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
mle.c
00001 /* 00002 * Copyright (c) 2013-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 "MLE/mle.h" 00020 00021 00022 #include "ns_types.h" 00023 #include "eventOS_event.h" 00024 #include "eventOS_event_timer.h" 00025 #include "socket_api.h" 00026 #include "Core/include/ns_socket.h" 00027 #include "nsdynmemLIB.h" 00028 #include "ns_trace.h" 00029 #include "string.h" 00030 #include "NWK_INTERFACE/Include/protocol.h" 00031 #include "Common_Protocols/udp.h" 00032 #include "6LoWPAN/Thread/thread_common.h" 00033 #include "6LoWPAN/Thread/thread_bootstrap.h" 00034 #include "6LoWPAN/Bootstraps/protocol_6lowpan.h" 00035 #include "6LoWPAN/Bootstraps/protocol_6lowpan_bootstrap.h" 00036 #include "platform/arm_hal_interrupt.h" 00037 #include "platform/topo_trace.h" 00038 #include "common_functions.h" 00039 #include "MLE/mle_tlv.h" 00040 #include "NWK_INTERFACE/Include/protocol_timer.h" 00041 #include "Common_Protocols/ipv6_constants.h" 00042 #include "Service_Libs/mle_service/mle_service_api.h" 00043 #include "Service_Libs/etx/etx.h" 00044 #include "6LoWPAN/MAC/mac_helper.h" 00045 #include "mac_api.h" 00046 #include "6LoWPAN/MAC/mac_data_poll.h" 00047 #include "6LoWPAN/lowpan_adaptation_interface.h" 00048 00049 #define TRACE_GROUP "mle" 00050 00051 00052 00053 int16_t mle_class_free_entry_count_get(struct protocol_interface_info_entry *cur) 00054 { 00055 mac_neighbor_table_list_t *mac_table_free_list = &mac_neighbor_info(cur)->free_list; 00056 return ns_list_count(mac_table_free_list); 00057 00058 } 00059 00060 int16_t mle_class_sleepy_entry_count_get(struct protocol_interface_info_entry *cur) 00061 { 00062 mac_neighbor_table_list_t *mac_table_list = &mac_neighbor_info(cur)->neighbour_list; 00063 00064 uint16_t count = 0; 00065 00066 ns_list_foreach(mac_neighbor_table_entry_t, entry, mac_table_list) { 00067 if (!entry->rx_on_idle) { 00068 count++; 00069 } 00070 } 00071 00072 return count; 00073 } 00074 00075 int16_t mle_class_rfd_entry_count_get(struct protocol_interface_info_entry *cur) 00076 { 00077 mac_neighbor_table_list_t *mac_table_list = &mac_neighbor_info(cur)->neighbour_list; 00078 00079 uint16_t count = 0; 00080 00081 ns_list_foreach(mac_neighbor_table_entry_t, entry, mac_table_list) { 00082 if (!entry->ffd_device) { 00083 count++; 00084 } 00085 } 00086 00087 return count; 00088 } 00089 00090 uint16_t mle_class_active_neigh_counter(protocol_interface_info_entry_t *cur) 00091 { 00092 mac_neighbor_table_list_t *mac_table_list = &mac_neighbor_info(cur)->neighbour_list; 00093 00094 return ns_list_count(mac_table_list); 00095 } 00096 00097 #ifndef NO_MLE 00098 00099 int8_t mle_class_set_new_key_pending(struct protocol_interface_info_entry *cur) 00100 { 00101 mac_neighbor_table_list_t *mac_table_list = &mac_neighbor_info(cur)->neighbour_list; 00102 00103 ns_list_foreach_safe(mac_neighbor_table_entry_t, cur_entry, mac_table_list) { 00104 mle_service_frame_counter_entry_new_key_pending_set(cur->id, cur_entry->index); 00105 } 00106 00107 return 0; 00108 } 00109 00110 uint8_t *mle_general_write_source_address(uint8_t *ptr, protocol_interface_info_entry_t *cur) 00111 { 00112 if (cur->global_address_available) { 00113 uint16_t mac16 = mac_helper_mac16_address_get(cur); 00114 if (mac16 < 0xfffe) { 00115 ptr = mle_tlv_write_source_address(ptr, mac16); 00116 } 00117 } 00118 return ptr; 00119 } 00120 00121 uint8_t *mle_general_write_link_layer_framecounter(uint8_t *ptr, protocol_interface_info_entry_t *cur) 00122 { 00123 uint32_t temp_counter; 00124 mac_helper_link_frame_counter_read(cur->id, &temp_counter); 00125 return mle_tlv_write_link_layer_framecount(ptr, temp_counter); 00126 } 00127 00128 bool mle_neigh_entry_frame_counter_update(struct mac_neighbor_table_entry *entry_temp, uint8_t *tlv_ptr, uint16_t tlv_length, protocol_interface_info_entry_t *cur, uint8_t key_id) 00129 { 00130 mle_tlv_info_t mle_tlv_info; 00131 uint32_t frame_counter; 00132 if (mle_tlv_option_discover(tlv_ptr, tlv_length, MLE_TYPE_LL_FRAME_COUNTER, &mle_tlv_info) != 4) { 00133 if (cur->mac_parameters->SecurityEnabled) { 00134 return false; 00135 } else { 00136 frame_counter = 0; 00137 } 00138 } else { 00139 frame_counter = common_read_32_bit(mle_tlv_info.dataPtr); 00140 } 00141 mlme_device_descriptor_t device_desc; 00142 mac_helper_device_description_write(cur, &device_desc, entry_temp->mac64 , entry_temp->mac16 , frame_counter, false); 00143 mac_helper_devicetable_set(&device_desc, cur, entry_temp->index , key_id, false); 00144 return true; 00145 } 00146 00147 00148 void mle_mode_parse_to_mac_entry(mac_neighbor_table_entry_t *mac_entry, uint8_t mode) 00149 { 00150 mac_entry->rx_on_idle = mode & MLE_RX_ON_IDLE; 00151 mac_entry->ffd_device = mode & MLE_FFD_DEV; 00152 } 00153 00154 uint8_t mle_mode_write_from_mac_entry(mac_neighbor_table_entry_t *mac_entry) 00155 { 00156 uint8_t mode = 0; 00157 if (mac_entry->rx_on_idle ) { 00158 mode |= MLE_RX_ON_IDLE; 00159 } 00160 00161 if (mac_entry->ffd_device ) { 00162 mode |= MLE_FFD_DEV; 00163 } 00164 return mode; 00165 } 00166 00167 00168 #endif /* NO_MLE */
Generated on Tue Jul 12 2022 13:54:35 by
