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
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" },
67 static const value_string response_code_vals
[] = {
69 { 0x01, "Invalid Op Code" },
70 { 0x02, "Invalid Parameter Value" },
71 { 0x03, "Invalid MDEP" },
72 { 0x04, "MDEP Busy" },
73 { 0x05, "Invalid MDL" },
75 { 0x07, "Invalid Operation" },
76 { 0x08, "Resource Unavailable" },
77 { 0x09, "Unspecified Error" },
78 { 0x0A, "Request Not Supported" },
79 { 0x0B, "Configuration Rejected" },
84 void proto_register_btmcap(void);
85 void proto_reg_handoff_btmcap(void);
88 dissect_btmcap(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void *data _U_
)
90 proto_item
*main_item
;
91 proto_tree
*main_tree
;
95 uint32_t response_code
;
98 uint32_t bluetooth_clock_sync_time
;
99 uint64_t timestamp_sync_time
;
101 main_item
= proto_tree_add_item(tree
, proto_btmcap
, tvb
, offset
, tvb_captured_length(tvb
), ENC_NA
);
102 main_tree
= proto_item_add_subtree(main_item
, ett_btmcap
);
104 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "MCAP");
106 switch (pinfo
->p2p_dir
) {
108 col_set_str(pinfo
->cinfo
, COL_INFO
, "Sent ");
111 col_set_str(pinfo
->cinfo
, COL_INFO
, "Rcvd ");
114 col_set_str(pinfo
->cinfo
, COL_INFO
, "UnknownDirection ");
118 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_op_code
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
119 op_code
= tvb_get_uint8(tvb
, offset
);
122 col_append_str(pinfo
->cinfo
, COL_INFO
, val_to_str_const(op_code
, op_code_vals
, "Unknown Op Code"));
123 if (op_code
>= 0x11 && op_code
<= 0x20) {
124 proto_item_append_text(pitem
, " (Clock Sync)");
125 col_append_str(pinfo
->cinfo
, COL_INFO
, " (Clock Sync)");
127 proto_item_append_text(pitem
, " (Standard)");
128 col_append_str(pinfo
->cinfo
, COL_INFO
, " (Standard)");
131 if (op_code
& 0x01) {
134 case 0x01: /* MD_CREATE_MDL_REQ */
135 case 0x03: /* MD_RECONNECT_MDL_REQ */
136 case 0x05: /* MD_ABORT_MDL_REQ */
137 case 0x07: /* MD_DELETE_MDL_REQ */
138 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_mdl_id
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
139 mdl_id
= tvb_get_ntohs(tvb
, offset
);
142 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - MDL ID: %u", mdl_id
);
143 if (mdl_id
== 0xFFFF) {
144 proto_item_append_text(pitem
, " (Indicates all MDLs)");
145 col_append_str(pinfo
->cinfo
, COL_INFO
, " (Indicates all MDLs)");
146 } else if (mdl_id
>= 0x0001 && mdl_id
<= 0xFEFF) {
147 proto_item_append_text(pitem
, " (Dynamic Range)");
148 col_append_str(pinfo
->cinfo
, COL_INFO
, " (Dynamic Range)");
149 } else if (mdl_id
== 0x0000) {
150 proto_item_append_text(pitem
, " (Reserved)");
151 col_append_str(pinfo
->cinfo
, COL_INFO
, " (Reserved)");
154 if (op_code
!= 0x07 && mdl_id
== 0xFFFF) {
155 expert_add_info(pinfo
, pitem
, &ei_btmcap_mdl_id_ffff
);
158 if (op_code
== 0x01) {
159 /* only MD_CREATE_MDL_REQ */
160 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_mdep_id
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
161 mdep_id
= tvb_get_uint8(tvb
, offset
);
164 if (mdep_id
<= 0x7F) {
165 proto_item_append_text(pitem
, " (Available for use)");
167 proto_item_append_text(pitem
, " (Reserved)");
170 proto_tree_add_item(main_tree
, hf_btmcap_configuration
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
174 case 0x11: /* MD_SYNC_CAP_REQ */
175 proto_tree_add_item(main_tree
, hf_btmcap_timestamp_required_accuracy
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
178 case 0x13: /* MD_SYNC_SET_REQ */
179 proto_tree_add_item(main_tree
, hf_btmcap_timestamp_update_information
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
182 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_bluetooth_clock_sync_time
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
183 bluetooth_clock_sync_time
= tvb_get_ntohl(tvb
, offset
);
184 if (bluetooth_clock_sync_time
== 0xFFFFFFFF)
185 proto_item_append_text(pitem
, " (Instant Synchronization)");
187 proto_item_append_text(pitem
, " (Baseband Half-Slot Instant)");
190 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_timestamp_sync_time
, tvb
, offset
, 8, ENC_BIG_ENDIAN
);
191 timestamp_sync_time
= tvb_get_ntoh64(tvb
, offset
);
192 if (timestamp_sync_time
== UINT64_C(0xFFFFFFFFFFFFFFFF))
193 proto_item_append_text(pitem
, " (No Time Synchronization)");
195 proto_item_append_text(pitem
, " (Time-Stamp Clock Instant)");
198 case 0x15: /* MD_SYNC_INFO_IND */
199 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_bluetooth_clock_sync_time
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
200 proto_item_append_text(pitem
, " (Baseband Half-Slot Instant)");
203 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_timestamp_sync_time
, tvb
, offset
, 8, ENC_BIG_ENDIAN
);
204 proto_item_append_text(pitem
, " (Time-Stamp Clock Instant)");
207 proto_tree_add_item(main_tree
, hf_btmcap_timestamp_sample_accuracy
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
214 proto_tree_add_item(main_tree
, hf_btmcap_response_code
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
215 response_code
= tvb_get_uint8(tvb
, offset
);
218 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - %s", val_to_str_const(response_code
, response_code_vals
, "Unknown ResponseCode"));
220 if (op_code
>= 0x11 && op_code
<= 0x20) {
223 case 0x12: /* MD_SYNC_CAP_RSP */
224 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_bluetooth_clock_access_resolution
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
225 proto_item_append_text(pitem
, " (Baseband half-slots)");
228 proto_tree_add_item(main_tree
, hf_btmcap_sync_lead_time
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
231 proto_tree_add_item(main_tree
, hf_btmcap_timestamp_native_resolution
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
234 proto_tree_add_item(main_tree
, hf_btmcap_timestamp_native_accuracy
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
237 case 0x14: /* MD_SYNC_SET_RSP */
238 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_bluetooth_clock_sync_time
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
239 bluetooth_clock_sync_time
= tvb_get_ntohl(tvb
, offset
);
240 if (bluetooth_clock_sync_time
== 0xFFFFFFFF)
241 proto_item_append_text(pitem
, " (Instant Synchronization)");
243 proto_item_append_text(pitem
, " (Baseband Half-Slot Instant)");
246 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_timestamp_sync_time
, tvb
, offset
, 8, ENC_BIG_ENDIAN
);
247 timestamp_sync_time
= tvb_get_ntoh64(tvb
, offset
);
248 if (timestamp_sync_time
== UINT64_C(0xFFFFFFFFFFFFFFFF))
249 proto_item_append_text(pitem
, " (No Time Synchronization)");
251 proto_item_append_text(pitem
, " (Time-Stamp Clock Instant)");
254 proto_tree_add_item(main_tree
, hf_btmcap_timestamp_sample_accuracy
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
259 /* Standard Op Code */
260 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_mdl_id
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
261 mdl_id
= tvb_get_ntohs(tvb
, offset
);
264 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - %u", mdl_id
);
265 if (mdl_id
== 0xFFFF) {
266 proto_item_append_text(pitem
, " (Indicates all MDLs)");
267 col_append_str(pinfo
->cinfo
, COL_INFO
, " (Indicates all MDLs)");
268 } else if (mdl_id
>= 0x0001 && mdl_id
<= 0xFEFF) {
269 proto_item_append_text(pitem
, " (Dynamic Range)");
270 col_append_str(pinfo
->cinfo
, COL_INFO
, " (Dynamic Range)");
271 } else if (mdl_id
== 0x0000) {
272 proto_item_append_text(pitem
, " (Reserved)");
273 col_append_str(pinfo
->cinfo
, COL_INFO
, " (Reserved)");
276 if ((op_code
== 0x03 || op_code
== 0x05 || op_code
== 0x07) && tvb_reported_length_remaining(tvb
, offset
)) {
277 expert_add_info_format(pinfo
, pitem
, &ei_btmcap_response_parameters_bad
,
278 "The Response Parameters for MD_RECONNECT_MDL_RSP shall have length zero.");
279 } else if (tvb_reported_length_remaining(tvb
, offset
)) {
280 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_response_parameters
, tvb
, offset
, tvb_reported_length_remaining(tvb
, offset
), ENC_NA
);
281 if (response_code
!= 0x00) {
282 expert_add_info_format(pinfo
, pitem
, &ei_btmcap_response_parameters_bad
,
283 "When the Response Code is not Success, the Response Parameters shall have length zero.");
285 offset
+= tvb_reported_length_remaining(tvb
, offset
);
290 if (tvb_reported_length_remaining(tvb
, offset
)) {
291 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_data
, tvb
, offset
, tvb_reported_length_remaining(tvb
, offset
), ENC_NA
);
292 expert_add_info(pinfo
, pitem
, &ei_btmcap_unexpected_data
);
293 offset
= tvb_reported_length(tvb
);
301 proto_register_btmcap(void)
304 expert_module_t
*expert_btmcap
;
306 static hf_register_info hf
[] = {
307 { &hf_btmcap_op_code
,
308 { "Op Code", "btmcap.op_code",
309 FT_UINT8
, BASE_HEX
, VALS(op_code_vals
), 0x0,
312 { &hf_btmcap_response_code
,
313 { "Response Code", "btmcap.response_code",
314 FT_UINT8
, BASE_HEX
, VALS(response_code_vals
), 0x0,
318 { "MDL ID", "btmcap.mdl_id",
319 FT_UINT16
, BASE_HEX
, NULL
, 0x0,
322 { &hf_btmcap_mdep_id
,
323 { "MDEP ID", "btmcap.mdep_id",
324 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
327 { &hf_btmcap_configuration
,
328 { "Configuration", "btmcap.configuration",
329 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
332 { &hf_btmcap_timestamp_required_accuracy
,
333 { "Timestamp Required Accuracy", "btmcap.timestamp_required_accuracy",
334 FT_UINT16
, BASE_DEC
|BASE_UNIT_STRING
, UNS(&units_ppm
), 0x00,
337 { &hf_btmcap_timestamp_update_information
,
338 { "Timestamp Update Information", "btmcap.timestamp_update_information",
339 FT_UINT8
, BASE_DEC
, NULL
, 0x00,
342 { &hf_btmcap_bluetooth_clock_sync_time
,
343 { "Bluetooth Clock Sync Time", "btmcap.bluetooth_clock_sync_time",
344 FT_UINT32
, BASE_DEC
, NULL
, 0x00,
347 { &hf_btmcap_timestamp_sync_time
,
348 { "Timestamp Sync Time", "btmcap.timestamp_sync_time",
349 FT_UINT64
, BASE_DEC
, NULL
, 0x00,
352 { &hf_btmcap_timestamp_sample_accuracy
,
353 { "Timestamp Sample Accuracy", "btmcap.timestamp_sample_accuracy",
354 FT_UINT16
, BASE_DEC
|BASE_UNIT_STRING
, UNS(&units_microseconds
), 0x00,
357 { &hf_btmcap_bluetooth_clock_access_resolution
,
358 { "Bluetooth Clock Access Resolution","btmcap.bluetooth_clock_access_resolution",
359 FT_UINT8
, BASE_DEC
, NULL
, 0x00,
362 { &hf_btmcap_sync_lead_time
,
363 { "Sync Lead Time", "btmcap.sync_lead_time",
364 FT_UINT16
, BASE_DEC
|BASE_UNIT_STRING
, UNS(&units_milliseconds
), 0x00,
367 { &hf_btmcap_timestamp_native_resolution
,
368 { "Timestamp Native Resolution", "btmcap.timestamp_native_resolution",
369 FT_UINT16
, BASE_DEC
|BASE_UNIT_STRING
, UNS(&units_microseconds
), 0x00,
372 { &hf_btmcap_timestamp_native_accuracy
,
373 { "Timestamp Native Accuracy", "btmcap.timestamp_native_accuracy",
374 FT_UINT16
, BASE_DEC
|BASE_UNIT_STRING
, UNS(&units_ppm
), 0x00,
377 { &hf_btmcap_response_parameters
,
378 { "Response Parameters", "btmcap.response_parameters",
379 FT_BYTES
, BASE_NONE
, NULL
, 0x00,
384 { "Data", "btmcap.data",
385 FT_NONE
, BASE_NONE
, NULL
, 0x00,
391 static int *ett
[] = {
395 static ei_register_info ei
[] = {
396 { &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
}},
397 { &ei_btmcap_response_parameters_bad
, { "btmcap.response_parameters.bad", PI_PROTOCOL
, PI_WARN
, "Response parameters bad", EXPFILL
}},
398 { &ei_btmcap_unexpected_data
, { "btmcap.unexpected_data", PI_PROTOCOL
, PI_WARN
, "Unexpected data", EXPFILL
}},
401 proto_btmcap
= proto_register_protocol("Bluetooth MCAP Protocol", "BT MCAP", "btmcap");
402 btmcap_handle
= register_dissector("btmcap", dissect_btmcap
, proto_btmcap
);
404 proto_register_field_array(proto_btmcap
, hf
, array_length(hf
));
405 proto_register_subtree_array(ett
, array_length(ett
));
406 expert_btmcap
= expert_register_protocol(proto_btmcap
);
407 expert_register_field_array(expert_btmcap
, ei
, array_length(ei
));
409 module
= prefs_register_protocol_subtree("Bluetooth", proto_btmcap
, NULL
);
410 prefs_register_static_text_preference(module
, "mcap.version",
411 "Bluetooth Protocol MCAP version: 1.0",
412 "Version of protocol supported by this dissector.");
417 proto_reg_handoff_btmcap(void)
419 dissector_add_string("bluetooth.uuid", "1e", btmcap_handle
);
420 dissector_add_string("bluetooth.uuid", "1f", btmcap_handle
);
421 dissector_add_string("bluetooth.uuid", "1400", btmcap_handle
);
422 dissector_add_string("bluetooth.uuid", "1401", btmcap_handle
);
423 dissector_add_string("bluetooth.uuid", "1402", btmcap_handle
);
426 dissector_add_for_decode_as("btl2cap.psm", btmcap_handle
);
427 dissector_add_for_decode_as("btl2cap.cid", btmcap_handle
);
431 * Editor modelines - https://www.wireshark.org/tools/modelines.html
436 * indent-tabs-mode: nil
439 * vi: set shiftwidth=4 tabstop=8 expandtab:
440 * :indentSize=4:tabSize=8:noTabs=true: