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
, void *data _U_
)
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 main_item
= proto_tree_add_item(tree
, proto_btmcap
, tvb
, offset
, -1, ENC_NA
);
116 main_tree
= proto_item_add_subtree(main_item
, ett_btmcap
);
118 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "MCAP");
120 switch (pinfo
->p2p_dir
) {
122 col_set_str(pinfo
->cinfo
, COL_INFO
, "Sent ");
125 col_set_str(pinfo
->cinfo
, COL_INFO
, "Rcvd ");
128 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Unknown direction %d ",
133 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_op_code
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
134 op_code
= tvb_get_guint8(tvb
, offset
);
137 col_append_fstr(pinfo
->cinfo
, COL_INFO
, "%s", val_to_str(op_code
, op_code_vals
, "Unknown Op Code"));
138 if (op_code
>= 0x11 && op_code
<= 0x20) {
139 proto_item_append_text(pitem
, " (Clock Sync)");
140 col_append_str(pinfo
->cinfo
, COL_INFO
, " (Clock Sync)");
142 proto_item_append_text(pitem
, " (Standard)");
143 col_append_str(pinfo
->cinfo
, COL_INFO
, " (Standard)");
146 if (op_code
& 0x01) {
149 case 0x01: /* MD_CREATE_MDL_REQ */
150 case 0x03: /* MD_RECONNECT_MDL_REQ */
151 case 0x05: /* MD_ABORT_MDL_REQ */
152 case 0x07: /* MD_DELETE_MDL_REQ */
153 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_mdl_id
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
154 mdl_id
= tvb_get_ntohs(tvb
, offset
);
157 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - MDL ID: %u", mdl_id
);
158 if (mdl_id
== 0xFFFF) {
159 proto_item_append_text(pitem
, " (Indicates all MDLs)");
160 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " (Indicates all MDLs)");
161 } else if (mdl_id
>= 0x0001 && mdl_id
<= 0xFEFF) {
162 proto_item_append_text(pitem
, " (Dynamic Range)");
163 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " (Dynamic Range)");
164 } else if (mdl_id
== 0x0000) {
165 proto_item_append_text(pitem
, " (Reserved)");
166 col_append_str(pinfo
->cinfo
, COL_INFO
, " (Reserved)");
169 if (op_code
!= 0x07 && mdl_id
== 0xFFFF) {
170 expert_add_info(pinfo
, pitem
, &ei_btmcap_mdl_id_ffff
);
173 if (op_code
== 0x01) {
174 /* only MD_CREATE_MDL_REQ */
175 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_mdep_id
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
176 mdep_id
= tvb_get_guint8(tvb
, offset
);
179 if (mdep_id
<= 0x7F) {
180 proto_item_append_text(pitem
, " (Available for use)");
182 proto_item_append_text(pitem
, " (Reserved)");
185 proto_tree_add_item(main_tree
, hf_btmcap_configuration
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
189 case 0x11: /* MD_SYNC_CAP_REQ */
190 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_timestamp_required_accuracy
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
191 proto_item_append_text(pitem
, " ppm");
194 case 0x13: /* MD_SYNC_SET_REQ */
195 proto_tree_add_item(main_tree
, hf_btmcap_timestamp_update_information
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
198 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_bluetooth_clock_sync_time
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
199 bluetooth_clock_sync_time
= tvb_get_ntohl(tvb
, offset
);
200 if (bluetooth_clock_sync_time
== 0xFFFFFFFF)
201 proto_item_append_text(pitem
, " (Instant Synchronization)");
203 proto_item_append_text(pitem
, " (Baseband Half-Slot Instant)");;
206 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_timestamp_sync_time
, tvb
, offset
, 8, ENC_BIG_ENDIAN
);
207 timestamp_sync_time
= tvb_get_ntoh64(tvb
, offset
);
208 if (timestamp_sync_time
== G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF))
209 proto_item_append_text(pitem
, " (No Time Synchronization)");
211 proto_item_append_text(pitem
, " (Time-Stamp Clock Instant)");
214 case 0x15: /* MD_SYNC_INFO_IND */
215 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_bluetooth_clock_sync_time
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
216 proto_item_append_text(pitem
, " (Baseband Half-Slot Instant)");
219 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_timestamp_sync_time
, tvb
, offset
, 8, ENC_BIG_ENDIAN
);
220 proto_item_append_text(pitem
, " (Time-Stamp Clock Instant)");
223 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_timestamp_sample_accuracy
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
224 proto_item_append_text(pitem
, " us");
231 proto_tree_add_item(main_tree
, hf_btmcap_response_code
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
232 response_code
= tvb_get_guint8(tvb
, offset
);
235 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - %s", val_to_str(response_code
, response_code_vals
, "Unknown ResponseCode"));
237 if (op_code
>= 0x11 && op_code
<= 0x20) {
240 case 0x12: /* MD_SYNC_CAP_RSP */
241 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_bluetooth_clock_access_resolution
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
242 proto_item_append_text(pitem
, " (Baseband half-slots)");
245 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_sync_lead_time
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
246 proto_item_append_text(pitem
, " ms");
249 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_timestamp_native_resolution
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
250 proto_item_append_text(pitem
, " us");
253 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_timestamp_native_accuracy
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
254 proto_item_append_text(pitem
, " ppm");
257 case 0x14: /* MD_SYNC_SET_RSP */
258 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_bluetooth_clock_sync_time
, tvb
, offset
, 4, ENC_BIG_ENDIAN
);
259 bluetooth_clock_sync_time
= tvb_get_ntohl(tvb
, offset
);
260 if (bluetooth_clock_sync_time
== 0xFFFFFFFF)
261 proto_item_append_text(pitem
, " (Instant Synchronization)");
263 proto_item_append_text(pitem
, " (Baseband Half-Slot Instant)");
266 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_timestamp_sync_time
, tvb
, offset
, 8, ENC_BIG_ENDIAN
);
267 timestamp_sync_time
= tvb_get_ntoh64(tvb
, offset
);
268 if (timestamp_sync_time
== G_GUINT64_CONSTANT(0xFFFFFFFFFFFFFFFF))
269 proto_item_append_text(pitem
, " (No Time Synchronization)");
271 proto_item_append_text(pitem
, " (Time-Stamp Clock Instant)");
274 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_timestamp_sample_accuracy
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
275 proto_item_append_text(pitem
, " us");
280 /* Standard Op Code */
281 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_mdl_id
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
282 mdl_id
= tvb_get_ntohs(tvb
, offset
);
285 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " - %u", mdl_id
);
286 if (mdl_id
== 0xFFFF) {
287 proto_item_append_text(pitem
, " (Indicates all MDLs)");
288 col_append_str(pinfo
->cinfo
, COL_INFO
, " (Indicates all MDLs)");
289 } else if (mdl_id
>= 0x0001 && mdl_id
<= 0xFEFF) {
290 proto_item_append_text(pitem
, " (Dynamic Range)");
291 col_append_str(pinfo
->cinfo
, COL_INFO
, " (Dynamic Range)");
292 } else if (mdl_id
== 0x0000) {
293 proto_item_append_text(pitem
, " (Reserved)");
294 col_append_str(pinfo
->cinfo
, COL_INFO
, " (Reserved)");
297 if ((op_code
== 0x03 || op_code
== 0x05 || op_code
== 0x07) && tvb_length_remaining(tvb
, offset
)) {
298 expert_add_info_format(pinfo
, pitem
, &ei_btmcap_response_parameters_bad
,
299 "The Response Parameters for MD_RECONNECT_MDL_RSP shall have length zero.");
300 } else if (tvb_length_remaining(tvb
, offset
)) {
301 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_response_parameters
, tvb
, offset
, -1, ENC_NA
);
302 if (response_code
!= 0x00) {
303 expert_add_info_format(pinfo
, pitem
, &ei_btmcap_response_parameters_bad
,
304 "When the Response Code is not Success, the Response Parameters shall have length zero.");
306 offset
+= tvb_length_remaining(tvb
, offset
);
311 if (tvb_length_remaining(tvb
, offset
)) {
312 pitem
= proto_tree_add_item(main_tree
, hf_btmcap_data
, tvb
, offset
, -1, ENC_NA
);
313 expert_add_info(pinfo
, pitem
, &ei_btmcap_unexpected_data
);
314 offset
= tvb_length(tvb
);
322 proto_register_btmcap(void)
325 expert_module_t
*expert_btmcap
;
327 static hf_register_info hf
[] = {
328 { &hf_btmcap_op_code
,
329 { "Op Code", "btmcap.op_code",
330 FT_UINT8
, BASE_HEX
, VALS(op_code_vals
), 0x0,
333 { &hf_btmcap_response_code
,
334 { "Response Code", "btmcap.response_code",
335 FT_UINT8
, BASE_HEX
, VALS(response_code_vals
), 0x0,
339 { "MDL ID", "btmcap.mdl_id",
340 FT_UINT16
, BASE_HEX
, NULL
, 0x0,
343 { &hf_btmcap_mdep_id
,
344 { "MDEP ID", "btmcap.mdep_id",
345 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
348 { &hf_btmcap_configuration
,
349 { "Configuration", "btmcap.configuration",
350 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
353 { &hf_btmcap_timestamp_required_accuracy
,
354 { "Timestamp Required Accuracy", "btmcap.timestamp_required_accuracy",
355 FT_UINT16
, BASE_DEC
, NULL
, 0x00,
358 { &hf_btmcap_timestamp_update_information
,
359 { "Timestamp Update Information", "btmcap.timestamp_update_information",
360 FT_UINT8
, BASE_DEC
, NULL
, 0x00,
363 { &hf_btmcap_bluetooth_clock_sync_time
,
364 { "Bluetooth Clock Sync Time", "btmcap.bluetooth_clock_sync_time",
365 FT_UINT32
, BASE_DEC
, NULL
, 0x00,
368 { &hf_btmcap_timestamp_sync_time
,
369 { "Timestamp Sync Time", "btmcap.timestamp_sync_time",
370 FT_UINT64
, BASE_DEC
, NULL
, 0x00,
373 { &hf_btmcap_timestamp_sample_accuracy
,
374 { "Timestamp Sample Accuracy", "btmcap.timestamp_sample_accuracy",
375 FT_UINT16
, BASE_DEC
, NULL
, 0x00,
378 { &hf_btmcap_bluetooth_clock_access_resolution
,
379 { "Bluetooth Clock Access Resolution","btmcap.bluetooth_clock_access_resolution",
380 FT_UINT8
, BASE_DEC
, NULL
, 0x00,
383 { &hf_btmcap_sync_lead_time
,
384 { "Sync Lead Time", "btmcap.sync_lead_time",
385 FT_UINT16
, BASE_DEC
, NULL
, 0x00,
388 { &hf_btmcap_timestamp_native_resolution
,
389 { "Timestamp Native Resolution", "btmcap.timestamp_native_resolution",
390 FT_UINT16
, BASE_DEC
, NULL
, 0x00,
393 { &hf_btmcap_timestamp_native_accuracy
,
394 { "Timestamp Native Accuracy", "btmcap.timestamp_native_accuracy",
395 FT_UINT16
, BASE_DEC
, NULL
, 0x00,
398 { &hf_btmcap_response_parameters
,
399 { "Response Parameters", "btmcap.response_parameters",
400 FT_BYTES
, BASE_NONE
, NULL
, 0x00,
405 { "Data", "btmcap.data",
406 FT_NONE
, BASE_NONE
, NULL
, 0x00,
412 static gint
*ett
[] = {
416 static ei_register_info ei
[] = {
417 { &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
}},
418 { &ei_btmcap_response_parameters_bad
, { "btmcap.response_parameters.bad", PI_PROTOCOL
, PI_WARN
, "Response parameters bad", EXPFILL
}},
419 { &ei_btmcap_unexpected_data
, { "btmcap.unexpected_data", PI_PROTOCOL
, PI_WARN
, "Unexpected data", EXPFILL
}},
422 proto_btmcap
= proto_register_protocol("Bluetooth MCAP Protocol", "BT MCAP", "btmcap");
423 new_register_dissector("btmcap", dissect_btmcap
, proto_btmcap
);
425 proto_register_field_array(proto_btmcap
, hf
, array_length(hf
));
426 proto_register_subtree_array(ett
, array_length(ett
));
427 expert_btmcap
= expert_register_protocol(proto_btmcap
);
428 expert_register_field_array(expert_btmcap
, ei
, array_length(ei
));
430 module
= prefs_register_protocol(proto_btmcap
, NULL
);
431 prefs_register_static_text_preference(module
, "mcap.version",
432 "Bluetooth Protocol MCAP version: 1.0",
433 "Version of protocol supported by this dissector.");
438 proto_reg_handoff_btmcap(void)
440 dissector_handle_t btmcap_handle
;
442 btmcap_handle
= find_dissector("btmcap");
444 dissector_add_uint("btl2cap.service", BTSDP_MCAP_CONTROL_CHANNEL_PROTOCOL_UUID
, btmcap_handle
);
445 dissector_add_uint("btl2cap.service", BTSDP_MCAP_DATA_CHANNEL_PROTOCOL_UUID
, btmcap_handle
);
447 dissector_add_uint("btl2cap.service", BTSDP_HDP_SERVICE_UUID
, btmcap_handle
);
448 dissector_add_uint("btl2cap.service", BTSDP_HDP_SOURCE_SERVICE_UUID
, btmcap_handle
);
449 dissector_add_uint("btl2cap.service", BTSDP_HDP_SINK_SERVICE_UUID
, btmcap_handle
);
452 dissector_add_handle("btl2cap.psm", btmcap_handle
);
453 dissector_add_handle("btl2cap.cid", btmcap_handle
);
457 * Editor modelines - http://www.wireshark.org/tools/modelines.html
462 * indent-tabs-mode: nil
465 * vi: set shiftwidth=4 tabstop=8 expandtab:
466 * :indentSize=4:tabSize=8:noTabs=true: