BLUETOOTH(9) | Kernel Developer's Manual | BLUETOOTH(9) |
BLUETOOTH
—
#include <netbt/bluetooth.h>
#include <netbt/hci.h>
#include <netbt/l2cap.h>
#include <netbt/rfcomm.h>
struct hci_unit *
hci_attach
(const
struct hci_if *hci_if,
device_t dev,
uint16_t flags);
void
hci_detach
(struct
hci_unit *unit);
void
hci_input_event
(struct
hci_unit *unit, struct
mbuf *m);
void
hci_input_acl
(struct
hci_unit *unit, struct
mbuf *m);
void
hci_input_sco
(struct
hci_unit *unit, struct
mbuf *m);
int
btproto_attach
(btproto_handle
*, const struct btproto
*proto, void
*ref);
int
btproto_bind
(btproto_handle,
struct sockaddr_bt
*addr);
int
btproto_sockaddr
(btproto_handle,
struct sockaddr_bt
*addr);
int
btproto_connect
(btproto_handle,
struct sockaddr_bt
*addr);
int
btproto_peeraddr
(btproto_handle,
struct sockaddr_bt
*addr);
int
btproto_disconnect
(btproto_handle,
int linger);
int
btproto_detach
(btproto_handle
*);
int
btproto_listen
(btproto_handle);
int
btproto_send
(btproto_handle,
struct mbuf *mbuf);
int
btproto_rcvd
(btproto_handle,
size_t space);
int
btproto_setopt
(btproto_handle,
int optarg,
void *arg);
int
btproto_getopt
(btproto_handle,
int optarg,
void *arg);
<netbt/hci.h>
containing the
driver information as follows:
struct hci_if { int (*enable)(device_t); void (*disable)(device_t); void (*output_cmd)(device_t, struct mbuf *); void (*output_acl)(device_t, struct mbuf *); void (*output_sco)(device_t, struct mbuf *); void (*get_stats)(device_t, struct bt_stats *, int); int ipl; };
Statistics counters should be updated by the device after packets have been transmitted or received, or when errors occur.
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; };
Bluetooth Protocol layers attaching above the Bluetooth Protocol
Stack will make use of the struct btproto data type,
which is defined in
<netbt/bluetooth.h>
and
contains the following function callbacks which should be initialized by the
protocol layer before attaching to the protocol which it uses:
struct btproto { void (*connecting)(void *); void (*connected)(void *); void (*disconnected)(void *, int); void *(*newconn)(void *, struct sockaddr_bt *, struct sockaddr_bt *); void (*complete)(void *, int); void (*linkmode)(void *, int); void (*input)(void *, struct mbuf *); };
hci_attach
(hci_if,
dev)BTF_xxxx
flag in the flags
argument.
hci_attach
() will return a
struct hci_unit handle to be passed to the
protocol stack in other calls.
hci_detach
(unit)hci_input_event
(unit,
mbuf)hci_input_acl
(unit,
mbuf)hci_input_sco
(unit,
mbuf)(*enable)
(dev)(*disable)
(dev)(*output_cmd)
(dev,
mbuf)(*output_acl)
(dev,
mbuf)(*output_sco)
(dev,
mbuf)hci_complete_sco
() call.(*get_stats)
(dev,
dest, flush)The following function definitions are related to the Bluetooth
Protocol API. Note that the "btproto" prefix is representative
only, the protocol being used will have a more specific prefix with
prototypes being declared in the appropriate
<netbt/btproto.h>
file.
btproto_attach
(handle_ptr,
proto, ref)btproto_bind
(handle,
addr)btproto_sockaddr
(handle,
addr)btproto_connect
(handle,
addr)proto->connected
() or
proto->disconnected
(), and optionally
proto->connecting
() with the appropriate
reference as given to btproto_attach
().btproto_peeraddr
(handle,
addr)btproto_disconnect
(handle,
linger)proto->disconnected
() with the appropriate
reference when the connection is torn down. If linger is zero, the
disconnection will be initiated immediately and any outstanding data may
be lost.btproto_detach
(handle_ptr)btproto_listen
(handle)proto->newconn
() function when incoming
connections are detected.btproto_send
(handle,
mbuf)btproto_rcvd
(handle,
space)btproto_setopt
(handle,
optarg, arg)btproto_getopt
(handle,
optarg, arg)(*connecting)
(ref)(*connected)
(ref)(*disconnected)
(ref,
error)*(*newconn)
(ref,
laddr, raddr)(*complete)
(ref,
count)(*linkmode)
(ref,
mode)(*input)
(ref,
mbuf)The Bluetooth Device API as described above is contained in the sys/netbt/hci_unit.c file.
For examples of the Bluetooth Protocol API see the interaction between the L2CAP upper layer in sys/netbt/l2cap_upper.c and either the L2CAP socket layer in sys/netbt/l2cap_socket.c or the bthidev(4) pseudo-device in sys/dev/bluetooth/bthidev.c.
Also, the RFCOMM upper layer in sys/netbt/rfcomm_upper.c and the RFCOMM socket layer in sys/netbt/rfcomm_socket.c.
November 20, 2007 | NetBSD 9.2 |