Skip to content

Commit 471feb2

Browse files
ndrs-pstkartben
authored andcommitted
bluetooth: shell: replace ctx_shell with sh where applicable
Limit the usage of `ctx_shell` to cases where printing requires it and `sh` is not available. Signed-off-by: Pisit Sawangvonganan <[email protected]>
1 parent 28ca65d commit 471feb2

File tree

1 file changed

+28
-33
lines changed
  • subsys/bluetooth/host/shell

1 file changed

+28
-33
lines changed

subsys/bluetooth/host/shell/bt.c

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,7 @@ static int cmd_id_show(const struct shell *sh, size_t argc, char *argv[])
15801580

15811581
bt_addr_le_to_str(&addrs[i], addr_str, sizeof(addr_str));
15821582
shell_print(sh, "%s%zu: %s", i == selected_id ? "*" : " ", i,
1583-
addr_str);
1583+
addr_str);
15841584
}
15851585

15861586
return 0;
@@ -1625,7 +1625,7 @@ static int cmd_active_scan_on(const struct shell *sh, uint32_t options,
16251625
err = bt_le_scan_start(&param, NULL);
16261626
if (err) {
16271627
shell_error(sh, "Bluetooth set active scan failed "
1628-
"(err %d)", err);
1628+
"(err %d)", err);
16291629
return err;
16301630
} else {
16311631
shell_print(sh, "Bluetooth active scan enabled");
@@ -1753,7 +1753,7 @@ static int cmd_scan_filter_set_name(const struct shell *sh, size_t argc,
17531753
const char *name_arg = argv[1];
17541754

17551755
if (strlen(name_arg) >= sizeof(scan_filter.name)) {
1756-
shell_error(ctx_shell, "Name is too long (max %zu): %s\n",
1756+
shell_error(sh, "Name is too long (max %zu): %s\n",
17571757
sizeof(scan_filter.name), name_arg);
17581758
return -ENOEXEC;
17591759
}
@@ -1773,8 +1773,7 @@ static int cmd_scan_filter_set_addr(const struct shell *sh, size_t argc,
17731773

17741774
/* Validate length including null terminator. */
17751775
if (len > max_cpy_len) {
1776-
shell_error(ctx_shell, "Invalid address string: %s\n",
1777-
addr_arg);
1776+
shell_error(sh, "Invalid address string: %s\n", addr_arg);
17781777
return -ENOEXEC;
17791778
}
17801779

@@ -1784,9 +1783,7 @@ static int cmd_scan_filter_set_addr(const struct shell *sh, size_t argc,
17841783
uint8_t tmp;
17851784

17861785
if (c != ':' && char2hex(c, &tmp) < 0) {
1787-
shell_error(ctx_shell,
1788-
"Invalid address string: %s\n",
1789-
addr_arg);
1786+
shell_error(sh, "Invalid address string: %s\n", addr_arg);
17901787
return -ENOEXEC;
17911788
}
17921789
}
@@ -2307,7 +2304,7 @@ static int cmd_adv_data(const struct shell *sh, size_t argc, char *argv[])
23072304
if (*data_len == ARRAY_SIZE(ad)) {
23082305
/* Maximum entries limit reached. */
23092306
shell_print(sh, "Failed to set advertising data: "
2310-
"Maximum entries limit reached");
2307+
"Maximum entries limit reached");
23112308

23122309
return -ENOEXEC;
23132310
}
@@ -2327,7 +2324,7 @@ static int cmd_adv_data(const struct shell *sh, size_t argc, char *argv[])
23272324
if (strcmp(arg, "scan-response") && *data_len == ARRAY_SIZE(ad)) {
23282325
/* Maximum entries limit reached. */
23292326
shell_print(sh, "Failed to set advertising data: "
2330-
"Maximum entries limit reached");
2327+
"Maximum entries limit reached");
23312328

23322329
return -ENOEXEC;
23332330
}
@@ -2341,7 +2338,7 @@ static int cmd_adv_data(const struct shell *sh, size_t argc, char *argv[])
23412338
} else if (!strcmp(arg, "scan-response")) {
23422339
if (data == sd) {
23432340
shell_print(sh, "Failed to set advertising data: "
2344-
"duplicate scan-response option");
2341+
"duplicate scan-response option");
23452342
return -ENOEXEC;
23462343
}
23472344

@@ -2358,7 +2355,7 @@ static int cmd_adv_data(const struct shell *sh, size_t argc, char *argv[])
23582355

23592356
if (!len || (len - 1) != (hex_data[hex_data_len])) {
23602357
shell_print(sh, "Failed to set advertising data: "
2361-
"malformed hex data");
2358+
"malformed hex data");
23622359
return -ENOEXEC;
23632360
}
23642361

