Skip to content

Commit

Permalink
Detect border router connection lost
Browse files Browse the repository at this point in the history
reset stack and go to discovery when lost connection to Border router
  • Loading branch information
Mika Tervonen committed Apr 11, 2018
1 parent c0e8673 commit 04797c2
Showing 1 changed file with 42 additions and 13 deletions.
55 changes: 42 additions & 13 deletions source/6LoWPAN/ws/ws_bootstrap.c
Expand Up @@ -43,6 +43,7 @@
#include "RPL/rpl_data.h"
#include "Common_Protocols/icmpv6.h"
#include "Common_Protocols/icmpv6_radv.h"
#include "Common_Protocols/ipv6_constants.h"
#include "6LoWPAN/ws/ws_common_defines.h"
#include "Service_Libs/Trickle/trickle.h"
#include "6LoWPAN/ws/ws_common_defines.h"
Expand Down Expand Up @@ -854,14 +855,34 @@ static void ws_bootstrap_network_configuration_learn(protocol_interface_info_ent
return;
}

static void ws_bootstrap_ip_stack_addr_clear(protocol_interface_info_entry_t *cur)
{
tr_debug("ip stack address clear");
ns_list_foreach_safe(if_address_entry_t, addr, &cur->ip_addresses) {
if (addr->source != ADDR_SOURCE_STATIC &&
addr_ipv6_scope(addr->address,cur) > IPV6_SCOPE_LINK_LOCAL) {
// Remove all exept User set address
addr_delete_entry(cur, addr);
}
}
}

static void ws_bootstrap_ip_stack_reset(protocol_interface_info_entry_t *cur)
{
tr_debug("ip stack reset");
// Delete all temporary cached information
ipv6_neighbour_cache_flush(&cur->ipv6_neighbour_cache);
lowpan_context_list_free(&cur->lowpan_contexts);
}

static void ws_bootstrap_ip_stack_activate(protocol_interface_info_entry_t *cur)
{
tr_debug("ip stack init");
clear_power_state(ICMP_ACTIVE);
cur->lowpan_info |= INTERFACE_NWK_BOOTSRAP_ACTIVE;
ipv6_neighbour_cache_flush(&cur->ipv6_neighbour_cache);

ws_bootstrap_ip_stack_reset(cur);
}

static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
{

Expand All @@ -874,12 +895,13 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
// Trigger statemachine check
cur->bootsrap_state_machine_cnt = 1;
} else if(event == RPL_EVENT_LOCAL_REPAIR_NO_MORE_DIS) {
// RPL gave up so we need to re-trigger network scan.
// TODO is this correct?
// TODO no! ws_bootstrap_event_configuration_start(cur); causes failure to
// We could send solicit for configuration and then select new parent when those arrive
/* This is done after address deletion, so RPL can act on them */
ws_bootstrap_event_configuration_start(cur);
/*
* RPL goes to passive mode, but does not require any extra changed
*
* We could remove our current addresses learned from RPL
* We could send solicit for configuration and then select new parent when those arrive
*
*/

}
cur->ws_info->rpl_state = event;
Expand All @@ -900,6 +922,7 @@ static void ws_bootstrap_rpl_activate(protocol_interface_info_entry_t *cur)

cur->ws_info->rpl_state = 0xff; // Set invalid state and learn from event
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_ROUTER) {
// TODO RPL should have function to reset DIS trickle and it should be called here
rpl_control_transmit_dis(cur->rpl_domain, cur, 0, 0, NULL, 0, ADDR_LINK_LOCAL_ALL_RPL_NODES);
}
}
Expand Down Expand Up @@ -940,6 +963,14 @@ static void ws_bootstrap_start_discovery(protocol_interface_info_entry_t *cur)
// Clear learned neighbours
ws_bootstrap_neighbor_list_clean(cur);

// Clear RPL information
rpl_control_remove_domain_from_interface(cur);

// Clear ip stack from old information
ws_bootstrap_ip_stack_reset(cur);
// New network scan started old addresses not assumed valid anymore
ws_bootstrap_ip_stack_addr_clear(cur);

// Reset advertisement solicit trickle to start discovering network
trickle_start(&cur->ws_info->trickle_pan_advertisement_solicit, &trickle_params_pan_configuration);
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_advertisement_solicit, &trickle_params_pan_configuration);
Expand All @@ -952,20 +983,18 @@ static void ws_bootstrap_start_configuration_learn(protocol_interface_info_entry
ws_bootstrap_state_change(cur, ER_SCAN);

cur->ws_info->configuration_learned = false;
cur->ws_info->pan_version_timeout_timer = 0;
rpl_control_remove_domain_from_interface(cur);
ipv6_neighbour_cache_flush(&cur->ipv6_neighbour_cache);
// Clear parent info
memset(cur->ws_info->parent_info.addr,0,8);

// Clear all temporary information
ws_bootstrap_ip_stack_reset(cur);

// Clear learned neighbours
ws_bootstrap_neighbor_list_clean(cur);

// Reset advertisement solicit trickle to start discovering network
trickle_start(&cur->ws_info->trickle_pan_config_solicit, &trickle_params_pan_configuration);
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config_solicit, &trickle_params_pan_configuration);


}

/*
Expand Down

0 comments on commit 04797c2

Please sign in to comment.