2015-02-11 11:32:08

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH v2 0/4] Testcases to verify HCI_LE_ENABLE fix in kernel

Following patches should get in if kernel fix for HCI_LE_ENABLE
gets upstream
[PATCH v2 1/3] Bluetooth: Do not allow LE connection if LE is not
enabled

Here we have 2 test cases on mgmt and l2cap level verifying that
LE connection will be rejected if LE host support is not enabled.

Also small update to error codes in mgmt-api has been added as now
Pair Device might return MGMT_RESULT_REJECT if user tries to make
connection on transport which is not enabled

v2:
* added new test cases for v2 of kernel patch.
* Added "Not Supported" error code to mgmt-api.txt
* Update test-coverage.txt

Lukasz Rymanowski (4):
tools/mgmt-tester: Add test for pair on not enabled transport
tools/mgmt-tester: Add test for pair on not supported transport
tools/l2cap-tester: Add L2CAP LE Connection Reject test
doc/mgmt-api: Update error codes for Pair Device Command

doc/mgmt-api.txt | 9 ++++++-
tools/l2cap-tester.c | 45 +++++++++++++++++++++++++++++++--
tools/mgmt-tester.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 120 insertions(+), 5 deletions(-)

--
1.8.4



2015-02-12 21:06:43

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH v2 0/4] Testcases to verify HCI_LE_ENABLE fix in kernel

Hi Lukasz,

On Wed, Feb 11, 2015, Lukasz Rymanowski wrote:
> Following patches should get in if kernel fix for HCI_LE_ENABLE
> gets upstream
> [PATCH v2 1/3] Bluetooth: Do not allow LE connection if LE is not
> enabled
>
> Here we have 2 test cases on mgmt and l2cap level verifying that
> LE connection will be rejected if LE host support is not enabled.
>
> Also small update to error codes in mgmt-api has been added as now
> Pair Device might return MGMT_RESULT_REJECT if user tries to make
> connection on transport which is not enabled
>
> v2:
> * added new test cases for v2 of kernel patch.
> * Added "Not Supported" error code to mgmt-api.txt
> * Update test-coverage.txt
>
> Lukasz Rymanowski (4):
> tools/mgmt-tester: Add test for pair on not enabled transport
> tools/mgmt-tester: Add test for pair on not supported transport
> tools/l2cap-tester: Add L2CAP LE Connection Reject test
> doc/mgmt-api: Update error codes for Pair Device Command
>
> doc/mgmt-api.txt | 9 ++++++-
> tools/l2cap-tester.c | 45 +++++++++++++++++++++++++++++++--
> tools/mgmt-tester.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++--
> 3 files changed, 120 insertions(+), 5 deletions(-)

Applied. Thanks.

Johan

2015-02-11 11:32:12

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH v2 4/4] doc/mgmt-api: Update error codes for Pair Device Command

This patch adds two error codes for Pair device command.

Reject error code which is used when requested transport is not enabled.
E.g. User wants to do LE pair but LE support is not enabled. Similar
with BREDR

Not Supported error code which is used if controller is not capable with
requested transport
---
doc/mgmt-api.txt | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/doc/mgmt-api.txt b/doc/mgmt-api.txt
index a51e913..bef9990 100644
--- a/doc/mgmt-api.txt
+++ b/doc/mgmt-api.txt
@@ -1023,7 +1023,14 @@ Pair Device Command
This command generates a Command Complete event on success
or failure.

- Possible errors: Connect Failed
+ Reject status is used when requested transport is not enabled.
+
+ Not Supported status is used if controller is not capable with
+ requested transport.
+
+ Possible errors: Rejected
+ Not Supported
+ Connect Failed
Busy
Invalid Parameters
Not Powered
--
1.8.4


2015-02-11 11:32:10

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH v2 2/4] tools/mgmt-tester: Add test for pair on not supported transport

If controller is not capable for giver transport, kernel will reply on
pair request with MGMT_STATUS_NOT_SUPPORTED
---
tools/mgmt-tester.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 3dff98f..18a5335 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -2511,6 +2511,26 @@ static const void *client_bdaddr_param_func(uint8_t *len)
return bdaddr;
}

