Skip to content

Commit

Permalink
[nrf fromlist] Bluetooth: Mesh: Remove bits for adv tag
Browse files Browse the repository at this point in the history
since tag for buf single only, no need for bit, also for
save some memory for rfu.

Upstream PR: zephyrproject-rtos/zephyr#62331
Signed-off-by: Lingao Meng <[email protected]>
(cherry picked from commit b14d235)
  • Loading branch information
LingaoM authored and nordicjm committed Nov 13, 2023
1 parent 9ed7de1 commit 2c3b9c4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 39 deletions.
14 changes: 7 additions & 7 deletions subsys/bluetooth/mesh/adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ 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_RELAY_ADV) {
return bt_mesh_adv_create_from_pool(&relay_buf_pool,
adv_relay_pool, type,
tag, xmit, timeout);
}
#endif

#if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)
if (tag & BT_MESH_FRIEND_ADV) {
if (tag == BT_MESH_FRIEND_ADV) {
return bt_mesh_adv_create_from_pool(&friend_buf_pool,
adv_friend_pool, type,
tag, xmit, timeout);
Expand Down Expand Up @@ -202,14 +202,14 @@ 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(uint8_t tag, 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) && tag & BT_MESH_FRIEND_ADV) {
if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && tags & BT_MESH_FRIEND_ADV_BIT) {
return net_buf_get(&bt_mesh_friend_queue, timeout);
}

#if CONFIG_BT_MESH_RELAY_ADV_SETS
if (tag & BT_MESH_RELAY_ADV) {
if (tags & BT_MESH_RELAY_ADV_BIT) {
return net_buf_get(&bt_mesh_relay_queue, timeout);
}
#endif
Expand All @@ -222,9 +222,9 @@ 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(uint8_t tag, k_timeout_t timeout)
struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout)
{
ARG_UNUSED(tag);
ARG_UNUSED(tags);

return bt_mesh_adv_buf_get(timeout);
}
Expand Down
17 changes: 12 additions & 5 deletions subsys/bluetooth/mesh/adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ enum bt_mesh_adv_type {
};

enum bt_mesh_adv_tag {
BT_MESH_LOCAL_ADV = BIT(0),
BT_MESH_RELAY_ADV = BIT(1),
BT_MESH_PROXY_ADV = BIT(2),
BT_MESH_FRIEND_ADV = BIT(3),
BT_MESH_LOCAL_ADV,
BT_MESH_RELAY_ADV,
BT_MESH_PROXY_ADV,
BT_MESH_FRIEND_ADV,
};

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),
};

