summaryrefslogtreecommitdiff
path: root/tools/smp-tester.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2014-08-18 13:49:08 +0300
committerJohan Hedberg <johan.hedberg@intel.com>2014-08-18 20:35:22 +0300
commit5fd1e9e5d4fe21205771eae43b6f449b6e32536f (patch)
tree0dca50c6562a2e392713a9a3822d84f1b431d53c /tools/smp-tester.c
parent49f19d04180596967409c060e1f1b1191601980f (diff)
downloadbluez-5fd1e9e5d4fe21205771eae43b6f449b6e32536f.tar.gz
smp-tester: Add support for expecting specific HCI commands
Diffstat (limited to 'tools/smp-tester.c')
-rw-r--r--tools/smp-tester.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/smp-tester.c b/tools/smp-tester.c
index a8f6a189e..83d5ee0ac 100644
--- a/tools/smp-tester.c
+++ b/tools/smp-tester.c
@@ -83,6 +83,10 @@ struct smp_data {
const struct smp_req_rsp *req;
size_t req_count;
bool mitm;
+ uint16_t expect_hci_command;
+ const void *expect_hci_param;
+ uint8_t expect_hci_len;
+ const void * (*expect_hci_func)(uint8_t *len);
};
static void mgmt_debug(const char *str, void *user_data)
@@ -611,6 +615,37 @@ failed:
tester_test_failed();
}
+static void command_hci_callback(uint16_t opcode, const void *param,
+ uint8_t length, void *user_data)
+{
+ struct test_data *data = user_data;
+ const struct smp_data *smp = data->test_data;
+ const void *expect_hci_param = smp->expect_hci_param;
+ uint8_t expect_hci_len = smp->expect_hci_len;
+
+ tester_print("HCI Command 0x%04x length %u", opcode, length);
+
+ if (opcode != smp->expect_hci_command)
+ return;
+
+ if (smp->expect_hci_func)
+ expect_hci_param = smp->expect_hci_func(&expect_hci_len);
+
+ if (length != expect_hci_len) {
+ tester_warn("Invalid parameter size for HCI command");
+ tester_test_failed();
+ return;
+ }
+
+ if (memcmp(param, expect_hci_param, length) != 0) {
+ tester_warn("Unexpected HCI command parameter value");
+ tester_test_failed();
+ return;
+ }
+
+ test_condition_complete(data);
+}
+
static void smp_new_conn(uint16_t handle, void *user_data)
{
struct test_data *data = user_data;
@@ -685,6 +720,13 @@ static void test_client(const void *test_data)
bthost_set_connect_cb(bthost, smp_new_conn, data);
test_add_condition(data);
+ if (smp->expect_hci_command) {
+ tester_print("Registering HCI command callback");
+ hciemu_add_master_post_command_hook(data->hciemu,
+ command_hci_callback, data);
+ test_add_condition(data);
+ }
+
memcpy(&cp.addr.bdaddr, data->ra, sizeof(data->ra));
cp.addr.type = BDADDR_LE_PUBLIC;
if (smp->mitm)
@@ -738,6 +780,7 @@ static void setup_powered_server(const void *test_data)
static void test_server(const void *test_data)
{
struct test_data *data = tester_get_data();
+ const struct smp_data *smp = data->test_data;
struct bthost *bthost;
data->out = true;
@@ -749,6 +792,13 @@ static void test_server(const void *test_data)
test_add_condition(data);
bthost_hci_connect(bthost, data->ra, BDADDR_LE_PUBLIC);
+
+ if (smp->expect_hci_command) {
+ tester_print("Registering HCI command callback");
+ hciemu_add_master_post_command_hook(data->hciemu,
+ command_hci_callback, data);
+ test_add_condition(data);
+ }
}
int main(int argc, char *argv[])