From c2b2641fc18233df68e7cec3f0665aa1dbf29f5f Mon Sep 17 00:00:00 2001 From: Lingao Meng Date: Fri, 8 Sep 2023 13:56:10 +0800 Subject: [PATCH] Bluetooth: Mesh: Move ext adv sector to vector Obviously, it looks obscure by putting it in a sector, so, let's move to vector. refs: https://github.com/zephyrproject-rtos/zephyr/pull/57883 Signed-off-by: Lingao Meng --- cmake/linker_script/common/common-ram.cmake | 3 - include/zephyr/linker/common-ram.ld | 4 - subsys/bluetooth/mesh/Kconfig | 38 +++-- subsys/bluetooth/mesh/adv.c | 41 ++--- subsys/bluetooth/mesh/adv.h | 18 +-- subsys/bluetooth/mesh/adv_ext.c | 151 +++++++++--------- subsys/bluetooth/mesh/adv_legacy.c | 5 +- subsys/bluetooth/mesh/provisioner.c | 2 - tests/bluetooth/mesh/basic/multi_ext_adv.conf | 2 +- .../bsim/bluetooth/mesh/src/test_advertiser.c | 2 +- 10 files changed, 129 insertions(+), 137 deletions(-) diff --git a/cmake/linker_script/common/common-ram.cmake b/cmake/linker_script/common/common-ram.cmake index e6ef59eaf29eb0..9c051477d10b29 100644 --- a/cmake/linker_script/common/common-ram.cmake +++ b/cmake/linker_script/common/common-ram.cmake @@ -111,9 +111,6 @@ if(CONFIG_UVB) zephyr_iterable_section(NAME uvb_node GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) endif() -if(CONFIG_BT_MESH_ADV_EXT) - zephyr_iterable_section(NAME bt_mesh_ext_adv GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) -endif() if(CONFIG_LOG) zephyr_iterable_section(NAME log_mpsc_pbuf GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) diff --git a/include/zephyr/linker/common-ram.ld b/include/zephyr/linker/common-ram.ld index d2d1a5ca7f1be7..c03351abf98915 100644 --- a/include/zephyr/linker/common-ram.ld +++ b/include/zephyr/linker/common-ram.ld @@ -12,10 +12,6 @@ #endif #endif /* NETWORKING */ -#if defined(CONFIG_BT_MESH) - ITERABLE_SECTION_RAM(bt_mesh_ext_adv, 4) -#endif - #if defined(CONFIG_GEN_SW_ISR_TABLE) && defined(CONFIG_DYNAMIC_INTERRUPTS) SECTION_DATA_PROLOGUE(sw_isr_table,,) { diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 667e80f45ab7a2..8667c1e70a0603 100644 --- a/subsys/bluetooth/mesh/Kconfig +++ b/subsys/bluetooth/mesh/Kconfig @@ -103,22 +103,22 @@ menuconfig BT_MESH_ADV_EXT if BT_MESH_ADV_EXT -config BT_MESH_SIMULT_ADV_SETS - int "Maximum number of parallel advertising sets that can be used by the Bluetooth Mesh stack" +config BT_MESH_RELAY_ADV_SETS + int "Maximum of simultaneous relay message support" default 0 range 0 BT_EXT_ADV_MAX_ADV_SET - depends on BT_MESH_RELAY || BT_MESH_PB_ADV + depends on BT_MESH_RELAY help - Maximum of simultaneous message support. Requires controller support + Maximum of simultaneous relay message support. Requires controller support multiple advertising sets. config BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET bool "Use the main advertising set to relay messages" - depends on BT_MESH_SIMULT_ADV_SETS > 0 + depends on BT_MESH_RELAY_ADV_SETS > 0 help When this option is enabled, there is a message that needs to be relayed, all relay advertising sets defined by - CONFIG_BT_MESH_SIMULT_ADV_SETS are busy with relaying messages + CONFIG_BT_MESH_RELAY_ADV_SETS are busy with relaying messages and the main advertising set is not busy with sending local messages, the stack will use the main advertising set to relay the message. This maximizes the utilization efficiency of @@ -192,16 +192,15 @@ config BT_MESH_UNPROV_BEACON_INT if BT_MESH_PB_ADV -config BT_MESH_PB_ADV_RETRANS_TIMEOUT - int "Timeout value of retransmit provisioning PDUs" - default 500 - range 100 800 +config BT_MESH_PB_ADV_USE_RELAY_SETS + bool "Use relay advertising sets to send provisioning PDUs" + depends on BT_MESH_RELAY_ADV_SETS > 0 help - Timeout value of retransmit provisioning PDUs. + Use relay advertising sets to send provisioning PDUs config BT_MESH_PB_ADV_TRANS_PDU_RETRANSMIT_COUNT int "Link Open and Transaction PDU retransmit count" - default 7 if BT_MESH_SIMULT_ADV_SETS > 0 + default 7 if BT_MESH_PB_ADV_USE_RELAY_SETS default 0 range 0 7 help @@ -210,21 +209,28 @@ config BT_MESH_PB_ADV_TRANS_PDU_RETRANSMIT_COUNT config BT_MESH_PB_ADV_TRANS_ACK_RETRANSMIT_COUNT int "Link Ack and Transaction Ack retransmit count" - default 0 + default 2 range 0 7 help - Controls the number of retransmissions of original Link Open and Transaction Acknowledgment PDU, + Controls the number of retransmissions of original Link Ack and Transaction Acknowledgment PDU, in addition to the first transmission. config BT_MESH_PB_ADV_LINK_CLOSE_RETRANSMIT_COUNT int "Link Close retransmit count" - default 7 if BT_MESH_SIMULT_ADV_SETS > 0 + default 7 if BT_MESH_PB_ADV_USE_RELAY_SETS default 2 range 0 7 help Controls the number of retransmissions of original Link Close, in addition to the first transmission. +config BT_MESH_PB_ADV_RETRANS_TIMEOUT + int "Timeout value of retransmit provisioning PDUs" + default 500 + range 100 800 + help + Timeout value of retransmit provisioning PDUs. + endif # BT_MESH_PB_ADV if BT_CONN @@ -401,7 +407,7 @@ config BT_MESH_RELAY_BUF_COUNT of packet drops. When considering the message latency, also consider the values of BT_MESH_RELAY_RETRANSMIT_COUNT and BT_MESH_RELAY_RETRANSMIT_INTERVAL. A higher number of - BT_MESH_SIMULT_ADV_SETS allows the increase in the number of buffers + BT_MESH_RELAY_ADV_SETS allows the increase in the number of buffers while maintaining the latency. endif # BT_MESH_RELAY diff --git a/subsys/bluetooth/mesh/adv.c b/subsys/bluetooth/mesh/adv.c index c7abcd53d70888..b24523aacf3a21 100644 --- a/subsys/bluetooth/mesh/adv.c +++ b/subsys/bluetooth/mesh/adv.c @@ -44,7 +44,7 @@ const uint8_t bt_mesh_adv_type[BT_MESH_ADV_TYPES] = { static bool active_scanning; static K_FIFO_DEFINE(bt_mesh_adv_queue); -static K_FIFO_DEFINE(bt_mesh_simult_queue); +static K_FIFO_DEFINE(bt_mesh_relay_queue); static K_FIFO_DEFINE(bt_mesh_friend_queue); void bt_mesh_adv_send_start(uint16_t duration, int err, struct bt_mesh_adv *adv) @@ -157,7 +157,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, tag, xmit, timeout); } -#if CONFIG_BT_MESH_SIMULT_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE +#if CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE static struct net_buf *process_events(struct k_poll_event *ev, int count) { for (; count; ev++, count--) { @@ -189,7 +189,7 @@ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) #if defined(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET) K_POLL_EVENT_STATIC_INITIALIZER(K_POLL_TYPE_FIFO_DATA_AVAILABLE, K_POLL_MODE_NOTIFY_ONLY, - &bt_mesh_simult_queue, + &bt_mesh_relay_queue, 0), #endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */ }; @@ -202,34 +202,34 @@ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) return process_events(events, ARRAY_SIZE(events)); } -struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout) +struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tag_bit tags, k_timeout_t timeout) { if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - tags & BT_MESH_ADV_TAG_FRIEND_BIT) { + tags & BT_MESH_ADV_TAG_BIT_FRIEND) { return net_buf_get(&bt_mesh_friend_queue, timeout); } - if (tags & BT_MESH_ADV_TAG_LOCAL_BIT) { - return bt_mesh_adv_buf_get(timeout); +#if CONFIG_BT_MESH_RELAY_ADV_SETS + if (!(tags & BT_MESH_ADV_TAG_BIT_LOCAL)) { + return net_buf_get(&bt_mesh_relay_queue, timeout); } - -#if CONFIG_BT_MESH_SIMULT_ADV_SETS - return net_buf_get(&bt_mesh_simult_queue, timeout); #endif + + return bt_mesh_adv_buf_get(timeout); } -#else /* !(CONFIG_BT_MESH_SIMULT_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) */ +#else /* !(CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) */ struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) { return net_buf_get(&bt_mesh_adv_queue, timeout); } -struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout) +struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tag_bit tags, k_timeout_t timeout) { ARG_UNUSED(tags); return bt_mesh_adv_buf_get(timeout); } -#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ +#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ void bt_mesh_adv_buf_get_cancel(void) { @@ -237,9 +237,9 @@ void bt_mesh_adv_buf_get_cancel(void) k_fifo_cancel_wait(&bt_mesh_adv_queue); -#if CONFIG_BT_MESH_SIMULT_ADV_SETS - k_fifo_cancel_wait(&bt_mesh_simult_queue); -#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ +#if CONFIG_BT_MESH_RELAY_ADV_SETS + k_fifo_cancel_wait(&bt_mesh_relay_queue); +#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)) { k_fifo_cancel_wait(&bt_mesh_friend_queue); @@ -267,11 +267,12 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, return; } -#if CONFIG_BT_MESH_SIMULT_ADV_SETS +#if CONFIG_BT_MESH_RELAY_ADV_SETS if (BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_RELAY || - BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_PROV) { - net_buf_put(&bt_mesh_simult_queue, net_buf_ref(buf)); - bt_mesh_adv_buf_simult_ready(); + (IS_ENABLED(CONFIG_BT_MESH_PB_ADV_USE_RELAY_SETS) && + BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_PROV)) { + net_buf_put(&bt_mesh_relay_queue, net_buf_ref(buf)); + bt_mesh_adv_buf_relay_ready(); return; } #endif diff --git a/subsys/bluetooth/mesh/adv.h b/subsys/bluetooth/mesh/adv.h index 50c5b47604c6be..a80ff7e8d4b696 100644 --- a/subsys/bluetooth/mesh/adv.h +++ b/subsys/bluetooth/mesh/adv.h @@ -33,12 +33,12 @@ enum bt_mesh_adv_tag { BT_MESH_ADV_TAG_PROV, }; -enum bt_mesh_adv_tags { - BT_MESH_ADV_TAG_LOCAL_BIT = BIT(BT_MESH_ADV_TAG_LOCAL), - BT_MESH_ADV_TAG_RELAY_BIT = BIT(BT_MESH_ADV_TAG_RELAY), - BT_MESH_ADV_TAG_PROXY_BIT = BIT(BT_MESH_ADV_TAG_PROXY), - BT_MESH_ADV_TAG_FRIEND_BIT = BIT(BT_MESH_ADV_TAG_FRIEND), - BT_MESH_ADV_TAG_PROV_BIT = BIT(BT_MESH_ADV_TAG_PROV), +enum bt_mesh_adv_tag_bit { + BT_MESH_ADV_TAG_BIT_LOCAL = BIT(BT_MESH_ADV_TAG_LOCAL), + BT_MESH_ADV_TAG_BIT_RELAY = BIT(BT_MESH_ADV_TAG_RELAY), + BT_MESH_ADV_TAG_BIT_PROXY = BIT(BT_MESH_ADV_TAG_PROXY), + BT_MESH_ADV_TAG_BIT_FRIEND = BIT(BT_MESH_ADV_TAG_FRIEND), + BT_MESH_ADV_TAG_BIT_PROV = BIT(BT_MESH_ADV_TAG_PROV), }; struct bt_mesh_adv { @@ -66,7 +66,7 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout); -struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout); +struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tag_bit tags, k_timeout_t timeout); void bt_mesh_adv_gatt_update(void); @@ -82,9 +82,9 @@ int bt_mesh_adv_enable(void); void bt_mesh_adv_buf_local_ready(void); -void bt_mesh_adv_buf_simult_ready(void); +void bt_mesh_adv_buf_relay_ready(void); -void bt_mesh_adv_buf_terminate(struct net_buf *buf); +void bt_mesh_adv_buf_terminate(const struct net_buf *buf); void bt_mesh_adv_buf_friend_ready(void); diff --git a/subsys/bluetooth/mesh/adv_ext.c b/subsys/bluetooth/mesh/adv_ext.c index b5be40b36586a7..0bfc2041c7df34 100644 --- a/subsys/bluetooth/mesh/adv_ext.c +++ b/subsys/bluetooth/mesh/adv_ext.c @@ -30,8 +30,8 @@ LOG_MODULE_REGISTER(bt_mesh_adv_ext); /* Convert from ms to 0.625ms units */ #define ADV_INT_FAST_MS 20 -#ifndef CONFIG_BT_MESH_SIMULT_ADV_SETS -#define CONFIG_BT_MESH_SIMULT_ADV_SETS 0 +#ifndef CONFIG_BT_MESH_RELAY_ADV_SETS +#define CONFIG_BT_MESH_RELAY_ADV_SETS 0 #endif enum { @@ -57,7 +57,7 @@ enum { }; struct bt_mesh_ext_adv { - enum bt_mesh_adv_tags tags; + const enum bt_mesh_adv_tag_bit tags; ATOMIC_DEFINE(flags, ADV_FLAGS_NUM); struct bt_le_ext_adv *instance; struct net_buf *buf; @@ -69,80 +69,71 @@ struct bt_mesh_ext_adv { static void send_pending_adv(struct k_work *work); static bool schedule_send(struct bt_mesh_ext_adv *adv); -static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_main) = { - .tags = ( +static struct bt_mesh_ext_adv advs[] = { + [0] = { + .tags = ( #if !defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - BT_MESH_ADV_TAG_FRIEND_BIT | + BT_MESH_ADV_TAG_BIT_FRIEND | #endif #if !defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) - BT_MESH_ADV_TAG_PROXY_BIT | + BT_MESH_ADV_TAG_BIT_PROXY | #endif /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ #if defined(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET) - BT_MESH_ADV_TAG_RELAY_BIT | + BT_MESH_ADV_TAG_BIT_RELAY | #endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */ - BT_MESH_ADV_TAG_LOCAL_BIT), - - .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), -}; - -#if CONFIG_BT_MESH_SIMULT_ADV_SETS -static STRUCT_SECTION_ITERABLE_ARRAY(bt_mesh_ext_adv, adv_relay, CONFIG_BT_MESH_SIMULT_ADV_SETS) = { - [0 ... CONFIG_BT_MESH_SIMULT_ADV_SETS - 1] = { +#if defined(CONFIG_BT_MESH_PB_ADV) + BT_MESH_ADV_TAG_BIT_PROV | +#endif /* CONFIG_BT_MESH_PB_ADV */ + BT_MESH_ADV_TAG_BIT_LOCAL + ), + .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), + }, +#if CONFIG_BT_MESH_RELAY_ADV_SETS + [1 ... CONFIG_BT_MESH_RELAY_ADV_SETS] = { .tags = ( #if defined(CONFIG_BT_MESH_RELAY) - BT_MESH_ADV_TAG_RELAY_BIT | + BT_MESH_ADV_TAG_BIT_RELAY | #endif /* CONFIG_BT_MESH_RELAY */ -#if defined(CONFIG_BT_MESH_PB_ADV) - BT_MESH_ADV_TAG_PROV_BIT | -#endif /* CONFIG_BT_MESH_PB_ADV */ +#if defined(CONFIG_BT_MESH_PB_ADV_USE_RELAY_SETS) + BT_MESH_ADV_TAG_BIT_PROV | +#endif /* CONFIG_BT_MESH_PB_ADV_USE_RELAY_SETS */ 0), - .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), - } -}; -#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ - + }, +#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) -#define ADV_EXT_FRIEND 1 -static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_friend) = { - .tags = BT_MESH_ADV_TAG_FRIEND_BIT, - .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), -}; -#else /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ -#define ADV_EXT_FRIEND 0 + { + .tags = BT_MESH_ADV_TAG_BIT_FRIEND, + .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), + }, #endif /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ - #if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) -#define ADV_EXT_GATT 1 -static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_gatt) = { - .tags = BT_MESH_ADV_TAG_PROXY_BIT, - .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), -}; -#else /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ -#define ADV_EXT_GATT 0 + { + .tags = BT_MESH_ADV_TAG_BIT_PROXY, + .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), + }, #endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ +}; -#define BT_MESH_ADV_COUNT (1 + CONFIG_BT_MESH_SIMULT_ADV_SETS + ADV_EXT_FRIEND + ADV_EXT_GATT) - -BUILD_ASSERT(CONFIG_BT_EXT_ADV_MAX_ADV_SET >= BT_MESH_ADV_COUNT, +BUILD_ASSERT(ARRAY_SIZE(advs) <= CONFIG_BT_EXT_ADV_MAX_ADV_SET, "Insufficient adv instances"); static inline struct bt_mesh_ext_adv *relay_adv_get(void) { -#if CONFIG_BT_MESH_SIMULT_ADV_SETS - return adv_relay; -#else /* !CONFIG_BT_MESH_SIMULT_ADV_SETS */ - return &adv_main; -#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ + if (!!(CONFIG_BT_MESH_RELAY_ADV_SETS)) { + return &advs[1]; + } else { + return &advs[0]; + } } static inline struct bt_mesh_ext_adv *gatt_adv_get(void) { -#if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) - return &adv_gatt; -#else /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ - return &adv_main; -#endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ + if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE)) { + return &advs[ARRAY_SIZE(advs) - 1]; + } else { + return &advs[0]; + } } static int adv_start(struct bt_mesh_ext_adv *adv, @@ -303,7 +294,7 @@ static void send_pending_adv(struct k_work *work) } if (!IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER) || - !(adv->tags & BT_MESH_ADV_TAG_PROXY_BIT)) { + !(adv->tags & BT_MESH_ADV_TAG_BIT_PROXY)) { return; } @@ -347,8 +338,8 @@ static bool schedule_send(struct bt_mesh_ext_adv *adv) atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULE_PENDING); if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - adv->tags & BT_MESH_ADV_TAG_FRIEND_BIT) || - (CONFIG_BT_MESH_SIMULT_ADV_SETS > 0 && adv->tags & BT_MESH_ADV_TAG_RELAY_BIT)) { + adv->tags & BT_MESH_ADV_TAG_BIT_FRIEND) || + (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && adv->tags & BT_MESH_ADV_TAG_BIT_RELAY)) { k_work_reschedule(&adv->work, K_NO_WAIT); } else { /* The controller will send the next advertisement immediately. @@ -369,14 +360,14 @@ void bt_mesh_adv_gatt_update(void) void bt_mesh_adv_buf_local_ready(void) { - (void)schedule_send(&adv_main); + (void)schedule_send(advs); } -void bt_mesh_adv_buf_simult_ready(void) +void bt_mesh_adv_buf_relay_ready(void) { struct bt_mesh_ext_adv *adv = relay_adv_get(); - for (int i = 0; i < CONFIG_BT_MESH_SIMULT_ADV_SETS; i++) { + for (int i = 0; i < CONFIG_BT_MESH_RELAY_ADV_SETS; i++) { if (schedule_send(&adv[i])) { return; } @@ -384,22 +375,26 @@ void bt_mesh_adv_buf_simult_ready(void) /* Attempt to use the main adv set for the sending of relay messages. */ if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET)) { - (void)schedule_send(&adv_main); + (void)schedule_send(advs); } } void bt_mesh_adv_buf_friend_ready(void) { -#if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - (void)schedule_send(&adv_friend); -#endif + if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)) { + schedule_send(&advs[1 + CONFIG_BT_MESH_RELAY_ADV_SETS]); + } else { + schedule_send(&advs[0]); + } } -void bt_mesh_adv_buf_terminate(struct net_buf *buf) +void bt_mesh_adv_buf_terminate(const struct net_buf *buf) { int err; - STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) { + for (int i = 0; i < ARRAY_SIZE(advs); i++) { + struct bt_mesh_ext_adv *adv = &advs[i]; + if (adv->buf != buf) { continue; } @@ -421,7 +416,7 @@ void bt_mesh_adv_buf_terminate(struct net_buf *buf) k_work_submit(&adv->work.work); - break; + return; } } @@ -434,17 +429,18 @@ void bt_mesh_adv_init(void) #if defined(CONFIG_BT_MESH_DEBUG_USE_ID_ADDR) .options = BT_LE_ADV_OPT_USE_IDENTITY, #endif -}; - STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) { - (void)memcpy(&adv->adv_param, &adv_param, sizeof(adv_param)); + }; + + for (int i = 0; i < ARRAY_SIZE(advs); i++) { + (void)memcpy(&advs[i].adv_param, &adv_param, sizeof(adv_param)); } } static struct bt_mesh_ext_adv *adv_instance_find(struct bt_le_ext_adv *instance) { - STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) { - if (adv->instance == instance) { - return adv; + for (int i = 0; i < ARRAY_SIZE(advs); i++) { + if (advs[i].instance == instance) { + return &advs[i]; } } @@ -494,15 +490,14 @@ int bt_mesh_adv_enable(void) #endif /* CONFIG_BT_MESH_GATT_SERVER */ }; - if (adv_main.instance) { + if (advs[0].instance) { /* Already initialized */ return 0; } - - STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) { - err = bt_le_ext_adv_create(&adv->adv_param, &adv_cb, - &adv->instance); + for (int i = 0; i < ARRAY_SIZE(advs); i++) { + err = bt_le_ext_adv_create(&advs[i].adv_param, &adv_cb, + &advs[i].instance); if (err) { return err; } @@ -532,5 +527,5 @@ int bt_mesh_adv_gatt_start(const struct bt_le_adv_param *param, int bt_mesh_adv_bt_data_send(uint8_t num_events, uint16_t adv_interval, const struct bt_data *ad, size_t ad_len) { - return bt_data_send(&adv_main, num_events, adv_interval, ad, ad_len); + return bt_data_send(advs, num_events, adv_interval, ad, ad_len); } diff --git a/subsys/bluetooth/mesh/adv_legacy.c b/subsys/bluetooth/mesh/adv_legacy.c index cb4028662f963d..a7d7dd1a3200aa 100644 --- a/subsys/bluetooth/mesh/adv_legacy.c +++ b/subsys/bluetooth/mesh/adv_legacy.c @@ -195,7 +195,7 @@ void bt_mesh_adv_buf_local_ready(void) /* Will be handled automatically */ } -void bt_mesh_adv_buf_simult_ready(void) +void bt_mesh_adv_buf_relay_ready(void) { /* Will be handled automatically */ } @@ -205,9 +205,8 @@ void bt_mesh_adv_gatt_update(void) bt_mesh_adv_buf_get_cancel(); } -void bt_mesh_adv_buf_terminate(struct net_buf *buf) +void bt_mesh_adv_buf_terminate(const struct net_buf *buf) { - /* todo */ ARG_UNUSED(buf); } diff --git a/subsys/bluetooth/mesh/provisioner.c b/subsys/bluetooth/mesh/provisioner.c index 6bf759272dd4fe..a65bd25ab53da4 100644 --- a/subsys/bluetooth/mesh/provisioner.c +++ b/subsys/bluetooth/mesh/provisioner.c @@ -20,8 +20,6 @@ #include "common/bt_str.h" -#include "host/long_wq.h" - #include "crypto.h" #include "adv.h" #include "mesh.h" diff --git a/tests/bluetooth/mesh/basic/multi_ext_adv.conf b/tests/bluetooth/mesh/basic/multi_ext_adv.conf index 0278bd557bd240..610318f847b685 100644 --- a/tests/bluetooth/mesh/basic/multi_ext_adv.conf +++ b/tests/bluetooth/mesh/basic/multi_ext_adv.conf @@ -51,5 +51,5 @@ CONFIG_BT_MESH_CRYPTO_LOG_LEVEL_DBG=y CONFIG_BT_MESH_ADV_LOG_LEVEL_DBG=y CONFIG_BT_EXT_ADV_MAX_ADV_SET=3 -CONFIG_BT_MESH_SIMULT_ADV_SETS=1 +CONFIG_BT_MESH_RELAY_ADV_SETS=1 CONFIG_BT_MESH_ADV_EXT=y diff --git a/tests/bsim/bluetooth/mesh/src/test_advertiser.c b/tests/bsim/bluetooth/mesh/src/test_advertiser.c index 603985afefc4e4..073651ae843913 100644 --- a/tests/bsim/bluetooth/mesh/src/test_advertiser.c +++ b/tests/bsim/bluetooth/mesh/src/test_advertiser.c @@ -638,7 +638,7 @@ static void test_tx_random_order(void) previous_checker = 0xff; buf[0] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, xmit, K_NO_WAIT); - ASSERT_FALSE(!buf[0], "Out of buffers\n"); + ASSERT_FALSE_MSG(!buf[0], "Out of buffers\n"); buf[1] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, xmit, K_NO_WAIT); ASSERT_FALSE_MSG(!buf[1], "Out of buffers\n");