From 141467a2611bde904cacc7d3f6b89ac282c617ac Mon Sep 17 00:00:00 2001 From: Lingao Meng Date: Wed, 6 Sep 2023 16:47:20 +0800 Subject: [PATCH] Bluetooth: Mesh: Rename adv relay to adv simultaneous Since notice that simultaneous advertising is not only used by relay message, provision over pb-adv can also be used. so it was changed to a more general name. refs:https://github.com/zephyrproject-rtos/zephyr/pull/48903 Signed-off-by: Lingao Meng --- subsys/bluetooth/mesh/Kconfig | 40 +++++-- subsys/bluetooth/mesh/adv.c | 44 +++---- subsys/bluetooth/mesh/adv.h | 22 ++-- subsys/bluetooth/mesh/adv_ext.c | 109 ++++++++++++------ subsys/bluetooth/mesh/adv_legacy.c | 8 +- subsys/bluetooth/mesh/beacon.c | 6 +- subsys/bluetooth/mesh/friend.c | 2 +- subsys/bluetooth/mesh/net.c | 2 +- subsys/bluetooth/mesh/pb_adv.c | 19 ++- subsys/bluetooth/mesh/statistic.c | 12 +- subsys/bluetooth/mesh/transport.c | 4 +- subsys/bluetooth/mesh/transport_legacy.c | 4 +- tests/bluetooth/mesh/basic/multi_ext_adv.conf | 2 +- .../bsim/bluetooth/mesh/src/test_advertiser.c | 18 +-- 14 files changed, 185 insertions(+), 107 deletions(-) diff --git a/subsys/bluetooth/mesh/Kconfig b/subsys/bluetooth/mesh/Kconfig index 7527a1beb16b87..f9d4d3bcf98be4 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_RELAY_ADV_SETS - int "Maximum of simultaneous relay message support" +config BT_MESH_SIMULT_ADV_SETS + int "Maximum number of parallel advertising sets that can be used by the Bluetooth Mesh stack" default 0 range 0 BT_EXT_ADV_MAX_ADV_SET - depends on BT_MESH_RELAY + depends on BT_MESH_RELAY || BT_MESH_PB_ADV help - Maximum of simultaneous relay message support. Requires controller support + Maximum of simultaneous 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_RELAY_ADV_SETS > 0 + depends on BT_MESH_SIMULT_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_RELAY_ADV_SETS are busy with relaying messages + CONFIG_BT_MESH_SIMULT_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 @@ -199,6 +199,32 @@ config BT_MESH_PB_ADV_RETRANS_TIMEOUT help Timeout value of retransmit 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 0 + range 0 7 + help + Controls the number of retransmissions of original Link Open and Transaction PDU, + in addition to the first transmission. + +config BT_MESH_PB_ADV_TRANS_ACK_RETRANSMIT_COUNT + int "Link Ack and Transaction Ack retransmit count" + default 2 + range 0 7 + help + Controls the number of retransmissions of original Link Open 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 2 + range 0 7 + help + Controls the number of retransmissions of original Link Close, + in addition to the first transmission. + endif # BT_MESH_PB_ADV if BT_CONN @@ -375,7 +401,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_RELAY_ADV_SETS allows the increase in the number of buffers + BT_MESH_SIMULT_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 e67d96414e7690..c7abcd53d70888 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_relay_queue); +static K_FIFO_DEFINE(bt_mesh_simult_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) @@ -138,7 +138,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, uint8_t xmit, k_timeout_t timeout) { #if defined(CONFIG_BT_MESH_RELAY) - if (tag == BT_MESH_RELAY_ADV) { + if (tag == BT_MESH_ADV_TAG_RELAY) { return bt_mesh_adv_create_from_pool(&relay_buf_pool, adv_relay_pool, type, tag, xmit, timeout); @@ -146,7 +146,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, #endif #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - if (tag == BT_MESH_FRIEND_ADV) { + if (tag == BT_MESH_ADV_TAG_FRIEND) { return bt_mesh_adv_create_from_pool(&friend_buf_pool, adv_friend_pool, type, tag, xmit, timeout); @@ -157,7 +157,7 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, tag, xmit, timeout); } -#if CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE +#if CONFIG_BT_MESH_SIMULT_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_relay_queue, + &bt_mesh_simult_queue, 0), #endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */ }; @@ -204,19 +204,20 @@ 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) { - if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && tags & BT_MESH_FRIEND_ADV_BIT) { + if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && + tags & BT_MESH_ADV_TAG_FRIEND_BIT) { return net_buf_get(&bt_mesh_friend_queue, timeout); } -#if CONFIG_BT_MESH_RELAY_ADV_SETS - if (tags & BT_MESH_RELAY_ADV_BIT) { - return net_buf_get(&bt_mesh_relay_queue, timeout); + if (tags & BT_MESH_ADV_TAG_LOCAL_BIT) { + return bt_mesh_adv_buf_get(timeout); } -#endif - return bt_mesh_adv_buf_get(timeout); +#if CONFIG_BT_MESH_SIMULT_ADV_SETS + return net_buf_get(&bt_mesh_simult_queue, timeout); +#endif } -#else /* !(CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) */ +#else /* !(CONFIG_BT_MESH_SIMULT_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); @@ -228,7 +229,7 @@ struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout return bt_mesh_adv_buf_get(timeout); } -#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ +#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS || CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ void bt_mesh_adv_buf_get_cancel(void) { @@ -236,9 +237,9 @@ void bt_mesh_adv_buf_get_cancel(void) k_fifo_cancel_wait(&bt_mesh_adv_queue); -#if CONFIG_BT_MESH_RELAY_ADV_SETS - k_fifo_cancel_wait(&bt_mesh_relay_queue); -#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ +#if CONFIG_BT_MESH_SIMULT_ADV_SETS + k_fifo_cancel_wait(&bt_mesh_simult_queue); +#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)) { k_fifo_cancel_wait(&bt_mesh_friend_queue); @@ -260,16 +261,17 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, } if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && - BT_MESH_ADV(buf)->tag == BT_MESH_FRIEND_ADV) { + BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_FRIEND) { net_buf_put(&bt_mesh_friend_queue, net_buf_ref(buf)); bt_mesh_adv_buf_friend_ready(); return; } -#if CONFIG_BT_MESH_RELAY_ADV_SETS - if (BT_MESH_ADV(buf)->tag == BT_MESH_RELAY_ADV) { - net_buf_put(&bt_mesh_relay_queue, net_buf_ref(buf)); - bt_mesh_adv_buf_relay_ready(); +#if CONFIG_BT_MESH_SIMULT_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(); return; } #endif diff --git a/subsys/bluetooth/mesh/adv.h b/subsys/bluetooth/mesh/adv.h index 22a8e0645e11f0..50c5b47604c6be 100644 --- a/subsys/bluetooth/mesh/adv.h +++ b/subsys/bluetooth/mesh/adv.h @@ -26,17 +26,19 @@ enum bt_mesh_adv_type { }; enum bt_mesh_adv_tag { - BT_MESH_LOCAL_ADV, - BT_MESH_RELAY_ADV, - BT_MESH_PROXY_ADV, - BT_MESH_FRIEND_ADV, + BT_MESH_ADV_TAG_LOCAL, + BT_MESH_ADV_TAG_RELAY, + BT_MESH_ADV_TAG_PROXY, + BT_MESH_ADV_TAG_FRIEND, + BT_MESH_ADV_TAG_PROV, }; enum bt_mesh_adv_tags { - BT_MESH_LOCAL_ADV_BIT = BIT(BT_MESH_LOCAL_ADV), - BT_MESH_RELAY_ADV_BIT = BIT(BT_MESH_RELAY_ADV), - BT_MESH_PROXY_ADV_BIT = BIT(BT_MESH_PROXY_ADV), - BT_MESH_FRIEND_ADV_BIT = BIT(BT_MESH_FRIEND_ADV), + 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), }; struct bt_mesh_adv { @@ -80,7 +82,9 @@ int bt_mesh_adv_enable(void); void bt_mesh_adv_buf_local_ready(void); -void bt_mesh_adv_buf_relay_ready(void); +void bt_mesh_adv_buf_simult_ready(void); + +void bt_mesh_adv_buf_terminate(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 9dbbea31fb55c7..b5be40b36586a7 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_RELAY_ADV_SETS -#define CONFIG_BT_MESH_RELAY_ADV_SETS 0 +#ifndef CONFIG_BT_MESH_SIMULT_ADV_SETS +#define CONFIG_BT_MESH_SIMULT_ADV_SETS 0 #endif enum { @@ -72,32 +72,40 @@ static bool schedule_send(struct bt_mesh_ext_adv *adv); static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_main) = { .tags = ( #if !defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - BT_MESH_FRIEND_ADV_BIT | + BT_MESH_ADV_TAG_FRIEND_BIT | #endif #if !defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) - BT_MESH_PROXY_ADV_BIT | + BT_MESH_ADV_TAG_PROXY_BIT | #endif /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ #if defined(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET) - BT_MESH_RELAY_ADV_BIT | + BT_MESH_ADV_TAG_RELAY_BIT | #endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */ - BT_MESH_LOCAL_ADV_BIT), + BT_MESH_ADV_TAG_LOCAL_BIT), .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; -#if CONFIG_BT_MESH_RELAY_ADV_SETS -static STRUCT_SECTION_ITERABLE_ARRAY(bt_mesh_ext_adv, adv_relay, CONFIG_BT_MESH_RELAY_ADV_SETS) = { - [0 ... CONFIG_BT_MESH_RELAY_ADV_SETS - 1] = { - .tags = BT_MESH_RELAY_ADV_BIT, +#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] = { + .tags = ( +#if defined(CONFIG_BT_MESH_RELAY) + BT_MESH_ADV_TAG_RELAY_BIT | +#endif /* CONFIG_BT_MESH_RELAY */ +#if defined(CONFIG_BT_MESH_PB_ADV) + BT_MESH_ADV_TAG_PROV_BIT | +#endif /* CONFIG_BT_MESH_PB_ADV */ + 0), + .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), } }; -#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ +#endif /* CONFIG_BT_MESH_SIMULT_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_FRIEND_ADV_BIT, + .tags = BT_MESH_ADV_TAG_FRIEND_BIT, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), }; #else /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ @@ -107,25 +115,25 @@ static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_friend) = { #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_PROXY_ADV_BIT, + .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 #endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ -#define BT_MESH_ADV_COUNT (1 + CONFIG_BT_MESH_RELAY_ADV_SETS + ADV_EXT_FRIEND + ADV_EXT_GATT) +#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, "Insufficient adv instances"); static inline struct bt_mesh_ext_adv *relay_adv_get(void) { -#if CONFIG_BT_MESH_RELAY_ADV_SETS +#if CONFIG_BT_MESH_SIMULT_ADV_SETS return adv_relay; -#else /* !CONFIG_BT_MESH_RELAY_ADV_SETS */ +#else /* !CONFIG_BT_MESH_SIMULT_ADV_SETS */ return &adv_main; -#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */ +#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ } static inline struct bt_mesh_ext_adv *gatt_adv_get(void) @@ -234,20 +242,13 @@ static int buf_send(struct bt_mesh_ext_adv *adv, struct net_buf *buf) return err; } -static const char *adv_tag_to_str(enum bt_mesh_adv_tags tags) -{ - if (tags & BT_MESH_LOCAL_ADV_BIT) { - return "local adv"; - } else if (tags & BT_MESH_PROXY_ADV_BIT) { - return "proxy adv"; - } else if (tags & BT_MESH_RELAY_ADV_BIT) { - return "relay adv"; - } else if (tags & BT_MESH_FRIEND_ADV_BIT) { - return "friend adv"; - } else { - return "(unknown tags)"; - } -} +static const char * const adv_tag_to_str[] = { + [BT_MESH_ADV_TAG_LOCAL] = "local adv", + [BT_MESH_ADV_TAG_RELAY] = "relay adv", + [BT_MESH_ADV_TAG_PROXY] = "proxy adv", + [BT_MESH_ADV_TAG_FRIEND] = "friend adv", + [BT_MESH_ADV_TAG_PROV] = "prov adv", +}; static void send_pending_adv(struct k_work *work) { @@ -264,8 +265,9 @@ static void send_pending_adv(struct k_work *work) */ int64_t duration = k_uptime_delta(&adv->timestamp); - LOG_DBG("Advertising stopped after %u ms for (%u) %s", (uint32_t)duration, adv->tags, - adv_tag_to_str(adv->tags)); + LOG_DBG("Advertising stopped after %u ms for %s", (uint32_t)duration, + adv->buf ? adv_tag_to_str[BT_MESH_ADV(adv->buf)->tag] : + adv_tag_to_str[BT_MESH_ADV_TAG_PROXY]); atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); atomic_clear_bit(adv->flags, ADV_FLAG_PROXY); @@ -301,7 +303,7 @@ static void send_pending_adv(struct k_work *work) } if (!IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER) || - !(adv->tags & BT_MESH_RELAY_ADV_BIT)) { + !(adv->tags & BT_MESH_ADV_TAG_PROXY_BIT)) { return; } @@ -344,8 +346,9 @@ 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_FRIEND_ADV_BIT) || - (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && adv->tags & BT_MESH_RELAY_ADV_BIT)) { + 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)) { k_work_reschedule(&adv->work, K_NO_WAIT); } else { /* The controller will send the next advertisement immediately. @@ -369,11 +372,11 @@ void bt_mesh_adv_buf_local_ready(void) (void)schedule_send(&adv_main); } -void bt_mesh_adv_buf_relay_ready(void) +void bt_mesh_adv_buf_simult_ready(void) { struct bt_mesh_ext_adv *adv = relay_adv_get(); - for (int i = 0; i < CONFIG_BT_MESH_RELAY_ADV_SETS; i++) { + for (int i = 0; i < CONFIG_BT_MESH_SIMULT_ADV_SETS; i++) { if (schedule_send(&adv[i])) { return; } @@ -392,6 +395,36 @@ void bt_mesh_adv_buf_friend_ready(void) #endif } +void bt_mesh_adv_buf_terminate(struct net_buf *buf) +{ + int err; + + STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) { + if (adv->buf != buf) { + continue; + } + + if (!atomic_test_bit(adv->flags, ADV_FLAG_ACTIVE)) { + return; + } + + err = bt_le_ext_adv_stop(adv->instance); + if (err) { + LOG_ERR("Failed to stop adv %d", err); + return; + } + + /* Do not call `cb:end`, since this user action */ + BT_MESH_ADV(adv->buf)->cb = NULL; + + atomic_set_bit(adv->flags, ADV_FLAG_SENT); + + k_work_submit(&adv->work.work); + + break; + } +} + void bt_mesh_adv_init(void) { struct bt_le_adv_param adv_param = { diff --git a/subsys/bluetooth/mesh/adv_legacy.c b/subsys/bluetooth/mesh/adv_legacy.c index 8136aef9f22dd9..cb4028662f963d 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_relay_ready(void) +void bt_mesh_adv_buf_simult_ready(void) { /* Will be handled automatically */ } @@ -205,6 +205,12 @@ void bt_mesh_adv_gatt_update(void) bt_mesh_adv_buf_get_cancel(); } +void bt_mesh_adv_buf_terminate(struct net_buf *buf) +{ + /* todo */ + ARG_UNUSED(buf); +} + void bt_mesh_adv_init(void) { k_thread_create(&adv_thread_data, adv_thread_stack, diff --git a/subsys/bluetooth/mesh/beacon.c b/subsys/bluetooth/mesh/beacon.c index 8c0ac3b54e94bf..afdea5b4c6a15b 100644 --- a/subsys/bluetooth/mesh/beacon.c +++ b/subsys/bluetooth/mesh/beacon.c @@ -271,7 +271,7 @@ static bool net_beacon_send(struct bt_mesh_subnet *sub, struct bt_mesh_beacon *b return false; } - buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_LOCAL_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_ADV_TAG_LOCAL, PROV_XMIT, K_NO_WAIT); if (!buf) { LOG_ERR("Unable to allocate beacon buffer"); @@ -335,7 +335,7 @@ static int unprovisioned_beacon_send(void) LOG_DBG(""); - buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_LOCAL_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_ADV_TAG_LOCAL, UNPROV_XMIT, K_NO_WAIT); if (!buf) { LOG_ERR("Unable to allocate beacon buffer"); @@ -362,7 +362,7 @@ static int unprovisioned_beacon_send(void) if (prov->uri) { size_t len; - buf = bt_mesh_adv_create(BT_MESH_ADV_URI, BT_MESH_LOCAL_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_URI, BT_MESH_ADV_TAG_LOCAL, UNPROV_XMIT, K_NO_WAIT); if (!buf) { LOG_ERR("Unable to allocate URI buffer"); diff --git a/subsys/bluetooth/mesh/friend.c b/subsys/bluetooth/mesh/friend.c index 179755d9706b0f..73b75eadf4f988 100644 --- a/subsys/bluetooth/mesh/friend.c +++ b/subsys/bluetooth/mesh/friend.c @@ -1281,7 +1281,7 @@ static void friend_timeout(struct k_work *work) frnd->queue_size--; send_last: - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_FRIEND_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_FRIEND, FRIEND_XMIT, K_NO_WAIT); if (!buf) { LOG_ERR("Unable to allocate friend adv buffer"); diff --git a/subsys/bluetooth/mesh/net.c b/subsys/bluetooth/mesh/net.c index 2cfc709c6482da..61efaeb2c812d4 100644 --- a/subsys/bluetooth/mesh/net.c +++ b/subsys/bluetooth/mesh/net.c @@ -712,7 +712,7 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, transmit = bt_mesh_net_transmit_get(); } - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_RELAY_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_RELAY, transmit, K_NO_WAIT); if (!buf) { LOG_DBG("Out of relay buffers"); diff --git a/subsys/bluetooth/mesh/pb_adv.c b/subsys/bluetooth/mesh/pb_adv.c index 27d55763298efc..cb5f53f32b7e8c 100644 --- a/subsys/bluetooth/mesh/pb_adv.c +++ b/subsys/bluetooth/mesh/pb_adv.c @@ -55,11 +55,11 @@ LOG_MODULE_REGISTER(bt_mesh_pb_adv); /* Acked messages, will do retransmissions manually, taking acks into account: */ -#define RETRANSMITS_RELIABLE 0 +#define RETRANSMITS_RELIABLE CONFIG_BT_MESH_PB_ADV_TRANS_PDU_RETRANSMIT_COUNT /* PDU acks: */ -#define RETRANSMITS_ACK 2 +#define RETRANSMITS_ACK CONFIG_BT_MESH_PB_ADV_TRANS_ACK_RETRANSMIT_COUNT /* Link close retransmits: */ -#define RETRANSMITS_LINK_CLOSE 2 +#define RETRANSMITS_LINK_CLOSE CONFIG_BT_MESH_PB_ADV_LINK_CLOSE_RETRANSMIT_COUNT enum { ADV_LINK_ACTIVE, /* Link has been opened */ @@ -178,8 +178,15 @@ static void free_segments(void) } link.tx.buf[i] = NULL; - /* Mark as canceled */ - BT_MESH_ADV(buf)->busy = 0U; + + /* Terminate active adv */ + if (BT_MESH_ADV(buf)->busy == 0U) { + bt_mesh_adv_buf_terminate(buf); + } else { + /* Mark as canceled */ + BT_MESH_ADV(buf)->busy = 0U; + } + net_buf_unref(buf); } } @@ -251,7 +258,7 @@ static struct net_buf *adv_buf_create(uint8_t retransmits) { struct net_buf *buf; - buf = bt_mesh_adv_create(BT_MESH_ADV_PROV, BT_MESH_LOCAL_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_PROV, BT_MESH_ADV_TAG_PROV, BT_MESH_TRANSMIT(retransmits, 20), BUF_TIMEOUT); if (!buf) { diff --git a/subsys/bluetooth/mesh/statistic.c b/subsys/bluetooth/mesh/statistic.c index 046fa3c0eeb976..21c451bee73843 100644 --- a/subsys/bluetooth/mesh/statistic.c +++ b/subsys/bluetooth/mesh/statistic.c @@ -24,22 +24,22 @@ void bt_mesh_stat_reset(void) void bt_mesh_stat_planned_count(struct bt_mesh_adv *adv) { - if (adv->tag == BT_MESH_LOCAL_ADV) { + if (adv->tag == BT_MESH_ADV_TAG_LOCAL) { stat.tx_local_planned++; - } else if (adv->tag == BT_MESH_RELAY_ADV) { + } else if (adv->tag == BT_MESH_ADV_TAG_RELAY) { stat.tx_adv_relay_planned++; - } else if (adv->tag == BT_MESH_FRIEND_ADV) { + } else if (adv->tag == BT_MESH_ADV_TAG_FRIEND) { stat.tx_friend_planned++; } } void bt_mesh_stat_succeeded_count(struct bt_mesh_adv *adv) { - if (adv->tag == BT_MESH_LOCAL_ADV) { + if (adv->tag == BT_MESH_ADV_TAG_LOCAL) { stat.tx_local_succeeded++; - } else if (adv->tag == BT_MESH_RELAY_ADV) { + } else if (adv->tag == BT_MESH_ADV_TAG_RELAY) { stat.tx_adv_relay_succeeded++; - } else if (adv->tag == BT_MESH_FRIEND_ADV) { + } else if (adv->tag == BT_MESH_ADV_TAG_FRIEND) { stat.tx_friend_succeeded++; } } diff --git a/subsys/bluetooth/mesh/transport.c b/subsys/bluetooth/mesh/transport.c index 0343993e34865f..f4c49aa6856e95 100644 --- a/subsys/bluetooth/mesh/transport.c +++ b/subsys/bluetooth/mesh/transport.c @@ -124,7 +124,7 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, { struct net_buf *buf; - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, tx->xmit, BUF_TIMEOUT); if (!buf) { LOG_ERR("Out of network buffers"); @@ -414,7 +414,7 @@ static void seg_tx_send_unacked(struct seg_tx *tx) continue; } - seg = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + seg = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, tx->xmit, BUF_TIMEOUT); if (!seg) { LOG_DBG("Allocating segment failed"); diff --git a/subsys/bluetooth/mesh/transport_legacy.c b/subsys/bluetooth/mesh/transport_legacy.c index 475a0429f755ea..23e103b4370573 100644 --- a/subsys/bluetooth/mesh/transport_legacy.c +++ b/subsys/bluetooth/mesh/transport_legacy.c @@ -131,7 +131,7 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, { struct net_buf *buf; - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, tx->xmit, BUF_TIMEOUT); if (!buf) { LOG_ERR("Out of network buffers"); @@ -401,7 +401,7 @@ static void seg_tx_send_unacked(struct seg_tx *tx) continue; } - seg = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + seg = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, tx->xmit, BUF_TIMEOUT); if (!seg) { LOG_DBG("Allocating segment failed"); diff --git a/tests/bluetooth/mesh/basic/multi_ext_adv.conf b/tests/bluetooth/mesh/basic/multi_ext_adv.conf index 610318f847b685..0278bd557bd240 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_RELAY_ADV_SETS=1 +CONFIG_BT_MESH_SIMULT_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 70d3e2f4a17a83..603985afefc4e4 100644 --- a/tests/bsim/bluetooth/mesh/src/test_advertiser.c +++ b/tests/bsim/bluetooth/mesh/src/test_advertiser.c @@ -81,7 +81,7 @@ static void adv_init(void) static void allocate_all_array(struct net_buf **buf, size_t num_buf, uint8_t xmit) { for (int i = 0; i < num_buf; i++) { - *buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + *buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, xmit, K_NO_WAIT); ASSERT_FALSE_MSG(!*buf, "Out of buffers\n"); @@ -94,7 +94,7 @@ static void verify_adv_queue_overflow(void) struct net_buf *dummy_buf; /* Verity Queue overflow */ - dummy_buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + dummy_buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); ASSERT_TRUE_MSG(!dummy_buf, "Unexpected extra buffer\n"); } @@ -160,7 +160,7 @@ static void realloc_end_cb(int err, void *cb_data) struct net_buf *buf = (struct net_buf *)cb_data; ASSERT_EQUAL(0, err); - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); ASSERT_FALSE_MSG(!buf, "Out of buffers\n"); @@ -425,7 +425,7 @@ static void test_tx_cb_single(void) bt_init(); adv_init(); - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); ASSERT_FALSE_MSG(!buf, "Out of buffers\n"); @@ -530,7 +530,7 @@ static void test_tx_proxy_mixin(void) * Advertising the proxy service should be resumed after * finishing advertising the message. */ - struct net_buf *buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + struct net_buf *buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, BT_MESH_TRANSMIT(5, 20), K_NO_WAIT); net_buf_add_mem(buf, txt_msg, sizeof(txt_msg)); bt_mesh_adv_send(buf, NULL, NULL); @@ -636,16 +636,16 @@ static void test_tx_random_order(void) /* Verify random order calls */ num_adv_sent = ARRAY_SIZE(buf); previous_checker = 0xff; - buf[0] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + buf[0] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, xmit, K_NO_WAIT); - ASSERT_FALSE_MSG(!buf[0], "Out of buffers\n"); - buf[1] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + ASSERT_FALSE(!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"); send_adv_buf(buf[0], 0, 0xff); - buf[2] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_LOCAL_ADV, + buf[2] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, xmit, K_NO_WAIT); ASSERT_FALSE_MSG(!buf[2], "Out of buffers\n");