ZDObject.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /**************************************************************************************************
  2. Filename: ZDObject.h
  3. Revised: $Date: 2010-03-30 17:07:05 -0700 (Tue, 30 Mar 2010) $
  4. Revision: $Revision: 22053 $
  5. Description: This file contains the interface to the Zigbee Device Object.
  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. #ifndef ZDOBJECT_H
  34. #define ZDOBJECT_H
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #endif
  39. /*********************************************************************
  40. * INCLUDES
  41. */
  42. #include "NLMEDE.h"
  43. #include "ZDApp.h"
  44. /*********************************************************************
  45. * CONSTANTS
  46. */
  47. #if defined( ZIGBEE_FRAGMENTATION ) || ( SECURE == 0 )
  48. #define ZDO_MAX_LQI_ITEMS 3
  49. #else
  50. #define ZDO_MAX_LQI_ITEMS 2
  51. #endif
  52. #define ZDO_MAX_NWKDISC_ITEMS 5
  53. #define ZDO_MAX_RTG_ITEMS 10
  54. #define ZDO_MAX_BIND_ITEMS 3
  55. /*********************************************************************
  56. * TYPEDEFS
  57. */
  58. typedef enum
  59. {
  60. MODE_JOIN,
  61. MODE_RESUME,
  62. //MODE_SOFT, // Not supported yet
  63. MODE_HARD,
  64. MODE_REJOIN
  65. } devStartModes_t;
  66. typedef struct
  67. {
  68. uint8 status;
  69. uint16 nwkAddr;
  70. uint8 extAddr[Z_EXTADDR_LEN];
  71. uint8 numAssocDevs;
  72. uint8 startIndex;
  73. uint16 devList[];
  74. } ZDO_NwkIEEEAddrResp_t;
  75. typedef struct
  76. {
  77. uint8 status;
  78. uint16 nwkAddr; // Network address of interest
  79. NodeDescriptorFormat_t nodeDesc;
  80. } ZDO_NodeDescRsp_t;
  81. typedef struct
  82. {
  83. uint8 status;
  84. uint16 nwkAddr; // Network address of interest
  85. NodePowerDescriptorFormat_t pwrDesc;
  86. } ZDO_PowerRsp_t;
  87. typedef struct
  88. {
  89. uint8 status;
  90. uint16 nwkAddr; // Network address of interest
  91. SimpleDescriptionFormat_t simpleDesc;
  92. } ZDO_SimpleDescRsp_t;
  93. typedef struct
  94. {
  95. uint8 status;
  96. uint16 nwkAddr; // Network address of interest
  97. uint8 cnt;
  98. uint8 epList[];
  99. } ZDO_ActiveEndpointRsp_t;
  100. typedef ZDO_ActiveEndpointRsp_t ZDO_MatchDescRsp_t;
  101. typedef struct
  102. {
  103. uint8 status;
  104. uint8 networkCount;
  105. uint8 startIndex;
  106. uint8 networkListCount;
  107. mgmtNwkDiscItem_t list[];
  108. } ZDO_MgmNwkDiscRsp_t;
  109. typedef struct
  110. {
  111. uint8 status;
  112. uint8 neighborLqiEntries;
  113. uint8 startIndex;
  114. uint8 neighborLqiCount;
  115. neighborLqiItem_t list[];
  116. } ZDO_MgmtLqiRsp_t;
  117. typedef struct
  118. {
  119. uint8 status;
  120. uint8 rtgCount;
  121. uint8 startIndex;
  122. uint8 rtgListCount;
  123. rtgItem_t list[];
  124. } ZDO_MgmtRtgRsp_t;
  125. typedef struct
  126. {
  127. uint8 status;
  128. uint8 bindingCount;
  129. uint8 startIndex;
  130. uint8 bindingListCount;
  131. apsBindingItem_t list[];
  132. } ZDO_MgmtBindRsp_t;
  133. typedef struct
  134. {
  135. uint8 status;
  136. uint16 nwkAddr; // Address of interest
  137. uint8 length;
  138. uint8 desc[];
  139. } ZDO_UserDescRsp_t;
  140. typedef struct
  141. {
  142. uint8 status;
  143. uint16 serverMask;
  144. } ZDO_ServerDiscRsp_t;
  145. typedef struct
  146. {
  147. uint8 srcAddress[Z_EXTADDR_LEN];
  148. uint8 srcEndpoint;
  149. uint16 clusterID;
  150. zAddrType_t dstAddress;
  151. uint8 dstEndpoint;
  152. } ZDO_BindUnbindReq_t;
  153. typedef struct
  154. {
  155. uint16 nwkAddr;
  156. uint8 extAddr[Z_EXTADDR_LEN];
  157. uint8 capabilities;
  158. } ZDO_DeviceAnnce_t;
  159. typedef struct
  160. {
  161. uint32 channelMask;
  162. uint8 scanDuration;
  163. uint8 scanCount;
  164. uint8 nwkUpdateId;
  165. int16 nwkManagerAddr;
  166. } ZDO_MgmtNwkUpdateReq_t;
  167. typedef struct
  168. {
  169. uint8 status;
  170. uint32 scannedChannels;
  171. uint16 totalTransmissions;
  172. uint16 transmissionFailures;
  173. uint8 listCount;
  174. uint8 energyValues[];
  175. } ZDO_MgmtNwkUpdateNotify_t;
  176. /*********************************************************************
  177. * Internal ZDO types
  178. */
  179. enum
  180. {
  181. ZDMATCH_REASON_START,
  182. ZDMATCH_REASON_TIMEOUT,
  183. ZDMATCH_REASON_UNBIND_RSP,
  184. ZDMATCH_REASON_BIND_RSP
  185. };
  186. typedef struct
  187. {
  188. ZDEndDeviceBind_t ed1;
  189. ZDEndDeviceBind_t ed2;
  190. uint8 state; // One of the above states
  191. uint8 sending; // 0 - not sent, 1 - unbind, 2 bind - expecting response
  192. uint8 transSeq;
  193. uint8 ed1numMatched;
  194. uint16 *ed1Matched;
  195. uint8 ed2numMatched;
  196. uint16 *ed2Matched;
  197. } ZDMatchEndDeviceBind_t;
  198. /*********************************************************************
  199. * MACROS
  200. */
  201. /*********************************************************************
  202. * GLOBAL VARIABLES
  203. */
  204. extern ZDMatchEndDeviceBind_t *matchED;
  205. /*********************************************************************
  206. * FUNCTIONS - API
  207. */
  208. /*
  209. * ZDO_Init - ZDObject and ZDApp Initialization.
  210. */
  211. extern void ZDO_Init( void );
  212. /*
  213. * ZDO_StartDevice - Start the device in a network
  214. */
  215. extern void ZDO_StartDevice( byte logicalType, devStartModes_t startMode,
  216. byte beaconOrder, byte superframeOrder );
  217. /*
  218. * ZDO_UpdateNwkStatus - Update nwk state in the apps
  219. */
  220. extern void ZDO_UpdateNwkStatus( devStates_t state );
  221. /*
  222. * ZDO_MatchEndDeviceBind - Match End Device Bind Requests
  223. */
  224. extern void ZDO_MatchEndDeviceBind( ZDEndDeviceBind_t *bindReq );
  225. /*********************************************************************
  226. * Call Back Functions from ZDProfile - API
  227. */
  228. extern byte ZDO_AnyClusterMatches(
  229. byte ACnt, uint16 *AList, byte BCnt, uint16 *BList );
  230. /*
  231. * ZDO_ProcessNodeDescReq - Process the Node_Desc_req message.
  232. */
  233. extern void ZDO_ProcessNodeDescReq( zdoIncomingMsg_t *inMsg );
  234. /*
  235. * ZDO_ProcessPowerDescReq - Process the Power_Desc_req message.
  236. */
  237. extern void ZDO_ProcessPowerDescReq( zdoIncomingMsg_t *inMsg );
  238. /*
  239. * ZDO_ProcessSimpleDescReq - Process the Simple_Desc_req message
  240. */
  241. extern void ZDO_ProcessSimpleDescReq( zdoIncomingMsg_t *inMsg );
  242. /*
  243. * ZDO_ProcessActiveEPReq - Process the Active_EP_req message
  244. */
  245. extern void ZDO_ProcessActiveEPReq( zdoIncomingMsg_t *inMsg );
  246. /*
  247. * ZDO_ProcessMatchDescReq - Process the Match_Desc_req message
  248. */
  249. extern void ZDO_ProcessMatchDescReq( zdoIncomingMsg_t *inMsg );
  250. /*
  251. * ZDO_ProcessServerDiscRsp - Process the Server_Discovery_rsp message.
  252. */
  253. void ZDO_ProcessServerDiscRsp( zdoIncomingMsg_t *inMsg );
  254. /*
  255. * ZDO_ProcessServerDiscReq - Process the Server_Discovery_req message.
  256. */
  257. void ZDO_ProcessServerDiscReq( zdoIncomingMsg_t *inMsg );
  258. /*********************************************************************
  259. * Internal ZDO interfaces
  260. */
  261. extern uint8 ZDMatchSendState( uint8 reason, uint8 status, uint8 TransSeq );
  262. /*********************************************************************
  263. * Call Back Functions from APS - API
  264. */
  265. /*
  266. * ZDO_EndDeviceTimeoutCB - Called when the binding timer expires
  267. */
  268. extern void ZDO_EndDeviceTimeoutCB( void );
  269. /*********************************************************************
  270. * Optional Management Messages
  271. */
  272. /*
  273. * ZDO_ProcessMgmtNwkDiscReq - Called to parse the incoming
  274. * Management Network Discover Response
  275. */
  276. extern void ZDO_ProcessMgmNwkDiscRsp( zdoIncomingMsg_t *inMsg );
  277. /*
  278. * ZDO_ProcessMgmtNwkDiscReq - Called to parse the incoming
  279. * Management LQI Request
  280. */
  281. extern void ZDO_ProcessMgmtNwkDiscReq( zdoIncomingMsg_t *inMsg );
  282. /*
  283. * ZDO_FinishProcessingMgmtNwkDiscReq - Called to parse the incoming
  284. * Management LQI Request
  285. */
  286. extern void ZDO_FinishProcessingMgmtNwkDiscReq( void );
  287. /*
  288. * ZDO_ProcessMgmtNwkUpdateReq - Parse the Mgmt_NWK_Update_req message
  289. *
  290. * returns none
  291. */
  292. extern void ZDO_ParseMgmtNwkUpdateReq( zdoIncomingMsg_t *inMsg, ZDO_MgmtNwkUpdateReq_t *pReq );
  293. /*
  294. * ZDO_ProcessMgmtLqiReq - Called to parse the incoming
  295. * Management LQI Request
  296. */
  297. extern void ZDO_ProcessMgmtLqiReq( zdoIncomingMsg_t *inMsg );
  298. /*
  299. * ZDO_ProcessMgmtRtgReq - Called to parse the incoming
  300. * Management Routing Request
  301. */
  302. extern void ZDO_ProcessMgmtRtgReq( zdoIncomingMsg_t *inMsg );
  303. extern void ZDO_ProcessMgmtBindReq( zdoIncomingMsg_t *inMsg );
  304. extern void ZDO_ProcessMgmtBindRsp( zdoIncomingMsg_t *inMsg );
  305. extern void ZDO_ProcessMgmtDirectJoinReq( zdoIncomingMsg_t *inMsg );
  306. extern void ZDO_ProcessMgmtLeaveReq( zdoIncomingMsg_t *inMsg );
  307. extern void ZDO_ProcessMgmtPermitJoinReq( zdoIncomingMsg_t *inMsg );
  308. extern void ZDO_ProcessUserDescReq( zdoIncomingMsg_t *inMsg );
  309. extern void ZDO_ProcessUserDescSet( zdoIncomingMsg_t *inMsg );
  310. extern void ZDO_ProcessDeviceAnnce( zdoIncomingMsg_t *inMsg );
  311. extern void ZDO_BuildSimpleDescBuf( uint8 *buf, SimpleDescriptionFormat_t *desc );
  312. extern uint8 ZDO_ParseSimpleDescBuf( uint8 *buf, SimpleDescriptionFormat_t *desc );
  313. extern void ZDO_UpdateAddrManager( uint16 nwkAddr, uint8 *extAddr );
  314. /*
  315. * ZDO_ParseAddrRsp - Parse the NWK_addr_rsp and IEEE_addr_rsp messages
  316. *
  317. * returns a pointer to parsed structures. This structure was
  318. * allocated using osal_mem_alloc, so it must be freed
  319. * by the calling function [osal_mem_free()].
  320. */
  321. extern ZDO_NwkIEEEAddrResp_t *ZDO_ParseAddrRsp( zdoIncomingMsg_t *inMsg );
  322. /*
  323. * ZDO_ParseNodeDescRsp - Parse the Node_Desc_rsp message
  324. */
  325. extern void ZDO_ParseNodeDescRsp( zdoIncomingMsg_t *inMsg, ZDO_NodeDescRsp_t *pNDRsp );
  326. /*
  327. * ZDO_ParsePowerDescRsp - Parse the Power_Desc_rsp message
  328. */
  329. extern void ZDO_ParsePowerDescRsp( zdoIncomingMsg_t *inMsg, ZDO_PowerRsp_t *pNPRsp );
  330. /*
  331. * ZDO_ParseSimpleDescRsp - Parse the Simple_Desc_rsp message
  332. * NOTE: The pAppInClusterList and pAppOutClusterList fields
  333. * in the SimpleDescriptionFormat_t structure are allocated
  334. * and the calling function needs to free [osal_msg_free()]
  335. * these buffers.
  336. */
  337. extern void ZDO_ParseSimpleDescRsp( zdoIncomingMsg_t *inMsg, ZDO_SimpleDescRsp_t *pSimpleDescRsp );
  338. /*
  339. * ZDO_ParseEPListRsp - Parse the Active_EP_rsp or Match_Desc_rsp message
  340. *
  341. * returns a pointer to parsed structures. This structure was
  342. * allocated using osal_mem_alloc, so it must be freed
  343. * by the calling function [osal_mem_free()].
  344. */
  345. extern ZDO_ActiveEndpointRsp_t *ZDO_ParseEPListRsp( zdoIncomingMsg_t *inMsg );
  346. /*
  347. * ZDO_ParseBindRsp - Parse the Bind_rsp, Unbind_rsp or End_Device_Bind_rsp message.
  348. * Parameter: a - pointer to the message to parse [zdoIncomingMsg_t *]
  349. *
  350. * returns the status field of the message.
  351. */
  352. #define ZDO_ParseBindRsp(a) ((uint8)(*(a->asdu)))
  353. /*
  354. * ZDO_ParseMgmNwkDiscRsp - Parse the Mgmt_NWK_Disc_rsp message
  355. *
  356. * returns a pointer to parsed response structure (NULL if not allocated).
  357. * This structure was allocated using osal_mem_alloc, so it must be freed
  358. * by the calling function [osal_mem_free()].
  359. */
  360. extern ZDO_MgmNwkDiscRsp_t *ZDO_ParseMgmNwkDiscRsp( zdoIncomingMsg_t *inMsg );
  361. /*
  362. * ZDO_ParseMgmtLqiRsp - Parse the Mgmt_Lqi_rsp message
  363. *
  364. * returns a pointer to parsed response structure (NULL if not allocated).
  365. * This structure was allocated using osal_mem_alloc, so it must be freed
  366. * by the calling function [osal_mem_free()].
  367. */
  368. extern ZDO_MgmtLqiRsp_t *ZDO_ParseMgmtLqiRsp( zdoIncomingMsg_t *inMsg );
  369. /*
  370. * ZDO_ParseMgmtRtgRsp - Parse the Mgmt_Rtg_rsp message
  371. *
  372. * returns a pointer to parsed response structure (NULL if not allocated).
  373. * This structure was allocated using osal_mem_alloc, so it must be freed
  374. * by the calling function [osal_mem_free()].
  375. */
  376. extern ZDO_MgmtRtgRsp_t *ZDO_ParseMgmtRtgRsp( zdoIncomingMsg_t *inMsg );
  377. /*
  378. * ZDO_ParseMgmtBindRsp - Parse the Mgmt_Bind_rsp message
  379. *
  380. * returns a pointer to parsed response structure (NULL if not allocated).
  381. * This structure was allocated using osal_mem_alloc, so it must be freed
  382. * by the calling function [osal_mem_free()].
  383. */
  384. extern ZDO_MgmtBindRsp_t *ZDO_ParseMgmtBindRsp( zdoIncomingMsg_t *inMsg );
  385. /*
  386. * ZDO_ParseMgmtDirectJoinRsp - Parse the Mgmt_Direct_Join_rsp message.
  387. * Parameter: a - pointer to the message to parse [zdoIncomingMsg_t *]
  388. *
  389. * returns the status field of the message.
  390. */
  391. #define ZDO_ParseMgmtDirectJoinRsp(a) ((uint8)(*(a->asdu)))
  392. /*
  393. * ZDO_ParseMgmtLeaveRsp - Parse the Mgmt_Leave_rsp message.
  394. * Parameter: a - pointer to the message to parse [zdoIncomingMsg_t *]
  395. *
  396. * returns the status field of the message.
  397. */
  398. #define ZDO_ParseMgmtLeaveRsp(a) ((uint8)(*(a->asdu)))
  399. /*
  400. * ZDO_ParseMgmtPermitJoinRsp - Parse the Mgmt_Permit_Join_rsp message.
  401. * Parameter: a - pointer to the message to parse [zdoIncomingMsg_t *]
  402. *
  403. * returns the status field of the message.
  404. */
  405. #define ZDO_ParseMgmtPermitJoinRsp(a) ((uint8)(*(a->asdu)))
  406. /*
  407. * ZDO_ParseUserDescRsp - Parse the User_Desc_rsp message
  408. *
  409. * returns a pointer to parsed response structure (NULL if not allocated).
  410. * This structure was allocated using osal_mem_alloc, so it must be freed
  411. * by the calling function [osal_mem_free()].
  412. */
  413. extern ZDO_UserDescRsp_t *ZDO_ParseUserDescRsp( zdoIncomingMsg_t *inMsg );
  414. /*
  415. * ZDO_ParseServerDiscRsp - Parse the Server_Discovery_rsp message
  416. *
  417. */
  418. extern void ZDO_ParseServerDiscRsp( zdoIncomingMsg_t *inMsg, ZDO_ServerDiscRsp_t *pRsp );
  419. /*
  420. * ZDO_ParseEndDeviceBindReq - Parse the User_Desc_rsp message
  421. *
  422. * NOTE: The clusters lists in bindReq are allocated in this
  423. * function and must be freed by that calling function.
  424. */
  425. extern void ZDO_ParseEndDeviceBindReq( zdoIncomingMsg_t *inMsg, ZDEndDeviceBind_t *bindReq );
  426. /*
  427. * ZDO_ParseBindUnbindReq - Parses the Bind_req or Unbind_req messages
  428. */
  429. extern void ZDO_ParseBindUnbindReq( zdoIncomingMsg_t *inMsg, ZDO_BindUnbindReq_t *pReq );
  430. /*
  431. * ZDApp_ProcessBindUnbindReq - Called to process a Bind_req or Unbind_req message
  432. */
  433. extern void ZDO_ProcessBindUnbindReq( zdoIncomingMsg_t *inMsg, ZDO_BindUnbindReq_t *pReq );
  434. /*
  435. * ZDO_ParseUserDescConf - Parse the User_Desc_conf message.
  436. * Parameter: a - pointer to the message to parse [zdoIncomingMsg_t *]
  437. *
  438. * returns the status field of the message.
  439. */
  440. #define ZDO_ParseUserDescConf(a) ((uint8)(*(a->asdu)))
  441. /*
  442. * ZDO_ParseDeviceAnnce - Called to parse an End_Device_annce message
  443. */
  444. extern void ZDO_ParseDeviceAnnce( zdoIncomingMsg_t *inMsg, ZDO_DeviceAnnce_t *pAnnce );
  445. /*
  446. * ZDO_ParseMgmtNwkUpdateNotify - Parse the Mgmt_NWK_Update_notify message
  447. *
  448. * returns a pointer to parsed response structure (NULL if not allocated).
  449. * This structure was allocated using osal_mem_alloc, so it must be freed
  450. * by the calling function [osal_mem_free()].
  451. */
  452. extern ZDO_MgmtNwkUpdateNotify_t *ZDO_ParseMgmtNwkUpdateNotify( zdoIncomingMsg_t *inMsg );
  453. /*********************************************************************
  454. *********************************************************************/
  455. #ifdef __cplusplus
  456. }
  457. #endif
  458. #endif /* ZDOBJECT_H */