Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-brcm-tag.c
blob66a4d0334974bf2dd33babe2c59f2851ad43909e
1 /* packet-brcm-tag.c
2 * Routines for Broadcom tag dissection
4 * Copyright 2017, Florian Fainelli <f.fainelli[AT]gmail.com>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald[AT]wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
13 #include "config.h"
15 #include <epan/packet.h>
16 #include <epan/etypes.h>
17 #include <epan/ptvcursor.h>
19 void proto_register_brcm_tag(void);
20 void proto_reg_handoff_brcm_tag(void);
22 static dissector_handle_t brcm_tag_handle;
24 #define BRCM_TAG_LEN 4
25 #define BRCM_TAG_OPCODE_MASK 0x7
26 #define BRCM_TAG_DEV_ID_MASK 0x3
27 #define BRCM_TAG_SRC_DEV_ID_SHIFT 4
28 #define BRCM_TAG_PORT_ID_MASK 0xF
30 #define BRCM_TAG_OPCODE_UNICAST 0x0
31 #define BRCM_TAG_OPCODE_MULTICAST 0x1
32 #define BRCM_TAG_OPCODE_EG_DIRECT 0x2
33 #define BRCM_TAG_OPCODE_IG_DIRECT 0x3
34 #define BRCM_TAG_OPCODE_SHIFT 5
36 #define BRCM_TAG_MR_SHIFT 4
37 #define BRCM_TAG_MO_SHIFT 3
39 static int proto_brcm_tag;
41 static int hf_brcm_tag_opcode;
42 static int hf_brcm_tag_frame_octet_cnt;
43 static int hf_brcm_tag_mr;
44 static int hf_brcm_tag_mo;
45 static int hf_brcm_tag_reserved;
46 static int hf_brcm_tag_dest_dev_id;
47 static int hf_brcm_tag_dest_port_id;
48 static int hf_brcm_tag_src_dev_id;
49 static int hf_brcm_tag_src_port_id;
51 static int ett_brcm_tag;
53 #define TVB_LEN_GREATEST 1
54 #define TVB_LEN_UNDEF 0
55 #define TVB_LEN_SHORTEST -1
57 static int check_tvb_length(ptvcursor_t *cursor, const int length)
59 if (!cursor)
60 return TVB_LEN_UNDEF;
62 if (tvb_reported_length_remaining(ptvcursor_tvbuff(cursor),
63 ptvcursor_current_offset(cursor)) < length)
64 return TVB_LEN_SHORTEST;
66 return TVB_LEN_GREATEST;
69 static const value_string brcm_tag_opcode_vals[] = {
70 { BRCM_TAG_OPCODE_UNICAST, "Unicast" },
71 { BRCM_TAG_OPCODE_MULTICAST, "Multicast" },
72 { BRCM_TAG_OPCODE_EG_DIRECT, "Egress directed" },
73 { BRCM_TAG_OPCODE_IG_DIRECT, "Ingress directed" },
74 { 0, NULL }
77 static int
78 dissect_brcm_tag(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
80 proto_item *ti;
81 proto_tree *brcm_tag_tree;
82 ptvcursor_t *cursor;
83 uint8_t opcode_mr_mo;
84 uint8_t opcode;
86 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Broadcom tag");
87 col_set_str(pinfo->cinfo, COL_INFO, "MAC Management");
89 ti = proto_tree_add_item(tree, proto_brcm_tag, tvb, 0, -1, ENC_NA);
90 brcm_tag_tree = proto_item_add_subtree(ti, ett_brcm_tag);
92 cursor = ptvcursor_new(pinfo->pool, brcm_tag_tree, tvb, 0);
94 /* Check if we have enough data to process the header */
95 if (check_tvb_length(cursor, BRCM_TAG_LEN) != TVB_LEN_SHORTEST) {
96 opcode_mr_mo = tvb_get_uint8(ptvcursor_tvbuff(cursor), ptvcursor_current_offset(cursor));
97 opcode = (opcode_mr_mo >> BRCM_TAG_OPCODE_SHIFT) & BRCM_TAG_OPCODE_MASK;
99 ptvcursor_add_no_advance(cursor, hf_brcm_tag_opcode, 1, ENC_NA);
100 ptvcursor_add_no_advance(cursor, hf_brcm_tag_mr, 1, ENC_NA);
101 ptvcursor_add(cursor, hf_brcm_tag_mo, 1, ENC_NA);
102 ptvcursor_add(cursor, hf_brcm_tag_frame_octet_cnt, 2, ENC_BIG_ENDIAN);
104 if (opcode == BRCM_TAG_OPCODE_UNICAST || opcode == BRCM_TAG_OPCODE_EG_DIRECT)
105 ptvcursor_add(cursor, hf_brcm_tag_dest_dev_id, 1, ENC_NA);
106 else
107 ptvcursor_add(cursor, hf_brcm_tag_reserved, 1, ENC_NA);
108 ptvcursor_add_no_advance(cursor, hf_brcm_tag_src_dev_id, 1, ENC_NA);
109 if (opcode == BRCM_TAG_OPCODE_EG_DIRECT)
110 ptvcursor_add_no_advance(cursor, hf_brcm_tag_dest_port_id, 1, ENC_NA);
111 else
112 ptvcursor_add_no_advance(cursor, hf_brcm_tag_src_port_id, 1, ENC_NA);
115 ptvcursor_free(cursor);
116 return tvb_captured_length(tvb);
119 void
120 proto_register_brcm_tag(void)
122 static hf_register_info hf[] = {
123 { &hf_brcm_tag_opcode,
124 { "Opcode", "brcm_tag.opcode",
125 FT_UINT8, BASE_HEX, VALS(brcm_tag_opcode_vals),
126 BRCM_TAG_OPCODE_MASK << BRCM_TAG_OPCODE_SHIFT, NULL, HFILL }
128 { &hf_brcm_tag_mr,
129 { "Mirror bit", "brcm_tag.mr",
130 FT_UINT8, BASE_HEX, NULL, 1 << BRCM_TAG_MR_SHIFT, NULL, HFILL }
132 { &hf_brcm_tag_mo,
133 { "Mirror only", "brcm_tag.mo",
134 FT_UINT8, BASE_HEX, NULL, 1 << BRCM_TAG_MO_SHIFT, NULL, HFILL }
136 { &hf_brcm_tag_reserved,
137 { "Reserved", "brcm_tag.reserved",
138 FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
140 { &hf_brcm_tag_frame_octet_cnt,
141 { "Frame octet count", "brcm_tag.frame_octet_cnt",
142 FT_UINT16, BASE_DEC, NULL, 0x0FFF, NULL, HFILL }
144 { &hf_brcm_tag_dest_dev_id,
145 { "Destination device ID", "brcm_tag.dest_dev_id",
146 FT_UINT8, BASE_DEC, NULL, BRCM_TAG_DEV_ID_MASK, NULL, HFILL }
148 { &hf_brcm_tag_dest_port_id,
149 { "Destination port ID", "brcm_tag.dest_port_id",
150 FT_UINT8, BASE_DEC, NULL, BRCM_TAG_PORT_ID_MASK, NULL, HFILL }
152 { &hf_brcm_tag_src_dev_id,
153 { "Source device ID", "brcm_tag.src_dev_id",
154 FT_UINT8, BASE_DEC, NULL, BRCM_TAG_DEV_ID_MASK << BRCM_TAG_SRC_DEV_ID_SHIFT, NULL, HFILL }
156 { &hf_brcm_tag_src_port_id,
157 { "Source port ID", "brcm_tag.src_port_id",
158 FT_UINT8, BASE_DEC, NULL, BRCM_TAG_PORT_ID_MASK, NULL, HFILL }
162 static int *ett[] = {
163 &ett_brcm_tag,
165 proto_brcm_tag = proto_register_protocol("Broadcom tag protocol", "Broadcom tag", "brcm-tag");
167 proto_register_field_array(proto_brcm_tag, hf, array_length(hf));
169 proto_register_subtree_array(ett, array_length(ett));
171 brcm_tag_handle = register_dissector("brcm-tag", dissect_brcm_tag, proto_brcm_tag);
174 void
175 proto_reg_handoff_brcm_tag(void)
177 dissector_add_uint("ethertype", ETHERTYPE_BRCM_TYPE, brcm_tag_handle);
181 * Editor modelines
183 * Local Variables:
184 * c-basic-offset: 3
185 * tab-width: 8
186 * indent-tabs-mode: nil
187 * End:
189 * ex: set shiftwidth=3 tabstop=8 expandtab:
190 * :indentSize=3:tabSize=8:noTabs=true: