aboutsummaryrefslogtreecommitdiffstats
path: root/binding
diff options
context:
space:
mode:
Diffstat (limited to 'binding')
-rw-r--r--binding/bluetooth-api.c36
-rw-r--r--binding/bluetooth-bluez.c1
-rw-r--r--binding/bluetooth-common.h2
-rw-r--r--binding/bluetooth-util.c15
4 files changed, 53 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);
}
diff --git a/binding/bluetooth-bluez.c b/binding/bluetooth-bluez.c
index 7640046..37c4469 100644
--- a/binding/bluetooth-bluez.c
+++ b/binding/bluetooth-bluez.c
@@ -147,6 +147,7 @@ void bluez_decode_call_error(struct bluetooth_state *ns,
} else if (!strcmp(method, "StartDiscovery") ||
!strcmp(method, "StopDiscovery") ||
+ !strcmp(method, "SetDiscoveryFilter") ||
!strcmp(method, "RegisterAgent")) {
g_clear_error(error);
diff --git a/binding/bluetooth-common.h b/binding/bluetooth-common.h
index bd64f83..e6fb97a 100644
--- a/binding/bluetooth-common.h
+++ b/binding/bluetooth-common.h
@@ -114,6 +114,8 @@ void json_process_path(json_object *jresp, const char *path);
gchar *return_bluez_path(afb_req_t request);
+gchar **json_array_to_strv(json_object *jobj);
+
/**
* Structure for converting from dbus properties to json
* and vice-versa.
diff --git a/binding/bluetooth-util.c b/binding/bluetooth-util.c
index f57b43e..21aae6c 100644
--- a/binding/bluetooth-util.c
+++ b/binding/bluetooth-util.c
@@ -1051,3 +1051,18 @@ gchar *return_bluez_path(afb_req_t request) {
return g_strconcat("/org/bluez/", adapter, "/", device, NULL);
}
+
+gchar **json_array_to_strv(json_object *jobj)
+{
+ int len = json_object_array_length(jobj);
+ gchar **val = g_malloc0(sizeof(gchar *) * (len + 1));
+ int i;
+
+ for (i = 0; i < len; i++) {
+ json_object *jstr = json_object_array_get_idx(jobj, i);
+ const char *str = json_object_get_string(jstr);
+ val[i] = g_strdup(str);
+ }
+
+ return val;
+}