LoRaMacMessageTypes.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*!
  2. * \file LoRaMacMessageTypes.h
  3. *
  4. * \brief LoRa MAC layer message type definitions
  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 Gregory Cristian ( Semtech )
  28. *
  29. * \author Daniel Jaeckle ( STACKFORCE )
  30. *
  31. * \author Johannes Bruder ( STACKFORCE )
  32. *
  33. * addtogroup LORAMAC
  34. * \{
  35. *
  36. */
  37. #ifndef __LORAMAC_MESSAGE_TYPES_H__
  38. #define __LORAMAC_MESSAGE_TYPES_H__
  39. #ifdef __cplusplus
  40. extern "C"
  41. {
  42. #endif
  43. #include <stdint.h>
  44. #include "LoRaMacHeaderTypes.h"
  45. /*! MAC header field size */
  46. #define LORAMAC_MHDR_FIELD_SIZE 1
  47. /*! Join EUI field size */
  48. #define LORAMAC_JOIN_EUI_FIELD_SIZE 8
  49. /*! Device EUI field size */
  50. #define LORAMAC_DEV_EUI_FIELD_SIZE 8
  51. /*! Join-server nonce field size */
  52. #define LORAMAC_JOIN_NONCE_FIELD_SIZE 3
  53. /*! Network ID field size */
  54. #define LORAMAC_NET_ID_FIELD_SIZE 3
  55. /*! Port field size */
  56. #define LORAMAC_F_PORT_FIELD_SIZE 1
  57. /*! CFList field size */
  58. #define LORAMAC_C_FLIST_FIELD_SIZE 16
  59. /*! MIC field size */
  60. #define LORAMAC_MIC_FIELD_SIZE 4
  61. /*! Join-request message size */
  62. #define LORAMAC_JOIN_REQ_MSG_SIZE 23
  63. /*! ReJoin-request type 1 message size */
  64. #define LORAMAC_RE_JOIN_1_MSG_SIZE 24
  65. /*! ReJoin-request type 0 or 2 message size */
  66. #define LORAMAC_RE_JOIN_0_2_MSG_SIZE 19
  67. /*!
  68. * LoRaMac type for Join-request message
  69. */
  70. typedef struct sLoRaMacMessageJoinRequest
  71. {
  72. /*!
  73. * Serialized message buffer
  74. */
  75. uint8_t* Buffer;
  76. /*!
  77. * Size of serialized message buffer
  78. */
  79. uint8_t BufSize;
  80. /*!
  81. * MAC header
  82. */
  83. LoRaMacHeader_t MHDR;
  84. /*!
  85. * Join EUI
  86. */
  87. uint8_t JoinEUI[LORAMAC_JOIN_EUI_FIELD_SIZE];
  88. /*!
  89. * Device EUI
  90. */
  91. uint8_t DevEUI[LORAMAC_DEV_EUI_FIELD_SIZE];
  92. /*!
  93. * Device Nonce
  94. */
  95. uint16_t DevNonce;
  96. /*!
  97. * Message integrity code (MIC)
  98. */
  99. uint32_t MIC;
  100. }LoRaMacMessageJoinRequest_t;
  101. /*!
  102. * LoRaMac type for rejoin-request type 1 message
  103. */
  104. typedef struct sLoRaMacMessageReJoinType1
  105. {
  106. /*!
  107. * Serialized message buffer
  108. */
  109. uint8_t* Buffer;
  110. /*!
  111. * Size of serialized message buffer
  112. */
  113. uint8_t BufSize;
  114. /*!
  115. * MAC header
  116. */
  117. LoRaMacHeader_t MHDR;
  118. /*!
  119. * Rejoin-request type ( 1 )
  120. */
  121. uint8_t ReJoinType;
  122. /*!
  123. * Join EUI
  124. */
  125. uint8_t JoinEUI[LORAMAC_JOIN_EUI_FIELD_SIZE];
  126. /*!
  127. * Device EUI
  128. */
  129. uint8_t DevEUI[LORAMAC_DEV_EUI_FIELD_SIZE];
  130. /*!
  131. * ReJoin Type 1 counter
  132. */
  133. uint16_t RJcount1;
  134. /*!
  135. * Message integrity code (MIC)
  136. */
  137. uint32_t MIC;
  138. }LoRaMacMessageReJoinType1_t;
  139. /*!
  140. * LoRaMac type for rejoin-request type 0 or 2 message
  141. */
  142. typedef struct sLoRaMacMessageReJoinType0or2
  143. {
  144. /*!
  145. * Serialized message buffer
  146. */
  147. uint8_t* Buffer;
  148. /*!
  149. * Size of serialized message buffer
  150. */
  151. uint8_t BufSize;
  152. /*!
  153. * MAC header
  154. */
  155. LoRaMacHeader_t MHDR;
  156. /*!
  157. * Rejoin-request type ( 0 or 2 )
  158. */
  159. uint8_t ReJoinType;
  160. /*!
  161. * Network ID ( 3 bytes )
  162. */
  163. uint8_t NetID[LORAMAC_NET_ID_FIELD_SIZE];
  164. /*!
  165. * Device EUI
  166. */
  167. uint8_t DevEUI[LORAMAC_DEV_EUI_FIELD_SIZE];
  168. /*!
  169. * ReJoin Type 0 and 2 frame counter
  170. */
  171. uint16_t RJcount0;
  172. /*!
  173. * Message integrity code (MIC)
  174. */
  175. uint32_t MIC;
  176. }LoRaMacMessageReJoinType0or2_t;
  177. /*!
  178. * LoRaMac type for Join-accept message
  179. */
  180. typedef struct sLoRaMacMessageJoinAccept
  181. {
  182. /*!
  183. * Serialized message buffer
  184. */
  185. uint8_t* Buffer;
  186. /*!
  187. * Size of serialized message buffer
  188. */
  189. uint8_t BufSize;
  190. /*!
  191. * MAC header
  192. */
  193. LoRaMacHeader_t MHDR;
  194. /*!
  195. * Server Nonce ( 3 bytes )
  196. */
  197. uint8_t JoinNonce[LORAMAC_JOIN_NONCE_FIELD_SIZE];
  198. /*!
  199. * Network ID ( 3 bytes )
  200. */
  201. uint8_t NetID[LORAMAC_NET_ID_FIELD_SIZE];
  202. /*!
  203. * Device address
  204. */
  205. uint32_t DevAddr;
  206. /*!
  207. * Device address
  208. */
  209. LoRaMacDLSettings_t DLSettings;
  210. /*!
  211. * Delay between TX and RX
  212. */
  213. uint8_t RxDelay;
  214. /*!
  215. * List of channel frequencies (opt.)
  216. */
  217. uint8_t CFList[16];
  218. /*!
  219. * Message integrity code (MIC)
  220. */
  221. uint32_t MIC;
  222. }LoRaMacMessageJoinAccept_t;
  223. /*!
  224. * LoRaMac type for Data MAC messages
  225. * (Unconfirmed Data Up, Confirmed Data Up, Unconfirmed Data Down, Confirmed Data Down)
  226. */
  227. typedef struct sLoRaMacMessageData
  228. {
  229. /*!
  230. * Serialized message buffer
  231. */
  232. uint8_t* Buffer;
  233. /*!
  234. * Size of serialized message buffer
  235. */
  236. uint8_t BufSize;
  237. /*!
  238. * MAC header
  239. */
  240. LoRaMacHeader_t MHDR;
  241. /*!
  242. * Frame header (FHDR)
  243. */
  244. LoRaMacFrameHeader_t FHDR;
  245. /*!
  246. * Port field (opt.)
  247. */
  248. uint8_t FPort;
  249. /*!
  250. * Frame payload may contain MAC commands or data (opt.)
  251. */
  252. uint8_t* FRMPayload;
  253. /*!
  254. * Size of frame payload (not included in LoRaMac messages)
  255. */
  256. uint8_t FRMPayloadSize;
  257. /*!
  258. * Message integrity code (MIC)
  259. */
  260. uint32_t MIC;
  261. }LoRaMacMessageData_t;
  262. /*!
  263. * LoRaMac message type enumerator
  264. */
  265. typedef enum eLoRaMacMessageType
  266. {
  267. /*!
  268. * Join-request message
  269. */
  270. LORAMAC_MSG_TYPE_JOIN_REQUEST,
  271. /*!
  272. * Rejoin-request type 1 message
  273. */
  274. LORAMAC_MSG_TYPE_RE_JOIN_1,
  275. /*!
  276. * Rejoin-request type 1 message
  277. */
  278. LORAMAC_MSG_TYPE_RE_JOIN_0_2,
  279. /*!
  280. * Join-accept message
  281. */
  282. LORAMAC_MSG_TYPE_JOIN_ACCEPT,
  283. /*!
  284. * Data MAC messages
  285. */
  286. LORAMAC_MSG_TYPE_DATA,
  287. /*!
  288. * Undefined message type
  289. */
  290. LORAMAC_MSG_TYPE_UNDEF,
  291. }LoRaMacMessageType_t;
  292. /*!
  293. * LoRaMac general message type
  294. */
  295. typedef struct sLoRaMacMessage
  296. {
  297. LoRaMacMessageType_t Type;
  298. union uMessage
  299. {
  300. LoRaMacMessageJoinRequest_t JoinReq;
  301. LoRaMacMessageReJoinType1_t ReJoin1;
  302. LoRaMacMessageReJoinType0or2_t ReJoin0or2;
  303. LoRaMacMessageJoinAccept_t JoinAccept;
  304. LoRaMacMessageData_t Data;
  305. }Message;
  306. }LoRaMacMessage_t;
  307. /*! \} addtogroup LORAMAC */
  308. #ifdef __cplusplus
  309. }
  310. #endif
  311. #endif // __LORAMAC_MESSAGE_TYPES_H__