xref: /freebsd/share/man/man4/ng_hci.4 (revision e0c4386e)
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.\" $Id: ng_hci.4,v 1.3 2003/05/21 19:37:35 max Exp $
26.\"
27.Dd June 25, 2002
28.Dt NG_HCI 4
29.Os
30.Sh NAME
31.Nm ng_hci
32.Nd Netgraph node type that is also a Bluetooth Host Controller Interface
33(HCI) layer
34.Sh SYNOPSIS
35.In sys/types.h
36.In netgraph/bluetooth/include/ng_hci.h
37.Sh DESCRIPTION
38The
39.Nm hci
40node type is a Netgraph node type that implements Bluetooth Host Controller
41Interface (HCI) layer as per chapter H1 of the Bluetooth Specification Book
42v1.1.
43.Sh INTRODUCTION TO BLUETOOTH
44Bluetooth is a short-range radio link intended to replace the cable(s)
45connecting portable and/or fixed electronic devices.
46Bluetooth operates in the unlicensed ISM band at 2.4 GHz.
47The Bluetooth protocol uses a
48combination of circuit and packet switching.
49Bluetooth can support an
50asynchronous data channel, up to three simultaneous synchronous voice
51channels, or a channel which simultaneously supports asynchronous data
52and synchronous voice.
53Each voice channel supports a 64 kb/s synchronous
54(voice) channel in each direction.
55The asynchronous channel can support
56maximal 723.2 kb/s asymmetric (and still up to 57.6 kb/s in the return
57direction), or 433.9 kb/s symmetric.
58.Pp
59The Bluetooth system provides a point-to-point connection (only two
60Bluetooth units involved), or a point-to-multipoint connection.
61In the point-to-multipoint connection,
62the channel is shared among several Bluetooth units.
63Two or more units sharing the same channel form a
64.Dq piconet .
65One Bluetooth unit acts as the master of the piconet, whereas the other
66unit(s) acts as slave(s).
67Up to seven slaves can be active in the piconet.
68In addition, many more slaves can remain locked to the master in a so-called
69parked state.
70These parked slaves cannot be active on the channel, but remain
71synchronized to the master.
72Both for active and parked slaves, the channel
73access is controlled by the master.
74.Pp
75Multiple piconets with overlapping coverage areas form a
76.Dq scatternet .
77Each piconet can only have a single master.
78However, slaves can participate
79in different piconets on a time-division multiplex basis.
80In addition, a master in one piconet can be a slave in another piconet.
81The piconets shall not be frequency-synchronized.
82Each piconet has its own hopping channel.
83.Ss Time Slots
84The channel is divided into time slots, each 625 usec in length.
85The time
86slots are numbered according to the Bluetooth clock of the piconet master.
87The slot numbering ranges from 0 to 2^27 -1 and is cyclic with a cycle length
88of 2^27.
89In the time slots, master and slave can transmit packets.
90.Ss SCO Link
91The SCO link is a symmetric, point-to-point link between the master and a
92specific slave.
93The SCO link reserves slots and can therefore be considered
94as a circuit-switched connection between the master and the slave.
95The SCO link typically supports time-bounded information like voice.
96The master can
97support up to three SCO links to the same slave or to different slaves.
98A slave can support up to three SCO links from the same master, or two SCO
99links if the links originate from different masters.
100SCO packets are never retransmitted.
101.Ss ACL Link
102In the slots not reserved for SCO links, the master can exchange packets
103with any slave on a per-slot basis.
104The ACL link provides a packet-switched
105connection between the master and all active slaves participating in the
106piconet.
107Both asynchronous and isochronous services are supported.
108Between a master and a slave only a single ACL link can exist.
109For most ACL packets,
110packet retransmission is applied to assure data integrity.
111.Sh HOST CONTROLLER INTERFACE (HCI)
112The HCI provides a command interface to the baseband controller and link
113manager, and access to hardware status and control registers.
114This interface
115provides a uniform method of accessing the Bluetooth baseband capabilities.
116.Pp
117The HCI layer on the Host exchanges data and commands with the HCI firmware
118on the Bluetooth hardware.
119The Host Controller Transport Layer (i.e., physical
120bus) driver provides both HCI layers with the ability to exchange information
121with each other.
122.Pp
123The Host will receive asynchronous notifications of HCI events independent
124of which Host Controller Transport Layer is used.
125HCI events are used for
126notifying the Host when something occurs.
127When the Host discovers that an
128event has occurred it will then parse the received event packet to determine
129which event occurred.
130The next sections specify the HCI packet formats.
131.Ss HCI Command Packet
132.Bd -literal -offset indent
133#define NG_HCI_CMD_PKT 0x01
134typedef struct {
135        uint8_t  type;   /* MUST be 0x1 */
136        uint16_t opcode; /* OpCode */
137        uint8_t  length; /* parameter(s) length in bytes */
138} __attribute__ ((packed)) ng_hci_cmd_pkt_t;
139.Ed
140.Pp
141The HCI command packet is used to send commands to the Host Controller
142from the Host.
143When the Host Controller completes most of the commands,
144a Command Complete event is sent to the Host.
145Some commands do not receive
146a Command Complete event when they have been completed.
147Instead, when the
148Host Controller receives one of these commands the Host Controller sends
149a Command Status event back to the Host when it has begun to execute the
150command.
151Later on, when the actions associated with the command have finished,
152an event that is associated with the sent command will be sent by the Host
153Controller to the Host.
154.Ss HCI Event Packet
155.Bd -literal -offset indent
156#define NG_HCI_EVENT_PKT 0x04
157typedef struct {
158        uint8_t type;   /* MUST be 0x4 */
159        uint8_t event;  /* event */
160        uint8_t length; /* parameter(s) length in bytes */
161} __attribute__ ((packed)) ng_hci_event_pkt_t;
162.Ed
163.Pp
164The HCI event packet is used by the Host Controller to notify the Host
165when events occur.
166.Ss HCI ACL Data Packet
167.Bd -literal -offset indent
168#define NG_HCI_ACL_DATA_PKT 0x02
169typedef struct {
170        uint8_t  type;       /* MUST be 0x2 */
171        uint16_t con_handle; /* connection handle + PB + BC flags */
172        uint16_t length;     /* payload length in bytes */
173} __attribute__ ((packed)) ng_hci_acldata_pkt_t;
174.Ed
175.Pp
176HCI ACL data packets are used to exchange ACL data between the Host and
177Host Controller.
178.Ss HCI SCO Data Packet
179.Bd -literal -offset indent
180#define NG_HCI_SCO_DATA_PKT 0x03
181typedef struct {
182        uint8_t  type;       /* MUST be 0x3 */
183        uint16_t con_handle; /* connection handle + reserved bits */
184        uint8_t  length;     /* payload length in bytes */
185} __attribute__ ((packed)) ng_hci_scodata_pkt_t;
186.Ed
187.Pp
188HCI SCO data packets are used to exchange SCO data between the Host and
189Host Controller.
190.Sh HCI INITIALIZATION
191On initialization, HCI control application must issue the following HCI
192commands (in any order).
193.Bl -tag -width foo
194.It Dv Read_BD_ADDR
195To obtain BD_ADDR of the Bluetooth unit.
196.It Dv Read_Local_Supported_Features
197To obtain the list of features supported by Bluetooth unit.
198.It Dv Read_Buffer_Size
199To determine the maximum size of HCI ACL and SCO HCI data packets (excluding
200header) that can be sent from the Host to the Host Controller.
201There are also
202two additional return parameters that specify the total number of HCI ACL and
203SCO data packets that the Host Controller can have waiting for transmission in
204its buffers.
205.El
206.Pp
207As soon as HCI initialization has been successfully performed, HCI control
208application must turn on
209.Dq inited
210bit for the node.
211Once HCI node has been initialized all upstream hooks
212will receive a
213.Dv NGM_HCI_NODE_UP
214Netgraph message defined as follows.
215.Bd -literal -offset indent
216#define NGM_HCI_NODE_UP 112 /* HCI -> Upper */
217typedef struct {
218        uint16_t  pkt_size; /* max. ACL/SCO packet size (w/o hdr) */
219        uint16_t  num_pkts; /* ACL/SCO packet queue size */
220        uint16_t  reserved; /* place holder */
221        bdaddr_t  bdaddr;   /* bdaddr */
222} ng_hci_node_up_ep;
223.Ed
224.Sh HCI FLOW CONTROL
225HCI layer performs flow control on baseband connection basis (i.e., ACL and
226SCO link).
227Each baseband connection has
228.Dq "connection handle"
229and queue of outgoing data packets.
230Upper layers protocols are allowed to
231send up to
232.Dv ( num_pkts
233\-
234.Dv pending )
235packets at one time.
236HCI layer will send
237.Dv NGM_HCI_SYNC_CON_QUEUE
238Netgraph messages to inform upper layers about current queue state for each
239connection handle.
240The
241.Dv NGM_HCI_SYNC_CON_QUEUE
242Netgraph message is defined as follows.
243.Bd -literal -offset indent
244#define NGM_HCI_SYNC_CON_QUEUE 113 /* HCI -> Upper */
245typedef struct {
246        uint16_t con_handle; /* connection handle */
247        uint16_t completed;  /* number of completed packets */
248} ng_hci_sync_con_queue_ep;
249.Ed
250.Sh HOOKS
251This node type supports the following hooks:
252.Bl -tag -width ".Va drv"
253.It Va drv
254Bluetooth Host Controller Transport Layer hook.
255Single HCI packet contained in single
256.Vt mbuf
257structure.
258.It Va acl
259Upper layer protocol/node is connected to the hook.
260Single HCI ACL data packet contained in single
261.Vt mbuf
262structure.
263.It Va sco
264Upper layer protocol/node is connected to the hook.
265Single HCI SCO data packet contained in single
266.Vt mbuf
267structure.
268.It Va raw
269Raw hook.
270Every HCI frame (including HCI command frame) that goes in
271or out will be delivered to the hook.
272Usually the Bluetooth raw HCI socket layer is connected to the hook.
273Single HCI frame contained in single
274.Vt mbuf
275structure.
276.El
277.Sh BLUETOOTH UPPER LAYER PROTOCOLS INTERFACE (LP CONTROL MESSAGES)
278.Bl -tag -width foo
279.It Dv NGM_HCI_LP_CON_REQ
280Requests the lower protocol to create a connection.
281If a physical link
282to the remote device does not exist, this message must be sent to the lower
283protocol (baseband) to establish the physical connection.
284.It Dv NGM_HCI_LP_DISCON_REQ
285Requests the lower protocol (baseband) to terminate a connection.
286.It Dv NGM_HCI_LP_CON_CFM
287Confirms success or failure of the
288.Dv NGM_HCI_LP_CON_REQ
289request to establish a lower layer (baseband) connection.
290This includes passing the authentication challenge if authentication is
291required to establish the physical link.
292.It Dv NGM_HCI_LP_CON_IND
293Indicates the lower protocol (baseband) has successfully established
294incoming connection.
295.It Dv NGM_HCI_LP_CON_RSP
296A response accepting or rejecting the previous connection indication request.
297.It Dv NGM_HCI_LP_DISCON_IND
298Indicates the lower protocol (baseband) has terminated connection.
299This could be a response to
300.Dv NGM_HCI_LP_DISCON_REQ
301or a timeout event.
302.It Dv NGM_HCI_LP_QOS_REQ
303Requests the lower protocol (baseband) to accommodate a particular QoS
304parameter set.
305.It Dv NGM_HCI_LP_QOS_CFM
306Confirms success or failure of the request for a given quality of service.
307.It Dv NGM_HCI_LP_QOS_IND
308Indicates the lower protocol (baseband) has detected a violation of the QoS
309agreement.
310.El
311.Sh NETGRAPH CONTROL MESSAGES
312This node type supports the generic control messages, plus the following:
313.Bl -tag -width foo
314.It Dv NGM_HCI_NODE_GET_STATE
315Returns current state for the node.
316.It Dv NGM_HCI_NODE_INIT
317Turn on
318.Dq inited
319bit for the node.
320.It Dv NGM_HCI_NODE_GET_DEBUG
321Returns an integer containing the current debug level for the node.
322.It Dv NGM_HCI_NODE_SET_DEBUG
323This command takes an integer argument and sets current debug level
324for the node.
325.It Dv NGM_HCI_NODE_GET_BUFFER
326Returns current state of data buffers.
327.It Dv NGM_HCI_NODE_GET_BDADDR
328Returns BD_ADDR as cached in the node.
329.It Dv NGM_HCI_NODE_GET_FEATURES
330Returns the list of features supported by hardware (as cached by the node).
331.It Dv NGM_HCI_NODE_GET_NEIGHBOR_CACHE
332Returns content of the neighbor cache.
333.It Dv NGM_HCI_NODE_FLUSH_NEIGHBOR_CACHE
334Remove all neighbor cache entries.
335.It Dv NGM_HCI_NODE_GET_CON_LIST
336Returns list of active baseband connections (i.e., ACL and SCO links).
337.It Dv NGM_HCI_NODE_GET_STAT
338Returns various statistic counters.
339.It Dv NGM_HCI_NODE_RESET_STAT
340Resets all statistic counters to zero.
341.It NGM_HCI_NODE_SET_LINK_POLICY_SETTINGS_MASK
342Sets current link policy settings mask.
343After the new ACL connection is
344created the HCI node will try set link policy for the ACL connection.
345By default, every supported Link Manager (LM) mode will be enabled.
346User can
347override this by setting link policy settings mask which specifies LM
348modes to be enabled.
349.It NGM_HCI_NODE_GET_LINK_POLICY_SETTINGS_MASK
350Returns current link policy settings mask.
351.It NGM_HCI_NODE_SET_PACKET_MASK
352Sets current packet mask.
353When new baseband (ACL or SCO) connection is
354created the HCI node will specify every packet type supported by the device.
355User can override this by setting packet mask which specifies packet types
356to be used for new baseband connections.
357.It NGM_HCI_NODE_GET_PACKET_MASK
358Returns current packet mask.
359.It NGM_HCI_NODE_SET_ROLE_SWITCH
360Sets the value of the role switch.
361Role switch is enabled when this value is not zero.
362This is the default state.
363Note that actual role switch at Bluetooth link level will only be performed if
364hardware supports role switch and it was enabled.
365.It NGM_HCI_NODE_GET_ROLE_SWITCH
366Returns the value of the role switch for the node.
367.El
368.Sh SHUTDOWN
369This node shuts down upon receipt of a
370.Dv NGM_SHUTDOWN
371control message, or
372when all hooks have been disconnected.
373.Sh SEE ALSO
374.Xr netgraph 4 ,
375.Xr hccontrol 8 ,
376.Xr ngctl 8
377.Sh HISTORY
378The
379.Nm hci
380node type was implemented in
381.Fx 5.0 .
382.Sh AUTHORS
383.An Maksim Yevmenkin Aq Mt m_evmenkin@yahoo.com
384.Sh BUGS
385Most likely.
386Please report if found.
387