aboutsummaryrefslogtreecommitdiffstats
path: root/src/direct_bt
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-11-15 07:05:44 +0100
committerSven Gothel <[email protected]>2020-11-15 07:05:44 +0100
commitb7e21bb00176089db76314af00aaf3494aaa2e5b (patch)
treeb2a733554d4fdaa06873a7f4cebe9c7c1b47ed5c /src/direct_bt
parentc68395a6af8fe20a998585f36bbea7699168717e (diff)
DBTManager: Add setL2CAPSecurity(..) and userConfirmReply(..) for MgmtUserConfirmReplyCmd/MgmtUserConfirmNegativeReplyCmd
Diffstat (limited to 'src/direct_bt')
-rw-r--r--src/direct_bt/DBTManager.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp
index 9fac89ff..ec794bca 100644
--- a/src/direct_bt/DBTManager.cpp
+++ b/src/direct_bt/DBTManager.cpp
@@ -732,6 +732,25 @@ MgmtStatus DBTManager::setDiscoverable(const uint16_t dev_id, const uint8_t stat
return res;
}
+bool DBTManager::setL2CAPSecurity(int l2cap_att_socket, uint8_t sec_level) {
+#if USE_LINUX_BT_SECURITY
+ struct bt_security bt_sec;
+ int result;
+
+ bzero(&bt_sec, sizeof(bt_sec));
+ bt_sec.level = sec_level;
+ result = setsockopt(l2cap_att_socket, SOL_BLUETOOTH, BT_SECURITY, &bt_sec, sizeof(bt_sec));
+ if (result != 0) {
+ ERR_PRINT("Setting L2CAP security level failed");
+ return false;
+ }
+ return true;
+#else
+ (void) l2cap_att_socket;
+ return false;
+#endif
+}
+
ScanType DBTManager::startDiscovery(const uint16_t dev_id, const BTMode btMode) noexcept {
return startDiscovery(dev_id, getScanType(btMode));
}
@@ -818,6 +837,23 @@ MgmtStatus DBTManager::userPasskeyNegativeReply(const uint16_t dev_id, const EUI
return MgmtStatus::TIMEOUT;
}
+MgmtStatus DBTManager::userConfirmReply(const uint16_t dev_id, const EUI48 &address, const BDAddressType addressType, const bool positive) noexcept {
+ std::shared_ptr<MgmtEvent> res;
+ if( positive ) {
+ MgmtUserConfirmReplyCmd cmd(dev_id, address, addressType);
+ res = sendWithReply(cmd);
+ } else {
+ MgmtUserConfirmNegativeReplyCmd cmd(dev_id, address, addressType);
+ res = sendWithReply(cmd);
+ }
+ if( nullptr != res && res->getOpcode() == MgmtEvent::Opcode::CMD_COMPLETE ) {
+ const MgmtEvtCmdComplete &res1 = *static_cast<const MgmtEvtCmdComplete *>(res.get());
+ // FIXME: Analyze address + addressType result?
+ return res1.getStatus();
+ }
+ return MgmtStatus::TIMEOUT;
+}
+
bool DBTManager::isDeviceWhitelisted(const uint16_t dev_id, const EUI48 &address) noexcept {
for(auto it = whitelist.begin(); it != whitelist.end(); ) {
std::shared_ptr<WhitelistElem> wle = *it;