2014-05-19 21:14:02

by Andrzej Kaczmarek

[permalink] [raw]
Subject: [PATCH 1/4] emulator/btdev: Add support for Read RSSI command

---
emulator/btdev.c | 11 +++++++++++
1 file changed, 11 insertions(+)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index e590efa..d97476b 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -1763,6 +1763,7 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
const struct bt_hci_cmd_le_start_encrypt *lse;
const struct bt_hci_cmd_le_ltk_req_reply *llrr;
const struct bt_hci_cmd_read_local_amp_assoc *rlaa_cmd;
+ const struct bt_hci_cmd_read_rssi *rrssi;
struct bt_hci_rsp_read_default_link_policy rdlp;
struct bt_hci_rsp_read_stored_link_key rslk;
struct bt_hci_rsp_write_stored_link_key wslk;
@@ -1813,6 +1814,7 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
struct bt_hci_rsp_pin_code_request_neg_reply pcrnr_rsp;
struct bt_hci_rsp_user_confirm_request_reply ucrr_rsp;
struct bt_hci_rsp_user_confirm_request_neg_reply ucrnr_rsp;
+ struct bt_hci_rsp_read_rssi rrssi_rsp;
uint8_t status, page;

switch (opcode) {
@@ -2465,6 +2467,15 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
cmd_complete(btdev, opcode, &rdbs, sizeof(rdbs));
break;

+ case BT_HCI_CMD_READ_RSSI:
+ rrssi = data;
+
+ rrssi_rsp.status = BT_HCI_ERR_SUCCESS;
+ rrssi_rsp.handle = rrssi->handle;
+ rrssi_rsp.rssi = -1; /* non-zero so we can see it in tester */
+ cmd_complete(btdev, opcode, &rrssi_rsp, sizeof(rrssi_rsp));
+ break;
+
case BT_HCI_CMD_READ_LOCAL_AMP_INFO:
if (btdev->type != BTDEV_TYPE_AMP)
goto unsupported;
--
1.9.3



2014-05-20 18:56:03

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH 1/4] emulator/btdev: Add support for Read RSSI command

Hi Andrzej,

On Mon, May 19, 2014, Andrzej Kaczmarek wrote:
> ---
> emulator/btdev.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)

All patches in this set have been applied. Thanks.

Johan

2014-05-19 21:14:04

by Andrzej Kaczmarek

[permalink] [raw]
Subject: [PATCH 3/4] tools/mgmt-tester: Add "Get Conn Info - Success"

---
tools/mgmt-tester.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 91 insertions(+)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 4cc7ba4..14b1d3d 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -2737,6 +2737,43 @@ static const struct generic_data set_privacy_nval_param_test = {
.expect_status = MGMT_STATUS_INVALID_PARAMS,
};

+static const void *get_conn_info_send_param_func(uint16_t *len)
+{
+ struct test_data *data = tester_get_data();
+ static uint8_t param[7];
+
+ memcpy(param, hciemu_get_client_bdaddr(data->hciemu), 6);
+ param[6] = 0x00; /* Address type */
+
+ *len = sizeof(param);
+
+ return param;
+}
+
+static const void *get_conn_info_expect_param_func(uint16_t *len)
+{
+ struct test_data *data = tester_get_data();
+ static uint8_t param[10];
+
+ memcpy(param, hciemu_get_client_bdaddr(data->hciemu), 6);
+ param[6] = 0x00; /* Address type */
+ param[7] = 0xff; /* RSSI (= -1) */
+ param[8] = 0xff; /* TX power (= -1) */
+ param[9] = 0x04; /* max TX power */
+
+ *len = sizeof(param);
+
+ return param;
+}
+
+static const struct generic_data get_conn_info_succes1_test = {
+ .setup_settings = settings_powered_connectable_pairable_ssp,
+ .send_opcode = MGMT_OP_GET_CONN_INFO,
+ .send_func = get_conn_info_send_param_func,
+ .expect_status = MGMT_STATUS_SUCCESS,
+ .expect_func = get_conn_info_expect_param_func,
+};
+
static void client_cmd_complete(uint16_t opcode, uint8_t status,
const void *param, uint8_t len,
void *user_data)
@@ -3422,6 +3459,57 @@ static void test_pairing_acceptor(const void *test_data)
bthost_hci_connect(bthost, master_bdaddr, addr_type);
}

+static void connected_event(uint16_t index, uint16_t length, const void *param,
+ void *user_data)
+{
+ struct test_data *data = tester_get_data();
+ const struct generic_data *test = data->test_data;
+ const void *send_param = test->send_param;
+ uint16_t send_len = test->send_len;
+
+ tester_print("Sending command 0x%04x", test->send_opcode);
+
+ if (test->send_func)
+ send_param = test->send_func(&send_len);
+
+ mgmt_send(data->mgmt, test->send_opcode, data->mgmt_index, send_len,
+ send_param, command_generic_callback, NULL, NULL);
+ test_add_condition(data);
+
+ /* Complete MGMT_EV_DEVICE_CONNECTED *after* adding new one */
+ test_condition_complete(data);
+}
+
+static void test_command_generic_connect(const void *test_data)
+{
+ struct test_data *data = tester_get_data();
+ unsigned int id;
+ const uint8_t *master_bdaddr;
+ uint8_t addr_type;
+ struct bthost *bthost;
+
+ tester_print("Registering %s notification",
+ mgmt_evstr(MGMT_EV_DEVICE_CONNECTED));
+ id = mgmt_register(data->mgmt_alt, MGMT_EV_DEVICE_CONNECTED,
+ data->mgmt_index, connected_event,
+ NULL, NULL);
+ data->mgmt_alt_ev_id = id;
+ test_add_condition(data);
+
+ master_bdaddr = hciemu_get_master_bdaddr(data->hciemu);
+ if (!master_bdaddr) {
+ tester_warn("No master bdaddr");
+ tester_test_failed();
+ return;
+ }
+
+ addr_type = data->hciemu_type == HCIEMU_TYPE_BREDRLE ? BDADDR_BREDR :
+ BDADDR_LE_PUBLIC;
+
+ bthost = hciemu_client_get_host(data->hciemu);
+ bthost_hci_connect(bthost, master_bdaddr, addr_type);
+}
+
int main(int argc, char *argv[])
{
tester_init(&argc, &argv);
@@ -4013,5 +4101,8 @@ int main(int argc, char *argv[])
&set_privacy_nval_param_test,
NULL, test_command_generic);

