summaryrefslogtreecommitdiffstats
path: root/src/direct_bt/BTDevice.cpp
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-08-30 07:42:35 +0200
committerSven Gothel <[email protected]>2021-08-30 07:42:35 +0200
commit294233cc48107dfea342ee11cfa89814c32dd7bc (patch)
tree16354dd9e825a853367e0c6796d3255c330a0031 /src/direct_bt/BTDevice.cpp
parent0b9089769663fc237ef5d4258726258c70cb19bc (diff)
Add support for Bluetooth 5.0 Adapter (using HCI extended scanning and connecting if supported)
On Bluetooth 5.0 Adapter where HCI extended scanning and connecting is suppored, the original HCI commands may fail via DISALLOWED. Tested adapter: Intel AX200 Bluetooth 5.0 (Wi-Fi 6 802.11ax (2.4Gbps) + BT 5.0)
Diffstat (limited to 'src/direct_bt/BTDevice.cpp')
-rw-r--r--src/direct_bt/BTDevice.cpp46
1 files changed, 41 insertions, 5 deletions
diff --git a/src/direct_bt/BTDevice.cpp b/src/direct_bt/BTDevice.cpp
index 5f98d855..a8f7d005 100644
--- a/src/direct_bt/BTDevice.cpp
+++ b/src/direct_bt/BTDevice.cpp
@@ -53,7 +53,7 @@ BTDevice::BTDevice(const ctor_cookie& cc, BTAdapter & a, EInfoReport const & r)
(void)cc;
ts_last_discovery = ts_creation;
hciConnHandle = 0;
- le_features = LEFeatures::NONE;
+ le_features = LE_Features::NONE;
isConnected = false;
allowDisconnect = false;
clearSMPStates(false /* connected */);
@@ -561,9 +561,9 @@ void BTDevice::notifyConnected(std::shared_ptr<BTDevice> sthis, const uint16_t h
(void)sthis; // not used yet
}
-void BTDevice::notifyLEFeatures(std::shared_ptr<BTDevice> sthis, const LEFeatures features) noexcept {
- DBG_PRINT("BTDevice::notifyLEFeatures: LE_Encryption %d, %s",
- isLEFeaturesBitSet(features, LEFeatures::LE_Encryption), toString().c_str());
+void BTDevice::notifyLEFeatures(std::shared_ptr<BTDevice> sthis, const LE_Features features) noexcept {
+ DBG_PRINT("BTDevice::notifyLEFeatures: %s, %s",
+ direct_bt::to_string(features).c_str(), toString().c_str());
le_features = features;
if( addressAndType.isLEAddress() && !l2cap_att.isOpen() ) {
@@ -585,7 +585,7 @@ void BTDevice::processL2CAPSetup(std::shared_ptr<BTDevice> sthis) {
const SMPIOCapability io_cap_conn = pairing_data.ioCap_conn;
BTSecurityLevel sec_level { BTSecurityLevel::UNSET };
- const bool responderLikesEncryption = pairing_data.res_requested_sec || isLEFeaturesBitSet(le_features, LEFeatures::LE_Encryption);
+ const bool responderLikesEncryption = pairing_data.res_requested_sec || isLEFeaturesBitSet(le_features, LE_Features::LE_Encryption);
if( BTSecurityLevel::UNSET != sec_level_user ) {
sec_level = sec_level_user;
} else if( responderLikesEncryption && SMPIOCapability::UNSET != io_cap_conn ) {
@@ -1645,6 +1645,42 @@ int BTDevice::removeAllCharListener() noexcept {
return gatt->removeAllCharListener();
}
+HCIStatusCode BTDevice::getConnectedLE_PHY(LE_PHYs& resRx, LE_PHYs& resTx) noexcept {
+ const std::lock_guard<std::recursive_mutex> lock_conn(mtx_connect); // RAII-style acquire and relinquish via destructor
+
+ HCIStatusCode res = HCIStatusCode::SUCCESS;
+ HCIHandler &hci = adapter.getHCI();
+
+ if( !isConnected ) { // should not happen
+ res = HCIStatusCode::DISCONNECTED;
+ goto errout;
+ }
+
+ if( 0 == hciConnHandle ) {
+ res = HCIStatusCode::UNSPECIFIED_ERROR;
+ goto errout;
+ }
+
+ if( !adapter.isPowered() ) {
+ res = HCIStatusCode::NOT_POWERED; // powered-off
+ goto errout;
+ }
+
+ res = hci.le_read_phy(hciConnHandle.load(), addressAndType, resRx, resTx);
+ if( HCIStatusCode::SUCCESS == res ) {
+ DBG_PRINT("BTDevice::getConnectedLE_PHY: status %s: RX %s, TX %s - %s",
+ to_string(res).c_str(),
+ to_string(resRx).c_str(), to_string(resTx).c_str(), toString().c_str());
+ return res;
+ }
+
+errout:
+ ERR_PRINT("BTDevice::getConnectedLE_PHY: status %s: RX %s, TX %s - %s",
+ to_string(res).c_str(),
+ to_string(resRx).c_str(), to_string(resTx).c_str(), toString().c_str());
+ return res;
+}
+
void BTDevice::notifyDisconnected() noexcept {
// coming from disconnect callback, ensure cleaning up!
DBG_PRINT("BTDevice::notifyDisconnected: handle %s -> zero, %s",