epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / dissectors / packet-btmcap.c
blob4d16821f4062789a4dcd6dccdb45f17f9f3c7ffa
1 /* packet-btmcap.c
2 * Routines for Bluetooth MCAP dissection
3 * https://www.bluetooth.org/Technical/Specifications/adopted.htm
5 * Copyright 2013, Michal Labedzki for Tieto Corporation
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include "config.h"
16 #include <epan/packet.h>
17 #include <epan/prefs.h>
18 #include <epan/expert.h>
19 #include <epan/unit_strings.h>
21 static int proto_btmcap;
23 static int hf_btmcap_op_code;
24 static int hf_btmcap_response_code;
25 static int hf_btmcap_mdl_id;
26 static int hf_btmcap_mdep_id;
27 static int hf_btmcap_response_parameters;
28 static int hf_btmcap_configuration;
29 static int hf_btmcap_timestamp_required_accuracy;
30 static int hf_btmcap_timestamp_update_information;
31 static int hf_btmcap_bluetooth_clock_sync_time;
32 static int hf_btmcap_timestamp_sync_time;
33 static int hf_btmcap_timestamp_sample_accuracy;
34 static int hf_btmcap_bluetooth_clock_access_resolution;
35 static int hf_btmcap_sync_lead_time;
36 static int hf_btmcap_timestamp_native_resolution;
37 static int hf_btmcap_timestamp_native_accuracy;
38 static int hf_btmcap_data;
40 static int ett_btmcap;
42 static expert_field ei_btmcap_mdl_id_ffff;
43 static expert_field ei_btmcap_response_parameters_bad;
44 static expert_field ei_btmcap_unexpected_data;
46 static dissector_handle_t btmcap_handle;
48 static const value_string op_code_vals[] = {
49 { 0x00, "ERROR_RSP" },
50 { 0x01, "MD_CREATE_MDL_REQ" },
51 { 0x02, "MD_CREATE_MDL_RSP" },
52 { 0x03, "MD_RECONNECT_MDL_REQ" },
53 { 0x04, "MD_RECONNECT_MDL_RSP" },
54 { 0x05, "MD_ABORT_MDL_REQ" },
55 { 0x06, "MD_ABORT_MDL_RSP" },
56 { 0x07, "MD_DELETE_MDL_REQ" },
57 { 0x08, "MD_DELETE_MDL_RSP" },
58 { 0x11, "MD_SYNC_CAP_REQ" },
59 { 0x12, "MD_SYNC_CAP_RSP" },
60 { 0x13, "MD_SYNC_SET_REQ" },
61 { 0x14, "MD_SYNC_SET_RSP" },
62 { 0x15, "MD_SYNC_INFO_IND" },
63 { 0x16, "Reserved as pseudoresponse" },
64 { 0, NULL }
67 static const value_string response_code_vals[] = {
68 { 0x00, "Success" },
69 { 0x01, "Invalid Op Code" },
70 { 0x02, "Invalid Parameter Value" },
71 { 0x03, "Invalid MDEP" },
72 { 0x04, "MDEP Busy" },
73 { 0x05, "Invalid MDL" },
74 { 0x06, "MDL Busy" },
75 { 0x07, "Invalid Operation" },
76 { 0x08, "Resource Unavailable" },
77 { 0x09, "Unspecified Error" },
78 { 0x0A, "Request Not Supported" },
79 { 0x0B, "Configuration Rejected" },
80 { 0, NULL }
83 static const unit_name_string units_ppm = { " ppm", NULL };
85 void proto_register_btmcap(void);
86 void proto_reg_handoff_btmcap(void);
88 static int
89 dissect_btmcap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
91 proto_item *main_item;
92 proto_tree *main_tree;
93 proto_item *pitem;
94 int offset = 0;
95 uint32_t op_code;
96 uint32_t response_code;
97 uint32_t mdl_id;
98 uint32_t mdep_id;
99 uint32_t bluetooth_clock_sync_time;
100 uint64_t timestamp_sync_time;
102 main_item = proto_tree_add_item(tree, proto_btmcap, tvb, offset, tvb_captured_length(tvb), ENC_NA);
103 main_tree = proto_item_add_subtree(main_item, ett_btmcap);
105 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MCAP");
107 switch (pinfo->p2p_dir) {
108 case P2P_DIR_SENT:
109 col_set_str(pinfo->cinfo, COL_INFO, "Sent ");
110 break;
111 case P2P_DIR_RECV:
112 col_set_str(pinfo->cinfo, COL_INFO, "Rcvd ");
113 break;
114 default:
115 col_set_str(pinfo->cinfo, COL_INFO, "UnknownDirection ");
116 break;
119 pitem = proto_tree_add_item(main_tree, hf_btmcap_op_code, tvb, offset, 1, ENC_BIG_ENDIAN);
120 op_code = tvb_get_uint8(tvb, offset);
121 offset += 1;
123 col_append_str(pinfo->cinfo, COL_INFO, val_to_str_const(op_code, op_code_vals, "Unknown Op Code"));
124 if (op_code >= 0x11 && op_code <= 0x20) {
125 proto_item_append_text(pitem, " (Clock Sync)");
126 col_append_str(pinfo->cinfo, COL_INFO, " (Clock Sync)");
127 } else {
128 proto_item_append_text(pitem, " (Standard)");
129 col_append_str(pinfo->cinfo, COL_INFO, " (Standard)");
132 if (op_code & 0x01) {
133 /* isRequest */
134 switch(op_code) {
135 case 0x01: /* MD_CREATE_MDL_REQ */
136 case 0x03: /* MD_RECONNECT_MDL_REQ */
137 case 0x05: /* MD_ABORT_MDL_REQ */
138 case 0x07: /* MD_DELETE_MDL_REQ */
139 pitem = proto_tree_add_item(main_tree, hf_btmcap_mdl_id, tvb, offset, 2, ENC_BIG_ENDIAN);
140 mdl_id = tvb_get_ntohs(tvb, offset);
141 offset += 2;
143 col_append_fstr(pinfo->cinfo, COL_INFO, " - MDL ID: %u", mdl_id);
144 if (mdl_id == 0xFFFF) {
145 proto_item_append_text(pitem, " (Indicates all MDLs)");
146 col_append_str(pinfo->cinfo, COL_INFO, " (Indicates all MDLs)");
147 } else if (mdl_id >= 0x0001 && mdl_id <= 0xFEFF) {
148 proto_item_append_text(pitem, " (Dynamic Range)");
149 col_append_str(pinfo->cinfo, COL_INFO, " (Dynamic Range)");
150 } else if (mdl_id == 0x0000) {
151 proto_item_append_text(pitem, " (Reserved)");
152 col_append_str(pinfo->cinfo, COL_INFO, " (Reserved)");
155 if (op_code != 0x07 && mdl_id == 0xFFFF) {
156 expert_add_info(pinfo, pitem, &ei_btmcap_mdl_id_ffff);
159 if (op_code == 0x01) {
160 /* only MD_CREATE_MDL_REQ */
161 pitem = proto_tree_add_item(main_tree, hf_btmcap_mdep_id, tvb, offset, 1, ENC_BIG_ENDIAN);
162 mdep_id = tvb_get_uint8(tvb, offset);
163 offset += 1;
165 if (mdep_id <= 0x7F) {
166 proto_item_append_text(pitem, " (Available for use)");
167 } else {
168 proto_item_append_text(pitem, " (Reserved)");
171 proto_tree_add_item(main_tree, hf_btmcap_configuration, tvb, offset, 1, ENC_BIG_ENDIAN);
172 offset += 1;
174 break;
175 case 0x11: /* MD_SYNC_CAP_REQ */
176 proto_tree_add_item(main_tree, hf_btmcap_timestamp_required_accuracy, tvb, offset, 2, ENC_BIG_ENDIAN);
177 offset += 2;
178 break;
179 case 0x13: /* MD_SYNC_SET_REQ */
180 proto_tree_add_item(main_tree, hf_btmcap_timestamp_update_information, tvb, offset, 1, ENC_BIG_ENDIAN);
181 offset += 1;
183 pitem = proto_tree_add_item(main_tree, hf_btmcap_bluetooth_clock_sync_time, tvb, offset, 4, ENC_BIG_ENDIAN);
184 bluetooth_clock_sync_time = tvb_get_ntohl(tvb, offset);
185 if (bluetooth_clock_sync_time == 0xFFFFFFFF)
186 proto_item_append_text(pitem, " (Instant Synchronization)");
187 else
188 proto_item_append_text(pitem, " (Baseband Half-Slot Instant)");
189 offset += 4;
191 pitem = proto_tree_add_item(main_tree, hf_btmcap_timestamp_sync_time, tvb, offset, 8, ENC_BIG_ENDIAN);
192 timestamp_sync_time = tvb_get_ntoh64(tvb, offset);
193 if (timestamp_sync_time == UINT64_C(0xFFFFFFFFFFFFFFFF))
194 proto_item_append_text(pitem, " (No Time Synchronization)");
195 else
196 proto_item_append_text(pitem, " (Time-Stamp Clock Instant)");
197 offset += 8;
198 break;
199 case 0x15: /* MD_SYNC_INFO_IND */
200 pitem = proto_tree_add_item(main_tree, hf_btmcap_bluetooth_clock_sync_time, tvb, offset, 4, ENC_BIG_ENDIAN);
201 proto_item_append_text(pitem, " (Baseband Half-Slot Instant)");
202 offset += 4;
204 pitem = proto_tree_add_item(main_tree, hf_btmcap_timestamp_sync_time, tvb, offset, 8, ENC_BIG_ENDIAN);
205 proto_item_append_text(pitem, " (Time-Stamp Clock Instant)");
206 offset += 8;
208 proto_tree_add_item(main_tree, hf_btmcap_timestamp_sample_accuracy, tvb, offset, 2, ENC_BIG_ENDIAN);
209 offset += 2;
210 break;
212 } else {
213 /* isResponse */
215 proto_tree_add_item(main_tree, hf_btmcap_response_code, tvb, offset, 1, ENC_BIG_ENDIAN);
216 response_code = tvb_get_uint8(tvb, offset);
217 offset += 1;
219 col_append_fstr(pinfo->cinfo, COL_INFO, " - %s", val_to_str_const(response_code, response_code_vals, "Unknown ResponseCode"));
221 if (op_code >= 0x11 && op_code <= 0x20) {
222 /* Clock Sync */
223 switch(op_code) {
224 case 0x12: /* MD_SYNC_CAP_RSP */
225 pitem = proto_tree_add_item(main_tree, hf_btmcap_bluetooth_clock_access_resolution, tvb, offset, 1, ENC_BIG_ENDIAN);
226 proto_item_append_text(pitem, " (Baseband half-slots)");
227 offset += 1;
229 proto_tree_add_item(main_tree, hf_btmcap_sync_lead_time, tvb, offset, 2, ENC_BIG_ENDIAN);
230 offset += 2;
232 proto_tree_add_item(main_tree, hf_btmcap_timestamp_native_resolution, tvb, offset, 2, ENC_BIG_ENDIAN);
233 offset += 2;
235 proto_tree_add_item(main_tree, hf_btmcap_timestamp_native_accuracy, tvb, offset, 2, ENC_BIG_ENDIAN);
236 offset += 2;
237 break;
238 case 0x14: /* MD_SYNC_SET_RSP */
239 pitem = proto_tree_add_item(main_tree, hf_btmcap_bluetooth_clock_sync_time, tvb, offset, 4, ENC_BIG_ENDIAN);
240 bluetooth_clock_sync_time = tvb_get_ntohl(tvb, offset);
241 if (bluetooth_clock_sync_time == 0xFFFFFFFF)
242 proto_item_append_text(pitem, " (Instant Synchronization)");
243 else
244 proto_item_append_text(pitem, " (Baseband Half-Slot Instant)");
245 offset += 4;
247 pitem = proto_tree_add_item(main_tree, hf_btmcap_timestamp_sync_time, tvb, offset, 8, ENC_BIG_ENDIAN);
248 timestamp_sync_time = tvb_get_ntoh64(tvb, offset);
249 if (timestamp_sync_time == UINT64_C(0xFFFFFFFFFFFFFFFF))
250 proto_item_append_text(pitem, " (No Time Synchronization)");
251 else
252 proto_item_append_text(pitem, " (Time-Stamp Clock Instant)");
253 offset += 8;
255 proto_tree_add_item(main_tree, hf_btmcap_timestamp_sample_accuracy, tvb, offset, 2, ENC_BIG_ENDIAN);
256 offset += 2;
257 break;
259 } else {
260 /* Standard Op Code */
261 pitem = proto_tree_add_item(main_tree, hf_btmcap_mdl_id, tvb, offset, 2, ENC_BIG_ENDIAN);
262 mdl_id = tvb_get_ntohs(tvb, offset);
263 offset += 2;
265 col_append_fstr(pinfo->cinfo, COL_INFO, " - %u", mdl_id);
266 if (mdl_id == 0xFFFF) {
267 proto_item_append_text(pitem, " (Indicates all MDLs)");
268 col_append_str(pinfo->cinfo, COL_INFO, " (Indicates all MDLs)");
269 } else if (mdl_id >= 0x0001 && mdl_id <= 0xFEFF) {
270 proto_item_append_text(pitem, " (Dynamic Range)");
271 col_append_str(pinfo->cinfo, COL_INFO, " (Dynamic Range)");
272 } else if (mdl_id == 0x0000) {
273 proto_item_append_text(pitem, " (Reserved)");
274 col_append_str(pinfo->cinfo, COL_INFO, " (Reserved)");
277 if ((op_code == 0x03 || op_code == 0x05 || op_code == 0x07) && tvb_reported_length_remaining(tvb, offset)) {
278 expert_add_info_format(pinfo, pitem, &ei_btmcap_response_parameters_bad,
279 "The Response Parameters for MD_RECONNECT_MDL_RSP shall have length zero.");
280 } else if (tvb_reported_length_remaining(tvb, offset)) {
281 pitem = proto_tree_add_item(main_tree, hf_btmcap_response_parameters, tvb, offset, tvb_reported_length_remaining(tvb, offset), ENC_NA);
282 if (response_code != 0x00) {
283 expert_add_info_format(pinfo, pitem, &ei_btmcap_response_parameters_bad,
284 "When the Response Code is not Success, the Response Parameters shall have length zero.");
286 offset += tvb_reported_length_remaining(tvb, offset);
291 if (tvb_reported_length_remaining(tvb, offset)) {
292 pitem = proto_tree_add_item(main_tree, hf_btmcap_data, tvb, offset, tvb_reported_length_remaining(tvb, offset), ENC_NA);
293 expert_add_info(pinfo, pitem, &ei_btmcap_unexpected_data);
294 offset = tvb_reported_length(tvb);
297 return offset;
301 void
302 proto_register_btmcap(void)
304 module_t *module;
305 expert_module_t *expert_btmcap;
307 static hf_register_info hf[] = {
308 { &hf_btmcap_op_code,
309 { "Op Code", "btmcap.op_code",
310 FT_UINT8, BASE_HEX, VALS(op_code_vals), 0x0,
311 NULL, HFILL }
313 { &hf_btmcap_response_code,
314 { "Response Code", "btmcap.response_code",
315 FT_UINT8, BASE_HEX, VALS(response_code_vals), 0x0,
316 NULL, HFILL }
318 { &hf_btmcap_mdl_id,
319 { "MDL ID", "btmcap.mdl_id",
320 FT_UINT16, BASE_HEX, NULL, 0x0,
321 NULL, HFILL }
323 { &hf_btmcap_mdep_id,
324 { "MDEP ID", "btmcap.mdep_id",
325 FT_UINT8, BASE_HEX, NULL, 0x0,
326 NULL, HFILL }
328 { &hf_btmcap_configuration,
329 { "Configuration", "btmcap.configuration",
330 FT_UINT8, BASE_HEX, NULL, 0x0,
331 NULL, HFILL }
333 { &hf_btmcap_timestamp_required_accuracy,
334 { "Timestamp Required Accuracy", "btmcap.timestamp_required_accuracy",
335 FT_UINT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_ppm), 0x00,
336 NULL, HFILL }
338 { &hf_btmcap_timestamp_update_information,
339 { "Timestamp Update Information", "btmcap.timestamp_update_information",
340 FT_UINT8, BASE_DEC, NULL, 0x00,
341 NULL, HFILL }
343 { &hf_btmcap_bluetooth_clock_sync_time,
344 { "Bluetooth Clock Sync Time", "btmcap.bluetooth_clock_sync_time",
345 FT_UINT32, BASE_DEC, NULL, 0x00,
346 NULL, HFILL }
348 { &hf_btmcap_timestamp_sync_time,
349 { "Timestamp Sync Time", "btmcap.timestamp_sync_time",
350 FT_UINT64, BASE_DEC, NULL, 0x00,
351 NULL, HFILL }
353 { &hf_btmcap_timestamp_sample_accuracy,
354 { "Timestamp Sample Accuracy", "btmcap.timestamp_sample_accuracy",
355 FT_UINT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_microseconds), 0x00,
356 NULL, HFILL }
358 { &hf_btmcap_bluetooth_clock_access_resolution,
359 { "Bluetooth Clock Access Resolution","btmcap.bluetooth_clock_access_resolution",
360 FT_UINT8, BASE_DEC, NULL, 0x00,
361 NULL, HFILL }
363 { &hf_btmcap_sync_lead_time,
364 { "Sync Lead Time", "btmcap.sync_lead_time",
365 FT_UINT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_milliseconds), 0x00,
366 NULL, HFILL }
368 { &hf_btmcap_timestamp_native_resolution,
369 { "Timestamp Native Resolution", "btmcap.timestamp_native_resolution",
370 FT_UINT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_microseconds), 0x00,
371 NULL, HFILL }
373 { &hf_btmcap_timestamp_native_accuracy,
374 { "Timestamp Native Accuracy", "btmcap.timestamp_native_accuracy",
375 FT_UINT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_ppm), 0x00,
376 NULL, HFILL }
378 { &hf_btmcap_response_parameters,
379 { "Response Parameters", "btmcap.response_parameters",
380 FT_BYTES, BASE_NONE, NULL, 0x00,
381 NULL, HFILL }
384 { &hf_btmcap_data,
385 { "Data", "btmcap.data",
386 FT_NONE, BASE_NONE, NULL, 0x00,
387 NULL, HFILL }
392 static int *ett[] = {
393 &ett_btmcap
396 static ei_register_info ei[] = {
397 { &ei_btmcap_mdl_id_ffff, { "btmcap.mdl_id.ffff", PI_PROTOCOL, PI_WARN, "The value 0xFFFF is not a valid MDL ID for this request and shall not be used.", EXPFILL }},
398 { &ei_btmcap_response_parameters_bad, { "btmcap.response_parameters.bad", PI_PROTOCOL, PI_WARN, "Response parameters bad", EXPFILL }},
399 { &ei_btmcap_unexpected_data, { "btmcap.unexpected_data", PI_PROTOCOL, PI_WARN, "Unexpected data", EXPFILL }},
402 proto_btmcap = proto_register_protocol("Bluetooth MCAP Protocol", "BT MCAP", "btmcap");
403 btmcap_handle = register_dissector("btmcap", dissect_btmcap, proto_btmcap);
405 proto_register_field_array(proto_btmcap, hf, array_length(hf));
406 proto_register_subtree_array(ett, array_length(ett));
407 expert_btmcap = expert_register_protocol(proto_btmcap);
408 expert_register_field_array(expert_btmcap, ei, array_length(ei));
410 module = prefs_register_protocol_subtree("Bluetooth", proto_btmcap, NULL);
411 prefs_register_static_text_preference(module, "mcap.version",
412 "Bluetooth Protocol MCAP version: 1.0",
413 "Version of protocol supported by this dissector.");
417 void
418 proto_reg_handoff_btmcap(void)
420 dissector_add_string("bluetooth.uuid", "1e", btmcap_handle);
421 dissector_add_string("bluetooth.uuid", "1f", btmcap_handle);
422 dissector_add_string("bluetooth.uuid", "1400", btmcap_handle);
423 dissector_add_string("bluetooth.uuid", "1401", btmcap_handle);
424 dissector_add_string("bluetooth.uuid", "1402", btmcap_handle);
426 /* dynamic PSM */
427 dissector_add_for_decode_as("btl2cap.psm", btmcap_handle);
428 dissector_add_for_decode_as("btl2cap.cid", btmcap_handle);
432 * Editor modelines - https://www.wireshark.org/tools/modelines.html
434 * Local variables:
435 * c-basic-offset: 4
436 * tab-width: 8
437 * indent-tabs-mode: nil
438 * End:
440 * vi: set shiftwidth=4 tabstop=8 expandtab:
441 * :indentSize=4:tabSize=8:noTabs=true: