2 * Routines for Bluetooth MCAP dissection
3 * https://www.bluetooth.org/Technical/Specifications/adopted.htm
5 * Copyright 2013, Michal Labedzki for Tieto Corporation
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include <epan/packet.h>
31 #include <epan/prefs.h>
32 #include <epan/expert.h>
34 #include "packet-btl2cap.h"
35 #include "packet-btsdp.h"
37 static int proto_btmcap = -1;
39 static int hf_btmcap_op_code = -1;
40 static int hf_btmcap_response_code = -1;
41 static int hf_btmcap_mdl_id = -1;
42 static int hf_btmcap_mdep_id = -1;
43 static int hf_btmcap_response_parameters = -1;
44 static int hf_btmcap_configuration = -1;
45 static int hf_btmcap_timestamp_required_accuracy = -1;
46 static int hf_btmcap_timestamp_update_information = -1;
47 static int hf_btmcap_bluetooth_clock_sync_time = -1;
48 static int hf_btmcap_timestamp_sync_time = -1;
49 static int hf_btmcap_timestamp_sample_accuracy = -1;
50 static int hf_btmcap_bluetooth_clock_access_resolution = -1;
51 static int hf_btmcap_sync_lead_time = -1;
52 static int hf_btmcap_timestamp_native_resolution = -1;
53 static int hf_btmcap_timestamp_native_accuracy = -1;
55 static int hf_btmcap_data = -1;
57 static gint ett_btmcap = -1;
59 static expert_field ei_btmcap_mdl_id_ffff = EI_INIT;
60 static expert_field ei_btmcap_response_parameters_bad = EI_INIT;
61 static expert_field ei_btmcap_unexpected_data = EI_INIT;
63 static const value_string op_code_vals[] = {
64 { 0x00, "ERROR_RSP" },
65 { 0x01, "MD_CREATE_MDL_REQ" },
66 { 0x02, "MD_CREATE_MDL_RSP" },
67 { 0x03, "MD_RECONNECT_MDL_REQ" },
68 { 0x04, "MD_RECONNECT_MDL_RSP" },
69 { 0x05, "MD_ABORT_MDL_REQ" },
70 { 0x06, "MD_ABORT_MDL_RSP" },
71 { 0x07, "MD_DELETE_MDL_REQ" },
72 { 0x08, "MD_DELETE_MDL_RSP" },
73 { 0x11, "MD_SYNC_CAP_REQ" },
74 { 0x12, "MD_SYNC_CAP_RSP" },
75 { 0x13, "MD_SYNC_SET_REQ" },
76 { 0x14, "MD_SYNC_SET_RSP" },
77 { 0x15, "MD_SYNC_INFO_IND" },
78 { 0x16, "Reserved as pseudoresponse" },
82 static const value_string response_code_vals[] = {
84 { 0x01, "Invalid Op Code" },
85 { 0x02, "Invalid Parameter Value" },
86 { 0x03, "Invalid MDEP" },
87 { 0x04, "MDEP Busy" },
88 { 0x05, "Invalid MDL" },
90 { 0x07, "Invalid Operation" },
91 { 0x08, "Resource Unavailable" },
92 { 0x09, "Unspecified Error" },
93 { 0x0A, "Request Not Supported" },
94 { 0x0B, "Configuration Rejected" },
98 void proto_register_btmcap(void);
99 void proto_reg_handoff_btmcap(void);
102 dissect_btmcap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
104 proto_item *main_item;
105 proto_tree *main_tree;
109 guint32 response_code;
112 guint32 bluetooth_clock_sync_time;
113 guint64 timestamp_sync_time;
115 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MCAP");
116 col_clear(pinfo->cinfo, COL_INFO);
118 switch (pinfo->p2p_dir) {
120 col_add_str(pinfo->cinfo, COL_INFO, "Sent ");
123 col_add_str(pinfo->cinfo, COL_INFO, "Rcvd ");
126 col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown direction %d ",
131 main_item = proto_tree_add_item(tree, proto_btmcap, tvb, offset, -1, ENC_NA);
132 main_tree = proto_item_add_subtree(main_item, ett_btmcap);
134 pitem = proto_tree_add_item(main_tree, hf_btmcap_op_code, tvb, offset, 1, ENC_BIG_ENDIAN);
135 op_code = tvb_get_guint8(tvb, offset);
138 col_append_fstr(pinfo->cinfo, COL_INFO, "%s", val_to_str(op_code, op_code_vals, "Unknown Op Code"));
139 if (op_code >= 0x11 && op_code <= 0x20) {
140 proto_item_append_text(pitem, " (Clock Sync)");
141 col_append_fstr(pinfo->cinfo, COL_INFO, " (Clock Sync)");
143 proto_item_append_text(pitem, " (Standard)");
144 col_append_fstr(pinfo->cinfo, COL_INFO, " (Standard)");
147 if (op_code & 0x01) {
150 case 0x01: /* MD_CREATE_MDL_REQ */
151 case 0x03: /* MD_RECONNECT_MDL_REQ */
152 case 0x05: /* MD_ABORT_MDL_REQ */
153 case 0x07: /* MD_DELETE_MDL_REQ */
154 pitem = proto_tree_add_item(main_tree, hf_btmcap_mdl_id, tvb, offset, 2, ENC_BIG_ENDIAN);
155 mdl_id = tvb_get_ntohs(tvb, offset);
158 col_append_fstr(pinfo->cinfo, COL_INFO, " - MDL ID: %u", mdl_id);
159 if (mdl_id == 0xFFFF) {
160 proto_item_append_text(pitem, " (Indicates all MDLs)");
161 col_append_fstr(pinfo->cinfo, COL_INFO, " (Indicates all MDLs)");
162 } else if (mdl_id >= 0x0001 && mdl_id <= 0xFEFF) {
163 proto_item_append_text(pitem, " (Dynamic Range)");
164 col_append_fstr(pinfo->cinfo, COL_INFO, " (Dynamic Range)");
165 } else if (mdl_id == 0x0000) {
166 proto_item_append_text(pitem, " (Reserved)");
167 col_append_fstr(pinfo->cinfo, COL_INFO, " (Reserved)");
170 if (op_code != 0x07 && mdl_id == 0xFFFF) {
171 expert_add_info(pinfo, pitem, &ei_btmcap_mdl_id_ffff);
174 if (op_code == 0x01) {
175 /* only MD_CREATE_MDL_REQ */
176 pitem = proto_tree_add_item(main_tree, hf_btmcap_mdep_id, tvb, offset, 1, ENC_BIG_ENDIAN);
177 mdep_id = tvb_get_guint8(tvb, offset);
180 if (mdep_id <= 0x7F) {
181 proto_item_append_text(pitem, " (Available for use)");
183 proto_item_append_text(pitem, " (Reserved)");
186 proto_tree_add_item(main_tree, hf_btmcap_configuration, tvb, offset, 1, ENC_BIG_ENDIAN);
190 case 0x11: /* MD_SYNC_CAP_REQ */
191 pitem = proto_tree_add_item(main_tree, hf_btmcap_timestamp_required_accuracy, tvb, offset, 2, ENC_BIG_ENDIAN);
192 proto_item_append_text(pitem, " ppm");
195 case 0x13: /* MD_SYNC_SET_REQ */
196 proto_tree_add_item(main_tree, hf_btmcap_timestamp_update_information, tvb, offset, 1, ENC_BIG_ENDIAN);
199 pitem = proto_tree_add_item(main_tree, hf_btmcap_bluetooth_clock_sync_time, tvb, offset, 4, ENC_BIG_ENDIAN);
200 bluetooth_clock_sync_time = tvb_get_ntohl(tvb, offset);
201 if (bluetooth_clock_sync_time == 0xFFFFFFFF)
202 proto_item_append_text(pitem, " (Instant Synchronization)");
204 proto_item_append_text(pitem, " (Baseband Half-Slot Instant)");;
207 pitem = proto_tree_add_item(main_tree, hf_btmcap_timestamp_sync_time, tvb, offset, 8, ENC_BIG_ENDIAN);
208 timestamp_sync_time = tvb_get_ntoh64(tvb, offset);
209 if (timestamp_sync_time == G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF))
210 proto_item_append_text(pitem, " (No Time Synchronization)");
212 proto_item_append_text(pitem, " (Time-Stamp Clock Instant)");
215 case 0x15: /* MD_SYNC_INFO_IND */
216 pitem = proto_tree_add_item(main_tree, hf_btmcap_bluetooth_clock_sync_time, tvb, offset, 4, ENC_BIG_ENDIAN);
217 proto_item_append_text(pitem, " (Baseband Half-Slot Instant)");
220 pitem = proto_tree_add_item(main_tree, hf_btmcap_timestamp_sync_time, tvb, offset, 8, ENC_BIG_ENDIAN);
221 proto_item_append_text(pitem, " (Time-Stamp Clock Instant)");
224 pitem = proto_tree_add_item(main_tree, hf_btmcap_timestamp_sample_accuracy, tvb, offset, 2, ENC_BIG_ENDIAN);
225 proto_item_append_text(pitem, " us");
232 proto_tree_add_item(main_tree, hf_btmcap_response_code, tvb, offset, 1, ENC_BIG_ENDIAN);
233 response_code = tvb_get_guint8(tvb, offset);
236 col_append_fstr(pinfo->cinfo, COL_INFO, " - %s", val_to_str(response_code, response_code_vals, "Unknown ResponseCode"));
238 if (op_code >= 0x11 && op_code <= 0x20) {
241 case 0x12: /* MD_SYNC_CAP_RSP */
242 pitem = proto_tree_add_item(main_tree, hf_btmcap_bluetooth_clock_access_resolution, tvb, offset, 1, ENC_BIG_ENDIAN);
243 proto_item_append_text(pitem, " (Baseband half-slots)");
246 pitem = proto_tree_add_item(main_tree, hf_btmcap_sync_lead_time, tvb, offset, 2, ENC_BIG_ENDIAN);
247 proto_item_append_text(pitem, " ms");
250 pitem = proto_tree_add_item(main_tree, hf_btmcap_timestamp_native_resolution, tvb, offset, 2, ENC_BIG_ENDIAN);
251 proto_item_append_text(pitem, " us");
254 pitem = proto_tree_add_item(main_tree, hf_btmcap_timestamp_native_accuracy, tvb, offset, 2, ENC_BIG_ENDIAN);
255 proto_item_append_text(pitem, " ppm");
258 case 0x14: /* MD_SYNC_SET_RSP */
259 pitem = proto_tree_add_item(main_tree, hf_btmcap_bluetooth_clock_sync_time, tvb, offset, 4, ENC_BIG_ENDIAN);
260 bluetooth_clock_sync_time = tvb_get_ntohl(tvb, offset);
261 if (bluetooth_clock_sync_time == 0xFFFFFFFF)
262 proto_item_append_text(pitem, " (Instant Synchronization)");
264 proto_item_append_text(pitem, " (Baseband Half-Slot Instant)");
267 pitem = proto_tree_add_item(main_tree, hf_btmcap_timestamp_sync_time, tvb, offset, 8, ENC_BIG_ENDIAN);
268 timestamp_sync_time = tvb_get_ntoh64(tvb, offset);
269 if (timestamp_sync_time == G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF))
270 proto_item_append_text(pitem, " (No Time Synchronization)");
272 proto_item_append_text(pitem, " (Time-Stamp Clock Instant)");
275 pitem = proto_tree_add_item(main_tree, hf_btmcap_timestamp_sample_accuracy, tvb, offset, 2, ENC_BIG_ENDIAN);
276 proto_item_append_text(pitem, " us");
281 /* Standard Op Code */
282 pitem = proto_tree_add_item(main_tree, hf_btmcap_mdl_id, tvb, offset, 2, ENC_BIG_ENDIAN);
283 mdl_id = tvb_get_ntohs(tvb, offset);
286 col_append_fstr(pinfo->cinfo, COL_INFO, " - %u", mdl_id);
287 if (mdl_id == 0xFFFF) {
288 proto_item_append_text(pitem, " (Indicates all MDLs)");
289 col_append_fstr(pinfo->cinfo, COL_INFO, " (Indicates all MDLs)");
290 } else if (mdl_id >= 0x0001 && mdl_id <= 0xFEFF) {
291 proto_item_append_text(pitem, " (Dynamic Range)");
292 col_append_fstr(pinfo->cinfo, COL_INFO, " (Dynamic Range)");
293 } else if (mdl_id == 0x0000) {
294 proto_item_append_text(pitem, " (Reserved)");
295 col_append_fstr(pinfo->cinfo, COL_INFO, " (Reserved)");
298 if ((op_code == 0x03 || op_code == 0x05 || op_code == 0x07) && tvb_length_remaining(tvb, offset)) {
299 expert_add_info_format_text(pinfo, pitem, &ei_btmcap_response_parameters_bad,
300 "The Response Parameters for MD_RECONNECT_MDL_RSP shall have length zero.");
301 } else if (tvb_length_remaining(tvb, offset)) {
302 pitem = proto_tree_add_item(main_tree, hf_btmcap_response_parameters, tvb, offset, -1, ENC_NA);
303 if (response_code != 0x00) {
304 expert_add_info_format_text(pinfo, pitem, &ei_btmcap_response_parameters_bad,
305 "When the Response Code is not Success, the Response Parameters shall have length zero.");
307 offset += tvb_length_remaining(tvb, offset);
312 if (tvb_length_remaining(tvb, offset)) {
313 pitem = proto_tree_add_item(main_tree, hf_btmcap_data, tvb, offset, -1, ENC_NA);
314 expert_add_info(pinfo, pitem, &ei_btmcap_unexpected_data);
320 proto_register_btmcap(void)
323 expert_module_t* expert_btmcap;
325 static hf_register_info hf[] = {
326 { &hf_btmcap_op_code,
327 { "Op Code", "btmcap.op_code",
328 FT_UINT8, BASE_HEX, VALS(op_code_vals), 0x0,
331 { &hf_btmcap_response_code,
332 { "Response Code", "btmcap.response_code",
333 FT_UINT8, BASE_HEX, VALS(response_code_vals), 0x0,
337 { "MDL ID", "btmcap.mdl_id",
338 FT_UINT16, BASE_HEX, NULL, 0x0,
341 { &hf_btmcap_mdep_id,
342 { "MDEP ID", "btmcap.mdep_id",
343 FT_UINT8, BASE_HEX, NULL, 0x0,
346 { &hf_btmcap_configuration,
347 { "Configuration", "btmcap.configuration",
348 FT_UINT8, BASE_HEX, NULL, 0x0,
351 { &hf_btmcap_timestamp_required_accuracy,
352 { "Timestamp Required Accuracy", "btmcap.timestamp_required_accuracy",
353 FT_UINT16, BASE_DEC, NULL, 0x00,
356 { &hf_btmcap_timestamp_update_information,
357 { "Timestamp Update Information", "btmcap.timestamp_update_information",
358 FT_UINT8, BASE_DEC, NULL, 0x00,
361 { &hf_btmcap_bluetooth_clock_sync_time,
362 { "Bluetooth Clock Sync Time", "btmcap.bluetooth_clock_sync_time",
363 FT_UINT32, BASE_DEC, NULL, 0x00,
366 { &hf_btmcap_timestamp_sync_time,
367 { "Timestamp Sync Time", "btmcap.timestamp_sync_time",
368 FT_UINT64, BASE_DEC, NULL, 0x00,
371 { &hf_btmcap_timestamp_sample_accuracy,
372 { "Timestamp Sample Accuracy", "btmcap.timestamp_sample_accuracy",
373 FT_UINT16, BASE_DEC, NULL, 0x00,
376 { &hf_btmcap_bluetooth_clock_access_resolution,
377 { "Bluetooth Clock Access Resolution","btmcap.bluetooth_clock_access_resolution",
378 FT_UINT8, BASE_DEC, NULL, 0x00,
381 { &hf_btmcap_sync_lead_time,
382 { "Sync Lead Time", "btmcap.sync_lead_time",
383 FT_UINT16, BASE_DEC, NULL, 0x00,
386 { &hf_btmcap_timestamp_native_resolution,
387 { "Timestamp Native Resolution", "btmcap.timestamp_native_resolution",
388 FT_UINT16, BASE_DEC, NULL, 0x00,
391 { &hf_btmcap_timestamp_native_accuracy,
392 { "Timestamp Native Accuracy", "btmcap.timestamp_native_accuracy",
393 FT_UINT16, BASE_DEC, NULL, 0x00,
396 { &hf_btmcap_response_parameters,
397 { "Response Parameters", "btmcap.response_parameters",
398 FT_BYTES, BASE_NONE, NULL, 0x00,
403 { "Data", "btmcap.data",
404 FT_NONE, BASE_NONE, NULL, 0x00,
410 static gint *ett[] = {
414 static ei_register_info ei[] = {
415 { &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 }},
416 { &ei_btmcap_response_parameters_bad, { "btmcap.response_parameters.bad", PI_PROTOCOL, PI_WARN, "Response parameters bad", EXPFILL }},
417 { &ei_btmcap_unexpected_data, { "btmcap.unexpected_data", PI_PROTOCOL, PI_WARN, "Unexpected data", EXPFILL }},
420 proto_btmcap = proto_register_protocol("Bluetooth MCAP Protocol", "BT MCAP", "btmcap");
421 register_dissector("btmcap", dissect_btmcap, proto_btmcap);
423 proto_register_field_array(proto_btmcap, hf, array_length(hf));
424 proto_register_subtree_array(ett, array_length(ett));
425 expert_btmcap = expert_register_protocol(proto_btmcap);
426 expert_register_field_array(expert_btmcap, ei, array_length(ei));
428 module = prefs_register_protocol(proto_btmcap, NULL);
429 prefs_register_static_text_preference(module, "mcap.version",
430 "Bluetooth Protocol MCAP version: 1.0",
431 "Version of protocol supported by this dissector.");
436 proto_reg_handoff_btmcap(void)
438 dissector_handle_t btmcap_handle;
440 btmcap_handle = find_dissector("btmcap");
442 dissector_add_uint("btl2cap.service", BTSDP_MCAP_CONTROL_CHANNEL_PROTOCOL_UUID, btmcap_handle);
443 dissector_add_uint("btl2cap.service", BTSDP_MCAP_DATA_CHANNEL_PROTOCOL_UUID, btmcap_handle);
445 dissector_add_uint("btl2cap.service", BTSDP_HDP_SERVICE_UUID, btmcap_handle);
446 dissector_add_uint("btl2cap.service", BTSDP_HDP_SOURCE_SERVICE_UUID, btmcap_handle);
447 dissector_add_uint("btl2cap.service", BTSDP_HDP_SINK_SERVICE_UUID, btmcap_handle);
450 dissector_add_handle("btl2cap.psm", btmcap_handle);
451 dissector_add_handle("btl2cap.cid", btmcap_handle);
455 * Editor modelines - http://www.wireshark.org/tools/modelines.html
460 * indent-tabs-mode: nil
463 * vi: set shiftwidth=4 tabstop=8 expandtab:
464 * :indentSize=4:tabSize=8:noTabs=true: