Skip to content

Commit

Permalink
linux: Filter ble/matter only (#9583)
Browse files Browse the repository at this point in the history
* linux: Restrict search to BLE only

For BlueZ, set "Transport" discovery filter to "le" avoiding
interleaved discovery. There is no need to inquiry for traditional
Bluetooth devices.

* linux: Restrict search to chip UUID

For BlueZ, set discovery "UUIDs" filter to chip UUID to avoid
reporting BLE devices that doesn't support chip/matter.
  • Loading branch information
cktakahasi authored and pull[bot] committed Oct 4, 2021
1 parent 887c06a commit 635bab3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/platform/Linux/bluez/ChipDeviceScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,29 @@ int ChipDeviceScanner::MainLoopStartScan(ChipDeviceScanner * self)
self->RemoveDevice(bluez_object_get_device1(&object));
}

/* Search for matter/chip UUID only */
GVariantBuilder uuidsBuilder;
GVariant * uuids;
g_variant_builder_init(&uuidsBuilder, G_VARIANT_TYPE("as"));
g_variant_builder_add(&uuidsBuilder, "s", CHIP_BLE_UUID_SERVICE_STRING);
uuids = g_variant_builder_end(&uuidsBuilder);

/* Search for LE only: Advertises */
GVariantBuilder filterBuilder;
GVariant * filter;

g_variant_builder_init(&filterBuilder, G_VARIANT_TYPE("a{sv}"));
g_variant_builder_add(&filterBuilder, "{sv}", "Transport", g_variant_new_string("le"));
g_variant_builder_add(&filterBuilder, "{sv}", "UUIDs", uuids);
filter = g_variant_builder_end(&filterBuilder);

if (!bluez_adapter1_call_set_discovery_filter_sync(self->mAdapter, filter, self->mCancellable, &error))
{
/* Not critical: ignore if fails */
ChipLogError(Ble, "Failed to set discovery filters: %s", error->message);
g_error_free(error);
}

ChipLogProgress(Ble, "BLE initiating scan.");
if (!bluez_adapter1_call_start_discovery_sync(self->mAdapter, self->mCancellable, &error))
{
Expand Down

0 comments on commit 635bab3

Please sign in to comment.