Skip to content

Commit c627164

Browse files
Thalleycarlescufi
authored andcommitted
Bluetooth: CSIP: Shell: Fix discover_members
The cmd_csip_set_coordinator_discover_members did not properly handle the members_found and addr_found values. It has been modified to run through all known values before scanning, and set the value appropriately. This also fixes a minor bug where err = 0 was missing. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 5572a27 commit c627164

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

subsys/bluetooth/audio/shell/csip_set_coordinator.c

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ static int cmd_csip_set_coordinator_discover(const struct shell *sh,
244244
char addr[BT_ADDR_LE_STR_LEN];
245245
static bool initialized;
246246
struct bt_conn *conn;
247-
int err;
247+
int err = 0;
248248

249249
if (!initialized) {
250250
k_work_init_delayable(&discover_members_timer,
@@ -311,10 +311,45 @@ static int cmd_csip_set_coordinator_discover_members(const struct shell *sh,
311311
return -EINVAL;
312312
}
313313

314-
if (members_found > 1) {
315-
members_found = 1;
314+
/* Reset and populate based on current connections */
315+
memset(addr_found, 0, sizeof(addr_found));
316+
members_found = 0;
317+
for (size_t i = 0U; i < ARRAY_SIZE(set_members); i++) {
318+
const struct bt_csip_set_coordinator_set_member *set_member = set_members[i];
319+
320+
if (set_member == NULL) {
321+
continue;
322+
}
323+
324+
for (size_t j = 0U; j < ARRAY_SIZE(set_members[i]->insts); j++) {
325+
const struct bt_csip_set_coordinator_csis_inst *inst =
326+
&set_members[i]->insts[j];
327+
328+
if (memcmp(inst->info.set_sirk, cur_inst->info.set_sirk,
329+
BT_CSIP_SET_SIRK_SIZE) == 0) {
330+
bt_addr_le_copy(&addr_found[members_found++],
331+
bt_conn_get_dst(conns[i]));
332+
break;
333+
}
334+
}
316335
}
317336

337+
if (cur_inst->info.set_size > 0) {
338+
if (members_found == cur_inst->info.set_size) {
339+
shell_print(sh, "All members already known");
340+
341+
return 0;
342+
} else if (members_found > cur_inst->info.set_size) {
343+
shell_error(sh, "Found %u members but set size is %u", members_found,
344+
cur_inst->info.set_size);
345+
346+
return -ENOEXEC;
347+
}
348+
}
349+
350+
shell_print(sh, "Already know %u/%u members, start scanning for remaining", members_found,
351+
cur_inst->info.set_size);
352+
318353
err = k_work_reschedule(&discover_members_timer,
319354
BT_CSIP_SET_COORDINATOR_DISCOVER_TIMER_VALUE);
320355
if (err < 0) { /* Can return 0, 1 and 2 for success */

0 commit comments

Comments
 (0)