Skip to content

Commit f1516c9

Browse files
ndrs-pstkartben
authored andcommitted
bluetooth: audio: shell: eliminate ctx_shell usage
This change aims to eliminate the dependency on `ctx_shell` in the Bluetooth `audio/shell/*`, making the code more maintainable. Replaced `shell_*` functions that depended on `ctx_shell` with the appropriate `bt_shell_*` functions. Signed-off-by: Pisit Sawangvonganan <[email protected]>
1 parent eeda631 commit f1516c9

21 files changed

+846
-1037
lines changed

subsys/bluetooth/audio/shell/audio.h

Lines changed: 171 additions & 184 deletions
Large diffs are not rendered by default.

subsys/bluetooth/audio/shell/bap.c

Lines changed: 151 additions & 165 deletions
Large diffs are not rendered by default.

subsys/bluetooth/audio/shell/bap_broadcast_assistant.c

Lines changed: 49 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static bool pa_decode_base(struct bt_data *data, void *user_data)
6565

6666
base_size = bt_bap_base_get_size(base);
6767
if (base_size < 0) {
68-
shell_error(ctx_shell, "BASE get size failed (%d)", base_size);
68+
bt_shell_error("BASE get size failed (%d)", base_size);
6969

7070
return true;
7171
}
@@ -93,12 +93,10 @@ static void bap_broadcast_assistant_discover_cb(struct bt_conn *conn, int err,
9393
uint8_t recv_state_count)
9494
{
9595
if (err != 0) {
96-
shell_error(ctx_shell, "BASS discover failed (%d)", err);
96+
bt_shell_error("BASS discover failed (%d)", err);
9797
} else {
98-
shell_print(ctx_shell, "BASS discover done with %u recv states",
99-
recv_state_count);
98+
bt_shell_print("BASS discover done with %u recv states", recv_state_count);
10099
}
101-
102100
}
103101

