MT_APP.c 15 KB

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