diff --git a/source/6LoWPAN/ws/ws_bootstrap.c b/source/6LoWPAN/ws/ws_bootstrap.c index b3b9c18506a..f6b66e1adda 100644 --- a/source/6LoWPAN/ws/ws_bootstrap.c +++ b/source/6LoWPAN/ws/ws_bootstrap.c @@ -238,6 +238,11 @@ void ws_bootstrap_configuration_reset(protocol_interface_info_entry_t *cur) cur->nwk_bootstrap_state = ER_ACTIVE_SCAN; cur->ws_info->network_pan_id = 0xffff; + trickle_stop(&cur->ws_info->trickle_pan_advertisement_solicit); + trickle_stop(&cur->ws_info->trickle_pan_advertisement); + trickle_stop(&cur->ws_info->trickle_pan_config_solicit); + trickle_stop(&cur->ws_info->trickle_pan_config); + //cur->mac_security_key_usage_update_cb = ws_management_mac_security_key_update_cb; return; } @@ -260,54 +265,49 @@ static bool ws_bootstrap_network_name_matches(const struct mcps_data_ie_list *ie return true; } -static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_info_entry *cur, const struct mcps_data_ind_s *data, const struct mcps_data_ie_list *ie_ext) +static void ws_bootstrap_pan_advertisement_analyse_active(struct protocol_interface_info_entry *cur, ws_pan_information_t *pan_information) { - - (void)ie_ext; - // if in active scan state - // if match network name - // Save the best network parent - if(!ws_bootstrap_state_discovery(cur)) { - return; - } - if (data->SrcAddrMode != 0x03) { - // Not from long address - return; - } - if (!ws_bootstrap_network_name_matches(ie_ext, cur->ws_info->network_name)) { - // Not in our network - return; + /* TODO In Active state + * + * A consistent transmission is defined as a PAN Advertisement received by a node with PAN ID and + * NETNAME-IE / Network Name matching that of the receiving node, and with a PAN-IE / Routing Cost + * the same or better than (less than or equal to) that of the receiving node. + * + * Inconsistent: + * PAN Advertisement solicit + * + * A PAN Advertisement received by a node with PAN ID and NETNAME-IE / Network name matching + * that of the receiving node, and PAN-IE / Routing Cost worse than (greater than) that of the receiving node. + * + */ + + if (pan_information->routing_cost <= cur->ws_info->pan_configuration.routing_cost) { + trickle_consistent_heard(&cur->ws_info->trickle_pan_advertisement); + } else { + trickle_inconsistent_heard(&cur->ws_info->trickle_pan_advertisement,&trickle_params_pan_advertisement); } - ws_utt_ie_t ws_utt; +} - if (!ws_wh_utt_read(ie_ext->headerIeList, ie_ext->headerIeListLength, &ws_utt)) { - // Corrupted - tr_error("No ufsi"); - return; +static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_info_entry *cur, const struct mcps_data_ind_s *data, ws_pan_information_t *pan_information, ws_utt_ie_t *ws_utt, ws_us_ie_t *ws_us) +{ + // if in active scan state + if(!ws_bootstrap_state_discovery(cur)) { + if (data->SrcPANId != cur->ws_info->network_pan_id) { + tr_debug("Wrong PAN id r:%u own:%u", data->SrcPANId, cur->ws_info->network_pan_id); + return; + } } - ws_pan_information_t pan_information; - ws_us_ie_t ws_us; - if (!ws_wp_nested_pan_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &pan_information)) { - // Corrupted - tr_error("No pan information"); - return; - } - // TODO create own function to read just dwell time - if (!ws_wp_nested_us_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &ws_us)) { - // Corrupted - tr_error("No unicast schedule"); - return; - } // Check pan flags so that it is valid - if (!pan_information.rpl_routing_method) { + if (!pan_information->rpl_routing_method) { // NOT RPL routing tr_warn("Not supported routing"); return; } + //TODO smarter Neighbor allocate system mac_neighbor_table_entry_t *neighbor = ws_bootstrap_add_neighbor(cur, data->SrcAddr); if (!neighbor) { @@ -318,65 +318,121 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf return; } - ws_neighbor_class_neighbor_unicast_time_info_update(ws_neighbor, &ws_utt, data->timestamp); - ws_neighbor_class_neighbor_unicast_schedule_set(ws_neighbor, &ws_us); + ws_neighbor_class_neighbor_unicast_time_info_update(ws_neighbor, ws_utt, data->timestamp); + ws_neighbor_class_neighbor_unicast_schedule_set(ws_neighbor, ws_us); - // This parent is selected and used for authentication. - if (memcmp(cur->ws_info->parent_info.addr, ADDR_UNSPECIFIED,8) != 0) { - //Decide which is better parent for authentication - if(cur->ws_info->parent_info.link_quality > data->mpduLinkQuality) { - return; + // Save the best network parent + + if(ws_bootstrap_state_discovery(cur)) { + // Discovery state processing + // This parent is selected and used for authentication. + if (memcmp(cur->ws_info->parent_info.addr, ADDR_UNSPECIFIED,8) != 0) { + //Decide which is better parent for authentication + if(cur->ws_info->parent_info.link_quality > data->mpduLinkQuality) { + return; + } } + // Parent valid store information + cur->ws_info->parent_info.ufsi = ws_utt->ufsi; + // Saved from unicast IE + cur->ws_info->parent_info.dwell_interval = ws_us->dwell_interval; + + // Saved from Pan information + cur->ws_info->parent_info.pan_configuration = *pan_information; + + // Saved from message + cur->ws_info->parent_info.timestamp = data->timestamp; + cur->ws_info->parent_info.pan_id = data->SrcPANId; + cur->ws_info->parent_info.link_quality = data->mpduLinkQuality; + cur->ws_info->parent_info.signal_dbm = data->signal_dbm; + memcpy(cur->ws_info->parent_info.addr, data->SrcAddr,8); + + // return to state machine after 1 - 3s + cur->bootsrap_state_machine_cnt = randLIB_get_random_in_range(10 ,30); + + tr_info("New possible parent found addr:%s", trace_array(cur->ws_info->parent_info.addr, 8)); + } else { + // Active state processing + ws_bootstrap_pan_advertisement_analyse_active(cur, pan_information); } - - // Parent valid store information - cur->ws_info->parent_info.ufsi = ws_utt.ufsi; - // Saved from unicast IE - cur->ws_info->parent_info.dwell_interval = ws_us.dwell_interval; - - // Saved from Pan information - cur->ws_info->parent_info.pan_configuration = pan_information; + cur->ws_info->parent_info.ufsi = ws_utt->ufsi; +} +static void ws_bootstrap_pan_advertisement_solicit_analyse(struct protocol_interface_info_entry *cur, const struct mcps_data_ind_s *data, ws_utt_ie_t *ws_utt, ws_us_ie_t *ws_us) +{ - // Saved from message - cur->ws_info->parent_info.timestamp = data->timestamp; - cur->ws_info->parent_info.pan_id = data->SrcPANId; - cur->ws_info->parent_info.link_quality = data->mpduLinkQuality; - cur->ws_info->parent_info.signal_dbm = data->signal_dbm; - memcpy(cur->ws_info->parent_info.addr, data->SrcAddr,8); + mac_neighbor_table_entry_t *neighbor = ws_bootstrap_add_neighbor(cur, data->SrcAddr); + if (!neighbor) { + return; + } + ws_neighbor_class_entry_t *ws_neighbor = ws_neighbor_class_entry_get(&cur->ws_info->neighbor_storage, neighbor->index); + if (!ws_neighbor) { + return; + } + ws_neighbor_class_neighbor_unicast_time_info_update(ws_neighbor, ws_utt, data->timestamp); + ws_neighbor_class_neighbor_unicast_schedule_set(ws_neighbor, ws_us); - tr_info("New possible parent found addr:%s", trace_array(cur->ws_info->parent_info.addr, 8)); + /* + * An inconsistent transmission is defined as: + * A PAN Advertisement Solicit with NETNAME-IE matching that of the receiving node. + */ + trickle_inconsistent_heard(&cur->ws_info->trickle_pan_advertisement,&trickle_params_pan_advertisement); + /* + * A consistent transmission is defined as + * a PAN Advertisement Solicit with NETNAME-IE / Network Name matching that configured on the receiving node. + */ + trickle_consistent_heard(&cur->ws_info->trickle_pan_advertisement_solicit); } -static void ws_bootstrap_pan_advertisement_solicit_analyse(struct protocol_interface_info_entry *cur, const struct mcps_data_ind_s *data, const struct mcps_data_ie_list *ie_ext) + +static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry *cur, const struct mcps_data_ind_s *data, const struct mcps_data_ie_list *ie_ext, ws_utt_ie_t *ws_utt, ws_us_ie_t *ws_us) { - if (data->SrcAddrMode != MAC_ADDR_MODE_64_BIT) { + + uint16_t pan_version; + ws_bs_ie_t ws_bs_ie; + uint8_t *gtkhash_ptr; + + + if (data->SrcPANId != cur->ws_info->network_pan_id) { + tr_debug("Wrong PAN id r:%u own:%u", data->SrcPANId, cur->ws_info->network_pan_id); return; } - - if(!ws_bootstrap_state_active(cur)) { - // We are not active yet + ws_bt_ie_t ws_bt_ie; + if (!ws_wh_bt_read(ie_ext->headerIeList, ie_ext->headerIeListLength, &ws_bt_ie)) { + tr_warn("BT-IE"); return; } - if (!ws_bootstrap_network_name_matches(ie_ext, cur->ws_info->network_name)) { - // Not in our network - tr_debug("Network name not matching"); + + /* + * A consistent transmission is defined as a PAN Configuration with a PAN-ID matching that of the receiving node and + * a PANVER-IE / PAN Version greater than or equal to the receiving node’s current PAN version. + * + * A inconsistent transmission is defined as: + * + * A PAN Configuration with PAN-ID matching that of the receiving node and a + * PANVER-IE / PAN Version that is less than the receiving node’s current PAN version. + */ + + // TODO Add this to neighbor table + // TODO save all information from config message if version number has changed + + if (!ws_wp_nested_pan_version_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &pan_version)) { + // Corrupted + tr_warn("no version"); return; } - ws_utt_ie_t ws_utt; - ws_us_ie_t ws_us; + gtkhash_ptr = ws_wp_nested_gtkhash_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength); - if (!ws_wh_utt_read(ie_ext->headerIeList, ie_ext->headerIeListLength, &ws_utt)) { + if (!gtkhash_ptr) { // Corrupted - tr_error("No ufsi"); + tr_error("No gtk hash"); return; } - // TODO create own function to read just dwell time - if (!ws_wp_nested_us_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &ws_us)) { + if (!ws_wp_nested_bs_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &ws_bs_ie)) { // Corrupted - tr_error("No unicast schedule"); + tr_error("No broadcast schedule"); return; } @@ -388,13 +444,86 @@ static void ws_bootstrap_pan_advertisement_solicit_analyse(struct protocol_inter if (!ws_neighbor) { return; } + //Update Neighbor Broadcast and Unicast Parameters + ws_neighbor_class_neighbor_unicast_time_info_update(ws_neighbor, ws_utt, data->timestamp); + ws_neighbor_class_neighbor_unicast_schedule_set(ws_neighbor, ws_us); + ws_neighbor_class_neighbor_broadcast_time_info_update(ws_neighbor, &ws_bt_ie, data->timestamp); + ws_neighbor_class_neighbor_broadcast_schedule_set(ws_neighbor, &ws_bs_ie); + + + if (cur->ws_info->configuration_learned && + common_serial_number_greater_16(cur->ws_info->pan_configuration.pan_version, pan_version)) { + // received version is lower se we need to reset the trickle + tr_info("older pan version heard"); + trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config,&trickle_params_pan_configuration); + return; + } + trickle_consistent_heard(&cur->ws_info->trickle_pan_config); - ws_neighbor_class_neighbor_unicast_time_info_update(ws_neighbor, &ws_utt, data->timestamp); - ws_neighbor_class_neighbor_unicast_schedule_set(ws_neighbor, &ws_us); + // TODO update and learn new neighbour + + if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) { + //Border router does not learn network information + return; + } + if (cur->ws_info->pan_configuration.pan_version == pan_version) { + // No new information + return; + } + + /* + * Learn new information from border router + */ + tr_info("Updated PAN configuration heard"); + + cur->ws_info->pan_configuration.pan_version = pan_version; + memcpy(cur->ws_info->gtkhash,gtkhash_ptr,32); + + //Broadcast schedule + cur->ws_info->hopping_schdule.fhss_broadcast_interval = ws_bs_ie.broadcast_interval; + cur->ws_info->hopping_schdule.fhss_bsi = ws_bs_ie.broadcast_schedule_identifier; + cur->ws_info->hopping_schdule.fhss_uc_dwell_interval = ws_bs_ie.dwell_interval; + + if (!cur->ws_info->configuration_learned) { + // Generate own hopping schedules Follow first parent broadcast and plans and also use same unicast dwell + cur->ws_info->configuration_learned = true; + // return to state machine after 1-2 s + cur->bootsrap_state_machine_cnt = randLIB_get_random_in_range(10 ,20); + } - trickle_inconsistent_heard(&cur->ws_info->trickle_pan_advertisement,&trickle_params_pan_advertisement); } +static void ws_bootstrap_pan_config_solicit_analyse(struct protocol_interface_info_entry *cur, const struct mcps_data_ind_s *data, ws_utt_ie_t *ws_utt, ws_us_ie_t *ws_us) +{ + if (data->SrcPANId != cur->ws_info->network_pan_id) { + tr_debug("Wrong PAN id r:%u own:%u", data->SrcPANId, cur->ws_info->network_pan_id); + return; + } + mac_neighbor_table_entry_t *neighbor = ws_bootstrap_add_neighbor(cur, data->SrcAddr); + if (!neighbor) { + return; + } + ws_neighbor_class_entry_t *ws_neighbor = ws_neighbor_class_entry_get(&cur->ws_info->neighbor_storage, neighbor->index); + if (!ws_neighbor) { + return; + } + + ws_neighbor_class_neighbor_unicast_time_info_update(ws_neighbor, ws_utt, data->timestamp); + ws_neighbor_class_neighbor_unicast_schedule_set(ws_neighbor, ws_us); + + /* + * A consistent transmission is defined as a PAN Configuration Solicit with + * a PAN-ID matching that of the receiving node and a NETNAME-IE / Network Name + * matching that configured on the receiving node. + */ + trickle_consistent_heard(&cur->ws_info->trickle_pan_config_solicit); + /* + * inconsistent transmission is defined as either: + * A PAN Configuration Solicit with a PAN-ID matching that of the receiving node and + * a NETNAME-IE / Network Name matching the network name configured on the receiving + */ + trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config,&trickle_params_pan_advertisement); +} static bool ws_bootstrap_network_found(protocol_interface_info_entry_t *cur) { tr_debug("analyze network discovery result"); @@ -410,27 +539,69 @@ static bool ws_bootstrap_network_found(protocol_interface_info_entry_t *cur) static void ws_bootstrap_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)data; - (void)ie_ext; + + if (data->SrcAddrMode != MAC_ADDR_MODE_64_BIT) { + // Not from long address + return; + } + ws_pan_information_t pan_information; + switch (message_type) { + case WS_FT_PAN_ADVERT: + case WS_FT_PAN_ADVERT_SOL: + //Validate Pan Corfirmation is at packet + if (!ws_wp_nested_pan_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &pan_information)) { + // Corrupted + tr_error("No pan information"); + return; + } + case WS_FT_PAN_CONF_SOL: + //Check Network Name + if (!ws_bootstrap_network_name_matches(ie_ext, cur->ws_info->network_name)) { + // Not in our network + tr_debug("Network name not matching"); + return; + } + break; + case WS_FT_PAN_CONF: + break; + default: + return; + } + + //UTT-IE and US-IE are mandatory for all Asynch Messages + ws_utt_ie_t ws_utt; + if (!ws_wh_utt_read(ie_ext->headerIeList, ie_ext->headerIeListLength, &ws_utt)) { + // Corrupted + tr_error("No ufsi"); + return; + } + + ws_us_ie_t ws_us; + if (!ws_wp_nested_us_read(ie_ext->payloadIeList, ie_ext->payloadIeListLength, &ws_us)) { + // Corrupted + tr_error("No unicast schedule"); + return; + } + + //Handle Message's switch (message_type) { case WS_FT_PAN_ADVERT: // Analyse Advertisement tr_debug("received ADVERT"); - ws_bootstrap_pan_advertisement_analyse(cur, data, ie_ext); + ws_bootstrap_pan_advertisement_analyse(cur, data, &pan_information, &ws_utt, &ws_us); break; case WS_FT_PAN_ADVERT_SOL: tr_debug("received ADVERT SOL"); - ws_bootstrap_pan_advertisement_solicit_analyse(cur, data, ie_ext); + ws_bootstrap_pan_advertisement_solicit_analyse(cur, data, &ws_utt, &ws_us); break; case WS_FT_PAN_CONF: tr_debug("received CONFIG"); - break; - case WS_FT_PAN_CONF_SOL: - tr_debug("received CONFIG SOL"); - trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config,&trickle_params_pan_configuration); + ws_bootstrap_pan_config_analyse(cur, data, ie_ext, &ws_utt, &ws_us); break; default: + tr_debug("received CONFIG SOL"); + ws_bootstrap_pan_config_solicit_analyse(cur, data, &ws_utt, &ws_us); break; } } @@ -634,13 +805,12 @@ static void ws_bootstrap_network_information_learn(protocol_interface_info_entry } static void ws_bootstrap_network_configuration_learn(protocol_interface_info_entry_t *cur) { - tr_debug("learn network information from parent"); - - // Save network information - cur->ws_info->pan_configuration = cur->ws_info->parent_info.pan_configuration; + tr_debug("Start using PAN configuration"); // Timing information can be modified here ws_llc_set_pan_information_pointer(cur, &cur->ws_info->pan_configuration); + ws_llc_set_gtkhash(cur, cur->ws_info->gtkhash); + // TODO update own fhss schedules we are starting to follow first parent return; } @@ -695,7 +865,9 @@ static void ws_bootstrap_network_discovery_configure(protocol_interface_info_ent static void ws_bootstrap_advertise_start(protocol_interface_info_entry_t *cur) { trickle_start(&cur->ws_info->trickle_pan_advertisement, &trickle_params_pan_advertisement); + trickle_inconsistent_heard(&cur->ws_info->trickle_pan_advertisement, &trickle_params_pan_advertisement); trickle_start(&cur->ws_info->trickle_pan_config, &trickle_params_pan_configuration); + trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config, &trickle_params_pan_configuration); } // Start network scan @@ -704,9 +876,12 @@ static void ws_bootstrap_start_discovery(protocol_interface_info_entry_t *cur) tr_debug("router discovery start"); ws_bootstrap_state_change(cur, ER_ACTIVE_SCAN); cur->nwk_nd_re_scan_count = 0; - // We go to discovery give jitter op 100ms - 5000ms - cur->bootsrap_state_machine_cnt = randLIB_get_random_in_range(1,50); - // TODO clear parent info + // 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); + // Clear parent info + memset(cur->ws_info->parent_info.addr,0,8); + } /* @@ -797,6 +972,7 @@ static void ws_bootstrap_pan_config(protocol_interface_info_entry_t *cur) async_req.message_type = WS_FT_PAN_CONF; //Request UTT Header, Pan information and US and Net name from payload async_req.wh_requested_ie_list.utt_ie = true; + async_req.wh_requested_ie_list.bt_ie = true; async_req.wp_requested_nested_ie_list.us_ie = true; async_req.wp_requested_nested_ie_list.bs_ie = true; async_req.wp_requested_nested_ie_list.pan_version_ie = true; @@ -828,6 +1004,9 @@ static void ws_bootstrap_event_handler(arm_event_s *event) break; case WS_DISCOVERY_START: tr_info("Discovery start"); + trickle_stop(&cur->ws_info->trickle_pan_advertisement); + trickle_stop(&cur->ws_info->trickle_pan_config); + if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) { tr_debug("Border router start network"); cur->ws_info->network_pan_id = randLIB_get_random_in_range(0,0xfffd); @@ -837,6 +1016,7 @@ static void ws_bootstrap_event_handler(arm_event_s *event) cur->ws_info->pan_configuration.rpl_routing_method = true; cur->ws_info->pan_configuration.use_parent_bs = true; cur->ws_info->pan_configuration.version = WS_FAN_VERSION_1_0; + ws_llc_set_gtkhash(cur, cur->ws_info->gtkhash); ws_bootstrap_fhss_activate(cur); ws_bootstrap_event_operation_start(cur); break; @@ -847,21 +1027,26 @@ static void ws_bootstrap_event_handler(arm_event_s *event) // Start network scan ws_bootstrap_start_discovery(cur); break; + case WS_AUTHENTICATION_START: + tr_info("authentication start"); + trickle_stop(&cur->ws_info->trickle_pan_advertisement_solicit); + ws_bootstrap_event_configuration_start(cur); + break; case WS_CONFIGURATION_START: tr_info("Configuration start"); // TODO temporary learn from parent - ws_bootstrap_network_configuration_learn(cur); - ws_bootstrap_event_authentication_start(cur); - break; - case WS_AUTHENTICATION_START: - tr_info("authentication start"); - ws_llc_set_gtkhash(cur, cur->ws_info->gtkhash); - ws_bootstrap_event_operation_start(cur); + // Start solicit tricklle + // TODO process state after first Config go to operation + 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); + ws_bootstrap_state_change(cur, ER_SCAN); + cur->ws_info->configuration_learned = false; break; case WS_OPERATION_START: tr_info("operation start"); // Activate RPL // Activate IPv6 stack + trickle_stop(&cur->ws_info->trickle_pan_config_solicit); ws_bootstrap_ip_stack_activate(cur); ws_bootstrap_rpl_activate(cur); ws_bootstrap_network_start(cur); @@ -886,7 +1071,6 @@ static void ws_bootstrap_event_handler(arm_event_s *event) void ws_bootstrap_network_scan_process(protocol_interface_info_entry_t *cur) { - cur->nwk_nd_re_scan_count++; if (ws_bootstrap_network_found(cur)) { tr_info("select network"); ws_bootstrap_network_information_learn(cur); @@ -894,17 +1078,17 @@ void ws_bootstrap_network_scan_process(protocol_interface_info_entry_t *cur) ws_bootstrap_event_authentication_start(cur); return; } + return; +} - // Sending Advertisement SOLICIT - ws_bootstrap_pan_advert_solicit(cur); +void ws_bootstrap_configure_process(protocol_interface_info_entry_t *cur) +{ - if (cur->nwk_nd_re_scan_count > 10) { - cur->nwk_nd_re_scan_count = 10; + if(cur->ws_info->configuration_learned) { + ws_bootstrap_network_configuration_learn(cur); + ws_bootstrap_event_operation_start(cur); + return; } - // 65 seconds to 605 seconds + random jitter of 15 seconds - uint16_t wait_ticks = cur->nwk_nd_re_scan_count * 600; - cur->bootsrap_state_machine_cnt = randLIB_get_random_in_range(wait_ticks + 50, wait_ticks + 200); - tr_info("Next solicit %ds",cur->bootsrap_state_machine_cnt/10); return; } @@ -916,12 +1100,21 @@ static bool ws_bootstrap_state_active(struct protocol_interface_info_entry *cur) return false; } +static bool ws_bootstrap_state_configure(struct protocol_interface_info_entry *cur) +{ + // Think about the state value + if(cur->nwk_bootstrap_state == ER_SCAN) { + return true; + } + return false; +} + static bool ws_bootstrap_state_discovery(struct protocol_interface_info_entry *cur) { - if(cur->nwk_bootstrap_state != ER_ACTIVE_SCAN) { - return false; + if(cur->nwk_bootstrap_state == ER_ACTIVE_SCAN) { + return true; } - return true; + return false; } static void ws_bootstrap_state_change(protocol_interface_info_entry_t *cur, icmp_state_t nwk_bootstrap_state) @@ -933,26 +1126,36 @@ void ws_bootstrap_state_machine(protocol_interface_info_entry_t *cur) { switch (cur->nwk_bootstrap_state) { - case ER_ACTIVE_SCAN: - tr_debug("WS SM:Active Scan"); - ws_bootstrap_network_scan_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_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_BOOTSRAP_DONE: + tr_debug("WS SM:Bootstrap Done"); + // Bootstrap_done event to application + nwk_bootsrap_state_update(ARM_NWK_BOOTSTRAP_READY, cur); + break; - default: - tr_warn("WS SM:Invalid state %d",cur->nwk_bootstrap_state); + default: + tr_warn("WS SM:Invalid state %d",cur->nwk_bootstrap_state); } } void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds) { - if (cur->ws_info->network_pan_id >= 0xfffe) { - // No pan configuration - return; + if(trickle_timer(&cur->ws_info->trickle_pan_advertisement_solicit, &trickle_params_pan_advertisement, seconds)) { + // send PAN advertisement solicit + tr_info("Send PAN advertisement Solicit"); + ws_bootstrap_pan_advert_solicit(cur); + } + if(trickle_timer(&cur->ws_info->trickle_pan_config_solicit, &trickle_params_pan_configuration, seconds)) { + // send PAN Configuration solicit + tr_info("Send PAN configuration Solicit"); + ws_bootstrap_pan_config_solicit(cur); } if(trickle_timer(&cur->ws_info->trickle_pan_advertisement, &trickle_params_pan_advertisement, seconds)) { // send PAN advertisement @@ -962,7 +1165,7 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s if(trickle_timer(&cur->ws_info->trickle_pan_config, &trickle_params_pan_configuration, seconds)) { // send PAN Configuration tr_info("Send PAN configuration"); -// ws_bootstrap_pan_config(cur); + ws_bootstrap_pan_config(cur); } } diff --git a/source/6LoWPAN/ws/ws_common.h b/source/6LoWPAN/ws/ws_common.h index 92981bf8d99..d91322035e8 100644 --- a/source/6LoWPAN/ws/ws_common.h +++ b/source/6LoWPAN/ws/ws_common.h @@ -42,10 +42,13 @@ typedef struct ws_info_s { char network_name[33]; // Network name max 32 octets + terminating 0. uint16_t network_pan_id; + trickle_t trickle_pan_config_solicit; trickle_t trickle_pan_config; + trickle_t trickle_pan_advertisement_solicit; trickle_t trickle_pan_advertisement; parent_info_t parent_info; uint8_t gtkhash[32]; + bool configuration_learned:1; struct ws_pan_information_s pan_configuration; ws_hopping_schedule_t hopping_schdule;