BlueZ


Start-up, console/debug logging:

[Error 11:14:14.598] [UiaDbusBridge.RaiseAutomationEvent] Inconsistent provider -> wrapper mapping state
[Error 11:14:14.696] [UiaDbusBridge.RaiseAutomationEvent] Inconsistent provider -> wrapper mapping state
Exception creating factory 'InTheHand.Net.Bluetooth.SocketsBluetoothFactory, ex: System.DllNotFoundException: Irprops.cpl
  at (wrapper managed-to-native) InTheHand.Net.Bluetooth.Msft.NativeMethods:BluetoothFindFirstRadio (InTheHand.Net.Bluetooth.BLUETOOTH_FIND_RADIO_PARAMS&,intptr&)
  at InTheHand.Net.Bluetooth.Msft.WindowsBluetoothRadio.get_AllRadios () [0x00000] in <filename unknown>:0
  at InTheHand.Net.Bluetooth.Msft.WindowsBluetoothRadio.get_IsPlatformSupported () [0x00000] in <filename unknown>:0
  at InTheHand.Net.Bluetooth.SocketsBluetoothFactory..ctor () [0x00000] in <filename unknown>:0
  at (wrapper managed-to-native) System.Reflection.MonoCMethod:InternalInvoke (System.Reflection.MonoCMethod*,object,object[],System.Exception&)
  at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00119] in /usr/src/packages/BUILD/mono-2.8/mcs/class/corlib/System.Reflection/MonoMethod.cs:523
BluezFactory platform: Unix = 0x00000004
got Manager
Dbus loop running
DefaultAdapter : ObjectPath
got Adapter
Now Registered2
InitRadios idPrimary: 0, dd: 14
Radio SUCCESS, addr: 001583B41BFA
got Manager
got Adapter
  got addrStr: 00:15:83:B4:1B:FA
got Manager
got Adapter
  got addrStr: 00:15:83:B4:1B:FA
InitRadios curDd: 15
Radio SUCCESS, addr: 001583B41BFA
got Manager
got Adapter
  got addrStr: 00:15:83:B4:1B:FA
got Manager
got Adapter
  got addrStr: 00:15:83:B4:1B:FA
Id: 0, DD: 16
Radio SUCCESS, addr: 001583B41BFA
got Manager
got Adapter
  got addrStr: 00:15:83:B4:1B:FA
got Manager
got Adapter
  got addrStr: 00:15:83:B4:1B:FA
Done BluezFactory init.

Get All Radios (one present):

---- GetAllRadios ----
1)  Radio, address: 00:15:83:B4:1B:FA
Mode: Discoverable
Name: linux-0
HCI Version: v2_0wEdr, Revision: 1958
LMP Version: v2_0wEdr, Subversion: 1958
ClassOfDevice: 4A0100, device: Computer / service: Network, Capturing, Telephony
Software: BlueZXxxx,  Hardware: CambridgeSiliconRadio, status: Running
Remote: ''

Logging:

got Manager
got Adapter
  got addrStr: 00:15:83:B4:1B:FA
got Manager
got Adapter
  got addrStr: 00:15:83:B4:1B:FA

Get DeviceInfo (i.e. new BluetoothDeviceInfo(BluetoothAddress.Parse(…)):

---- GetDeviceInfo ----
* FREDPC1w
Address: 000A3A686599
Remembered: False, Authenticated: False, Connected: False
LastSeen: 01/01/0001 00:00:00 (Unspecified), LastUsed: 01/01/0001 00:00:00 (Unspecified)
CoD: (0x000000)
 Device:  Miscellaneous (0x00) / Miscellaneous (0x0000)
 Service: None (0x00)
Rssi: failed

Logging:

got Manager
DefaultAdapter : ObjectPath
got Adapter
gonna FindDevice
GetDevice_ error: org.bluez.Error.DoesNotExist: Device does not exist
No dbus device properties.
_name is null
hci_read_remote_name ret: 0.

Get DeviceInfo to non-existent device:

---- GetDeviceInfo ----
* 00:22:33:44:55:66
Address: 002233445566
Remembered: False, Authenticated: False, Connected: False
LastSeen: 01/01/0001 00:00:00 (Unspecified), LastUsed: 01/01/0001 00:00:00 (Unspecified)
CoD: (0x000000)
 Device:  Miscellaneous (0x00) / Miscellaneous (0x0000)
 Service: None (0x00)
Rssi: failed

Logging:

got Manager
DefaultAdapter : ObjectPath
got Adapter
gonna FindDevice
GetDevice_ error: org.bluez.Error.DoesNotExist: Device does not exist
No dbus device properties.
_name is null
hci_read_remote_name ret: -1.

Set Radio Mode; Success. Logging:

got Adapter
DONE SetAdapterMode.

BDI.GetServiceRecords; Success.  Logging:

got Manager
DefaultAdapter : ObjectPath
got Adapter
gonna FindDevice
GetDevice_ error: org.bluez.Error.DoesNotExist: Device does not exist
No dbus device properties.
Gonna sdp_connect (SafeHandle)...
xAdapter_PropertyChanged name: Devices, newValue: NDesk.DBus.ObjectPath[]
rfcommOnly: False
sdp_service_search_attr_req in: -1267215624, attrid_list: -1267271928
sdp_service_search_attr_req ret: 0, result: -1267467016
attr count: 8
record count: 1
xAdapter_PropertyChanged name: Devices, newValue: NDesk.DBus.ObjectPath[]

BluetoothClient fails!

---- NewBtCli ----
Swallowed Exception: System.PlatformNotSupportedException: 32feet.NET does not support the Bluetooth stack on this device. ---> System.Net.Sockets.SocketException: An address incompatible with the requested protocol was used
  at System.Net.Sockets.Socket..ctor (AddressFamily family, SocketType type, ProtocolType proto) [0x0005e] in /usr/src/packages/BUILD/mono-2.8/mcs/class/System/System.Net.Sockets/Socket_2_1.cs:212
  at InTheHand.Net.Bluetooth.Msft.SocketBluetoothClient.CreateSocket () [0x00000] in :0
  at InTheHand.Net.Bluetooth.Msft.SocketBluetoothClient..ctor (InTheHand.Net.Bluetooth.Factory.BluetoothFactory fcty) [0x00000] in :0
  --- End of inner exception stack trace ---
  at InTheHand.Net.Bluetooth.Msft.SocketBluetoothClient..ctor (InTheHand.Net.Bluetooth.Factory.BluetoothFactory fcty) [0x00000] in :0
  at InTheHand.Net.Bluetooth.BlueZ.BluezClient..ctor (InTheHand.Net.Bluetooth.BlueZ.BluezFactory fcty) [0x00000] in :0
  at InTheHand.Net.Bluetooth.BlueZ.BluezFactory.GetBluetoothClient () [0x00000] in :0
  at InTheHand.Net.Bluetooth.Factory.BluetoothFactory.DoGetBluetoothClient () [0x00000] in :0
  at InTheHand.Net.Sockets.BluetoothClient..ctor (InTheHand.Net.Bluetooth.Factory.BluetoothFactory factory) [0x00000] in :0
  at InTheHand.Net.Sockets.BluetoothClient..ctor () [0x00000] in :0
  at ConsoleMenuTesting.BluetoothTesting.Create_BluetoothClient () [0x00000] in :0
  at ConsoleMenuTesting.BluetoothTesting.NewBtCli () [0x00000] in :0
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod*,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000d0] in /usr/src/packages/BUILD/mono-2.8/mcs/class/corlib/System.Reflection/MonoMethod.cs:223

