1 /*! 2 * \file LoRaMacCommands.h 3 * 4 * \brief LoRa MAC commands 5 * 6 * \copyright Revised BSD License, see section \ref LICENSE. 7 * 8 * \code 9 * ______ _ 10 * / _____) _ | | 11 * ( (____ _____ ____ _| |_ _____ ____| |__ 12 * \____ \| ___ | (_ _) ___ |/ ___) _ \ 13 * _____) ) ____| | | || |_| ____( (___| | | | 14 * (______/|_____)_|_|_| \__)_____)\____)_| |_| 15 * (C)2013 Semtech 16 * 17 * ___ _____ _ ___ _ _____ ___ ___ ___ ___ 18 * / __|_ _/_\ / __| |/ / __/ _ \| _ \/ __| __| 19 * \__ \ | |/ _ \ (__| ' <| _| (_) | / (__| _| 20 * |___/ |_/_/ \_\___|_|\_\_| \___/|_|_\\___|___| 21 * embedded.connectivity.solutions=============== 22 * 23 * \endcode 24 * 25 * \author Miguel Luis ( Semtech ) 26 * 27 * \author Daniel Jaeckle ( STACKFORCE ) 28 * 29 * \author Johannes Bruder ( STACKFORCE ) 30 * 31 * addtogroup LORAMAC 32 * \{ 33 * 34 */ 35 #ifndef __LORAMAC_COMMANDS_H__ 36 #define __LORAMAC_COMMANDS_H__ 37 38 #ifdef __cplusplus 39 extern "C" 40 { 41 #endif 42 43 #include <stdint.h> 44 #include <stddef.h> 45 #include "LoRaMacTypes.h" 46 47 48 /* 49 * Number of MAC Command slots 50 */ 51 #define LORAMAC_COMMADS_MAX_NUM_OF_PARAMS 2 52 53 /*! 54 * LoRaWAN MAC Command element 55 */ 56 typedef struct sMacCommand MacCommand_t; 57 58 struct sMacCommand 59 { 60 /*! 61 * The pointer to the next MAC Command element in the list 62 */ 63 MacCommand_t* Next; 64 /*! 65 * MAC command identifier 66 */ 67 uint8_t CID; 68 /*! 69 * MAC command payload 70 */ 71 uint8_t Payload[LORAMAC_COMMADS_MAX_NUM_OF_PARAMS]; 72 /*! 73 * Size of MAC command payload 74 */ 75 size_t PayloadSize; 76 /*! 77 * Indicates if it's a sticky MAC command 78 */ 79 bool IsSticky; 80 /*! 81 * The command requires an explicit confirmation 82 */ 83 bool IsConfirmationRequired; 84 }; 85 86 /*! 87 * LoRaMac Commands Status 88 */ 89 typedef enum eLoRaMacCommandsStatus 90 { 91 /*! 92 * No error occurred 93 */ 94 LORAMAC_COMMANDS_SUCCESS = 0, 95 /*! 96 * Null pointer exception 97 */ 98 LORAMAC_COMMANDS_ERROR_NPE, 99 /*! 100 * There is no memory left to add a further MAC command 101 */ 102 LORAMAC_COMMANDS_ERROR_MEMORY, 103 /*! 104 * MAC command not found. 105 */ 106 LORAMAC_COMMANDS_ERROR_CMD_NOT_FOUND, 107 /*! 108 * Unknown or corrupted command error occurred. 109 */ 110 LORAMAC_COMMANDS_ERROR_UNKNOWN_CMD, 111 /*! 112 * Undefined Error occurred 113 */ 114 LORAMAC_COMMANDS_ERROR, 115 }LoRaMacCommandStatus_t; 116 117 /*! 118 * Signature of callback function to be called by this module when the 119 * non-volatile needs to be saved. 120 */ 121 typedef void ( *LoRaMacCommandsNvmEvent )( void ); 122 123 /*! 124 * \brief Initialization of LoRaMac MAC commands module 125 * 126 * \retval - Status of the operation 127 */ 128 LoRaMacCommandStatus_t LoRaMacCommandsInit( void ); 129 130 /*! 131 * \brief Adds a new MAC command to be sent. 132 * 133 * \param[IN] cid - MAC command identifier 134 * \param[IN] payload - MAC command payload containing parameters 135 * \param[IN] payloadSize - Size of MAC command payload 136 * 137 * \retval - Status of the operation 138 */ 139 LoRaMacCommandStatus_t LoRaMacCommandsAddCmd( uint8_t cid, uint8_t* payload, size_t payloadSize ); 140 141 /*! 142 * \brief Remove a MAC command. 143 * 144 * \param[OUT] cmd - MAC command 145 * 146 * \retval - Status of the operation 147 */ 148 LoRaMacCommandStatus_t LoRaMacCommandsRemoveCmd( MacCommand_t* macCmd ); 149 150 /*! 151 * \brief Get the MAC command with corresponding CID. 152 * 153 * \param[IN] cid - MAC command identifier 154 * \param[OUT] cmd - MAC command 155 * 156 * \retval - Status of the operation 157 */ 158 LoRaMacCommandStatus_t LoRaMacCommandsGetCmd( uint8_t cid, MacCommand_t** macCmd ); 159 160 /*! 161 * \brief Remove all none sticky MAC commands. 162 * 163 * \retval - Status of the operation 164 */ 165 LoRaMacCommandStatus_t LoRaMacCommandsRemoveNoneStickyCmds( void ); 166 167 /*! 168 * \brief Remove all sticky answer MAC commands. 169 * 170 * \retval - Status of the operation 171 */ 172 LoRaMacCommandStatus_t LoRaMacCommandsRemoveStickyAnsCmds( void ); 173 174 /*! 175 * \brief Get size of all MAC commands serialized as buffer 176 * 177 * \param[out] size - Available size of memory for MAC commands 178 * 179 * \retval - Status of the operation 180 */ 181 LoRaMacCommandStatus_t LoRaMacCommandsGetSizeSerializedCmds( size_t* size ); 182 183 /*! 184 * \brief Get as many as possible MAC commands serialized 185 * 186 * \param[IN] availableSize - Available size of memory for MAC commands 187 * \param[out] effectiveSize - Size of memory which was effectively used for serializing. 188 * \param[out] buffer - Destination data buffer 189 * 190 * \retval - Status of the operation 191 */ 192 LoRaMacCommandStatus_t LoRaMacCommandsSerializeCmds( size_t availableSize, size_t* effectiveSize, uint8_t* buffer ); 193 194 /*! 195 * \brief Get the MAC command size with corresponding CID. 196 * 197 * \param[IN] cid - MAC command identifier 198 * 199 * \retval Size of the command. 200 */ 201 uint8_t LoRaMacCommandsGetCmdSize( uint8_t cid ); 202 203 /*! \} addtogroup LORAMAC */ 204 205 #ifdef __cplusplus 206 } 207 #endif 208 209 #endif // __LORAMAC_COMMANDS_H__ 210 211