[PATCH 1/2] android/gatt: Handle Register gatt client command

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

 



This adds register gatt client app command handling.
---
 android/gatt.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 62 insertions(+), 1 deletion(-)

diff --git a/android/gatt.c b/android/gatt.c
index ce85af4..f8f7208 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -31,6 +31,7 @@
 #include <glib.h>
 
 #include "ipc.h"
+#include "ipc-common.h"
 #include "lib/bluetooth.h"
 #include "gatt.h"
 #include "src/log.h"
@@ -38,13 +39,73 @@
 
 static struct ipc *hal_ipc = NULL;
 static bdaddr_t adapter_addr;
+static int32_t client_if_counter;
+
+struct gatt_client {
+	int32_t client_if;
+	uint8_t uuid[16];
+};
+
+GList *gatt_client_list = NULL;
+
+static int find_client_uuid(gconstpointer data, gconstpointer user_data)
+{
+	const uint8_t *exp_uuid = user_data;
+	const uint8_t *cur_uuid = ((struct gatt_client *)data)->uuid;
+	struct gatt_client *client;
+
+	if (memcmp(exp_uuid, cur_uuid, sizeof(client->uuid)))
+		return 1;
+
+	return 0;
+}
+
 
 static void handle_client_register(const void *buf, uint16_t len)
 {
+	const struct hal_cmd_gatt_client_register *cmd = buf;
+	struct hal_ev_gatt_client_register_client ev;
+	struct gatt_client *client;
+	GList *found_client_uuid;
+
 	DBG("");
 
+	if (!cmd->uuid) {
+		error("no uuid received");
+		goto failed;
+	}
+
+	found_client_uuid = g_list_find_custom(gatt_client_list,
+					&cmd->uuid, find_client_uuid);
+
+	if (found_client_uuid) {
+		error("client uuid is already on list");
+		goto failed;
+	}
+
+	client = g_new0(struct gatt_client, 1);
+	g_memmove(client->uuid, cmd->uuid, sizeof(client->uuid));
+
+	client->client_if = ++client_if_counter;
+
+	gatt_client_list = g_list_append(gatt_client_list, client);
+
 	ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT, HAL_OP_GATT_CLIENT_REGISTER,
-							HAL_STATUS_FAILED);
+							HAL_STATUS_SUCCESS);
+
+	ev.status = HAL_STATUS_SUCCESS;
+	ev.client_if = client->client_if;
+	g_memmove(ev.app_uuid, client->uuid, sizeof(client->uuid));
+
+	ipc_send_notif(hal_ipc, HAL_SERVICE_ID_GATT,
+			HAL_EV_GATT_CLIENT_REGISTER_CLIENT, sizeof(ev), &ev);
+
+	return;
+
+failed:
+	ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
+				HAL_OP_GATT_CLIENT_REGISTER, HAL_STATUS_FAILED);
+
 }
 
 static void handle_client_unregister(const void *buf, uint16_t len)
-- 
1.8.5.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