Manually using Bluetooth

From Openmoko

(Difference between revisions)
Jump to: navigation, search
(-cat)
(Further reading)
 
(38 intermediate revisions by 10 users not shown)
Line 5: Line 5:
 
This page details how to use bluetooth from the command line.
 
This page details how to use bluetooth from the command line.
 
We have quite a lot of plans about what exactly Bluetooth should be used for.
 
We have quite a lot of plans about what exactly Bluetooth should be used for.
 +
 +
'''Please keep in mind that whenever <code>hcid</code> or <code>pand</code> or <code>hidd</code> are mentioned it means that instructions are applicable only to bluez3 systems which is deprecated ages ago. Modern bluez4 uses only one daemon - <code>bluetoothd</code> and you are supposed to use dbus api directly to configure it. For pairing from command line use simple-agent script.'''
  
 
== Power it up ==
 
== Power it up ==
 +
'''Bluez4-compatible'''
  
 
Power up the adapter by clicking on the bluetooth icon in the top bar and selecting power on.
 
Power up the adapter by clicking on the bluetooth icon in the top bar and selecting power on.
  
The old way to do it is a shell command (for kernels before 2.6.24):
+
For any FSO-based distro (including SHR) you want to consult [[FSO_Resources]] page.
  
root@fic-gta01:~# echo 1 > /sys/bus/platform/devices/gta01-pm-bt.0/power_on
+
For others consult your distro's documentation. The most low-level way to power bluetooth on is to
 
+
  echo 1 > /sys/bus/platform/devices/neo1973-pm-bt.0/power_on
For kernel 2.6.24 (or later) use
+
 
+
  root@om-gta02:~# echo 1 > /sys/bus/platform/devices/neo1973-pm-bt.0/power_on
+
 
+
and on the GTA02 *only* (i.e. not on the GTA01) also use
+
 
+
root@om-gta02:~# echo 0 > /sys/bus/platform/devices/neo1973-pm-bt.0/reset
+
 
+
But nowadays[http://permalink.gmane.org/gmane.comp.hardware.smartphones.userland/165], one should use [[Dbus device API]]s!
+
  
 
At the shell, "hciconfig" should print information about the adapter if it powered up properly:
 
At the shell, "hciconfig" should print information about the adapter if it powered up properly:
Line 36: Line 30:
 
  hciconfig hci0 up
 
  hciconfig hci0 up
  
== Bluetooth Functions ==
+
== How to use bluez4 dbus API ==
 +
'''Bluez4-compatible'''
  
===Configuring Bluetooth on Openmoko 2007.2 (August 27 snapshot with kernel 2.6.21.6-moko11) ===
+
You can do it with [[OpenmokoFramework/mdbus]] or with
 +
<code>dbus-send</code>.  
  
In file /etc/bluetooth/hcid.conf you should change the passkey from BlueZ to something numeric. For testing you may use "0000". Also, you can set the name to "Neo (%d)".
+
First you need to get path to the default bluetooth adapter which
 +
should appear when you have bluetoothd running and bluetooth device is
 +
powered on. Do it like this:
  
=== Scanning for bluetooth devices ===
+
export BTADAPTER=`dbus-send --system --dest=org.bluez --print-reply / org.bluez.Manager.DefaultAdapter | tail -1 | sed 's/^.*"\(.*\)".*$/\1/'`
 +
 
 +
To introspect with dbus-send you can employ something like this:
 +
dbus-send --system --dest=org.bluez --print-reply $BTADAPTER org.freedesktop.DBus.Introspectable.Introspect
 +
 
 +
The next example is how to make your device discoverable:
 +
dbus-send --system --dest=org.bluez --print-reply $BTADAPTER org.bluez.Adapter.SetProperty string:Discoverable variant:boolean:true
 +
 
 +
== Scanning for bluetooth devices ==
 +
'''Bluez4-compatible'''
  
 
  hcitool scan
 
  hcitool scan
Line 48: Line 55:
 
This will list the addresses of any discoverable bluetooth devices in the vicinity
 
This will list the addresses of any discoverable bluetooth devices in the vicinity
  
=== passkey agent example ===
+
== Pair ==
 +
'''Bluez4-compatible'''
 +
 
 +
Pairing is nothing special, do it with simple-agent [http://git.kernel.org/?p=bluetooth/bluez.git;a=blob_plain;f=test/simple-agent;hb=HEAD] as described here or with any other agent you like as described in that agent's documentation. Bluez also comes with a simple command-line agent written in C, you can grab the source from [http://git.kernel.org/?p=bluetooth/bluez.git;a=blob_plain;f=test/agent.c;hb=HEAD] .
 +
 
 +
Make sure the bluetooth chip is powered up (see below) and that bluetoothd is running.
 +
 
 +
Now, to actually pair with other device, you will need the simple-agent script. If you do not have that already, download, put it in /usr/local/bin/ and run '''chmod a+x /usr/local/bin/simple-agent'''
 +
 
 +
Now put the other device into pairing mode and run '''hcitool scan'''. Find that device and use its address in the command '''simple-agent hci0 XX:XX:XX:XX:XX:XX'''. If you give a third parameter (what it is doesn't matter) to simple-agent, it will disconnect then reconnect.
 +
 
 +
If you give it only one parameter, it will register as an agent and will wait for other devices to initiate pairing. Feel free to tweak that script to your needs (e.g. to hardcode a pin to use).
 +
 
 +
== HID (Human Input Device) ==
 +
'''Bluez4-compatible'''
 +
 
 +
Pair with your device first.
 +
 
 +
Then do
 +
dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_18_00_00_C2_37 org.bluez.Input.Connect
  
There should be a passkey agent built into openmoko, but for now you can start up the example passkey agent and set the pin code there. This will allow for new pairings to be made when you attempt a connection.
+
Where <code>00_18_00_00_C2_37</code> is the address of your HID device. You can query for the device address with:
  
  passkey-agent --default 0000 &
+
  dbus-send --system --dest=org.bluez --print-reply $BTADAPTER org.bluez.Adapter.ListDevices
  
Note: the passkey-agent is not required in Openmoko 2007.2 with kernel 2.6.21.6 as of at least since August 27 (maybe earlier).
+
Enjoy.
  
In debian there is no passkey-agent binary but the package bluez-utils has its source code at /usr/share/doc/bluez-utils/examples/passkey-agent.c.gz.
+
''I've tested this with a BT mouse (no issues) and with SE cellphones that can pretend to be a mouse and keyboard. Both cellphones work without issues with my laptop using exactly the same procedure. The first phone seemed to work for a couple of seconds with FR too, after that the connection was lost. The second didn't work with FR at all.  
  
=== HID (Human Input Device) ===
+
I tried an external BT dongle (broadcom iirc) with both my FR and laptop (to eliminate hardware differences) and the result was the same. Even though bluez and kernel versions were roughly the same O_o -- PaulFertser''
  
 
==== Being able to use HID devices ====
 
==== Being able to use HID devices ====
 +
'''deprecated bluez3-specific, will be removed'''
  
 
If you are trying to connect a keyboard and you have bluez4, see [[Freedom_Slim_Keyboard]].
 
If you are trying to connect a keyboard and you have bluez4, see [[Freedom_Slim_Keyboard]].
Line 114: Line 141:
  
 
(See also [[Freedom_Slim_Keyboard]] for fso scripts which work with bluez4.)
 
(See also [[Freedom_Slim_Keyboard]] for fso scripts which work with bluez4.)
 +
 +
==== Mouse ====
 +
Edit /etc/X11/Xserver and replace ''tslib'' with ''/dev/input/mice''.
 +
<pre>
 +
      "GTA02")
 +
                if [ `screen_width` -gt 330 ] ; then
 +
                    DPI=285
 +
                else
 +
                    DPI=140
 +
                fi
 +
                ARGS="$ARGS -dpi ${DPI} -screen ${SCREEN_SIZE} -mouse /dev/input/mice -root-ppm /usr/share/pixmaps/xsplash-vga.ppm vt1"
 +
                XSERVER=/usr/bin/Xglamo
 +
                ;;
 +
</pre>
  
 
==== Acting as HID device ====
 
==== Acting as HID device ====
Line 119: Line 160:
 
We want to be able to use the Neo as a HID device, being able to use it as controller for presentations. See [[ReMoko]]
 
We want to be able to use the Neo as a HID device, being able to use it as controller for presentations. See [[ReMoko]]
  
=== RFCOMM ===
+
== RFCOMM ==
 +
'''i guess it's Bluez4-compatible'''
  
 
Here's how to connect to an external Bluetooth GPS and read NMEA data (Tested with a Holux GPSSlim236 and a Nokia LD-3W ).
 
Here's how to connect to an external Bluetooth GPS and read NMEA data (Tested with a Holux GPSSlim236 and a Nokia LD-3W ).
Line 163: Line 205:
 
If you have nothing better to do, you can now pinpoint my office :-).
 
If you have nothing better to do, you can now pinpoint my office :-).
  
=== OBEX ===
+
== OBEX ==
 +
'''Mostly bluez4-compatible, you don't need to edit hcid.conf at all, bluetoothd will take care of using proper parameters itself'''
 +
 
 
OBEX (abbreviation of OBject EXchange, also termed IrOBEX) is a communications protocol that facilitates the exchange of binary objects between devices. Here is the notes about how to use OBEX to send/receive files via bluetooth in NEO.
 
OBEX (abbreviation of OBject EXchange, also termed IrOBEX) is a communications protocol that facilitates the exchange of binary objects between devices. Here is the notes about how to use OBEX to send/receive files via bluetooth in NEO.
  
