* [PATCH v4 1/2] android/gatt: Handle Register gatt client command
@ 2014-03-12 9:27 Grzegorz Kolodziejczyk
2014-03-12 9:27 ` [PATCH v4 2/2] android/gatt: Handle Unregister " Grzegorz Kolodziejczyk
2014-03-12 13:09 ` [PATCH v4 1/2] android/gatt: Handle Register " Szymon Janc
0 siblings, 2 replies; 3+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-03-12 9:27 UTC (permalink / raw)
To: linux-bluetooth
This adds register gatt client app command handling.
---
android/gatt.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 53 insertions(+), 2 deletions(-)
diff --git a/android/gatt.c b/android/gatt.c
index ce85af4..34549dd 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -31,20 +31,71 @@
#include <glib.h>
#include "ipc.h"
+#include "ipc-common.h"
#include "lib/bluetooth.h"
#include "gatt.h"
#include "src/log.h"
#include "hal-msg.h"
+struct gatt_client {
+ int32_t id;
+ uint8_t uuid[16];
+};
+
static struct ipc *hal_ipc = NULL;
static bdaddr_t adapter_addr;
+static GSList *gatt_clients = NULL;
+
+static int find_client_by_uuid(gconstpointer data, gconstpointer user_data)
+{
+ const uint8_t *exp_uuid = user_data;
+ const struct gatt_client *client = data;
+
+ return memcmp(exp_uuid, client->uuid, sizeof(client->uuid));
+}
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;
+ static int32_t client_cnt = 1;
+ uint8_t status;
+
DBG("");
- ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT, HAL_OP_GATT_CLIENT_REGISTER,
- HAL_STATUS_FAILED);
+ if (!cmd->uuid) {
+ error("gatt: no uuid received");
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+
+ if (g_slist_find_custom(gatt_clients, &cmd->uuid,
+ find_client_by_uuid)) {
+ error("gatt: client uuid is already on list");
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+
+ client = g_new0(struct gatt_client, 1);
+ memcpy(client->uuid, cmd->uuid, sizeof(client->uuid));
+
+ client->id = client_cnt++;
+
+ gatt_clients = g_slist_prepend(gatt_clients, client);
+
+ status = HAL_STATUS_SUCCESS;
+
+ ev.status = status;
+ ev.client_if = client->id;
+ memcpy(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);
+
+failed:
+ ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
+ HAL_OP_GATT_CLIENT_REGISTER, status);
}
static void handle_client_unregister(const void *buf, uint16_t len)
--
1.8.5.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH v4 2/2] android/gatt: Handle Unregister gatt client command
2014-03-12 9:27 [PATCH v4 1/2] android/gatt: Handle Register gatt client command Grzegorz Kolodziejczyk
@ 2014-03-12 9:27 ` Grzegorz Kolodziejczyk
2014-03-12 13:09 ` [PATCH v4 1/2] android/gatt: Handle Register " Szymon Janc
1 sibling, 0 replies; 3+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-03-12 9:27 UTC (permalink / raw)
To: linux-bluetooth
This adds unregister gatt client app command handling.
---
android/gatt.c | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/android/gatt.c b/android/gatt.c
index 34549dd..a874737 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -36,6 +36,7 @@
#include "gatt.h"
#include "src/log.h"
#include "hal-msg.h"
+#include "src/shared/util.h"
struct gatt_client {
int32_t id;
@@ -54,6 +55,14 @@ static int find_client_by_uuid(gconstpointer data, gconstpointer user_data)
return memcmp(exp_uuid, client->uuid, sizeof(client->uuid));
}
+static int find_client_by_id(gconstpointer data, gconstpointer user_data)
+{
+ int32_t exp_id = PTR_TO_INT(user_data);
+ const struct gatt_client *client = data;
+
+ return client->id != exp_id;
+}
+
static void handle_client_register(const void *buf, uint16_t len)
{
const struct hal_cmd_gatt_client_register *cmd = buf;
@@ -100,10 +109,27 @@ failed:
static void handle_client_unregister(const void *buf, uint16_t len)
{
+ const struct hal_cmd_gatt_client_unregister *cmd = buf;
+ GSList *l;
+ uint8_t status;
+
DBG("");
+ l = g_slist_find_custom(gatt_clients, INT_TO_PTR(cmd->client_if),
+ find_client_by_id);
+ if (!l) {
+ error("gatt: client_if=%d not found", cmd->client_if);
+ status = HAL_STATUS_FAILED;
+ goto failed;
+ }
+
+ gatt_clients = g_slist_remove(gatt_clients, l->data);
+
+ status = HAL_STATUS_SUCCESS;
+
+failed:
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
- HAL_OP_GATT_CLIENT_UNREGISTER, HAL_STATUS_FAILED);
+ HAL_OP_GATT_CLIENT_UNREGISTER, status);
}
static void handle_client_scan(const void *buf, uint16_t len)
--
1.8.5.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v4 1/2] android/gatt: Handle Register gatt client command
2014-03-12 9:27 [PATCH v4 1/2] android/gatt: Handle Register gatt client command Grzegorz Kolodziejczyk
2014-03-12 9:27 ` [PATCH v4 2/2] android/gatt: Handle Unregister " Grzegorz Kolodziejczyk
@ 2014-03-12 13:09 ` Szymon Janc
1 sibling, 0 replies; 3+ messages in thread
From: Szymon Janc @ 2014-03-12 13:09 UTC (permalink / raw)
To: Grzegorz Kolodziejczyk; +Cc: linux-bluetooth
Hi Grzegorz,
On Wednesday 12 of March 2014 10:27:37 Grzegorz Kolodziejczyk wrote:
> This adds register gatt client app command handling.
> ---
> android/gatt.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 53 insertions(+), 2 deletions(-)
>
> diff --git a/android/gatt.c b/android/gatt.c
> index ce85af4..34549dd 100644
> --- a/android/gatt.c
> +++ b/android/gatt.c
> @@ -31,20 +31,71 @@
> #include <glib.h>
>
> #include "ipc.h"
> +#include "ipc-common.h"
> #include "lib/bluetooth.h"
> #include "gatt.h"
> #include "src/log.h"
> #include "hal-msg.h"
>
> +struct gatt_client {
> + int32_t id;
> + uint8_t uuid[16];
> +};
> +
> static struct ipc *hal_ipc = NULL;
> static bdaddr_t adapter_addr;
> +static GSList *gatt_clients = NULL;
> +
> +static int find_client_by_uuid(gconstpointer data, gconstpointer user_data)
> +{
> + const uint8_t *exp_uuid = user_data;
> + const struct gatt_client *client = data;
> +
> + return memcmp(exp_uuid, client->uuid, sizeof(client->uuid));
> +}
>
> 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;
> + static int32_t client_cnt = 1;
> + uint8_t status;
> +
> DBG("");
>
> - ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT, HAL_OP_GATT_CLIENT_REGISTER,
> - HAL_STATUS_FAILED);
> + if (!cmd->uuid) {
> + error("gatt: no uuid received");
> + status = HAL_STATUS_FAILED;
> + goto failed;
> + }
> +
> + if (g_slist_find_custom(gatt_clients, &cmd->uuid,
> + find_client_by_uuid)) {
> + error("gatt: client uuid is already on list");
> + status = HAL_STATUS_FAILED;
> + goto failed;
> + }
> +
> + client = g_new0(struct gatt_client, 1);
> + memcpy(client->uuid, cmd->uuid, sizeof(client->uuid));
> +
> + client->id = client_cnt++;
> +
> + gatt_clients = g_slist_prepend(gatt_clients, client);
> +
> + status = HAL_STATUS_SUCCESS;
> +
> + ev.status = status;
> + ev.client_if = client->id;
> + memcpy(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);
> +
> +failed:
> + ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
> + HAL_OP_GATT_CLIENT_REGISTER, status);
> }
>
> static void handle_client_unregister(const void *buf, uint16_t len)
>
Both Patches applied. Thanks.
--
Best regards,
Szymon Janc
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-03-12 13:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-12 9:27 [PATCH v4 1/2] android/gatt: Handle Register gatt client command Grzegorz Kolodziejczyk
2014-03-12 9:27 ` [PATCH v4 2/2] android/gatt: Handle Unregister " Grzegorz Kolodziejczyk
2014-03-12 13:09 ` [PATCH v4 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