Skip to content

Commit

Permalink
Added validation at MAC ack buffer handler
Browse files Browse the repository at this point in the history
We need to verify that ACK buffer is valid for current active buffer. Otherwise it may mean that wrong TX process is finished by wrong ACK.
  • Loading branch information
Juha Heiskanen committed Oct 5, 2020
1 parent 2a465b2 commit a792e83
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
9 changes: 9 additions & 0 deletions source/MAC/IEEE802_15_4/mac_mcps_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1183,15 +1183,24 @@ static void mac_pd_data_confirm_failure_handle(protocol_interface_rf_mac_setup_s
mcps_data_confirm_cb(rf_mac_setup, &mcps_data_conf, NULL);
}


static void mac_pd_data_ack_handler(mac_pre_parsed_frame_t *buf)
{
protocol_interface_rf_mac_setup_s *rf_mac_setup = buf->mac_class_ptr;

if (!rf_mac_setup->active_pd_data_request) {
mcps_sap_pre_parsed_frame_buffer_free(buf);
tr_debug("RX ack without active buffer");
} else {
mac_pre_build_frame_t *buffer = rf_mac_setup->active_pd_data_request;

//Validate here ack is proper to active buffer
if (!mac_pd_sap_ack_validation(rf_mac_setup, &buf->fcf_dsn, mac_header_message_start_pointer(buf))) {
tr_debug("Not a valid ACK for active tx process");
mcps_sap_pre_parsed_frame_buffer_free(buf);
return;
}

if (mac_ack_sap_rx_handler(buf, rf_mac_setup)) {
//Do not forward ACK payload but Accept ACK
mcps_sap_pre_parsed_frame_buffer_free(buf);
Expand Down
8 changes: 6 additions & 2 deletions source/MAC/IEEE802_15_4/mac_pd_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,12 +655,16 @@ static int8_t mac_data_interface_tx_done_by_ack_cb(protocol_interface_rf_mac_set
return 0;
}

static bool mac_pd_sap_ack_validation(protocol_interface_rf_mac_setup_s *rf_ptr, const mac_fcf_sequence_t *fcf_dsn, const uint8_t *data_ptr)
bool mac_pd_sap_ack_validation(protocol_interface_rf_mac_setup_s *rf_ptr, const mac_fcf_sequence_t *fcf_dsn, const uint8_t *data_ptr)
{
if (!rf_ptr->active_pd_data_request || !rf_ptr->active_pd_data_request->fcf_dsn.ackRequested) {
if (!rf_ptr->active_pd_data_request || (!rf_ptr->active_pd_data_request->fcf_dsn.ackRequested && !rf_ptr->active_pd_data_request->ExtendedFrameExchange)) {
return false; //No active Data request anymore or no ACK request for current TX
}

if (rf_ptr->active_pd_data_request->ExtendedFrameExchange && fcf_dsn->frametype == FC_DATA_FRAME) {
return true;//EFDE final message
}

if (fcf_dsn->frameVersion != rf_ptr->active_pd_data_request->fcf_dsn.frameVersion) {
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions source/MAC/IEEE802_15_4/mac_pd_sap.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

struct protocol_interface_rf_mac_setup;
struct arm_phy_sap_msg_s;
struct mac_fcf_sequence_s;

#define ENHANCED_ACK_NEIGHBOUR_POLL_MAX_TIME_US 3500

Expand Down Expand Up @@ -61,4 +62,6 @@ void mac_pd_sap_state_machine(struct protocol_interface_rf_mac_setup *rf_mac_set

int8_t mac_data_edfe_force_stop(struct protocol_interface_rf_mac_setup *rf_ptr);

bool mac_pd_sap_ack_validation(struct protocol_interface_rf_mac_setup *rf_ptr, const struct mac_fcf_sequence_s *fcf_dsn, const uint8_t *data_ptr);

#endif /* MAC_PD_SAP_H_ */
5 changes: 5 additions & 0 deletions test/nanostack/unittest/stub/mac_pd_sap_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ int8_t mac_data_edfe_force_stop(struct protocol_interface_rf_mac_setup *rf_ptr)
{
return 0;
}

bool mac_pd_sap_ack_validation(struct protocol_interface_rf_mac_setup *rf_ptr, const struct mac_fcf_sequence_s *fcf_dsn, const uint8_t *data_ptr)
{
return true;
}

0 comments on commit a792e83

Please sign in to comment.