wifi: shell: replace print(...) with PR(...)
Additionally, replace the local print(sh, level, fmt, ...) macros with PR, PR_ERROR, and PR_WARNING macros. Then remove the print(sh, level, fmt, ...) macros. Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
This commit is contained in:
parent
81342132fb
commit
055ac61542
|
@ -75,15 +75,6 @@ struct wifi_ap_sta_node {
|
|||
};
|
||||
static struct wifi_ap_sta_node sta_list[CONFIG_WIFI_SHELL_MAX_AP_STA];
|
||||
|
||||
#define print(sh, level, fmt, ...) \
|
||||
do { \
|
||||
if (sh) { \
|
||||
shell_fprintf(sh, level, fmt, ##__VA_ARGS__); \
|
||||
} else { \
|
||||
printk(fmt, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
static bool parse_number(const struct shell *sh, long *param, char *str, long min, long max)
|
||||
{
|
||||
char *endptr;
|
||||
|
@ -98,12 +89,12 @@ static bool parse_number(const struct shell *sh, long *param, char *str, long mi
|
|||
}
|
||||
|
||||
if (*endptr != '\0') {
|
||||
print(sh, SHELL_ERROR, "Invalid number: %s", str_tmp);
|
||||
PR_ERROR("Invalid number: %s", str_tmp);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((num) < (min) || (num) > (max)) {
|
||||
print(sh, SHELL_WARNING, "Value out of range: %s, (%ld-%ld)", str_tmp, min, max);
|
||||
PR_WARNING("Value out of range: %s, (%ld-%ld)", str_tmp, min, max);
|
||||
return false;
|
||||
}
|
||||
*param = num;
|
||||
|
@ -115,26 +106,25 @@ static void handle_wifi_scan_result(struct net_mgmt_event_callback *cb)
|
|||
const struct wifi_scan_result *entry =
|
||||
(const struct wifi_scan_result *)cb->info;
|
||||
uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")];
|
||||
const struct shell *sh = context.sh;
|
||||
|
||||
context.scan_result++;
|
||||
|
||||
if (context.scan_result == 1U) {
|
||||
print(context.sh, SHELL_NORMAL,
|
||||
"\n%-4s | %-32s %-5s | %-13s | %-4s | %-15s | %-17s | %-8s\n",
|
||||
"Num", "SSID", "(len)", "Chan (Band)", "RSSI", "Security", "BSSID", "MFP");
|
||||
PR("\n%-4s | %-32s %-5s | %-13s | %-4s | %-15s | %-17s | %-8s\n",
|
||||
"Num", "SSID", "(len)", "Chan (Band)", "RSSI", "Security", "BSSID", "MFP");
|
||||
}
|
||||
|
||||
print(context.sh, SHELL_NORMAL,
|
||||
"%-4d | %-32s %-5u | %-4u (%-6s) | %-4d | %-15s | %-17s | %-8s\n",
|
||||
context.scan_result, entry->ssid, entry->ssid_length, entry->channel,
|
||||
wifi_band_txt(entry->band),
|
||||
entry->rssi,
|
||||
wifi_security_txt(entry->security),
|
||||
((entry->mac_length) ?
|
||||
net_sprint_ll_addr_buf(entry->mac, WIFI_MAC_ADDR_LEN,
|
||||
mac_string_buf,
|
||||
sizeof(mac_string_buf)) : ""),
|
||||
wifi_mfp_txt(entry->mfp));
|
||||
PR("%-4d | %-32s %-5u | %-4u (%-6s) | %-4d | %-15s | %-17s | %-8s\n",
|
||||
context.scan_result, entry->ssid, entry->ssid_length, entry->channel,
|
||||
wifi_band_txt(entry->band),
|
||||
entry->rssi,
|
||||
wifi_security_txt(entry->security),
|
||||
((entry->mac_length) ?
|
||||
net_sprint_ll_addr_buf(entry->mac, WIFI_MAC_ADDR_LEN,
|
||||
mac_string_buf,
|
||||
sizeof(mac_string_buf)) : ""),
|
||||
wifi_mfp_txt(entry->mfp));
|
||||
}
|
||||
|
||||
static int wifi_freq_to_channel(int frequency)
|
||||
|
@ -188,28 +178,27 @@ static void handle_wifi_raw_scan_result(struct net_mgmt_event_callback *cb)
|
|||
context.scan_result++;
|
||||
|
||||
if (context.scan_result == 1U) {
|
||||
print(sh, SHELL_NORMAL,
|
||||
"\n%-4s | %-13s | %-4s | %-15s | %-15s | %-32s\n",
|
||||
"Num", "Channel (Band)", "RSSI", "BSSID", "Frame length", "Frame Body");
|
||||
PR("\n%-4s | %-13s | %-4s | %-15s | %-15s | %-32s\n",
|
||||
"Num", "Channel (Band)", "RSSI", "BSSID", "Frame length", "Frame Body");
|
||||
}
|
||||
|
||||
rssi = raw->rssi;
|
||||
channel = wifi_freq_to_channel(raw->frequency);
|
||||
band = wifi_freq_to_band(raw->frequency);
|
||||
|
||||
print(sh, SHELL_NORMAL, "%-4d | %-4u (%-6s) | %-4d | %s | %-4d ",
|
||||
context.scan_result,
|
||||
channel,
|
||||
wifi_band_txt(band),
|
||||
rssi,
|
||||
net_sprint_ll_addr_buf(raw->data + 10, WIFI_MAC_ADDR_LEN, mac_string_buf,
|
||||
sizeof(mac_string_buf)), raw->frame_length);
|
||||
PR("%-4d | %-4u (%-6s) | %-4d | %s | %-4d ",
|
||||
context.scan_result,
|
||||
channel,
|
||||
wifi_band_txt(band),
|
||||
rssi,
|
||||
net_sprint_ll_addr_buf(raw->data + 10, WIFI_MAC_ADDR_LEN, mac_string_buf,
|
||||
sizeof(mac_string_buf)), raw->frame_length);
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
print(sh, SHELL_NORMAL, "%02X ", *(raw->data + i));
|
||||
PR("%02X ", *(raw->data + i));
|
||||
}
|
||||
|
||||
print(sh, SHELL_NORMAL, "\n");
|
||||
PR("\n");
|
||||
}
|
||||
#endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */
|
||||
|
||||
|
@ -220,10 +209,9 @@ static void handle_wifi_scan_done(struct net_mgmt_event_callback *cb)
|
|||
const struct shell *sh = context.sh;
|
||||
|
||||
if (status->status) {
|
||||
print(sh, SHELL_WARNING,
|
||||
"Scan request failed (%d)\n", status->status);
|
||||
PR_WARNING("Scan request failed (%d)\n", status->status);
|
||||
} else {
|
||||
print(sh, SHELL_NORMAL, "Scan request done\n");
|
||||
PR("Scan request done\n");
|
||||
}
|
||||
|
||||
context.scan_result = 0U;
|
||||
|
@ -233,12 +221,12 @@ static void handle_wifi_connect_result(struct net_mgmt_event_callback *cb)
|
|||
{
|
||||
const struct wifi_status *status =
|
||||
(const struct wifi_status *) cb->info;
|
||||
const struct shell *sh = context.sh;
|
||||
|
||||
if (status->status) {
|
||||
print(context.sh, SHELL_WARNING,
|
||||
"Connection request failed (%d)\n", status->status);
|
||||
PR_WARNING("Connection request failed (%d)\n", status->status);
|
||||
} else {
|
||||
print(context.sh, SHELL_NORMAL, "Connected\n");
|
||||
PR("Connected\n");
|
||||
}
|
||||
|
||||
context.connecting = false;
|
||||
|
@ -248,16 +236,17 @@ static void handle_wifi_disconnect_result(struct net_mgmt_event_callback *cb)
|
|||
{
|
||||
const struct wifi_status *status =
|
||||
(const struct wifi_status *) cb->info;
|
||||
const struct shell *sh = context.sh;
|
||||
|
||||
if (context.disconnecting) {
|
||||
print(context.sh,
|
||||
status->status ? SHELL_WARNING : SHELL_NORMAL,
|
||||
"Disconnection request %s (%d)\n",
|
||||
status->status ? "failed" : "done",
|
||||
status->status);
|
||||
if (status->status) {
|
||||
PR_WARNING("Disconnection request failed (%d)\n", status->status);
|
||||
} else {
|
||||
PR("Disconnection request done (%d)\n", status->status);
|
||||
}
|
||||
context.disconnecting = false;
|
||||
} else {
|
||||
print(context.sh, SHELL_NORMAL, "Disconnected\n");
|
||||
PR("Disconnected\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,25 +258,25 @@ static void print_twt_params(uint8_t dialog_token, uint8_t flow_id,
|
|||
{
|
||||
const struct shell *sh = context.sh;
|
||||
|
||||
print(sh, SHELL_NORMAL, "TWT Dialog token: %d\n",
|
||||
PR("TWT Dialog token: %d\n",
|
||||
dialog_token);
|
||||
print(sh, SHELL_NORMAL, "TWT flow ID: %d\n",
|
||||
PR("TWT flow ID: %d\n",
|
||||
flow_id);
|
||||
print(sh, SHELL_NORMAL, "TWT negotiation type: %s\n",
|
||||
PR("TWT negotiation type: %s\n",
|
||||
wifi_twt_negotiation_type_txt(negotiation_type));
|
||||
print(sh, SHELL_NORMAL, "TWT responder: %s\n",
|
||||
PR("TWT responder: %s\n",
|
||||
responder ? "true" : "false");
|
||||
print(sh, SHELL_NORMAL, "TWT implicit: %s\n",
|
||||
PR("TWT implicit: %s\n",
|
||||
implicit ? "true" : "false");
|
||||
print(sh, SHELL_NORMAL, "TWT announce: %s\n",
|
||||
PR("TWT announce: %s\n",
|
||||
announce ? "true" : "false");
|
||||
print(sh, SHELL_NORMAL, "TWT trigger: %s\n",
|
||||
PR("TWT trigger: %s\n",
|
||||
trigger ? "true" : "false");
|
||||
print(sh, SHELL_NORMAL, "TWT wake interval: %d us\n",
|
||||
PR("TWT wake interval: %d us\n",
|
||||
twt_wake_interval);
|
||||
print(sh, SHELL_NORMAL, "TWT interval: %lld us\n",
|
||||
PR("TWT interval: %lld us\n",
|
||||
twt_interval);
|
||||
print(sh, SHELL_NORMAL, "========================\n");
|
||||
PR("========================\n");
|
||||
}
|
||||
|
||||
static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb)
|
||||
|
@ -298,19 +287,19 @@ static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb)
|
|||
|
||||
if (resp->operation == WIFI_TWT_TEARDOWN) {
|
||||
if (resp->teardown_status == WIFI_TWT_TEARDOWN_SUCCESS) {
|
||||
print(sh, SHELL_NORMAL, "TWT teardown succeeded for flow ID %d\n",
|
||||
PR("TWT teardown succeeded for flow ID %d\n",
|
||||
resp->flow_id);
|
||||
} else {
|
||||
print(sh, SHELL_NORMAL, "TWT teardown failed for flow ID %d\n",
|
||||
PR("TWT teardown failed for flow ID %d\n",
|
||||
resp->flow_id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (resp->resp_status == WIFI_TWT_RESP_RECEIVED) {
|
||||
print(sh, SHELL_NORMAL, "TWT response: %s\n",
|
||||
PR("TWT response: %s\n",
|
||||
wifi_twt_setup_cmd_txt(resp->setup_cmd));
|
||||
print(sh, SHELL_NORMAL, "== TWT negotiated parameters ==\n");
|
||||
PR("== TWT negotiated parameters ==\n");
|
||||
print_twt_params(resp->dialog_token,
|
||||
resp->flow_id,
|
||||
resp->negotiation_type,
|
||||
|
@ -321,7 +310,7 @@ static void handle_wifi_twt_event(struct net_mgmt_event_callback *cb)
|
|||
resp->setup.twt_wake_interval,
|
||||
resp->setup.twt_interval);
|
||||
} else {
|
||||
print(sh, SHELL_NORMAL, "TWT response timed out\n");
|
||||
PR("TWT response timed out\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,10 +321,9 @@ static void handle_wifi_ap_enable_result(struct net_mgmt_event_callback *cb)
|
|||
const struct shell *sh = context.sh;
|
||||
|
||||
if (status->status) {
|
||||
print(sh, SHELL_WARNING,
|
||||
"AP enable request failed (%d)\n", status->status);
|
||||
PR_WARNING("AP enable request failed (%d)\n", status->status);
|
||||
} else {
|
||||
print(sh, SHELL_NORMAL, "AP enabled\n");
|
||||
PR("AP enabled\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -346,10 +334,9 @@ static void handle_wifi_ap_disable_result(struct net_mgmt_event_callback *cb)
|
|||
const struct shell *sh = context.sh;
|
||||
|
||||
if (status->status) {
|
||||
print(sh, SHELL_WARNING,
|
||||
"AP disable request failed (%d)\n", status->status);
|
||||
PR_WARNING("AP disable request failed (%d)\n", status->status);
|
||||
} else {
|
||||
print(sh, SHELL_NORMAL, "AP disabled\n");
|
||||
PR("AP disabled\n");
|
||||
}
|
||||
|
||||
k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER);
|
||||
|
@ -365,9 +352,9 @@ static void handle_wifi_ap_sta_connected(struct net_mgmt_event_callback *cb)
|
|||
uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")];
|
||||
int i;
|
||||
|
||||
print(sh, SHELL_NORMAL, "Station connected: %s\n",
|
||||
net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN,
|
||||
mac_string_buf, sizeof(mac_string_buf)));
|
||||
PR("Station connected: %s\n",
|
||||
net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN,
|
||||
mac_string_buf, sizeof(mac_string_buf)));
|
||||
|
||||
k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER);
|
||||
for (i = 0; i < CONFIG_WIFI_SHELL_MAX_AP_STA; i++) {
|
||||
|
@ -378,8 +365,8 @@ static void handle_wifi_ap_sta_connected(struct net_mgmt_event_callback *cb)
|
|||
}
|
||||
}
|
||||
if (i == CONFIG_WIFI_SHELL_MAX_AP_STA) {
|
||||
print(sh, SHELL_WARNING, "No space to store station info: "
|
||||
"Increase CONFIG_WIFI_SHELL_MAX_AP_STA\n");
|
||||
PR_WARNING("No space to store station info: "
|
||||
"Increase CONFIG_WIFI_SHELL_MAX_AP_STA\n");
|
||||
}
|
||||
k_mutex_unlock(&wifi_ap_sta_list_lock);
|
||||
}
|
||||
|
@ -391,9 +378,9 @@ static void handle_wifi_ap_sta_disconnected(struct net_mgmt_event_callback *cb)
|
|||
const struct shell *sh = context.sh;
|
||||
uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")];
|
||||
|
||||
print(sh, SHELL_NORMAL, "Station disconnected: %s\n",
|
||||
net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN,
|
||||
mac_string_buf, sizeof(mac_string_buf)));
|
||||
PR("Station disconnected: %s\n",
|
||||
net_sprint_ll_addr_buf(sta_info->mac, WIFI_MAC_ADDR_LEN,
|
||||
mac_string_buf, sizeof(mac_string_buf)));
|
||||
|
||||
k_mutex_lock(&wifi_ap_sta_list_lock, K_FOREVER);
|
||||
for (int i = 0; i < CONFIG_WIFI_SHELL_MAX_AP_STA; i++) {
|
||||
|
@ -468,9 +455,8 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
|
|||
params->ssid = argv[0];
|
||||
params->ssid_length = strlen(params->ssid);
|
||||
if (params->ssid_length > WIFI_SSID_MAX_LEN) {
|
||||
print(sh, SHELL_WARNING,
|
||||
"SSID too long (max %d characters)\n",
|
||||
WIFI_SSID_MAX_LEN);
|
||||
PR_WARNING("SSID too long (max %d characters)\n",
|
||||
WIFI_SSID_MAX_LEN);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -486,11 +472,10 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
|
|||
size_t offset = 0;
|
||||
|
||||
if (*endptr != '\0') {
|
||||
print(sh, SHELL_ERROR,
|
||||
"Failed to parse channel: %s: endp: %s, err: %s\n",
|
||||
argv[idx],
|
||||
endptr,
|
||||
strerror(errno));
|
||||
PR_ERROR("Failed to parse channel: %s: endp: %s, err: %s\n",
|
||||
argv[idx],
|
||||
endptr,
|
||||
strerror(errno));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -508,15 +493,13 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
|
|||
params->band = WIFI_FREQ_BAND_6_GHZ;
|
||||
break;
|
||||
default:
|
||||
print(sh, SHELL_ERROR,
|
||||
"Invalid band: %ld\n", channel);
|
||||
PR_ERROR("Invalid band: %ld\n", channel);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (channel < 0) {
|
||||
print(sh, SHELL_ERROR,
|
||||
"Invalid channel: %ld\n", channel);
|
||||
PR_ERROR("Invalid channel: %ld\n", channel);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
@ -529,10 +512,9 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
|
|||
band ? "," : "",
|
||||
wifi_band_txt(all_bands[band]));
|
||||
if (offset >= sizeof(bands_str)) {
|
||||
print(sh, SHELL_ERROR,
|
||||
"Failed to parse channel: %s: "
|
||||
"band string too long\n",
|
||||
argv[idx]);
|
||||
PR_ERROR("Failed to parse channel: %s: "
|
||||
"band string too long\n",
|
||||
argv[idx]);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -544,10 +526,9 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
|
|||
}
|
||||
|
||||
if (!found) {
|
||||
print(sh, SHELL_ERROR,
|
||||
"Invalid channel: %ld, checked bands: %s\n",
|
||||
channel,
|
||||
bands_str);
|
||||
PR_ERROR("Invalid channel: %ld, checked bands: %s\n",
|
||||
channel,
|
||||
bands_str);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -580,9 +561,8 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
|
|||
|
||||
if (security == WIFI_SECURITY_TYPE_NONE ||
|
||||
security == WIFI_SECURITY_TYPE_WPA_PSK) {
|
||||
print(sh, SHELL_ERROR,
|
||||
"MFP not supported for security type %s\n",
|
||||
wifi_security_txt(security));
|
||||
PR_ERROR("MFP not supported for security type %s\n",
|
||||
wifi_security_txt(security));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -598,10 +578,9 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
|
|||
params->psk_length > WIFI_PSK_MAX_LEN) ||
|
||||
(params->security == WIFI_SECURITY_TYPE_SAE &&
|
||||
params->psk_length > WIFI_SAE_PSWD_MAX_LEN)) {
|
||||
print(sh, SHELL_ERROR,
|
||||
"Invalid PSK length (%d) for security type %s\n",
|
||||
params->psk_length,
|
||||
wifi_security_txt(params->security));
|
||||
PR_ERROR("Invalid PSK length (%d) for security type %s\n",
|
||||
params->psk_length,
|
||||
wifi_security_txt(params->security));
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue