From c89618370dce83aa561ef733179a0b62ad927e93 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 3 Jul 2017 14:06:06 +0300 Subject: [PATCH] client: Add release-notify command This adds release-notify command which closes an existing fd unlocking the attribute: [Test peripheral:/service001f/char0020]# release-notify [CHG] Attribute /org/bluez/hci1/dev_69_16_5B_9A_06_CD/service001f/char0020 NotifyAcquired: no --- client/gatt.c | 10 ++++++++++ client/gatt.h | 1 + client/main.c | 12 ++++++++++++ doc/gatt-api.txt | 21 ++++++++++++--------- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/client/gatt.c b/client/gatt.c index 053385437..33e8936ea 100644 --- a/client/gatt.c +++ b/client/gatt.c @@ -842,6 +842,16 @@ void gatt_acquire_notify(GDBusProxy *proxy, const char *arg) notify_proxy = proxy; } +void gatt_release_notify(GDBusProxy *proxy, const char *arg) +{ + if (proxy != notify_proxy || !notify_io) { + rl_printf("Write not acquired\n"); + return; + } + + notify_io_destroy(); +} + static void notify_reply(DBusMessage *message, void *user_data) { bool enable = GPOINTER_TO_UINT(user_data); diff --git a/client/gatt.h b/client/gatt.h index 5dba26b6e..9bab42902 100644 --- a/client/gatt.h +++ b/client/gatt.h @@ -42,6 +42,7 @@ void gatt_acquire_write(GDBusProxy *proxy, const char *arg); void gatt_release_write(GDBusProxy *proxy, const char *arg); void gatt_acquire_notify(GDBusProxy *proxy, const char *arg); +void gatt_release_notify(GDBusProxy *proxy, const char *arg); void gatt_add_manager(GDBusProxy *proxy); void gatt_remove_manager(GDBusProxy *proxy); diff --git a/client/main.c b/client/main.c index e0a265db4..8f75f0e32 100644 --- a/client/main.c +++ b/client/main.c @@ -1829,6 +1829,16 @@ static void cmd_acquire_notify(const char *arg) gatt_acquire_notify(default_attr, arg); } +static void cmd_release_notify(const char *arg) +{ + if (!default_attr) { + rl_printf("No attribute selected\n"); + return; + } + + gatt_release_notify(default_attr, arg); +} + static void cmd_notify(const char *arg) { dbus_bool_t enable; @@ -2310,6 +2320,8 @@ static const struct { "Release Write file descriptor" }, { "acquire-notify", NULL, cmd_acquire_notify, "Acquire Notify file descriptor" }, + { "release-notify", NULL, cmd_release_notify, + "Release Notify file descriptor" }, { "notify", "", cmd_notify, "Notify attribute value" }, { "register-application", "[UUID ...]", cmd_register_app, "Register profile to connect" }, diff --git a/doc/gatt-api.txt b/doc/gatt-api.txt index 3f4a3ca3f..c0ad1de25 100644 --- a/doc/gatt-api.txt +++ b/doc/gatt-api.txt @@ -93,8 +93,9 @@ Methods array{byte} ReadValue(dict options) fd, uint16 AcquireWrite() [experimental] (Client only) - Acquire write file descriptor and MTU and lock - write access to the characteristic. + Acquire file descriptor and MTU for writing. Usage of + WriteValue will be locked causing it to return + NotPermitted error. Only works with characteristic that has WriteAcquired property which relies on @@ -115,8 +116,9 @@ Methods array{byte} ReadValue(dict options) fd, uint16 AcquireNotify() [experimental] (Client only) - Acquire notify file descriptor and MTU and lock - notifications to the characteristic. + Acquire file descriptor and MTU for notify. Usage of + StartNotify will be locked causing it to return + NotPermitted error. Only works with characteristic that has NotifyAcquired which relies on notify Flag and no other client have @@ -125,7 +127,7 @@ Methods array{byte} ReadValue(dict options) Notification are enabled during this procedure so StartNotify shall not be called, any notification will be dispatched via file descriptor therefore the - Value property is no affected during the time where + Value property is not affected during the time where notify has been acquired. To release the lock the client shall close the file @@ -147,6 +149,7 @@ Methods array{byte} ReadValue(dict options) if it supports value notifications or indications. Possible Errors: org.bluez.Error.Failed + org.bluez.Error.NotPermitted org.bluez.Error.InProgress org.bluez.Error.NotSupported @@ -177,15 +180,15 @@ Properties string UUID [read-only] boolean WriteAcquired [read-only, optional] - True, if this characteristic has been acquire by any + True, if this characteristic has been acquired by any client using AcquireWrite. This properties is ommited - in case write-without-response flag is not set. + in case 'write-without-response' flag is not set. boolean NotifyAcquired [read-only, optional] - True, if this characteristic has been acquire by any + True, if this characteristic has been acquired by any client using AcquireNotify. This properties is ommited - in case notify flag is not set. + in case 'notify' flag is not set. boolean Notifying [read-only, optional] -- 2.47.3