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.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
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_BOOTSTRAP_FAILED); 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_BOOTSTRAP_FAILED); 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_BOOTSTRAP_FAILED); 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_BOOTSTRAP_FAILED); 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_BOOTSTRAP_FAILED); 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 thread_tasklet_data_ptr->connection_status = MESH_DISCONNECTED; 00249 } 00250 } 00251 00252 void read_link_configuration() 00253 { 00254 00255 thread_tasklet_data_ptr->link_config.panId = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_PANID; 00256 TRACE_DETAIL("PANID %x", thread_tasklet_data_ptr->link_config.panId); 00257 00258 thread_tasklet_data_ptr->link_config.rfChannel = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_CHANNEL; 00259 TRACE_DETAIL("channel: %d", thread_tasklet_data_ptr->link_config.rfChannel); 00260 00261 // Mesh prefix 00262 const uint8_t mesh_local_prefix[] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_ML_PREFIX; 00263 MBED_ASSERT(sizeof(mesh_local_prefix) == 8); 00264 00265 memcpy(thread_tasklet_data_ptr->link_config.mesh_local_ula_prefix, mesh_local_prefix, 8); 00266 TRACE_DETAIL("Mesh prefix: %s", trace_array(mesh_local_prefix, 8)); 00267 00268 // Master Key 00269 const uint8_t master_key[] = MBED_CONF_MBED_MESH_API_THREAD_MASTER_KEY; 00270 MBED_ASSERT(sizeof(master_key) == 16); 00271 memcpy(thread_tasklet_data_ptr->link_config.master_key, master_key, 16); 00272 00273 // PSKc 00274 const uint8_t PSKc[] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_PSKC; 00275 MBED_ASSERT(sizeof(PSKc) == 16); 00276 memcpy(thread_tasklet_data_ptr->link_config.PSKc, PSKc, 16); 00277 00278 thread_tasklet_data_ptr->link_config.key_rotation = 3600; 00279 thread_tasklet_data_ptr->link_config.key_sequence = 0; 00280 00281 thread_tasklet_data_ptr->link_config.securityPolicy = MBED_CONF_MBED_MESH_API_THREAD_SECURITY_POLICY; 00282 00283 // network name 00284 MBED_ASSERT(strlen(MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME) > 0 && strlen(MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME) < 17); 00285 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)); 00286 00287 thread_tasklet_data_ptr->link_config.timestamp = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_COMMISSIONING_DATASET_TIMESTAMP; 00288 00289 // extended pan-id 00290 const uint8_t extented_panid[] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_EXTENDED_PANID; 00291 MBED_ASSERT(sizeof(extented_panid) == 8); 00292 memcpy(thread_tasklet_data_ptr->link_config.extented_pan_id, extented_panid, sizeof(extented_panid)); 00293 } 00294 00295 /* 00296 * \brief Configure mesh network 00297 * 00298 */ 00299 void thread_tasklet_configure_and_connect_to_network(void) 00300 { 00301 int8_t status; 00302 link_configuration_s *temp_link_config = NULL; 00303 00304 00305 if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_MINIMAL_END_DEVICE) { 00306 thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_HOST; 00307 } else if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_SLEEPY_END_DEVICE) { 00308 thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_SLEEPY_HOST; 00309 } else { 00310 thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_ROUTER; 00311 } 00312 00313 arm_nwk_interface_configure_6lowpan_bootstrap_set( 00314 thread_tasklet_data_ptr->nwk_if_id, 00315 thread_tasklet_data_ptr->operating_mode, 00316 NET_6LOWPAN_THREAD); 00317 00318 thread_tasklet_data_ptr->channel_list.channel_page = (channel_page_e)MBED_CONF_MBED_MESH_API_THREAD_CONFIG_CHANNEL_PAGE; 00319 thread_tasklet_data_ptr->channel_list.channel_mask[0] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_CHANNEL_MASK; 00320 00321 TRACE_DETAIL("channel page: %d", thread_tasklet_data_ptr->channel_list.channel_page); 00322 TRACE_DETAIL("channel mask: 0x%.8" PRIx32, thread_tasklet_data_ptr->channel_list.channel_mask[0]); 00323 00324 // PSKd 00325 const char PSKd[] = MBED_CONF_MBED_MESH_API_THREAD_PSKD; 00326 if (device_configuration.PSKd_len == 0) { 00327 int ret = thread_tasklet_device_pskd_set(PSKd); 00328 MBED_ASSERT(!ret); 00329 } 00330 00331 if (true == MBED_CONF_MBED_MESH_API_THREAD_USE_STATIC_LINK_CONFIG) { 00332 read_link_configuration(); 00333 temp_link_config = &thread_tasklet_data_ptr->link_config; 00334 } 00335 00336 thread_management_node_init(thread_tasklet_data_ptr->nwk_if_id, 00337 &thread_tasklet_data_ptr->channel_list, 00338 &device_configuration, 00339 temp_link_config); 00340 00341 status = arm_nwk_interface_up(thread_tasklet_data_ptr->nwk_if_id); 00342 00343 if (status >= 0) { 00344 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_STARTED; 00345 tr_info("Start Thread bootstrap (%s mode)", thread_tasklet_data_ptr->operating_mode == NET_6LOWPAN_SLEEPY_HOST ? "SED" : "Router"); 00346 thread_tasklet_network_state_changed(MESH_BOOTSTRAP_STARTED); 00347 } else { 00348 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; 00349 tr_err("Bootstrap start failed, %d", status); 00350 thread_tasklet_network_state_changed(MESH_BOOTSTRAP_START_FAILED); 00351 } 00352 } 00353 00354 /* 00355 * Inform application about network state change 00356 */ 00357 void thread_tasklet_network_state_changed(mesh_connection_status_t status) 00358 { 00359 thread_tasklet_data_ptr->connection_status = status; 00360 if (thread_tasklet_data_ptr->mesh_api_cb) { 00361 (thread_tasklet_data_ptr->mesh_api_cb)(status); 00362 } 00363 } 00364 00365 /* 00366 * Trace bootstrap information. 00367 */ 00368 #ifdef TRACE_THREAD_TASKLET 00369 void thread_tasklet_trace_bootstrap_info() 00370 { 00371 link_layer_address_s app_link_address_info; 00372 uint8_t temp_ipv6[16]; 00373 if (arm_net_address_get(thread_tasklet_data_ptr->nwk_if_id, 00374 ADDR_IPV6_GP, temp_ipv6) == 0) { 00375 tr_debug("GP IPv6: %s", trace_ipv6(temp_ipv6)); 00376 } 00377 00378 if (arm_nwk_mac_address_read(thread_tasklet_data_ptr->nwk_if_id, 00379 &app_link_address_info) != 0) { 00380 tr_error("MAC Address read fail\n"); 00381 } else { 00382 uint8_t temp[2]; 00383 common_write_16_bit(app_link_address_info.mac_short, temp); 00384 tr_debug("MAC 16-bit: %s", trace_array(temp, 2)); 00385 common_write_16_bit(app_link_address_info.PANId, temp); 00386 tr_debug("PAN ID: %s", trace_array(temp, 2)); 00387 tr_debug("MAC 64-bit: %s", trace_array(app_link_address_info.mac_long, 8)); 00388 tr_debug("IID (Based on MAC 64-bit address): %s", trace_array(app_link_address_info.iid_eui64, 8)); 00389 } 00390 } 00391 #endif /* #define TRACE_THREAD_TASKLET */ 00392 00393 int8_t thread_tasklet_connect(mesh_interface_cb callback, int8_t nwk_interface_id) 00394 { 00395 int8_t re_connecting = true; 00396 int8_t tasklet = thread_tasklet_data_ptr->tasklet; 00397 00398 if (thread_tasklet_data_ptr->nwk_if_id != INVALID_INTERFACE_ID) { 00399 return -3; // already connected to network 00400 } 00401 00402 if (thread_tasklet_data_ptr->tasklet_state == TASKLET_STATE_CREATED) { 00403 re_connecting = false; 00404 } 00405 00406 memset(thread_tasklet_data_ptr, 0, sizeof(thread_tasklet_data_str_t)); 00407 thread_tasklet_data_ptr->mesh_api_cb = callback; 00408 thread_tasklet_data_ptr->nwk_if_id = nwk_interface_id; 00409 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_INITIALIZED; 00410 thread_tasklet_data_ptr->poll_network_status_timeout = 00411 eventOS_timeout_every_ms(thread_tasklet_poll_network_status, 2000, NULL); 00412 00413 if (re_connecting == false) { 00414 thread_tasklet_data_ptr->tasklet = eventOS_event_handler_create(&thread_tasklet_main, 00415 ARM_LIB_TASKLET_INIT_EVENT); 00416 if (thread_tasklet_data_ptr->tasklet < 0) { 00417 // -1 handler already used by other tasklet 00418 // -2 memory allocation failure 00419 return thread_tasklet_data_ptr->tasklet; 00420 } 00421 } else { 00422 thread_tasklet_data_ptr->tasklet = tasklet; 00423 mesh_system_send_connect_event(thread_tasklet_data_ptr->tasklet); 00424 } 00425 00426 return thread_tasklet_data_ptr->tasklet; 00427 } 00428 00429 int8_t thread_tasklet_disconnect(bool send_cb) 00430 { 00431 int8_t status = -1; 00432 // check that module is initialized 00433 if (thread_tasklet_data_ptr != NULL) { 00434 if (thread_tasklet_data_ptr->nwk_if_id != INVALID_INTERFACE_ID) { 00435 status = arm_nwk_interface_down(thread_tasklet_data_ptr->nwk_if_id); 00436 thread_tasklet_data_ptr->nwk_if_id = INVALID_INTERFACE_ID; 00437 if (send_cb == true) { 00438 thread_tasklet_network_state_changed(MESH_DISCONNECTED); 00439 } 00440 } 00441 00442 // Clear callback, it will be set again in next connect 00443 thread_tasklet_data_ptr->mesh_api_cb = NULL; 00444 // Cancel the callback timeout 00445 eventOS_timeout_cancel(thread_tasklet_data_ptr->poll_network_status_timeout); 00446 } 00447 return status; 00448 } 00449 00450 void thread_tasklet_init(void) 00451 { 00452 if (thread_tasklet_data_ptr == NULL) { 00453 thread_tasklet_data_ptr = ns_dyn_mem_alloc(sizeof(thread_tasklet_data_str_t)); 00454 memset(thread_tasklet_data_ptr, 0, sizeof(thread_tasklet_data_str_t)); 00455 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_CREATED; 00456 thread_tasklet_data_ptr->nwk_if_id = INVALID_INTERFACE_ID; 00457 } 00458 } 00459 00460 int8_t thread_tasklet_network_init(int8_t device_id) 00461 { 00462 // TODO, read interface name from configuration 00463 mac_description_storage_size_t storage_sizes; 00464 storage_sizes.device_decription_table_size = 32; 00465 storage_sizes.key_description_table_size = 6; 00466 storage_sizes.key_lookup_size = 1; 00467 storage_sizes.key_usage_size = 3; 00468 if (!mac_api) { 00469 mac_api = ns_sw_mac_create(device_id, &storage_sizes); 00470 } 00471 return arm_nwk_interface_lowpan_init(mac_api, INTERFACE_NAME); 00472 } 00473 00474 void thread_tasklet_device_eui64_set(const uint8_t *eui64) 00475 { 00476 memcpy(device_configuration.eui64, eui64, 8); 00477 } 00478 00479 void thread_tasklet_device_eui64_get(uint8_t *eui64) 00480 { 00481 memcpy(eui64, device_configuration.eui64, 8); 00482 } 00483 00484 uint8_t thread_tasklet_device_pskd_set(const char *pskd) 00485 { 00486 int len = strlen(pskd); 00487 if (len < 6 || len > 32) { 00488 return MESH_ERROR_PARAM; 00489 } 00490 char *dyn_buf = ns_dyn_mem_alloc(strlen(pskd) + 1); 00491 if (!dyn_buf) { 00492 return MESH_ERROR_MEMORY; 00493 } 00494 strcpy(dyn_buf, pskd); 00495 ns_dyn_mem_free(device_configuration.PSKd_ptr); 00496 device_configuration.PSKd_ptr = (uint8_t *)dyn_buf; 00497 device_configuration.PSKd_len = strlen(pskd); 00498 return 0; 00499 } 00500 00501 00502 int8_t thread_tasklet_data_poll_rate_set(uint32_t timeout) 00503 { 00504 int8_t status = -1; 00505 if (thread_tasklet_data_ptr) { 00506 if (timeout != 0) { 00507 status = arm_nwk_host_mode_set(thread_tasklet_data_ptr->nwk_if_id, NET_HOST_SLOW_POLL_MODE, timeout); 00508 } else { 00509 status = arm_nwk_host_mode_set(thread_tasklet_data_ptr->nwk_if_id, NET_HOST_RX_ON_IDLE, timeout); 00510 } 00511 } 00512 00513 return status; 00514 }
Generated on Tue Jul 12 2022 13:55:00 by
