Direct-BT
2.3.1
Direct-BT - Direct Bluetooth Programming.
|
Go to the documentation of this file.
26 #ifndef DBT_MANAGER_HPP_
27 #define DBT_MANAGER_HPP_
44 #include "BTIoctl.hpp"
72 static
BTMode getEnvBTMode();
120 const int32_t MGMT_READ_PACKET_MAX_RETRY;
213 #if USE_LINUX_BT_SECURITY
220 static std::mutex mtx_singleton;
222 struct WhitelistElem {
228 : dev_id(dev_id_), address_and_type(address_and_type_), ctype(ctype_) { }
233 const BTMode defaultBTMode;
241 std::mutex mtx_mgmtReaderLifecycle;
242 std::condition_variable cv_mgmtReaderInit;
243 pthread_t mgmtReaderThreadId;
246 std::recursive_mutex mtx_sendReply;
252 inline bool isValidMgmtEventCallbackListsIndex(
const MgmtEvent::Opcode opc)
const noexcept {
253 return static_cast<uint16_t
>(opc) < mgmtAdapterEventCallbackLists.size();
268 void mgmtReaderThreadImpl() noexcept;
274 std::unique_ptr<MgmtEvent> sendWithReply(MgmtCommand &req) noexcept;
276 bool send(MgmtCommand &req) noexcept;
282 BTManager(const
BTMode defaultBTMode) noexcept;
284 BTManager(const BTManager&) = delete;
285 void operator=(const BTManager&) = delete;
287 void setAdapterMode(const uint16_t dev_id, const uint8_t ssp, const uint8_t bredr, const uint8_t le) noexcept;
288 std::unique_ptr<AdapterInfo> initAdapter(const uint16_t dev_id, const
BTMode btMode) noexcept;
289 void shutdownAdapter(BTAdapter& adapter) noexcept;
291 void processAdapterAdded(std::unique_ptr<MgmtEvent> e) noexcept;
292 void processAdapterRemoved(std::unique_ptr<MgmtEvent> e) noexcept;
293 bool mgmtEvNewSettingsCB(const MgmtEvent& e) noexcept;
294 bool mgmtEventAnyCB(const MgmtEvent& e) noexcept;
296 std::shared_ptr<BTAdapter> addAdapter(const AdapterInfo& ai) noexcept;
302 std::shared_ptr<BTAdapter> removeAdapter(const uint16_t dev_id) noexcept;
309 bool removeAdapter(BTAdapter* adapter) noexcept;
336 void close() noexcept;
372 std::shared_ptr<BTAdapter>
getAdapter(
const uint16_t dev_id)
const noexcept;
409 const uint16_t conn_interval_min=12, const uint16_t conn_interval_max=12,
439 std::shared_ptr<
NameAndShortName>
setLocalName(const uint16_t dev_id, const std::
string & name, const std::
string & short_name) noexcept;
@ UNSET
Denoting unset value, i.e.
AdapterSetting
Adapter Setting Bits.
int getAdapterCount() const noexcept
retrieve information gathered at startup
ScanType startDiscovery(const uint16_t dev_id, const BTMode btMode) noexcept
Start discovery on given adapter dev_id with a ScanType matching the given BTMode.
const int32_t MGMT_COMMAND_REPLY_TIMEOUT
Timeout for mgmt command replies, defaults to 3s.
static MgmtEnv & get() noexcept
Base jau environment class, merely to tag all environment settings by inheritance and hence documenta...
MgmtStatus setDiscoverable(const uint16_t dev_id, const uint8_t state, const uint16_t timeout, AdapterSetting ¤t_settings) noexcept
bool disconnect(const bool ioErrorCause, const uint16_t dev_id, const BDAddressAndType &addressAndType, const HCIStatusCode reason=HCIStatusCode::REMOTE_USER_TERMINATED_CONNECTION) noexcept
HCIWhitelistConnectType
HCI Whitelist connection type.
int removeMgmtEventCallback(const MgmtEvent::Opcode opc, const MgmtEventCallback &cb) noexcept
Returns count of removed given MgmtEventCallback from the named MgmtEvent::Opcode list.
ScanType
Meta ScanType as derived from BTMode, with defined value mask consisting of BDAddressType bits.
std::string toString() const noexcept override
bool isOpen() const noexcept
mgmt_addr_info { EUI48, uint8_t type }, int8_t rssi, int8_t tx_power, int8_t max_tx_power;
PRAGMA_DISABLE_WARNING_POP constexpr_cxx20 std::string to_string(const endian &v) noexcept
Return std::string representation of the given jau::endian.
@ NO_INPUT_NO_OUTPUT
No input not output, value 3.
bool pairDevice(const uint16_t dev_id, const BDAddressAndType &addressAndType, const SMPIOCapability iocap) noexcept
uint16_t opcode, uint16_t dev-id, uint16_t param_size
int removeAllDevicesFromWhitelist() noexcept
Remove all previously added devices from the autoconnect whitelist.
HCIStatusCode
BT Core Spec v5.2: Vol 1, Part F Controller Error Codes: 1.3 List of Error Codes.
Implementation of a dynamic linear array storage, aka vector.
BTMode getDefaultBTMode() noexcept
Returns the default BTMode, adapters are tried to be initialized.
bool isDeviceWhitelisted(const uint16_t dev_id, const BDAddressAndType &addressAndType) noexcept
Returns true, if the adapter's device is already whitelisted.
Used for MgmtLoadLinkKeyCmd and MgmtEvtNewLinkKey.
const bool DEBUG_EVENT
Debug all Mgmt event communication.
jau::darray< std::shared_ptr< BTAdapter > > getAdapters()
Returns a list of currently added DBTAdapter.
bool addDeviceToWhitelist(const uint16_t dev_id, const BDAddressAndType &addressAndType, const HCIWhitelistConnectType ctype) noexcept
Add the given device to the adapter's autoconnect whitelist.
bool setIOCapability(const uint16_t dev_id, const SMPIOCapability io_cap, SMPIOCapability &pre_io_cap) noexcept
static std::string java_class() noexcept
bool removeDeviceFromWhitelist(const uint16_t dev_id, const BDAddressAndType &addressAndType) noexcept
Remove the given device from the adapter's autoconnect whitelist.
const int32_t MGMT_EVT_RING_CAPACITY
Small ringbuffer capacity for synchronized commands, defaults to 64 messages.
bool isOpen() const noexcept
Returns true if this mgmt instance is open and hence valid, otherwise false.
int removeChangedAdapterSetCallback(const ChangedAdapterSetCallback &l)
Remove the given ChangedAdapterSetCallback from this manager.
static BTManager & get(const BTMode defaultBTMode=BTMode::NONE)
Retrieves the singleton instance.
std::string javaObjectToString() const noexcept
Ring buffer implementation, a.k.a circular buffer, exposing lock-free get*(..) and put*(....
A thread safe singleton handler of the Linux Kernel's BlueZ manager control channel.
void clearAllCallbacks() noexcept
Removes all MgmtEventCallbacks from all MgmtEvent::Opcode lists.
Read/Write HCI communication channel.
constexpr int32_t getHCIConnSupervisorTimeout(const uint16_t conn_latency, const uint16_t conn_interval_max_ms, const uint16_t min_result_ms=number(HCIConstInt::LE_CONN_MIN_TIMEOUT_MS), const uint16_t multiplier=10) noexcept
Defining the supervising timeout for LE connections to be a multiple of the maximum connection interv...
SMPIOCapability getIOCapability(const uint16_t dev_id) const noexcept
std::string to_string(const BDAddressType type) noexcept
void addChangedAdapterSetCallback(const ChangedAdapterSetCallback &l)
ChangedAdapterSetCallback handling.
~BTAdapter() noexcept
Releases this instance.
void sendMgmtEvent(const MgmtEvent &event) noexcept
Manually send a MgmtEvent to all of its listeners.
void clearMgmtEventCallbacks(const MgmtEvent::Opcode opc) noexcept
Removes all MgmtEventCallbacks from the to the named MgmtEvent::Opcode list.
const bool DEBUG_GLOBAL
Global Debug flag, retrieved first to triggers DBTEnv initialization.
std::string get_java_class() const noexcept override
bool(* ChangedAdapterSetFunc)(bool added, std::shared_ptr< BTAdapter > &adapter)
Callback function to receive change events regarding the system's adapter set, e.g.
std::shared_ptr< ConnectionInfo > getConnectionInfo(const uint16_t dev_id, const BDAddressAndType &addressAndType) noexcept
HCIStatusCode uploadLongTermKey(const uint16_t dev_id, const MgmtLongTermKeyInfo &key) noexcept
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
static const pid_t pidSelf
bool setMode(const uint16_t dev_id, const MgmtCommand::Opcode opc, const uint8_t mode, AdapterSetting ¤t_settings) noexcept
Sharing the anonymous Java object (JavaAnon), i.e.
SMPIOCapability
Vol 3, Part H, 2.3.2 IO capabilities.
bool stopDiscovery(const uint16_t dev_id, const ScanType type) noexcept
Stop discovery on given adapter dev_id.
MgmtStatus uploadLinkKey(const uint16_t dev_id, const bool debug_keys, const MgmtLinkKeyInfo &key) noexcept
Security commands.
HCIStatusCode uploadLongTermKeyInfo(const uint16_t dev_id, const BDAddressAndType &addressAndType, const SMPLongTermKeyInfo <k) noexcept
bool 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.
std::shared_ptr< BTAdapter > getDefaultAdapter() const noexcept
Returns the default AdapterInfo.
const BTMode DEFAULT_BTMODE
Default BTMode when initializing new adapter.
MgmtStatus unpairDevice(const uint16_t dev_id, const BDAddressAndType &addressAndType, const bool disconnect) noexcept
const int32_t MGMT_READER_THREAD_POLL_TIMEOUT
Poll timeout for mgmt reader thread, defaults to 10s.
jau::cow_darray< ChangedAdapterSetCallback > ChangedAdapterSetCallbackList
bool addMgmtEventCallback(const int dev_id, const MgmtEvent::Opcode opc, const MgmtEventCallback &cb) noexcept
MgmtEventCallback handling
Persistent octet data, i.e.
Managment Singleton runtime environment properties.
std::shared_ptr< NameAndShortName > setLocalName(const uint16_t dev_id, const std::string &name, const std::string &short_name) noexcept
Unique Bluetooth EUI48 address and BDAddressType tuple.
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.
MgmtStatus userConfirmReply(const uint16_t dev_id, const BDAddressAndType &addressAndType, const bool positive) noexcept
MgmtStatus userPasskeyReply(const uint16_t dev_id, const BDAddressAndType &addressAndType, const uint32_t passkey) noexcept
jau::FunctionDef< bool, bool, std::shared_ptr< BTAdapter > & > ChangedAdapterSetCallback
Callback jau::FunctionDef to receive change events regarding the system's adapter set,...
Used for MgmtLoadLongTermKeyCmd and MgmtEvtNewLongTermKey.
BTMode
Bluetooth adapter operating mode.
MgmtStatus userPasskeyNegativeReply(const uint16_t dev_id, const BDAddressAndType &addressAndType) noexcept
SMP Long Term Key Info, used for platform agnostic persistence.