diff --git a/subsys/bluetooth/host/shell/CMakeLists.txt b/subsys/bluetooth/host/shell/CMakeLists.txt index 98f1e6ac2a590d..73ff18086f3152 100644 --- a/subsys/bluetooth/host/shell/CMakeLists.txt +++ b/subsys/bluetooth/host/shell/CMakeLists.txt @@ -1,7 +1,10 @@ # SPDX-License-Identifier: Apache-2.0 zephyr_library() -zephyr_library_sources(bt.c) +zephyr_library_sources( + bt.c + bt_shell_private.c + ) zephyr_library_sources_ifdef(CONFIG_BT_CONN gatt.c) zephyr_library_sources_ifdef(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL l2cap.c) zephyr_library_sources_ifdef(CONFIG_BT_ISO iso.c) diff --git a/subsys/bluetooth/host/shell/bt.c b/subsys/bluetooth/host/shell/bt.c index da55537f3395e2..4284944d540b68 100644 --- a/subsys/bluetooth/host/shell/bt.c +++ b/subsys/bluetooth/host/shell/bt.c @@ -35,6 +35,7 @@ #include #include +#include "bt_shell_private.h" #include "audio/shell/audio.h" #include "controller/ll_sw/shell/ll.h" @@ -101,7 +102,8 @@ static ATOMIC_DEFINE(adv_set_opt, SHELL_ADV_OPT_NUM)[CONFIG_BT_EXT_ADV_MAX_ADV_S static const char *phy2str(uint8_t phy) { switch (phy) { - case 0: return "No packets"; + case 0: + return "No packets"; case BT_GAP_LE_PHY_1M: return "LE 1M"; case BT_GAP_LE_PHY_2M: @@ -125,8 +127,8 @@ 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) */ @@ -346,7 +348,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 +356,15 @@ 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 +377,14 @@ 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)", - data->data_len); + 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); } @@ -418,14 +420,14 @@ 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)", - data->data_len); + 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 +435,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,13 +446,13 @@ 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", - strlen(scan_response_label), ""); + bt_shell_fprintf_info("\n%*s[START DECRYPTED DATA]\n", + strlen(scan_response_label), ""); int ead_err; struct net_buf_simple decrypted_buf; @@ -460,7 +462,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,8 +470,8 @@ 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]", - strlen(scan_response_label), ""); + bt_shell_fprintf_info("%*s[END DECRYPTED DATA]", + strlen(scan_response_label), ""); #endif } break; @@ -477,7 +479,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,27 +562,26 @@ 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 " - "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, - le_addr, info->adv_type, info->rssi, name, - (info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE) != 0, - (info->adv_props & BT_GAP_ADV_PROP_SCANNABLE) != 0, - (info->adv_props & BT_GAP_ADV_PROP_DIRECTED) != 0, - (info->adv_props & BT_GAP_ADV_PROP_SCAN_RESPONSE) != 0, - (info->adv_props & BT_GAP_ADV_PROP_EXT_ADV) != 0, - phy2str(info->primary_phy), phy2str(info->secondary_phy), - info->interval, BT_CONN_INTERVAL_TO_US(info->interval), - info->sid); + 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, + le_addr, info->adv_type, info->rssi, name, + (info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE) != 0, + (info->adv_props & BT_GAP_ADV_PROP_SCANNABLE) != 0, + (info->adv_props & BT_GAP_ADV_PROP_DIRECTED) != 0, + (info->adv_props & BT_GAP_ADV_PROP_SCAN_RESPONSE) != 0, + (info->adv_props & BT_GAP_ADV_PROP_EXT_ADV) != 0, + phy2str(info->primary_phy), phy2str(info->secondary_phy), + info->interval, BT_CONN_INTERVAL_TO_US(info->interval), + info->sid); if (scan_verbose_output) { - shell_info(ctx_shell, - "%*s[SCAN DATA START - %s]", - strlen(scan_response_label), "", - scan_response_type_txt(info->adv_type)); + 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) @@ -614,7 +615,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 +624,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 +635,8 @@ 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 +648,8 @@ 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,9 +660,9 @@ 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, - keep_rpa ? "not expired" : "expired"); + bt_shell_print("Advertiser[%d] %p RPA %s", + adv_index, adv, + keep_rpa ? "not expired" : "expired"); #if defined(CONFIG_BT_EAD) /* EAD must be updated each time the RPA is updated */ @@ -744,9 +745,9 @@ static void print_le_oob(const struct shell *sh, struct bt_le_oob *oob) bin2hex(oob->le_sc_data.c, sizeof(oob->le_sc_data.c), c, sizeof(c)); bin2hex(oob->le_sc_data.r, sizeof(oob->le_sc_data.r), r, sizeof(r)); - shell_print(sh, "OOB data:"); - shell_print(sh, "%-29s %-32s %-32s", "addr", "random", "confirm"); - shell_print(sh, "%29s %32s %32s", addr, r, c); + bt_shell_print("OOB data:"); + bt_shell_print("%-29s %-32s %-32s", "addr", "random", "confirm"); + bt_shell_print("%29s %32s %32s", addr, r, c); } static void connected(struct bt_conn *conn, uint8_t err) @@ -758,16 +759,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, - err, bt_hci_err_to_str(err)); + 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 +802,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 +812,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 +821,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,9 +834,9 @@ 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" - " to %d", param->interval_min, param->interval_max, - param->latency, param->timeout); + 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); return true; } @@ -843,8 +844,8 @@ 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 " - "to %d", interval, latency, timeout); + bt_shell_print("LE conn param updated: int 0x%04x lat %d " + "to %d", interval, latency, timeout); } #if defined(CONFIG_BT_SMP) @@ -857,8 +858,8 @@ 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,12 +898,12 @@ 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 " - "reason: %s (%d)", - addr, level, security_err_str(err), err); + bt_shell_print("Security failed: %s level %u " + "reason: %s (%d)", + addr, level, security_err_str(err), err); } } #endif @@ -916,11 +917,10 @@ 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 " - "manufacturer 0x%04x", bt_hci_get_ver_str(remote_info->version), - remote_info->version, remote_info->subversion, - remote_info->manufacturer); + 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); } if (info.type == BT_CONN_TYPE_LE) { @@ -931,7 +931,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,10 +940,9 @@ 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)" - " RX (len: %d time: %d)", info->tx_max_len, - info->tx_max_time, info->rx_max_len, info->rx_max_time); + 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); } #endif @@ -951,8 +950,8 @@ 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", - phy2str(info->tx_phy), phy2str(info->rx_phy)); + bt_shell_print("LE PHY updated: TX PHY %s, RX PHY %s", + phy2str(info->tx_phy), phy2str(info->rx_phy)); } #endif @@ -960,11 +959,11 @@ 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", - 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", - tx_power_flag2str(report->tx_power_level_flag), report->delta); + 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); + bt_shell_print("Tx Power Level Flag Info: %s, Delta: %d", + tx_power_flag2str(report->tx_power_level_flag), report->delta); } #endif @@ -972,8 +971,8 @@ 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", - plm_report_zone_str(report->zone), report->path_loss); + bt_shell_print("Path Loss Threshold event: Zone: %s, Path loss dbm: %d", + plm_report_zone_str(report->zone), report->path_loss); } #endif @@ -1207,12 +1206,12 @@ 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, " - "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), - phy2str(info->phy), info->service_data, - is_past_peer ? past_peer : "not present"); + 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), + phy2str(info->phy), info->service_data, + is_past_peer ? past_peer : "not present"); if (info->conn) { /* if from PAST */ for (int i = 0; i < ARRAY_SIZE(per_adv_syncs); i++) { @@ -1238,8 +1237,8 @@ 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_le_per_adv_sync_get_index(sync), le_addr); + bt_shell_print("PER_ADV_SYNC[%u]: [DEVICE]: %s sync terminated", + bt_le_per_adv_sync_get_index(sync), le_addr); } static void per_adv_sync_recv_cb( @@ -1250,10 +1249,10 @@ 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, " - "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); + 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); } static void per_adv_sync_biginfo_cb(struct bt_le_per_adv_sync *sync, @@ -1262,16 +1261,16 @@ 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, " - "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", - bt_le_per_adv_sync_get_index(sync), le_addr, biginfo->sid, biginfo->num_bis, - biginfo->sub_evt_count, biginfo->iso_interval, - BT_CONN_INTERVAL_TO_US(biginfo->iso_interval), biginfo->burst_number, - biginfo->offset, biginfo->rep_count, biginfo->max_pdu, biginfo->sdu_interval, - biginfo->max_sdu, phy2str(biginfo->phy), biginfo->framing, - biginfo->encryption ? "" : "not "); + 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", + bt_le_per_adv_sync_get_index(sync), le_addr, biginfo->sid, biginfo->num_bis, + biginfo->sub_evt_count, biginfo->iso_interval, + BT_CONN_INTERVAL_TO_US(biginfo->iso_interval), biginfo->burst_number, + biginfo->offset, biginfo->rep_count, biginfo->max_pdu, biginfo->sdu_interval, + biginfo->max_sdu, phy2str(biginfo->phy), biginfo->framing, + biginfo->encryption ? "" : "not "); } static struct bt_le_per_adv_sync_cb per_adv_sync_cb = { @@ -1285,15 +1284,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)) { @@ -1347,8 +1346,8 @@ static int cmd_init(const struct shell *sh, size_t argc, char *argv[]) } else { err = bt_enable(bt_ready); if (err) { - shell_error(sh, "Bluetooth init failed (err %d)", - err); + bt_shell_error("Bluetooth init failed (err %d)", + err); } } @@ -1368,11 +1367,11 @@ static int cmd_settings_load(const struct shell *sh, size_t argc, err = settings_load(); if (err) { - shell_error(sh, "Settings load failed (err %d)", err); + bt_shell_error("Settings load failed (err %d)", err); return err; } - shell_print(sh, "Settings loaded"); + bt_shell_print("Settings loaded"); return 0; } #endif @@ -1395,14 +1394,14 @@ static int cmd_hci_cmd(const struct shell *sh, size_t argc, char *argv[]) size_t len; if (strlen(argv[3]) > 2 * HCI_CMD_MAX_PARAM) { - shell_error(sh, "Data field too large\n"); + bt_shell_error("Data field too large\n"); return -ENOEXEC; } len = hex2bin(argv[3], strlen(argv[3]), &hex_data[hex_data_len], sizeof(hex_data) - hex_data_len); if (!len) { - shell_error(sh, "HCI command illegal data field\n"); + bt_shell_error("HCI command illegal data field\n"); return -ENOEXEC; } @@ -1417,7 +1416,7 @@ static int cmd_hci_cmd(const struct shell *sh, size_t argc, char *argv[]) err = bt_hci_cmd_send_sync(BT_OP(ogf, ocf), buf, &rsp); if (err) { - shell_error(sh, "HCI command failed (err %d)", err); + bt_shell_error("HCI command failed (err %d)", err); return err; } else { shell_hexdump(sh, rsp->data, rsp->len); @@ -1433,14 +1432,14 @@ static int cmd_name(const struct shell *sh, size_t argc, char *argv[]) int err; if (argc < 2) { - shell_print(sh, "Bluetooth Local Name: %s", bt_get_name()); + bt_shell_print("Bluetooth Local Name: %s", bt_get_name()); return 0; } err = bt_set_name(argv[1]); if (err) { - shell_error(sh, "Unable to set name %s (err %d)", argv[1], - err); + bt_shell_error("Unable to set name %s (err %d)", argv[1], + err); return err; } @@ -1450,7 +1449,7 @@ static int cmd_name(const struct shell *sh, size_t argc, char *argv[]) static int cmd_appearance(const struct shell *sh, size_t argc, char *argv[]) { if (argc == 1) { - shell_print(sh, "Bluetooth Appearance: 0x%04x", bt_get_appearance()); + bt_shell_print("Bluetooth Appearance: 0x%04x", bt_get_appearance()); return 0; } @@ -1462,19 +1461,19 @@ static int cmd_appearance(const struct shell *sh, size_t argc, char *argv[]) val = argv[1]; if (strlen(val) != 6 || strncmp(val, "0x", 2)) { - shell_error(sh, "Argument must be 0x followed by exactly 4 hex digits."); + bt_shell_error("Argument must be 0x followed by exactly 4 hex digits."); return -EINVAL; } app = shell_strtoul(val, 16, &err); if (err) { - shell_error(sh, "Argument must be 0x followed by exactly 4 hex digits."); + bt_shell_error("Argument must be 0x followed by exactly 4 hex digits."); return -EINVAL; } err = bt_set_appearance(app); if (err) { - shell_error(sh, "bt_set_appearance(0x%04x) failed with err %d", app, err); + bt_shell_error("bt_set_appearance(0x%04x) failed with err %d", app, err); return err; } #endif /* defined(CONFIG_BT_DEVICE_APPEARANCE_DYNAMIC) */ @@ -1491,7 +1490,7 @@ static int cmd_id_create(const struct shell *sh, size_t argc, char *argv[]) if (argc > 1) { err = bt_addr_le_from_str(argv[1], "random", &addr); if (err) { - shell_error(sh, "Invalid address"); + bt_shell_error("Invalid address"); } } else { bt_addr_le_copy(&addr, BT_ADDR_LE_ANY); @@ -1499,12 +1498,12 @@ static int cmd_id_create(const struct shell *sh, size_t argc, char *argv[]) err = bt_id_create(&addr, NULL); if (err < 0) { - shell_error(sh, "Creating new ID failed (err %d)", err); + bt_shell_error("Creating new ID failed (err %d)", err); return err; } bt_addr_le_to_str(&addr, addr_str, sizeof(addr_str)); - shell_print(sh, "New identity (%d) created: %s", err, addr_str); + bt_shell_print("New identity (%d) created: %s", err, addr_str); return 0; } @@ -1517,7 +1516,7 @@ static int cmd_id_reset(const struct shell *sh, size_t argc, char *argv[]) int err; if (argc < 2) { - shell_error(sh, "Identity identifier not specified"); + bt_shell_error("Identity identifier not specified"); return -ENOEXEC; } @@ -1526,7 +1525,7 @@ static int cmd_id_reset(const struct shell *sh, size_t argc, char *argv[]) if (argc > 2) { err = bt_addr_le_from_str(argv[2], "random", &addr); if (err) { - shell_print(sh, "Invalid address"); + bt_shell_print("Invalid address"); return err; } } else { @@ -1535,12 +1534,12 @@ static int cmd_id_reset(const struct shell *sh, size_t argc, char *argv[]) err = bt_id_reset(id, &addr, NULL); if (err < 0) { - shell_print(sh, "Resetting ID %u failed (err %d)", id, err); + bt_shell_print("Resetting ID %u failed (err %d)", id, err); return err; } bt_addr_le_to_str(&addr, addr_str, sizeof(addr_str)); - shell_print(sh, "Identity %u reset: %s", id, addr_str); + bt_shell_print("Identity %u reset: %s", id, addr_str); return 0; } @@ -1551,7 +1550,7 @@ static int cmd_id_delete(const struct shell *sh, size_t argc, char *argv[]) int err; if (argc < 2) { - shell_error(sh, "Identity identifier not specified"); + bt_shell_error("Identity identifier not specified"); return -ENOEXEC; } @@ -1559,11 +1558,11 @@ static int cmd_id_delete(const struct shell *sh, size_t argc, char *argv[]) err = bt_id_delete(id); if (err < 0) { - shell_error(sh, "Deleting ID %u failed (err %d)", id, err); + bt_shell_error("Deleting ID %u failed (err %d)", id, err); return err; } - shell_print(sh, "Identity %u deleted", id); + bt_shell_print("Identity %u deleted", id); return 0; } @@ -1579,8 +1578,8 @@ static int cmd_id_show(const struct shell *sh, size_t argc, char *argv[]) char addr_str[BT_ADDR_LE_STR_LEN]; bt_addr_le_to_str(&addrs[i], addr_str, sizeof(addr_str)); - shell_print(sh, "%s%zu: %s", i == selected_id ? "*" : " ", i, - addr_str); + bt_shell_print("%s%zu: %s", i == selected_id ? "*" : " ", i, + addr_str); } return 0; @@ -1597,12 +1596,12 @@ static int cmd_id_select(const struct shell *sh, size_t argc, char *argv[]) bt_id_get(addrs, &count); if (count <= id) { - shell_error(sh, "Invalid identity"); + bt_shell_error("Invalid identity"); return -ENOEXEC; } bt_addr_le_to_str(&addrs[id], addr_str, sizeof(addr_str)); - shell_print(sh, "Selected identity: %s", addr_str); + bt_shell_print("Selected identity: %s", addr_str); selected_id = id; return 0; @@ -1624,11 +1623,11 @@ static int cmd_active_scan_on(const struct shell *sh, uint32_t options, err = bt_le_scan_start(¶m, NULL); if (err) { - shell_error(sh, "Bluetooth set active scan failed " - "(err %d)", err); + bt_shell_error("Bluetooth set active scan failed " + "(err %d)", err); return err; } else { - shell_print(sh, "Bluetooth active scan enabled"); + bt_shell_print("Bluetooth active scan enabled"); } if (timeout != 0) { @@ -1654,11 +1653,11 @@ static int cmd_passive_scan_on(const struct shell *sh, uint32_t options, err = bt_le_scan_start(¶m, NULL); if (err) { - shell_error(sh, "Bluetooth set passive scan failed " - "(err %d)", err); + bt_shell_error("Bluetooth set passive scan failed " + "(err %d)", err); return err; } else { - shell_print(sh, "Bluetooth passive scan enabled"); + bt_shell_print("Bluetooth passive scan enabled"); } return 0; @@ -1673,10 +1672,10 @@ static int cmd_scan_off(const struct shell *sh) err = bt_le_scan_stop(); if (err) { - shell_error(sh, "Stopping scanning failed (err %d)", err); + bt_shell_error("Stopping scanning failed (err %d)", err); return err; } else { - shell_print(sh, "Scan successfully stopped"); + bt_shell_print("Scan successfully stopped"); } return 0; @@ -1753,8 +1752,8 @@ static int cmd_scan_filter_set_name(const struct shell *sh, size_t argc, const char *name_arg = argv[1]; if (strlen(name_arg) >= sizeof(scan_filter.name)) { - shell_error(ctx_shell, "Name is too long (max %zu): %s\n", - sizeof(scan_filter.name), name_arg); + bt_shell_error("Name is too long (max %zu): %s\n", + sizeof(scan_filter.name), name_arg); return -ENOEXEC; } @@ -1772,8 +1771,8 @@ static int cmd_scan_filter_set_addr(const struct shell *sh, size_t argc, /* Validate length including null terminator. */ if (strlen(addr_arg) > max_cpy_len) { - shell_error(ctx_shell, "Invalid address string: %s\n", - addr_arg); + bt_shell_error("Invalid address string: %s\n", + addr_arg); return -ENOEXEC; } @@ -1783,9 +1782,8 @@ static int cmd_scan_filter_set_addr(const struct shell *sh, size_t argc, uint8_t tmp; if (c != ':' && char2hex(c, &tmp) < 0) { - shell_error(ctx_shell, - "Invalid address string: %s\n", - addr_arg); + bt_shell_error("Invalid address string: %s\n", + addr_arg); return -ENOEXEC; } } @@ -1808,16 +1806,16 @@ static int cmd_scan_filter_set_rssi(const struct shell *sh, size_t argc, char *a if (IN_RANGE(rssi, INT8_MIN, INT8_MAX)) { scan_filter.rssi = (int8_t)rssi; scan_filter.rssi_set = true; - shell_print(sh, "RSSI cutoff set at %d dB", scan_filter.rssi); + bt_shell_print("RSSI cutoff set at %d dB", scan_filter.rssi); return 0; } - shell_print(sh, "value out of bounds (%d to %d)", INT8_MIN, INT8_MAX); + bt_shell_print("value out of bounds (%d to %d)", INT8_MIN, INT8_MAX); err = -ERANGE; } - shell_print(sh, "error %d", err); + bt_shell_print("error %d", err); shell_help(sh); return SHELL_CMD_HELP_PRINTED; @@ -1837,20 +1835,20 @@ static int cmd_scan_filter_set_pa_interval(const struct shell *sh, size_t argc, BT_GAP_PER_ADV_MAX_INTERVAL)) { scan_filter.pa_interval = (uint16_t)pa_interval; scan_filter.pa_interval_set = true; - shell_print(sh, "PA interval cutoff set at %u", - scan_filter.pa_interval); + bt_shell_print("PA interval cutoff set at %u", + scan_filter.pa_interval); return 0; } - shell_print(sh, "value out of bounds (%d to %d)", - BT_GAP_PER_ADV_MIN_INTERVAL, - BT_GAP_PER_ADV_MAX_INTERVAL); + bt_shell_print("value out of bounds (%d to %d)", + BT_GAP_PER_ADV_MIN_INTERVAL, + BT_GAP_PER_ADV_MAX_INTERVAL); err = -ERANGE; } - shell_print(sh, "error %d", err); + bt_shell_print("error %d", err); shell_help(sh); return SHELL_CMD_HELP_PRINTED; @@ -1936,7 +1934,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; } @@ -1989,10 +1987,10 @@ static int cmd_advertise(const struct shell *sh, size_t argc, char *argv[]) if (!strcmp(argv[1], "off")) { if (bt_le_adv_stop() < 0) { - shell_error(sh, "Failed to stop advertising"); + bt_shell_error("Failed to stop advertising"); return -ENOEXEC; } else { - shell_print(sh, "Advertising stopped"); + bt_shell_print("Advertising stopped"); } return 0; @@ -2071,11 +2069,11 @@ static int cmd_advertise(const struct shell *sh, size_t argc, char *argv[]) err = bt_le_adv_start(¶m, ad_len > 0 ? ad : NULL, ad_len, sd_len > 0 ? sd : NULL, sd_len); if (err < 0) { - shell_error(sh, "Failed to start advertising (err %d)", + bt_shell_error("Failed to start advertising (err %d)", err); return err; } else { - shell_print(sh, "Advertising started"); + bt_shell_print("Advertising started"); } return 0; @@ -2096,7 +2094,7 @@ static int cmd_directed_adv(const struct shell *sh, err = bt_addr_le_from_str(argv[1], argv[2], &addr); param = *BT_LE_ADV_CONN_DIR(&addr); if (err) { - shell_error(sh, "Invalid peer address (err %d)", err); + bt_shell_error("Invalid peer address (err %d)", err); return err; } @@ -2125,11 +2123,11 @@ static int cmd_directed_adv(const struct shell *sh, err = bt_le_adv_start(¶m, NULL, 0, NULL, 0); if (err) { - shell_error(sh, "Failed to start directed advertising (%d)", - err); + bt_shell_error("Failed to start directed advertising (%d)", + err); return -ENOEXEC; } else { - shell_print(sh, "Started directed advertising"); + bt_shell_print("Started directed advertising"); } return 0; @@ -2236,7 +2234,7 @@ static int cmd_adv_create(const struct shell *sh, size_t argc, char *argv[]) err = bt_le_ext_adv_create(¶m, &adv_callbacks, &adv); if (err) { - shell_error(sh, "Failed to create advertiser set (%d)", err); + bt_shell_error("Failed to create advertiser set (%d)", err); return -ENOEXEC; } @@ -2249,7 +2247,7 @@ static int cmd_adv_create(const struct shell *sh, size_t argc, char *argv[]) atomic_set_bit_to(adv_set_opt[adv_index], SHELL_ADV_OPT_EXT_ADV, (param.options & BT_LE_ADV_OPT_EXT_ADV) > 0); - shell_print(sh, "Created adv id: %d, adv: %p", adv_index, adv); + bt_shell_print("Created adv id: %d, adv: %p", adv_index, adv); return 0; } @@ -2267,7 +2265,7 @@ static int cmd_adv_param(const struct shell *sh, size_t argc, char *argv[]) err = bt_le_ext_adv_update_param(adv, ¶m); if (err) { - shell_error(sh, "Failed to update advertiser set (%d)", err); + bt_shell_error("Failed to update advertiser set (%d)", err); return -ENOEXEC; } @@ -2307,8 +2305,8 @@ static int cmd_adv_data(const struct shell *sh, size_t argc, char *argv[]) if (name && !dev_name && name_value == NULL) { if (*data_len == ARRAY_SIZE(ad)) { /* Maximum entries limit reached. */ - shell_print(sh, "Failed to set advertising data: " - "Maximum entries limit reached"); + bt_shell_print("Failed to set advertising data: " + "Maximum entries limit reached"); return -ENOEXEC; } @@ -2327,8 +2325,8 @@ static int cmd_adv_data(const struct shell *sh, size_t argc, char *argv[]) if (strcmp(arg, "scan-response") && *data_len == ARRAY_SIZE(ad)) { /* Maximum entries limit reached. */ - shell_print(sh, "Failed to set advertising data: " - "Maximum entries limit reached"); + bt_shell_print("Failed to set advertising data: " + "Maximum entries limit reached"); return -ENOEXEC; } @@ -2341,8 +2339,8 @@ static int cmd_adv_data(const struct shell *sh, size_t argc, char *argv[]) appearance = true; } else if (!strcmp(arg, "scan-response")) { if (data == sd) { - shell_print(sh, "Failed to set advertising data: " - "duplicate scan-response option"); + bt_shell_print("Failed to set advertising data: " + "duplicate scan-response option"); return -ENOEXEC; } @@ -2358,8 +2356,8 @@ static int cmd_adv_data(const struct shell *sh, size_t argc, char *argv[]) sizeof(hex_data) - hex_data_len); if (!len || (len - 1) != (hex_data[hex_data_len])) { - shell_print(sh, "Failed to set advertising data: " - "malformed hex data"); + bt_shell_print("Failed to set advertising data: " + "malformed hex data"); return -ENOEXEC; } @@ -2372,15 +2370,15 @@ static int cmd_adv_data(const struct shell *sh, size_t argc, char *argv[]) } if (name && !dev_name && name_value == NULL) { - shell_error(sh, "Failed to set advertising data: Expected a value for 'name'"); + bt_shell_error("Failed to set advertising data: Expected a value for 'name'"); return -ENOEXEC; } if (name && dev_name && name_value == NULL) { if (*data_len == ARRAY_SIZE(ad)) { /* Maximum entries limit reached. */ - shell_print(sh, "Failed to set advertising data: " - "Maximum entries limit reached"); + bt_shell_print("Failed to set advertising data: " + "Maximum entries limit reached"); return -ENOEXEC; } @@ -2396,7 +2394,7 @@ static int cmd_adv_data(const struct shell *sh, size_t argc, char *argv[]) len = ad_init(&data[*data_len], AD_SIZE - *data_len, adv_set_opt[selected_adv]); if (len < 0) { - shell_error(sh, "Failed to initialize stack advertising data"); + bt_shell_error("Failed to initialize stack advertising data"); return -ENOEXEC; } @@ -2410,8 +2408,8 @@ static int cmd_adv_data(const struct shell *sh, size_t argc, char *argv[]) err = bt_le_ext_adv_set_data(adv, ad_len > 0 ? ad : NULL, ad_len, sd_len > 0 ? sd : NULL, sd_len); if (err) { - shell_print(sh, "Failed to set advertising set data (%d)", - err); + bt_shell_print("Failed to set advertising set data (%d)", + err); return -ENOEXEC; } @@ -2427,7 +2425,7 @@ static int cmd_adv_start(const struct shell *sh, size_t argc, char *argv[]) int err; if (!adv) { - shell_print(sh, "Advertiser[%d] not created", selected_adv); + bt_shell_print("Advertiser[%d] not created", selected_adv); return -EINVAL; } @@ -2456,11 +2454,11 @@ static int cmd_adv_start(const struct shell *sh, size_t argc, char *argv[]) err = bt_le_ext_adv_start(adv, ¶m); if (err) { - shell_print(sh, "Failed to start advertising set (%d)", err); + bt_shell_print("Failed to start advertising set (%d)", err); return -ENOEXEC; } - shell_print(sh, "Advertiser[%d] %p set started", selected_adv, adv); + bt_shell_print("Advertiser[%d] %p set started", selected_adv, adv); return 0; fail_show_help: @@ -2474,17 +2472,17 @@ static int cmd_adv_stop(const struct shell *sh, size_t argc, char *argv[]) int err; if (!adv) { - shell_print(sh, "Advertiser[%d] not created", selected_adv); + bt_shell_print("Advertiser[%d] not created", selected_adv); return -EINVAL; } err = bt_le_ext_adv_stop(adv); if (err) { - shell_print(sh, "Failed to stop advertising set (%d)", err); + bt_shell_print("Failed to stop advertising set (%d)", err); return -ENOEXEC; } - shell_print(sh, "Advertiser set stopped"); + bt_shell_print("Advertiser set stopped"); return 0; } @@ -2494,13 +2492,13 @@ static int cmd_adv_delete(const struct shell *sh, size_t argc, char *argv[]) int err; if (!adv) { - shell_print(sh, "Advertiser[%d] not created", selected_adv); + bt_shell_print("Advertiser[%d] not created", selected_adv); return -EINVAL; } err = bt_le_ext_adv_delete(adv); if (err) { - shell_error(ctx_shell, "Failed to delete advertiser set"); + bt_shell_error("Failed to delete advertiser set"); return err; } @@ -2523,7 +2521,7 @@ static int cmd_adv_select(const struct shell *sh, size_t argc, char *argv[]) for (int i = 0; i < ARRAY_SIZE(adv_sets); i++) { if (adv_sets[i]) { - shell_print(sh, "Advertiser[%d] %p", i, adv_sets[i]); + bt_shell_print("Advertiser[%d] %p", i, adv_sets[i]); } } @@ -2542,12 +2540,12 @@ static int cmd_adv_info(const struct shell *sh, size_t argc, char *argv[]) err = bt_le_ext_adv_get_info(adv, &info); if (err) { - shell_error(sh, "OOB data failed"); + bt_shell_error("OOB data failed"); return err; } - shell_print(sh, "Advertiser[%d] %p", selected_adv, adv); - shell_print(sh, "Id: %d, TX power: %d dBm", info.id, info.tx_power); + bt_shell_print("Advertiser[%d] %p", selected_adv, adv); + bt_shell_print("Id: %d, TX power: %d dBm", info.id, info.tx_power); print_le_addr("Address", info.addr); return 0; @@ -2565,7 +2563,7 @@ static int cmd_adv_oob(const struct shell *sh, size_t argc, char *argv[]) err = bt_le_ext_adv_oob_get_local(adv, &oob_local); if (err) { - shell_error(sh, "OOB data failed"); + bt_shell_error("OOB data failed"); return err; } @@ -2580,12 +2578,12 @@ static int cmd_adv_rpa_expire(const struct shell *sh, size_t argc, char *argv[]) { if (!strcmp(argv[1], "on")) { atomic_clear_bit(adv_set_opt[selected_adv], SHELL_ADV_OPT_KEEP_RPA); - shell_print(sh, "RPA will expire on next timeout"); + bt_shell_print("RPA will expire on next timeout"); } else if (!strcmp(argv[1], "off")) { atomic_set_bit(adv_set_opt[selected_adv], SHELL_ADV_OPT_KEEP_RPA); - shell_print(sh, "RPA will not expire on RPA timeout"); + bt_shell_print("RPA will not expire on RPA timeout"); } else { - shell_error(sh, "Invalid argument: %s", argv[1]); + bt_shell_error("Invalid argument: %s", argv[1]); return -EINVAL; } @@ -2599,26 +2597,24 @@ static int cmd_per_adv(const struct shell *sh, size_t argc, char *argv[]) struct bt_le_ext_adv *adv = adv_sets[selected_adv]; if (!adv) { - shell_error(sh, "No extended advertisement set selected"); + bt_shell_error("No extended advertisement set selected"); return -EINVAL; } if (!strcmp(argv[1], "off")) { if (bt_le_per_adv_stop(adv) < 0) { - shell_error(sh, - "Failed to stop periodic advertising"); + bt_shell_error("Failed to stop periodic advertising"); } else { - shell_print(sh, "Periodic advertising stopped"); + bt_shell_print("Periodic advertising stopped"); } } else if (!strcmp(argv[1], "on")) { if (bt_le_per_adv_start(adv) < 0) { - shell_error(sh, - "Failed to start periodic advertising"); + bt_shell_error("Failed to start periodic advertising"); } else { - shell_print(sh, "Periodic advertising started"); + bt_shell_print("Periodic advertising started"); } } else { - shell_error(sh, "Invalid argument: %s", argv[1]); + bt_shell_error("Invalid argument: %s", argv[1]); return -EINVAL; } @@ -2633,7 +2629,7 @@ static int cmd_per_adv_param(const struct shell *sh, size_t argc, int err; if (!adv) { - shell_error(sh, "No extended advertisement set selected"); + bt_shell_error("No extended advertisement set selected"); return -EINVAL; } @@ -2651,8 +2647,7 @@ static int cmd_per_adv_param(const struct shell *sh, size_t argc, } if (param.interval_min > param.interval_max) { - shell_error(sh, - "Min interval shall be less than max interval"); + bt_shell_error("Min interval shall be less than max interval"); return -EINVAL; } @@ -2664,8 +2659,8 @@ static int cmd_per_adv_param(const struct shell *sh, size_t argc, err = bt_le_per_adv_set_param(adv, ¶m); if (err) { - shell_error(sh, "Failed to set periodic advertising " - "parameters (%d)", err); + bt_shell_error("Failed to set periodic advertising " + "parameters (%d)", err); return -ENOEXEC; } @@ -2703,7 +2698,7 @@ static int cmd_per_adv_data(const struct shell *sh, size_t argc, int err; if (!adv) { - shell_error(sh, "No extended advertisement set selected"); + bt_shell_error("No extended advertisement set selected"); return -EINVAL; } @@ -2715,7 +2710,7 @@ static int cmd_per_adv_data(const struct shell *sh, size_t argc, sizeof(hex_data)); if (hex_len == 0U) { - shell_error(sh, "Could not parse adv data"); + bt_shell_error("Could not parse adv data"); return -ENOEXEC; } @@ -2728,7 +2723,7 @@ static int cmd_per_adv_data(const struct shell *sh, size_t argc, stack_ad_len = pa_ad_init(&ad[ad_len], ARRAY_SIZE(ad) - ad_len); if (stack_ad_len < 0) { - shell_error(sh, "Failed to get stack PA data"); + bt_shell_error("Failed to get stack PA data"); return -ENOEXEC; } @@ -2736,9 +2731,8 @@ static int cmd_per_adv_data(const struct shell *sh, size_t argc, err = bt_le_per_adv_set_data(adv, ad, ad_len); if (err) { - shell_error(sh, - "Failed to set periodic advertising data (%d)", - err); + bt_shell_error("Failed to set periodic advertising data (%d)", + err); return -ENOEXEC; } @@ -2759,13 +2753,13 @@ static int cmd_per_adv_sync_create(const struct shell *sh, size_t argc, uint32_t options = 0; if (per_adv_sync != NULL) { - shell_error(sh, "Selected per-adv-sync is not NULL"); + bt_shell_error("Selected per-adv-sync is not NULL"); return -ENOEXEC; } err = bt_addr_le_from_str(argv[1], argv[2], &create_params.addr); if (err) { - shell_error(sh, "Invalid peer address (err %d)", err); + bt_shell_error("Invalid peer address (err %d)", err); return -ENOEXEC; } @@ -2811,9 +2805,9 @@ static int cmd_per_adv_sync_create(const struct shell *sh, size_t argc, err = bt_le_per_adv_sync_create(&create_params, &per_adv_syncs[selected_per_adv_sync]); if (err) { - shell_error(sh, "Per adv sync failed (%d)", err); + bt_shell_error("Per adv sync failed (%d)", err); } else { - shell_print(sh, "Per adv sync pending"); + bt_shell_print("Per adv sync pending"); } return 0; @@ -2826,16 +2820,16 @@ static int cmd_per_adv_sync_delete(const struct shell *sh, size_t argc, int err; if (!per_adv_sync) { - shell_error(sh, "Selected per-adv-sync is NULL"); + bt_shell_error("Selected per-adv-sync is NULL"); return -EINVAL; } err = bt_le_per_adv_sync_delete(per_adv_sync); if (err) { - shell_error(sh, "Per adv sync delete failed (%d)", err); + bt_shell_error("Per adv sync delete failed (%d)", err); } else { - shell_print(sh, "Per adv sync deleted"); + bt_shell_print("Per adv sync deleted"); per_adv_syncs[selected_per_adv_sync] = NULL; } @@ -2850,12 +2844,12 @@ static int cmd_per_adv_sync_select(const struct shell *sh, size_t argc, char *ar id = shell_strtoul(argv[1], 0, &err); if (err != 0) { - shell_error(sh, "Could not parse id: %d", err); + bt_shell_error("Could not parse id: %d", err); return -ENOEXEC; } if (id > ARRAY_SIZE(adv_sets)) { - shell_error(sh, "Invalid id: %lu", id); + bt_shell_error("Invalid id: %lu", id); return -EINVAL; } @@ -2865,7 +2859,7 @@ static int cmd_per_adv_sync_select(const struct shell *sh, size_t argc, char *ar for (size_t i = 0U; i < ARRAY_SIZE(adv_sets); i++) { if (adv_sets[i]) { - shell_print(sh, "PER_ADV_SYNC[%zu] %p", i, adv_sets[i]); + bt_shell_print("PER_ADV_SYNC[%zu] %p", i, adv_sets[i]); } } @@ -2882,7 +2876,7 @@ static int cmd_past_subscribe(const struct shell *sh, size_t argc, bool global = true; if (i == ARRAY_SIZE(per_adv_syncs)) { - shell_error(sh, "Cannot create more per adv syncs"); + bt_shell_error("Cannot create more per adv syncs"); return -ENOEXEC; } @@ -2920,7 +2914,7 @@ static int cmd_past_subscribe(const struct shell *sh, size_t argc, param.skip = strtoul(argv[j], NULL, 16); } else if (!strcmp(argv[j], "conn")) { if (!default_conn) { - shell_print(sh, "Not connected"); + bt_shell_print("Not connected"); return -EINVAL; } global = false; @@ -2936,9 +2930,9 @@ static int cmd_past_subscribe(const struct shell *sh, size_t argc, global ? NULL : default_conn, ¶m); if (err) { - shell_error(sh, "PAST subscribe failed (%d)", err); + bt_shell_error("PAST subscribe failed (%d)", err); } else { - shell_print(sh, "Subscribed to PAST"); + bt_shell_print("Subscribed to PAST"); } return 0; @@ -2956,7 +2950,7 @@ static int cmd_past_unsubscribe(const struct shell *sh, size_t argc, bt_le_per_adv_sync_transfer_unsubscribe( default_conn); } else { - shell_print(sh, "Not connected"); + bt_shell_print("Not connected"); return -EINVAL; } } else { @@ -2968,7 +2962,7 @@ static int cmd_past_unsubscribe(const struct shell *sh, size_t argc, } if (err) { - shell_error(sh, "PAST unsubscribe failed (%d)", err); + bt_shell_error("PAST unsubscribe failed (%d)", err); } return err; @@ -2990,8 +2984,8 @@ static int cmd_per_adv_sync_transfer(const struct shell *sh, size_t argc, } if (index >= ARRAY_SIZE(per_adv_syncs)) { - shell_error(sh, "Maximum index is %zu but %d was requested", - ARRAY_SIZE(per_adv_syncs) - 1, index); + bt_shell_error("Maximum index is %zu but %d was requested", + ARRAY_SIZE(per_adv_syncs) - 1, index); } per_adv_sync = per_adv_syncs[index]; @@ -3001,7 +2995,7 @@ static int cmd_per_adv_sync_transfer(const struct shell *sh, size_t argc, err = bt_le_per_adv_sync_transfer(per_adv_sync, default_conn, 0); if (err) { - shell_error(sh, "Periodic advertising sync transfer failed (%d)", err); + bt_shell_error("Periodic advertising sync transfer failed (%d)", err); } return err; @@ -3017,14 +3011,14 @@ static int cmd_per_adv_set_info_transfer(const struct shell *sh, size_t argc, int err; if (default_conn == NULL) { - shell_error(sh, "%s: at least, one connection is required", - sh->ctx->active_cmd.syntax); + bt_shell_error("%s: at least, one connection is required", + sh->ctx->active_cmd.syntax); return -ENOEXEC; } err = bt_le_per_adv_set_info_transfer(adv, default_conn, 0U); if (err) { - shell_error(sh, "Periodic advertising sync transfer failed (%d)", err); + bt_shell_error("Periodic advertising sync transfer failed (%d)", err); } return err; @@ -3041,10 +3035,10 @@ static int cmd_read_remote_tx_power(const struct shell *sh, size_t argc, char *a err = bt_conn_le_get_remote_tx_power_level(default_conn, phy); if (!err) { - shell_print(sh, "Read Remote TX Power for PHY %s", - tx_pwr_ctrl_phy2str(phy)); + bt_shell_print("Read Remote TX Power for PHY %s", + tx_pwr_ctrl_phy2str(phy)); } else { - shell_print(sh, "error %d", err); + bt_shell_print("error %d", err); } } else { shell_help(sh); @@ -3068,22 +3062,23 @@ static int cmd_read_local_tx_power(const struct shell *sh, size_t argc, char *ar tx_power_level.max_level = 6; if (default_conn == NULL) { - shell_error(sh, "Conn handle error, at least one connection is required."); + bt_shell_error("Conn handle error, at least one connection is required."); return -ENOEXEC; } err = bt_conn_le_get_tx_power_level(default_conn, &tx_power_level); if (err) { - shell_print(sh, "Command returned error %d", err); + bt_shell_print("Command returned error %d", err); return err; } if (tx_power_level.current_level == unachievable_current_level) { - shell_print(sh, "We received no current tx power level."); + bt_shell_print("We received no current tx power level."); return -EIO; } - shell_print(sh, "Read local TX Power: current level: %d, PHY: %s, Max Level: %d", - tx_power_level.current_level, - tx_pwr_ctrl_phy2str((enum bt_conn_le_tx_power_phy)tx_power_level.phy), - tx_power_level.max_level); + bt_shell_print( + "Read local TX Power: current level: %d, PHY: %s, Max Level: %d", + tx_power_level.current_level, + tx_pwr_ctrl_phy2str((enum bt_conn_le_tx_power_phy)tx_power_level.phy), + tx_power_level.max_level); } else { shell_help(sh); return SHELL_CMD_HELP_PRINTED; @@ -3106,16 +3101,16 @@ static int cmd_set_power_report_enable(const struct shell *sh, size_t argc, char remote_enable = 1; } if (default_conn == NULL) { - shell_error(sh, "Conn handle error, at least one connection is required."); + bt_shell_error("Conn handle error, at least one connection is required."); return -ENOEXEC; } err = bt_conn_le_set_tx_power_report_enable(default_conn, local_enable, - remote_enable); + remote_enable); if (!err) { - shell_print(sh, "Tx Power Report: local: %s, remote: %s", - enabled2str(local_enable), enabled2str(remote_enable)); + bt_shell_print("Tx Power Report: local: %s, remote: %s", + enabled2str(local_enable), enabled2str(remote_enable)); } else { - shell_print(sh, "error %d", err); + bt_shell_print("error %d", err); } } else { shell_help(sh); @@ -3132,7 +3127,7 @@ static int cmd_set_path_loss_reporting_parameters(const struct shell *sh, size_t int err = 0; if (default_conn == NULL) { - shell_error(sh, "Conn handle error, at least one connection is required."); + bt_shell_error("Conn handle error, at least one connection is required."); return -ENOEXEC; } @@ -3141,7 +3136,7 @@ static int cmd_set_path_loss_reporting_parameters(const struct shell *sh, size_t if (err) { shell_help(sh); - shell_error(sh, "Could not parse input number %d", argn); + bt_shell_error("Could not parse input number %d", argn); return SHELL_CMD_HELP_PRINTED; } } @@ -3156,7 +3151,7 @@ static int cmd_set_path_loss_reporting_parameters(const struct shell *sh, size_t err = bt_conn_le_set_path_loss_mon_param(default_conn, ¶ms); if (err) { - shell_error(sh, "bt_conn_le_set_path_loss_mon_param returned error %d", err); + bt_shell_error("bt_conn_le_set_path_loss_mon_param returned error %d", err); return -ENOEXEC; } @@ -3169,7 +3164,7 @@ static int cmd_set_path_loss_reporting_enable(const struct shell *sh, size_t arg int err = 0; if (default_conn == NULL) { - shell_error(sh, "Conn handle error, at least one connection is required."); + bt_shell_error("Conn handle error, at least one connection is required."); return -ENOEXEC; } @@ -3182,7 +3177,7 @@ static int cmd_set_path_loss_reporting_enable(const struct shell *sh, size_t arg err = bt_conn_le_set_path_loss_mon_enable(default_conn, enable); if (err) { - shell_error(sh, "bt_conn_le_set_path_loss_mon_enable returned error %d", err); + bt_shell_error("bt_conn_le_set_path_loss_mon_enable returned error %d", err); return -ENOEXEC; } @@ -3273,7 +3268,7 @@ static int cmd_connect_le(const struct shell *sh, size_t argc, char *argv[]) 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."); + bt_shell_error("No connectable adv stored, please trigger a scan first."); shell_help(sh); return SHELL_CMD_HELP_PRINTED; @@ -3281,7 +3276,7 @@ static int cmd_connect_le(const struct shell *sh, size_t argc, char *argv[]) } else { err = bt_addr_le_from_str(argv[1], argv[2], &addr); if (err) { - shell_error(sh, "Invalid peer address (err %d)", err); + bt_shell_error("Invalid peer address (err %d)", err); return err; } } @@ -3309,11 +3304,11 @@ 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); + bt_shell_error("Connection failed (%d)", err); return -ENOEXEC; } else { - shell_print(sh, "Connection pending"); + bt_shell_print("Connection pending"); /* unref connection obj in advance as app user */ bt_conn_unref(conn); @@ -3330,7 +3325,7 @@ static int cmd_auto_conn(const struct shell *sh, size_t argc, char *argv[]) err = bt_addr_le_from_str(argv[1], argv[2], &addr); if (err) { - shell_error(sh, "Invalid peer address (err %d)", err); + bt_shell_error("Invalid peer address (err %d)", err); return err; } @@ -3365,19 +3360,18 @@ static int cmd_connect_le_name(const struct shell *sh, size_t argc, char *argv[] */ err = cmd_scan_filter_set_name(sh, argc, argv); if (err) { - shell_error(sh, - "Bluetooth set scan filter name to %s failed (err %d)", - argv[1], err); + bt_shell_error("Bluetooth set scan filter name to %s failed (err %d)", + argv[1], err); return err; } err = bt_le_scan_start(¶m, NULL); if (err) { - shell_error(sh, "Bluetooth scan failed (err %d)", err); + bt_shell_error("Bluetooth scan failed (err %d)", err); return err; } - shell_print(sh, "Bluetooth active scan enabled"); + bt_shell_print("Bluetooth active scan enabled"); /* Set boolean to tell the scan callback to connect to this name */ auto_connect.connect_name = true; @@ -3406,8 +3400,8 @@ static int cmd_disconnect(const struct shell *sh, size_t argc, char *argv[]) err = bt_addr_le_from_str(argv[1], argv[2], &addr); if (err) { - shell_error(sh, "Invalid peer address (err %d)", - err); + bt_shell_error("Invalid peer address (err %d)", + err); return err; } @@ -3415,13 +3409,13 @@ static int cmd_disconnect(const struct shell *sh, size_t argc, char *argv[]) } if (!conn) { - shell_error(sh, "Not connected"); + bt_shell_error("Not connected"); return -ENOEXEC; } err = bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); if (err) { - shell_error(sh, "Disconnection failed (err %d)", err); + bt_shell_error("Disconnection failed (err %d)", err); return err; } @@ -3439,13 +3433,13 @@ static int cmd_select(const struct shell *sh, size_t argc, char *argv[]) err = bt_addr_le_from_str(argv[1], argv[2], &addr); if (err) { - shell_error(sh, "Invalid peer address (err %d)", err); + bt_shell_error("Invalid peer address (err %d)", err); return err; } conn = bt_conn_lookup_addr_le(selected_id, &addr); if (!conn) { - shell_error(sh, "No matching connection found"); + bt_shell_error("No matching connection found"); return -ENOEXEC; } @@ -3456,7 +3450,7 @@ static int cmd_select(const struct shell *sh, size_t argc, char *argv[]) default_conn = conn; bt_addr_le_to_str(&addr, addr_str, sizeof(addr_str)); - shell_print(sh, "Selected conn is now: %s", addr_str); + bt_shell_print("Selected conn is now: %s", addr_str); return 0; } @@ -3497,8 +3491,8 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[]) addr.type = BT_ADDR_LE_PUBLIC; err = bt_addr_from_str(argv[1], &addr.a); if (err) { - shell_error(sh, "Invalid peer address (err %d)", - err); + bt_shell_error("Invalid peer address (err %d)", + err); return err; } conn = bt_conn_lookup_addr_le(selected_id, &addr); @@ -3507,8 +3501,8 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[]) err = bt_addr_le_from_str(argv[1], argv[2], &addr); if (err) { - shell_error(sh, "Invalid peer address (err %d)", - err); + bt_shell_error("Invalid peer address (err %d)", + err); return err; } conn = bt_conn_lookup_addr_le(selected_id, &addr); @@ -3516,20 +3510,20 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[]) } if (!conn) { - shell_error(sh, "Not connected"); + bt_shell_error("Not connected"); return -ENOEXEC; } err = bt_conn_get_info(conn, &info); if (err) { - shell_print(ctx_shell, "Failed to get info"); + bt_shell_print("Failed to get info"); goto done; } - shell_print(ctx_shell, "Type: %s, Role: %s, Id: %u", - get_conn_type_str(info.type), - get_conn_role_str(info.role), - info.id); + bt_shell_print("Type: %s, Role: %s, Id: %u", + get_conn_type_str(info.type), + get_conn_role_str(info.role), + info.id); if (info.type == BT_CONN_TYPE_LE) { print_le_addr("Remote", info.le.dst); @@ -3537,25 +3531,25 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[]) print_le_addr("Remote on-air", info.le.remote); print_le_addr("Local on-air", info.le.local); - shell_print(ctx_shell, "Interval: 0x%04x (%u us)", - info.le.interval, - BT_CONN_INTERVAL_TO_US(info.le.interval)); - shell_print(ctx_shell, "Latency: 0x%04x", - info.le.latency); - shell_print(ctx_shell, "Supervision timeout: 0x%04x (%d ms)", - info.le.timeout, info.le.timeout * 10); + bt_shell_print("Interval: 0x%04x (%u us)", + info.le.interval, + BT_CONN_INTERVAL_TO_US(info.le.interval)); + bt_shell_print("Latency: 0x%04x", + info.le.latency); + bt_shell_print("Supervision timeout: 0x%04x (%d ms)", + info.le.timeout, info.le.timeout * 10); #if defined(CONFIG_BT_USER_PHY_UPDATE) - shell_print(ctx_shell, "LE PHY: TX PHY %s, RX PHY %s", - phy2str(info.le.phy->tx_phy), - phy2str(info.le.phy->rx_phy)); + bt_shell_print("LE PHY: TX PHY %s, RX PHY %s", + phy2str(info.le.phy->tx_phy), + phy2str(info.le.phy->rx_phy)); #endif #if defined(CONFIG_BT_USER_DATA_LEN_UPDATE) - shell_print(ctx_shell, "LE data len: TX (len: %d time: %d)" - " RX (len: %d time: %d)", - info.le.data_len->tx_max_len, - info.le.data_len->tx_max_time, - info.le.data_len->rx_max_len, - info.le.data_len->rx_max_time); + bt_shell_print("LE data len: TX (len: %d time: %d)" + " RX (len: %d time: %d)", + info.le.data_len->tx_max_len, + info.le.data_len->tx_max_time, + info.le.data_len->rx_max_len, + info.le.data_len->rx_max_time); #endif #if defined(CONFIG_BT_SUBRATING) shell_print(ctx_shell, "LE Subrating: Subrate Factor: %d" @@ -3570,7 +3564,7 @@ static int cmd_info(const struct shell *sh, size_t argc, char *argv[]) char addr_str[BT_ADDR_STR_LEN]; bt_addr_to_str(info.br.dst, addr_str, sizeof(addr_str)); - shell_print(ctx_shell, "Peer address %s", addr_str); + bt_shell_print("Peer address %s", addr_str); } #endif /* defined(CONFIG_BT_CLASSIC) */ @@ -3586,9 +3580,8 @@ static int cmd_conn_update(const struct shell *sh, size_t argc, char *argv[]) int err; if (default_conn == NULL) { - shell_error(sh, - "%s: at least, one connection is required", - sh->ctx->active_cmd.syntax); + bt_shell_error("%s: at least, one connection is required", + sh->ctx->active_cmd.syntax); return -ENOEXEC; } @@ -3599,9 +3592,9 @@ static int cmd_conn_update(const struct shell *sh, size_t argc, char *argv[]) err = bt_conn_le_param_update(default_conn, ¶m); if (err) { - shell_error(sh, "conn update failed (err %d).", err); + bt_shell_error("conn update failed (err %d).", err); } else { - shell_print(sh, "conn update initiated."); + bt_shell_print("conn update initiated."); } return err; @@ -3635,9 +3628,8 @@ static int cmd_conn_data_len_update(const struct shell *sh, size_t argc, int err; if (default_conn == NULL) { - shell_error(sh, - "%s: at least, one connection is required", - sh->ctx->active_cmd.syntax); + bt_shell_error("%s: at least, one connection is required", + sh->ctx->active_cmd.syntax); return -ENOEXEC; } @@ -3658,16 +3650,14 @@ static int cmd_conn_data_len_update(const struct shell *sh, size_t argc, } #endif param.tx_max_time = tx_time_calc(phy, param.tx_max_len); - shell_print(sh, "Calculated tx time: %d", param.tx_max_time); + bt_shell_print("Calculated tx time: %d", param.tx_max_time); } - - err = bt_conn_le_data_len_update(default_conn, ¶m); if (err) { - shell_error(sh, "data len update failed (err %d).", err); + bt_shell_error("data len update failed (err %d).", err); } else { - shell_print(sh, "data len update initiated."); + bt_shell_print("data len update initiated."); } return err; @@ -3682,9 +3672,8 @@ static int cmd_conn_phy_update(const struct shell *sh, size_t argc, int err; if (default_conn == NULL) { - shell_error(sh, - "%s: at least, one connection is required", - sh->ctx->active_cmd.syntax); + bt_shell_error("%s: at least, one connection is required", + sh->ctx->active_cmd.syntax); return -ENOEXEC; } @@ -3706,9 +3695,9 @@ static int cmd_conn_phy_update(const struct shell *sh, size_t argc, err = bt_conn_le_phy_update(default_conn, ¶m); if (err) { - shell_error(sh, "PHY update failed (err %d).", err); + bt_shell_error("PHY update failed (err %d).", err); } else { - shell_print(sh, "PHY update initiated."); + bt_shell_print("PHY update initiated."); } return err; @@ -3722,16 +3711,16 @@ static int cmd_chan_map(const struct shell *sh, size_t argc, char *argv[]) int err; if (hex2bin(argv[1], strlen(argv[1]), chan_map, 5) == 0) { - shell_error(sh, "Invalid channel map"); + bt_shell_error("Invalid channel map"); return -ENOEXEC; } sys_mem_swap(chan_map, 5); err = bt_le_set_chan_map(chan_map); if (err) { - shell_error(sh, "Failed to set channel map (err %d)", err); + bt_shell_error("Failed to set channel map (err %d)", err); } else { - shell_print(sh, "Channel map set"); + bt_shell_print("Channel map set"); } return err; @@ -3744,7 +3733,7 @@ static int cmd_oob(const struct shell *sh, size_t argc, char *argv[]) err = bt_le_oob_get_local(selected_id, &oob_local); if (err) { - shell_error(sh, "OOB data failed"); + bt_shell_error("OOB data failed"); return err; } @@ -3762,7 +3751,7 @@ static int cmd_oob_remote(const struct shell *sh, size_t argc, err = bt_addr_le_from_str(argv[1], argv[2], &addr); if (err) { - shell_error(sh, "Invalid peer address (err %d)", err); + bt_shell_error("Invalid peer address (err %d)", err); return err; } @@ -3799,11 +3788,11 @@ static int cmd_clear(const struct shell *sh, size_t argc, char *argv[]) if (strcmp(argv[1], "all") == 0) { err = bt_unpair(selected_id, NULL); if (err) { - shell_error(sh, "Failed to clear pairings (err %d)", - err); + bt_shell_error("Failed to clear pairings (err %d)", + err); return err; } else { - shell_print(sh, "Pairings successfully cleared"); + bt_shell_print("Pairings successfully cleared"); } return 0; @@ -3814,7 +3803,7 @@ static int cmd_clear(const struct shell *sh, size_t argc, char *argv[]) addr.type = BT_ADDR_LE_PUBLIC; err = bt_addr_from_str(argv[1], &addr.a); #else - shell_print(sh, "Both address and address type needed"); + bt_shell_print("Both address and address type needed"); return -ENOEXEC; #endif } else { @@ -3822,15 +3811,15 @@ static int cmd_clear(const struct shell *sh, size_t argc, char *argv[]) } if (err) { - shell_print(sh, "Invalid address"); + bt_shell_print("Invalid address"); return err; } err = bt_unpair(selected_id, &addr); if (err) { - shell_error(sh, "Failed to clear pairing (err %d)", err); + bt_shell_error("Failed to clear pairing (err %d)", err); } else { - shell_print(sh, "Pairing successfully cleared"); + bt_shell_print("Pairing successfully cleared"); } return err; @@ -3844,12 +3833,12 @@ static int cmd_security(const struct shell *sh, size_t argc, char *argv[]) struct bt_conn_info info; if (!default_conn || (bt_conn_get_info(default_conn, &info) < 0)) { - shell_error(sh, "Not connected"); + bt_shell_error("Not connected"); return -ENOEXEC; } if (argc < 2) { - shell_print(sh, "BT_SECURITY_L%d", bt_conn_get_security(default_conn)); + bt_shell_print("BT_SECURITY_L%d", bt_conn_get_security(default_conn)); return 0; } @@ -3858,13 +3847,13 @@ static int cmd_security(const struct shell *sh, size_t argc, char *argv[]) if ((info.type == BT_CONN_TYPE_BR && (sec < BT_SECURITY_L0 || sec > BT_SECURITY_L3))) { - shell_error(sh, "Invalid BR/EDR security level (%d)", sec); + bt_shell_error("Invalid BR/EDR security level (%d)", sec); return -ENOEXEC; } if ((info.type == BT_CONN_TYPE_LE && (sec < BT_SECURITY_L1 || sec > BT_SECURITY_L4))) { - shell_error(sh, "Invalid LE security level (%d)", sec); + bt_shell_error("Invalid LE security level (%d)", sec); return -ENOEXEC; } @@ -3879,7 +3868,7 @@ static int cmd_security(const struct shell *sh, size_t argc, char *argv[]) err = bt_conn_set_security(default_conn, sec); if (err) { - shell_error(sh, "Setting security failed (err %d)", err); + bt_shell_error("Setting security failed (err %d)", err); } return err; @@ -3937,7 +3926,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)++; } @@ -3945,9 +3934,9 @@ static int cmd_bonds(const struct shell *sh, size_t argc, char *argv[]) { int bond_count = 0; - shell_print(sh, "Bonded devices:"); + bt_shell_print("Bonded devices:"); bt_foreach_bond(selected_id, bond_info, &bond_count); - shell_print(sh, "Total %d", bond_count); + bt_shell_print("Total %d", bond_count); return 0; } @@ -3971,7 +3960,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; } @@ -3979,19 +3968,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", - conn == default_conn ? "*" : " ", info.id, role_str(info.role), addr, - info.le.interval, info.le.latency, info.le.timeout); + 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: @@ -4005,9 +3994,9 @@ static int cmd_connections(const struct shell *sh, size_t argc, char *argv[]) { int conn_count = 0; - shell_print(sh, "Connected devices:"); + bt_shell_print("Connected devices:"); bt_conn_foreach(BT_CONN_TYPE_ALL, connection_info, &conn_count); - shell_print(sh, "Total %d", conn_count); + bt_shell_print("Total %d", conn_count); return 0; } @@ -4021,7 +4010,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) @@ -4032,8 +4021,8 @@ 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", - addr, type); + bt_shell_print("Passkey keypress notification from %s: type %d", + addr, type); } #endif @@ -4046,7 +4035,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) @@ -4055,7 +4044,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) @@ -4064,7 +4053,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) { @@ -4079,7 +4068,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) @@ -4125,9 +4114,8 @@ 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; } @@ -4135,9 +4123,8 @@ 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; } @@ -4145,14 +4132,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, ", - oob_config_str(oob_info->lesc.oob_config), addr); + 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) @@ -4161,8 +4148,8 @@ 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) @@ -4171,8 +4158,8 @@ 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) @@ -4192,10 +4179,10 @@ 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); } /* @@ -4212,12 +4199,12 @@ 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: " - "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, - feat->auth_req, feat->max_enc_key_size, - feat->init_key_dist, feat->resp_key_dist); + 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, + feat->auth_req, feat->max_enc_key_size, + feat->init_key_dist, feat->resp_key_dist); return BT_SECURITY_ERR_SUCCESS; } @@ -4228,7 +4215,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 = { @@ -4359,7 +4346,7 @@ static int cmd_auth(const struct shell *sh, size_t argc, char *argv[]) } if (err) { - shell_error(sh, "Failed to set auth handlers (%d)", err); + bt_shell_error("Failed to set auth handlers (%d)", err); } return err; @@ -4379,7 +4366,7 @@ static int cmd_auth_cancel(const struct shell *sh, } if (!conn) { - shell_print(sh, "Not connected"); + bt_shell_print("Not connected"); return -ENOEXEC; } @@ -4392,7 +4379,7 @@ static int cmd_auth_passkey_confirm(const struct shell *sh, size_t argc, char *argv[]) { if (!default_conn) { - shell_print(sh, "Not connected"); + bt_shell_print("Not connected"); return -ENOEXEC; } @@ -4404,7 +4391,7 @@ static int cmd_auth_pairing_confirm(const struct shell *sh, size_t argc, char *argv[]) { if (!default_conn) { - shell_print(sh, "Not connected"); + bt_shell_print("Not connected"); return -ENOEXEC; } @@ -4420,13 +4407,13 @@ static int cmd_fal_add(const struct shell *sh, size_t argc, char *argv[]) err = bt_addr_le_from_str(argv[1], argv[2], &addr); if (err) { - shell_error(sh, "Invalid peer address (err %d)", err); + bt_shell_error("Invalid peer address (err %d)", err); return err; } err = bt_le_filter_accept_list_add(&addr); if (err) { - shell_error(sh, "Add to fa list failed (err %d)", err); + bt_shell_error("Add to fa list failed (err %d)", err); return err; } @@ -4440,14 +4427,14 @@ static int cmd_fal_rem(const struct shell *sh, size_t argc, char *argv[]) err = bt_addr_le_from_str(argv[1], argv[2], &addr); if (err) { - shell_error(sh, "Invalid peer address (err %d)", err); + bt_shell_error("Invalid peer address (err %d)", err); return err; } err = bt_le_filter_accept_list_remove(&addr); if (err) { - shell_error(sh, "Remove from fa list failed (err %d)", - err); + bt_shell_error("Remove from fa list failed (err %d)", + err); return err; } return 0; @@ -4459,7 +4446,7 @@ static int cmd_fal_clear(const struct shell *sh, size_t argc, char *argv[]) err = bt_le_filter_accept_list_clear(); if (err) { - shell_error(sh, "Clearing fa list failed (err %d)", err); + bt_shell_error("Clearing fa list failed (err %d)", err); return err; } @@ -4496,14 +4483,14 @@ static int cmd_fal_connect(const struct shell *sh, size_t argc, char *argv[]) err = bt_conn_le_create_auto(create_params, BT_LE_CONN_PARAM_DEFAULT); if (err) { - shell_error(sh, "Auto connect failed (err %d)", err); + bt_shell_error("Auto connect failed (err %d)", err); return err; } } else if (!strcmp(action, "off")) { err = bt_conn_create_auto_stop(); if (err) { - shell_error(sh, "Auto connect stop failed (err %d)", - err); + bt_shell_error("Auto connect stop failed (err %d)", + err); } return err; } @@ -4522,20 +4509,20 @@ static int cmd_fixed_passkey(const struct shell *sh, if (argc < 2) { bt_passkey_set(BT_PASSKEY_INVALID); - shell_print(sh, "Fixed passkey cleared"); + bt_shell_print("Fixed passkey cleared"); return 0; } passkey = atoi(argv[1]); if (passkey > 999999) { - shell_print(sh, "Passkey should be between 0-999999"); + bt_shell_print("Passkey should be between 0-999999"); return -ENOEXEC; } err = bt_passkey_set(passkey); if (err) { - shell_print(sh, "Setting fixed passkey failed (err %d)", - err); + bt_shell_print("Setting fixed passkey failed (err %d)", + err); } return err; @@ -4549,19 +4536,19 @@ static int cmd_auth_passkey(const struct shell *sh, int err; if (!default_conn) { - shell_print(sh, "Not connected"); + bt_shell_print("Not connected"); return -ENOEXEC; } passkey = atoi(argv[1]); if (passkey > 999999) { - shell_print(sh, "Passkey should be between 0-999999"); + bt_shell_print("Passkey should be between 0-999999"); return -EINVAL; } err = bt_conn_auth_passkey_entry(default_conn, passkey); if (err) { - shell_error(sh, "Failed to set passkey (%d)", err); + bt_shell_error("Failed to set passkey (%d)", err); return err; } @@ -4576,7 +4563,7 @@ static int cmd_auth_passkey_notify(const struct shell *sh, int err; if (!default_conn) { - shell_print(sh, "Not connected"); + bt_shell_print("Not connected"); return -ENOEXEC; } @@ -4587,13 +4574,13 @@ static int cmd_auth_passkey_notify(const struct shell *sh, type != BT_CONN_AUTH_KEYPRESS_DIGIT_ENTERED && type != BT_CONN_AUTH_KEYPRESS_DIGIT_ERASED && type != BT_CONN_AUTH_KEYPRESS_CLEARED && type != BT_CONN_AUTH_KEYPRESS_ENTRY_COMPLETED)) { - shell_error(sh, " must be a value of enum bt_conn_auth_keypress"); + bt_shell_error(" must be a value of enum bt_conn_auth_keypress"); return -EINVAL; } err = bt_conn_auth_keypress_notify(default_conn, type); if (err) { - shell_error(sh, "bt_conn_auth_keypress_notify errno %d", err); + bt_shell_error("bt_conn_auth_keypress_notify errno %d", err); return err; } @@ -4610,13 +4597,13 @@ static int cmd_auth_oob_tk(const struct shell *sh, size_t argc, char *argv[]) len = hex2bin(argv[1], strlen(argv[1]), tk, sizeof(tk)); if (len != sizeof(tk)) { - shell_error(sh, "TK should be 16 bytes"); + bt_shell_error("TK should be 16 bytes"); return -EINVAL; } err = bt_le_oob_set_legacy_tk(default_conn, tk); if (err) { - shell_error(sh, "Failed to set TK (%d)", err); + bt_shell_error("Failed to set TK (%d)", err); return err; } @@ -4635,19 +4622,19 @@ static int cmd_encrypted_ad_set_keys(const struct shell *sh, size_t argc, char * len = hex2bin(session_key, strlen(session_key), bt_shell_ead_session_key, BT_EAD_KEY_SIZE); if (len != BT_EAD_KEY_SIZE) { - shell_error(sh, "Failed to set session key"); + bt_shell_error("Failed to set session key"); return -ENOEXEC; } len = hex2bin(iv, strlen(iv), bt_shell_ead_iv, BT_EAD_IV_SIZE); if (len != BT_EAD_IV_SIZE) { - shell_error(sh, "Failed to set initialisation vector"); + bt_shell_error("Failed to set initialisation vector"); return -ENOEXEC; } - shell_info(sh, "session key set to:"); + bt_shell_info("session key set to:"); shell_hexdump(sh, bt_shell_ead_session_key, BT_EAD_KEY_SIZE); - shell_info(sh, "initialisation vector set to:"); + bt_shell_info("initialisation vector set to:"); shell_hexdump(sh, bt_shell_ead_iv, BT_EAD_IV_SIZE); return 0; @@ -4662,8 +4649,8 @@ int encrypted_ad_store_ad(const struct shell *sh, uint8_t type, const uint8_t *d uint8_t new_data_size = data_len + 2; if (bt_shell_ead_data_size + new_data_size > BT_SHELL_EAD_DATA_MAX_SIZE) { - shell_error(sh, "Failed to add data (trying to add %d but %d already used on %d)", - new_data_size, bt_shell_ead_data_size, BT_SHELL_EAD_DATA_MAX_SIZE); + bt_shell_error("Failed to add data (trying to add %d but %d already used on %d)", + new_data_size, bt_shell_ead_data_size, BT_SHELL_EAD_DATA_MAX_SIZE); return -ENOEXEC; } @@ -4716,22 +4703,21 @@ static int cmd_encrypted_ad_add_ead(const struct shell *sh, size_t argc, char *a uint8_t ead_size = BT_EAD_ENCRYPTED_PAYLOAD_SIZE(payload_size); if (ead_size > BT_SHELL_EAD_DATA_MAX_SIZE) { - shell_error(sh, - "Failed to add data. Maximum AD size is %d, passed data size after " - "encryption is %d", - BT_SHELL_EAD_DATA_MAX_SIZE, ead_size); + bt_shell_error("Failed to add data. Maximum AD size is %d, passed data size after " + "encryption is %d", + BT_SHELL_EAD_DATA_MAX_SIZE, ead_size); return -ENOEXEC; } len = hex2bin(hex_payload, hex_payload_size, payload, BT_SHELL_EAD_DATA_MAX_SIZE); if (len != payload_size) { - shell_error(sh, "Failed to add data"); + bt_shell_error("Failed to add data"); return -ENOEXEC; } /* check that the given advertising data structures are valid before encrypting them */ if (!is_payload_valid_ad(payload, payload_size)) { - shell_error(sh, "Failed to add data. Advertising structure are malformed."); + bt_shell_error("Failed to add data. Advertising structure are malformed."); return -ENOEXEC; } @@ -4753,7 +4739,7 @@ static int cmd_encrypted_ad_add_ad(const struct shell *sh, size_t argc, char *ar len = hex2bin(hex_payload, hex_payload_size, payload, BT_SHELL_EAD_DATA_MAX_SIZE); if (len != payload_size) { - shell_error(sh, "Failed to add data"); + bt_shell_error("Failed to add data"); return -ENOEXEC; } @@ -4768,9 +4754,9 @@ static int cmd_encrypted_ad_add_ad(const struct shell *sh, size_t argc, char *ar * fail */ if (len != ad_len + 2) { - shell_error(sh, - "Failed to add data. Data need to be formatted as specified in the " - "Core Spec. Only one non-encrypted AD payload can be added at a time."); + bt_shell_error( + "Failed to add data. Data need to be formatted as specified in the " + "Core Spec. Only one non-encrypted AD payload can be added at a time."); return -ENOEXEC; } @@ -4784,7 +4770,7 @@ static int cmd_encrypted_ad_clear_ad(const struct shell *sh, size_t argc, char * bt_shell_ead_ad_len = 0; bt_shell_ead_data_size = 0; - shell_info(sh, "Advertising data has been cleared."); + bt_shell_info("Advertising data has been cleared."); return 0; } @@ -4796,7 +4782,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; } @@ -4824,7 +4810,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; } @@ -4852,11 +4838,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; } @@ -4872,13 +4858,13 @@ static int cmd_encrypted_ad_decrypt_scan(const struct shell *sh, size_t argc, ch if (strcmp(action, "on") == 0) { bt_shell_ead_decrypt_scan = true; - shell_info(sh, "Received encrypted advertising data will now be decrypted using " - "provided key materials."); + bt_shell_info("Received encrypted advertising data will now be decrypted using " + "provided key materials."); } else if (strcmp(action, "off") == 0) { bt_shell_ead_decrypt_scan = false; - shell_info(sh, "Received encrypted advertising data will now longer be decrypted."); + bt_shell_info("Received encrypted advertising data will now longer be decrypted."); } else { - shell_error(sh, "Invalid option."); + bt_shell_error("Invalid option."); return -ENOEXEC; } @@ -4893,7 +4879,7 @@ static int cmd_default_handler(const struct shell *sh, size_t argc, char **argv) return SHELL_CMD_HELP_PRINTED; } - shell_error(sh, "%s unknown parameter: %s", argv[0], argv[1]); + bt_shell_error("%s unknown parameter: %s", argv[0], argv[1]); return -EINVAL; } diff --git a/subsys/bluetooth/host/shell/bt_shell_private.c b/subsys/bluetooth/host/shell/bt_shell_private.c new file mode 100644 index 00000000000000..52f8497637f6cb --- /dev/null +++ b/subsys/bluetooth/host/shell/bt_shell_private.c @@ -0,0 +1,53 @@ +/** + * @file bt_shell_private.c + * @brief Bluetooth shell private module + * + * Provide common function which can be shared using privately inside Bluetooth shell. + */ + +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include "bt_shell_private.h" + +extern const struct shell *ctx_shell; + +void bt_shell_info_impl(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + shell_vfprintf(ctx_shell, SHELL_INFO, fmt, args); + va_end(args); +} + +void bt_shell_print_impl(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + shell_vfprintf(ctx_shell, SHELL_NORMAL, fmt, args); + va_end(args); +} + + +void bt_shell_warn_impl(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + shell_vfprintf(ctx_shell, SHELL_WARNING, fmt, args); + va_end(args); +} + +void bt_shell_error_impl(const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + shell_vfprintf(ctx_shell, SHELL_ERROR, fmt, args); + va_end(args); +} diff --git a/subsys/bluetooth/host/shell/bt_shell_private.h b/subsys/bluetooth/host/shell/bt_shell_private.h new file mode 100644 index 00000000000000..5dedc1d8152cac --- /dev/null +++ b/subsys/bluetooth/host/shell/bt_shell_private.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#ifndef __BT_SHELL_PRIVATE_H +#define __BT_SHELL_PRIVATE_H + +/** + * @brief printf-like function which sends formatted data stream to the shell. + * (Bluetooth context specific) + * + * This function can be used from the command handler or from threads, but not + * from an interrupt context. + * + * @param[in] fmt Format string. + * @param[in] ... List of parameters to print. + */ +void __printf_like(1, 2) bt_shell_info_impl(const char *fmt, ...); +void __printf_like(1, 2) bt_shell_print_impl(const char *fmt, ...); +void __printf_like(1, 2) bt_shell_warn_impl(const char *fmt, ...); +void __printf_like(1, 2) bt_shell_error_impl(const char *fmt, ...); + +/** + * @brief Print info message to the shell. + * (Bluetooth context specific) + * + * @param[in] _ft Format string. + * @param[in] ... List of parameters to print. + */ +#define bt_shell_info(_ft, ...) \ + bt_shell_info_impl(_ft "\n", ##__VA_ARGS__) + +/** + * @brief Print normal message to the shell. + * (Bluetooth context specific) + * + * @param[in] _ft Format string. + * @param[in] ... List of parameters to print. + */ +#define bt_shell_print(_ft, ...) \ + bt_shell_print_impl(_ft "\n", ##__VA_ARGS__) + +/** + * @brief Print warning message to the shell. + * (Bluetooth context specific) + * + * @param[in] _ft Format string. + * @param[in] ... List of parameters to print. + */ +#define bt_shell_warn(_ft, ...) \ + bt_shell_warn_impl(_ft "\n", ##__VA_ARGS__) + +/** + * @brief Print error message to the shell. + * (Bluetooth context specific) + * + * @param[in] _ft Format string. + * @param[in] ... List of parameters to print. + */ +#define bt_shell_error(_ft, ...) \ + bt_shell_error_impl(_ft "\n", ##__VA_ARGS__) + +#define bt_shell_fprintf_info(_ft, ...) \ + bt_shell_info_impl(_ft, ##__VA_ARGS__) + +#define bt_shell_fprintf_print(_ft, ...) \ + bt_shell_print_impl(_ft, ##__VA_ARGS__) + +#define bt_shell_fprintf_warn(_ft, ...) \ + bt_shell_warn_impl(_ft, ##__VA_ARGS__) + +#endif /* __BT_SHELL_PRIVATE_H */