aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/direct_bt/HCIHandler.hpp20
-rw-r--r--src/direct_bt/HCIHandler.cpp40
2 files changed, 60 insertions, 0 deletions
diff --git a/api/direct_bt/HCIHandler.hpp b/api/direct_bt/HCIHandler.hpp
index 1879accf..64c69f99 100644
--- a/api/direct_bt/HCIHandler.hpp
+++ b/api/direct_bt/HCIHandler.hpp
@@ -222,6 +222,26 @@ namespace direct_bt {
HCIStatusCode reset();
/**
+ * Sets LE scanning parameters.
+ * <p>
+ * BT Core Spec v5.2: Vol 4, Part E HCI: 7.8.10 LE Set Scan Parameters command
+ * </p>
+ * Should not be called while scanning is active.
+ */
+ HCIStatusCode le_set_scan_param(const bool le_scan_active=false,
+ const HCILEOwnAddressType own_mac_type=HCILEOwnAddressType::PUBLIC,
+ const uint16_t le_scan_interval=48, const uint16_t le_scan_window=48,
+ const uint8_t filter_policy=0x00);
+
+ /**
+ * Starts or stops LE scanning.
+ * <p>
+ * BT Core Spec v5.2: Vol 4, Part E HCI: 7.8.11 LE Set Scan Enable command
+ * </p>
+ */
+ HCIStatusCode le_enable_scan(const bool enable, const bool filter_dup=false);
+
+ /**
* Establish a connection to the given LE peer.
* <p>
* BT Core Spec v5.2: Vol 4, Part E HCI: 7.8.12 LE Create Connection command
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,