[PATCH 03/14] android/gatt: Fix sending callback in get_characteristic

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

 



Notification should be send to client in case of error.
---
 android/gatt.c | 50 +++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 37 insertions(+), 13 deletions(-)

diff --git a/android/gatt.c b/android/gatt.c
index fb29339..f16d365 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -2517,28 +2517,49 @@ reply:
 			HAL_OP_GATT_CLIENT_GET_INCLUDED_SERVICE, status);
 }
 
-static void send_client_char_notify(const struct characteristic *ch,
-					int32_t conn_id,
-					const struct service *service)
+static void send_client_char_notify(const struct hal_gatt_srvc_id *service,
+					const struct hal_gatt_gatt_id *charac,
+					int32_t char_prop, int32_t conn_id)
 {
 	struct hal_ev_gatt_client_get_characteristic ev;
 
-	memset(&ev, 0, sizeof(ev));
-	ev.status = ch ? GATT_SUCCESS : GATT_FAILURE;
+	ev.conn_id = conn_id;
 
-	if (ch) {
-		ev.char_prop = ch->ch.properties;
-		element_id_to_hal_gatt_id(&ch->id, &ev.char_id);
+	if (charac) {
+		memcpy(&ev.char_id, charac, sizeof(struct hal_gatt_gatt_id));
+		ev.char_prop = char_prop;
+		ev.status = GATT_SUCCESS;
+	} else {
+		memset(&ev.char_id, 0, sizeof(struct hal_gatt_gatt_id));
+		ev.char_prop = 0;
+		ev.status = GATT_FAILURE;
 	}
 
-	ev.conn_id = conn_id;
-	element_id_to_hal_srvc_id(&service->id, service->primary, &ev.srvc_id);
+	memcpy(&ev.srvc_id, service, sizeof(struct hal_gatt_srvc_id));
 
 	ipc_send_notif(hal_ipc, HAL_SERVICE_ID_GATT,
 					HAL_EV_GATT_CLIENT_GET_CHARACTERISTIC,
 					sizeof(ev), &ev);
 }
 
+static void convert_send_client_char_notify(const struct characteristic *ch,
+					int32_t conn_id,
+					const struct service *service)
+{
+	struct hal_gatt_srvc_id srvc;
+	struct hal_gatt_gatt_id charac;
+
+	element_id_to_hal_srvc_id(&service->id, service->primary, &srvc);
+
+	if (ch) {
+		element_id_to_hal_gatt_id(&ch->id, &charac);
+		send_client_char_notify(&srvc, &charac, ch->ch.properties,
+								conn_id);
+	} else {
+		send_client_char_notify(&srvc, NULL, 0, conn_id);
+	}
+}
+
 static void cache_all_srvc_chars(struct service *srvc, GSList *characteristics)
 {
 	uint16_t inst_id = 0;
@@ -2604,8 +2625,8 @@ static void discover_char_cb(uint8_t status, GSList *characteristics,
 	if (queue_isempty(srvc->chars))
 		cache_all_srvc_chars(srvc, characteristics);
 
-	send_client_char_notify(queue_peek_head(srvc->chars), data->conn_id,
-									srvc);
+	convert_send_client_char_notify(queue_peek_head(srvc->chars),
+							data->conn_id, srvc);
 
 	free(data);
 }
@@ -2671,11 +2692,14 @@ static void handle_client_get_characteristic(const void *buf, uint16_t len)
 	else
 		ch = queue_peek_head(srvc->chars);
 
-	send_client_char_notify(ch, conn->id, srvc);
+	convert_send_client_char_notify(ch, conn->id, srvc);
 
 	status = HAL_STATUS_SUCCESS;
 
 done:
+	if (status != HAL_STATUS_SUCCESS)
+		send_client_char_notify(&cmd->srvc_id, NULL, 0, cmd->conn_id);
+
 	ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
 				HAL_OP_GATT_CLIENT_GET_CHARACTERISTIC, status);
 }
-- 
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