Skip to content

Commit 953bea5

Browse files
committed
Bluetooth: BAP: BA: Refactor discover to not do read
Refactor the bt_bap_broadcast_assistant_discover function to not read receives at the end of discovery. This makes the function more true to what it is supposed to do, and significantly reduces the complexity of the procedure and the read callback. Users will be required to, if wanted, to read the receive state themselves with the existing bt_bap_broadcast_assistant_read_recv_state. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
1 parent 8912f07 commit 953bea5

File tree

2 files changed

+16
-55
lines changed

2 files changed

+16
-55
lines changed

doc/releases/migration-guide-4.2.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,11 @@ Bluetooth Audio
371371
* ``BT_AUDIO_CONTEXT_TYPE_PROHIBITED`` has been renamed to
372372
:c:enumerator:`BT_AUDIO_CONTEXT_TYPE_NONE`. (:github:`89506`)
373373

374+
* :c:func:`bt_bap_broadcast_assistant_discover` will now no longer perform reads of the remote BASS
375+
receive states at the end of the procedure. Users will have to manually call
376+
:c:func:`bt_bap_broadcast_assistant_read_recv_state` to read the existing receive states, if any,
377+
prior to performing any operations.
378+
374379
Bluetooth HCI
375380
=============
376381

subsys/bluetooth/audio/bap_broadcast_assistant.c

Lines changed: 11 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/*
44
* Copyright (c) 2019 Bose Corporation
5-
* Copyright (c) 2022-2023 Nordic Semiconductor ASA
5+
* Copyright (c) 2022-2025 Nordic Semiconductor ASA
66
* Copyright (c) 2024 Demant A/S
77
*
88
* SPDX-License-Identifier: Apache-2.0
@@ -565,20 +565,15 @@ static uint8_t read_recv_state_cb(struct bt_conn *conn, uint8_t err,
565565
const void *data, uint16_t length)
566566
{
567567
struct bap_broadcast_assistant_instance *inst = inst_by_conn(conn);
568+
bool active_recv_state = data != NULL && length != 0;
569+
struct bt_bap_scan_delegator_recv_state recv_state;
570+
uint16_t handle = params->single.handle;
571+
int cb_err = err;
568572

569573
if (inst == NULL) {
570574
return BT_GATT_ITER_STOP;
571575
}
572576

573-
uint16_t handle = params->single.handle;
574-
uint8_t last_handle_index = inst->recv_state_cnt - 1;
575-
uint16_t last_handle = inst->recv_state_handles[last_handle_index];
576-
struct bt_bap_scan_delegator_recv_state recv_state;
577-
int cb_err = err;
578-
bool active_recv_state = data != NULL && length != 0;
579-
580-
/* TODO: Split discovery and receive state characteristic read */
581-
582577
(void)memset(params, 0, sizeof(*params));
583578

584579
LOG_DBG("%s receive state", active_recv_state ? "Active " : "Inactive");
@@ -611,48 +606,12 @@ static uint8_t read_recv_state_cb(struct bt_conn *conn, uint8_t err,
611606

612607
if (cb_err != 0) {
613608
LOG_DBG("err %d", cb_err);
614-
615-
if (atomic_test_bit(inst->flags, BAP_BA_FLAG_DISCOVER_IN_PROGRESS)) {
616-
bap_broadcast_assistant_discover_complete(conn, cb_err, 0);
617-
} else {
618-
atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY);
619-
bap_broadcast_assistant_recv_state_changed(conn, cb_err, NULL);
620-
}
621-
} else if (handle == last_handle) {
622-
if (atomic_test_bit(inst->flags, BAP_BA_FLAG_DISCOVER_IN_PROGRESS)) {
623-
const uint8_t recv_state_cnt = inst->recv_state_cnt;
624-
625-
bap_broadcast_assistant_discover_complete(conn, cb_err, recv_state_cnt);
626-
} else {
627-
atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY);
628-
bap_broadcast_assistant_recv_state_changed(conn, cb_err,
629-
active_recv_state ?
630-
&recv_state : NULL);
631-
}
609+
atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY);
610+
bap_broadcast_assistant_recv_state_changed(conn, cb_err, NULL);
632611
} else {
633-
for (uint8_t i = 0U; i < inst->recv_state_cnt; i++) {
634-
if (handle != inst->recv_state_handles[i]) {
635-
continue;
636-
}
637-
638-
if (i + 1 < ARRAY_SIZE(inst->recv_state_handles)) {
639-
cb_err = read_recv_state(inst, i + 1);
640-
if (cb_err != 0) {
641-
LOG_DBG("Failed to read receive state: %d", cb_err);
642-
643-
if (atomic_test_bit(inst->flags,
644-
BAP_BA_FLAG_DISCOVER_IN_PROGRESS)) {
645-
bap_broadcast_assistant_discover_complete(
646-
conn, cb_err, 0);
647-
} else {
648-
atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY);
649-
bap_broadcast_assistant_recv_state_changed(
650-
conn, cb_err, NULL);
651-
}
652-
}
653-
}
654-
break;
655-
}
612+
atomic_clear_bit(inst->flags, BAP_BA_FLAG_BUSY);
613+
bap_broadcast_assistant_recv_state_changed(conn, cb_err,
614+
active_recv_state ? &recv_state : NULL);
656615
}
657616

658617
return BT_GATT_ITER_STOP;
@@ -686,10 +645,7 @@ static uint8_t char_discover_func(struct bt_conn *conn,
686645
LOG_DBG("Found %u BASS receive states", inst->recv_state_cnt);
687646
(void)memset(params, 0, sizeof(*params));
688647

689-
err = read_recv_state(inst, 0);
690-
if (err != 0) {
691-
bap_broadcast_assistant_discover_complete(conn, err, 0);
692-
}
648+
bap_broadcast_assistant_discover_complete(conn, 0, inst->recv_state_cnt);
693649

694650
return BT_GATT_ITER_STOP;
695651
}

0 commit comments

Comments
 (0)