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 <menglingao@xiaomi.com>
This commit is contained in:
Lingao Meng 2023-09-08 13:56:10 +08:00 committed by Carles Cufí
commit c2b2641fc1
10 changed files with 129 additions and 137 deletions

View file

@ -111,9 +111,6 @@ if(CONFIG_UVB)
zephyr_iterable_section(NAME uvb_node GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) zephyr_iterable_section(NAME uvb_node GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4)
endif() 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) if(CONFIG_LOG)
zephyr_iterable_section(NAME log_mpsc_pbuf GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4) zephyr_iterable_section(NAME log_mpsc_pbuf GROUP DATA_REGION ${XIP_ALIGN_WITH_INPUT} SUBALIGN 4)

View file

@ -12,10 +12,6 @@
#endif #endif
#endif /* NETWORKING */ #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) #if defined(CONFIG_GEN_SW_ISR_TABLE) && defined(CONFIG_DYNAMIC_INTERRUPTS)
SECTION_DATA_PROLOGUE(sw_isr_table,,) SECTION_DATA_PROLOGUE(sw_isr_table,,)
{ {

View file

@ -103,22 +103,22 @@ menuconfig BT_MESH_ADV_EXT
if BT_MESH_ADV_EXT if BT_MESH_ADV_EXT
config BT_MESH_SIMULT_ADV_SETS config BT_MESH_RELAY_ADV_SETS
int "Maximum number of parallel advertising sets that can be used by the Bluetooth Mesh stack" int "Maximum of simultaneous relay message support"
default 0 default 0
range 0 BT_EXT_ADV_MAX_ADV_SET range 0 BT_EXT_ADV_MAX_ADV_SET
depends on BT_MESH_RELAY || BT_MESH_PB_ADV depends on BT_MESH_RELAY
help help
Maximum of simultaneous message support. Requires controller support Maximum of simultaneous relay message support. Requires controller support
multiple advertising sets. multiple advertising sets.
config BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET config BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET
bool "Use the main advertising set to relay messages" 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 help
When this option is enabled, there is a message that needs to be When this option is enabled, there is a message that needs to be
relayed, all relay advertising sets defined by 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 and the main advertising set is not busy with sending local
messages, the stack will use the main advertising set to relay messages, the stack will use the main advertising set to relay
the message. This maximizes the utilization efficiency of the message. This maximizes the utilization efficiency of
@ -192,16 +192,15 @@ config BT_MESH_UNPROV_BEACON_INT
if BT_MESH_PB_ADV if BT_MESH_PB_ADV
config BT_MESH_PB_ADV_RETRANS_TIMEOUT config BT_MESH_PB_ADV_USE_RELAY_SETS
int "Timeout value of retransmit provisioning PDUs" bool "Use relay advertising sets to send provisioning PDUs"
default 500 depends on BT_MESH_RELAY_ADV_SETS > 0
range 100 800
help help
Timeout value of retransmit provisioning PDUs. Use relay advertising sets to send provisioning PDUs
config BT_MESH_PB_ADV_TRANS_PDU_RETRANSMIT_COUNT config BT_MESH_PB_ADV_TRANS_PDU_RETRANSMIT_COUNT
int "Link Open and Transaction 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 default 0
range 0 7 range 0 7
help help
@ -210,21 +209,28 @@ config BT_MESH_PB_ADV_TRANS_PDU_RETRANSMIT_COUNT
config BT_MESH_PB_ADV_TRANS_ACK_RETRANSMIT_COUNT config BT_MESH_PB_ADV_TRANS_ACK_RETRANSMIT_COUNT
int "Link Ack and Transaction Ack retransmit count" int "Link Ack and Transaction Ack retransmit count"
default 0 default 2
range 0 7 range 0 7
help 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. in addition to the first transmission.
config BT_MESH_PB_ADV_LINK_CLOSE_RETRANSMIT_COUNT config BT_MESH_PB_ADV_LINK_CLOSE_RETRANSMIT_COUNT
int "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 default 2
range 0 7 range 0 7
help help
Controls the number of retransmissions of original Link Close, Controls the number of retransmissions of original Link Close,
in addition to the first transmission. 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 endif # BT_MESH_PB_ADV
if BT_CONN if BT_CONN
@ -401,7 +407,7 @@ config BT_MESH_RELAY_BUF_COUNT
of packet drops. When considering the message latency, also consider of packet drops. When considering the message latency, also consider
the values of BT_MESH_RELAY_RETRANSMIT_COUNT and the values of BT_MESH_RELAY_RETRANSMIT_COUNT and
BT_MESH_RELAY_RETRANSMIT_INTERVAL. A higher number of 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. while maintaining the latency.
endif # BT_MESH_RELAY endif # BT_MESH_RELAY

View file

@ -44,7 +44,7 @@ const uint8_t bt_mesh_adv_type[BT_MESH_ADV_TYPES] = {
static bool active_scanning; static bool active_scanning;
static K_FIFO_DEFINE(bt_mesh_adv_queue); 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); static K_FIFO_DEFINE(bt_mesh_friend_queue);
void bt_mesh_adv_send_start(uint16_t duration, int err, struct bt_mesh_adv *adv) 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); 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) static struct net_buf *process_events(struct k_poll_event *ev, int count)
{ {
for (; count; ev++, 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) #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_EVENT_STATIC_INITIALIZER(K_POLL_TYPE_FIFO_DATA_AVAILABLE,
K_POLL_MODE_NOTIFY_ONLY, K_POLL_MODE_NOTIFY_ONLY,
&bt_mesh_simult_queue, &bt_mesh_relay_queue,
0), 0),
#endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */ #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)); 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) && 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); return net_buf_get(&bt_mesh_friend_queue, timeout);
} }
if (tags & BT_MESH_ADV_TAG_LOCAL_BIT) { #if CONFIG_BT_MESH_RELAY_ADV_SETS
return bt_mesh_adv_buf_get(timeout); 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 #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) struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout)
{ {
return net_buf_get(&bt_mesh_adv_queue, 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); ARG_UNUSED(tags);
return bt_mesh_adv_buf_get(timeout); 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) 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); k_fifo_cancel_wait(&bt_mesh_adv_queue);
#if CONFIG_BT_MESH_SIMULT_ADV_SETS #if CONFIG_BT_MESH_RELAY_ADV_SETS
k_fifo_cancel_wait(&bt_mesh_simult_queue); k_fifo_cancel_wait(&bt_mesh_relay_queue);
#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ #endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */
if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)) { if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)) {
k_fifo_cancel_wait(&bt_mesh_friend_queue); 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; 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 || if (BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_RELAY ||
BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_PROV) { (IS_ENABLED(CONFIG_BT_MESH_PB_ADV_USE_RELAY_SETS) &&
net_buf_put(&bt_mesh_simult_queue, net_buf_ref(buf)); BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_PROV)) {
bt_mesh_adv_buf_simult_ready(); net_buf_put(&bt_mesh_relay_queue, net_buf_ref(buf));
bt_mesh_adv_buf_relay_ready();
return; return;
} }
#endif #endif

