BA / SerialCom

Fork of OmniWheels by Gustav Atmel

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lorawan_data_structures.h Source File

lorawan_data_structures.h

Go to the documentation of this file.
00001 /**
00002  * @file lorawan_data_structures.h
00003  *
00004  * @brief Contains common data structures used by Mbed-OS
00005  *        LoRaWAN mplementation.
00006  *
00007  *  \code
00008  *   ______                              _
00009  *  / _____)             _              | |
00010  * ( (____  _____ ____ _| |_ _____  ____| |__
00011  *  \____ \| ___ |    (_   _) ___ |/ ___)  _ \
00012  *  _____) ) ____| | | || |_| ____( (___| | | |
00013  * (______/|_____)_|_|_| \__)_____)\____)_| |_|
00014  *   (C)2013 Semtech
00015  *  ___ _____ _   ___ _  _____ ___  ___  ___ ___
00016  * / __|_   _/_\ / __| |/ / __/ _ \| _ \/ __| __|
00017  * \__ \ | |/ _ \ (__| ' <| _| (_) |   / (__| _|
00018  * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___|
00019  * embedded.connectivity.solutions===============
00020  *
00021  * \endcode
00022  *
00023  * Description: LoRa PHY layer
00024  *
00025  * License: Revised BSD License, see LICENSE.TXT file include in the project
00026  *
00027  * Maintainer: Miguel Luis ( Semtech ), Gregory Cristian ( Semtech ) and Daniel Jaeckle ( STACKFORCE )
00028  *
00029  * Copyright (c) 2017, Arm Limited and affiliates.
00030  * SPDX-License-Identifier: BSD-3-Clause
00031  *
00032  */
00033 
00034 #ifndef LORAWAN_SYSTEM_LORAWAN_DATA_STRUCTURES_H_
00035 #define LORAWAN_SYSTEM_LORAWAN_DATA_STRUCTURES_H_
00036 
00037 #include <inttypes.h>
00038 #include "platform/Callback.h"
00039 
00040 /*!
00041  * \brief Timer time variable definition
00042  */
00043 #ifndef lorawan_time_t
00044 typedef uint32_t lorawan_time_t;
00045 #endif
00046 
00047 // Radio wake-up time from sleep - unit ms.
00048 #define RADIO_WAKEUP_TIME                           1
00049 
00050 /**
00051  * Option Flags for send(), receive() APIs
00052  */
00053 #define MSG_UNCONFIRMED_FLAG                  0x01
00054 #define MSG_CONFIRMED_FLAG                    0x02
00055 #define MSG_MULTICAST_FLAG                    0x04
00056 #define MSG_PROPRIETARY_FLAG                  0x08
00057 
00058 /**
00059  * A macro to test a if a bit is on in a channel mask or not.
00060  */
00061 //#define MASK_BIT_TEST(mask, bit)    (mask & (1U << bit))
00062 //#define MASK_BIT_TEST(mask, bit)    ((mask)[(bit) / 16] & (1U << ((bit) % 16)))
00063 /**
00064  * A macro to clear a bit in a channel mask.
00065  */
00066 //#define MASK_BIT_CLEAR(mask, bit)   (mask &= ~(1 << bit))
00067 
00068 /**
00069  * A macro to clear a bit in a channel mask.
00070  */
00071 //#define MASK_BIT_SET(mask, bit)   (mask |= (1 << bit))
00072 
00073 /**
00074  * Bit mask for message flags
00075  */
00076 
00077 #define MSG_FLAG_MASK                         0x0F
00078 
00079 /**
00080  * Mask for unconfirmed multicast message
00081  */
00082 #define MSG_UNCONFIRMED_MULTICAST              0x05
00083 
00084 /**
00085  * Mask for confirmed multicast message
00086  */
00087 #define MSG_CONFIRMED_MULTICAST                0x06
00088 
00089 /**
00090  * Mask for unconfirmed message proprietary message
00091  */
00092 #define MSG_UNCONFIRMED_PROPRIETARY            0x09
00093 
00094 /**
00095  * Mask for confirmed proprietary message
00096  */
00097 #define MSG_CONFIRMED_PROPRIETARY              0x0A
00098 
00099 /*!
00100  * Sets the length of the LoRaMAC footer field.
00101  * Mainly indicates the MIC field length.
00102  */
00103 #define LORAMAC_MFR_LEN                             4
00104 
00105 /*!
00106  * The FRMPayload overhead to be used when setting the `Radio.SetMaxPayloadLength`
00107  * in the `RxWindowSetup` function.
00108  * The maximum PHYPayload = MaxPayloadOfDatarate/MaxPayloadOfDatarateRepeater + LORA_MAC_FRMPAYLOAD_OVERHEAD
00109  */
00110 #define LORA_MAC_FRMPAYLOAD_OVERHEAD                13 // MHDR(1) + FHDR(7) + Port(1) + MIC(4)
00111 
00112 /**
00113  * LoRaMac maximum number of channels
00114  */
00115 #define LORA_MAX_NB_CHANNELS                        16
00116 
00117 /**
00118  * Maximum PHY layer payload size for reception.
00119  */
00120 #define LORAMAC_PHY_MAXPAYLOAD                      255
00121 
00122 /**
00123  *
00124  * Default user application maximum data size for transmission
00125  */
00126 // reject if user tries to set more than MTU
00127 #if MBED_CONF_LORA_TX_MAX_SIZE > 255
00128     #warning "Cannot set TX Max size more than MTU=255"
00129     #define MBED_CONF_LORA_TX_MAX_SIZE              255
00130 #endif
00131 
00132 /*!
00133  * LoRaWAN device classes definition.
00134  *
00135  * LoRaWAN Specification V1.0.2, chapter 2.1.
00136  */
00137 typedef enum {
00138     /*!
00139      * LoRaWAN device class A.
00140      *
00141      * LoRaWAN Specification V1.0.2, chapter 3.
00142      */
00143     CLASS_A ,
00144     /*!
00145      * LoRaWAN device class B.
00146      *
00147      * LoRaWAN Specification V1.0.2, chapter 8.
00148      */
00149     CLASS_B ,
00150     /*!
00151      * LoRaWAN device class C.
00152      *
00153      * LoRaWAN Specification V1.0.2, chapter 17.
00154      */
00155     CLASS_C ,
00156 } device_class_t ;
00157 
00158 /*!
00159  * LoRaMAC channel parameters definition.
00160  */
00161 typedef union {
00162     /*!
00163      * Byte-access to the bits.
00164      */
00165     int8_t value ;
00166     /*!
00167      * The structure to store the minimum and the maximum datarate.
00168      */
00169     struct sFields 
00170     {
00171          /*!
00172          * The minimum data rate.
00173          *
00174          * LoRaWAN Regional Parameters V1.0.2rB.
00175          *
00176          * The allowed ranges are region-specific. Please refer to \ref DR_0 to \ref DR_15 for details.
00177          */
00178         int8_t min : 4;
00179         /*!
00180          * The maximum data rate.
00181          *
00182          * LoRaWAN Regional Parameters V1.0.2rB.
00183          *
00184          * The allowed ranges are region-specific. Please refer to \ref DR_0 to \ref DR_15 for details.
00185          */
00186         int8_t max : 4;
00187     } fields;
00188 } dr_range_t ;
00189 
00190 /*!
00191  * LoRaMAC channel definition.
00192  */
00193 typedef struct {
00194     /*!
00195      * The frequency in Hz.
00196      */
00197     uint32_t frequency ;
00198     /*!
00199      * The alternative frequency for RX window 1.
00200      */
00201     uint32_t rx1_frequency ;
00202     /*!
00203      * The data rate definition.
00204      */
00205     dr_range_t  dr_range ;
00206     /*!
00207      * The band index.
00208      */
00209     uint8_t band ;
00210 } channel_params_t ;
00211 
00212 /*!
00213  * LoRaMAC band parameters definition.
00214  */
00215 typedef struct {
00216     /*!
00217      * The duty cycle.
00218      */
00219     uint16_t duty_cycle ;
00220     /*!
00221      * The maximum TX power.
00222      */
00223     int8_t max_tx_pwr ;
00224     /*!
00225      * The timestamp of the last Join Request TX frame.
00226      */
00227     lorawan_time_t last_join_tx_time ;
00228     /*!
00229      * The timestamp of the last TX frame.
00230      */
00231     lorawan_time_t last_tx_time ;
00232     /*!
00233      * The device off time.
00234      */
00235     lorawan_time_t off_time ;
00236     /*!
00237      * Lower band boundry
00238      */
00239     uint32_t lower_band_freq ;
00240     /*!
00241      * Higher band boundry
00242      */
00243     uint32_t higher_band_freq ;
00244 } band_t ;
00245 
00246 /*!
00247  * LoRaMAC receive window 2 channel parameters.
00248  */
00249 typedef struct {
00250     /*!
00251      * The frequency in Hz.
00252      */
00253     uint32_t frequency ;
00254     /*!
00255      * The data rate.
00256      *
00257      * LoRaWAN Regional Parameters V1.0.2rB.
00258      *
00259      * The allowed ranges are region-specific. Please refer to \ref DR_0 to \ref DR_15 for details.
00260      */
00261     uint8_t  datarate ;
00262 } rx2_channel_params ;
00263 
00264 /*!
00265  * LoRaMAC receive window enumeration
00266  */
00267 typedef enum {
00268     /*!
00269      * LoRaMAC receive window 1
00270      */
00271     RX_SLOT_WIN_1 ,
00272     /*!
00273      * LoRaMAC receive window 2
00274      */
00275     RX_SLOT_WIN_2 ,
00276     /*!
00277      * LoRaMAC receive window 2 for class c - continuous listening
00278      */
00279     RX_SLOT_WIN_CLASS_C ,
00280     /*!
00281      * LoRaMAC class b ping slot window
00282      */
00283     RX_SLOT_WIN_PING_SLOT 
00284 } rx_slot_t ;
00285 
00286 /*!
00287  * The global MAC layer parameters.
00288  */
00289 typedef struct {
00290     /*!
00291      * The TX power in channels.
00292      */
00293     int8_t channel_tx_power ;
00294     /*!
00295      * The data rate in channels.
00296      */
00297     int8_t channel_data_rate ;
00298     /*!
00299      * The system overall timing error in milliseconds.
00300      * [-SystemMaxRxError : +SystemMaxRxError]
00301      * Default: +/-10 ms
00302      */
00303     uint32_t max_sys_rx_error ;
00304     /*!
00305      * The minimum number of symbols required to detect an RX frame.
00306      * Default: 6 symbols
00307      */
00308     uint8_t min_rx_symb ;
00309     /*!
00310      * LoRaMac maximum time a reception window stays open.
00311      */
00312     uint32_t max_rx_win_time ;
00313     /*!
00314      * Receive delay 1.
00315      */
00316     uint32_t recv_delay1 ;
00317     /*!
00318      * Receive delay 2.
00319      */
00320     uint32_t recv_delay2 ;
00321     /*!
00322      * Join accept delay 1.
00323      */
00324     uint32_t join_accept_delay1 ;
00325     /*!
00326      * Join accept delay 1.
00327      */
00328     uint32_t join_accept_delay2 ;
00329     /*!
00330      * The number of uplink messages repetitions (confirmed messages only).
00331      */
00332     uint8_t retry_num ;
00333     /*!
00334      * The datarate offset between uplink and downlink on first window.
00335      */
00336     uint8_t rx1_dr_offset ;
00337     /*!
00338      * LoRaMAC 2nd reception window settings.
00339      */
00340     rx2_channel_params  rx2_channel ;
00341     /*!
00342      * The uplink dwell time configuration. 0: No limit, 1: 400ms
00343      */
00344     uint8_t uplink_dwell_time ;
00345     /*!
00346      * The downlink dwell time configuration. 0: No limit, 1: 400ms
00347      */
00348     uint8_t downlink_dwell_time ;
00349     /*!
00350      * The maximum possible EIRP.
00351      */
00352     float max_eirp ;
00353     /*!
00354      * The antenna gain of the node.
00355      */
00356     float antenna_gain ;
00357 
00358     /*!
00359      * Maximum duty cycle
00360      * \remark Possibility to shutdown the device.
00361      */
00362     uint8_t max_duty_cycle ;
00363     /*!
00364      * Aggregated duty cycle management
00365      */
00366     uint16_t aggregated_duty_cycle ;
00367 
00368     /*!
00369      * LoRaMac ADR control status
00370      */
00371     bool adr_on ;
00372 } lora_mac_system_params_t ;
00373 
00374 /*!
00375  * LoRaMAC multicast channel parameter.
00376  */
00377 typedef struct multicast_params_s  {
00378     /*!
00379      * Address.
00380      */
00381     uint32_t address ;
00382     /*!
00383      * Network session key.
00384      */
00385     uint8_t nwk_skey [16];
00386     /*!
00387      * Application session key.
00388      */
00389     uint8_t app_skey [16];
00390     /*!
00391      * Downlink counter.
00392      */
00393     uint32_t dl_frame_counter ;
00394     /*!
00395      * A reference pointer to the next multicast channel parameters in the list.
00396      */
00397     struct multicast_params_s  *next ;
00398 } multicast_params_t ;
00399 
00400 /*!
00401  * LoRaMAC frame types.
00402  *
00403  * LoRaWAN Specification V1.0.2, chapter 4.2.1, table 1.
00404  */
00405 typedef enum {
00406     /*!
00407      * LoRaMAC join request frame.
00408      */
00409     FRAME_TYPE_JOIN_REQ               = 0x00,
00410     /*!
00411      * LoRaMAC join accept frame.
00412      */
00413     FRAME_TYPE_JOIN_ACCEPT            = 0x01,
00414     /*!
00415      * LoRaMAC unconfirmed uplink frame.
00416      */
00417     FRAME_TYPE_DATA_UNCONFIRMED_UP    = 0x02,
00418     /*!
00419      * LoRaMAC unconfirmed downlink frame.
00420      */
00421     FRAME_TYPE_DATA_UNCONFIRMED_DOWN  = 0x03,
00422     /*!
00423      * LoRaMAC confirmed uplink frame.
00424      */
00425     FRAME_TYPE_DATA_CONFIRMED_UP      = 0x04,
00426     /*!
00427      * LoRaMAC confirmed downlink frame.
00428      */
00429     FRAME_TYPE_DATA_CONFIRMED_DOWN    = 0x05,
00430     /*!
00431      * LoRaMAC RFU frame.
00432      */
00433     FRAME_TYPE_RFU                    = 0x06,
00434     /*!
00435      * LoRaMAC proprietary frame.
00436      */
00437     FRAME_TYPE_PROPRIETARY            = 0x07,
00438 } mac_frame_type_t ;
00439 
00440 /*!
00441  * LoRaMAC mote MAC commands.
00442  *
00443  * LoRaWAN Specification V1.0.2, chapter 5, table 4.
00444  */
00445 typedef enum {
00446     /*!
00447      * LinkCheckReq
00448      */
00449     MOTE_MAC_LINK_CHECK_REQ           = 0x02,
00450     /*!
00451      * LinkADRAns
00452      */
00453     MOTE_MAC_LINK_ADR_ANS             = 0x03,
00454     /*!
00455      * DutyCycleAns
00456      */
00457     MOTE_MAC_DUTY_CYCLE_ANS           = 0x04,
00458     /*!
00459      * RXParamSetupAns
00460      */
00461     MOTE_MAC_RX_PARAM_SETUP_ANS       = 0x05,
00462     /*!
00463      * DevStatusAns
00464      */
00465     MOTE_MAC_DEV_STATUS_ANS           = 0x06,
00466     /*!
00467      * NewChannelAns
00468      */
00469     MOTE_MAC_NEW_CHANNEL_ANS          = 0x07,
00470     /*!
00471      * RXTimingSetupAns
00472      */
00473     MOTE_MAC_RX_TIMING_SETUP_ANS      = 0x08,
00474     /*!
00475      * TXParamSetupAns
00476      */
00477     MOTE_MAC_TX_PARAM_SETUP_ANS       = 0x09,
00478     /*!
00479      * DlChannelAns
00480      */
00481     MOTE_MAC_DL_CHANNEL_ANS           = 0x0A
00482 } mote_mac_cmds_t ;
00483 
00484 /*!
00485  * LoRaMAC server MAC commands.
00486  *
00487  * LoRaWAN Specification V1.0.2 chapter 5, table 4.
00488  */
00489 typedef enum {
00490     /*!
00491      * LinkCheckAns
00492      */
00493     SRV_MAC_LINK_CHECK_ANS            = 0x02,
00494     /*!
00495      * LinkADRReq
00496      */
00497     SRV_MAC_LINK_ADR_REQ              = 0x03,
00498     /*!
00499      * DutyCycleReq
00500      */
00501     SRV_MAC_DUTY_CYCLE_REQ            = 0x04,
00502     /*!
00503      * RXParamSetupReq
00504      */
00505     SRV_MAC_RX_PARAM_SETUP_REQ        = 0x05,
00506     /*!
00507      * DevStatusReq
00508      */
00509     SRV_MAC_DEV_STATUS_REQ            = 0x06,
00510     /*!
00511      * NewChannelReq
00512      */
00513     SRV_MAC_NEW_CHANNEL_REQ           = 0x07,
00514     /*!
00515      * RXTimingSetupReq
00516      */
00517     SRV_MAC_RX_TIMING_SETUP_REQ       = 0x08,
00518     /*!
00519      * NewChannelReq
00520      */
00521     SRV_MAC_TX_PARAM_SETUP_REQ        = 0x09,
00522     /*!
00523      * DlChannelReq
00524      */
00525     SRV_MAC_DL_CHANNEL_REQ            = 0x0A,
00526 } server_mac_cmds_t ;
00527 
00528 /*!
00529  * LoRaMAC battery level indicator.
00530  */
00531 typedef enum {
00532     /*!
00533      * An external power source.
00534      */
00535     BAT_LEVEL_EXT_SRC                 = 0x00,
00536     /*!
00537      * Battery level empty.
00538      */
00539     BAT_LEVEL_EMPTY                   = 0x01,
00540     /*!
00541      * Battery level full.
00542      */
00543     BAT_LEVEL_FULL                    = 0xFE,
00544     /*!
00545      * Battery level - no measurement available.
00546      */
00547     BAT_LEVEL_NO_MEASURE              = 0xFF,
00548 } device_battery_level_t ;
00549 
00550 /*!
00551  * LoRaMAC header field definition (MHDR field).
00552  *
00553  * LoRaWAN Specification V1.0.2, chapter 4.2.
00554  */
00555 typedef union {
00556     /*!
00557      * Byte-access to the bits.
00558      */
00559     uint8_t value ;
00560     /*!
00561      * The structure containing single access to header bits.
00562      */
00563     struct hdr_bits_s 
00564     {
00565         /*!
00566          * Major version.
00567          */
00568         uint8_t major           : 2;
00569         /*!
00570          * RFU
00571          */
00572         uint8_t RFU             : 3;
00573         /*!
00574          * Message type
00575          */
00576         uint8_t mtype           : 3;
00577     } bits;
00578 } loramac_mhdr_t ;
00579 
00580 /*!
00581  * LoRaMAC frame control field definition (FCtrl).
00582  *
00583  * LoRaWAN Specification V1.0.2, chapter 4.3.1.
00584  */
00585 typedef union {
00586     /*!
00587      * Byte-access to the bits.
00588      */
00589     uint8_t value ;
00590     /*!
00591      * The structure containing single access to bits.
00592      */
00593     struct ctrl_bits_s 
00594     {
00595         /*!
00596          * Frame options length.
00597          */
00598         uint8_t fopts_len        : 4;
00599         /*!
00600          * Frame pending bit.
00601          */
00602         uint8_t fpending        : 1;
00603         /*!
00604          * Message acknowledge bit.
00605          */
00606         uint8_t ack             : 1;
00607         /*!
00608          * ADR acknowledgment request bit.
00609          */
00610         uint8_t adr_ack_req       : 1;
00611         /*!
00612          * ADR control in the frame header.
00613          */
00614         uint8_t adr             : 1;
00615     } bits;
00616 } loramac_frame_ctrl_t ;
00617 
00618 /*!
00619  * The enumeration containing the status of the operation of a MAC service.
00620  */
00621 typedef enum {
00622     /*!
00623      * Service performed successfully.
00624      */
00625     LORAMAC_EVENT_INFO_STATUS_OK  = 0,
00626     /*!
00627      * An error occurred during the execution of the service.
00628      */
00629     LORAMAC_EVENT_INFO_STATUS_ERROR ,
00630     /*!
00631      * A TX timeout occurred.
00632      */
00633     LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT ,
00634     /*!
00635      * An RX timeout occurred on receive window 1.
00636      */
00637     LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT ,
00638     /*!
00639      * An RX timeout occurred on receive window 2.
00640      */
00641     LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT ,
00642     /*!
00643      * An RX error occurred on receive window 1.
00644      */
00645     LORAMAC_EVENT_INFO_STATUS_RX1_ERROR ,
00646     /*!
00647      * An RX error occurred on receive window 2.
00648      */
00649     LORAMAC_EVENT_INFO_STATUS_RX2_ERROR ,
00650     /*!
00651      * An error occurred in the join procedure.
00652      */
00653     LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL ,
00654     /*!
00655      * A frame with an invalid downlink counter was received. The
00656      * downlink counter of the frame was equal to the local copy
00657      * of the downlink counter of the node.
00658      */
00659     LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED ,
00660     /*!
00661      * The MAC could not retransmit a frame since the MAC decreased the datarate. The
00662      * payload size is not applicable for the datarate.
00663      */
00664     LORAMAC_EVENT_INFO_STATUS_TX_DR_PAYLOAD_SIZE_ERROR ,
00665     /*!
00666      * The node has lost MAX_FCNT_GAP or more frames.
00667      */
00668     LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS ,
00669     /*!
00670      * An address error occurred.
00671      */
00672     LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL ,
00673     /*!
00674      * Message integrity check failure.
00675      */
00676     LORAMAC_EVENT_INFO_STATUS_MIC_FAIL ,
00677     /*!
00678      * Crypto methods failure
00679      */
00680     LORAMAC_EVENT_INFO_STATUS_CRYPTO_FAIL ,
00681 } loramac_event_info_status_t ;
00682 
00683 /*!
00684  * LoRaMac service state flags.
00685  */
00686 typedef union {
00687     /*!
00688      * Byte-access to the bits.
00689      */
00690     uint8_t value ;
00691     /*!
00692      * The structure containing single access to bits.
00693      */
00694     struct mac_flag_bits_s 
00695     {
00696         /*!
00697          * MCPS-Req pending
00698          */
00699         uint8_t mcps_req         : 1;
00700         /*!
00701          * MCPS-Ind pending
00702          */
00703         uint8_t mcps_ind         : 1;
00704         /*!
00705          * MCPS-Ind pending. Skip indication to the application layer.
00706          */
00707         uint8_t mcps_ind_skip     : 1;
00708         /*!
00709          * MLME-Req pending
00710          */
00711         uint8_t mlme_req         : 1;
00712         /*!
00713          * MLME-Ind pending
00714          */
00715         uint8_t mlme_ind         : 1;
00716         /*!
00717          * MAC cycle done
00718          */
00719         uint8_t mac_done         : 1;
00720     } bits;
00721 } loramac_flags_t ;
00722 
00723 /*!
00724  *
00725  * \brief   LoRaMAC data services
00726  *
00727  * \details The following table list the primitives supported by a
00728  *          specific MAC data service:
00729  *
00730  * Name                  | Request | Indication | Response | Confirm
00731  * --------------------- | :-----: | :--------: | :------: | :-----:
00732  * \ref MCPS_UNCONFIRMED | YES     | YES        | NO       | YES
00733  * \ref MCPS_CONFIRMED   | YES     | YES        | NO       | YES
00734  * \ref MCPS_MULTICAST   | NO      | YES        | NO       | NO
00735  * \ref MCPS_PROPRIETARY | YES     | YES        | NO       | YES
00736  *
00737  * The following table provides links to the function implementations of the
00738  * related MCPS primitives:
00739  *
00740  * Primitive        | Function
00741  * ---------------- | :---------------------:
00742  * MCPS-Request     | LoRaMacMlmeRequest
00743  * MCPS-Confirm     | MacMcpsConfirm in \ref loramac_primitives_t
00744  * MCPS-Indication  | MacMcpsIndication in \ref loramac_primitives_t
00745  */
00746 typedef enum {
00747     /*!
00748      * Unconfirmed LoRaMAC frame.
00749      */
00750     MCPS_UNCONFIRMED ,
00751     /*!
00752      * Confirmed LoRaMAC frame.
00753      */
00754     MCPS_CONFIRMED ,
00755     /*!
00756      * Multicast LoRaMAC frame.
00757      */
00758     MCPS_MULTICAST ,
00759     /*!
00760      * Proprietary frame.
00761      */
00762     MCPS_PROPRIETARY ,
00763 } mcps_type_t;
00764 
00765 /*!
00766  * LoRaMAC MCPS-Request structure.
00767  */
00768 typedef struct {
00769     /*!
00770      * MCPS-Request type.
00771      */
00772     mcps_type_t type ;
00773 
00774     /*!
00775      * Frame port field. Must be set if the payload is not empty. Use the
00776      * application-specific frame port values: [1...223].
00777      *
00778      * LoRaWAN Specification V1.0.2, chapter 4.3.2.
00779      */
00780     uint8_t fport ;
00781 
00782     /*!
00783      * Uplink datarate, if ADR is off.
00784      */
00785     int8_t data_rate ;
00786     /*!
00787      * The number of trials to transmit the frame, if the LoRaMAC layer did not
00788      * receive an acknowledgment. The MAC performs a datarate adaptation
00789      * according to the LoRaWAN Specification V1.0.2, chapter 18.4, as in
00790      * the following table:
00791      *
00792      * Transmission nb | Data Rate
00793      * ----------------|-----------
00794      * 1 (first)       | DR
00795      * 2               | DR
00796      * 3               | max(DR-1,0)
00797      * 4               | max(DR-1,0)
00798      * 5               | max(DR-2,0)
00799      * 6               | max(DR-2,0)
00800      * 7               | max(DR-3,0)
00801      * 8               | max(DR-3,0)
00802      *
00803      * Note that if nb_trials is set to 1 or 2, the MAC will not decrease
00804      * the datarate, if the LoRaMAC layer did not receive an acknowledgment.
00805      */
00806     uint8_t nb_trials ;
00807 
00808     /** Payload data
00809       *
00810       * A pointer to the buffer of the frame payload.
00811       */
00812      void *f_buffer;
00813      /** Payload size
00814       *
00815       * The size of the frame payload.
00816       */
00817      uint16_t f_buffer_size;
00818 
00819 } loramac_mcps_req_t ;
00820 
00821 /*!
00822  * LoRaMAC MCPS-Confirm.
00823  */
00824 typedef struct {
00825     /*!
00826      * Holds the previously performed MCPS-Request type. i.e., the type of
00827      * the MCPS request for which this confirmation is being generated
00828      */
00829     mcps_type_t req_type ;
00830     /*!
00831      * The status of the operation.
00832      */
00833     loramac_event_info_status_t  status ;
00834     /*!
00835      * The uplink datarate.
00836      */
00837     uint8_t data_rate ;
00838     /*!
00839      * The transmission power.
00840      */
00841     int8_t tx_power ;
00842     /*!
00843      * Set if an acknowledgement was received.
00844      */
00845     bool ack_received ;
00846     /*!
00847      * Provides the number of retransmissions.
00848      */
00849     uint8_t nb_retries ;
00850     /*!
00851      * The transmission time on air of the frame.
00852      */
00853     lorawan_time_t tx_toa ;
00854     /*!
00855      * The uplink counter value related to the frame.
00856      */
00857     uint32_t ul_frame_counter ;
00858     /*!
00859      * The uplink frequency related to the frame.
00860      */
00861     uint32_t ul_frequency ;
00862 } loramac_mcps_confirm_t ;
00863 
00864 /*!
00865  * LoRaMAC MCPS-Indication primitive.
00866  */
00867 typedef struct {
00868     /*!
00869      * MCPS-Indication type.
00870      */
00871     mcps_type_t type ;
00872     /*!
00873      * The status of the operation.
00874      */
00875     loramac_event_info_status_t  status ;
00876     /*!
00877      * Multicast.
00878      */
00879     uint8_t multicast ;
00880     /*!
00881      * The application port.
00882      */
00883     uint8_t port ;
00884     /*!
00885      * The downlink datarate.
00886      */
00887     uint8_t rx_datarate ;
00888     /*!
00889      * Frame pending status.
00890      */
00891     uint8_t fpending_status ;
00892     /*!
00893      * A pointer to the received data stream.
00894      */
00895     uint8_t *buffer ;
00896     /*!
00897      * The size of the received data stream.
00898      */
00899     uint16_t buffer_size ;
00900     /*!
00901      * Indicates, if data is available.
00902      */
00903     bool is_data_recvd ;
00904     /*!
00905      * The RSSI of the received packet.
00906      */
00907     int16_t rssi ;
00908     /*!
00909      * The SNR of the received packet.
00910      */
00911     uint8_t snr ;
00912     /*!
00913      * The receive window.
00914      *
00915      * [0: Rx window 1, 1: Rx window 2]
00916      */
00917     rx_slot_t  rx_slot ;
00918     /*!
00919      * Set if an acknowledgement was received.
00920      */
00921     bool is_ack_recvd ;
00922     /*!
00923      * The downlink counter value for the received frame.
00924      */
00925     uint32_t dl_frame_counter ;
00926 } loramac_mcps_indication_t ;
00927 
00928 /*!
00929  * \brief LoRaMAC management services.
00930  *
00931  * \details The following table list the primitives supported by a
00932  *          specific MAC management service:
00933  *
00934  * Name                         | Request | Indication | Response | Confirm
00935  * ---------------------------- | :-----: | :--------: | :------: | :-----:
00936  * \ref MLME_JOIN               | YES     | NO         | NO       | YES
00937  * \ref MLME_LINK_CHECK         | YES     | NO         | NO       | YES
00938  * \ref MLME_TXCW               | YES     | NO         | NO       | YES
00939  * \ref MLME_SCHEDULE_UPLINK    | NO      | YES        | NO       | NO
00940  *
00941  * The following table provides links to the function implementations of the
00942  * related MLME primitives.
00943  *
00944  * Primitive        | Function
00945  * ---------------- | :---------------------:
00946  * MLME-Request     | LoRaMacMlmeRequest
00947  * MLME-Confirm     | MacMlmeConfirm in \ref loramac_primitives_t
00948  * MLME-Indication  | MacMlmeIndication in \ref loramac_primitives_t
00949  */
00950 typedef enum {
00951     /*!
00952      * Initiates the Over-the-Air activation.
00953      *
00954      * LoRaWAN Specification V1.0.2, chapter 6.2.
00955      */
00956     MLME_JOIN ,
00957     /*!
00958      * LinkCheckReq - Connectivity validation.
00959      *
00960      * LoRaWAN Specification V1.0.2, chapter 5, table 4.
00961      */
00962     MLME_LINK_CHECK ,
00963     /*!
00964      * Sets TX continuous wave mode.
00965      *
00966      * LoRaWAN end-device certification.
00967      */
00968     MLME_TXCW ,
00969     /*!
00970      * Sets TX continuous wave mode (new LoRa-Alliance CC definition).
00971      *
00972      * LoRaWAN end-device certification.
00973      */
00974     MLME_TXCW_1 ,
00975     /*!
00976      * Indicates that the application shall perform an uplink as
00977      * soon as possible.
00978      */
00979     MLME_SCHEDULE_UPLINK 
00980 } mlme_type_t;
00981 
00982 /*!
00983  * LoRaMAC MLME-Request for the join service.
00984  */
00985 typedef struct {
00986     /*!
00987      * A globally unique end-device identifier.
00988      *
00989      * LoRaWAN Specification V1.0.2, chapter 6.2.1.
00990      */
00991     uint8_t *dev_eui ;
00992     /*!
00993      * An application identifier.
00994      *
00995      * LoRaWAN Specification V1.0.2, chapter 6.1.2
00996      */
00997     uint8_t *app_eui ;
00998     /*!
00999      * AES-128 application key.
01000      *
01001      * LoRaWAN Specification V1.0.2, chapter 6.2.2.
01002      */
01003     uint8_t *app_key ;
01004     /*!
01005      * The number of trials for the join request.
01006      */
01007     uint8_t nb_trials ;
01008 } mlme_join_req_t ;
01009 
01010 /*!
01011  * LoRaMAC MLME-Request for TX continuous wave mode.
01012  */
01013 typedef struct {
01014     /*!
01015      * The time while the radio is kept in continuous wave mode, in seconds.
01016      */
01017     uint16_t timeout ;
01018     /*!
01019      * The RF frequency to set (only used with the new way).
01020      */
01021     uint32_t frequency ;
01022     /*!
01023      * The RF output power to set (only used with the new way).
01024      */
01025     uint8_t power ;
01026 } mlme_cw_tx_mode_t ;
01027 
01028 /*!
01029  * LoRaMAC MLME-Request structure.
01030  */
01031 typedef struct {
01032     /*!
01033      * MLME-Request type.
01034      */
01035     mlme_type_t type ;
01036 
01037     /*!
01038      * MLME-Request parameters.
01039      */
01040     union {
01041         /*!
01042          * MLME-Request parameters for a join request.
01043          */
01044         mlme_join_req_t  join ;
01045         /*!
01046          * MLME-Request parameters for TX continuous mode request.
01047          */
01048         mlme_cw_tx_mode_t  cw_tx_mode ;
01049     } req;
01050 } loramac_mlme_req_t ;
01051 
01052 /*!
01053  * LoRaMAC MLME-Confirm primitive.
01054  */
01055 typedef struct {
01056     /*!
01057      * The previously performed MLME-Request. i.e., the request type
01058      * for which the confirmation is being generated
01059      */
01060     mlme_type_t req_type ;
01061     /*!
01062      * The status of the operation.
01063      */
01064     loramac_event_info_status_t  status ;
01065     /*!
01066      * The transmission time on air of the frame.
01067      */
01068     lorawan_time_t tx_toa ;
01069     /*!
01070      * The demodulation margin. Contains the link margin [dB] of the last LinkCheckReq
01071      * successfully received.
01072      */
01073     uint8_t demod_margin ;
01074     /*!
01075      * The number of gateways which received the last LinkCheckReq.
01076      */
01077     uint8_t nb_gateways ;
01078     /*!
01079      * The number of retransmissions.
01080      */
01081     uint8_t nb_retries ;
01082 } loramac_mlme_confirm_t ;
01083 
01084 /*!
01085  * LoRaMAC MLME-Indication primitive
01086  */
01087 typedef struct {
01088     /*!
01089      * MLME-Indication type
01090      */
01091     mlme_type_t indication_type ;
01092 } loramac_mlme_indication_t ;
01093 
01094 /*!
01095  * LoRa MAC Information Base (MIB).
01096  *
01097  * The following table lists the MIB parameters and the related attributes:
01098  *
01099  * Attribute                         | Get | Set
01100  * --------------------------------- | :-: | :-:
01101  * \ref MIB_DEVICE_CLASS             | YES | YES
01102  * \ref MIB_NETWORK_JOINED           | YES | YES
01103  * \ref MIB_ADR                      | YES | YES
01104  * \ref MIB_NET_ID                   | YES | YES
01105  * \ref MIB_DEV_ADDR                 | YES | YES
01106  * \ref MIB_NWK_SKEY                 | YES | YES
01107  * \ref MIB_APP_SKEY                 | YES | YES
01108  * \ref MIB_PUBLIC_NETWORK           | YES | YES
01109  * \ref MIB_REPEATER_SUPPORT         | YES | YES
01110  * \ref MIB_CHANNELS                 | YES | NO
01111  * \ref MIB_RX2_CHANNEL              | YES | YES
01112  * \ref MIB_CHANNELS_MASK            | YES | YES
01113  * \ref MIB_CHANNELS_DEFAULT_MASK    | YES | YES
01114  * \ref MIB_CHANNELS_NB_REP          | YES | YES
01115  * \ref MIB_MAX_RX_WINDOW_DURATION   | YES | YES
01116  * \ref MIB_RECEIVE_DELAY_1          | YES | YES
01117  * \ref MIB_RECEIVE_DELAY_2          | YES | YES
01118  * \ref MIB_JOIN_ACCEPT_DELAY_1      | YES | YES
01119  * \ref MIB_JOIN_ACCEPT_DELAY_2      | YES | YES
01120  * \ref MIB_CHANNELS_DATARATE        | YES | YES
01121  * \ref MIB_CHANNELS_DEFAULT_DATARATE| YES | YES
01122  * \ref MIB_CHANNELS_TX_POWER        | YES | YES
01123  * \ref MIB_CHANNELS_DEFAULT_TX_POWER| YES | YES
01124  * \ref MIB_UPLINK_COUNTER           | YES | YES
01125  * \ref MIB_DOWNLINK_COUNTER         | YES | YES
01126  * \ref MIB_MULTICAST_CHANNEL        | YES | NO
01127  * \ref MIB_SYSTEM_MAX_RX_ERROR      | YES | YES
01128  * \ref MIB_MIN_RX_SYMBOLS           | YES | YES
01129  * \ref MIB_ANTENNA_GAIN             | YES | YES
01130  *
01131  * The following table provides links to the function implementations of the
01132  * related MIB primitives:
01133  *
01134  * Primitive        | Function
01135  * ---------------- | :---------------------:
01136  * MIB-Set          | LoRaMacMibSetRequestConfirm
01137  * MIB-Get          | LoRaMacMibGetRequestConfirm
01138  */
01139 typedef enum {
01140     /*!
01141      * LoRaWAN device class.
01142      *
01143      * LoRaWAN Specification V1.0.2.
01144      */
01145     MIB_DEVICE_CLASS ,
01146     /*!
01147      * LoRaWAN Network joined attribute.
01148      *
01149      * LoRaWAN Specification V1.0.2.
01150      */
01151     MIB_NETWORK_JOINED ,
01152     /*!
01153      * Adaptive data rate.
01154      *
01155      * LoRaWAN Specification V1.0.2, chapter 4.3.1.1.
01156      *
01157      * [true: ADR enabled, false: ADR disabled].
01158      */
01159     MIB_ADR ,
01160     /*!
01161      * Network identifier.
01162      *
01163      * LoRaWAN Specification V1.0.2, chapter 6.1.1.
01164      */
01165     MIB_NET_ID ,
01166     /*!
01167      * End-device address.
01168      *
01169      * LoRaWAN Specification V1.0.2, chapter 6.1.1.
01170      */
01171     MIB_DEV_ADDR ,
01172     /*!
01173      * Network session key.
01174      *
01175      * LoRaWAN Specification V1.0.2, chapter 6.1.3.
01176      */
01177     MIB_NWK_SKEY ,
01178     /*!
01179      * Application session key.
01180      *
01181      * LoRaWAN Specification V1.0.2, chapter 6.1.4.
01182      */
01183     MIB_APP_SKEY ,
01184     /*!
01185      * Set the network type to public or private.
01186      *
01187      * LoRaWAN Regional Parameters V1.0.2rB.
01188      *
01189      * [true: public network, false: private network]
01190      */
01191     MIB_PUBLIC_NETWORK ,
01192     /*!
01193      * Support the operation with repeaters.
01194      *
01195      * LoRaWAN Regional Parameters V1.0.2rB.
01196      *
01197      * [true: repeater support enabled, false: repeater support disabled]
01198      */
01199     MIB_REPEATER_SUPPORT ,
01200     /*!
01201      * Communication channels. A GET request will return a
01202      * pointer that references the first entry of the channel list. The
01203      * list is of size LORA_MAX_NB_CHANNELS.
01204      *
01205      * LoRaWAN Regional Parameters V1.0.2rB.
01206      */
01207     MIB_CHANNELS ,
01208     /*!
01209      * Set receive window 2 channel.
01210      *
01211      * LoRaWAN Specification V1.0.2, chapter 3.3.1.
01212      */
01213     MIB_RX2_CHANNEL ,
01214     /*!
01215      * Set receive window 2 channel.
01216      *
01217      * LoRaWAN Specification V1.0.2, chapter 3.3.2.
01218      */
01219     MIB_RX2_DEFAULT_CHANNEL ,
01220     /*!
01221      * LoRaWAN channels mask.
01222      *
01223      * LoRaWAN Regional Parameters V1.0.2rB.
01224      */
01225     MIB_CHANNELS_MASK ,
01226     /*!
01227      * LoRaWAN default channels mask.
01228      *
01229      * LoRaWAN Regional Parameters V1.0.2rB.
01230      */
01231     MIB_CHANNELS_DEFAULT_MASK ,
01232     /*!
01233      * Set the number of repetitions on a channel.
01234      *
01235      * LoRaWAN Specification V1.0.2, chapter 5.2.
01236      */
01237     MIB_CHANNELS_NB_REP ,
01238     /*!
01239      * The maximum receive window duration in [ms].
01240      *
01241      * LoRaWAN Specification V1.0.2, chapter 3.3.3.
01242      */
01243     MIB_MAX_RX_WINDOW_DURATION ,
01244     /*!
01245      * The receive delay 1 in [ms].
01246      *
01247      * LoRaWAN Regional Parameters V1.0.2rB.
01248      */
01249     MIB_RECEIVE_DELAY_1 ,
01250     /*!
01251      * The receive delay 2 in [ms].
01252      *
01253      * LoRaWAN Regional Parameters V1.0.2rB.
01254      */
01255     MIB_RECEIVE_DELAY_2 ,
01256     /*!
01257      * The join accept delay 1 in [ms].
01258      *
01259      * LoRaWAN Regional Parameters V1.0.2rB.
01260      */
01261     MIB_JOIN_ACCEPT_DELAY_1 ,
01262     /*!
01263      * The join accept delay 2 in [ms].
01264      *
01265      * LoRaWAN Regional Parameters V1.0.2rB.
01266      */
01267     MIB_JOIN_ACCEPT_DELAY_2 ,
01268     /*!
01269      * The default data rate of a channel.
01270      *
01271      * LoRaWAN Regional Parameters V1.0.2rB.
01272      *
01273      * The allowed ranges are region-specific. Please refer to \ref DR_0 to \ref DR_15 for details.
01274      */
01275     MIB_CHANNELS_DEFAULT_DATARATE ,
01276     /*!
01277      * The data rate of a channel.
01278      *
01279      * LoRaWAN Regional Parameters V1.0.2rB.
01280      *
01281      * The allowed ranges are region-specific. Please refer to \ref DR_0 to \ref DR_15 for details.
01282      */
01283     MIB_CHANNELS_DATARATE ,
01284     /*!
01285      * The transmission power of a channel.
01286      *
01287      * LoRaWAN Regional Parameters V1.0.2rB.
01288      *
01289      * The allowed ranges are region-specific. Please refer to \ref TX_POWER_0 to \ref TX_POWER_15 for details.
01290      */
01291     MIB_CHANNELS_TX_POWER ,
01292     /*!
01293      * The transmission power of a channel.
01294      *
01295      * LoRaWAN Regional Parameters V1.0.2rB.
01296      *
01297      * The allowed ranges are region-specific. Please refer to \ref TX_POWER_0 to \ref TX_POWER_15 for details.
01298      */
01299     MIB_CHANNELS_DEFAULT_TX_POWER ,
01300     /*!
01301      * LoRaWAN uplink counter.
01302      *
01303      * LoRaWAN Specification V1.0.2, chapter 4.3.1.5.
01304      */
01305     MIB_UPLINK_COUNTER ,
01306     /*!
01307      * LoRaWAN downlink counter.
01308      *
01309      * LoRaWAN Specification V1.0.2, chapter 4.3.1.5.
01310      */
01311     MIB_DOWNLINK_COUNTER ,
01312     /*!
01313      * Multicast channels. A GET request will return a pointer to the first
01314      * entry of the multicast channel linked list. If the pointer is equal to
01315      * NULL, the list is empty.
01316      */
01317     MIB_MULTICAST_CHANNEL ,
01318     /*!
01319      * System overall timing error in milliseconds.
01320      * [-SystemMaxRxError : +SystemMaxRxError]
01321      * Default: +/-10 ms
01322      */
01323     MIB_SYSTEM_MAX_RX_ERROR ,
01324     /*!
01325      * The minimum  number of symbols required to detect an RX frame.
01326      * Default: 6 symbols
01327      */
01328     MIB_MIN_RX_SYMBOLS ,
01329     /*!
01330      * The antenna gain of the node. The default value is region-specific.
01331      * The antenna gain is used to calculate the TX power of the node.
01332      * The formula is:
01333      * radioTxPower = ( int8_t )floor( maxEirp - antennaGain )
01334      */
01335     MIB_ANTENNA_GAIN 
01336 } mib_type_t ;
01337 
01338 /*!
01339  * LoRaMAC MIB parameters.
01340  */
01341 typedef union {
01342     /*!
01343      * LoRaWAN device class.
01344      *
01345      * Related MIB type: \ref MIB_DEVICE_CLASS
01346      */
01347     device_class_t  dev_class ;
01348     /*!
01349      * LoRaWAN network joined attribute
01350      *
01351      * Related MIB type: \ref MIB_NETWORK_JOINED
01352      */
01353     bool is_nwk_joined ;
01354     /*!
01355      * Activation state of ADR
01356      *
01357      * Related MIB type: \ref MIB_ADR
01358      */
01359     bool is_adr_enable ;
01360     /*!
01361      * Network identifier
01362      *
01363      * Related MIB type: \ref MIB_NET_ID
01364      */
01365     uint32_t net_id ;
01366     /*!
01367      * End-device address
01368      *
01369      * Related MIB type: \ref MIB_DEV_ADDR
01370      */
01371     uint32_t dev_addr ;
01372     /*!
01373      * Network session key
01374      *
01375      * Related MIB type: \ref MIB_NWK_SKEY
01376      */
01377     uint8_t *nwk_skey ;
01378     /*!
01379      * Application session key
01380      *
01381      * Related MIB type: \ref MIB_APP_SKEY
01382      */
01383     uint8_t *app_skey ;
01384     /*!
01385      * Enable or disable a public network
01386      *
01387      * Related MIB type: \ref MIB_PUBLIC_NETWORK
01388      */
01389     bool enable_public_nwk ;
01390     /*!
01391      * Enable or disable repeater support
01392      *
01393      * Related MIB type: \ref MIB_REPEATER_SUPPORT
01394      */
01395     bool enable_repeater_support ;
01396     /*!
01397      * LoRaWAN channel
01398      *
01399      * Related MIB type: \ref MIB_CHANNELS
01400      */
01401     channel_params_t * channel_list ;
01402      /*!
01403      * Channel for the receive window 2
01404      *
01405      * Related MIB type: \ref MIB_RX2_CHANNEL
01406      */
01407     rx2_channel_params  rx2_channel ;
01408      /*!
01409      * Channel for the receive window 2
01410      *
01411      * Related MIB type: \ref MIB_RX2_DEFAULT_CHANNEL
01412      */
01413     rx2_channel_params  default_rx2_channel ;
01414     /*!
01415      * Channel mask
01416      *
01417      * Related MIB type: \ref MIB_CHANNELS_MASK
01418      */
01419     uint16_t* channel_mask ;
01420     /*!
01421      * Default channel mask
01422      *
01423      * Related MIB type: \ref MIB_CHANNELS_DEFAULT_MASK
01424      */
01425     uint16_t* default_channel_mask ;
01426     /*!
01427      * Number of frame repetitions
01428      *
01429      * Related MIB type: \ref MIB_CHANNELS_NB_REP
01430      */
01431     uint8_t channel_nb_rep ;
01432     /*!
01433      * Maximum receive window duration
01434      *
01435      * Related MIB type: \ref MIB_MAX_RX_WINDOW_DURATION
01436      */
01437     uint32_t max_rx_window ;
01438     /*!
01439      * Receive delay 1
01440      *
01441      * Related MIB type: \ref MIB_RECEIVE_DELAY_1
01442      */
01443     uint32_t recv_delay1 ;
01444     /*!
01445      * Receive delay 2
01446      *
01447      * Related MIB type: \ref MIB_RECEIVE_DELAY_2
01448      */
01449     uint32_t recv_delay2 ;
01450     /*!
01451      * Join accept delay 1
01452      *
01453      * Related MIB type: \ref MIB_JOIN_ACCEPT_DELAY_1
01454      */
01455     uint32_t join_accept_delay1 ;
01456     /*!
01457      * Join accept delay 2
01458      *
01459      * Related MIB type: \ref MIB_JOIN_ACCEPT_DELAY_2
01460      */
01461     uint32_t join_accept_delay2 ;
01462     /*!
01463      * Channels data rate
01464      *
01465      * Related MIB type: \ref MIB_CHANNELS_DEFAULT_DATARATE
01466      */
01467     int8_t default_channel_data_rate ;
01468     /*!
01469      * Channels data rate
01470      *
01471      * Related MIB type: \ref MIB_CHANNELS_DATARATE
01472      */
01473     int8_t channel_data_rate ;
01474     /*!
01475      * Channels TX power
01476      *
01477      * Related MIB type: \ref MIB_CHANNELS_DEFAULT_TX_POWER
01478      */
01479     int8_t default_channel_tx_pwr ;
01480     /*!
01481      * Channels TX power
01482      *
01483      * Related MIB type: \ref MIB_CHANNELS_TX_POWER
01484      */
01485     int8_t channel_tx_pwr ;
01486     /*!
01487      * LoRaWAN uplink counter
01488      *
01489      * Related MIB type: \ref MIB_UPLINK_COUNTER
01490      */
01491     uint32_t ul_frame_counter ;
01492     /*!
01493      * LoRaWAN downlink counter
01494      *
01495      * Related MIB type: \ref MIB_DOWNLINK_COUNTER
01496      */
01497     uint32_t dl_frame_counter ;
01498     /*!
01499      * Multicast channel
01500      *
01501      * Related MIB type: \ref MIB_MULTICAST_CHANNEL
01502      */
01503     multicast_params_t * multicast_list ;
01504     /*!
01505      * System overall timing error in milliseconds
01506      *
01507      * Related MIB type: \ref MIB_SYSTEM_MAX_RX_ERROR
01508      */
01509     uint32_t max_rx_sys_error ;
01510     /*!
01511      * Minimum required number of symbols to detect an RX frame
01512      *
01513      * Related MIB type: \ref MIB_MIN_RX_SYMBOLS
01514      */
01515     uint8_t min_rx_symb ;
01516     /*!
01517      * Antenna gain
01518      *
01519      * Related MIB type: \ref MIB_ANTENNA_GAIN
01520      */
01521     float antenna_gain ;
01522 } mib_params_t ;
01523 
01524 /*!
01525  * LoRaMAC MIB-RequestConfirm structure
01526  */
01527 typedef struct {
01528     /*!
01529      * MIB-Request type
01530      */
01531     mib_type_t  type ;
01532 
01533     /*!
01534      * MLME-RequestConfirm parameters
01535      */
01536     mib_params_t  param ;
01537 }loramac_mib_req_confirm_t ;
01538 
01539 /*!
01540  * LoRaMAC TX information
01541  */
01542 typedef struct {
01543     /*!
01544      * Defines the size of the applicable payload that can be processed.
01545      */
01546     uint8_t max_possible_payload_size ;
01547     /*!
01548      * The current payload size, dependent on the current datarate.
01549      */
01550     uint8_t current_payload_size ;
01551 } loramac_tx_info_t ;
01552 
01553 /** LoRaMAC status.
01554  *
01555  */
01556 typedef enum lorawan_status {
01557     LORAWAN_STATUS_OK = 0,                         /**< Service started successfully */
01558     LORAWAN_STATUS_BUSY = -1000,                   /**< Service not started - LoRaMAC is busy */
01559     LORAWAN_STATUS_WOULD_BLOCK = -1001,            /**< LoRaMAC cannot send at the moment or have nothing to read */
01560     LORAWAN_STATUS_SERVICE_UNKNOWN = -1002,        /**< Service unknown */
01561     LORAWAN_STATUS_PARAMETER_INVALID = -1003,      /**< Service not started - invalid parameter */
01562     LORAWAN_STATUS_FREQUENCY_INVALID = -1004,      /**< Service not started - invalid frequency */
01563     LORAWAN_STATUS_DATARATE_INVALID = -1005,       /**< Service not started - invalid datarate */
01564     LORAWAN_STATUS_FREQ_AND_DR_INVALID = -1006,    /**< Service not started - invalid frequency and datarate */
01565     LORAWAN_STATUS_NO_NETWORK_JOINED = -1009,      /**< Service not started - the device is not in a LoRaWAN */
01566     LORAWAN_STATUS_LENGTH_ERROR = -1010,           /**< Service not started - payload lenght error */
01567     LORAWAN_STATUS_DEVICE_OFF = -1011,             /**< Service not started - the device is switched off */
01568     LORAWAN_STATUS_NOT_INITIALIZED = -1012,        /**< Service not started - stack not initialized */
01569     LORAWAN_STATUS_UNSUPPORTED = -1013,            /**< Service not supported */
01570     LORAWAN_STATUS_CRYPTO_FAIL = -1014,            /**< Service not started - crypto failure */
01571     LORAWAN_STATUS_PORT_INVALID = -1015,           /**< Invalid port */
01572     LORAWAN_STATUS_CONNECT_IN_PROGRESS = -1016,    /**< Services started - Connection in progress */
01573     LORAWAN_STATUS_NO_ACTIVE_SESSIONS = -1017,            /**< Services not started - No active session */
01574     LORAWAN_STATUS_IDLE = -1018,                   /**< Services started - Idle at the moment */
01575 #if defined(LORAWAN_COMPLIANCE_TEST)
01576     LORAWAN_STATUS_COMPLIANCE_TEST_ON = -1019,     /**< Compliance test - is on-going */
01577 #endif
01578 } lorawan_status_t;
01579 
01580 /*!
01581  * LoRaMAC events structure.
01582  * Used to notify upper layers of MAC events.
01583  */
01584 typedef struct {
01585     /*!
01586      * \brief   MCPS-Confirm primitive.
01587      *
01588      * \param   [OUT] MCPS-Confirm parameters.
01589      */
01590     mbed::Callback<void(loramac_mcps_confirm_t*)> mcps_confirm;
01591 
01592     /*!
01593      * \brief   MCPS-Indication primitive.
01594      *
01595      * \param   [OUT] MCPS-Indication parameters.
01596      */
01597     mbed::Callback<void(loramac_mcps_indication_t*)> mcps_indication;
01598 
01599     /*!
01600      * \brief   MLME-Confirm primitive.
01601      *
01602      * \param   [OUT] MLME-Confirm parameters.
01603      */
01604     mbed::Callback<void(loramac_mlme_confirm_t*)> mlme_confirm;
01605 
01606     /*!
01607      * \brief   MLME-Indication primitive
01608      *
01609      * \param   [OUT] MLME-Indication parameters
01610      */
01611     mbed::Callback<void(loramac_mlme_indication_t*)> mlme_indication;
01612 }loramac_primitives_t ;
01613 
01614 /** Enum of LoRaWAN connection type.
01615  *
01616  * The LoRaWAN connection type specifies how an end-device connects to the gateway.
01617  */
01618 typedef enum lorawan_connect_type {
01619     LORAWAN_CONNECTION_OTAA = 0,    /**< Over The Air Activation */
01620     LORAWAN_CONNECTION_ABP          /**< Activation By Personalization */
01621 } lorawan_connect_type_t;
01622 
01623 /** The lorawan_connect_otaa structure.
01624  *
01625  * A structure representing the LoRaWAN Over The Air Activation
01626  * parameters.
01627  */
01628 typedef struct {
01629     /** End-device identifier
01630      *
01631      * LoRaWAN Specification V1.0.2, chapter 6.2.1
01632      */
01633     uint8_t *dev_eui;
01634     /** Application identifier
01635      *
01636      * LoRaWAN Specification V1.0.2, chapter 6.1.2
01637      */
01638     uint8_t *app_eui;
01639     /** AES-128 application key
01640      *
01641      * LoRaWAN Specification V1.0.2, chapter 6.2.2
01642      */
01643     uint8_t *app_key;
01644     /** Join request trials
01645      *
01646      * Number of trials for the join request.
01647      */
01648     uint8_t nb_trials;
01649 } lorawan_connect_otaa_t;
01650 
01651 /** The lorawan_connect_abp structure.
01652  *
01653  * A structure representing the LoRaWAN Activation By Personalization
01654  * parameters.
01655  */
01656 typedef struct {
01657     /** Network identifier
01658      *
01659      * LoRaWAN Specification V1.0.2, chapter 6.1.1
01660      */
01661     uint32_t nwk_id;
01662     /** End-device address
01663      *
01664      * LoRaWAN Specification V1.0.2, chapter 6.1.1
01665      */
01666     uint32_t dev_addr;
01667     /** Network session key
01668      *
01669      * LoRaWAN Specification V1.0.2, chapter 6.1.3
01670      */
01671     uint8_t *nwk_skey;
01672     /** Application session key
01673      *
01674      * LoRaWAN Specification V1.0.2, chapter 6.1.4
01675      */
01676     uint8_t *app_skey;
01677 } lorawan_connect_abp_t;
01678 
01679 /**
01680  * Stack level TX message structure
01681  */
01682 typedef struct {
01683 
01684     /**
01685      * TX Ongoing flag
01686      */
01687     bool tx_ongoing;
01688 
01689     /**
01690      * Application Port Number
01691      */
01692     uint8_t port;
01693 
01694     /**
01695      * Message type
01696      */
01697     mcps_type_t type;
01698 
01699     /*!
01700      * Frame port field. Must be set if the payload is not empty. Use the
01701      * application-specific frame port values: [1...223].
01702      *
01703      * LoRaWAN Specification V1.0.2, chapter 4.3.2.
01704      */
01705     uint8_t fport ;
01706 
01707     /*!
01708      * Uplink datarate, if ADR is off.
01709      */
01710     int8_t data_rate ;
01711     /*!
01712      * The number of trials to transmit the frame, if the LoRaMAC layer did not
01713      * receive an acknowledgment. The MAC performs a datarate adaptation
01714      * according to the LoRaWAN Specification V1.0.2, chapter 18.4, as in
01715      * the following table:
01716      *
01717      * Transmission nb | Data Rate
01718      * ----------------|-----------
01719      * 1 (first)       | DR
01720      * 2               | DR
01721      * 3               | max(DR-1,0)
01722      * 4               | max(DR-1,0)
01723      * 5               | max(DR-2,0)
01724      * 6               | max(DR-2,0)
01725      * 7               | max(DR-3,0)
01726      * 8               | max(DR-3,0)
01727      *
01728      * Note that if nb_trials is set to 1 or 2, the MAC will not decrease
01729      * the datarate, if the LoRaMAC layer did not receive an acknowledgment.
01730      */
01731     uint8_t nb_trials ;
01732 
01733     /** Payload data
01734      *
01735      * Base pointer to the buffer
01736      */
01737     uint8_t f_buffer[MBED_CONF_LORA_TX_MAX_SIZE];
01738 
01739     /** Payload size.
01740      *
01741      * The size of the frame payload.
01742      */
01743     uint16_t f_buffer_size;
01744 
01745     /**
01746      * Pending data size
01747      */
01748     uint16_t pending_size;
01749 
01750 } loramac_tx_message_t;
01751 
01752 /** lora_mac_rx_message_type_t
01753  *
01754  * An enum representing a structure for RX messages.
01755  */
01756 typedef enum  {
01757     LORAMAC_RX_MLME_CONFIRM = 0,    /**< lora_mac_mlme_confirm_t */
01758     LORAMAC_RX_MCPS_CONFIRM,        /**< lora_mac_mcps_confirm_t */
01759     LORAMAC_RX_MCPS_INDICATION      /**< lora_mac_mcps_indication_t */
01760 } rx_msg_type;
01761 
01762 /** lora_mac_rx_message_by_type_t union
01763  *
01764  * A union representing a structure for RX messages.
01765  */
01766 typedef union {
01767     loramac_mlme_confirm_t  mlme_confirm;
01768     loramac_mcps_confirm_t  mcps_confirm;
01769     loramac_mcps_indication_t  mcps_indication;
01770 } rx_message_u;
01771 
01772 /** loramac_rx_message_t
01773  *
01774  * A structure representing a structure for an RX message.
01775  */
01776 typedef struct {
01777     bool receive_ready;
01778     rx_msg_type type;
01779     rx_message_u msg;
01780     uint16_t pending_size;
01781     uint16_t prev_read_size;
01782 } loramac_rx_message_t;
01783 
01784 /**
01785  * Structure to hold A list of LoRa Channels
01786  */
01787 typedef struct lora_channels_s {
01788     uint8_t id;
01789     channel_params_t  ch_param;
01790 } loramac_channel_t;
01791 
01792 
01793 /** lorawan_connect_t structure
01794  *
01795  * A structure representing the parameters for different connections.
01796  */
01797 typedef struct lorawan_connect {
01798     /*!
01799      * Select the connection type, either LORAWAN_CONNECTION_OTAA
01800      * or LORAWAN_CONNECTION_ABP.
01801      */
01802     uint8_t connect_type ;
01803 
01804     union {
01805         /*!
01806          * Join the network using OTA
01807          */
01808         lorawan_connect_otaa_t otaa ;
01809         /*!
01810          * Authentication by personalization
01811          */
01812         lorawan_connect_abp_t abp ;
01813     } connection_u;
01814 
01815 } lorawan_connect_t;
01816 
01817 /** LoRaWAN session
01818  *
01819  * A structure for keeping session details.
01820  */
01821 typedef struct lorawan_session {
01822     /**
01823      * True if the session is active
01824      */
01825     bool active;
01826 
01827     lorawan_connect_t connection;
01828     /**
01829      * LoRaWAN uplink counter
01830      *
01831      * Related MIB type: LORA_MIB_UPLINK_COUNTER
01832      */
01833     uint32_t uplink_counter;
01834     /**
01835      * LoRaWAN downlink counter
01836      *
01837      * Related MIB type: LORA_MIB_DOWNLINK_COUNTER
01838      */
01839     uint32_t downlink_counter;
01840 } lorawan_session_t;
01841 
01842 /** Commissioning data
01843  *
01844  * A structure for data in commission.
01845  */
01846 typedef struct {
01847     /** Connection information
01848      *
01849      * Saves information for etc. keys
01850      */
01851     lorawan_connect_t connection;
01852     /**
01853      * LoRaWAN Up-link counter
01854      *
01855      * Related MIB type: LORA_MIB_UPLINK_COUNTER
01856      */
01857     uint32_t uplink_counter;
01858     /**
01859      * LoRaWAN Down-link counter
01860      *
01861      * Related MIB type: LORA_MIB_DOWNLINK_COUNTER
01862      */
01863     uint32_t downlink_counter;
01864 } lorawan_dev_commission_t;
01865 
01866 /** Structure containing the uplink status
01867  *
01868  */
01869 typedef struct {
01870     /** Is acked
01871      *
01872      */
01873     uint8_t acked;
01874     /** Uplink data rate
01875      *
01876      */
01877     int8_t datarate;
01878     /** Uplink counter
01879      *
01880      */
01881     uint16_t uplink_counter;
01882     /** Port is used by application
01883      *
01884      */
01885     uint8_t port;
01886     /** Payload
01887      *
01888      */
01889     uint8_t *buffer;
01890     /** Payload size
01891      *
01892      */
01893     uint8_t buffer_size;
01894 } loramac_uplink_status_t;
01895 
01896 /** A structure containing the downlink status
01897  *
01898  */
01899 typedef struct {
01900     /** RSSI of downlink
01901      *
01902      */
01903     int16_t rssi;
01904     /** SNR of downlink
01905      *
01906      */
01907     int8_t snr;
01908     /** Downlink counter
01909      *
01910      */
01911     uint16_t downlink_counter;
01912     /** Is RX data received
01913      *
01914      */
01915     bool rx_data;
01916     /** Port used by application
01917      *
01918      */
01919     uint8_t port;
01920     /** Payload
01921      *
01922      */
01923     uint8_t *buffer;
01924     /** Payload size
01925      *
01926      */
01927     uint8_t buffer_size;
01928 } loramac_downlink_status_t;
01929 
01930 /*!
01931  * The parameter structure for the function for regional rx configuration.
01932  */
01933 typedef struct {
01934     /*!
01935      * The RX channel.
01936      */
01937     uint8_t channel ;
01938     /*!
01939      * The RX datarate.
01940      */
01941     uint8_t datarate ;
01942     /*!
01943      * The RX bandwidth.
01944      */
01945     uint8_t bandwidth ;
01946     /*!
01947      * The RX datarate offset.
01948      */
01949     int8_t dr_offset ;
01950     /*!
01951      * The RX frequency.
01952      */
01953     uint32_t frequency ;
01954     /*!
01955      * The RX window timeout
01956      */
01957      uint32_t window_timeout ;
01958     /*!
01959      * The RX window offset
01960      */
01961     int32_t window_offset ;
01962     /*!
01963      * The downlink dwell time.
01964      */
01965     uint8_t dl_dwell_time ;
01966     /*!
01967      * Set to true, if a repeater is supported.
01968      */
01969     bool is_repeater_supported ;
01970     /*!
01971      * Set to true, if RX should be continuous.
01972      */
01973     bool is_rx_continuous ;
01974     /*!
01975      * Sets the RX window.
01976      */
01977     rx_slot_t  rx_slot ;
01978 } rx_config_params_t ;
01979 
01980 /*!
01981  * \brief Timer object description
01982  */
01983 typedef struct {
01984     mbed::Callback<void()> callback;
01985     int timer_id;
01986 } timer_event_t;
01987 
01988 /*!
01989  * LoRaMac internal states
01990  */
01991 typedef enum {
01992     LORAMAC_IDLE          = 0x00000000,
01993     LORAMAC_TX_RUNNING    = 0x00000001,
01994     LORAMAC_RX            = 0x00000002,
01995     LORAMAC_ACK_REQ       = 0x00000004,
01996     LORAMAC_ACK_RETRY     = 0x00000008,
01997     LORAMAC_TX_DELAYED    = 0x00000010,
01998     LORAMAC_TX_CONFIG     = 0x00000020,
01999     LORAMAC_RX_ABORT      = 0x00000040,
02000 } loramac_internal_state ;
02001 
02002 typedef struct {
02003     /*!
02004      * Device IEEE EUI
02005      */
02006     uint8_t *dev_eui;
02007 
02008     /*!
02009      * Application IEEE EUI
02010      */
02011     uint8_t *app_eui;
02012 
02013     /*!
02014      * AES encryption/decryption cipher application key
02015      */
02016     uint8_t *app_key;
02017 
02018     /*!
02019      * AES encryption/decryption cipher network session key
02020      */
02021     uint8_t nwk_skey[16];
02022 
02023     /*!
02024      * AES encryption/decryption cipher application session key
02025      */
02026     uint8_t app_skey[16];
02027 
02028 } loramac_keys;
02029 
02030 typedef struct {
02031       /*!
02032        * Aggregated duty cycle management
02033        */
02034       lorawan_time_t aggregated_last_tx_time;
02035       lorawan_time_t aggregated_timeoff;
02036 
02037       /*!
02038        * Stores the time at LoRaMac initialization.
02039        *
02040        * \remark Used for the BACKOFF_DC computation.
02041        */
02042       lorawan_time_t mac_init_time;
02043 
02044 
02045       /*!
02046        * Last transmission time on air
02047        */
02048       lorawan_time_t tx_toa;
02049 
02050       /*!
02051        * LoRaMac timer used to check the LoRaMacState (runs every second)
02052        */
02053       timer_event_t mac_state_check_timer;
02054 
02055       /*!
02056        * LoRaMac duty cycle delayed Tx timer
02057        */
02058       timer_event_t tx_delayed_timer;
02059 
02060       /*!
02061        * LoRaMac reception windows timers
02062        */
02063       timer_event_t rx_window1_timer;
02064       timer_event_t rx_window2_timer;
02065 
02066       /*!
02067        * Acknowledge timeout timer. Used for packet retransmissions.
02068        */
02069       timer_event_t ack_timeout_timer;
02070 
02071 } lorawan_timers;
02072 
02073 typedef struct {
02074 
02075     /*!
02076      * Actual device class
02077      */
02078     device_class_t  dev_class;
02079 
02080     /*!
02081      * Holds the type of current Receive window slot
02082      */
02083      rx_slot_t  rx_slot;
02084 
02085     /*!
02086      * Indicates if the node is connected to a private or public network
02087      */
02088     bool is_nwk_public;
02089 
02090     /*!
02091      * Indicates if the node supports repeaters
02092      */
02093     bool is_repeater_supported;
02094 
02095     /*!
02096      * IsPacketCounterFixed enables the MIC field tests by fixing the
02097      * ul_frame_counter value
02098      */
02099     bool is_ul_frame_counter_fixed;
02100 
02101     /*!
02102      * Used for test purposes. Disables the opening of the reception windows.
02103      */
02104     bool is_rx_window_enabled;
02105 
02106     /*!
02107      * Indicates if the MAC layer has already joined a network.
02108      */
02109     bool is_nwk_joined;
02110 
02111     /*!
02112      * If the node has sent a FRAME_TYPE_DATA_CONFIRMED_UP this variable indicates
02113      * if the nodes needs to manage the server acknowledgement.
02114      */
02115     bool is_node_ack_requested;
02116 
02117     /*!
02118      * If the server has sent a FRAME_TYPE_DATA_CONFIRMED_DOWN this variable indicates
02119      * if the ACK bit must be set for the next transmission
02120      */
02121     bool is_srv_ack_requested;
02122 
02123     /*!
02124      * Enables/Disables duty cycle management (Test only)
02125      */
02126     bool is_dutycycle_on;
02127 
02128     /*!
02129      * Set to true, if the last uplink was a join request
02130      */
02131     bool is_last_tx_join_request;
02132 
02133     /*!
02134      * Indicates if the AckTimeout timer has expired or not
02135      */
02136     bool is_ack_retry_timeout_expired;
02137 
02138     /*!
02139      * Current channel index
02140      */
02141     uint8_t channel;
02142 
02143     /*!
02144      * Current channel index
02145      */
02146     uint8_t last_channel_idx;
02147 
02148     /*!
02149      * Uplink messages repetitions counter
02150      */
02151     uint8_t ul_nb_rep_counter;
02152 
02153     /*!
02154      * Buffer containing the data to be sent or received.
02155      */
02156     uint8_t buffer[LORAMAC_PHY_MAXPAYLOAD];
02157 
02158     /*!
02159      * Length of packet in LoRaMacBuffer
02160      */
02161     uint16_t buffer_pkt_len;
02162 
02163     /*!
02164      * Buffer containing the upper layer data.
02165      */
02166     uint8_t payload[LORAMAC_PHY_MAXPAYLOAD];
02167 
02168     /*!
02169      * Length of the payload in LoRaMacBuffer
02170      */
02171     uint8_t payload_length;
02172 
02173     /*!
02174      * Number of trials to get a frame acknowledged
02175      */
02176     uint8_t max_ack_timeout_retries;
02177 
02178     /*!
02179      * Number of trials to get a frame acknowledged
02180      */
02181     uint8_t ack_timeout_retry_counter;
02182 
02183     /*!
02184      * Maximum number of trials for the Join Request
02185      */
02186     uint8_t max_join_request_trials;
02187 
02188     /*!
02189      * Number of trials for the Join Request
02190      */
02191     uint8_t join_request_trial_counter;
02192 
02193     /*!
02194      * Mac keys
02195      */
02196     loramac_keys keys;
02197 
02198     /*!
02199      * LoRaMac tx/rx operation state
02200      */
02201     loramac_flags_t  flags;
02202 
02203     /*!
02204      * Device nonce is a random value extracted by issuing a sequence of RSSI
02205      * measurements
02206      */
02207     uint16_t dev_nonce;
02208 
02209     /*!
02210      * Network ID ( 3 bytes )
02211      */
02212     uint32_t net_id;
02213 
02214     /*!
02215      * Mote Address
02216      */
02217     uint32_t dev_addr;
02218 
02219     /*!
02220      * LoRaMAC frame counter. Each time a packet is sent the counter is incremented.
02221      * Only the 16 LSB bits are sent
02222      */
02223     uint32_t ul_frame_counter;
02224 
02225     /*!
02226      * LoRaMAC frame counter. Each time a packet is received the counter is incremented.
02227      * Only the 16 LSB bits are received
02228      */
02229     uint32_t dl_frame_counter;
02230 
02231     /*!
02232      * Counts the number of missed ADR acknowledgements
02233      */
02234     uint32_t adr_ack_counter;
02235 
02236     /*!
02237      * LoRaMac internal state
02238      */
02239     uint32_t mac_state;
02240 
02241     /*!
02242      * LoRaMac reception windows delay
02243      * \remark normal frame: RxWindowXDelay = ReceiveDelayX - RADIO_WAKEUP_TIME
02244      *         join frame  : RxWindowXDelay = JoinAcceptDelayX - RADIO_WAKEUP_TIME
02245      */
02246     uint32_t rx_window1_delay;
02247     uint32_t rx_window2_delay;
02248 
02249     /*!
02250      * Timer objects and stored values
02251      */
02252     lorawan_timers timers;
02253 
02254     /*!
02255      * LoRaMac parameters
02256      */
02257     lora_mac_system_params_t  sys_params;
02258 
02259     /*!
02260      * Receive Window configurations for PHY layer
02261      */
02262     rx_config_params_t  rx_window1_config;
02263     rx_config_params_t  rx_window2_config;
02264 
02265     /*!
02266      * Multicast channels linked list
02267      */
02268     multicast_params_t  *multicast_channels;
02269 
02270 } loramac_protocol_params;
02271 
02272 /** LoRaWAN callback functions
02273  *
02274  */
02275 typedef enum lora_events {
02276     CONNECTED=0,
02277     DISCONNECTED,
02278     TX_DONE,
02279     TX_TIMEOUT,
02280     TX_ERROR,
02281     TX_CRYPTO_ERROR,
02282     TX_SCHEDULING_ERROR,
02283     RX_DONE,
02284     RX_TIMEOUT,
02285     RX_ERROR,
02286     JOIN_FAILURE,
02287 } lorawan_event_t;
02288 
02289 typedef struct  {
02290      // Mandatory. Event Callback must be provided
02291      mbed::Callback<void(lorawan_event_t)> events;
02292 
02293      // Rest are optional
02294      // If the user do not assign these callbacks, these callbacks would return
02295      // null if checked with bool operator
02296      // link_check_resp callback and other such callbacks will be maped in
02297      // future releases of Mbed-OS
02298      mbed::Callback<void(uint8_t, uint8_t)> link_check_resp;
02299 
02300      // Battery level callback goes in the down direction, i.e., it informs
02301      // the stack about the battery level by calling a function provided
02302      // by the upper layers
02303      mbed::Callback<uint8_t(void)> battery_level;
02304  } lorawan_app_callbacks_t;
02305 
02306 typedef struct lora_channelplan {
02307     uint8_t nb_channels;    // number of channels
02308     loramac_channel_t *channels;
02309 } lorawan_channelplan_t;
02310 
02311 #if defined(LORAWAN_COMPLIANCE_TEST)
02312 /**  LoRaWAN compliance tests support data
02313  *
02314  */
02315 typedef struct compliance_test {
02316     /** Is test running
02317      *
02318      */
02319     bool running;
02320     /** State of test
02321      *
02322      */
02323     uint8_t state;
02324     /** Is TX confirmed
02325      *
02326      */
02327     bool is_tx_confirmed;
02328     /** Port used by the application
02329      *
02330      */
02331     uint8_t app_port;
02332     /** Maximum size of data used by application
02333      *
02334      */
02335     uint8_t app_data_size;
02336     /** Data provided by application
02337      *
02338      */
02339     uint8_t *app_data_buffer;
02340     /** Downlink counter
02341      *
02342      */
02343     uint16_t downlink_counter;
02344     /** Is link check required
02345      *
02346      */
02347     bool link_check;
02348     /** Demodulation margin
02349      *
02350      */
02351     uint8_t demod_margin;
02352     /** Number of gateways
02353      *
02354      */
02355     uint8_t nb_gateways;
02356 } compliance_test_t;
02357 #endif
02358 
02359 #endif /* LORAWAN_SYSTEM_LORAWAN_DATA_STRUCTURES_H_ */