Tuesday, May 6, 2008

Bluetooth

Bluetooth USB Dongle

Enable Bluetooth support

  • Check whether Dongle is recognized and working. We use a kernel with bluetooth support! ;)

Start debian bluetooth support:

/etc/init.d/bluez-utils start

The log:

Apr  2 20:54:04 tadpole hcid[19051]: Bluetooth HCI daemon
Apr 2 20:54:04 tadpole hcid[19051]: Starting security manager 0
Apr 2 20:54:04 tadpole sdpd[19055]: Bluetooth SDP daemon
Apr 2 21:04:24 tadpole hcid[19204]: HCI dev 0 registered
Apr 2 21:04:24 tadpole hcid[19204]: HCI dev 0 up

With bluez-utils started successfully we use hciconfig to determine the dongle status:

root@tadpole:~# hciconfig
hci0: Type: USB
BD Address: 00:09:DD:10:50:F8 ACL MTU: 192:8 SCO MTU: 64:8
UP RUNNING PSCAN ISCAN AUTH ENCRYPT
RX bytes:101 acl:0 sco:0 events:13 errors:0
TX bytes:296 acl:0 sco:0 commands:12 errors:0

This means, the USB bluetooth dongle is operational.

  • We may make the bluetooth stuff be survive reboot:
update-rc.d bluez-utils defaults

Device Detection

  • Put mobile phone in See-Me mode and scan for it:
root@tadpole:~# hcitool scan
Scanning ...
00:0F:DE:14:47:21 TF-Mobile
root@tadpole:~# hcitool inq
Inquiring ...
00:0F:DE:35:71:22 clock offset: 0x569d class: 0x520204

Yep, found the right thingy. We might want to use graphical interfaces (http://gentoo-wiki.com/HOWTO_mobile_phone,_Bluetooth_and_GNOME) to interact with our mobile phone.

Once we know our phone's bluetooth MAC we can ping the phone as we would do on a standard network to check network availability:

root@tadpole:~# l2ping 00:0F:DE:13:88:91
Ping: 00:0F:DE:13:88:91 from 00:09:DD:13:92:F8 (data size 20) ...
0 bytes from 00:0F:DE:13:88:91 id 0 time 38.70ms
0 bytes from 00:0F:DE:13:88:91 id 1 time 40.69ms
0 bytes from 00:0F:DE:13:88:91 id 2 time 43.19ms
0 bytes from 00:0F:DE:13:88:91 id 3 time 37.67ms
0 bytes from 00:0F:DE:13:88:91 id 4 time 35.21ms
5 sent, 5 received, 0% loss

Interestingly enough, the l2ping to a Nokia 6230i is a bit faster. ;)

Ping: 08:00:28:4F:1B:A6 from 00:09:DD:13:88:98 (data size 20) ...
0 bytes from 08:00:28:4F:1B:A6 id 0 time 16.53ms
0 bytes from 08:00:28:4F:1B:A6 id 1 time 29.33ms
0 bytes from 08:00:28:4F:1B:A6 id 2 time 29.63ms
0 bytes from 08:00:28:4F:1B:A6 id 3 time 34.59ms
0 bytes from 08:00:28:4F:1B:A6 id 4 time 33.41ms
0 bytes from 08:00:28:4F:1B:A6 id 5 time 27.51ms
0 bytes from 08:00:28:4F:1B:A6 id 6 time 41.03ms

Connection Establishing

  • We might change the name XYZ line in /etc/bluetooth/hcid.conf to something more personal. :) See man 5 hcid.conf for more.
  • Write a whatever PIN into /etc/bluetooth/pin. Remember it and enter it when prompted for a PIN connecting from your phone to the dongle.
  • When connecting from the phone to the dongle have a look at the logs, /var/log/syslog:
Apr  2 20:26:32 tadpole hcid[18268]: link_key_request (sba=00:09:DD:13:92:F8, dba=00:0F:DE:13:88:91)
Apr 2 20:26:32 tadpole hcid[18268]: pin_code_request (sba=00:09:DD:13:92:F8, dba=00:0F:DE:13:88:91)
Apr 2 20:26:33 tadpole hcid[18268]: link_key_notify (sba=00:09:DD:13:92:F8)
Apr 2 20:26:33 tadpole hcid[18268]: Replacing link key 00:09:DD:13:92:F8 00:0F:DE:13:88:91
Apr 2 20:26:34 tadpole hcid[18268]: link_key_request (sba=00:09:DD:13:92:F8, dba=00:0F:DE:13:88:91)
Apr 2 20:27:11 tadpole hcid[18268]: link_key_request (sba=00:09:DD:13:92:F8, dba=00:0F:DE:13:88:91)
Apr 2 20:27:16 tadpole hcid[18268]: link_key_request (sba=00:09:DD:13:92:F8, dba=00:0F:DE:13:88:91)
  • We may now push our data from the phone to the computer with the USB-dongle connected.
  • It might be necessary to grant access to our X server for the helper tool to query us for the PIN. To do so execute xhost + as user.

