📄 network-bluetooth.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>Bluetooth</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD Handbook" href="index.html" /><link rel="UP" title="Advanced Networking" href="advanced-networking.html" /><link rel="PREVIOUS" title="Wireless Networking" href="network-wireless.html" /><link rel="NEXT" title="Bridging" href="network-bridging.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD Handbook</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="network-wireless.html"accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 24 Advanced Networking</td><td width="10%" align="right" valign="bottom"><a href="network-bridging.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="NETWORK-BLUETOOTH" name="NETWORK-BLUETOOTH">24.4Bluetooth</a></h1><i class="AUTHORGROUP"><span class="CONTRIB">Written by</span> Pav Lucistnik.</i> <div class="SECT2"><h2 class="SECT2"><a id="AEN36611" name="AEN36611">24.4.1 Introduction</a></h2><p>Bluetooth is a wireless technology for creating personal networks operating in the 2.4GHz unlicensed band, with a range of 10 meters. Networks are usually formed ad-hoc fromportable devices such as cellular phones, handhelds and laptops. Unlike the other popularwireless technology, Wi-Fi, Bluetooth offers higher level service profiles, e.g. FTP-likefile servers, file pushing, voice transport, serial line emulation, and more.</p><p>The Bluetooth stack in FreeBSD is implemented using the Netgraph framework (see <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=netgraph&sektion=4"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">netgraph</span>(4)</span></a>). A broadvariety of Bluetooth USB dongles is supported by the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=ng_ubt&sektion=4"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">ng_ubt</span>(4)</span></a> driver. TheBroadcom BCM2033 chip based Bluetooth devices are supported via the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=ubtbcmfw&sektion=4"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">ubtbcmfw</span>(4)</span></a> and <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=ng_ubt&sektion=4"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">ng_ubt</span>(4)</span></a> drivers. The3Com Bluetooth PC Card 3CRWB60-A is supported by the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=ng_bt3c&sektion=4"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">ng_bt3c</span>(4)</span></a> driver.Serial and UART based Bluetooth devices are supported via <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=sio&sektion=4"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sio</span>(4)</span></a>, <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=ng_h4&sektion=4"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">ng_h4</span>(4)</span></a> and <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=hcseriald&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">hcseriald</span>(8)</span></a>. Thissection describes the use of the USB Bluetooth dongle. Bluetooth support is available inFreeBSD 5.0 and newer systems.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN36639" name="AEN36639">24.4.2 Plugging in the Device</a></h2><p>By default Bluetooth device drivers are available as kernel modules. Before attachinga device, you will need to load the driver into the kernel:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">kldload ng_ubt</kbd></pre><p>If the Bluetooth device is present in the system during system startup, load themodule from <tt class="FILENAME">/boot/loader.conf</tt>:</p><pre class="PROGRAMLISTING">ng_ubt_load="YES"</pre><p>Plug in your USB dongle. The output similar to the following will appear on theconsole (or in syslog):</p><pre class="SCREEN">ubt0: vendor 0x0a12 product 0x0001, rev 1.10/5.25, addr 2ubt0: Interface 0 endpoints: interrupt=0x81, bulk-in=0x82, bulk-out=0x2ubt0: Interface 1 (alt.config 5) endpoints: isoc-in=0x83, isoc-out=0x3, wMaxPacketSize=49, nframes=6, buffer size=294</pre><p>Copy <tt class="FILENAME">/usr/share/examples/netgraph/bluetooth/rc.bluetooth</tt>into some convenient place, like <tt class="FILENAME">/etc/rc.bluetooth</tt>. This scriptis used to start and stop the Bluetooth stack. It is a good idea to stop the stack beforeunplugging the device, but it is not (usually) fatal. When starting the stack, you willreceive output similar to the following:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">/etc/rc.bluetooth start ubt0</kbd>BD_ADDR: 00:02:72:00:d4:1aFeatures: 0xff 0xff 0xf 00 00 00 00 00<3-Slot> <5-Slot> <Encryption> <Slot offset><Timing accuracy> <Switch> <Hold mode> <Sniff mode><Park mode> <RSSI> <Channel quality> <SCO link><HV2 packets> <HV3 packets> <u-law log> <A-law log> <CVSD><Paging scheme> <Power control> <Transparent SCO data>Max. ACL packet size: 192 bytesNumber of ACL packets: 8Max. SCO packet size: 64 bytesNumber of SCO packets: 8</pre></div><div class="SECT2"><h2 class="SECT2"><a id="AEN36658" name="AEN36658">24.4.3 Host Controller Interface(HCI)</a></h2><p>Host Controller Interface (HCI) provides a command interface to the basebandcontroller and link manager, and access to hardware status and control registers. Thisinterface provides a uniform method of accessing the Bluetooth baseband capabilities. HCIlayer on the Host exchanges data and commands with the HCI firmware on the Bluetoothhardware. The Host Controller Transport Layer (i.e. physical bus) driver provides bothHCI layers with the ability to exchange information with each other.</p><p>A single Netgraph node of type <span class="emphasis"><iclass="EMPHASIS">hci</i></span> is created for a single Bluetooth device. The HCI node isnormally connected to the Bluetooth device driver node (downstream) and the L2CAP node(upstream). All HCI operations must be performed on the HCI node and not on the devicedriver node. Default name for the HCI node is ``devicehci''. For more details refer tothe <a href="http://www.FreeBSD.org/cgi/man.cgi?query=ng_hci&sektion=4"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">ng_hci</span>(4)</span></a> manualpage.</p><p>One of the most common tasks is discovery of Bluetooth devices in RF proximity. Thisoperation is called <span class="emphasis"><i class="EMPHASIS">inquiry</i></span>.Inquiry and other HCI related operations are done with the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=hccontrol&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">hccontrol</span>(8)</span></a> utility.The example below shows how to find out which Bluetooth devices are in range. You shouldreceive the list of devices in a few seconds. Note that a remote device will only answerthe inquiry if it put into <span class="emphasis"><iclass="EMPHASIS">discoverable</i></span> mode.</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbd class="USERINPUT">hccontrol -n ubt0hci inquiry</kbd>Inquiry result, num_responses=1Inquiry result #0 BD_ADDR: 00:80:37:29:19:a4 Page Scan Rep. Mode: 0x1 Page Scan Period Mode: 00 Page Scan Mode: 00 Class: 52:02:04 Clock offset: 0x78efInquiry complete. Status: No error [00]</pre><p><var class="LITERAL">BD_ADDR</var> is unique address of a Bluetooth device, similar toMAC addresses of a network card. This address is needed for further communication with adevice. It is possible to assign human readable name to a BD_ADDR. The <ttclass="FILENAME">/etc/bluetooth/hosts</tt> file contains information regarding the knownBluetooth hosts. The following example shows how to obtain human readable name that wasassigned to the remote device:</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbdclass="USERINPUT">hccontrol -n ubt0hci remote_name_request 00:80:37:29:19:a4</kbd>BD_ADDR: 00:80:37:29:19:a4Name: Pav's T39</pre><p>If you perform an inquiry on a remote Bluetooth device, it will find your computer as``your.host.name (ubt0)''. The name assigned to the local device can be changed at anytime.</p><p>The Bluetooth system provides a point-to-point connection (only two Bluetooth unitsinvolved), or a point-to-multipoint connection. In the point-to-multipoint connection theconnection is shared among several Bluetooth devices. The following example shows how toobtain the list of active baseband connections for the local device:</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbdclass="USERINPUT">hccontrol -n ubt0hci read_connection_list</kbd>Remote BD_ADDR Handle Type Mode Role Encrypt Pending Queue State00:80:37:29:19:a4 41 ACL 0 MAST NONE 0 0 OPEN</pre><p>A <span class="emphasis"><i class="EMPHASIS">connection handle</i></span> is usefulwhen termination of the baseband connection is required. Note, that it is normally notrequired to do it by hand. The stack will automatically terminate inactive basebandconnections.</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbdclass="USERINPUT">hccontrol -n ubt0hci disconnect 41</kbd>Connection handle: 41Reason: Connection terminated by local host [0x16]</pre><p>Refer to <tt class="COMMAND">hccontrol help</tt> for a complete listing of availableHCI commands. Most of the HCI commands do not require superuser privileges.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN36697" name="AEN36697">24.4.4 Logical Link Control andAdaptation Protocol (L2CAP)</a></h2><p>Logical Link Control and Adaptation Protocol (L2CAP) provides connection-oriented andconnectionless data services to upper layer protocols with protocol multiplexingcapability and segmentation and reassembly operation. L2CAP permits higher levelprotocols and applications to transmit and receive L2CAP data packets up to 64 kilobytesin length.</p><p>L2CAP is based around the concept of <span class="emphasis"><iclass="EMPHASIS">channels</i></span>. Channel is a logical connection on top of basebandconnection. Each channel is bound to a single protocol in a many-to-one fashion. Multiplechannels can be bound to the same protocol, but a channel cannot be bound to multipleprotocols. Each L2CAP packet received on a channel is directed to the appropriate higherlevel protocol. Multiple channels can share the same baseband connection.</p><p>A single Netgraph node of type <span class="emphasis"><iclass="EMPHASIS">l2cap</i></span> is created for a single Bluetooth device. The L2CAPnode is normally connected to the Bluetooth HCI node (downstream) and Bluetooth socketsnodes (upstream). Default name for the L2CAP node is ``devicel2cap''. For more detailsrefer to the <a href="http://www.FreeBSD.org/cgi/man.cgi?query=ng_l2cap&sektion=4"><span
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -