Skip to content

Commit

Permalink
Bluetooth: BAP: Fix notifying recv state for bonded devices
Browse files Browse the repository at this point in the history
The scan_delegator_security_changed function had a few issues
that were addressed:
1) It used an internal field to check level rather than the
   value provided by the API
2) It did not treat bt_addr_le_is_bonded as a boolean return value
3) It did not properly truncate the recv state (fixed by using the
   proper function bass_notify_receive_state)

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
  • Loading branch information
Thalley authored and aescolar committed Jul 11, 2024
1 parent 367c9d7 commit 2761204
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions subsys/bluetooth/audio/bap_scan_delegator.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,15 @@ static void scan_delegator_security_changed(struct bt_conn *conn,
bt_security_t level,
enum bt_security_err err)
{
if (err != 0 || conn->encrypt == 0) {
return;
}

if (bt_addr_le_is_bonded(conn->id, &conn->le.dst) == 0) {
if (err != 0 || level < BT_SECURITY_L2 || !bt_addr_le_is_bonded(conn->id, &conn->le.dst)) {
return;
}

/* Notify all receive states after a bonded device reconnects */
for (size_t i = 0; i < ARRAY_SIZE(scan_delegator.recv_states); i++) {
struct bass_recv_state_internal *internal_state = &scan_delegator.recv_states[i];
int gatt_err;
const struct bass_recv_state_internal *internal_state =
&scan_delegator.recv_states[i];

if (!internal_state->active) {
continue;
Expand All @@ -300,17 +297,9 @@ static void scan_delegator_security_changed(struct bt_conn *conn,
}

net_buf_put_recv_state(internal_state);

gatt_err = bt_gatt_notify_uuid(conn, BT_UUID_BASS_RECV_STATE,
internal_state->attr, read_buf.data,
read_buf.len);
bass_notify_receive_state(conn, internal_state);

k_sem_give(&read_buf_sem);

if (gatt_err != 0) {
LOG_WRN("Could not notify receive state[%d] to reconnecting assistant: %d",
i, gatt_err);
}
}
}

Expand Down

0 comments on commit 2761204

Please sign in to comment.