Skip to content

Commit

Permalink
Bluetooth: Mesh: Fixes after proxy advertising unable to send messages
Browse files Browse the repository at this point in the history
When Proxy advertising or PB-GATT Advertising Enabled and use a same
advertising sets.

As adv\_start will call multi HCI Command will cause syswork_q yield.
At same time, if another thread(BT RX) all schedule\_send will cause
unable send mesh message, because ADV\_FLAG\_ACTIVE was be set, but
ADV\_FLAG\_PROXY not set currentlly.

Add ADV\_FLAG\_SCHEDULE\_PENDING indicate mesh buf has been pendings
but not scheduled, so when proxy advertising enable, let's take again,
as we can't break or terminated adv\_start, so we must waiting proxy
advertising enabled.

But after zephyrproject-rtos/zephyr#68558

The `k_work_is_pending` always true in `send_pending_adv`, which cause
unable to send more mesh message until more mesh message comming

(cherry picked from commit 537d215)

Original-Signed-off-by: Lingao Meng <[email protected]>
GitOrigin-RevId: 537d215
Cr-Build-Id: 8733565196572304993
Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8733565196572304993
Copybot-Job-Name: zephyr-main-copybot-downstream
Change-Id: I94956c624381163d4e77709858bf90cdb7bab7b6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5937740
Reviewed-by: Jeremy Bettis <[email protected]>
Commit-Queue: Eric Yilun Lin <[email protected]>
Reviewed-by: Fabio Baltieri <[email protected]>
Tested-by: Dawid Niedźwiecki <[email protected]>
Reviewed-by: Dawid Niedźwiecki <[email protected]>
  • Loading branch information
LingaoM authored and Chromeos LUCI committed Oct 22, 2024
1 parent 57bdd6b commit b513c19
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions subsys/bluetooth/mesh/adv_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,28 @@ static const char * const adv_tag_to_str[] = {
[BT_MESH_ADV_TAG_PROV] = "prov adv",
};

static bool schedule_send_with_mask(struct bt_mesh_ext_adv *ext_adv, int ignore_mask)
{
if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_PROXY)) {
atomic_clear_bit(ext_adv->flags, ADV_FLAG_PROXY_START);
(void)bt_le_ext_adv_stop(ext_adv->instance);

atomic_clear_bit(ext_adv->flags, ADV_FLAG_ACTIVE);
}

if (atomic_test_bit(ext_adv->flags, ADV_FLAG_ACTIVE)) {
atomic_set_bit(ext_adv->flags, ADV_FLAG_SCHEDULE_PENDING);
return false;
} else if ((~ignore_mask) & k_work_busy_get(&ext_adv->work)) {
return false;
}

atomic_clear_bit(ext_adv->flags, ADV_FLAG_SCHEDULE_PENDING);
k_work_submit(&ext_adv->work);

return true;
}

static void send_pending_adv(struct k_work *work)
{
struct bt_mesh_ext_adv *ext_adv;
Expand Down Expand Up @@ -314,30 +336,13 @@ static void send_pending_adv(struct k_work *work)
}

if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_SCHEDULE_PENDING)) {
schedule_send(ext_adv);
schedule_send_with_mask(ext_adv, K_WORK_RUNNING);
}
}

static bool schedule_send(struct bt_mesh_ext_adv *ext_adv)
{
if (atomic_test_and_clear_bit(ext_adv->flags, ADV_FLAG_PROXY)) {
atomic_clear_bit(ext_adv->flags, ADV_FLAG_PROXY_START);
(void)bt_le_ext_adv_stop(ext_adv->instance);

atomic_clear_bit(ext_adv->flags, ADV_FLAG_ACTIVE);
}

if (atomic_test_bit(ext_adv->flags, ADV_FLAG_ACTIVE)) {
atomic_set_bit(ext_adv->flags, ADV_FLAG_SCHEDULE_PENDING);
return false;
} else if (k_work_is_pending(&ext_adv->work)) {
return false;
}

atomic_clear_bit(ext_adv->flags, ADV_FLAG_SCHEDULE_PENDING);
k_work_submit(&ext_adv->work);

return true;
return schedule_send_with_mask(ext_adv, 0);
}

void bt_mesh_adv_gatt_update(void)
Expand Down

0 comments on commit b513c19

Please sign in to comment.