Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-maap.c
blobf8e29a9eeb825113288e06489216a448a2fc43b5
1 /* packet-maap.c
2 * Routines for 802.3 MAC Address Allocation Protocol defined by IEEE1722
3 * Copyright 2012, Jason Damori, Biamp Systems <jdamori at biamp dot com>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include "config.h"
16 #include <epan/packet.h>
17 #include <epan/to_str.h>
19 void proto_register_maap(void);
20 void proto_reg_handoff_maap(void);
22 static dissector_handle_t maap_handle;
24 /* MAAP starts after common 1722 header */
25 #define MAAP_START_OFFSET 1
27 /* MAAP Field Offsets */
28 #define MAAP_MSG_TYPE_OFFSET 0+MAAP_START_OFFSET
29 #define MAAP_VERSION_OFFSET 1+MAAP_START_OFFSET
30 #define MAAP_STREAM_ID_OFFSET 3+MAAP_START_OFFSET
31 #define MAAP_REQ_START_ADDR_OFFSET 11+MAAP_START_OFFSET
32 #define MAAP_REQ_COUNT_OFFSET 17+MAAP_START_OFFSET
33 #define MAAP_CONFLICT_START_ADDR_OFFSET 19+MAAP_START_OFFSET
34 #define MAAP_CONFLICT_COUNT_OFFSET 25+MAAP_START_OFFSET
36 /* Bit Field Masks */
37 #define MAAP_MSG_TYPE_MASK 0x0f
38 #define MAAP_VERSION_MASK 0xf8
39 #define MAAP_DATA_LEN_MASK 0x07ff
41 /* MAAP message_type */
42 #define MAAP_MSG_TYPE_RESERVED_0 0x00
43 #define MAAP_MSG_TYPE_PROBE 0x01
44 #define MAAP_MSG_TYPE_DEFEND 0x02
45 #define MAAP_MSG_TYPE_ANNOUNCE 0x03
46 #define MAAP_MSG_TYPE_RESERVED_4 0x04
47 #define MAAP_MSG_TYPE_RESERVED_5 0x05
49 static const value_string maap_msg_type_vals [] = {
50 {MAAP_MSG_TYPE_PROBE, "MAAP_PROBE"},
51 {MAAP_MSG_TYPE_DEFEND, "MAAP_DEFEND"},
52 {MAAP_MSG_TYPE_ANNOUNCE, "MAAP_ANNOUNCE"},
53 {0, NULL}
56 /**********************************************************/
57 /* Initialize the protocol and registered fields */
58 /**********************************************************/
59 static int proto_maap;
61 /* MAAP PDU */
62 static int hf_maap_message_type;
63 static int hf_maap_version;
64 static int hf_maap_data_length;
65 static int hf_maap_stream_id;
66 static int hf_maap_req_start_addr;
67 static int hf_maap_req_count;
68 static int hf_maap_conflict_start_addr;
69 static int hf_maap_conflict_count;
71 /* Initialize the subtree pointers */
72 static int ett_maap;
74 static int
75 dissect_maap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
77 uint8_t maap_msg_type;
78 proto_item *maap_item = NULL;
79 proto_tree *maap_tree = NULL;
81 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MAAP");
82 col_clear(pinfo->cinfo, COL_INFO);
84 /* The maap msg type will be handy in a moment */
85 maap_msg_type = tvb_get_uint8(tvb, MAAP_MSG_TYPE_OFFSET);
86 maap_msg_type &= 0x0f;
88 /* Display the name of the packet type in the info column. */
89 col_add_fstr(pinfo->cinfo, COL_INFO, "%s:",
90 val_to_str(maap_msg_type, maap_msg_type_vals,
91 "Unknown Type(0x%02x)"));
93 /* Now, we'll add the start and conflict addresses and counts to the info column as appropriate */
94 switch (maap_msg_type)
96 case MAAP_MSG_TYPE_PROBE:
97 case MAAP_MSG_TYPE_ANNOUNCE:
98 col_append_fstr(pinfo->cinfo, COL_INFO, " req_start=%s, cnt=%d",
99 tvb_ether_to_str(pinfo->pool, tvb, MAAP_REQ_START_ADDR_OFFSET),
100 tvb_get_ntohs(tvb, MAAP_REQ_COUNT_OFFSET));
102 break;
103 case MAAP_MSG_TYPE_DEFEND:
104 col_append_fstr(pinfo->cinfo, COL_INFO, " conflict_start=%s, cnt=%d",
105 tvb_ether_to_str(pinfo->pool, tvb, MAAP_CONFLICT_START_ADDR_OFFSET),
106 tvb_get_ntohs(tvb, MAAP_CONFLICT_COUNT_OFFSET));
107 break;
108 default:
109 /* no info for reserved or unknown msg types */
110 break;
114 if (tree) {
115 maap_item = proto_tree_add_item(tree, proto_maap, tvb, MAAP_START_OFFSET, -1, ENC_NA);
116 maap_tree = proto_item_add_subtree(maap_item, ett_maap);
118 proto_tree_add_item(maap_tree, hf_maap_message_type, tvb, MAAP_MSG_TYPE_OFFSET, 1, ENC_BIG_ENDIAN);
119 proto_tree_add_item(maap_tree, hf_maap_version, tvb, MAAP_VERSION_OFFSET, 1, ENC_BIG_ENDIAN);
120 proto_tree_add_item(maap_tree, hf_maap_data_length, tvb, MAAP_VERSION_OFFSET, 2, ENC_BIG_ENDIAN);
121 proto_tree_add_item(maap_tree, hf_maap_stream_id, tvb, MAAP_STREAM_ID_OFFSET, 8, ENC_BIG_ENDIAN);
122 proto_tree_add_item(maap_tree, hf_maap_req_start_addr, tvb, MAAP_REQ_START_ADDR_OFFSET, 6, ENC_NA);
123 proto_tree_add_item(maap_tree, hf_maap_req_count, tvb, MAAP_REQ_COUNT_OFFSET, 2, ENC_BIG_ENDIAN);
124 proto_tree_add_item(maap_tree, hf_maap_conflict_start_addr, tvb, MAAP_CONFLICT_START_ADDR_OFFSET, 6, ENC_NA);
125 proto_tree_add_item(maap_tree, hf_maap_conflict_count, tvb, MAAP_CONFLICT_COUNT_OFFSET, 2, ENC_BIG_ENDIAN);
128 return tvb_captured_length(tvb);
129 } /* end dissect_maap() */
131 /* Register the protocol with Wireshark */
132 void
133 proto_register_maap(void)
135 static hf_register_info hf[] = {
136 { &hf_maap_message_type,
137 { "Message Type", "maap.message_type",
138 FT_UINT8, BASE_HEX,
139 VALS(maap_msg_type_vals), MAAP_MSG_TYPE_MASK,
140 NULL, HFILL }},
142 { &hf_maap_version,
143 { "MAAP Version", "maap.version",
144 FT_UINT8, BASE_HEX,
145 NULL, MAAP_VERSION_MASK,
146 NULL, HFILL }},
148 { &hf_maap_data_length,
149 { "Data Length", "maap.data_length",
150 FT_UINT16, BASE_HEX,
151 NULL, MAAP_DATA_LEN_MASK,
152 NULL, HFILL }},
154 { &hf_maap_stream_id,
155 { "Stream ID", "maap.stream_id",
156 FT_UINT64, BASE_HEX,
157 NULL, 0x00,
158 NULL, HFILL }},
160 { &hf_maap_req_start_addr,
161 { "Requested Start Address", "maap.req_start_addr",
162 FT_ETHER, BASE_NONE,
163 NULL, 0x00,
164 NULL, HFILL }},
166 { &hf_maap_req_count,
167 { "Request Count", "maap.req_count",
168 FT_UINT16, BASE_HEX,
169 NULL, 0x00,
170 NULL, HFILL }},
172 { &hf_maap_conflict_start_addr,
173 { "Conflict Start Address", "maap.conflict_start_addr",
174 FT_ETHER, BASE_NONE,
175 NULL, 0x00,
176 NULL, HFILL }},
178 { &hf_maap_conflict_count,
179 { "Conflict Count", "maap.conflict_count",
180 FT_UINT16, BASE_HEX,
181 NULL, 0x00,
182 NULL, HFILL }}
183 }; /* end of static hf_register_info hf[] = */
185 /* Setup protocol subtree array */
186 static int *ett[] = { &ett_maap };
188 /* Register the protocol name and description */
189 proto_maap = proto_register_protocol (
190 "IEEE 1722 MAAP Protocol", /* name */
191 "MAAP", /* short name */
192 "maap" /* abbrev */
195 /* Required function calls to register the header fields and subtrees used */
196 proto_register_field_array(proto_maap, hf, array_length(hf));
197 proto_register_subtree_array(ett, array_length(ett));
199 /* Register the dissector */
200 maap_handle = register_dissector("maap", dissect_maap, proto_maap);
202 } /* end proto_register_maap() */
204 void
205 proto_reg_handoff_maap(void)
207 dissector_add_uint("ieee1722.subtype", 0xFE, maap_handle);
211 * Editor modelines - https://www.wireshark.org/tools/modelines.html
213 * Local variables:
214 * c-basic-offset: 4
215 * tab-width: 8
216 * indent-tabs-mode: nil
217 * End:
219 * vi: set shiftwidth=4 tabstop=8 expandtab:
220 * :indentSize=4:tabSize=8:noTabs=true: