2 * Routines for PAgP (Port Aggregation Protocol - aka FEC) dissection
3 * Original Author Mark C. Brown <mbrown@hp.com>
4 * Copyright (C) 2004 Hewlett-Packard Development Company, L.P.
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * Copied from packet-slowprotocols.c
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 #include <epan/packet.h>
35 /* Offsets of fields within a PagP PDU */
37 #define PAGP_VERSION_NUMBER 0
40 #define PAGP_LOCAL_DEVICE_ID 2
41 #define PAGP_LOCAL_LEARN_CAP 8
42 #define PAGP_LOCAL_PORT_PRIORITY 9
43 #define PAGP_LOCAL_SENT_PORT_IFINDEX 10
44 #define PAGP_LOCAL_GROUP_CAPABILITY 14
45 #define PAGP_LOCAL_GROUP_IFINDEX 18
46 #define PAGP_PARTNER_DEVICE_ID 22
47 #define PAGP_PARTNER_LEARN_CAP 28
48 #define PAGP_PARTNER_PORT_PRIORITY 29
49 #define PAGP_PARTNER_SENT_PORT_IFINDEX 30
50 #define PAGP_PARTNER_GROUP_CAPABILITY 34
51 #define PAGP_PARTNER_GROUP_IFINDEX 38
52 #define PAGP_PARTNER_COUNT 42
53 #define PAGP_NUM_TLVS 44
54 #define PAGP_FIRST_TLV 46
56 #define PAGP_FLUSH_LOCAL_DEVICE_ID 2
57 #define PAGP_FLUSH_PARTNER_DEVICE_ID 8
58 #define PAGP_FLUSH_TRANSACTION_ID 14
62 #define PAGP_INFO_PDU 1
63 #define PAGP_FLUSH_PDU 2
67 #define PAGP_FLAGS_SLOW_HELLO 0x01
68 #define PAGP_FLAGS_AUTO_MODE 0x02
69 #define PAGP_FLAGS_CONSISTENT_STATE 0x04
74 #define PAGP_TLV_DEVICE_NAME 1
75 #define PAGP_TLV_PORT_NAME 2
76 #define PAGP_TLV_AGPORT_MAC 3
77 #define PAGP_TLV_RESERVED 4
79 /* Initialise the protocol and registered fields */
81 static int proto_pagp = -1;
83 static int hf_pagp_version_number = -1;
85 static int hf_pagp_flags = -1;
86 static int hf_pagp_flags_slow_hello = -1;
87 static int hf_pagp_flags_auto_mode = -1;
88 static int hf_pagp_flags_consistent_state = -1;
89 static int hf_pagp_local_device_id = -1;
90 static int hf_pagp_local_learn_cap = -1;
91 static int hf_pagp_local_port_priority = -1;
92 static int hf_pagp_local_sent_port_ifindex = -1;
93 static int hf_pagp_local_group_capability = -1;
94 static int hf_pagp_local_group_ifindex = -1;
95 static int hf_pagp_partner_device_id = -1;
96 static int hf_pagp_partner_learn_cap = -1;
97 static int hf_pagp_partner_port_priority = -1;
98 static int hf_pagp_partner_sent_port_ifindex = -1;
99 static int hf_pagp_partner_group_capability = -1;
100 static int hf_pagp_partner_group_ifindex = -1;
101 static int hf_pagp_partner_count = -1;
102 static int hf_pagp_num_tlvs = -1;
103 static int hf_pagp_tlv = -1;
104 static int hf_pagp_tlv_device_name = -1;
105 static int hf_pagp_tlv_port_name = -1;
106 static int hf_pagp_tlv_agport_mac = -1;
108 static int hf_pagp_flush_local_device_id = -1;
109 static int hf_pagp_flush_partner_device_id = -1;
110 static int hf_pagp_flush_transaction_id = -1;
112 /* Initialise the subtree pointers */
114 static gint ett_pagp = -1;
115 static gint ett_pagp_flags = -1;
116 static gint ett_pagp_tlvs = -1;
118 /* General declarations and macros */
120 static const char initial_sep[] = " (";
121 static const char cont_sep[] = ", ";
123 static const value_string pdu_vers[] = {
129 static const value_string learn_cap[] = {
130 { 1, "Source-based Distribution" },
131 { 2, "Arbitrary Distribution" },
135 static const value_string tlv_types[] = {
136 { 1, "Device Name TLV" },
137 { 2, "Physical Port Name TLV" },
138 { 3, "Agport MAC Address" },
143 static const true_false_string automode = {
148 #define APPEND_BOOLEAN_FLAG(flag, item, string) \
151 proto_item_append_text(item, string, sep); \
155 /* Code to actually dissect the PAGP packets */
157 dissect_pagp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
160 guint16 raw_half_word;
165 guint16 offset = PAGP_FIRST_TLV;
172 proto_tree *pagp_tree = NULL;
173 proto_item *pagp_item;
174 proto_tree *flags_tree;
175 proto_item *flags_item;
176 proto_tree *tlv_tree;
177 proto_item *tlv_item;
183 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PAGP"); /* PAGP Protocol */
185 col_clear(pinfo->cinfo, COL_INFO);
187 pinfo->current_proto = "PAGP";
189 raw_octet = tvb_get_guint8(tvb, PAGP_VERSION_NUMBER);
191 pagp_item = proto_tree_add_protocol_format(tree, proto_pagp, tvb,
192 0, -1, "Port Aggregation Protocol");
193 pagp_tree = proto_item_add_subtree(pagp_item, ett_pagp);
194 proto_tree_add_uint(pagp_tree, hf_pagp_version_number, tvb,
195 PAGP_VERSION_NUMBER, 1, raw_octet);
197 if (check_col(pinfo->cinfo, COL_INFO)) {
198 col_append_str(pinfo->cinfo, COL_INFO,
199 val_to_str(raw_octet, pdu_vers, "Unknown PDU version"));
202 if (raw_octet == PAGP_FLUSH_PDU) {
204 if (check_col(pinfo->cinfo, COL_INFO)) {
205 col_append_fstr(pinfo->cinfo, COL_INFO, "; Local DevID: %s",
206 tvb_ether_to_str(tvb, PAGP_FLUSH_LOCAL_DEVICE_ID));
209 proto_tree_add_item(pagp_tree, hf_pagp_flush_local_device_id, tvb,
210 PAGP_FLUSH_LOCAL_DEVICE_ID, 6, ENC_NA);
213 if (check_col(pinfo->cinfo, COL_INFO)) {
214 col_append_fstr(pinfo->cinfo, COL_INFO, ", Partner DevID: %s",
215 tvb_ether_to_str(tvb, PAGP_FLUSH_PARTNER_DEVICE_ID));
218 proto_tree_add_item(pagp_tree, hf_pagp_flush_partner_device_id, tvb,
219 PAGP_FLUSH_PARTNER_DEVICE_ID, 6, ENC_NA);
222 raw_word = tvb_get_ntohl(tvb, PAGP_FLUSH_TRANSACTION_ID);
223 if (check_col(pinfo->cinfo, COL_INFO)) {
224 col_append_fstr(pinfo->cinfo, COL_INFO,
225 "; Transaction ID: 0x%x ", raw_word);
228 proto_tree_add_uint(pagp_tree, hf_pagp_flush_transaction_id, tvb,
229 PAGP_FLUSH_TRANSACTION_ID, 4, raw_word);
236 flags = tvb_get_guint8(tvb, PAGP_FLAGS);
237 if (check_col(pinfo->cinfo, COL_INFO)) {
238 col_append_fstr(pinfo->cinfo, COL_INFO, "; Flags 0x%x", flags);
242 flags_item = proto_tree_add_uint(pagp_tree, hf_pagp_flags, tvb,
243 PAGP_FLAGS, 1, flags);
244 flags_tree = proto_item_add_subtree(flags_item, ett_pagp_flags);
248 APPEND_BOOLEAN_FLAG(flags & PAGP_FLAGS_SLOW_HELLO, flags_item, "%sSlow Hello");
249 proto_tree_add_boolean(flags_tree, hf_pagp_flags_slow_hello, tvb,
250 PAGP_FLAGS, 1, flags);
252 APPEND_BOOLEAN_FLAG(flags & PAGP_FLAGS_AUTO_MODE, flags_item, "%sAuto Mode");
253 proto_tree_add_boolean(flags_tree, hf_pagp_flags_auto_mode, tvb,
254 PAGP_FLAGS, 1, flags);
256 APPEND_BOOLEAN_FLAG(flags & PAGP_FLAGS_CONSISTENT_STATE, flags_item,
257 "%sConsistent State");
258 proto_tree_add_boolean(flags_tree, hf_pagp_flags_consistent_state, tvb,
259 PAGP_FLAGS, 1, flags);
262 if (sep != initial_sep) {
263 /* We put something in; put in the terminating ")" */
264 proto_item_append_text(flags_item, ")");
268 if (check_col(pinfo->cinfo, COL_INFO)) {
269 col_append_fstr(pinfo->cinfo, COL_INFO, "; Local DevID: %s",
270 tvb_ether_to_str(tvb, PAGP_LOCAL_DEVICE_ID));
273 proto_tree_add_item(pagp_tree, hf_pagp_local_device_id, tvb,
274 PAGP_LOCAL_DEVICE_ID, 6, ENC_NA);
278 raw_octet = tvb_get_guint8(tvb, PAGP_LOCAL_LEARN_CAP);
279 proto_tree_add_uint(pagp_tree, hf_pagp_local_learn_cap, tvb,
280 PAGP_LOCAL_LEARN_CAP, 1, raw_octet);
282 raw_octet = tvb_get_guint8(tvb, PAGP_LOCAL_PORT_PRIORITY);
283 proto_tree_add_uint(pagp_tree, hf_pagp_local_port_priority, tvb,
284 PAGP_LOCAL_PORT_PRIORITY, 1, raw_octet);
286 raw_word = tvb_get_ntohl(tvb, PAGP_LOCAL_SENT_PORT_IFINDEX);
287 proto_tree_add_uint(pagp_tree, hf_pagp_local_sent_port_ifindex, tvb,
288 PAGP_LOCAL_SENT_PORT_IFINDEX, 4, raw_word);
290 raw_word = tvb_get_ntohl(tvb, PAGP_LOCAL_GROUP_CAPABILITY);
291 proto_tree_add_uint(pagp_tree, hf_pagp_local_group_capability, tvb,
292 PAGP_LOCAL_GROUP_CAPABILITY, 4, raw_word);
294 raw_word = tvb_get_ntohl(tvb, PAGP_LOCAL_GROUP_IFINDEX);
295 proto_tree_add_uint(pagp_tree, hf_pagp_local_group_ifindex, tvb,
296 PAGP_LOCAL_GROUP_IFINDEX, 4, raw_word);
299 if (check_col(pinfo->cinfo, COL_INFO)) {
300 col_append_fstr(pinfo->cinfo, COL_INFO, ", Partner DevID: %s",
301 tvb_ether_to_str(tvb, PAGP_PARTNER_DEVICE_ID));
304 proto_tree_add_item(pagp_tree, hf_pagp_partner_device_id, tvb,
305 PAGP_PARTNER_DEVICE_ID, 6, ENC_NA);
309 raw_octet = tvb_get_guint8(tvb, PAGP_PARTNER_LEARN_CAP);
310 proto_tree_add_uint(pagp_tree, hf_pagp_partner_learn_cap, tvb,
311 PAGP_PARTNER_LEARN_CAP, 1, raw_octet);
313 raw_octet = tvb_get_guint8(tvb, PAGP_PARTNER_PORT_PRIORITY);
314 proto_tree_add_uint(pagp_tree, hf_pagp_partner_port_priority, tvb,
315 PAGP_PARTNER_PORT_PRIORITY, 1, raw_octet);
317 raw_word = tvb_get_ntohl(tvb, PAGP_PARTNER_SENT_PORT_IFINDEX);
318 proto_tree_add_uint(pagp_tree, hf_pagp_partner_sent_port_ifindex, tvb,
319 PAGP_PARTNER_SENT_PORT_IFINDEX, 4, raw_word);
321 raw_word = tvb_get_ntohl(tvb, PAGP_PARTNER_GROUP_CAPABILITY);
322 proto_tree_add_uint(pagp_tree, hf_pagp_partner_group_capability, tvb,
323 PAGP_PARTNER_GROUP_CAPABILITY, 4, raw_word);
325 raw_word = tvb_get_ntohl(tvb, PAGP_PARTNER_GROUP_IFINDEX);
326 proto_tree_add_uint(pagp_tree, hf_pagp_partner_group_ifindex, tvb,
327 PAGP_PARTNER_GROUP_IFINDEX, 4, raw_word);
329 raw_half_word = tvb_get_ntohs(tvb, PAGP_PARTNER_COUNT);
330 proto_tree_add_uint(pagp_tree, hf_pagp_partner_count, tvb,
331 PAGP_PARTNER_COUNT, 2, raw_half_word);
333 num_tlvs = tvb_get_ntohs(tvb, PAGP_NUM_TLVS);
334 proto_tree_add_uint(pagp_tree, hf_pagp_num_tlvs, tvb,
335 PAGP_NUM_TLVS, 2, num_tlvs);
337 /* dump TLV entries */
339 for ( i = 1; i <= num_tlvs; i++ ) {
341 tlv = tvb_get_ntohs(tvb, offset);
342 len = tvb_get_ntohs(tvb, offset + 2);
344 proto_tree_add_text(pagp_tree, tvb, offset, -1,
345 "Unknown data - TLV len=0");
349 tlv_item = proto_tree_add_text (pagp_tree, tvb, offset, len,
352 tlv_tree = proto_item_add_subtree (tlv_item, ett_pagp_tlvs);
353 proto_tree_add_uint_format (tlv_tree, hf_pagp_tlv, tvb,
354 offset,2,tlv,"Type = %d (%s)", tlv,
355 val_to_str(tlv,tlv_types, "Unknown")) ;
356 proto_tree_add_text (tlv_tree, tvb, offset+2, 2,
357 "Length = %u bytes (includes Type and Length)", len) ;
358 if ( tvb_reported_length_remaining(tvb, offset) < len ) {
359 proto_tree_add_text(tlv_tree, tvb, offset, -1,
360 "TLV length too large");
365 case PAGP_TLV_DEVICE_NAME:
366 ch = tvb_get_ephemeral_string(tvb, offset+4, len-4);
367 proto_tree_add_string(tlv_tree, hf_pagp_tlv_device_name,
368 tvb, offset+4, len-4, ch);
370 case PAGP_TLV_PORT_NAME:
371 ch = tvb_get_ephemeral_string(tvb, offset+4, len-4);
372 proto_tree_add_string(tlv_tree, hf_pagp_tlv_port_name,
373 tvb, offset+4, len-4, ch);
375 case PAGP_TLV_AGPORT_MAC:
376 proto_tree_add_item(tlv_tree, hf_pagp_tlv_agport_mac,
377 tvb, offset+4, 6, ENC_NA);
379 case PAGP_TLV_RESERVED:
390 /* Register the protocol with Wireshark */
393 proto_register_pagp(void)
395 /* Setup list of header fields */
397 static hf_register_info hf[] = {
399 { &hf_pagp_version_number,
400 { "Version", "pagp.version",
401 FT_UINT8, BASE_HEX, VALS(pdu_vers), 0x0,
402 "Identifies the PAgP PDU version: 1 = Info, 2 = Flush", HFILL }},
405 { "Flags", "pagp.flags",
406 FT_UINT8, BASE_HEX, NULL, 0x0,
407 "Information flags", HFILL }},
409 { &hf_pagp_flags_slow_hello,
410 { "Slow Hello", "pagp.flags.slowhello",
411 FT_BOOLEAN, 8, TFS(&tfs_yes_no), PAGP_FLAGS_SLOW_HELLO,
412 "1 = using Slow Hello, 0 = Slow Hello disabled", HFILL }},
414 { &hf_pagp_flags_auto_mode,
415 { "Auto Mode", "pagp.flags.automode",
416 FT_BOOLEAN, 8, TFS(&automode), PAGP_FLAGS_AUTO_MODE,
417 "1 = Auto Mode enabled, 0 = Desirable Mode", HFILL }},
419 { &hf_pagp_flags_consistent_state,
420 { "Consistent State", "pagp.flags.state",
421 FT_BOOLEAN, 8, NULL, PAGP_FLAGS_CONSISTENT_STATE,
422 "1 = Consistent State, 0 = Not Ready", HFILL }},
424 { &hf_pagp_local_device_id,
425 { "Local Device ID", "pagp.localdevid",
426 FT_ETHER, BASE_NONE, NULL, 0x0,
429 { &hf_pagp_local_learn_cap,
430 { "Local Learn Capability", "pagp.localearncap",
431 FT_UINT8, BASE_HEX, VALS(learn_cap), 0x0,
434 { &hf_pagp_local_port_priority,
435 { "Local Port Hot Standby Priority", "pagp.localportpri",
436 FT_UINT8, BASE_DEC, NULL, 0x0,
437 "The local hot standby priority assigned to this port", HFILL }},
439 { &hf_pagp_local_sent_port_ifindex,
440 { "Local Sent Port ifindex", "pagp.localsentportifindex",
441 FT_UINT32, BASE_DEC, NULL, 0x0,
442 "The interface index of the local port used to send PDU", HFILL }},
444 { &hf_pagp_local_group_capability,
445 { "Local Group Capability", "pagp.localgroupcap",
446 FT_UINT32, BASE_HEX, NULL, 0x0,
447 "The local group capability", HFILL }},
449 { &hf_pagp_local_group_ifindex,
450 { "Local Group ifindex", "pagp.localgroupifindex",
451 FT_UINT32, BASE_DEC, NULL, 0x0,
452 "The local group interface index", HFILL }},
454 { &hf_pagp_partner_device_id,
455 { "Partner Device ID", "pagp.partnerdevid",
456 FT_ETHER, BASE_NONE, NULL, 0x0,
457 "Remote Device ID (MAC)", HFILL }},
459 { &hf_pagp_partner_learn_cap,
460 { "Partner Learn Capability", "pagp.partnerlearncap",
461 FT_UINT8, BASE_HEX, VALS(learn_cap), 0x0,
462 "Remote learn capability", HFILL }},
464 { &hf_pagp_partner_port_priority,
465 { "Partner Port Hot Standby Priority", "pagp.partnerportpri",
466 FT_UINT8, BASE_DEC, NULL, 0x0,
467 "Remote port priority", HFILL }},
469 { &hf_pagp_partner_sent_port_ifindex,
470 { "Partner Sent Port ifindex", "pagp.partnersentportifindex",
471 FT_UINT32, BASE_DEC, NULL, 0x0,
472 "Remote port interface index sent", HFILL }},
474 { &hf_pagp_partner_group_capability,
475 { "Partner Group Capability", "pagp.partnergroupcap",
476 FT_UINT32, BASE_HEX, NULL, 0x0,
477 "Remote group capability", HFILL }},
479 { &hf_pagp_partner_group_ifindex,
480 { "Partner Group ifindex", "pagp.partnergroupifindex",
481 FT_UINT32, BASE_DEC, NULL, 0x0,
482 "Remote group interface index", HFILL }},
484 { &hf_pagp_partner_count,
485 { "Partner Count", "pagp.partnercount",
486 FT_UINT16, BASE_DEC, NULL, 0x0,
490 { "Number of TLVs", "pagp.numtlvs",
491 FT_UINT16, BASE_DEC, NULL, 0x0,
492 "Number of TLVs following", HFILL }},
495 { "Entry", "pagp.tlv",
496 FT_UINT16, BASE_DEC, NULL, 0x0,
497 "Type/Length/Value", HFILL }},
499 { &hf_pagp_tlv_device_name,
500 { "Device Name", "pagp.tlvdevname",
501 FT_STRING, BASE_NONE, NULL, 0x0,
502 "sysName of device", HFILL }},
504 { &hf_pagp_tlv_port_name,
505 { "Physical Port Name", "pagp.tlvportname",
506 FT_STRING, BASE_NONE, NULL, 0x0,
507 "Name of port used to send PDU", HFILL }},
509 { &hf_pagp_tlv_agport_mac,
510 { "Agport MAC Address", "pagp.tlvagportmac",
511 FT_ETHER, BASE_NONE, NULL, 0x0,
512 "Source MAC on frames for this aggregate", HFILL }},
514 { &hf_pagp_flush_local_device_id,
515 { "Flush Local Device ID", "pagp.flushlocaldevid",
516 FT_ETHER, BASE_NONE, NULL, 0x0,
519 { &hf_pagp_flush_partner_device_id,
520 { "Flush Partner Device ID", "pagp.flushpartnerdevid",
521 FT_ETHER, BASE_NONE, NULL, 0x0,
522 "Flush remote device ID", HFILL }},
524 { &hf_pagp_flush_transaction_id,
525 { "Transaction ID", "pagp.transid",
526 FT_UINT32, BASE_HEX, NULL, 0x0,
527 "Flush transaction ID", HFILL }},
531 /* Setup protocol subtree array */
533 static gint *ett[] = {
539 /* Register the protocol name and description */
541 proto_pagp = proto_register_protocol("Port Aggregation Protocol", "PAGP", "pagp");
543 /* Required function calls to register the header fields and subtrees used */
545 proto_register_field_array(proto_pagp, hf, array_length(hf));
546 proto_register_subtree_array(ett, array_length(ett));
552 proto_reg_handoff_pagp(void)
554 dissector_handle_t pagp_handle;
556 pagp_handle = create_dissector_handle(dissect_pagp, proto_pagp);
557 dissector_add_uint("llc.cisco_pid", 0x0104, pagp_handle);