linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/3] android/gatt: Remove redundant hal cmd check
@ 2014-04-01 12:54 Grzegorz Kolodziejczyk
  2014-04-01 12:54 ` [PATCH v2 2/3] android/gatt: Handle register gatt server command Grzegorz Kolodziejczyk
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-04-01 12:54 UTC (permalink / raw)
  To: linux-bluetooth

This removes redundant hal cmd check (is received in cmd UUID == NULL).
---
 android/gatt.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/android/gatt.c b/android/gatt.c
index 941582a..ee77a4e 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -350,12 +350,6 @@ static void handle_client_register(const void *buf, uint16_t len)
 
 	DBG("");
 
-	if (!cmd->uuid) {
-		error("gatt: no uuid received");
-		status = HAL_STATUS_FAILED;
-		goto failed;
-	}
-
 	if (queue_find(gatt_clients, match_client_by_uuid, &cmd->uuid)) {
 		error("gatt: client uuid is already on list");
 		status = HAL_STATUS_FAILED;
-- 
1.9.1


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

* [PATCH v2 2/3] android/gatt: Handle register gatt server command
  2014-04-01 12:54 [PATCH v2 1/3] android/gatt: Remove redundant hal cmd check Grzegorz Kolodziejczyk
@ 2014-04-01 12:54 ` Grzegorz Kolodziejczyk
  2014-04-01 12:54 ` [PATCH v2 3/3] android/gatt: Handle unregister " Grzegorz Kolodziejczyk
  2014-04-01 13:56 ` [PATCH v2 1/3] android/gatt: Remove redundant hal cmd check Szymon Janc
  2 siblings, 0 replies; 4+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-04-01 12:54 UTC (permalink / raw)
  To: linux-bluetooth

This adds register gatt server command handling.
---
 android/gatt.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 75 insertions(+), 2 deletions(-)

diff --git a/android/gatt.c b/android/gatt.c
index ee77a4e..fb4d9d1 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -57,6 +57,11 @@ struct gatt_client {
 	struct queue *notifications;
 };
 
+struct gatt_server {
+	int32_t id;
+	uint8_t uuid[16];
+};
+
 struct element_id {
 	bt_uuid_t uuid;
 	uint8_t instance;
@@ -105,6 +110,7 @@ static bdaddr_t adapter_addr;
 static bool scanning = false;
 
 static struct queue *gatt_clients = NULL;
+static struct queue *gatt_servers = NULL;
 static struct queue *conn_list	= NULL;		/* Connected devices */
 static struct queue *conn_wait_queue = NULL;	/* Devs waiting to connect */
 
@@ -184,6 +190,14 @@ static bool match_client_by_uuid(const void *data, const void *user_data)
 	return !memcmp(exp_uuid, client->uuid, sizeof(client->uuid));
 }
 
+static bool match_server_by_uuid(const void *data, const void *user_data)
+{
+	const uint8_t *exp_uuid = user_data;
+	const struct gatt_server *server = data;
+
+	return !memcmp(exp_uuid, server->uuid, sizeof(server->uuid));
+}
+
 static bool match_client_by_id(const void *data, const void *user_data)
 {
 	int32_t exp_id = PTR_TO_INT(user_data);
@@ -340,6 +354,13 @@ static void destroy_gatt_client(void *data)
 	free(client);
 }
 
