For fields of type FT_ABSOLUTE_TIME, have the "display" value be one of
[obnox/wireshark/wip.git] / epan / dissectors / packet-zbee-zcl.c
1 /* packet-zbee-zcl.c
2  * Dissector routines for the ZigBee Cluster Library (ZCL)
3  * By Fred Fierling <fff@exegin.com>
4  * Copyright 2009 Exegin Technologies Limited
5  *
6  * $Id$
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * Used Owen Kirby's packet-zbee-aps module as a template. Based
13  * on ZigBee Cluster Library Specification document 075123r02ZB
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28  */
29
30 /*  Include Files */
31 #ifdef HAVE_CONFIG_H
32 #include "config.h"
33 #endif /* HAVEHCONFIG_H */
34
35 #include <string.h>
36 #include <glib.h>
37 #include <epan/packet.h>
38
39 #include "packet-zbee.h"
40 #include "packet-zbee-zcl.h"
41
42 /*************************
43  * Function Declarations *
44  *************************
45  */
46 /* Dissector Routines */
47 static void dissect_zbee_zcl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
48
49 /* Command Dissector Helpers */
50 static void dissect_zcl_read_attr (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint *offset);
51 static void dissect_zcl_read_attr_resp (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
52                 guint *offset);
53 static void dissect_zcl_write_attr (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint *offset);
54 static void dissect_zcl_write_attr_resp (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
55                 guint *offset);
56 static void dissect_zcl_config_report (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint *offset);
57 static void dissect_zcl_config_report_resp (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
58                 guint *offset);
59 static void dissect_zcl_read_report_config (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
60                 guint *offset);
61 static void dissect_zcl_read_report_config_resp (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
62                 guint *offset);
63 static void dissect_zcl_default_resp (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint *offset);
64 static void dissect_zcl_discover_attr (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint *offset);
65 static void dissect_zcl_discover_attr_resp (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
66                 guint *offset);
67
68 /* Helper routines */
69 guint zbee_apf_transaction_len (tvbuff_t *tvb, guint offset, guint8 type);
70 static void  dissect_zcl_attr_data_type_val (tvbuff_t *tvb, proto_tree *tree, guint *offset);
71 #if 0
72 static guint dissect_zcl_attr_data_type (tvbuff_t *tvb, proto_tree *tree, guint *offset);
73 #endif
74 static void  dissect_zcl_attr_data (tvbuff_t *tvb, proto_tree *tree, guint *offset, guint data_type);
75 static void  dissect_zcl_attr_bytes (tvbuff_t *tvb, proto_tree *tree, guint *offset, guint length);
76 static guint dissect_zcl_attr_uint8 (tvbuff_t *tvb, proto_tree *tree, guint *offset, int *length);
77 static guint dissect_zcl_attr_uint16 (tvbuff_t *tvb, proto_tree *tree, guint *offset, int *length);
78 static void  dissect_zcl_attr_id (tvbuff_t *tvb, proto_tree *tree, guint *offset);
79 static void  dissect_zcl_big_int (tvbuff_t *tvb, proto_tree *tree, guint *offset, guint length,
80                 gboolean signed_flag);
81 static void  zcl_dump_data(tvbuff_t *tvb, guint offset, packet_info *pinfo, proto_tree *tree);
82
83 static guint64 tvb_get_letohi (tvbuff_t *tvb, guint offset, guint length, gboolean signed_flag);
84
85 /********************
86  * Global Variables *
87  ********************
88  */
89 /* Header Field Indices. */
90 static int proto_zbee_zcl = -1;
91 static int hf_zbee_zcl_fcf_frame_type = -1;
92 static int hf_zbee_zcl_fcf_mfr_spec = -1;
93 static int hf_zbee_zcl_fcf_dir = -1;
94 static int hf_zbee_zcl_fcf_disable_default_resp = -1;
95 static int hf_zbee_zcl_mfr_code = -1;
96 static int hf_zbee_zcl_tran_seqno = -1;
97
98 static int hf_zbee_zcl_cmd_id = -1;
99 static int hf_zbee_zcl_cs_cmd_id = -1;
100 static int hf_zbee_zcl_attr_id = -1;
101 static int hf_zbee_zcl_attr_data_type = -1;
102 static int hf_zbee_zcl_attr_boolean = -1;
103 static int hf_zbee_zcl_attr_uint8 = -1;
104 static int hf_zbee_zcl_attr_uint16 = -1;
105 static int hf_zbee_zcl_attr_uint24 = -1;
106 static int hf_zbee_zcl_attr_uint32 = -1;
107 static int hf_zbee_zcl_attr_uint64 = -1;
108 static int hf_zbee_zcl_attr_int8 = -1;
109 static int hf_zbee_zcl_attr_int16 = -1;
110 static int hf_zbee_zcl_attr_int24 = -1;
111 static int hf_zbee_zcl_attr_int32 = -1;
112 static int hf_zbee_zcl_attr_int64 = -1;
113 static int hf_zbee_zcl_attr_semi = -1;
114 static int hf_zbee_zcl_attr_float = -1;
115 static int hf_zbee_zcl_attr_double = -1;
116 static int hf_zbee_zcl_attr_bytes = -1;
117 static int hf_zbee_zcl_attr_minint = -1;
118 static int hf_zbee_zcl_attr_maxint = -1;
119 static int hf_zbee_zcl_attr_timeout = -1;
120 static int hf_zbee_zcl_attr_cid = -1;
121 static int hf_zbee_zcl_attr_hours = -1;
122 static int hf_zbee_zcl_attr_mins = -1;
123 static int hf_zbee_zcl_attr_secs = -1;
124 static int hf_zbee_zcl_attr_csecs = -1;
125 static int hf_zbee_zcl_attr_yy = -1;
126 static int hf_zbee_zcl_attr_mm = -1;
127 static int hf_zbee_zcl_attr_md = -1;
128 static int hf_zbee_zcl_attr_wd = -1;
129 static int hf_zbee_zcl_attr_utc = -1;
130 static int hf_zbee_zcl_attr_status = -1;
131 static int hf_zbee_zcl_attr_dir = -1;
132 static int hf_zbee_zcl_attr_dis = -1;
133 static int hf_zbee_zcl_attr_start = -1;
134 static int hf_zbee_zcl_attr_maxnum = -1;
135 static int hf_zbee_zcl_attr_str_len = -1;
136 static int hf_zbee_zcl_attr_str = -1;
137 static int hf_zbee_zcl_attr_ostr = -1;
138
139 /* Subtree indices. */
140 static gint ett_zbee_zcl = -1;
141 static gint ett_zbee_zcl_fcf = -1;
142 static gint ett_zbee_zcl_attr[ZBEE_ZCL_NUM_ATTR_ETT];
143
144 /* Dissector Handles. */
145 static dissector_handle_t   data_handle;
146
147 /********************/
148 /* Field Names      */
149 /********************/
150 /* Frame Type Names */
151 static const value_string zbee_zcl_frame_types[] = {
152     { ZBEE_ZCL_FCF_PROFILE_WIDE,    "Profile-wide" },
153     { ZBEE_ZCL_FCF_CLUSTER_SPEC,    "Cluster-specific" },
154     { 0, NULL }
155 };
156
157 /* ZCL Command Names */
158 static const value_string zbee_zcl_cmd_names[] = {
159     { ZBEE_ZCL_CMD_READ_ATTR,               "Read Attributes" },
160     { ZBEE_ZCL_CMD_READ_ATTR_RESP,          "Read Attributes Response" },
161     { ZBEE_ZCL_CMD_WRITE_ATTR,              "Write Attributes" },
162     { ZBEE_ZCL_CMD_WRITE_ATTR_UNDIVIDED,    "Write Attributes Undivided" },
163     { ZBEE_ZCL_CMD_WRITE_ATTR_RESP,         "Write Attributes Response" },
164     { ZBEE_ZCL_CMD_WRITE_ATTR_NO_RESP,      "Write Attributes No Response" },
165     { ZBEE_ZCL_CMD_CONFIG_REPORT,           "Configure Reporting" },
166     { ZBEE_ZCL_CMD_CONFIG_REPORT_RESP,      "Configure Reporting Response" },
167     { ZBEE_ZCL_CMD_READ_REPORT_CONFIG,      "Read Reporting Configuration" },
168     { ZBEE_ZCL_CMD_READ_REPORT_CONFIG_RESP, "Read Reporting Configuration Response" },
169     { ZBEE_ZCL_CMD_REPORT_ATTR,             "Report Attributes" },
170     { ZBEE_ZCL_CMD_DEFAULT_RESP,            "Default Response" },
171     { ZBEE_ZCL_CMD_DISCOVER_ATTR,           "Discover Attributes" },
172     { ZBEE_ZCL_CMD_DISCOVER_ATTR_RESP,      "Discover Attributes Response" },
173     { ZBEE_ZCL_CMD_READ_ATTR_STRUCT,        "Read Attributes Structured" },
174     { ZBEE_ZCL_CMD_WRITE_ATTR_STRUCT,       "Write Attributes Structured" },
175     { ZBEE_ZCL_CMD_WRITE_ATTR_STRUCT_RESP,  "Write Attributes Structured Response" },
176
177     { 0, NULL }
178 };
179
180 /* ZCL Cluster-Specific Command Names */
181 static const value_string zbee_zcl_cs_cmd_names[] = {
182     { 0, NULL }
183 };
184
185
186 /* Manufacturer Name Table */
187 static const value_string zbee_mfr_code_names[] = {
188
189     { ZBEE_MFG_CODE_CIRRONET,   ZBEE_MFG_CIRRONET },
190     { ZBEE_MFG_CODE_CHIPCON,    ZBEE_MFG_CHIPCON },
191     { ZBEE_MFG_CODE_EMBER,      ZBEE_MFG_EMBER },
192     { ZBEE_MFG_CODE_NTS,        ZBEE_MFG_NTS },
193     { ZBEE_MFG_CODE_FREESCALE,  ZBEE_MFG_FREESCALE },
194     { ZBEE_MFG_CODE_IPCOM,      ZBEE_MFG_IPCOM },
195     { ZBEE_MFG_CODE_SAN_JUAN,   ZBEE_MFG_SAN_JUAN },
196     { ZBEE_MFG_CODE_TUV,        ZBEE_MFG_TUV },
197     { ZBEE_MFG_CODE_COMPXS,     ZBEE_MFG_COMPXS },
198     { ZBEE_MFG_CODE_BM,         ZBEE_MFG_BM },
199     { ZBEE_MFG_CODE_AWAREPOINT, ZBEE_MFG_AWAREPOINT },
200     { ZBEE_MFG_CODE_PHILIPS,    ZBEE_MFG_PHILIPS },
201     { ZBEE_MFG_CODE_LUXOFT,     ZBEE_MFG_LUXOFT },
202     { ZBEE_MFG_CODE_KORWIN,     ZBEE_MFG_KORWIN },
203     { ZBEE_MFG_CODE_1_RF,       ZBEE_MFG_1_RF },
204     { ZBEE_MFG_CODE_STG,        ZBEE_MFG_STG },
205     { ZBEE_MFG_CODE_TELEGESIS,  ZBEE_MFG_TELEGESIS },
206     { ZBEE_MFG_CODE_VISIONIC,   ZBEE_MFG_VISIONIC },
207     { ZBEE_MFG_CODE_INSTA,      ZBEE_MFG_INSTA },
208     { ZBEE_MFG_CODE_ATALUM,     ZBEE_MFG_ATALUM },
209     { ZBEE_MFG_CODE_ATMEL,      ZBEE_MFG_ATMEL },
210     { ZBEE_MFG_CODE_DEVELCO,    ZBEE_MFG_DEVELCO },
211     { ZBEE_MFG_CODE_HONEYWELL,  ZBEE_MFG_HONEYWELL },
212     /**/
213     { ZBEE_MFG_CODE_RENESAS,    ZBEE_MFG_RENESAS },
214     { ZBEE_MFG_CODE_XANADU,     ZBEE_MFG_XANADU },
215     { ZBEE_MFG_CODE_NEC,        ZBEE_MFG_NEC },
216     { ZBEE_MFG_CODE_YAMATAKE,   ZBEE_MFG_YAMATAKE },
217     { ZBEE_MFG_CODE_TENDRIL,    ZBEE_MFG_TENDRIL },
218     { ZBEE_MFG_CODE_ASSA,       ZBEE_MFG_ASSA },
219     { ZBEE_MFG_CODE_MAXSTREAM,  ZBEE_MFG_MAXSTREAM },
220     { ZBEE_MFG_CODE_NEUROCOM,   ZBEE_MFG_NEUROCOM },
221
222     { ZBEE_MFG_CODE_III,        ZBEE_MFG_III },
223     { ZBEE_MFG_CODE_VANTAGE,    ZBEE_MFG_VANTAGE },
224     { ZBEE_MFG_CODE_ICONTROL,   ZBEE_MFG_ICONTROL },
225     { ZBEE_MFG_CODE_RAYMARINE,  ZBEE_MFG_RAYMARINE },
226     { ZBEE_MFG_CODE_LSR,        ZBEE_MFG_LSR },
227     { ZBEE_MFG_CODE_ONITY,      ZBEE_MFG_ONITY },
228     { ZBEE_MFG_CODE_MONO,       ZBEE_MFG_MONO },
229     { ZBEE_MFG_CODE_RFT,        ZBEE_MFG_RFT },
230     { ZBEE_MFG_CODE_ITRON,      ZBEE_MFG_ITRON },
231     { ZBEE_MFG_CODE_TRITECH,    ZBEE_MFG_TRITECH },
232     { ZBEE_MFG_CODE_EMBEDIT,    ZBEE_MFG_EMBEDIT },
233     { ZBEE_MFG_CODE_S3C,        ZBEE_MFG_S3C },
234     { ZBEE_MFG_CODE_SIEMENS,    ZBEE_MFG_SIEMENS },
235     { ZBEE_MFG_CODE_MINDTECH,   ZBEE_MFG_MINDTECH },
236     { ZBEE_MFG_CODE_LGE,        ZBEE_MFG_LGE },
237     { ZBEE_MFG_CODE_MITSUBISHI, ZBEE_MFG_MITSUBISHI },
238
239     { ZBEE_MFG_CODE_JOHNSON,    ZBEE_MFG_JOHNSON },
240     { ZBEE_MFG_CODE_PRI,        ZBEE_MFG_PRI },
241     { ZBEE_MFG_CODE_KNICK,      ZBEE_MFG_KNICK },
242     { ZBEE_MFG_CODE_VICONICS,   ZBEE_MFG_VICONICS },
243     { ZBEE_MFG_CODE_FLEXIPANEL, ZBEE_MFG_FLEXIPANEL },
244     /**/
245     { ZBEE_MFG_CODE_TRANE,      ZBEE_MFG_TRANE },
246     { ZBEE_MFG_CODE_JENNIC,     ZBEE_MFG_JENNIC },
247     { ZBEE_MFG_CODE_LIG,        ZBEE_MFG_LIG },
248     { ZBEE_MFG_CODE_ALERTME,    ZBEE_MFG_ALERTME },
249     { ZBEE_MFG_CODE_DAINTREE,   ZBEE_MFG_DAINTREE },
250     { ZBEE_MFG_CODE_AIJI,       ZBEE_MFG_AIJI },
251     { ZBEE_MFG_CODE_TEL_ITALIA, ZBEE_MFG_TEL_ITALIA },
252     { ZBEE_MFG_CODE_MIKROKRETS, ZBEE_MFG_MIKROKRETS },
253     { ZBEE_MFG_CODE_OKI,        ZBEE_MFG_OKI },
254     { ZBEE_MFG_CODE_NEWPORT,    ZBEE_MFG_NEWPORT },
255
256     { ZBEE_MFG_CODE_C4,         ZBEE_MFG_C4 },
257     { ZBEE_MFG_CODE_STM,        ZBEE_MFG_STM },
258     { ZBEE_MFG_CODE_ASN,        ZBEE_MFG_ASN },
259     { ZBEE_MFG_CODE_DCSI,       ZBEE_MFG_DCSI },
260     { ZBEE_MFG_CODE_FRANCE_TEL, ZBEE_MFG_FRANCE_TEL },
261     { ZBEE_MFG_CODE_MUNET,      ZBEE_MFG_MUNET },
262     { ZBEE_MFG_CODE_AUTANI,     ZBEE_MFG_AUTANI },
263     { ZBEE_MFG_CODE_COL_VNET,   ZBEE_MFG_COL_VNET },
264     { ZBEE_MFG_CODE_AEROCOMM,   ZBEE_MFG_AEROCOMM },
265     { ZBEE_MFG_CODE_SI_LABS,    ZBEE_MFG_SI_LABS },
266     { ZBEE_MFG_CODE_INNCOM,     ZBEE_MFG_INNCOM },
267     { ZBEE_MFG_CODE_CANNON,     ZBEE_MFG_CANNON },
268     { ZBEE_MFG_CODE_SYNAPSE,    ZBEE_MFG_SYNAPSE },
269     { ZBEE_MFG_CODE_FPS,        ZBEE_MFG_FPS },
270     { ZBEE_MFG_CODE_CLS,        ZBEE_MFG_CLS },
271     { ZBEE_MFG_CODE_CRANE,      ZBEE_MFG_CRANE },
272
273     { ZBEE_MFG_CODE_MOBILARM,   ZBEE_MFG_MOBILARM },
274     { ZBEE_MFG_CODE_IMONITOR,   ZBEE_MFG_IMONITOR },
275     { ZBEE_MFG_CODE_BARTECH,    ZBEE_MFG_BARTECH },
276     { ZBEE_MFG_CODE_MESHNETICS, ZBEE_MFG_MESHNETICS },
277     { ZBEE_MFG_CODE_LS_IND,     ZBEE_MFG_LS_IND },
278     { ZBEE_MFG_CODE_CASON,      ZBEE_MFG_CASON },
279     { ZBEE_MFG_CODE_WLESS_GLUE, ZBEE_MFG_WLESS_GLUE },
280     { ZBEE_MFG_CODE_ELSTER,     ZBEE_MFG_ELSTER },
281     { ZBEE_MFG_CODE_SMS_TEC,    ZBEE_MFG_SMS_TEC },
282     { ZBEE_MFG_CODE_ONSET,      ZBEE_MFG_ONSET },
283     { ZBEE_MFG_CODE_RIGA,       ZBEE_MFG_RIGA },
284     { ZBEE_MFG_CODE_ENERGATE,   ZBEE_MFG_ENERGATE },
285     { ZBEE_MFG_CODE_CONMED,     ZBEE_MFG_CONMED },
286     { ZBEE_MFG_CODE_POWERMAND,  ZBEE_MFG_POWERMAND },
287     { ZBEE_MFG_CODE_SCHNEIDER,  ZBEE_MFG_SCHNEIDER },
288     { ZBEE_MFG_CODE_EATON,      ZBEE_MFG_EATON },
289
290     { ZBEE_MFG_CODE_TELULAR,    ZBEE_MFG_TELULAR },
291     { ZBEE_MFG_CODE_DELPHI,     ZBEE_MFG_DELPHI },
292     { ZBEE_MFG_CODE_EPISENSOR,  ZBEE_MFG_EPISENSOR },
293     { ZBEE_MFG_CODE_LANDIS_GYR, ZBEE_MFG_LANDIS_GYR },
294     { ZBEE_MFG_CODE_KABA,       ZBEE_MFG_KABA },
295     { ZBEE_MFG_CODE_SHURE,      ZBEE_MFG_SHURE },
296     { ZBEE_MFG_CODE_COMVERGE,   ZBEE_MFG_COMVERGE },
297     /**/
298     { ZBEE_MFG_CODE_HIDALGO,    ZBEE_MFG_HIDALGO },
299     { ZBEE_MFG_CODE_AIR2APP,    ZBEE_MFG_AIR2APP },
300     { ZBEE_MFG_CODE_AMX,        ZBEE_MFG_AMX },
301     { ZBEE_MFG_CODE_EDMI,       ZBEE_MFG_EDMI },
302     { ZBEE_MFG_CODE_CYAN,       ZBEE_MFG_CYAN },
303     { ZBEE_MFG_CODE_SYS_SPA,    ZBEE_MFG_SYS_SPA },
304     { ZBEE_MFG_CODE_TELIT,      ZBEE_MFG_TELIT },
305
306     { ZBEE_MFG_CODE_KAGA,       ZBEE_MFG_KAGA },
307     { ZBEE_MFG_CODE_4_NOKS,     ZBEE_MFG_4_NOKS },
308     { 0, NULL }
309 };
310
311 /* ZCL Attribute Status Names */
312 static const value_string zbee_zcl_status_names[] = {
313     { ZBEE_ZCL_STAT_SUCCESS,                        "Success"},
314     { ZBEE_ZCL_STAT_FAILURE,                        "Failure"},
315
316     { ZBEE_ZCL_STAT_NOT_AUTHORIZED,                 "Not Authorized"},
317     { ZBEE_ZCL_STAT_RESERVED_FIELD_NOT_ZERO,        "Reserved Field Not Zero"},
318     { ZBEE_ZCL_STAT_MALFORMED_CMD,                  "Malformed Command"},
319     { ZBEE_ZCL_STAT_UNSUP_CLUSTER_CMD,              "Unsupported Cluster Command"},
320     { ZBEE_ZCL_STAT_UNSUP_GENERAL_CMD,              "Unsupported General Command"},
321     { ZBEE_ZCL_STAT_UNSUP_MFR_CLUSTER_CMD,          "Unsupported Manufacturer Cluster Command"},
322     { ZBEE_ZCL_STAT_UNSUP_MFR_GENERAL_CMD,          "Unsupported Manufacturer General Command"},
323     { ZBEE_ZCL_STAT_INVALID_FIELD,                  "Invalid Field"},
324     { ZBEE_ZCL_STAT_UNSUPPORTED_ATTR,               "Unsupported Attribute"},
325     { ZBEE_ZCL_STAT_INSUFFICIENT_SPACE,             "Insufficient Space"},
326     { ZBEE_ZCL_STAT_DUPLICATE_EXISTS,               "Duplicate Exists"},
327     { ZBEE_ZCL_STAT_NOT_FOUND,                      "Not Found"},
328     { ZBEE_ZCL_STAT_UNREPORTABLE_ATTR,              "Unreportable Attribute"},
329     { ZBEE_ZCL_STAT_INVALID_DATA_TYPE,              "Invalid Data Type"},
330     { ZBEE_ZCL_STAT_INVALID_SELECTOR,               "Invalid Selector"},
331     { ZBEE_ZCL_STAT_WRITE_ONLY,                     "Write Only"},
332     { ZBEE_ZCL_STAT_INCONSISTENT_STARTUP_STATE,     "Inconsistent Startup State"},
333     { ZBEE_ZCL_STAT_DEFINED_OUT_OF_BAND,            "Defined Out of Band"},
334     { ZBEE_ZCL_STAT_HARDWARE_FAILURE,               "Hardware Failure"},
335     { ZBEE_ZCL_STAT_SOFTWARE_FAILURE,               "Software Failure"},
336
337     { ZBEE_ZCL_STAT_CALIBRATION_ERROR,              "Calibration Error"},
338     { ZBEE_ZCL_STAT_INVALID_VALUE,                  "Invalid Value"},
339     { ZBEE_ZCL_STAT_READ_ONLY,                      "Read Only"},
340
341     { 0, NULL }
342 };
343
344 /* ZCL Attribute Data Names */
345 static const value_string zbee_zcl_data_type_names[] = {
346     { ZBEE_ZCL_NO_DATA,             "No Data" },
347     { ZBEE_ZCL_8_BIT_DATA,          "8-Bit Data" },
348     { ZBEE_ZCL_16_BIT_DATA,         "16-Bit Data" },
349     { ZBEE_ZCL_24_BIT_DATA,         "24-Bit Data" },
350     { ZBEE_ZCL_32_BIT_DATA,         "32-Bit Data" },
351     { ZBEE_ZCL_40_BIT_DATA,         "40-Bit Data" },
352     { ZBEE_ZCL_48_BIT_DATA,         "48-Bit Data" },
353     { ZBEE_ZCL_56_BIT_DATA,         "56-Bit Data" },
354     { ZBEE_ZCL_64_BIT_DATA,         "64-Bit Data" },
355
356     { ZBEE_ZCL_BOOLEAN,             "Boolean" },
357
358     { ZBEE_ZCL_8_BIT_BITMAP,        "8-Bit Bitmap" },
359     { ZBEE_ZCL_16_BIT_BITMAP,       "16-Bit Bitmap" },
360     { ZBEE_ZCL_24_BIT_BITMAP,       "24-Bit Bitmap" },
361     { ZBEE_ZCL_32_BIT_BITMAP,       "32-Bit Bitmap" },
362     { ZBEE_ZCL_40_BIT_BITMAP,       "40-Bit Bitmap" },
363     { ZBEE_ZCL_48_BIT_BITMAP,       "48-Bit Bitmap" },
364     { ZBEE_ZCL_56_BIT_BITMAP,       "56-Bit Bitmap" },
365     { ZBEE_ZCL_64_BIT_BITMAP,       "64-Bit Bitmap" },
366
367     { ZBEE_ZCL_8_BIT_UINT,          "8-Bit Unsigned Integer" },
368     { ZBEE_ZCL_16_BIT_UINT,         "16-Bit Unsigned Integer" },
369     { ZBEE_ZCL_24_BIT_UINT,         "24-Bit Unsigned Integer" },
370     { ZBEE_ZCL_32_BIT_UINT,         "32-Bit Unsigned Integer" },
371     { ZBEE_ZCL_40_BIT_UINT,         "40-Bit Unsigned Integer" },
372     { ZBEE_ZCL_48_BIT_UINT,         "48-Bit Unsigned Integer" },
373     { ZBEE_ZCL_56_BIT_UINT,         "56-Bit Unsigned Integer" },
374     { ZBEE_ZCL_64_BIT_UINT,         "64-Bit Unsigned Integer" },
375
376     { ZBEE_ZCL_8_BIT_INT,           "8-Bit Signed Integer" },
377     { ZBEE_ZCL_16_BIT_INT,          "16-Bit Signed Integer" },
378     { ZBEE_ZCL_24_BIT_INT,          "24-Bit Signed Integer" },
379     { ZBEE_ZCL_32_BIT_INT,          "32-Bit Signed Integer" },
380     { ZBEE_ZCL_40_BIT_INT,          "40-Bit Signed Integer" },
381     { ZBEE_ZCL_48_BIT_INT,          "48-Bit Signed Integer" },
382     { ZBEE_ZCL_56_BIT_INT,          "56-Bit Signed Integer" },
383     { ZBEE_ZCL_64_BIT_INT,          "64-Bit Signed Integer" },
384
385     { ZBEE_ZCL_8_BIT_ENUM,          "8-Bit Enumeration" },
386     { ZBEE_ZCL_16_BIT_ENUM,         "16-Bit Enumeration" },
387
388     { ZBEE_ZCL_SEMI_FLOAT,          "Semi-precision Floating Point" },
389     { ZBEE_ZCL_SINGLE_FLOAT,        "Single Precision Floating Point" },
390     { ZBEE_ZCL_DOUBLE_FLOAT,        "Double Precision Floating Point" },
391
392     { ZBEE_ZCL_OCTET_STRING,        "Octet String" },
393     { ZBEE_ZCL_CHAR_STRING,         "Character String" },
394     { ZBEE_ZCL_LONG_OCTET_STRING,   "Long Octet String" },
395     { ZBEE_ZCL_LONG_CHAR_STRING,    "Long Character String" },
396
397     { ZBEE_ZCL_ARRAY,               "Array" },
398     { ZBEE_ZCL_STRUCT,              "Structure" },
399
400     { ZBEE_ZCL_SET,                 "Set Collection" },
401     { ZBEE_ZCL_BAG,                 "Bag Collection" },
402
403     { ZBEE_ZCL_TIME,                "Time of Day" },
404     { ZBEE_ZCL_DATE,                "Date" },
405     { ZBEE_ZCL_UTC,                 "UTC Time" },
406
407     { ZBEE_ZCL_CLUSTER_ID,          "Cluster ID" },
408     { ZBEE_ZCL_ATTR_ID,             "Attribute ID" },
409     { ZBEE_ZCL_BACNET_OID,          "BACnet OID" },
410
411     { ZBEE_ZCL_IEEE_ADDR,           "IEEE Address" },
412     { ZBEE_ZCL_SECURITY_KEY,        "128-Bit Security Key" },
413
414     { ZBEE_ZCL_UNKNOWN,             "Unknown" },
415
416     { 0, NULL }
417 };
418
419 /* ZCL Attribute Short Data Names */
420 static const value_string zbee_zcl_short_data_type_names[] = {
421     { ZBEE_ZCL_NO_DATA,             "No Data" },
422     { ZBEE_ZCL_8_BIT_DATA,          "Data8" },
423     { ZBEE_ZCL_16_BIT_DATA,         "Data16" },
424     { ZBEE_ZCL_24_BIT_DATA,         "Data24" },
425     { ZBEE_ZCL_32_BIT_DATA,         "Data32" },
426     { ZBEE_ZCL_40_BIT_DATA,         "Data40" },
427     { ZBEE_ZCL_48_BIT_DATA,         "Data48" },
428     { ZBEE_ZCL_56_BIT_DATA,         "Data56" },
429     { ZBEE_ZCL_64_BIT_DATA,         "Data64" },
430
431     { ZBEE_ZCL_BOOLEAN,             "Boolean" },
432
433     { ZBEE_ZCL_8_BIT_BITMAP,        "Bit8" },
434     { ZBEE_ZCL_16_BIT_BITMAP,       "Bit16" },
435     { ZBEE_ZCL_24_BIT_BITMAP,       "Bit24" },
436     { ZBEE_ZCL_32_BIT_BITMAP,       "Bit32" },
437     { ZBEE_ZCL_40_BIT_BITMAP,       "Bit40" },
438     { ZBEE_ZCL_48_BIT_BITMAP,       "Bit48" },
439     { ZBEE_ZCL_56_BIT_BITMAP,       "Bit56" },
440     { ZBEE_ZCL_64_BIT_BITMAP,       "Bit64" },
441
442     { ZBEE_ZCL_8_BIT_UINT,          "Uint8" },
443     { ZBEE_ZCL_16_BIT_UINT,         "Uint16" },
444     { ZBEE_ZCL_24_BIT_UINT,         "Uint24" },
445     { ZBEE_ZCL_32_BIT_UINT,         "Uint32" },
446     { ZBEE_ZCL_40_BIT_UINT,         "Uint40" },
447     { ZBEE_ZCL_48_BIT_UINT,         "Uint48" },
448     { ZBEE_ZCL_56_BIT_UINT,         "Uint56" },
449     { ZBEE_ZCL_64_BIT_UINT,         "Uint64" },
450
451     { ZBEE_ZCL_8_BIT_INT,           "Int8" },
452     { ZBEE_ZCL_16_BIT_INT,          "Int16" },
453     { ZBEE_ZCL_24_BIT_INT,          "Int24" },
454     { ZBEE_ZCL_32_BIT_INT,          "Int32" },
455     { ZBEE_ZCL_40_BIT_INT,          "Int40" },
456     { ZBEE_ZCL_48_BIT_INT,          "Int48" },
457     { ZBEE_ZCL_56_BIT_INT,          "Int56" },
458     { ZBEE_ZCL_64_BIT_INT,          "Int64" },
459
460     { ZBEE_ZCL_8_BIT_ENUM,          "Enum8" },
461     { ZBEE_ZCL_16_BIT_ENUM,         "Enum16" },
462
463     { ZBEE_ZCL_SEMI_FLOAT,          "Semi Float" },
464     { ZBEE_ZCL_SINGLE_FLOAT,        "Float" },
465     { ZBEE_ZCL_DOUBLE_FLOAT,        "Double Float" },
466
467     { ZBEE_ZCL_OCTET_STRING,        "Oct String" },
468     { ZBEE_ZCL_CHAR_STRING,         "Char String" },
469     { ZBEE_ZCL_LONG_OCTET_STRING,   "Long Oct String" },
470     { ZBEE_ZCL_LONG_CHAR_STRING,    "Long Char String" },
471
472     { ZBEE_ZCL_ARRAY,               "Array" },
473     { ZBEE_ZCL_STRUCT,              "Structure" },
474
475     { ZBEE_ZCL_SET,                 "Set" },
476     { ZBEE_ZCL_BAG,                 "Bag" },
477
478     { ZBEE_ZCL_TIME,                "Time" },
479     { ZBEE_ZCL_DATE,                "Date" },
480     { ZBEE_ZCL_UTC,                 "UTC" },
481
482     { ZBEE_ZCL_CLUSTER_ID,          "Cluster" },
483     { ZBEE_ZCL_ATTR_ID,             "Attribute" },
484     { ZBEE_ZCL_BACNET_OID,          "BACnet" },
485
486     { ZBEE_ZCL_IEEE_ADDR,           "EUI" },
487     { ZBEE_ZCL_SECURITY_KEY,        "Key" },
488
489     { ZBEE_ZCL_UNKNOWN,             "Unknown" },
490
491     { 0, NULL }
492 };
493
494 /* ZCL Attribute English Weekday Names */
495 static const value_string zbee_zcl_wd_names[] = {
496     { 1,    "Monday" },
497     { 2,    "Tuesday" },
498     { 3,    "Wednesday" },
499     { 4,    "Thursday" },
500     { 5,    "Friday" },
501     { 6,    "Saturday" },
502     { 7,    "Sunday" },
503
504     { 0, NULL }
505 };
506
507 /* Attribute Direction Names */
508 static const value_string zbee_zcl_dir_names[] = {
509     { 0,    "Reported" },
510     { 1,    "Received" },
511
512     { 0, NULL }
513 };
514
515 /* Attribute Discovery Names */
516 static const value_string zbee_zcl_dis_names[] = {
517     { 0,    "Incomplete" },
518     { 1,    "Complete" },
519
520     { 0, NULL }
521 };
522
523 /*FUNCTION:------------------------------------------------------
524  *  NAME
525  *      dissect_zbee_zcl
526  *  DESCRIPTION
527  *      ZigBee Cluster Library dissector for wireshark.
528  *  PARAMETERS
529  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
530  *      packet_into *pinfo  - pointer to packet information fields
531  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
532  *  RETURNS
533  *      void
534  *---------------------------------------------------------------
535  */
536 static void dissect_zbee_zcl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
537 {
538     proto_tree  *zcl_tree = NULL;
539     proto_tree  *sub_tree = NULL;
540
541     proto_item  *proto_root = NULL;
542     proto_item  *ti;
543
544     zbee_zcl_packet packet;
545
546     guint8  fcf;
547     guint   offset = 0;
548
549     /* Init. */
550     memset(&packet, 0, sizeof(zbee_zcl_packet));
551
552     /* Create the protocol tree */
553     if ( tree ) {
554         proto_root = proto_tree_add_protocol_format(tree, proto_zbee_zcl, tvb, offset,
555                                 tvb_length(tvb), "ZigBee Cluster Library Frame");
556
557         zcl_tree = proto_item_add_subtree(proto_root, ett_zbee_zcl);
558     }
559
560     /* Clear info column */
561     col_clear(pinfo->cinfo, COL_INFO);
562
563     /* Get the FCF */
564     fcf = tvb_get_guint8(tvb, offset);
565     packet.frame_type = zbee_get_bit_field(fcf, ZBEE_ZCL_FCF_FRAME_TYPE);
566     packet.mfr_spec = zbee_get_bit_field(fcf, ZBEE_ZCL_FCF_MFR_SPEC);
567     packet.direction = zbee_get_bit_field(fcf, ZBEE_ZCL_FCF_DIRECTION);
568     packet.disable_default_resp = zbee_get_bit_field(fcf, ZBEE_ZCL_FCF_DISABLE_DEFAULT_RESP);
569
570     /* Display the FCF */
571     if ( tree ) {
572         /* Create the subtree */
573         ti = proto_tree_add_text(zcl_tree, tvb, offset, sizeof(guint8),
574                     "Frame Control Field: %s (0x%02x)",
575                     val_to_str(packet.frame_type, zbee_zcl_frame_types, "Unknown"), fcf);
576         sub_tree = proto_item_add_subtree(ti, ett_zbee_zcl_fcf);
577
578         /* Add the frame type */
579         proto_tree_add_uint(sub_tree, hf_zbee_zcl_fcf_frame_type, tvb, offset, sizeof(guint8),
580             fcf & ZBEE_ZCL_FCF_FRAME_TYPE);
581
582         /* Add the manufacturer specific, direction, and disable default response flags */
583         proto_tree_add_boolean(sub_tree, hf_zbee_zcl_fcf_mfr_spec, tvb, offset,
584                         sizeof(guint8), fcf & ZBEE_ZCL_FCF_MFR_SPEC);
585
586         proto_tree_add_boolean(sub_tree, hf_zbee_zcl_fcf_dir, tvb, offset, sizeof(guint8),
587             fcf & ZBEE_ZCL_FCF_DIRECTION);
588
589         proto_tree_add_boolean(sub_tree, hf_zbee_zcl_fcf_disable_default_resp, tvb, offset,
590                         sizeof(guint8), fcf & ZBEE_ZCL_FCF_DISABLE_DEFAULT_RESP);
591     }
592     offset += sizeof(guint8);
593
594     /* If the manufacturer code is present, get and display it. */
595     if (packet.mfr_spec) {
596         packet.mfr_code = tvb_get_letohs(tvb, offset);
597
598         if ( tree ) {
599             proto_tree_add_uint(zcl_tree, hf_zbee_zcl_mfr_code, tvb, offset, sizeof(guint16),
600                             packet.mfr_code);
601
602             proto_item_append_text(proto_root, ", Mfr: %s (0x%04x)",
603                             val_to_str(packet.mfr_code, zbee_mfr_code_names, "Unknown"),
604                             packet.mfr_code);
605         }
606         offset += sizeof(guint16);
607     }
608
609     /* Add the transaction sequence number to the tree */
610     packet.tran_seqno = tvb_get_guint8(tvb, offset);
611
612     if ( zcl_tree ) {
613         proto_tree_add_uint(zcl_tree, hf_zbee_zcl_tran_seqno, tvb, offset, sizeof(guint8),
614                         packet.tran_seqno);
615     }
616     offset += sizeof(guint8);
617
618     /* Display the command and sequence number on the proto root and info column. */
619     packet.cmd_id = tvb_get_guint8(tvb, offset);
620
621     /* Add command ID to the tree. */
622     if ( packet.frame_type == ZBEE_ZCL_FCF_PROFILE_WIDE ) {
623         if ( tree ) {
624             proto_item_append_text(proto_root, ", Command: %s, Seq: %u",
625                 val_to_str(packet.cmd_id, zbee_zcl_cmd_names, "Unknown Command"),
626                 packet.tran_seqno);
627         }
628
629         if ( check_col(pinfo->cinfo, COL_INFO) ) {
630             col_append_fstr(pinfo->cinfo, COL_INFO, "%s, Seq: %u",
631                 val_to_str(packet.cmd_id, zbee_zcl_cmd_names, "Unknown Command"),
632                 packet.tran_seqno);
633         }
634
635         if ( zcl_tree ) {
636             proto_tree_add_uint(zcl_tree, hf_zbee_zcl_cmd_id, tvb, offset, sizeof(guint8),
637                             packet.cmd_id);
638         }
639         offset += sizeof(guint8);
640     } else {
641         if ( tree ) {
642             proto_item_append_text(proto_root, ", Cluster-specific Command: 0x%02x, Seq: %u",
643                 packet.cmd_id, packet.tran_seqno);
644         }
645
646         if ( check_col(pinfo->cinfo, COL_INFO) ) {
647             col_append_fstr(pinfo->cinfo, COL_INFO, "Command: 0x%02x, Seq: %u",
648                 packet.cmd_id, packet.tran_seqno);
649         }
650
651         if ( zcl_tree ) {
652             proto_tree_add_uint(zcl_tree, hf_zbee_zcl_cs_cmd_id, tvb, offset, sizeof(guint8),
653                             packet.cmd_id);
654         }
655         offset += sizeof(guint8);
656
657         /* Don't decode cluster-specific commands */
658         zcl_dump_data(tvb, offset, pinfo, zcl_tree);
659         return;
660     }
661
662     /* Handle the contents of the command frame. */
663     switch ( packet.cmd_id ) {
664         case ZBEE_ZCL_CMD_READ_ATTR:
665             dissect_zcl_read_attr(tvb, pinfo, zcl_tree, &offset);
666             break;
667
668         case ZBEE_ZCL_CMD_READ_ATTR_RESP:
669             dissect_zcl_read_attr_resp(tvb, pinfo, zcl_tree, &offset);
670             break;
671
672         case ZBEE_ZCL_CMD_WRITE_ATTR:
673         case ZBEE_ZCL_CMD_WRITE_ATTR_UNDIVIDED:
674         case ZBEE_ZCL_CMD_WRITE_ATTR_NO_RESP:
675         case ZBEE_ZCL_CMD_REPORT_ATTR:
676             dissect_zcl_write_attr(tvb, pinfo, zcl_tree, &offset);
677             break;
678
679         case ZBEE_ZCL_CMD_WRITE_ATTR_RESP:
680             dissect_zcl_write_attr_resp(tvb, pinfo, zcl_tree, &offset);
681             break;
682
683         case ZBEE_ZCL_CMD_CONFIG_REPORT:
684             dissect_zcl_config_report(tvb, pinfo, zcl_tree, &offset);
685             break;
686
687         case ZBEE_ZCL_CMD_CONFIG_REPORT_RESP:
688             dissect_zcl_config_report_resp(tvb, pinfo, zcl_tree, &offset);
689             break;
690
691         case ZBEE_ZCL_CMD_READ_REPORT_CONFIG:
692             dissect_zcl_read_report_config(tvb, pinfo, zcl_tree, &offset);
693             break;
694
695         case ZBEE_ZCL_CMD_READ_REPORT_CONFIG_RESP:
696             dissect_zcl_read_report_config_resp(tvb, pinfo, zcl_tree, &offset);
697             break;
698
699         case ZBEE_ZCL_CMD_DEFAULT_RESP:
700             dissect_zcl_default_resp(tvb, pinfo, zcl_tree, &offset);
701             break;
702
703         case ZBEE_ZCL_CMD_DISCOVER_ATTR:
704             dissect_zcl_discover_attr(tvb, pinfo, zcl_tree, &offset);
705             break;
706
707         case ZBEE_ZCL_CMD_DISCOVER_ATTR_RESP:
708             dissect_zcl_discover_attr_resp(tvb, pinfo, zcl_tree, &offset);
709             break;
710
711         /* BUGBUG: don't dissect these for now */
712         case ZBEE_ZCL_CMD_READ_ATTR_STRUCT:
713         case ZBEE_ZCL_CMD_WRITE_ATTR_STRUCT:
714         case ZBEE_ZCL_CMD_WRITE_ATTR_STRUCT_RESP:
715         default:
716             zcl_dump_data(tvb, offset, pinfo, zcl_tree);
717             break;
718     } /* switch */
719
720     return;
721 } /* dissect_zbee_zcl */
722
723 /*FUNCTION:------------------------------------------------------
724  *  NAME
725  *      dissect_zcl_read_attr
726  *  DESCRIPTION
727  *      Helper dissector for ZCL Read Attributes and
728  *      Write Attributes No Response commands.
729  *  PARAMETERS
730  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
731  *      packet_info *pinfo  - pointer to packet information fields
732  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
733  *      offset              - pointer to offset from caller
734  *  RETURNS
735  *      guint               - offset after command dissection.
736  *---------------------------------------------------------------
737  */
738 static void dissect_zcl_read_attr(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint *offset)
739 {
740     guint tvb_len;
741
742     tvb_len = tvb_length(tvb);
743     while ( *offset < tvb_len ) {
744         /* Dissect the attribute identifier */
745         dissect_zcl_attr_id(tvb, tree, offset);
746     }
747
748     return;
749 } /* dissect_zcl_read_attr */
750
751 /*FUNCTION:------------------------------------------------------
752  *  NAME
753  *      dissect_zcl_read_attr_resp
754  *  DESCRIPTION
755  *      Helper dissector for ZCL Read Attributes Response command.
756  *  PARAMETERS
757  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
758  *      packet_info *pinfo  - pointer to packet information fields
759  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
760  *      offset              - pointer to offset from caller
761  *  RETURNS
762  *      guint               - offset after command dissection.
763  *---------------------------------------------------------------
764  */
765 static void dissect_zcl_read_attr_resp(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint *offset)
766 {
767     proto_item  *ti = NULL;
768     proto_tree  *sub_tree = NULL;
769
770     guint tvb_len;
771     guint i = 0;
772
773     tvb_len = tvb_length(tvb);
774     while ( *offset < tvb_len && i < ZBEE_ZCL_NUM_ATTR_ETT ) {
775
776         if ( tree ) {
777             /* Create subtree for attribute status field */
778             ti = proto_tree_add_text(tree, tvb, *offset, 0, "Status Record");
779             sub_tree = proto_item_add_subtree(ti, ett_zbee_zcl_attr[i]);
780             i++;
781         }
782
783         /* Dissect the attribute identifier */
784         dissect_zcl_attr_id(tvb, sub_tree, offset);
785
786         /* Dissect the status and optionally the data type and value */
787         if ( dissect_zcl_attr_uint8(tvb, sub_tree, offset, &hf_zbee_zcl_attr_status)
788             == ZBEE_ZCL_STAT_SUCCESS ) {
789
790             /* Dissect the attribute data type and data */
791             dissect_zcl_attr_data_type_val(tvb, sub_tree, offset);
792         }
793     }
794
795     return;
796 } /* dissect_zcl_read_attr_resp */
797
798 /*FUNCTION:------------------------------------------------------
799  *  NAME
800  *      dissect_zcl_write_attr
801  *  DESCRIPTION
802  *      Helper dissector for ZCL Report Attribute commands.
803  *  PARAMETERS
804  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
805  *      packet_info *pinfo  - pointer to packet information fields
806  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
807  *      offset              - pointer to offset from caller
808  *  RETURNS
809  *      guint               - offset after command dissection.
810  *---------------------------------------------------------------
811  */
812 static void dissect_zcl_write_attr(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint *offset)
813 {
814     proto_item  *ti = NULL;
815     proto_tree  *sub_tree = NULL;
816
817     guint tvb_len;
818     guint i = 0;
819
820     tvb_len = tvb_length(tvb);
821     while ( *offset < tvb_len && i < ZBEE_ZCL_NUM_ATTR_ETT ) {
822
823         if ( tree ) {
824             /* Create subtree for attribute status field */
825             ti = proto_tree_add_text(tree, tvb, *offset, 0, "Attribute Field");
826             sub_tree = proto_item_add_subtree(ti, ett_zbee_zcl_attr[i]);
827             i++;
828         }
829         /* Dissect the attribute identifier */
830         dissect_zcl_attr_id(tvb, sub_tree, offset);
831
832         /* Dissect the attribute data type and data */
833         dissect_zcl_attr_data_type_val(tvb, sub_tree, offset);
834     }
835
836     return;
837 } /* dissect_zcl_write_attr */
838
839 /*FUNCTION:------------------------------------------------------
840  *  NAME
841  *      dissect_zcl_write_attr_resp
842  *  DESCRIPTION
843  *      Helper dissector for ZCL Write Attribute Response command.
844  *  PARAMETERS
845  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
846  *      packet_info *pinfo  - pointer to packet information fields
847  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
848  *      offset              - pointer to offset from caller
849  *  RETURNS
850  *      guint               - offset after command dissection.
851  *---------------------------------------------------------------
852  */
853 static void dissect_zcl_write_attr_resp(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint *offset)
854 {
855     proto_item  *ti = NULL;
856     proto_tree  *sub_tree = NULL;
857
858     guint tvb_len;
859     guint i = 0;
860
861     tvb_len = tvb_length(tvb);
862     while ( *offset < tvb_len && i < ZBEE_ZCL_NUM_ATTR_ETT ) {
863
864         if ( tree ) {
865             /* Create subtree for attribute status field */
866             ti = proto_tree_add_text(tree, tvb, *offset, 0, "Status Record");
867             sub_tree = proto_item_add_subtree(ti, ett_zbee_zcl_attr[i]);
868             i++;
869         }
870
871         /* Dissect the status */
872         if ( dissect_zcl_attr_uint8(tvb, sub_tree, offset, &hf_zbee_zcl_attr_status) !=
873             ZBEE_ZCL_STAT_SUCCESS ) {
874
875             /* Dissect the failed attribute identifier */
876             dissect_zcl_attr_id(tvb, sub_tree, offset);
877         }
878     }
879
880     return;
881 } /* dissect_zcl_write_attr_resp */
882
883 /*FUNCTION:------------------------------------------------------
884  *  NAME
885  *      dissect_zcl_read_report_config_resp
886  *  DESCRIPTION
887  *      Helper dissector for ZCL Report Attribute commands.
888  *  PARAMETERS
889  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
890  *      packet_info *pinfo  - pointer to packet information fields
891  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
892  *      offset              - pointer to offset from caller
893  *---------------------------------------------------------------
894  */
895 static void dissect_zcl_read_report_config_resp(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree,
896                 guint *offset)
897 {
898     proto_item  *ti = NULL;
899     proto_tree  *sub_tree = NULL;
900
901     guint tvb_len;
902     guint i = 0;
903     guint data_type;
904     guint attr_status;
905     guint attr_dir;
906
907     tvb_len = tvb_length(tvb);
908     while ( *offset < tvb_len && i < ZBEE_ZCL_NUM_ATTR_ETT ) {
909
910         if ( tree ) {
911             /* Create subtree for attribute status field */
912             ti = proto_tree_add_text(tree, tvb, *offset, 3, "Reporting Configuration Record");
913             sub_tree = proto_item_add_subtree(ti, ett_zbee_zcl_attr[i]);
914             i++;
915         }
916         /* Dissect the status */
917         attr_status = dissect_zcl_attr_uint8(tvb, sub_tree, offset, &hf_zbee_zcl_attr_status);
918
919         /* Dissect the direction and any reported configuration */
920         attr_dir = dissect_zcl_attr_uint8(tvb, sub_tree, offset, &hf_zbee_zcl_attr_dir);
921
922         /* Dissect the attribute id */
923         dissect_zcl_attr_id(tvb, sub_tree, offset);
924
925         if ( attr_status == ZBEE_ZCL_STAT_SUCCESS ) {
926             if ( attr_dir == ZBEE_ZCL_DIR_REPORTED ) {
927
928                 /* Dissect the attribute data type */
929                 data_type = dissect_zcl_attr_uint8(tvb, sub_tree, offset,
930                         &hf_zbee_zcl_attr_data_type);
931
932                 /* Dissect minimum reporting interval */
933                 dissect_zcl_attr_uint16(tvb, sub_tree, offset, &hf_zbee_zcl_attr_minint);
934
935                 /* Dissect maximum reporting interval */
936                 dissect_zcl_attr_uint16(tvb, sub_tree, offset, &hf_zbee_zcl_attr_maxint);
937
938                 if ( IS_ANALOG_SUBTYPE(data_type) ) {
939                     /* Dissect reportable change */
940                     dissect_zcl_attr_data(tvb, sub_tree, offset, data_type);
941                 }
942
943             } else {
944                 /* Dissect timeout period */
945                 dissect_zcl_attr_uint16(tvb, sub_tree, offset, &hf_zbee_zcl_attr_timeout);
946             }
947         }
948     }
949
950     return;
951 } /* dissect_zcl_read_report_config_resp */
952
953 /*FUNCTION:------------------------------------------------------
954  *  NAME
955  *      dissect_zcl_config_report
956  *  DESCRIPTION
957  *      Helper dissector for ZCL Report Attribute commands.
958  *  PARAMETERS
959  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
960  *      packet_info *pinfo  - pointer to packet information fields
961  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
962  *      offset              - pointer to offset from caller
963  *---------------------------------------------------------------
964  */
965 static void dissect_zcl_config_report(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint *offset)
966 {
967     proto_item  *ti = NULL;
968     proto_tree  *sub_tree = NULL;
969
970     guint tvb_len;
971     guint i = 0;
972     guint data_type;
973
974     tvb_len = tvb_length(tvb);
975     while ( *offset < tvb_len && i < ZBEE_ZCL_NUM_ATTR_ETT ) {
976
977         if ( tree ) {
978             /* Create subtree for attribute status field */
979             ti = proto_tree_add_text(tree, tvb, *offset, 3, "Reporting Configuration Record");
980             sub_tree = proto_item_add_subtree(ti, ett_zbee_zcl_attr[i]);
981             i++;
982         }
983
984         /* Dissect the direction and any reported configuration */
985         if ( dissect_zcl_attr_uint8(tvb, sub_tree, offset, &hf_zbee_zcl_attr_dir)
986                         == ZBEE_ZCL_DIR_REPORTED ) {
987
988             /* Dissect the attribute id */
989             dissect_zcl_attr_id(tvb, sub_tree, offset);
990
991             /* Dissect the attribute data type */
992             data_type = dissect_zcl_attr_uint8(tvb, sub_tree, offset, &hf_zbee_zcl_attr_data_type);
993
994             /* Dissect minimum reporting interval */
995             dissect_zcl_attr_uint16(tvb, sub_tree, offset, &hf_zbee_zcl_attr_minint);
996
997             /* Dissect maximum reporting interval */
998             dissect_zcl_attr_uint16(tvb, sub_tree, offset, &hf_zbee_zcl_attr_maxint);
999
1000             if ( IS_ANALOG_SUBTYPE(data_type) ) {
1001                 /* Dissect reportable change */
1002                 dissect_zcl_attr_data(tvb, sub_tree, offset, data_type);
1003             }
1004         } else {
1005
1006             /* Dissect the attribute id */
1007             dissect_zcl_attr_id(tvb, sub_tree, offset);
1008
1009             /* Dissect timeout period */
1010             dissect_zcl_attr_uint16(tvb, sub_tree, offset, &hf_zbee_zcl_attr_timeout);
1011         }
1012     }
1013
1014     return;
1015 } /* dissect_zcl_config_report */
1016
1017 /*FUNCTION:------------------------------------------------------
1018  *  NAME
1019  *      dissect_zcl_config_report_resp
1020  *  DESCRIPTION
1021  *      Helper dissector for ZCL Report Attribute commands.
1022  *  PARAMETERS
1023  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
1024  *      packet_info *pinfo  - pointer to packet information fields
1025  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
1026  *      offset              - pointer to offset from caller
1027  *  RETURNS
1028  *      guint               - offset after command dissection.
1029  *---------------------------------------------------------------
1030  */
1031 static void dissect_zcl_config_report_resp(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree,
1032                 guint *offset)
1033 {
1034     proto_item  *ti = NULL;
1035     proto_tree  *sub_tree = NULL;
1036
1037     guint tvb_len;
1038     guint i = 0;
1039
1040     tvb_len = tvb_length(tvb);
1041     while ( *offset < tvb_len && i < ZBEE_ZCL_NUM_ATTR_ETT ) {
1042
1043         if ( tree ) {
1044             /* Create subtree for attribute status field */
1045             ti = proto_tree_add_text(tree, tvb, *offset, 3, "Attribute Status Record");
1046             sub_tree = proto_item_add_subtree(ti, ett_zbee_zcl_attr[i]);
1047             i++;
1048         }
1049
1050         /* Dissect the status */
1051         if ( dissect_zcl_attr_uint8(tvb, sub_tree, offset, &hf_zbee_zcl_attr_status) !=
1052             ZBEE_ZCL_STAT_SUCCESS ) {
1053                 /* Dissect the direction on error */
1054                 dissect_zcl_attr_uint8(tvb, sub_tree, offset, &hf_zbee_zcl_attr_dir);
1055
1056                 /* Dissect the attribute identifier on error */
1057                 dissect_zcl_attr_id(tvb, sub_tree, offset);
1058         }
1059     }
1060
1061     return;
1062 } /* dissect_zcl_config_report_resp */
1063
1064 /*FUNCTION:------------------------------------------------------
1065  *  NAME
1066  *      dissect_zcl_read_report_config
1067  *  DESCRIPTION
1068  *      Helper dissector for ZCL Read Report Configuration command.
1069  *  PARAMETERS
1070  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
1071  *      packet_info *pinfo  - pointer to packet information fields
1072  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
1073  *      offset              - pointer to offset from caller
1074  *  RETURNS
1075  *      guint               - offset after command dissection.
1076  *---------------------------------------------------------------
1077  */
1078 static void dissect_zcl_read_report_config(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree,
1079                 guint *offset)
1080 {
1081     proto_item  *ti = NULL;
1082     proto_tree  *sub_tree = NULL;
1083
1084     guint tvb_len;
1085     guint i = 0;
1086
1087     tvb_len = tvb_length(tvb);
1088     while ( *offset < tvb_len && i < ZBEE_ZCL_NUM_ATTR_ETT ) {
1089
1090         if ( tree ) {
1091             /* Create subtree for attribute status field */
1092             ti = proto_tree_add_text(tree, tvb, *offset, 3, "Attribute Status Record");
1093             sub_tree = proto_item_add_subtree(ti, ett_zbee_zcl_attr[i]);
1094             i++;
1095         }
1096
1097         /* Dissect the direction */
1098         dissect_zcl_attr_uint8(tvb, sub_tree, offset, &hf_zbee_zcl_attr_dir);
1099
1100         /* Dissect the attribute identifier */
1101         dissect_zcl_attr_id(tvb, sub_tree, offset);
1102     }
1103
1104     return;
1105 } /* dissect_zcl_read_report_config */
1106
1107 /*FUNCTION:------------------------------------------------------
1108  *  NAME
1109  *      dissect_zcl_default_resp
1110  *  DESCRIPTION
1111  *      Helper dissector for ZCL Default Response command.
1112  *  PARAMETERS
1113  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
1114  *      packet_info *pinfo  - pointer to packet information fields
1115  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
1116  *      offset              - pointer to offset from caller
1117  *  RETURNS
1118  *      void
1119  *---------------------------------------------------------------
1120  */
1121 static void dissect_zcl_default_resp(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint *offset)
1122 {
1123     guint cmd_id;
1124
1125     /* Dissect the command identifier */
1126     cmd_id = tvb_get_guint8(tvb, *offset);
1127
1128     if ( tree ) {
1129         proto_tree_add_uint(tree, hf_zbee_zcl_cmd_id, tvb, *offset, sizeof(guint8), cmd_id);
1130
1131     }
1132     *offset += sizeof(guint8);
1133
1134     /* Dissect the status */
1135     dissect_zcl_attr_uint8(tvb, tree, offset, &hf_zbee_zcl_attr_status);
1136
1137     return;
1138 } /* dissect_zcl_default_resp */
1139
1140 /*FUNCTION:------------------------------------------------------
1141  *  NAME
1142  *      dissect_zcl_discover_attr
1143  *  DESCRIPTION
1144  *      Helper dissector for ZCL Discover Attributes command.
1145  *  PARAMETERS
1146  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
1147  *      packet_info *pinfo  - pointer to packet information fields
1148  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
1149  *      offset              - pointer to offset from caller
1150  *  RETURNS
1151  *      void
1152  *---------------------------------------------------------------
1153  */
1154 static void dissect_zcl_discover_attr(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, guint *offset)
1155 {
1156     /* Dissect the starting attribute identifier */
1157     dissect_zcl_attr_uint16(tvb, tree, offset, &hf_zbee_zcl_attr_start);
1158
1159     /* Dissect the number of maximum attribute identifiers */
1160     dissect_zcl_attr_uint8(tvb, tree, offset, &hf_zbee_zcl_attr_maxnum);
1161
1162     return;
1163 } /* dissect_zcl_discover_attr */
1164
1165
1166 /*FUNCTION:------------------------------------------------------
1167  *  NAME
1168  *      dissect_zcl_discover_attr_resp
1169  *  DESCRIPTION
1170  *      Helper dissector for ZCL Discover Attributes command.
1171  *  PARAMETERS
1172  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
1173  *      packet_info *pinfo  - pointer to packet information fields
1174  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
1175  *      offset              - pointer to offset from caller
1176  *  RETURNS
1177  *      void
1178  *---------------------------------------------------------------
1179  */
1180 static void dissect_zcl_discover_attr_resp(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree,
1181                 guint *offset)
1182 {
1183     proto_item  *ti = NULL;
1184     proto_tree  *sub_tree = NULL;
1185
1186     guint tvb_len;
1187     guint i = 0;
1188
1189     dissect_zcl_attr_uint8(tvb, sub_tree, offset, &hf_zbee_zcl_attr_dis);
1190
1191     tvb_len = tvb_length(tvb);
1192     while ( *offset < tvb_len && i < ZBEE_ZCL_NUM_ATTR_ETT ) {
1193
1194         if ( tree ) {
1195             /* Create subtree for attribute status field */
1196             ti = proto_tree_add_text(tree, tvb, *offset, 3, "Attribute Status Record");
1197             sub_tree = proto_item_add_subtree(ti, ett_zbee_zcl_attr[i]);
1198             i++;
1199
1200             /* Dissect the attribute identifier */
1201             dissect_zcl_attr_id(tvb, sub_tree, offset);
1202
1203             /* Dissect the number of maximum attribute identifiers */
1204             dissect_zcl_attr_uint8(tvb, sub_tree, offset, &hf_zbee_zcl_attr_data_type);
1205         }
1206     }
1207
1208     return;
1209 } /* dissect_zcl_discover_attr_resp */
1210
1211 #if 0
1212 /*FUNCTION:------------------------------------------------------
1213  *  NAME
1214  *      dissect_zcl_attr_data_type
1215  *  DESCRIPTION
1216  *      Helper dissector for ZCL Attribute commands.
1217  *  PARAMETERS
1218  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
1219  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
1220  *      offset              - offset into the tvb to begin dissection.
1221  *  RETURNS
1222  *      guint               - attribute data type
1223  *---------------------------------------------------------------
1224  */
1225 static guint dissect_zcl_attr_data_type(tvbuff_t *tvb, proto_tree *tree, guint *offset)
1226 {
1227     guint attr_data_type;
1228
1229     /* Dissect attribute data type */
1230     attr_data_type = tvb_get_guint8(tvb, *offset);
1231
1232     if ( tree ) {
1233         proto_tree_add_uint(tree, hf_zbee_zcl_attr_data_type, tvb, *offset, sizeof(guint8),
1234                     attr_data_type);
1235     }
1236     *offset += sizeof(guint8);
1237
1238     return attr_data_type;
1239 } /* dissect_zcl_attr_data_type */
1240 #endif
1241
1242 /*FUNCTION:------------------------------------------------------
1243  *  NAME
1244  *      dissect_zcl_attr_id
1245  *  DESCRIPTION
1246  *      Dissects Attribute ID field. This could be done with the
1247  *      dissect_zcl_attr_uint16 function, but we leave it separate
1248  *      so we can dissect the attr_id with a hash in the future.
1249  *  PARAMETERS
1250  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
1251  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
1252  *      offset              - offset into the tvb to begin dissection.
1253  *  RETURNS
1254  *      void
1255  *---------------------------------------------------------------
1256  */
1257 static void dissect_zcl_attr_id(tvbuff_t *tvb, proto_tree *tree, guint *offset)
1258 {
1259     guint16 attr_id;
1260
1261     attr_id = tvb_get_letohs(tvb, *offset);
1262
1263     /* add it to tree */
1264     if ( tree ) {
1265         /* Add the identifier */
1266         proto_tree_add_uint(tree, hf_zbee_zcl_attr_id, tvb, *offset, sizeof(guint16),
1267                         attr_id);
1268     }
1269     *offset += sizeof(guint16);
1270
1271     return;
1272 } /* dissect_zcl_attr_id */
1273
1274 /*FUNCTION:------------------------------------------------------
1275  *  NAME
1276  *      dissect_zcl_attr_data_type_val
1277  *  DESCRIPTION
1278  *      Helper dissector for ZCL Attribute commands.
1279  *  PARAMETERS
1280  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
1281  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
1282  *      offset              - offset into the tvb to begin dissection.
1283  *  RETURNS
1284  *      void
1285  *---------------------------------------------------------------
1286  */
1287 static void dissect_zcl_attr_data_type_val(tvbuff_t *tvb, proto_tree *tree, guint *offset)
1288 {
1289     dissect_zcl_attr_data(tvb, tree, offset,
1290             dissect_zcl_attr_uint8(tvb, tree, offset, &hf_zbee_zcl_attr_data_type) );
1291
1292     return;
1293 } /* dissect_zcl_attr_data_type_val */
1294
1295 /*FUNCTION:------------------------------------------------------
1296  *  NAME
1297  *      dissect_zcl_attr_data
1298  *  DESCRIPTION
1299  *      Dissects the various types of ZCL attribute data.
1300  *  PARAMETERS
1301  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
1302  *      packet_info *pinfo  - pointer to packet information fields
1303  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
1304  *      offset              - offset into the tvb to begin dissection.
1305  *      data_type           - the type of ZCL data in the packet buffer
1306  *  RETURNS
1307  *      void
1308  *---------------------------------------------------------------
1309  */
1310 static void dissect_zcl_attr_data(tvbuff_t *tvb, proto_tree *tree, guint *offset, guint data_type)
1311 {
1312     guint attr_uint;
1313     guint64 attr_uint64;
1314     gint attr_int;
1315     gint64 attr_int64;
1316     guint8 *attr_string;
1317     guint8 attr_uint8[4];
1318     gfloat attr_float;
1319     gdouble attr_double;
1320     nstime_t attr_time;
1321
1322     attr_uint = 0;
1323     attr_uint64 = 0;
1324     attr_int = 0;
1325     attr_int64 = 0;
1326
1327     /* Dissect attribute data type and data */
1328     switch ( data_type ) {
1329         case ZBEE_ZCL_NO_DATA:
1330             break;
1331
1332         case ZBEE_ZCL_8_BIT_DATA:
1333         case ZBEE_ZCL_8_BIT_BITMAP:
1334             dissect_zcl_attr_bytes(tvb, tree, offset, 1);
1335             break;
1336
1337         case ZBEE_ZCL_8_BIT_UINT:
1338         case ZBEE_ZCL_8_BIT_ENUM:
1339
1340             /* Display 8 bit unsigned integer */
1341             attr_uint = tvb_get_guint8(tvb, *offset);
1342
1343             if ( tree ) {
1344                 proto_item_append_text(tree, ", %s: %u",
1345                     val_to_str(data_type, zbee_zcl_short_data_type_names, "Reserved"), attr_uint);
1346
1347                 proto_tree_add_uint(tree, hf_zbee_zcl_attr_uint8, tvb, *offset, sizeof(guint8),
1348                             attr_uint);
1349             }
1350
1351             *offset += sizeof(guint8);
1352             break;
1353
1354         case ZBEE_ZCL_8_BIT_INT:
1355             /* Display 8 bit integer */
1356
1357             attr_int = (gint8)tvb_get_guint8(tvb, *offset);
1358
1359             if ( tree ) {
1360                 proto_item_append_text(tree, ", %s: %-d",
1361                     val_to_str(data_type, zbee_zcl_short_data_type_names, "Reserved"), attr_int);
1362
1363                 proto_tree_add_int(tree, hf_zbee_zcl_attr_int8, tvb, *offset, sizeof(gint8),
1364                             (gint)attr_int);
1365             }
1366
1367             *offset += sizeof(gint8);
1368             break;
1369
1370         case ZBEE_ZCL_BOOLEAN:
1371
1372             attr_uint = tvb_get_guint8(tvb, *offset);
1373
1374             if ( tree ) {
1375                 proto_item_append_text(tree, ", %s: 0x%02x",
1376                     val_to_str(data_type, zbee_zcl_short_data_type_names, "Reserved"), attr_uint);
1377
1378                 proto_tree_add_uint(tree, hf_zbee_zcl_attr_boolean, tvb, *offset, sizeof(guint8),
1379                             attr_uint);
1380             }
1381             *offset += sizeof(guint8);
1382             break;
1383
1384         case ZBEE_ZCL_16_BIT_DATA:
1385         case ZBEE_ZCL_16_BIT_BITMAP:
1386             dissect_zcl_attr_bytes(tvb, tree, offset, 2);
1387             break;
1388
1389         case ZBEE_ZCL_16_BIT_UINT:
1390         case ZBEE_ZCL_16_BIT_ENUM:
1391             /* Display 16 bit unsigned integer */
1392
1393             attr_uint = tvb_get_letohs(tvb, *offset);
1394
1395             if ( tree ) {
1396                 proto_item_append_text(tree, ", %s: %u",
1397                     val_to_str(data_type, zbee_zcl_short_data_type_names, "Reserved"), attr_uint);
1398
1399                 proto_tree_add_uint(tree, hf_zbee_zcl_attr_uint16, tvb, *offset, sizeof(guint16),
1400                             attr_uint);
1401             }
1402             *offset += sizeof(guint16);
1403             break;
1404
1405         case ZBEE_ZCL_16_BIT_INT:
1406             /* Display 16 bit integer */
1407
1408             attr_int = (gint16)tvb_get_letohs(tvb, *offset);
1409
1410             if ( tree ) {
1411                 proto_item_append_text(tree, ", %s: %-d",
1412                     val_to_str(data_type, zbee_zcl_short_data_type_names, "Reserved"), attr_int);
1413
1414                 proto_tree_add_int(tree, hf_zbee_zcl_attr_int16, tvb, *offset, sizeof(gint16),
1415                             attr_int);
1416             }
1417             *offset += sizeof(gint16);
1418             break;
1419
1420         case ZBEE_ZCL_24_BIT_DATA:
1421         case ZBEE_ZCL_24_BIT_BITMAP:
1422             dissect_zcl_attr_bytes(tvb, tree, offset, 3);
1423             break;
1424
1425         case ZBEE_ZCL_24_BIT_UINT:
1426             /* Display 24 bit unsigned integer */
1427
1428             attr_uint = tvb_get_letoh24(tvb, *offset);
1429
1430             if ( tree ) {
1431                 proto_item_append_text(tree, ", %s: %u",
1432                     val_to_str(data_type, zbee_zcl_short_data_type_names, "Reserved"), attr_uint);
1433
1434                 proto_tree_add_uint(tree, hf_zbee_zcl_attr_uint24, tvb, *offset, 3,
1435                             attr_uint);
1436             }
1437             *offset += 3;
1438             break;
1439
1440         case ZBEE_ZCL_24_BIT_INT:
1441             /* Display 24 bit signed integer */
1442
1443             attr_int = (gint)tvb_get_letoh24(tvb, *offset);
1444             /* sign extend into int32 */
1445             if (attr_int & INT24_SIGN_BITS) attr_int |= INT24_SIGN_BITS;
1446
1447             if ( tree ) {
1448                 proto_item_append_text(tree, ", %s: %-d",
1449                     val_to_str(data_type, zbee_zcl_short_data_type_names, "Reserved"), attr_int);
1450
1451                 proto_tree_add_int(tree, hf_zbee_zcl_attr_int24, tvb, *offset, 3,
1452                             attr_int);
1453             }
1454             *offset += 3;
1455             break;
1456
1457         case ZBEE_ZCL_32_BIT_DATA:
1458         case ZBEE_ZCL_32_BIT_BITMAP:
1459             dissect_zcl_attr_bytes(tvb, tree, offset, 4);
1460             break;
1461
1462         case ZBEE_ZCL_32_BIT_UINT:
1463             /* Display 32 bit unsigned integer */
1464
1465             attr_uint = tvb_get_letohl(tvb, *offset);
1466
1467             if ( tree ) {
1468                 proto_item_append_text(tree, ", %s: %u",
1469                     val_to_str(data_type, zbee_zcl_short_data_type_names, "Reserved"), attr_uint);
1470
1471                 proto_tree_add_uint(tree, hf_zbee_zcl_attr_uint32, tvb, *offset, sizeof(guint),
1472                             attr_uint);
1473             }
1474             *offset += sizeof(guint);
1475             break;
1476
1477         case ZBEE_ZCL_32_BIT_INT:
1478             /* Display 32 bit signed integer */
1479
1480             attr_int = (gint)tvb_get_letohl(tvb, *offset);
1481
1482             if ( tree ) {
1483                 proto_item_append_text(tree, ", %s: %-d",
1484                     val_to_str(data_type, zbee_zcl_short_data_type_names, "Reserved"), attr_int);
1485
1486                 proto_tree_add_int(tree, hf_zbee_zcl_attr_int32, tvb, *offset, sizeof(gint),
1487                             attr_int);
1488             }
1489             *offset += sizeof(gint);
1490             break;
1491
1492         case ZBEE_ZCL_40_BIT_DATA:
1493         case ZBEE_ZCL_40_BIT_BITMAP:
1494             dissect_zcl_attr_bytes(tvb, tree, offset, 5);
1495             break;
1496
1497         case ZBEE_ZCL_40_BIT_UINT:
1498             dissect_zcl_big_int(tvb, tree, offset, 5, FALSE);
1499             break;
1500
1501         case ZBEE_ZCL_40_BIT_INT:
1502             dissect_zcl_big_int(tvb, tree, offset, 5, TRUE);
1503             break;
1504
1505         case ZBEE_ZCL_48_BIT_DATA:
1506         case ZBEE_ZCL_48_BIT_BITMAP:
1507             dissect_zcl_attr_bytes(tvb, tree, offset, 6);
1508             break;
1509
1510         case ZBEE_ZCL_48_BIT_UINT:
1511             dissect_zcl_big_int(tvb, tree, offset, 6, FALSE);
1512             break;
1513
1514         case ZBEE_ZCL_48_BIT_INT:
1515             dissect_zcl_big_int(tvb, tree, offset, 6, TRUE);
1516             break;
1517
1518         case ZBEE_ZCL_56_BIT_DATA:
1519         case ZBEE_ZCL_56_BIT_BITMAP:
1520             dissect_zcl_attr_bytes(tvb, tree, offset, 7);
1521             break;
1522
1523         case ZBEE_ZCL_56_BIT_UINT:
1524             dissect_zcl_big_int(tvb, tree, offset, 7, FALSE);
1525             break;
1526
1527         case ZBEE_ZCL_56_BIT_INT:
1528             dissect_zcl_big_int(tvb, tree, offset, 7, TRUE);
1529             break;
1530
1531         case ZBEE_ZCL_64_BIT_DATA:
1532         case ZBEE_ZCL_64_BIT_BITMAP:
1533             dissect_zcl_attr_bytes(tvb, tree, offset, 8);
1534             break;
1535
1536         case ZBEE_ZCL_64_BIT_UINT:
1537             dissect_zcl_big_int(tvb, tree, offset, 8, FALSE);
1538             break;
1539
1540         case ZBEE_ZCL_64_BIT_INT:
1541             dissect_zcl_big_int(tvb, tree, offset, 8, TRUE);
1542             break;
1543
1544         case ZBEE_ZCL_SEMI_FLOAT:
1545             /* BUGBUG */
1546             dissect_zcl_attr_bytes(tvb, tree, offset, 2);
1547             break;
1548
1549         case ZBEE_ZCL_SINGLE_FLOAT:
1550             attr_float = tvb_get_letohieee_float(tvb, *offset);
1551
1552             if ( tree ) {
1553                 proto_item_append_text(tree, ", %s: %g",
1554                     val_to_str(data_type, zbee_zcl_short_data_type_names, "Reserved"), attr_float);
1555
1556                 proto_tree_add_item(tree, hf_zbee_zcl_attr_float, tvb, *offset, 4, TRUE);
1557             }
1558             *offset += 4;
1559             break;
1560
1561         case ZBEE_ZCL_DOUBLE_FLOAT:
1562             attr_double = tvb_get_letohieee_double(tvb, *offset);
1563
1564             if ( tree ) {
1565                 proto_item_append_text(tree, ", Double: %lg", attr_double);
1566
1567                 proto_tree_add_item(tree, hf_zbee_zcl_attr_double, tvb, *offset, 8, TRUE);
1568             }
1569             *offset += 8;
1570             break;
1571
1572         case ZBEE_ZCL_OCTET_STRING:
1573
1574             /* Display octet string */
1575             attr_uint = tvb_get_guint8(tvb, *offset); /* string length */
1576             if (attr_uint == ZBEE_ZCL_INVALID_STR_LENGTH) attr_uint = 0;
1577
1578             if ( tree ) {
1579                 proto_tree_add_uint(tree, hf_zbee_zcl_attr_str_len, tvb, *offset, sizeof(guint8),
1580                             attr_uint);
1581             }
1582             *offset += sizeof(guint8);
1583
1584             attr_string = tvb_bytes_to_str_punct(tvb, *offset, attr_uint, ':');
1585             if ( tree ) {
1586                 proto_item_append_text(tree, ", Octets: %s", attr_string);
1587
1588                 proto_tree_add_string(tree, hf_zbee_zcl_attr_ostr, tvb, *offset, attr_uint,
1589                                 attr_string);
1590             }
1591             *offset += attr_uint;
1592             break;
1593
1594         case ZBEE_ZCL_CHAR_STRING:
1595
1596             /* Display string */
1597             attr_uint = tvb_get_guint8(tvb, *offset); /* string length */
1598             if (attr_uint == ZBEE_ZCL_INVALID_STR_LENGTH) attr_uint = 0;
1599
1600             if ( tree ) {
1601                 proto_tree_add_uint(tree, hf_zbee_zcl_attr_str_len, tvb, *offset, sizeof(guint8),
1602                             attr_uint);
1603             }
1604             *offset += sizeof(guint8);
1605
1606             attr_string = tvb_get_ephemeral_string(tvb, *offset, attr_uint);
1607             if ( tree ) {
1608                 proto_item_append_text(tree, ", String: %s", attr_string);
1609
1610                 proto_tree_add_string(tree, hf_zbee_zcl_attr_str, tvb, *offset, attr_uint,
1611                                 attr_string);
1612             }
1613             *offset += attr_uint;
1614             break;
1615
1616         case ZBEE_ZCL_LONG_OCTET_STRING:
1617
1618             /* Display long octet string */
1619             attr_uint = tvb_get_letohs(tvb, *offset); /* string length */
1620             if (attr_uint == ZBEE_ZCL_INVALID_LONG_STR_LENGTH) attr_uint = 0;
1621
1622             if ( tree ) {
1623                 proto_tree_add_uint(tree, hf_zbee_zcl_attr_str_len, tvb, *offset, sizeof(guint16),
1624                             attr_uint);
1625             }
1626             *offset += sizeof(guint16);
1627
1628             attr_string = tvb_bytes_to_str_punct(tvb, *offset, attr_uint, ':');
1629             if ( tree ) {
1630                 proto_item_append_text(tree, ", Octets: %s", attr_string);
1631
1632                 proto_tree_add_string(tree, hf_zbee_zcl_attr_ostr, tvb, *offset, attr_uint,
1633                                 attr_string);
1634             }
1635             *offset += attr_uint;
1636             break;
1637
1638         case ZBEE_ZCL_LONG_CHAR_STRING:
1639
1640             /* Display long string */
1641             attr_uint = tvb_get_letohs(tvb, *offset); /* string length */
1642             if (attr_uint == ZBEE_ZCL_INVALID_LONG_STR_LENGTH) attr_uint = 0;
1643
1644             if ( tree ) {
1645                 proto_tree_add_uint(tree, hf_zbee_zcl_attr_str_len, tvb, *offset, sizeof(guint16),
1646                             attr_uint);
1647             }
1648             *offset += sizeof(guint16);
1649
1650             attr_string = tvb_get_ephemeral_string(tvb, *offset, attr_uint);
1651             if ( tree ) {
1652                 proto_item_append_text(tree, ", String: %s", attr_string);
1653
1654                 proto_tree_add_string(tree, hf_zbee_zcl_attr_str, tvb, *offset, attr_uint,
1655                                 attr_string);
1656             }
1657             *offset += attr_uint;
1658             break;
1659
1660         case ZBEE_ZCL_TIME:
1661             /* Dissect Time of Day */
1662             attr_uint8[0] = dissect_zcl_attr_uint8(tvb, tree, offset, &hf_zbee_zcl_attr_hours);
1663             attr_uint8[1] = dissect_zcl_attr_uint8(tvb, tree, offset, &hf_zbee_zcl_attr_mins);
1664             attr_uint8[2] = dissect_zcl_attr_uint8(tvb, tree, offset, &hf_zbee_zcl_attr_secs);
1665             attr_uint8[3] = dissect_zcl_attr_uint8(tvb, tree, offset, &hf_zbee_zcl_attr_csecs);
1666
1667             if ( tree ) {
1668                 proto_item_append_text(tree, ", Time: %u:%u:%u.%u",
1669                     attr_uint8[0], attr_uint8[1], attr_uint8[2], attr_uint8[3]);
1670             }
1671             break;
1672
1673         case ZBEE_ZCL_DATE:
1674             /* Dissect Date */
1675             attr_uint8[0] = dissect_zcl_attr_uint8(tvb, tree, offset, &hf_zbee_zcl_attr_yy);
1676             attr_uint8[1] = dissect_zcl_attr_uint8(tvb, tree, offset, &hf_zbee_zcl_attr_mm);
1677             attr_uint8[2] = dissect_zcl_attr_uint8(tvb, tree, offset, &hf_zbee_zcl_attr_md);
1678             attr_uint8[3] = dissect_zcl_attr_uint8(tvb, tree, offset, &hf_zbee_zcl_attr_wd);
1679
1680             if ( tree ) {
1681                 proto_item_append_text(tree, ", Date: %u/%u/%u %s",
1682                     attr_uint8[0]+1900, attr_uint8[1], attr_uint8[2],
1683                     val_to_str(attr_uint8[3], zbee_zcl_wd_names, "Invalid Weekday") );
1684             }
1685             break;
1686
1687         case ZBEE_ZCL_UTC:
1688             /* Display UTC */
1689             attr_time.secs = (guint32)tvb_get_letohl(tvb, *offset);
1690             attr_time.secs += ZBEE_ZCL_NSTIME_UTC_OFFSET;
1691             attr_time.nsecs = 0;
1692
1693             if ( tree ) {
1694                 proto_item_append_text(tree, ", %s",
1695                     val_to_str(data_type, zbee_zcl_short_data_type_names, "Reserved") );
1696
1697                 proto_tree_add_time(tree, hf_zbee_zcl_attr_utc, tvb, *offset, sizeof(guint),
1698                             &attr_time);
1699             }
1700
1701             *offset += sizeof(guint32);
1702             break;
1703
1704         case ZBEE_ZCL_CLUSTER_ID:
1705             dissect_zcl_attr_uint16(tvb, tree, offset, &hf_zbee_zcl_attr_cid);
1706             break;
1707
1708         case ZBEE_ZCL_ATTR_ID:
1709             dissect_zcl_attr_id(tvb, tree, offset);
1710             break;
1711
1712         case ZBEE_ZCL_BACNET_OID:
1713             dissect_zcl_attr_bytes(tvb, tree, offset, 4);
1714             break;
1715
1716         case ZBEE_ZCL_IEEE_ADDR:
1717             dissect_zcl_attr_bytes(tvb, tree, offset, 8);
1718             break;
1719
1720         case ZBEE_ZCL_SECURITY_KEY:
1721             dissect_zcl_attr_bytes(tvb, tree, offset, 16);
1722             break;
1723
1724         default:
1725             break;
1726         }
1727
1728     return;
1729 } /* dissect_zcl_attr_data */
1730
1731 /*FUNCTION:------------------------------------------------------
1732  *  NAME
1733  *      dissect_zcl_big_int
1734  *  DESCRIPTION
1735  *      Dissects int or uint of up to 64 bits.
1736  *  PARAMETERS
1737  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
1738  *      packet_info *pinfo  - pointer to packet information fields
1739  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
1740  *      offset              - offset into the tvb to begin dissection.
1741  *      signed_flag         - if TRUE, dissect a signed int
1742  *  RETURNS
1743  *      void
1744  *---------------------------------------------------------------
1745  */
1746 static void dissect_zcl_big_int(tvbuff_t *tvb, proto_tree *tree, guint *offset, guint length,
1747                 gboolean signed_flag)
1748 {
1749     guint64 attr_uint64;
1750
1751     attr_uint64 = tvb_get_letohi(tvb, *offset, length, signed_flag);
1752
1753     /* add it to tree */
1754     if ( tree ) {
1755         if ( signed_flag ) {
1756             proto_item_append_text(tree, ", Int: %" G_GINT64_MODIFIER "d", (gint64)attr_uint64);
1757
1758             proto_tree_add_int64(tree, hf_zbee_zcl_attr_int64, tvb, *offset, length,
1759                     (gint64)attr_uint64);
1760         } else {
1761             proto_item_append_text(tree, ", Uint: %" G_GINT64_MODIFIER "u", attr_uint64);
1762
1763             proto_tree_add_uint64(tree, hf_zbee_zcl_attr_uint64, tvb, *offset, length,
1764                     attr_uint64);
1765         }
1766
1767     }
1768     *offset += length;
1769
1770     return;
1771 } /* dissect_zcl_big_int */
1772
1773 /*FUNCTION:------------------------------------------------------
1774  *  NAME
1775  *      dissect_zcl_attr_uint8
1776  *  DESCRIPTION
1777  *      Helper dissector for ZCL Attribute commands.
1778  *  PARAMETERS
1779  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
1780  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
1781  *      offset              - offset into the tvb to begin dissection.
1782  *      hf_zbee_zcl         - pointer to header field index
1783  *  RETURNS
1784  *      guint               - dissected data
1785  *---------------------------------------------------------------
1786  */
1787 static guint dissect_zcl_attr_uint8(tvbuff_t *tvb, proto_tree *tree, guint *offset, int *hf_zbee_zcl)
1788 {
1789         guint attr_uint;
1790
1791         attr_uint = tvb_get_guint8(tvb, *offset);
1792
1793         if ( tree ) {
1794             proto_tree_add_uint(tree, *hf_zbee_zcl, tvb, *offset, sizeof(guint8), attr_uint);
1795         }
1796         (*offset)++;
1797
1798         return attr_uint;
1799 } /* dissect_zcl_attr_uint8 */
1800
1801 /*FUNCTION:------------------------------------------------------
1802  *  NAME
1803  *      dissect_zcl_attr_uint16
1804  *  DESCRIPTION
1805  *      Helper dissector for ZCL Attribute commands.
1806  *  PARAMETERS
1807  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
1808  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
1809  *      offset              - offset into the tvb to begin dissection.
1810  *      hf_zbee_zcl         - pointer to header field index
1811  *  RETURNS
1812  *      guint               - field value
1813  *---------------------------------------------------------------
1814  */
1815 static guint dissect_zcl_attr_uint16(tvbuff_t *tvb, proto_tree *tree, guint *offset, int *hf_zbee_zcl)
1816 {
1817         guint attr_uint;
1818
1819         attr_uint = tvb_get_letohs(tvb, *offset);
1820
1821         if ( tree ) {
1822             proto_tree_add_uint(tree, *hf_zbee_zcl, tvb, *offset, sizeof(guint16), attr_uint);
1823         }
1824         *offset += sizeof(guint16);
1825
1826         return attr_uint;
1827 } /* dissect_zcl_attr_uint16 */
1828
1829 /*FUNCTION:------------------------------------------------------
1830  *  NAME
1831  *      dissect_zcl_attr_bytes
1832  *  DESCRIPTION
1833  *      Helper dissector for ZCL Attribute commands.
1834  *  PARAMETERS
1835  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
1836  *      proto_tree *tree    - pointer to data tree ethereal uses to display packet.
1837  *      offset              - offset into the tvb to begin dissection.
1838  *      length              - number of bytes to dissect
1839  *  RETURNS
1840  *      void
1841  *---------------------------------------------------------------
1842  */
1843 static void dissect_zcl_attr_bytes(tvbuff_t *tvb, proto_tree *tree, guint *offset, guint length)
1844 {
1845         if ( tree ) {
1846             proto_tree_add_bytes(tree, hf_zbee_zcl_attr_bytes, tvb, *offset, length,
1847                         tvb_get_ptr(tvb, *offset, length));
1848         }
1849         *offset += length;
1850
1851         return;
1852 } /* dissect_dcl_attr_bytes */
1853
1854 /*FUNCTION:------------------------------------------------------
1855  *  NAME
1856  *      zcl_dump_data
1857  *  DESCRIPTION
1858  *      Helper functions dumps any remaining data into the data dissector.
1859  *  PARAMETERS
1860  *      tvbuff_t    *tvb    - pointer to buffer containing raw packet.
1861  *      guint       offset  - offset after parsing last item.
1862  *      packet_info *pinfo  - packet information structure.
1863  *      proto_tree  *tree   - pointer to data tree Wireshark uses to display packet.
1864  *  RETURNS
1865  *      void
1866  *---------------------------------------------------------------
1867  */
1868 static void zcl_dump_data(tvbuff_t *tvb, guint offset, packet_info *pinfo, proto_tree *tree)
1869 {
1870     proto_tree  *root = proto_tree_get_root(tree);
1871     guint       length = tvb_length_remaining(tvb, offset);
1872     tvbuff_t    *remainder;
1873
1874     if (length > 0) {
1875         remainder = tvb_new_subset(tvb, offset, length, length);
1876         call_dissector(data_handle, remainder, pinfo, root);
1877     }
1878 } /* zcl_dump_data */
1879
1880 /*FUNCTION:------------------------------------------------------
1881  *  NAME
1882  *      tvb_get_letohi
1883  *  DESCRIPTION
1884  *      Gets little endian int or uint of up to 8 bytes from tvb buffer.
1885  *  PARAMETERS
1886  *      tvbuff_t *tvb       - pointer to buffer containing raw packet.
1887  *      offset              - offset into the tvb to begin dissection.
1888  *      length              - length of int or uint in bytes
1889  *      signed_flag         - if TRUE, get a signed int
1890  *  RETURNS
1891  *      guint64             - value retrieved from tvb buffer
1892  *---------------------------------------------------------------
1893  */
1894 static guint64 tvb_get_letohi(tvbuff_t *tvb, guint offset, guint length, gboolean signed_flag)
1895 {
1896         guint64 result;
1897         guint shift;
1898
1899         DISSECTOR_ASSERT((length>=1) && (length<=8));
1900
1901         result = 0;
1902         shift = 0;
1903         /* build big int of length bytes */
1904         while ( length-- ) {
1905             result += (guint64)tvb_get_guint8(tvb, offset) << shift;
1906             offset += sizeof(guint8);
1907             shift += 8;
1908         }
1909
1910         if ( signed_flag && (result >> (shift - 1)) ) {
1911             /* sign extend remaining bytes */
1912             while ( shift < (sizeof(guint64) * 8) ) {
1913                 result += (guint64)0xff << shift;
1914                 shift += 8;
1915             }
1916         }
1917
1918         return result;
1919 } /* tvb_get_letohi */
1920
1921 /*FUNCTION:------------------------------------------------------
1922  *  NAME
1923  *      proto_register_zbee_zcl
1924  *  DESCRIPTION
1925  *      ZigBee ZCL protocol registration routine.
1926  *  PARAMETERS
1927  *      none
1928  *  RETURNS
1929  *      void
1930  *---------------------------------------------------------------
1931  */
1932 void proto_register_zbee_zcl(void)
1933 {
1934     guint i, j;
1935
1936     static const true_false_string tfs_client_server = {
1937         "To Client",
1938         "To Server"
1939     };
1940
1941     static hf_register_info hf[] = {
1942         { &hf_zbee_zcl_fcf_frame_type,
1943             { "Frame Type", "zbee.zcl.type", FT_UINT8, BASE_HEX, VALS(zbee_zcl_frame_types),
1944                 ZBEE_ZCL_FCF_FRAME_TYPE, NULL, HFILL }},
1945
1946         { &hf_zbee_zcl_fcf_mfr_spec,
1947             { "Manufacturer Specific", "zbee.zcl.ms", FT_BOOLEAN, 8, NULL,
1948                 ZBEE_ZCL_FCF_MFR_SPEC, NULL, HFILL }},
1949
1950         { &hf_zbee_zcl_fcf_dir,
1951             { "Direction", "zbee.zcl.dir", FT_BOOLEAN, 8, TFS(&tfs_client_server),
1952                 ZBEE_ZCL_FCF_DIRECTION, NULL, HFILL }},
1953
1954         { &hf_zbee_zcl_fcf_disable_default_resp,
1955             { "Disable Default Response", "zbee.zcl.ddr", FT_BOOLEAN, 8, NULL,
1956                 ZBEE_ZCL_FCF_DISABLE_DEFAULT_RESP, NULL, HFILL }},
1957
1958         { &hf_zbee_zcl_mfr_code,
1959             { "Manufacturer Code", "zbee.zcl.cmd.mc", FT_UINT16, BASE_HEX,
1960                     VALS(zbee_mfr_code_names), 0x0, "Assigned manufacturer code.", HFILL }},
1961
1962         { &hf_zbee_zcl_tran_seqno,
1963             { "Sequence Number", "zbee.zcl.cmd.tsn", FT_UINT8, BASE_DEC, NULL, 0x0,
1964                 NULL, HFILL }},
1965
1966         { &hf_zbee_zcl_cmd_id,
1967             { "Command",    "zbee.zcl.cmd.id", FT_UINT8, BASE_HEX, VALS(zbee_zcl_cmd_names),
1968                 0x0, NULL, HFILL }},
1969
1970         { &hf_zbee_zcl_cs_cmd_id,
1971           { "Command",    "zbee.zcl.cs.cmd.id", FT_UINT8, BASE_HEX, VALS(zbee_zcl_cs_cmd_names) /*"Unknown"*/,
1972                 0x0, NULL, HFILL }},
1973
1974         { &hf_zbee_zcl_attr_id,
1975             { "Attribute",  "zbee.zcl.attr.id", FT_UINT16, BASE_HEX, NULL, 0x0,
1976                 NULL, HFILL }},
1977
1978         { &hf_zbee_zcl_attr_data_type,
1979             { "Data Type",  "zbee.zcl.attr.data.type", FT_UINT8, BASE_HEX,
1980                 VALS(zbee_zcl_data_type_names), 0x0, NULL, HFILL }},
1981
1982         { &hf_zbee_zcl_attr_boolean,
1983             { "Boolean",    "zbee.zcl.attr.boolean", FT_BOOLEAN, 8, TFS(&tfs_true_false), 0xff,
1984                 NULL, HFILL }},
1985
1986         { &hf_zbee_zcl_attr_uint8,
1987             { "Uint8",  "zbee.zcl.attr.uint8", FT_UINT8, BASE_DEC_HEX, NULL, 0x0,
1988                 NULL, HFILL }},
1989
1990         { &hf_zbee_zcl_attr_uint16,
1991             { "Uint16", "zbee.zcl.attr.uint16", FT_UINT16, BASE_DEC_HEX, NULL, 0x0,
1992                 NULL, HFILL }},
1993
1994         { &hf_zbee_zcl_attr_uint24,
1995             { "Uint24", "zbee.zcl.attr.uint24", FT_UINT24, BASE_DEC_HEX, NULL, 0x0,
1996                 NULL, HFILL }},
1997
1998         { &hf_zbee_zcl_attr_uint32,
1999             { "Uint32", "zbee.zcl.attr.uint32", FT_UINT32, BASE_DEC_HEX, NULL, 0x0,
2000                 NULL, HFILL }},
2001
2002         { &hf_zbee_zcl_attr_uint64,
2003             { "Uint64", "zbee.zcl.attr.uint64", FT_UINT64, BASE_DEC_HEX, NULL, 0x0,
2004                 NULL, HFILL }},
2005
2006         { &hf_zbee_zcl_attr_int8,
2007             { "Int8",   "zbee.zcl.attr.int8", FT_INT8, BASE_DEC, NULL, 0x0,
2008                 NULL, HFILL }},
2009
2010         { &hf_zbee_zcl_attr_int16,
2011             { "Int16",  "zbee.zcl.attr.int16", FT_INT16, BASE_DEC, NULL, 0x0,
2012                 NULL, HFILL }},
2013
2014         { &hf_zbee_zcl_attr_int24,
2015             { "Int24",  "zbee.zcl.attr.int24", FT_INT24, BASE_DEC, NULL, 0x0,
2016                 NULL, HFILL }},
2017
2018         { &hf_zbee_zcl_attr_int32,
2019             { "Int32",  "zbee.zcl.attr.int32", FT_INT32, BASE_DEC, NULL, 0x0,
2020                 NULL, HFILL }},
2021
2022         { &hf_zbee_zcl_attr_int64,
2023             { "Int64",  "zbee.zcl.attr.int64", FT_INT64, BASE_DEC, NULL, 0x0,
2024                 NULL, HFILL }},
2025
2026         { &hf_zbee_zcl_attr_semi,
2027             { "Semi Float", "zbee.zcl.attr.float", FT_FLOAT, BASE_NONE, NULL, 0x0,
2028                 NULL, HFILL }},
2029
2030         { &hf_zbee_zcl_attr_float,
2031             { "Float", "zbee.zcl.attr.float", FT_FLOAT, BASE_NONE, NULL, 0x0,
2032                 NULL, HFILL }},
2033
2034         { &hf_zbee_zcl_attr_double,
2035             { "Double Float", "zbee.zcl.attr.float", FT_DOUBLE, BASE_NONE, NULL, 0x0,
2036                 NULL, HFILL }},
2037
2038         { &hf_zbee_zcl_attr_bytes,
2039             { "Bytes",  "zbee.zcl.attr.bytes", FT_BYTES, BASE_NONE, NULL, 0x0,
2040                 NULL, HFILL }},
2041
2042         { &hf_zbee_zcl_attr_minint,
2043             { "Minimum Interval", "zbee.zcl.attr.minint", FT_UINT16, BASE_DEC, NULL, 0x0,
2044                 NULL, HFILL }},
2045
2046         { &hf_zbee_zcl_attr_maxint,
2047             { "Maximum Interval", "zbee.zcl.attr.maxint", FT_UINT16, BASE_DEC, NULL, 0x0,
2048                 NULL, HFILL }},
2049
2050         { &hf_zbee_zcl_attr_timeout,
2051             { "Timeout", "zbee.zcl.attr.timeout", FT_UINT16, BASE_DEC, NULL, 0x0,
2052                 NULL, HFILL }},
2053
2054         { &hf_zbee_zcl_attr_hours,
2055             { "Hours",  "zbee.zcl.attr.hours", FT_UINT8, BASE_DEC, NULL, 0x0,
2056                 NULL, HFILL }},
2057
2058         { &hf_zbee_zcl_attr_mins,
2059             { "Minutes", "zbee.zcl.attr.mins", FT_UINT8, BASE_DEC, NULL, 0x0,
2060                 NULL, HFILL }},
2061
2062         { &hf_zbee_zcl_attr_secs,
2063             { "Seconds", "zbee.zcl.attr.secs", FT_UINT8, BASE_DEC, NULL, 0x0,
2064                 NULL, HFILL }},
2065
2066         { &hf_zbee_zcl_attr_csecs,
2067             { "Centiseconds", "zbee.zcl.attr.csecs", FT_UINT8, BASE_DEC, NULL, 0x0,
2068                 NULL, HFILL }},
2069
2070         { &hf_zbee_zcl_attr_yy,
2071             { "Year", "zbee.zcl.attr.yy", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2072
2073         { &hf_zbee_zcl_attr_mm,
2074             { "Month", "zbee.zcl.attr.mm", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2075
2076         { &hf_zbee_zcl_attr_md,
2077             { "Day of Month", "zbee.zcl.attr.md", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2078
2079         { &hf_zbee_zcl_attr_wd,
2080             { "Day of Week", "zbee.zcl.attr.wd", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
2081
2082         { &hf_zbee_zcl_attr_utc,
2083             { "UTC", "zbee.zcl.attr.utc", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0x0, NULL, HFILL }},
2084
2085         { &hf_zbee_zcl_attr_status,
2086             { "Status", "zbee.zcl.attr.status", FT_UINT8, BASE_HEX, VALS(zbee_zcl_status_names),
2087                 0x0, NULL, HFILL }},
2088
2089         { &hf_zbee_zcl_attr_dir,
2090             { "Direction", "zbee.zcl.attr.dir", FT_UINT8, BASE_HEX, VALS(zbee_zcl_dir_names),
2091                 0x0, NULL, HFILL }},
2092
2093         { &hf_zbee_zcl_attr_dis,
2094             { "Discovery", "zbee.zcl.attr.dis", FT_UINT8, BASE_HEX, VALS(zbee_zcl_dis_names),
2095                 0x0, NULL, HFILL }},
2096
2097         { &hf_zbee_zcl_attr_cid,
2098             { "Cluster", "zbee.zcl.attr.cid", FT_UINT16, BASE_HEX, NULL, 0x0,
2099                 NULL, HFILL }},
2100
2101         { &hf_zbee_zcl_attr_start,
2102             { "Start Attribute", "zbee.zcl.attr.start", FT_UINT16, BASE_HEX, NULL, 0x0,
2103                 NULL, HFILL }},
2104
2105         { &hf_zbee_zcl_attr_maxnum,
2106             { "Maxiumum Number", "zbee.zcl.attr.maxnum", FT_UINT8, BASE_DEC, NULL, 0x0,
2107                 NULL, HFILL }},
2108
2109         { &hf_zbee_zcl_attr_str_len,
2110             { "Length", "zbee.zcl.attr.str.len", FT_UINT8, BASE_DEC, NULL, 0x0,
2111                 NULL, HFILL }},
2112
2113         { &hf_zbee_zcl_attr_str,
2114             { "String", "zbee.zcl.attr.str", FT_STRING, BASE_NONE, NULL, 0x0,
2115                 NULL, HFILL }},
2116
2117         { &hf_zbee_zcl_attr_ostr,
2118             { "Octet String",   "zbee.zcl.attr.ostr", FT_STRING, BASE_NONE, NULL, 0x0,
2119                 NULL, HFILL }}
2120     };
2121
2122     /* ZCL subtrees */
2123     gint *ett[ZBEE_ZCL_NUM_INDIVIDUAL_ETT + ZBEE_ZCL_NUM_ATTR_ETT];
2124
2125     ett[0] = &ett_zbee_zcl;
2126     ett[1] = &ett_zbee_zcl_fcf;
2127
2128     j = ZBEE_ZCL_NUM_INDIVIDUAL_ETT;
2129
2130     /* initialize attribute subtree types */
2131     for ( i = 0; i < ZBEE_ZCL_NUM_ATTR_ETT; i++, j++) {
2132         ett_zbee_zcl_attr[i] = -1;
2133         ett[j] = &ett_zbee_zcl_attr[i];
2134     }
2135
2136     /* Register ZigBee ZCL protocol with Wireshark. */
2137     proto_zbee_zcl = proto_register_protocol("ZigBee Cluster Library", "ZigBee ZCL", "zbee.zcl");
2138     proto_register_field_array(proto_zbee_zcl, hf, array_length(hf));
2139     proto_register_subtree_array(ett, array_length(ett));
2140
2141     /* Register the ZCL dissector and subdissector list. */
2142     register_dissector("zbee.zcl", dissect_zbee_zcl, proto_zbee_zcl);
2143
2144 } /* proto_register_zbee_zcl */
2145
2146 /*FUNCTION:------------------------------------------------------
2147  *  NAME
2148  *      proto_reg_handoff_zbee_zcl
2149  *  DESCRIPTION
2150  *      Finds the dissectors used in this module.
2151  *  PARAMETERS
2152  *      none
2153  *  RETURNS
2154  *      void
2155  *---------------------------------------------------------------
2156  */
2157 void proto_reg_handoff_zbee_zcl(void)
2158 {
2159     dissector_handle_t   zbee_zcl_handle;
2160
2161     /* Find the dissectors we need. */
2162     data_handle = find_dissector("data");
2163
2164     /* Register our dissector for the appropriate profiles. */
2165     zbee_zcl_handle = find_dissector("zbee.zcl");
2166     dissector_add("zbee.profile", ZBEE_PROFILE_IPM,   zbee_zcl_handle);
2167     dissector_add("zbee.profile", ZBEE_PROFILE_T1,    zbee_zcl_handle);
2168     dissector_add("zbee.profile", ZBEE_PROFILE_HA,    zbee_zcl_handle);
2169     dissector_add("zbee.profile", ZBEE_PROFILE_CBA,   zbee_zcl_handle);
2170     dissector_add("zbee.profile", ZBEE_PROFILE_WSN,   zbee_zcl_handle);
2171     dissector_add("zbee.profile", ZBEE_PROFILE_TA,    zbee_zcl_handle);
2172     dissector_add("zbee.profile", ZBEE_PROFILE_HC,    zbee_zcl_handle);
2173     dissector_add("zbee.profile", ZBEE_PROFILE_SE,    zbee_zcl_handle);
2174
2175     dissector_add("zbee.profile", ZBEE_PROFILE_C4_CL, zbee_zcl_handle);
2176 } /* proto_reg_handoff_zbee_zcl */