Microchip® Advanced Software Framework

lorawan.h File Reference

LoRaWAN header file.

Copyright (c) 2019-2020 Microchip Technology Inc. and its subsidiaries.

#include <stdint.h>
#include <stdlib.h>
#include "compiler.h"
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include "stack_common.h"

Data Structures

struct  _appCbParams
 
union  _ChannelAttr
 
struct  _ChannelParameters
 
union  _DataRange
 
struct  _DevTime
 Device time value in relation to GPS Epoch. More...
 
struct  _ecrConfig
 Error Coding Configuration This structure is used to override the error coding rate in RADIO layer when transmitting the packet. More...
 
struct  _GPSEpochTime
 
struct  _LorawanLBTParams
 
struct  _LorawanMcastAppSkey
 
struct  _LorawanMcastDatarate
 
struct  _LorawanMcastDevAddr
 
struct  _LorawanMcastDlFreqeuncy
 
struct  _LorawanMcastFcnt
 
struct  _LorawanMcastNwkSkey
 
struct  _LorawanMcastPeriodicity
 
struct  _LorawanMcastStatus
 
struct  _LorawanSendReq
 
union  _LorawanStatus
 
struct  _radioConfig
 
struct  _ReceiveWindow2Params
 
union  _StackVersion_t
 
struct  _TimeOnAirParams
 
struct  AppData_t
 
union  LorawanMacStatus_t
 

Macros

#define DR0   0
 
#define DR1   1
 
#define DR10   10
 
#define DR11   11
 
#define DR12   12
 
#define DR13   13
 
#define DR14   14
 
#define DR15   15
 
#define DR2   2
 
#define DR3   3
 
#define DR4   4
 
#define DR5   5
 
#define DR6   6
 
#define DR7   7
 
#define DR8   8
 
#define DR9   9
 
#define FIRST_NIBBLE   0xF0
 
#define INFINITE_CHANNEL_RETRY   0xFFFF
 
#define LAST_NIBBLE   0x0F
 
#define LORAWAN_SESSIONKEY_LENGTH   (16)
 

Typedefs

typedef enum _ActivationType ActivationType_t
 
typedef struct _appCbParams appCbParams_t
 
typedef void(* AppDataCb_t )(void *appHandle, appCbParams_t *data)
 
typedef union _ChannelAttr ChannelAttr_t
 
typedef uint8_t ChannelId_t
 
typedef struct _ChannelParameters ChannelParameters_t
 
typedef union _DataRange DataRange_t
 
typedef struct _DevTime DevTime_t
 Device time value in relation to GPS Epoch. More...
 
typedef struct _ecrConfig ecrConfig_t
 Error Coding Configuration This structure is used to override the error coding rate in RADIO layer when transmitting the packet. More...
 
typedef enum _EdClass EdClass_t
 
typedef enum _FeaturesSupported FeaturesSupported_t
 Features Supported List. More...
 
typedef uint32_t(* FHSSCallback_t )(void)
 The radio callback typedef used to declare callback functions for registering to FHSS. More...
 
typedef struct _GPSEpochTime GPSEpochTime_t
 
typedef void(* JoinResponseCb_t )(StackRetStatus_t status)
 
typedef enum _LorawanAttributes LorawanAttributes_t
 
typedef enum _LorawanEvent LorawanEvent_t
 event indexes for application interface More...
 
typedef struct _LorawanLBTParams LorawanLBTParams_t
 
typedef struct _LorawanMcastAppSkey LorawanMcastAppSkey_t
 
typedef struct
_LorawanMcastDatarate 
LorawanMcastDatarate_t
 
typedef struct _LorawanMcastDevAddr LorawanMcastDevAddr_t
 
typedef struct
_LorawanMcastDlFreqeuncy 
LorawanMcastDlFreqeuncy_t
 
typedef struct _LorawanMcastFcnt LorawanMcastFcnt_t
 
typedef struct _LorawanMcastNwkSkey LorawanMcastNwkSkey_t
 
typedef struct
_LorawanMcastPeriodicity 
LorawanMcastPeriodicity_t
 
typedef struct _LorawanMcastStatus LorawanMcastStatus_t
 
typedef struct _LorawanSendReq LorawanSendReq_t
 
typedef union _LorawanStatus LorawanStatus_t
 
typedef enum _OpStatus OpStatus_t
 
typedef struct _radioConfig radioConfig_t
 
typedef struct
_ReceiveWindow2Params 
ReceiveWindow2Params_t
 
typedef union _StackVersion_t StackVersion_t
 
typedef struct _TimeOnAirParams TimeOnAirParams_t
 
