📄 network-bluetooth.html
字号:
class="CITEREFENTRY"><span class="REFENTRYTITLE">ng_l2cap</span>(4)</span></a> manualpage.</p><p>A useful command is <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=l2ping&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">l2ping</span>(8)</span></a>, which canbe used to ping other devices. Some Bluetooth implementations might not return all of thedata sent to them, so <var class="LITERAL">0 bytes</var> 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 <a href="http://www.FreeBSD.org/cgi/man.cgi?query=l2control&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">l2control</span>(8)</span></a> utilityis used to perform various operations on L2CAP nodes. This example shows how to obtainthe list of logical connections (channels) and the list of baseband connections for thelocal 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 <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=btsockstat&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">btsockstat</span>(1)</span></a>. It doesa job similar to as <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=netstat&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">netstat</span>(1)</span></a> does, butfor Bluetooth network-related data structures. The example below shows the same logicalconnection as <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=l2control&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">l2control</span>(8)</span></a>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="AEN36740" name="AEN36740">24.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="AEN36748" name="AEN36748">24.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 <a href="http://www.FreeBSD.org/cgi/man.cgi?query=hcsecd&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">hcsecd</span>(8)</span></a> daemon isresponsible 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; pin "1234"; }</pre><p>There is no limitation on PIN codes (except length). Some devices (for exampleBluetooth headsets) may have a fixed PIN code built in. The <var class="OPTION">-d</var>switch forces the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=hcsecd&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">hcsecd</span>(8)</span></a> daemon tostay in the foreground, so it is easy to see what is happening. Set the remote device toreceive pairing and initiate the Bluetooth connection to the remote device. The remotedevice should say that pairing was accepted, and request the PIN code. Enter the same PINcode as you have in <tt class="FILENAME">hcsecd.conf</tt>. Now your PC and the remotedevice are paired. Alternatively, you can initiate pairing on the remote device. Thefollowing is a sample of the <b class="APPLICATION">hcsecd</b> daemon output:</p><pre class="PROGRAMLISTING">hcsecd[16484]: Got Link_Key_Request event from 'ubt0hci', remote bdaddr 0:80:37:29:19:a4hcsecd[16484]: Found matching entry, remote bdaddr 0:80:37:29:19:a4, name 'Pav's T39', link key doesn't existhcsecd[16484]: Sending Link_Key_Negative_Reply to 'ubt0hci' for remote bdaddr 0:80:37:29:19:a4hcsecd[16484]: Got PIN_Code_Request event from 'ubt0hci', remote bdaddr 0:80:37:29:19:a4hcsecd[16484]: Found matching entry, remote bdaddr 0:80:37:29:19:a4, name 'Pav's T39', PIN code existshcsecd[16484]: Sending PIN_Code_Reply to 'ubt0hci' for remote bdaddr 0:80:37:29:19:a4</pre></div><div class="SECT2"><h2 class="SECT2"><a id="AEN36771" name="AEN36771">24.4.7 Service Discovery Protocol(SDP)</a></h2><p>The Service Discovery Protocol (SDP) provides the means for client applications todiscover the existence of services provided by server applications as well as theattributes of those services. The attributes of a service include the type or class ofservice offered and the mechanism or protocol information needed to utilize theservice.</p><p>SDP involves communication between a SDP server and a SDP client. The server maintainsa list of service records that describe the characteristics of services associated withthe server. Each service record contains information about a single service. A client mayretrieve information from a service record maintained by the SDP server by issuing a SDPrequest. If the client, or an application associated with the client, decides to use aservice, it must open a separate connection to the service provider in order to utilizethe service. SDP provides a mechanism for discovering services and their attributes, butit does not provide a mechanism for utilizing those services.</p><p>Normally, a SDP client searches for services based on some desired characteristics ofthe services. However, there are times when it is desirable to discover which types ofservices are described by an SDP server's service records without any a prioriinformation about the services. This process of looking for any offered services iscalled <span class="emphasis"><i class="EMPHASIS">browsing</i></span>.</p><p>The Bluetooth SDP server <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=sdpd&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sdpd</span>(8)</span></a> and commandline client <a href="http://www.FreeBSD.org/cgi/man.cgi?query=sdpcontrol&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sdpcontrol</span>(8)</span></a> areincluded in the standard FreeBSD installation. The following example shows how to performa SDP browse query.</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbdclass="USERINPUT">sdpcontrol -a 00:01:03:fc:6e:ec browse</kbd>Record Handle: 00000000Service Class ID List: Service Discovery Server (0x1000)Protocol Descriptor List: L2CAP (0x0100) Protocol specific parameter #1: u/int/uuid16 1 Protocol specific parameter #2: u/int/uuid16 1Record Handle: 0x00000001Service Class ID List: Browse Group Descriptor (0x1001)Record Handle: 0x00000002Service Class ID List: LAN Access Using PPP (0x1102)Protocol Descriptor List: L2CAP (0x0100) RFCOMM (0x0003) Protocol specific parameter #1: u/int8/bool 1Bluetooth Profile Descriptor List: LAN Access Using PPP (0x1102) ver. 1.0</pre><p>... and so on. Note that each service has a list of attributes (RFCOMM channel forexample). Depending on the service you might need to make a note of some of theattributes. Some Bluetooth implementations do not support service browsing and may returnan empty list. In this case it is possible to search for the specific service. Theexample below shows how to search for the OBEX Object Push (OPUSH) service:</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbdclass="USERINPUT">sdpcontrol -a 00:01:03:fc:6e:ec search OPUSH</kbd></pre><p>Offering services on FreeBSD to Bluetooth clients is done with the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=sdpd&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sdpd</span>(8)</span></a> server:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">sdpd</kbd></pre><p>The local server application that wants to provide Bluetooth service to the remoteclients will register service with the local SDP daemon. The example of such applicationis <a href="http://www.FreeBSD.org/cgi/man.cgi?query=rfcomm_pppd&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">rfcomm_pppd</span>(8)</span></a>. Oncestarted it will register Bluetooth LAN service with the local SDP daemon.</p><p>The list of services registered with the local SDP server can be obtained by issuingSDP browse query via local control channel:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">sdpcontrol -l browse</kbd></pre></div><div class="SECT2"><h2 class="SECT2"><a id="AEN36806" name="AEN36806">24.4.8 Dial-Up Networking (DUN) and
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -