aboutsummaryrefslogtreecommitdiffstats
path: root/components/net/bluetooth_thread.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/net/bluetooth_thread.rs')
-rw-r--r--components/net/bluetooth_thread.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/components/net/bluetooth_thread.rs b/components/net/bluetooth_thread.rs
index e81ed2be8b6..efdeb02d7b2 100644
--- a/components/net/bluetooth_thread.rs
+++ b/components/net/bluetooth_thread.rs
@@ -84,17 +84,20 @@ impl BluetoothThreadFactory for IpcSender<BluetoothMethodMsg> {
}
}
+// https://webbluetoothcg.github.io/web-bluetooth/#matches-a-filter
fn matches_filter(device: &BluetoothDevice, filter: &BluetoothScanfilter) -> bool {
if filter.is_empty_or_invalid() {
return false;
}
+ // Step 1.
if !filter.get_name().is_empty() {
if device.get_name().ok() != Some(filter.get_name().to_string()) {
return false;
}
}
+ // Step 2.
if !filter.get_name_prefix().is_empty() {
if let Ok(device_name) = device.get_name() {
if !device_name.starts_with(filter.get_name_prefix()) {
@@ -105,6 +108,7 @@ fn matches_filter(device: &BluetoothDevice, filter: &BluetoothScanfilter) -> boo
}
}
+ // Step 3.
if !filter.get_services().is_empty() {
if let Ok(device_uuids) = device.get_uuids() {
for service in filter.get_services() {
@@ -115,6 +119,23 @@ fn matches_filter(device: &BluetoothDevice, filter: &BluetoothScanfilter) -> boo
}
}
+// Step 4.
+// TODO: Implement get_manufacturer_data in device crate.
+// if let Some(manufacturer_id) = filter.get_manufacturer_id() {
+// if !device.get_manufacturer_data().contains_key(manufacturer_id) {
+// return false;
+// }
+// }
+//
+// Step 5.
+// TODO: Implement get_device_data in device crate.
+// if !filter.get_service_data_uuid().is_empty() {
+// if !device.get_service_data().contains_key(filter.get_service_data_uuid()) {
+// return false;
+// }
+// }
+
+ // Step 6.
true
}
@@ -428,6 +449,7 @@ impl BluetoothManager {
// Methods
+ // https://webbluetoothcg.github.io/web-bluetooth/#request-bluetooth-devices
fn request_device(&mut self,
options: RequestDeviceoptions,
sender: IpcSender<BluetoothResult<BluetoothDeviceMsg>>) {
@@ -439,13 +461,18 @@ impl BluetoothManager {
let _ = session.stop_discovery();
}
+ // Step 6.
+ // Note: There is no requiredServiceUUIDS, we scan for all devices.
let mut matched_devices = self.get_and_cache_devices(&mut adapter);
+
+ // Step 7.
if !options.is_accepting_all_devices() {
matched_devices = matched_devices.into_iter()
.filter(|d| matches_filters(d, options.get_filters()))
.collect();
}
+ // Step 8.
if let Some(address) = self.select_device(matched_devices) {
let device_id = match self.address_to_id.get(&address) {
Some(id) => id.clone(),