All of lore.kernel.org
 help / color / mirror / Atom feed
* "Add Support for "Included Services" in Bluez"
       [not found] <CGME20180315144648epcas2p33469538b136a71c74b4dbb4796f349bf@epcas2p3.samsung.com>
@ 2018-03-15 14:45 ` avichal
       [not found]   ` <CGME20180315144716epcas1p4a2b031836b8c1977ed9c47edf4645f55@epcas1p4.samsung.com>
                     ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: avichal @ 2018-03-15 14:45 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: sachin.dev, anupam.r


Hi,

 Currently in bluez, Included Service support is under "Not Implemented" status

After adding support for the same in gatt-database, i am able to verify the operation as follows.

- Three primary services "1802","a00d","a00c" are created
- Further, the services "a00d" and "a00c" are included in "1802".

Following is the log showing Included services are added to Main service [using btgatt-client tool]
I will be submitting patches for the support in subsequent patches. Please review and share your opinion. Thanks.



pi@raspberrypi:~/Downloads/bluez-5.48/tools $ ./btgatt-client  -d 00:1B:DC:07:33:50
Connecting to device... Done
[GATT client]# Service Added - UUID: 00001800-0000-1000-8000-00805f9b34fb start: 0x0001 end: 0x0005
[GATT client]# Service Added - UUID: 00001801-0000-1000-8000-00805f9b34fb start: 0x0006 end: 0x0009
[GATT client]# Service Added - UUID: 0000a00d-0000-1000-8000-00805f9b34fb start: 0x005c end: 0x005f
[GATT client]# Service Added - UUID: 0000a00c-0000-1000-8000-00805f9b34fb start: 0x0060 end: 0x0063
[GATT client]# Service Added - UUID: 00001802-0000-1000-8000-00805f9b34fb start: 0x0064 end: 0x0069
[GATT client]# GATT discovery procedures complete
[GATT client]# 
service - start: 0x0001, end: 0x0005, type: primary, uuid: 00001800-0000-1000-8000-00805f9b34fb
	  charac - start: 0x0002, value: 0x0003, props: 0x02, ext_props: 0x0000, uuid: 00002a00-0000-1000-8000-00805f9b34fb
	  charac - start: 0x0004, value: 0x0005, props: 0x02, ext_props: 0x0000, uuid: 00002a01-0000-1000-8000-00805f9b34fb

service - start: 0x0006, end: 0x0009, type: primary, uuid: 00001801-0000-1000-8000-00805f9b34fb
	  charac - start: 0x0007, value: 0x0008, props: 0x20, ext_props: 0x0000, uuid: 00002a05-0000-1000-8000-00805f9b34fb
		  descr - handle: 0x0009, uuid: 00002902-0000-1000-8000-00805f9b34fb

service - start: 0x005c, end: 0x005f, type: primary, uuid: 0000a00d-0000-1000-8000-00805f9b34fb
	  charac - start: 0x005d, value: 0x005e, props: 0x04, ext_props: 0x0000, uuid: 00002b06-0000-1000-8000-00805f9b34fb
		  descr - handle: 0x005f, uuid: 0260c653-1a54-426b-9e36-e84c238bc669

service - start: 0x0060, end: 0x0063, type: primary, uuid: 0000a00c-0000-1000-8000-00805f9b34fb
	  charac - start: 0x0061, value: 0x0062, props: 0x04, ext_props: 0x0000, uuid: 00002c07-0000-1000-8000-00805f9b34fb
		  descr - handle: 0x0063, uuid: 0000ffff-0000-1000-8000-00805f9b34fb

service - start: 0x0064, end: 0x0069, type: primary, uuid: 00001802-0000-1000-8000-00805f9b34fb
	  include - handle: 0x0065, - start: 0x005c, end: 0x005f,uuid: 0000a00d-0000-1000-8000-00805f9b34fb
	  include - handle: 0x0066, - start: 0x0060, end: 0x0063,uuid: 0000a00c-0000-1000-8000-00805f9b34fb
	  charac - start: 0x0067, value: 0x0068, props: 0x04, ext_props: 0x0000, uuid: 00002a06-0000-1000-8000-00805f9b34fb
		  descr - handle: 0x0069, uuid: 8260c653-1a54-426b-9e36-e84c238bc669

[GATT client]# 




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

