Annotation of wikisrc/guide/bluetooth.mdwn, revision 1.2

1.2     ! jdf         1: **Contents**
        !             2: 
        !             3: [[!toc levels=3]]
        !             4: 
1.1       jdf         5: # Bluetooth on NetBSD
                      6: 
                      7: ## Introduction
                      8: 
                      9: Bluetooth is a digital radio protocol used for short range and low power
                     10: communications. NetBSD 4.0 introduced support for the Bluetooth protocol stack,
                     11: and some integration of service profiles into the NetBSD device framework.
                     12: 
                     13: The lower layers of the Bluetooth protocol stack pertaining to actual radio
                     14: links between devices are handled inside the Bluetooth Controller, which
                     15: communicates with the Host computer using the *Host Controller Interface* (HCI)
                     16: protocol which can be accessed via a raw packet BTPROTO\_HCI socket interface.
                     17: 
                     18: Most of the Bluetooth protocols or services layer atop the *Link Layer Control
                     19: and Adaptation Protocol (L2CAP)*, which can be accessed via a BTPROTO\_L2CAP
                     20: socket interface. This provides sequential packet connections to remote devices,
                     21: with up to 64k channels. When an L2CAP channel is opened, the protocol or
                     22: service that is required is identified by a *Protocol/Service Multiplexer (PSM)*
                     23: value.
                     24: 
                     25: Service Discovery in the Bluetooth environment is provided for by the
                     26: [sdp(3)](http://netbsd.gw.com/cgi-bin/man-cgi?sdp+3+NetBSD-5.0.1+i386) library
                     27: functions and the
                     28: [sdpd(8)](http://netbsd.gw.com/cgi-bin/man-cgi?sdpd+8+NetBSD-5.0.1+i386) daemon,
                     29: which keeps a database of locally registered services and makes the information
                     30: available to remote devices performing queries. The
                     31: [sdpquery(1)](http://netbsd.gw.com/cgi-bin/man-cgi?sdpquery+1+NetBSD-5.0.1+i386)
                     32: tool can be used to query local and remote service databases.
                     33: 
                     34: Security on Bluetooth links can be enabled by encryption and authentication
                     35: options to
                     36: [btconfig(8)](http://netbsd.gw.com/cgi-bin/man-cgi?btconfig+8+NetBSD-5.0.1+i386)
                     37: which apply to all baseband links that a controller makes, or encryption and
                     38: authentication can be enabled for individual RFCOMM and L2CAP links as required.
                     39: When authentication is requested, a PIN is presented by each side (generally
                     40: entered by the operator, some limited input devices have a fixed PIN). The
                     41: controller uses this PIN to generate a Link Key and reports this to the Host
                     42: which may be asked to produce it to authenticate subsequent connections. On
                     43: NetBSD, the
                     44: [bthcid(8)](http://netbsd.gw.com/cgi-bin/man-cgi?bthcid+8+NetBSD-5.0.1+i386)
                     45: daemon is responsible for storing link keys and responding to Link Key Requests,
                     46: and also provides an interface to allow unprivileged users to specify a PIN with
                     47: a PIN client, such as
                     48: [btpin(1)](http://netbsd.gw.com/cgi-bin/man-cgi?btpin+1+NetBSD-5.0.1+i386).
                     49: 
                     50: ## Supported Hardware
                     51: 
                     52: Because Bluetooth controllers normally use the standard HCI protocol as
                     53: specified in the *Bluetooth 2.0 Core* documentation to communicate with the
                     54: host, the NetBSD Bluetooth stack is compatible with most controllers, only
                     55: requiring an interface driver, with the following drivers available in NetBSD
                     56: 5.0:
                     57: 
                     58:  * [bcsp(4)](http://netbsd.gw.com/cgi-bin/man-cgi?bcsp+4+NetBSD-5.0.1+i386)
                     59:    provides a
                     60:    [tty(4)](http://netbsd.gw.com/cgi-bin/man-cgi?tty+4+NetBSD-5.0.1+i386) line
                     61:    discipline to send and receive BlueCore Serial Protocol packets over a serial
                     62:    line as described in the *BlueCore Serial Protocol (BCSP)* specification.
                     63:  * [bt3c(4)](http://netbsd.gw.com/cgi-bin/man-cgi?bt3c+4+NetBSD-5.0.1+i386)
                     64:    provides an interface to the 3Com Bluetooth PC Card, model 3CRWB6096-A.
                     65:  * [btbc(4)](http://netbsd.gw.com/cgi-bin/man-cgi?btbc+4+NetBSD-5.0.1+i386)
                     66:    provides support for the AnyCom BlueCard (LSE041, LSE039, LSE139) PCMCIA
                     67:    devices.
                     68:  * [btuart(4)](http://netbsd.gw.com/cgi-bin/man-cgi?btuart+4+NetBSD-5.0.1+i386)
                     69:    provides a
                     70:    [tty(4)](http://netbsd.gw.com/cgi-bin/man-cgi?tty+4+NetBSD-5.0.1+i386) line
                     71:    discipline to send and receive Bluetooth packets over a serial line as
                     72:    described in the *Bluetooth Host Controller Interface [Transport Layer]
                     73:    specification, Vol 4 part A*.
                     74:  * [sbt(4)](http://netbsd.gw.com/cgi-bin/man-cgi?sbt+4+NetBSD-5.0.1+i386)
                     75:    provides support for Secure Digital IO Bluetooth adapters.
                     76:  * [ubt(4)](http://netbsd.gw.com/cgi-bin/man-cgi?ubt+4+NetBSD-5.0.1+i386)
                     77:    interfaces to all USB Bluetooth controllers conforming to the *HCI USB
                     78:    Transport Layer* specification.
                     79: 
                     80: If support for the NetBSD Bluetooth stack is enabled in the kernel,
                     81: autoconfiguration messages will show up in the
                     82: [dmesg(8)](http://netbsd.gw.com/cgi-bin/man-cgi/man?dmesg+8+NetBSD-current)
                     83: output, for example:
                     84: 
                     85:     bt3c0 at pcmcia0 function 0: <3COM, 3CRWB60-A, Bluetooth PC Card>
                     86:     
                     87:     ubt0 at uhub1 port 4 configuration 1 interface 0
                     88:     ubt0: Cambridge Silicon Radio Bluetooth USB Adapter, rev 2.00/19.58, addr 4
                     89:     
                     90:     ubt1 at uhub1 port 2 configuration 1 interface 0
                     91:     ubt1: Broadcom Belkin Bluetooth Device, rev 1.10/0.01, addr 5
                     92: 
                     93: When support is not already compiled in, it can be added to the kernel
                     94: configuration file for any platform that supports USB and/or PCMCIA (see
                     95: [[Kernel Tuning|guide/tuning]]), using the following declarations, as required:
                     96: 
                     97:     # Bluetooth Controller and Device support
                     98:     
                     99:     pseudo-device   bcsp                   # BlueCore Serial Protocol
                    100:     pseudo-device   btuart                 # Bluetooth HCI UART
                    101:     
                    102:     # Bluetooth PCMCIA Controllers
                    103:     bt3c* at pcmcia? function ?             # 3Com 3CRWB6096-A
                    104:     btbc* at pcmcia? function ?             # AnyCom BlueCard LSE041/039/139
                    105:     
                    106:     # Bluetooth SDIO Controllers
                    107:     sbt* at sdmmc?
                    108:     
                    109:     # Bluetooth USB Controllers
                    110:     ubt* at uhub? port ?
                    111:     
                    112:     # Bluetooth Device Hub
                    113:     bthub* at bcsp?
                    114:     bthub* at bt3c?
                    115:     bthub* at btbc?
                    116:     bthub* at btuart?
                    117:     bthub* at sbt?
                    118:     bthub* at ubt?
                    119:     
                    120:     # Bluetooth HID support
                    121:     bthidev* at bthub?
                    122:     
                    123:     # Bluetooth Mouse
                    124:     btms* at bthidev? reportid ?
                    125:     wsmouse* at btms? mux 0
                    126:     
                    127:     # Bluetooth Keyboard
                    128:     btkbd* at bthidev? reportid ?
                    129:     wskbd* at btkbd? console ? mux 1
                    130:     
                    131:     # Bluetooth Audio support
                    132:     btsco* at bthub?
                    133:         
                    134: 
                    135: Some older USB Bluetooth dongles based on the Broadcom BCM2033 chip require
                    136: firmware to be loaded before they can function, and these devices will be
                    137: attached to
                    138: [ugen(4)](http://netbsd.gw.com/cgi-bin/man-cgi?ugen+4+NetBSD-5.0.1+i386). Use
                    139: the `sysutils/bcmfw` package from the NetBSD Package Collection, to load
                    140: firmware and enable these.
                    141: 
                    142: ## System Configuration
                    143: 
                    144: To fully enable Bluetooth services on NetBSD, the following line should be added
                    145: to the `/etc/rc.conf` file.
                    146: 
                    147:     bluetooth=YES
                    148: 
                    149: and either reboot, or execute the following command:
                    150: 
                    151:     # /etc/rc.d/bluetooth start
                    152: 
                    153: *Note*: Configuration of Bluetooth controllers is done with the
                    154: [btconfig(8)](http://netbsd.gw.com/cgi-bin/man-cgi?btconfig+8+NetBSD-5.0.1+i386)
                    155: program, and the above argument enables only basic functionality, see the manual
                    156: page for other useful options.
                    157: 
                    158: **Important**:
                    159: [bthcid(8)](http://netbsd.gw.com/cgi-bin/man-cgi?bthcid+8+NetBSD-5.0.1+i386)
                    160: *must* be running in order to make authenticated connections with remote
                    161: devices, and authentication may be requested by either device.
                    162: 
                    163: ## Human Interface Devices
                    164: 
                    165: Support for *Human Interface Devices (HIDs)*, which operate using the USB HID
                    166: protocol over a pair of L2CAP channels is provided by the
                    167: [bthidev(4)](http://netbsd.gw.com/cgi-bin/man-cgi?bthidev+4+NetBSD-5.0.1+i386)
                    168: driver. Currently, keyboards and mice are catered for, and attach to
                    169: [wscons(4)](http://netbsd.gw.com/cgi-bin/man-cgi?wscons+4+NetBSD-5.0.1+i386) as
                    170: normal.
                    171: 
                    172: ### Mice
                    173: 
                    174: Bluetooth Mice can be attached to the system with the
                    175: [btms(4)](http://netbsd.gw.com/cgi-bin/man-cgi?btms+4+NetBSD-5.0.1+i386) driver,
                    176: using
                    177: [btdevctl(8)](http://netbsd.gw.com/cgi-bin/man-cgi?btdevctl+8+NetBSD-5.0.1+i386).
                    178: 
                    179: First, you must discover the BDADDR of the device. This may be printed on the
                    180: box, but the easiest way is to place the device into discoverable mode and
                    181: perform a device inquiry with the appropriate controller:
                    182: 
                    183:     # btconfig ubt0 inquiry
                    184:     Device Discovery on ubt0 .... 1 response
                    185:       1: bdaddr 00:14:51:c1:b9:2d (unknown)
                    186:        : name "Mighty Mouse"
                    187:        : class: [0x002580] Peripheral Mouse <Limited Discoverable>
                    188:        : page scan rep mode 0x01
                    189:        : page scan period mode 0x02
                    190:        : page scan mode 0x00
                    191:        : clock offset 6944
                    192: 
                    193: For ease of use, you may want to add the address to the `/etc/bluetooth/hosts`
                    194: file, so that you can refer to the mouse by alias:
                    195: 
                    196:     # echo "00:14:51:c1:b9:2d mouse" >>/etc/bluetooth/hosts
                    197: 
                    198: Now, you can query the mouse, which will likely request authentication before it
                    199: accepts connections. The fixed PIN should be listed in the documentation, though
                    200: `0000` is often used. Set the PIN first using the
                    201: [btpin(1)](http://netbsd.gw.com/cgi-bin/man-cgi?btpin+1+NetBSD-5.0.1+i386)
                    202: program:
                    203: 
                    204:     # btpin -d ubt0 -a mouse -p 0000
                    205:     # btdevctl -d ubt0 -a mouse -s HID
                    206:     local bdaddr: 00:08:1b:8d:ba:6d
                    207:     remote bdaddr: 00:14:51:c1:b9:2d
                    208:     link mode: auth
                    209:     device type: bthidev
                    210:     control psm: 0x0011
                    211:     interrupt psm: 0x0013
                    212:     Collection page=Generic_Desktop usage=Mouse
                    213:       Input id=2 size=1 count=1 page=Button usage=Button_1 Variable, logical range 0..1
                    214:       Input id=2 size=1 count=1 page=Button usage=Button_2 Variable, logical range 0..1
                    215:       Input id=2 size=1 count=1 page=Button usage=Button_3 Variable, logical range 0..1
                    216:       Input id=2 size=1 count=1 page=Button usage=Button_4 Variable, logical range 0..1
                    217:       Input id=2 size=4 count=1 page=0x0000 usage=0x0000 Const Variable, logical range 0..1
                    218:     Collection page=Generic_Desktop usage=Pointer
                    219:       Input id=2 size=8 count=1 page=Generic_Desktop usage=X Variable Relative, logical range -127..127
                    220:       Input id=2 size=8 count=1 page=Generic_Desktop usage=Y Variable Relative, logical range -127..127
                    221:       Input id=2 size=8 count=1 page=Consumer usage=AC_Pan Variable Relative, logical range -127..127
                    222:       Input id=2 size=8 count=1 page=Generic_Desktop usage=Wheel Variable Relative, logical range -127..127
                    223:     End collection
                    224:       Input id=2 size=8 count=1 page=0x00ff usage=0x00c0 Variable, logical range -127..127
                    225:     Feature id=71 size=8 count=1 page=0x0006 usage=0x0020 Variable NoPref Volatile, logical range 0..100
                    226:     End collection
                    227: 
                    228: This tells you that the mouse has responded to an SDP query, and the device
                    229: capabilities are shown. Note that authentication is enabled by default for
                    230: Bluetooth mice. You may now attach to the system:
                    231: 
                    232:     # btdevctl -d ubt0 -a mouse -s HID -A
                    233: 
                    234: which should generate some messages on the system console:
                    235: 
                    236:     bthidev0 at bthub0 remote-bdaddr 00:14:51:c1:b9:2d link-mode auth
                    237:     btms0 at bthidev1 reportid 2: 4 buttons, W and Z dirs.
                    238:     wsmouse1 at btms0 mux 0
                    239:     bthidev1: reportid 71 not configured
                    240:     bthidev1: connected
                    241: 
                    242: and the mouse should work.
                    243: 
                    244: The device capabilities are cached by
                    245: [btdevctl(8)](http://netbsd.gw.com/cgi-bin/man-cgi?btdevctl+8+NetBSD-5.0.1+i386),
                    246: and to reattach the mouse at system startup, place an entry in
                    247: `/etc/bluetooth/btdevctl.conf`. The
                    248: [bthidev(4)](http://netbsd.gw.com/cgi-bin/man-cgi?bthidev+4+NetBSD-5.0.1+i386)
                    249: driver will attempt to connect once, though mice will usually be sleeping and
                    250: may require a tap on the shoulder to awaken, in which case they should initiate
                    251: the connection to the host computer.
                    252: 
                    253: ### Keyboards
                    254: 
                    255: Bluetooth Keyboards can be attached to the system with the
                    256: [btkbd(4)](http://netbsd.gw.com/cgi-bin/man-cgi?btkbd+4+NetBSD-5.0.1+i386)
                    257: driver, using
                    258: [btdevctl(8)](http://netbsd.gw.com/cgi-bin/man-cgi?btdevctl+8+NetBSD-5.0.1+i386).
                    259: 
                    260: First, you must discover the BDADDR of the device. This may be printed on the
                    261: box, but the easiest way is to place the device into discoverable mode and
                    262: perform a device inquiry with the appropriate controller:
                    263: 
                    264:     # btconfig ubt0 inquiry
                    265:     Device Discovery on ubt0 .... 1 response
                    266:       1: bdaddr 00:0a:95:45:a4:a0 (unknown)
                    267:        : name "Apple Wireless Keyboard"
                    268:        : class: [0x002540] Peripheral Keyboard <Limited Discoverable>
                    269:        : page scan rep mode 0x01
                    270:        : page scan period mode 0x00
                    271:        : page scan mode 0x00
                    272:        : clock offset 18604
                    273: 
                    274: For ease of use, you may want to add the address to the `/etc/bluetooth/hosts`
                    275: file, so that you can refer to the keyboard by alias:
                    276: 
                    277:     # echo "00:0a:95:45:a4:a0 keyboard" >>/etc/bluetooth/hosts
                    278: 
                    279: Now, you can query the keyboard, which will likely request authentication before
                    280: it accepts connections. The PIN will need to be entered on the keyboard, and we
                    281: can generate a random PIN, using the
                    282: [btpin(1)](http://netbsd.gw.com/cgi-bin/man-cgi?btpin+1+NetBSD-5.0.1+i386)
                    283: program.
                    284: 
                    285:     # btpin -d ubt0 -a keyboard -r -l 8
                    286:     PIN: 18799632
                    287:     # btdevctl -d ubt0 -a keyboard -s HID
                    288:     
                    289:         < ENTER PIN ON BLUETOOTH KEYBOARD NOW >
                    290:     
                    291:     local bdaddr: 00:08:1b:8d:ba:6d
                    292:     remote bdaddr: 00:0a:95:45:a4:a0
                    293:     link mode: encrypt
                    294:     device type: bthidev
                    295:     control psm: 0x0011
                    296:     interrupt psm: 0x0013
                    297:     Collection page=Generic_Desktop usage=Keyboard
                    298:       Input id=1 size=1 count=1 page=Keyboard usage=Keyboard_LeftControl Variable, logical range 0..1
                    299:       Input id=1 size=1 count=1 page=Keyboard usage=Keyboard_LeftShift Variable, logical range 0..1
                    300:       Input id=1 size=1 count=1 page=Keyboard usage=Keyboard_LeftAlt Variable, logical range 0..1
                    301:       Input id=1 size=1 count=1 page=Keyboard usage=Keyboard_Left_GUI Variable, logical range 0..1
                    302:       Input id=1 size=1 count=1 page=Keyboard usage=Keyboard_RightControl Variable, logical range 0..1
                    303:       Input id=1 size=1 count=1 page=Keyboard usage=Keyboard_RightShift Variable, logical range 0..1
                    304:       Input id=1 size=1 count=1 page=Keyboard usage=Keyboard_RightAlt Variable, logical range 0..1
                    305:       Input id=1 size=1 count=1 page=Keyboard usage=Keyboard_Right_GUI Variable, logical range 0..1
                    306:       Input id=1 size=8 count=1 page=0x0000 usage=0x0000 Const, logical range 0..1
                    307:      Output id=1 size=1 count=1 page=LEDs usage=Num_Lock Variable, logical range 0..1
                    308:      Output id=1 size=1 count=1 page=LEDs usage=Caps_Lock Variable, logical range 0..1
                    309:      Output id=1 size=1 count=1 page=LEDs usage=Scroll_Lock Variable, logical range 0..1
                    310:      Output id=1 size=1 count=1 page=LEDs usage=Compose Variable, logical range 0..1
                    311:      Output id=1 size=1 count=1 page=LEDs usage=Kana Variable, logical range 0..1
                    312:      Output id=1 size=3 count=1 page=0x0000 usage=0x0000 Const, logical range 0..1
                    313:       Input id=1 size=8 count=6 page=Keyboard usage=No_Event, logical range 0..255
                    314:       Input id=1 size=1 count=1 page=Consumer usage=Eject Variable Relative, logical range 0..1
                    315:       Input id=1 size=1 count=1 page=Consumer usage=Mute Variable Relative, logical range 0..1
                    316:       Input id=1 size=1 count=1 page=Consumer usage=Volume_Up Variable, logical range 0..1
                    317:       Input id=1 size=1 count=1 page=Consumer usage=Volume_Down Variable, logical range 0..1
                    318:       Input id=1 size=1 count=4 page=0x0000 usage=0x0000 Const, logical range 0..1
                    319:     End collection
                    320:           
                    321: 
                    322: This tells you that the keyboard has responded to an SDP query, and the device
                    323: capabilities are shown. Note that encryption is enabled by default, since
                    324: encrypted connection support is mandatory for Bluetooth keyboards. You may now
                    325: attach to the system:
                    326: 
                    327:     # btdevctl -d ubt0 -a keyboard -s HID -A
                    328: 
                    329: which should generate some messages on the system console:
                    330: 
                    331:     bthidev1 at bthub0 remote-bdaddr 00:0a:95:45:a4:a0 link-mode encrypt
                    332:     btkbd0 at bthidev0 reportid 1
                    333:     wskbd1 at btkbd0 mux 1
                    334:     wskbd1: connecting to wsdisplay0
                    335:     bthidev1: connected
                    336: 
                    337: and the keyboard should work.
                    338: 
                    339: The device capabilities are cached by
                    340: [btdevctl(8)](http://netbsd.gw.com/cgi-bin/man-cgi?btdevctl+8+NetBSD-5.0.1+i386),
                    341: and to reattach the keyboard at system startup, place an entry in
                    342: `/etc/bluetooth/btdevctl.conf`. The
                    343: [bthidev(4)](http://netbsd.gw.com/cgi-bin/man-cgi?bthidev+4+NetBSD-5.0.1+i386)
                    344: driver will attempt to connect once when attached, but if the keyboard is not
                    345: available at that time, you may find that pressing a key will cause it to wake
                    346: up and initiate a connection to the last paired host.
                    347: 
                    348: ## Personal Area Networking
                    349: 
                    350: Personal Area Networking services over Bluetooth are provided by the
                    351: [btpand(8)](http://netbsd.gw.com/cgi-bin/man-cgi?btpand+8+NetBSD-5.0.1+i386)
                    352: daemon which can assume all roles from the PAN profile and connects remote
                    353: devices to the system through a
                    354: [tap(4)](http://netbsd.gw.com/cgi-bin/man-cgi?tap+4+NetBSD-5.0.1+i386) virtual
                    355: Ethernet interface.
                    356: 
                    357: ### Personal Area Networking User
                    358: 
                    359: The "Personal Area Networking User" role is the client that accesses Network
                    360: services on another device. For instance, in order to connect to the Internet
                    361: via a smart phone with the NAP profile, make sure that the phone is
                    362: discoverable, then:
                    363: 
                    364:     # btconfig ubt0 inquiry
                    365:     Device Discovery from device: ubt0 .... 1 response
                    366:       1: bdaddr 00:17:83:30:bd:5e (unknown)
                    367:        : name "HTC Touch"
                    368:        : class: [0x5a020c] Smart Phone <Networking> <Capturing> <Object Transfer>
                    369:         <Telephony>
                    370:        : page scan rep mode 0x01
                    371:        : clock offset 9769
                    372:        : rssi -42
                    373:     
                    374:     # echo "00:17:83:30:bd:5e phone" >>/etc/bluetooth/hosts
                    375: 
                    376: You will see that the phone should have the `<Networking>` flag set in the Class
                    377: of Device. Checking for the NAP service:
                    378: 
                    379:     # sdpquery -a phone search NAP
                    380:     ServiceRecordHandle: 0x00010000
                    381:     ServiceClassIDList:
                    382:         Network Access Point
                    383:     ProtocolDescriptorList:
                    384:         L2CAP (PSM 0x000f)
                    385:         BNEP (v1.0; IPv4, ARP, IPv6)
                    386:     LanguageBaseAttributeIDList:
                    387:         en.UTF-8 base 0x0100
                    388:     BluetoothProfileDescriptorList:
                    389:         Network Access Point, v1.0
                    390:     ServiceName: "Network Access Point"
                    391:     ServiceDescription: "Bluetooth NAP Service"
                    392:     SecurityDescription: None
                    393:     NetAccessType: 100Mb Ethernet
                    394:     MaxNetAccessRate: 100000
                    395: 
                    396: reveals that the NAP service is available and that it provides IPv4, ARP and IPv6 protocols.
                    397: 
                    398: Most likely, the phone will request authentication before it allows connections
                    399: to the NAP service, so before you make the first connection you may need to
                    400: provide a PIN, which can be randomly generated. Then start
                    401: [btpand(8)](http://netbsd.gw.com/cgi-bin/man-cgi?btpand+8+NetBSD-5.0.1+i386):
                    402: 
                    403:     # btpin -d ubt0 -a phone -r -l 6
                    404:     PIN: 862048
                    405:     # btpand -d ubt0 -a phone -s NAP
                    406:     
                    407:         < ENTER PIN ON PHONE NOW >
                    408:     
                    409:     Searching for NAP service at 00:17:83:30:bd:5e
                    410:     Found PSM 15 for service NAP
                    411:     Opening connection to service 0x1116 at 00:17:83:30:bd:5e
                    412:     Using interface tap0 with addr 00:10:60:e1:50:3d
                    413: 
                    414: Finally, you will need to configure the
                    415: [tap(4)](http://netbsd.gw.com/cgi-bin/man-cgi?tap+4+NetBSD-5.0.1+i386)
                    416: interface, but the phone should have a DHCP server so
                    417: [dhcpcd(8)](http://netbsd.gw.com/cgi-bin/man-cgi?dhcpcd+8+NetBSD-5.0.1+i386)
                    418: will do that for you.
                    419: 
                    420:     # dhcpcd tap0
                    421: 
                    422: Now you can surf the World Wide Web, but watch your data usage unless you have a
                    423: comprehensive data plan.
                    424: 
                    425: ## Serial Connections
                    426: 
                    427: Serial connections over Bluetooth are provided for by the RFCOMM protocol, which
                    428: provides up to 30 channels multiplexed over a single L2CAP channel. This
                    429: streamed data protocol can be accessed using the BTPROTO\_RFCOMM socket
                    430: interface, or via the
                    431: [rfcomm\_sppd(1)](http://netbsd.gw.com/cgi-bin/man-cgi?rfcomm_sppd+1+NetBSD-5.0.1+i386)
                    432: program.
                    433: 
                    434: For instance, you can make a serial connection to the *Dial Up Networking (DUN)*
                    435: service of a mobile phone in order to connect to the Internet with PPP. First
                    436: you should discover the BDADDR of the phone, and add this to your
                    437: `/etc/bluetooth/hosts` for ease of use. Place the phone into Discoverable mode,
                    438: and perform an inquiry from the appropriate controller:
                    439: 
                    440:     # btconfig ubt0 inquiry
                    441:     Device Discovery from device: ubt0 ..... 1 response
                    442:       1: bdaddr 00:16:bc:00:e8:48 (unknown)
                    443:        : name "Nokia 6103"
                    444:        : class: [0x520204] Cellular Phone <Networking> <Object Transfer> <Telephony>
                    445:        : page scan rep mode 0x01
                    446:        : page scan period mode 0x02
                    447:        : page scan mode 0x00
                    448:        : clock offset 30269
                    449:     
                    450:     # echo "00:16:bc:00:e8:48 phone" >>/etc/bluetooth/hosts
                    451: 
                    452: Now, you can query the phone to confirm that it supports the DUN profile:
                    453: 
                    454:     # sdpquery -d ubt0 -a phone search DUN
                    455:     ServiceRecordHandle: 0x00010003
                    456:     ServiceClassIDList:
                    457:         Dialup Networking
                    458:         Generic Networking
                    459:     ProtocolDescriptorList:
                    460:         L2CAP
                    461:         RFCOMM (channel 1)
                    462:     BrowseGroupList:
                    463:         Public Browse Root
                    464:     LanguageBaseAttributeIDList:
                    465:         en.UTF-8 base 0x0100
                    466:     BluetoothProfileDescriptorList:
                    467:         Dialup Networking, v1.0
                    468:     ServiceName: "Dial-up networking"
                    469: 
                    470: Most likely, the phone will request authentication before it allows connections
                    471: to the DUN service, so before you make the first connection you may need to
                    472: provide a PIN, which can be randomly generated. You can use `rfcomm_sppd` in
                    473: stdio mode to check that the connection is working ok, press `^C` to
                    474: disconnect and return to the shell, for example:
                    475: 
                    476:     # btpin -d ubt0 -a phone -r -l 6
                    477:     PIN: 904046
                    478:     # rfcomm_sppd -d ubt0 -a phone -s DUN
                    479:     
                    480:         < ENTER PIN ON PHONE NOW >
                    481:     
                    482:     rfcomm_sppd[24635]: Starting on stdio...
                    483:     at
                    484:     OK
                    485:     ati
                    486:     Nokia
                    487:     
                    488:     OK
                    489:     ati3
                    490:     Nokia 6103
                    491:     
                    492:     OK
                    493:     at&v
                    494:     ACTIVE PROFILE:
                    495:     E1 Q0 V1 X5 &C1 &D2 &S0 &Y0
                    496:     +CMEE=0 +CSTA=129 +CBST=0,0,1 +CRLP=61,61,48,6 +CR=0 +CRC=0 +CLIP=0,2
                    497:     +CLIR=0,2 +CSNS=0 +CVHU=1 +DS=0,0,2048,32 +DR=0 +ILRR=0
                    498:     +CHSN=0,0,0,0 +CHSR=0 +CPBS="SM"
                    499:     S00:000 S01:000 S02:043 S03:013 S04:010 S05:008 S07:060 S08:002
                    500:     S10:100 S12:050 S25:000
                    501:     
                    502:     OK
                    503:     ^C
                    504:     rfcomm_sppd[24635]: Completed on stdio
                    505: 
                    506: To have [pppd(8)](http://netbsd.gw.com/cgi-bin/man-cgi?pppd+8+NetBSD-5.0.1+i386)
                    507: connect to the DUN service of your phone automatically when making outbound
                    508: connections, add the following line to the `/etc/ppp/options` file in place of
                    509: the normal tty declaration:
                    510: 
                    511:     pty "rfcomm_sppd -d ubt0 -a phone -s DUN -m encrypt"
                    512: 
                    513: ## Audio
                    514: 
                    515: Isochronous (SCO) Audio connections may be created on a baseband radio link
                    516: using either the BTPROTO\_SCO socket interface, or the
                    517: [btsco(4)](http://netbsd.gw.com/cgi-bin/man-cgi?btsco+4+NetBSD-5.0.1+i386) audio
                    518: device driver. While the specification says that up to three such links can be
                    519: made between devices, the current Bluetooth stack can only handle one with any
                    520: dignity.
                    521: 
                    522: **Important**: When using SCO Audio with USB Bluetooth controllers, you will
                    523: need to enable isochronous data, and calculate the MTU that the device will use,
                    524: see [ubt(4)](http://netbsd.gw.com/cgi-bin/man-cgi?ubt+4+NetBSD-5.0.1+i386) and
                    525: [btconfig(8)](http://netbsd.gw.com/cgi-bin/man-cgi?btconfig+8+NetBSD-5.0.1+i386).
                    526: 
                    527: *Note*: SCO Audio does not work properly with the
                    528: [bt3c(4)](http://netbsd.gw.com/cgi-bin/man-cgi?bt3c+4+NetBSD-5.0.1+i386) driver,
                    529: use a USB controller for best results.
                    530: 
                    531: *Note*: SCO Audio will not work with
                    532: [ehci(4)](http://netbsd.gw.com/cgi-bin/man-cgi?ehci+4+NetBSD-5.0.1+i386) USB
                    533: controllers, since support for Isochronous data over EHCI is missing in NetBSD.
                    534: 
                    535: ### SCO Audio Headsets
                    536: 
                    537: Audio connections to Bluetooth Headsets are possible using the
                    538: [btsco(4)](http://netbsd.gw.com/cgi-bin/man-cgi?btsco+4+NetBSD-5.0.1+i386) audio
                    539: driver, and the
                    540: [bthset(1)](http://netbsd.gw.com/cgi-bin/man-cgi?bthset+1+NetBSD-5.0.1+i386)
                    541: program. First, you need to discover the BDADDR of the headset, and will
                    542: probably wish to make an alias in your `/etc/bluetooth/hosts` file for ease of
                    543: use. Place the headset into discoverable mode and perform an inquiry with the
                    544: appropriate controller:
                    545: 
                    546:     # btconfig ubt0 inquiry
                    547:     Device Discovery from device: ubt0 ..... 1 response
                    548:      1: bdaddr 00:07:a4:23:10:83 (unknown)
                    549:       : name "JABRA 250"
                    550:       : class: [0x200404] Wearable Headset <Audio>
                    551:       : page scan rep mode 0x01
                    552:       : page scan period mode 0x00
                    553:       : page scan mode 0x00
                    554:       : clock offset 147
                    555:     
                    556:     # echo "00:07:a4:23:10:83 headset" >>/etc/bluetooth/hosts
                    557: 
                    558: You will need to pair with the headset the first time you connect, the fixed PIN
                    559: should be listed in the manual (often, `0000` is used).
                    560: [btdevctl(8)](http://netbsd.gw.com/cgi-bin/man-cgi?btdevctl+8+NetBSD-5.0.1+i386)
                    561: will query the device and attach the
                    562: [btsco(4)](http://netbsd.gw.com/cgi-bin/man-cgi?btsco+4+NetBSD-5.0.1+i386) audio
                    563: driver.
                    564: 
                    565:     # btpin -d ubt0 -a headset -p 0000
                    566:     # btdevctl -d ubt0 -a headset -s HSET -A
                    567:     local bdaddr: 00:08:1b:8d:ba:6d
                    568:     remote bdaddr: 00:07:a4:23:10:83
                    569:     link mode: none
                    570:     device type: btsco
                    571:     mode: connect
                    572:     channel: 1
                    573: 
                    574: which should generate some messages on the system console:
                    575: 
                    576:     btsco0 at bthub0 remote-bdaddr 00:07:a4:23:10:83 channel 1
                    577:     audio1 at btsco0: full duplex
                    578: 
                    579: In order to use the audio device, you will need to open a control connection
                    580: with
                    581: [bthset(1)](http://netbsd.gw.com/cgi-bin/man-cgi?bthset+1+NetBSD-5.0.1+i386)
                    582: which conveys volume information to the mixer device.
                    583: 
                    584:     # bthset -m /dev/mixer1 -v
                    585:     Headset Info:
                    586:             mixer: /dev/mixer1
                    587:             laddr: 00:08:1b:8d:ba:6d
                    588:             raddr: 00:07:a4:23:10:83
                    589:             channel: 1
                    590:             vgs.dev: 0, vgm.dev: 1
                    591: 
                    592: and you should now be able to transfer 8khz samples to and from `/dev/audio1`
                    593: using any program that supports audio, such as
                    594: [audioplay(1)](http://netbsd.gw.com/cgi-bin/man-cgi?audioplay+1+NetBSD-5.0.1+i386)
                    595: or
                    596: [audiorecord(1)](http://netbsd.gw.com/cgi-bin/man-cgi?audiorecord+1+NetBSD-5.0.1+i386).
                    597: Adjusting the mixer values should work when playing though you may find that
                    598: when opening a connection, the headset will reset the volume to the last known
                    599: settings.
                    600: 
                    601:     # audiorecord -d /dev/audio1 voice.au
                    602:             < TALK NONSENSE NOW >
                    603:     ^C
                    604:     # audioplay -d /dev/audio voice.au
                    605:             < THATS REALLY WHAT YOU SOUND LIKE >
                    606:     # audioplay -d /dev/audio1 voice.au
                    607:             < IN THE HEADSET >
                    608: 
                    609: The device capabilities are cached by
                    610: [btdevctl(8)](http://netbsd.gw.com/cgi-bin/man-cgi?btdevctl+8+NetBSD-5.0.1+i386),
                    611: and to reattach the
                    612: [btsco(4)](http://netbsd.gw.com/cgi-bin/man-cgi?btsco+4+NetBSD-5.0.1+i386)
                    613: driver at system startup, add an entry to `/etc/bluetooth/btdevctl.conf`.
                    614: 
                    615: ### SCO Audio Handsfree
                    616: 
                    617: Audio connections to Bluetooth mobile phones using the Handsfree profile are
                    618: possible with the `comms/bthfp` program from the NetBSD Package Collection.
                    619: 
                    620: First, you need to discover the BDADDR of the phone, and will probably wish to
                    621: make an alias in your `/etc/bluetooth/hosts` file for ease of use. Place the
                    622: phone into discoverable mode and perform an inquiry with the appropriate
                    623: controller:
                    624: 
                    625:     # btconfig ubt0 inquiry
                    626:     Device Discovery from device: ubt0 ..... 1 response
                    627:       1: bdaddr 00:16:bc:00:e8:48 (unknown)
                    628:        : name "Nokia 6103"
                    629:        : class: [0x520204] Cellular Phone <Networking;gt; <Object Transfer;gt; <Telephony;gt;
                    630:        : page scan rep mode 0x01
                    631:        : page scan period mode 0x02
                    632:        : page scan mode 0x00
                    633:        : clock offset 10131
                    634:     
                    635:     # echo "00:16:bc:00:e8:48 phone" >>/etc/bluetooth/hosts
                    636: 
                    637: Now, you should be able to query the phone to confirm that it supports the
                    638: Handsfree profile:
                    639: 
                    640:     # sdpquery -d ubt0 -a phone search HF
                    641:     ServiceRecordHandle: 0x00010006
                    642:     ServiceClassIDList:
                    643:         Handsfree Audio Gateway
                    644:         Generic Audio
                    645:     ProtocolDescriptorList:
                    646:         L2CAP
                    647:         RFCOMM (channel 13)
                    648:     BrowseGroupList:
                    649:         Public Browse Root
                    650:     LanguageBaseAttributeIDList:
                    651:         en.UTF-8 base 0x0100
                    652:     BluetoothProfileDescriptorList:
                    653:         Handsfree, v1.5
                    654:     ServiceName: "Voice Gateway"
                    655:     Network: Ability to reject a call
                    656:     SupportedFeatures:
                    657:         3 Way Calling
                    658:         Echo Cancellation/Noise Reduction
                    659:         Voice Recognition
                    660:         In-band Ring Tone
                    661: 
                    662: and you will be able to use the bthfp program to access the Handsfree profile.
                    663: The first time you connect, you may need to use a PIN to pair with the phone,
                    664: which can be generated randomly by
                    665: [btpin(1)](http://netbsd.gw.com/cgi-bin/man-cgi?btpin+1+NetBSD-5.0.1+i386):
                    666: 
                    667:     # btpin -d ubt0 -a phone -r -l 6
                    668:     PIN: 349163
                    669:     # bthfp -d ubt0 -a phone -v
                    670:     
                    671:           < ENTER PIN ON PHONE NOW >
                    672:     Handsfree channel: 13
                    673:     Press ? for commands
                    674:     Connecting.. ok
                    675:     < AT+BRSF=20
                    676:     > +BRSF: 47
                    677:     Features: [0x002f] <3 way calling> <EC/NR> <Voice Recognition> <In-band ringtone> <reject ability>
                    678:     > OK
                    679:     < AT+CIND=?
                    680:     > +CIND: ("call",(0,1)),("service",(0,1)),("call_setup",(0-3)),("callsetup",(0-3))
                    681:     > OK
                    682:     < AT+CIND?
                    683:     > +CIND: 0,1,0,0
                    684:     > OK
                    685:     < AT+CMER=3,0,0,1
                    686:     > OK
                    687:     < AT+CLIP=1
                    688:     > OK
                    689:     Service Level established
                    690: 
                    691: When the phone rings, just press `a` to answer, and audio should be routed
                    692: through the `/dev/audio` device. Note that you will need a microphone connected
                    693: in order to speak to the remote party.
                    694: 
                    695: ## Object Exchange
                    696: 
                    697: NetBSD does not currently have any native OBEX capability, see the
                    698: `comms/obexapp` or `comms/obexftp` packages from the NetBSD Package Collection.
                    699: 
                    700: ## Troubleshooting
                    701: 
                    702: When nothing seems to be happening, it may be useful to try the hcidump program
                    703: from the `sysutils/netbt-hcidump` package in the NetBSD Package Collection. This
                    704: has the capability to dump packets entering and leaving Bluetooth controllers on
                    705: NetBSD, which is greatly helpful in pinpointing problems.
                    706: 

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb