This patch sets adds unit tests for the new Add/Remove Advertising mgmt
commands and related events.
Arman Uguray (6):
lib: Provide data structures for Add/Remove Advertising
tools/mgmt-tester: Add Advertising test cases
tools/mgmt-tester: Remove Advertising test cases
tools/mgmt-tester: Add Advertising scan response test cases
tools/mgmt-tester: Add Advertising timeout test cases
doc/test-coverage.txt: Update mgmt-tester test count
doc/test-coverage.txt | 2 +-
lib/mgmt.h | 33 +++
tools/mgmt-tester.c | 618 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 652 insertions(+), 1 deletion(-)
--
2.2.0.rc0.207.ga3a616c
Hi Arman,
> This patch sets adds unit tests for the new Add/Remove Advertising mgmt
> commands and related events.
>
> Arman Uguray (6):
> lib: Provide data structures for Add/Remove Advertising
> tools/mgmt-tester: Add Advertising test cases
> tools/mgmt-tester: Remove Advertising test cases
> tools/mgmt-tester: Add Advertising scan response test cases
> tools/mgmt-tester: Add Advertising timeout test cases
> doc/test-coverage.txt: Update mgmt-tester test count
>
> doc/test-coverage.txt | 2 +-
> lib/mgmt.h | 33 +++
> tools/mgmt-tester.c | 618 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 652 insertions(+), 1 deletion(-)
all 6 patches have been applied.
Regards
Marcel
---
doc/test-coverage.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/doc/test-coverage.txt b/doc/test-coverage.txt
index 1f179c8..3ef7a30 100644
--- a/doc/test-coverage.txt
+++ b/doc/test-coverage.txt
@@ -40,7 +40,7 @@ Automated end-to-end testing
Application Count Description
-------------------------------------------
-mgmt-tester 246 Kernel management interface testing
+mgmt-tester 269 Kernel management interface testing
l2cap-tester 27 Kernel L2CAP implementation testing
rfcomm-tester 9 Kernel RFCOMM implementation testing
smp-tester 5 Kernel SMP implementation testing
--
2.2.0.rc0.207.ga3a616c
This patch adds test cases for the Add Advertising command when a
timeout parameter has been given.
---
tools/mgmt-tester.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 73 insertions(+)
diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index aebcd90..5de9967 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -3794,6 +3794,12 @@ static const uint8_t add_advertising_param_2[] = {
0x05, 0x03, 0x0d, 0x18, 0x0f, 0x18,
};
+static const uint8_t add_advertising_param_3[] = {
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x09, 0x00,
+ 0x03, 0x02, 0x0d, 0x18,
+ 0x04, 0xff, 0x01, 0x02, 0x03,
+};
+
static const uint8_t advertising_instance_param[] = {
0x01,
};
@@ -3989,6 +3995,14 @@ static const struct generic_data add_advertising_fail_11 = {
.expect_status = MGMT_STATUS_INVALID_PARAMS,
};
+static const struct generic_data add_advertising_fail_12 = {
+ .setup_settings = settings_le,
+ .send_opcode = MGMT_OP_ADD_ADVERTISING,
+ .send_param = add_advertising_param_3,
+ .send_len = sizeof(add_advertising_param_3),
+ .expect_status = MGMT_STATUS_REJECTED,
+};
+
static const struct generic_data add_advertising_success_1 = {
.setup_settings = settings_powered_le,
.send_opcode = MGMT_OP_ADD_ADVERTISING,
@@ -4091,6 +4105,22 @@ static const struct generic_data add_advertising_success_7 = {
.expect_hci_len = sizeof(set_scan_rsp_1),
};
+static const char set_powered_off_le_settings_param[] = {
+ 0x80, 0x02, 0x00, 0x00
+};
+
+static const struct generic_data add_advertising_timeout_power_off = {
+ .send_opcode = MGMT_OP_SET_POWERED,
+ .send_param = set_powered_off_param,
+ .send_len = sizeof(set_powered_off_param),
+ .expect_status = MGMT_STATUS_SUCCESS,
+ .expect_param = set_powered_off_le_settings_param,
+ .expect_len = sizeof(set_powered_off_le_settings_param),
+ .expect_alt_ev = MGMT_EV_ADVERTISING_REMOVED,
+ .expect_alt_ev_param = advertising_instance_param,
+ .expect_alt_ev_len = sizeof(advertising_instance_param),
+};
+
static const uint8_t remove_advertising_param_1[] = {
0x01,
};
@@ -4565,6 +4595,42 @@ static void setup_add_advertising(const void *test_data)
NULL, NULL);
}
+static void setup_add_advertising_timeout(const void *test_data)
+{
+ struct test_data *data = tester_get_data();
+ struct mgmt_cp_add_advertising *cp;
+ unsigned char adv_param[sizeof(*cp) + 6];
+ unsigned char param[] = { 0x01 };
+
+ tester_print("Adding advertising instance while unpowered");
+
+ cp = (struct mgmt_cp_add_advertising *) adv_param;
+ memset(cp, 0, sizeof(*cp));
+
+ cp->instance = 1;
+ cp->timeout = 5;
+ cp->adv_data_len = 6;
+ cp->data[0] = 0x05;
+ cp->data[1] = 0x08;
+ cp->data[2] = 't';
+ cp->data[3] = 'e';
+ cp->data[4] = 's';
+ cp->data[5] = 't';
+
+ mgmt_send(data->mgmt, MGMT_OP_SET_LE, data->mgmt_index,
+ sizeof(param), ¶m,
+ NULL, NULL, NULL);
+
+ mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index,
+ sizeof(param), ¶m,
+ NULL, NULL, NULL);
+
+ mgmt_send(data->mgmt, MGMT_OP_ADD_ADVERTISING, data->mgmt_index,
+ sizeof(adv_param), adv_param,
+ setup_add_advertising_callback,
+ NULL, NULL);
+}
+
static void setup_set_and_add_advertising(const void *test_data)
{
struct test_data *data = tester_get_data();
@@ -5959,6 +6025,13 @@ int main(int argc, char *argv[])
test_le("Add Advertising - Invalid Params 10 (ScRsp too long)",
&add_advertising_fail_11,
NULL, test_command_generic);
+ test_bredrle("Add Advertising - Timeout Not Powered",
+ &add_advertising_fail_12,
+ NULL, test_command_generic);
+ test_bredrle("Add Advertising - Timeout Power off",
+ &add_advertising_timeout_power_off,
+ setup_add_advertising_timeout,
+ test_command_generic);
test_bredrle("Add Advertising - Success 1",
&add_advertising_success_1,
NULL, test_command_generic);
--
2.2.0.rc0.207.ga3a616c
This patch adds Scan Response Data related test cases for the Add
Advertising command.
---
tools/mgmt-tester.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 144 insertions(+), 2 deletions(-)
diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 1648dc8..aebcd90 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -3782,8 +3782,16 @@ static const struct generic_data remove_device_success_5 = {
static const uint8_t add_advertising_param_1[] = {
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
- 0x03, 0x03, 0x0d, 0x18,
+ 0x03, 0x02, 0x0d, 0x18,
+ 0x04, 0xff, 0x01, 0x02, 0x03,
+};
+
+static const uint8_t add_advertising_param_2[] = {
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x0a,
+ 0x03, 0x02, 0x0d, 0x18,
0x04, 0xff, 0x01, 0x02, 0x03,
+ 0x03, 0x19, 0x40, 0x03,
+ 0x05, 0x03, 0x0d, 0x18, 0x0f, 0x18,
};
static const uint8_t advertising_instance_param[] = {
@@ -3791,7 +3799,7 @@ static const uint8_t advertising_instance_param[] = {
};
static const uint8_t set_adv_data_1[] = {
- 0x09, 0x03, 0x03, 0x0d, 0x18, 0x04, 0xff, 0x01, 0x02, 0x03,
+ 0x09, 0x03, 0x02, 0x0d, 0x18, 0x04, 0xff, 0x01, 0x02, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00,
@@ -3818,6 +3826,13 @@ static const uint8_t set_adv_data_4[] = {
0x00, 0x00,
};
+static const uint8_t set_scan_rsp_1[] = {
+ 0x0a, 0x03, 0x19, 0x40, 0x03, 0x05, 0x03, 0x0d, 0x18, 0x0f,
+ 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00,
+};
+
static const uint8_t add_advertising_invalid_param_1[] = {
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
0x03, 0x03, 0x0d, 0x18,
@@ -3852,6 +3867,40 @@ static const uint8_t add_advertising_invalid_param_5[] = {
0x15, 0x16, 0x17, 0x18,
};
+static const uint8_t add_advertising_invalid_param_6[] = {
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
+ 0x03, 0x03, 0x0d, 0x18,
+ 0x19, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+ 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
+ 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e,
+};
+
+static const uint8_t add_advertising_invalid_param_7[] = {
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,
+ 0x04, 0x03, 0x0d, 0x18,
+ 0x04, 0xff, 0x01, 0x02, 0x03,
+};
+
+static const uint8_t add_advertising_invalid_param_8[] = {
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,
+ 0x03, 0x03, 0x0d, 0x18,
+ 0x02, 0xff, 0x01, 0x02, 0x03,
+};
+
+static const uint8_t add_advertising_invalid_param_9[] = {
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09,
+ 0x03, 0x03, 0x0d, 0x18,
+ 0x05, 0xff, 0x01, 0x02, 0x03,
+};
+
+static const uint8_t add_advertising_invalid_param_10[] = {
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1D,
+ 0x03, 0x03, 0x0d, 0x18,
+ 0x19, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+ 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
+ 0x15, 0x16, 0x17, 0x18,
+};
+
static const struct generic_data add_advertising_fail_1 = {
.setup_settings = settings_powered,
.send_opcode = MGMT_OP_ADD_ADVERTISING,
@@ -3900,6 +3949,46 @@ static const struct generic_data add_advertising_fail_6 = {
.expect_status = MGMT_STATUS_INVALID_PARAMS,
};
+static const struct generic_data add_advertising_fail_7 = {
+ .setup_settings = settings_powered_le,
+ .send_opcode = MGMT_OP_ADD_ADVERTISING,
+ .send_param = add_advertising_invalid_param_6,
+ .send_len = sizeof(add_advertising_invalid_param_6),
+ .expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data add_advertising_fail_8 = {
+ .setup_settings = settings_powered_le,
+ .send_opcode = MGMT_OP_ADD_ADVERTISING,
+ .send_param = add_advertising_invalid_param_7,
+ .send_len = sizeof(add_advertising_invalid_param_7),
+ .expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data add_advertising_fail_9 = {
+ .setup_settings = settings_powered_le,
+ .send_opcode = MGMT_OP_ADD_ADVERTISING,
+ .send_param = add_advertising_invalid_param_8,
+ .send_len = sizeof(add_advertising_invalid_param_8),
+ .expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data add_advertising_fail_10 = {
+ .setup_settings = settings_powered_le,
+ .send_opcode = MGMT_OP_ADD_ADVERTISING,
+ .send_param = add_advertising_invalid_param_9,
+ .send_len = sizeof(add_advertising_invalid_param_9),
+ .expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data add_advertising_fail_11 = {
+ .setup_settings = settings_powered_le,
+ .send_opcode = MGMT_OP_ADD_ADVERTISING,
+ .send_param = add_advertising_invalid_param_10,
+ .send_len = sizeof(add_advertising_invalid_param_10),
+ .expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
static const struct generic_data add_advertising_success_1 = {
.setup_settings = settings_powered_le,
.send_opcode = MGMT_OP_ADD_ADVERTISING,
@@ -3970,6 +4059,38 @@ static const struct generic_data add_advertising_success_5 = {
.expect_hci_len = sizeof(set_adv_data_3),
};
+static const struct generic_data add_advertising_success_6 = {
+ .setup_settings = settings_powered_le,
+ .send_opcode = MGMT_OP_ADD_ADVERTISING,
+ .send_param = add_advertising_param_2,
+ .send_len = sizeof(add_advertising_param_2),
+ .expect_param = advertising_instance_param,
+ .expect_len = sizeof(advertising_instance_param),
+ .expect_status = MGMT_STATUS_SUCCESS,
+ .expect_alt_ev = MGMT_EV_ADVERTISING_ADDED,
+ .expect_alt_ev_param = advertising_instance_param,
+ .expect_alt_ev_len = sizeof(advertising_instance_param),
+ .expect_hci_command = BT_HCI_CMD_LE_SET_ADV_DATA,
+ .expect_hci_param = set_adv_data_1,
+ .expect_hci_len = sizeof(set_adv_data_1),
+};
+
+static const struct generic_data add_advertising_success_7 = {
+ .setup_settings = settings_powered_le,
+ .send_opcode = MGMT_OP_ADD_ADVERTISING,
+ .send_param = add_advertising_param_2,
+ .send_len = sizeof(add_advertising_param_2),
+ .expect_param = advertising_instance_param,
+ .expect_len = sizeof(advertising_instance_param),
+ .expect_status = MGMT_STATUS_SUCCESS,
+ .expect_alt_ev = MGMT_EV_ADVERTISING_ADDED,
+ .expect_alt_ev_param = advertising_instance_param,
+ .expect_alt_ev_len = sizeof(advertising_instance_param),
+ .expect_hci_command = BT_HCI_CMD_LE_SET_SCAN_RSP_DATA,
+ .expect_hci_param = set_scan_rsp_1,
+ .expect_hci_len = sizeof(set_scan_rsp_1),
+};
+
static const uint8_t remove_advertising_param_1[] = {
0x01,
};
@@ -5823,6 +5944,21 @@ int main(int argc, char *argv[])
test_le("Add Advertising - Invalid Params 5 (AD too long)",
&add_advertising_fail_6,
NULL, test_command_generic);
+ test_bredrle("Add Advertising - Invalid Params 6 (ScRsp too long)",
+ &add_advertising_fail_7,
+ NULL, test_command_generic);
+ test_bredrle("Add Advertising - Invalid Params 7 (Malformed len)",
+ &add_advertising_fail_8,
+ NULL, test_command_generic);
+ test_bredrle("Add Advertising - Invalid Params 8 (Malformed len)",
+ &add_advertising_fail_9,
+ NULL, test_command_generic);
+ test_bredrle("Add Advertising - Invalid Params 9 (Malformed len)",
+ &add_advertising_fail_10,
+ NULL, test_command_generic);
+ test_le("Add Advertising - Invalid Params 10 (ScRsp too long)",
+ &add_advertising_fail_11,
+ NULL, test_command_generic);
test_bredrle("Add Advertising - Success 1",
&add_advertising_success_1,
NULL, test_command_generic);
@@ -5842,6 +5978,12 @@ int main(int argc, char *argv[])
&add_advertising_success_5,
setup_set_and_add_advertising,
test_command_generic);
+ test_bredrle("Add Advertising - Success 4",
+ &add_advertising_success_6,
+ NULL, test_command_generic);
+ test_bredrle("Add Advertising - Success 5",
+ &add_advertising_success_7,
+ NULL, test_command_generic);
test_bredrle("Remove Advertising - Invalid Params 1",
&remove_advertising_fail_1,
--
2.2.0.rc0.207.ga3a616c
Added test cases for the Add Advertising command.
---
tools/mgmt-tester.c | 346 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 346 insertions(+)
diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index e2549d4..6d334c6 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -3780,6 +3780,196 @@ static const struct generic_data remove_device_success_5 = {
.expect_hci_len = sizeof(set_le_scan_off),
};
+static const uint8_t add_advertising_param_1[] = {
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
+ 0x03, 0x03, 0x0d, 0x18,
+ 0x04, 0xff, 0x01, 0x02, 0x03,
+};
+
+static const uint8_t advertising_instance_param[] = {
+ 0x01,
+};
+
+static const uint8_t set_adv_data_1[] = {
+ 0x09, 0x03, 0x03, 0x0d, 0x18, 0x04, 0xff, 0x01, 0x02, 0x03,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00,
+};
+
+static const uint8_t set_adv_data_2[] = {
+ 0x0c, 0x02, 0x01, 0x04, 0x03, 0x03, 0x0d, 0x18, 0x04, 0xff,
+ 0x01, 0x02, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00,
+};
+
+static const uint8_t set_adv_data_3[] = {
+ 0x06, 0x05, 0x08, 0x74, 0x65, 0x73, 0x74, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00,
+};
+
+static const uint8_t set_adv_data_4[] = {
+ 0x03, 0x02, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00,
+};
+
+static const uint8_t add_advertising_invalid_param_1[] = {
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00,
+ 0x03, 0x03, 0x0d, 0x18,
+ 0x19, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+ 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
+ 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e,
+};
+
+static const uint8_t add_advertising_invalid_param_2[] = {
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
+ 0x04, 0x03, 0x0d, 0x18,
+ 0x04, 0xff, 0x01, 0x02, 0x03,
+};
+
+static const uint8_t add_advertising_invalid_param_3[] = {
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
+ 0x03, 0x03, 0x0d, 0x18,
+ 0x02, 0xff, 0x01, 0x02, 0x03,
+};
+
+static const uint8_t add_advertising_invalid_param_4[] = {
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
+ 0x03, 0x03, 0x0d, 0x18,
+ 0x05, 0xff, 0x01, 0x02, 0x03,
+};
+
+static const uint8_t add_advertising_invalid_param_5[] = {
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1D, 0x00,
+ 0x03, 0x03, 0x0d, 0x18,
+ 0x19, 0xff, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
+ 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
+ 0x15, 0x16, 0x17, 0x18,
+};
+
+static const struct generic_data add_advertising_fail_1 = {
+ .setup_settings = settings_powered,
+ .send_opcode = MGMT_OP_ADD_ADVERTISING,
+ .send_param = add_advertising_param_1,
+ .send_len = sizeof(add_advertising_param_1),
+ .expect_status = MGMT_STATUS_REJECTED,
+};
+
+static const struct generic_data add_advertising_fail_2 = {
+ .setup_settings = settings_powered_le,
+ .send_opcode = MGMT_OP_ADD_ADVERTISING,
+ .send_param = add_advertising_invalid_param_1,
+ .send_len = sizeof(add_advertising_invalid_param_1),
+ .expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data add_advertising_fail_3 = {
+ .setup_settings = settings_powered_le,
+ .send_opcode = MGMT_OP_ADD_ADVERTISING,
+ .send_param = add_advertising_invalid_param_2,
+ .send_len = sizeof(add_advertising_invalid_param_2),
+ .expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data add_advertising_fail_4 = {
+ .setup_settings = settings_powered_le,
+ .send_opcode = MGMT_OP_ADD_ADVERTISING,
+ .send_param = add_advertising_invalid_param_3,
+ .send_len = sizeof(add_advertising_invalid_param_3),
+ .expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data add_advertising_fail_5 = {
+ .setup_settings = settings_powered_le,
+ .send_opcode = MGMT_OP_ADD_ADVERTISING,
+ .send_param = add_advertising_invalid_param_4,
+ .send_len = sizeof(add_advertising_invalid_param_4),
+ .expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data add_advertising_fail_6 = {
+ .setup_settings = settings_powered_le,
+ .send_opcode = MGMT_OP_ADD_ADVERTISING,
+ .send_param = add_advertising_invalid_param_5,
+ .send_len = sizeof(add_advertising_invalid_param_5),
+ .expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data add_advertising_success_1 = {
+ .setup_settings = settings_powered_le,
+ .send_opcode = MGMT_OP_ADD_ADVERTISING,
+ .send_param = add_advertising_param_1,
+ .send_len = sizeof(add_advertising_param_1),
+ .expect_param = advertising_instance_param,
+ .expect_len = sizeof(advertising_instance_param),
+ .expect_status = MGMT_STATUS_SUCCESS,
+ .expect_alt_ev = MGMT_EV_ADVERTISING_ADDED,
+ .expect_alt_ev_param = advertising_instance_param,
+ .expect_alt_ev_len = sizeof(advertising_instance_param),
+ .expect_hci_command = BT_HCI_CMD_LE_SET_ADV_DATA,
+ .expect_hci_param = set_adv_data_1,
+ .expect_hci_len = sizeof(set_adv_data_1),
+};
+
+static const char set_powered_adv_instance_settings_param[] = {
+ 0x81, 0x02, 0x00, 0x00,
+};
+
+static const struct generic_data add_advertising_success_2 = {
+ .send_opcode = MGMT_OP_SET_POWERED,
+ .send_param = set_powered_on_param,
+ .send_len = sizeof(set_powered_on_param),
+ .expect_status = MGMT_STATUS_SUCCESS,
+ .expect_param = set_powered_adv_instance_settings_param,
+ .expect_len = sizeof(set_powered_adv_instance_settings_param),
+ .expect_hci_command = BT_HCI_CMD_LE_SET_ADV_DATA,
+ .expect_hci_param = set_adv_data_3,
+ .expect_hci_len = sizeof(set_adv_data_3),
+};
+
+static const struct generic_data add_advertising_success_3 = {
+ .send_opcode = MGMT_OP_SET_POWERED,
+ .send_param = set_powered_on_param,
+ .send_len = sizeof(set_powered_on_param),
+ .expect_status = MGMT_STATUS_SUCCESS,
+ .expect_param = set_powered_adv_instance_settings_param,
+ .expect_len = sizeof(set_powered_adv_instance_settings_param),
+ .expect_hci_command = BT_HCI_CMD_LE_SET_ADV_ENABLE,
+ .expect_hci_param = set_adv_on_set_adv_enable_param,
+ .expect_hci_len = sizeof(set_adv_on_set_adv_enable_param),
+};
+
+static const struct generic_data add_advertising_success_4 = {
+ .send_opcode = MGMT_OP_SET_ADVERTISING,
+ .send_param = set_adv_on_param,
+ .send_len = sizeof(set_adv_on_param),
+ .expect_status = MGMT_STATUS_SUCCESS,
+ .expect_param = set_adv_settings_param_2,
+ .expect_len = sizeof(set_adv_settings_param_2),
+ .expect_hci_command = BT_HCI_CMD_LE_SET_ADV_DATA,
+ .expect_hci_param = set_adv_data_4,
+ .expect_hci_len = sizeof(set_adv_data_4),
+};
+
+static const char set_adv_off_param[] = { 0x00 };
+
+static const struct generic_data add_advertising_success_5 = {
+ .send_opcode = MGMT_OP_SET_ADVERTISING,
+ .send_param = set_adv_off_param,
+ .send_len = sizeof(set_adv_off_param),
+ .expect_status = MGMT_STATUS_SUCCESS,
+ .expect_param = set_powered_adv_instance_settings_param,
+ .expect_len = sizeof(set_powered_adv_instance_settings_param),
+ .expect_hci_command = BT_HCI_CMD_LE_SET_ADV_DATA,
+ .expect_hci_param = set_adv_data_3,
+ .expect_hci_len = sizeof(set_adv_data_3),
+};
+
static void client_cmd_complete(uint16_t opcode, uint8_t status,
const void *param, uint8_t len,
void *user_data)
@@ -4130,6 +4320,124 @@ static void setup_add_device(const void *test_data)
setup_powered_callback, NULL, NULL);
}
+static void setup_add_advertising_callback(uint8_t status, uint16_t length,
+ const void *param, void *user_data)
+{
+ if (status != MGMT_STATUS_SUCCESS) {
+ tester_setup_failed();
+ return;
+ }
+
+ tester_print("Add Advertising setup complete");
+
+ setup_bthost();
+}
+
+static void setup_add_advertising_not_powered(const void *test_data)
+{
+ struct test_data *data = tester_get_data();
+ struct mgmt_cp_add_advertising *cp;
+ unsigned char adv_param[sizeof(*cp) + 6];
+ unsigned char param[] = { 0x01 };
+
+ tester_print("Adding advertising instance while unpowered");
+
+ cp = (struct mgmt_cp_add_advertising *) adv_param;
+ memset(cp, 0, sizeof(*cp));
+
+ cp->instance = 1;
+ cp->adv_data_len = 6;
+ cp->data[0] = 0x05;
+ cp->data[1] = 0x08;
+ cp->data[2] = 't';
+ cp->data[3] = 'e';
+ cp->data[4] = 's';
+ cp->data[5] = 't';
+
+ mgmt_send(data->mgmt, MGMT_OP_SET_LE, data->mgmt_index,
+ sizeof(param), ¶m,
+ NULL, NULL, NULL);
+
+ mgmt_send(data->mgmt, MGMT_OP_ADD_ADVERTISING, data->mgmt_index,
+ sizeof(adv_param), adv_param,
+ setup_add_advertising_callback,
+ NULL, NULL);
+}
+
+static void setup_add_advertising(const void *test_data)
+{
+ struct test_data *data = tester_get_data();
+ struct mgmt_cp_add_advertising *cp;
+ unsigned char adv_param[sizeof(*cp) + 6];
+ unsigned char param[] = { 0x01 };
+
+ tester_print("Adding advertising instance while unpowered");
+
+ cp = (struct mgmt_cp_add_advertising *) adv_param;
+ memset(cp, 0, sizeof(*cp));
+
+ cp->instance = 1;
+ cp->adv_data_len = 6;
+ cp->data[0] = 0x05;
+ cp->data[1] = 0x08;
+ cp->data[2] = 't';
+ cp->data[3] = 'e';
+ cp->data[4] = 's';
+ cp->data[5] = 't';
+
+ mgmt_send(data->mgmt, MGMT_OP_SET_LE, data->mgmt_index,
+ sizeof(param), ¶m,
+ NULL, NULL, NULL);
+
+ mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index,
+ sizeof(param), ¶m,
+ NULL, NULL, NULL);
+
+ mgmt_send(data->mgmt, MGMT_OP_ADD_ADVERTISING, data->mgmt_index,
+ sizeof(adv_param), adv_param,
+ setup_add_advertising_callback,
+ NULL, NULL);
+}
+
+static void setup_set_and_add_advertising(const void *test_data)
+{
+ struct test_data *data = tester_get_data();
+ struct mgmt_cp_add_advertising *cp;
+ unsigned char adv_param[sizeof(*cp) + 6];
+ unsigned char param[] = { 0x01 };
+
+ tester_print("Adding advertising instance while unpowered");
+
+ cp = (struct mgmt_cp_add_advertising *) adv_param;
+ memset(cp, 0, sizeof(*cp));
+
+ cp->instance = 1;
+ cp->adv_data_len = 6;
+ cp->data[0] = 0x05;
+ cp->data[1] = 0x08;
+ cp->data[2] = 't';
+ cp->data[3] = 'e';
+ cp->data[4] = 's';
+ cp->data[5] = 't';
+
+ mgmt_send(data->mgmt, MGMT_OP_SET_LE, data->mgmt_index,
+ sizeof(param), ¶m,
+ NULL, NULL, NULL);
+
+ mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index,
+ sizeof(param), ¶m,
+ NULL, NULL, NULL);
+
+ mgmt_send(data->mgmt, MGMT_OP_SET_ADVERTISING, data->mgmt_index,
+ sizeof(param), ¶m,
+ NULL, NULL, NULL);
+
+ mgmt_send(data->mgmt, MGMT_OP_ADD_ADVERTISING, data->mgmt_index,
+ sizeof(adv_param), adv_param,
+ setup_add_advertising_callback,
+ NULL, NULL);
+}
+
static void setup_complete(uint8_t status, uint16_t length,
const void *param, void *user_data)
{
@@ -5452,5 +5760,43 @@ int main(int argc, char *argv[])
&remove_device_success_5,
setup_add_device, test_command_generic);
+ test_bredrle("Add Advertising - Failure: LE off",
+ &add_advertising_fail_1,
+ NULL, test_command_generic);
+ test_bredrle("Add Advertising - Invalid Params 1 (AD too long)",
+ &add_advertising_fail_2,
+ NULL, test_command_generic);
+ test_bredrle("Add Advertising - Invalid Params 2 (Malformed len)",
+ &add_advertising_fail_3,
+ NULL, test_command_generic);
+ test_bredrle("Add Advertising - Invalid Params 3 (Malformed len)",
+ &add_advertising_fail_4,
+ NULL, test_command_generic);
+ test_bredrle("Add Advertising - Invalid Params 4 (Malformed len)",
+ &add_advertising_fail_5,
+ NULL, test_command_generic);
+ test_le("Add Advertising - Invalid Params 5 (AD too long)",
+ &add_advertising_fail_6,
+ NULL, test_command_generic);
+ test_bredrle("Add Advertising - Success 1",
+ &add_advertising_success_1,
+ NULL, test_command_generic);
+ test_bredrle("Add Advertising - Success 2",
+ &add_advertising_success_2,
+ setup_add_advertising_not_powered,
+ test_command_generic);
+ test_bredrle("Add Advertising - Success 3",
+ &add_advertising_success_3,
+ setup_add_advertising_not_powered,
+ test_command_generic);
+ test_bredrle("Add Advertising - Set Advertising on override 1",
+ &add_advertising_success_4,
+ setup_add_advertising,
+ test_command_generic);
+ test_bredrle("Add Advertising - Set Advertising off override 2",
+ &add_advertising_success_5,
+ setup_set_and_add_advertising,
+ test_command_generic);
+
return tester_run();
}
--
2.2.0.rc0.207.ga3a616c
This patch adds test cases for the Remove Advertising command.
---
tools/mgmt-tester.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 6d334c6..1648dc8 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -3970,6 +3970,51 @@ static const struct generic_data add_advertising_success_5 = {
.expect_hci_len = sizeof(set_adv_data_3),
};
+static const uint8_t remove_advertising_param_1[] = {
+ 0x01,
+};
+
+static const uint8_t remove_advertising_param_2[] = {
+ 0x00,
+};
+
+static const struct generic_data remove_advertising_fail_1 = {
+ .send_opcode = MGMT_OP_REMOVE_ADVERTISING,
+ .send_param = remove_advertising_param_1,
+ .send_len = sizeof(remove_advertising_param_1),
+ .expect_status = MGMT_STATUS_INVALID_PARAMS,
+};
+
+static const struct generic_data remove_advertising_success_1 = {
+ .send_opcode = MGMT_OP_REMOVE_ADVERTISING,
+ .send_param = remove_advertising_param_1,
+ .send_len = sizeof(remove_advertising_param_1),
+ .expect_status = MGMT_STATUS_SUCCESS,
+ .expect_param = remove_advertising_param_1,
+ .expect_len = sizeof(remove_advertising_param_1),
+ .expect_alt_ev = MGMT_EV_ADVERTISING_REMOVED,
+ .expect_alt_ev_param = advertising_instance_param,
+ .expect_alt_ev_len = sizeof(advertising_instance_param),
+ .expect_hci_command = BT_HCI_CMD_LE_SET_ADV_ENABLE,
+ .expect_hci_param = set_adv_off_param,
+ .expect_hci_len = sizeof(set_adv_off_param),
+};
+
+static const struct generic_data remove_advertising_success_2 = {
+ .send_opcode = MGMT_OP_REMOVE_ADVERTISING,
+ .send_param = remove_advertising_param_2,
+ .send_len = sizeof(remove_advertising_param_2),
+ .expect_status = MGMT_STATUS_SUCCESS,
+ .expect_param = remove_advertising_param_1,
+ .expect_len = sizeof(remove_advertising_param_1),
+ .expect_alt_ev = MGMT_EV_ADVERTISING_REMOVED,
+ .expect_alt_ev_param = advertising_instance_param,
+ .expect_alt_ev_len = sizeof(advertising_instance_param),
+ .expect_hci_command = BT_HCI_CMD_LE_SET_ADV_ENABLE,
+ .expect_hci_param = set_adv_off_param,
+ .expect_hci_len = sizeof(set_adv_off_param),
+};
+
static void client_cmd_complete(uint16_t opcode, uint8_t status,
const void *param, uint8_t len,
void *user_data)
@@ -5798,5 +5843,17 @@ int main(int argc, char *argv[])
setup_set_and_add_advertising,
test_command_generic);
+ test_bredrle("Remove Advertising - Invalid Params 1",
+ &remove_advertising_fail_1,
+ NULL, test_command_generic);
+ test_bredrle("Remove Advertising - Success 1",
+ &remove_advertising_success_1,
+ setup_add_advertising,
+ test_command_generic);
+ test_bredrle("Remove Advertising - Success 2",
+ &remove_advertising_success_2,
+ setup_add_advertising,
+ test_command_generic);
+
return tester_run();
}
--
2.2.0.rc0.207.ga3a616c
This patch provides data structures and opcodes for the Add/Remove
Advertising commands and the Advertising Added/Removed events.
---
lib/mgmt.h | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/lib/mgmt.h b/lib/mgmt.h
index 15dee70..01d948b 100644
--- a/lib/mgmt.h
+++ b/lib/mgmt.h
@@ -484,6 +484,29 @@ struct mgmt_rp_read_adv_features {
uint8_t instance[0];
} __packed;
+#define MGMT_OP_ADD_ADVERTISING 0x003E
+struct mgmt_cp_add_advertising {
+ uint8_t instance;
+ uint32_t flags;
+ uint16_t duration;
+ uint16_t timeout;
+ uint8_t adv_data_len;
+ uint8_t scan_rsp_len;
+ uint8_t data[0];
+} __packed;
+struct mgmt_rp_add_advertising {
+ uint8_t instance;
+} __packed;
+
+#define MGMT_OP_REMOVE_ADVERTISING 0x003F
+struct mgmt_cp_remove_advertising {
+ uint8_t instance;
+} __packed;
+#define MGMT_REMOVE_ADVERTISING_SIZE 1
+struct mgmt_rp_remove_advertising {
+ uint8_t instance;
+} __packed;
+
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
uint16_t opcode;
@@ -686,6 +709,16 @@ struct mgmt_ev_local_oob_data_updated {
uint8_t eir[0];
} __packed;
+#define MGMT_EV_ADVERTISING_ADDED 0x0023
+struct mgmt_ev_advertising_added {
+ uint8_t instance;
+} __packed;
+
+#define MGMT_EV_ADVERTISING_REMOVED 0x0024
+struct mgmt_ev_advertising_removed {
+ uint8_t instance;
+} __packed;
+
static const char *mgmt_op[] = {
"<0x0000>",
"Read Version",
--
2.2.0.rc0.207.ga3a616c