linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] android/gatt: Handle register gatt server command
@ 2014-04-01 10:13 Grzegorz Kolodziejczyk
  2014-04-01 10:13 ` [PATCH 2/2] android/gatt: Handle unregister " Grzegorz Kolodziejczyk
  2014-04-01 11:54 ` [PATCH 1/2] android/gatt: Handle register " Szymon Janc
  0 siblings, 2 replies; 3+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-04-01 10:13 UTC (permalink / raw)
  To: linux-bluetooth

This adds register gatt server command handling.
---
 android/gatt.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 73 insertions(+), 1 deletion(-)

diff --git a/android/gatt.c b/android/gatt.c
index 61746b1..5ca3fe7 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 */
 
@@ -154,6 +160,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);
@@ -1883,10 +1897,61 @@ 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 (!cmd->uuid) {
+		error("gatt: No uuid received");
+		status = GATT_FAILURE;
+		goto failed;
+	}
+
+	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)
@@ -2123,6 +2188,12 @@ bool bt_gatt_register(struct ipc *ipc, const bdaddr_t *addr)
 		return false;
 	}
 
+	gatt_servers = queue_new();
+	if (!gatt_servers) {
+		error("gatt: Cannot allocate gatt_servers");
+		return false;
+	}
+
 	return true;
 }
 
@@ -2131,6 +2202,7 @@ void bt_gatt_unregister(void)
 	DBG("");
 
 	queue_destroy(gatt_clients, free);
+	queue_destroy(gatt_servers, free);
 
 	ipc_unregister(hal_ipc, HAL_SERVICE_ID_GATT);
 	hal_ipc = NULL;
-- 
1.8.5.2


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

* [PATCH 2/2] android/gatt: Handle unregister gatt server command
  2014-04-01 10:13 [PATCH 1/2] android/gatt: Handle register gatt server command Grzegorz Kolodziejczyk
@ 2014-04-01 10:13 ` Grzegorz Kolodziejczyk
  2014-04-01 11:54 ` [PATCH 1/2] android/gatt: Handle register " Szymon Janc
  1 sibling, 0 replies; 3+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-04-01 10:13 UTC (permalink / raw)
  To: linux-bluetooth

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

diff --git a/android/gatt.c b/android/gatt.c
index 5ca3fe7..0f99ab3 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -176,6 +176,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));
@@ -335,6 +343,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;
@@ -1956,10 +1971,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.8.5.2


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

* Re: [PATCH 1/2] android/gatt: Handle register gatt server command
  2014-04-01 10:13 [PATCH 1/2] android/gatt: Handle register gatt server command Grzegorz Kolodziejczyk
  2014-04-01 10:13 ` [PATCH 2/2] android/gatt: Handle unregister " Grzegorz Kolodziejczyk
@ 2014-04-01 11:54 ` Szymon Janc
  1 sibling, 0 replies; 3+ messages in thread
From: Szymon Janc @ 2014-04-01 11:54 UTC (permalink / raw)
  To: Grzegorz Kolodziejczyk; +Cc: linux-bluetooth

Hi Grzegorz,

On Tuesday 01 of April 2014 12:13:58 Grzegorz Kolodziejczyk wrote:
> This adds register gatt server command handling.
> ---
>  android/gatt.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 73 insertions(+), 1 deletion(-)
> 
> diff --git a/android/gatt.c b/android/gatt.c
> index 61746b1..5ca3fe7 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 */
>  
> @@ -154,6 +160,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);
> @@ -1883,10 +1897,61 @@ 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 (!cmd->uuid) {
> +		error("gatt: No uuid received");
> +		status = GATT_FAILURE;
> +		goto failed;
> +	}

This is not needed.

> +
> +	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)
> @@ -2123,6 +2188,12 @@ bool bt_gatt_register(struct ipc *ipc, const bdaddr_t *addr)
>  		return false;
>  	}
>  
> +	gatt_servers = queue_new();
> +	if (!gatt_servers) {
> +		error("gatt: Cannot allocate gatt_servers");
> +		return false;
> +	}
> +
>  	return true;
>  }
>  
> @@ -2131,6 +2202,7 @@ void bt_gatt_unregister(void)
>  	DBG("");
>  
>  	queue_destroy(gatt_clients, free);
> +	queue_destroy(gatt_servers, free);
>  
>  	ipc_unregister(hal_ipc, HAL_SERVICE_ID_GATT);
>  	hal_ipc = NULL;
> 

-- 
Best regards, 
Szymon Janc

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

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

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-01 10:13 [PATCH 1/2] android/gatt: Handle register gatt server command Grzegorz Kolodziejczyk
2014-04-01 10:13 ` [PATCH 2/2] android/gatt: Handle unregister " Grzegorz Kolodziejczyk
2014-04-01 11:54 ` [PATCH 1/2] android/gatt: Handle register " 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).