ALSA Bluetooth Headset Driver
=============================

This is a preliminary driver for Bluetooth headsets. The original version of
the driver (dated 2003-09-15 and called 'snd-bluez-sco') worked with kernel 
2.4. This version should work with 2.6 (but not 2.4) and has been renamed 
'snd-bt-sco'.

It has only been tested with the following configurations:

    USB Bluetooth adapter (Bluecore02)
    usb-ohci driver (on a desktop)
    kernel 2.6.4 single processor (there may be race conditions)
    alsa-1.0.3
    HBH-60 Bluetooth headset
    recent bluez tools/utils
    hci_usb with extra patch* for SCO support (hciusb-9byte-2.6.4.patch)
      * this is required

Only 8-bit (8000hz) mode is supported at the moment. You must configure
your hci device with 'hciconfig hci0 voice 0x0040'.

The speaker and microphone volume levels are presented as ALSA mixer 
controls. The HBH-60 only supports speaker volume, so I haven't managed
to test the microphone support.

The ALSA device doesn't produce or consume any audio data when the headset
isn't connected via the bluezsco control program -- this will cause apps
to time out after a few seconds.

Pressing the headset button while connected will disconnect. Pressing
the headset button while disconnected (assuming the headset decides to connect
to your PC rather than your phone) will not work, since the control program
doesn't act as a server.

There seems to be some unexplained noise that's noticeable when a program has
the device open but is not sending audio data. Instead of seeing all silence,
the driver is receiving the occasional non-zero byte. I've added a temporary
filter to eliminate this, but I'd really like to know what's causing it.

There are a number of debugging kernel printk() left in the code since it
is still experimental.

Please get in touch if you manage to get it to work or have any questions.

Jonathan Paisley
http://www.dcs.gla.ac.uk/~jp/snd-bt-sco/
March 14, 2004

Usage
=====

Load the snd-bt-sco kernel module. 

Run 

    btsco-0.2/btsco <bdaddr> <channel>

where <headset> is the bdaddr of your headset.
    
You can find out which channel is appropriate with:

    sdptool search --bdaddr <bdaddr> 0x1108
    
If all is well, a connection to your headset will be made and the SCO
connection handed off to the kernel module. For a simple test you can enable
the 'Loopback' switch via the alsa mixer. This causes the kernel module
to send all incoming audio back to the headset.

For normal use, you can use the ALSA device 'plughw:Headset':

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

You may find the 'aplay' command fails with the following error:

ALSA lib pcm.c:824:(snd_pcm_sw_params) snd_pcm_sw_params: params->avail_min problem for start_threshold

I'm not sure exactly what's causing this, but setting the buffer size to exactly
one second seems to work around it:

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


For recording:

    arecord -D plughw:Headset blah.wav

Installation
============

The download package contains a patch against the ALSA 1.0.3
drivers package, a patch against the hci_usb bluetooth driver
in the kernel, and a directory for the btsco control package.

These installation instructions and the packaging are a bit sketchy, but I
hope you'll get the gist.

# First it is necessary to patch the drivers/bluetooth/hci_usb.c file
# in the linux-2.6.4 kernel tree. For example:

(
    cd /usr/src/linux-2.6.4
    patch -p1 < /path/to/hci_usb-9byte-2.6.4.patch
    make modules
    sudo make modules_install 
    # restart or reload hci_usb module etc
)

# Now deal with the alsa-driver package

# Untar the base package
tar xjvf alsa-driver-1.0.3.tar.bz2

# Patch in the headset driver sources
patch -p0 < alsa-driver-1.0.3-btsco.patch

# We must redo the autoconf things
(   
    cd alsa-driver-1.0.3
    aclocal
    autoconf
    ./configure --with-cards=bt-sco # maybe add --with-kernel=blah
    make
    sudo make install
)

(
    # Depends on btsco.h from alsa-driver
    cd btsco-0.2
    ./configure
    make
)
