Skip to content

Commit

Permalink
Allowed separate default settings in WS API
Browse files Browse the repository at this point in the history
if 0 or FF is given to API the default values are used
  • Loading branch information
Mika committed Sep 21, 2020
1 parent 850252b commit 6b0e264
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 11 deletions.
9 changes: 3 additions & 6 deletions source/6LoWPAN/ws/ws_cfg_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,8 @@ static void ws_cfg_network_size_config_set_xlarge(ws_cfg_nw_size_t *cfg);
static void ws_cfg_network_size_config_set_certificate(ws_cfg_nw_size_t *cfg);
static int8_t ws_cfg_network_size_default_set(ws_gen_cfg_t *cfg);
static int8_t ws_cfg_gen_default_set(ws_gen_cfg_t *cfg);
static int8_t ws_cfg_phy_default_set(ws_phy_cfg_t *cfg);
static int8_t ws_cfg_timing_default_set(ws_timing_cfg_t *cfg);
static int8_t ws_cfg_bbr_default_set(ws_bbr_cfg_t *cfg);
static int8_t ws_cfg_mpl_default_set(ws_mpl_cfg_t *cfg);
static int8_t ws_cfg_fhss_default_set(ws_fhss_cfg_t *cfg);
static int8_t ws_cfg_sec_timer_default_set(ws_sec_timer_cfg_t *cfg);
static int8_t ws_cfg_sec_prot_default_set(ws_sec_prot_cfg_t *cfg);

Expand Down Expand Up @@ -601,7 +598,7 @@ int8_t ws_cfg_gen_set(protocol_interface_info_entry_t *cur, ws_gen_cfg_t *cfg, w
return CFG_SETTINGS_OK;
}

static int8_t ws_cfg_phy_default_set(ws_phy_cfg_t *cfg)
int8_t ws_cfg_phy_default_set(ws_phy_cfg_t *cfg)
{
// FHSS configuration
cfg->regulatory_domain = REG_DOMAIN_EU;
Expand Down Expand Up @@ -681,7 +678,7 @@ int8_t ws_cfg_phy_set(protocol_interface_info_entry_t *cur, ws_phy_cfg_t *cfg, w
return CFG_SETTINGS_OK;
}

static int8_t ws_cfg_timing_default_set(ws_timing_cfg_t *cfg)
int8_t ws_cfg_timing_default_set(ws_timing_cfg_t *cfg)
{
// Configure the Wi-SUN timing trickle parameters
cfg->disc_trickle_imin = TRICKLE_IMIN_60_SECS; // 60 seconds
Expand Down Expand Up @@ -901,7 +898,7 @@ int8_t ws_cfg_mpl_set(protocol_interface_info_entry_t *cur, ws_mpl_cfg_t *cfg, w
return CFG_SETTINGS_OK;
}

static int8_t ws_cfg_fhss_default_set(ws_fhss_cfg_t *cfg)
int8_t ws_cfg_fhss_default_set(ws_fhss_cfg_t *cfg)
{
// Set defaults for the device. user can modify these.
cfg->fhss_uc_fixed_channel = 0xffff;
Expand Down
3 changes: 3 additions & 0 deletions source/6LoWPAN/ws/ws_cfg_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@ int8_t ws_cfg_gen_get(ws_gen_cfg_t *cfg, uint8_t *flags);
int8_t ws_cfg_gen_validate(ws_gen_cfg_t *cfg, ws_gen_cfg_t *new_cfg);
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);

int8_t ws_cfg_phy_default_set(ws_phy_cfg_t *cfg);
int8_t ws_cfg_phy_get(ws_phy_cfg_t *cfg, uint8_t *flags);
int8_t ws_cfg_phy_validate(ws_phy_cfg_t *cfg, ws_phy_cfg_t *new_cfg);
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);

int8_t ws_cfg_timing_default_set(ws_timing_cfg_t *cfg);
int8_t ws_cfg_timing_get(ws_timing_cfg_t *cfg, uint8_t *flags);
int8_t ws_cfg_timing_validate(ws_timing_cfg_t *cfg, ws_timing_cfg_t *new_cfg);
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);
Expand All @@ -175,6 +177,7 @@ int8_t ws_cfg_mpl_get(ws_mpl_cfg_t *cfg, uint8_t *flags);
int8_t ws_cfg_mpl_validate(ws_mpl_cfg_t *cfg, ws_mpl_cfg_t *new_cfg);
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);

