BA
/
BaBoRo1
Embed:
(wiki syntax)
Show/hide line numbers
thread_commissioning_if.c
00001 /* 00002 * Copyright (c) 2014-2017, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: BSD-3-Clause 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the copyright holder nor the 00014 * names of its contributors may be used to endorse or promote products 00015 * derived from this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 #include "nsconfig.h" 00030 #ifdef HAVE_THREAD 00031 #include "ns_types.h" 00032 #include <string.h> 00033 #include <nsdynmemLIB.h> 00034 #include "eventOS_event_timer.h" 00035 #include <ns_list.h> 00036 #include <net_thread_test.h> 00037 #include "ns_trace.h" 00038 #include "Core/include/ns_buffer.h" 00039 #include "common_functions.h" 00040 #include "NWK_INTERFACE/Include/protocol.h" 00041 #include "6LoWPAN/Thread/thread_common.h" 00042 #include "6LoWPAN/Thread/thread_config.h" 00043 #include "6LoWPAN/Thread/thread_management_internal.h" 00044 #include "6LoWPAN/Thread/thread_management_server.h" 00045 #include "6LoWPAN/Thread/thread_joiner_application.h" 00046 #include "6LoWPAN/Thread/thread_bootstrap.h" 00047 #include "net_interface.h" // TODO remove when fixing properly 00048 #include "thread_commissioning_if.h" 00049 #include "thread_management_if.h" 00050 #include "6LoWPAN/MAC/mac_helper.h" 00051 #include "6LoWPAN/MAC/mac_pairwise_key.h" 00052 00053 #define TRACE_GROUP "thrC" 00054 00055 /* Local function declarations */ 00056 00057 int thread_commissioning_if_pairwise_key_add(int8_t interface_id, uint32_t valid_life_time, uint8_t eui64[static 8], uint8_t key[static 16]) 00058 { 00059 int ret; 00060 if (!eui64 || !key) { 00061 return -1; 00062 } 00063 // TODO this is now IID either change to full LL64 address or sumthing 00064 tr_debug("pairwise key:%s, interface:%d, iid: %s", trace_array(key, 16), interface_id, trace_array(eui64, 8)); 00065 eui64[0] ^= 2; 00066 ret = mac_pairwise_key_add(interface_id, valid_life_time, eui64, key); 00067 eui64[0] ^= 2; 00068 return ret; 00069 } 00070 00071 int thread_commissioning_if_pairwise_key_del(int8_t interface_id, uint8_t eui64[static 8]) 00072 { 00073 int ret; 00074 if (!eui64 ) { 00075 return -1; 00076 } 00077 tr_debug("pairwise key delete interface:%d, iid: %s", interface_id, trace_array(eui64, 8)); 00078 eui64[0] ^= 2; 00079 ret = mac_pairwise_key_del(interface_id, eui64); 00080 eui64[0] ^= 2; 00081 return ret; 00082 } 00083 00084 int thread_commissioning_if_pairwise_key_delete_all(int8_t interface_id) 00085 { 00086 return mac_pairwise_key_flush_list(interface_id); 00087 } 00088 00089 int thread_commissioning_if_border_router_locator_get(int8_t interface_id, uint8_t *address_ptr) 00090 { 00091 protocol_interface_info_entry_t *cur; 00092 if (!address_ptr) { 00093 return -1; 00094 } 00095 00096 cur = protocol_stack_interface_info_get_by_id(interface_id); 00097 if (!cur || !cur->thread_info) { 00098 return -1; 00099 } 00100 00101 if (!cur->thread_info->registered_commissioner.commissioner_valid) { 00102 return -3; 00103 } 00104 00105 memcpy(address_ptr, cur->thread_info->registered_commissioner.border_router_address, 16); 00106 00107 return 0; 00108 } 00109 00110 int thread_commissioning_if_enable_security(int8_t interface_id) 00111 { 00112 protocol_interface_info_entry_t *cur; 00113 00114 cur = protocol_stack_interface_info_get_by_id(interface_id); 00115 if (!cur || !cur->mac_parameters) { 00116 return -1; 00117 } 00118 cur->mac_parameters->mac_configured_sec_level = SEC_ENC_MIC32; 00119 mac_helper_default_security_level_set(cur, cur->mac_parameters->mac_configured_sec_level); 00120 mac_helper_default_security_key_id_mode_set(cur,MAC_KEY_ID_MODE_IDX); 00121 return 0; 00122 } 00123 00124 #endif 00125 00126
Generated on Tue Jul 12 2022 12:22:24 by
