1 /* packet-zbee-zcl-ha.c
2 * Dissector routines for the ZigBee ZCL SE clusters like
4 * By Fabio Tarabelloni <fabio.tarabelloni@reloc.it>
5 * Copyright 2013 RELOC s.r.l.
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 #include <epan/packet.h>
34 #include <epan/to_str.h>
36 #include "packet-zbee.h"
37 #include "packet-zbee-aps.h"
38 #include "packet-zbee-zcl.h"
40 /* ########################################################################## */
41 /* #### (0x0703) MESSAGING CLUSTER ########################################## */
42 /* ########################################################################## */
44 /*************************/
46 /*************************/
48 #define ZBEE_ZCL_MSG_NUM_GENERIC_ETT 2
49 #define ZBEE_ZCL_MSG_NUM_ETT (ZBEE_ZCL_MSG_NUM_GENERIC_ETT)
51 /* Attributes - None */
53 /* Server Commands Received */
54 #define ZBEE_ZCL_CMD_ID_MSG_GET_LAST_MSG 0x00 /* Get Last Message */
55 #define ZBEE_ZCL_CMD_ID_MSG_MSG_CONFIRM 0x01 /* Message Confirmation */
57 /* Server Commands Generated */
58 #define ZBEE_ZCL_CMD_ID_MSG_DISPLAY_MSG 0x00 /* Display Message */
59 #define ZBEE_ZCL_CMD_ID_MSG_CANCEL_MSG 0x01 /* Cancel Message */
61 /* Message Control Field Bit Map */
62 #define ZBEE_ZCL_MSG_CTRL_TX_MASK 0x03
63 #define ZBEE_ZCL_MSG_CTRL_IMPORTANCE_MASK 0x0C
64 #define ZBEE_ZCL_MSG_CTRL_RESERVED_MASK 0x70
65 #define ZBEE_ZCL_MSG_CTRL_CONFIRM_MASK 0x80
67 #define ZBEE_ZCL_MSG_CTRL_TX_NORMAL_ONLY 0x00 /* Normal Transmission Only */
68 #define ZBEE_ZCL_MSG_CTRL_TX_NORMAL_ANON_INTERPAN 0x01 /* Normal and Anonymous Inter-PAN Transmission Only */
69 #define ZBEE_ZCL_MSG_CTRL_TX_ANON_INTERPAN_ONLY 0x02 /* Anonymous Inter-PAN Transmission Only */
71 #define ZBEE_ZCL_MSG_CTRL_IMPORTANCE_LOW 0x00 /* Low */
72 #define ZBEE_ZCL_MSG_CTRL_IMPORTANCE_MEDIUM 0x01 /* Medium */
73 #define ZBEE_ZCL_MSG_CTRL_IMPORTANCE_HIGH 0x02 /* High */
74 #define ZBEE_ZCL_MSG_CTRL_IMPORTANCE_CRITICAL 0x03 /* Critical */
76 #define ZBEE_ZCL_MSG_START_TIME_NOW 0x00000000 /* Now */
78 /*************************/
79 /* Function Declarations */
80 /*************************/
82 /* Command Dissector Helpers */
83 static void dissect_zcl_msg_display (tvbuff_t
*tvb
, proto_tree
*tree
, guint
*offset
);
84 static void dissect_zcl_msg_cancel (tvbuff_t
*tvb
, proto_tree
*tree
, guint
*offset
);
85 static void dissect_zcl_msg_confirm (tvbuff_t
*tvb
, proto_tree
*tree
, guint
*offset
);
87 /* Private functions prototype */
88 static void decode_zcl_msg_duration (gchar
*s
, guint16 value
);
90 /*************************/
91 /* Global Variables */
92 /*************************/
94 /* Initialize the protocol and registered fields */
95 static int proto_zbee_zcl_msg
= -1;
97 static int hf_zbee_zcl_msg_srv_tx_cmd_id
= -1;
98 static int hf_zbee_zcl_msg_srv_rx_cmd_id
= -1;
99 static int hf_zbee_zcl_msg_message_id
= -1;
100 static int hf_zbee_zcl_msg_ctrl_tx
= -1;
101 static int hf_zbee_zcl_msg_ctrl_importance
= -1;
102 static int hf_zbee_zcl_msg_ctrl_reserved
= -1;
103 static int hf_zbee_zcl_msg_ctrl_confirm
= -1;
104 static int hf_zbee_zcl_msg_start_time
= -1;
105 static int hf_zbee_zcl_msg_duration
= -1;
106 static int hf_zbee_zcl_msg_message_length
=- 1;
107 static int hf_zbee_zcl_msg_message
= -1;
108 static int hf_zbee_zcl_msg_confirm_time
= -1;
110 /* Initialize the subtree pointers */
111 static gint ett_zbee_zcl_msg
= -1;
112 static gint ett_zbee_zcl_msg_message_control
= -1;
114 /* Server Commands Received */
115 static const value_string zbee_zcl_msg_srv_rx_cmd_names
[] = {
116 { ZBEE_ZCL_CMD_ID_MSG_GET_LAST_MSG
, "Get Last Message" },
117 { ZBEE_ZCL_CMD_ID_MSG_MSG_CONFIRM
, "Message Confirmation" },
121 /* Server Commands Generated */
122 static const value_string zbee_zcl_msg_srv_tx_cmd_names
[] = {
123 { ZBEE_ZCL_CMD_ID_MSG_DISPLAY_MSG
, "Display Message" },
124 { ZBEE_ZCL_CMD_ID_MSG_CANCEL_MSG
, "Cancel Message" },
128 /* Message Control Transmission */
129 static const value_string zbee_zcl_msg_ctrl_tx_names
[] = {
130 { ZBEE_ZCL_MSG_CTRL_TX_NORMAL_ONLY
, "Normal Transmission Only" },
131 { ZBEE_ZCL_MSG_CTRL_TX_NORMAL_ANON_INTERPAN
, "Normal and Anonymous Inter-PAN Transmission Only" },
132 { ZBEE_ZCL_MSG_CTRL_TX_ANON_INTERPAN_ONLY
, "Anonymous Inter-PAN Transmission Only" },
136 /* Message Control Importance */
137 static const value_string zbee_zcl_msg_ctrl_importance_names
[] = {
138 { ZBEE_ZCL_MSG_CTRL_IMPORTANCE_LOW
, "Low" },
139 { ZBEE_ZCL_MSG_CTRL_IMPORTANCE_MEDIUM
, "Medium" },
140 { ZBEE_ZCL_MSG_CTRL_IMPORTANCE_HIGH
, "High" },
141 { ZBEE_ZCL_MSG_CTRL_IMPORTANCE_CRITICAL
, "Critical" },
146 /*************************/
147 /* Function Bodies */
148 /*************************/
150 /*FUNCTION:------------------------------------------------------
152 * dissect_zbee_zcl_msg
154 * ZigBee ZCL Messaging cluster dissector for wireshark.
156 * tvbuff_t *tvb - pointer to buffer containing raw packet.
157 * packet_info *pinfo - pointer to packet information fields
158 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
161 *---------------------------------------------------------------
164 dissect_zbee_zcl_msg(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data
)
166 proto_item
*payload_root
;
167 proto_tree
*payload_tree
;
168 zbee_zcl_packet
*zcl
= (zbee_zcl_packet
*)data
;
170 guint8 cmd_id
= zcl
->cmd_id
;
173 /* Create a subtree for the ZCL Command frame, and add the command ID to it. */
174 if (zcl
->direction
== ZBEE_ZCL_FCF_TO_SERVER
) {
175 /* Append the command name to the info column. */
176 col_append_fstr(pinfo
->cinfo
, COL_INFO
, "%s, Seq: %u",
177 val_to_str_const(cmd_id
, zbee_zcl_msg_srv_rx_cmd_names
, "Unknown Command"),
180 /* Add the command ID. */
181 proto_tree_add_item(tree
, hf_zbee_zcl_msg_srv_rx_cmd_id
, tvb
, offset
, 1, cmd_id
);
183 /* Check is this command has a payload, than add the payload tree */
184 rem_len
= tvb_reported_length_remaining(tvb
, ++offset
);
186 payload_root
= proto_tree_add_text(tree
, tvb
, offset
, rem_len
, "Payload");
187 payload_tree
= proto_item_add_subtree(payload_root
, ett_zbee_zcl_msg
);
189 /* Call the appropriate command dissector */
192 case ZBEE_ZCL_CMD_ID_MSG_GET_LAST_MSG
:
196 case ZBEE_ZCL_CMD_ID_MSG_MSG_CONFIRM
:
197 dissect_zcl_msg_confirm(tvb
, payload_tree
, &offset
);
205 else { /* ZBEE_ZCL_FCF_TO_CLIENT */
206 /* Append the command name to the info column. */
207 col_append_fstr(pinfo
->cinfo
, COL_INFO
, "%s, Seq: %u",
208 val_to_str_const(cmd_id
, zbee_zcl_msg_srv_tx_cmd_names
, "Unknown Command"),
211 /* Add the command ID. */
212 proto_tree_add_item(tree
, hf_zbee_zcl_msg_srv_tx_cmd_id
, tvb
, offset
, 1, cmd_id
);
214 /* Check is this command has a payload, than add the payload tree */
215 rem_len
= tvb_reported_length_remaining(tvb
, ++offset
);
217 payload_root
= proto_tree_add_text(tree
, tvb
, offset
, rem_len
, "Payload");
218 payload_tree
= proto_item_add_subtree(payload_root
, ett_zbee_zcl_msg
);
220 /* Call the appropriate command dissector */
223 case ZBEE_ZCL_CMD_ID_MSG_DISPLAY_MSG
:
224 dissect_zcl_msg_display(tvb
, payload_tree
, &offset
);
227 case ZBEE_ZCL_CMD_ID_MSG_CANCEL_MSG
:
228 dissect_zcl_msg_cancel(tvb
, payload_tree
, &offset
);
237 return tvb_length(tvb
);
238 } /*dissect_zbee_zcl_msg*/
240 /*FUNCTION:------------------------------------------------------
242 * dissect_zcl_msg_display
244 * This function manages the Display Message payload
246 * tvbuff_t *tvb - pointer to buffer containing raw packet.
247 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
251 *---------------------------------------------------------------
254 dissect_zcl_msg_display(tvbuff_t
*tvb
, proto_tree
*tree
, guint
*offset
)
256 proto_tree
*sub_tree
= NULL
;
262 /* Retrieve "Message ID" field */
263 proto_tree_add_item(tree
, hf_zbee_zcl_msg_message_id
, tvb
, *offset
, 4, ENC_LITTLE_ENDIAN
);
266 /* Retrieve "Message Control" field */
267 control
= tvb_get_guint8(tvb
, *offset
);
268 ti
= proto_tree_add_text(tree
, tvb
, *offset
, 1, "Message Control: 0x%02x", control
);
269 sub_tree
= proto_item_add_subtree(ti
, ett_zbee_zcl_msg_message_control
);
270 proto_tree_add_item(sub_tree
, hf_zbee_zcl_msg_ctrl_tx
, tvb
, *offset
, 1, ENC_NA
);
271 proto_tree_add_item(sub_tree
, hf_zbee_zcl_msg_ctrl_importance
, tvb
, *offset
, 1, ENC_NA
);
272 proto_tree_add_item(sub_tree
, hf_zbee_zcl_msg_ctrl_reserved
, tvb
, *offset
, 1, ENC_NA
);
273 proto_tree_add_item(sub_tree
, hf_zbee_zcl_msg_ctrl_confirm
, tvb
, *offset
, 1, ENC_NA
);
276 /* Retrieve "Start Time" field */
277 proto_tree_add_item(tree
, hf_zbee_zcl_msg_start_time
, tvb
, *offset
, 4, ENC_LITTLE_ENDIAN
);
280 /* Retrieve "Duration In Minutes" field */
281 proto_tree_add_item(tree
, hf_zbee_zcl_msg_duration
, tvb
, *offset
, 2, ENC_LITTLE_ENDIAN
);
284 /* Retrieve "Message Length" field */
285 msg_len
= tvb_get_guint8(tvb
, *offset
); /* string length */
286 proto_tree_add_item(tree
, hf_zbee_zcl_msg_message_length
, tvb
, *offset
, 1, ENC_NA
);
289 /* Retrieve "Message" field */
290 msg_data
= tvb_get_string_enc(wmem_packet_scope(), tvb
, *offset
, msg_len
, ENC_LITTLE_ENDIAN
);
291 proto_tree_add_string(tree
, hf_zbee_zcl_msg_message
, tvb
, *offset
, msg_len
, msg_data
);
294 } /*dissect_zcl_msg_display*/
296 /*FUNCTION:------------------------------------------------------
298 * dissect_zcl_msg_cancel
300 * This function manages the Cancel Message payload
302 * tvbuff_t *tvb - pointer to buffer containing raw packet.
303 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
307 *---------------------------------------------------------------
310 dissect_zcl_msg_cancel(tvbuff_t
*tvb
, proto_tree
*tree
, guint
*offset
)
312 proto_tree
*sub_tree
= NULL
;
316 /* Retrieve "Message ID" field */
317 proto_tree_add_item(tree
, hf_zbee_zcl_msg_message_id
, tvb
, *offset
, 4, ENC_LITTLE_ENDIAN
);
320 /* Retrieve "Message Control" field */
321 control
= tvb_get_guint8(tvb
, *offset
);
322 ti
= proto_tree_add_text(tree
, tvb
, *offset
, 1, "Message Control: 0x%02x", control
);
323 sub_tree
= proto_item_add_subtree(ti
, ett_zbee_zcl_msg_message_control
);
324 proto_tree_add_item(sub_tree
, hf_zbee_zcl_msg_ctrl_tx
, tvb
, *offset
, 1, ENC_NA
);
325 proto_tree_add_item(sub_tree
, hf_zbee_zcl_msg_ctrl_importance
, tvb
, *offset
, 1, ENC_NA
);
326 proto_tree_add_item(sub_tree
, hf_zbee_zcl_msg_ctrl_reserved
, tvb
, *offset
, 1, ENC_NA
);
327 proto_tree_add_item(sub_tree
, hf_zbee_zcl_msg_ctrl_confirm
, tvb
, *offset
, 1, ENC_NA
);
331 /*FUNCTION:------------------------------------------------------
333 * dissect_zcl_msg_confirm
335 * This function manages the Message Confirmation payload
337 * tvbuff_t *tvb - pointer to buffer containing raw packet.
338 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
342 *---------------------------------------------------------------
345 dissect_zcl_msg_confirm(tvbuff_t
*tvb
, proto_tree
*tree
, guint
*offset
)
347 nstime_t confirm_time
;
349 /* Retrieve "Message ID" field */
350 proto_tree_add_item(tree
, hf_zbee_zcl_msg_message_id
, tvb
, *offset
, 4, ENC_LITTLE_ENDIAN
);
353 /* Retrieve "Confirmation Time" field */
354 confirm_time
.secs
= tvb_get_letohl(tvb
, *offset
) + ZBEE_ZCL_NSTIME_UTC_OFFSET
;
355 confirm_time
.nsecs
= 0;
356 proto_tree_add_time(tree
, hf_zbee_zcl_msg_confirm_time
, tvb
, *offset
, 4, &confirm_time
);
360 /*FUNCTION:------------------------------------------------------
362 * decode_zcl_msg_duration
364 * this function decodes duration in minute type variable
368 *---------------------------------------------------------------
371 decode_zcl_msg_duration(gchar
*s
, guint16 value
)
374 g_snprintf(s
, ITEM_LABEL_LENGTH
, "Until changed");
376 g_snprintf(s
, ITEM_LABEL_LENGTH
, "%d minutes", value
);
378 } /*decode_zcl_msg_duration*/
380 /*FUNCTION:------------------------------------------------------
382 * decode_zcl_msg_start_time
384 * this function decodes start time, with peculiarity case for
385 * messaging specifications.
387 * guint *s - string to display
388 * guint32 value - value to decode
391 *---------------------------------------------------------------
394 decode_zcl_msg_start_time(gchar
*s
, guint32 value
)
396 if (value
== ZBEE_ZCL_MSG_START_TIME_NOW
)
397 g_snprintf(s
, ITEM_LABEL_LENGTH
, "Now");
399 value
+= ZBEE_ZCL_NSTIME_UTC_OFFSET
;
400 g_snprintf(s
, ITEM_LABEL_LENGTH
, "%s", abs_time_secs_to_str (value
, ABSOLUTE_TIME_LOCAL
, TRUE
));
402 } /* decode_zcl_msg_start_time */
405 /*FUNCTION:------------------------------------------------------
407 * proto_register_zbee_zcl_msg
409 * this function registers the ZCL Messaging dissector
410 * and all its information.
415 *---------------------------------------------------------------
418 proto_register_zbee_zcl_msg(void)
420 static hf_register_info hf
[] = {
422 { &hf_zbee_zcl_msg_srv_tx_cmd_id
,
423 { "Command", "zbee_zcl_se.msg.cmd.srv_tx.id", FT_UINT8
, BASE_HEX
, VALS(zbee_zcl_msg_srv_tx_cmd_names
),
424 0x00, NULL
, HFILL
} },
426 { &hf_zbee_zcl_msg_srv_rx_cmd_id
,
427 { "Command", "zbee_zcl_se.msg.cmd.srv_rx.id", FT_UINT8
, BASE_HEX
, VALS(zbee_zcl_msg_srv_rx_cmd_names
),
428 0x00, NULL
, HFILL
} },
430 { &hf_zbee_zcl_msg_message_id
,
431 { "Message ID", "zbee_zcl_se.msg.message.id", FT_UINT32
, BASE_HEX
, NULL
,
432 0x00, NULL
, HFILL
} },
434 /* Start of 'Message Control' fields */
435 { &hf_zbee_zcl_msg_ctrl_tx
,
436 { "Transmission", "zbee_zcl_se.msg.message.ctrl.tx", FT_UINT8
, BASE_HEX
, VALS(zbee_zcl_msg_ctrl_tx_names
),
437 ZBEE_ZCL_MSG_CTRL_TX_MASK
, NULL
, HFILL
} },
439 { &hf_zbee_zcl_msg_ctrl_importance
,
440 { "Importance", "zbee_zcl_se.msg.message.ctrl.importance", FT_UINT8
, BASE_HEX
, VALS(zbee_zcl_msg_ctrl_importance_names
),
441 ZBEE_ZCL_MSG_CTRL_IMPORTANCE_MASK
, NULL
, HFILL
} },
443 { &hf_zbee_zcl_msg_ctrl_reserved
,
444 { "Reserved", "zbee_zcl_se.msg.message.ctrl.reserved", FT_UINT8
, BASE_HEX
, NULL
,
445 ZBEE_ZCL_MSG_CTRL_RESERVED_MASK
, NULL
, HFILL
} },
447 { &hf_zbee_zcl_msg_ctrl_confirm
,
448 { "Confirmation", "zbee_zcl_se.msg.message.ctrl.confirm", FT_BOOLEAN
, 8, TFS(&tfs_requested_not_requested
),
449 ZBEE_ZCL_MSG_CTRL_CONFIRM_MASK
, NULL
, HFILL
} },
450 /* End of 'Message Control' fields */
452 { &hf_zbee_zcl_msg_start_time
,
453 { "Start Time", "zbee_zcl_se.msg.message.start_time", FT_UINT32
, BASE_CUSTOM
, decode_zcl_msg_start_time
,
454 0x00, NULL
, HFILL
} },
456 { &hf_zbee_zcl_msg_duration
,
457 { "Duration", "zbee_zcl_se.msg.message.duration", FT_UINT16
, BASE_CUSTOM
, decode_zcl_msg_duration
,
458 0x00, NULL
, HFILL
} },
460 { &hf_zbee_zcl_msg_message_length
,
461 { "Message Length", "zbee_zcl_se.msg.message.length", FT_UINT8
, BASE_DEC
, NULL
,
462 0x00, NULL
, HFILL
} },
464 { &hf_zbee_zcl_msg_message
,
465 { "Message", "zbee_zcl_se.msg.message", FT_STRING
, BASE_NONE
, NULL
,
466 0x00, NULL
, HFILL
} },
468 { &hf_zbee_zcl_msg_confirm_time
,
469 { "Confirmation Time", "zbee_zcl_se.msg.message.confirm_time", FT_ABSOLUTE_TIME
, ABSOLUTE_TIME_LOCAL
, NULL
,
474 /* ZCL Messaging subtrees */
475 gint
*ett
[ZBEE_ZCL_MSG_NUM_ETT
];
477 ett
[0] = &ett_zbee_zcl_msg
;
478 ett
[1] = &ett_zbee_zcl_msg_message_control
;
480 /* Register the ZigBee ZCL Messaging cluster protocol name and description */
481 proto_zbee_zcl_msg
= proto_register_protocol("ZigBee ZCL Messaging", "ZCL Messaging", ZBEE_PROTOABBREV_ZCL_MSG
);
482 proto_register_field_array(proto_zbee_zcl_msg
, hf
, array_length(hf
));
483 proto_register_subtree_array(ett
, array_length(ett
));
485 /* Register the ZigBee ZCL Messaging dissector. */
486 new_register_dissector(ZBEE_PROTOABBREV_ZCL_MSG
, dissect_zbee_zcl_msg
, proto_zbee_zcl_msg
);
488 } /*proto_register_zbee_zcl_msg*/
491 /*FUNCTION:------------------------------------------------------
493 * proto_reg_handoff_zbee_zcl_msg
495 * Hands off the Zcl Messaging dissector.
500 *---------------------------------------------------------------
503 proto_reg_handoff_zbee_zcl_msg(void)
505 dissector_handle_t msg_handle
;
507 /* Register our dissector with the ZigBee application dissectors. */
508 msg_handle
= find_dissector(ZBEE_PROTOABBREV_ZCL_MSG
);
509 dissector_add_uint("zbee.zcl.cluster", ZBEE_ZCL_CID_MESSAGE
, msg_handle
);
511 zbee_zcl_init_cluster( proto_zbee_zcl_msg
,
513 ZBEE_ZCL_CID_MESSAGE
,
517 } /*proto_reg_handoff_zbee_zcl_msg*/