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.
Fork of OmniWheels by
mac_api.h
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 /** 00019 * \file mac_api.h 00020 * \brief A API class to support different MACs from multiple vendors. 00021 * Vendor must implement a function which fills supported callback functions which Upper layer will use. 00022 */ 00023 00024 #ifndef MAC_API_H 00025 #define MAC_API_H 00026 00027 #include <inttypes.h> 00028 #include "mlme.h" 00029 #include "mac_mcps.h" 00030 00031 #ifdef __cplusplus 00032 extern "C" { 00033 #endif 00034 00035 typedef struct mac_api_s mac_api_t; 00036 00037 /** 00038 * Every MAC adapting to Upper layer must implement a function which creates mac_api_t pointer, e.g 'mac_api_t* create_mac_api();' 00039 * In the function external Mac needs to fill necessary function pointers so that Upper layer can use it. 00040 * For Nanostack to work, following (mlme/mcps) request functions are mandatory: 00041 * - mcps-data 00042 * - scan 00043 * - start 00044 * - poll 00045 * - get 00046 * - set 00047 * - reset 00048 * - (purge) 00049 * Also indication and confirm callbacks for above are needed plus 00050 * - beacon notify 00051 * - comm status 00052 * 00053 * \return mac_api_t Ownership of newly created object 00054 */ 00055 00056 /*! 00057 * \enum mlme_primitive 00058 * \brief Enum for MLME primitive types. 00059 */ 00060 typedef enum { 00061 MLME_ASSOCIATE, 00062 MLME_DISASSOCIATE, 00063 MLME_BEACON_NOTIFY, 00064 MLME_GET, 00065 MLME_GTS, 00066 MLME_ORPHAN, 00067 MLME_RESET, 00068 MLME_RX_ENABLE, 00069 MLME_SCAN, 00070 MLME_COMM_STATUS, 00071 MLME_SET, 00072 MLME_START, 00073 MLME_SYNC, 00074 MLME_SYNC_LOSS, 00075 MLME_POLL 00076 } mlme_primitive; 00077 00078 /** 00079 * \struct mac_description_storage_size_t 00080 * \brief Container for MAC storage sizes. 00081 */ 00082 typedef struct mac_description_storage_size_s { 00083 uint8_t device_decription_table_size; /**< MAC Device description list size */ 00084 uint8_t key_description_table_size; /**< MAC Key description list size */ 00085 uint8_t key_lookup_size; /**< Key description key lookup list size */ 00086 uint8_t key_usage_size; /**< Key description key usage list size */ 00087 } mac_description_storage_size_t; 00088 00089 /*! 00090 * \enum mac_extended_address_type 00091 * \brief Enum for MAC extended address types. 00092 */ 00093 typedef enum mac_extended_address_type { 00094 MAC_EXTENDED_READ_ONLY, /** EUID64 which is unique */ 00095 MAC_EXTENDED_DYNAMIC /** Configured MAC 64-bit address to RAM and Radio */ 00096 }mac_extended_address_type; 00097 //External MAC functions 00098 00099 /** 00100 * @brief mlme_associate_response 00101 * @param api API to handle the request 00102 * @param data MLME-ASSOCIATE.response specific values 00103 */ 00104 //typedef void mlme_associate_response(const mac_api_t* api, mlme_associate_resp_t *data); 00105 00106 //typedef void mlme_orphan_response(const mac_api_t* api, mlme_orphan_resp_t *data); 00107 00108 /** 00109 * @brief mlme_request 00110 * @param api API to handle the request 00111 * @param id The identifier of the MLME primitive 00112 * @param data Primitive specific data (\see mlme.h) 00113 */ 00114 typedef void mlme_request(const mac_api_t* api, mlme_primitive id, const void *data); 00115 00116 /** 00117 * @brief mcps_request MCPS_DATA request call 00118 * @param api API to handle the request 00119 * @param data MCPS-DATA.request specific values 00120 */ 00121 typedef void mcps_data_request(const mac_api_t* api, const mcps_data_req_t *data); 00122 00123 /** 00124 * @brief mcps_purge_request MCPS_PURGE request call 00125 * @param api API to handle the request 00126 * @param data MCPS-PURGE.request specific values 00127 */ 00128 typedef void mcps_purge_request(const mac_api_t* api, const mcps_purge_t *data); 00129 00130 //Upper layer specific callback functions (will also be set by Upper layer after mac_api_t has been created and given to it) 00131 00132 /** 00133 * @brief mcps_data_confirm MCPS-DATA confirm is called as a response to MCPS-DATA request 00134 * @param api The API which handled the response 00135 * @param data MCPS-DATA.confirm specific values 00136 */ 00137 typedef void mcps_data_confirm(const mac_api_t* api, const mcps_data_conf_t *data); 00138 00139 /** 00140 * @brief mcps_data_indication MCPS-DATA indication is called when MAC layer has received data 00141 * @param api The API which handled the response 00142 * @param data MCPS-DATA.indication specific values 00143 */ 00144 typedef void mcps_data_indication(const mac_api_t* api, const mcps_data_ind_t *data); 00145 00146 /** 00147 * @brief mcps_purge_confirm MCPS-PURGE confirm is called as a response to MCPS-PURGE request 00148 * @param api The API which handled the request 00149 * @param data MCPS-PURGE.confirm specific values 00150 */ 00151 typedef void mcps_purge_confirm( const mac_api_t* api, mcps_purge_conf_t *data ); 00152 00153 /** 00154 * @brief mlme_confirm One of the MLME primitive confirm callbacks 00155 * @param api API which handled the response 00156 * @param id The identifier of the MLME primitive 00157 * @param data Primitive specific data (\see mlme.h) 00158 */ 00159 typedef void mlme_confirm(const mac_api_t* api, mlme_primitive id, const void *data); 00160 00161 /** 00162 * @brief mlme_indication One of the 00163 * @param api API which handled the response 00164 * @param id The identifier of the MLME primitive 00165 * @param data Primitive specific data (\see mlme.h) 00166 */ 00167 typedef void mlme_indication(const mac_api_t* api, mlme_primitive id, const void *data); 00168 00169 /** 00170 * @brief Set extended address from MAC 00171 * @param api API to handle the request 00172 * @param mac64 pointer 00173 */ 00174 typedef int8_t mac_ext_mac64_address_set(const mac_api_t* api, const uint8_t *mac64); 00175 00176 /** 00177 * @brief Read extended address from MAC 00178 * @param api API to handle the request 00179 * @param mac64_buf Pointer where mac extended address can be written 00180 */ 00181 typedef int8_t mac_ext_mac64_address_get(const mac_api_t* api, mac_extended_address_type type, uint8_t *mac64_buf); 00182 00183 /** 00184 * @brief Read MAC security description storage sizes from MAC 00185 * @param api API to handle the request 00186 * @param buffer Pointer where supported sizes can be written 00187 */ 00188 typedef int8_t mac_storage_decription_sizes_get(const mac_api_t* api, mac_description_storage_size_t *buffer); 00189 00190 /** 00191 * @brief mac_api_initialize Initialises MAC layer into use, callbacks must be non-NULL. 00192 * @param api mac_api_t pointer, which is created by application. 00193 * @param data_conf_cb Upper layer function to handle MCPS confirmations 00194 * @param data_ind_cb Upper layer function to handle MCPS indications 00195 * @param mlme_conf_cb Upper layer function to handle MLME confirmations 00196 * @param mlme_ind_cb Upper layer function to handle MLME indications 00197 * @param parent_id Upper layer id, which is used in confirmation and indication callbacks 00198 * @return -1 if error, -2 if OOM, 0 otherwise 00199 */ 00200 typedef int8_t mac_api_initialize(mac_api_t *api, mcps_data_confirm *data_conf_cb, 00201 mcps_data_indication *data_ind_cb, mcps_purge_confirm *purge_conf_cb, mlme_confirm *mlme_conf_cb, 00202 mlme_indication *mlme_ind_cb, int8_t parent_id); 00203 00204 /** 00205 * \brief Struct mac_api_s defines functions for two-way communications between external MAC and Upper layer. 00206 * Application creates mac_api_t object by calling external MAC's creator function. 00207 * Then object is passed to Upper layer which then initializes it's own callback functions. 00208 * Then MAC is operated by Upper layer by calling MLME or MCPS primitive functions. 00209 */ 00210 struct mac_api_s { 00211 mac_api_initialize *mac_initialize; /**< MAC initialize function to use */ 00212 //External MAC callbacks 00213 mlme_request *mlme_req; /**< MAC MLME request function to use */ 00214 mcps_data_request *mcps_data_req; /**< MAC MCPS data request function to use */ 00215 mcps_purge_request *mcps_purge_req; /**< MAC MCPS purge request function to use */ 00216 00217 //Upper layer callbacksMLME_ASSOCIATE 00218 mcps_data_confirm *data_conf_cb; /**< MAC MCPS data confirm callback function */ 00219 mcps_data_indication *data_ind_cb; /**< MAC MCPS data indication callback function */ 00220 mcps_purge_confirm *purge_conf_cb; /**< MAC MCPS purge confirm callback function */ 00221 mlme_confirm *mlme_conf_cb; /**< MAC MLME confirm callback function */ 00222 mlme_indication *mlme_ind_cb; /**< MAC MLME indication callback function */ 00223 mac_ext_mac64_address_set *mac64_set; /**< MAC extension function to set mac64 address */ 00224 mac_ext_mac64_address_get *mac64_get; /**< MAC extension function to get mac64 address */ 00225 mac_storage_decription_sizes_get *mac_storage_sizes_get; /**< Getter function to query data storage sizes from MAC */ 00226 00227 int8_t parent_id; /**< Upper layer id */ 00228 uint16_t phyMTU; /**< Maximum Transmission Unit(MTU) used by MAC*/ 00229 }; 00230 00231 /** 00232 * \struct mac_statistics_t 00233 * \brief MAC statistics structure. 00234 */ 00235 typedef struct mac_statistics_s { 00236 uint16_t mac_tx_queue_size; /**< MAC TX queue current size. */ 00237 uint16_t mac_tx_queue_peak; /**< MAC TX queue peak size. */ 00238 uint32_t mac_rx_count; /**< MAC RX packet count. */ 00239 uint32_t mac_tx_count; /**< MAC TX packet count. */ 00240 uint32_t mac_bc_rx_count; /**< MAC broadcast RX packet count. */ 00241 uint32_t mac_bc_tx_count; /**< MAC broadcast TX packet count. */ 00242 uint32_t mac_beacon_rx_count; /**< MAC Beacon RX packet count. */ 00243 uint32_t mac_beacon_tx_count; /**< MAC Beacon TX packet count. */ 00244 uint32_t mac_rx_drop_count; /**< MAC RX packet drop count. */ 00245 uint32_t mac_tx_bytes; /**< MAC TX bytes count. */ 00246 uint32_t mac_rx_bytes; /**< MAC RX bytes count. */ 00247 uint32_t mac_tx_failed_count; /**< MAC TX failed count. */ 00248 uint32_t mac_retry_count; /**< MAC TX retry count. */ 00249 uint32_t mac_cca_attempts_count; /**< MAC CCA attempts count. */ 00250 uint32_t mac_failed_cca_count; /**< MAC failed CCA count. */ 00251 } mac_statistics_t; 00252 00253 #ifdef __cplusplus 00254 } 00255 #endif 00256 00257 #endif // MAC_API_H
Generated on Fri Jul 22 2022 04:53:53 by
