Direct-BT
v3.1.2
Direct-BT - Direct Bluetooth Programming.
|
A thread safe singleton handler of the BTAdapter manager, e.g. More...
#include <BTManager.hpp>
Public Types | |
enum | Defaults : int32_t { ClientMaxMTU = 512 } |
typedef jau::nsize_t | size_type |
Public Member Functions | |
BTManager (const BTManager &)=delete | |
~BTManager () noexcept override | |
void | addChangedAdapterSetCallback (ChangedAdapterSetFunc f) |
Adds the given ChangedAdapterSetFunc to this manager. More... | |
void | addChangedAdapterSetCallback (const ChangedAdapterSetCallback &l) |
ChangedAdapterSetCallback handling. More... | |
bool | addDeviceToWhitelist (const uint16_t dev_id, const BDAddressAndType &addressAndType, const HCIWhitelistConnectType ctype) noexcept |
Add the given device to the adapter's autoconnect whitelist. More... | |
bool | addMgmtEventCallback (const int dev_id, const MgmtEvent::Opcode opc, const MgmtEventCallback &cb) noexcept |
MgmtEventCallback handling More... | |
void | clearAllCallbacks () noexcept |
Removes all MgmtEventCallbacks from all MgmtEvent::Opcode lists. More... | |
void | clearMgmtEventCallbacks (const MgmtEvent::Opcode opc) noexcept |
Removes all MgmtEventCallbacks from the to the named MgmtEvent::Opcode list. More... | |
void | close () noexcept |
std::string | get_java_class () const noexcept override |
std::shared_ptr< BTAdapter > | getAdapter (const uint16_t dev_id) const noexcept |
Returns the DBTAdapter with the given dev_id, or nullptr if not found. More... | |
size_type | getAdapterCount () const noexcept |
retrieve information gathered at startup More... | |
jau::darray< std::shared_ptr< BTAdapter > > | getAdapters () |
Returns a list of currently added DBTAdapter. More... | |
std::shared_ptr< ConnectionInfo > | getConnectionInfo (const uint16_t dev_id, const BDAddressAndType &addressAndType) noexcept |
std::shared_ptr< BTAdapter > | getDefaultAdapter () const noexcept |
Returns the default AdapterInfo. More... | |
SMPIOCapability | getIOCapability (const uint16_t dev_id) const noexcept |
HCIStatusCode | initializeAdapter (AdapterInfo &adapterInfo, const uint16_t dev_id, const BTRole btRole, const BTMode btMode) noexcept |
Initialize the adapter with default values, including power-on. More... | |
bool | isDeviceWhitelisted (const uint16_t dev_id, const BDAddressAndType &addressAndType) noexcept |
Returns true, if the adapter's device is already whitelisted. More... | |
bool | isOpen () const noexcept |
Returns true if this mgmt instance is open and hence valid, otherwise false. More... | |
bool | isValidLongTermKeyAddressAndType (const EUI48 &address, const BDAddressType &address_type) const noexcept |
Security commands. More... | |
void | operator= (const BTManager &)=delete |
std::vector< MgmtDefaultParam > | readDefaultSysParam (const uint16_t dev_id) noexcept |
Read default connection parameter for given adapter to the kernel. More... | |
size_type | removeAllChangedAdapterSetCallbacks () noexcept |
Remove all added ChangedAdapterSetCallback entries from this manager. More... | |
size_type | removeAllDevicesFromWhitelist () noexcept |
Remove all previously added devices from the autoconnect whitelist. More... | |
size_type | removeChangedAdapterSetCallback (ChangedAdapterSetFunc f) |
Remove the given ChangedAdapterSetFunc from this manager. More... | |
size_type | removeChangedAdapterSetCallback (const ChangedAdapterSetCallback &l) |
Remove the given ChangedAdapterSetCallback from this manager. More... | |
bool | removeDeviceFromWhitelist (const uint16_t dev_id, const BDAddressAndType &addressAndType) noexcept |
Remove the given device from the adapter's autoconnect whitelist. More... | |
size_type | removeMgmtEventCallback (const int dev_id) noexcept |
Returns count of removed MgmtEventCallback from the named MgmtEvent::Opcode list matching the given adapter dev_id . More... | |
size_type | removeMgmtEventCallback (const MgmtEvent::Opcode opc, const MgmtEventCallback &cb) noexcept |
Returns count of removed given MgmtEventCallback from the named MgmtEvent::Opcode list. More... | |
void | sendMgmtEvent (const MgmtEvent &event) noexcept |
Manually send a MgmtEvent to all of its listeners. More... | |
HCIStatusCode | setDefaultConnParam (const uint16_t dev_id, const uint16_t conn_interval_min=8, const uint16_t conn_interval_max=40, const uint16_t conn_latency=0, const uint16_t supervision_timeout=getHCIConnSupervisorTimeout(0, 50)) noexcept |
Set default connection parameter for given adapter to the kernel. More... | |
MgmtStatus | setDiscoverable (const uint16_t dev_id, const uint8_t state, const uint16_t timeout, AdapterSetting ¤t_settings) noexcept |
bool | setIOCapability (const uint16_t dev_id, const SMPIOCapability io_cap, SMPIOCapability &pre_io_cap) noexcept |
std::shared_ptr< NameAndShortName > | setLocalName (const uint16_t dev_id, const std::string &name, const std::string &short_name) noexcept |
bool | setMode (const uint16_t dev_id, const MgmtCommand::Opcode opc, const uint8_t mode, AdapterSetting ¤t_settings) noexcept |
std::string | toString () const noexcept override |
HCIStatusCode | unpairDevice (const uint16_t dev_id, const BDAddressAndType &addressAndType, const bool disconnect) noexcept |
HCIStatusCode | uploadConnParam (const uint16_t dev_id, const BDAddressAndType &addressAndType, const uint16_t conn_interval_min=12, const uint16_t conn_interval_max=12, const uint16_t conn_latency=0, const uint16_t supervision_timeout=getHCIConnSupervisorTimeout(0, 15)) noexcept |
Uploads given connection parameter for given device to the kernel. More... | |
HCIStatusCode | uploadLinkKey (const uint16_t dev_id, const BDAddressAndType &addressAndType, const SMPLinkKey &lk) noexcept |
HCIStatusCode | uploadLinkKey (const uint16_t dev_id, const MgmtLinkKeyInfo &key) noexcept |
HCIStatusCode | uploadLongTermKey (const BTRole adapterRole, const uint16_t dev_id, const BDAddressAndType &addressAndType, const jau::darray< SMPLongTermKey > <ks) noexcept |
HCIStatusCode | uploadLongTermKey (const uint16_t dev_id, const jau::darray< MgmtLongTermKeyInfo > &keys) noexcept |
MgmtStatus | userConfirmReply (const uint16_t dev_id, const BDAddressAndType &addressAndType, const bool positive) noexcept |
MgmtStatus | userPasskeyNegativeReply (const uint16_t dev_id, const BDAddressAndType &addressAndType) noexcept |
MgmtStatus | userPasskeyReply (const uint16_t dev_id, const BDAddressAndType &addressAndType, const uint32_t passkey) noexcept |
![]() | |
JavaUplink () noexcept=default | |
JavaUplink (const JavaUplink &o) noexcept=default | |
JavaUplink (JavaUplink &&o) noexcept=default | |
virtual | ~JavaUplink () noexcept |
virtual void | checkValidInstance () const |
Throws an IllegalStateException if instance is not valid. More... | |
const JavaAnonRef & | getJavaObject () noexcept |
std::string | javaObjectToString () const noexcept |
JavaUplink & | operator= (const JavaUplink &o) noexcept=default |
JavaUplink & | operator= (JavaUplink &&o) noexcept=default |
void | setJavaObject () noexcept |
Resets the shared JavaAnon reference, the replaced item might be deleted via JNI from dtor. More... | |
void | setJavaObject (const JavaAnonRef &objRef) noexcept |
Assigns a new shared JavaAnon reference, replaced item might be deleted via JNI from dtor. More... | |
Static Public Member Functions | |
static const std::shared_ptr< BTManager > & | get () noexcept |
Retrieves the singleton instance. More... | |
static std::string | java_class () noexcept |
A thread safe singleton handler of the BTAdapter manager, e.g.
Linux Kernel's BlueZ manager control channel.
Implementation utilizes a lock free ringbuffer receiving data within its separate thread.
Controlling Environment variables, see MgmtEnv.
Definition at line 204 of file BTManager.hpp.
Definition at line 211 of file BTManager.hpp.
enum direct_bt::BTManager::Defaults : int32_t |
Enumerator | |
---|---|
ClientMaxMTU |
Definition at line 206 of file BTManager.hpp.
|
delete |
|
overridenoexcept |
Definition at line 512 of file BTManager.cpp.
|
delete |
|
inlinestaticnoexcept |
Retrieves the singleton instance.
First call will open and initialize the bluetooth kernel.
Definition at line 337 of file BTManager.hpp.
|
noexcept |
|
inlineoverridevirtualnoexcept |
Implements jau::jni::JavaUplink.
Definition at line 356 of file BTManager.hpp.
|
inlinestaticnoexcept |
|
inlinenoexcept |
Returns true if this mgmt instance is open and hence valid, otherwise false.
Definition at line 364 of file BTManager.hpp.
|
inlineoverridevirtualnoexcept |
Reimplemented from jau::jni::JavaUplink.
Definition at line 368 of file BTManager.hpp.
|
inlinenoexcept |
retrieve information gathered at startup
Returns AdapterInfo count in list
Definition at line 377 of file BTManager.hpp.
|
inline |
Returns a list of currently added DBTAdapter.
Definition at line 382 of file BTManager.hpp.
|
noexcept |
Returns the DBTAdapter with the given dev_id, or nullptr if not found.
Definition at line 569 of file BTManager.cpp.
|
noexcept |
Returns the default AdapterInfo.
The default adapter is either the first AdapterSetting::POWERED adapter, or function returns nullptr if none is AdapterSetting::POWERED.
Definition at line 559 of file BTManager.cpp.
|
noexcept |
Definition at line 636 of file BTManager.cpp.
|
noexcept |
Definition at line 659 of file BTManager.cpp.
|
noexcept |
Definition at line 669 of file BTManager.cpp.
|
noexcept |
Definition at line 696 of file BTManager.cpp.
|
noexcept |
Initialize the adapter with default values, including power-on.
Method shall be issued on the desired adapter found via ChangedAdapterSetFunc.
While initialization, the adapter is first powered-off, setup and then powered-on.
adapterInfo | reference for the AdapterInfo, updated to reflect the new initialized values. |
dev_id | the adapter's device id |
btRole | the desired adapter's BTRole (currently ignored) |
btMode | the desired adapter's BTMode |
Definition at line 225 of file BTManager.cpp.
|
noexcept |
Read default connection parameter for given adapter to the kernel.
dev_id |
Definition at line 721 of file BTManager.cpp.
|
noexcept |
Set default connection parameter for given adapter to the kernel.
dev_id | |
conn_interval_min | in units of 1.25ms, default value 8 for 10ms; Value range [6 .. 3200] for [7.5ms .. 4000ms]. |
conn_interval_max | in units of 1.25ms, default value 40 for 50ms; Value range [6 .. 3200] for [7.5ms .. 4000ms] |
conn_latency | slave latency in units of connection events, default value 0; Value range [0 .. 0x01F3]. |
supervision_timeout | in units of 10ms, default value 500ms >= 10 x conn_interval_max, we use HCIConstInt::LE_CONN_MIN_TIMEOUT_MS minimum; Value range [0xA-0x0C80] for [100ms - 32s]. |
Definition at line 735 of file BTManager.cpp.
|
noexcept |
Uploads given connection parameter for given device to the kernel.
dev_id | |
address | |
address_type | |
conn_interval_min | in units of 1.25ms, default value 12 for 15ms; Value range [6 .. 3200] for [7.5ms .. 4000ms] |
conn_interval_max | in units of 1.25ms, default value 12 for 15ms; Value range [6 .. 3200] for [7.5ms .. 4000ms] |
conn_latency | slave latency in units of connection events, default value 0; Value range [0 .. 0x01F3]. |
supervision_timeout | in units of 10ms, default value >= 10 x conn_interval_max, we use HCIConstInt::LE_CONN_MIN_TIMEOUT_MS minimum; Value range [0xA-0x0C80] for [100ms - 32s]. |
Definition at line 756 of file BTManager.cpp.
|
noexcept |
Returns true, if the adapter's device is already whitelisted.
Definition at line 946 of file BTManager.cpp.
|
noexcept |
Add the given device to the adapter's autoconnect whitelist.
Make sure uploadConnParam(..) is invoked first, otherwise performance will lack.
Method will reject duplicate devices, in which case it should be removed first.
Definition at line 957 of file BTManager.cpp.
|
noexcept |
Remove the given device from the adapter's autoconnect whitelist.
Definition at line 1003 of file BTManager.cpp.
|
noexcept |
Remove all previously added devices from the autoconnect whitelist.
Returns number of removed devices.
Definition at line 976 of file BTManager.cpp.
|
noexcept |
Definition at line 1029 of file BTManager.cpp.
|
noexcept |
Definition at line 1042 of file BTManager.cpp.
|
noexcept |
Security commands.
Linux Kernel load_long_term_keys(..)
(mgmt.c) require either BDAddressType::BDADDR_LE_PUBLIC
or BDAddressType::BDADDR_LE_RANDOM and BLERandomAddressType::STATIC_PUBLIC in ltk_is_valid(..) (mgmt.c).
The Linux kernel will reject unresolvable random addresses and resolvable random addresses.
Definition at line 774 of file BTManager.cpp.
|
noexcept |
Definition at line 792 of file BTManager.cpp.
|
noexcept |
Definition at line 822 of file BTManager.cpp.
|
noexcept |
Definition at line 840 of file BTManager.cpp.
|
noexcept |
Definition at line 869 of file BTManager.cpp.
|
noexcept |
Definition at line 879 of file BTManager.cpp.
|
noexcept |
Definition at line 894 of file BTManager.cpp.
|
noexcept |
Definition at line 909 of file BTManager.cpp.
|
noexcept |
Definition at line 930 of file BTManager.cpp.
|
noexcept |
MgmtEventCallback handling
Appends the given MgmtEventCallback for the given adapter dev_id to the named MgmtEvent::Opcode list, if it is not present already (dev_id + opcode + callback).
The adapter dev_id allows filtering the events only directed to the given adapter. Use dev_id -1
to receive the event for all adapter.
dev_id | the associated adapter dev_id |
opc | opcode index for callback list, the callback shall be added to |
cb | the to be added callback |
Definition at line 1074 of file BTManager.cpp.
|
noexcept |
Returns count of removed given MgmtEventCallback from the named MgmtEvent::Opcode list.
Definition at line 1083 of file BTManager.cpp.
|
noexcept |
Returns count of removed MgmtEventCallback from the named MgmtEvent::Opcode list matching the given adapter dev_id .
Definition at line 1092 of file BTManager.cpp.
|
noexcept |
Removes all MgmtEventCallbacks from the to the named MgmtEvent::Opcode list.
Definition at line 1104 of file BTManager.cpp.
|
noexcept |
Removes all MgmtEventCallbacks from all MgmtEvent::Opcode lists.
Definition at line 1111 of file BTManager.cpp.
|
noexcept |
Manually send a MgmtEvent to all of its listeners.
Definition at line 139 of file BTManager.cpp.
void BTManager::addChangedAdapterSetCallback | ( | const ChangedAdapterSetCallback & | l | ) |
ChangedAdapterSetCallback handling.
Adds the given ChangedAdapterSetCallback to this manager.
When a new callback is added, all available adapter's will be reported as added, this allows a fully event driven workflow.
The callback is performed on a dedicated thread, allowing the user to perform complex operations.
Definition at line 1184 of file BTManager.cpp.
BTManager::size_type BTManager::removeChangedAdapterSetCallback | ( | const ChangedAdapterSetCallback & | l | ) |
Remove the given ChangedAdapterSetCallback from this manager.
l | the to be removed element |
Definition at line 1192 of file BTManager.cpp.
void BTManager::addChangedAdapterSetCallback | ( | ChangedAdapterSetFunc | f | ) |
Adds the given ChangedAdapterSetFunc to this manager.
When a new callback is added, all available adapter's will be reported as added, this allows a fully event driven workflow.
The callback is performed on a dedicated thread, allowing the user to perform complex operations.
Definition at line 1196 of file BTManager.cpp.
BTManager::size_type BTManager::removeChangedAdapterSetCallback | ( | ChangedAdapterSetFunc | f | ) |
Remove the given ChangedAdapterSetFunc from this manager.
l | the to be removed element |
Definition at line 1200 of file BTManager.cpp.
|
noexcept |
Remove all added ChangedAdapterSetCallback entries from this manager.
Definition at line 1205 of file BTManager.cpp.