Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 1/4] android/gatt: Unify read by type and read by group type
@ 2014-11-26  8:47 Jakub Tyszkowski
  2014-11-26  8:47 ` [PATCH 2/4] android/gatt: Improve prepare write request response Jakub Tyszkowski
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Jakub Tyszkowski @ 2014-11-26  8:47 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Jakub Tyszkowski

These two functions were veary similar but inconsisten in used error
codes and freeing allocated data.
---
 android/gatt.c | 89 ++++++++++++++++++----------------------------------------
 1 file changed, 27 insertions(+), 62 deletions(-)

diff --git a/android/gatt.c b/android/gatt.c
index 092473c..6d79e61 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -5895,71 +5895,27 @@ static const struct ipc_handler cmd_handlers[] = {
 		sizeof(struct hal_cmd_gatt_client_read_batchscan_reports) },
 };
 
-static uint8_t read_by_group_type(const uint8_t *cmd, uint16_t cmd_len,
-						struct gatt_device *device)
-{
-	uint16_t start, end;
-	int len;
-	bt_uuid_t uuid;
-	struct queue *q;
-
-	len = dec_read_by_grp_req(cmd, cmd_len, &start, &end, &uuid);
-	if (!len)
-		return ATT_ECODE_INVALID_PDU;
-
-	if (start > end || start == 0)
-		return ATT_ECODE_INVALID_HANDLE;
-
-	q = queue_new();
-	if (!q)
-		return ATT_ECODE_INSUFF_RESOURCES;
-
-	gatt_db_read_by_group_type(gatt_db, start, end, uuid, q);
-
-	if (queue_isempty(q)) {
-		queue_destroy(q, NULL);
-		return ATT_ECODE_ATTR_NOT_FOUND;
-	}
-
-	while (queue_peek_head(q)) {
-		struct gatt_db_attribute *attrib = queue_pop_head(q);
-		struct pending_request *entry;
-
-		entry = new0(struct pending_request, 1);
-		if (!entry) {
-			queue_destroy(q, destroy_pending_request);
-			return ATT_ECODE_UNLIKELY;
-		}
-
-		entry->attrib = attrib;
-		entry->state = REQUEST_INIT;
-
-		if (!queue_push_tail(device->pending_requests, entry)) {
-			queue_remove_all(device->pending_requests, NULL, NULL,
-						destroy_pending_request);
-			free(entry);
-			queue_destroy(q, NULL);
-			return ATT_ECODE_UNLIKELY;
-		}
-	}
-
-	queue_destroy(q, NULL);
-	process_dev_pending_requests(device, cmd[0]);
-
-	return 0;
-}
-
 static uint8_t read_by_type(const uint8_t *cmd, uint16_t cmd_len,
 						struct gatt_device *device)
 {
 	uint16_t start, end;
-	uint16_t len;
+	uint16_t len = 0;
 	bt_uuid_t uuid;
 	struct queue *q;
 
 	DBG("");
 
-	len = dec_read_by_type_req(cmd, cmd_len, &start, &end, &uuid);
+	switch (cmd[0]) {
+	case ATT_OP_READ_BY_TYPE_REQ:
+		len = dec_read_by_type_req(cmd, cmd_len, &start, &end, &uuid);
+		break;
+	case ATT_OP_READ_BY_GROUP_REQ:
+		len = dec_read_by_grp_req(cmd, cmd_len, &start, &end, &uuid);
+		break;
+	default:
+		break;
+	}
+
 	if (!len)
 		return ATT_ECODE_INVALID_PDU;
 
@@ -5970,7 +5926,16 @@ static uint8_t read_by_type(const uint8_t *cmd, uint16_t cmd_len,
 	if (!q)
 		return ATT_ECODE_INSUFF_RESOURCES;
 
-	gatt_db_read_by_type(gatt_db, start, end, uuid, q);
+	switch (cmd[0]) {
+	case ATT_OP_READ_BY_TYPE_REQ:
+		gatt_db_read_by_type(gatt_db, start, end, uuid, q);
+		break;
+	case ATT_OP_READ_BY_GROUP_REQ:
+		gatt_db_read_by_group_type(gatt_db, start, end, uuid, q);
+		break;
+	default:
+		break;
+	}
 
 	if (queue_isempty(q)) {
 		queue_destroy(q, NULL);
@@ -5989,13 +5954,15 @@ static uint8_t read_by_type(const uint8_t *cmd, uint16_t cmd_len,
 
 		data->state = REQUEST_INIT;
 		data->attrib = attrib;
-		if (!queue_push_tail(device->pending_requests, data))
+		if (!queue_push_tail(device->pending_requests, data)) {
 			free(data);
+			queue_destroy(q, NULL);
+			return ATT_ECODE_INSUFF_RESOURCES;
+		}
 	}
 
 	queue_destroy(q, NULL);
-
-	process_dev_pending_requests(device, ATT_OP_READ_BY_TYPE_REQ);
+	process_dev_pending_requests(device, cmd[0]);
 
 	return 0;
 }
@@ -6518,8 +6485,6 @@ static void att_handler(const uint8_t *ipdu, uint16_t len, gpointer user_data)
 
 	switch (ipdu[0]) {
 	case ATT_OP_READ_BY_GROUP_REQ:
-		status = read_by_group_type(ipdu, len, dev);
-		break;
 	case ATT_OP_READ_BY_TYPE_REQ:
 		status = read_by_type(ipdu, len, dev);
 		break;
-- 
1.9.1


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

end of thread, other threads:[~2014-12-01 11:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-26  8:47 [PATCH 1/4] android/gatt: Unify read by type and read by group type Jakub Tyszkowski
2014-11-26  8:47 ` [PATCH 2/4] android/gatt: Improve prepare write request response Jakub Tyszkowski
2014-11-26  8:47 ` [PATCH 3/4] android/gatt: Fix improper signed write request decoding buffer size Jakub Tyszkowski
2014-11-26  8:47 ` [PATCH 4/4] android/gatt: Set proper MTU for BR/EDR link Jakub Tyszkowski
2014-11-26 12:44   ` Johan Hedberg
2014-11-27  7:58     ` Tyszkowski Jakub
2014-12-01 11:45 ` [PATCH 1/4] android/gatt: Unify read by type and read by group type Szymon Janc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox