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.
mac_fhss_callbacks.c
00001 /* 00002 * Copyright (c) 2016-2017, 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 <string.h> 00019 #include "nsconfig.h" 00020 #include "ns_types.h" 00021 #include "mac_api.h" 00022 #include "fhss_api.h " 00023 #include "MAC/IEEE802_15_4/mac_fhss_callbacks.h" 00024 #include "MAC/IEEE802_15_4/mac_defines.h" 00025 #include "MAC/IEEE802_15_4/sw_mac_internal.h" 00026 #include "MAC/IEEE802_15_4/mac_mlme.h" 00027 #include "MAC/IEEE802_15_4/mac_mcps_sap.h" 00028 #include "MAC/rf_driver_storage.h" 00029 #include "common_functions.h" 00030 00031 00032 uint16_t mac_read_tx_queue_sizes(const fhss_api_t *fhss_api, bool broadcast_queue) 00033 { 00034 protocol_interface_rf_mac_setup_s *mac_setup = get_sw_mac_ptr_by_fhss_api(fhss_api); 00035 if (!mac_setup) { 00036 return 0; 00037 } 00038 if (broadcast_queue == true) { 00039 return mac_setup->broadcast_queue_size; 00040 } 00041 return mac_setup->unicast_queue_size; 00042 } 00043 00044 int mac_read_64bit_mac_address(const fhss_api_t *fhss_api, uint8_t *mac_address) 00045 { 00046 protocol_interface_rf_mac_setup_s *mac_setup = get_sw_mac_ptr_by_fhss_api(fhss_api); 00047 if (!mac_setup) { 00048 return -1; 00049 } 00050 memcpy(mac_address, mac_setup->mac64, 8); 00051 return 0; 00052 } 00053 00054 uint32_t mac_read_phy_datarate(const fhss_api_t *fhss_api) 00055 { 00056 protocol_interface_rf_mac_setup_s *mac_setup = get_sw_mac_ptr_by_fhss_api(fhss_api); 00057 if (!mac_setup) { 00058 return 0; 00059 } 00060 return dev_get_phy_datarate(mac_setup->dev_driver->phy_driver, mac_setup->mac_channel_list.channel_page); 00061 } 00062 00063 int mac_set_channel(const fhss_api_t *fhss_api, uint8_t channel_number) 00064 { 00065 protocol_interface_rf_mac_setup_s *mac_setup = get_sw_mac_ptr_by_fhss_api(fhss_api); 00066 if (!mac_setup) { 00067 return -1; 00068 } 00069 // If TX is active, send internal CCA fail event. MAC state machine would crash without TX done event. 00070 if (mac_setup->macRfRadioTxActive == true) { 00071 mac_setup->dev_driver->phy_driver->phy_tx_done_cb(mac_setup->dev_driver->id, 1, PHY_LINK_TX_FAIL, 0, 0); 00072 } 00073 return mac_mlme_rf_channel_change(mac_setup, channel_number); 00074 } 00075 00076 int mac_fhss_frame_tx(const fhss_api_t *fhss_api, int frame_type) 00077 { 00078 protocol_interface_rf_mac_setup_s *mac_setup = get_sw_mac_ptr_by_fhss_api(fhss_api); 00079 if (!mac_setup) { 00080 return -1; 00081 } 00082 if (FHSS_SYNCH_REQUEST_FRAME == frame_type) { 00083 if (mac_mlme_beacon_req_tx(mac_setup) != 1) { 00084 return -1; 00085 } 00086 } else if (FHSS_SYNCH_FRAME == frame_type) { 00087 if (mac_mlme_beacon_tx(mac_setup) != 0) { 00088 return -1; 00089 } 00090 } else { 00091 return -1; 00092 } 00093 return 0; 00094 } 00095 00096 int mac_synch_lost(const fhss_api_t *fhss_api) 00097 { 00098 protocol_interface_rf_mac_setup_s *mac_setup = get_sw_mac_ptr_by_fhss_api(fhss_api); 00099 if (!mac_setup) { 00100 return -1; 00101 } 00102 mac_api_t *mac_api = get_sw_mac_api(mac_setup); 00103 if (!mac_api) { 00104 return -1; 00105 } 00106 mlme_sync_loss_t sync_loss; 00107 sync_loss.LossReason = BEACON_LOST; 00108 mac_api->mlme_ind_cb(mac_api, MLME_SYNC_LOSS, &sync_loss); 00109 return 0; 00110 } 00111 00112 int mac_poll_tx_queue(const fhss_api_t *fhss_api) 00113 { 00114 protocol_interface_rf_mac_setup_s *mac_setup = get_sw_mac_ptr_by_fhss_api(fhss_api); 00115 if (!mac_setup) { 00116 return -1; 00117 } 00118 mcps_sap_trig_tx(mac_setup); 00119 return 0; 00120 } 00121 00122 int mac_broadcast_notification(const fhss_api_t *fhss_api, uint32_t broadcast_time) 00123 { 00124 protocol_interface_rf_mac_setup_s *mac_setup = get_sw_mac_ptr_by_fhss_api(fhss_api); 00125 if (!mac_setup) { 00126 return -1; 00127 } 00128 if (mac_setup->tun_extension_rf_driver && mac_setup->tun_extension_rf_driver->phy_driver->virtual_config_tx_cb) { 00129 uint8_t data_buffer[5]; 00130 data_buffer[0] = MAC_BROADCAST_EVENT; 00131 common_write_32_bit(broadcast_time, &data_buffer[1]); 00132 mac_setup->tun_extension_rf_driver->phy_driver->virtual_config_tx_cb(mac_setup->tun_extension_rf_driver->id, data_buffer, 5); 00133 } 00134 return 0; 00135 } 00136 00137 int mac_get_coordinator_mac_address(const fhss_api_t *fhss_api, uint8_t *mac_address) 00138 { 00139 protocol_interface_rf_mac_setup_s *mac_setup = get_sw_mac_ptr_by_fhss_api(fhss_api); 00140 if (!mac_setup) { 00141 return -1; 00142 } 00143 memcpy(mac_address, mac_setup->coord_long_address, 8); 00144 return 0; 00145 }
Generated on Tue Jul 12 2022 12:44:54 by
