Tuesday, September 25, 2007

Bluetooth on Debian

This howto will help you using the now well-known Bluetooth (from here simply Blu) on a distro (Debian or Debian-based) in a minute, and then using the graphical tools available on Gnome and KDE.

Let's start:

Install the basic packages, that is bluez-utils and bluz-libs.
Type this command on the console

$ apt-get install bluez-utils

to make sure all is alright it's suggested to install also packages like bluez-firmware e bluez-hcidump which can be found HERE (the same packages could be installed through apt or its graphical front-end synaptic)

Install the graphical tools accordingly to the DE used, respectively: The KDE Bluetooth Framework for KDE users.

For GnomeBluetooth's users, install the front-end by SID repository.

Now plug the Blu drive in to the PC through USB and by root execute the recognizing command

$ hciconfig

you will get an output like this:
hci0: Type: USB
BD Address: 00:0E:8E:00:C0:2E ACL MTU: 377:10 SCO MTU: 16:0
RX bytes:163 acl:0 sco:0 events:22 errors:0
TX bytes:596 acl:0 sco:0 commands:22 errors:0

where the BD address is the hardware address of your drive (or integrated card in the laptop)

Enable your mobile phone's Blu and execute this by root:
$ hcitool scan

you will get:
Scanning ...
00:12:EE:F9:15:20 Debian

this address is fundamental, write it because you will need it (of course this is my mobile's).

Open with an editor /etc/bluetooth/rfcomm.conf and modify it:
# # Bluetooth address of the device
# device 00:12:EE:F9:15:20;
# # RFCOMM channel for the connection
# channel 10;
# # Description of the connection
# comment "Sony_Ericsson V_800";

$ sdptool add --channel=10 OPUSH

with a text editor create a little script named cellpin.sh and save it into /etc/bluetooth
#! /bin/bash
echo PIN: 1234

then type
$ chmod 700 /etc/bluetooth/cellpin.sh

open the hcid.conf file in /etc/bluetooth and modify it this way:
#PIN helper
pin_helper /etc/bluetooth/cellpin.sh;
#pin_helper /usr/bin/bluez-pin;

just execute:
$ hcid -f /etc/bluetooth/hcid.conf

Now when you plug the blu drive in and you enable your mobile's Blu you can exchange files :)
To the Gnome users who wants to send a file through bluetooth simply by clicking on the file with the right mouse key, select: Send to...open a text editor and write these lines

# send file to bluetooth
obexftp -b 00:12:EE:F9:15:20 -p $filepath

Save it with the name send_to_bluetooth, give it the right permissions to execute is as an user and move it into /home/vostronomeutente/.gnome2/nautilus-scripts

Some problems

If your mobile doesn't see the BT drive (so the files can't be transferred between phone and PC) execute this command on the console

$ dbus-send --system --dest=org.bluez /org/bluez/hci0 \

and then
$ org.bluez.Adapter.SetMode string:discoverable

Have fun ;)


An useful report from Gica78R: I followed this howto on Sarge but I had some problems, and the same on Etch. In particular, although in /etc/bluetooth/hcid.conf the iscan enable option was enabled, my computer kept on being invisible from the other devices. I hadn't any problem moving files from the Debian pc to the other devices, or viceversa if those devices knew in some way the PC's Bluetooth address. But if I tried to perform a device search, my pc wasn't visible.

Eventually it's a common bug so, through hcdi.conf settings, the hcin daemon enables only the PSCAN option instead of both PSCAN an ISCAN.
A sort of workaround to solve this:

1) Delete all the content of /var/lib/bluetooth/ (usually it contains a subdirectory for each Bluetooth device detected). ATTENTION: delete only the /var/lib/bluetooth/ content, NOT the directory itself!

2) add in the device section into /etc/bluetooth/hcid.conf this option: discovto 0;

3) reboot the Bluetooth service with this command as root: /etc/init.d/bluetooth restart

When is this necessary? When, although the /etc/bluetooth/hcid.conf contains the iscan enable; option, the output of hciconfig looks like this:

hci0:   Type: USB
BD Address: 00:10:60:D1:4D:C0 ACL MTU: 384:8 SCO MTU: 64:8
RX bytes:455 acl:0 sco:0 events:27 errors:0
TX bytes:358 acl:0 sco:0 commands:24 errors:0

that is the ISCAN option isn't showed as enabled.

After have followed the istructions above, this output should look like:

hci0:   Type: USB
BD Address: 00:10:60:D1:4D:C0 ACL MTU: 384:8 SCO MTU: 64:8
RX bytes:455 acl:0 sco:0 events:27 errors:0
TX bytes:358 acl:0 sco:0 commands:24 errors:0
you can note ISCAN is enabled!


stesha said...

I would like to thank you for the great blog!! It is very usefull for Debian beginnerss like me, and I enjoy reading it...
However I've got problem with my mobile phone Nokia 6233. I can send files to Nokia, but I cannot connect to my Debian PC from my mobile phone. I get "Connection Failed" info on my phone. But when I use SonyEricsson K750i, everything seems to work just fine. What could it be? Thanks in advance!

Anonymous said...

Great blog! The article on bluetooth setup on Debian is really very helpful.