Skip to contentSkip to conversation

Provide return status in gatt_service_add function

PATCH In review Santiago Carot-Nemesio 4 participants 11 messages Nov 24, 2011 – Dec 5, 2011 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Provide return status in gatt_service_add function

Service plugins using the new GATT API may need to know if their attributes were successfuly retgistered. In this way, plugins might abort loading operation if they weren't registered.

---
 attrib/gatt-service.c |   15 +++++++++------
 attrib/gatt-service.h |    2 +-
 2 files changed, 10 insertions(+), 7 deletions(-)
attrib/gatt-service.c +9 -6
index ead3f8e..b904ce6 100644
@@ -244,7 +244,7 @@ static void free_gatt_info(void *data)
 	g_free(info);
 }
 
-void gatt_service_add(uint16_t uuid, uint16_t svc_uuid, gatt_option opt1, ...)
+gboolean gatt_service_add(uint16_t uuid, uint16_t svc_uuid, gatt_option opt1, ...)
 {
 	uint16_t start_handle, h;
 	unsigned int size;
@@ -265,7 +265,8 @@ void gatt_service_add(uint16_t uuid, uint16_t svc_uuid, gatt_option opt1, ...)
 	start_handle = attrib_db_find_avail(size);
 	if (start_handle == 0) {
 		error("Not enough free handles to register service");
-		goto done;
+		g_slist_free_full(chrs, free_gatt_info);
+		return FALSE;
 	}
 
 	DBG("New service: handle 0x%04x, UUID 0x%04x, %d attributes",
@@ -282,13 +283,15 @@ void gatt_service_add(uint16_t uuid, uint16_t svc_uuid, gatt_option opt1, ...)
 		struct gatt_info *info = l->data;
 
 		DBG("New characteristic: handle 0x%04x", h);
-		if (!add_characteristic(&h, info))
-			goto done;
+		if (!add_characteristic(&h, info)) {
+			g_slist_free_full(chrs, free_gatt_info);
+			return FALSE;
+		}
 	}
 
 	g_assert(size < USHRT_MAX);
 	g_assert(h - start_handle == (uint16_t) size);
-
-done:
 	g_slist_free_full(chrs, free_gatt_info);
+
+	return TRUE;
 }
attrib/gatt-service.h +1 -1
index 6525dc0..95064c0 100644
@@ -47,4 +47,4 @@ typedef enum {
 	ATTRIB_WRITE,
 } attrib_event_t;
 
-void gatt_service_add(uint16_t uuid, uint16_t svc_uuid, gatt_option opt1, ...);
+gboolean gatt_service_add(uint16_t uuid, uint16_t svc_uuid, gatt_option opt1, ...);
Signature · 1 line
1.7.7.4
#1 lore raw

PATCH 2/2 Update gatt-exmaple to check if attributes were registered.

---
 plugins/gatt-example.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
plugins/gatt-example.c +8 -3
index 1456284..6d9b6b8 100644
@@ -28,6 +28,7 @@
 
 #include <glib.h>
 #include <bluetooth/uuid.h>
+#include <errno.h>
 
 #include "plugin.h"
 #include "hcid.h"
@@ -68,9 +69,9 @@ static uint8_t battery_state_read(struct attribute *a, gpointer user_data)
 	return 0;
 }
 
