BlueZ on Linux
We have support for the BlueZ Bluetooth protocol stack on Linux. We support running on the
CLI there, but require a patch to the Mono runtime as it blocks Bluetooth Sockets by default. Our BlueZ support is not included in our release versions but is included in a DEBUG build, so you need to build the library
yourself to use this (and for instance you can add a definition of BlueZ
in the project file if you want to include it in a release build).
Currently we have the following support:
- Radio: Well supported, for instance we list the values properly (Address, Name, CoD, Mode and HardwareStatus), and do also allow setting the Mode. 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: Good support for discovering both in-range and remembered devices, ‘live’ discovery is also supported. Note that the discovery support on BlueZ lists in-range devices only when first discovered; which is differenct from other stacks.
More work is needed to use the arrival and departure events to provide the same behaviour as on other stacks
- Security: RemoveDevice supported. PairRequest requires us to run a D-Bus Agent and that wouldn't work for me.
As noted above BluetoothClient.Connect and BluetoothListener use Sockets. However current versions of Mono (2.8) 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
. Use the second patch and not the first. LATER:
See also new
Apply that patch to your Mono source code, rebuild, test and let me have your comments… Other dependencies required include managed assembly
and native library libbluetooth
. For the latter install the necessary package, for instance on Ubuntu that's package
. For the former there's a copy in our sources at "ExternalLibs/Mono etc/NDesk.DBus.dll". There's presumably also a package for that.
for sample logging to compare against what you see. To see debug logging on Mono use the following command first:
As a mega hack, if you want to test device discovery before you've patched Mono's sockets support you can enable the
hack at the top of
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 using the original BlueZ ‘hci’ API for some things and the D-Bus API for the rest.
Since the original BlueZ ‘hci’ API seems deprecated -- it is included in that 'dev' package -- we should look at changing to only using the D-Bus API.
Note that if the D-Bus managed assembly is missing, then very unhelpful error message shown below occurs. Note that it doesn't mention any assembly/library name. I'll have a check to see if there's anything we as a consumer of that library can do.
Exception creating factory 'InTheHand.Net.Bluetooth.BlueZ.BluezFactory, ex: System.TypeLoadException: A type load exception has occurred.
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) [0x00000] in <filename unknown>:0