1 // Copyright 2016 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #pragma once
6 
7 // clang-format off
8 
9 #include <stdint.h>
10 #include <zircon/device/ioctl.h>
11 #include <zircon/device/ioctl-wrapper.h>
12 
13 __BEGIN_CDECLS
14 
15 // Potential values for the flags bitfield in a snoop channel packet.
16 typedef uint32_t bt_hci_snoop_type_t;
17 #define BT_HCI_SNOOP_TYPE_CMD ((bt_hci_snoop_type_t)0)
18 #define BT_HCI_SNOOP_TYPE_EVT ((bt_hci_snoop_type_t)1)
19 #define BT_HCI_SNOOP_TYPE_ACL ((bt_hci_snoop_type_t)2)
20 #define BT_HCI_SNOOP_TYPE_SCO ((bt_hci_snoop_type_t)3)
21 
22 #define BT_HCI_SNOOP_FLAG_RECV 0x04 // Host -> Controller
23 
bt_hci_snoop_flags(bt_hci_snoop_type_t type,bool is_received)24 static inline uint8_t bt_hci_snoop_flags(bt_hci_snoop_type_t type, bool is_received) {
25   return (uint8_t)(type | (is_received ? BT_HCI_SNOOP_FLAG_RECV : 0x00));
26 }
27 
28 // Get a channel handle for a two-way HCI command channel for sending and
29 // receiving HCI command and event packets, respectively.
30 //   in: none
31 //   out: handle to channel
32 #define IOCTL_BT_HCI_GET_COMMAND_CHANNEL \
33     IOCTL(IOCTL_KIND_GET_HANDLE, IOCTL_FAMILY_BT_HCI, 0)
34 
35 // Get a channel handle for a two-way HCI ACL data channel for sending and receiving HCI ACL data
36 // packets.
37 //   in: none
38 //   out: handle to channel
39 #define IOCTL_BT_HCI_GET_ACL_DATA_CHANNEL \
40     IOCTL(IOCTL_KIND_GET_HANDLE, IOCTL_FAMILY_BT_HCI, 1)
41 
42 // Get a uni-directional channel for sniffing HCI traffic. The format of each message is as follows:
43 //
44 //    [1-octet flags][n-octet payload]
45 //
46 // The flags octet is a bitfield with the following values defined:
47 //
48 //     - 0x00: The payload represents a command packet sent from the host to the
49 //             controller.
50 //     - 0x01: The payload represents an event packet sent by the controller.
51 //
52 // IOCTL parameters:
53 //   in: none
54 //   out: handle to channel
55 #define IOCTL_BT_HCI_GET_SNOOP_CHANNEL \
56     IOCTL(IOCTL_KIND_GET_HANDLE, IOCTL_FAMILY_BT_HCI, 2)
57 
58 // ssize_t ioctl_bt_hci_get_command_channel(int fd, zx_handle_t* out);
59 IOCTL_WRAPPER_OUT(ioctl_bt_hci_get_command_channel, IOCTL_BT_HCI_GET_COMMAND_CHANNEL, zx_handle_t);
60 
61 // ssize_t ioctl_bt_hci_get_acl_data_channel(int fd, zx_handle_t* out);
62 IOCTL_WRAPPER_OUT(ioctl_bt_hci_get_acl_data_channel, IOCTL_BT_HCI_GET_ACL_DATA_CHANNEL, zx_handle_t);
63 
64 // ssize_t ioctl_bt_hci_get_snoop_channel(int fd, zx_handle_t* out);
65 IOCTL_WRAPPER_OUT(ioctl_bt_hci_get_snoop_channel, IOCTL_BT_HCI_GET_SNOOP_CHANNEL, zx_handle_t);
66 
67 // TODO(jamuraa): Add ioctl for SCO
68 
69 __END_CDECLS
70