⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 network-bluetooth.html

📁 FreeBSD安装说明概述 FreeBSD 提供了一个以文字为主
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!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 使用手册" 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" /><meta http-equiv="Content-Type" content="text/html; charset=GB2312" /></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 使用手册</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 19. 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">19.4.Bluetooth</a></h1><i class="AUTHORGROUP"><span class="CONTRIB">Written by</span> Pav Lucistnik.</i> <div class="SECT2"><h2 class="SECT2"><a id="AEN25706" name="AEN25706">19.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 <spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">netgraph</span>(4)</span>). A broadvariety of Bluetooth USB dongles is supported by the <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">ng_ubt</span>(4)</span> driver. The Broadcom BCM2033 chip basedBluetooth devices are supported via the <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">ubtbcmfw</span>(4)</span> and <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">ng_ubt</span>(4)</span> drivers. The 3Com Bluetooth PC Card3CRWB60-A is supported by the <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">ng_bt3c</span>(4)</span> driver. Serial and UART based Bluetoothdevices are supported via <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">sio</span>(4)</span>, <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">ng_h4</span>(4)</span> and <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">hcseriald</span>(8)</span>. This chapter describes the use of theUSB Bluetooth dongle. Bluetooth support is available in FreeBSD 5.0 and newersystems.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN25734" name="AEN25734">19.4.2. Plugging in theDevice</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&lt;3-Slot&gt; &lt;5-Slot&gt; &lt;Encryption&gt; &lt;Slot offset&gt;&lt;Timing accuracy&gt; &lt;Switch&gt; &lt;Hold mode&gt; &lt;Sniff mode&gt;&lt;Park mode&gt; &lt;RSSI&gt; &lt;Channel quality&gt; &lt;SCO link&gt;&lt;HV2 packets&gt; &lt;HV3 packets&gt; &lt;u-law log&gt; &lt;A-law log&gt; &lt;CVSD&gt;&lt;Paging scheme&gt; &lt;Power control&gt; &lt;Transparent SCO data&gt;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="AEN25753" name="AEN25753">19.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 <span class="CITEREFENTRY"><span class="REFENTRYTITLE">ng_hci</span>(4)</span> manpage.</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 realated operations are done with the <spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">hccontrol</span>(8)</span> utility. Theexample 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="AEN25792" name="AEN25792">19.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 <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">ng_l2cap</span>(4)</span> man page.</p><p>A useful command is <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">l2ping</span>(8)</span>, which can be used to ping other devices.Some Bluetooth implementations might not return all of the data sent to them, so <spanclass="emphasis"><i class="EMPHASIS">0 bytes</i></span> in the following example isnormal.</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">l2ping -a 00:80:37:29:19:a4</kbd>0 bytes from 0:80:37:29:19:a4 seq_no=0 time=48.633 ms result=00 bytes from 0:80:37:29:19:a4 seq_no=1 time=37.551 ms result=00 bytes from 0:80:37:29:19:a4 seq_no=2 time=28.324 ms result=00 bytes from 0:80:37:29:19:a4 seq_no=3 time=46.150 ms result=0</pre><p>The <span class="CITEREFENTRY"><span class="REFENTRYTITLE">l2control</span>(8)</span>utility is used to perform various operations on L2CAP nodes. This example shows how toobtain the list of logical connections (channels) and the list of baseband connectionsfor the local device.</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbdclass="USERINPUT">l2control -a 00:02:72:00:d4:1a read_channel_list</kbd>L2CAP channels:Remote BD_ADDR     SCID/ DCID   PSM  IMTU/ OMTU State00:07:e0:00:0b:ca    66/   64     3   132/  672 OPEN<samp class="PROMPT">%</samp> <kbdclass="USERINPUT">l2control -a 00:02:72:00:d4:1a read_connection_list</kbd>L2CAP connections:Remote BD_ADDR    Handle Flags Pending State00:07:e0:00:0b:ca     41 O           0 OPEN</pre><p>Another diagnostic tool is <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">btsockstat</span>(1)</span>. It does a job similar to as <spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">netstat</span>(1)</span> does, but forBluetooth network-related data structures. The example below shows the same logicalconnection as <span class="CITEREFENTRY"><spanclass="REFENTRYTITLE">l2control</span>(8)</span> above.</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbd class="USERINPUT">btsockstat</kbd>Active L2CAP socketsPCB      Recv-Q Send-Q Local address/PSM       Foreign address   CID   Statec2afe900      0      0 00:02:72:00:d4:1a/3     00:07:e0:00:0b:ca 66    OPENActive RFCOMM sessionsL2PCB    PCB      Flag MTU   Out-Q DLCs Statec2afe900 c2b53380 1    127   0     Yes  OPENActive RFCOMM socketsPCB      Recv-Q Send-Q Local address     Foreign address   Chan DLCI Statec2e8bc80      0    250 00:02:72:00:d4:1a 00:07:e0:00:0b:ca 3    6    OPEN</pre></div><div class="SECT2"><h2 class="SECT2"><a id="AEN25835" name="AEN25835">19.4.5. RFCOMM Protocol</a></h2><p>The RFCOMM protocol provides emulation of serial ports over the L2CAP protocol. Theprotocol is based on the ETSI standard TS 07.10. RFCOMM is a simple transport protocol,with additional provisions for emulating the 9 circuits of RS-232 (EIATIA-232-E) serialports. The RFCOMM protocol supports up to 60 simultaneous connections (RFCOMM channels)between two Bluetooth devices.</p><p>For the purposes of RFCOMM, a complete communication path involves two applicationsrunning on different devices (the communication endpoints) with a communication segmentbetween them. RFCOMM is intended to cover applications that make use of the serial portsof the devices in which they reside. The communication segment is a Bluetooth link fromone device to another (direct connect).</p><p>RFCOMM is only concerned with the connection between the devices in the direct connectcase, or between the device and a modem in the network case. RFCOMM can support otherconfigurations, such as modules that communicate via Bluetooth wireless technology on oneside and provide a wired interface on the other side.</p><p>In FreeBSD the RFCOMM protocol is implemented at the Bluetooth sockets layer.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN25843" name="AEN25843">19.4.6. Pairing of Devices</a></h2><p>By default, Bluetooth communication is not authenticated, and any device can talk toany other device. A Bluetooth device (for example, cellular phone) may choose to requireauthentication to provide a particular service (for example, Dial-Up service). Bluetoothauthentication is normally done with <span class="emphasis"><i class="EMPHASIS">PINcodes</i></span>. A PIN code is an ASCII string up to 16 characters in length. User isrequired to enter the same PIN code on both devices. Once user has entered the PIN code,both devices will generate a <span class="emphasis"><i class="EMPHASIS">linkkey</i></span>. After that the link key can be stored either in the devices themselves orin a persistent storage. Next time both devices will use previously generated link key.The described above procedure is called <span class="emphasis"><iclass="EMPHASIS">pairing</i></span>. Note that if the link key is lost by any device thenpairing must be repeated.</p><p>The <span class="CITEREFENTRY"><span class="REFENTRYTITLE">hcsecd</span>(8)</span>daemon is responsible for handling of all Bluetooth authentication requests. The defaultconfiguration file is <tt class="FILENAME">/etc/bluetooth/hcsecd.conf</tt>. An examplesection for a cellular phone with the PIN code arbitrarily set to ``1234'' is shownbelow.</p><pre class="PROGRAMLISTING">device {        bdaddr  00:80:37:29:19:a4;        name    "Pav's T39";        key     nokey;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -