Direct-BT
2.3.1
Direct-BT - Direct Bluetooth Programming.
|
This project's canonical repositories is hosted on Gothel Software.
This project aims to create a clean, modern and easy to use API for Bluetooth LE and BREDR, fully accessible through C++, Java and other languages.
Direct-BT provides direct Bluetooth LE and BREDR programming, offering robust high-performance support for embedded & desktop with zero overhead via C++ and Java.
You will find a detailed overview of Direct-BT (C++) and the same in the Java API.
Direct-BT supports a fully event driven workflow from adapter management via device discovery to GATT programming. using its platform agnostic HCI, L2CAP, SMP and GATT client-side protocol implementation.
AdapterStatusListener allows listening to adapter changes and device discovery and BTGattCharListener to GATT indications and notifications.
Direct-BT may be utilized via its C++ API or via its Java API.
Direct-BT is exposed via the following native libraries
Direct-BT is C++17 conform and shall upgrade towards C++20 when widely available on all target platforms.
Some more elaboration on the implementation and its status
The host-side of HCI, L2CAP etc is usually implemented within the OS, e.g. Linux/BlueZ Kernel. These layers communicate with the actual BT controller and the user application, acting as the middleman.
Direct-BT offers packet types and handler facilities for HCI, L2CAP, SMP, ATT-PDU and GATT (as well to Linux/BlueZ-Mngr) to communicate with these universal host-side Bluetooth layers and hence to reach-out to devices.
Currently only the master/client mode is supported to work with LE BT devices.
LE Secure Connections and LE legacy pairing is supported, exposing BTSecurityLevel and SMPIOCapability setup per connection and providing automatic security mode negotiation.
BLE slave peripheral and GATT server support is underway.
BREDR support is planned and prepared for.
To support other platforms than Linux/BlueZ, we will have to
The following platforms are tested and hence supported
Debian 10 Buster (GNU/Linux)
Debian 11 Bullseye (GNU/Linux)
The following Bluetooth Adapter were tested
RTK_BT_5.0
)Since Direct-BT is not using a 3rd party Bluetooth client library or daemon/service, they should be disabled to allow operation without any interference. To disable the BlueZ D-Bus userspace daemon bluetoothd via systemd, you may use the following commands.
Since Direct-BT requires root permissions to certain Bluetooth network device facilities, non-root user require to be granted such permissions.
For GNU/Linux, there permissions are called capabilities. The following capabilites are required
On Debian 11 we can use package libcap2-bin
, version 1:2.44-1
, which provides the binaries /sbin/setcap
and /sbin/getcap
. It depends on package libcap2
, version >= 1:2.33
. If using earlier setcap
binaries, your mileage may vary (YMMV).
In case your platform lacks support for mentioned setcap
, you may need to execute your application as root using sudo
, e.g.:
To launch your Direct-BT application as a user, you may set the required capabilities
before launch via setcap
Alternatively one can set the required capabilities
of a Direct-BT application and launch it as a user via capsh.
Notable here is that capsh needs to be invoked by root to hand over the capabilities and to pass over the cap_net_raw,cap_net_admin+eip via –addamb=... it also needs cap_setpcap,cap_setuid,cap_setgid+ep beforehand.
The capsh method (default), setcap and root method is being utilized in
See Examples below ...
Exposed API closely follows and references the Bluetooth Specification.
Up to date API documentation can be found:
A guide for getting started with Direct-BT on C++ and Java may follow up.
org.direct_bt.BTFactory provides a factory to instantiate the initial root org.direct_bt.BTManager, using the Direct-BT implementation.
Direct-BT C++ examples are available, dbt_scanner10.cpp demonstrates the event driven and multithreading workflow.
Direct-BT Java examples are availble, DBTScanner10.java demonstrates the event driven and multithreading workflow - matching dbt_scanner10.cpp.
The project requires CMake 3.13+ for building and a Java JDK >= 11.
This project also uses the Jau Library as a git submodule, which has been extracted earlier from this project to better encapsulation and allow general use.
Direct-BT does not require GLib/GIO nor shall the BlueZ userspace service bluetoothd be active for best experience.
To disable the bluetoothd service using systemd:
Installing build dependencies on Debian (10 or 11):
For a generic build use:
The install target of the last command will create the include/ and lib/ directories with a copy of the headers and library objects respectively in your build location. Note that doing an out-of-source build may cause issues when rebuilding later on.
Our cmake configure has a number of options, cmake-gui or ccmake can show you all the options. The interesting ones are detailed below:
Changing install path from /usr/local to /usr
Building debug build:
Disable stripping native lib even in non debug build:
Override default javac debug arguments source,lines
:
Building debug and instrumentation (sanitizer) build:
Using clang instead of gcc:
Cross-compiling on a different system:
To build Java bindings:
To build examples:
To build documentation run:
Will be updated
Direct-BT is the new implementation as provided by Gothel Software and Zafena ICT.
If you like to utilize Direct-BT in a commercial setting, please contact Gothel Software to setup a potential support contract.
If you have any issues, please go through the Troubleshooting Guide.
If the solution is not there, please search for an existing issue in our Bugzilla DB, please contact us for a new bugzilla account via email to Sven Gothel sgoth. el@j ausof t.co m
You shall agree to Developer Certificate of Origin and Sign-off your code, using a real name and e-mail address.
Please check the Contribution document for more details.
Starting with version 2.3, the previously refactored TinyB has been removed completely.
Motivation was lack of detailed Bluetooth support, inclusive increasing diversion with Direct-BT. Furthermore, work is underway for BLE slave peripheral and GATT server
support and its mapping to BlueZ D-Bus is questionable and would be resource intensive.
2.3.0 Direct-BT Maturity (Bluetooth LE)
2.3.00
2.2.14
LE_2M
and L2_CODED
, ... ???2.2.13
2.2.11
BTDeviceRegistry
and BTSecurityRegistry
universalBTDeviceRegistry
and BTSecurityRegistry
to direct_bt
library (from examples)hash_code()
, clear()
, indexOf()
, contains()
, ...readAndApply(..)
must validate minSecLevel
.BTAdapter::mgmtEvDeviceFoundHCI(..)
: Clarify code path, covering name change via AD EIR.BTAdapter::startDiscovery(..)
-> HCIHandler::le_set_scan_param(..)
: Add le_scan_active
and filter_policy
. Active scanning is used to gather device name in discovery mode (AD EIR).-dbt_debug
argument for AD EIR direct_bt.debug.hci.scan_ad_eir
and parse EIR GAPFlags2.2.5
setPairingPasskey(passkey = 0)
for performance.2.2.4
SMPKeyBin
for LTK, CSRK and secure connection param setup persistence and upload.2.2.00
jaulib
.2.1.33
2.1.30
2.0.0
0.5.0
0.4.0