Skip to content

Commit 1a09af7

Browse files
author
Mika Tervonen
committed
Updated management api
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
1 parent f52289f commit 1a09af7

File tree

13 files changed

+236
-65
lines changed

13 files changed

+236
-65
lines changed

nanostack/ws_management_api.h

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,38 @@ extern "C" {
3636
#endif
3737

3838
/* Regulatory domain values*/
39-
#define REG_DOMAIN_WW 0x00 // World wide
40-
#define REG_DOMAIN_NA 0x01 // North America
41-
#define REG_DOMAIN_JP 0x02 // Japan
42-
#define REG_DOMAIN_EU 0x03 // European Union
43-
#define REG_DOMAIN_CH 0x04 // China
44-
#define REG_DOMAIN_IN 0x05 // India
45-
#define REG_DOMAIN_MX 0x06 //
46-
#define REG_DOMAIN_BZ 0x07 // Brazil
47-
#define REG_DOMAIN_AZ 0x08 // Australia
48-
#define REG_DOMAIN_NZ 0x08 // New zealand
49-
#define REG_DOMAIN_KR 0x09 // Korea
50-
#define REG_DOMAIN_PH 0x0A //
51-
#define REG_DOMAIN_MY 0x0B //
39+
#define REG_DOMAIN_WW 0x00 // World wide
40+
#define REG_DOMAIN_NA 0x01 // North America
41+
#define REG_DOMAIN_JP 0x02 // Japan
42+
#define REG_DOMAIN_EU 0x03 // European Union
43+
#define REG_DOMAIN_CH 0x04 // China
44+
#define REG_DOMAIN_IN 0x05 // India
45+
#define REG_DOMAIN_MX 0x06 //
46+
#define REG_DOMAIN_BZ 0x07 // Brazil
47+
#define REG_DOMAIN_AZ 0x08 // Australia
48+
#define REG_DOMAIN_NZ 0x08 // New zealand
49+
#define REG_DOMAIN_KR 0x09 // Korea
50+
#define REG_DOMAIN_PH 0x0A //
51+
#define REG_DOMAIN_MY 0x0B //
52+
#define REG_DOMAIN_HK 0x0C //
53+
#define REG_DOMAIN_SG 0x0D // band 866-869
54+
#define REG_DOMAIN_TH 0x0E //
55+
#define REG_DOMAIN_VN 0x0F //
56+
#define REG_DOMAIN_SG_H 0x10 // band 920-925
5257

53-
#define OPERATING_MODE_1a 0x01
54-
#define OPERATING_MODE_1b 0x02
55-
#define OPERATING_MODE_2a 0x03
56-
#define OPERATING_MODE_2b 0x04
57-
#define OPERATING_MODE_3 0x05
58-
#define OPERATING_MODE_4a 0x06
59-
#define OPERATING_MODE_4b 0x07
60-
#define OPERATING_MODE_5 0x08
58+
#define OPERATING_MODE_1a 0x1a
59+
#define OPERATING_MODE_1b 0x1b
60+
#define OPERATING_MODE_2a 0x2a
61+
#define OPERATING_MODE_2b 0x2b
62+
#define OPERATING_MODE_3 0x03
63+
#define OPERATING_MODE_4a 0x4a
64+
#define OPERATING_MODE_4b 0x4b
65+
#define OPERATING_MODE_5 0x05
6166

62-
#define CHANNEL_FUNCTION_FIXED 0x00 // Fixed channel
63-
#define CHANNEL_FUNCTION_TR51CF 0x01 // TR51CF
64-
#define CHANNEL_FUNCTION_DIRECT_HASH 0x02 // Direct Hash
67+
#define CHANNEL_FUNCTION_FIXED 0x00 // Fixed channel
68+
#define CHANNEL_FUNCTION_TR51CF 0x01 // TR51CF
69+
#define CHANNEL_FUNCTION_DH1CF 0x02 // Direct Hash
70+
#define CHANNEL_FUNCTION_VENDOR_DEFINED 0x03 // Direct Hash
6571

6672
#define CHANNEL_SPACING_200 0x00 // 200 khz
6773
#define CHANNEL_SPACING_400 0x01 // 400 khz
@@ -169,4 +175,21 @@ int ws_management_fhss_timing_configure(
169175
uint32_t fhss_broadcast_interval,
170176
uint8_t fhss_bc_dwell_interval);
171177

178+
/**
179+
* Configure channel function.
180+
*
181+
* Change the default configuration for Wi-SUN FHSS operation.
182+
* This will use randomized value for fixed channel if used.
183+
* if application defined is used the behaviour is undefined
184+
*
185+
* \param interface_id Network interface ID.
186+
* \param channel_function channel
187+
*
188+
* \return 0, Init OK.
189+
* \return <0 Init fail.
190+
*/
191+
int ws_management_fhss_channel_function_configure(
192+
int8_t interface_id,
193+
uint8_t channel_function);
194+
172195
#endif /* WS_MANAGEMENT_API_H_ */

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "Common_Protocols/ipv6_constants.h"
4747
#include "6LoWPAN/ws/ws_common_defines.h"
4848
#include "Service_Libs/Trickle/trickle.h"
49+
#include "Service_Libs/fhss/channel_list.h"
4950
#include "6LoWPAN/ws/ws_common_defines.h"
5051
#include "6LoWPAN/ws/ws_llc.h"
5152
#include "6LoWPAN/ws/ws_neighbor_class.h"
@@ -249,26 +250,45 @@ static int8_t ws_fhss_set_defaults(protocol_interface_info_entry_t *cur)
249250

250251
return 0;
251252
}
253+
static int8_t ws_fhss_discovery_configure(protocol_interface_info_entry_t *cur)
254+
{
255+
// Read configuration of existing FHSS and start using the default values for any network
256+
fhss_ws_configuration_t fhss_configuration = {0};
257+
if (ns_fhss_ws_configuration_get(cur->ws_info->fhss_api)) {
258+
memcpy(&fhss_configuration, ns_fhss_ws_configuration_get(cur->ws_info->fhss_api), sizeof(fhss_ws_configuration_t));
259+
}
260+
261+
fhss_configuration.fhss_uc_dwell_interval = 0;
262+
fhss_configuration.ws_channel_function = WS_FIXED_CHANNEL;
263+
fhss_configuration.fhss_bc_dwell_interval = 0;
264+
fhss_configuration.fhss_broadcast_interval = 0;
265+
cur->ws_info->hopping_schdule.fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels);
266+
memset(fhss_configuration.channel_mask, 0, sizeof(uint32_t) * 8);
267+
channel_list_set_channel(fhss_configuration.channel_mask, cur->ws_info->hopping_schdule.fixed_channel, true);
268+
269+
ns_fhss_ws_configuration_set(cur->ws_info->fhss_api,&fhss_configuration);
270+
ws_bootstrap_llc_hopping_update(cur,&fhss_configuration);
271+
272+
return 0;
273+
}
252274

253275
static int8_t ws_fhss_enable(protocol_interface_info_entry_t *cur)
254276
{
255-
fhss_api_t *fhss_api = ns_sw_mac_get_fhss_api(cur->mac_api);
256-
const fhss_ws_configuration_t *fhss_configuration = ns_fhss_ws_configuration_get(fhss_api);
277+
const fhss_ws_configuration_t *fhss_configuration = ns_fhss_ws_configuration_get(cur->ws_info->fhss_api);
257278

258-
if (!fhss_api || !fhss_configuration) {
279+
if (!cur->ws_info->fhss_api || !fhss_configuration) {
259280
return -1;
260281
}
261282
// Set the LLC information to follow the actual fhss settings
262283
ws_bootstrap_llc_hopping_update(cur,fhss_configuration);
263284

264285
// Set neighbor info callback
265-
if (ns_fhss_set_neighbor_info_fp(fhss_api, &ws_get_neighbor_info)) {
286+
if (ns_fhss_set_neighbor_info_fp(cur->ws_info->fhss_api, &ws_get_neighbor_info)) {
266287
return -1;
267288
}
268289
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
269-
ns_fhss_ws_set_hop_count(fhss_api, 0);
290+
ns_fhss_ws_set_hop_count(cur->ws_info->fhss_api, 0);
270291
}
271-
cur->ws_info->fhss_api = fhss_api;
272292
return 0;
273293
}
274294

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

284-
// unicast information is only followed from parent if fixed channel is selected
285-
if (neighbor_info->ws_neighbor->fhss_data.uc_timing_info.unicast_channel_function == WS_FIXED_CHANNEL) {
286-
cur->ws_info->hopping_schdule.fixed_channel = neighbor_info->ws_neighbor->fhss_data.uc_timing_info.fixed_channel;
287-
fhss_configuration.ws_channel_function = WS_FIXED_CHANNEL;
288-
tr_info("attaching to fixed channel network following configurtion");
289-
} else if (fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {
290-
// fixed channel cannot be mixed with other channel functions as it messes the broadcast schedule
291-
fhss_configuration.ws_channel_function = WS_DH1CF;
292-
tr_info("attaching channel hopping network changing to hopping");
293-
}
304+
fhss_configuration.ws_channel_function = neighbor_info->ws_neighbor->fhss_data.uc_timing_info.unicast_channel_function;
305+
cur->ws_info->hopping_schdule.fixed_channel = neighbor_info->ws_neighbor->fhss_data.uc_timing_info.fixed_channel;
306+
/* Learning different unicast is not working currently at fhss network follows border router
307+
*/
294308
// Learn broadcast information from selected parent
295309
fhss_configuration.bsi = neighbor_info->ws_neighbor->fhss_data.bc_timing_info.broadcast_schedule_id;
296310
fhss_configuration.fhss_bc_dwell_interval = neighbor_info->ws_neighbor->fhss_data.bc_timing_info.broadcast_dwell_interval;
@@ -368,6 +382,8 @@ static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
368382
tr_error("fhss initialization failed");
369383
return -3;
370384
}
385+
// Save FHSS api
386+
cur->ws_info->fhss_api = ns_sw_mac_get_fhss_api(cur->mac_api);
371387

372388
addr_interface_set_ll64(cur, NULL);
373389
cur->nwk_nd_re_scan_count = 0;
@@ -715,19 +731,21 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
715731
cur->ws_info->pan_information.pan_version = pan_version;
716732
memcpy(cur->ws_info->gtkhash,gtkhash_ptr,32);
717733

718-
if (neighbor_info.neighbor->link_role == PRIORITY_PARENT_NEIGHBOUR) {
719-
// RPL priority parent configuration we must update FHSS data
720-
ws_bootstrap_primary_parent_set(cur, &neighbor_info);
721-
}
722-
723734
if (!cur->ws_info->configuration_learned) {
724735
// Generate own hopping schedules Follow first parent broadcast and plans and also use same unicast dwell
736+
tr_info("learn network configuration");
725737
cur->ws_info->configuration_learned = true;
726738
// return to state machine after 1-2 s
727739
cur->bootsrap_state_machine_cnt = randLIB_get_random_in_range(10 ,20);
740+
// enable frequency hopping for unicast channel and start listening first neighbour
741+
ws_fhss_set_defaults(cur);
742+
ws_bootstrap_primary_parent_set(cur, &neighbor_info);
743+
} else if (neighbor_info.neighbor->link_role == PRIORITY_PARENT_NEIGHBOUR) {
744+
// RPL priority parent configuration we must update FHSS data
728745
ws_bootstrap_primary_parent_set(cur, &neighbor_info);
729746
}
730747

748+
731749
}
732750

