| Wireshark 4.7.3 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
packet-zbee-zcl.h
1/* packet-zbee-zcl.h
2 * Dissector routines for the ZigBee Cluster Library (ZCL)
3 * By Fred Fierling <fff@exegin.com>
4 * Copyright 2009 Exegin Technologies Limited
5 *
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
12
13#ifndef PACKET_ZBEE_ZCL_H
14#define PACKET_ZBEE_ZCL_H
15
16#include <wsutil/epochs.h>
17
18/* Structure to contain the ZCL frame information */
19 typedef struct{
20 bool mfr_spec;
21 bool direction;
22 bool disable_default_resp;
23
24 uint8_t frame_type;
25 uint16_t mfr_code;
26 uint8_t tran_seqno;
27 uint8_t cmd_id;
28} zbee_zcl_packet;
29
30/* ZCL Commands */
31#define ZBEE_ZCL_CMD_READ_ATTR 0x00
32#define ZBEE_ZCL_CMD_READ_ATTR_RESP 0x01
33#define ZBEE_ZCL_CMD_WRITE_ATTR 0x02
34#define ZBEE_ZCL_CMD_WRITE_ATTR_UNDIVIDED 0x03
35#define ZBEE_ZCL_CMD_WRITE_ATTR_RESP 0x04
36#define ZBEE_ZCL_CMD_WRITE_ATTR_NO_RESP 0x05
37#define ZBEE_ZCL_CMD_CONFIG_REPORT 0x06
38#define ZBEE_ZCL_CMD_CONFIG_REPORT_RESP 0x07
39#define ZBEE_ZCL_CMD_READ_REPORT_CONFIG 0x08
40#define ZBEE_ZCL_CMD_READ_REPORT_CONFIG_RESP 0x09
41#define ZBEE_ZCL_CMD_REPORT_ATTR 0x0a
42#define ZBEE_ZCL_CMD_DEFAULT_RESP 0x0b
43#define ZBEE_ZCL_CMD_DISCOVER_ATTR 0x0c
44#define ZBEE_ZCL_CMD_DISCOVER_ATTR_RESP 0x0d
45#define ZBEE_ZCL_CMD_READ_ATTR_STRUCT 0x0e
46#define ZBEE_ZCL_CMD_WRITE_ATTR_STRUCT 0x0f
47#define ZBEE_ZCL_CMD_WRITE_ATTR_STRUCT_RESP 0x10
48#define ZBEE_ZCL_CMD_DISCOVER_CMDS_REC 0x11
49#define ZBEE_ZCL_CMD_DISCOVER_CMDS_REC_RESP 0x12
50#define ZBEE_ZCL_CMD_DISCOVER_CMDS_GEN 0x13
51#define ZBEE_ZCL_CMD_DISCOVER_CMDS_GEN_RESP 0x14
52#define ZBEE_ZCL_CMD_DISCOVER_ATTR_EXTENDED 0x15
53#define ZBEE_ZCL_CMD_DISCOVER_ATTR_EXTENDED_RESP 0x16
54
55
56/* ZCL Data Types */
57#define ZBEE_ZCL_NO_DATA 0x00
58
59#define ZBEE_ZCL_8_BIT_DATA 0x08
60#define ZBEE_ZCL_16_BIT_DATA 0x09
61#define ZBEE_ZCL_24_BIT_DATA 0x0a
62#define ZBEE_ZCL_32_BIT_DATA 0x0b
63#define ZBEE_ZCL_40_BIT_DATA 0x0c
64#define ZBEE_ZCL_48_BIT_DATA 0x0d
65#define ZBEE_ZCL_56_BIT_DATA 0x0e
66#define ZBEE_ZCL_64_BIT_DATA 0x0f
67
68#define ZBEE_ZCL_BOOLEAN 0x10
69
70#define ZBEE_ZCL_8_BIT_BITMAP 0x18
71#define ZBEE_ZCL_16_BIT_BITMAP 0x19
72#define ZBEE_ZCL_24_BIT_BITMAP 0x1a
73#define ZBEE_ZCL_32_BIT_BITMAP 0x1b
74#define ZBEE_ZCL_40_BIT_BITMAP 0x1c
75#define ZBEE_ZCL_48_BIT_BITMAP 0x1d
76#define ZBEE_ZCL_56_BIT_BITMAP 0x1e
77#define ZBEE_ZCL_64_BIT_BITMAP 0x1f
78
79#define ZBEE_ZCL_8_BIT_UINT 0x20
80#define ZBEE_ZCL_16_BIT_UINT 0x21
81#define ZBEE_ZCL_24_BIT_UINT 0x22
82#define ZBEE_ZCL_32_BIT_UINT 0x23
83#define ZBEE_ZCL_40_BIT_UINT 0x24
84#define ZBEE_ZCL_48_BIT_UINT 0x25
85#define ZBEE_ZCL_56_BIT_UINT 0x26
86#define ZBEE_ZCL_64_BIT_UINT 0x27
87
88#define ZBEE_ZCL_8_BIT_INT 0x28
89#define ZBEE_ZCL_16_BIT_INT 0x29
90#define ZBEE_ZCL_24_BIT_INT 0x2a
91#define ZBEE_ZCL_32_BIT_INT 0x2b
92#define ZBEE_ZCL_40_BIT_INT 0x2c
93#define ZBEE_ZCL_48_BIT_INT 0x2d
94#define ZBEE_ZCL_56_BIT_INT 0x2e
95#define ZBEE_ZCL_64_BIT_INT 0x2f
96
97#define ZBEE_ZCL_8_BIT_ENUM 0x30
98#define ZBEE_ZCL_16_BIT_ENUM 0x31
99
100#define ZBEE_ZCL_SEMI_FLOAT 0x38
101#define ZBEE_ZCL_SINGLE_FLOAT 0x39
102#define ZBEE_ZCL_DOUBLE_FLOAT 0x3a
103
104#define ZBEE_ZCL_OCTET_STRING 0x41
105#define ZBEE_ZCL_CHAR_STRING 0x42
106#define ZBEE_ZCL_LONG_OCTET_STRING 0x43
107#define ZBEE_ZCL_LONG_CHAR_STRING 0x44
108
109#define ZBEE_ZCL_ARRAY 0x48
110#define ZBEE_ZCL_STRUCT 0x4c
111
112#define ZBEE_ZCL_SET 0x50
113#define ZBEE_ZCL_BAG 0x51
114
115#define ZBEE_ZCL_TIME 0xe0
116#define ZBEE_ZCL_DATE 0xe1
117#define ZBEE_ZCL_UTC 0xe2
118
119#define ZBEE_ZCL_CLUSTER_ID 0xe8
120#define ZBEE_ZCL_ATTR_ID 0xe9
121#define ZBEE_ZCL_BACNET_OID 0xea
122
123#define ZBEE_ZCL_IEEE_ADDR 0xf0
124#define ZBEE_ZCL_SECURITY_KEY 0xf1
125
126#define ZBEE_ZCL_UNKNOWN 0xff
127
128/* ZCL Miscellaneous */
129#define ZBEE_ZCL_DIR_REPORTED 0
130#define ZBEE_ZCL_DIR_RECEIVED 1
131
132#define IS_ANALOG_SUBTYPE(x) ( (x & 0xF0) == 0x20 || (x & 0xF8) == 0x38 || (x & 0xF8) == 0xE0 )
133
134/* ZCL Status Enumerations */
135#define ZBEE_ZCL_STAT_SUCCESS 0x00
136#define ZBEE_ZCL_STAT_FAILURE 0x01
137
138#define ZBEE_ZCL_STAT_NOT_AUTHORIZED 0x7e
139#define ZBEE_ZCL_STAT_RESERVED_FIELD_NOT_ZERO 0x7f
140#define ZBEE_ZCL_STAT_MALFORMED_CMD 0x80
141#define ZBEE_ZCL_STAT_UNSUP_CLUSTER_CMD 0x81
142#define ZBEE_ZCL_STAT_UNSUP_GENERAL_CMD 0x82
143#define ZBEE_ZCL_STAT_UNSUP_MFR_CLUSTER_CMD 0x83
144#define ZBEE_ZCL_STAT_UNSUP_MFR_GENERAL_CMD 0x84
145#define ZBEE_ZCL_STAT_INVALID_FIELD 0x85
146#define ZBEE_ZCL_STAT_UNSUPPORTED_ATTR 0x86
147#define ZBEE_ZCL_STAT_INVALID_VALUE 0x87
148#define ZBEE_ZCL_STAT_READ_ONLY 0x88
149#define ZBEE_ZCL_STAT_INSUFFICIENT_SPACE 0x89
150#define ZBEE_ZCL_STAT_DUPLICATE_EXISTS 0x8a
151#define ZBEE_ZCL_STAT_NOT_FOUND 0x8b
152#define ZBEE_ZCL_STAT_UNREPORTABLE_ATTR 0x8c
153#define ZBEE_ZCL_STAT_INVALID_DATA_TYPE 0x8d
154#define ZBEE_ZCL_STAT_INVALID_SELECTOR 0x8e
155#define ZBEE_ZCL_STAT_WRITE_ONLY 0x8f
156#define ZBEE_ZCL_STAT_INCONSISTENT_STARTUP_STATE 0x90
157#define ZBEE_ZCL_STAT_DEFINED_OUT_OF_BAND 0x91
158#define ZBEE_ZCL_STAT_INCONSISTENT 0x92
159#define ZBEE_ZCL_STAT_ACTION_DENIED 0x93
160#define ZBEE_ZCL_STAT_TIMEOUT 0x94
161#define ZBEE_ZCL_STAT_OTA_ABORT 0x95
162#define ZBEE_ZCL_STAT_OTA_INVALID_IMAGE 0x96
163#define ZBEE_ZCL_STAT_OTA_WAIT_FOR_DATA 0x97
164#define ZBEE_ZCL_STAT_OTA_NO_IMAGE_AVAILABLE 0x98
165#define ZBEE_ZCL_STAT_OTA_REQUIRE_MORE_IMAGE 0x99
166#define ZBEE_ZCL_STAT_OTA_NOTIFICATION_PENDING 0x9a
167#define ZBEE_ZCL_STAT_HARDWARE_FAILURE 0xc0
168#define ZBEE_ZCL_STAT_SOFTWARE_FAILURE 0xc1
169#define ZBEE_ZCL_STAT_CALIBRATION_ERROR 0xc2
170#define ZBEE_ZCL_STAT_UNSUPPORTED_CLUSTER 0xc3
171#define ZBEE_ZCL_STAT_LIMIT_REACHED 0xc4
172
173/* Misc. */
174#define INT24_SIGN_BITS 0xffff8000
175#define MONTHS_PER_YEAR 12
176#define YEAR_OFFSET 1900
177
178/* ZigBee ZCL Cluster Key */
179#define ZCL_CLUSTER_MFR_KEY(cluster_id,mfr_code) (((mfr_code)<<16) | (cluster_id))
180
181 typedef void (*zbee_zcl_fn_attr_data)(proto_tree *tree, packet_info* pinfo, tvbuff_t *tvb, unsigned *offset, uint16_t attr_id, unsigned data_type, bool client_attr);
182
183 typedef struct _zbee_zcl_cluster_desc {
184 int proto_id;
185 protocol_t *proto;
186 const char *name;
187 int ett;
188 int hf_attr_server_id;
189 int hf_attr_client_id;
190 int hf_cmd_rx_id;
191 int hf_cmd_tx_id;
192 uint16_t cluster_id;
193 uint16_t mfr_code;
194 zbee_zcl_fn_attr_data fn_attr_data;
195} zbee_zcl_cluster_desc;
196
197 extern const value_string zbee_zcl_short_data_type_names[];
198 extern const value_string zbee_mfr_code_names[];
199 extern const value_string zbee_zcl_status_names[];
200
201 extern const time_value_string now_strings[];
202 extern const time_value_string zbee_zcl_utctime_strings[];
203
204/* Dissector functions */
205 extern void dissect_zcl_read_attr (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, unsigned *offset, uint16_t cluster_id, uint16_t mfr_code, bool direction);
206 extern void dissect_zcl_write_attr (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, unsigned *offset, uint16_t cluster_id, uint16_t mfr_code, bool direction);
207 extern void dissect_zcl_report_attr(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, unsigned *offset, uint16_t cluster_id, uint16_t mfr_code, bool direction);
208 extern void dissect_zcl_read_attr_resp (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, unsigned *offset, uint16_t cluster_id, uint16_t mfr_code, bool direction);
209 extern void dissect_zcl_attr_id(tvbuff_t *tvb, proto_tree *tree, unsigned *offset, uint16_t cluster_id, uint16_t mfr_code, bool client_attr);
210 extern void dissect_zcl_attr_data_type_val(tvbuff_t *tvb, packet_info* pinfo, proto_tree *tree, unsigned *offset, uint16_t attr_id, uint16_t cluster_id, uint16_t mfr_code, bool client_attr);
211 extern unsigned dissect_zcl_attr_uint8 (tvbuff_t *tvb, proto_tree *tree, unsigned *offset, int *length);
212
213/* Helper functions */
214
215/* Exported DLL functions */
216WS_DLL_PUBLIC void decode_zcl_time_in_100ms (char *s, uint16_t value);
217WS_DLL_PUBLIC void decode_zcl_time_in_seconds (char *s, uint16_t value);
218WS_DLL_PUBLIC void decode_zcl_time_in_minutes (char *s, uint16_t value);
219WS_DLL_PUBLIC void dissect_zcl_attr_data (tvbuff_t *tvb, packet_info* pinfo, proto_tree *tree, unsigned *offset, unsigned data_type, bool client_attr);
220
221WS_DLL_PUBLIC void zbee_zcl_init_cluster(const char *proto_abbrev, int proto, int ett, uint16_t cluster_id, uint16_t mfr_code, int hf_attr_server_id, int hf_attr_client_id, int hf_cmd_rx_id, int hf_cmd_tx_id, zbee_zcl_fn_attr_data fn_attr_data);
222
223/* Cluster-specific commands and parameters */
224#define ZBEE_ZCL_CSC_IAS_ZONE_C_ERC_NEP 0x02
225#define ZBEE_ZCL_CSC_IAS_ZONE_C_ERC_NS 0x01
226#define ZBEE_ZCL_CSC_IAS_ZONE_C_ERC_S 0x00
227#define ZBEE_ZCL_CSC_IAS_ZONE_C_ERC_TMZ 0x03
228#define ZBEE_ZCL_CSC_IAS_ZONE_C_ZER 0x00
229#define ZBEE_ZCL_CSC_IAS_ZONE_S_ZER 0x01
230#define ZBEE_ZCL_CSC_IAS_ZONE_S_ZSCN 0x00
231#define ZBEE_ZCL_CSC_POLL_CONTROL_C_CIR 0x00
232#define ZBEE_ZCL_CSC_POLL_CONTROL_C_FPS 0x01
233#define ZBEE_ZCL_CSC_POLL_CONTROL_C_SLPI 0x02
234#define ZBEE_ZCL_CSC_POLL_CONTROL_C_SSPI 0x03
235#define ZBEE_ZCL_CSC_POLL_CONTROL_S_CI 0x00
236#define ZBEE_ZCL_CSC_THERMOSTAT_C_CWS 0x03
237#define ZBEE_ZCL_CSC_THERMOSTAT_C_GWS 0x02
238#define ZBEE_ZCL_CSC_THERMOSTAT_C_SRL 0x00
239#define ZBEE_ZCL_CSC_THERMOSTAT_C_SWS 0x01
240#define ZBEE_ZCL_CSC_THERMOSTAT_C_SWS_DOW_AV 0x80
241#define ZBEE_ZCL_CSC_THERMOSTAT_C_SWS_DOW_FR 0x20
242#define ZBEE_ZCL_CSC_THERMOSTAT_C_SWS_DOW_MO 0x02
243#define ZBEE_ZCL_CSC_THERMOSTAT_C_SWS_DOW_SA 0x40
244#define ZBEE_ZCL_CSC_THERMOSTAT_C_SWS_DOW_SU 0x01
245#define ZBEE_ZCL_CSC_THERMOSTAT_C_SWS_DOW_TH 0x10
246#define ZBEE_ZCL_CSC_THERMOSTAT_C_SWS_DOW_TU 0x04
247#define ZBEE_ZCL_CSC_THERMOSTAT_C_SWS_DOW_WE 0x08
248#define ZBEE_ZCL_CSC_THERMOSTAT_C_SWS_SP_B 0x03
249#define ZBEE_ZCL_CSC_THERMOSTAT_C_SWS_SP_C 0x02
250#define ZBEE_ZCL_CSC_THERMOSTAT_C_SWS_SP_H 0x01
251#define ZBEE_ZCL_CSC_THERMOSTAT_S_GWSR 0x00
252
253/*
254 * Convert a given Zigbee time value to an nstime_t, for initializing
255 * fields in a time_value_string.
256 *
257 * This might overflow when converted to a time_t, e.g. with 32-bit
258 * signed integer time_t. EPOCH_DELTA_2000_01_01_00_00_00_UTC is a
259 * UINT64_C so we can do this test to prevent overflow safely.
260 * Make sure to coordinate with whatever proto.c get_time_value()
261 * does with overflow of an ENC_TIME_ZBEE_ZCL.
262 */
263#define NSTIME_INIT_ZBEE(t) \
264 NSTIME_INIT_SECS(MIN(((uint32_t)(t)) + EPOCH_DELTA_2000_01_01_00_00_00_UTC, TIME_T_MAX))
265
266#endif /* PACKET_ZBEE_ZCL_H*/
epochs.h
packet_info
struct _packet_info packet_info
Represents the metadata and indexing information for a single captured frame.
protocol_t
struct _protocol protocol_t
Definition proto.h:100
_zbee_zcl_cluster_desc
Definition packet-zbee-zcl.h:183
zbee_zcl_packet
Definition packet-zbee-zcl.h:19
time_value_string
struct _time_value_string time_value_string
Maps a timestamp key to a string value, used for table-driven time-to-string lookups.
value_string
struct _value_string value_string
Mapping between a 32-bit integer value and its string representation.