@@ -2379,7 +2376,7 @@ static int cmd_adv_data(const struct shell *sh, size_t argc, char *argv[])
23792376
if (*data_len == ARRAY_SIZE(ad)) {
23802377
/* Maximum entries limit reached. */
23812378
shell_print(sh, "Failed to set advertising data: "
2382-
"Maximum entries limit reached");
2379+
"Maximum entries limit reached");
23832380

23842381
return -ENOEXEC;
23852382
}
@@ -2499,7 +2496,7 @@ static int cmd_adv_delete(const struct shell *sh, size_t argc, char *argv[])
24992496

25002497
err = bt_le_ext_adv_delete(adv);
25012498
if (err) {
2502-
shell_error(ctx_shell, "Failed to delete advertiser set");
2499+
shell_error(sh, "Failed to delete advertiser set");
25032500
return err;
25042501
}
25052502

@@ -3109,7 +3106,7 @@ static int cmd_set_power_report_enable(const struct shell *sh, size_t argc, char
31093106
return -ENOEXEC;
31103107
}
31113108
err = bt_conn_le_set_tx_power_report_enable(default_conn, local_enable,
3112-
remote_enable);
3109+
remote_enable);
31133110
if (!err) {
31143111
shell_print(sh, "Tx Power Report: local: %s, remote: %s",
31153112
enabled2str(local_enable), enabled2str(remote_enable));
@@ -3494,11 +3491,11 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[])
34943491

34953492
err = bt_conn_get_info(conn, &info);
34963493
if (err) {
3497-
shell_print(ctx_shell, "Failed to get info");
3494+
shell_print(sh, "Failed to get info");
34983495
goto done;
34993496
}
35003497

3501-
shell_print(ctx_shell, "Type: %s, Role: %s, Id: %u",
3498+
shell_print(sh, "Type: %s, Role: %s, Id: %u",
35023499
get_conn_type_str(info.type),
35033500
get_conn_role_str(info.role),
35043501
info.id);
@@ -3509,28 +3506,28 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[])
35093506
print_le_addr("Remote on-air", info.le.remote);
35103507
print_le_addr("Local on-air", info.le.local);
35113508

