@@ -70,6 +70,7 @@ static void mac_set_active_event(protocol_interface_rf_mac_setup_s *rf_mac_setup
7070static void mac_clear_active_event (protocol_interface_rf_mac_setup_s * rf_mac_setup , uint8_t event_type );
7171static bool mac_read_active_event (protocol_interface_rf_mac_setup_s * rf_mac_setup , uint8_t event_type );
7272static int8_t mcps_pd_data_cca_trig (protocol_interface_rf_mac_setup_s * rf_ptr , mac_pre_build_frame_t * buffer );
73+ static void mac_pd_data_confirm_failure_handle (protocol_interface_rf_mac_setup_s * rf_mac_setup );
7374
7475static int8_t mac_tasklet_event_handler = -1 ;
7576
@@ -362,13 +363,14 @@ void mcps_sap_data_req_handler_ext(protocol_interface_rf_mac_setup_s *rf_mac_set
362363
363364 verify_status :
364365 if (status != MLME_SUCCESS ){
365- mcps_data_conf_t confirm ;
366- memset (& confirm , 0 , sizeof (mcps_data_conf_t ));
367- confirm .msduHandle = data_req -> msduHandle ;
368- confirm .status = status ;
369366 tr_debug ("DATA REQ Fail %u" , status );
367+ rf_mac_setup -> mac_mcps_data_conf_fail .msduHandle = data_req -> msduHandle ;
368+ rf_mac_setup -> mac_mcps_data_conf_fail .status = status ;
370369 mcps_sap_prebuild_frame_buffer_free (buffer );
371- mcps_data_confirm_cb (rf_mac_setup , & confirm , NULL );
370+ if (mcps_sap_pd_confirm_failure (rf_mac_setup ) != 0 ) {
371+ // event sending failed, calling handler directly
372+ mac_pd_data_confirm_failure_handle (rf_mac_setup );
373+ }
372374 }
373375}
374376
@@ -1093,7 +1095,6 @@ void mac_mcps_trig_buffer_from_queue(protocol_interface_rf_mac_setup_s *rf_mac_s
10931095 }
10941096}
10951097
1096-
10971098static int8_t mac_ack_sap_rx_handler (mac_pre_parsed_frame_t * buf , protocol_interface_rf_mac_setup_s * rf_mac_setup )
10981099{
10991100 //allocate Data ind primitiv and parse packet to that
@@ -1144,6 +1145,14 @@ static void mac_pd_data_confirm_handle(protocol_interface_rf_mac_setup_s *rf_mac
11441145 mac_mcps_trig_buffer_from_queue (rf_mac_setup );
11451146}
11461147
1148+ static void mac_pd_data_confirm_failure_handle (protocol_interface_rf_mac_setup_s * rf_mac_setup )
1149+ {
1150+ mcps_data_conf_t mcps_data_conf ;
1151+ memset (& mcps_data_conf , 0 , sizeof (mcps_data_conf_t ));
1152+ mcps_data_conf .msduHandle = rf_mac_setup -> mac_mcps_data_conf_fail .msduHandle ;
1153+ mcps_data_conf .status = rf_mac_setup -> mac_mcps_data_conf_fail .status ;
1154+ mcps_data_confirm_cb (rf_mac_setup , & mcps_data_conf , NULL );
1155+ }
11471156
11481157static void mac_pd_data_ack_handler (mac_pre_parsed_frame_t * buf )
11491158{
@@ -1187,6 +1196,10 @@ static void mac_mcps_sap_data_tasklet(arm_event_s *event)
11871196 mac_pd_data_confirm_handle ((protocol_interface_rf_mac_setup_s * )event -> data_ptr );
11881197 break ;
11891198
1199+ case MCPS_SAP_DATA_CNF_FAIL_EVENT :
1200+ mac_pd_data_confirm_failure_handle ((protocol_interface_rf_mac_setup_s * )event -> data_ptr );
1201+ break ;
1202+
11901203 case MCPS_SAP_DATA_ACK_CNF_EVENT :
11911204 mac_pd_data_ack_handler ((mac_pre_parsed_frame_t * )event -> data_ptr );
11921205 break ;
@@ -1907,7 +1920,14 @@ void mcps_sap_pd_req_queue_write(protocol_interface_rf_mac_setup_s *rf_mac_setup
19071920 if (mcps_pd_data_request (rf_mac_setup , buffer ) != 0 ) {
19081921 rf_mac_setup -> mac_tx_result = MAC_TX_PRECOND_FAIL ;
19091922 rf_mac_setup -> macTxRequestAck = false;
1910- mcps_sap_pd_confirm (rf_mac_setup );
1923+ if (mcps_sap_pd_confirm (rf_mac_setup ) != 0 ) {
1924+ // can't send event, try calling error handler directly
1925+ rf_mac_setup -> mac_mcps_data_conf_fail .msduHandle = buffer -> msduHandle ;
1926+ rf_mac_setup -> mac_mcps_data_conf_fail .status = buffer -> status ;
1927+ mcps_sap_prebuild_frame_buffer_free (buffer );
1928+ rf_mac_setup -> active_pd_data_request = NULL ;
1929+ mac_pd_data_confirm_failure_handle (rf_mac_setup );
1930+ }
19111931 }
19121932
19131933 return ;
@@ -2087,10 +2107,10 @@ int8_t mcps_sap_pd_ind(mac_pre_parsed_frame_t *buffer)
20872107 return eventOS_event_send (& event );
20882108}
20892109
2090- void mcps_sap_pd_confirm (void * mac_ptr )
2110+ int8_t mcps_sap_pd_confirm (void * mac_ptr )
20912111{
20922112 if (mac_tasklet_event_handler < 0 || !mac_ptr ) {
2093- return ;
2113+ return -2 ;
20942114 }
20952115 arm_event_s event = {
20962116 .receiver = mac_tasklet_event_handler ,
@@ -2101,8 +2121,24 @@ void mcps_sap_pd_confirm(void *mac_ptr)
21012121 .priority = ARM_LIB_HIGH_PRIORITY_EVENT ,
21022122 };
21032123
2104- eventOS_event_send (& event );
2124+ return eventOS_event_send (& event );
2125+ }
21052126
2127+ int8_t mcps_sap_pd_confirm_failure (void * mac_ptr )
2128+ {
2129+ if (mac_tasklet_event_handler < 0 || !mac_ptr ) {
2130+ return -2 ;
2131+ }
2132+ arm_event_s event = {
2133+ .receiver = mac_tasklet_event_handler ,
2134+ .sender = 0 ,
2135+ .event_id = 0 ,
2136+ .data_ptr = mac_ptr ,
2137+ .event_type = MCPS_SAP_DATA_CNF_FAIL_EVENT ,
2138+ .priority = ARM_LIB_HIGH_PRIORITY_EVENT ,
2139+ };
2140+
2141+ return eventOS_event_send (& event );
21062142}
21072143
21082144void mcps_sap_pd_ack (void * ack_ptr )
0 commit comments