LoRaMacCommands.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. #ifdef __cplusplus
  38. extern "C"
  39. {
  40. #endif
  41. #include <stdint.h>
  42. #include <stddef.h>
  43. #include "LoRaMacTypes.h"
  44. /*
  45. * Number of MAC Command slots
  46. */
  47. #define LORAMAC_COMMADS_MAX_NUM_OF_PARAMS 2
  48. /*!
  49. * LoRaWAN MAC Command element
  50. */
  51. typedef struct sMacCommand MacCommand_t;
  52. struct sMacCommand
  53. {
  54. /*!
  55. * The pointer to the next MAC Command element in the list
  56. */
  57. MacCommand_t* Next;
  58. /*!
  59. * MAC command identifier
  60. */
  61. uint8_t CID;
  62. /*!
  63. * MAC command payload
  64. */
  65. uint8_t Payload[LORAMAC_COMMADS_MAX_NUM_OF_PARAMS];
  66. /*!
  67. * Size of MAC command payload
  68. */
  69. size_t PayloadSize;
  70. /*!
  71. * Indicates if it's a sticky MAC command
  72. */
  73. bool IsSticky;
  74. };
  75. /*!
  76. * LoRaMac Commands Status
  77. */
  78. typedef enum eLoRaMacCommandsStatus
  79. {
  80. /*!
  81. * No error occurred
  82. */
  83. LORAMAC_COMMANDS_SUCCESS = 0,
  84. /*!
  85. * Null pointer exception
  86. */
  87. LORAMAC_COMMANDS_ERROR_NPE,
  88. /*!
  89. * There is no memory left to add a further MAC command
  90. */
  91. LORAMAC_COMMANDS_ERROR_MEMORY,
  92. /*!
  93. * MAC command not found.
  94. */
  95. LORAMAC_COMMANDS_ERROR_CMD_NOT_FOUND,
  96. /*!
  97. * Unknown or corrupted command error occurred.
  98. */
  99. LORAMAC_COMMANDS_ERROR_UNKNOWN_CMD,
  100. /*!
  101. * Undefined Error occurred
  102. */
  103. LORAMAC_COMMANDS_ERROR,
  104. }LoRaMacCommandStatus_t;
  105. /*!
  106. * Signature of callback function to be called by this module when the
  107. * non-volatile needs to be saved.
  108. */
  109. typedef void ( *LoRaMacCommandsNvmEvent )( void );
  110. /*!
  111. * \brief Initialization of LoRaMac MAC commands module
  112. *
  113. * \param[IN] commandsNvmCtxChanged - Callback function which will be called when the
  114. * non-volatile context needs to be saved.
  115. *
  116. * \retval - Status of the operation
  117. */
  118. LoRaMacCommandStatus_t LoRaMacCommandsInit( LoRaMacCommandsNvmEvent commandsNvmCtxChanged );
  119. /*!
  120. * Restores the internal non-volatile context from passed pointer.
  121. *
  122. * \param[IN] commandsNvmCtx - Pointer to non-volatile MAC commands module context to be restored.
  123. *
  124. * \retval - Status of the operation
  125. */
  126. LoRaMacCommandStatus_t LoRaMacCommandsRestoreNvmCtx( void* commandsNvmCtx );
  127. /*!
  128. * Returns a pointer to the internal non-volatile context.
  129. *
  130. * \param[IN] commandsNvmCtxSize - Size of the module non-volatile context
  131. *
  132. * \retval - Points to a structure where the module store its non-volatile context
  133. */
  134. void* LoRaMacCommandsGetNvmCtx( size_t* commandsNvmCtxSize );
  135. /*!
  136. * \brief Adds a new MAC command to be sent.
  137. *
  138. * \param[IN] cid - MAC command identifier
  139. * \param[IN] payload - MAC command payload containing parameters
  140. * \param[IN] payloadSize - Size of MAC command payload
  141. *
  142. * \retval - Status of the operation
  143. */
  144. LoRaMacCommandStatus_t LoRaMacCommandsAddCmd( uint8_t cid, uint8_t* payload, size_t payloadSize );
  145. /*!
  146. * \brief Remove a MAC command.
  147. *
  148. * \param[OUT] cmd - MAC command
  149. *
  150. * \retval - Status of the operation
  151. */
  152. LoRaMacCommandStatus_t LoRaMacCommandsRemoveCmd( MacCommand_t* macCmd );
  153. /*!
  154. * \brief Get the MAC command with corresponding CID.
  155. *
  156. * \param[IN] cid - MAC command identifier
  157. * \param[OUT] cmd - MAC command
  158. *
  159. * \retval - Status of the operation
  160. */
  161. LoRaMacCommandStatus_t LoRaMacCommandsGetCmd( uint8_t cid, MacCommand_t** macCmd );
  162. /*!
  163. * \brief Remove all none sticky MAC commands.
  164. *
  165. * \retval - Status of the operation
  166. */
  167. LoRaMacCommandStatus_t LoRaMacCommandsRemoveNoneStickyCmds( void );
  168. /*!
  169. * \brief Remove all sticky answer MAC commands.
  170. *
  171. * \retval - Status of the operation
  172. */
  173. LoRaMacCommandStatus_t LoRaMacCommandsRemoveStickyAnsCmds( void );
  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. * \brief Get as many as possible MAC commands serialized
  184. *
  185. * \param[IN] availableSize - Available size of memory for MAC commands
  186. * \param[out] effectiveSize - Size of memory which was effectively used for serializing.
  187. * \param[out] buffer - Destination data buffer
  188. *
  189. * \retval - Status of the operation
  190. */
  191. LoRaMacCommandStatus_t LoRaMacCommandsSerializeCmds( size_t availableSize, size_t* effectiveSize, uint8_t* buffer );
  192. /*!
  193. * \brief Determines if there are sticky MAC commands pending.
  194. *
  195. * \param[IN] cmdsPending - Indicates if there are sticky MAC commands in the queue.
  196. *
  197. * \retval - Status of the operation
  198. */
  199. LoRaMacCommandStatus_t LoRaMacCommandsStickyCmdsPending( bool* cmdsPending );
  200. /*! \} addtogroup LORAMAC */
  201. #ifdef __cplusplus
  202. }
  203. #endif
  204. #endif // __LORAMAC_COMMANDS_H__