zcl_pi.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /**************************************************************************************************
  2. Filename: zcl_pi.c
  3. Revised: $Date: 2010-09-28 08:39:46 -0700 (Tue, 28 Sep 2010) $
  4. Revision: $Revision: 23926 $
  5. Description: Zigbee Cluster Library - Protocol Interfaces (PI)
  6. Copyright 2010 Texas Instruments Incorporated. All rights reserved.
  7. IMPORTANT: Your use of this Software is limited to those specific rights
  8. granted under the terms of a software license agreement between the user
  9. who downloaded the software, his/her employer (which must be your employer)
  10. and Texas Instruments Incorporated (the "License"). You may not use this
  11. Software unless you agree to abide by the terms of the License. The License
  12. limits your use, and you acknowledge, that the Software may not be modified,
  13. copied or distributed unless embedded on a Texas Instruments microcontroller
  14. or used solely and exclusively in conjunction with a Texas Instruments radio
  15. frequency transceiver, which is integrated into your product. Other than for
  16. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  17. works of, modify, distribute, perform, display or sell this Software and/or
  18. its documentation for any purpose.
  19. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  20. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  21. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  22. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  23. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  24. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  25. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  26. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  27. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  28. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  29. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  30. Should you have any questions regarding your right to use this Software,
  31. contact Texas Instruments Incorporated at www.TI.com.
  32. **************************************************************************************************/
  33. /*********************************************************************
  34. * INCLUDES
  35. */
  36. #include "ZComDef.h"
  37. #include "OSAL.h"
  38. #include "zcl.h"
  39. #include "zcl_general.h"
  40. #include "zcl_pi.h"
  41. #if defined ( INTER_PAN )
  42. #include "stub_aps.h"
  43. #endif
  44. /*********************************************************************
  45. * MACROS
  46. */
  47. /*********************************************************************
  48. * CONSTANTS
  49. */
  50. /*********************************************************************
  51. * TYPEDEFS
  52. */
  53. typedef struct zclPICBRec
  54. {
  55. struct zclPICBRec *next;
  56. uint8 endpoint; // Used to link it into the endpoint descriptor
  57. zclPI_AppCallbacks_t *CBs; // Pointer to Callback function
  58. } zclPICBRec_t;
  59. /*********************************************************************
  60. * GLOBAL VARIABLES
  61. */
  62. /*********************************************************************
  63. * GLOBAL FUNCTIONS
  64. */
  65. /*********************************************************************
  66. * LOCAL VARIABLES
  67. */
  68. static zclPICBRec_t *zclPICBs = (zclPICBRec_t *)NULL;
  69. static uint8 zclPIPluginRegisted = FALSE;
  70. /*********************************************************************
  71. * LOCAL FUNCTIONS
  72. */
  73. static ZStatus_t zclPI_HdlIncoming( zclIncoming_t *pInHdlrMsg );
  74. static ZStatus_t zclPI_HdlInSpecificCommands( zclIncoming_t *pInMsg );
  75. static zclPI_AppCallbacks_t *zclPI_FindCallbacks( uint8 endpoint );
  76. static ZStatus_t zclPI_ProcessIn_GenericTunneServer( zclIncoming_t *pInMsg,
  77. zclPI_AppCallbacks_t *pCBs );
  78. static ZStatus_t zclPI_ProcessIn_GenericTunneClient( zclIncoming_t *pInMsg,
  79. zclPI_AppCallbacks_t *pCBs );
  80. static ZStatus_t zclPI_ProcessIn_BACnetTunnelCmds( zclIncoming_t *pInMsg,
  81. zclPI_AppCallbacks_t *pCBs );
  82. static ZStatus_t zclPI_ProcessIn_11073TunnelCmds( zclIncoming_t *pInMsg,
  83. zclPI_AppCallbacks_t *pCBs );
  84. /*********************************************************************
  85. * @fn zclPI_RegisterCmdCallbacks
  86. *
  87. * @brief Register an applications command callbacks
  88. *
  89. * @param endpoint - application's endpoint
  90. * @param callbacks - pointer to the callback record.
  91. *
  92. * @return ZMemError if not able to allocate
  93. */
  94. ZStatus_t zclPI_RegisterCmdCallbacks( uint8 endpoint, zclPI_AppCallbacks_t *callbacks )
  95. {
  96. zclPICBRec_t *pNewItem;
  97. zclPICBRec_t *pLoop;
  98. // Register as a ZCL Plugin
  99. if ( !zclPIPluginRegisted )
  100. {
  101. zcl_registerPlugin( ZCL_CLUSTER_ID_PI_GENERIC_TUNNEL,
  102. ZCL_CLUSTER_ID_PI_11073_PROTOCOL_TUNNEL,
  103. zclPI_HdlIncoming );
  104. zclPIPluginRegisted = TRUE;
  105. }
  106. // Fill in the new profile list
  107. pNewItem = osal_mem_alloc( sizeof( zclPICBRec_t ) );
  108. if ( pNewItem == NULL )
  109. return (ZMemError);
  110. pNewItem->next = (zclPICBRec_t *)NULL;
  111. pNewItem->endpoint = endpoint;
  112. pNewItem->CBs = callbacks;
  113. // Find spot in list
  114. if ( zclPICBs == NULL )
  115. {
  116. zclPICBs = pNewItem;
  117. }
  118. else
  119. {
  120. // Look for end of list
  121. pLoop = zclPICBs;
  122. while ( pLoop->next != NULL )
  123. pLoop = pLoop->next;
  124. // Put new item at end of list
  125. pLoop->next = pNewItem;
  126. }
  127. return ( ZSuccess );
  128. }
  129. /*******************************************************************************
  130. * @fn zclPI_Send_MatchProtocolAddrCmd
  131. *
  132. * @brief Call to send out a Match Protocol Address Command. This command is
  133. * used when an associated protocol specific tunnel wishes to find out
  134. * the ZigBee address of the Generic Tunnel server cluster representing
  135. * a protocol-specific device with a given protocol address. The
  136. * command is typically multicast to a group of inter-communicating
  137. * Generic Tunnel clusters.
  138. *
  139. * @param srcEP - Sending application's endpoint
  140. * @param dstAddr - where you want the message to go
  141. * @param len - length of protocol address
  142. * @param protocolAddr - protocol address
  143. * @param disableDefaultRsp - whether to disable the Default Response command
  144. * @param seqNum - sequence number
  145. *
  146. * @return ZStatus_t
  147. */
  148. ZStatus_t zclPI_Send_MatchProtocolAddrCmd( uint8 srcEP, afAddrType_t *dstAddr,
  149. uint8 len, uint8 *protocolAddr,
  150. uint8 disableDefaultRsp, uint8 seqNum )
  151. {
  152. uint8 *buf;
  153. ZStatus_t stat;
  154. buf = osal_mem_alloc( len+1 ); // 1 for length field
  155. if ( buf )
  156. {
  157. buf[0] = len;
  158. osal_memcpy( &(buf[1]), protocolAddr, len );
  159. stat = zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_PI_GENERIC_TUNNEL,
  160. COMMAND_PI_GENERIC_TUNNEL_MATCH_PROTOCOL_ADDR, TRUE,
  161. ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0, seqNum,
  162. (len+1), buf );
  163. osal_mem_free( buf );
  164. }
  165. else
  166. {
  167. stat = ZMemError;
  168. }
  169. return ( stat );
  170. }
  171. /*******************************************************************************
  172. * @fn zclPI_Send_MatchProtocolAddrRsp
  173. *
  174. * @brief Call to send out a Match Protocol Address Response. This response
  175. * is sent back upon receipt of a Match Protocol Address command to
  176. * indicate that the Protocol Address was successfully matched.
  177. *
  178. * @param srcEP - Sending application's endpoint
  179. * @param dstAddr - where you want the message to go
  180. * @param ieeeAddr - device address
  181. * @param len - length of protocol address
  182. * @param protocolAddr - protocol address
  183. * @param disableDefaultRsp - whether to disable the Default Response command
  184. * @param seqNum - sequence number
  185. *
  186. * @return ZStatus_t
  187. */
  188. ZStatus_t zclPI_Send_MatchProtocolAddrRsp( uint8 srcEP, afAddrType_t *dstAddr,
  189. uint8 *ieeeAddr, uint8 len, uint8 *protocolAddr,
  190. uint8 disableDefaultRsp, uint8 seqNum )
  191. {
  192. uint8 *buf;
  193. uint8 msgLen = Z_EXTADDR_LEN + 1 + len; // IEEE Address + 1 for length field
  194. ZStatus_t stat;
  195. buf = osal_mem_alloc( msgLen ); // 1 for length field
  196. if ( buf )
  197. {
  198. // Copy over IEEE Address
  199. osal_cpyExtAddr( buf, ieeeAddr );
  200. // Copy over Protocol Address
  201. buf[8] = len;
  202. osal_memcpy( &(buf[9]), protocolAddr, len );
  203. stat = zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_PI_GENERIC_TUNNEL,
  204. COMMAND_PI_GENERIC_TUNNEL_MATCH_PROTOCOL_ADDR_RSP, TRUE,
  205. ZCL_FRAME_SERVER_CLIENT_DIR, disableDefaultRsp, 0, seqNum,
  206. msgLen, buf );
  207. osal_mem_free( buf );
  208. }
  209. else
  210. {
  211. stat = ZMemError;
  212. }
  213. return ( stat );
  214. }
  215. /*******************************************************************************
  216. * @fn zclPI_Send_AdvertiseProtocolAddrCmd
  217. *
  218. * @brief Call to send out an Advertise Protocol Address Command. This command
  219. * is sent out typically upon startup or whenever the Protocol Address
  220. * attribute changes. It is typically multicast to a group of inter-
  221. * communicating Generic Tunnel clusters.
  222. *
  223. * @param srcEP - Sending application's endpoint
  224. * @param dstAddr - where you want the message to go
  225. * @param len - length of protocol address
  226. * @param protocolAddr - protocol address
  227. * @param disableDefaultRsp - whether to disable the Default Response command
  228. * @param seqNum - sequence number
  229. *
  230. * @return ZStatus_t
  231. */
  232. ZStatus_t zclPI_Send_AdvertiseProtocolAddrCmd( uint8 srcEP, afAddrType_t *dstAddr,
  233. uint8 len, uint8 *protocolAddr,
  234. uint8 disableDefaultRsp, uint8 seqNum )
  235. {
  236. uint8 *buf;
  237. ZStatus_t stat;
  238. buf = osal_mem_alloc( len+1 ); // 1 for length field
  239. if ( buf )
  240. {
  241. buf[0] = len;
  242. osal_memcpy( &(buf[1]), protocolAddr, len );
  243. stat = zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_PI_GENERIC_TUNNEL,
  244. COMMAND_PI_GENERIC_TUNNEL_ADVERTISE_PROTOCOL_ADDR, TRUE,
  245. ZCL_FRAME_SERVER_CLIENT_DIR, disableDefaultRsp, 0, seqNum,
  246. (len+1), buf );
  247. osal_mem_free( buf );
  248. }
  249. else
  250. {
  251. stat = ZMemError;
  252. }
  253. return ( stat );
  254. }
  255. /*******************************************************************************
  256. * @fn zclPI_Send_11073TransferAPDUCmd
  257. *
  258. * @brief Call to send out an 11073 Transfer APDU Command. This command is
  259. * used when an 11073 network layer wishes to transfer an 11073 APDU
  260. * across a ZigBee tunnel to another 11073 network layer.
  261. *
  262. * The most stringent reliability characteristic of a given transport
  263. * technology is “Best” reliability. Note - For ZigBee, this corresponds
  264. * to use of APS-ACKs.
  265. *
  266. * The least stringent reliability characteristic of a given transport
  267. * technology is “Good” reliability. Note - For ZigBee, this corresponds
  268. * to no use of APS-ACKs.
  269. *
  270. * Note: This command shall always be transmitted with the Disable Default
  271. * Response bit in the ZCL frame control field set to 1.
  272. *
  273. * @param srcEP - Sending application's endpoint
  274. * @param dstAddr - where you want the message to go
  275. * @param len - length of APDU
  276. * @param apdu - APDU to be sent
  277. * @param seqNum - sequence number
  278. *
  279. * @return ZStatus_t
  280. */
  281. ZStatus_t zclPI_Send_11073TransferAPDUCmd( uint8 srcEP, afAddrType_t *dstAddr,
  282. uint16 len, uint8 *apdu, uint8 seqNum )
  283. {
  284. uint8 *buf;
  285. ZStatus_t stat;
  286. buf = osal_mem_alloc( len+2 ); // 2 for length field (long octet string)
  287. if ( buf )
  288. {
  289. buf[0] = LO_UINT16( len );
  290. buf[1] = HI_UINT16( len );
  291. osal_memcpy( &(buf[2]), apdu, len );
  292. // This command shall always be transmitted with the Disable Default
  293. // Response bit in the ZCL frame control field set to 1.
  294. stat = zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_PI_11073_PROTOCOL_TUNNEL,
  295. COMMAND_PI_11073_TUNNEL_TRANSFER_APDU, TRUE,
  296. ZCL_FRAME_CLIENT_SERVER_DIR, TRUE, 0, seqNum, (len+2), buf );
  297. osal_mem_free( buf );
  298. }
  299. else
  300. {
  301. stat = ZMemError;
  302. }
  303. return ( stat );
  304. }
  305. /*******************************************************************************
  306. * @fn zclPI_Send_11073ConnectReq
  307. *
  308. * @brief Call to send out an 11073 Connect Request Command. This command
  309. * is generated when a Data Management device wishes to connect to
  310. * an 11073 agent device. This may be in response to receiving a
  311. * connect status notification command from that agent device with
  312. * the connect status field set to RECONNECT_REQUEST.
  313. *
  314. * @param srcEP - Sending application's endpoint
  315. * @param dstAddr - where you want the message to go
  316. * @param connectCtrl - connect control
  317. * @param idleTimeout - inactivity time (in minutes) which Data Management device
  318. * will wait w/o receiving any data before it disconnects
  319. * @param managerAddr - IEEE address (64-bit) of Data Management device
  320. * transmitting this frame
  321. * @param managerEP - source endpoint from which Data Management device is
  322. transmitting this frame
  323. * @param disableDefaultRsp - whether to disable the Default Response command
  324. * @param seqNum - sequence number
  325. *
  326. * @return ZStatus_t
  327. */
  328. ZStatus_t zclPI_Send_11073ConnectReq( uint8 srcEP, afAddrType_t *dstAddr,
  329. uint8 connectCtrl, uint16 idleTimeout,
  330. uint8 *managerAddr, uint8 managerEP,
  331. uint8 disableDefaultRsp, uint8 seqNum )
  332. {
  333. uint8 *buf;
  334. uint8 msgLen = 1 + 2 + Z_EXTADDR_LEN + 1; // connect ctrl + idle timeout + IEEE Address + manager EP
  335. ZStatus_t stat;
  336. buf = osal_mem_alloc( msgLen );
  337. if ( buf )
  338. {
  339. buf[0] = connectCtrl;
  340. buf[1] = LO_UINT16( idleTimeout );
  341. buf[2] = HI_UINT16( idleTimeout );
  342. osal_memcpy( &(buf[3]), managerAddr, Z_EXTADDR_LEN );
  343. buf[11] = managerEP;
  344. stat = zcl_SendCommand( srcEP, dstAddr, ZCL_CLUSTER_ID_PI_11073_PROTOCOL_TUNNEL,
  345. COMMAND_PI_11073_TUNNEL_CONNECT_REQ, TRUE,
  346. ZCL_FRAME_CLIENT_SERVER_DIR, disableDefaultRsp, 0, seqNum,
  347. msgLen, buf );
  348. osal_mem_free( buf );
  349. }
  350. else
  351. {
  352. stat = ZMemError;
  353. }
  354. return ( stat );
  355. }
  356. /*********************************************************************
  357. * @fn zclPI_FindCallbacks
  358. *
  359. * @brief Find the callbacks for an endpoint
  360. *
  361. * @param endpoint
  362. *
  363. * @return pointer to the callbacks
  364. */
  365. static zclPI_AppCallbacks_t *zclPI_FindCallbacks( uint8 endpoint )
  366. {
  367. zclPICBRec_t *pCBs;
  368. pCBs = zclPICBs;
  369. while ( pCBs )
  370. {
  371. if ( pCBs->endpoint == endpoint )
  372. return ( pCBs->CBs );
  373. }
  374. return ( (zclPI_AppCallbacks_t *)NULL );
  375. }
  376. /*********************************************************************
  377. * @fn zclPI_HdlIncoming
  378. *
  379. * @brief Callback from ZCL to process incoming Commands specific
  380. * to this cluster library or Profile commands for attributes
  381. * that aren't in the attribute list
  382. *
  383. * @param pInMsg - pointer to the incoming message
  384. * @param logicalClusterID
  385. *
  386. * @return ZStatus_t
  387. */
  388. static ZStatus_t zclPI_HdlIncoming( zclIncoming_t *pInMsg )
  389. {
  390. ZStatus_t stat = ZSuccess;
  391. #if defined ( INTER_PAN )
  392. if ( StubAPS_InterPan( pInMsg->msg->srcAddr.panId, pInMsg->msg->srcAddr.endPoint ) )
  393. return ( stat ); // Cluster not supported thru Inter-PAN
  394. #endif
  395. if ( zcl_ClusterCmd( pInMsg->hdr.fc.type ) )
  396. {
  397. // Is this a manufacturer specific command?
  398. if ( pInMsg->hdr.fc.manuSpecific == 0 )
  399. {
  400. stat = zclPI_HdlInSpecificCommands( pInMsg );
  401. }
  402. else
  403. {
  404. // We don't support any manufacturer specific command -- ignore it.
  405. stat = ZFailure;
  406. }
  407. }
  408. else
  409. {
  410. // Handle all the normal (Read, Write...) commands
  411. stat = ZFailure;
  412. }
  413. return ( stat );
  414. }
  415. /*********************************************************************
  416. * @fn zclPI_HdlInSpecificCommands
  417. *
  418. * @brief Callback from ZCL to process incoming Commands specific
  419. * to this cluster library
  420. *
  421. * @param pInMsg - pointer to the incoming message
  422. *
  423. * @return ZStatus_t
  424. */
  425. static ZStatus_t zclPI_HdlInSpecificCommands( zclIncoming_t *pInMsg )
  426. {
  427. ZStatus_t stat;
  428. zclPI_AppCallbacks_t *pCBs;
  429. // make sure endpoint exists
  430. pCBs = zclPI_FindCallbacks( pInMsg->msg->endPoint );
  431. if ( pCBs == NULL )
  432. return ( ZFailure );
  433. switch ( pInMsg->msg->clusterId )
  434. {
  435. case ZCL_CLUSTER_ID_PI_GENERIC_TUNNEL:
  436. if ( zcl_ServerCmd( pInMsg->hdr.fc.direction ) )
  437. stat = zclPI_ProcessIn_GenericTunneServer( pInMsg, pCBs );
  438. else
  439. stat = zclPI_ProcessIn_GenericTunneClient( pInMsg, pCBs );
  440. break;
  441. case ZCL_CLUSTER_ID_PI_BACNET_PROTOCOL_TUNNEL:
  442. stat = zclPI_ProcessIn_BACnetTunnelCmds( pInMsg, pCBs );
  443. break;
  444. case ZCL_CLUSTER_ID_PI_11073_PROTOCOL_TUNNEL:
  445. stat = zclPI_ProcessIn_11073TunnelCmds( pInMsg, pCBs );
  446. break;
  447. default:
  448. stat = ZFailure;
  449. break;
  450. }
  451. return ( stat );
  452. }
  453. /*********************************************************************
  454. * @fn zclPI_ProcessIn_GenericTunneServer
  455. *
  456. * @brief Callback from ZCL to process incoming Commands specific
  457. * to this cluster library on a command ID basis
  458. *
  459. * @param pInMsg - pointer to the incoming message
  460. *
  461. * @return ZStatus_t
  462. */
  463. static ZStatus_t zclPI_ProcessIn_GenericTunneServer( zclIncoming_t *pInMsg,
  464. zclPI_AppCallbacks_t *pCBs )
  465. {
  466. if ( pInMsg->hdr.commandID != COMMAND_PI_GENERIC_TUNNEL_MATCH_PROTOCOL_ADDR )
  467. return (ZFailure); // Error ignore the command
  468. if ( pCBs->pfnPI_MatchProtocolAddr )
  469. {
  470. zclPIMatchProtocolAddr_t cmd;
  471. cmd.srcAddr = &(pInMsg->msg->srcAddr);
  472. cmd.seqNum = pInMsg->hdr.transSeqNum;
  473. cmd.len = pInMsg->pData[0];
  474. cmd.protocolAddr = &(pInMsg->pData[1]);
  475. pCBs->pfnPI_MatchProtocolAddr( &cmd );
  476. }
  477. return ( ZSuccess );
  478. }
  479. /*********************************************************************
  480. * @fn zclPI_ProcessIn_GenericTunneClient
  481. *
  482. * @brief Callback from ZCL to process incoming Commands specific
  483. * to this cluster library on a command ID basis
  484. *
  485. * @param pInMsg - pointer to the incoming message
  486. *
  487. * @return ZStatus_t
  488. */
  489. static ZStatus_t zclPI_ProcessIn_GenericTunneClient( zclIncoming_t *pInMsg,
  490. zclPI_AppCallbacks_t *pCBs )
  491. {
  492. ZStatus_t stat = ZSuccess;
  493. switch ( pInMsg->hdr.commandID )
  494. {
  495. case COMMAND_PI_GENERIC_TUNNEL_MATCH_PROTOCOL_ADDR_RSP:
  496. if ( pCBs->pfnPI_MatchProtocolAddrRsp )
  497. {
  498. zclPIMatchProtocolAddrRsp_t cmd;
  499. cmd.srcAddr = &(pInMsg->msg->srcAddr);
  500. cmd.ieeeAddr = pInMsg->pData;
  501. cmd.len = pInMsg->pData[8];
  502. cmd.protocolAddr = &(pInMsg->pData[9]);
  503. pCBs->pfnPI_MatchProtocolAddrRsp( &cmd );
  504. }
  505. break;
  506. case COMMAND_PI_GENERIC_TUNNEL_ADVERTISE_PROTOCOL_ADDR:
  507. if ( pCBs->pfnPI_AdvertiseProtocolAddr )
  508. {
  509. zclPIAdvertiseProtocolAddr_t cmd;
  510. cmd.srcAddr = &(pInMsg->msg->srcAddr);
  511. cmd.len = pInMsg->pData[0];
  512. cmd.protocolAddr = &(pInMsg->pData[1]);
  513. pCBs->pfnPI_AdvertiseProtocolAddr( &cmd );
  514. }
  515. break;
  516. default:
  517. // Unknown command
  518. stat = ZFailure;
  519. break;
  520. }
  521. return ( stat );
  522. }
  523. /*********************************************************************
  524. * @fn zclPI_ProcessIn_BACnetTunnelCmds
  525. *
  526. * @brief Callback from ZCL to process incoming Commands specific
  527. * to this cluster library on a command ID basis
  528. *
  529. * @param pInMsg - pointer to the incoming message
  530. *
  531. * @return ZStatus_t
  532. */
  533. static ZStatus_t zclPI_ProcessIn_BACnetTunnelCmds( zclIncoming_t *pInMsg,
  534. zclPI_AppCallbacks_t *pCBs )
  535. {
  536. if ( pInMsg->hdr.commandID != COMMAND_PI_BACNET_TUNNEL_TRANSFER_NPDU )
  537. return (ZFailure); // Error ignore the command
  538. if ( pCBs->pfnPI_BACnetTransferNPDU )
  539. {
  540. zclBACnetTransferNPDU_t cmd;
  541. cmd.srcAddr = &(pInMsg->msg->srcAddr);
  542. cmd.len = pInMsg->pDataLen;
  543. cmd.npdu = pInMsg->pData;
  544. pCBs->pfnPI_BACnetTransferNPDU( &cmd );
  545. }
  546. return ( ZSuccess );
  547. }
  548. /*********************************************************************
  549. * @fn zclPI_ProcessIn_11073TunnelCmds
  550. *
  551. * @brief Callback from ZCL to process incoming Commands specific
  552. * to this cluster library on a command ID basis
  553. *
  554. * @param pInMsg - pointer to the incoming message
  555. *
  556. * @return ZStatus_t
  557. */
  558. static ZStatus_t zclPI_ProcessIn_11073TunnelCmds( zclIncoming_t *pInMsg,
  559. zclPI_AppCallbacks_t *pCBs )
  560. {
  561. ZStatus_t stat = ZSuccess;
  562. switch ( pInMsg->hdr.commandID )
  563. {
  564. case COMMAND_PI_11073_TUNNEL_TRANSFER_APDU:
  565. if ( pCBs->pfnPI_11073TransferAPDU )
  566. {
  567. zcl11073TransferAPDU_t cmd;
  568. cmd.srcAddr = &(pInMsg->msg->srcAddr);
  569. cmd.len = BUILD_UINT16( pInMsg->pData[0], pInMsg->pData[1] );
  570. cmd.apdu = &(pInMsg->pData[2]);
  571. pCBs->pfnPI_11073TransferAPDU( &cmd );
  572. }
  573. break;
  574. case COMMAND_PI_11073_TUNNEL_CONNECT_REQ:
  575. if ( pCBs->pfnPI_11073ConnectReq )
  576. {
  577. zcl11073ConnectReq_t cmd;
  578. cmd.srcAddr = &(pInMsg->msg->srcAddr);
  579. cmd.seqNum = pInMsg->hdr.transSeqNum;
  580. cmd.connectCtrl = pInMsg->pData[0];
  581. cmd.idleTimeout = BUILD_UINT16( pInMsg->pData[1], pInMsg->pData[2] );
  582. cmd.managerAddr = &(pInMsg->pData[3]);
  583. cmd.managerEP = pInMsg->pData[11];
  584. pCBs->pfnPI_11073ConnectReq( &cmd );
  585. }
  586. break;
  587. case COMMAND_PI_11073_TUNNEL_DISCONNECT_REQ:
  588. if ( pCBs->pfnPI_11073DisconnectReq )
  589. {
  590. zcl11073DisconnectReq_t cmd;
  591. cmd.srcAddr = &(pInMsg->msg->srcAddr);
  592. cmd.seqNum = pInMsg->hdr.transSeqNum;
  593. cmd.managerAddr = pInMsg->pData;
  594. pCBs->pfnPI_11073DisconnectReq( &cmd );
  595. }
  596. break;
  597. case COMMAND_PI_11073_TUNNEL_CONNECT_STATUS_NOTI:
  598. if ( pCBs->pfnPI_11073ConnectStatusNoti )
  599. {
  600. zcl11073ConnectStatusNoti_t cmd;
  601. cmd.srcAddr = &(pInMsg->msg->srcAddr);
  602. cmd.connectStatus = pInMsg->pData[0];
  603. pCBs->pfnPI_11073ConnectStatusNoti( &cmd );
  604. }
  605. break;
  606. default:
  607. // Unknown command
  608. stat = ZFailure;
  609. break;
  610. }
  611. return ( stat );
  612. }
  613. /****************************************************************************
  614. ****************************************************************************/