linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/8] android/gatt: Fix return status if cannot alloc memory
@ 2014-10-17 13:38 Grzegorz Kolodziejczyk
  2014-10-17 13:38 ` [PATCH 2/8] android/tester: Define write types for GATT test cases Grzegorz Kolodziejczyk
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-10-17 13:38 UTC (permalink / raw)
  To: linux-bluetooth

NOMEM HAL status should be returned in case if it's not possible to
alloc memory for notifiaction data.
---
 android/gatt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/android/gatt.c b/android/gatt.c
index ea20941..c26d45a 100644
--- a/android/gatt.c
+++ b/android/gatt.c
@@ -3759,7 +3759,7 @@ static void handle_client_register_for_notification(const void *buf,
 
 	notification = new0(struct notification_data, 1);
 	if (!notification) {
-		status = HAL_STATUS_FAILED;
+		status = HAL_STATUS_NOMEM;
 		goto failed;
 	}
 
-- 
1.9.3


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

* [PATCH 2/8] android/tester: Define write types for GATT test cases
  2014-10-17 13:38 [PATCH 1/8] android/gatt: Fix return status if cannot alloc memory Grzegorz Kolodziejczyk
@ 2014-10-17 13:38 ` Grzegorz Kolodziejczyk
  2014-10-17 13:38 ` [PATCH 3/8] android/tester: Fix hardcoded length values Grzegorz Kolodziejczyk
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-10-17 13:38 UTC (permalink / raw)
  To: linux-bluetooth

Gatt test cases should use defined write types.
---
 android/tester-gatt.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/android/tester-gatt.c b/android/tester-gatt.c
index 8b95e9c..38dd0ee 100644
--- a/android/tester-gatt.c
+++ b/android/tester-gatt.c
@@ -41,6 +41,11 @@
 #define GATT_SERVER_TRANSPORT_BREDR		0x01
 #define GATT_SERVER_TRANSPORT_LE_BREDR		0x02
 
+#define GATT_WRITE_TYPE_NO_RESPONSE	0x01
+#define GATT_WRITE_TYPE_DEFAULT		0x02
+#define GATT_WRITE_TYPE_PREPARE		0x03
+#define GATT_WRITE_TYPE_SIGNED		0x04
+
 static struct queue *list; /* List of gatt test cases */
 
 static int srvc1_handle;
@@ -368,7 +373,7 @@ static struct write_char_data write_char_data_1 = {
 	.conn_id = CONN1_ID,
 	.service = &service_1,
 	.characteristic = &characteristic_1,
-	.write_type = 1,
+	.write_type = GATT_WRITE_TYPE_NO_RESPONSE,
 	.len = sizeof(value_2),
 	.p_value = value_2,
 	.auth_req = 0
@@ -378,7 +383,7 @@ static struct write_char_data write_char_data_2 = {
 	.conn_id = CONN1_ID,
 	.service = &service_1,
 	.characteristic = &characteristic_1,
-	.write_type = 2,
+	.write_type = GATT_WRITE_TYPE_DEFAULT,
 	.len = sizeof(value_2),
 	.p_value = value_2,
 	.auth_req = 0
-- 
1.9.3


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

* [PATCH 3/8] android/tester: Fix hardcoded length values
  2014-10-17 13:38 [PATCH 1/8] android/gatt: Fix return status if cannot alloc memory Grzegorz Kolodziejczyk
  2014-10-17 13:38 ` [PATCH 2/8] android/tester: Define write types for GATT test cases Grzegorz Kolodziejczyk
@ 2014-10-17 13:38 ` Grzegorz Kolodziejczyk
  2014-10-17 13:38 ` [PATCH 4/8] android/tester: Use BT_STATUS defines instead of hardcoded values Grzegorz Kolodziejczyk
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-10-17 13:38 UTC (permalink / raw)
  To: linux-bluetooth

Lenght variable shouldn't be hardcoded in test case structs.
---
 android/tester-gatt.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/android/tester-gatt.c b/android/tester-gatt.c
index 38dd0ee..97fe0f0 100644
--- a/android/tester-gatt.c
+++ b/android/tester-gatt.c
@@ -596,7 +596,7 @@ static struct set_read_params set_read_param_1 = {
 	.srvc_id = &service_1,
 	.char_id = &characteristic_1,
 	.value = value_1,
-	.len = 1,
+	.len = sizeof(value_1),
 	.status = BT_STATUS_SUCCESS
 };
 
@@ -620,7 +620,7 @@ static struct set_read_params set_read_param_4 = {
 	.char_id = &characteristic_1,
 	.descr_id = &desc_1,
 	.value = value_1,
-	.len = 1,
+	.len = sizeof(value_1),
 	.status = BT_STATUS_SUCCESS
 };
 
-- 
1.9.3


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

* [PATCH 4/8] android/tester: Use BT_STATUS defines instead of hardcoded values
  2014-10-17 13:38 [PATCH 1/8] android/gatt: Fix return status if cannot alloc memory Grzegorz Kolodziejczyk
  2014-10-17 13:38 ` [PATCH 2/8] android/tester: Define write types for GATT test cases Grzegorz Kolodziejczyk
  2014-10-17 13:38 ` [PATCH 3/8] android/tester: Fix hardcoded length values Grzegorz Kolodziejczyk
@ 2014-10-17 13:38 ` Grzegorz Kolodziejczyk
  2014-10-17 13:38 ` [PATCH 5/8] android/tester: Add att pdu remote receive debug log Grzegorz Kolodziejczyk
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-10-17 13:38 UTC (permalink / raw)
  To: linux-bluetooth

Status value in test case structs should use defined BT_STATUS types.
---
 android/tester-gatt.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/android/tester-gatt.c b/android/tester-gatt.c