typedef enum _TransmissionType TransmissionType_t
 

Enumerations

enum  _ActivationType {
  LORAWAN_OTAA = 0,
  LORAWAN_ABP
}
 
enum  _EdClass {
  CLASS_A = 1 << 0u,
  CLASS_B = 1 << 1u,
  CLASS_C = 1 << 2u
}
 
enum  _FeaturesSupported {
  NONE,
  DUTY_CYCLE_SUPPORT = 1 << 1u,
  LBT_SUPPORT = 1 << 2u,
  FHSS_SUPPORT = 1<< 3u,
  PA_SUPPORT = 1 << 4u,
  JOIN_BACKOFF_SUPPORT = 1 << 5u
}
 Features Supported List. More...
 
enum  _LorawanAttributes {
  DEV_EUI = 0,
  JOIN_EUI,
  DEV_ADDR,
  APP_KEY,
  NWKS_KEY,
  APPS_KEY,
  ADR,
  CURRENT_DATARATE,
  TX_POWER,
  SYNC_WORD,
  UPLINK_COUNTER,
  DOWNLINK_COUNTER,
  RX_DELAY1,
  JOINACCEPT_DELAY1,
  JOINACCEPT_DELAY2,
  MAX_FCOUNT_GAP,
  ADR_ACKLIMIT,
  ADR_ACKDELAY,
  RETRANSMITTIMEOUT,
  CNF_RETRANSMISSION_NUM,
  UNCNF_REPETITION_NUM,
  RX2_WINDOW_PARAMS,
  RXC_WINDOW_PARAMS,
  AUTOREPLY,
  BATTERY,
  LINK_CHECK_PERIOD,
  EDCLASS,
  CH_PARAM_FREQUENCY,
  CH_PARAM_DR_RANGE,
  CH_PARAM_STATUS,
  CH_PARAM_DUTYCYCLE,
  RX_DELAY2,
  AGGREGATED_DUTYCYCLE,
  LORAWAN_STATUS,
  LINK_CHECK_MARGIN,
  LINK_CHECK_GWCNT,
  ISMBAND,
  EDCLASS_SUPPORTED,
  MACVERSION,
  FHSS_CALLBACK,
  LORAWAN_LBT_PARAMS,
  MCAST_ENABLE,
  MCAST_GROUP_ADDR,
  MCAST_NWKS_KEY,
  MCAST_APPS_KEY,
  MCAST_FCNT_DOWN,
  MCAST_FCNT_DOWN_MIN,
  MCAST_FCNT_DOWN_MAX,
  MCAST_FREQUENCY,
  MCAST_DATARATE,
  MCAST_PERIODICITY,
  TEST_MODE_ENABLE,
  JOIN_BACKOFF_ENABLE,
  SUPPORTED_BANDS,
  LAST_PACKET_RSSI,
  IS_FPENDING,
  DL_ACK_REQD,
  LAST_CH_ID,
  PENDING_DUTY_CYCLE_TIME,
  RETRY_COUNTER_CNF,
  RETRY_COUNTER_UNCNF,
  NEXT_PAYLOAD_SIZE,
  PENDING_JOIN_DUTY_CYCLE_TIME,
  MAX_FCNT_PDS_UPDATE_VAL,
  CRYPTODEVICE_ENABLED,
  SEND_DEVICE_TIME_CMD,
  STACK_VERSION,
  DEVICE_GPS_EPOCH_TIME,
  PACKET_TIME_ON_AIR,
  REGIONAL_DUTY_CYCLE,
  SEND_LINK_CHECK_CMD
}
 
enum  _LorawanEvent {
  LORAWAN_EVT_TX_DONE = 1 << 0u,
  LORAWAN_EVT_RX_DATA_AVAILABLE = 1 << 1u,
  LORAWAN_EVT_TRANSACTION_COMPLETE = 1<< 2u,
  LORAWAN_EVT_UNSUPPORTED = 1 << 3u
}
 event indexes for application interface More...
 
enum  _OpStatus {
  MAC_NOT_OK = 0,
  MAC_OK,
  RADIO_NOT_OK,
  RADIO_OK,
  INVALID_BUFFER_LEN,
  RADIO_CHANNEL_BUSY,
  INVALID_FCNTR,
  MIC_ERROR,
  INVALID_MTYPE,
  MCAST_HDR_INVALID,
  NO_ACK
}
 
enum  _TransmissionType {
  LORAWAN_UNCNF = 0,
  LORAWAN_CNF
}
 

Functions

void LORAWAN_ForceEnable (void)
 Function disables the Silent Immediately state. More...
 
