2014-05-26 21:53:23

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 0/5] android: GATT client test interface

Hi,

This adds initial implementation of GATT client test command. It seems
to be usefull when testing against PTS for executing actions that are
no possible from standard API.

This is initial implementation with enable/connect/disconnect commands.

Commands are not defined in HAL but in here:
http://androidxref.com/4.4.2_r1/xref/packages/apps/Bluetooth/src/com/android/bluetooth/gatt/GattDebugUtils.java#77

BR
Szymon Janc

Szymon Janc (5):
android/gatt: Add initial implementation of client test command
android/gatt: Factor out unregistering client into helper function
android/gatt: Implement enable test command
android/gatt: Implement connect test command
android/gatt: Implement disconnect test command

android/gatt.c | 89 +++++++++++++++++++++++++++++++++++++++++++++----------
android/hal-msg.h | 6 ++++
2 files changed, 79 insertions(+), 16 deletions(-)

--
2.0.0.rc4



2014-05-28 12:45:17

by Szymon Janc

[permalink] [raw]
Subject: Re: [PATCH 0/5] android: GATT client test interface

On Monday 26 of May 2014 23:53:23 Szymon Janc wrote:
> Hi,
>
> This adds initial implementation of GATT client test command. It seems
> to be usefull when testing against PTS for executing actions that are
> no possible from standard API.
>
> This is initial implementation with enable/connect/disconnect commands.
>
> Commands are not defined in HAL but in here:
> http://androidxref.com/4.4.2_r1/xref/packages/apps/Bluetooth/src/com/android/bluetooth/gatt/GattDebugUtils.java#77
>
> BR
> Szymon Janc
>
> Szymon Janc (5):
> android/gatt: Add initial implementation of client test command
> android/gatt: Factor out unregistering client into helper function
> android/gatt: Implement enable test command
> android/gatt: Implement connect test command
> android/gatt: Implement disconnect test command
>
> android/gatt.c | 89 +++++++++++++++++++++++++++++++++++++++++++++----------
> android/hal-msg.h | 6 ++++
> 2 files changed, 79 insertions(+), 16 deletions(-)
>
>

Applied.

--
Best regards,
Szymon Janc

2014-05-26 21:53:26

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 3/5] android/gatt: Implement enable test command

This command is used to enable and disable test interface.
---
android/gatt.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)

diff --git a/android/gatt.c b/android/gatt.c
index 8b0082e..1ce6ff9 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -194,6 +194,12 @@ static GIOChannel *listening_io = NULL;

static struct bt_crypto *crypto = NULL;

+static int test_client_if = 0;
+static const uint8_t TEST_UUID[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04
+};
+
static void bt_le_discovery_stop_cb(void);

static bool is_bluetooth_uuid(const uint8_t *uuid)
@@ -3450,6 +3456,20 @@ static void handle_client_test_command(const void *buf, uint16_t len)

switch (cmd->command) {
case GATT_CLIENT_TEST_CMD_ENABLE:
+ if (cmd->u1) {
+ if (!test_client_if)
+ test_client_if = register_app(TEST_UUID,
+ APP_CLIENT);
+
+ if (test_client_if)
+ status = HAL_STATUS_SUCCESS;
+ else
+ status = HAL_STATUS_FAILED;
+ } else {
+ status = unregister_client(test_client_if);
+ test_client_if = 0;
+ }
+ break;
case GATT_CLIENT_TEST_CMD_CONNECT:
case GATT_CLIENT_TEST_CMD_DISCONNECT:
case GATT_CLIENT_TEST_CMD_DISCOVER:
--
2.0.0.rc4


2014-05-26 21:53:27

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 4/5] android/gatt: Implement connect test command

---
android/gatt.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/android/gatt.c b/android/gatt.c
index 1ce6ff9..6eb4440 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -3471,6 +3471,9 @@ static void handle_client_test_command(const void *buf, uint16_t len)
}
break;
case GATT_CLIENT_TEST_CMD_CONNECT:
+ /* TODO u1 holds device type, for now assume BLE */
+ status = handle_connect(test_client_if, &bdaddr);
+ break;
case GATT_CLIENT_TEST_CMD_DISCONNECT:
case GATT_CLIENT_TEST_CMD_DISCOVER:
case GATT_CLIENT_TEST_CMD_PAIRING_CONFIG:
--
2.0.0.rc4


2014-05-26 21:53:28

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 5/5] android/gatt: Implement disconnect test command

