From 4030f19f4e3bea44f5df7cbbc0e526e719391bea Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Wed, 2 Jan 2019 15:20:20 -0800 Subject: binding: bluetooth: add Transport parameter to discovery filter Allow clients to select what Bluetooth transport they want a discovery scan to attempt to detect. This will improve scanning in for example when a client only wants to detect bredr or ble devices . Bug-AGL: SPEC-2094 Change-Id: I2a983f5243aefcb582a7476bbae34d6ba88c39a6 Signed-off-by: Matt Ranostay --- README.md | 10 ++++++++-- binding/bluetooth-api.c | 37 +++++++++++++++++++++++++------------ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 162e550..6cd4b50 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ This verb allows an client to get initial paired devices, and discovered unpaire ### adapter_state verb -adapter_state verb allows setting and retrieving of requested adapter settings: +#### adapter_state verb allows setting and retrieving of requested adapter settings | Name | Description | |-----------------|------------------------------------------------------------------------| @@ -137,7 +137,13 @@ adapter_state verb allows setting and retrieving of requested adapter settings: | discovery | Discover nearby broadcasting devices | | discoverable | Allow other devices to detect this device | | powered | Adapter power state (optional, rfkill should be disabled already) | -| filter | Display devices only with respective UUIDS listed (write only setting) | + +#### adapter_state verb write-only parameters + +| Name | Description | +|-----------------|--------------------------------------------------------------------------| +| filter | Scan for devices only with respective UUIDS listed | +| transport | Scan for devices with only defined transport type (e.g. auto, bredr, le) | #### avrcp_controls verb diff --git a/binding/bluetooth-api.c b/binding/bluetooth-api.c index 8388695..3f66033 100644 --- a/binding/bluetooth-api.c +++ b/binding/bluetooth-api.c @@ -777,7 +777,7 @@ static void bluetooth_adapter(afb_req_t request) struct bluetooth_state *ns = bluetooth_get_userdata(request); GError *error = NULL; const char *adapter = afb_req_value(request, "adapter"); - const char *scan, *discoverable, *powered, *filter; + const char *scan, *discoverable, *powered, *filter, *transport; adapter = BLUEZ_ROOT_PATH(adapter ? adapter : ns->default_adapter); @@ -837,28 +837,41 @@ static void bluetooth_adapter(afb_req_t request) } filter = afb_req_value(request, "filter"); - if (filter) { - json_object *jobj = json_tokener_parse(filter); + transport = afb_req_value(request, "transport"); + + if (filter || transport) { GVariantBuilder builder; GVariant *flt, *reply; - gchar **uuid = NULL; - if (json_object_get_type(jobj) != json_type_array) { - afb_req_fail_f(request, "failed", "invalid discovery filter"); - return; + g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}")); + + if (filter) { + json_object *jobj = json_tokener_parse(filter); + gchar **uuid = NULL; + + if (json_object_get_type(jobj) != json_type_array) { + afb_req_fail_f(request, "failed", "invalid discovery filter"); + return; + } + + uuid = json_array_to_strv(jobj); + g_variant_builder_add(&builder, "{sv}", "UUIDs", + g_variant_new_strv((const gchar * const *) uuid, -1)); + + g_strfreev(uuid); } - g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}")); + if (transport) { + g_variant_builder_add(&builder, "{sv}", "Transport", + g_variant_new_string(transport)); + + } - uuid = json_array_to_strv(jobj); - g_variant_builder_add(&builder, "{sv}", "UUIDs", - g_variant_new_strv((const gchar * const *) uuid, -1)); flt = g_variant_builder_end(&builder); reply = adapter_call(ns, adapter, "SetDiscoveryFilter", g_variant_new("(@a{sv})", flt), &error); - g_strfreev(uuid); if (!reply) { afb_req_fail_f(request, "failed", -- cgit 1.2.3-korg