From d883fcae96862c652a9de2fe869090e907bc0f4a Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Wed, 16 Jan 2013 15:39:13 +0200 Subject: [PATCH] tools: Add class of device change monitoring support to mgmt-tester --- tools/mgmt-tester.c | 61 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c index 0aef9441e..7db0d4133 100644 --- a/tools/mgmt-tester.c +++ b/tools/mgmt-tester.c @@ -44,6 +44,9 @@ struct test_data { uint32_t initial_settings; struct mgmt *mgmt; struct mgmt *mgmt_alt; + unsigned int mgmt_settings_id; + unsigned int mgmt_alt_settings_id; + unsigned int mgmt_alt_class_id; uint8_t mgmt_version; uint16_t mgmt_revision; uint16_t mgmt_index; @@ -292,6 +295,7 @@ struct generic_data { uint16_t expect_len; uint32_t expect_settings_set; uint32_t expect_settings_unset; + const void *expect_class_of_dev; uint16_t expect_hci_command; const void *expect_hci_param; uint8_t expect_hci_len; @@ -725,6 +729,7 @@ static const struct generic_data set_dev_class_valid_param_test_2 = { .expect_status = MGMT_STATUS_SUCCESS, .expect_param = set_dev_class_valid_rsp, .expect_len = sizeof(set_dev_class_valid_rsp), + .expect_class_of_dev = set_dev_class_valid_rsp, .expect_hci_command = BT_HCI_CMD_WRITE_CLASS_OF_DEV, .expect_hci_param = set_dev_class_valid_hci, .expect_hci_len = sizeof(set_dev_class_valid_hci), @@ -831,7 +836,7 @@ static void command_generic_new_settings(uint16_t index, uint16_t length, tester_print("New settings event received"); - mgmt_unregister_index(data->mgmt, index); + mgmt_unregister(data->mgmt, data->mgmt_settings_id); tester_test_failed(); } @@ -868,7 +873,7 @@ static void command_generic_new_settings_alt(uint16_t index, uint16_t length, done: tester_print("Unregistering new settings notification"); - mgmt_unregister_index(data->mgmt_alt, index); + mgmt_unregister(data->mgmt_alt, data->mgmt_alt_settings_id); if (test->expect_hci_command && !data->hci_commands_complete) { tester_warn("Settings received without expected HCI command"); @@ -879,6 +884,42 @@ done: tester_test_passed(); } +static void command_generic_class_changed_alt(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 struct mgmt_ev_class_of_dev_changed *ev = param; + + if (length != sizeof(*ev)) { + tester_warn("Invalid length Class of Device changed event"); + tester_test_failed(); + return; + } + + tester_print("New Class of Device 0x%02x%02x%02x received", + ev->class_of_dev[2], ev->class_of_dev[1], + ev->class_of_dev[0]); + + if (!test->expect_class_of_dev) + return; + + if (memcmp(ev->class_of_dev, test->expect_class_of_dev, 3) != 0) + return; + + tester_print("Unregistering Class of Device notification"); + + mgmt_unregister(data->mgmt_alt, data->mgmt_alt_class_id); + + if (test->expect_hci_command && !data->hci_commands_complete) { + tester_warn("CoD changed without expected HCI command"); + tester_test_failed(); + return; + } + + tester_test_passed(); +} + static void command_generic_callback(uint8_t status, uint16_t length, const void *param, void *user_data) { @@ -946,6 +987,7 @@ static void test_command_generic(const void *test_data) { struct test_data *data = tester_get_data(); const struct generic_data *test = data->test_data; + unsigned int id; uint16_t index; index = test->send_index_none ? MGMT_INDEX_NONE : data->mgmt_index; @@ -953,11 +995,22 @@ static void test_command_generic(const void *test_data) if (test->expect_settings_set) { tester_print("Registering new settings notification"); - mgmt_register(data->mgmt, MGMT_EV_NEW_SETTINGS, index, + id = mgmt_register(data->mgmt, MGMT_EV_NEW_SETTINGS, index, command_generic_new_settings, NULL, NULL); + data->mgmt_settings_id = id; - mgmt_register(data->mgmt_alt, MGMT_EV_NEW_SETTINGS, index, + id = mgmt_register(data->mgmt_alt, MGMT_EV_NEW_SETTINGS, index, command_generic_new_settings_alt, NULL, NULL); + data->mgmt_alt_settings_id = id; + } + + if (test->expect_class_of_dev) { + tester_print("Registering Class of Device notification"); + id = mgmt_register(data->mgmt_alt, + MGMT_EV_CLASS_OF_DEV_CHANGED, index, + command_generic_class_changed_alt, + NULL, NULL); + data->mgmt_alt_class_id = id; } if (test->expect_hci_command) { -- 2.47.3