From c91d0646a6bf06f054324fafbf44a004ec2699b2 Mon Sep 17 00:00:00 2001 From: Trond Einar Snekvik Date: Mon, 26 Aug 2019 14:34:44 +0200 Subject: [PATCH] Bluetooth: Mesh: Add prov input_complete cb Allows the user to pass a provisioning input complete callback to the provisioning module, letting the application stop displaying its output OOB value when the other party finishes their OOB input. Signed-off-by: Trond Einar Snekvik --- include/bluetooth/mesh/main.h | 8 ++++++++ subsys/bluetooth/mesh/prov.c | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/bluetooth/mesh/main.h b/include/bluetooth/mesh/main.h index 935ec0003f2..b6f47d8a7f7 100644 --- a/include/bluetooth/mesh/main.h +++ b/include/bluetooth/mesh/main.h @@ -128,6 +128,14 @@ struct bt_mesh_prov { */ int (*input)(bt_mesh_input_action_t act, u8_t size); + /** @brief The other device finished their OOB input. + * + * This callback notifies the application that it should stop + * displaying its output OOB value, as the other party finished their + * OOB input. + */ + void (*input_complete)(void); + /** @brief Provisioning link has been opened. * * This callback notifies the application that a provisioning diff --git a/subsys/bluetooth/mesh/prov.c b/subsys/bluetooth/mesh/prov.c index dded2ab4c59..e253ba5ef96 100644 --- a/subsys/bluetooth/mesh/prov.c +++ b/subsys/bluetooth/mesh/prov.c @@ -112,6 +112,7 @@ enum { 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. */ LINK_INVALID, /* Error occurred during provisioning */ NUM_FLAGS, @@ -672,6 +673,8 @@ static int prov_auth(u8_t method, u8_t action, u8_t size) return -EINVAL; } + atomic_set_bit(link.flags, NOTIFY_INPUT_COMPLETE); + if (output == BT_MESH_DISPLAY_STRING) { unsigned char str[9]; u8_t i; @@ -954,9 +957,18 @@ static void pub_key_ready(const u8_t *pkey) } } +static void notify_input_complete(void) +{ + if (atomic_test_and_clear_bit(link.flags, NOTIFY_INPUT_COMPLETE) && + prov->input_complete) { + prov->input_complete(); + } +} + static void prov_input_complete(const u8_t *data) { BT_DBG(""); + notify_input_complete(); } static void prov_confirm(const u8_t *data) @@ -965,6 +977,7 @@ static void prov_confirm(const u8_t *data) memcpy(link.conf, data, 16); + notify_input_complete(); send_confirm(); }