From de92d1a83b542fb22c87f46073bb80c325a8a5cb Mon Sep 17 00:00:00 2001 From: Tobias Svehagen Date: Sat, 13 Jul 2019 12:18:43 +0200 Subject: [PATCH] Bluetooth: Mesh: Add callback for unprovisioned device beacon Adds the unprovisioned_beacon callback to the bt_mesh_prov structure. Signed-off-by: Tobias Svehagen --- include/bluetooth/mesh/main.h | 14 +++++++++++++ subsys/bluetooth/mesh/beacon.c | 36 +++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/include/bluetooth/mesh/main.h b/include/bluetooth/mesh/main.h index b6f47d8a7f7..bbaa670fd05 100644 --- a/include/bluetooth/mesh/main.h +++ b/include/bluetooth/mesh/main.h @@ -136,6 +136,20 @@ struct bt_mesh_prov { */ void (*input_complete)(void); + /** @brief Unprovisioned beacon has been received. + * + * This callback notifies the application that an unprovisioned + * beacon has been received. + * + * @param uuid UUID + * @param oob_info OOB Information + * @param uri_hash Pointer to URI Hash value. NULL if no hash was + * present in the beacon. + */ + void (*unprovisioned_beacon)(u8_t uuid[16], + bt_mesh_prov_oob_info_t oob_info, + u32_t *uri_hash); + /** @brief Provisioning link has been opened. * * This callback notifies the application that a provisioning diff --git a/subsys/bluetooth/mesh/beacon.c b/subsys/bluetooth/mesh/beacon.c index f0f30605656..bbf126545d2 100644 --- a/subsys/bluetooth/mesh/beacon.c +++ b/subsys/bluetooth/mesh/beacon.c @@ -205,6 +205,40 @@ static int unprovisioned_beacon_send(void) return 0; } +static void unprovisioned_beacon_recv(struct net_buf_simple *buf) +{ +#if defined(CONFIG_BT_MESH_PB_ADV) + const struct bt_mesh_prov *prov; + u8_t *uuid; + u16_t oob_info; + u32_t uri_hash_val; + u32_t *uri_hash = NULL; + + if (buf->len != 18 && buf->len != 22) { + BT_ERR("Invalid unprovisioned beacon length (%u)", buf->len); + return; + } + + uuid = net_buf_simple_pull_mem(buf, 16); + oob_info = net_buf_simple_pull_be16(buf); + + if (buf->len == 4) { + uri_hash_val = net_buf_simple_pull_be32(buf); + uri_hash = &uri_hash_val; + } + + BT_DBG("uuid %s", bt_hex(uuid, 16)); + + prov = bt_mesh_prov_get(); + + if (prov->unprovisioned_beacon) { + prov->unprovisioned_beacon(uuid, + (bt_mesh_prov_oob_info_t)oob_info, + uri_hash); + } +#endif +} + static void update_beacon_observation(void) { static bool first_half; @@ -352,7 +386,7 @@ void bt_mesh_beacon_recv(struct net_buf_simple *buf) type = net_buf_simple_pull_u8(buf); switch (type) { case BEACON_TYPE_UNPROVISIONED: - BT_DBG("Ignoring unprovisioned device beacon"); + unprovisioned_beacon_recv(buf); break; case BEACON_TYPE_SECURE: secure_beacon_recv(buf);