Skip to content

Commit

Permalink
Merge pull request ARMmbed#1670 from ARMmbed/IOTTHD-2449
Browse files Browse the repository at this point in the history
FHSS: support FHSS created by application
  • Loading branch information
Jarkko Paso authored Apr 23, 2018
2 parents 67f578a + 82a8bca commit 5974344
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 30 deletions.
11 changes: 0 additions & 11 deletions nanostack/fhss_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,6 @@ typedef struct fhss_configuration
*/
typedef int32_t fhss_vendor_defined_cf(const fhss_api_t *api, uint16_t slot, uint8_t eui64[8], uint16_t bsi, uint16_t number_of_channels);

/**
* @brief Get neighbor timing/hopping schedule.
* @param api FHSS instance.
* @param eui64 EUI-64 address of node for which the info is requested.
* @return Neighbor timing/hopping schedule.
*/
typedef fhss_ws_neighbor_timing_info_t *fhss_get_neighbor_info(const fhss_api_t *api, uint8_t eui64[8]);

/**
* \brief Struct fhss_ws_configuration defines configuration of WS FHSS.
*/
Expand All @@ -125,9 +117,6 @@ typedef struct fhss_ws_configuration
/** Vendor defined channel function. */
fhss_vendor_defined_cf *vendor_defined_cf;

/** Get neighbor timing/hopping schedule. */
fhss_get_neighbor_info *get_neighbor_info;

} fhss_ws_configuration_t;

/**
Expand Down
17 changes: 17 additions & 0 deletions nanostack/fhss_ws_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ typedef struct fhss_ws_neighbor_timing_info {
uint32_t *excluded_channels; /**< Neighbor excluded channels (bit mask) */
} fhss_ws_neighbor_timing_info_t;

/**
* @brief Get neighbor timing/hopping schedule.
* @param api FHSS instance.
* @param eui64 EUI-64 address of node for which the info is requested.
* @return Neighbor timing/hopping schedule.
*/
typedef fhss_ws_neighbor_timing_info_t *fhss_get_neighbor_info(const fhss_api_t *api, uint8_t eui64[8]);

/**
* @brief Set parent which broadcast channels must be listened by FHSS.
* @param fhss_api FHSS instance.
Expand All @@ -82,6 +90,15 @@ extern int ns_fhss_ws_set_parent(const fhss_api_t *fhss_api, const uint8_t eui64
*/
extern int ns_fhss_ws_remove_parent(const fhss_api_t *fhss_api, const uint8_t eui64[8]);

/**
* @brief Set neighbor timing/hopping schedule request function.
* @param fhss_api FHSS instance.
* @param get_neighbor_info Neighbor info function pointer.
* @return 0 on success, -1 on fail.
*/
extern int ns_fhss_set_neighbor_info_fp(const fhss_api_t *fhss_api, fhss_get_neighbor_info *get_neighbor_info);


