MT_APP.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. /***************************************************************************************************
  2. Filename: MT_APP.c
  3. Revised: $Date: 2011-05-27 16:00:27 -0700 (Fri, 27 May 2011) $
  4. Revision: $Revision: 26145 $
  5. Description: MonitorTest processing for APP commands
  6. Copyright 2007-2011 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 "MT.h" /* This is here because all the SPI_CMD_XXX are defined in this header */
  38. #include "MT_APP.h"
  39. #include "MT_AF.h" /* This is here because this MT_APP makes some routine call to AF */
  40. #include "MT_RPC.h"
  41. #if defined( APP_TP )
  42. #include "TestProfile.h"
  43. #endif
  44. #if defined( APP_TP2 )
  45. #include "TestProfile2.h"
  46. #include "nwk_util.h"
  47. #endif
  48. /***************************************************************************************************
  49. * LOCAL FUNCTIONS
  50. ***************************************************************************************************/
  51. #if defined (MT_APP_FUNC)
  52. void MT_AppMsg(uint8 *pBuf);
  53. void MT_AppUserCmd(byte *pData);
  54. #endif
  55. #if defined (MT_APP_FUNC)
  56. /***************************************************************************************************
  57. * @fn MT_AppCommandProcessing
  58. *
  59. * @brief Process all the APP commands that are issued by test tool
  60. *
  61. * @param pBuf - pointer to the received buffer
  62. *
  63. * @return status
  64. ***************************************************************************************************/
  65. uint8 MT_AppCommandProcessing(uint8 *pBuf)
  66. {
  67. uint8 status = MT_RPC_SUCCESS;
  68. switch (pBuf[MT_RPC_POS_CMD1])
  69. {
  70. case MT_APP_MSG:
  71. MT_AppMsg(pBuf);
  72. break;
  73. case MT_APP_USER_TEST:
  74. MT_AppUserCmd(pBuf);
  75. break;
  76. default:
  77. status = MT_RPC_ERR_COMMAND_ID;
  78. break;
  79. }
  80. return status;
  81. }
  82. /***************************************************************************************************
  83. * @fn MT_AppMsg
  84. *
  85. * @brief Process APP_MSG command
  86. *
  87. * @param pBuf - pointer to the received buffer
  88. *
  89. * @return void
  90. ***************************************************************************************************/
  91. void MT_AppMsg(uint8 *pBuf)
  92. {
  93. uint8 retValue = ZFailure;
  94. uint8 endpoint;
  95. endPointDesc_t *epDesc;
  96. mtSysAppMsg_t *msg;
  97. uint8 cmdId, dataLen;
  98. /* parse header */
  99. dataLen = pBuf[MT_RPC_POS_LEN];
  100. cmdId = pBuf[MT_RPC_POS_CMD1];
  101. pBuf += MT_RPC_FRAME_HDR_SZ;
  102. /* Get the endpoint and skip past it.*/
  103. endpoint = *pBuf++;
  104. dataLen--;
  105. /* Look up the endpoint */
  106. epDesc = afFindEndPointDesc( endpoint );
  107. if (epDesc)
  108. {
  109. /* Build and send the message to the APP */
  110. msg = (mtSysAppMsg_t *)osal_msg_allocate(sizeof(mtSysAppMsg_t) + (dataLen));
  111. if ( msg )
  112. {
  113. /* Build and send message up the app */
  114. msg->hdr.event = MT_SYS_APP_MSG;
  115. msg->endpoint = endpoint;
  116. msg->appDataLen = dataLen;
  117. msg->appData = (uint8*)(msg+1);
  118. osal_memcpy( msg->appData, pBuf, dataLen);
  119. osal_msg_send( *(epDesc->task_id), (uint8 *)msg );
  120. /* Info for response */
  121. retValue = ZSuccess;
  122. }
  123. }
  124. /* Build and send back the response */
  125. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_APP), cmdId, 1, &retValue);
  126. }
  127. /***************************************************************************************************
  128. * @fn MT_AppMsg
  129. *
  130. * @brief Process APP_MSG command
  131. *
  132. * @param pBuf - pointer to the received buffer
  133. *
  134. * @return void
  135. ***************************************************************************************************/
  136. void MT_AppUserCmd(uint8 *pBuf)
  137. {
  138. uint8 retValue, cmdId;
  139. #if defined (APP_TGEN) || defined (NWK_TEST) || defined (APP_TP) || defined (APP_TP2) || defined (OSAL_TOTAL_MEM) || defined (APP_DEBUG)
  140. uint16 app_cmd;
  141. uint8 srcEp;
  142. uint16 param1;
  143. uint16 param2;
  144. #endif
  145. #if defined (OSAL_TOTAL_MEM)
  146. uint8 pData[2];
  147. #endif
  148. /* parse header */
  149. cmdId = pBuf[MT_RPC_POS_CMD1];
  150. pBuf += MT_RPC_FRAME_HDR_SZ;
  151. retValue = INVALID_TASK; //should be changed later
  152. #if defined (APP_TGEN) || defined (NWK_TEST) || defined (APP_TP) || defined (APP_TP2) || defined (OSAL_TOTAL_MEM) || defined (APP_DEBUG)
  153. srcEp = *pBuf++;
  154. app_cmd = BUILD_UINT16( pBuf[0] , pBuf[1] );
  155. pBuf = pBuf + sizeof( uint16 );
  156. param1 = BUILD_UINT16( pBuf[0] , pBuf[1] );
  157. pBuf = pBuf + sizeof( uint16 );
  158. param2 = BUILD_UINT16( pBuf[0] , pBuf[1] );
  159. switch ( app_cmd )
  160. {
  161. #if defined (APP_TGEN)
  162. case TGEN_START:
  163. TrafficGenApp_SendCmdMSG( param1, param2, TRAFFICGENAPP_CMD_START );
  164. retValue = ZSUCCESS;
  165. break;
  166. case TGEN_STOP:
  167. TrafficGenApp_SendCmdMSG( param1, param2, TRAFFICGENAPP_CMD_STOP );
  168. retValue = ZSUCCESS;
  169. break;
  170. case TGEN_COUNT:
  171. retValue = TrafficGenApp_CountPkt( param1, param2 );
  172. return;
  173. break;
  174. #endif
  175. #if defined (NWK_TEST)
  176. case HW_TEST:
  177. HwApp_Start( HI_UINT16(param1), LO_UINT16(param1), HI_UINT16(param2),
  178. 1000, LO_UINT16(param2), 3, 0 );
  179. break;
  180. case HW_DISPLAY_RESULT:
  181. HwApp_TestInfo();
  182. break;
  183. case HW_SEND_STATUS:
  184. HwApp_SendStats();
  185. break;
  186. #endif
  187. #if defined( APP_TP ) || defined ( APP_TP2 )
  188. #if defined( APP_TP )
  189. case TP_SEND_NODATA:
  190. retValue = TestProfileApp_SendNoData( srcEp, (byte)param1 );
  191. break;
  192. #endif // APP_TP
  193. case TP_SEND_BUFFERTEST:
  194. retValue = TestProfileApp_SendBufferReq( srcEp, (byte)param1 );
  195. break;
  196. #if defined( APP_TP )
  197. case TP_SEND_UINT8:
  198. retValue = TestProfileApp_SendUint8( srcEp, (byte)param1 );
  199. break;
  200. case TP_SEND_INT8:
  201. retValue = TestProfileApp_SendInt8( srcEp, (byte)param1 );
  202. break;
  203. case TP_SEND_UINT16:
  204. retValue = TestProfileApp_SendUint16( srcEp, (byte)param1 );
  205. break;
  206. case TP_SEND_INT16:
  207. retValue = TestProfileApp_SendInt16( srcEp, (byte)param1 );
  208. break;
  209. case TP_SEND_SEMIPREC:
  210. retValue = TestProfileApp_SendSemiPrec( srcEp, (byte)param1 );
  211. break;
  212. case TP_SEND_FREEFORM:
  213. retValue = TestProfileApp_SendFreeFormReq( srcEp, (byte)param1 );
  214. break;
  215. #else // APP_TP
  216. case TP_SEND_FREEFORM:
  217. retValue = TestProfileApp_SendFreeFormReq(srcEp, (byte)param1, (byte)param2);
  218. break;
  219. #endif
  220. #if defined( APP_TP )
  221. case TP_SEND_ABS_TIME:
  222. retValue = TestProfileApp_SendAbsTime( srcEp, (byte)param1 );
  223. break;
  224. case TP_SEND_REL_TIME:
  225. retValue = TestProfileApp_SendRelativeTime( srcEp, (byte)param1 );
  226. break;
  227. case TP_SEND_CHAR_STRING:
  228. retValue = TestProfileApp_SendCharString( srcEp, (byte)param1 );
  229. break;
  230. case TP_SEND_OCTET_STRING:
  231. retValue = TestProfileApp_SendOctetString( srcEp, (byte)param1 );
  232. break;
  233. #endif // APP_TP
  234. case TP_SET_DSTADDRESS:
  235. retValue = TestProfileApp_SetDestAddress(HI_UINT16(param1), LO_UINT16(param1), param2);
  236. break;
  237. #if defined( APP_TP2 )
  238. case TP_SEND_BUFFER_GROUP:
  239. retValue = TestProfileApp_SendBufferGroup( srcEp, (byte)param1 );
  240. break;
  241. #endif // APP_TP
  242. case TP_SEND_BUFFER:
  243. retValue = TestProfileApp_SendBuffer( srcEp, (byte)param1 );
  244. break;
  245. #if defined( APP_TP )
  246. case TP_SEND_MULT_KVP_8BIT:
  247. TestProfileApp_SendMultiKVP_8bit( srcEp, (byte)param1 );
  248. retValue = ZSuccess;
  249. break;
  250. case TP_SEND_MULT_KVP_16BIT:
  251. TestProfileApp_SendMultiKVP_16bit( srcEp, (byte)param1 );
  252. retValue = ZSuccess;
  253. break;
  254. case TP_SEND_MULT_KVP_TIME:
  255. TestProfileApp_SendMultiKVP_Time( srcEp, (byte)param1 );
  256. retValue = ZSuccess;
  257. break;
  258. case TP_SEND_MULT_KVP_STRING:
  259. TestProfileApp_SendMultiKVP_String( srcEp, (byte)param1 );
  260. retValue = ZSuccess;
  261. break;
  262. case TP_SEND_MULTI_KVP_STR_TIME:
  263. retValue = ZSuccess;
  264. TestProfileApp_SendMultiKVP_String_Time( srcEp, (byte)param1 );
  265. break;
  266. #endif // APP_TP
  267. case TP_SEND_COUNTED_PKTS:
  268. TestProfileApp_SendCountedPktsReq(HI_UINT16(param1), LO_UINT16(param1), param2);
  269. retValue = ZSuccess;
  270. break;
  271. case TP_SEND_RESET_COUNTER:
  272. TestProfileApp_CountedPakts_ResetCounterReq( (byte)param1 );
  273. retValue = ZSuccess;
  274. break;
  275. case TP_SEND_GET_COUNTER:
  276. TestProfileApp_CountedPakts_GetCounterReq( srcEp, (byte)param1 );
  277. retValue = ZSuccess;
  278. break;
  279. case TP_SET_PERMIT_JOIN:
  280. if ( ZG_BUILD_RTR_TYPE && ZG_DEVICE_RTR_TYPE )
  281. {
  282. NLME_PermitJoiningRequest( (byte)param1 );
  283. retValue = ZSuccess;
  284. }
  285. else
  286. {
  287. retValue = ZFailure;
  288. }
  289. break;
  290. #if defined ( APP_TP2 )
  291. case TP_ADD_GROUP:
  292. retValue = TestProfileApp_SetGroup( srcEp, param1 );
  293. break;
  294. case TP_REMOVE_GROUP:
  295. retValue = TestProfileApp_RemoveGroup( srcEp, param1 );
  296. break;
  297. case TP_SEND_UPDATE_KEY:
  298. retValue = TestProfileApp_UpdateKey( srcEp, (uint8)param1, param2 );
  299. break;
  300. case TP_SEND_SWITCH_KEY:
  301. retValue = TestProfileApp_SwitchKey( srcEp, (uint8)param1, param2 );
  302. break;
  303. case TP_SEND_BUFFERTEST_GROUP:
  304. retValue = TestProfileApp_SendBufferGroupReq( srcEp, (byte)param1, (byte)param2 );
  305. break;
  306. case TP_SEND_ROUTE_DISC_REQ:
  307. retValue = TestProfileApp_SendRouteDiscReq( srcEp, param1,
  308. HI_UINT16( param2 ), LO_UINT16( param2 ) );
  309. break;
  310. case TP_SEND_ROUTE_DISCOVERY:
  311. if ( ZG_BUILD_RTR_TYPE && ZG_DEVICE_RTR_TYPE )
  312. {
  313. retValue = TestProfileApp_SendRouteDiscovery( param1,
  314. HI_UINT16( param2 ), LO_UINT16( param2 ) );
  315. }
  316. break;
  317. case TP_SEND_NEW_ADDR:
  318. retValue = TestProfileApp_ChangeShortAddr( param1, LO_UINT16(param2) );
  319. break;
  320. case TP_SEND_NWK_UPDATE:
  321. /* Send out a Network Update command. */
  322. retValue = NLME_SendNetworkUpdate( NWK_BROADCAST_SHORTADDR, NWKUPDATE_PANID_UPDATE,
  323. _NIB.extendedPANID, _NIB.nwkUpdateId+1, param1 );
  324. break;
  325. case TP_NWK_ADDR_CONFLICT:
  326. retValue = NLME_SendNetworkStatus( NWK_BROADCAST_SHORTADDR_DEVZCZR, param1,
  327. NWKSTAT_ADDRESS_CONFLICT, FALSE );
  328. break;
  329. #if (ZG_BUILD_JOINING_TYPE)
  330. case TP_AK_SETUP_PARTNER:
  331. retValue = TestProfileApp_AppKeySetupPartner( srcEp, param1, param2 );
  332. break;
  333. case TP_AK_REQ_KEY:
  334. retValue = TestProfileApp_AppKeyRequest( srcEp, param1, param2 );
  335. break;
  336. case TP_AK_PARTNER_NWKADDR:
  337. retValue = TestProfileApp_SetPartnerNwkAddr( srcEp, param1, param2 );
  338. break;
  339. case TP_AK_PARTNER_EXTADDR7654:
  340. retValue = TestProfileApp_SetPartnerExtAddr7654( srcEp, param1, param2 );
  341. break;
  342. case TP_AK_PARTNER_EXTADDR3210:
  343. retValue = TestProfileApp_SetPartnerExtAddr3210( srcEp, param1, param2 );
  344. break;
  345. case TP_AK_PARTNER_SET:
  346. retValue = TestProfileApp_SetPartner( srcEp, param1, param2 );
  347. break;
  348. #endif /* ZG_BUILD_JOINING_TYPE */
  349. #if (ZG_BUILD_COORDINATOR_TYPE)
  350. case TP_AK_TYPE_SET:
  351. retValue = TestProfileApp_AppKeyTypeSet( srcEp, param1, param2 );
  352. break;
  353. #endif /* ZG_BUILD_COORDINATOR_TYPE */
  354. #if defined ( ZIGBEE_FRAGMENTATION )
  355. case TP_FRAG_SKIP_BLOCK:
  356. retValue = TestProfileApp_FragSkipBlock( (uint8)param1 );
  357. break;
  358. #endif
  359. case TP_APS_REMOVE:
  360. retValue = TestProfileApp_APSRemove( param1, param2 );
  361. break;
  362. #endif // APP_TP2
  363. #endif // APP_TP || APP_TP2
  364. #if defined ( OSAL_TOTAL_MEM )
  365. case OSAL_MEM_STACK_HIGH_WATER:
  366. case OSAL_MEM_HEAP_HIGH_WATER:
  367. if ( app_cmd == OSAL_MEM_STACK_HIGH_WATER)
  368. {
  369. param1 = osal_stack_used();
  370. }
  371. else
  372. {
  373. param1 = osal_heap_high_water();
  374. }
  375. pData[0] = LO_UINT16( param1 );
  376. pData[1] = HI_UINT16( param1 );
  377. MT_BuildAndSendZToolResponse((MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_APP), cmdId, 2, pData);
  378. return;
  379. #endif
  380. #if defined ( APP_DEBUG )
  381. case DEBUG_GET:
  382. DebugApp_SendQuery( param1 );
  383. retValue = ZSUCCESS;
  384. break;
  385. #endif
  386. #if defined ( APP_TP2 )
  387. case TP_SEND_BCAST_RSP:
  388. retValue = TestProfileApp_SendBcastRsp( srcEp, (byte)param1 );
  389. break;
  390. #endif
  391. default:
  392. break;
  393. }
  394. #endif // (APP_TGEN) || (NWK_TEST) || (APP_TP) || (APP_TP2) || (OSAL_TOTAL_MEM) || (APP_DEBUG)
  395. /* Build and send back the response */
  396. MT_BuildAndSendZToolResponse(((uint8)MT_RPC_CMD_SRSP | (uint8)MT_RPC_SYS_APP), cmdId, 1, &retValue);
  397. }
  398. #endif /* MT_APP_FUNC */
  399. /***************************************************************************************************
  400. ***************************************************************************************************/