bluetooth: shell: refactor shell print to eliminate ctx_shell usage

This change aims to eliminate the dependency on `ctx_shell` in
the Bluetooth `host/shell/*`, making the code more maintainable.
Replaced `shell_*` functions that depended on `ctx_shell` with
the appropriate `bt_shell_*` functions.

The shell-less functions `bt_do_scan_filter_clear_name`, `bt_do_scan_off`,
and `bt_do_connect_le` were added so they can be called without `sh`.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
This commit is contained in:
Pisit Sawangvonganan 2024-11-11 00:10:06 +07:00 committed by Benjamin Cabé
commit aa1a38e2aa
5 changed files with 323 additions and 297 deletions

View file

@ -35,6 +35,7 @@
#include <zephyr/bluetooth/ead.h>
#include <zephyr/shell/shell.h>
#include "bt_shell_private.h"
#include "audio/shell/audio.h"
#include "controller/ll_sw/shell/ll.h"
@ -125,8 +126,7 @@ static void print_le_addr(const char *desc, const bt_addr_le_t *addr)
bt_addr_le_to_str(addr, addr_str, sizeof(addr_str));
shell_print(ctx_shell, "%s address: %s (%s)", desc, addr_str,
addr_desc);
bt_shell_print("%s address: %s (%s)", desc, addr_str, addr_desc);
}
#endif /* CONFIG_BT_CONN || (CONFIG_BT_BROADCASTER && CONFIG_BT_EXT_ADV) */
@ -210,10 +210,9 @@ static const char *plm_report_zone_str(enum bt_conn_le_path_loss_zone zone)
#endif /* CONFIG_BT_PATH_LOSS_MONITORING */
#if defined(CONFIG_BT_CENTRAL)
static int cmd_scan_off(const struct shell *sh);
static int cmd_connect_le(const struct shell *sh, size_t argc, char *argv[]);
static int cmd_scan_filter_clear_name(const struct shell *sh, size_t argc,
char *argv[]);
static void bt_do_scan_filter_clear_name(void);
static int bt_do_scan_off(void);
static int bt_do_connect_le(int *ercd, size_t argc, char *argv[]);
static struct bt_auto_connect {
bt_addr_le_t addr;
@ -227,18 +226,17 @@ static void active_scan_timeout(struct k_work *work)
{
int err;
shell_print(ctx_shell, "Scan timeout");
bt_shell_print("Scan timeout");
err = bt_le_scan_stop();
if (err) {
shell_error(ctx_shell, "Failed to stop scan (err %d)", err);
bt_shell_error("Failed to stop scan (err %d)", err);
}
#if defined(CONFIG_BT_CENTRAL)
if (auto_connect.connect_name) {
auto_connect.connect_name = false;
/* "name" is what would be in argv[0] normally */
cmd_scan_filter_clear_name(ctx_shell, 1, (char *[]){ "name" });
bt_do_scan_filter_clear_name();
}
#endif /* CONFIG_BT_CENTRAL */
}
@ -326,12 +324,12 @@ static void print_data_hex(const uint8_t *data, uint8_t len, enum shell_vt100_co
return;
}
shell_fprintf(ctx_shell, color, "0x");
bt_shell_fprintf(color, "0x");
/* Reverse the byte order when printing as advertising data is LE
* and the MSB should be first in the printed output.
*/
for (int16_t i = len - 1; i >= 0; i--) {
shell_fprintf(ctx_shell, color, "%02x", data[i]);
bt_shell_fprintf(color, "%02x", data[i]);
}
}
@ -346,7 +344,7 @@ static void print_data_set(uint8_t set_value_len,
do {
if (idx > 0) {
shell_fprintf(ctx_shell, SHELL_INFO, ADV_DATA_DELIMITER);
bt_shell_fprintf_info(ADV_DATA_DELIMITER);
}
print_data_hex(&scan_data[idx], set_value_len, SHELL_INFO);
@ -354,15 +352,14 @@ static void print_data_set(uint8_t set_value_len,
} while (idx + set_value_len <= scan_data_len);
if (idx < scan_data_len) {
shell_fprintf(ctx_shell, SHELL_WARNING, " Excess data: ");
bt_shell_fprintf_warn(" Excess data: ");
print_data_hex(&scan_data[idx], scan_data_len - idx, SHELL_WARNING);
}
}
static bool data_verbose_cb(struct bt_data *data, void *user_data)
{
shell_fprintf(ctx_shell, SHELL_INFO, "%*sType 0x%02x: ",
strlen(scan_response_label), "", data->type);
bt_shell_fprintf_info("%*sType 0x%02x: ", strlen(scan_response_label), "", data->type);
switch (data->type) {
case BT_DATA_UUID16_SOME:
@ -375,14 +372,13 @@ static bool data_verbose_cb(struct bt_data *data, void *user_data)
* the rest is unknown and printed as single bytes
*/
if (data->data_len < BT_UUID_SIZE_16) {
shell_fprintf(ctx_shell, SHELL_WARNING,
"BT_DATA_SVC_DATA16 data length too short (%u)",
bt_shell_fprintf_warn("BT_DATA_SVC_DATA16 data length too short (%u)",
data->data_len);
break;
}
print_data_set(BT_UUID_SIZE_16, data->data, BT_UUID_SIZE_16);
if (data->data_len > BT_UUID_SIZE_16) {
shell_fprintf(ctx_shell, SHELL_INFO, ADV_DATA_DELIMITER);
bt_shell_fprintf_info(ADV_DATA_DELIMITER);
print_data_set(1, data->data + BT_UUID_SIZE_16,
data->data_len - BT_UUID_SIZE_16);
}
@ -396,14 +392,13 @@ static bool data_verbose_cb(struct bt_data *data, void *user_data)
* the rest is unknown and printed as single bytes
*/
if (data->data_len < BT_UUID_SIZE_32) {
shell_fprintf(ctx_shell, SHELL_WARNING,
"BT_DATA_SVC_DATA32 data length too short (%u)",
bt_shell_fprintf_warn("BT_DATA_SVC_DATA32 data length too short (%u)",
data->data_len);
break;
}
print_data_set(BT_UUID_SIZE_32, data->data, BT_UUID_SIZE_32);
if (data->data_len > BT_UUID_SIZE_32) {
shell_fprintf(ctx_shell, SHELL_INFO, ADV_DATA_DELIMITER);
bt_shell_fprintf_info(ADV_DATA_DELIMITER);
print_data_set(1, data->data + BT_UUID_SIZE_32,
data->data_len - BT_UUID_SIZE_32);
}
@ -418,14 +413,13 @@ static bool data_verbose_cb(struct bt_data *data, void *user_data)
* the rest is unknown and printed as single bytes
*/
if (data->data_len < BT_UUID_SIZE_128) {
shell_fprintf(ctx_shell, SHELL_WARNING,
"BT_DATA_SVC_DATA128 data length too short (%u)",
bt_shell_fprintf_warn("BT_DATA_SVC_DATA128 data length too short (%u)",
data->data_len);
break;
}
print_data_set(BT_UUID_SIZE_128, data->data, BT_UUID_SIZE_128);
if (data->data_len > BT_UUID_SIZE_128) {
shell_fprintf(ctx_shell, SHELL_INFO, ADV_DATA_DELIMITER);
bt_shell_fprintf_info(ADV_DATA_DELIMITER);
print_data_set(1, data->data + BT_UUID_SIZE_128,
data->data_len - BT_UUID_SIZE_128);
}
@ -433,7 +427,7 @@ static bool data_verbose_cb(struct bt_data *data, void *user_data)
case BT_DATA_NAME_SHORTENED:
case BT_DATA_NAME_COMPLETE:
case BT_DATA_BROADCAST_NAME:
shell_fprintf(ctx_shell, SHELL_INFO, "%.*s", data->data_len, data->data);
bt_shell_fprintf_info("%.*s", data->data_len, data->data);
break;
case BT_DATA_PUB_TARGET_ADDR:
case BT_DATA_RAND_TARGET_ADDR:
@ -444,12 +438,12 @@ static bool data_verbose_cb(struct bt_data *data, void *user_data)
print_data_set(3, data->data, data->data_len);
break;
case BT_DATA_ENCRYPTED_AD_DATA:
shell_fprintf(ctx_shell, SHELL_INFO, "Encrypted Advertising Data: ");
bt_shell_fprintf_info("Encrypted Advertising Data: ");
print_data_set(1, data->data, data->data_len);
if (bt_shell_ead_decrypt_scan) {
#if defined(CONFIG_BT_EAD)
shell_fprintf(ctx_shell, SHELL_INFO, "\n%*s[START DECRYPTED DATA]\n",
bt_shell_fprintf_info("\n%*s[START DECRYPTED DATA]\n",
strlen(scan_response_label), "");
int ead_err;
@ -460,7 +454,7 @@ static bool data_verbose_cb(struct bt_data *data, void *user_data)
ead_err = bt_ead_decrypt(bt_shell_ead_session_key, bt_shell_ead_iv,
data->data, data->data_len, decrypted_data);
if (ead_err) {
shell_error(ctx_shell, "Error during decryption (err %d)", ead_err);
bt_shell_error("Error during decryption (err %d)", ead_err);
}
net_buf_simple_init_with_data(&decrypted_buf, &decrypted_data[0],
@ -468,7 +462,7 @@ static bool data_verbose_cb(struct bt_data *data, void *user_data)
bt_data_parse(&decrypted_buf, &data_verbose_cb, user_data);
shell_fprintf(ctx_shell, SHELL_INFO, "%*s[END DECRYPTED DATA]",
bt_shell_fprintf_info("%*s[END DECRYPTED DATA]",
strlen(scan_response_label), "");
#endif
}
@ -477,7 +471,7 @@ static bool data_verbose_cb(struct bt_data *data, void *user_data)
print_data_set(1, data->data, data->data_len);
}
shell_fprintf(ctx_shell, SHELL_INFO, "\n");
bt_shell_fprintf_info("\n");
return true;
}
@ -560,7 +554,7 @@ static void scan_recv(const struct bt_le_scan_recv_info *info, struct net_buf_si
bt_data_parse(buf, data_cb, name);
bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr));
shell_print(ctx_shell, "%s%s, AD evt type %u, RSSI %i %s "
bt_shell_print("%s%s, AD evt type %u, RSSI %i %s "
"C:%u S:%u D:%d SR:%u E:%u Prim: %s, Secn: %s, "
"Interval: 0x%04x (%u us), SID: 0x%x",
scan_response_label,
@ -575,12 +569,11 @@ static void scan_recv(const struct bt_le_scan_recv_info *info, struct net_buf_si
info->sid);
if (scan_verbose_output) {
shell_info(ctx_shell,
"%*s[SCAN DATA START - %s]",
bt_shell_info("%*s[SCAN DATA START - %s]",
strlen(scan_response_label), "",
scan_response_type_txt(info->adv_type));
bt_data_parse(&buf_copy, data_verbose_cb, NULL);
shell_info(ctx_shell, "%*s[SCAN DATA END]", strlen(scan_response_label), "");
bt_shell_info("%*s[SCAN DATA END]", strlen(scan_response_label), "");
}
#if defined(CONFIG_BT_CENTRAL)
@ -595,15 +588,16 @@ static void scan_recv(const struct bt_le_scan_recv_info *info, struct net_buf_si
/* Use the above auto_connect.addr address to automatically connect */
if (auto_connect.connect_name) {
__maybe_unused int ercd;
auto_connect.connect_name = false;
cmd_scan_off(ctx_shell);
bt_do_scan_off();
/* "name" is what would be in argv[0] normally */
cmd_scan_filter_clear_name(ctx_shell, 1, (char *[]){"name"});
bt_do_scan_filter_clear_name();
/* "connect" is what would be in argv[0] normally */
cmd_connect_le(ctx_shell, 1, (char *[]){"connect"});
bt_do_connect_le(&ercd, 1, (char *[]){"connect"});
}
} else {
bt_conn_unref(conn);
@ -614,7 +608,7 @@ static void scan_recv(const struct bt_le_scan_recv_info *info, struct net_buf_si
static void scan_timeout(void)
{
shell_print(ctx_shell, "Scan timeout");
bt_shell_print("Scan timeout");
}
#endif /* CONFIG_BT_OBSERVER */
@ -623,8 +617,8 @@ static void scan_timeout(void)
static void adv_sent(struct bt_le_ext_adv *adv,
struct bt_le_ext_adv_sent_info *info)
{
shell_print(ctx_shell, "Advertiser[%d] %p sent %d",
bt_le_ext_adv_get_index(adv), adv, info->num_sent);
bt_shell_print("Advertiser[%d] %p sent %d", bt_le_ext_adv_get_index(adv), adv,
info->num_sent);
}
static void adv_scanned(struct bt_le_ext_adv *adv,
@ -634,8 +628,7 @@ static void adv_scanned(struct bt_le_ext_adv *adv,
bt_addr_le_to_str(info->addr, str, sizeof(str));
shell_print(ctx_shell, "Advertiser[%d] %p scanned by %s",
bt_le_ext_adv_get_index(adv), adv, str);
bt_shell_print("Advertiser[%d] %p scanned by %s", bt_le_ext_adv_get_index(adv), adv, str);
}
#endif /* CONFIG_BT_BROADCASTER */
@ -647,8 +640,7 @@ static void adv_connected(struct bt_le_ext_adv *adv,
bt_addr_le_to_str(bt_conn_get_dst(info->conn), str, sizeof(str));
shell_print(ctx_shell, "Advertiser[%d] %p connected by %s",
bt_le_ext_adv_get_index(adv), adv, str);
bt_shell_print("Advertiser[%d] %p connected by %s", bt_le_ext_adv_get_index(adv), adv, str);
}
#endif /* CONFIG_BT_PERIPHERAL */
@ -659,8 +651,7 @@ static bool adv_rpa_expired(struct bt_le_ext_adv *adv)
bool keep_rpa = atomic_test_bit(adv_set_opt[adv_index],
SHELL_ADV_OPT_KEEP_RPA);
shell_print(ctx_shell, "Advertiser[%d] %p RPA %s",
adv_index, adv,
bt_shell_print("Advertiser[%d] %p RPA %s", adv_index, adv,
keep_rpa ? "not expired" : "expired");
#if defined(CONFIG_BT_EAD)
@ -758,16 +749,16 @@ static void connected(struct bt_conn *conn, uint8_t err)
conn_addr_str(conn, addr, sizeof(addr));
if (err) {
shell_error(ctx_shell, "Failed to connect to %s 0x%02x %s", addr,
bt_shell_error("Failed to connect to %s 0x%02x %s", addr,
err, bt_hci_err_to_str(err));
goto done;
}
shell_print(ctx_shell, "Connected: %s", addr);
bt_shell_print("Connected: %s", addr);
info_err = bt_conn_get_info(conn, &info);
if (info_err != 0) {
shell_error(ctx_shell, "Failed to connection information: %d", info_err);
bt_shell_error("Failed to connection information: %d", info_err);
goto done;
}
@ -801,7 +792,7 @@ static void disconnected_set_new_default_conn_cb(struct bt_conn *conn, void *use
}
if (bt_conn_get_info(conn, &info) != 0) {
shell_error(ctx_shell, "Unable to get info: conn %p", conn);
bt_shell_error("Unable to get info: conn %p", conn);
return;
}
@ -811,7 +802,7 @@ static void disconnected_set_new_default_conn_cb(struct bt_conn *conn, void *use
default_conn = bt_conn_ref(conn);
bt_addr_le_to_str(info.le.dst, addr_str, sizeof(addr_str));
shell_print(ctx_shell, "Selected conn is now: %s", addr_str);
bt_shell_print("Selected conn is now: %s", addr_str);
}
}
@ -820,7 +811,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
char addr[BT_ADDR_LE_STR_LEN];
conn_addr_str(conn, addr, sizeof(addr));
shell_print(ctx_shell, "Disconnected: %s (reason 0x%02x)", addr, reason);
bt_shell_print("Disconnected: %s (reason 0x%02x)", addr, reason);
if (default_conn == conn) {
bt_conn_unref(default_conn);
@ -833,7 +824,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param)
{
shell_print(ctx_shell, "LE conn param req: int (0x%04x, 0x%04x) lat %d"
bt_shell_print("LE conn param req: int (0x%04x, 0x%04x) lat %d"
" to %d", param->interval_min, param->interval_max,
param->latency, param->timeout);
@ -843,7 +834,7 @@ static bool le_param_req(struct bt_conn *conn, struct bt_le_conn_param *param)
static void le_param_updated(struct bt_conn *conn, uint16_t interval,
uint16_t latency, uint16_t timeout)
{
shell_print(ctx_shell, "LE conn param updated: int 0x%04x lat %d "
bt_shell_print("LE conn param updated: int 0x%04x lat %d "
"to %d", interval, latency, timeout);
}
@ -857,8 +848,7 @@ static void identity_resolved(struct bt_conn *conn, const bt_addr_le_t *rpa,
bt_addr_le_to_str(identity, addr_identity, sizeof(addr_identity));
bt_addr_le_to_str(rpa, addr_rpa, sizeof(addr_rpa));
shell_print(ctx_shell, "Identity resolved %s -> %s", addr_rpa,
addr_identity);
bt_shell_print("Identity resolved %s -> %s", addr_rpa, addr_identity);
}
#endif
@ -897,10 +887,9 @@ static void security_changed(struct bt_conn *conn, bt_security_t level,
conn_addr_str(conn, addr, sizeof(addr));
if (!err) {
shell_print(ctx_shell, "Security changed: %s level %u", addr,
level);
bt_shell_print("Security changed: %s level %u", addr, level);
} else {
shell_print(ctx_shell, "Security failed: %s level %u "
bt_shell_print("Security failed: %s level %u "
"reason: %s (%d)",
addr, level, security_err_str(err), err);
}
@ -916,8 +905,7 @@ static void remote_info_available(struct bt_conn *conn,
bt_conn_get_info(conn, &info);
if (IS_ENABLED(CONFIG_BT_REMOTE_VERSION)) {
shell_print(ctx_shell,
"Remote LMP version %s (0x%02x) subversion 0x%04x "
bt_shell_print("Remote LMP version %s (0x%02x) subversion 0x%04x "
"manufacturer 0x%04x", bt_hci_get_ver_str(remote_info->version),
remote_info->version, remote_info->subversion,
remote_info->manufacturer);
@ -931,7 +919,7 @@ static void remote_info_available(struct bt_conn *conn,
sizeof(features));
bin2hex(features, sizeof(features),
features_str, sizeof(features_str));
shell_print(ctx_shell, "LE Features: 0x%s ", features_str);
bt_shell_print("LE Features: 0x%s ", features_str);
}
}
#endif /* defined(CONFIG_BT_REMOTE_INFO) */
@ -940,8 +928,7 @@ static void remote_info_available(struct bt_conn *conn,
void le_data_len_updated(struct bt_conn *conn,
struct bt_conn_le_data_len_info *info)
{
shell_print(ctx_shell,
"LE data len updated: TX (len: %d time: %d)"
bt_shell_print("LE data len updated: TX (len: %d time: %d)"
" RX (len: %d time: %d)", info->tx_max_len,
info->tx_max_time, info->rx_max_len, info->rx_max_time);
}
@ -951,7 +938,7 @@ void le_data_len_updated(struct bt_conn *conn,
void le_phy_updated(struct bt_conn *conn,
struct bt_conn_le_phy_info *info)
{
shell_print(ctx_shell, "LE PHY updated: TX PHY %s, RX PHY %s",
bt_shell_print("LE PHY updated: TX PHY %s, RX PHY %s",
phy2str(info->tx_phy), phy2str(info->rx_phy));
}
#endif
@ -960,10 +947,10 @@ void le_phy_updated(struct bt_conn *conn,
void tx_power_report(struct bt_conn *conn,
const struct bt_conn_le_tx_power_report *report)
{
shell_print(ctx_shell, "Tx Power Report: Reason: %s, PHY: %s, Tx Power Level: %d",
bt_shell_print("Tx Power Report: Reason: %s, PHY: %s, Tx Power Level: %d",
tx_power_report_reason2str(report->reason), tx_pwr_ctrl_phy2str(report->phy),
report->tx_power_level);
shell_print(ctx_shell, "Tx Power Level Flag Info: %s, Delta: %d",
bt_shell_print("Tx Power Level Flag Info: %s, Delta: %d",
tx_power_flag2str(report->tx_power_level_flag), report->delta);
}
#endif
@ -972,7 +959,7 @@ void tx_power_report(struct bt_conn *conn,
void path_loss_threshold_report(struct bt_conn *conn,
const struct bt_conn_le_path_loss_threshold_report *report)
{
shell_print(ctx_shell, "Path Loss Threshold event: Zone: %s, Path loss dbm: %d",
bt_shell_print("Path Loss Threshold event: Zone: %s, Path loss dbm: %d",
plm_report_zone_str(report->zone), report->path_loss);
}
#endif
@ -982,7 +969,7 @@ void subrate_changed(struct bt_conn *conn,
const struct bt_conn_le_subrate_changed *params)
{
if (params->status == BT_HCI_ERR_SUCCESS) {
shell_print(ctx_shell, "Subrate parameters changed: "
bt_shell_print("Subrate parameters changed: "
"Subrate Factor: %d "
"Continuation Number: %d "
"Peripheral latency: 0x%04x "
@ -993,7 +980,7 @@ void subrate_changed(struct bt_conn *conn,
params->supervision_timeout,
params->supervision_timeout * 10);
} else {
shell_print(ctx_shell, "Subrate change failed (HCI status 0x%02x)", params->status);
bt_shell_print("Subrate change failed (HCI status 0x%02x)", params->status);
}
}
#endif
@ -1001,8 +988,7 @@ void subrate_changed(struct bt_conn *conn,
#if defined(CONFIG_BT_CHANNEL_SOUNDING)
void print_remote_cs_capabilities(struct bt_conn *conn, struct bt_conn_le_cs_capabilities *params)
{
shell_print(
ctx_shell,
bt_shell_print(
"Received remote channel sounding capabilities:\n"
"- Num CS configurations: %d\n"
"- Max consecutive CS procedures: %d\n"
@ -1065,8 +1051,8 @@ void print_remote_cs_capabilities(struct bt_conn *conn, struct bt_conn_le_cs_cap
void print_remote_cs_fae_table(struct bt_conn *conn, struct bt_conn_le_cs_fae_table *params)
{
shell_print(ctx_shell, "Received FAE Table: ");
shell_hexdump(ctx_shell, params->remote_fae_table, 72);
bt_shell_print("Received FAE Table: ");
bt_shell_hexdump(params->remote_fae_table, 72);
}
static void le_cs_config_created(struct bt_conn *conn, struct bt_conn_le_cs_config *config)
@ -1091,7 +1077,7 @@ static void le_cs_config_created(struct bt_conn *conn, struct bt_conn_le_cs_conf
uint8_t chsel_type_idx = MIN(config->channel_selection_type, 2);
uint8_t ch3c_shape_idx = MIN(config->ch3c_shape, 2);
shell_print(ctx_shell,
bt_shell_print(
"New CS config created:\n"
"- ID: %d\n"
"- Role: %s\n"
@ -1124,7 +1110,7 @@ static void le_cs_config_created(struct bt_conn *conn, struct bt_conn_le_cs_conf
static void le_cs_config_removed(struct bt_conn *conn, uint8_t config_id)
{
shell_print(ctx_shell, "CS config %d is removed", config_id);
bt_shell_print("CS config %d is removed", config_id);
}
#endif
@ -1207,7 +1193,7 @@ static void per_adv_sync_sync_cb(struct bt_le_per_adv_sync *sync,
conn_addr_str(info->conn, past_peer, sizeof(past_peer));
}
shell_print(ctx_shell, "PER_ADV_SYNC[%u]: [DEVICE]: %s synced, "
bt_shell_print("PER_ADV_SYNC[%u]: [DEVICE]: %s synced, "
"Interval 0x%04x (%u us), PHY %s, SD 0x%04X, PAST peer %s",
bt_le_per_adv_sync_get_index(sync), le_addr,
info->interval, BT_CONN_INTERVAL_TO_US(info->interval),
@ -1238,7 +1224,7 @@ static void per_adv_sync_terminated_cb(
}
bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr));
shell_print(ctx_shell, "PER_ADV_SYNC[%u]: [DEVICE]: %s sync terminated",
bt_shell_print("PER_ADV_SYNC[%u]: [DEVICE]: %s sync terminated",
bt_le_per_adv_sync_get_index(sync), le_addr);
}
@ -1250,7 +1236,7 @@ static void per_adv_sync_recv_cb(
char le_addr[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(info->addr, le_addr, sizeof(le_addr));
shell_print(ctx_shell, "PER_ADV_SYNC[%u]: [DEVICE]: %s, tx_power %i, "
bt_shell_print("PER_ADV_SYNC[%u]: [DEVICE]: %s, tx_power %i, "
"RSSI %i, CTE %u, data length %u",
bt_le_per_adv_sync_get_index(sync), le_addr, info->tx_power,
info->rssi, info->cte_type, buf->len);
@ -1262,7 +1248,7 @@ static void per_adv_sync_biginfo_cb(struct bt_le_per_adv_sync *sync,
char le_addr[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(biginfo->addr, le_addr, sizeof(le_addr));
shell_print(ctx_shell, "BIG_INFO PER_ADV_SYNC[%u]: [DEVICE]: %s, sid 0x%02x, num_bis %u, "
bt_shell_print("BIG_INFO PER_ADV_SYNC[%u]: [DEVICE]: %s, sid 0x%02x, num_bis %u, "
"nse 0x%02x, interval 0x%04x (%u us), bn 0x%02x, pto 0x%02x, irc 0x%02x, "
"max_pdu 0x%04x, sdu_interval 0x%04x, max_sdu 0x%04x, phy %s, framing 0x%02x, "
"%sencrypted",
@ -1285,15 +1271,15 @@ static struct bt_le_per_adv_sync_cb per_adv_sync_cb = {
static void bt_ready(int err)
{
if (err) {
shell_error(ctx_shell, "Bluetooth init failed (err %d)", err);
bt_shell_error("Bluetooth init failed (err %d)", err);
return;
}
shell_print(ctx_shell, "Bluetooth initialized");
bt_shell_print("Bluetooth initialized");
if (IS_ENABLED(CONFIG_SETTINGS) && !no_settings_load) {
settings_load();
shell_print(ctx_shell, "Settings Loaded");
bt_shell_print("Settings Loaded");
}
if (IS_ENABLED(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY)) {
@ -1664,7 +1650,7 @@ static int cmd_passive_scan_on(const struct shell *sh, uint32_t options,
return 0;
}
static int cmd_scan_off(const struct shell *sh)
static int bt_do_scan_off(void)
{
int err;
@ -1672,6 +1658,15 @@ static int cmd_scan_off(const struct shell *sh)
(void)k_work_cancel_delayable(&active_scan_timeout_work);
err = bt_le_scan_stop();
return err;
}
static int cmd_scan_off(const struct shell *sh)
{
int err;
err = bt_do_scan_off();
if (err) {
shell_error(sh, "Stopping scanning failed (err %d)", err);
return err;
@ -1862,11 +1857,20 @@ static int cmd_scan_filter_clear_all(const struct shell *sh, size_t argc,
return 0;
}
static int cmd_scan_filter_clear_name(const struct shell *sh, size_t argc,
char *argv[])
static void bt_do_scan_filter_clear_name(void)
{
(void)memset(scan_filter.name, 0, sizeof(scan_filter.name));
scan_filter.name_set = false;
}
static int cmd_scan_filter_clear_name(const struct shell *sh, size_t argc,
char *argv[])
{
ARG_UNUSED(sh);
ARG_UNUSED(argc);
ARG_UNUSED(argv);
bt_do_scan_filter_clear_name();
return 0;
}
@ -1874,6 +1878,10 @@ static int cmd_scan_filter_clear_name(const struct shell *sh, size_t argc,
static int cmd_scan_filter_clear_addr(const struct shell *sh, size_t argc,
char *argv[])
{
ARG_UNUSED(sh);
ARG_UNUSED(argc);
ARG_UNUSED(argv);
(void)memset(scan_filter.addr, 0, sizeof(scan_filter.addr));
scan_filter.addr_set = false;
@ -1934,7 +1942,7 @@ static ssize_t ad_init(struct bt_data *data_array, const size_t data_array_size,
csis_ad_len = csis_ad_data_add(&data_array[ad_len],
data_array_size - ad_len, discoverable);
if (csis_ad_len < 0) {
shell_error(ctx_shell, "Failed to add CSIS data (err %d)", csis_ad_len);
bt_shell_error("Failed to add CSIS data (err %d)", csis_ad_len);
return ad_len;
}
@ -3257,28 +3265,27 @@ static int cmd_subrate_request(const struct shell *sh, size_t argc, char *argv[]
#if defined(CONFIG_BT_CONN)
#if defined(CONFIG_BT_CENTRAL)
static int cmd_connect_le(const struct shell *sh, size_t argc, char *argv[])
static int bt_do_connect_le(int *ercd, size_t argc, char *argv[])
{
int err;
bt_addr_le_t addr;
struct bt_conn *conn = NULL;
uint32_t options = 0;
*ercd = 0;
/* When no arguments are specified, connect to the last scanned device. */
if (argc == 1) {
if (auto_connect.addr_set) {
bt_addr_le_copy(&addr, &auto_connect.addr);
} else {
shell_error(sh, "No connectable adv stored, please trigger a scan first.");
shell_help(sh);
return SHELL_CMD_HELP_PRINTED;
return -ENOENT;
}
} else {
err = bt_addr_le_from_str(argv[1], argv[2], &addr);
if (err) {
shell_error(sh, "Invalid peer address (err %d)", err);
return err;
*ercd = err;
return -EINVAL;
}
}
@ -3291,7 +3298,6 @@ static int cmd_connect_le(const struct shell *sh, size_t argc, char *argv[])
} else if (!strcmp(arg, "no-1m")) {
options |= BT_CONN_LE_OPT_NO_1M;
} else {
shell_help(sh);
return SHELL_CMD_HELP_PRINTED;
}
}
@ -3305,12 +3311,9 @@ static int cmd_connect_le(const struct shell *sh, size_t argc, char *argv[])
err = bt_conn_le_create(&addr, create_params, BT_LE_CONN_PARAM_DEFAULT,
&conn);
if (err) {
shell_error(sh, "Connection failed (%d)", err);
*ercd = err;
return -ENOEXEC;
} else {
shell_print(sh, "Connection pending");
/* unref connection obj in advance as app user */
bt_conn_unref(conn);
}
@ -3318,6 +3321,32 @@ static int cmd_connect_le(const struct shell *sh, size_t argc, char *argv[])
return 0;
}
static int cmd_connect_le(const struct shell *sh, size_t argc, char *argv[])
{
int err;
int ercd;
err = bt_do_connect_le(&ercd, argc, argv);
switch (err) {
case -ENOENT:
shell_error(sh, "No connectable adv stored. Please trigger a scan first.");
shell_help(sh);
return SHELL_CMD_HELP_PRINTED;
case -EINVAL:
shell_error(sh, "Invalid peer address (err %d)", ercd);
return ercd;
case SHELL_CMD_HELP_PRINTED:
shell_help(sh);
return SHELL_CMD_HELP_PRINTED;
case -ENOEXEC:
shell_error(sh, "Connection failed (%d)", ercd);
return -ENOEXEC;
default:
shell_print(sh, "Connection pending");
return 0;
}
}
static int cmd_connect_le_name(const struct shell *sh, size_t argc, char *argv[])
{
const struct bt_le_scan_param param = {
@ -3904,7 +3933,7 @@ static void bond_info(const struct bt_bond_info *info, void *user_data)
int *bond_count = user_data;
bt_addr_le_to_str(&info->addr, addr, sizeof(addr));
shell_print(ctx_shell, "Remote Identity: %s", addr);
bt_shell_print("Remote Identity: %s", addr);
(*bond_count)++;
}
@ -3938,7 +3967,7 @@ static void connection_info(struct bt_conn *conn, void *user_data)
struct bt_conn_info info;
if (bt_conn_get_info(conn, &info) < 0) {
shell_error(ctx_shell, "Unable to get info: conn %p", conn);
bt_shell_error("Unable to get info: conn %p", conn);
return;
}
@ -3946,19 +3975,19 @@ static void connection_info(struct bt_conn *conn, void *user_data)
#if defined(CONFIG_BT_CLASSIC)
case BT_CONN_TYPE_BR:
bt_addr_to_str(info.br.dst, addr, sizeof(addr));
shell_print(ctx_shell, " #%u [BR][%s] %s", info.id, role_str(info.role), addr);
bt_shell_print(" #%u [BR][%s] %s", info.id, role_str(info.role), addr);
break;
#endif
case BT_CONN_TYPE_LE:
bt_addr_le_to_str(info.le.dst, addr, sizeof(addr));
shell_print(ctx_shell, "%s#%u [LE][%s] %s: Interval %u latency %u timeout %u",
bt_shell_print("%s#%u [LE][%s] %s: Interval %u latency %u timeout %u",
conn == default_conn ? "*" : " ", info.id, role_str(info.role), addr,
info.le.interval, info.le.latency, info.le.timeout);
break;
#if defined(CONFIG_BT_ISO)
case BT_CONN_TYPE_ISO:
bt_addr_le_to_str(info.le.dst, addr, sizeof(addr));
shell_print(ctx_shell, " #%u [ISO][%s] %s", info.id, role_str(info.role), addr);
bt_shell_print(" #%u [ISO][%s] %s", info.id, role_str(info.role), addr);
break;
#endif
default:
@ -3988,7 +4017,7 @@ static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey)
snprintk(passkey_str, 7, "%06u", passkey);
shell_print(ctx_shell, "Passkey for %s: %s", addr, passkey_str);
bt_shell_print("Passkey for %s: %s", addr, passkey_str);
}
#if defined(CONFIG_BT_PASSKEY_KEYPRESS)
@ -3999,7 +4028,7 @@ static void auth_passkey_display_keypress(struct bt_conn *conn,
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
shell_print(ctx_shell, "Passkey keypress notification from %s: type %d",
bt_shell_print("Passkey keypress notification from %s: type %d",
addr, type);
}
#endif
@ -4013,7 +4042,7 @@ static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey)
snprintk(passkey_str, 7, "%06u", passkey);
shell_print(ctx_shell, "Confirm passkey for %s: %s", addr, passkey_str);
bt_shell_print("Confirm passkey for %s: %s", addr, passkey_str);
}
static void auth_passkey_entry(struct bt_conn *conn)
@ -4022,7 +4051,7 @@ static void auth_passkey_entry(struct bt_conn *conn)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
shell_print(ctx_shell, "Enter passkey for %s", addr);
bt_shell_print("Enter passkey for %s", addr);
}
static void auth_cancel(struct bt_conn *conn)
@ -4031,7 +4060,7 @@ static void auth_cancel(struct bt_conn *conn)
conn_addr_str(conn, addr, sizeof(addr));
shell_print(ctx_shell, "Pairing cancelled: %s", addr);
bt_shell_print("Pairing cancelled: %s", addr);
/* clear connection reference for sec mode 3 pairing */
if (pairing_conn) {
@ -4046,7 +4075,7 @@ static void auth_pairing_confirm(struct bt_conn *conn)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
shell_print(ctx_shell, "Confirm pairing for %s", addr);
bt_shell_print("Confirm pairing for %s", addr);
}
#if !defined(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY)
@ -4092,9 +4121,7 @@ static void auth_pairing_oob_data_request(struct bt_conn *conn,
if (oobd_remote &&
!bt_addr_le_eq(info.le.remote, &oob_remote.addr)) {
bt_addr_le_to_str(info.le.remote, addr, sizeof(addr));
shell_print(ctx_shell,
"No OOB data available for remote %s",
addr);
bt_shell_print("No OOB data available for remote %s", addr);
bt_conn_auth_cancel(conn);
return;
}
@ -4102,9 +4129,7 @@ static void auth_pairing_oob_data_request(struct bt_conn *conn,
if (oobd_local &&
!bt_addr_le_eq(info.le.local, &oob_local.addr)) {
bt_addr_le_to_str(info.le.local, addr, sizeof(addr));
shell_print(ctx_shell,
"No OOB data available for local %s",
addr);
bt_shell_print("No OOB data available for local %s", addr);
bt_conn_auth_cancel(conn);
return;
}
@ -4112,14 +4137,14 @@ static void auth_pairing_oob_data_request(struct bt_conn *conn,
bt_le_oob_set_sc_data(conn, oobd_local, oobd_remote);
bt_addr_le_to_str(info.le.dst, addr, sizeof(addr));
shell_print(ctx_shell, "Set %s OOB SC data for %s, ",
bt_shell_print("Set %s OOB SC data for %s, ",
oob_config_str(oob_info->lesc.oob_config), addr);
return;
}
#endif /* CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY */
bt_addr_le_to_str(info.le.dst, addr, sizeof(addr));
shell_print(ctx_shell, "Legacy OOB TK requested from remote %s", addr);
bt_shell_print("Legacy OOB TK requested from remote %s", addr);
}
static void auth_pairing_complete(struct bt_conn *conn, bool bonded)
@ -4128,8 +4153,7 @@ static void auth_pairing_complete(struct bt_conn *conn, bool bonded)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
shell_print(ctx_shell, "%s with %s", bonded ? "Bonded" : "Paired",
addr);
bt_shell_print("%s with %s", bonded ? "Bonded" : "Paired", addr);
}
static void auth_pairing_failed(struct bt_conn *conn, enum bt_security_err err)
@ -4138,8 +4162,7 @@ static void auth_pairing_failed(struct bt_conn *conn, enum bt_security_err err)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
shell_print(ctx_shell, "Pairing failed with %s reason: %s (%d)", addr,
security_err_str(err), err);
bt_shell_print("Pairing failed with %s reason: %s (%d)", addr, security_err_str(err), err);
}
#if defined(CONFIG_BT_CLASSIC)
@ -4159,10 +4182,9 @@ static void auth_pincode_entry(struct bt_conn *conn, bool highsec)
bt_addr_to_str(info.br.dst, addr, sizeof(addr));
if (highsec) {
shell_print(ctx_shell, "Enter 16 digits wide PIN code for %s",
addr);
bt_shell_print("Enter 16 digits wide PIN code for %s", addr);
} else {
shell_print(ctx_shell, "Enter PIN code for %s", addr);
bt_shell_print("Enter PIN code for %s", addr);
}
/*
@ -4179,7 +4201,7 @@ static void auth_pincode_entry(struct bt_conn *conn, bool highsec)
enum bt_security_err pairing_accept(
struct bt_conn *conn, const struct bt_conn_pairing_feat *const feat)
{
shell_print(ctx_shell, "Remote pairing features: "
bt_shell_print("Remote pairing features: "
"IO: 0x%02x, OOB: %d, AUTH: 0x%02x, Key: %d, "
"Init Kdist: 0x%02x, Resp Kdist: 0x%02x",
feat->io_capability, feat->oob_data_flag,
@ -4195,7 +4217,7 @@ void bond_deleted(uint8_t id, const bt_addr_le_t *peer)
char addr[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(peer, addr, sizeof(addr));
shell_print(ctx_shell, "Bond deleted for %s, id %u", addr, id);
bt_shell_print("Bond deleted for %s, id %u", addr, id);
}
static struct bt_conn_auth_cb auth_cb_display = {
@ -4763,7 +4785,7 @@ int ead_encrypt_ad(const uint8_t *payload, uint8_t payload_size, uint8_t *encryp
err = bt_ead_encrypt(bt_shell_ead_session_key, bt_shell_ead_iv, payload, payload_size,
encrypted_payload);
if (err != 0) {
shell_error(ctx_shell, "Failed to encrypt AD.");
bt_shell_error("Failed to encrypt AD.");
return -1;
}
@ -4791,7 +4813,7 @@ int ead_update_ad(void)
if (ad->data_len < 0) {
/* if the len is less than 0 that mean there is not even a type field */
shell_error(ctx_shell, "Failed to update AD due to malformed AD.");
bt_shell_error("Failed to update AD due to malformed AD.");
return -ENOEXEC;
}
@ -4819,11 +4841,11 @@ int ead_update_ad(void)
err = bt_le_ext_adv_set_data(adv, ad_structs, bt_shell_ead_ad_len, NULL, 0);
if (err != 0) {
shell_error(ctx_shell, "Failed to set advertising data (err %d)", err);
bt_shell_error("Failed to set advertising data (err %d)", err);
return -ENOEXEC;
}
shell_info(ctx_shell, "Advertising data for Advertiser[%d] %p updated.", selected_adv, adv);
bt_shell_info("Advertising data for Advertiser[%d] %p updated.", selected_adv, adv);
return 0;
}

View file

@ -24,7 +24,8 @@
#include <zephyr/bluetooth/cs.h>
#include <errno.h>
#include "bt.h"
#include "host/shell/bt.h"
#include "host/shell/bt_shell_private.h"
static int check_cs_sync_antenna_selection_input(uint16_t input)
{
@ -138,21 +139,21 @@ static int cmd_read_remote_fae_table(const struct shell *sh, size_t argc, char *
static bool process_step_data(struct bt_le_cs_subevent_step *step, void *user_data)
{
shell_print(ctx_shell, "Subevent results contained step data: ");
shell_print(ctx_shell, "- Step mode %d\n"
bt_shell_print("Subevent results contained step data: ");
bt_shell_print("- Step mode %d\n"
"- Step channel %d\n"
"- Step data hexdump:",
step->mode,
step->channel);
shell_hexdump(ctx_shell, step->data, step->data_len);
bt_shell_hexdump(step->data, step->data_len);
return true;
}
static void cs_test_subevent_data_cb(struct bt_conn_le_cs_subevent_result *result)
{
shell_print(ctx_shell, "Received subevent results.");
shell_print(ctx_shell, "Subevent Header:\n"
bt_shell_print("Received subevent results.");
bt_shell_print("Subevent Header:\n"
"- Procedure Counter: %d\n"
"- Frequency Compensation: 0x%04x\n"
"- Reference Power Level: %d\n"
@ -179,7 +180,7 @@ static void cs_test_subevent_data_cb(struct bt_conn_le_cs_subevent_result *resul
static void cs_test_end_complete_cb(void)
{
shell_print(ctx_shell, "CS Test End Complete.");
bt_shell_print("CS Test End Complete.");
}
static int cmd_cs_test_simple(const struct shell *sh, size_t argc, char *argv[])

View file

@ -27,6 +27,7 @@
#include <zephyr/shell/shell.h>
#include "host/shell/bt.h"
#include "host/shell/bt_shell_private.h"
#if defined(CONFIG_BT_GATT_CLIENT) || defined(CONFIG_BT_GATT_DYNAMIC_DB)
extern uint8_t selected_id;
@ -75,7 +76,7 @@ static void update_write_stats(uint16_t len)
static void print_write_stats(void)
{
shell_print(ctx_shell, "Write #%u: %u bytes (%u bps)",
bt_shell_print("Write #%u: %u bytes (%u bps)",
write_stats.count, write_stats.total, write_stats.rate);
}
#endif /* CONFIG_BT_GATT_CLIENT || CONFIG_BT_GATT_DYNAMIC_DB */
@ -94,7 +95,7 @@ static struct bt_gatt_exchange_params exchange_params;
static void exchange_func(struct bt_conn *conn, uint8_t err,
struct bt_gatt_exchange_params *params)
{
shell_print(ctx_shell, "Exchange %s", err == 0U ? "successful" :
bt_shell_print("Exchange %s", err == 0U ? "successful" :
"failed");
/* Release global `exchange_params`. */
@ -139,43 +140,43 @@ static int cmd_exchange_mtu(const struct shell *sh,
static struct bt_gatt_discover_params discover_params;
static struct bt_uuid_16 uuid = BT_UUID_INIT_16(0);
static void print_chrc_props(const struct shell *sh, uint8_t properties)
static void print_chrc_props(uint8_t properties)
{
shell_print(sh, "Properties: ");
bt_shell_print("Properties: ");
if (properties & BT_GATT_CHRC_BROADCAST) {
shell_print(sh, "[bcast]");
bt_shell_print("[bcast]");
}
if (properties & BT_GATT_CHRC_READ) {
shell_print(sh, "[read]");
bt_shell_print("[read]");
}
if (properties & BT_GATT_CHRC_WRITE) {
shell_print(sh, "[write]");
bt_shell_print("[write]");
}
if (properties & BT_GATT_CHRC_WRITE_WITHOUT_RESP) {
shell_print(sh, "[write w/w rsp]");
bt_shell_print("[write w/w rsp]");
}
if (properties & BT_GATT_CHRC_NOTIFY) {
shell_print(sh, "[notify]");
bt_shell_print("[notify]");
}
if (properties & BT_GATT_CHRC_INDICATE) {
shell_print(sh, "[indicate]");
bt_shell_print("[indicate]");
}
if (properties & BT_GATT_CHRC_AUTH) {
shell_print(sh, "[auth]");
bt_shell_print("[auth]");
}
if (properties & BT_GATT_CHRC_EXT_PROP) {
shell_print(sh, "[ext prop]");
bt_shell_print("[ext prop]");
}
shell_print(sh, "");
bt_shell_print("");
}
static uint8_t discover_func(struct bt_conn *conn,
@ -188,7 +189,7 @@ static uint8_t discover_func(struct bt_conn *conn,
char str[BT_UUID_STR_LEN];
if (!attr) {
shell_print(ctx_shell, "Discover complete");
bt_shell_print("Discover complete");
(void)memset(params, 0, sizeof(*params));
return BT_GATT_ITER_STOP;
}
@ -198,28 +199,28 @@ static uint8_t discover_func(struct bt_conn *conn,
case BT_GATT_DISCOVER_PRIMARY:
gatt_service = attr->user_data;
bt_uuid_to_str(gatt_service->uuid, str, sizeof(str));
shell_print(ctx_shell, "Service %s found: start handle %x, "
bt_shell_print("Service %s found: start handle %x, "
"end_handle %x", str, attr->handle,
gatt_service->end_handle);
break;
case BT_GATT_DISCOVER_CHARACTERISTIC:
gatt_chrc = attr->user_data;
bt_uuid_to_str(gatt_chrc->uuid, str, sizeof(str));
shell_print(ctx_shell, "Characteristic %s found: handle %x",
bt_shell_print("Characteristic %s found: handle %x",
str, attr->handle);
print_chrc_props(ctx_shell, gatt_chrc->properties);
print_chrc_props(gatt_chrc->properties);
break;
case BT_GATT_DISCOVER_INCLUDE:
gatt_include = attr->user_data;
bt_uuid_to_str(gatt_include->uuid, str, sizeof(str));
shell_print(ctx_shell, "Include %s found: handle %x, start %x, "
bt_shell_print("Include %s found: handle %x, start %x, "
"end %x", str, attr->handle,
gatt_include->start_handle,
gatt_include->end_handle);
break;
default:
bt_uuid_to_str(attr->uuid, str, sizeof(str));
shell_print(ctx_shell, "Descriptor %s found: handle %x", str,
bt_shell_print("Descriptor %s found: handle %x", str,
attr->handle);
break;
}
@ -291,13 +292,13 @@ static uint8_t read_func(struct bt_conn *conn, uint8_t err,
struct bt_gatt_read_params *params,
const void *data, uint16_t length)
{
shell_print(ctx_shell, "Read complete: err 0x%02x length %u", err, length);
bt_shell_print("Read complete: err 0x%02x length %u", err, length);
if (!data) {
(void)memset(params, 0, sizeof(*params));
return BT_GATT_ITER_STOP;
} else {
shell_hexdump(ctx_shell, data, length);
bt_shell_hexdump(data, length);
}
return BT_GATT_ITER_CONTINUE;
@ -429,7 +430,7 @@ static uint8_t gatt_write_buf[BT_ATT_MAX_ATTRIBUTE_LEN];
static void write_func(struct bt_conn *conn, uint8_t err,
struct bt_gatt_write_params *params)
{
shell_print(ctx_shell, "Write complete: err 0x%02x", err);
bt_shell_print("Write complete: err 0x%02x", err);
(void)memset(&write_params, 0, sizeof(write_params));
}
@ -557,14 +558,14 @@ static uint8_t notify_func(struct bt_conn *conn,
const void *data, uint16_t length)
{
if (!data) {
shell_print(ctx_shell, "Unsubscribed");
bt_shell_print("Unsubscribed");
params->value_handle = 0U;
return BT_GATT_ITER_STOP;
}
shell_print(ctx_shell, "Notification: value_handle %u, length %u",
bt_shell_print("Notification: value_handle %u, length %u",
params->value_handle, length);
shell_hexdump(ctx_shell, data, length);
bt_shell_hexdump(data, length);
return BT_GATT_ITER_CONTINUE;
}
@ -793,7 +794,7 @@ static ssize_t write_vnd1(struct bt_conn *conn, const struct bt_gatt_attr *attr,
uint8_t flags)
{
if (echo_enabled) {
shell_print(ctx_shell, "Echo attr len %u", len);
bt_shell_print("Echo attr len %u", len);
bt_gatt_notify(conn, attr, buf, len);
}

View file

@ -23,6 +23,7 @@
#include <zephyr/bluetooth/iso.h>
#include "host/shell/bt.h"
#include "host/shell/bt_shell_private.h"
#if defined(CONFIG_BT_ISO_TX)
#define DEFAULT_IO_QOS \
@ -75,7 +76,7 @@ static void iso_recv(struct bt_iso_chan *chan, const struct bt_iso_recv_info *in
struct net_buf *buf)
{
if (info->flags & BT_ISO_FLAGS_VALID) {
shell_print(ctx_shell, "Incoming data channel %p len %u, seq: %d, ts: %d",
bt_shell_print("Incoming data channel %p len %u, seq: %d, ts: %d",
chan, buf->len, info->seq_num, info->ts);
}
}
@ -86,7 +87,7 @@ static void iso_connected(struct bt_iso_chan *chan)
struct bt_iso_info iso_info;
int err;
shell_print(ctx_shell, "ISO Channel %p connected", chan);
bt_shell_print("ISO Channel %p connected", chan);
err = bt_iso_chan_get_info(chan, &iso_info);
@ -108,7 +109,7 @@ static void iso_connected(struct bt_iso_chan *chan)
static void iso_disconnected(struct bt_iso_chan *chan, uint8_t reason)
{
shell_print(ctx_shell, "ISO Channel %p disconnected with reason 0x%02x",
bt_shell_print("ISO Channel %p disconnected with reason 0x%02x",
chan, reason);
}
@ -474,11 +475,11 @@ static int cmd_connect(const struct shell *sh, size_t argc, char *argv[])
static int iso_accept(const struct bt_iso_accept_info *info,
struct bt_iso_chan **chan)
{
shell_print(ctx_shell, "Incoming request from %p with CIG ID 0x%02X and CIS ID 0x%02X",
bt_shell_print("Incoming request from %p with CIG ID 0x%02X and CIS ID 0x%02X",
info->acl, info->cig_id, info->cis_id);
if (iso_chan.iso) {
shell_print(ctx_shell, "No channels available");
bt_shell_print("No channels available");
return -ENOMEM;
}

View file

@ -30,6 +30,7 @@
#include <zephyr/shell/shell.h>
#include "host/shell/bt.h"
#include "host/shell/bt_shell_private.h"
#define CREDITS 10
#define DATA_MTU (23 * CREDITS)
@ -89,7 +90,7 @@ static void l2cap_recv_cb(struct k_work *work)
struct net_buf *buf;
while ((buf = k_fifo_get(&l2cap_recv_fifo, K_NO_WAIT))) {
shell_print(ctx_shell, "Confirming reception");
bt_shell_print("Confirming reception");
bt_l2cap_chan_recv_complete(&c->ch.chan, buf);
}
}
@ -102,17 +103,17 @@ static int l2cap_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
return l2cap_recv_metrics(chan, buf);
}
shell_print(ctx_shell, "Incoming data channel %p len %u", chan,
bt_shell_print("Incoming data channel %p len %u", chan,
buf->len);
if (buf->len) {
shell_hexdump(ctx_shell, buf->data, buf->len);
bt_shell_hexdump(buf->data, buf->len);
}
if (l2cap_recv_delay_ms > 0) {
/* Submit work only if queue is empty */
if (k_fifo_is_empty(&l2cap_recv_fifo)) {
shell_print(ctx_shell, "Delaying response in %u ms...",
bt_shell_print("Delaying response in %u ms...",
l2cap_recv_delay_ms);
}
@ -127,12 +128,12 @@ static int l2cap_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
static void l2cap_sent(struct bt_l2cap_chan *chan)
{
shell_print(ctx_shell, "Outgoing data channel %p transmitted", chan);
bt_shell_print("Outgoing data channel %p transmitted", chan);
}
static void l2cap_status(struct bt_l2cap_chan *chan, atomic_t *status)
{
shell_print(ctx_shell, "Channel %p status %u", chan, (uint32_t)*status);
bt_shell_print("Channel %p status %u", chan, (uint32_t)*status);
}
static void l2cap_connected(struct bt_l2cap_chan *chan)
@ -141,19 +142,19 @@ static void l2cap_connected(struct bt_l2cap_chan *chan)
k_work_init_delayable(&c->recv_work, l2cap_recv_cb);
shell_print(ctx_shell, "Channel %p connected", chan);
bt_shell_print("Channel %p connected", chan);
}
static void l2cap_disconnected(struct bt_l2cap_chan *chan)
{
shell_print(ctx_shell, "Channel %p disconnected", chan);
bt_shell_print("Channel %p disconnected", chan);
}
static struct net_buf *l2cap_alloc_buf(struct bt_l2cap_chan *chan)
{
/* print if metrics is disabled */
if (!metrics) {
shell_print(ctx_shell, "Channel %p requires buffer", chan);
bt_shell_print("Channel %p requires buffer", chan);
}
return net_buf_alloc(&data_rx_pool, K_FOREVER);
@ -217,7 +218,7 @@ static int l2cap_accept(struct bt_conn *conn, struct bt_l2cap_server *server,
{
int err;
shell_print(ctx_shell, "Incoming conn %p", conn);
bt_shell_print("Incoming conn %p", conn);
err = l2cap_accept_policy(conn);
if (err < 0) {
@ -225,7 +226,7 @@ static int l2cap_accept(struct bt_conn *conn, struct bt_l2cap_server *server,
}
if (l2ch_chan.ch.chan.conn) {
shell_print(ctx_shell, "No channels available");
bt_shell_print("No channels available");
return -ENOMEM;
}