Device Capability Discovery

  • Query the capabilities:
sdptool browse

The T630 answer and the one the Nokia 6230i gave.

Pulling Data From Mobile

  • First query the list of available files:
obexftp -b  00:0F:DE:13:88:11 -c Bilder
Browsing 00:0F:DE:13:88:11 ...
Channel: 7
No custom transport
Connecting...bt: 1
done
Sending Bilder... Sending Bilder... done
Receiving (null).../





done
Disconnecting...done
  • Get specific file:
radtkens@tadpole:$  obexftp -b  00:0F:DE:13:88:11 -c Bilder  -g "img(27).jpg"
Browsing 00:0F:DE:13:88:11 ...
Channel: 7
No custom transport
Connecting...bt: 1
done
Sending Bilder... Sending Bilder... done
Receiving img(27).jpg...-done
Disconnecting...done

The image is now in pwd. Fire up gqview and see! :-)

  • To boldly fetch any picture in Bilder directory, use this one-liner:
for i in $(obexftp -b 00:0F:DE:13:88:11 -c Bilder -l 2>&1 | grep .jpg | \
sed 's/.*name="//g; s/" size.*//g'); do obexftp -b 00:0F:DE:13:88:11 -c Bilder -g "$i"; done;
  • We rename the files to a nicer naming scheme:
for i in $(ls *.jpg); do \
no=$(echo $i|sed 's/img(\(.*\)).jpg/\1/g');
mv -vi $i img_$(printf "%03.0f" $no).jpg;
done

Before: "img(1).jpg", after: "img_001.jpg". Have fun! :-)

Sync Tools

  • obexftp is suitable for pulling images.
  • Synchronise contacts, events and tasks using a tool such as multisync.
  • multisync has IRDA and Bluetooth plugins as well as backup, evolution and SyncML plugins.


Headset

Connection

Start bluetooth (debian way):

/etc/init.d/bluez-utils start

Check whether our bluetooth is up and running:

hcitool dev
Devices:
hci0 00:05:33:10:71:F3

This is the MAC address of our USB-bluetooth adapter.

Put your headset into pairing mode and scan for it:

hcitool scan

It should have discovered your headset, so connect to it via:

hcitool cc 

This will require us to enter the headset PIN: To prevent it from asking every time we connect we setup a small pin-helper /etc/bluetooth/pin-helper.sh script:

#!/bin/sh
echo "PIN:0000"

Modify /etc/bluetooth/hcid.conf to match this filename:

pin_helper /etc/bluetooth/pin-helper.sh;

Bluez Configuration Files

/etc/bluetooth/hcid.conf

options {
autoinit yes;
security user;
pairing multi;
pin_helper /etc/bluetooth/pin-helper.sh;
}
device {
name "My_bt%d";
class 0x3e0100;
iscan enable; pscan enable;
lm accept;
lp rswitch,hold,sniff,park;
auth enable;
encrypt enable;
}


/etc/bluetooth/rfcomm.conf

rfcomm0 {
bind yes;
device ;
channel 1;
comment "My-bt";
}

Build btsco

Requirements:

