Skip to content

Commit 7ad7e81

Browse files
author
Juha Heiskanen
committed
Wi-SUN recovery and BR BSI update:
BSI is randomized at first use. Border router support BSI update at BootUp process and BBR NVM BBR NVM information support update wi-sun bbr read BSI from NVM at boot up process. BSI is stored to NVM when it is update at discoverty state or manual set from Application. Node detetc Border router updated BSI at PAN config handler and start discovery and start block old shedule select. Update PAE controller target address at DAO ACK done event.
1 parent d166c89 commit 7ad7e81

File tree

6 files changed

+192
-7
lines changed

6 files changed

+192
-7
lines changed

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
*

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;

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

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 45 additions & 2 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) {
@@ -1584,6 +1589,27 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
15841589
llc_neighbour_req_t neighbor_info;
15851590
bool neighbour_pointer_valid;
15861591

1592+
//Validate BSI
1593+
if (cur->bootsrap_mode != ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
1594+
1595+
if (cur->ws_info->ws_bsi_block.block_time && cur->ws_info->ws_bsi_block.old_bsi == ws_bs_ie.broadcast_schedule_identifier) {
1596+
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);
1597+
//Refresh Block time when hear a old BSI
1598+
cur->ws_info->ws_bsi_block.block_time = cur->ws_info->cfg->timing.pan_timeout;
1599+
return;
1600+
}
1601+
1602+
//When Config is learned and USE Parent BS is enabled compare is this new BSI
1603+
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) {
1604+
tr_debug("NEW Brodcast Schedule %u...BR rebooted", ws_bs_ie.broadcast_schedule_identifier);
1605+
cur->ws_info->ws_bsi_block.block_time = cur->ws_info->cfg->timing.pan_timeout;
1606+
cur->ws_info->ws_bsi_block.old_bsi = cur->ws_info->hopping_schdule.fhss_bsi;
1607+
ws_bootstrap_event_discovery_start(cur);
1608+
return;
1609+
}
1610+
}
1611+
1612+
15871613
if (cur->ws_info->configuration_learned || cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
15881614
//If we are border router or learned configuration we only update already learned neighbours.
15891615
neighbour_pointer_valid = ws_bootstrap_neighbor_info_request(cur, data->SrcAddr, &neighbor_info, false);
@@ -2491,6 +2517,13 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
24912517
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);
24922518
// Network key is valid, indicate border router IID to controller
24932519
ws_pae_controller_nw_key_valid(cur, &dodag_info.dodag_id[8]);
2520+
//Update here Suplikant target by validated Primary Parent
2521+
if (cur->bootsrap_mode != ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
2522+
mac_neighbor_table_entry_t *mac_neighbor = mac_neighbor_entry_get_priority(mac_neighbor_info(cur));
2523+
if (mac_neighbor) {
2524+
ws_pae_controller_set_target(cur, cur->ws_info->network_pan_id, mac_neighbor->mac64);
2525+
}
2526+
}
24942527

24952528
// After successful DAO ACK connection to border router is verified
24962529
cur->ws_info->pan_timeout_timer = cur->ws_info->cfg->timing.pan_timeout;
@@ -3657,6 +3690,16 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s
36573690
}
36583691
}
36593692

3693+
if (cur->ws_info->ws_bsi_block.block_time) {
3694+
if (cur->ws_info->ws_bsi_block.block_time > seconds) {
3695+
cur->ws_info->ws_bsi_block.block_time -= seconds;
3696+
} else {
3697+
//Clear A BSI blokker
3698+
cur->ws_info->ws_bsi_block.block_time = 0;
3699+
cur->ws_info->ws_bsi_block.old_bsi = 0;
3700+
}
3701+
}
3702+
36603703
ws_llc_timer_seconds(cur, seconds);
36613704

36623705
}

source/6LoWPAN/ws/ws_cfg_settings.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ typedef struct ws_timing_cfg_s {
5656
* \brief Struct ws_rpl_cfg_t RPL configuration
5757
*/
5858
typedef struct ws_bbr_cfg_s {
59-
uint8_t dio_interval_min; /**> DIO interval min; DEFAULT_DIO_INTERVAL_MIN; 2^value in milliseconds; range 1-255; default */
60-
uint8_t dio_interval_doublings; /**> DIO interval doublings; DEFAULT_DIO_INTERVAL_DOUBLINGS; range 1-8; default */
61-
uint8_t dio_redundancy_constant; /**> DIO redundancy constant; DEFAULT_DIO_REDUNDANCY_CONSTANT; range 0-10; default */
59+
uint8_t dio_interval_min; /**< DIO interval min; DEFAULT_DIO_INTERVAL_MIN; 2^value in milliseconds; range 1-255; default */
60+
uint8_t dio_interval_doublings; /**< DIO interval doublings; DEFAULT_DIO_INTERVAL_DOUBLINGS; range 1-8; default */
61+
uint8_t dio_redundancy_constant; /**< DIO redundancy constant; DEFAULT_DIO_REDUNDANCY_CONSTANT; range 0-10; default */
6262
uint16_t dag_max_rank_increase;
6363
uint16_t min_hop_rank_increase;
64-
uint32_t dhcp_address_lifetime; /**> DHCP address lifetime in seconds minimum 2 hours and maximum as days hours*/
64+
uint32_t dhcp_address_lifetime; /**< DHCP address lifetime in seconds minimum 2 hours and maximum as days hours*/
6565
} ws_bbr_cfg_t;
6666

6767
/**

source/6LoWPAN/ws/ws_common.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ typedef struct {
7373
uint8_t index;
7474
} ws_pending_key_index_t;
7575

76+
typedef struct {
77+
uint32_t block_time;
78+
uint16_t old_bsi;
79+
} ws_bsi_block_t;
80+
7681
typedef NS_LIST_HEAD(ws_nud_table_entry_t, link) ws_nud_table_list_t;
7782

7883
typedef struct ws_info_s {
@@ -89,6 +94,7 @@ typedef struct ws_info_s {
8994
parent_info_t parent_info[WS_PARENT_LIST_SIZE];
9095
parent_info_list_t parent_list_free;
9196
parent_info_list_t parent_list_reserved;
97+
ws_bsi_block_t ws_bsi_block;
9298
uint16_t aro_registration_timer; /**< Aro registration timer */
9399
uint16_t rpl_version_timer; /**< RPL version update timeout */
94100
uint32_t pan_timeout_timer; /**< routers will fallback to previous state after this */

0 commit comments

Comments
 (0)