* [PATCH BlueZ 1/2] doc/gatt-api.txt: Add support for Included Service
       [not found]   ` <CGME20180315144716epcas1p4a2b031836b8c1977ed9c47edf4645f55@epcas1p4.samsung.com>
@ 2018-03-15 14:45     ` avichal
  0 siblings, 0 replies; 7+ messages in thread
From: avichal @ 2018-03-15 14:45 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: sachin.dev, anupam.r, avichal

included service support implemented at server side

Signed-off-by: avichal <avichal.a@samsung.com>
---
 doc/gatt-api.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/gatt-api.txt b/doc/gatt-api.txt
index ccf3a8b..9579381 100644
--- a/doc/gatt-api.txt
+++ b/doc/gatt-api.txt
@@ -45,7 +45,7 @@ Properties	string UUID [read-only]
 			belongs to. Only present on services from remote
 			devices.
 
-		array{object} Includes [read-only]: Not implemented
+		array{object} Includes [read-only]
 
 			Array of object paths representing the included
 			services of this service.
-- 
2.7.4


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

* [PATCH BlueZ 2/2] gatt-database : Add support for Included service
       [not found]   ` <CGME20180315144722epcas2p2761b6a90377b142efcf8a725af458810@epcas2p2.samsung.com>
@ 2018-03-15 14:45     ` avichal
  2018-03-16  8:08       ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 7+ messages in thread
From: avichal @ 2018-03-15 14:45 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: sachin.dev, anupam.r, avichal


Added support of included services in gatt server
While registring the service new property is added
"includes"

        array{object} type  [read-only]
        Array of object paths representing the included
        services of this service.

Signed-off-by: avichal <avichal.a@samsung.com>
---
 src/gatt-database.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 99 insertions(+), 1 deletion(-)

diff --git a/src/gatt-database.c b/src/gatt-database.c
index 9a33ae7..b2e93ce 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -109,6 +109,7 @@ struct external_service {
 	uint16_t attr_cnt;
 	struct queue *chrcs;
 	struct queue *descs;
+	struct queue *includes;
 };
 
 struct external_profile {
@@ -444,12 +445,21 @@ static void desc_free(void *data)
 	free(desc);
 }
 
+static void inc_free(void *data)
+{
+	struct external_desc *inc = data;
+
+	free(inc);
+}
+
+
 static void service_free(void *data)
 {
 	struct external_service *service = data;
 
 	queue_destroy(service->chrcs, chrc_free);
 	queue_destroy(service->descs, desc_free);
+	queue_destroy(service->includes,inc_free );
 
 	if (service->attrib)
 		gatt_db_remove_service(service->app->database->db,
@@ -1533,6 +1543,7 @@ static struct external_service *create_service(struct gatt_app *app,
 	service->proxy = g_dbus_proxy_ref(proxy);
 	service->chrcs = queue_new();
 	service->descs = queue_new();
+	service->includes = queue_new();
 
 	/* Add 1 for the service declaration */
 	if (!incr_attr_count(service, 1)) {
@@ -1616,6 +1627,44 @@ static bool parse_uuid(GDBusProxy *proxy, bt_uuid_t *uuid)
 	return true;
 }
 
+
+static bool parse_includes(GDBusProxy *proxy, struct external_service * service)
+{
+	DBusMessageIter iter;
+	DBusMessageIter array;
+	char *obj;
+
+	if (!g_dbus_proxy_get_property(proxy, "Includes", &iter))
+		return false;
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
+		return false;
+
+	dbus_message_iter_recurse(&iter, &array);
+
+
+	do {
+		if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_OBJECT_PATH)
+			return false;
+
+		dbus_message_iter_get_basic(&array, &obj);
+
+		if(queue_push_tail(service->includes,obj)){
+			DBG("Included paths added\n");
+			incr_attr_count(service ,1);
+		}
+		else{
+			error("Failed to add Includes path in que\n");
+			return FALSE;
+		}
+
+	} while (dbus_message_iter_next(&array));
+
+
+	return true;
+}
+
+
 static bool parse_primary(GDBusProxy *proxy, bool *primary)
 {
 	DBusMessageIter iter;
@@ -2488,6 +2537,46 @@ fail:
 	gatt_db_attribute_write_result(attrib, id, BT_ATT_ERROR_UNLIKELY);
 }
 
+
+
+static void include_services(void * data ,void *userdata)
+{
+	char *obj = (char*)data;
+	struct external_service * service = (struct external_service *)userdata;
+	struct gatt_db_attribute *attrib=NULL;
+	struct external_service  *service_inc=NULL;
+
+	DBG("object path recieved %s,",obj);
+
+	service_inc = queue_find(service->app->services, match_service_by_path, obj);
+	if(service_inc)	{
+
+		if(!(service)->attrib)
+			error("service attibute not found\n");
+
+
+		if(!service_inc->attrib)
+			error("include attribute not found\n");
+
+
+		attrib = gatt_db_service_add_included((service)->attrib ,service_inc ->attrib);
+		if(attrib == NULL)
+			error("include service attributes failed \n");
+
+		else
+			(service)->attrib = attrib;
+
+	}
+	else
+		error("include service not found\n");
+
+}
+
+static void database_add_includes(struct external_service *service)
+{
+	queue_foreach(service->includes,include_services,service );
+}
+
 static bool database_add_chrc(struct external_service *service,
 						struct external_chrc *chrc)
 {
@@ -2560,11 +2649,20 @@ static bool database_add_service(struct external_service *service)
 		return false;
 	}
 
+
+	if(!parse_includes(service->proxy,service)){
+		error("Failed to read \"Includes\" property of service");
+	}
+
 	service->attrib = gatt_db_add_service(service->app->database->db, &uuid,
-						primary, service->attr_cnt);
+					primary, service->attr_cnt);
 	if (!service->attrib)
 		return false;
 
+	database_add_includes(service);
+	DBG("ATTR count %d\n",service->attr_cnt);
+
+
 	entry = queue_get_entries(service->chrcs);
 	while (entry) {
 		struct external_chrc *chrc = entry->data;
-- 
2.7.4


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

* [PATCH BlueZ] tools/gatt-service: Add reference implementation for Included Service
       [not found]   ` <CGME20180315144724epcas1p4ea57deffd99cd3ac2bb1e3c6f51445b6@epcas1p4.samsung.com>
@ 2018-03-15 14:45     ` avichal
  0 siblings, 0 replies; 7+ messages in thread
From: avichal @ 2018-03-15 14:45 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: sachin.dev, anupam.r, avichal

Created two new primary services which will act as includes services for
first  primary service

Signed-off-by: avichal <avichal.a@samsung.com>
---
 tools/gatt-service.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 94 insertions(+), 2 deletions(-)

diff --git a/tools/gatt-service.c b/tools/gatt-service.c
index 6bd5576..379c120 100644
--- a/tools/gatt-service.c
+++ b/tools/gatt-service.c
@@ -47,9 +47,17 @@
 /* Immediate Alert Service UUID */
 #define IAS_UUID			"00001802-0000-1000-8000-00805f9b34fb"
 #define ALERT_LEVEL_CHR_UUID		"00002a06-0000-1000-8000-00805f9b34fb"
+#define IAS_UUID1   "A00B"
+#define IAS_UUID2   "A00C"
+#define IAS_UUID3   "A00D"
+#define ALERT_LEVEL_CHR_UUID1		"00002b06-0000-1000-8000-00805f9b34fb"
+#define ALERT_LEVEL_CHR_UUID2		"00002c07-0000-1000-8000-00805f9b34fb"
+/* Random UUID for testing purpose */
 
 /* Random UUID for testing purpose */
 #define READ_WRITE_DESCRIPTOR_UUID	"8260c653-1a54-426b-9e36-e84c238bc669"
+#define READ_WRITE_DESCRIPTOR_UUID1 "0260c653-1a54-426b-9e36-e84c238bc669"
+#define READ_WRITE_DESCRIPTOR_UUID2 "FFFF"
 
 static GMainLoop *main_loop;
 static GSList *services;
@@ -335,18 +343,47 @@ static gboolean service_get_includes(const GDBusPropertyTable *property,
 					DBusMessageIter *iter, void *user_data)
 {
 	const char *uuid = user_data;
+	char service_path[100] = {0,};
+	DBusMessageIter array;
+	char *p = NULL;
 
+	snprintf(service_path,100,"/service3");
 	printf("Get Includes: %s\n", uuid);
 
+	p = service_path;
+
+	printf("Includes path: %s\n", p);
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
+			DBUS_TYPE_OBJECT_PATH_AS_STRING, &array);
+
+	dbus_message_iter_append_basic(&array, DBUS_TYPE_OBJECT_PATH,
+							&p);
+
+	snprintf(service_path,100,"/service2");
+	p = service_path;
+	printf("Get Includes: %s\n", p);
+
+	dbus_message_iter_append_basic(&array, DBUS_TYPE_OBJECT_PATH,
+							&p);
+	dbus_message_iter_close_container(iter, &array);
+
+
 	return TRUE;
+
 }
 
+
 static gboolean service_exist_includes(const GDBusPropertyTable *property,
 							void *user_data)
 {
 	const char *uuid = user_data;
 
 	printf("Exist Includes: %s\n", uuid);
+	if(strncmp(uuid,"00001802",8) == 0)
+	{
+		return TRUE;
+	}
 
 	return FALSE;
 }
@@ -624,7 +661,7 @@ static char *register_service(const char *uuid)
 	return path;
 }
 
