Skip to content

Commit 6b0e264

Browse files
author
Mika
committed
Allowed separate default settings in WS API
if 0 or FF is given to API the default values are used
1 parent 850252b commit 6b0e264

File tree

4 files changed

+109
-11
lines changed

4 files changed

+109
-11
lines changed

source/6LoWPAN/ws/ws_cfg_settings.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,8 @@ static void ws_cfg_network_size_config_set_xlarge(ws_cfg_nw_size_t *cfg);
8787
static void ws_cfg_network_size_config_set_certificate(ws_cfg_nw_size_t *cfg);
8888
static int8_t ws_cfg_network_size_default_set(ws_gen_cfg_t *cfg);
8989
static int8_t ws_cfg_gen_default_set(ws_gen_cfg_t *cfg);
90-
static int8_t ws_cfg_phy_default_set(ws_phy_cfg_t *cfg);
91-
static int8_t ws_cfg_timing_default_set(ws_timing_cfg_t *cfg);
9290
static int8_t ws_cfg_bbr_default_set(ws_bbr_cfg_t *cfg);
9391
static int8_t ws_cfg_mpl_default_set(ws_mpl_cfg_t *cfg);
94-
static int8_t ws_cfg_fhss_default_set(ws_fhss_cfg_t *cfg);
9592
static int8_t ws_cfg_sec_timer_default_set(ws_sec_timer_cfg_t *cfg);
9693
static int8_t ws_cfg_sec_prot_default_set(ws_sec_prot_cfg_t *cfg);
9794

@@ -601,7 +598,7 @@ int8_t ws_cfg_gen_set(protocol_interface_info_entry_t *cur, ws_gen_cfg_t *cfg, w
601598
return CFG_SETTINGS_OK;
602599
}
603600

604-
static int8_t ws_cfg_phy_default_set(ws_phy_cfg_t *cfg)
601+
int8_t ws_cfg_phy_default_set(ws_phy_cfg_t *cfg)
605602
{
606603
// FHSS configuration
607604
cfg->regulatory_domain = REG_DOMAIN_EU;
@@ -681,7 +678,7 @@ int8_t ws_cfg_phy_set(protocol_interface_info_entry_t *cur, ws_phy_cfg_t *cfg, w
681678
return CFG_SETTINGS_OK;
682679
}
683680

684-
static int8_t ws_cfg_timing_default_set(ws_timing_cfg_t *cfg)
681+
int8_t ws_cfg_timing_default_set(ws_timing_cfg_t *cfg)
685682
{
686683
// Configure the Wi-SUN timing trickle parameters
687684
cfg->disc_trickle_imin = TRICKLE_IMIN_60_SECS; // 60 seconds
@@ -901,7 +898,7 @@ int8_t ws_cfg_mpl_set(protocol_interface_info_entry_t *cur, ws_mpl_cfg_t *cfg, w
901898
return CFG_SETTINGS_OK;
902899
}
903900

904-
static int8_t ws_cfg_fhss_default_set(ws_fhss_cfg_t *cfg)
901+
int8_t ws_cfg_fhss_default_set(ws_fhss_cfg_t *cfg)
905902
{
906903
// Set defaults for the device. user can modify these.
907904
cfg->fhss_uc_fixed_channel = 0xffff;

source/6LoWPAN/ws/ws_cfg_settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ int8_t ws_cfg_gen_get(ws_gen_cfg_t *cfg, uint8_t *flags);
159159
int8_t ws_cfg_gen_validate(ws_gen_cfg_t *cfg, ws_gen_cfg_t *new_cfg);
160160
int8_t ws_cfg_gen_set(protocol_interface_info_entry_t *cur, ws_gen_cfg_t *cfg, ws_gen_cfg_t *new_cfg, uint8_t *flags);
161161

162+
int8_t ws_cfg_phy_default_set(ws_phy_cfg_t *cfg);
162163
int8_t ws_cfg_phy_get(ws_phy_cfg_t *cfg, uint8_t *flags);
163164
int8_t ws_cfg_phy_validate(ws_phy_cfg_t *cfg, ws_phy_cfg_t *new_cfg);
164165
int8_t ws_cfg_phy_set(protocol_interface_info_entry_t *cur, ws_phy_cfg_t *cfg, ws_phy_cfg_t *new_cfg, uint8_t *flags);
165166

167+
int8_t ws_cfg_timing_default_set(ws_timing_cfg_t *cfg);
166168
int8_t ws_cfg_timing_get(ws_timing_cfg_t *cfg, uint8_t *flags);
167169
int8_t ws_cfg_timing_validate(ws_timing_cfg_t *cfg, ws_timing_cfg_t *new_cfg);
168170
int8_t ws_cfg_timing_set(protocol_interface_info_entry_t *cur, ws_timing_cfg_t *cfg, ws_timing_cfg_t *new_cfg, uint8_t *flags);
@@ -175,6 +177,7 @@ int8_t ws_cfg_mpl_get(ws_mpl_cfg_t *cfg, uint8_t *flags);
175177
int8_t ws_cfg_mpl_validate(ws_mpl_cfg_t *cfg, ws_mpl_cfg_t *new_cfg);
176178
int8_t ws_cfg_mpl_set(protocol_interface_info_entry_t *cur, ws_mpl_cfg_t *cfg, ws_mpl_cfg_t *new_cfg, uint8_t *flags);
177179

180+
int8_t ws_cfg_fhss_default_set(ws_fhss_cfg_t *cfg);
178181
int8_t ws_cfg_fhss_get(ws_fhss_cfg_t *cfg, uint8_t *flags);
179182
int8_t ws_cfg_fhss_validate(ws_fhss_cfg_t *cfg, ws_fhss_cfg_t *new_cfg);
180183
int8_t ws_cfg_fhss_set(protocol_interface_info_entry_t *cur, ws_fhss_cfg_t *cfg, ws_fhss_cfg_t *new_cfg, uint8_t *flags);

source/6LoWPAN/ws/ws_management_api.c

Lines changed: 89 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,18 +170,29 @@ int ws_management_regulatory_domain_set(
170170
}
171171

172172
ws_phy_cfg_t cfg;
173+
ws_phy_cfg_t cfg_default;
173174
if (ws_cfg_phy_get(&cfg, NULL) < 0) {
174175
return -3;
175176
}
176177

178+
if (ws_cfg_phy_default_set(&cfg_default) < 0) {
179+
return -3;
180+
}
181+
177182
if (regulatory_domain != 255) {
178183
cfg.regulatory_domain = regulatory_domain;
184+
} else {
185+
cfg.regulatory_domain = cfg_default.regulatory_domain;
179186
}
180187
if (operating_mode != 255) {
181188
cfg.operating_mode = operating_mode;
189+
} else {
190+
cfg.operating_mode = cfg_default.operating_mode;
182191
}
183192
if (operating_class != 255) {
184193
cfg.operating_class = operating_class;
194+
} else {
195+
cfg.operating_class = cfg_default.operating_class;
185196
}
186197

187198
if (ws_cfg_phy_set(cur, NULL, &cfg, 0) < 0) {
@@ -334,7 +345,18 @@ int ws_management_channel_mask_set(
334345
return -2;
335346
}
336347

337-
memcpy(cfg.fhss_channel_mask, channel_mask, sizeof(uint32_t) * 8);
348+
ws_fhss_cfg_t cfg_default;
349+
if (ws_cfg_fhss_default_set(&cfg_default) < 0) {
350+
return -2;
351+
}
352+
353+
if (channel_mask) {
354+
memcpy(cfg.fhss_channel_mask, channel_mask, sizeof(uint32_t) * 8);
355+
} else {
356+
// Use the default
357+
memcpy(cfg.fhss_channel_mask, cfg_default.fhss_channel_mask, sizeof(uint32_t) * 8);
358+
}
359+
338360

339361
if (ws_cfg_fhss_set(cur, NULL, &cfg, 0) < 0) {
340362
return -3;
@@ -434,14 +456,27 @@ int ws_management_fhss_timing_configure(
434456
return -2;
435457
}
436458

459+
ws_fhss_cfg_t cfg_default;
460+
if (ws_cfg_fhss_default_set(&cfg_default) < 0) {
461+
return -2;
462+
}
463+
437464
if (fhss_uc_dwell_interval > 0) {
438465
cfg.fhss_uc_dwell_interval = fhss_uc_dwell_interval;
466+
} else if (fhss_uc_dwell_interval == 0xff) {
467+
cfg.fhss_uc_dwell_interval = cfg_default.fhss_uc_dwell_interval;
439468
}
469+
440470
if (fhss_broadcast_interval > 0) {
441471
cfg.fhss_bc_interval = fhss_broadcast_interval;
472+
} else if (fhss_broadcast_interval == 0xffff) {
473+
cfg.fhss_bc_interval = cfg_default.fhss_bc_interval;
442474
}
475+
443476
if (fhss_bc_dwell_interval > 0) {
444477
cfg.fhss_bc_dwell_interval = fhss_bc_dwell_interval;
478+
} else if (fhss_bc_dwell_interval == 0xff) {
479+
cfg.fhss_bc_dwell_interval = cfg_default.fhss_bc_dwell_interval;
445480
}
446481

447482
if (ws_cfg_fhss_set(cur, NULL, &cfg, 0) < 0) {
@@ -469,12 +504,27 @@ int ws_management_fhss_unicast_channel_function_configure(
469504
return -2;
470505
}
471506

507+
ws_fhss_cfg_t cfg_default;
508+
if (ws_cfg_fhss_default_set(&cfg_default) < 0) {
509+
return -2;
510+
}
511+
472512
if (dwell_interval > 0) {
473513
cfg.fhss_uc_dwell_interval = dwell_interval;
514+
} else {
515+
cfg.fhss_uc_dwell_interval = cfg_default.fhss_uc_dwell_interval;
516+
}
517+
if (channel_function < 0xff) {
518+
cfg.fhss_uc_channel_function = channel_function;
519+
} else {
520+
cfg.fhss_uc_channel_function = cfg_default.fhss_uc_channel_function;
474521
}
475522

476-
cfg.fhss_uc_channel_function = channel_function;
477-
cfg.fhss_uc_fixed_channel = fixed_channel;
523+
if (fixed_channel < 0xffff) {
524+
cfg.fhss_uc_fixed_channel = fixed_channel;
525+
} else {
526+
cfg.fhss_uc_fixed_channel = cfg_default.fhss_uc_fixed_channel;
527+
}
478528

479529
if (ws_cfg_fhss_set(cur, NULL, &cfg, 0) < 0) {
480530
return -3;
@@ -556,16 +606,34 @@ int ws_management_fhss_broadcast_channel_function_configure(
556606
if (ws_cfg_fhss_get(&cfg, NULL) < 0) {
557607
return -2;
558608
}
609+
ws_fhss_cfg_t cfg_default;
610+
if (ws_cfg_fhss_default_set(&cfg_default) < 0) {
611+
return -2;
612+
}
559613

560614
if (dwell_interval > 0) {
561615
cfg.fhss_bc_dwell_interval = dwell_interval;
616+
} else {
617+
cfg.fhss_bc_dwell_interval = cfg_default.fhss_bc_dwell_interval;
562618
}
619+
563620
if (broadcast_interval > 0) {
564621
cfg.fhss_bc_interval = broadcast_interval;
622+
} else {
623+
cfg.fhss_bc_interval = cfg_default.fhss_bc_interval;
565624
}
566625

567-
cfg.fhss_bc_channel_function = channel_function;
568-
cfg.fhss_bc_fixed_channel = fixed_channel;
626+
if (channel_function != 0xff) {
627+
cfg.fhss_bc_channel_function = channel_function;
628+
} else {
629+
cfg.fhss_bc_channel_function = cfg_default.fhss_bc_channel_function;
630+
}
631+
632+
if (fixed_channel != 0xffff) {
633+
cfg.fhss_bc_fixed_channel = fixed_channel;
634+
} else {
635+
cfg.fhss_bc_fixed_channel = cfg_default.fhss_bc_fixed_channel;
636+
}
569637

570638
if (ws_cfg_fhss_set(cur, NULL, &cfg, 0) < 0) {
571639
return -3;
@@ -652,17 +720,33 @@ int ws_management_timing_parameters_set(
652720
return -2;
653721
}
654722

723+
ws_timing_cfg_t cfg_default;
724+
if (ws_cfg_timing_default_set(&cfg_default) < 0) {
725+
return -2;
726+
}
727+
655728
if (disc_trickle_imin > 0) {
656729
cfg.disc_trickle_imin = disc_trickle_imin;
730+
} else {
731+
cfg.disc_trickle_imin = cfg_default.disc_trickle_imin;
657732
}
733+
658734
if (disc_trickle_imax > 0) {
659735
cfg.disc_trickle_imax = disc_trickle_imax;
736+
} else {
737+
cfg.disc_trickle_imax = cfg_default.disc_trickle_imax;;
660738
}
739+
661740
if (disc_trickle_k > 0) {
662741
cfg.disc_trickle_k = disc_trickle_k;
742+
} else {
743+
cfg.disc_trickle_k = cfg_default.disc_trickle_k;;
663744
}
745+
664746
if (pan_timeout > 0) {
665747
cfg.pan_timeout = pan_timeout;
748+
} else {
749+
cfg.pan_timeout = cfg_default.pan_timeout;;
666750
}
667751

668752
if (ws_cfg_timing_set(cur, NULL, &cfg, 0) < 0) {

test/nanostack/unittest/stub/ws_cfg_settings_stub.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ int8_t ws_cfg_gen_set(protocol_interface_info_entry_t *cur, ws_gen_cfg_t *cfg, w
137137
return ws_cfg_settings_stub.int8_ret_value[ws_cfg_settings_stub.int8_stub_index++];
138138
}
139139

140+
int8_t ws_cfg_phy_default_set(ws_phy_cfg_t *cfg)
141+
{
142+
return 0;
143+
}
144+
140145
int8_t ws_cfg_phy_get(ws_phy_cfg_t *cfg, uint8_t *flags)
141146
{
142147
memcpy(&ws_cfg_settings_stub.cfgs_input[ws_cfg_settings_stub.int8_stub_index], cfg, sizeof(ws_phy_cfg_t));
@@ -173,6 +178,10 @@ int8_t ws_cfg_phy_set(protocol_interface_info_entry_t *cur, ws_phy_cfg_t *cfg, w
173178
return ws_cfg_settings_stub.int8_ret_value[ws_cfg_settings_stub.int8_stub_index++];
174179
}
175180

181+
int8_t ws_cfg_timing_default_set(ws_timing_cfg_t *cfg)
182+
{
183+
return 0;
184+
}
176185
int8_t ws_cfg_timing_get(ws_timing_cfg_t *cfg, uint8_t *flags)
177186
{
178187
memcpy(&ws_cfg_settings_stub.cfgs_input[ws_cfg_settings_stub.int8_stub_index], cfg, sizeof(ws_timing_cfg_t));
@@ -281,6 +290,11 @@ int8_t ws_cfg_mpl_set(protocol_interface_info_entry_t *cur, ws_mpl_cfg_t *cfg, w
281290
return ws_cfg_settings_stub.int8_ret_value[ws_cfg_settings_stub.int8_stub_index++];
282291
}
283292

293+
int8_t ws_cfg_fhss_default_set(ws_fhss_cfg_t *cfg)
294+
{
295+
return 0;
296+
}
297+
284298
int8_t ws_cfg_fhss_get(ws_fhss_cfg_t *cfg, uint8_t *flags)
285299
{
286300
memcpy(&ws_cfg_settings_stub.cfgs_input[ws_cfg_settings_stub.int8_stub_index], cfg, sizeof(ws_fhss_cfg_t));

0 commit comments

Comments
 (0)