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
kmp_addr.c
00001 /* 00002 * Copyright (c) 2016-2019, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #include "nsconfig.h" 00019 #include <string.h> 00020 #include "ns_types.h" 00021 #include "ns_list.h" 00022 #include "ns_trace.h" 00023 #include "nsdynmemLIB.h" 00024 #include "eventOS_event.h" 00025 #include "eventOS_scheduler.h" 00026 #include "eventOS_event_timer.h" 00027 #include "NWK_INTERFACE/Include/protocol.h" 00028 #include "Common_Protocols/ipv6_constants.h" 00029 #include "6LoWPAN/ws/ws_config.h" 00030 #include "Security/kmp/kmp_addr.h" 00031 00032 #ifdef HAVE_WS 00033 00034 #define TRACE_GROUP "kmar" 00035 00036 void kmp_address_init(kmp_addr_e type, kmp_addr_t *addr, const uint8_t *eui_64) 00037 { 00038 memset(addr, 0, sizeof(kmp_addr_t)); 00039 addr->type = type; 00040 if (eui_64) { 00041 memcpy(addr->eui_64, eui_64, 8); 00042 } 00043 } 00044 00045 00046 const uint8_t *kmp_address_eui_64_get(const kmp_addr_t *addr) 00047 { 00048 if (!addr) { 00049 return NULL; 00050 } 00051 00052 return addr->eui_64; 00053 } 00054 00055 const uint8_t *kmp_address_ip_get(const kmp_addr_t *addr) 00056 { 00057 if (!addr || addr->type != KMP_ADDR_EUI_64_AND_IP) { 00058 return NULL; 00059 } 00060 00061 return addr->relay_address; 00062 } 00063 00064 int8_t kmp_address_eui_64_set(kmp_addr_t *addr, const uint8_t *eui64) 00065 { 00066 if (!addr) { 00067 return -1; 00068 } 00069 00070 memcpy(addr->eui_64, eui64, 8); 00071 return 0; 00072 } 00073 00074 int8_t kmp_address_copy(kmp_addr_t *to_addr, const kmp_addr_t *from_addr) 00075 { 00076 if (!to_addr || !from_addr) { 00077 return -1; 00078 } 00079 00080 memcpy(to_addr->eui_64, from_addr->eui_64, 8); 00081 00082 if (to_addr->type == KMP_ADDR_EUI_64_AND_IP 00083 && from_addr->type == KMP_ADDR_EUI_64_AND_IP) { 00084 memcpy(to_addr->relay_address, from_addr->relay_address, sizeof(address_t)); 00085 to_addr->port = from_addr->port; 00086 } else if (to_addr->type == KMP_ADDR_EUI_64_AND_IP) { 00087 memset(to_addr->relay_address, 0, sizeof(address_t)); 00088 to_addr->port = 0; 00089 } 00090 00091 return 0; 00092 } 00093 00094 #endif /* HAVE_WS */ 00095
Generated on Tue Jul 12 2022 13:54:25 by