3512-
shell_print(ctx_shell, "Interval: 0x%04x (%u us)",
3509+
shell_print(sh, "Interval: 0x%04x (%u us)",
35133510
info.le.interval,
35143511
BT_CONN_INTERVAL_TO_US(info.le.interval));
3515-
shell_print(ctx_shell, "Latency: 0x%04x",
3512+
shell_print(sh, "Latency: 0x%04x",
35163513
info.le.latency);
3517-
shell_print(ctx_shell, "Supervision timeout: 0x%04x (%d ms)",
3514+
shell_print(sh, "Supervision timeout: 0x%04x (%d ms)",
35183515
info.le.timeout, info.le.timeout * 10);
35193516
#if defined(CONFIG_BT_USER_PHY_UPDATE)
3520-
shell_print(ctx_shell, "LE PHY: TX PHY %s, RX PHY %s",
3517+
shell_print(sh, "LE PHY: TX PHY %s, RX PHY %s",
35213518
phy2str(info.le.phy->tx_phy),
35223519
phy2str(info.le.phy->rx_phy));
35233520
#endif
35243521
#if defined(CONFIG_BT_USER_DATA_LEN_UPDATE)
3525-
shell_print(ctx_shell, "LE data len: TX (len: %d time: %d)"
3522+
shell_print(sh, "LE data len: TX (len: %d time: %d)"
35263523
" RX (len: %d time: %d)",
35273524
info.le.data_len->tx_max_len,
35283525
info.le.data_len->tx_max_time,
35293526
info.le.data_len->rx_max_len,
35303527
info.le.data_len->rx_max_time);
35313528
#endif
35323529
#if defined(CONFIG_BT_SUBRATING)
3533-
shell_print(ctx_shell, "LE Subrating: Subrate Factor: %d"
3530+
shell_print(sh, "LE Subrating: Subrate Factor: %d"
35343531
" Continuation Number: %d",
35353532
info.le.subrate->factor,
35363533
info.le.subrate->continuation_number);
@@ -3542,7 +3539,7 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[])
35423539
char addr_str[BT_ADDR_STR_LEN];
35433540

35443541
bt_addr_to_str(info.br.dst, addr_str, sizeof(addr_str));
3545-
shell_print(ctx_shell, "Peer address %s", addr_str);
3542+
shell_print(sh, "Peer address %s", addr_str);
35463543
}
35473544
#endif /* defined(CONFIG_BT_CLASSIC) */
35483545

@@ -3559,8 +3556,8 @@ static int cmd_conn_update(const struct shell *sh, size_t argc, char *argv[])
35593556

35603557
if (default_conn == NULL) {
35613558
shell_error(sh,
3562-
"%s: at least, one connection is required",
3563-
sh->ctx->active_cmd.syntax);
3559+
"%s: at least, one connection is required",
3560+
sh->ctx->active_cmd.syntax);
35643561
return -ENOEXEC;
35653562
}
35663563

@@ -3608,8 +3605,8 @@ static int cmd_conn_data_len_update(const struct shell *sh, size_t argc,
36083605

36093606
if (default_conn == NULL) {
36103607
shell_error(sh,
3611-
"%s: at least, one connection is required",
3612-
sh->ctx->active_cmd.syntax);
3608+
"%s: at least, one connection is required",
3609+
sh->ctx->active_cmd.syntax);
36133610
return -ENOEXEC;
36143611
}
36153612

@@ -3633,8 +3630,6 @@ static int cmd_conn_data_len_update(const struct shell *sh, size_t argc,
36333630
shell_print(sh, "Calculated tx time: %d", param.tx_max_time);
36343631
}
36353632

3636-
3637-
36383633
err = bt_conn_le_data_len_update(default_conn, &param);
36393634
if (err) {
36403635
shell_error(sh, "data len update failed (err %d).", err);
@@ -3655,8 +3650,8 @@ static int cmd_conn_phy_update(const struct shell *sh, size_t argc,
36553650

36563651
if (default_conn == NULL) {
36573652
shell_error(sh,
3658-
"%s: at least, one connection is required",
3659-
sh->ctx->active_cmd.syntax);
3653+
"%s: at least, one connection is required",
3654+
sh->ctx->active_cmd.syntax);
36603655
return -ENOEXEC;
36613656
}
36623657

@@ -3772,7 +3767,7 @@ static int cmd_clear(const struct shell *sh, size_t argc, char *argv[])
37723767
err = bt_unpair(selected_id, NULL);
37733768
if (err) {
37743769
shell_error(sh, "Failed to clear pairings (err %d)",
3775-
err);
3770+
err);
37763771
return err;
37773772
} else {
37783773
shell_print(sh, "Pairings successfully cleared");

0 commit comments

Comments
 (0)