#ifdef __cplusplus
}
#endif
Expand Down
7 changes: 7 additions & 0 deletions nanostack/net_fhss.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ extern fhss_api_t *ns_fhss_ws_create(const fhss_ws_configuration_t *fhss_configu
*/
extern int ns_fhss_configuration_set(fhss_api_t *fhss_api, const fhss_synch_configuration_t *fhss_synch_configuration);

/**
* @brief Get WS configuration.
* @param fhss_api FHSS instance.
* @return WS configuration.
*/
extern const fhss_ws_configuration_t *ns_fhss_ws_configuration_get(const fhss_api_t *fhss_api);

/**
* @brief Deletes a FHSS API instance and removes it from software MAC.
* @param fhss_api FHSS instance.
Expand Down
7 changes: 7 additions & 0 deletions nanostack/sw_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ extern int8_t ns_sw_mac_virtual_client_unregister(struct mac_api_s *api);
*/
extern int ns_sw_mac_fhss_register(struct mac_api_s *mac_api, struct fhss_api *fhss_api);

/**
* @brief Request registered FHSS API instance from software MAC instance.
* @param mac_api MAC instance.
* @return FHSS api.
*/
extern struct fhss_api *ns_sw_mac_get_fhss_api(struct mac_api_s *mac_api);

/**
* @brief Start collecting statistics from software MAC.
* @param mac_api MAC instance.
Expand Down
48 changes: 33 additions & 15 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,22 +179,41 @@ static fhss_ws_neighbor_timing_info_t *ws_get_neighbor_info(const fhss_api_t *ap

static int8_t ws_enable_fhss(protocol_interface_info_entry_t *cur)
{
fhss_ws_configuration_t fhss_configuration;
memset(&fhss_configuration, 0, sizeof(fhss_ws_configuration_t));
fhss_configuration.bsi = cur->ws_info->hopping_schdule.fhss_bsi;
memcpy(fhss_configuration.channel_mask, cur->ws_info->hopping_schdule.channel_mask, sizeof(uint32_t) * 8);
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
fhss_configuration.fhss_bc_dwell_interval = cur->ws_info->hopping_schdule.fhss_bc_dwell_interval;
fhss_configuration.fhss_broadcast_interval = cur->ws_info->hopping_schdule.fhss_broadcast_interval;
}
fhss_configuration.fhss_uc_dwell_interval = cur->ws_info->hopping_schdule.fhss_uc_dwell_interval;
fhss_configuration.get_neighbor_info = &ws_get_neighbor_info;
fhss_configuration.ws_channel_function = cur->ws_info->hopping_schdule.channel_function;
fhss_api_t *fhss_api = ns_fhss_ws_create(&fhss_configuration, cur->ws_info->fhss_timer_ptr);
if (fhss_api) {
fhss_api_t *fhss_api = ns_sw_mac_get_fhss_api(cur->mac_api);
if (!fhss_api) {
// When FHSS doesn't exist yet, create one
fhss_ws_configuration_t fhss_configuration;
memset(&fhss_configuration, 0, sizeof(fhss_ws_configuration_t));
fhss_configuration.bsi = cur->ws_info->hopping_schdule.fhss_bsi;
memcpy(fhss_configuration.channel_mask, cur->ws_info->hopping_schdule.channel_mask, sizeof(uint32_t) * 8);
fhss_configuration.fhss_uc_dwell_interval = cur->ws_info->hopping_schdule.fhss_uc_dwell_interval;
fhss_configuration.ws_channel_function = cur->ws_info->hopping_schdule.channel_function;
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
fhss_configuration.fhss_bc_dwell_interval = cur->ws_info->hopping_schdule.fhss_bc_dwell_interval;
fhss_configuration.fhss_broadcast_interval = cur->ws_info->hopping_schdule.fhss_broadcast_interval;
}
fhss_api = ns_fhss_ws_create(&fhss_configuration, cur->ws_info->fhss_timer_ptr);
if (!fhss_api) {
return -1;
}
ns_sw_mac_fhss_register(cur->mac_api, fhss_api);
cur->ws_info->fhss_api = fhss_api;
} else {
// Read configuration of existing FHSS
const fhss_ws_configuration_t *fhss_configuration = ns_fhss_ws_configuration_get(fhss_api);
if (!fhss_configuration) {
return -1;
}
memcpy(cur->ws_info->hopping_schdule.channel_mask, fhss_configuration->channel_mask, sizeof(uint32_t) * 8);
cur->ws_info->hopping_schdule.channel_function = fhss_configuration->ws_channel_function;
cur->ws_info->hopping_schdule.fhss_bc_dwell_interval = fhss_configuration->fhss_bc_dwell_interval;
cur->ws_info->hopping_schdule.fhss_broadcast_interval = fhss_configuration->fhss_broadcast_interval;
cur->ws_info->hopping_schdule.fhss_uc_dwell_interval = fhss_configuration->fhss_uc_dwell_interval;
}
// Set neighbor info callback
if (ns_fhss_set_neighbor_info_fp(fhss_api, &ws_get_neighbor_info)) {
return -1;
}
cur->ws_info->fhss_api = fhss_api;
return 0;
}

Expand Down Expand Up @@ -1230,7 +1249,6 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
cur->ws_info->pan_information.rpl_routing_method = true;
cur->ws_info->pan_information.use_parent_bs = true;
cur->ws_info->pan_information.version = WS_FAN_VERSION_1_0;
cur->ws_info->hopping_schdule.channel_function = WS_FIXED_CHANNEL;
ws_llc_set_gtkhash(cur, cur->ws_info->gtkhash);
cur->ws_info->pan_version_timer = PAN_VERSION_LIFETIME;
ws_bootstrap_fhss_activate(cur);
Expand Down
12 changes: 12 additions & 0 deletions source/MAC/IEEE802_15_4/sw_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ int ns_sw_mac_fhss_register(mac_api_t *mac_api, fhss_api_t *fhss_api)
return 0;
}

struct fhss_api *ns_sw_mac_get_fhss_api(struct mac_api_s *mac_api)
{
if (!mac_api) {
return NULL;
}
protocol_interface_rf_mac_setup_s *mac_setup = get_sw_mac_ptr_by_mac_api(mac_api);
if (!mac_setup) {
return NULL;
}
return mac_setup->fhss_api;
}

int ns_sw_mac_statistics_start(struct mac_api_s *mac_api, struct mac_statistics_s *mac_statistics)
{
if (!mac_api || !mac_statistics) {
Expand Down
19 changes: 19 additions & 0 deletions source/Service_Libs/fhss/fhss_configuration_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,22 @@ int ns_fhss_configuration_set(fhss_api_t *fhss_api, const fhss_synch_configurati
}
return fhss_set_synch_configuration(fhss_structure, fhss_synch_configuration);
}

int ns_fhss_set_neighbor_info_fp(const fhss_api_t *fhss_api, fhss_get_neighbor_info *get_neighbor_info)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(fhss_api);
if (!fhss_structure || !fhss_structure->ws) {
return -1;
}
fhss_structure->ws->get_neighbor_info = get_neighbor_info;
return 0;
}

const fhss_ws_configuration_t *ns_fhss_ws_configuration_get(const fhss_api_t *fhss_api)
{
fhss_structure_t *fhss_structure = fhss_get_object_with_api(fhss_api);
if (!fhss_structure || !fhss_structure->ws) {
return NULL;
}
return &fhss_structure->ws->fhss_configuration;
}
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 @@ -264,7 +264,7 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
return 0;
}
if (fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
fhss_ws_neighbor_timing_info_t *neighbor_timing_info = fhss_structure->ws->fhss_configuration.get_neighbor_info(api, destination_address);
fhss_ws_neighbor_timing_info_t *neighbor_timing_info = fhss_structure->ws->get_neighbor_info(api, destination_address);
if (!neighbor_timing_info) {
tr_err("FHSS: No neighbor info: %s", trace_array(destination_address, 8));
return -2;
Expand Down
1 change: 1 addition & 0 deletions source/Service_Libs/fhss/fhss_ws.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct fhss_ws
bool is_on_bc_channel;
struct fhss_ws_configuration fhss_configuration;
const struct broadcast_timing_info *parent_bc_info;
fhss_get_neighbor_info *get_neighbor_info;
};

fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configuration_t *fhss_configuration, const fhss_timer_t *fhss_timer);
Expand Down
6 changes: 3 additions & 3 deletions test/nanostack/unittest/service_libs/fhss_ws/test_fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static fhss_api_t *test_generate_fhss_api(void)
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_uc_dwell_interval = 200;
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_bc_dwell_interval = 250;
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_broadcast_interval = 1000;
fhss_common_stub.fhss_struct.ws->fhss_configuration.get_neighbor_info = &app_get_neighbor_info;
fhss_common_stub.fhss_struct.ws->get_neighbor_info = &app_get_neighbor_info;
fhss_common_stub.fhss_struct.number_of_channels = 50;
fhss_common_stub.fhss_struct.rx_channel = DEFAULT_CHANNEL;
fhss_common_stub.fhss_struct.fhss_state = FHSS_UNSYNCHRONIZED;
Expand Down Expand Up @@ -220,12 +220,12 @@ bool test_fhss_ws_tx_handle_callback()
neighbor_info.uc_timing_info.unicast_channel_function = WS_TR51CF;
neighbor_info.uc_timing_info.unicast_number_of_channels = fhss_common_stub.fhss_struct.number_of_channels;
fhss_common_stub.fhss_struct.fhss_state = DEFAULT_FHSS_STATE;
fhss_common_stub.fhss_struct.ws->fhss_configuration.get_neighbor_info = &app_no_neighbor_info;
fhss_common_stub.fhss_struct.ws->get_neighbor_info = &app_no_neighbor_info;
if (fhss_common_stub.fhss_struct.fhss_api->tx_handle(api, DEFAULT_IS_BC_DEST, dest_address, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH, DEFAULT_TX_TIME) != -2) {
return false;
}
// Test fixed channel
fhss_common_stub.fhss_struct.ws->fhss_configuration.get_neighbor_info = &app_get_neighbor_info;
fhss_common_stub.fhss_struct.ws->get_neighbor_info = &app_get_neighbor_info;
neighbor_info.uc_timing_info.unicast_channel_function = WS_FIXED_CHANNEL;
if (fhss_common_stub.fhss_struct.fhss_api->tx_handle(api, DEFAULT_IS_BC_DEST, dest_address, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH, DEFAULT_TX_TIME) != 0) {
return false;
Expand Down

0 comments on commit 5974344

Please sign in to comment.