zmac.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. /**************************************************************************************************
  2. Filename: zmac.c
  3. Revised: $Date: 2011-02-28 16:59:59 -0800 (Mon, 28 Feb 2011) $
  4. Revision: $Revision: 25230 $
  5. Description: This file contains the ZStack MAC Porting Layer
  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. /********************************************************************************************************
  34. * INCLUDES
  35. ********************************************************************************************************/
  36. #include "ZComDef.h"
  37. #include "OSAL.h"
  38. #include "ZMAC.h"
  39. #include "mac_main.h"
  40. #include "ssp.h"
  41. #if !defined NONWK
  42. #include "ZGlobals.h"
  43. #endif
  44. /********************************************************************************************************
  45. * MACROS
  46. ********************************************************************************************************/
  47. /********************************************************************************************************
  48. * CONSTANTS
  49. ********************************************************************************************************/
  50. /********************************************************************************************************
  51. * GLOBALS
  52. ********************************************************************************************************/
  53. uint32 _ScanChannels;
  54. extern uint8 aExtendedAddress[];
  55. /**************************************************************************************************
  56. * @fn MAC_SetRandomSeedCB
  57. *
  58. * @brief MAC function: Set the function pointer for the random seed callback.
  59. *
  60. * input parameters
  61. *
  62. * @param pCBFcn - function pointer of the random seed callback
  63. *
  64. * output parameters
  65. *
  66. * None.
  67. *
  68. * @return none
  69. **************************************************************************************************
  70. */
  71. extern void MAC_SetRandomSeedCB(macRNGFcn_t pCBFcn);
  72. /********************************************************************************************************
  73. * LOCALS
  74. ********************************************************************************************************/
  75. /* Pointer to scan result buffer */
  76. void *ZMac_ScanBuf = NULL;
  77. /********************************************************************************************************
  78. * LOCAL FUNCTION PROTOTYPES
  79. ********************************************************************************************************/
  80. /********************************************************************************************************
  81. * TYPEDEFS
  82. ********************************************************************************************************/
  83. /********************************************************************************************************
  84. * FUNCTIONS
  85. ********************************************************************************************************/
  86. /********************************************************************************************************
  87. * @fn ZMacInit
  88. *
  89. * @brief Initialize MAC.
  90. *
  91. * @param none.
  92. *
  93. * @return status.
  94. ********************************************************************************************************/
  95. uint8 ZMacInit( void )
  96. {
  97. uint8 stat;
  98. #if defined( ZCL_KEY_ESTABLISH )
  99. /* Set the callback function for 16 byte random seed */
  100. MAC_SetRandomSeedCB( SSP_StoreRandomSeedNV);
  101. #endif
  102. MAC_Init();
  103. MAC_InitDevice();
  104. #if !defined NONWK
  105. if ( ZG_BUILD_RTR_TYPE )
  106. {
  107. MAC_InitCoord();
  108. }
  109. #endif
  110. // If OK, initialize the MAC
  111. stat = ZMacReset( TRUE );
  112. // Turn off interrupts
  113. osal_int_disable( INTS_ALL );
  114. return ( stat );
  115. }
  116. /********************************************************************************************************
  117. * @fn ZMacReset
  118. *
  119. * @brief Reset the MAC.
  120. *
  121. * @param Default to PIB defaults.
  122. *
  123. * @return status.
  124. ********************************************************************************************************/
  125. uint8 ZMacReset( bool SetDefaultPIB )
  126. {
  127. byte stat;
  128. byte value;
  129. stat = MAC_MlmeResetReq( SetDefaultPIB );
  130. // Don't send PAN ID conflict
  131. value = FALSE;
  132. MAC_MlmeSetReq( MAC_ASSOCIATED_PAN_COORD, &value );
  133. MAC_MlmeSetReq( MAC_EXTENDED_ADDRESS, &aExtendedAddress );
  134. if (ZMac_ScanBuf)
  135. {
  136. osal_mem_free(ZMac_ScanBuf);
  137. ZMac_ScanBuf = NULL;
  138. }
  139. return ( stat );
  140. }
  141. /********************************************************************************************************
  142. * @fn ZMacGetReq
  143. *
  144. * @brief Read a MAC PIB attribute.
  145. *
  146. * @param attr - PIB attribute to get
  147. * @param value - pointer to the buffer to store the attribute
  148. *
  149. * @return status
  150. ********************************************************************************************************/
  151. uint8 ZMacGetReq( uint8 attr, uint8 *value )
  152. {
  153. if ( attr == ZMacExtAddr )
  154. {
  155. osal_cpyExtAddr( value, &aExtendedAddress );
  156. return ZMacSuccess;
  157. }
  158. return (ZMacStatus_t) MAC_MlmeGetReq( attr, value );
  159. }
  160. /********************************************************************************************************
  161. * @fn ZMacSetReq
  162. *
  163. * @brief Write a MAC PIB attribute.
  164. *
  165. * @param attr - PIB attribute to Set
  166. * @param value - pointer to the data
  167. *
  168. * @return status
  169. ********************************************************************************************************/
  170. uint8 ZMacSetReq( uint8 attr, byte *value )
  171. {
  172. if ( attr == ZMacExtAddr )
  173. {
  174. osal_cpyExtAddr( aExtendedAddress, value );
  175. }
  176. return (ZMacStatus_t) MAC_MlmeSetReq( attr, value );
  177. }
  178. #ifdef MAC_SECURITY
  179. /********************************************************************************************************
  180. * @fn ZMacSecurityGetReq
  181. *
  182. * @brief Read a MAC Security PIB attribute.
  183. *
  184. * @param attr - PIB attribute to get
  185. * @param value - pointer to the buffer to store the attribute
  186. *
  187. * @return status
  188. ********************************************************************************************************/
  189. uint8 ZMacSecurityGetReq( uint8 attr, uint8 *value )
  190. {
  191. return (ZMacStatus_t) MAC_MlmeGetSecurityReq( attr, value );
  192. }
  193. /********************************************************************************************************
  194. * @fn ZMacSecuritySetReq
  195. *
  196. * @brief Write a MAC Security PIB attribute.
  197. *
  198. * @param attr - PIB attribute to Set
  199. * @param value - pointer to the data
  200. *
  201. * @return status
  202. ********************************************************************************************************/
  203. uint8 ZMacSecuritySetReq( uint8 attr, byte *value )
  204. {
  205. return (ZMacStatus_t) MAC_MlmeSetSecurityReq( attr, value );
  206. }
  207. #endif /* MAC_SECURITY */
  208. /********************************************************************************************************
  209. * @fn ZMacAssociateReq
  210. *
  211. * @brief Request an association with a coordinator.
  212. *
  213. * @param structure with info need to associate.
  214. *
  215. * @return status
  216. ********************************************************************************************************/
  217. uint8 ZMacAssociateReq( ZMacAssociateReq_t *pData )
  218. {
  219. /* Right now, set security to zero */
  220. pData->Sec.SecurityLevel = false;
  221. MAC_MlmeAssociateReq ( (macMlmeAssociateReq_t *)pData);
  222. return ( ZMacSuccess );
  223. }
  224. /********************************************************************************************************
  225. * @fn ZMacAssociateRsp
  226. *
  227. * @brief Request to send an association response message.
  228. *
  229. * @param structure with associate response and info needed to send it.
  230. *
  231. * @return MAC_SUCCESS or MAC error code
  232. ********************************************************************************************************/
  233. uint8 ZMacAssociateRsp( ZMacAssociateRsp_t *pData )
  234. {
  235. /* TBD: set security to zero for now. Require Ztool change */
  236. pData->Sec.SecurityLevel = false;
  237. return ( MAC_MlmeAssociateRsp( (macMlmeAssociateRsp_t *) pData ) );
  238. }
  239. /********************************************************************************************************
  240. * @fn ZMacDisassociateReq
  241. *
  242. * @brief Request to send a disassociate request message.
  243. *
  244. * @param structure with info need send it.
  245. *
  246. * @return status
  247. ********************************************************************************************************/
  248. uint8 ZMacDisassociateReq( ZMacDisassociateReq_t *pData )
  249. {
  250. /* Right now, set security to zero */
  251. pData->Sec.SecurityLevel = false;
  252. MAC_MlmeDisassociateReq( (macMlmeDisassociateReq_t *)pData);
  253. return ( ZMacSuccess );
  254. }
  255. /********************************************************************************************************
  256. * @fn ZMacOrphanRsp
  257. *
  258. * @brief Allows next higher layer to respond to an orphan indication message.
  259. *
  260. * @param structure with info need send it.
  261. *
  262. * @return status
  263. ********************************************************************************************************/
  264. uint8 ZMacOrphanRsp( ZMacOrphanRsp_t *pData )
  265. {
  266. /* Right now, set security to zero */
  267. pData->Sec.SecurityLevel = false;
  268. MAC_MlmeOrphanRsp( (macMlmeOrphanRsp_t *)pData);
  269. return ( ZMacSuccess );
  270. }
  271. /********************************************************************************************************
  272. * @fn ZMacScanReq
  273. *
  274. * @brief This function is called to perform a network scan.
  275. *
  276. * @param param - structure with info need send it.
  277. *
  278. * @return status
  279. ********************************************************************************************************/
  280. uint8 ZMacScanReq( ZMacScanReq_t *pData )
  281. {
  282. _ScanChannels = pData->ScanChannels;
  283. /* scan in progress */
  284. if (ZMac_ScanBuf != NULL)
  285. {
  286. return MAC_SCAN_IN_PROGRESS;
  287. }
  288. if (pData->ScanType != ZMAC_ORPHAN_SCAN)
  289. {
  290. /* Allocate memory depends on the scan type */
  291. if (pData->ScanType == ZMAC_ED_SCAN)
  292. {
  293. if ((ZMac_ScanBuf = osal_mem_alloc(ZMAC_ED_SCAN_MAXCHANNELS)) == NULL)
  294. {
  295. return MAC_NO_RESOURCES;
  296. }
  297. osal_memset(ZMac_ScanBuf, 0, ZMAC_ED_SCAN_MAXCHANNELS);
  298. pData->Result.pEnergyDetect = ((uint8*)ZMac_ScanBuf) + MAC_CHAN_11;
  299. }
  300. else if (pData->MaxResults > 0)
  301. {
  302. if ((ZMac_ScanBuf = pData->Result.pPanDescriptor =
  303. osal_mem_alloc( sizeof( ZMacPanDesc_t ) * pData->MaxResults )) == NULL)
  304. {
  305. return MAC_NO_RESOURCES;
  306. }
  307. }
  308. }
  309. /* Channel Page */
  310. pData->ChannelPage = 0x00;
  311. MAC_MlmeScanReq ((macMlmeScanReq_t *)pData);
  312. return ZMacSuccess;
  313. }
  314. /********************************************************************************************************
  315. * @fn ZMacStartReq
  316. *
  317. * @brief This function is called to tell the MAC to transmit beacons
  318. * and become a coordinator.
  319. *
  320. * @param structure with info need send it.
  321. *
  322. * @return status
  323. ********************************************************************************************************/
  324. uint8 ZMacStartReq( ZMacStartReq_t *pData )
  325. {
  326. uint8 stat;
  327. // Probably want to keep the receiver on
  328. stat = true;
  329. MAC_MlmeSetReq( MAC_RX_ON_WHEN_IDLE, &stat );
  330. /* Right now, set security to zero */
  331. pData->RealignSec.SecurityLevel = false;
  332. pData->BeaconSec.SecurityLevel = false;
  333. MAC_MlmeStartReq((macMlmeStartReq_t *) pData);
  334. // MAC does not issue mlmeStartConfirm(), so we have to
  335. // mlmeStartConfirm( stat ); This needs to be addressed some how
  336. return ZMacSuccess;
  337. }
  338. /********************************************************************************************************
  339. * @fn ZMacSyncReq
  340. *
  341. * @brief This function is called to request a sync to the current
  342. * networks beacons.
  343. *
  344. * @param LogicalChannel -
  345. * @param TrackBeacon - true/false
  346. *
  347. * @return status
  348. ********************************************************************************************************/
  349. uint8 ZMacSyncReq( ZMacSyncReq_t *pData )
  350. {
  351. MAC_MlmeSyncReq( (macMlmeSyncReq_t *)pData);
  352. return ZMacSuccess;
  353. }
  354. /********************************************************************************************************
  355. * @fn ZMacPollReq
  356. *
  357. * @brief This function is called to request MAC data request poll.
  358. *
  359. * @param coordAddr -
  360. * @param coordPanId -
  361. * @param SecurityEnable - true or false.
  362. *
  363. * @return status
  364. ********************************************************************************************************/
  365. uint8 ZMacPollReq( ZMacPollReq_t *pData )
  366. {
  367. /* Right now, set security to zero */
  368. pData->Sec.SecurityLevel = false;
  369. MAC_MlmePollReq ((macMlmePollReq_t *)pData);
  370. return ( ZMacSuccess );
  371. }
  372. /********************************************************************************************************
  373. * @fn ZMacDataReqSec
  374. *
  375. * @brief Send a MAC Data Frame packet, calls the passed in function to apply non-MAC security
  376. * on the MAC data field after the MAC buffer allocation.
  377. *
  378. * @param pData - structure containing data and where to send it.
  379. * @param secCB - callback function to apply security, NULL indicates no security
  380. *
  381. * @return status
  382. ********************************************************************************************************/
  383. uint8 ZMacDataReqSec( ZMacDataReq_t *pData, applySecCB_t secCB )
  384. {
  385. macMcpsDataReq_t *pBuf;
  386. /* Allocate memory */
  387. pBuf = MAC_McpsDataAlloc( pData->msduLength, pData->Sec.SecurityLevel, pData->Sec.KeyIdMode );
  388. if ( pBuf )
  389. {
  390. /* Copy the addresses */
  391. osal_memcpy( &pBuf->mac, pData, sizeof (macDataReq_t) );
  392. /* Copy data */
  393. osal_memcpy( pBuf->msdu.p, pData->msdu, pData->msduLength );
  394. /* Copy Security parameters */
  395. osal_memcpy( &pBuf->sec, &pData->Sec, sizeof (macSec_t));
  396. /* Encrypt in place */
  397. if ( secCB && pBuf->msdu.len && pBuf->msdu.p )
  398. {
  399. if ( secCB( pBuf->msdu.len, pBuf->msdu.p ) != ZSuccess )
  400. {
  401. // Deallocate the buffer. MAC_McpsDataAlloc() calls osal_msg_allocate() and
  402. // returns the same pointer.
  403. osal_msg_deallocate( (uint8 *)pBuf );
  404. return ( MAC_NO_RESOURCES );
  405. }
  406. }
  407. /* Call Mac Data Request */
  408. MAC_McpsDataReq( pBuf );
  409. return ( ZMacSuccess );
  410. }
  411. return ( MAC_NO_RESOURCES );
  412. }
  413. /********************************************************************************************************
  414. * @fn ZMacDataReq
  415. *
  416. * @brief Send a MAC Data Frame packet.
  417. *
  418. * @param structure containing data and where to send it.
  419. *
  420. * @return status
  421. ********************************************************************************************************/
  422. uint8 ZMacDataReq( ZMacDataReq_t *pData )
  423. {
  424. return ZMacDataReqSec( pData, NULL );
  425. }
  426. /********************************************************************************************************
  427. * @fn ZMacPurgeReq
  428. *
  429. * @brief Purge a MAC Data Frame packet.
  430. *
  431. * @param MSDU data handle.
  432. *
  433. * @return status
  434. ********************************************************************************************************/
  435. uint8 ZMacPurgeReq( byte Handle )
  436. {
  437. MAC_McpsPurgeReq( Handle );
  438. return ZMacSuccess;
  439. }
  440. /********************************************************************************************************
  441. * @fn ZMacSrcMatchEnable
  442. *
  443. * @brief This function is call to enable AUTOPEND and source address matching.
  444. *
  445. * @param addressType - address type that the application uses
  446. * SADDR_MODE_SHORT or SADDR_MODE_EXT.
  447. * numEntries - number of source address table entries to be used
  448. *
  449. * @return status
  450. ********************************************************************************************************/
  451. ZMacStatus_t ZMacSrcMatchEnable (uint8 addrType, uint8 numEntries)
  452. {
  453. return (MAC_SrcMatchEnable(addrType, numEntries));
  454. }
  455. /********************************************************************************************************
  456. * @fn ZMacSrcMatchAddEntry
  457. *
  458. * @brief This function is called to add a short or extended address to source address table.
  459. *
  460. * @param addr - a pointer to sAddr_t which contains addrMode
  461. * and a union of a short 16-bit MAC address or an extended
  462. * 64-bit MAC address to be added to the source address table.
  463. * panID - the device PAN ID. It is only used when the addr is
  464. * using short address
  465. *
  466. * @return status
  467. ********************************************************************************************************/
  468. ZMacStatus_t ZMacSrcMatchAddEntry (zAddrType_t *addr, uint16 panID)
  469. {
  470. return (MAC_SrcMatchAddEntry ((sAddr_t*)addr, panID));
  471. }
  472. /********************************************************************************************************
  473. * @fn ZMacSrcMatchDeleteEntry
  474. *
  475. * @brief This function is called to delete a short or extended address from source address table.
  476. *
  477. * @param addr - a pointer to sAddr_t which contains addrMode
  478. * and a union of a short 16-bit MAC address or an extended
  479. * 64-bit MAC address to be added to the source address table.
  480. * panID - the device PAN ID. It is only used when the addr is
  481. * using short address
  482. *
  483. * @return status
  484. ********************************************************************************************************/
  485. ZMacStatus_t ZMacSrcMatchDeleteEntry (zAddrType_t *addr, uint16 panID)
  486. {
  487. return (MAC_SrcMatchDeleteEntry ((sAddr_t*)addr, panID));
  488. }
  489. /********************************************************************************************************
  490. * @fn ZMacSrcMatchAckAllPending
  491. *
  492. * @brief Enabled/disable acknowledging all packets with pending bit set
  493. * It is normally enabled when adding new entries to
  494. * the source address table fails due to the table is full, or
  495. * disabled when more entries are deleted and the table has
  496. * empty slots.
  497. *
  498. * @param option - true (acknowledging all packets with pending field set)
  499. * false (acknowledging all packets with pending field cleared)
  500. *
  501. * @return status
  502. ********************************************************************************************************/
  503. ZMacStatus_t ZMacSrcMatchAckAllPending (uint8 option)
  504. {
  505. MAC_SrcMatchAckAllPending (option);
  506. return ZMacSuccess;
  507. }
  508. /********************************************************************************************************
  509. * @fn ZMacSrcMatchCheckAllPending
  510. *
  511. * @brief This function is called to check if acknowledging all packets with pending bit set is enabled.
  512. *
  513. * @param none
  514. *
  515. * @return status
  516. ********************************************************************************************************/
  517. ZMacStatus_t ZMacSrcMatchCheckAllPending (void)
  518. {
  519. return (MAC_SrcMatchCheckAllPending ());
  520. }
  521. /********************************************************************************************************
  522. * @fn - ZMACPwrOnReq
  523. *
  524. * @brief - This function requests the MAC to power on the radio hardware
  525. * and wake up. When the power on procedure is complete the MAC
  526. * will send a MAC_PWR_ON_CNF to the application.
  527. *
  528. * @input - None.
  529. *
  530. * @output - None.
  531. *
  532. * @return - None.
  533. ********************************************************************************************************/
  534. void ZMacPwrOnReq ( void )
  535. {
  536. MAC_PwrOnReq();
  537. }
  538. /********************************************************************************************************
  539. * @fn MAC_PwrMode
  540. *
  541. * @brief This function returns the current power mode of the MAC.
  542. *
  543. * input parameters
  544. *
  545. * None.
  546. *
  547. * output parameters
  548. *
  549. * None.
  550. *
  551. * @return The current power mode of the MAC.
  552. ********************************************************************************************************/
  553. uint8 ZMac_PwrMode(void)
  554. {
  555. return (MAC_PwrMode());
  556. }
  557. /********************************************************************************************************
  558. * @fn ZMacSetTransmitPower
  559. *
  560. * @brief Set the transmitter power according to the level setting param.
  561. *
  562. * @param Valid power level setting as defined in ZMAC.h.
  563. *
  564. * @return ZMacSuccess if PHY_TRANSMIT_POWER found or ZMacUnsupportedAttribute.
  565. ********************************************************************************************************/
  566. uint8 ZMacSetTransmitPower( ZMacTransmitPower_t level )
  567. {
  568. return MAC_MlmeSetReq( ZMacPhyTransmitPowerSigned, &level );
  569. }
  570. /********************************************************************************************************
  571. * @fn ZMacSendNoData
  572. *
  573. * @brief This function sends an empty msg
  574. *
  575. * @param DstAddr - destination short address
  576. * DstPANId - destination pan id
  577. *
  578. * @return None
  579. ********************************************************************************************************/
  580. void ZMacSendNoData ( uint16 DstAddr, uint16 DstPANId )
  581. {
  582. macMcpsDataReq_t *pBuf;
  583. /* Allocate memory */
  584. pBuf = MAC_McpsDataAlloc(0, MAC_SEC_LEVEL_NONE, MAC_KEY_ID_MODE_NONE);
  585. if (pBuf)
  586. {
  587. /* Fill in src information */
  588. pBuf->mac.srcAddrMode = SADDR_MODE_SHORT;
  589. /* Fill in dst information */
  590. pBuf->mac.dstAddr.addr.shortAddr = DstAddr;
  591. pBuf->mac.dstAddr.addrMode = SADDR_MODE_SHORT;
  592. pBuf->mac.dstPanId = DstPANId;
  593. /* Misc information */
  594. pBuf->mac.msduHandle = 0;
  595. pBuf->mac.txOptions = ZMAC_TXOPTION_ACK | ZMAC_TXOPTION_NO_RETRANS | ZMAC_TXOPTION_NO_CNF;
  596. /* Right now, set security to zero */
  597. pBuf->sec.securityLevel = false;
  598. /* Call Mac Data Request */
  599. MAC_McpsDataReq(pBuf);
  600. }
  601. }
  602. /********************************************************************************************************
  603. * @fn ZMacStateIdle
  604. *
  605. * @brief This function returns true if the MAC state is idle.
  606. *
  607. * @param none
  608. *
  609. * @return TRUE if the MAC state is idle, FALSE otherwise.
  610. ********************************************************************************************************/
  611. uint8 ZMacStateIdle( void )
  612. {
  613. return macStateIdle();
  614. }