Skip to content

Commit

Permalink
Merge branch 'release_internal' into release_external
Browse files Browse the repository at this point in the history
* release_internal:
  Removed Black list reject from wi-sun neighbour request function
  Support SLAAC addressing method for Wi-SUN Border router
  Modified Wi-SUN etx to wait for Probes
  Wi-SUN discovery and address registration update
  If PMK and PTK are not set do not store keys to NVM
  Follow Mbed OS coding style
  (via mbedos) Possible invalid memory access on memcpy
  Set frame counter increment to 1000000
  ETX update
  EAPOL parent TX feilure is reorder candidate list.
  Allowed separate default settings in WS API
  Fixed EAPOL brodcast synch at border router device.
  Corrected unit test
  Changed EAPOL negotiation limit on small nw to 20
  Wi-sun ETX update
  Changed EAP-TLS retry trace to info trace level
  WS: Use special retry configuration when discovery is started (ARMmbed#2450)
  • Loading branch information
Arto Kinnunen committed Oct 5, 2020
2 parents 7e3b99c + 9a3278a commit 09d9e24
Show file tree
Hide file tree
Showing 22 changed files with 406 additions and 113 deletions.
1 change: 1 addition & 0 deletions nanostack/ws_bbr_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ int ws_bbr_start(int8_t interface_id, int8_t backbone_interface_id);
#define BBR_BB_WAIT 0x0004 /**< Wait backbone availability before starting Wi-SUN network */
#define BBR_DEFAULT_ROUTE 0x0008 /**< Add default route parameter to DIO */
#define BBR_REQUIRE_DAO_REFRESH 0x0010 /**< Do not increment PAN version number when active forces DAO update from nodes*/
#define BBR_GUA_SLAAC 0x0020 /**< in Global prefix use SLAAC address generation to reduce traffic during bootstrap */

/**
* Configure border router features.
Expand Down
15 changes: 12 additions & 3 deletions source/6LoWPAN/ws/ws_bbr_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,8 @@ static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)

uint8_t local_prefix[8] = {0};
uint8_t global_prefix[8] = {0};
uint8_t prefix_flags = 0;
uint32_t prefix_lifetime = 0;

//tr_info("BBR status check");

Expand Down Expand Up @@ -596,7 +598,6 @@ static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)
}
// TODO add global prefix
if (memcmp(global_prefix, ADDR_UNSPECIFIED, 8) != 0) {

tr_info("RPL global prefix activate %s", trace_ipv6_prefix(global_prefix, 64));
// Add default route to RPL
// Enable default routing to backbone
Expand All @@ -606,8 +607,12 @@ static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)
return;
}
}
if (configuration & BBR_GUA_SLAAC) {
prefix_flags |= PIO_A;
prefix_lifetime = WS_ULA_LIFETIME;
}
ws_bbr_dhcp_server_start(cur, global_prefix, cur->ws_info->cfg->bbr.dhcp_address_lifetime);
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_prefix, 64, 0, 0, 0, false);
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, global_prefix, 64, prefix_flags, prefix_lifetime, prefix_lifetime, false);
// no check for failure should have

if (configuration & BBR_GUA_ROUTE) {
Expand All @@ -626,7 +631,11 @@ static void ws_bbr_rpl_status_check(protocol_interface_info_entry_t *cur)
* There is no status checks on prefix adds so this makes sure they are not lost
* DHCP validation should be done also
*/
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, current_global_prefix, 64, 0, 0, 0, false);
if (configuration & BBR_GUA_SLAAC) {
prefix_flags |= PIO_A;
prefix_lifetime = WS_ULA_LIFETIME;
}
rpl_control_update_dodag_prefix(protocol_6lowpan_rpl_root_dodag, current_global_prefix, 64, prefix_flags, prefix_lifetime, prefix_lifetime, false);

