hci − Bluetooth HCI protocol
#include
<sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
hci_socket = socket(PF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
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.
struct
sockaddr_hci {
sa_family_t hci_family;
unsigned short hci_dev;
unsigned short hci_channel;
};
Possible values for hci_channel:
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;
The socket options listed below can be set by using setsockopt(2) and read with getsockopt(2) with the socket level set to SOL_BLUETOOTH or SOL_HCI (HCI_FILTER).
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));
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));
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);
<http://www.bluez.org>
<linux−[email protected]>
socket(7)
Free use of this software is granted under the terms of the GNU Lesser General Public Licenses (LGPL).