---
android/gatt.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/android/gatt.c b/android/gatt.c
index 6eb4440..af3af08 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -3445,6 +3445,7 @@ failed:
static void handle_client_test_command(const void *buf, uint16_t len)
{
const struct hal_cmd_gatt_client_test_command *cmd = buf;
+ struct gatt_app *app;
bdaddr_t bdaddr;
bt_uuid_t uuid;
uint8_t status;
@@ -3475,6 +3476,13 @@ static void handle_client_test_command(const void *buf, uint16_t len)
status = handle_connect(test_client_if, &bdaddr);
break;
case GATT_CLIENT_TEST_CMD_DISCONNECT:
+ app = queue_find(gatt_apps, match_app_by_id,
+ INT_TO_PTR(test_client_if));
+ if (app)
+ app_disconnect_devices(app);
+
+ status = HAL_STATUS_SUCCESS;
+ break;
case GATT_CLIENT_TEST_CMD_DISCOVER:
case GATT_CLIENT_TEST_CMD_PAIRING_CONFIG:
default:
--
2.0.0.rc4


2014-05-26 21:53:25

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 2/5] android/gatt: Factor out unregistering client into helper function

This will be also used by test interface.
---
android/gatt.c | 37 ++++++++++++++++++++++---------------
1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/android/gatt.c b/android/gatt.c
index 0acb4b6..8b0082e 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -1360,28 +1360,35 @@ static bool trigger_connection(struct app_connection *connection)
return true;
}

+static uint8_t unregister_client(int client_if)
+{
+ struct gatt_app *cl;
+
+ cl = queue_remove_if(gatt_apps, match_app_by_id, INT_TO_PTR(client_if));
+ if (!cl) {
+ error("gatt: client_if=%d not found", client_if);
+
+ return HAL_STATUS_FAILED;
+ }
+
+ /*
+ * Check if there is any connect request or connected device
+ * for this client. If so, remove this client from those lists.
+ */
+ app_disconnect_devices(cl);
+ destroy_gatt_app(cl);
+
+ return HAL_STATUS_SUCCESS;
+}
+
static void handle_client_unregister(const void *buf, uint16_t len)
{
const struct hal_cmd_gatt_client_unregister *cmd = buf;
uint8_t status;
- struct gatt_app *cl;

DBG("");

- cl = queue_remove_if(gatt_apps, match_app_by_id,
- INT_TO_PTR(cmd->client_if));
- if (!cl) {
- error("gatt: client_if=%d not found", cmd->client_if);
- status = HAL_STATUS_FAILED;
- } else {
- /*
- * Check if there is any connect request or connected device
- * for this client. If so, remove this client from those lists.
- */
- app_disconnect_devices(cl);
- destroy_gatt_app(cl);
- status = HAL_STATUS_SUCCESS;
- }
+ status = unregister_client(cmd->client_if);

ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
HAL_OP_GATT_CLIENT_UNREGISTER, status);
--
2.0.0.rc4


2014-05-26 21:53:24

by Szymon Janc

[permalink] [raw]
Subject: [PATCH 1/5] android/gatt: Add initial implementation of client test command

This command is used to performe some tasks not available from
standard API and usable only for PTS testing.
---
android/gatt.c | 21 ++++++++++++++++++++-
android/hal-msg.h | 6 ++++++
2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/android/gatt.c b/android/gatt.c
index e41a69e..0acb4b6 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -3431,10 +3431,29 @@ failed:

static void handle_client_test_command(const void *buf, uint16_t len)
{
+ const struct hal_cmd_gatt_client_test_command *cmd = buf;
+ bdaddr_t bdaddr;
+ bt_uuid_t uuid;
+ uint8_t status;
+
DBG("");

+ android2bdaddr(cmd->bda1, &bdaddr);
+ android2uuid(cmd->uuid1, &uuid);
+
+ switch (cmd->command) {
+ case GATT_CLIENT_TEST_CMD_ENABLE:
+ case GATT_CLIENT_TEST_CMD_CONNECT:
+ case GATT_CLIENT_TEST_CMD_DISCONNECT:
+ case GATT_CLIENT_TEST_CMD_DISCOVER:
+ case GATT_CLIENT_TEST_CMD_PAIRING_CONFIG:
+ default:
+ status = HAL_STATUS_FAILED;
+ break;
+ }
+
ipc_send_rsp(hal_ipc, HAL_SERVICE_ID_GATT,
- HAL_OP_GATT_CLIENT_TEST_COMMAND, HAL_STATUS_FAILED);
+ HAL_OP_GATT_CLIENT_TEST_COMMAND, status);
}

static void handle_server_register(const void *buf, uint16_t len)
diff --git a/android/hal-msg.h b/android/hal-msg.h
index b68a4c7..d051b67 100644
--- a/android/hal-msg.h
+++ b/android/hal-msg.h
@@ -747,6 +747,12 @@ struct hal_cmd_gatt_client_set_adv_data {
uint8_t manufacturer_data[0];
} __attribute__((packed));

+#define GATT_CLIENT_TEST_CMD_ENABLE 0x01
+#define GATT_CLIENT_TEST_CMD_CONNECT 0x02
+#define GATT_CLIENT_TEST_CMD_DISCONNECT 0x03
+#define GATT_CLIENT_TEST_CMD_DISCOVER 0x04
+#define GATT_CLIENT_TEST_CMD_PAIRING_CONFIG 0xf0
+
#define HAL_OP_GATT_CLIENT_TEST_COMMAND 0x16
struct hal_cmd_gatt_client_test_command {
int32_t command;
--
2.0.0.rc4