2 * Dissector routines for the ZigBee Network Layer (NWK)
3 * By Owen Kirby <osk@exegin.com>
4 * Copyright 2009 Exegin Technologies Limited
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
34 #include <epan/packet.h>
35 #include <epan/exceptions.h>
36 #include <epan/prefs.h>
37 #include <epan/addr_resolv.h>
38 #include <epan/expert.h>
39 #include <epan/wmem/wmem.h>
41 #include "packet-ieee802154.h"
42 #include "packet-zbee.h"
43 #include "packet-zbee-nwk.h"
44 #include "packet-zbee-security.h"
46 /*************************/
47 /* Function Declarations */
48 /*************************/
49 /* Dissector Routines */
50 static int dissect_zbee_nwk (tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data
);
51 static void dissect_zbee_nwk_cmd (tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, zbee_nwk_packet
* packet
);
52 static int dissect_zbee_beacon (tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data
);
54 /* Command Dissector Helpers */
55 static guint
dissect_zbee_nwk_route_req (tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
,
56 zbee_nwk_packet
* packet
, guint offset
);
57 static guint
dissect_zbee_nwk_route_rep (tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, guint offset
, guint8 version
);
58 static guint
dissect_zbee_nwk_status (tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, guint offset
);
59 static guint
dissect_zbee_nwk_leave (tvbuff_t
*tvb
, proto_tree
*tree
, guint offset
);
60 static guint
dissect_zbee_nwk_route_rec (tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
,
61 zbee_nwk_packet
* packet
, guint offset
);
62 static guint
dissect_zbee_nwk_rejoin_req (tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
,
63 zbee_nwk_packet
* packet
, guint offset
);
64 static guint
dissect_zbee_nwk_rejoin_resp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
,
65 zbee_nwk_packet
* packet
, guint offset
);
66 static guint
dissect_zbee_nwk_link_status(tvbuff_t
*tvb
, proto_tree
*tree
, guint offset
);
67 static guint
dissect_zbee_nwk_report (tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, guint offset
);
68 static guint
dissect_zbee_nwk_update (tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, guint offset
);
69 static void proto_init_zbee_nwk (void);
70 void proto_register_zbee_nwk(void);
71 void proto_reg_handoff_zbee_nwk(void);
73 /********************/
74 /* Global Variables */
75 /********************/
76 static int proto_zbee_nwk
= -1;
77 static int hf_zbee_nwk_frame_type
= -1;
78 static int hf_zbee_nwk_proto_version
= -1;
79 static int hf_zbee_nwk_discover_route
= -1;
80 static int hf_zbee_nwk_multicast
= -1;
81 static int hf_zbee_nwk_security
= -1;
82 static int hf_zbee_nwk_source_route
= -1;
83 static int hf_zbee_nwk_ext_dst
= -1;
84 static int hf_zbee_nwk_ext_src
= -1;
85 static int hf_zbee_nwk_dst
= -1;
86 static int hf_zbee_nwk_src
= -1;
87 static int hf_zbee_nwk_radius
= -1;
88 static int hf_zbee_nwk_seqno
= -1;
89 static int hf_zbee_nwk_mcast_mode
= -1;
90 static int hf_zbee_nwk_mcast_radius
= -1;
91 static int hf_zbee_nwk_mcast_max_radius
= -1;
92 static int hf_zbee_nwk_dst64
= -1;
93 static int hf_zbee_nwk_src64
= -1;
94 static int hf_zbee_nwk_src64_origin
= -1;
95 static int hf_zbee_nwk_relay_count
= -1;
96 static int hf_zbee_nwk_relay_index
= -1;
98 static int hf_zbee_nwk_cmd_id
= -1;
99 static int hf_zbee_nwk_cmd_addr
= -1;
100 static int hf_zbee_nwk_cmd_route_id
= -1;
101 static int hf_zbee_nwk_cmd_route_dest
= -1;
102 static int hf_zbee_nwk_cmd_route_orig
= -1;
103 static int hf_zbee_nwk_cmd_route_resp
= -1;
104 static int hf_zbee_nwk_cmd_route_dest_ext
= -1;
105 static int hf_zbee_nwk_cmd_route_orig_ext
= -1;
106 static int hf_zbee_nwk_cmd_route_resp_ext
= -1;
107 static int hf_zbee_nwk_cmd_route_cost
= -1;
108 static int hf_zbee_nwk_cmd_route_opt_repair
= -1;
109 static int hf_zbee_nwk_cmd_route_opt_multicast
= -1;
110 static int hf_zbee_nwk_cmd_route_opt_dest_ext
= -1;
111 static int hf_zbee_nwk_cmd_route_opt_resp_ext
= -1;
112 static int hf_zbee_nwk_cmd_route_opt_orig_ext
= -1;
113 static int hf_zbee_nwk_cmd_route_opt_many_to_one
= -1;
114 static int hf_zbee_nwk_cmd_nwk_status
= -1;
115 static int hf_zbee_nwk_cmd_leave_rejoin
= -1;
116 static int hf_zbee_nwk_cmd_leave_request
= -1;
117 static int hf_zbee_nwk_cmd_leave_children
= -1;
118 static int hf_zbee_nwk_cmd_relay_count
= -1;
119 static int hf_zbee_nwk_cmd_cinfo_alt_coord
= -1;
120 static int hf_zbee_nwk_cmd_cinfo_type
= -1;
121 static int hf_zbee_nwk_cmd_cinfo_power
= -1;
122 static int hf_zbee_nwk_cmd_cinfo_idle_rx
= -1;
123 static int hf_zbee_nwk_cmd_cinfo_security
= -1;
124 static int hf_zbee_nwk_cmd_cinfo_alloc
= -1;
125 static int hf_zbee_nwk_cmd_rejoin_status
= -1;
126 static int hf_zbee_nwk_cmd_link_last
= -1;
127 static int hf_zbee_nwk_cmd_link_first
= -1;
128 static int hf_zbee_nwk_cmd_link_count
= -1;
129 static int hf_zbee_nwk_cmd_report_type
= -1;
130 static int hf_zbee_nwk_cmd_report_count
= -1;
131 static int hf_zbee_nwk_cmd_update_type
= -1;
132 static int hf_zbee_nwk_cmd_update_count
= -1;
133 static int hf_zbee_nwk_cmd_update_id
= -1;
134 static int hf_zbee_nwk_cmd_epid
= -1;
137 static int hf_zbee_beacon_protocol
= -1;
138 static int hf_zbee_beacon_stack_profile
= -1;
139 static int hf_zbee_beacon_version
= -1;
140 static int hf_zbee_beacon_router_capacity
= -1;
141 static int hf_zbee_beacon_depth
= -1;
142 static int hf_zbee_beacon_end_device_capacity
= -1;
143 static int hf_zbee_beacon_epid
= -1;
144 static int hf_zbee_beacon_tx_offset
= -1;
145 static int hf_zbee_beacon_update_id
= -1;
147 static gint ett_zbee_nwk
= -1;
148 static gint ett_zbee_beacon
= -1;
149 static gint ett_zbee_nwk_fcf
= -1;
150 static gint ett_zbee_nwk_mcast
= -1;
151 static gint ett_zbee_nwk_route
= -1;
152 static gint ett_zbee_nwk_cmd
= -1;
153 static gint ett_zbee_nwk_cmd_options
= -1;
154 static gint ett_zbee_nwk_cmd_cinfo
= -1;
156 static expert_field ei_zbee_nwk_missing_payload
= EI_INIT
;
158 static dissector_handle_t data_handle
;
159 static dissector_handle_t aps_handle
;
161 /********************/
163 /********************/
165 static const value_string zbee_nwk_frame_types
[] = {
166 { ZBEE_NWK_FCF_DATA
, "Data" },
167 { ZBEE_NWK_FCF_CMD
, "Command" },
171 /* Route Discovery Modes */
172 static const value_string zbee_nwk_discovery_modes
[] = {
173 { ZBEE_NWK_FCF_DISCOVERY_SUPPRESS
, "Suppress" },
174 { ZBEE_NWK_FCF_DISCOVERY_ENABLE
, "Enable" },
175 { ZBEE_NWK_FCF_DISCOVERY_FORCE
, "Force" },
180 static const value_string zbee_nwk_cmd_names
[] = {
181 { ZBEE_NWK_CMD_ROUTE_REQ
, "Route Request" },
182 { ZBEE_NWK_CMD_ROUTE_REPLY
, "Route Reply" },
183 { ZBEE_NWK_CMD_NWK_STATUS
, "Network Status" },
184 { ZBEE_NWK_CMD_LEAVE
, "Leave" },
185 { ZBEE_NWK_CMD_ROUTE_RECORD
, "Route Record" },
186 { ZBEE_NWK_CMD_REJOIN_REQ
, "Rejoin Request" },
187 { ZBEE_NWK_CMD_REJOIN_RESP
, "Rejoin Response" },
188 { ZBEE_NWK_CMD_LINK_STATUS
, "Link Status" },
189 { ZBEE_NWK_CMD_NWK_REPORT
, "Network Report" },
190 { ZBEE_NWK_CMD_NWK_UPDATE
, "Network Update" },
194 /* Many-To-One Route Discovery Modes. */
195 static const value_string zbee_nwk_cmd_route_many_modes
[] = {
196 { ZBEE_NWK_CMD_ROUTE_OPTION_MANY_NONE
, "Not Many-to-One" },
197 { ZBEE_NWK_CMD_ROUTE_OPTION_MANY_REC
, "With Source Routing" },
198 { ZBEE_NWK_CMD_ROUTE_OPTION_MANY_NOREC
, "Without Source Routing" },
202 /* Rejoin Status Codes */
203 static const value_string zbee_nwk_rejoin_codes
[] = {
204 { IEEE802154_CMD_ASRSP_AS_SUCCESS
, "Success" },
205 { IEEE802154_CMD_ASRSP_PAN_FULL
, "PAN Full" },
206 { IEEE802154_CMD_ASRSP_PAN_DENIED
, "PAN Access Denied" },
210 /* Network Report Types */
211 static const value_string zbee_nwk_report_types
[] = {
212 { ZBEE_NWK_CMD_NWK_REPORT_ID_PAN_CONFLICT
, "PAN Identifier Conflict" },
216 /* Network Update Types */
217 static const value_string zbee_nwk_update_types
[] = {
218 { ZBEE_NWK_CMD_NWK_UPDATE_ID_PAN_UPDATE
, "PAN Identifier Update" },
222 /* Network Status Codes */
223 static const value_string zbee_nwk_status_codes
[] = {
224 { ZBEE_NWK_STATUS_NO_ROUTE_AVAIL
, "No Route Available" },
225 { ZBEE_NWK_STATUS_TREE_LINK_FAIL
, "Tree Link Failure" },
226 { ZBEE_NWK_STATUS_NON_TREE_LINK_FAIL
, "Non-tree Link Failure" },
227 { ZBEE_NWK_STATUS_LOW_BATTERY
, "Low Battery" },
228 { ZBEE_NWK_STATUS_NO_ROUTING
, "No Routing Capacity" },
229 { ZBEE_NWK_STATUS_NO_INDIRECT
, "No Indirect Capacity" },
230 { ZBEE_NWK_STATUS_INDIRECT_EXPIRE
, "Indirect Transaction Expiry" },
231 { ZBEE_NWK_STATUS_DEVICE_UNAVAIL
, "Target Device Unavailable" },
232 { ZBEE_NWK_STATUS_ADDR_UNAVAIL
, "Target Address Unallocated" },
233 { ZBEE_NWK_STATUS_PARENT_LINK_FAIL
, "Parent Link Failure" },
234 { ZBEE_NWK_STATUS_VALIDATE_ROUTE
, "Validate Route" },
235 { ZBEE_NWK_STATUS_SOURCE_ROUTE_FAIL
, "Source Route Failure" },
236 { ZBEE_NWK_STATUS_MANY_TO_ONE_FAIL
, "Many-to-One Route Failure" },
237 { ZBEE_NWK_STATUS_ADDRESS_CONFLICT
, "Address Conflict" },
238 { ZBEE_NWK_STATUS_VERIFY_ADDRESS
, "Verify Address" },
239 { ZBEE_NWK_STATUS_PANID_UPDATE
, "PAN ID Update" },
240 { ZBEE_NWK_STATUS_ADDRESS_UPDATE
, "Network Address Update" },
241 { ZBEE_NWK_STATUS_BAD_FRAME_COUNTER
, "Bad Frame Counter" },
242 { ZBEE_NWK_STATUS_BAD_KEY_SEQNO
, "Bad Key Sequence Number" },
246 /* Stack Profile Values. */
247 static const value_string zbee_nwk_stack_profiles
[] = {
248 { 0x00, "Network Specific" },
249 { 0x01, "ZigBee Home" },
250 { 0x02, "ZigBee PRO" },
254 /* TODO: much of the following copied from ieee80154 dissector */
255 /*-------------------------------------
256 * Hash Tables and Lists
257 *-------------------------------------
259 ieee802154_map_tab_t zbee_nwk_map
= { NULL
, NULL
};
260 GHashTable
*zbee_table_nwk_keyring
= NULL
;
261 GHashTable
*zbee_table_link_keyring
= NULL
;
263 /*FUNCTION:------------------------------------------------------
267 * Extracts an integer sub-field from an int with a given mask
268 * if the mask is 0, this will return 0, if the mask is non-
269 * continuous the output is undefined.
275 *---------------------------------------------------------------
278 zbee_get_bit_field(guint input
, guint mask
)
280 /* Sanity Check, don't want infinite loops. */
281 if (mask
== 0) return 0;
282 /* Shift input and mask together. */
283 while (!(mask
& 0x1)) {
287 return (input
& mask
);
288 } /* zbee_get_bit_field */
290 /*FUNCTION:------------------------------------------------------
292 * dissect_zbee_nwk_heur
294 * Heuristic interpreter for the ZigBee network dissectors.
296 * tvbuff_t *tvb - pointer to buffer containing raw packet.
297 * packet_into *pinfo - pointer to packet information fields
298 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
300 * Boolean value, whether it handles the packet or not.
301 *---------------------------------------------------------------
304 dissect_zbee_nwk_heur(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data
)
306 ieee802154_packet
*packet
= (ieee802154_packet
*)data
;
308 /* All ZigBee frames must always have a 16-bit source address. */
309 if (packet
->src_addr_mode
!= IEEE802154_FCF_ADDR_SHORT
) {
312 /* ZigBee MAC frames must always contain a 16-bit destination address. */
313 if ( (packet
->frame_type
== IEEE802154_FCF_DATA
) &&
314 (packet
->dst_addr_mode
== IEEE802154_FCF_ADDR_SHORT
) ) {
315 dissect_zbee_nwk(tvb
, pinfo
, tree
, packet
);
318 /* ZigBee MAC Beacons must have the first byte (protocol ID) equal to the
319 * ZigBee protocol ID. */
320 if ( (packet
->frame_type
== IEEE802154_FCF_BEACON
) &&
321 (tvb_get_guint8(tvb
, 0) == ZBEE_NWK_BEACON_PROCOL_ID
) ) {
322 dissect_zbee_beacon(tvb
, pinfo
, tree
, packet
);
325 /* If we get this far, then this packet did not meet the requirements for
329 } /* dissect_zbee_heur */
331 /*FUNCTION:------------------------------------------------------
335 * ZigBee packet dissection routine for Wireshark.
337 * tvbuff_t *tvb - pointer to buffer containing raw packet.
338 * packet_into *pinfo - pointer to packet information fields
339 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
342 *---------------------------------------------------------------
345 dissect_zbee_nwk(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data
)
347 tvbuff_t
*payload_tvb
= NULL
;
349 proto_item
*proto_root
= NULL
;
350 proto_item
*ti
= NULL
;
351 proto_tree
*nwk_tree
= NULL
;
352 proto_tree
*field_tree
= NULL
;
354 zbee_nwk_packet packet
;
355 ieee802154_packet
*ieee_packet
= (ieee802154_packet
*)data
;
358 static gchar src_addr
[32], dst_addr
[32]; /* has to be static due to SET_ADDRESS */
362 ieee802154_short_addr addr16
;
363 ieee802154_map_rec
*map_rec
;
364 ieee802154_hints_t
*ieee_hints
;
366 zbee_nwk_hints_t
*nwk_hints
;
367 gboolean unicast_src
;
369 memset(&packet
, 0, sizeof(packet
));
371 /* Set up hint structures */
372 if (!pinfo
->fd
->flags
.visited
) {
373 /* Allocate frame data with hints for upper layers */
374 nwk_hints
= wmem_new0(wmem_file_scope(), zbee_nwk_hints_t
);
375 p_add_proto_data(pinfo
->fd
, proto_zbee_nwk
, 0, nwk_hints
);
377 /* Retrieve existing structure */
378 nwk_hints
= (zbee_nwk_hints_t
*)p_get_proto_data(pinfo
->fd
, proto_zbee_nwk
, 0);
381 ieee_hints
= (ieee802154_hints_t
*)p_get_proto_data(pinfo
->fd
,
382 proto_get_id_by_filter_name(IEEE802154_PROTOABBREV_WPAN
), 0);
384 /* Add ourself to the protocol column, clear the info column, and create the protocol tree. */
385 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "ZigBee");
386 col_clear(pinfo
->cinfo
, COL_INFO
);
388 proto_root
= proto_tree_add_protocol_format(tree
, proto_zbee_nwk
, tvb
, offset
,
389 tvb_length(tvb
), "ZigBee Network Layer");
390 nwk_tree
= proto_item_add_subtree(proto_root
, ett_zbee_nwk
);
393 /* Get and parse the FCF */
394 fcf
= tvb_get_letohs(tvb
, offset
);
395 packet
.type
= zbee_get_bit_field(fcf
, ZBEE_NWK_FCF_FRAME_TYPE
);
396 packet
.version
= zbee_get_bit_field(fcf
, ZBEE_NWK_FCF_VERSION
);
397 packet
.discovery
= zbee_get_bit_field(fcf
, ZBEE_NWK_FCF_DISCOVER_ROUTE
);
398 packet
.security
= zbee_get_bit_field(fcf
, ZBEE_NWK_FCF_SECURITY
);
399 packet
.multicast
= zbee_get_bit_field(fcf
, ZBEE_NWK_FCF_MULTICAST
);
400 packet
.route
= zbee_get_bit_field(fcf
, ZBEE_NWK_FCF_SOURCE_ROUTE
);
401 packet
.ext_dst
= zbee_get_bit_field(fcf
, ZBEE_NWK_FCF_EXT_DEST
);
402 packet
.ext_src
= zbee_get_bit_field(fcf
, ZBEE_NWK_FCF_EXT_SOURCE
);
404 /* Display the FCF. */
406 /* Create a subtree for the FCF. */
407 ti
= proto_tree_add_text(nwk_tree
, tvb
, offset
, 2, "Frame Control Field: %s (0x%04x)",
408 val_to_str_const(packet
.type
, zbee_nwk_frame_types
, "Unknown"), fcf
);
409 field_tree
= proto_item_add_subtree(ti
, ett_zbee_nwk_fcf
);
410 proto_tree_add_uint(field_tree
, hf_zbee_nwk_frame_type
, tvb
, offset
, 1,
411 fcf
& ZBEE_NWK_FCF_FRAME_TYPE
);
413 /* Add the rest of the fcf fields to the subtree */
414 proto_tree_add_uint(field_tree
, hf_zbee_nwk_proto_version
, tvb
, offset
, 1,
415 fcf
& ZBEE_NWK_FCF_VERSION
);
416 proto_tree_add_uint(field_tree
, hf_zbee_nwk_discover_route
, tvb
, offset
, 1,
417 fcf
& ZBEE_NWK_FCF_DISCOVER_ROUTE
);
418 if (packet
.version
>= ZBEE_VERSION_2007
) {
419 proto_tree_add_boolean(field_tree
, hf_zbee_nwk_multicast
, tvb
, offset
+1,
420 1, fcf
& ZBEE_NWK_FCF_MULTICAST
);
422 proto_tree_add_boolean(field_tree
, hf_zbee_nwk_security
, tvb
, offset
+1,
423 1, fcf
& ZBEE_NWK_FCF_SECURITY
);
424 if (packet
.version
>= ZBEE_VERSION_2007
) {
425 proto_tree_add_boolean(field_tree
, hf_zbee_nwk_source_route
, tvb
, offset
+1,
426 1, fcf
& ZBEE_NWK_FCF_SOURCE_ROUTE
);
427 proto_tree_add_boolean(field_tree
, hf_zbee_nwk_ext_dst
, tvb
, offset
+1,
428 1, fcf
& ZBEE_NWK_FCF_EXT_DEST
);
429 proto_tree_add_boolean(field_tree
, hf_zbee_nwk_ext_src
, tvb
, offset
+1,
430 1, fcf
& ZBEE_NWK_FCF_EXT_SOURCE
);
435 /* Add the frame type to the info column and protocol root. */
437 proto_item_append_text(proto_root
, " %s", val_to_str_const(packet
.type
, zbee_nwk_frame_types
, "Unknown Type"));
439 col_set_str(pinfo
->cinfo
, COL_INFO
, val_to_str_const(packet
.type
, zbee_nwk_frame_types
, "Reserved Frame Type"));
441 /* Get the destination address. */
442 packet
.dst
= tvb_get_letohs(tvb
, offset
);
443 proto_tree_add_uint(nwk_tree
, hf_zbee_nwk_dst
, tvb
, offset
, 2, packet
.dst
);
447 /* Display the destination address. */
448 if ( (packet
.dst
== ZBEE_BCAST_ALL
)
449 || (packet
.dst
== ZBEE_BCAST_ACTIVE
)
450 || (packet
.dst
== ZBEE_BCAST_ROUTERS
)){
451 g_snprintf(dst_addr
, 32, "Broadcast");
454 g_snprintf(dst_addr
, 32, "0x%04x", packet
.dst
);
457 SET_ADDRESS(&pinfo
->dst
, AT_STRINGZ
, (int)strlen(dst_addr
)+1, dst_addr
);
458 SET_ADDRESS(&pinfo
->net_dst
, AT_STRINGZ
, (int)strlen(dst_addr
)+1, dst_addr
);
461 proto_item_append_text(proto_root
, ", Dst: %s", dst_addr
);
463 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ", Dst: %s", dst_addr
);
466 /* Get the short nwk source address and pass it to upper layers */
467 packet
.src
= tvb_get_letohs(tvb
, offset
);
468 if (nwk_hints
) nwk_hints
->src
= packet
.src
;
470 proto_tree_add_uint(nwk_tree
, hf_zbee_nwk_src
, tvb
, offset
, 2, packet
.src
);
474 /* Display the source address. */
475 if ( (packet
.src
== ZBEE_BCAST_ALL
)
476 || (packet
.src
== ZBEE_BCAST_ACTIVE
)
477 || (packet
.src
== ZBEE_BCAST_ROUTERS
)){
478 /* Source Broadcast doesn't make much sense. */
479 g_snprintf(src_addr
, 32, "Unexpected Source Broadcast");
483 g_snprintf(src_addr
, 32, "0x%04x", packet
.src
);
487 SET_ADDRESS(&pinfo
->src
, AT_STRINGZ
, (int)strlen(src_addr
)+1, src_addr
);
488 SET_ADDRESS(&pinfo
->net_src
, AT_STRINGZ
, (int)strlen(src_addr
)+1, src_addr
);
491 proto_item_append_text(proto_root
, ", Src: %s", src_addr
);
493 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ", Src: %s", src_addr
);
495 /* Get and display the radius. */
496 packet
.radius
= tvb_get_guint8(tvb
, offset
);
498 proto_tree_add_uint(nwk_tree
, hf_zbee_nwk_radius
, tvb
, offset
, 1, packet
.radius
);
502 /* Get and display the sequence number. */
503 packet
.seqno
= tvb_get_guint8(tvb
, offset
);
505 proto_tree_add_uint(nwk_tree
, hf_zbee_nwk_seqno
, tvb
, offset
, 1, packet
.seqno
);
509 /* Add Multicast control field. (ZigBee 2006 and later). */
510 if ((packet
.version
>= ZBEE_VERSION_2007
) && packet
.multicast
) {
511 guint8 mcast_control
= tvb_get_guint8(tvb
, offset
);
513 packet
.mcast_mode
= zbee_get_bit_field(mcast_control
, ZBEE_NWK_MCAST_MODE
);
514 packet
.mcast_radius
= zbee_get_bit_field(mcast_control
, ZBEE_NWK_MCAST_RADIUS
);
515 packet
.mcast_max_radius
= zbee_get_bit_field(mcast_control
, ZBEE_NWK_MCAST_MAX_RADIUS
);
517 /* Create a subtree for the multicast control field. */
518 ti
= proto_tree_add_text(nwk_tree
, tvb
, offset
, 1, "Multicast Control Field");
519 field_tree
= proto_item_add_subtree(ti
, ett_zbee_nwk_mcast
);
520 /* Add the fields. */
521 ti
= proto_tree_add_uint(field_tree
, hf_zbee_nwk_mcast_mode
, tvb
, offset
, 1,
522 mcast_control
& ZBEE_NWK_MCAST_MODE
);
523 proto_tree_add_uint(field_tree
, hf_zbee_nwk_mcast_radius
, tvb
, offset
, 1,
524 mcast_control
& ZBEE_NWK_MCAST_RADIUS
);
525 proto_tree_add_uint(field_tree
, hf_zbee_nwk_mcast_max_radius
, tvb
, offset
, 1,
526 mcast_control
& ZBEE_NWK_MCAST_MAX_RADIUS
);
531 /* Add the extended destination address (ZigBee 2006 and later). */
532 if ((packet
.version
>= ZBEE_VERSION_2007
) && packet
.ext_dst
) {
533 packet
.dst64
= tvb_get_letoh64(tvb
, offset
);
535 proto_tree_add_item(nwk_tree
, hf_zbee_nwk_dst64
, tvb
, offset
, 8, ENC_LITTLE_ENDIAN
);
540 /* Display the extended source address. (ZigBee 2006 and later). */
541 if (packet
.version
>= ZBEE_VERSION_2007
) {
542 addr16
.pan
= ieee_packet
->src_pan
;
544 if (packet
.ext_src
) {
545 packet
.src64
= tvb_get_letoh64(tvb
, offset
);
546 proto_tree_add_item(nwk_tree
, hf_zbee_nwk_src64
, tvb
, offset
, 8, ENC_LITTLE_ENDIAN
);
549 if (!pinfo
->fd
->flags
.visited
&& nwk_hints
) {
550 /* Provide hints to upper layers */
551 nwk_hints
->src_pan
= ieee_packet
->src_pan
;
553 /* Update nwk extended address hash table */
555 nwk_hints
->map_rec
= ieee802154_addr_update(&zbee_nwk_map
,
556 packet
.src
, addr16
.pan
, packet
.src64
, pinfo
->current_proto
, pinfo
->fd
->num
);
561 /* See if extended source info was previously sniffed */
562 if (!pinfo
->fd
->flags
.visited
&& nwk_hints
) {
563 nwk_hints
->src_pan
= ieee_packet
->src_pan
;
564 addr16
.addr
= packet
.src
;
566 map_rec
= (ieee802154_map_rec
*) g_hash_table_lookup(zbee_nwk_map
.short_table
, &addr16
);
568 /* found a nwk mapping record */
569 nwk_hints
->map_rec
= map_rec
;
572 /* does ieee layer know? */
573 map_rec
= (ieee802154_map_rec
*) g_hash_table_lookup(ieee_packet
->short_table
, &addr16
);
574 if (map_rec
) nwk_hints
->map_rec
= map_rec
;
576 } /* (!pinfo->fd->flags.visited) */
578 if (tree
&& nwk_hints
&& nwk_hints
->map_rec
) {
579 /* Display inferred source address info */
580 ti
= proto_tree_add_eui64(nwk_tree
, hf_zbee_nwk_src64
, tvb
, offset
, 0,
581 nwk_hints
->map_rec
->addr64
);
582 PROTO_ITEM_SET_GENERATED(ti
);
584 if ( nwk_hints
->map_rec
->start_fnum
) {
585 ti
= proto_tree_add_uint(nwk_tree
, hf_zbee_nwk_src64_origin
, tvb
, 0, 0,
586 nwk_hints
->map_rec
->start_fnum
);
589 ti
= proto_tree_add_text(nwk_tree
, tvb
, 0, 0, "Origin: Pre-configured");
591 PROTO_ITEM_SET_GENERATED(ti
);
596 /* If ieee layer didn't know its extended source address, and nwk layer does, fill it in */
597 if (!pinfo
->fd
->flags
.visited
) {
598 if ( (ieee_packet
->src_addr_mode
== IEEE802154_FCF_ADDR_SHORT
) &&
599 ieee_hints
&& !ieee_hints
->map_rec
) {
600 addr16
.pan
= ieee_packet
->src_pan
;
601 addr16
.addr
= ieee_packet
->src16
;
602 map_rec
= (ieee802154_map_rec
*) g_hash_table_lookup(zbee_nwk_map
.short_table
, &addr16
);
605 /* found a ieee mapping record */
606 ieee_hints
->map_rec
= map_rec
;
609 } /* (!pinfo->fd->flags.visited */
610 } /* (pinfo->zbee_stack_vers >= ZBEE_VERSION_2007) */
612 /* Add the Source Route field. (ZigBee 2006 and later). */
613 if ((packet
.version
>= ZBEE_VERSION_2007
) && packet
.route
) {
620 /* Create a subtree for the source route field. */
621 ti
= proto_tree_add_text(nwk_tree
, tvb
, offset
, 1, "Source Route");
622 field_tree
= proto_item_add_subtree(ti
, ett_zbee_nwk_route
);
625 /* Get and display the relay count. */
626 relay_count
= tvb_get_guint8(tvb
, offset
);
628 proto_tree_add_uint(field_tree
, hf_zbee_nwk_relay_count
, tvb
, offset
, 1, relay_count
);
629 proto_item_append_text(ti
, ", Length: %d", relay_count
);
634 /* Correct the length of the source route fields. */
635 proto_item_set_len(ti
, 1 + relay_count
*2);
638 /* Get and display the relay index. */
639 relay_index
= tvb_get_guint8(tvb
, offset
);
640 proto_tree_add_uint(field_tree
, hf_zbee_nwk_relay_index
, tvb
, offset
, 1, relay_index
);
644 /* Get and display the relay list. */
645 for (i
=0; i
<relay_count
; i
++) {
646 relay_addr
= tvb_get_letohs(tvb
, offset
);
648 proto_tree_add_text(field_tree
, tvb
, offset
, 2, "Relay %d: 0x%04x", i
+1, relay_addr
);
655 * Ensure that the payload exists. There are no valid ZigBee network
656 * packets that have no payload.
658 if (offset
>= tvb_length(tvb
)) {
659 /* Non-existent or truncated payload. */
660 expert_add_info(pinfo
, proto_root
, &ei_zbee_nwk_missing_payload
);
663 /* Payload is encrypted, attempt security operations. */
664 else if (packet
.security
) {
665 payload_tvb
= dissect_zbee_secure(tvb
, pinfo
, nwk_tree
, offset
);
666 if (payload_tvb
== NULL
) {
667 /* If Payload_tvb is NULL, then the security dissector cleaned up. */
668 return tvb_length(tvb
);
671 /* Plaintext payload. */
673 payload_tvb
= tvb_new_subset_remaining(tvb
, offset
);
676 if (packet
.type
== ZBEE_NWK_FCF_CMD
) {
677 /* Dissect the Network Command. */
678 dissect_zbee_nwk_cmd(payload_tvb
, pinfo
, nwk_tree
, &packet
);
680 else if (packet
.type
== ZBEE_NWK_FCF_DATA
) {
681 /* Dissect the Network Payload (APS layer). */
682 call_dissector_with_data(aps_handle
, payload_tvb
, pinfo
, tree
, &packet
);
686 call_dissector(data_handle
, payload_tvb
, pinfo
, tree
);
689 return tvb_length(tvb
);
690 } /* dissect_zbee_nwk */
692 /*FUNCTION:------------------------------------------------------
694 * dissect_zbee_nwk_cmd
696 * ZigBee Network command packet dissection routine for Wireshark.
697 * note: this dissector differs from others in that it shouldn't be
698 * passed the main tree pointer, but the nwk tree instead.
700 * tvbuff_t *tvb - pointer to buffer containing raw packet.
701 * packet_into *pinfo - pointer to packet information fields
702 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
705 *---------------------------------------------------------------
707 static void dissect_zbee_nwk_cmd(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, zbee_nwk_packet
* packet
)
709 proto_tree
*cmd_tree
= NULL
;
710 proto_item
*cmd_root
= NULL
;
713 guint8 cmd_id
= tvb_get_guint8(tvb
, offset
);
715 /* Create a subtree for this command. */
717 cmd_root
= proto_tree_add_text(tree
, tvb
, offset
, tvb_length(tvb
), "Command Frame: %s",
718 val_to_str_const(cmd_id
, zbee_nwk_cmd_names
, "Unknown"));
719 cmd_tree
= proto_item_add_subtree(cmd_root
, ett_zbee_nwk_cmd
);
721 /* Add the command ID. */
722 proto_tree_add_uint(cmd_tree
, hf_zbee_nwk_cmd_id
, tvb
, offset
, 1, cmd_id
);
726 /* Add the command name to the info column. */
727 col_set_str(pinfo
->cinfo
, COL_INFO
, val_to_str_const(cmd_id
, zbee_nwk_cmd_names
, "Unknown Command"));
730 /* Handle the command. */
732 case ZBEE_NWK_CMD_ROUTE_REQ
:
733 /* Route Request Command. */
734 offset
= dissect_zbee_nwk_route_req(tvb
, pinfo
, cmd_tree
, packet
, offset
);
737 case ZBEE_NWK_CMD_ROUTE_REPLY
:
738 /* Route Reply Command. */
739 offset
= dissect_zbee_nwk_route_rep(tvb
, pinfo
, cmd_tree
, offset
, packet
->version
);
742 case ZBEE_NWK_CMD_NWK_STATUS
:
743 /* Network Status Command. */
744 offset
= dissect_zbee_nwk_status(tvb
, pinfo
, cmd_tree
, offset
);
747 case ZBEE_NWK_CMD_LEAVE
:
749 offset
= dissect_zbee_nwk_leave(tvb
, cmd_tree
, offset
);
752 case ZBEE_NWK_CMD_ROUTE_RECORD
:
753 /* Route Record Command. */
754 offset
= dissect_zbee_nwk_route_rec(tvb
, pinfo
, cmd_tree
, packet
, offset
);
757 case ZBEE_NWK_CMD_REJOIN_REQ
:
758 /* Rejoin Request Command. */
759 offset
= dissect_zbee_nwk_rejoin_req(tvb
, pinfo
, cmd_tree
, packet
, offset
);
762 case ZBEE_NWK_CMD_REJOIN_RESP
:
763 /* Rejoin Response Command. */
764 offset
= dissect_zbee_nwk_rejoin_resp(tvb
, pinfo
, cmd_tree
, packet
, offset
);
767 case ZBEE_NWK_CMD_LINK_STATUS
:
768 /* Link Status Command. */
769 offset
= dissect_zbee_nwk_link_status(tvb
, cmd_tree
, offset
);
772 case ZBEE_NWK_CMD_NWK_REPORT
:
773 /* Network Report Command. */
774 offset
= dissect_zbee_nwk_report(tvb
, pinfo
, cmd_tree
, offset
);
777 case ZBEE_NWK_CMD_NWK_UPDATE
:
778 /* Network Update Command. */
779 offset
= dissect_zbee_nwk_update(tvb
, pinfo
, cmd_tree
, offset
);
783 /* Just break out and let the overflow handler deal with the payload. */
787 /* There is excess data in the packet. */
788 if (offset
< tvb_length(tvb
)) {
789 /* There are leftover bytes! */
790 guint leftover_len
= tvb_length(tvb
) - offset
;
791 tvbuff_t
*leftover_tvb
= tvb_new_subset(tvb
, offset
, leftover_len
, leftover_len
);
792 proto_tree
*root
= NULL
;
794 /* Correct the length of the command tree. */
796 root
= proto_tree_get_root(tree
);
797 proto_item_set_len(cmd_root
, offset
);
800 /* Dump the leftover to the data dissector. */
801 call_dissector(data_handle
, leftover_tvb
, pinfo
, root
);
803 } /* dissect_zbee_nwk_cmd */
805 /*FUNCTION:------------------------------------------------------
807 * dissect_zbee_nwk_route_req
809 * Helper dissector for the Route Request command.
811 * tvbuff_t *tvb - pointer to buffer containing raw packet.
812 * packet_into *pinfo - pointer to packet information fields
813 * proto_tree *tree - pointer to the command subtree.
814 * zbee_nwk_packet *packet - pointer to the network packet struct.
815 * offset - offset into the tvb to begin dissection.
817 * guint - offset after command dissection.
818 *---------------------------------------------------------------
821 dissect_zbee_nwk_route_req(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, zbee_nwk_packet
* packet
, guint offset
)
823 proto_tree
*field_tree
;
826 guint8 route_options
;
831 /* Get and display the route options field. */
832 route_options
= tvb_get_guint8(tvb
, offset
);
834 /* Create a subtree for the command options. */
835 ti
= proto_tree_add_text(tree
, tvb
, offset
, 1, "Command Options (0x%02x)", route_options
);
836 field_tree
= proto_item_add_subtree(ti
, ett_zbee_nwk_cmd_options
);
838 if (packet
->version
>= ZBEE_VERSION_2007
) {
839 proto_tree_add_boolean(field_tree
, hf_zbee_nwk_cmd_route_opt_multicast
, tvb
, offset
,
840 1, route_options
& ZBEE_NWK_CMD_ROUTE_OPTION_MCAST
);
841 proto_tree_add_boolean(field_tree
, hf_zbee_nwk_cmd_route_opt_dest_ext
, tvb
, offset
,
842 1, route_options
& ZBEE_NWK_CMD_ROUTE_OPTION_DEST_EXT
);
843 proto_tree_add_uint(field_tree
, hf_zbee_nwk_cmd_route_opt_many_to_one
, tvb
, offset
,
844 1, route_options
& ZBEE_NWK_CMD_ROUTE_OPTION_MANY_MASK
);
847 proto_tree_add_boolean(tree
, hf_zbee_nwk_cmd_route_opt_repair
, tvb
, offset
, 1,
848 route_options
& ZBEE_NWK_CMD_ROUTE_OPTION_REPAIR
);
853 /* Get and display the route request ID. */
854 route_id
= tvb_get_guint8(tvb
, offset
);
856 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_route_id
, tvb
, offset
, 1, route_id
);
860 /* Get and display the destination address. */
861 dest_addr
= tvb_get_letohs(tvb
, offset
);
863 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_route_dest
, tvb
, offset
, 2, dest_addr
);
867 /* Get and display the path cost. */
868 path_cost
= tvb_get_guint8(tvb
, offset
);
870 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_route_cost
, tvb
, offset
, 1, path_cost
);
874 /* Get and display the extended destination address. */
875 if (route_options
& ZBEE_NWK_CMD_ROUTE_OPTION_DEST_EXT
) {
877 proto_tree_add_item(tree
, hf_zbee_nwk_cmd_route_dest_ext
, tvb
, offset
, 8, ENC_LITTLE_ENDIAN
);
882 /* Update the info column. */
883 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ", Dst: 0x%04x, Src: 0x%04x", dest_addr
, packet
->src
);
887 } /* dissect_zbee_nwk_route_req */
889 /*FUNCTION:------------------------------------------------------
891 * dissect_zbee_nwk_route_rep
893 * Helper dissector for the Route Reply command.
895 * tvbuff_t *tvb - pointer to buffer containing raw packet.
896 * packet_into *pinfo - pointer to packet information fields
897 * proto_tree *tree - pointer to the command subtree.
898 * offset - offset into the tvb to begin dissection.
900 * guint - offset after command dissection.
901 *---------------------------------------------------------------
904 dissect_zbee_nwk_route_rep(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, guint offset
, guint8 version
)
906 proto_tree
*field_tree
;
909 guint8 route_options
;
915 /* Get and display the route options field. */
916 route_options
= tvb_get_guint8(tvb
, offset
);
918 /* Create a subtree for the command options. */
919 ti
= proto_tree_add_text(tree
, tvb
, offset
, 1, "Command Options (0x%02x)", route_options
);
920 field_tree
= proto_item_add_subtree(ti
, ett_zbee_nwk_cmd_options
);
922 if (version
>= ZBEE_VERSION_2007
) {
923 proto_tree_add_boolean(field_tree
, hf_zbee_nwk_cmd_route_opt_multicast
, tvb
, offset
, 1, route_options
& ZBEE_NWK_CMD_ROUTE_OPTION_MCAST
);
924 proto_tree_add_boolean(field_tree
, hf_zbee_nwk_cmd_route_opt_resp_ext
, tvb
, offset
, 1, route_options
& ZBEE_NWK_CMD_ROUTE_OPTION_RESP_EXT
);
925 proto_tree_add_boolean(field_tree
, hf_zbee_nwk_cmd_route_opt_orig_ext
, tvb
, offset
, 1, route_options
& ZBEE_NWK_CMD_ROUTE_OPTION_ORIG_EXT
);
928 proto_tree_add_boolean(tree
, hf_zbee_nwk_cmd_route_opt_repair
, tvb
, offset
, 1, route_options
& ZBEE_NWK_CMD_ROUTE_OPTION_REPAIR
);
933 /* Get and display the route request ID. */
934 route_id
= tvb_get_guint8(tvb
, offset
);
936 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_route_id
, tvb
, offset
, 1, route_id
);
940 /* Get and display the originator address. */
941 orig_addr
= tvb_get_letohs(tvb
, offset
);
943 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_route_orig
, tvb
, offset
, 2, orig_addr
);
947 /* Get and display the responder address. */
948 resp_addr
= tvb_get_letohs(tvb
, offset
);
950 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_route_resp
, tvb
, offset
, 2, resp_addr
);
954 /* Get and display the path cost. */
955 path_cost
= tvb_get_guint8(tvb
, offset
);
957 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_route_cost
, tvb
, offset
, 1, path_cost
);
961 /* Get and display the originator extended address. */
962 if (route_options
& ZBEE_NWK_CMD_ROUTE_OPTION_ORIG_EXT
) {
964 proto_tree_add_item(tree
, hf_zbee_nwk_cmd_route_orig_ext
, tvb
, offset
, 8, ENC_LITTLE_ENDIAN
);
969 /* Get and display the responder extended address. */
970 if (route_options
& ZBEE_NWK_CMD_ROUTE_OPTION_RESP_EXT
) {
972 proto_tree_add_item(tree
, hf_zbee_nwk_cmd_route_resp_ext
, tvb
, offset
, 8, ENC_LITTLE_ENDIAN
);
977 /* Update the info column. */
978 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ", Dst: 0x%04x, Src: 0x%04x", resp_addr
, orig_addr
);
982 } /* dissect_zbee_nwk_route_rep */
984 /*FUNCTION:------------------------------------------------------
986 * dissect_zbee_nwk_status
988 * Helper dissector for the Network Status command.
990 * tvbuff_t *tvb - pointer to buffer containing raw packet.
991 * packet_into *pinfo - pointer to packet information fields
992 * proto_tree *tree - pointer to the command subtree.
993 * offset - offset into the tvb to begin dissection.
995 * guint - offset after command dissection.
996 *---------------------------------------------------------------
999 dissect_zbee_nwk_status(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, guint offset
)
1004 /* Get and display the status code. */
1005 status_code
= tvb_get_guint8(tvb
, offset
);
1007 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_nwk_status
, tvb
, offset
, 1, status_code
);
1011 /* Get and display the destination address. */
1012 addr
= tvb_get_letohs(tvb
, offset
);
1014 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_route_dest
, tvb
, offset
, 2, addr
);
1018 /* Update the info column. */
1019 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ", 0x%04x: %s", addr
, val_to_str_const(status_code
, zbee_nwk_status_codes
, "Unknown Status Code"));
1023 } /* dissect_zbee_nwk_status */
1025 /*FUNCTION:------------------------------------------------------
1027 * dissect_zbee_nwk_leave
1029 * Helper dissector for the Leave command.
1031 * tvbuff_t *tvb - pointer to buffer containing raw packet.
1032 * proto_tree *tree - pointer to the command subtree.
1033 * offset - offset into the tvb to begin dissection.
1035 * guint - offset after command dissection.
1036 *---------------------------------------------------------------
1039 dissect_zbee_nwk_leave(tvbuff_t
*tvb
, proto_tree
*tree
, guint offset
)
1041 guint8 leave_options
;
1043 /* Get and display the leave options. */
1044 leave_options
= tvb_get_guint8(tvb
, offset
);
1046 proto_tree_add_boolean(tree
, hf_zbee_nwk_cmd_leave_rejoin
, tvb
, offset
, 1,
1047 leave_options
& ZBEE_NWK_CMD_LEAVE_OPTION_REJOIN
);
1048 proto_tree_add_boolean(tree
, hf_zbee_nwk_cmd_leave_request
, tvb
, offset
, 1,
1049 leave_options
& ZBEE_NWK_CMD_LEAVE_OPTION_REQUEST
);
1050 proto_tree_add_boolean(tree
, hf_zbee_nwk_cmd_leave_children
, tvb
, offset
, 1,
1051 leave_options
& ZBEE_NWK_CMD_LEAVE_OPTION_CHILDREN
);
1057 } /* dissect_zbee_nwk_leave */
1059 /*FUNCTION:------------------------------------------------------
1061 * dissect_zbee_nwk_route_rec
1063 * Helper dissector for the Reoute Record command.
1065 * tvbuff_t *tvb - pointer to buffer containing raw packet.
1066 * packet_into *pinfo - pointer to packet information fields
1067 * proto_tree *tree - pointer to the command subtree.
1068 * zbee_nwk_packet *packet - pointer to the network packet struct.
1069 * offset - offset into the tvb to begin dissection.
1071 * guint - offset after command dissection.
1072 *---------------------------------------------------------------
1075 dissect_zbee_nwk_route_rec(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, zbee_nwk_packet
* packet
, guint offset
)
1081 /* Get and display the relay count. */
1082 relay_count
= tvb_get_guint8(tvb
, offset
);
1084 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_relay_count
, tvb
, offset
, 1, relay_count
);
1088 /* Get and display the relay addresses. */
1089 for (i
=0; i
<relay_count
; i
++) {
1090 relay_addr
= tvb_get_letohs(tvb
, offset
);
1092 proto_tree_add_text(tree
, tvb
, offset
, 2, "Relay Device %d: 0x%04x", i
+1, relay_addr
);
1097 /* Update the info column. */
1098 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ", Dst: 0x%04x", packet
->dst
);
1103 } /* dissect_zbee_nwk_route_rec */
1105 /*FUNCTION:------------------------------------------------------
1107 * dissect_zbee_nwk_rejoin_req
1109 * Helper dissector for the Rejoin Request command.
1111 * tvbuff_t *tvb - pointer to buffer containing raw packet.
1112 * packet_into *pinfo - pointer to packet information fields
1113 * proto_tree *tree - pointer to the command subtree.
1114 * zbee_nwk_packet *packet - pointer to the network packet struct.
1115 * offset - offset into the tvb to begin dissection.
1117 * guint - offset after command dissection.
1118 *---------------------------------------------------------------
1121 dissect_zbee_nwk_rejoin_req(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, zbee_nwk_packet
* packet
, guint offset
)
1123 proto_tree
*field_tree
;
1126 guint8 capabilities
;
1128 /* Get and dispaly the capabilities information. */
1129 capabilities
= tvb_get_guint8(tvb
, offset
);
1131 /* Create a subtree for the capability information. */
1132 ti
= proto_tree_add_text(tree
, tvb
, offset
, 1, "Capability Information");
1133 field_tree
= proto_item_add_subtree(ti
, ett_zbee_nwk_cmd_cinfo
);
1135 /* Add the capability info flags. */
1136 proto_tree_add_boolean(field_tree
, hf_zbee_nwk_cmd_cinfo_alt_coord
, tvb
, offset
, 1,
1137 capabilities
& ZBEE_CINFO_ALT_COORD
);
1138 proto_tree_add_boolean(field_tree
, hf_zbee_nwk_cmd_cinfo_type
, tvb
, offset
, 1,
1139 capabilities
& ZBEE_CINFO_FFD
);
1140 proto_tree_add_boolean(field_tree
, hf_zbee_nwk_cmd_cinfo_power
, tvb
, offset
, 1,
1141 capabilities
& ZBEE_CINFO_POWER
);
1142 proto_tree_add_boolean(field_tree
, hf_zbee_nwk_cmd_cinfo_idle_rx
, tvb
, offset
, 1,
1143 capabilities
& ZBEE_CINFO_IDLE_RX
);
1144 proto_tree_add_boolean(field_tree
, hf_zbee_nwk_cmd_cinfo_security
, tvb
, offset
, 1,
1145 capabilities
& ZBEE_CINFO_SECURITY
);
1146 proto_tree_add_boolean(field_tree
, hf_zbee_nwk_cmd_cinfo_alloc
, tvb
, offset
, 1,
1147 capabilities
& ZBEE_CINFO_ALLOC
);
1151 /* Update the info column.*/
1152 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ", Device: 0x%04x", packet
->src
);
1156 } /* dissect_zbee_nwk_rejoin_req */
1158 /*FUNCTION:------------------------------------------------------
1160 * dissect_zbee_nwk_rejoin_resp
1162 * Helper dissector for the Rejoin Response command.
1164 * tvbuff_t *tvb - pointer to buffer containing raw packet.
1165 * packet_into *pinfo - pointer to packet information fields
1166 * proto_tree *tree - pointer to the command subtree.
1167 * zbee_nwk_packet *packet - pointer to the network packet struct.
1168 * offset - offset into the tvb to begin dissection.
1170 * guint - offset after command dissection.
1171 *---------------------------------------------------------------
1174 dissect_zbee_nwk_rejoin_resp(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, zbee_nwk_packet
* packet
, guint offset
)
1179 /* Get and display the short address. */
1180 addr
= tvb_get_letohs(tvb
, offset
);
1182 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_addr
, tvb
, offset
, 2, addr
);
1186 /* Get and display the rejoin status. */
1187 status
= tvb_get_guint8(tvb
, offset
);
1189 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_rejoin_status
, tvb
, offset
, 1, status
);
1193 /* Update the info column. */
1194 if (status
== IEEE802154_CMD_ASRSP_AS_SUCCESS
) {
1195 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ", Address: 0x%04x", packet
->src
);
1198 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ", %s", val_to_str_const(status
, zbee_nwk_rejoin_codes
, "Unknown Rejoin Response"));
1203 } /* dissect_zbee_nwk_rejoin_resp */
1205 /*FUNCTION:------------------------------------------------------
1207 * dissect_zbee_nwk_link_status
1209 * Helper dissector for the Link Status command.
1211 * tvbuff_t *tvb - pointer to buffer containing raw packet.
1212 * proto_tree *tree - pointer to the command subtree.
1213 * offset - offset into the tvb to begin dissection.
1215 * guint - offset after command dissection.
1216 *---------------------------------------------------------------
1219 dissect_zbee_nwk_link_status(tvbuff_t
*tvb
, proto_tree
*tree
, guint offset
)
1225 /* Get and Display the link status options. */
1226 options
= tvb_get_guint8(tvb
, offset
);
1227 link_count
= options
& ZBEE_NWK_CMD_LINK_OPTION_COUNT_MASK
;
1229 proto_tree_add_boolean(tree
, hf_zbee_nwk_cmd_link_last
, tvb
, offset
, 1,
1230 options
& ZBEE_NWK_CMD_LINK_OPTION_LAST_FRAME
);
1231 proto_tree_add_boolean(tree
, hf_zbee_nwk_cmd_link_first
, tvb
, offset
, 1,
1232 options
& ZBEE_NWK_CMD_LINK_OPTION_FIRST_FRAME
);
1233 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_link_count
, tvb
, offset
, 1, link_count
);
1237 /* Get and Display the link status list. */
1238 for (i
=0; i
<link_count
; i
++) {
1239 /* Get the address and link status. */
1240 addr
= tvb_get_letohs(tvb
, offset
);
1241 options
= tvb_get_guint8(tvb
, offset
+2);
1243 proto_tree_add_text(tree
, tvb
, offset
, 2+1,
1244 "0x%04x, Incoming Cost: %d Outgoing Cost: %d", addr
,
1245 options
& ZBEE_NWK_CMD_LINK_INCOMMING_COST_MASK
,
1246 (options
& ZBEE_NWK_CMD_LINK_OUTGOING_COST_MASK
)>>4);
1251 /* TODO: Update the info column. */
1253 } /* dissect_zbee_nwk_link_status */
1255 /*FUNCTION:------------------------------------------------------
1257 * dissect_zbee_nwk_report
1259 * Helper dissector for the Network Report command.
1261 * tvbuff_t *tvb - pointer to buffer containing raw packet.
1262 * packet_into *pinfo - pointer to packet information fields
1263 * proto_tree *tree - pointer to the command subtree.
1264 * offset - offset into the tvb to begin dissection.
1266 * guint - offset after command dissection.
1267 *---------------------------------------------------------------
1270 dissect_zbee_nwk_report(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, guint offset
)
1277 /* Get and display the command options field. */
1278 options
= tvb_get_guint8(tvb
, offset
);
1279 report_count
= options
& ZBEE_NWK_CMD_NWK_REPORT_COUNT_MASK
;
1280 report_type
= options
& ZBEE_NWK_CMD_NWK_REPORT_ID_MASK
;
1282 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_report_type
, tvb
, offset
, 1, report_type
);
1283 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_report_count
, tvb
, offset
, 1, report_count
);
1287 /* Get and display the epid. */
1289 proto_tree_add_item(tree
, hf_zbee_nwk_cmd_epid
, tvb
, offset
, 8, ENC_LITTLE_ENDIAN
);
1293 if (report_type
== ZBEE_NWK_CMD_NWK_REPORT_ID_PAN_CONFLICT
) {
1296 /* Report information contains a list of PANS with range of the sender. */
1297 for (i
=0; i
<report_count
; i
++) {
1298 panId
= tvb_get_letohs(tvb
, offset
);
1300 proto_tree_add_text(tree
, tvb
, offset
, 2, "PANID: 0x%04x", panId
);
1306 /* Update the info column. */
1307 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ", %s", val_to_str_const(report_type
, zbee_nwk_report_types
, "Unknown Report Type"));
1311 } /* dissect_zbee_nwk_report */
1313 /*FUNCTION:------------------------------------------------------
1315 * dissect_zbee_nwk_update
1317 * Helper dissector for the Network Update command.
1319 * tvbuff_t *tvb - pointer to buffer containing raw packet.
1320 * packet_into *pinfo - pointer to packet information fields
1321 * proto_tree *tree - pointer to the command subtree.
1322 * offset - offset into the tvb to begin dissection.
1324 * guint - offset after command dissection.
1325 *---------------------------------------------------------------
1328 dissect_zbee_nwk_update(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, guint offset
)
1336 /* Get and display the command options field. */
1337 options
= tvb_get_guint8(tvb
, offset
);
1338 update_count
= options
& ZBEE_NWK_CMD_NWK_UPDATE_COUNT_MASK
;
1339 update_type
= options
& ZBEE_NWK_CMD_NWK_UPDATE_ID_MASK
;
1341 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_update_type
, tvb
, offset
, 1, update_type
);
1342 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_update_count
, tvb
, offset
, 1, update_count
);
1346 /* Get and display the epid. */
1348 proto_tree_add_item(tree
, hf_zbee_nwk_cmd_epid
, tvb
, offset
, 8, ENC_LITTLE_ENDIAN
);
1352 /* Get and display the updateID. */
1353 update_id
= tvb_get_guint8(tvb
, offset
);
1355 proto_tree_add_uint(tree
, hf_zbee_nwk_cmd_update_id
, tvb
, offset
, 1, update_id
);
1359 if (update_type
== ZBEE_NWK_CMD_NWK_UPDATE_ID_PAN_UPDATE
) {
1362 /* Report information contains a list of PANS with range of the sender. */
1363 for (i
=0; i
<update_count
; i
++) {
1364 panId
= tvb_get_letohs(tvb
, offset
);
1366 proto_tree_add_text(tree
, tvb
, offset
, 2, "PANID: 0x%04x", panId
);
1372 /* Update the info column. */
1373 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ", %s", val_to_str_const(update_type
, zbee_nwk_update_types
, "Unknown Update Type"));
1377 } /* dissect_zbee_nwk_update */
1379 /*FUNCTION:------------------------------------------------------
1381 * dissect_zbee_beacon
1383 * Dissector for ZigBee network beacons.
1385 * tvbuff_t *tvb - pointer to buffer containing raw packet.
1386 * packet_into *pinfo - pointer to packet information fields
1387 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
1390 *---------------------------------------------------------------
1392 static int dissect_zbee_beacon(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data
)
1394 ieee802154_packet
*packet
= (ieee802154_packet
*)data
;
1396 proto_item
*beacon_root
= NULL
;
1397 proto_tree
*beacon_tree
= NULL
;
1405 /* Add ourself to the protocol column. */
1406 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "ZigBee");
1407 /* Create the tree for this beacon. */
1409 beacon_root
= proto_tree_add_protocol_format(tree
, proto_zbee_nwk
, tvb
, 0, tvb_length(tvb
), "ZigBee Beacon");
1410 beacon_tree
= proto_item_add_subtree(beacon_root
, ett_zbee_beacon
);
1413 /* Update the info column. */
1414 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Beacon, Src: 0x%04x", packet
->src16
);
1416 /* Get and display the protocol id, must be 0 on all ZigBee beacons. */
1417 proto_tree_add_item(beacon_tree
, hf_zbee_beacon_protocol
, tvb
, offset
, 1, ENC_NA
);
1420 /* Get and display the stack profile and protocol version. */
1421 temp
= tvb_get_guint8(tvb
, offset
);
1422 version
= zbee_get_bit_field(temp
, ZBEE_NWK_BEACON_PROTOCOL_VERSION
);
1424 proto_tree_add_uint(beacon_tree
, hf_zbee_beacon_stack_profile
, tvb
, offset
, 1,
1425 zbee_get_bit_field(temp
, ZBEE_NWK_BEACON_STACK_PROFILE
));
1426 proto_tree_add_uint(beacon_tree
, hf_zbee_beacon_version
, tvb
, offset
, 1, version
);
1430 /* Get and display the security level and flags. */
1431 temp
= tvb_get_guint8(tvb
, offset
);
1433 proto_tree_add_boolean(beacon_tree
, hf_zbee_beacon_router_capacity
, tvb
, offset
, 1,
1434 zbee_get_bit_field(temp
, ZBEE_NWK_BEACON_ROUTER_CAPACITY
));
1435 proto_tree_add_uint(beacon_tree
, hf_zbee_beacon_depth
, tvb
, offset
, 1,
1436 zbee_get_bit_field(temp
, ZBEE_NWK_BEACON_NETWORK_DEPTH
));
1437 proto_tree_add_boolean(beacon_tree
, hf_zbee_beacon_end_device_capacity
, tvb
, offset
, 1,
1438 zbee_get_bit_field(temp
, ZBEE_NWK_BEACON_END_DEVICE_CAPACITY
));
1442 if (version
>= ZBEE_VERSION_2007
) {
1443 /* In ZigBee 2006 and later, the beacon contains an extended PAN ID. */
1444 epid
= tvb_get_letoh64(tvb
, offset
);
1446 proto_tree_add_item(beacon_tree
, hf_zbee_beacon_epid
, tvb
, offset
, 8, ENC_LITTLE_ENDIAN
);
1450 /* Update the Info Column with the EPID. */
1451 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ", EPID: %s", get_eui64_name(epid
));
1454 * In ZigBee 2006 the Tx-Offset is optional, while in the 2007 and
1455 * later versions, the Tx-Offset is a required value. Since both 2006 and
1456 * and 2007 versions have the same protocol version (2), we should treat
1457 * the Tx-Offset as well as the update ID as optional elements
1459 if (tvb_bytes_exist(tvb
, offset
, 3)) {
1460 tx_offset
= tvb_get_letoh24(tvb
, offset
);
1461 proto_tree_add_uint(beacon_tree
, hf_zbee_beacon_tx_offset
, tvb
, offset
, 3, tx_offset
);
1464 /* Get and display the update ID. */
1465 if(tvb_length_remaining(tvb
, offset
)) {
1466 temp
= tvb_get_guint8(tvb
, offset
);
1467 proto_tree_add_uint(beacon_tree
, hf_zbee_beacon_update_id
, tvb
, offset
, 1, temp
);
1472 else if (tvb_bytes_exist(tvb
, offset
, 3)) {
1473 /* In ZigBee 2004, the Tx-Offset is an optional value. */
1474 tx_offset
= tvb_get_letoh24(tvb
, offset
);
1476 proto_tree_add_uint(beacon_tree
, hf_zbee_beacon_tx_offset
, tvb
, offset
, 3, tx_offset
);
1480 /* Update the info column with the PAN ID. */
1481 col_append_fstr(pinfo
->cinfo
, COL_INFO
, ", PAN: 0x%04x", packet
->src_pan
);
1484 /* Check for leftover bytes. */
1485 if (offset
< tvb_length(tvb
)) {
1486 /* Bytes leftover! */
1487 guint leftover_len
= tvb_length(tvb
) - offset
;
1488 tvbuff_t
*leftover_tvb
= tvb_new_subset(tvb
, offset
, leftover_len
, leftover_len
);
1489 proto_tree
*root
= NULL
;
1491 /* Correct the length of the beacon tree. */
1493 root
= proto_tree_get_root(tree
);
1494 proto_item_set_len(beacon_root
, offset
);
1497 /* Dump the leftover to the data dissector. */
1498 call_dissector(data_handle
, leftover_tvb
, pinfo
, root
);
1501 return tvb_length(tvb
);
1502 } /* dissect_zbee_beacon */
1504 /*FUNCTION:------------------------------------------------------
1506 * proto_register_zbee_nwk
1508 * ZigBee protocol registration routine.
1513 *---------------------------------------------------------------
1515 void proto_register_zbee_nwk(void)
1517 static hf_register_info hf
[] = {
1519 { &hf_zbee_nwk_frame_type
,
1520 { "Frame Type", "zbee_nwk.frame_type", FT_UINT16
, BASE_HEX
, VALS(zbee_nwk_frame_types
),
1521 ZBEE_NWK_FCF_FRAME_TYPE
, NULL
, HFILL
}},
1523 { &hf_zbee_nwk_proto_version
,
1524 { "Protocol Version", "zbee_nwk.proto_version", FT_UINT16
, BASE_DEC
, NULL
, ZBEE_NWK_FCF_VERSION
,
1527 { &hf_zbee_nwk_discover_route
,
1528 { "Discover Route", "zbee_nwk.discovery", FT_UINT16
, BASE_HEX
, VALS(zbee_nwk_discovery_modes
),
1529 ZBEE_NWK_FCF_DISCOVER_ROUTE
,
1530 "Determines how route discovery may be handled, if at all.", HFILL
}},
1532 { &hf_zbee_nwk_multicast
,
1533 { "Multicast", "zbee_nwk.multicast", FT_BOOLEAN
, 16, NULL
, ZBEE_NWK_FCF_MULTICAST
,
1536 { &hf_zbee_nwk_security
,
1537 { "Security", "zbee_nwk.security", FT_BOOLEAN
, 16, NULL
, ZBEE_NWK_FCF_SECURITY
,
1538 "Whether or not security operations are performed on the network payload.", HFILL
}},
1540 { &hf_zbee_nwk_source_route
,
1541 { "Source Route", "zbee_nwk.src_route", FT_BOOLEAN
, 16, NULL
, ZBEE_NWK_FCF_SOURCE_ROUTE
,
1544 { &hf_zbee_nwk_ext_dst
,
1545 { "Destination", "zbee_nwk.ext_dst", FT_BOOLEAN
, 16, NULL
, ZBEE_NWK_FCF_EXT_DEST
,
1548 { &hf_zbee_nwk_ext_src
,
1549 { "Extended Source", "zbee_nwk.ext_src", FT_BOOLEAN
, 16, NULL
, ZBEE_NWK_FCF_EXT_SOURCE
,
1553 { "Destination", "zbee_nwk.dst", FT_UINT16
, BASE_HEX
, NULL
, 0x0,
1557 { "Source", "zbee_nwk.src", FT_UINT16
, BASE_HEX
, NULL
, 0x0,
1560 { &hf_zbee_nwk_radius
,
1561 { "Radius", "zbee_nwk.radius", FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1562 "Number of hops remaining for a range-limited broadcast packet.", HFILL
}},
1564 { &hf_zbee_nwk_seqno
,
1565 { "Sequence Number", "zbee_nwk.seqno", FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1568 { &hf_zbee_nwk_mcast_mode
,
1569 { "Multicast Mode", "zbee_nwk.multicast.mode", FT_UINT8
, BASE_DEC
, NULL
, ZBEE_NWK_MCAST_MODE
,
1570 "Controls whether this packet is permitted to be routed through non-members of the multicast group.",
1573 { &hf_zbee_nwk_mcast_radius
,
1574 { "Non-Member Radius", "zbee_nwk.multicast.radius", FT_UINT8
, BASE_DEC
, NULL
, ZBEE_NWK_MCAST_RADIUS
,
1575 "Limits the range of multicast packets when being routed through non-members.", HFILL
}},
1577 { &hf_zbee_nwk_mcast_max_radius
,
1578 { "Max Non-Member Radius", "zbee_nwk.multicast.max_radius", FT_UINT8
, BASE_DEC
, NULL
,
1579 ZBEE_NWK_MCAST_MAX_RADIUS
, NULL
, HFILL
}},
1581 { &hf_zbee_nwk_dst64
,
1582 { "Destination", "zbee_nwk.dst64", FT_EUI64
, BASE_NONE
, NULL
, 0x0,
1585 { &hf_zbee_nwk_src64
,
1586 { "Extended Source", "zbee_nwk.src64", FT_EUI64
, BASE_NONE
, NULL
, 0x0,
1589 { &hf_zbee_nwk_src64_origin
,
1590 { "Origin", "zbee_nwk.src64.origin", FT_FRAMENUM
, BASE_NONE
, NULL
, 0x0,
1593 { &hf_zbee_nwk_relay_count
,
1594 { "Relay Count", "zbee_nwk.relay.count", FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1595 "Number of entries in the relay list.", HFILL
}},
1597 { &hf_zbee_nwk_relay_index
,
1598 { "Relay Index", "zbee_nwk.relay.index", FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1599 "Number of relays required to route to the source device.", HFILL
}},
1601 { &hf_zbee_nwk_cmd_id
,
1602 { "Command Identifier", "zbee_nwk.cmd.id", FT_UINT8
, BASE_HEX
, VALS(zbee_nwk_cmd_names
), 0x0,
1605 { &hf_zbee_nwk_cmd_addr
,
1606 { "Address", "zbee_nwk.cmd.addr", FT_UINT16
, BASE_HEX
, NULL
, 0x0,
1609 { &hf_zbee_nwk_cmd_route_id
,
1610 { "Route ID", "zbee_nwk.cmd.route.id", FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1611 "A sequence number for routing commands.", HFILL
}},
1613 { &hf_zbee_nwk_cmd_route_dest
,
1614 { "Destination", "zbee_nwk.cmd.route.dest", FT_UINT16
, BASE_HEX
, NULL
, 0x0,
1617 { &hf_zbee_nwk_cmd_route_orig
,
1618 { "Originator", "zbee_nwk.cmd.route.orig", FT_UINT16
, BASE_HEX
, NULL
, 0x0,
1621 { &hf_zbee_nwk_cmd_route_resp
,
1622 { "Responder", "zbee_nwk.cmd.route.resp", FT_UINT16
, BASE_HEX
, NULL
, 0x0,
1625 { &hf_zbee_nwk_cmd_route_dest_ext
,
1626 { "Extended Destination", "zbee_nwk.cmd.route.dest_ext", FT_EUI64
, BASE_NONE
, NULL
, 0x0,
1629 { &hf_zbee_nwk_cmd_route_orig_ext
,
1630 { "Extended Originator", "zbee_nwk.cmd.route.orig_ext", FT_EUI64
, BASE_NONE
, NULL
, 0x0,
1633 { &hf_zbee_nwk_cmd_route_resp_ext
,
1634 { "Extended Responder", "zbee_nwk.cmd.route.resp_ext", FT_EUI64
, BASE_NONE
, NULL
, 0x0,
1637 { &hf_zbee_nwk_cmd_route_cost
,
1638 { "Path Cost", "zbee_nwk.cmd.route.cost", FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1639 "A value specifying the efficiency of this route.", HFILL
}},
1641 { &hf_zbee_nwk_cmd_route_opt_repair
,
1642 { "Route Repair", "zbee_nwk.cmd.route.opts.repair", FT_BOOLEAN
, 8, NULL
,
1643 ZBEE_NWK_CMD_ROUTE_OPTION_REPAIR
,
1644 "Flag identifying whether the route request command was to repair a failed route.", HFILL
}},
1646 { &hf_zbee_nwk_cmd_route_opt_multicast
,
1647 { "Multicast", "zbee_nwk.cmd.route.opts.mcast", FT_BOOLEAN
, 8, NULL
,
1648 ZBEE_NWK_CMD_ROUTE_OPTION_MCAST
,
1649 "Flag identifying this as a multicast route request.", HFILL
}},
1651 { &hf_zbee_nwk_cmd_route_opt_dest_ext
,
1652 { "Extended Destination", "zbee_nwk.cmd.route.opts.dest_ext", FT_BOOLEAN
, 8, NULL
,
1653 ZBEE_NWK_CMD_ROUTE_OPTION_DEST_EXT
, NULL
, HFILL
}},
1655 { &hf_zbee_nwk_cmd_route_opt_resp_ext
,
1656 { "Extended Responder", "zbee_nwk.cmd.route.opts.resp_ext", FT_BOOLEAN
, 8, NULL
,
1657 ZBEE_NWK_CMD_ROUTE_OPTION_RESP_EXT
, NULL
, HFILL
}},
1659 { &hf_zbee_nwk_cmd_route_opt_orig_ext
,
1660 { "Extended Originator", "zbee_nwk.cmd.route.opts.orig_ext", FT_BOOLEAN
, 8, NULL
,
1661 ZBEE_NWK_CMD_ROUTE_OPTION_ORIG_EXT
, NULL
, HFILL
}},
1663 { &hf_zbee_nwk_cmd_route_opt_many_to_one
,
1664 { "Many-to-One Discovery", "zbee_nwk.cmd.route.opts.many2one", FT_UINT8
, BASE_HEX
,
1665 VALS(zbee_nwk_cmd_route_many_modes
), ZBEE_NWK_CMD_ROUTE_OPTION_MANY_MASK
,
1668 { &hf_zbee_nwk_cmd_nwk_status
,
1669 { "Status Code", "zbee_nwk.cmd.status", FT_UINT8
, BASE_HEX
, VALS(zbee_nwk_status_codes
), 0x0,
1672 { &hf_zbee_nwk_cmd_leave_rejoin
,
1673 { "Rejoin", "zbee_nwk.cmd.leave.rejoin", FT_BOOLEAN
, 8, NULL
,
1674 ZBEE_NWK_CMD_LEAVE_OPTION_REJOIN
, "Flag instructing the device to rejoin the network.", HFILL
}},
1676 { &hf_zbee_nwk_cmd_leave_request
,
1677 { "Request", "zbee_nwk.cmd.leave.request", FT_BOOLEAN
, 8, NULL
,
1678 ZBEE_NWK_CMD_LEAVE_OPTION_REQUEST
,
1679 "Flag identifying the direction of this command. 1=Request, 0=Indication", HFILL
}},
1681 { &hf_zbee_nwk_cmd_leave_children
,
1682 { "Remove Children", "zbee_nwk.cmd.leave.children", FT_BOOLEAN
, 8, NULL
,
1683 ZBEE_NWK_CMD_LEAVE_OPTION_CHILDREN
,
1684 "Flag instructing the device to remove its children in addition to itself.", HFILL
}},
1686 { &hf_zbee_nwk_cmd_relay_count
,
1687 { "Relay Count", "zbee_nwk.cmd.relay_count", FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1688 "Number of relays required to route to the destination.", HFILL
}},
1690 { &hf_zbee_nwk_cmd_cinfo_alt_coord
,
1691 { "Alternate Coordinator", "zbee_nwk.cmd.cinfo.alt_coord", FT_BOOLEAN
, 8, NULL
,
1692 IEEE802154_CMD_CINFO_ALT_PAN_COORD
,
1693 "Indicates that the device is able to operate as a PAN coordinator.", HFILL
}},
1695 { &hf_zbee_nwk_cmd_cinfo_type
,
1696 { "Full-Function Device", "zbee_nwk.cmd.cinfo.ffd", FT_BOOLEAN
, 8, NULL
,
1697 IEEE802154_CMD_CINFO_DEVICE_TYPE
, NULL
, HFILL
}},
1699 { &hf_zbee_nwk_cmd_cinfo_power
,
1700 { "AC Power", "zbee_nwk.cmd.cinfo.power", FT_BOOLEAN
, 8, NULL
,
1701 IEEE802154_CMD_CINFO_POWER_SRC
, "Indicates this device is using AC/Mains power.", HFILL
}},
1703 { &hf_zbee_nwk_cmd_cinfo_idle_rx
,
1704 { "Rx On When Idle", "zbee_nwk.cmd.cinfo.power", FT_BOOLEAN
, 8, NULL
,
1705 IEEE802154_CMD_CINFO_IDLE_RX
,
1706 "Indicates the receiver is active when the device is idle.", HFILL
}},
1708 { &hf_zbee_nwk_cmd_cinfo_security
,
1709 { "Security Capability", "zbee_nwk.cmd.cinfo.security", FT_BOOLEAN
, 8, NULL
,
1710 IEEE802154_CMD_CINFO_SEC_CAPABLE
,
1711 "Indicates this device is capable of performing encryption/decryption.", HFILL
}},
1713 { &hf_zbee_nwk_cmd_cinfo_alloc
,
1714 { "Allocate Short Address", "zbee_nwk.cmd.cinfo.alloc", FT_BOOLEAN
, 8, NULL
,
1715 IEEE802154_CMD_CINFO_ALLOC_ADDR
,
1716 "Flag requesting the parent to allocate a short address for this device.", HFILL
}},
1718 { &hf_zbee_nwk_cmd_rejoin_status
,
1719 { "Status", "zbee_nwk.cmd.rejoin_status", FT_UINT8
, BASE_HEX
,
1720 VALS(zbee_nwk_rejoin_codes
), 0x0, NULL
, HFILL
}},
1722 { &hf_zbee_nwk_cmd_link_last
,
1723 { "Last Frame", "zbee_nwk.cmd.link.last", FT_BOOLEAN
, 8, NULL
,
1724 ZBEE_NWK_CMD_LINK_OPTION_LAST_FRAME
,
1725 "Flag indicating the last in a series of link status commands.", HFILL
}},
1727 { &hf_zbee_nwk_cmd_link_first
,
1728 { "First Frame", "zbee_nwk.cmd.link.first", FT_BOOLEAN
, 8, NULL
,
1729 ZBEE_NWK_CMD_LINK_OPTION_FIRST_FRAME
,
1730 "Flag indicating the first in a series of link status commands.", HFILL
}},
1732 { &hf_zbee_nwk_cmd_link_count
,
1733 { "Link Status Count", "zbee_nwk.cmd.link.count", FT_UINT8
, BASE_DEC
, NULL
,
1734 ZBEE_NWK_CMD_LINK_OPTION_COUNT_MASK
, NULL
, HFILL
}},
1736 { &hf_zbee_nwk_cmd_report_type
,
1737 { "Report Type", "zbee_nwk.cmd.report.type", FT_UINT8
, BASE_HEX
,
1738 VALS(zbee_nwk_report_types
), ZBEE_NWK_CMD_NWK_REPORT_ID_MASK
, NULL
, HFILL
}},
1740 { &hf_zbee_nwk_cmd_report_count
,
1741 { "Report Information Count", "zbee_nwk.cmd.report.count", FT_UINT8
, BASE_DEC
, NULL
,
1742 ZBEE_NWK_CMD_NWK_REPORT_COUNT_MASK
, NULL
, HFILL
}},
1744 { &hf_zbee_nwk_cmd_update_type
,
1745 { "Update Type", "zbee_nwk.cmd.update.type", FT_UINT8
, BASE_HEX
,
1746 VALS(zbee_nwk_update_types
), ZBEE_NWK_CMD_NWK_UPDATE_ID_MASK
, NULL
, HFILL
}},
1748 { &hf_zbee_nwk_cmd_update_count
,
1749 { "Update Information Count", "zbee_nwk.cmd.update.count", FT_UINT8
, BASE_DEC
, NULL
,
1750 ZBEE_NWK_CMD_NWK_UPDATE_COUNT_MASK
, NULL
, HFILL
}},
1752 { &hf_zbee_nwk_cmd_update_id
,
1753 { "Update ID", "zbee_nwk.cmd.update.id", FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1756 { &hf_zbee_nwk_cmd_epid
,
1757 { "Extended PAN ID", "zbee_nwk.cmd.epid", FT_EUI64
, BASE_NONE
, NULL
, 0x0,
1760 { &hf_zbee_beacon_protocol
,
1761 { "Protocol ID", "zbee_beacon.protocol", FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1764 { &hf_zbee_beacon_stack_profile
,
1765 { "Stack Profile", "zbee_beacon.profile", FT_UINT8
, BASE_HEX
,
1766 VALS(zbee_nwk_stack_profiles
), 0x0, NULL
, HFILL
}},
1768 { &hf_zbee_beacon_version
,
1769 { "Protocol Version", "zbee_beacon.version", FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1772 { &hf_zbee_beacon_router_capacity
,
1773 { "Router Capacity", "zbee_beacon.router", FT_BOOLEAN
, BASE_NONE
, NULL
, 0x0,
1774 "Whether the device can accept join requests from routing capable devices.", HFILL
}},
1776 { &hf_zbee_beacon_depth
,
1777 { "Device Depth", "zbee_beacon.depth", FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1778 "The tree depth of the device, 0 indicates the network coordinator.", HFILL
}},
1780 { &hf_zbee_beacon_end_device_capacity
,
1781 { "End Device Capacity", "zbee_beacon.end_dev", FT_BOOLEAN
, BASE_NONE
, NULL
, 0x0,
1782 "Whether the device can accept join requests from ZigBee end devices.", HFILL
}},
1784 { &hf_zbee_beacon_epid
,
1785 { "Extended PAN ID", "zbee_beacon.ext_panid", FT_EUI64
, BASE_NONE
, NULL
, 0x0,
1786 "Extended PAN identifier.", HFILL
}},
1788 { &hf_zbee_beacon_tx_offset
,
1789 { "Tx Offset", "zbee_beacon.tx_offset", FT_UINT32
, BASE_DEC
, NULL
, 0x0,
1790 "The time difference between a device and its parent's beacon.", HFILL
}},
1792 { &hf_zbee_beacon_update_id
,
1793 { "Update ID", "zbee_beacon.update_id", FT_UINT8
, BASE_DEC
, NULL
, 0x0,
1797 /* NWK Layer subtrees */
1798 static gint
*ett
[] = {
1802 &ett_zbee_nwk_mcast
,
1803 &ett_zbee_nwk_route
,
1805 &ett_zbee_nwk_cmd_options
,
1806 &ett_zbee_nwk_cmd_cinfo
1809 static ei_register_info ei
[] = {
1810 { &ei_zbee_nwk_missing_payload
, { "zbee_nwk.missing_payload", PI_MALFORMED
, PI_ERROR
, "Missing Payload", EXPFILL
}},
1813 expert_module_t
* expert_zbee_nwk
;
1815 expert_zbee_nwk
= expert_register_protocol(proto_zbee_nwk
);
1816 expert_register_field_array(expert_zbee_nwk
, ei
, array_length(ei
));
1818 register_init_routine(proto_init_zbee_nwk
);
1820 /* Register the protocol with Wireshark. */
1821 proto_zbee_nwk
= proto_register_protocol("ZigBee Network Layer", "ZigBee NWK", ZBEE_PROTOABBREV_NWK
);
1822 proto_register_field_array(proto_zbee_nwk
, hf
, array_length(hf
));
1823 proto_register_subtree_array(ett
, array_length(ett
));
1825 /* Register the dissectors with Wireshark. */
1826 new_register_dissector(ZBEE_PROTOABBREV_NWK
, dissect_zbee_nwk
, proto_zbee_nwk
);
1827 new_register_dissector("zbee_beacon", dissect_zbee_beacon
, proto_zbee_nwk
);
1829 /* Register the Security dissector. */
1830 zbee_security_register(NULL
, proto_zbee_nwk
);
1831 } /* proto_register_zbee_nwk */
1833 /*FUNCTION:------------------------------------------------------
1835 * proto_reg_handoff_zbee_nwk
1837 * Registers the zigbee dissector with Wireshark.
1842 *---------------------------------------------------------------
1844 void proto_reg_handoff_zbee_nwk(void)
1846 /* Find the other dissectors we need. */
1847 data_handle
= find_dissector("data");
1848 aps_handle
= find_dissector("zbee_aps");
1850 /* Register our dissector with IEEE 802.15.4 */
1851 heur_dissector_add(IEEE802154_PROTOABBREV_WPAN
, dissect_zbee_nwk_heur
, proto_zbee_nwk
);
1853 /* Handoff the ZigBee security dissector code. */
1854 zbee_security_handoff();
1855 } /* proto_reg_handoff_zbee */
1857 static void free_keyring_val(gpointer a
)
1859 GSList
**slist
= (GSList
**)a
;
1860 g_slist_free(*slist
);
1864 /*FUNCTION:------------------------------------------------------
1866 * proto_init_zbee_nwk
1868 * Init routine for the nwk dissector. Creates a
1869 * hash table for mapping 16-bit to 64-bit addresses and
1870 * populates it with static address pairs from a UAT
1876 *---------------------------------------------------------------
1879 proto_init_zbee_nwk(void)
1881 /* Destroy the hash tables, if they exist. */
1882 if (zbee_nwk_map
.short_table
) g_hash_table_destroy(zbee_nwk_map
.short_table
);
1883 if (zbee_nwk_map
.long_table
) g_hash_table_destroy(zbee_nwk_map
.long_table
);
1884 if (zbee_table_nwk_keyring
) g_hash_table_destroy(zbee_table_nwk_keyring
);
1886 /* (Re)create the hash tables. */
1887 zbee_nwk_map
.short_table
= g_hash_table_new(ieee802154_short_addr_hash
, ieee802154_short_addr_equal
);
1888 zbee_nwk_map
.long_table
= g_hash_table_new(ieee802154_long_addr_hash
, ieee802154_long_addr_equal
);
1889 zbee_table_nwk_keyring
= g_hash_table_new_full(g_int_hash
, g_int_equal
, NULL
, free_keyring_val
);
1890 } /* proto_init_zbee_nwk */