Skip to content

Commit a0a4707

Browse files
author
Arto Kinnunen
authored
Merge pull request #13883 from artokin/nanostack_release_v12_6_2
feature-wisun: Nanostack release v12.6.2
2 parents 0f4dbfd + 554cfaf commit a0a4707

File tree

15 files changed

+356
-36
lines changed

15 files changed

+356
-36
lines changed

features/nanostack/sal-stack-nanostack/mbed_lib.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
"configuration": {
66
"help": "Build time configuration. Refer to Handbook for valid values. Default: full stack",
77
"value": "nanostack_full"
8+
},
9+
"trace_max_level": {
10+
"help": "One of mbed-trace level defines: TRACE_LEVEL_DEBUG, TRACE_LEVEL_INFO, TRACE_LEVEL_WARN or TRACE_LEVEL_ERROR",
11+
"value": null
812
}
913
},
1014
"macros": ["NS_USE_EXTERNAL_MBED_TLS"],

features/nanostack/sal-stack-nanostack/nanostack/ws_bbr_api.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,19 @@ int ws_bbr_pan_configuration_get(int8_t interface_id, uint16_t *pan_id);
334334
*/
335335
int ws_bbr_pan_configuration_validate(int8_t interface_id, uint16_t pan_id);
336336

337+
/**
338+
* Sets Wi-SUN BSI
339+
*
340+
* Sets Wi-SUN PAN BSI.
341+
*
342+
* \param interface_id Network interface ID.
343+
* \param new_bsi Identifier.
344+
*
345+
* \return 0, PAN BSI set.
346+
* \return <0 PAN BSI set failed.
347+
*/
348+
int ws_bbr_bsi_set(int8_t interface_id, uint16_t new_bsi);
349+
337350
/**
338351
* Sets memory used for key storages
339352
*

features/nanostack/sal-stack-nanostack/source/6LoWPAN/ws/ws_bbr_api.c

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "ns_types.h"
2121
#include "ns_trace.h"
2222
#include "nsdynmemLIB.h"
23+
#include "randLIB.h"
24+
#include "common_functions.h"
2325
#include "net_interface.h"
2426
#include "socket_api.h"
2527
#include "eventOS_event.h"
@@ -31,6 +33,7 @@
3133
#include "6LoWPAN/ws/ws_bootstrap.h"
3234
#include "6LoWPAN/ws/ws_cfg_settings.h"
3335
#include "6LoWPAN/ws/ws_pae_key_storage.h"
36+
#include "6LoWPAN/ws/ws_pae_nvm_store.h"
3437
#include "RPL/rpl_control.h"
3538
#include "RPL/rpl_data.h"
3639
#include "Common_Protocols/icmpv6.h"
@@ -61,6 +64,20 @@ static uint8_t current_instance_id = RPL_INSTANCE_ID;
6164
#define BBR_CHECK_INTERVAL 60
6265
#define BBR_BACKUP_ULA_DELAY 300
6366

67+
//TAG ID This must be update if NVM_BBR_INFO_LEN or data structure
68+
#define NVM_BBR_INFO_TAG 1
69+
// BSI 2 bytes
70+
#define NVM_BBR_INFO_LEN 2
71+
72+
typedef struct bbr_info_nvm_tlv {
73+
uint16_t tag; /**< Unique tag */
74+
uint16_t len; /**< Number of the bytes after the length field */
75+
uint8_t data[NVM_BBR_INFO_LEN]; /**< Data */
76+
} bbr_info_nvm_tlv_t;
77+
78+
//NVM file name
79+
static const char *BBR_INFO_FILE = "pae_bbr_info";
80+
6481
/* when creating BBR make ULA dodag ID always and when network becomes available add prefix to DHCP
6582
*
6683
*
@@ -105,6 +122,52 @@ typedef struct dns_resolution {
105122
#define MAX_DNS_RESOLUTIONS 4
106123

107124
static dns_resolution_t pre_resolved_dns_queries[MAX_DNS_RESOLUTIONS] = {0};
125+
//BBR NVM info buffer
126+
127+
#define BBR_NVM_BSI_OFFSET 0
128+
static bbr_info_nvm_tlv_t bbr_info_nvm_tlv = {
129+
.tag = NVM_BBR_INFO_TAG,
130+
.len = 0,
131+
.data = {0}
132+
};
133+
134+
static uint16_t ws_bbr_fhss_bsi = 0;
135+
136+
static int8_t ws_bbr_nvm_info_read(bbr_info_nvm_tlv_t *tlv_entry)
137+
{
138+
tlv_entry->tag = NVM_BBR_INFO_TAG;
139+
tlv_entry->len = NVM_BBR_INFO_LEN;
140+
141+
int8_t ret_val = ws_pae_nvm_store_tlv_file_read(BBR_INFO_FILE, (nvm_tlv_t *) &bbr_info_nvm_tlv);
142+
143+
if (ret_val < 0 || tlv_entry->tag != NVM_BBR_INFO_TAG || tlv_entry->len != NVM_BBR_INFO_LEN) {
144+
ws_pae_nvm_store_tlv_file_remove(BBR_INFO_FILE);
145+
tlv_entry->len = 0;
146+
return -1;
147+
}
148+
return 0;
149+
}
150+
151+
static void ws_bbr_nvm_info_write(bbr_info_nvm_tlv_t *tlv_entry)
152+
{
153+
tlv_entry->tag = NVM_BBR_INFO_TAG;
154+
tlv_entry->len = NVM_BBR_INFO_LEN;
155+
ws_pae_nvm_store_tlv_file_write(BBR_INFO_FILE, (nvm_tlv_t *) tlv_entry);
156+
tr_debug("BBR info NVM update");
157+
}
158+
159+
static uint16_t ws_bbr_bsi_read(bbr_info_nvm_tlv_t *tlv_entry)
160+
{
161+
if (tlv_entry->tag != NVM_BBR_INFO_TAG || tlv_entry->len != NVM_BBR_INFO_LEN) {
162+
return 0;
163+
}
164+
return common_read_16_bit(tlv_entry->data + BBR_NVM_BSI_OFFSET);
165+
}
166+
167+
static void ws_bbr_bsi_write(bbr_info_nvm_tlv_t *tlv_entry, uint16_t bsi)
168+
{
169+
common_write_16_bit(bsi, tlv_entry->data + BBR_NVM_BSI_OFFSET);
170+
}
108171

109172
static void ws_bbr_rpl_version_timer_start(protocol_interface_info_entry_t *cur, uint8_t version)
110173
{
@@ -134,7 +197,6 @@ static void ws_bbr_rpl_version_increase(protocol_interface_info_entry_t *cur)
134197
ws_bbr_rpl_version_timer_start(cur, rpl_control_increment_dodag_version(protocol_6lowpan_rpl_root_dodag));
135198
}
136199

137-
138200
void ws_bbr_rpl_config(protocol_interface_info_entry_t *cur, uint8_t imin, uint8_t doubling, uint8_t redundancy, uint16_t dag_max_rank_increase, uint16_t min_hop_rank_increase)
139201
{
140202
if (imin == 0 || doubling == 0) {
@@ -785,6 +847,35 @@ bool ws_bbr_ready_to_start(protocol_interface_info_entry_t *cur)
785847

786848
return true;
787849
}
850+
851+
void ws_bbr_init(protocol_interface_info_entry_t *interface)
852+
{
853+
(void) interface;
854+
//Read From NVM
855+
if (ws_bbr_nvm_info_read(&bbr_info_nvm_tlv) < 0) {
856+
//NVM value not available Randomize Value Here by first time
857+
ws_bbr_fhss_bsi = randLIB_get_16bit();
858+
tr_debug("Randomized init value BSI %u", ws_bbr_fhss_bsi);
859+
} else {
860+
ws_bbr_fhss_bsi = ws_bbr_bsi_read(&bbr_info_nvm_tlv);
861+
tr_debug("Read BSI %u from NVM", ws_bbr_fhss_bsi);
862+
}
863+
}
864+
865+
866+
uint16_t ws_bbr_bsi_generate(protocol_interface_info_entry_t *interface)
867+
{
868+
(void) interface;
869+
//Give current one
870+
uint16_t bsi = ws_bbr_fhss_bsi;
871+
//Update value for next round
872+
ws_bbr_fhss_bsi++;
873+
//Store To NVN
874+
ws_bbr_bsi_write(&bbr_info_nvm_tlv, ws_bbr_fhss_bsi);
875+
ws_bbr_nvm_info_write(&bbr_info_nvm_tlv);
876+
return bsi;
877+
}
878+
788879
#endif //HAVE_WS_BORDER_ROUTER
789880

790881
/* Public APIs
@@ -1070,6 +1161,33 @@ int ws_bbr_rpl_parameters_validate(int8_t interface_id, uint8_t dio_interval_min
10701161
#endif
10711162
}
10721163

1164+
int ws_bbr_bsi_set(int8_t interface_id, uint16_t new_bsi)
1165+
{
1166+
(void) interface_id;
1167+
#ifdef HAVE_WS_BORDER_ROUTER
1168+
1169+
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
1170+
1171+
//Check if new value is different than current active
1172+
if (cur && cur->ws_info && cur->lowpan_info & INTERFACE_NWK_ACTIVE) {
1173+
if (cur->ws_info->hopping_schdule.fhss_bsi == new_bsi) {
1174+
return 0;
1175+
}
1176+
tr_debug("New BSI %u to delayed activate", new_bsi);
1177+
ws_bootstrap_restart_delayed(cur->id);
1178+
}
1179+
1180+
ws_bbr_bsi_write(&bbr_info_nvm_tlv, new_bsi);
1181+
ws_bbr_nvm_info_write(&bbr_info_nvm_tlv);
1182+
ws_bbr_fhss_bsi = new_bsi;
1183+
return 0;
1184+
#else
1185+
(void) new_bsi;
1186+
return -1;
1187+
#endif
1188+
}
1189+
1190+
10731191
int ws_bbr_pan_configuration_set(int8_t interface_id, uint16_t pan_id)
10741192
{
10751193
(void) interface_id;

features/nanostack/sal-stack-nanostack/source/6LoWPAN/ws/ws_bbr_api_internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ bool ws_bbr_ready_to_start(protocol_interface_info_entry_t *cur);
3737

3838
bool ws_bbr_backbone_address_get(uint8_t *address);
3939

40+
uint16_t ws_bbr_bsi_generate(protocol_interface_info_entry_t *interface);
41+
void ws_bbr_init(protocol_interface_info_entry_t *interface);
42+
4043
#else
4144

4245
#define ws_bbr_seconds_timer( cur, seconds)
@@ -46,6 +49,8 @@ bool ws_bbr_backbone_address_get(uint8_t *address);
4649
#define ws_bbr_dhcp_address_lifetime_set(cur, dhcp_address_lifetime)
4750
#define ws_bbr_ready_to_start(cur) true
4851
#define ws_bbr_backbone_address_get(address) 0
52+
#define ws_bbr_bsi_generate(interface) 0
53+
#define ws_bbr_init(interface) (void) 0
4954

5055
#endif //HAVE_WS_BORDER_ROUTER
5156

features/nanostack/sal-stack-nanostack/source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,9 @@ static int8_t ws_fhss_border_router_configure(protocol_interface_info_entry_t *c
670670
if (ns_fhss_ws_configuration_get(cur->ws_info->fhss_api)) {
671671
memcpy(&fhss_configuration, ns_fhss_ws_configuration_get(cur->ws_info->fhss_api), sizeof(fhss_ws_configuration_t));
672672
}
673+
674+
//GET BSI from BBR module
675+
fhss_configuration.bsi = ws_bbr_bsi_generate(cur);
673676
ws_fhss_set_defaults(cur, &fhss_configuration);
674677
ws_fhss_configure_channel_masks(cur, &fhss_configuration);
675678
ns_fhss_ws_configuration_set(cur->ws_info->fhss_api, &fhss_configuration);
@@ -988,15 +991,17 @@ static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
988991
tr_error("fhss initialization failed");
989992
return -3;
990993
}
991-
994+
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
995+
//BBR init like NVM read
996+
ws_bbr_init(cur);
997+
}
992998
// Save FHSS api
993999
cur->ws_info->fhss_api = ns_sw_mac_get_fhss_api(cur->mac_api);
9941000

9951001
ws_bootstrap_ll_address_validate(cur);
9961002

9971003
addr_interface_set_ll64(cur, NULL);
9981004
cur->nwk_nd_re_scan_count = 0;
999-
//WS_interface_up(cur);
10001005
// Trigger discovery for bootstrap
10011006
ret_val = nwk_6lowpan_up(cur);
10021007
if (ret_val) {
@@ -1487,12 +1492,6 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
14871492
ws_bootsrap_create_ll_address(ll_address, neighbor_info.neighbor->mac64);
14881493

14891494
if (rpl_control_is_dodag_parent(cur, ll_address)) {
1490-
// automatic network size adjustment learned
1491-
if (cur->ws_info->cfg->gen.network_size == NETWORK_SIZE_AUTOMATIC &&
1492-
cur->ws_info->pan_information.pan_size != pan_information.pan_size) {
1493-
ws_cfg_network_size_configure(cur, pan_information.pan_size);
1494-
}
1495-
14961495
cur->ws_info->pan_information.pan_size = pan_information.pan_size;
14971496
cur->ws_info->pan_information.routing_cost = pan_information.routing_cost;
14981497
cur->ws_info->pan_information.rpl_routing_method = pan_information.rpl_routing_method;
@@ -1584,6 +1583,27 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
15841583
llc_neighbour_req_t neighbor_info;
15851584
bool neighbour_pointer_valid;
15861585

1586+
//Validate BSI
1587+
if (cur->bootsrap_mode != ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
1588+
1589+
if (cur->ws_info->ws_bsi_block.block_time && cur->ws_info->ws_bsi_block.old_bsi == ws_bs_ie.broadcast_schedule_identifier) {
1590+
tr_debug("Do not accept a old BSI: %u in time %"PRIu32, cur->ws_info->ws_bsi_block.old_bsi, cur->ws_info->ws_bsi_block.block_time);
1591+
//Refresh Block time when hear a old BSI
1592+
cur->ws_info->ws_bsi_block.block_time = cur->ws_info->cfg->timing.pan_timeout;
1593+
return;
1594+
}
1595+
1596+
//When Config is learned and USE Parent BS is enabled compare is this new BSI
1597+
if (cur->ws_info->configuration_learned && cur->ws_info->pan_information.use_parent_bs && ws_bs_ie.broadcast_schedule_identifier != cur->ws_info->hopping_schdule.fhss_bsi) {
1598+
tr_debug("NEW Brodcast Schedule %u...BR rebooted", ws_bs_ie.broadcast_schedule_identifier);
1599+
cur->ws_info->ws_bsi_block.block_time = cur->ws_info->cfg->timing.pan_timeout;
1600+
cur->ws_info->ws_bsi_block.old_bsi = cur->ws_info->hopping_schdule.fhss_bsi;
1601+
ws_bootstrap_event_discovery_start(cur);
1602+
return;
1603+
}
1604+
}
1605+
1606+
15871607
if (cur->ws_info->configuration_learned || cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
15881608
//If we are border router or learned configuration we only update already learned neighbours.
15891609
neighbour_pointer_valid = ws_bootstrap_neighbor_info_request(cur, data->SrcAddr, &neighbor_info, false);
@@ -2491,6 +2511,13 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
24912511
ws_pae_controller_nw_info_set(cur, cur->ws_info->network_pan_id, cur->ws_info->pan_information.pan_version, cur->ws_info->cfg->gen.network_name);
24922512
// Network key is valid, indicate border router IID to controller
24932513
ws_pae_controller_nw_key_valid(cur, &dodag_info.dodag_id[8]);
2514+
//Update here Suplikant target by validated Primary Parent
2515+
if (cur->bootsrap_mode != ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
2516+
mac_neighbor_table_entry_t *mac_neighbor = mac_neighbor_entry_get_priority(mac_neighbor_info(cur));
2517+
if (mac_neighbor) {
2518+
ws_pae_controller_set_target(cur, cur->ws_info->network_pan_id, mac_neighbor->mac64);
2519+
}
2520+
}
24942521

24952522
// After successful DAO ACK connection to border router is verified
24962523
cur->ws_info->pan_timeout_timer = cur->ws_info->cfg->timing.pan_timeout;
@@ -3657,6 +3684,16 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s
36573684
}
36583685
}
36593686

3687+
if (cur->ws_info->ws_bsi_block.block_time) {
3688+
if (cur->ws_info->ws_bsi_block.block_time > seconds) {
3689+
cur->ws_info->ws_bsi_block.block_time -= seconds;
3690+
} else {
3691+
//Clear A BSI blokker
3692+
cur->ws_info->ws_bsi_block.block_time = 0;
3693+
cur->ws_info->ws_bsi_block.old_bsi = 0;
3694+
}
3695+
}
3696+
36603697
ws_llc_timer_seconds(cur, seconds);
36613698

36623699
}

0 commit comments

Comments
 (0)