StackRetStatus_t LORAWAN_GetAttr (LorawanAttributes_t attrType, void *attrInput, void *attrOutput)
 LORAWAN Get Attributes This function is used to get the various Lorawan attributes. More...
 
void LORAWAN_Init (AppDataCb_t appdata, JoinResponseCb_t joindata)
 LoRaWAN Initialization function This function initializes LoRaWAN stack and the radio module. More...
 
StackRetStatus_t LORAWAN_Join (ActivationType_t activationTypeNew)
 LoRaWAN activation procedure. More...
 
uint32_t LORAWAN_Pause (void)
 Function pauses LoRaWAN stack. More...
 
bool LORAWAN_ReadyToSleep (bool deviceResetAfterSleep)
 This function returns the readiness of the stack for sleep This function is used for querying the readiness of the stack for sleep. More...
 
StackRetStatus_t LORAWAN_Reset (IsmBand_t ismBand)
 This function will automatically reset the software LoRaWAN stack and initialize it with the parameters for the selected ISM band. More...
 
void LORAWAN_Resume (void)
 Function resumes LoRaWAN stack functionality. More...
 
StackRetStatus_t LORAWAN_Send (LorawanSendReq_t *lorasendreq)
 Bidirectional communication start. More...
 
StackRetStatus_t LORAWAN_SetAttr (LorawanAttributes_t attrType, void *attrValue)
 LORAWAN Set Attribute This function is used to set the various Lorawan attributes. More...
 
void LORAWAN_SetCallbackBitmask (uint32_t evtmask)
 LoRaWAN Set Callback Bit mask function. More...
 
StackRetStatus_t LORAWAN_SetMulticastParam (LorawanAttributes_t attrType, void *attrValue)
 LORAWAN Set Multicast Param This function is used to set the various Mcast attributes specific from application. More...
 

#define DR1   1
#define DR10   10
#define DR11   11
#define DR12   12
#define DR13   13

Referenced by LORAReg_InitAU(), and LORAReg_InitNA().

#define DR14   14
#define DR15   15
#define DR3   3
#define DR4   4

Referenced by LORAReg_InitNA().

#define DR5   5
#define DR6   6

Referenced by getChBandDrT1(), and LORAReg_InitAU().

#define DR7   7

Referenced by getChBandDrT1(), and getChBandDrT2().

#define DR8   8

Referenced by LORAReg_InitAU(), and LORAReg_InitNA().

#define DR9   9
#define FIRST_NIBBLE   0xF0
#define INFINITE_CHANNEL_RETRY   0xFFFF
#define LAST_NIBBLE   0x0F
#define LORAWAN_SESSIONKEY_LENGTH   (16)

Referenced by set_multicast_params().

typedef struct _appCbParams appCbParams_t
typedef void(* AppDataCb_t)(void *appHandle, appCbParams_t *data)
typedef union _ChannelAttr ChannelAttr_t
typedef uint8_t ChannelId_t
typedef union _DataRange DataRange_t
typedef struct _DevTime DevTime_t

Device time value in relation to GPS Epoch.

This structure contains the value of GPS Epoch value and corresponding system time value when the GPS Epoch value is received by the stack

typedef struct _ecrConfig ecrConfig_t

Error Coding Configuration This structure is used to override the error coding rate in RADIO layer when transmitting the packet.

The override variable is used to inform MAC layer to SET ecr value in the structure. In general, ecr value will not be SET for every transmission.

typedef enum _EdClass EdClass_t

Features Supported List.

typedef uint32_t(* FHSSCallback_t)(void)

The radio callback typedef used to declare callback functions for registering to FHSS.

typedef struct _GPSEpochTime GPSEpochTime_t
typedef void(* JoinResponseCb_t)(StackRetStatus_t status)

event indexes for application interface

typedef enum _OpStatus OpStatus_t
typedef struct _radioConfig radioConfig_t

Enumerator
LORAWAN_OTAA 
LORAWAN_ABP 
enum _EdClass
Enumerator
CLASS_A 
CLASS_B 
CLASS_C 

Features Supported List.

