Skip to content

Commit

Permalink
Updated management api
Browse files Browse the repository at this point in the history
Switch discovery to use Fixed channel
when starting discovery start using fixed channel
When configuration is learned switch to default configuration

added channel mask set function to modify individual channel from mask
  • Loading branch information
Mika Tervonen committed Aug 21, 2018
1 parent f52289f commit 1a09af7
Show file tree
Hide file tree
Showing 13 changed files with 236 additions and 65 deletions.
71 changes: 47 additions & 24 deletions nanostack/ws_management_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,38 @@ extern "C" {
#endif

/* Regulatory domain values*/
#define REG_DOMAIN_WW 0x00 // World wide
#define REG_DOMAIN_NA 0x01 // North America
#define REG_DOMAIN_JP 0x02 // Japan
#define REG_DOMAIN_EU 0x03 // European Union
#define REG_DOMAIN_CH 0x04 // China
#define REG_DOMAIN_IN 0x05 // India
#define REG_DOMAIN_MX 0x06 //
#define REG_DOMAIN_BZ 0x07 // Brazil
#define REG_DOMAIN_AZ 0x08 // Australia
#define REG_DOMAIN_NZ 0x08 // New zealand
#define REG_DOMAIN_KR 0x09 // Korea
#define REG_DOMAIN_PH 0x0A //
#define REG_DOMAIN_MY 0x0B //
#define REG_DOMAIN_WW 0x00 // World wide
#define REG_DOMAIN_NA 0x01 // North America
#define REG_DOMAIN_JP 0x02 // Japan
#define REG_DOMAIN_EU 0x03 // European Union
#define REG_DOMAIN_CH 0x04 // China
#define REG_DOMAIN_IN 0x05 // India
#define REG_DOMAIN_MX 0x06 //
#define REG_DOMAIN_BZ 0x07 // Brazil
#define REG_DOMAIN_AZ 0x08 // Australia
#define REG_DOMAIN_NZ 0x08 // New zealand
#define REG_DOMAIN_KR 0x09 // Korea
#define REG_DOMAIN_PH 0x0A //
#define REG_DOMAIN_MY 0x0B //
#define REG_DOMAIN_HK 0x0C //
#define REG_DOMAIN_SG 0x0D // band 866-869
#define REG_DOMAIN_TH 0x0E //
#define REG_DOMAIN_VN 0x0F //
#define REG_DOMAIN_SG_H 0x10 // band 920-925

#define OPERATING_MODE_1a 0x01
#define OPERATING_MODE_1b 0x02
#define OPERATING_MODE_2a 0x03
#define OPERATING_MODE_2b 0x04
#define OPERATING_MODE_3 0x05
#define OPERATING_MODE_4a 0x06
#define OPERATING_MODE_4b 0x07
#define OPERATING_MODE_5 0x08
#define OPERATING_MODE_1a 0x1a
#define OPERATING_MODE_1b 0x1b
#define OPERATING_MODE_2a 0x2a
#define OPERATING_MODE_2b 0x2b
#define OPERATING_MODE_3 0x03
#define OPERATING_MODE_4a 0x4a
#define OPERATING_MODE_4b 0x4b
#define OPERATING_MODE_5 0x05

#define CHANNEL_FUNCTION_FIXED 0x00 // Fixed channel
#define CHANNEL_FUNCTION_TR51CF 0x01 // TR51CF
#define CHANNEL_FUNCTION_DIRECT_HASH 0x02 // Direct Hash
#define CHANNEL_FUNCTION_FIXED 0x00 // Fixed channel
#define CHANNEL_FUNCTION_TR51CF 0x01 // TR51CF
#define CHANNEL_FUNCTION_DH1CF 0x02 // Direct Hash
#define CHANNEL_FUNCTION_VENDOR_DEFINED 0x03 // Direct Hash

#define CHANNEL_SPACING_200 0x00 // 200 khz
#define CHANNEL_SPACING_400 0x01 // 400 khz
Expand Down Expand Up @@ -169,4 +175,21 @@ int ws_management_fhss_timing_configure(
uint32_t fhss_broadcast_interval,
uint8_t fhss_bc_dwell_interval);

/**
* Configure channel function.
*
* Change the default configuration for Wi-SUN FHSS operation.
* This will use randomized value for fixed channel if used.
* if application defined is used the behaviour is undefined
*
* \param interface_id Network interface ID.
* \param channel_function channel
*
* \return 0, Init OK.
* \return <0 Init fail.
*/
int ws_management_fhss_channel_function_configure(
int8_t interface_id,
uint8_t channel_function);

#endif /* WS_MANAGEMENT_API_H_ */
82 changes: 53 additions & 29 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "Common_Protocols/ipv6_constants.h"
#include "6LoWPAN/ws/ws_common_defines.h"
#include "Service_Libs/Trickle/trickle.h"
#include "Service_Libs/fhss/channel_list.h"
#include "6LoWPAN/ws/ws_common_defines.h"
#include "6LoWPAN/ws/ws_llc.h"
#include "6LoWPAN/ws/ws_neighbor_class.h"
Expand Down Expand Up @@ -249,26 +250,45 @@ static int8_t ws_fhss_set_defaults(protocol_interface_info_entry_t *cur)

return 0;
}
static int8_t ws_fhss_discovery_configure(protocol_interface_info_entry_t *cur)
{
// Read configuration of existing FHSS and start using the default values for any network
fhss_ws_configuration_t fhss_configuration = {0};
if (ns_fhss_ws_configuration_get(cur->ws_info->fhss_api)) {
memcpy(&fhss_configuration, ns_fhss_ws_configuration_get(cur->ws_info->fhss_api), sizeof(fhss_ws_configuration_t));
}

fhss_configuration.fhss_uc_dwell_interval = 0;
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);
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);