104102
static void bap_broadcast_assistant_scan_cb(const struct bt_le_scan_recv_info *info,
@@ -107,8 +105,7 @@ static void bap_broadcast_assistant_scan_cb(const struct bt_le_scan_recv_info *i
107105
char le_addr[BT_ADDR_LE_STR_LEN];
108106

109107
bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr));
110-
shell_print(
111-
ctx_shell,
108+
bt_shell_print(
112109
"[DEVICE]: %s, broadcast_id 0x%06X, interval (ms) %u (0x%04x)), SID 0x%x, RSSI %i",
113110
le_addr, broadcast_id, BT_GAP_PER_ADV_INTERVAL_TO_MS(info->interval),
114111
info->interval, info->sid, info->rssi);
@@ -120,8 +117,8 @@ static bool metadata_entry(struct bt_data *data, void *user_data)
120117

121118
bin2hex(data->data, data->data_len, metadata, sizeof(metadata));
122119

123-
shell_print(ctx_shell, "\t\tMetadata length %u, type %u, data: %s",
124-
data->data_len, data->type, metadata);
120+
bt_shell_print("\t\tMetadata length %u, type %u, data: %s",
121+
data->data_len, data->type, metadata);
125122

126123
return true;
127124
}
@@ -135,34 +132,33 @@ static void bap_broadcast_assistant_recv_state_cb(
135132
bool is_bad_code;
136133

137134
if (err != 0) {
138-
shell_error(ctx_shell, "BASS recv state read failed (%d)", err);
135+
bt_shell_error("BASS recv state read failed (%d)", err);
139136
return;
140137
}
141138

142139
bt_addr_le_to_str(&state->addr, le_addr, sizeof(le_addr));
143140
bin2hex(state->bad_code, BT_ISO_BROADCAST_CODE_SIZE, bad_code, sizeof(bad_code));
144141

145142
is_bad_code = state->encrypt_state == BT_BAP_BIG_ENC_STATE_BAD_CODE;
146-
shell_print(ctx_shell,
147-
"BASS recv state: src_id %u, addr %s, sid %u, broadcast_id 0x%06X, sync_state "
148-
"%u, encrypt_state %u%s%s",
149-
state->src_id, le_addr, state->adv_sid, state->broadcast_id,
150-
state->pa_sync_state, state->encrypt_state, is_bad_code ? ", bad code" : "",
151-
is_bad_code ? bad_code : "");
143+
bt_shell_print(
144+
"BASS recv state: src_id %u, addr %s, sid %u, broadcast_id 0x%06X, sync_state "
145+
"%u, encrypt_state %u%s%s",
146+
state->src_id, le_addr, state->adv_sid, state->broadcast_id,
147+
state->pa_sync_state, state->encrypt_state, is_bad_code ? ", bad code" : "",
148+
is_bad_code ? bad_code : "");
152149

153150
for (int i = 0; i < state->num_subgroups; i++) {
154151
const struct bt_bap_bass_subgroup *subgroup = &state->subgroups[i];
155152
struct net_buf_simple buf;
156153

157-
shell_print(ctx_shell, "\t[%d]: BIS sync 0x%04X, metadata_len %zu", i,
158-
subgroup->bis_sync, subgroup->metadata_len);
154+
bt_shell_print("\t[%d]: BIS sync 0x%04X, metadata_len %zu", i,
155+
subgroup->bis_sync, subgroup->metadata_len);
159156

160157
net_buf_simple_init_with_data(&buf, (void *)subgroup->metadata,
161158
subgroup->metadata_len);
162159
bt_data_parse(&buf, metadata_entry, NULL);
163160
}
164161

165-
166162
if (state->pa_sync_state == BT_BAP_PA_STATE_INFO_REQ) {
167163
struct bt_le_per_adv_sync *per_adv_sync = NULL;
168164
struct bt_le_ext_adv *ext_adv = NULL;
@@ -172,21 +168,20 @@ static void bap_broadcast_assistant_recv_state_cb(
172168
if (per_adv_syncs[i] != NULL &&
173169
bt_addr_le_eq(&per_adv_syncs[i]->addr, &state->addr)) {
174170
per_adv_sync = per_adv_syncs[i];
175-
shell_print(ctx_shell, "Found matching PA sync [%zu]", i);
171+
bt_shell_print("Found matching PA sync [%zu]", i);
176172
break;
177173
}
178174
}
179175

180176
if (per_adv_sync && IS_ENABLED(CONFIG_BT_PER_ADV_SYNC_TRANSFER_SENDER)) {
181-
shell_print(ctx_shell, "Sending PAST");
177+
bt_shell_print("Sending PAST");
182178

183179
err = bt_le_per_adv_sync_transfer(per_adv_sync,
184180
conn,
185181
BT_UUID_BASS_VAL);
186182

187183
if (err != 0) {
188-
shell_error(ctx_shell, "Could not transfer periodic adv sync: %d",
189-
err);
184+
bt_shell_error("Could not transfer periodic adv sync: %d", err);
190185
}
191186

192187
return;
@@ -204,9 +199,7 @@ static void bap_broadcast_assistant_recv_state_cb(
204199
&oob_local);
205200

206201
if (err != 0) {
207-
shell_error(ctx_shell,
208-
"Could not get local OOB %d",
209-
err);
202+
bt_shell_error("Could not get local OOB %d", err);
210203
return;
211204
}
212205

@@ -218,80 +211,77 @@ static void bap_broadcast_assistant_recv_state_cb(
218211

219212
if (ext_adv != NULL && IS_ENABLED(CONFIG_BT_PER_ADV) &&
220213
IS_ENABLED(CONFIG_BT_PER_ADV_SYNC_TRANSFER_SENDER)) {
221-
shell_print(ctx_shell, "Sending local PAST");
214+
bt_shell_print("Sending local PAST");
222215

223216
err = bt_le_per_adv_set_info_transfer(ext_adv, conn,
224217
BT_UUID_BASS_VAL);
225218

226219
if (err != 0) {
227-
shell_error(ctx_shell,
228-
"Could not transfer per adv set info: %d",
229-
err);
220+
bt_shell_error("Could not transfer per adv set info: %d", err);
230221
}
231222
} else {
232-
shell_error(ctx_shell,
233-
"Could not send PA to Scan Delegator");
223+
bt_shell_error("Could not send PA to Scan Delegator");
234224
}
235225
}
236226
}
237227

238228
static void bap_broadcast_assistant_recv_state_removed_cb(struct bt_conn *conn, uint8_t src_id)
239229
{
240-
shell_print(ctx_shell, "BASS recv state %u removed", src_id);
230+
bt_shell_print("BASS recv state %u removed", src_id);
241231
}
242232

243233
static void bap_broadcast_assistant_scan_start_cb(struct bt_conn *conn, int err)
244234
{
245235
if (err != 0) {
246-
shell_error(ctx_shell, "BASS scan start failed (%d)", err);
236+
bt_shell_error("BASS scan start failed (%d)", err);
247237
} else {
248-
shell_print(ctx_shell, "BASS scan start successful");
238+
bt_shell_print("BASS scan start successful");
249239
}
250240
}
251241

252242
static void bap_broadcast_assistant_scan_stop_cb(struct bt_conn *conn, int err)
253243
{
254244
if (err != 0) {
255-
shell_error(ctx_shell, "BASS scan stop failed (%d)", err);
245+
bt_shell_error("BASS scan stop failed (%d)", err);
256246
} else {
257-
shell_print(ctx_shell, "BASS scan stop successful");
247+
bt_shell_print("BASS scan stop successful");
258248
}
259249
}
260250

261251
static void bap_broadcast_assistant_add_src_cb(struct bt_conn *conn, int err)
262252
{
263253
if (err != 0) {
264-
shell_error(ctx_shell, "BASS add source failed (%d)", err);
254+
bt_shell_error("BASS add source failed (%d)", err);
265255
} else {
266-
shell_print(ctx_shell, "BASS add source successful");
256+
bt_shell_print("BASS add source successful");
267257
}
268258
}
269259

270260
static void bap_broadcast_assistant_mod_src_cb(struct bt_conn *conn, int err)
271261
{
272262
if (err != 0) {
273-
shell_error(ctx_shell, "BASS modify source failed (%d)", err);
263+
bt_shell_error("BASS modify source failed (%d)", err);
274264
} else {
275-
shell_print(ctx_shell, "BASS modify source successful");
265+
bt_shell_print("BASS modify source successful");
276266
}
277267
}
278268

279269
static void bap_broadcast_assistant_broadcast_code_cb(struct bt_conn *conn,
280270
int err)
281271
{
282272
if (err != 0) {
283-
shell_error(ctx_shell, "BASS broadcast code failed (%d)", err);
273+
bt_shell_error("BASS broadcast code failed (%d)", err);
284274
} else {
285-
shell_print(ctx_shell, "BASS broadcast code successful");
275+
bt_shell_print("BASS broadcast code successful");
286276
}
287277
}
288278

289279
static void bap_broadcast_assistant_rem_src_cb(struct bt_conn *conn, int err)
290280
{
291281
if (err != 0) {
292-
shell_error(ctx_shell, "BASS remove source failed (%d)", err);
282+
bt_shell_error("BASS remove source failed (%d)", err);
293283
} else {
294-
shell_print(ctx_shell, "BASS remove source successful");
284+
bt_shell_print("BASS remove source successful");
295285
}
296286
}
297287

@@ -551,18 +541,18 @@ static void scan_recv_cb(const struct bt_le_scan_recv_info *info,
551541
is_substring(auto_scan.broadcast_name, sr_info.broadcast_name)) {
552542
identified_broadcast = true;
553543

554-
shell_print(ctx_shell, "Found matched broadcast name '%s' with address %s",
555-
sr_info.broadcast_name, addr_str);
544+
bt_shell_print("Found matched broadcast name '%s' with address %s",
545+
sr_info.broadcast_name, addr_str);
556546
}
557547

558548
if (identified_broadcast) {
559-
shell_print(ctx_shell,
560-
"Found BAP broadcast source with address %s and ID 0x%06X\n",
561-
addr_str, sr_info.broadcast_id);
549+
bt_shell_print(
550+
"Found BAP broadcast source with address %s and ID 0x%06X\n",
551+
addr_str, sr_info.broadcast_id);
562552

563553
err = bt_le_scan_stop();
564554
if (err) {
565-
shell_error(ctx_shell, "Failed to stop scan: %d", err);
555+
bt_shell_error("Failed to stop scan: %d", err);
566556
}
567557

568558
bt_addr_le_copy(&param.addr, info->addr);
@@ -575,7 +565,7 @@ static void scan_recv_cb(const struct bt_le_scan_recv_info *info,
575565

576566
err = bt_bap_broadcast_assistant_add_src(default_conn, &param);
577567
if (err) {
578-
shell_print(ctx_shell, "Failed to add source: %d", err);
568+
bt_shell_print("Failed to add source: %d", err);
579569
}
580570

581571
memset(&auto_scan, 0, sizeof(auto_scan));
@@ -586,7 +576,7 @@ static void scan_recv_cb(const struct bt_le_scan_recv_info *info,
586576

587577
static void scan_timeout_cb(void)
588578
{
589-
shell_print(ctx_shell, "Scan timeout");
579+
bt_shell_print("Scan timeout");
590580

591581
memset(&auto_scan, 0, sizeof(auto_scan));
592582
auto_scan.broadcast_id = BT_BAP_INVALID_BROADCAST_ID;
@@ -891,8 +881,8 @@ static inline bool add_pa_sync_base_subgroup_cb(const struct bt_bap_base_subgrou
891881
int ret;
892882

893883
if (param->num_subgroups == CONFIG_BT_BAP_BASS_MAX_SUBGROUPS) {
894-
shell_warn(ctx_shell, "Cannot fit all subgroups param with size %d",
895-
CONFIG_BT_BAP_BASS_MAX_SUBGROUPS);
884+
bt_shell_warn("Cannot fit all subgroups param with size %d",
885+
CONFIG_BT_BAP_BASS_MAX_SUBGROUPS);
896886

897887
return true; /* return true to avoid returning -ECANCELED as this is OK */
898888
}
@@ -905,8 +895,8 @@ static inline bool add_pa_sync_base_subgroup_cb(const struct bt_bap_base_subgrou
905895
subgroup_param = &param->subgroups[param->num_subgroups];
906896

907897
if (ret > ARRAY_SIZE(subgroup_param->metadata)) {
908-
shell_info(ctx_shell, "Cannot fit %d octets into subgroup param with size %zu", ret,
909-
ARRAY_SIZE(subgroup_param->metadata));
898+
bt_shell_info("Cannot fit %d octets into subgroup param with size %zu", ret,
899+
ARRAY_SIZE(subgroup_param->metadata));
910900
return false;
911901
}
912902

@@ -1001,7 +991,7 @@ static int cmd_bap_broadcast_assistant_add_pa_sync(const struct shell *sh,
1001991
err = bt_bap_base_foreach_subgroup((const struct bt_bap_base *)received_base,
1002992
add_pa_sync_base_subgroup_cb, &param);
1003993
if (err < 0) {
1004-
shell_error(ctx_shell, "Could not add BASE to params %d", err);
994+
shell_error(sh, "Could not add BASE to params %d", err);
1005995

1006996
return -ENOEXEC;
1007997
}
@@ -1023,7 +1013,7 @@ static int cmd_bap_broadcast_assistant_add_pa_sync(const struct shell *sh,
10231013
if ((subgroups_bis_sync & bis_bitfield_req) != bis_bitfield_req) {
10241014
/* bis_sync of all subgroups should contain at least all the bits in request */
10251015
/* Otherwise Command will be rejected */
1026-
shell_error(ctx_shell, "Cannot set BIS index 0x%06X when BASE subgroups only "
1016+
shell_error(sh, "Cannot set BIS index 0x%06X when BASE subgroups only "
10271017
"supports %d", bis_bitfield_req, subgroups_bis_sync);
10281018
return -ENOEXEC;
10291019
}

0 commit comments

Comments
 (0)