/src/wireshark/epan/dissectors/packet-cl3dcw.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* packet-cl3dcw.c |
2 | | * Routines for CableLabs Dual-Channel Wi-Fi Messaging Protocol Dissection |
3 | | * Copyright 2019 Jon Dennis <j.dennis[at]cablelabs.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 | | * CableLabs Specifications Can Be Found At: |
12 | | * https://www.cablelabs.com/specs |
13 | | */ |
14 | | |
15 | | |
16 | | #include "config.h" |
17 | | #include <epan/packet.h> |
18 | | #include <epan/expert.h> |
19 | | |
20 | | void proto_register_cl3dcw(void); |
21 | | void proto_reg_handoff_cl3dcw(void); |
22 | | |
23 | | static dissector_handle_t cl3dcw_handle; |
24 | 0 | #define SSID_MAX_LENGTH 32 |
25 | | |
26 | | /* persistent handles for this dissector */ |
27 | | static int proto_cl3dcw; |
28 | | static int ett_cl3dcw; |
29 | | static int hf_cl3dcw_type; |
30 | | static int hf_cl3dcw_dccount; |
31 | | static int hf_cl3dcw_datamacaddrcount; |
32 | | static int hf_cl3dcw_datassidcount; |
33 | | static int hf_cl3dcw_dcmacaddr; |
34 | | static int hf_cl3dcw_dcssid; |
35 | | static int hf_cl3dcw_dcbond; |
36 | | static int ett_cl3dcw_dcbond; |
37 | | static expert_field ei_cl3dcw_unknown_type; |
38 | | static expert_field ei_cl3dcw_nodc; |
39 | | static expert_field ei_cl3dcw_ssid_too_big; |
40 | | |
41 | | |
42 | | /* message id types */ |
43 | 0 | #define DCWMSG_STA_JOIN 0x01 |
44 | 0 | #define DCWMSG_STA_UNJOIN 0x02 |
45 | 0 | #define DCWMSG_STA_ACK 0x11 |
46 | 0 | #define DCWMSG_STA_NACK 0x12 |
47 | 0 | #define DCWMSG_AP_ACCEPT_STA 0x21 |
48 | 0 | #define DCWMSG_AP_REJECT_STA 0x22 |
49 | 0 | #define DCWMSG_AP_ACK_DISCONNECT 0x41 |
50 | 0 | #define DCWMSG_AP_QUIT 0x99 |
51 | | |
52 | | /* message type strings */ |
53 | | static const value_string cl3dcw_msg_types[] = { |
54 | | {DCWMSG_STA_JOIN, "Station Join" }, |
55 | | {DCWMSG_STA_UNJOIN, "Station Unjoin" }, |
56 | | {DCWMSG_STA_ACK, "Station Ack" }, |
57 | | {DCWMSG_STA_NACK, "Station Nack" }, |
58 | | {DCWMSG_AP_ACCEPT_STA, "AP Accept Station" }, |
59 | | {DCWMSG_AP_REJECT_STA, "AP Reject Station" }, |
60 | | {DCWMSG_AP_ACK_DISCONNECT, "AP Ack Disconnect" }, |
61 | | {DCWMSG_AP_QUIT, "AQ Quit" }, |
62 | | {0, NULL} |
63 | | }; |
64 | | |
65 | | |
66 | | static int |
67 | 0 | dissect_sta_join(tvbuff_t * const tvb, packet_info * const pinfo, proto_tree * const tree _U_, proto_item * const ti) { |
68 | 0 | uint32_t data_macaddr_count; |
69 | 0 | int offset; |
70 | |
|
71 | 0 | proto_tree_add_item_ret_uint(tree, hf_cl3dcw_datamacaddrcount, tvb, 0, 1, ENC_NA, &data_macaddr_count); |
72 | 0 | if (data_macaddr_count < 1) { |
73 | 0 | expert_add_info(pinfo, ti, &ei_cl3dcw_nodc); |
74 | 0 | } |
75 | |
|
76 | 0 | offset = 1; |
77 | 0 | while(data_macaddr_count--) { |
78 | 0 | proto_tree_add_item(tree, hf_cl3dcw_dcmacaddr, tvb, offset, 6, ENC_NA); |
79 | 0 | offset += 6; |
80 | 0 | } |
81 | |
|
82 | 0 | return offset; |
83 | 0 | } |
84 | | |
85 | | static int |
86 | 0 | dissect_sta_unjoin(tvbuff_t * const tvb, packet_info * const pinfo, proto_tree * const tree _U_, proto_item * const ti) { |
87 | 0 | uint32_t data_macaddr_count; |
88 | 0 | int offset; |
89 | |
|
90 | 0 | proto_tree_add_item_ret_uint(tree, hf_cl3dcw_datamacaddrcount, tvb, 0, 1, ENC_NA, &data_macaddr_count); |
91 | 0 | if (data_macaddr_count < 1) { |
92 | 0 | expert_add_info(pinfo, ti, &ei_cl3dcw_nodc); |
93 | 0 | } |
94 | |
|
95 | 0 | offset = 1; |
96 | 0 | while (data_macaddr_count--) { |
97 | 0 | proto_tree_add_item(tree, hf_cl3dcw_dcmacaddr, tvb, offset, 6, ENC_NA); |
98 | 0 | offset += 6; |
99 | 0 | } |
100 | |
|
101 | 0 | return offset; |
102 | 0 | } |
103 | | |
104 | | static int |
105 | 0 | dissect_sta_ack(tvbuff_t * const tvb, packet_info * const pinfo, proto_tree * const tree _U_, proto_item * const ti) { |
106 | |
|
107 | 0 | proto_item *bond_item; |
108 | 0 | proto_tree *bond_tree; |
109 | |
|
110 | 0 | uint32_t data_channel_count; |
111 | 0 | uint8_t ssid_len; |
112 | 0 | uint8_t *ssidbuf; |
113 | |
|
114 | 0 | int offset; |
115 | |
|
116 | 0 | proto_tree_add_item_ret_uint(tree, hf_cl3dcw_dccount, tvb, 0, 1, ENC_NA, &data_channel_count); |
117 | 0 | if (data_channel_count < 1) { |
118 | 0 | expert_add_info(pinfo, ti, &ei_cl3dcw_nodc); |
119 | 0 | } |
120 | |
|
121 | 0 | offset = 1; |
122 | 0 | while (data_channel_count--) { |
123 | | /* parse each data channel bond... |
124 | | * format is 6-byte mac addr + 1 byte ssid string length + ssid string |
125 | | */ |
126 | 0 | ssid_len = tvb_get_uint8(tvb, offset + 6); /* +6 = skip over mac address */ |
127 | 0 | if (ssid_len > SSID_MAX_LENGTH) { |
128 | 0 | expert_add_info(pinfo, ti, &ei_cl3dcw_ssid_too_big); |
129 | 0 | } |
130 | 0 | ssidbuf = tvb_get_string_enc(pinfo->pool, tvb, offset + 6 + 1, ssid_len, ENC_ASCII); /* +6+1 = skip over mac address and length field */ |
131 | | |
132 | | /* add the data channel bond sub-tree item */ |
133 | 0 | bond_item = proto_tree_add_item(tree, hf_cl3dcw_dcbond, tvb, offset, 6, ENC_NA); |
134 | 0 | proto_item_append_text(bond_item, " -> \"%s\"", ssidbuf); |
135 | 0 | proto_item_set_len(bond_item, 6 + 1 + ssid_len); |
136 | 0 | bond_tree = proto_item_add_subtree(bond_item, ett_cl3dcw_dcbond); |
137 | | |
138 | | /* add the MAC address... */ |
139 | 0 | proto_tree_add_item(bond_tree, hf_cl3dcw_dcmacaddr, tvb, offset, 6, ENC_NA); |
140 | 0 | offset += 6; |
141 | | |
142 | | /* add the SSID string |
143 | | * XXX the intent here is to highlight the leading length byte in the hex dump |
144 | | * without printing it in the string... i suspect there is a better way of doing this |
145 | | */ |
146 | 0 | proto_tree_add_string_format(bond_tree, hf_cl3dcw_dcssid, tvb, offset, 1 + ssid_len, |
147 | 0 | "", "Data Channel SSID: %s", ssidbuf); |
148 | 0 | offset += 1 + ssid_len; |
149 | 0 | } |
150 | |
|
151 | 0 | return offset; |
152 | 0 | } |
153 | | |
154 | | static int |
155 | 0 | dissect_sta_nack(tvbuff_t * const tvb, packet_info * const pinfo, proto_tree * const tree _U_, proto_item * const ti) { |
156 | 0 | uint32_t data_macaddr_count; |
157 | 0 | int offset; |
158 | |
|
159 | 0 | proto_tree_add_item_ret_uint(tree, hf_cl3dcw_datamacaddrcount, tvb, 0, 1, ENC_NA, &data_macaddr_count); |
160 | 0 | if (data_macaddr_count < 1) { |
161 | 0 | expert_add_info(pinfo, ti, &ei_cl3dcw_nodc); |
162 | 0 | } |
163 | |
|
164 | 0 | offset = 1; |
165 | 0 | while (data_macaddr_count--) { |
166 | 0 | proto_tree_add_item(tree, hf_cl3dcw_dcmacaddr, tvb, offset, 6, ENC_NA); |
167 | 0 | offset += 6; |
168 | 0 | } |
169 | |
|
170 | 0 | return offset; |
171 | 0 | } |
172 | | |
173 | | static int |
174 | 0 | dissect_ap_accept_sta(tvbuff_t * const tvb, packet_info * const pinfo, proto_tree * const tree _U_, proto_item * const ti) { |
175 | |
|
176 | 0 | uint32_t data_ssid_count; |
177 | 0 | uint8_t ssid_len; |
178 | 0 | uint8_t *ssidbuf; |
179 | |
|
180 | 0 | int offset; |
181 | |
|
182 | 0 | proto_tree_add_item_ret_uint(tree, hf_cl3dcw_datassidcount, tvb, 0, 1, ENC_NA, &data_ssid_count); |
183 | 0 | if (data_ssid_count < 1) { |
184 | 0 | expert_add_info(pinfo, ti, &ei_cl3dcw_nodc); |
185 | 0 | } |
186 | |
|
187 | 0 | offset = 1; |
188 | 0 | while (data_ssid_count--) { |
189 | 0 | ssid_len = tvb_get_uint8(tvb, offset); |
190 | 0 | if (ssid_len > SSID_MAX_LENGTH) { |
191 | 0 | expert_add_info(pinfo, ti, &ei_cl3dcw_ssid_too_big); |
192 | 0 | } |
193 | 0 | ssidbuf = tvb_get_string_enc(pinfo->pool, tvb, offset + 1, ssid_len, ENC_ASCII); /* +1 = skip over length field */ |
194 | | |
195 | | /* add the SSID string |
196 | | * XXX the intent here is to highlight the leading length byte in the hex dump |
197 | | * without printing it in the string... i suspect there is a better way of doing this |
198 | | */ |
199 | 0 | proto_tree_add_string_format(tree, hf_cl3dcw_dcssid, tvb, offset, 1 + ssid_len, |
200 | 0 | "", "Data Channel SSID: %s", ssidbuf); |
201 | 0 | offset += 1 + ssid_len; |
202 | 0 | } |
203 | |
|
204 | 0 | return offset; |
205 | 0 | } |
206 | | |
207 | | static int |
208 | 0 | dissect_ap_reject_sta(tvbuff_t * const tvb, packet_info * const pinfo, proto_tree * const tree _U_, proto_item * const ti) { |
209 | 0 | uint32_t data_macaddr_count; |
210 | 0 | int offset; |
211 | |
|
212 | 0 | proto_tree_add_item_ret_uint(tree, hf_cl3dcw_datamacaddrcount, tvb, 0, 1, ENC_NA, &data_macaddr_count); |
213 | 0 | if (data_macaddr_count < 1) { |
214 | 0 | expert_add_info(pinfo, ti, &ei_cl3dcw_nodc); |
215 | 0 | } |
216 | |
|
217 | 0 | offset = 1; |
218 | 0 | while (data_macaddr_count--) { |
219 | 0 | proto_tree_add_item(tree, hf_cl3dcw_dcmacaddr, tvb, offset, 6, ENC_NA); |
220 | 0 | offset += 6; |
221 | 0 | } |
222 | |
|
223 | 0 | return offset; |
224 | 0 | } |
225 | | |
226 | | /* called for each incomming framing matching our CL3 (sub-)protocol id: */ |
227 | | static int |
228 | 0 | dissect_cl3dcw(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree _U_, void *data _U_) { |
229 | |
|
230 | 0 | proto_item *ti; |
231 | 0 | proto_tree *cl3dcw_tree; |
232 | 0 | tvbuff_t *tvb_msg; |
233 | 0 | int total_dcw_message_len; |
234 | |
|
235 | 0 | uint8_t type; |
236 | | |
237 | | /* parse the header fields */ |
238 | 0 | total_dcw_message_len = 1; |
239 | 0 | type = tvb_get_uint8(tvb, 0); |
240 | | |
241 | | /* setup the "packet summary view" fields */ |
242 | 0 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "CL3-DCW"); |
243 | 0 | col_clear(pinfo->cinfo, COL_INFO); |
244 | 0 | col_add_fstr(pinfo->cinfo, COL_INFO, "Dual-Channel Wi-Fi %s [Type 0x%02X]", val_to_str_const(type, cl3dcw_msg_types, "Unknown"), (unsigned)type); |
245 | | |
246 | | /* create a tree node for us... */ |
247 | 0 | ti = proto_tree_add_protocol_format(tree, proto_cl3dcw, tvb, 0, tvb_captured_length(tvb), "Dual-Channel Wi-Fi Control Message"); |
248 | 0 | cl3dcw_tree = proto_item_add_subtree(ti, ett_cl3dcw); |
249 | 0 | tvb_msg = tvb_new_subset_remaining(tvb, 1); |
250 | | |
251 | | /* display dcw fields: */ |
252 | 0 | proto_tree_add_uint(cl3dcw_tree, hf_cl3dcw_type, tvb, 0, 1, type); |
253 | | |
254 | | /* parse the message by type... */ |
255 | 0 | switch (type) { |
256 | 0 | case DCWMSG_STA_JOIN: total_dcw_message_len += dissect_sta_join(tvb_msg, pinfo, cl3dcw_tree, ti); break; |
257 | 0 | case DCWMSG_STA_UNJOIN: total_dcw_message_len += dissect_sta_unjoin(tvb_msg, pinfo, cl3dcw_tree, ti); break; |
258 | 0 | case DCWMSG_STA_ACK: total_dcw_message_len += dissect_sta_ack(tvb_msg, pinfo, cl3dcw_tree, ti); break; |
259 | 0 | case DCWMSG_STA_NACK: total_dcw_message_len += dissect_sta_nack(tvb_msg, pinfo, cl3dcw_tree, ti); break; |
260 | 0 | case DCWMSG_AP_ACCEPT_STA: total_dcw_message_len += dissect_ap_accept_sta(tvb_msg, pinfo, cl3dcw_tree, ti); break; |
261 | 0 | case DCWMSG_AP_REJECT_STA: total_dcw_message_len += dissect_ap_reject_sta(tvb_msg, pinfo, cl3dcw_tree, ti); break; |
262 | 0 | case DCWMSG_AP_ACK_DISCONNECT: /* nothing to really dissect */ break; |
263 | 0 | case DCWMSG_AP_QUIT: /* nothing to really dissect */ break; |
264 | 0 | default: |
265 | 0 | expert_add_info(pinfo, ti, &ei_cl3dcw_unknown_type); |
266 | 0 | return tvb_captured_length(tvb); |
267 | 0 | } |
268 | | |
269 | | /* now that the individual message dissection functions have ran, |
270 | | update the tree item length so that the hex dissection dieplay |
271 | | highlighting does not include any ethernet frame padding */ |
272 | 0 | proto_item_set_len(ti, total_dcw_message_len); |
273 | 0 | return total_dcw_message_len; /* is this correct ? */ |
274 | 0 | } |
275 | | |
276 | | /* initializes this dissector */ |
277 | | void |
278 | 14 | proto_register_cl3dcw(void) { |
279 | 14 | static hf_register_info hf[] = { |
280 | 14 | { &hf_cl3dcw_type, |
281 | 14 | { "Type", "cl3dcw.type", |
282 | 14 | FT_UINT8, BASE_HEX, VALS(cl3dcw_msg_types), 0x0, |
283 | 14 | NULL, HFILL }}, |
284 | 14 | { &hf_cl3dcw_dccount, |
285 | 14 | { "Data Channel Count", "cl3dcw.dccount", |
286 | 14 | FT_UINT8, BASE_DEC, NULL, 0x0, |
287 | 14 | NULL, HFILL }}, |
288 | 14 | { &hf_cl3dcw_datamacaddrcount, |
289 | 14 | { "Data MAC Address Count", "cl3dcw.datamacaddrcount", |
290 | 14 | FT_UINT8, BASE_DEC, NULL, 0x0, |
291 | 14 | NULL, HFILL }}, |
292 | 14 | { &hf_cl3dcw_datassidcount, |
293 | 14 | { "Data SSID Count", "cl3dcw.datassidcount", |
294 | 14 | FT_UINT8, BASE_DEC, NULL, 0x0, |
295 | 14 | NULL, HFILL }}, |
296 | 14 | { &hf_cl3dcw_dcmacaddr, |
297 | 14 | { "Data Channel MAC Address", "cl3dcw.dcmacaddr", |
298 | 14 | FT_ETHER, BASE_NONE, NULL, 0x0, |
299 | 14 | NULL, HFILL }}, |
300 | 14 | { &hf_cl3dcw_dcssid, |
301 | 14 | { "Data Channel SSID", "cl3dcw.dcssid", |
302 | 14 | FT_STRING, BASE_NONE, NULL, 0x0, |
303 | 14 | NULL, HFILL }}, |
304 | 14 | { &hf_cl3dcw_dcbond, |
305 | 14 | { "Data Channel Bond", "cl3dcw.dcbond", |
306 | 14 | FT_BYTES, SEP_COLON, NULL, 0x0, |
307 | 14 | NULL, HFILL }}, |
308 | 14 | }; |
309 | 14 | static int *ett[] = { |
310 | 14 | &ett_cl3dcw, |
311 | 14 | &ett_cl3dcw_dcbond, |
312 | 14 | }; |
313 | 14 | static ei_register_info ei[] = { |
314 | 14 | { &ei_cl3dcw_unknown_type, { "cl3dcw.unknown_type", PI_MALFORMED, PI_ERROR, "Unknown DCW message type", EXPFILL }}, |
315 | 14 | { &ei_cl3dcw_nodc, { "cl3dcw.no_data_channels", PI_MALFORMED, PI_WARN, "No data-channels provided", EXPFILL }}, |
316 | 14 | { &ei_cl3dcw_ssid_too_big, { "cl3dcw.ssid_too_big", PI_MALFORMED, PI_WARN, "Data channel SSID too big (expecting 32-byte maximum SSID)", EXPFILL }}, |
317 | 14 | }; |
318 | | |
319 | 14 | expert_module_t* expert_cl3dcw; |
320 | | |
321 | 14 | proto_cl3dcw = proto_register_protocol("CableLabs Dual-Channel Wi-Fi", "cl3dcw", "cl3dcw"); |
322 | | |
323 | 14 | proto_register_field_array(proto_cl3dcw, hf, array_length(hf)); |
324 | 14 | proto_register_subtree_array(ett, array_length(ett)); |
325 | 14 | expert_cl3dcw = expert_register_protocol(proto_cl3dcw); |
326 | 14 | expert_register_field_array(expert_cl3dcw, ei, array_length(ei)); |
327 | | |
328 | 14 | cl3dcw_handle = register_dissector("cl3dcw", &dissect_cl3dcw, proto_cl3dcw); |
329 | 14 | } |
330 | | |
331 | | /* hooks in our dissector to be called on matching CL3 (sub-)protocol id */ |
332 | | void |
333 | 14 | proto_reg_handoff_cl3dcw(void) { |
334 | 14 | dissector_add_uint("cl3.subprotocol", 0x00DC, cl3dcw_handle); |
335 | 14 | } |
336 | | |
337 | | /* |
338 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
339 | | * |
340 | | * Local variables: |
341 | | * c-basic-offset: 2 |
342 | | * tab-width: 8 |
343 | | * indent-tabs-mode: nil |
344 | | * End: |
345 | | * |
346 | | * vi: set shiftwidth=2 tabstop=8 expandtab: |
347 | | * :indentSize=2:tabSize=8:noTabs=true: |
348 | | */ |