Bluetooth: Mesh: Add common section for ext_adv
Use section for omit macro config. Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
This commit is contained in:
parent
414250106f
commit
aeb12304b3
2 changed files with 38 additions and 72 deletions
|
@ -10,6 +10,10 @@
|
||||||
#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,,)
|
||||||
{
|
{
|
||||||
|
|
|
@ -42,7 +42,7 @@ enum {
|
||||||
ADV_FLAGS_NUM
|
ADV_FLAGS_NUM
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ext_adv {
|
struct bt_mesh_ext_adv {
|
||||||
uint8_t tag;
|
uint8_t tag;
|
||||||
ATOMIC_DEFINE(flags, ADV_FLAGS_NUM);
|
ATOMIC_DEFINE(flags, ADV_FLAGS_NUM);
|
||||||
struct bt_le_ext_adv *instance;
|
struct bt_le_ext_adv *instance;
|
||||||
|
@ -53,7 +53,8 @@ struct ext_adv {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void send_pending_adv(struct k_work *work);
|
static void send_pending_adv(struct k_work *work);
|
||||||
static struct ext_adv adv_main = {
|
|
||||||
|
static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_main) = {
|
||||||
.tag = (BT_MESH_LOCAL_ADV |
|
.tag = (BT_MESH_LOCAL_ADV |
|
||||||
#if !defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE)
|
#if !defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE)
|
||||||
BT_MESH_PROXY_ADV |
|
BT_MESH_PROXY_ADV |
|
||||||
|
@ -61,29 +62,13 @@ static struct ext_adv adv_main = {
|
||||||
BT_MESH_RELAY_ADV),
|
BT_MESH_RELAY_ADV),
|
||||||
|
|
||||||
.work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv),
|
.work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv),
|
||||||
.adv_param = {
|
|
||||||
.id = BT_ID_DEFAULT,
|
|
||||||
.interval_min = BT_MESH_ADV_SCAN_UNIT(ADV_INT_FAST_MS),
|
|
||||||
.interval_max = BT_MESH_ADV_SCAN_UNIT(ADV_INT_FAST_MS),
|
|
||||||
#if defined(CONFIG_BT_MESH_DEBUG_USE_ID_ADDR)
|
|
||||||
.options = BT_LE_ADV_OPT_USE_IDENTITY,
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#if CONFIG_BT_MESH_RELAY_ADV_SETS
|
#if CONFIG_BT_MESH_RELAY_ADV_SETS
|
||||||
static struct ext_adv adv_relay[CONFIG_BT_MESH_RELAY_ADV_SETS] = {
|
static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_relay[CONFIG_BT_MESH_RELAY_ADV_SETS]) = {
|
||||||
[0 ... CONFIG_BT_MESH_RELAY_ADV_SETS - 1] = {
|
[0 ... CONFIG_BT_MESH_RELAY_ADV_SETS - 1] = {
|
||||||
.tag = BT_MESH_RELAY_ADV,
|
.tag = BT_MESH_RELAY_ADV,
|
||||||
.work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv),
|
.work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv),
|
||||||
.adv_param = {
|
|
||||||
.id = BT_ID_DEFAULT,
|
|
||||||
.interval_min = BT_MESH_ADV_SCAN_UNIT(ADV_INT_FAST_MS),
|
|
||||||
.interval_max = BT_MESH_ADV_SCAN_UNIT(ADV_INT_FAST_MS),
|
|
||||||
#if defined(CONFIG_BT_MESH_DEBUG_USE_ID_ADDR)
|
|
||||||
.options = BT_LE_ADV_OPT_USE_IDENTITY,
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#define BT_MESH_RELAY_ADV_INS (adv_relay)
|
#define BT_MESH_RELAY_ADV_INS (adv_relay)
|
||||||
|
@ -93,17 +78,9 @@ static struct ext_adv adv_relay[CONFIG_BT_MESH_RELAY_ADV_SETS] = {
|
||||||
|
|
||||||
#if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE)
|
#if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE)
|
||||||
#define BT_MESH_ADV_COUNT (1 + CONFIG_BT_MESH_RELAY_ADV_SETS + 1)
|
#define BT_MESH_ADV_COUNT (1 + CONFIG_BT_MESH_RELAY_ADV_SETS + 1)
|
||||||
static struct ext_adv adv_gatt = {
|
static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_gatt) = {
|
||||||
.tag = BT_MESH_PROXY_ADV,
|
.tag = BT_MESH_PROXY_ADV,
|
||||||
.work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv),
|
.work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv),
|
||||||
.adv_param = {
|
|
||||||
.id = BT_ID_DEFAULT,
|
|
||||||
.interval_min = BT_MESH_ADV_SCAN_UNIT(ADV_INT_FAST_MS),
|
|
||||||
.interval_max = BT_MESH_ADV_SCAN_UNIT(ADV_INT_FAST_MS),
|
|
||||||
#if defined(CONFIG_BT_MESH_DEBUG_USE_ID_ADDR)
|
|
||||||
.options = BT_LE_ADV_OPT_USE_IDENTITY,
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
#define BT_MESH_ADV_EXT_GATT_SEPARATE_INS (&adv_gatt)
|
#define BT_MESH_ADV_EXT_GATT_SEPARATE_INS (&adv_gatt)
|
||||||
#elif defined(CONFIG_BT_MESH_GATT_SERVER)
|
#elif defined(CONFIG_BT_MESH_GATT_SERVER)
|
||||||
|
@ -111,13 +88,13 @@ static struct ext_adv adv_gatt = {
|
||||||
#define BT_MESH_ADV_EXT_GATT_SEPARATE_INS (&adv_main)
|
#define BT_MESH_ADV_EXT_GATT_SEPARATE_INS (&adv_main)
|
||||||
#else /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */
|
#else /* !CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */
|
||||||
#define BT_MESH_ADV_COUNT (1 + CONFIG_BT_MESH_RELAY_ADV_SETS)
|
#define BT_MESH_ADV_COUNT (1 + CONFIG_BT_MESH_RELAY_ADV_SETS)
|
||||||
#define BT_MESH_ADV_EXT_GATT_SEPARATE_INS (struct ext_adv)NULL
|
#define BT_MESH_ADV_EXT_GATT_SEPARATE_INS (struct bt_mesh_ext_adv)NULL
|
||||||
#endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */
|
#endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */
|
||||||
|
|
||||||
BUILD_ASSERT(CONFIG_BT_EXT_ADV_MAX_ADV_SET >= BT_MESH_ADV_COUNT,
|
BUILD_ASSERT(CONFIG_BT_EXT_ADV_MAX_ADV_SET >= BT_MESH_ADV_COUNT,
|
||||||
"Insufficient adv instances");
|
"Insufficient adv instances");
|
||||||
|
|
||||||
static int adv_start(struct ext_adv *adv,
|
static int adv_start(struct bt_mesh_ext_adv *adv,
|
||||||
const struct bt_le_adv_param *param,
|
const struct bt_le_adv_param *param,
|
||||||
struct bt_le_ext_adv_start_param *start,
|
struct bt_le_ext_adv_start_param *start,
|
||||||
const struct bt_data *ad, size_t ad_len,
|
const struct bt_data *ad, size_t ad_len,
|
||||||
|
@ -165,7 +142,7 @@ static int adv_start(struct ext_adv *adv,
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int buf_send(struct ext_adv *adv, struct net_buf *buf)
|
static int buf_send(struct bt_mesh_ext_adv *adv, struct net_buf *buf)
|
||||||
{
|
{
|
||||||
struct bt_le_ext_adv_start_param start = {
|
struct bt_le_ext_adv_start_param start = {
|
||||||
.num_events =
|
.num_events =
|
||||||
|
@ -209,10 +186,11 @@ static int buf_send(struct ext_adv *adv, struct net_buf *buf)
|
||||||
|
|
||||||
static void send_pending_adv(struct k_work *work)
|
static void send_pending_adv(struct k_work *work)
|
||||||
{
|
{
|
||||||
struct ext_adv *adv = CONTAINER_OF(work, struct ext_adv, work.work);
|
struct bt_mesh_ext_adv *adv;
|
||||||
struct net_buf *buf;
|
struct net_buf *buf;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
adv = CONTAINER_OF(work, struct bt_mesh_ext_adv, work.work);
|
||||||
atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULED);
|
atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULED);
|
||||||
|
|
||||||
while ((buf = bt_mesh_adv_buf_get_by_tag(adv->tag, K_NO_WAIT))) {
|
while ((buf = bt_mesh_adv_buf_get_by_tag(adv->tag, K_NO_WAIT))) {
|
||||||
|
@ -240,7 +218,7 @@ static void send_pending_adv(struct k_work *work)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool schedule_send(struct ext_adv *adv)
|
static bool schedule_send(struct bt_mesh_ext_adv *adv)
|
||||||
{
|
{
|
||||||
uint64_t timestamp;
|
uint64_t timestamp;
|
||||||
int64_t delta;
|
int64_t delta;
|
||||||
|
@ -294,27 +272,26 @@ void bt_mesh_adv_buf_relay_ready(void)
|
||||||
|
|
||||||
void bt_mesh_adv_init(void)
|
void bt_mesh_adv_init(void)
|
||||||
{
|
{
|
||||||
}
|
struct bt_le_adv_param adv_param = {
|
||||||
|
.id = BT_ID_DEFAULT,
|
||||||
static struct ext_adv *adv_instance_find(struct bt_le_ext_adv *instance)
|
.interval_min = BT_MESH_ADV_SCAN_UNIT(ADV_INT_FAST_MS),
|
||||||
{
|
.interval_max = BT_MESH_ADV_SCAN_UNIT(ADV_INT_FAST_MS),
|
||||||
if (adv_main.instance == instance) {
|
#if defined(CONFIG_BT_MESH_DEBUG_USE_ID_ADDR)
|
||||||
return &adv_main;
|
.options = BT_LE_ADV_OPT_USE_IDENTITY,
|
||||||
}
|
|
||||||
|
|
||||||
#if CONFIG_BT_MESH_RELAY_ADV_SETS
|
|
||||||
for (int i = 0; i < ARRAY_SIZE(adv_relay); i++) {
|
|
||||||
if (adv_relay[i].instance == instance) {
|
|
||||||
return &adv_relay[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */
|
|
||||||
|
|
||||||
#if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE)
|
|
||||||
if (adv_gatt.instance == instance) {
|
|
||||||
return &adv_gatt;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
};
|
||||||
|
STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) {
|
||||||
|
(void)memcpy(&adv->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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -322,7 +299,7 @@ static struct ext_adv *adv_instance_find(struct bt_le_ext_adv *instance)
|
||||||
static void adv_sent(struct bt_le_ext_adv *instance,
|
static void adv_sent(struct bt_le_ext_adv *instance,
|
||||||
struct bt_le_ext_adv_sent_info *info)
|
struct bt_le_ext_adv_sent_info *info)
|
||||||
{
|
{
|
||||||
struct ext_adv *adv = adv_instance_find(instance);
|
struct bt_mesh_ext_adv *adv = adv_instance_find(instance);
|
||||||
|
|
||||||
if (!adv) {
|
if (!adv) {
|
||||||
BT_WARN("Unexpected adv instance");
|
BT_WARN("Unexpected adv instance");
|
||||||
|
@ -350,7 +327,7 @@ static void adv_sent(struct bt_le_ext_adv *instance,
|
||||||
static void connected(struct bt_le_ext_adv *instance,
|
static void connected(struct bt_le_ext_adv *instance,
|
||||||
struct bt_le_ext_adv_connected_info *info)
|
struct bt_le_ext_adv_connected_info *info)
|
||||||
{
|
{
|
||||||
struct ext_adv *adv = BT_MESH_ADV_EXT_GATT_SEPARATE_INS;
|
struct bt_mesh_ext_adv *adv = BT_MESH_ADV_EXT_GATT_SEPARATE_INS;
|
||||||
|
|
||||||
if (atomic_test_and_clear_bit(adv->flags, ADV_FLAG_PROXY)) {
|
if (atomic_test_and_clear_bit(adv->flags, ADV_FLAG_PROXY)) {
|
||||||
atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE);
|
atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE);
|
||||||
|
@ -376,38 +353,23 @@ int bt_mesh_adv_enable(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
err = bt_le_ext_adv_create(&adv_main.adv_param, &adv_cb,
|
STRUCT_SECTION_FOREACH(bt_mesh_ext_adv, adv) {
|
||||||
&adv_main.instance);
|
err = bt_le_ext_adv_create(&adv->adv_param, &adv_cb,
|
||||||
if (err) {
|
&adv->instance);
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if CONFIG_BT_MESH_RELAY_ADV_SETS
|
|
||||||
for (int i = 0; i < CONFIG_BT_MESH_RELAY_ADV_SETS; i++) {
|
|
||||||
err = bt_le_ext_adv_create(&adv_relay[i].adv_param, &adv_cb,
|
|
||||||
&adv_relay[i].instance);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */
|
|
||||||
|
|
||||||
#if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE)
|
|
||||||
err = bt_le_ext_adv_create(&adv_gatt.adv_param, &adv_cb,
|
|
||||||
&adv_gatt.instance);
|
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
#endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bt_mesh_adv_gatt_start(const struct bt_le_adv_param *param, int32_t duration,
|
int bt_mesh_adv_gatt_start(const struct bt_le_adv_param *param,
|
||||||
|
int32_t duration,
|
||||||
const struct bt_data *ad, size_t ad_len,
|
const struct bt_data *ad, size_t ad_len,
|
||||||
const struct bt_data *sd, size_t sd_len)
|
const struct bt_data *sd, size_t sd_len)
|
||||||
{
|
{
|
||||||
struct ext_adv *adv = BT_MESH_ADV_EXT_GATT_SEPARATE_INS;
|
struct bt_mesh_ext_adv *adv = BT_MESH_ADV_EXT_GATT_SEPARATE_INS;
|
||||||
struct bt_le_ext_adv_start_param start = {
|
struct bt_le_ext_adv_start_param start = {
|
||||||
/* Timeout is set in 10 ms steps, with 0 indicating "forever" */
|
/* Timeout is set in 10 ms steps, with 0 indicating "forever" */
|
||||||
.timeout = (duration == SYS_FOREVER_MS) ? 0 : (duration / 10),
|
.timeout = (duration == SYS_FOREVER_MS) ? 0 : (duration / 10),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue