mac_api.h 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638
  1. /**************************************************************************************************
  2. Filename: mac_api.h
  3. Revised: $Date: 2011-02-28 16:59:59 -0800 (Mon, 28 Feb 2011) $
  4. Revision: $Revision: 25230 $
  5. Description: Public interface file for 802.15.4 MAC.
  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_API_H
  34. #define MAC_API_H
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /* ------------------------------------------------------------------------------------------------
  39. * Includes
  40. * ------------------------------------------------------------------------------------------------
  41. */
  42. #include "hal_types.h"
  43. #include "saddr.h"
  44. #include "sdata.h"
  45. /* ------------------------------------------------------------------------------------------------
  46. * Constants
  47. * ------------------------------------------------------------------------------------------------
  48. */
  49. /* Status */
  50. #define MAC_SUCCESS 0x00 /* Operation successful */
  51. #define MAC_AUTOACK_PENDING_ALL_ON 0xFE /* The AUTOPEND pending all is turned on */
  52. #define MAC_AUTOACK_PENDING_ALL_OFF 0xFF /* The AUTOPEND pending all is turned off */
  53. #define MAC_BEACON_LOSS 0xE0 /* The beacon was lost following a synchronization request */
  54. #define MAC_CHANNEL_ACCESS_FAILURE 0xE1 /* The operation or data request failed because of
  55. activity on the channel */
  56. #define MAC_COUNTER_ERROR 0xDB /* The frame counter puportedly applied by the originator of
  57. the received frame is invalid */
  58. #define MAC_DENIED 0xE2 /* The MAC was not able to enter low power mode. */
  59. #define MAC_DISABLE_TRX_FAILURE 0xE3 /* Unused */
  60. #define MAC_FRAME_TOO_LONG 0xE5 /* The received frame or frame resulting from an operation
  61. or data request is too long to be processed by the MAC */
  62. #define MAC_IMPROPER_KEY_TYPE 0xDC /* The key purportedly applied by the originator of the
  63. received frame is not allowed */
  64. #define MAC_IMPROPER_SECURITY_LEVEL 0xDD /* The security level purportedly applied by the originator of
  65. the received frame does not meet the minimum security level */
  66. #define MAC_INVALID_ADDRESS 0xF5 /* The data request failed because neither the source address nor
  67. destination address parameters were present */
  68. #define MAC_INVALID_GTS 0xE6 /* Unused */
  69. #define MAC_INVALID_HANDLE 0xE7 /* The purge request contained an invalid handle */
  70. #define MAC_INVALID_INDEX 0xF9 /* Unused */
  71. #define MAC_INVALID_PARAMETER 0xE8 /* The API function parameter is out of range */
  72. #define MAC_LIMIT_REACHED 0xFA /* The scan terminated because the PAN descriptor storage limit
  73. was reached */
  74. #define MAC_NO_ACK 0xE9 /* The operation or data request failed because no
  75. acknowledgement was received */
  76. #define MAC_NO_BEACON 0xEA /* The scan request failed because no beacons were received or the
  77. orphan scan failed because no coordinator realignment was received */
  78. #define MAC_NO_DATA 0xEB /* The associate request failed because no associate response was received
  79. or the poll request did not return any data */
  80. #define MAC_NO_SHORT_ADDRESS 0xEC /* The short address parameter of the start request was invalid */
  81. #define MAC_ON_TIME_TOO_LONG 0xF6 /* Unused */
  82. #define MAC_OUT_OF_CAP 0xED /* Unused */
  83. #define MAC_PAN_ID_CONFLICT 0xEE /* A PAN identifier conflict has been detected and
  84. communicated to the PAN coordinator */
  85. #define MAC_PAST_TIME 0xF7 /* Unused */
  86. #define MAC_READ_ONLY 0xFB /* A set request was issued with a read-only identifier */
  87. #define MAC_REALIGNMENT 0xEF /* A coordinator realignment command has been received */
  88. #define MAC_SCAN_IN_PROGRESS 0xFC /* The scan request failed because a scan is already in progress */
  89. #define MAC_SECURITY_ERROR 0xE4 /* Cryptographic processing of the received secure frame failed */
  90. #define MAC_SUPERFRAME_OVERLAP 0xFD /* The beacon start time overlapped the coordinator transmission time */
  91. #define MAC_TRACKING_OFF 0xF8 /* The start request failed because the device is not tracking
  92. the beacon of its coordinator */
  93. #define MAC_TRANSACTION_EXPIRED 0xF0 /* The associate response, disassociate request, or indirect
  94. data transmission failed because the peer device did not respond
  95. before the transaction expired or was purged */
  96. #define MAC_TRANSACTION_OVERFLOW 0xF1 /* The request failed because MAC data buffers are full */
  97. #define MAC_TX_ACTIVE 0xF2 /* Unused */
  98. #define MAC_UNAVAILABLE_KEY 0xF3 /* The operation or data request failed because the
  99. security key is not available */
  100. #define MAC_UNSUPPORTED_ATTRIBUTE 0xF4 /* The set or get request failed because the attribute is not supported */
  101. #define MAC_UNSUPPORTED_LEGACY 0xDE /* The received frame was secured with legacy security which is
  102. not supported */
  103. #define MAC_UNSUPPORTED_SECURITY 0xDF /* The security of the received frame is not supported */
  104. #define MAC_UNSUPPORTED 0x18 /* The operation is not supported in the current configuration */
  105. #define MAC_BAD_STATE 0x19 /* The operation could not be performed in the current state */
  106. #define MAC_NO_RESOURCES 0x1A /* The operation could not be completed because no
  107. memory resources were available */
  108. #define MAC_ACK_PENDING 0x1B /* For internal use only */
  109. #define MAC_NO_TIME 0x1C /* For internal use only */
  110. #define MAC_TX_ABORTED 0x1D /* For internal use only */
  111. #define MAC_DUPLICATED_ENTRY 0x1E /* For internal use only - A duplicated entry is added to the source matching table */
  112. /* MAC Security Level */
  113. #define MAC_SEC_LEVEL_NONE 0x00 /* No security is used */
  114. #define MAC_SEC_LEVEL_MIC_32 0x01 /* MIC-32 authentication is used */
  115. #define MAC_SEC_LEVEL_MIC_64 0x02 /* MIC-64 authentication is used */
  116. #define MAC_SEC_LEVEL_MIC_128 0x03 /* MIC-128 authentication is used */
  117. #define MAC_SEC_LEVEL_ENC 0x04 /* AES encryption is used */
  118. #define MAC_SEC_LEVEL_ENC_MIC_32 0x05 /* AES encryption and MIC-32 authentication are used */
  119. #define MAC_SEC_LEVEL_ENC_MIC_64 0x06 /* AES encryption and MIC-64 authentication are used */
  120. #define MAC_SEC_LEVEL_ENC_MIC_128 0x07 /* AES encryption and MIC-128 authentication are used */
  121. /* Key Identifier Mode */
  122. #define MAC_KEY_ID_MODE_NONE 0x00 /* Key is is not used */
  123. #define MAC_KEY_ID_MODE_IMPLICIT 0x00 /* Key is determined implicitly */
  124. #define MAC_KEY_ID_MODE_1 0x01 /* Key is determined from the 1-byte key index */
  125. #define MAC_KEY_ID_MODE_4 0x02 /* Key is determined from the 4-byte key index */
  126. #define MAC_KEY_ID_MODE_8 0x03 /* Key is determined from the 8-byte key index */
  127. /* Key identifier field length in bytes */
  128. #define MAC_KEY_ID_IMPLICIT_LEN 0
  129. #define MAC_KEY_ID_1_LEN 1
  130. #define MAC_KEY_ID_4_LEN 5
  131. #define MAC_KEY_ID_8_LEN 9
  132. /* Key source maximum length in bytes */
  133. #define MAC_KEY_SOURCE_MAX_LEN 8
  134. /* Key index length in bytes */
  135. #define MAC_KEY_INDEX_LEN 1
  136. /* Frame counter length in bytes */
  137. #define MAC_FRAME_COUNTER_LEN 4
  138. /* Key length in bytes */
  139. #define MAC_KEY_MAX_LEN 16
  140. /* Key lookup data length in bytes */
  141. #define MAC_KEY_LOOKUP_SHORT_LEN 5
  142. #define MAC_KEY_LOOKUP_LONG_LEN 9
  143. #define MAC_MAX_KEY_LOOKUP_LEN MAC_KEY_LOOKUP_LONG_LEN
  144. /* Data constants */
  145. #if !defined ( MAC_MAX_FRAME_SIZE )
  146. #define MAC_MAX_FRAME_SIZE 102 /* Maximum application data length without security */
  147. #endif
  148. #define MAC_DATA_OFFSET 24 /* Bytes required for MAC header in data frame */
  149. #define MAC_ENC_OFFSET 5 /* Data offset required for encryption header */
  150. #define MAC_MIC_32_LEN 4 /* Length required for MIC-32 authentication */
  151. #define MAC_MIC_64_LEN 8 /* Length required for MIC-64 authentication */
  152. #define MAC_MIC_128_LEN 16 /* Length required for MIC-128 authentication */
  153. /* MHR length for received frame */
  154. #define MAC_MHR_LEN 37 /* FCF (2) + Seq (1) + Addr Fields (20) + Security HDR (14) */
  155. /* TX Options */
  156. #define MAC_TXOPTION_ACK 0x01 /* Acknowledged transmission. The MAC will attempt to retransmit
  157. the frame until it is acknowledged */
  158. #define MAC_TXOPTION_GTS 0x02 /* GTS transmission (unused) */
  159. #define MAC_TXOPTION_INDIRECT 0x04 /* Indirect transmission. The MAC will queue the data and wait
  160. for the destination device to poll for it. This can only be used
  161. by a coordinator device */
  162. #define MAC_TXOPTION_PEND_BIT 0x08 /* This proprietary option forces the pending bit set for direct
  163. transmission */
  164. #define MAC_TXOPTION_NO_RETRANS 0x10 /* This proprietary option prevents the frame from being retransmitted */
  165. #define MAC_TXOPTION_NO_CNF 0x20 /* This proprietary option prevents a MAC_MCPS_DATA_CNF
  166. event from being sent for this frame */
  167. #define MAC_TXOPTION_ALT_BE 0x40 /* Use PIB value MAC_ALT_BE for the minimum backoff exponent */
  168. #define MAC_TXOPTION_PWR_CHAN 0x80 /* Use the power and channel values in macDataReq_t
  169. instead of the PIB values */
  170. /* Channels */
  171. #define MAC_CHAN_11 11
  172. #define MAC_CHAN_12 12
  173. #define MAC_CHAN_13 13
  174. #define MAC_CHAN_14 14
  175. #define MAC_CHAN_15 15
  176. #define MAC_CHAN_16 16
  177. #define MAC_CHAN_17 17
  178. #define MAC_CHAN_18 18
  179. #define MAC_CHAN_19 19
  180. #define MAC_CHAN_20 20
  181. #define MAC_CHAN_21 21
  182. #define MAC_CHAN_22 22
  183. #define MAC_CHAN_23 23
  184. #define MAC_CHAN_24 24
  185. #define MAC_CHAN_25 25
  186. #define MAC_CHAN_26 26
  187. #define MAC_CHAN_27 27
  188. #define MAC_CHAN_28 28
  189. /* This macro converts a channel to a mask */
  190. #define MAC_CHAN_MASK(chan) ((uint32) 1 << (chan))
  191. /* Channel Masks */
  192. #define MAC_CHAN_11_MASK MAC_CHAN_MASK(MAC_CHAN_11)
  193. #define MAC_CHAN_12_MASK MAC_CHAN_MASK(MAC_CHAN_12)
  194. #define MAC_CHAN_13_MASK MAC_CHAN_MASK(MAC_CHAN_13)
  195. #define MAC_CHAN_14_MASK MAC_CHAN_MASK(MAC_CHAN_14)
  196. #define MAC_CHAN_15_MASK MAC_CHAN_MASK(MAC_CHAN_15)
  197. #define MAC_CHAN_16_MASK MAC_CHAN_MASK(MAC_CHAN_16)
  198. #define MAC_CHAN_17_MASK MAC_CHAN_MASK(MAC_CHAN_17)
  199. #define MAC_CHAN_18_MASK MAC_CHAN_MASK(MAC_CHAN_18)
  200. #define MAC_CHAN_19_MASK MAC_CHAN_MASK(MAC_CHAN_19)
  201. #define MAC_CHAN_20_MASK MAC_CHAN_MASK(MAC_CHAN_20)
  202. #define MAC_CHAN_21_MASK MAC_CHAN_MASK(MAC_CHAN_21)
  203. #define MAC_CHAN_22_MASK MAC_CHAN_MASK(MAC_CHAN_22)
  204. #define MAC_CHAN_23_MASK MAC_CHAN_MASK(MAC_CHAN_23)
  205. #define MAC_CHAN_24_MASK MAC_CHAN_MASK(MAC_CHAN_24)
  206. #define MAC_CHAN_25_MASK MAC_CHAN_MASK(MAC_CHAN_25)
  207. #define MAC_CHAN_26_MASK MAC_CHAN_MASK(MAC_CHAN_26)
  208. #define MAC_CHAN_27_MASK MAC_CHAN_MASK(MAC_CHAN_27)
  209. #define MAC_CHAN_28_MASK MAC_CHAN_MASK(MAC_CHAN_28)
  210. /* Channel Page */
  211. #define MAC_CHANNEL_PAGE_0 0 /* 2.4 GHz band using O-QPSK */
  212. #define MAC_CHANNEL_PAGE_1 1 /* 868 and 915 MHz bands using ASK */
  213. #define MAC_CHANNEL_PAGE_2 2 /* 868 and 915 MHz bands using O-QPSK */
  214. /* Capability Information */
  215. #define MAC_CAPABLE_PAN_COORD 0x01 /* Device is capable of becoming a PAN coordinator */
  216. #define MAC_CAPABLE_FFD 0x02 /* Device is an FFD */
  217. #define MAC_CAPABLE_MAINS_POWER 0x04 /* Device is mains powered rather than battery powered */
  218. #define MAC_CAPABLE_RX_ON_IDLE 0x08 /* Device has its receiver on when idle */
  219. #define MAC_CAPABLE_SECURITY 0x40 /* Device is capable of sending and receiving secured frames */
  220. #define MAC_CAPABLE_ALLOC_ADDR 0x80 /* Request allocation of a short address in the associate procedure */
  221. /* Standard PIB Get and Set Attributes */
  222. #define MAC_ACK_WAIT_DURATION 0x40 /* The maximum number of symbols to wait for an acknowledgment frame */
  223. #define MAC_ASSOCIATION_PERMIT 0x41 /* TRUE if a coordinator is currently allowing association */
  224. #define MAC_AUTO_REQUEST 0x42 /* TRUE if a device automatically sends a data request if its address
  225. is listed in the beacon frame */
  226. #define MAC_BATT_LIFE_EXT 0x43 /* TRUE if battery life extension is enabled */
  227. #define MAC_BATT_LIFE_EXT_PERIODS 0x44 /* The number of backoff periods during which the receiver is
  228. enabled following a beacon in battery life extension mode */
  229. #define MAC_BEACON_PAYLOAD 0x45 /* The contents of the beacon payload */
  230. #define MAC_BEACON_PAYLOAD_LENGTH 0x46 /* The length in bytes of the beacon payload */
  231. #define MAC_BEACON_ORDER 0x47 /* How often the coordinator transmits a beacon */
  232. #define MAC_BEACON_TX_TIME 0x48 /* The time the device transmitted its last beacon frame,
  233. in backoff period units */
  234. #define MAC_BSN 0x49 /* The beacon sequence number */
  235. #define MAC_COORD_EXTENDED_ADDRESS 0x4A /* The extended address of the coordinator with which the device
  236. is associated */
  237. #define MAC_COORD_SHORT_ADDRESS 0x4B /* The short address assigned to the coordinator with which the
  238. device is associated. A value of MAC_ADDR_USE_EXT indicates
  239. that the coordinator is using its extended address */
  240. #define MAC_DSN 0x4C /* The data or MAC command frame sequence number */
  241. #define MAC_GTS_PERMIT 0x4D /* TRUE if the PAN coordinator accepts GTS requests */
  242. #define MAC_MAX_CSMA_BACKOFFS 0x4E /* The maximum number of backoffs the CSMA-CA algorithm will attempt
  243. before declaring a channel failure */
  244. #define MAC_MIN_BE 0x4F /* The minimum value of the backoff exponent in the CSMA-CA algorithm.
  245. If this value is set to 0, collision avoidance is disabled during
  246. the first iteration of the algorithm. Also for the slotted version
  247. of the CSMA-CA algorithm with the battery life extension enabled,
  248. the minimum value of the backoff exponent will be at least 2 */
  249. #define MAC_PAN_ID 0x50 /* The PAN identifier. If this value is 0xffff, the device is not
  250. associated */
  251. #define MAC_PROMISCUOUS_MODE 0x51 /* TRUE if the MAC is in promiscuous mode */
  252. #define MAC_RX_ON_WHEN_IDLE 0x52 /* TRUE if the MAC enables its receiver during idle periods */
  253. #define MAC_SHORT_ADDRESS 0x53 /* The short address that the device uses to communicate in the PAN.
  254. If the device is a PAN coordinator, this value shall be set before
  255. calling MAC_StartReq(). Otherwise the value is allocated during
  256. association. Value MAC_ADDR_USE_EXT indicates that the device is
  257. associated but not using a short address */
  258. #define MAC_SUPERFRAME_ORDER 0x54 /* This specifies the length of the active portion of the superframe */
  259. #define MAC_TRANSACTION_PERSISTENCE_TIME 0x55 /* The maximum time in beacon intervals that a transaction is stored by
  260. a coordinator and indicated in the beacon */
  261. #define MAC_ASSOCIATED_PAN_COORD 0x56 /* TRUE if the device is associated to the PAN coordinator */
  262. #define MAC_MAX_BE 0x57 /* The maximum value of the backoff exponent in the CSMA-CA algorithm */
  263. #define MAC_MAX_FRAME_TOTAL_WAIT_TIME 0x58 /* The maximum number of CAP symbols in a beacon-enabled PAN, or
  264. symbols in a non beacon-enabled PAN, to wait for a frame intended
  265. as a response to a data request frame */
  266. #define MAC_MAX_FRAME_RETRIES 0x59 /* The maximum number of retries allowed after a transmission failure */
  267. #define MAC_RESPONSE_WAIT_TIME 0x5A /* The maximum number of symbols a device shall wait for a response
  268. command to be available following a request command in multiples
  269. of aBaseSuperframeDuration */
  270. #define MAC_SYNC_SYMBOL_OFFSET 0x5B /* The timestamp offset from SFD in symbols */
  271. #define MAC_TIMESTAMP_SUPPORTED 0x5C /* TRUE if the MAC supports RX and TX timestamps */
  272. #define MAC_SECURITY_ENABLED 0x5D /* TRUE if security is enabled */
  273. /* Security PIB Get and Set Attributes */
  274. #define MAC_KEY_TABLE 0x71 /* A table of KeyDescriptor, entries, each containing keys and related
  275. information required for secured communications */
  276. #define MAC_KEY_TABLE_ENTRIES 0x72 /* The number of entries in macKeyTable */
  277. #define MAC_DEVICE_TABLE 0x73 /* A table of Device-Descriptor entries, each indicating a remote device
  278. with which this device securely communicates */
  279. #define MAC_DEVICE_TABLE_ENTRIES 0x74 /* The number of entries in macDeviceTable. */
  280. #define MAC_SECURITY_LEVEL_TABLE 0x75 /* A table of SecurityLevel-Descriptor entries, each with information
  281. about the minimum security level expected depending on incoming frame
  282. type and subtype. */
  283. #define MAC_SECURITY_LEVEL_TABLE_ENTRIES 0x76 /* The number of entries in macSecurityLevelTable. */
  284. #define MAC_FRAME_COUNTER 0x77 /* The outgoing frame counter for this device */
  285. #define MAC_AUTO_REQUEST_SECURITY_LEVEL 0x78 /* The security level used for automatic data requests. */
  286. #define MAC_AUTO_REQUEST_KEY_ID_MODE 0x79 /* The key identifier mode used for automatic data requests */
  287. #define MAC_AUTO_REQUEST_KEY_SOURCE 0x7A /* The originator of the key used for automatic data requests. */
  288. #define MAC_AUTO_REQUEST_KEY_INDEX 0x7B /* The index of the key used for automatic data requests. */
  289. #define MAC_DEFAULT_KEY_SOURCE 0x7C /* The originator of the default key used for key ID mode 0x01 */
  290. #define MAC_PAN_COORD_EXTENDED_ADDRESS 0x7D /* The 64-bit address of the PAN coordinator. */
  291. #define MAC_PAN_COORD_SHORT_ADDRESS 0x7E /* The 16-bit short address assigned to the PAN coordinator. */
  292. /* Proprietary Security PIB Get and Set Attributes */
  293. #define MAC_KEY_ID_LOOKUP_ENTRY 0xD0 /* The key lookup table entry, part of an entry of the key table */
  294. #define MAC_KEY_DEVICE_ENTRY 0xD1 /* The key device entry, part of an entry of the key table */
  295. #define MAC_KEY_USAGE_ENTRY 0xD2 /* The key usage entry, part of an entry of the key table */
  296. #define MAC_KEY_ENTRY 0xD3 /* The MAC key entry, an entry of the key table */
  297. #define MAC_DEVICE_ENTRY 0xD4 /* The MAC device entry, an entry of the device table */
  298. #define MAC_SECURITY_LEVEL_ENTRY 0xD5 /* The AMC security level entry, an entry of the security level table */
  299. /* Proprietary PIB Get and Set Attributes */
  300. #define MAC_PHY_TRANSMIT_POWER 0xE0 /* The transmit power in units of -1 dBm */
  301. #define MAC_LOGICAL_CHANNEL 0xE1 /* The logical channel */
  302. #define MAC_EXTENDED_ADDRESS 0xE2 /* The extended address of the device */
  303. #define MAC_ALT_BE 0xE3 /* alternate minimum backoff exponent */
  304. #define MAC_DEVICE_BEACON_ORDER 0xE4 /* Device beacon order */
  305. #define MAC_PHY_TRANSMIT_POWER_SIGNED 0xE5 /* Duplicate transmit power attribute in signed
  306. (2's complement) dBm unit */
  307. /* Disassociate Reason */
  308. #define MAC_DISASSOC_COORD 1 /* The coordinator wishes the device to disassociate */
  309. #define MAC_DISASSOC_DEVICE 2 /* The device itself wishes to disassociate */
  310. /* Scan Type */
  311. #define MAC_SCAN_ED 0 /* Energy detect scan. The device will tune to each channel and
  312. perform and energy measurement. The list of channels and their
  313. associated measurements will be returned at the end of the scan */
  314. #define MAC_SCAN_ACTIVE 1 /* Active scan. The device tunes to each channel, sends a beacon
  315. request and listens for beacons. The PAN descriptors are returned
  316. at the end of the scan */
  317. #define MAC_SCAN_PASSIVE 2 /* Passive scan. The device tunes to each channel and listens for
  318. beacons. The PAN descriptors are returned at the end of the scan */
  319. #define MAC_SCAN_ORPHAN 3 /* Orphan scan. The device tunes to each channel and sends an orphan
  320. notification to try and find its coordinator. The status is returned
  321. at the end of the scan */
  322. /* Special address values */
  323. #define MAC_ADDR_USE_EXT 0xFFFE /* Short address value indicating extended address is used */
  324. #define MAC_SHORT_ADDR_BROADCAST 0xFFFF /* Broadcast short address */
  325. #define MAC_SHORT_ADDR_NONE 0xFFFF /* Short address when there is no short address */
  326. /* Comm status indication reasons */
  327. #define MAC_COMM_ASSOCIATE_RSP 0 /* Event sent in response to MAC_AssociateRsp() */
  328. #define MAC_COMM_ORPHAN_RSP 1 /* Event sent in response to MAC_OrphanRsp() */
  329. #define MAC_COMM_RX_SECURE 2 /* Event sent as a result of receiving a secure frame */
  330. /* Power Mode */
  331. #define MAC_PWR_ON 0 /* MAC and radio hardware is powered on */
  332. #define MAC_PWR_SLEEP_LITE 1 /* MAC and radio hardware are partially powered off */
  333. #define MAC_PWR_SLEEP_DEEP 2 /* MAC and radio hardware are fully powered off */
  334. /* MAC Callback Events */
  335. #define MAC_MLME_ASSOCIATE_IND 1 /* Associate indication */
  336. #define MAC_MLME_ASSOCIATE_CNF 2 /* Associate confirm */
  337. #define MAC_MLME_DISASSOCIATE_IND 3 /* Disassociate indication */
  338. #define MAC_MLME_DISASSOCIATE_CNF 4 /* Disassociate confirm */
  339. #define MAC_MLME_BEACON_NOTIFY_IND 5 /* Beacon notify indication */
  340. #define MAC_MLME_ORPHAN_IND 6 /* Orphan indication */
  341. #define MAC_MLME_SCAN_CNF 7 /* Scan confirm */
  342. #define MAC_MLME_START_CNF 8 /* Start confirm */
  343. #define MAC_MLME_SYNC_LOSS_IND 9 /* Sync loss indication */
  344. #define MAC_MLME_POLL_CNF 10 /* Poll confirm */
  345. #define MAC_MLME_COMM_STATUS_IND 11 /* Communication status indication */
  346. #define MAC_MCPS_DATA_CNF 12 /* Data confirm */
  347. #define MAC_MCPS_DATA_IND 13 /* Data indication */
  348. #define MAC_MCPS_PURGE_CNF 14 /* Purge confirm */
  349. #define MAC_PWR_ON_CNF 15 /* Power on confirm */
  350. #define MAC_MLME_POLL_IND 16 /* Poll indication */
  351. /* The length of the random seed is currently set to 16 bytes to match
  352. the security key length of Z-Stack */
  353. #define MAC_RANDOM_SEED_LEN 16
  354. /* ------------------------------------------------------------------------------------------------
  355. * Macros
  356. * ------------------------------------------------------------------------------------------------
  357. */
  358. /* Returns the number of short addresses in the pending address specification */
  359. #define MAC_PEND_NUM_SHORT(pendAddrSpec) ((pendAddrSpec) & 0x07)
  360. /* Returns the number of extended addresses in the pending address specification */
  361. #define MAC_PEND_NUM_EXT(pendAddrSpec) (((pendAddrSpec) & 0x70) >> 4)
  362. /* Returns the length in bytes of the pending address fields in the beacon */
  363. #define MAC_PEND_FIELDS_LEN(pendAddrSpec) ((MAC_PEND_NUM_SHORT(pendAddrSpec) * 2) + \
  364. (MAC_PEND_NUM_EXT(pendAddrSpec) * 8))
  365. /* The following macros are provided to help parse the superframe specification */
  366. #define MAC_SFS_BEACON_ORDER(s) ((s) & 0x0F) /* returns the beacon order */
  367. #define MAC_SFS_SUPERFRAME_ORDER(s) (((s) >> 4) & 0x0F) /* returns the beacon order */
  368. #define MAC_SFS_FINAL_CAP_SLOT(s) (((s) >> 8) & 0x0F) /* returns the final CAP slot */
  369. #define MAC_SFS_BLE(s) (((s) >> 12) & 0x01) /* returns the battery life extension bit */
  370. #define MAC_SFS_PAN_COORDINATOR(s) (((s) >> 14) & 0x01) /* returns the PAN coordinator bit */
  371. #define MAC_SFS_ASSOCIATION_PERMIT(s) ((s) >> 15) /* returns the association permit bit */
  372. /* ------------------------------------------------------------------------------------------------
  373. * Typedefs
  374. * ------------------------------------------------------------------------------------------------
  375. */
  376. /* MAC event header type */
  377. typedef struct
  378. {
  379. uint8 event; /* MAC event */
  380. uint8 status; /* MAC status */
  381. } macEventHdr_t;
  382. /* Common security type */
  383. typedef struct
  384. {
  385. uint8 keySource[MAC_KEY_SOURCE_MAX_LEN]; /* Key source */
  386. uint8 securityLevel; /* Security level */
  387. uint8 keyIdMode; /* Key identifier mode */
  388. uint8 keyIndex; /* Key index */
  389. } macSec_t;
  390. /* Key ID Lookup Descriptor */
  391. typedef struct
  392. {
  393. uint8 lookupData[MAC_MAX_KEY_LOOKUP_LEN]; /* Data used to identify the key */
  394. uint8 lookupDataSize; /* 0x00 indicates 5 octets; 0x01 indicates 9 octets. */
  395. } keyIdLookupDescriptor_t;
  396. /* Key Device Descriptor */
  397. typedef struct
  398. {
  399. uint8 deviceDescriptorHandle; /* Handle to the DeviceDescriptor */
  400. bool uniqueDevice; /* Is it a link key or a group key? */
  401. bool blackListed; /* This key exhausted the frame counter. */
  402. } keyDeviceDescriptor_t;
  403. /* Key Usage Descriptor */
  404. typedef struct
  405. {
  406. uint8 frameType; /* Frame Type */
  407. uint8 cmdFrameId; /* Command Frame Identifier */
  408. } keyUsageDescriptor_t;
  409. /* Key Descriptor */
  410. typedef struct
  411. {
  412. keyIdLookupDescriptor_t *keyIdLookupList; /* A list identifying this KeyDescriptor */
  413. uint8 keyIdLookupEntries; /* The number of entries in KeyIdLookupList */
  414. keyDeviceDescriptor_t *keyDeviceList; /* A list indicating which devices are
  415. currently using this key, including
  416. their blacklist status. */
  417. uint8 keyDeviceListEntries; /* The number of entries in KeyDeviceList */
  418. keyUsageDescriptor_t *keyUsageList; /* A list indicating which frame types
  419. * this key may be used with. */
  420. uint8 keyUsageListEntries; /* The number of entries in KeyUsageList */
  421. uint8 key[MAC_KEY_MAX_LEN]; /* The actual value of the key */
  422. } keyDescriptor_t;
  423. /* Device Descriptor */
  424. typedef struct
  425. {
  426. uint16 panID; /* The 16-bit PAN identifier of the device */
  427. uint16 shortAddress; /* The 16-bit short address of the device */
  428. sAddrExt_t extAddress; /* The 64-bit IEEE extended address of the
  429. device. This element is also used in
  430. unsecuring operations on incoming frames. */
  431. uint32 frameCounter; /* The incoming frame counter of the device.
  432. This value is used to ensure sequential
  433. freshness of frames. */
  434. bool exempt; /* Device may override the minimum security
  435. level settings. */
  436. } deviceDescriptor_t;
  437. /* Security Level Descriptor */
  438. typedef struct
  439. {
  440. uint8 frameType; /* Frame Type */
  441. uint8 commandFrameIdentifier; /* Command Frame ID */
  442. uint8 securityMinimum; /* The minimal required/expected security
  443. level for incoming MAC frames. */
  444. bool securityOverrideSecurityMinimum;
  445. /* Indication of whether originating devices
  446. for which the Exempt flag is set may
  447. override the minimum security level
  448. indicated by the SecurityMinimum
  449. element. If TRUE, this indicates that for
  450. originating devices with Exempt status,
  451. the incoming security level zero is
  452. acceptable. */
  453. } securityLevelDescriptor_t;
  454. /* For internal use only */
  455. typedef struct
  456. {
  457. uint32 timestamp;
  458. uint16 timestamp2;
  459. uint16 timeToLive;
  460. uint8 frameType;
  461. uint8 txOptions;
  462. uint8 txMode;
  463. uint8 txSched;
  464. uint8 retries;
  465. uint8 channel;
  466. uint8 power;
  467. uint8 mpduLinkQuality;
  468. uint8 correlation;
  469. int8 rssi;
  470. } macTxIntData_t;
  471. /* For internal use only */
  472. typedef struct
  473. {
  474. uint8 frameType;
  475. uint8 flags;
  476. } macRxIntData_t;
  477. /* Data request parameters type */
  478. typedef struct
  479. {
  480. sAddr_t dstAddr; /* The address of the destination device */
  481. uint16 dstPanId; /* The PAN ID of the destination device */
  482. uint8 srcAddrMode; /* The source address mode */
  483. uint8 msduHandle; /* Application-defined handle value associated with this data request */
  484. uint8 txOptions; /* TX options bit mask */
  485. uint8 channel; /* Transmit the data frame on this channel */
  486. uint8 power; /* Transmit the data frame at this power level */
  487. } macDataReq_t;
  488. /* MCPS data request type */
  489. typedef struct
  490. {
  491. macEventHdr_t hdr; /* Internal use only */
  492. sData_t msdu; /* Data pointer and length */
  493. macTxIntData_t internal; /* Internal use only */
  494. macSec_t sec; /* Security parameters */
  495. macDataReq_t mac; /* Data request parameters */
  496. } macMcpsDataReq_t;
  497. /* Data indication parameters type */
  498. typedef struct
  499. {
  500. sAddr_t srcAddr; /* The address of the sending device */
  501. sAddr_t dstAddr; /* The address of the destination device */
  502. uint32 timestamp; /* The time, in backoffs, at which the data were received */
  503. uint16 timestamp2; /* The time, in internal MAC timer units, at which the
  504. data were received */
  505. uint16 srcPanId; /* The PAN ID of the sending device */
  506. uint16 dstPanId; /* The PAN ID of the destination device */
  507. uint8 mpduLinkQuality; /* The link quality of the received data frame */
  508. uint8 correlation; /* The raw correlation value of the received data frame */
  509. int8 rssi; /* The received RF power in units dBm */
  510. uint8 dsn; /* The data sequence number of the received frame */
  511. } macDataInd_t;
  512. /* MCPS data indication type */
  513. typedef struct
  514. {
  515. macEventHdr_t hdr; /* Internal use only */
  516. sData_t msdu; /* Data pointer and length */
  517. macRxIntData_t internal; /* Internal use only */
  518. macSec_t sec; /* Security parameters */
  519. macDataInd_t mac; /* Data indication parameters */
  520. } macMcpsDataInd_t;
  521. /* MCPS data confirm type */
  522. typedef struct
  523. {
  524. macEventHdr_t hdr; /* Contains the status of the data request operation */
  525. uint8 msduHandle; /* Application-defined handle value associated with the data request */
  526. macMcpsDataReq_t *pDataReq; /* Pointer to the data request buffer for this data confirm */
  527. uint32 timestamp; /* The time, in backoffs, at which the frame was transmitted */
  528. uint16 timestamp2; /* The time, in internal MAC timer units, at which the
  529. frame was transmitted */
  530. uint8 retries; /* The number of retries required to transmit the data frame */
  531. uint8 mpduLinkQuality; /* The link quality of the received ack frame */
  532. uint8 correlation; /* The raw correlation value of the received ack frame */
  533. int8 rssi; /* The RF power of the received ack frame in units dBm */
  534. } macMcpsDataCnf_t;
  535. /* MCPS purge confirm type */
  536. typedef struct
  537. {
  538. macEventHdr_t hdr; /* Contains the status of the purge request operation */
  539. uint8 msduHandle; /* Application-defined handle value associated with the data request */
  540. } macMcpsPurgeCnf_t;
  541. /* PAN descriptor type */
  542. typedef struct
  543. {
  544. sAddr_t coordAddress; /* The address of the coordinator sending the beacon */
  545. uint16 coordPanId; /* The PAN ID of the network */
  546. uint16 superframeSpec; /* The superframe specification of the network */
  547. uint8 logicalChannel; /* The logical channel of the network */
  548. uint8 channelPage; /* The current channel page occupied by the network */
  549. bool gtsPermit; /* TRUE if coordinator accepts GTS requests */
  550. uint8 linkQuality; /* The link quality of the received beacon */
  551. uint32 timestamp; /* The time at which the beacon was received, in backoffs */
  552. bool securityFailure; /* Set to TRUE if there was an error in the security processing */
  553. macSec_t sec; /* The security parameters for the received beacon frame */
  554. } macPanDesc_t;
  555. /* MLME associate request type */
  556. typedef struct
  557. {
  558. uint8 logicalChannel; /* The channel on which to attempt association */
  559. uint8 channelPage; /* The channel page on which to attempt association */
  560. sAddr_t coordAddress; /* Address of the coordinator with which to associate */
  561. uint16 coordPanId; /* The identifier of the PAN with which to associate */
  562. uint8 capabilityInformation; /* The operational capabilities of this device */
  563. macSec_t sec; /* The security parameters for this message */
  564. } macMlmeAssociateReq_t;
  565. /* MLME associate response type */
  566. typedef struct
  567. {
  568. sAddrExt_t deviceAddress; /* The address of the device requesting association */
  569. uint16 assocShortAddress; /* The short address allocated to the device */
  570. uint8 status; /* The status of the association attempt */
  571. macSec_t sec; /* The security parameters for this message */
  572. } macMlmeAssociateRsp_t;
  573. /* MLME disassociate request type */
  574. typedef struct
  575. {
  576. sAddr_t deviceAddress; /* The address of the device with which to disassociate */
  577. uint16 devicePanId; /* The PAN ID of the device */
  578. uint8 disassociateReason; /* The disassociate reason */
  579. bool txIndirect; /* Transmit Indirect */
  580. macSec_t sec; /* The security parameters for this message */
  581. } macMlmeDisassociateReq_t;
  582. /* MLME orphan response type */
  583. typedef struct
  584. {
  585. sAddrExt_t orphanAddress; /* The extended address of the device sending the orphan notification */
  586. uint16 shortAddress; /* The short address of the orphaned device */
  587. bool associatedMember; /* Set to TRUE if the orphaned device is associated with this coordinator */
  588. macSec_t sec; /* The security parameters for this message */
  589. } macMlmeOrphanRsp_t;
  590. /* MLME poll request type */
  591. typedef struct
  592. {
  593. sAddr_t coordAddress; /* The address of the coordinator device to poll */
  594. uint16 coordPanId; /* The PAN ID of the coordinator */
  595. macSec_t sec; /* The security parameters for this message */
  596. } macMlmePollReq_t;
  597. /* MLME scan request type */
  598. typedef struct
  599. {
  600. uint32 scanChannels; /* Bit mask indicating which channels to scan */
  601. uint8 scanType; /* The type of scan */
  602. uint8 scanDuration; /* The exponent used in the scan duration calculation */
  603. uint8 channelPage; /* The channel page on which to perform the scan */
  604. uint8 maxResults; /* The maximum number of PAN descriptor results */
  605. macSec_t sec; /* The security parameters for orphan scan */
  606. union {
  607. uint8 *pEnergyDetect; /* Pointer to a buffer to store energy detect measurements */
  608. macPanDesc_t *pPanDescriptor; /* Pointer to a buffer to store PAN descriptors */
  609. } result;
  610. } macMlmeScanReq_t;
  611. /* MLME start request type */
  612. typedef struct
  613. {
  614. uint32 startTime; /* The time to begin transmitting beacons relative to the received beacon */
  615. uint16 panId; /* The PAN ID to use. This parameter is ignored if panCoordinator is FALSE */
  616. uint8 logicalChannel; /* The logical channel to use. This parameter is ignored if panCoordinator is FALSE */
  617. uint8 channelPage; /* The channel page to use. This parameter is ignored if panCoordinator is FALSE */
  618. uint8 beaconOrder; /* The exponent used to calculate the beacon interval */
  619. uint8 superframeOrder; /* The exponent used to calculate the superframe duration */
  620. bool panCoordinator; /* Set to TRUE to start a network as PAN coordinator */
  621. bool batteryLifeExt; /* If this value is TRUE, the receiver is disabled after MAC_BATT_LIFE_EXT_PERIODS
  622. full backoff periods following the interframe spacing period of the beacon frame */
  623. bool coordRealignment; /* Set to TRUE to transmit a coordinator realignment prior to changing
  624. the superframe configuration */
  625. macSec_t realignSec; /* Security parameters for the coordinator realignment frame */
  626. macSec_t beaconSec; /* Security parameters for the beacon frame */
  627. } macMlmeStartReq_t;
  628. /* MAC_MlmeSyncReq type */
  629. typedef struct
  630. {
  631. uint8 logicalChannel; /* The logical channel to use */
  632. uint8 channelPage; /* The channel page to use */
  633. bool trackBeacon; /* Set to TRUE to continue tracking beacons after synchronizing with the
  634. first beacon. Set to FALSE to only synchronize with the first beacon */
  635. } macMlmeSyncReq_t;
  636. /* MAC_MLME_ASSOCIATE_IND type */
  637. typedef struct
  638. {
  639. macEventHdr_t hdr; /* The event header */
  640. sAddrExt_t deviceAddress; /* The address of the device requesting association */
  641. uint8 capabilityInformation; /* The operational capabilities of the device requesting association */
  642. macSec_t sec; /* The security parameters for this message */
  643. } macMlmeAssociateInd_t;
  644. /* MAC_MLME_ASSOCIATE_CNF type */
  645. typedef struct
  646. {
  647. macEventHdr_t hdr; /* Event header contains the status of the associate attempt */
  648. uint16 assocShortAddress; /* If successful, the short address allocated to this device */
  649. macSec_t sec; /* The security parameters for this message */
  650. } macMlmeAssociateCnf_t;
  651. /* MAC_MLME_DISASSOCIATE_IND type */
  652. typedef struct
  653. {
  654. macEventHdr_t hdr; /* The event header */
  655. sAddrExt_t deviceAddress; /* The address of the device sending the disassociate command */
  656. uint8 disassociateReason; /* The disassociate reason */
  657. macSec_t sec; /* The security parameters for this message */
  658. } macMlmeDisassociateInd_t;
  659. /* MAC_MLME_DISASSOCIATE_CNF type */
  660. typedef struct
  661. {
  662. macEventHdr_t hdr; /* Event header contains the status of the disassociate attempt */
  663. sAddr_t deviceAddress; /* The address of the device that has either requested disassociation
  664. or been instructed to disassociate by its coordinator */
  665. uint16 panId; /* The pan ID of the device that has either requested disassociation
  666. or been instructed to disassociate by its coordinator */
  667. } macMlmeDisassociateCnf_t;
  668. /* MAC_MLME_BEACON_NOTIFY_IND type */
  669. typedef struct
  670. {
  671. macEventHdr_t hdr; /* The event header */
  672. uint8 bsn; /* The beacon sequence number */
  673. macPanDesc_t *pPanDesc; /* The PAN descriptor for the received beacon */
  674. uint8 pendAddrSpec; /* The beacon pending address specification */
  675. uint8 *pAddrList; /* The list of device addresses for which the sender of the beacon has data */
  676. uint8 sduLength; /* The number of bytes in the beacon payload of the beacon frame */
  677. uint8 *pSdu; /* The beacon payload */
  678. } macMlmeBeaconNotifyInd_t;
  679. /* MAC_MLME_ORPHAN_IND type */
  680. typedef struct
  681. {
  682. macEventHdr_t hdr; /* The event header */
  683. sAddrExt_t orphanAddress; /* The address of the orphaned device */
  684. macSec_t sec; /* The security parameters for this message */
  685. } macMlmeOrphanInd_t;
  686. /* MAC_MLME_SCAN_CNF type */
  687. typedef struct
  688. {
  689. macEventHdr_t hdr; /* Event header contains the status of the scan request */
  690. uint8 scanType; /* The type of scan requested */
  691. uint8 channelPage; /* The channel page of the scan */
  692. uint32 unscannedChannels; /* Bit mask of channels that were not scanned */
  693. uint8 resultListSize; /* The number of PAN descriptors returned in the results list */
  694. union
  695. {
  696. uint8 *pEnergyDetect; /* The list of energy measurements, one for each channel scanned */
  697. macPanDesc_t *pPanDescriptor; /* The list of PAN descriptors, one for each beacon found */
  698. } result;
  699. } macMlmeScanCnf_t;
  700. /* MAC_MLME_START_CNF type */
  701. typedef struct
  702. {
  703. macEventHdr_t hdr; /* Event header contains the status of the start request */
  704. } macMlmeStartCnf_t;
  705. /* MAC_MLME_SYNC_LOSS_IND type */
  706. typedef struct
  707. {
  708. macEventHdr_t hdr; /* Event header contains the reason that synchronization was lost */
  709. uint16 panId; /* The PAN ID of the realignment */
  710. uint8 logicalChannel; /* The logical channel of the realignment */
  711. uint8 channelPage; /* The channel page of the realignment */
  712. macSec_t sec; /* The security parameters for this message */
  713. } macMlmeSyncLossInd_t;
  714. /* MAC_MLME_POLL_CNF type */
  715. typedef struct
  716. {
  717. macEventHdr_t hdr; /* Event header contains the status of the poll request */
  718. } macMlmePollCnf_t;
  719. /* MAC_MLME_COMM_STATUS_IND type */
  720. typedef struct
  721. {
  722. macEventHdr_t hdr; /* Event header contains the status for this event */
  723. sAddr_t srcAddr; /* The source address associated with the event */
  724. sAddr_t dstAddr; /* The destination address associated with the event */
  725. uint16 panId; /* The PAN ID associated with the event */
  726. uint8 reason; /* The reason the event was generated */
  727. macSec_t sec; /* The security parameters for this message */
  728. } macMlmeCommStatusInd_t;
  729. /* MAC_MLME_POLL_IND type */
  730. typedef struct
  731. {
  732. macEventHdr_t hdr;
  733. uint16 srcShortAddr; /* Short address of the device sending the data request */
  734. uint16 srcPanId; /* Pan ID of the device sending the data request */
  735. } macMlmePollInd_t;
  736. /* Union of callback structures */
  737. typedef union
  738. {
  739. macEventHdr_t hdr;
  740. macMlmeAssociateInd_t associateInd; /* MAC_MLME_ASSOCIATE_IND */
  741. macMlmeAssociateCnf_t associateCnf; /* MAC_MLME_ASSOCIATE_CNF */
  742. macMlmeDisassociateInd_t disassociateInd; /* MAC_MLME_DISASSOCIATE_IND */
  743. macMlmeDisassociateCnf_t disassociateCnf; /* MAC_MLME_DISASSOCIATE_CNF */
  744. macMlmeBeaconNotifyInd_t beaconNotifyInd; /* MAC_MLME_BEACON_NOTIFY_IND */
  745. macMlmeOrphanInd_t orphanInd; /* MAC_MLME_ORPHAN_IND */
  746. macMlmeScanCnf_t scanCnf; /* MAC_MLME_SCAN_CNF */
  747. macMlmeStartCnf_t startCnf; /* MAC_MLME_START_CNF */
  748. macMlmeSyncLossInd_t syncLossInd; /* MAC_MLME_SYNC_LOSS_IND */
  749. macMlmePollCnf_t pollCnf; /* MAC_MLME_POLL_CNF */
  750. macMlmeCommStatusInd_t commStatusInd; /* MAC_MLME_COMM_STATUS_IND */
  751. macMlmePollInd_t pollInd; /* MAC_MLME_POLL_IND */
  752. macMcpsDataCnf_t dataCnf; /* MAC_MCPS_DATA_CNF */
  753. macMcpsDataInd_t dataInd; /* MAC_MCPS_DATA_IND */
  754. macMcpsPurgeCnf_t purgeCnf; /* MAC_MCPS_PURGE_CNF */
  755. } macCbackEvent_t;
  756. /* Configurable parameters */
  757. typedef struct
  758. {
  759. uint8 txDataMax; /* maximum number of data frames in transmit queue */
  760. uint8 txMax; /* maximum number of frames of all types in transmit queue */
  761. uint8 rxMax; /* maximum number of command and data frames in receive queue */
  762. uint8 dataIndOffset; /* allocate additional bytes in the data indication for
  763. application-defined headers */
  764. bool appPendingQueue; /* determine whether MAC_MLME_POLL_IND will be sent to the application or not
  765. when data request is received and no pending frame is found in the MAC */
  766. } macCfg_t;
  767. /* ------------------------------------------------------------------------------------------------
  768. * Internal Functions
  769. * ------------------------------------------------------------------------------------------------
  770. */
  771. /* These functions are used when creating the OSAL MAC task. They must not be used for any
  772. * other purpose.
  773. */
  774. extern void macTaskInit(uint8 taskId);
  775. extern uint16 macEventLoop(uint8 taskId, uint16 events);
  776. /* ------------------------------------------------------------------------------------------------
  777. * Functions
  778. * ------------------------------------------------------------------------------------------------
  779. */
  780. /**************************************************************************************************
  781. * @fn MAC_Init
  782. *
  783. * @brief This function initializes the MAC subsystem. It must be called once when the
  784. * software system is started and before any other function in the MAC API
  785. * is called.
  786. *
  787. * input parameters
  788. *
  789. * None.
  790. *
  791. * output parameters
  792. *
  793. * None.
  794. *
  795. * @return None.
  796. **************************************************************************************************
  797. */
  798. extern void MAC_Init(void);
  799. /**************************************************************************************************
  800. * @fn MAC_InitDevice
  801. *
  802. * @brief This function initializes the MAC to associate with a non
  803. * beacon-enabled network. This function would be used to
  804. * initialize a device as an RFD. If this function is used it
  805. * must be called during application initialization before any
  806. * other function in the data or management API is called.
  807. *
  808. * input parameters
  809. *
  810. * None.
  811. *
  812. * output parameters
  813. *
  814. * None.
  815. *
  816. * @return None.
  817. **************************************************************************************************
  818. */
  819. extern void MAC_InitDevice(void);
  820. /**************************************************************************************************
  821. * @fn MAC_InitCoord
  822. *
  823. * @brief This function initializes the MAC for operation as a
  824. * coordinator. A coordinator can start a network, accept
  825. * associate requests from other devices, send beacons, send
  826. * indirect data, and other operations. This function would
  827. * be used to initialize a device as an FFD. If this function
  828. * is used it must be called during application initialization
  829. * before any other function in the data or management API
  830. * is called.
  831. *
  832. * input parameters
  833. *
  834. * None.
  835. *
  836. * output parameters
  837. *
  838. * None.
  839. *
  840. * @return None.
  841. **************************************************************************************************
  842. */
  843. extern void MAC_InitCoord(void);
  844. /**************************************************************************************************
  845. * @fn MAC_InitSecurity
  846. *
  847. * @brief This function initializes the MAC to allow use of security.
  848. * If this function is used it must be called during application
  849. * initialization before any other function in the data or
  850. * management API is called.
  851. *
  852. * input parameters
  853. *
  854. * None.
  855. *
  856. * output parameters
  857. *
  858. * None.
  859. *
  860. * @return None.
  861. **************************************************************************************************
  862. */
  863. extern void MAC_InitSecurity(void);
  864. /**************************************************************************************************
  865. * @fn MAC_InitBeaconCoord
  866. *
  867. * @brief This function initializes the MAC for operation as a coordinator in a
  868. * beacon-enabled network. If this function is used it must
  869. * be called during application initialization before any other
  870. * function in the data or management API is called.
  871. *
  872. * input parameters
  873. *
  874. * None.
  875. *
  876. * output parameters
  877. *
  878. * None.
  879. *
  880. * @return None.
  881. **************************************************************************************************
  882. */
  883. extern void MAC_InitBeaconCoord(void);
  884. /**************************************************************************************************
  885. * @fn MAC_InitBeaconTrack
  886. *
  887. * @brief This function initializes the MAC to allow it to associate
  888. * with and track a beacon-enabled network. If this function is
  889. * used it must be called during application initialization
  890. * before any other function in the data or management API
  891. * is called.
  892. *
  893. * input parameters
  894. *
  895. * None.
  896. *
  897. * output parameters
  898. *
  899. * None.
  900. *
  901. * @return None.
  902. **************************************************************************************************
  903. */
  904. extern void MAC_InitBeaconDevice(void);
  905. /**************************************************************************************************
  906. * @fn MAC_McpsDataReq
  907. *
  908. * @brief This function sends application data to the MAC for
  909. * transmission in a MAC data frame.
  910. *
  911. * input parameters
  912. *
  913. * @param pData - Pointer to parameters structure.
  914. *
  915. * output parameters
  916. *
  917. * None.
  918. *
  919. * @return None.
  920. **************************************************************************************************
  921. */
  922. extern void MAC_McpsDataReq(macMcpsDataReq_t *pData);
  923. /**************************************************************************************************
  924. * @fn MAC_McpsPurgeReq
  925. *
  926. * @brief This function purges and discards a data request from the
  927. * MAC data queue. When the operation is complete the MAC sends
  928. * a MAC_MCPS_PURGE_CNF.
  929. *
  930. * input parameters
  931. *
  932. * @param msduHandle - The application-defined handle value
  933. *
  934. * output parameters
  935. *
  936. * None.
  937. *
  938. * @return None.
  939. **************************************************************************************************
  940. */
  941. extern void MAC_McpsPurgeReq(uint8 msduHandle);
  942. /**************************************************************************************************
  943. * @fn MAC_McpsDataAlloc
  944. *
  945. * @brief This direct-execute function simplifies the allocation and
  946. * preparation of the data buffer MAC_McpsDataReq(). The
  947. * function allocates a buffer and prepares the data pointer.
  948. *
  949. * input parameters
  950. *
  951. * @param len - Length of application data in bytes.
  952. * @param securityLevel - Security level used for this frame.
  953. * @param keyIdMode - Key ID mode used for this frame.
  954. *
  955. * output parameters
  956. *
  957. * None.
  958. *
  959. * @return Returns a pointer to the allocated buffer. If the function
  960. * fails for any reason it returns NULL.
  961. **************************************************************************************************
  962. */
  963. extern macMcpsDataReq_t *MAC_McpsDataAlloc(uint8 len, uint8 securityLevel, uint8 keyIdMode);
  964. /**************************************************************************************************
  965. * @fn MAC_MlmeAssociateReq
  966. *
  967. * @brief This function sends an associate request to a coordinator
  968. * device. The application shall attempt to associate only with
  969. * a PAN that is currently allowing association, as indicated
  970. * in the results of the scanning procedure. In a beacon-enabled
  971. * PAN the beacon order and superframe order must be set by using
  972. * MAC_MlmeSetReq() before making the call to MAC_MlmeAssociateReq().
  973. * If not, the associate request frame is likely to be transmitted
  974. * outside the superframe. When the associate request is complete
  975. * the MAC sends a MAC_MLME_ASSOCIATE_CNF to the application.
  976. *
  977. * input parameters
  978. *
  979. * @param pData - Pointer to parameters structure.
  980. *
  981. * output parameters
  982. *
  983. * None.
  984. *
  985. * @return None.
  986. **************************************************************************************************
  987. */
  988. extern void MAC_MlmeAssociateReq(macMlmeAssociateReq_t *pData);
  989. /**************************************************************************************************
  990. * @fn MAC_MlmeAssociateRsp
  991. *
  992. * @brief This function sends an associate response to a device
  993. * requesting to associate. This function must be called after
  994. * receiving a MAC_MLME_ASSOCIATE_IND. When the associate response is
  995. * complete the MAC sends a MAC_MLME_COMM_STATUS_IND to the application
  996. * to indicate the success or failure of the operation.
  997. *
  998. * input parameters
  999. *
  1000. * @param pData - Pointer to parameters structure.
  1001. *
  1002. * output parameters
  1003. *
  1004. * None.
  1005. *
  1006. * @return MAC_SUCCESS or MAC error code.
  1007. **************************************************************************************************
  1008. */
  1009. extern uint8 MAC_MlmeAssociateRsp(macMlmeAssociateRsp_t *pData);
  1010. /**************************************************************************************************
  1011. * @fn MAC_MlmeDisassociateReq
  1012. *
  1013. * @brief This function is used by an associated device to notify the
  1014. * coordinator of its intent to leave the PAN. It is also used
  1015. * by the coordinator to instruct an associated device to leave
  1016. * the PAN. When the disassociate is complete the MAC sends a
  1017. * MAC_MLME_DISASSOCIATE_CNF to the application.
  1018. *
  1019. * input parameters
  1020. *
  1021. * @param pData - Pointer to parameters structure.
  1022. *
  1023. * output parameters
  1024. *
  1025. * None.
  1026. *
  1027. * @return None.
  1028. **************************************************************************************************
  1029. */
  1030. extern void MAC_MlmeDisassociateReq(macMlmeDisassociateReq_t *pData);
  1031. /**************************************************************************************************
  1032. * @fn MAC_MlmeGetReq
  1033. *
  1034. * @brief This direct execute function retrieves an attribute value
  1035. * from the MAC PIB.
  1036. *
  1037. * input parameters
  1038. *
  1039. * @param pibAttribute - The attribute identifier.
  1040. * @param pValue - pointer to the attribute value.
  1041. *
  1042. * output parameters
  1043. *
  1044. * @param pValue - pointer to the attribute value.
  1045. *
  1046. * @return The status of the request, as follows:
  1047. * MAC_SUCCESS Operation successful.
  1048. * MAC_UNSUPPORTED_ATTRIBUTE Attribute not found.
  1049. *
  1050. **************************************************************************************************
  1051. */
  1052. extern uint8 MAC_MlmeGetReq(uint8 pibAttribute, void *pValue);
  1053. /**************************************************************************************************
  1054. * @fn MAC_MlmeGetSecutityReq
  1055. *
  1056. * @brief This direct execute function retrieves an attribute value
  1057. * from the MAC Secutity PIB. This function only exists when MAC_SECURITY
  1058. * is defined.
  1059. *
  1060. * input parameters
  1061. *
  1062. * @param pibAttribute - The attribute identifier.
  1063. * @param pValue - pointer to the attribute value.
  1064. *
  1065. * output parameters
  1066. *
  1067. * @param pValue - pointer to the attribute value.
  1068. *
  1069. * @return The status of the request, as follows:
  1070. * MAC_SUCCESS Operation successful.
  1071. * MAC_UNSUPPORTED_ATTRIBUTE Attribute not found.
  1072. *
  1073. **************************************************************************************************
  1074. */
  1075. extern uint8 MAC_MlmeGetSecurityReq(uint8 pibAttribute, void *pValue);
  1076. /**************************************************************************************************
  1077. * @fn MAC_MlmeOrphanRsp
  1078. *
  1079. * @brief This function is called in response to an orphan notification
  1080. * from a peer device. This function must be called after
  1081. * receiving a MAC_MLME_ORPHAN_IND. When the orphan response is
  1082. * complete the MAC sends a MAC_MLME_COMM_STATUS_IND to the
  1083. * application to indicate the success or failure of the operation.
  1084. *
  1085. * input parameters
  1086. *
  1087. * @param pData - Pointer to parameters structure.
  1088. *
  1089. * output parameters
  1090. *
  1091. * None.
  1092. *
  1093. * @return None.
  1094. **************************************************************************************************
  1095. */
  1096. extern void MAC_MlmeOrphanRsp(macMlmeOrphanRsp_t *pData);
  1097. /**************************************************************************************************
  1098. * @fn MAC_MlmePollReq
  1099. *
  1100. * @brief This function is used to request pending data from the
  1101. * coordinator. When the poll request is complete the MAC sends
  1102. * a MAC_MLME_POLL_CNF to the application. If a data frame of
  1103. * nonzero length is received from the coordinator the MAC sends
  1104. * a MAC_MLME_POLL_CNF with status MAC_SUCCESS and then sends a
  1105. * MAC_MCPS_DATA_IND with the data.
  1106. *
  1107. * input parameters
  1108. *
  1109. * @param pData - Pointer to parameters structure.
  1110. *
  1111. * output parameters
  1112. *
  1113. * None.
  1114. *
  1115. * @return None.
  1116. **************************************************************************************************
  1117. */
  1118. extern void MAC_MlmePollReq(macMlmePollReq_t *pData);
  1119. /**************************************************************************************************
  1120. * @fn MAC_MlmeResetReq
  1121. *
  1122. * @brief This direct execute function resets the MAC. This function
  1123. * must be called once at system startup before any other
  1124. * function in the management API is called.
  1125. *
  1126. * input parameters
  1127. *
  1128. * @param setDefaultPib - Set to TRUE to reset the MAC PIB to its
  1129. * default values.
  1130. *
  1131. * output parameters
  1132. *
  1133. * None.
  1134. *
  1135. * @return Returns MAC_SUCCESS always.
  1136. *
  1137. **************************************************************************************************
  1138. */
  1139. extern uint8 MAC_MlmeResetReq(bool setDefaultPib);
  1140. /**************************************************************************************************
  1141. * @fn MAC_MlmeScanReq
  1142. *
  1143. * @brief This function initiates an energy detect, active, passive,
  1144. * or orphan scan on one or more channels. An energy detect
  1145. * scan measures the peak energy on each requested channel.
  1146. * An active scan sends a beacon request on each channel and
  1147. * then listening for beacons. A passive scan is a receive-only
  1148. * operation that listens for beacons on each channel. An orphan
  1149. * scan is used to locate the coordinator with which the scanning
  1150. * device had previously associated. When a scan operation is
  1151. * complete the MAC sends a MAC_MLME_SCAN_CNF to the application.
  1152. *
  1153. * input parameters
  1154. *
  1155. * @param pData - Pointer to parameters structure.
  1156. *
  1157. * output parameters
  1158. *
  1159. * None.
  1160. *
  1161. * @return None.
  1162. **************************************************************************************************
  1163. */
  1164. extern void MAC_MlmeScanReq(macMlmeScanReq_t *pData);
  1165. /**************************************************************************************************
  1166. * @fn MAC_MlmeSetReq
  1167. *
  1168. * @brief This direct execute function sets an attribute value
  1169. * in the MAC PIB.
  1170. *
  1171. * input parameters
  1172. *
  1173. * @param pibAttribute - The attribute identifier.
  1174. * @param pValue - pointer to the attribute value.
  1175. *
  1176. * output parameters
  1177. *
  1178. * None.
  1179. *
  1180. * @return The status of the request, as follows:
  1181. * MAC_SUCCESS Operation successful.
  1182. * MAC_UNSUPPORTED_ATTRIBUTE Attribute not found.
  1183. *
  1184. **************************************************************************************************
  1185. */
  1186. extern uint8 MAC_MlmeSetReq(uint8 pibAttribute, void *pValue);
  1187. /**************************************************************************************************
  1188. * @fn MAC_MlmeSetSecurityReq
  1189. *
  1190. * @brief This direct execute function sets an attribute value
  1191. * in the MAC Security PIB. This function only exists when MAC_SECURITY
  1192. * is defined.
  1193. *
  1194. * input parameters
  1195. *
  1196. * @param pibAttribute - The attribute identifier.
  1197. * @param pValue - pointer to the attribute value.
  1198. *
  1199. * output parameters
  1200. *
  1201. * None.
  1202. *
  1203. * @return The status of the request, as follows:
  1204. * MAC_SUCCESS Operation successful.
  1205. * MAC_UNSUPPORTED_ATTRIBUTE Attribute not found.
  1206. *
  1207. **************************************************************************************************
  1208. */
  1209. extern uint8 MAC_MlmeSetSecurityReq(uint8 pibAttribute, void *pValue);
  1210. /**************************************************************************************************
  1211. * @fn MAC_MlmeStartReq
  1212. *
  1213. * @brief This function is called by a coordinator or PAN coordinator
  1214. * to start or reconfigure a network. Before starting a
  1215. * network the device must have set its short address. A PAN
  1216. * coordinator sets the short address by setting the attribute
  1217. * MAC_SHORT_ADDRESS. A coordinator sets the short address
  1218. * through association. When the operation is complete the
  1219. * MAC sends a MAC_MLME_START_CNF to the application.
  1220. *
  1221. * input parameters
  1222. *
  1223. * @param pData - Pointer to parameters structure.
  1224. *
  1225. * output parameters
  1226. *
  1227. * None.
  1228. *
  1229. * @return None.
  1230. **************************************************************************************************
  1231. */
  1232. extern void MAC_MlmeStartReq(macMlmeStartReq_t *pData);
  1233. /**************************************************************************************************
  1234. * @fn MAC_MlmeSyncReq
  1235. *
  1236. * @brief This function requests the MAC to synchronize with the
  1237. * coordinator by acquiring and optionally tracking its beacons.
  1238. * Synchronizing with the coordinator is recommended before
  1239. * associating in a beacon-enabled network. If the beacon could
  1240. * not be located on its initial search or during tracking, the
  1241. * MAC sends a MAC_MLME_SYNC_LOSS_IND to the application with
  1242. * status MAC_BEACON_LOSS.
  1243. *
  1244. * input parameters
  1245. *
  1246. * @param pData - Pointer to parameters structure.
  1247. *
  1248. * output parameters
  1249. *
  1250. * None.
  1251. *
  1252. * @return None.
  1253. **************************************************************************************************
  1254. */
  1255. extern void MAC_MlmeSyncReq(macMlmeSyncReq_t *pData);
  1256. /**************************************************************************************************
  1257. * @fn MAC_PwrOffReq
  1258. *
  1259. * @brief This direct execute function requests the MAC to power off
  1260. * the radio hardware and go to sleep. If the MAC is able to
  1261. * power off it will execute its power off procedure and return
  1262. * MAC_SUCCESS. If the MAC is unable to sleep it will return
  1263. * MAC_DENIED. The MAC is unable to sleep when it is executing
  1264. * certain procedures, such as a scan, data request, or association.
  1265. * If this function is called when the MAC is already in sleep mode
  1266. * it will return MAC_SUCCESS but do nothing.
  1267. *
  1268. * input parameters
  1269. *
  1270. * @param mode - The desired low power mode.
  1271. *
  1272. * output parameters
  1273. *
  1274. * None.
  1275. *
  1276. * @return The status of the request, as follows:
  1277. * MAC_SUCCESS Operation successful; the MAC is powered off.
  1278. * MAC_DENIED The MAC was not able to power off.
  1279. **************************************************************************************************
  1280. */
  1281. extern uint8 MAC_PwrOffReq(uint8 mode);
  1282. /**************************************************************************************************
  1283. * @fn MAC_PwrOnReq
  1284. *
  1285. * @brief This function requests the MAC to power on the radio hardware
  1286. * and wake up. When the power on procedure is complete the MAC
  1287. * will send a MAC_PWR_ON_CNF to the application.
  1288. *
  1289. * input parameters
  1290. *
  1291. * None.
  1292. *
  1293. * output parameters
  1294. *
  1295. * None.
  1296. *
  1297. * @return None.
  1298. **************************************************************************************************
  1299. */
  1300. extern void MAC_PwrOnReq(void);
  1301. /**************************************************************************************************
  1302. * @fn MAC_PwrMode
  1303. *
  1304. * @brief This function returns the current power mode of the MAC.
  1305. *
  1306. * input parameters
  1307. *
  1308. * None.
  1309. *
  1310. * output parameters
  1311. *
  1312. * None.
  1313. *
  1314. * @return The current power mode of the MAC.
  1315. **************************************************************************************************
  1316. */
  1317. extern uint8 MAC_PwrMode(void);
  1318. /**************************************************************************************************
  1319. * @fn MAC_PwrNextTimeout
  1320. *
  1321. * @brief This function returns the next MAC timer expiration in 320 usec units. If no
  1322. * timer is running it returns zero.
  1323. *
  1324. * input parameters
  1325. *
  1326. * None.
  1327. *
  1328. * output parameters
  1329. *
  1330. * None.
  1331. *
  1332. * @return The next MAC timer expiration or zero.
  1333. **************************************************************************************************
  1334. */
  1335. extern uint32 MAC_PwrNextTimeout(void);
  1336. /**************************************************************************************************
  1337. * @fn MAC_RandomByte
  1338. *
  1339. * @brief This function returns a random byte from the MAC random number generator.
  1340. *
  1341. * input parameters
  1342. *
  1343. * None.
  1344. *
  1345. * output parameters
  1346. *
  1347. * None.
  1348. *
  1349. * @return A random byte.
  1350. **************************************************************************************************
  1351. */
  1352. extern uint8 MAC_RandomByte(void);
  1353. /**************************************************************************************************
  1354. * @fn MAC_SrcMatchEnable
  1355. *
  1356. * @brief Enabled AUTOPEND and source address matching. if number of source
  1357. * address table entries asked for is more than the hardware
  1358. * supports. It will allocate maximum number of entries and return
  1359. * MAC_INVALID_PARAMETER. This function shall not be called from
  1360. * ISR. It is not thread safe.
  1361. *
  1362. * @param addressType - address type that the application uses
  1363. * SADDR_MODE_SHORT or SADDR_MODE_EXT
  1364. * @param num - number of source address table entries to be used
  1365. *
  1366. * @return MAC_SUCCESS or MAC_INVALID_PARAMETER
  1367. **************************************************************************************************
  1368. */
  1369. extern uint8 MAC_SrcMatchEnable ( uint8 addrType, uint8 num );
  1370. /**************************************************************************************************
  1371. * @fn MAC_SrcMatchAddEntry
  1372. *
  1373. * @brief Add a short or extended address to source address table. This
  1374. * function shall not be called from ISR. It is not thread safe.
  1375. *
  1376. * @param addr - a pointer to sAddr_t which contains addrMode
  1377. * and a union of a short 16-bit MAC address or an extended
  1378. * 64-bit MAC address to be added to the source address table.
  1379. * @param panID - the device PAN ID. It is only used when the addr is
  1380. * using short address
  1381. *
  1382. * @return MAC_SUCCESS or MAC_NO_RESOURCES (source address
  1383. * table full) or MAC_DUPLICATED_ENTRY (the entry added is duplicated),
  1384. * or MAC_INVALID_PARAMETER if the input parameters are invalid.
  1385. **************************************************************************************************
  1386. */
  1387. extern uint8 MAC_SrcMatchAddEntry ( sAddr_t *addr, uint16 panID );
  1388. /**************************************************************************************************
  1389. * @fn MAC_SrcMatchDeleteEntry
  1390. *
  1391. * @brief Delete a short or extended address from source address table.
  1392. * This function shall not be called from ISR. It is not thread safe.
  1393. *
  1394. * @param addr - a pointer to sAddr_t which contains addrMode
  1395. * and a union of a short 16-bit MAC address or an extended
  1396. * 64-bit MAC address to be deleted from the source address table.
  1397. * @param panID - the device PAN ID. It is only used when the addr is
  1398. * using short address
  1399. *
  1400. * @return MAC_SUCCESS or MAC_INVALID_PARAMETER (address to be deleted
  1401. * cannot be found in the source address table).
  1402. **************************************************************************************************
  1403. */
  1404. extern uint8 MAC_SrcMatchDeleteEntry ( sAddr_t *addr, uint16 panID );
  1405. /**************************************************************************************************
  1406. * @fn MAC_SrcMatchAckAllPending
  1407. *
  1408. * @brief Enabled/disable acknowledging all packets with pending bit set
  1409. * The application normally enables it when adding new entries to
  1410. * the source address table fails due to the table is full, or
  1411. * disables it when more entries are deleted and the table has
  1412. * empty slots.
  1413. *
  1414. * @param option - TRUE (acknowledging all packets with pending field set)
  1415. * FALSE (acknowledging all packets with pending field cleared)
  1416. *
  1417. * @return none
  1418. **************************************************************************************************
  1419. */
  1420. extern void MAC_SrcMatchAckAllPending ( uint8 option );
  1421. /**************************************************************************************************
  1422. * @fn MAC_SrcMatchCheckAllPending
  1423. *
  1424. * @brief Check if acknowledging all packets with pending bit set
  1425. * is enabled.
  1426. *
  1427. * @param none
  1428. *
  1429. * @return MAC_AUTOACK_PENDING_ALL_ON or MAC_AUTOACK_PENDING_ALL_OFF
  1430. **************************************************************************************************
  1431. */
  1432. extern uint8 MAC_SrcMatchCheckAllPending ( void );
  1433. /**************************************************************************************************
  1434. * @fn MAC_SelectRadioRegTable
  1435. *
  1436. * @brief Select radio register table in case multiple register tables are included
  1437. * in the build
  1438. *
  1439. * @param txPwrTblIdx - TX power register value table index
  1440. * @param rssiAdjIdx - RSSI adjustment value index
  1441. *
  1442. * @return none
  1443. **************************************************************************************************
  1444. */
  1445. extern void MAC_SetRadioRegTable ( uint8 txPwrTblIdx, uint8 rssiAdjIdx );
  1446. /**************************************************************************************************
  1447. * @fn MAC_CbackEvent
  1448. *
  1449. * @brief This callback function sends MAC events to the application.
  1450. * The application must implement this function. A typical
  1451. * implementation of this function would allocate an OSAL message,
  1452. * copy the event parameters to the message, and send the message
  1453. * to the application's OSAL event handler. This function may be
  1454. * executed from task or interrupt context and therefore must
  1455. * be reentrant.
  1456. *
  1457. * input parameters
  1458. *
  1459. * @param pData - Pointer to parameters structure.
  1460. *
  1461. * output parameters
  1462. *
  1463. * None.
  1464. *
  1465. * @return None.
  1466. **************************************************************************************************
  1467. */
  1468. extern void MAC_CbackEvent(macCbackEvent_t *pData);
  1469. /**************************************************************************************************
  1470. * @fn MAC_CbackCheckPending
  1471. *
  1472. * @brief This callback function returns the number of pending indirect messages queued in
  1473. * the application. Most applications do not queue indirect data and can simply
  1474. * always return zero. The number of pending indirect messages only needs to be
  1475. * returned if macCfg.appPendingQueue to TRUE.
  1476. *
  1477. * input parameters
  1478. *
  1479. * None.
  1480. *
  1481. * output parameters
  1482. *
  1483. * None.
  1484. *
  1485. * @return The number of indirect messages queued in the application or zero.
  1486. **************************************************************************************************
  1487. */
  1488. extern uint8 MAC_CbackCheckPending(void);
  1489. /**************************************************************************************************
  1490. */
  1491. #ifdef __cplusplus
  1492. };
  1493. #endif
  1494. #endif /* MAC_API_H */