Bluetooth support

Matthew Garrett mjg59 at srcf.ucam.org
Wed Aug 16 14:30:02 PDT 2006


Hi,

I've put the current version of my Bluetooth code at 
http://www.codon.org.uk/~mjg59/tmp/addon-bluetooth.tar.gz . At this 
point I've managed to build working code around it, so I think it's 
fairly feature complete. Of course, it's probably also massively buggy.

Requirements: Post 0.57 git, plus as recent a bluez as you can get away 
with. Some functionality requires patches to bluez that aren't currently 
integrated - see later on for that.

This addon is started whenever a Bluetooth host controller is connected 
to the machine. Host controllers provide the following methods:

Scan
----
Takes no arguments. Triggers the discovery process. As new devices are 
found, they will be added to the hal device tree underneath the hci. 
Devices that are currently in the tree, but which are (a) not currently 
connected and (b) not found on a subsequent discovery pass will be 
removed from the tree.

SetName
-------
Takes a single string argument. This sets the name of the device, which 
will be visible to other bluetooth devices if the hci is discoverable.

SetMode
-------
Takes a single string argument. Values may be "off", "connectable" or 
"discoverable".

SetDiscoverableTimeout
----------------------
Takes a single integer argument. This is the number of seconds that the 
hci will remain in discoverable mode before lapsing back to connectable. 
If 0, the device will remain discoverable forever.

Connect
-------
Takes a single string argument. This will attempt to trigger a baseband 
connection to the bluetooth device with the specified address. If 
successful, this will result in the device being added to the hal tree. 
Intended for situations where you know the bluetooth address of a 
device, but it is currently not discoverable.

(note: requires patch to bluez that is not yet integrated)

Once bluetooth devices have appeared in the tree, they will each have 
the following methods:

Pair
----
Takes no arguments. Will attempt to pair with the device in question. If 
a link key already exists, this will succeed without the requirement to 
provide a PIN. Otherwise a PIN agent is required.

DisconnectRemoteDevice
----------------------
Takes no arguments. Tears down any existing connections.

Unbond
------
Takes no arguments. Tears down any existing connections and removes the 
link key.

SetRemoteAlias
--------------
Takes a single string argument. This allows applications to provide a 
friendly alias for the device. This may be used instead of the name 
provided by the device itself during discovery.

ClearRemoteAlias
----------------
Takes no arguments. This clears any existing friendly alias for the 
device.

Browse
------
Takes no arguments. This browses the device for any available services. 
Each located service will create a new hal object.

Once a device has been browsed, a set of new objects will be added. 
Currently these have no methods. I'm waiting for a patch to be added to 
Bluez that makes it possible to set up rfcomm connections via the DBus 
interface - once that's there, this will become rather more useful.

I've attached a hal-device dump of what these Bluetooth devices look 
like in the tree. Comments welcome.

-- 
Matthew Garrett | mjg59 at srcf.ucam.org
-------------- next part --------------
0: udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF/1103'
  info.udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF/1103'  (string)
  bluetooth.serviceid = 'Dial-Up Networking'  (string)
  info.uuid = '1103'  (string)
  info.product = 'Dial-Up Networking'  (string)
  info.parent = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF'  (string)
  info.capabilities = { 'bluetooth.service', 'bluetooth.dun' } (string list)

1: udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF/111a'
  info.udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF/111a'  (string)
  bluetooth.serviceid = 'Imaging'  (string)
  info.uuid = '111a'  (string)
  info.product = 'Imaging'  (string)
  info.parent = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF'  (string)
  info.capabilities = { 'bluetooth.service', 'bluetooth.imaging' } (string list)

2: udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF/1105'
  info.udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF/1105'  (string)
  bluetooth.serviceid = 'OBEX Object Push'  (string)
  info.uuid = '1105'  (string)
  info.product = 'OBEX Object Push'  (string)
  info.parent = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF'  (string)
  info.capabilities = { 'bluetooth.service', 'bluetooth.obex_push' } (string list)

3: udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF/00005005_0000_1000_8000_0002ee000001'
  info.udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF/00005005_0000_1000_8000_0002ee000001'  (string)
  bluetooth.serviceid = 'Nokia OBEX PC Suite Services'  (string)
  info.uuid = '00005005-0000-1000-8000-0002ee000001'  (string)
  info.product = 'Nokia OBEX PC Suite Services'  (string)
  info.parent = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF'  (string)
  info.capabilities = { 'bluetooth.service' } (string list)

4: udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF/00000002_0000_1000_8000_0002ee000002'
  info.udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF/00000002_0000_1000_8000_0002ee000002'  (string)
  bluetooth.serviceid = 'SyncMLClient'  (string)
  info.uuid = '00000002-0000-1000-8000-0002ee000002'  (string)
  info.product = 'SyncMLClient'  (string)
  info.parent = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF'  (string)
  info.capabilities = { 'bluetooth.service' } (string list)

5: udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF/1106'
  info.udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF/1106'  (string)
  bluetooth.serviceid = 'OBEX File Transfer'  (string)
  info.uuid = '1106'  (string)
  info.product = 'OBEX File Transfer'  (string)
  info.parent = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF'  (string)
  info.capabilities = { 'bluetooth.service', 'bluetooth.obex_ftp' } (string list)

6: udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF/1108'
  info.udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF/1108'  (string)
  bluetooth.serviceid = 'Headset Audio Gateway'  (string)
  info.uuid = '1108'  (string)
  info.product = 'Headset Audio Gateway'  (string)
  info.parent = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF'  (string)
  info.capabilities = { 'bluetooth.service', 'bluetooth.headset' } (string list)

7: udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF/111f'
  info.udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF/111f'  (string)
  bluetooth.serviceid = 'Hands-Free Audio Gateway'  (string)
  info.uuid = '111f'  (string)
  info.product = 'Hands-Free Audio Gateway'  (string)
  info.parent = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF'  (string)
  info.capabilities = { 'bluetooth.service', 'bluetooth.handsfreegw' } (string list)

8: udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF'
  info.interfaces = { 'org.freedesktop.Hal.Device.Bluetooth' } (string list)
  bluetooth.manufacturer = 'Cambridge Silicon Radio'  (string)
  bluetooth.revision = 'HCI 0x6CC'  (string)
  bluetooth.version = 'Bluetooth 2.0'  (string)
  bluetooth.lastused = '2006-08-16 21:27:53 GMT'  (string)
  bluetooth.lastseen = '2006-08-16 21:27:36 GMT'  (string)
  bluetooth.company = ''  (string)
  bluetooth.paired = true  (bool)
  bluetooth.connected = true  (bool)
  bluetooth.alias = ''  (string)
  info.product = 'Mjg59'  (string)
  bluetooth.minor = 'smart phone'  (string)
  bluetooth.major = 'phone'  (string)
  info.udi = '/org/freedesktop/Hal/devices/bluetooth/hci0/00_17_4B_48_D8_AF'  (string)
  bluetooth.addr = '00:17:4B:48:D8:AF'  (string)
  info.parent = '/org/freedesktop/Hal/devices/usb_device_a5c_200a_001060AC1483_if0_bluetooth_hci'  (string)
  info.capabilities = { 'bluetooth' } (string list)


More information about the hal mailing list