View file

@ -33,12 +33,12 @@ enum bt_mesh_adv_tag {
BT_MESH_ADV_TAG_PROV, BT_MESH_ADV_TAG_PROV,
}; };
enum bt_mesh_adv_tags { enum bt_mesh_adv_tag_bit {
BT_MESH_ADV_TAG_LOCAL_BIT = BIT(BT_MESH_ADV_TAG_LOCAL), BT_MESH_ADV_TAG_BIT_LOCAL = BIT(BT_MESH_ADV_TAG_LOCAL),
BT_MESH_ADV_TAG_RELAY_BIT = BIT(BT_MESH_ADV_TAG_RELAY), BT_MESH_ADV_TAG_BIT_RELAY = BIT(BT_MESH_ADV_TAG_RELAY),
BT_MESH_ADV_TAG_PROXY_BIT = BIT(BT_MESH_ADV_TAG_PROXY), BT_MESH_ADV_TAG_BIT_PROXY = BIT(BT_MESH_ADV_TAG_PROXY),
BT_MESH_ADV_TAG_FRIEND_BIT = BIT(BT_MESH_ADV_TAG_FRIEND), BT_MESH_ADV_TAG_BIT_FRIEND = BIT(BT_MESH_ADV_TAG_FRIEND),
BT_MESH_ADV_TAG_PROV_BIT = BIT(BT_MESH_ADV_TAG_PROV), BT_MESH_ADV_TAG_BIT_PROV = BIT(BT_MESH_ADV_TAG_PROV),
}; };
struct bt_mesh_adv { 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(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); 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_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); void bt_mesh_adv_buf_friend_ready(void);

View file

