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
mac_response_handler.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 #include "nsconfig.h" 00018 #include <string.h> 00019 #include "mlme.h" 00020 #include "common_functions.h" 00021 #include "ns_trace.h" 00022 #include "NWK_INTERFACE/Include/protocol_abstract.h" 00023 #include "NWK_INTERFACE/Include/protocol_timer.h" 00024 #include "Service_Libs/mle_service/mle_service_api.h" 00025 #include "Core/include/ns_address_internal.h" 00026 #include "Core/include/ns_socket.h" 00027 #include "6LoWPAN/Thread/thread_common.h" 00028 #include "6LoWPAN/Thread/thread_management_internal.h" 00029 #include "6LoWPAN/MAC/mac_helper.h" 00030 #include "MLE/mle.h" 00031 #include "mac_mcps.h" 00032 #include "6LoWPAN/MAC/mac_data_poll.h" 00033 #include "6LoWPAN/MAC/mac_response_handler.h" 00034 #include "6LoWPAN/MAC/mpx_api.h" 00035 #include "6LoWPAN/lowpan_adaptation_interface.h" 00036 #include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h" 00037 00038 #define TRACE_GROUP "MRsH" 00039 00040 00041 static void mac_mlme_device_table_confirmation_handle(protocol_interface_info_entry_t *info_entry, mlme_get_conf_t *confirmation) 00042 { 00043 if (confirmation->value_size != sizeof(mlme_device_descriptor_t)) { 00044 return; 00045 } 00046 00047 mlme_device_descriptor_t *descpription = (mlme_device_descriptor_t *)confirmation->value_pointer; 00048 00049 tr_debug("Dev stable get confirmation %x", confirmation->status); 00050 00051 if (confirmation->status == MLME_SUCCESS) { 00052 //GET ME table by extended mac64 address 00053 mac_neighbor_table_entry_t *entry = mac_neighbor_table_address_discover(mac_neighbor_info(info_entry), descpription->ExtAddress, ADDR_802_15_4_LONG ); 00054 00055 if (!entry) { 00056 return; 00057 } 00058 00059 if (entry->mac16 != descpription->ShortAddress) { 00060 //Refresh Short ADDRESS 00061 mlme_set_t set_request; 00062 descpription->ShortAddress = entry->mac16 ; 00063 00064 //CALL MLME-SET 00065 set_request.attr = macDeviceTable; 00066 set_request.attr_index = confirmation->attr_index; 00067 set_request.value_pointer = descpription; 00068 set_request.value_size = confirmation->value_size; 00069 info_entry->mac_api->mlme_req(info_entry->mac_api, MLME_SET, &set_request); 00070 } 00071 00072 } 00073 } 00074 00075 static void mac_mlme_frame_counter_confirmation_handle(protocol_interface_info_entry_t *info_entry, mlme_get_conf_t *confirmation) 00076 { 00077 if (confirmation->value_size != 4) { 00078 return; 00079 } 00080 uint32_t *temp_ptr = (uint32_t *)confirmation->value_pointer; 00081 info_entry->mac_parameters->security_frame_counter = *temp_ptr; 00082 } 00083 00084 static void mac_mlme_get_confirmation_handler(protocol_interface_info_entry_t *info_entry, mlme_get_conf_t *confirmation) 00085 { 00086 00087 if (!confirmation) { 00088 return; 00089 } 00090 switch (confirmation->attr) { 00091 case macDeviceTable: 00092 mac_mlme_device_table_confirmation_handle(info_entry, confirmation); 00093 break; 00094 00095 case macFrameCounter: 00096 mac_mlme_frame_counter_confirmation_handle(info_entry, confirmation); 00097 break; 00098 00099 default: 00100 00101 break; 00102 00103 } 00104 } 00105 00106 void mcps_data_confirm_handler(const mac_api_t *api, const mcps_data_conf_t *data) 00107 { 00108 protocol_interface_info_entry_t *info_entry = protocol_stack_interface_info_get_by_id(api->parent_id); 00109 //TODO: create buffer_t and call correct function 00110 //Update protocol_status 00111 lowpan_adaptation_interface_tx_confirm(info_entry, data); 00112 } 00113 00114 void mcps_data_indication_handler(const mac_api_t *api, const mcps_data_ind_t *data_ind) 00115 { 00116 protocol_interface_info_entry_t *info_entry = protocol_stack_interface_info_get_by_id(api->parent_id); 00117 lowpan_adaptation_interface_data_ind(info_entry, data_ind); 00118 } 00119 00120 void mcps_purge_confirm_handler(const mac_api_t *api, mcps_purge_conf_t *data) 00121 { 00122 (void)api; 00123 tr_info("MCPS Data Purge confirm status %u, for handle %u", data->status, data->msduHandle); 00124 } 00125 00126 static void stop_bootstrap_timer(protocol_interface_info_entry_t *info_entry) 00127 { 00128 if (info_entry->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) { 00129 protocol_timer_stop(PROTOCOL_TIMER_BOOTSTRAP_TIM); 00130 } 00131 } 00132 00133 void mlme_confirm_handler(const mac_api_t *api, mlme_primitive id, const void *data) 00134 { 00135 protocol_interface_info_entry_t *info_entry = protocol_stack_interface_info_get_by_id(api->parent_id); 00136 if (!info_entry) { 00137 return; 00138 } 00139 //TODO: create buffer_t and call correct function 00140 switch (id) { 00141 case MLME_ASSOCIATE: { 00142 //Unsupported 00143 break; 00144 } 00145 case MLME_DISASSOCIATE: { 00146 //Unsupported 00147 break; 00148 } 00149 case MLME_GET: { 00150 mlme_get_conf_t *dat = (mlme_get_conf_t *)data; 00151 mac_mlme_get_confirmation_handler(info_entry, dat); 00152 break; 00153 } 00154 case MLME_GTS: { 00155 //Unsupported 00156 break; 00157 } 00158 case MLME_RESET: { 00159 // mlme_reset_conf_t *dat = (mlme_reset_conf_t*)data; 00160 break; 00161 } 00162 case MLME_RX_ENABLE: { 00163 //Unsupported 00164 break; 00165 } 00166 case MLME_SCAN: { 00167 const mlme_scan_conf_t *dat = (mlme_scan_conf_t *)data; 00168 stop_bootstrap_timer(info_entry); 00169 info_entry->scan_cb(api->parent_id, dat); 00170 break; 00171 } 00172 case MLME_SET: { 00173 // mlme_set_conf_t *dat = (mlme_set_conf_t*)data; 00174 break; 00175 } 00176 case MLME_START: { 00177 // mlme_start_conf_t *dat = (mlme_start_conf_t*)data; 00178 stop_bootstrap_timer(info_entry); 00179 break; 00180 } 00181 case MLME_POLL: { 00182 const mlme_poll_conf_t *dat = (mlme_poll_conf_t *)data; 00183 mac_mlme_poll_confirm(info_entry, dat); 00184 break; 00185 } 00186 case MLME_BEACON_NOTIFY: 00187 case MLME_ORPHAN: 00188 case MLME_COMM_STATUS: 00189 case MLME_SYNC: 00190 case MLME_SYNC_LOSS: 00191 default: { 00192 tr_error("Invalid state in mlme_confirm_handler(): %d", id); 00193 break; 00194 } 00195 } 00196 } 00197 00198 void mlme_indication_handler(const mac_api_t *api, mlme_primitive id, const void *data) 00199 { 00200 switch (id) { 00201 case MLME_ASSOCIATE: { 00202 //Unsupported 00203 //mlme_associate_ind_t *dat = (mlme_associate_ind_t*)data; 00204 break; 00205 } 00206 case MLME_DISASSOCIATE: { 00207 //Unsupported 00208 //mlme_disassociate_ind_t *dat = (mlme_disassociate_ind_t*)data; 00209 break; 00210 } 00211 case MLME_BEACON_NOTIFY: { 00212 const mlme_beacon_ind_t *dat = (mlme_beacon_ind_t *)data; 00213 protocol_interface_info_entry_t *info_entry = protocol_stack_interface_info_get_by_id(api->parent_id); 00214 if (info_entry && info_entry->beacon_cb) { 00215 info_entry->beacon_cb(api->parent_id, dat); 00216 } 00217 break; 00218 } 00219 case MLME_GTS: { 00220 //Unsupported 00221 break; 00222 } 00223 case MLME_ORPHAN: { 00224 //Unsupported 00225 break; 00226 } 00227 case MLME_COMM_STATUS: { 00228 mlme_comm_status_t *dat = (mlme_comm_status_t *)data; 00229 protocol_interface_info_entry_t *info_entry = protocol_stack_interface_info_get_by_id(api->parent_id); 00230 if (info_entry && info_entry->comm_status_ind_cb) { 00231 info_entry->comm_status_ind_cb(api->parent_id, dat); 00232 } 00233 00234 break; 00235 } 00236 case MLME_SYNC_LOSS: { 00237 mlme_sync_loss_t *dat = (mlme_sync_loss_t *)data; 00238 protocol_interface_info_entry_t *info_entry = protocol_stack_interface_info_get_by_id(api->parent_id); 00239 if (info_entry) { 00240 if (dat->LossReason == BEACON_LOST) { 00241 nwk_bootsrap_state_update(ARM_NWK_NWK_SCAN_FAIL, info_entry); 00242 } 00243 } 00244 break; 00245 } 00246 case MLME_GET: 00247 case MLME_RESET: 00248 case MLME_RX_ENABLE: 00249 case MLME_SCAN: 00250 case MLME_SET: 00251 case MLME_START: 00252 case MLME_SYNC: 00253 case MLME_POLL: 00254 default: { 00255 tr_error("Invalid state in mlme_indication_handler(): %d", id); 00256 break; 00257 } 00258 } 00259 } 00260
Generated on Tue Jul 12 2022 13:54:31 by
