From f0a80d06e825a6b8c689d8e8ed495a826b95b089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Fri, 6 Nov 2020 11:08:48 +0100 Subject: [PATCH] mesh: Fix send input_complete before public key According Mesh Profile Spec 5.4.2.4 Authentication, if device use Input OOB Authentication method, should send input complete pub after local public key has been acked. `bt_mesh_input_string` or `bt_mesh_input_number` directly send `input_complete`, however does not check whether the pub key has been sent. Mesh Provisioning timeout set to `60` seconds, so even this probability is extremely low, it does not mean that there is no such probability. this is port of 4cc8cb1c1513033e8aa6d9c1086456a062c9bc57 --- nimble/host/mesh/src/prov.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/nimble/host/mesh/src/prov.c b/nimble/host/mesh/src/prov.c index e2b36ab46..a75ba7f26 100644 --- a/nimble/host/mesh/src/prov.c +++ b/nimble/host/mesh/src/prov.c @@ -63,12 +63,14 @@ #define PROV_ALG_P256 0x00 enum { - WAIT_PUB_KEY, /* Waiting for local PubKey to be generated */ - LINK_ACTIVE, /* Link has been opened */ - WAIT_NUMBER, /* Waiting for number input from user */ - WAIT_STRING, /* Waiting for string input from user */ - NOTIFY_INPUT_COMPLETE, /* Notify that input has been completed. */ - PROVISIONER, /* The link was opened as provisioner */ + WAIT_PUB_KEY, /* Waiting for local PubKey to be generated */ + LINK_ACTIVE, /* Link has been opened */ + WAIT_NUMBER, /* Waiting for number input from user */ + WAIT_STRING, /* Waiting for string input from user */ + NOTIFY_INPUT_COMPLETE, /* Notify that input has been completed. */ + PROVISIONER, /* The link was opened as provisioner */ + PUB_KEY_SENT, /* Public key has been sent */ + INPUT_COMPLETE, /* Device input completed */ NUM_FLAGS, }; @@ -589,6 +591,15 @@ static void send_input_complete(void) os_mbuf_free_chain(buf); } +static void input_complete(void) +{ + if (atomic_test_bit(link.flags, PUB_KEY_SENT)) { + send_input_complete(); + } else { + atomic_set_bit(link.flags, INPUT_COMPLETE); + } +} + int bt_mesh_input_number(uint32_t num) { BT_DBG("%u", (unsigned) num); @@ -599,11 +610,21 @@ int bt_mesh_input_number(uint32_t num) sys_put_be32(num, &link.auth[12]); - send_input_complete(); + input_complete(); return 0; } +static void public_key_sent(int err, void *cb_data) +{ + atomic_set_bit(link.flags, PUB_KEY_SENT); + + if (atomic_test_bit(link.flags, INPUT_COMPLETE)) { + send_input_complete(); + return; + } +} + int bt_mesh_input_string(const char *str) { BT_DBG("%s", str); @@ -647,7 +668,7 @@ static void send_pub_key(void) memcpy(&link.conf_inputs[81], &buf->om_data[1], 64); } - if (prov_send(buf, NULL)) { + if (prov_send(buf, public_key_sent)) { BT_ERR("Failed to send Public Key"); goto done; }