hci(7) Linux System Administration hci(7)

# [Name](#Name)

hci - Bluetooth HCI protocol

# [SYNOPSIS](#SYNOPSIS)

```
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
hci_socket = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
```

# [DESCRIPTION](#DESCRIPTION)

Bluetooth Host Controller Interface (HCI) is the standard protocol to communicate with Bluetooth adapters. HCI protocol provides a uniform command method for the Host to access Controller capabilities and to control connections to other Controllers.

# [SOCKET ADDRESS](#SOCKET_ADDRESS)

```
struct sockaddr_hci {


    sa_family_t    hci_family;


    unsigned short hci_dev;


    unsigned short hci_channel;
};
```

Possible values for hci\_channel:

Define Value Description **HCI\_CHANNEL\_RAW** 0x00 Raw channel - Used for raw HCI communication **HCI\_CHANNEL\_USER** 0x01 User channel - Used for userspace HCI communication (disables kernel processing) **HCI\_CHANNEL\_MONITOR** 0x02 Monitor channel - Used for monitoring HCI traffic ([btmon(1)](/man/os/bluez/btmon.1)) **HCI\_CHANNEL\_CONTROL** 0x03 Control channel - Used to manage local adapters ([bluetoothd(7)](/man/os/bluez/bluetoothd.7)) **HCI\_CHANNEL\_LOGGING** 0x04 Logging channel - Used to inject logging messages ([bluetoothd(7)](/man/os/bluez/bluetoothd.7))

Example:

```
struct sockaddr_hci addr;
memset(&addr, 0, sizeof(addr));
addr.hci_family = AF_BLUETOOTH;
addr.hci_dev = HCI_DEV_NONE;
addr.hci_channel = HCI_CHANNEL_CONTROL;
```

# [SOCKET OPTIONS](#SOCKET_OPTIONS)

The socket options listed below can be set by using [**setsockopt(2)**](/man/os/bluez/setsockopt.2) and read with [**getsockopt(2)**](/man/os/bluez/getsockopt.2) with the socket level set to SOL\_BLUETOOTH or SOL\_HCI (HCI\_FILTER).

## [HCI\_FILTER (since Linux 2.6)](#HCI_FILTER_%28since_Linux_2.6%29)

Filter by HCI events, requires hci\_channel to be set to HCI\_CHANNEL\_RAW, possible values:

```
struct hci_filter {


    uint32_t type_mask;


    uint32_t event_mask[2];


    uint16_t opcode;
};
```

Example:

```
struct hci_filter flt;
memset(&flt, 0, sizeof(flt));
flt.type_mask = 1 << BT_H4_EVT_PKT;
flt.event_mask[0] = 0xffffffff;
flt.event_mask[1] = 0xffffffff;
setsockopt(fd, SOL_HCI, HCI_FILTER, &flt, sizeof(flt));
```

## [BT\_SNDBUF (since Linux 5.16)](#BT_SNDBUF_%28since_Linux_5.16%29)

Set send buffer size, requires hci\_channel to be set to HCI\_CHANNEL\_MONITOR, HCI\_CHANNEL\_CONTROL or HCI\_CHANNEL\_LOGGING.

Default value is 1028.

Example:

```
uint16_t mtu = UINT16_MAX;
int err;
err = setsockopt(fd, SOL_BLUETOOTH, BT_SNDMTU, &mtu, sizeof(mtu));
```

## [BT\_RCVBUF (since Linux 5.16)](#BT_RCVBUF_%28since_Linux_5.16%29)

Set receive buffer size, requires hci\_channel to be set to HCI\_CHANNEL\_MONITOR, HCI\_CHANNEL\_CONTROL or HCI\_CHANNEL\_LOGGING.

Default value is 1028.

Example:

```
uint16_t mtu;
socklen_t len;
int err;
len = sizeof(mtu);
err = getsockopt(sock, SOL_BLUETOOTH, BT_RCVMTU, mtu, &len);
```

# [RESOURCES](#RESOURCES)

&lt;http://www.bluez.org&gt;

# [REPORTING BUGS](#REPORTING_BUGS)

&lt;linux-bluetooth@vger.kernel.org&gt;

# [SEE ALSO](#SEE_ALSO)

[socket(7)](/man/os/bluez/socket.7)

# [Copyright](#Copyright)

Free use of this software is granted under the terms of the GNU Lesser General Public Licenses (LGPL).

October 2024 BlueZ

---

Document: hci(7) from bluez 5.87-r3 (Chainguard OS)
Source: https://github.com/bluez/bluez