xx

We’ve implemented support to use BlueZ’s D-Bus ‘newly discovered device’ signal for our ‘live’ discovery feature. Use BluetoothComponent.DiscoverDevicesAsync as always.   It appears that a signal is only raised if the device wasn’t seen the last time discovery was run — I haven’t found whether this is per application or is controllable through their “session” features.  Maybe we need to store the old set each time, adding when we see the DeviceFound signal and removing from it when we see the DeviceDisappeared signal.

Radio.set_Mode is also now supported.  Note that once a radio is ‘PoweredOff’ I can’t find a way through the BlueZ control panels to re-enable it, we don’t load it either so I had to use a custome application to re-enable it.

Finally we’ve also had some feedback from the Mono team that they don’t want to support Bluetooth sockets specifically and have to pull in their header file, so we suggested having their socket layer stop blocking unknown address families and sockaddr types but instead pass them through. We submitted a new patch to them for this[1] and have updated out BluetoothEndPoint class to match[2].

[1] https://bugzilla.novell.com/show_bug.cgi?id=655153#c6

[2] http://32feet.codeplex.com/SourceControl/changeset/changes/82268

(Further to: https://32feetnetdev.wordpress.com/2010/12/05/further-support-for-bluez/ and https://32feetnetdev.wordpress.com/2010/11/24/bluez-support/)

We’ve now added support for the BlueZ D-Bus API.  So with it we now have support for:

  • Radio: Reading Mode and HardwareStatus is supported.
  • DiscoverDevices: Get Remembered devices, so we have full support there except for ‘live’ discovery.
  • BluetoothSecurity.RemoveDevice: Supported.
  • BluetoothSecurity.PairRequest: Support for pin=null case, that is where we want the system to prompt the local user for passphrase/etc.

We need to do more work to support Radio.set_Mode and fully automated PairRequest.

We have new support for the BlueZ Bluetooth protocol stack on Linux. We running on the Mono CLR there.

 Currently we have the following support:

  • Radio: We list the values propertly (Address, Name, CoD).  We do not get the Mode or HardwareStatus or allow setting them.   We will list all the installed radios, but see below for multi-radio usage.
  • Client.Connect: Supported.  No support for Authenticate/Encrypt/SetPin etc.
  • Data transfer: BlueZ uses Sockets for data transfer so everything should be fine. 🙂
  • Listener: Supported, including advertising SDP record.  Again no support for Auth/Encrypt/SetPin.
  • Client.DiscoverDevices: we discover only in-range devices.  There is no support currently for remembered devices and will return an error if they are requested — there doesn’t seem a ‘hci’ API.  There is also currently no support for ‘live’ discovery.
  • Security: No support currently.

As noted above BluetoothClient.Connect and BluetoothListener use Sockets.  Current versions of Mono do not support opening or using Bluetooth sockets.  My old pal Andy Hume and I have created a patch to Mono to enable this support, and have posted it as Mono/Novell bug id 655153.

Apply that patch to your Mono source code, rebuild, test and let me have your comments…

As noted above, unlike apparently every stack on Windows, BlueZ does support multiple radios. We do list all the radios and BluetoothClient and BluetoothListener will bind to a particular local address if requested to do so. However the other functionality does not currently ensure it runs on a particular radio, DiscoverDevices and GetServiceRecords (and as used internally by Connect) will use the primary radio.

We currently are using the original BlueZ ‘hci’ API. For many things their D-Bus based API is recommended instead, we will add support for that at some stage… There seems for instance no native API to get the list of remembered device, unless I’ve missed it…