From: Johan Hedberg Date: Thu, 19 Sep 2013 16:59:30 +0000 (+0300) Subject: tools/l2cap-tester: Add LE support X-Git-Tag: android-x86-4.4-r3~7541 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=f203ef5eae676a41bfe2d11ff35fd0b9703e1a1b;p=android-x86%2Fexternal-bluetooth-bluez.git tools/l2cap-tester: Add LE support --- diff --git a/tools/l2cap-tester.c b/tools/l2cap-tester.c index 6f267d253..35cb2f5fa 100644 --- a/tools/l2cap-tester.c +++ b/tools/l2cap-tester.c @@ -212,13 +212,27 @@ static void test_data_free(void *test_data) free(data); } -#define test_l2cap(name, data, setup, func) \ +#define test_l2cap_bredr(name, data, setup, func) \ do { \ struct test_data *user; \ user = malloc(sizeof(struct test_data)); \ if (!user) \ break; \ - user->hciemu_type = HCIEMU_TYPE_BREDRLE; \ + user->hciemu_type = HCIEMU_TYPE_BREDR; \ + user->io_id = 0; \ + user->test_data = data; \ + tester_add_full(name, data, \ + test_pre_setup, setup, func, NULL, \ + test_post_teardown, 2, user, test_data_free); \ + } while (0) + +#define test_l2cap_le(name, data, setup, func) \ + do { \ + struct test_data *user; \ + user = malloc(sizeof(struct test_data)); \ + if (!user) \ + break; \ + user->hciemu_type = HCIEMU_TYPE_LE; \ user->io_id = 0; \ user->test_data = data; \ tester_add_full(name, data, \ @@ -301,8 +315,13 @@ static void client_connectable_complete(uint16_t opcode, uint8_t status, const void *param, uint8_t len, void *user_data) { - if (opcode != BT_HCI_CMD_WRITE_SCAN_ENABLE) + switch (opcode) { + case BT_HCI_CMD_WRITE_SCAN_ENABLE: + case BT_HCI_CMD_LE_SET_ADV_ENABLE: + break; + default: return; + } tester_print("Client set connectable status 0x%02x", status); @@ -327,7 +346,10 @@ static void setup_powered_callback(uint8_t status, uint16_t length, bthost = hciemu_client_get_host(data->hciemu); bthost_set_cmd_complete_cb(bthost, client_connectable_complete, data); - bthost_write_scan_enable(bthost, 0x03); + if (data->hciemu_type == HCIEMU_TYPE_LE) + bthost_set_adv_enable(bthost, 0x01); + else + bthost_write_scan_enable(bthost, 0x03); } static void setup_powered(const void *test_data) @@ -337,15 +359,16 @@ static void setup_powered(const void *test_data) tester_print("Powering on controller"); - mgmt_send(data->mgmt, MGMT_OP_SET_CONNECTABLE, data->mgmt_index, - sizeof(param), param, - NULL, NULL, NULL); - - mgmt_send(data->mgmt, MGMT_OP_SET_SSP, data->mgmt_index, + if (data->hciemu_type == HCIEMU_TYPE_BREDR) { + mgmt_send(data->mgmt, MGMT_OP_SET_CONNECTABLE, data->mgmt_index, + sizeof(param), param, + NULL, NULL, NULL); + mgmt_send(data->mgmt, MGMT_OP_SET_SSP, data->mgmt_index, sizeof(param), param, NULL, NULL, NULL); - - mgmt_send(data->mgmt, MGMT_OP_SET_LE, data->mgmt_index, + } else { + mgmt_send(data->mgmt, MGMT_OP_SET_LE, data->mgmt_index, sizeof(param), param, NULL, NULL, NULL); + } mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index, sizeof(param), param, @@ -424,6 +447,10 @@ static int create_l2cap_sock(struct test_data *data, uint16_t psm) addr.l2_family = AF_BLUETOOTH; addr.l2_psm = htobs(psm); bacpy(&addr.l2_bdaddr, (void *) master_bdaddr); + if (data->hciemu_type == HCIEMU_TYPE_LE) + addr.l2_bdaddr_type = BDADDR_LE_PUBLIC; + else + addr.l2_bdaddr_type = BDADDR_BREDR; if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) { err = -errno; @@ -452,6 +479,10 @@ static int connect_l2cap_sock(struct test_data *data, int sk, uint16_t psm) addr.l2_family = AF_BLUETOOTH; bacpy(&addr.l2_bdaddr, (void *) client_bdaddr); addr.l2_psm = htobs(psm); + if (data->hciemu_type == HCIEMU_TYPE_LE) + addr.l2_bdaddr_type = BDADDR_LE_PUBLIC; + else + addr.l2_bdaddr_type = BDADDR_BREDR; err = connect(sk, (struct sockaddr *) &addr, sizeof(addr)); if (err < 0 && !(errno == EAGAIN || errno == EINPROGRESS)) { @@ -464,7 +495,7 @@ static int connect_l2cap_sock(struct test_data *data, int sk, uint16_t psm) return 0; } -static void test_bredr_connect(const void *test_data) +static void test_connect(const void *test_data) { struct test_data *data = tester_get_data(); const struct l2cap_client_data *l2data = data->test_data; @@ -642,28 +673,29 @@ int main(int argc, char *argv[]) { tester_init(&argc, &argv); - test_l2cap("Basic L2CAP Socket - Success", NULL, setup_powered, + test_l2cap_bredr("Basic L2CAP Socket - Success", NULL, setup_powered, test_basic); - test_l2cap("L2CAP BR/EDR Client - Success", + test_l2cap_bredr("L2CAP BR/EDR Client - Success", &client_connect_success_test, - setup_powered, test_bredr_connect); - test_l2cap("L2CAP BR/EDR Client - Invalid PSM", + setup_powered, test_connect); + test_l2cap_bredr("L2CAP BR/EDR Client - Invalid PSM", &client_connect_nval_psm_test, - setup_powered, test_bredr_connect); + setup_powered, test_connect); - test_l2cap("L2CAP BR/EDR Server - Success", &l2cap_server_success_test, + test_l2cap_bredr("L2CAP BR/EDR Server - Success", + &l2cap_server_success_test, setup_powered, test_bredr_server); - test_l2cap("L2CAP BR/EDR Server - Invalid PSM", + test_l2cap_bredr("L2CAP BR/EDR Server - Invalid PSM", &l2cap_server_nval_psm_test, setup_powered, test_bredr_server); - test_l2cap("L2CAP BR/EDR Server - Invalid PDU", + test_l2cap_bredr("L2CAP BR/EDR Server - Invalid PDU", &l2cap_server_nval_pdu_test1, setup_powered, test_bredr_server); - test_l2cap("L2CAP BR/EDR Server - Invalid Disconnect CID", + test_l2cap_bredr("L2CAP BR/EDR Server - Invalid Disconnect CID", &l2cap_server_nval_cid_test1, setup_powered, test_bredr_server); - test_l2cap("L2CAP BR/EDR Server - Invalid Config CID", + test_l2cap_bredr("L2CAP BR/EDR Server - Invalid Config CID", &l2cap_server_nval_cid_test2, setup_powered, test_bredr_server);