Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 38 additions & 59 deletions subsys/bluetooth/mesh/adv_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,70 +71,50 @@

static struct bt_mesh_ext_adv advs[] = {
[0] = {
.tags = (
#if !defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)
BT_MESH_ADV_TAG_BIT_FRIEND |
#endif
#if !defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE)
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_BIT_RELAY |
#endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */
#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_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_BIT_RELAY |
#endif /* CONFIG_BT_MESH_RELAY */
#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_INITIALIZER(send_pending_adv),
},
#endif /* CONFIG_BT_MESH_RELAY_ADV_SETS */
#if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)
{
.tags = BT_MESH_ADV_TAG_BIT_FRIEND,
.work = Z_WORK_INITIALIZER(send_pending_adv),
},
#endif /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */
#if defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE)
{
.tags = BT_MESH_ADV_TAG_BIT_PROXY,
.tags = (BT_MESH_ADV_TAG_BIT_LOCAL |
(IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)
? 0 : BT_MESH_ADV_TAG_BIT_FRIEND) |
(IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE)
? 0 : BT_MESH_ADV_TAG_BIT_PROXY) |
(IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET)
? BT_MESH_ADV_TAG_BIT_RELAY : 0) |
(IS_ENABLED(CONFIG_BT_MESH_PB_ADV)
? BT_MESH_ADV_TAG_BIT_PROV : 0)),
.work = Z_WORK_INITIALIZER(send_pending_adv),
},
#endif /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */
COND_CODE_0(CONFIG_BT_MESH_RELAY_ADV_SETS,

Check notice on line 85 in subsys/bluetooth/mesh/adv_ext.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/bluetooth/mesh/adv_ext.c:85 - [0] = { - .tags = (BT_MESH_ADV_TAG_BIT_LOCAL | + [0] = + { + .tags = (BT_MESH_ADV_TAG_BIT_LOCAL | (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) - ? 0 : BT_MESH_ADV_TAG_BIT_FRIEND) | + ? 0 + : BT_MESH_ADV_TAG_BIT_FRIEND) | (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) - ? 0 : BT_MESH_ADV_TAG_BIT_PROXY) | + ? 0 + : BT_MESH_ADV_TAG_BIT_PROXY) | (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET) - ? BT_MESH_ADV_TAG_BIT_RELAY : 0) | - (IS_ENABLED(CONFIG_BT_MESH_PB_ADV) - ? BT_MESH_ADV_TAG_BIT_PROV : 0)), - .work = Z_WORK_INITIALIZER(send_pending_adv), - }, + ? BT_MESH_ADV_TAG_BIT_RELAY + : 0) | + (IS_ENABLED(CONFIG_BT_MESH_PB_ADV) ? BT_MESH_ADV_TAG_BIT_PROV + : 0)), + .work = Z_WORK_INITIALIZER(send_pending_adv), + },
(), ([1 ... CONFIG_BT_MESH_RELAY_ADV_SETS] = {
.tags = (
(IS_ENABLED(CONFIG_BT_MESH_RELAY) ?
BT_MESH_ADV_TAG_BIT_RELAY : 0) |
(IS_ENABLED(CONFIG_BT_MESH_PB_ADV_USE_RELAY_SETS) ?
BT_MESH_ADV_TAG_BIT_PROV : 0)
),
.work = Z_WORK_INITIALIZER(send_pending_adv),
}))
COND_CODE_1(IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE),
({ .tags = BT_MESH_ADV_TAG_BIT_FRIEND,
.work = Z_WORK_INITIALIZER(send_pending_adv),
}), ())
COND_CODE_1(IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE),
({ .tags = BT_MESH_ADV_TAG_BIT_PROXY,
.work = Z_WORK_INITIALIZER(send_pending_adv),
}), ())
};

