shared/gatt-client: Fix not freeing notify data
Luiz Augusto von Dentz
maintainerPATCH 1/3 shared/gatt-client: Fix not freeing notify data
From: Luiz Augusto von Dentz <[email protected]>
notify_data_write_ccc takes another reference in case it succeed so the original reference should be dropped to cause the data to be freed once notify_data_write_ccc completes.
--- src/shared/gatt-client.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
src/shared/gatt-client.c +1 -2
@@ -1596,8 +1596,7 @@ static void complete_unregister_notify(void *data) !notify_data->chrc->ccc_handle) goto done; -if (notify_data_write_ccc (notify_data, false, disable_ccc_callback)) -return ; +notify_data_write_ccc (notify_data, false, disable_ccc_callback); done:notify_data_unref (notify_data);
Signature · 1 line
2.4.3
Luiz Augusto von Dentz
maintainerPATCH 2/3 core/gatt: Fix not able to read/write on reconnections
From: Luiz Augusto von Dentz <[email protected]>
Upon reconnecting the attributes may already be available from cache which mean the client would be able to issue commands while discovery is not complete thus btd_gatt_client_ready was not called yet.
To fix now btd_gatt_client_ready is split into btd_gatt_client_connected which is called whenever connected leaving btd_gatt_client_ready to only deal with exporting services found during the discovery.
--- src/device.c | 2 ++ src/gatt-client.c | 24 +++++++++++++++++------- src/gatt-client.h | 1 + 3 files changed, 20 insertions(+), 7 deletions(-)
src/device.c +2 -0
@@ -4602,6 +4602,8 @@ static void gatt_client_init(struct btd_device *device) } device->gatt_cache_used = !gatt_db_isempty (device->db); + +btd_gatt_client_connected (device->client_dbus); }static void gatt_server_init (struct btd_device *device,struct gatt_db *db)
src/gatt-client.c +17 -7
@@ -1825,20 +1825,14 @@ fail:void btd_gatt_client_ready (struct btd_gatt_client *client) { -struct bt_gatt_client *gatt; -if (!client)return ; - gatt =btd_device_get_gatt_client (client->device); -if (!gatt) { +if (!client->gatt) {error ("GATT client not initialized" );return ; } -bt_gatt_client_unref (client->gatt); - client->gatt =bt_gatt_client_ref (gatt); - client->ready = true;DBG ("GATT client ready" );
@@ -1852,6 +1846,22 @@ void btd_gatt_client_ready(struct btd_gatt_client *client)queue_foreach (client->all_notify_clients, register_notify, client); } +void btd_gatt_client_connected (struct btd_gatt_client *client) +{ +struct bt_gatt_client *gatt; + + gatt =btd_device_get_gatt_client (client->device); +if (!gatt) { +error ("GATT client not initialized" ); +return ; + } + +DBG ("Device connected." ); + +bt_gatt_client_unref (client->gatt); + client->gatt =bt_gatt_client_ref (gatt); +} +void btd_gatt_client_service_added (struct btd_gatt_client *client,struct gatt_db_attribute *attrib) {
src/gatt-client.h +1 -0
@@ -23,6 +23,7 @@ struct btd_gatt_client *btd_gatt_client_new(struct btd_device *device);void btd_gatt_client_destroy (struct btd_gatt_client *client);void btd_gatt_client_ready (struct btd_gatt_client *client); +void btd_gatt_client_connected (struct btd_gatt_client *client);void btd_gatt_client_service_added (struct btd_gatt_client *client,struct gatt_db_attribute *attrib); void btd_gatt_client_service_removed(struct btd_gatt_client *client,
Signature · 1 line
2.4.3
Luiz Augusto von Dentz
maintainerPATCH 3/3 core/device: Only reload database if empty
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
There is no need to reload the database once it has been populated.
--- src/device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
src/device.c +2 -1
@@ -4717,7 +4717,8 @@ bool device_attach_att(struct btd_device *dev, GIOChannel *io) dst =device_get_address (dev);ba2str (dst, dstaddr); -load_gatt_db (dev, srcaddr, dstaddr); +if (gatt_db_isempty (dev->db)) +load_gatt_db (dev, srcaddr, dstaddr);gatt_client_init (dev);gatt_server_init (dev,btd_gatt_database_get_db (database));
Signature · 1 line
2.4.3
Re: [PATCH BlueZ 2/3] core/gatt: Fix not able to read/write on reconnections
In reply to Luiz Augusto von DentzHi Luiz,
This patch fixes all my issues with writing just after connecting. Thanks alot!
Quoted 96 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
Upon reconnecting the attributes may already be available from cache which mean the client would be able to issue commands while discovery is not complete thus
btd_gatt_client_readywas not called yet.To fix now
btd_gatt_client_readyis split intobtd_gatt_client_connectedwhich is called whenever connected leavingbtd_gatt_client_readyto only deal with exporting services found during the discovery.--- src/device.c | 2 ++ src/gatt-client.c | 24 +++++++++++++++++------- src/gatt-client.h | 1 + 3 files changed, 20 insertions(+), 7 deletions(-)src/device.c +2
-0@@ -4602,6 +4602,8 @@ static void gatt_client_init(struct btd_device *device) } device->gatt_cache_used = !gatt_db_isempty (device->db); + +btd_gatt_client_connected (device->client_dbus); }static void gatt_server_init (struct btd_device *device,struct gatt_db *db)src/gatt-client.c +17
-7@@ -1825,20 +1825,14 @@ fail:void btd_gatt_client_ready (struct btd_gatt_client *client) { -struct bt_gatt_client *gatt; -if (!client)return ; - gatt =btd_device_get_gatt_client (client->device); -if (!gatt) { +if (!client->gatt) {error ("GATT client not initialized" );return ; } -bt_gatt_client_unref (client->gatt); - client->gatt =bt_gatt_client_ref (gatt); - client->ready = true;DBG ("GATT client ready" );@@ -1852,6 +1846,22 @@ void btd_gatt_client_ready(struct btd_gatt_client *client)queue_foreach (client->all_notify_clients, register_notify, client); } +void btd_gatt_client_connected (struct btd_gatt_client *client) +{ +struct bt_gatt_client *gatt; + + gatt =btd_device_get_gatt_client (client->device); +if (!gatt) { +error ("GATT client not initialized" ); +return ; + } + +DBG ("Device connected." ); + +bt_gatt_client_unref (client->gatt); + client->gatt =bt_gatt_client_ref (gatt); +} +void btd_gatt_client_service_added (struct btd_gatt_client *client,struct gatt_db_attribute *attrib) {src/gatt-client.h +1
-1@@ -23,6 +23,7 @@ struct btd_gatt_client *btd_gatt_client_new(struct btd_device *device);void btd_gatt_client_destroy (struct btd_gatt_client *client);void btd_gatt_client_ready (struct btd_gatt_client *client); +void btd_gatt_client_connected (struct btd_gatt_client *client);void btd_gatt_client_service_added (struct btd_gatt_client *client,struct gatt_db_attribute *attrib); void btd_gatt_client_service_removed(struct btd_gatt_client *client, --2.4.3
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi,
Quoted 24 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
notify_data_write_ccctakes another reference in case it succeed so the original reference should be dropped to cause the data to be freed oncenotify_data_write_ccccompletes.--- src/shared/gatt-client.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)src/shared/gatt-client.c +1
-3@@ -1596,8 +1596,7 @@ static void complete_unregister_notify(void *data) !notify_data->chrc->ccc_handle) goto done; -if (notify_data_write_ccc (notify_data, false, disable_ccc_callback)) -return ; +notify_data_write_ccc (notify_data, false, disable_ccc_callback); done:notify_data_unref (notify_data); --
Quoted 1 line
2.4.3
Applied.
Signature · 1 line
Luiz Augusto von Dentz
Re: [PATCH BlueZ 2/3] core/gatt: Fix not able to read/write on reconnections
In reply to Jakub PawlowskiHi Luiz,
Quoted 5 lines · Jakub Pawlowski
Hi Luiz,
This patch fixes all my issues with writing just after connecting. Thanks alot!
So reading and writing works perfectly, even better than I fought - I have some short flows that execute before services get re-discovered, but registering for notifications just after connection fails.
I can call DBus method register for notifications before I connect , and request will succeed, but I would really be registered for notifications after btd_gatt_client_ready is called.
This cause a race condition:
1. App Call DBus register for notifications.
2. App call Connect on Device.
3. App Write - write succeds immediately.
4. Device sends back notification which I don't receive in App (I can see it coming in btmon).
5. Now btd_gatt_client_ready is called, and App is really being registered for notifications (too late).
I'm working on fixing that. It whould require registering for notifications right after connecting, before serivces get discovered.
Quoted 98 lines
Quoted 96 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
Upon reconnecting the attributes may already be available from cache which mean the client would be able to issue commands while discovery is not complete thus
btd_gatt_client_readywas not called yet.To fix now
btd_gatt_client_readyis split intobtd_gatt_client_connectedwhich is called whenever connected leavingbtd_gatt_client_readyto only deal with exporting services found during the discovery.--- src/device.c | 2 ++ src/gatt-client.c | 24 +++++++++++++++++------- src/gatt-client.h | 1 + 3 files changed, 20 insertions(+), 7 deletions(-)src/device.c +2
-0@@ -4602,6 +4602,8 @@ static void gatt_client_init(struct btd_device *device) } device->gatt_cache_used = !gatt_db_isempty (device->db); + +btd_gatt_client_connected (device->client_dbus); }static void gatt_server_init (struct btd_device *device,struct gatt_db *db)src/gatt-client.c +17
-7@@ -1825,20 +1825,14 @@ fail:void btd_gatt_client_ready (struct btd_gatt_client *client) { -struct bt_gatt_client *gatt; -if (!client)return ; - gatt =btd_device_get_gatt_client (client->device); -if (!gatt) { +if (!client->gatt) {error ("GATT client not initialized" );return ; } -bt_gatt_client_unref (client->gatt); - client->gatt =bt_gatt_client_ref (gatt); - client->ready = true;DBG ("GATT client ready" );@@ -1852,6 +1846,22 @@ void btd_gatt_client_ready(struct btd_gatt_client *client)queue_foreach (client->all_notify_clients, register_notify, client); } +void btd_gatt_client_connected (struct btd_gatt_client *client) +{ +struct bt_gatt_client *gatt; + + gatt =btd_device_get_gatt_client (client->device); +if (!gatt) { +error ("GATT client not initialized" ); +return ; + } + +DBG ("Device connected." ); + +bt_gatt_client_unref (client->gatt); + client->gatt =bt_gatt_client_ref (gatt); +} +void btd_gatt_client_service_added (struct btd_gatt_client *client,struct gatt_db_attribute *attrib) {src/gatt-client.h +1
-1@@ -23,6 +23,7 @@ struct btd_gatt_client *btd_gatt_client_new(struct btd_device *device);void btd_gatt_client_destroy (struct btd_gatt_client *client);void btd_gatt_client_ready (struct btd_gatt_client *client); +void btd_gatt_client_connected (struct btd_gatt_client *client);void btd_gatt_client_service_added (struct btd_gatt_client *client,struct gatt_db_attribute *attrib); void btd_gatt_client_service_removed(struct btd_gatt_client *client, --2.4.3
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html