Fix bug in StartNotify()
cover Fix bug in StartNotify()
Hi,
if you call StartNotify() right after a device disappears, bluez returns an org.bluez.Error.InProgress, even though the device isn't there at all. A simple fix is checking the case of !gatt at the very beginning of function characteristic_start_notify, since we can return the correct error immediately. The patch returns an Error.NotConnected, which I think is the correct error in this case, but it can be problematic since this function never returned that before. Another possible error is Error.Failed with the message "Not connected" since that's already expected from the function. This patch also cancels out the cleaning of client at the bottom of the function, since we never create it in the first place when a device is not available.
cheers.
Ahmed (1):
Fix bug in characteristic_start_notify.
src/gatt-client.c | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/1 Fix bug in characteristic_start_notify.
From: Ahmed <[email protected]>
--- src/gatt-client.c | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-)
src/gatt-client.c +3 -29
@@ -1514,6 +1514,9 @@ static DBusMessage *characteristic_start_notify(DBusConnection *conn,struct async_dbus_op *op;struct notify_client *client; +if (!gatt) +return btd_error_not_connected (msg); +if (chrc->notify_io)return btd_error_not_permitted (msg,"Notify acquired" );
@@ -1535,26 +1538,6 @@ static DBusMessage *characteristic_start_notify(DBusConnection *conn,queue_push_tail (chrc->notify_clients, client);queue_push_tail (chrc->service->client->all_notify_clients, client); -/* -* If the device is currently not connected, return success. We will -* automatically try and register all clients when a GATT client becomes -* ready. -*/ -if (!gatt) { -DBusMessage *reply; - - reply =g_dbus_create_reply (msg,DBUS_TYPE_INVALID ); -if (reply) -return reply; - -/* -* Clean up and respond with an error instead of timing out to -* avoid any ambiguities. -*/ -error ("Failed to construct D-Bus message reply" ); - goto fail; - } - op =async_dbus_op_new (msg, client); client->notify_id = bt_gatt_client_register_notify(gatt,
@@ -1565,15 +1548,6 @@ static DBusMessage *characteristic_start_notify(DBusConnection *conn,return NULL ;async_dbus_op_free (op); - -fail: -queue_remove (chrc->notify_clients, client); -queue_remove (chrc->service->client->all_notify_clients, client); - -/* Directly free the client */ -notify_client_free (client); - -return btd_error_failed (msg,"Failed to register notify session" ); } static DBusMessage *characteristic_stop_notify(DBusConnection *conn,
Signature · 1 line
2.11.0
Re: [PATCH BlueZ 1/1] Fix bug in characteristic_start_notify.
In reply to a message not in the archiveHi Luiz,
Quoted 3 lines · Luiz Augusto von Dentz
Hi Ahmed,
Note that StartNotify is intended to work offline, so when it connects it will subscribe which seem this would prevent that to happen.
Thanks for the clarification, this does indeed prevent that from happening, sorry for the silly mistake on my side.
PATCH 1/1 Fix bug in characteristic_start_notify.
In reply to a message not in the archiveHi again,
Quoted 10 lines · Ahmed Alsharif
Hi Luiz,
Quoted 3 lines · Luiz Augusto von Dentz
Hi Ahmed,
Note that StartNotify is intended to work offline, so when it connects it will subscribe which seem this would prevent that to happen.Thanks for the clarification, this does indeed prevent that from happening, sorry for the silly mistake on my side.
I'm interested in hearing your thoughts on the following:
Isn't it a bit inconsistent, that when a device is connected, and a characteristic is already notifying, no error is returned when trying to subscribe to it again (bluez-5.43 and below used to actually return an "Already notifying" error), but when a device is not connected, an InProgress error is returned? This means that an InProgress error just tells us that a device is not connected, which only adds ambiguity I think.
Cheers:)