LoRaMacHeaderTypes.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*!
  2. * \file LoRaMacHeaderTypes.h
  3. *
  4. * \brief LoRa MAC layer header 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_HEADER_TYPES_H__
  38. #define __LORAMAC_HEADER_TYPES_H__
  39. #ifdef __cplusplus
  40. extern "C"
  41. {
  42. #endif
  43. #include <stdint.h>
  44. /*! Frame header (FHDR) maximum field size */
  45. #define LORAMAC_FHDR_MAX_FIELD_SIZE 22
  46. /*! FHDR Device address field size */
  47. #define LORAMAC_FHDR_DEV_ADD_FIELD_SIZE 4
  48. /*! FHDR Frame control field size */
  49. #define LORAMAC_FHDR_F_CTRL_FIELD_SIZE 1
  50. /*! FHDR Frame control field size */
  51. #define LORAMAC_FHDR_F_CNT_FIELD_SIZE 2
  52. /*! FOpts maximum field size */
  53. #define LORAMAC_FHDR_F_OPTS_MAX_FIELD_SIZE 15
  54. /*!
  55. * LoRaMAC field definition of DLSettings
  56. *
  57. * LoRaWAN Specification V1.0.2, chapter 5.4
  58. */
  59. typedef union uLoRaMacDLSettings
  60. {
  61. /*!
  62. * Byte-access to the bits
  63. */
  64. uint8_t Value;
  65. /*!
  66. * Structure containing single access to header bits
  67. */
  68. struct sDLSettingsBits
  69. {
  70. /*!
  71. * Data rate of a downlink using the second receive window
  72. */
  73. uint8_t RX2DataRate : 4;
  74. /*!
  75. * Offset between up and downlink datarate of first reception slot
  76. */
  77. uint8_t RX1DRoffset : 3;
  78. /*!
  79. * Indicates network server LoRaWAN implementation version 1.1 or later.
  80. */
  81. uint8_t OptNeg : 1;
  82. }Bits;
  83. }LoRaMacDLSettings_t;
  84. /*!
  85. * LoRaMAC header field definition (MHDR field)
  86. *
  87. * LoRaWAN Specification V1.0.2, chapter 4.2
  88. */
  89. typedef union uLoRaMacHeader
  90. {
  91. /*!
  92. * Byte-access to the bits
  93. */
  94. uint8_t Value;
  95. /*!
  96. * Structure containing single access to header bits
  97. */
  98. struct sMacHeaderBits
  99. {
  100. /*!
  101. * Major version
  102. */
  103. uint8_t Major : 2;
  104. /*!
  105. * RFU
  106. */
  107. uint8_t RFU : 3;
  108. /*!
  109. * Message type
  110. */
  111. uint8_t MType : 3;
  112. }Bits;
  113. }LoRaMacHeader_t;
  114. /*!
  115. * LoRaMAC frame control field definition (FCtrl)
  116. *
  117. * LoRaWAN Specification V1.0.2, chapter 4.3.1
  118. */
  119. typedef union uLoRaMacFrameCtrl
  120. {
  121. /*!
  122. * Byte-access to the bits
  123. */
  124. uint8_t Value;
  125. /*!
  126. * Structure containing single access to bits
  127. */
  128. struct sCtrlBits
  129. {
  130. /*!
  131. * Frame options length
  132. */
  133. uint8_t FOptsLen : 4;
  134. /*!
  135. * Frame pending bit
  136. */
  137. uint8_t FPending : 1;
  138. /*!
  139. * Message acknowledge bit
  140. */
  141. uint8_t Ack : 1;
  142. /*!
  143. * ADR acknowledgment request bit
  144. */
  145. uint8_t AdrAckReq : 1;
  146. /*!
  147. * ADR control in frame header
  148. */
  149. uint8_t Adr : 1;
  150. }Bits;
  151. }LoRaMacFrameCtrl_t;
  152. /*!
  153. * LoRaMac Frame header (FHDR)
  154. *
  155. * LoRaWAN Specification V1.0.2, chapter 4.3.1
  156. */
  157. typedef struct sLoRaMacFrameHeader
  158. {
  159. /*!
  160. * Device address
  161. */
  162. uint32_t DevAddr;
  163. /*!
  164. * Frame control field
  165. */
  166. LoRaMacFrameCtrl_t FCtrl;
  167. /*!
  168. * Frame counter
  169. */
  170. uint16_t FCnt;
  171. /*!
  172. * FOpts field may transport MAC commands (opt. 0-15 Bytes)
  173. */
  174. uint8_t FOpts[LORAMAC_FHDR_F_OPTS_MAX_FIELD_SIZE];
  175. }LoRaMacFrameHeader_t;
  176. /*! \} addtogroup LORAMAC */
  177. #ifdef __cplusplus
  178. }
  179. #endif
  180. #endif // __LORAMAC_HEADER_TYPES_H__