| File: | builds/wireshark/wireshark/epan/dissectors/packet-dsa.c |
| Warning: | line 349, column 9 Value stored to 'offset' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* packet-dsa.c |
| 2 | * Dissector for Marvell DSA- and EDSA-tagged Ethernet frames |
| 3 | * |
| 4 | * Wireshark - Network traffic analyzer |
| 5 | * By Gerald Combs <gerald@wireshark.org> |
| 6 | * Copyright 1998 Gerald Combs |
| 7 | * |
| 8 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 9 | * |
| 10 | * Dissects Ethernet frames with a Marvell (EtherType) Distributed |
| 11 | * Switch Architecture tag. The switch chip uses it for bidirectionally |
| 12 | * passing additional metadata. |
| 13 | * |
| 14 | * Frame layout: |
| 15 | * DSA: | DA(6) | SA(6) | DSA tag(4) | EtherType/Length(2) | payload | |
| 16 | * EDSA: | DA(6) | SA(6) | prog. EtherType(2) | 0x0000(2) | DSA tag(4) | EtherType/Length(2) | payload | |
| 17 | * |
| 18 | * The first EtherType in the EDSA tag is not a constant but a |
| 19 | * programmable value. |
| 20 | * |
| 21 | * The 4-byte DSA tag (big-endian bitfields): |
| 22 | * Byte 0: cmd[7:6] | tagged[5] | device[4:0] |
| 23 | * Byte 1: port[7:3] | cmd-specific[2:1] | cfi[0] |
| 24 | * Byte 2: pcp[7:5] | cmd-specific[4] | vid[11:8][3:0] |
| 25 | * Byte 3: vid[7:0] |
| 26 | */ |
| 27 | #include "config.h" |
| 28 | |
| 29 | #include <epan/packet.h> |
| 30 | #include <epan/etypes.h> |
| 31 | #include <epan/expert.h> |
| 32 | #include <wiretap/wtap.h> |
| 33 | #include "packet-ieee8023.h" |
| 34 | |
| 35 | void proto_register_dsa(void); |
| 36 | void proto_reg_handoff_dsa(void); |
| 37 | |
| 38 | /* Protocols */ |
| 39 | static int proto_dsa; |
| 40 | static int proto_edsa; |
| 41 | |
| 42 | /* Subtrees */ |
| 43 | static int ett_frame; |
| 44 | static int ett_tag_dsa; |
| 45 | static int ett_tag_edsa; |
| 46 | |
| 47 | /* Header fields */ |
| 48 | static int hf_dsa_da; |
| 49 | static int hf_dsa_sa; |
| 50 | static int hf_dsa_edsa_etype; |
| 51 | static int hf_dsa_edsa_reserved; |
| 52 | static int hf_dsa_type; |
| 53 | static int hf_dsa_len; |
| 54 | static int hf_dsa_cmd; |
| 55 | static int hf_dsa_tagged; |
| 56 | static int hf_dsa_device; |
| 57 | static int hf_dsa_port; |
| 58 | static int hf_dsa_trunk; |
| 59 | static int hf_dsa_rx_sniff; |
| 60 | static int hf_dsa_code; |
| 61 | static int hf_dsa_pcp; |
| 62 | static int hf_dsa_cfi; |
| 63 | static int hf_dsa_vid; |
| 64 | static int hf_dsa_ingress_vid; |
| 65 | static int hf_dsa_unused_byte1_bit1; |
| 66 | static int hf_dsa_unused_byte1_bits_21; |
| 67 | static int hf_dsa_unused_byte2_bit4; |
| 68 | static int hf_dsa_trailer; |
| 69 | |
| 70 | /* Dissector handles */ |
| 71 | static dissector_handle_t dsa_handle; |
| 72 | static dissector_handle_t edsa_handle; |
| 73 | static dissector_handle_t ethertype_handle; |
| 74 | |
| 75 | /* Expert info */ |
| 76 | static expert_module_t *expert_dsa; |
| 77 | static expert_field ei_dsa_too_short; |
| 78 | static expert_field ei_dsa_bad_reserved; |
| 79 | static expert_field ei_dsa_len; |
| 80 | |
| 81 | /* |
| 82 | * Geometry of the 4-byte DSA tag (big-endian; bit 7 is the MSB of each |
| 83 | * byte). The masks name the bits as they sit within a byte. |
| 84 | */ |
| 85 | #define DSA_TAG_CMD_MASK0xC0 0xC0 /* byte 0, bits 7:6 (command) */ |
| 86 | #define DSA_TAG_CMD_POS6 6 /* shift to isolate the command */ |
| 87 | #define DSA_TAG_TAGGED0x20 0x20 /* byte 0, bit 5 (tagged) */ |
| 88 | #define DSA_TAG_DEV_MASK0x1F 0x1F /* byte 0, bits 4:0 (device) */ |
| 89 | #define DSA_TAG_PORT_MASK0xF8 0xF8 /* byte 1, bits 7:3 (port) */ |
| 90 | #define DSA_TAG_PORT_POS3 3 /* shift to isolate the port */ |
| 91 | #define DSA_TAG_B1_BIT20x04 0x04 /* byte 1, bit 2 */ |
| 92 | #define DSA_TAG_B1_BIT10x02 0x02 /* byte 1, bit 1 */ |
| 93 | #define DSA_TAG_CFI0x01 0x01 /* byte 1, bit 0 (CFI) */ |
| 94 | #define DSA_TAG_PCP_MASK0xE0 0xE0 /* byte 2, bits 7:5 (PCP) */ |
| 95 | #define DSA_TAG_B2_BIT40x10 0x10 /* byte 2, bit 4 */ |
| 96 | #define DSA_TAG_VID_MASK0x0FFF 0x0FFF /* byte 2, bits 3:0 + byte 3 */ |
| 97 | |
| 98 | /* DSA command values */ |
| 99 | #define DSA_CMD_TO_CPU0 0 |
| 100 | #define DSA_CMD_FROM_CPU1 1 |
| 101 | #define DSA_CMD_TO_SNIFFER2 2 |
| 102 | #define DSA_CMD_FORWARD3 3 |
| 103 | |
| 104 | static const value_string dsa_cmd_vals[] = { |
| 105 | { DSA_CMD_TO_CPU0, "TO_CPU" }, |
| 106 | { DSA_CMD_FROM_CPU1, "FROM_CPU" }, |
| 107 | { DSA_CMD_TO_SNIFFER2, "TO_SNIFFER" }, |
| 108 | { DSA_CMD_FORWARD3, "FORWARD" }, |
| 109 | { 0, NULL((void*)0) } |
| 110 | }; |
| 111 | |
| 112 | /* DSA TO_CPU code values */ |
| 113 | static const value_string dsa_code_vals[] = { |
| 114 | { 0, "MGMT_TRAP" }, |
| 115 | { 1, "FRAME2REG" }, |
| 116 | { 2, "IGMP_MLD_TRAP" }, |
| 117 | { 3, "POLICY_TRAP" }, |
| 118 | { 4, "ARP_MIRROR" }, |
| 119 | { 5, "POLICY_MIRROR" }, |
| 120 | { 6, "RESERVED_6" }, |
| 121 | { 7, "RESERVED_7" }, |
| 122 | { 0, NULL((void*)0) } |
| 123 | }; |
| 124 | |
| 125 | /* |
| 126 | * The TO_CPU code is 3 bits split across two bytes of the tag: |
| 127 | * code[2:1] = byte1 bits [2:1], code[0] = byte2 bit [4]. |
| 128 | * Crumb bit offsets are relative to the start of byte 1 |
| 129 | * (bit_offset = (tag_offset + 1) * 8), most significant crumb first. |
| 130 | */ |
| 131 | static const crumb_spec_t dsa_code_crumbs[] = { |
| 132 | { 5, 2 }, /* byte1 bits [2:1] = code[2:1] */ |
| 133 | { 11, 1 }, /* byte2 bit [4] = code[0] */ |
| 134 | { 0, 0 } /* sentinel */ |
| 135 | }; |
| 136 | |
| 137 | /* |
| 138 | * Dissect the 4-byte DSA tag at the given offset, in its own subtree |
| 139 | * under the given tree. Returns the command value for info column use. |
| 140 | */ |
| 141 | static int |
| 142 | dissect_dsa_tag(proto_tree *parent_tree, tvbuff_t *tvb, unsigned tag_offset, |
| 143 | uint32_t *port, bool_Bool *trunk) |
| 144 | { |
| 145 | proto_tree *tag_tree; |
| 146 | uint8_t byte0; |
| 147 | uint8_t byte1; |
| 148 | int cmd; |
| 149 | bool_Bool tagged; |
| 150 | |
| 151 | if (tvb_reported_length_remaining(tvb, tag_offset) < 4) { |
| 152 | return -1; |
| 153 | } |
| 154 | |
| 155 | tag_tree = proto_tree_add_subtree(parent_tree, tvb, tag_offset, 4, |
| 156 | ett_tag_dsa, NULL((void*)0), "DSA tag"); |
| 157 | |
| 158 | byte0 = tvb_get_uint8(tvb, tag_offset); |
| 159 | |
| 160 | cmd = (byte0 & DSA_TAG_CMD_MASK0xC0) >> DSA_TAG_CMD_POS6; |
| 161 | tagged = !!(byte0 & DSA_TAG_TAGGED0x20); |
| 162 | |
| 163 | /* Byte 0: cmd[7:6] | tagged[5] | device[4:0] */ |
| 164 | proto_tree_add_item(tag_tree, hf_dsa_cmd, tvb, tag_offset, 1, ENC_BIG_ENDIAN0x00000000); |
| 165 | proto_tree_add_item(tag_tree, hf_dsa_tagged, tvb, tag_offset, 1, ENC_BIG_ENDIAN0x00000000); |
| 166 | proto_tree_add_item(tag_tree, hf_dsa_device, tvb, tag_offset, 1, ENC_BIG_ENDIAN0x00000000); |
| 167 | |
| 168 | /* Byte 1: port[7:3] | (command-dependent bits [2:1]) | cfi[0] */ |
| 169 | byte1 = tvb_get_uint8(tvb, tag_offset + 1); |
| 170 | *port = byte1 >> DSA_TAG_PORT_POS3; |
| 171 | proto_tree_add_item(tag_tree, hf_dsa_port, tvb, tag_offset + 1, 1, ENC_BIG_ENDIAN0x00000000); |
| 172 | |
| 173 | switch (cmd) { |
| 174 | case DSA_CMD_TO_CPU0: /* code[2:1] in byte1 bits [2:1], code[0] in byte2 bit [4] */ |
| 175 | proto_tree_add_split_bits_item_ret_val(tag_tree, hf_dsa_code, tvb, |
| 176 | (tag_offset + 1) * 8, dsa_code_crumbs, NULL((void*)0)); |
| 177 | break; |
| 178 | case DSA_CMD_FROM_CPU1: /* bits [2:1] both unused */ |
| 179 | proto_tree_add_item(tag_tree, hf_dsa_unused_byte1_bits_21, tvb, tag_offset + 1, 1, ENC_BIG_ENDIAN0x00000000); |
| 180 | break; |
| 181 | case DSA_CMD_TO_SNIFFER2: /* bit2=rx_sniff (ingress), bit1=unused */ |
| 182 | proto_tree_add_item(tag_tree, hf_dsa_rx_sniff, tvb, tag_offset + 1, 1, ENC_BIG_ENDIAN0x00000000); |
| 183 | proto_tree_add_item(tag_tree, hf_dsa_unused_byte1_bit1, tvb, tag_offset + 1, 1, ENC_BIG_ENDIAN0x00000000); |
| 184 | break; |
| 185 | case DSA_CMD_FORWARD3: /* bit2=trunk, bit1=unused */ |
| 186 | *trunk = !!(byte1 & DSA_TAG_B1_BIT20x04); |
| 187 | proto_tree_add_item(tag_tree, hf_dsa_trunk, tvb, tag_offset + 1, 1, ENC_BIG_ENDIAN0x00000000); |
| 188 | proto_tree_add_item(tag_tree, hf_dsa_unused_byte1_bit1, tvb, tag_offset + 1, 1, ENC_BIG_ENDIAN0x00000000); |
| 189 | break; |
| 190 | default: /* unreachable: cmd is a 2-bit field, all values handled above */ |
| 191 | DISSECTOR_ASSERT_NOT_REACHED()(proto_report_dissector_bug("%s:%u: failed assertion \"DISSECTOR_ASSERT_NOT_REACHED\"" , "epan/dissectors/packet-dsa.c", 191)); |
| 192 | break; |
| 193 | } |
| 194 | |
| 195 | proto_tree_add_item(tag_tree, hf_dsa_cfi, tvb, tag_offset + 1, 1, ENC_BIG_ENDIAN0x00000000); |
| 196 | |
| 197 | /* Byte 2: pcp[7:5] | (command-dependent bit4) | vid[11:8][3:0] |
| 198 | * bit4 is code[0] only in TO_CPU (shown in the Code bitmap above); |
| 199 | * unused in all other commands. */ |
| 200 | proto_tree_add_item(tag_tree, hf_dsa_pcp, tvb, tag_offset + 2, 1, ENC_BIG_ENDIAN0x00000000); |
| 201 | |
| 202 | if (cmd != DSA_CMD_TO_CPU0) { |
| 203 | proto_tree_add_item(tag_tree, hf_dsa_unused_byte2_bit4, tvb, tag_offset + 2, 1, ENC_BIG_ENDIAN0x00000000); |
| 204 | } |
| 205 | |
| 206 | /* Bytes 2-3: VID (12 bits: byte2[3:0] + byte3[7:0]) */ |
| 207 | if (tagged) { |
| 208 | proto_tree_add_item(tag_tree, hf_dsa_vid, tvb, tag_offset + 2, 2, ENC_BIG_ENDIAN0x00000000); |
| 209 | } else { |
| 210 | proto_tree_add_item(tag_tree, hf_dsa_ingress_vid, tvb, tag_offset + 2, 2, ENC_BIG_ENDIAN0x00000000); |
| 211 | } |
| 212 | |
| 213 | return cmd; |
| 214 | } |
| 215 | |
| 216 | /* |
| 217 | * Dissect the 8-byte EDSA tag at the given offset: a programmable |
| 218 | * EtherType, a reserved field (which must be 0x0000), then the 4-byte |
| 219 | * DSA tag. The EDSA tag gets its own subtree, with the DSA tag nested |
| 220 | * inside it. Returns the command value for info column use, or -1 if |
| 221 | * the tag is truncated. |
| 222 | */ |
| 223 | static int |
| 224 | dissect_edsa_tag(packet_info *pinfo, proto_tree *parent_tree, tvbuff_t *tvb, |
| 225 | unsigned tag_offset, uint32_t *port, bool_Bool *trunk) |
| 226 | { |
| 227 | proto_tree *edsa_tree; |
| 228 | |
| 229 | /* The EtherType is programmable; show it as-is. */ |
| 230 | if (tvb_reported_length_remaining(tvb, tag_offset) < 2) |
| 231 | return -1; |
| 232 | |
| 233 | edsa_tree = proto_tree_add_subtree(parent_tree, tvb, tag_offset, 8, |
| 234 | ett_tag_edsa, NULL((void*)0), "EDSA tag"); |
| 235 | |
| 236 | proto_tree_add_item(edsa_tree, hf_dsa_edsa_etype, tvb, tag_offset, 2, |
| 237 | ENC_BIG_ENDIAN0x00000000); |
| 238 | |
| 239 | if (tvb_reported_length_remaining(tvb, tag_offset + 2) < 2) |
| 240 | return -1; |
| 241 | { |
| 242 | uint16_t edsa_reserved = tvb_get_ntohs(tvb, tag_offset + 2); |
| 243 | proto_item *res_ti = proto_tree_add_item(edsa_tree, |
| 244 | hf_dsa_edsa_reserved, tvb, tag_offset + 2, 2, ENC_BIG_ENDIAN0x00000000); |
| 245 | if (edsa_reserved != 0) { |
| 246 | expert_add_info_format(pinfo, res_ti, &ei_dsa_bad_reserved, |
| 247 | "Non-zero EDSA reserved field 0x%04x", edsa_reserved); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | /* The 4-byte DSA tag the EDSA tag wraps */ |
| 252 | return dissect_dsa_tag(edsa_tree, tvb, tag_offset + 4, port, trunk); |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * Common dissection of a DSA or EDSA frame. |
| 257 | * The tvb starts at the beginning of the frame data (DA address). |
| 258 | * The frame fields (addresses, type/length) are dissected directly; the |
| 259 | * tag is delegated to dissect_dsa_tag() or dissect_edsa_tag(), each of |
| 260 | * which nests its tag in its own subtree. |
| 261 | */ |
| 262 | static int |
| 263 | dissect_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, |
| 264 | bool_Bool is_edsa) |
| 265 | { |
| 266 | proto_item *ti; |
| 267 | proto_tree *frame_tree; |
| 268 | unsigned offset; |
| 269 | uint16_t etype; |
| 270 | ethertype_data_t ethertype_data; |
| 271 | int cmd; |
| 272 | uint32_t port = 0; |
| 273 | bool_Bool trunk = false0; |
| 274 | |
| 275 | /* Full header length including the type/length field */ |
| 276 | const unsigned full_len = 12 + (is_edsa ? 4 : 0) + 4 + 2; |
| 277 | |
| 278 | col_set_str(pinfo->cinfo, COL_PROTOCOL, is_edsa ? "EDSA" : "DSA"); |
| 279 | |
| 280 | ti = proto_tree_add_item(tree, is_edsa ? proto_edsa : proto_dsa, tvb, 0, |
| 281 | full_len, ENC_NA0x00000000); |
| 282 | frame_tree = proto_item_add_subtree(ti, ett_frame); |
| 283 | |
| 284 | if (tvb_reported_length(tvb) < full_len) { |
| 285 | expert_add_info_format(pinfo, ti, &ei_dsa_too_short, |
| 286 | "DSA frame too short: expected %u bytes, available %u bytes", |
| 287 | full_len, tvb_reported_length(tvb)); |
| 288 | } |
| 289 | |
| 290 | offset = 0; |
| 291 | |
| 292 | /* DA and SA */ |
| 293 | if (tvb_reported_length_remaining(tvb, offset) < 12) |
| 294 | goto out; |
| 295 | proto_tree_add_item(frame_tree, hf_dsa_da, tvb, offset, 6, ENC_NA0x00000000); |
| 296 | offset += 6; |
| 297 | proto_tree_add_item(frame_tree, hf_dsa_sa, tvb, offset, 6, ENC_NA0x00000000); |
| 298 | offset += 6; |
| 299 | |
| 300 | /* |
| 301 | * Dissect the 4-byte DSA tag, or the 8-byte EDSA tag, reporting the |
| 302 | * port and the trunk bit, which the info column below is built from. |
| 303 | */ |
| 304 | if (is_edsa) { |
| 305 | cmd = dissect_edsa_tag(pinfo, frame_tree, tvb, offset, &port, &trunk); |
| 306 | if (cmd < 0) |
| 307 | goto out; |
| 308 | offset += 8; |
| 309 | } else { |
| 310 | cmd = dissect_dsa_tag(frame_tree, tvb, offset, &port, &trunk); |
| 311 | if (cmd < 0) |
| 312 | goto out; |
| 313 | offset += 4; |
| 314 | } |
| 315 | |
| 316 | /* Info column */ |
| 317 | { |
| 318 | const char *cmd_name = val_to_str_const(cmd, dsa_cmd_vals, "?"); |
| 319 | if (cmd == DSA_CMD_FORWARD3 && trunk) |
| 320 | col_add_fstr(pinfo->cinfo, COL_INFO, "%s, trunk %u", cmd_name, port); |
| 321 | else |
| 322 | col_add_fstr(pinfo->cinfo, COL_INFO, "%s, port %u", cmd_name, port); |
| 323 | } |
| 324 | |
| 325 | /* |
| 326 | * The two bytes after the tag are the type/length field of the |
| 327 | * encapsulated Ethernet frame, as in packet-eth.c: |
| 328 | * a value <= the maximum 802.3 length (and non-zero) is a |
| 329 | * length field (802.3/LLC framing, e.g. STP BPDUs); otherwise |
| 330 | * it is an EtherType. |
| 331 | */ |
| 332 | if (tvb_reported_length_remaining(tvb, offset) < 2) |
| 333 | goto out; |
| 334 | etype = tvb_get_ntohs(tvb, offset); |
| 335 | if (etype <= IEEE_802_3_MAX_LEN1500 && etype != ETHERTYPE_UNK0x0000) { |
| 336 | bool_Bool is_802_2 = true1; |
| 337 | |
| 338 | /* |
| 339 | * If the first two bytes of the payload are 0xFFFF there |
| 340 | * is no 802.2 (LLC) header; the payload is a "raw" 802.3 |
| 341 | * (IPX or CCSDS) payload. |
| 342 | */ |
| 343 | if (tvb_reported_length_remaining(tvb, offset + 2) >= 2 && |
| 344 | tvb_get_ntohs(tvb, offset + 2) == 0xFFFF) { |
| 345 | is_802_2 = false0; |
| 346 | } |
| 347 | dissect_802_3(etype, is_802_2, tvb, offset + 2, pinfo, |
| 348 | tree, frame_tree, hf_dsa_len, hf_dsa_trailer, &ei_dsa_len, 0); |
| 349 | offset += 2; |
Value stored to 'offset' is never read | |
| 350 | } else { |
| 351 | proto_tree_add_item(frame_tree, hf_dsa_type, tvb, offset, 2, ENC_BIG_ENDIAN0x00000000); |
| 352 | ethertype_data.etype = etype; |
| 353 | ethertype_data.payload_offset = offset + 2; |
| 354 | ethertype_data.fh_tree = frame_tree; |
| 355 | ethertype_data.trailer_id = hf_dsa_trailer; |
| 356 | ethertype_data.fcs_len = 0; |
| 357 | call_dissector_with_data(ethertype_handle, tvb, pinfo, tree, ðertype_data); |
| 358 | offset += 2; |
| 359 | } |
| 360 | |
| 361 | out: |
| 362 | return tvb_captured_length(tvb); |
| 363 | } |
| 364 | |
| 365 | static int |
| 366 | dissect_dsa_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, |
| 367 | void *data _U___attribute__((unused))) |
| 368 | { |
| 369 | return dissect_frame(tvb, pinfo, tree, false0); |
| 370 | } |
| 371 | |
| 372 | static int |
| 373 | dissect_edsa_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, |
| 374 | void *data _U___attribute__((unused))) |
| 375 | { |
| 376 | return dissect_frame(tvb, pinfo, tree, true1); |
| 377 | } |
| 378 | |
| 379 | void |
| 380 | proto_register_dsa(void) |
| 381 | { |
| 382 | static hf_register_info hf[] = { |
| 383 | { &hf_dsa_da, |
| 384 | { "Destination", "dsa.da", |
| 385 | FT_ETHER, BASE_NONE, NULL((void*)0), 0x0, |
| 386 | "Destination address", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 387 | }, |
| 388 | { &hf_dsa_sa, |
| 389 | { "Source", "dsa.sa", |
| 390 | FT_ETHER, BASE_NONE, NULL((void*)0), 0x0, |
| 391 | "Source address", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 392 | }, |
| 393 | { &hf_dsa_edsa_etype, |
| 394 | { "DSA EtherType", "dsa.edsa.etype", |
| 395 | FT_UINT16, BASE_HEX, NULL((void*)0), 0x0, |
| 396 | "EtherType marker preceding the DSA tag", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 397 | }, |
| 398 | { &hf_dsa_edsa_reserved, |
| 399 | { "Reserved", "dsa.edsa.reserved", |
| 400 | FT_UINT16, BASE_HEX, NULL((void*)0), 0x0, |
| 401 | "Reserved (should be 0x0000)", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 402 | }, |
| 403 | { &hf_dsa_type, |
| 404 | { "Type", "dsa.type", |
| 405 | FT_UINT16, BASE_HEX, VALS(etype_vals)((0 ? (const struct _value_string*)0 : ((etype_vals)))), 0x0, |
| 406 | "Encapsulated Ethernet protocol type", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 407 | }, |
| 408 | { &hf_dsa_len, |
| 409 | { "Length", "dsa.length", |
| 410 | FT_UINT16, BASE_DEC, NULL((void*)0), 0x0, |
| 411 | "802.3 length of the encapsulated frame payload", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 412 | }, |
| 413 | { &hf_dsa_cmd, |
| 414 | { "Command", "dsa.cmd", |
| 415 | FT_UINT8, BASE_DEC, VALS(dsa_cmd_vals)((0 ? (const struct _value_string*)0 : ((dsa_cmd_vals)))), DSA_TAG_CMD_MASK0xC0, |
| 416 | "DSA command", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 417 | }, |
| 418 | { &hf_dsa_tagged, |
| 419 | { "Tagged", "dsa.tagged", |
| 420 | FT_BOOLEAN, 8, NULL((void*)0), DSA_TAG_TAGGED0x20, |
| 421 | "VLAN tag present in DSA header", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 422 | }, |
| 423 | { &hf_dsa_device, |
| 424 | { "Device", "dsa.device", |
| 425 | FT_UINT8, BASE_DEC, NULL((void*)0), DSA_TAG_DEV_MASK0x1F, |
| 426 | "Switch device number", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 427 | }, |
| 428 | { &hf_dsa_port, |
| 429 | { "Port", "dsa.port", |
| 430 | FT_UINT8, BASE_DEC, NULL((void*)0), DSA_TAG_PORT_MASK0xF8, |
| 431 | "Switch port number", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 432 | }, |
| 433 | { &hf_dsa_trunk, |
| 434 | { "Trunk", "dsa.trunk", |
| 435 | FT_BOOLEAN, 8, NULL((void*)0), DSA_TAG_B1_BIT20x04, |
| 436 | "Trunk (LAG) membership (FORWARD command)", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 437 | }, |
| 438 | { &hf_dsa_rx_sniff, |
| 439 | { "Rx Sniff", "dsa.rx_sniff", |
| 440 | FT_BOOLEAN, 8, NULL((void*)0), DSA_TAG_B1_BIT20x04, |
| 441 | "Ingress sniff (TO_SNIFFER command)", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 442 | }, |
| 443 | { &hf_dsa_code, |
| 444 | { "Code", "dsa.code", |
| 445 | FT_UINT8, BASE_DEC, VALS(dsa_code_vals)((0 ? (const struct _value_string*)0 : ((dsa_code_vals)))), 0x0, |
| 446 | "TO_CPU code (byte1 bits [2:1] + byte2 bit [4])", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 447 | }, |
| 448 | { &hf_dsa_pcp, |
| 449 | { "PCP", "dsa.pcp", |
| 450 | FT_UINT8, BASE_DEC, NULL((void*)0), DSA_TAG_PCP_MASK0xE0, |
| 451 | "802.1Q Priority Code Point", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 452 | }, |
| 453 | { &hf_dsa_cfi, |
| 454 | { "CFI", "dsa.cfi", |
| 455 | FT_BOOLEAN, 8, NULL((void*)0), DSA_TAG_CFI0x01, |
| 456 | "802.1Q Canonical Format Indicator", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 457 | }, |
| 458 | { &hf_dsa_vid, |
| 459 | { "VID", "dsa.vid", |
| 460 | FT_UINT16, BASE_DEC, NULL((void*)0), DSA_TAG_VID_MASK0x0FFF, |
| 461 | "802.1Q VLAN ID (byte2[3:0] + byte3)", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 462 | }, |
| 463 | { &hf_dsa_ingress_vid, |
| 464 | { "Ingress VID", "dsa.ingress_vid", |
| 465 | FT_UINT16, BASE_DEC, NULL((void*)0), DSA_TAG_VID_MASK0x0FFF, |
| 466 | "Ingress VLAN ID (0=standalone, 4095=bridged)", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 467 | }, |
| 468 | { &hf_dsa_unused_byte1_bit1, |
| 469 | { "Unused", "dsa.unused_byte1_bit1", |
| 470 | FT_UINT8, BASE_HEX, NULL((void*)0), DSA_TAG_B1_BIT10x02, |
| 471 | "byte1 bit 1 (FORWARD or TO_SNIFFER command)", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 472 | }, |
| 473 | { &hf_dsa_unused_byte1_bits_21, |
| 474 | { "Unused", "dsa.unused_byte1_bits_21", |
| 475 | FT_UINT8, BASE_HEX, NULL((void*)0), DSA_TAG_B1_BIT20x04 | DSA_TAG_B1_BIT10x02, |
| 476 | "byte1 bits 2:1 (FROM_CPU command)", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 477 | }, |
| 478 | { &hf_dsa_unused_byte2_bit4, |
| 479 | { "Unused", "dsa.unused_byte2_bit4", |
| 480 | FT_UINT8, BASE_HEX, NULL((void*)0), DSA_TAG_B2_BIT40x10, |
| 481 | "byte2 bit 4 (any command but TO_CPU)", HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 482 | }, |
| 483 | { &hf_dsa_trailer, |
| 484 | { "Trailer", "dsa.trailer", |
| 485 | FT_BYTES, BASE_NONE, NULL((void*)0), 0x0, |
| 486 | NULL((void*)0), HFILL-1, 0, HF_REF_TYPE_NONE, -1, ((void*)0) } |
| 487 | }, |
| 488 | }; |
| 489 | |
| 490 | static int *ett[] = { |
| 491 | &ett_frame, |
| 492 | &ett_tag_dsa, |
| 493 | &ett_tag_edsa, |
| 494 | }; |
| 495 | |
| 496 | static ei_register_info ei[] = { |
| 497 | { &ei_dsa_too_short, |
| 498 | { "dsa.too_short", PI_MALFORMED0x07000000, PI_WARN0x00600000, "DSA frame too short", EXPFILL0, ((void*)0), 0, ((void*)0), {0, {((void*)0), ((void*)0), FT_NONE , BASE_NONE, ((void*)0), 0, ((void*)0), -1, 0, HF_REF_TYPE_NONE , -1, ((void*)0)}} } |
| 499 | }, |
| 500 | { &ei_dsa_bad_reserved, |
| 501 | { "dsa.bad_reserved", PI_MALFORMED0x07000000, PI_WARN0x00600000, "Non-zero EDSA reserved field", EXPFILL0, ((void*)0), 0, ((void*)0), {0, {((void*)0), ((void*)0), FT_NONE , BASE_NONE, ((void*)0), 0, ((void*)0), -1, 0, HF_REF_TYPE_NONE , -1, ((void*)0)}} } |
| 502 | }, |
| 503 | { &ei_dsa_len, |
| 504 | { "dsa.len.past_end", PI_MALFORMED0x07000000, PI_ERROR0x00800000, |
| 505 | "Length field value goes past the end of the payload", EXPFILL0, ((void*)0), 0, ((void*)0), {0, {((void*)0), ((void*)0), FT_NONE , BASE_NONE, ((void*)0), 0, ((void*)0), -1, 0, HF_REF_TYPE_NONE , -1, ((void*)0)}} } |
| 506 | }, |
| 507 | }; |
| 508 | |
| 509 | proto_dsa = proto_register_protocol( |
| 510 | "Marvell DSA-tagged Ethernet", "DSA-tagged", "dsa"); |
| 511 | proto_edsa = proto_register_protocol( |
| 512 | "Marvell EDSA-tagged Ethernet", "EDSA-tagged", "edsa"); |
| 513 | proto_register_field_array(proto_dsa, hf, array_length(hf)(sizeof (hf) / sizeof (hf)[0])); |
| 514 | proto_register_subtree_array(ett, array_length(ett)(sizeof (ett) / sizeof (ett)[0])); |
| 515 | expert_dsa = expert_register_protocol(proto_dsa); |
| 516 | expert_register_field_array(expert_dsa, ei, array_length(ei)(sizeof (ei) / sizeof (ei)[0])); |
| 517 | } |
| 518 | |
| 519 | void |
| 520 | proto_reg_handoff_dsa(void) |
| 521 | { |
| 522 | dsa_handle = create_dissector_handle(dissect_dsa_frame, proto_dsa); |
| 523 | edsa_handle = create_dissector_handle(dissect_edsa_frame, proto_edsa); |
| 524 | |
| 525 | dissector_add_uint("wtap_encap", WTAP_ENCAP_DSA232, dsa_handle); |
| 526 | dissector_add_uint("wtap_encap", WTAP_ENCAP_EDSA233, edsa_handle); |
| 527 | |
| 528 | ethertype_handle = find_dissector_add_dependency("ethertype", proto_dsa); |
| 529 | } |
| 530 | |
| 531 | /* |
| 532 | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
| 533 | * |
| 534 | * Local variables: |
| 535 | * c-basic-offset: 4 |
| 536 | * tab-width: 8 |
| 537 | * indent-tabs-mode: nil |
| 538 | * End: |
| 539 | * |
| 540 | * vi: set shiftwidth=4 tabstop=8 expandtab: |
| 541 | * :indentSize=4:tabSize=8:noTabs=false: |
| 542 | */ |