Skip to content

Commit

Permalink
Store TX start channel and black list if TX failed (ARMmbed#2261)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso authored Dec 19, 2019
1 parent 0494606 commit 11a1e1d
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 20 deletions.
3 changes: 2 additions & 1 deletion nanostack/fhss_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ typedef void fhss_data_tx_done(const fhss_api_t *api, bool waiting_ack, bool tx_
* @param api FHSS instance.
* @param handle Handle of the data request.
* @param frame_type Frame type of packet (Frames types are defined by FHSS api).
* @param channel Channel wanted to black list temporarily.
* @return true if frame has to be queued for retransmission, false otherwise.
*/
typedef bool fhss_data_tx_fail(const fhss_api_t *api, uint8_t handle, int frame_type);
typedef bool fhss_data_tx_fail(const fhss_api_t *api, uint8_t handle, int frame_type, uint8_t channel);

/**
* @brief Change synchronization state.
Expand Down
1 change: 1 addition & 0 deletions source/MAC/IEEE802_15_4/mac_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ typedef struct protocol_interface_rf_mac_setup {
mac_scan_type_t scan_type;

uint8_t mac_channel;
uint8_t mac_tx_start_channel;
//uint8_t cca_failure;

/* MAC TX Queue */
Expand Down
3 changes: 2 additions & 1 deletion source/MAC/IEEE802_15_4/mac_mcps_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@ static void mcps_data_confirm_handle(protocol_interface_rf_mac_setup_s *rf_ptr,
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 ((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)) == true) {
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 (rf_ptr->mac_tx_result == MAC_TX_FAIL) {
buffer->fhss_retry_count += 1 + rf_ptr->mac_tx_status.retry;
Expand Down Expand Up @@ -1921,6 +1921,7 @@ static int8_t mcps_pd_data_request(protocol_interface_rf_mac_setup_s *rf_ptr, ma
memset(&(rf_ptr->mac_tx_status), 0, sizeof(mac_tx_status_t));
rf_ptr->mac_cca_retry = 0;
rf_ptr->mac_tx_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) {
return -1;
Expand Down
3 changes: 2 additions & 1 deletion source/Service_Libs/fhss/fhss.c
Original file line number Diff line number Diff line change
Expand Up @@ -1123,8 +1123,9 @@ static void fhss_data_tx_done_callback(const fhss_api_t *api, bool waiting_ack,
}
}

static bool fhss_data_tx_fail_callback(const fhss_api_t *api, uint8_t handle, int frame_type)
static bool fhss_data_tx_fail_callback(const fhss_api_t *api, uint8_t handle, int frame_type, uint8_t channel)
{
(void) channel;
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
if (!fhss_structure) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ static void fhss_ws_data_tx_done_callback(const fhss_api_t *api, bool waiting_ac
}
}

static bool fhss_ws_data_tx_fail_callback(const fhss_api_t *api, uint8_t handle, int frame_type)
static bool fhss_ws_data_tx_fail_callback(const fhss_api_t *api, uint8_t handle, int frame_type, uint8_t channel)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(api);
if (!fhss_structure) {
Expand All @@ -687,7 +687,7 @@ static bool fhss_ws_data_tx_fail_callback(const fhss_api_t *api, uint8_t handle,
fhss_failed_handle_remove(fhss_structure, handle);
return false;
}
fhss_failed_tx->bad_channel = fhss_structure->rx_channel;
fhss_failed_tx->bad_channel = channel;
} else {
// Create new failure handle and return true to retransmit
fhss_failed_handle_add(fhss_structure, handle, fhss_structure->rx_channel);
Expand Down
15 changes: 8 additions & 7 deletions test/nanostack/unittest/service_libs/fhss/test_fhss.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#define DEFAULT_WAITING_ACK false
#define DEFAULT_TX_COMPLETED true
#define DEFAULT_PHY_MTU_SIZE 255
#define DEFAULT_BAD_CHANNEL 0

static fhss_api_t fhss_api;
static fhss_bs_t bs;
Expand Down Expand Up @@ -259,12 +260,12 @@ bool test_fhss_check_tx_conditions_callback()
enable_fhss_struct();
FHSS.fhss_state = FHSS_SYNCHRONIZED;
nsdynmemlib_stub.returnCounter = 1;
FHSS.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE);
FHSS.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE, DEFAULT_BAD_CHANNEL);
if (FHSS.fhss_api->check_tx_conditions(api, DEFAULT_IS_BC_DEST, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH) != false) {
return false;
}
// Second call of TX fail should remove the failed handle from list
FHSS.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE);
FHSS.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE, DEFAULT_BAD_CHANNEL);
// Test failing channel type
if (FHSS.fhss_api->check_tx_conditions(api, true, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH) != false) {
return false;
Expand Down Expand Up @@ -377,7 +378,7 @@ bool test_fhss_data_tx_done_callback()

// Test removing failed handle
nsdynmemlib_stub.returnCounter = 1;
FHSS.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE);
FHSS.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE, DEFAULT_BAD_CHANNEL);
FHSS.fhss_api->data_tx_done(api, true, DEFAULT_TX_COMPLETED, DEFAULT_HANDLE);

