From fbf0e15694fe5ece291bad45de2c13f5e8051c44 Mon Sep 17 00:00:00 2001 From: Linyan Liu Date: Wed, 27 Aug 2025 16:11:56 +0800 Subject: [PATCH] feat(ble_mesh): Miscellaneous update for BLE Mesh --- components/bt/CMakeLists.txt | 13 +- components/bt/esp_ble_mesh/core/access.c | 70 ++++++- components/bt/esp_ble_mesh/core/adv.c | 86 +++----- components/bt/esp_ble_mesh/core/adv.h | 4 - components/bt/esp_ble_mesh/core/adv_common.c | 196 +++++++++--------- components/bt/esp_ble_mesh/core/adv_common.h | 54 +++-- components/bt/esp_ble_mesh/core/ble_adv.c | 33 +-- .../core/bluedroid_host/adapter.c | 8 +- components/bt/esp_ble_mesh/core/ext_adv.c | 129 +++++------- components/bt/esp_ble_mesh/core/ext_adv.h | 7 - components/bt/esp_ble_mesh/core/friend.c | 2 +- .../esp_ble_mesh/core/include/mesh/adapter.h | 10 +- components/bt/esp_ble_mesh/core/net.c | 14 +- .../esp_ble_mesh/core/nimble_host/adapter.c | 25 ++- .../bt/esp_ble_mesh/core/proxy_server.c | 10 + components/bt/esp_ble_mesh/core/scan.c | 40 ++-- components/bt/esp_ble_mesh/core/transport.c | 83 +------- .../bt/esp_ble_mesh/core/transport.enh.c | 68 ------ .../models/client/client_common.c | 51 ++--- 19 files changed, 392 insertions(+), 511 deletions(-) diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index d6d30e650ff..77f4919d025 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -562,7 +562,6 @@ if(CONFIG_BT_ENABLED) "esp_ble_mesh/core/storage/settings.c" "esp_ble_mesh/core/access.c" "esp_ble_mesh/core/adv_common.c" - "esp_ble_mesh/core/ble_adv.c" "esp_ble_mesh/core/beacon.c" "esp_ble_mesh/core/cfg_cli.c" "esp_ble_mesh/core/cfg_srv.c" @@ -619,6 +618,7 @@ if(CONFIG_BT_ENABLED) "esp_ble_mesh/common/tinycrypt/src/sha256.c" "esp_ble_mesh/common/tinycrypt/src/utils.c") endif() + if(CONFIG_BLE_MESH_V11_SUPPORT) list(APPEND include_dirs ${ble_mesh_v11_include_dirs}) @@ -655,24 +655,27 @@ if(CONFIG_BT_ENABLED) "esp_ble_mesh/v1.1/dfu/dfu_slot.c" "esp_ble_mesh/v1.1/dfu/dfu_metadata.c" "esp_ble_mesh/lib/ext.c") + if(CONFIG_BLE_MESH_SAR_ENHANCEMENT) list(APPEND srcs "esp_ble_mesh/core/transport.enh.c") else() list(APPEND srcs "esp_ble_mesh/core/transport.c") endif() else() - list(APPEND srcs - "esp_ble_mesh/core/transport.c") + list(APPEND srcs "esp_ble_mesh/core/transport.c") endif() + if(CONFIG_BLE_MESH_SUPPORT_MULTI_ADV) list(APPEND srcs "esp_ble_mesh/core/ext_adv.c") else() list(APPEND srcs "esp_ble_mesh/core/adv.c") endif() + + if(CONFIG_BLE_MESH_SUPPORT_BLE_ADV) + list(APPEND srcs "esp_ble_mesh/core/ble_adv.c") + endif() endif() - - if(CONFIG_BT_LE_CONTROLLER_NPL_OS_PORTING_SUPPORT) list(APPEND srcs "porting/npl/freertos/src/npl_os_freertos.c" diff --git a/components/bt/esp_ble_mesh/core/access.c b/components/bt/esp_ble_mesh/core/access.c index 73363c2f993..5aad6a0a848 100644 --- a/components/bt/esp_ble_mesh/core/access.c +++ b/components/bt/esp_ble_mesh/core/access.c @@ -117,7 +117,7 @@ static int32_t next_period(struct bt_mesh_model *mod) if (!pub) { BT_ERR("Model has no publication support"); - return -ENOTSUP; + return 0; } period = bt_mesh_model_pub_period_get(mod); @@ -1404,3 +1404,71 @@ struct bt_mesh_app_key *bt_mesh_rx_appkey_get(size_t index) return key; } + +struct bt_mesh_app_key *bt_mesh_app_key_get(uint16_t app_idx) +{ + if (bt_mesh_is_provisioned()) { +#if CONFIG_BLE_MESH_NODE + if (!IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV)) { + for (int i = 0; i < ARRAY_SIZE(bt_mesh.app_keys); i++) { + if (bt_mesh.app_keys[i].net_idx != BLE_MESH_KEY_UNUSED && + bt_mesh.app_keys[i].app_idx == app_idx) { + return &bt_mesh.app_keys[i]; + } + } + } else { + return bt_mesh_fast_prov_app_key_find(app_idx); + } +#endif + } else if (bt_mesh_is_provisioner_en()) { +#if CONFIG_BLE_MESH_PROVISIONER + for (int i = 0; i < ARRAY_SIZE(bt_mesh.p_app_keys); i++) { + if (bt_mesh.p_app_keys[i] && + bt_mesh.p_app_keys[i]->net_idx != BLE_MESH_KEY_UNUSED && + bt_mesh.p_app_keys[i]->app_idx == app_idx) { + return bt_mesh.p_app_keys[i]; + } + } +#endif + } + + return NULL; +} + +int bt_mesh_upper_key_get(const struct bt_mesh_subnet *subnet, uint16_t app_idx, + const uint8_t **key, uint8_t *aid, uint16_t dst) +{ + struct bt_mesh_app_key *app_key = NULL; + + if (app_idx == BLE_MESH_KEY_DEV) { + *key = bt_mesh_dev_key_get(dst); + if (!*key) { + BT_ERR("DevKey of 0x%04x not found", dst); + return -EINVAL; + } + + *aid = 0U; + return 0; + } + + if (!subnet) { + BT_ERR("Invalid subnet"); + return -EINVAL; + } + + app_key = bt_mesh_app_key_get(app_idx); + if (!app_key) { + BT_ERR("AppKey 0x%04x not found", app_idx); + return -ENOENT; + } + + if (subnet->kr_phase == BLE_MESH_KR_PHASE_2 && app_key->updated) { + *key = app_key->keys[1].val; + *aid = app_key->keys[1].id; + } else { + *key = app_key->keys[0].val; + *aid = app_key->keys[0].id; + } + + return 0; +} diff --git a/components/bt/esp_ble_mesh/core/adv.c b/components/bt/esp_ble_mesh/core/adv.c index fa4249c1875..d9096caa136 100644 --- a/components/bt/esp_ble_mesh/core/adv.c +++ b/components/bt/esp_ble_mesh/core/adv.c @@ -37,24 +37,7 @@ static QueueSetHandle_t mesh_queue_set; #endif /* CONFIG_BLE_MESH_RELAY_ADV_BUF */ -static inline void adv_send_start(uint16_t duration, int err, - const struct bt_mesh_send_cb *cb, - void *cb_data) -{ - if (cb && cb->start) { - cb->start(duration, err, cb_data); - } -} - -static inline void adv_send_end(int err, const struct bt_mesh_send_cb *cb, - void *cb_data) -{ - if (cb && cb->end) { - cb->end(err, cb_data); - } -} - -static inline int adv_send(struct net_buf *buf) +static int adv_send(struct net_buf *buf) { const struct bt_mesh_send_cb *cb = BLE_MESH_ADV(buf)->cb; void *cb_data = BLE_MESH_ADV(buf)->cb_data; @@ -201,17 +184,15 @@ static inline int adv_send(struct net_buf *buf) BT_DBG("Advertising started. Sleeping %u ms", duration); #if CONFIG_BLE_MESH_USE_BLE_50 - if (!ble_mesh_adv_task_wait(UINT32_MAX, K_FOREVER, NULL)) { + if (!bt_mesh_adv_task_wait(UINT32_MAX, K_FOREVER, NULL)) { BT_WARN("Advertising didn't finish on time"); bt_le_ext_adv_stop(CONFIG_BLE_MESH_ADV_INST_ID); } #else /* CONFIG_BLE_MESH_USE_BLE_50 */ - ble_mesh_adv_task_wait(K_MSEC(duration)); -#endif /* CONFIG_BLE_MESH_USE_BLE_50 */ + bt_mesh_adv_task_wait(K_MSEC(duration)); -#if !CONFIG_BLE_MESH_USE_BLE_50 err = bt_le_adv_stop(); -#endif +#endif /* CONFIG_BLE_MESH_USE_BLE_50 */ adv_send_end(err, cb, cb_data); if (err) { @@ -223,15 +204,34 @@ static inline int adv_send(struct net_buf *buf) return 0; } +#if CONFIG_BLE_MESH_RELAY_ADV_BUF +static QueueHandle_t relay_adv_handle_get(void) +{ + struct bt_mesh_adv_type_manager *adv_type = NULL; + + adv_type = bt_mesh_adv_types_mgmt_get(BLE_MESH_ADV_RELAY_DATA); + + if (adv_type->adv_q == NULL) { + return NULL; + } + + return adv_type->adv_q->q.handle; +} +#endif /* CONFIG_BLE_MESH_RELAY_ADV_BUF */ + static void adv_thread(void *p) { #if CONFIG_BLE_MESH_RELAY_ADV_BUF + QueueHandle_t relay_adv_handle = NULL; QueueSetMemberHandle_t handle = NULL; - QueueHandle_t relay_adv_handle = - bt_mesh_adv_types_mgnt_get(BLE_MESH_ADV_RELAY_DATA)->adv_q->q.handle; #endif - bt_mesh_msg_t msg = {0}; struct net_buf **buf = NULL; + bt_mesh_msg_t msg = {0}; + +#if CONFIG_BLE_MESH_RELAY_ADV_BUF + relay_adv_handle = relay_adv_handle_get(); + assert(relay_adv_handle); +#endif /* CONFIG_BLE_MESH_RELAY_ADV_BUF */ buf = (struct net_buf **)(&msg.arg); @@ -328,28 +328,6 @@ static void adv_thread(void *p) } } -void bt_mesh_adv_send(struct net_buf *buf, uint8_t xmit, - const struct bt_mesh_send_cb *cb, - void *cb_data) -{ - bt_mesh_msg_t msg = { - .relay = false, - }; - - BT_DBG("type 0x%02x len %u: %s", BLE_MESH_ADV(buf)->type, buf->len, - bt_hex(buf->data, buf->len)); - - BLE_MESH_ADV(buf)->cb = cb; - BLE_MESH_ADV(buf)->cb_data = cb_data; - bt_mesh_atomic_set(&BLE_MESH_ADV_BUSY(buf), 1); - BLE_MESH_ADV(buf)->xmit = xmit; - - bt_mesh_adv_buf_ref_debug(__func__, buf, 3U, BLE_MESH_BUF_REF_SMALL); - - msg.arg = (void *)net_buf_ref(buf); - bt_mesh_task_post(&msg, portMAX_DELAY, false); -} - void bt_mesh_adv_update(void) { bt_mesh_msg_t msg = { @@ -375,11 +353,11 @@ void bt_mesh_adv_init(void) bt_mesh_ble_adv_init(); #endif -#if CONFIG_BLE_MESH_RELAY_ADV_BUF && !CONFIG_BLE_MESH_SUPPORT_MULTI_ADV - QueueHandle_t relay_adv_handle = - bt_mesh_adv_types_mgnt_get(BLE_MESH_ADV_RELAY_DATA)->adv_q->q.handle; +#if CONFIG_BLE_MESH_RELAY_ADV_BUF + QueueHandle_t relay_adv_handle = relay_adv_handle_get(); + assert(relay_adv_handle); mesh_queue_set = xQueueCreateSet(BLE_MESH_QUEUE_SET_SIZE); - __ASSERT(mesh_queue_set, "Failed to create queue set"); + assert(mesh_queue_set); xQueueAddToSet(adv_queue->q.handle, mesh_queue_set); xQueueAddToSet(relay_adv_handle, mesh_queue_set); #endif @@ -394,8 +372,8 @@ void bt_mesh_adv_deinit(void) bt_mesh_adv_task_deinit(); #if CONFIG_BLE_MESH_RELAY_ADV_BUF - QueueHandle_t relay_adv_handle = - bt_mesh_adv_types_mgnt_get(BLE_MESH_ADV_RELAY_DATA)->adv_q->q.handle; + QueueHandle_t relay_adv_handle = relay_adv_handle_get(); + assert(relay_adv_handle); xQueueRemoveFromSet(adv_queue->q.handle, mesh_queue_set); xQueueRemoveFromSet(relay_adv_handle, mesh_queue_set); diff --git a/components/bt/esp_ble_mesh/core/adv.h b/components/bt/esp_ble_mesh/core/adv.h index 5770364a2e3..a2c8dd03301 100644 --- a/components/bt/esp_ble_mesh/core/adv.h +++ b/components/bt/esp_ble_mesh/core/adv.h @@ -23,10 +23,6 @@ extern "C" { #endif -void bt_mesh_adv_send(struct net_buf *buf, uint8_t xmit, - const struct bt_mesh_send_cb *cb, - void *cb_data); - void bt_mesh_adv_update(void); void bt_mesh_adv_init(void); diff --git a/components/bt/esp_ble_mesh/core/adv_common.c b/components/bt/esp_ble_mesh/core/adv_common.c index 96b4ac773ae..ec1e3b68dbc 100644 --- a/components/bt/esp_ble_mesh/core/adv_common.c +++ b/components/bt/esp_ble_mesh/core/adv_common.c @@ -76,15 +76,7 @@ static inline void init_adv_with_defaults(struct bt_mesh_adv *adv, NET_BUF_POOL_FIXED_DEFINE(friend_buf_pool, FRIEND_BUF_COUNT, BLE_MESH_ADV_DATA_SIZE, NULL); -bt_mesh_friend_adv_t frnd_adv_pool[FRIEND_BUF_COUNT]; - -struct bt_mesh_adv *bt_mesh_frnd_adv_buf_get(int idx, enum bt_mesh_adv_type type) -{ - memset(&frnd_adv_pool[idx].adv, 0, sizeof(struct bt_mesh_adv)); - init_adv_with_defaults(&frnd_adv_pool[idx].adv, type); - frnd_adv_pool[idx].app_idx = BLE_MESH_KEY_UNUSED; - return &frnd_adv_pool[idx].adv; -} +static bt_mesh_friend_adv_t frnd_adv_pool[FRIEND_BUF_COUNT]; #endif struct bt_mesh_adv_task { @@ -102,7 +94,7 @@ static struct bt_mesh_adv_type_manager adv_types[BLE_MESH_ADV_TYPES_NUM]; #if CONFIG_BLE_MESH_USE_BLE_50 static struct bt_mesh_adv_inst adv_insts[] = { - [BLE_MESH_ADV_INS] = { + [BLE_MESH_ADV_INST] = { .id = CONFIG_BLE_MESH_ADV_INST_ID, #if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV .busy = false, @@ -111,19 +103,19 @@ static struct bt_mesh_adv_inst adv_insts[] = { #if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV #if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_SERVER - [BLE_MESH_ADV_PROXY_INS] = { + [BLE_MESH_ADV_PROXY_INST] = { .id = CONFIG_BLE_MESH_PROXY_ADV_INST_ID, .busy = false, }, #endif #if CONFIG_BLE_MESH_SEPARATE_RELAY_ADV_INSTANCE - [BLE_MESH_RELAY_ADV_INS] = { + [BLE_MESH_RELAY_ADV_INST] = { .id = CONFIG_BLE_MESH_RELAY_ADV_INST_ID, .busy = false, }, #endif #if CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE - [BLE_MESH_BLE_ADV_INS] = { + [BLE_MESH_BLE_ADV_INST] = { .id = CONFIG_BLE_MESH_BLE_ADV_INST_ID, .busy = false, }, @@ -154,7 +146,7 @@ bool bt_mesh_is_adv_inst_used(uint8_t adv_inst_id) int bt_mesh_adv_inst_init(enum bt_mesh_adv_inst_type inst_type, uint8_t inst_id) { - if (inst_type >= BLE_MESH_ADV_INS_TYPES_NUM) { + if (inst_type >= BLE_MESH_ADV_INST_TYPES_NUM) { BT_ERR("Invalid instance type %d", inst_type); return -EINVAL; } @@ -170,7 +162,7 @@ int bt_mesh_adv_inst_init(enum bt_mesh_adv_inst_type inst_type, uint8_t inst_id) int bt_mesh_adv_inst_deinit(enum bt_mesh_adv_inst_type inst_type) { - if (inst_type >= BLE_MESH_ADV_INS_TYPES_NUM) { + if (inst_type >= BLE_MESH_ADV_INST_TYPES_NUM) { BT_ERR("Invalid instance type %d", inst_type); return -EINVAL; } @@ -186,7 +178,7 @@ int bt_mesh_adv_inst_deinit(enum bt_mesh_adv_inst_type inst_type) #endif /* CONFIG_BLE_MESH_USE_BLE_50 */ -struct bt_mesh_adv *adv_alloc(int id, enum bt_mesh_adv_type type) +static struct bt_mesh_adv *adv_alloc(int id, enum bt_mesh_adv_type type) { init_adv_with_defaults(&adv_pool[id], type); return &adv_pool[id]; @@ -268,10 +260,10 @@ void bt_mesh_adv_buf_ref_debug(const char *func, struct net_buf *buf, } #if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV -void bt_mesh_adv_inst_supported_adv_type_add(enum bt_mesh_adv_inst_type inst_type, - enum bt_mesh_adv_type adv_type) +void bt_mesh_adv_inst_type_add(enum bt_mesh_adv_inst_type inst_type, + enum bt_mesh_adv_type adv_type) { - if (inst_type >= BLE_MESH_ADV_INS_TYPES_NUM) { + if (inst_type >= BLE_MESH_ADV_INST_TYPES_NUM) { BT_ERR("Invalid instance type %d", inst_type); return; } @@ -284,10 +276,10 @@ void bt_mesh_adv_inst_supported_adv_type_add(enum bt_mesh_adv_inst_type inst_typ adv_insts[inst_type].spt_mask |= BIT(adv_type); } -void bt_mesh_adv_inst_supported_adv_type_rm(enum bt_mesh_adv_inst_type inst_type, - enum bt_mesh_adv_type adv_type) +void bt_mesh_adv_inst_type_rm(enum bt_mesh_adv_inst_type inst_type, + enum bt_mesh_adv_type adv_type) { - if (inst_type >= BLE_MESH_ADV_INS_TYPES_NUM) { + if (inst_type >= BLE_MESH_ADV_INST_TYPES_NUM) { BT_ERR("Invalid instance type %d", inst_type); return; } @@ -303,7 +295,7 @@ void bt_mesh_adv_inst_supported_adv_type_rm(enum bt_mesh_adv_inst_type inst_type void bt_mesh_adv_inst_supported_adv_type_clear(enum bt_mesh_adv_inst_type inst_type, enum bt_mesh_adv_type adv_type) { - if (inst_type >= BLE_MESH_ADV_INS_TYPES_NUM) { + if (inst_type >= BLE_MESH_ADV_INST_TYPES_NUM) { BT_ERR("Invalid instance type %d", inst_type); return; } @@ -379,18 +371,18 @@ void bt_mesh_adv_type_deinit(enum bt_mesh_adv_type adv_type) } #if CONFIG_BLE_MESH_USE_BLE_50 -int ble_mesh_adv_task_wakeup(uint32_t evt) +int bt_mesh_adv_task_wakeup(uint32_t evt) { xTaskNotify(adv_task.handle, evt, eSetBits); return 0; } -bool ble_mesh_adv_task_wait(uint32_t wait_bits, uint32_t timeout, uint32_t *notify) +bool bt_mesh_adv_task_wait(uint32_t wait_bits, uint32_t timeout, uint32_t *notify) { return (xTaskNotifyWait(wait_bits, UINT32_MAX, notify, K_WAIT(timeout)) == pdTRUE); } #else /* CONFIG_BLE_MESH_USE_BLE_50 */ -bool ble_mesh_adv_task_wait(uint32_t timeout) +bool bt_mesh_adv_task_wait(uint32_t timeout) { vTaskDelay(K_WAIT(timeout)); return true; @@ -408,25 +400,29 @@ uint16_t bt_mesh_pdu_duration(uint8_t xmit) return duration; } -struct net_buf *bt_mesh_adv_create_from_pool(enum bt_mesh_adv_type type, - int32_t timeout) +struct net_buf *bt_mesh_adv_create_from_pool(enum bt_mesh_adv_type type, int32_t timeout) { struct bt_mesh_adv *adv = NULL; struct net_buf *buf = NULL; - struct net_buf_pool *pool = adv_types[type].pool; if (bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_SUSPENDED)) { BT_WARN("Refusing to allocate buffer while suspended"); return NULL; } - if (!pool || !adv_types[type].pool_allocator) { + if (type >= BLE_MESH_ADV_TYPES_NUM) { + BT_ERR("%s, Invalid adv type %u", __func__, type); + return NULL; + } + + if (adv_types[type].pool == NULL || adv_types[type].pool_allocator == NULL) { BT_ERR("Uninitialized adv type %d", type); return NULL; } bt_mesh_r_mutex_lock(&adv_buf_alloc_lock); - buf = net_buf_alloc(pool, timeout); + + buf = net_buf_alloc(adv_types[type].pool, timeout); if (!buf) { bt_mesh_r_mutex_unlock(&adv_buf_alloc_lock); BT_WARN("Buf alloc failed"); @@ -434,7 +430,8 @@ struct net_buf *bt_mesh_adv_create_from_pool(enum bt_mesh_adv_type type, } BT_DBG("pool %p, buf_count %d, uinit_count %d, ref %d", - buf->pool, pool->buf_count, pool->uninit_count, buf->ref); + adv_types[type].pool, adv_types[type].pool->buf_count, + adv_types[type].pool->uninit_count, buf->ref); adv = adv_types[type].pool_allocator(net_buf_id(buf), type); BLE_MESH_ADV(buf) = adv; @@ -460,10 +457,9 @@ void bt_mesh_unref_buf_from_pool(struct net_buf_pool *pool) void bt_mesh_unref_buf(bt_mesh_msg_t *msg) { - struct net_buf *buf = NULL; + struct net_buf *buf = msg->arg; - if (msg->arg) { - buf = (struct net_buf *)msg->arg; + if (buf) { bt_mesh_atomic_set(&BLE_MESH_ADV_BUSY(buf), 0); if (buf->ref > 1U) { buf->ref = 1U; @@ -502,12 +498,13 @@ void bt_mesh_generic_adv_send(struct net_buf *buf, uint8_t xmit, } #endif - assert(adv_types[BLE_MESH_ADV(buf)->type].adv_q && adv_types[BLE_MESH_ADV(buf)->type].adv_q->send); + assert(adv_types[BLE_MESH_ADV(buf)->type].adv_q); + assert(adv_types[BLE_MESH_ADV(buf)->type].adv_q->send); adv_types[BLE_MESH_ADV(buf)->type].adv_q->send(&msg, portMAX_DELAY, front); #if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV - ble_mesh_adv_task_wakeup(ADV_TASK_PKT_SEND_EVT); + bt_mesh_adv_task_wakeup(ADV_TASK_PKT_SEND_EVT); #endif } @@ -558,12 +555,7 @@ static struct bt_mesh_adv *relay_adv_alloc(int id, enum bt_mesh_adv_type type) return &relay_adv_pool[id]; } -struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, int32_t timeout) -{ - return bt_mesh_adv_create_from_pool(type, timeout); -} - -static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout, bool front) +static void bt_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout, bool front) { bt_mesh_msg_t old_msg = {0}; @@ -609,7 +601,7 @@ uint16_t bt_mesh_get_stored_relay_count(void) } static ALWAYS_INLINE -uint16_t ble_mesh_relay_adv_buf_count_get(void) +uint16_t bt_mesh_relay_adv_buf_count_get(void) { uint16_t relay_adv_count = 2 + CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT; @@ -625,8 +617,8 @@ uint16_t ble_mesh_relay_adv_buf_count_get(void) void bt_mesh_relay_adv_init(void) { - bt_mesh_adv_queue_init(&relay_adv_queue, ble_mesh_relay_adv_buf_count_get(), - ble_mesh_relay_task_post); + bt_mesh_adv_queue_init(&relay_adv_queue, bt_mesh_relay_adv_buf_count_get(), + bt_mesh_relay_task_post); bt_mesh_adv_type_init(BLE_MESH_ADV_RELAY_DATA, &relay_adv_queue, &relay_adv_buf_pool, &relay_adv_alloc); #if CONFIG_BLE_MESH_EXT_ADV @@ -634,29 +626,29 @@ void bt_mesh_relay_adv_init(void) &ext_adv_buf_pool, &ext_relay_adv_alloc); #if CONFIG_BLE_MESH_LONG_PACKET && CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT bt_mesh_adv_type_init(BLE_MESH_ADV_EXT_LONG_RELAY_DATA, &relay_adv_queue, - &ext_long_relay_adv_buf_pool, ext_long_relay_adv_alloc); -#endif /* CONFIG_BLE_MESH_LONG_PACKET */ + &ext_long_relay_adv_buf_pool, ext_long_relay_adv_alloc); +#endif /* CONFIG_BLE_MESH_LONG_PACKET && CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT */ #endif /* CONFIG_BLE_MESH_EXT_ADV */ #if CONFIG_BLE_MESH_USE_BLE_50 #if CONFIG_BLE_MESH_SEPARATE_RELAY_ADV_INSTANCE - bt_mesh_adv_inst_init(BLE_MESH_RELAY_ADV_INS, + bt_mesh_adv_inst_init(BLE_MESH_RELAY_ADV_INST, CONFIG_BLE_MESH_RELAY_ADV_INST_ID); - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_RELAY_ADV_INS, BLE_MESH_ADV_RELAY_DATA); + bt_mesh_adv_inst_type_add(BLE_MESH_RELAY_ADV_INST, BLE_MESH_ADV_RELAY_DATA); #if CONFIG_BLE_MESH_EXT_ADV - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_RELAY_ADV_INS, BLE_MESH_ADV_EXT_RELAY_DATA); + bt_mesh_adv_inst_type_add(BLE_MESH_RELAY_ADV_INST, BLE_MESH_ADV_EXT_RELAY_DATA); #if CONFIG_BLE_MESH_LONG_PACKET - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_RELAY_ADV_INS, BLE_MESH_ADV_EXT_LONG_RELAY_DATA); + bt_mesh_adv_inst_type_add(BLE_MESH_RELAY_ADV_INST, BLE_MESH_ADV_EXT_LONG_RELAY_DATA); #endif /* CONFIG_BLE_MESH_LONG_PACKET */ #endif /* CONFIG_BLE_MESH_EXT_ADV */ -#else +#else /* CONFIG_BLE_MESH_SEPARATE_RELAY_ADV_INSTANCE */ #if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_RELAY_DATA); + bt_mesh_adv_inst_type_add(BLE_MESH_ADV_INST, BLE_MESH_ADV_RELAY_DATA); #if CONFIG_BLE_MESH_EXT_ADV - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_RELAY_DATA); + bt_mesh_adv_inst_type_add(BLE_MESH_ADV_INST, BLE_MESH_ADV_EXT_RELAY_DATA); #if CONFIG_BLE_MESH_LONG_PACKET - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_LONG_RELAY_DATA); + bt_mesh_adv_inst_type_add(BLE_MESH_ADV_INST, BLE_MESH_ADV_EXT_LONG_RELAY_DATA); #endif /* CONFIG_BLE_MESH_LONG_PACKET */ #endif /* CONFIG_BLE_MESH_EXT_ADV */ #endif /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */ @@ -673,25 +665,25 @@ void bt_mesh_relay_adv_deinit(void) #if CONFIG_BLE_MESH_LONG_PACKET bt_mesh_adv_type_deinit(BLE_MESH_ADV_EXT_LONG_RELAY_DATA); #endif /* CONFIG_BLE_MESH_LONG_PACKET */ -#endif +#endif /* CONFIG_BLE_MESH_EXT_ADV */ #if CONFIG_BLE_MESH_USE_BLE_50 #if CONFIG_BLE_MESH_SEPARATE_RELAY_ADV_INSTANCE - bt_mesh_adv_inst_supported_adv_type_rm(BLE_MESH_RELAY_ADV_INS, BLE_MESH_ADV_RELAY_DATA); + bt_mesh_adv_inst_type_rm(BLE_MESH_RELAY_ADV_INST, BLE_MESH_ADV_RELAY_DATA); #if CONFIG_BLE_MESH_EXT_ADV - bt_mesh_adv_inst_supported_adv_type_rm(BLE_MESH_RELAY_ADV_INS, BLE_MESH_ADV_EXT_RELAY_DATA); + bt_mesh_adv_inst_type_rm(BLE_MESH_RELAY_ADV_INST, BLE_MESH_ADV_EXT_RELAY_DATA); #if CONFIG_BLE_MESH_LONG_PACKET - bt_mesh_adv_inst_supported_adv_type_rm(BLE_MESH_RELAY_ADV_INS, BLE_MESH_ADV_EXT_LONG_RELAY_DATA); + bt_mesh_adv_inst_type_rm(BLE_MESH_RELAY_ADV_INST, BLE_MESH_ADV_EXT_LONG_RELAY_DATA); #endif /* CONFIG_BLE_MESH_LONG_PACKET */ #endif /* CONFIG_BLE_MESH_EXT_ADV */ - bt_mesh_adv_inst_deinit(BLE_MESH_RELAY_ADV_INS); -#else + bt_mesh_adv_inst_deinit(BLE_MESH_RELAY_ADV_INST); +#else /* CONFIG_BLE_MESH_SEPARATE_RELAY_ADV_INSTANCE */ #if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV - bt_mesh_adv_inst_supported_adv_type_rm(BLE_MESH_ADV_INS, BLE_MESH_ADV_RELAY_DATA); + bt_mesh_adv_inst_type_rm(BLE_MESH_ADV_INST, BLE_MESH_ADV_RELAY_DATA); #if CONFIG_BLE_MESH_EXT_ADV - bt_mesh_adv_inst_supported_adv_type_rm(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_RELAY_DATA); + bt_mesh_adv_inst_type_rm(BLE_MESH_ADV_INST, BLE_MESH_ADV_EXT_RELAY_DATA); #if CONFIG_BLE_MESH_LONG_PACKET - bt_mesh_adv_inst_supported_adv_type_rm(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_LONG_RELAY_DATA); + bt_mesh_adv_inst_type_rm(BLE_MESH_ADV_INST, BLE_MESH_ADV_EXT_LONG_RELAY_DATA); #endif /* CONFIG_BLE_MESH_LONG_PACKET */ #endif /* CONFIG_BLE_MESH_EXT_ADV */ #endif /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */ @@ -704,16 +696,19 @@ void bt_mesh_relay_adv_deinit(void) #endif /* CONFIG_BLE_MESH_RELAY_ADV_BUF */ #if CONFIG_BLE_MESH_FRIEND -struct net_buf_pool *bt_mesh_frnd_adv_pool_get(void) +static struct bt_mesh_adv *bt_mesh_frnd_adv_buf_get(int idx, enum bt_mesh_adv_type type) { - return &friend_buf_pool; + memset(&frnd_adv_pool[idx].adv, 0, sizeof(struct bt_mesh_adv)); + init_adv_with_defaults(&frnd_adv_pool[idx].adv, type); + frnd_adv_pool[idx].app_idx = BLE_MESH_KEY_UNUSED; + return &frnd_adv_pool[idx].adv; } void bt_mesh_frnd_adv_init(void) { bt_mesh_adv_type_init(BLE_MESH_ADV_FRIEND, &adv_queue, &friend_buf_pool, bt_mesh_frnd_adv_buf_get); #if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_FRIEND); + bt_mesh_adv_inst_type_add(BLE_MESH_ADV_INST, BLE_MESH_ADV_FRIEND); #endif /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */ } @@ -722,7 +717,7 @@ void bt_mesh_frnd_adv_deinit(void) bt_mesh_adv_type_deinit(BLE_MESH_ADV_FRIEND); #if CONFIG_BLE_MESH_FRIEND && CONFIG_BLE_MESH_SUPPORT_MULTI_ADV - bt_mesh_adv_inst_supported_adv_type_rm(BLE_MESH_ADV_INS, BLE_MESH_ADV_FRIEND); + bt_mesh_adv_inst_type_rm(BLE_MESH_ADV_INST, BLE_MESH_ADV_FRIEND); #endif /* CONFIG_BLE_MESH_FRIEND */ bt_mesh_unref_buf_from_pool(&friend_buf_pool); @@ -731,7 +726,7 @@ void bt_mesh_frnd_adv_deinit(void) #endif /* CONFIG_BLE_MESH_FRIEND */ static ALWAYS_INLINE -uint16_t ble_mesh_adv_buf_count_get(void) +uint16_t bt_mesh_adv_buf_count_get(void) { uint16_t adv_count = 2 + CONFIG_BLE_MESH_ADV_BUF_COUNT; @@ -739,15 +734,15 @@ uint16_t ble_mesh_adv_buf_count_get(void) adv_count += CONFIG_BLE_MESH_EXT_ADV_BUF_COUNT; #if !CONFIG_BLE_MESH_RELAY_ADV_BUF && CONFIG_BLE_MESH_RELAY adv_count += CONFIG_BLE_MESH_EXT_RELAY_ADV_BUF_COUNT; -#endif -#endif +#endif /* !CONFIG_BLE_MESH_RELAY_ADV_BUF && CONFIG_BLE_MESH_RELAY */ +#endif /* CONFIG_BLE_MESH_EXT_ADV */ #if CONFIG_BLE_MESH_LONG_PACKET adv_count += CONFIG_BLE_MESH_LONG_PACKET_ADV_BUF_COUNT; #if !CONFIG_BLE_MESH_RELAY_ADV_BUF && CONFIG_BLE_MESH_RELAY adv_count += CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT; -#endif -#endif +#endif /* !CONFIG_BLE_MESH_RELAY_ADV_BUF && CONFIG_BLE_MESH_RELAY */ +#endif /* CONFIG_BLE_MESH_LONG_PACKET */ #if (CONFIG_BLE_MESH_SUPPORT_BLE_ADV && \ !(CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE)) @@ -768,24 +763,29 @@ void bt_mesh_adv_task_init(void adv_thread(void *p)) (CONFIG_SPIRAM_CACHE_WORKAROUND || !CONFIG_IDF_TARGET_ESP32) && \ CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY) adv_task.task = heap_caps_calloc(1, sizeof(StaticTask_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); - __ASSERT(adv_task.task, "Failed to create adv thread task"); - adv_task.stack = heap_caps_calloc_prefer(1, BLE_MESH_ADV_TASK_STACK_SIZE * sizeof(StackType_t), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); - __ASSERT(adv_task.stack, "Failed to create adv thread stack"); - adv_task.handle = xTaskCreateStaticPinnedToCore(adv_thread, BLE_MESH_ADV_TASK_NAME, BLE_MESH_ADV_TASK_STACK_SIZE, NULL, - BLE_MESH_ADV_TASK_PRIO, adv_task.stack, adv_task.task, BLE_MESH_ADV_TASK_CORE); - __ASSERT(adv_task.handle, "Failed to create static adv thread"); + assert(adv_task.task); + + adv_task.stack = heap_caps_calloc_prefer(1, BLE_MESH_ADV_TASK_STACK_SIZE * sizeof(StackType_t), + 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, + MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + assert(adv_task.stack); + + adv_task.handle = xTaskCreateStaticPinnedToCore(adv_thread, BLE_MESH_ADV_TASK_NAME, + BLE_MESH_ADV_TASK_STACK_SIZE, NULL, + BLE_MESH_ADV_TASK_PRIO, adv_task.stack, + adv_task.task, BLE_MESH_ADV_TASK_CORE); + assert(adv_task.handle); #else /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && (CONFIG_SPIRAM_CACHE_WORKAROUND || !CONFIG_IDF_TARGET_ESP32) && CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY */ int ret = xTaskCreatePinnedToCore(adv_thread, BLE_MESH_ADV_TASK_NAME, BLE_MESH_ADV_TASK_STACK_SIZE, NULL, BLE_MESH_ADV_TASK_PRIO, &adv_task.handle, BLE_MESH_ADV_TASK_CORE); - __ASSERT(ret == pdTRUE, "Failed to create adv thread"); - (void)ret; + assert(ret == pdTRUE); #endif /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && (CONFIG_SPIRAM_CACHE_WORKAROUND || !CONFIG_IDF_TARGET_ESP32) && CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY */ } void bt_mesh_adv_common_init(void) { bt_mesh_r_mutex_create(&adv_buf_alloc_lock); - bt_mesh_adv_queue_init(&adv_queue, ble_mesh_adv_buf_count_get(), bt_mesh_task_post); + bt_mesh_adv_queue_init(&adv_queue, bt_mesh_adv_buf_count_get(), bt_mesh_task_post); bt_mesh_adv_type_init(BLE_MESH_ADV_PROV, &adv_queue, &adv_buf_pool, adv_alloc); bt_mesh_adv_type_init(BLE_MESH_ADV_DATA, &adv_queue, &adv_buf_pool, adv_alloc); bt_mesh_adv_type_init(BLE_MESH_ADV_BEACON, &adv_queue, &adv_buf_pool, adv_alloc); @@ -795,7 +795,7 @@ void bt_mesh_adv_common_init(void) #endif #if CONFIG_BLE_MESH_USE_BLE_50 - bt_mesh_adv_inst_init(BLE_MESH_ADV_INS, CONFIG_BLE_MESH_ADV_INST_ID); + bt_mesh_adv_inst_init(BLE_MESH_ADV_INST, CONFIG_BLE_MESH_ADV_INST_ID); #if CONFIG_BLE_MESH_EXT_ADV bt_mesh_adv_type_init(BLE_MESH_ADV_EXT_PROV, &adv_queue, &ext_adv_buf_pool, ext_adv_alloc); bt_mesh_adv_type_init(BLE_MESH_ADV_EXT_DATA, &adv_queue, &ext_adv_buf_pool, ext_adv_alloc); @@ -818,24 +818,24 @@ void bt_mesh_adv_common_init(void) * it is not possible to use multiple advertising instances to process * data from the same message queue when sending mesh packets. * - * Therefore, shall to check whether there are - * duplicates in the queue buffer corresponding to each advertising instance. - */ - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_PROV); - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_DATA); - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_BEACON); - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_URI); + * Therefore, shall to check whether there are duplicates in the queue + * buffer corresponding to each advertising instance. + */ + bt_mesh_adv_inst_type_add(BLE_MESH_ADV_INST, BLE_MESH_ADV_PROV); + bt_mesh_adv_inst_type_add(BLE_MESH_ADV_INST, BLE_MESH_ADV_DATA); + bt_mesh_adv_inst_type_add(BLE_MESH_ADV_INST, BLE_MESH_ADV_BEACON); + bt_mesh_adv_inst_type_add(BLE_MESH_ADV_INST, BLE_MESH_ADV_URI); #if CONFIG_BLE_MESH_EXT_ADV - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_PROV); - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_DATA); + bt_mesh_adv_inst_type_add(BLE_MESH_ADV_INST, BLE_MESH_ADV_EXT_PROV); + bt_mesh_adv_inst_type_add(BLE_MESH_ADV_INST, BLE_MESH_ADV_EXT_DATA); #if CONFIG_BLE_MESH_RELAY && !CONFIG_BLE_MESH_RELAY_ADV_BUF - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_RELAY_DATA); + bt_mesh_adv_inst_type_add(BLE_MESH_ADV_INST, BLE_MESH_ADV_EXT_RELAY_DATA); #endif #if CONFIG_BLE_MESH_LONG_PACKET - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_LONG_PROV); - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_LONG_DATA); + bt_mesh_adv_inst_type_add(BLE_MESH_ADV_INST, BLE_MESH_ADV_EXT_LONG_PROV); + bt_mesh_adv_inst_type_add(BLE_MESH_ADV_INST, BLE_MESH_ADV_EXT_LONG_DATA); #if CONFIG_BLE_MESH_RELAY && !CONFIG_BLE_MESH_RELAY_ADV_BUF - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_LONG_RELAY_DATA); + bt_mesh_adv_inst_type_add(BLE_MESH_ADV_INST, BLE_MESH_ADV_EXT_LONG_RELAY_DATA); #endif /* !CONFIG_BLE_MESH_RELAY_ADV_BUF */ #endif /* CONFIG_BLE_MESH_LONG_PACKET */ #endif /* CONFIG_BLE_MESH_EXT_ADV */ @@ -886,7 +886,7 @@ void bt_mesh_adv_common_deinit(void) bt_mesh_adv_queue_deinit(&adv_queue); #if CONFIG_BLE_MESH_USE_BLE_50 - bt_mesh_adv_inst_deinit(BLE_MESH_ADV_INS); + bt_mesh_adv_inst_deinit(BLE_MESH_ADV_INST); #endif bt_mesh_unref_buf_from_pool(&adv_buf_pool); diff --git a/components/bt/esp_ble_mesh/core/adv_common.h b/components/bt/esp_ble_mesh/core/adv_common.h index 23372d404cf..d5172a676af 100644 --- a/components/bt/esp_ble_mesh/core/adv_common.h +++ b/components/bt/esp_ble_mesh/core/adv_common.h @@ -46,7 +46,7 @@ extern "C" { #define BLE_MESH_MSG_NET_BUF(msg) ((struct net_buf *)(msg->arg)) -#define BLE_MESH_ADV_INS_UNUSED 0xFF +#define BLE_MESH_ADV_INST_UNUSED 0xFF struct bt_mesh_adv { const struct bt_mesh_send_cb *cb; @@ -128,7 +128,7 @@ struct bt_mesh_adv_inst { bool busy; struct net_buf *sending_buf; - /* indicates that which adv_type is supported by this instance */ + /* Indicate which adv_type is supported by this instance */ uint32_t spt_mask; #endif /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */ }; @@ -212,10 +212,26 @@ static inline TickType_t K_WAIT(int32_t val) return (val == K_FOREVER) ? portMAX_DELAY : (val / portTICK_PERIOD_MS); } +static inline void adv_send_start(uint16_t duration, int err, + const struct bt_mesh_send_cb *cb, + void *cb_data) +{ + if (cb && cb->start) { + cb->start(duration, err, cb_data); + } +} + +static inline void adv_send_end(int err, const struct bt_mesh_send_cb *cb, + void *cb_data) +{ + if (cb && cb->end) { + cb->end(err, cb_data); + } +} + struct bt_mesh_adv_queue *bt_mesh_adv_queue_get(void); -struct net_buf *bt_mesh_adv_create_from_pool(enum bt_mesh_adv_type type, - int32_t timeout); +struct net_buf *bt_mesh_adv_create_from_pool(enum bt_mesh_adv_type type, int32_t timeout); static inline struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, int32_t timeout) { @@ -225,13 +241,20 @@ static inline struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, int void bt_mesh_adv_buf_ref_debug(const char *func, struct net_buf *buf, uint8_t ref_cmp, bt_mesh_buf_ref_flag_t flag); -struct bt_mesh_adv_type_manager *bt_mesh_adv_types_mgnt_get(enum bt_mesh_adv_type adv_type); +struct bt_mesh_adv_type_manager *bt_mesh_adv_types_mgmt_get(enum bt_mesh_adv_type adv_type); void bt_mesh_generic_adv_send(struct net_buf *buf, uint8_t xmit, const struct bt_mesh_send_cb *cb, void *cb_data, uint16_t src, uint16_t dst, bool front); +static inline void bt_mesh_adv_send(struct net_buf *buf, uint8_t xmit, + const struct bt_mesh_send_cb *cb, + void *cb_data) +{ + bt_mesh_generic_adv_send(buf, xmit, cb, cb_data, BLE_MESH_ADDR_UNASSIGNED, BLE_MESH_ADDR_UNASSIGNED, false); +} + void bt_mesh_unref_buf_from_pool(struct net_buf_pool *pool); void bt_mesh_unref_buf(bt_mesh_msg_t *msg); @@ -252,15 +275,16 @@ void bt_mesh_task_post(bt_mesh_msg_t *msg, uint32_t timeout, bool front); #if CONFIG_BLE_MESH_USE_BLE_50 struct bt_mesh_adv_inst * bt_mesh_get_adv_insts_set(void); +bool bt_mesh_is_adv_inst_used(uint8_t adv_inst_id); int bt_mesh_adv_inst_init(enum bt_mesh_adv_inst_type inst_type, uint8_t inst_id); int bt_mesh_adv_inst_deinit(enum bt_mesh_adv_inst_type inst_type); #endif /* CONFIG_BLE_MESH_USE_BLE_50 */ #if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV -void bt_mesh_adv_inst_supported_adv_type_add(enum bt_mesh_adv_inst_type inst_type, +void bt_mesh_adv_inst_type_add(enum bt_mesh_adv_inst_type inst_type, enum bt_mesh_adv_type adv_type); -void bt_mesh_adv_inst_supported_adv_type_rm(enum bt_mesh_adv_inst_type inst_type, +void bt_mesh_adv_inst_type_rm(enum bt_mesh_adv_inst_type inst_type, enum bt_mesh_adv_type adv_type); void bt_mesh_adv_inst_supported_adv_type_clear(enum bt_mesh_adv_inst_type inst_type, @@ -270,7 +294,6 @@ void bt_mesh_adv_inst_supported_adv_type_clear(enum bt_mesh_adv_inst_type inst_t #if CONFIG_BLE_MESH_RELAY_ADV_BUF void bt_mesh_relay_adv_init(void); bool bt_mesh_ignore_relay_packet(uint32_t timestamp); -struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, int32_t timeout); static inline void bt_mesh_relay_adv_send(struct net_buf *buf, uint8_t xmit, uint16_t src, uint16_t dst, @@ -288,8 +311,6 @@ void bt_mesh_relay_adv_deinit(void); #endif /* CONFIG_BLE_MESH_RELAY_ADV_BUF */ #if CONFIG_BLE_MESH_FRIEND -struct bt_mesh_adv *bt_mesh_frnd_adv_buf_get(int id, enum bt_mesh_adv_type type); -struct net_buf_pool *bt_mesh_frnd_adv_pool_get(void); void bt_mesh_frnd_adv_init(void); #if CONFIG_BLE_MESH_DEINIT void bt_mesh_frnd_adv_deinit(void); @@ -305,14 +326,19 @@ void bt_mesh_adv_common_deinit(void); #endif #if CONFIG_BLE_MESH_USE_BLE_50 -bool bt_mesh_is_adv_inst_used(uint8_t adv_inst_id); -bool ble_mesh_adv_task_wait(uint32_t wait_bits, TickType_t timeout, uint32_t *notify); -int ble_mesh_adv_task_wakeup(uint32_t evt); +int bt_mesh_adv_task_wakeup(uint32_t evt); +bool bt_mesh_adv_task_wait(uint32_t wait_bits, TickType_t timeout, uint32_t *notify); #else -bool ble_mesh_adv_task_wait(uint32_t timeout); +bool bt_mesh_adv_task_wait(uint32_t timeout); #endif #if CONFIG_BLE_MESH_SUPPORT_BLE_ADV +static inline void bt_mesh_ble_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, + void *cb_data, bool front) +{ + bt_mesh_generic_adv_send(buf, 0, cb, cb_data, BLE_MESH_ADDR_UNASSIGNED, BLE_MESH_ADDR_UNASSIGNED, front); +} + int bt_mesh_start_ble_advertising(const struct bt_mesh_ble_adv_param *param, const struct bt_mesh_ble_adv_data *data, uint8_t *index); diff --git a/components/bt/esp_ble_mesh/core/ble_adv.c b/components/bt/esp_ble_mesh/core/ble_adv.c index 110e52e2204..e27109c0471 100644 --- a/components/bt/esp_ble_mesh/core/ble_adv.c +++ b/components/bt/esp_ble_mesh/core/ble_adv.c @@ -14,14 +14,14 @@ #include "mesh/common.h" #include "mesh/buf.h" -#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV #if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE /* Use independent ble adv queue only if multi adv instance is used */ static struct bt_mesh_adv_queue ble_adv_queue; static void bt_mesh_ble_task_post(bt_mesh_msg_t *msg, uint32_t timeout, bool front); #endif + static struct bt_mesh_adv_queue *p_ble_adv_queue; -#define BLE_MESH_BLE_ADV_QUEUE_SIZE (CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT + 1) + /* length + advertising data + length + scan response data */ NET_BUF_POOL_DEFINE(ble_adv_buf_pool, CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT, ((BLE_MESH_ADV_DATA_SIZE + 3) << 1), BLE_MESH_ADV_USER_DATA_SIZE, NULL); @@ -64,17 +64,6 @@ static void bt_mesh_ble_task_post(bt_mesh_msg_t *msg, uint32_t timeout, bool fro } #endif -static struct net_buf *bt_mesh_ble_adv_create(enum bt_mesh_adv_type type, int32_t timeout) -{ - return bt_mesh_adv_create_from_pool(type, timeout); -} - -inline void bt_mesh_ble_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, - void *cb_data, bool front) -{ - bt_mesh_generic_adv_send(buf, 0, cb, cb_data, BLE_MESH_ADDR_UNASSIGNED, BLE_MESH_ADDR_UNASSIGNED, front); -} - static void ble_adv_tx_reset(struct bt_mesh_ble_adv_tx *tx, bool unref) { if (tx->buf == NULL) { @@ -211,7 +200,7 @@ int bt_mesh_start_ble_advertising(const struct bt_mesh_ble_adv_param *param, return -EINVAL; } - buf = bt_mesh_ble_adv_create(BLE_MESH_ADV_BLE, K_NO_WAIT); + buf = bt_mesh_adv_create(BLE_MESH_ADV_BLE, K_NO_WAIT); if (!buf) { BT_ERR("No empty ble adv buffer"); return -ENOBUFS; @@ -303,11 +292,11 @@ void bt_mesh_ble_adv_init(void) bt_mesh_adv_type_init(BLE_MESH_ADV_BLE, p_ble_adv_queue, &ble_adv_buf_pool, ble_adv_alloc); #if CONFIG_BLE_MESH_USE_BLE_50 #if CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE - bt_mesh_adv_inst_init(BLE_MESH_BLE_ADV_INS, CONFIG_BLE_MESH_BLE_ADV_INST_ID); - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_BLE_ADV_INS, BLE_MESH_ADV_BLE); + bt_mesh_adv_inst_init(BLE_MESH_BLE_ADV_INST, CONFIG_BLE_MESH_BLE_ADV_INST_ID); + bt_mesh_adv_inst_type_add(BLE_MESH_BLE_ADV_INST, BLE_MESH_ADV_BLE); #else #if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV - bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_BLE); + bt_mesh_adv_inst_type_add(BLE_MESH_ADV_INST, BLE_MESH_ADV_BLE); #endif #endif /* CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE */ #endif /* CONFIG_BLE_MESH_USE_BLE_50 */ @@ -317,8 +306,7 @@ void bt_mesh_ble_adv_init(void) void bt_mesh_ble_adv_deinit(void) { for (int i = 0; i < ARRAY_SIZE(ble_adv_tx); i++) { - struct bt_mesh_ble_adv_tx *tx = &ble_adv_tx[i]; - ble_adv_tx_reset(tx, false); + ble_adv_tx_reset(&ble_adv_tx[i], false); } bt_mesh_unref_buf_from_pool(&ble_adv_buf_pool); memset(ble_adv_pool, 0, sizeof(ble_adv_pool)); @@ -331,14 +319,13 @@ void bt_mesh_ble_adv_deinit(void) bt_mesh_adv_type_deinit(BLE_MESH_ADV_BLE); #if CONFIG_BLE_MESH_USE_BLE_50 #if CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE - bt_mesh_adv_inst_deinit(BLE_MESH_BLE_ADV_INS); - bt_mesh_adv_inst_supported_adv_type_rm(BLE_MESH_BLE_ADV_INS, BLE_MESH_ADV_BLE); + bt_mesh_adv_inst_deinit(BLE_MESH_BLE_ADV_INST); + bt_mesh_adv_inst_type_rm(BLE_MESH_BLE_ADV_INST, BLE_MESH_ADV_BLE); #else #if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV - bt_mesh_adv_inst_supported_adv_type_rm(BLE_MESH_ADV_INS, BLE_MESH_ADV_BLE); + bt_mesh_adv_inst_type_rm(BLE_MESH_ADV_INST, BLE_MESH_ADV_BLE); #endif #endif /* CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE */ #endif /* CONFIG_BLE_MESH_USE_BLE_50 */ } #endif /* CONFIG_BLE_MESH_DEINIT */ -#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */ diff --git a/components/bt/esp_ble_mesh/core/bluedroid_host/adapter.c b/components/bt/esp_ble_mesh/core/bluedroid_host/adapter.c index fd42502fdaf..0520ca7a114 100644 --- a/components/bt/esp_ble_mesh/core/bluedroid_host/adapter.c +++ b/components/bt/esp_ble_mesh/core/bluedroid_host/adapter.c @@ -396,11 +396,11 @@ void ble_mesh_5_gap_callback(tBTA_DM_BLE_5_GAP_EVENT event, goto transfer_to_user; } #if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV - ble_mesh_adv_task_wakeup(ADV_TASK_ADV_INST_EVT(params->adv_term.adv_handle)); + bt_mesh_adv_task_wakeup(ADV_TASK_ADV_INST_EVT(params->adv_term.adv_handle)); #else /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */ if (params->adv_term.status == 0x43 || /* Limit reached */ params->adv_term.status == 0x3C) { /* Advertising timeout */ - ble_mesh_adv_task_wakeup(ADV_TASK_MESH_ADV_INST_EVT); + bt_mesh_adv_task_wakeup(ADV_TASK_MESH_ADV_INST_EVT); } #if CONFIG_BLE_MESH_SUPPORT_BLE_ADV /** @@ -423,7 +423,7 @@ void ble_mesh_5_gap_callback(tBTA_DM_BLE_5_GAP_EVENT event, * could lead to resource contention issues. */ bt_mesh_unset_ble_adv_running(); - ble_mesh_adv_task_wakeup(ADV_TASK_MESH_ADV_INST_EVT); + bt_mesh_adv_task_wakeup(ADV_TASK_MESH_ADV_INST_EVT); } #endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */ #endif /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */ @@ -655,7 +655,7 @@ static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARC static struct { bool set; tBTA_DM_BLE_GAP_EXT_ADV_PARAMS param; -} last_param[BLE_MESH_ADV_INS_TYPES_NUM]; +} last_param[BLE_MESH_ADV_INST_TYPES_NUM]; int bt_le_ext_adv_start(const uint8_t inst_id, const struct bt_mesh_adv_param *param, diff --git a/components/bt/esp_ble_mesh/core/ext_adv.c b/components/bt/esp_ble_mesh/core/ext_adv.c index ebc28517779..4958e5686db 100644 --- a/components/bt/esp_ble_mesh/core/ext_adv.c +++ b/components/bt/esp_ble_mesh/core/ext_adv.c @@ -28,28 +28,9 @@ #include "adv_common.h" #include "ble_adv.h" -static struct bt_mesh_adv_queue *adv_queue; - static struct bt_mesh_adv_inst *adv_insts; -static inline void adv_send_start(uint16_t duration, int err, - const struct bt_mesh_send_cb *cb, - void *cb_data) -{ - if (cb && cb->start) { - cb->start(duration, err, cb_data); - } -} - -static inline void adv_send_end(int err, const struct bt_mesh_send_cb *cb, - void *cb_data) -{ - if (cb && cb->end) { - cb->end(err, cb_data); - } -} - -static inline int adv_send(struct bt_mesh_adv_inst *inst, uint16_t *adv_duration) +static int adv_send(struct bt_mesh_adv_inst *inst, uint16_t *adv_duration) { struct net_buf *buf = inst->sending_buf; const struct bt_mesh_send_cb *cb = BLE_MESH_ADV(buf)->cb; @@ -205,40 +186,40 @@ static inline int adv_send(struct bt_mesh_adv_inst *inst, uint16_t *adv_duration return 0; } -static inline int find_valid_msg_from_queue(bt_mesh_queue_t *msg_queue, bt_mesh_msg_t *msg) +static int find_valid_msg_from_queue(bt_mesh_queue_t *msg_queue, bt_mesh_msg_t *msg) { while(uxQueueMessagesWaiting(msg_queue->handle)) { xQueueReceive(msg_queue->handle, msg, K_WAIT(K_FOREVER)); - /* In the previous adv task design, only - * the *buf of messages pushed to the queue - * by adv_update would be empty, but in the - * new design, there is a new processing method - * for adv_update's messages, - * so *buf here cannot be empty. */ + /* In the previous adv task design, only the *buf of messages pushed to the queue + * by adv_update would be empty, but in the new design, there is a new processing + * method for adv_update's messages, so *buf here cannot be empty. + */ assert(msg->arg); - /* If the message is canceled for advertising, - * then continue to retrieve the next message - * from that queue. */ + /* If the message is cancelled for advertising, then continue to retrieve the next + * message from that queue. + */ if (!bt_mesh_atomic_cas(&BLE_MESH_ADV_BUSY(BLE_MESH_MSG_NET_BUF(msg)), 1, 0)) { bt_mesh_adv_buf_ref_debug(__func__, BLE_MESH_MSG_NET_BUF(msg), 1U, BLE_MESH_BUF_REF_EQUAL); /* Cancel the adv task's reference to this data packet. - * tips: The reference of buffer by adv_task occurs - * when the buffer is pushed into the queue. + * Tips: + * The reference of buffer by adv_task occurs when the buffer is pushed into + * the queue. */ net_buf_unref(BLE_MESH_MSG_NET_BUF(msg)); - /* Avoid reading the last message in the queue, which could lead - * to pointing to an invalid buffer due to the absence of other - * messages in the queue. */ + + /* Avoid reading the last message in the queue, which could lead to pointing + * to an invalid buffer due to the absence of other messages in the queue. + */ msg->arg = NULL; continue; } #if CONFIG_BLE_MESH_RELAY_ADV_BUF - /* If the relay message should be ignored, - * then continue to retrieve the next message - * from that queue. */ + /* If the relay message should be ignored, then continue to retrieve the next message + * from that queue. + */ if (msg->relay && bt_mesh_ignore_relay_packet(msg->timestamp)) { /* If the interval between "current time - msg.timestamp" is bigger than * BLE_MESH_RELAY_TIME_INTERVAL, this relay packet will not be sent. @@ -259,32 +240,32 @@ static inline int find_valid_msg_from_queue(bt_mesh_queue_t *msg_queue, bt_mesh_ return 0; } -static inline int active_idle_adv_instance(uint32_t *update_evts, uint16_t *min_duration) +static int activate_idle_adv_instance(uint32_t *update_evts, uint16_t *min_duration) { - uint32_t evts = 0; - uint16_t duration = K_FOREVER; uint16_t cur_min_duration = K_FOREVER; enum bt_mesh_adv_type adv_type = 0; - struct bt_mesh_adv_inst *instance = NULL; bt_mesh_queue_t *msg_queue = NULL; + uint16_t duration = K_FOREVER; bt_mesh_msg_t msg = {0}; uint32_t spt_mask = 0; + uint32_t evts = 0; #if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_SERVER - if (!adv_insts[BLE_MESH_ADV_PROXY_INS].busy) { + if (!adv_insts[BLE_MESH_ADV_PROXY_INST].busy) { BT_DBG("Mesh Proxy Advertising start"); duration = bt_mesh_proxy_server_adv_start(); if (duration < cur_min_duration) { cur_min_duration = duration; } - adv_insts[BLE_MESH_ADV_PROXY_INS].busy = true; - evts |= ADV_TASK_ADV_INST_EVT(adv_insts[BLE_MESH_ADV_PROXY_INS].id); + adv_insts[BLE_MESH_ADV_PROXY_INST].busy = true; + evts |= ADV_TASK_ADV_INST_EVT(adv_insts[BLE_MESH_ADV_PROXY_INST].id); } #endif - for (int i = BLE_MESH_ADV_INS; i < BLE_MESH_ADV_INS_TYPES_NUM; i++) { - instance = &adv_insts[i]; + for (int i = BLE_MESH_ADV_INST; i < BLE_MESH_ADV_INST_TYPES_NUM; i++) { + struct bt_mesh_adv_inst *instance = &adv_insts[i]; + if (instance->busy #if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_SERVER @@ -300,10 +281,9 @@ static inline int active_idle_adv_instance(uint32_t *update_evts, uint16_t *min_ while(spt_mask) { adv_type = find_lsb_set(spt_mask) - 1; spt_mask &= ~BIT(adv_type); - msg_queue = &(bt_mesh_adv_types_mgnt_get(adv_type)->adv_q->q); + msg_queue = &(bt_mesh_adv_types_mgmt_get(adv_type)->adv_q->q); - /* When there is no new message in the queue, *buf (aka: msg.arg) - * will be empty. */ + /* If no new message in the queue, the *buf (aka: msg.arg) will be empty */ if (find_valid_msg_from_queue(msg_queue, &msg)) { BT_DBG("no valid message for instance %d", instance->id); continue; @@ -312,15 +292,17 @@ static inline int active_idle_adv_instance(uint32_t *update_evts, uint16_t *min_ instance->sending_buf = (struct net_buf *)msg.arg; if (adv_send(instance, &duration)) { BT_ERR("adv start failed"); + /* When this adv instance fails to broadcast, it could be due to some + * persistent issues, such as incorrect adv parameter settings, or it + * could be due to some temporary issues, such as memory allocation + * failure. + * + * Therefore, it is advisable to skip subsequent queue reads for this + * instance and attempt to broadcast subsequent data again next time, + * rather than disabling the adv instance. + */ net_buf_unref(instance->sending_buf); instance->sending_buf = NULL; - /* When this adv instance fails to broadcast, it could be - * due to some persistent issues, such as incorrect adv - * parameter settings, or it could be due to some temporary - * issues, such as memory allocation failure. Therefore, it - * is advisable to skip subsequent queue reads for this instance - * and attempt to broadcast subsequent data again next time, - * rather than disabling the adv instance. */ break; } @@ -331,9 +313,9 @@ static inline int active_idle_adv_instance(uint32_t *update_evts, uint16_t *min_ instance->busy = true; evts |= ADV_TASK_ADV_INST_EVT(adv_insts[i].id); - /* Must be nullified to avoid affecting the next adv - * instance's judgment on whether the message queue - * is empty. */ + /* Must be nullified to avoid affecting the next adv instance's judgment + * on whether the message queue is empty. + */ msg.arg = NULL; break; } @@ -347,19 +329,18 @@ static inline int active_idle_adv_instance(uint32_t *update_evts, uint16_t *min_ static uint32_t received_adv_evts_handle(uint32_t recv_evts) { - uint32_t evt = 0; - if (!recv_evts) { return 0; } - for (int i = 0; recv_evts && i < BLE_MESH_ADV_INS_TYPES_NUM; i++) { - evt = ADV_TASK_ADV_INST_EVT(adv_insts[i].id); + for (int i = 0; recv_evts && i < BLE_MESH_ADV_INST_TYPES_NUM; i++) { + uint32_t evt = ADV_TASK_ADV_INST_EVT(adv_insts[i].id); + if (recv_evts & evt) { recv_evts &= ~evt; #if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_SERVER - if (unlikely(i == BLE_MESH_ADV_PROXY_INS)) { + if (unlikely(i == BLE_MESH_ADV_PROXY_INST)) { BT_DBG("Mesh Proxy Advertising auto stop"); bt_mesh_proxy_server_adv_flag_set(false); } else @@ -390,24 +371,23 @@ static void adv_thread(void *p) adv_duration = K_FOREVER; wait_evts |= ADV_TASK_PKT_SEND_EVT; - active_idle_adv_instance(&wait_evts, &adv_duration); + activate_idle_adv_instance(&wait_evts, &adv_duration); - ble_mesh_adv_task_wait(wait_evts, adv_duration, &recv_evts); + bt_mesh_adv_task_wait(wait_evts, adv_duration, &recv_evts); wait_evts &= ~recv_evts; #if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_SERVER if (recv_evts & ADV_TASK_PROXY_ADV_UPD_EVT) { - adv_insts[BLE_MESH_ADV_PROXY_INS].busy = false; + adv_insts[BLE_MESH_ADV_PROXY_INST].busy = false; recv_evts &= ~ADV_TASK_PROXY_ADV_UPD_EVT; } #endif - /** - * `recv_evts == ADV_TASK_PKT_SEND_EVT` indicates that new packets - * have been placed into the queue, and the advertising instances started - * previous have not yet stopped. + /* The `recv_evts == ADV_TASK_PKT_SEND_EVT` indicates that new packets + * have been put into the queue, and the advertising instances started + * previously have not yet been stopped. */ if (recv_evts == ADV_TASK_PKT_SEND_EVT) { continue; @@ -431,8 +411,8 @@ void bt_mesh_adv_update(void) CONFIG_BLE_MESH_GATT_PROXY_SERVER BT_DBG("Mesh Proxy Advertising stopped manually"); bt_mesh_proxy_server_adv_stop(); - if (adv_insts[BLE_MESH_ADV_PROXY_INS].busy) { - ble_mesh_adv_task_wakeup(ADV_TASK_PROXY_ADV_UPD_EVT); + if (adv_insts[BLE_MESH_ADV_PROXY_INST].busy) { + bt_mesh_adv_task_wakeup(ADV_TASK_PROXY_ADV_UPD_EVT); } #endif } @@ -442,7 +422,6 @@ void bt_mesh_adv_init(void) bt_mesh_adv_common_init(); adv_insts = bt_mesh_get_adv_insts_set(); - adv_queue = bt_mesh_adv_queue_get(); #if CONFIG_BLE_MESH_RELAY_ADV_BUF bt_mesh_relay_adv_init(); diff --git a/components/bt/esp_ble_mesh/core/ext_adv.h b/components/bt/esp_ble_mesh/core/ext_adv.h index 3004db27cdf..536b0aa4fd1 100644 --- a/components/bt/esp_ble_mesh/core/ext_adv.h +++ b/components/bt/esp_ble_mesh/core/ext_adv.h @@ -20,13 +20,6 @@ extern "C" { #endif -static inline void bt_mesh_adv_send(struct net_buf *buf, uint8_t xmit, - const struct bt_mesh_send_cb *cb, - void *cb_data) -{ - bt_mesh_generic_adv_send(buf, xmit, cb, cb_data, BLE_MESH_ADDR_UNASSIGNED, BLE_MESH_ADDR_UNASSIGNED, false); -} - void bt_mesh_adv_update(void); void bt_mesh_adv_init(void); diff --git a/components/bt/esp_ble_mesh/core/friend.c b/components/bt/esp_ble_mesh/core/friend.c index 99e41cd099d..eae9f9471d0 100644 --- a/components/bt/esp_ble_mesh/core/friend.c +++ b/components/bt/esp_ble_mesh/core/friend.c @@ -346,7 +346,7 @@ static struct net_buf *create_friend_pdu(struct bt_mesh_friend *frnd, { struct net_buf *buf = NULL; - buf = bt_mesh_adv_create_from_pool(BLE_MESH_ADV_FRIEND, K_NO_WAIT); + buf = bt_mesh_adv_create(BLE_MESH_ADV_FRIEND, K_NO_WAIT); if (!buf) { return NULL; } diff --git a/components/bt/esp_ble_mesh/core/include/mesh/adapter.h b/components/bt/esp_ble_mesh/core/include/mesh/adapter.h index de8b01c95f1..39c359d695c 100644 --- a/components/bt/esp_ble_mesh/core/include/mesh/adapter.h +++ b/components/bt/esp_ble_mesh/core/include/mesh/adapter.h @@ -512,20 +512,20 @@ struct bt_mesh_adv_param { #define ADV_TASK_ADV_INST_EVT(inst_id) BIT(inst_id) enum bt_mesh_adv_inst_type { - BLE_MESH_ADV_INS, + BLE_MESH_ADV_INST, #if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV #if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_SERVER - BLE_MESH_ADV_PROXY_INS, + BLE_MESH_ADV_PROXY_INST, #endif #if CONFIG_BLE_MESH_SEPARATE_RELAY_ADV_INSTANCE - BLE_MESH_RELAY_ADV_INS, + BLE_MESH_RELAY_ADV_INST, #endif #if CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE - BLE_MESH_BLE_ADV_INS, + BLE_MESH_BLE_ADV_INST, #endif #endif /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */ - BLE_MESH_ADV_INS_TYPES_NUM, + BLE_MESH_ADV_INST_TYPES_NUM, }; #if CONFIG_BLE_MESH_SUPPORT_BLE_ADV diff --git a/components/bt/esp_ble_mesh/core/net.c b/components/bt/esp_ble_mesh/core/net.c index c81b15d37df..3d140927040 100644 --- a/components/bt/esp_ble_mesh/core/net.c +++ b/components/bt/esp_ble_mesh/core/net.c @@ -1679,7 +1679,7 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, if (rx->ctx.enh.long_pkt_cfg) { buf = bt_mesh_adv_create(BLE_MESH_ADV_EXT_LONG_RELAY_DATA, K_NO_WAIT); } else -#endif +#endif /* CONFIG_BLE_MESH_LONG_PACKET */ { buf = bt_mesh_adv_create(BLE_MESH_ADV_EXT_DATA, K_NO_WAIT); } @@ -1690,11 +1690,11 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, EXT_ADV(buf)->tx_power = rx->ctx.enh.ext_adv_cfg.tx_power; } } else -#endif +#endif /* CONFIG_BLE_MESH_EXT_ADV */ { buf = bt_mesh_adv_create(BLE_MESH_ADV_DATA, K_NO_WAIT); } -#else +#else /* !CONFIG_BLE_MESH_RELAY_ADV_BUF */ /* Check if the number of relay packets in queue is too large, if so * use minimum relay retransmit value for later relay packets. */ @@ -1707,7 +1707,7 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, if (rx->ctx.enh.long_pkt_cfg) { buf = bt_mesh_adv_create(BLE_MESH_ADV_EXT_LONG_RELAY_DATA, K_NO_WAIT); } else -#endif +#endif /* CONFIG_BLE_MESH_LONG_PACKET */ { buf = bt_mesh_adv_create(BLE_MESH_ADV_EXT_DATA, K_NO_WAIT); } @@ -1718,11 +1718,11 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, EXT_ADV(buf)->tx_power = rx->ctx.enh.ext_adv_cfg.tx_power; } } else -#endif +#endif /* CONFIG_BLE_MESH_EXT_ADV */ { - buf = bt_mesh_relay_adv_create(BLE_MESH_ADV_RELAY_DATA, K_NO_WAIT); + buf = bt_mesh_adv_create(BLE_MESH_ADV_RELAY_DATA, K_NO_WAIT); } -#endif +#endif /* !CONFIG_BLE_MESH_RELAY_ADV_BUF */ if (!buf) { BT_INFO("Out of relay buffers"); 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 f5fd0279fc4..d89c63b3492 100644 --- a/components/bt/esp_ble_mesh/core/nimble_host/adapter.c +++ b/components/bt/esp_ble_mesh/core/nimble_host/adapter.c @@ -997,12 +997,12 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg) event->adv_complete.reason); #if CONFIG_BLE_MESH_USE_BLE_50 #if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV - ble_mesh_adv_task_wakeup(ADV_TASK_ADV_INST_EVT(event->adv_complete.instance)); + bt_mesh_adv_task_wakeup(ADV_TASK_ADV_INST_EVT(event->adv_complete.instance)); #else /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */ assert(CONFIG_BLE_MESH_ADV_INST_ID == event->adv_complete.instance); /* Limit Reached (0x43) and Advertising Timeout (0x3C) will cause BLE_HS_ETIMEOUT to be set. */ if (event->adv_complete.reason == BLE_HS_ETIMEOUT) { - ble_mesh_adv_task_wakeup(ADV_TASK_ADV_INST_EVT(event->adv_complete.instance)); + bt_mesh_adv_task_wakeup(ADV_TASK_ADV_INST_EVT(event->adv_complete.instance)); } #if CONFIG_BLE_MESH_SUPPORT_BLE_ADV /** @@ -1020,12 +1020,12 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg) */ if (bt_mesh_is_ble_adv_running() && event->adv_complete.reason == 0) { - /* The unset operation must be performed before waking up the - * adv task; performing the unset after waking up the adv task - * could lead to resource contention issues. - */ + /* The unset operation must be performed before waking up the + * adv task; performing the unset after waking up the adv task + * could lead to resource contention issues. + */ bt_mesh_unset_ble_adv_running(); - ble_mesh_adv_task_wakeup(ADV_TASK_ADV_INST_EVT(event->adv_complete.instance)); + bt_mesh_adv_task_wakeup(ADV_TASK_ADV_INST_EVT(event->adv_complete.instance)); } #endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */ #endif /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */ @@ -1124,12 +1124,12 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg) BT_DBG("Provisioner advertise complete; reason=%d", event->adv_complete.reason); #if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV - ble_mesh_adv_task_wakeup(ADV_TASK_ADV_INST_EVT(event->adv_complete.instance)); + bt_mesh_adv_task_wakeup(ADV_TASK_ADV_INST_EVT(event->adv_complete.instance)); #else /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */ assert(CONFIG_BLE_MESH_ADV_INST_ID == event->adv_complete.instance); /* Limit Reached (0x43) and Advertising Timeout (0x3C) will cause BLE_HS_ETIMEOUT to be set. */ if (event->adv_complete.reason == BLE_HS_ETIMEOUT) { - ble_mesh_adv_task_wakeup(ADV_TASK_ADV_INST_EVT(CONFIG_BLE_MESH_ADV_INST_ID)); + bt_mesh_adv_task_wakeup(ADV_TASK_ADV_INST_EVT(CONFIG_BLE_MESH_ADV_INST_ID)); } #if CONFIG_BLE_MESH_SUPPORT_BLE_ADV /** @@ -1152,7 +1152,7 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg) * could lead to resource contention issues. */ bt_mesh_unset_ble_adv_running(); - ble_mesh_adv_task_wakeup(ADV_TASK_ADV_INST_EVT(CONFIG_BLE_MESH_ADV_INST_ID)); + bt_mesh_adv_task_wakeup(ADV_TASK_ADV_INST_EVT(CONFIG_BLE_MESH_ADV_INST_ID)); } #endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */ #endif /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */ @@ -1167,7 +1167,7 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg) static struct { bool set; struct ble_gap_ext_adv_params param; -} last_param[BLE_MESH_ADV_INS_TYPES_NUM]; +} last_param[BLE_MESH_ADV_INST_TYPES_NUM]; int bt_le_ext_adv_start(const uint8_t inst_id, const struct bt_mesh_adv_param *param, @@ -2516,8 +2516,7 @@ void bt_mesh_gatt_init(void) static bool init = false; if (init == false) { - - __ASSERT(g_gatts_svcs_add, "func bt_mesh_gatts_svcs_add should be called before mesh init"); + assert(g_gatts_svcs_add); ble_gatts_svc_set_visibility(prov_svc_start_handle, 1); ble_gatts_svc_set_visibility(proxy_svc_start_handle, 0); diff --git a/components/bt/esp_ble_mesh/core/proxy_server.c b/components/bt/esp_ble_mesh/core/proxy_server.c index 062bb9b247f..c6cc15cab6e 100644 --- a/components/bt/esp_ble_mesh/core/proxy_server.c +++ b/components/bt/esp_ble_mesh/core/proxy_server.c @@ -1598,8 +1598,13 @@ static int private_node_id_adv(struct bt_mesh_subnet *sub) memcpy(proxy_svc_data + 3, tmp + 8, 8); proxy_sd_len = gatt_proxy_adv_create(&proxy_sd); +#if CONFIG_BLE_MESH_USE_BLE_50 + err = bt_le_ext_adv_start(proxy_adv_inst, &fast_adv_param, private_node_id_ad, + ARRAY_SIZE(private_node_id_ad), &proxy_sd, proxy_sd_len); +#else /* CONFIG_BLE_MESH_USE_BLE_50 */ err = bt_le_adv_start(&fast_adv_param, private_node_id_ad, ARRAY_SIZE(private_node_id_ad), &proxy_sd, proxy_sd_len); +#endif /* CONFIG_BLE_MESH_USE_BLE_50 */ if (err) { BT_WARN("Failed to advertise with Private Node ID (err %d)", err); return err; @@ -1642,8 +1647,13 @@ static int private_net_id_adv(struct bt_mesh_subnet *sub) proxy_sd_len = gatt_proxy_adv_create(&proxy_sd); +#if CONFIG_BLE_MESH_USE_BLE_50 + err = bt_le_ext_adv_start(proxy_adv_inst, &fast_adv_param, private_net_id_ad, + ARRAY_SIZE(private_net_id_ad), &proxy_sd, proxy_sd_len); +#else /* CONFIG_BLE_MESH_USE_BLE_50 */ err = bt_le_adv_start(&fast_adv_param, private_net_id_ad, ARRAY_SIZE(private_net_id_ad), &proxy_sd, proxy_sd_len); +#endif /* CONFIG_BLE_MESH_USE_BLE_50 */ if (err) { BT_WARN("Failed to advertise with Private Net ID (err %d)", err); return err; diff --git a/components/bt/esp_ble_mesh/core/scan.c b/components/bt/esp_ble_mesh/core/scan.c index df6f22e117e..c298f184566 100644 --- a/components/bt/esp_ble_mesh/core/scan.c +++ b/components/bt/esp_ble_mesh/core/scan.c @@ -43,18 +43,18 @@ static struct bt_mesh_scan_param scan_param = { #if CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN - .type = BLE_MESH_SCAN_ACTIVE, + .type = BLE_MESH_SCAN_ACTIVE, #else - .type = BLE_MESH_SCAN_PASSIVE, + .type = BLE_MESH_SCAN_PASSIVE, #endif #if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN - .filter_dup = BLE_MESH_SCAN_FILTER_DUP_ENABLE, + .filter_dup = BLE_MESH_SCAN_FILTER_DUP_ENABLE, #else - .filter_dup = BLE_MESH_SCAN_FILTER_DUP_DISABLE, + .filter_dup = BLE_MESH_SCAN_FILTER_DUP_DISABLE, #endif - .interval = SCAN_INTERVAL, - .window = SCAN_WINDOW, - .scan_fil_policy = BLE_MESH_SP_ADV_ALL, + .interval = SCAN_INTERVAL, + .window = SCAN_WINDOW, + .scan_fil_policy = BLE_MESH_SP_ADV_ALL, }; #if (CONFIG_BLE_MESH_PROVISIONER || CONFIG_BLE_MESH_RPR_SRV) @@ -115,21 +115,21 @@ int bt_mesh_unprov_dev_info_query(uint8_t uuid[16], uint8_t addr[6], if (!memcmp(unprov_dev_info_fifo.info[idx].addr, addr, 6)) { if (query_type & BLE_MESH_STORE_UNPROV_INFO_QUERY_TYPE_EXISTS) { return 0; - } else { - memcpy(uuid, unprov_dev_info_fifo.info[idx].uuid, 16); - *adv_type = unprov_dev_info_fifo.info[idx].adv_type; - break; } + + memcpy(uuid, unprov_dev_info_fifo.info[idx].uuid, 16); + *adv_type = unprov_dev_info_fifo.info[idx].adv_type; + break; } } else { if (!memcmp(unprov_dev_info_fifo.info[idx].uuid, uuid, 16)) { if (query_type & BLE_MESH_STORE_UNPROV_INFO_QUERY_TYPE_EXISTS) { return 0; - } else { - memcpy(addr, unprov_dev_info_fifo.info[idx].addr, 6); - *adv_type = unprov_dev_info_fifo.info[idx].adv_type; - break; } + + memcpy(addr, unprov_dev_info_fifo.info[idx].addr, 6); + *adv_type = unprov_dev_info_fifo.info[idx].adv_type; + break; } } cnt++; @@ -458,12 +458,12 @@ static void bt_mesh_scan_cb(struct bt_mesh_adv_report *adv_rpt) */ if (rpr_ext_scan_handle_adv_pkt(&adv_rpt->addr, adv_data, adv_len)) { return; - } else { -#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN - callback_ble_adv_pkt(&adv_rpt->addr, adv_rpt->adv_type, adv_data, adv_len, adv_rpt->rssi); -#endif - net_buf_simple_restore(buf, &buf_state); } + +#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN + callback_ble_adv_pkt(&adv_rpt->addr, adv_rpt->adv_type, adv_data, adv_len, adv_rpt->rssi); +#endif + net_buf_simple_restore(buf, &buf_state); } #endif /* CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN */ diff --git a/components/bt/esp_ble_mesh/core/transport.c b/components/bt/esp_ble_mesh/core/transport.c index 88a6158b89e..797ff2a1ad3 100644 --- a/components/bt/esp_ble_mesh/core/transport.c +++ b/components/bt/esp_ble_mesh/core/transport.c @@ -177,74 +177,6 @@ int32_t bt_mesh_get_seg_rtx_timeout(uint16_t dst, uint8_t ttl) return SEG_RETRANSMIT_TIMEOUT_UNICAST(&tx); } -struct bt_mesh_app_key *bt_mesh_app_key_get(uint16_t app_idx) -{ - if (bt_mesh_is_provisioned()) { -#if CONFIG_BLE_MESH_NODE - if (!IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV)) { - for (int i = 0; i < ARRAY_SIZE(bt_mesh.app_keys); i++) { - if (bt_mesh.app_keys[i].net_idx != BLE_MESH_KEY_UNUSED && - bt_mesh.app_keys[i].app_idx == app_idx) { - return &bt_mesh.app_keys[i]; - } - } - } else { - return bt_mesh_fast_prov_app_key_find(app_idx); - } -#endif - } else if (bt_mesh_is_provisioner_en()) { -#if CONFIG_BLE_MESH_PROVISIONER - for (int i = 0; i < ARRAY_SIZE(bt_mesh.p_app_keys); i++) { - if (bt_mesh.p_app_keys[i] && - bt_mesh.p_app_keys[i]->net_idx != BLE_MESH_KEY_UNUSED && - bt_mesh.p_app_keys[i]->app_idx == app_idx) { - return bt_mesh.p_app_keys[i]; - } - } -#endif - } - - return NULL; -} - -int bt_mesh_upper_key_get(const struct bt_mesh_subnet *subnet, uint16_t app_idx, - const uint8_t **key, uint8_t *aid, uint16_t dst) -{ - struct bt_mesh_app_key *app_key = NULL; - - if (app_idx == BLE_MESH_KEY_DEV) { - *key = bt_mesh_dev_key_get(dst); - if (!*key) { - BT_ERR("DevKey of 0x%04x not found", dst); - return -EINVAL; - } - - *aid = 0U; - return 0; - } - - if (!subnet) { - BT_ERR("Invalid subnet"); - return -EINVAL; - } - - app_key = bt_mesh_app_key_get(app_idx); - if (!app_key) { - BT_ERR("AppKey 0x%04x not found", app_idx); - return -ENOENT; - } - - if (subnet->kr_phase == BLE_MESH_KR_PHASE_2 && app_key->updated) { - *key = app_key->keys[1].val; - *aid = app_key->keys[1].id; - } else { - *key = app_key->keys[0].val; - *aid = app_key->keys[0].id; - } - - return 0; -} - static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, const struct bt_mesh_send_cb *cb, void *cb_data, const uint8_t *ctl_op) @@ -442,7 +374,6 @@ static inline void seg_tx_complete(struct seg_tx *tx, int err) static void schedule_retransmit(struct seg_tx *tx) { - bt_mesh_seg_tx_lock(tx); /* It's possible that a segment broadcast hasn't finished, * but the tx are already released. Only the seg_pending * of this segment remains unprocessed. So, here, we @@ -450,27 +381,29 @@ static void schedule_retransmit(struct seg_tx *tx) * destination (dst) is unassigned, and then process * the seg_pending of this segment. * See BLEMESH25-92 for details */ + + bt_mesh_seg_tx_lock(tx); + if (tx->dst == BLE_MESH_ADDR_UNASSIGNED) { if (tx->seg_pending) { tx->seg_pending--; } - bt_mesh_seg_tx_unlock(tx); - return; + goto end; } if (--tx->seg_pending) { - bt_mesh_seg_tx_unlock(tx); - return; + goto end; } if (!BLE_MESH_ADDR_IS_UNICAST(tx->dst) && !tx->attempts) { BT_INFO("Complete tx sdu to group"); seg_tx_complete(tx, 0); - bt_mesh_seg_tx_unlock(tx); - return; + goto end; } k_delayed_work_submit(&tx->rtx_timer, SEG_RETRANSMIT_TIMEOUT(tx)); + +end: bt_mesh_seg_tx_unlock(tx); } diff --git a/components/bt/esp_ble_mesh/core/transport.enh.c b/components/bt/esp_ble_mesh/core/transport.enh.c index 318b21bb099..583f83e6a30 100644 --- a/components/bt/esp_ble_mesh/core/transport.enh.c +++ b/components/bt/esp_ble_mesh/core/transport.enh.c @@ -209,74 +209,6 @@ uint32_t bt_mesh_seg_ack_period(void) return (uint32_t)(val * bt_mesh_seg_rx_interval()); } -struct bt_mesh_app_key *bt_mesh_app_key_get(uint16_t app_idx) -{ - if (bt_mesh_is_provisioned()) { -#if CONFIG_BLE_MESH_NODE - if (!IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV)) { - for (int i = 0; i < ARRAY_SIZE(bt_mesh.app_keys); i++) { - if (bt_mesh.app_keys[i].net_idx != BLE_MESH_KEY_UNUSED && - bt_mesh.app_keys[i].app_idx == app_idx) { - return &bt_mesh.app_keys[i]; - } - } - } else { - return bt_mesh_fast_prov_app_key_find(app_idx); - } -#endif - } else if (bt_mesh_is_provisioner_en()) { -#if CONFIG_BLE_MESH_PROVISIONER - for (int i = 0; i < ARRAY_SIZE(bt_mesh.p_app_keys); i++) { - if (bt_mesh.p_app_keys[i] && - bt_mesh.p_app_keys[i]->net_idx != BLE_MESH_KEY_UNUSED && - bt_mesh.p_app_keys[i]->app_idx == app_idx) { - return bt_mesh.p_app_keys[i]; - } - } -#endif - } - - return NULL; -} - -int bt_mesh_upper_key_get(const struct bt_mesh_subnet *subnet, uint16_t app_idx, - const uint8_t **key, uint8_t *aid, uint16_t dst) -{ - struct bt_mesh_app_key *app_key = NULL; - - if (app_idx == BLE_MESH_KEY_DEV) { - *key = bt_mesh_dev_key_get(dst); - if (!*key) { - BT_ERR("DevKey of 0x%04x not found", dst); - return -EINVAL; - } - - *aid = 0U; - return 0; - } - - if (!subnet) { - BT_ERR("Invalid subnet"); - return -EINVAL; - } - - app_key = bt_mesh_app_key_get(app_idx); - if (!app_key) { - BT_ERR("AppKey 0x%04x not found", app_idx); - return -ENOENT; - } - - if (subnet->kr_phase == BLE_MESH_KR_PHASE_2 && app_key->updated) { - *key = app_key->keys[1].val; - *aid = app_key->keys[1].id; - } else { - *key = app_key->keys[0].val; - *aid = app_key->keys[0].id; - } - - return 0; -} - static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, const struct bt_mesh_send_cb *cb, void *cb_data, const uint8_t *ctl_op) diff --git a/components/bt/esp_ble_mesh/models/client/client_common.c b/components/bt/esp_ble_mesh/models/client/client_common.c index 5917b69cdf7..8c8afdd563f 100644 --- a/components/bt/esp_ble_mesh/models/client/client_common.c +++ b/components/bt/esp_ble_mesh/models/client/client_common.c @@ -20,7 +20,7 @@ #define HCI_TIME_FOR_START_ADV K_MSEC(5) /* Three adv related hci commands may take 4 ~ 5ms */ -static bt_mesh_client_node_t *bt_mesh_client_pick_node(sys_slist_t *list, uint16_t tx_dst) +static bt_mesh_client_node_t *client_pick_node(sys_slist_t *list, uint16_t tx_dst) { bt_mesh_client_node_t *node = NULL; sys_snode_t *cur = NULL; @@ -86,7 +86,7 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(struct bt_mesh_model * return NULL; } - if ((node = bt_mesh_client_pick_node(&data->queue, ctx->addr)) == NULL) { + if ((node = client_pick_node(&data->queue, ctx->addr)) == NULL) { BT_DBG("Unexpected status message 0x%08x", ctx->recv_op); if (cli->publish_status && need_pub) { cli->publish_status(ctx->recv_op, model, ctx, buf); @@ -113,32 +113,8 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(struct bt_mesh_model * return node; } -static bool bt_mesh_client_check_node_in_list(sys_slist_t *list, uint16_t tx_dst) -{ - bt_mesh_client_node_t *node = NULL; - sys_snode_t *cur = NULL; - - bt_mesh_list_lock(); - if (sys_slist_is_empty(list)) { - bt_mesh_list_unlock(); - return false; - } - - for (cur = sys_slist_peek_head(list); - cur != NULL; cur = sys_slist_peek_next(cur)) { - node = (bt_mesh_client_node_t *)cur; - if (node->ctx.addr == tx_dst) { - bt_mesh_list_unlock(); - return true; - } - } - - bt_mesh_list_unlock(); - return false; -} - -static uint32_t bt_mesh_client_get_status_op(const bt_mesh_client_op_pair_t *op_pair, - int size, uint32_t opcode) +static uint32_t client_get_status_op(const bt_mesh_client_op_pair_t *op_pair, + int size, uint32_t opcode) { if (!op_pair || size == 0) { return 0; @@ -155,7 +131,7 @@ static uint32_t bt_mesh_client_get_status_op(const bt_mesh_client_op_pair_t *op_ return 0; } -static int32_t bt_mesh_get_adv_duration(struct bt_mesh_msg_ctx *ctx) +static int32_t client_get_adv_duration(struct bt_mesh_msg_ctx *ctx) { uint16_t duration = 0, adv_int = 0; uint8_t xmit = 0; @@ -177,9 +153,9 @@ static int32_t bt_mesh_get_adv_duration(struct bt_mesh_msg_ctx *ctx) return (int32_t)duration; } -static int32_t bt_mesh_client_calc_timeout(struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *msg, - uint32_t opcode, int32_t timeout) +static int32_t client_calc_timeout(struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *msg, + uint32_t opcode, int32_t timeout) { int32_t seg_rtx_to = 0, duration = 0, time = 0; uint8_t seg_count = 0, seg_rtx_num = 0; @@ -228,7 +204,7 @@ static int32_t bt_mesh_client_calc_timeout(struct bt_mesh_msg_ctx *ctx, seg_count = (msg->len + mic_size - 1) / 12U + 1U; } - duration = bt_mesh_get_adv_duration(ctx); + duration = client_get_adv_duration(ctx); /* Currently only consider the time consumption of the same segmented * messages, but if there are other messages between any two retrans- @@ -334,7 +310,7 @@ int bt_mesh_client_send_msg(bt_mesh_client_common_param_t *param, return -EINVAL; } - if (bt_mesh_client_check_node_in_list(&internal->queue, param->ctx.addr)) { + if (client_pick_node(&internal->queue, param->ctx.addr)) { BT_ERR("Busy sending message to DST 0x%04x", param->ctx.addr); return -EBUSY; } @@ -349,14 +325,15 @@ int bt_mesh_client_send_msg(bt_mesh_client_common_param_t *param, memcpy(&node->ctx, ¶m->ctx, sizeof(struct bt_mesh_msg_ctx)); node->model = param->model; node->opcode = param->opcode; - node->op_pending = bt_mesh_client_get_status_op(client->op_pair, client->op_pair_size, param->opcode); + node->op_pending = client_get_status_op(client->op_pair, client->op_pair_size, param->opcode); if (node->op_pending == 0U) { BT_ERR("Status opcode not found in op_pair list, opcode 0x%08x", param->opcode); bt_mesh_free(node); return -EINVAL; } - node->timeout = bt_mesh_client_calc_timeout(¶m->ctx, msg, param->opcode, - param->msg_timeout ? param->msg_timeout : CONFIG_BLE_MESH_CLIENT_MSG_TIMEOUT); + node->timeout = client_calc_timeout(¶m->ctx, msg, param->opcode, + (param->msg_timeout ? param->msg_timeout : + CONFIG_BLE_MESH_CLIENT_MSG_TIMEOUT)); if (k_delayed_work_init(&node->timer, timer_handler)) { BT_ERR("Failed to create a timer");