Enumerator
NONE 
DUTY_CYCLE_SUPPORT 
LBT_SUPPORT 
FHSS_SUPPORT 
PA_SUPPORT 
JOIN_BACKOFF_SUPPORT 
Enumerator
DEV_EUI 
JOIN_EUI 
DEV_ADDR 
APP_KEY 
NWKS_KEY 
APPS_KEY 
ADR 
CURRENT_DATARATE 
TX_POWER 
SYNC_WORD 
UPLINK_COUNTER 
DOWNLINK_COUNTER 
RX_DELAY1 
JOINACCEPT_DELAY1 
JOINACCEPT_DELAY2 
MAX_FCOUNT_GAP 
ADR_ACKLIMIT 
ADR_ACKDELAY 
RETRANSMITTIMEOUT 
CNF_RETRANSMISSION_NUM 
UNCNF_REPETITION_NUM 
RX2_WINDOW_PARAMS 
RXC_WINDOW_PARAMS 
AUTOREPLY 
BATTERY 
LINK_CHECK_PERIOD 
EDCLASS 
CH_PARAM_FREQUENCY 
CH_PARAM_DR_RANGE 
CH_PARAM_STATUS 
CH_PARAM_DUTYCYCLE 
RX_DELAY2 
AGGREGATED_DUTYCYCLE 
LORAWAN_STATUS 
LINK_CHECK_MARGIN 
LINK_CHECK_GWCNT 
ISMBAND 
EDCLASS_SUPPORTED 
MACVERSION 
FHSS_CALLBACK 
LORAWAN_LBT_PARAMS 
MCAST_ENABLE 
MCAST_GROUP_ADDR 
MCAST_NWKS_KEY 
MCAST_APPS_KEY 
MCAST_FCNT_DOWN 
MCAST_FCNT_DOWN_MIN 
MCAST_FCNT_DOWN_MAX 
MCAST_FREQUENCY 
MCAST_DATARATE 
MCAST_PERIODICITY 
TEST_MODE_ENABLE 
JOIN_BACKOFF_ENABLE 
SUPPORTED_BANDS 
LAST_PACKET_RSSI 
IS_FPENDING 
DL_ACK_REQD 
LAST_CH_ID 
PENDING_DUTY_CYCLE_TIME 
RETRY_COUNTER_CNF 
RETRY_COUNTER_UNCNF 
NEXT_PAYLOAD_SIZE 
PENDING_JOIN_DUTY_CYCLE_TIME 
MAX_FCNT_PDS_UPDATE_VAL 
CRYPTODEVICE_ENABLED 
SEND_DEVICE_TIME_CMD 
STACK_VERSION 
DEVICE_GPS_EPOCH_TIME 
PACKET_TIME_ON_AIR 
REGIONAL_DUTY_CYCLE 
SEND_LINK_CHECK_CMD 

event indexes for application interface

Enumerator
LORAWAN_EVT_TX_DONE 
LORAWAN_EVT_RX_DATA_AVAILABLE 
LORAWAN_EVT_TRANSACTION_COMPLETE 
LORAWAN_EVT_UNSUPPORTED 
enum _OpStatus
Enumerator
MAC_NOT_OK 
MAC_OK 
RADIO_NOT_OK 
RADIO_OK 
INVALID_BUFFER_LEN 
RADIO_CHANNEL_BUSY 
INVALID_FCNTR 
MIC_ERROR 
INVALID_MTYPE 
MCAST_HDR_INVALID 
NO_ACK 
Enumerator
LORAWAN_UNCNF 
LORAWAN_CNF 

void LORAWAN_ForceEnable ( void  )

Function disables the Silent Immediately state.

The network can issue a certain command that would require the end device to go silent immediately. This mechanism disables any further communication of the module, effectively isolating it from the network. Using this function, after this network command has been received, restores the modules connectivity by allowing it to send data. None None None

StackRetStatus_t LORAWAN_GetAttr ( LorawanAttributes_t  attrType,
void *  attrInput,
void *  attrOutput 
)

LORAWAN Get Attributes This function is used to get the various Lorawan attributes.

None attrType - represents the attribute type; can be any of the parameters in LorawanAttributes_t attrInput - pointer to the sub-parameter/index of attribute in an array for example to get CH_PARAM_FREQUENCY, channel index is given as input attribute attrOutput - pointer containing the attribute value The error condition for getting a given attribute.

Referenced by cert_app_timer_callback(), cert_appdata_callback(), cert_joindata_callback(), demo_joindata_callback(), enddevice_cpc_execute_command(), messageGetIdByGroupAddr(), messageIsDutyCyclePending(), messageReceiveProcess(), messageSendProcess(), mote_demo_init(), MSG_IsTxPossible(), print_application_config(), processRunRestoreBand(), processRxDataAvailable(), processTransactionComplete(), and set_multicast_params().

void LORAWAN_Init ( AppDataCb_t  appdata,
JoinResponseCb_t  joindata 
)

LoRaWAN Initialization function This function initializes LoRaWAN stack and the radio module.

None appdata - pointer to function that gets called after the bidirectional communication ended. joindata - pointer to function that gets called after the activation procedure None