+static const struct generic_data pair_device_not_supported_test_1 = {
+ .setup_settings = settings_powered_bondable,
+ .send_opcode = MGMT_OP_PAIR_DEVICE,
+ .send_func = pair_device_send_param_func,
+ .expect_status = MGMT_STATUS_NOT_SUPPORTED,
+ .expect_func = pair_device_expect_param_func,
+ .addr_type_avail = true,
+ .addr_type = BDADDR_BREDR,
+};
+
+static const struct generic_data pair_device_not_supported_test_2 = {
+ .setup_settings = settings_powered_bondable,
+ .send_opcode = MGMT_OP_PAIR_DEVICE,
+ .send_func = pair_device_send_param_func,
+ .expect_status = MGMT_STATUS_NOT_SUPPORTED,
+ .expect_func = pair_device_expect_param_func,
+ .addr_type_avail = true,
+ .addr_type = BDADDR_LE_PUBLIC,
+};
+
static uint16_t settings_powered_bondable_le[] = { MGMT_OP_SET_LE,
MGMT_OP_SET_BONDABLE,
MGMT_OP_SET_POWERED,
@@ -5099,6 +5119,12 @@ int main(int argc, char *argv[])
test_bredrle("Pair Device - Power off 1",
&pair_device_power_off_test_1,
NULL, test_command_generic);
+ test_le("Pair Device - Incorrect transport reject 1",
+ &pair_device_not_supported_test_1,
+ NULL, test_command_generic);
+ test_bredr("Pair Device - Incorrect transport reject 2",
+ &pair_device_not_supported_test_2,
+ NULL, test_command_generic);
test_bredrle("Pair Device - Reject on not enabled transport 1",
&pair_device_reject_transport_not_enabled_1,
NULL, test_command_generic);
--
1.8.4


2015-02-11 11:32:11

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH v2 3/4] tools/l2cap-tester: Add L2CAP LE Connection Reject test

This test checks if kernel correctly rejects LE connection when host is
not configured to support LE.
---
tools/l2cap-tester.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 43 insertions(+), 2 deletions(-)

diff --git a/tools/l2cap-tester.c b/tools/l2cap-tester.c
index cf0fa38..7f03591 100644
--- a/tools/l2cap-tester.c
+++ b/tools/l2cap-tester.c
@@ -82,6 +82,9 @@ struct l2cap_data {
const void *pin;
uint8_t client_pin_len;
const void *client_pin;
+
+ bool addr_type_avail;
+ uint8_t addr_type;
};

static void mgmt_debug(const char *str, void *user_data)
@@ -441,6 +444,12 @@ static const struct l2cap_data le_client_connect_reject_test_1 = {
.expect_err = ECONNREFUSED,
};