if (configuration & BBR_GUA_ROUTE) {
// Add also global prefix and route to RPL
Expand Down
128 changes: 90 additions & 38 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ static int8_t ws_bootstrap_neighbor_set(protocol_interface_info_entry_t *cur, pa

static void ws_bootstrap_candidate_table_reset(protocol_interface_info_entry_t *cur);
static parent_info_t *ws_bootstrap_candidate_parent_get(struct protocol_interface_info_entry *cur, const uint8_t *addr, bool create);
static void ws_bootstrap_candidate_parent_sort(struct protocol_interface_info_entry *cur, parent_info_t *new_entry);

typedef enum {
WS_PARENT_SOFT_SYNCH = 0, /**< let FHSS make decision if synchronization is needed*/
Expand Down Expand Up @@ -289,6 +290,20 @@ static void ws_bootstrap_address_notification_cb(struct protocol_interface_info_
}
}

static void ws_bootstrap_configure_max_retries(protocol_interface_info_entry_t *cur, uint8_t max_mac_retries, uint8_t max_channel_retries)
{
mac_helper_mac_mlme_max_retry_set(cur->id, max_mac_retries);

const fhss_ws_configuration_t *fhss_configuration_cur = ns_fhss_ws_configuration_get(cur->ws_info->fhss_api);
if (fhss_configuration_cur && fhss_configuration_cur->config_parameters.number_of_channel_retries != max_channel_retries) {
fhss_ws_configuration_t fhss_configuration;
memset(&fhss_configuration, 0, sizeof(fhss_ws_configuration_t));
memcpy(&fhss_configuration, ns_fhss_ws_configuration_get(cur->ws_info->fhss_api), sizeof(fhss_ws_configuration_t));
fhss_configuration.config_parameters.number_of_channel_retries = max_channel_retries;
ns_fhss_ws_configuration_set(cur->ws_info->fhss_api, &fhss_configuration);
}
}

static int ws_bootstrap_tasklet_init(protocol_interface_info_entry_t *cur)
{
if (cur->bootStrapId < 0) {
Expand Down Expand Up @@ -601,7 +616,6 @@ static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur)
fhss_configuration.ws_bc_channel_function = (fhss_ws_channel_functions)cur->ws_info->cfg->fhss.fhss_bc_channel_function;
fhss_configuration.fhss_bc_dwell_interval = cur->ws_info->cfg->fhss.fhss_bc_dwell_interval;
fhss_configuration.fhss_broadcast_interval = cur->ws_info->cfg->fhss.fhss_bc_interval;
fhss_configuration.config_parameters.number_of_channel_retries = WS_NUMBER_OF_CHANNEL_RETRIES;
fhss_api = ns_fhss_ws_create(&fhss_configuration, cur->ws_info->fhss_timer_ptr);

if (!fhss_api) {
Expand Down Expand Up @@ -765,7 +779,7 @@ static void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry

void ws_bootstrap_eapol_parent_synch(struct protocol_interface_info_entry *cur, llc_neighbour_req_t *neighbor_info)
{
if (cur->ws_info->configuration_learned || !neighbor_info->ws_neighbor->broadcast_shedule_info_stored || !neighbor_info->ws_neighbor->broadcast_timing_info_stored) {
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER || cur->ws_info->configuration_learned || !neighbor_info->ws_neighbor->broadcast_shedule_info_stored || !neighbor_info->ws_neighbor->broadcast_timing_info_stored) {
return;
}

Expand Down Expand Up @@ -820,6 +834,7 @@ static void ws_bootstrap_ll_address_validate(struct protocol_interface_info_entr
*/
uint16_t ws_etx_read(protocol_interface_info_entry_t *interface, addrtype_t addr_type, const uint8_t *addr_ptr)
{
uint16_t etx;

if (!addr_ptr || !interface) {
return 0;
Expand All @@ -839,7 +854,16 @@ uint16_t ws_etx_read(protocol_interface_info_entry_t *interface, addrtype_t addr
return 0xffff;
}

return etx_local_etx_read(interface->id, attribute_index);
etx = etx_local_etx_read(interface->id, attribute_index);

// If we dont have valid ETX for children we assume good ETX.
// After enough packets is sent to children real calculated ETX is given.
// This might result in ICMP source route errors returned to Border router causing secondary route uses
if (etx == 0xffff && ipv6_neighbour_has_registered_by_eui64(&interface->ipv6_neighbour_cache, mac_neighbor->mac64)) {
return 0x100;
}

return etx;
}
bool ws_bootstrap_nd_ns_transmit(protocol_interface_info_entry_t *cur, ipv6_neighbour_t *entry, bool unicast, uint8_t seq)
{
Expand Down Expand Up @@ -1152,7 +1176,7 @@ static void ws_bootstrap_pan_advertisement_analyse_active(struct protocol_interf
static parent_info_t *ws_bootstrap_candidate_parent_get_best(protocol_interface_info_entry_t *cur)
{
ns_list_foreach_safe(parent_info_t, entry, &cur->ws_info->parent_list_reserved) {
tr_info("candidate list a:%s panid:%x cost:%d size:%d rssi:%d age:%"PRIu32, trace_array(entry->addr, 8), entry->pan_id, entry->pan_information.routing_cost, entry->pan_information.pan_size, entry->signal_dbm, protocol_core_monotonic_time - entry->age);
tr_info("candidate list a:%s panid:%x cost:%d size:%d rssi:%d txFailure:%u age:%"PRIu32, trace_array(entry->addr, 8), entry->pan_id, entry->pan_information.routing_cost, entry->pan_information.pan_size, entry->signal_dbm, entry->tx_fail, protocol_core_monotonic_time - entry->age);
}

return ns_list_get_first(&cur->ws_info->parent_list_reserved);
Expand Down Expand Up @@ -1250,19 +1274,12 @@ static parent_info_t *ws_bootstrap_candidate_parent_allocate(protocol_interface_
} else {
// If there is no free entries always allocate the last one of reserved as it is the worst
entry = ns_list_get_last(&cur->ws_info->parent_list_reserved);
}
return entry;
}

static void ws_bootstrap_candidate_parent_free(protocol_interface_info_entry_t *cur, const uint8_t *addr)
{
ns_list_foreach_safe(parent_info_t, entry, &cur->ws_info->parent_list_reserved) {
if (memcmp(entry->addr, addr, 8) == 0) {
ns_list_remove(&cur->ws_info->parent_list_reserved, entry);
ns_list_add_to_end(&cur->ws_info->parent_list_free, entry);
return;
}
}
if (entry) {
entry->tx_fail = 0;
}
return entry;
}

static parent_info_t *ws_bootstrap_candidate_parent_get(struct protocol_interface_info_entry *cur, const uint8_t *addr, bool create)
Expand All @@ -1278,13 +1295,34 @@ static parent_info_t *ws_bootstrap_candidate_parent_get(struct protocol_interfac
return NULL;
}

static void ws_bootstrap_candidate_parent_mark_failure(protocol_interface_info_entry_t *cur, const uint8_t *addr)
{
parent_info_t *entry = ws_bootstrap_candidate_parent_get(cur, addr, false);
if (entry) {
ns_list_remove(&cur->ws_info->parent_list_reserved, entry);
if (entry->tx_fail >= 2) {
ns_list_add_to_end(&cur->ws_info->parent_list_free, entry);
} else {
entry->tx_fail++;
//New last
ns_list_add_to_end(&cur->ws_info->parent_list_reserved, entry);
ws_bootstrap_candidate_parent_sort(cur, entry);
}

}
}

static bool ws_bootstrap_candidate_parent_compare(parent_info_t *p1, parent_info_t *p2)
{
// Return true if P2 is better
// signal lower than threshold for both
// pan_cost
// signal quality

if (p2->tx_fail > p1->tx_fail) {
return false;
}

if (ws_neighbor_class_rsl_from_dbm_calculate(p1->signal_dbm) < (DEVICE_MIN_SENS + CAND_PARENT_THRESHOLD + CAND_PARENT_HYSTERISIS) &&
ws_neighbor_class_rsl_from_dbm_calculate(p2->signal_dbm) > (DEVICE_MIN_SENS + CAND_PARENT_THRESHOLD + CAND_PARENT_HYSTERISIS)) {
// above threshold is always better than not.
Expand Down Expand Up @@ -1336,11 +1374,15 @@ static void ws_bootstrap_candidate_list_clean(struct protocol_interface_info_ent

static void ws_bootstrap_candidate_parent_sort(struct protocol_interface_info_entry *cur, parent_info_t *new_entry)
{
//Remove from the list

ns_list_foreach_safe(parent_info_t, entry, &cur->ws_info->parent_list_reserved) {

if (entry == new_entry) {
// own entry skip it
continue;
}

if (ws_bootstrap_candidate_parent_compare(entry, new_entry)) {
// New entry is better
//tr_debug("candidate list new is better");
Expand Down Expand Up @@ -1550,7 +1592,6 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
}

if (neighbour_pointer_valid) {
etx_lqi_dbm_update(cur->id, data->mpduLinkQuality, data->signal_dbm, neighbor_info.neighbor->index, neighbor_info.neighbor->mac64);
//Update Neighbor Broadcast and Unicast Parameters
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor_info.ws_neighbor, ws_utt, data->timestamp, (uint8_t *) data->SrcAddr);
ws_neighbor_class_neighbor_unicast_schedule_set(neighbor_info.ws_neighbor, ws_us, &cur->ws_info->hopping_schdule);
Expand Down Expand Up @@ -1639,7 +1680,6 @@ static void ws_bootstrap_pan_config_solicit_analyse(struct protocol_interface_in

llc_neighbour_req_t neighbor_info;
if (ws_bootstrap_neighbor_info_request(cur, data->SrcAddr, &neighbor_info, false)) {
etx_lqi_dbm_update(cur->id, data->mpduLinkQuality, data->signal_dbm, neighbor_info.neighbor->index, neighbor_info.neighbor->mac64);
ws_neighbor_class_neighbor_unicast_time_info_update(neighbor_info.ws_neighbor, ws_utt, data->timestamp, (uint8_t *) data->SrcAddr);
ws_neighbor_class_neighbor_unicast_schedule_set(neighbor_info.ws_neighbor, ws_us, &cur->ws_info->hopping_schdule);
}
Expand Down Expand Up @@ -1901,14 +1941,6 @@ static bool ws_bootstrap_neighbor_info_request(struct protocol_interface_info_en
return false;
}

uint8_t ll_target[16];
ws_bootsrap_create_ll_address(ll_target, mac_64);

if (blacklist_reject(ll_target)) {
// Rejected by blacklist
return false;
}

ws_bootstrap_neighbor_table_clean(interface);

neighbor_buffer->neighbor = ws_bootstrap_mac_neighbor_add(interface, mac_64);
Expand Down Expand Up @@ -1948,6 +1980,15 @@ static void ws_neighbor_entry_remove_notify(mac_neighbor_table_entry_t *entry_pt
ws_bootstrap_neighbor_delete(cur, entry_ptr);
}

static uint32_t ws_probe_init_time_get(protocol_interface_info_entry_t *cur)
{
if (cur->ws_info->cfg->gen.network_size <= NETWORK_SIZE_SMALL) {
return WS_SMALL_PROBE_INIT_BASE_SECONDS;
}

return WS_NORMAL_PROBE_INIT_BASE_SECONDS;
}

static bool ws_neighbor_entry_nud_notify(mac_neighbor_table_entry_t *entry_ptr, void *user_data)
{
uint32_t time_from_start = entry_ptr->link_lifetime - entry_ptr->lifetime;
Expand Down Expand Up @@ -2000,17 +2041,23 @@ static bool ws_neighbor_entry_nud_notify(mac_neighbor_table_entry_t *entry_ptr,
nud_proces = activate_nud;
} else if (etx_entry->etx_samples < WS_NEIGHBOR_ETX_SAMPLE_MAX) {
//Take Random number for trig a prope.
//Small network
//ETX Sample 0: random 1-4
//ETX Sample 1: random 2-8
//ETX Sample 2: random 4-16
//Medium and large
//ETX Sample 0: random 1-8
//ETX Sample 1: random 2-16
//ETX Sample 2: random 4-32

ws_bootsrap_create_ll_address(ll_address, entry_ptr->mac64);
if (!rpl_control_probe_parent_candidate(cur, ll_address)) {
return false;
}


uint32_t probe_period = WS_PROBE_INIT_BASE_SECONDS << etx_entry->etx_samples;
uint32_t probe_period = ws_probe_init_time_get(cur) << etx_entry->etx_samples;
uint32_t time_block = 1 << etx_entry->etx_samples;

if (time_from_start >= probe_period) {
//tr_debug("Link Probe test %u Sample trig", etx_entry->etx_samples);
activate_nud = true;
Expand Down Expand Up @@ -2073,6 +2120,11 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
return -1;
}

if (!etx_allow_drop_for_poor_measurements(WS_ETX_BAD_INIT_LINK_LEVEL, WS_ETX_MAX_BAD_LINK_DROP)) {
etx_storage_list_allocate(cur->id, 0);
return -1;
}

etx_max_update_set(WS_ETX_MAX_UPDATE);
etx_max_set(WS_ETX_MAX);

Expand Down Expand Up @@ -2182,8 +2234,6 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
set_req.value_size = sizeof(bool);
cur->mac_api->mlme_req(cur->mac_api, MLME_SET, &set_req);

mac_helper_mac_mlme_max_retry_set(cur->id, WS_MAX_FRAME_RETRIES);

// Set the default parameters for MPL
cur->mpl_proactive_forwarding = true;

Expand Down Expand Up @@ -2443,7 +2493,8 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
}

ws_set_fhss_hop(cur);

// Set retry configuration for bootstrap ready state
ws_bootstrap_configure_max_retries(cur, WS_MAX_FRAME_RETRIES, WS_NUMBER_OF_CHANNEL_RETRIES);
} else if (event == RPL_EVENT_LOCAL_REPAIR_NO_MORE_DIS) {
/*
* RPL goes to passive mode, but does not require any extra changed
Expand Down Expand Up @@ -2643,8 +2694,6 @@ static bool ws_rpl_new_parent_callback(uint8_t *ll_parent_address, void *handle,
ws_bootstrap_neighbor_set_stable(cur, entry->mac64);
//Copy fhss temporary data
*ws_neigh = entry->neigh_info_list;
//ETX Create here
etx_lqi_dbm_update(cur->id, entry->mpduLinkQuality, entry->signal_dbm, neigh_buffer.neighbor->index, neigh_buffer.neighbor->mac64);
mac_neighbor_table_trusted_neighbor(mac_neighbor_info(cur), neigh_buffer.neighbor, true);
}
ws_llc_free_multicast_temp_entry(cur, entry);
Expand Down Expand Up @@ -2741,9 +2790,6 @@ static void ws_bootstrap_start_discovery(protocol_interface_info_entry_t *cur)
cur->ws_info->pan_timeout_timer = 0;
cur->ws_info->weakest_received_rssi = 0;

// Clear learned neighbours
ws_bootstrap_neighbor_list_clean(cur);

// Clear learned candidate parents
ws_bootstrap_candidate_table_reset(cur);

Expand Down Expand Up @@ -2884,7 +2930,7 @@ static void ws_bootstrap_authentication_completed(protocol_interface_info_entry_
// eapol parent selected is not working
tr_debug("authentication TX failed");

ws_bootstrap_candidate_parent_free(cur, target_eui_64);
ws_bootstrap_candidate_parent_mark_failure(cur, target_eui_64);
// Go back for network scanning
ws_bootstrap_state_change(cur, ER_ACTIVE_SCAN);

Expand All @@ -2906,7 +2952,7 @@ static void ws_bootstrap_authentication_completed(protocol_interface_info_entry_

static const uint8_t *ws_bootstrap_authentication_next_target(protocol_interface_info_entry_t *cur, const uint8_t *previous_eui_64, uint16_t *pan_id)
{
ws_bootstrap_candidate_parent_free(cur, previous_eui_64);
ws_bootstrap_candidate_parent_mark_failure(cur, previous_eui_64);

// Gets best target
parent_info_t *parent_info = ws_bootstrap_candidate_parent_get_best(cur);
Expand Down Expand Up @@ -3262,14 +3308,20 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
// Set PAE port to 10254 and authenticator relay to 10253 (and to own ll address)
ws_pae_controller_authenticator_start(cur, PAE_AUTH_SOCKET_PORT, ll_addr, EAPOL_RELAY_SOCKET_PORT);

// Set retry configuration for bootstrap ready state
ws_bootstrap_configure_max_retries(cur, WS_MAX_FRAME_RETRIES, WS_NUMBER_OF_CHANNEL_RETRIES);

ws_bootstrap_event_operation_start(cur);
break;
}
ws_pae_controller_supp_init(cur);

// Clear learned neighbours
ws_bootstrap_neighbor_list_clean(cur);
// Configure LLC for network discovery
ws_bootstrap_network_discovery_configure(cur);
ws_bootstrap_fhss_activate(cur);
// Set retry configuration for discovery state
ws_bootstrap_configure_max_retries(cur, WS_MAX_FRAME_RETRIES_BOOTSTRAP, WS_NUMBER_OF_CHANNEL_RETRIES_BOOTSTRAP);
// Start network scan
ws_bootstrap_start_discovery(cur);
break;
Expand Down
Loading

0 comments on commit 09d9e24

Please sign in to comment.