diff options
author | Sven Gothel <[email protected]> | 2020-07-02 07:46:19 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-07-02 07:46:19 +0200 |
commit | 613fbbef65c4d9593c97fb84d3b6a0e27037f9bf (patch) | |
tree | 4d9088252ea626e516e9344ec0ac05fe4d8f3b9c | |
parent | c92aec05cbea8703a23bc5827680dd6e7a787e55 (diff) |
Support BDADDR_LE_RANDOM (p1.2): Map BLERandomAddressType::STATIC_PUBLIC -> RANDOM; L2CAPComm uses device->getAddressType()
Map BLERandomAddressType::STATIC_PUBLIC -> HCILEPeerAddressType::RANDOM
This only works for a static random address not changing at all,
i.e. between power-cycles - hence a temporary hack.
We need to use 'resolving list' and/or LE Set Privacy Mode (HCI) for all devices.
+++
L2CAPComm uses device->getAddressType(), i.e. no need for a (wrong) public argument flag.
-rw-r--r-- | api/direct_bt/L2CAPComm.hpp | 3 | ||||
-rw-r--r-- | src/direct_bt/DBTDevice.cpp | 17 | ||||
-rw-r--r-- | src/direct_bt/L2CAPComm.cpp | 6 |
3 files changed, 15 insertions, 11 deletions
diff --git a/api/direct_bt/L2CAPComm.hpp b/api/direct_bt/L2CAPComm.hpp index 0f2e484f..5af7b4c8 100644 --- a/api/direct_bt/L2CAPComm.hpp +++ b/api/direct_bt/L2CAPComm.hpp @@ -68,7 +68,6 @@ namespace direct_bt { const std::string deviceString; const uint16_t psm; const uint16_t cid; - const bool pubaddr; std::atomic<int> _dd; // the l2cap socket std::atomic<bool> isConnected; // reflects state std::atomic<bool> hasIOError; // reflects state @@ -76,7 +75,7 @@ namespace direct_bt { std::atomic<pthread_t> tid_connect; public: - L2CAPComm(std::shared_ptr<DBTDevice> device, const uint16_t psm, const uint16_t cid, const bool pubaddr=true); + L2CAPComm(std::shared_ptr<DBTDevice> device, const uint16_t psm, const uint16_t cid); std::shared_ptr<DBTDevice> getDevice() { return device; } diff --git a/src/direct_bt/DBTDevice.cpp b/src/direct_bt/DBTDevice.cpp index 3dc1ac91..7e5f723d 100644 --- a/src/direct_bt/DBTDevice.cpp +++ b/src/direct_bt/DBTDevice.cpp @@ -254,29 +254,34 @@ bool DBTDevice::connectLE(uint16_t le_scan_interval, uint16_t le_scan_window, { const std::lock_guard<std::recursive_mutex> lock_conn(mtx_connect); // RAII-style acquire and relinquish via destructor - const HCILEOwnAddressType hci_own_mac_type = HCILEOwnAddressType::PUBLIC; // FIXME: Support non public address-type for adapter? - + HCILEOwnAddressType hci_own_mac_type; HCILEPeerAddressType hci_peer_mac_type; switch( addressType ) { case BDAddressType::BDADDR_LE_PUBLIC: hci_peer_mac_type = HCILEPeerAddressType::PUBLIC; + hci_own_mac_type = HCILEOwnAddressType::PUBLIC; break; case BDAddressType::BDADDR_LE_RANDOM: { switch( leRandomAddressType ) { case BLERandomAddressType::UNRESOLVABLE_PRIVAT: - // hci_peer_mac_type = HCILEPeerAddressType::RANDOM; + hci_peer_mac_type = HCILEPeerAddressType::RANDOM; + hci_own_mac_type = HCILEOwnAddressType::RANDOM; ERR_PRINT("LE Random address type '%s' not supported yet: %s", getBLERandomAddressTypeString(leRandomAddressType).c_str(), toString().c_str()); return false; case BLERandomAddressType::RESOLVABLE_PRIVAT: - // hci_peer_mac_type = HCILEPeerAddressType::RANDOM; + hci_peer_mac_type = HCILEPeerAddressType::PUBLIC_IDENTITY; + hci_own_mac_type = HCILEOwnAddressType::RESOLVABLE_OR_PUBLIC; ERR_PRINT("LE Random address type '%s' not supported yet: %s", getBLERandomAddressTypeString(leRandomAddressType).c_str(), toString().c_str()); return false; case BLERandomAddressType::STATIC_PUBLIC: - // FIXME: Even though HCI_LE_SetPrivacy_mode is advised if supported by both. - hci_peer_mac_type = HCILEPeerAddressType::RANDOM_STATIC_IDENTITY; + // FIXME: This only works for a static random address not changing at all, + // i.e. between power-cycles - hence a temporary hack. + // We need to use 'resolving list' and/or LE Set Privacy Mode (HCI) for all devices. + hci_peer_mac_type = HCILEPeerAddressType::RANDOM; + hci_own_mac_type = HCILEOwnAddressType::PUBLIC; break; default: { ERR_PRINT("Can't connectLE to LE Random address type '%s': %s", diff --git a/src/direct_bt/L2CAPComm.cpp b/src/direct_bt/L2CAPComm.cpp index d974d35a..b7054f67 100644 --- a/src/direct_bt/L2CAPComm.cpp +++ b/src/direct_bt/L2CAPComm.cpp @@ -97,8 +97,8 @@ int L2CAPComm::l2cap_close_dev(int dd) // ************************************************* // ************************************************* -L2CAPComm::L2CAPComm(std::shared_ptr<DBTDevice> device, const uint16_t psm, const uint16_t cid, const bool pubaddr) -: device(device), deviceString(device->getAddressString()), psm(psm), cid(cid), pubaddr(pubaddr), +L2CAPComm::L2CAPComm(std::shared_ptr<DBTDevice> device, const uint16_t psm, const uint16_t cid) +: device(device), deviceString(device->getAddressString()), psm(psm), cid(cid), _dd(-1), isConnected(false), hasIOError(false), interruptFlag(false), tid_connect(0) { } @@ -132,7 +132,7 @@ bool L2CAPComm::connect() { req.l2_psm = cpu_to_le(psm); req.l2_bdaddr = device->getAddress(); req.l2_cid = cpu_to_le(cid); - req.l2_bdaddr_type = pubaddr ? BDADDR_LE_PUBLIC : BDADDR_LE_RANDOM; + req.l2_bdaddr_type = device->getAddressType(); while( !interruptFlag ) { // blocking |