core/device: Load stored attributes before initializing GATT client
Luiz Augusto von Dentz
maintainerPATCH 1/8 core/device: Load stored attributes before initializing GATT client
From: Luiz Augusto von Dentz <[email protected]>
During gatt_client_init service are requested to accept the connection which may leads the driver to check existence of attributes.
--- src/device.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
src/device.c +3 -3
@@ -4823,12 +4823,12 @@ bool device_attach_att(struct btd_device *dev, GIOChannel *io) dst =device_get_address (dev);ba2str (dst, dstaddr); -gatt_client_init (dev); -gatt_server_init (dev,btd_gatt_database_get_db (database)); -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)); +/* * Remove the device from the connect_list and give the passive * scanning another chance to be restarted in case there are
Signature · 1 line
2.7.4
Luiz Augusto von Dentz
maintainerPATCH 2/8 gap: Fix not handling accept properly
From: Luiz Augusto von Dentz <[email protected]>
On accept the profile shall check about existing attribute, etc and once done call btd_service_connecting_complete updating the service state properly.
--- profiles/gap/gas.c | 7 +++++++ 1 file changed, 7 insertions(+)
profiles/gap/gas.c +7 -0
@@ -300,6 +300,13 @@ static int gap_driver_accept(struct btd_service *service)bt_uuid16_create (&gap_uuid,GAP_UUID16 );gatt_db_foreach_service (db, &gap_uuid, foreach_gap_service, gas); +if (!gas->attr) { +error ("GAP attribute not found" ); +return -1 ; + } + +btd_service_connecting_complete (service,0 ); +return 0 ; }
Signature · 1 line
2.7.4
Luiz Augusto von Dentz
maintainerPATCH 3/8 gap: Make use of service user_data to store service context
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Instead of storing service context data in a list this make use of btd_service_set_user_data to store the context data which later can be retrieved with btd_service_get_user_data.
--- profiles/gap/gas.c | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-)
profiles/gap/gas.c +8 -32
@@ -57,8 +57,6 @@ struct gas {struct gatt_db_attribute *attr; }; -static GSList *devices; -static void gas_free (struct gas *gas) {gatt_db_unref (gas->db);
@@ -67,14 +65,6 @@ static void gas_free(struct gas *gas)g_free (gas); } -static int cmp_device (gconstpointer a,gconstpointer b) -{ -const struct gas *gas = a; -const struct btd_device *device = b; - -return gas->device == device ?0 :-1 ; -} -static char *name2utf8 (const uint8_t *name,uint16_t len) {char utf8_name[HCI_MAX_NAME_LENGTH +2 ];
@@ -208,16 +198,14 @@ static void handle_gap_service(struct gas *gas)static int gap_driver_probe (struct btd_service *service) {struct btd_device *device =btd_service_get_device (service); -struct gas *gas; -GSList *l; +struct gas *gas =btd_service_get_user_data (service);char addr[18 ];ba2str (device_get_address (device), addr);DBG ("GAP profile probe (%s)" , addr);/* Ignore, if we were probed for this device already */ - l =g_slist_find_custom (devices, device, cmp_device); -if (l) { +if (gas) {error ("Profile probed twice for the same device!" );return -1 ; }
@@ -227,7 +215,7 @@ static int gap_driver_probe(struct btd_service *service)return -1 ; gas->device =btd_device_ref (device); - devices =g_slist_append (devices, gas); +btd_service_set_user_data (service, gas);return 0 ; }
@@ -236,21 +224,17 @@ static void gap_driver_remove(struct btd_service *service) {struct btd_device *device =btd_service_get_device (service);struct gas *gas; -GSList *l;char addr[18 ];ba2str (device_get_address (device), addr);DBG ("GAP profile remove (%s)" , addr); - l =g_slist_find_custom (devices, device, cmp_device); -if (!l) { + gas =btd_service_get_user_data (service); +if (!gas) {error ("GAP service not handled by profile" );return ; } - gas = l->data; - - devices =g_slist_remove (devices, gas);gas_free (gas); }
@@ -272,22 +256,18 @@ static int gap_driver_accept(struct btd_service *service)struct btd_device *device =btd_service_get_device (service);struct gatt_db *db =btd_device_get_gatt_db (device);struct bt_gatt_client *client =btd_device_get_gatt_client (device); -struct gas *gas; -GSList *l; +struct gas *gas =btd_service_get_user_data (service);char addr[18 ];bt_uuid_t gap_uuid;ba2str (device_get_address (device), addr);DBG ("GAP profile accept (%s)" , addr); - l =g_slist_find_custom (devices, device, cmp_device); -if (!l) { +if (!gas) {error ("GAP service not handled by profile" );return -1 ; } - gas = l->data; -/* Clean-up any old client/db and acquire the new ones */ gas->attr =NULL ;gatt_db_unref (gas->db);
@@ -320,11 +300,7 @@ static struct btd_profile gap_profile = {static int gap_init (void ) { - devices =NULL ; - -btd_profile_register (&gap_profile); - -return 0 ; +return btd_profile_register (&gap_profile); }static void gap_exit (void )
Signature · 1 line
2.7.4
Luiz Augusto von Dentz
maintainerPATCH 4/8 gap: Implement disconnect callback
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This implements the profile disconnect callback using it to cleanup existing references of bt_gatt_client and gatt_db.
--- profiles/gap/gas.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-)
profiles/gap/gas.c +23 -6
@@ -251,6 +251,15 @@ static void foreach_gap_service(struct gatt_db_attribute *attr, void *user_data)handle_gap_service (gas); } +static void gas_reset (struct gas *gas) +{ + gas->attr =NULL ; +gatt_db_unref (gas->db); + gas->db =NULL ; +bt_gatt_client_unref (gas->client); + gas->client =NULL ; +} +static int gap_driver_accept (struct btd_service *service) {struct btd_device *device =btd_service_get_device (service);
@@ -268,11 +277,6 @@ static int gap_driver_accept(struct btd_service *service)return -1 ; } -/* Clean-up any old client/db and acquire the new ones */ - gas->attr =NULL ; -gatt_db_unref (gas->db); -bt_gatt_client_unref (gas->client); - gas->db =gatt_db_ref (db); gas->client =bt_gatt_client_ref (client);
@@ -282,6 +286,7 @@ static int gap_driver_accept(struct btd_service *service)if (!gas->attr) {error ("GAP attribute not found" ); +gas_reset (gas);return -1 ; }
@@ -290,12 +295,24 @@ static int gap_driver_accept(struct btd_service *service)return 0 ; } +static int gap_disconnect (struct btd_service *service) +{ +struct gas *gas =btd_service_get_user_data (service); + +gas_reset (gas); + +btd_service_disconnecting_complete (service,0 ); + +return 0 ; +} +static struct btd_profile gap_profile = { .name ="gap-profile" , .remote_uuid =GAP_UUID , .device_probe = gap_driver_probe, .device_remove = gap_driver_remove, - .accept = gap_driver_accept + .accept = gap_driver_accept, + .disconnect = gap_disconnect, };static int gap_init (void )
Signature · 1 line
2.7.4
Luiz Augusto von Dentz
maintainerPATCH 5/8 gap: Use shorter names for profile callback
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- profiles/gap/gas.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
profiles/gap/gas.c +6 -6
@@ -195,7 +195,7 @@ static void handle_gap_service(struct gas *gas)gatt_db_service_foreach_char (gas->attr, handle_characteristic, gas); } -static int gap_driver_probe (struct btd_service *service) +static int gap_probe (struct btd_service *service) {struct btd_device *device =btd_service_get_device (service);struct gas *gas =btd_service_get_user_data (service);
@@ -220,7 +220,7 @@ static int gap_driver_probe(struct btd_service *service)return 0 ; } -static void gap_driver_remove (struct btd_service *service) +static void gap_remove (struct btd_service *service) {struct btd_device *device =btd_service_get_device (service);struct gas *gas;
@@ -260,7 +260,7 @@ static void gas_reset(struct gas *gas) gas->client =NULL ; } -static int gap_driver_accept (struct btd_service *service) +static int gap_accept (struct btd_service *service) {struct btd_device *device =btd_service_get_device (service);struct gatt_db *db =btd_device_get_gatt_db (device);
@@ -309,9 +309,9 @@ static int gap_disconnect(struct btd_service *service)static struct btd_profile gap_profile = { .name ="gap-profile" , .remote_uuid =GAP_UUID , - .device_probe = gap_driver_probe, - .device_remove = gap_driver_remove, - .accept = gap_driver_accept, + .device_probe = gap_probe, + .device_remove = gap_remove, + .accept = gap_accept, .disconnect = gap_disconnect, };
Signature · 1 line
2.7.4
Luiz Augusto von Dentz
maintainerPATCH 6/8 deviceinfo: Fix not handling accept properly
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
On accept the profile shall check about existing attribute, etc and once done call btd_service_connecting_complete updating the service state properly.
--- profiles/deviceinfo/deviceinfo.c | 2 ++ 1 file changed, 2 insertions(+)
profiles/deviceinfo/deviceinfo.c +2 -0
@@ -136,6 +136,8 @@ static int deviceinfo_driver_accept(struct btd_service *service)gatt_db_foreach_service (db, &deviceinfo_uuid, foreach_deviceinfo_service, device); +btd_service_connecting_complete (service,0 ); +return 0 ; }
Signature · 1 line
2.7.4
Luiz Augusto von Dentz
maintainerPATCH 7/8 deviceinfo: Implement disconnect callback
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This implements the profile disconnect so the service state is updated properly.
--- profiles/deviceinfo/deviceinfo.c | 8 ++++++++ 1 file changed, 8 insertions(+)
profiles/deviceinfo/deviceinfo.c +8 -0
@@ -141,6 +141,13 @@ static int deviceinfo_driver_accept(struct btd_service *service)return 0 ; } +static int deviceinfo_disconnect (struct btd_service *service) +{ +btd_service_disconnecting_complete (service,0 ); + +return 0 ; +} +static struct btd_profile deviceinfo_profile = { .name ="deviceinfo" , .remote_uuid =DEVICE_INFORMATION_UUID ,
@@ -148,6 +155,7 @@ static struct btd_profile deviceinfo_profile = { .device_probe = deviceinfo_driver_probe, .device_remove = deviceinfo_driver_remove, .accept = deviceinfo_driver_accept, + .disconnect = deviceinfo_disconnect, };static int deviceinfo_init (void )
Signature · 1 line
2.7.4
Luiz Augusto von Dentz
maintainerPATCH 8/8 deviceinfo: Use shorter names for profile callback
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
--- profiles/deviceinfo/deviceinfo.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
profiles/deviceinfo/deviceinfo.c +6 -6
@@ -111,17 +111,17 @@ static void foreach_deviceinfo_service(struct gatt_db_attribute *attr,gatt_db_service_foreach_char (attr, handle_characteristic, device); } -static int deviceinfo_driver_probe (struct btd_service *service) +static int deviceinfo_probe (struct btd_service *service) {return 0 ; } -static void deviceinfo_driver_remove (struct btd_service *service) +static void deviceinfo_remove (struct btd_service *service) { } -static int deviceinfo_driver_accept (struct btd_service *service) +static int deviceinfo_accept (struct btd_service *service) {struct btd_device *device =btd_service_get_device (service);struct gatt_db *db =btd_device_get_gatt_db (device);
@@ -152,9 +152,9 @@ static struct btd_profile deviceinfo_profile = { .name = "deviceinfo", .remote_uuid = DEVICE_INFORMATION_UUID, .external = true, - .device_probe = deviceinfo_driver_probe, - .device_remove = deviceinfo_driver_remove, - .accept = deviceinfo_driver_accept, + .device_probe = deviceinfo_probe, + .device_remove = deviceinfo_remove, + .accept = deviceinfo_accept, .disconnect = deviceinfo_disconnect, };
Signature · 1 line
2.7.4
Hi,
Quoted 29 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
During
gatt_client_initservice are requested to accept the connection which may leads the driver to check existence of attributes.--- src/device.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)src/device.c +3
-4@@ -4823,12 +4823,12 @@ bool device_attach_att(struct btd_device *dev, GIOChannel *io) dst =device_get_address (dev);ba2str (dst, dstaddr); -gatt_client_init (dev); -gatt_server_init (dev,btd_gatt_database_get_db (database)); -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)); +/* * Remove the device from the connect_list and give the passive * scanning another chance to be restarted in case there are --
Quoted 1 line
2.7.4
Applied.
Signature · 1 line
Luiz Augusto von Dentz