+static const struct l2cap_data le_client_connect_reject_test_2 = {
+ .client_psm = 0x0080,
+ .addr_type_avail = true,
+ .addr_type = BDADDR_LE_PUBLIC,
+};
+
static const struct l2cap_data le_client_connect_nval_psm_test = {
.client_psm = 0x0080,
.expect_err = ECONNREFUSED,
@@ -943,6 +952,7 @@ failed:
static int create_l2cap_sock(struct test_data *data, uint16_t psm,
uint16_t cid, int sec_level)
{
+ const struct l2cap_data *l2data = data->test_data;
const uint8_t *master_bdaddr;
struct sockaddr_l2 addr;
int sk, err;
@@ -968,7 +978,10 @@ static int create_l2cap_sock(struct test_data *data, uint16_t psm,
addr.l2_psm = htobs(psm);
addr.l2_cid = htobs(cid);
bacpy(&addr.l2_bdaddr, (void *) master_bdaddr);
- if (data->hciemu_type == HCIEMU_TYPE_LE)
+
+ if (l2data && l2data->addr_type_avail)
+ addr.l2_bdaddr_type = l2data->addr_type;
+ else if (data->hciemu_type == HCIEMU_TYPE_LE)
addr.l2_bdaddr_type = BDADDR_LE_PUBLIC;
else
addr.l2_bdaddr_type = BDADDR_BREDR;
@@ -1003,6 +1016,7 @@ static int create_l2cap_sock(struct test_data *data, uint16_t psm,
static int connect_l2cap_sock(struct test_data *data, int sk, uint16_t psm,
uint16_t cid)
{
+ const struct l2cap_data *l2data = data->test_data;
const uint8_t *client_bdaddr;
struct sockaddr_l2 addr;
int err;
@@ -1018,7 +1032,10 @@ static int connect_l2cap_sock(struct test_data *data, int sk, uint16_t psm,
bacpy(&addr.l2_bdaddr, (void *) client_bdaddr);
addr.l2_psm = htobs(psm);
addr.l2_cid = htobs(cid);
- if (data->hciemu_type == HCIEMU_TYPE_LE)
+
+ if (l2data && l2data->addr_type_avail)
+ addr.l2_bdaddr_type = l2data->addr_type;
+ else if (data->hciemu_type == HCIEMU_TYPE_LE)
addr.l2_bdaddr_type = BDADDR_LE_PUBLIC;
else
addr.l2_bdaddr_type = BDADDR_BREDR;
@@ -1084,6 +1101,27 @@ static void test_connect(const void *test_data)
tester_print("Connect in progress");
}

+static void test_connect_reject(const void *test_data)
+{
+ struct test_data *data = tester_get_data();
+ const struct l2cap_data *l2data = data->test_data;
+ int sk;
+
+ sk = create_l2cap_sock(data, 0, l2data->cid, l2data->sec_level);
+ if (sk < 0) {
+ tester_test_failed();
+ return;
+ }
+
+ if (connect_l2cap_sock(data, sk, l2data->client_psm,
+ l2data->cid) < 0)
+ tester_test_passed();
+ else
+ tester_test_failed();
+
+ close(sk);
+}
+
static gboolean l2cap_listen_cb(GIOChannel *io, GIOCondition cond,
gpointer user_data)
{
@@ -1396,6 +1434,9 @@ int main(int argc, char *argv[])
test_l2cap_le("L2CAP LE Client - Command Reject",
&le_client_connect_reject_test_1,
setup_powered_client, test_connect);
+ test_l2cap_bredr("L2CAP LE Client - Connection Reject",
+ &le_client_connect_reject_test_2,
+ setup_powered_client, test_connect_reject);
test_l2cap_le("L2CAP LE Client - Invalid PSM",
&le_client_connect_nval_psm_test,
setup_powered_client, test_connect);
--
1.8.4


2015-02-11 11:32:09

by Lukasz Rymanowski

[permalink] [raw]
Subject: [PATCH v2 1/4] tools/mgmt-tester: Add test for pair on not enabled transport

If transport is not enabled but controller is capable, kernel replies
with MGMT_STATUS_REJECTED
---
tools/mgmt-tester.c | 45 +++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 43 insertions(+), 2 deletions(-)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 3eb058a..3dff98f 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -407,6 +407,8 @@ struct generic_data {
bool client_enable_sc;
bool expect_sc_key;
bool force_power_off;
+ bool addr_type_avail;
+ uint8_t addr_type;
};

static const char dummy_data[] = { 0x00 };
@@ -2396,7 +2398,10 @@ static const void *pair_device_send_param_func(uint16_t *len)
static uint8_t param[8];

memcpy(param, hciemu_get_client_bdaddr(data->hciemu), 6);
- if (data->hciemu_type == HCIEMU_TYPE_LE)
+
+ if (test->addr_type_avail)
+ param[6] = test->addr_type;
+ else if (data->hciemu_type == HCIEMU_TYPE_LE)
param[6] = 0x01; /* Address type */
else
param[6] = 0x00; /* Address type */
@@ -2410,10 +2415,14 @@ static const void *pair_device_send_param_func(uint16_t *len)
static const void *pair_device_expect_param_func(uint16_t *len)
{
struct test_data *data = tester_get_data();
+ const struct generic_data *test = data->test_data;
static uint8_t param[7];

memcpy(param, hciemu_get_client_bdaddr(data->hciemu), 6);
- if (data->hciemu_type == HCIEMU_TYPE_LE)
+
+ if (test->addr_type_avail)
+ param[6] = test->addr_type;
+ else if (data->hciemu_type == HCIEMU_TYPE_LE)
param[6] = 0x01; /* Address type */
else
param[6] = 0x00; /* Address type */
@@ -2502,6 +2511,32 @@ static const void *client_bdaddr_param_func(uint8_t *len)
return bdaddr;
}

+static uint16_t settings_powered_bondable_le[] = { MGMT_OP_SET_LE,
+ MGMT_OP_SET_BONDABLE,
+ MGMT_OP_SET_POWERED,
+ 0 };
+
+static const struct generic_data pair_device_reject_transport_not_enabled_1 = {
+ .setup_settings = settings_powered_bondable_le,
+ .setup_nobredr = true,
+ .send_opcode = MGMT_OP_PAIR_DEVICE,
+ .send_func = pair_device_send_param_func,
+ .expect_status = MGMT_STATUS_REJECTED,
+ .expect_func = pair_device_expect_param_func,
+ .addr_type_avail = true,
+ .addr_type = BDADDR_BREDR,
+};
+
+static const struct generic_data pair_device_reject_transport_not_enabled_2 = {
+ .setup_settings = settings_powered_bondable,
+ .send_opcode = MGMT_OP_PAIR_DEVICE,
+ .send_func = pair_device_send_param_func,
+ .expect_status = MGMT_STATUS_REJECTED,
+ .expect_func = pair_device_expect_param_func,
+ .addr_type_avail = true,
+ .addr_type = BDADDR_LE_PUBLIC,
+};
+
static const struct generic_data pair_device_reject_test_1 = {
.setup_settings = settings_powered_bondable,
.send_opcode = MGMT_OP_PAIR_DEVICE,
@@ -5064,6 +5099,12 @@ int main(int argc, char *argv[])
test_bredrle("Pair Device - Power off 1",
&pair_device_power_off_test_1,
NULL, test_command_generic);
+ test_bredrle("Pair Device - Reject on not enabled transport 1",
+ &pair_device_reject_transport_not_enabled_1,
+ NULL, test_command_generic);
+ test_bredrle("Pair Device - Reject on not enabled transport 2",
+ &pair_device_reject_transport_not_enabled_2,
+ NULL, test_command_generic);
test_bredrle("Pair Device - Invalid Parameters 1",
&pair_device_invalid_param_test_1,
NULL, test_command_generic);
--
1.8.4