MT_MAC.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904
  1. /**************************************************************************************************
  2. Filename: MT_MAC.c
  3. Revised: $Date: 2009-03-30 22:36:57 -0700 (Mon, 30 Mar 2009) $
  4. Revision: $Revision: 19596 $
  5. Description: MonitorTest functions for the MAC 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. #if defined (MT_MAC_FUNC) || defined (MT_MAC_CB_FUNC) //MAC commands
  34. /***************************************************************************************************
  35. * INCLUDES
  36. ***************************************************************************************************/
  37. #include "ZComDef.h"
  38. #include "OSAL.h"
  39. #include "MT.h"
  40. #include "MT_UART.h"
  41. #include "ZMAC.h"
  42. #include "MT_MAC.h"
  43. #if !defined( WIN32 )
  44. #include "OnBoard.h"
  45. #endif
  46. /* MAC radio */
  47. #include "mac_radio_defs.h"
  48. /* Hal */
  49. #include "hal_uart.h"
  50. /***************************************************************************************************
  51. * MACROS
  52. ***************************************************************************************************/
  53. /* The length in bytes of the pending address fields in the beacon */
  54. #define MT_MAC_PEND_LEN(pendAddrSpec) ((((pendAddrSpec) & 0x07) * 2) + \
  55. ((((pendAddrSpec) & 0x70) >> 4) * 8))
  56. /* This matches the value used by nwk */
  57. #define MT_MAC_ED_SCAN_MAXCHANNELS 27
  58. /* Maximum size of pending address spec in beacon notify ind */
  59. #define MT_MAC_PEND_LEN_MAX 32
  60. /* Maximum size of the payload SDU in beacon notify ind */
  61. #define MT_MAC_SDU_LEN_MAX 32
  62. /* Maximum length of scan result in bytes */
  63. #define MT_MAC_SCAN_RESULT_LEN_MAX 32
  64. /* Maximum size of beacon payload */
  65. #define MT_MAC_BEACON_PAYLOAD_MAX 16
  66. /***************************************************************************************************
  67. * CONSTANTS
  68. ***************************************************************************************************/
  69. #define DEFAULT_NSDU_HANDLE 0x00
  70. #define MT_MAC_LEN_ASSOCIATE_IND 0x14 /* Associate Indication */
  71. #define MT_MAC_LEN_ASSOCIATE_CNF 0x0E /* Associate Confirmation */
  72. #define MT_MAC_LEN_DISASSOCIATE_IND 0x14 /* Disassociate Indication */
  73. #define MT_MAC_LEN_DISASSOCIATE_CNF 0x0c /* Disassociate Confirmation */
  74. #define MT_MAC_LEN_BEACON_NOTIFY_IND 0x63 /* Beacon Notification */
  75. #define MT_MAC_LEN_ORPHAN_IND 0x13 /* Orphan Indication */
  76. #define MT_MAC_LEN_SCAN_CNF 0x09 /* Scan Confirmation */
  77. #define MT_MAC_LEN_SYNC_LOSS_IND 0x10 /* Sync Loss Indication */
  78. #define MT_MAC_LEN_COMM_STATUS_IND 0x21 /* Comm Status Indication */
  79. #define MT_MAC_LEN_DATA_CNF 0x08 /* Data Confirmation */
  80. #define MT_MAC_LEN_DATA_IND 0x2C /* Data Indication */
  81. #define MT_MAC_LEN_PURGE_CNF 0x02 /* Purge Confirmation */
  82. /***************************************************************************************************
  83. * GLOBAL VARIABLES
  84. ***************************************************************************************************/
  85. uint16 _macCallbackSub;
  86. /* storage for MAC beacon payload */
  87. static uint8 mtMacBeaconPayload[MT_MAC_BEACON_PAYLOAD_MAX];
  88. /***************************************************************************************************
  89. * LOCAL FUNCTIONS
  90. ***************************************************************************************************/
  91. static void MT_MacSpi2Sec( ZMacSec_t *pSec, uint8 *pSrc );
  92. static void MT_MacSpi2Addr( zAddrType_t *pDst, uint8 *pSrc );
  93. static void MT_MacAddr2Spi( uint8 *pDst, zAddrType_t *pSrc );
  94. static void MT_MacRevExtCpy( uint8 *pDst, uint8 *pSrc );
  95. void MT_MacResetReq(uint8 *pBuf);
  96. void MT_MacInit(uint8 *pBuf);
  97. void MT_MacStartReq(uint8 *pBuf);
  98. void MT_MacSyncReq(uint8 *pBuf);
  99. void MT_MacDataReq(uint8 *pBuf);
  100. void MT_MacAssociateReq(uint8 *pBuf);
  101. void MT_MacDisassociateReq(uint8 *pBuf);
  102. void MT_MacGetReq(uint8 *pBuf);
  103. void MT_MacSetReq(uint8 *pBuf);
  104. void MT_MacScanReq(uint8 * pBuf);
  105. void MT_MacPollReq(uint8 *pBuf);
  106. void MT_MacPurgeReq(uint8 *pBuf);
  107. void MT_MacSetRxGainReq(uint8 *pBuf);
  108. void MT_MacAssociateRsp(uint8 *pBuf);
  109. void MT_MacOrphanRsp(uint8 *pBuf);
  110. void MT_MacSrcMatchEnable (uint8 *pBuf);
  111. void MT_MacSrcMatchAddEntry (uint8 *pBuf);
  112. void MT_MacSrcMatchDeleteEntry (uint8 *pBuf);
  113. void MT_MacSrcMatchCheckSrcAddr (uint8 *pBuf);
  114. void MT_MacSrcMatchAckAllPending (uint8 *pBuf);
  115. void MT_MacSrcMatchCheckAllPending (uint8 *pBuf);
  116. /***************************************************************************************************
  117. * @fn MT_MacCommandProcessing
  118. *
  119. * @brief Process all the MAC commands that are issued by test tool
  120. *
  121. * @param pBuf - pointer to the msg buffer
  122. *
  123. * | LEN | CMD0 | CMD1 | DATA |
  124. * | 1 | 1 | 1 | 0-255 |
  125. *
  126. * @return void
  127. ***************************************************************************************************/
  128. uint8 MT_MacCommandProcessing (uint8 *pBuf)
  129. {
  130. uint8 status = MT_RPC_SUCCESS;
  131. switch (pBuf[MT_RPC_POS_CMD1])
  132. {
  133. case MT_MAC_RESET_REQ:
  134. MT_MacResetReq(pBuf);
  135. break;
  136. case MT_MAC_INIT:
  137. MT_MacInit(pBuf);
  138. break;
  139. case MT_MAC_START_REQ:
  140. MT_MacStartReq(pBuf);
  141. break;
  142. case MT_MAC_SYNC_REQ:
  143. MT_MacSyncReq(pBuf);
  144. break;
  145. case MT_MAC_DATA_REQ:
  146. MT_MacDataReq(pBuf);
  147. break;
  148. case MT_MAC_ASSOCIATE_REQ:
  149. MT_MacAssociateReq(pBuf);
  150. break;
  151. case MT_MAC_DISASSOCIATE_REQ:
  152. MT_MacDisassociateReq(pBuf);
  153. break;
  154. case MT_MAC_GET_REQ:
  155. MT_MacGetReq(pBuf);
  156. break;
  157. case MT_MAC_SET_REQ:
  158. MT_MacSetReq(pBuf);
  159. break;
  160. case MT_MAC_GTS_REQ:
  161. /* Not supported */
  162. break;
  163. case MT_MAC_SCAN_REQ:
  164. MT_MacScanReq(pBuf);
  165. break;
  166. case MT_MAC_POLL_REQ:
  167. MT_MacPollReq(pBuf);
  168. break;
  169. case MT_MAC_PURGE_REQ:
  170. MT_MacPurgeReq(pBuf);
  171. break;
  172. case MT_MAC_SET_RX_GAIN_REQ:
  173. MT_MacSetRxGainReq(pBuf);
  174. break;
  175. case MT_MAC_ASSOCIATE_RSP:
  176. MT_MacAssociateRsp(pBuf);
  177. break;
  178. case MT_MAC_ORPHAN_RSP:
  179. MT_MacOrphanRsp(pBuf);
  180. break;
  181. case MT_MAC_SRC_MATCH_ENABLE:
  182. MT_MacSrcMatchEnable(pBuf);
  183. break;
  184. case MT_MAC_SRC_MATCH_ADD_ENTRY:
  185. MT_MacSrcMatchAddEntry(pBuf);
  186. break;
  187. case MT_MAC_SRC_MATCH_DEL_ENTRY:
  188. MT_MacSrcMatchDeleteEntry(pBuf);
  189. break;
  190. case MT_MAC_SRC_MATCH_CHECK_SRC_ADDR:
  191. MT_MacSrcMatchCheckSrcAddr(pBuf);
  192. break;
  193. case MT_MAC_SRC_MATCH_ACK_ALL_PENDING:
  194. MT_MacSrcMatchAckAllPending(pBuf);
  195. break;
  196. case MT_MAC_SRC_MATCH_CHECK_ALL_PENDING:
  197. MT_MacSrcMatchCheckAllPending(pBuf);
  198. break;
  199. default:
  200. status = MT_RPC_ERR_COMMAND_ID;
  201. break;
  202. }
  203. return status;
  204. }
  205. /***************************************************************************************************
  206. * @fn MT_MacReset
  207. *
  208. * @brief Process MAC Reset command that are issued by test tool
  209. *
  210. * @param pBuf - Buffer contains the data
  211. *
  212. * @return void
  213. ***************************************************************************************************/
  214. void MT_MacResetReq(uint8 *pBuf)
  215. {
  216. uint8 retValue, cmdId;
  217. /* Parse header */
  218. cmdId = pBuf[MT_RPC_POS_CMD1];
  219. pBuf += MT_RPC_FRAME_HDR_SZ;
  220. retValue = ZMacReset(*pBuf);
  221. /* Build and send back the response */
  222. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue );
  223. }
  224. /***************************************************************************************************
  225. * @fn MT_MacInit
  226. *
  227. * @brief Process Mac Init command that are issued by test tool
  228. *
  229. * @param pBuf - Buffer contains the data
  230. *
  231. * @return void
  232. ***************************************************************************************************/
  233. void MT_MacInit(uint8 *pBuf)
  234. {
  235. uint8 retValue, cmdId;
  236. /* Parse header */
  237. cmdId = pBuf[MT_RPC_POS_CMD1];
  238. pBuf += MT_RPC_FRAME_HDR_SZ;
  239. retValue = ZMacInit();
  240. /* Build and send back the response */
  241. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue );
  242. }
  243. /***************************************************************************************************
  244. * @fn MT_MacStart
  245. *
  246. * @brief Process MAC Start command that are issued by test tool
  247. *
  248. * @param pBuf - Buffer contains the data
  249. *
  250. * @return void
  251. ***************************************************************************************************/
  252. void MT_MacStartReq(uint8 *pBuf)
  253. {
  254. uint8 retValue, cmdId;
  255. ZMacStartReq_t startReq;
  256. /* Parse header */
  257. cmdId = pBuf[MT_RPC_POS_CMD1];
  258. pBuf += MT_RPC_FRAME_HDR_SZ;
  259. #ifdef RTR_NWK
  260. /* StartTime */
  261. startReq.StartTime = BUILD_UINT32 (pBuf[0], pBuf[1], pBuf[2], pBuf[3]);
  262. pBuf += 4;
  263. /* PanID */
  264. startReq.PANID = BUILD_UINT16( pBuf[0] , pBuf[1] );
  265. pBuf += 2;
  266. /* Fill in other fields sequentially incrementing the pointer*/
  267. startReq.LogicalChannel = *pBuf++;
  268. startReq.ChannelPage = *pBuf++;
  269. startReq.BeaconOrder = *pBuf++;
  270. startReq.SuperframeOrder = *pBuf++;
  271. startReq.PANCoordinator = *pBuf++;
  272. startReq.BatteryLifeExt = *pBuf++;
  273. startReq.CoordRealignment = *pBuf++;
  274. /* Realign Security Information */
  275. MT_MacSpi2Sec( &startReq.RealignSec, pBuf );
  276. pBuf += ZTEST_DEFAULT_SEC_LEN;
  277. /* Beacon Security Information */
  278. MT_MacSpi2Sec( &startReq.BeaconSec, pBuf );
  279. /* Call corresponding ZMAC function */
  280. retValue = ZMacStartReq( &startReq );
  281. #else
  282. retValue = ZMacDenied;
  283. #endif
  284. /* Build and send back the response */
  285. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue );
  286. }
  287. /***************************************************************************************************
  288. * @fn MT_MacSync
  289. *
  290. * @brief Process MAC Sync command that are issued by test tool
  291. *
  292. * @param pBuf - Buffer contains the data
  293. *
  294. * @return void
  295. ***************************************************************************************************/
  296. void MT_MacSyncReq(uint8 *pBuf)
  297. {
  298. uint8 retValue, cmdId;
  299. ZMacSyncReq_t syncReq;
  300. /* Parse header */
  301. cmdId = pBuf[MT_RPC_POS_CMD1];
  302. pBuf += MT_RPC_FRAME_HDR_SZ;
  303. /* LogicalChannel */
  304. syncReq.LogicalChannel = *pBuf++;
  305. /* ChannelPage */
  306. syncReq.ChannelPage = *pBuf++;
  307. /* TrackBeacon */
  308. syncReq.TrackBeacon = *pBuf;
  309. /* Call corresponding ZMAC function */
  310. retValue = ZMacSyncReq( &syncReq );
  311. /* Build and send back the response */
  312. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue );
  313. }
  314. /***************************************************************************************************
  315. * @fn MT_MacDataReq
  316. *
  317. * @brief Process MAC Data Request command that are issued by test tool
  318. *
  319. * @param pBuf - Buffer contains the data
  320. *
  321. * @return void
  322. ***************************************************************************************************/
  323. void MT_MacDataReq(uint8 *pBuf)
  324. {
  325. uint8 retValue, cmdId;
  326. ZMacDataReq_t dataReq;
  327. /* Parse header */
  328. cmdId = pBuf[MT_RPC_POS_CMD1];
  329. pBuf += MT_RPC_FRAME_HDR_SZ;
  330. /* Destination address mode */
  331. dataReq.DstAddr.addrMode = *pBuf++;
  332. /* Destination address */
  333. MT_MacSpi2Addr( &dataReq.DstAddr, pBuf);
  334. pBuf += Z_EXTADDR_LEN;
  335. /* Destination Pan ID */
  336. dataReq.DstPANId = BUILD_UINT16( pBuf[0] , pBuf[1] );
  337. pBuf += 2;
  338. /* Source address mode */
  339. dataReq.SrcAddrMode = *pBuf++;
  340. /* Handle */
  341. dataReq.Handle = *pBuf++;
  342. /* TxOptions */
  343. dataReq.TxOptions = *pBuf++;
  344. /* Channel */
  345. dataReq.Channel = *pBuf++;
  346. /* Power */
  347. dataReq.Power = *pBuf++;
  348. /* Security Information */
  349. MT_MacSpi2Sec( &dataReq.Sec, pBuf );
  350. pBuf += ZTEST_DEFAULT_SEC_LEN;
  351. /* Data length */
  352. dataReq.msduLength = *pBuf++;
  353. /* Data - Just pass the pointer to the structure */
  354. dataReq.msdu = pBuf;
  355. /* Call corresponding ZMAC function */
  356. retValue = ZMacDataReq( &dataReq );
  357. /* Build and send back the response */
  358. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue );
  359. }
  360. /***************************************************************************************************
  361. * @fn MT_MacAssociateReq
  362. *
  363. * @brief Process MAC Get Request command that are issued by test tool
  364. *
  365. * @param pBuf - Buffer contains the data
  366. *
  367. * @return void
  368. ***************************************************************************************************/
  369. void MT_MacAssociateReq(uint8 *pBuf)
  370. {
  371. uint8 retValue, cmdId;
  372. ZMacAssociateReq_t assocReq;
  373. /* Parse header */
  374. cmdId = pBuf[MT_RPC_POS_CMD1];
  375. pBuf += MT_RPC_FRAME_HDR_SZ;
  376. /* Logical Channel */
  377. assocReq.LogicalChannel = *pBuf++;
  378. /* Channel Page */
  379. assocReq.ChannelPage = *pBuf++;
  380. /* Address Mode */
  381. assocReq.CoordAddress.addrMode = *pBuf++;
  382. /* Coordinator Address, address mode must be set at this point */
  383. MT_MacSpi2Addr( &assocReq.CoordAddress, pBuf );
  384. pBuf += Z_EXTADDR_LEN;
  385. /* Coordinator PanID */
  386. assocReq.CoordPANId = BUILD_UINT16( pBuf[0] , pBuf[1] );
  387. pBuf += 2;
  388. /* Capability information */
  389. assocReq.CapabilityInformation = *pBuf++;
  390. /* Security Information */
  391. MT_MacSpi2Sec( &assocReq.Sec, pBuf );
  392. /* Call corresponding ZMAC function */
  393. retValue = ZMacAssociateReq( &assocReq );
  394. /* Build and send back the response */
  395. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue );
  396. }
  397. /***************************************************************************************************
  398. * @fn MT_MacDisassociateReq
  399. *
  400. * @brief Process MAC Get Request command that are issued by test tool
  401. *
  402. * @param pBuf - Buffer contains the data
  403. *
  404. * @return void
  405. ***************************************************************************************************/
  406. void MT_MacDisassociateReq(uint8 *pBuf)
  407. {
  408. uint8 retValue, cmdId;
  409. ZMacDisassociateReq_t disassocReq;
  410. /* Parse header */
  411. cmdId = pBuf[MT_RPC_POS_CMD1];
  412. pBuf += MT_RPC_FRAME_HDR_SZ;
  413. /* Device address mode */
  414. disassocReq.DeviceAddress.addrMode = *pBuf++;
  415. /* Device address - Device address mode have to be set to use this function*/
  416. MT_MacSpi2Addr( &disassocReq.DeviceAddress, pBuf);
  417. pBuf += Z_EXTADDR_LEN;
  418. /* Pan ID */
  419. disassocReq.DevicePanId = BUILD_UINT16( pBuf[0] , pBuf[1] );
  420. pBuf += 2;
  421. /* Disassociate reason */
  422. disassocReq.DisassociateReason = *pBuf++;
  423. /* TxIndirect */
  424. disassocReq.TxIndirect = *pBuf++;
  425. /* Security Information */
  426. MT_MacSpi2Sec( &disassocReq.Sec, pBuf );
  427. /* Call corresponding ZMAC function */
  428. retValue = ZMacDisassociateReq( &disassocReq );
  429. /* Build and send back the response */
  430. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue );
  431. }
  432. /***************************************************************************************************
  433. * @fn MT_MacGetReq
  434. *
  435. * @brief Process MAC Get Request command that are issued by test tool
  436. *
  437. * @param pBuf - Buffer contains the data
  438. *
  439. * @return void
  440. ***************************************************************************************************/
  441. void MT_MacGetReq(uint8 *pBuf)
  442. {
  443. uint8 respLen, cmdId, attr;
  444. uint8 *pRetBuf;
  445. /* Parse header */
  446. cmdId = pBuf[MT_RPC_POS_CMD1];
  447. pBuf += MT_RPC_FRAME_HDR_SZ;
  448. /* Response length is 16 bytes + 1 byte status */
  449. respLen = ZTEST_DEFAULT_PARAM_LEN;
  450. /* Allocate */
  451. pRetBuf = osal_mem_alloc(respLen);
  452. /* Attribute to be read */
  453. attr = *pBuf;
  454. if (pRetBuf)
  455. {
  456. /* Zero everything */
  457. osal_memset(pRetBuf, 0, respLen);
  458. /* Default to ZFailure */
  459. pRetBuf[0] = ZFailure;
  460. /* Read the pib value */
  461. pRetBuf[0] = ZMacGetReq(attr, &pRetBuf[1]);
  462. /* Build and send back the response */
  463. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, respLen, pRetBuf );
  464. /* Deallocate */
  465. osal_mem_free(pRetBuf);
  466. }
  467. }
  468. /***************************************************************************************************
  469. * @fn MT_MacSetReq
  470. *
  471. * @brief Process MAC Set Req command that are issued by test tool
  472. *
  473. * @param pBuf - Buffer contains the data
  474. *
  475. * @return void
  476. ***************************************************************************************************/
  477. void MT_MacSetReq(uint8 *pBuf)
  478. {
  479. uint8 retValue, cmdId, attr;
  480. /* Parse header */
  481. cmdId = pBuf[MT_RPC_POS_CMD1];
  482. pBuf += MT_RPC_FRAME_HDR_SZ;
  483. /*
  484. In the data field of 'msg', the first byte is the attribute and remainder
  485. is the attribute value. So the pointer 'pBuf' points directly to the attribute.
  486. The value of the attribute is from the next byte position
  487. */
  488. attr = *pBuf;
  489. /* special case for beacon payload */
  490. if ( attr == ZMacBeaconMSDU )
  491. {
  492. osal_memcpy( mtMacBeaconPayload, pBuf + 1, MT_MAC_BEACON_PAYLOAD_MAX );
  493. retValue = ZMacSetReq( (ZMacAttributes_t)attr , (byte *) &mtMacBeaconPayload );
  494. }
  495. else
  496. {
  497. retValue = ZMacSetReq( (ZMacAttributes_t)attr , pBuf + 1 );
  498. }
  499. /* Build and send back the response */
  500. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue );
  501. }
  502. /***************************************************************************************************
  503. * @fn MT_MacScanReq
  504. *
  505. * @brief Process MAC Scan Req command that are issued by test tool
  506. *
  507. * @param pBuf - Buffer contains the data
  508. *
  509. * @return void
  510. ***************************************************************************************************/
  511. void MT_MacScanReq(uint8 * pBuf)
  512. {
  513. uint8 retValue, cmdId;
  514. ZMacScanReq_t scanReq;
  515. /* Parse header */
  516. cmdId = pBuf[MT_RPC_POS_CMD1];
  517. pBuf += MT_RPC_FRAME_HDR_SZ;
  518. /* ScanChannels is the 32-bit channel list */
  519. scanReq.ScanChannels = BUILD_UINT32 (pBuf[0], pBuf[1], pBuf[2], pBuf[3]);
  520. pBuf += 4;
  521. /* Fill in fields sequentially incrementing the pointer */
  522. scanReq.ScanType = *pBuf++;
  523. /* ScanDuration */
  524. scanReq.ScanDuration = *pBuf++;
  525. /* Channel Page */
  526. scanReq.ChannelPage = *pBuf++;
  527. /* MaxResults */
  528. scanReq.MaxResults = *pBuf++;
  529. /* Security Information */
  530. MT_MacSpi2Sec( &scanReq.Sec, pBuf );
  531. /* Call corresponding ZMAC function */
  532. retValue = ZMacScanReq( &scanReq );
  533. /* Build and send back the response */
  534. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue );
  535. }
  536. /***************************************************************************************************
  537. * @fn MT_MacPollReq
  538. *
  539. * @brief Process MAC Poll Req command that are issued by test tool
  540. *
  541. * @param pBuf - Buffer contains the data
  542. *
  543. * @return void
  544. ***************************************************************************************************/
  545. void MT_MacPollReq(uint8 *pBuf)
  546. {
  547. uint8 retValue, cmdId;
  548. ZMacPollReq_t pollReq;
  549. /* Parse header */
  550. cmdId = pBuf[MT_RPC_POS_CMD1];
  551. pBuf += MT_RPC_FRAME_HDR_SZ;
  552. /* Coordinator address mode */
  553. pollReq.CoordAddress.addrMode = *pBuf++;
  554. /* Coordinator address - Device address mode have to be set to use this function */
  555. MT_MacSpi2Addr( &pollReq.CoordAddress, pBuf);
  556. pBuf += Z_EXTADDR_LEN;
  557. /* Coordinator Pan ID */
  558. pollReq.CoordPanId = BUILD_UINT16(pBuf[0] , pBuf[1]);
  559. pBuf += 2;
  560. /* Security Information */
  561. MT_MacSpi2Sec(&pollReq.Sec, pBuf);
  562. /* Call corresponding ZMAC function */
  563. retValue = ZMacPollReq( &pollReq );
  564. /* Build and send back the response */
  565. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue );
  566. }
  567. /***************************************************************************************************
  568. * @fn MT_MacPurgeReq
  569. *
  570. * @brief Process MAC Purge Req command that are issued by test tool
  571. *
  572. * @param pBuf - Buffer contains the data
  573. *
  574. * @return void
  575. ***************************************************************************************************/
  576. void MT_MacPurgeReq(uint8 *pBuf)
  577. {
  578. uint8 retValue, cmdId;
  579. /* Parse header */
  580. cmdId = pBuf[MT_RPC_POS_CMD1];
  581. pBuf += MT_RPC_FRAME_HDR_SZ;
  582. /* First and only byte - MsduHandle */
  583. retValue = ZMacPurgeReq (*pBuf);
  584. /* Build and send back the response */
  585. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue );
  586. }
  587. /***************************************************************************************************
  588. * @fn MT_MacSetRxGainReq
  589. *
  590. * @brief Process MAC Rx Gain Req command that are issued by test tool
  591. *
  592. * @param pBuf - Buffer contains the data
  593. *
  594. * @return void
  595. ***************************************************************************************************/
  596. void MT_MacSetRxGainReq(uint8 *pBuf)
  597. {
  598. uint8 retValue, cmdId;
  599. /* Parse header */
  600. cmdId = pBuf[MT_RPC_POS_CMD1];
  601. pBuf += MT_RPC_FRAME_HDR_SZ;
  602. #ifdef HAL_PA_LNA
  603. /* Toggle PA/LNA mode */
  604. if (*pBuf)
  605. {
  606. HAL_PA_LNA_RX_HGM();
  607. }
  608. else
  609. {
  610. HAL_PA_LNA_RX_LGM();
  611. }
  612. retValue = ZSuccess;
  613. #else
  614. retValue = ZFailure;
  615. #endif
  616. /* Build and send back the response */
  617. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue );
  618. }
  619. /***************************************************************************************************
  620. * @fn MT_MacAssociateRsp
  621. *
  622. * @brief Process MAC Associate Rsp command that are issued by test tool
  623. *
  624. * @param pBuf - Buffer contains the data
  625. *
  626. * @return void
  627. ***************************************************************************************************/
  628. void MT_MacAssociateRsp(uint8 *pBuf)
  629. {
  630. uint8 retValue, cmdId;
  631. ZMacAssociateRsp_t assocRsp;
  632. /* Parse header */
  633. cmdId = pBuf[MT_RPC_POS_CMD1];
  634. pBuf += MT_RPC_FRAME_HDR_SZ;
  635. #ifdef RTR_NWK
  636. /* The address of the device requesting association */
  637. MT_MacRevExtCpy(assocRsp.DeviceAddress, pBuf);
  638. pBuf += Z_EXTADDR_LEN;
  639. /* The short address allocated to the (associated) device */
  640. assocRsp.AssocShortAddress = BUILD_UINT16(pBuf[0],pBuf[1]);
  641. pBuf += 2;
  642. /* Status of the association */
  643. assocRsp.Status = *pBuf++;
  644. /* Security Information */
  645. MT_MacSpi2Sec( &assocRsp.Sec, pBuf );
  646. /* Call corresponding ZMAC function */
  647. retValue = ZMacAssociateRsp( &assocRsp );
  648. #else
  649. retValue = ZMacDenied;
  650. #endif
  651. /* Build and send back the response */
  652. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue);
  653. }
  654. /***************************************************************************************************
  655. * @fn MT_MacOrphanRsp
  656. *
  657. * @brief Process MAC Orphan Response command that are issued by test tool
  658. *
  659. * @param pBuf - Buffer contains the data
  660. *
  661. * @return void
  662. ***************************************************************************************************/
  663. void MT_MacOrphanRsp(uint8 *pBuf)
  664. {
  665. uint8 retValue, cmdId;
  666. ZMacOrphanRsp_t orphanRsp;
  667. /* Parse header */
  668. cmdId = pBuf[MT_RPC_POS_CMD1];
  669. pBuf += MT_RPC_FRAME_HDR_SZ;
  670. /* Extended address of the device sending the notification */
  671. MT_MacRevExtCpy( orphanRsp.OrphanAddress, pBuf );
  672. pBuf += Z_EXTADDR_LEN;
  673. /* Short address of the orphan device */
  674. orphanRsp.ShortAddress = BUILD_UINT16( pBuf[0] , pBuf[1] );
  675. pBuf += 2;
  676. /* Associated member */
  677. orphanRsp.AssociatedMember = *pBuf++;
  678. /* Security Information */
  679. MT_MacSpi2Sec( &orphanRsp.Sec, pBuf );
  680. /* Call corresponding ZMAC function */
  681. retValue = ZMacOrphanRsp( &orphanRsp );
  682. /* Build and send back the response */
  683. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue);
  684. }
  685. /***************************************************************************************************
  686. * @fn MAC_SrcMatchEnable
  687. *
  688. * @brief Enabled AUTOPEND and source address matching.
  689. *
  690. * @param pBuf - Buffer contains the data
  691. *
  692. * @return void
  693. ***************************************************************************************************/
  694. void MT_MacSrcMatchEnable (uint8 *pBuf)
  695. {
  696. uint8 retValue, cmdId;
  697. /* Parse header */
  698. cmdId = pBuf[MT_RPC_POS_CMD1];
  699. pBuf += MT_RPC_FRAME_HDR_SZ;
  700. #ifdef AUTO_PEND
  701. /* Call the routine */
  702. retValue = ZMacSrcMatchEnable (pBuf[0], pBuf[1]);
  703. #else
  704. retValue = ZMacUnsupported;
  705. #endif
  706. /* Build and send back the response */
  707. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue );
  708. }
  709. /***************************************************************************************************
  710. * @fn MAC_SrcMatchAddEntry
  711. *
  712. * @brief Add a short or extended address to source address table.
  713. *
  714. * @param pBuf - Buffer contains the data
  715. *
  716. * @return void
  717. ***************************************************************************************************/
  718. void MT_MacSrcMatchAddEntry (uint8 *pBuf)
  719. {
  720. uint8 retValue, cmdId;
  721. /* Parse header */
  722. cmdId = pBuf[MT_RPC_POS_CMD1];
  723. pBuf += MT_RPC_FRAME_HDR_SZ;
  724. #ifdef AUTO_PEND
  725. uint16 panID;
  726. zAddrType_t devAddr;
  727. /* Address mode */
  728. devAddr.addrMode = *pBuf++;
  729. /* Address based on the address mode */
  730. MT_MacSpi2Addr( &devAddr, pBuf);
  731. pBuf += Z_EXTADDR_LEN;
  732. /* PanID */
  733. panID = BUILD_UINT16( pBuf[0] , pBuf[1] );
  734. /* Call the routine */
  735. retValue = ZMacSrcMatchAddEntry (&devAddr, panID);
  736. #else
  737. retValue = ZMacUnsupported;
  738. #endif
  739. /* Build and send back the response */
  740. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue );
  741. }
  742. /***************************************************************************************************
  743. * @fn MAC_SrcMatchDeleteEntry
  744. *
  745. * @brief Delete a short or extended address from source address table.
  746. *
  747. * @param pBuf - Buffer contains the data
  748. *
  749. * @return void
  750. ***************************************************************************************************/
  751. void MT_MacSrcMatchDeleteEntry (uint8 *pBuf)
  752. {
  753. uint8 retValue, cmdId;
  754. /* Parse header */
  755. cmdId = pBuf[MT_RPC_POS_CMD1];
  756. pBuf += MT_RPC_FRAME_HDR_SZ;
  757. #ifdef AUTO_PEND
  758. uint16 panID;
  759. zAddrType_t devAddr;
  760. /* Address mode */
  761. devAddr.addrMode = *pBuf++;
  762. /* Address based on the address mode */
  763. MT_MacSpi2Addr( &devAddr, pBuf);
  764. pBuf += Z_EXTADDR_LEN;
  765. /* PanID */
  766. panID = BUILD_UINT16( pBuf[0] , pBuf[1] );
  767. /* Call the routine */
  768. retValue = ZMacSrcMatchDeleteEntry (&devAddr, panID);
  769. #else
  770. retValue = ZMacUnsupported;
  771. #endif
  772. /* Build and send back the response */
  773. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue );
  774. }
  775. /***************************************************************************************************
  776. * @fn MT_MacSrcMatchCheckSrcAddr
  777. *
  778. * @brief Check if a short or extended address is in the source address table.
  779. *
  780. * @param pBuf - Buffer contains the data
  781. *
  782. * @return void
  783. ***************************************************************************************************/
  784. void MT_MacSrcMatchCheckSrcAddr (uint8 *pBuf)
  785. {
  786. uint8 cmdId;
  787. uint8 retArray[2];
  788. /* Parse header */
  789. cmdId = pBuf[MT_RPC_POS_CMD1];
  790. pBuf += MT_RPC_FRAME_HDR_SZ;
  791. #if 0 /* Unsupported */
  792. uint16 panID;
  793. zAddrType_t devAddr;
  794. /* Address mode */
  795. devAddr.addrMode = *pBuf++;
  796. /* Address based on the address mode */
  797. MT_MacSpi2Addr( &devAddr, pBuf);
  798. pBuf += Z_EXTADDR_LEN;
  799. /* PanID */
  800. panID = BUILD_UINT16( pBuf[0] , pBuf[1] );
  801. /* Call the routine */
  802. retArray[1] = ZMacSrcMatchCheckSrcAddr (&devAddr, panID);
  803. /* Return failure if the index is invalid */
  804. if (retArray[1] == ZMacSrcMatchInvalidIndex )
  805. {
  806. retArray[0] = ZFailure;
  807. }
  808. else
  809. {
  810. retArray[0] = ZSuccess;
  811. }
  812. #else
  813. retArray[0] = ZMacUnsupported;
  814. retArray[1] = ZMacSrcMatchInvalidIndex;
  815. #endif
  816. /* Build and send back the response */
  817. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 2, retArray );
  818. }
  819. /***************************************************************************************************
  820. * @fn MAC_SrcMatchAckAllPending
  821. *
  822. * @brief Enabled/disable acknowledging all packets with pending bit set
  823. * It is normally enabled when adding new entries to
  824. * the source address table fails due to the table is full, or
  825. * disabled when more entries are deleted and the table has
  826. * empty slots.
  827. *
  828. * @param pBuf - Buffer contains the data
  829. *
  830. * @return void
  831. ***************************************************************************************************/
  832. void MT_MacSrcMatchAckAllPending (uint8 *pBuf)
  833. {
  834. uint8 retValue, cmdId;
  835. /* Parse header */
  836. cmdId = pBuf[MT_RPC_POS_CMD1];
  837. pBuf += MT_RPC_FRAME_HDR_SZ;
  838. #ifdef AUTO_PEND
  839. /* Call the routine */
  840. retValue = ZMacSrcMatchAckAllPending(*pBuf);
  841. #else
  842. retValue = ZMacUnsupported;
  843. #endif
  844. /* Build and send back the response */
  845. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 1, &retValue );
  846. }
  847. /***************************************************************************************************
  848. * @fn MT_MacSrcMatchCheckAllPending
  849. *
  850. * @brief Check if acknowledging all packets with pending bit set
  851. * is enabled.
  852. *
  853. * @param pBuf - Buffer contains the data
  854. *
  855. * @return void
  856. ***************************************************************************************************/
  857. void MT_MacSrcMatchCheckAllPending (uint8 *pBuf)
  858. {
  859. uint8 retArray[2], cmdId;
  860. /* Parse header */
  861. cmdId = pBuf[MT_RPC_POS_CMD1];
  862. pBuf += MT_RPC_FRAME_HDR_SZ;
  863. #ifdef AUTO_PEND
  864. /* Call the routine */
  865. retArray[0] = ZMacSuccess;
  866. retArray[1] = ZMacSrcMatchCheckAllPending();
  867. #else
  868. retArray[0] = ZMacUnsupported;
  869. retArray[1] = FALSE;
  870. #endif
  871. /* Build and send back the response */
  872. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_MAC), cmdId, 2, retArray );
  873. }
  874. #if defined ( MT_MAC_CB_FUNC )
  875. /***************************************************************************************************
  876. * @fn nwk_MTCallbackSubNwkSyncLossInd
  877. *
  878. * @brief Process the callback subscription for nwk_sync_loss_ind
  879. *
  880. * @param byte LossReason
  881. *
  882. * @return None
  883. ***************************************************************************************************/
  884. void nwk_MTCallbackSubNwkSyncLossInd( ZMacSyncLossInd_t *param )
  885. {
  886. uint8 respLen;
  887. uint8 *pRetBuf, *tp;
  888. respLen = MT_MAC_LEN_SYNC_LOSS_IND;
  889. pRetBuf = osal_mem_alloc (respLen);
  890. if ( pRetBuf )
  891. {
  892. tp = pRetBuf;
  893. /* Status - loss reason */
  894. *tp++ = param->hdr.Status;
  895. /* Pan Id */
  896. *tp++ = LO_UINT16( param->PANId );
  897. *tp++ = HI_UINT16( param->PANId );
  898. /* Logical Channel */
  899. *tp++ = param->LogicalChannel;
  900. /* Channel Page */
  901. *tp++ = param->ChannelPage;
  902. /* Security */
  903. MT_MacSpi2Sec ((ZMacSec_t *)tp, (uint8 *)&param->Sec);
  904. /* Build and send back the response */
  905. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_MAC), MT_MAC_SYNC_LOSS_IND, respLen, pRetBuf);
  906. /* Deallocate */
  907. osal_mem_free(pRetBuf);
  908. }
  909. }
  910. /***************************************************************************************************
  911. * @fn nwk_MTCallbackSubNwkAssociateInd
  912. *
  913. * @brief Process the callback subscription for nwk_associate_ind
  914. *
  915. * @param pointer of type macnwk_associate_ind_t
  916. *
  917. * @return None
  918. ***************************************************************************************************/
  919. void nwk_MTCallbackSubNwkAssociateInd( ZMacAssociateInd_t *param )
  920. {
  921. uint8 respLen;
  922. uint8 *pRetBuf, *tp;
  923. respLen = MT_MAC_LEN_ASSOCIATE_IND;
  924. pRetBuf = osal_mem_alloc (respLen);
  925. if ( pRetBuf )
  926. {
  927. tp = pRetBuf;
  928. /* Extended address */
  929. MT_MacAddr2Spi(pRetBuf, (zAddrType_t*)param->DeviceAddress);
  930. tp += Z_EXTADDR_LEN;
  931. /* Capability Information */
  932. *tp++ = param->CapabilityInformation;
  933. /* Security */
  934. MT_MacSpi2Sec ((ZMacSec_t *)tp, (uint8 *)&param->Sec);
  935. /* Build and send back the response */
  936. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_MAC), MT_MAC_ASSOCIATE_IND, respLen, pRetBuf);
  937. /* Deallocate */
  938. osal_mem_free(pRetBuf);
  939. }
  940. }
  941. /***************************************************************************************************
  942. * @fn nwk_MTCallbackSubNwkAssociateCnf
  943. *
  944. * @brief Process the callback subscription for nwk_associate_cnf
  945. *
  946. * @param pointer of type macnwk_associate_cnf_t
  947. *
  948. * @return SUCCESS if message sent succesfully , else N_FAIL
  949. ***************************************************************************************************/
  950. void nwk_MTCallbackSubNwkAssociateCnf( ZMacAssociateCnf_t *param )
  951. {
  952. uint8 respLen;
  953. uint8 *pRetBuf, *tp;
  954. respLen = MT_MAC_LEN_ASSOCIATE_CNF;
  955. pRetBuf = osal_mem_alloc (respLen);
  956. if ( pRetBuf )
  957. {
  958. tp = pRetBuf;
  959. /* Status */
  960. *tp++ = param->hdr.Status;
  961. /* Short address */
  962. *tp++ = LO_UINT16( param->AssocShortAddress );
  963. *tp++ = HI_UINT16( param->AssocShortAddress );
  964. /* Security */
  965. MT_MacSpi2Sec ((ZMacSec_t *)tp, (uint8 *)&param->Sec);
  966. /* Build and send back the response */
  967. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_MAC), MT_MAC_ASSOCIATE_CNF, respLen, pRetBuf);
  968. /* Deallocate */
  969. osal_mem_free(pRetBuf);
  970. }
  971. }
  972. /***************************************************************************************************
  973. * @fn nwk_MTCallbackSubNwkBeaconNotifyInd
  974. *
  975. * @brief Process the callback subscription for
  976. * beacon_notify_ind.
  977. *
  978. * @param pointer to ZMacBeaconNotifyInd_t
  979. *
  980. * @return None
  981. ***************************************************************************************************/
  982. void nwk_MTCallbackSubNwkBeaconNotifyInd ( ZMacBeaconNotifyInd_t *param )
  983. {
  984. uint8 respLen;
  985. uint8 *pRetBuf, *tp;
  986. respLen = MT_MAC_LEN_BEACON_NOTIFY_IND;
  987. pRetBuf = osal_mem_alloc (respLen);
  988. if ( pRetBuf )
  989. {
  990. tp = pRetBuf;
  991. /* BSN */
  992. *tp++ = param->BSN;
  993. /* Timestamp */
  994. *tp++ = BREAK_UINT32( param->pPanDesc->TimeStamp, 0 );
  995. *tp++ = BREAK_UINT32( param->pPanDesc->TimeStamp, 1 );
  996. *tp++ = BREAK_UINT32( param->pPanDesc->TimeStamp, 2 );
  997. *tp++ = BREAK_UINT32( param->pPanDesc->TimeStamp, 3 );
  998. /* Coordinator address mode */
  999. *tp++ = param->pPanDesc->CoordAddress.addrMode;
  1000. /* Coordinator address */
  1001. MT_MacAddr2Spi( tp, &param->pPanDesc->CoordAddress );
  1002. tp += Z_EXTADDR_LEN;
  1003. /* PAN ID */
  1004. *tp++ = LO_UINT16( param->pPanDesc->CoordPANId );
  1005. *tp++ = HI_UINT16( param->pPanDesc->CoordPANId );
  1006. /* Superframe spec */
  1007. *tp++ = LO_UINT16( param->pPanDesc->SuperframeSpec );
  1008. *tp++ = HI_UINT16( param->pPanDesc->SuperframeSpec );
  1009. /* LogicalChannel */
  1010. *tp++ = param->pPanDesc->LogicalChannel;
  1011. /* GTSPermit */
  1012. *tp++ = param->pPanDesc->GTSPermit;
  1013. /* LinkQuality */
  1014. *tp++ = param->pPanDesc->LinkQuality;
  1015. /* SecurityFailure */
  1016. *tp++ = param->pPanDesc->SecurityFailure;
  1017. /* Security */
  1018. MT_MacSpi2Sec ((ZMacSec_t *)tp, (uint8 *)&param->pPanDesc->Sec);
  1019. tp += ZTEST_DEFAULT_SEC_LEN;
  1020. /* PendingAddrSpec */
  1021. *tp++ = param->PendAddrSpec;
  1022. /* AddrList */
  1023. osal_memset( tp, 0, MT_MAC_PEND_LEN_MAX );
  1024. osal_memcpy( tp, param->AddrList, MIN(MT_MAC_PEND_LEN_MAX, MT_MAC_PEND_LEN(param->PendAddrSpec)) );
  1025. tp += MT_MAC_PEND_LEN_MAX;
  1026. /* SDULength */
  1027. *tp++ = param->sduLength;
  1028. /* SDU */
  1029. osal_memset( tp, 0, MT_MAC_SDU_LEN_MAX );
  1030. osal_memcpy( tp, param->sdu, MIN(MT_MAC_SDU_LEN_MAX, param->sduLength) );
  1031. /* Build and send back the response */
  1032. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_MAC), MT_MAC_BEACON_NOTIFY_IND, respLen, pRetBuf);
  1033. /* Deallocate */
  1034. osal_mem_free(pRetBuf);
  1035. }
  1036. }
  1037. /***************************************************************************************************
  1038. * @fn nwk_MTCallbackSubNwkDataCnf
  1039. *
  1040. * @brief Process the callback subscription for nwk_data_cnf
  1041. *
  1042. * @param pointer of type macnwk_data_cnf_t
  1043. *
  1044. * @return None
  1045. ***************************************************************************************************/
  1046. void nwk_MTCallbackSubNwkDataCnf( ZMacDataCnf_t *param )
  1047. {
  1048. uint8 *pRetBuf, *tp;
  1049. /* Allocate */
  1050. pRetBuf = osal_mem_alloc(MT_MAC_LEN_DATA_CNF);
  1051. if (pRetBuf)
  1052. {
  1053. tp = pRetBuf;
  1054. /* Status */
  1055. *tp++ = param->hdr.Status;
  1056. /* Handle */
  1057. *tp++ = param->msduHandle;
  1058. /* Timestamp */
  1059. *tp++ = BREAK_UINT32( param->Timestamp, 0 );
  1060. *tp++ = BREAK_UINT32( param->Timestamp, 1 );
  1061. *tp++ = BREAK_UINT32( param->Timestamp, 2 );
  1062. *tp++ = BREAK_UINT32( param->Timestamp, 3 );
  1063. /* Timestamp2 */
  1064. *tp++ = LO_UINT16( param->Timestamp2);
  1065. *tp = HI_UINT16( param->Timestamp2);
  1066. /* Build and send back the response */
  1067. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_MAC), MT_MAC_DATA_CNF, MT_MAC_LEN_DATA_CNF, pRetBuf);
  1068. /* Deallocate */
  1069. osal_mem_free(pRetBuf);
  1070. }
  1071. }
  1072. /***************************************************************************************************
  1073. * @fn nwk_MTCallbackSubNwkDataInd
  1074. *
  1075. * @brief Process the callback subscription for nwk_data_ind
  1076. *
  1077. * @param pointer of type macnwk_data_ind_t
  1078. *
  1079. * @return None
  1080. ***************************************************************************************************/
  1081. void nwk_MTCallbackSubNwkDataInd( ZMacDataInd_t *param )
  1082. {
  1083. uint8 respLen, tempLen;
  1084. uint8 *pRetBuf, *tp;
  1085. /* Packet length is 44 + 102 data */
  1086. respLen = MT_MAC_LEN_DATA_IND + ZTEST_DEFAULT_DATA_LEN;
  1087. pRetBuf = osal_mem_alloc (respLen);
  1088. if ( pRetBuf )
  1089. {
  1090. tp = pRetBuf;
  1091. /* Src address mode */
  1092. *tp++ = param->SrcAddr.addrMode;
  1093. if (param->SrcAddr.addrMode != SADDR_MODE_NONE)
  1094. {
  1095. /* Src Address */
  1096. MT_MacAddr2Spi( tp, &param->SrcAddr );
  1097. }
  1098. else
  1099. {
  1100. /* No address */
  1101. for ( uint8 i = 0; i< Z_EXTADDR_LEN; i++ )
  1102. {
  1103. tp[i] = 0x00;
  1104. }
  1105. }
  1106. tp += Z_EXTADDR_LEN;
  1107. /* Dst address mode */
  1108. *tp++ = param->DstAddr.addrMode;
  1109. /* Dst address */
  1110. MT_MacAddr2Spi( tp, &param->DstAddr );
  1111. tp += Z_EXTADDR_LEN;
  1112. /* Timestamp */
  1113. *tp++ = BREAK_UINT32( param->Timestamp, 0 );
  1114. *tp++ = BREAK_UINT32( param->Timestamp, 1 );
  1115. *tp++ = BREAK_UINT32( param->Timestamp, 2 );
  1116. *tp++ = BREAK_UINT32( param->Timestamp, 3 );
  1117. /* Timestamp2 */
  1118. *tp++ = LO_UINT16( param->Timestamp2);
  1119. *tp++ = HI_UINT16( param->Timestamp2);
  1120. /* Src Pan Id */
  1121. *tp++ = LO_UINT16( param->SrcPANId );
  1122. *tp++ = HI_UINT16( param->SrcPANId );
  1123. /* Dst Pan Id */
  1124. *tp++ = LO_UINT16( param->DstPANId );
  1125. *tp++ = HI_UINT16( param->DstPANId );
  1126. /* mpdu Link Quality */
  1127. *tp++ = param->mpduLinkQuality;
  1128. /* LQI */
  1129. *tp++ = param->Correlation;
  1130. /* RSSI */
  1131. *tp++ = param->Rssi;
  1132. /* DSN */
  1133. *tp++ = param->Dsn;
  1134. /* Security */
  1135. MT_MacSpi2Sec ((ZMacSec_t *)tp, (uint8 *)&param->Sec);
  1136. tp += ZTEST_DEFAULT_SEC_LEN;
  1137. /* Determine the length of the actual data */
  1138. if ( param->msduLength < ZTEST_DEFAULT_DATA_LEN )
  1139. tempLen = param->msduLength;
  1140. else
  1141. tempLen = ZTEST_DEFAULT_DATA_LEN;
  1142. /* Length */
  1143. *tp++ = tempLen;
  1144. /* Copy the data according to Len, the rest are zeroed out */
  1145. osal_memset( tp, 0, ZTEST_DEFAULT_DATA_LEN );
  1146. osal_memcpy( tp, param->msdu, tempLen );
  1147. /* Build and send back the response */
  1148. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_MAC), MT_MAC_DATA_IND, respLen, pRetBuf);
  1149. /* Deallocate */
  1150. osal_mem_free(pRetBuf);
  1151. }
  1152. }
  1153. /***************************************************************************************************
  1154. * @fn nwk_MTCallbackSubNwkDisassociateInd
  1155. *
  1156. * @brief Process the callback subscription for nwk_disassociate_ind
  1157. *
  1158. * @param pointer of type macnwk_disassociate_ind_t
  1159. *
  1160. * @return None
  1161. ***************************************************************************************************/
  1162. void nwk_MTCallbackSubNwkDisassociateInd( ZMacDisassociateInd_t *param )
  1163. {
  1164. uint8 respLen;
  1165. uint8 *pRetBuf, *tp;
  1166. respLen = MT_MAC_LEN_DISASSOCIATE_IND;
  1167. pRetBuf = osal_mem_alloc (respLen);
  1168. if ( pRetBuf )
  1169. {
  1170. tp = pRetBuf;
  1171. /* Extended address */
  1172. MT_MacRevExtCpy( pRetBuf, param->DeviceAddress );
  1173. tp += Z_EXTADDR_LEN;
  1174. /* Disassociate Reason */
  1175. *tp++ = param->DisassociateReason;
  1176. /* Security */
  1177. MT_MacSpi2Sec ((ZMacSec_t *)tp, (uint8 *)&param->Sec);
  1178. /* Build and send back the response */
  1179. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_MAC), MT_MAC_DISASSOCIATE_IND, respLen, pRetBuf);
  1180. /* Deallocate */
  1181. osal_mem_free(pRetBuf);
  1182. }
  1183. }
  1184. /***************************************************************************************************
  1185. * @fn nwk_MTCallbackSubNwkDisassociateCnf
  1186. *
  1187. * @brief Process the callback subscription for nwk_disassociate_cnf
  1188. *
  1189. * @param param
  1190. *
  1191. * @return None
  1192. ***************************************************************************************************/
  1193. void nwk_MTCallbackSubNwkDisassociateCnf( ZMacDisassociateCnf_t *param )
  1194. {
  1195. uint8 respLen;
  1196. uint8 *pRetBuf, *tp;
  1197. respLen = MT_MAC_LEN_DISASSOCIATE_CNF;
  1198. pRetBuf = osal_mem_alloc (respLen);
  1199. if ( pRetBuf )
  1200. {
  1201. tp = pRetBuf;
  1202. /* Status */
  1203. *tp++ = param->hdr.Status;
  1204. /* DeviceAddress */
  1205. *tp++ = param->DeviceAddress.addrMode;
  1206. /* Copy Address */
  1207. MT_MacAddr2Spi( tp, &param->DeviceAddress );
  1208. tp += Z_EXTADDR_LEN;
  1209. /* Pan ID */
  1210. *tp++ = LO_UINT16( param->panID );
  1211. *tp = HI_UINT16( param->panID );
  1212. /* Build and send back the response */
  1213. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_MAC), MT_MAC_DISASSOCIATE_CNF, respLen, pRetBuf);
  1214. /* Deallocate */
  1215. osal_mem_free(pRetBuf);
  1216. }
  1217. }
  1218. /***************************************************************************************************
  1219. * @fn nwk_MTCallbackSubNwkOrphanInd
  1220. *
  1221. * @brief Process the callback subscription for nwk_orphan_ind
  1222. *
  1223. * @param pointer of type macnwk_orphan_ind_t
  1224. *
  1225. * @return SUCCESS if message sent succesfully , else N_FAIL
  1226. ***************************************************************************************************/
  1227. void nwk_MTCallbackSubNwkOrphanInd( ZMacOrphanInd_t *param )
  1228. {
  1229. uint8 respLen;
  1230. uint8 *pRetBuf, *tp;
  1231. respLen = MT_MAC_LEN_ORPHAN_IND;
  1232. pRetBuf = osal_mem_alloc (respLen);
  1233. if ( pRetBuf )
  1234. {
  1235. tp = pRetBuf;
  1236. /* Extended address */
  1237. MT_MacRevExtCpy( tp, param->OrphanAddress );
  1238. tp += Z_EXTADDR_LEN;
  1239. /* Security */
  1240. MT_MacSpi2Sec ((ZMacSec_t *)tp, (uint8 *)&param->Sec);
  1241. /* Build and send back the response */
  1242. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_MAC), MT_MAC_ORPHAN_IND, respLen, pRetBuf);
  1243. /* Deallocate */
  1244. osal_mem_free(pRetBuf);
  1245. }
  1246. }
  1247. /***************************************************************************************************
  1248. * @fn nwk_MTCallbackSubNwkPollCnf
  1249. *
  1250. * @brief Process the callback subscription for nwk_poll_cnf
  1251. *
  1252. * @param byte Status
  1253. *
  1254. * @return None
  1255. ***************************************************************************************************/
  1256. void nwk_MTCallbackSubNwkPollCnf( byte Status )
  1257. {
  1258. uint8 retValue;
  1259. /*The only data byte is Status */
  1260. retValue = Status;
  1261. /* Build and send back the response */
  1262. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_MAC), MT_MAC_POLL_CNF, 1, &retValue);
  1263. }
  1264. /***************************************************************************************************
  1265. * @fn nwk_MTCallbackSubNwkScanCnf
  1266. *
  1267. * @brief Process the callback subscription for nwk_scan_cnf
  1268. *
  1269. * @param pointer of type macnwk_scan_cnf_t
  1270. *
  1271. * @return SUCCESS if message sent succesfully , else N_FAIL
  1272. ***************************************************************************************************/
  1273. void nwk_MTCallbackSubNwkScanCnf( ZMacScanCnf_t *param )
  1274. {
  1275. uint8 respLen, resultLen;
  1276. uint8 *pRetBuf, *tp;
  1277. /* Depends on the type of scan, calculate the required length */
  1278. if ( param->ScanType == ZMAC_ED_SCAN )
  1279. resultLen = MT_MAC_ED_SCAN_MAXCHANNELS;
  1280. else if ( param->ScanType == ZMAC_ACTIVE_SCAN )
  1281. resultLen = (param->ResultListSize * sizeof( ZMacPanDesc_t ));
  1282. else if ( param->ScanType == ZMAC_PASSIVE_SCAN )
  1283. resultLen = (param->ResultListSize * sizeof( ZMacPanDesc_t ));
  1284. else if ( param->ScanType == ZMAC_ORPHAN_SCAN )
  1285. resultLen = 0;
  1286. else
  1287. return;
  1288. /* Make sure the result wont be more than the size */
  1289. resultLen = MIN(resultLen, MT_MAC_SCAN_RESULT_LEN_MAX);
  1290. respLen = MT_MAC_LEN_SCAN_CNF + MT_MAC_SCAN_RESULT_LEN_MAX + 1; /* Extra byte for the length of the list */
  1291. /* Allocate */
  1292. pRetBuf = osal_mem_alloc (respLen);
  1293. if ( pRetBuf )
  1294. {
  1295. tp = pRetBuf;
  1296. /* Status */
  1297. *tp++ = param->hdr.Status;
  1298. /* ED max energy parameter no longer used */
  1299. *tp++ = 0;
  1300. /* Scan type */
  1301. *tp++ = param->ScanType;
  1302. /* Channel page */
  1303. *tp++ = param->ChannelPage;
  1304. /* Unscanned channel list */
  1305. *tp++ = BREAK_UINT32( param->UnscannedChannels, 0 );
  1306. *tp++ = BREAK_UINT32( param->UnscannedChannels, 1 );
  1307. *tp++ = BREAK_UINT32( param->UnscannedChannels, 2 );
  1308. *tp++ = BREAK_UINT32( param->UnscannedChannels, 3 );
  1309. /* Result count */
  1310. *tp++ = param->ResultListSize;
  1311. /* MAX length of the result List */
  1312. *tp++ = MT_MAC_SCAN_RESULT_LEN_MAX;
  1313. /* PAN descriptor information */
  1314. osal_memcpy( tp, param->Result.pPanDescriptor, resultLen );
  1315. /* clear extra buffer space at end, if any */
  1316. osal_memset( tp, 0, (MT_MAC_SCAN_RESULT_LEN_MAX - resultLen));
  1317. /* Build and send back the response */
  1318. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_MAC), MT_MAC_SCAN_CNF, respLen, pRetBuf);
  1319. /* Deallocate */
  1320. osal_mem_free(pRetBuf);
  1321. }
  1322. }
  1323. /***************************************************************************************************
  1324. * @fn nwk_MTCallbackSubCommStatusInd
  1325. *
  1326. * @brief Process the callback subscription for comm_status_ind.
  1327. *
  1328. * @param None
  1329. *
  1330. * @return None
  1331. ***************************************************************************************************/
  1332. void nwk_MTCallbackSubCommStatusInd ( ZMacCommStatusInd_t *param )
  1333. {
  1334. uint8 respLen;
  1335. uint8 *pRetBuf, *tp;
  1336. respLen = MT_MAC_LEN_COMM_STATUS_IND;
  1337. pRetBuf = osal_mem_alloc (respLen);
  1338. if ( pRetBuf )
  1339. {
  1340. tp = pRetBuf;
  1341. /* Status */
  1342. *tp++ = param->hdr.Status;
  1343. /* Source address */
  1344. *tp++ = param->SrcAddress.addrMode;
  1345. MT_MacAddr2Spi( tp, &param->SrcAddress );
  1346. tp += Z_EXTADDR_LEN;
  1347. /* Destination address */
  1348. *tp++ = param->DstAddress.addrMode;
  1349. MT_MacAddr2Spi( tp, &param->DstAddress );
  1350. tp += Z_EXTADDR_LEN;
  1351. /* PAN ID */
  1352. *tp++ = LO_UINT16( param->PANId );
  1353. *tp++ = HI_UINT16( param->PANId );
  1354. /* Reason */
  1355. *tp++ = param->Reason;
  1356. /* Security */
  1357. MT_MacSpi2Sec ((ZMacSec_t *)tp, (uint8 *)&param->Sec);
  1358. /* Build and send back the response */
  1359. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_MAC), MT_MAC_COMM_STATUS_IND, respLen, pRetBuf);
  1360. /* Deallocate */
  1361. osal_mem_free(pRetBuf);
  1362. }
  1363. }
  1364. /***************************************************************************************************
  1365. * @fn nwk_MTCallbackSubNwkStartCnf
  1366. *
  1367. * @brief Process the callback subscription for nwk_start_cnf
  1368. *
  1369. * @param byte Status
  1370. *
  1371. * @return None
  1372. ***************************************************************************************************/
  1373. void nwk_MTCallbackSubNwkStartCnf( uint8 Status )
  1374. {
  1375. uint8 retValue;
  1376. retValue = Status;
  1377. /* Build and send back the response */
  1378. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_MAC), MT_MAC_START_CNF, 1, &retValue);
  1379. }
  1380. /***************************************************************************************************
  1381. * @fn nwk_MTCallbackSubNwkRxEnableCnf
  1382. *
  1383. * @brief Process the callback subscription for nwk_Rx_Enable_cnf
  1384. *
  1385. * @param
  1386. *
  1387. * @return SUCCESS if message sent succesfully , else N_FAIL
  1388. ***************************************************************************************************/
  1389. void nwk_MTCallbackSubNwkRxEnableCnf ( byte Status )
  1390. {
  1391. uint8 retValue;
  1392. /* The only data byte is Status */
  1393. retValue = Status;
  1394. /* Build and send back the response */
  1395. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_MAC), MT_MAC_RX_ENABLE_CNF, 1, &retValue);
  1396. }
  1397. /***************************************************************************************************
  1398. * @fn nwk_MTCallbackSubNwkPurgeCnf
  1399. *
  1400. * @brief Process the callback subscription for nwk_purge_cnf
  1401. *
  1402. * @param pointer of type ZMacPurgeCnf_t
  1403. *
  1404. * @return SUCCESS if message sent succesfully , else N_FAIL
  1405. ***************************************************************************************************/
  1406. void nwk_MTCallbackSubNwkPurgeCnf( ZMacPurgeCnf_t *param )
  1407. {
  1408. uint8 respLen;
  1409. uint8 *pRetBuf, *tp;
  1410. respLen = MT_MAC_LEN_PURGE_CNF;
  1411. pRetBuf = osal_mem_alloc (respLen);
  1412. if ( pRetBuf )
  1413. {
  1414. tp = pRetBuf;
  1415. /* Status */
  1416. *tp++ = param->hdr.Status;
  1417. /* Handle */
  1418. *tp = param->msduHandle;
  1419. /* Build and send back the response */
  1420. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_AREQ | (uint8)MT_RPC_SYS_MAC), MT_MAC_PURGE_CNF, respLen, pRetBuf);
  1421. /* Deallocate */
  1422. osal_mem_free(pRetBuf);
  1423. }
  1424. }
  1425. #endif // MT_MAC_CB_FUNC
  1426. /***************************************************************************************************
  1427. * SUPPORT
  1428. ***************************************************************************************************/
  1429. /***************************************************************************************************
  1430. * @fn MT_MacRevExtCpy
  1431. *
  1432. * @brief
  1433. *
  1434. * Reverse-copy an extended address.
  1435. *
  1436. * @param pDst - Pointer to data destination
  1437. * @param pSrc - Pointer to data source
  1438. *
  1439. * @return void
  1440. ***************************************************************************************************/
  1441. static void MT_MacRevExtCpy( uint8 *pDst, uint8 *pSrc )
  1442. {
  1443. int8 i;
  1444. for ( i = Z_EXTADDR_LEN - 1; i >= 0; i-- )
  1445. {
  1446. *pDst++ = pSrc[i];
  1447. }
  1448. }
  1449. /***************************************************************************************************
  1450. * @fn MT_MacSpi2Addr
  1451. *
  1452. * @brief Copy an address from an SPI message to an address struct. The
  1453. * addrMode in pAddr must already be set.
  1454. *
  1455. * @param pDst - Pointer to address struct
  1456. * @param pSrc - Pointer SPI message byte array
  1457. *
  1458. * @return void
  1459. ***************************************************************************************************/
  1460. static void MT_MacSpi2Addr( zAddrType_t *pDst, uint8 *pSrc )
  1461. {
  1462. if ( pDst->addrMode == Addr16Bit )
  1463. {
  1464. pDst->addr.shortAddr = BUILD_UINT16( pSrc[0] , pSrc[1] );
  1465. }
  1466. else if ( pDst->addrMode == Addr64Bit )
  1467. {
  1468. MT_MacRevExtCpy( pDst->addr.extAddr, pSrc );
  1469. }
  1470. }
  1471. /***************************************************************************************************
  1472. * @fn MT_MacSpi2Sec
  1473. *
  1474. * @brief Copy Security information from SPI message to a Sec structure
  1475. *
  1476. * @param pSec - Pointer to security struct
  1477. * @param pSrc - Pointer SPI message byte array
  1478. *
  1479. * @return void
  1480. ***************************************************************************************************/
  1481. static void MT_MacSpi2Sec( ZMacSec_t *pSec, uint8 *pSrc )
  1482. {
  1483. /* Right now, set everything to zero */
  1484. osal_memset (pSec, 0, sizeof (ZMacSec_t));
  1485. }
  1486. /***************************************************************************************************
  1487. * @fn MT_MacAddr2Spi
  1488. *
  1489. * @brief Copy an address from an address struct to an SPI message.
  1490. *
  1491. * @param pDst - Pointer SPI message byte array
  1492. * @param pSrc - Pointer to address struct
  1493. *
  1494. * @return void
  1495. ***************************************************************************************************/
  1496. static void MT_MacAddr2Spi( uint8 *pDst, zAddrType_t *pSrc )
  1497. {
  1498. if ( pSrc->addrMode == Addr16Bit )
  1499. {
  1500. *pDst++ = LO_UINT16( pSrc->addr.shortAddr );
  1501. *pDst++ = HI_UINT16( pSrc->addr.shortAddr );
  1502. *pDst++ = 0; *pDst++ = 0; *pDst++ = 0;
  1503. *pDst++ = 0; *pDst++ = 0; *pDst = 0;
  1504. }
  1505. else if ( pSrc->addrMode == Addr64Bit )
  1506. {
  1507. for ( uint8 i = 0; i< Z_EXTADDR_LEN; i++ )
  1508. {
  1509. *pDst++ = pSrc->addr.extAddr[i];
  1510. }
  1511. }
  1512. else
  1513. {
  1514. for ( uint8 i = 0; i< Z_EXTADDR_LEN; i++ )
  1515. {
  1516. *pDst++ = pSrc->addr.extAddr[i];
  1517. }
  1518. }
  1519. }
  1520. /***************************************************************************************************
  1521. ***************************************************************************************************/
  1522. #endif // MT_MAC_FUNC