ns_fhss_ws_configuration_set(cur->ws_info->fhss_api,&fhss_configuration);
ws_bootstrap_llc_hopping_update(cur,&fhss_configuration);

return 0;
}

static int8_t ws_fhss_enable(protocol_interface_info_entry_t *cur)
{
fhss_api_t *fhss_api = ns_sw_mac_get_fhss_api(cur->mac_api);
const fhss_ws_configuration_t *fhss_configuration = ns_fhss_ws_configuration_get(fhss_api);
const fhss_ws_configuration_t *fhss_configuration = ns_fhss_ws_configuration_get(cur->ws_info->fhss_api);

if (!fhss_api || !fhss_configuration) {
if (!cur->ws_info->fhss_api || !fhss_configuration) {
return -1;
}
// Set the LLC information to follow the actual fhss settings
ws_bootstrap_llc_hopping_update(cur,fhss_configuration);

// Set neighbor info callback
if (ns_fhss_set_neighbor_info_fp(fhss_api, &ws_get_neighbor_info)) {
if (ns_fhss_set_neighbor_info_fp(cur->ws_info->fhss_api, &ws_get_neighbor_info)) {
return -1;
}
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
ns_fhss_ws_set_hop_count(fhss_api, 0);
ns_fhss_ws_set_hop_count(cur->ws_info->fhss_api, 0);
}
cur->ws_info->fhss_api = fhss_api;
return 0;
}

Expand All @@ -281,16 +301,10 @@ static void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry
fhss_ws_configuration_t fhss_configuration;
memcpy(&fhss_configuration, ns_fhss_ws_configuration_get(cur->ws_info->fhss_api), sizeof(fhss_ws_configuration_t));

// unicast information is only followed from parent if fixed channel is selected
if (neighbor_info->ws_neighbor->fhss_data.uc_timing_info.unicast_channel_function == WS_FIXED_CHANNEL) {
cur->ws_info->hopping_schdule.fixed_channel = neighbor_info->ws_neighbor->fhss_data.uc_timing_info.fixed_channel;
fhss_configuration.ws_channel_function = WS_FIXED_CHANNEL;
tr_info("attaching to fixed channel network following configurtion");
} else if (fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {
// fixed channel cannot be mixed with other channel functions as it messes the broadcast schedule
fhss_configuration.ws_channel_function = WS_DH1CF;
tr_info("attaching channel hopping network changing to hopping");
}
fhss_configuration.ws_channel_function = neighbor_info->ws_neighbor->fhss_data.uc_timing_info.unicast_channel_function;
cur->ws_info->hopping_schdule.fixed_channel = neighbor_info->ws_neighbor->fhss_data.uc_timing_info.fixed_channel;
/* Learning different unicast is not working currently at fhss network follows border router
*/
// Learn broadcast information from selected parent
fhss_configuration.bsi = neighbor_info->ws_neighbor->fhss_data.bc_timing_info.broadcast_schedule_id;
fhss_configuration.fhss_bc_dwell_interval = neighbor_info->ws_neighbor->fhss_data.bc_timing_info.broadcast_dwell_interval;
Expand Down Expand Up @@ -368,6 +382,8 @@ static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
tr_error("fhss initialization failed");
return -3;
}
// Save FHSS api
cur->ws_info->fhss_api = ns_sw_mac_get_fhss_api(cur->mac_api);

addr_interface_set_ll64(cur, NULL);
cur->nwk_nd_re_scan_count = 0;
Expand Down Expand Up @@ -715,19 +731,21 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
cur->ws_info->pan_information.pan_version = pan_version;
memcpy(cur->ws_info->gtkhash,gtkhash_ptr,32);

if (neighbor_info.neighbor->link_role == PRIORITY_PARENT_NEIGHBOUR) {
// RPL priority parent configuration we must update FHSS data
ws_bootstrap_primary_parent_set(cur, &neighbor_info);
}

if (!cur->ws_info->configuration_learned) {
// Generate own hopping schedules Follow first parent broadcast and plans and also use same unicast dwell
tr_info("learn network configuration");
cur->ws_info->configuration_learned = true;
// return to state machine after 1-2 s
cur->bootsrap_state_machine_cnt = randLIB_get_random_in_range(10 ,20);
// enable frequency hopping for unicast channel and start listening first neighbour
ws_fhss_set_defaults(cur);
ws_bootstrap_primary_parent_set(cur, &neighbor_info);
} else if (neighbor_info.neighbor->link_role == PRIORITY_PARENT_NEIGHBOUR) {
// RPL priority parent configuration we must update FHSS data
ws_bootstrap_primary_parent_set(cur, &neighbor_info);
}


}

