[PATCH 2/6] android/gatt: Cache end handle for characteristics

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

 



---
 android/gatt.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/android/gatt.c b/android/gatt.c
index 59bcd23..67bb9b5 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -78,6 +78,7 @@ struct descriptor {
 struct characteristic {
 	struct element_id id;
 	struct gatt_char ch;
+	uint16_t end_handle;
 
 	struct queue *descriptors;
 };
@@ -1734,7 +1735,8 @@ static void send_client_char_notify(const struct characteristic *ch,
 					sizeof(ev), &ev);
 }
 
-static void cache_all_srvc_chars(GSList *characteristics, struct queue *q)
+static void cache_all_srvc_chars(struct service *srvc,
+							GSList *characteristics)
 {
 	uint16_t inst_id = 0;
 	bt_uuid_t uuid;
@@ -1765,7 +1767,16 @@ static void cache_all_srvc_chars(GSList *characteristics, struct queue *q)
 		 */
 		ch->id.instance = ++inst_id;
 
-		if (!queue_push_tail(q, ch)) {
+		/* Store end handle to use later for descriptors discovery */
+		if (characteristics->next) {
+			struct gatt_char *next = characteristics->next->data;
+			ch->end_handle = next->handle - 1;
+		} else {
+			ch->end_handle = srvc->primary ? srvc->prim.range.end :
+							srvc->incl.range.end;
+		}
+
+		if (!queue_push_tail(srvc->chars, ch)) {
 			error("gatt: Error while caching characteristic");
 			destroy_characteristic(ch);
 		}
@@ -1783,7 +1794,7 @@ static void discover_char_cb(uint8_t status, GSList *characteristics,
 	struct discover_char_data *data = user_data;
 
 	if (queue_isempty(data->service->chars))
-		cache_all_srvc_chars(characteristics, data->service->chars);
+		cache_all_srvc_chars(data->service, characteristics);
 
 	send_client_char_notify(queue_peek_head(data->service->chars),
 						data->conn_id, data->service);
-- 
1.9.2

--
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