733751
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)
@@ -1041,6 +1059,16 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
10411059
return ret_val;
10421060
}
10431061

1062+
int ws_bootstrap_restart(int8_t interface_id)
1063+
{
1064+
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
1065+
if (!cur || !cur->ws_info) {
1066+
return -1;
1067+
}
1068+
ws_bootstrap_event_discovery_start(cur);
1069+
return 0;
1070+
}
1071+
10441072
static void ws_bootstrap_mac_activate(protocol_interface_info_entry_t *cur, uint16_t channel, uint16_t panid, bool coordinator)
10451073
{
10461074
mlme_start_t start_req;
@@ -1199,14 +1227,7 @@ static void ws_bootstrap_network_discovery_configure(protocol_interface_info_ent
11991227
cur->ws_info->network_pan_id = 0xffff;
12001228

12011229
ws_common_regulatory_domain_config(cur);
1202-
1203-
// Set default schedules for discovery
1204-
cur->ws_info->hopping_schdule.fhss_uc_dwell_interval = WS_FHSS_UC_DWELL_INTERVAL;
1205-
cur->ws_info->hopping_schdule.fhss_broadcast_interval = WS_FHSS_BC_INTERVAL;
1206-
cur->ws_info->hopping_schdule.fhss_bc_dwell_interval = WS_FHSS_BC_DWELL_INTERVAL;
1207-
// By default, uses fixed channel
1208-
cur->ws_info->hopping_schdule.channel_function = WS_FIXED_CHANNEL;
1209-
cur->ws_info->hopping_schdule.fixed_channel = randLIB_get_random_in_range(11,25);
1230+
ws_fhss_discovery_configure(cur);
12101231

12111232
//Set Network names, Pan information configure, hopping schedule & GTKHash
12121233
ws_llc_set_network_name(cur, (uint8_t*)cur->ws_info->network_name, strlen(cur->ws_info->network_name));
@@ -1479,6 +1500,8 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
14791500

14801501
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
14811502
tr_debug("Border router start network");
1503+
// Randomize fixed channel. Only used if channel plan is fixed
1504+
cur->ws_info->hopping_schdule.fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels);
14821505
cur->ws_info->network_pan_id = randLIB_get_random_in_range(0,0xfffd);
14831506
cur->ws_info->pan_information.pan_size = 0;
14841507
cur->ws_info->pan_information.pan_version = randLIB_get_random_in_range(0,0xffff);
@@ -1488,6 +1511,7 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
14881511
cur->ws_info->pan_information.version = WS_FAN_VERSION_1_0;
14891512
ws_llc_set_gtkhash(cur, cur->ws_info->gtkhash);
14901513
cur->ws_info->pan_version_timer = PAN_VERSION_LIFETIME;
1514+
// Set default parameters for FHSS when starting a discovery
14911515
ws_bootstrap_fhss_activate(cur);
14921516
ws_bootstrap_set_test_key(cur);
14931517
ws_bootstrap_event_operation_start(cur);

source/6LoWPAN/ws/ws_bootstrap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode);
3535