static void ws_bootstrap_pan_config_solicit_analyse(struct protocol_interface_info_entry *cur, const struct mcps_data_ind_s *data, ws_utt_ie_t *ws_utt, ws_us_ie_t *ws_us)
Expand Down Expand Up @@ -1041,6 +1059,16 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
return ret_val;
}

int ws_bootstrap_restart(int8_t interface_id)
{
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
if (!cur || !cur->ws_info) {
return -1;
}
ws_bootstrap_event_discovery_start(cur);
return 0;
}

static void ws_bootstrap_mac_activate(protocol_interface_info_entry_t *cur, uint16_t channel, uint16_t panid, bool coordinator)
{
mlme_start_t start_req;
Expand Down Expand Up @@ -1199,14 +1227,7 @@ static void ws_bootstrap_network_discovery_configure(protocol_interface_info_ent
cur->ws_info->network_pan_id = 0xffff;

ws_common_regulatory_domain_config(cur);

// Set default schedules for discovery
cur->ws_info->hopping_schdule.fhss_uc_dwell_interval = WS_FHSS_UC_DWELL_INTERVAL;
cur->ws_info->hopping_schdule.fhss_broadcast_interval = WS_FHSS_BC_INTERVAL;
cur->ws_info->hopping_schdule.fhss_bc_dwell_interval = WS_FHSS_BC_DWELL_INTERVAL;
// By default, uses fixed channel
cur->ws_info->hopping_schdule.channel_function = WS_FIXED_CHANNEL;
cur->ws_info->hopping_schdule.fixed_channel = randLIB_get_random_in_range(11,25);
ws_fhss_discovery_configure(cur);

//Set Network names, Pan information configure, hopping schedule & GTKHash
ws_llc_set_network_name(cur, (uint8_t*)cur->ws_info->network_name, strlen(cur->ws_info->network_name));
Expand Down Expand Up @@ -1479,6 +1500,8 @@ 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->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 All @@ -1488,6 +1511,7 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
cur->ws_info->pan_information.version = WS_FAN_VERSION_1_0;
ws_llc_set_gtkhash(cur, cur->ws_info->gtkhash);
cur->ws_info->pan_version_timer = PAN_VERSION_LIFETIME;
// Set default parameters for FHSS when starting a discovery
ws_bootstrap_fhss_activate(cur);
ws_bootstrap_set_test_key(cur);
ws_bootstrap_event_operation_start(cur);
Expand Down
3 changes: 3 additions & 0 deletions source/6LoWPAN/ws/ws_bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode);

void ws_bootstrap_state_machine(protocol_interface_info_entry_t *cur);

int ws_bootstrap_restart(int8_t interface_id);

/*State machine transactions*/
void ws_bootstrap_event_discovery_start(protocol_interface_info_entry_t *cur);

Expand All @@ -56,6 +58,7 @@ void ws_bootstrap_trigle_timer(protocol_interface_info_entry_t *cur, uint16_t ti

#define ws_bootstrap_init(interface_id, bootstrap_mode) (-1)
#define ws_bootstrap_state_machine(cur)
#define ws_bootstrap_restart(cur)

#endif //HAVE_WS

Expand Down
7 changes: 0 additions & 7 deletions source/6LoWPAN/ws/ws_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,6 @@ int8_t ws_common_allocate_and_init(protocol_interface_info_entry_t *cur)
cur->ws_info->fhss_channel_mask[n] = 0xffffffff;
}

// By default, uses fixed channel
cur->ws_info->hopping_schdule.fhss_uc_dwell_interval = WS_FHSS_UC_DWELL_INTERVAL;
cur->ws_info->hopping_schdule.fhss_broadcast_interval = WS_FHSS_BC_INTERVAL;
cur->ws_info->hopping_schdule.fhss_bc_dwell_interval = WS_FHSS_BC_DWELL_INTERVAL;
cur->ws_info->hopping_schdule.channel_function = WS_FIXED_CHANNEL;
cur->ws_info->hopping_schdule.fixed_channel = randLIB_get_random_in_range(11,25);

return 0;
}

