From 6826f9dbba2b16fc4374dd99783ef623debea471 Mon Sep 17 00:00:00 2001 From: wangjialiang Date: Tue, 20 Apr 2021 11:39:28 +0800 Subject: [PATCH] ble_mesh: stack: Fix provisioning input or output count number should be at least 1 Closes https://github.com/espressif/esp-idf/issues/6863 --- components/bt/esp_ble_mesh/mesh_core/prov.c | 13 ++++++++++++- .../bt/esp_ble_mesh/mesh_core/provisioner_prov.c | 12 +++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/prov.c b/components/bt/esp_ble_mesh/mesh_core/prov.c index c2be7fb418..9a4cef9bd4 100644 --- a/components/bt/esp_ble_mesh/mesh_core/prov.c +++ b/components/bt/esp_ble_mesh/mesh_core/prov.c @@ -751,7 +751,18 @@ static int prov_auth(uint8_t method, uint8_t action, uint8_t size) uint32_t num = 0U; bt_mesh_rand(&num, sizeof(num)); - num %= div[size - 1]; + + if (output == BLE_MESH_BLINK || + output == BLE_MESH_BEEP || + output == BLE_MESH_VIBRATE) { + /** NOTE: According to the Bluetooth Mesh Profile Specification + * Section 5.4.2.4, blink, beep and vibrate should be a random + * integer between 0 and 10^size. + */ + num = (num % (div[size - 1] - 1)) + 1; + } else { + num %= div[size - 1]; + } sys_put_be32(num, &link.auth[12]); (void)memset(link.auth, 0, 12); diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c index 37917733e4..c1ee15967a 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c @@ -1954,7 +1954,17 @@ static int prov_auth(const uint8_t idx, uint8_t method, uint8_t action, uint8_t uint32_t num = 0U; bt_mesh_rand(&num, sizeof(num)); - num %= div[size - 1]; + + if (input == BLE_MESH_PUSH || + input == BLE_MESH_TWIST) { + /** NOTE: According to the Bluetooth Mesh Profile Specification + * Section 5.4.2.4, push and twist should be a random integer + * between 0 and 10^size. + */ + num = (num % (div[size - 1] - 1)) + 1; + } else { + num %= div[size - 1]; + } sys_put_be32(num, &link[idx].auth[12]); memset(link[idx].auth, 0, 12);