Diff between 5b1a876e42c82ec00534be575bb9659224077900 and 33c8ed93e8dc7f04fa89c97a12ab4b09bcf455dc

Changed Files

File Additions Deletions Status
tools/mgmt-tester.c +44 -0 modified

Full Patch

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index fc2baf4..0f83b07 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -2766,6 +2766,15 @@ static const struct generic_data pairing_acceptor_le_3 = {
 	.reject_confirm = true,
 };
 
+static const struct generic_data pairing_acceptor_le_4 = {
+	.setup_settings = settings_powered_bondable_connectable_advertising,
+	.io_cap = 0x02, /* KeyboardOnly */
+	.client_io_cap = 0x04, /* KeyboardDisplay */
+	.client_auth_req = 0x05, /* Bonding - MITM */
+	.expect_alt_ev =  MGMT_EV_NEW_LONG_TERM_KEY,
+	.expect_alt_ev_len = sizeof(struct mgmt_ev_new_long_term_key),
+};
+
 static const char unpair_device_param[] = {
 			0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00, 0x00 };
 static const char unpair_device_rsp[] = {
@@ -3643,6 +3652,34 @@ static void user_confirm_request_callback(uint16_t index, uint16_t length,
 							NULL, NULL, NULL);
 }
 
+static void user_passkey_request_callback(uint16_t index, uint16_t length,
+							const void *param,
+							void *user_data)
+{
+	const struct mgmt_ev_user_passkey_request *ev = param;
+	struct test_data *data = user_data;
+	const struct generic_data *test = data->test_data;
+	struct mgmt_cp_user_passkey_reply cp;
+	uint16_t opcode;
+
+	if (test->just_works) {
+		tester_warn("User Passkey Request for just-works case");
+		tester_test_failed();
+		return;
+	}
+
+	memset(&cp, 0, sizeof(cp));
+	memcpy(&cp.addr, &ev->addr, sizeof(cp.addr));
+
+	if (test->reject_confirm)
+		opcode = MGMT_OP_USER_PASSKEY_NEG_REPLY;
+	else
+		opcode = MGMT_OP_USER_PASSKEY_REPLY;
+
+	mgmt_reply(data->mgmt, opcode, data->mgmt_index, sizeof(cp), &cp,
+							NULL, NULL, NULL);
+}
+
 static void test_setup(const void *test_data)
 {
 	struct test_data *data = tester_get_data();
@@ -3664,6 +3701,10 @@ static void test_setup(const void *test_data)
 			data->mgmt_index, user_confirm_request_callback,
 			data, NULL);
 
+	mgmt_register(data->mgmt, MGMT_EV_USER_PASSKEY_REQUEST,
+			data->mgmt_index, user_passkey_request_callback,
+			data, NULL);
+
 	if (test->client_pin)
 		bthost_set_pin_code(bthost, test->client_pin,
 							test->client_pin_len);
@@ -4590,6 +4631,9 @@ int main(int argc, char *argv[])
 	test_le("Pairing Acceptor - LE 3",
 				&pairing_acceptor_le_3, setup_pairing_acceptor,
 				test_pairing_acceptor);
+	test_le("Pairing Acceptor - LE 4",
+				&pairing_acceptor_le_4, setup_pairing_acceptor,
+				test_pairing_acceptor);
 
 	test_bredrle("Unpair Device - Not Powered 1",
 				&unpair_device_not_powered_test_1,