MSWSP: fix dissect_mswsp_smb()
[wireshark-wip.git] / epan / dissectors / packet-zbee-zdp-management.c
blob3e9a2ae0edfd5e7cbc22097bd67888aee505576f
1 /* packet-zbee-zdp-management.c
2 * Dissector helper routines for the management services of the ZigBee Device Profile
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 <glib.h>
32 #include <epan/packet.h>
33 #include <epan/addr_resolv.h>
35 #include "packet-zbee.h"
36 #include "packet-zbee-zdp.h"
38 /**************************************
39 * HELPER FUNCTIONS
40 **************************************
42 /*FUNCTION:------------------------------------------------------
43 * NAME
44 * zdp_parse_nwk_desc
45 * DESCRIPTION
46 * Parses and displays a single network descriptor
47 * PARAMETERS
48 * tvbuff_t *tvb - pointer to buffer containing raw packet.
49 * packet_into *pinfo - pointer to packet information fields
50 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
51 * RETURNS
52 * void
53 *---------------------------------------------------------------
55 void
56 zdp_parse_nwk_desc(proto_tree *tree, tvbuff_t *tvb, guint *offset, guint8 version)
58 proto_item *ti = NULL;
59 guint len = 0;
61 guint64 ext_pan;
62 guint16 pan;
63 guint8 channel;
64 guint8 profile;
65 guint8 profile_version;
66 guint8 beacon;
67 guint8 superframe;
68 gboolean permit;
70 if (version >= ZBEE_VERSION_2007) {
71 /* Extended PAN Identifiers are used in ZigBee 2006 & later. */
72 ext_pan = tvb_get_letoh64(tvb, *offset + len);
73 if (tree) ti = proto_tree_add_text(tree, tvb, *offset, 0, "{Pan: %s", eui64_to_str(ext_pan));
74 len += (int)sizeof(guint64);
76 else {
77 /* Short PAN Identifiers are used in ZigBee 2003 and earlier. */
78 pan = tvb_get_letohs(tvb, *offset + len);
79 if (tree) ti = proto_tree_add_text(tree, tvb, *offset, 0, "{Pan: 0x%04x", pan);
80 len += (int)sizeof(guint16);
83 channel = tvb_get_guint8(tvb, *offset + len);
84 if (tree) proto_item_append_text(ti, ", Channel: %d", channel);
85 len += (int)sizeof(guint8);
87 profile = (tvb_get_guint8(tvb, *offset + len) & 0x0f) >> 0;
88 profile_version = (tvb_get_guint8(tvb, *offset + len) & 0xf0) >> 4;
89 if (tree) proto_item_append_text(ti, ", Profile: 0x%01x, Version: %d", profile, profile_version);
90 len += (int)sizeof(guint8);
92 beacon = (tvb_get_guint8(tvb, *offset + len) & 0x0f) >> 0;
93 superframe = (tvb_get_guint8(tvb, *offset + len) & 0xf0) >> 4;
94 if ((tree) && (beacon == 0xf)) {
95 proto_item_append_text(ti, ", Beacons Disabled");
97 else if (tree) {
98 proto_item_append_text(ti, ", BeaconOrder: %d, SuperframeOrder: %d", beacon, superframe);
100 len += (int)sizeof(guint8);
102 permit = tvb_get_guint8(tvb, *offset) & 0x01;
103 if (tree) proto_item_append_text(ti, ", PermitJoining: %s}", permit?"True":"False");
104 len += (int)sizeof(guint8);
106 if (tree) proto_item_set_len(ti, len);
107 *offset += len;
108 } /* zdp_parse_nwk_desc */
110 /*FUNCTION:------------------------------------------------------
111 * NAME
112 * zdp_parse_neighbor_table_entry
113 * DESCRIPTION
114 * Parses and displays a neighbor table entry.
115 * PARAMETERS
116 * tvbuff_t *tvb - pointer to buffer containing raw packet.
117 * packet_into *pinfo - pointer to packet information fields
118 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
119 * RETURNS
120 * void
121 *---------------------------------------------------------------
123 void
124 zdp_parse_neighbor_table_entry(proto_tree *tree, tvbuff_t *tvb, guint *offset, guint8 version)
126 proto_item *ti = NULL;
127 guint len = 0;
129 guint64 ext_pan;
130 guint16 pan;
131 guint64 ext_addr;
132 guint16 device;
133 guint8 type;
134 guint8 idle_rx;
135 guint8 rel;
136 guint8 permit_joining;
137 guint8 depth;
138 guint8 lqi;
140 if (version >= ZBEE_VERSION_2007) {
141 /* ZigBee 2006 & later use an extended PAN Identifier. */
142 ext_pan = tvb_get_letoh64(tvb, *offset + len);
143 if (tree) ti = proto_tree_add_text(tree, tvb, *offset, 0, "{Extended PAN: %s", eui64_to_str(ext_pan));
144 len += (int)sizeof(guint64);
146 else {
147 /* ZigBee 2003 & earlier use a short PAN Identifier. */
148 pan = tvb_get_letohs(tvb, *offset + len);
149 if (tree) ti = proto_tree_add_text(tree, tvb, *offset, 0, "{PAN: 0x%04x", pan);
150 len += (int)sizeof(guint16);
153 ext_addr = tvb_get_letoh64(tvb, *offset + len);
154 if (tree) proto_item_append_text(ti, ", Extended Addr: %s", get_eui64_name(ext_addr));
155 len += (int)sizeof(guint64);
157 device = tvb_get_letohs(tvb, *offset + len);
158 if (tree) proto_item_append_text(ti, ", Addr: 0x%04x", device);
159 len += (int)sizeof(guint16);
161 if (version >= ZBEE_VERSION_2007) {
162 type = (tvb_get_guint8(tvb, *offset + len) & 0x03) >> 0;
163 idle_rx = (tvb_get_guint8(tvb, *offset + len) & 0x0c) >> 2;
164 rel = (tvb_get_guint8(tvb, *offset + len) & 0x70) >> 4;
166 else {
167 type = (tvb_get_guint8(tvb, *offset + len) & 0x03) >> 0;
168 idle_rx = (tvb_get_guint8(tvb, *offset + len) & 0x04) >> 2;
169 rel = (tvb_get_guint8(tvb, *offset + len) & 0x18) >> 3;
171 if (tree) {
172 if (type == 0x00) proto_item_append_text(ti, ", Type: Coordinator");
173 else if (type == 0x01) proto_item_append_text(ti, ", Type: Router");
174 else if (type == 0x02) proto_item_append_text(ti, ", Type: End Device");
175 else proto_item_append_text(ti, ", Type: Unknown");
177 if (idle_rx == 0x00) proto_item_append_text(ti, ", Idle Rx: False");
178 else if (idle_rx==0x01) proto_item_append_text(ti, ", Idle Rx: True");
179 else proto_item_append_text(ti, ", Idle Rx: Unknown");
181 if (rel == 0x00) proto_item_append_text(ti, ", Relationship: Parent");
182 else if (rel == 0x01) proto_item_append_text(ti, ", Relationship: Child");
183 else if (rel == 0x02) proto_item_append_text(ti, ", Relationship: Sibling");
184 else if (rel == 0x03) proto_item_append_text(ti, ", Relationship: None");
185 else if (rel == 0x04) proto_item_append_text(ti, ", Relationship: Previous Child");
186 else proto_item_append_text(ti, ", Relationship: Unknown");
188 len += (int)sizeof(guint8);
190 if (version <= ZBEE_VERSION_2004) {
191 /* In ZigBee 2003 & earlier, the depth field is before the permit joining field. */
192 depth = tvb_get_guint8(tvb, *offset + len);
193 if (tree) proto_item_append_text(ti, ", Depth: %d", depth);
194 len += (int)sizeof(guint8);
197 permit_joining = (tvb_get_guint8(tvb, *offset + len) & 0x03) >> 0;
198 if (tree) {
199 if (permit_joining == 0x00) proto_item_append_text(ti, ", Permit Joining: False");
200 else if (permit_joining == 0x01)proto_item_append_text(ti, ", Permit Joining: True");
201 else proto_item_append_text(ti, ", Permit Joining: Unknown");
203 len += (int)sizeof(guint8);
205 if (version >= ZBEE_VERSION_2007) {
206 /* In ZigBee 2006 & later, the depth field is after the permit joining field. */
207 depth = tvb_get_guint8(tvb, *offset + len);
208 if (tree) proto_item_append_text(ti, ", Depth: %d", depth);
209 len += (int)sizeof(guint8);
212 lqi = tvb_get_guint8(tvb, *offset + len);
213 if (tree) proto_item_append_text(ti, ", LQI: %d}", lqi);
214 len += (int)sizeof(guint8);
216 if (tree) proto_item_set_len(ti, len);
217 *offset += len;
218 } /* zdp_parse_neighbor_table_entry */
220 /*FUNCTION:------------------------------------------------------
221 * NAME
222 * zdp_parse_routing_table_entry
223 * DESCRIPTION
224 * Parses and displays a routing table entry.
225 * PARAMETERS
226 * tvbuff_t *tvb - pointer to buffer containing raw packet.
227 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
228 * RETURNS
229 * void
230 *---------------------------------------------------------------
232 static void
233 zdp_parse_routing_table_entry(proto_tree *tree, tvbuff_t *tvb, guint *offset)
235 proto_item *ti = NULL;
236 guint len = 0;
238 guint16 dest;
239 guint8 status;
240 guint16 next;
242 dest = tvb_get_letohs(tvb, *offset + len);
243 if (tree) ti = proto_tree_add_text(tree, tvb, *offset, 2*(int)sizeof(guint16) + (int)sizeof(guint8), "{Destination: 0x%04x", dest);
244 len += (int)sizeof(guint16);
246 status = tvb_get_guint8(tvb, *offset + len);
247 next = tvb_get_letohs(tvb, *offset + len + (int)sizeof(guint8));
248 if (tree) {
249 /* Display the next hop first, because it looks a lot cleaner that way. */
250 proto_item_append_text(ti, ", Next Hop: 0x%04x", next);
252 if (status == 0x00) proto_item_append_text(ti, ", Status: Active}");
253 else if (status == 0x01)proto_item_append_text(ti, ", Status: Discovery Underway}");
254 else if (status == 0x02)proto_item_append_text(ti, ", Status: Discovery Failed}");
255 else if (status == 0x03)proto_item_append_text(ti, ", Status: Inactive}");
256 else proto_item_append_text(ti, ", Status: Unknown}");
258 len += (int)sizeof(guint8) + (int)sizeof(guint16);
260 *offset += len;
261 } /* zdp_parse_routing_table_entry */
263 /*FUNCTION:------------------------------------------------------
264 * NAME
265 * zdp_parse_bind_table_entry
266 * DESCRIPTION
267 * Parses and displays a single binding table entry.
268 * PARAMETERS
269 * tvbuff_t *tvb - pointer to buffer containing raw packet.
270 * packet_into *pinfo - pointer to packet information fields
271 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
272 * RETURNS
273 * void
274 *---------------------------------------------------------------
276 extern void zdp_parse_bind_table_entry(proto_tree *tree, tvbuff_t *tvb, guint *offset, guint8 version);
278 /**************************************
279 * MANAGEMENT REQUESTS
280 **************************************
282 /*FUNCTION:------------------------------------------------------
283 * NAME
284 * dissect_zbee_zdp_req_mgmt_nwk_disc
285 * DESCRIPTION
286 * ZigBee Device Profile dissector for the network discovery
287 * request. Cluster ID = 0x0030.
288 * PARAMETERS
289 * tvbuff_t *tvb - pointer to buffer containing raw packet.
290 * packet_into *pinfo - pointer to packet information fields
291 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
292 * RETURNS
293 * void
294 *---------------------------------------------------------------
296 void
297 dissect_zbee_zdp_req_mgmt_nwk_disc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
299 proto_item *ti;
300 guint i;
302 guint offset = 0;
303 guint32 channels;
304 /*guint8 duration;*/
305 /*guint8 idx;*/
307 /* Get the channel bitmap. */
308 channels = tvb_get_letohl(tvb, offset);
309 if (tree) {
310 gboolean first = 1;
311 ti = proto_tree_add_text(tree, tvb, offset, (int)sizeof(guint32), "Scan Channels: ");
313 for (i=0; i<27; i++) {
314 if (channels & (1<<i)) {
315 if (first) proto_item_append_text(ti, "%d", i);
316 else proto_item_append_text(ti, ", %d", i);
317 if (channels & (2<<i)) {
318 while ((channels&(2<<i)) && (i<26)) i++;
319 proto_item_append_text(ti, "-%d", i);
321 first = 0;
324 if (first) proto_item_append_text(ti, "None");
326 offset += (int)sizeof(guint32);
328 /*duration =*/ zbee_parse_uint(tree, hf_zbee_zdp_duration, tvb, &offset, (int)sizeof(guint8), NULL);
329 /*idx =*/ zbee_parse_uint(tree, hf_zbee_zdp_index, tvb, &offset, (int)sizeof(guint8), NULL);
331 /* Dump any leftover bytes. */
332 zdp_dump_excess(tvb, offset, pinfo, tree);
333 } /* dissect_zbee_zdp_req_mgmt_nwk_disc */
335 /*FUNCTION:------------------------------------------------------
336 * NAME
337 * dissect_zbee_zdp_req_mgmt_lqi
338 * DESCRIPTION
339 * ZigBee Device Profile dissector for the link quality information
340 * request. Cluster ID = 0x0031.
341 * PARAMETERS
342 * tvbuff_t *tvb - pointer to buffer containing raw packet.
343 * packet_into *pinfo - pointer to packet information fields
344 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
345 * RETURNS
346 * void
347 *---------------------------------------------------------------
349 void
350 dissect_zbee_zdp_req_mgmt_lqi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
352 guint offset = 0;
353 /*guint8 idx;*/
355 /*idx =*/ zbee_parse_uint(tree, hf_zbee_zdp_index, tvb, &offset, (int)sizeof(guint8), NULL);
357 /* Dump any leftover bytes. */
358 zdp_dump_excess(tvb, offset, pinfo, tree);
359 } /* dissect_zbee_zdp_req_mgmt_lqi */
361 /*FUNCTION:------------------------------------------------------
362 * NAME
363 * dissect_zbee_zdp_req_mgmt_rtg
364 * DESCRIPTION
365 * ZigBee Device Profile dissector for the routing table
366 * request. Cluster ID = 0x0032.
367 * PARAMETERS
368 * tvbuff_t *tvb - pointer to buffer containing raw packet.
369 * packet_into *pinfo - pointer to packet information fields
370 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
371 * RETURNS
372 * void
373 *---------------------------------------------------------------
375 void
376 dissect_zbee_zdp_req_mgmt_rtg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
378 guint offset = 0;
379 /*guint8 idx;*/
381 /*idx =*/ zbee_parse_uint(tree, hf_zbee_zdp_index, tvb, &offset, (int)sizeof(guint8), NULL);
383 /* Dump any leftover bytes. */
384 zdp_dump_excess(tvb, offset, pinfo, tree);
385 } /* dissect_zbee_zdp_req_mgmt_rtg */
387 /*FUNCTION:------------------------------------------------------
388 * NAME
389 * dissect_zbee_zdp_req_mgmt_bind
390 * DESCRIPTION
391 * ZigBee Device Profile dissector for the binding table
392 * request. Cluster ID = 0x0033.
393 * PARAMETERS
394 * tvbuff_t *tvb - pointer to buffer containing raw packet.
395 * packet_into *pinfo - pointer to packet information fields
396 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
397 * RETURNS
398 * void
399 *---------------------------------------------------------------
401 void
402 dissect_zbee_zdp_req_mgmt_bind(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
404 guint offset = 0;
405 /*guint8 idx;*/
407 /*idx =*/ zbee_parse_uint(tree, hf_zbee_zdp_index, tvb, &offset, (int)sizeof(guint8), NULL);
409 /* Dump any leftover bytes. */
410 zdp_dump_excess(tvb, offset, pinfo, tree);
411 } /* dissect_zbee_zdp_req_mgmt_bind */
413 /*FUNCTION:------------------------------------------------------
414 * NAME
415 * dissect_zbee_zdp_req_mgmt_leave
416 * DESCRIPTION
417 * ZigBee Device Profile dissector for the leave request.
418 * Cluster ID = 0x0034.
419 * PARAMETERS
420 * tvbuff_t *tvb - pointer to buffer containing raw packet.
421 * packet_into *pinfo - pointer to packet information fields
422 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
423 * RETURNS
424 * void
425 *---------------------------------------------------------------
427 void
428 dissect_zbee_zdp_req_mgmt_leave(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 version)
430 guint offset = 0;
431 guint64 ext_addr;
432 guint8 flags;
434 ext_addr = zbee_parse_eui64(tree, hf_zbee_zdp_ext_addr, tvb, &offset, (int)sizeof(guint64), NULL);
435 if (version >= ZBEE_VERSION_2007) {
436 /* Flags present on ZigBee 2006 & later. */
437 flags = tvb_get_guint8(tvb, offset);
438 if (tree) {
439 proto_tree_add_boolean(tree, hf_zbee_zdp_leave_children, tvb, offset, (int)sizeof(guint8), flags & ZBEE_ZDP_MGMT_LEAVE_CHILDREN);
440 proto_tree_add_boolean(tree, hf_zbee_zdp_leave_rejoin, tvb, offset, (int)sizeof(guint8), flags & ZBEE_ZDP_MGMT_LEAVE_REJOIN);
442 offset += (int)sizeof(guint8);
445 zbee_append_info(tree, pinfo, ", Device: %s", get_eui64_name(ext_addr));
447 /* Dump any leftover bytes. */
448 zdp_dump_excess(tvb, offset, pinfo, tree);
449 } /* dissect_zbee_zdp_req_mgmt_bind */
451 /*FUNCTION:------------------------------------------------------
452 * NAME
453 * dissect_zbee_zdp_req_mgmt_direct_join
454 * DESCRIPTION
455 * ZigBee Device Profile dissector for the direct join request.
456 * Cluster ID = 0x0035.
457 * PARAMETERS
458 * tvbuff_t *tvb - pointer to buffer containing raw packet.
459 * packet_into *pinfo - pointer to packet information fields
460 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
461 * RETURNS
462 * void
463 *---------------------------------------------------------------
465 void
466 dissect_zbee_zdp_req_mgmt_direct_join(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
468 guint offset = 0;
469 guint64 ext_addr;
470 /*guint8 cinfo;*/
472 ext_addr = zbee_parse_eui64(tree, hf_zbee_zdp_ext_addr, tvb, &offset, (int)sizeof(guint64), NULL);
473 /*cinfo =*/ zdp_parse_cinfo(tree, ett_zbee_zdp_cinfo, tvb, &offset);
475 zbee_append_info(tree, pinfo, ", Device: %s", get_eui64_name(ext_addr));
477 /* Dump any leftover bytes. */
478 zdp_dump_excess(tvb, offset, pinfo, tree);
479 } /* dissect_zbee_zdp_req_mgmt_direct_join */
481 /*FUNCTION:------------------------------------------------------
482 * NAME
483 * dissect_zbee_zdp_req_mgmt_permit_join
484 * DESCRIPTION
485 * ZigBee Device Profile dissector for the permit joining
486 * request. Cluster ID = 0x0036.
487 * PARAMETERS
488 * tvbuff_t *tvb - pointer to buffer containing raw packet.
489 * packet_into *pinfo - pointer to packet information fields
490 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
491 * RETURNS
492 * void
493 *---------------------------------------------------------------
495 void
496 dissect_zbee_zdp_req_mgmt_permit_join(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
498 guint offset = 0;
499 /*guint8 duration;*/
500 /*guint8 significance;*/
502 /*duration =*/ zbee_parse_uint(tree, hf_zbee_zdp_duration, tvb, &offset, (int)sizeof(guint8), NULL);
503 /*significance =*/ zbee_parse_uint(tree, hf_zbee_zdp_significance, tvb, &offset, (int)sizeof(guint8), NULL);
505 /* Dump any leftover bytes. */
506 zdp_dump_excess(tvb, offset, pinfo, tree);
507 } /* dissect_zbee_zdp_req_mgmt_permit_join */
509 /*FUNCTION:------------------------------------------------------
510 * NAME
511 * dissect_zbee_zdp_req_mgmt_cache
512 * DESCRIPTION
513 * ZigBee Device Profile dissector for the cache request.
514 * Cluster ID = 0x0037.
515 * PARAMETERS
516 * tvbuff_t *tvb - pointer to buffer containing raw packet.
517 * packet_into *pinfo - pointer to packet information fields
518 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
519 * RETURNS
520 * void
521 *---------------------------------------------------------------
523 void
524 dissect_zbee_zdp_req_mgmt_cache(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
526 guint offset = 0;
527 /*guint8 idx;*/
529 /*idx =*/ zbee_parse_uint(tree, hf_zbee_zdp_index, tvb, &offset, (int)sizeof(guint8), NULL);
531 /* Dump any leftover bytes. */
532 zdp_dump_excess(tvb, offset, pinfo, tree);
533 } /* dissect_zbee_zdp_req_mgmt_cache */
535 /*FUNCTION:------------------------------------------------------
536 * NAME
537 * dissect_zbee_zdp_req_mgmt_nwkupdate
538 * DESCRIPTION
539 * ZigBee Device Profile dissector for the nwk update request.
540 * Cluster ID = 0x0038.
541 * PARAMETERS
542 * tvbuff_t *tvb - pointer to buffer containing raw packet.
543 * packet_into *pinfo - pointer to packet information fields
544 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
545 * RETURNS
546 * void
547 *---------------------------------------------------------------
549 void
550 dissect_zbee_zdp_req_mgmt_nwkupdate(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
552 guint offset = 0;
553 /*guint32 channels;*/
554 guint8 duration;
555 /*guint8 count;*/
556 /*guint8 update_id;*/
557 /*guint16 manager;*/
559 /*channels =*/ zdp_parse_chanmask(tree, tvb, &offset);
560 duration = zbee_parse_uint(tree, hf_zbee_zdp_duration, tvb, &offset, (int)sizeof(guint8), NULL);
561 if (duration == ZBEE_ZDP_NWKUPDATE_PARAMETERS) {
562 /*update_id =*/ zbee_parse_uint(tree, hf_zbee_zdp_update_id, tvb, &offset, (int)sizeof(guint8), NULL);
563 /*manager =*/ zbee_parse_uint(tree, hf_zbee_zdp_manager, tvb, &offset, (int)sizeof(guint16), NULL);
565 else if (duration == ZBEE_ZDP_NWKUPDATE_CHANNEL_HOP) {
566 /*update_id =*/ zbee_parse_uint(tree, hf_zbee_zdp_update_id, tvb, &offset, (int)sizeof(guint8), NULL);
568 else if (duration <= ZBEE_ZDP_NWKUPDATE_SCAN_MAX) {
569 /*count =*/ zbee_parse_uint(tree, hf_zbee_zdp_scan_count, tvb, &offset, (int)sizeof(guint8), NULL);
572 /* Dump any leftover bytes. */
573 zdp_dump_excess(tvb, offset, pinfo, tree);
574 } /* dissect_zbee_zdp_req_mgmt_nwkupdate */
576 /**************************************
577 * MANAGEMENT RESPONSES
578 **************************************
580 /*FUNCTION:------------------------------------------------------
581 * NAME
582 * dissect_zbee_zdp_rsp_mgmt_nwk_disc
583 * DESCRIPTION
584 * ZigBee Device Profile dissector for the network discovery
585 * response. Cluster ID = 0x8030.
586 * PARAMETERS
587 * tvbuff_t *tvb - pointer to buffer containing raw packet.
588 * packet_into *pinfo - pointer to packet information fields
589 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
590 * RETURNS
591 * void
592 *---------------------------------------------------------------
594 void
595 dissect_zbee_zdp_rsp_mgmt_nwk_disc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 version)
597 proto_item *ti;
598 proto_tree *field_tree = NULL;
599 guint offset = 0;
600 guint i;
602 guint8 status;
603 /*guint8 table_size;*/
604 /*guint8 idx;*/
605 guint8 table_count;
607 status = zdp_parse_status(tree, tvb, &offset);
608 /*table_size =*/ zbee_parse_uint(tree, hf_zbee_zdp_table_size, tvb, &offset, (int)sizeof(guint8), NULL);
609 /*idx =*/ zbee_parse_uint(tree, hf_zbee_zdp_index, tvb, &offset, (int)sizeof(guint8), NULL);
610 table_count = zbee_parse_uint(tree, hf_zbee_zdp_table_count, tvb, &offset, (int)sizeof(guint8), NULL);
612 if (tree && table_count) {
613 ti = proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset), "Network List");
614 field_tree = proto_item_add_subtree(ti, ett_zbee_zdp_nwk);
616 for (i=0; i<table_count; i++) {
617 zdp_parse_nwk_desc(field_tree, tvb, &offset, version);
618 } /* for */
620 zbee_append_info(tree, pinfo, ", Status: %s", zdp_status_name(status));
622 /* Dump any leftover bytes. */
623 zdp_dump_excess(tvb, offset, pinfo, tree);
624 } /* dissect_zbee_zdp_rsp_mgmt_nwk_disc */
626 /*FUNCTION:------------------------------------------------------
627 * NAME
628 * dissect_zbee_zdp_rsp_mgmt_lqi
629 * DESCRIPTION
630 * ZigBee Device Profile dissector for the link quality information
631 * response. Cluster ID = 0x8031.
632 * PARAMETERS
633 * tvbuff_t *tvb - pointer to buffer containing raw packet.
634 * packet_into *pinfo - pointer to packet information fields
635 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
636 * RETURNS
637 * void
638 *---------------------------------------------------------------
640 void
641 dissect_zbee_zdp_rsp_mgmt_lqi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 version)
643 proto_item *ti;
644 proto_tree *field_tree = NULL;
645 guint offset = 0;
646 guint i;
648 guint8 status;
649 /*guint8 table_size;*/
650 /*guint8 idx;*/
651 guint8 table_count;
653 status = zdp_parse_status(tree, tvb, &offset);
654 /*table_size =*/ zbee_parse_uint(tree, hf_zbee_zdp_table_size, tvb, &offset, (int)sizeof(guint8), NULL);
655 /*idx =*/ zbee_parse_uint(tree, hf_zbee_zdp_index, tvb, &offset, (int)sizeof(guint8), NULL);
656 table_count = zbee_parse_uint(tree, hf_zbee_zdp_table_count, tvb, &offset, (int)sizeof(guint8), NULL);
658 if (tree && table_count) {
659 ti = proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset), "Neighbor Table");
660 field_tree = proto_item_add_subtree(ti, ett_zbee_zdp_lqi);
662 for (i=0; i<table_count; i++) {
663 zdp_parse_neighbor_table_entry(field_tree, tvb, &offset, version);
664 } /* for */
666 zbee_append_info(tree, pinfo, ", Status: %s", zdp_status_name(status));
668 /* Dump any leftover bytes. */
669 zdp_dump_excess(tvb, offset, pinfo, tree);
670 } /* dissect_zbee_zdp_rsp_mgmt_lqi */
672 /*FUNCTION:------------------------------------------------------
673 * NAME
674 * dissect_zbee_zdp_rsp_mgmt_rtg
675 * DESCRIPTION
676 * ZigBee Device Profile dissector for the routing table
677 * response. Cluster ID = 0x8032.
678 * PARAMETERS
679 * tvbuff_t *tvb - pointer to buffer containing raw packet.
680 * packet_into *pinfo - pointer to packet information fields
681 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
682 * RETURNS
683 * void
684 *---------------------------------------------------------------
686 void
687 dissect_zbee_zdp_rsp_mgmt_rtg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
689 proto_item *ti;
690 proto_tree *field_tree = NULL;
691 guint offset = 0;
692 guint i;
694 guint8 status;
695 /*guint8 table_size;*/
696 /*guint8 idx;*/
697 guint8 table_count;
699 status = zdp_parse_status(tree, tvb, &offset);
700 /*table_size =*/ zbee_parse_uint(tree, hf_zbee_zdp_table_size, tvb, &offset, (int)sizeof(guint8), NULL);
701 /*idx =*/ zbee_parse_uint(tree, hf_zbee_zdp_index, tvb, &offset, (int)sizeof(guint8), NULL);
702 table_count = zbee_parse_uint(tree, hf_zbee_zdp_table_count, tvb, &offset, (int)sizeof(guint8), NULL);
704 if (tree && table_count) {
705 ti = proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset), "Routing Table");
706 field_tree = proto_item_add_subtree(ti, ett_zbee_zdp_rtg);
708 for (i=0; i<table_count; i++) {
709 zdp_parse_routing_table_entry(field_tree, tvb, &offset);
710 } /* for */
712 zbee_append_info(tree, pinfo, ", Status: %s", zdp_status_name(status));
714 /* Dump any leftover bytes. */
715 zdp_dump_excess(tvb, offset, pinfo, tree);
716 } /* dissect_zbee_zdp_rsp_mgmt_rtg */
718 /*FUNCTION:------------------------------------------------------
719 * NAME
720 * dissect_zbee_zdp_rsp_mgmt_bind
721 * DESCRIPTION
722 * ZigBee Device Profile dissector for the binding table
723 * response. Cluster ID = 0x8033.
724 * PARAMETERS
725 * tvbuff_t *tvb - pointer to buffer containing raw packet.
726 * packet_into *pinfo - pointer to packet information fields
727 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
728 * RETURNS
729 * void
730 *---------------------------------------------------------------
732 void
733 dissect_zbee_zdp_rsp_mgmt_bind(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint8 version)
735 proto_item *ti;
736 proto_tree *field_tree = NULL;
737 guint offset = 0;
738 guint i;
740 guint8 status;
741 /*guint8 table_size;*/
742 /*guint8 idx;*/
743 guint8 table_count;
745 status = zdp_parse_status(tree, tvb, &offset);
746 /*table_size =*/ zbee_parse_uint(tree, hf_zbee_zdp_table_size, tvb, &offset, (int)sizeof(guint8), NULL);
747 /*idx =*/ zbee_parse_uint(tree, hf_zbee_zdp_index, tvb, &offset, (int)sizeof(guint8), NULL);
748 table_count = zbee_parse_uint(tree, hf_zbee_zdp_table_count, tvb, &offset, (int)sizeof(guint8), NULL);
750 if (tree && table_count) {
751 ti = proto_tree_add_text(tree, tvb, offset, tvb_length_remaining(tvb, offset), "Binding Table");
752 field_tree = proto_item_add_subtree(ti, ett_zbee_zdp_bind);
754 for (i=0; i<table_count; i++) {
755 zdp_parse_bind_table_entry(field_tree, tvb, &offset, version);
756 } /* for */
758 zbee_append_info(tree, pinfo, ", Status: %s", zdp_status_name(status));
760 /* Dump any leftover bytes. */
761 zdp_dump_excess(tvb, offset, pinfo, tree);
762 } /* dissect_zbee_zdp_rsp_mgmt_bind */
764 /*FUNCTION:------------------------------------------------------
765 * NAME
766 * dissect_zbee_zdp_rsp_mgmt_leave
767 * DESCRIPTION
768 * ZigBee Device Profile dissector for the leave response.
769 * Cluster ID = 0x8034.
770 * PARAMETERS
771 * tvbuff_t *tvb - pointer to buffer containing raw packet.
772 * packet_into *pinfo - pointer to packet information fields
773 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
774 * RETURNS
775 * void
776 *---------------------------------------------------------------
778 void
779 dissect_zbee_zdp_rsp_mgmt_leave(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
781 guint offset = 0;
782 guint8 status;
784 status = zdp_parse_status(tree, tvb, &offset);
786 zbee_append_info(tree, pinfo, ", Status: %s", zdp_status_name(status));
788 /* Dump any leftover bytes. */
789 zdp_dump_excess(tvb, offset, pinfo, tree);
790 } /* dissect_zbee_zdp_rsp_mgmt_bind */
792 /*FUNCTION:------------------------------------------------------
793 * NAME
794 * dissect_zbee_zdp_rsp_mgmt_direct_join
795 * DESCRIPTION
796 * ZigBee Device Profile dissector for the direct join response.
797 * Cluster ID = 0x8035.
798 * PARAMETERS
799 * tvbuff_t *tvb - pointer to buffer containing raw packet.
800 * packet_into *pinfo - pointer to packet information fields
801 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
802 * RETURNS
803 * void
804 *---------------------------------------------------------------
806 void
807 dissect_zbee_zdp_rsp_mgmt_direct_join(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
809 guint offset = 0;
810 guint8 status;
812 status = zdp_parse_status(tree, tvb, &offset);
814 zbee_append_info(tree, pinfo, ", Status: %s", zdp_status_name(status));
816 /* Dump any leftover bytes. */
817 zdp_dump_excess(tvb, offset, pinfo, tree);
818 } /* dissect_zbee_zdp_rsp_mgmt_direct_join */
820 /*FUNCTION:------------------------------------------------------
821 * NAME
822 * dissect_zbee_zdp_rsp_mgmt_permit_join
823 * DESCRIPTION
824 * ZigBee Device Profile dissector for the permit joining response.
825 * Cluster ID = 0x8036.
826 * PARAMETERS
827 * tvbuff_t *tvb - pointer to buffer containing raw packet.
828 * packet_into *pinfo - pointer to packet information fields
829 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
830 * RETURNS
831 * void
832 *---------------------------------------------------------------
834 void
835 dissect_zbee_zdp_rsp_mgmt_permit_join(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
837 guint offset = 0;
838 guint8 status;
840 status = zdp_parse_status(tree, tvb, &offset);
842 zbee_append_info(tree, pinfo, ", Status: %s", zdp_status_name(status));
844 /* Dump any leftover bytes. */
845 zdp_dump_excess(tvb, offset, pinfo, tree);
846 } /* dissect_zbee_zdp_rsp_mgmt_permit_join */
848 /*FUNCTION:------------------------------------------------------
849 * NAME
850 * dissect_zbee_zdp_rsp_mgmt_cache
851 * DESCRIPTION
852 * ZigBee Device Profile dissector for the cache response.
853 * Cluster ID = 0x8037.
854 * PARAMETERS
855 * tvbuff_t *tvb - pointer to buffer containing raw packet.
856 * packet_into *pinfo - pointer to packet information fields
857 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
858 * RETURNS
859 * void
860 *---------------------------------------------------------------
862 void
863 dissect_zbee_zdp_rsp_mgmt_cache(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
865 proto_item *ti;
866 proto_tree *field_tree;
867 guint offset = 0;
868 guint i;
870 guint8 status;
871 /*guint8 table_size;*/
872 /*guint8 idx;*/
873 guint8 table_count;
875 status = zdp_parse_status(tree, tvb, &offset);
876 /*table_size =*/ zbee_parse_uint(tree, hf_zbee_zdp_table_size, tvb, &offset, (int)sizeof(guint8), NULL);
877 /*idx =*/ zbee_parse_uint(tree, hf_zbee_zdp_index, tvb, &offset, (int)sizeof(guint8), NULL);
878 table_count = zbee_parse_uint(tree, hf_zbee_zdp_table_count, tvb, &offset, (int)sizeof(guint8), NULL);
880 if (tree && table_count) {
881 ti = proto_tree_add_text(tree, tvb, offset, table_count*((int)sizeof(guint16)+(int)sizeof(guint64)), "Discovery Cache");
882 field_tree = proto_item_add_subtree(ti, ett_zbee_zdp_cache);
883 } else {
884 field_tree = NULL;
886 for (i=0; i<table_count; i++) {
887 guint64 addr64 = tvb_get_letoh64(tvb, offset);
888 guint16 addr16 = tvb_get_letohs(tvb, offset+(int)sizeof(guint64));
890 if (field_tree) {
891 proto_tree_add_text(field_tree, tvb, offset, (int)sizeof(guint16)+(int)sizeof(guint64), "{%s = 0x%04x}", get_eui64_name(addr64), addr16);
893 offset += (int)sizeof(guint16)+(int)sizeof(guint64);
894 } /* for */
896 zbee_append_info(tree, pinfo, ", Status: %s", zdp_status_name(status));
898 /* Dump any leftover bytes. */
899 zdp_dump_excess(tvb, offset, pinfo, tree);
900 } /* dissect_zbee_zdp_rsp_mgmt_bind */
902 /*FUNCTION:------------------------------------------------------
903 * NAME
904 * dissect_zbee_zdp_rsp_mgmt_nwkupdate
905 * DESCRIPTION
906 * ZigBee Device Profile dissector for the nwk update notify.
907 * Cluster ID = 0x8038.
908 * PARAMETERS
909 * tvbuff_t *tvb - pointer to buffer containing raw packet.
910 * packet_into *pinfo - pointer to packet information fields
911 * proto_tree *tree - pointer to data tree Wireshark uses to display packet.
912 * RETURNS
913 * void
914 *---------------------------------------------------------------
916 void
917 dissect_zbee_zdp_rsp_mgmt_nwkupdate(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
919 guint offset = 0;
920 guint i, j;
922 /*guint8 status;*/
923 guint32 channels;
924 /*guint16 tx_total;*/
925 /*guint16 tx_fail;*/
926 guint8 channel_count;
928 /*status =*/ zdp_parse_status(tree, tvb, &offset);
929 channels = zdp_parse_chanmask(tree, tvb, &offset);
930 /*tx_total =*/ zbee_parse_uint(tree, hf_zbee_zdp_tx_total, tvb, &offset, (int)sizeof(guint16), NULL);
931 /*tx_fail =*/ zbee_parse_uint(tree, hf_zbee_zdp_tx_fail, tvb, &offset, (int)sizeof(guint16), NULL);
932 channel_count = zbee_parse_uint(tree, hf_zbee_zdp_channel_count, tvb, &offset, (int)sizeof(guint8), NULL);
934 /* Display the channel list. */
935 for (i=0, j=0; i<(8*(int)sizeof(guint32)); i++) {
936 guint8 energy;
938 if ( ! ((1<<i) & channels) ) {
939 /* Channel not scanned. */
940 continue;
942 if (j>=channel_count) {
943 /* Channel list has ended. */
944 break;
946 /* Get and display the channel energy. */
947 energy = tvb_get_guint8(tvb, offset);
948 if (tree) {
949 proto_tree_add_text(tree, tvb, offset, (int)sizeof(guint8), "Channel %d Energy = 0x%02x", i, energy);
951 offset += (int)sizeof(guint8);
952 /* Increment the number of channels we found energy values for. */
953 j++;
954 } /* for */
956 /* Dump any leftover bytes. */
957 zdp_dump_excess(tvb, offset, pinfo, tree);
958 } /* dissect_zbee_zdp_rsp_mgmt_nwkupdate */