Bluetooth: Mesh: Use memslab replace with net_buf_pool

Use memslab more efficiency than net_buf_pool and consume
less ram with flash resource.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
This commit is contained in:
Lingao Meng 2023-12-05 10:01:19 +08:00 committed by Fabio Baltieri
commit 683098728a
43 changed files with 534 additions and 537 deletions

View file

@ -19,7 +19,6 @@
#include "host/testing.h" #include "host/testing.h"
#include "mesh.h" #include "mesh.h"
#include "adv.h"
#include "net.h" #include "net.h"
#include "lpn.h" #include "lpn.h"
#include "transport.h" #include "transport.h"

View file

@ -17,7 +17,6 @@
#include "common/bt_str.h" #include "common/bt_str.h"
#include "adv.h"
#include "net.h" #include "net.h"
#include "foundation.h" #include "foundation.h"
#include "beacon.h" #include "beacon.h"
@ -47,124 +46,144 @@ static K_FIFO_DEFINE(bt_mesh_adv_queue);
static K_FIFO_DEFINE(bt_mesh_relay_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) K_MEM_SLAB_DEFINE_STATIC(local_adv_pool, sizeof(struct bt_mesh_adv),
{ CONFIG_BT_MESH_ADV_BUF_COUNT, __alignof__(struct bt_mesh_adv));
if (!adv->started) {
adv->started = 1;
if (adv->cb && adv->cb->start) { #if defined(CONFIG_BT_MESH_RELAY_BUF_COUNT)
adv->cb->start(duration, err, adv->cb_data); K_MEM_SLAB_DEFINE_STATIC(relay_adv_pool, sizeof(struct bt_mesh_adv),
} CONFIG_BT_MESH_RELAY_BUF_COUNT, __alignof__(struct bt_mesh_adv));
if (err) {
adv->cb = NULL;
} else if (IS_ENABLED(CONFIG_BT_MESH_STATISTIC)) {
bt_mesh_stat_succeeded_count(adv);
}
}
}
static void bt_mesh_adv_send_end(int err, struct bt_mesh_adv const *adv)
{
if (adv->started && adv->cb && adv->cb->end) {
adv->cb->end(err, adv->cb_data);
}
}
static void adv_buf_destroy(struct net_buf *buf)
{
struct bt_mesh_adv adv = *BT_MESH_ADV(buf);
net_buf_destroy(buf);
bt_mesh_adv_send_end(0, &adv);
}
NET_BUF_POOL_DEFINE(adv_buf_pool, CONFIG_BT_MESH_ADV_BUF_COUNT,
BT_MESH_ADV_DATA_SIZE, BT_MESH_ADV_USER_DATA_SIZE,
adv_buf_destroy);
static struct bt_mesh_adv adv_local_pool[CONFIG_BT_MESH_ADV_BUF_COUNT];
#if defined(CONFIG_BT_MESH_RELAY)
NET_BUF_POOL_DEFINE(relay_buf_pool, CONFIG_BT_MESH_RELAY_BUF_COUNT,
BT_MESH_ADV_DATA_SIZE, BT_MESH_ADV_USER_DATA_SIZE,
adv_buf_destroy);
static struct bt_mesh_adv adv_relay_pool[CONFIG_BT_MESH_RELAY_BUF_COUNT];
#endif #endif
#if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)
NET_BUF_POOL_DEFINE(friend_buf_pool, CONFIG_BT_MESH_FRIEND_LPN_COUNT, K_MEM_SLAB_DEFINE_STATIC(friend_adv_pool, sizeof(struct bt_mesh_adv),
BT_MESH_ADV_DATA_SIZE, BT_MESH_ADV_USER_DATA_SIZE, CONFIG_BT_MESH_FRIEND_LPN_COUNT, __alignof__(struct bt_mesh_adv));
adv_buf_destroy);
static struct bt_mesh_adv adv_friend_pool[CONFIG_BT_MESH_FRIEND_LPN_COUNT];
#endif #endif
static struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *buf_pool, void bt_mesh_adv_send_start(uint16_t duration, int err, struct bt_mesh_adv_ctx *ctx)
struct bt_mesh_adv *adv_pool,
enum bt_mesh_adv_type type,
enum bt_mesh_adv_tag tag,
uint8_t xmit, k_timeout_t timeout)
{ {
if (!ctx->started) {
ctx->started = 1;
if (ctx->cb && ctx->cb->start) {
ctx->cb->start(duration, err, ctx->cb_data);
}
if (err) {
ctx->cb = NULL;
} else if (IS_ENABLED(CONFIG_BT_MESH_STATISTIC)) {
bt_mesh_stat_succeeded_count(ctx);
}
}
}
static void bt_mesh_adv_send_end(int err, struct bt_mesh_adv_ctx const *ctx)
{
if (ctx->started && ctx->cb && ctx->cb->end) {
ctx->cb->end(err, ctx->cb_data);
}
}
static struct bt_mesh_adv *adv_create_from_pool(struct k_mem_slab *buf_pool,
enum bt_mesh_adv_type type,
enum bt_mesh_adv_tag tag,
uint8_t xmit, k_timeout_t timeout)
{
struct bt_mesh_adv_ctx *ctx;
struct bt_mesh_adv *adv; struct bt_mesh_adv *adv;
struct net_buf *buf; int err;
if (atomic_test_bit(bt_mesh.flags, BT_MESH_SUSPENDED)) { if (atomic_test_bit(bt_mesh.flags, BT_MESH_SUSPENDED)) {
LOG_WRN("Refusing to allocate buffer while suspended"); LOG_WRN("Refusing to allocate buffer while suspended");
return NULL; return NULL;
} }
buf = net_buf_alloc(buf_pool, timeout); err = k_mem_slab_alloc(buf_pool, (void **)&adv, timeout);
if (!buf) { if (err) {
return NULL; return NULL;
} }
adv = &adv_pool[net_buf_id(buf)]; adv->__ref = 1;
BT_MESH_ADV(buf) = adv;
(void)memset(adv, 0, sizeof(*adv)); net_buf_simple_init_with_data(&adv->b, adv->__bufs, BT_MESH_ADV_DATA_SIZE);
net_buf_simple_reset(&adv->b);
adv->type = type; ctx = &adv->ctx;
adv->tag = tag;
adv->xmit = xmit;
return buf; (void)memset(ctx, 0, sizeof(*ctx));
ctx->type = type;
ctx->tag = tag;
ctx->xmit = xmit;
return adv;
} }
struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, struct bt_mesh_adv *bt_mesh_adv_ref(struct bt_mesh_adv *adv)
enum bt_mesh_adv_tag tag, {
uint8_t xmit, k_timeout_t timeout) __ASSERT_NO_MSG(adv->__ref < UINT8_MAX);
adv->__ref++;
return adv;
}
void bt_mesh_adv_unref(struct bt_mesh_adv *adv)
{
__ASSERT_NO_MSG(adv->__ref > 0);
if (--adv->__ref > 0) {
return;
}
struct k_mem_slab *slab = &local_adv_pool;
struct bt_mesh_adv_ctx ctx = adv->ctx;
#if defined(CONFIG_BT_MESH_RELAY)
if (adv->ctx.tag == BT_MESH_ADV_TAG_RELAY) {
slab = &relay_adv_pool;
}
#endif
#if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)
if (adv->ctx.tag == BT_MESH_ADV_TAG_FRIEND) {
slab = &friend_adv_pool;
}
#endif
k_mem_slab_free(slab, (void *)adv);
bt_mesh_adv_send_end(0, &ctx);
}
struct bt_mesh_adv *bt_mesh_adv_create(enum bt_mesh_adv_type type,
enum bt_mesh_adv_tag tag,
uint8_t xmit, k_timeout_t timeout)
{ {
#if defined(CONFIG_BT_MESH_RELAY) #if defined(CONFIG_BT_MESH_RELAY)
if (tag == BT_MESH_ADV_TAG_RELAY) { if (tag == BT_MESH_ADV_TAG_RELAY) {
return bt_mesh_adv_create_from_pool(&relay_buf_pool, return adv_create_from_pool(&relay_adv_pool,
adv_relay_pool, type, type, tag, xmit, timeout);
tag, xmit, timeout);
} }
#endif #endif
#if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) #if defined(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)
if (tag == BT_MESH_ADV_TAG_FRIEND) { if (tag == BT_MESH_ADV_TAG_FRIEND) {
return bt_mesh_adv_create_from_pool(&friend_buf_pool, return adv_create_from_pool(&friend_adv_pool,
adv_friend_pool, type, type, tag, xmit, timeout);
tag, xmit, timeout);
} }
#endif #endif
return bt_mesh_adv_create_from_pool(&adv_buf_pool, adv_local_pool, type, return adv_create_from_pool(&local_adv_pool, type,
tag, xmit, timeout); tag, xmit, timeout);
} }
static struct net_buf *process_events(struct k_poll_event *ev, int count) static struct bt_mesh_adv *process_events(struct k_poll_event *ev, int count)
{ {
for (; count; ev++, count--) { for (; count; ev++, count--) {
LOG_DBG("ev->state %u", ev->state); LOG_DBG("ev->state %u", ev->state);
switch (ev->state) { switch (ev->state) {
case K_POLL_STATE_FIFO_DATA_AVAILABLE: case K_POLL_STATE_FIFO_DATA_AVAILABLE:
return net_buf_get(ev->fifo, K_NO_WAIT); return k_fifo_get(ev->fifo, K_NO_WAIT);
case K_POLL_STATE_NOT_READY: case K_POLL_STATE_NOT_READY:
case K_POLL_STATE_CANCELLED: case K_POLL_STATE_CANCELLED:
break; break;
@ -177,7 +196,7 @@ static struct net_buf *process_events(struct k_poll_event *ev, int count)
return NULL; return NULL;
} }
struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout) struct bt_mesh_adv *bt_mesh_adv_get(k_timeout_t timeout)
{ {
int err; int err;
struct k_poll_event events[] = { struct k_poll_event events[] = {
@ -204,22 +223,22 @@ 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_tag_bit tags, k_timeout_t timeout) struct bt_mesh_adv *bt_mesh_adv_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_BIT_FRIEND) { tags & BT_MESH_ADV_TAG_BIT_FRIEND) {
return net_buf_get(&bt_mesh_friend_queue, timeout); return k_fifo_get(&bt_mesh_friend_queue, timeout);
} }
if (IS_ENABLED(CONFIG_BT_MESH_RELAY) && if (IS_ENABLED(CONFIG_BT_MESH_RELAY) &&
!(tags & BT_MESH_ADV_TAG_BIT_LOCAL)) { !(tags & BT_MESH_ADV_TAG_BIT_LOCAL)) {
return net_buf_get(&bt_mesh_relay_queue, timeout); return k_fifo_get(&bt_mesh_relay_queue, timeout);
} }
return bt_mesh_adv_buf_get(timeout); return bt_mesh_adv_get(timeout);
} }
void bt_mesh_adv_buf_get_cancel(void) void bt_mesh_adv_get_cancel(void)
{ {
LOG_DBG(""); LOG_DBG("");
@ -234,38 +253,38 @@ void bt_mesh_adv_buf_get_cancel(void)
} }
} }
void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, void bt_mesh_adv_send(struct bt_mesh_adv *adv, const struct bt_mesh_send_cb *cb,
void *cb_data) void *cb_data)
{ {
LOG_DBG("type 0x%02x len %u: %s", BT_MESH_ADV(buf)->type, buf->len, LOG_DBG("type 0x%02x len %u: %s", adv->ctx.type, adv->b.len,
bt_hex(buf->data, buf->len)); bt_hex(adv->b.data, adv->b.len));
BT_MESH_ADV(buf)->cb = cb; adv->ctx.cb = cb;
BT_MESH_ADV(buf)->cb_data = cb_data; adv->ctx.cb_data = cb_data;
BT_MESH_ADV(buf)->busy = 1U; adv->ctx.busy = 1U;
if (IS_ENABLED(CONFIG_BT_MESH_STATISTIC)) { if (IS_ENABLED(CONFIG_BT_MESH_STATISTIC)) {
bt_mesh_stat_planned_count(BT_MESH_ADV(buf)); bt_mesh_stat_planned_count(&adv->ctx);
} }
if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) && if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE) &&
BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_FRIEND) { adv->ctx.tag == BT_MESH_ADV_TAG_FRIEND) {
net_buf_put(&bt_mesh_friend_queue, net_buf_ref(buf)); k_fifo_put(&bt_mesh_friend_queue, bt_mesh_adv_ref(adv));
bt_mesh_adv_buf_friend_ready(); bt_mesh_adv_friend_ready();
return; return;
} }
if ((IS_ENABLED(CONFIG_BT_MESH_RELAY) && if ((IS_ENABLED(CONFIG_BT_MESH_RELAY) &&
BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_RELAY) || adv->ctx.tag == BT_MESH_ADV_TAG_RELAY) ||
(IS_ENABLED(CONFIG_BT_MESH_PB_ADV_USE_RELAY_SETS) && (IS_ENABLED(CONFIG_BT_MESH_PB_ADV_USE_RELAY_SETS) &&
BT_MESH_ADV(buf)->tag == BT_MESH_ADV_TAG_PROV)) { adv->ctx.tag == BT_MESH_ADV_TAG_PROV)) {
net_buf_put(&bt_mesh_relay_queue, net_buf_ref(buf)); k_fifo_put(&bt_mesh_relay_queue, bt_mesh_adv_ref(adv));
bt_mesh_adv_buf_relay_ready(); bt_mesh_adv_relay_ready();
return; return;
} }
net_buf_put(&bt_mesh_adv_queue, net_buf_ref(buf)); k_fifo_put(&bt_mesh_adv_queue, bt_mesh_adv_ref(adv));
bt_mesh_adv_buf_local_ready(); bt_mesh_adv_local_ready();
} }
int bt_mesh_adv_gatt_send(void) int bt_mesh_adv_gatt_send(void)

View file

