Denislam Valeev / Mbed OS Nucleo_rtos_basic
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 for an unconfirmed frame.
00767  */
00768 typedef struct {
00769     /*!
00770      * Frame port field. Must be set if the payload is not empty. Use the
00771      * application-specific frame port values: [1...223].
00772      *
00773      * LoRaWAN Specification V1.0.2, chapter 4.3.2.
00774      */
00775     uint8_t fport ;
00776 
00777     /*!
00778      * Uplink datarate, if ADR is off.
00779      */
00780     int8_t data_rate ;
00781 } mcps_req_unconfirmed_t ;
00782 
00783 /*!
00784  * LoRaMAC MCPS-Request for a confirmed frame.
00785  */
00786 typedef struct {
00787     /*!
00788      * Frame port field. Must be set if the payload is not empty. Use the
00789      * application-specific frame port values: [1...223].
00790      *
00791      * LoRaWAN Specification V1.0.2, chapter 4.3.2.
00792      */
00793     uint8_t fport ;
00794 
00795     /*!
00796      * Uplink datarate, if ADR is off.
00797      */
00798     int8_t data_rate ;
00799     /*!
00800      * The number of trials to transmit the frame, if the LoRaMAC layer did not
00801      * receive an acknowledgment. The MAC performs a datarate adaptation
00802      * according to the LoRaWAN Specification V1.0.2, chapter 18.4, as in
00803      * the following table:
00804      *
00805      * Transmission nb | Data Rate
00806      * ----------------|-----------
00807      * 1 (first)       | DR
00808      * 2               | DR
00809      * 3               | max(DR-1,0)
00810      * 4               | max(DR-1,0)
00811      * 5               | max(DR-2,0)
00812      * 6               | max(DR-2,0)
00813      * 7               | max(DR-3,0)
00814      * 8               | max(DR-3,0)
00815      *
00816      * Note that if nb_trials is set to 1 or 2, the MAC will not decrease
00817      * the datarate, if the LoRaMAC layer did not receive an acknowledgment.
00818      */
00819     uint8_t nb_trials ;
00820 } mcps_req_confirmed_t ;
00821 
00822 /*!
00823  * LoRaMAC MCPS-Request for a proprietary frame.
00824  */
00825 typedef struct {
00826     /*!
00827      * Uplink datarate, if ADR is off.
00828      */
00829     int8_t data_rate ;
00830 } mcps_req_proprietary_t ;
00831 
00832 /*!
00833  * LoRaMAC MCPS-Request structure.
00834  */
00835 typedef struct {
00836     /*!
00837      * MCPS-Request type.
00838      */
00839     mcps_type_t type ;
00840 
00841     /*!
00842      * MCPS-Request parameters.
00843      */
00844     union
00845     {
00846         /*!
00847          * MCPS-Request parameters for an unconfirmed frame.
00848          */
00849         mcps_req_unconfirmed_t  unconfirmed ;
00850         /*!
00851          * MCPS-Request parameters for a confirmed frame.
00852          */
00853         mcps_req_confirmed_t  confirmed ;
00854         /*!
00855          * MCPS-Request parameters for a proprietary frame.
00856          */
00857         mcps_req_proprietary_t  proprietary ;
00858     } req;
00859 
00860     /** Payload data
00861       *
00862       * A pointer to the buffer of the frame payload.
00863       */
00864      void *f_buffer;
00865      /** Payload size
00866       *
00867       * The size of the frame payload.
00868       */
00869      uint16_t f_buffer_size;
00870 
00871 } loramac_mcps_req_t ;
00872 
00873 /*!
00874  * LoRaMAC MCPS-Confirm.
00875  */
00876 typedef struct {
00877     /*!
00878      * Holds the previously performed MCPS-Request type. i.e., the type of
00879      * the MCPS request for which this confirmation is being generated
00880      */
00881     mcps_type_t req_type ;
00882     /*!
00883      * The status of the operation.
00884      */
00885     loramac_event_info_status_t  status ;
00886     /*!
00887      * The uplink datarate.
00888      */
00889     uint8_t data_rate ;
00890     /*!
00891      * The transmission power.
00892      */
00893     int8_t tx_power ;
00894     /*!
00895      * Set if an acknowledgement was received.
00896      */
00897     bool ack_received ;
00898     /*!
00899      * Provides the number of retransmissions.
00900      */
00901     uint8_t nb_retries ;
00902     /*!
00903      * The transmission time on air of the frame.
00904      */
00905     lorawan_time_t tx_toa ;
00906     /*!
00907      * The uplink counter value related to the frame.
00908      */
00909     uint32_t ul_frame_counter ;
00910     /*!
00911      * The uplink frequency related to the frame.
00912      */
00913     uint32_t ul_frequency ;
00914 } loramac_mcps_confirm_t ;
00915 
00916 /*!
00917  * LoRaMAC MCPS-Indication primitive.
00918  */
00919 typedef struct {
00920     /*!
00921      * MCPS-Indication type.
00922      */
00923     mcps_type_t type ;
00924     /*!
00925      * The status of the operation.
00926      */
00927     loramac_event_info_status_t  status ;
00928     /*!
00929      * Multicast.
00930      */
00931     uint8_t multicast ;
00932     /*!
00933      * The application port.
00934      */
00935     uint8_t port ;
00936     /*!
00937      * The downlink datarate.
00938      */
00939     uint8_t rx_datarate ;
00940     /*!
00941      * Frame pending status.
00942      */
00943     uint8_t fpending_status ;
00944     /*!
00945      * A pointer to the received data stream.
00946      */
00947     uint8_t *buffer ;
00948     /*!
00949      * The size of the received data stream.
00950      */
00951     uint16_t buffer_size ;
00952     /*!
00953      * Indicates, if data is available.
00954      */
00955     bool is_data_recvd ;
00956     /*!
00957      * The RSSI of the received packet.
00958      */
00959     int16_t rssi ;
00960     /*!
00961      * The SNR of the received packet.
00962      */
00963     uint8_t snr ;
00964     /*!
00965      * The receive window.
00966      *
00967      * [0: Rx window 1, 1: Rx window 2]
00968      */
00969     rx_slot_t  rx_slot ;
00970     /*!
00971      * Set if an acknowledgement was received.
00972      */
00973     bool is_ack_recvd ;
00974     /*!
00975      * The downlink counter value for the received frame.
00976      */
00977     uint32_t dl_frame_counter ;
00978 } loramac_mcps_indication_t ;
00979 
00980 /*!
00981  * \brief LoRaMAC management services.
00982  *
00983  * \details The following table list the primitives supported by a
00984  *          specific MAC management service:
00985  *
00986  * Name                         | Request | Indication | Response | Confirm
00987  * ---------------------------- | :-----: | :--------: | :------: | :-----:
00988  * \ref MLME_JOIN               | YES     | NO         | NO       | YES
00989  * \ref MLME_LINK_CHECK         | YES     | NO         | NO       | YES
00990  * \ref MLME_TXCW               | YES     | NO         | NO       | YES
00991  * \ref MLME_SCHEDULE_UPLINK    | NO      | YES        | NO       | NO
00992  *
00993  * The following table provides links to the function implementations of the
00994  * related MLME primitives.
00995  *
00996  * Primitive        | Function
00997  * ---------------- | :---------------------:
00998  * MLME-Request     | LoRaMacMlmeRequest
00999  * MLME-Confirm     | MacMlmeConfirm in \ref loramac_primitives_t
01000  * MLME-Indication  | MacMlmeIndication in \ref loramac_primitives_t
01001  */
01002 typedef enum {
01003     /*!
01004      * Initiates the Over-the-Air activation.
01005      *
01006      * LoRaWAN Specification V1.0.2, chapter 6.2.
01007      */
01008     MLME_JOIN ,
01009     /*!
01010      * LinkCheckReq - Connectivity validation.
01011      *
01012      * LoRaWAN Specification V1.0.2, chapter 5, table 4.
01013      */
01014     MLME_LINK_CHECK ,
01015     /*!
01016      * Sets TX continuous wave mode.
01017      *
01018      * LoRaWAN end-device certification.
01019      */
01020     MLME_TXCW ,
01021     /*!
01022      * Sets TX continuous wave mode (new LoRa-Alliance CC definition).
01023      *
01024      * LoRaWAN end-device certification.
01025      */
01026     MLME_TXCW_1 ,
01027     /*!
01028      * Indicates that the application shall perform an uplink as
01029      * soon as possible.
01030      */
01031     MLME_SCHEDULE_UPLINK 
01032 } mlme_type_t;
01033 
01034 /*!
01035  * LoRaMAC MLME-Request for the join service.
01036  */
01037 typedef struct {
01038     /*!
01039      * A globally unique end-device identifier.
01040      *
01041      * LoRaWAN Specification V1.0.2, chapter 6.2.1.
01042      */
01043     uint8_t *dev_eui ;
01044     /*!
01045      * An application identifier.
01046      *
01047      * LoRaWAN Specification V1.0.2, chapter 6.1.2
01048      */
01049     uint8_t *app_eui ;
01050     /*!
01051      * AES-128 application key.
01052      *
01053      * LoRaWAN Specification V1.0.2, chapter 6.2.2.
01054      */
01055     uint8_t *app_key ;
01056     /*!
01057      * The number of trials for the join request.
01058      */
01059     uint8_t nb_trials ;
01060 } mlme_join_req_t ;
01061 
01062 /*!
01063  * LoRaMAC MLME-Request for TX continuous wave mode.
01064  */
01065 typedef struct {
01066     /*!
01067      * The time while the radio is kept in continuous wave mode, in seconds.
01068      */
01069     uint16_t timeout ;
01070     /*!
01071      * The RF frequency to set (only used with the new way).
01072      */
01073     uint32_t frequency ;
01074     /*!
01075      * The RF output power to set (only used with the new way).
01076      */
01077     uint8_t power ;
01078 } mlme_cw_tx_mode_t ;
01079 
01080 /*!
01081  * LoRaMAC MLME-Request structure.
01082  */
01083 typedef struct {
01084     /*!
01085      * MLME-Request type.
01086      */
01087     mlme_type_t type ;
01088 
01089     /*!
01090      * MLME-Request parameters.
01091      */
01092     union {
01093         /*!
01094          * MLME-Request parameters for a join request.
01095          */
01096         mlme_join_req_t  join ;
01097         /*!
01098          * MLME-Request parameters for TX continuous mode request.
01099          */
01100         mlme_cw_tx_mode_t  cw_tx_mode ;
01101     } req;
01102 } loramac_mlme_req_t ;
01103 
01104 /*!
01105  * LoRaMAC MLME-Confirm primitive.
01106  */
01107 typedef struct {
01108     /*!
01109      * The previously performed MLME-Request. i.e., the request type
01110      * for which the confirmation is being generated
01111      */
01112     mlme_type_t req_type ;
01113     /*!
01114      * The status of the operation.
01115      */
01116     loramac_event_info_status_t  status ;
01117     /*!
01118      * The transmission time on air of the frame.
01119      */
01120     lorawan_time_t tx_toa ;
01121     /*!
01122      * The demodulation margin. Contains the link margin [dB] of the last LinkCheckReq
01123      * successfully received.
01124      */
01125     uint8_t demod_margin ;
01126     /*!
01127      * The number of gateways which received the last LinkCheckReq.
01128      */
01129     uint8_t nb_gateways ;
01130     /*!
01131      * The number of retransmissions.
01132      */
01133     uint8_t nb_retries ;
01134 } loramac_mlme_confirm_t ;
01135 
01136 /*!
01137  * LoRaMAC MLME-Indication primitive
01138  */
01139 typedef struct {
01140     /*!
01141      * MLME-Indication type
01142      */
01143     mlme_type_t indication_type ;
01144 } loramac_mlme_indication_t ;
01145 
01146 /*!
01147  * LoRa MAC Information Base (MIB).
01148  *
01149  * The following table lists the MIB parameters and the related attributes:
01150  *
01151  * Attribute                         | Get | Set
01152  * --------------------------------- | :-: | :-:
01153  * \ref MIB_DEVICE_CLASS             | YES | YES
01154  * \ref MIB_NETWORK_JOINED           | YES | YES
01155  * \ref MIB_ADR                      | YES | YES
01156  * \ref MIB_NET_ID                   | YES | YES
01157  * \ref MIB_DEV_ADDR                 | YES | YES
01158  * \ref MIB_NWK_SKEY                 | YES | YES
01159  * \ref MIB_APP_SKEY                 | YES | YES
01160  * \ref MIB_PUBLIC_NETWORK           | YES | YES
01161  * \ref MIB_REPEATER_SUPPORT         | YES | YES
01162  * \ref MIB_CHANNELS                 | YES | NO
01163  * \ref MIB_RX2_CHANNEL              | YES | YES
01164  * \ref MIB_CHANNELS_MASK            | YES | YES
01165  * \ref MIB_CHANNELS_DEFAULT_MASK    | YES | YES
01166  * \ref MIB_CHANNELS_NB_REP          | YES | YES
01167  * \ref MIB_MAX_RX_WINDOW_DURATION   | YES | YES
01168  * \ref MIB_RECEIVE_DELAY_1          | YES | YES
01169  * \ref MIB_RECEIVE_DELAY_2          | YES | YES
01170  * \ref MIB_JOIN_ACCEPT_DELAY_1      | YES | YES
01171  * \ref MIB_JOIN_ACCEPT_DELAY_2      | YES | YES
01172  * \ref MIB_CHANNELS_DATARATE        | YES | YES
01173  * \ref MIB_CHANNELS_DEFAULT_DATARATE| YES | YES
01174  * \ref MIB_CHANNELS_TX_POWER        | YES | YES
01175  * \ref MIB_CHANNELS_DEFAULT_TX_POWER| YES | YES
01176  * \ref MIB_UPLINK_COUNTER           | YES | YES
01177  * \ref MIB_DOWNLINK_COUNTER         | YES | YES
01178  * \ref MIB_MULTICAST_CHANNEL        | YES | NO
01179  * \ref MIB_SYSTEM_MAX_RX_ERROR      | YES | YES
01180  * \ref MIB_MIN_RX_SYMBOLS           | YES | YES
01181  * \ref MIB_ANTENNA_GAIN             | YES | YES
01182  *
01183  * The following table provides links to the function implementations of the
01184  * related MIB primitives:
01185  *
01186  * Primitive        | Function
01187  * ---------------- | :---------------------:
01188  * MIB-Set          | LoRaMacMibSetRequestConfirm
01189  * MIB-Get          | LoRaMacMibGetRequestConfirm
01190  */
01191 typedef enum {
01192     /*!
01193      * LoRaWAN device class.
01194      *
01195      * LoRaWAN Specification V1.0.2.
01196      */
01197     MIB_DEVICE_CLASS ,
01198     /*!
01199      * LoRaWAN Network joined attribute.
01200      *
01201      * LoRaWAN Specification V1.0.2.
01202      */
01203     MIB_NETWORK_JOINED ,
01204     /*!
01205      * Adaptive data rate.
01206      *
01207      * LoRaWAN Specification V1.0.2, chapter 4.3.1.1.
01208      *
01209      * [true: ADR enabled, false: ADR disabled].
01210      */
01211     MIB_ADR ,
01212     /*!
01213      * Network identifier.
01214      *
01215      * LoRaWAN Specification V1.0.2, chapter 6.1.1.
01216      */
01217     MIB_NET_ID ,
01218     /*!
01219      * End-device address.
01220      *
01221      * LoRaWAN Specification V1.0.2, chapter 6.1.1.
01222      */
01223     MIB_DEV_ADDR ,
01224     /*!
01225      * Network session key.
01226      *
01227      * LoRaWAN Specification V1.0.2, chapter 6.1.3.
01228      */
01229     MIB_NWK_SKEY ,
01230     /*!
01231      * Application session key.
01232      *
01233      * LoRaWAN Specification V1.0.2, chapter 6.1.4.
01234      */
01235     MIB_APP_SKEY ,
01236     /*!
01237      * Set the network type to public or private.
01238      *
01239      * LoRaWAN Regional Parameters V1.0.2rB.
01240      *
01241      * [true: public network, false: private network]
01242      */
01243     MIB_PUBLIC_NETWORK ,
01244     /*!
01245      * Support the operation with repeaters.
01246      *
01247      * LoRaWAN Regional Parameters V1.0.2rB.
01248      *
01249      * [true: repeater support enabled, false: repeater support disabled]
01250      */
01251     MIB_REPEATER_SUPPORT ,
01252     /*!
01253      * Communication channels. A GET request will return a
01254      * pointer that references the first entry of the channel list. The
01255      * list is of size LORA_MAX_NB_CHANNELS.
01256      *
01257      * LoRaWAN Regional Parameters V1.0.2rB.
01258      */
01259     MIB_CHANNELS ,
01260     /*!
01261      * Set receive window 2 channel.
01262      *
01263      * LoRaWAN Specification V1.0.2, chapter 3.3.1.
01264      */
01265     MIB_RX2_CHANNEL ,
01266     /*!
01267      * Set receive window 2 channel.
01268      *
01269      * LoRaWAN Specification V1.0.2, chapter 3.3.2.
01270      */
01271     MIB_RX2_DEFAULT_CHANNEL ,
01272     /*!
01273      * LoRaWAN channels mask.
01274      *
01275      * LoRaWAN Regional Parameters V1.0.2rB.
01276      */
01277     MIB_CHANNELS_MASK ,
01278     /*!
01279      * LoRaWAN default channels mask.
01280      *
01281      * LoRaWAN Regional Parameters V1.0.2rB.
01282      */
01283     MIB_CHANNELS_DEFAULT_MASK ,
01284     /*!
01285      * Set the number of repetitions on a channel.
01286      *
01287      * LoRaWAN Specification V1.0.2, chapter 5.2.
01288      */
01289     MIB_CHANNELS_NB_REP ,
01290     /*!
01291      * The maximum receive window duration in [ms].
01292      *
01293      * LoRaWAN Specification V1.0.2, chapter 3.3.3.
01294      */
01295     MIB_MAX_RX_WINDOW_DURATION ,
01296     /*!
01297      * The receive delay 1 in [ms].
01298      *
01299      * LoRaWAN Regional Parameters V1.0.2rB.
01300      */
01301     MIB_RECEIVE_DELAY_1 ,
01302     /*!
01303      * The receive delay 2 in [ms].
01304      *
01305      * LoRaWAN Regional Parameters V1.0.2rB.
01306      */
01307     MIB_RECEIVE_DELAY_2 ,
01308     /*!
01309      * The join accept delay 1 in [ms].
01310      *
01311      * LoRaWAN Regional Parameters V1.0.2rB.
01312      */
01313     MIB_JOIN_ACCEPT_DELAY_1 ,
01314     /*!
01315      * The join accept delay 2 in [ms].
01316      *
01317      * LoRaWAN Regional Parameters V1.0.2rB.
01318      */
01319     MIB_JOIN_ACCEPT_DELAY_2 ,
01320     /*!
01321      * The default data rate of a channel.
01322      *
01323      * LoRaWAN Regional Parameters V1.0.2rB.
01324      *
01325      * The allowed ranges are region-specific. Please refer to \ref DR_0 to \ref DR_15 for details.
01326      */
01327     MIB_CHANNELS_DEFAULT_DATARATE ,
01328     /*!
01329      * The data rate of a channel.
01330      *
01331      * LoRaWAN Regional Parameters V1.0.2rB.
01332      *
01333      * The allowed ranges are region-specific. Please refer to \ref DR_0 to \ref DR_15 for details.
01334      */
01335     MIB_CHANNELS_DATARATE ,
01336     /*!
01337      * The transmission power of a channel.
01338      *
01339      * LoRaWAN Regional Parameters V1.0.2rB.
01340      *
01341      * The allowed ranges are region-specific. Please refer to \ref TX_POWER_0 to \ref TX_POWER_15 for details.
01342      */
01343     MIB_CHANNELS_TX_POWER ,
01344     /*!
01345      * The transmission power of a channel.
01346      *
01347      * LoRaWAN Regional Parameters V1.0.2rB.
01348      *
01349      * The allowed ranges are region-specific. Please refer to \ref TX_POWER_0 to \ref TX_POWER_15 for details.
01350      */
01351     MIB_CHANNELS_DEFAULT_TX_POWER ,
01352     /*!
01353      * LoRaWAN uplink counter.
01354      *
01355      * LoRaWAN Specification V1.0.2, chapter 4.3.1.5.
01356      */
01357     MIB_UPLINK_COUNTER ,
01358     /*!
01359      * LoRaWAN downlink counter.
01360      *
01361      * LoRaWAN Specification V1.0.2, chapter 4.3.1.5.
01362      */
01363     MIB_DOWNLINK_COUNTER ,
01364     /*!
01365      * Multicast channels. A GET request will return a pointer to the first
01366      * entry of the multicast channel linked list. If the pointer is equal to
01367      * NULL, the list is empty.
01368      */
01369     MIB_MULTICAST_CHANNEL ,
01370     /*!
01371      * System overall timing error in milliseconds.
01372      * [-SystemMaxRxError : +SystemMaxRxError]
01373      * Default: +/-10 ms
01374      */
01375     MIB_SYSTEM_MAX_RX_ERROR ,
01376     /*!
01377      * The minimum  number of symbols required to detect an RX frame.
01378      * Default: 6 symbols
01379      */
01380     MIB_MIN_RX_SYMBOLS ,
01381     /*!
01382      * The antenna gain of the node. The default value is region-specific.
01383      * The antenna gain is used to calculate the TX power of the node.
01384      * The formula is:
01385      * radioTxPower = ( int8_t )floor( maxEirp - antennaGain )
01386      */
01387     MIB_ANTENNA_GAIN 
01388 } mib_type_t ;
01389 
01390 /*!
01391  * LoRaMAC MIB parameters.
01392  */
01393 typedef union {
01394     /*!
01395      * LoRaWAN device class.
01396      *
01397      * Related MIB type: \ref MIB_DEVICE_CLASS
01398      */
01399     device_class_t  dev_class ;
01400     /*!
01401      * LoRaWAN network joined attribute
01402      *
01403      * Related MIB type: \ref MIB_NETWORK_JOINED
01404      */
01405     bool is_nwk_joined ;
01406     /*!
01407      * Activation state of ADR
01408      *
01409      * Related MIB type: \ref MIB_ADR
01410      */
01411     bool is_adr_enable ;
01412     /*!
01413      * Network identifier
01414      *
01415      * Related MIB type: \ref MIB_NET_ID
01416      */
01417     uint32_t net_id ;
01418     /*!
01419      * End-device address
01420      *
01421      * Related MIB type: \ref MIB_DEV_ADDR
01422      */
01423     uint32_t dev_addr ;
01424     /*!
01425      * Network session key
01426      *
01427      * Related MIB type: \ref MIB_NWK_SKEY
01428      */
01429     uint8_t *nwk_skey ;
01430     /*!
01431      * Application session key
01432      *
01433      * Related MIB type: \ref MIB_APP_SKEY
01434      */
01435     uint8_t *app_skey ;
01436     /*!
01437      * Enable or disable a public network
01438      *
01439      * Related MIB type: \ref MIB_PUBLIC_NETWORK
01440      */
01441     bool enable_public_nwk ;
01442     /*!
01443      * Enable or disable repeater support
01444      *
01445      * Related MIB type: \ref MIB_REPEATER_SUPPORT
01446      */
01447     bool enable_repeater_support ;
01448     /*!
01449      * LoRaWAN channel
01450      *
01451      * Related MIB type: \ref MIB_CHANNELS
01452      */
01453     channel_params_t * channel_list ;
01454      /*!
01455      * Channel for the receive window 2
01456      *
01457      * Related MIB type: \ref MIB_RX2_CHANNEL
01458      */
01459     rx2_channel_params  rx2_channel ;
01460      /*!
01461      * Channel for the receive window 2
01462      *
01463      * Related MIB type: \ref MIB_RX2_DEFAULT_CHANNEL
01464      */
01465     rx2_channel_params  default_rx2_channel ;
01466     /*!
01467      * Channel mask
01468      *
01469      * Related MIB type: \ref MIB_CHANNELS_MASK
01470      */
01471     uint16_t* channel_mask ;
01472     /*!
01473      * Default channel mask
01474      *
01475      * Related MIB type: \ref MIB_CHANNELS_DEFAULT_MASK
01476      */
01477     uint16_t* default_channel_mask ;
01478     /*!
01479      * Number of frame repetitions
01480      *
01481      * Related MIB type: \ref MIB_CHANNELS_NB_REP
01482      */
01483     uint8_t channel_nb_rep ;
01484     /*!
01485      * Maximum receive window duration
01486      *
01487      * Related MIB type: \ref MIB_MAX_RX_WINDOW_DURATION
01488      */
01489     uint32_t max_rx_window ;
01490     /*!
01491      * Receive delay 1
01492      *
01493      * Related MIB type: \ref MIB_RECEIVE_DELAY_1
01494      */
01495     uint32_t recv_delay1 ;
01496     /*!
01497      * Receive delay 2
01498      *
01499      * Related MIB type: \ref MIB_RECEIVE_DELAY_2
01500      */
01501     uint32_t recv_delay2 ;
01502     /*!
01503      * Join accept delay 1
01504      *
01505      * Related MIB type: \ref MIB_JOIN_ACCEPT_DELAY_1
01506      */
01507     uint32_t join_accept_delay1 ;
01508     /*!
01509      * Join accept delay 2
01510      *
01511      * Related MIB type: \ref MIB_JOIN_ACCEPT_DELAY_2
01512      */
01513     uint32_t join_accept_delay2 ;
01514     /*!
01515      * Channels data rate
01516      *
01517      * Related MIB type: \ref MIB_CHANNELS_DEFAULT_DATARATE
01518      */
01519     int8_t default_channel_data_rate ;
01520     /*!
01521      * Channels data rate
01522      *
01523      * Related MIB type: \ref MIB_CHANNELS_DATARATE
01524      */
01525     int8_t channel_data_rate ;
01526     /*!
01527      * Channels TX power
01528      *
01529      * Related MIB type: \ref MIB_CHANNELS_DEFAULT_TX_POWER
01530      */
01531     int8_t default_channel_tx_pwr ;
01532     /*!
01533      * Channels TX power
01534      *
01535      * Related MIB type: \ref MIB_CHANNELS_TX_POWER
01536      */
01537     int8_t channel_tx_pwr ;
01538     /*!
01539      * LoRaWAN uplink counter
01540      *
01541      * Related MIB type: \ref MIB_UPLINK_COUNTER
01542      */
01543     uint32_t ul_frame_counter ;
01544     /*!
01545      * LoRaWAN downlink counter
01546      *
01547      * Related MIB type: \ref MIB_DOWNLINK_COUNTER
01548      */
01549     uint32_t dl_frame_counter ;
01550     /*!
01551      * Multicast channel
01552      *
01553      * Related MIB type: \ref MIB_MULTICAST_CHANNEL
01554      */
01555     multicast_params_t * multicast_list ;
01556     /*!
01557      * System overall timing error in milliseconds
01558      *
01559      * Related MIB type: \ref MIB_SYSTEM_MAX_RX_ERROR
01560      */
01561     uint32_t max_rx_sys_error ;
01562     /*!
01563      * Minimum required number of symbols to detect an RX frame
01564      *
01565      * Related MIB type: \ref MIB_MIN_RX_SYMBOLS
01566      */
01567     uint8_t min_rx_symb ;
01568     /*!
01569      * Antenna gain
01570      *
01571      * Related MIB type: \ref MIB_ANTENNA_GAIN
01572      */
01573     float antenna_gain ;
01574 } mib_params_t ;
01575 
01576 /*!
01577  * LoRaMAC MIB-RequestConfirm structure
01578  */
01579 typedef struct {
01580     /*!
01581      * MIB-Request type
01582      */
01583     mib_type_t  type ;
01584 
01585     /*!
01586      * MLME-RequestConfirm parameters
01587      */
01588     mib_params_t  param ;
01589 }loramac_mib_req_confirm_t ;
01590 
01591 /*!
01592  * LoRaMAC TX information
01593  */
01594 typedef struct {
01595     /*!
01596      * Defines the size of the applicable payload that can be processed.
01597      */
01598     uint8_t max_possible_payload_size ;
01599     /*!
01600      * The current payload size, dependent on the current datarate.
01601      */
01602     uint8_t current_payload_size ;
01603 } loramac_tx_info_t ;
01604 
01605 /** LoRaMAC status.
01606  *
01607  */
01608 typedef enum lorawan_status {
01609     LORAWAN_STATUS_OK = 0,                         /**< Service started successfully */
01610     LORAWAN_STATUS_BUSY = -1000,                   /**< Service not started - LoRaMAC is busy */
01611     LORAWAN_STATUS_WOULD_BLOCK = -1001,            /**< LoRaMAC cannot send at the moment or have nothing to read */
01612     LORAWAN_STATUS_SERVICE_UNKNOWN = -1002,        /**< Service unknown */
01613     LORAWAN_STATUS_PARAMETER_INVALID = -1003,      /**< Service not started - invalid parameter */
01614     LORAWAN_STATUS_FREQUENCY_INVALID = -1004,      /**< Service not started - invalid frequency */
01615     LORAWAN_STATUS_DATARATE_INVALID = -1005,       /**< Service not started - invalid datarate */
01616     LORAWAN_STATUS_FREQ_AND_DR_INVALID = -1006,    /**< Service not started - invalid frequency and datarate */
01617     LORAWAN_STATUS_NO_NETWORK_JOINED = -1009,      /**< Service not started - the device is not in a LoRaWAN */
01618     LORAWAN_STATUS_LENGTH_ERROR = -1010,           /**< Service not started - payload lenght error */
01619     LORAWAN_STATUS_DEVICE_OFF = -1011,             /**< Service not started - the device is switched off */
01620     LORAWAN_STATUS_NOT_INITIALIZED = -1012,        /**< Service not started - stack not initialized */
01621     LORAWAN_STATUS_UNSUPPORTED = -1013,            /**< Service not supported */
01622     LORAWAN_STATUS_CRYPTO_FAIL = -1014,            /**< Service not started - crypto failure */
01623     LORAWAN_STATUS_PORT_INVALID = -1015,           /**< Invalid port */
01624     LORAWAN_STATUS_CONNECT_IN_PROGRESS = -1016,    /**< Services started - Connection in progress */
01625     LORAWAN_STATUS_NO_ACTIVE_SESSIONS = -1017,            /**< Services not started - No active session */
01626     LORAWAN_STATUS_IDLE = -1018,                   /**< Services started - Idle at the moment */
01627 #if defined(LORAWAN_COMPLIANCE_TEST)
01628     LORAWAN_STATUS_COMPLIANCE_TEST_ON = -1019,     /**< Compliance test - is on-going */
01629 #endif
01630 } lorawan_status_t;
01631 
01632 /*!
01633  * LoRaMAC events structure.
01634  * Used to notify upper layers of MAC events.
01635  */
01636 typedef struct {
01637     /*!
01638      * \brief   MCPS-Confirm primitive.
01639      *
01640      * \param   [OUT] MCPS-Confirm parameters.
01641      */
01642     mbed::Callback<void(loramac_mcps_confirm_t*)> mcps_confirm;
01643 
01644     /*!
01645      * \brief   MCPS-Indication primitive.
01646      *
01647      * \param   [OUT] MCPS-Indication parameters.
01648      */
01649     mbed::Callback<void(loramac_mcps_indication_t*)> mcps_indication;
01650 
01651     /*!
01652      * \brief   MLME-Confirm primitive.
01653      *
01654      * \param   [OUT] MLME-Confirm parameters.
01655      */
01656     mbed::Callback<void(loramac_mlme_confirm_t*)> mlme_confirm;
01657 
01658     /*!
01659      * \brief   MLME-Indication primitive
01660      *
01661      * \param   [OUT] MLME-Indication parameters
01662      */
01663     mbed::Callback<void(loramac_mlme_indication_t*)> mlme_indication;
01664 }loramac_primitives_t ;
01665 
01666 /** End-device states.
01667  *
01668  */
01669 typedef enum device_states {
01670     DEVICE_STATE_NOT_INITIALIZED,
01671     DEVICE_STATE_INIT,
01672     DEVICE_STATE_JOINING,
01673     DEVICE_STATE_ABP_CONNECTING,
01674     DEVICE_STATE_JOINED,
01675     DEVICE_STATE_SEND,
01676     DEVICE_STATE_IDLE,
01677 #if defined(LORAWAN_COMPLIANCE_TEST)
01678     DEVICE_STATE_COMPLIANCE_TEST,
01679 #endif
01680     DEVICE_STATE_SHUTDOWN
01681 } device_states_t;
01682 
01683 /** Enum of LoRaWAN connection type.
01684  *
01685  * The LoRaWAN connection type specifies how an end-device connects to the gateway.
01686  */
01687 typedef enum lorawan_connect_type {
01688     LORAWAN_CONNECTION_OTAA = 0,    /**< Over The Air Activation */
01689     LORAWAN_CONNECTION_ABP          /**< Activation By Personalization */
01690 } lorawan_connect_type_t;
01691 
01692 /** The lorawan_connect_otaa structure.
01693  *
01694  * A structure representing the LoRaWAN Over The Air Activation
01695  * parameters.
01696  */
01697 typedef struct {
01698     /** End-device identifier
01699      *
01700      * LoRaWAN Specification V1.0.2, chapter 6.2.1
01701      */
01702     uint8_t *dev_eui;
01703     /** Application identifier
01704      *
01705      * LoRaWAN Specification V1.0.2, chapter 6.1.2
01706      */
01707     uint8_t *app_eui;
01708     /** AES-128 application key
01709      *
01710      * LoRaWAN Specification V1.0.2, chapter 6.2.2
01711      */
01712     uint8_t *app_key;
01713     /** Join request trials
01714      *
01715      * Number of trials for the join request.
01716      */
01717     uint8_t nb_trials;
01718 } lorawan_connect_otaa_t;
01719 
01720 /** The lorawan_connect_abp structure.
01721  *
01722  * A structure representing the LoRaWAN Activation By Personalization
01723  * parameters.
01724  */
01725 typedef struct {
01726     /** Network identifier
01727      *
01728      * LoRaWAN Specification V1.0.2, chapter 6.1.1
01729      */
01730     uint32_t nwk_id;
01731     /** End-device address
01732      *
01733      * LoRaWAN Specification V1.0.2, chapter 6.1.1
01734      */
01735     uint32_t dev_addr;
01736     /** Network session key
01737      *
01738      * LoRaWAN Specification V1.0.2, chapter 6.1.3
01739      */
01740     uint8_t *nwk_skey;
01741     /** Application session key
01742      *
01743      * LoRaWAN Specification V1.0.2, chapter 6.1.4
01744      */
01745     uint8_t *app_skey;
01746 } lorawan_connect_abp_t;
01747 
01748 /**
01749  * Stack level TX message structure
01750  */
01751 typedef struct {
01752 
01753     /**
01754      * TX Ongoing flag
01755      */
01756     bool tx_ongoing;
01757 
01758     /**
01759      * Application Port Number
01760      */
01761     uint8_t port;
01762 
01763     /**
01764      * Message type
01765      */
01766     mcps_type_t type;
01767     /** Message parameters.
01768      *
01769      */
01770     union message {
01771         /** An unconfirmed frame.
01772          *
01773          * The message parameters for an unconfirmed frame.
01774          */
01775         mcps_req_unconfirmed_t  unconfirmed;
01776         /** A confirmed frame.
01777          *
01778          * The message parameters for a confirmed frame.
01779          */
01780         mcps_req_confirmed_t  confirmed;
01781         /** A proprietary frame.
01782          *
01783          * The message parameters for a proprietary frame.
01784          */
01785         mcps_req_proprietary_t  proprietary;
01786     } message_u;
01787 
01788     /** Payload data
01789      *
01790      * Base pointer to the buffer
01791      */
01792     uint8_t f_buffer[MBED_CONF_LORA_TX_MAX_SIZE];
01793 
01794     /** Payload size.
01795      *
01796      * The size of the frame payload.
01797      */
01798     uint16_t f_buffer_size;
01799 
01800     /**
01801      * Pending data size
01802      */
01803     uint16_t pending_size;
01804 
01805 } loramac_tx_message_t;
01806 
01807 /** lora_mac_rx_message_type_t
01808  *
01809  * An enum representing a structure for RX messages.
01810  */
01811 typedef enum  {
01812     LORAMAC_RX_MLME_CONFIRM = 0,    /**< lora_mac_mlme_confirm_t */
01813     LORAMAC_RX_MCPS_CONFIRM,        /**< lora_mac_mcps_confirm_t */
01814     LORAMAC_RX_MCPS_INDICATION      /**< lora_mac_mcps_indication_t */
01815 } rx_msg_type;
01816 
01817 /** lora_mac_rx_message_by_type_t union
01818  *
01819  * A union representing a structure for RX messages.
01820  */
01821 typedef union {
01822     loramac_mlme_confirm_t  mlme_confirm;
01823     loramac_mcps_confirm_t  mcps_confirm;
01824     loramac_mcps_indication_t  mcps_indication;
01825 } rx_message_u;
01826 
01827 /** loramac_rx_message_t
01828  *
01829  * A structure representing a structure for an RX message.
01830  */
01831 typedef struct {
01832     bool receive_ready;
01833     rx_msg_type type;
01834     rx_message_u msg;
01835     uint16_t pending_size;
01836     uint16_t prev_read_size;
01837 } loramac_rx_message_t;
01838 
01839 /**
01840  * Structure to hold A list of LoRa Channels
01841  */
01842 typedef struct lora_channels_s {
01843     uint8_t id;
01844     channel_params_t  ch_param;
01845 } loramac_channel_t;
01846 
01847 
01848 /** lorawan_connect_t structure
01849  *
01850  * A structure representing the parameters for different connections.
01851  */
01852 typedef struct lorawan_connect {
01853     /*!
01854      * Select the connection type, either LORAWAN_CONNECTION_OTAA
01855      * or LORAWAN_CONNECTION_ABP.
01856      */
01857     uint8_t connect_type ;
01858 
01859     union {
01860         /*!
01861          * Join the network using OTA
01862          */
01863         lorawan_connect_otaa_t otaa ;
01864         /*!
01865          * Authentication by personalization
01866          */
01867         lorawan_connect_abp_t abp ;
01868     } connection_u;
01869 
01870 } lorawan_connect_t;
01871 
01872 /** LoRaWAN session
01873  *
01874  * A structure for keeping session details.
01875  */
01876 typedef struct lorawan_session {
01877     /**
01878      * True if the session is active
01879      */
01880     bool active;
01881 
01882     lorawan_connect_t connection;
01883     /**
01884      * LoRaWAN uplink counter
01885      *
01886      * Related MIB type: LORA_MIB_UPLINK_COUNTER
01887      */
01888     uint32_t uplink_counter;
01889     /**
01890      * LoRaWAN downlink counter
01891      *
01892      * Related MIB type: LORA_MIB_DOWNLINK_COUNTER
01893      */
01894     uint32_t downlink_counter;
01895 } lorawan_session_t;
01896 
01897 /** Commissioning data
01898  *
01899  * A structure for data in commission.
01900  */
01901 typedef struct {
01902     /** Connection information
01903      *
01904      * Saves information for etc. keys
01905      */
01906     lorawan_connect_t connection;
01907     /**
01908      * LoRaWAN Up-link counter
01909      *
01910      * Related MIB type: LORA_MIB_UPLINK_COUNTER
01911      */
01912     uint32_t uplink_counter;
01913     /**
01914      * LoRaWAN Down-link counter
01915      *
01916      * Related MIB type: LORA_MIB_DOWNLINK_COUNTER
01917      */
01918     uint32_t downlink_counter;
01919 } lorawan_dev_commission_t;
01920 
01921 #if defined(LORAWAN_COMPLIANCE_TEST)
01922 /**  LoRaWAN compliance tests support data
01923  *
01924  */
01925 typedef struct compliance_test {
01926     /** Is test running
01927      *
01928      */
01929     bool running;
01930     /** State of test
01931      *
01932      */
01933     uint8_t state;
01934     /** Is TX confirmed
01935      *
01936      */
01937     bool is_tx_confirmed;
01938     /** Port used by the application
01939      *
01940      */
01941     uint8_t app_port;
01942     /** Maximum size of data used by application
01943      *
01944      */
01945     uint8_t app_data_size;
01946     /** Data provided by application
01947      *
01948      */
01949     uint8_t *app_data_buffer;
01950     /** Downlink counter
01951      *
01952      */
01953     uint16_t downlink_counter;
01954     /** Is link check required
01955      *
01956      */
01957     bool link_check;
01958     /** Demodulation margin
01959      *
01960      */
01961     uint8_t demod_margin;
01962     /** Number of gateways
01963      *
01964      */
01965     uint8_t nb_gateways;
01966 } compliance_test_t;
01967 #endif
01968 
01969 /** Structure containing the uplink status
01970  *
01971  */
01972 typedef struct {
01973     /** Is acked
01974      *
01975      */
01976     uint8_t acked;
01977     /** Uplink data rate
01978      *
01979      */
01980     int8_t datarate;
01981     /** Uplink counter
01982      *
01983      */
01984     uint16_t uplink_counter;
01985     /** Port is used by application
01986      *
01987      */
01988     uint8_t port;
01989     /** Payload
01990      *
01991      */
01992     uint8_t *buffer;
01993     /** Payload size
01994      *
01995      */
01996     uint8_t buffer_size;
01997 } loramac_uplink_status_t;
01998 
01999 /** A structure containing the downlink status
02000  *
02001  */
02002 typedef struct {
02003     /** RSSI of downlink
02004      *
02005      */
02006     int16_t rssi;
02007     /** SNR of downlink
02008      *
02009      */
02010     int8_t snr;
02011     /** Downlink counter
02012      *
02013      */
02014     uint16_t downlink_counter;
02015     /** Is RX data received
02016      *
02017      */
02018     bool rx_data;
02019     /** Port used by application
02020      *
02021      */
02022     uint8_t port;
02023     /** Payload
02024      *
02025      */
02026     uint8_t *buffer;
02027     /** Payload size
02028      *
02029      */
02030     uint8_t buffer_size;
02031 } loramac_downlink_status_t;
02032 
02033 /*!
02034  * The parameter structure for the function for regional rx configuration.
02035  */
02036 typedef struct {
02037     /*!
02038      * The RX channel.
02039      */
02040     uint8_t channel ;
02041     /*!
02042      * The RX datarate.
02043      */
02044     uint8_t datarate ;
02045     /*!
02046      * The RX bandwidth.
02047      */
02048     uint8_t bandwidth ;
02049     /*!
02050      * The RX datarate offset.
02051      */
02052     int8_t dr_offset ;
02053     /*!
02054      * The RX frequency.
02055      */
02056     uint32_t frequency ;
02057     /*!
02058      * The RX window timeout
02059      */
02060      uint32_t window_timeout ;
02061     /*!
02062      * The RX window offset
02063      */
02064     int32_t window_offset ;
02065     /*!
02066      * The downlink dwell time.
02067      */
02068     uint8_t dl_dwell_time ;
02069     /*!
02070      * Set to true, if a repeater is supported.
02071      */
02072     bool is_repeater_supported ;
02073     /*!
02074      * Set to true, if RX should be continuous.
02075      */
02076     bool is_rx_continuous ;
02077     /*!
02078      * Sets the RX window.
02079      */
02080     rx_slot_t  rx_slot ;
02081 } rx_config_params_t ;
02082 
02083 /*!
02084  * \brief Timer object description
02085  */
02086 typedef struct {
02087     mbed::Callback<void()> callback;
02088     int timer_id;
02089 } timer_event_t;
02090 
02091 /*!
02092  * LoRaMac internal states
02093  */
02094 typedef enum {
02095     LORAMAC_IDLE          = 0x00000000,
02096     LORAMAC_TX_RUNNING    = 0x00000001,
02097     LORAMAC_RX            = 0x00000002,
02098     LORAMAC_ACK_REQ       = 0x00000004,
02099     LORAMAC_ACK_RETRY     = 0x00000008,
02100     LORAMAC_TX_DELAYED    = 0x00000010,
02101     LORAMAC_TX_CONFIG     = 0x00000020,
02102     LORAMAC_RX_ABORT      = 0x00000040,
02103 } loramac_internal_state ;
02104 
02105 typedef struct {
02106     /*!
02107      * Device IEEE EUI
02108      */
02109     uint8_t *dev_eui;
02110 
02111     /*!
02112      * Application IEEE EUI
02113      */
02114     uint8_t *app_eui;
02115 
02116     /*!
02117      * AES encryption/decryption cipher application key
02118      */
02119     uint8_t *app_key;
02120 
02121     /*!
02122      * AES encryption/decryption cipher network session key
02123      */
02124     uint8_t nwk_skey[16];
02125 
02126     /*!
02127      * AES encryption/decryption cipher application session key
02128      */
02129     uint8_t app_skey[16];
02130 
02131 } loramac_keys;
02132 
02133 typedef struct {
02134       /*!
02135        * Aggregated duty cycle management
02136        */
02137       lorawan_time_t aggregated_last_tx_time;
02138       lorawan_time_t aggregated_timeoff;
02139 
02140       /*!
02141        * Stores the time at LoRaMac initialization.
02142        *
02143        * \remark Used for the BACKOFF_DC computation.
02144        */
02145       lorawan_time_t mac_init_time;
02146 
02147 
02148       /*!
02149        * Last transmission time on air
02150        */
02151       lorawan_time_t tx_toa;
02152 
02153       /*!
02154        * LoRaMac timer used to check the LoRaMacState (runs every second)
02155        */
02156       timer_event_t mac_state_check_timer;
02157 
02158       /*!
02159        * LoRaMac duty cycle delayed Tx timer
02160        */
02161       timer_event_t tx_delayed_timer;
02162 
02163       /*!
02164        * LoRaMac reception windows timers
02165        */
02166       timer_event_t rx_window1_timer;
02167       timer_event_t rx_window2_timer;
02168 
02169       /*!
02170        * Acknowledge timeout timer. Used for packet retransmissions.
02171        */
02172       timer_event_t ack_timeout_timer;
02173 
02174 } lorawan_timers;
02175 
02176 typedef struct {
02177 
02178     /*!
02179      * Actual device class
02180      */
02181     device_class_t  dev_class;
02182 
02183     /*!
02184      * Holds the type of current Receive window slot
02185      */
02186      rx_slot_t  rx_slot;
02187 
02188     /*!
02189      * Indicates if the node is connected to a private or public network
02190      */
02191     bool is_nwk_public;
02192 
02193     /*!
02194      * Indicates if the node supports repeaters
02195      */
02196     bool is_repeater_supported;
02197 
02198     /*!
02199      * IsPacketCounterFixed enables the MIC field tests by fixing the
02200      * ul_frame_counter value
02201      */
02202     bool is_ul_frame_counter_fixed;
02203 
02204     /*!
02205      * Used for test purposes. Disables the opening of the reception windows.
02206      */
02207     bool is_rx_window_enabled;
02208 
02209     /*!
02210      * Indicates if the MAC layer has already joined a network.
02211      */
02212     bool is_nwk_joined;
02213 
02214     /*!
02215      * If the node has sent a FRAME_TYPE_DATA_CONFIRMED_UP this variable indicates
02216      * if the nodes needs to manage the server acknowledgement.
02217      */
02218     bool is_node_ack_requested;
02219 
02220     /*!
02221      * If the server has sent a FRAME_TYPE_DATA_CONFIRMED_DOWN this variable indicates
02222      * if the ACK bit must be set for the next transmission
02223      */
02224     bool is_srv_ack_requested;
02225 
02226     /*!
02227      * Enables/Disables duty cycle management (Test only)
02228      */
02229     bool is_dutycycle_on;
02230 
02231     /*!
02232      * Set to true, if the last uplink was a join request
02233      */
02234     bool is_last_tx_join_request;
02235 
02236     /*!
02237      * Indicates if the AckTimeout timer has expired or not
02238      */
02239     bool is_ack_retry_timeout_expired;
02240 
02241     /*!
02242      * Current channel index
02243      */
02244     uint8_t channel;
02245 
02246     /*!
02247      * Current channel index
02248      */
02249     uint8_t last_channel_idx;
02250 
02251     /*!
02252      * Uplink messages repetitions counter
02253      */
02254     uint8_t ul_nb_rep_counter;
02255 
02256     /*!
02257      * Buffer containing the data to be sent or received.
02258      */
02259     uint8_t buffer[LORAMAC_PHY_MAXPAYLOAD];
02260 
02261     /*!
02262      * Length of packet in LoRaMacBuffer
02263      */
02264     uint16_t buffer_pkt_len;
02265 
02266     /*!
02267      * Buffer containing the upper layer data.
02268      */
02269     uint8_t payload[LORAMAC_PHY_MAXPAYLOAD];
02270 
02271     /*!
02272      * Length of the payload in LoRaMacBuffer
02273      */
02274     uint8_t payload_length;
02275 
02276     /*!
02277      * Number of trials to get a frame acknowledged
02278      */
02279     uint8_t max_ack_timeout_retries;
02280 
02281     /*!
02282      * Number of trials to get a frame acknowledged
02283      */
02284     uint8_t ack_timeout_retry_counter;
02285 
02286     /*!
02287      * Maximum number of trials for the Join Request
02288      */
02289     uint8_t max_join_request_trials;
02290 
02291     /*!
02292      * Number of trials for the Join Request
02293      */
02294     uint8_t join_request_trial_counter;
02295 
02296     /*!
02297      * Mac keys
02298      */
02299     loramac_keys keys;
02300 
02301     /*!
02302      * LoRaMac tx/rx operation state
02303      */
02304     loramac_flags_t  flags;
02305 
02306     /*!
02307      * Device nonce is a random value extracted by issuing a sequence of RSSI
02308      * measurements
02309      */
02310     uint16_t dev_nonce;
02311 
02312     /*!
02313      * Network ID ( 3 bytes )
02314      */
02315     uint32_t net_id;
02316 
02317     /*!
02318      * Mote Address
02319      */
02320     uint32_t dev_addr;
02321 
02322     /*!
02323      * LoRaMAC frame counter. Each time a packet is sent the counter is incremented.
02324      * Only the 16 LSB bits are sent
02325      */
02326     uint32_t ul_frame_counter;
02327 
02328     /*!
02329      * LoRaMAC frame counter. Each time a packet is received the counter is incremented.
02330      * Only the 16 LSB bits are received
02331      */
02332     uint32_t dl_frame_counter;
02333 
02334     /*!
02335      * Counts the number of missed ADR acknowledgements
02336      */
02337     uint32_t adr_ack_counter;
02338 
02339     /*!
02340      * LoRaMac internal state
02341      */
02342     uint32_t mac_state;
02343 
02344     /*!
02345      * LoRaMac reception windows delay
02346      * \remark normal frame: RxWindowXDelay = ReceiveDelayX - RADIO_WAKEUP_TIME
02347      *         join frame  : RxWindowXDelay = JoinAcceptDelayX - RADIO_WAKEUP_TIME
02348      */
02349     uint32_t rx_window1_delay;
02350     uint32_t rx_window2_delay;
02351 
02352     /*!
02353      * Timer objects and stored values
02354      */
02355     lorawan_timers timers;
02356 
02357     /*!
02358      * LoRaMac parameters
02359      */
02360     lora_mac_system_params_t  sys_params;
02361 
02362     /*!
02363      * Receive Window configurations for PHY layer
02364      */
02365     rx_config_params_t  rx_window1_config;
02366     rx_config_params_t  rx_window2_config;
02367 
02368     /*!
02369      * Multicast channels linked list
02370      */
02371     multicast_params_t  *multicast_channels;
02372 
02373 } loramac_protocol_params;
02374 
02375 /** LoRaWAN callback functions
02376  *
02377  */
02378 typedef enum lora_events {
02379     CONNECTED=0,
02380     DISCONNECTED,
02381     TX_DONE,
02382     TX_TIMEOUT,
02383     TX_ERROR,
02384     TX_CRYPTO_ERROR,
02385     TX_SCHEDULING_ERROR,
02386     RX_DONE,
02387     RX_TIMEOUT,
02388     RX_ERROR,
02389     JOIN_FAILURE,
02390 } lorawan_event_t;
02391 
02392 typedef struct  {
02393      // Mandatory. Event Callback must be provided
02394      mbed::Callback<void(lorawan_event_t)> events;
02395 
02396      // Rest are optional
02397      // If the user do not assign these callbacks, these callbacks would return
02398      // null if checked with bool operator
02399      // link_check_resp callback and other such callbacks will be maped in
02400      // future releases of Mbed-OS
02401      mbed::Callback<void(uint8_t, uint8_t)> link_check_resp;
02402 
02403      // Battery level callback goes in the down direction, i.e., it informs
02404      // the stack about the battery level by calling a function provided
02405      // by the upper layers
02406      mbed::Callback<uint8_t(void)> battery_level;
02407  } lorawan_app_callbacks_t;
02408 
02409 typedef struct lora_channelplan {
02410     uint8_t nb_channels;    // number of channels
02411     loramac_channel_t *channels;
02412 } lorawan_channelplan_t;
02413 
02414 #endif /* LORAWAN_SYSTEM_LORAWAN_DATA_STRUCTURES_H_ */