Check notice on line 104 in subsys/bluetooth/mesh/adv_ext.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/bluetooth/mesh/adv_ext.c:104 - COND_CODE_1(IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE), + COND_CODE_1(IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE), ({ .tags = BT_MESH_ADV_TAG_BIT_FRIEND, .work = Z_WORK_INITIALIZER(send_pending_adv), }), ()) - COND_CODE_1(IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE), + COND_CODE_1(IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE), ({ .tags = BT_MESH_ADV_TAG_BIT_PROXY, .work = Z_WORK_INITIALIZER(send_pending_adv), - }), ()) -}; + }), ()) };
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_RELAY_ADV_SETS)) {
return &advs[1];
} else {
return &advs[0];
}
return !!(CONFIG_BT_MESH_RELAY_ADV_SETS) ? &advs[1] : &advs[0];
Comment on lines -123 to +110
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, and this is also out of scope of the PR, since it's talking about replacing #if and not if ()

}

static inline struct bt_mesh_ext_adv *gatt_adv_get(void)
{
if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE)) {
return &advs[ARRAY_SIZE(advs) - 1];
} else {
return &advs[0];
}
return IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) ?
&advs[ARRAY_SIZE(advs) - 1] : &advs[0];
Comment on lines -132 to +116
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you're a fan of compact code, however I really don't think this improves readability. The C ternary operator is useful in places where you can't use if () however I don't think it improves readability at all (IMO it does the contrary).

}

Check notice on line 117 in subsys/bluetooth/mesh/adv_ext.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/bluetooth/mesh/adv_ext.c:117 - return IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) ? - &advs[ARRAY_SIZE(advs) - 1] : &advs[0]; + return IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE) ? &advs[ARRAY_SIZE(advs) - 1] + : &advs[0];

static int adv_start(struct bt_mesh_ext_adv *ext_adv,
const struct bt_le_adv_param *param,
Expand Down Expand Up @@ -233,14 +213,6 @@
return err;
}

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 bool schedule_send_with_mask(struct bt_mesh_ext_adv *ext_adv, int ignore_mask)
{
if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_PROXY)) {
Expand All @@ -265,6 +237,13 @@

static void send_pending_adv(struct k_work *work)
{
static const char * const adv_tag_to_str[] = {
[BT_MESH_ADV_TAG_LOCAL] = "local",
[BT_MESH_ADV_TAG_RELAY] = "relay",
[BT_MESH_ADV_TAG_PROXY] = "proxy",
[BT_MESH_ADV_TAG_FRIEND] = "friend",
[BT_MESH_ADV_TAG_PROV] = "prov",
};

Check notice on line 246 in subsys/bluetooth/mesh/adv_ext.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/bluetooth/mesh/adv_ext.c:246 - static const char * const adv_tag_to_str[] = { - [BT_MESH_ADV_TAG_LOCAL] = "local", - [BT_MESH_ADV_TAG_RELAY] = "relay", - [BT_MESH_ADV_TAG_PROXY] = "proxy", - [BT_MESH_ADV_TAG_FRIEND] = "friend", - [BT_MESH_ADV_TAG_PROV] = "prov", + static const char *const adv_tag_to_str[] = { + [BT_MESH_ADV_TAG_LOCAL] = "local", [BT_MESH_ADV_TAG_RELAY] = "relay", + [BT_MESH_ADV_TAG_PROXY] = "proxy", [BT_MESH_ADV_TAG_FRIEND] = "friend", + [BT_MESH_ADV_TAG_PROV] = "prov",
struct bt_mesh_ext_adv *ext_adv;
struct bt_mesh_adv *adv;
int err;
Expand All @@ -277,7 +256,7 @@
}

if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_SENT)) {
LOG_DBG("Advertising stopped after %u ms for %s",
LOG_DBG("Advertising stopped after %u ms for %s adv",
k_uptime_get_32() - ext_adv->timestamp,
ext_adv->adv ? adv_tag_to_str[ext_adv->adv->ctx.tag]
: adv_tag_to_str[BT_MESH_ADV_TAG_PROXY]);
Expand Down
Loading