mac_api.h 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451
  1. /**************************************************************************************************
  2. Filename: mac_api.h
  3. Revised: $Date: 2009-02-11 12:35:27 -0800 (Wed, 11 Feb 2009) $
  4. Revision: $Revision: 19083 $
  5. Description: Public interface file for 802.15.4 MAC.
  6. Copyright 2005-2009 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. /* Data constants */
  135. #if !defined ( MAC_MAX_FRAME_SIZE )
  136. #define MAC_MAX_FRAME_SIZE 102 /* Maximum application data length without security */
  137. #endif
  138. #define MAC_DATA_OFFSET 24 /* Bytes required for MAC header in data frame */
  139. #define MAC_ENC_OFFSET 5 /* Data offset required for encryption header */
  140. #define MAC_MIC_32_LEN 4 /* Length required for MIC-32 authentication */
  141. #define MAC_MIC_64_LEN 8 /* Length required for MIC-64 authentication */
  142. #define MAC_MIC_128_LEN 16 /* Length required for MIC-128 authentication */
  143. /* TX Options */
  144. #define MAC_TXOPTION_ACK 0x01 /* Acknowledged transmission. The MAC will attempt to retransmit
  145. the frame until it is acknowledged */
  146. #define MAC_TXOPTION_GTS 0x02 /* GTS transmission (unused) */
  147. #define MAC_TXOPTION_INDIRECT 0x04 /* Indirect transmission. The MAC will queue the data and wait
  148. for the destination device to poll for it. This can only be used
  149. by a coordinator device */
  150. #define MAC_TXOPTION_NO_RETRANS 0x10 /* This proprietary option prevents the frame from being retransmitted */
  151. #define MAC_TXOPTION_NO_CNF 0x20 /* This proprietary option prevents a MAC_MCPS_DATA_CNF
  152. event from being sent for this frame */
  153. #define MAC_TXOPTION_ALT_BE 0x40 /* Use PIB value MAC_ALT_BE for the minimum backoff exponent */
  154. #define MAC_TXOPTION_PWR_CHAN 0x80 /* Use the power and channel values in macDataReq_t
  155. instead of the PIB values */
  156. /* Channels */
  157. #define MAC_CHAN_11 11
  158. #define MAC_CHAN_12 12
  159. #define MAC_CHAN_13 13
  160. #define MAC_CHAN_14 14
  161. #define MAC_CHAN_15 15
  162. #define MAC_CHAN_16 16
  163. #define MAC_CHAN_17 17
  164. #define MAC_CHAN_18 18
  165. #define MAC_CHAN_19 19
  166. #define MAC_CHAN_20 20
  167. #define MAC_CHAN_21 21
  168. #define MAC_CHAN_22 22
  169. #define MAC_CHAN_23 23
  170. #define MAC_CHAN_24 24
  171. #define MAC_CHAN_25 25
  172. #define MAC_CHAN_26 26
  173. #define MAC_CHAN_27 27
  174. #define MAC_CHAN_28 28
  175. /* This macro converts a channel to a mask */
  176. #define MAC_CHAN_MASK(chan) ((uint32) 1 << (chan))
  177. /* Channel Masks */
  178. #define MAC_CHAN_11_MASK MAC_CHAN_MASK(MAC_CHAN_11)
  179. #define MAC_CHAN_12_MASK MAC_CHAN_MASK(MAC_CHAN_12)
  180. #define MAC_CHAN_13_MASK MAC_CHAN_MASK(MAC_CHAN_13)
  181. #define MAC_CHAN_14_MASK MAC_CHAN_MASK(MAC_CHAN_14)
  182. #define MAC_CHAN_15_MASK MAC_CHAN_MASK(MAC_CHAN_15)
  183. #define MAC_CHAN_16_MASK MAC_CHAN_MASK(MAC_CHAN_16)
  184. #define MAC_CHAN_17_MASK MAC_CHAN_MASK(MAC_CHAN_17)
  185. #define MAC_CHAN_18_MASK MAC_CHAN_MASK(MAC_CHAN_18)
  186. #define MAC_CHAN_19_MASK MAC_CHAN_MASK(MAC_CHAN_19)
  187. #define MAC_CHAN_20_MASK MAC_CHAN_MASK(MAC_CHAN_20)
  188. #define MAC_CHAN_21_MASK MAC_CHAN_MASK(MAC_CHAN_21)
  189. #define MAC_CHAN_22_MASK MAC_CHAN_MASK(MAC_CHAN_22)
  190. #define MAC_CHAN_23_MASK MAC_CHAN_MASK(MAC_CHAN_23)
  191. #define MAC_CHAN_24_MASK MAC_CHAN_MASK(MAC_CHAN_24)
  192. #define MAC_CHAN_25_MASK MAC_CHAN_MASK(MAC_CHAN_25)
  193. #define MAC_CHAN_26_MASK MAC_CHAN_MASK(MAC_CHAN_26)
  194. #define MAC_CHAN_27_MASK MAC_CHAN_MASK(MAC_CHAN_27)
  195. #define MAC_CHAN_28_MASK MAC_CHAN_MASK(MAC_CHAN_28)
  196. /* Channel Page */
  197. #define MAC_CHANNEL_PAGE_0 0 /* 2.4 GHz band using O-QPSK */
  198. #define MAC_CHANNEL_PAGE_1 1 /* 868 and 915 MHz bands using ASK */
  199. #define MAC_CHANNEL_PAGE_2 2 /* 868 and 915 MHz bands using O-QPSK */
  200. /* Capability Information */
  201. #define MAC_CAPABLE_PAN_COORD 0x01 /* Device is capable of becoming a PAN coordinator */
  202. #define MAC_CAPABLE_FFD 0x02 /* Device is an FFD */
  203. #define MAC_CAPABLE_MAINS_POWER 0x04 /* Device is mains powered rather than battery powered */
  204. #define MAC_CAPABLE_RX_ON_IDLE 0x08 /* Device has its receiver on when idle */
  205. #define MAC_CAPABLE_SECURITY 0x40 /* Device is capable of sending and receiving secured frames */
  206. #define MAC_CAPABLE_ALLOC_ADDR 0x80 /* Request allocation of a short address in the associate procedure */
  207. /* Standard PIB Get and Set Attributes */
  208. #define MAC_ACK_WAIT_DURATION 0x40 /* The maximum number of symbols to wait for an acknowledgment frame */
  209. #define MAC_ASSOCIATION_PERMIT 0x41 /* TRUE if a coordinator is currently allowing association */
  210. #define MAC_AUTO_REQUEST 0x42 /* TRUE if a device automatically sends a data request if its address
  211. is listed in the beacon frame */
  212. #define MAC_BATT_LIFE_EXT 0x43 /* TRUE if battery life extension is enabled */
  213. #define MAC_BATT_LIFE_EXT_PERIODS 0x44 /* The number of backoff periods during which the receiver is
  214. enabled following a beacon in battery life extension mode */
  215. #define MAC_BEACON_PAYLOAD 0x45 /* The contents of the beacon payload */
  216. #define MAC_BEACON_PAYLOAD_LENGTH 0x46 /* The length in bytes of the beacon payload */
  217. #define MAC_BEACON_ORDER 0x47 /* How often the coordinator transmits a beacon */
  218. #define MAC_BEACON_TX_TIME 0x48 /* The time the device transmitted its last beacon frame,
  219. in backoff period units */
  220. #define MAC_BSN 0x49 /* The beacon sequence number */
  221. #define MAC_COORD_EXTENDED_ADDRESS 0x4A /* The extended address of the coordinator with which the device
  222. is associated */
  223. #define MAC_COORD_SHORT_ADDRESS 0x4B /* The short address assigned to the coordinator with which the
  224. device is associated. A value of MAC_ADDR_USE_EXT indicates
  225. that the coordinator is using its extended address */
  226. #define MAC_DSN 0x4C /* The data or MAC command frame sequence number */
  227. #define MAC_GTS_PERMIT 0x4D /* TRUE if the PAN coordinator accepts GTS requests */
  228. #define MAC_MAX_CSMA_BACKOFFS 0x4E /* The maximum number of backoffs the CSMA-CA algorithm will attempt
  229. before declaring a channel failure */
  230. #define MAC_MIN_BE 0x4F /* The minimum value of the backoff exponent in the CSMA-CA algorithm.
  231. If this value is set to 0, collision avoidance is disabled during
  232. the first iteration of the algorithm. Also for the slotted version
  233. of the CSMA-CA algorithm with the battery life extension enabled,
  234. the minimum value of the backoff exponent will be at least 2 */
  235. #define MAC_PAN_ID 0x50 /* The PAN identifier. If this value is 0xffff, the device is not
  236. associated */
  237. #define MAC_PROMISCUOUS_MODE 0x51 /* TRUE if the MAC is in promiscuous mode */
  238. #define MAC_RX_ON_WHEN_IDLE 0x52 /* TRUE if the MAC enables its receiver during idle periods */
  239. #define MAC_SHORT_ADDRESS 0x53 /* The short address that the device uses to communicate in the PAN.
  240. If the device is a PAN coordinator, this value shall be set before
  241. calling MAC_StartReq(). Otherwise the value is allocated during
  242. association. Value MAC_ADDR_USE_EXT indicates that the device is
  243. associated but not using a short address */
  244. #define MAC_SUPERFRAME_ORDER 0x54 /* This specifies the length of the active portion of the superframe */
  245. #define MAC_TRANSACTION_PERSISTENCE_TIME 0x55 /* The maximum time in beacon intervals that a transaction is stored by
  246. a coordinator and indicated in the beacon */
  247. #define MAC_ASSOCIATED_PAN_COORD 0x56 /* TRUE if the device is associated to the PAN coordinator */
  248. #define MAC_MAX_BE 0x57 /* The maximum value of the backoff exponent in the CSMA-CA algorithm */
  249. #define MAC_MAX_FRAME_TOTAL_WAIT_TIME 0x58 /* The maximum number of CAP symbols in a beacon-enabled PAN, or
  250. symbols in a non beacon-enabled PAN, to wait for a frame intended
  251. as a response to a data request frame */
  252. #define MAC_MAX_FRAME_RETRIES 0x59 /* The maximum number of retries allowed after a transmission failure */
  253. #define MAC_RESPONSE_WAIT_TIME 0x5A /* The maximum number of symbols a device shall wait for a response
  254. command to be available following a request command in multiples
  255. of aBaseSuperframeDuration */
  256. #define MAC_SYNC_SYMBOL_OFFSET 0x5B /* The timestamp offset from SFD in symbols */
  257. #define MAC_TIMESTAMP_SUPPORTED 0x5C /* TRUE if the MAC supports RX and TX timestamps */
  258. #define MAC_SECURITY_ENABLED 0x5D /* TRUE if security is enabled */
  259. /* Proprietary PIB Get and Set Attributes */
  260. #define MAC_PHY_TRANSMIT_POWER 0xE0 /* The transmit power in units of -1 dBm */
  261. #define MAC_LOGICAL_CHANNEL 0xE1 /* The logical channel */
  262. #define MAC_EXTENDED_ADDRESS 0xE2 /* The extended address of the device */
  263. #define MAC_ALT_BE 0xE3 /* alternate minimum backoff exponent */
  264. /* Disassociate Reason */
  265. #define MAC_DISASSOC_COORD 1 /* The coordinator wishes the device to disassociate */
  266. #define MAC_DISASSOC_DEVICE 2 /* The device itself wishes to disassociate */
  267. /* Scan Type */
  268. #define MAC_SCAN_ED 0 /* Energy detect scan. The device will tune to each channel and
  269. perform and energy measurement. The list of channels and their
  270. associated measurements will be returned at the end of the scan */
  271. #define MAC_SCAN_ACTIVE 1 /* Active scan. The device tunes to each channel, sends a beacon
  272. request and listens for beacons. The PAN descriptors are returned
  273. at the end of the scan */
  274. #define MAC_SCAN_PASSIVE 2 /* Passive scan. The device tunes to each channel and listens for
  275. beacons. The PAN descriptors are returned at the end of the scan */
  276. #define MAC_SCAN_ORPHAN 3 /* Orphan scan. The device tunes to each channel and sends an orphan
  277. notification to try and find its coordinator. The status is returned
  278. at the end of the scan */
  279. /* Special address values */
  280. #define MAC_ADDR_USE_EXT 0xFFFE /* Short address value indicating extended address is used */
  281. #define MAC_SHORT_ADDR_BROADCAST 0xFFFF /* Broadcast short address */
  282. #define MAC_SHORT_ADDR_NONE 0xFFFF /* Short address when there is no short address */
  283. /* Comm status indication reasons */
  284. #define MAC_COMM_ASSOCIATE_RSP 0 /* Event sent in response to MAC_AssociateRsp() */
  285. #define MAC_COMM_ORPHAN_RSP 1 /* Event sent in response to MAC_OrphanRsp() */
  286. #define MAC_COMM_RX_SECURE 2 /* Event sent as a result of receiving a secure frame */
  287. /* Power Mode */
  288. #define MAC_PWR_ON 0 /* MAC and radio hardware is powered on */
  289. #define MAC_PWR_SLEEP_LITE 1 /* MAC and radio hardware are partially powered off */
  290. #define MAC_PWR_SLEEP_DEEP 2 /* MAC and radio hardware are fully powered off */
  291. /* MAC Callback Events */
  292. #define MAC_MLME_ASSOCIATE_IND 1 /* Associate indication */
  293. #define MAC_MLME_ASSOCIATE_CNF 2 /* Associate confirm */
  294. #define MAC_MLME_DISASSOCIATE_IND 3 /* Disassociate indication */
  295. #define MAC_MLME_DISASSOCIATE_CNF 4 /* Disassociate confirm */
  296. #define MAC_MLME_BEACON_NOTIFY_IND 5 /* Beacon notify indication */
  297. #define MAC_MLME_ORPHAN_IND 6 /* Orphan indication */
  298. #define MAC_MLME_SCAN_CNF 7 /* Scan confirm */
  299. #define MAC_MLME_START_CNF 8 /* Start confirm */
  300. #define MAC_MLME_SYNC_LOSS_IND 9 /* Sync loss indication */
  301. #define MAC_MLME_POLL_CNF 10 /* Poll confirm */
  302. #define MAC_MLME_COMM_STATUS_IND 11 /* Communication status indication */
  303. #define MAC_MCPS_DATA_CNF 12 /* Data confirm */
  304. #define MAC_MCPS_DATA_IND 13 /* Data indication */
  305. #define MAC_MCPS_PURGE_CNF 14 /* Purge confirm */
  306. #define MAC_PWR_ON_CNF 15 /* Power on confirm */
  307. #define MAC_MLME_POLL_IND 16 /* Poll indication */
  308. /* ------------------------------------------------------------------------------------------------
  309. * Macros
  310. * ------------------------------------------------------------------------------------------------
  311. */
  312. /* Returns the number of short addresses in the pending address specification */
  313. #define MAC_PEND_NUM_SHORT(pendAddrSpec) ((pendAddrSpec) & 0x07)
  314. /* Returns the number of extended addresses in the pending address specification */
  315. #define MAC_PEND_NUM_EXT(pendAddrSpec) (((pendAddrSpec) & 0x70) >> 4)
  316. /* Returns the length in bytes of the pending address fields in the beacon */
  317. #define MAC_PEND_FIELDS_LEN(pendAddrSpec) ((MAC_PEND_NUM_SHORT(pendAddrSpec) * 2) + \
  318. (MAC_PEND_NUM_EXT(pendAddrSpec) * 8))
  319. /* The following macros are provided to help parse the superframe specification */
  320. #define MAC_SFS_BEACON_ORDER(s) ((s) & 0x0F) /* returns the beacon order */
  321. #define MAC_SFS_SUPERFRAME_ORDER(s) (((s) >> 4) & 0x0F) /* returns the beacon order */
  322. #define MAC_SFS_FINAL_CAP_SLOT(s) (((s) >> 8) & 0x0F) /* returns the final CAP slot */
  323. #define MAC_SFS_BLE(s) (((s) >> 12) & 0x01) /* returns the battery life extension bit */
  324. #define MAC_SFS_PAN_COORDINATOR(s) (((s) >> 14) & 0x01) /* returns the PAN coordinator bit */
  325. #define MAC_SFS_ASSOCIATION_PERMIT(s) ((s) >> 15) /* returns the association permit bit */
  326. /* ------------------------------------------------------------------------------------------------
  327. * Typedefs
  328. * ------------------------------------------------------------------------------------------------
  329. */
  330. /* MAC event header type */
  331. typedef struct
  332. {
  333. uint8 event; /* MAC event */
  334. uint8 status; /* MAC status */
  335. } macEventHdr_t;
  336. /* Common security type */
  337. typedef struct
  338. {
  339. uint8 keySource[MAC_KEY_SOURCE_MAX_LEN]; /* Key source */
  340. uint8 securityLevel; /* Security level */
  341. uint8 keyIdMode; /* Key identifier mode */
  342. uint8 keyIndex; /* Key index */
  343. } macSec_t;
  344. /* For internal use only */
  345. typedef struct
  346. {
  347. uint32 timestamp;
  348. uint16 timestamp2;
  349. uint16 timeToLive;
  350. uint8 frameType;
  351. uint8 txOptions;
  352. uint8 txMode;
  353. uint8 txSched;
  354. uint8 retries;
  355. uint8 channel;
  356. uint8 power;
  357. uint8 mpduLinkQuality;
  358. uint8 correlation;
  359. int8 rssi;
  360. } macTxIntData_t;
  361. /* For internal use only */
  362. typedef struct
  363. {
  364. uint8 frameType;
  365. uint8 flags;
  366. } macRxIntData_t;
  367. /* Data request parameters type */
  368. typedef struct
  369. {
  370. sAddr_t dstAddr; /* The address of the destination device */
  371. uint16 dstPanId; /* The PAN ID of the destination device */
  372. uint8 srcAddrMode; /* The source address mode */
  373. uint8 msduHandle; /* Application-defined handle value associated with this data request */
  374. uint8 txOptions; /* TX options bit mask */
  375. uint8 channel; /* Transmit the data frame on this channel */
  376. uint8 power; /* Transmit the data frame at this power level */
  377. } macDataReq_t;
  378. /* MCPS data request type */
  379. typedef struct
  380. {
  381. macEventHdr_t hdr; /* Internal use only */
  382. sData_t msdu; /* Data pointer and length */
  383. macTxIntData_t internal; /* Internal use only */
  384. macSec_t sec; /* Security parameters */
  385. macDataReq_t mac; /* Data request parameters */
  386. } macMcpsDataReq_t;
  387. /* Data indication parameters type */
  388. typedef struct
  389. {
  390. sAddr_t srcAddr; /* The address of the sending device */
  391. sAddr_t dstAddr; /* The address of the destination device */
  392. uint32 timestamp; /* The time, in backoffs, at which the data were received */
  393. uint16 timestamp2; /* The time, in internal MAC timer units, at which the
  394. data were received */
  395. uint16 srcPanId; /* The PAN ID of the sending device */
  396. uint16 dstPanId; /* The PAN ID of the destination device */
  397. uint8 mpduLinkQuality; /* The link quality of the received data frame */
  398. uint8 correlation; /* The raw correlation value of the received data frame */
  399. int8 rssi; /* The received RF power in units dBm */
  400. uint8 dsn; /* The data sequence number of the received frame */
  401. } macDataInd_t;
  402. /* MCPS data indication type */
  403. typedef struct
  404. {
  405. macEventHdr_t hdr; /* Internal use only */
  406. sData_t msdu; /* Data pointer and length */
  407. macRxIntData_t internal; /* Internal use only */
  408. macSec_t sec; /* Security parameters */
  409. macDataInd_t mac; /* Data indication parameters */
  410. } macMcpsDataInd_t;
  411. /* MCPS data confirm type */
  412. typedef struct
  413. {
  414. macEventHdr_t hdr; /* Contains the status of the data request operation */
  415. uint8 msduHandle; /* Application-defined handle value associated with the data request */
  416. macMcpsDataReq_t *pDataReq; /* Pointer to the data request buffer for this data confirm */
  417. uint32 timestamp; /* The time, in backoffs, at which the frame was transmitted */
  418. uint16 timestamp2; /* The time, in internal MAC timer units, at which the
  419. frame was transmitted */
  420. uint8 retries; /* The number of retries required to transmit the data frame */
  421. uint8 mpduLinkQuality; /* The link quality of the received ack frame */
  422. uint8 correlation; /* The raw correlation value of the received ack frame */
  423. int8 rssi; /* The RF power of the received ack frame in units dBm */
  424. } macMcpsDataCnf_t;
  425. /* MCPS purge confirm type */
  426. typedef struct
  427. {
  428. macEventHdr_t hdr; /* Contains the status of the purge request operation */
  429. uint8 msduHandle; /* Application-defined handle value associated with the data request */
  430. } macMcpsPurgeCnf_t;
  431. /* PAN descriptor type */
  432. typedef struct
  433. {
  434. sAddr_t coordAddress; /* The address of the coordinator sending the beacon */
  435. uint16 coordPanId; /* The PAN ID of the network */
  436. uint16 superframeSpec; /* The superframe specification of the network */
  437. uint8 logicalChannel; /* The logical channel of the network */
  438. uint8 channelPage; /* The current channel page occupied by the network */
  439. bool gtsPermit; /* TRUE if coordinator accepts GTS requests */
  440. uint8 linkQuality; /* The link quality of the received beacon */
  441. uint32 timestamp; /* The time at which the beacon was received, in backoffs */
  442. bool securityFailure; /* Set to TRUE if there was an error in the security processing */
  443. macSec_t sec; /* The security parameters for the received beacon frame */
  444. } macPanDesc_t;
  445. /* MLME associate request type */
  446. typedef struct
  447. {
  448. uint8 logicalChannel; /* The channel on which to attempt association */
  449. uint8 channelPage; /* The channel page on which to attempt association */
  450. sAddr_t coordAddress; /* Address of the coordinator with which to associate */
  451. uint16 coordPanId; /* The identifier of the PAN with which to associate */
  452. uint8 capabilityInformation; /* The operational capabilities of this device */
  453. macSec_t sec; /* The security parameters for this message */
  454. } macMlmeAssociateReq_t;
  455. /* MLME associate response type */
  456. typedef struct
  457. {
  458. sAddrExt_t deviceAddress; /* The address of the device requesting association */
  459. uint16 assocShortAddress; /* The short address allocated to the device */
  460. uint8 status; /* The status of the association attempt */
  461. macSec_t sec; /* The security parameters for this message */
  462. } macMlmeAssociateRsp_t;
  463. /* MLME disassociate request type */
  464. typedef struct
  465. {
  466. sAddr_t deviceAddress; /* The address of the device with which to disassociate */
  467. uint16 devicePanId; /* The PAN ID of the device */
  468. uint8 disassociateReason; /* The disassociate reason */
  469. bool txIndirect; /* Transmit Indirect */
  470. macSec_t sec; /* The security parameters for this message */
  471. } macMlmeDisassociateReq_t;
  472. /* MLME orphan response type */
  473. typedef struct
  474. {
  475. sAddrExt_t orphanAddress; /* The extended address of the device sending the orphan notification */
  476. uint16 shortAddress; /* The short address of the orphaned device */
  477. bool associatedMember; /* Set to TRUE if the orphaned device is associated with this coordinator */
  478. macSec_t sec; /* The security parameters for this message */
  479. } macMlmeOrphanRsp_t;
  480. /* MLME poll request type */
  481. typedef struct
  482. {
  483. sAddr_t coordAddress; /* The address of the coordinator device to poll */
  484. uint16 coordPanId; /* The PAN ID of the coordinator */
  485. macSec_t sec; /* The security parameters for this message */
  486. } macMlmePollReq_t;
  487. /* MLME scan request type */
  488. typedef struct
  489. {
  490. uint32 scanChannels; /* Bit mask indicating which channels to scan */
  491. uint8 scanType; /* The type of scan */
  492. uint8 scanDuration; /* The exponent used in the scan duration calculation */
  493. uint8 channelPage; /* The channel page on which to perform the scan */
  494. uint8 maxResults; /* The maximum number of PAN descriptor results */
  495. macSec_t sec; /* The security parameters for orphan scan */
  496. union {
  497. uint8 *pEnergyDetect; /* Pointer to a buffer to store energy detect measurements */
  498. macPanDesc_t *pPanDescriptor; /* Pointer to a buffer to store PAN descriptors */
  499. } result;
  500. } macMlmeScanReq_t;
  501. /* MLME start request type */
  502. typedef struct
  503. {
  504. uint32 startTime; /* The time to begin transmitting beacons relative to the received beacon */
  505. uint16 panId; /* The PAN ID to use. This parameter is ignored if panCoordinator is FALSE */
  506. uint8 logicalChannel; /* The logical channel to use. This parameter is ignored if panCoordinator is FALSE */
  507. uint8 channelPage; /* The channel page to use. This parameter is ignored if panCoordinator is FALSE */
  508. uint8 beaconOrder; /* The exponent used to calculate the beacon interval */
  509. uint8 superframeOrder; /* The exponent used to calculate the superframe duration */
  510. bool panCoordinator; /* Set to TRUE to start a network as PAN coordinator */
  511. bool batteryLifeExt; /* If this value is TRUE, the receiver is disabled after MAC_BATT_LIFE_EXT_PERIODS
  512. full backoff periods following the interframe spacing period of the beacon frame */
  513. bool coordRealignment; /* Set to TRUE to transmit a coordinator realignment prior to changing
  514. the superframe configuration */
  515. macSec_t realignSec; /* Security parameters for the coordinator realignment frame */
  516. macSec_t beaconSec; /* Security parameters for the beacon frame */
  517. } macMlmeStartReq_t;
  518. /* MAC_MlmeSyncReq type */
  519. typedef struct
  520. {
  521. uint8 logicalChannel; /* The logical channel to use */
  522. uint8 channelPage; /* The channel page to use */
  523. bool trackBeacon; /* Set to TRUE to continue tracking beacons after synchronizing with the
  524. first beacon. Set to FALSE to only synchronize with the first beacon */
  525. } macMlmeSyncReq_t;
  526. /* MAC_MLME_ASSOCIATE_IND type */
  527. typedef struct
  528. {
  529. macEventHdr_t hdr; /* The event header */
  530. sAddrExt_t deviceAddress; /* The address of the device requesting association */
  531. uint8 capabilityInformation; /* The operational capabilities of the device requesting association */
  532. macSec_t sec; /* The security parameters for this message */
  533. } macMlmeAssociateInd_t;
  534. /* MAC_MLME_ASSOCIATE_CNF type */
  535. typedef struct
  536. {
  537. macEventHdr_t hdr; /* Event header contains the status of the associate attempt */
  538. uint16 assocShortAddress; /* If successful, the short address allocated to this device */
  539. macSec_t sec; /* The security parameters for this message */
  540. } macMlmeAssociateCnf_t;
  541. /* MAC_MLME_DISASSOCIATE_IND type */
  542. typedef struct
  543. {
  544. macEventHdr_t hdr; /* The event header */
  545. sAddrExt_t deviceAddress; /* The address of the device sending the disassociate command */
  546. uint8 disassociateReason; /* The disassociate reason */
  547. macSec_t sec; /* The security parameters for this message */
  548. } macMlmeDisassociateInd_t;
  549. /* MAC_MLME_DISASSOCIATE_CNF type */
  550. typedef struct
  551. {
  552. macEventHdr_t hdr; /* Event header contains the status of the disassociate attempt */
  553. sAddr_t deviceAddress; /* The address of the device that has either requested disassociation
  554. or been instructed to disassociate by its coordinator */
  555. uint16 panId; /* The pan ID of the device that has either requested disassociation
  556. or been instructed to disassociate by its coordinator */
  557. } macMlmeDisassociateCnf_t;
  558. /* MAC_MLME_BEACON_NOTIFY_IND type */
  559. typedef struct
  560. {
  561. macEventHdr_t hdr; /* The event header */
  562. uint8 bsn; /* The beacon sequence number */
  563. macPanDesc_t *pPanDesc; /* The PAN descriptor for the received beacon */
  564. uint8 pendAddrSpec; /* The beacon pending address specification */
  565. uint8 *pAddrList; /* The list of device addresses for which the sender of the beacon has data */
  566. uint8 sduLength; /* The number of bytes in the beacon payload of the beacon frame */
  567. uint8 *pSdu; /* The beacon payload */
  568. } macMlmeBeaconNotifyInd_t;
  569. /* MAC_MLME_ORPHAN_IND type */
  570. typedef struct
  571. {
  572. macEventHdr_t hdr; /* The event header */
  573. sAddrExt_t orphanAddress; /* The address of the orphaned device */
  574. macSec_t sec; /* The security parameters for this message */
  575. } macMlmeOrphanInd_t;
  576. /* MAC_MLME_SCAN_CNF type */
  577. typedef struct
  578. {
  579. macEventHdr_t hdr; /* Event header contains the status of the scan request */
  580. uint8 scanType; /* The type of scan requested */
  581. uint8 channelPage; /* The channel page of the scan */
  582. uint32 unscannedChannels; /* Bit mask of channels that were not scanned */
  583. uint8 resultListSize; /* The number of PAN descriptors returned in the results list */
  584. union
  585. {
  586. uint8 *pEnergyDetect; /* The list of energy measurements, one for each channel scanned */
  587. macPanDesc_t *pPanDescriptor; /* The list of PAN descriptors, one for each beacon found */
  588. } result;
  589. } macMlmeScanCnf_t;
  590. /* MAC_MLME_START_CNF type */
  591. typedef struct
  592. {
  593. macEventHdr_t hdr; /* Event header contains the status of the start request */
  594. } macMlmeStartCnf_t;
  595. /* MAC_MLME_SYNC_LOSS_IND type */
  596. typedef struct
  597. {
  598. macEventHdr_t hdr; /* Event header contains the reason that synchronization was lost */
  599. uint16 panId; /* The PAN ID of the realignment */
  600. uint8 logicalChannel; /* The logical channel of the realignment */
  601. uint8 channelPage; /* The channel page of the realignment */
  602. macSec_t sec; /* The security parameters for this message */
  603. } macMlmeSyncLossInd_t;
  604. /* MAC_MLME_POLL_CNF type */
  605. typedef struct
  606. {
  607. macEventHdr_t hdr; /* Event header contains the status of the poll request */
  608. } macMlmePollCnf_t;
  609. /* MAC_MLME_COMM_STATUS_IND type */
  610. typedef struct
  611. {
  612. macEventHdr_t hdr; /* Event header contains the status for this event */
  613. sAddr_t srcAddr; /* The source address associated with the event */
  614. sAddr_t dstAddr; /* The destination address associated with the event */
  615. uint16 panId; /* The PAN ID associated with the event */
  616. uint8 reason; /* The reason the event was generated */
  617. macSec_t sec; /* The security parameters for this message */
  618. } macMlmeCommStatusInd_t;
  619. /* MAC_MLME_POLL_IND type */
  620. typedef struct
  621. {
  622. macEventHdr_t hdr;
  623. uint16 srcShortAddr; /* Short address of the device sending the data request */
  624. uint16 srcPanId; /* Pan ID of the device sending the data request */
  625. } macMlmePollInd_t;
  626. /* Union of callback structures */
  627. typedef union
  628. {
  629. macEventHdr_t hdr;
  630. macMlmeAssociateInd_t associateInd; /* MAC_MLME_ASSOCIATE_IND */
  631. macMlmeAssociateCnf_t associateCnf; /* MAC_MLME_ASSOCIATE_CNF */
  632. macMlmeDisassociateInd_t disassociateInd; /* MAC_MLME_DISASSOCIATE_IND */
  633. macMlmeDisassociateCnf_t disassociateCnf; /* MAC_MLME_DISASSOCIATE_CNF */
  634. macMlmeBeaconNotifyInd_t beaconNotifyInd; /* MAC_MLME_BEACON_NOTIFY_IND */
  635. macMlmeOrphanInd_t orphanInd; /* MAC_MLME_ORPHAN_IND */
  636. macMlmeScanCnf_t scanCnf; /* MAC_MLME_SCAN_CNF */
  637. macMlmeStartCnf_t startCnf; /* MAC_MLME_START_CNF */
  638. macMlmeSyncLossInd_t syncLossInd; /* MAC_MLME_SYNC_LOSS_IND */
  639. macMlmePollCnf_t pollCnf; /* MAC_MLME_POLL_CNF */
  640. macMlmeCommStatusInd_t commStatusInd; /* MAC_MLME_COMM_STATUS_IND */
  641. macMlmePollInd_t pollInd; /* MAC_MLME_POLL_IND */
  642. macMcpsDataCnf_t dataCnf; /* MAC_MCPS_DATA_CNF */
  643. macMcpsDataInd_t dataInd; /* MAC_MCPS_DATA_IND */
  644. macMcpsPurgeCnf_t purgeCnf; /* MAC_MCPS_PURGE_CNF */
  645. } macCbackEvent_t;
  646. /* Configurable parameters */
  647. typedef struct
  648. {
  649. uint8 txDataMax; /* maximum number of data frames in transmit queue */
  650. uint8 txMax; /* maximum number of frames of all types in transmit queue */
  651. uint8 rxMax; /* maximum number of command and data frames in receive queue */
  652. uint8 dataIndOffset; /* allocate additional bytes in the data indication for
  653. application-defined headers */
  654. bool appPendingQueue; /* determine whether MAC_MLME_POLL_IND will be sent to the application or not
  655. when data request is received and no pending frame is found in the MAC */
  656. } macCfg_t;
  657. /* ------------------------------------------------------------------------------------------------
  658. * Internal Functions
  659. * ------------------------------------------------------------------------------------------------
  660. */
  661. /* These functions are used when creating the OSAL MAC task. They must not be used for any
  662. * other purpose.
  663. */
  664. extern void macTaskInit(uint8 taskId);
  665. extern uint16 macEventLoop(uint8 taskId, uint16 events);
  666. /* ------------------------------------------------------------------------------------------------
  667. * Functions
  668. * ------------------------------------------------------------------------------------------------
  669. */
  670. /**************************************************************************************************
  671. * @fn MAC_Init
  672. *
  673. * @brief This function initializes the MAC subsystem. It must be called once when the
  674. * software system is started and before any other function in the MAC API
  675. * is called.
  676. *
  677. * input parameters
  678. *
  679. * None.
  680. *
  681. * output parameters
  682. *
  683. * None.
  684. *
  685. * @return None.
  686. **************************************************************************************************
  687. */
  688. extern void MAC_Init(void);
  689. /**************************************************************************************************
  690. * @fn MAC_InitDevice
  691. *
  692. * @brief This function initializes the MAC to associate with a non
  693. * beacon-enabled network. This function would be used to
  694. * initialize a device as an RFD. If this function is used it
  695. * must be called during application initialization before any
  696. * other function in the data or management API is called.
  697. *
  698. * input parameters
  699. *
  700. * None.
  701. *
  702. * output parameters
  703. *
  704. * None.
  705. *
  706. * @return None.
  707. **************************************************************************************************
  708. */
  709. extern void MAC_InitDevice(void);
  710. /**************************************************************************************************
  711. * @fn MAC_InitCoord
  712. *
  713. * @brief This function initializes the MAC for operation as a
  714. * coordinator. A coordinator can start a network, accept
  715. * associate requests from other devices, send beacons, send
  716. * indirect data, and other operations. This function would
  717. * be used to initialize a device as an FFD. If this function
  718. * is used it must be called during application initialization
  719. * before any other function in the data or management API
  720. * is called.
  721. *
  722. * input parameters
  723. *
  724. * None.
  725. *
  726. * output parameters
  727. *
  728. * None.
  729. *
  730. * @return None.
  731. **************************************************************************************************
  732. */
  733. extern void MAC_InitCoord(void);
  734. /**************************************************************************************************
  735. * @fn MAC_InitSecurity
  736. *
  737. * @brief This function initializes the MAC to allow use of security.
  738. * If this function is used it must be called during application
  739. * initialization before any other function in the data or
  740. * management API is called.
  741. *
  742. * input parameters
  743. *
  744. * None.
  745. *
  746. * output parameters
  747. *
  748. * None.
  749. *
  750. * @return None.
  751. **************************************************************************************************
  752. */
  753. extern void MAC_InitSecurity(void);
  754. /**************************************************************************************************
  755. * @fn MAC_InitBeaconCoord
  756. *
  757. * @brief This function initializes the MAC for operation as a coordinator in a
  758. * beacon-enabled network. If this function is used it must
  759. * be called during application initialization before any other
  760. * function in the data or management API is called.
  761. *
  762. * input parameters
  763. *
  764. * None.
  765. *
  766. * output parameters
  767. *
  768. * None.
  769. *
  770. * @return None.
  771. **************************************************************************************************
  772. */
  773. extern void MAC_InitBeaconCoord(void);
  774. /**************************************************************************************************
  775. * @fn MAC_InitBeaconTrack
  776. *
  777. * @brief This function initializes the MAC to allow it to associate
  778. * with and track a beacon-enabled network. If this function is
  779. * used it must be called during application initialization
  780. * before any other function in the data or management API
  781. * is called.
  782. *
  783. * input parameters
  784. *
  785. * None.
  786. *
  787. * output parameters
  788. *
  789. * None.
  790. *
  791. * @return None.
  792. **************************************************************************************************
  793. */
  794. extern void MAC_InitBeaconDevice(void);
  795. /**************************************************************************************************
  796. * @fn MAC_McpsDataReq
  797. *
  798. * @brief This function sends application data to the MAC for
  799. * transmission in a MAC data frame.
  800. *
  801. * input parameters
  802. *
  803. * @param pData - Pointer to parameters structure.
  804. *
  805. * output parameters
  806. *
  807. * None.
  808. *
  809. * @return None.
  810. **************************************************************************************************
  811. */
  812. extern void MAC_McpsDataReq(macMcpsDataReq_t *pData);
  813. /**************************************************************************************************
  814. * @fn MAC_McpsPurgeReq
  815. *
  816. * @brief This function purges and discards a data request from the
  817. * MAC data queue. When the operation is complete the MAC sends
  818. * a MAC_MCPS_PURGE_CNF.
  819. *
  820. * input parameters
  821. *
  822. * @param msduHandle - The application-defined handle value
  823. *
  824. * output parameters
  825. *
  826. * None.
  827. *
  828. * @return None.
  829. **************************************************************************************************
  830. */
  831. extern void MAC_McpsPurgeReq(uint8 msduHandle);
  832. /**************************************************************************************************
  833. * @fn MAC_McpsDataAlloc
  834. *
  835. * @brief This direct-execute function simplifies the allocation and
  836. * preparation of the data buffer MAC_McpsDataReq(). The
  837. * function allocates a buffer and prepares the data pointer.
  838. *
  839. * input parameters
  840. *
  841. * @param len - Length of application data in bytes.
  842. * @param securityLevel - Security level used for this frame.
  843. * @param keyIdMode - Key ID mode used for this frame.
  844. *
  845. * output parameters
  846. *
  847. * None.
  848. *
  849. * @return Returns a pointer to the allocated buffer. If the function
  850. * fails for any reason it returns NULL.
  851. **************************************************************************************************
  852. */
  853. extern macMcpsDataReq_t *MAC_McpsDataAlloc(uint8 len, uint8 securityLevel, uint8 keyIdMode);
  854. /**************************************************************************************************
  855. * @fn MAC_MlmeAssociateReq
  856. *
  857. * @brief This function sends an associate request to a coordinator
  858. * device. The application shall attempt to associate only with
  859. * a PAN that is currently allowing association, as indicated
  860. * in the results of the scanning procedure. In a beacon-enabled
  861. * PAN the beacon order and superframe order must be set by using
  862. * MAC_MlmeSetReq() before making the call to MAC_MlmeAssociateReq().
  863. * If not, the associate request frame is likely to be transmitted
  864. * outside the superframe. When the associate request is complete
  865. * the MAC sends a MAC_MLME_ASSOCIATE_CNF to the application.
  866. *
  867. * input parameters
  868. *
  869. * @param pData - Pointer to parameters structure.
  870. *
  871. * output parameters
  872. *
  873. * None.
  874. *
  875. * @return None.
  876. **************************************************************************************************
  877. */
  878. extern void MAC_MlmeAssociateReq(macMlmeAssociateReq_t *pData);
  879. /**************************************************************************************************
  880. * @fn MAC_MlmeAssociateRsp
  881. *
  882. * @brief This function sends an associate response to a device
  883. * requesting to associate. This function must be called after
  884. * receiving a MAC_MLME_ASSOCIATE_IND. When the associate response is
  885. * complete the MAC sends a MAC_MLME_COMM_STATUS_IND to the application
  886. * to indicate the success or failure of the operation.
  887. *
  888. * input parameters
  889. *
  890. * @param pData - Pointer to parameters structure.
  891. *
  892. * output parameters
  893. *
  894. * None.
  895. *
  896. * @return None.
  897. **************************************************************************************************
  898. */
  899. extern void MAC_MlmeAssociateRsp(macMlmeAssociateRsp_t *pData);
  900. /**************************************************************************************************
  901. * @fn MAC_MlmeDisassociateReq
  902. *
  903. * @brief This function is used by an associated device to notify the
  904. * coordinator of its intent to leave the PAN. It is also used
  905. * by the coordinator to instruct an associated device to leave
  906. * the PAN. When the disassociate is complete the MAC sends a
  907. * MAC_MLME_DISASSOCIATE_CNF to the application.
  908. *
  909. * input parameters
  910. *
  911. * @param pData - Pointer to parameters structure.
  912. *
  913. * output parameters
  914. *
  915. * None.
  916. *
  917. * @return None.
  918. **************************************************************************************************
  919. */
  920. extern void MAC_MlmeDisassociateReq(macMlmeDisassociateReq_t *pData);
  921. /**************************************************************************************************
  922. * @fn MAC_MlmeGetReq
  923. *
  924. * @brief This direct execute function retrieves an attribute value
  925. * from the MAC PIB.
  926. *
  927. * input parameters
  928. *
  929. * @param pibAttribute - The attribute identifier.
  930. * @param pValue - pointer to the attribute value.
  931. *
  932. * output parameters
  933. *
  934. * @param pValue - pointer to the attribute value.
  935. *
  936. * @return The status of the request, as follows:
  937. * MAC_SUCCESS Operation successful.
  938. * MAC_UNSUPPORTED_ATTRIBUTE Attribute not found.
  939. *
  940. **************************************************************************************************
  941. */
  942. extern uint8 MAC_MlmeGetReq(uint8 pibAttribute, void *pValue);
  943. /**************************************************************************************************
  944. * @fn MAC_MlmeOrphanRsp
  945. *
  946. * @brief This function is called in response to an orphan notification
  947. * from a peer device. This function must be called after
  948. * receiving a MAC_MLME_ORPHAN_IND. When the orphan response is
  949. * complete the MAC sends a MAC_MLME_COMM_STATUS_IND to the
  950. * application to indicate the success or failure of the operation.
  951. *
  952. * input parameters
  953. *
  954. * @param pData - Pointer to parameters structure.
  955. *
  956. * output parameters
  957. *
  958. * None.
  959. *
  960. * @return None.
  961. **************************************************************************************************
  962. */
  963. extern void MAC_MlmeOrphanRsp(macMlmeOrphanRsp_t *pData);
  964. /**************************************************************************************************
  965. * @fn MAC_MlmePollReq
  966. *
  967. * @brief This function is used to request pending data from the
  968. * coordinator. When the poll request is complete the MAC sends
  969. * a MAC_MLME_POLL_CNF to the application. If a data frame of
  970. * nonzero length is received from the coordinator the MAC sends
  971. * a MAC_MLME_POLL_CNF with status MAC_SUCCESS and then sends a
  972. * MAC_MCPS_DATA_IND with the data.
  973. *
  974. * input parameters
  975. *
  976. * @param pData - Pointer to parameters structure.
  977. *
  978. * output parameters
  979. *
  980. * None.
  981. *
  982. * @return None.
  983. **************************************************************************************************
  984. */
  985. extern void MAC_MlmePollReq(macMlmePollReq_t *pData);
  986. /**************************************************************************************************
  987. * @fn MAC_MlmeResetReq
  988. *
  989. * @brief This direct execute function resets the MAC. This function
  990. * must be called once at system startup before any other
  991. * function in the management API is called.
  992. *
  993. * input parameters
  994. *
  995. * @param setDefaultPib - Set to TRUE to reset the MAC PIB to its
  996. * default values.
  997. *
  998. * output parameters
  999. *
  1000. * None.
  1001. *
  1002. * @return Returns MAC_SUCCESS always.
  1003. *
  1004. **************************************************************************************************
  1005. */
  1006. extern uint8 MAC_MlmeResetReq(bool setDefaultPib);
  1007. /**************************************************************************************************
  1008. * @fn MAC_MlmeScanReq
  1009. *
  1010. * @brief This function initiates an energy detect, active, passive,
  1011. * or orphan scan on one or more channels. An energy detect
  1012. * scan measures the peak energy on each requested channel.
  1013. * An active scan sends a beacon request on each channel and
  1014. * then listening for beacons. A passive scan is a receive-only
  1015. * operation that listens for beacons on each channel. An orphan
  1016. * scan is used to locate the coordinator with which the scanning
  1017. * device had previously associated. When a scan operation is
  1018. * complete the MAC sends a MAC_MLME_SCAN_CNF to the application.
  1019. *
  1020. * input parameters
  1021. *
  1022. * @param pData - Pointer to parameters structure.
  1023. *
  1024. * output parameters
  1025. *
  1026. * None.
  1027. *
  1028. * @return None.
  1029. **************************************************************************************************
  1030. */
  1031. extern void MAC_MlmeScanReq(macMlmeScanReq_t *pData);
  1032. /**************************************************************************************************
  1033. * @fn MAC_MlmeSetReq
  1034. *
  1035. * @brief This direct execute function sets an attribute value
  1036. * in the MAC PIB.
  1037. *
  1038. * input parameters
  1039. *
  1040. * @param pibAttribute - The attribute identifier.
  1041. * @param pValue - pointer to the attribute value.
  1042. *
  1043. * output parameters
  1044. *
  1045. * None.
  1046. *
  1047. * @return The status of the request, as follows:
  1048. * MAC_SUCCESS Operation successful.
  1049. * MAC_UNSUPPORTED_ATTRIBUTE Attribute not found.
  1050. *
  1051. **************************************************************************************************
  1052. */
  1053. extern uint8 MAC_MlmeSetReq(uint8 pibAttribute, void *pValue);
  1054. /**************************************************************************************************
  1055. * @fn MAC_MlmeStartReq
  1056. *
  1057. * @brief This function is called by a coordinator or PAN coordinator
  1058. * to start or reconfigure a network. Before starting a
  1059. * network the device must have set its short address. A PAN
  1060. * coordinator sets the short address by setting the attribute
  1061. * MAC_SHORT_ADDRESS. A coordinator sets the short address
  1062. * through association. When the operation is complete the
  1063. * MAC sends a MAC_MLME_START_CNF to the application.
  1064. *
  1065. * input parameters
  1066. *
  1067. * @param pData - Pointer to parameters structure.
  1068. *
  1069. * output parameters
  1070. *
  1071. * None.
  1072. *
  1073. * @return None.
  1074. **************************************************************************************************
  1075. */
  1076. extern void MAC_MlmeStartReq(macMlmeStartReq_t *pData);
  1077. /**************************************************************************************************
  1078. * @fn MAC_MlmeSyncReq
  1079. *
  1080. * @brief This function requests the MAC to synchronize with the
  1081. * coordinator by acquiring and optionally tracking its beacons.
  1082. * Synchronizing with the coordinator is recommended before
  1083. * associating in a beacon-enabled network. If the beacon could
  1084. * not be located on its initial search or during tracking, the
  1085. * MAC sends a MAC_MLME_SYNC_LOSS_IND to the application with
  1086. * status MAC_BEACON_LOSS.
  1087. *
  1088. * input parameters
  1089. *
  1090. * @param pData - Pointer to parameters structure.
  1091. *
  1092. * output parameters
  1093. *
  1094. * None.
  1095. *
  1096. * @return None.
  1097. **************************************************************************************************
  1098. */
  1099. extern void MAC_MlmeSyncReq(macMlmeSyncReq_t *pData);
  1100. /**************************************************************************************************
  1101. * @fn MAC_PwrOffReq
  1102. *
  1103. * @brief This direct execute function requests the MAC to power off
  1104. * the radio hardware and go to sleep. If the MAC is able to
  1105. * power off it will execute its power off procedure and return
  1106. * MAC_SUCCESS. If the MAC is unable to sleep it will return
  1107. * MAC_DENIED. The MAC is unable to sleep when it is executing
  1108. * certain procedures, such as a scan, data request, or association.
  1109. * If this function is called when the MAC is already in sleep mode
  1110. * it will return MAC_SUCCESS but do nothing.
  1111. *
  1112. * input parameters
  1113. *
  1114. * @param mode - The desired low power mode.
  1115. *
  1116. * output parameters
  1117. *
  1118. * None.
  1119. *
  1120. * @return The status of the request, as follows:
  1121. * MAC_SUCCESS Operation successful; the MAC is powered off.
  1122. * MAC_DENIED The MAC was not able to power off.
  1123. **************************************************************************************************
  1124. */
  1125. extern uint8 MAC_PwrOffReq(uint8 mode);
  1126. /**************************************************************************************************
  1127. * @fn MAC_PwrOnReq
  1128. *
  1129. * @brief This function requests the MAC to power on the radio hardware
  1130. * and wake up. When the power on procedure is complete the MAC
  1131. * will send a MAC_PWR_ON_CNF to the application.
  1132. *
  1133. * input parameters
  1134. *
  1135. * None.
  1136. *
  1137. * output parameters
  1138. *
  1139. * None.
  1140. *
  1141. * @return None.
  1142. **************************************************************************************************
  1143. */
  1144. extern void MAC_PwrOnReq(void);
  1145. /**************************************************************************************************
  1146. * @fn MAC_PwrMode
  1147. *
  1148. * @brief This function returns the current power mode of the MAC.
  1149. *
  1150. * input parameters
  1151. *
  1152. * None.
  1153. *
  1154. * output parameters
  1155. *
  1156. * None.
  1157. *
  1158. * @return The current power mode of the MAC.
  1159. **************************************************************************************************
  1160. */
  1161. extern uint8 MAC_PwrMode(void);
  1162. /**************************************************************************************************
  1163. * @fn MAC_PwrNextTimeout
  1164. *
  1165. * @brief This function returns the next MAC timer expiration in 320 usec units. If no
  1166. * timer is running it returns zero.
  1167. *
  1168. * input parameters
  1169. *
  1170. * None.
  1171. *
  1172. * output parameters
  1173. *
  1174. * None.
  1175. *
  1176. * @return The next MAC timer expiration or zero.
  1177. **************************************************************************************************
  1178. */
  1179. extern uint32 MAC_PwrNextTimeout(void);
  1180. /**************************************************************************************************
  1181. * @fn MAC_RandomByte
  1182. *
  1183. * @brief This function returns a random byte from the MAC random number generator.
  1184. *
  1185. * input parameters
  1186. *
  1187. * None.
  1188. *
  1189. * output parameters
  1190. *
  1191. * None.
  1192. *
  1193. * @return A random byte.
  1194. **************************************************************************************************
  1195. */
  1196. extern uint8 MAC_RandomByte(void);
  1197. /**************************************************************************************************
  1198. * @fn MAC_SrcMatchEnable
  1199. *
  1200. * @brief Enabled AUTOPEND and source address matching. if number of source
  1201. * address table entries asked for is more than the hardware
  1202. * supports. It will allocate maximum number of entries and return
  1203. * MAC_INVALID_PARAMETER. This function shall not be called from
  1204. * ISR. It is not thread safe.
  1205. *
  1206. * @param addressType - address type that the application uses
  1207. * SADDR_MODE_SHORT or SADDR_MODE_EXT
  1208. * @param num - number of source address table entries to be used
  1209. *
  1210. * @return MAC_SUCCESS or MAC_INVALID_PARAMETER
  1211. **************************************************************************************************
  1212. */
  1213. extern uint8 MAC_SrcMatchEnable ( uint8 addrType, uint8 num );
  1214. /**************************************************************************************************
  1215. * @fn MAC_SrcMatchAddEntry
  1216. *
  1217. * @brief Add a short or extended address to source address table. This
  1218. * function shall not be called from ISR. It is not thread safe.
  1219. *
  1220. * @param addr - a pointer to sAddr_t which contains addrMode
  1221. * and a union of a short 16-bit MAC address or an extended
  1222. * 64-bit MAC address to be added to the source address table.
  1223. * @param panID - the device PAN ID. It is only used when the addr is
  1224. * using short address
  1225. *
  1226. * @return MAC_SUCCESS or MAC_NO_RESOURCES (source address
  1227. * table full) or MAC_DUPLICATED_ENTRY (the entry added is duplicated),
  1228. * or MAC_INVALID_PARAMETER if the input parameters are invalid.
  1229. **************************************************************************************************
  1230. */
  1231. extern uint8 MAC_SrcMatchAddEntry ( sAddr_t *addr, uint16 panID );
  1232. /**************************************************************************************************
  1233. * @fn MAC_SrcMatchDeleteEntry
  1234. *
  1235. * @brief Delete a short or extended address from source address table.
  1236. * This function shall not be called from ISR. It is not thread safe.
  1237. *
  1238. * @param addr - a pointer to sAddr_t which contains addrMode
  1239. * and a union of a short 16-bit MAC address or an extended
  1240. * 64-bit MAC address to be deleted from the source address table.
  1241. * @param panID - the device PAN ID. It is only used when the addr is
  1242. * using short address
  1243. *
  1244. * @return MAC_SUCCESS or MAC_INVALID_PARAMETER (address to be deleted
  1245. * cannot be found in the source address table).
  1246. **************************************************************************************************
  1247. */
  1248. extern uint8 MAC_SrcMatchDeleteEntry ( sAddr_t *addr, uint16 panID );
  1249. /**************************************************************************************************
  1250. * @fn MAC_SrcMatchAckAllPending
  1251. *
  1252. * @brief Enabled/disable acknowledging all packets with pending bit set
  1253. * The application normally enables it when adding new entries to
  1254. * the source address table fails due to the table is full, or
  1255. * disables it when more entries are deleted and the table has
  1256. * empty slots.
  1257. *
  1258. * @param option - TRUE (acknowledging all packets with pending field set)
  1259. * FALSE (acknowledging all packets with pending field cleared)
  1260. *
  1261. * @return none
  1262. **************************************************************************************************
  1263. */
  1264. extern void MAC_SrcMatchAckAllPending ( uint8 option );
  1265. /**************************************************************************************************
  1266. * @fn MAC_SrcMatchCheckAllPending
  1267. *
  1268. * @brief Check if acknowledging all packets with pending bit set
  1269. * is enabled.
  1270. *
  1271. * @param none
  1272. *
  1273. * @return MAC_AUTOACK_PENDING_ALL_ON or MAC_AUTOACK_PENDING_ALL_OFF
  1274. **************************************************************************************************
  1275. */
  1276. extern uint8 MAC_SrcMatchCheckAllPending ( void );
  1277. /**************************************************************************************************
  1278. * @fn MAC_CbackEvent
  1279. *
  1280. * @brief This callback function sends MAC events to the application.
  1281. * The application must implement this function. A typical
  1282. * implementation of this function would allocate an OSAL message,
  1283. * copy the event parameters to the message, and send the message
  1284. * to the application's OSAL event handler. This function may be
  1285. * executed from task or interrupt context and therefore must
  1286. * be reentrant.
  1287. *
  1288. * input parameters
  1289. *
  1290. * @param pData - Pointer to parameters structure.
  1291. *
  1292. * output parameters
  1293. *
  1294. * None.
  1295. *
  1296. * @return None.
  1297. **************************************************************************************************
  1298. */
  1299. extern void MAC_CbackEvent(macCbackEvent_t *pData);
  1300. /**************************************************************************************************
  1301. * @fn MAC_CbackCheckPending
  1302. *
  1303. * @brief This callback function returns the number of pending indirect messages queued in
  1304. * the application. Most applications do not queue indirect data and can simply
  1305. * always return zero. The number of pending indirect messages only needs to be
  1306. * returned if macCfg.appPendingQueue to TRUE.
  1307. *
  1308. * input parameters
  1309. *
  1310. * None.
  1311. *
  1312. * output parameters
  1313. *
  1314. * None.
  1315. *
  1316. * @return The number of indirect messages queued in the application or zero.
  1317. **************************************************************************************************
  1318. */
  1319. extern uint8 MAC_CbackCheckPending(void);
  1320. /**************************************************************************************************
  1321. */
  1322. #ifdef __cplusplus
  1323. };
  1324. #endif
  1325. #endif /* MAC_API_H */