@ -30,8 +30,8 @@ LOG_MODULE_REGISTER(bt_mesh_adv_ext);
/* Convert from ms to 0.625ms units */ /* Convert from ms to 0.625ms units */
#define ADV_INT_FAST_MS 20 #define ADV_INT_FAST_MS 20
#ifndef CONFIG_BT_MESH_SIMULT_ADV_SETS #ifndef CONFIG_BT_MESH_RELAY_ADV_SETS
#define CONFIG_BT_MESH_SIMULT_ADV_SETS 0 #define CONFIG_BT_MESH_RELAY_ADV_SETS 0
#endif #endif
enum { enum {
@ -57,7 +57,7 @@ enum {
}; };
struct bt_mesh_ext_adv { 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); ATOMIC_DEFINE(flags, ADV_FLAGS_NUM);
struct bt_le_ext_adv *instance; struct bt_le_ext_adv *instance;
struct net_buf *buf; struct net_buf *buf;
@ -69,80 +69,71 @@ struct bt_mesh_ext_adv {
static void send_pending_adv(struct k_work *work); static void send_pending_adv(struct k_work *work);
static bool schedule_send(struct bt_mesh_ext_adv *adv); static bool schedule_send(struct bt_mesh_ext_adv *adv);
static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_main) = { static struct bt_mesh_ext_adv advs[] = {
.tags = ( [0] = {
.tags = (
#if !defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) #if !defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)
BT_MESH_ADV_TAG_FRIEND_BIT | BT_MESH_ADV_TAG_BIT_FRIEND |
#endif #endif
#if !defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) #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 */ #endif /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */
#if defined(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET) #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 */ #endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */
BT_MESH_ADV_TAG_LOCAL_BIT), #if defined(CONFIG_BT_MESH_PB_ADV)
BT_MESH_ADV_TAG_BIT_PROV |
.work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), #endif /* CONFIG_BT_MESH_PB_ADV */
}; BT_MESH_ADV_TAG_BIT_LOCAL
),
#if CONFIG_BT_MESH_SIMULT_ADV_SETS .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv),
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 CONFIG_BT_MESH_RELAY_ADV_SETS
[1 ... CONFIG_BT_MESH_RELAY_ADV_SETS] = {
.tags = ( .tags = (
#if defined(CONFIG_BT_MESH_RELAY) #if defined(CONFIG_BT_MESH_RELAY)
BT_MESH_ADV_TAG_RELAY_BIT | BT_MESH_ADV_TAG_BIT_RELAY |
#endif /* CONFIG_BT_MESH_RELAY */ #endif /* CONFIG_BT_MESH_RELAY */
#if defined(CONFIG_BT_MESH_PB_ADV) #if defined(CONFIG_BT_MESH_PB_ADV_USE_RELAY_SETS)
BT_MESH_ADV_TAG_PROV_BIT | BT_MESH_ADV_TAG_BIT_PROV |
#endif /* CONFIG_BT_MESH_PB_ADV */ #endif /* CONFIG_BT_MESH_PB_ADV_USE_RELAY_SETS */
0), 0),
.work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), .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) #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_BIT_FRIEND,
.tags = BT_MESH_ADV_TAG_FRIEND_BIT, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv),
.work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv), },
};
#else /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */
#define ADV_EXT_FRIEND 0
#endif /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */ #endif /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */
#if defined(CONFIG_BT_MESH_ADV_EXT_GATT_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_BIT_PROXY,
.tags = BT_MESH_ADV_TAG_PROXY_BIT, .work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv),
.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 */ #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(ARRAY_SIZE(advs) <= CONFIG_BT_EXT_ADV_MAX_ADV_SET,
BUILD_ASSERT(CONFIG_BT_EXT_ADV_MAX_ADV_SET >= BT_MESH_ADV_COUNT,
"Insufficient adv instances"); "Insufficient adv instances");
static inline struct bt_mesh_ext_adv *relay_adv_get(void) static inline struct bt_mesh_ext_adv *relay_adv_get(void)
{ {
#if CONFIG_BT_MESH_SIMULT_ADV_SETS if (!!(CONFIG_BT_MESH_RELAY_ADV_SETS)) {
return adv_relay; return &advs[1];
#else /* !CONFIG_BT_MESH_SIMULT_ADV_SETS */ } else {
return &adv_main; return &advs[0];
#endif /* CONFIG_BT_MESH_SIMULT_ADV_SETS */ }
} }
static inline struct bt_mesh_ext_adv *gatt_adv_get(void) static inline struct bt_mesh_ext_adv *gatt_adv_get(void)
{ {
#if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE)) {
return &adv_gatt; return &advs[ARRAY_SIZE(advs) - 1];
#else /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ } else {
return &adv_main; return &advs[0];
#endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */ }
} }
static int adv_start(struct bt_mesh_ext_adv *adv, 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) || 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; return;
} }
@ -347,8 +338,8 @@ static bool schedule_send(struct bt_mesh_ext_adv *adv)
atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULE_PENDING); atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULE_PENDING);
if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && if ((IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) &&
adv->tags & BT_MESH_ADV_TAG_FRIEND_BIT) || adv->tags & BT_MESH_ADV_TAG_BIT_FRIEND) ||
(CONFIG_BT_MESH_SIMULT_ADV_SETS > 0 && adv->tags & BT_MESH_ADV_TAG_RELAY_BIT)) { (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && adv->tags & BT_MESH_ADV_TAG_BIT_RELAY)) {
k_work_reschedule(&adv->work, K_NO_WAIT); k_work_reschedule(&adv->work, K_NO_WAIT);
} else { } else {
/* The controller will send the next advertisement immediately. /* 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 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(); 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])) { if (schedule_send(&adv[i])) {
return; 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. */ /* 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)) { 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) void bt_mesh_adv_buf_friend_ready(void)
{ {
#if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)) {
(void)schedule_send(&adv_friend); schedule_send(&advs[1 + CONFIG_BT_MESH_RELAY_ADV_SETS]);
#endif } 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; 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) { if (adv->buf != buf) {
continue; continue;
} }
@ -421,7 +416,7 @@ void bt_mesh_adv_buf_terminate(struct net_buf *buf)
k_work_submit(&adv->work.work); 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) #if defined(CONFIG_BT_MESH_DEBUG_USE_ID_ADDR)
.options = BT_LE_ADV_OPT_USE_IDENTITY, .options = BT_LE_ADV_OPT_USE_IDENTITY,
#endif #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) static struct bt_mesh_ext_adv *adv_instance_find(struct bt_le_ext_adv *instance)
{ {
STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) { for (int i = 0; i < ARRAY_SIZE(advs); i++) {
if (adv->instance == instance) { if (advs[i].instance == instance) {
return adv; return &advs[i];
} }
} }
@ -494,15 +490,14 @@ int bt_mesh_adv_enable(void)
#endif /* CONFIG_BT_MESH_GATT_SERVER */ #endif /* CONFIG_BT_MESH_GATT_SERVER */
}; };
if (adv_main.instance) { if (advs[0].instance) {
/* Already initialized */ /* Already initialized */
return 0; return 0;
} }
for (int i = 0; i < ARRAY_SIZE(advs); i++) {
STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) { err = bt_le_ext_adv_create(&advs[i].adv_param, &adv_cb,
err = bt_le_ext_adv_create(&adv->adv_param, &adv_cb, &advs[i].instance);
&adv->instance);
if (err) { if (err) {
return 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, int bt_mesh_adv_bt_data_send(uint8_t num_events, uint16_t adv_interval,
const struct bt_data *ad, size_t ad_len) 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);
} }

