ON Semiconductor / mbed-os

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers mac_api.h Source File

mac_api.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2016 ARM Limited. All rights reserved.
00003  *
00004  * SPDX-License-Identifier: LicenseRef-PBL
00005  *
00006  * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  * https://www.mbed.com/licenses/PBL-1.0
00010  *
00011  * See the License for the specific language governing permissions and limitations under the License.
00012  *
00013  */
00014 
00015 /**
00016  * \file mac_api.h
00017  * \brief A API class to support different MACs from multiple vendors.
00018  * Vendor must implement a function which fills supported callback functions which Upper layer will use.
00019  */
00020 
00021 #ifndef MAC_API_H
00022 #define MAC_API_H
00023 
00024 #include <inttypes.h>
00025 #include "mlme.h"
00026 #include "mac_mcps.h"
00027 
00028 #ifdef __cplusplus
00029 extern "C" {
00030 #endif
00031 
00032 typedef struct mac_api_s mac_api_t;
00033 
00034 /**
00035  * Every MAC adapting to Upper layer must implement a function which creates mac_api_t pointer, e.g 'mac_api_t* create_mac_api();'
00036  * In the function external Mac needs to fill necessary function pointers so that Upper layer can use it.
00037  * For Nanostack to work, following (mlme/mcps) request functions are mandatory:
00038  *   - mcps-data
00039  *   - scan
00040  *   - start
00041  *   - poll
00042  *   - get
00043  *   - set
00044  *   - reset
00045  *   - (purge)
00046  * Also indication and confirm callbacks for above are needed plus
00047  *   - beacon notify
00048  *   - comm status
00049  *
00050  * \return mac_api_t Ownership of newly created object
00051  */
00052 
00053 typedef enum {
00054     MLME_ASSOCIATE,
00055     MLME_DISASSOCIATE,
00056     MLME_BEACON_NOTIFY,
00057     MLME_GET,
00058     MLME_GTS,
00059     MLME_ORPHAN,
00060     MLME_RESET,
00061     MLME_RX_ENABLE,
00062     MLME_SCAN,
00063     MLME_COMM_STATUS,
00064     MLME_SET,
00065     MLME_START,
00066     MLME_SYNC,
00067     MLME_SYNC_LOSS,
00068     MLME_POLL
00069 } mlme_primitive;
00070 
00071 
00072 typedef struct mac_description_storage_size_s {
00073     uint8_t device_decription_table_size;   /** MAC Device description list size */
00074     uint8_t key_description_table_size;     /** MAC Key description list size */
00075     uint8_t key_lookup_size;                /** Key description key lookup list size */
00076     uint8_t key_usage_size;                 /** Key description key usage list size */
00077 } mac_description_storage_size_t;
00078 
00079 typedef enum mac_extended_address_type  {
00080     MAC_EXTENDED_READ_ONLY, /** EUID64 which is unique */
00081     MAC_EXTENDED_DYNAMIC /** Configured MAC 64-bit address to RAM and Radio */
00082 }mac_extended_address_type ;
00083 //External MAC functions
00084 
00085 /**
00086  * @brief mlme_associate_response
00087  * @param api API to handle the request
00088  * @param data MLME-ASSOCIATE.response specific values
00089  */
00090 //typedef void mlme_associate_response(const mac_api_t* api, mlme_associate_resp_t *data);
00091 
00092 //typedef void mlme_orphan_response(const mac_api_t* api, mlme_orphan_resp_t *data);
00093 
00094 /**
00095  * @brief mlme_request
00096  * @param api API to handle the request
00097  * @param id The identifier of the MLME primitive
00098  * @param data Primitive specific data (\see mlme.h)
00099  */
00100 typedef void mlme_request(const mac_api_t* api, mlme_primitive id, const void *data);
00101 
00102 /**
00103  * @brief mcps_request MCPS_DATA request call
00104  * @param api API to handle the request
00105  * @param data MCPS-DATA.request specific values
00106  */
00107 typedef void mcps_data_request(const mac_api_t* api, const mcps_data_req_t *data);
00108 
00109 /**
00110  * @brief mcps_purge_request MCPS_PURGE request call
00111  * @param api API to handle the request
00112  * @param data MCPS-PURGE.request specific values
00113  */
00114 typedef void mcps_purge_request(const mac_api_t* api, const mcps_purge_t *data);
00115 
00116 //Upper layer specific callback functions (will also be set by Upper layer after mac_api_t has been created and given to it)
00117 
00118 /**
00119  * @brief mcps_data_confirm MCPS-DATA confirm is called as a response to MCPS-DATA request
00120  * @param api The API which handled the response
00121  * @param data MCPS-DATA.confirm specific values
00122  */
00123 typedef void mcps_data_confirm(const mac_api_t* api, const mcps_data_conf_t *data);
00124 
00125 /**
00126  * @brief mcps_data_indication MCPS-DATA indication is called when MAC layer has received data
00127  * @param api The API which handled the response
00128  * @param data MCPS-DATA.indication specific values
00129  */
00130 typedef void mcps_data_indication(const mac_api_t* api, const mcps_data_ind_t *data);
00131 
00132 /**
00133  * @brief mcps_purge_confirm MCPS-PURGE confirm is called as a response to MCPS-PURGE request
00134  * @param api The API which handled the request
00135  * @param data MCPS-PURGE.confirm specific values
00136  */
00137 typedef void mcps_purge_confirm( const mac_api_t* api, mcps_purge_conf_t *data );
00138 
00139 /**
00140  * @brief mlme_confirm One of the MLME primitive confirm callbacks
00141  * @param api API which handled the response
00142  * @param id The identifier of the MLME primitive
00143  * @param data Primitive specific data (\see mlme.h)
00144  */
00145 typedef void mlme_confirm(const mac_api_t* api, mlme_primitive id, const void *data);
00146 
00147 /**
00148  * @brief mlme_indication One of the
00149  * @param api API which handled the response
00150  * @param id The identifier of the MLME primitive
00151  * @param data Primitive specific data (\see mlme.h)
00152  */
00153 typedef void mlme_indication(const mac_api_t* api, mlme_primitive id, const void *data);
00154 
00155 /**
00156  * @brief Set extended address from MAC
00157  * @param api API to handle the request
00158  * @param mac64 pointer
00159  */
00160 typedef int8_t mac_ext_mac64_address_set(const mac_api_t* api, const uint8_t *mac64);
00161 
00162 /**
00163  * @brief Read extended address from MAC
00164  * @param api API to handle the request
00165  * @param mac64_buf Pointer where mac extended address can be written
00166  */
00167 typedef int8_t mac_ext_mac64_address_get(const mac_api_t* api, mac_extended_address_type  type, uint8_t *mac64_buf);
00168 
00169 /**
00170  * @brief Read MAC security description storage sizes from MAC
00171  * @param api API to handle the request
00172  * @param buffer Pointer where supported sizes can be written
00173  */
00174 typedef int8_t mac_storage_decription_sizes_get(const mac_api_t* api, mac_description_storage_size_t *buffer);
00175 
00176 /**
00177  * @brief mac_api_initialize Initialises MAC layer into use, callbacks must be non-NULL.
00178  * @param api mac_api_t pointer, which is created by application.
00179  * @param data_conf_cb Upper layer function to handle MCPS confirmations
00180  * @param data_ind_cb Upper layer function to handle MCPS indications
00181  * @param mlme_conf_cb Upper layer function to handle MLME confirmations
00182  * @param mlme_ind_cb Upper layer function to handle MLME indications
00183  * @param parent_id Upper layer id, which is used in confirmation and indication callbacks
00184  * @return -1 if error, -2 if OOM, 0 otherwise
00185  */
00186 typedef int8_t mac_api_initialize(mac_api_t *api, mcps_data_confirm *data_conf_cb,
00187                                   mcps_data_indication *data_ind_cb, mcps_purge_confirm *purge_conf_cb, mlme_confirm *mlme_conf_cb,
00188                                   mlme_indication *mlme_ind_cb, int8_t parent_id);
00189 
00190 /**
00191  * \brief Struct mac_api_s defines functions for two-way communications between external MAC and Upper layer.
00192  * Application creates mac_api_t object by calling external MAC's creator function.
00193  * Then object is passed to Upper layer which then initializes it's own callback functions.
00194  * Then MAC is operated by Upper layer by calling MLME or MCPS primitive functions.
00195  */
00196 struct mac_api_s {
00197     mac_api_initialize          *mac_initialize;
00198     //External MAC callbacks
00199     mlme_request                *mlme_req;
00200     mcps_data_request           *mcps_data_req;
00201     mcps_purge_request          *mcps_purge_req;
00202 
00203     //Upper layer callbacksMLME_ASSOCIATE
00204     mcps_data_confirm           *data_conf_cb;
00205     mcps_data_indication        *data_ind_cb;
00206     mcps_purge_confirm          *purge_conf_cb;
00207     mlme_confirm                *mlme_conf_cb;
00208     mlme_indication             *mlme_ind_cb;
00209     mac_ext_mac64_address_set   *mac64_set;
00210     mac_ext_mac64_address_get   *mac64_get;
00211     mac_storage_decription_sizes_get *mac_storage_sizes_get;
00212 
00213     int8_t                      parent_id;
00214     uint16_t                    phyMTU;
00215 };
00216 
00217 #ifdef __cplusplus
00218 }
00219 #endif
00220 
00221 #endif // MAC_API_H