+ test_bredrle("Get Conn Info - Success",
+ &get_conn_info_succes1_test, NULL,
+ test_command_generic_connect);
return tester_run();
}
--
1.9.3


2014-05-19 21:14:03

by Andrzej Kaczmarek

[permalink] [raw]
Subject: [PATCH 2/4] emulator/btdev: Add support for Read TX Power command

---
emulator/btdev.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index d97476b..28709ca 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -1764,6 +1764,7 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
const struct bt_hci_cmd_le_ltk_req_reply *llrr;
const struct bt_hci_cmd_read_local_amp_assoc *rlaa_cmd;
const struct bt_hci_cmd_read_rssi *rrssi;
+ const struct bt_hci_cmd_read_tx_power *rtxp;
struct bt_hci_rsp_read_default_link_policy rdlp;
struct bt_hci_rsp_read_stored_link_key rslk;
struct bt_hci_rsp_write_stored_link_key wslk;
@@ -1815,6 +1816,7 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
struct bt_hci_rsp_user_confirm_request_reply ucrr_rsp;
struct bt_hci_rsp_user_confirm_request_neg_reply ucrnr_rsp;
struct bt_hci_rsp_read_rssi rrssi_rsp;
+ struct bt_hci_rsp_read_tx_power rtxp_rsp;
uint8_t status, page;

switch (opcode) {
@@ -2476,6 +2478,30 @@ static void default_cmd(struct btdev *btdev, uint16_t opcode,
cmd_complete(btdev, opcode, &rrssi_rsp, sizeof(rrssi_rsp));
break;

+ case BT_HCI_CMD_READ_TX_POWER:
+ rtxp = data;
+
+ switch (rtxp->type) {
+ case 0x00:
+ rtxp_rsp.status = BT_HCI_ERR_SUCCESS;
+ rtxp_rsp.level = -1; /* non-zero */
+ break;
+
+ case 0x01:
+ rtxp_rsp.status = BT_HCI_ERR_SUCCESS;
+ rtxp_rsp.level = 4; /* max for class 2 radio */
+ break;
+
+ default:
+ rtxp_rsp.level = 0;
+ rtxp_rsp.status = BT_HCI_ERR_INVALID_PARAMETERS;
+ break;
+ }
+
+ rtxp_rsp.handle = rtxp->handle;
+ cmd_complete(btdev, opcode, &rtxp_rsp, sizeof(rtxp_rsp));
+ break;
+
case BT_HCI_CMD_READ_LOCAL_AMP_INFO:
if (btdev->type != BTDEV_TYPE_AMP)
goto unsupported;
--
1.9.3


2014-05-19 21:14:05

by Andrzej Kaczmarek

[permalink] [raw]
Subject: [PATCH 4/4] tools/mgmt-tester: Add "Get Conn Info - Not Connected"

---
tools/mgmt-tester.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 14b1d3d..4290c21 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -2766,6 +2766,22 @@ static const void *get_conn_info_expect_param_func(uint16_t *len)
return param;
}

+static const void *get_conn_info_error_expect_param_func(uint16_t *len)
+{
+ struct test_data *data = tester_get_data();
+ static uint8_t param[10];
+
+ /* All unset parameters shall be 0 in case of error */
+ memset(param, 0, sizeof(param));
+
+ memcpy(param, hciemu_get_client_bdaddr(data->hciemu), 6);
+ param[6] = 0x00; /* Address type */
+
+ *len = sizeof(param);
+
+ return param;
+}
+
static const struct generic_data get_conn_info_succes1_test = {
.setup_settings = settings_powered_connectable_pairable_ssp,
.send_opcode = MGMT_OP_GET_CONN_INFO,
@@ -2774,6 +2790,14 @@ static const struct generic_data get_conn_info_succes1_test = {
.expect_func = get_conn_info_expect_param_func,
};

+static const struct generic_data get_conn_info_ncon_test = {
+ .setup_settings = settings_powered_connectable_pairable_ssp,
+ .send_opcode = MGMT_OP_GET_CONN_INFO,
+ .send_func = get_conn_info_send_param_func,
+ .expect_status = MGMT_STATUS_NOT_CONNECTED,
+ .expect_func = get_conn_info_error_expect_param_func,
+};
+
static void client_cmd_complete(uint16_t opcode, uint8_t status,
const void *param, uint8_t len,
void *user_data)
@@ -4104,5 +4128,9 @@ int main(int argc, char *argv[])
test_bredrle("Get Conn Info - Success",
&get_conn_info_succes1_test, NULL,
test_command_generic_connect);
+ test_bredrle("Get Conn Info - Not Connected",
+ &get_conn_info_ncon_test, NULL,
+ test_command_generic);
+
return tester_run();
}
--
1.9.3