* [PATCH BlueZ 1/8] core/device: Load stored attributes before initializing GATT client
@ 2016-09-12 14:07 Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 2/8] gap: Fix not handling accept properly Luiz Augusto von Dentz
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2016-09-12 14:07 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
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(-)
diff --git a/src/device.c b/src/device.c
index fd928fc..73bcc8f 100644
--- a/src/device.c
+++ b/src/device.c
@@ -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
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH BlueZ 2/8] gap: Fix not handling accept properly
2016-09-12 14:07 [PATCH BlueZ 1/8] core/device: Load stored attributes before initializing GATT client Luiz Augusto von Dentz
@ 2016-09-12 14:07 ` Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 3/8] gap: Make use of service user_data to store service context Luiz Augusto von Dentz
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2016-09-12 14:07 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
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(+)
diff --git a/profiles/gap/gas.c b/profiles/gap/gas.c
index 35b996c..b10b6ac 100644
--- a/profiles/gap/gas.c
+++ b/profiles/gap/gas.c
@@ -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;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH BlueZ 3/8] gap: Make use of service user_data to store service context
2016-09-12 14:07 [PATCH BlueZ 1/8] core/device: Load stored attributes before initializing GATT client Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 2/8] gap: Fix not handling accept properly Luiz Augusto von Dentz
@ 2016-09-12 14:07 ` Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 4/8] gap: Implement disconnect callback Luiz Augusto von Dentz
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2016-09-12 14:07 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
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(-)
diff --git a/profiles/gap/gas.c b/profiles/gap/gas.c
index b10b6ac..93a9a6d 100644
--- a/profiles/gap/gas.c
+++ b/profiles/gap/gas.c
@@ -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)
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH BlueZ 4/8] gap: Implement disconnect callback
2016-09-12 14:07 [PATCH BlueZ 1/8] core/device: Load stored attributes before initializing GATT client Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 2/8] gap: Fix not handling accept properly Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 3/8] gap: Make use of service user_data to store service context Luiz Augusto von Dentz
@ 2016-09-12 14:07 ` Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 5/8] gap: Use shorter names for profile callback Luiz Augusto von Dentz
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2016-09-12 14:07 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
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(-)
diff --git a/profiles/gap/gas.c b/profiles/gap/gas.c
index 93a9a6d..2077ed9 100644
--- a/profiles/gap/gas.c
+++ b/profiles/gap/gas.c
@@ -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)
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH BlueZ 5/8] gap: Use shorter names for profile callback
2016-09-12 14:07 [PATCH BlueZ 1/8] core/device: Load stored attributes before initializing GATT client Luiz Augusto von Dentz
` (2 preceding siblings ...)
2016-09-12 14:07 ` [PATCH BlueZ 4/8] gap: Implement disconnect callback Luiz Augusto von Dentz
@ 2016-09-12 14:07 ` Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 6/8] deviceinfo: Fix not handling accept properly Luiz Augusto von Dentz
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2016-09-12 14:07 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
profiles/gap/gas.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/profiles/gap/gas.c b/profiles/gap/gas.c
index 2077ed9..47c8c25 100644
--- a/profiles/gap/gas.c
+++ b/profiles/gap/gas.c
@@ -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,
};
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH BlueZ 6/8] deviceinfo: Fix not handling accept properly
2016-09-12 14:07 [PATCH BlueZ 1/8] core/device: Load stored attributes before initializing GATT client Luiz Augusto von Dentz
` (3 preceding siblings ...)
2016-09-12 14:07 ` [PATCH BlueZ 5/8] gap: Use shorter names for profile callback Luiz Augusto von Dentz
@ 2016-09-12 14:07 ` Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 7/8] deviceinfo: Implement disconnect callback Luiz Augusto von Dentz
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2016-09-12 14:07 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
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(+)
diff --git a/profiles/deviceinfo/deviceinfo.c b/profiles/deviceinfo/deviceinfo.c
index 0c48f00..34d9e20 100644
--- a/profiles/deviceinfo/deviceinfo.c
+++ b/profiles/deviceinfo/deviceinfo.c
@@ -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;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH BlueZ 7/8] deviceinfo: Implement disconnect callback
2016-09-12 14:07 [PATCH BlueZ 1/8] core/device: Load stored attributes before initializing GATT client Luiz Augusto von Dentz
` (4 preceding siblings ...)
2016-09-12 14:07 ` [PATCH BlueZ 6/8] deviceinfo: Fix not handling accept properly Luiz Augusto von Dentz
@ 2016-09-12 14:07 ` Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 8/8] deviceinfo: Use shorter names for profile callback Luiz Augusto von Dentz
2016-09-13 14:09 ` [PATCH BlueZ 1/8] core/device: Load stored attributes before initializing GATT client Luiz Augusto von Dentz
7 siblings, 0 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2016-09-12 14:07 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This implements the profile disconnect so the service state is updated
properly.
---
profiles/deviceinfo/deviceinfo.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/profiles/deviceinfo/deviceinfo.c b/profiles/deviceinfo/deviceinfo.c
index 34d9e20..0ce7edb 100644
--- a/profiles/deviceinfo/deviceinfo.c
+++ b/profiles/deviceinfo/deviceinfo.c
@@ -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)
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH BlueZ 8/8] deviceinfo: Use shorter names for profile callback
2016-09-12 14:07 [PATCH BlueZ 1/8] core/device: Load stored attributes before initializing GATT client Luiz Augusto von Dentz
` (5 preceding siblings ...)
2016-09-12 14:07 ` [PATCH BlueZ 7/8] deviceinfo: Implement disconnect callback Luiz Augusto von Dentz
@ 2016-09-12 14:07 ` Luiz Augusto von Dentz
2016-09-13 14:09 ` [PATCH BlueZ 1/8] core/device: Load stored attributes before initializing GATT client Luiz Augusto von Dentz
7 siblings, 0 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2016-09-12 14:07 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
profiles/deviceinfo/deviceinfo.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/profiles/deviceinfo/deviceinfo.c b/profiles/deviceinfo/deviceinfo.c
index 0ce7edb..fa94efe 100644
--- a/profiles/deviceinfo/deviceinfo.c
+++ b/profiles/deviceinfo/deviceinfo.c
@@ -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,
};
--
2.7.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH BlueZ 1/8] core/device: Load stored attributes before initializing GATT client
2016-09-12 14:07 [PATCH BlueZ 1/8] core/device: Load stored attributes before initializing GATT client Luiz Augusto von Dentz
` (6 preceding siblings ...)
2016-09-12 14:07 ` [PATCH BlueZ 8/8] deviceinfo: Use shorter names for profile callback Luiz Augusto von Dentz
@ 2016-09-13 14:09 ` Luiz Augusto von Dentz
7 siblings, 0 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2016-09-13 14:09 UTC (permalink / raw)
To: linux-bluetooth@vger.kernel.org
Hi,
On Mon, Sep 12, 2016 at 5:07 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> 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(-)
>
> diff --git a/src/device.c b/src/device.c
> index fd928fc..73bcc8f 100644
> --- a/src/device.c
> +++ b/src/device.c
> @@ -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
> --
> 2.7.4
Applied.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2016-09-13 14:09 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-12 14:07 [PATCH BlueZ 1/8] core/device: Load stored attributes before initializing GATT client Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 2/8] gap: Fix not handling accept properly Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 3/8] gap: Make use of service user_data to store service context Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 4/8] gap: Implement disconnect callback Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 5/8] gap: Use shorter names for profile callback Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 6/8] deviceinfo: Fix not handling accept properly Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 7/8] deviceinfo: Implement disconnect callback Luiz Augusto von Dentz
2016-09-12 14:07 ` [PATCH BlueZ 8/8] deviceinfo: Use shorter names for profile callback Luiz Augusto von Dentz
2016-09-13 14:09 ` [PATCH BlueZ 1/8] core/device: Load stored attributes before initializing GATT client Luiz Augusto von Dentz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).