Wireshark  4.3.0
The Wireshark network protocol analyzer
packet-bluetooth.h
1 /* packet-bluetooth.h
2  *
3  * Wireshark - Network traffic analyzer
4  * By Gerald Combs <gerald@wireshark.org>
5  * Copyright 1998 Gerald Combs
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9 
10 #ifndef __PACKET_BLUETOOTH_H__
11 #define __PACKET_BLUETOOTH_H__
12 
13 #include <epan/wmem_scopes.h>
14 
15 #include "packet-usb.h"
16 #include "packet-ubertooth.h"
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif /* __cplusplus */
21 
22 #define PROTO_DATA_BLUETOOTH_SERVICE_UUID 0
23 
24 #define BLUETOOTH_DATA_SRC 0
25 #define BLUETOOTH_DATA_DST 1
26 
27 #define HCI_H4_TYPE_CMD 0x01
28 #define HCI_H4_TYPE_ACL 0x02
29 #define HCI_H4_TYPE_SCO 0x03
30 #define HCI_H4_TYPE_EVT 0x04
31 #define HCI_H4_TYPE_ISO 0x05
32 
33 #define HCI_OGF_LINK_CONTROL 0x01
34 #define HCI_OGF_LINK_POLICY 0x02
35 #define HCI_OGF_HOST_CONTROLLER 0x03
36 #define HCI_OGF_INFORMATIONAL 0x04
37 #define HCI_OGF_STATUS 0x05
38 #define HCI_OGF_TESTING 0x06
39 #define HCI_OGF_LOW_ENERGY 0x08
40 #define HCI_OGF_LOGO_TESTING 0x3e
41 #define HCI_OGF_VENDOR_SPECIFIC 0x3f
42 
43 #define HCI_VENDOR_DEFAULT 0
44 
45 #define DID_VENDOR_ID_SOURCE_BLUETOOTH_SIG 1
46 #define DID_VENDOR_ID_SOURCE_USB_FORUM 2
47 
48 #define ACCESS_ADDRESS_ADVERTISING 0x8e89bed6
49 
50 extern int proto_bluetooth;
51 
52 extern const value_string bluetooth_address_type_vals[];
53 
54 #define STATUS_SUCCESS 0x00
55 
56 #define UUID_GATT_PRIMARY_SERVICE_DECLARATION 0x2800
57 #define UUID_GATT_SECONDARY_SERVICE_DECLARATION 0x2801
58 #define UUID_GATT_INCLUDE_DECLARATION 0x2802
59 #define UUID_GATT_CHARACTERISTIC_DECLARATION 0x2803
60 
61 /* We support Bluetooth over various interfaces, interface_id and adapter_id
62  is used to decode further payload. Case: there is a host. Host has X
63  interfaces. Each interface has Y adapter. Each adapter has ACL handle or
64  L2CAP CID. ACL handle has L2CAP CID and/or L2CAP PSM. L2CAP CID or
65  L2CAP PSM has RFCOMM channel or other end-protocol like OBEX, AVRCP, HID,
66  AVDTP, BNEP etc. RFCOMM channel has end-protocol like OBEX, HFP, etc.
67  Important note: correct payload decoding should store needed data using
68  key contain interface_id, adapter_id, ..., last_channel_type (for example
69  RFCOMM channel, transaction_id, frame number etc. )
70 
71  interface_id - interface id provided by Wireshark, see "frame.interface_id",
72  in case where is only one interface id HCI_INTERFACE_DEFAULT
73  is used (for example open BTSNOOP file with HCI H4 protocol)
74  adapter_id - identified Bluetooth device (interface, for example Linux
75  hci0, hci1, etc.)
76 */
77 #define HCI_INTERFACE_DEFAULT 0
78 #define HCI_ADAPTER_DEFAULT 0
79 
80 typedef enum {
81  BT_PD_NONE, /* no protocol data */
82  BT_PD_BTHCI, /* struct bthci_phdr * */
83  BT_PD_BTMON, /* struct btmon_phdr * */
84  BT_PD_USB_CONV_INFO, /* usb_conv_info_t * */
85  BT_PD_UBERTOOTH_DATA /* ubertooth_data_t * */
86 } bt_protocol_data_type;
87 
88 /* chandle_sessions: interface_id + adapter_id + connection_handle + frame_number -> connect_in_frame, disconnect_in_frame */
89 /* chandle_to_bdaddr: interface_id + adapter_id + connection_handle + frame_number -> bd_addr[6] */
90 /* chandle_to_mode: interface_id + adapter_id + connection_handle + frame_number -> mode */
91 /* shandle_to_chandle: interface_id + adapter_id + stream_handle + frame_number -> connection_handle */
92 /* bdaddr_to_name: bd_addr[6] + frame_number -> name */
93 /* bdaddr_to_role: bd_addr[6] + frame_number -> role */
94 /* localhost_bdaddr: interface_id + adapter_id + frame_number -> bd_addr[6] */
95 /* localhost_name: interface_id + adapter_id + frame_number -> name */
96 typedef struct _bluetooth_data_t {
97  guint32 interface_id;
98  guint32 adapter_id;
99  guint32 *adapter_disconnect_in_frame;
100  wmem_tree_t *chandle_sessions;
101  wmem_tree_t *chandle_to_bdaddr;
102  wmem_tree_t *chandle_to_mode;
103  wmem_tree_t *shandle_to_chandle;
104  wmem_tree_t *bdaddr_to_name;
105  wmem_tree_t *bdaddr_to_role;
106  wmem_tree_t *localhost_bdaddr;
107  wmem_tree_t *localhost_name;
108  wmem_tree_t *hci_vendors;
109 
110  bt_protocol_data_type previous_protocol_data_type;
111  union {
112  void *none;
113  struct bthci_phdr *bthci;
114  struct btmon_phdr *btmon;
115  usb_conv_info_t *usb_conv_info;
116  ubertooth_data_t *ubertooth_data;
117  } previous_protocol_data;
118 
120 
121 #define BT_LINK_TYPE_UNKNOWN 0
122 #define BT_LINK_TYPE_ACL 1
123 #define BT_LINK_TYPE_SCO 2
124 #define BT_LINK_TYPE_LL 3
125 #define BT_LINK_TYPE_ISO 4
126 
127 typedef struct _chandle_session_t {
128  guint32 connect_in_frame;
129  guint32 disconnect_in_frame;
130  guint32 link_type;
132 
133 typedef struct _remote_bdaddr_t {
134  guint32 interface_id;
135  guint32 adapter_id;
136  guint16 chandle;
137  guint8 bd_addr[6];
139 
140 typedef struct _device_name_t {
141  guint32 bd_addr_oui;
142  guint32 bd_addr_id;
143  gchar *name;
144 } device_name_t;
145 
146 typedef struct _device_role_t {
147  guint32 role;
148  guint32 change_in_frame;
149 } device_role_t;
150 
151 typedef struct _connection_mode_t {
152  gint32 mode;
153  guint32 change_in_frame;
155 
157  gint32 chandle;
158  guint32 change_in_frame;
160 
161 #define ROLE_UNKNOWN 0
162 #define ROLE_CENTRAL 1
163 #define ROLE_PERIPHERAL 2
164 
166  guint32 interface_id;
167  guint32 adapter_id;
168  guint8 bd_addr[6];
170 
171 typedef struct _localhost_name_entry_t {
172  guint32 interface_id;
173  guint32 adapter_id;
174  gchar *name;
176 
177 typedef struct _bluetooth_tap_data_t {
178  guint32 interface_id;
179  guint32 adapter_id;
181 
182 typedef struct _hci_vendor_data_t {
183  guint16 manufacturer;
184  guint16 hci_revision;
185  guint16 lmp_subversion;
186  guint32 change_in_frame;
187  struct _hci_vendor_data_t *previous;
189 
190 typedef struct _uuid_t {
191  guint16 bt_uuid;
192  guint8 size;
193  guint8 data[16];
195 
196 enum bluetooth_device_type {
197  BLUETOOTH_DEVICE_BD_ADDR,
198  BLUETOOTH_DEVICE_NAME,
199  BLUETOOTH_DEVICE_LOCAL_ADAPTER,
200  BLUETOOTH_DEVICE_LOCAL_VERSION,
201  BLUETOOTH_DEVICE_REMOTE_VERSION,
202  BLUETOOTH_DEVICE_RESET,
203  BLUETOOTH_DEVICE_SCAN,
204  BLUETOOTH_DEVICE_VOICE_SETTING,
205  BLUETOOTH_DEVICE_AUTHENTICATION,
206  BLUETOOTH_DEVICE_ENCRYPTION,
207  BLUETOOTH_DEVICE_CLASS_OF_DEVICE,
208  BLUETOOTH_DEVICE_SIMPLE_PAIRING_MODE,
209  BLUETOOTH_DEVICE_PAGE_TIMEOUT,
210  BLUETOOTH_DEVICE_INQUIRY_MODE,
211  BLUETOOTH_DEVICE_MTUS,
212  BLUETOOTH_DEVICE_LE_MTU
213 };
214 
215 typedef struct _bluetooth_device_tap_t {
216  guint32 interface_id;
217  guint32 adapter_id;
218 
219  gboolean is_local;
220  gboolean has_bd_addr;
221  guint8 bd_addr[6];
222  enum bluetooth_device_type type;
223  union {
224  char *name;
225  struct {
226  guint8 hci_version;
227  guint16 hci_revision;
228  guint8 lmp_version;
229  guint16 lmp_subversion;
230  guint16 manufacturer;
231  } local_version;
232  struct {
233  guint8 lmp_version;
234  guint16 lmp_subversion;
235  guint16 manufacturer;
236  } remote_version;
237  guint8 scan;
238  guint16 page_timeout;
239  guint8 authentication;
240  guint8 encryption;
241  guint32 class_of_device;
242  guint16 voice_setting;
243  guint8 simple_pairing_mode;
244  guint8 inquiry_mode;
245  struct {
246  guint16 acl_mtu;
247  guint8 sco_mtu;
248  guint16 acl_packets;
249  guint16 sco_packets;
250  } mtus;
251  struct {
252  guint16 acl_mtu;
253  guint16 iso_mtu;
254  guint16 acl_packets;
255  guint16 iso_packets;
256  } le_mtus;
257  } data;
259 
260 enum bluetooth_hci_summary_type {
261  BLUETOOTH_HCI_SUMMARY_OPCODE,
262  BLUETOOTH_HCI_SUMMARY_EVENT_OPCODE,
263  BLUETOOTH_HCI_SUMMARY_EVENT,
264  BLUETOOTH_HCI_SUMMARY_SUBEVENT,
265  BLUETOOTH_HCI_SUMMARY_VENDOR_OPCODE,
266  BLUETOOTH_HCI_SUMMARY_VENDOR_EVENT_OPCODE,
267  BLUETOOTH_HCI_SUMMARY_VENDOR_EVENT,
268  BLUETOOTH_HCI_SUMMARY_STATUS,
269  BLUETOOTH_HCI_SUMMARY_STATUS_PENDING,
270  BLUETOOTH_HCI_SUMMARY_REASON,
271  BLUETOOTH_HCI_SUMMARY_HARDWARE_ERROR
272 };
273 
275  guint32 interface_id;
276  guint32 adapter_id;
277 
278  guint16 ocf;
279  guint8 ogf;
280  guint8 event;
281  guint8 subevent;
282  guint8 status;
283  guint8 reason;
284  guint8 hardware_error;
285 
286  const gchar *name;
287  enum bluetooth_hci_summary_type type;
289 
290 typedef struct _bluetooth_eir_ad_data_t {
291  guint32 interface_id;
292  guint32 adapter_id;
293 
294  guint8 *bd_addr;
296 
297 
298 extern int bluetooth_device_tap;
299 extern int bluetooth_hci_summary_tap;
300 
301 WS_DLL_PUBLIC const value_string bluetooth_uuid_vals[];
302 
303 extern dissector_table_t bluetooth_uuid_table;
304 
305 WS_DLL_PUBLIC wmem_tree_t *bluetooth_uuids;
306 
307 WS_DLL_PUBLIC value_string_ext bluetooth_uuid_vals_ext;
308 WS_DLL_PUBLIC value_string_ext bluetooth_company_id_vals_ext;
309 extern guint32 bluetooth_max_disconnect_in_frame;
310 
311 extern gint dissect_bd_addr(gint hf_bd_addr, packet_info *pinfo, proto_tree *tree,
312  tvbuff_t *tvb, gint offset, gboolean is_local_bd_addr,
313  guint32 interface_id, guint32 adapter_id, guint8 *bdaddr);
314 
315 extern void bluetooth_unit_1p25_ms(gchar *buf, guint32 value);
316 extern void bluetooth_unit_0p125_ms(gchar *buf, guint32 value);
317 
318 extern bluetooth_uuid_t get_bluetooth_uuid(tvbuff_t *tvb, gint offset, gint size);
319 WS_DLL_PUBLIC const gchar *print_bluetooth_uuid(wmem_allocator_t *pool, bluetooth_uuid_t *uuid);
320 WS_DLL_PUBLIC const gchar *print_numeric_bluetooth_uuid(wmem_allocator_t *pool, bluetooth_uuid_t *uuid);
321 
322 extern void save_local_device_name_from_eir_ad(tvbuff_t *tvb, gint offset,
323  packet_info *pinfo, guint8 size, bluetooth_data_t *bluetooth_data);
324 
325 WS_DLL_PUBLIC bluetooth_data_t *
326 dissect_bluetooth_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
327 
328 #ifdef __cplusplus
329 }
330 #endif /* __cplusplus */
331 
332 #endif
333 
334 /*
335  * Editor modelines - https://www.wireshark.org/tools/modelines.html
336  *
337  * Local variables:
338  * c-basic-offset: 4
339  * tab-width: 8
340  * indent-tabs-mode: nil
341  * End:
342  *
343  * vi: set shiftwidth=4 tabstop=8 expandtab:
344  * :indentSize=4:tabSize=8:noTabs=true:
345  */
Definition: packet-bluetooth.h:96
Definition: packet-bluetooth.h:215
Definition: packet-bluetooth.h:290
Definition: packet-bluetooth.h:274
Definition: packet-bluetooth.h:177
Definition: packet-bluetooth.h:127
Definition: packet-bluetooth.h:151
Definition: packet-bluetooth.h:140
Definition: packet-bluetooth.h:146
Definition: packet-bluetooth.h:182
Definition: packet-bluetooth.h:165
Definition: packet-bluetooth.h:171
Definition: packet_info.h:44
Definition: proto.h:904
Definition: packet-bluetooth.h:133
Definition: packet-bluetooth.h:156
Definition: packet-ubertooth.h:17
Definition: packet-usb.h:114
Definition: packet-bluetooth.h:190
Definition: value_string.h:170
Definition: value_string.h:26
Definition: wmem_allocator.h:27
Definition: wmem_tree-int.h:48
Definition: wtap.h:1051
Definition: wtap.h:1063
Definition: packet.c:86
Definition: tvbuff-int.h:35