From d408f4afe5e70962937c7ce015d0a80a79b0e3a9 Mon Sep 17 00:00:00 2001 From: Trond Einar Snekvik Date: Fri, 16 Aug 2019 10:56:51 +0200 Subject: [PATCH] Bluetooth: Mesh: Prov confirm tx after confirm rx According to Mesh Profile Specification 1.0.1 Figure 5.17, the unprovisioned device should send its confirmation value after the provisioner sends theirs. Previously, the confirmation value would be sent immediately after OOB input complete. Now it first waits for the input data, then from confirmation from the provisioner before sending the confirmation. Fixes: #18178. Signed-off-by: Trond Einar Snekvik --- subsys/bluetooth/mesh/prov.c | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/subsys/bluetooth/mesh/prov.c b/subsys/bluetooth/mesh/prov.c index a72a72e5c53..b1546738e02 100644 --- a/subsys/bluetooth/mesh/prov.c +++ b/subsys/bluetooth/mesh/prov.c @@ -108,7 +108,6 @@ enum { REMOTE_PUB_KEY, /* Remote key has been received */ LINK_ACTIVE, /* Link has been opened */ - SEND_CONFIRM, /* Waiting to send Confirm value */ WAIT_NUMBER, /* Waiting for number input from user */ WAIT_STRING, /* Waiting for string input from user */ LINK_INVALID, /* Error occurred during provisioning */ @@ -823,6 +822,7 @@ static void send_input_complete(void) if (prov_send(&buf)) { BT_ERR("Failed to send Provisioning Input Complete"); } + link.expect = PROV_CONFIRM; } int bt_mesh_input_number(u32_t num) @@ -837,10 +837,6 @@ int bt_mesh_input_number(u32_t num) send_input_complete(); - if (atomic_test_and_clear_bit(link.flags, SEND_CONFIRM)) { - send_confirm(); - } - return 0; } @@ -856,10 +852,6 @@ int bt_mesh_input_string(const char *str) send_input_complete(); - if (atomic_test_and_clear_bit(link.flags, SEND_CONFIRM)) { - send_confirm(); - } - return 0; } @@ -902,8 +894,11 @@ static void send_pub_key(const u8_t dhkey[32]) return; } - atomic_set_bit(link.flags, SEND_CONFIRM); - link.expect = PROV_CONFIRM; + if (atomic_test_bit(link.flags, WAIT_NUMBER) || atomic_test_bit(link.flags, WAIT_STRING)) { + link.expect = 0xff; /* Don't expect any packets until after input */ + } else { + link.expect = PROV_CONFIRM; + } } static void prov_dh_key_gen(void) @@ -968,18 +963,7 @@ static void prov_confirm(const u8_t *data) memcpy(link.conf, data, 16); - if (atomic_test_bit(link.flags, WAIT_NUMBER) || - atomic_test_bit(link.flags, WAIT_STRING)) { - /* Clear retransmit timer */ -#if defined(CONFIG_BT_MESH_PB_ADV) - prov_clear_tx(); -#endif - return; - } - - if (atomic_test_and_clear_bit(link.flags, SEND_CONFIRM)) { - send_confirm(); - } + send_confirm(); } static void prov_random(const u8_t *data)