From btsco README:

  • automake-1.7
  • libbluetooth-dev
  • libasound2-dev (aka alsa-devel)
  • a recent (2.6.11.7 or newer) kernel with *integrated* alsa enabled (it won't work with the "standalone" alsa drivers that are a separate download from the kernel)

Get btsco from CVS

cvs -d:pserver:anonymous@cvs.sf.net:/cvsroot/bluetooth-alsa login
cvs -d:pserver:anonymous@cvs.sf.net:/cvsroot/bluetooth-alsa co btsco

btsco Compilation

cd btsco/
./bootstrap
./configure
make
make install

We might skip this one as we need some tools built that are otherwise wiped again:

make maintainer-clean

Kernel Module Compilation

For SCO (two-way voice quality audio) you need a kernel with the emu10k1 driver selected (this is one of the drivers that forces the inclusion of the implementation of "snd_hwdep_new").

cd kernel/
make
make install
depmod -e
make clean

Using btsco

modprobe snd_bt_sco

If running esd stop it:

esdctl stop

Do:

hciconfig hci0 voice 0x0060

Put headset into pairing mode. It should not be connected with your mobile as it would prevent pairing with our linux box. Run btsco with -v for verbose mode or with -f for daemon mode:

btsco 

This might ask for the headset PIN. Standard is with most devices 0000.

Testing

Play some WAV file (not every WAV will work, try some):

aplay -B 1000000 -D plughw:Headset my_wav_that_works.wav

The btsco seems in alpha stage. While playing a WAV may work the first time it fails on subsequent tries. Leaving this in the kernel log:

radtkens@tadpole:$ dmesg | tail
[17190778.216000] snd-bt-sco: Shift problem detected! Fixing to 1.
[17190778.216000] snd-bt-sco: Shift problem detected! Fixing to 0.
[17190779.196000] snd-bt-sco: playback_trigger 0
[17190779.196000] snd-bt-sco: setting playback to NULL
[17190779.200000] snd-bt-sco: Disposing of previous socket count 2
[17190782.504000] snd-bt-sco: playback_open
[17190782.508000] snd-bt-sco: prepare ok bps: 16000 size: 16002 count: 4000
[17190782.508000] snd-bt-sco: playback_trigger 1
[17190782.508000] snd-bt-sco: setting playback to bspcm
[17191026.524000] snd-bt-sco: Disposing of previous socket count 2
[17191026.560000] hci_scodata_packet: hci0 SCO packet for unknown connection handle 48
[17191026.560000] hci_scodata_packet: hci0 SCO packet for unknown connection handle 48
[17191026.560000] hci_scodata_packet: hci0 SCO packet for unknown connection handle 48

Unloading (rmmod sco) and reloading (modprobe sco) the sco kernel module reenables playback..

Sample output from verbose btsco:

radtkens@tadpole:$ /usr/local/btsco/bin/btsco MAC -v
btsco v0.41
Device is 2:0
Voice setting: 0x0060
RFCOMM channel 1 connected
Using interface hci0
recieved AT*ECBP=?
recieved AT+CLIP=1
recieved AT+CSCS="UTF-8"
recieved AT+CLAN?
speaker volume: 0 mic volume: 0
i/o needed: connecting sco...
connected SCO channel
Done setting sco fd
speaker volume: 0 mic volume: 0
driver is not in use
disconnected SCO channel
RFCOMM channel lost

Tipps

To use our bluetooth headset with skype we start btsco right before we start skype. skype now offers one more input method in the preferences. Have fun! :-)

We may configure the daemonized btsco using ~/.btscorc.

Links

  • btsco homepage (http://bluetooth-alsa.sourceforge.net/), alsa support for bluetooth headsets
  • btsco howto (http://www.linux.ie/articles/bluetoothheadset.php) short and good.
  • List of bluetooth devices (http://www.holtmann.org/linux/bluetooth/features.html) with features
  • Bluetooth howto collection (http://www.holtmann.org/linux/bluetooth/)
  • How to whack'n'hack bluetooth headsets (http://isospider.net/news/?a=view&id=1520), his homepage (http://www.digitalmunition.com/) and the tools (http://trifinite.org/trifinite_downloads.html)
  • Bluetooth howto (http://www.des.udc.es/~mpquique/HOWTO/en-txt/Bluetooth-Howto.txt), features some note on obex and push mechanism.
  • General bluetooth information (http://www.developertutorials.com/tutorials/wireless-technology/linux-wireless-networking-050504/page3.html) and short overview of bluez-utils (such as hci../sdpd/..).
  • Nice bluetooth tool compilation (http://tuxmobil.org/bluetooth_cell_apps.html)
  • Using IRDA (http://ale.shouldshave.org/t630_linux.html)
  • Nice page about using bluetooth (http://www.caside.lancs.ac.uk/java_bt.php) with linux including determining the notebooks OBEX DIAC.
  • Gentoo and bluetooth (http://www.gentoo.org/doc/en/bluetooth-guide.xml) presenting a bunch of gnome and kde bluetooth tools.
  • Nokia's Smartphone with Python (http://pramode.net/articles/lfy/mobile/pramode.html). There's also an interesting section called 'Parting thoughts', give it a try, that's a good thought. :)
  • Wikipedia Bluetooth (http://en.wikipedia.org/wiki/Bluetooth) page.
  • Jean Tourrilhes' bluetooth (http://www.hpl.hp.com/personal/Jean_Tourrilhes/bt/) page.
  • Running a bluetooth network (http://www.triptico.com/software/bluetooth.html)
  • Bluez (http://www.bluez.org/) homepage.

Bluetooth and GPRS

No comments: