Skip to content

Commit 21cb94f

Browse files
committed
Bluetooth: BAP: Shell add common unicast_group struct
Add a common unicast_group struct for both the BAP and CAP shell, similar to the broadcast_source. The purpose of this is to be able to use the appropriate type for both the CAP and BAP shells, instead of using the BAP unicast group for the CAP shell. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 27d27a6 commit 21cb94f

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

subsys/bluetooth/audio/shell/audio.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ struct broadcast_sink {
188188
bool syncable;
189189
};
190190

191+
struct unicast_group {
192+
bool is_cap;
193+
union {
194+
struct bt_bap_unicast_group *bap_group;
195+
struct bt_cap_unicast_group *cap_group;
196+
};
197+
};
198+
191199
#define BAP_UNICAST_AC_MAX_CONN 2U
192200
#define BAP_UNICAST_AC_MAX_SNK (2U * BAP_UNICAST_AC_MAX_CONN)
193201
#define BAP_UNICAST_AC_MAX_SRC (2U * BAP_UNICAST_AC_MAX_CONN)
@@ -220,7 +228,7 @@ struct bap_unicast_ac_param {
220228
size_t src_chan_cnt;
221229
};
222230

223-
extern struct bt_bap_unicast_group *default_unicast_group;
231+
extern struct unicast_group default_unicast_group;
224232
extern struct bt_bap_ep *snks[CONFIG_BT_MAX_CONN][CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT];
225233
extern struct bt_bap_ep *srcs[CONFIG_BT_MAX_CONN][CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SRC_COUNT];
226234
extern struct named_lc3_preset default_sink_preset;

subsys/bluetooth/audio/shell/bap.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ struct shell_stream unicast_streams[CONFIG_BT_MAX_CONN *
6565
MAX(UNICAST_SERVER_STREAM_COUNT, UNICAST_CLIENT_STREAM_COUNT)];
6666

6767
#if defined(CONFIG_BT_BAP_UNICAST_CLIENT)
68-
struct bt_bap_unicast_group *default_unicast_group;
68+
struct unicast_group default_unicast_group;
6969
static struct bt_bap_unicast_client_cb unicast_client_cbs;
7070
#if CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT > 0
7171
struct bt_bap_ep *snks[CONFIG_BT_MAX_CONN][CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT];
@@ -876,7 +876,7 @@ int bap_ac_create_unicast_group(const struct bap_unicast_ac_param *param,
876876
group_param.params = pair_params;
877877
group_param.params_count = pair_cnt;
878878

879-
return bt_bap_unicast_group_create(&group_param, &default_unicast_group);
879+
return bt_bap_unicast_group_create(&group_param, &default_unicast_group.bap_group);
880880
}
881881

882882
static uint8_t stream_dir(const struct bt_bap_stream *stream)
@@ -1492,7 +1492,7 @@ static int create_unicast_group(const struct shell *sh)
14921492
return err;
14931493
}
14941494

1495-
err = bt_bap_unicast_group_create(&group_param, &default_unicast_group);
1495+
err = bt_bap_unicast_group_create(&group_param, &default_unicast_group.bap_group);
14961496
if (err != 0) {
14971497
shell_error(sh, "Unable to create default unicast group: %d", err);
14981498

@@ -1514,7 +1514,7 @@ static int reconfig_unicast_group(const struct shell *sh)
15141514
return err;
15151515
}
15161516

1517-
err = bt_bap_unicast_group_reconfig(default_unicast_group, &group_param);
1517+
err = bt_bap_unicast_group_reconfig(default_unicast_group.bap_group, &group_param);
15181518
if (err != 0) {
15191519
shell_error(sh, "Unable to create default unicast group: %d", err);
15201520

@@ -1538,7 +1538,13 @@ static int cmd_qos(const struct shell *sh, size_t argc, char *argv[])
15381538
return -ENOEXEC;
15391539
}
15401540

1541-
if (default_unicast_group == NULL) {
1541+
if (default_unicast_group.is_cap) {
1542+
shell_error(sh, "Cannot perform action on CAP unicast group");
1543+
1544+
return -ENOEXEC;
1545+
}
1546+
1547+
if (default_unicast_group.bap_group == NULL) {
15421548
err = create_unicast_group(sh);
15431549
if (err != 0) {
15441550
return err;
@@ -1550,7 +1556,7 @@ static int cmd_qos(const struct shell *sh, size_t argc, char *argv[])
15501556
}
15511557
}
15521558

1553-
err = bt_bap_stream_qos(default_conn, default_unicast_group);
1559+
err = bt_bap_stream_qos(default_conn, default_unicast_group.bap_group);
15541560
if (err) {
15551561
shell_error(sh, "Unable to setup QoS: %d", err);
15561562
return -ENOEXEC;
@@ -3177,7 +3183,7 @@ static void stream_released_cb(struct bt_bap_stream *stream)
31773183
bt_shell_print("Stream %p released\n", stream);
31783184

31793185
#if defined(CONFIG_BT_BAP_UNICAST_CLIENT)
3180-
if (default_unicast_group != NULL) {
3186+
if (default_unicast_group.bap_group != NULL && !default_unicast_group.is_cap) {
31813187
bool group_can_be_deleted = true;
31823188

31833189
for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) {
@@ -3202,12 +3208,12 @@ static void stream_released_cb(struct bt_bap_stream *stream)
32023208

32033209
bt_shell_print("All streams released, deleting group\n");
32043210

3205-
err = bt_bap_unicast_group_delete(default_unicast_group);
3211+
err = bt_bap_unicast_group_delete(default_unicast_group.bap_group);
32063212

32073213
if (err != 0) {
32083214
bt_shell_error("Failed to delete unicast group: %d", err);
32093215
} else {
3210-
default_unicast_group = NULL;
3216+
default_unicast_group.bap_group = NULL;
32113217
}
32123218
}
32133219
}

0 commit comments

Comments
 (0)