takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mac_response_handler.c Source File

mac_response_handler.c

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