diff --git a/source/Service_Libs/fhss/fhss.c b/source/Service_Libs/fhss/fhss.c index a4d7e020694..4626d3f24fc 100644 --- a/source/Service_Libs/fhss/fhss.c +++ b/source/Service_Libs/fhss/fhss.c @@ -728,12 +728,16 @@ void fhss_failed_list_free(fhss_structure_t *fhss_structure) } } -static int fhss_handle_state_set(fhss_structure_t *fhss_structure, fhss_states fhss_state, uint16_t pan_id) +static void fhss_handle_state_set(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id) { + fhss_structure_t *fhss_structure = fhss_get_object_with_api(api); + if (!fhss_structure) { + return; + } // State is already set if (fhss_structure->fhss_state == fhss_state) { tr_debug("Synch same state %u", fhss_state); - return -1; + return; } if (fhss_state == FHSS_UNSYNCHRONIZED) { @@ -747,12 +751,12 @@ static int fhss_handle_state_set(fhss_structure_t *fhss_structure, fhss_states f // Do not synchronize to current pan if (fhss_structure->synch_panid == pan_id) { tr_debug("Synch same panid %u", pan_id); - return -1; + return; } if (fhss_structure->fhss_scramble_table == NULL) { if (fhss_generate_scramble_table(fhss_structure)) { tr_error("Failed to generate scramble table"); - return -1; + return; } } uint32_t datarate = fhss_structure->callbacks.read_datarate(fhss_structure->fhss_api); @@ -778,10 +782,11 @@ static int fhss_handle_state_set(fhss_structure_t *fhss_structure, fhss_states f fhss_start_timer(fhss_structure, fhss_structure->synch_configuration.fhss_superframe_length, fhss_superframe_handler); } else { tr_error("Synch info not found"); - return -1; + return; } } - return 0; + fhss_structure->fhss_state = fhss_state; + return; } static void fhss_destroy_scramble_table(fhss_structure_t *fhss_structure) @@ -914,6 +919,42 @@ static void fhss_update_channel_callback(fhss_structure_t *fhss_structure) } } +static int16_t fhss_write_synch_info_callback(const fhss_api_t *api, uint8_t *info_ptr, int info_type, int frame_type_id, uint32_t tx_time) +{ + fhss_structure_t *fhss_structure = fhss_get_object_with_api(api); + (void) frame_type_id; + (void) tx_time; + if (!fhss_structure) { + return -1; + } + if (info_type == FHSS_PLAIN_SYNCH_INFO) { + if (!info_ptr) { + return -1; + } + fhss_beacon_build(fhss_structure, info_ptr); + return FHSS_SYNCH_INFO_LENGTH; + } + return -1; +} + +static void fhss_data_tx_done_callback(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle) +{ + fhss_structure_t *fhss_structure = fhss_get_object_with_api(api); + if (!fhss_structure) { + return; + } + if (waiting_ack == false) { + fhss_change_to_rx_channel(fhss_structure); + } + // Buffer was successfully transmitted. Remove stored failure handle if exists. + if (tx_completed == true) { + fhss_failed_tx_t *fhss_failed_tx = fhss_failed_handle_find(fhss_structure, handle); + if (fhss_failed_tx) { + fhss_failed_handle_remove(fhss_structure, handle); + } + } +} + int fhss_set_callbacks(fhss_structure_t *fhss_structure) { // Set external API @@ -922,17 +963,16 @@ int fhss_set_callbacks(fhss_structure_t *fhss_structure) fhss_structure->fhss_api->tx_handle = &fhss_tx_handle_callback; fhss_structure->fhss_api->check_tx_conditions = &fhss_check_tx_conditions_callback; fhss_structure->fhss_api->receive_frame = &fhss_receive_frame_cb; - fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb; + fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_callback; fhss_structure->fhss_api->data_tx_fail = &fhss_data_tx_fail_cb; - fhss_structure->fhss_api->synch_state_set = &fhss_synch_state_set_cb; + fhss_structure->fhss_api->synch_state_set = &fhss_handle_state_set; fhss_structure->fhss_api->read_timestamp = &fhss_read_timestamp_cb; fhss_structure->fhss_api->get_retry_period = &fhss_get_retry_period_cb; - fhss_structure->fhss_api->write_synch_info = &fhss_write_synch_info_cb; + fhss_structure->fhss_api->write_synch_info = &fhss_write_synch_info_callback; fhss_structure->fhss_api->init_callbacks = &fhss_init_callbacks_cb; // Set internal API fhss_structure->update_channel = fhss_update_channel_callback; fhss_structure->update_superframe = fhss_superframe_callback; fhss_structure->read_superframe_timeout = fhss_get_sf_timeout_callback; - fhss_structure->handle_state_set = fhss_handle_state_set; return 0; } diff --git a/source/Service_Libs/fhss/fhss_common.c b/source/Service_Libs/fhss/fhss_common.c index aba524fa2ef..b9fac8fbf61 100644 --- a/source/Service_Libs/fhss/fhss_common.c +++ b/source/Service_Libs/fhss/fhss_common.c @@ -152,7 +152,7 @@ int8_t fhss_disable(fhss_structure_t *fhss_structure) if (!fhss_structure) { return -1; } - fhss_structure->handle_state_set(fhss_structure, FHSS_UNSYNCHRONIZED, 0); + fhss_structure->fhss_api->synch_state_set(fhss_structure->fhss_api, FHSS_UNSYNCHRONIZED, 0); ns_dyn_mem_free(fhss_structure->ws); ns_dyn_mem_free(fhss_structure); fhss_structure = 0; diff --git a/source/Service_Libs/fhss/fhss_common.h b/source/Service_Libs/fhss/fhss_common.h index b7f06b2da0d..89f85e3918e 100644 --- a/source/Service_Libs/fhss/fhss_common.h +++ b/source/Service_Libs/fhss/fhss_common.h @@ -43,15 +43,6 @@ typedef void fhss_update_superframe_cb(fhss_structure_t *fhss_structure); */ typedef uint32_t fhss_read_superframe_timeout_cb(fhss_structure_t *fhss_structure); -/** - * @brief Set FHSS state. - * @param fhss_structure FHSS structure. - * @param fhss_state FHSS state to set. - * @param pan_id Network PAN id. - * @return 0 Success, -1 Failure. - */ -typedef int fhss_handle_state_set_cb(fhss_structure_t *fhss_structure, fhss_states fhss_state, uint16_t pan_id); - union fhss_conf { fhss_configuration_t fhss_configuration; fhss_ws_configuration_t fhss_ws_configuration; @@ -121,7 +112,6 @@ struct fhss_structure fhss_update_channel_cb *update_channel; /**< Update listening channel */ fhss_update_superframe_cb *update_superframe; /**< Update superframe */ fhss_read_superframe_timeout_cb *read_superframe_timeout; /**< Read next FHSS superframe timeout length */ - fhss_handle_state_set_cb *handle_state_set; /**< Set FHSS state */ }; fhss_structure_t *fhss_allocate_instance(fhss_api_t *fhss_api, const fhss_timer_t *fhss_timer); diff --git a/source/Service_Libs/fhss/fhss_mac_interface.c b/source/Service_Libs/fhss/fhss_mac_interface.c index 55792e69ef2..5af65895c3b 100644 --- a/source/Service_Libs/fhss/fhss_mac_interface.c +++ b/source/Service_Libs/fhss/fhss_mac_interface.c @@ -89,24 +89,6 @@ void fhss_receive_frame_cb(const fhss_api_t *api, uint16_t pan_id, uint8_t *sour } } -void fhss_data_tx_done_cb(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle) -{ - fhss_structure_t *fhss_structure = fhss_get_object_with_api(api); - if (!fhss_structure) { - return; - } - if (waiting_ack == false) { - fhss_change_to_rx_channel(fhss_structure); - } - // Buffer was successfully transmitted. Remove stored failure handle if exists. - if (tx_completed == true) { - fhss_failed_tx_t *fhss_failed_tx = fhss_failed_handle_find(fhss_structure, handle); - if (fhss_failed_tx) { - fhss_failed_handle_remove(fhss_structure, handle); - } - } -} - bool fhss_data_tx_fail_cb(const fhss_api_t *api, uint8_t handle, int frame_type) { fhss_structure_t *fhss_structure = fhss_get_object_with_api(api); @@ -141,18 +123,6 @@ bool fhss_data_tx_fail_cb(const fhss_api_t *api, uint8_t handle, int frame_type) return true; } -void fhss_synch_state_set_cb(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id) -{ - fhss_structure_t *fhss_structure = fhss_get_object_with_api(api); - if (!fhss_structure) { - return; - } - if (fhss_structure->handle_state_set) { - fhss_structure->handle_state_set(fhss_structure, fhss_state, pan_id); - } - fhss_structure->fhss_state = fhss_state; -} - uint32_t fhss_read_timestamp_cb(const fhss_api_t *api) { fhss_structure_t *fhss_structure = fhss_get_object_with_api(api); @@ -205,24 +175,6 @@ uint16_t fhss_get_retry_period_cb(const fhss_api_t *api, uint8_t *destination_ad return retry_period; } -int16_t fhss_write_synch_info_cb(const fhss_api_t *api, uint8_t *info_ptr, int info_type, int frame_type_id, uint32_t tx_time) -{ - fhss_structure_t *fhss_structure = fhss_get_object_with_api(api); - (void) frame_type_id; - (void) tx_time; - if (!fhss_structure) { - return -1; - } - if (info_type == FHSS_PLAIN_SYNCH_INFO) { - if (!info_ptr) { - return -1; - } - fhss_beacon_build(fhss_structure, info_ptr); - return FHSS_SYNCH_INFO_LENGTH; - } - return -1; -} - int fhss_init_callbacks_cb(const fhss_api_t *api, fhss_callback_t *callbacks) { diff --git a/source/Service_Libs/fhss/fhss_mac_interface.h b/source/Service_Libs/fhss/fhss_mac_interface.h index 97cd47bd17c..691cdb7a1b1 100644 --- a/source/Service_Libs/fhss/fhss_mac_interface.h +++ b/source/Service_Libs/fhss/fhss_mac_interface.h @@ -21,12 +21,9 @@ bool fhss_is_broadcast_channel_cb(const fhss_api_t *api); bool fhss_use_broadcast_queue_cb(const fhss_api_t *api, bool is_broadcast_addr, int frame_type); void fhss_receive_frame_cb(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(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle); bool fhss_data_tx_fail_cb(const fhss_api_t *api, uint8_t handle, int frame_type); -void fhss_synch_state_set_cb(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id); uint32_t fhss_read_timestamp_cb(const fhss_api_t *api); uint16_t fhss_get_retry_period_cb(const fhss_api_t *api, uint8_t *destination_address, uint16_t phy_mtu); -int16_t fhss_write_synch_info_cb(const fhss_api_t *api, uint8_t *info_ptr, int info_type, int frame_type_id, uint32_t tx_time); int fhss_init_callbacks_cb(const fhss_api_t *api, fhss_callback_t *callbacks); #endif /* FHSS_MAC_INTERFACE_H_ */ diff --git a/source/Service_Libs/fhss/fhss_ws.c b/source/Service_Libs/fhss/fhss_ws.c index b48e63022cb..fbfba173547 100644 --- a/source/Service_Libs/fhss/fhss_ws.c +++ b/source/Service_Libs/fhss/fhss_ws.c @@ -153,9 +153,13 @@ static uint32_t fhss_ws_get_sf_timeout_callback(fhss_structure_t *fhss_structure return fhss_structure->fhss_conf.fhss_ws_configuration.fhss_uc_dwell_interval * 1000; } -static int fhss_ws_handle_state_set(fhss_structure_t *fhss_structure, fhss_states fhss_state, uint16_t pan_id) +static void fhss_ws_handle_state_set(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id) { (void) pan_id; + fhss_structure_t *fhss_structure = fhss_get_object_with_api(api); + if (!fhss_structure) { + return; + } if (fhss_state == FHSS_SYNCHRONIZED) { uint32_t fhss_broadcast_interval = fhss_structure->fhss_conf.fhss_ws_configuration.fhss_broadcast_interval; uint8_t fhss_bc_dwell_interval = fhss_structure->fhss_conf.fhss_ws_configuration.fhss_bc_dwell_interval; @@ -169,7 +173,7 @@ static int fhss_ws_handle_state_set(fhss_structure_t *fhss_structure, fhss_state } fhss_structure->fhss_state = fhss_state; - return 0; + return; } static void fhss_ws_superframe_callback(fhss_structure_t *fhss_structure) @@ -216,6 +220,9 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a if (!fhss_structure) { return -1; } + if (is_broadcast_addr) { + return 0; + } if (fhss_structure->fhss_state == FHSS_SYNCHRONIZED) { int32_t tx_channel; //TODO: Get destination UFSI, timestamp and dwell time from neighbour table @@ -247,6 +254,31 @@ static bool fhss_ws_check_tx_conditions_callback(const fhss_api_t *api, bool is_ return true; } +static int16_t fhss_ws_write_synch_info_callback(const fhss_api_t *api, uint8_t *info_ptr, int info_type, int frame_type_id, uint32_t tx_time) +{ + fhss_structure_t *fhss_structure = fhss_get_object_with_api(api); + (void) frame_type_id; + (void) tx_time; + (void) info_ptr; + (void) info_type; + if (!fhss_structure) { + return -1; + } + + return -1; +} + +static void fhss_ws_data_tx_done_callback(const fhss_api_t *api, bool waiting_ack, bool tx_completed, uint8_t handle) +{ + (void) waiting_ack; + (void) tx_completed; + (void) handle; + fhss_structure_t *fhss_structure = fhss_get_object_with_api(api); + if (!fhss_structure) { + return; + } +} + int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure) { // Set external API @@ -255,18 +287,17 @@ int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure) fhss_structure->fhss_api->tx_handle = &fhss_ws_tx_handle_callback; fhss_structure->fhss_api->check_tx_conditions = &fhss_ws_check_tx_conditions_callback; fhss_structure->fhss_api->receive_frame = &fhss_receive_frame_cb; - fhss_structure->fhss_api->data_tx_done = &fhss_data_tx_done_cb; + fhss_structure->fhss_api->data_tx_done = &fhss_ws_data_tx_done_callback; fhss_structure->fhss_api->data_tx_fail = &fhss_data_tx_fail_cb; - fhss_structure->fhss_api->synch_state_set = &fhss_synch_state_set_cb; + fhss_structure->fhss_api->synch_state_set = &fhss_ws_handle_state_set; fhss_structure->fhss_api->read_timestamp = &fhss_read_timestamp_cb; fhss_structure->fhss_api->get_retry_period = &fhss_get_retry_period_cb; - fhss_structure->fhss_api->write_synch_info = &fhss_write_synch_info_cb; + fhss_structure->fhss_api->write_synch_info = &fhss_ws_write_synch_info_callback; fhss_structure->fhss_api->init_callbacks = &fhss_init_callbacks_cb; // Set internal API fhss_structure->update_channel = fhss_ws_update_uc_channel_callback; fhss_structure->update_superframe = fhss_ws_superframe_callback; fhss_structure->read_superframe_timeout = fhss_ws_get_sf_timeout_callback; - fhss_structure->handle_state_set = fhss_ws_handle_state_set; fhss_structure->ws = ns_dyn_mem_alloc(sizeof(fhss_ws_t)); if (!fhss_structure->ws) { return -1; diff --git a/test/nanostack/unittest/service_libs/fhss_mac_interface/fhssmaciftest.cpp b/test/nanostack/unittest/service_libs/fhss_mac_interface/fhssmaciftest.cpp index 0c24399838e..8fe488b5cee 100644 --- a/test/nanostack/unittest/service_libs/fhss_mac_interface/fhssmaciftest.cpp +++ b/test/nanostack/unittest/service_libs/fhss_mac_interface/fhssmaciftest.cpp @@ -44,21 +44,11 @@ TEST(fhss_mac_if, test_fhss_receive_frame_cb) CHECK(test_fhss_receive_frame_cb()); } -TEST(fhss_mac_if, test_fhss_data_tx_done_cb) -{ - CHECK(test_fhss_data_tx_done_cb()); -} - TEST(fhss_mac_if, test_fhss_data_tx_fail_cb) { CHECK(test_fhss_data_tx_fail_cb()); } -TEST(fhss_mac_if, test_fhss_synch_state_set_cb) -{ - CHECK(test_fhss_synch_state_set_cb()); -} - TEST(fhss_mac_if, test_fhss_read_timestamp_cb) { CHECK(test_fhss_read_timestamp_cb()); diff --git a/test/nanostack/unittest/service_libs/fhss_mac_interface/test_fhss_mac_interface.c b/test/nanostack/unittest/service_libs/fhss_mac_interface/test_fhss_mac_interface.c index 16e7aeefe23..b410372f176 100644 --- a/test/nanostack/unittest/service_libs/fhss_mac_interface/test_fhss_mac_interface.c +++ b/test/nanostack/unittest/service_libs/fhss_mac_interface/test_fhss_mac_interface.c @@ -119,29 +119,12 @@ bool test_fhss_receive_frame_cb() return true; } -bool test_fhss_data_tx_done_cb() -{ - fhss_api_t fhss_api; - // By setting bool value false, fhss_struct can not be found - fhss_stub.bool_value = false; - fhss_data_tx_done_cb(&fhss_api, true, true, 0); - // By setting bool value true, fhss_struct can be found - fhss_stub.bool_value = true; - fhss_data_tx_done_cb(&fhss_api, false, true, 0); - // Should find failed TX handle - fhss_stub.fhss_failed_tx.handle = 10; - fhss_data_tx_done_cb(&fhss_api, false, true, 10); - // Verify removed handle (255 means removed in this test) - if (fhss_stub.fhss_failed_tx.handle != 255) { - return false; - } - return true; -} bool test_fhss_data_tx_fail_cb() { fhss_api_t fhss_api; uint8_t handle = 1; + fhss_stub.fhss_struct.fhss_state = FHSS_SYNCHRONIZED; // By setting bool value false, fhss_struct can not be found fhss_stub.bool_value = false; @@ -176,44 +159,6 @@ bool test_fhss_data_tx_fail_cb() return true; } -bool test_fhss_synch_state_set_cb() -{ - uint16_t panid = 0xacdc; - fhss_api_t fhss_api; - fhss_timer_t platform_functions; - fhss_stub.fhss_struct.callbacks.read_datarate = mac_read_phy_datarate; - fhss_stub.fhss_struct.callbacks.read_mac_address = mac_read_64bit_mac_address; - fhss_stub.fhss_struct.synch_panid = 0; - fhss_stub.fhss_struct.own_hop = 1; - platform_functions.fhss_get_timestamp = fhss_get_timestamp_stub; - fhss_stub.fhss_struct.platform_functions = platform_functions; - fhss_api.read_timestamp = fhss_read_timestamp_cb; - - // By setting bool value false, fhss_struct can not be found - fhss_stub.bool_value = false; - fhss_synch_state_set_cb(&fhss_api, FHSS_UNSYNCHRONIZED, 0); - // By setting bool value true, fhss_struct can be found - fhss_stub.bool_value = true; - // Test setting current state again - fhss_stub.fhss_struct.fhss_state = FHSS_SYNCHRONIZED; - fhss_synch_state_set_cb(&fhss_api, FHSS_SYNCHRONIZED, 0); - // Test setting unsynchronized state - fhss_synch_state_set_cb(&fhss_api, FHSS_UNSYNCHRONIZED, 0); - // Test setting synchronized state - fhss_stub.fhss_struct.fhss_state = FHSS_UNSYNCHRONIZED; - fhss_synch_state_set_cb(&fhss_api, FHSS_SYNCHRONIZED, 0); - // Test finding beacon info - fhss_stub.beacon_info.pan_id = panid; - fhss_synch_state_set_cb(&fhss_api, FHSS_SYNCHRONIZED, panid); - // Test if device is synch root - fhss_stub.fhss_struct.own_hop = 0; - fhss_stub.fhss_struct.synch_panid = 0; - fhss_stub.beacon_info.pan_id = 1; - fhss_stub.fhss_struct.fhss_state = FHSS_UNSYNCHRONIZED; - fhss_synch_state_set_cb(&fhss_api, FHSS_SYNCHRONIZED, panid); - - return true; -} bool test_fhss_read_timestamp_cb() { fhss_api_t fhss_api; diff --git a/test/nanostack/unittest/service_libs/fhss_mac_interface/test_fhss_mac_interface.h b/test/nanostack/unittest/service_libs/fhss_mac_interface/test_fhss_mac_interface.h index 6ce80a75f70..7b2ba5259fa 100644 --- a/test/nanostack/unittest/service_libs/fhss_mac_interface/test_fhss_mac_interface.h +++ b/test/nanostack/unittest/service_libs/fhss_mac_interface/test_fhss_mac_interface.h @@ -28,8 +28,6 @@ bool test_fhss_is_broadcast_channel_cb(); bool test_fhss_use_broadcast_queue_cb(); // Test frame receive callback bool test_fhss_receive_frame_cb(); -// Test TX done callback -bool test_fhss_data_tx_done_cb(); // Test TX fail callback bool test_fhss_data_tx_fail_cb(); // Test state set callback diff --git a/test/nanostack/unittest/stub/fhss_stub.c b/test/nanostack/unittest/stub/fhss_stub.c index 5fc27412f4b..13b07fc6878 100644 --- a/test/nanostack/unittest/stub/fhss_stub.c +++ b/test/nanostack/unittest/stub/fhss_stub.c @@ -190,7 +190,7 @@ int fhss_generate_scramble_table(fhss_structure_t *fhss_structure) return 0; } -int fhss_handle_state_set(fhss_structure_t *fhss_structure, fhss_states fhss_state, uint16_t pan_id) +int fhss_handle_state_set(const fhss_api_t *api, fhss_states fhss_state, uint16_t pan_id) { return 0; }