-static void create_services()
+static void create_services_one()
 {
 	char *service_path;
 	uint8_t level = 0;
@@ -651,6 +688,59 @@ static void create_services()
 	printf("Registered service: %s\n", service_path);
 }
 
+
+static void create_services_two()
+{
+	char *service_path;
+	uint8_t level = 0;
+
+	service_path = register_service(IAS_UUID2);
+	if (!service_path)
+		return;
+
+	if (!register_characteristic(ALERT_LEVEL_CHR_UUID2,
+						&level, sizeof(level),
+						ias_alert_level_props,
+						READ_WRITE_DESCRIPTOR_UUID2,
+						desc_props,
+						service_path)) {
+		printf("Couldn't register Alert Level characteristic (IAS)\n");
+		g_dbus_unregister_interface(connection, service_path,
+							GATT_SERVICE_IFACE);
+		g_free(service_path);
+		return;
+	}
+	services = g_slist_prepend(services, service_path);
+	printf("Registered service: %s\n", service_path);
+}
+
+static void create_services_three()
+{
+	char *service_path;
+	uint8_t level = 0;
+
+	service_path = register_service(IAS_UUID3);
+	if (!service_path)
+		return;
+
+	if (!register_characteristic(ALERT_LEVEL_CHR_UUID1,
+						&level, sizeof(level),
+						ias_alert_level_props,
+						READ_WRITE_DESCRIPTOR_UUID1,
+						desc_props,
+						service_path)) {
+		printf("Couldn't register Alert Level characteristic (IAS)\n");
+		g_dbus_unregister_interface(connection, service_path,
+							GATT_SERVICE_IFACE);
+		g_free(service_path);
+		return;
+	}
+
+
+	services = g_slist_prepend(services, service_path);
+	printf("Registered service: %s\n", service_path);
+}
+
 static void register_app_reply(DBusMessage *reply, void *user_data)
 {
 	DBusError derr;
@@ -789,7 +879,9 @@ int main(int argc, char *argv[])
 	printf("gatt-service unique name: %s\n",
 				dbus_bus_get_unique_name(connection));
 
-	create_services();
+	create_services_one();
+	create_services_two();
+	create_services_three();
 
 	client = g_dbus_client_new(connection, "org.bluez", "/");
 
-- 
2.7.4


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

* Re: [PATCH BlueZ 2/2] gatt-database : Add support for Included service
  2018-03-15 14:45     ` [PATCH BlueZ 2/2] gatt-database : Add support for Included service avichal
@ 2018-03-16  8:08       ` Luiz Augusto von Dentz
       [not found]         ` <CGME20180316131046epcas1p1016f3684a15ae62cfce0cecef9d6a5c4@epcas1p1.samsung.com>
  0 siblings, 1 reply; 7+ messages in thread
From: Luiz Augusto von Dentz @ 2018-03-16  8:08 UTC (permalink / raw)
  To: avichal; +Cc: linux-bluetooth, sachin.dev, Anupam Roy

Hi avichal,

On Thu, Mar 15, 2018 at 4:45 PM, avichal <avichal.a@samsung.com> wrote:
>
> Added support of included services in gatt server
> While registring the service new property is added
> "includes"
>
>         array{object} type  [read-only]
>         Array of object paths representing the included
>         services of this service.
>
> Signed-off-by: avichal <avichal.a@samsung.com>

We do not use Signed-off-by in userspace.

> ---
>  src/gatt-database.c | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 99 insertions(+), 1 deletion(-)
>
> diff --git a/src/gatt-database.c b/src/gatt-database.c
> index 9a33ae7..b2e93ce 100644
> --- a/src/gatt-database.c
> +++ b/src/gatt-database.c
> @@ -109,6 +109,7 @@ struct external_service {
>         uint16_t attr_cnt;
>         struct queue *chrcs;
>         struct queue *descs;
> +       struct queue *includes;
>  };
>
>  struct external_profile {
> @@ -444,12 +445,21 @@ static void desc_free(void *data)
>         free(desc);
>  }
>
> +static void inc_free(void *data)
> +{
> +       struct external_desc *inc = data;
> +
> +       free(inc);
> +}
> +

Extra line empty, please remove it.

>  static void service_free(void *data)
>  {
>         struct external_service *service = data;
>
>         queue_destroy(service->chrcs, chrc_free);
>         queue_destroy(service->descs, desc_free);
> +       queue_destroy(service->includes,inc_free );
>
>         if (service->attrib)
>                 gatt_db_remove_service(service->app->database->db,
> @@ -1533,6 +1543,7 @@ static struct external_service *create_service(struct gatt_app *app,
>         service->proxy = g_dbus_proxy_ref(proxy);
>         service->chrcs = queue_new();
>         service->descs = queue_new();
> +       service->includes = queue_new();
>
>         /* Add 1 for the service declaration */
>         if (!incr_attr_count(service, 1)) {
> @@ -1616,6 +1627,44 @@ static bool parse_uuid(GDBusProxy *proxy, bt_uuid_t *uuid)
>         return true;
>  }
>
> +
> +static bool parse_includes(GDBusProxy *proxy, struct external_service * service)
> +{
> +       DBusMessageIter iter;
> +       DBusMessageIter array;
> +       char *obj;
> +
> +       if (!g_dbus_proxy_get_property(proxy, "Includes", &iter))
> +               return false;
> +
> +       if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
> +               return false;
> +
> +       dbus_message_iter_recurse(&iter, &array);
> +

Ditto.

> +       do {
> +               if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_OBJECT_PATH)
> +                       return false;
> +
> +               dbus_message_iter_get_basic(&array, &obj);
> +
> +               if(queue_push_tail(service->includes,obj)){
> +                       DBG("Included paths added\n");
> +                       incr_attr_count(service ,1);
> +               }
> +               else{
> +                       error("Failed to add Includes path in que\n");
> +                       return FALSE;
> +               }

Always use a space after if statement, e.g if (cond), also the else
should be in the same like as in the closing }, like in } else {.

> +
> +       } while (dbus_message_iter_next(&array));
> +
> +
> +       return true;
> +}
> +
> +
>  static bool parse_primary(GDBusProxy *proxy, bool *primary)
>  {
>         DBusMessageIter iter;
> @@ -2488,6 +2537,46 @@ fail:
>         gatt_db_attribute_write_result(attrib, id, BT_ATT_ERROR_UNLIKELY);
>  }
>

Again, please remove extra empty lines.

> +
> +static void include_services(void * data ,void *userdata)
> +{
> +       char *obj = (char*)data;
> +       struct external_service * service = (struct external_service *)userdata;
> +       struct gatt_db_attribute *attrib=NULL;
> +       struct external_service  *service_inc=NULL;
> +
> +       DBG("object path recieved %s,",obj);
> +
> +       service_inc = queue_find(service->app->services, match_service_by_path, obj);
> +       if(service_inc) {
> +
> +               if(!(service)->attrib)
> +                       error("service attibute not found\n");
> +

Ditto.

> +               if(!service_inc->attrib)
> +                       error("include attribute not found\n");
> +

Ditto.

> +               attrib = gatt_db_service_add_included((service)->attrib ,service_inc ->attrib);
> +               if(attrib == NULL)
> +                       error("include service attributes failed \n");
> +
> +               else
> +                       (service)->attrib = attrib;
> +
> +       }
> +       else
> +               error("include service not found\n");
> +
> +}
> +
> +static void database_add_includes(struct external_service *service)
> +{
> +       queue_foreach(service->includes,include_services,service );
> +}
> +
>  static bool database_add_chrc(struct external_service *service,
>                                                 struct external_chrc *chrc)
>  {
> @@ -2560,11 +2649,20 @@ static bool database_add_service(struct external_service *service)
>                 return false;
>         }
>

Ditto,

> +       if(!parse_includes(service->proxy,service)){
> +               error("Failed to read \"Includes\" property of service");
> +       }
> +
>         service->attrib = gatt_db_add_service(service->app->database->db, &uuid,
> -                                               primary, service->attr_cnt);
> +                                       primary, service->attr_cnt);
>         if (!service->attrib)
>                 return false;
>
> +       database_add_includes(service);
> +       DBG("ATTR count %d\n",service->attr_cnt);
> +

Ditto.

>         entry = queue_get_entries(service->chrcs);
>         while (entry) {
>                 struct external_chrc *chrc = entry->data;
> --
> 2.7.4

There are probably more code style problems that I miss, but you can
prevent this errors by having checkpatch.pl on your pre-commit and
pre-applypatch hooks like this:

exec git diff --cached | /pathto/checkpatch.pl -q --no-signoff
--ignore INITIALISED_STATIC,GLOBAL_INITIALISERS,PREFER_PACKED,SPACING,FSF_MAILING_ADDRESS,TRAILING_STATEMENTS,RETURN_VOID,,SPLIT_STRING,OPEN_BRACE,STATIC_CONST_CHAR_ARRAY,LINE_SPACING
 --show-types -

-- 
Luiz Augusto von Dentz

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

* [PATCH BlueZ 2/2] gatt-database: Add support for Included service
       [not found]         ` <CGME20180316131046epcas1p1016f3684a15ae62cfce0cecef9d6a5c4@epcas1p1.samsung.com>
@ 2018-03-16 13:09           ` avichal
  2018-03-19 11:51             ` Johan Hedberg
  0 siblings, 1 reply; 7+ messages in thread
From: avichal @ 2018-03-16 13:09 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: sachin.dev, anupam.r, avichal

Add support of included services in gatt server.While
registring the service new property is added
"includes"
        array{object} type  [read-only]
        Array of object paths representing the included
        services of this service.
---
 src/gatt-database.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)