Expand Down
56 changes: 51 additions & 5 deletions source/6LoWPAN/ws/ws_management_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <nsdynmemLIB.h>
#include "NWK_INTERFACE/Include/protocol.h"
#include "6LoWPAN/ws/ws_common.h"
#include "6LoWPAN/ws/ws_bootstrap.h"

#include "ws_management_api.h"

Expand Down Expand Up @@ -72,13 +73,18 @@ int ws_management_regulatory_domain_set(
cur->ws_info->hopping_schdule.operating_class = operating_class;
if (ws_common_regulatory_domain_config(cur) != 0) {
// Restore old config on failure
//tr_error("unsupported regulatory domain: %d class: %d, mode: %d", regulatory_domain, operating_class, operating_mode);
cur->ws_info->hopping_schdule.regulatory_domain = regulatory_domain_saved;
cur->ws_info->hopping_schdule.operating_mode = operating_mode_saved;
cur->ws_info->hopping_schdule.operating_class = operating_class_saved;
ws_common_regulatory_domain_config(cur);
return -1;
}
// TODO update fields to llc
// if settings change reset_restart for the settings needed
if (cur->lowpan_info & INTERFACE_NWK_ACTIVE) {
// bootstrap active need to restart
ws_bootstrap_restart(interface_id);
}

return 0;
}
Expand All @@ -93,7 +99,7 @@ int ws_management_channel_mask_set(
if (!cur || !ws_info(cur)) {
return -1;
}
memcpy(cur->ws_info->hopping_schdule.channel_mask, channel_mask, sizeof(uint32_t)*8);
memcpy(cur->ws_info->fhss_channel_mask, channel_mask, sizeof(uint32_t)*8);
return 0;
}

Expand Down Expand Up @@ -133,10 +139,50 @@ int ws_management_fhss_timing_configure(
if (!cur || !ws_info(cur)) {
return -1;
}
cur->ws_info->hopping_schdule.fhss_uc_dwell_interval = fhss_uc_dwell_interval;
cur->ws_info->hopping_schdule.fhss_broadcast_interval = fhss_broadcast_interval;
cur->ws_info->hopping_schdule.fhss_bc_dwell_interval = fhss_bc_dwell_interval;
if (fhss_uc_dwell_interval > 0) {
cur->ws_info->fhss_uc_dwell_interval = fhss_uc_dwell_interval;
}
if (fhss_broadcast_interval > 0) {
cur->ws_info->fhss_bc_interval = fhss_broadcast_interval;

}
if (fhss_bc_dwell_interval > 0) {
cur->ws_info->fhss_bc_dwell_interval = fhss_bc_dwell_interval;

}

// if settings change reset_restart for the settings needed
if (cur->lowpan_info & INTERFACE_NWK_ACTIVE) {
// bootstrap active need to restart
ws_bootstrap_restart(interface_id);
}
return 0;
}

int ws_management_fhss_channel_function_configure(
int8_t interface_id,
uint8_t channel_function)
{
protocol_interface_info_entry_t *cur;

cur = protocol_stack_interface_info_get_by_id(interface_id);
if (!cur || !ws_info(cur)) {
return -1;
}
if (channel_function != WS_FIXED_CHANNEL &&
channel_function != WS_VENDOR_DEF_CF &&
channel_function != WS_DH1CF &&
channel_function != WS_TR51CF) {
return -2;
}
cur->ws_info->fhss_channel_function = channel_function;

// if settings change reset_restart for the settings needed
if (cur->lowpan_info & INTERFACE_NWK_ACTIVE) {
// bootstrap active need to restart
ws_bootstrap_restart(interface_id);
}
return 0;

}
#endif // HAVE_WS
13 changes: 13 additions & 0 deletions source/Service_Libs/fhss/channel_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ uint8_t channel_list_get_channel(const uint32_t* list, int current_index)
return found_index;
}

void channel_list_set_channel(uint32_t* list, int channel, bool active)
{
if (channel >= CHANNEL_LIST_SIZE_IN_BITS) {
return;
}
if (active) {
list[channel/32] |= (1 << channel % 32);
} else {
list[channel/32] &= ~(1 << channel % 32);
}
return;
}

// count the amount of channels enabled in a list
int channel_list_count_channels(const uint32_t* list)
{
Expand Down
Loading

0 comments on commit 1a09af7

Please sign in to comment.