summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-08-23 09:42:32 +0200
committerSven Gothel <[email protected]>2020-08-23 09:42:32 +0200
commit5cb8c348f36359ea8e81fc6789337a582bbd516b (patch)
treec77fc7341399a023a560bf7980e36c0875769b33 /src
parent0cf343f7db6276b257a4664ad2f0048bb690c989 (diff)
HCIHandler: Add le_set_scan_param(..) and le_enable_scan(..)
This replaces Linux Mgmt's discover start/stop with native HCI commands. Besides avoiding side-effects, we can utilize le_set_scan_param(..) similar to le_create_conn(..) for fine grained scanning performance.
Diffstat (limited to 'src')
-rw-r--r--src/direct_bt/HCIHandler.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/direct_bt/HCIHandler.cpp b/src/direct_bt/HCIHandler.cpp
index 6ade9e67..5a5443e2 100644
--- a/src/direct_bt/HCIHandler.cpp
+++ b/src/direct_bt/HCIHandler.cpp
@@ -538,6 +538,46 @@ HCIStatusCode HCIHandler::reset() {
return ev_cc->getReturnStatus(0);
}
+HCIStatusCode HCIHandler::le_set_scan_param(const bool le_scan_active,
+ const HCILEOwnAddressType own_mac_type,
+ const uint16_t le_scan_interval, const uint16_t le_scan_window,
+ const uint8_t filter_policy) {
+ const std::lock_guard<std::recursive_mutex> lock(mtx); // RAII-style acquire and relinquish via destructor
+ if( !comm.isOpen() ) {
+ ERR_PRINT("HCIHandler::le_set_scan_param: device not open");
+ return HCIStatusCode::INTERNAL_FAILURE;
+ }
+ HCIStructCommand<hci_cp_le_set_scan_param> req0(HCIOpcode::LE_SET_SCAN_PARAM);
+ hci_cp_le_set_scan_param * cp = req0.getWStruct();
+ cp->type = le_scan_active ? LE_SCAN_ACTIVE : LE_SCAN_PASSIVE;
+ cp->interval = cpu_to_le(le_scan_interval);
+ cp->window = cpu_to_le(le_scan_window);
+ cp->own_address_type = static_cast<uint8_t>(own_mac_type);
+ cp->filter_policy = filter_policy;
+
+ const hci_rp_status * ev_status;
+ HCIStatusCode status;
+ std::shared_ptr<HCIEvent> ev = processCommandComplete(req0, &ev_status, &status);
+ return status;
+}
+
+HCIStatusCode HCIHandler::le_enable_scan(const bool enable, const bool filter_dup) {
+ const std::lock_guard<std::recursive_mutex> lock(mtx); // RAII-style acquire and relinquish via destructor
+ if( !comm.isOpen() ) {
+ ERR_PRINT("HCIHandler::le_enable_scan: device not open");
+ return HCIStatusCode::INTERNAL_FAILURE;
+ }
+ HCIStructCommand<hci_cp_le_set_scan_enable> req0(HCIOpcode::LE_SET_SCAN_ENABLE);
+ hci_cp_le_set_scan_enable * cp = req0.getWStruct();
+ cp->enable = enable ? LE_SCAN_ENABLE : LE_SCAN_DISABLE;
+ cp->filter_dup = filter_dup ? LE_SCAN_FILTER_DUP_ENABLE : LE_SCAN_FILTER_DUP_DISABLE;
+
+ const hci_rp_status * ev_status;
+ HCIStatusCode status;
+ std::shared_ptr<HCIEvent> ev = processCommandComplete(req0, &ev_status, &status);
+ return status;
+}
+
HCIStatusCode HCIHandler::le_create_conn(const EUI48 &peer_bdaddr,
const HCILEPeerAddressType peer_mac_type,
const HCILEOwnAddressType own_mac_type,