3636
void ws_bootstrap_state_machine(protocol_interface_info_entry_t *cur);
3737

38+
int ws_bootstrap_restart(int8_t interface_id);
39+
3840
/*State machine transactions*/
3941
void ws_bootstrap_event_discovery_start(protocol_interface_info_entry_t *cur);
4042

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

5759
#define ws_bootstrap_init(interface_id, bootstrap_mode) (-1)
5860
#define ws_bootstrap_state_machine(cur)
61+
#define ws_bootstrap_restart(cur)
5962

6063
#endif //HAVE_WS
6164

source/6LoWPAN/ws/ws_common.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,6 @@ int8_t ws_common_allocate_and_init(protocol_interface_info_entry_t *cur)
159159
cur->ws_info->fhss_channel_mask[n] = 0xffffffff;
160160
}
161161

162-
// By default, uses fixed channel
163-
cur->ws_info->hopping_schdule.fhss_uc_dwell_interval = WS_FHSS_UC_DWELL_INTERVAL;
164-
cur->ws_info->hopping_schdule.fhss_broadcast_interval = WS_FHSS_BC_INTERVAL;
165-
cur->ws_info->hopping_schdule.fhss_bc_dwell_interval = WS_FHSS_BC_DWELL_INTERVAL;
166-
cur->ws_info->hopping_schdule.channel_function = WS_FIXED_CHANNEL;
167-
cur->ws_info->hopping_schdule.fixed_channel = randLIB_get_random_in_range(11,25);
168-
169162
return 0;
170163
}
171164

source/6LoWPAN/ws/ws_management_api.c

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <nsdynmemLIB.h>
2424
#include "NWK_INTERFACE/Include/protocol.h"
2525
#include "6LoWPAN/ws/ws_common.h"
26+
#include "6LoWPAN/ws/ws_bootstrap.h"
2627

2728
#include "ws_management_api.h"
2829

