xref: /freebsd/share/man/man4/ng_btsocket.4 (revision 57bd0fc6e89b888516b6a64206715bef500fc2d1)
1.\" Copyright (c) 2001-2002 Maksim Yevmenkin <m_evmenkin@yahoo.com>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" $FreeBSD$
26.\"
27.Dd July 8, 2002
28.Dt NG_BTSOCKET 4
29.Os
30.Sh NAME
31.Nm ng_btsocket
32.Nd Bluetooth sockets layer
33.Sh SYNOPSIS
34.In sys/types.h
35.In sys/socket.h
36.In bitstring.h
37.In netgraph.h
38.In ng_hci.h
39.In ng_l2cap.h
40.In ng_btsocket.h
41.Sh DESCRIPTION
42The
43.Nm
44module implements three Netgraph node types.
45Each type in its turn implements one protocol within
46.Dv PF_BLUETOOTH
47domain.
48.Sh Dv BLUETOOTH_PROTO_HCI Sh protocol
49.Ss Dv SOCK_RAW Ss HCI sockets
50Implemented by
51.Nm btsock_hci_raw
52Netgraph type.
53Raw HCI sockets allow sending of raw HCI command datagrams
54only to correspondents named in
55.Xr send 2
56calls.
57Raw HCI datagrams (HCI commands, events and data) are generally received with
58.Xr recvfrom 2 ,
59which returns the next datagram with its return address.
60Raw HCI sockets can also be used to control HCI nodes.
61.Pp
62The Bluetooth raw HCI socket address is defined as follows:
63.Bd -literal -offset indent
64/* Bluetooth version of struct sockaddr for raw HCI sockets */
65struct sockaddr_hci {
66        u_char	hci_len;      /* total length */
67        u_char	hci_family;   /* address family */
68	char	hci_node[16]; /* HCI node name */
69};
70.Ed
71.Pp
72Raw HCI sockets support number of
73.Xr ioctl 2
74requests such as:
75.Bl -tag -width indent
76.It Dv SIOC_HCI_RAW_NODE_GET_STATE
77Returns current state for the HCI node.
78.It Dv SIOC_HCI_RAW_NODE_INIT
79Turn on
80.Dq inited
81bit for the HCI node.
82.It Dv SIOC_HCI_RAW_NODE_GET_DEBUG
83Returns current debug level for the HCI node.
84.It Dv SIOC_HCI_RAW_NODE_SET_DEBUG
85Sets current debug level for the HCI node.
86.It Dv SIOC_HCI_RAW_NODE_GET_BUFFER
87Returns current state of data buffers for the HCI node.
88.It Dv SIOC_HCI_RAW_NODE_GET_BDADDR
89Returns BD_ADDR for the HCI node.
90.It Dv SIOC_HCI_RAW_NODE_GET_FEATURES
91Returns the list of features supported by hardware for the HCI node.
92.It Dv SIOC_HCI_RAW_NODE_GET_STAT
93Returns various statistic counters for the HCI node.
94.It Dv SIOC_HCI_RAW_NODE_RESET_STAT
95Resets all statistic counters for the HCI node to zero.
96.It Dv SIOC_HCI_RAW_NODE_FLUSH_NEIGHBOR_CACHE
97Remove all neighbor cache entries for the HCI node.
98.It Dv SIOC_HCI_RAW_NODE_GET_NEIGHBOR_CACHE
99Returns content of the neighbor cache for the HCI node.
100.It Dv SIOC_HCI_RAW_NODE_GET_CON_LIST
101Returns list of active baseband connections (i.e. ACL and SCO links) for
102the HCI node.
103.It SIOC_HCI_RAW_NODE_GET_LINK_POLICY_MASK
104Returns current link policy settings mask for the HCI node.
105.It SIOC_HCI_RAW_NODE_SET_LINK_POLICY_MASK
106Sets current link policy settings mask for the HCI node.
107.It SIOC_HCI_RAW_NODE_GET_PACKET_MASK
108Returns current packet mask for the HCI node.
109.It SIOC_HCI_RAW_NODE_SET_PACKET_MASK
110Sets current packet mask for the HCI node.
111.El
112.Pp
113Raw HCI sockets support filters.
114The application can filter certain HCI datagram types.
115For HCI event datagrams the application can set additional filter.
116The raw HCI socket filter defined as follows:
117.Bd -literal -offset indent
118/*
119 * Raw HCI socket filter.
120 *
121 * For packet mask use (1 << (HCI packet indicator - 1))
122 * For event mask use (1 << (Event - 1))
123 */
124
125struct ng_btsocket_hci_raw_filter {
126        bitstr_t bit_decl(packet_mask, 32);
127        bitstr_t bit_decl(event_mask, (NG_HCI_EVENT_MASK_SIZE * 8));
128};
129.Ed
130.Pp
131The
132.Dv SO_HCI_RAW_FILTER
133option defined at
134.Dv SOL_HCI_RAW
135level can be used to obtain via
136.Xr getsockopt 2
137or change via
138.Xr setsockopt 2
139raw HCI socket's filter.
140.Sh Dv BLUETOOTH_PROTO_L2CAP Sh protocol
141The Bluetooth L2CAP socket address is defined as follows:
142.Bd -literal -offset indent
143/* Bluetooth version of struct sockaddr for L2CAP sockets */
144struct sockaddr_l2cap {
145        u_char    l2cap_len;    /* total length */
146        u_char    l2cap_family; /* address family */
147        u_int16_t l2cap_psm;    /* Protocol/Service Multiplexor */
148        bdaddr_t  l2cap_bdaddr; /* address */
149};
150.Ed
151.Ss Dv SOCK_RAW Ss L2CAP sockets
152Implemented by
153.Nm btsock_l2c_raw
154Netgraph type.
155Raw L2CAP sockets do not provide access to raw L2CAP datagrams.
156These
157sockets used to control L2CAP nodes and to issue special L2CAP requests
158such as
159.Dv ECHO_REQUEST
160and
161.Dv GET_INFO
162request.
163.Pp
164Raw L2CAP sockets support number of
165.Xr ioctl 2
166requests such as:
167.Bl -tag -width indent
168.It Dv SIOC_L2CAP_NODE_GET_FLAGS
169Returns current state for the L2CAP node.
170.It Dv SIOC_L2CAP_NODE_GET_DEBUG
171Returns current debug level for the L2CAP node.
172.It Dv SIOC_L2CAP_NODE_SET_DEBUG
173Sets current debug level for the L2CAP node.
174.It Dv SIOC_L2CAP_NODE_GET_CON_LIST
175Returns list of active baseband connections (i.e. ACL links) for the L2CAP
176node.
177.It Dv SIOC_L2CAP_NODE_GET_CHAN_LIST
178Returns list of active channels for the L2CAP node.
179.It Dv SIOC_L2CAP_L2CA_PING
180Issues L2CAP
181.Dv ECHO_REQUEST .
182.It Dv SIOC_L2CAP_L2CA_GET_INFO
183Issues L2CAP
184.Dv GET_INFO
185request.
186.El
187.Ss Dv SOCK_SEQPACKET Ss L2CAP sockets
188Implemented by
189.Nm btsock_l2c
190Netgraph type.
191L2CAP sockets are either
192.Dq active
193or
194.Dq passive .
195Active sockets initiate connections to passive sockets.
196By default L2CAP sockets are created active; to create a passive socket the
197.Xr listen 2
198system call must be used after binding the socket with the
199.Xr bind 2
200system call.
201Only passive sockets may use the
202.Xr accept 2
203call to accept incoming connections.
204Only active sockets may use the
205.Xr connect 2
206call to initiate connections.
207.Pp
208L2CAP sockets support
209.Dq "wildcard addressing" .
210In this case, socket must be bound to
211.Dv NG_HCI_BDADDR_ANY
212address.
213Note that PSM (Protocol/Service Multiplexor) filed is always
214required.
215Once a connection has been established the socket's address is
216fixed by the peer entity's location.
217The address assigned the socket is
218the address associated with the Bluetooth device through which packets are
219being transmitted and received, and PSM (Protocol/Service Multiplexor).
220.Pp
221L2CAP sockets support number of options defined at
222.Dv SOL_L2CAP
223level which can be set with
224.Xr setsockopt 2
225and tested with
226.Xr getsockopt 2 :
227.Bl -tag -width indent
228.It Dv SO_L2CAP_IMTU
229Get (set) maximum payload size the local socket is capable of accepting.
230.It Dv SO_L2CAP_OMTU
231Get maximum payload size the remote socket is capable of accepting.
232.It Dv SO_L2CAP_IFLOW
233Get incoming flow specification for the socket.
234.Bf -emphasis
235Not implemented.
236.Ef
237.It Dv SO_L2CAP_OFLOW
238Get (set) outgoing flow specification for the socket.
239.Bf -emphasis
240Not implemented.
241.Ef
242.It Dv SO_L2CAP_FLUSH
243Get (set) value of the flush timeout.
244.Bf -emphasis
245Not implemented.
246.Ef
247.El
248.Sh HOOKS
249This node type supports hooks with arbitrary names (as long as they are
250unique) and always accepts hook connection requests.
251.Sh NETGRAPH CONTROL MESSAGES
252This node type supports the generic control messages.
253.Sh SHUTDOWN
254These nodes are persistent and cannot be shut down.
255.Sh BUGS
256Most likely.
257Please report if found.
258.Sh SEE ALSO
259.Xr btsockstat 1 ,
260.Xr socket 2 ,
261.Xr netgraph 4 ,
262.Xr ng_hci 4 ,
263.Xr ng_l2cap 4 ,
264.Xr ngctl 8
265.Sh HISTORY
266The
267.Nm btsock_hci_raw , btsock_l2c_raw ,
268and
269.Nm btsock_l2c
270node types were implemented in
271.Fx 5.0 .
272.Sh AUTHORS
273.An Maksim Yevmenkin Aq m_evmenkin@yahoo.com
274