Skip to content

Commit

Permalink
Merge pull request ARMmbed#1799 from ARMmbed/several_bug_fixs
Browse files Browse the repository at this point in the history
Bug fixes:
  • Loading branch information
Juha Heiskanen authored Aug 28, 2018
2 parents f39312b + 63d8a41 commit 08d3e12
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ static int8_t ws_fhss_discovery_configure(protocol_interface_info_entry_t *cur)
fhss_configuration.ws_channel_function = WS_FIXED_CHANNEL;
fhss_configuration.fhss_bc_dwell_interval = 0;
fhss_configuration.fhss_broadcast_interval = 0;
cur->ws_info->hopping_schdule.fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels);
cur->ws_info->hopping_schdule.fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels - 1);
memset(fhss_configuration.channel_mask, 0, sizeof(uint32_t) * 8);
channel_list_set_channel(fhss_configuration.channel_mask, cur->ws_info->hopping_schdule.fixed_channel, true);

Expand Down Expand Up @@ -1516,7 +1516,7 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
tr_debug("Border router start network");
// Randomize fixed channel. Only used if channel plan is fixed
cur->ws_info->hopping_schdule.fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels);
cur->ws_info->hopping_schdule.fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels - 1);
cur->ws_info->network_pan_id = randLIB_get_random_in_range(0,0xfffd);
cur->ws_info->pan_information.pan_size = 0;
cur->ws_info->pan_information.pan_version = randLIB_get_random_in_range(0,0xffff);
Expand Down
9 changes: 6 additions & 3 deletions source/MAC/IEEE802_15_4/mac_mcps_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1819,9 +1819,12 @@ static int8_t mcps_pd_data_cca_trig(protocol_interface_rf_mac_setup_s *rf_ptr, m
}
mac_pd_sap_set_phy_tx_time(rf_ptr, buffer->tx_time, cca_enabled);
if (mac_plme_cca_req(rf_ptr) != 0) {
rf_ptr->macTxProcessActive = false;
rf_ptr->mac_ack_tx_active = false;
return -1;

if (buffer->fcf_dsn.frametype == MAC_FRAME_ACK) {
rf_ptr->macTxProcessActive = false;
return -1;
}
mac_csma_backoff_start(rf_ptr);
}
} else {
timer_mac_start(rf_ptr, MAC_TIMER_CCA, (uint16_t)(buffer->tx_time / 50));
Expand Down
12 changes: 10 additions & 2 deletions source/MAC/IEEE802_15_4/mac_pd_sap.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define NWKTX_TIMEOUT_PERIOD (1200*20)

static int8_t mac_data_interface_tx_done_cb(protocol_interface_rf_mac_setup_s *rf_ptr, phy_link_tx_status_e status, uint8_t cca_retry, uint8_t tx_retry);
static void mac_sap_cca_fail_cb(protocol_interface_rf_mac_setup_s *rf_ptr);

void mac_csma_param_init(protocol_interface_rf_mac_setup_s *rf_mac_setup)
{
Expand All @@ -64,7 +65,7 @@ static uint16_t mac_csma_backoff_period_convert_to50us(uint8_t random, uint8_t b
return (random * backoff_period_in_10us) / 5;
}

static void mac_csma_backoff_start(protocol_interface_rf_mac_setup_s *rf_mac_setup)
void mac_csma_backoff_start(protocol_interface_rf_mac_setup_s *rf_mac_setup)
{
uint8_t backoff = mac_csma_random_backoff_get(rf_mac_setup);
uint16_t backoff_slots = mac_csma_backoff_period_convert_to50us(backoff, rf_mac_setup->backoff_period_in_10us);
Expand Down Expand Up @@ -219,6 +220,12 @@ void mac_pd_sap_state_machine(protocol_interface_rf_mac_setup_s *rf_mac_setup)
if (rf_mac_setup->macUpState && rf_mac_setup->macTxProcessActive) {

if (rf_mac_setup->mac_tx_result == MAC_TIMER_CCA) {

if (rf_mac_setup->rf_csma_extension_supported) {
mac_sap_cca_fail_cb(rf_mac_setup);
return;
}

if (rf_mac_setup->fhss_api) {
uint8_t *synch_info = NULL;
mac_pre_build_frame_t *active_buf = rf_mac_setup->active_pd_data_request;
Expand Down Expand Up @@ -270,7 +277,8 @@ void mac_pd_sap_state_machine(protocol_interface_rf_mac_setup_s *rf_mac_setup)
}
}

static void mac_sap_cca_fail_cb(protocol_interface_rf_mac_setup_s *rf_ptr) {
static void mac_sap_cca_fail_cb(protocol_interface_rf_mac_setup_s *rf_ptr)
{
rf_ptr->macRfRadioTxActive = false;
if (rf_ptr->mac_cca_retry > rf_ptr->macMaxCSMABackoffs || (rf_ptr->active_pd_data_request && rf_ptr->active_pd_data_request->asynch_request)) {
//Send MAC_CCA_FAIL
Expand Down
2 changes: 2 additions & 0 deletions source/MAC/IEEE802_15_4/mac_pd_sap.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ int8_t mac_pd_sap_data_cb(void *identifier, struct arm_phy_sap_msg_s *message);
void mac_csma_param_init(struct protocol_interface_rf_mac_setup *rf_mac_setup);

uint32_t mac_csma_backoff_get(struct protocol_interface_rf_mac_setup *rf_mac_setup);

void mac_csma_backoff_start(struct protocol_interface_rf_mac_setup *rf_mac_setup);
/**
* Run Mac data interface state Machine.
*
Expand Down
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 @@ -73,3 +73,8 @@ uint32_t mac_csma_backoff_get(protocol_interface_rf_mac_setup_s *rf_mac_setup)
return 960;
}

void mac_csma_backoff_start(protocol_interface_rf_mac_setup_s *rf_mac_setup)
{

}

0 comments on commit 08d3e12

Please sign in to comment.