| BLUETOOTH(4) | Device Drivers Manual | BLUETOOTH(4) |
bluetooth —
#include <netbt/bluetooth.h>
#include <netbt/hci.h>
#include <netbt/l2cap.h>
#include <netbt/rfcomm.h>
struct sockaddr_bt {
uint8_t bt_len;
sa_family_t bt_family;
bdaddr_t bt_bdaddr;
uint16_t bt_psm;
uint8_t bt_channel;
};
The local address used by the socket can be set with bind(2).
BTPROTO_HCIBDADDR_ANY is specified then the socket will
receive packets from all devices on the system.
connect(2) may be used to
create connections such that packets sent with
send(2) will be delivered to
the specified device, otherwise
sendto(2) should be used.
The bt_psm and bt_channel fields in the sockaddr_bt structure are ignored by HCI protocol code and should be set to zero.
HCI socket options:
SO_HCI_EVT_FILTER
[struct hci_filter]<netbt/hci.h> for
available events. By default, Command_Complete and Command_Status
events only are enabled.SO_HCI_PKT_FILTER
[struct hci_filter]SO_HCI_DIRECTION
[int]HCI sysctl(8) controls:
net.bluetooth.hci.sendspacenet.bluetooth.hci.recvspacenet.bluetooth.hci.acl_expirynet.bluetooth.hci.memo_expirynet.bluetooth.hci.eventq_maxnet.bluetooth.hci.aclrxq_maxnet.bluetooth.hci.scorxq_maxBTPROTO_L2CAPL2CAP_PSM_ANY is bound when the
listen(2) call is made, the
next available PSM from the dynamic range above 0x1001 will be selected
and may be discovered using the
getsockname(2) call.
L2CAP socket options:
SO_L2CAP_IMTU
[uint16_t]SO_L2CAP_OMTU
[uint16_t]SO_L2CAP_LM
[int]L2CAP_LM_AUTHL2CAP_LM_ENCRYPTL2CAP_LM_SECURELink mode settings will be applied to the baseband link
during L2CAP connection establishment. If the L2CAP connection is
already established, EINPROGRESS may be
returned, and it is not possible to guarantee that data already
queued (from either end) will not be delivered. If the mode change
fails, the L2CAP connection will be aborted.
L2CAP sysctl(8) controls:
net.bluetooth.l2cap.sendspacenet.bluetooth.l2cap.recvspacenet.bluetooth.l2cap.rtxnet.bluetooth.l2cap.ertxBTPROTO_RFCOMMRFCOMM_CHANNEL_ANY is bound, when the
listen(2) call is made, the
first unused channel for the relevant bdaddr will be allocated and may be
discovered using the
getsockname(2) call. If
no PSM is specified, a default value of
L2CAP_PSM_RFCOMM (0x0003) will be used.
RFCOMM socket options:
SO_RFCOMM_MTU
[uint16_t]SO_RFCOMM_LM
[int]RFCOMM_LM_AUTHRFCOMM_LM_ENCRYPTRFCOMM_LM_SECURELink mode settings will be applied to the baseband link
during RFCOMM connection establishment. If the RFCOMM connection is
already established, EINPROGRESS may be
returned, and it is not possible to guarantee that data already
queued (from either end) will not be delivered. If the mode change
fails, the RFCOMM connection will be aborted.
RFCOMM sysctl(8) controls:
net.bluetooth.rfcomm.sendspacenet.bluetooth.rfcomm.recvspacenet.bluetooth.rfcomm.default_mtunet.bluetooth.ack_timeoutnet.bluetooth.mcc_timeoutBTPROTO_SCOSCO socket options:
SO_SCO_MTU
[uint16_t]SO_SCO_HANDLE
[uint16_t]SCO sysctl(8) controls:
net.bluetooth.sco.sendspacenet.bluetooth.sco.recvspaceBTPROTO_HCI sockets. All of the requests take a
btreq structure defined as follows as their parameter
and unless otherwise specified, use the btr_name field
to identify the device.
struct btreq {
char btr_name[HCI_DEVNAME_SIZE]; /* device name */
union {
struct {
bdaddr_t btri_bdaddr; /* device bdaddr */
uint16_t btri_flags; /* flags */
uint16_t btri_num_cmd; /* # of free cmd buffers */
uint16_t btri_num_acl; /* # of free ACL buffers */
uint16_t btri_num_sco; /* # of free SCO buffers */
uint16_t btri_acl_mtu; /* ACL mtu */
uint16_t btri_sco_mtu; /* SCO mtu */
uint16_t btri_link_policy; /* Link Policy */
uint16_t btri_packet_type; /* Packet Type */
uint16_t btri_max_acl; /* max ACL buffers */
uint16_t btri_max_sco; /* max SCO buffers */
} btri;
struct {
uint8_t btrf_page0[HCI_FEATURES_SIZE]; /* basic */
uint8_t btrf_page1[HCI_FEATURES_SIZE]; /* extended page 1 */
uint8_t btrf_page2[HCI_FEATURES_SIZE]; /* extended page 2 */
} btrf;
struct bt_stats btrs; /* unit stats */
} btru;
};
#define btr_flags btru.btri.btri_flags
#define btr_bdaddr btru.btri.btri_bdaddr
#define btr_num_cmd btru.btri.btri_num_cmd
#define btr_num_acl btru.btri.btri_num_acl
#define btr_num_sco btru.btri.btri_num_sco
#define btr_acl_mtu btru.btri.btri_acl_mtu
#define btr_sco_mtu btru.btri.btri_sco_mtu
#define btr_link_policy btru.btri.btri_link_policy
#define btr_packet_type btru.btri.btri_packet_type
#define btr_max_acl btru.btri.btri_max_acl
#define btr_max_sco btru.btri.btri_max_sco
#define btr_features0 btru.btrf.btrf_page0
#define btr_features1 btru.btrf.btrf_page1
#define btr_features2 btru.btrf.btrf_page2
#define btr_stats btru.btrs
/* btr_flags */
#define BTF_UP (1<<0) /* unit is up */
#define BTF_RUNNING (1<<1) /* unit is running */
#define BTF_XMIT_CMD (1<<2) /* transmitting CMD packets */
#define BTF_XMIT_ACL (1<<3) /* transmitting ACL packets */
#define BTF_XMIT_SCO (1<<4) /* transmitting SCO packets */
#define BTF_INIT_BDADDR (1<<5) /* waiting for bdaddr */
#define BTF_INIT_BUFFER_SIZE (1<<6) /* waiting for buffer size */
#define BTF_INIT_FEATURES (1<<7) /* waiting for features */
#define BTF_NOOP_ON_RESET (1<<8) /* wait for No-op on reset */
#define BTF_INIT_COMMANDS (1<<9) /* waiting for supported commands */
#define BTF_MASTER (1<<10) /* request Master role */
struct bt_stats {
uint32_t err_tx;
uint32_t err_rx;
uint32_t cmd_tx;
uint32_t evt_rx;
uint32_t acl_tx;
uint32_t acl_rx;
uint32_t sco_tx;
uint32_t sco_rx;
uint32_t byte_tx;
uint32_t byte_rx;
};
SIOCGBTINFOSIOCGBTINFOASIOCNBTINFOENXIO. Thus, you can cycle through all devices in
the system.SIOCSBTFLAGSSIOCGBTFEATSIOCSBTPOLICY<netbt/hci.h>, though you
can only set bits that the device supports.SIOCSBTPTYPESIOCGBTSTATSSIOCZBTSTATSOnly the super-user may change device configurations.
| November 20, 2010 | NetBSD 10.0 |