ZMAC.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /**************************************************************************************************
  2. Filename: ZMAC.h
  3. Revised: $Date: 2009-03-10 08:35:17 -0700 (Tue, 10 Mar 2009) $
  4. Revision: $Revision: 19360 $
  5. Description: This file contains the ZStack MAC Porting Layer.
  6. Copyright 2004-2007 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 ZMAC_H
  34. #define ZMAC_H
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #endif
  39. /*********************************************************************
  40. * INCLUDES
  41. */
  42. #include "ZComDef.h"
  43. #include "zmac_internal.h"
  44. /*********************************************************************
  45. * MACROS
  46. */
  47. /* Maximum length of the beacon payload */
  48. #ifndef ZMAC_MAX_BEACON_PAYLOAD_LEN
  49. #define ZMAC_MAX_BEACON_PAYLOAD_LEN (7 + Z_EXTADDR_LEN)
  50. #endif
  51. /*********************************************************************
  52. * CONSTANTS
  53. */
  54. #if defined( MAC_API_H )
  55. #define ZMAC_CHAN_MASK ( \
  56. MAC_CHAN_11_MASK | \
  57. MAC_CHAN_12_MASK | \
  58. MAC_CHAN_13_MASK | \
  59. MAC_CHAN_14_MASK | \
  60. MAC_CHAN_15_MASK | \
  61. MAC_CHAN_16_MASK | \
  62. MAC_CHAN_17_MASK | \
  63. MAC_CHAN_18_MASK | \
  64. MAC_CHAN_19_MASK | \
  65. MAC_CHAN_20_MASK | \
  66. MAC_CHAN_21_MASK | \
  67. MAC_CHAN_22_MASK | \
  68. MAC_CHAN_23_MASK | \
  69. MAC_CHAN_24_MASK | \
  70. MAC_CHAN_25_MASK | \
  71. MAC_CHAN_26_MASK | \
  72. MAC_CHAN_27_MASK | \
  73. MAC_CHAN_28_MASK )
  74. #else
  75. #define ZMAC_CHAN_MASK 0x07FFF800
  76. #endif
  77. /*********************************************************************
  78. * TYPEDEFS
  79. */
  80. /* ZMAC event header type */
  81. typedef struct
  82. {
  83. uint8 Event; /* ZMAC event */
  84. uint8 Status; /* ZMAC status */
  85. } ZMacEventHdr_t;
  86. /* Common security type */
  87. typedef struct
  88. {
  89. uint8 KeySource[ZMAC_KEY_SOURCE_MAX_LEN];
  90. uint8 SecurityLevel;
  91. uint8 KeyIdMode;
  92. uint8 KeyIndex;
  93. }ZMacSec_t;
  94. /* PAN descriptor type */
  95. typedef struct
  96. {
  97. zAddrType_t CoordAddress;
  98. uint16 CoordPANId;
  99. uint16 SuperframeSpec;
  100. uint8 LogicalChannel;
  101. uint8 ChannelPage;
  102. uint8 GTSPermit;
  103. uint8 LinkQuality;
  104. uint32 TimeStamp;
  105. uint8 SecurityFailure;
  106. ZMacSec_t Sec;
  107. } ZMacPanDesc_t;
  108. /* Communication status indication type */
  109. typedef struct
  110. {
  111. ZMacEventHdr_t hdr;
  112. zAddrType_t SrcAddress;
  113. zAddrType_t DstAddress;
  114. uint16 PANId;
  115. uint8 Reason;
  116. ZMacSec_t Sec;
  117. } ZMacCommStatusInd_t;
  118. /* SYNC */
  119. typedef struct
  120. {
  121. uint8 LogicalChannel; /* The logical channel to use */
  122. uint8 ChannelPage; /* The channel page to use */
  123. uint8 TrackBeacon; /* Set to TRUE to continue tracking beacons after synchronizing with the
  124. first beacon. Set to FALSE to only synchronize with the first beacon */
  125. }ZMacSyncReq_t;
  126. /* DATA TYPES */
  127. /* Data request parameters type */
  128. typedef struct
  129. {
  130. zAddrType_t DstAddr;
  131. uint16 DstPANId;
  132. uint8 SrcAddrMode;
  133. uint8 Handle;
  134. uint8 TxOptions;
  135. uint8 Channel;
  136. uint8 Power;
  137. ZMacSec_t Sec;
  138. uint8 msduLength;
  139. uint8 *msdu;
  140. } ZMacDataReq_t;
  141. /* Data confirm type */
  142. typedef struct
  143. {
  144. ZMacEventHdr_t hdr;
  145. uint8 msduHandle;
  146. ZMacDataReq_t *pDataReq;
  147. uint32 Timestamp;
  148. uint16 Timestamp2;
  149. uint8 retries;
  150. uint8 mpduLinkQuality;
  151. uint8 correlation;
  152. int8 rssi;
  153. } ZMacDataCnf_t;
  154. /* ASSOCIATION TYPES */
  155. /* Associate request type */
  156. typedef struct
  157. {
  158. uint8 LogicalChannel;
  159. uint8 ChannelPage;
  160. zAddrType_t CoordAddress;
  161. uint16 CoordPANId;
  162. uint8 CapabilityInformation;
  163. ZMacSec_t Sec;
  164. } ZMacAssociateReq_t;
  165. /* Associate response type */
  166. typedef struct
  167. {
  168. ZLongAddr_t DeviceAddress;
  169. uint16 AssocShortAddress;
  170. uint8 Status;
  171. ZMacSec_t Sec;
  172. } ZMacAssociateRsp_t;
  173. /* Associate indication parameters type */
  174. typedef struct
  175. {
  176. ZMacEventHdr_t hdr;
  177. ZLongAddr_t DeviceAddress;
  178. uint8 CapabilityInformation;
  179. ZMacSec_t Sec;
  180. } ZMacAssociateInd_t;
  181. /* Associate confim type */
  182. typedef struct
  183. {
  184. ZMacEventHdr_t hdr;
  185. uint16 AssocShortAddress;
  186. ZMacSec_t Sec;
  187. } ZMacAssociateCnf_t;
  188. /* Disassociate request type */
  189. typedef struct
  190. {
  191. zAddrType_t DeviceAddress;
  192. uint16 DevicePanId;
  193. uint8 DisassociateReason;
  194. uint8 TxIndirect;
  195. ZMacSec_t Sec;
  196. } ZMacDisassociateReq_t;
  197. /* Rx enable confirm type */
  198. typedef struct
  199. {
  200. ZMacEventHdr_t hdr;
  201. } ZMacRxEnableCnf_t;
  202. /* SCAN */
  203. /* Scan request type */
  204. typedef struct
  205. {
  206. uint32 ScanChannels;
  207. uint8 ScanType;
  208. uint8 ScanDuration;
  209. uint8 ChannelPage;
  210. uint8 MaxResults;
  211. ZMacSec_t Sec;
  212. union
  213. {
  214. uint8 *pEnergyDetect;
  215. ZMacPanDesc_t *pPanDescriptor;
  216. }Result;
  217. } ZMacScanReq_t;
  218. /* Scan confirm type */
  219. typedef struct
  220. {
  221. ZMacEventHdr_t hdr;
  222. uint8 ScanType;
  223. uint8 ChannelPage;
  224. uint32 UnscannedChannels;
  225. uint8 ResultListSize;
  226. union
  227. {
  228. uint8 *pEnergyDetect;
  229. ZMacPanDesc_t *pPanDescriptor;
  230. }Result;
  231. } ZMacScanCnf_t;
  232. /* START */
  233. /* Start request type */
  234. typedef struct
  235. {
  236. uint32 StartTime;
  237. uint16 PANID;
  238. uint8 LogicalChannel;
  239. uint8 ChannelPage;
  240. uint8 BeaconOrder;
  241. uint8 SuperframeOrder;
  242. uint8 PANCoordinator;
  243. uint8 BatteryLifeExt;
  244. uint8 CoordRealignment;
  245. ZMacSec_t RealignSec;
  246. ZMacSec_t BeaconSec;
  247. } ZMacStartReq_t;
  248. /* Start confirm type */
  249. typedef struct
  250. {
  251. ZMacEventHdr_t hdr;
  252. } ZMacStartCnf_t;
  253. /* POLL */
  254. /* Roll request type */
  255. typedef struct
  256. {
  257. zAddrType_t CoordAddress;
  258. uint16 CoordPanId;
  259. ZMacSec_t Sec;
  260. } ZMacPollReq_t;
  261. /* Poll confirm type */
  262. typedef struct
  263. {
  264. ZMacEventHdr_t hdr;
  265. } ZMacPollCnf_t;
  266. /* MAC_MLME_POLL_IND type */
  267. typedef struct
  268. {
  269. ZMacEventHdr_t hdr;
  270. uint16 srcShortAddr; /* Short address of the device sending the data request */
  271. uint16 srcPanId; /* Pan ID of the device sending the data request */
  272. } ZMacPollInd_t;
  273. /* ORPHAN */
  274. /* Orphan response type */
  275. typedef struct
  276. {
  277. ZLongAddr_t OrphanAddress;
  278. uint16 ShortAddress;
  279. uint8 AssociatedMember;
  280. ZMacSec_t Sec;
  281. } ZMacOrphanRsp_t;
  282. /* Orphan indication type */
  283. typedef struct
  284. {
  285. ZMacEventHdr_t hdr;
  286. ZLongAddr_t OrphanAddress;
  287. ZMacSec_t Sec;
  288. } ZMacOrphanInd_t;
  289. #if defined (MT_MAC_FUNC) || defined (MT_MAC_CB_FUNC)
  290. /* Sync loss indication type */
  291. typedef struct
  292. {
  293. ZMacEventHdr_t hdr;
  294. uint16 PANId;
  295. uint8 LogicalChannel;
  296. uint8 ChannelPage;
  297. ZMacSec_t Sec;
  298. } ZMacSyncLossInd_t;
  299. /* Data indication parameters type */
  300. typedef struct
  301. {
  302. ZMacEventHdr_t hdr;
  303. zAddrType_t SrcAddr;
  304. zAddrType_t DstAddr;
  305. uint32 Timestamp;
  306. uint16 Timestamp2;
  307. uint16 SrcPANId;
  308. uint16 DstPANId;
  309. uint8 mpduLinkQuality;
  310. uint8 Correlation;
  311. uint8 Rssi;
  312. uint8 Dsn;
  313. ZMacSec_t Sec;
  314. uint8 msduLength;
  315. uint8 *msdu;
  316. } ZMacDataInd_t;
  317. /* Disassociate indication type */
  318. typedef struct
  319. {
  320. ZMacEventHdr_t hdr;
  321. ZLongAddr_t DeviceAddress;
  322. uint8 DisassociateReason;
  323. ZMacSec_t Sec;
  324. } ZMacDisassociateInd_t;
  325. /* Disassociate confirm type */
  326. typedef struct
  327. {
  328. ZMacEventHdr_t hdr;
  329. zAddrType_t DeviceAddress;
  330. uint16 panID;
  331. } ZMacDisassociateCnf_t;
  332. /* Beacon notify indication type */
  333. typedef struct
  334. {
  335. ZMacEventHdr_t hdr;
  336. uint8 BSN;
  337. ZMacPanDesc_t *pPanDesc;
  338. uint8 PendAddrSpec;
  339. uint8 *AddrList;
  340. uint8 sduLength;
  341. uint8 *sdu;
  342. } ZMacBeaconNotifyInd_t;
  343. /* Purge confirm type */
  344. typedef struct
  345. {
  346. ZMacEventHdr_t hdr;
  347. uint8 msduHandle;
  348. } ZMacPurgeCnf_t;
  349. #endif
  350. typedef enum
  351. {
  352. TX_PWR_MAX,
  353. TX_PWR_MINUS_1,
  354. TX_PWR_MINUS_2,
  355. TX_PWR_MINUS_3,
  356. TX_PWR_MINUS_4,
  357. TX_PWR_MINUS_5,
  358. TX_PWR_MINUS_6,
  359. TX_PWR_MINUS_7,
  360. TX_PWR_MINUS_8,
  361. TX_PWR_MINUS_9,
  362. TX_PWR_MINUS_10,
  363. TX_PWR_MINUS_11,
  364. TX_PWR_MINUS_12,
  365. TX_PWR_MINUS_13,
  366. TX_PWR_MINUS_14,
  367. TX_PWR_MINUS_15
  368. } ZMacTransmitPower_t;
  369. typedef struct
  370. {
  371. byte protocolID;
  372. byte stackProfile; // 4 bit in native
  373. byte protocolVersion; // 4 bit in native
  374. byte reserved; // 2 bit in native
  375. byte routerCapacity; // 1 bit in native
  376. byte deviceDepth; // 4 bit in native
  377. byte deviceCapacity; // 1 bit in native
  378. byte extendedPANID[Z_EXTADDR_LEN];
  379. byte txOffset[3];
  380. byte updateId;
  381. } beaconPayload_t;
  382. /*********************************************************************
  383. * GLOBAL VARIABLES
  384. */
  385. #define NWK_CMD_ID_LEN sizeof( byte )
  386. /*********************************************************************
  387. * FUNCTIONS
  388. */
  389. /*
  390. * Initialize.
  391. */
  392. extern ZMacStatus_t ZMacInit( void );
  393. /*
  394. * Send a MAC Data Frame packet.
  395. */
  396. extern ZMacStatus_t ZMacDataReq( ZMacDataReq_t *param );
  397. /*
  398. * Request an association with a coordinator.
  399. */
  400. extern ZMacStatus_t ZMacAssociateReq( ZMacAssociateReq_t *param );
  401. /*
  402. * Request to send an association response message.
  403. */
  404. extern ZMacStatus_t ZMacAssociateRsp( ZMacAssociateRsp_t *param );
  405. /*
  406. * Request to send a disassociate request message.
  407. */
  408. extern ZMacStatus_t ZMacDisassociateReq( ZMacDisassociateReq_t *param );
  409. /*
  410. * Gives the MAC extra processing time.
  411. * Returns false if its OK to sleep.
  412. */
  413. extern byte ZMacUpdate( void );
  414. /*
  415. * Read a MAC PIB attribute.
  416. */
  417. extern ZMacStatus_t ZMacGetReq( ZMacAttributes_t attr, byte *value );
  418. /*
  419. * This function allows the next higher layer to respond to
  420. * an orphan indication message.
  421. */
  422. extern ZMacStatus_t ZMacOrphanRsp( ZMacOrphanRsp_t *param );
  423. /*
  424. * This function is called to request MAC data request poll.
  425. */
  426. extern ZMacStatus_t ZMacPollReq( ZMacPollReq_t *param );
  427. /*
  428. * Reset the MAC.
  429. */
  430. extern ZMacStatus_t ZMacReset( byte SetDefaultPIB );
  431. /*
  432. * This function is called to perform a network scan.
  433. */
  434. extern ZMacStatus_t ZMacScanReq( ZMacScanReq_t *param );
  435. /*
  436. * Write a MAC PIB attribute.
  437. */
  438. extern ZMacStatus_t ZMacSetReq( ZMacAttributes_t attr, byte *value );
  439. /*
  440. * This function is called to tell the MAC to transmit beacons
  441. * and become a coordinator.
  442. */
  443. extern ZMacStatus_t ZMacStartReq( ZMacStartReq_t *param );
  444. /*
  445. * This function is called to request a sync to the current
  446. * networks beacons.
  447. */
  448. extern ZMacStatus_t ZMacSyncReq( ZMacSyncReq_t *param );
  449. /*
  450. * This function requests to reset mac state machine and
  451. * transaction.
  452. */
  453. extern ZMacStatus_t ZMacCleanReq( void );
  454. /*
  455. * This function is called to request MAC to purge a message.
  456. */
  457. extern ZMacStatus_t ZMacPurgeReq( byte msduHandle );
  458. /*
  459. * This function is called to enable AUTOPEND and source address matching.
  460. */
  461. extern ZMacStatus_t ZMacSrcMatchEnable (uint8 addrType, uint8 numEntries);
  462. /*
  463. * This function is called to add a short or extended address to source address table.
  464. */
  465. extern ZMacStatus_t ZMacSrcMatchAddEntry (zAddrType_t *addr, uint16 panID);
  466. /*
  467. * This function is called to delete a short or extended address from source address table.
  468. */
  469. extern ZMacStatus_t ZMacSrcMatchDeleteEntry (zAddrType_t *addr, uint16 panID);
  470. /*
  471. * This funciton is called to enabled/disable acknowledging all packets with pending bit set
  472. */
  473. extern ZMacStatus_t ZMacSrcMatchAckAllPending (uint8 option);
  474. /*
  475. * This function is called to check if acknowledging all packets with pending bit set is enabled.
  476. */
  477. extern ZMacStatus_t ZMacSrcMatchCheckAllPending (void);
  478. /*
  479. * This function is called to request MAC to power on the radio hardware and wake up.
  480. */
  481. extern void ZMacPwrOnReq ( void );
  482. /*
  483. * This function returns the current power mode of the MAC.
  484. */
  485. extern uint8 ZMac_PwrMode(void);
  486. /*
  487. * This function is called to request MAC to set the transmit power level.
  488. */
  489. extern ZMacStatus_t ZMacSetTransmitPower( ZMacTransmitPower_t level );
  490. /*
  491. * This function is called to send out an empty msg
  492. */
  493. extern void ZMacSendNoData( uint16 DstAddr, uint16 DstPANId );
  494. /*
  495. * This callback function is called for every MAC message that is received
  496. * over-the-air or generated locally by MAC for the application.
  497. */
  498. extern uint8 (*pZMac_AppCallback)( uint8 *msgPtr );
  499. /*
  500. * This function returns true if the MAC state is idle.
  501. */
  502. extern uint8 ZMacStateIdle( void );
  503. /*********************************************************************
  504. *********************************************************************/
  505. #ifdef __cplusplus
  506. }
  507. #endif
  508. #endif /* ZMAC_H */