From 14e1597234329673026284002d1cc01af7f5327e Mon Sep 17 00:00:00 2001 From: Juha Heiskanen Date: Thu, 19 Apr 2018 12:12:49 +0300 Subject: [PATCH] Fixed missing TX ime calculation for pre-builded MAC packet send. Change-Id: Iea6eb869a11138fbaffabe61140bd03a9bb36cd8 --- source/MAC/IEEE802_15_4/mac_mcps_sap.c | 27 +++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/source/MAC/IEEE802_15_4/mac_mcps_sap.c b/source/MAC/IEEE802_15_4/mac_mcps_sap.c index 07a9e65da18..b62fead6746 100644 --- a/source/MAC/IEEE802_15_4/mac_mcps_sap.c +++ b/source/MAC/IEEE802_15_4/mac_mcps_sap.c @@ -1395,6 +1395,15 @@ static void mcps_generic_sequence_number_allocate(protocol_interface_rf_mac_setu } +static uint32_t mcps_generic_backoff_calc(protocol_interface_rf_mac_setup_s *rf_ptr) +{ + uint32_t random_period = mac_csma_backoff_get(rf_ptr); + if (rf_ptr->fhss_api) { + return mcps_calculate_tx_time(rf_ptr, random_period); + } + return random_period; +} + static int8_t mcps_generic_packet_build(protocol_interface_rf_mac_setup_s *rf_ptr, mac_pre_build_frame_t *buffer) { phy_device_driver_s *dev_driver = rf_ptr->dev_driver->phy_driver; @@ -1411,6 +1420,7 @@ static int8_t mcps_generic_packet_build(protocol_interface_rf_mac_setup_s *rf_pt tx_buf->len = buffer->mac_payload_length; memcpy(ptr, buffer->mac_payload, buffer->mac_payload_length ); + buffer->tx_time = mcps_generic_backoff_calc(rf_ptr); return 0; } @@ -1466,13 +1476,7 @@ static int8_t mcps_generic_packet_build(protocol_interface_rf_mac_setup_s *rf_pt tx_buf->len = frame_length; uint8_t *mhr_start = ptr; - - uint32_t random_period = mac_csma_backoff_get(rf_ptr); - if (rf_ptr->fhss_api) { - buffer->tx_time = mcps_calculate_tx_time(rf_ptr, random_period); - } else { - buffer->tx_time = random_period; - } + buffer->tx_time = mcps_generic_backoff_calc(rf_ptr); ptr = mac_generic_packet_write(rf_ptr, ptr, buffer); @@ -1506,6 +1510,7 @@ static int8_t mcps_generic_packet_rebuild(protocol_interface_rf_mac_setup_s *rf_ tx_buf->len = buffer->mac_payload_length; memcpy(ptr, buffer->mac_payload, buffer->mac_payload_length ); + buffer->tx_time = mcps_generic_backoff_calc(rf_ptr); return 0; } @@ -1533,12 +1538,8 @@ static int8_t mcps_generic_packet_rebuild(protocol_interface_rf_mac_setup_s *rf_ tx_buf->len = frame_length; uint8_t *mhr_start = ptr; - uint32_t random_period = mac_csma_backoff_get(rf_ptr); - if (rf_ptr->fhss_api) { - buffer->tx_time = mcps_calculate_tx_time(rf_ptr, random_period); - } else { - buffer->tx_time = random_period; - } + buffer->tx_time = mcps_generic_backoff_calc(rf_ptr); + ptr = mac_generic_packet_write(rf_ptr, ptr, buffer); if (buffer->fcf_dsn.securityEnabled) {