@ -4,14 +4,12 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#ifndef ZEPHYR_SUBSYS_BLUETOOTH_MESH_ADV_H_
#define ZEPHYR_SUBSYS_BLUETOOTH_MESH_ADV_H_
/* Maximum advertising data payload for a single data type */ /* Maximum advertising data payload for a single data type */
#define BT_MESH_ADV_DATA_SIZE 29 #define BT_MESH_ADV_DATA_SIZE 29
/* The user data is a pointer (4 bytes) to struct bt_mesh_adv */
#define BT_MESH_ADV_USER_DATA_SIZE 4
#define BT_MESH_ADV(buf) (*(struct bt_mesh_adv **)net_buf_user_data(buf))
#define BT_MESH_ADV_SCAN_UNIT(_ms) ((_ms) * 8 / 5) #define BT_MESH_ADV_SCAN_UNIT(_ms) ((_ms) * 8 / 5)
#define BT_MESH_SCAN_INTERVAL_MS 30 #define BT_MESH_SCAN_INTERVAL_MS 30
#define BT_MESH_SCAN_WINDOW_MS 30 #define BT_MESH_SCAN_WINDOW_MS 30
@ -41,7 +39,7 @@ enum bt_mesh_adv_tag_bit {
BT_MESH_ADV_TAG_BIT_PROV = 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_ctx {
const struct bt_mesh_send_cb *cb; const struct bt_mesh_send_cb *cb;
void *cb_data; void *cb_data;
@ -53,24 +51,39 @@ struct bt_mesh_adv {
uint8_t xmit; uint8_t xmit;
}; };
struct bt_mesh_adv {
sys_snode_t node;
struct bt_mesh_adv_ctx ctx;
struct net_buf_simple b;
uint8_t __ref;
uint8_t __bufs[BT_MESH_ADV_DATA_SIZE];
};
/* Lookup table for Advertising data types for bt_mesh_adv_type: */ /* Lookup table for Advertising data types for bt_mesh_adv_type: */
extern const uint8_t bt_mesh_adv_type[BT_MESH_ADV_TYPES]; extern const uint8_t bt_mesh_adv_type[BT_MESH_ADV_TYPES];
/* xmit_count: Number of retransmissions, i.e. 0 == 1 transmission */ struct bt_mesh_adv *bt_mesh_adv_ref(struct bt_mesh_adv *adv);
struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, void bt_mesh_adv_unref(struct bt_mesh_adv *adv);
enum bt_mesh_adv_tag tag,
uint8_t xmit, k_timeout_t timeout);
void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, /* xmit_count: Number of retransmissions, i.e. 0 == 1 transmission */
struct bt_mesh_adv *bt_mesh_adv_create(enum bt_mesh_adv_type type,
enum bt_mesh_adv_tag tag,
uint8_t xmit, k_timeout_t timeout);
void bt_mesh_adv_send(struct bt_mesh_adv *adv, const struct bt_mesh_send_cb *cb,
void *cb_data); void *cb_data);
struct net_buf *bt_mesh_adv_buf_get(k_timeout_t timeout); struct bt_mesh_adv *bt_mesh_adv_get(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); struct bt_mesh_adv *bt_mesh_adv_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);
void bt_mesh_adv_buf_get_cancel(void); void bt_mesh_adv_get_cancel(void);
void bt_mesh_adv_init(void); void bt_mesh_adv_init(void);
@ -83,13 +96,13 @@ int bt_mesh_adv_enable(void);
/* Should not be called from work queue due to undefined behavior */ /* Should not be called from work queue due to undefined behavior */
int bt_mesh_adv_disable(void); int bt_mesh_adv_disable(void);
void bt_mesh_adv_buf_local_ready(void); void bt_mesh_adv_local_ready(void);
void bt_mesh_adv_buf_relay_ready(void); void bt_mesh_adv_relay_ready(void);
void bt_mesh_adv_buf_terminate(const struct net_buf *buf); void bt_mesh_adv_terminate(struct bt_mesh_adv *adv);
void bt_mesh_adv_buf_friend_ready(void); void bt_mesh_adv_friend_ready(void);
int bt_mesh_adv_gatt_send(void); int bt_mesh_adv_gatt_send(void);
@ -97,9 +110,11 @@ 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);
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_ctx *ctx);
int bt_mesh_scan_active_set(bool active); int bt_mesh_scan_active_set(bool active);
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);
#endif /* ZEPHYR_SUBSYS_BLUETOOTH_MESH_ADV_H_ */

View file

@ -18,7 +18,6 @@
#include "host/hci_core.h" #include "host/hci_core.h"
#include "adv.h"
#include "net.h" #include "net.h"
#include "proxy.h" #include "proxy.h"
#include "solicitation.h" #include "solicitation.h"
@ -60,14 +59,14 @@ struct bt_mesh_ext_adv {
const enum bt_mesh_adv_tag_bit 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 bt_mesh_adv *adv;
uint64_t timestamp; uint64_t timestamp;
struct k_work_delayable work; struct k_work_delayable work;
struct bt_le_adv_param adv_param; struct bt_le_adv_param adv_param;
}; };
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 *ext_adv);
static struct bt_mesh_ext_adv advs[] = { static struct bt_mesh_ext_adv advs[] = {
[0] = { [0] = {
@ -136,7 +135,7 @@ static inline struct bt_mesh_ext_adv *gatt_adv_get(void)
} }
} }
static int adv_start(struct bt_mesh_ext_adv *adv, static int adv_start(struct bt_mesh_ext_adv *ext_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,
@ -144,47 +143,47 @@ static int adv_start(struct bt_mesh_ext_adv *adv,
{ {
int err; int err;
if (!adv->instance) { if (!ext_adv->instance) {
LOG_ERR("Mesh advertiser not enabled"); LOG_ERR("Mesh advertiser not enabled");
return -ENODEV; return -ENODEV;
} }
if (atomic_test_and_set_bit(adv->flags, ADV_FLAG_ACTIVE)) { if (atomic_test_and_set_bit(ext_adv->flags, ADV_FLAG_ACTIVE)) {
LOG_ERR("Advertiser is busy"); LOG_ERR("Advertiser is busy");
return -EBUSY; return -EBUSY;
} }
if (atomic_test_bit(adv->flags, ADV_FLAG_UPDATE_PARAMS)) { if (atomic_test_bit(ext_adv->flags, ADV_FLAG_UPDATE_PARAMS)) {
err = bt_le_ext_adv_update_param(adv->instance, param); err = bt_le_ext_adv_update_param(ext_adv->instance, param);
if (err) { if (err) {
LOG_ERR("Failed updating adv params: %d", err); LOG_ERR("Failed updating adv params: %d", err);
atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); atomic_clear_bit(ext_adv->flags, ADV_FLAG_ACTIVE);
return err; return err;
} }
atomic_set_bit_to(adv->flags, ADV_FLAG_UPDATE_PARAMS, atomic_set_bit_to(ext_adv->flags, ADV_FLAG_UPDATE_PARAMS,
param != &adv->adv_param); param != &ext_adv->adv_param);
} }
err = bt_le_ext_adv_set_data(adv->instance, ad, ad_len, sd, sd_len); err = bt_le_ext_adv_set_data(ext_adv->instance, ad, ad_len, sd, sd_len);
if (err) { if (err) {
LOG_ERR("Failed setting adv data: %d", err); LOG_ERR("Failed setting adv data: %d", err);
atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); atomic_clear_bit(ext_adv->flags, ADV_FLAG_ACTIVE);
return err; return err;
} }
adv->timestamp = k_uptime_get(); ext_adv->timestamp = k_uptime_get();
err = bt_le_ext_adv_start(adv->instance, start); err = bt_le_ext_adv_start(ext_adv->instance, start);
if (err) { if (err) {
LOG_ERR("Advertising failed: err %d", err); LOG_ERR("Advertising failed: err %d", err);
atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); atomic_clear_bit(ext_adv->flags, ADV_FLAG_ACTIVE);
} }
return err; return err;
} }
static int bt_data_send(struct bt_mesh_ext_adv *adv, uint8_t num_events, uint16_t adv_interval, static int bt_data_send(struct bt_mesh_ext_adv *ext_adv, 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)
{ {
struct bt_le_ext_adv_start_param start = { struct bt_le_ext_adv_start_param start = {
@ -194,41 +193,41 @@ static int bt_data_send(struct bt_mesh_ext_adv *adv, uint8_t num_events, uint16_
adv_interval = MAX(ADV_INT_FAST_MS, adv_interval); adv_interval = MAX(ADV_INT_FAST_MS, adv_interval);
/* Only update advertising parameters if they're different */ /* Only update advertising parameters if they're different */
if (adv->adv_param.interval_min != BT_MESH_ADV_SCAN_UNIT(adv_interval)) { if (ext_adv->adv_param.interval_min != BT_MESH_ADV_SCAN_UNIT(adv_interval)) {
adv->adv_param.interval_min = BT_MESH_ADV_SCAN_UNIT(adv_interval); ext_adv->adv_param.interval_min = BT_MESH_ADV_SCAN_UNIT(adv_interval);
adv->adv_param.interval_max = adv->adv_param.interval_min; ext_adv->adv_param.interval_max = ext_adv->adv_param.interval_min;
atomic_set_bit(adv->flags, ADV_FLAG_UPDATE_PARAMS); atomic_set_bit(ext_adv->flags, ADV_FLAG_UPDATE_PARAMS);
} }
return adv_start(adv, &adv->adv_param, &start, ad, ad_len, NULL, 0); return adv_start(ext_adv, &ext_adv->adv_param, &start, ad, ad_len, NULL, 0);
} }
static int buf_send(struct bt_mesh_ext_adv *adv, struct net_buf *buf) static int adv_send(struct bt_mesh_ext_adv *ext_adv, struct bt_mesh_adv *adv)
{ {
uint8_t num_events = BT_MESH_TRANSMIT_COUNT(BT_MESH_ADV(buf)->xmit) + 1; uint8_t num_events = BT_MESH_TRANSMIT_COUNT(adv->ctx.xmit) + 1;
uint16_t duration, adv_int; uint16_t duration, adv_int;
struct bt_data ad; struct bt_data ad;
int err; int err;
adv_int = BT_MESH_TRANSMIT_INT(BT_MESH_ADV(buf)->xmit); adv_int = BT_MESH_TRANSMIT_INT(adv->ctx.xmit);
/* Upper boundary estimate: */ /* Upper boundary estimate: */
duration = num_events * (adv_int + 10); duration = num_events * (adv_int + 10);
LOG_DBG("type %u len %u: %s", BT_MESH_ADV(buf)->type, LOG_DBG("type %u len %u: %s", adv->ctx.type,
buf->len, bt_hex(buf->data, buf->len)); adv->b.len, bt_hex(adv->b.data, adv->b.len));
LOG_DBG("count %u interval %ums duration %ums", LOG_DBG("count %u interval %ums duration %ums",
num_events, adv_int, duration); num_events, adv_int, duration);
ad.type = bt_mesh_adv_type[BT_MESH_ADV(buf)->type]; ad.type = bt_mesh_adv_type[adv->ctx.type];
ad.data_len = buf->len; ad.data_len = adv->b.len;
ad.data = buf->data; ad.data = adv->b.data;
err = bt_data_send(adv, num_events, adv_int, &ad, 1); err = bt_data_send(ext_adv, num_events, adv_int, &ad, 1);
if (!err) { if (!err) {
adv->buf = net_buf_ref(buf); ext_adv->adv = bt_mesh_adv_ref(adv);
} }
bt_mesh_adv_send_start(duration, err, BT_MESH_ADV(buf)); bt_mesh_adv_send_start(duration, err, &adv->ctx);
return err; return err;
} }
@ -243,50 +242,50 @@ static const char * const adv_tag_to_str[] = {
static void send_pending_adv(struct k_work *work) static void send_pending_adv(struct k_work *work)
{ {
struct bt_mesh_ext_adv *adv; struct bt_mesh_ext_adv *ext_adv;
struct net_buf *buf; struct bt_mesh_adv *adv;
int err; int err;
adv = CONTAINER_OF(work, struct bt_mesh_ext_adv, work.work); ext_adv = CONTAINER_OF(work, struct bt_mesh_ext_adv, work.work);
if (atomic_test_and_clear_bit(adv->flags, ADV_FLAG_SENT)) { if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_SENT)) {
/* Calling k_uptime_delta on a timestamp moves it to the current time. /* Calling k_uptime_delta on a timestamp moves it to the current time.
* This is essential here, as schedule_send() uses the end of the event * This is essential here, as schedule_send() uses the end of the event
* as a reference to avoid sending the next advertisement too soon. * as a reference to avoid sending the next advertisement too soon.
*/ */
int64_t duration = k_uptime_delta(&adv->timestamp); int64_t duration = k_uptime_delta(&ext_adv->timestamp);
LOG_DBG("Advertising stopped after %u ms for %s", (uint32_t)duration, LOG_DBG("Advertising stopped after %u ms for %s", (uint32_t)duration,
adv->buf ? adv_tag_to_str[BT_MESH_ADV(adv->buf)->tag] : ext_adv->adv ? adv_tag_to_str[ext_adv->adv->ctx.tag] :
adv_tag_to_str[BT_MESH_ADV_TAG_PROXY]); adv_tag_to_str[BT_MESH_ADV_TAG_PROXY]);
atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); atomic_clear_bit(ext_adv->flags, ADV_FLAG_ACTIVE);
atomic_clear_bit(adv->flags, ADV_FLAG_PROXY); atomic_clear_bit(ext_adv->flags, ADV_FLAG_PROXY);
atomic_clear_bit(adv->flags, ADV_FLAG_PROXY_START); atomic_clear_bit(ext_adv->flags, ADV_FLAG_PROXY_START);
if (adv->buf) { if (ext_adv->adv) {
net_buf_unref(adv->buf); bt_mesh_adv_unref(ext_adv->adv);
adv->buf = NULL; ext_adv->adv = NULL;
} }
(void)schedule_send(adv); (void)schedule_send(ext_adv);
return; return;
} }
atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULED); atomic_clear_bit(ext_adv->flags, ADV_FLAG_SCHEDULED);
while ((buf = bt_mesh_adv_buf_get_by_tag(adv->tags, K_NO_WAIT))) { while ((adv = bt_mesh_adv_get_by_tag(ext_adv->tags, K_NO_WAIT))) {
/* busy == 0 means this was canceled */ /* busy == 0 means this was canceled */
if (!BT_MESH_ADV(buf)->busy) { if (!adv->ctx.busy) {
net_buf_unref(buf); bt_mesh_adv_unref(adv);
continue; continue;
} }
BT_MESH_ADV(buf)->busy = 0U; adv->ctx.busy = 0U;
err = buf_send(adv, buf); err = adv_send(ext_adv, adv);
net_buf_unref(buf); bt_mesh_adv_unref(adv);
if (!err) { if (!err) {
return; /* Wait for advertising to finish */ return; /* Wait for advertising to finish */
@ -294,7 +293,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_BIT_PROXY)) { !(ext_adv->tags & BT_MESH_ADV_TAG_BIT_PROXY)) {
return; return;
} }
@ -303,51 +302,51 @@ static void send_pending_adv(struct k_work *work)
return; return;
} }
atomic_set_bit(adv->flags, ADV_FLAG_PROXY_START); atomic_set_bit(ext_adv->flags, ADV_FLAG_PROXY_START);
if (!bt_mesh_adv_gatt_send()) { if (!bt_mesh_adv_gatt_send()) {
atomic_set_bit(adv->flags, ADV_FLAG_PROXY); atomic_set_bit(ext_adv->flags, ADV_FLAG_PROXY);
} }
if (atomic_test_and_clear_bit(adv->flags, ADV_FLAG_SCHEDULE_PENDING)) { if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_SCHEDULE_PENDING)) {
schedule_send(adv); schedule_send(ext_adv);
} }
} }
static bool schedule_send(struct bt_mesh_ext_adv *adv) static bool schedule_send(struct bt_mesh_ext_adv *ext_adv)
{ {
uint64_t timestamp; uint64_t timestamp;
int64_t delta; int64_t delta;
timestamp = adv->timestamp; timestamp = ext_adv->timestamp;
if (atomic_test_and_clear_bit(adv->flags, ADV_FLAG_PROXY)) { if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_PROXY)) {
atomic_clear_bit(adv->flags, ADV_FLAG_PROXY_START); atomic_clear_bit(ext_adv->flags, ADV_FLAG_PROXY_START);
(void)bt_le_ext_adv_stop(adv->instance); (void)bt_le_ext_adv_stop(ext_adv->instance);
atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); atomic_clear_bit(ext_adv->flags, ADV_FLAG_ACTIVE);
} }
if (atomic_test_bit(adv->flags, ADV_FLAG_ACTIVE)) { if (atomic_test_bit(ext_adv->flags, ADV_FLAG_ACTIVE)) {
atomic_set_bit(adv->flags, ADV_FLAG_SCHEDULE_PENDING); atomic_set_bit(ext_adv->flags, ADV_FLAG_SCHEDULE_PENDING);
return false; return false;
} else if (atomic_test_and_set_bit(adv->flags, ADV_FLAG_SCHEDULED)) { } else if (atomic_test_and_set_bit(ext_adv->flags, ADV_FLAG_SCHEDULED)) {
return false; return false;
} }
atomic_clear_bit(adv->flags, ADV_FLAG_SCHEDULE_PENDING); atomic_clear_bit(ext_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_BIT_FRIEND) || ext_adv->tags & BT_MESH_ADV_TAG_BIT_FRIEND) ||
(CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && adv->tags & BT_MESH_ADV_TAG_BIT_RELAY)) { (CONFIG_BT_MESH_RELAY_ADV_SETS > 0 && ext_adv->tags & BT_MESH_ADV_TAG_BIT_RELAY)) {
k_work_reschedule(&adv->work, K_NO_WAIT); k_work_reschedule(&ext_adv->work, K_NO_WAIT);
} else { } else {
/* The controller will send the next advertisement immediately. /* The controller will send the next advertisement immediately.
* Introduce a delay here to avoid sending the next mesh packet closer * Introduce a delay here to avoid sending the next mesh packet closer
* to the previous packet than what's permitted by the specification. * to the previous packet than what's permitted by the specification.
*/ */
delta = k_uptime_delta(&timestamp); delta = k_uptime_delta(&timestamp);
k_work_reschedule(&adv->work, K_MSEC(ADV_INT_FAST_MS - delta)); k_work_reschedule(&ext_adv->work, K_MSEC(ADV_INT_FAST_MS - delta));
} }
return true; return true;
@ -358,17 +357,17 @@ void bt_mesh_adv_gatt_update(void)
(void)schedule_send(gatt_adv_get()); (void)schedule_send(gatt_adv_get());
} }
void bt_mesh_adv_buf_local_ready(void) void bt_mesh_adv_local_ready(void)
{ {
(void)schedule_send(advs); (void)schedule_send(advs);
} }
void bt_mesh_adv_buf_relay_ready(void) void bt_mesh_adv_relay_ready(void)
{ {
struct bt_mesh_ext_adv *adv = relay_adv_get(); struct bt_mesh_ext_adv *ext_adv = relay_adv_get();
for (int i = 0; i < CONFIG_BT_MESH_RELAY_ADV_SETS; i++) { for (int i = 0; i < CONFIG_BT_MESH_RELAY_ADV_SETS; i++) {
if (schedule_send(&adv[i])) { if (schedule_send(&ext_adv[i])) {
return; return;
} }
} }
@ -379,7 +378,7 @@ void bt_mesh_adv_buf_relay_ready(void)
} }
} }
void bt_mesh_adv_buf_friend_ready(void) void bt_mesh_adv_friend_ready(void)
{ {
if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)) { if (IS_ENABLED(CONFIG_BT_MESH_ADV_EXT_FRIEND_SEPARATE)) {
schedule_send(&advs[1 + CONFIG_BT_MESH_RELAY_ADV_SETS]); schedule_send(&advs[1 + CONFIG_BT_MESH_RELAY_ADV_SETS]);
@ -388,33 +387,33 @@ void bt_mesh_adv_buf_friend_ready(void)
} }
} }
void bt_mesh_adv_buf_terminate(const struct net_buf *buf) void bt_mesh_adv_terminate(struct bt_mesh_adv *adv)
{ {
int err; int err;
for (int i = 0; i < ARRAY_SIZE(advs); i++) { for (int i = 0; i < ARRAY_SIZE(advs); i++) {
struct bt_mesh_ext_adv *adv = &advs[i]; struct bt_mesh_ext_adv *ext_adv = &advs[i];
if (adv->buf != buf) { if (ext_adv->adv != adv) {
continue; continue;
} }
if (!atomic_test_bit(adv->flags, ADV_FLAG_ACTIVE)) { if (!atomic_test_bit(ext_adv->flags, ADV_FLAG_ACTIVE)) {
return; return;
} }
err = bt_le_ext_adv_stop(adv->instance); err = bt_le_ext_adv_stop(ext_adv->instance);
if (err) { if (err) {
LOG_ERR("Failed to stop adv %d", err); LOG_ERR("Failed to stop adv %d", err);
return; return;
} }
/* Do not call `cb:end`, since this user action */ /* Do not call `cb:end`, since this user action */
BT_MESH_ADV(adv->buf)->cb = NULL; adv->ctx.cb = NULL;
atomic_set_bit(adv->flags, ADV_FLAG_SENT); atomic_set_bit(ext_adv->flags, ADV_FLAG_SENT);
k_work_submit(&adv->work.work); k_work_submit(&ext_adv->work.work);
return; return;
} }
@ -450,31 +449,31 @@ static struct bt_mesh_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 bt_mesh_ext_adv *adv = adv_instance_find(instance); struct bt_mesh_ext_adv *ext_adv = adv_instance_find(instance);
if (!adv) { if (!ext_adv) {
LOG_WRN("Unexpected adv instance"); LOG_WRN("Unexpected adv instance");
return; return;
} }
if (!atomic_test_bit(adv->flags, ADV_FLAG_ACTIVE)) { if (!atomic_test_bit(ext_adv->flags, ADV_FLAG_ACTIVE)) {
return; return;
} }
atomic_set_bit(adv->flags, ADV_FLAG_SENT); atomic_set_bit(ext_adv->flags, ADV_FLAG_SENT);
k_work_submit(&adv->work.work); k_work_submit(&ext_adv->work.work);
} }
#if defined(CONFIG_BT_MESH_GATT_SERVER) #if defined(CONFIG_BT_MESH_GATT_SERVER)
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 bt_mesh_ext_adv *adv = gatt_adv_get(); struct bt_mesh_ext_adv *ext_adv = gatt_adv_get();
if (atomic_test_and_clear_bit(adv->flags, ADV_FLAG_PROXY_START)) { if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_PROXY_START)) {
atomic_clear_bit(adv->flags, ADV_FLAG_ACTIVE); atomic_clear_bit(ext_adv->flags, ADV_FLAG_ACTIVE);
(void)schedule_send(adv); (void)schedule_send(ext_adv);
} }
} }
#endif /* CONFIG_BT_MESH_GATT_SERVER */ #endif /* CONFIG_BT_MESH_GATT_SERVER */
@ -541,7 +540,7 @@ int bt_mesh_adv_gatt_start(const struct bt_le_adv_param *param,
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 bt_mesh_ext_adv *adv = gatt_adv_get(); struct bt_mesh_ext_adv *ext_adv = gatt_adv_get();
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 : MAX(1, duration / 10), .timeout = (duration == SYS_FOREVER_MS) ? 0 : MAX(1, duration / 10),
@ -549,9 +548,9 @@ int bt_mesh_adv_gatt_start(const struct bt_le_adv_param *param,
LOG_DBG("Start advertising %d ms", duration); LOG_DBG("Start advertising %d ms", duration);
atomic_set_bit(adv->flags, ADV_FLAG_UPDATE_PARAMS); atomic_set_bit(ext_adv->flags, ADV_FLAG_UPDATE_PARAMS);
return adv_start(adv, param, &start, ad, ad_len, sd, sd_len); return adv_start(ext_adv, param, &start, ad, ad_len, sd, sd_len);
} }
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,