return true;
Expand All @@ -388,23 +389,23 @@ bool test_fhss_data_tx_fail_callback()
fhss_api_t *api = test_generate_fhss_api();
// Test when FHSS struct not found
disable_fhss_struct();
if (FHSS.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE) != false) {
if (FHSS.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE, DEFAULT_BAD_CHANNEL) != false) {
return false;
}
// Test when FHSS not synchronized
enable_fhss_struct();
if (FHSS.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE) != false) {
if (FHSS.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE, DEFAULT_BAD_CHANNEL) != false) {
return false;
}
// Test when channel retries are disabled
FHSS.fhss_state = FHSS_SYNCHRONIZED;
FHSS.bs->fhss_configuration.fhss_number_of_channel_retries = 0;
if (FHSS.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE) != false) {
if (FHSS.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE, DEFAULT_BAD_CHANNEL) != false) {
return false;
}
// Test incorrect frame type
FHSS.bs->fhss_configuration.fhss_number_of_channel_retries = 1;
if (FHSS.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, FHSS_SYNCH_FRAME) != false) {
if (FHSS.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, FHSS_SYNCH_FRAME, DEFAULT_BAD_CHANNEL) != false) {
return false;
}

Expand Down
13 changes: 7 additions & 6 deletions test/nanostack/unittest/service_libs/fhss_ws/test_fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#define DEFAULT_TIMESTAMP 0
#define DEFAULT_WAITING_ACK false
#define DEFAULT_TX_COMPLETED true
#define DEFAULT_BAD_CHANNEL 0

static fhss_api_t fhss_api;
static fhss_ws_t ws;
Expand Down Expand Up @@ -399,33 +400,33 @@ bool test_fhss_ws_data_tx_fail_callback()
fhss_api_t *api = test_generate_fhss_api();
// Test when FHSS struct not found
disable_fhss_struct();
if (fhss_common_stub.fhss_struct.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE) != false) {
if (fhss_common_stub.fhss_struct.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE, DEFAULT_BAD_CHANNEL) != false) {
return false;
}
// Test when FHSS is unsynchronized
enable_fhss_struct();
if (fhss_common_stub.fhss_struct.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE) != false) {
if (fhss_common_stub.fhss_struct.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE, DEFAULT_BAD_CHANNEL) != false) {
return false;
}
// Test when not data frame
fhss_common_stub.fhss_struct.fhss_state = FHSS_SYNCHRONIZED;
if (fhss_common_stub.fhss_struct.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, FHSS_SYNCH_FRAME) != false) {
if (fhss_common_stub.fhss_struct.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, FHSS_SYNCH_FRAME, DEFAULT_BAD_CHANNEL) != false) {
return false;
}
// Test adding new failed entry
fhss_common_stub.fhss_failed_tx.handle = DEFAULT_HANDLE + 1;
fhss_common_stub.fhss_failed_tx.retries_done = 0;
if (fhss_common_stub.fhss_struct.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE) != true) {
if (fhss_common_stub.fhss_struct.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE, DEFAULT_BAD_CHANNEL) != true) {
return false;
}
// Test when handle failed again
fhss_common_stub.fhss_failed_tx.handle = DEFAULT_HANDLE;
if (fhss_common_stub.fhss_struct.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE) != true) {
if (fhss_common_stub.fhss_struct.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE, DEFAULT_BAD_CHANNEL) != true) {
return false;
}
// Test last failure
fhss_common_stub.fhss_failed_tx.retries_done = 3;
if (fhss_common_stub.fhss_struct.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE) != false) {
if (fhss_common_stub.fhss_struct.fhss_api->data_tx_fail(api, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE, DEFAULT_BAD_CHANNEL) != false) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion test/nanostack/unittest/stub/fhss_config_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void fhss_data_tx_done_cb_stub(const fhss_api_t *api, bool waiting_ack, bool tx_
fhss_config_stub.int8_value++;
}

bool fhss_data_tx_fail_cb_stub(const fhss_api_t *api, uint8_t handle, int frame_type)
bool fhss_data_tx_fail_cb_stub(const fhss_api_t *api, uint8_t handle, int frame_type, uint8_t channel)
{
fhss_config_stub.int8_value++;
return true;
Expand Down
2 changes: 1 addition & 1 deletion test/nanostack/unittest/stub/fhss_config_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool fhss_is_broadcast_channel_cb_stub(const fhss_api_t *api);
bool fhss_use_broadcast_queue_cb_stub(const fhss_api_t *api, bool is_broadcast_addr, int frame_type);
void fhss_receive_frame_cb_stub(const fhss_api_t *api, uint16_t pan_id, uint8_t *source_address, uint32_t timestamp, uint8_t *synch_info, int frame_type);
void fhss_data_tx_done_cb_stub(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle);
bool fhss_data_tx_fail_cb_stub(const fhss_api_t *api, uint8_t handle, int frame_type);
bool fhss_data_tx_fail_cb_stub(const fhss_api_t *api, uint8_t handle, int frame_type, uint8_t channel);
void fhss_synch_state_set_cb_stub(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id);
uint32_t fhss_read_timestamp_cb_stub(const fhss_api_t *api);
uint16_t fhss_get_retry_period_cb_stub(const fhss_api_t *api, uint8_t *destination_address, uint16_t phy_mtu);
Expand Down

0 comments on commit 11a1e1d

Please sign in to comment.