[PATCH 4/6] shared/gatt: Add Secondary services to service_list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If included service was found and doesn't exist on service list,
create Secondary Service and insert it.
---
 src/shared/gatt-client.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 16b1630..54e6fec 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -471,6 +471,7 @@ static void discover_incl_cb(bool success, uint8_t att_ecode,
 						&includes[i].start_handle,
 						&includes[i].end_handle,
 						includes[i].uuid)) {
+		struct service_list *service;
 		uuid_to_string(includes[i].uuid, uuid_str);
 		util_debug(client->debug_callback, client->debug_data,
 				"handle: 0x%04x, start: 0x%04x, end: 0x%04x,"
@@ -478,7 +479,56 @@ static void discover_incl_cb(bool success, uint8_t att_ecode,
 				includes[i].start_handle,
 				includes[i].end_handle, uuid_str);
 
-		/* TODO check if included service is on list */
+
+		/*
+		 * Check if included service was found previously in this
+		 * session
+		 */
+		for (service = op->result_head; service; service =
+								service->next) {
+			if (service->service.start_handle ==
+						includes[i].start_handle)
+				break;
+		}
+
+		/*
+		 * Check if included service was found in previous session
+		 */
+		if (!service) {
+			for (service = client->svc_head; service; service =
+								service->next) {
+				if (service->service.start_handle ==
+						includes[i].start_handle)
+					break;
+			}
+		}
+
+		if (!service) {
+			service = new0(struct service_list, 1);
+			if (!service) {
+				free(includes);
+				success = false;
+				goto done;
+			}
+
+			service->service.primary = false;
+			service->service.start_handle =
+						includes[i].start_handle;
+			service->service.end_handle = includes[i].end_handle;
+			memcpy(service->service.uuid, includes[i].uuid,
+								UUID_BYTES);
+
+			service_list_insert_services(&op->result_head,
+							&op->result_tail,
+							service, service);
+
+			/*
+			 * TODO: Newly created Secondary Service can contain
+			 * Included Services too. They should be discovered
+			 * before characteristic discovery.
+			 */
+		}
+
 		i++;
 	}
 
-- 
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux