Skip to content

Commit

Permalink
Iotthd 4478 (ARMmbed#2560)
Browse files Browse the repository at this point in the history
* Timing tool: Trace for CSMA-CA start and stop

* MAC: Push active packet back to queue if incorrect channel type

* Updated change log

* Store original priority
  • Loading branch information
Jarkko Paso authored Jan 28, 2021
1 parent 7ca6c24 commit d258068
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

### Changes
* Wi-SUN stack enables IPv6 tunnel allways for traffic to Border router direction. This fixes interoperability issues with other Wi-SUN vendors.
* Push active MAC packet back to TX queue if channel type is wrong. Allows MAC to start new transmission with applicable packet type improving for example multicast delivery.

### Bugfix
* Added support for handle RPL hop by Hop sender rank 0. This fixes interoperability issues with other Wi-SUN vendors.
Expand Down
3 changes: 3 additions & 0 deletions source/MAC/IEEE802_15_4/mac_data_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ typedef struct mac_pre_build_frame {
uint8_t csma_periods_left;
uint8_t fhss_retry_count;
uint8_t fhss_cca_retry_count;
uint8_t stored_retry_cnt;
uint8_t stored_cca_cnt;
uint16_t initial_tx_channel;
uint32_t tx_time;
bool upper_layer_request: 1;
Expand All @@ -102,6 +104,7 @@ typedef struct mac_pre_build_frame {
bool WaitResponse: 1;
unsigned security_mic_len: 5; //Max possible lengths 0, 4, 8, 16 bytes
unsigned priority: 2;
unsigned stored_priority: 2;
struct mac_pre_build_frame *next; //Pointer for queue purpose
} mac_pre_build_frame_t;

Expand Down
3 changes: 2 additions & 1 deletion source/MAC/IEEE802_15_4/mac_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ typedef enum mac_event_t {
MAC_TX_TIMEOUT,
MAC_ACK_SECURITY_FAIL,
MAC_UNKNOWN_DESTINATION,
MAC_TX_PRECOND_FAIL
MAC_TX_PRECOND_FAIL,
MAC_RETURN_TO_QUEUE
} mac_event_t;

typedef enum mac_tx_status_type_t {
Expand Down
23 changes: 18 additions & 5 deletions source/MAC/IEEE802_15_4/mac_mcps_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1507,11 +1507,16 @@ static void mcps_data_confirm_handle(protocol_interface_rf_mac_setup_s *rf_ptr,
mcps_data_conf_t confirm;
if (rf_ptr->fhss_api && !buffer->asynch_request) {
// FHSS checks if this failed buffer needs to be pushed back to TX queue and retransmitted
if (!mcps_buffer_edfe_data_failure(rf_ptr, buffer) && ((rf_ptr->mac_tx_result == MAC_TX_FAIL) || (rf_ptr->mac_tx_result == MAC_CCA_FAIL))) {
if (rf_ptr->fhss_api->data_tx_fail(rf_ptr->fhss_api, buffer->msduHandle, mac_convert_frame_type_to_fhss(buffer->fcf_dsn.frametype), rf_ptr->mac_tx_start_channel) == true) {

if (!mcps_buffer_edfe_data_failure(rf_ptr, buffer) && ((rf_ptr->mac_tx_result == MAC_TX_FAIL) || (rf_ptr->mac_tx_result == MAC_CCA_FAIL) || (rf_ptr->mac_tx_result == MAC_RETURN_TO_QUEUE))) {
if ((rf_ptr->mac_tx_result == MAC_RETURN_TO_QUEUE) || rf_ptr->fhss_api->data_tx_fail(rf_ptr->fhss_api, buffer->msduHandle, mac_convert_frame_type_to_fhss(buffer->fcf_dsn.frametype), rf_ptr->mac_tx_start_channel) == true) {
if (rf_ptr->mac_tx_result == MAC_TX_FAIL) {
buffer->fhss_retry_count += 1 + rf_ptr->mac_tx_status.retry;
} else if (rf_ptr->mac_tx_result == MAC_RETURN_TO_QUEUE) {
buffer->stored_retry_cnt = rf_ptr->mac_tx_retry;
buffer->stored_cca_cnt = rf_ptr->mac_cca_retry;
buffer->stored_priority = buffer->priority;
// Use priority to transmit it first when proper channel is available
buffer->priority = MAC_PD_DATA_TX_IMMEDIATELY;
} else {
buffer->fhss_retry_count += rf_ptr->mac_tx_status.retry;
}
Expand Down Expand Up @@ -2135,8 +2140,16 @@ static int8_t mcps_pd_data_request(protocol_interface_rf_mac_setup_s *rf_ptr, ma
rf_ptr->macTxRequestAck = false;

memset(&(rf_ptr->mac_tx_status), 0, sizeof(mac_tx_status_t));
rf_ptr->mac_cca_retry = 0;
rf_ptr->mac_tx_retry = 0;
if (buffer->priority == MAC_PD_DATA_TX_IMMEDIATELY) {
// Return original priority and retry/CCA counts
buffer->priority = buffer->stored_priority;
rf_ptr->mac_tx_retry = rf_ptr->mac_tx_status.retry = buffer->stored_retry_cnt;
rf_ptr->mac_cca_retry = rf_ptr->mac_tx_status.cca_cnt = buffer->stored_cca_cnt;
buffer->stored_retry_cnt = buffer->stored_cca_cnt = 0;
} else {
rf_ptr->mac_tx_retry = 0;
rf_ptr->mac_cca_retry = 0;
}
rf_ptr->mac_tx_start_channel = rf_ptr->mac_channel;
mac_csma_param_init(rf_ptr);
if (mcps_generic_packet_build(rf_ptr, buffer) != 0) {
Expand Down
1 change: 1 addition & 0 deletions source/MAC/IEEE802_15_4/mac_mcps_sap.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ typedef enum {
#define MAC_PD_DATA_NORMAL_PRIORITY 0 //Normal MCPS DATA REQ
#define MAC_PD_DATA_MEDIUM_PRIORITY 1 //Indirect Data which is polled
#define MAC_PD_DATA_HIGH_PRIOTITY 2 //Beacon request Beacon response
#define MAC_PD_DATA_TX_IMMEDIATELY 3 //Only for packets whose transmission was interrupted by wrong channel type. E.g. unicast on broadcast channel.

#define MCPS_SAP_DATA_IND_EVENT 1
#define MCPS_SAP_DATA_CNF_EVENT 2
Expand Down
22 changes: 17 additions & 5 deletions source/MAC/IEEE802_15_4/mac_pd_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ int8_t mac_plme_cca_req(protocol_interface_rf_mac_setup_s *rf_mac_setup)
length = tx_buf->len;
}
if (dev_driver->tx(buffer, length, 1, PHY_LAYER_PAYLOAD) == 0) {
#ifdef TIMING_TOOL_TRACES
tr_info("%u CSMA_start", mac_mcps_sap_get_phy_timestamp(rf_mac_setup));
#endif
return 0;
}

Expand Down Expand Up @@ -451,9 +454,13 @@ static int8_t mac_data_interface_tx_done_cb(protocol_interface_rf_mac_setup_s *r
return -1;
}

if (status == PHY_LINK_CCA_PREPARE) {

#ifdef TIMING_TOOL_TRACES
if ((status == PHY_LINK_CCA_FAIL) || (status == PHY_LINK_CCA_PREPARE)) {
tr_info("%u CSMA_done", mac_mcps_sap_get_phy_timestamp(rf_ptr));
}
#endif

if (status == PHY_LINK_CCA_PREPARE) {
if (rf_ptr->mac_ack_tx_active || rf_ptr->mac_edfe_tx_active) {
goto VALIDATE_TX_TIME;
}
Expand Down Expand Up @@ -485,10 +492,12 @@ static int8_t mac_data_interface_tx_done_cb(protocol_interface_rf_mac_setup_s *r
mac_sap_cca_fail_cb(rf_ptr, 0xffff);
return PHY_TX_NOT_ALLOWED;
}
// When FHSS TX handle returns -3, we are trying to transmit broadcast packet on unicast channel -> push back
// to queue by using CCA fail event
// When FHSS TX handle returns -3, we are trying to:
// - transmit broadcast packet on unicast channel
// - transmit unicast packet on broadcast channel
// Push back to queue to allow sending applicable packet
if (tx_handle_retval == -3) {
mac_tx_done_state_set(rf_ptr, MAC_CCA_FAIL);
mac_tx_done_state_set(rf_ptr, MAC_RETURN_TO_QUEUE);
return PHY_TX_NOT_ALLOWED;
} else if (tx_handle_retval == -2) {
mac_tx_done_state_set(rf_ptr, MAC_UNKNOWN_DESTINATION);
Expand All @@ -505,6 +514,9 @@ static int8_t mac_data_interface_tx_done_cb(protocol_interface_rf_mac_setup_s *r
active_buf->csma_periods_left--;
active_buf->tx_time += rf_ptr->multi_cca_interval;
mac_pd_sap_set_phy_tx_time(rf_ptr, active_buf->tx_time, true);
#ifdef TIMING_TOOL_TRACES
tr_info("%u CSMA_start", mac_mcps_sap_get_phy_timestamp(rf_ptr));
#endif
return PHY_RESTART_CSMA;
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
}
// Do not allow unicast destination on broadcast channel
if (!is_broadcast_addr && (fhss_structure->ws->is_on_bc_channel == true)) {
return -1;
return -3;
}
// Check TX/RX slot
if (!fhss_ws_check_tx_allowed(fhss_structure)) {
Expand Down

0 comments on commit d258068

Please sign in to comment.