Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
thread_tasklet.c
00001 /* 00002 * Copyright (c) 2015 ARM Limited. All rights reserved. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * Licensed under the Apache License, Version 2.0 (the License); you may 00005 * not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an AS IS BASIS, WITHOUT 00012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include <string.h> //memset 00018 #include "eventOS_event_timer.h" 00019 #include "common_functions.h" 00020 #include "net_interface.h" 00021 #include "ip6string.h" //ip6tos 00022 #include "nsdynmemLIB.h" 00023 #include "thread_management_if.h" 00024 #include "net_polling_api.h" 00025 #include "include/thread_tasklet.h" 00026 #include "include/mesh_system.h" 00027 #include <mbed_assert.h> 00028 #include "ns_event_loop.h" 00029 00030 // For tracing we need to define flag, have include and define group 00031 #define HAVE_DEBUG 1 00032 #include "ns_trace.h" 00033 #define TRACE_GROUP "m6Thread" 00034 00035 #include "mac_api.h" 00036 #include "sw_mac.h" 00037 00038 #define DETAILED_TRACES 00039 #ifdef DETAILED_TRACES 00040 #define TRACE_DETAIL tr_debug 00041 #else 00042 #define TRACE_DETAIL(...) 00043 #endif 00044 00045 #define INTERFACE_NAME "6L-THREAD" 00046 00047 // Tasklet timer events 00048 #define TIMER_EVENT_START_BOOTSTRAP 1 00049 00050 #define INVALID_INTERFACE_ID (-1) 00051 00052 /* 00053 * Thread tasklet states. 00054 */ 00055 typedef enum { 00056 TASKLET_STATE_CREATED = 0, 00057 TASKLET_STATE_INITIALIZED, 00058 TASKLET_STATE_BOOTSTRAP_STARTED, 00059 TASKLET_STATE_BOOTSTRAP_FAILED, 00060 TASKLET_STATE_BOOTSTRAP_READY 00061 } tasklet_state_t; 00062 00063 /* 00064 * Mesh tasklet data structure. 00065 */ 00066 typedef struct { 00067 void (*mesh_api_cb)(mesh_connection_status_t nwk_status); 00068 channel_list_s channel_list; 00069 tasklet_state_t tasklet_state; 00070 mesh_connection_status_t connection_status; 00071 timeout_t *poll_network_status_timeout; 00072 int8_t tasklet; 00073 00074 net_6lowpan_mode_e operating_mode; 00075 int8_t nwk_if_id; 00076 link_configuration_s link_config; 00077 00078 /** Default network ID*/ 00079 uint8_t networkid[16]; 00080 uint8_t extented_panid[8]; 00081 uint8_t ip[16]; 00082 } thread_tasklet_data_str_t; 00083 00084 00085 /* Tasklet data */ 00086 static thread_tasklet_data_str_t *thread_tasklet_data_ptr = NULL; 00087 static mac_api_t *mac_api = NULL; 00088 static device_configuration_s device_configuration; 00089 00090 /* private function prototypes */ 00091 void thread_tasklet_main(arm_event_s *event); 00092 void thread_tasklet_network_state_changed(mesh_connection_status_t status); 00093 void thread_tasklet_parse_network_event(arm_event_s *event); 00094 void thread_tasklet_configure_and_connect_to_network(void); 00095 void thread_tasklet_poll_network_status(void *param); 00096 #define TRACE_THREAD_TASKLET 00097 #ifndef TRACE_THREAD_TASKLET 00098 #define thread_tasklet_trace_bootstrap_info() ((void) 0) 00099 #else 00100 void thread_tasklet_trace_bootstrap_info(void); 00101 #endif 00102 00103 /* 00104 * \brief A function which will be eventually called by NanoStack OS when ever the OS has an event to deliver. 00105 * @param event, describes the sender, receiver and event type. 00106 * 00107 * NOTE: Interrupts requested by HW are possible during this function! 00108 */ 00109 void thread_tasklet_main(arm_event_s *event) 00110 { 00111 arm_library_event_type_e event_type; 00112 event_type = (arm_library_event_type_e) event->event_type; 00113 00114 switch (event_type) { 00115 case ARM_LIB_NWK_INTERFACE_EVENT: 00116 /* This event is delivered every and each time when there is new 00117 * information of network connectivity. 00118 */ 00119 thread_tasklet_parse_network_event(event); 00120 break; 00121 00122 case ARM_LIB_TASKLET_INIT_EVENT: 00123 /* Event with type EV_INIT is an initializer event of NanoStack OS. 00124 * The event is delivered when the NanoStack OS is running fine. 00125 * This event should be delivered ONLY ONCE. 00126 */ 00127 mesh_system_send_connect_event(thread_tasklet_data_ptr->tasklet); 00128 break; 00129 00130 case ARM_LIB_SYSTEM_TIMER_EVENT: 00131 eventOS_event_timer_cancel(event->event_id, 00132 thread_tasklet_data_ptr->tasklet); 00133 00134 if (event->event_id == TIMER_EVENT_START_BOOTSTRAP) { 00135 int8_t status; 00136 tr_debug("Restart bootstrap"); 00137 status = arm_nwk_interface_up(thread_tasklet_data_ptr->nwk_if_id); 00138 00139 if (status >= 0) { 00140 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_STARTED; 00141 tr_info("Start Thread bootstrap (%s mode)", thread_tasklet_data_ptr->operating_mode == NET_6LOWPAN_SLEEPY_HOST ? "SED" : "Router"); 00142 thread_tasklet_network_state_changed(MESH_BOOTSTRAP_STARTED); 00143 } else { 00144 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; 00145 tr_err("Bootstrap start failed, %d", status); 00146 thread_tasklet_network_state_changed(MESH_BOOTSTRAP_START_FAILED); 00147 } 00148 } 00149 break; 00150 00151 case APPLICATION_EVENT: 00152 if (event->event_id == APPL_EVENT_CONNECT) { 00153 thread_tasklet_configure_and_connect_to_network(); 00154 } 00155 break; 00156 00157 default: 00158 break; 00159 } // switch(event_type) 00160 } 00161 00162 /** 00163 * \brief Network state event handler. 00164 * \param event show network start response or current network state. 00165 * 00166 * - ARM_NWK_BOOTSTRAP_READY: Save NVK persistent data to NVM and Net role 00167 * - ARM_NWK_NWK_SCAN_FAIL: Link Layer Active Scan Fail, Stack is Already at Idle state 00168 * - ARM_NWK_IP_ADDRESS_ALLOCATION_FAIL: No ND Router at current Channel Stack is Already at Idle state 00169 * - ARM_NWK_NWK_CONNECTION_DOWN: Connection to Access point is lost wait for Scan Result 00170 * - ARM_NWK_NWK_PARENT_POLL_FAIL: Host should run net start without any PAN-id filter and all channels 00171 * - ARM_NWK_AUHTENTICATION_FAIL: Pana Authentication fail, Stack is Already at Idle state 00172 */ 00173 void thread_tasklet_parse_network_event(arm_event_s *event) 00174 { 00175 arm_nwk_interface_status_type_e status = (arm_nwk_interface_status_type_e) event->event_data; 00176 tr_debug("app_parse_network_event() %d", status); 00177 switch (status) { 00178 case ARM_NWK_BOOTSTRAP_READY: 00179 /* Network is ready and node is connected to Access Point */ 00180 if (thread_tasklet_data_ptr->tasklet_state != TASKLET_STATE_BOOTSTRAP_READY) { 00181 tr_info("Thread bootstrap ready"); 00182 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_READY; 00183 thread_tasklet_trace_bootstrap_info(); 00184 /* We are connected, for Local or Global IP */ 00185 thread_tasklet_poll_network_status(NULL); 00186 } 00187 break; 00188 case ARM_NWK_NWK_SCAN_FAIL: 00189 /* Link Layer Active Scan Fail, Stack is Already at Idle state */ 00190 tr_debug("Link Layer Scan Fail: No Beacons"); 00191 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; 00192 thread_tasklet_network_state_changed(MESH_DISCONNECTED); 00193 break; 00194 case ARM_NWK_IP_ADDRESS_ALLOCATION_FAIL: 00195 /* No ND Router at current Channel Stack is Already at Idle state */ 00196 tr_debug("ND Scan/ GP REG fail"); 00197 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; 00198 thread_tasklet_network_state_changed(MESH_DISCONNECTED); 00199 break; 00200 case ARM_NWK_NWK_CONNECTION_DOWN: 00201 /* Connection to Access point is lost wait for Scan Result */ 00202 tr_debug("ND/RPL scan new network"); 00203 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; 00204 thread_tasklet_network_state_changed(MESH_DISCONNECTED); 00205 break; 00206 case ARM_NWK_NWK_PARENT_POLL_FAIL: 00207 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; 00208 thread_tasklet_network_state_changed(MESH_DISCONNECTED); 00209 break; 00210 case ARM_NWK_AUHTENTICATION_FAIL: 00211 tr_debug("Network authentication fail"); 00212 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; 00213 thread_tasklet_network_state_changed(MESH_DISCONNECTED); 00214 break; 00215 default: 00216 tr_warn("Unknown event %d", status); 00217 break; 00218 } 00219 00220 if (thread_tasklet_data_ptr->tasklet_state != TASKLET_STATE_BOOTSTRAP_READY && 00221 thread_tasklet_data_ptr->nwk_if_id != INVALID_INTERFACE_ID) { 00222 // Set 5s timer for a new network scan 00223 eventOS_event_timer_request(TIMER_EVENT_START_BOOTSTRAP, 00224 ARM_LIB_SYSTEM_TIMER_EVENT, 00225 thread_tasklet_data_ptr->tasklet, 00226 5000); 00227 } 00228 } 00229 00230 void thread_tasklet_poll_network_status(void *param) 00231 { 00232 /* Check if we do have an IP */ 00233 uint8_t temp_ipv6[16]; 00234 if (arm_net_address_get(thread_tasklet_data_ptr->nwk_if_id, ADDR_IPV6_GP, temp_ipv6) == 0) { 00235 /* Check if this is the same IP than previously */ 00236 if (memcmp(temp_ipv6, thread_tasklet_data_ptr->ip, 16) == 0) { 00237 return; 00238 } else { 00239 memcpy(thread_tasklet_data_ptr->ip, temp_ipv6, 16); 00240 link_configuration_s *link_cfg = thread_management_configuration_get(thread_tasklet_data_ptr->nwk_if_id); 00241 if (memcmp(thread_tasklet_data_ptr->ip, link_cfg->mesh_local_ula_prefix, 8) == 0) { 00242 thread_tasklet_network_state_changed(MESH_CONNECTED_LOCAL); 00243 } else { 00244 thread_tasklet_network_state_changed(MESH_CONNECTED_GLOBAL); 00245 } 00246 } 00247 } else { 00248 if (thread_tasklet_data_ptr->connection_status != MESH_DISCONNECTED && 00249 thread_tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED) 00250 thread_tasklet_network_state_changed(MESH_DISCONNECTED); 00251 } 00252 } 00253 00254 void read_link_configuration() { 00255 00256 thread_tasklet_data_ptr->link_config.panId = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_PANID; 00257 TRACE_DETAIL("PANID %x", thread_tasklet_data_ptr->link_config.panId); 00258 00259 thread_tasklet_data_ptr->link_config.rfChannel = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_CHANNEL; 00260 TRACE_DETAIL("channel: %d", thread_tasklet_data_ptr->link_config.rfChannel); 00261 00262 // Mesh prefix 00263 const uint8_t mesh_local_prefix[] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_ML_PREFIX; 00264 MBED_ASSERT(sizeof(mesh_local_prefix) == 8); 00265 00266 memcpy(thread_tasklet_data_ptr->link_config.mesh_local_ula_prefix, mesh_local_prefix, 8); 00267 TRACE_DETAIL("Mesh prefix: %s", trace_array(mesh_local_prefix, 8)); 00268 00269 // Master Key 00270 const uint8_t master_key[] = MBED_CONF_MBED_MESH_API_THREAD_MASTER_KEY; 00271 MBED_ASSERT(sizeof(master_key) == 16); 00272 memcpy(thread_tasklet_data_ptr->link_config.master_key, master_key, 16); 00273 00274 // PSKc 00275 const uint8_t PSKc[] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_PSKC; 00276 MBED_ASSERT(sizeof(PSKc) == 16); 00277 memcpy(thread_tasklet_data_ptr->link_config.PSKc, PSKc, 16); 00278 00279 thread_tasklet_data_ptr->link_config.key_rotation = 3600; 00280 thread_tasklet_data_ptr->link_config.key_sequence = 0; 00281 00282 thread_tasklet_data_ptr->link_config.securityPolicy = MBED_CONF_MBED_MESH_API_THREAD_SECURITY_POLICY; 00283 00284 // network name 00285 MBED_ASSERT(strlen(MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME) > 0 && strlen(MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME) < 17); 00286 memcpy(thread_tasklet_data_ptr->link_config.name, MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME, strlen(MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME)); 00287 00288 thread_tasklet_data_ptr->link_config.timestamp = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_COMMISSIONING_DATASET_TIMESTAMP; 00289 00290 // extended pan-id 00291 const uint8_t extented_panid[] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_EXTENDED_PANID; 00292 MBED_ASSERT(sizeof(extented_panid) == 8); 00293 memcpy(thread_tasklet_data_ptr->link_config.extented_pan_id, extented_panid, sizeof(extented_panid)); 00294 } 00295 00296 /* 00297 * \brief Configure mesh network 00298 * 00299 */ 00300 void thread_tasklet_configure_and_connect_to_network(void) 00301 { 00302 int8_t status; 00303 link_configuration_s* temp_link_config=NULL; 00304 00305 00306 if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_MINIMAL_END_DEVICE) { 00307 thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_HOST; 00308 } 00309 else if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_SLEEPY_END_DEVICE) { 00310 thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_SLEEPY_HOST; 00311 } else { 00312 thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_ROUTER; 00313 } 00314 00315 arm_nwk_interface_configure_6lowpan_bootstrap_set( 00316 thread_tasklet_data_ptr->nwk_if_id, 00317 thread_tasklet_data_ptr->operating_mode, 00318 NET_6LOWPAN_THREAD); 00319 00320 thread_tasklet_data_ptr->channel_list.channel_page = (channel_page_e)MBED_CONF_MBED_MESH_API_THREAD_CONFIG_CHANNEL_PAGE; 00321 thread_tasklet_data_ptr->channel_list.channel_mask[0] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_CHANNEL_MASK; 00322 00323 TRACE_DETAIL("channel page: %d", thread_tasklet_data_ptr->channel_list.channel_page); 00324 TRACE_DETAIL("channel mask: 0x%.8lx", thread_tasklet_data_ptr->channel_list.channel_mask[0]); 00325 00326 // PSKd 00327 const char PSKd[] = MBED_CONF_MBED_MESH_API_THREAD_PSKD; 00328 if(device_configuration.PSKd_len==0) { 00329 int ret = thread_tasklet_device_pskd_set(PSKd); 00330 MBED_ASSERT(!ret); 00331 } 00332 00333 if (true == MBED_CONF_MBED_MESH_API_THREAD_USE_STATIC_LINK_CONFIG) { 00334 read_link_configuration(); 00335 temp_link_config = &thread_tasklet_data_ptr->link_config; 00336 } 00337 00338 thread_management_node_init(thread_tasklet_data_ptr->nwk_if_id, 00339 &thread_tasklet_data_ptr->channel_list, 00340 &device_configuration, 00341 temp_link_config); 00342 00343 status = arm_nwk_interface_up(thread_tasklet_data_ptr->nwk_if_id); 00344 00345 if (status >= 0) { 00346 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_STARTED; 00347 tr_info("Start Thread bootstrap (%s mode)", thread_tasklet_data_ptr->operating_mode == NET_6LOWPAN_SLEEPY_HOST ? "SED" : "Router"); 00348 thread_tasklet_network_state_changed(MESH_BOOTSTRAP_STARTED); 00349 } else { 00350 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; 00351 tr_err("Bootstrap start failed, %d", status); 00352 thread_tasklet_network_state_changed(MESH_BOOTSTRAP_START_FAILED); 00353 } 00354 } 00355 00356 /* 00357 * Inform application about network state change 00358 */ 00359 void thread_tasklet_network_state_changed(mesh_connection_status_t status) 00360 { 00361 thread_tasklet_data_ptr->connection_status = status; 00362 if (thread_tasklet_data_ptr->mesh_api_cb) { 00363 (thread_tasklet_data_ptr->mesh_api_cb)(status); 00364 } 00365 } 00366 00367 /* 00368 * Trace bootstrap information. 00369 */ 00370 #ifdef TRACE_THREAD_TASKLET 00371 void thread_tasklet_trace_bootstrap_info() 00372 { 00373 link_layer_address_s app_link_address_info; 00374 uint8_t temp_ipv6[16]; 00375 if (arm_net_address_get(thread_tasklet_data_ptr->nwk_if_id, 00376 ADDR_IPV6_GP, temp_ipv6) == 0) { 00377 tr_debug("GP IPv6: %s", trace_ipv6(temp_ipv6)); 00378 } 00379 00380 if (arm_nwk_mac_address_read(thread_tasklet_data_ptr->nwk_if_id, 00381 &app_link_address_info) != 0) { 00382 tr_error("MAC Address read fail\n"); 00383 } else { 00384 uint8_t temp[2]; 00385 common_write_16_bit(app_link_address_info.mac_short,temp); 00386 tr_debug("MAC 16-bit: %s", trace_array(temp, 2)); 00387 common_write_16_bit(app_link_address_info.PANId, temp); 00388 tr_debug("PAN ID: %s", trace_array(temp, 2)); 00389 tr_debug("MAC 64-bit: %s", trace_array(app_link_address_info.mac_long, 8)); 00390 tr_debug("IID (Based on MAC 64-bit address): %s", trace_array(app_link_address_info.iid_eui64, 8)); 00391 } 00392 } 00393 #endif /* #define TRACE_THREAD_TASKLET */ 00394 00395 int8_t thread_tasklet_connect(mesh_interface_cb callback, int8_t nwk_interface_id) 00396 { 00397 int8_t re_connecting = true; 00398 int8_t tasklet = thread_tasklet_data_ptr->tasklet; 00399 00400 if (thread_tasklet_data_ptr->nwk_if_id != INVALID_INTERFACE_ID) { 00401 return -3; // already connected to network 00402 } 00403 00404 if (thread_tasklet_data_ptr->tasklet_state == TASKLET_STATE_CREATED) { 00405 re_connecting = false; 00406 } 00407 00408 memset(thread_tasklet_data_ptr, 0, sizeof(thread_tasklet_data_str_t)); 00409 thread_tasklet_data_ptr->mesh_api_cb = callback; 00410 thread_tasklet_data_ptr->nwk_if_id = nwk_interface_id; 00411 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_INITIALIZED; 00412 thread_tasklet_data_ptr->poll_network_status_timeout = 00413 eventOS_timeout_every_ms(thread_tasklet_poll_network_status, 2000, NULL); 00414 00415 if (re_connecting == false) { 00416 thread_tasklet_data_ptr->tasklet = eventOS_event_handler_create(&thread_tasklet_main, 00417 ARM_LIB_TASKLET_INIT_EVENT); 00418 if (thread_tasklet_data_ptr->tasklet < 0) { 00419 // -1 handler already used by other tasklet 00420 // -2 memory allocation failure 00421 return thread_tasklet_data_ptr->tasklet; 00422 } 00423 } else { 00424 thread_tasklet_data_ptr->tasklet = tasklet; 00425 mesh_system_send_connect_event(thread_tasklet_data_ptr->tasklet); 00426 } 00427 00428 return thread_tasklet_data_ptr->tasklet; 00429 } 00430 00431 int8_t thread_tasklet_disconnect(bool send_cb) 00432 { 00433 int8_t status = -1; 00434 // check that module is initialized 00435 if (thread_tasklet_data_ptr != NULL) { 00436 if (thread_tasklet_data_ptr->nwk_if_id != INVALID_INTERFACE_ID) { 00437 status = arm_nwk_interface_down(thread_tasklet_data_ptr->nwk_if_id); 00438 thread_tasklet_data_ptr->nwk_if_id = INVALID_INTERFACE_ID; 00439 if (send_cb == true) { 00440 thread_tasklet_network_state_changed(MESH_DISCONNECTED); 00441 } 00442 } 00443 00444 // Clear callback, it will be set again in next connect 00445 thread_tasklet_data_ptr->mesh_api_cb = NULL; 00446 // Cancel the callback timeout 00447 eventOS_timeout_cancel(thread_tasklet_data_ptr->poll_network_status_timeout); 00448 } 00449 return status; 00450 } 00451 00452 void thread_tasklet_init(void) 00453 { 00454 if (thread_tasklet_data_ptr == NULL) { 00455 thread_tasklet_data_ptr = ns_dyn_mem_alloc(sizeof(thread_tasklet_data_str_t)); 00456 memset(thread_tasklet_data_ptr, 0, sizeof(thread_tasklet_data_str_t)); 00457 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_CREATED; 00458 thread_tasklet_data_ptr->nwk_if_id = INVALID_INTERFACE_ID; 00459 } 00460 } 00461 00462 int8_t thread_tasklet_network_init(int8_t device_id) 00463 { 00464 // TODO, read interface name from configuration 00465 mac_description_storage_size_t storage_sizes; 00466 storage_sizes.device_decription_table_size = 32; 00467 storage_sizes.key_description_table_size = 6; 00468 storage_sizes.key_lookup_size = 1; 00469 storage_sizes.key_usage_size = 3; 00470 if (!mac_api) { 00471 mac_api = ns_sw_mac_create(device_id, &storage_sizes); 00472 } 00473 return arm_nwk_interface_lowpan_init(mac_api, INTERFACE_NAME); 00474 } 00475 00476 void thread_tasklet_device_eui64_set(const uint8_t *eui64) 00477 { 00478 memcpy(device_configuration.eui64, eui64, 8); 00479 } 00480 00481 void thread_tasklet_device_eui64_get(uint8_t *eui64) 00482 { 00483 memcpy(eui64, device_configuration.eui64, 8); 00484 } 00485 00486 uint8_t thread_tasklet_device_pskd_set(const char *pskd) 00487 { 00488 int len = strlen(pskd); 00489 if(len < 6 || len > 32) { 00490 return MESH_ERROR_PARAM; 00491 } 00492 char *dyn_buf = ns_dyn_mem_alloc(strlen(pskd)+1); 00493 if (!dyn_buf) { 00494 return MESH_ERROR_MEMORY; 00495 } 00496 strcpy(dyn_buf, pskd); 00497 ns_dyn_mem_free(device_configuration.PSKd_ptr); 00498 device_configuration.PSKd_ptr = (uint8_t*)dyn_buf; 00499 device_configuration.PSKd_len = strlen(pskd); 00500 return 0; 00501 } 00502 00503 00504 int8_t thread_tasklet_data_poll_rate_set(uint32_t timeout) 00505 { 00506 int8_t status = -1; 00507 if (thread_tasklet_data_ptr) { 00508 if (timeout != 0) { 00509 status = arm_nwk_host_mode_set(thread_tasklet_data_ptr->nwk_if_id, NET_HOST_SLOW_POLL_MODE, timeout); 00510 } else { 00511 status = arm_nwk_host_mode_set(thread_tasklet_data_ptr->nwk_if_id, NET_HOST_RX_ON_IDLE, timeout); 00512 } 00513 } 00514 00515 return status; 00516 }
Generated on Tue Aug 9 2022 00:37:23 by
1.7.2