zcl.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. /**************************************************************************************************
  2. Filename: zcl.h
  3. Revised: $Date: 2008-08-01 14:42:30 -0700 (Fri, 01 Aug 2008) $
  4. Revision: $Revision: 17690 $
  5. Description: This file contains the Zigbee Cluster Library Foundation definitions.
  6. Copyright 2006-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 ZCL_H
  34. #define ZCL_H
  35. #ifdef __cplusplus
  36. extern "C"
  37. {
  38. #endif
  39. /*********************************************************************
  40. * INCLUDES
  41. */
  42. #include "AF.h"
  43. #include "aps_groups.h"
  44. /*********************************************************************
  45. * CONSTANTS
  46. */
  47. // General Clusters
  48. #define ZCL_CLUSTER_ID_GEN_BASIC 0x0000
  49. #define ZCL_CLUSTER_ID_GEN_POWER_CFG 0x0001
  50. #define ZCL_CLUSTER_ID_GEN_DEVICE_TEMP_CONFIG 0x0002
  51. #define ZCL_CLUSTER_ID_GEN_IDENTIFY 0x0003
  52. #define ZCL_CLUSTER_ID_GEN_GROUPS 0x0004
  53. #define ZCL_CLUSTER_ID_GEN_SCENES 0x0005
  54. #define ZCL_CLUSTER_ID_GEN_ON_OFF 0x0006
  55. #define ZCL_CLUSTER_ID_GEN_ON_OFF_SWITCH_CONFIG 0x0007
  56. #define ZCL_CLUSTER_ID_GEN_LEVEL_CONTROL 0x0008
  57. #define ZCL_CLUSTER_ID_GEN_ALARMS 0x0009
  58. #define ZCL_CLUSTER_ID_GEN_TIME 0x000A
  59. #define ZCL_CLUSTER_ID_GEN_LOCATION 0x000B
  60. #define ZCL_CLUSTER_ID_GEN_KEY_ESTABLISHMENT 0x0800
  61. // Closures Clusters
  62. #define ZCL_CLUSTER_ID_CLOSURES_SHADE_CONFIG 0x0100
  63. // HVAC Clusters
  64. #define ZCL_CLUSTER_ID_HVAC_PUMP_CONFIG_CONTROL 0x0200
  65. #define ZCL_CLUSTER_ID_HAVC_THERMOSTAT 0x0201
  66. #define ZCL_CLUSTER_ID_HAVC_FAN_CONTROL 0x0202
  67. #define ZCL_CLUSTER_ID_HAVC_DIHUMIDIFICATION_CONTROL 0x0203
  68. #define ZCL_CLUSTER_ID_HAVC_USER_INTERFACE_CONFIG 0x0204
  69. // Lighting Clusters
  70. #define ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL 0x0300
  71. #define ZCL_CLUSTER_ID_LIGHTING_BALLAST_CONFIG 0x0301
  72. // Measurement and Sensing Clusters
  73. #define ZCL_CLUSTER_ID_MS_ILLUMINANCE_MEASUREMENT 0x0400
  74. #define ZCL_CLUSTER_ID_MS_ILLUMINANCE_LEVEL_SENSING_CONFIG 0x0401
  75. #define ZCL_CLUSTER_ID_MS_TEMPERATURE_MEASUREMENT 0x0402
  76. #define ZCL_CLUSTER_ID_MS_PRESSURE_MEASUREMENT 0x0403
  77. #define ZCL_CLUSTER_ID_MS_FLOW_MEASUREMENT 0x0404
  78. #define ZCL_CLUSTER_ID_MS_RELATIVE_HUMIDITY 0x0405
  79. #define ZCL_CLUSTER_ID_MS_OCCUPANCY_SENSING 0x0406
  80. // Security and Safety (SS) Clusters
  81. #define ZCL_CLUSTER_ID_SS_IAS_ZONE 0x0500
  82. #define ZCL_CLUSTER_ID_SS_IAS_ACE 0x0501
  83. #define ZCL_CLUSTER_ID_SS_IAS_WD 0x0502
  84. // Advanced Metering Initiative (SE) Clusters
  85. #define ZCL_CLUSTER_ID_SE_PRICING 0x0700
  86. #define ZCL_CLUSTER_ID_SE_LOAD_CONTROL 0x0701
  87. #define ZCL_CLUSTER_ID_SE_SIMPLE_METERING 0x0702
  88. #define ZCL_CLUSTER_ID_SE_MESSAGE 0x0703
  89. #define ZCL_CLUSTER_ID_SE_REGISTRATION 0x0704
  90. #define ZCL_CLUSTER_ID_SE_SE_TUNNELING 0x0705
  91. #define ZCL_CLUSTER_ID_SE_PRE_PAYMENT 0x0706
  92. /*** Frame Control bit mask ***/
  93. #define ZCL_FRAME_CONTROL_TYPE 0x03
  94. #define ZCL_FRAME_CONTROL_MANU_SPECIFIC 0x04
  95. #define ZCL_FRAME_CONTROL_DIRECTION 0x08
  96. #define ZCL_FRAME_CONTROL_DISABLE_DEFAULT_RSP 0x10
  97. /*** Frame Types ***/
  98. #define ZCL_FRAME_TYPE_PROFILE_CMD 0x00
  99. #define ZCL_FRAME_TYPE_SPECIFIC_CMD 0x01
  100. /*** Frame Client/Server Directions ***/
  101. #define ZCL_FRAME_CLIENT_SERVER_DIR 0x00
  102. #define ZCL_FRAME_SERVER_CLIENT_DIR 0x01
  103. /*** Chipcon Manufacturer Code ***/
  104. #define CC_MANUFACTURER_CODE 0x1001
  105. /*** Foundation Command IDs ***/
  106. #define ZCL_CMD_READ 0x00
  107. #define ZCL_CMD_READ_RSP 0x01
  108. #define ZCL_CMD_WRITE 0x02
  109. #define ZCL_CMD_WRITE_UNDIVIDED 0x03
  110. #define ZCL_CMD_WRITE_RSP 0x04
  111. #define ZCL_CMD_WRITE_NO_RSP 0x05
  112. #define ZCL_CMD_CONFIG_REPORT 0x06
  113. #define ZCL_CMD_CONFIG_REPORT_RSP 0x07
  114. #define ZCL_CMD_READ_REPORT_CFG 0x08
  115. #define ZCL_CMD_READ_REPORT_CFG_RSP 0x09
  116. #define ZCL_CMD_REPORT 0x0a
  117. #define ZCL_CMD_DEFAULT_RSP 0x0b
  118. #define ZCL_CMD_DISCOVER 0x0c
  119. #define ZCL_CMD_DISCOVER_RSP 0x0d
  120. #define ZCL_CMD_MAX ZCL_CMD_DISCOVER_RSP
  121. /*** Data Types ***/
  122. #define ZCL_DATATYPE_NO_DATA 0x00
  123. #define ZCL_DATATYPE_DATA8 0x08
  124. #define ZCL_DATATYPE_DATA16 0x09
  125. #define ZCL_DATATYPE_DATA24 0x0a
  126. #define ZCL_DATATYPE_DATA32 0x0b
  127. #define ZCL_DATATYPE_BOOLEAN 0x10
  128. #define ZCL_DATATYPE_BITMAP8 0x18
  129. #define ZCL_DATATYPE_BITMAP16 0x19
  130. #define ZCL_DATATYPE_BITMAP24 0x1a
  131. #define ZCL_DATATYPE_BITMAP32 0x1b
  132. #define ZCL_DATATYPE_UINT8 0x20
  133. #define ZCL_DATATYPE_UINT16 0x21
  134. #define ZCL_DATATYPE_UINT24 0x22
  135. #define ZCL_DATATYPE_UINT32 0x23
  136. #define ZCL_DATATYPE_UINT40 0x24
  137. #define ZCL_DATATYPE_UINT48 0x25
  138. #define ZCL_DATATYPE_INT8 0x28
  139. #define ZCL_DATATYPE_INT16 0x29
  140. #define ZCL_DATATYPE_INT24 0x2a
  141. #define ZCL_DATATYPE_INT32 0x2b
  142. #define ZCL_DATATYPE_ENUM8 0x30
  143. #define ZCL_DATATYPE_ENUM16 0x31
  144. #define ZCL_DATATYPE_SEMI_PREC 0x38
  145. #define ZCL_DATATYPE_SINGLE_PREC 0x39
  146. #define ZCL_DATATYPE_DOUBLE_PREC 0x3a
  147. #define ZCL_DATATYPE_OCTET_STR 0x41
  148. #define ZCL_DATATYPE_CHAR_STR 0x42
  149. #define ZCL_DATATYPE_TOD 0xe0
  150. #define ZCL_DATATYPE_DATE 0xe1
  151. #define ZCL_DATATYPE_UTC 0xe2
  152. #define ZCL_DATATYPE_CLUSTER_ID 0xe8
  153. #define ZCL_DATATYPE_ATTR_ID 0xe9
  154. #define ZCL_DATATYPE_BAC_OID 0xea
  155. #define ZCL_DATATYPE_IEEE_ADDR 0xf0
  156. #define ZCL_DATATYPE_UNKNOWN 0xff
  157. /*** Error Status Codes ***/
  158. #define ZCL_STATUS_SUCCESS 0x00
  159. #define ZCL_STATUS_FAILURE 0x01
  160. // 0x02-0x7F are reserved.
  161. #define ZCL_STATUS_MALFORMED_COMMAND 0x80
  162. #define ZCL_STATUS_UNSUP_CLUSTER_COMMAND 0x81
  163. #define ZCL_STATUS_UNSUP_GENERAL_COMMAND 0x82
  164. #define ZCL_STATUS_UNSUP_MANU_CLUSTER_COMMAND 0x83
  165. #define ZCL_STATUS_UNSUP_MANU_GENERAL_COMMAND 0x84
  166. #define ZCL_STATUS_INVALID_FIELD 0x85
  167. #define ZCL_STATUS_UNSUPPORTED_ATTRIBUTE 0x86
  168. #define ZCL_STATUS_INVALID_VALUE 0x87
  169. #define ZCL_STATUS_READ_ONLY 0x88
  170. #define ZCL_STATUS_INSUFFICIENT_SPACE 0x89
  171. #define ZCL_STATUS_DUPLICATE_EXISTS 0x8a
  172. #define ZCL_STATUS_NOT_FOUND 0x8b
  173. #define ZCL_STATUS_UNREPORTABLE_ATTRIBUTE 0x8c
  174. #define ZCL_STATUS_INVALID_DATA_TYPE 0x8d
  175. // 0xbd-bf are reserved.
  176. #define ZCL_STATUS_HARDWARE_FAILURE 0xc0
  177. #define ZCL_STATUS_SOFTWARE_FAILURE 0xc1
  178. #define ZCL_STATUS_CALIBRATION_ERROR 0xc2
  179. // 0xc3-0xff are reserved.
  180. #define ZCL_STATUS_CMD_HAS_RSP 0xFF // Non-standard status (used for Default Rsp)
  181. /*** Attribute Access Control - bit masks ***/
  182. #define ACCESS_CONTROL_READ 0x01
  183. #define ACCESS_CONTROL_WRITE 0x02
  184. #define ACCESS_CONTROL_COMMAND 0x04
  185. #define ZCL_INVALID_CLUSTER_ID 0xFFFF
  186. #define ZCL_ATTR_ID_MAX 0xFFFF
  187. // Used by Configure Reporting Command
  188. #define ZCL_SEND_ATTR_REPORTS 0x00
  189. #define ZCL_EXPECT_ATTR_REPORTS 0x01
  190. // Predefined Maximum String Length
  191. #define MAX_UTF8_STRING_LEN 50
  192. /*********************************************************************
  193. * MACROS
  194. */
  195. #define zcl_ProfileCmd( a ) ( (a) == ZCL_FRAME_TYPE_PROFILE_CMD )
  196. #define zcl_ClusterCmd( a ) ( (a) == ZCL_FRAME_TYPE_SPECIFIC_CMD )
  197. #define zcl_ServerCmd( a ) ( (a) == ZCL_FRAME_CLIENT_SERVER_DIR )
  198. #define zcl_ClientCmd( a ) ( (a) == ZCL_FRAME_SERVER_CLIENT_DIR )
  199. #define UNICAST_MSG( msg ) ( (msg)->wasBroadcast == false && (msg)->groupId == 0 )
  200. // Padding needed if buffer has odd number of octects in length
  201. #define PADDING_NEEDED( bufLen ) ( (bufLen) % 2 )
  202. // Check for Cluster IDs
  203. #define ZCL_CLUSTER_ID_GEN( id ) ( /* (id) >= ZCL_CLUSTER_ID_GEN_BASIC &&*/ \
  204. (id) <= ZCL_CLUSTER_ID_GEN_LOCATION )
  205. #define ZCL_CLUSTER_ID_CLOSURES( id ) ( (id) == ZCL_CLUSTER_ID_CLOSURES_SHADE_CONFIG )
  206. #define ZCL_CLUSTER_ID_HVAC( id ) ( (id) >= ZCL_CLUSTER_ID_HVAC_PUMP_CONFIG_CONTROL && \
  207. (id) <= ZCL_CLUSTER_ID_HAVC_USER_INTERFACE_CONFIG )
  208. #define ZCL_CLUSTER_ID_LIGHTING( id ) ( (id) >= ZCL_CLUSTER_ID_LIGHTING_COLOR_CONTROL && \
  209. (id) <= ZCL_CLUSTER_ID_LIGHTING_BALLAST_CONFIG )
  210. #define ZCL_CLUSTER_ID_MS( id ) ( (id) >= ZCL_CLUSTER_ID_MS_ILLUMINANCE_MEASUREMENT && \
  211. (id) <= ZCL_CLUSTER_ID_MS_OCCUPANCY_SENSING )
  212. #define ZCL_CLUSTER_ID_SS( id ) ( (id) >= ZCL_CLUSTER_ID_SS_IAS_ZONE && \
  213. (id) <= ZCL_CLUSTER_ID_SS_IAS_WD )
  214. #define ZCL_CLUSTER_ID_KEY( id ) ( (id) == ZCL_CLUSTER_ID_GEN_KEY_ESTABLISHMENT )
  215. #define ZCL_CLUSTER_ID_SE( id ) ( (id) >= ZCL_CLUSTER_ID_SE_PRICING && \
  216. (id) <= ZCL_CLUSTER_ID_SE_PRE_PAYMENT )
  217. /*********************************************************************
  218. * TYPEDEFS
  219. */
  220. // ZCL header - frame control field
  221. typedef struct
  222. {
  223. unsigned int type:2;
  224. unsigned int manuSpecific:1;
  225. unsigned int direction:1;
  226. unsigned int disableDefaultRsp:1;
  227. unsigned int reserved:3;
  228. } zclFrameControl_t;
  229. // ZCL header
  230. typedef struct
  231. {
  232. zclFrameControl_t fc;
  233. uint16 manuCode;
  234. uint8 transSeqNum;
  235. uint8 commandID;
  236. } zclFrameHdr_t;
  237. #ifdef ZCL_READ
  238. // Read Attribute Command format
  239. typedef struct
  240. {
  241. uint8 numAttr; // number of attributes in the list
  242. uint16 attrID[]; // supported attributes list - this structure should
  243. // be allocated with the appropriate number of attributes.
  244. } zclReadCmd_t;
  245. // Read Attribute Response Status record
  246. typedef struct
  247. {
  248. uint16 attrID; // attribute ID
  249. uint8 status; // should be ZCL_STATUS_SUCCESS or error
  250. uint8 dataType; // attribute data type
  251. uint8 *data; // this structure is allocated, so the data is HERE
  252. // - the size depends on the attribute data type
  253. } zclReadRspStatus_t;
  254. // Read Attribute Response Command format
  255. typedef struct
  256. {
  257. uint8 numAttr; // number of attributes in the list
  258. zclReadRspStatus_t attrList[]; // attribute status list
  259. } zclReadRspCmd_t;
  260. #endif // ZCL_READ
  261. // Write Attribute record
  262. typedef struct
  263. {
  264. uint16 attrID; // attribute ID
  265. uint8 dataType; // attribute data type
  266. uint8 *attrData; // this structure is allocated, so the data is HERE
  267. // - the size depends on the attribute data type
  268. } zclWriteRec_t;
  269. // Write Attribute Command format
  270. typedef struct
  271. {
  272. uint8 numAttr; // number of attribute records in the list
  273. zclWriteRec_t attrList[]; // attribute records
  274. } zclWriteCmd_t;
  275. // Write Attribute Status record
  276. typedef struct
  277. {
  278. uint8 status; // should be ZCL_STATUS_SUCCESS or error
  279. uint16 attrID; // attribute ID
  280. } zclWriteRspStatus_t;
  281. // Write Attribute Response Command format
  282. typedef struct
  283. {
  284. uint8 numAttr; // number of attribute status in the list
  285. zclWriteRspStatus_t attrList[]; // attribute status records
  286. } zclWriteRspCmd_t;
  287. // Configure Reporting Command format
  288. typedef struct
  289. {
  290. uint8 direction; // to send or receive reports of the attribute
  291. uint16 attrID; // attribute ID
  292. uint8 dataType; // attribute data type
  293. uint16 minReportInt; // minimum reporting interval
  294. uint16 maxReportInt; // maximum reporting interval
  295. uint16 timeoutPeriod; // timeout period
  296. uint8 *reportableChange; // reportable change (only applicable to analog data type)
  297. // - the size depends on the attribute data type
  298. } zclCfgReportRec_t;
  299. typedef struct
  300. {
  301. uint8 numAttr; // number of attribute IDs in the list
  302. zclCfgReportRec_t attrList[]; // attribute ID list
  303. } zclCfgReportCmd_t;
  304. // Attribute Status record
  305. typedef struct
  306. {
  307. uint8 status; // should be ZCL_STATUS_SUCCESS or error
  308. uint8 direction; // whether attributes are reported or reports of attributes are received
  309. uint16 attrID; // attribute ID
  310. } zclCfgReportStatus_t;
  311. // Configure Reporting Response Command format
  312. typedef struct
  313. {
  314. uint8 numAttr; // number of attribute status in the list
  315. zclCfgReportStatus_t attrList[]; // attribute status records
  316. } zclCfgReportRspCmd_t;
  317. // Read Reporting Configuration Command format
  318. typedef struct
  319. {
  320. uint8 direction; // to send or receive reports of the attribute
  321. uint16 attrID; // attribute ID
  322. } zclReadReportCfgRec_t;
  323. typedef struct
  324. {
  325. uint8 numAttr; // number of attributes in the list
  326. zclReadReportCfgRec_t attrList[]; // attribute ID list
  327. } zclReadReportCfgCmd_t;
  328. // Attribute Reporting Configuration record
  329. typedef struct
  330. {
  331. uint8 status; // status field
  332. uint8 direction; // to send or receive reports of the attribute
  333. uint16 attrID; // attribute ID
  334. uint8 dataType; // attribute data type
  335. uint16 minReportInt; // minimum reporting interval
  336. uint16 maxReportInt; // maximum reporting interval
  337. uint16 timeoutPeriod; // timeout period
  338. uint8 *reportableChange; // reportable change (only applicable to analog data type)
  339. // - the size depends on the attribute data type
  340. } zclReportCfgRspRec_t;
  341. // Read Reporting Configuration Response Command format
  342. typedef struct
  343. {
  344. uint8 numAttr; // number of records in the list
  345. zclReportCfgRspRec_t attrList[]; // attribute reporting configuration list
  346. } zclReadReportCfgRspCmd_t;
  347. // Attribute Report
  348. typedef struct
  349. {
  350. uint16 attrID; // atrribute ID
  351. uint8 dataType; // attribute data type
  352. uint8 *attrData; // this structure is allocated, so the data is HERE
  353. // - the size depends on the data type of attrID
  354. } zclReport_t;
  355. // Report Attributes Command format
  356. typedef struct
  357. {
  358. uint8 numAttr; // number of reports in the list
  359. zclReport_t attrList[]; // attribute report list
  360. } zclReportCmd_t;
  361. // Default Response Command format
  362. typedef struct
  363. {
  364. uint8 commandID;
  365. uint8 statusCode;
  366. } zclDefaultRspCmd_t;
  367. // Discover Attributes Command format
  368. typedef struct
  369. {
  370. uint16 startAttr; // specifies the minimum value of the identifier
  371. // to begin attribute discovery.
  372. uint8 maxAttrIDs; // maximum number of attribute IDs that are to be
  373. // returned in the resulting response command.
  374. } zclDiscoverCmd_t;
  375. // Attribute Report info
  376. typedef struct
  377. {
  378. uint16 attrID; // attribute ID
  379. uint8 dataType; // attribute data type (see Table 17 in Spec)
  380. } zclDiscoverInfo_t;
  381. // Discover Attributes Response Command format
  382. typedef struct
  383. {
  384. uint8 discComplete; // whether or not there're more attributes to be discovered
  385. uint8 numAttr; // number of attributes in the list
  386. zclDiscoverInfo_t attrList[]; // supported attributes list
  387. } zclDiscoverRspCmd_t;
  388. // String Data Type
  389. typedef struct
  390. {
  391. uint8 strLen;
  392. uint8 *pStr;
  393. } UTF8String_t;
  394. /*********************************************************************
  395. * Plugins
  396. */
  397. // Incoming ZCL message, this buffer will be allocated, cmd will point to the
  398. // the command record.
  399. typedef struct
  400. {
  401. afIncomingMSGPacket_t *msg; // incoming message
  402. zclFrameHdr_t hdr; // ZCL header parsed
  403. uint8 *pData; // pointer to data after header
  404. uint8 pDataLen; // length of remaining data
  405. void *attrCmd; // pointer to the parsed attribute or command
  406. } zclIncoming_t;
  407. // Outgoing ZCL Cluster Specific Commands
  408. typedef struct
  409. {
  410. zclFrameHdr_t hdr;
  411. uint16 realClusterID;
  412. uint16 attrID;
  413. void *cmdStruct;
  414. uint8 cmdLen;
  415. uint8 *cmdData;
  416. } zclOutgoingCmd_t;
  417. // Incoming ZCL message passed to the Application. This buffer will be
  418. // allocated and attrCmd will point to the command record.
  419. //
  420. // NOTE - the Application must deallocate the message plus attrCmd buffer.
  421. //
  422. typedef struct
  423. {
  424. osal_event_hdr_t hdr; // OSAL header
  425. zclFrameHdr_t zclHdr; // ZCL header parsed
  426. uint16 clusterId; // Cluster ID
  427. afAddrType_t srcAddr; // Sender's address
  428. void *attrCmd; // pointer to the parsed attribute or command
  429. } zclIncomingMsg_t;
  430. // Function pointer type to handle incoming messages.
  431. // msg - incoming message
  432. // logicalClusterID - logical cluster ID
  433. typedef ZStatus_t (*zclInHdlr_t)( zclIncoming_t *pInHdlrMsg );
  434. // Function pointer type to handle incoming write commands.
  435. // msg - incoming message
  436. // logicalClusterID - logical cluster ID
  437. // writeRec - received data to be written
  438. typedef ZStatus_t (*zclInWrtHdlr_t)( zclIncoming_t *msg, uint16 logicalClusterID, zclWriteRec_t *writeRec );
  439. // Attribute record
  440. typedef struct
  441. {
  442. uint16 attrId; // Attribute ID
  443. uint8 dataType; // Data Type - defined in AF.h
  444. uint8 accessControl; // Read/write - bit field
  445. void *dataPtr; // Pointer to data field
  446. } zclAttribute_t;
  447. typedef struct
  448. {
  449. uint16 clusterID; // Real cluster ID
  450. zclAttribute_t attr;
  451. } zclAttrRec_t;
  452. // Function pointer type to validate attribute data.
  453. // pAttr - where data to be written
  454. // pAttrInfo - pointer to attribute info
  455. typedef uint8 (*zclValidateAttrData_t)( zclAttrRec_t *pAttr, zclWriteRec_t *pAttrInfo );
  456. typedef struct
  457. {
  458. uint16 clusterID; // Real cluster ID
  459. uint8 option;
  460. } zclOptionRec_t;
  461. // Parse received command
  462. typedef struct
  463. {
  464. uint8 endpoint;
  465. uint8 dataLen;
  466. uint8 *pData;
  467. } zclParseCmd_t;
  468. /*********************************************************************
  469. * GLOBAL VARIABLES
  470. */
  471. extern uint8 zcl_TaskID;
  472. extern uint8 zcl_SeqNum;
  473. /*********************************************************************
  474. * FUNCTION MACROS
  475. */
  476. #ifdef ZCL_WRITE
  477. /*
  478. * Send a Write Command - ZCL_CMD_WRITE
  479. * Use like:
  480. * ZStatus_t zcl_SendWrite( uint8 srcEP, afAddrType_t *dstAddr, uint16 realClusterID, zclWriteCmd_t *writeCmd, uint8 direction, uint8 disableDefaultRsp, uint8 seqNum );
  481. */
  482. #define zcl_SendWrite(a,b,c,d,e,f,g) (zcl_SendWriteRequest( (a), (b), (c), (d), ZCL_CMD_WRITE, (e), (f), (g) ))
  483. /*
  484. * Send a Write Undivided Command - ZCL_CMD_WRITE_UNDIVIDED
  485. * Use like:
  486. * ZStatus_t zcl_SendWriteUndivided( uint8 srcEP, afAddrType_t *dstAddr, uint16 realClusterID, zclWriteCmd_t *writeCmd, uint8 direction, uint8 disableDefaultRsp, uint8 seqNum );
  487. */
  488. #define zcl_SendWriteUndivided(a,b,c,d,e,f,g) (zcl_SendWriteRequest( (a), (b), (c), (d), ZCL_CMD_WRITE_UNDIVIDED, (e), (f), (g) ))
  489. /*
  490. * Send a Write No Response Command - ZCL_CMD_WRITE_NO_RSP
  491. * Use like:
  492. * ZStatus_t zcl_SendWriteNoRsp( uint8 srcEP, afAddrType_t *dstAddr, uint16 realClusterID, zclWriteCmd_t *writeCmd, uint8 direction, uint8 disableDefaultRsp, uint8 seqNum );
  493. */
  494. #define zcl_SendWriteNoRsp(a,b,c,d,e,f,g) (zcl_SendWriteRequest( (a), (b), (c), (d), ZCL_CMD_WRITE_NO_RSP, (e), (f), (g) ))
  495. #endif // ZCL_WRITE
  496. /*********************************************************************
  497. * FUNCTIONS
  498. */
  499. /*
  500. * Initialization for the task
  501. */
  502. extern void zcl_Init( byte task_id );
  503. /*
  504. * Event Process for the task
  505. */
  506. extern UINT16 zcl_event_loop( byte task_id, UINT16 events );
  507. /*
  508. * Function for Plugins' to register for incoming messages
  509. */
  510. extern ZStatus_t zcl_registerPlugin( uint16 startLogCluster, uint16 endLogCluster,
  511. zclInHdlr_t pfnIncomingHdlr );
  512. /*
  513. * Register Application's Attribute table
  514. */
  515. extern ZStatus_t zcl_registerAttrList( uint8 endpoint, uint8 numAttr, CONST zclAttrRec_t attrList[] );
  516. /*
  517. * Register Application's Cluster Option table
  518. */
  519. extern ZStatus_t zcl_registerClusterOptionList( uint8 endpoint, uint8 numOption, zclOptionRec_t optionList[] );
  520. /*
  521. * Register Application's attribute data validation callback routine
  522. */
  523. extern ZStatus_t zcl_registerValidateAttrData( zclValidateAttrData_t pfnValidateAttrData );
  524. /*
  525. * Register the Application to receive the unprocessed Foundation command/response messages
  526. */
  527. extern uint8 zcl_registerForMsg( uint8 taskId );
  528. /*
  529. * Function for Sending a Command
  530. */
  531. extern ZStatus_t zcl_SendCommand( uint8 srcEP, afAddrType_t *dstAddr,
  532. uint16 clusterID, uint8 cmd, uint8 specific, uint8 direction,
  533. uint8 disableDefaultRsp, uint16 manuCode, uint8 seqNum,
  534. uint8 cmdFormatLen, uint8 *cmdFormat );
  535. #ifdef ZCL_READ
  536. /*
  537. * Function for Reading an Attribute
  538. */
  539. extern ZStatus_t zcl_SendRead( uint8 srcEP, afAddrType_t *dstAddr,
  540. uint16 realClusterID, zclReadCmd_t *readCmd,
  541. uint8 direction, uint8 disableDefaultRsp, uint8 seqNum );
  542. /*
  543. * Function for sending a Read response command
  544. */
  545. extern ZStatus_t zcl_SendReadRsp( uint8 srcEP, afAddrType_t *dstAddr,
  546. uint16 realClusterID, zclReadRspCmd_t *readRspCmd,
  547. uint8 direction, uint8 disableDefaultRsp, uint8 seqNum );
  548. #endif // ZCL_READ
  549. #ifdef ZCL_WRITE
  550. /*
  551. * Function for Writing an Attribute
  552. */
  553. extern ZStatus_t zcl_SendWriteRequest( uint8 srcEP, afAddrType_t *dstAddr,
  554. uint16 realClusterID, zclWriteCmd_t *writeCmd,
  555. uint8 cmd, uint8 direction, uint8 disableDefaultRsp, uint8 seqNum );
  556. /*
  557. * Function for sending a Write response command
  558. */
  559. extern ZStatus_t zcl_SendWriteRsp( uint8 srcEP, afAddrType_t *dstAddr,
  560. uint16 realClusterID, zclWriteRspCmd_t *writeRspCmd,
  561. uint8 direction, uint8 disableDefaultRsp, uint8 seqNum );
  562. #endif // ZCL_WRITE
  563. #ifdef ZCL_REPORT
  564. /*
  565. * Function for Configuring the Reporting mechanism for one or more attributes
  566. */
  567. extern ZStatus_t zcl_SendConfigReportCmd( uint8 srcEP, afAddrType_t *dstAddr,
  568. uint16 realClusterID, zclCfgReportCmd_t *cfgReportCmd,
  569. uint8 direction, uint8 disableDefaultRsp, uint8 seqNum );
  570. /*
  571. * Function for sending a Configure Reporting Response Command
  572. */
  573. extern ZStatus_t zcl_SendConfigReportRspCmd( uint8 srcEP, afAddrType_t *dstAddr,
  574. uint16 realClusterID, zclCfgReportRspCmd_t *cfgReportRspCmd,
  575. uint8 direction, uint8 disableDefaultRsp, uint8 seqNum );
  576. /*
  577. * Function for Reading the configuration details of the Reporting mechanism
  578. */
  579. extern ZStatus_t zcl_SendReadReportCfgCmd( uint8 srcEP, afAddrType_t *dstAddr,
  580. uint16 realClusterID, zclReadReportCfgCmd_t *readReportCfgCmd,
  581. uint8 direction, uint8 disableDefaultRsp, uint8 seqNum );
  582. /*
  583. * Function for sending a Read Reporting Configuration Response command
  584. */
  585. extern ZStatus_t zcl_SendReadReportCfgRspCmd( uint8 srcEP, afAddrType_t *dstAddr,
  586. uint16 realClusterID, zclReadReportCfgRspCmd_t *readReportCfgRspCmd,
  587. uint8 direction, uint8 disableDefaultRsp, uint8 seqNum );
  588. /*
  589. * Function for Reporting the value of one or more attributes
  590. */
  591. extern ZStatus_t zcl_SendReportCmd( uint8 srcEP, afAddrType_t *dstAddr,
  592. uint16 realClusterID, zclReportCmd_t *reportCmd,
  593. uint8 direction, uint8 disableDefaultRsp, uint8 seqNum );
  594. #endif // ZCL_REPORT
  595. /*
  596. * Function for sending the Default Response command
  597. */
  598. extern ZStatus_t zcl_SendDefaultRspCmd( uint8 srcEP, afAddrType_t *dstAddr,
  599. uint16 realClusterID, zclDefaultRspCmd_t *defaultRspCmd,
  600. uint8 direction, uint8 disableDefaultRsp, uint8 seqNum );
  601. #ifdef ZCL_DISCOVER
  602. /*
  603. * Function to Discover the ID and Types of the Attributes on a remote device
  604. */
  605. extern ZStatus_t zcl_SendDiscoverCmd( uint8 srcEP, afAddrType_t *dstAddr,
  606. uint16 realClusterID, zclDiscoverCmd_t *discoverCmd,
  607. uint8 direction, uint8 disableDefaultRsp, uint8 seqNum );
  608. /*
  609. * Function for sending the Discover Attributes Response command
  610. */
  611. extern ZStatus_t zcl_SendDiscoverRspCmd( uint8 srcEP, afAddrType_t *dstAddr,
  612. uint16 realClusterID, zclDiscoverRspCmd_t *discoverRspCmd,
  613. uint8 direction, uint8 disableDefaultRsp, uint8 seqNum );
  614. #endif // ZCL_DISCOVER
  615. #ifdef ZCL_READ
  616. /*
  617. * Function to parse the "Profile" Read Commands
  618. */
  619. extern void *zclParseInReadCmd( zclParseCmd_t *pCmd );
  620. #endif // ZCL_READ
  621. #ifdef ZCL_WRITE
  622. /*
  623. * Function to parse the "Profile" Write, Write Undivided and Write No Response
  624. * Commands
  625. */
  626. extern void *zclParseInWriteCmd( zclParseCmd_t *pCmd );
  627. #endif // ZCL_WRITE
  628. #ifdef ZCL_REPORT
  629. /*
  630. * Function to parse the "Profile" Configure Reporting Command
  631. */
  632. extern void *zclParseInConfigReportCmd( zclParseCmd_t *pCmd );
  633. /*
  634. * Function to parse the "Profile" Read Reporting Configuration Command
  635. */
  636. extern void *zclParseInReadReportCfgCmd( zclParseCmd_t *pCmd );
  637. /*
  638. * Function to parse the "Profile" Report attribute Command
  639. */
  640. extern void *zclParseInReportCmd( zclParseCmd_t *pCmd );
  641. /*
  642. * Function to check to see if Data Type is Analog
  643. */
  644. extern uint8 zclAnalogDataType( uint8 dataType );
  645. #endif // ZCL_REPORT
  646. #ifdef ZCL_DISCOVER
  647. /*
  648. * Function to parse the "Profile" Discover Commands
  649. */
  650. extern void *zclParseInDiscCmd( zclParseCmd_t *pCmd );
  651. #endif // ZCL_DISCOVER
  652. /*
  653. * Function to parse header of the ZCL format
  654. */
  655. extern uint8 *zclParseHdr( zclFrameHdr_t *hdr, uint8 *pData );
  656. /*
  657. * Function to find the attribute record that matchs the parameters
  658. */
  659. extern uint8 zclFindAttrRec( uint8 endpoint, uint16 realClusterID, uint16 attrId, zclAttrRec_t *pAttr );
  660. /*
  661. * Function to read the attribute's current value
  662. */
  663. extern uint8 zclReadAttrData( uint8 *pAttrData, zclAttrRec_t *pAttr );
  664. /*
  665. * Function to return the length of the datatype in length.
  666. */
  667. extern uint8 zclGetDataTypeLength( uint8 dataType );
  668. /*
  669. * Function to return the length of the attribute.
  670. */
  671. extern uint8 zclGetAttrDataLength( uint8 dataType, uint8 *pData);
  672. /*********************************************************************
  673. *********************************************************************/
  674. #ifdef __cplusplus
  675. }
  676. #endif
  677. #endif /* ZCL_H */