Referenced by cert_app_init(), and mote_demo_init().

StackRetStatus_t LORAWAN_Join ( ActivationType_t  activationTypeNew)

LoRaWAN activation procedure.

This function starts LoRaWAN activation procedure. None activationTypeNew - activation type: OTAA or ABP Function returns the status of the operation (StackRetStatus_t).

Referenced by cert_app_init(), cert_handle_cert_rx_data(), cert_joindata_callback(), enddevice_cpc_fresh_join(), mote_set_parameters(), and processJoinAndSend().

uint32_t LORAWAN_Pause ( void  )

Function pauses LoRaWAN stack.

This function pauses the LoRaWAN stack functionality to allow transceiver (radio) configuration. Through the use of "mac pause", radio commands can be generated between a LoRaWAN protocol uplink application, and the LoRaWAN protocol Receive windows. This function will reply with the time interval in milliseconds that the transceiver can be used without affecting the LoRaWAN functionality. None None Returns the number in milliseconds representing how much it can be paused without affecting the functionality. Returns 0 if it cannot be paused, maximum value when in idle mode.

bool LORAWAN_ReadyToSleep ( bool  deviceResetAfterSleep)

This function returns the readiness of the stack for sleep This function is used for querying the readiness of the stack for sleep.

This function has dependency on RADIO for corresponding readiness check function in TAL. None – 'true' means device will reset during wakeup 'false' means device does not reset during wakeup 'true' if stack is in ready state for sleep, otherwise 'false' bool status = LORAWAN_ReadyToSleep(false);

Referenced by processJoinAndSend().

StackRetStatus_t LORAWAN_Reset ( IsmBand_t  ismBand)

This function will automatically reset the software LoRaWAN stack and initialize it with the parameters for the selected ISM band.

This command will set default values for most of the LoRaWAN parameters. Everything set prior to this command will lose its set value, being reinitialized to the default value, including setting the cryptographic keys to 0. None none The success/failure condition for the reset request

Referenced by cert_select_band(), enddevice_cpc_fresh_join(), mote_set_parameters(), processRunDemoApp(), and processRunRestoreBand().

void LORAWAN_Resume ( void  )

Function resumes LoRaWAN stack functionality.

This function resumes LoRaWAN stack functionality, in order to continue normal functionality after being paused. None None None

StackRetStatus_t LORAWAN_Send ( LorawanSendReq_t lorasendreq)

Bidirectional communication start.

This function starts a bidirectional communication process. None confirmed - represents the transmission type; can be either UNCNF - unconfirmed or CNF - confirmed (TransmissionType_t) port - represents the port on which the transmission is being made; it's a number between 0 and 255 (uint8_t) buffer - a data buffer used to store the data to be sent bufferLength - the length in bytes of the data buffer (uint8_t) Function returns the status of the operation (StackRetStatus_t). uint8_t dataToSend = 45; LORAWAN_Send (UNCNF, 20, &dataToSend, sizeof(dataToSend));

Referenced by cert_app_timer_callback(), and messageSendProcess().

StackRetStatus_t LORAWAN_SetAttr ( LorawanAttributes_t  attrType,
void *  attrValue 
)

LORAWAN Set Attribute This function is used to set the various Lorawan attributes.

None attrType - represents the attribute type; can be any of the parameters in (LorawanAttributes_t) attrValue - pointer that is used to get the attribute value The error condition for getting a given attribute.

Referenced by cert_app_timer_callback(), cert_enable_channels(), cert_set_join_parameters(), cert_set_mac_parameters(), enddevice_cpc_execute_command(), enddevice_cpc_fresh_join(), mote_set_parameters(), processRunRestoreBand(), set_device_type(), set_join_parameters(), and set_multicast_params().

void LORAWAN_SetCallbackBitmask ( uint32_t  evtmask)

LoRaWAN Set Callback Bit mask function.

This function is used for enabling the particular callback from MAC to application None evtmask - Bit mask of the particular callback none LORAWAN_SetCallbackBitmask(LORAWAN_EVT_RX_DATA_AVAILABLE|LORAWAN_EVT_TRANSACTION_COMPLETE);

StackRetStatus_t LORAWAN_SetMulticastParam ( LorawanAttributes_t  attrType,
void *  attrValue 
)

LORAWAN Set Multicast Param This function is used to set the various Mcast attributes specific from application.

None attrType - represents the attribute type; can be any of the MCAST parameters in (LorawanAttributes_t) attrValue - pointer that is used to get the attribute value The error condition for getting a given attribute.

Referenced by set_multicast_params().