From 2d063d3b4af3f416c140773b1cc8892c22c00f4b Mon Sep 17 00:00:00 2001 From: Mika Tervonen Date: Thu, 2 Sep 2021 20:19:21 +0300 Subject: [PATCH] Moved State machine and timer functions to own files Reorganized bootstrap file a bit to place function related to others in closer proximity Moved Wi-SUN FFN functions to own files and renamed --- source/6LoWPAN/ws/ws_bootstrap.c | 520 +++++++++----------------- source/6LoWPAN/ws/ws_bootstrap.h | 8 +- source/6LoWPAN/ws/ws_bootstrap_6lbr.c | 41 ++ source/6LoWPAN/ws/ws_bootstrap_6lbr.h | 4 + source/6LoWPAN/ws/ws_bootstrap_ffn.c | 196 +++++++++- source/6LoWPAN/ws/ws_bootstrap_ffn.h | 4 + source/6LoWPAN/ws/ws_bootstrap_lfn.c | 39 ++ source/6LoWPAN/ws/ws_bootstrap_lfn.h | 4 + source/6LoWPAN/ws/ws_common.c | 19 +- 9 files changed, 480 insertions(+), 355 deletions(-) diff --git a/source/6LoWPAN/ws/ws_bootstrap.c b/source/6LoWPAN/ws/ws_bootstrap.c index c2661a219adc..544bceac453d 100644 --- a/source/6LoWPAN/ws/ws_bootstrap.c +++ b/source/6LoWPAN/ws/ws_bootstrap.c @@ -110,8 +110,8 @@ static ws_nud_table_entry_t *ws_nud_entry_discover(protocol_interface_info_entry static void ws_nud_entry_remove(protocol_interface_info_entry_t *cur, mac_neighbor_table_entry_t *entry_ptr); static bool ws_neighbor_entry_nud_notify(mac_neighbor_table_entry_t *entry_ptr, void *user_data); -static void ws_address_registration_update(protocol_interface_info_entry_t *interface, const uint8_t addr[16]); -static int8_t ws_bootstrap_neighbor_set(protocol_interface_info_entry_t *cur, parent_info_t *parent_ptr, bool clear_list); +static void ws_bootstrap_dhcp_neighbour_update_cb(int8_t interface_id, uint8_t ll_addr[static 16]); +static void ws_bootstrap_dhcp_info_notify_cb(int8_t interface, dhcp_option_notify_t *options, dhcp_server_notify_info_t *server_info); static void ws_bootstrap_test_procedure_trigger_timer(protocol_interface_info_entry_t *cur, uint32_t seconds); @@ -674,7 +674,7 @@ uint16_t ws_randomize_fixed_channel(uint16_t configured_fixed_channel, uint8_t n } } -static int8_t ws_fhss_configure(protocol_interface_info_entry_t *cur, bool discovery) +int8_t ws_fhss_configure(protocol_interface_info_entry_t *cur, bool discovery) { // Read configuration of existing FHSS and start using the default values for any network fhss_ws_configuration_t fhss_configuration; @@ -882,142 +882,6 @@ bool ws_bootstrap_nd_ns_transmit(protocol_interface_info_entry_t *cur, ipv6_neig // True means we skip the message sending return true; } - -static void ws_bootstrap_dhcp_neighbour_update_cb(int8_t interface_id, uint8_t ll_addr[static 16]) -{ - if (memcmp(ll_addr, ADDR_LINK_LOCAL_PREFIX, 8)) { - return; - } - - protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id); - if (!cur) { - return; - } - - uint8_t mac64[8]; - memcpy(mac64, ll_addr + 8, 8); - mac64[0] ^= 2; - ws_bootstrap_mac_neighbor_short_time_set(cur, mac64, WS_NEIGHBOUR_DHCP_ENTRY_LIFETIME); -} - -static void ws_bootstrap_dhcp_info_notify_cb(int8_t interface, dhcp_option_notify_t *options, dhcp_server_notify_info_t *server_info) -{ - protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface); - if (!cur) { - return; - } - uint8_t server_ll64[16]; - memcpy(server_ll64, ADDR_LINK_LOCAL_PREFIX, 8); - - if (server_info->duid_length == 8) { - memcpy(server_ll64 + 8, server_info->duid, 8); - } else { - server_ll64[8] = server_info->duid[0]; - server_ll64[9] = server_info->duid[1]; - server_ll64[10] = server_info->duid[2]; - server_ll64[11] = 0xff; - server_ll64[12] = 0xfe; - server_ll64[13] = server_info->duid[3]; - server_ll64[14] = server_info->duid[4]; - server_ll64[15] = server_info->duid[5]; - } - server_ll64[8] ^= 2; - - switch (options->option_type) { - case DHCPV6_OPTION_VENDOR_SPECIFIC_INFO: - if (options->option.vendor_spesific.enterprise_number != ARM_ENTERPRISE_NUMBER) { - break; - } - while (options->option.vendor_spesific.data_length) { - uint16_t option_type; - char *domain; - uint8_t *address; - uint16_t option_len; - option_len = net_dns_option_vendor_option_data_get_next(options->option.vendor_spesific.data, options->option.vendor_spesific.data_length, &option_type); - tr_debug("DHCP vendor specific data type:%u length %d", option_type, option_len); - //tr_debug("DHCP vendor specific data %s", trace_array(options->option.vendor_spesific.data, options->option.vendor_spesific.data_length)); - - if (option_len == 0) { - // Option fields were corrupted - break; - } - if (option_type == ARM_DHCP_VENDOR_DATA_DNS_QUERY_RESULT) { - // Process ARM DNS query result - domain = NULL; - address = NULL; - if (net_dns_option_vendor_option_data_dns_query_read(options->option.vendor_spesific.data, options->option.vendor_spesific.data_length, &address, &domain) > 0 || - domain || address) { - // Valid ARM DNS query entry - net_dns_query_result_set(interface, address, domain, server_info->life_time); - } - } - if (option_type == ARM_DHCP_VENDOR_DATA_TIME_CONFIGURATION) { - timezone_info_t time_configuration; - if (net_vendor_option_time_configuration_read(options->option.vendor_spesific.data, options->option.vendor_spesific.data_length, &time_configuration.timestamp, &time_configuration.timezone, &time_configuration.deviation, &time_configuration.status)) { - int ret = ns_time_system_timezone_info_notify(&time_configuration); - tr_info("Network Time configuration %s status:%"PRIu16" time stamp: %"PRIu64" deviation: %"PRId16" Time Zone: %"PRId16, ret == 0 ? "notified" : "notify FAILED", time_configuration.status, time_configuration.timestamp, time_configuration.deviation, time_configuration.timezone); - } - } - if (option_type == ARM_DHCP_VENDOR_DATA_NETWORK_TIME) { - // Process ARM Network Time - // Get Current time - // Get Round trip time of the DHCP request - // Estimated error is elapsed time of request - // If current time difference is larger than estimated error update current time - // set the time for server time + *.5 RTT - int32_t era; - uint32_t offset; - if (net_vendor_option_current_time_read(options->option.vendor_spesific.data, options->option.vendor_spesific.data_length, &era, &offset, NULL)) { - uint64_t current_time; - uint64_t network_time = (era * (uint64_t)(4294967296)) + offset - 2208988800; //Convert to First day of Unix (1 Jan 1970) - - tr_debug("Network Time option Era:%"PRId32" Offset:%"PRIu32" rtt: %"PRId32" time: %"PRIu64, era, offset, server_info->rtt, network_time); - if (0 == ns_time_system_time_read(¤t_time)) { - uint64_t difference; - // We only adjust clock if time has drifted more than 10 seconds to avoid constant changing of time - // If Round trip time is very high the accuracy is reduced. - uint32_t estimated_error = 10 + server_info->rtt / 10; - // Take into account the round trip time it took the response to arrive from the time server Write the time. - network_time += server_info->rtt / 20; - - if (current_time > network_time) { - difference = current_time - network_time; - } else { - difference = network_time - current_time; - } - if (difference > estimated_error) { - // Larger than 10 second difference update the time - int ret = ns_time_system_time_write(network_time); - tr_info("Network Time %s: Era:%"PRId32" Offset:%"PRIu32" old time: %"PRIu64" time: %"PRIu64, ret == 0 ? "updated" : "update FAILED", era, offset, current_time, network_time); - } - // System time has been acquired - ns_time_system_time_acquired_set(); - } - } - } - - options->option.vendor_spesific.data_length -= option_len; - options->option.vendor_spesific.data += option_len; - } - break; - - case DHCPV6_OPTION_DNS_SERVERS: - while (options->option.generic.data_length && options->option.generic.data_length >= 16 && options->option.generic.data_length % 16 == 0) { - // Validate payload to have full 16 byte length addresses without any extra bytes - net_dns_server_address_set(interface, server_ll64, options->option.generic.data, server_info->life_time); - options->option.generic.data_length -= 16; - options->option.generic.data += 16; - } - break; - case DHCPV6_OPTION_DOMAIN_LIST: - net_dns_server_search_list_set(interface, server_ll64, options->option.generic.data, options->option.generic.data_length, server_info->life_time); - break; - default: - break; - } - -} - static void ws_bootstrap_memory_configuration() { /* Configure memory limits for garbage collection based on total memory size @@ -1124,43 +988,6 @@ static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur) return ret_val; } -void ws_bootstrap_state_disconnect(protocol_interface_info_entry_t *cur, ws_bootsrap_event_type_e event_type) -{ - if (cur->nwk_bootstrap_state == ER_RPL_NETWORK_LEAVING) { - //Already moved to leaving state. - return; - } - // We are no longer connected - cur->ws_info->connected_time = 0; - - if (cur->rpl_domain && cur->nwk_bootstrap_state == ER_BOOTSRAP_DONE) { - //Stop Asych Timer - ws_bootstrap_asynch_trickle_stop(cur); - tr_debug("Start Network soft leaving"); - if (event_type == WS_FAST_DISCONNECT) { - rpl_control_instant_poison(cur, cur->rpl_domain); - cur->bootsrap_state_machine_cnt = 80; //Give 8 seconds time to send Poison - } else { - rpl_control_poison(cur->rpl_domain, 1); - cur->bootsrap_state_machine_cnt = 6000; //Give 10 minutes time for poison if RPL is not report - } - - } else { - ws_bootstrap_event_discovery_start(cur); - } - cur->nwk_bootstrap_state = ER_RPL_NETWORK_LEAVING; -} - - -void ws_bootstrap_asynch_trickle_stop(protocol_interface_info_entry_t *cur) -{ - cur->ws_info->trickle_pas_running = false; - cur->ws_info->trickle_pa_running = false; - cur->ws_info->trickle_pcs_running = false; - cur->ws_info->trickle_pc_running = false; - cur->ws_info->trickle_pc_consistency_block_period = 0; -} - static int8_t ws_bootstrap_down(protocol_interface_info_entry_t *cur) { if (!cur || !(cur->lowpan_info & INTERFACE_NWK_ACTIVE)) { @@ -1322,7 +1149,7 @@ void ws_bootstrap_candidate_parent_store(parent_info_t *parent, const struct mcp parent->age = protocol_core_monotonic_time; } -static parent_info_t *ws_bootstrap_candidate_parent_get_best(protocol_interface_info_entry_t *cur) +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 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); @@ -2160,19 +1987,6 @@ void ws_bootstrap_fhss_activate(protocol_interface_info_entry_t *cur) return; } -static void ws_bootstrap_network_configuration_learn(protocol_interface_info_entry_t *cur) -{ - tr_debug("Start using PAN configuration"); - - // Timing information can be modified here - ws_llc_set_pan_information_pointer(cur, &cur->ws_info->pan_information); - uint8_t *gtkhash = ws_pae_controller_gtk_hash_ptr_get(cur); - ws_llc_set_gtkhash(cur, gtkhash); - // TODO update own fhss schedules we are starting to follow first parent - - return; -} - void ws_bootstrap_ip_stack_reset(protocol_interface_info_entry_t *cur) { tr_debug("ip stack reset"); @@ -2209,6 +2023,140 @@ static void ws_set_fhss_hop(protocol_interface_info_entry_t *cur) tr_debug("own hop: %u, own rank: %u, rank inc: %u", own_hop, own_rank, rank_inc); } +static void ws_bootstrap_dhcp_neighbour_update_cb(int8_t interface_id, uint8_t ll_addr[static 16]) +{ + if (memcmp(ll_addr, ADDR_LINK_LOCAL_PREFIX, 8)) { + return; + } + + protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id); + if (!cur) { + return; + } + + uint8_t mac64[8]; + memcpy(mac64, ll_addr + 8, 8); + mac64[0] ^= 2; + ws_bootstrap_mac_neighbor_short_time_set(cur, mac64, WS_NEIGHBOUR_DHCP_ENTRY_LIFETIME); +} + +static void ws_bootstrap_dhcp_info_notify_cb(int8_t interface, dhcp_option_notify_t *options, dhcp_server_notify_info_t *server_info) +{ + protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface); + if (!cur) { + return; + } + uint8_t server_ll64[16]; + memcpy(server_ll64, ADDR_LINK_LOCAL_PREFIX, 8); + + if (server_info->duid_length == 8) { + memcpy(server_ll64 + 8, server_info->duid, 8); + } else { + server_ll64[8] = server_info->duid[0]; + server_ll64[9] = server_info->duid[1]; + server_ll64[10] = server_info->duid[2]; + server_ll64[11] = 0xff; + server_ll64[12] = 0xfe; + server_ll64[13] = server_info->duid[3]; + server_ll64[14] = server_info->duid[4]; + server_ll64[15] = server_info->duid[5]; + } + server_ll64[8] ^= 2; + + switch (options->option_type) { + case DHCPV6_OPTION_VENDOR_SPECIFIC_INFO: + if (options->option.vendor_spesific.enterprise_number != ARM_ENTERPRISE_NUMBER) { + break; + } + while (options->option.vendor_spesific.data_length) { + uint16_t option_type; + char *domain; + uint8_t *address; + uint16_t option_len; + option_len = net_dns_option_vendor_option_data_get_next(options->option.vendor_spesific.data, options->option.vendor_spesific.data_length, &option_type); + tr_debug("DHCP vendor specific data type:%u length %d", option_type, option_len); + //tr_debug("DHCP vendor specific data %s", trace_array(options->option.vendor_spesific.data, options->option.vendor_spesific.data_length)); + + if (option_len == 0) { + // Option fields were corrupted + break; + } + if (option_type == ARM_DHCP_VENDOR_DATA_DNS_QUERY_RESULT) { + // Process ARM DNS query result + domain = NULL; + address = NULL; + if (net_dns_option_vendor_option_data_dns_query_read(options->option.vendor_spesific.data, options->option.vendor_spesific.data_length, &address, &domain) > 0 || + domain || address) { + // Valid ARM DNS query entry + net_dns_query_result_set(interface, address, domain, server_info->life_time); + } + } + if (option_type == ARM_DHCP_VENDOR_DATA_TIME_CONFIGURATION) { + timezone_info_t time_configuration; + if (net_vendor_option_time_configuration_read(options->option.vendor_spesific.data, options->option.vendor_spesific.data_length, &time_configuration.timestamp, &time_configuration.timezone, &time_configuration.deviation, &time_configuration.status)) { + int ret = ns_time_system_timezone_info_notify(&time_configuration); + tr_info("Network Time configuration %s status:%"PRIu16" time stamp: %"PRIu64" deviation: %"PRId16" Time Zone: %"PRId16, ret == 0 ? "notified" : "notify FAILED", time_configuration.status, time_configuration.timestamp, time_configuration.deviation, time_configuration.timezone); + } + } + if (option_type == ARM_DHCP_VENDOR_DATA_NETWORK_TIME) { + // Process ARM Network Time + // Get Current time + // Get Round trip time of the DHCP request + // Estimated error is elapsed time of request + // If current time difference is larger than estimated error update current time + // set the time for server time + *.5 RTT + int32_t era; + uint32_t offset; + if (net_vendor_option_current_time_read(options->option.vendor_spesific.data, options->option.vendor_spesific.data_length, &era, &offset, NULL)) { + uint64_t current_time; + uint64_t network_time = (era * (uint64_t)(4294967296)) + offset - 2208988800; //Convert to First day of Unix (1 Jan 1970) + + tr_debug("Network Time option Era:%"PRId32" Offset:%"PRIu32" rtt: %"PRId32" time: %"PRIu64, era, offset, server_info->rtt, network_time); + if (0 == ns_time_system_time_read(¤t_time)) { + uint64_t difference; + // We only adjust clock if time has drifted more than 10 seconds to avoid constant changing of time + // If Round trip time is very high the accuracy is reduced. + uint32_t estimated_error = 10 + server_info->rtt / 10; + // Take into account the round trip time it took the response to arrive from the time server Write the time. + network_time += server_info->rtt / 20; + + if (current_time > network_time) { + difference = current_time - network_time; + } else { + difference = network_time - current_time; + } + if (difference > estimated_error) { + // Larger than 10 second difference update the time + int ret = ns_time_system_time_write(network_time); + tr_info("Network Time %s: Era:%"PRId32" Offset:%"PRIu32" old time: %"PRIu64" time: %"PRIu64, ret == 0 ? "updated" : "update FAILED", era, offset, current_time, network_time); + } + // System time has been acquired + ns_time_system_time_acquired_set(); + } + } + } + + options->option.vendor_spesific.data_length -= option_len; + options->option.vendor_spesific.data += option_len; + } + break; + + case DHCPV6_OPTION_DNS_SERVERS: + while (options->option.generic.data_length && options->option.generic.data_length >= 16 && options->option.generic.data_length % 16 == 0) { + // Validate payload to have full 16 byte length addresses without any extra bytes + net_dns_server_address_set(interface, server_ll64, options->option.generic.data, server_info->life_time); + options->option.generic.data_length -= 16; + options->option.generic.data += 16; + } + break; + case DHCPV6_OPTION_DOMAIN_LIST: + net_dns_server_search_list_set(interface, server_ll64, options->option.generic.data, options->option.generic.data_length, server_info->life_time); + break; + default: + break; + } + +} static void ws_dhcp_client_global_adress_cb(int8_t interface, uint8_t dhcp_addr[static 16], uint8_t prefix[static 16], bool register_status) { @@ -2240,7 +2188,7 @@ void ws_dhcp_client_address_delete(protocol_interface_info_entry_t *cur, uint8_t dhcp_client_global_address_delete(cur->id, NULL, prefix); } -static void ws_address_registration_update(protocol_interface_info_entry_t *interface, const uint8_t addr[16]) +void ws_address_registration_update(protocol_interface_info_entry_t *interface, const uint8_t addr[16]) { rpl_control_register_address(interface, addr); // Timer is used only to track full registrations @@ -2695,20 +2643,6 @@ void ws_bootstrap_network_start(protocol_interface_info_entry_t *cur) ws_llc_set_pan_information_pointer(cur, &cur->ws_info->pan_information); } -void ws_bootstrap_network_discovery_configure(protocol_interface_info_entry_t *cur) -{ - // Reset information to defaults - cur->ws_info->network_pan_id = 0xffff; - - ws_common_regulatory_domain_config(cur, &cur->ws_info->hopping_schdule); - ws_bootstrap_set_domain_rf_config(cur); - ws_fhss_configure(cur, true); - - //Set Network names, Pan information configure, hopping schedule & GTKHash - ws_llc_set_network_name(cur, (uint8_t *)cur->ws_info->cfg->gen.network_name, strlen(cur->ws_info->cfg->gen.network_name)); -} - - void ws_bootstrap_advertise_start(protocol_interface_info_entry_t *cur) { cur->ws_info->trickle_pa_running = true; @@ -2725,7 +2659,7 @@ static void ws_bootstrap_pan_version_increment(protocol_interface_info_entry_t * } // Start authentication -static void ws_bootstrap_start_authentication(protocol_interface_info_entry_t *cur) +void ws_bootstrap_start_authentication(protocol_interface_info_entry_t *cur) { // Set PAN ID and network name to controller 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); @@ -3102,7 +3036,7 @@ static void ws_bootstrap_event_handler(arm_event_s *event) } } -static int8_t ws_bootstrap_neighbor_set(protocol_interface_info_entry_t *cur, parent_info_t *parent_ptr, bool clear_list) +int8_t ws_bootstrap_neighbor_set(protocol_interface_info_entry_t *cur, parent_info_t *parent_ptr, bool clear_list) { uint16_t pan_id = cur->ws_info->network_pan_id; @@ -3138,69 +3072,31 @@ static int8_t ws_bootstrap_neighbor_set(protocol_interface_info_entry_t *cur, pa * State machine * * */ -void ws_bootstrap_network_scan_process(protocol_interface_info_entry_t *cur) -{ - - parent_info_t *selected_parent_ptr; - - tr_debug("analyze network discovery result"); - -select_best_candidate: - selected_parent_ptr = ws_bootstrap_candidate_parent_get_best(cur); - - if (!selected_parent_ptr) { - // Configure LLC for network discovery - ws_bootstrap_network_discovery_configure(cur); - // randomize new channel and start MAC - ws_bootstrap_fhss_activate(cur); - // Next check will be after one trickle - uint32_t random_start = cur->ws_info->trickle_params_pan_discovery.Imin + randLIB_get_random_in_range(0, cur->ws_info->trickle_params_pan_discovery.Imin); - if (random_start > 0xffff) { - random_start = 0xffff; - } - cur->bootsrap_state_machine_cnt = random_start; - - tr_info("Making parent selection in %u s", (cur->bootsrap_state_machine_cnt / 10)); - return; - } - tr_info("selected parent:%s panid %u", trace_array(selected_parent_ptr->addr, 8), selected_parent_ptr->pan_id); - - if (ws_bootstrap_neighbor_set(cur, selected_parent_ptr, false) < 0) { - goto select_best_candidate; - } - - ws_pae_controller_set_target(cur, selected_parent_ptr->pan_id, selected_parent_ptr->addr); // temporary!!! store since auth - ws_bootstrap_event_authentication_start(cur); - return; -} - -void ws_bootstrap_configure_process(protocol_interface_info_entry_t *cur) +void ws_bootstrap_state_disconnect(protocol_interface_info_entry_t *cur, ws_bootsrap_event_type_e event_type) { - - if (cur->ws_info->configuration_learned) { - ws_bootstrap_network_configuration_learn(cur); - ws_bootstrap_event_operation_start(cur); + if (cur->nwk_bootstrap_state == ER_RPL_NETWORK_LEAVING) { + //Already moved to leaving state. return; } - return; -} -void ws_bootstrap_rpl_wait_process(protocol_interface_info_entry_t *cur) -{ + // We are no longer connected + cur->ws_info->connected_time = 0; - if (cur->ws_info->rpl_state == RPL_EVENT_DAO_DONE) { - // RPL routing is ready - cur->ws_info->connected_time = cur->ws_info->uptime; - ws_bootstrap_event_routing_ready(cur); - } else if (!rpl_control_have_dodag(cur->rpl_domain)) { - // RPL not ready send DIS message if possible - if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_ROUTER) { - // TODO Multicast DIS should be sent only if no DIO heard for some time - rpl_control_transmit_dis(cur->rpl_domain, cur, 0, 0, NULL, 0, ADDR_LINK_LOCAL_ALL_RPL_NODES); + if (cur->rpl_domain && cur->nwk_bootstrap_state == ER_BOOTSRAP_DONE) { + //Stop Asych Timer + ws_bootstrap_asynch_trickle_stop(cur); + tr_debug("Start Network soft leaving"); + if (event_type == WS_FAST_DISCONNECT) { + rpl_control_instant_poison(cur, cur->rpl_domain); + cur->bootsrap_state_machine_cnt = 80; //Give 8 seconds time to send Poison + } else { + rpl_control_poison(cur->rpl_domain, 1); + cur->bootsrap_state_machine_cnt = 6000; //Give 10 minutes time for poison if RPL is not report } - // set timer for next DIS - cur->bootsrap_state_machine_cnt = randLIB_get_random_in_range(WS_RPL_DIS_TIMEOUT / 2, WS_RPL_DIS_TIMEOUT); + + } else { + ws_bootstrap_event_discovery_start(cur); } - return; + cur->nwk_bootstrap_state = ER_RPL_NETWORK_LEAVING; } bool ws_bootstrap_state_discovery(struct protocol_interface_info_entry *cur) @@ -3257,52 +3153,6 @@ void ws_bootstrap_network_down(protocol_interface_info_entry_t *cur) ws_nwk_event_post(cur, ARM_NWK_NWK_CONNECTION_DOWN); } -void ws_bootstrap_state_machine(protocol_interface_info_entry_t *cur) -{ - - switch (cur->nwk_bootstrap_state) { - case ER_WAIT_RESTART: - tr_debug("WS SM:Wait for startup"); - ws_bootstrap_event_discovery_start(cur); - break; - case ER_ACTIVE_SCAN: - tr_debug("WS SM:Active Scan"); - ws_bootstrap_network_scan_process(cur); - break; - case ER_SCAN: - tr_debug("WS SM:configuration Scan"); - ws_bootstrap_configure_process(cur); - break; - case ER_PANA_AUTH: - tr_info("authentication start"); - // Advertisements stopped during the EAPOL - ws_bootstrap_asynch_trickle_stop(cur); - ws_fhss_configure(cur, false); - int8_t new_default = cur->ws_info->weakest_received_rssi - 1; - if ((new_default < CCA_DEFAULT_DBM) && (new_default >= CCA_LOW_LIMIT) && (new_default <= CCA_HIGH_LIMIT)) { - // Restart automatic CCA threshold using weakest received RSSI as new default - mac_helper_start_auto_cca_threshold(cur->id, cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->weakest_received_rssi - 1, CCA_HIGH_LIMIT, CCA_LOW_LIMIT); - } - ws_bootstrap_start_authentication(cur); - break; - case ER_RPL_SCAN: - tr_debug("WS SM:Wait RPL to contact DODAG root"); - ws_bootstrap_rpl_wait_process(cur); - break; - case ER_BOOTSRAP_DONE: - tr_debug("WS SM:Bootstrap Done"); - // Bootstrap_done event to application - nwk_bootsrap_state_update(ARM_NWK_BOOTSTRAP_READY, cur); - break; - case ER_RPL_NETWORK_LEAVING: - tr_debug("WS SM:RPL Leaving ready trigger discovery"); - ws_bootstrap_event_discovery_start(cur); - break; - default: - tr_warn("WS SM:Invalid state %d", cur->nwk_bootstrap_state); - } -} - void ws_bootstrap_trickle_timer(protocol_interface_info_entry_t *cur, uint16_t ticks) { if (cur->ws_info->trickle_pas_running && @@ -3364,50 +3214,18 @@ void ws_bootstrap_trickle_timer(protocol_interface_info_entry_t *cur, uint16_t t } } +void ws_bootstrap_asynch_trickle_stop(protocol_interface_info_entry_t *cur) +{ + cur->ws_info->trickle_pas_running = false; + cur->ws_info->trickle_pa_running = false; + cur->ws_info->trickle_pcs_running = false; + cur->ws_info->trickle_pc_running = false; + cur->ws_info->trickle_pc_consistency_block_period = 0; +} + void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds) { - /* Border router keep alive check - */ - if (cur->ws_info->pan_timeout_timer) { - // PAN version timer running - if (cur->ws_info->pan_timeout_timer > seconds) { - cur->ws_info->pan_timeout_timer -= seconds; - if (cur->ws_info->pan_timeout_timer < cur->ws_info->cfg->timing.pan_timeout / 10) { - /* pan timeout is closing need to verify that DAO is tested before the pan times out. - This will give some extra time for RPL to find better parents. - Border router liveliness can be checked from version number change or from successful DAO registrations - in this case there has not been any version number changes during this PAN lifetime. - */ - rpl_control_dao_timeout(cur->rpl_domain, 20); - } - } else { - // Border router has timed out - //Clear Timeout timer - cur->ws_info->pan_timeout_timer = 0; - tr_warn("Border router has timed out"); - ws_bootstrap_event_disconnect(cur, WS_FAST_DISCONNECT); - } - } - if (cur->ws_info->aro_registration_timer) { - if (cur->ws_info->aro_registration_timer > seconds) { - cur->ws_info->aro_registration_timer -= seconds; - } else { - // Update all addressess. This function will update the timer value if needed - cur->ws_info->aro_registration_timer = 0; - ws_address_registration_update(cur, NULL); - } - } - - if (cur->ws_info->ws_bsi_block.block_time) { - if (cur->ws_info->ws_bsi_block.block_time > seconds) { - cur->ws_info->ws_bsi_block.block_time -= seconds; - } else { - //Clear A BSI blokker - cur->ws_info->ws_bsi_block.block_time = 0; - cur->ws_info->ws_bsi_block.old_bsi = 0; - } - } /*Update join state statistics*/ if (ws_bootstrap_state_discovery(cur)) { ws_stats_update(cur, STATS_WS_STATE_1, 1); diff --git a/source/6LoWPAN/ws/ws_bootstrap.h b/source/6LoWPAN/ws/ws_bootstrap.h index 61c344068519..95e95106cbf1 100644 --- a/source/6LoWPAN/ws/ws_bootstrap.h +++ b/source/6LoWPAN/ws/ws_bootstrap.h @@ -145,6 +145,9 @@ void ws_bootstrap_test_procedure_trigger_exec(protocol_interface_info_entry_t *c void ws_bootstrap_network_down(protocol_interface_info_entry_t *cur); +// Bootstrap functions +void ws_bootstrap_start_authentication(protocol_interface_info_entry_t *cur); + // Bootstrap state machine state Functions bool ws_bootstrap_state_discovery(struct protocol_interface_info_entry *cur); @@ -160,15 +163,19 @@ void ws_bootstrap_candidate_parent_store(parent_info_t *parent, const struct mcp void ws_bootstrap_candidate_table_reset(protocol_interface_info_entry_t *cur); parent_info_t *ws_bootstrap_candidate_parent_get(struct protocol_interface_info_entry *cur, const uint8_t *addr, bool create); void ws_bootstrap_candidate_parent_sort(struct protocol_interface_info_entry *cur, parent_info_t *new_entry); +parent_info_t *ws_bootstrap_candidate_parent_get_best(protocol_interface_info_entry_t *cur); void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry *cur, struct llc_neighbour_req *neighbor_info, ws_parent_synch_e synch_req); void ws_bootstrap_parent_confirm(protocol_interface_info_entry_t *cur, struct rpl_instance *instance); bool ws_bootstrap_neighbor_info_request(struct protocol_interface_info_entry *interface, const uint8_t *mac_64, struct llc_neighbour_req *neighbor_buffer, bool request_new); void ws_bootstrap_neighbor_list_clean(struct protocol_interface_info_entry *interface); +int8_t ws_bootstrap_neighbor_set(protocol_interface_info_entry_t *cur, parent_info_t *parent_ptr, bool clear_list); void ws_nud_table_reset(protocol_interface_info_entry_t *cur); +void ws_address_registration_update(protocol_interface_info_entry_t *interface, const uint8_t addr[16]); void ws_bootstrap_configure_csma_ca_backoffs(protocol_interface_info_entry_t *cur, uint8_t max_backoffs, uint8_t min_be, uint8_t max_be); +int8_t ws_fhss_configure(protocol_interface_info_entry_t *cur, bool discovery); void ws_fhss_configure_channel_masks(protocol_interface_info_entry_t *cur, fhss_ws_configuration_t *fhss_configuration); int8_t ws_fhss_set_defaults(protocol_interface_info_entry_t *cur, fhss_ws_configuration_t *fhss_configuration); void ws_bootstrap_fhss_activate(protocol_interface_info_entry_t *cur); @@ -190,7 +197,6 @@ void ws_bootstrap_packet_congestion_init(protocol_interface_info_entry_t *cur); void ws_bootstrap_asynch_trickle_stop(protocol_interface_info_entry_t *cur); void ws_bootstrap_advertise_start(protocol_interface_info_entry_t *cur); -void ws_bootstrap_network_discovery_configure(protocol_interface_info_entry_t *cur); void ws_bootstrap_network_start(protocol_interface_info_entry_t *cur); diff --git a/source/6LoWPAN/ws/ws_bootstrap_6lbr.c b/source/6LoWPAN/ws/ws_bootstrap_6lbr.c index 78f4d2065d13..3ab1aa5146e7 100644 --- a/source/6LoWPAN/ws/ws_bootstrap_6lbr.c +++ b/source/6LoWPAN/ws/ws_bootstrap_6lbr.c @@ -439,4 +439,45 @@ void ws_bootstrap_6lbr_event_handler(protocol_interface_info_entry_t *cur, arm_e } } +void ws_bootstrap_6lbr_state_machine(protocol_interface_info_entry_t *cur) +{ + + switch (cur->nwk_bootstrap_state) { + case ER_WAIT_RESTART: + tr_debug("WS SM:Wait for startup"); + ws_bootstrap_event_discovery_start(cur); + break; + case ER_ACTIVE_SCAN: + tr_debug("WS SM:Active Scan"); + break; + case ER_SCAN: + tr_debug("WS SM:configuration Scan"); + break; + case ER_PANA_AUTH: + tr_info("authentication start"); + break; + case ER_RPL_SCAN: + tr_debug("WS SM:Wait RPL to contact DODAG root"); + break; + case ER_BOOTSRAP_DONE: + tr_debug("WS SM:Bootstrap Done"); + // Bootstrap_done event to application + nwk_bootsrap_state_update(ARM_NWK_BOOTSTRAP_READY, cur); + break; + case ER_RPL_NETWORK_LEAVING: + tr_debug("WS SM:RPL Leaving ready trigger discovery"); + ws_bootstrap_event_discovery_start(cur); + break; + default: + tr_warn("WS SM:Invalid state %d", cur->nwk_bootstrap_state); + } +} + +void ws_bootstrap_6lbr_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds) +{ + (void)cur; + (void)seconds; +} + + #endif //HAVE_WS_BORDER_ROUTER && HAVE_WS diff --git a/source/6LoWPAN/ws/ws_bootstrap_6lbr.h b/source/6LoWPAN/ws/ws_bootstrap_6lbr.h index 2ca51c5c05ca..5517793fb515 100644 --- a/source/6LoWPAN/ws/ws_bootstrap_6lbr.h +++ b/source/6LoWPAN/ws/ws_bootstrap_6lbr.h @@ -23,6 +23,8 @@ void ws_bootstrap_6lbr_asynch_ind(struct protocol_interface_info_entry *cur, const struct mcps_data_ind_s *data, const struct mcps_data_ie_list *ie_ext, uint8_t message_type); void ws_bootstrap_6lbr_asynch_confirm(struct protocol_interface_info_entry *interface, uint8_t asynch_message); void ws_bootstrap_6lbr_event_handler(protocol_interface_info_entry_t *cur, arm_event_s *event); +void ws_bootstrap_6lbr_state_machine(protocol_interface_info_entry_t *cur); +void ws_bootstrap_6lbr_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds); #define wisun_mode_border_router(cur) (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) @@ -31,6 +33,8 @@ void ws_bootstrap_6lbr_event_handler(protocol_interface_info_entry_t *cur, arm_e #define ws_bootstrap_6lbr_asynch_ind(cur, data, ie_ext, message_type) ((void) 0) #define ws_bootstrap_6lbr_asynch_confirm(interface, asynch_message) ((void) 0) #define ws_bootstrap_6lbr_event_handler(cur, event) ((void) 0) +#define ws_bootstrap_6lbr_state_machine(cur) ((void) 0) +#define ws_bootstrap_6lbr_seconds_timer(cur, seconds) ((void) 0) #define wisun_mode_border_router(cur) (false) diff --git a/source/6LoWPAN/ws/ws_bootstrap_ffn.c b/source/6LoWPAN/ws/ws_bootstrap_ffn.c index 4384129a640a..e74263c21e19 100644 --- a/source/6LoWPAN/ws/ws_bootstrap_ffn.c +++ b/source/6LoWPAN/ws/ws_bootstrap_ffn.c @@ -134,6 +134,19 @@ static void ws_bootstrap_ffn_pan_information_store(struct protocol_interface_inf return; } +void ws_bootstrap_ffn_network_discovery_configure(protocol_interface_info_entry_t *cur) +{ + // Reset information to defaults + cur->ws_info->network_pan_id = 0xffff; + + ws_common_regulatory_domain_config(cur, &cur->ws_info->hopping_schdule); + ws_bootstrap_set_domain_rf_config(cur); + ws_fhss_configure(cur, true); + + //Set Network names, Pan information configure, hopping schedule & GTKHash + ws_llc_set_network_name(cur, (uint8_t *)cur->ws_info->cfg->gen.network_name, strlen(cur->ws_info->cfg->gen.network_name)); +} + // Start network scan static void ws_bootstrap_ffn_start_discovery(protocol_interface_info_entry_t *cur) { @@ -193,7 +206,6 @@ static void ws_bootstrap_ffn_start_discovery(protocol_interface_info_entry_t *cu tr_info("Making parent selection in %u s", (cur->bootsrap_state_machine_cnt / 10)); } - // Start configuration learning static void ws_bootstrap_ffn_start_configuration_learn(protocol_interface_info_entry_t *cur) { @@ -214,6 +226,19 @@ static void ws_bootstrap_ffn_start_configuration_learn(protocol_interface_info_e trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config_solicit, &cur->ws_info->trickle_params_pan_discovery); } +static void ws_bootstrap_ffn_network_configuration_learn(protocol_interface_info_entry_t *cur) +{ + tr_debug("Start using PAN configuration"); + + // Timing information can be modified here + ws_llc_set_pan_information_pointer(cur, &cur->ws_info->pan_information); + uint8_t *gtkhash = ws_pae_controller_gtk_hash_ptr_get(cur); + ws_llc_set_gtkhash(cur, gtkhash); + // TODO update own fhss schedules we are starting to follow first parent + + return; +} + static void ws_bootstrap_ffn_pan_advertisement_analyse_active(struct protocol_interface_info_entry *cur, ws_pan_information_t *pan_information) { /* In Active state @@ -736,7 +761,7 @@ void ws_bootstrap_ffn_event_handler(protocol_interface_info_entry_t *cur, arm_ev // Clear learned neighbours ws_bootstrap_neighbor_list_clean(cur); // Configure LLC for network discovery - ws_bootstrap_network_discovery_configure(cur); + ws_bootstrap_ffn_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); @@ -802,4 +827,171 @@ void ws_bootstrap_ffn_event_handler(protocol_interface_info_entry_t *cur, arm_ev } } +/* + * Statemachine state functions + * */ + +static void ws_bootstrap_ffn_network_scan_process(protocol_interface_info_entry_t *cur) +{ + + parent_info_t *selected_parent_ptr; + + tr_debug("analyze network discovery result"); + +select_best_candidate: + selected_parent_ptr = ws_bootstrap_candidate_parent_get_best(cur); + + if (!selected_parent_ptr) { + // Configure LLC for network discovery + ws_bootstrap_ffn_network_discovery_configure(cur); + // randomize new channel and start MAC + ws_bootstrap_fhss_activate(cur); + // Next check will be after one trickle + uint32_t random_start = cur->ws_info->trickle_params_pan_discovery.Imin + randLIB_get_random_in_range(0, cur->ws_info->trickle_params_pan_discovery.Imin); + if (random_start > 0xffff) { + random_start = 0xffff; + } + cur->bootsrap_state_machine_cnt = random_start; + + tr_info("Making parent selection in %u s", (cur->bootsrap_state_machine_cnt / 10)); + return; + } + tr_info("selected parent:%s panid %u", trace_array(selected_parent_ptr->addr, 8), selected_parent_ptr->pan_id); + + if (ws_bootstrap_neighbor_set(cur, selected_parent_ptr, false) < 0) { + goto select_best_candidate; + } + + ws_pae_controller_set_target(cur, selected_parent_ptr->pan_id, selected_parent_ptr->addr); // temporary!!! store since auth + ws_bootstrap_event_authentication_start(cur); + return; +} + +static void ws_bootstrap_ffn_configure_process(protocol_interface_info_entry_t *cur) +{ + + if (cur->ws_info->configuration_learned) { + ws_bootstrap_ffn_network_configuration_learn(cur); + ws_bootstrap_event_operation_start(cur); + return; + } + return; +} + +void ws_bootstrap_ffn_rpl_wait_process(protocol_interface_info_entry_t *cur) +{ + + if (cur->ws_info->rpl_state == RPL_EVENT_DAO_DONE) { + // RPL routing is ready + cur->ws_info->connected_time = cur->ws_info->uptime; + ws_bootstrap_event_routing_ready(cur); + } else if (!rpl_control_have_dodag(cur->rpl_domain)) { + // RPL not ready send DIS message if possible + if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_ROUTER) { + // TODO Multicast DIS should be sent only if no DIO heard for some time + rpl_control_transmit_dis(cur->rpl_domain, cur, 0, 0, NULL, 0, ADDR_LINK_LOCAL_ALL_RPL_NODES); + } + // set timer for next DIS + cur->bootsrap_state_machine_cnt = randLIB_get_random_in_range(WS_RPL_DIS_TIMEOUT / 2, WS_RPL_DIS_TIMEOUT); + } + return; +} + + +/* + * State machine + */ + +void ws_bootstrap_ffn_state_machine(protocol_interface_info_entry_t *cur) +{ + + switch (cur->nwk_bootstrap_state) { + case ER_WAIT_RESTART: + tr_debug("WS SM:Wait for startup"); + ws_bootstrap_event_discovery_start(cur); + break; + case ER_ACTIVE_SCAN: + tr_debug("WS SM:Active Scan"); + ws_bootstrap_ffn_network_scan_process(cur); + break; + case ER_SCAN: + tr_debug("WS SM:configuration Scan"); + ws_bootstrap_ffn_configure_process(cur); + break; + case ER_PANA_AUTH: + tr_info("authentication start"); + // Advertisements stopped during the EAPOL + ws_bootstrap_asynch_trickle_stop(cur); + ws_fhss_configure(cur, false); + int8_t new_default = cur->ws_info->weakest_received_rssi - 1; + if ((new_default < CCA_DEFAULT_DBM) && (new_default >= CCA_LOW_LIMIT) && (new_default <= CCA_HIGH_LIMIT)) { + // Restart automatic CCA threshold using weakest received RSSI as new default + mac_helper_start_auto_cca_threshold(cur->id, cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->weakest_received_rssi - 1, CCA_HIGH_LIMIT, CCA_LOW_LIMIT); + } + ws_bootstrap_start_authentication(cur); + break; + case ER_RPL_SCAN: + tr_debug("WS SM:Wait RPL to contact DODAG root"); + ws_bootstrap_ffn_rpl_wait_process(cur); + break; + case ER_BOOTSRAP_DONE: + tr_debug("WS SM:Bootstrap Done"); + // Bootstrap_done event to application + nwk_bootsrap_state_update(ARM_NWK_BOOTSTRAP_READY, cur); + break; + case ER_RPL_NETWORK_LEAVING: + tr_debug("WS SM:RPL Leaving ready trigger discovery"); + ws_bootstrap_event_discovery_start(cur); + break; + default: + tr_warn("WS SM:Invalid state %d", cur->nwk_bootstrap_state); + } +} + +void ws_bootstrap_ffn_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds) +{ + /* Border router keep alive check + */ + if (cur->ws_info->pan_timeout_timer) { + // PAN version timer running + if (cur->ws_info->pan_timeout_timer > seconds) { + cur->ws_info->pan_timeout_timer -= seconds; + if (cur->ws_info->pan_timeout_timer < cur->ws_info->cfg->timing.pan_timeout / 10) { + /* pan timeout is closing need to verify that DAO is tested before the pan times out. + This will give some extra time for RPL to find better parents. + Border router liveliness can be checked from version number change or from successful DAO registrations + in this case there has not been any version number changes during this PAN lifetime. + */ + rpl_control_dao_timeout(cur->rpl_domain, 20); + } + } else { + // Border router has timed out + //Clear Timeout timer + cur->ws_info->pan_timeout_timer = 0; + tr_warn("Border router has timed out"); + ws_bootstrap_event_disconnect(cur, WS_FAST_DISCONNECT); + } + } + if (cur->ws_info->aro_registration_timer) { + if (cur->ws_info->aro_registration_timer > seconds) { + cur->ws_info->aro_registration_timer -= seconds; + } else { + // Update all addressess. This function will update the timer value if needed + cur->ws_info->aro_registration_timer = 0; + ws_address_registration_update(cur, NULL); + } + } + + if (cur->ws_info->ws_bsi_block.block_time) { + if (cur->ws_info->ws_bsi_block.block_time > seconds) { + cur->ws_info->ws_bsi_block.block_time -= seconds; + } else { + //Clear A BSI blokker + cur->ws_info->ws_bsi_block.block_time = 0; + cur->ws_info->ws_bsi_block.old_bsi = 0; + } + } +} + + #endif //HAVE_WS_BORDER_ROUTER && HAVE_WS diff --git a/source/6LoWPAN/ws/ws_bootstrap_ffn.h b/source/6LoWPAN/ws/ws_bootstrap_ffn.h index 920851eff0a1..fcc9dd25d613 100644 --- a/source/6LoWPAN/ws/ws_bootstrap_ffn.h +++ b/source/6LoWPAN/ws/ws_bootstrap_ffn.h @@ -23,6 +23,8 @@ void ws_bootstrap_ffn_asynch_ind(struct protocol_interface_info_entry *cur, const struct mcps_data_ind_s *data, const struct mcps_data_ie_list *ie_ext, uint8_t message_type); void ws_bootstrap_ffn_asynch_confirm(struct protocol_interface_info_entry *interface, uint8_t asynch_message); void ws_bootstrap_ffn_event_handler(protocol_interface_info_entry_t *cur, arm_event_s *event); +void ws_bootstrap_ffn_state_machine(protocol_interface_info_entry_t *cur); +void ws_bootstrap_ffn_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds); #define wisun_mode_router(cur) (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_ROUTER) @@ -31,6 +33,8 @@ void ws_bootstrap_ffn_event_handler(protocol_interface_info_entry_t *cur, arm_ev #define ws_bootstrap_ffn_asynch_ind(cur, data, ie_ext, message_type) ((void) 0) #define ws_bootstrap_ffn_asynch_confirm(interface, asynch_message) ((void) 0) #define ws_bootstrap_ffn_event_handler(cur, event) ((void) 0) +#define ws_bootstrap_ffn_state_machine(cur) ((void) 0) +#define ws_bootstrap_ffn_seconds_timer(cur, seconds) ((void) 0) #define wisun_mode_router(cur) (false) diff --git a/source/6LoWPAN/ws/ws_bootstrap_lfn.c b/source/6LoWPAN/ws/ws_bootstrap_lfn.c index af3e96feeaf3..3ee2237399b1 100644 --- a/source/6LoWPAN/ws/ws_bootstrap_lfn.c +++ b/source/6LoWPAN/ws/ws_bootstrap_lfn.c @@ -130,4 +130,43 @@ void ws_bootstrap_lfn_event_handler(protocol_interface_info_entry_t *cur, arm_ev } } +void ws_bootstrap_lfn_state_machine(protocol_interface_info_entry_t *cur) +{ + + switch (cur->nwk_bootstrap_state) { + case ER_WAIT_RESTART: + tr_debug("WS SM:Wait for startup"); + break; + case ER_ACTIVE_SCAN: + tr_debug("WS SM:Active Scan"); + break; + case ER_SCAN: + tr_debug("WS SM:configuration Scan"); + break; + case ER_PANA_AUTH: + tr_info("authentication start"); + // Advertisements stopped during the EAPOL + break; + case ER_RPL_SCAN: + tr_debug("WS SM:Wait RPL to contact DODAG root"); + break; + case ER_BOOTSRAP_DONE: + tr_debug("WS SM:Bootstrap Done"); + // Bootstrap_done event to application + break; + case ER_RPL_NETWORK_LEAVING: + tr_debug("WS SM:RPL Leaving ready trigger discovery"); + break; + default: + tr_warn("WS SM:Invalid state %d", cur->nwk_bootstrap_state); + } +} + +void ws_bootstrap_lfn_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds) +{ + (void)cur; + (void)seconds; +} + + #endif //HAVE_WS_BORDER_ROUTER && HAVE_WS diff --git a/source/6LoWPAN/ws/ws_bootstrap_lfn.h b/source/6LoWPAN/ws/ws_bootstrap_lfn.h index 7deb82d414eb..84a0cf81018b 100644 --- a/source/6LoWPAN/ws/ws_bootstrap_lfn.h +++ b/source/6LoWPAN/ws/ws_bootstrap_lfn.h @@ -23,6 +23,8 @@ void ws_bootstrap_lfn_asynch_ind(struct protocol_interface_info_entry *cur, const struct mcps_data_ind_s *data, const struct mcps_data_ie_list *ie_ext, uint8_t message_type); void ws_bootstrap_lfn_asynch_confirm(struct protocol_interface_info_entry *interface, uint8_t asynch_message); void ws_bootstrap_lfn_event_handler(protocol_interface_info_entry_t *cur, arm_event_s *event); +void ws_bootstrap_lfn_state_machine(protocol_interface_info_entry_t *cur); +void ws_bootstrap_lfn_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds); #define wisun_mode_host(cur) (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_HOST) @@ -31,6 +33,8 @@ void ws_bootstrap_lfn_event_handler(protocol_interface_info_entry_t *cur, arm_ev #define ws_bootstrap_ffn_asynch_ind(cur, data, ie_ext, message_type) ((void) 0) #define ws_bootstrap_ffn_asynch_confirm(interface, asynch_message) ((void) 0) #define ws_bootstrap_ffn_event_handler(cur, event) ((void) 0) +#define ws_bootstrap_lfn_state_machine(cur) ((void) 0) +#define ws_bootstrap_lfn_seconds_timer(cur, seconds) ((void) 0) #define wisun_mode_host(cur) (false) diff --git a/source/6LoWPAN/ws/ws_common.c b/source/6LoWPAN/ws/ws_common.c index 690855294e3d..ef6f4064f247 100644 --- a/source/6LoWPAN/ws/ws_common.c +++ b/source/6LoWPAN/ws/ws_common.c @@ -25,12 +25,16 @@ #include "Common_Protocols/icmpv6.h" #include "mac_common_defines.h" #include "net_interface.h" +#include "eventOS_event.h" #include "6LoWPAN/MAC/mpx_api.h" #include "6LoWPAN/ws/ws_config.h" #include "6LoWPAN/ws/ws_common_defines.h" #include "6LoWPAN/ws/ws_llc.h" #include "6LoWPAN/ws/ws_common.h" #include "6LoWPAN/ws/ws_bootstrap.h" +#include "6LoWPAN/ws/ws_bootstrap_6lbr.h" +#include "6LoWPAN/ws/ws_bootstrap_ffn.h" +#include "6LoWPAN/ws/ws_bootstrap_lfn.h" #include "6LoWPAN/ws/ws_bbr_api_internal.h" #include "6LoWPAN/ws/ws_pae_controller.h" #include "6LoWPAN/ws/ws_cfg_settings.h" @@ -561,13 +565,26 @@ int ws_common_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode) void ws_common_state_machine(protocol_interface_info_entry_t *cur) { - ws_bootstrap_state_machine(cur); + if (wisun_mode_host(cur)) { + // Configure for LFN device + ws_bootstrap_lfn_state_machine(cur); + } else if (wisun_mode_router(cur)) { + // Configure FFN device + ws_bootstrap_ffn_state_machine(cur); + } else if (wisun_mode_border_router(cur)) { + // Configure as Border router + ws_bootstrap_6lbr_state_machine(cur); + } + } void ws_common_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds) { ws_bbr_seconds_timer(cur, seconds); ws_bootstrap_seconds_timer(cur, seconds); + ws_bootstrap_6lbr_seconds_timer(cur, seconds); + ws_bootstrap_ffn_seconds_timer(cur, seconds); + ws_bootstrap_lfn_seconds_timer(cur, seconds); blacklist_ttl_update(seconds); }