mac_spec.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /**************************************************************************************************
  2. Filename: mac_spec.h
  3. Revised: $Date: 2011-02-28 16:59:59 -0800 (Mon, 28 Feb 2011) $
  4. Revision: $Revision: 25230 $
  5. Description: This file contains constants and other data defined by the 802.15.4 spec.
  6. Copyright 2005-2010 Texas Instruments Incorporated. All rights reserved.
  7. IMPORTANT: Your use of this Software is limited to those specific rights
  8. granted under the terms of a software license agreement between the user
  9. who downloaded the software, his/her employer (which must be your employer)
  10. and Texas Instruments Incorporated (the "License"). You may not use this
  11. Software unless you agree to abide by the terms of the License. The License
  12. limits your use, and you acknowledge, that the Software may not be modified,
  13. copied or distributed unless embedded on a Texas Instruments microcontroller
  14. or used solely and exclusively in conjunction with a Texas Instruments radio
  15. frequency transceiver, which is integrated into your product. Other than for
  16. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  17. works of, modify, distribute, perform, display or sell this Software and/or
  18. its documentation for any purpose.
  19. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  20. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  21. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  22. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  23. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  24. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  25. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  26. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  27. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  28. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  29. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  30. Should you have any questions regarding your right to use this Software,
  31. contact Texas Instruments Incorporated at www.TI.com.
  32. **************************************************************************************************/
  33. #ifndef MAC_SPEC_H
  34. #define MAC_SPEC_H
  35. /* ------------------------------------------------------------------------------------------------
  36. * Constants
  37. * ------------------------------------------------------------------------------------------------
  38. */
  39. /* PHY packet fields lengths in bytes */
  40. #define MAC_PHY_SHR_LEN 5 /* preamble bytes plus SFD byte */
  41. #define MAC_PHY_PHR_LEN 1 /* length byte */
  42. /* MAC frame field lengths in bytes */
  43. #define MAC_FCF_FIELD_LEN 2 /* frame control field */
  44. #define MAC_SEQ_NUM_FIELD_LEN 1 /* sequence number */
  45. #define MAC_PAN_ID_FIELD_LEN 2 /* PAN ID */
  46. #define MAC_EXT_ADDR_FIELD_LEN 8 /* Extended address */
  47. #define MAC_SHORT_ADDR_FIELD_LEN 2 /* Short address */
  48. #define MAC_FCS_FIELD_LEN 2 /* FCS field */
  49. #define MAC_SEC_CONTROL_FIELD_LEN 1 /* Security control field */
  50. /* Frame offsets in bytes */
  51. #define MAC_FCF_OFFSET 0 /* offset to frame control field */
  52. #define MAC_SEQ_NUM_OFFSET 2 /* offset to sequence number */
  53. #define MAC_DEST_PAN_ID_OFFSET 3 /* offset to destination PAN ID */
  54. #define MAC_DEST_ADDR_OFFSET 5 /* offset to destination address */
  55. /* Frame control field bit masks */
  56. #define MAC_FCF_FRAME_TYPE_MASK 0x0007
  57. #define MAC_FCF_SEC_ENABLED_MASK 0x0008
  58. #define MAC_FCF_FRAME_PENDING_MASK 0x0010
  59. #define MAC_FCF_ACK_REQUEST_MASK 0x0020
  60. #define MAC_FCF_INTRA_PAN_MASK 0x0040
  61. #define MAC_FCF_DST_ADDR_MODE_MASK 0x0C00
  62. #define MAC_FCF_FRAME_VERSION_MASK 0x3000
  63. #define MAC_FCF_SRC_ADDR_MODE_MASK 0xC000
  64. /* Frame control field bit positions */
  65. #define MAC_FCF_FRAME_TYPE_POS 0
  66. #define MAC_FCF_SEC_ENABLED_POS 3
  67. #define MAC_FCF_FRAME_PENDING_POS 4
  68. #define MAC_FCF_ACK_REQUEST_POS 5
  69. #define MAC_FCF_INTRA_PAN_POS 6
  70. #define MAC_FCF_DST_ADDR_MODE_POS 10
  71. #define MAC_FCF_FRAME_VERSION_POS 12
  72. #define MAC_FCF_SRC_ADDR_MODE_POS 14
  73. /* Security control field bit masks */
  74. #define MAC_SCF_SECURITY_LEVEL_MASK 0x07
  75. #define MAC_SCF_KEY_IDENTIFIER_MASK 0x18
  76. /* Security control field bit positions */
  77. #define MAC_SCF_SECURITY_LEVEL_POS 0
  78. #define MAC_SCF_KEY_IDENTIFIER_POS 3
  79. /* MAC Payload offsets in bytes */
  80. #define MAC_SFS_OFFSET 0
  81. #define MAC_PENDING_ADDR_OFFSET 3 /* if GTS is not in use */
  82. /* Beacon superframe spec bit positions, low byte */
  83. #define MAC_SFS_BEACON_ORDER_POS 0
  84. #define MAC_SFS_SUPERFRAME_ORDER_POS 4
  85. /* Beacon superframe spec bit positions, high byte */
  86. #define MAC_SFS_FINAL_CAP_SLOT_POS 0
  87. #define MAC_SFS_BATT_LIFE_EXT_POS 4
  88. #define MAC_SFS_PAN_COORD_POS 6
  89. #define MAC_SFS_ASSOC_PERMIT_POS 7
  90. /* Frame type */
  91. #define MAC_FRAME_TYPE_BEACON 0
  92. #define MAC_FRAME_TYPE_DATA 1
  93. #define MAC_FRAME_TYPE_ACK 2
  94. #define MAC_FRAME_TYPE_COMMAND 3
  95. #define MAC_FRAME_TYPE_MAX_VALID MAC_FRAME_TYPE_COMMAND
  96. /* Command frame identifiers */
  97. #define MAC_ASSOC_REQ_FRAME 1
  98. #define MAC_ASSOC_RSP_FRAME 2
  99. #define MAC_DISASSOC_NOTIF_FRAME 3
  100. #define MAC_DATA_REQ_FRAME 4
  101. #define MAC_PAN_CONFLICT_FRAME 5
  102. #define MAC_ORPHAN_NOTIF_FRAME 6
  103. #define MAC_BEACON_REQ_FRAME 7
  104. #define MAC_COORD_REALIGN_FRAME 8
  105. #define MAC_GTS_REQ_FRAME 9
  106. /* Length of command frame payload (includes command ID byte) */
  107. #define MAC_ZERO_DATA_PAYLOAD 0
  108. #define MAC_ASSOC_REQ_PAYLOAD 2
  109. #define MAC_ASSOC_RSP_PAYLOAD 4
  110. #define MAC_DISASSOC_NOTIF_PAYLOAD 2
  111. #define MAC_DATA_REQ_PAYLOAD 1
  112. #define MAC_PAN_CONFLICT_PAYLOAD 1
  113. #define MAC_ORPHAN_NOTIF_PAYLOAD 1
  114. #define MAC_BEACON_REQ_PAYLOAD 1
  115. #define MAC_COORD_REALIGN_PAYLOAD 9
  116. #define MAC_GTS_REQ_PAYLOAD 2
  117. /* Length of command frames (max header plus payload) */
  118. #define MAC_ZERO_DATA_FRAME_LEN (21 + MAC_ZERO_DATA_PAYLOAD)
  119. #define MAC_ASSOC_REQ_FRAME_LEN (23 + MAC_ASSOC_REQ_PAYLOAD)
  120. #define MAC_ASSOC_RSP_FRAME_LEN (23 + MAC_ASSOC_RSP_PAYLOAD)
  121. #define MAC_DISASSOC_NOTIF_FRAME_LEN (17 + MAC_DISASSOC_NOTIF_PAYLOAD)
  122. #define MAC_DATA_REQ_FRAME_LEN (23 + MAC_DATA_REQ_PAYLOAD)
  123. #define MAC_PAN_CONFLICT_FRAME_LEN (23 + MAC_PAN_CONFLICT_PAYLOAD)
  124. #define MAC_ORPHAN_NOTIF_FRAME_LEN (17 + MAC_ORPHAN_NOTIF_PAYLOAD)
  125. #define MAC_BEACON_REQ_FRAME_LEN (7 + MAC_BEACON_REQ_PAYLOAD)
  126. #define MAC_COORD_REALIGN_FRAME_LEN (23 + MAC_COORD_REALIGN_PAYLOAD)
  127. #define MAC_GTS_REQ_FRAME_LEN (7 + MAC_GTS_REQ_PAYLOAD)
  128. /* Beacon frame base length (max header plus minimum payload) */
  129. #define MAC_BEACON_FRAME_BASE_LEN (13 + 4)
  130. /* Maximum number of pending addresses in a beacon */
  131. #define MAC_PEND_ADDR_MAX 7
  132. /* Associate response command frame status values */
  133. #define MAC_ASSOC_SUCCESS 0 /* association successful */
  134. #define MAC_ASSOC_CAPACITY 1 /* PAN at capacity */
  135. #define MAC_ASSOC_DENIED 2 /* PAN access denied */
  136. /* Beacon order and superframe order maximum values */
  137. #define MAC_BO_NON_BEACON 15
  138. #define MAC_SO_NONE 15
  139. /* Broadcast PAN ID */
  140. #define MAC_PAN_ID_BROADCAST 0xFFFF
  141. /* Number of symbols per octet */
  142. #define MAC_SYMBOLS_PER_OCTET 2
  143. /* Maximum phy frame size in bytes */
  144. #define MAC_A_MAX_PHY_PACKET_SIZE 127
  145. /* Phy RX <--> TX turnaround time in symbols */
  146. #define MAC_A_TURNAROUND_TIME 12
  147. /* Number of backoffs forming a superframe slot when the superframe order is equal to 0 */
  148. #define MAC_A_BASE_SLOT_DURATION 3
  149. /* Number of backoffs forming a superframe when the superframe order is equal to 0 */
  150. #define MAC_A_BASE_SUPERFRAME_DURATION (MAC_A_BASE_SLOT_DURATION * MAC_A_NUM_SUPERFRAME_SLOTS)
  151. /* Maximum number of bytes added by the MAC sublayer to the payload of its beacon frame */
  152. #define MAC_A_MAX_BEACON_OVERHEAD 75
  153. /* Maximum size in bytes of a beacon payload */
  154. #define MAC_A_MAX_BEACON_PAYLOAD_LENGTH (MAC_A_MAX_PHY_PACKET_SIZE - MAC_A_MAX_BEACON_OVERHEAD)
  155. /* The number of superframes a GTS descriptor exists for in the beacon frame */
  156. #define MAC_A_GTS_DESC_PERSISTENCE_TIME 4
  157. /* Maximum size in bytes of a MAC frame header */
  158. #define MAC_A_MAX_FRAME_OVERHEAD 25
  159. /* The number of consecutive lost beacons that will case the MAC to declare a sync loss */
  160. #define MAC_A_MAX_LOST_BEACONS 4
  161. /* The maximum number of bytes that can be transmitted in the MAC frame payload */
  162. #define MAC_A_MAX_FRAME_SIZE (MAC_A_MAX_PHY_PACKET_SIZE - MAC_A_MAX_FRAME_OVERHEAD)
  163. /* The maximum frame size in bytes that can be followed by a short interframe spacing period */
  164. #define MAC_A_MAX_SIFS_FRAME_SIZE 18
  165. /* The minimum number of symbols forming the CAP */
  166. #define MAC_A_MIN_CAP_LENGTH 440
  167. /* The minimum number of symbols forming a long interframe spacing period */
  168. #define MAC_A_MIN_LIFS_PERIOD 40
  169. /* The minimum number of symbols forming a short interframe spacing period */
  170. #define MAC_A_MIN_SIFS_PERIOD 12
  171. /* The number of slots contained in any superframe */
  172. #define MAC_A_NUM_SUPERFRAME_SLOTS 16
  173. /* The number of symbols forming a basic CSMA-CA time period */
  174. #define MAC_A_UNIT_BACKOFF_PERIOD 20
  175. /* Maximum value for energy detect */
  176. #define MAC_SPEC_ED_MAX 0xFF
  177. /* Threshold above receiver sensitivity for minimum energy detect in dBm (see 6.9.7) */
  178. #define MAC_SPEC_ED_MIN_DBM_ABOVE_RECEIVER_SENSITIVITY 10
  179. /* ----- values specific to 2450 MHz PHY ----- */
  180. /* minimum receiver sensitivity in dBm (see 6.5.3.3) */
  181. #define MAC_SPEC_MIN_RECEIVER_SENSITIVITY -85
  182. /* Length of preamble field in symbols */
  183. #define MAC_SPEC_PREAMBLE_FIELD_LENGTH 8
  184. /* Length of SFD field in symbols */
  185. #define MAC_SPEC_SFD_FIELD_LENGTH 2
  186. /* Microseconds in one symbol */
  187. #define MAC_SPEC_USECS_PER_SYMBOL 16
  188. /* Microseconds in one backoff period */
  189. #define MAC_SPEC_USECS_PER_BACKOFF (MAC_SPEC_USECS_PER_SYMBOL * MAC_A_UNIT_BACKOFF_PERIOD)
  190. /* octets (or bytes) per symbol */
  191. #define MAC_SPEC_OCTETS_PER_SYMBOL 2
  192. /* ------------------------------------------------------------------------------------------------
  193. * Macros
  194. * ------------------------------------------------------------------------------------------------
  195. */
  196. /* Length of GTS fields in a beacon, not including one byte for GTS specification */
  197. #define MAC_GTS_FIELDS_LEN(gtsSpec) ((uint8)((((gtsSpec) & 0x07) * 3) + (((gtsSpec) & 0x07) ? 1 : 0)))
  198. /*
  199. * Macros to decode FCF and sequence number. For efficiency, the FCF is accessed as separate
  200. * bytes instead of as a 16-bit word. The first byte (+0) is the lowest significant byte.
  201. * The second byte (+1) is the most signficant byte. NOTE! Any change to the specification
  202. * involving FCF would require updating these macros.
  203. *
  204. * Macro parameter is pointer to start of frame.
  205. */
  206. #define MAC_FRAME_TYPE(p) ((p)[MAC_FCF_OFFSET+0] & 0x07)
  207. #define MAC_SEC_ENABLED(p) ((p)[MAC_FCF_OFFSET+0] & 0x08) /* note: value is *non-zero* if true */
  208. #define MAC_FRAME_PENDING(p) ((p)[MAC_FCF_OFFSET+0] & 0x10) /* note: value is *non-zero* if true */
  209. #define MAC_ACK_REQUEST(p) ((p)[MAC_FCF_OFFSET+0] & 0x20) /* note: value is *non-zero* if true */
  210. #define MAC_INTRA_PAN(p) ((p)[MAC_FCF_OFFSET+0] & 0x40) /* note: value is *non-zero* if true */
  211. #define MAC_DEST_ADDR_MODE(p) (((p)[MAC_FCF_OFFSET+1] >> 2) & 0x3)
  212. #define MAC_FRAME_VERSION(p) (((p)[MAC_FCF_OFFSET+1] >> 4) & 0x3)
  213. #define MAC_SRC_ADDR_MODE(p) (((p)[MAC_FCF_OFFSET+1] >> 6) & 0x3)
  214. #define MAC_SEQ_NUMBER(p) ((p)[MAC_SEQ_NUM_OFFSET])
  215. /**************************************************************************************************
  216. */
  217. #endif /* MAC_SPEC_H */