Gleb Klochkov / Mbed OS Climatcontroll_Main

Dependencies:   esp8266-driver

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  * Bit mask for message flags
00060  */
00061 
00062 #define MSG_FLAG_MASK                         0x0F
00063 
00064 /**
00065  * Mask for unconfirmed multicast message
00066  */
00067 #define MSG_UNCONFIRMED_MULTICAST              0x05
00068 
00069 /**
00070  * Mask for confirmed multicast message
00071  */
00072 #define MSG_CONFIRMED_MULTICAST                0x06
00073 
00074 /**
00075  * Mask for unconfirmed message proprietary message
00076  */
00077 #define MSG_UNCONFIRMED_PROPRIETARY            0x09
00078 
00079 /**
00080  * Mask for confirmed proprietary message
00081  */
00082 #define MSG_CONFIRMED_PROPRIETARY              0x0A
00083 
00084 /*!
00085  * Sets the length of the LoRaMAC footer field.
00086  * Mainly indicates the MIC field length.
00087  */
00088 #define LORAMAC_MFR_LEN                             4
00089 
00090 /*!
00091  * The FRMPayload overhead to be used when setting the `Radio.SetMaxPayloadLength`
00092  * in the `RxWindowSetup` function.
00093  * The maximum PHYPayload = MaxPayloadOfDatarate/MaxPayloadOfDatarateRepeater + LORA_MAC_FRMPAYLOAD_OVERHEAD
00094  */
00095 #define LORA_MAC_FRMPAYLOAD_OVERHEAD                13 // MHDR(1) + FHDR(7) + Port(1) + MIC(4)
00096 
00097 /**
00098  * LoRaMac maximum number of channels
00099  */
00100 #define LORA_MAX_NB_CHANNELS                        16
00101 
00102 /**
00103  * Maximum PHY layer payload size for reception.
00104  */
00105 #define LORAMAC_PHY_MAXPAYLOAD                      255
00106 
00107 /**
00108  *
00109  * Default user application maximum data size for transmission
00110  */
00111 // reject if user tries to set more than MTU
00112 #if MBED_CONF_LORA_TX_MAX_SIZE > 255
00113     #warning "Cannot set TX Max size more than MTU=255"
00114     #define MBED_CONF_LORA_TX_MAX_SIZE              255
00115 #endif
00116 
00117 /*!
00118  * LoRaWAN device classes definition.
00119  *
00120  * LoRaWAN Specification V1.0.2, chapter 2.1.
00121  */
00122 typedef enum {
00123     /*!
00124      * LoRaWAN device class A.
00125      *
00126      * LoRaWAN Specification V1.0.2, chapter 3.
00127      */
00128     CLASS_A ,
00129     /*!
00130      * LoRaWAN device class B.
00131      *
00132      * LoRaWAN Specification V1.0.2, chapter 8.
00133      */
00134     CLASS_B ,
00135     /*!
00136      * LoRaWAN device class C.
00137      *
00138      * LoRaWAN Specification V1.0.2, chapter 17.
00139      */
00140     CLASS_C ,
00141 } device_class_t ;
00142 
00143 /*!
00144  * LoRaMAC channel parameters definition.
00145  * DO NOT MODIFY, WILL BREAK THE API!
00146  */
00147 typedef union {
00148     /*!
00149      * Byte-access to the bits.
00150      */
00151     int8_t value ;
00152     /*!
00153      * The structure to store the minimum and the maximum datarate.
00154      */
00155     struct sFields 
00156     {
00157          /*!
00158          * The minimum data rate.
00159          *
00160          * LoRaWAN Regional Parameters V1.0.2rB.
00161          *
00162          * The allowed ranges are region-specific. Please refer to \ref DR_0 to \ref DR_15 for details.
00163          */
00164         int8_t min : 4;
00165         /*!
00166          * The maximum data rate.
00167          *
00168          * LoRaWAN Regional Parameters V1.0.2rB.
00169          *
00170          * The allowed ranges are region-specific. Please refer to \ref DR_0 to \ref DR_15 for details.
00171          */
00172         int8_t max : 4;
00173     } fields;
00174 } dr_range_t ;
00175 
00176 /*!
00177  * LoRaMAC channel definition.
00178  * DO NOT MODIFY, WILL BREAK THE API!
00179  */
00180 typedef struct {
00181     /*!
00182      * The frequency in Hz.
00183      */
00184     uint32_t frequency ;
00185     /*!
00186      * The alternative frequency for RX window 1.
00187      */
00188     uint32_t rx1_frequency ;
00189     /*!
00190      * The data rate definition.
00191      */
00192     dr_range_t  dr_range ;
00193     /*!
00194      * The band index.
00195      */
00196     uint8_t band ;
00197 } channel_params_t ;
00198 
00199 /*!
00200  * LoRaMAC band parameters definition.
00201  */
00202 typedef struct {
00203     /*!
00204      * The duty cycle.
00205      */
00206     uint16_t duty_cycle ;
00207     /*!
00208      * The maximum TX power.
00209      */
00210     int8_t max_tx_pwr ;
00211     /*!
00212      * The timestamp of the last Join Request TX frame.
00213      */
00214     lorawan_time_t last_join_tx_time ;
00215     /*!
00216      * The timestamp of the last TX frame.
00217      */
00218     lorawan_time_t last_tx_time ;
00219     /*!
00220      * The device off time.
00221      */
00222     lorawan_time_t off_time ;
00223     /*!
00224      * Lower band boundry
00225      */
00226     uint32_t lower_band_freq ;
00227     /*!
00228      * Higher band boundry
00229      */
00230     uint32_t higher_band_freq ;
00231 } band_t ;
00232 
00233 /*!
00234  * LoRaMAC receive window 2 channel parameters.
00235  */
00236 typedef struct {
00237     /*!
00238      * The frequency in Hz.
00239      */
00240     uint32_t frequency ;
00241     /*!
00242      * The data rate.
00243      *
00244      * LoRaWAN Regional Parameters V1.0.2rB.
00245      *
00246      * The allowed ranges are region-specific. Please refer to \ref DR_0 to \ref DR_15 for details.
00247      */
00248     uint8_t  datarate ;
00249 } rx2_channel_params ;
00250 
00251 /*!
00252  * LoRaMAC receive window enumeration
00253  */
00254 typedef enum {
00255     /*!
00256      * LoRaMAC receive window 1
00257      */
00258     RX_SLOT_WIN_1 ,
00259     /*!
00260      * LoRaMAC receive window 2
00261      */
00262     RX_SLOT_WIN_2 ,
00263     /*!
00264      * LoRaMAC receive window 2 for class c - continuous listening
00265      */
00266     RX_SLOT_WIN_CLASS_C ,
00267     /*!
00268      * LoRaMAC class b ping slot window
00269      */
00270     RX_SLOT_WIN_PING_SLOT 
00271 } rx_slot_t ;
00272 
00273 /*!
00274  * The global MAC layer parameters.
00275  */
00276 typedef struct {
00277     /*!
00278      * The TX power in channels.
00279      */
00280     int8_t channel_tx_power ;
00281     /*!
00282      * The data rate in channels.
00283      */
00284     int8_t channel_data_rate ;
00285     /*!
00286      * The system overall timing error in milliseconds.
00287      * [-SystemMaxRxError : +SystemMaxRxError]
00288      * Default: +/-10 ms
00289      */
00290     uint32_t max_sys_rx_error ;
00291     /*!
00292      * The minimum number of symbols required to detect an RX frame.
00293      * Default: 6 symbols
00294      */
00295     uint8_t min_rx_symb ;
00296     /*!
00297      * LoRaMac maximum time a reception window stays open.
00298      */
00299     uint32_t max_rx_win_time ;
00300     /*!
00301      * Receive delay 1.
00302      */
00303     uint32_t recv_delay1 ;
00304     /*!
00305      * Receive delay 2.
00306      */
00307     uint32_t recv_delay2 ;
00308     /*!
00309      * Join accept delay 1.
00310      */
00311     uint32_t join_accept_delay1 ;
00312     /*!
00313      * Join accept delay 1.
00314      */
00315     uint32_t join_accept_delay2 ;
00316     /*!
00317      * The number of uplink messages repetitions (confirmed messages only).
00318      */
00319     uint8_t retry_num ;
00320     /*!
00321      * The datarate offset between uplink and downlink on first window.
00322      */
00323     uint8_t rx1_dr_offset ;
00324     /*!
00325      * LoRaMAC 2nd reception window settings.
00326      */
00327     rx2_channel_params  rx2_channel ;
00328     /*!
00329      * The uplink dwell time configuration. 0: No limit, 1: 400ms
00330      */
00331     uint8_t uplink_dwell_time ;
00332     /*!
00333      * The downlink dwell time configuration. 0: No limit, 1: 400ms
00334      */
00335     uint8_t downlink_dwell_time ;
00336     /*!
00337      * The maximum possible EIRP.
00338      */
00339     float max_eirp ;
00340     /*!
00341      * The antenna gain of the node.
00342      */
00343     float antenna_gain ;
00344 
00345     /*!
00346      * Maximum duty cycle
00347      * \remark Possibility to shutdown the device.
00348      */
00349     uint8_t max_duty_cycle ;
00350     /*!
00351      * Aggregated duty cycle management
00352      */
00353     uint16_t aggregated_duty_cycle ;
00354 
00355     /*!
00356      * LoRaMac ADR control status
00357      */
00358     bool adr_on ;
00359 } lora_mac_system_params_t ;
00360 
00361 /*!
00362  * LoRaMAC multicast channel parameter.
00363  */
00364 typedef struct multicast_params_s  {
00365     /*!
00366      * Address.
00367      */
00368     uint32_t address ;
00369     /*!
00370      * Network session key.
00371      */
00372     uint8_t nwk_skey [16];
00373     /*!
00374      * Application session key.
00375      */
00376     uint8_t app_skey [16];
00377     /*!
00378      * Downlink counter.
00379      */
00380     uint32_t dl_frame_counter ;
00381     /*!
00382      * A reference pointer to the next multicast channel parameters in the list.
00383      */
00384     struct multicast_params_s  *next ;
00385 } multicast_params_t ;
00386 
00387 /*!
00388  * LoRaMAC frame types.
00389  *
00390  * LoRaWAN Specification V1.0.2, chapter 4.2.1, table 1.
00391  */
00392 typedef enum {
00393     /*!
00394      * LoRaMAC join request frame.
00395      */
00396     FRAME_TYPE_JOIN_REQ               = 0x00,
00397     /*!
00398      * LoRaMAC join accept frame.
00399      */
00400     FRAME_TYPE_JOIN_ACCEPT            = 0x01,
00401     /*!
00402      * LoRaMAC unconfirmed uplink frame.
00403      */
00404     FRAME_TYPE_DATA_UNCONFIRMED_UP    = 0x02,
00405     /*!
00406      * LoRaMAC unconfirmed downlink frame.
00407      */
00408     FRAME_TYPE_DATA_UNCONFIRMED_DOWN  = 0x03,
00409     /*!
00410      * LoRaMAC confirmed uplink frame.
00411      */
00412     FRAME_TYPE_DATA_CONFIRMED_UP      = 0x04,
00413     /*!
00414      * LoRaMAC confirmed downlink frame.
00415      */
00416     FRAME_TYPE_DATA_CONFIRMED_DOWN    = 0x05,
00417     /*!
00418      * LoRaMAC RFU frame.
00419      */
00420     FRAME_TYPE_RFU                    = 0x06,
00421     /*!
00422      * LoRaMAC proprietary frame.
00423      */
00424     FRAME_TYPE_PROPRIETARY            = 0x07,
00425 } mac_frame_type_t ;
00426 
00427 /*!
00428  * LoRaMAC mote MAC commands.
00429  *
00430  * LoRaWAN Specification V1.0.2, chapter 5, table 4.
00431  */
00432 typedef enum {
00433     /*!
00434      * LinkCheckReq
00435      */
00436     MOTE_MAC_LINK_CHECK_REQ           = 0x02,
00437     /*!
00438      * LinkADRAns
00439      */
00440     MOTE_MAC_LINK_ADR_ANS             = 0x03,
00441     /*!
00442      * DutyCycleAns
00443      */
00444     MOTE_MAC_DUTY_CYCLE_ANS           = 0x04,
00445     /*!
00446      * RXParamSetupAns
00447      */
00448     MOTE_MAC_RX_PARAM_SETUP_ANS       = 0x05,
00449     /*!
00450      * DevStatusAns
00451      */
00452     MOTE_MAC_DEV_STATUS_ANS           = 0x06,
00453     /*!
00454      * NewChannelAns
00455      */
00456     MOTE_MAC_NEW_CHANNEL_ANS          = 0x07,
00457     /*!
00458      * RXTimingSetupAns
00459      */
00460     MOTE_MAC_RX_TIMING_SETUP_ANS      = 0x08,
00461     /*!
00462      * TXParamSetupAns
00463      */
00464     MOTE_MAC_TX_PARAM_SETUP_ANS       = 0x09,
00465     /*!
00466      * DlChannelAns
00467      */
00468     MOTE_MAC_DL_CHANNEL_ANS           = 0x0A
00469 } mote_mac_cmds_t ;
00470 
00471 /*!
00472  * LoRaMAC server MAC commands.
00473  *
00474  * LoRaWAN Specification V1.0.2 chapter 5, table 4.
00475  */
00476 typedef enum {
00477     /*!
00478      * LinkCheckAns
00479      */
00480     SRV_MAC_LINK_CHECK_ANS            = 0x02,
00481     /*!
00482      * LinkADRReq
00483      */
00484     SRV_MAC_LINK_ADR_REQ              = 0x03,
00485     /*!
00486      * DutyCycleReq
00487      */
00488     SRV_MAC_DUTY_CYCLE_REQ            = 0x04,
00489     /*!
00490      * RXParamSetupReq
00491      */
00492     SRV_MAC_RX_PARAM_SETUP_REQ        = 0x05,
00493     /*!
00494      * DevStatusReq
00495      */
00496     SRV_MAC_DEV_STATUS_REQ            = 0x06,
00497     /*!
00498      * NewChannelReq
00499      */
00500     SRV_MAC_NEW_CHANNEL_REQ           = 0x07,
00501     /*!
00502      * RXTimingSetupReq
00503      */
00504     SRV_MAC_RX_TIMING_SETUP_REQ       = 0x08,
00505     /*!
00506      * NewChannelReq
00507      */
00508     SRV_MAC_TX_PARAM_SETUP_REQ        = 0x09,
00509     /*!
00510      * DlChannelReq
00511      */
00512     SRV_MAC_DL_CHANNEL_REQ            = 0x0A,
00513 } server_mac_cmds_t ;
00514 
00515 /*!
00516  * LoRaMAC battery level indicator.
00517  */
00518 typedef enum {
00519     /*!
00520      * An external power source.
00521      */
00522     BAT_LEVEL_EXT_SRC                 = 0x00,
00523     /*!
00524      * Battery level empty.
00525      */
00526     BAT_LEVEL_EMPTY                   = 0x01,
00527     /*!
00528      * Battery level full.
00529      */
00530     BAT_LEVEL_FULL                    = 0xFE,
00531     /*!
00532      * Battery level - no measurement available.
00533      */
00534     BAT_LEVEL_NO_MEASURE              = 0xFF,
00535 } device_battery_level_t ;
00536 
00537 /*!
00538  * LoRaMAC header field definition (MHDR field).
00539  *
00540  * LoRaWAN Specification V1.0.2, chapter 4.2.
00541  */
00542 typedef union {
00543     /*!
00544      * Byte-access to the bits.
00545      */
00546     uint8_t value ;
00547     /*!
00548      * The structure containing single access to header bits.
00549      */
00550     struct hdr_bits_s 
00551     {
00552         /*!
00553          * Major version.
00554          */
00555         uint8_t major           : 2;
00556         /*!
00557          * RFU
00558          */
00559         uint8_t RFU             : 3;
00560         /*!
00561          * Message type
00562          */
00563         uint8_t mtype           : 3;
00564     } bits;
00565 } loramac_mhdr_t ;
00566 
00567 /*!
00568  * LoRaMAC frame control field definition (FCtrl).
00569  *
00570  * LoRaWAN Specification V1.0.2, chapter 4.3.1.
00571  */
00572 typedef union {
00573     /*!
00574      * Byte-access to the bits.
00575      */
00576     uint8_t value ;
00577     /*!
00578      * The structure containing single access to bits.
00579      */
00580     struct ctrl_bits_s 
00581     {
00582         /*!
00583          * Frame options length.
00584          */
00585         uint8_t fopts_len        : 4;
00586         /*!
00587          * Frame pending bit.
00588          */
00589         uint8_t fpending        : 1;
00590         /*!
00591          * Message acknowledge bit.
00592          */
00593         uint8_t ack             : 1;
00594         /*!
00595          * ADR acknowledgment request bit.
00596          */
00597         uint8_t adr_ack_req       : 1;
00598         /*!
00599          * ADR control in the frame header.
00600          */
00601         uint8_t adr             : 1;
00602     } bits;
00603 } loramac_frame_ctrl_t ;
00604 
00605 /*!
00606  * The enumeration containing the status of the operation of a MAC service.
00607  */
00608 typedef enum {
00609     /*!
00610      * Service performed successfully.
00611      */
00612     LORAMAC_EVENT_INFO_STATUS_OK  = 0,
00613     /*!
00614      * An error occurred during the execution of the service.
00615      */
00616     LORAMAC_EVENT_INFO_STATUS_ERROR ,
00617     /*!
00618      * A TX timeout occurred.
00619      */
00620     LORAMAC_EVENT_INFO_STATUS_TX_TIMEOUT ,
00621     /*!
00622      * An RX timeout occurred on receive window 1.
00623      */
00624     LORAMAC_EVENT_INFO_STATUS_RX1_TIMEOUT ,
00625     /*!
00626      * An RX timeout occurred on receive window 2.
00627      */
00628     LORAMAC_EVENT_INFO_STATUS_RX2_TIMEOUT ,
00629     /*!
00630      * An RX error occurred on receive window 1.
00631      */
00632     LORAMAC_EVENT_INFO_STATUS_RX1_ERROR ,
00633     /*!
00634      * An RX error occurred on receive window 2.
00635      */
00636     LORAMAC_EVENT_INFO_STATUS_RX2_ERROR ,
00637     /*!
00638      * An error occurred in the join procedure.
00639      */
00640     LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL ,
00641     /*!
00642      * A frame with an invalid downlink counter was received. The
00643      * downlink counter of the frame was equal to the local copy
00644      * of the downlink counter of the node.
00645      */
00646     LORAMAC_EVENT_INFO_STATUS_DOWNLINK_REPEATED ,
00647     /*!
00648      * The MAC could not retransmit a frame since the MAC decreased the datarate. The
00649      * payload size is not applicable for the datarate.
00650      */
00651     LORAMAC_EVENT_INFO_STATUS_TX_DR_PAYLOAD_SIZE_ERROR ,
00652     /*!
00653      * The node has lost MAX_FCNT_GAP or more frames.
00654      */
00655     LORAMAC_EVENT_INFO_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS ,
00656     /*!
00657      * An address error occurred.
00658      */
00659     LORAMAC_EVENT_INFO_STATUS_ADDRESS_FAIL ,
00660     /*!
00661      * Message integrity check failure.
00662      */
00663     LORAMAC_EVENT_INFO_STATUS_MIC_FAIL ,
00664     /*!
00665      * Crypto methods failure
00666      */
00667     LORAMAC_EVENT_INFO_STATUS_CRYPTO_FAIL ,
00668 } loramac_event_info_status_t ;
00669 
00670 /*!
00671  * LoRaMac service state flags.
00672  */
00673 typedef union {
00674     /*!
00675      * Byte-access to the bits.
00676      */
00677     uint8_t value ;
00678     /*!
00679      * The structure containing single access to bits.
00680      */
00681     struct mac_flag_bits_s 
00682     {
00683         /*!
00684          * MCPS-Req pending
00685          */
00686         uint8_t mcps_req         : 1;
00687         /*!
00688          * MCPS-Ind pending
00689          */
00690         uint8_t mcps_ind         : 1;
00691         /*!
00692          * MCPS-Ind pending. Skip indication to the application layer.
00693          */
00694         uint8_t mcps_ind_skip     : 1;
00695         /*!
00696          * MLME-Req pending
00697          */
00698         uint8_t mlme_req         : 1;
00699         /*!
00700          * MLME-Ind pending
00701          */
00702         uint8_t mlme_ind         : 1;
00703         /*!
00704          * MAC cycle done
00705          */
00706         uint8_t mac_done         : 1;
00707     } bits;
00708 } loramac_flags_t ;
00709 
00710 /*!
00711  *
00712  * \brief   LoRaMAC data services
00713  *
00714  * \details The following table list the primitives supported by a
00715  *          specific MAC data service:
00716  *
00717  * Name                  | Request | Indication | Response | Confirm
00718  * --------------------- | :-----: | :--------: | :------: | :-----:
00719  * \ref MCPS_UNCONFIRMED | YES     | YES        | NO       | YES
00720  * \ref MCPS_CONFIRMED   | YES     | YES        | NO       | YES
00721  * \ref MCPS_MULTICAST   | NO      | YES        | NO       | NO
00722  * \ref MCPS_PROPRIETARY | YES     | YES        | NO       | YES
00723  *
00724  * The following table provides links to the function implementations of the
00725  * related MCPS primitives:
00726  *
00727  * Primitive        | Function
00728  * ---------------- | :---------------------:
00729  * MCPS-Request     | LoRaMacMlmeRequest
00730  * MCPS-Confirm     | MacMcpsConfirm in \ref loramac_primitives_t
00731  * MCPS-Indication  | MacMcpsIndication in \ref loramac_primitives_t
00732  */
00733 typedef enum {
00734     /*!
00735      * Unconfirmed LoRaMAC frame.
00736      */
00737     MCPS_UNCONFIRMED ,
00738     /*!
00739      * Confirmed LoRaMAC frame.
00740      */
00741     MCPS_CONFIRMED ,
00742     /*!
00743      * Multicast LoRaMAC frame.
00744      */
00745     MCPS_MULTICAST ,
00746     /*!
00747      * Proprietary frame.
00748      */
00749     MCPS_PROPRIETARY ,
00750 } mcps_type_t;
00751 
00752 /*!
00753  * LoRaMAC MCPS-Confirm.
00754  */
00755 typedef struct {
00756     /*!
00757      * Holds the previously performed MCPS-Request type. i.e., the type of
00758      * the MCPS request for which this confirmation is being generated
00759      */
00760     mcps_type_t req_type ;
00761     /*!
00762      * The status of the operation.
00763      */
00764     loramac_event_info_status_t  status ;
00765     /*!
00766      * The uplink datarate.
00767      */
00768     uint8_t data_rate ;
00769     /*!
00770      * The transmission power.
00771      */
00772     int8_t tx_power ;
00773     /*!
00774      * Set if an acknowledgement was received.
00775      */
00776     bool ack_received ;
00777     /*!
00778      * Provides the number of retransmissions.
00779      */
00780     uint8_t nb_retries ;
00781     /*!
00782      * The transmission time on air of the frame.
00783      */
00784     lorawan_time_t tx_toa ;
00785     /*!
00786      * The uplink counter value related to the frame.
00787      */
00788     uint32_t ul_frame_counter ;
00789     /*!
00790      * The uplink channel related to the frame.
00791      */
00792     uint32_t channel ;
00793 } loramac_mcps_confirm_t ;
00794 
00795 /*!
00796  * LoRaMAC MCPS-Indication primitive.
00797  */
00798 typedef struct {
00799     /*!
00800      * MCPS-Indication type.
00801      */
00802     mcps_type_t type ;
00803     /*!
00804      * The status of the operation.
00805      */
00806     loramac_event_info_status_t  status ;
00807     /*!
00808      * Multicast.
00809      */
00810     uint8_t multicast ;
00811     /*!
00812      * The application port.
00813      */
00814     uint8_t port ;
00815     /*!
00816      * The downlink datarate.
00817      */
00818     uint8_t rx_datarate ;
00819     /*!
00820      * Frame pending status.
00821      */
00822     uint8_t fpending_status ;
00823     /*!
00824      * A pointer to the received data stream.
00825      */
00826     uint8_t *buffer ;
00827     /*!
00828      * The size of the received data stream.
00829      */
00830     uint16_t buffer_size ;
00831     /*!
00832      * Indicates, if data is available.
00833      */
00834     bool is_data_recvd ;
00835     /*!
00836      * The RSSI of the received packet.
00837      */
00838     int16_t rssi ;
00839     /*!
00840      * The SNR of the received packet.
00841      */
00842     uint8_t snr ;
00843     /*!
00844      * The receive window.
00845      *
00846      * [0: Rx window 1, 1: Rx window 2]
00847      */
00848     rx_slot_t  rx_slot ;
00849     /*!
00850      * Set if an acknowledgement was received.
00851      */
00852     bool is_ack_recvd ;
00853     /*!
00854      * The downlink counter value for the received frame.
00855      */
00856     uint32_t dl_frame_counter ;
00857 } loramac_mcps_indication_t ;
00858 
00859 /*!
00860  * \brief LoRaMAC management services.
00861  *
00862  * \details The following table list the primitives supported by a
00863  *          specific MAC management service:
00864  *
00865  * Name                         | Request | Indication | Response | Confirm
00866  * ---------------------------- | :-----: | :--------: | :------: | :-----:
00867  * \ref MLME_JOIN               | YES     | NO         | NO       | YES
00868  * \ref MLME_LINK_CHECK         | YES     | NO         | NO       | YES
00869  * \ref MLME_TXCW               | YES     | NO         | NO       | YES
00870  * \ref MLME_SCHEDULE_UPLINK    | NO      | YES        | NO       | NO
00871  *
00872  * The following table provides links to the function implementations of the
00873  * related MLME primitives.
00874  *
00875  * Primitive        | Function
00876  * ---------------- | :---------------------:
00877  * MLME-Request     | LoRaMacMlmeRequest
00878  * MLME-Confirm     | MacMlmeConfirm in \ref loramac_primitives_t
00879  * MLME-Indication  | MacMlmeIndication in \ref loramac_primitives_t
00880  */
00881 typedef enum {
00882     /*!
00883      * Initiates the Over-the-Air activation.
00884      *
00885      * LoRaWAN Specification V1.0.2, chapter 6.2.
00886      */
00887     MLME_JOIN ,
00888     /*!
00889      * LinkCheckReq - Connectivity validation.
00890      *
00891      * LoRaWAN Specification V1.0.2, chapter 5, table 4.
00892      */
00893     MLME_LINK_CHECK ,
00894     /*!
00895      * Sets TX continuous wave mode.
00896      *
00897      * LoRaWAN end-device certification.
00898      */
00899     MLME_TXCW ,
00900     /*!
00901      * Sets TX continuous wave mode (new LoRa-Alliance CC definition).
00902      *
00903      * LoRaWAN end-device certification.
00904      */
00905     MLME_TXCW_1 ,
00906     /*!
00907      * Indicates that the application shall perform an uplink as
00908      * soon as possible.
00909      */
00910     MLME_SCHEDULE_UPLINK 
00911 } mlme_type_t;
00912 
00913 /*!
00914  * LoRaMAC MLME-Request for the join service.
00915  */
00916 typedef struct {
00917     /*!
00918      * A globally unique end-device identifier.
00919      *
00920      * LoRaWAN Specification V1.0.2, chapter 6.2.1.
00921      */
00922     uint8_t *dev_eui ;
00923     /*!
00924      * An application identifier.
00925      *
00926      * LoRaWAN Specification V1.0.2, chapter 6.1.2
00927      */
00928     uint8_t *app_eui ;
00929     /*!
00930      * AES-128 application key.
00931      *
00932      * LoRaWAN Specification V1.0.2, chapter 6.2.2.
00933      */
00934     uint8_t *app_key ;
00935     /*!
00936      * The number of trials for the join request.
00937      */
00938     uint8_t nb_trials ;
00939 } mlme_join_req_t ;
00940 
00941 /*!
00942  * LoRaMAC MLME-Request for TX continuous wave mode.
00943  */
00944 typedef struct {
00945     /*!
00946      * The time while the radio is kept in continuous wave mode, in seconds.
00947      */
00948     uint16_t timeout ;
00949     /*!
00950      * The RF frequency to set (only used with the new way).
00951      */
00952     uint32_t frequency ;
00953     /*!
00954      * The RF output power to set (only used with the new way).
00955      */
00956     uint8_t power ;
00957 } mlme_cw_tx_mode_t ;
00958 
00959 
00960 /*!
00961  * LoRaMAC MLME-Confirm primitive.
00962  */
00963 typedef struct {
00964     /*!
00965      * The previously performed MLME-Request. i.e., the request type
00966      * for which the confirmation is being generated
00967      */
00968     mlme_type_t req_type ;
00969     /*!
00970      * The status of the operation.
00971      */
00972     loramac_event_info_status_t  status ;
00973     /*!
00974      * The transmission time on air of the frame.
00975      */
00976     lorawan_time_t tx_toa ;
00977     /*!
00978      * The demodulation margin. Contains the link margin [dB] of the last LinkCheckReq
00979      * successfully received.
00980      */
00981     uint8_t demod_margin ;
00982     /*!
00983      * The number of gateways which received the last LinkCheckReq.
00984      */
00985     uint8_t nb_gateways ;
00986     /*!
00987      * The number of retransmissions.
00988      */
00989     uint8_t nb_retries ;
00990 } loramac_mlme_confirm_t ;
00991 
00992 /*!
00993  * LoRaMAC MLME-Indication primitive
00994  */
00995 typedef struct {
00996     /*!
00997      * MLME-Indication type
00998      */
00999     mlme_type_t indication_type ;
01000 } loramac_mlme_indication_t ;
01001 
01002 /** LoRaMAC status.
01003  *
01004  */
01005 typedef enum lorawan_status {
01006     LORAWAN_STATUS_OK = 0,                         /**< Service started successfully */
01007     LORAWAN_STATUS_BUSY = -1000,                   /**< Service not started - LoRaMAC is busy */
01008     LORAWAN_STATUS_WOULD_BLOCK = -1001,            /**< LoRaMAC cannot send at the moment or have nothing to read */
01009     LORAWAN_STATUS_SERVICE_UNKNOWN = -1002,        /**< Service unknown */
01010     LORAWAN_STATUS_PARAMETER_INVALID = -1003,      /**< Service not started - invalid parameter */
01011     LORAWAN_STATUS_FREQUENCY_INVALID = -1004,      /**< Service not started - invalid frequency */
01012     LORAWAN_STATUS_DATARATE_INVALID = -1005,       /**< Service not started - invalid datarate */
01013     LORAWAN_STATUS_FREQ_AND_DR_INVALID = -1006,    /**< Service not started - invalid frequency and datarate */
01014     LORAWAN_STATUS_NO_NETWORK_JOINED = -1009,      /**< Service not started - the device is not in a LoRaWAN */
01015     LORAWAN_STATUS_LENGTH_ERROR = -1010,           /**< Service not started - payload lenght error */
01016     LORAWAN_STATUS_DEVICE_OFF = -1011,             /**< Service not started - the device is switched off */
01017     LORAWAN_STATUS_NOT_INITIALIZED = -1012,        /**< Service not started - stack not initialized */
01018     LORAWAN_STATUS_UNSUPPORTED = -1013,            /**< Service not supported */
01019     LORAWAN_STATUS_CRYPTO_FAIL = -1014,            /**< Service not started - crypto failure */
01020     LORAWAN_STATUS_PORT_INVALID = -1015,           /**< Invalid port */
01021     LORAWAN_STATUS_CONNECT_IN_PROGRESS = -1016,    /**< Services started - Connection in progress */
01022     LORAWAN_STATUS_NO_ACTIVE_SESSIONS = -1017,            /**< Services not started - No active session */
01023     LORAWAN_STATUS_IDLE = -1018,                   /**< Services started - Idle at the moment */
01024 #if defined(LORAWAN_COMPLIANCE_TEST)
01025     LORAWAN_STATUS_COMPLIANCE_TEST_ON = -1019,     /**< Compliance test - is on-going */
01026 #endif
01027     LORAWAN_STATUS_DUTYCYCLE_RESTRICTED = -1020,
01028     LORAWAN_STATUS_NO_CHANNEL_FOUND = -1021,
01029     LORAWAN_STATUS_NO_FREE_CHANNEL_FOUND = -1022,
01030 } lorawan_status_t;
01031 
01032 /*!
01033  * LoRaMAC events structure.
01034  * Used to notify upper layers of MAC events.
01035  */
01036 typedef struct {
01037     /*!
01038      * \brief   MCPS-Confirm primitive.
01039      *
01040      * \param   [OUT] MCPS-Confirm parameters.
01041      */
01042     mbed::Callback<void(loramac_mcps_confirm_t*)> mcps_confirm;
01043 
01044     /*!
01045      * \brief   MCPS-Indication primitive.
01046      *
01047      * \param   [OUT] MCPS-Indication parameters.
01048      */
01049     mbed::Callback<void(loramac_mcps_indication_t*)> mcps_indication;
01050 
01051     /*!
01052      * \brief   MLME-Confirm primitive.
01053      *
01054      * \param   [OUT] MLME-Confirm parameters.
01055      */
01056     mbed::Callback<void(loramac_mlme_confirm_t*)> mlme_confirm;
01057 
01058     /*!
01059      * \brief   MLME-Indication primitive
01060      *
01061      * \param   [OUT] MLME-Indication parameters
01062      */
01063     mbed::Callback<void(loramac_mlme_indication_t*)> mlme_indication;
01064 }loramac_primitives_t ;
01065 
01066 /** Enum of LoRaWAN connection type.
01067  *
01068  * The LoRaWAN connection type specifies how an end-device connects to the gateway.
01069  */
01070 typedef enum lorawan_connect_type {
01071     LORAWAN_CONNECTION_OTAA = 0,    /**< Over The Air Activation */
01072     LORAWAN_CONNECTION_ABP          /**< Activation By Personalization */
01073 } lorawan_connect_type_t;
01074 
01075 /** The lorawan_connect_otaa structure.
01076  *
01077  * A structure representing the LoRaWAN Over The Air Activation
01078  * parameters.
01079  */
01080 typedef struct {
01081     /** End-device identifier
01082      *
01083      * LoRaWAN Specification V1.0.2, chapter 6.2.1
01084      */
01085     uint8_t *dev_eui;
01086     /** Application identifier
01087      *
01088      * LoRaWAN Specification V1.0.2, chapter 6.1.2
01089      */
01090     uint8_t *app_eui;
01091     /** AES-128 application key
01092      *
01093      * LoRaWAN Specification V1.0.2, chapter 6.2.2
01094      */
01095     uint8_t *app_key;
01096     /** Join request trials
01097      *
01098      * Number of trials for the join request.
01099      */
01100     uint8_t nb_trials;
01101 } lorawan_connect_otaa_t;
01102 
01103 /** The lorawan_connect_abp structure.
01104  *
01105  * A structure representing the LoRaWAN Activation By Personalization
01106  * parameters.
01107  */
01108 typedef struct {
01109     /** Network identifier
01110      *
01111      * LoRaWAN Specification V1.0.2, chapter 6.1.1
01112      */
01113     uint32_t nwk_id;
01114     /** End-device address
01115      *
01116      * LoRaWAN Specification V1.0.2, chapter 6.1.1
01117      */
01118     uint32_t dev_addr;
01119     /** Network session key
01120      *
01121      * LoRaWAN Specification V1.0.2, chapter 6.1.3
01122      */
01123     uint8_t *nwk_skey;
01124     /** Application session key
01125      *
01126      * LoRaWAN Specification V1.0.2, chapter 6.1.4
01127      */
01128     uint8_t *app_skey;
01129 } lorawan_connect_abp_t;
01130 
01131 /**
01132  * Stack level TX message structure
01133  */
01134 typedef struct {
01135 
01136     /**
01137      * TX Ongoing flag
01138      */
01139     bool tx_ongoing;
01140 
01141     /**
01142      * Application Port Number
01143      */
01144     uint8_t port;
01145 
01146     /**
01147      * Message type
01148      */
01149     mcps_type_t type;
01150 
01151     /*!
01152      * Frame port field. Must be set if the payload is not empty. Use the
01153      * application-specific frame port values: [1...223].
01154      *
01155      * LoRaWAN Specification V1.0.2, chapter 4.3.2.
01156      */
01157     uint8_t fport ;
01158 
01159     /*!
01160      * Uplink datarate, if ADR is off.
01161      */
01162     int8_t data_rate ;
01163     /*!
01164      * The number of trials to transmit the frame, if the LoRaMAC layer did not
01165      * receive an acknowledgment. The MAC performs a datarate adaptation
01166      * according to the LoRaWAN Specification V1.0.2, chapter 18.4, as in
01167      * the following table:
01168      *
01169      * Transmission nb | Data Rate
01170      * ----------------|-----------
01171      * 1 (first)       | DR
01172      * 2               | DR
01173      * 3               | max(DR-1,0)
01174      * 4               | max(DR-1,0)
01175      * 5               | max(DR-2,0)
01176      * 6               | max(DR-2,0)
01177      * 7               | max(DR-3,0)
01178      * 8               | max(DR-3,0)
01179      *
01180      * Note that if nb_trials is set to 1 or 2, the MAC will not decrease
01181      * the datarate, if the LoRaMAC layer did not receive an acknowledgment.
01182      */
01183     uint8_t nb_trials ;
01184 
01185     /** Payload data
01186      *
01187      * Base pointer to the buffer
01188      */
01189     uint8_t f_buffer[MBED_CONF_LORA_TX_MAX_SIZE];
01190 
01191     /** Payload size.
01192      *
01193      * The size of the frame payload.
01194      */
01195     uint16_t f_buffer_size;
01196 
01197     /**
01198      * Pending data size
01199      */
01200     uint16_t pending_size;
01201 
01202 } loramac_tx_message_t;
01203 
01204 /** lora_mac_rx_message_type_t
01205  *
01206  * An enum representing a structure for RX messages.
01207  */
01208 typedef enum  {
01209     LORAMAC_RX_MLME_CONFIRM = 0,    /**< lora_mac_mlme_confirm_t */
01210     LORAMAC_RX_MCPS_CONFIRM,        /**< lora_mac_mcps_confirm_t */
01211     LORAMAC_RX_MCPS_INDICATION      /**< lora_mac_mcps_indication_t */
01212 } rx_msg_type;
01213 
01214 /** lora_mac_rx_message_by_type_t union
01215  *
01216  * A union representing a structure for RX messages.
01217  */
01218 typedef union {
01219     loramac_mlme_confirm_t  mlme_confirm;
01220     loramac_mcps_confirm_t  mcps_confirm;
01221     loramac_mcps_indication_t  mcps_indication;
01222 } rx_message_u;
01223 
01224 /** loramac_rx_message_t
01225  *
01226  * A structure representing a structure for an RX message.
01227  */
01228 typedef struct {
01229     bool receive_ready;
01230     rx_msg_type type;
01231     rx_message_u msg;
01232     uint16_t pending_size;
01233     uint16_t prev_read_size;
01234 } loramac_rx_message_t;
01235 
01236 /**
01237  * Structure to hold A list of LoRa Channels
01238  * DO NOT MODIFY, WILL BREAK THE API!
01239  */
01240 typedef struct lora_channels_s {
01241     uint8_t id;
01242     channel_params_t  ch_param;
01243 } loramac_channel_t;
01244 
01245 
01246 /** lorawan_connect_t structure
01247  *
01248  * A structure representing the parameters for different connections.
01249  */
01250 typedef struct lorawan_connect {
01251     /*!
01252      * Select the connection type, either LORAWAN_CONNECTION_OTAA
01253      * or LORAWAN_CONNECTION_ABP.
01254      */
01255     uint8_t connect_type ;
01256 
01257     union {
01258         /*!
01259          * Join the network using OTA
01260          */
01261         lorawan_connect_otaa_t otaa ;
01262         /*!
01263          * Authentication by personalization
01264          */
01265         lorawan_connect_abp_t abp ;
01266     } connection_u;
01267 
01268 } lorawan_connect_t;
01269 
01270 /** LoRaWAN session
01271  *
01272  * A structure for keeping session details.
01273  */
01274 typedef struct lorawan_session {
01275     /**
01276      * True if the session is active
01277      */
01278     bool active;
01279 
01280     lorawan_connect_t connection;
01281     /**
01282      * LoRaWAN uplink counter
01283      */
01284     uint32_t uplink_counter;
01285     /**
01286      * LoRaWAN downlink counter
01287      */
01288     uint32_t downlink_counter;
01289 } lorawan_session_t;
01290 
01291 /** Structure containing the uplink status
01292  *
01293  */
01294 typedef struct {
01295     /** Is acked
01296      *
01297      */
01298     uint8_t acked;
01299     /** Uplink data rate
01300      *
01301      */
01302     int8_t datarate;
01303     /** Uplink counter
01304      *
01305      */
01306     uint16_t uplink_counter;
01307     /** Port is used by application
01308      *
01309      */
01310     uint8_t port;
01311     /** Payload
01312      *
01313      */
01314     uint8_t *buffer;
01315     /** Payload size
01316      *
01317      */
01318     uint8_t buffer_size;
01319 } loramac_uplink_status_t;
01320 
01321 /** A structure containing the downlink status
01322  *
01323  */
01324 typedef struct {
01325     /** RSSI of downlink
01326      *
01327      */
01328     int16_t rssi;
01329     /** SNR of downlink
01330      *
01331      */
01332     int8_t snr;
01333     /** Downlink counter
01334      *
01335      */
01336     uint16_t downlink_counter;
01337     /** Is RX data received
01338      *
01339      */
01340     bool rx_data;
01341     /** Port used by application
01342      *
01343      */
01344     uint8_t port;
01345     /** Payload
01346      *
01347      */
01348     uint8_t *buffer;
01349     /** Payload size
01350      *
01351      */
01352     uint8_t buffer_size;
01353 } loramac_downlink_status_t;
01354 
01355 /*!
01356  * The parameter structure for the function for regional rx configuration.
01357  */
01358 typedef struct {
01359     /*!
01360      * The RX channel.
01361      */
01362     uint8_t channel ;
01363     /*!
01364      * The RX datarate.
01365      */
01366     uint8_t datarate ;
01367     /*!
01368      * The RX bandwidth.
01369      */
01370     uint8_t bandwidth ;
01371     /*!
01372      * The RX datarate offset.
01373      */
01374     int8_t dr_offset ;
01375     /*!
01376      * The RX frequency.
01377      */
01378     uint32_t frequency ;
01379     /*!
01380      * The RX window timeout
01381      */
01382      uint32_t window_timeout ;
01383     /*!
01384      * The RX window offset
01385      */
01386     int32_t window_offset ;
01387     /*!
01388      * The downlink dwell time.
01389      */
01390     uint8_t dl_dwell_time ;
01391     /*!
01392      * Set to true, if a repeater is supported.
01393      */
01394     bool is_repeater_supported ;
01395     /*!
01396      * Set to true, if RX should be continuous.
01397      */
01398     bool is_rx_continuous ;
01399     /*!
01400      * Sets the RX window.
01401      */
01402     rx_slot_t  rx_slot ;
01403 } rx_config_params_t ;
01404 
01405 /*!
01406  * \brief Timer object description
01407  */
01408 typedef struct {
01409     mbed::Callback<void()> callback;
01410     int timer_id;
01411 } timer_event_t;
01412 
01413 /*!
01414  * LoRaMac internal states
01415  */
01416 typedef enum {
01417     LORAMAC_IDLE          = 0x00000000,
01418     LORAMAC_TX_RUNNING    = 0x00000001,
01419     LORAMAC_RX            = 0x00000002,
01420     LORAMAC_ACK_REQ       = 0x00000004,
01421     LORAMAC_ACK_RETRY     = 0x00000008,
01422     LORAMAC_TX_DELAYED    = 0x00000010,
01423     LORAMAC_TX_CONFIG     = 0x00000020,
01424     LORAMAC_RX_ABORT      = 0x00000040,
01425 } loramac_internal_state ;
01426 
01427 typedef struct {
01428     /*!
01429      * Device IEEE EUI
01430      */
01431     uint8_t *dev_eui;
01432 
01433     /*!
01434      * Application IEEE EUI
01435      */
01436     uint8_t *app_eui;
01437 
01438     /*!
01439      * AES encryption/decryption cipher application key
01440      */
01441     uint8_t *app_key;
01442 
01443     /*!
01444      * AES encryption/decryption cipher network session key
01445      */
01446     uint8_t nwk_skey[16];
01447 
01448     /*!
01449      * AES encryption/decryption cipher application session key
01450      */
01451     uint8_t app_skey[16];
01452 
01453 } loramac_keys;
01454 
01455 typedef struct {
01456       /*!
01457        * Aggregated duty cycle management
01458        */
01459       lorawan_time_t aggregated_last_tx_time;
01460       lorawan_time_t aggregated_timeoff;
01461 
01462       /*!
01463        * Stores the time at LoRaMac initialization.
01464        *
01465        * \remark Used for the BACKOFF_DC computation.
01466        */
01467       lorawan_time_t mac_init_time;
01468 
01469 
01470       /*!
01471        * Last transmission time on air
01472        */
01473       lorawan_time_t tx_toa;
01474 
01475       /*!
01476        * LoRaMac timer used to check the LoRaMacState (runs every second)
01477        */
01478       timer_event_t mac_state_check_timer;
01479 
01480       /*!
01481        * LoRaMac duty cycle delayed Tx timer
01482        */
01483       timer_event_t tx_delayed_timer;
01484 
01485       /*!
01486        * LoRaMac reception windows timers
01487        */
01488       timer_event_t rx_window1_timer;
01489       timer_event_t rx_window2_timer;
01490 
01491       /*!
01492        * Acknowledge timeout timer. Used for packet retransmissions.
01493        */
01494       timer_event_t ack_timeout_timer;
01495 
01496 } lorawan_timers;
01497 
01498 typedef struct {
01499 
01500     /*!
01501      * Holds the type of current Receive window slot
01502      */
01503      rx_slot_t  rx_slot;
01504 
01505     /*!
01506      * Indicates if the node is connected to a private or public network
01507      */
01508     bool is_nwk_public;
01509 
01510     /*!
01511      * Indicates if the node supports repeaters
01512      */
01513     bool is_repeater_supported;
01514 
01515     /*!
01516      * IsPacketCounterFixed enables the MIC field tests by fixing the
01517      * ul_frame_counter value
01518      */
01519     bool is_ul_frame_counter_fixed;
01520 
01521     /*!
01522      * Used for test purposes. Disables the opening of the reception windows.
01523      */
01524     bool is_rx_window_enabled;
01525 
01526     /*!
01527      * Indicates if the MAC layer has already joined a network.
01528      */
01529     bool is_nwk_joined;
01530 
01531     /*!
01532      * If the node has sent a FRAME_TYPE_DATA_CONFIRMED_UP this variable indicates
01533      * if the nodes needs to manage the server acknowledgement.
01534      */
01535     bool is_node_ack_requested;
01536 
01537     /*!
01538      * If the server has sent a FRAME_TYPE_DATA_CONFIRMED_DOWN this variable indicates
01539      * if the ACK bit must be set for the next transmission
01540      */
01541     bool is_srv_ack_requested;
01542 
01543     /*!
01544      * Enables/Disables duty cycle management (Test only)
01545      */
01546     bool is_dutycycle_on;
01547 
01548     /*!
01549      * Set to true, if the last uplink was a join request
01550      */
01551     bool is_last_tx_join_request;
01552 
01553     /*!
01554      * Indicates if the AckTimeout timer has expired or not
01555      */
01556     bool is_ack_retry_timeout_expired;
01557 
01558     /*!
01559      * Current channel index
01560      */
01561     uint8_t channel;
01562 
01563     /*!
01564      * Current channel index
01565      */
01566     uint8_t last_channel_idx;
01567 
01568     /*!
01569      * Uplink messages repetitions counter
01570      */
01571     uint8_t ul_nb_rep_counter;
01572 
01573     /*!
01574      * Buffer containing the data to be sent or received.
01575      */
01576     uint8_t buffer[LORAMAC_PHY_MAXPAYLOAD];
01577 
01578     /*!
01579      * Length of packet in LoRaMacBuffer
01580      */
01581     uint16_t buffer_pkt_len;
01582 
01583     /*!
01584      * Buffer containing the upper layer data.
01585      */
01586     uint8_t payload[LORAMAC_PHY_MAXPAYLOAD];
01587 
01588     /*!
01589      * Length of the payload in LoRaMacBuffer
01590      */
01591     uint8_t payload_length;
01592 
01593     /*!
01594      * Number of trials to get a frame acknowledged
01595      */
01596     uint8_t max_ack_timeout_retries;
01597 
01598     /*!
01599      * Number of trials to get a frame acknowledged
01600      */
01601     uint8_t ack_timeout_retry_counter;
01602 
01603     /*!
01604      * Maximum number of trials for the Join Request
01605      */
01606     uint8_t max_join_request_trials;
01607 
01608     /*!
01609      * Number of trials for the Join Request
01610      */
01611     uint8_t join_request_trial_counter;
01612 
01613     /*!
01614      * Mac keys
01615      */
01616     loramac_keys keys;
01617 
01618     /*!
01619      * LoRaMac tx/rx operation state
01620      */
01621     loramac_flags_t  flags;
01622 
01623     /*!
01624      * Device nonce is a random value extracted by issuing a sequence of RSSI
01625      * measurements
01626      */
01627     uint16_t dev_nonce;
01628 
01629     /*!
01630      * Network ID ( 3 bytes )
01631      */
01632     uint32_t net_id;
01633 
01634     /*!
01635      * Mote Address
01636      */
01637     uint32_t dev_addr;
01638 
01639     /*!
01640      * LoRaMAC frame counter. Each time a packet is sent the counter is incremented.
01641      * Only the 16 LSB bits are sent
01642      */
01643     uint32_t ul_frame_counter;
01644 
01645     /*!
01646      * LoRaMAC frame counter. Each time a packet is received the counter is incremented.
01647      * Only the 16 LSB bits are received
01648      */
01649     uint32_t dl_frame_counter;
01650 
01651     /*!
01652      * Counts the number of missed ADR acknowledgements
01653      */
01654     uint32_t adr_ack_counter;
01655 
01656     /*!
01657      * LoRaMac internal state
01658      */
01659     uint32_t mac_state;
01660 
01661     /*!
01662      * LoRaMac reception windows delay
01663      * \remark normal frame: RxWindowXDelay = ReceiveDelayX - RADIO_WAKEUP_TIME
01664      *         join frame  : RxWindowXDelay = JoinAcceptDelayX - RADIO_WAKEUP_TIME
01665      */
01666     uint32_t rx_window1_delay;
01667     uint32_t rx_window2_delay;
01668 
01669     /*!
01670      * Timer objects and stored values
01671      */
01672     lorawan_timers timers;
01673 
01674     /*!
01675      * LoRaMac parameters
01676      */
01677     lora_mac_system_params_t  sys_params;
01678 
01679     /*!
01680      * Receive Window configurations for PHY layer
01681      */
01682     rx_config_params_t  rx_window1_config;
01683     rx_config_params_t  rx_window2_config;
01684 
01685     /*!
01686      * Multicast channels linked list
01687      */
01688     multicast_params_t  *multicast_channels;
01689 
01690 } loramac_protocol_params;
01691 
01692 /** LoRaWAN callback functions
01693  *
01694  */
01695 typedef enum lora_events {
01696     CONNECTED=0,
01697     DISCONNECTED,
01698     TX_DONE,
01699     TX_TIMEOUT,
01700     TX_ERROR,
01701     TX_CRYPTO_ERROR,
01702     TX_SCHEDULING_ERROR,
01703     RX_DONE,
01704     RX_TIMEOUT,
01705     RX_ERROR,
01706     JOIN_FAILURE,
01707 } lorawan_event_t;
01708 
01709 typedef struct  {
01710      // Mandatory. Event Callback must be provided
01711      mbed::Callback<void(lorawan_event_t)> events;
01712 
01713      // Rest are optional
01714      // If the user do not assign these callbacks, these callbacks would return
01715      // null if checked with bool operator
01716      // link_check_resp callback and other such callbacks will be maped in
01717      // future releases of Mbed-OS
01718      mbed::Callback<void(uint8_t, uint8_t)> link_check_resp;
01719 
01720      // Battery level callback goes in the down direction, i.e., it informs
01721      // the stack about the battery level by calling a function provided
01722      // by the upper layers
01723      mbed::Callback<uint8_t(void)> battery_level;
01724  } lorawan_app_callbacks_t;
01725 
01726 /**
01727   * DO NOT MODIFY, WILL BREAK THE API!
01728   */
01729 typedef struct lora_channelplan {
01730     uint8_t nb_channels;    // number of channels
01731     loramac_channel_t *channels;
01732 } lorawan_channelplan_t;
01733 
01734 #if defined(LORAWAN_COMPLIANCE_TEST)
01735 
01736 typedef struct {
01737     /*!
01738      * MLME-Request type.
01739      */
01740     mlme_type_t type;
01741 
01742     mlme_cw_tx_mode_t  cw_tx_mode;
01743 } loramac_mlme_req_t;
01744 
01745 typedef struct {
01746     /*!
01747      * Compliance test request
01748      */
01749     mcps_type_t type;
01750 
01751     /*!
01752      * Frame port field. Must be set if the payload is not empty. Use the
01753      * application-specific frame port values: [1...223].
01754      *
01755      * LoRaWAN Specification V1.0.2, chapter 4.3.2.
01756      */
01757     uint8_t fport;
01758 
01759     /*!
01760      * Uplink datarate, if ADR is off.
01761      */
01762     int8_t data_rate;
01763     /*!
01764      * The number of trials to transmit the frame, if the LoRaMAC layer did not
01765      * receive an acknowledgment. The MAC performs a datarate adaptation
01766      * according to the LoRaWAN Specification V1.0.2, chapter 18.4, as in
01767      * the following table:
01768      *
01769      * Transmission nb | Data Rate
01770      * ----------------|-----------
01771      * 1 (first)       | DR
01772      * 2               | DR
01773      * 3               | max(DR-1,0)
01774      * 4               | max(DR-1,0)
01775      * 5               | max(DR-2,0)
01776      * 6               | max(DR-2,0)
01777      * 7               | max(DR-3,0)
01778      * 8               | max(DR-3,0)
01779      *
01780      * Note that if nb_trials is set to 1 or 2, the MAC will not decrease
01781      * the datarate, if the LoRaMAC layer did not receive an acknowledgment.
01782      */
01783     uint8_t nb_trials;
01784 
01785     /** Payload data
01786       *
01787       * A pointer to the buffer of the frame payload.
01788       */
01789     uint8_t f_buffer[LORAMAC_PHY_MAXPAYLOAD];
01790 
01791     /** Payload size
01792      *
01793      * The size of the frame payload.
01794      */
01795     uint16_t f_buffer_size;
01796 
01797 } loramac_compliance_test_req_t;
01798 
01799 /**  LoRaWAN compliance tests support data
01800  *
01801  */
01802 typedef struct compliance_test {
01803     /** Is test running
01804      *
01805      */
01806     bool running;
01807     /** State of test
01808      *
01809      */
01810     uint8_t state;
01811     /** Is TX confirmed
01812      *
01813      */
01814     bool is_tx_confirmed;
01815     /** Port used by the application
01816      *
01817      */
01818     uint8_t app_port;
01819     /** Maximum size of data used by application
01820      *
01821      */
01822     uint8_t app_data_size;
01823     /** Data provided by application
01824      *
01825      */
01826     uint8_t app_data_buffer[MBED_CONF_LORA_TX_MAX_SIZE];
01827     /** Downlink counter
01828      *
01829      */
01830     uint16_t downlink_counter;
01831     /** Is link check required
01832      *
01833      */
01834     bool link_check;
01835     /** Demodulation margin
01836      *
01837      */
01838     uint8_t demod_margin;
01839     /** Number of gateways
01840      *
01841      */
01842     uint8_t nb_gateways;
01843 } compliance_test_t;
01844 #endif
01845 
01846 #endif /* LORAWAN_SYSTEM_LORAWAN_DATA_STRUCTURES_H_ */