diff --git a/components/bt/esp_ble_mesh/core/main.c b/components/bt/esp_ble_mesh/core/main.c index 94a43c19b1..957234e312 100644 --- a/components/bt/esp_ble_mesh/core/main.c +++ b/components/bt/esp_ble_mesh/core/main.c @@ -441,7 +441,9 @@ int bt_mesh_init(const struct bt_mesh_prov *prov, if ((IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) || - IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)) { + IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT) || + (IS_ENABLED(CONFIG_BLE_MESH_RPR_SRV) && + IS_ENABLED(CONFIG_BLE_MESH_PB_GATT))) { bt_mesh_proxy_client_init(); } @@ -591,7 +593,9 @@ int bt_mesh_deinit(struct bt_mesh_deinit_param *param) if ((IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) || - IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)) { + IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT) || + (IS_ENABLED(CONFIG_BLE_MESH_RPR_SRV) && + IS_ENABLED(CONFIG_BLE_MESH_PB_GATT))) { bt_mesh_proxy_client_deinit(); } diff --git a/components/bt/esp_ble_mesh/core/nimble_host/adapter.c b/components/bt/esp_ble_mesh/core/nimble_host/adapter.c index fcad720059..1a16321171 100644 --- a/components/bt/esp_ble_mesh/core/nimble_host/adapter.c +++ b/components/bt/esp_ble_mesh/core/nimble_host/adapter.c @@ -147,7 +147,8 @@ void bt_mesh_hci_init(void) static struct ble_gap_disc_params scan_param; #if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ - CONFIG_BLE_MESH_GATT_PROXY_CLIENT + CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \ + (CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT) static struct gattc_prov_info { /* Service to be found depends on the type of adv pkt received */ struct bt_mesh_conn conn; @@ -396,13 +397,16 @@ static int svc_disced(uint16_t conn_handle, const struct ble_gatt_error *error, return rc; } -#endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_CLIENT */ +#endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ + CONFIG_BLE_MESH_GATT_PROXY_CLIENT || + (CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT) */ static int disc_cb(struct ble_gap_event *event, void *arg) { struct ble_gap_disc_desc *desc; #if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ - CONFIG_BLE_MESH_GATT_PROXY_CLIENT + CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \ + (CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT) int rc, i; uint8_t notif_data[100]; uint16_t notif_len; @@ -425,7 +429,8 @@ static int disc_cb(struct ble_gap_event *event, void *arg) break; } #if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ - CONFIG_BLE_MESH_GATT_PROXY_CLIENT + CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \ + (CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT) case BLE_GAP_EVENT_CONNECT: if (event->connect.status == 0) { /* Connection successfully established. */ @@ -1357,7 +1362,8 @@ int bt_mesh_gatts_set_local_device_name(const char *name) #endif /* CONFIG_BLE_MESH_NODE */ #if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ - CONFIG_BLE_MESH_GATT_PROXY_CLIENT + CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \ + (CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT) void bt_mesh_gattc_conn_cb_register(struct bt_mesh_prov_conn_cb *cb) { bt_mesh_gattc_conn_cb = cb; @@ -1598,7 +1604,10 @@ void bt_mesh_gattc_disconnect(struct bt_mesh_conn *conn) * Mesh Proxy Data In: 0x2ADD * Mesh PROXY Data Out: 0x2ADE */ -#endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_CLIENT */ + +#endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || + CONFIG_BLE_MESH_GATT_PROXY_CLIENT || + (CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT)*/ struct bt_mesh_conn *bt_mesh_conn_ref(struct bt_mesh_conn *conn) { @@ -1743,7 +1752,8 @@ void bt_mesh_gatt_init(void) #endif /* CONFIG_BLE_MESH_NODE */ #if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ - CONFIG_BLE_MESH_GATT_PROXY_CLIENT + CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \ + (CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT) for (int i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) { bt_mesh_gattc_info[i].conn.handle = 0xFFFF; bt_mesh_gattc_info[i].mtu = BLE_ATT_MTU_DFLT; @@ -1761,7 +1771,8 @@ void bt_mesh_gatt_deinit(void) #endif #if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ - CONFIG_BLE_MESH_GATT_PROXY_CLIENT + CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \ + (CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT) for (int i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) { bt_mesh_gattc_info[i].conn.handle = 0xFFFF; memset(&bt_mesh_gattc_info[i].addr, 0, sizeof(bt_mesh_addr_t)); diff --git a/components/bt/esp_ble_mesh/core/prov_node.c b/components/bt/esp_ble_mesh/core/prov_node.c index 8053ac8201..0613dcadb9 100644 --- a/components/bt/esp_ble_mesh/core/prov_node.c +++ b/components/bt/esp_ble_mesh/core/prov_node.c @@ -2,7 +2,7 @@ /* * SPDX-FileCopyrightText: 2017 Intel Corporation - * SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -82,12 +82,13 @@ static void reset_state(void) } #endif /* CONFIG_BLE_MESH_PB_GATT */ -#if CONFIG_BLE_MESH_PB_ADV /* Clear everything except the retransmit and protocol timer * delayed work objects. */ (void)memset(&prov_link, 0, offsetof(struct bt_mesh_prov_link, tx.retransmit)); +#if CONFIG_BLE_MESH_PB_ADV + prov_link.pending_ack = PROV_XACT_NVAL; prov_link.rx.prev_id = PROV_XACT_NVAL; @@ -122,6 +123,8 @@ static void reset_adv_link(struct bt_mesh_prov_link *link, uint8_t reason) { ARG_UNUSED(link); + bt_mesh_prov_bearer_ctl_send(&prov_link, LINK_CLOSE, &reason, sizeof(reason)); + bt_mesh_prov_clear_tx(&prov_link, true); if (bt_mesh_prov_get()->link_close) { @@ -154,7 +157,7 @@ static int prov_send_gatt(struct bt_mesh_prov_link *link, struct net_buf_simple /* Changed by Espressif, add provisioning timeout timer operations. * When sending a provisioning PDU successfully, restart the 60s timer. */ -#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT && CONFIG_BLE_MESH_RPR_SRV +#if CONFIG_BLE_MESH_RPR_SRV if (bt_mesh_atomic_test_bit(link->flags, PB_REMOTE)) { err = bt_mesh_proxy_client_send(link->conn, BLE_MESH_PROXY_PROV, msg); @@ -1075,10 +1078,18 @@ static void link_ack(struct prov_rx *rx, struct net_buf_simple *buf) bt_mesh_prov_clear_tx(&prov_link, true); bt_mesh_rpr_srv_recv_link_ack(prov_link.pb_remote_uuid, true); } else { - BT_INFO("Link ACK for PB-Remote already received"); + BT_DBG("Link ACK for PB-Remote already received"); + return; } } #endif /* CONFIG_BLE_MESH_RPR_SRV */ + if (!k_delayed_work_remaining_get(&prov_link.prot_timer)) { + /** + * When the link is opened, the Provisioner and the unprovisioned device + * shall start the link timer from the initial value set 60 seconds. + */ + k_delayed_work_submit(&prov_link.prot_timer, PROTOCOL_TIMEOUT); + } } static void link_close(struct prov_rx *rx, struct net_buf_simple *buf) @@ -1434,6 +1445,11 @@ int bt_mesh_pb_gatt_open(struct bt_mesh_conn *conn) { BT_DBG("conn %p", conn); + /** + * It's necessary to determine if it is PB_REMOTE because when the + * node acts as an RPR server, LINK_ACTIVE has already been set upon + * receiving the link open from the RPR client. + */ if (!bt_mesh_atomic_test_bit(prov_link.flags, PB_REMOTE) && bt_mesh_atomic_test_and_set_bit(prov_link.flags, LINK_ACTIVE)) { BT_ERR("Link is busy"); @@ -1451,6 +1467,14 @@ int bt_mesh_pb_gatt_open(struct bt_mesh_conn *conn) prov_link.expect = PROV_INVITE; } + /** + * Just like ADV Link, start provision timeout timer after + * establishing the link to prevent the RPR server from + * being unable to recover to a configurable network state + * during remote provisioning. + */ + k_delayed_work_submit(&prov_link.prot_timer, PROTOCOL_TIMEOUT); + if (bt_mesh_prov_get()->link_open) { bt_mesh_prov_get()->link_open(BLE_MESH_PROV_GATT); } @@ -1496,7 +1520,7 @@ static void protocol_timeout(struct k_work *work) #if CONFIG_BLE_MESH_PB_GATT if (prov_link.conn) { -#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT && CONFIG_BLE_MESH_RPR_SRV +#if CONFIG_BLE_MESH_RPR_SRV if (bt_mesh_atomic_test_bit(prov_link.flags, PB_REMOTE)) { prov_link.pb_remote_reset = true; bt_mesh_gattc_disconnect(prov_link.conn); @@ -1512,6 +1536,7 @@ static void protocol_timeout(struct k_work *work) uint8_t reason = CLOSE_REASON_TIMEOUT; prov_link.rx.seg = 0U; bt_mesh_prov_bearer_ctl_send(&prov_link, LINK_CLOSE, &reason, sizeof(reason)); + close_link(reason); #endif /* CONFIG_BLE_MESH_PB_ADV */ } diff --git a/components/bt/esp_ble_mesh/core/prov_pvnr.c b/components/bt/esp_ble_mesh/core/prov_pvnr.c index 9066597e87..d3449a5ec4 100644 --- a/components/bt/esp_ble_mesh/core/prov_pvnr.c +++ b/components/bt/esp_ble_mesh/core/prov_pvnr.c @@ -47,6 +47,9 @@ _Static_assert(BLE_MESH_MAX_CONN >= CONFIG_BLE_MESH_PBG_SAME_TIME, */ static struct bt_mesh_prov_link prov_links[BLE_MESH_PROV_SAME_TIME]; +#if CONFIG_BLE_MESH_RPR_CLI +extern struct bt_mesh_prov_link rpr_links[CONFIG_BLE_MESH_RPR_CLI_PROV_SAME_TIME]; +#endif struct bt_mesh_prov_ctx { /* Primary element address of Provisioner */ uint16_t primary_addr; @@ -244,7 +247,7 @@ void bt_mesh_provisioner_restore_prov_info(uint16_t primary_addr, uint16_t alloc } #endif /* CONFIG_BLE_MESH_SETTINGS */ -static bool is_unprov_dev_being_provision(const uint8_t uuid[16]) +bool is_unprov_dev_being_provision(const uint8_t uuid[16]) { int i; @@ -261,6 +264,14 @@ static bool is_unprov_dev_being_provision(const uint8_t uuid[16]) } #endif /* CONFIG_BLE_MESH_FAST_PROV */ +#if CONFIG_BLE_MESH_RPR_CLI + for (i = 0; i < CONFIG_BLE_MESH_RPR_CLI_PROV_SAME_TIME;i++) { + if (!memcmp(rpr_links[i].pb_remote_uuid, uuid, 16)) { + BT_WARN("Device is being provisioning by Remote Provisioning"); + return true; + } + } +#endif for (i = 0; i < BLE_MESH_PROV_SAME_TIME; i++) { if (bt_mesh_atomic_test_bit(prov_links[i].flags, LINK_ACTIVE) #if CONFIG_BLE_MESH_PB_GATT @@ -1959,6 +1970,7 @@ static void send_prov_data(struct bt_mesh_prov_link *link) uint8_t session_key[16] = {0}; uint8_t nonce[13] = {0}; uint8_t pdu[25] = {0}; + uint8_t *dev_uuid = NULL; PROV_BUF(buf, 34); int err = 0; @@ -2014,7 +2026,13 @@ static void send_prov_data(struct bt_mesh_prov_link *link) */ /* Check if this device is a re-provisioned device */ - node = bt_mesh_provisioner_get_node_with_uuid(link->uuid); + if (bt_mesh_atomic_test_bit(link->flags, PB_REMOTE)) { + dev_uuid = link->pb_remote_uuid; + } else { + dev_uuid = link->uuid; + } + + node = bt_mesh_provisioner_get_node_with_uuid(dev_uuid); if (node) { if (link->element_num <= node->element_num && link->pb_remote_nppi != NPPI_NODE_ADDR_REFRESH) { @@ -2029,7 +2047,7 @@ static void send_prov_data(struct bt_mesh_prov_link *link) */ if (!bt_mesh_atomic_test_bit(link->flags, PB_REMOTE) || link->pb_remote_nppi == NPPI_UNKNOWN) { - bt_mesh_provisioner_remove_node(link->uuid); + bt_mesh_provisioner_remove_node(dev_uuid); } } @@ -2213,6 +2231,7 @@ static void prov_complete(struct bt_mesh_prov_link *link, uint16_t net_idx = 0U; uint16_t index = 0U; bool nppi = false; + uint8_t *dev_uuid = NULL; int err = 0; int i; @@ -2229,12 +2248,16 @@ static void prov_complete(struct bt_mesh_prov_link *link, net_idx = prov_ctx.net_idx; } - if (bt_mesh_atomic_test_bit(link->flags, PB_REMOTE) && - link->pb_remote_nppi != NPPI_UNKNOWN) { - nppi = true; + if (bt_mesh_atomic_test_bit(link->flags, PB_REMOTE)) { + if (link->pb_remote_nppi != NPPI_UNKNOWN) { + nppi = true; + } + dev_uuid = link->pb_remote_uuid; + } else { + dev_uuid = link->uuid; } - err = bt_mesh_provisioner_provision(&link->addr, link->uuid, link->oob_info, + err = bt_mesh_provisioner_provision(&link->addr, dev_uuid, link->oob_info, link->unicast_addr, link->element_num, net_idx, link->kri_flags, bt_mesh.iv_index, device_key, &index, nppi); @@ -2266,13 +2289,13 @@ static void prov_complete(struct bt_mesh_prov_link *link, #endif /* CONFIG_BLE_MESH_RPR_CLI */ if (bt_mesh_prov_get()->prov_complete) { - bt_mesh_prov_get()->prov_complete(index, link->uuid, link->unicast_addr, + bt_mesh_prov_get()->prov_complete(index, dev_uuid, link->unicast_addr, link->element_num, net_idx); } /* Find if the device is in the device queue */ for (i = 0; i < ARRAY_SIZE(unprov_dev); i++) { - if (!memcmp(unprov_dev[i].uuid, link->uuid, 16) && + if (!memcmp(unprov_dev[i].uuid, dev_uuid, 16) && (unprov_dev[i].flags & RM_AFTER_PROV)) { memset(&unprov_dev[i], 0, sizeof(struct unprov_dev_queue)); break; diff --git a/components/bt/esp_ble_mesh/core/prov_pvnr.h b/components/bt/esp_ble_mesh/core/prov_pvnr.h index 0553a72d36..c9ee8f89c4 100644 --- a/components/bt/esp_ble_mesh/core/prov_pvnr.h +++ b/components/bt/esp_ble_mesh/core/prov_pvnr.h @@ -379,6 +379,8 @@ uint16_t bt_mesh_provisioner_get_fast_prov_net_idx(void); */ uint8_t bt_mesh_set_fast_prov_unicast_addr_range(uint16_t min, uint16_t max); +bool is_unprov_dev_being_provision(const uint8_t uuid[16]); + int bt_mesh_rpr_cli_pdu_recv(struct bt_mesh_prov_link *link, uint8_t type, struct net_buf_simple *buf); diff --git a/components/bt/esp_ble_mesh/core/proxy_client.c b/components/bt/esp_ble_mesh/core/proxy_client.c index 1719e4737d..016db7f2ce 100644 --- a/components/bt/esp_ble_mesh/core/proxy_client.c +++ b/components/bt/esp_ble_mesh/core/proxy_client.c @@ -26,7 +26,8 @@ #endif #if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ - CONFIG_BLE_MESH_GATT_PROXY_CLIENT + CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \ + (CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT) static struct bt_mesh_proxy_server { struct bt_mesh_conn *conn; @@ -85,6 +86,22 @@ static void proxy_sar_timeout(struct k_work *work) bt_mesh_gattc_disconnect(server->conn); } +#if (CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT) +int bt_mesh_rpr_srv_set_waiting_prov_link(struct bt_mesh_prov_link *link, + bt_mesh_addr_t *addr) +{ + for (size_t i = 0; i < ARRAY_SIZE(waiting_conn_link);i++) { + if (waiting_conn_link[i].link == NULL) { + waiting_conn_link[i].link = link; + memcpy(&waiting_conn_link[i].addr, addr, sizeof(bt_mesh_addr_t)); + return 0; + } + } + + return -ENOBUFS; +} +#endif /* CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT */ + #if CONFIG_BLE_MESH_GATT_PROXY_CLIENT /** * The following callbacks are used to notify proper information @@ -115,22 +132,6 @@ void bt_mesh_proxy_client_set_filter_status_cb(proxy_client_recv_filter_status_c proxy_client_filter_status_recv_cb = cb; } -#if (CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT) -int bt_mesh_rpr_srv_set_waiting_prov_link(struct bt_mesh_prov_link *link, - bt_mesh_addr_t *addr) -{ - for (size_t i = 0; i < ARRAY_SIZE(waiting_conn_link);i++) { - if (waiting_conn_link[i].link == NULL) { - waiting_conn_link[i].link = link; - memcpy(&waiting_conn_link[i].addr, addr, sizeof(bt_mesh_addr_t)); - return 0; - } - } - - return -ENOBUFS; -} -#endif /* CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT */ - static void filter_status(struct bt_mesh_proxy_server *server, struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) @@ -266,7 +267,9 @@ static void proxy_complete_pdu(struct bt_mesh_proxy_server *server) } else #endif { +#if CONFIG_BLE_MESH_PROVISIONER bt_mesh_provisioner_pb_gatt_recv(server->conn, &server->buf); +#endif } break; #endif @@ -494,6 +497,7 @@ static void proxy_disconnected(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn, if (bt_mesh_prov_node_get_link()->conn == conn) { for (size_t i = 0; i < ARRAY_SIZE(waiting_conn_link); i++) { if (waiting_conn_link[i].link->conn == conn) { + waiting_conn_link[i].link = NULL; memset(&waiting_conn_link[i].addr, 0, sizeof(bt_mesh_addr_t)); break; } @@ -503,7 +507,9 @@ static void proxy_disconnected(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn, } else #endif /* CONFIG_BLE_MESH_RPR_SRV */ { +#if CONFIG_BLE_MESH_PROVISIONER bt_mesh_provisioner_pb_gatt_close(conn, reason); +#endif /* CONFIG_BLE_MESH_PROVISIONER */ } } #endif /* CONFIG_BLE_MESH_PB_GATT && (CONFIG_BLE_MESH_PROVISIONER || CONFIG_BLE_MESH_RPR_SRV) */ @@ -550,7 +556,9 @@ static ssize_t prov_write_ccc(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn) } #endif +#if CONFIG_BLE_MESH_PROVISIONER return bt_mesh_provisioner_pb_gatt_open(conn, addr->val); +#endif } return -ENOMEM; @@ -694,10 +702,12 @@ int bt_mesh_proxy_client_gatt_disable(void) static struct bt_mesh_prov_conn_cb conn_callbacks = { .connected = proxy_connected, .disconnected = proxy_disconnected, -#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT +#if (CONFIG_BLE_MESH_PROVISIONER || CONFIG_BLE_MESH_RPR_SRV) && \ + CONFIG_BLE_MESH_PB_GATT .prov_write_descr = prov_write_ccc, .prov_notify = prov_recv_ntf, -#endif /* CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT */ +#endif /* (CONFIG_BLE_MESH_PROVISIONER || CONFIG_BLE_MESH_RPR_SRV) && \ + CONFIG_BLE_MESH_PB_GATT */ #if CONFIG_BLE_MESH_GATT_PROXY_CLIENT .proxy_write_descr = proxy_write_ccc, .proxy_notify = proxy_recv_ntf, @@ -1125,4 +1135,5 @@ int bt_mesh_proxy_client_deinit(void) #endif /* CONFIG_BLE_MESH_DEINIT */ #endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ - CONFIG_BLE_MESH_GATT_PROXY_CLIENT */ + CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \ + (CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT) */ diff --git a/components/bt/esp_ble_mesh/core/proxy_server.c b/components/bt/esp_ble_mesh/core/proxy_server.c index 532b23d823..633fe7f954 100644 --- a/components/bt/esp_ble_mesh/core/proxy_server.c +++ b/components/bt/esp_ble_mesh/core/proxy_server.c @@ -830,6 +830,13 @@ static void proxy_connected(struct bt_mesh_conn *conn, uint8_t err) conn_count++; + if (gatt_svc == MESH_GATT_PROV && + conn_count > 1) { + BT_WARN("Only one prov connection could exists"); + bt_mesh_gatts_disconnect(conn, 0x13); + return; + } + /* Since we use ADV_OPT_ONE_TIME */ proxy_adv_enabled = false; diff --git a/components/bt/esp_ble_mesh/core/scan.c b/components/bt/esp_ble_mesh/core/scan.c index 72b1ccb300..94ab17aaf3 100644 --- a/components/bt/esp_ble_mesh/core/scan.c +++ b/components/bt/esp_ble_mesh/core/scan.c @@ -119,7 +119,6 @@ int bt_mesh_unprov_dev_info_query(uint8_t uuid[16], uint8_t addr[6], } if (cnt == unprov_dev_info_fifo.pair_num) { - BT_WARN("Didn't find info for %d", query_type); return -1; } @@ -136,6 +135,11 @@ int bt_mesh_unprov_dev_fifo_enqueue(uint8_t uuid[16], const uint8_t addr[6], uin return -EINVAL; } + if (!bt_mesh_unprov_dev_info_query(uuid, addr, NULL, BLE_MESH_STORE_UNPROV_INFO_QUERY_TYPE_UUID| + BLE_MESH_STORE_UNPROV_INFO_QUERY_TYPE_EXISTS)) { + return 0; + } + if (unprov_dev_info_fifo.pair_num == BLE_MESH_STORE_UNPROV_INFO_MAX_NUM) { bt_mesh_unprov_dev_fifo_dequeue(NULL, NULL); } @@ -166,7 +170,8 @@ uint8_t bt_mesh_get_adv_type(void) #if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \ - CONFIG_BLE_MESH_PROXY_SOLIC_PDU_RX + CONFIG_BLE_MESH_PROXY_SOLIC_PDU_RX || \ + (CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT) static bool adv_flags_valid(struct net_buf_simple *buf) { uint8_t flags = 0U; @@ -253,8 +258,10 @@ static void handle_adv_service_data(struct net_buf_simple *buf, } switch (type) { -#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT +#if (CONFIG_BLE_MESH_PROVISIONER || CONFIG_BLE_MESH_RPR_SRV) && \ + CONFIG_BLE_MESH_PB_GATT case BLE_MESH_UUID_MESH_PROV_VAL: +#if CONFIG_BLE_MESH_PROVISIONER if (bt_mesh_is_provisioner_en()) { if (buf->len != PROV_SVC_DATA_LEN) { BT_WARN("Invalid Mesh Prov Service Data length %d", buf->len); @@ -264,16 +271,18 @@ static void handle_adv_service_data(struct net_buf_simple *buf, BT_DBG("Start to handle Mesh Prov Service Data"); bt_mesh_provisioner_prov_adv_recv(buf, addr, rssi); } - +#endif /* CONFIG_BLE_MESH_PROVISIONER */ #if CONFIG_BLE_MESH_RPR_SRV if (bt_mesh_is_provisioned()) { const bt_mesh_addr_t *addr = bt_mesh_get_unprov_dev_addr(); bt_mesh_unprov_dev_fifo_enqueue(buf->data, addr->val, bt_mesh_get_adv_type()); bt_mesh_rpr_srv_unprov_beacon_recv(buf, bt_mesh_get_adv_type(), addr, rssi); } -#endif +#endif /* CONFIG_BLE_MESH_RPR_SRV */ +#endif /* (CONFIG_BLE_MESH_PROVISIONER || CONFIG_BLE_MESH_RPR_SRV) && + CONFIG_BLE_MESH_PB_GATT */ break; -#endif + #if CONFIG_BLE_MESH_GATT_PROXY_CLIENT case BLE_MESH_UUID_MESH_PROXY_VAL: if (buf->len != PROXY_SVC_DATA_LEN_NET_ID && @@ -306,8 +315,9 @@ static void handle_adv_service_data(struct net_buf_simple *buf, } } #endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ - CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \ - CONFIG_BLE_MESH_PROXY_SOLIC_PDU_RX */ + CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \ + CONFIG_BLE_MESH_PROXY_SOLIC_PDU_RX || \ + (CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT) */ #if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN static bool ble_scan_en; @@ -370,8 +380,9 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, uint8_t scan_rsp_len) { #if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ - CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \ - CONFIG_BLE_MESH_PROXY_SOLIC_PDU_RX + CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \ + CONFIG_BLE_MESH_PROXY_SOLIC_PDU_RX || \ + (CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT) uint16_t uuid = 0U; #endif #if (CONFIG_BLE_MESH_RPR_SRV || CONFIG_BLE_MESH_SUPPORT_BLE_SCAN) @@ -445,7 +456,8 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, break; #if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \ - CONFIG_BLE_MESH_PROXY_SOLIC_PDU_RX + CONFIG_BLE_MESH_PROXY_SOLIC_PDU_RX || \ + (CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT) case BLE_MESH_DATA_FLAGS: if (!adv_flags_valid(buf)) { BT_DBG("Adv Flags mismatch, ignore this adv pkt"); diff --git a/components/bt/esp_ble_mesh/core/transport.c b/components/bt/esp_ble_mesh/core/transport.c index 09a9c9cda6..cee0154731 100644 --- a/components/bt/esp_ble_mesh/core/transport.c +++ b/components/bt/esp_ble_mesh/core/transport.c @@ -1561,7 +1561,7 @@ static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx, * eventually be freed up and we'll be able to process * this one. */ - BT_WARN("No free slots for new incoming segmented messages"); + BT_WARN("No free slots for new incoming segmented messages addr: %04x", net_rx->ctx.addr); return -ENOMEM; } diff --git a/components/bt/esp_ble_mesh/lib/ext.c b/components/bt/esp_ble_mesh/lib/ext.c index 1c8dfed3f5..e1561bf53a 100644 --- a/components/bt/esp_ble_mesh/lib/ext.c +++ b/components/bt/esp_ble_mesh/lib/ext.c @@ -1506,6 +1506,11 @@ void bt_mesh_ext_prov_link_set_expect(void *link, uint8_t val) LINK(link)->expect = val; } +uint8_t bt_mesh_ext_prov_link_get_expect(void *link) +{ + return LINK(link)->expect; +} + uint8_t bt_mesh_ext_prov_link_get_pub_key_type(void *link) { return LINK(link)->public_key; @@ -1633,6 +1638,16 @@ uint8_t *bt_mesh_ext_prov_link_get_pb_remote_uuid(void *link) return LINK(link)->pb_remote_uuid; } +void *bt_mesh_ext_prov_link_get_prot_timer(void *link) +{ + return &(LINK(link)->prot_timer); +} + +void *bt_mesh_ext_prov_link_get_with_work(void *work) +{ + return CONTAINER_OF(work, struct bt_mesh_prov_link, prot_timer.work); +} + uint8_t bt_mesh_ext_prov_link_get_pb_remote_timeout(void *link) { return LINK(link)->pb_remote_timeout; @@ -2049,9 +2064,18 @@ int bt_mesh_ext_rpr_cli_pdu_recv(void *link, uint8_t type, struct net_buf_simple } #if CONFIG_BLE_MESH_RPR_CLI -static struct bt_mesh_prov_link rpr_links[CONFIG_BLE_MESH_RPR_CLI_PROV_SAME_TIME]; +struct bt_mesh_prov_link rpr_links[CONFIG_BLE_MESH_RPR_CLI_PROV_SAME_TIME]; #endif /* CONFIG_BLE_MESH_RPR_CLI */ +bool bt_mesh_ext_is_unprov_dev_being_provision(void *uuid) +{ +#if CONFIG_BLE_MESH_RPR_CLI + return is_unprov_dev_being_provision(uuid); +#else + assert(0); +#endif +} + void *bt_mesh_ext_rpr_cli_get_rpr_link(uint8_t index) { #if CONFIG_BLE_MESH_RPR_CLI @@ -2083,15 +2107,13 @@ int bt_mesh_ext_rpr_srv_nppi_pdu_recv(uint8_t type, const uint8_t *data) int bt_mesh_ext_rpr_srv_set_waiting_prov_link(void* link, bt_mesh_addr_t *addr) { -#if (CONFIG_BLE_MESH_GATT_PROXY_CLIENT && \ - CONFIG_BLE_MESH_PB_GATT && \ +#if (CONFIG_BLE_MESH_PB_GATT && \ CONFIG_BLE_MESH_RPR_SRV) return bt_mesh_rpr_srv_set_waiting_prov_link(link, addr); #else assert(0); return 0; -#endif /* (CONFIG_BLE_MESH_GATT_PROXY_CLIENT && \ - CONFIG_BLE_MESH_PB_GATT && \ +#endif /* CONFIG_BLE_MESH_PB_GATT && \ CONFIG_BLE_MESH_RPR_SRV) */ } @@ -4011,6 +4033,7 @@ typedef struct { uint64_t config_ble_mesh_srpl_cli : 1; uint64_t config_ble_mesh_srpl_srv : 1; + uint32_t config_ble_mesh_prov_protocol_timeout; uint16_t config_ble_mesh_record_frag_max_size; uint16_t config_ble_mesh_crpl; uint16_t config_ble_mesh_proxy_solic_rx_crpl; @@ -4176,7 +4199,7 @@ static const bt_mesh_ext_config_t bt_mesh_ext_cfg = { .config_ble_mesh_sar_srv = IS_ENABLED(CONFIG_BLE_MESH_SAR_SRV), .config_ble_mesh_srpl_cli = IS_ENABLED(CONFIG_BLE_MESH_SRPL_CLI), .config_ble_mesh_srpl_srv = IS_ENABLED(CONFIG_BLE_MESH_SRPL_SRV), - + .config_ble_mesh_prov_protocol_timeout = PROTOCOL_TIMEOUT, #if CONFIG_BLE_MESH_CERT_BASED_PROV .config_ble_mesh_record_frag_max_size = CONFIG_BLE_MESH_RECORD_FRAG_MAX_SIZE, #endif /* CONFIG_BLE_MESH_CERT_BASED_PROV */ @@ -4511,6 +4534,7 @@ typedef struct { int (*_bt_mesh_ext_rpr_cli_pdu_send)(void *link, uint8_t type); int (*_bt_mesh_ext_rpr_cli_recv_pub_key_outbound_report)(void *link); int (*_bt_mesh_ext_rpr_cli_pdu_recv)(void *link, uint8_t type, struct net_buf_simple *buf); + bool (*_bt_mesh_ext_is_unprov_dev_being_provision)(void *uuid); void *(*_bt_mesh_ext_rpr_cli_get_rpr_link)(uint8_t index); /* CONFIG_BLE_MESH_RPR_CLI */ @@ -4832,6 +4856,7 @@ static const bt_mesh_ext_funcs_t bt_mesh_ext_func = { ._bt_mesh_ext_rpr_cli_pdu_send = bt_mesh_ext_rpr_cli_pdu_send, ._bt_mesh_ext_rpr_cli_recv_pub_key_outbound_report = bt_mesh_ext_rpr_cli_recv_pub_key_outbound_report, ._bt_mesh_ext_rpr_cli_pdu_recv = bt_mesh_ext_rpr_cli_pdu_recv, + ._bt_mesh_ext_is_unprov_dev_being_provision = bt_mesh_ext_is_unprov_dev_being_provision, ._bt_mesh_ext_rpr_cli_get_rpr_link = bt_mesh_ext_rpr_cli_get_rpr_link, /* CONFIG_BLE_MESH_RPR_CLI */