struct bt_mesh_adv {
Expand Down Expand Up @@ -57,7 +64,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(uint8_t tag, k_timeout_t timeout);
struct net_buf *bt_mesh_adv_buf_get_by_tag(enum bt_mesh_adv_tags tags, k_timeout_t timeout);

void bt_mesh_adv_gatt_update(void);

Expand Down
42 changes: 21 additions & 21 deletions subsys/bluetooth/mesh/adv_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ enum {
};

struct bt_mesh_ext_adv {
uint8_t tag;
enum bt_mesh_adv_tags tags;
ATOMIC_DEFINE(flags, ADV_FLAGS_NUM);
struct bt_le_ext_adv *instance;
struct net_buf *buf;
Expand All @@ -73,25 +73,25 @@ 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) = {
.tag = (
.tags = (
#if !defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)
BT_MESH_FRIEND_ADV |
BT_MESH_FRIEND_ADV_BIT |
#endif
#if !defined(CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE)
BT_MESH_PROXY_ADV |
BT_MESH_PROXY_ADV_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 |
BT_MESH_RELAY_ADV_BIT |
#endif /* CONFIG_BT_MESH_ADV_EXT_RELAY_USING_MAIN_ADV_SET */
BT_MESH_LOCAL_ADV),
BT_MESH_LOCAL_ADV_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] = {
.tag = BT_MESH_RELAY_ADV,
.tags = BT_MESH_RELAY_ADV_BIT,
.work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv),
}
};
Expand All @@ -100,7 +100,7 @@ static STRUCT_SECTION_ITERABLE_ARRAY(bt_mesh_ext_adv, adv_relay, CONFIG_BT_MESH_
#if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)
#define ADV_EXT_FRIEND 1
static STRUCT_SECTION_ITERABLE(bt_mesh_ext_adv, adv_friend) = {
.tag = BT_MESH_FRIEND_ADV,
.tags = BT_MESH_FRIEND_ADV_BIT,
.work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv),
};
#else /* CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE */
Expand All @@ -110,7 +110,7 @@ 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) = {
.tag = BT_MESH_PROXY_ADV,
.tags = BT_MESH_PROXY_ADV_BIT,
.work = Z_WORK_DELAYABLE_INITIALIZER(send_pending_adv),
};
#else /* CONFIG_BT_MESH_ADV_EXT_GATT_SEPARATE */
Expand Down Expand Up @@ -259,18 +259,18 @@ 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_tag tag)
static const char *adv_tag_to_str(enum bt_mesh_adv_tags tags)
{
if (tag & BT_MESH_LOCAL_ADV) {
if (tags & BT_MESH_LOCAL_ADV_BIT) {
return "local adv";
} else if (tag & BT_MESH_PROXY_ADV) {
} else if (tags & BT_MESH_PROXY_ADV_BIT) {
return "proxy adv";
} else if (tag & BT_MESH_RELAY_ADV) {
} else if (tags & BT_MESH_RELAY_ADV_BIT) {
return "relay adv";
} else if (tag & BT_MESH_FRIEND_ADV) {
} else if (tags & BT_MESH_FRIEND_ADV_BIT) {
return "friend adv";
} else {
return "(unknown tag)";
return "(unknown tags)";
}
}

Expand All @@ -289,8 +289,8 @@ 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->tag,
adv_tag_to_str(adv->tag));
LOG_DBG("Advertising stopped after %u ms for (%u) %s", (uint32_t)duration, adv->tags,
adv_tag_to_str(adv->tags));

atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE);
atomic_clear_bit(adv->flags, ADV_FLAG_PROXY);
Expand All @@ -308,7 +308,7 @@ static void send_pending_adv(struct k_work *work)

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->tags, K_NO_WAIT))) {
/* busy == 0 means this was canceled */
if (!BT_MESH_ADV(buf)->busy) {
net_buf_unref(buf);
Expand All @@ -326,7 +326,7 @@ static void send_pending_adv(struct k_work *work)
}

if (!IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER) ||
!(adv->tag & BT_MESH_PROXY_ADV)) {
!(adv->tags & BT_MESH_RELAY_ADV_BIT)) {
return;
}

Expand Down Expand Up @@ -369,8 +369,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->tag & BT_MESH_FRIEND_ADV) ||
(CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && adv->tag == BT_MESH_RELAY_ADV)) {
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)) {
k_work_reschedule(&adv->work, K_NO_WAIT);
} else {
/* The controller will send the next advertisement immediately.
Expand Down
12 changes: 6 additions & 6 deletions subsys/bluetooth/mesh/statistic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_LOCAL_ADV) {
stat.tx_local_planned++;
} else if (adv->tag & BT_MESH_RELAY_ADV) {
} else if (adv->tag == BT_MESH_RELAY_ADV) {
stat.tx_adv_relay_planned++;
} else if (adv->tag & BT_MESH_FRIEND_ADV) {
} else if (adv->tag == BT_MESH_FRIEND_ADV) {
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_LOCAL_ADV) {
stat.tx_local_succeeded++;
} else if (adv->tag & BT_MESH_RELAY_ADV) {
} else if (adv->tag == BT_MESH_RELAY_ADV) {
stat.tx_adv_relay_succeeded++;
} else if (adv->tag & BT_MESH_FRIEND_ADV) {
} else if (adv->tag == BT_MESH_FRIEND_ADV) {
stat.tx_friend_succeeded++;
}
}
Expand Down

0 comments on commit 2c3b9c4

Please sign in to comment.