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