View file

@ -19,7 +19,6 @@
#include "host/hci_core.h" #include "host/hci_core.h"
#include "adv.h"
#include "net.h" #include "net.h"
#include "foundation.h" #include "foundation.h"
#include "beacon.h" #include "beacon.h"
@ -43,7 +42,7 @@ static bool enabled;
static int bt_data_send(uint8_t num_events, uint16_t adv_int, static int bt_data_send(uint8_t num_events, uint16_t adv_int,
const struct bt_data *ad, size_t ad_len, const struct bt_data *ad, size_t ad_len,
struct bt_mesh_adv *adv) struct bt_mesh_adv_ctx *ctx)
{ {
struct bt_le_adv_param param = {}; struct bt_le_adv_param param = {};
uint64_t uptime = k_uptime_get(); uint64_t uptime = k_uptime_get();
@ -101,8 +100,8 @@ static int bt_data_send(uint8_t num_events, uint16_t adv_int,
LOG_DBG("Advertising started. Sleeping %u ms", duration); LOG_DBG("Advertising started. Sleeping %u ms", duration);
if (adv) { if (ctx) {
bt_mesh_adv_send_start(duration, err, adv); bt_mesh_adv_send_start(duration, err, ctx);
} }
k_sleep(K_MSEC(duration)); k_sleep(K_MSEC(duration));
@ -124,37 +123,37 @@ int bt_mesh_adv_bt_data_send(uint8_t num_events, uint16_t adv_int,
return bt_data_send(num_events, adv_int, ad, ad_len, NULL); return bt_data_send(num_events, adv_int, ad, ad_len, NULL);
} }
static inline void buf_send(struct net_buf *buf) static inline void adv_send(struct bt_mesh_adv *adv)
{ {
uint16_t num_events = BT_MESH_TRANSMIT_COUNT(BT_MESH_ADV(buf)->xmit) + 1; uint16_t num_events = BT_MESH_TRANSMIT_COUNT(adv->ctx.xmit) + 1;
uint16_t adv_int; uint16_t adv_int;
struct bt_data ad; struct bt_data ad;
adv_int = BT_MESH_TRANSMIT_INT(BT_MESH_ADV(buf)->xmit); adv_int = BT_MESH_TRANSMIT_INT(adv->ctx.xmit);
LOG_DBG("type %u len %u: %s", BT_MESH_ADV(buf)->type, LOG_DBG("type %u len %u: %s", adv->ctx.type,
buf->len, bt_hex(buf->data, buf->len)); adv->b.len, bt_hex(adv->b.data, adv->b.len));
ad.type = bt_mesh_adv_type[BT_MESH_ADV(buf)->type]; ad.type = bt_mesh_adv_type[adv->ctx.type];
ad.data_len = buf->len; ad.data_len = adv->b.len;
ad.data = buf->data; ad.data = adv->b.data;
bt_data_send(num_events, adv_int, &ad, 1, BT_MESH_ADV(buf)); bt_data_send(num_events, adv_int, &ad, 1, &adv->ctx);
} }
static void adv_thread(void *p1, void *p2, void *p3) static void adv_thread(void *p1, void *p2, void *p3)
{ {
LOG_DBG("started"); LOG_DBG("started");
struct net_buf *buf; struct bt_mesh_adv *adv;
while (enabled) { while (enabled) {
if (IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER)) { if (IS_ENABLED(CONFIG_BT_MESH_GATT_SERVER)) {
buf = bt_mesh_adv_buf_get(K_NO_WAIT); adv = bt_mesh_adv_get(K_NO_WAIT);
if (IS_ENABLED(CONFIG_BT_MESH_PROXY_SOLICITATION) && !buf) { if (IS_ENABLED(CONFIG_BT_MESH_PROXY_SOLICITATION) && !adv) {
(void)bt_mesh_sol_send(); (void)bt_mesh_sol_send();
} }
while (!buf) { while (!adv) {
/* Adv timeout may be set by a call from proxy /* Adv timeout may be set by a call from proxy
* to bt_mesh_adv_gatt_start: * to bt_mesh_adv_gatt_start:
@ -162,58 +161,58 @@ static void adv_thread(void *p1, void *p2, void *p3)
adv_timeout = SYS_FOREVER_MS; adv_timeout = SYS_FOREVER_MS;
(void)bt_mesh_adv_gatt_send(); (void)bt_mesh_adv_gatt_send();
buf = bt_mesh_adv_buf_get(SYS_TIMEOUT_MS(adv_timeout)); adv = bt_mesh_adv_get(SYS_TIMEOUT_MS(adv_timeout));
bt_le_adv_stop(); bt_le_adv_stop();
if (IS_ENABLED(CONFIG_BT_MESH_PROXY_SOLICITATION) && !buf) { if (IS_ENABLED(CONFIG_BT_MESH_PROXY_SOLICITATION) && !adv) {
(void)bt_mesh_sol_send(); (void)bt_mesh_sol_send();
} }
} }
} else { } else {
buf = bt_mesh_adv_buf_get(K_FOREVER); adv = bt_mesh_adv_get(K_FOREVER);
} }
if (!buf) { if (!adv) {
continue; continue;
} }
/* busy == 0 means this was canceled */ /* busy == 0 means this was canceled */
if (BT_MESH_ADV(buf)->busy) { if (adv->ctx.busy) {
BT_MESH_ADV(buf)->busy = 0U; adv->ctx.busy = 0U;
buf_send(buf); adv_send(adv);
} }
net_buf_unref(buf); bt_mesh_adv_unref(adv);
/* Give other threads a chance to run */ /* Give other threads a chance to run */
k_yield(); k_yield();
} }
/* Empty the advertising pool when advertising is disabled */ /* Empty the advertising pool when advertising is disabled */
while ((buf = bt_mesh_adv_buf_get(K_NO_WAIT))) { while ((adv = bt_mesh_adv_get(K_NO_WAIT))) {
bt_mesh_adv_send_start(0, -ENODEV, BT_MESH_ADV(buf)); bt_mesh_adv_send_start(0, -ENODEV, &adv->ctx);
net_buf_unref(buf); bt_mesh_adv_unref(adv);
} }
} }
void bt_mesh_adv_buf_local_ready(void) void bt_mesh_adv_local_ready(void)
{ {
/* Will be handled automatically */ /* Will be handled automatically */
} }
void bt_mesh_adv_buf_relay_ready(void) void bt_mesh_adv_relay_ready(void)
{ {
/* Will be handled automatically */ /* Will be handled automatically */
} }
void bt_mesh_adv_gatt_update(void) void bt_mesh_adv_gatt_update(void)
{ {
bt_mesh_adv_buf_get_cancel(); bt_mesh_adv_get_cancel();
} }
void bt_mesh_adv_buf_terminate(const struct net_buf *buf) void bt_mesh_adv_terminate(struct bt_mesh_adv *adv)
{ {
ARG_UNUSED(buf); ARG_UNUSED(adv);
} }
void bt_mesh_adv_init(void) void bt_mesh_adv_init(void)

View file

@ -17,7 +17,6 @@
#include "rpl.h" #include "rpl.h"
#include "settings.h" #include "settings.h"
#include "crypto.h" #include "crypto.h"
#include "adv.h"
#include "proxy.h" #include "proxy.h"
#include "friend.h" #include "friend.h"
#include "foundation.h" #include "foundation.h"

View file

@ -16,7 +16,6 @@
#include "common/bt_str.h" #include "common/bt_str.h"
#include "adv.h"
#include "mesh.h" #include "mesh.h"
#include "net.h" #include "net.h"
#include "prov.h" #include "prov.h"
@ -256,7 +255,7 @@ static bool net_beacon_send(struct bt_mesh_subnet *sub, struct bt_mesh_beacon *b
.end = beacon_complete, .end = beacon_complete,
}; };
uint32_t now = k_uptime_get_32(); uint32_t now = k_uptime_get_32();
struct net_buf *buf; struct bt_mesh_adv *adv;
uint32_t time_diff; uint32_t time_diff;
uint32_t time_since_last_recv; uint32_t time_since_last_recv;
int err; int err;
@ -271,19 +270,19 @@ static bool net_beacon_send(struct bt_mesh_subnet *sub, struct bt_mesh_beacon *b
return false; return false;
} }
buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_ADV_TAG_LOCAL, adv = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_ADV_TAG_LOCAL,
PROV_XMIT, K_NO_WAIT); PROV_XMIT, K_NO_WAIT);
if (!buf) { if (!adv) {
LOG_ERR("Unable to allocate beacon buffer"); LOG_ERR("Unable to allocate beacon adv");
return true; /* Bail out */ return true; /* Bail out */
} }
err = beacon_create(sub, &buf->b); err = beacon_create(sub, &adv->b);
if (!err) { if (!err) {
bt_mesh_adv_send(buf, &send_cb, beacon); bt_mesh_adv_send(adv, &send_cb, beacon);
} }
net_buf_unref(buf); bt_mesh_adv_unref(adv);
return err != 0; return err != 0;
} }
@ -330,22 +329,22 @@ static int unprovisioned_beacon_send(void)
{ {
const struct bt_mesh_prov *prov; const struct bt_mesh_prov *prov;
uint8_t uri_hash[16] = { 0 }; uint8_t uri_hash[16] = { 0 };
struct net_buf *buf; struct bt_mesh_adv *adv;
uint16_t oob_info; uint16_t oob_info;
LOG_DBG(""); LOG_DBG("");
buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_ADV_TAG_LOCAL, adv = bt_mesh_adv_create(BT_MESH_ADV_BEACON, BT_MESH_ADV_TAG_LOCAL,
UNPROV_XMIT, K_NO_WAIT); UNPROV_XMIT, K_NO_WAIT);
if (!buf) { if (!adv) {
LOG_ERR("Unable to allocate beacon buffer"); LOG_ERR("Unable to allocate beacon adv");
return -ENOBUFS; return -ENOBUFS;
} }
prov = bt_mesh_prov_get(); prov = bt_mesh_prov_get();
net_buf_add_u8(buf, BEACON_TYPE_UNPROVISIONED); net_buf_simple_add_u8(&adv->b, BEACON_TYPE_UNPROVISIONED);
net_buf_add_mem(buf, prov->uuid, 16); net_buf_simple_add_mem(&adv->b, prov->uuid, 16);
if (prov->uri && bt_mesh_s1_str(prov->uri, uri_hash) == 0) { if (prov->uri && bt_mesh_s1_str(prov->uri, uri_hash) == 0) {
oob_info = prov->oob_info | BT_MESH_PROV_OOB_URI; oob_info = prov->oob_info | BT_MESH_PROV_OOB_URI;
@ -353,31 +352,31 @@ static int unprovisioned_beacon_send(void)
oob_info = prov->oob_info; oob_info = prov->oob_info;
} }
net_buf_add_be16(buf, oob_info); net_buf_simple_add_be16(&adv->b, oob_info);
net_buf_add_mem(buf, uri_hash, 4); net_buf_simple_add_mem(&adv->b, uri_hash, 4);
bt_mesh_adv_send(buf, NULL, NULL); bt_mesh_adv_send(adv, NULL, NULL);
net_buf_unref(buf); bt_mesh_adv_unref(adv);
if (prov->uri) { if (prov->uri) {
size_t len; size_t len;
buf = bt_mesh_adv_create(BT_MESH_ADV_URI, BT_MESH_ADV_TAG_LOCAL, adv = bt_mesh_adv_create(BT_MESH_ADV_URI, BT_MESH_ADV_TAG_LOCAL,
UNPROV_XMIT, K_NO_WAIT); UNPROV_XMIT, K_NO_WAIT);
if (!buf) { if (!adv) {
LOG_ERR("Unable to allocate URI buffer"); LOG_ERR("Unable to allocate URI adv");
return -ENOBUFS; return -ENOBUFS;
} }
len = strlen(prov->uri); len = strlen(prov->uri);
if (net_buf_tailroom(buf) < len) { if (net_buf_simple_tailroom(&adv->b) < len) {
LOG_WRN("Too long URI to fit advertising data"); LOG_WRN("Too long URI to fit advertising data");
} else { } else {
net_buf_add_mem(buf, prov->uri, len); net_buf_simple_add_mem(&adv->b, prov->uri, len);
bt_mesh_adv_send(buf, NULL, NULL); bt_mesh_adv_send(adv, NULL, NULL);
} }
net_buf_unref(buf); bt_mesh_adv_unref(adv);
} }
return 0; return 0;

View file

@ -14,7 +14,6 @@
#include "settings.h" #include "settings.h"
#include "heartbeat.h" #include "heartbeat.h"
#include "friend.h" #include "friend.h"
#include "adv.h"
#include "cfg.h" #include "cfg.h"
#include "od_priv_proxy.h" #include "od_priv_proxy.h"
#include "priv_beacon.h" #include "priv_beacon.h"

View file

@ -21,7 +21,6 @@
#include "host/testing.h" #include "host/testing.h"
#include "mesh.h" #include "mesh.h"
#include "adv.h"
#include "net.h" #include "net.h"
#include "rpl.h" #include "rpl.h"
#include "lpn.h" #include "lpn.h"

View file

@ -13,7 +13,6 @@
#include <zephyr/bluetooth/mesh.h> #include <zephyr/bluetooth/mesh.h>
#include "crypto.h" #include "crypto.h"
#include "adv.h"
#include "mesh.h" #include "mesh.h"
#include "net.h" #include "net.h"
#include "app_keys.h" #include "app_keys.h"
@ -1239,7 +1238,7 @@ static void friend_timeout(struct k_work *work)
.start = buf_send_start, .start = buf_send_start,
.end = buf_send_end, .end = buf_send_end,
}; };
struct net_buf *buf; struct bt_mesh_adv *adv;
uint8_t md; uint8_t md;
if (!friend_is_allocated(frnd)) { if (!friend_is_allocated(frnd)) {
@ -1281,19 +1280,19 @@ static void friend_timeout(struct k_work *work)
frnd->queue_size--; frnd->queue_size--;
send_last: send_last:
buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_FRIEND, adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_FRIEND,
FRIEND_XMIT, K_NO_WAIT); FRIEND_XMIT, K_NO_WAIT);
if (!buf) { if (!adv) {
LOG_ERR("Unable to allocate friend adv buffer"); LOG_ERR("Unable to allocate friend adv");
return; return;
} }
net_buf_add_mem(buf, frnd->last->data, frnd->last->len); net_buf_simple_add_mem(&adv->b, frnd->last->data, frnd->last->len);
frnd->pending_req = 0U; frnd->pending_req = 0U;
frnd->pending_buf = 1U; frnd->pending_buf = 1U;
bt_mesh_adv_send(buf, &buf_sent_cb, frnd); bt_mesh_adv_send(adv, &buf_sent_cb, frnd);
net_buf_unref(buf); bt_mesh_adv_unref(adv);
} }
static void subnet_evt(struct bt_mesh_subnet *sub, enum bt_mesh_key_evt evt) static void subnet_evt(struct bt_mesh_subnet *sub, enum bt_mesh_key_evt evt)

View file

@ -18,7 +18,6 @@
#include "common/bt_str.h" #include "common/bt_str.h"
#include "mesh.h" #include "mesh.h"
#include "adv.h"
#include "net.h" #include "net.h"
#include "rpl.h" #include "rpl.h"
#include "transport.h" #include "transport.h"

View file

@ -16,7 +16,6 @@
#include <zephyr/bluetooth/mesh.h> #include <zephyr/bluetooth/mesh.h>
#include "mesh.h" #include "mesh.h"
#include "adv.h"
#include "net.h" #include "net.h"
#include "transport.h" #include "transport.h"
#include "access.h" #include "access.h"

View file

@ -13,7 +13,6 @@
#include <zephyr/bluetooth/mesh.h> #include <zephyr/bluetooth/mesh.h>
#include "crypto.h" #include "crypto.h"
#include "adv.h"
#include "mesh.h" #include "mesh.h"
#include "net.h" #include "net.h"
#include "transport.h" #include "transport.h"

View file

@ -18,7 +18,6 @@
#include <common/bt_str.h> #include <common/bt_str.h>
#include "test.h" #include "test.h"
#include "adv.h"
#include "prov.h" #include "prov.h"
#include "provisioner.h" #include "provisioner.h"
#include "net.h" #include "net.h"

View file

