Bluetooth setup
Contents |
Kernel Configuration
As the latest linux stable kernel is 2.6.x, the configuration will be done for these series of the kernel. Most Bluetooth devices are connected to a USB port, so USB will be enabled too. If you want, you can use hotplugging in case you want to use modules instead of compiling support built into the kernel, refer to the last chapters of the Gentoo Installation Guide.
Networking --->
<M> Bluetooth subsystem support --->
<M> L2CAP protocol support
<M> RFCOMM protocol support
[*] RFCOMM TTY support
<M> BNEP protocol support
[*] Multicast filter support
[*] Protocol filter support
Bluetooth device drivers --->
<M> HCI USB driver
USB support ---> <*> Support for Host-side USB --- USB Host Controller Drivers <M> EHCI HCD (USB 2.0) support <M> OHCI HCD support <*> UHCI HCD (most Intel and VIA) support
After that, we have to boot with our new kernel. If all the process went fine, we can run the following command:
# cat /proc/bus/usb/devices | grep -e^[TPD] | grep -e Cls=e0 -B1 -A1 T: Bus=02 Lev=02 Prnt=03 Port=00 Cnt=01 Dev#= 4 Spd=12 MxCh= 0 D: Ver= 1.10 Cls=e0(unk. ) Sub=01 Prot=01 MxPS=64 #Cfgs= 1 P: Vendor=0a12 ProdID=0001 Rev= 5.25
NOTICE: The Cls=e0(unk. ) identifies the bluetooth adapter.
BlueZ Installation, Configuration & PIN Pairing
Now that the device was detected by the kernel, we need a layer that lets applications communicate with the bluetooth device. We will use BlueZ for doing so. We will need the following bluez packages:
* net-wireless/bluez-libs
Latest version available: 2.7
Latest version installed: 2.7
Size of downloaded files: 208 kB
Homepage: http://bluez.sourceforge.net/
Description: Bluetooth Userspace Libraries
License: GPL-2
* net-wireless/bluez-utils
Latest version available: 2.7
Latest version installed: 2.7
Size of downloaded files: 276 kB
Homepage: http://bluez.sourceforge.net/
Description: bluetooth utilities
License: GPL-2
IMPORTANT: Some devices, which are not listed here, might also need net-wireless/bluez-bluefw. These will not be handled by this document yet.
WARNING: Do not emerge bluez-kernel neither bluez-sdp, as they will break bluez-utils!
After having installed bluez-libs and bluez-utils, the command hciconfig should return something like:
# hciconfig hci0: Type: USB BD Address: 00:10:60:A2:DD:2A ACL MTU: 192:8 SCO MTU: 64:8 DOWN RX bytes:131 acl:0 sco:0 events:18 errors:0 TX bytes:565 acl:0 sco:0 commands:17 errors:0
Now authentification: /etc/bluetooth/pin file on host machine should be like this :
1234
and this is the code the client host that wants to connect to this master host has to have in its /usr/bin/bluepin in the following form
#!/bin/sh echo "PIN:1234"
To make things simple we assume that the codes for both hosts will be the same so /etc/bluetooth/pin and /usr/bin/bluepin on host A will be the same as on host B
IMPORTANT: This number (of your choice) must be the same in all your hosts with bluetooth devices. Alright, now we are ready to start the service and add it to the default runlevel:
# /etc/init.d/bluetooth start # rc-update add bluetooth default
Now let's check that the bluetooth daemons started successfully:
# ps -ae | grep hcid 26050 ? 00:00:00 hcid # ps -ae | grep sdpd 26054 ? 00:00:00 sdpd
After that, we have to check that the device is up and running. If it isn't, stop the bluetooth service, unplug the bluetooth device, plug it back and start the bluetooth service again. A successful initialization would show something like:
# hciconfig hci0: Type: USB BD Address: 00:10:60:A2:DD:2A ACL MTU: 192:8 SCO MTU: 64:8 UP RUNNING PSCAN ISCAN AUTH ENCRYPT RX bytes:408 acl:0 sco:0 events:21 errors:0 TX bytes:574 acl:0 sco:0 commands:20 errors:0 # hciconfig -a hci0: Type: USB BD Address: 00:10:60:A2:DD:2A ACL MTU: 192:8 SCO MTU: 64:8 UP RUNNING PSCAN ISCAN AUTH ENCRYPT RX bytes:408 acl:0 sco:0 events:21 errors:0 TX bytes:574 acl:0 sco:0 commands:20 errors:0 Features: 0xff 0xff 0x0f 0x00 0x00 0x00 0x00 0x00 Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 Link policy: RSWITCH HOLD SNIFF PARK Link mode: SLAVE ACCEPT Name: 'Blackhat BlueZ' Class: 0x000100 Service Classes: Unspecified Device Class: Computer, Uncategorized HCI Ver: 1.1 (0x1) HCI Rev: 0x20d LMP Ver: 1.1 (0x1) LMP Subver: 0x20d Manufacturer: Cambridge Silicon Radio (10)
NOTICE: If we run hciconfig -a, we can see whether the parameters configured in /etc/bluetooth/hcid.conf were set correctly.
Detecting Bluetooth Devices in Other Hosts
At this point we are now ready to detect bluetooth devices installed in other machines. This is independent of the host Operating System. We will make use of the hcitool command along this chapter.
To check for local devices before trying to detect remote ones:
# hcitool dev Devices: hci0 00:10:60:A2:DD:2A
On host A: To scan for remote devices:
# hcitool scan Scanning ... 00:10:60:A3:CB:41 Grayhat
To inquire remote devices:
# hcitool inq Inquiring ... 00:10:60:A3:CB:41 clock offset: 0x5579 class: 0x72010c
Now we need to pair the bluetooth devices. executing
# hcitool cc 00:10:60:A3:CB:41
on the host B we do the same using btaddr of the bluetooth device on host A
# hcitool inq Inquiring ... 00:10:60:A2:DD:2A clock offset: 0x5579 class: 0x72010c # hcitool cc 00:10:60:A2:DD:2A
If the pairing doesnt work try deleting files /etc/bluetooth/link_key on host A and B.
In some setups, the link_key file is located in /var/bluetooth/00:10:60:A2:DD:2A/linkkeys (where "00:10:60:A2:DD:2A" is the MAC-address of your local bluez-device). linkkeys might also be in /var/lib/bluetooth.
After having paired the devices, now we can do whatever we want with them. Let's start by a simple ping:
# l2ping 00:10:60:A3:CB:41 Ping: 00:10:60:A3:CB:41 from 00:10:60:A2:DD:2A (data size 20) ... 20 bytes from 00:10:60:A3:CB:41 id 200 time 69.5ms 20 bytes from 00:10:60:A3:CB:41 id 201 time 9.97ms 20 bytes from 00:10:60:A3:CB:41 id 202 time 56.6ms 20 bytes from 00:10:60:A3:CB:41 id 203 time 39.2ms 4 sent, 4 received, 0% loss
Personal Area Network
You can use Bluetooth Network Encapsulation Protocol (BNEP) to have a TCP/IP link over bluetooth. There are several options of network architecture (peer-to-peer, client-server) - just like Wifi. In this simple example, we will make a connection between two hosts only.
At first, the bnep kernel module has to be compiled and loaded.
On one host start (as root):
one # pand --listen --role NAP
On the other one (assuming the same device ID from previous sections):
two # pand --connect 00:10:60:A3:CB:41
This should make a 'bnep0' network interface on both hosts. Now assign IP adresses to both sides:
one # ifconfig bnep0 10.20.30.1 netmask 255.255.255.0 broadcast 10.20.30.255 two # ifconfig bnep0 10.20.30.2 netmask 255.255.255.0 broadcast 10.20.30.255
Now, you can try to ping it:
one # ping 10.20.30.2 PING 10.20.30.2 (10.20.30.2) 56(84) bytes of data. 64 bytes from 10.20.30.2: icmp_seq=1 ttl=128 time=40.8 ms 64 bytes from 10.20.30.2: icmp_seq=2 ttl=128 time=19.5 ms 64 bytes from 10.20.30.2: icmp_seq=3 ttl=128 time=42.7 ms --- 10.20.30.2 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 19.580/34.401/42.768/10.510 ms
Note: If you try to connect a Linux box with a Windows box, try to make the first (Linux) a NAP (Access Point) and the latter (Windows) the PANU (User). Other combinations didn't work for me (Linux <--> W98).
Now we setup bluetooth to start PAN automatically. On Gentoo systems, modify /etc/conf.d/bluetooth
PAND_ENABLE=true PAND_OPTIONS="--listen --role NAP"
More information here:
![[LOGO]](/workbook/skins/workbook/create_small2.png)