int8_t ws_cfg_fhss_default_set(ws_fhss_cfg_t *cfg);
int8_t ws_cfg_fhss_get(ws_fhss_cfg_t *cfg, uint8_t *flags);
int8_t ws_cfg_fhss_validate(ws_fhss_cfg_t *cfg, ws_fhss_cfg_t *new_cfg);
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);
Expand Down
94 changes: 89 additions & 5 deletions source/6LoWPAN/ws/ws_management_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,29 @@ int ws_management_regulatory_domain_set(
}

ws_phy_cfg_t cfg;
ws_phy_cfg_t cfg_default;
if (ws_cfg_phy_get(&cfg, NULL) < 0) {
return -3;
}

if (ws_cfg_phy_default_set(&cfg_default) < 0) {
return -3;
}

if (regulatory_domain != 255) {
cfg.regulatory_domain = regulatory_domain;
} else {
cfg.regulatory_domain = cfg_default.regulatory_domain;
}
if (operating_mode != 255) {
cfg.operating_mode = operating_mode;
} else {
cfg.operating_mode = cfg_default.operating_mode;
}
if (operating_class != 255) {
cfg.operating_class = operating_class;
} else {
cfg.operating_class = cfg_default.operating_class;
}

if (ws_cfg_phy_set(cur, NULL, &cfg, 0) < 0) {
Expand Down Expand Up @@ -334,7 +345,18 @@ int ws_management_channel_mask_set(
return -2;
}

memcpy(cfg.fhss_channel_mask, channel_mask, sizeof(uint32_t) * 8);
ws_fhss_cfg_t cfg_default;
if (ws_cfg_fhss_default_set(&cfg_default) < 0) {
return -2;
}

if (channel_mask) {
memcpy(cfg.fhss_channel_mask, channel_mask, sizeof(uint32_t) * 8);
} else {
// Use the default
memcpy(cfg.fhss_channel_mask, cfg_default.fhss_channel_mask, sizeof(uint32_t) * 8);
}


if (ws_cfg_fhss_set(cur, NULL, &cfg, 0) < 0) {
return -3;
Expand Down Expand Up @@ -434,14 +456,27 @@ int ws_management_fhss_timing_configure(
return -2;
}

ws_fhss_cfg_t cfg_default;
if (ws_cfg_fhss_default_set(&cfg_default) < 0) {
return -2;
}

if (fhss_uc_dwell_interval > 0) {
cfg.fhss_uc_dwell_interval = fhss_uc_dwell_interval;
} else if (fhss_uc_dwell_interval == 0xff) {
cfg.fhss_uc_dwell_interval = cfg_default.fhss_uc_dwell_interval;
}

if (fhss_broadcast_interval > 0) {
cfg.fhss_bc_interval = fhss_broadcast_interval;
} else if (fhss_broadcast_interval == 0xffff) {
cfg.fhss_bc_interval = cfg_default.fhss_bc_interval;
}

if (fhss_bc_dwell_interval > 0) {
cfg.fhss_bc_dwell_interval = fhss_bc_dwell_interval;
} else if (fhss_bc_dwell_interval == 0xff) {
cfg.fhss_bc_dwell_interval = cfg_default.fhss_bc_dwell_interval;
}

if (ws_cfg_fhss_set(cur, NULL, &cfg, 0) < 0) {
Expand Down Expand Up @@ -469,12 +504,27 @@ int ws_management_fhss_unicast_channel_function_configure(
return -2;
}

ws_fhss_cfg_t cfg_default;
if (ws_cfg_fhss_default_set(&cfg_default) < 0) {
return -2;
}

if (dwell_interval > 0) {
cfg.fhss_uc_dwell_interval = dwell_interval;
} else {
cfg.fhss_uc_dwell_interval = cfg_default.fhss_uc_dwell_interval;
}
if (channel_function < 0xff) {
cfg.fhss_uc_channel_function = channel_function;
} else {
cfg.fhss_uc_channel_function = cfg_default.fhss_uc_channel_function;
}

cfg.fhss_uc_channel_function = channel_function;
cfg.fhss_uc_fixed_channel = fixed_channel;
if (fixed_channel < 0xffff) {
cfg.fhss_uc_fixed_channel = fixed_channel;
} else {
cfg.fhss_uc_fixed_channel = cfg_default.fhss_uc_fixed_channel;
}

if (ws_cfg_fhss_set(cur, NULL, &cfg, 0) < 0) {
return -3;
Expand Down Expand Up @@ -556,16 +606,34 @@ int ws_management_fhss_broadcast_channel_function_configure(
if (ws_cfg_fhss_get(&cfg, NULL) < 0) {
return -2;
}
ws_fhss_cfg_t cfg_default;
if (ws_cfg_fhss_default_set(&cfg_default) < 0) {
return -2;
}

if (dwell_interval > 0) {
cfg.fhss_bc_dwell_interval = dwell_interval;
} else {
cfg.fhss_bc_dwell_interval = cfg_default.fhss_bc_dwell_interval;
}

if (broadcast_interval > 0) {
cfg.fhss_bc_interval = broadcast_interval;
} else {
cfg.fhss_bc_interval = cfg_default.fhss_bc_interval;
}

cfg.fhss_bc_channel_function = channel_function;
cfg.fhss_bc_fixed_channel = fixed_channel;
if (channel_function != 0xff) {
cfg.fhss_bc_channel_function = channel_function;
} else {
cfg.fhss_bc_channel_function = cfg_default.fhss_bc_channel_function;
}

if (fixed_channel != 0xffff) {
cfg.fhss_bc_fixed_channel = fixed_channel;
} else {
cfg.fhss_bc_fixed_channel = cfg_default.fhss_bc_fixed_channel;
}

if (ws_cfg_fhss_set(cur, NULL, &cfg, 0) < 0) {
return -3;
Expand Down Expand Up @@ -652,17 +720,33 @@ int ws_management_timing_parameters_set(
return -2;
}

ws_timing_cfg_t cfg_default;
if (ws_cfg_timing_default_set(&cfg_default) < 0) {
return -2;
}

if (disc_trickle_imin > 0) {
cfg.disc_trickle_imin = disc_trickle_imin;
} else {
cfg.disc_trickle_imin = cfg_default.disc_trickle_imin;
}

if (disc_trickle_imax > 0) {
cfg.disc_trickle_imax = disc_trickle_imax;
} else {
cfg.disc_trickle_imax = cfg_default.disc_trickle_imax;;
}

if (disc_trickle_k > 0) {
cfg.disc_trickle_k = disc_trickle_k;
} else {
cfg.disc_trickle_k = cfg_default.disc_trickle_k;;
}

if (pan_timeout > 0) {
cfg.pan_timeout = pan_timeout;
} else {
cfg.pan_timeout = cfg_default.pan_timeout;;
}

if (ws_cfg_timing_set(cur, NULL, &cfg, 0) < 0) {
Expand Down
14 changes: 14 additions & 0 deletions test/nanostack/unittest/stub/ws_cfg_settings_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ int8_t ws_cfg_gen_set(protocol_interface_info_entry_t *cur, ws_gen_cfg_t *cfg, w
return ws_cfg_settings_stub.int8_ret_value[ws_cfg_settings_stub.int8_stub_index++];
}

int8_t ws_cfg_phy_default_set(ws_phy_cfg_t *cfg)
{
return 0;
}

int8_t ws_cfg_phy_get(ws_phy_cfg_t *cfg, uint8_t *flags)
{
memcpy(&ws_cfg_settings_stub.cfgs_input[ws_cfg_settings_stub.int8_stub_index], cfg, sizeof(ws_phy_cfg_t));
Expand Down Expand Up @@ -173,6 +178,10 @@ int8_t ws_cfg_phy_set(protocol_interface_info_entry_t *cur, ws_phy_cfg_t *cfg, w
return ws_cfg_settings_stub.int8_ret_value[ws_cfg_settings_stub.int8_stub_index++];
}

int8_t ws_cfg_timing_default_set(ws_timing_cfg_t *cfg)
{
return 0;
}
int8_t ws_cfg_timing_get(ws_timing_cfg_t *cfg, uint8_t *flags)
{
memcpy(&ws_cfg_settings_stub.cfgs_input[ws_cfg_settings_stub.int8_stub_index], cfg, sizeof(ws_timing_cfg_t));
Expand Down Expand Up @@ -281,6 +290,11 @@ int8_t ws_cfg_mpl_set(protocol_interface_info_entry_t *cur, ws_mpl_cfg_t *cfg, w
return ws_cfg_settings_stub.int8_ret_value[ws_cfg_settings_stub.int8_stub_index++];
}

int8_t ws_cfg_fhss_default_set(ws_fhss_cfg_t *cfg)
{
return 0;
}

int8_t ws_cfg_fhss_get(ws_fhss_cfg_t *cfg, uint8_t *flags)
{
memcpy(&ws_cfg_settings_stub.cfgs_input[ws_cfg_settings_stub.int8_stub_index], cfg, sizeof(ws_fhss_cfg_t));
Expand Down

0 comments on commit 6b0e264

Please sign in to comment.