-static void register_battery_service(void)
+static gboolean register_battery_service(void)
 {
-	gatt_service_add(GATT_PRIM_SVC_UUID, BATTERY_STATE_SVC_UUID,
+	return gatt_service_add(GATT_PRIM_SVC_UUID, BATTERY_STATE_SVC_UUID,
 			/* battery state characteristic */
 			GATT_OPT_CHR_UUID, BATTERY_STATE_UUID,
 			GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_READ |
@@ -445,7 +446,11 @@ static int gatt_example_init(void)
 		return -1;
 	}
 
-	register_battery_service();
+	if (!register_battery_service()) {
+		DBG("Battery service could not be registered");
+		return -EIO;
+	}
+
 	register_manuf1_service(manuf1_range);
 	register_manuf2_service(manuf2_range);
 	register_termometer_service(manuf1_range, manuf2_range);
Signature · 1 line
1.7.7.4
#2 lore raw
In reply to Santiago Carot-Nemesio

Hi Santiago,

Quoted 7 lines · Santiago Carot-Nemesio

Service plugins using the new GATT API may need to know if their attributes were successfuly retgistered. In this way, plugins might abort loading operation if they weren't registered.

---
 attrib/gatt-service.c |   15 +++++++++------
 attrib/gatt-service.h |    2 +-
 2 files changed, 10 insertions(+), 7 deletions(-)

Both patches applied after fixing typos in your commit messages. Thanks.

Johan

#3 lore raw

Hi Johan,

2011/12/2 Johan Hedberg <[email protected]>:

Quoted 11 lines

Hi Santiago,

Quoted 7 lines · Santiago Carot-Nemesio

Service plugins using the new GATT API may need to know if their attributes were successfuly retgistered. In this way, plugins might abort loading operation if they weren't registered.
---
 attrib/gatt-service.c |   15 +++++++++------ attrib/gatt-service.h |    2 +-

 2 files changed, 10 insertions(+), 7 deletions(-)
Quoted 2 lines

Both patches applied after fixing typos in your commit messages. Thanks.

When I was working in this stuff, I was wondering if there may exist the case when a plugin registers several services and the last one fails, Do you think it would have sense to provide the service ID as return parameter to allow plugins remove their attributes before aborting the loading operation?, On the other hand, this feature would raise the posibility of finding gaps in the distribution of handlers assigned in GATT due that plugins could add and remove services dynamically, I'm not sure if that is expected in GATT.

Waiting comments.
Regards

#4 lore raw

Hi Santiago,

Quoted 8 lines · Santiago Carot

When I was working in this stuff, I was wondering if there may exist the case when a plugin registers several services and the last one fails, Do you think it would have sense to provide the service ID as return parameter to allow plugins remove their attributes before aborting the loading operation?, On the other hand, this feature would raise the posibility of finding gaps in the distribution of handlers assigned in GATT due that plugins could add and remove services dynamically, I'm not sure if that is expected in GATT.

I think that, before doing anything like this, we should ensure the handles allocated for GATT servers do not change after registration (i.e. they are kept in storage and reloaded when bluez starts). If possible, can you contribute on this regard?

Thanks,

Signature · 3 lines
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
#5 lore raw

Anderson,

Quoted 28 lines

-----Original Message-----
From: [email protected] [mailto:linux-bluetooth- [email protected]] On Behalf Of Anderson Lizardo
Sent: Friday, December 02, 2011 5:37 PM
To: Santiago Carot
Cc: [email protected]
Subject: Re: [PATCH 1/2] Provide return status in gatt_service_add function

Hi Santiago,

Quoted 5 lines · Santiago Carot

When I was working in this stuff, I was wondering if there may exist the case when a plugin registers several services and the last one fails, Do you think it would have sense to provide the service ID as return parameter to allow plugins remove their attributes before aborting the loading operation?, On the other hand, this feature

would

Quoted 3 lines

raise the posibility of finding gaps in the distribution of handlers assigned in GATT due that plugins could add and remove services dynamically, I'm not sure if that is expected in GATT.

I think that, before doing anything like this, we should ensure the handles allocated for GATT servers do not change after registration (i.e. they are kept in storage and reloaded when bluez starts). If possible, can you contribute on this regard?

Quoted 10 lines

Thanks,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
--
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

How do you ensure that? Do you assume that all servers will always initialize at bluetoothd startup, and always in the same order? Who's responsibility is it to send out the "service changed" notification when something changed? What is the proposed logic for this ?

Thanks,
Chen Ganir

#6 lore raw

Hi Chen,

Quoted 1 line · Chen

How do you ensure that? Do you assume that all servers will always initialize at bluetoothd startup, and always in the same order? Who's responsibility is it to send out the "service changed" notification when something changed? What is the proposed logic for this ?

To make sure the handles do not change between bluetoothd restarts (and is not dependent on any loading order), we need to save/restore attribute handles, like is done for other BlueZ parts.

"Service Changed" is not necessary to be sent if attribute handle storage is implemented. We have no plans to implement "Service Changed" now, but feel free to send patches :)

Regards,

Signature · 3 lines
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
#7 lore raw

Anderson,

Quoted 24 lines

-----Original Message-----
From: Anderson Lizardo [mailto:[email protected]]
Sent: Monday, December 05, 2011 12:56 PM
To: Ganir, Chen
Cc: Santiago Carot; [email protected]
Subject: Re: [PATCH 1/2] Provide return status in gatt_service_add function

Hi Chen,

Quoted 1 line · Chen

How do you ensure that? Do you assume that all servers will always

initialize at bluetoothd startup, and always in the same order? Who's responsibility is it to send out the "service changed" notification when something changed? What is the proposed logic for this ?

To make sure the handles do not change between bluetoothd restarts (and is not dependent on any loading order), we need to save/restore attribute handles, like is done for other BlueZ parts.

"Service Changed" is not necessary to be sent if attribute handle storage is implemented. We have no plans to implement "Service Changed" now, but feel free to send patches :)

Quoted 5 lines

Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

What do you mean restoring the attribute handles ? Each of the profiles registers its own services when the plugin is loaded, according to the load order (which I assume will not change). When a profile registers its attributes, it can specify callbacks for read/write which are actually function pointers. How to you plan to support this? In addition, who will be responsible for reloading the database and populating the values (profile plugin or bluetoothd core) ? how do you synchronize them?

Do you have an RFC or a simple design description which will allow reviewing?

Thanks,
Chen Ganir.

Thanks,
Chen Ganir

#8 lore raw

Hi Chen,

Quoted 1 line · Chen

What do you mean restoring the attribute handles ? Each of the profiles registers its own services when the plugin is loaded, according to the load order (which I assume will not change).

There is no guarantee in the load order. As we add more plugins, you can't predict the order the plugins will be loaded.