@ -20,7 +20,6 @@
#include "common/bt_str.h" #include "common/bt_str.h"
#include "crypto.h" #include "crypto.h"
#include "adv.h"
#include "mesh.h" #include "mesh.h"
#include "net.h" #include "net.h"
#include "rpl.h" #include "rpl.h"
@ -526,19 +525,19 @@ static int net_loopback(const struct bt_mesh_net_tx *tx, const uint8_t *data,
return 0; return 0;
} }
int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf, int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct bt_mesh_adv *adv,
const struct bt_mesh_send_cb *cb, void *cb_data) const struct bt_mesh_send_cb *cb, void *cb_data)
{ {
const struct bt_mesh_net_cred *cred; const struct bt_mesh_net_cred *cred;
int err; int err;
LOG_DBG("src 0x%04x dst 0x%04x len %u headroom %zu tailroom %zu", tx->src, tx->ctx->addr, LOG_DBG("src 0x%04x dst 0x%04x len %u headroom %zu tailroom %zu", tx->src, tx->ctx->addr,
buf->len, net_buf_headroom(buf), net_buf_tailroom(buf)); adv->b.len, net_buf_simple_headroom(&adv->b), net_buf_simple_tailroom(&adv->b));
LOG_DBG("Payload len %u: %s", buf->len, bt_hex(buf->data, buf->len)); LOG_DBG("Payload len %u: %s", adv->b.len, bt_hex(adv->b.data, adv->b.len));
LOG_DBG("Seq 0x%06x", bt_mesh.seq); LOG_DBG("Seq 0x%06x", bt_mesh.seq);
cred = net_tx_cred_get(tx); cred = net_tx_cred_get(tx);
err = net_header_encode(tx, cred->nid, &buf->b); err = net_header_encode(tx, cred->nid, &adv->b);
if (err) { if (err) {
goto done; goto done;
} }
@ -546,7 +545,7 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
/* Deliver to local network interface if necessary */ /* Deliver to local network interface if necessary */
if (bt_mesh_fixed_group_match(tx->ctx->addr) || if (bt_mesh_fixed_group_match(tx->ctx->addr) ||
bt_mesh_has_addr(tx->ctx->addr)) { bt_mesh_has_addr(tx->ctx->addr)) {
err = net_loopback(tx, buf->data, buf->len); err = net_loopback(tx, adv->b.data, adv->b.len);
/* Local unicast messages should not go out to network */ /* Local unicast messages should not go out to network */
if (BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr) || if (BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr) ||
@ -569,28 +568,28 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
goto done; goto done;
} }
err = net_encrypt(&buf->b, cred, BT_MESH_NET_IVI_TX, BT_MESH_NONCE_NETWORK); err = net_encrypt(&adv->b, cred, BT_MESH_NET_IVI_TX, BT_MESH_NONCE_NETWORK);
if (err) { if (err) {
goto done; goto done;
} }
BT_MESH_ADV(buf)->cb = cb; adv->ctx.cb = cb;
BT_MESH_ADV(buf)->cb_data = cb_data; adv->ctx.cb_data = cb_data;
/* Deliver to GATT Proxy Clients if necessary. */ /* Deliver to GATT Proxy Clients if necessary. */
if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) { if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) {
(void)bt_mesh_proxy_relay(buf, tx->ctx->addr); (void)bt_mesh_proxy_relay(adv, tx->ctx->addr);
} }
/* Deliver to GATT Proxy Servers if necessary. */ /* Deliver to GATT Proxy Servers if necessary. */
if (IS_ENABLED(CONFIG_BT_MESH_PROXY_CLIENT)) { if (IS_ENABLED(CONFIG_BT_MESH_PROXY_CLIENT)) {
(void)bt_mesh_proxy_cli_relay(buf); (void)bt_mesh_proxy_cli_relay(adv);
} }
bt_mesh_adv_send(buf, cb, cb_data); bt_mesh_adv_send(adv, cb, cb_data);
done: done:
net_buf_unref(buf); bt_mesh_adv_unref(adv);
return err; return err;
} }
@ -684,7 +683,7 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
struct bt_mesh_net_rx *rx) struct bt_mesh_net_rx *rx)
{ {
const struct bt_mesh_net_cred *cred; const struct bt_mesh_net_cred *cred;
struct net_buf *buf; struct bt_mesh_adv *adv;
uint8_t transmit; uint8_t transmit;
if (rx->ctx.recv_ttl <= 1U) { if (rx->ctx.recv_ttl <= 1U) {
@ -711,10 +710,10 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
transmit = bt_mesh_net_transmit_get(); transmit = bt_mesh_net_transmit_get();
} }
buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_RELAY, adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_RELAY,
transmit, K_NO_WAIT); transmit, K_NO_WAIT);
if (!buf) { if (!adv) {
LOG_DBG("Out of relay buffers"); LOG_DBG("Out of relay advs");
return; return;
} }
@ -722,23 +721,23 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
sbuf->data[1] &= 0x80; sbuf->data[1] &= 0x80;
sbuf->data[1] |= rx->ctx.recv_ttl - 1U; sbuf->data[1] |= rx->ctx.recv_ttl - 1U;
net_buf_add_mem(buf, sbuf->data, sbuf->len); net_buf_simple_add_mem(&adv->b, sbuf->data, sbuf->len);
cred = &rx->sub->keys[SUBNET_KEY_TX_IDX(rx->sub)].msg; cred = &rx->sub->keys[SUBNET_KEY_TX_IDX(rx->sub)].msg;
LOG_DBG("Relaying packet. TTL is now %u", TTL(buf->data)); LOG_DBG("Relaying packet. TTL is now %u", TTL(adv->b.data));
/* Update NID if RX or RX was with friend credentials */ /* Update NID if RX or RX was with friend credentials */
if (rx->friend_cred) { if (rx->friend_cred) {
buf->data[0] &= 0x80; /* Clear everything except IVI */ adv->b.data[0] &= 0x80; /* Clear everything except IVI */
buf->data[0] |= cred->nid; adv->b.data[0] |= cred->nid;
} }
/* We re-encrypt and obfuscate using the received IVI rather than /* We re-encrypt and obfuscate using the received IVI rather than
* the normal TX IVI (which may be different) since the transport * the normal TX IVI (which may be different) since the transport
* layer nonce includes the IVI. * layer nonce includes the IVI.
*/ */
if (net_encrypt(&buf->b, cred, BT_MESH_NET_IVI_RX(rx), BT_MESH_NONCE_NETWORK)) { if (net_encrypt(&adv->b, cred, BT_MESH_NET_IVI_RX(rx), BT_MESH_NONCE_NETWORK)) {
LOG_ERR("Re-encrypting failed"); LOG_ERR("Re-encrypting failed");
goto done; goto done;
} }
@ -751,15 +750,15 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
(rx->friend_cred || (rx->friend_cred ||
bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED || bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED ||
bt_mesh_priv_gatt_proxy_get() == BT_MESH_PRIV_GATT_PROXY_ENABLED)) { bt_mesh_priv_gatt_proxy_get() == BT_MESH_PRIV_GATT_PROXY_ENABLED)) {
bt_mesh_proxy_relay(buf, rx->ctx.recv_dst); bt_mesh_proxy_relay(adv, rx->ctx.recv_dst);
} }
if (relay_to_adv(rx->net_if) || rx->friend_cred) { if (relay_to_adv(rx->net_if) || rx->friend_cred) {
bt_mesh_adv_send(buf, NULL, NULL); bt_mesh_adv_send(adv, NULL, NULL);
} }
done: done:
net_buf_unref(buf); bt_mesh_adv_unref(adv);
} }
void bt_mesh_net_header_parse(struct net_buf_simple *buf, void bt_mesh_net_header_parse(struct net_buf_simple *buf,

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include "adv.h"
#include "subnet.h" #include "subnet.h"
#include <zephyr/bluetooth/mesh/sar_cfg.h> #include <zephyr/bluetooth/mesh/sar_cfg.h>
@ -291,7 +292,7 @@ bool bt_mesh_net_iv_update(uint32_t iv_index, bool iv_update);
int bt_mesh_net_encode(struct bt_mesh_net_tx *tx, struct net_buf_simple *buf, int bt_mesh_net_encode(struct bt_mesh_net_tx *tx, struct net_buf_simple *buf,
enum bt_mesh_nonce_type type); enum bt_mesh_nonce_type type);
int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf, int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct bt_mesh_adv *adv,
const struct bt_mesh_send_cb *cb, void *cb_data); const struct bt_mesh_send_cb *cb, void *cb_data);
int bt_mesh_net_decode(struct net_buf_simple *in, enum bt_mesh_net_if net_if, int bt_mesh_net_decode(struct net_buf_simple *in, enum bt_mesh_net_if net_if,

View file

@ -11,7 +11,6 @@
#include <zephyr/net/buf.h> #include <zephyr/net/buf.h>
#include "host/testing.h" #include "host/testing.h"
#include "net.h" #include "net.h"
#include "adv.h"
#include "crypto.h" #include "crypto.h"
#include "beacon.h" #include "beacon.h"
#include "prov.h" #include "prov.h"
@ -101,8 +100,8 @@ struct pb_adv {
/* Transaction timeout in seconds */ /* Transaction timeout in seconds */
uint8_t timeout; uint8_t timeout;
/* Pending outgoing buffer(s) */ /* Pending outgoing adv(s) */
struct net_buf *buf[3]; struct bt_mesh_adv *adv[3];
prov_bearer_send_complete_t cb; prov_bearer_send_complete_t cb;
@ -170,24 +169,24 @@ static void free_segments(void)
{ {
int i; int i;
for (i = 0; i < ARRAY_SIZE(link.tx.buf); i++) { for (i = 0; i < ARRAY_SIZE(link.tx.adv); i++) {
struct net_buf *buf = link.tx.buf[i]; struct bt_mesh_adv *adv = link.tx.adv[i];
if (!buf) { if (!adv) {
break; break;
} }
link.tx.buf[i] = NULL; link.tx.adv[i] = NULL;
/* Terminate active adv */ /* Terminate active adv */
if (BT_MESH_ADV(buf)->busy == 0U) { if (adv->ctx.busy == 0U) {
bt_mesh_adv_buf_terminate(buf); bt_mesh_adv_terminate(adv);
} else { } else {
/* Mark as canceled */ /* Mark as canceled */
BT_MESH_ADV(buf)->busy = 0U; adv->ctx.busy = 0U;
} }
net_buf_unref(buf); bt_mesh_adv_unref(adv);
} }
} }
@ -200,7 +199,7 @@ static void prov_clear_tx(void)
{ {
LOG_DBG(""); LOG_DBG("");
/* If this fails, the work handler will not find any buffers to send, /* If this fails, the work handler will not find any advs to send,
* and return without rescheduling. The work handler also checks the * and return without rescheduling. The work handler also checks the
* LINK_ACTIVE flag, so if this call is part of reset_adv_link, it'll * LINK_ACTIVE flag, so if this call is part of reset_adv_link, it'll
* exit early. * exit early.
@ -254,19 +253,19 @@ static void close_link(enum prov_bearer_link_status reason)
cb->link_closed(&bt_mesh_pb_adv, cb_data, reason); cb->link_closed(&bt_mesh_pb_adv, cb_data, reason);
} }
static struct net_buf *adv_buf_create(uint8_t retransmits) static struct bt_mesh_adv *adv_create(uint8_t retransmits)
{ {
struct net_buf *buf; struct bt_mesh_adv *adv;
buf = bt_mesh_adv_create(BT_MESH_ADV_PROV, BT_MESH_ADV_TAG_PROV, adv = bt_mesh_adv_create(BT_MESH_ADV_PROV, BT_MESH_ADV_TAG_PROV,
BT_MESH_TRANSMIT(retransmits, 20), BT_MESH_TRANSMIT(retransmits, 20),
BUF_TIMEOUT); BUF_TIMEOUT);
if (!buf) { if (!adv) {
LOG_ERR("Out of provisioning buffers"); LOG_ERR("Out of provisioning advs");
return NULL; return NULL;
} }
return buf; return adv;
} }
static void ack_complete(uint16_t duration, int err, void *user_data) static void ack_complete(uint16_t duration, int err, void *user_data)
@ -328,7 +327,7 @@ static void gen_prov_ack_send(uint8_t xact_id)
.start = ack_complete, .start = ack_complete,
}; };
const struct bt_mesh_send_cb *complete; const struct bt_mesh_send_cb *complete;
struct net_buf *buf; struct bt_mesh_adv *adv;
bool pending = atomic_test_and_set_bit(link.flags, ADV_ACK_PENDING); bool pending = atomic_test_and_set_bit(link.flags, ADV_ACK_PENDING);
LOG_DBG("xact_id 0x%x", xact_id); LOG_DBG("xact_id 0x%x", xact_id);
@ -338,8 +337,8 @@ static void gen_prov_ack_send(uint8_t xact_id)
return; return;
} }
buf = adv_buf_create(RETRANSMITS_ACK); adv = adv_create(RETRANSMITS_ACK);
if (!buf) { if (!adv) {
atomic_clear_bit(link.flags, ADV_ACK_PENDING); atomic_clear_bit(link.flags, ADV_ACK_PENDING);
return; return;
} }
@ -351,12 +350,12 @@ static void gen_prov_ack_send(uint8_t xact_id)
complete = &cb; complete = &cb;
} }
net_buf_add_be32(buf, link.id); net_buf_simple_add_be32(&adv->b, link.id);
net_buf_add_u8(buf, xact_id); net_buf_simple_add_u8(&adv->b, xact_id);
net_buf_add_u8(buf, GPC_ACK); net_buf_simple_add_u8(&adv->b, GPC_ACK);
bt_mesh_adv_send(buf, complete, NULL); bt_mesh_adv_send(adv, complete, NULL);
net_buf_unref(buf); bt_mesh_adv_unref(adv);
} }
static void gen_prov_cont(struct prov_rx *rx, struct net_buf_simple *buf) static void gen_prov_cont(struct prov_rx *rx, struct net_buf_simple *buf)
@ -431,7 +430,7 @@ static void gen_prov_ack(struct prov_rx *rx, struct net_buf_simple *buf)
{ {
LOG_DBG("len %u", buf->len); LOG_DBG("len %u", buf->len);
if (!link.tx.buf[0]) { if (!link.tx.adv[0]) {
return; return;
} }
@ -596,20 +595,20 @@ static void send_reliable(void)
{ {
int i; int i;
for (i = 0; i < ARRAY_SIZE(link.tx.buf); i++) { for (i = 0; i < ARRAY_SIZE(link.tx.adv); i++) {
struct net_buf *buf = link.tx.buf[i]; struct bt_mesh_adv *adv = link.tx.adv[i];
if (!buf) { if (!adv) {
break; break;
} }
if (BT_MESH_ADV(buf)->busy) { if (adv->ctx.busy) {
continue; continue;
} }
LOG_DBG("%u bytes: %s", buf->len, bt_hex(buf->data, buf->len)); LOG_DBG("%u bytes: %s", adv->b.len, bt_hex(adv->b.data, adv->b.len));
bt_mesh_adv_send(buf, NULL, NULL); bt_mesh_adv_send(adv, NULL, NULL);
} }
k_work_reschedule(&link.tx.retransmit, RETRANSMIT_TIMEOUT); k_work_reschedule(&link.tx.retransmit, RETRANSMIT_TIMEOUT);
@ -633,30 +632,30 @@ static void prov_retransmit(struct k_work *work)
send_reliable(); send_reliable();
} }
static struct net_buf *ctl_buf_create(uint8_t op, const void *data, uint8_t data_len, static struct bt_mesh_adv *ctl_adv_create(uint8_t op, const void *data, uint8_t data_len,
uint8_t retransmits) uint8_t retransmits)
{ {
struct net_buf *buf; struct bt_mesh_adv *adv;
LOG_DBG("op 0x%02x data_len %u", op, data_len); LOG_DBG("op 0x%02x data_len %u", op, data_len);
buf = adv_buf_create(retransmits); adv = adv_create(retransmits);
if (!buf) { if (!adv) {
return NULL; return NULL;
} }
net_buf_add_be32(buf, link.id); net_buf_simple_add_be32(&adv->b, link.id);
/* Transaction ID, always 0 for Bearer messages */ /* Transaction ID, always 0 for Bearer messages */
net_buf_add_u8(buf, 0x00); net_buf_simple_add_u8(&adv->b, 0x00);
net_buf_add_u8(buf, GPC_CTL(op)); net_buf_simple_add_u8(&adv->b, GPC_CTL(op));
net_buf_add_mem(buf, data, data_len); net_buf_simple_add_mem(&adv->b, data, data_len);
return buf; return adv;
} }
static int bearer_ctl_send(struct net_buf *buf) static int bearer_ctl_send(struct bt_mesh_adv *adv)
{ {
if (!buf) { if (!adv) {
return -ENOMEM; return -ENOMEM;
} }
@ -664,23 +663,23 @@ static int bearer_ctl_send(struct net_buf *buf)
k_work_reschedule(&link.prot_timer, bt_mesh_prov_protocol_timeout_get()); k_work_reschedule(&link.prot_timer, bt_mesh_prov_protocol_timeout_get());
link.tx.start = k_uptime_get(); link.tx.start = k_uptime_get();
link.tx.buf[0] = buf; link.tx.adv[0] = adv;
send_reliable(); send_reliable();
return 0; return 0;
} }
static int bearer_ctl_send_unacked(struct net_buf *buf, void *user_data) static int bearer_ctl_send_unacked(struct bt_mesh_adv *adv, void *user_data)
{ {
if (!buf) { if (!adv) {
return -ENOMEM; return -ENOMEM;
} }
prov_clear_tx(); prov_clear_tx();
k_work_reschedule(&link.prot_timer, bt_mesh_prov_protocol_timeout_get()); k_work_reschedule(&link.prot_timer, bt_mesh_prov_protocol_timeout_get());
bt_mesh_adv_send(buf, &buf_sent_cb, user_data); bt_mesh_adv_send(adv, &buf_sent_cb, user_data);
net_buf_unref(buf); bt_mesh_adv_unref(adv);
return 0; return 0;
} }
@ -688,26 +687,26 @@ static int bearer_ctl_send_unacked(struct net_buf *buf, void *user_data)
static int prov_send_adv(struct net_buf_simple *msg, static int prov_send_adv(struct net_buf_simple *msg,
prov_bearer_send_complete_t cb, void *cb_data) prov_bearer_send_complete_t cb, void *cb_data)
{ {
struct net_buf *start, *buf; struct bt_mesh_adv *start, *adv;
uint8_t seg_len, seg_id; uint8_t seg_len, seg_id;
prov_clear_tx(); prov_clear_tx();
k_work_reschedule(&link.prot_timer, bt_mesh_prov_protocol_timeout_get()); k_work_reschedule(&link.prot_timer, bt_mesh_prov_protocol_timeout_get());
start = adv_buf_create(RETRANSMITS_RELIABLE); start = adv_create(RETRANSMITS_RELIABLE);
if (!start) { if (!start) {
return -ENOBUFS; return -ENOBUFS;
} }
link.tx.id = next_transaction_id(link.tx.id); link.tx.id = next_transaction_id(link.tx.id);
net_buf_add_be32(start, link.id); net_buf_simple_add_be32(&start->b, link.id);
net_buf_add_u8(start, link.tx.id); net_buf_simple_add_u8(&start->b, link.tx.id);
net_buf_add_u8(start, GPC_START(last_seg(msg->len))); net_buf_simple_add_u8(&start->b, GPC_START(last_seg(msg->len)));
net_buf_add_be16(start, msg->len); net_buf_simple_add_be16(&start->b, msg->len);
net_buf_add_u8(start, bt_mesh_fcs_calc(msg->data, msg->len)); net_buf_simple_add_u8(&start->b, bt_mesh_fcs_calc(msg->data, msg->len));
link.tx.buf[0] = start; link.tx.adv[0] = start;
link.tx.cb = cb; link.tx.cb = cb;
link.tx.cb_data = cb_data; link.tx.cb_data = cb_data;
link.tx.start = k_uptime_get(); link.tx.start = k_uptime_get();
@ -716,33 +715,33 @@ static int prov_send_adv(struct net_buf_simple *msg,
seg_len = MIN(msg->len, START_PAYLOAD_MAX); seg_len = MIN(msg->len, START_PAYLOAD_MAX);
LOG_DBG("seg 0 len %u: %s", seg_len, bt_hex(msg->data, seg_len)); LOG_DBG("seg 0 len %u: %s", seg_len, bt_hex(msg->data, seg_len));
net_buf_add_mem(start, msg->data, seg_len); net_buf_simple_add_mem(&start->b, msg->data, seg_len);
net_buf_simple_pull(msg, seg_len); net_buf_simple_pull(msg, seg_len);
buf = start; adv = start;
for (seg_id = 1U; msg->len > 0; seg_id++) { for (seg_id = 1U; msg->len > 0; seg_id++) {
if (seg_id >= ARRAY_SIZE(link.tx.buf)) { if (seg_id >= ARRAY_SIZE(link.tx.adv)) {
LOG_ERR("Too big message"); LOG_ERR("Too big message");
free_segments(); free_segments();
return -E2BIG; return -E2BIG;
} }
buf = adv_buf_create(RETRANSMITS_RELIABLE); adv = adv_create(RETRANSMITS_RELIABLE);
if (!buf) { if (!adv) {
free_segments(); free_segments();
return -ENOBUFS; return -ENOBUFS;
} }
link.tx.buf[seg_id] = buf; link.tx.adv[seg_id] = adv;
seg_len = MIN(msg->len, CONT_PAYLOAD_MAX); seg_len = MIN(msg->len, CONT_PAYLOAD_MAX);
LOG_DBG("seg %u len %u: %s", seg_id, seg_len, bt_hex(msg->data, seg_len)); LOG_DBG("seg %u len %u: %s", seg_id, seg_len, bt_hex(msg->data, seg_len));
net_buf_add_be32(buf, link.id); net_buf_simple_add_be32(&adv->b, link.id);
net_buf_add_u8(buf, link.tx.id); net_buf_simple_add_u8(&adv->b, link.tx.id);
net_buf_add_u8(buf, GPC_CONT(seg_id)); net_buf_simple_add_u8(&adv->b, GPC_CONT(seg_id));
net_buf_add_mem(buf, msg->data, seg_len); net_buf_simple_add_mem(&adv->b, msg->data, seg_len);
net_buf_simple_pull(msg, seg_len); net_buf_simple_pull(msg, seg_len);
} }
@ -776,7 +775,7 @@ static void link_open(struct prov_rx *rx, struct net_buf_simple *buf)
LOG_DBG("Resending link ack"); LOG_DBG("Resending link ack");
/* Ignore errors, message will be attempted again if we keep receiving link open: */ /* Ignore errors, message will be attempted again if we keep receiving link open: */
(void)bearer_ctl_send_unacked( (void)bearer_ctl_send_unacked(
ctl_buf_create(LINK_ACK, NULL, 0, RETRANSMITS_ACK), ctl_adv_create(LINK_ACK, NULL, 0, RETRANSMITS_ACK),
(void *)PROV_BEARER_LINK_STATUS_SUCCESS); (void *)PROV_BEARER_LINK_STATUS_SUCCESS);
return; return;
} }
@ -791,7 +790,7 @@ static void link_open(struct prov_rx *rx, struct net_buf_simple *buf)
net_buf_simple_reset(link.rx.buf); net_buf_simple_reset(link.rx.buf);
err = bearer_ctl_send_unacked( err = bearer_ctl_send_unacked(
ctl_buf_create(LINK_ACK, NULL, 0, RETRANSMITS_ACK), ctl_adv_create(LINK_ACK, NULL, 0, RETRANSMITS_ACK),
(void *)PROV_BEARER_LINK_STATUS_SUCCESS); (void *)PROV_BEARER_LINK_STATUS_SUCCESS);
if (err) { if (err) {
reset_adv_link(); reset_adv_link();
@ -891,7 +890,7 @@ static int prov_link_open(const uint8_t uuid[16], uint8_t timeout,
net_buf_simple_reset(link.rx.buf); net_buf_simple_reset(link.rx.buf);
return bearer_ctl_send(ctl_buf_create(LINK_OPEN, uuid, 16, RETRANSMITS_RELIABLE)); return bearer_ctl_send(ctl_adv_create(LINK_OPEN, uuid, 16, RETRANSMITS_RELIABLE));
} }
static int prov_link_accept(const struct prov_bearer_cb *cb, void *cb_data) static int prov_link_accept(const struct prov_bearer_cb *cb, void *cb_data)
@ -936,7 +935,7 @@ static void prov_link_close(enum prov_bearer_link_status status)
link.tx.timeout = CLOSING_TIMEOUT; link.tx.timeout = CLOSING_TIMEOUT;
/* Ignore errors, the link will time out eventually if this doesn't get sent */ /* Ignore errors, the link will time out eventually if this doesn't get sent */
bearer_ctl_send_unacked( bearer_ctl_send_unacked(
ctl_buf_create(LINK_CLOSE, &status, 1, RETRANSMITS_LINK_CLOSE), ctl_adv_create(LINK_CLOSE, &status, 1, RETRANSMITS_LINK_CLOSE),
(void *)status); (void *)status);
} }

View file

@ -8,7 +8,6 @@
#include <zephyr/bluetooth/conn.h> #include <zephyr/bluetooth/conn.h>
#include "net.h" #include "net.h"
#include "proxy.h" #include "proxy.h"
#include "adv.h"
#include "prov.h" #include "prov.h"
#include "pb_gatt.h" #include "pb_gatt.h"
#include "proxy_msg.h" #include "proxy_msg.h"

View file

@ -16,7 +16,6 @@
#include <zephyr/bluetooth/mesh.h> #include <zephyr/bluetooth/mesh.h>
#include "mesh.h" #include "mesh.h"
#include "adv.h"
#include "net.h" #include "net.h"
#include "rpl.h" #include "rpl.h"
#include "transport.h" #include "transport.h"

View file

@ -17,7 +17,6 @@
#include "common/bt_str.h" #include "common/bt_str.h"
#include "mesh.h" #include "mesh.h"
#include "adv.h"
#include "net.h" #include "net.h"
#include "rpl.h" #include "rpl.h"
#include "transport.h" #include "transport.h"

View file

@ -5,7 +5,6 @@
*/ */
#include <zephyr/bluetooth/mesh.h> #include <zephyr/bluetooth/mesh.h>
#include "net.h" #include "net.h"
#include "adv.h"
#include <zephyr/bluetooth/conn.h> #include <zephyr/bluetooth/conn.h>
#include "proxy.h" #include "proxy.h"
#include "foundation.h" #include "foundation.h"

View file

@ -20,7 +20,6 @@
#include "common/bt_str.h" #include "common/bt_str.h"
#include "crypto.h" #include "crypto.h"
#include "adv.h"
#include "mesh.h" #include "mesh.h"
#include "net.h" #include "net.h"
#include "rpl.h" #include "rpl.h"

View file

@ -21,7 +21,6 @@
#include "common/bt_str.h" #include "common/bt_str.h"
#include "crypto.h" #include "crypto.h"
#include "adv.h"
#include "mesh.h" #include "mesh.h"
#include "net.h" #include "net.h"
#include "rpl.h" #include "rpl.h"

View file

@ -34,6 +34,6 @@ int bt_mesh_proxy_adv_start(void);
void bt_mesh_proxy_identity_start(struct bt_mesh_subnet *sub, bool private); void bt_mesh_proxy_identity_start(struct bt_mesh_subnet *sub, bool private);
void bt_mesh_proxy_identity_stop(struct bt_mesh_subnet *sub); void bt_mesh_proxy_identity_stop(struct bt_mesh_subnet *sub);
bool bt_mesh_proxy_relay(struct net_buf *buf, uint16_t dst); bool bt_mesh_proxy_relay(struct bt_mesh_adv *adv, uint16_t dst);
void bt_mesh_proxy_addr_add(struct net_buf_simple *buf, uint16_t addr); void bt_mesh_proxy_addr_add(struct net_buf_simple *buf, uint16_t addr);
uint8_t bt_mesh_proxy_srv_connected_cnt(void); uint8_t bt_mesh_proxy_srv_connected_cnt(void);

View file

@ -16,7 +16,6 @@
#include <zephyr/bluetooth/mesh.h> #include <zephyr/bluetooth/mesh.h>
#include "mesh.h" #include "mesh.h"
#include "adv.h"
#include "net.h" #include "net.h"
#include "rpl.h" #include "rpl.h"
#include "transport.h" #include "transport.h"
@ -79,7 +78,7 @@ static struct bt_mesh_proxy_server *find_proxy_srv_by_conn(struct bt_conn *conn)
return NULL; return NULL;
} }
bool bt_mesh_proxy_cli_relay(struct net_buf *buf) bool bt_mesh_proxy_cli_relay(struct bt_mesh_adv *adv)
{ {
bool relayed = false; bool relayed = false;
int i; int i;
@ -91,7 +90,7 @@ bool bt_mesh_proxy_cli_relay(struct net_buf *buf)
continue; continue;
} }
if (bt_mesh_proxy_relay_send(server->role->conn, buf)) { if (bt_mesh_proxy_relay_send(server->role->conn, adv)) {
continue; continue;
} }

View file

@ -8,6 +8,6 @@
void bt_mesh_proxy_cli_adv_recv(const struct bt_le_scan_recv_info *info, void bt_mesh_proxy_cli_adv_recv(const struct bt_le_scan_recv_info *info,
struct net_buf_simple *buf); struct net_buf_simple *buf);
bool bt_mesh_proxy_cli_relay(struct net_buf *buf); bool bt_mesh_proxy_cli_relay(struct bt_mesh_adv *adv);
bool bt_mesh_proxy_cli_is_connected(uint16_t net_idx); bool bt_mesh_proxy_cli_is_connected(uint16_t net_idx);

View file

@ -21,7 +21,6 @@
#include "common/bt_str.h" #include "common/bt_str.h"
#include "mesh.h" #include "mesh.h"
#include "adv.h"
#include "net.h" #include "net.h"
#include "rpl.h" #include "rpl.h"
#include "transport.h" #include "transport.h"
@ -196,12 +195,12 @@ int bt_mesh_proxy_msg_send(struct bt_conn *conn, uint8_t type,
static void buf_send_end(struct bt_conn *conn, void *user_data) static void buf_send_end(struct bt_conn *conn, void *user_data)
{ {
struct net_buf *buf = user_data; struct bt_mesh_adv *adv = user_data;
net_buf_unref(buf); bt_mesh_adv_unref(adv);
} }
int bt_mesh_proxy_relay_send(struct bt_conn *conn, struct net_buf *buf) int bt_mesh_proxy_relay_send(struct bt_conn *conn, struct bt_mesh_adv *adv)
{ {
int err; int err;
@ -211,12 +210,12 @@ int bt_mesh_proxy_relay_send(struct bt_conn *conn, struct net_buf *buf)
* so we need to make a copy. * so we need to make a copy.
*/ */
net_buf_simple_reserve(&msg, 1); net_buf_simple_reserve(&msg, 1);
net_buf_simple_add_mem(&msg, buf->data, buf->len); net_buf_simple_add_mem(&msg, adv->b.data, adv->b.len);
err = bt_mesh_proxy_msg_send(conn, BT_MESH_PROXY_NET_PDU, err = bt_mesh_proxy_msg_send(conn, BT_MESH_PROXY_NET_PDU,
&msg, buf_send_end, net_buf_ref(buf)); &msg, buf_send_end, bt_mesh_adv_ref(adv));
bt_mesh_adv_send_start(0, err, BT_MESH_ADV(buf)); bt_mesh_adv_send_start(0, err, &adv->ctx);
if (err) { if (err) {
LOG_ERR("Failed to send proxy message (err %d)", err); LOG_ERR("Failed to send proxy message (err %d)", err);
@ -225,7 +224,7 @@ int bt_mesh_proxy_relay_send(struct bt_conn *conn, struct net_buf *buf)
* which is just opaque data to segment_and send) reference given * which is just opaque data to segment_and send) reference given
* to segment_and_send() here. * to segment_and_send() here.
*/ */
net_buf_unref(buf); bt_mesh_adv_unref(adv);
} }
return err; return err;

View file

@ -51,7 +51,7 @@ ssize_t bt_mesh_proxy_msg_recv(struct bt_conn *conn,
int bt_mesh_proxy_msg_send(struct bt_conn *conn, uint8_t type, int bt_mesh_proxy_msg_send(struct bt_conn *conn, uint8_t type,
struct net_buf_simple *msg, struct net_buf_simple *msg,
bt_gatt_complete_func_t end, void *user_data); bt_gatt_complete_func_t end, void *user_data);
int bt_mesh_proxy_relay_send(struct bt_conn *conn, struct net_buf *buf); int bt_mesh_proxy_relay_send(struct bt_conn *conn, struct bt_mesh_adv *adv);
struct bt_mesh_proxy_role *bt_mesh_proxy_role_setup(struct bt_conn *conn, struct bt_mesh_proxy_role *bt_mesh_proxy_role_setup(struct bt_conn *conn,
proxy_send_cb_t send, proxy_send_cb_t send,
proxy_recv_cb_t recv); proxy_recv_cb_t recv);

View file

@ -20,7 +20,6 @@
#include "common/bt_str.h" #include "common/bt_str.h"
#include "mesh.h" #include "mesh.h"
#include "adv.h"
#include "net.h" #include "net.h"
#include "rpl.h" #include "rpl.h"
#include "transport.h" #include "transport.h"
@ -1022,12 +1021,12 @@ static bool client_filter_match(struct bt_mesh_proxy_client *client,
return false; return false;
} }
bool bt_mesh_proxy_relay(struct net_buf *buf, uint16_t dst) bool bt_mesh_proxy_relay(struct bt_mesh_adv *adv, uint16_t dst)
{ {
bool relayed = false; bool relayed = false;
int i; int i;
LOG_DBG("%u bytes to dst 0x%04x", buf->len, dst); LOG_DBG("%u bytes to dst 0x%04x", adv->b.len, dst);
for (i = 0; i < ARRAY_SIZE(clients); i++) { for (i = 0; i < ARRAY_SIZE(clients); i++) {
struct bt_mesh_proxy_client *client = &clients[i]; struct bt_mesh_proxy_client *client = &clients[i];
@ -1040,7 +1039,7 @@ bool bt_mesh_proxy_relay(struct net_buf *buf, uint16_t dst)
continue; continue;
} }
if (bt_mesh_proxy_relay_send(client->cli->conn, buf)) { if (bt_mesh_proxy_relay_send(client->cli->conn, adv)) {
continue; continue;
} }

View file

@ -20,7 +20,6 @@
#include <zephyr/bluetooth/mesh.h> #include <zephyr/bluetooth/mesh.h>
#include "mesh.h" #include "mesh.h"
#include "adv.h"
#include "net.h" #include "net.h"
#include "rpl.h" #include "rpl.h"
#include "settings.h" #include "settings.h"

View file

@ -14,7 +14,6 @@
#include <zephyr/bluetooth/mesh/sar_cfg.h> #include <zephyr/bluetooth/mesh/sar_cfg.h>
#include <zephyr/bluetooth/mesh/keys.h> #include <zephyr/bluetooth/mesh/keys.h>
#include "access.h" #include "access.h"
#include "adv.h"
#include "prov.h" #include "prov.h"
#include "crypto.h" #include "crypto.h"
#include "rpr.h" #include "rpr.h"

View file

@ -12,7 +12,6 @@
#include <zephyr/bluetooth/hci.h> #include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/uuid.h> #include <zephyr/bluetooth/uuid.h>
#include "access.h" #include "access.h"
#include "adv.h"
#include "cfg.h" #include "cfg.h"
#include "crypto.h" #include "crypto.h"
#include "mesh.h" #include "mesh.h"

View file

@ -6,7 +6,6 @@
#include <zephyr/bluetooth/mesh.h> #include <zephyr/bluetooth/mesh.h>
#include "adv.h"
#include "net.h" #include "net.h"
#include "statistic.h" #include "statistic.h"
@ -22,24 +21,24 @@ void bt_mesh_stat_reset(void)
memset(&stat, 0, sizeof(struct bt_mesh_statistic)); memset(&stat, 0, sizeof(struct bt_mesh_statistic));
} }
void bt_mesh_stat_planned_count(struct bt_mesh_adv *adv) void bt_mesh_stat_planned_count(struct bt_mesh_adv_ctx *ctx)
{ {
if (adv->tag == BT_MESH_ADV_TAG_LOCAL) { if (ctx->tag == BT_MESH_ADV_TAG_LOCAL) {
stat.tx_local_planned++; stat.tx_local_planned++;
} else if (adv->tag == BT_MESH_ADV_TAG_RELAY) { } else if (ctx->tag == BT_MESH_ADV_TAG_RELAY) {
stat.tx_adv_relay_planned++; stat.tx_adv_relay_planned++;
} else if (adv->tag == BT_MESH_ADV_TAG_FRIEND) { } else if (ctx->tag == BT_MESH_ADV_TAG_FRIEND) {
stat.tx_friend_planned++; stat.tx_friend_planned++;
} }
} }
void bt_mesh_stat_succeeded_count(struct bt_mesh_adv *adv) void bt_mesh_stat_succeeded_count(struct bt_mesh_adv_ctx *ctx)
{ {
if (adv->tag == BT_MESH_ADV_TAG_LOCAL) { if (ctx->tag == BT_MESH_ADV_TAG_LOCAL) {
stat.tx_local_succeeded++; stat.tx_local_succeeded++;
} else if (adv->tag == BT_MESH_ADV_TAG_RELAY) { } else if (ctx->tag == BT_MESH_ADV_TAG_RELAY) {
stat.tx_adv_relay_succeeded++; stat.tx_adv_relay_succeeded++;
} else if (adv->tag == BT_MESH_ADV_TAG_FRIEND) { } else if (ctx->tag == BT_MESH_ADV_TAG_FRIEND) {
stat.tx_friend_succeeded++; stat.tx_friend_succeeded++;
} }
} }

View file

@ -7,8 +7,8 @@
#ifndef ZEPHYR_SUBSYS_BLUETOOTH_MESH_STATISTIC_H_ #ifndef ZEPHYR_SUBSYS_BLUETOOTH_MESH_STATISTIC_H_
#define ZEPHYR_SUBSYS_BLUETOOTH_MESH_STATISTIC_H_ #define ZEPHYR_SUBSYS_BLUETOOTH_MESH_STATISTIC_H_
void bt_mesh_stat_planned_count(struct bt_mesh_adv *adv); void bt_mesh_stat_planned_count(struct bt_mesh_adv_ctx *ctx);
void bt_mesh_stat_succeeded_count(struct bt_mesh_adv *adv); void bt_mesh_stat_succeeded_count(struct bt_mesh_adv_ctx *ctx);
void bt_mesh_stat_rx(enum bt_mesh_net_if net_if); void bt_mesh_stat_rx(enum bt_mesh_net_if net_if);
#endif /* ZEPHYR_SUBSYS_BLUETOOTH_MESH_STATISTIC_H_ */ #endif /* ZEPHYR_SUBSYS_BLUETOOTH_MESH_STATISTIC_H_ */

View file

@ -22,7 +22,6 @@
#include "common/bt_str.h" #include "common/bt_str.h"
#include "crypto.h" #include "crypto.h"
#include "adv.h"
#include "mesh.h" #include "mesh.h"
#include "net.h" #include "net.h"
#include "lpn.h" #include "lpn.h"

View file

@ -22,7 +22,6 @@
#include "host/testing.h" #include "host/testing.h"
#include "crypto.h" #include "crypto.h"
#include "adv.h"
#include "mesh.h" #include "mesh.h"
#include "net.h" #include "net.h"
#include "app_keys.h" #include "app_keys.h"
@ -122,26 +121,26 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu,
const struct bt_mesh_send_cb *cb, void *cb_data, const struct bt_mesh_send_cb *cb, void *cb_data,
const uint8_t *ctl_op) const uint8_t *ctl_op)
{ {
struct net_buf *buf; struct bt_mesh_adv *adv;
buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL,
tx->xmit, BUF_TIMEOUT); tx->xmit, BUF_TIMEOUT);
if (!buf) { if (!adv) {
LOG_ERR("Out of network buffers"); LOG_ERR("Out of network advs");
return -ENOBUFS; return -ENOBUFS;
} }
net_buf_reserve(buf, BT_MESH_NET_HDR_LEN); net_buf_simple_reserve(&adv->b, BT_MESH_NET_HDR_LEN);
if (ctl_op) { if (ctl_op) {
net_buf_add_u8(buf, TRANS_CTL_HDR(*ctl_op, 0)); net_buf_simple_add_u8(&adv->b, TRANS_CTL_HDR(*ctl_op, 0));
} else if (BT_MESH_IS_DEV_KEY(tx->ctx->app_idx)) { } else if (BT_MESH_IS_DEV_KEY(tx->ctx->app_idx)) {
net_buf_add_u8(buf, UNSEG_HDR(0, 0)); net_buf_simple_add_u8(&adv->b, UNSEG_HDR(0, 0));
} else { } else {
net_buf_add_u8(buf, UNSEG_HDR(1, tx->aid)); net_buf_simple_add_u8(&adv->b, UNSEG_HDR(1, tx->aid));
} }
net_buf_add_mem(buf, sdu->data, sdu->len); net_buf_simple_add_mem(&adv->b, sdu->data, sdu->len);
if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) {
if (!bt_mesh_friend_queue_has_space(tx->sub->net_idx, if (!bt_mesh_friend_queue_has_space(tx->sub->net_idx,
@ -149,7 +148,7 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu,
NULL, 1)) { NULL, 1)) {
if (BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { if (BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
LOG_ERR("Not enough space in Friend Queue"); LOG_ERR("Not enough space in Friend Queue");
net_buf_unref(buf); bt_mesh_adv_unref(adv);
return -ENOBUFS; return -ENOBUFS;
} else { } else {
LOG_WRN("No space in Friend Queue"); LOG_WRN("No space in Friend Queue");
@ -158,19 +157,19 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu,
} }
if (bt_mesh_friend_enqueue_tx(tx, BT_MESH_FRIEND_PDU_SINGLE, if (bt_mesh_friend_enqueue_tx(tx, BT_MESH_FRIEND_PDU_SINGLE,
NULL, 1, &buf->b) && NULL, 1, &adv->b) &&
BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
/* PDUs for a specific Friend should only go /* PDUs for a specific Friend should only go
* out through the Friend Queue. * out through the Friend Queue.
*/ */
net_buf_unref(buf); bt_mesh_adv_unref(adv);
send_cb_finalize(cb, cb_data); send_cb_finalize(cb, cb_data);
return 0; return 0;
} }
} }
send: send:
return bt_mesh_net_send(tx, buf, cb, cb_data); return bt_mesh_net_send(tx, adv, cb, cb_data);
} }
static inline uint8_t seg_len(bool ctl) static inline uint8_t seg_len(bool ctl)
@ -405,7 +404,7 @@ static void seg_tx_send_unacked(struct seg_tx *tx)
(uint16_t)(tx->seq_auth & TRANS_SEQ_ZERO_MASK), tx->attempts_left); (uint16_t)(tx->seq_auth & TRANS_SEQ_ZERO_MASK), tx->attempts_left);
while (tx->seg_o <= tx->seg_n) { while (tx->seg_o <= tx->seg_n) {
struct net_buf *seg; struct bt_mesh_adv *seg;
int err; int err;
if (!tx->seg[tx->seg_o]) { if (!tx->seg[tx->seg_o]) {
@ -421,7 +420,7 @@ static void seg_tx_send_unacked(struct seg_tx *tx)
goto end; goto end;
} }
net_buf_reserve(seg, BT_MESH_NET_HDR_LEN); net_buf_simple_reserve(&seg->b, BT_MESH_NET_HDR_LEN);
seg_tx_buf_build(tx, tx->seg_o, &seg->b); seg_tx_buf_build(tx, tx->seg_o, &seg->b);
LOG_DBG("Sending %u/%u", tx->seg_o, tx->seg_n); LOG_DBG("Sending %u/%u", tx->seg_o, tx->seg_n);

View file

@ -22,7 +22,6 @@
#include "host/testing.h" #include "host/testing.h"
#include "crypto.h" #include "crypto.h"
#include "adv.h"
#include "mesh.h" #include "mesh.h"
#include "net.h" #include "net.h"
#include "app_keys.h" #include "app_keys.h"
@ -129,26 +128,26 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu,
const struct bt_mesh_send_cb *cb, void *cb_data, const struct bt_mesh_send_cb *cb, void *cb_data,
const uint8_t *ctl_op) const uint8_t *ctl_op)
{ {
struct net_buf *buf; struct bt_mesh_adv *adv;
buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL,
tx->xmit, BUF_TIMEOUT); tx->xmit, BUF_TIMEOUT);
if (!buf) { if (!adv) {
LOG_ERR("Out of network buffers"); LOG_ERR("Out of network advs");
return -ENOBUFS; return -ENOBUFS;
} }
net_buf_reserve(buf, BT_MESH_NET_HDR_LEN); net_buf_simple_reserve(&adv->b, BT_MESH_NET_HDR_LEN);
if (ctl_op) { if (ctl_op) {
net_buf_add_u8(buf, TRANS_CTL_HDR(*ctl_op, 0)); net_buf_simple_add_u8(&adv->b, TRANS_CTL_HDR(*ctl_op, 0));
} else if (BT_MESH_IS_DEV_KEY(tx->ctx->app_idx)) { } else if (BT_MESH_IS_DEV_KEY(tx->ctx->app_idx)) {
net_buf_add_u8(buf, UNSEG_HDR(0, 0)); net_buf_simple_add_u8(&adv->b, UNSEG_HDR(0, 0));
} else { } else {
net_buf_add_u8(buf, UNSEG_HDR(1, tx->aid)); net_buf_simple_add_u8(&adv->b, UNSEG_HDR(1, tx->aid));
} }
net_buf_add_mem(buf, sdu->data, sdu->len); net_buf_simple_add_mem(&adv->b, sdu->data, sdu->len);
if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) {
if (!bt_mesh_friend_queue_has_space(tx->sub->net_idx, if (!bt_mesh_friend_queue_has_space(tx->sub->net_idx,
@ -156,7 +155,7 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu,
NULL, 1)) { NULL, 1)) {
if (BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { if (BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
LOG_ERR("Not enough space in Friend Queue"); LOG_ERR("Not enough space in Friend Queue");
net_buf_unref(buf); bt_mesh_adv_unref(adv);
return -ENOBUFS; return -ENOBUFS;
} }
@ -165,19 +164,19 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu,
} }
if (bt_mesh_friend_enqueue_tx(tx, BT_MESH_FRIEND_PDU_SINGLE, if (bt_mesh_friend_enqueue_tx(tx, BT_MESH_FRIEND_PDU_SINGLE,
NULL, 1, &buf->b) && NULL, 1, &adv->b) &&
BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
/* PDUs for a specific Friend should only go /* PDUs for a specific Friend should only go
* out through the Friend Queue. * out through the Friend Queue.
*/ */
net_buf_unref(buf); bt_mesh_adv_unref(adv);
send_cb_finalize(cb, cb_data); send_cb_finalize(cb, cb_data);
return 0; return 0;
} }
} }
send: send:
return bt_mesh_net_send(tx, buf, cb, cb_data); return bt_mesh_net_send(tx, adv, cb, cb_data);
} }
static inline uint8_t seg_len(bool ctl) static inline uint8_t seg_len(bool ctl)
@ -392,7 +391,7 @@ static void seg_tx_send_unacked(struct seg_tx *tx)
tx->attempts); tx->attempts);
while (tx->seg_o <= tx->seg_n) { while (tx->seg_o <= tx->seg_n) {
struct net_buf *seg; struct bt_mesh_adv *seg;
int err; int err;
if (!tx->seg[tx->seg_o]) { if (!tx->seg[tx->seg_o]) {
@ -408,7 +407,7 @@ static void seg_tx_send_unacked(struct seg_tx *tx)
goto end; goto end;
} }
net_buf_reserve(seg, BT_MESH_NET_HDR_LEN); net_buf_simple_reserve(&seg->b, BT_MESH_NET_HDR_LEN);
seg_tx_buf_build(tx, tx->seg_o, &seg->b); seg_tx_buf_build(tx, tx->seg_o, &seg->b);
LOG_DBG("Sending %u/%u", tx->seg_o, tx->seg_n); LOG_DBG("Sending %u/%u", tx->seg_o, tx->seg_n);

View file

@ -7,7 +7,6 @@
#include <zephyr/kernel.h> #include <zephyr/kernel.h>
#include <zephyr/bluetooth/hci.h> #include <zephyr/bluetooth/hci.h>
#include "mesh_test.h" #include "mesh_test.h"
#include "mesh/adv.h"
#include "mesh/net.h" #include "mesh/net.h"
#include "mesh/mesh.h" #include "mesh/mesh.h"
#include "mesh/foundation.h" #include "mesh/foundation.h"
@ -78,25 +77,25 @@ static void adv_init(void)
ASSERT_OK_MSG(bt_mesh_adv_enable(), "Mesh adv init failed"); ASSERT_OK_MSG(bt_mesh_adv_enable(), "Mesh adv init failed");
} }
static void allocate_all_array(struct net_buf **buf, size_t num_buf, uint8_t xmit) static void allocate_all_array(struct bt_mesh_adv **adv, size_t num_adv, uint8_t xmit)
{ {
for (int i = 0; i < num_buf; i++) { for (int i = 0; i < num_adv; i++) {
*buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, *adv = 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, "Out of buffers\n"); ASSERT_FALSE_MSG(!*adv, "Out of advs\n");
buf++; adv++;
} }
} }
static void verify_adv_queue_overflow(void) static void verify_adv_queue_overflow(void)
{ {
struct net_buf *dummy_buf; struct bt_mesh_adv *dummy_adv;
/* Verity Queue overflow */ /* Verity Queue overflow */
dummy_buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, dummy_adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL,
BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); BT_MESH_TRANSMIT(2, 20), K_NO_WAIT);
ASSERT_TRUE_MSG(!dummy_buf, "Unexpected extra buffer\n"); ASSERT_TRUE_MSG(!dummy_adv, "Unexpected extra adv\n");
} }
static bool check_delta_time(uint8_t transmit, uint64_t interval) static bool check_delta_time(uint8_t transmit, uint64_t interval)
@ -157,12 +156,12 @@ static void single_end_cb(int err, void *cb_data)
static void realloc_end_cb(int err, void *cb_data) static void realloc_end_cb(int err, void *cb_data)
{ {
struct net_buf *buf = (struct net_buf *)cb_data; struct bt_mesh_adv *adv = (struct bt_mesh_adv *)cb_data;
ASSERT_EQUAL(0, err); ASSERT_EQUAL(0, err);
buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL,
BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); BT_MESH_TRANSMIT(2, 20), K_NO_WAIT);
ASSERT_FALSE_MSG(!buf, "Out of buffers\n"); ASSERT_FALSE_MSG(!adv, "Out of advs\n");
k_sem_give(&observer_sem); k_sem_give(&observer_sem);
} }
@ -305,13 +304,13 @@ static void rx_xmit_adv(void)
static void send_order_start_cb(uint16_t duration, int err, void *user_data) static void send_order_start_cb(uint16_t duration, int err, void *user_data)
{ {
struct net_buf *buf = (struct net_buf *)user_data; struct bt_mesh_adv *adv = (struct bt_mesh_adv *)user_data;
ASSERT_OK_MSG(err, "Failed adv start cb err (%d)", err); ASSERT_OK_MSG(err, "Failed adv start cb err (%d)", err);
ASSERT_EQUAL(2, buf->len); ASSERT_EQUAL(2, adv->b.len);
uint8_t current = buf->data[0]; uint8_t current = adv->b.data[0];
uint8_t previous = buf->data[1]; uint8_t previous = adv->b.data[1];
LOG_INF("tx start: current(%d) previous(%d)", current, previous); LOG_INF("tx start: current(%d) previous(%d)", current, previous);
@ -321,10 +320,7 @@ static void send_order_start_cb(uint16_t duration, int err, void *user_data)
static void send_order_end_cb(int err, void *user_data) static void send_order_end_cb(int err, void *user_data)
{ {
struct net_buf *buf = (struct net_buf *)user_data;
ASSERT_OK_MSG(err, "Failed adv start cb err (%d)", err); ASSERT_OK_MSG(err, "Failed adv start cb err (%d)", err);
ASSERT_TRUE_MSG(!buf->data, "Data not cleared!\n");
seq_checker++; seq_checker++;
LOG_INF("tx end: seq(%d)", seq_checker); LOG_INF("tx end: seq(%d)", seq_checker);
@ -380,19 +376,19 @@ static void receive_order(int expect_adv)
ASSERT_FALSE_MSG(err && err != -EALREADY, "Stopping scan failed (err %d)\n", err); ASSERT_FALSE_MSG(err && err != -EALREADY, "Stopping scan failed (err %d)\n", err);
} }
static void send_adv_buf(struct net_buf *buf, uint8_t curr, uint8_t prev) static void send_adv_buf(struct bt_mesh_adv *adv, uint8_t curr, uint8_t prev)
{ {
send_cb.start = send_order_start_cb; send_cb.start = send_order_start_cb;
send_cb.end = send_order_end_cb; send_cb.end = send_order_end_cb;
(void)net_buf_add_u8(buf, curr); (void)net_buf_simple_add_u8(&adv->b, curr);
(void)net_buf_add_u8(buf, prev); (void)net_buf_simple_add_u8(&adv->b, prev);
bt_mesh_adv_send(buf, &send_cb, buf); bt_mesh_adv_send(adv, &send_cb, adv);
net_buf_unref(buf); bt_mesh_adv_unref(adv);
} }
static void send_adv_array(struct net_buf **buf, size_t num_buf, bool reverse) static void send_adv_array(struct bt_mesh_adv **adv, size_t num_buf, bool reverse)
{ {
uint8_t previous; uint8_t previous;
int i; int i;
@ -405,13 +401,13 @@ static void send_adv_array(struct net_buf **buf, size_t num_buf, bool reverse)
i = num_buf - 1; i = num_buf - 1;
} }
while ((!reverse && i < num_buf) || (reverse && i >= 0)) { while ((!reverse && i < num_buf) || (reverse && i >= 0)) {
send_adv_buf(*buf, (uint8_t)i, previous); send_adv_buf(*adv, (uint8_t)i, previous);
previous = (uint8_t)i; previous = (uint8_t)i;
if (!reverse) { if (!reverse) {
buf++; adv++;
i++; i++;
} else { } else {
buf--; adv--;
i--; i--;
} }
} }
@ -419,24 +415,24 @@ static void send_adv_array(struct net_buf **buf, size_t num_buf, bool reverse)
static void test_tx_cb_single(void) static void test_tx_cb_single(void)
{ {
struct net_buf *buf; struct bt_mesh_adv *adv;
int err; int err;
bt_init(); bt_init();
adv_init(); adv_init();
buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL,
BT_MESH_TRANSMIT(2, 20), K_NO_WAIT); BT_MESH_TRANSMIT(2, 20), K_NO_WAIT);
ASSERT_FALSE_MSG(!buf, "Out of buffers\n"); ASSERT_FALSE_MSG(!adv, "Out of advs\n");
send_cb.start = single_start_cb; send_cb.start = single_start_cb;
send_cb.end = single_end_cb; send_cb.end = single_end_cb;
net_buf_add_mem(buf, txt_msg, sizeof(txt_msg)); net_buf_simple_add_mem(&adv->b, txt_msg, sizeof(txt_msg));
seq_checker = 0; seq_checker = 0;
tx_timestamp = k_uptime_get(); tx_timestamp = k_uptime_get();
bt_mesh_adv_send(buf, &send_cb, (void *)cb_msg); bt_mesh_adv_send(adv, &send_cb, (void *)cb_msg);
net_buf_unref(buf); bt_mesh_adv_unref(adv);
err = k_sem_take(&observer_sem, K_SECONDS(1)); err = k_sem_take(&observer_sem, K_SECONDS(1));
ASSERT_OK_MSG(err, "Didn't call end tx cb."); ASSERT_OK_MSG(err, "Didn't call end tx cb.");
@ -457,37 +453,37 @@ static void test_rx_xmit(void)
static void test_tx_cb_multi(void) static void test_tx_cb_multi(void)
{ {
struct net_buf *buf[CONFIG_BT_MESH_ADV_BUF_COUNT]; struct bt_mesh_adv *adv[CONFIG_BT_MESH_ADV_BUF_COUNT];
int err; int err;
bt_init(); bt_init();
adv_init(); adv_init();
/* Allocate all network buffers. */ /* Allocate all network advs. */
allocate_all_array(buf, ARRAY_SIZE(buf), BT_MESH_TRANSMIT(2, 20)); allocate_all_array(adv, ARRAY_SIZE(adv), BT_MESH_TRANSMIT(2, 20));
/* Start single adv to reallocate one network buffer in callback. /* Start single adv to reallocate one network adv in callback.
* Check that the buffer is freed before cb is triggered. * Check that the adv is freed before cb is triggered.
*/ */
send_cb.start = NULL; send_cb.start = NULL;
send_cb.end = realloc_end_cb; send_cb.end = realloc_end_cb;
net_buf_add_mem(buf[0], txt_msg, sizeof(txt_msg)); net_buf_simple_add_mem(&(adv[0]->b), txt_msg, sizeof(txt_msg));
bt_mesh_adv_send(buf[0], &send_cb, buf[0]); bt_mesh_adv_send(adv[0], &send_cb, adv[0]);
net_buf_unref(buf[0]); bt_mesh_adv_unref(adv[0]);
err = k_sem_take(&observer_sem, K_SECONDS(1)); err = k_sem_take(&observer_sem, K_SECONDS(1));
ASSERT_OK_MSG(err, "Didn't call the end tx cb that reallocates buffer one more time."); ASSERT_OK_MSG(err, "Didn't call the end tx cb that reallocates adv one more time.");
/* Start multi advs to check that all buffers are sent and cbs are triggered. */ /* Start multi advs to check that all advs are sent and cbs are triggered. */
send_cb.start = seq_start_cb; send_cb.start = seq_start_cb;
send_cb.end = seq_end_cb; send_cb.end = seq_end_cb;
seq_checker = 0; seq_checker = 0;
for (int i = 0; i < CONFIG_BT_MESH_ADV_BUF_COUNT; i++) { for (int i = 0; i < CONFIG_BT_MESH_ADV_BUF_COUNT; i++) {
net_buf_add_le32(buf[i], i); net_buf_simple_add_le32(&(adv[i]->b), i);
bt_mesh_adv_send(buf[i], &send_cb, (void *)(intptr_t)i); bt_mesh_adv_send(adv[i], &send_cb, (void *)(intptr_t)i);
net_buf_unref(buf[i]); bt_mesh_adv_unref(adv[i]);
} }
err = k_sem_take(&observer_sem, K_SECONDS(10)); err = k_sem_take(&observer_sem, K_SECONDS(10));
@ -530,10 +526,10 @@ static void test_tx_proxy_mixin(void)
* Advertising the proxy service should be resumed after * Advertising the proxy service should be resumed after
* finishing advertising the message. * finishing advertising the message.
*/ */
struct net_buf *buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, struct bt_mesh_adv *adv = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL,
BT_MESH_TRANSMIT(5, 20), K_NO_WAIT); BT_MESH_TRANSMIT(5, 20), K_NO_WAIT);
net_buf_add_mem(buf, txt_msg, sizeof(txt_msg)); net_buf_simple_add_mem(&adv->b, txt_msg, sizeof(txt_msg));
bt_mesh_adv_send(buf, NULL, NULL); bt_mesh_adv_send(adv, NULL, NULL);
k_sleep(K_MSEC(150)); k_sleep(K_MSEC(150));
/* Let the tester to measure an interval between advertisements again. */ /* Let the tester to measure an interval between advertisements again. */
@ -577,46 +573,46 @@ static void test_rx_proxy_mixin(void)
static void test_tx_send_order(void) static void test_tx_send_order(void)
{ {
struct net_buf *buf[CONFIG_BT_MESH_ADV_BUF_COUNT]; struct bt_mesh_adv *adv[CONFIG_BT_MESH_ADV_BUF_COUNT];
uint8_t xmit = BT_MESH_TRANSMIT(2, 20); uint8_t xmit = BT_MESH_TRANSMIT(2, 20);
bt_init(); bt_init();
adv_init(); adv_init();
/* Verify sending order */ /* Verify sending order */
allocate_all_array(buf, ARRAY_SIZE(buf), xmit); allocate_all_array(adv, ARRAY_SIZE(adv), xmit);
verify_adv_queue_overflow(); verify_adv_queue_overflow();
send_adv_array(&buf[0], ARRAY_SIZE(buf), false); send_adv_array(&adv[0], ARRAY_SIZE(adv), false);
/* Wait for no message receive window to end. */ /* Wait for no message receive window to end. */
ASSERT_OK_MSG(k_sem_take(&observer_sem, K_SECONDS(10)), ASSERT_OK_MSG(k_sem_take(&observer_sem, K_SECONDS(10)),
"Didn't call the last end tx cb."); "Didn't call the last end tx cb.");
/* Verify buffer allocation/deallocation after sending */ /* Verify adv allocation/deallocation after sending */
allocate_all_array(buf, ARRAY_SIZE(buf), xmit); allocate_all_array(adv, ARRAY_SIZE(adv), xmit);
verify_adv_queue_overflow(); verify_adv_queue_overflow();
for (int i = 0; i < CONFIG_BT_MESH_ADV_BUF_COUNT; i++) { for (int i = 0; i < CONFIG_BT_MESH_ADV_BUF_COUNT; i++) {
net_buf_unref(buf[i]); bt_mesh_adv_unref(adv[i]);
buf[i] = NULL; adv[i] = NULL;
} }
/* Check that it possible to add just one net buf. */ /* Check that it possible to add just one net adv. */
allocate_all_array(buf, 1, xmit); allocate_all_array(adv, 1, xmit);
PASS(); PASS();
} }
static void test_tx_reverse_order(void) static void test_tx_reverse_order(void)
{ {
struct net_buf *buf[CONFIG_BT_MESH_ADV_BUF_COUNT]; struct bt_mesh_adv *adv[CONFIG_BT_MESH_ADV_BUF_COUNT];
uint8_t xmit = BT_MESH_TRANSMIT(2, 20); uint8_t xmit = BT_MESH_TRANSMIT(2, 20);
bt_init(); bt_init();
adv_init(); adv_init();
/* Verify reversed sending order */ /* Verify reversed sending order */
allocate_all_array(buf, ARRAY_SIZE(buf), xmit); allocate_all_array(adv, ARRAY_SIZE(adv), xmit);
send_adv_array(&buf[CONFIG_BT_MESH_ADV_BUF_COUNT - 1], ARRAY_SIZE(buf), true); send_adv_array(&adv[CONFIG_BT_MESH_ADV_BUF_COUNT - 1], ARRAY_SIZE(adv), true);
/* Wait for no message receive window to end. */ /* Wait for no message receive window to end. */
ASSERT_OK_MSG(k_sem_take(&observer_sem, K_SECONDS(10)), ASSERT_OK_MSG(k_sem_take(&observer_sem, K_SECONDS(10)),
@ -627,31 +623,31 @@ static void test_tx_reverse_order(void)
static void test_tx_random_order(void) static void test_tx_random_order(void)
{ {
struct net_buf *buf[3]; struct bt_mesh_adv *adv[3];
uint8_t xmit = BT_MESH_TRANSMIT(0, 20); uint8_t xmit = BT_MESH_TRANSMIT(0, 20);
bt_init(); bt_init();
adv_init(); adv_init();
/* Verify random order calls */ /* Verify random order calls */
num_adv_sent = ARRAY_SIZE(buf); num_adv_sent = ARRAY_SIZE(adv);
previous_checker = 0xff; previous_checker = 0xff;
buf[0] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, adv[0] = 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[0], "Out of buffers\n"); ASSERT_FALSE_MSG(!adv[0], "Out of advs\n");
buf[1] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, adv[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(!adv[1], "Out of advs\n");
send_adv_buf(buf[0], 0, 0xff); send_adv_buf(adv[0], 0, 0xff);
buf[2] = bt_mesh_adv_create(BT_MESH_ADV_DATA, BT_MESH_ADV_TAG_LOCAL, adv[2] = 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[2], "Out of buffers\n"); ASSERT_FALSE_MSG(!adv[2], "Out of advs\n");
send_adv_buf(buf[2], 2, 0); send_adv_buf(adv[2], 2, 0);
send_adv_buf(buf[1], 1, 2); send_adv_buf(adv[1], 1, 2);
/* Wait for no message receive window to end. */ /* Wait for no message receive window to end. */
ASSERT_OK_MSG(k_sem_take(&observer_sem, K_SECONDS(10)), ASSERT_OK_MSG(k_sem_take(&observer_sem, K_SECONDS(10)),

View file

@ -6,7 +6,6 @@
#include <zephyr/kernel.h> #include <zephyr/kernel.h>
#include <zephyr/bluetooth/hci.h> #include <zephyr/bluetooth/hci.h>
#include "mesh_test.h" #include "mesh_test.h"
#include "mesh/adv.h"
#include "mesh/net.h" #include "mesh/net.h"
#include "mesh/beacon.h" #include "mesh/beacon.h"
#include "mesh/mesh.h" #include "mesh/mesh.h"

View file

@ -6,9 +6,9 @@
#include "mesh_test.h" #include "mesh_test.h"
#include "dfu_blob_common.h" #include "dfu_blob_common.h"
#include "friendship_common.h" #include "friendship_common.h"
#include "mesh/adv.h"
#include "mesh/blob.h" #include "mesh/blob.h"
#include "argparse.h" #include "argparse.h"
#include "mesh/adv.h"
#define LOG_MODULE_NAME test_blob #define LOG_MODULE_NAME test_blob

View file

@ -6,7 +6,6 @@
#include "mesh_test.h" #include "mesh_test.h"
#include "mesh/dfd_srv_internal.h" #include "mesh/dfd_srv_internal.h"
#include "mesh/dfu_slot.h" #include "mesh/dfu_slot.h"
#include "mesh/adv.h"
#include "mesh/dfu.h" #include "mesh/dfu.h"
#include "mesh/blob.h" #include "mesh/blob.h"
#include "argparse.h" #include "argparse.h"

View file

@ -28,7 +28,6 @@
#define LOG_MODULE_NAME mesh_prov #define LOG_MODULE_NAME mesh_prov
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>
#include "mesh/adv.h"
#include "mesh/rpr.h" #include "mesh/rpr.h"
LOG_MODULE_REGISTER(LOG_MODULE_NAME); LOG_MODULE_REGISTER(LOG_MODULE_NAME);

View file

@ -6,7 +6,6 @@
#include <zephyr/kernel.h> #include <zephyr/kernel.h>
#include "mesh_test.h" #include "mesh_test.h"
#include "mesh/net.h" #include "mesh/net.h"
#include "mesh/adv.h"
#include "mesh/mesh.h" #include "mesh/mesh.h"
#include "mesh/foundation.h" #include "mesh/foundation.h"