I need to change the Secure Simple Pairing mode programmatically, but I can't figure out how to set SSP mode on or off in Bluez using a DBus command.
Using btmgmt utility, I just do:
btmgmt ssp off
btmgmt ssp on
Ok, but what I need is rather DBus method calls that I can include in my application.
But the Bluez documentation doesn't seem to mention any DBus method to change the SSP mode.
Does anyone know how to do that? (a gdbus call or dbus-send example would be just great).
Or is this just impossible?
There is no way you can do this using DBus. Bluez has no DBus API for this. You need to either use Bluetooth Management socket interface to toggle SSP mode or you can do this using bluez deprecated HCI interface.
To know how to use Bluetooth Management sockets see bluez-5-X/doc/mgmt-api.txt file in bluez-5.X source directory. Command code to toggle SSP is 0x000B. Actually, this is how btmgmt tool enables/disables SSP. It uses Bluetooth Management socket. Search keyword ssp in bluez-5.X/tools/btmgmt.c and see the sample C code.
You can also do this using deprecated hci API (not recommended). See hci_write_simple_pairing_mode method in bluez-5-X/lib/hci.c.
Related
Prior to BlueZ 5, the way to add/remove Bluetooth services/attributes/profiles on Linux was done through the sdptool as follows:-
To browse local records
#sdptool browse local
Browsing FF:FF:FF:00:00:00 ...
To add a service
#sdptool add SP
Serial Port service registered
To remove a service
#sdptool del 0x10007
Service Record deleted.
However, sdptool was deprecated (along with hciattach, hciconfig, hcitool, hcidump, rfcomm, ciptool, and gatttool) and removed from the main BlueZ build as can be seen in the following links:-
Link 1
Link 2
Link 3
Fortunately, most of these commands have been replaced with newer ones (btattach, btmgmt, and bluetoothctl). However, there doesn't seem to be any replacement for the sdptool.
My question is:- what tool can I use now instead of sdptool in order to browse local services/profile as well as add or remove profiles?
Please note that I am aware that sdptool can be rebuilt-in and enabled, but I am searching for the replacement to the command rather than a workaround.
From Bluez 5 this needs to be done using ProfileManager DBUS interface. One needs to register the custom/external profile using this interface and Bluez handles all the aspect of security and connection.
Once the connection is ready, bluez provides file descriptor to operate on for the external profile. You can find an example implementation of HFP profile in bluez-alsa.
In detail, You can implement all the methods of org.bluez.Profile1 interface and register it with Bluez using org.bluez.ProfileManager1 interface where you can specify the UUID, auth (if any needed).
In bluez-alsa,
Registration is done here.
Methods are implemented here.
Once the connection for this profile is established, NewConnection API is called with the fd in argument.
But AFAIK, there isn't any direct way to achieve this using existing tools like bluetoothctl.
I have a device with a few custom GATT services, and I would like to write a Linux program to interact with it. After some searching I found out that Linux is using BlueZ to handle the Bluetooth LE protocol. I'm using Ubuntu 15.10 with BlueZ 5.35, but I cannot figure out how use this BlueZ from a user-space program. I cannot find an API documentation anywhere, no tutorials, examples, nothing. Is it even possible to use this BlueZ stack to do anything other than just connecting to Bluetooth devices with default services? And if so, where is the documentation? (Preferably C/C++ API but at this point anything goes)
Have a look at attrib/gatttool.c in the bluez sources [1]. Gatttool is a command line utility for connecting to BTLE devices using the C "API". The GATT interface is not exposed in libbluetooth though.
A newer alternative to gatttool and thus another example to learn
from is the btgatt-client, which you can find in
tools/btgatt-client.c (to enable compilation configure bluez with
--enable-experimental).
Besides the C interface bluez integrated a DBUS interface.
bluetoothctl is an example tool using the DBUS interface. The code of
bluetoothctl can be found in client/ [2].
Another example program using the C interface of bluez is the Anki
Drive SDK [3]. It packaged the bluez GATT C interface in its own
library libbzle [4]. When using the C interface you have to connect a
socket when establishing a BTLE connection. The gatttool does this
via the GATT interface, which in turn uses glib iirc. But you can
also do this using syscalls (socket, connect, ...) as explained e.g.
here [5]. This document also explains:
Unfortunately, as of now there is no official API reference to refer to, so more curious readers are advised to download and examine the BlueZ source code.
Gilbert Brault also extracted the GATT interface from bluez [6] and links to a rudimentary doxygen documentation of the GATT interface [7] with the following disclaimer:
This is a work in progress with the intent of documenting all important functions and data structures
Also Szymon Janc gave a nice overview in his talk "Bluetooth on Modern Linux" at the Embedded Linux Conference 2016 [8]. Starting at 42:00 he talks about the unexposed C interface. But in general he seems to recommend the DBUS API (see "Tips" slide at 45:30). Some DBUS documentation can be found in doc/gatt-api.txt [9] and Python examples using the DBUS interface can be found in test/.
Hope this helps.
[1] http://git.kernel.org/cgit/bluetooth/bluez.git/tree/attrib/gatttool.c
[2] http://git.kernel.org/cgit/bluetooth/bluez.git/tree/client/
[3] https://github.com/anki/drive-sdk/
[4] https://github.com/anki/drive-sdk/tree/master/deps/bzle/
[5] https://people.csail.mit.edu/albert/bluez-intro/c404.html
[6] https://github.com/gbrault/gattclient
[7] http://gbrault.github.io/gattclient/index.html
[8] https://www.youtube.com/watch?v=tclS9arLFzk
[9] http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/gatt-api.txt
I feel your pain. I needed to add user input from a custom BLE peripheral, a simple remote pushbutton, to an embedded program running under Linux (Stretch) on a Raspberry Pi. I was stunned by the needless complexity and Spartan (not a compliment) documentation of the BlueZ API. All the BlueZ “examples” are written from the perspective that Bluetooth is the center of the universe and the user wants to support every Bluetooth device ever invented. In my case I knew exactly the device, service, and GATT characteristics I needed to interact with, and I wanted a minimum overhead task that would do its thing in a low priority thread.
It turns out a BLE central client is pretty straightforward using BlueZ, but it was an arduous road starting with the source for the BlueZ utility bluetoothctl in release 5.49. I accomplished my needs using only three unmodified source files from the BlueZ distribution and excerpts from an additional three source files. Since the BlueZ source is inextricably dependent on D-Bus and the Gnome GLib main loop, I grudgingly included them.
Following OlivierM's generous lead, and in hopes that my embarrassingly massive investment in time saves someone else a month of their life, I have posted my example Bluetooth BLE client on GitHub: https://github.com/jjjsmit/BluetoothBLEClient
It would arguably be simpler and quicker to write a shell script on Linux to do what you need to do. The BlueZ commands are relatively simple and straightforward, and there are many tutorials and questions on how to use it.
Tutorials:-
http://www.jaredwolff.com/blog/get-started-with-bluetooth-low-energy/
https://learn.adafruit.com/reverse-engineering-a-bluetooth-low-energy-light-bulb/control-with-bluez
https://lilyhack.wordpress.com/2014/02/03/ble-read-write-arduino-raspberry-pi/
http://joost.damad.be/2013/08/experiments-with-bluetooth-low-energy.html
Questions:-
Using Bluetooth low energy in linux command line
Bluetooth Low Energy: listening for notifications/indications in linux
How can I connect to the FitBit Zip over Bluetooth 4.0 LE on Linux with bluez?
Once you are more familiar with using the commands manually you can then write a minimal shell script so that this is automated for you.
I had a similar issue which is to interact with a BLE device with a GATT C/C++ API. I have realized there was no such API existing.
The way I fixed my issue was to write my own GATT library. I have pushed the code on Github: https://github.com/labapart/gattlib
I use this library in my own BLE project and it fulfils my needs. I created few examples https://github.com/labapart/gattlib/tree/master/examples that use the library to encourage people to use it and have better feedback.
I recently found out that Qt has Bluetooth Low Energy support as host since Qt 5.7. Qt Bluetooth LE. It is available under LGPLv3 or commercial license, and exposes a C++ API.
I want to create an app in Linux that can browse the files from a bluetooth phone and eventually retrieve them. I've been reading and googling and it seems the way to do it is communicating with Bluez via DBus.
However there doesn't seem to be DBus methods for interacting with files. Therefore, do I need to use obex protocol to do this instead? I'm quite lost here.
Thanks
In your case you want to use FTP profile which uses obex protocol,this obex will call RFCOMM layer and thus bluetooth will be used.You need to create a filetransfer(org.bluez.obex.FileTransfer) interface and call obex methods via dbus call,check here or the ftp plugin available in bluez
I am working on using the Bluetooth low energy modem with Linux. I am using the command line option for that i.e. hcitool . I am able to the find the devices using the command: $ hcitool scan
It is working fine for me, also I am able to broadcast my device using :
sudo hciconfig hci0 leadv
It is also working fine. But I want to add the services and characteristic to the modem device which can be detected by other device. I have tried sdptool add but it is not working for me. Does anyone know how to add the services and characteristics to the peripheral using the command line tools in ubuntu?
Edit: My modem is broadcasting but not able to explore the services and characteristic to the other BLE device. Now I am able to set the name of device using hcio name command
Edit: Now I am able to render the services and characteristic, by simultaneously running sudo hcidump command. But I am not able to track from where I am getting those services and characteristics. One definite observation is those services are rendering from the machine.
SDP is absent in BLE. Broadcast/advertise frame and GATT client/server are used instead.
Several links:
BlueZ gatttool: command line tool to run common GATT procedures
BlueZ GATT's ready profiles
hint: DBUS
GATT and DBUS example
How can I connect to the FitBit Zip over Bluetooth 4.0 LE on Linux with bluez?
Bluetooth Low Energy: listening for notifications/indications in linux
http://comments.gmane.org/gmane.linux.bluez.kernel/29547
I used to broadcast BT services by following this article. This page not only shouws you how to advertise a profile, but also gives you an example on how to implement the HSP profile.
To know the bt class you need to announce, you can check this other page.
What are the IPC mechanisms used in webos for bluez connection, also to develop any bluetooth profile in webos, are the proper methods exposed or bluetooth , can someone explain me on the luna bus interaction with bluez ?
Luna-bus system is used in webos for bluez connection.
"com.palm.bt" is a Luna service name for webos bluetooth. Methods such as connect, write, read and close should be defined in bluetooth adapter and you can use this method using luna-send command. You can find the luna-send command example here: http://www.openwebosproject.org/docs/developer_guide/tools/luna_send/#.Uliv2mQqd1M