Linux bluetooth development
 help / color / mirror / Atom feed
* [Bluez-users] [HOWTO] Headset with alsa
@ 2003-09-29 13:40 Rainer Jochem
  0 siblings, 0 replies; only message in thread
From: Rainer Jochem @ 2003-09-29 13:40 UTC (permalink / raw)
  To: bluez-users; +Cc: jp

[-- Attachment #1: Type: text/plain, Size: 9490 bytes --]


BLUETOOTH-mini-HOWTO for Headsets
=================================

Some words in the beginning:
I'm an absolute newbie to the whole bluetooth stuff and I'm
glad that I was able to get everything working in two days
although it wasn't that easy all the time.
A big "Thank you!" goes to Jonathan Paisley who wrote the
snd-bluez-sco driver and also was patient with me to help
me with my first steps in the Bluetooth-world.
Of course not to forget all the others of bluez: 
kudos to all of you!

The sections marked with /* */ are just some thoughts I had
during writing this stuff. If you are only interested in the
howto, ignore them :)


I have tested it using 

  - Anycom AHS-10 Headset
  - Anycom USB100 Bluetooth-dongle
  - Bluetake BT007SV Bluetooth-dongle

  - Kernel 2.4.22
  - Kernel 2.4.21-ac4

  - Alsa 0.9.6 (www.alsa-project.org)
    (Alsa 0.9.7 currently won't work)
    - alsa-driver-0.9.6
    - alsa-lib-0.9.6

  - from bluez.sourceforge.net:
    - bluez-libs-2.4.tar.gz
    - bluez-utils-2.3.tar.gz
    - bluez-sdp-1.5.tar.gz
    - bluez-pan-1.1.tar.gz
    - bluez-hcidump-1.5.tar.gz
    - bluez-hciemu-1.0.tar.gz
    - bluez-bluefw-0.9.tar.gz

  - from http://www.dcs.gla.ac.uk/~jp/snd-bluez-sco/
    - snd-bluez-sco-2003-09-15.tar.gz 
 
  - Time (lots of)...



Let's start:
~~~~~~~~~~~~

First, you'll need to patch the alsa-driver, alsa-libs and your
kernel:

Unpack the alsa stuff and the snd-bluez-sco package from J. Paisley.
You'll find the required patches in the snd-bluez-sco directory.

So do a:
   cd alsa-driver-0.9.6
   patch -p1 < alsa-driver-0.9.6-bluezsco.patch

   cd alsa-libs-0.9.6
   patch -p1 < alsa-lib-0.9.6-bluezsco.patch

   cd /usr/src/linux (or where your kernel-sources are)
   patch -p1 < hciusb-isoc.patch
   (this should not produce any errors)

   You might need to give the patch command the absolute path to
   the .patch-files 
   (e.g. patch -p1 < /tmp/snd-bluez-sco-2003-09-15/hciusb-isoc.patch)  


Depending on the version of your snd-bluez-sco package it might be
neccessary to add this line to alsa-driver-0.9.6/alsa-kernel/core/Makefile:
 
 obj-$(CONFIG_SND_BLUEZ_SCO) += snd-pcm.o snd-page-alloc.o snd.o snd-hwdep.o
 
(see http://sourceforge.net/mailarchive/message.php?msg_id=6056143)

This line was forgotten in the patch and I got "unresolved symbols"
when I tried to load the module without it.



Having everything patched, you'll need bluetooth support in your
kernel:

   cd /usr/src/linux
   make menuconfig	(or xconfig, or whatever you like)
   in "Bluetooth support" enable all the modules.
   
   /* 
    * I actually don't know what modules are really 
    * needed, I've just switched everything on and 
    * it worked - so someone with more experience
    * may enlighten me :)
    */

   Then build and install your kernel (and the modules).



Now, it's time for alsa:

   cd alsa-driver-0.9.6
   aclocal
   autoconf
   ./configure --with-cards=bluez-sco 
   (depending on your system you might want to add other soundcards or
   things like oss too - see ./configure --help for all the possibilities)
   make
   make install

   cd alsa-lib-0.9.6
   ./configure
   make
   make install



Then install the bluez-packages:

   Unpack every archive and install each one:
   cd <package-name>
   ./configure
   make
   make install



...build the bluezsco-tool

   cd snd-bluez-sco-2003-09-15/bluezsco-0.1/
   ./configure
   make


After having built and installed everything you'll need to edit some
files in /etc:

   in /etc/modules.conf add the following lines:
      alias net-pf-31 bluez
      alias bt-proto-0 l2cap
      alias bt-proto-2 sco
      alias bt-proto-3 rfcomm
      alias bt-proto-4 bnep
      alias tty-ldisc-15 hci_uart

   or - depending on your distro (e.g. debian), write these 
   lines in /etc/modutils/bluez (and do an update-modules)


   in /etc/bluetooth/ you'll find these files:
      hcid.conf
      pin
      rfcomm.conf

   I didn't need to edit hcid.conf. Just enter the
   pin of your headset in the pin-file and change the 
   device-entry in rfcomm.conf to the MAC (or btaddr 
   how it's called in the bluetooth-world) of your 
   Bluetooth-USB-dongle.

   /*
    * Again, I don't really know what all the possible
    * options are good for (some of them are described though)
    * so perhaps someone might explain them a bit further
    * than it is in the files. (I like to know what I'm
    * doing when I enable certain features without having
    * to consult an RFC first ;)
    */ 


If you managed it to proceed until here, it's now 
time to reboot your machine with the new kernel.





Testing...
~~~~~~~~~~

Plug-in your Bluetooth adapter and start the Bluetooth-subsystem
with 
     /etc/init.d/bluetooth start

Check if the following modules are loaded (using lsmod):
     
     snd-bluez-sco
     hci_usb
     rfcomm
     l2cap
     bluez

If not, load them with modprobe.

Now, "hciconfig hci0" should show you the Bluetooth-Adapter:

hci0:   Type: USB 
        BD Address: xx:xx:xx:xx:xx:xx ACL MTU: 192:8  SCO MTU: 64:8
        UP RUNNING PSCAN ISCAN 
        RX bytes:52636 acl:27 sco:1905 events:80 errors:0
        TX bytes:52112 acl:25 sco:1895 commands:31 errors:0

Then, switch the Headset on in Pairing-mode (on the AHS-10: 
hold the On-Off-Switch pressed for 10 seconds until the LED
starts flashing red and green)
Do "sdptool search HSET". If a window appears asking for the
headset-pin, enter it (0000 is factory default). 

 /*
  * I might be wrong... but if I have an /etc/bluetooth/pin 
  * file, why is it asking me again for the pin and doesnt
  * use the one specified there?
  * Also, the pin-window irritates me... I was logged in via
  * ssh -X on my notebook and ran this command on my PC
  * and this window appeared on the notebook-screen and not
  * on the monitor of my PC.... what's that ?
  * Why is this hardcoded to the local Xserver of the PC where
  * the bluetooth-stuff is running on? 
  * (..one should LART the person who did that ;)
  *
  * Another thing which I think is quite annoying is the fact
  * that pin and btaddr of the headset must be entered 
  * manually each time. Support for a ~/.bluetoothrc would
  * be much more comfortable.
  */

After this you should see an output similar to this:

    Inquiring ...
    Searching for HSET on xx:xx:xx:xx:xx:xx ...
    Service Name: Headset
    Service RecHandle: 0x20000
    Service Class ID List:
      "Headset" (0x1108)
      "Generic Audio" (0x1203)
    Protocol Descriptor List:
      "L2CAP" (0x0100)
      "RFCOMM" (0x0003)
      Channel: 6
    Language Base Attr List:
      coade_ISO639: 0x656e
      encoding:    0x6a
      base_offset: 0x100

xx:xx:xx:xx:xx:xx is the btaddr of your headset 
(called MAC ID on the sticker of the headset)



...aaand Action!
~~~~~~~~~~~~~~~~

If everything worked fine until here, the following
command should finally let you send and receive audio
from your headset:

snd-bluez-sco-2003-09-15/bluezsco-0.1/bluezsco <btaddr> <channel>

where channel is the same as in the output of the sdptool command
above. i.e. 
    
    bluezsco xx:xx:xx:xx:xx:xx 6
     
And you should get an output similar to this:

    Device is 2:0
    Voice setting: 0x0040
    RFCOMM channel connected
    SCO audio channel connected (handle 44, mtu 64)
    Setting sco fd
    Done setting sco fd
    AT+VGS=15
    Sending up speaker change 15


That's it!

Now you should be able to play s.th. using

    aplay -D plughw:Headset blah.wav
or
    alsaplayer -d plughw:Headset blah.mp3

And for recording:

    arecord -D plughw:Headset blah.wav


If you examine your audiodevices, you should also find your headset
there. On my PC it was /dev/dsp1, on my notebook /dev/unknown 
...yes, really... 


Quite easy, isn't it? *SCNR*



Notes for devfs-users:
~~~~~~~~~~~~~~~~~~~~~~

If you installed the debian packages and have s.th. like

    /etc/devfs/devices.d/bluez

on your system - delete the file, or uncomment every entry
as described in:

http://sourceforge.net/mailarchive/message.php?msg_id=5461094

It'll work then. (my notebook has devfs and I needed to do so)




That's all folks...
Again,  I'm a complete bluetooth-newbie and just a linux-geek
who wanted to get his bluetooth headset working with linux. So if you
have any questions about some details or why something isn't working:
I'm the wrong person to ask.
Search the Mailing-list archives and read the stuff on bluez.sf.net
or if this shouldn't help, ask the bluetooth-gurus on the
mailing-list.


Of course I welcome any feedback and improvements on this topic :)


Some additional thoughts:
Is it possible to have the BT-dongle run via hotplug-agent so
everything (modules, enabling of the voice settings) is done 
automagically and having the hcid listen to commands from the 
headset (e.g. pushing a knob there) and doing a certain action 
(like enabling/disabling the voice connection). 
I guess this is what the hcid is good for?



-- 
This email was written on 100% recycled electrons.

Rainer Jochem	              rainer@graphics.cs.uni-sb.de
http://www.admininside.org/   http://graphics.cs.uni-sb.de/~rainer/


[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-09-29 13:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-09-29 13:40 [Bluez-users] [HOWTO] Headset with alsa Rainer Jochem

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox