HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / dissectors / packet-zbee-nwk.c
blob7b647b37c1a7a066ac7e9c0efe75d2c1c2ececdc
1 /* packet-zbee-nwk.c
2 * Dissector routines for the ZigBee Network Layer (NWK)
3 * By Owen Kirby <osk@exegin.com>
4 * Copyright 2009 Exegin Technologies Limited
6 * $Id$
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.
27 /* Include Files */
28 #include "config.h"
30 #include <string.h>
32 #include <glib.h>
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;
136 /* ZigBee Beacons */
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 /********************/
162 /* Field Names */
163 /********************/
164 /* Frame Types */
165 static const value_string zbee_nwk_frame_types[] = {
166 { ZBEE_NWK_FCF_DATA, "Data" },
167 { ZBEE_NWK_FCF_CMD, "Command" },
168 { 0, NULL }
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" },
176 { 0, NULL }
179 /* Command Names*/
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" },
191 { 0, NULL }
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" },
199 { 0, NULL }
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" },
207 { 0, NULL }
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" },
213 { 0, NULL }
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" },
219 { 0, NULL }
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" },
243 { 0, NULL }
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" },
251 { 0, NULL }
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:------------------------------------------------------
264 * NAME
265 * zbee_get_bit_field
266 * DESCRIPTION
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.
270 * PARAMETERS
271 * guint input
272 * guint mask
273 * RETURNS
274 * guint
275 *---------------------------------------------------------------
277 guint
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)) {
284 input >>= 1;
285 mask >>=1;
286 } /* while */
287 return (input & mask);
288 } /* zbee_get_bit_field */
290 /*FUNCTION:------------------------------------------------------
291 * NAME
292 * dissect_zbee_nwk_heur
293 * DESCRIPTION
294 * Heuristic interpreter for the ZigBee network dissectors.
295 * PARAMETERS
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.
299 * RETURNS
300 * Boolean value, whether it handles the packet or not.
301 *---------------------------------------------------------------
303 static gboolean
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) {
310 return FALSE;
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);
316 return TRUE;
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);
323 return TRUE;
325 /* If we get this far, then this packet did not meet the requirements for
326 * a ZigBee frame.
328 return FALSE;
329 } /* dissect_zbee_heur */
331 /*FUNCTION:------------------------------------------------------
332 * NAME
333 * dissect_zbee_nwk
334 * DESCRIPTION
335 * ZigBee packet dissection routine for Wireshark.
336 * PARAMETERS
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.
340 * RETURNS
341 * void
342 *---------------------------------------------------------------
344 static int
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;
357 guint offset = 0;
358 static gchar src_addr[32], dst_addr[32]; /* has to be static due to SET_ADDRESS */
360 guint16 fcf;
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);
376 } else {
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);
387 if (tree) {
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. */
405 if (tree) {
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);
433 offset += 2;
435 /* Add the frame type to the info column and protocol root. */
436 if (tree) {
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);
445 offset += 2;
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");
453 else {
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);
460 if (tree) {
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;
469 if (tree) {
470 proto_tree_add_uint(nwk_tree, hf_zbee_nwk_src, tvb, offset, 2, packet.src);
472 offset += 2;
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");
480 unicast_src = FALSE;
482 else {
483 g_snprintf(src_addr, 32, "0x%04x", packet.src);
484 unicast_src = TRUE;
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);
490 if (tree) {
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);
497 if (tree) {
498 proto_tree_add_uint(nwk_tree, hf_zbee_nwk_radius, tvb, offset, 1, packet.radius);
500 offset += 1;
502 /* Get and display the sequence number. */
503 packet.seqno = tvb_get_guint8(tvb, offset);
504 if (tree) {
505 proto_tree_add_uint(nwk_tree, hf_zbee_nwk_seqno, tvb, offset, 1, packet.seqno);
507 offset += 1;
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);
516 if (tree) {
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);
528 offset += 1;
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);
534 if (tree) {
535 proto_tree_add_item(nwk_tree, hf_zbee_nwk_dst64, tvb, offset, 8, ENC_LITTLE_ENDIAN);
537 offset += 8;
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);
547 offset += 8;
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 */
554 if ( unicast_src ) {
555 nwk_hints->map_rec = ieee802154_addr_update(&zbee_nwk_map,
556 packet.src, addr16.pan, packet.src64, pinfo->current_proto, pinfo->fd->num);
560 else {
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);
567 if (map_rec) {
568 /* found a nwk mapping record */
569 nwk_hints->map_rec = map_rec;
571 else {
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) */
577 else {
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);
588 else {
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);
604 if (map_rec) {
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) {
614 guint8 relay_count;
615 guint8 relay_index;
616 guint16 relay_addr;
617 guint i;
619 if (tree) {
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);
627 if (tree) {
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);
631 offset += 1;
633 if (tree) {
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);
642 offset += 1;
644 /* Get and display the relay list. */
645 for (i=0; i<relay_count; i++) {
646 relay_addr = tvb_get_letohs(tvb, offset);
647 if (tree) {
648 proto_tree_add_text(field_tree, tvb, offset, 2, "Relay %d: 0x%04x", i+1, relay_addr);
650 offset += 2;
651 } /* for */
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);
661 THROW(BoundsError);
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. */
672 else {
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);
684 else {
685 /* Invalid type. */
686 call_dissector(data_handle, payload_tvb, pinfo, tree);
689 return tvb_length(tvb);
690 } /* dissect_zbee_nwk */
692 /*FUNCTION:------------------------------------------------------
693 * NAME
694 * dissect_zbee_nwk_cmd
695 * DESCRIPTION
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.
699 * PARAMETERS
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.
703 * RETURNS
704 * void
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;
712 guint offset=0;
713 guint8 cmd_id = tvb_get_guint8(tvb, offset);
715 /* Create a subtree for this command. */
716 if (tree) {
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);
724 offset += 1;
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. */
731 switch(cmd_id){
732 case ZBEE_NWK_CMD_ROUTE_REQ:
733 /* Route Request Command. */
734 offset = dissect_zbee_nwk_route_req(tvb, pinfo, cmd_tree, packet, offset);
735 break;
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);
740 break;
742 case ZBEE_NWK_CMD_NWK_STATUS:
743 /* Network Status Command. */
744 offset = dissect_zbee_nwk_status(tvb, pinfo, cmd_tree, offset);
745 break;
747 case ZBEE_NWK_CMD_LEAVE:
748 /* Leave Command. */
749 offset = dissect_zbee_nwk_leave(tvb, cmd_tree, offset);
750 break;
752 case ZBEE_NWK_CMD_ROUTE_RECORD:
753 /* Route Record Command. */
754 offset = dissect_zbee_nwk_route_rec(tvb, pinfo, cmd_tree, packet, offset);
755 break;
757 case ZBEE_NWK_CMD_REJOIN_REQ:
758 /* Rejoin Request Command. */
759 offset = dissect_zbee_nwk_rejoin_req(tvb, pinfo, cmd_tree, packet, offset);
760 break;
762 case ZBEE_NWK_CMD_REJOIN_RESP:
763 /* Rejoin Response Command. */
764 offset = dissect_zbee_nwk_rejoin_resp(tvb, pinfo, cmd_tree, packet, offset);
765 break;
767 case ZBEE_NWK_CMD_LINK_STATUS:
768 /* Link Status Command. */
769 offset = dissect_zbee_nwk_link_status(tvb, cmd_tree, offset);
770 break;
772 case ZBEE_NWK_CMD_NWK_REPORT:
773 /* Network Report Command. */
774 offset = dissect_zbee_nwk_report(tvb, pinfo, cmd_tree, offset);
775 break;
777 case ZBEE_NWK_CMD_NWK_UPDATE:
778 /* Network Update Command. */
779 offset = dissect_zbee_nwk_update(tvb, pinfo, cmd_tree, offset);
780 break;
782 default:
783 /* Just break out and let the overflow handler deal with the payload. */
784 break;
785 } /* switch */
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. */
795 if (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:------------------------------------------------------
806 * NAME
807 * dissect_zbee_nwk_route_req
808 * DESCRIPTION
809 * Helper dissector for the Route Request command.
810 * PARAMETERS
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.
816 * RETURNS
817 * guint - offset after command dissection.
818 *---------------------------------------------------------------
820 static guint
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;
824 proto_item *ti;
826 guint8 route_options;
827 guint8 route_id;
828 guint16 dest_addr;
829 guint8 path_cost;
831 /* Get and display the route options field. */
832 route_options = tvb_get_guint8(tvb, offset);
833 if (tree) {
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);
846 else {
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);
851 offset += 1;
853 /* Get and display the route request ID. */
854 route_id = tvb_get_guint8(tvb, offset);
855 if (tree) {
856 proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_id, tvb, offset, 1, route_id);
858 offset += 1;
860 /* Get and display the destination address. */
861 dest_addr = tvb_get_letohs(tvb, offset);
862 if (tree) {
863 proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_dest, tvb, offset, 2, dest_addr);
865 offset += 2;
867 /* Get and display the path cost. */
868 path_cost = tvb_get_guint8(tvb, offset);
869 if (tree) {
870 proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_cost, tvb, offset, 1, path_cost);
872 offset += 1;
874 /* Get and display the extended destination address. */
875 if (route_options & ZBEE_NWK_CMD_ROUTE_OPTION_DEST_EXT) {
876 if (tree) {
877 proto_tree_add_item(tree, hf_zbee_nwk_cmd_route_dest_ext, tvb, offset, 8, ENC_LITTLE_ENDIAN);
879 offset += 8;
882 /* Update the info column. */
883 col_append_fstr(pinfo->cinfo, COL_INFO, ", Dst: 0x%04x, Src: 0x%04x", dest_addr, packet->src);
885 /* Done */
886 return offset;
887 } /* dissect_zbee_nwk_route_req */
889 /*FUNCTION:------------------------------------------------------
890 * NAME
891 * dissect_zbee_nwk_route_rep
892 * DESCRIPTION
893 * Helper dissector for the Route Reply command.
894 * PARAMETERS
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.
899 * RETURNS
900 * guint - offset after command dissection.
901 *---------------------------------------------------------------
903 static guint
904 dissect_zbee_nwk_route_rep(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint offset, guint8 version)
906 proto_tree *field_tree;
907 proto_item *ti;
909 guint8 route_options;
910 guint8 route_id;
911 guint16 orig_addr;
912 guint16 resp_addr;
913 guint8 path_cost;
915 /* Get and display the route options field. */
916 route_options = tvb_get_guint8(tvb, offset);
917 if (tree) {
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);
927 else {
928 proto_tree_add_boolean(tree, hf_zbee_nwk_cmd_route_opt_repair, tvb, offset, 1, route_options & ZBEE_NWK_CMD_ROUTE_OPTION_REPAIR);
931 offset += 1;
933 /* Get and display the route request ID. */
934 route_id = tvb_get_guint8(tvb, offset);
935 if (tree) {
936 proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_id, tvb, offset, 1, route_id);
938 offset += 1;
940 /* Get and display the originator address. */
941 orig_addr = tvb_get_letohs(tvb, offset);
942 if (tree) {
943 proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_orig, tvb, offset, 2, orig_addr);
945 offset += 2;
947 /* Get and display the responder address. */
948 resp_addr = tvb_get_letohs(tvb, offset);
949 if (tree) {
950 proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_resp, tvb, offset, 2, resp_addr);
952 offset += 2;
954 /* Get and display the path cost. */
955 path_cost = tvb_get_guint8(tvb, offset);
956 if (tree) {
957 proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_cost, tvb, offset, 1, path_cost);
959 offset += 1;
961 /* Get and display the originator extended address. */
962 if (route_options & ZBEE_NWK_CMD_ROUTE_OPTION_ORIG_EXT) {
963 if (tree) {
964 proto_tree_add_item(tree, hf_zbee_nwk_cmd_route_orig_ext, tvb, offset, 8, ENC_LITTLE_ENDIAN);
966 offset += 8;
969 /* Get and display the responder extended address. */
970 if (route_options & ZBEE_NWK_CMD_ROUTE_OPTION_RESP_EXT) {
971 if (tree) {
972 proto_tree_add_item(tree, hf_zbee_nwk_cmd_route_resp_ext, tvb, offset, 8, ENC_LITTLE_ENDIAN);
974 offset += 8;
977 /* Update the info column. */
978 col_append_fstr(pinfo->cinfo, COL_INFO, ", Dst: 0x%04x, Src: 0x%04x", resp_addr, orig_addr);
980 /* Done */
981 return offset;
982 } /* dissect_zbee_nwk_route_rep */
984 /*FUNCTION:------------------------------------------------------
985 * NAME
986 * dissect_zbee_nwk_status
987 * DESCRIPTION
988 * Helper dissector for the Network Status command.
989 * PARAMETERS
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.
994 * RETURNS
995 * guint - offset after command dissection.
996 *---------------------------------------------------------------
998 static guint
999 dissect_zbee_nwk_status(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint offset)
1001 guint8 status_code;
1002 guint16 addr;
1004 /* Get and display the status code. */
1005 status_code = tvb_get_guint8(tvb, offset);
1006 if (tree) {
1007 proto_tree_add_uint(tree, hf_zbee_nwk_cmd_nwk_status, tvb, offset, 1, status_code);
1009 offset += 1;
1011 /* Get and display the destination address. */
1012 addr = tvb_get_letohs(tvb, offset);
1013 if (tree) {
1014 proto_tree_add_uint(tree, hf_zbee_nwk_cmd_route_dest, tvb, offset, 2, addr);
1016 offset += 2;
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"));
1021 /* Done */
1022 return offset;
1023 } /* dissect_zbee_nwk_status */
1025 /*FUNCTION:------------------------------------------------------
1026 * NAME
1027 * dissect_zbee_nwk_leave
1028 * DESCRIPTION
1029 * Helper dissector for the Leave command.
1030 * PARAMETERS
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.
1034 * RETURNS
1035 * guint - offset after command dissection.
1036 *---------------------------------------------------------------
1038 static guint
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);
1045 if (tree) {
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);
1053 offset += 1;
1055 /* Done */
1056 return offset;
1057 } /* dissect_zbee_nwk_leave */
1059 /*FUNCTION:------------------------------------------------------
1060 * NAME
1061 * dissect_zbee_nwk_route_rec
1062 * DESCRIPTION
1063 * Helper dissector for the Reoute Record command.
1064 * PARAMETERS
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.
1070 * RETURNS
1071 * guint - offset after command dissection.
1072 *---------------------------------------------------------------
1074 static guint
1075 dissect_zbee_nwk_route_rec(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, zbee_nwk_packet * packet, guint offset)
1077 guint8 relay_count;
1078 guint16 relay_addr;
1079 guint i;
1081 /* Get and display the relay count. */
1082 relay_count = tvb_get_guint8(tvb, offset);
1083 if (tree) {
1084 proto_tree_add_uint(tree, hf_zbee_nwk_cmd_relay_count, tvb, offset, 1, relay_count);
1086 offset += 1;
1088 /* Get and display the relay addresses. */
1089 for (i=0; i<relay_count; i++) {
1090 relay_addr = tvb_get_letohs(tvb, offset);
1091 if (tree) {
1092 proto_tree_add_text(tree, tvb, offset, 2, "Relay Device %d: 0x%04x", i+1, relay_addr);
1094 offset += 2;
1095 } /* for */
1097 /* Update the info column. */
1098 col_append_fstr(pinfo->cinfo, COL_INFO, ", Dst: 0x%04x", packet->dst);
1101 /* Done */
1102 return offset;
1103 } /* dissect_zbee_nwk_route_rec */
1105 /*FUNCTION:------------------------------------------------------
1106 * NAME
1107 * dissect_zbee_nwk_rejoin_req
1108 * DESCRIPTION
1109 * Helper dissector for the Rejoin Request command.
1110 * PARAMETERS
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.
1116 * RETURNS
1117 * guint - offset after command dissection.
1118 *---------------------------------------------------------------
1120 static guint
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;
1124 proto_item *ti;
1126 guint8 capabilities;
1128 /* Get and dispaly the capabilities information. */
1129 capabilities = tvb_get_guint8(tvb, offset);
1130 if (tree) {
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);
1149 offset += 1;
1151 /* Update the info column.*/
1152 col_append_fstr(pinfo->cinfo, COL_INFO, ", Device: 0x%04x", packet->src);
1154 /* Done */
1155 return offset;
1156 } /* dissect_zbee_nwk_rejoin_req */
1158 /*FUNCTION:------------------------------------------------------
1159 * NAME
1160 * dissect_zbee_nwk_rejoin_resp
1161 * DESCRIPTION
1162 * Helper dissector for the Rejoin Response command.
1163 * PARAMETERS
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.
1169 * RETURNS
1170 * guint - offset after command dissection.
1171 *---------------------------------------------------------------
1173 static guint
1174 dissect_zbee_nwk_rejoin_resp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, zbee_nwk_packet * packet, guint offset)
1176 guint16 addr;
1177 guint8 status;
1179 /* Get and display the short address. */
1180 addr = tvb_get_letohs(tvb, offset);
1181 if (tree) {
1182 proto_tree_add_uint(tree, hf_zbee_nwk_cmd_addr, tvb, offset, 2, addr);
1184 offset += 2;
1186 /* Get and display the rejoin status. */
1187 status = tvb_get_guint8(tvb, offset);
1188 if (tree) {
1189 proto_tree_add_uint(tree, hf_zbee_nwk_cmd_rejoin_status, tvb, offset, 1, status);
1191 offset += 1;
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);
1197 else {
1198 col_append_fstr(pinfo->cinfo, COL_INFO, ", %s", val_to_str_const(status, zbee_nwk_rejoin_codes, "Unknown Rejoin Response"));
1201 /* Done */
1202 return offset;
1203 } /* dissect_zbee_nwk_rejoin_resp */
1205 /*FUNCTION:------------------------------------------------------
1206 * NAME
1207 * dissect_zbee_nwk_link_status
1208 * DESCRIPTION
1209 * Helper dissector for the Link Status command.
1210 * PARAMETERS
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.
1214 * RETURNS
1215 * guint - offset after command dissection.
1216 *---------------------------------------------------------------
1218 static guint
1219 dissect_zbee_nwk_link_status(tvbuff_t *tvb, proto_tree *tree, guint offset)
1221 guint8 options;
1222 guint16 addr;
1223 int i, link_count;
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;
1228 if (tree) {
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);
1235 offset += 1;
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);
1242 if (tree) {
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);
1248 offset += (2+1);
1249 } /* for */
1251 /* TODO: Update the info column. */
1252 return offset;
1253 } /* dissect_zbee_nwk_link_status */
1255 /*FUNCTION:------------------------------------------------------
1256 * NAME
1257 * dissect_zbee_nwk_report
1258 * DESCRIPTION
1259 * Helper dissector for the Network Report command.
1260 * PARAMETERS
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.
1265 * RETURNS
1266 * guint - offset after command dissection.
1267 *---------------------------------------------------------------
1269 static guint
1270 dissect_zbee_nwk_report(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint offset)
1272 guint8 options;
1273 guint8 report_type;
1274 int report_count;
1275 int i;
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;
1281 if (tree) {
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);
1285 offset += 1;
1287 /* Get and display the epid. */
1288 if (tree) {
1289 proto_tree_add_item(tree, hf_zbee_nwk_cmd_epid, tvb, offset, 8, ENC_LITTLE_ENDIAN);
1291 offset += 8;
1293 if (report_type == ZBEE_NWK_CMD_NWK_REPORT_ID_PAN_CONFLICT) {
1294 guint16 panId;
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);
1299 if (tree) {
1300 proto_tree_add_text(tree, tvb, offset, 2, "PANID: 0x%04x", panId);
1302 offset += 2;
1303 } /* for */
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"));
1309 /* Done */
1310 return offset;
1311 } /* dissect_zbee_nwk_report */
1313 /*FUNCTION:------------------------------------------------------
1314 * NAME
1315 * dissect_zbee_nwk_update
1316 * DESCRIPTION
1317 * Helper dissector for the Network Update command.
1318 * PARAMETERS
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.
1323 * RETURNS
1324 * guint - offset after command dissection.
1325 *---------------------------------------------------------------
1327 static guint
1328 dissect_zbee_nwk_update(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint offset)
1330 guint8 options;
1331 guint8 update_type;
1332 guint8 update_id;
1333 int update_count;
1334 int i;
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;
1340 if (tree) {
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);
1344 offset += 1;
1346 /* Get and display the epid. */
1347 if (tree) {
1348 proto_tree_add_item(tree, hf_zbee_nwk_cmd_epid, tvb, offset, 8, ENC_LITTLE_ENDIAN);
1350 offset += 8;
1352 /* Get and display the updateID. */
1353 update_id = tvb_get_guint8(tvb, offset);
1354 if (tree) {
1355 proto_tree_add_uint(tree, hf_zbee_nwk_cmd_update_id, tvb, offset, 1, update_id);
1357 offset += 1;
1359 if (update_type == ZBEE_NWK_CMD_NWK_UPDATE_ID_PAN_UPDATE) {
1360 guint16 panId;
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);
1365 if (tree) {
1366 proto_tree_add_text(tree, tvb, offset, 2, "PANID: 0x%04x", panId);
1368 offset += 2;
1369 } /* for */
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"));
1375 /* Done */
1376 return offset;
1377 } /* dissect_zbee_nwk_update */
1379 /*FUNCTION:------------------------------------------------------
1380 * NAME
1381 * dissect_zbee_beacon
1382 * DESCRIPTION
1383 * Dissector for ZigBee network beacons.
1384 * PARAMETERS
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.
1388 * RETURNS
1389 * void
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;
1398 guint offset = 0;
1400 guint8 temp;
1401 guint8 version;
1402 guint64 epid;
1403 guint32 tx_offset;
1405 /* Add ourself to the protocol column. */
1406 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ZigBee");
1407 /* Create the tree for this beacon. */
1408 if (tree) {
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);
1418 offset += 1;
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);
1423 if (tree) {
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);
1428 offset += 1;
1430 /* Get and display the security level and flags. */
1431 temp = tvb_get_guint8(tvb, offset);
1432 if (tree) {
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));
1440 offset += 1;
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);
1445 if (tree) {
1446 proto_tree_add_item(beacon_tree, hf_zbee_beacon_epid, tvb, offset, 8, ENC_LITTLE_ENDIAN);
1448 offset += 8;
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);
1462 offset += 3;
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);
1468 offset += 1;
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);
1475 if (tree) {
1476 proto_tree_add_uint(beacon_tree, hf_zbee_beacon_tx_offset, tvb, offset, 3, tx_offset);
1478 offset += 3;
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. */
1492 if (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:------------------------------------------------------
1505 * NAME
1506 * proto_register_zbee_nwk
1507 * DESCRIPTION
1508 * ZigBee protocol registration routine.
1509 * PARAMETERS
1510 * none
1511 * RETURNS
1512 * void
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,
1525 NULL, HFILL }},
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,
1534 NULL, HFILL }},
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,
1542 NULL, HFILL }},
1544 { &hf_zbee_nwk_ext_dst,
1545 { "Destination", "zbee_nwk.ext_dst", FT_BOOLEAN, 16, NULL, ZBEE_NWK_FCF_EXT_DEST,
1546 NULL, HFILL }},
1548 { &hf_zbee_nwk_ext_src,
1549 { "Extended Source", "zbee_nwk.ext_src", FT_BOOLEAN, 16, NULL, ZBEE_NWK_FCF_EXT_SOURCE,
1550 NULL, HFILL }},
1552 { &hf_zbee_nwk_dst,
1553 { "Destination", "zbee_nwk.dst", FT_UINT16, BASE_HEX, NULL, 0x0,
1554 NULL, HFILL }},
1556 { &hf_zbee_nwk_src,
1557 { "Source", "zbee_nwk.src", FT_UINT16, BASE_HEX, NULL, 0x0,
1558 NULL, HFILL }},
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,
1566 NULL, HFILL }},
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.",
1571 HFILL }},
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,
1583 NULL, HFILL }},
1585 { &hf_zbee_nwk_src64,
1586 { "Extended Source", "zbee_nwk.src64", FT_EUI64, BASE_NONE, NULL, 0x0,
1587 NULL, HFILL }},
1589 { &hf_zbee_nwk_src64_origin,
1590 { "Origin", "zbee_nwk.src64.origin", FT_FRAMENUM, BASE_NONE, NULL, 0x0,
1591 NULL, HFILL }},
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,
1603 NULL, HFILL }},
1605 { &hf_zbee_nwk_cmd_addr,
1606 { "Address", "zbee_nwk.cmd.addr", FT_UINT16, BASE_HEX, NULL, 0x0,
1607 NULL, HFILL }},
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,
1615 NULL, HFILL }},
1617 { &hf_zbee_nwk_cmd_route_orig,
1618 { "Originator", "zbee_nwk.cmd.route.orig", FT_UINT16, BASE_HEX, NULL, 0x0,
1619 NULL, HFILL }},
1621 { &hf_zbee_nwk_cmd_route_resp,
1622 { "Responder", "zbee_nwk.cmd.route.resp", FT_UINT16, BASE_HEX, NULL, 0x0,
1623 NULL, HFILL }},
1625 { &hf_zbee_nwk_cmd_route_dest_ext,
1626 { "Extended Destination", "zbee_nwk.cmd.route.dest_ext", FT_EUI64, BASE_NONE, NULL, 0x0,
1627 NULL, HFILL }},
1629 { &hf_zbee_nwk_cmd_route_orig_ext,
1630 { "Extended Originator", "zbee_nwk.cmd.route.orig_ext", FT_EUI64, BASE_NONE, NULL, 0x0,
1631 NULL, HFILL }},
1633 { &hf_zbee_nwk_cmd_route_resp_ext,
1634 { "Extended Responder", "zbee_nwk.cmd.route.resp_ext", FT_EUI64, BASE_NONE, NULL, 0x0,
1635 NULL, HFILL }},
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,
1666 NULL, HFILL }},
1668 { &hf_zbee_nwk_cmd_nwk_status,
1669 { "Status Code", "zbee_nwk.cmd.status", FT_UINT8, BASE_HEX, VALS(zbee_nwk_status_codes), 0x0,
1670 NULL, HFILL }},
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,
1754 NULL, HFILL }},
1756 { &hf_zbee_nwk_cmd_epid,
1757 { "Extended PAN ID", "zbee_nwk.cmd.epid", FT_EUI64, BASE_NONE, NULL, 0x0,
1758 NULL, HFILL }},
1760 { &hf_zbee_beacon_protocol,
1761 { "Protocol ID", "zbee_beacon.protocol", FT_UINT8, BASE_DEC, NULL, 0x0,
1762 NULL, HFILL }},
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,
1770 NULL, HFILL }},
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,
1794 NULL, HFILL }}
1797 /* NWK Layer subtrees */
1798 static gint *ett[] = {
1799 &ett_zbee_nwk,
1800 &ett_zbee_beacon,
1801 &ett_zbee_nwk_fcf,
1802 &ett_zbee_nwk_mcast,
1803 &ett_zbee_nwk_route,
1804 &ett_zbee_nwk_cmd,
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:------------------------------------------------------
1834 * NAME
1835 * proto_reg_handoff_zbee_nwk
1836 * DESCRIPTION
1837 * Registers the zigbee dissector with Wireshark.
1838 * PARAMETERS
1839 * none
1840 * RETURNS
1841 * void
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);
1861 return;
1864 /*FUNCTION:------------------------------------------------------
1865 * NAME
1866 * proto_init_zbee_nwk
1867 * DESCRIPTION
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
1871 * preference table.
1872 * PARAMETERS
1873 * none
1874 * RETURNS
1875 * void
1876 *---------------------------------------------------------------
1878 static void
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 */