diff --git a/src/gatt-database.c b/src/gatt-database.c
index 9a33ae7..d1acc65 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -109,6 +109,7 @@ struct external_service {
 	uint16_t attr_cnt;
 	struct queue *chrcs;
 	struct queue *descs;
+	struct queue *includes;
 };
 
 struct external_profile {
@@ -444,12 +445,20 @@ static void desc_free(void *data)
 	free(desc);
 }
 
+static void inc_free(void *data)
+{
+	struct external_desc *inc = data;
+
+	free(inc);
+}
+
 static void service_free(void *data)
 {
 	struct external_service *service = data;
 
 	queue_destroy(service->chrcs, chrc_free);
 	queue_destroy(service->descs, desc_free);
+	queue_destroy(service->includes,inc_free );
 
 	if (service->attrib)
 		gatt_db_remove_service(service->app->database->db,
@@ -1533,6 +1542,7 @@ static struct external_service *create_service(struct gatt_app *app,
 	service->proxy = g_dbus_proxy_ref(proxy);
 	service->chrcs = queue_new();
 	service->descs = queue_new();
+	service->includes = queue_new();
 
 	/* Add 1 for the service declaration */
 	if (!incr_attr_count(service, 1)) {
@@ -1616,6 +1626,39 @@ static bool parse_uuid(GDBusProxy *proxy, bt_uuid_t *uuid)
 	return true;
 }
 
+static bool parse_includes(GDBusProxy *proxy, struct external_service *service)
+{
+	DBusMessageIter iter;
+	DBusMessageIter array;
+	char *obj;
+
+	if (!g_dbus_proxy_get_property(proxy, "Includes", &iter))
+		return false;
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
+		return false;
+
+	dbus_message_iter_recurse(&iter, &array);
+
+	do {
+		if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_OBJECT_PATH)
+			return false;
+
+		dbus_message_iter_get_basic(&array, &obj);
+
+		if (queue_push_tail(service->includes,obj)){
+			DBG("Included paths added\n");
+			incr_attr_count(service ,1);
+		}else {
+			error("Failed to add Includes path in que\n");
+			return FALSE;
+		}
+
+	} while (dbus_message_iter_next(&array));
+
+	return true;
+}
+
 static bool parse_primary(GDBusProxy *proxy, bool *primary)
 {
 	DBusMessageIter iter;
@@ -2488,6 +2531,40 @@ fail:
 	gatt_db_attribute_write_result(attrib, id, BT_ATT_ERROR_UNLIKELY);
 }
 
+static void include_services(void *data ,void *userdata)
+{
+	char *obj = (char *)data;
+	struct external_service *service = (struct external_service *)userdata;
+	struct gatt_db_attribute *attrib=NULL;
+	struct external_service  *service_inc=NULL;
+
+	DBG("object path receieved %s,",obj);
+
+	service_inc = queue_find(service->app->services, match_service_by_path, obj);
+	if(service_inc)	{
+
+		if (!(service)->attrib)
+			error("service attibute not found\n");
+
+		if (!service_inc->attrib)
+			error("include attribute not found\n");
+
+		attrib = gatt_db_service_add_included((service)->attrib ,service_inc->attrib);
+		if (attrib == NULL)
+			error("include service attributes failed\n");
+		else
+			(service)->attrib = attrib;
+
+	} else
+		error("include service not found\n");
+
+}
+
+static void database_add_includes(struct external_service *service)
+{
+	queue_foreach(service->includes,include_services,service );
+}
+
 static bool database_add_chrc(struct external_service *service,
 						struct external_chrc *chrc)
 {
@@ -2560,11 +2637,17 @@ static bool database_add_service(struct external_service *service)
 		return false;
 	}
 
+	if (!parse_includes(service->proxy,service))
+		error("Failed to read \"Includes\" property of service");
+
 	service->attrib = gatt_db_add_service(service->app->database->db, &uuid,
 						primary, service->attr_cnt);
 	if (!service->attrib)
 		return false;
 
+	database_add_includes(service);
+	DBG("ATTR count %d\n",service->attr_cnt);
+
 	entry = queue_get_entries(service->chrcs);
 	while (entry) {
 		struct external_chrc *chrc = entry->data;
-- 
2.7.4


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

* Re: [PATCH BlueZ 2/2] gatt-database: Add support for Included service
  2018-03-16 13:09           ` [PATCH BlueZ 2/2] gatt-database: " avichal
@ 2018-03-19 11:51             ` Johan Hedberg
  0 siblings, 0 replies; 7+ messages in thread
From: Johan Hedberg @ 2018-03-19 11:51 UTC (permalink / raw)
  To: avichal; +Cc: linux-bluetooth, sachin.dev, anupam.r

Hi Avichal,

On Fri, Mar 16, 2018, avichal wrote:
> Add support of included services in gatt server.While
> registring the service new property is added
> "includes"
>         array{object} type  [read-only]
>         Array of object paths representing the included
>         services of this service.
> ---
>  src/gatt-database.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 83 insertions(+)

Please fix your git author information to be of the format "Firstname
Lastname <email>". We don't generally accept patches with a username or
just the first name. Some have slipped through in the past, and for that
we have the .mailmap file in the tree - I don't think you want an entry
for yourself there ;)

Johan

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

end of thread, other threads:[~2018-03-19 11:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20180315144648epcas2p33469538b136a71c74b4dbb4796f349bf@epcas2p3.samsung.com>
2018-03-15 14:45 ` "Add Support for "Included Services" in Bluez" avichal
     [not found]   ` <CGME20180315144716epcas1p4a2b031836b8c1977ed9c47edf4645f55@epcas1p4.samsung.com>
2018-03-15 14:45     ` [PATCH BlueZ 1/2] doc/gatt-api.txt: Add support for Included Service avichal
     [not found]   ` <CGME20180315144722epcas2p2761b6a90377b142efcf8a725af458810@epcas2p2.samsung.com>
2018-03-15 14:45     ` [PATCH BlueZ 2/2] gatt-database : Add support for Included service avichal
2018-03-16  8:08       ` Luiz Augusto von Dentz
     [not found]         ` <CGME20180316131046epcas1p1016f3684a15ae62cfce0cecef9d6a5c4@epcas1p1.samsung.com>
2018-03-16 13:09           ` [PATCH BlueZ 2/2] gatt-database: " avichal
2018-03-19 11:51             ` Johan Hedberg
     [not found]   ` <CGME20180315144724epcas1p4ea57deffd99cd3ac2bb1e3c6f51445b6@epcas1p4.samsung.com>
2018-03-15 14:45     ` [PATCH BlueZ] tools/gatt-service: Add reference implementation for Included Service avichal

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.