Initialize included queue even if service is Secondary Service.
---
android/gatt.c | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/android/gatt.c b/android/gatt.c
index 7cf612f..6b57145 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -318,8 +318,7 @@ static void destroy_service(void *data)
* So we need to free service memory only once but we need to destroy
* two queues
*/
- if (srvc->primary)
- queue_destroy(srvc->included, NULL);
+ queue_destroy(srvc->included, NULL);
free(srvc);
}
@@ -1081,6 +1080,14 @@ static struct service *create_service(uint8_t id, bool primary, char *uuid,
return NULL;
}
+ s->included = queue_new();
+ if (!s->included) {
+ error("gatt: Cannot allocate memory for included queue");
+ queue_destroy(s->chars, NULL);
+ free(s);
+ return NULL;
+ }
+
if (bt_string_to_uuid(&s->id.uuid, uuid) < 0) {
error("gatt: Cannot convert string to uuid");
queue_destroy(s->chars, NULL);
@@ -1092,20 +1099,10 @@ static struct service *create_service(uint8_t id, bool primary, char *uuid,
/* Put primary service to our local list */
s->primary = primary;
- if (s->primary) {
+ if (s->primary)
memcpy(&s->prim, data, sizeof(s->prim));
- } else {
+ else
memcpy(&s->incl, data, sizeof(s->incl));
- return s;
- }
-
- /* For primary service allocate queue for included services */
- s->included = queue_new();
- if (!s->included) {
- queue_destroy(s->chars, NULL);
- free(s);
- return NULL;
- }
return s;
}
--
1.9.3
Hi Marcin,
On Thursday 06 of November 2014 13:57:05 Marcin Kraglak wrote:
> Initialize included queue even if service is Secondary Service.
> ---
> android/gatt.c | 25 +++++++++++--------------
> 1 file changed, 11 insertions(+), 14 deletions(-)
>
> diff --git a/android/gatt.c b/android/gatt.c
> index 7cf612f..6b57145 100644
> --- a/android/gatt.c
> +++ b/android/gatt.c
> @@ -318,8 +318,7 @@ static void destroy_service(void *data)
> * So we need to free service memory only once but we need to destroy
> * two queues
> */
> - if (srvc->primary)
> - queue_destroy(srvc->included, NULL);
> + queue_destroy(srvc->included, NULL);
>
> free(srvc);
> }
> @@ -1081,6 +1080,14 @@ static struct service *create_service(uint8_t id, bool primary, char *uuid,
> return NULL;
> }
>
> + s->included = queue_new();
> + if (!s->included) {
> + error("gatt: Cannot allocate memory for included queue");
> + queue_destroy(s->chars, NULL);
> + free(s);
> + return NULL;
> + }
> +
> if (bt_string_to_uuid(&s->id.uuid, uuid) < 0) {
> error("gatt: Cannot convert string to uuid");
> queue_destroy(s->chars, NULL);
> @@ -1092,20 +1099,10 @@ static struct service *create_service(uint8_t id, bool primary, char *uuid,
>
> /* Put primary service to our local list */
> s->primary = primary;
> - if (s->primary) {
> + if (s->primary)
> memcpy(&s->prim, data, sizeof(s->prim));
> - } else {
> + else
> memcpy(&s->incl, data, sizeof(s->incl));
> - return s;
> - }
> -
> - /* For primary service allocate queue for included services */
> - s->included = queue_new();
> - if (!s->included) {
> - queue_destroy(s->chars, NULL);
> - free(s);
> - return NULL;
> - }
>
> return s;
> }
Both patches applied, thanks.
--
Best regards,
Szymon Janc
Check type of service and perform include service discovery with valid
range.
---
android/gatt.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/android/gatt.c b/android/gatt.c
index 6b57145..56123ce 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -2416,6 +2416,7 @@ static bool search_included_services(struct app_connection *connection,
struct service *service)
{
struct get_included_data *data;
+ uint16_t start, end;
data = new0(struct get_included_data, 1);
if (!data) {
@@ -2426,9 +2427,17 @@ static bool search_included_services(struct app_connection *connection,
data->prim = service;
data->conn = connection;
- gatt_find_included(connection->device->attrib,
- service->prim.range.start,
- service->prim.range.end, get_included_cb, data);
+ if (service->primary) {
+ start = service->prim.range.start;
+ end = service->prim.range.end;
+ } else {
+ start = service->incl.range.start;
+ end = service->incl.range.end;
+ }
+
+ gatt_find_included(connection->device->attrib, start, end,
+ get_included_cb, data);
+
return true;
}
--
1.9.3