power on bluetooth:
+
power on bluetooth.
if you use FSO image
+
root@om-gta02:~# dbus-send --system --dest=org.freesmartphone.odeviced --type=method_call --print-reply
+
/org/freesmartphone/Device/PowerControl/Bluetooth org.freesmartphone.Device.PowerControl.SetPower int32:1
+
else: (GTA02 only)
+
root@om-gta02:~# echo 1 > /sys/bus/platform/devices/neo1973-pm-bt.0/reset
+
root@om-gta02:~# echo 0 > /sys/bus/platform/devices/neo1973-pm-bt.0/reset
+
  
 
[http://linux.die.net/man/5/hcid.conf hcid.conf]  
 
[http://linux.die.net/man/5/hcid.conf hcid.conf]  
Line 309: Line 347:
 
How to pair with a bluetooth device, check [http://wiki.bluez.org/wiki/Security bluez wiki]
 
How to pair with a bluetooth device, check [http://wiki.bluez.org/wiki/Security bluez wiki]
  
=== Networking ===
+
== Networking ==
 +
 
 +
''' Please note that whenever <code>hcid</code> or <code>pand</code> is mentioned it means that instructions are applicable only to bluez3 systems which is deprecated ages ago. Modern bluez4 uses only one daemon - <code>bluetoothd</code> and you are supposed to use dbus api directly to configure it to connect as a client or act as a server. The API is described at [http://git.kernel.org/?p=bluetooth/bluez.git;a=blob;f=doc/network-api.txt;hb=HEAD]. Please update other instructions as soon as you get it working.'''
 +
 
 +
To ease the task you can try to use [https://launchpad.net/blueman Blueman] GUI software on one or both sides of the link.
 +
 
 +
=== Information about bluez4 networking ===
 +
'''I managed to successfully connect from PocketPC PDA (used as PANU) to my FR (both NAP and GN configurations worked). Also i was able to use my laptop as PANU and my FR as GN/NAP, reverse should work too'''.
 +
 
 +
For some reason bluez4 needs ipv6 (fixed on 2009-03-10) and ethernet bridging kernel support. So to avoid more problems you better have it. Also you'll need bnep kernel module.
 +
 
 +
==== Bluetooth networking concepts ====
 +
This HOW-TO is directly applicable only to bluez3 but still worth reading to understand PANU/GN/NAP roles: [http://bluez.sourceforge.net/contrib/HOWTO-PAN].
 +
 
 +
In short, GN is network bridge (aka hub/switch), NAP is network router and PANU is a network client.
 +
 
 +
You can enable or disable various roles by setting <code>Enable</code> property to true/false. Example for GN:
 +
dbus-send --system --dest=org.bluez --print-reply $BTADAPTER org.bluez.NetworkHub.SetProperty string:Enabled variant:boolean:true
 +
 
 +
For PANU use org.bluez.NetworkPeer interface and for NAP use org.bluez.NetworkRouter.
 +
 
 +
You might want to know UUID of GN for later use, so you need to read its properties:
 +
dbus-send --system --dest=org.bluez --print-reply $BTADAPTER org.bluez.NetworkHub.GetProperties
 +
 
 +
To use NAP you'll need to create bridge device manually with
 +
brctl addbr pan1
 +
For GN bridge <code>pan0</code> is created automatically on <code>bluetoothd</code> start.
 +
 
 +
''I can't see a difference between GN and NAP in the Linux networking context so i suppose GN is the easiest to get going''
 +
 
 +
==== Pairing ====
 +
Pairing is nothing special, do it with simple-agent as described in other sections or by any other pairing agent.
 +
 
 +
==== Trust ====
 +
On GN/NAP role you need to ''trust'' the PANU peer:
 +
dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_06_6E_17_27_E0 org.bluez.Device.SetProperty string:Trusted variant:boolean:true
 +
 
 +
Where <code>00_06_6E_17_27_E0</code> is the MAC of peer.
 +
 
 +
==== Connection establishing ====
 +
On PANU you need to have a helper script <code>panu.py</code>:
 +
<pre>
 +
#!/usr/bin/python
 +
 
 +
import dbus
 +
import sys
 +
import os
 +
 
 +
bus = dbus.SystemBus()
 +
network = dbus.Interface(bus.get_object("org.bluez",
 +
                sys.argv[1]),
 +
                "org.bluez.Network")
 +
 
 +
network.Connect("GN")
 +
print "Networking established, exit the shell to end this session"
 +
os.spawnl(os.P_WAIT, os.environ['SHELL'])
 +
print "Networking released"
 +
</pre>
 +
 
 +
Then you do:
 +
./panu.py $BTADAPTER/dev_00_06_6E_17_27_E0
 +
 
 +
Where <code>00_16_CE_E4_44_D5</code> is MAC of GN/NAP.
 +
 
 +
Hopefully after this you'll have two new interfaces <code>bnep0</code> created on both sides and it'll be added to the <code>pan0</code> bridge on GN.
 +
 
 +
Set up packet forwarding, IP addresses etc. as usual.
  
 
==== Using PC's connection from Neo ====
 
==== Using PC's connection from Neo ====
  
 
===== Bluetooth networking with a Linux system =====
 
===== Bluetooth networking with a Linux system =====
 +
'''deprecated bluez3-specific, to be removed soon'''
  
 
Bluetooth should behave just like our usbnet and provide full TCP/IP access to the phone.  BNEP has to be used.
 
Bluetooth should behave just like our usbnet and provide full TCP/IP access to the phone.  BNEP has to be used.
Line 636: Line 741:
  
 
== Once Again, Bluetooth Headset on Freerunner ==
 
== Once Again, Bluetooth Headset on Freerunner ==
 +
'''Bluez4-compatible'''
  
 
=== List of known to work headsets ===
 
=== List of known to work headsets ===
no-name "Jabra", discovered as "Bluetooth headset" -- PaulFertser
+
Moved to [[List_of_bluetooth_headsets]]
 
+
'''Plantronics Voyager 855''' -- DigitalPioneer
+
 
+
no-name '''BT Headset-12''' -- Vanous
+
 
+
'''Plantronics Explorer 220''' -- Vendion
+
 
+
'''Insmat (HS200?), a real cheap one''' -- Rakshasa
+
  
 
=== List of non-working headsets ===
 
=== List of non-working headsets ===
Line 660: Line 758:
  
 
If you're using SHR unstable, you already has a correct state file and rules.yaml, so you can skip to the pairing section.
 
If you're using SHR unstable, you already has a correct state file and rules.yaml, so you can skip to the pairing section.
 +
 +
'''Some SHR versions have ophoned disabled. Make sure there's no disable=1 in [ophoned] section in /etc/frameworkd.conf'''
  
 
==== State file ====
 
==== State file ====
Line 667: Line 767:
  
 
==== Rules file ====
 
==== Rules file ====
You will also need to modify your oevents/rules.yaml file. You should replace the entire section from '''Call -> Audio Scenario Handling''' (Which is shown) to (but not including) '''while: PowerStatus()''' with the following:
+
You will also need to modify your /etc/freesmartphone/oevents/rules.yaml file. You should replace the entire section from '''Call -> Audio Scenario Handling''' (Which is shown) to (but not including) '''while: PowerStatus()''' with the following:
  
 
  -
 
  -
Line 726: Line 826:
 
  /etc/bluetooth/audio.conf
 
  /etc/bluetooth/audio.conf
  
 +
like this:
 +
 +
# SCO routing. Either PCM or HCI (in which case audio is routed to/from ALSA) 
 +
# Defaults to HCI                                                             
 +
SCORouting=PCM                                                                 
 +
 
do not forget to restart bluetoothd after that.
 
do not forget to restart bluetoothd after that.
 +
 +
/etc/init.d/bluetooth stop
 +
/etc/init.d/bluetooth start
  
 
=== Configuring FSO ===
 
=== Configuring FSO ===
Line 736: Line 845:
  
 
You need to restart FSO for the changes to take effect.
 
You need to restart FSO for the changes to take effect.
 +
 +
example of my /etc/freesmartphone/opreferences/conf/phone/default.yaml:
 +
 +
 +
message-length: 7
 +
message-tone: notify_message.wav
 +
message-vibration: 1
 +
message-volume: 10
 +
ring-loop: 1
 +
ring-tone: ringtone_ringnroll.wav
 +
ring-vibration: 1
 +
ring-volume: 10
 +
bt-headset-enabled: 1
 +
bt-headset-address: 00:09:DD:31:92:98
  
 
===Connecting and reconnecting the bt device===
 
===Connecting and reconnecting the bt device===
Line 741: Line 864:
 
You might need to get the bluetooth headset connected manually on the beggining and also after suspend:
 
You might need to get the bluetooth headset connected manually on the beggining and also after suspend:
  
  mdbus -s org.bluez /org/bluez/`pidof bluetoothd`/hci0/dev_xx_xx_xx_xx_xx_xx org.bluez.Headset.Connect
+
  mdbus -s org.bluez $BTADAPTER/dev_xx_xx_xx_xx_xx_xx org.bluez.Headset.Connect
  
 
where xx_xx_xx_xx_xx_xx is address of the device, for example:
 
where xx_xx_xx_xx_xx_xx is address of the device, for example:
  
  mdbus -s org.bluez /org/bluez/`pidof bluetoothd`/hci0/dev_00_09_DD_31_92_98 org.bluez.Headset.Connect
+
  mdbus -s org.bluez $BTADAPTER/dev_00_09_DD_31_92_98 org.bluez.Headset.Connect
  
 
Hopefully, your bluetooth headset now works. Good luck!
 
Hopefully, your bluetooth headset now works. Good luck!
Line 769: Line 892:
  
 
If anything goes wrong, capture the bluetooth traffic with
 
If anything goes wrong, capture the bluetooth traffic with
  sudo hcidump -l 4096 -w bt.dump
+
  hcidump -l 4096 -w bt.dump
 
and attach bt.dump to your bug reports etc.
 
and attach bt.dump to your bug reports etc.
  
 
== Further reading ==
 
== Further reading ==
  
http://www.holtmann.org/papers/bluetooth/ols2006_slides.pdf
+
*http://www.holtmann.org/papers/bluetooth/ols2006_slides.pdf
http://wiki.bluez.org/wiki/Audio#org.bluez.Audio
+
*http://wiki.bluez.org/wiki/Audio#org.bluez.Audio
http://www.gentoo.org/doc/en/bluetooth-guide.xml
+
*http://www.gentoo.org/doc/en/bluetooth-guide.xml
 +
*http://github.com/gabrys/gta02-gsm-bt-fix -- small standalone program to "fix" using Bluetooth for GSM calls. Can be used in any distribution that doesn't fix the problem on their own.
  
 
{{Languages|Manually_using_Bluetooth}}
 
{{Languages|Manually_using_Bluetooth}}
  
 
[[Category:Bluetooth| ]]
 
[[Category:Bluetooth| ]]

Latest revision as of 16:53, 24 July 2010

In progress: This article or section documents one or more features whose implementation are in progress.

Bluetooth is one of the core functions of the Neo1973, however it is basically unimplemented on the software side at the moment. Hardware problems in the P1 phone mean that the CPU has to be active in order to wake on external bluetooth events, which will reduce the battery life to some 2 days at best in standby.

This page details how to use bluetooth from the command line. We have quite a lot of plans about what exactly Bluetooth should be used for.

Please keep in mind that whenever hcid or pand or hidd are mentioned it means that instructions are applicable only to bluez3 systems which is deprecated ages ago. Modern bluez4 uses only one daemon - bluetoothd and you are supposed to use dbus api directly to configure it. For pairing from command line use simple-agent script.

Contents

[edit] Power it up

Bluez4-compatible

Power up the adapter by clicking on the bluetooth icon in the top bar and selecting power on.

For any FSO-based distro (including SHR) you want to consult FSO_Resources page.

For others consult your distro's documentation. The most low-level way to power bluetooth on is to

echo 1 > /sys/bus/platform/devices/neo1973-pm-bt.0/power_on

At the shell, "hciconfig" should print information about the adapter if it powered up properly:

hciconfig

The devices should show as UP. If not you can use

hciconfig <device> up

i.e.

hciconfig hci0 up

[edit] How to use bluez4 dbus API

Bluez4-compatible

You can do it with OpenmokoFramework/mdbus or with dbus-send.

First you need to get path to the default bluetooth adapter which should appear when you have bluetoothd running and bluetooth device is powered on. Do it like this:

export BTADAPTER=`dbus-send --system --dest=org.bluez --print-reply / org.bluez.Manager.DefaultAdapter | tail -1 | sed 's/^.*"\(.*\)".*$/\1/'`

To introspect with dbus-send you can employ something like this:

dbus-send --system --dest=org.bluez --print-reply $BTADAPTER org.freedesktop.DBus.Introspectable.Introspect

The next example is how to make your device discoverable:

dbus-send --system --dest=org.bluez --print-reply $BTADAPTER org.bluez.Adapter.SetProperty string:Discoverable variant:boolean:true

[edit] Scanning for bluetooth devices

Bluez4-compatible

hcitool scan

This will list the addresses of any discoverable bluetooth devices in the vicinity

[edit] Pair

Bluez4-compatible

Pairing is nothing special, do it with simple-agent [1] as described here or with any other agent you like as described in that agent's documentation. Bluez also comes with a simple command-line agent written in C, you can grab the source from [2] .

Make sure the bluetooth chip is powered up (see below) and that bluetoothd is running.

Now, to actually pair with other device, you will need the simple-agent script. If you do not have that already, download, put it in /usr/local/bin/ and run chmod a+x /usr/local/bin/simple-agent

Now put the other device into pairing mode and run hcitool scan. Find that device and use its address in the command simple-agent hci0 XX:XX:XX:XX:XX:XX. If you give a third parameter (what it is doesn't matter) to simple-agent, it will disconnect then reconnect.

If you give it only one parameter, it will register as an agent and will wait for other devices to initiate pairing. Feel free to tweak that script to your needs (e.g. to hardcode a pin to use).

[edit] HID (Human Input Device)

Bluez4-compatible

Pair with your device first.

Then do

dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_18_00_00_C2_37 org.bluez.Input.Connect

Where 00_18_00_00_C2_37 is the address of your HID device. You can query for the device address with:

dbus-send --system --dest=org.bluez --print-reply $BTADAPTER org.bluez.Adapter.ListDevices

Enjoy.

I've tested this with a BT mouse (no issues) and with SE cellphones that can pretend to be a mouse and keyboard. Both cellphones work without issues with my laptop using exactly the same procedure. The first phone seemed to work for a couple of seconds with FR too, after that the connection was lost. The second didn't work with FR at all.

I tried an external BT dongle (broadcom iirc) with both my FR and laptop (to eliminate hardware differences) and the result was the same. Even though bluez and kernel versions were roughly the same O_o -- PaulFertser

[edit] Being able to use HID devices

deprecated bluez3-specific, will be removed

If you are trying to connect a keyboard and you have bluez4, see Freedom_Slim_Keyboard.

Using a bluetooth keyboard with the built-in terminal is a little funky... I can only type into the console using the bt keyboard if the onscreen keyboard is visible. Also, pressing "p" twice on the bt keyboard actually gives you a "q".

We want to be able to use a bluetooth keyboard to type into the various applications of our Neo1973. To use a Bluetooth Keyboard type: (11:22:33:44:55:66 is the Address of your BT-Keyboard)

hidd --connect 11:22:33:44:55:66

and press "Connect" on your BT-KB. Alternately, if you know that only one BT-Keyboard is within range, you can just:

hidd --search

to find and connect to any BT-Keyboard. There are some bluetooth keyboard only support SPP profile can't direct using hidd comannd to connect. Please reference the discussion of this page for more information.

Tested on:

  • Logitech diNovo Mini Works well, very portable and the touchpad also works just fine. Also has no problems with double letters.
  • Logitech Dinovo Edge
  • Logitech Dinovo Media Desktop (keyboard)
  • Nokia SU-8W. Switched on the BT keyboard, scanned for BT address and ran the connect statement above. Works fine.
  • Chordite. This keyboard uses the Broadcom BCM2042 BT keyboard controller along with a custom driver.
  • Apple's Aluminum Keyboard. You may have to add 'auth enable; encrypt enable;' to device {} in hcid.conf. Run the passkey agent the first time. --search works to pair and every time after. (Might be obvious for those who have used BT in other spots, but you have to type in y our passkey on the keyboard as the connect is happening, otherwise pairing doesn't take place. I don't think there is a prompt on the Neo for this)
  • Apple's white "Wireless Keyboard (original)" - details may be the same as above. (tested some time ago)
  • FrogPad - as above
  • The freedom keyboard and its many rebranded models (they look like this: [3]) need 'modprobe uinput' to circumvent the 'Can't open input device: No such file or directory (2)' error of 'hidd --search'. It works as of february 7th 2008.
    • Freeedom Universal Keyboard Model G912 does not work (see Discussion Page)
  • Logitech Playstation 3 Keyboard Works well, Mouse pad works.
  • iGo Stowaway UltraSlim (which was apparently discontinued early 2008, but can still be bought in some places) (user:ChristW I have 2008.8 on it, and using hidd --search to connect to the iGo works perfectly. I also used it to edit a new contact, dial a number and edit a settings text box in TangoGPS. So far, no problems...)
  • I-Tech Virtual Laser Keyboard works. Cursor keys not recognized as such, but produce keycodes than can be mapped.

This is a script that I've (User:ChristW) been using with varying results. YMMV:

echo Power on
echo 1 > /sys/bus/platform/devices/neo1973-pm-bt.0/power_on
sleep 1
echo Reset on
echo 1 > /sys/bus/platform/devices/neo1973-pm-bt.0/reset
sleep 1
echo Reset off
echo 0 > /sys/bus/platform/devices/neo1973-pm-bt.0/reset
sleep 1
echo hciconfig down
hciconfig hci0 down
sleep 1
echo hciconfig up
hciconfig hci0 up
sleep 1
echo Connect
hidd --connect XX:XX:XX:XX:XX:XX

(See also Freedom_Slim_Keyboard for fso scripts which work with bluez4.)

[edit] Mouse

Edit /etc/X11/Xserver and replace tslib with /dev/input/mice.

       "GTA02")
                if [ `screen_width` -gt 330 ] ; then
                     DPI=285
                else
                     DPI=140
                fi 
                ARGS="$ARGS -dpi ${DPI} -screen ${SCREEN_SIZE} -mouse /dev/input/mice -root-ppm /usr/share/pixmaps/xsplash-vga.ppm vt1"
                XSERVER=/usr/bin/Xglamo
                ;;

[edit] Acting as HID device

We want to be able to use the Neo as a HID device, being able to use it as controller for presentations. See ReMoko

[edit] RFCOMM

i guess it's Bluez4-compatible

Here's how to connect to an external Bluetooth GPS and read NMEA data (Tested with a Holux GPSSlim236 and a Nokia LD-3W ).

First, switch on the GPS and identify the BT address:

 hcitool scan

Then, edit /etc/bluetooth/rfcomm.conf, which by default has all settings commented out, to something like this:

 rfcomm0 {
       # Automatically bind the device at startup
       bind no;
       # Bluetooth address of the device
       device 00:11:22:33:44:55;
       # RFCOMM channel for the connection (check your GPS docs for details)
       channel 1;
       # Description of the connection
       comment "Bluetooth GPS";
 }

Restart the BT services:

 root@neo:~$ /etc/init.d/bluetooth stop
 root@neo:~$ /etc/init.d/bluetooth start

You should now be able to bind the GPS to /dev/rfcomm0, like this:

 root@neo:~$ rfcomm bind 0

Confirm the connect:

 root@neo:~$ rfcomm
 rfcomm0: 00:11:22:33:44:55 channel 1 clean 

... and watch the NMEA strings coming from your GPS:

 root@neo:~$ cat /dev/rfcomm0 
 $GPGGA,111748.000,5907.6964,N,01121.1787,E,1,06,1.2,57.7,M,40.1,M,,0000*6F
 $GPRMC,111748.000,A,5907.6964,N,01121.1787,E,0.00,94.94,160807,,,A*50
 $GPVTG,94.94,T,,M,0.00,N,0.0,K,A*3D

If you have nothing better to do, you can now pinpoint my office :-).

[edit] OBEX

Mostly bluez4-compatible, you don't need to edit hcid.conf at all, bluetoothd will take care of using proper parameters itself

OBEX (abbreviation of OBject EXchange, also termed IrOBEX) is a communications protocol that facilitates the exchange of binary objects between devices. Here is the notes about how to use OBEX to send/receive files via bluetooth in NEO.

power on bluetooth.

hcid.conf modify /etc/bluetooth/hcid.conf

#
# HCI daemon configuration file.
#

# 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 auto;

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

	# Default PIN code for incoming connections
	passkey "1234";
}

# Default settings for HCI devices
device {
	# Local device name
	#   %d - device id
	#   %h - host name
	name "%h-%d";

	# Local device class
	class 0x000100;

	# Default packet type
	pkt_type DH1,DM1,HV1;

	# 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;

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

hcid - Bluetooth Host Controller Interface Daemon

All paired devices information are stored in /var/lib/bluetooth/BT HW addr folder eg.

root@om-gta02:/var/lib/bluetooth/00:06:6E:16:EB:C7# ls
classes        features       lastused       names          panu
config         gn             manufacturers  nap

Display local devices

root@om-gta02:/# hcitool dev

Scan all nearby bluetooth devices

root@om-gta02:~# hcitool scan

Browse what kind of services in this device

root@om-gta02:~# sdptool browse 00:18:C5:42:18:78
Browsing 00:18:C5:42:18:78 ...

Service Name: OBEX File Transfer
Service RecHandle: 0x1005b
Service Class ID List:
  "OBEX File Transfer" (0x1106)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 11
  "OBEX" (0x0008)
Language Base Attr List:
  code_ISO639: 0x454e
  encoding:    0x6a
  base_offset: 0x100
Profile Descriptor List:
  "OBEX File Transfer" (0x1106)
    Version: 0x0100

Service Name: OBEX Object Push
Service RecHandle: 0x1005e
Service Class ID List:
  "OBEX Object Push" (0x1105)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 9
  "OBEX" (0x0008)
Language Base Attr List:
  code_ISO639: 0x454e
  encoding:    0x6a
  base_offset: 0x100
Profile Descriptor List:
  "OBEX Object Push" (0x1105)
    Version: 0x0100

Use obexpush and obexftp tools

install obexpush, obexftp packages

opkg install obexpush obexftp

obexpush would launch 'opd' and it's a obex data server. It starts OBEX file transfer service. The default folder is /home/root and it would store all received files here.

 root@om-gta02:~# ps aux | grep opd
 root      1322  0.0  0.4   1972   604 ?        Ss   16:21   0:00 opd: waiting for incomming OBEX connections on channel 10...

How to pair with a bluetooth device, check bluez wiki

[edit] Networking

Please note that whenever hcid or pand is mentioned it means that instructions are applicable only to bluez3 systems which is deprecated ages ago. Modern bluez4 uses only one daemon - bluetoothd and you are supposed to use dbus api directly to configure it to connect as a client or act as a server. The API is described at [4]. Please update other instructions as soon as you get it working.

To ease the task you can try to use Blueman GUI software on one or both sides of the link.

[edit] Information about bluez4 networking

I managed to successfully connect from PocketPC PDA (used as PANU) to my FR (both NAP and GN configurations worked). Also i was able to use my laptop as PANU and my FR as GN/NAP, reverse should work too.

For some reason bluez4 needs ipv6 (fixed on 2009-03-10) and ethernet bridging kernel support. So to avoid more problems you better have it. Also you'll need bnep kernel module.

[edit] Bluetooth networking concepts

This HOW-TO is directly applicable only to bluez3 but still worth reading to understand PANU/GN/NAP roles: [5].

In short, GN is network bridge (aka hub/switch), NAP is network router and PANU is a network client.

You can enable or disable various roles by setting Enable property to true/false. Example for GN:

dbus-send --system --dest=org.bluez --print-reply $BTADAPTER org.bluez.NetworkHub.SetProperty string:Enabled variant:boolean:true

For PANU use org.bluez.NetworkPeer interface and for NAP use org.bluez.NetworkRouter.

You might want to know UUID of GN for later use, so you need to read its properties:

dbus-send --system --dest=org.bluez --print-reply $BTADAPTER org.bluez.NetworkHub.GetProperties

To use NAP you'll need to create bridge device manually with

brctl addbr pan1

For GN bridge pan0 is created automatically on bluetoothd start.

I can't see a difference between GN and NAP in the Linux networking context so i suppose GN is the easiest to get going

[edit] Pairing

Pairing is nothing special, do it with simple-agent as described in other sections or by any other pairing agent.

[edit] Trust

On GN/NAP role you need to trust the PANU peer:

dbus-send --system --dest=org.bluez --print-reply $BTADAPTER/dev_00_06_6E_17_27_E0 org.bluez.Device.SetProperty string:Trusted variant:boolean:true

Where 00_06_6E_17_27_E0 is the MAC of peer.

[edit] Connection establishing

On PANU you need to have a helper script panu.py:

#!/usr/bin/python

import dbus
import sys
import os

bus = dbus.SystemBus()
network = dbus.Interface(bus.get_object("org.bluez",
                sys.argv[1]),
                "org.bluez.Network")

network.Connect("GN")
print "Networking established, exit the shell to end this session"
os.spawnl(os.P_WAIT, os.environ['SHELL'])
print "Networking released"

Then you do:

./panu.py $BTADAPTER/dev_00_06_6E_17_27_E0

Where 00_16_CE_E4_44_D5 is MAC of GN/NAP.

Hopefully after this you'll have two new interfaces bnep0 created on both sides and it'll be added to the pan0 bridge on GN.

Set up packet forwarding, IP addresses etc. as usual.

[edit] Using PC's connection from Neo

[edit] Bluetooth networking with a Linux system

deprecated bluez3-specific, to be removed soon

Bluetooth should behave just like our usbnet and provide full TCP/IP access to the phone. BNEP has to be used.

On the laptop

  • Start bluetooth
/etc/init.d/bluetooth start
  • Start pand as server
pand -s
  • As soon as pand is started on the phone configure your IP address
ip a add 10.0.0.1/24 dev bnep0
ip l set bnep0 up
  • Configure IP forwarding and masquerading to your liking (see USB_Networking). You can even set up Udev rules to do this for you once the bnep0 interface appears.


On the Neo

  • There is a little script that does the steps below (and retries the pand -c command; I had issues with it not working the first time every time) at Bt-net-script You shouldn't need the other steps below if you use the script.
  • Power on bluetooth (see above)
  • Scan for the laptop
root@fic-gta01:~$ hcitool scan
Scanning ...
00:0E:6D:C0:0l:6A       Sho
00:20:E0:5A:FE:C8       BlueZ (0)
  • Connect to the laptop pand
root@fic-gta01:~$ pand -c 00:20:E0:5A:FE:C8
  • Configure your IP address
ip a add 10.0.0.2/24 dev bnep0
ip r add default via 10.0.0.1
  • Sometimes you may need to bring up the bnep0 on the phone as well:
ip l set bnep0 up
  • Enjoy


  • --Mantis 18:37, 15 October 2008 (UTC) Note for use on OpenSuse 11.0 - I was getting a connection failure with 'Host is down(112)' errors in /var/log/messages (on neo).

I found that editing /etc/bluetooth/hcid.conf to set 'pscan enable' instead of 'pscan disable' and making passkey consistent with Neo Freerunner made it work.

Should see log line like

pand[17965]: New connection from 00:06:6E:XX:XX:XX at bnep0

if connection is successful in server's /var/log/messages.

[edit] Bluetooth networking with a MacOS X system

Please refer to MacOS_X#Bluetooth_2

For using the Neo as a dialup Bluetooth server and the Mac as the client, please see below at Manually_using_Bluetooth#PPP_Networking

[edit] Bluetooth networking with a Windows XP system

This was tested with a Windows XP SP2 on a IBM Thinkpad T41 with the Widcomm BT stack

  • Start bluetooth on Windows XP
  • Enable "Network Access" in the Bluetooth configuration
  • Scan for the Neo and pair with the Neo (right click, select pair)


On the Neo

  • Enable PAN support on the Neo by changing Autostart from false to true in /etc/bluetooth/network.service
  • Power on bluetooth (see above)
  • Scan for the laptop
root@fic-gta01:~$ hcitool scan
Scanning ...
        <laptop_bt_address>     Thinkpad
        ...


  • Connect to the laptop pand
pand -c <laptop_bt_address> -r PANU -d NAP -e bnep0 -A -E -S

(add '-n' to see the pand status messages until you get it right)

For some reason, I was not able to initiate PAN connections from the Neo, I got 'Permission denied (13)' even when I had explicitly allowed the Neo to connect (right click on Neo icon, set properties, on Authorization tab). But initiating 'PAN User' from Windows worked when executing on Neo:

pand -l -r PANU -d NAP -e bnep0 -A -E -S

(add '-n' to see the pand status messages until you get it right)


  • Configure your IP address. It should work like when connecting to Linux:
ip a add 10.0.0.2/24 dev bnep0
ip r add default via 10.0.0.1

If this does not work, the IP stacks may have auto-assigned network addresses to themselves. You can look this up with 'ifconfig' on the Neo and with 'ipconfig' on Windows.


  • You should now be able to ssh/putty from Windows to your Neo. Enjoy!

By setting up the Windows Bluetooth connection properly, it should also be possible to share the Internet Connection of the Windows box with the Neo.

[edit] PPP Networking

If you are unable to use the 'BNEP' method described above, you may be able to use PPP and a DUN (dialup-networking) emulation mode. On the Neo:

  • Edit the /etc/default/bluetooth file and set the following options:
RFCOMM_ENABLE=true
DUND_ENABLE=true
DUND_OPTIONS="--listen --persist call dun"
  • Create an /etc/ppp/peers/dun file with options like the following:
115200
192.168.2.202:192.168.2.200
passive
local
noipdefault
noauth
nodefaultroute

  • Restart bluetooth (/etc/init.d/bluetooth stop ; /etc/init.d/bluetooth start)

To connect from a MacOS 10.3 client:

  • Open "Applications/Utilities/Bluetooth Serial Utility"
  • Click on "New"
  • Choose a name, then click "Choose Device"
  • Locate your Neo, then select the "LAN Access Point" service. If your device is not found, or if this service does not show up, then you will need to troubleshoot and fix that before continuing. Bluetooth is designed for short-range communication, so make sure that the devices are physically close to each other.
  • Select "Port type: RS-232" and "Show in Network Preferences". Click OK.
  • Open the Network Preferences page then "Show: Network Port Configurations". Enable the new device that you defined in the previous step and drag it to the bottom of the device list (so that it will not interfere with your other network connections)
  • Choose "Show: <your-device-name>", then click "Modem"
  • Select "Null Modem 115200" from the list of available devices. Uncheck "Wait for dial tone" and "Enable error correction and compression in modem". Optionally check "Show modem status in menu bar".
  • Click "Connect". If everything worked, you will end up with a 'ppp0' device on your Mac with a local address of 192.168.2.200 and you will be able to access your Neo at 192.168.2.202.
[edit] Bluetooth networking with a Linux system - More secure way

Check this, probably needs some corrections

Bluetooth should behave just like our usbnet and provide full TCP/IP access to the phone. BNEP has to be used.

On the laptop

  • check these options in /etc/bluetooth/hcid.conf
security auto;
passkey "your pin";
lm master;
  • Start bluetooth
# /etc/init.d/bluetooth start
  • Start pand as server
 pand --listen --role NAP --encrypt
auto bnep0
iface bnep0 inet static
address 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
       post-up iptables -A POSTROUTING -t nat -j MASQUERADE -s 192.168.1.0/24
       post-up echo 1 > /proc/sys/net/ipv4/ip_forward
       post-up iptables -P FORWARD ACCEPT

On the Neo

  • Power on bluetooth (see above)
  • Scan for the laptop
root@fic-gta01:~$ hcitool scan
Scanning ...
        00:20:E0:5A:FE:C8       laptop
  • Set pin
root@fic-gta01:~$ passkey-agent 'your pin' 00:20:E0:5A:FE:C8 &
  • Connect to the laptop pand
root@fic-gta01:~$ pand -c 00:20:E0:5A:FE:C8
  • Configure your IP address
root@fic-gta01:~$ ifconfig bnep0 192.168.1.2
root@fic-gta01:~$ route add default gateway 192.168.1.1
  • Enjoy

[edit] Using Neo's connection from PC

[edit] Calling Neo's GPRS modem via Bluetooth

In this mode, Neo would behave like any other phone which can be used from a PC to get a network connection.

This section not written yet. Has someone set it up?

[edit] Sharing existing Neo's connection

In this mode, Neo already has a network connection (GPRS, WLAN, ...), and it should get shared to the PC. This guide is general on how to forward network connection from a machine running Linux to another machine. If interested, please see more information for example at http://www.gentoo.org/doc/en/bluetooth-guide.xml.

On the PC

  1. Check with hciconfig you have working Bluetooth

On the Neo (if on Debian etc., remember modprobe ohci_hcd hci_usb)

  1. Initialize Bluetooth as told before:
    1. echo 1 > /sys/bus/platform/devices/neo1973-pm-bt.0/power_on
    2. echo 0 > /sys/bus/platform/devices/neo1973-pm-bt.0/reset
  2. install iptables: opkg install http://www.angstrom-distribution.org/feeds/2008/ipk/glibc/armv4t/base/iptables_1.3.8-r4.1_armv4t.ipk
  3. modprobe bnep
  4. Check that hcid is running both on Neo and PC (Bluetooth 4.x: install bluez-compat)
  5. Use default passkey "1234" in /etc/bluetooth/hcid.conf
  6. pand --listen --role NAP --master --autozap # note: after this you might have to the the step 1 below ("On the PC") or the next step of getting the interface up does not work # note2: you could automate pand listener to start automatically when Bluetooth is turned on
  7. ifconfig bnep0 10.0.5.2 up
  8. echo 1 > /proc/sys/net/ipv4/ip_forward
  9. iptables -t nat -A POSTROUTING -j MASQUERADE -o ppp0

On the PC:

  1. sudo pand --connect <your bluetooth mac address> --service NAP --autozap
  2. ifconfig bnep0 10.0.5.1 up
  3. You can test the connection with ping 10.0.5.2
  4. sudo ip route add default via 10.0.5.2 dev bnep0
  5. [not automated yet] add GPRS connection's nameservers to /etc/resolv.conf

[edit] Advanced Audio Distribution Profile (A2DP)

See A2DP.

[edit] Headset Audio

Neo1973_Audio_Subsystem has detail about alsa settings and a proposal for audio scenario management.

To try this out, follow the instructions on the A2DP page to install software and run the passkey agent.

Remove or disable the stuff you put in asound.conf. When using a voice headset, the application uses the regular system audio device and it gets routed to bluetooth in the codec.

Put the headset in pairing mode. Replace the bluetooth address below with your headset's and run the python script:

#!/usr/bin/python
import dbus
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object('org.bluez', '/org/bluez'), 'org.bluez.Manager')
conn = manager.ActivateService('audio')
audio = dbus.Interface(bus.get_object(conn, '/org/bluez/audio'), 'org.bluez.audio.Manager')
path = audio.CreateHeadset('00:0B:2E:39:33:22')
audio.ChangeDefaultHeadset(path)
headset = dbus.Interface (bus.get_object(conn, path), 'org.bluez.audio.Headset')
headset.Connect()
headset.Play()

Now place a call and try to route it to bluetooth (after it's in progress):

alsactl -f /etc/gsmbluetooth.state restore

You may also be able to listen to system audio given the right state file:

alsactl -f /etc/systembluetooth.state restore
madplay song.mp3

[edit] Bluetooth Headset on Freerunner

The following describes a procedure applicable only to some old deprecated shit (namely OM2008.x), skip to the next section if you want to see instructions on using BT headset with modern FSO-based distros.

This thread suggests the following:

Turn on bluetooth. If some of the scripts below fail you may need to reboot Bluetooth after suspend
Pair your headset according to these instructions or use the script below. The script will change your .asoundrc so make a backup before you run it.
http://handheldshell.com/BtConfigure.py
Put the headset in pairing mode ( this only needs to be done once for each new headset ) and run
BtConfigure.py 
Download the the following python scripts to set up the audio service and set the headset as the default device:
http://handheldshell.com/BtHeadset.py
http://handheldshell.com/passkey.py
http://handheldshell.com/BtHeadsetDisconnect.py
http://handheldshell.com/python-pyalsaaudio_0.3-ml0_armv4t.ipk - can someone add python-pyalsa to the feeds ?
Download the the following python scripts if you prefer not to mess around with alsactl:
http://handheldshell.com/pymixer.py
http://handheldshell.com/volume.desktop
put pymixer in /usr/bin
chmod u+x /usr/bin/pymixer.py
put volume.desktop in /usr/share/applications
Get the [alsa state file] - this state file _WORKS_, mic and earphones are properly routed
cp gsm_headset.txt /usr/share/openmoko/scenarios/btheadset.state
from the home screen run Volume
from the terminal run
BtHeadset.py 
Wait until it says waiting for call to end, you should hear static in the headset. If you don't something has gone wrong.
Now start the call
In the volume control switch to the btheadset tab. press restore
You should now hear the call in your headset.
End the call
BtHeadsetDisconnect.py 
This was all done with the 2008-updates image from sept 4.
The new scripts rely on a specific format for the .asoundrc . A stanza like this is required :
pcm.headset {
    type bluetooth
    device <headset mac>
    profile "voice"
}

[edit] Once Again, Bluetooth Headset on Freerunner

Bluez4-compatible

[edit] List of known to work headsets

Moved to List_of_bluetooth_headsets

[edit] List of non-working headsets

Iqua BHS-333 (it turns on/off, beeps etc properly, but gives no sound) -- PaulFertser

Nokia BH-200 same as above :( , will try again --Vanous

[edit] User reports

Heh, firsthand success experience finally :) I did everything according to these instructions, restarted frameworkd, started zhone, used fsoraw to request bluetooth resource (once i needed to press button on headset to turn it on). Call ring sounds at the Freerunner, calls got automatically routed to the headset, the sound was ok both ways (probably some tweaking might be needed depending on your headset's mic sensitivity). Unfortunately, alsa python bindings in Debian are too old so this works only for the first call (updating bindings should solve that). - this is not valid for SHR users, more calls can be placed and even after suspend when the bt device get's disconnected, it can be manually reconnected via dbus call (see bellow) -- Vanous. -- PaulFertser

[edit] Prerequisites

PLEASE NOTE: You will need a recent git revision of frameworkd (latest in SHR-Unstable repos will do) and bluez4 to do this.

If you're using SHR unstable, you already has a correct state file and rules.yaml, so you can skip to the pairing section.

Some SHR versions have ophoned disabled. Make sure there's no disable=1 in [ophoned] section in /etc/frameworkd.conf

[edit] State file

To prepare, you will need a fixed statefile for bluetooth. You can download this at: http://dl.getdropbox.com/u/453116/gsmbluetooth.state You need to put it on your Freerunner in the /usr/share/openmoko/scenarios/ directory.

[edit] Rules file

You will also need to modify your /etc/freesmartphone/oevents/rules.yaml file. You should replace the entire section from Call -> Audio Scenario Handling (Which is shown) to (but not including) while: PowerStatus() with the following:

-
    #
    # Call -> Audio Scenario Handling
    #
    trigger: IncomingMessage()
    actions: MessageTone(play)

-
    while: CallListContains("incoming")
    filters: Not(CallListContains("active"))
    actions:
             - RingTone()
             - SetDisplayBrightness("0", 90)
             - OccupyResource(CPU)

-
    while: CallStatus()
    filters: Or(HasAttr(status, "outgoing"), HasAttr(status, "active"))
    actions:
            - OccupyResource(CPU)
-
    while: CallStatus()
    filters:
            - Or(HasAttr(status, "outgoing"), HasAttr(status, "active"))
            - Not(BTHeadsetIsConnected())
    actions:
            - SetScenario(gsmhandset)
-
    while: CallStatus()
    filters:
            - Or(HasAttr(status, "outgoing"), HasAttr(status, "active"))
            - BTHeadsetIsConnected()
    actions:
            - SetScenario(gsmbluetooth)
            - BTHeadsetPlaying()
-

Now you will need to restart frameworkd:

/etc/init.d/frameworkd restart

This causes problems for me, so you may find it easier to reboot. (Restarting ophonekitd seems to help with this):

killall ophonekitd && ophonekitd&

[edit] Pairing

Now, you must pair the bluetooth headset with your Freerunner. Make sure the bluetooth chip is powered up (can be done through the Connectivity section in the SHR-Unstable settings manager) and that bluetoothd is running:

/etc/init.d/bluetooth start

Now, to actually pair the bluetooth headset, you will need the simple-agent script. If you already have it, excellent. If you, like me, do not, then you can get it here: http://dl.getdropbox.com/u/453116/simple-agent Put it in /usr/bin/ and run chmod a+x /usr/bin/simple-agent

Now put your headset into pairing mode and run hcitool scan. Find your headset and use its address in the command simple-agent hci0 XX:XX:XX:XX:XX:XX. If you give a third parameter (what it is doesn't matter) to simple-agent, it will disconnect then reconnect to the headset.

[edit] Configuring bluez

Uncomment SCORouting=PCM setting in [General] section of

/etc/bluetooth/audio.conf

like this:

# SCO routing. Either PCM or HCI (in which case audio is routed to/from ALSA)   
# Defaults to HCI                                                               
SCORouting=PCM                                                                  

do not forget to restart bluetoothd after that.

/etc/init.d/bluetooth stop
/etc/init.d/bluetooth start

[edit] Configuring FSO

Now we must tell frameworkd that you have a bluetooth headset. Headset parameters should be set in

/etc/freesmartphone/opreferences/conf/phone/default.yaml

Parameters bt-headset-enabled and bt-headset-address (see opreferences/schema/phone.yaml for semantics).

You need to restart FSO for the changes to take effect.

example of my /etc/freesmartphone/opreferences/conf/phone/default.yaml:


message-length: 7
message-tone: notify_message.wav
message-vibration: 1
message-volume: 10
ring-loop: 1
ring-tone: ringtone_ringnroll.wav
ring-vibration: 1
ring-volume: 10
bt-headset-enabled: 1
bt-headset-address: 00:09:DD:31:92:98

[edit] Connecting and reconnecting the bt device

You might need to get the bluetooth headset connected manually on the beggining and also after suspend:

mdbus -s org.bluez $BTADAPTER/dev_xx_xx_xx_xx_xx_xx org.bluez.Headset.Connect

where xx_xx_xx_xx_xx_xx is address of the device, for example:

mdbus -s org.bluez $BTADAPTER/dev_00_09_DD_31_92_98 org.bluez.Headset.Connect

Hopefully, your bluetooth headset now works. Good luck!

[edit] Additional helpfull testing commands

Unfortunately, some headsets do not output any sound while everything else (it turns on, beeps, powers amplifier, turns off) works as expected. The reason is unknown but nevertheless one might try these commands (please don't forget to report the results on ML!):

rmmod sco
modprobe sco disable_esco=1


If you want to manually play with bluetooth and statefiles, take into account that there's a kernel bug that makes loading gsmbluetooth state file not enough to actually work. One has to do

amixer sset "Capture Left Mixer" "Analogue Mix Right"
amixer sset "Capture Left Mixer" "Analogue Mix Left"

every time after loading this statefile.

[edit] Troubleshooting

Ensure you have bluetooth powered and that bluetoothd is running. Read frameworkd log for the hints. Report on IRC/ML.

[edit] Debugging

If anything goes wrong, capture the bluetooth traffic with

hcidump -l 4096 -w bt.dump

and attach bt.dump to your bug reports etc.

[edit] Further reading

Personal tools
In progress: This article or section documents one or more features whose implementation are in progress.

Bluetooth is one of the core functions of the Neo1973, however it is basically unimplemented on the software side at the moment. Hardware problems in the P1 phone mean that the CPU has to be active in order to wake on external bluetooth events, which will reduce the battery life to some 2 days at best in standby.

This page details how to use bluetooth from the command line. We have quite a lot of plans about what exactly Bluetooth should be used for.

Power it up

Power up the adapter by clicking on the bluetooth icon in the top bar and selecting power on.

The old way to do it is a shell command (for kernels before 2.6.24):

root@fic-gta01:~# echo 1 > /sys/bus/platform/devices/gta01-pm-bt.0/power_on

For kernel 2.6.24 (or later) use

root@om-gta02:~# echo 1 > /sys/bus/platform/devices/neo1973-pm-bt.0/power_on

and on the GTA02 *only* (i.e. not on the GTA01) also use

root@om-gta02:~# echo 0 > /sys/bus/platform/devices/neo1973-pm-bt.0/reset

But nowadays[1], one should use Dbus device APIs!

At the shell, "hciconfig" should print information about the adapter if it powered up properly:

hciconfig

The devices should show as UP. If not you can use

hciconfig <device> up

i.e.

hciconfig hci0 up

Bluetooth Functions

Configuring Bluetooth on Openmoko 2007.2 (August 27 snapshot with kernel 2.6.21.6-moko11)

In file /etc/bluetooth/hcid.conf you should change the passkey from BlueZ to something numeric. For testing you may use "0000". Also, you can set the name to "Neo (%d)".

Scanning for bluetooth devices

hcitool scan

This will list the addresses of any discoverable bluetooth devices in the vicinity

passkey agent example

There should be a passkey agent built into openmoko, but for now you can start up the example passkey agent and set the pin code there. This will allow for new pairings to be made when you attempt a connection.

passkey-agent --default 0000 &

Note: the passkey-agent is not required in Openmoko 2007.2 with kernel 2.6.21.6 as of at least since August 27 (maybe earlier).

In debian there is no passkey-agent binary but the package bluez-utils has its source code at /usr/share/doc/bluez-utils/examples/passkey-agent.c.gz.

HID (Human Input Device)

Being able to use HID devices

If you are trying to connect a keyboard and you have bluez4, see Freedom_Slim_Keyboard.

Using a bluetooth keyboard with the built-in terminal is a little funky... I can only type into the console using the bt keyboard if the onscreen keyboard is visible. Also, pressing "p" twice on the bt keyboard actually gives you a "q".

We want to be able to use a bluetooth keyboard to type into the various applications of our Neo1973. To use a Bluetooth Keyboard type: (11:22:33:44:55:66 is the Address of your BT-Keyboard)

hidd --connect 11:22:33:44:55:66

and press "Connect" on your BT-KB. Alternately, if you know that only one BT-Keyboard is within range, you can just:

hidd --search

to find and connect to any BT-Keyboard. There are some bluetooth keyboard only support SPP profile can't direct using hidd comannd to connect. Please reference the discussion of this page for more information.

Tested on:

  • Logitech diNovo Mini Works well, very portable and the touchpad also works just fine. Also has no problems with double letters.
  • Logitech Dinovo Edge
  • Logitech Dinovo Media Desktop (keyboard)
  • Nokia SU-8W. Switched on the BT keyboard, scanned for BT address and ran the connect statement above. Works fine.
  • Chordite. This keyboard uses the Broadcom BCM2042 BT keyboard controller along with a custom driver.
  • Apple's Aluminum Keyboard. You may have to add 'auth enable; encrypt enable;' to device {} in hcid.conf. Run the passkey agent the first time. --search works to pair and every time after. (Might be obvious for those who have used BT in other spots, but you have to type in y our passkey on the keyboard as the connect is happening, otherwise pairing doesn't take place. I don't think there is a prompt on the Neo for this)
  • Apple's white "Wireless Keyboard (original)" - details may be the same as above. (tested some time ago)
  • FrogPad - as above
  • The freedom keyboard and its many rebranded models (they look like this: [2]) need 'modprobe uinput' to circumvent the 'Can't open input device: No such file or directory (2)' error of 'hidd --search'. It works as of february 7th 2008.
    • Freeedom Universal Keyboard Model G912 does not work (see Discussion Page)
  • Logitech Playstation 3 Keyboard Works well, Mouse pad works.
  • iGo Stowaway UltraSlim (which was apparently discontinued early 2008, but can still be bought in some places) (user:ChristW I have 2008.8 on it, and using hidd --search to connect to the iGo works perfectly. I also used it to edit a new contact, dial a number and edit a settings text box in TangoGPS. So far, no problems...)
  • I-Tech Virtual Laser Keyboard works. Cursor keys not recognized as such, but produce keycodes than can be mapped.

This is a script that I've (User:ChristW) been using with varying results. YMMV:

echo Power on
echo 1 > /sys/bus/platform/devices/neo1973-pm-bt.0/power_on
sleep 1
echo Reset on
echo 1 > /sys/bus/platform/devices/neo1973-pm-bt.0/reset
sleep 1
echo Reset off
echo 0 > /sys/bus/platform/devices/neo1973-pm-bt.0/reset
sleep 1
echo hciconfig down
hciconfig hci0 down
sleep 1
echo hciconfig up
hciconfig hci0 up
sleep 1
echo Connect
hidd --connect XX:XX:XX:XX:XX:XX

(See also Freedom_Slim_Keyboard for fso scripts which work with bluez4.)

Acting as HID device

We want to be able to use the Neo as a HID device, being able to use it as controller for presentations. See ReMoko

RFCOMM

Here's how to connect to an external Bluetooth GPS and read NMEA data (Tested with a Holux GPSSlim236 and a Nokia LD-3W ).

First, switch on the GPS and identify the BT address:

 hcitool scan

Then, edit /etc/bluetooth/rfcomm.conf, which by default has all settings commented out, to something like this:

 rfcomm0 {
       # Automatically bind the device at startup
       bind no;
       # Bluetooth address of the device
       device 00:11:22:33:44:55;
       # RFCOMM channel for the connection (check your GPS docs for details)
       channel 1;
       # Description of the connection
       comment "Bluetooth GPS";
 }

Restart the BT services:

 root@neo:~$ /etc/init.d/bluetooth stop
 root@neo:~$ /etc/init.d/bluetooth start

You should now be able to bind the GPS to /dev/rfcomm0, like this:

 root@neo:~$ rfcomm bind 0

Confirm the connect:

 root@neo:~$ rfcomm
 rfcomm0: 00:11:22:33:44:55 channel 1 clean 

... and watch the NMEA strings coming from your GPS:

 root@neo:~$ cat /dev/rfcomm0 
 $GPGGA,111748.000,5907.6964,N,01121.1787,E,1,06,1.2,57.7,M,40.1,M,,0000*6F
 $GPRMC,111748.000,A,5907.6964,N,01121.1787,E,0.00,94.94,160807,,,A*50
 $GPVTG,94.94,T,,M,0.00,N,0.0,K,A*3D

If you have nothing better to do, you can now pinpoint my office :-).

OBEX

OBEX (abbreviation of OBject EXchange, also termed IrOBEX) is a communications protocol that facilitates the exchange of binary objects between devices. Here is the notes about how to use OBEX to send/receive files via bluetooth in NEO.

power on bluetooth: if you use FSO image

root@om-gta02:~# dbus-send --system --dest=org.freesmartphone.odeviced --type=method_call --print-reply 
/org/freesmartphone/Device/PowerControl/Bluetooth org.freesmartphone.Device.PowerControl.SetPower int32:1

else: (GTA02 only)

root@om-gta02:~# echo 1 > /sys/bus/platform/devices/neo1973-pm-bt.0/reset
root@om-gta02:~# echo 0 > /sys/bus/platform/devices/neo1973-pm-bt.0/reset

hcid.conf modify /etc/bluetooth/hcid.conf

#
# HCI daemon configuration file.
#

# 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 auto;

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

	# Default PIN code for incoming connections
	passkey "1234";
}

# Default settings for HCI devices
device {
	# Local device name
	#   %d - device id
	#   %h - host name
	name "%h-%d";

	# Local device class
	class 0x000100;

	# Default packet type
	pkt_type DH1,DM1,HV1;

	# 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;

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

hcid - Bluetooth Host Controller Interface Daemon

All paired devices information are stored in /var/lib/bluetooth/BT HW addr folder eg.

root@om-gta02:/var/lib/bluetooth/00:06:6E:16:EB:C7# ls
classes        features       lastused       names          panu
config         gn             manufacturers  nap

Display local devices

root@om-gta02:/# hcitool dev

Scan all nearby bluetooth devices

root@om-gta02:~# hcitool scan

Browse what kind of services in this device

root@om-gta02:~# sdptool browse 00:18:C5:42:18:78
Browsing 00:18:C5:42:18:78 ...

Service Name: OBEX File Transfer
Service RecHandle: 0x1005b
Service Class ID List:
  "OBEX File Transfer" (0x1106)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 11
  "OBEX" (0x0008)
Language Base Attr List:
  code_ISO639: 0x454e
  encoding:    0x6a
  base_offset: 0x100
Profile Descriptor List:
  "OBEX File Transfer" (0x1106)
    Version: 0x0100

Service Name: OBEX Object Push
Service RecHandle: 0x1005e
Service Class ID List:
  "OBEX Object Push" (0x1105)
Protocol Descriptor List:
  "L2CAP" (0x0100)
  "RFCOMM" (0x0003)
    Channel: 9
  "OBEX" (0x0008)
Language Base Attr List:
  code_ISO639: 0x454e
  encoding:    0x6a
  base_offset: 0x100
Profile Descriptor List:
  "OBEX Object Push" (0x1105)
    Version: 0x0100

Use obexpush and obexftp tools

install obexpush, obexftp packages

opkg install obexpush obexftp

obexpush would launch 'opd' and it's a obex data server. It starts OBEX file transfer service. The default folder is /home/root and it would store all received files here.

 root@om-gta02:~# ps aux | grep opd
 root      1322  0.0  0.4   1972   604 ?        Ss   16:21   0:00 opd: waiting for incomming OBEX connections on channel 10...

How to pair with a bluetooth device, check bluez wiki

Networking

Using PC's connection from Neo

Bluetooth networking with a Linux system

Bluetooth should behave just like our usbnet and provide full TCP/IP access to the phone. BNEP has to be used.

On the laptop

  • Start bluetooth
/etc/init.d/bluetooth start
  • Start pand as server
pand -s
  • As soon as pand is started on the phone configure your IP address
ip a add 10.0.0.1/24 dev bnep0
ip l set bnep0 up
  • Configure IP forwarding and masquerading to your liking (see USB_Networking). You can even set up Udev rules to do this for you once the bnep0 interface appears.


On the Neo

  • There is a little script that does the steps below (and retries the pand -c command; I had issues with it not working the first time every time) at Bt-net-script You shouldn't need the other steps below if you use the script.
  • Power on bluetooth (see above)
  • Scan for the laptop
root@fic-gta01:~$ hcitool scan
Scanning ...
00:0E:6D:C0:0l:6A       Sho
00:20:E0:5A:FE:C8       BlueZ (0)
  • Connect to the laptop pand
root@fic-gta01:~$ pand -c 00:20:E0:5A:FE:C8
  • Configure your IP address
ip a add 10.0.0.2/24 dev bnep0
ip r add default via 10.0.0.1
  • Sometimes you may need to bring up the bnep0 on the phone as well:
ip l set bnep0 up
  • Enjoy


  • --Mantis 18:37, 15 October 2008 (UTC) Note for use on OpenSuse 11.0 - I was getting a connection failure with 'Host is down(112)' errors in /var/log/messages (on neo).

I found that editing /etc/bluetooth/hcid.conf to set 'pscan enable' instead of 'pscan disable' and making passkey consistent with Neo Freerunner made it work.

Should see log line like

pand[17965]: New connection from 00:06:6E:XX:XX:XX at bnep0

if connection is successful in server's /var/log/messages.

Bluetooth networking with a MacOS X system

Please refer to MacOS_X#Bluetooth_2

For using the Neo as a dialup Bluetooth server and the Mac as the client, please see below at Manually_using_Bluetooth#PPP_Networking

Bluetooth networking with a Windows XP system

This was tested with a Windows XP SP2 on a IBM Thinkpad T41 with the Widcomm BT stack

  • Start bluetooth on Windows XP
  • Enable "Network Access" in the Bluetooth configuration
  • Scan for the Neo and pair with the Neo (right click, select pair)


On the Neo

  • Enable PAN support on the Neo by changing Autostart from false to true in /etc/bluetooth/network.service
  • Power on bluetooth (see above)
  • Scan for the laptop
root@fic-gta01:~$ hcitool scan
Scanning ...
        <laptop_bt_address>     Thinkpad
        ...


  • Connect to the laptop pand
pand -c <laptop_bt_address> -r PANU -d NAP -e bnep0 -A -E -S

(add '-n' to see the pand status messages until you get it right)

For some reason, I was not able to initiate PAN connections from the Neo, I got 'Permission denied (13)' even when I had explicitly allowed the Neo to connect (right click on Neo icon, set properties, on Authorization tab). But initiating 'PAN User' from Windows worked when executing on Neo:

pand -l -r PANU -d NAP -e bnep0 -A -E -S

(add '-n' to see the pand status messages until you get it right)


  • Configure your IP address. It should work like when connecting to Linux:
ip a add 10.0.0.2/24 dev bnep0
ip r add default via 10.0.0.1

If this does not work, the IP stacks may have auto-assigned network addresses to themselves. You can look this up with 'ifconfig' on the Neo and with 'ipconfig' on Windows.


  • You should now be able to ssh/putty from Windows to your Neo. Enjoy!

By setting up the Windows Bluetooth connection properly, it should also be possible to share the Internet Connection of the Windows box with the Neo.

PPP Networking

If you are unable to use the 'BNEP' method described above, you may be able to use PPP and a DUN (dialup-networking) emulation mode. On the Neo:

  • Edit the /etc/default/bluetooth file and set the following options:
RFCOMM_ENABLE=true
DUND_ENABLE=true
DUND_OPTIONS="--listen --persist call dun"
  • Create an /etc/ppp/peers/dun file with options like the following:
115200
192.168.2.202:192.168.2.200
passive
local
noipdefault
noauth
nodefaultroute

  • Restart bluetooth (/etc/init.d/bluetooth stop ; /etc/init.d/bluetooth start)

To connect from a MacOS 10.3 client:

  • Open "Applications/Utilities/Bluetooth Serial Utility"
  • Click on "New"
  • Choose a name, then click "Choose Device"
  • Locate your Neo, then select the "LAN Access Point" service. If your device is not found, or if this service does not show up, then you will need to troubleshoot and fix that before continuing. Bluetooth is designed for short-range communication, so make sure that the devices are physically close to each other.
  • Select "Port type: RS-232" and "Show in Network Preferences". Click OK.
  • Open the Network Preferences page then "Show: Network Port Configurations". Enable the new device that you defined in the previous step and drag it to the bottom of the device list (so that it will not interfere with your other network connections)
  • Choose "Show: <your-device-name>", then click "Modem"
  • Select "Null Modem 115200" from the list of available devices. Uncheck "Wait for dial tone" and "Enable error correction and compression in modem". Optionally check "Show modem status in menu bar".
  • Click "Connect". If everything worked, you will end up with a 'ppp0' device on your Mac with a local address of 192.168.2.200 and you will be able to access your Neo at 192.168.2.202.
Bluetooth networking with a Linux system - More secure way

Check this, probably needs some corrections

Bluetooth should behave just like our usbnet and provide full TCP/IP access to the phone. BNEP has to be used.

On the laptop

  • check these options in /etc/bluetooth/hcid.conf
security auto;
passkey "your pin";
lm master;
  • Start bluetooth
# /etc/init.d/bluetooth start
  • Start pand as server
 pand --listen --role NAP --encrypt
auto bnep0
iface bnep0 inet static
address 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
       post-up iptables -A POSTROUTING -t nat -j MASQUERADE -s 192.168.1.0/24
       post-up echo 1 > /proc/sys/net/ipv4/ip_forward
       post-up iptables -P FORWARD ACCEPT

On the Neo

  • Power on bluetooth (see above)
  • Scan for the laptop
root@fic-gta01:~$ hcitool scan
Scanning ...
        00:20:E0:5A:FE:C8       laptop
  • Set pin
root@fic-gta01:~$ passkey-agent 'your pin' 00:20:E0:5A:FE:C8 &
  • Connect to the laptop pand
root@fic-gta01:~$ pand -c 00:20:E0:5A:FE:C8
  • Configure your IP address
root@fic-gta01:~$ ifconfig bnep0 192.168.1.2
root@fic-gta01:~$ route add default gateway 192.168.1.1
  • Enjoy

Using Neo's connection from PC

Calling Neo's GPRS modem via Bluetooth

In this mode, Neo would behave like any other phone which can be used from a PC to get a network connection.

This section not written yet. Has someone set it up?

Sharing existing Neo's connection

In this mode, Neo already has a network connection (GPRS, WLAN, ...), and it should get shared to the PC. This guide is general on how to forward network connection from a machine running Linux to another machine. If interested, please see more information for example at http://www.gentoo.org/doc/en/bluetooth-guide.xml.

On the PC

  1. Check with hciconfig you have working Bluetooth

On the Neo (if on Debian etc., remember modprobe ohci_hcd hci_usb)

  1. Initialize Bluetooth as told before:
    1. echo 1 > /sys/bus/platform/devices/neo1973-pm-bt.0/power_on
    2. echo 0 > /sys/bus/platform/devices/neo1973-pm-bt.0/reset
  2. install iptables: opkg install http://www.angstrom-distribution.org/feeds/2008/ipk/glibc/armv4t/base/iptables_1.3.8-r4.1_armv4t.ipk
  3. modprobe bnep
  4. Check that hcid is running both on Neo and PC (Bluetooth 4.x: install bluez-compat)
  5. Use default passkey "1234" in /etc/bluetooth/hcid.conf
  6. pand --listen --role NAP --master --autozap # note: after this you might have to the the step 1 below ("On the PC") or the next step of getting the interface up does not work # note2: you could automate pand listener to start automatically when Bluetooth is turned on
  7. ifconfig bnep0 10.0.5.2 up
  8. echo 1 > /proc/sys/net/ipv4/ip_forward
  9. iptables -t nat -A POSTROUTING -j MASQUERADE -o ppp0

On the PC:

  1. sudo pand --connect <your bluetooth mac address> --service NAP --autozap
  2. ifconfig bnep0 10.0.5.1 up
  3. You can test the connection with ping 10.0.5.2
  4. sudo ip route add default via 10.0.5.2 dev bnep0
  5. [not automated yet] add GPRS connection's nameservers to /etc/resolv.conf

Advanced Audio Distribution Profile (A2DP)

See A2DP.

Headset Audio

Neo1973_Audio_Subsystem has detail about alsa settings and a proposal for audio scenario management.

To try this out, follow the instructions on the A2DP page to install software and run the passkey agent.

Remove or disable the stuff you put in asound.conf. When using a voice headset, the application uses the regular system audio device and it gets routed to bluetooth in the codec.

Put the headset in pairing mode. Replace the bluetooth address below with your headset's and run the python script:

#!/usr/bin/python
import dbus
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object('org.bluez', '/org/bluez'), 'org.bluez.Manager')
conn = manager.ActivateService('audio')
audio = dbus.Interface(bus.get_object(conn, '/org/bluez/audio'), 'org.bluez.audio.Manager')
path = audio.CreateHeadset('00:0B:2E:39:33:22')
audio.ChangeDefaultHeadset(path)
headset = dbus.Interface (bus.get_object(conn, path), 'org.bluez.audio.Headset')
headset.Connect()
headset.Play()

Now place a call and try to route it to bluetooth (after it's in progress):

alsactl -f /etc/gsmbluetooth.state restore

You may also be able to listen to system audio given the right state file:

alsactl -f /etc/systembluetooth.state restore
madplay song.mp3

Bluetooth Headset on Freerunner

The following describes a procedure applicable only to some old deprecated shit (namely OM2008.x), skip to the next section if you want to see instructions on using BT headset with modern FSO-based distros.

This thread suggests the following:

Turn on bluetooth. If some of the scripts below fail you may need to reboot Bluetooth after suspend
Pair your headset according to these instructions or use the script below. The script will change your .asoundrc so make a backup before you run it.
http://handheldshell.com/BtConfigure.py
Put the headset in pairing mode ( this only needs to be done once for each new headset ) and run
BtConfigure.py 
Download the the following python scripts to set up the audio service and set the headset as the default device:
http://handheldshell.com/BtHeadset.py
http://handheldshell.com/passkey.py
http://handheldshell.com/BtHeadsetDisconnect.py
http://handheldshell.com/python-pyalsaaudio_0.3-ml0_armv4t.ipk - can someone add python-pyalsa to the feeds ?
Download the the following python scripts if you prefer not to mess around with alsactl:
http://handheldshell.com/pymixer.py
http://handheldshell.com/volume.desktop
put pymixer in /usr/bin
chmod u+x /usr/bin/pymixer.py
put volume.desktop in /usr/share/applications
Get the [alsa state file] - this state file _WORKS_, mic and earphones are properly routed
cp gsm_headset.txt /usr/share/openmoko/scenarios/btheadset.state
from the home screen run Volume
from the terminal run
BtHeadset.py 
Wait until it says waiting for call to end, you should hear static in the headset. If you don't something has gone wrong.
Now start the call
In the volume control switch to the btheadset tab. press restore
You should now hear the call in your headset.
End the call
BtHeadsetDisconnect.py 
This was all done with the 2008-updates image from sept 4.
The new scripts rely on a specific format for the .asoundrc . A stanza like this is required :
pcm.headset {
    type bluetooth
    device <headset mac>
    profile "voice"
}

Once Again, Bluetooth Headset on Freerunner

List of known to work headsets

no-name "Jabra", discovered as "Bluetooth headset" -- PaulFertser

Plantronics Voyager 855 -- DigitalPioneer

no-name BT Headset-12 -- Vanous

Plantronics Explorer 220 -- Vendion

Insmat (HS200?), a real cheap one -- Rakshasa

List of non-working headsets

Iqua BHS-333 (it turns on/off, beeps etc properly, but gives no sound) -- PaulFertser

Nokia BH-200 same as above :( , will try again --Vanous

User reports

Heh, firsthand success experience finally :) I did everything according to these instructions, restarted frameworkd, started zhone, used fsoraw to request bluetooth resource (once i needed to press button on headset to turn it on). Call ring sounds at the Freerunner, calls got automatically routed to the headset, the sound was ok both ways (probably some tweaking might be needed depending on your headset's mic sensitivity). Unfortunately, alsa python bindings in Debian are too old so this works only for the first call (updating bindings should solve that). - this is not valid for SHR users, more calls can be placed and even after suspend when the bt device get's disconnected, it can be manually reconnected via dbus call (see bellow) -- Vanous. -- PaulFertser

Prerequisites

PLEASE NOTE: You will need a recent git revision of frameworkd (latest in SHR-Unstable repos will do) and bluez4 to do this.

If you're using SHR unstable, you already has a correct state file and rules.yaml, so you can skip to the pairing section.

State file

To prepare, you will need a fixed statefile for bluetooth. You can download this at: http://dl.getdropbox.com/u/453116/gsmbluetooth.state You need to put it on your Freerunner in the /usr/share/openmoko/scenarios/ directory.

Rules file

You will also need to modify your oevents/rules.yaml file. You should replace the entire section from Call -> Audio Scenario Handling (Which is shown) to (but not including) while: PowerStatus() with the following:

-
    #
    # Call -> Audio Scenario Handling
    #
    trigger: IncomingMessage()
    actions: MessageTone(play)

-
    while: CallListContains("incoming")
    filters: Not(CallListContains("active"))
    actions:
             - RingTone()
             - SetDisplayBrightness("0", 90)
             - OccupyResource(CPU)

-
    while: CallStatus()
    filters: Or(HasAttr(status, "outgoing"), HasAttr(status, "active"))
    actions:
            - OccupyResource(CPU)
-
    while: CallStatus()
    filters:
            - Or(HasAttr(status, "outgoing"), HasAttr(status, "active"))
            - Not(BTHeadsetIsConnected())
    actions:
            - SetScenario(gsmhandset)
-
    while: CallStatus()
    filters:
            - Or(HasAttr(status, "outgoing"), HasAttr(status, "active"))
            - BTHeadsetIsConnected()
    actions:
            - SetScenario(gsmbluetooth)
            - BTHeadsetPlaying()
-

Now you will need to restart frameworkd:

/etc/init.d/frameworkd restart

This causes problems for me, so you may find it easier to reboot. (Restarting ophonekitd seems to help with this):

killall ophonekitd && ophonekitd&

Pairing

Now, you must pair the bluetooth headset with your Freerunner. Make sure the bluetooth chip is powered up (can be done through the Connectivity section in the SHR-Unstable settings manager) and that bluetoothd is running:

/etc/init.d/bluetooth start

Now, to actually pair the bluetooth headset, you will need the simple-agent script. If you already have it, excellent. If you, like me, do not, then you can get it here: http://dl.getdropbox.com/u/453116/simple-agent Put it in /usr/bin/ and run chmod a+x /usr/bin/simple-agent

Now put your headset into pairing mode and run hcitool scan. Find your headset and use its address in the command simple-agent hci0 XX:XX:XX:XX:XX:XX. If you give a third parameter (what it is doesn't matter) to simple-agent, it will disconnect then reconnect to the headset.

Configuring bluez

Uncomment SCORouting=PCM setting in [General] section of

/etc/bluetooth/audio.conf

do not forget to restart bluetoothd after that.

Configuring FSO

Now we must tell frameworkd that you have a bluetooth headset. Headset parameters should be set in

/etc/freesmartphone/opreferences/conf/phone/default.yaml

Parameters bt-headset-enabled and bt-headset-address (see opreferences/schema/phone.yaml for semantics).

You need to restart FSO for the changes to take effect.

Connecting and reconnecting the bt device

You might need to get the bluetooth headset connected manually on the beggining and also after suspend:

mdbus -s org.bluez /org/bluez/`pidof bluetoothd`/hci0/dev_xx_xx_xx_xx_xx_xx org.bluez.Headset.Connect

where xx_xx_xx_xx_xx_xx is address of the device, for example:

mdbus -s org.bluez /org/bluez/`pidof bluetoothd`/hci0/dev_00_09_DD_31_92_98 org.bluez.Headset.Connect

Hopefully, your bluetooth headset now works. Good luck!

Additional helpfull testing commands

Unfortunately, some headsets do not output any sound while everything else (it turns on, beeps, powers amplifier, turns off) works as expected. The reason is unknown but nevertheless one might try these commands (please don't forget to report the results on ML!):

rmmod sco
modprobe sco disable_esco=1


If you want to manually play with bluetooth and statefiles, take into account that there's a kernel bug that makes loading gsmbluetooth state file not enough to actually work. One has to do

amixer sset "Capture Left Mixer" "Analogue Mix Right"
amixer sset "Capture Left Mixer" "Analogue Mix Left"

every time after loading this statefile.

Troubleshooting

Ensure you have bluetooth powered and that bluetoothd is running. Read frameworkd log for the hints. Report on IRC/ML.

Debugging

If anything goes wrong, capture the bluetooth traffic with

sudo hcidump -l 4096 -w bt.dump

and attach bt.dump to your bug reports etc.

Further reading

http://www.holtmann.org/papers/bluetooth/ols2006_slides.pdf http://wiki.bluez.org/wiki/Audio#org.bluez.Audio http://www.gentoo.org/doc/en/bluetooth-guide.xml