Bluetooth: Mesh: Reconstructing adv callback logic

The adv callback logic is reconstructed to coexist
with proxy send callback.

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
This commit is contained in:
Lingao Meng 2021-05-26 20:32:18 -07:00 committed by Johan Hedberg
commit a63f2d8d60
4 changed files with 41 additions and 23 deletions

View file

@ -55,8 +55,7 @@ enum {
static struct {
ATOMIC_DEFINE(flags, ADV_FLAGS_NUM);
struct bt_le_ext_adv *instance;
const struct bt_mesh_send_cb *cb;
void *cb_data;
struct net_buf *buf;
uint64_t timestamp;
struct k_work_delayable work;
} adv;
@ -140,12 +139,12 @@ static int buf_send(struct net_buf *buf)
atomic_set_bit(adv.flags, ADV_FLAG_UPDATE_PARAMS);
}
adv.cb = BT_MESH_ADV(buf)->cb;
adv.cb_data = BT_MESH_ADV(buf)->cb_data;
err = adv_start(&adv_param, &start, &ad, 1, NULL, 0);
net_buf_unref(buf);
bt_mesh_adv_send_start(duration, err, adv.cb, adv.cb_data);
if (!err) {
adv.buf = net_buf_ref(buf);
}
bt_mesh_adv_send_start(duration, err, BT_MESH_ADV(buf));
return err;
}
@ -166,6 +165,9 @@ static void send_pending_adv(struct k_work *work)
BT_MESH_ADV(buf)->busy = 0U;
err = buf_send(buf);
net_buf_unref(buf);
if (!err) {
return; /* Wait for advertising to finish */
}
@ -235,7 +237,7 @@ static void adv_sent(struct bt_le_ext_adv *instance,
atomic_clear_bit(adv.flags, ADV_FLAG_ACTIVE);
if (!atomic_test_and_clear_bit(adv.flags, ADV_FLAG_PROXY)) {
bt_mesh_adv_send_end(0, adv.cb, adv.cb_data);
net_buf_unref(adv.buf);
}
schedule_send();