View file

@ -195,7 +195,7 @@ void bt_mesh_adv_buf_local_ready(void)
/* Will be handled automatically */ /* Will be handled automatically */
} }
void bt_mesh_adv_buf_simult_ready(void) void bt_mesh_adv_buf_relay_ready(void)
{ {
/* Will be handled automatically */ /* Will be handled automatically */
} }
@ -205,9 +205,8 @@ void bt_mesh_adv_gatt_update(void)
bt_mesh_adv_buf_get_cancel(); 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); ARG_UNUSED(buf);
} }

View file

@ -20,8 +20,6 @@
#include "common/bt_str.h" #include "common/bt_str.h"
#include "host/long_wq.h"
#include "crypto.h" #include "crypto.h"
#include "adv.h" #include "adv.h"
#include "mesh.h" #include "mesh.h"

View file

@ -51,5 +51,5 @@ CONFIG_BT_MESH_CRYPTO_LOG_LEVEL_DBG=y
CONFIG_BT_MESH_ADV_LOG_LEVEL_DBG=y CONFIG_BT_MESH_ADV_LOG_LEVEL_DBG=y
CONFIG_BT_EXT_ADV_MAX_ADV_SET=3 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 CONFIG_BT_MESH_ADV_EXT=y

View file

@ -638,7 +638,7 @@ static void test_tx_random_order(void)
previous_checker = 0xff; previous_checker = 0xff;
buf[0] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, buf[0] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL,
xmit, K_NO_WAIT); 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, buf[1] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL,
xmit, K_NO_WAIT); xmit, K_NO_WAIT);
ASSERT_FALSE_MSG(!buf[1], "Out of buffers\n"); ASSERT_FALSE_MSG(!buf[1], "Out of buffers\n");