From 587add577c8ab4d1f1c9c9df1b1e62ae61f807ee Mon Sep 17 00:00:00 2001 From: Jarkko Paso Date: Thu, 27 Aug 2020 15:38:40 +0300 Subject: [PATCH] MAC: Validate TX time (#2429) --- source/MAC/IEEE802_15_4/mac_pd_sap.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/MAC/IEEE802_15_4/mac_pd_sap.c b/source/MAC/IEEE802_15_4/mac_pd_sap.c index 71e201935dfb..6b36a7f7d69d 100644 --- a/source/MAC/IEEE802_15_4/mac_pd_sap.c +++ b/source/MAC/IEEE802_15_4/mac_pd_sap.c @@ -507,7 +507,14 @@ static int8_t mac_data_interface_tx_done_cb(protocol_interface_rf_mac_setup_s *r } } VALIDATE_TX_TIME: -// TODO: Validate TX time here + if (rf_ptr->active_pd_data_request && rf_ptr->active_pd_data_request->tx_time && !rf_ptr->mac_ack_tx_active && !rf_ptr->mac_edfe_tx_active) { + int32_t tx_time_error_us = mac_mcps_sap_get_phy_timestamp(rf_ptr) - rf_ptr->active_pd_data_request->tx_time; + // Positive error means that TX is too late. Do not allow transmit if transmission is delayed over 5ms + if (tx_time_error_us > 5000) { + mac_sap_cca_fail_cb(rf_ptr, 0xffff); + return PHY_TX_NOT_ALLOWED; + } + } #ifdef TIMING_TOOL_TRACES tr_info("%u TX_start %u", mac_mcps_sap_get_phy_timestamp(rf_ptr), rf_ptr->mac_channel); #endif