BA
/
BaBoRo1
Embed:
(wiki syntax)
Show/hide line numbers
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 device_configuration_s device_configuration; 00088 00089 /* private function prototypes */ 00090 void thread_tasklet_main(arm_event_s *event); 00091 void thread_tasklet_network_state_changed(mesh_connection_status_t status); 00092 void thread_tasklet_parse_network_event(arm_event_s *event); 00093 void thread_tasklet_configure_and_connect_to_network(void); 00094 void thread_tasklet_poll_network_status(void *param); 00095 #define TRACE_THREAD_TASKLET 00096 #ifndef TRACE_THREAD_TASKLET 00097 #define thread_tasklet_trace_bootstrap_info() ((void) 0) 00098 #else 00099 void thread_tasklet_trace_bootstrap_info(void); 00100 #endif 00101 00102 /* 00103 * \brief A function which will be eventually called by NanoStack OS when ever the OS has an event to deliver. 00104 * @param event, describes the sender, receiver and event type. 00105 * 00106 * NOTE: Interrupts requested by HW are possible during this function! 00107 */ 00108 void thread_tasklet_main(arm_event_s *event) 00109 { 00110 arm_library_event_type_e event_type; 00111 event_type = (arm_library_event_type_e) event->event_type; 00112 00113 switch (event_type) { 00114 case ARM_LIB_NWK_INTERFACE_EVENT: 00115 /* This event is delivered every and each time when there is new 00116 * information of network connectivity. 00117 */ 00118 thread_tasklet_parse_network_event(event); 00119 break; 00120 00121 case ARM_LIB_TASKLET_INIT_EVENT: 00122 /* Event with type EV_INIT is an initializer event of NanoStack OS. 00123 * The event is delivered when the NanoStack OS is running fine. 00124 * This event should be delivered ONLY ONCE. 00125 */ 00126 mesh_system_send_connect_event(thread_tasklet_data_ptr->tasklet); 00127 break; 00128 00129 case ARM_LIB_SYSTEM_TIMER_EVENT: 00130 eventOS_event_timer_cancel(event->event_id, 00131 thread_tasklet_data_ptr->tasklet); 00132 00133 if (event->event_id == TIMER_EVENT_START_BOOTSTRAP) { 00134 int8_t status; 00135 tr_debug("Restart bootstrap"); 00136 status = arm_nwk_interface_up(thread_tasklet_data_ptr->nwk_if_id); 00137 00138 if (status >= 0) { 00139 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_STARTED; 00140 tr_info("Start Thread bootstrap (%s mode)", thread_tasklet_data_ptr->operating_mode == NET_6LOWPAN_SLEEPY_HOST ? "SED" : "Router"); 00141 thread_tasklet_network_state_changed(MESH_BOOTSTRAP_STARTED); 00142 } else { 00143 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; 00144 tr_err("Bootstrap start failed, %d", status); 00145 thread_tasklet_network_state_changed(MESH_BOOTSTRAP_START_FAILED); 00146 } 00147 } 00148 break; 00149 00150 case APPLICATION_EVENT: 00151 if (event->event_id == APPL_EVENT_CONNECT) { 00152 thread_tasklet_configure_and_connect_to_network(); 00153 } 00154 break; 00155 00156 default: 00157 break; 00158 } // switch(event_type) 00159 } 00160 00161 /** 00162 * \brief Network state event handler. 00163 * \param event show network start response or current network state. 00164 * 00165 * - ARM_NWK_BOOTSTRAP_READY: Save NVK persistent data to NVM and Net role 00166 * - ARM_NWK_NWK_SCAN_FAIL: Link Layer Active Scan Fail, Stack is Already at Idle state 00167 * - ARM_NWK_IP_ADDRESS_ALLOCATION_FAIL: No ND Router at current Channel Stack is Already at Idle state 00168 * - ARM_NWK_NWK_CONNECTION_DOWN: Connection to Access point is lost wait for Scan Result 00169 * - ARM_NWK_NWK_PARENT_POLL_FAIL: Host should run net start without any PAN-id filter and all channels 00170 * - ARM_NWK_AUHTENTICATION_FAIL: Pana Authentication fail, Stack is Already at Idle state 00171 */ 00172 void thread_tasklet_parse_network_event(arm_event_s *event) 00173 { 00174 arm_nwk_interface_status_type_e status = (arm_nwk_interface_status_type_e) event->event_data; 00175 tr_debug("app_parse_network_event() %d", status); 00176 switch (status) { 00177 case ARM_NWK_BOOTSTRAP_READY: 00178 /* Network is ready and node is connected to Access Point */ 00179 if (thread_tasklet_data_ptr->tasklet_state != TASKLET_STATE_BOOTSTRAP_READY) { 00180 tr_info("Thread bootstrap ready"); 00181 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_READY; 00182 thread_tasklet_trace_bootstrap_info(); 00183 /* We are connected, for Local or Global IP */ 00184 thread_tasklet_poll_network_status(NULL); 00185 } 00186 break; 00187 case ARM_NWK_NWK_SCAN_FAIL: 00188 /* Link Layer Active Scan Fail, Stack is Already at Idle state */ 00189 tr_debug("Link Layer Scan Fail: No Beacons"); 00190 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; 00191 thread_tasklet_network_state_changed(MESH_DISCONNECTED); 00192 break; 00193 case ARM_NWK_IP_ADDRESS_ALLOCATION_FAIL: 00194 /* No ND Router at current Channel Stack is Already at Idle state */ 00195 tr_debug("ND Scan/ GP REG fail"); 00196 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; 00197 thread_tasklet_network_state_changed(MESH_DISCONNECTED); 00198 break; 00199 case ARM_NWK_NWK_CONNECTION_DOWN: 00200 /* Connection to Access point is lost wait for Scan Result */ 00201 tr_debug("ND/RPL scan new network"); 00202 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; 00203 thread_tasklet_network_state_changed(MESH_DISCONNECTED); 00204 break; 00205 case ARM_NWK_NWK_PARENT_POLL_FAIL: 00206 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; 00207 thread_tasklet_network_state_changed(MESH_DISCONNECTED); 00208 break; 00209 case ARM_NWK_AUHTENTICATION_FAIL: 00210 tr_debug("Network authentication fail"); 00211 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED; 00212 thread_tasklet_network_state_changed(MESH_DISCONNECTED); 00213 break; 00214 default: 00215 tr_warn("Unknown event %d", status); 00216 break; 00217 } 00218 00219 if (thread_tasklet_data_ptr->tasklet_state != TASKLET_STATE_BOOTSTRAP_READY) { 00220 // Set 5s timer for a new network scan 00221 eventOS_event_timer_request(TIMER_EVENT_START_BOOTSTRAP, 00222 ARM_LIB_SYSTEM_TIMER_EVENT, 00223 thread_tasklet_data_ptr->tasklet, 00224 5000); 00225 } 00226 } 00227 00228 void thread_tasklet_poll_network_status(void *param) 00229 { 00230 /* Check if we do have an IP */ 00231 uint8_t temp_ipv6[16]; 00232 if (arm_net_address_get(thread_tasklet_data_ptr->nwk_if_id, ADDR_IPV6_GP, temp_ipv6) == 0) { 00233 /* Check if this is the same IP than previously */ 00234 if (memcmp(temp_ipv6, thread_tasklet_data_ptr->ip, 16) == 0) { 00235 return; 00236 } else { 00237 memcpy(thread_tasklet_data_ptr->ip, temp_ipv6, 16); 00238 link_configuration_s *link_cfg = thread_management_configuration_get(thread_tasklet_data_ptr->nwk_if_id); 00239 if (memcmp(thread_tasklet_data_ptr->ip, link_cfg->mesh_local_ula_prefix, 8) == 0) { 00240 thread_tasklet_network_state_changed(MESH_CONNECTED_LOCAL); 00241 } else { 00242 thread_tasklet_network_state_changed(MESH_CONNECTED_GLOBAL); 00243 } 00244 } 00245 } else { 00246 if (thread_tasklet_data_ptr->connection_status != MESH_DISCONNECTED && 00247 thread_tasklet_data_ptr->connection_status != MESH_BOOTSTRAP_STARTED) 00248 thread_tasklet_network_state_changed(MESH_DISCONNECTED); 00249 } 00250 } 00251 00252 void read_link_configuration() { 00253 00254 thread_tasklet_data_ptr->link_config.panId = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_PANID; 00255 TRACE_DETAIL("PANID %x", thread_tasklet_data_ptr->link_config.panId); 00256 00257 thread_tasklet_data_ptr->link_config.rfChannel = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_CHANNEL; 00258 TRACE_DETAIL("channel: %d", thread_tasklet_data_ptr->link_config.rfChannel); 00259 00260 // Mesh prefix 00261 const uint8_t mesh_local_prefix[] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_ML_PREFIX; 00262 MBED_ASSERT(sizeof(mesh_local_prefix) == 8); 00263 00264 memcpy(thread_tasklet_data_ptr->link_config.mesh_local_ula_prefix, mesh_local_prefix, 8); 00265 TRACE_DETAIL("Mesh prefix: %s", trace_array(mesh_local_prefix, 8)); 00266 00267 // Master Key 00268 const uint8_t master_key[] = MBED_CONF_MBED_MESH_API_THREAD_MASTER_KEY; 00269 MBED_ASSERT(sizeof(master_key) == 16); 00270 memcpy(thread_tasklet_data_ptr->link_config.master_key, master_key, 16); 00271 00272 // PSKc 00273 const uint8_t PSKc[] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_PSKC; 00274 MBED_ASSERT(sizeof(PSKc) == 16); 00275 memcpy(thread_tasklet_data_ptr->link_config.PSKc, PSKc, 16); 00276 00277 thread_tasklet_data_ptr->link_config.key_rotation = 3600; 00278 thread_tasklet_data_ptr->link_config.key_sequence = 0; 00279 00280 thread_tasklet_data_ptr->link_config.securityPolicy = MBED_CONF_MBED_MESH_API_THREAD_SECURITY_POLICY; 00281 00282 // network name 00283 MBED_ASSERT(strlen(MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME) > 0 && strlen(MBED_CONF_MBED_MESH_API_THREAD_CONFIG_NETWORK_NAME) < 17); 00284 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)); 00285 00286 thread_tasklet_data_ptr->link_config.timestamp = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_COMMISSIONING_DATASET_TIMESTAMP; 00287 00288 // extended pan-id 00289 const uint8_t extented_panid[] = MBED_CONF_MBED_MESH_API_THREAD_CONFIG_EXTENDED_PANID; 00290 MBED_ASSERT(sizeof(extented_panid) == 8); 00291 memcpy(thread_tasklet_data_ptr->link_config.extented_pan_id, extented_panid, sizeof(extented_panid)); 00292 } 00293 00294 /* 00295 * \brief Configure mesh network 00296 * 00297 */ 00298 void thread_tasklet_configure_and_connect_to_network(void) 00299 { 00300 int8_t status; 00301 link_configuration_s* temp_link_config=NULL; 00302 00303 00304 if (MBED_CONF_MBED_MESH_API_THREAD_DEVICE_TYPE == MESH_DEVICE_TYPE_THREAD_MINIMAL_END_DEVICE) { 00305 thread_tasklet_data_ptr->operating_mode = NET_6LOWPAN_HOST; 00306 } 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%.8lx", 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_get_ip_address(char *address, int8_t len) 00394 { 00395 uint8_t binary_ipv6[16]; 00396 00397 if ((len >= 40) && (0 == arm_net_address_get( 00398 thread_tasklet_data_ptr->nwk_if_id, ADDR_IPV6_GP, binary_ipv6))) { 00399 ip6tos(binary_ipv6, address); 00400 //tr_debug("IP address: %s", address); 00401 return 0; 00402 } else { 00403 return -1; 00404 } 00405 } 00406 00407 int8_t thread_tasklet_connect(mesh_interface_cb callback, int8_t nwk_interface_id) 00408 { 00409 int8_t re_connecting = true; 00410 int8_t tasklet = thread_tasklet_data_ptr->tasklet; 00411 00412 if (thread_tasklet_data_ptr->nwk_if_id != INVALID_INTERFACE_ID) { 00413 return -3; // already connected to network 00414 } 00415 00416 if (thread_tasklet_data_ptr->tasklet_state == TASKLET_STATE_CREATED) { 00417 re_connecting = false; 00418 } 00419 00420 memset(thread_tasklet_data_ptr, 0, sizeof(thread_tasklet_data_str_t)); 00421 thread_tasklet_data_ptr->mesh_api_cb = callback; 00422 thread_tasklet_data_ptr->nwk_if_id = nwk_interface_id; 00423 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_INITIALIZED; 00424 thread_tasklet_data_ptr->poll_network_status_timeout = 00425 eventOS_timeout_every_ms(thread_tasklet_poll_network_status, 2000, NULL); 00426 00427 if (re_connecting == false) { 00428 thread_tasklet_data_ptr->tasklet = eventOS_event_handler_create(&thread_tasklet_main, 00429 ARM_LIB_TASKLET_INIT_EVENT); 00430 if (thread_tasklet_data_ptr->tasklet < 0) { 00431 // -1 handler already used by other tasklet 00432 // -2 memory allocation failure 00433 return thread_tasklet_data_ptr->tasklet; 00434 } 00435 00436 ns_event_loop_thread_start(); 00437 } else { 00438 thread_tasklet_data_ptr->tasklet = tasklet; 00439 mesh_system_send_connect_event(thread_tasklet_data_ptr->tasklet); 00440 } 00441 00442 return thread_tasklet_data_ptr->tasklet; 00443 } 00444 00445 int8_t thread_tasklet_disconnect(bool send_cb) 00446 { 00447 int8_t status = -1; 00448 // check that module is initialized 00449 if (thread_tasklet_data_ptr != NULL) { 00450 if (thread_tasklet_data_ptr->nwk_if_id != INVALID_INTERFACE_ID) { 00451 status = arm_nwk_interface_down(thread_tasklet_data_ptr->nwk_if_id); 00452 thread_tasklet_data_ptr->nwk_if_id = INVALID_INTERFACE_ID; 00453 if (send_cb == true) { 00454 thread_tasklet_network_state_changed(MESH_DISCONNECTED); 00455 } 00456 } 00457 00458 // Clear callback, it will be set again in next connect 00459 thread_tasklet_data_ptr->mesh_api_cb = NULL; 00460 // Cancel the callback timeout 00461 eventOS_timeout_cancel(thread_tasklet_data_ptr->poll_network_status_timeout); 00462 } 00463 return status; 00464 } 00465 00466 void thread_tasklet_init(void) 00467 { 00468 if (thread_tasklet_data_ptr == NULL) { 00469 thread_tasklet_data_ptr = ns_dyn_mem_alloc(sizeof(thread_tasklet_data_str_t)); 00470 memset(thread_tasklet_data_ptr, 0, sizeof(thread_tasklet_data_str_t)); 00471 thread_tasklet_data_ptr->tasklet_state = TASKLET_STATE_CREATED; 00472 thread_tasklet_data_ptr->nwk_if_id = INVALID_INTERFACE_ID; 00473 } 00474 } 00475 00476 int8_t thread_tasklet_network_init(int8_t device_id) 00477 { 00478 // TODO, read interface name from configuration 00479 mac_description_storage_size_t storage_sizes; 00480 storage_sizes.device_decription_table_size = 32; 00481 storage_sizes.key_description_table_size = 6; 00482 storage_sizes.key_lookup_size = 1; 00483 storage_sizes.key_usage_size = 3; 00484 mac_api_t *api = ns_sw_mac_create(device_id, &storage_sizes); 00485 return arm_nwk_interface_lowpan_init(api, INTERFACE_NAME); 00486 } 00487 00488 void thread_tasklet_device_eui64_set(const uint8_t *eui64) 00489 { 00490 memcpy(device_configuration.eui64, eui64, 8); 00491 } 00492 00493 uint8_t thread_tasklet_device_pskd_set(const char *pskd) 00494 { 00495 int len = strlen(pskd); 00496 if(len < 6 || len > 32) { 00497 return MESH_ERROR_PARAM; 00498 } 00499 char *dyn_buf = ns_dyn_mem_alloc(strlen(pskd)+1); 00500 if (!dyn_buf) { 00501 return MESH_ERROR_MEMORY; 00502 } 00503 strcpy(dyn_buf, pskd); 00504 ns_dyn_mem_free(device_configuration.PSKd_ptr); 00505 device_configuration.PSKd_ptr = (uint8_t*)dyn_buf; 00506 device_configuration.PSKd_len = strlen(pskd); 00507 return 0; 00508 } 00509 00510 00511 int8_t thread_tasklet_data_poll_rate_set(uint32_t timeout) 00512 { 00513 int8_t status = -1; 00514 if (thread_tasklet_data_ptr) { 00515 if (timeout != 0) { 00516 status = arm_nwk_host_mode_set(thread_tasklet_data_ptr->nwk_if_id, NET_HOST_SLOW_POLL_MODE, timeout); 00517 } else { 00518 status = arm_nwk_host_mode_set(thread_tasklet_data_ptr->nwk_if_id, NET_HOST_RX_ON_IDLE, timeout); 00519 } 00520 } 00521 00522 return status; 00523 }
Generated on Tue Jul 12 2022 12:22:26 by
