All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/2] shared/gatt-db: Use insert_service for add_service
@ 2014-12-01 23:59 Michael Janssen
  2014-12-01 23:59 ` [PATCH BlueZ 2/2] shared/gatt-db: Prevent insert at invalid handle 0 Michael Janssen
  2014-12-02 13:56 ` [PATCH BlueZ 1/2] shared/gatt-db: Use insert_service for add_service Luiz Augusto von Dentz
  0 siblings, 2 replies; 3+ messages in thread
From: Michael Janssen @ 2014-12-01 23:59 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Michael Janssen

gatt_db_add_service is the same as gatt_db_insert_service with little
change except not specifying the handle.  Reuse the code.
---
 src/shared/gatt-db.c | 38 +++++++++-----------------------------
 1 file changed, 9 insertions(+), 29 deletions(-)

diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index b210376..2a35bae 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -258,35 +258,6 @@ static struct gatt_db_service *gatt_db_service_create(const bt_uuid_t *uuid,
 	return service;
 }
 
-struct gatt_db_attribute *gatt_db_add_service(struct gatt_db *db,
-						const bt_uuid_t *uuid,
-						bool primary,
-						uint16_t num_handles)
-{
-	struct gatt_db_service *service;
-
-	if (!db || (num_handles + db->next_handle - 1) > UINT16_MAX)
-		return NULL;
-
-	service = gatt_db_service_create(uuid, primary, num_handles);
-	if (!service)
-		return NULL;
-
-	if (!queue_push_tail(db->services, service)) {
-		gatt_db_service_destroy(service);
-		return NULL;
-	}
-
-	/* TODO now we get next handle from database. We should first look
-	 * for 'holes' between existing services first, and assign next_handle
-	 * only if enough space was not found.
-	 */
-	service->attributes[0]->handle = db->next_handle;
-	db->next_handle += num_handles;
-	service->num_handles = num_handles;
-
-	return service->attributes[0];
-}
 
 bool gatt_db_remove_service(struct gatt_db *db,
 					struct gatt_db_attribute *attrib)
@@ -442,6 +413,15 @@ fail:
 	return NULL;
 }
 
+struct gatt_db_attribute *gatt_db_add_service(struct gatt_db *db,
+						const bt_uuid_t *uuid,
+						bool primary,
+						uint16_t num_handles)
+{
+	return gatt_db_insert_service(db, db->next_handle, uuid, primary
+								num_handles);
+}
+
 static uint16_t get_attribute_index(struct gatt_db_service *service,
 							int end_offset)
 {
-- 
2.2.0.rc0.207.ga3a616c


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH BlueZ 2/2] shared/gatt-db: Prevent insert at invalid handle 0
  2014-12-01 23:59 [PATCH BlueZ 1/2] shared/gatt-db: Use insert_service for add_service Michael Janssen
@ 2014-12-01 23:59 ` Michael Janssen
  2014-12-02 13:56 ` [PATCH BlueZ 1/2] shared/gatt-db: Use insert_service for add_service Luiz Augusto von Dentz
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Janssen @ 2014-12-01 23:59 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Michael Janssen

Handles can't be placed at 0x0000.
---
 src/shared/gatt-db.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 2a35bae..2a0fcb1 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -376,7 +376,8 @@ struct gatt_db_attribute *gatt_db_insert_service(struct gatt_db *db,
 	struct insert_loc_data data;
 	struct gatt_db_service *service;
 
-	if (!db || num_handles < 1 || (handle + num_handles - 1) > UINT16_MAX)
+	if (!db || num_handles < 1 || handle < 1 ||
+					(handle + num_handles - 1) > UINT16_MAX)
 		return NULL;
 
 	memset(&data, 0, sizeof(data));
-- 
2.2.0.rc0.207.ga3a616c


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH BlueZ 1/2] shared/gatt-db: Use insert_service for add_service
  2014-12-01 23:59 [PATCH BlueZ 1/2] shared/gatt-db: Use insert_service for add_service Michael Janssen
  2014-12-01 23:59 ` [PATCH BlueZ 2/2] shared/gatt-db: Prevent insert at invalid handle 0 Michael Janssen
@ 2014-12-02 13:56 ` Luiz Augusto von Dentz
  1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2014-12-02 13:56 UTC (permalink / raw)
  To: Michael Janssen; +Cc: linux-bluetooth

Hi Michael,

On Tue, Dec 2, 2014 at 1:59 AM, Michael Janssen <jamuraa@chromium.org> wrote:
> gatt_db_add_service is the same as gatt_db_insert_service with little
> change except not specifying the handle.  Reuse the code.
> ---
>  src/shared/gatt-db.c | 38 +++++++++-----------------------------
>  1 file changed, 9 insertions(+), 29 deletions(-)
>
> diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
> index b210376..2a35bae 100644
> --- a/src/shared/gatt-db.c
> +++ b/src/shared/gatt-db.c
> @@ -258,35 +258,6 @@ static struct gatt_db_service *gatt_db_service_create(const bt_uuid_t *uuid,
>         return service;
>  }
>
> -struct gatt_db_attribute *gatt_db_add_service(struct gatt_db *db,
> -                                               const bt_uuid_t *uuid,
> -                                               bool primary,
> -                                               uint16_t num_handles)
> -{
> -       struct gatt_db_service *service;
> -
> -       if (!db || (num_handles + db->next_handle - 1) > UINT16_MAX)
> -               return NULL;
> -
> -       service = gatt_db_service_create(uuid, primary, num_handles);
> -       if (!service)
> -               return NULL;
> -
> -       if (!queue_push_tail(db->services, service)) {
> -               gatt_db_service_destroy(service);
> -               return NULL;
> -       }
> -
> -       /* TODO now we get next handle from database. We should first look
> -        * for 'holes' between existing services first, and assign next_handle
> -        * only if enough space was not found.
> -        */
> -       service->attributes[0]->handle = db->next_handle;
> -       db->next_handle += num_handles;
> -       service->num_handles = num_handles;
> -
> -       return service->attributes[0];
> -}
>
>  bool gatt_db_remove_service(struct gatt_db *db,
>                                         struct gatt_db_attribute *attrib)
> @@ -442,6 +413,15 @@ fail:
>         return NULL;
>  }
>
> +struct gatt_db_attribute *gatt_db_add_service(struct gatt_db *db,
> +                                               const bt_uuid_t *uuid,
> +                                               bool primary,
> +                                               uint16_t num_handles)
> +{
> +       return gatt_db_insert_service(db, db->next_handle, uuid, primary
> +                                                               num_handles);

This one did not compile initially since there is a missing ','
between primary and num_handles, I fixed that and applied both.


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-12-02 13:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-01 23:59 [PATCH BlueZ 1/2] shared/gatt-db: Use insert_service for add_service Michael Janssen
2014-12-01 23:59 ` [PATCH BlueZ 2/2] shared/gatt-db: Prevent insert at invalid handle 0 Michael Janssen
2014-12-02 13:56 ` [PATCH BlueZ 1/2] shared/gatt-db: Use insert_service for add_service Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.