Quoted 1 line

When a profile registers its attributes, it can specify callbacks for read/write which are actually function pointers. How to you plan to support this?

Only attribute *handles* are to be stored (for now). The mapping could be based on service+characteristic UUIDs (but we need to pay attention if we have multiple services with same service and characteristic UUIDs; for this case, I'm not even sure how the client knows which one to use).

Quoted 1 line

In addition, who will be responsible for reloading the database and populating the values (profile plugin or bluetoothd core) ? how do you synchronize them?

My suggestion would be to implement this in attrib/gatt-service.c so gatt_service_add() could load attribute handles from storage transparently. This could also avoid changing every profile.

Note this is only for *server* roles (e.g. PAS server, TIP server, PXP reporter etc.).

I'm not sure what you mean with synchronization. The attribute handles are to be stored when the service is registered (and you can't change them after registration).

Quoted 1 line

Do you have an RFC or a simple design description which will allow reviewing?

No. I am not working on this currently. This discussion started from an idea from Santiago to how to handle registration failures (see initial post), to which I responded that we may want first to address attribute handle storage to make sure handles stay the same during device lifetime (until it is factory reset).

Regards,

Signature · 3 lines
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil
#9 lore raw

Anderson,

Quoted 52 lines

-----Original Message-----
From: Anderson Lizardo [mailto:[email protected]]
Sent: Monday, December 05, 2011 1:37 PM
To: Ganir, Chen
Cc: Santiago Carot; [email protected]
Subject: Re: [PATCH 1/2] Provide return status in gatt_service_add function

Hi Chen,

Quoted 1 line · Chen

What do you mean restoring the attribute handles ? Each of the

profiles registers its own services when the plugin is loaded, according to the load order (which I assume will not change).

There is no guarantee in the load order. As we add more plugins, you can't predict the order the plugins will be loaded.

Quoted 1 line

When a profile registers its attributes, it can specify callbacks for

read/write which are actually function pointers. How to you plan to support this?

Only attribute *handles* are to be stored (for now). The mapping could be based on service+characteristic UUIDs (but we need to pay attention if we have multiple services with same service and characteristic UUIDs; for this case, I'm not even sure how the client knows which one to use).

Quoted 1 line

In addition, who will be responsible for reloading the database and

populating the values (profile plugin or bluetoothd core) ? how do you synchronize them?

My suggestion would be to implement this in attrib/gatt-service.c so gatt_service_add() could load attribute handles from storage transparently. This could also avoid changing every profile.

Note this is only for *server* roles (e.g. PAS server, TIP server, PXP reporter etc.).

I'm not sure what you mean with synchronization. The attribute handles are to be stored when the service is registered (and you can't change them after registration).

Quoted 1 line

Do you have an RFC or a simple design description which will allow

reviewing?

No. I am not working on this currently. This discussion started from an idea from Santiago to how to handle registration failures (see initial post), to which I responded that we may want first to address attribute handle storage to make sure handles stay the same during device lifetime (until it is factory reset).

Quoted 5 lines

Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

Thanks.

Chen Ganir.

#10 lore raw
In reply to Anderson Lizardo

Hi Chen, Lizardo,

2011/12/5 Anderson Lizardo <[email protected]>:

Quoted 8 lines

Hi Chen,

Quoted 1 line · Chen

What do you mean restoring the attribute handles ? Each of the profiles registers its own services when the plugin is loaded, according to the load order (which I assume will not change).

There is no guarantee in the load order. As we add more plugins, you can't predict the order the plugins will be loaded.

Quoted 8 lines
Quoted 1 line

When a profile registers its attributes, it can specify callbacks for read/write which are actually function pointers. How to you plan to support this?

Only attribute *handles* are to be stored (for now). The mapping could be based on service+characteristic UUIDs (but we need to pay attention if we have multiple services with same service and characteristic UUIDs; for this case, I'm not even sure how the client knows which one to use).

I was thinking in using a sort of server_id to distinguish between services registered among different plugins. That a first idea I have, I'm going to try to send a RFCs patches during these days. As always, I'll be updating my git repository at github if you want to follow my progress.

Quoted 13 lines
Quoted 1 line

In addition, who will be responsible for reloading the database and populating the values (profile plugin or bluetoothd core) ? how do you synchronize them?

My suggestion would be to implement this in attrib/gatt-service.c so gatt_service_add() could load attribute handles from storage transparently. This could also avoid changing every profile.

Note this is only for *server* roles (e.g. PAS server, TIP server, PXP reporter etc.).

I'm not sure what you mean with synchronization. The attribute handles are to be stored when the service is registered (and you can't change them after registration).

Quoted 8 lines
Quoted 1 line

Do you have an RFC or a simple design description which will allow reviewing?

No. I am not working on this currently. This discussion started from an idea from Santiago to how to handle registration failures (see initial post), to which I responded that we may want first to address attribute handle storage to make sure handles stay the same during device lifetime (until it is factory reset).

I'll put my hands on this issue.

Regards