Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: TBS: Fixed return call_index 0 after overflow #64545

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions subsys/bluetooth/audio/tbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,18 +307,21 @@ static void tbs_set_terminate_reason(struct tbs_service_inst *inst,
static uint8_t next_free_call_index(void)
{
for (int i = 0; i < CONFIG_BT_TBS_MAX_CALLS; i++) {
static uint8_t next_call_index = 1;
const struct bt_tbs_call *call = lookup_call(next_call_index);

if (call == NULL) {
return next_call_index++;
}
static uint8_t next_call_index;
const struct bt_tbs_call *call;

/* For each new call, the call index should be incremented */
next_call_index++;
if (next_call_index == UINT8_MAX) {

if (next_call_index == BT_TBS_FREE_CALL_INDEX) {
/* call_index = 0 reserved for outgoing calls */
next_call_index = 1;
}

call = lookup_call(next_call_index);
if (call == NULL) {
return next_call_index;
}
}

LOG_DBG("No more free call spots");
Expand Down
Loading