/src/wireshark/epan/dissectors/packet-maap.c
Line | Count | Source (jump to first uncovered line) |
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> |
4 | | * |
5 | | * Wireshark - Network traffic analyzer |
6 | | * By Gerald Combs <gerald@wireshark.org> |
7 | | * Copyright 1998 Gerald Combs |
8 | | * |
9 | | * SPDX-License-Identifier: GPL-2.0-or-later |
10 | | * |
11 | | */ |
12 | | |
13 | | |
14 | | #include "config.h" |
15 | | |
16 | | #include <epan/packet.h> |
17 | | #include <epan/to_str.h> |
18 | | |
19 | | void proto_register_maap(void); |
20 | | void proto_reg_handoff_maap(void); |
21 | | |
22 | | static dissector_handle_t maap_handle; |
23 | | |
24 | | /* MAAP starts after common 1722 header */ |
25 | 21 | #define MAAP_START_OFFSET 1 |
26 | | |
27 | | /* MAAP Field Offsets */ |
28 | 4 | #define MAAP_MSG_TYPE_OFFSET 0+MAAP_START_OFFSET |
29 | 4 | #define MAAP_VERSION_OFFSET 1+MAAP_START_OFFSET |
30 | 2 | #define MAAP_STREAM_ID_OFFSET 3+MAAP_START_OFFSET |
31 | 2 | #define MAAP_REQ_START_ADDR_OFFSET 11+MAAP_START_OFFSET |
32 | 3 | #define MAAP_REQ_COUNT_OFFSET 17+MAAP_START_OFFSET |
33 | 2 | #define MAAP_CONFLICT_START_ADDR_OFFSET 19+MAAP_START_OFFSET |
34 | 2 | #define MAAP_CONFLICT_COUNT_OFFSET 25+MAAP_START_OFFSET |
35 | | |
36 | | /* Bit Field Masks */ |
37 | 14 | #define MAAP_MSG_TYPE_MASK 0x0f |
38 | 14 | #define MAAP_VERSION_MASK 0xf8 |
39 | 14 | #define MAAP_DATA_LEN_MASK 0x07ff |
40 | | |
41 | | /* MAAP message_type */ |
42 | | #define MAAP_MSG_TYPE_RESERVED_0 0x00 |
43 | 0 | #define MAAP_MSG_TYPE_PROBE 0x01 |
44 | 0 | #define MAAP_MSG_TYPE_DEFEND 0x02 |
45 | 1 | #define MAAP_MSG_TYPE_ANNOUNCE 0x03 |
46 | | #define MAAP_MSG_TYPE_RESERVED_4 0x04 |
47 | | #define MAAP_MSG_TYPE_RESERVED_5 0x05 |
48 | | |
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} |
54 | | }; |
55 | | |
56 | | /**********************************************************/ |
57 | | /* Initialize the protocol and registered fields */ |
58 | | /**********************************************************/ |
59 | | static int proto_maap; |
60 | | |
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; |
70 | | |
71 | | /* Initialize the subtree pointers */ |
72 | | static int ett_maap; |
73 | | |
74 | | static int |
75 | | dissect_maap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) |
76 | 2 | { |
77 | 2 | uint8_t maap_msg_type; |
78 | 2 | proto_item *maap_item = NULL; |
79 | 2 | proto_tree *maap_tree = NULL; |
80 | | |
81 | 2 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "MAAP"); |
82 | 2 | col_clear(pinfo->cinfo, COL_INFO); |
83 | | |
84 | | /* The maap msg type will be handy in a moment */ |
85 | 2 | maap_msg_type = tvb_get_uint8(tvb, MAAP_MSG_TYPE_OFFSET); |
86 | 2 | maap_msg_type &= 0x0f; |
87 | | |
88 | | /* Display the name of the packet type in the info column. */ |
89 | 2 | col_add_fstr(pinfo->cinfo, COL_INFO, "%s:", |
90 | 2 | val_to_str(maap_msg_type, maap_msg_type_vals, |
91 | 2 | "Unknown Type(0x%02x)")); |
92 | | |
93 | | /* Now, we'll add the start and conflict addresses and counts to the info column as appropriate */ |
94 | 2 | switch (maap_msg_type) |
95 | 2 | { |
96 | 0 | case MAAP_MSG_TYPE_PROBE: |
97 | 1 | case MAAP_MSG_TYPE_ANNOUNCE: |
98 | 1 | col_append_fstr(pinfo->cinfo, COL_INFO, " req_start=%s, cnt=%d", |
99 | 1 | tvb_ether_to_str(pinfo->pool, tvb, MAAP_REQ_START_ADDR_OFFSET), |
100 | 1 | tvb_get_ntohs(tvb, MAAP_REQ_COUNT_OFFSET)); |
101 | | |
102 | 1 | break; |
103 | 0 | case MAAP_MSG_TYPE_DEFEND: |
104 | 0 | col_append_fstr(pinfo->cinfo, COL_INFO, " conflict_start=%s, cnt=%d", |
105 | 0 | tvb_ether_to_str(pinfo->pool, tvb, MAAP_CONFLICT_START_ADDR_OFFSET), |
106 | 0 | tvb_get_ntohs(tvb, MAAP_CONFLICT_COUNT_OFFSET)); |
107 | 0 | break; |
108 | 1 | default: |
109 | | /* no info for reserved or unknown msg types */ |
110 | 1 | break; |
111 | 2 | } |
112 | | |
113 | | |
114 | 2 | if (tree) { |
115 | 2 | maap_item = proto_tree_add_item(tree, proto_maap, tvb, MAAP_START_OFFSET, -1, ENC_NA); |
116 | 2 | maap_tree = proto_item_add_subtree(maap_item, ett_maap); |
117 | | |
118 | 2 | proto_tree_add_item(maap_tree, hf_maap_message_type, tvb, MAAP_MSG_TYPE_OFFSET, 1, ENC_BIG_ENDIAN); |
119 | 2 | proto_tree_add_item(maap_tree, hf_maap_version, tvb, MAAP_VERSION_OFFSET, 1, ENC_BIG_ENDIAN); |
120 | 2 | proto_tree_add_item(maap_tree, hf_maap_data_length, tvb, MAAP_VERSION_OFFSET, 2, ENC_BIG_ENDIAN); |
121 | 2 | proto_tree_add_item(maap_tree, hf_maap_stream_id, tvb, MAAP_STREAM_ID_OFFSET, 8, ENC_BIG_ENDIAN); |
122 | 2 | proto_tree_add_item(maap_tree, hf_maap_req_start_addr, tvb, MAAP_REQ_START_ADDR_OFFSET, 6, ENC_NA); |
123 | 2 | proto_tree_add_item(maap_tree, hf_maap_req_count, tvb, MAAP_REQ_COUNT_OFFSET, 2, ENC_BIG_ENDIAN); |
124 | 2 | proto_tree_add_item(maap_tree, hf_maap_conflict_start_addr, tvb, MAAP_CONFLICT_START_ADDR_OFFSET, 6, ENC_NA); |
125 | 2 | proto_tree_add_item(maap_tree, hf_maap_conflict_count, tvb, MAAP_CONFLICT_COUNT_OFFSET, 2, ENC_BIG_ENDIAN); |
126 | 2 | } |
127 | | |
128 | 2 | return tvb_captured_length(tvb); |
129 | 2 | } /* end dissect_maap() */ |
130 | | |
131 | | /* Register the protocol with Wireshark */ |
132 | | void |
133 | | proto_register_maap(void) |
134 | 14 | { |
135 | 14 | static hf_register_info hf[] = { |
136 | 14 | { &hf_maap_message_type, |
137 | 14 | { "Message Type", "maap.message_type", |
138 | 14 | FT_UINT8, BASE_HEX, |
139 | 14 | VALS(maap_msg_type_vals), MAAP_MSG_TYPE_MASK, |
140 | 14 | NULL, HFILL }}, |
141 | | |
142 | 14 | { &hf_maap_version, |
143 | 14 | { "MAAP Version", "maap.version", |
144 | 14 | FT_UINT8, BASE_HEX, |
145 | 14 | NULL, MAAP_VERSION_MASK, |
146 | 14 | NULL, HFILL }}, |
147 | | |
148 | 14 | { &hf_maap_data_length, |
149 | 14 | { "Data Length", "maap.data_length", |
150 | 14 | FT_UINT16, BASE_HEX, |
151 | 14 | NULL, MAAP_DATA_LEN_MASK, |
152 | 14 | NULL, HFILL }}, |
153 | | |
154 | 14 | { &hf_maap_stream_id, |
155 | 14 | { "Stream ID", "maap.stream_id", |
156 | 14 | FT_UINT64, BASE_HEX, |
157 | 14 | NULL, 0x00, |
158 | 14 | NULL, HFILL }}, |
159 | | |
160 | 14 | { &hf_maap_req_start_addr, |
161 | 14 | { "Requested Start Address", "maap.req_start_addr", |
162 | 14 | FT_ETHER, BASE_NONE, |
163 | 14 | NULL, 0x00, |
164 | 14 | NULL, HFILL }}, |
165 | | |
166 | 14 | { &hf_maap_req_count, |
167 | 14 | { "Request Count", "maap.req_count", |
168 | 14 | FT_UINT16, BASE_HEX, |
169 | 14 | NULL, 0x00, |
170 | 14 | NULL, HFILL }}, |
171 | | |
172 | 14 | { &hf_maap_conflict_start_addr, |
173 | 14 | { "Conflict Start Address", "maap.conflict_start_addr", |
174 | 14 | FT_ETHER, BASE_NONE, |
175 | 14 | NULL, 0x00, |
176 | 14 | NULL, HFILL }}, |
177 | | |
178 | 14 | { &hf_maap_conflict_count, |
179 | 14 | { "Conflict Count", "maap.conflict_count", |
180 | 14 | FT_UINT16, BASE_HEX, |
181 | 14 | NULL, 0x00, |
182 | 14 | NULL, HFILL }} |
183 | 14 | }; /* end of static hf_register_info hf[] = */ |
184 | | |
185 | | /* Setup protocol subtree array */ |
186 | 14 | static int *ett[] = { &ett_maap }; |
187 | | |
188 | | /* Register the protocol name and description */ |
189 | 14 | proto_maap = proto_register_protocol ( |
190 | 14 | "IEEE 1722 MAAP Protocol", /* name */ |
191 | 14 | "MAAP", /* short name */ |
192 | 14 | "maap" /* abbrev */ |
193 | 14 | ); |
194 | | |
195 | | /* Required function calls to register the header fields and subtrees used */ |
196 | 14 | proto_register_field_array(proto_maap, hf, array_length(hf)); |
197 | 14 | proto_register_subtree_array(ett, array_length(ett)); |
198 | | |
199 | | /* Register the dissector */ |
200 | 14 | maap_handle = register_dissector("maap", dissect_maap, proto_maap); |
201 | | |
202 | 14 | } /* end proto_register_maap() */ |
203 | | |
204 | | void |
205 | | proto_reg_handoff_maap(void) |
206 | 14 | { |
207 | 14 | dissector_add_uint("ieee1722.subtype", 0xFE, maap_handle); |
208 | 14 | } |
209 | | |
210 | | /* |
211 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
212 | | * |
213 | | * Local variables: |
214 | | * c-basic-offset: 4 |
215 | | * tab-width: 8 |
216 | | * indent-tabs-mode: nil |
217 | | * End: |
218 | | * |
219 | | * vi: set shiftwidth=4 tabstop=8 expandtab: |
220 | | * :indentSize=4:tabSize=8:noTabs=true: |
221 | | */ |