Using Bluetooth under Linux

xXXXXXXXXx
xXX^^^^^^^^^^XXx
xX..............Xx
xX.......|\.......Xx
##### X........|\\.......X
####### xX........||\\......Xx
##O#O## X.........||.\\......X
#VVVVV# xX.........||..\\.....Xx
##.VVVV.## XX....\\...||..//.....XX
#..........## XX.....\\..||.//......XX
#............## XX......\\.||//.......XX
#............### XX.......\\|//........XX
QQ#...........##Q XX........\\/.........XX
QQQQQQ#.......#QQQQQQ XX........//\.........XX
QQQQQQQ#.....#QQQQQQQ XX.......//|\\........XX
QQQQQ#######QQQQQ XX......//.||\\.......XX
XX.....//..||.\\......XX
XX....//...||..\\.....XX
^X.........||..//.....X^
XX........||.//.....XX
^X........||//......X^
XX.......|//......XX
^XX......|/......XX^
^Xx_.........._xX^
^XXXxxxxxxxxXX^
^XXXXXX^



Table of content:

requirement and assumption

It is not assumed that you have any knowledge about Bluetooth, but it is assumed that you have a reasonable knowledge of Linux.

We will focus on USING bluetooth. we will assume that your distribution provides binaries for bluetooth. i.e. we won't discuss on how to compile anything !