index 97fe0f0..d123619 100644
--- a/android/tester-gatt.c
+++ b/android/tester-gatt.c
@@ -611,7 +611,7 @@ static struct set_read_params set_read_param_3 = {
 	.params = &read_params_1,
 	.srvc_id = &service_2,
 	.char_id = &characteristic_1,
-	.status = 0x01,
+	.status = BT_STATUS_FAIL
 };
 
 static struct set_read_params set_read_param_4 = {
@@ -637,7 +637,7 @@ static struct set_read_params set_read_param_6 = {
 	.srvc_id = &service_1,
 	.char_id = &characteristic_1,
 	.descr_id = &desc_2,
-	.status = 0x01
+	.status = BT_STATUS_FAIL
 };
 
 static struct set_write_params set_write_param_1 = {
@@ -658,7 +658,7 @@ static struct set_write_params set_write_param_3 = {
 	.params = &write_params_1,
 	.srvc_id = &service_1,
 	.char_id = &characteristic_1,
-	.status = 0x01
+	.status = BT_STATUS_FAIL
 };
 
 static struct set_write_params set_write_param_4 = {
@@ -674,7 +674,7 @@ static struct set_write_params set_write_param_5 = {
 	.srvc_id = &service_1,
 	.char_id = &characteristic_1,
 	.descr_id = &desc_2,
-	.status = 0x01
+	.status = BT_STATUS_FAIL
 };
 
 static struct set_write_params set_write_param_6 = {
-- 
1.9.3


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

* [PATCH 5/8] android/tester: Add att pdu remote receive debug log
  2014-10-17 13:38 [PATCH 1/8] android/gatt: Fix return status if cannot alloc memory Grzegorz Kolodziejczyk
                   ` (2 preceding siblings ...)
  2014-10-17 13:38 ` [PATCH 4/8] android/tester: Use BT_STATUS defines instead of hardcoded values Grzegorz Kolodziejczyk
@ 2014-10-17 13:38 ` Grzegorz Kolodziejczyk
  2014-10-17 13:38 ` [PATCH 6/8] android/tester: Add GATT server send indication test cases Grzegorz Kolodziejczyk
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-10-17 13:38 UTC (permalink / raw)
  To: linux-bluetooth

This adds additional logs with received opcode of att pdu by remote
---
 android/tester-gatt.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/android/tester-gatt.c b/android/tester-gatt.c
index d123619..c0065a7 100644
--- a/android/tester-gatt.c
+++ b/android/tester-gatt.c
@@ -1457,6 +1457,8 @@ static void gatt_cid_hook_cb(const void *data, uint16_t len, void *user_data)
 	const uint8_t *pdu = data;
 	struct iovec *gatt_pdu = queue_peek_head(t_data->pdus);
 
+	tester_debug("Received att pdu with opcode 0x%02x", pdu[0]);
+
 	switch (pdu[0]) {
 	case L2CAP_ATT_EXCHANGE_MTU_REQ:
 		tester_print("Exchange MTU request received.");
-- 
1.9.3


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

* [PATCH 6/8] android/tester: Add GATT server send indication test cases
  2014-10-17 13:38 [PATCH 1/8] android/gatt: Fix return status if cannot alloc memory Grzegorz Kolodziejczyk
                   ` (3 preceding siblings ...)
  2014-10-17 13:38 ` [PATCH 5/8] android/tester: Add att pdu remote receive debug log Grzegorz Kolodziejczyk
@ 2014-10-17 13:38 ` Grzegorz Kolodziejczyk
  2014-10-17 13:38 ` [PATCH 7/8] android/tester: Add GATT server send response to read req " Grzegorz Kolodziejczyk
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-10-17 13:38 UTC (permalink / raw)
  To: linux-bluetooth

This adds send indication by server test cases.
---
 android/tester-gatt.c | 160 +++++++++++++++++++++++++++++++++++++++++++++++++-
 android/tester-main.c |   2 +
 android/tester-main.h |   2 +
 3 files changed, 162 insertions(+), 2 deletions(-)

diff --git a/android/tester-gatt.c b/android/tester-gatt.c
index c0065a7..2ceb295 100644
--- a/android/tester-gatt.c
+++ b/android/tester-gatt.c
@@ -23,6 +23,8 @@
 
 #define L2CAP_ATT_EXCHANGE_MTU_REQ	0x02
 #define L2CAP_ATT_EXCHANGE_MTU_RSP	0x03
+#define L2CAP_ATT_HANDLE_VALUE_NOTIFY	0x1b
+#define L2CAP_ATT_HANDLE_VALUE_IND	0x1d
 
 #define GATT_STATUS_SUCCESS	0x00000000
 #define GATT_STATUS_FAILURE	0x00000101
@@ -61,6 +63,8 @@ static bt_uuid_t app2_uuid = {
 				0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 },
 };
 
+static uint8_t value_1[] = {0x01};
+
 struct gatt_connect_data {
 	const int app_id;
 	const int conn_id;
@@ -174,6 +178,15 @@ struct delete_srvc_data {
 	int *srvc_handle;
 };
 
+struct send_indication_data {
+	int app_id;
+	int *attr_handle;
+	int conn_id;
+	int len;
+	int confirm;
+	char *p_value;
+};
+
 static bt_bdaddr_t emu_remote_bdaddr_val = {
 	.address = { 0x00, 0xaa, 0x01, 0x01, 0x00, 0x00 },
 };
@@ -560,6 +573,36 @@ static struct delete_srvc_data delete_bad_srvc_data_1 = {
 	.app_id = APP1_ID,
 	.srvc_handle = &srvc_bad_handle
 };
+
+static int srvc_indication_handle_1 = 0x01;
+
+static struct send_indication_data send_indication_data_1 = {
+	.app_id = APP1_ID,
+	.attr_handle = &srvc_indication_handle_1,
+	.conn_id = CONN1_ID,
+	.len = sizeof(value_2),
+	.p_value = value_2,
+	.confirm = 1
+};
+
+static struct send_indication_data send_indication_data_2 = {
+	.app_id = APP1_ID,
+	.attr_handle = &srvc_indication_handle_1,
+	.conn_id = CONN1_ID,
+	.len = sizeof(value_2),
+	.p_value = value_2,
+	.confirm = 0
+};
+
+static struct send_indication_data send_bad_indication_data_1 = {
+	.app_id = APP1_ID,
+	.attr_handle = &srvc_indication_handle_1,
+	.conn_id = CONN2_ID,
+	.len = sizeof(value_2),
+	.p_value = value_2,
+	.confirm = 0
+};
+
 struct set_read_params {
 	btgatt_read_params_t *params;
 	btgatt_srvc_id_t *srvc_id;
@@ -589,8 +632,6 @@ struct set_notify_params {
 	bt_bdaddr_t *bdaddr;
 };
 
-static uint8_t value_1[] = {0x01};
-
 static struct set_read_params set_read_param_1 = {
 	.params = &read_params_1,
 	.srvc_id = &service_1,
@@ -1004,6 +1045,17 @@ static struct iovec notification_3[] = {
 	end_pdu
 };
 
+static struct iovec send_indication_1[] = {
+	raw_pdu(0x1d, 0x01, 0x00, 0x00, 0x01, 0x02, 0x03),
+	raw_pdu(0x1e),
+	end_pdu
+};
+
+static struct iovec send_notification_1[] = {
+	raw_pdu(0x1b, 0x01, 0x00, 0x00, 0x01, 0x02, 0x03),
+	end_pdu
+};
+
 static void gatt_client_register_action(void)
 {
 	struct test_data *data = tester_get_data();
@@ -1449,6 +1501,25 @@ static void gatt_server_delete_srvc_action(void)
 	schedule_action_verification(step);
 }
 
+static void gatt_server_send_indication_action(void)
+{
+	struct test_data *data = tester_get_data();
+	struct step *current_data_step = queue_peek_head(data->steps);
+	struct send_indication_data *send_indication_data =
+						current_data_step->set_data;
+	struct step *step = g_new0(struct step, 1);
+
+	step->action_status = data->if_gatt->server->send_indication(
+					send_indication_data->app_id,
+					*send_indication_data->attr_handle,
+					send_indication_data->conn_id,
+					send_indication_data->len,
+					send_indication_data->confirm,
+					send_indication_data->p_value);
+
+	schedule_action_verification(step);
+}
+
 static void gatt_cid_hook_cb(const void *data, uint16_t len, void *user_data)
 {
 	struct test_data *t_data = tester_get_data();
@@ -1456,6 +1527,7 @@ static void gatt_cid_hook_cb(const void *data, uint16_t len, void *user_data)
 	struct emu_l2cap_cid_data *cid_data = user_data;
 	const uint8_t *pdu = data;
 	struct iovec *gatt_pdu = queue_peek_head(t_data->pdus);
+	struct step *step;
 
 	tester_debug("Received att pdu with opcode 0x%02x", pdu[0]);
 
@@ -1473,6 +1545,20 @@ static void gatt_cid_hook_cb(const void *data, uint16_t len, void *user_data)
 		tester_print("Exchange MTU response received.");
 
 		break;
+	case L2CAP_ATT_HANDLE_VALUE_IND:
+		step = g_new0(struct step, 1);
+
+		step->callback = CB_EMU_VALUE_INDICATION;
+
+		schedule_callback_verification(step);
+		break;
+	case L2CAP_ATT_HANDLE_VALUE_NOTIFY:
+		step = g_new0(struct step, 1);
+
+		step->callback = CB_EMU_VALUE_NOTIFICATION;
+
+		schedule_callback_verification(step);
+		break;
 	default:
 		if (!gatt_pdu || !gatt_pdu->iov_base) {
 			tester_print("Unknown ATT packet.");
@@ -3091,6 +3177,76 @@ static struct test_case test_cases[] = {
 		CALLBACK_GATTS_SERVICE_DELETED(GATT_STATUS_FAILURE, APP1_ID,
 									NULL),
 	),
+	TEST_CASE_BREDRLE("Gatt Server - Send Indication",
+		ACTION_SUCCESS(init_pdus, send_indication_1),
+		ACTION_SUCCESS(bluetooth_enable_action, NULL),
+		CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+		ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
+		ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
+		ACTION_SUCCESS(emu_set_connect_cb_action, gatt_conn_cb),
+		ACTION_SUCCESS(gatt_server_register_action, &app1_uuid),
+		CALLBACK_STATUS(CB_GATTS_REGISTER_SERVER, BT_STATUS_SUCCESS),
+		ACTION_SUCCESS(bt_start_discovery_action, NULL),
+		CALLBACK_STATE(CB_BT_DISCOVERY_STATE_CHANGED,
+							BT_DISCOVERY_STARTED),
+		CALLBACK_DEVICE_FOUND(prop_emu_remotes_default_le_set, 2),
+		ACTION_SUCCESS(bt_cancel_discovery_action, NULL),
+		ACTION_SUCCESS(gatt_server_connect_action, &app1_conn_req),
+		CALLBACK_GATTS_CONNECTION(GATT_SERVER_CONNECTED,
+						prop_emu_remotes_default_set,
+						CONN1_ID, APP1_ID),
+		ACTION_SUCCESS(gatt_server_send_indication_action,
+						&send_indication_data_1),
+		CALLBACK(CB_EMU_VALUE_INDICATION),
+		ACTION_SUCCESS(bluetooth_disable_action, NULL),
+		CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+	),
+	TEST_CASE_BREDRLE("Gatt Server - Send Notification",
+		ACTION_SUCCESS(init_pdus, send_notification_1),
+		ACTION_SUCCESS(bluetooth_enable_action, NULL),
+		CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+		ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
+		ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
+		ACTION_SUCCESS(emu_set_connect_cb_action, gatt_conn_cb),
+		ACTION_SUCCESS(gatt_server_register_action, &app1_uuid),
+		CALLBACK_STATUS(CB_GATTS_REGISTER_SERVER, BT_STATUS_SUCCESS),
+		ACTION_SUCCESS(bt_start_discovery_action, NULL),
+		CALLBACK_STATE(CB_BT_DISCOVERY_STATE_CHANGED,
+							BT_DISCOVERY_STARTED),
+		CALLBACK_DEVICE_FOUND(prop_emu_remotes_default_le_set, 2),
+		ACTION_SUCCESS(bt_cancel_discovery_action, NULL),
+		ACTION_SUCCESS(gatt_server_connect_action, &app1_conn_req),
+		CALLBACK_GATTS_CONNECTION(GATT_SERVER_CONNECTED,
+						prop_emu_remotes_default_set,
+						CONN1_ID, APP1_ID),
+		ACTION_SUCCESS(gatt_server_send_indication_action,
+						&send_indication_data_2),
+		CALLBACK(CB_EMU_VALUE_NOTIFICATION),
+		ACTION_SUCCESS(bluetooth_disable_action, NULL),
+		CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+	),
+	TEST_CASE_BREDRLE("Gatt Server - Send Notification, wrong conn id",
+		ACTION_SUCCESS(bluetooth_enable_action, NULL),
+		CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+		ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
+		ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
+		ACTION_SUCCESS(emu_set_connect_cb_action, gatt_conn_cb),
+		ACTION_SUCCESS(gatt_server_register_action, &app1_uuid),
+		CALLBACK_STATUS(CB_GATTS_REGISTER_SERVER, BT_STATUS_SUCCESS),
+		ACTION_SUCCESS(bt_start_discovery_action, NULL),
+		CALLBACK_STATE(CB_BT_DISCOVERY_STATE_CHANGED,
+							BT_DISCOVERY_STARTED),
+		CALLBACK_DEVICE_FOUND(prop_emu_remotes_default_le_set, 2),
+		ACTION_SUCCESS(bt_cancel_discovery_action, NULL),
+		ACTION_SUCCESS(gatt_server_connect_action, &app1_conn_req),
+		CALLBACK_GATTS_CONNECTION(GATT_SERVER_CONNECTED,
+						prop_emu_remotes_default_set,
+						CONN1_ID, APP1_ID),
+		ACTION_FAIL(gatt_server_send_indication_action,
+						&send_bad_indication_data_1),
+		ACTION_SUCCESS(bluetooth_disable_action, NULL),
+		CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+	),
 };
 
 struct queue *get_gatt_tests(void)
diff --git a/android/tester-main.c b/android/tester-main.c
index a804f11..1018cae 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -107,6 +107,8 @@ static struct {
 	DBG_CB(CB_EMU_ENCRYPTION_ENABLED),
 	DBG_CB(CB_EMU_ENCRYPTION_DISABLED),
 	DBG_CB(CB_EMU_CONNECTION_REJECTED),
+	DBG_CB(CB_EMU_VALUE_INDICATION),
+	DBG_CB(CB_EMU_VALUE_NOTIFICATION),
 };
 
 static gboolean check_callbacks_called(gpointer user_data)
diff --git a/android/tester-main.h b/android/tester-main.h
index 22c5c8b..31d271a 100644
--- a/android/tester-main.h
+++ b/android/tester-main.h
@@ -469,6 +469,8 @@ typedef enum {
 	CB_EMU_ENCRYPTION_ENABLED,
 	CB_EMU_ENCRYPTION_DISABLED,
 	CB_EMU_CONNECTION_REJECTED,
+	CB_EMU_VALUE_INDICATION,
+	CB_EMU_VALUE_NOTIFICATION,
 } expected_bt_callback_t;
 
 struct test_data {
-- 
1.9.3


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

* [PATCH 7/8] android/tester: Add GATT server send response to read req test cases
  2014-10-17 13:38 [PATCH 1/8] android/gatt: Fix return status if cannot alloc memory Grzegorz Kolodziejczyk
                   ` (4 preceding siblings ...)
  2014-10-17 13:38 ` [PATCH 6/8] android/tester: Add GATT server send indication test cases Grzegorz Kolodziejczyk
@ 2014-10-17 13:38 ` Grzegorz Kolodziejczyk
  2014-10-17 13:38 ` [PATCH 8/8] android/tester: Add GATT server send response to write " Grzegorz Kolodziejczyk
  2014-10-24 12:18 ` [PATCH 1/8] android/gatt: Fix return status if cannot alloc memory Szymon Janc
  7 siblings, 0 replies; 9+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-10-17 13:38 UTC (permalink / raw)
  To: linux-bluetooth

This adds send response by server to read request test cases.
---
 android/tester-gatt.c | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++
 android/tester-main.c |  65 ++++++++++++++++++++-
 android/tester-main.h |  27 +++++++++
 3 files changed, 244 insertions(+), 1 deletion(-)

diff --git a/android/tester-gatt.c b/android/tester-gatt.c
index 2ceb295..6655f2d 100644
--- a/android/tester-gatt.c
+++ b/android/tester-gatt.c
@@ -21,8 +21,12 @@
 #include "tester-main.h"
 #include "src/shared/util.h"
 
+#define ATT_HANDLE_SIZE	2
+
 #define L2CAP_ATT_EXCHANGE_MTU_REQ	0x02
 #define L2CAP_ATT_EXCHANGE_MTU_RSP	0x03
+#define L2CAP_ATT_READ_REQ		0x0a
+#define L2CAP_ATT_READ_RSP		0x0b
 #define L2CAP_ATT_HANDLE_VALUE_NOTIFY	0x1b
 #define L2CAP_ATT_HANDLE_VALUE_IND	0x1d
 
@@ -39,6 +43,8 @@
 #define CONN1_ID	1
 #define CONN2_ID	2
 
+#define TRANS1_ID	1
+
 #define GATT_SERVER_TRANSPORT_LE		0x00
 #define GATT_SERVER_TRANSPORT_BREDR		0x01
 #define GATT_SERVER_TRANSPORT_LE_BREDR		0x02
@@ -52,6 +58,13 @@ static struct queue *list; /* List of gatt test cases */
 
 static int srvc1_handle;
 static int inc_srvc1_handle;
+static int char1_handle;
+
+struct set_att_data {
+	char *to;
+	char *from;
+	int len;
+};
 
 static bt_uuid_t app1_uuid = {
 	.uu = { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
@@ -187,6 +200,13 @@ struct send_indication_data {
 	char *p_value;
 };
 
+struct send_resp_data {
+	int conn_id;
+	int trans_id;
+	int status;
+	btgatt_response_t *response;
+};
+
 static bt_bdaddr_t emu_remote_bdaddr_val = {
 	.address = { 0x00, 0xaa, 0x01, 0x01, 0x00, 0x00 },
 };
@@ -746,6 +766,21 @@ static struct set_notify_params set_notify_param_2 = {
 	.bdaddr = &emu_remote_bdaddr_val
 };
 
+static btgatt_response_t response_1 = {
+	.handle = 0x1c,
+	.attr_value.auth_req = 0,
+	.attr_value.handle = 0x1d,
+	.attr_value.len = 0,
+	.attr_value.offset = 0,
+};
+
+static struct send_resp_data send_resp_data_1 = {
+	.conn_id = CONN1_ID,
+	.trans_id = TRANS1_ID,
+	.status = BT_STATUS_SUCCESS,
+	.response = &response_1,
+};
+
 static struct iovec search_service[] = {
 	raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28),
 	raw_pdu(0x11, 0x06, 0x01, 0x00, 0x10, 0x00, 0x00, 0x18),
@@ -1056,6 +1091,36 @@ static struct iovec send_notification_1[] = {
 	end_pdu
 };
 
+/* att commands define raw pdus */
+static struct iovec att_read_req = raw_pdu(0x0a, 0x00, 0x00);
+
+static void gatt_att_pdu_modify(void)
+{
+	struct test_data *data = tester_get_data();
+	struct step *current_data_step = queue_peek_head(data->steps);
+	struct iovec *store_pdu = current_data_step->set_data_to;
+	struct step *step = g_new0(struct step, 1);
+	unsigned char *raw_pdu = store_pdu->iov_base;
+	int set_data_len = current_data_step->set_data_len;
+
+	switch (raw_pdu[0]) {
+	case L2CAP_ATT_READ_REQ: {
+		uint16_t handle = *((int *)current_data_step->set_data);
+
+		memcpy(raw_pdu + 1, &handle, set_data_len);
+		tester_debug("gatt: modify pdu read request handle to 0x%02x",
+									handle);
+
+		break;
+	}
+
+	default:
+		break;
+	}
+
+	schedule_action_verification(step);
+}
+
 static void gatt_client_register_action(void)
 {
 	struct test_data *data = tester_get_data();
@@ -1520,6 +1585,22 @@ static void gatt_server_send_indication_action(void)
 	schedule_action_verification(step);
 }
 
+static void gatt_server_send_response_action(void)
+{
+	struct test_data *data = tester_get_data();
+	struct step *current_data_step = queue_peek_head(data->steps);
+	struct send_resp_data *send_resp_data = current_data_step->set_data;
+	struct step *step = g_new0(struct step, 1);
+
+	step->action_status = data->if_gatt->server->send_response(
+						send_resp_data->conn_id,
+						send_resp_data->trans_id,
+						send_resp_data->status,
+						send_resp_data->response);
+
+	schedule_action_verification(step);
+}
+
 static void gatt_cid_hook_cb(const void *data, uint16_t len, void *user_data)
 {
 	struct test_data *t_data = tester_get_data();
@@ -1559,6 +1640,14 @@ static void gatt_cid_hook_cb(const void *data, uint16_t len, void *user_data)
 
 		schedule_callback_verification(step);
 		break;
+	case L2CAP_ATT_READ_RSP:
+		/* TODO - More complicated cases should also verify pdu data */
+		step = g_new0(struct step, 1);
+
+		step->callback = CB_EMU_READ_RESPONSE;
+
+		schedule_callback_verification(step);
+		break;
 	default:
 		if (!gatt_pdu || !gatt_pdu->iov_base) {
 			tester_print("Unknown ATT packet.");
@@ -1607,6 +1696,26 @@ static void gatt_remote_send_frame_action(void)
 	schedule_action_verification(step);
 }
 
+static void gatt_remote_send_raw_pdu_action(void)
+{
+	struct test_data *data = tester_get_data();
+	struct bthost *bthost = hciemu_client_get_host(data->hciemu);
+	struct step *current_data_step = queue_peek_head(data->steps);
+	struct iovec *pdu = current_data_step->set_data;
+	struct step *step = g_new0(struct step, 1);
+
+	if (cid_data.handle && cid_data.cid) {
+		bthost_send_cid_v(bthost, cid_data.handle, cid_data.cid,
+									pdu, 1);
+		step->action_status = BT_STATUS_SUCCESS;
+	} else {
+		tester_debug("No connection set up");
+		step->action_status = BT_STATUS_FAIL;
+	}
+
+	schedule_action_verification(step);
+}
+
 static void gatt_conn_cb(uint16_t handle, void *user_data)
 {
 	struct test_data *data = tester_get_data();
@@ -3247,6 +3356,50 @@ static struct test_case test_cases[] = {
 		ACTION_SUCCESS(bluetooth_disable_action, NULL),
 		CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
 	),
+	TEST_CASE_BREDRLE("Gatt Server - Send response to read char request",
+		ACTION_SUCCESS(bluetooth_enable_action, NULL),
+		CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+		ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
+		ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
+		ACTION_SUCCESS(emu_set_connect_cb_action, gatt_conn_cb),
+		ACTION_SUCCESS(gatt_server_register_action, &app1_uuid),
+		CALLBACK_STATUS(CB_GATTS_REGISTER_SERVER, BT_STATUS_SUCCESS),
+		ACTION_SUCCESS(gatt_server_add_service_action,
+							&add_service_data_5),
+		CALLBACK_GATTS_SERVICE_ADDED(GATT_STATUS_SUCCESS, APP1_ID,
+							&service_add_1, NULL,
+							&srvc1_handle),
+		ACTION_SUCCESS(gatt_server_add_char_action, &add_char_data_1),
+		CALLBACK_GATTS_CHARACTERISTIC_ADDED(GATT_STATUS_SUCCESS,
+							APP1_ID, &app1_uuid,
+							&srvc1_handle, NULL,
+							&char1_handle),
+		ACTION_SUCCESS(gatt_server_start_srvc_action,
+							&start_srvc_data_2),
+		CALLBACK_GATTS_SERVICE_STARTED(GATT_STATUS_SUCCESS, APP1_ID,
+								&srvc1_handle),
+		ACTION_SUCCESS(bt_start_discovery_action, NULL),
+		CALLBACK_STATE(CB_BT_DISCOVERY_STATE_CHANGED,
+							BT_DISCOVERY_STARTED),
+		CALLBACK_DEVICE_FOUND(prop_emu_remotes_default_le_set, 2),
+		ACTION_SUCCESS(bt_cancel_discovery_action, NULL),
+		ACTION_SUCCESS(gatt_server_connect_action, &app1_conn_req),
+		CALLBACK_GATTS_CONNECTION(GATT_SERVER_CONNECTED,
+						prop_emu_remotes_default_set,
+						CONN1_ID, APP1_ID),
+		MODIFY_DATA(GATT_STATUS_SUCCESS, gatt_att_pdu_modify,
+						&char1_handle, &att_read_req,
+						ATT_HANDLE_SIZE),
+		ACTION_SUCCESS(gatt_remote_send_raw_pdu_action, &att_read_req),
+		CALLBACK_GATTS_REQUEST_READ(CONN1_ID, TRANS1_ID,
+						prop_emu_remotes_default_set,
+						&char1_handle, 0, false),
+		ACTION_SUCCESS(gatt_server_send_response_action,
+							&send_resp_data_1),
+		CALLBACK(CB_EMU_READ_RESPONSE),
+		ACTION_SUCCESS(bluetooth_disable_action, NULL),
+		CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+	),
 };
 
 struct queue *get_gatt_tests(void)
diff --git a/android/tester-main.c b/android/tester-main.c
index 1018cae..e9ebfdd 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -109,6 +109,7 @@ static struct {
 	DBG_CB(CB_EMU_CONNECTION_REJECTED),
 	DBG_CB(CB_EMU_VALUE_INDICATION),
 	DBG_CB(CB_EMU_VALUE_NOTIFICATION),
+	DBG_CB(CB_EMU_READ_RESPONSE),
 };
 
 static gboolean check_callbacks_called(gpointer user_data)
@@ -775,6 +776,16 @@ static bool match_data(struct step *step)
 		return false;
 	}
 
+	if (exp->callback_result.attr_handle &&
+					step->callback_result.attr_handle)
+		if (*exp->callback_result.attr_handle !=
+					*step->callback_result.attr_handle) {
+			tester_debug("Gatt attribute handle mismatch: %d vs %d",
+					*step->callback_result.attr_handle,
+					*exp->callback_result.attr_handle);
+			return false;
+		}
+
 	if (exp->callback_result.srvc_handle &&
 					step->callback_result.srvc_handle)
 		if (*exp->callback_result.srvc_handle !=
@@ -803,6 +814,27 @@ static bool match_data(struct step *step)
 			return false;
 		}
 
+	if (exp->callback_result.trans_id != step->callback_result.trans_id) {
+		tester_debug("Gatt trans id mismatch: %d vs %d",
+						exp->callback_result.trans_id,
+						step->callback_result.trans_id);
+		return false;
+	}
+
+	if (exp->callback_result.offset != step->callback_result.offset) {
+		tester_debug("Gatt offset mismatch: %d vs %d",
+						exp->callback_result.offset,
+						step->callback_result.offset);
+		return false;
+	}
+
+	if (exp->callback_result.is_long != step->callback_result.is_long) {
+		tester_debug("Gatt is long attr value flag mismatch: %d vs %d",
+						exp->callback_result.is_long,
+						step->callback_result.is_long);
+		return false;
+	}
+
 	if (exp->store_srvc_handle)
 		memcpy(exp->store_srvc_handle,
 					step->callback_result.srvc_handle,
@@ -931,6 +963,9 @@ static void destroy_callback_step(void *data)
 	if (step->callback_result.desc_handle)
 		free(step->callback_result.desc_handle);
 
+	if (step->callback_result.attr_handle)
+		free(step->callback_result.attr_handle);
+
 	g_free(step);
 	g_atomic_int_dec_and_test(&scheduled_cbacks_num);
 }
@@ -1652,6 +1687,34 @@ static void gatts_service_deleted_cb(int status, int server_if, int srvc_handle)
 	schedule_callback_verification(step);
 }
 
+static void gatts_request_read_cb(int conn_id, int trans_id, bt_bdaddr_t *bda,
+						int attr_handle, int offset,
+						bool is_long)
+{
+	struct step *step = g_new0(struct step, 1);
+	bt_property_t *props[1];
+
+	step->callback = CB_GATTS_REQUEST_READ;
+
+	step->callback_result.conn_id = conn_id;
+	step->callback_result.trans_id = trans_id;
+	step->callback_result.attr_handle = g_memdup(&attr_handle,
+							sizeof(attr_handle));
+	step->callback_result.offset = offset;
+	step->callback_result.is_long = is_long;
+
+	/* Utilize property verification mechanism for bdaddr */
+	props[0] = create_property(BT_PROPERTY_BDADDR, bda, sizeof(*bda));
+
+	step->callback_result.num_properties = 1;
+	step->callback_result.properties = repack_properties(1, props);
+
+	g_free(props[0]->val);
+	g_free(props[0]);
+
+	schedule_callback_verification(step);
+}
+
 static void pan_control_state_cb(btpan_control_state_t state,
 					bt_status_t error, int local_role,
 							const char *ifname)
@@ -1782,7 +1845,7 @@ static const btgatt_server_callbacks_t btgatt_server_callbacks = {
 	.service_started_cb = gatts_service_started_cb,
 	.service_stopped_cb = gatts_service_stopped_cb,
 	.service_deleted_cb = gatts_service_deleted_cb,
-	.request_read_cb = NULL,
+	.request_read_cb = gatts_request_read_cb,
 	.request_write_cb = NULL,
 	.request_exec_write_cb = NULL,
 	.response_confirmation_cb = NULL
diff --git a/android/tester-main.h b/android/tester-main.h
index 31d271a..e710a03 100644
--- a/android/tester-main.h
+++ b/android/tester-main.h
@@ -84,6 +84,14 @@ struct pdu_set {
 		(struct step[]) {__VA_ARGS__}, \
 	}
 
+#define MODIFY_DATA(status, modif_fun, from, to, len) { \
+		.action_status = status, \
+		.action = modif_fun, \
+		.set_data = from, \
+		.set_data_to = to, \
+		.set_data_len = len, \
+	}
+
 #define ACTION(status, act_fun, data_set) { \
 		.action_status = status, \
 		.action = act_fun, \
@@ -318,6 +326,19 @@ struct pdu_set {
 		.callback_result.srvc_handle = cb_srvc_handle, \
 	}
 
+#define CALLBACK_GATTS_REQUEST_READ(cb_conn_id, cb_trans_id, cb_prop, \
+						cb_attr_handle, cb_offset, \
+						cb_is_long) { \
+		.callback = CB_GATTS_REQUEST_READ, \
+		.callback_result.conn_id = cb_conn_id, \
+		.callback_result.trans_id = cb_trans_id, \
+		.callback_result.properties = cb_prop, \
+		.callback_result.num_properties = 1, \
+		.callback_result.attr_handle = cb_attr_handle, \
+		.callback_result.offset = cb_offset, \
+		.callback_result.is_long = cb_is_long, \
+	}
+
 #define CALLBACK_PAN_CTRL_STATE(cb, cb_res, cb_state, cb_local_role) { \
 		.callback = cb, \
 		.callback_result.status = cb_res, \
@@ -471,6 +492,7 @@ typedef enum {
 	CB_EMU_CONNECTION_REJECTED,
 	CB_EMU_VALUE_INDICATION,
 	CB_EMU_VALUE_NOTIFICATION,
+	CB_EMU_READ_RESPONSE,
 } expected_bt_callback_t;
 
 struct test_data {
@@ -568,7 +590,11 @@ struct bt_callback_data {
 
 	int gatt_app_id;
 	int conn_id;
+	int trans_id;
+	int offset;
+	bool is_long;
 	int connected;
+	int *attr_handle;
 	int *srvc_handle;
 	int *inc_srvc_handle;
 	int *char_handle;
@@ -607,6 +633,7 @@ struct step {
 	struct bt_callback_data callback_result;
 
 	void *set_data;
+	void *set_data_to;
 	int set_data_len;
 
 	int *store_srvc_handle;
-- 
1.9.3


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

* [PATCH 8/8] android/tester: Add GATT server send response to write req test cases
  2014-10-17 13:38 [PATCH 1/8] android/gatt: Fix return status if cannot alloc memory Grzegorz Kolodziejczyk
                   ` (5 preceding siblings ...)
  2014-10-17 13:38 ` [PATCH 7/8] android/tester: Add GATT server send response to read req " Grzegorz Kolodziejczyk
@ 2014-10-17 13:38 ` Grzegorz Kolodziejczyk
  2014-10-24 12:18 ` [PATCH 1/8] android/gatt: Fix return status if cannot alloc memory Szymon Janc
  7 siblings, 0 replies; 9+ messages in thread
From: Grzegorz Kolodziejczyk @ 2014-10-17 13:38 UTC (permalink / raw)
  To: linux-bluetooth

This adds send response by server to write request test cases.
---
 android/tester-gatt.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++
 android/tester-main.c |  73 +++++++++++++++++++++++++++-
 android/tester-main.h |  22 +++++++++
 3 files changed, 222 insertions(+), 1 deletion(-)

diff --git a/android/tester-gatt.c b/android/tester-gatt.c
index 6655f2d..f99100d 100644
--- a/android/tester-gatt.c
+++ b/android/tester-gatt.c
@@ -27,6 +27,8 @@
 #define L2CAP_ATT_EXCHANGE_MTU_RSP	0x03
 #define L2CAP_ATT_READ_REQ		0x0a
 #define L2CAP_ATT_READ_RSP		0x0b
+#define L2CAP_ATT_WRITE_REQ		0x12
+#define L2CAP_ATT_WRITE_RSP		0x13
 #define L2CAP_ATT_HANDLE_VALUE_NOTIFY	0x1b
 #define L2CAP_ATT_HANDLE_VALUE_IND	0x1d
 
@@ -54,6 +56,24 @@
 #define GATT_WRITE_TYPE_PREPARE		0x03
 #define GATT_WRITE_TYPE_SIGNED		0x04
 
+#define CHAR_PROP_BROADCAST			0x01
+#define CHAR_PROP_READ				0x02
+#define CHAR_PROP_WRITE_WITHOUT_RESPONSE	0x04
+#define CHAR_PROP_WRITE				0x08
+#define CHAR_PROP_NOTIFY			0x10
+#define CHAR_PROP_INDICATE			0x20
+#define CHAR_PROP_AUTHENTICATED_SIGNED_WRITES	0x40
+#define CHAR_PROP_EXTENDED_PROPERTIES		0x80
+
+#define CHAR_PERM_READ			0x0001
+#define CHAR_PERM_READ_ENCRYPTED	0x0002
+#define CHAR_PERM_READ_ENCRYPTED_MITM	0x0004
+#define CHAR_PERM_WRITE			0x0010
+#define CHAR_PERM_WRITE_ENCRYPTED	0x0020
+#define CHAR_PERM_WRITE_ENCRYPTED_MITM	0x0040
+#define CHAR_PERM_WRITE_SIGNED		0x0080
+#define CHAR_PERM_WRITE_SIGNED_MITM	0x0100
+
 static struct queue *list; /* List of gatt test cases */
 
 static int srvc1_handle;
@@ -66,6 +86,11 @@ struct set_att_data {
 	int len;
 };
 
+struct att_write_req_data {
+	int *attr_handle;
+	uint8_t *value;
+};
+
 static bt_uuid_t app1_uuid = {
 	.uu = { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
 				0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 },
@@ -78,6 +103,8 @@ static bt_uuid_t app2_uuid = {
 
 static uint8_t value_1[] = {0x01};
 
+static uint8_t att_write_req_value_1[] = {0x00, 0x01, 0x02, 0x03};
+
 struct gatt_connect_data {
 	const int app_id;
 	const int conn_id;
@@ -521,6 +548,14 @@ static struct add_char_data add_char_data_1 = {
 	.permissions = 0
 };
 
+static struct add_char_data add_char_data_2 = {
+	.app_id = APP1_ID,
+	.srvc_handle = &srvc1_handle,
+	.uuid = &app1_uuid,
+	.properties = CHAR_PROP_WRITE,
+	.permissions = CHAR_PERM_WRITE
+};
+
 static struct add_char_data add_bad_char_data_1 = {
 	.app_id = APP1_ID,
 	.srvc_handle = &srvc_bad_handle,
@@ -774,6 +809,14 @@ static btgatt_response_t response_1 = {
 	.attr_value.offset = 0,
 };
 
+static btgatt_response_t response_2 = {
+	.handle = 0x1c,
+	.attr_value.auth_req = 0,
+	.attr_value.handle = 0x1d,
+	.attr_value.len = sizeof(att_write_req_value_1),
+	.attr_value.offset = 0,
+};
+
 static struct send_resp_data send_resp_data_1 = {
 	.conn_id = CONN1_ID,
 	.trans_id = TRANS1_ID,
@@ -781,6 +824,13 @@ static struct send_resp_data send_resp_data_1 = {
 	.response = &response_1,
 };
 
+static struct send_resp_data send_resp_data_2 = {
+	.conn_id = CONN1_ID,
+	.trans_id = TRANS1_ID,
+	.status = BT_STATUS_SUCCESS,
+	.response = &response_2,
+};
+
 static struct iovec search_service[] = {
 	raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28),
 	raw_pdu(0x11, 0x06, 0x01, 0x00, 0x10, 0x00, 0x00, 0x18),
@@ -1091,8 +1141,15 @@ static struct iovec send_notification_1[] = {
 	end_pdu
 };
 
+static struct att_write_req_data att_write_req_data_1  = {
+	.attr_handle = &char1_handle,
+	.value = att_write_req_value_1,
+};
+
 /* att commands define raw pdus */
 static struct iovec att_read_req = raw_pdu(0x0a, 0x00, 0x00);
+static struct iovec att_write_req_1 = raw_pdu(0x12, 0x00, 0x00, 0x00, 0x00,
+								0x00, 0x00);
 
 static void gatt_att_pdu_modify(void)
 {
@@ -1114,7 +1171,21 @@ static void gatt_att_pdu_modify(void)
 		break;
 	}
 
+	case L2CAP_ATT_WRITE_REQ: {
+		struct att_write_req_data *pdu_set_data =
+						current_data_step->set_data;
+		uint16_t handle = *((int *)(pdu_set_data->attr_handle));
+		uint8_t *value = pdu_set_data->value;
+
+		memcpy(raw_pdu + 1, &handle, sizeof(handle));
+		memcpy(raw_pdu + 3, value, set_data_len - sizeof(handle));
+
+		break;
+	}
 	default:
+		tester_debug("modify att pdu with opcode 0x%02x not handled",
+								raw_pdu[0]);
+
 		break;
 	}
 
@@ -1648,6 +1719,14 @@ static void gatt_cid_hook_cb(const void *data, uint16_t len, void *user_data)
 
 		schedule_callback_verification(step);
 		break;
+	case L2CAP_ATT_WRITE_RSP:
+		/* TODO - More complicated cases should also verify pdu data */
+		step = g_new0(struct step, 1);
+
+		step->callback = CB_EMU_WRITE_RESPONSE;
+
+		schedule_callback_verification(step);
+		break;
 	default:
 		if (!gatt_pdu || !gatt_pdu->iov_base) {
 			tester_print("Unknown ATT packet.");
@@ -3400,6 +3479,55 @@ static struct test_case test_cases[] = {
 		ACTION_SUCCESS(bluetooth_disable_action, NULL),
 		CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
 	),
+	TEST_CASE_BREDRLE("Gatt Server - Send response to write char request",
+		ACTION_SUCCESS(bluetooth_enable_action, NULL),
+		CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_ON),
+		ACTION_SUCCESS(emu_setup_powered_remote_action, NULL),
+		ACTION_SUCCESS(emu_set_ssp_mode_action, NULL),
+		ACTION_SUCCESS(emu_set_connect_cb_action, gatt_conn_cb),
+		ACTION_SUCCESS(gatt_server_register_action, &app1_uuid),
+		CALLBACK_STATUS(CB_GATTS_REGISTER_SERVER, BT_STATUS_SUCCESS),
+		ACTION_SUCCESS(gatt_server_add_service_action,
+							&add_service_data_5),
+		CALLBACK_GATTS_SERVICE_ADDED(GATT_STATUS_SUCCESS, APP1_ID,
+							&service_add_1, NULL,
+							&srvc1_handle),
+		ACTION_SUCCESS(gatt_server_add_char_action, &add_char_data_2),
+		CALLBACK_GATTS_CHARACTERISTIC_ADDED(GATT_STATUS_SUCCESS,
+							APP1_ID, &app1_uuid,
+							&srvc1_handle, NULL,
+							&char1_handle),
+		ACTION_SUCCESS(gatt_server_start_srvc_action,
+							&start_srvc_data_2),
+		CALLBACK_GATTS_SERVICE_STARTED(GATT_STATUS_SUCCESS, APP1_ID,
+								&srvc1_handle),
+		ACTION_SUCCESS(bt_start_discovery_action, NULL),
+		CALLBACK_STATE(CB_BT_DISCOVERY_STATE_CHANGED,
+							BT_DISCOVERY_STARTED),
+		CALLBACK_DEVICE_FOUND(prop_emu_remotes_default_le_set, 2),
+		ACTION_SUCCESS(bt_cancel_discovery_action, NULL),
+		ACTION_SUCCESS(gatt_server_connect_action, &app1_conn_req),
+		CALLBACK_GATTS_CONNECTION(GATT_SERVER_CONNECTED,
+						prop_emu_remotes_default_set,
+						CONN1_ID, APP1_ID),
+		MODIFY_DATA(GATT_STATUS_SUCCESS, gatt_att_pdu_modify,
+					&att_write_req_data_1, &att_write_req_1,
+					sizeof(att_write_req_value_1) +
+					ATT_HANDLE_SIZE),
+		ACTION_SUCCESS(gatt_remote_send_raw_pdu_action,
+							&att_write_req_1),
+		CALLBACK_GATTS_REQUEST_WRITE(CONN1_ID, TRANS1_ID,
+						prop_emu_remotes_default_set,
+						&char1_handle, 0,
+						sizeof(att_write_req_value_1),
+						true, false,
+						att_write_req_value_1),
+		ACTION_SUCCESS(gatt_server_send_response_action,
+							&send_resp_data_2),
+		CALLBACK(CB_EMU_WRITE_RESPONSE),
+		ACTION_SUCCESS(bluetooth_disable_action, NULL),
+		CALLBACK_STATE(CB_BT_ADAPTER_STATE_CHANGED, BT_STATE_OFF),
+	),
 };
 
 struct queue *get_gatt_tests(void)
diff --git a/android/tester-main.c b/android/tester-main.c
index e9ebfdd..270be18 100644
--- a/android/tester-main.c
+++ b/android/tester-main.c
@@ -110,6 +110,7 @@ static struct {
 	DBG_CB(CB_EMU_VALUE_INDICATION),
 	DBG_CB(CB_EMU_VALUE_NOTIFICATION),
 	DBG_CB(CB_EMU_READ_RESPONSE),
+	DBG_CB(CB_EMU_WRITE_RESPONSE),
 };
 
 static gboolean check_callbacks_called(gpointer user_data)
@@ -835,6 +836,41 @@ static bool match_data(struct step *step)
 		return false;
 	}
 
+	if (exp->callback_result.length > 0) {
+		if (exp->callback_result.length !=
+						step->callback_result.length) {
+			tester_debug("Gatt attr length mismatch: %d vs %d",
+						exp->callback_result.length,
+						step->callback_result.length);
+			return false;
+		}
+		if (!exp->callback_result.value ||
+						!step->callback_result.value) {
+			tester_debug("Gatt attr values are wrong set");
+			return false;
+		}
+		if (!memcmp(exp->callback_result.value,
+						step->callback_result.value,
+						exp->callback_result.length)) {
+			tester_debug("Gatt attr value mismatch");
+			return false;
+		}
+	}
+
+	if (exp->callback_result.need_rsp != step->callback_result.need_rsp) {
+		tester_debug("Gatt need response value flag mismatch: %d vs %d",
+						exp->callback_result.need_rsp,
+						step->callback_result.need_rsp);
+		return false;
+	}
+
+	if (exp->callback_result.is_prep != step->callback_result.is_prep) {
+		tester_debug("Gatt is prepared value flag mismatch: %d vs %d",
+						exp->callback_result.is_prep,
+						step->callback_result.is_prep);
+		return false;
+	}
+
 	if (exp->store_srvc_handle)
 		memcpy(exp->store_srvc_handle,
 					step->callback_result.srvc_handle,
@@ -966,6 +1002,9 @@ static void destroy_callback_step(void *data)
 	if (step->callback_result.attr_handle)
 		free(step->callback_result.attr_handle);
 
+	if (step->callback_result.value)
+		free(step->callback_result.value);
+
 	g_free(step);
 	g_atomic_int_dec_and_test(&scheduled_cbacks_num);
 }
@@ -1715,6 +1754,38 @@ static void gatts_request_read_cb(int conn_id, int trans_id, bt_bdaddr_t *bda,
 	schedule_callback_verification(step);
 }
 
+static void gatts_request_write_cb(int conn_id, int trans_id, bt_bdaddr_t *bda,
+						int attr_handle, int offset,
+						int length, bool need_rsp,
+						bool is_prep, uint8_t *value)
+{
+	struct step *step = g_new0(struct step, 1);
+	bt_property_t *props[1];
+
+	step->callback = CB_GATTS_REQUEST_WRITE;
+
+	step->callback_result.conn_id = conn_id;
+	step->callback_result.trans_id = trans_id;
+	step->callback_result.attr_handle = g_memdup(&attr_handle,
+							sizeof(attr_handle));
+	step->callback_result.offset = offset;
+	step->callback_result.length = length;
+	step->callback_result.need_rsp = need_rsp;
+	step->callback_result.is_prep = is_prep;
+	step->callback_result.value = g_memdup(&value, length);
+
+	/* Utilize property verification mechanism for bdaddr */
+	props[0] = create_property(BT_PROPERTY_BDADDR, bda, sizeof(*bda));
+
+	step->callback_result.num_properties = 1;
+	step->callback_result.properties = repack_properties(1, props);
+
+	g_free(props[0]->val);
+	g_free(props[0]);
+
+	schedule_callback_verification(step);
+}
+
 static void pan_control_state_cb(btpan_control_state_t state,
 					bt_status_t error, int local_role,
 							const char *ifname)
@@ -1846,7 +1917,7 @@ static const btgatt_server_callbacks_t btgatt_server_callbacks = {
 	.service_stopped_cb = gatts_service_stopped_cb,
 	.service_deleted_cb = gatts_service_deleted_cb,
 	.request_read_cb = gatts_request_read_cb,
-	.request_write_cb = NULL,
+	.request_write_cb = gatts_request_write_cb,
 	.request_exec_write_cb = NULL,
 	.response_confirmation_cb = NULL
 };
diff --git a/android/tester-main.h b/android/tester-main.h
index e710a03..c938d44 100644
--- a/android/tester-main.h
+++ b/android/tester-main.h
@@ -339,6 +339,23 @@ struct pdu_set {
 		.callback_result.is_long = cb_is_long, \
 	}
 
+#define CALLBACK_GATTS_REQUEST_WRITE(cb_conn_id, cb_trans_id, cb_prop, \
+						cb_attr_handle, cb_offset, \
+						cb_length, cb_need_rsp, \
+						cb_is_prep, cb_value) { \
+		.callback = CB_GATTS_REQUEST_WRITE, \
+		.callback_result.conn_id = cb_conn_id, \
+		.callback_result.trans_id = cb_trans_id, \
+		.callback_result.properties = cb_prop, \
+		.callback_result.num_properties = 1, \
+		.callback_result.attr_handle = cb_attr_handle, \
+		.callback_result.offset = cb_offset, \
+		.callback_result.length = cb_length, \
+		.callback_result.need_rsp = cb_need_rsp, \
+		.callback_result.is_prep = cb_is_prep, \
+		.callback_result.value = cb_value, \
+	}
+
 #define CALLBACK_PAN_CTRL_STATE(cb, cb_res, cb_state, cb_local_role) { \
 		.callback = cb, \
 		.callback_result.status = cb_res, \
@@ -493,6 +510,7 @@ typedef enum {
 	CB_EMU_VALUE_INDICATION,
 	CB_EMU_VALUE_NOTIFICATION,
 	CB_EMU_READ_RESPONSE,
+	CB_EMU_WRITE_RESPONSE,
 } expected_bt_callback_t;
 
 struct test_data {
@@ -608,6 +626,10 @@ struct bt_callback_data {
 	btgatt_notify_params_t *notify_params;
 	int notification_registered;
 	int char_prop;
+	int length;
+	uint8_t *value;
+	bool need_rsp;
+	bool is_prep;
 
 	btpan_control_state_t ctrl_state;
 	btpan_connection_state_t conn_state;
-- 
1.9.3


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

* Re: [PATCH 1/8] android/gatt: Fix return status if cannot alloc memory
  2014-10-17 13:38 [PATCH 1/8] android/gatt: Fix return status if cannot alloc memory Grzegorz Kolodziejczyk
                   ` (6 preceding siblings ...)
  2014-10-17 13:38 ` [PATCH 8/8] android/tester: Add GATT server send response to write " Grzegorz Kolodziejczyk
@ 2014-10-24 12:18 ` Szymon Janc
  7 siblings, 0 replies; 9+ messages in thread
From: Szymon Janc @ 2014-10-24 12:18 UTC (permalink / raw)
  To: Grzegorz Kolodziejczyk; +Cc: linux-bluetooth

Hi Grzegorz,

On Friday 17 of October 2014 15:38:12 Grzegorz Kolodziejczyk wrote:
> NOMEM HAL status should be returned in case if it's not possible to
> alloc memory for notifiaction data.
> ---
>  android/gatt.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/android/gatt.c b/android/gatt.c
> index ea20941..c26d45a 100644
> --- a/android/gatt.c
> +++ b/android/gatt.c
> @@ -3759,7 +3759,7 @@ static void handle_client_register_for_notification(const void *buf,
>  
>  	notification = new0(struct notification_data, 1);
>  	if (!notification) {
> -		status = HAL_STATUS_FAILED;
> +		status = HAL_STATUS_NOMEM;
>  		goto failed;
>  	}
>  

All patches have been applied. Thanks. 

-- 
Best regards, 
Szymon Janc

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

end of thread, other threads:[~2014-10-24 12:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-17 13:38 [PATCH 1/8] android/gatt: Fix return status if cannot alloc memory Grzegorz Kolodziejczyk
2014-10-17 13:38 ` [PATCH 2/8] android/tester: Define write types for GATT test cases Grzegorz Kolodziejczyk
2014-10-17 13:38 ` [PATCH 3/8] android/tester: Fix hardcoded length values Grzegorz Kolodziejczyk
2014-10-17 13:38 ` [PATCH 4/8] android/tester: Use BT_STATUS defines instead of hardcoded values Grzegorz Kolodziejczyk
2014-10-17 13:38 ` [PATCH 5/8] android/tester: Add att pdu remote receive debug log Grzegorz Kolodziejczyk
2014-10-17 13:38 ` [PATCH 6/8] android/tester: Add GATT server send indication test cases Grzegorz Kolodziejczyk
2014-10-17 13:38 ` [PATCH 7/8] android/tester: Add GATT server send response to read req " Grzegorz Kolodziejczyk
2014-10-17 13:38 ` [PATCH 8/8] android/tester: Add GATT server send response to write " Grzegorz Kolodziejczyk
2014-10-24 12:18 ` [PATCH 1/8] android/gatt: Fix return status if cannot alloc memory 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).