Skip to content

Commit 67ea075

Browse files
author
Mika Tervonen
committed
Wi-SUN node init API change
Added regulatory domain as mandatory parameter. Support for setting regulatory domain without changing default mode and class
1 parent d74d5ff commit 67ea075

File tree

5 files changed

+58
-19
lines changed

5 files changed

+58
-19
lines changed

nanostack/ws_management_api.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,27 @@ extern "C" {
6767
#define CHANNEL_FUNCTION_FIXED 0x00 // Fixed channel
6868
#define CHANNEL_FUNCTION_TR51CF 0x01 // TR51CF
6969
#define CHANNEL_FUNCTION_DH1CF 0x02 // Direct Hash
70-
#define CHANNEL_FUNCTION_VENDOR_DEFINED 0x03 // Direct Hash
70+
#define CHANNEL_FUNCTION_VENDOR_DEFINED 0x03 // vendor given channel hop schedule
7171

7272
#define CHANNEL_SPACING_200 0x00 // 200 khz
7373
#define CHANNEL_SPACING_400 0x01 // 400 khz
7474
#define CHANNEL_SPACING_600 0x02 // 600 khz
7575
#define CHANNEL_SPACING_100 0x03 // 100 khz
7676
#define CHANNEL_SPACING_250 0x04 // 250 khz
7777

78+
79+
/** Temporary API change flag. this will be removed when new version of API is implemented on applications
80+
*
81+
*/
82+
#define WS_MANAGEMENT_API_VER_2
83+
7884
/**
7985
* Initialize Wi-SUN stack.
8086
*
8187
* Generates the default configuration for Wi-SUN operation
8288
*
8389
* \param interface_id Network interface ID.
90+
* \param regulatory_domain Mandatory regulatory domain value of the device.
8491
* \param network_name_ptr Network name where to join if no configuration found from storage.
8592
* \param fhss_timer_ptr FHSS functions for timer adaptation to platform.
8693
*
@@ -89,6 +96,7 @@ extern "C" {
8996
*/
9097
int ws_management_node_init(
9198
int8_t interface_id,
99+
uint8_t regulatory_domain,
92100
char *network_name_ptr,
93101
fhss_timer_t *fhss_timer_ptr);
94102

@@ -102,6 +110,8 @@ int ws_management_node_init(
102110
* Operating class: (1), (2)
103111
* operation mode: "1b" (symbol rate 50, modulation index 1)
104112
*
113+
* if value of 255 is given then previous value is used.
114+
*
105115
* \param interface_id Network interface ID.
106116
* \param regulatory_domain FHSS regulatory domain default to "KR" 0x09.
107117
* \param operating_class FHSS operating class default to 1.

source/6LoWPAN/ws/ws_common.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ int8_t ws_common_regulatory_domain_config(protocol_interface_info_entry_t *cur)
114114
return -1;
115115
}
116116
} else if(cur->ws_info->hopping_schdule.regulatory_domain == REG_DOMAIN_WW) {
117-
if(cur->ws_info->hopping_schdule.operating_class == 2) {
117+
if(cur->ws_info->hopping_schdule.operating_class == 1) {
118+
cur->ws_info->hopping_schdule.ch0_freq = 24002;
119+
cur->ws_info->hopping_schdule.channel_spacing = CHANNEL_SPACING_200;
120+
cur->ws_info->hopping_schdule.number_of_channels = (uint8_t)416; // TODO we dont support this yet, but it is used as test value
121+
} else if(cur->ws_info->hopping_schdule.operating_class == 2) {
118122
cur->ws_info->hopping_schdule.ch0_freq = 24004;
119123
cur->ws_info->hopping_schdule.channel_spacing = CHANNEL_SPACING_400;
120124
cur->ws_info->hopping_schdule.number_of_channels = 207;

source/6LoWPAN/ws/ws_empty_functions.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
#ifndef HAVE_WS
3030
int ws_management_node_init(
3131
int8_t interface_id,
32+
uint8_t regulatory_domain,
3233
char *network_name_ptr,
3334
fhss_timer_t *fhss_timer_ptr)
3435
{
3536
(void)interface_id;
37+
(void)regulatory_domain;
3638
(void)network_name_ptr;
3739
(void)fhss_timer_ptr;
3840
return -1;

source/6LoWPAN/ws/ws_management_api.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
int ws_management_node_init(
3535
int8_t interface_id,
36+
uint8_t regulatory_domain,
3637
char *network_name_ptr,
3738
fhss_timer_t *fhss_timer_ptr)
3839
{
@@ -45,6 +46,11 @@ int ws_management_node_init(
4546
if (!network_name_ptr || !fhss_timer_ptr) {
4647
return -2;
4748
}
49+
cur->ws_info->hopping_schdule.regulatory_domain = regulatory_domain;
50+
if (ws_common_regulatory_domain_config(cur) < 0) {
51+
// Invalid regulatory domain set
52+
return -3;
53+
}
4854
strncpy(cur->ws_info->network_name,network_name_ptr,32);
4955
cur->ws_info->fhss_timer_ptr = fhss_timer_ptr;
5056
return 0;
@@ -68,9 +74,15 @@ int ws_management_regulatory_domain_set(
6874
regulatory_domain_saved = cur->ws_info->hopping_schdule.regulatory_domain;
6975
operating_class_saved = cur->ws_info->hopping_schdule.operating_mode;
7076
operating_mode_saved = cur->ws_info->hopping_schdule.operating_class;
71-
cur->ws_info->hopping_schdule.regulatory_domain = regulatory_domain;
72-
cur->ws_info->hopping_schdule.operating_mode = operating_mode;
73-
cur->ws_info->hopping_schdule.operating_class = operating_class;
77+
if (regulatory_domain != 255) {
78+
cur->ws_info->hopping_schdule.regulatory_domain = regulatory_domain;
79+
}
80+
if (operating_mode != 255) {
81+
cur->ws_info->hopping_schdule.operating_mode = operating_mode;
82+
}
83+
if (operating_class != 255) {
84+
cur->ws_info->hopping_schdule.operating_class = operating_class;
85+
}
7486
if (ws_common_regulatory_domain_config(cur) != 0) {
7587
// Restore old config on failure
7688
//tr_error("unsupported regulatory domain: %d class: %d, mode: %d", regulatory_domain, operating_class, operating_mode);

test/nanostack/unittest/6LoWPAN/ws_management_api/test_ws_management_api.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "nsdynmemLIB.h"
2323
#include "NWK_INTERFACE/Include/protocol.h"
2424
#include "6LoWPAN/ws/ws_common.h"
25+
#include "ws_management_api.h"
2526

2627
/* Stubs */
2728
#include "protocol_core_stub.h"
@@ -37,38 +38,48 @@ bool test_ws_management_node_init()
3738
memset(&entry, 0, sizeof(protocol_interface_info_entry_t));
3839
memset(&ws_info_entry, 0, sizeof(ws_info_t));
3940
memset(&fhss_timer_entry, 0, sizeof(fhss_timer_t));
41+
ws_common_stub.int8_value = 0;
42+
4043

4144
/* No interface info entry found */
42-
if (-1 != ws_management_node_init(1, NULL, NULL)) {
45+
if (-1 != ws_management_node_init(1, 3, NULL, NULL)) {
4346
return false;
4447
}
4548

4649
protocol_core_stub.entry_ptr = &entry;
4750

4851
/* No ws_info found */
49-
if (-1 != ws_management_node_init(1, NULL, NULL)) {
52+
if (-1 != ws_management_node_init(1, 3, NULL, NULL)) {
5053
return false;
5154
}
5255

5356
entry.ws_info = &ws_info_entry;
5457

5558
/* NULL pointers as a parameters */
56-
if (-2 != ws_management_node_init(1, NULL, NULL)) {
59+
if (-2 != ws_management_node_init(1, 3, NULL, NULL)) {
5760
return false;
5861
}
5962

6063
/* NULL pointers as a FHSS info */
61-
if (-2 != ws_management_node_init(1, nw_name, NULL)) {
64+
if (-2 != ws_management_node_init(1, 3, nw_name, NULL)) {
6265
return false;
6366
}
6467

6568
/* NULL pointers as a network name */
66-
if (-2 != ws_management_node_init(1, NULL, fhss_timer_entry)) {
69+
if (-2 != ws_management_node_init(1, 3, NULL, &fhss_timer_entry)) {
70+
return false;
71+
}
72+
73+
// Invalid regulatory domain
74+
ws_common_stub.int8_value = -1;
75+
if (-3 != ws_management_node_init(1, 43, nw_name, &fhss_timer_entry)) {
6776
return false;
6877
}
6978

7079
/* OK case */
71-
if (0 != ws_management_node_init(1, nw_name, fhss_timer_entry)) {
80+
ws_common_stub.int8_value = 0;
81+
82+
if (0 != ws_management_node_init(1, 3, nw_name, &fhss_timer_entry)) {
7283
return false;
7384
}
7485

@@ -159,21 +170,21 @@ bool test_ws_management_channel_plan_set()
159170
protocol_core_stub.entry_ptr = NULL;
160171

161172
/* No protocol info entry */
162-
if (-1 != ws_management_channel_plan_set(1,0,0,0,0,0)) {
173+
if (-1 != ws_management_channel_plan_set(1,0,0,0,0,0,0)) {
163174
return false;
164175
}
165176

166177
protocol_core_stub.entry_ptr = &entry;
167178

168179
/* No ws_info found */
169-
if (-1 != ws_management_channel_plan_set(1,0,0,0,0,0)) {
180+
if (-1 != ws_management_channel_plan_set(1,0,0,0,0,0,0)) {
170181
return false;
171182
}
172183

173184
entry.ws_info = &ws_info_entry;
174185

175186
/* OK case */
176-
if (0 != ws_management_channel_plan_set(1,0,0,0,0,0)) {
187+
if (0 != ws_management_channel_plan_set(1,0,0,0,0,0,0)) {
177188
return false;
178189
}
179190

@@ -225,29 +236,29 @@ bool test_ws_management_fhss_channel_function_configure()
225236

226237
protocol_core_stub.entry_ptr = NULL;
227238

228-
if (-1 != ws_management_fhss_unicast_channel_function_configure(1,10))
239+
if (-1 != ws_management_fhss_unicast_channel_function_configure(1,10,0,0))
229240
{
230241
return false;
231242
}
232243
protocol_core_stub.entry_ptr = &entry;
233244

234-
if (-1 != ws_management_fhss_unicast_channel_function_configure(1,10))
245+
if (-1 != ws_management_fhss_unicast_channel_function_configure(1,10,0,0))
235246
{
236247
return false;
237248
}
238249
entry.ws_info = &ws_info_entry;
239-
if (-2 != ws_management_fhss_unicast_channel_function_configure(1,10))
250+
if (-2 != ws_management_fhss_unicast_channel_function_configure(1,10,0,0))
240251
{
241252
return false;
242253
}
243254

244255
entry.lowpan_info = 0;
245-
if (0 != ws_management_fhss_unicast_channel_function_configure(1,0))
256+
if (0 != ws_management_fhss_unicast_channel_function_configure(1,0,0,0))
246257
{
247258
return false;
248259
}
249260
entry.lowpan_info = INTERFACE_NWK_ACTIVE;
250-
if (0 != ws_management_fhss_unicast_channel_function_configure(1,0))
261+
if (0 != ws_management_fhss_unicast_channel_function_configure(1,0,0,0))
251262
{
252263
return false;
253264
}

0 commit comments

Comments
 (0)