Unless specified, it is assume that you are running thoses steps as root... (but don't stay root longer than necessary !).

Introduction

Bluetooth is a radio-frequency standard to connect two (or up to 7) devices. You can think of it as a replacement for cables of a few meters (USB and legacy interface like serial port, parallel port and PS2 mouse, keyboard) for applications that have low bandwith requirement. It designed for battery operated mobile devices and provides voice, data and audio connections between devices.

Don't be confused, it is not a replacement for USB (which have much higher speed : 480 mbit/s ; and it can provide up to 500 mA to the attached device)

And it's not a competitor to "WiFi" (802.11a/b/g)... which has higher range, higher bandwidth... and much higher power consumption !

Technically, Bluetooth is known as 802.11(?). It can interconnect up to 7 devices at up to 950 kbit/s up to 10 meters.

There are two implementation of bluetooth under Linux : Bluez and Affix. thoses are called "bluetooth stacks". This document currently focus on the first only.

Supported hardware

There is a wide variety of Bluetooth devices that are currently supported : USB and PCCard / Compact flash...

TODO provide some links

Basic Setup

As far as security is concerned a proper operating system should, by default, install the minimum service. So let's install the required software.

Install the software

Since Redhat put the PC Card driver configuration files in the application package, let's all download the basic software:

Distribution

Required packages (*)

Howto do install

Debian Woody / Sarge (**)

bluez-utils
bluez-sdp
gnome-bluetooth

apt-get install bluez-sdp

RedHat / Fedora

bluez-sdp
gnome-bluetooth

Menu/System Settings/ Add­Remove Applications/GNOME Desktop Environnment
click Details
select gnome-bluetooth

Mandrake



knoppix






(*) Plus direct dependencies ! Packages in italics are optional.
(**) as of today, you will need to add a line to your apt repository (http://bluez.sourceforge.net/download/debian/APT-README ). Debian Sarge might ship with bluez out of the box.

You can try running "hciconfig -a"

Setup the driver

USB devices

USB devices should be fully plug and play under linux... otherwise go back configuring your distribution and check the hardware compatibility with Linux ;)

Verifications : If everything is setup correctly, doing lsusb should report your device (otherwise, you have an usb configuration error... that's not specific to your bluetooth device)

hostname:/root# lsusb
Bus 004 Device 001: ID 0000:0000
Bus 003 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle
Bus 003 Device 001: ID 0000:0000
Bus 002 Device 004: ID 04b8:010b Seiko Epson Corp. Perfection 1240
Bus 002 Device 003: ID 046d:c00e Logitech, Inc. Optical Mouse
Bus 002 Device 002: ID 0451:2046 Texas Instruments, Inc. TUSB2046 Hub
Bus 002 Device 001: ID 0000:0000
Bus 001 Device 001: ID 0000:0000

Here, i have a "Cambridge Silicon Radio" (CSR) dongle. with the pair value "Vendor ID:Product ID" = 0a12:0001

Then run

cat /proc/bus/usb/devices  | more

in which you should have a section with the same vendorID:Product ID :

T:  Bus=03 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  2 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= 3.73
C:* #Ifs= 3 Cfg#= 1 Atr=80 MxPwr=100mA
I:  If#= 0 Alt= 0 #EPs= 3 Cls=e0(unk. ) Sub=01 Prot=01 Driver=hci_usb
E:  Ad=81(I) Atr=03(Int.) MxPS=  16 Ivl=1ms
E:  Ad=02(O) Atr=02(Bulk) MxPS=  64 Ivl=0ms
E:  Ad=82(I) Atr=02(Bulk) MxPS=  64 Ivl=0ms
I:  If#= 1 Alt= 0 #EPs= 2 Cls=e0(unk. ) Sub=01 Prot=01 Driver=hci_usb
E:  Ad=03(O) Atr=01(Isoc) MxPS=   0 Ivl=1ms
E:  Ad=83(I) Atr=01(Isoc) MxPS=   0 Ivl=1ms
I:  If#= 1 Alt= 1 #EPs= 2 Cls=e0(unk. ) Sub=01 Prot=01 Driver=hci_usb
E:  Ad=03(O) Atr=01(Isoc) MxPS=   9 Ivl=1ms
E:  Ad=83(I) Atr=01(Isoc) MxPS=   9 Ivl=1ms
I:  If#= 1 Alt= 2 #EPs= 2 Cls=e0(unk. ) Sub=01 Prot=01 Driver=hci_usb
E:  Ad=03(O) Atr=01(Isoc) MxPS=  17 Ivl=1ms
E:  Ad=83(I) Atr=01(Isoc) MxPS=  17 Ivl=1ms
I:  If#= 1 Alt= 3 #EPs= 2 Cls=e0(unk. ) Sub=01 Prot=01 Driver=hci_usb
E:  Ad=03(O) Atr=01(Isoc) MxPS=  25 Ivl=1ms
E:  Ad=83(I) Atr=01(Isoc) MxPS=  25 Ivl=1ms
I:  If#= 1 Alt= 4 #EPs= 2 Cls=e0(unk. ) Sub=01 Prot=01 Driver=hci_usb
E:  Ad=03(O) Atr=01(Isoc) MxPS=  33 Ivl=1ms
E:  Ad=83(I) Atr=01(Isoc) MxPS=  33 Ivl=1ms
I:  If#= 1 Alt= 5 #EPs= 2 Cls=e0(unk. ) Sub=01 Prot=01 Driver=hci_usb
E:  Ad=03(O) Atr=01(Isoc) MxPS=  49 Ivl=1ms
E:  Ad=83(I) Atr=01(Isoc) MxPS=  49 Ivl=1ms
I:  If#= 2 Alt= 0 #EPs= 0 Cls=fe(app. ) Sub=01 Prot=00 Driver=(none)

you can notice that at least one of the end-point has a driver associated "Driver=hci_usb"... which is OK.

a typical lsmod should include the following lines :

hostname:/root# lsmod | more
Module                  Size  Used by
hci_usb                13312  1 
bluetooth              50820  10 hci_usb



PC-Card devices (PCMCIA, CardBus, Compact Flash)

PC-Card devices might (!) be plug and play... otherwise go back configuring you OS and check the compatibility ;)

Verifications : if your PC-Card system (which include Pcmcia, CardBus and Compact Flash devices)

[root@localhost root]# cardctl ident
Socket 0:
  no product info available
Socket 1:
  product info: "WSS", "LSE039"
  manfid: 0x0264, 0x0008
  function: 6 (network)

My "Bluetooth Compact Flash" from Anycom reports itself with the strings "WSS" and "LSE0039". It is in Socket 1

[root@localhost root]# cardctl status
Socket 0:
  no card
Socket 1:
  3.3V 16-bit PC Card
  function 0: [ready], [wp]

note the "[ready]" above

If you don't get this, you have a problem with your PCCard subsystem, read your system documentation about setting up PCMCIA (Hint : check your "/etc/sysconfig/pcmcia" and then do a "/etc/init.d/pcmcia restart".)

Now let's have a look at the driver in use :

[root@localhost root]# cat /proc/bus/pccard/drivers
bluecard_cs              0 1

if the driver name appears, fine ! jump to configuration step

[root@localhost root]# cat /proc/bus/pccard/drivers
cat: /proc/bus/pccard/drivers: No such file or directory

But if the driver name isn't there.. humm your devices isn't configred in /etc/pcmcia/bluetooth.conf or /etc/pcmcia/config-2.4 or /etc/pcmcia/config (see you system documentation on how to set this up).

Here are some hints : You might have to create or to enable the following two sections (in one of the above /etc/pcmcia/* files).

### ADD THIS IN ONE OF THE /etc/pcmcia/config or config-2.4 or bluetooth.conf files
device "bluecard_cs"
  class "bluetooth" module "bluecard_cs"
card "Anymom LSE039 Bluetooth Compact Flash Card"
  version "WSS", "LSE039"
  manfid 0x0264, 0x0008
  bind "bluecard_cs"

Note that "version" and "manfid" are matching the information returned by "carddtl status" we ran before.

Configuration

Before we continue, running "hciconfig -a" should return something like the sample below. At this point it doesn't matter what is the output, we just want to know that "hci0" or "hciXX" is there. if the command returns nothing at all, go back configuring the device driver !

hostname:/root# hciconfig -a
hci0:   Type: USB
        BD Address: 00:01:02:03:04:05 ACL MTU: 192:8  SCO MTU: 64:8
        DOWN
        RX bytes:112651 acl:5019 sco:0 events:1078 errors:0
        TX bytes:17672 acl:643 sco:0 commands:327 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: ACCEPT MASTER

I will simply reproduce here a reasonable /etc/bluetooth/hcid.conf file. I have re-written the man pages.. see appendix.

# HCId options
options {
	# Automatically initialize new devices
	autoinit yes;

	# Security Manager mode
	#   none - Security manager disabled
	#   auto - Use local PIN for incoming connections
	#   user - Always ask user for a PIN
	security user;

	# Pairing mode
	#   none  - Pairing disabled
	#   multi - Allow pairing with already paired devices
	#   once  - Pair once and deny successive attempts
	pairing multi;

	# PIN helper
	pin_helper /usr/bin/bluez-pin;
}

# Default settings for HCI devices
device {
	# Local device name
	name "MyPC";

	# Local device class
	class 0x100;

	# Inquiry and Page scan
	iscan enable; pscan enable;

	# Default link mode
	#   none   - no specific policy 
	#   accept - always accept incoming connections
	#   master - become master on incoming connections,
	#            deny role switch on outgoing connections
	#
	#lm accept,master;
	lm accept;

	# Default link policy
	#   none    - no specific policy
	#   rswitch - allow role switch
	#   hold    - allow hold mode
	#   sniff   - allow sniff mode
	#   park    - allow park mode
	#
	#lp hold,sniff;
	lp hold,sniff,park;

	# Authentication and Encryption
	auth enable;
	encrypt enable;
}

Setting up specific features

rfcomm (or using a mobile phone for GPRS)

pan (or )

dun



and using GRPS

Appendix

Bluez

The applications

Bluetooth utilities (bluez-utils)

hciconfig (new manpage)

Configure Bluetooth devices (or display configuration)

hcitool (new manpage)

Configure Bluetooth connections

hciattach (new manpage)

Attach a serial UART to the Bluetooth stack as HCI transport interface (/dev/ttyS?)

hcid (new manpage)

Bluetooth daemon

l2ping (new manpage)

Ping a remote device

/etc/pcmcia/bluetooth

PC Card configuration handler



Bluetooth utilities (bluez-sdp)

sdptool (new manpage)


sdpd (new manpage)




The config files

/etc/bluetooth/hcid.conf (new manpage)

This file contains Bluetooth devices configurations, connection configuration and security options.

/etc/bluetooth/pin

This file may contain your "automatic" PIN code for pairing with others devices.

/etc/bluetooth/rfcomm.conf (new manpage)

This file contains /dev/rfcomm? bindings configurations.

/etc/pcmcia/bluetooth.conf

PC Card only configuration : device to driver mappings.

/etc/rc.d/init.d/bluetooth
or
/etc/rc.d/init.d/bluez-*

init script to start bluetooth





What are the modules ?

Those are the drivers shipped with the kernel

Module Name
(path relative to /lib/modules/<version>/)

Description

.../kernel/net/bluetooth/bluetooth.(o|ko)


.../kernel/net/bluetooth/l2cap.(o|ko)


.../kernel/net/bluetooth/sco.(o|ko)


.../kernel/net/bluetooth/bnep/bnep.(o|ko)


.../kernel/net/bluetooth/cmtp/cmtp.(o|ko)


.../kernel/net/bluetooth/rfcomm/rfcomm.(o|ko)




.../kernel/drivers/bluetooth/hci_uart.(o|ko)


.../kernel/drivers/bluetooth/hci_vhci.(o|ko)


.../kernel/drivers/bluetooth/hci_usb.(o|ko)

Driver for USB devices

.../kernel/drivers/bluetooth/bluecard_cs.(o|ko)


.../kernel/drivers/bluetooth/bcm203x.(o|ko)


.../kernel/drivers/bluetooth/btuart_cs.(o|ko)




.../kernel/drivers/bluetooth/bfusb.(o|ko)

new (between 2.4.21 to 2.6.3)

.../kernel/drivers/bluetooth/bt3c_cs.(o|ko)


.../kernel/drivers/bluetooth/dtl1_cs.(o|ko)






Links

Well, this seems to be a must have ;)

Bluetooth Specifications : https://www.bluetooth.org/spec/

BlueZ : http://www.bluez.org/