static void thread_discover_timer_trig(void) { if (thread_discover_timer_active || thread_discover_tasklet_id == -1) { } eventOS_event_timer_request(3, THREAD_DISCOVER_TIMER, thread_discover_tasklet_id, THREAD_DISCOVER_TIMER_PERIOD); thread_discover_timer_active = true; }
/** * \brief Network state event handler. * \param event show network start response or current network state. * * - ARM_NWK_BOOTSTRAP_READY: Save NVK persistent data to NVM and Net role * - ARM_NWK_NWK_SCAN_FAIL: Link Layer Active Scan Fail, Stack is Already at Idle state * - ARM_NWK_IP_ADDRESS_ALLOCATION_FAIL: No ND Router at current Channel Stack is Already at Idle state * - ARM_NWK_NWK_CONNECTION_DOWN: Connection to Access point is lost wait for Scan Result * - ARM_NWK_NWK_PARENT_POLL_FAIL: Host should run net start without any PAN-id filter and all channels * - ARM_NWK_AUHTENTICATION_FAIL: Pana Authentication fail, Stack is Already at Idle state */ void nd_tasklet_parse_network_event(arm_event_s *event) { arm_nwk_interface_status_type_e status = (arm_nwk_interface_status_type_e) event->event_data; tr_debug("app_parse_network_event() %d", status); switch (status) { case ARM_NWK_BOOTSTRAP_READY: /* Network is ready and node is connected to Access Point */ if (tasklet_data_ptr->tasklet_state != TASKLET_STATE_BOOTSTRAP_READY) { tr_info("6LoWPAN ND bootstrap ready"); tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_READY; nd_tasklet_trace_bootstrap_info(); nd_tasklet_network_state_changed(MESH_CONNECTED); } break; case ARM_NWK_NWK_SCAN_FAIL: /* Link Layer Active Scan Fail, Stack is Already at Idle state */ tr_debug("Link Layer Scan Fail: No Beacons"); tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; nd_tasklet_network_state_changed(MESH_DISCONNECTED); break; case ARM_NWK_IP_ADDRESS_ALLOCATION_FAIL: /* No ND Router at current Channel Stack is Already at Idle state */ tr_debug("ND Scan/ GP REG fail"); tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; nd_tasklet_network_state_changed(MESH_DISCONNECTED); break; case ARM_NWK_NWK_CONNECTION_DOWN: /* Connection to Access point is lost wait for Scan Result */ tr_debug("ND/RPL scan new network"); tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; nd_tasklet_network_state_changed(MESH_DISCONNECTED); break; case ARM_NWK_NWK_PARENT_POLL_FAIL: tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; nd_tasklet_network_state_changed(MESH_DISCONNECTED); break; case ARM_NWK_AUHTENTICATION_FAIL: tr_debug("Network authentication fail"); tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; nd_tasklet_network_state_changed(MESH_DISCONNECTED); break; default: tr_warn("Unknown event %d", status); break; } if (tasklet_data_ptr->tasklet_state != TASKLET_STATE_BOOTSTRAP_READY && tasklet_data_ptr->network_interface_id != INVALID_INTERFACE_ID) { // Set 5s timer for new network scan eventOS_event_timer_request(TIMER_EVENT_START_BOOTSTRAP, ARM_LIB_SYSTEM_TIMER_EVENT, tasklet_data_ptr->tasklet, 5000); } }
int8_t nd_tasklet_connect(mesh_interface_cb callback, int8_t nwk_interface_id) { int8_t re_connecting = true; int8_t tasklet_id = tasklet_data_ptr->tasklet; if (tasklet_data_ptr->network_interface_id != INVALID_INTERFACE_ID) { return -3; // already connected to network } if (tasklet_data_ptr->tasklet_state == TASKLET_STATE_CREATED) { re_connecting = false; } memset(tasklet_data_ptr, 0, sizeof(tasklet_data_str_t)); tasklet_data_ptr->mesh_api_cb = callback; tasklet_data_ptr->network_interface_id = nwk_interface_id; tasklet_data_ptr->tasklet_state = TASKLET_STATE_INITIALIZED; tasklet_data_ptr->mode = MBED_CONF_MBED_MESH_API_6LOWPAN_ND_DEVICE_TYPE; tasklet_data_ptr->sec_mode = NET_SEC_MODE_NO_LINK_SECURITY; //tasklet_data_ptr->psk_sec_info.key_id = 0; if (re_connecting == false) { tasklet_data_ptr->tasklet = eventOS_event_handler_create(&nd_tasklet_main, ARM_LIB_TASKLET_INIT_EVENT); if (tasklet_data_ptr->tasklet < 0) { // -1 handler already used by other tasklet // -2 memory allocation failure return tasklet_data_ptr->tasklet; } } else { tasklet_data_ptr->tasklet = tasklet_id; eventOS_event_timer_request(TIMER_EVENT_START_BOOTSTRAP, ARM_LIB_SYSTEM_TIMER_EVENT, tasklet_data_ptr->tasklet, 500); } return tasklet_data_ptr->tasklet; }
/** * \brief Network state event handler. * \param event show network start response or current network state. * * - ARM_NWK_BOOTSTRAP_READY: Save NVK peristant data to NVM and Net role * - ARM_NWK_NWK_SCAN_FAIL: Link Layer Active Scan Fail, Stack is Already at Idle state * - ARM_NWK_IP_ADDRESS_ALLOCATION_FAIL: No ND Router at current Channel Stack is Already at Idle state * - ARM_NWK_NWK_CONNECTION_DOWN: Connection to Access point is lost wait for Scan Result * - ARM_NWK_NWK_PARENT_POLL_FAIL: Host should run net start without any PAN-id filter and all channels * - ARM_NWK_AUHTENTICATION_FAIL: Pana Authentication fail, Stack is Already at Idle state */ void app_parse_network_event(arm_event_s *event ) { arm_nwk_interface_status_type_e status = (arm_nwk_interface_status_type_e)event->event_data; switch (status) { case ARM_NWK_BOOTSTRAP_READY: /* Network is ready and node is connect to Access Point */ if(access_point_status==0) { uint8_t temp_ipv6[16]; tr_debug("Network Connection Ready"); access_point_status=1; if( arm_nwk_nd_address_read(net_rf_id,&app_nd_address_info) != 0) { tr_debug("ND Address read fail"); } else { debug("ND Access Point:"); printf_ipv6_address(app_nd_address_info.border_router); debug("ND Prefix 64:"); printf_array(app_nd_address_info.prefix, 8); if(arm_net_address_get(net_rf_id,ADDR_IPV6_GP,temp_ipv6) == 0) { debug("GP IPv6:"); printf_ipv6_address(temp_ipv6); } } if( arm_nwk_mac_address_read(net_rf_id,&app_link_address_info) != 0) { tr_debug("MAC Address read fail\n"); } else { uint8_t temp[2]; debug("MAC 16-bit:"); common_write_16_bit(app_link_address_info.PANId,temp); debug("PAN ID:"); printf_array(temp, 2); debug("MAC 64-bit:"); printf_array(app_link_address_info.mac_long, 8); debug("IID (Based on MAC 64-bit address):"); printf_array(app_link_address_info.iid_eui64, 8); } } break; case ARM_NWK_NWK_SCAN_FAIL: /* Link Layer Active Scan Fail, Stack is Already at Idle state */ tr_debug("Link Layer Scan Fail: No Beacons"); access_point_status=0; break; case ARM_NWK_IP_ADDRESS_ALLOCATION_FAIL: /* No ND Router at current Channel Stack is Already at Idle state */ tr_debug("ND Scan/ GP REG fail"); access_point_status=0; break; case ARM_NWK_NWK_CONNECTION_DOWN: /* Connection to Access point is lost wait for Scan Result */ tr_debug("ND/RPL scan new network"); access_point_status=0; break; case ARM_NWK_NWK_PARENT_POLL_FAIL: access_point_status=0; break; case ARM_NWK_AUHTENTICATION_FAIL: tr_debug("Network authentication fail"); access_point_status=0; break; default: debug_hex(status); debug("Unknow event"); break; } if(access_point_status == 0) { //Set Timer for new network scan eventOS_event_timer_request(1, ARM_LIB_SYSTEM_TIMER_EVENT,node_main_tasklet_id,5000); // 5 sec timer started } }