+static void destroy_gatt_server(void *data)
+{
+	struct gatt_server *server = data;
+
+	free(server);
+}
+
 static void handle_client_register(const void *buf, uint16_t len)
 {
 	const struct hal_cmd_gatt_client_register *cmd = buf;
@@ -1874,10 +1895,55 @@ static void handle_client_test_command(const void *buf, uint16_t len)
 
 static void handle_server_register(const void *buf, uint16_t len)
 {
+	const struct hal_cmd_gatt_server_register *cmd = buf;
+	struct hal_ev_gatt_server_register ev;
+	struct gatt_server *server;
+	static int32_t server_cnt = 1;
+	uint32_t status;
+
 	DBG("");
 
+	memset(&ev, 0, sizeof(ev));
+
+	if (queue_find(gatt_servers, match_server_by_uuid, &cmd->uuid)) {
+		error("gatt: Server uuid is already on list");
+		status = HAL_STATUS_FAILED;
+		goto failed;
+	}
+
+	server = new0(struct gatt_server, 1);
+	if (!server) {
+		error("gatt: Cannot allocate memory for registering server");
+		status = HAL_STATUS_NOMEM;
+		goto failed;
+	}
+
+	memcpy(server->uuid, cmd->uuid, sizeof(server->uuid));
+
+	server->id = server_cnt++;
+
+	if (!queue_push_head(gatt_servers, server)) {
+		error("gatt: Cannot push server on the list");
+		free(server);
+		status = HAL_STATUS_FAILED;
+		goto failed;
+	}
+
+	ev.status = GATT_SUCCESS;
+	ev.server_if = server->id;
+	memcpy(ev.uuid, server->uuid, sizeof(server->uuid));
+
+	status = HAL_STATUS_SUCCESS;
+
+failed:
+	if (status != HAL_STATUS_SUCCESS)
+		ev.status = GATT_FAILURE;
+
+	ipc_send_notif(hal_ipc, HAL_SERVICE_ID_GATT,
+				HAL_EV_GATT_SERVER_REGISTER, sizeof(ev), &ev);
+
 	ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT, HAL_OP_GATT_SERVER_REGISTER,
-							HAL_STATUS_FAILED);
+									status);
 }
 
 static void handle_server_unregister(const void *buf, uint16_t len)
@@ -2092,10 +2158,14 @@ bool bt_gatt_register(struct ipc *ipc, const bdaddr_t *addr)
 	conn_list = queue_new();
 	conn_wait_queue = queue_new();
 	gatt_clients = queue_new();
+	gatt_servers = queue_new();
 
