summaryrefslogtreecommitdiff
path: root/tools/l2cap-tester.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2014-01-21 12:52:18 +0200
committerJohan Hedberg <johan.hedberg@intel.com>2014-01-21 12:52:18 +0200
commit3c9caf5bdc8cf8fe1e2c44814e48c06bf90ede69 (patch)
tree42128d07a11eb7d4282bf1cbbabb6d43fd5dc75a /tools/l2cap-tester.c
parentdafd46e0784ecd47e8798c60a7bacc3ed20185dd (diff)
downloadbluez-3c9caf5bdc8cf8fe1e2c44814e48c06bf90ede69.tar.gz
tools/l2cap-tester: Add support for custom responses for client tests
Diffstat (limited to 'tools/l2cap-tester.c')
-rw-r--r--tools/l2cap-tester.c54
1 files changed, 52 insertions, 2 deletions
diff --git a/tools/l2cap-tester.c b/tools/l2cap-tester.c
index 38cbb5f80..4e114bdfd 100644
--- a/tools/l2cap-tester.c
+++ b/tools/l2cap-tester.c
@@ -592,6 +592,50 @@ static void pin_code_request_callback(uint16_t index, uint16_t length,
sizeof(cp), &cp, NULL, NULL, NULL);
}
+static void bthost_send_rsp(const void *buf, uint16_t len, void *user_data)
+{
+ struct test_data *data = tester_get_data();
+ const struct l2cap_data *l2data = data->test_data;
+ struct bthost *bthost;
+
+ if (l2data->expect_cmd_len && len != l2data->expect_cmd_len) {
+ tester_test_failed();
+ return;
+ }
+
+ if (l2data->expect_cmd && memcmp(buf, l2data->expect_cmd,
+ l2data->expect_cmd_len)) {
+ tester_test_failed();
+ return;
+ }
+
+ if (!l2data->send_cmd)
+ return;
+
+ bthost = hciemu_client_get_host(data->hciemu);
+ bthost_send_cid(bthost, data->handle, data->dcid,
+ l2data->send_cmd, l2data->send_cmd_len);
+}
+
+static void send_rsp_new_conn(uint16_t handle, void *user_data)
+{
+ struct test_data *data = user_data;
+ struct bthost *bthost;
+
+ tester_print("New connection with handle 0x%04x", handle);
+
+ data->handle = handle;
+
+ if (data->hciemu_type == HCIEMU_TYPE_LE)
+ data->dcid = 0x0005;
+ else
+ data->dcid = 0x0001;
+
+ bthost = hciemu_client_get_host(data->hciemu);
+ bthost_add_cid_hook(bthost, data->handle, data->dcid,
+ bthost_send_rsp, NULL);
+}
+
static void setup_powered_common(void)
{
struct test_data *data = tester_get_data();
@@ -629,12 +673,18 @@ static void setup_powered_common(void)
static void setup_powered_client(const void *test_data)
{
struct test_data *data = tester_get_data();
+ const struct l2cap_data *test = data->test_data;
unsigned char param[] = { 0x01 };
setup_powered_common();
tester_print("Powering on controller");
+ if (test->expect_cmd || test->send_cmd) {
+ struct bthost *bthost = hciemu_client_get_host(data->hciemu);
+ bthost_set_connect_cb(bthost, send_rsp_new_conn, data);
+ }
+
mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index,
sizeof(param), param, setup_powered_client_callback,
NULL, NULL);
@@ -1067,7 +1117,7 @@ failed:
tester_test_failed();
}
-static void client_new_conn(uint16_t handle, void *user_data)
+static void send_req_new_conn(uint16_t handle, void *user_data)
{
struct test_data *data = user_data;
const struct l2cap_data *l2data = data->test_data;
@@ -1138,7 +1188,7 @@ static void test_server(const void *test_data)
}
bthost = hciemu_client_get_host(data->hciemu);
- bthost_set_connect_cb(bthost, client_new_conn, data);
+ bthost_set_connect_cb(bthost, send_req_new_conn, data);
if (data->hciemu_type == HCIEMU_TYPE_BREDR)
addr_type = BDADDR_BREDR;