summaryrefslogtreecommitdiff
path: root/android/tester-gatt.c
diff options
context:
space:
mode:
authorJakub Tyszkowski <jakub.tyszkowski@tieto.com>2015-01-08 10:17:42 +0100
committerSzymon Janc <szymon.janc@tieto.com>2015-01-13 14:46:53 +0100
commita9f6a0e15d1c665f275459b05e7a6a0d0da816a4 (patch)
tree563f2a765d241450b4e7eedd591a0a89275ba8e0 /android/tester-gatt.c
parent06c65aaee7dde41e335dd21d0ab92271e99feec0 (diff)
downloadbluez-a9f6a0e15d1c665f275459b05e7a6a0d0da816a4.tar.gz
android/tester: Use multiple iovecs instead of one large buffer
This simplifies sending pdus which are made of header ond few other parts by using multiple iovectors instead of copying buffers and aggregating data in some additional structures.
Diffstat (limited to 'android/tester-gatt.c')
-rw-r--r--android/tester-gatt.c80
1 files changed, 18 insertions, 62 deletions
diff --git a/android/tester-gatt.c b/android/tester-gatt.c
index a8dbd353c..644e2049d 100644
--- a/android/tester-gatt.c
+++ b/android/tester-gatt.c
@@ -85,6 +85,11 @@ static uint16_t srvc1_handle;
static uint16_t inc_srvc1_handle;
static uint16_t char1_handle;
+static struct iovec char1_handle_v = {
+ .iov_base = &char1_handle,
+ .iov_len = sizeof(char1_handle),
+};
+
struct set_att_data {
char *to;
char *from;
@@ -109,6 +114,10 @@ static bt_uuid_t app2_uuid = {
static uint8_t value_1[] = {0x01};
static uint8_t att_write_req_value_1[] = {0x00, 0x01, 0x02, 0x03};
+static struct iovec att_write_req_value_1_v = {
+ .iov_base = att_write_req_value_1,
+ .iov_len = sizeof(att_write_req_value_1),
+};
struct gatt_connect_data {
const int app_id;
@@ -1065,59 +1074,9 @@ 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)
-{
- 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_2;
- 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;
- }
-
- 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));
-
- tester_debug("gatt: modify pdu write request handle to 0x%02x",
- handle);
-
- break;
- }
- default:
- tester_debug("modify att pdu with opcode 0x%02x not handled",
- raw_pdu[0]);
-
- break;
- }
-
- schedule_action_verification(step);
-}
+static struct iovec att_read_req_op_v = raw_pdu(L2CAP_ATT_READ_REQ);
+static struct iovec att_write_req_op_v = raw_pdu(L2CAP_ATT_WRITE_REQ);
static void gatt_client_register_action(void)
{
@@ -3352,10 +3311,9 @@ static struct test_case test_cases[] = {
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),
+ PROCESS_DATA(GATT_STATUS_SUCCESS,
+ gatt_remote_send_raw_pdu_action,
+ &att_read_req_op_v, &char1_handle_v, NULL),
CALLBACK_GATTS_REQUEST_READ(CONN1_ID, TRANS1_ID,
prop_emu_remotes_default_set,
&char1_handle, 0, false),
@@ -3396,12 +3354,10 @@ static struct test_case test_cases[] = {
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),
+ PROCESS_DATA(GATT_STATUS_SUCCESS,
+ gatt_remote_send_raw_pdu_action,
+ &att_write_req_op_v, &char1_handle_v,
+ &att_write_req_value_1_v),
CALLBACK_GATTS_REQUEST_WRITE(CONN1_ID, TRANS1_ID,
prop_emu_remotes_default_set,
&char1_handle, 0,