From 0ec37a6a1885e81dcbf31478be5254a89e4b897f Mon Sep 17 00:00:00 2001 From: Mika Tervonen Date: Fri, 27 Apr 2018 15:34:03 +0300 Subject: [PATCH] Count the amount of configuration solicits if count exeeds defined value device goes back to discovery Added check for RPL domain Start advertisements after Routing is ready --- source/6LoWPAN/ws/ws_bootstrap.c | 13 +++++++++++-- source/6LoWPAN/ws/ws_common.h | 1 + source/6LoWPAN/ws/ws_config.h | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/source/6LoWPAN/ws/ws_bootstrap.c b/source/6LoWPAN/ws/ws_bootstrap.c index 8717ba33747..a7dde7db30f 100644 --- a/source/6LoWPAN/ws/ws_bootstrap.c +++ b/source/6LoWPAN/ws/ws_bootstrap.c @@ -1088,6 +1088,7 @@ static void ws_bootstrap_start_configuration_learn(protocol_interface_info_entry // Clear all temporary information ws_bootstrap_ip_stack_reset(cur); + cur->ws_info->pas_requests = 0; // Reset advertisement solicit trickle to start discovering network trickle_start(&cur->ws_info->trickle_pan_config_solicit, &trickle_params_pan_discovery); trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config_solicit, &trickle_params_pan_discovery); @@ -1163,7 +1164,9 @@ static uint16_t ws_bootstrap_route_cost_calculate(protocol_interface_info_entry_ // Find selected parent from RPL struct rpl_instance *best_instance = NULL; - + if (!cur->rpl_domain) { + return 0xffff; + } ns_list_foreach(struct rpl_instance, instance, &cur->rpl_domain->instances) { best_instance = instance; // Select best grounded and lowest rank? But there should be only one really @@ -1300,7 +1303,6 @@ static void ws_bootstrap_event_handler(arm_event_s *event) ws_bootstrap_ip_stack_activate(cur); ws_bootstrap_rpl_activate(cur); ws_bootstrap_network_start(cur); - ws_bootstrap_advertise_start(cur); // Wait for RPL start if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) { ws_bootstrap_event_routing_ready(cur); @@ -1311,6 +1313,7 @@ static void ws_bootstrap_event_handler(arm_event_s *event) break; case WS_ROUTING_READY: tr_info("Routing ready"); + ws_bootstrap_advertise_start(cur); ws_bootstrap_state_change(cur, ER_BOOTSRAP_DONE); break; case WS_ADDRESS_ADDED: @@ -1449,7 +1452,13 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s } if(trickle_timer(&cur->ws_info->trickle_pan_config_solicit, &trickle_params_pan_discovery, seconds)) { // send PAN Configuration solicit + if (cur->ws_info->pas_requests > PCS_MAX) { + // if MAX PCS sent restart discovery + ws_bootstrap_event_discovery_start(cur); + return; + } tr_info("Send PAN configuration Solicit"); + cur->ws_info->pas_requests++; ws_bootstrap_pan_config_solicit(cur); } if(trickle_timer(&cur->ws_info->trickle_pan_advertisement, &trickle_params_pan_discovery, seconds)) { diff --git a/source/6LoWPAN/ws/ws_common.h b/source/6LoWPAN/ws/ws_common.h index 5efb1a288fb..676ac6eba6e 100644 --- a/source/6LoWPAN/ws/ws_common.h +++ b/source/6LoWPAN/ws/ws_common.h @@ -48,6 +48,7 @@ typedef struct ws_info_s { trickle_t trickle_pan_advertisement_solicit; trickle_t trickle_pan_advertisement; uint8_t rpl_state; // state from rpl_event_t + uint8_t pas_requests; // Amount of PAN solicits sent parent_info_t parent_info; uint32_t pan_version_timer; /**< border router version udate timeout */ uint32_t pan_version_timeout_timer; /**< routers will fallback to previous state after this */ diff --git a/source/6LoWPAN/ws/ws_config.h b/source/6LoWPAN/ws/ws_config.h index 9e37aacc7a0..12743242f7a 100644 --- a/source/6LoWPAN/ws/ws_config.h +++ b/source/6LoWPAN/ws/ws_config.h @@ -74,4 +74,9 @@ extern int8_t DEVICE_MIN_SENS; /* Candidate parent Threshold hysteresis */ #define CAND_PARENT_HYSTERISIS 3 -#endif /* WS_CONFIG_H_ */ + +/* Maximum amount of Pan Configuration Solicits before restarting Discovery. + */ +#define PCS_MAX 5 + + #endif /* WS_CONFIG_H_ */