-	if (!conn_list || !conn_wait_queue || !gatt_clients) {
+	if (!conn_list || !conn_wait_queue || !gatt_clients !gatt_servers) {
 		error("gatt: Failed to allocate memory for queues");
 
+		queue_destroy(gatt_servers, NULL);
+		gatt_servers = NULL;
+
 		queue_destroy(gatt_clients, NULL);
 		gatt_clients = NULL;
 
@@ -2125,6 +2195,9 @@ void bt_gatt_unregister(void)
 	ipc_unregister(hal_ipc, HAL_SERVICE_ID_GATT);
 	hal_ipc = NULL;
 
+	queue_destroy(gatt_servers, destroy_gatt_server);
+	gatt_servers = NULL;
+
 	queue_destroy(gatt_clients, destroy_gatt_client);
 	gatt_clients = NULL;
 
-- 
1.9.1


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

* [PATCH v2 3/3] android/gatt: Handle unregister gatt server command
  2014-04-01 12:54 [PATCH v2 1/3] android/gatt: Remove redundant hal cmd check Grzegorz Kolodziejczyk
  2014-04-01 12:54 ` [PATCH v2 2/3] android/gatt: Handle register gatt server command Grzegorz Kolodziejczyk
@ 2014-04-01 12:54 ` Grzegorz Kolodziejczyk
  2014-04-01 13:56 ` [PATCH v2 1/3] android/gatt: Remove redundant hal cmd check Szymon Janc
  2 siblings, 0 replies; 4+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-04-01 12:54 UTC (permalink / raw)
  To: linux-bluetooth

This adds unregister gatt server app command handling.
---
 android/gatt.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/android/gatt.c b/android/gatt.c
index fb4d9d1..de2ceb0 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -206,6 +206,14 @@ static bool match_client_by_id(const void *data, const void *user_data)
 	return client->id == exp_id;
 }
 
+static bool match_server_by_id(const void *data, const void *user_data)
+{
+	int32_t exp_id = PTR_TO_INT(user_data);
+	const struct gatt_server *server = data;
+
+	return server->id == exp_id;
+}
+
 static struct gatt_client *find_client_by_id(int32_t id)
 {
 	return queue_find(gatt_clients, match_client_by_id, INT_TO_PTR(id));
@@ -1948,10 +1956,26 @@ failed:
 
 static void handle_server_unregister(const void *buf, uint16_t len)
 {
+	const struct hal_cmd_gatt_server_unregister *cmd = buf;
+	uint8_t status;
+	struct gatt_server *server;
+
 	DBG("");
 
+	server = queue_remove_if(gatt_servers, match_server_by_id,
+						INT_TO_PTR(cmd->server_if));
+	if (!server) {
+		error("gatt: server_if=%d not found", cmd->server_if);
+		status = HAL_STATUS_FAILED;
+		goto failed;
+	}
+
+	destroy_gatt_server(server);
+	status = HAL_STATUS_SUCCESS;
+
+failed:
 	ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
-			HAL_OP_GATT_SERVER_UNREGISTER, HAL_STATUS_FAILED);
+					HAL_OP_GATT_SERVER_UNREGISTER, status);
 }
 
 static void handle_server_connect(const void *buf, uint16_t len)
-- 
1.9.1


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

* Re: [PATCH v2 1/3] android/gatt: Remove redundant hal cmd check
  2014-04-01 12:54 [PATCH v2 1/3] android/gatt: Remove redundant hal cmd check Grzegorz Kolodziejczyk
  2014-04-01 12:54 ` [PATCH v2 2/3] android/gatt: Handle register gatt server command Grzegorz Kolodziejczyk
  2014-04-01 12:54 ` [PATCH v2 3/3] android/gatt: Handle unregister " Grzegorz Kolodziejczyk
@ 2014-04-01 13:56 ` Szymon Janc
  2 siblings, 0 replies; 4+ messages in thread
From: Szymon Janc @ 2014-04-01 13:56 UTC (permalink / raw)
  To: Grzegorz Kolodziejczyk; +Cc: linux-bluetooth

Hi Grzegorz,

On Tuesday 01 of April 2014 14:54:27 Grzegorz Kolodziejczyk wrote:
> This removes redundant hal cmd check (is received in cmd UUID == NULL).
> ---
>  android/gatt.c | 6 ------
>  1 file changed, 6 deletions(-)
> 
> diff --git a/android/gatt.c b/android/gatt.c
> index 941582a..ee77a4e 100644
> --- a/android/gatt.c
> +++ b/android/gatt.c
> @@ -350,12 +350,6 @@ static void handle_client_register(const void *buf, uint16_t len)
>  
>  	DBG("");
>  
> -	if (!cmd->uuid) {
> -		error("gatt: no uuid received");
> -		status = HAL_STATUS_FAILED;
> -		goto failed;
> -	}
> -
>  	if (queue_find(gatt_clients, match_client_by_uuid, &cmd->uuid)) {
>  		error("gatt: client uuid is already on list");
>  		status = HAL_STATUS_FAILED;
> 

All patches pushed (with some fixes applied), thanks.

-- 
Best regards, 
Szymon Janc

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

end of thread, other threads:[~2014-04-01 13:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-01 12:54 [PATCH v2 1/3] android/gatt: Remove redundant hal cmd check Grzegorz Kolodziejczyk
2014-04-01 12:54 ` [PATCH v2 2/3] android/gatt: Handle register gatt server command Grzegorz Kolodziejczyk
2014-04-01 12:54 ` [PATCH v2 3/3] android/gatt: Handle unregister " Grzegorz Kolodziejczyk
2014-04-01 13:56 ` [PATCH v2 1/3] android/gatt: Remove redundant hal cmd check Szymon Janc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).