summaryrefslogtreecommitdiffstats
path: root/binding/bluetooth-api.c
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2018-10-30 11:39:25 -0700
committerMatt Ranostay <matt.ranostay@konsulko.com>2018-11-23 08:49:14 -0800
commitc19902405ebe92a17efe041cae9a3584c3b182e5 (patch)
treef0135d733f77a938bac29a64a24d9e2f3afed421 /binding/bluetooth-api.c
parent9796db317ac252bd99584471421fb757a19d23d3 (diff)
binding: bluetooth: add initial discovery filter support
Allow clients to request devices only with certain profile UUIDs to be displayed in an discovery scan. This allows to filter out things like location tokens, smart scales, and etc which can't possibly have a2dp or hfp profiles for instance. NOTE: This is a write only setting. In the future should be read/write to see current discovery filters. Bug-AGL: SPEC-1630 Change-Id: Ic8b18656f84ac8047b170d6e601fcc2e63786af0 Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'binding/bluetooth-api.c')
-rw-r--r--binding/bluetooth-api.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/binding/bluetooth-api.c b/binding/bluetooth-api.c
index 58c326c..5c123e3 100644
--- a/binding/bluetooth-api.c
+++ b/binding/bluetooth-api.c
@@ -618,7 +618,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;
+ const char *scan, *discoverable, *powered, *filter;
adapter = BLUEZ_ROOT_PATH(adapter ? adapter : BLUEZ_DEFAULT_ADAPTER);
@@ -665,6 +665,40 @@ static void bluetooth_adapter(afb_req_t request)
}
}
+ filter = afb_req_value(request, "filter");
+ if (filter) {
+ json_object *jobj = json_tokener_parse(filter);
+ 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}"));
+
+ 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",
+ "adapter %s SetDiscoveryFilter error %s",
+ adapter, BLUEZ_ERRMSG(error));
+ g_error_free(error);
+ return;
+ }
+ g_variant_unref(reply);
+ }
+
bluetooth_state(request);
}