From 88cc07b6ca1fbac7e3685db42533d5a38ec63643 Mon Sep 17 00:00:00 2001 From: lly Date: Wed, 27 May 2020 09:31:33 +0800 Subject: [PATCH] ble_mesh: stack: Transport rx reset settings update When reset the rx info of transport layer, the rpl list will always cleared, and rpl stored in the nvs will only be erased when erase flag is true and BLE_MESH_SETTINGS is enabled. Compared with the previous solution, it should be more clear. --- .../bt/esp_ble_mesh/api/esp_ble_mesh_defs.h | 4 +-- components/bt/esp_ble_mesh/mesh_core/access.c | 5 ++++ components/bt/esp_ble_mesh/mesh_core/lpn.c | 2 +- components/bt/esp_ble_mesh/mesh_core/main.c | 2 +- .../esp_ble_mesh/mesh_core/provisioner_prov.c | 5 ++++ .../bt/esp_ble_mesh/mesh_core/settings.c | 18 ++++++------- .../bt/esp_ble_mesh/mesh_core/transport.c | 25 ++++--------------- .../bt/esp_ble_mesh/mesh_core/transport.h | 4 +-- 8 files changed, 29 insertions(+), 36 deletions(-) diff --git a/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h b/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h index 79d12e93cb..ff0ee666d9 100644 --- a/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h +++ b/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h @@ -1176,14 +1176,14 @@ typedef union { /** * @brief ESP_BLE_MESH_PROVISIONER_DELETE_NODE_WITH_UUID_COMP_EVT */ - struct ble_mesh_provisioner_delete_node_with_uuid_comp_data_comp_param { + struct ble_mesh_provisioner_delete_node_with_uuid_comp_param { int err_code; /*!< Indicate the result of deleting node with uuid by the Provisioner */ uint8_t uuid[16]; /*!< Node device uuid */ } provisioner_delete_node_with_uuid_comp; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_DELETE_NODE_WITH_UUID_COMP_EVT */ /** * @brief ESP_BLE_MESH_PROVISIONER_DELETE_NODE_WITH_ADDR_COMP_EVT */ - struct ble_mesh_provisioner_delete_node_with_addr_comp_data_comp_param { + struct ble_mesh_provisioner_delete_node_with_addr_comp_param { int err_code; /*!< Indicate the result of deleting node with unicast address by the Provisioner */ uint16_t unicast_addr; /*!< Node unicast address */ } provisioner_delete_node_with_addr_comp; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_DELETE_NODE_WITH_ADDR_COMP_EVT */ diff --git a/components/bt/esp_ble_mesh/mesh_core/access.c b/components/bt/esp_ble_mesh/mesh_core/access.c index c204aad3e1..2f6fe91402 100644 --- a/components/bt/esp_ble_mesh/mesh_core/access.c +++ b/components/bt/esp_ble_mesh/mesh_core/access.c @@ -35,6 +35,11 @@ void bt_mesh_model_foreach(void (*func)(struct bt_mesh_model *mod, { int i, j; + if (dev_comp == NULL) { + BT_ERR("Invalid device composition"); + return; + } + for (i = 0; i < dev_comp->elem_count; i++) { struct bt_mesh_elem *elem = &dev_comp->elem[i]; diff --git a/components/bt/esp_ble_mesh/mesh_core/lpn.c b/components/bt/esp_ble_mesh/mesh_core/lpn.c index 5ee5700460..7ba704573a 100644 --- a/components/bt/esp_ble_mesh/mesh_core/lpn.c +++ b/components/bt/esp_ble_mesh/mesh_core/lpn.c @@ -218,7 +218,7 @@ static void clear_friendship(bool force, bool disable) return; } - bt_mesh_rx_reset(); + bt_mesh_rx_reset(true); k_delayed_work_cancel(&lpn->timer); diff --git a/components/bt/esp_ble_mesh/mesh_core/main.c b/components/bt/esp_ble_mesh/mesh_core/main.c index f755910c40..17d0a21c08 100644 --- a/components/bt/esp_ble_mesh/mesh_core/main.c +++ b/components/bt/esp_ble_mesh/mesh_core/main.c @@ -102,7 +102,7 @@ void bt_mesh_node_reset(void) bt_mesh_cfg_reset(); - bt_mesh_rx_reset(); + bt_mesh_rx_reset(true); bt_mesh_tx_reset(); if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) { 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 18497ae0b3..cdab4b974d 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c @@ -1134,6 +1134,11 @@ int bt_mesh_provisioner_init_prov_info(void) /* If unicast address of primary element of Provisioner has not been set * before, then the following initialization procedure will be used. */ + if (prov == NULL) { + BT_ERR("No provisioning context provided"); + return -EINVAL; + } + if (!BLE_MESH_ADDR_IS_UNICAST(prov->prov_unicast_addr) || !BLE_MESH_ADDR_IS_UNICAST(prov->prov_start_address)) { BT_ERR("Invalid address, own 0x%04x, start 0x%04x", diff --git a/components/bt/esp_ble_mesh/mesh_core/settings.c b/components/bt/esp_ble_mesh/mesh_core/settings.c index 5d01228476..beca5ad363 100644 --- a/components/bt/esp_ble_mesh/mesh_core/settings.c +++ b/components/bt/esp_ble_mesh/mesh_core/settings.c @@ -1355,13 +1355,13 @@ int settings_core_commit(void) #if defined(CONFIG_BLE_MESH_NODE) if (bt_mesh_is_node()) { - BT_INFO("sub[0].net_idx 0x%03x", bt_mesh.sub[0].net_idx); - if (bt_mesh.sub[0].net_idx == BLE_MESH_KEY_UNUSED) { /* Nothing to do since we're not yet provisioned */ return 0; } + BT_INFO("Settings commit, sub[0].net_idx 0x%03x", bt_mesh.sub[0].net_idx); + if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) { bt_mesh_proxy_server_prov_disable(true); } @@ -1388,7 +1388,7 @@ int settings_core_commit(void) return 0; } - BT_INFO("p_sub[0]->net_idx 0x%03x", bt_mesh.p_sub[0]->net_idx); + BT_INFO("Settings commit, p_sub[0]->net_idx 0x%03x", bt_mesh.p_sub[0]->net_idx); for (i = 0; i < ARRAY_SIZE(bt_mesh.p_sub); i++) { sub = bt_mesh.p_sub[i]; @@ -1405,11 +1405,13 @@ int settings_core_commit(void) } #endif /* CONFIG_BLE_MESH_PROVISIONER */ - if (bt_mesh.ivu_duration < BLE_MESH_IVU_MIN_HOURS) { - k_delayed_work_submit(&bt_mesh.ivu_timer, BLE_MESH_IVU_TIMEOUT); - } + if (bt_mesh_is_node() || bt_mesh_is_provisioner()) { + if (bt_mesh.ivu_duration < BLE_MESH_IVU_MIN_HOURS) { + k_delayed_work_submit(&bt_mesh.ivu_timer, BLE_MESH_IVU_TIMEOUT); + } - bt_mesh_model_foreach(commit_model, NULL); + bt_mesh_model_foreach(commit_model, NULL); + } #if defined(CONFIG_BLE_MESH_NODE) if (bt_mesh_is_node()) { @@ -1602,8 +1604,6 @@ static void clear_rpl(void) BT_DBG("%s", __func__); - bt_mesh_rpl_clear(); - buf = bt_mesh_get_core_settings_item("mesh/rpl"); if (!buf) { bt_mesh_erase_core_settings("mesh/rpl"); diff --git a/components/bt/esp_ble_mesh/mesh_core/transport.c b/components/bt/esp_ble_mesh/mesh_core/transport.c index bcb0ac47c5..313decc8f9 100644 --- a/components/bt/esp_ble_mesh/mesh_core/transport.c +++ b/components/bt/esp_ble_mesh/mesh_core/transport.c @@ -1768,7 +1768,7 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx) return err; } -void bt_mesh_rx_reset(void) +void bt_mesh_rx_reset(bool erase) { int i; @@ -1778,10 +1778,10 @@ void bt_mesh_rx_reset(void) seg_rx_reset(&seg_rx[i], true); } - if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { + (void)memset(bt_mesh.rpl, 0, sizeof(bt_mesh.rpl)); + + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS) && erase) { bt_mesh_clear_rpl(); - } else { - (void)memset(bt_mesh.rpl, 0, sizeof(bt_mesh.rpl)); } } @@ -1863,16 +1863,7 @@ void bt_mesh_trans_deinit(bool erase) { int i; - for (i = 0; i < ARRAY_SIZE(seg_rx); i++) { - seg_rx_reset(&seg_rx[i], true); - } - - if (erase && IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { - bt_mesh_clear_rpl(); - } else { - bt_mesh_rpl_clear(); - } - + bt_mesh_rx_reset(erase); bt_mesh_tx_reset(); for (i = 0; i < ARRAY_SIZE(seg_tx); i++) { @@ -1887,12 +1878,6 @@ void bt_mesh_trans_deinit(bool erase) bt_mesh_rx_seg_mutex_free(); } -void bt_mesh_rpl_clear(void) -{ - BT_DBG("%s", __func__); - (void)memset(bt_mesh.rpl, 0, sizeof(bt_mesh.rpl)); -} - void bt_mesh_heartbeat_send(void) { struct bt_mesh_cfg_srv *cfg = bt_mesh_cfg_get(); diff --git a/components/bt/esp_ble_mesh/mesh_core/transport.h b/components/bt/esp_ble_mesh/mesh_core/transport.h index ac80273b0d..043f8f77a1 100644 --- a/components/bt/esp_ble_mesh/mesh_core/transport.h +++ b/components/bt/esp_ble_mesh/mesh_core/transport.h @@ -97,7 +97,7 @@ struct bt_mesh_app_key *bt_mesh_app_key_find(u16_t app_idx); bool bt_mesh_tx_in_progress(void); -void bt_mesh_rx_reset(void); +void bt_mesh_rx_reset(bool erase); void bt_mesh_tx_reset(void); void bt_mesh_rx_reset_single(u16_t src); void bt_mesh_tx_reset_single(u16_t dst); @@ -114,8 +114,6 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx); void bt_mesh_trans_init(void); void bt_mesh_trans_deinit(bool erase); -void bt_mesh_rpl_clear(void); - void bt_mesh_heartbeat_send(void); int bt_mesh_app_key_get(const struct bt_mesh_subnet *subnet, u16_t app_idx,