@@ -72,13 +73,18 @@ int ws_management_regulatory_domain_set(
7273
cur->ws_info->hopping_schdule.operating_class = operating_class;
7374
if (ws_common_regulatory_domain_config(cur) != 0) {
7475
// Restore old config on failure
76+
//tr_error("unsupported regulatory domain: %d class: %d, mode: %d", regulatory_domain, operating_class, operating_mode);
7577
cur->ws_info->hopping_schdule.regulatory_domain = regulatory_domain_saved;
7678
cur->ws_info->hopping_schdule.operating_mode = operating_mode_saved;
7779
cur->ws_info->hopping_schdule.operating_class = operating_class_saved;
7880
ws_common_regulatory_domain_config(cur);
7981
return -1;
8082
}
81-
// TODO update fields to llc
83+
// if settings change reset_restart for the settings needed
84+
if (cur->lowpan_info & INTERFACE_NWK_ACTIVE) {
85+
// bootstrap active need to restart
86+
ws_bootstrap_restart(interface_id);
87+
}
8288

8389
return 0;
8490
}
@@ -93,7 +99,7 @@ int ws_management_channel_mask_set(
9399
if (!cur || !ws_info(cur)) {
94100
return -1;
95101
}
96-
memcpy(cur->ws_info->hopping_schdule.channel_mask, channel_mask, sizeof(uint32_t)*8);
102+
memcpy(cur->ws_info->fhss_channel_mask, channel_mask, sizeof(uint32_t)*8);
97103
return 0;
98104
}
99105

@@ -133,10 +139,50 @@ int ws_management_fhss_timing_configure(
133139
if (!cur || !ws_info(cur)) {
134140
return -1;
135141
}
136-
cur->ws_info->hopping_schdule.fhss_uc_dwell_interval = fhss_uc_dwell_interval;
137-
cur->ws_info->hopping_schdule.fhss_broadcast_interval = fhss_broadcast_interval;
138-
cur->ws_info->hopping_schdule.fhss_bc_dwell_interval = fhss_bc_dwell_interval;
142+
if (fhss_uc_dwell_interval > 0) {
143+
cur->ws_info->fhss_uc_dwell_interval = fhss_uc_dwell_interval;
144+
}
145+
if (fhss_broadcast_interval > 0) {
146+
cur->ws_info->fhss_bc_interval = fhss_broadcast_interval;
147+
148+
}
149+
if (fhss_bc_dwell_interval > 0) {
150+
cur->ws_info->fhss_bc_dwell_interval = fhss_bc_dwell_interval;
151+
152+
}
153+
154+
// if settings change reset_restart for the settings needed
155+
if (cur->lowpan_info & INTERFACE_NWK_ACTIVE) {
156+
// bootstrap active need to restart
157+
ws_bootstrap_restart(interface_id);
158+
}
139159
return 0;
140160
}
141161

162+
int ws_management_fhss_channel_function_configure(
163+
int8_t interface_id,
164+
uint8_t channel_function)
165+
{
166+
protocol_interface_info_entry_t *cur;
167+
168+
cur = protocol_stack_interface_info_get_by_id(interface_id);
169+
if (!cur || !ws_info(cur)) {
170+
return -1;
171+
}
172+
if (channel_function != WS_FIXED_CHANNEL &&
173+
channel_function != WS_VENDOR_DEF_CF &&
174+
channel_function != WS_DH1CF &&
175+
channel_function != WS_TR51CF) {
176+
return -2;
177+
}
178+
cur->ws_info->fhss_channel_function = channel_function;
179+
180+
// if settings change reset_restart for the settings needed
181+
if (cur->lowpan_info & INTERFACE_NWK_ACTIVE) {
182+
// bootstrap active need to restart
183+
ws_bootstrap_restart(interface_id);
184+
}
185+
return 0;
186+
187+
}
142188
#endif // HAVE_WS

source/Service_Libs/fhss/channel_list.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ uint8_t channel_list_get_channel(const uint32_t* list, int current_index)
8888
return found_index;
8989
}
9090

91+
void channel_list_set_channel(uint32_t* list, int channel, bool active)
92+
{
93+
if (channel >= CHANNEL_LIST_SIZE_IN_BITS) {
94+
return;
95+
}
96+
if (active) {
97+
list[channel/32] |= (1 << channel % 32);
98+
} else {
99+
list[channel/32] &= ~(1 << channel % 32);
100+
}
101+
return;
102+
}
103+
91104
// count the amount of channels enabled in a list
92105
int channel_list_count_channels(const uint32_t* list)
93106
{

0 commit comments

Comments
 (0)