samples: net: zperf: Comply with Coccinelle requirements

Cocinelle complains about "shell" being used as a parameter name:

"Violation to rule 5.7 (Tag name should be unique) tag: shell"

Therefore rename the parameter throughout the sample to "sh".

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2022-06-08 10:42:13 +02:00 committed by Carles Cufí
parent fd2fab1a49
commit fb802fb6c0
8 changed files with 276 additions and 276 deletions

View file

@ -21,7 +21,7 @@ const char *KBPS_UNIT[] = { "Mbps", "Kbps" };
const uint32_t K[] = { 1024 * 1024, 1024, 0 };
const char *K_UNIT[] = { "M", "K", "" };
void print_number(const struct shell *shell, uint32_t value,
void print_number(const struct shell *sh, uint32_t value,
const uint32_t *divisor, const char **units)
{
const char **unit;
@ -39,10 +39,10 @@ void print_number(const struct shell *shell, uint32_t value,
if (*div != 0U) {
radix = value / *div;
dec = (value % *div) * 100U / *div;
shell_fprintf(shell, SHELL_NORMAL, "%u.%s%u %s", radix,
shell_fprintf(sh, SHELL_NORMAL, "%u.%s%u %s", radix,
(dec < 10) ? "0" : "", dec, *unit);
} else {
shell_fprintf(shell, SHELL_NORMAL, "%u %s", value, *unit);
shell_fprintf(sh, SHELL_NORMAL, "%u %s", value, *unit);
}
}

View file

@ -18,7 +18,7 @@ extern const char *KBPS_UNIT[];
extern const uint32_t K[];
extern const char *K_UNIT[];
extern void print_number(const struct shell *shell, uint32_t value,
extern void print_number(const struct shell *sh, uint32_t value,
const uint32_t *divisor, const char **units);
extern long parse_number(const char *string, const uint32_t *divisor,
const char **units);

View file

@ -70,15 +70,15 @@ static inline uint32_t time_delta(uint32_t ts, uint32_t t)
return (t >= ts) ? (t - ts) : (ULONG_MAX - ts + t);
}
int zperf_get_ipv6_addr(const struct shell *shell, char *host,
int zperf_get_ipv6_addr(const struct shell *sh, char *host,
char *prefix_str, struct in6_addr *addr);
struct sockaddr_in6 *zperf_get_sin6(void);
int zperf_get_ipv4_addr(const struct shell *shell, char *host,
int zperf_get_ipv4_addr(const struct shell *sh, char *host,
struct in_addr *addr);
struct sockaddr_in *zperf_get_sin(void);
extern void zperf_udp_upload(const struct shell *shell,
extern void zperf_udp_upload(const struct shell *sh,
int sock,
int port,
unsigned int duration_in_ms,
@ -86,11 +86,11 @@ extern void zperf_udp_upload(const struct shell *shell,
unsigned int rate_in_kbps,
struct zperf_results *results);
extern void zperf_udp_receiver_init(const struct shell *shell, int port);
extern void zperf_udp_receiver_init(const struct shell *sh, int port);
extern void zperf_tcp_receiver_init(const struct shell *shell, int port);
extern void zperf_tcp_receiver_init(const struct shell *sh, int port);
extern void zperf_tcp_uploader_init(struct k_fifo *tx_queue);
extern void zperf_tcp_upload(const struct shell *shell,
extern void zperf_tcp_upload(const struct shell *sh,
int sock,
unsigned int duration_in_ms,
unsigned int packet_size,

View file

@ -88,19 +88,19 @@ struct sockaddr_in *zperf_get_sin(void)
return &in4_addr_my;
}
static void zperf_init(const struct shell *shell);
static void zperf_init(const struct shell *sh);
static void do_init(const struct shell *shell)
static void do_init(const struct shell *sh)
{
static bool init_ok;
if (!init_ok) {
zperf_init(shell);
zperf_init(sh);
init_ok = true;
}
}
static int parse_ipv6_addr(const struct shell *shell, char *host, char *port,
static int parse_ipv6_addr(const struct shell *sh, char *host, char *port,
struct sockaddr_in6 *addr)
{
int ret;
@ -111,14 +111,14 @@ static int parse_ipv6_addr(const struct shell *shell, char *host, char *port,
ret = net_addr_pton(AF_INET6, host, &addr->sin6_addr);
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Invalid IPv6 address %s\n", host);
return -EINVAL;
}
addr->sin6_port = htons(strtoul(port, NULL, 10));
if (!addr->sin6_port) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Invalid port %s\n", port);
return -EINVAL;
}
@ -126,7 +126,7 @@ static int parse_ipv6_addr(const struct shell *shell, char *host, char *port,
return 0;
}
int zperf_get_ipv6_addr(const struct shell *shell, char *host,
int zperf_get_ipv6_addr(const struct shell *sh, char *host,
char *prefix_str, struct in6_addr *addr)
{
struct net_if_ipv6_prefix *prefix;
@ -148,7 +148,7 @@ int zperf_get_ipv6_addr(const struct shell *shell, char *host,
ifaddr = net_if_ipv6_addr_add(net_if_get_default(),
addr, NET_ADDR_MANUAL, 0);
if (!ifaddr) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Cannot set IPv6 address %s\n", host);
return -EINVAL;
}
@ -157,7 +157,7 @@ int zperf_get_ipv6_addr(const struct shell *shell, char *host,
addr, prefix_len,
NET_IPV6_ND_INFINITE_LIFETIME);
if (!prefix) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Cannot set IPv6 prefix %s\n", prefix_str);
return -EINVAL;
}
@ -165,7 +165,7 @@ int zperf_get_ipv6_addr(const struct shell *shell, char *host,
return 0;
}
static int parse_ipv4_addr(const struct shell *shell, char *host, char *port,
static int parse_ipv4_addr(const struct shell *sh, char *host, char *port,
struct sockaddr_in *addr)
{
int ret;
@ -176,14 +176,14 @@ static int parse_ipv4_addr(const struct shell *shell, char *host, char *port,
ret = net_addr_pton(AF_INET, host, &addr->sin_addr);
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Invalid IPv4 address %s\n", host);
return -EINVAL;
}
addr->sin_port = htons(strtoul(port, NULL, 10));
if (!addr->sin_port) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Invalid port %s\n", port);
return -EINVAL;
}
@ -191,7 +191,7 @@ static int parse_ipv4_addr(const struct shell *shell, char *host, char *port,
return 0;
}
int zperf_get_ipv4_addr(const struct shell *shell, char *host,
int zperf_get_ipv4_addr(const struct shell *sh, char *host,
struct in_addr *addr)
{
struct net_if_addr *ifaddr;
@ -209,7 +209,7 @@ int zperf_get_ipv4_addr(const struct shell *shell, char *host,
ifaddr = net_if_ipv4_addr_add(net_if_get_default(),
addr, NET_ADDR_MANUAL, 0);
if (!ifaddr) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Cannot set IPv4 address %s\n", host);
return -EINVAL;
}
@ -237,43 +237,43 @@ const struct in6_addr *zperf_get_default_if_in6_addr(void)
#endif
}
static int cmd_setip(const struct shell *shell, size_t argc, char *argv[])
static int cmd_setip(const struct shell *sh, size_t argc, char *argv[])
{
int start = 0;
do_init(shell);
do_init(sh);
if (IS_ENABLED(CONFIG_NET_IPV6) && !IS_ENABLED(CONFIG_NET_IPV4)) {
if (argc != 3) {
shell_help(shell);
shell_help(sh);
return -ENOEXEC;
}
if (zperf_get_ipv6_addr(shell, argv[start + 1], argv[start + 2],
if (zperf_get_ipv6_addr(sh, argv[start + 1], argv[start + 2],
&ipv6) < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Unable to set IP\n");
return 0;
}
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Setting IP address %s\n",
net_sprint_ipv6_addr(&ipv6));
}
if (IS_ENABLED(CONFIG_NET_IPV4) && !IS_ENABLED(CONFIG_NET_IPV6)) {
if (argc != 2) {
shell_help(shell);
shell_help(sh);
return -ENOEXEC;
}
if (zperf_get_ipv4_addr(shell, argv[start + 1], &ipv4) < 0) {
shell_fprintf(shell, SHELL_WARNING,
if (zperf_get_ipv4_addr(sh, argv[start + 1], &ipv4) < 0) {
shell_fprintf(sh, SHELL_WARNING,
"Unable to set IP\n");
return -ENOEXEC;
}
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Setting IP address %s\n",
net_sprint_ipv4_addr(&ipv4));
}
@ -281,34 +281,34 @@ static int cmd_setip(const struct shell *shell, size_t argc, char *argv[])
if (IS_ENABLED(CONFIG_NET_IPV6) && IS_ENABLED(CONFIG_NET_IPV4)) {
if (net_addr_pton(AF_INET6, argv[start + 1], &ipv6) < 0) {
if (argc != 2) {
shell_help(shell);
shell_help(sh);
return -ENOEXEC;
}
if (zperf_get_ipv4_addr(shell, argv[start + 1],
if (zperf_get_ipv4_addr(sh, argv[start + 1],
&ipv4) < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Unable to set IP\n");
return -ENOEXEC;
}
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Setting IP address %s\n",
net_sprint_ipv4_addr(&ipv4));
} else {
if (argc != 3) {
shell_help(shell);
shell_help(sh);
return -ENOEXEC;
}
if (zperf_get_ipv6_addr(shell, argv[start + 1],
if (zperf_get_ipv6_addr(sh, argv[start + 1],
argv[start + 2], &ipv6) < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Unable to set IP\n");
return -ENOEXEC;
}
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Setting IP address %s\n",
net_sprint_ipv6_addr(&ipv6));
}
@ -317,14 +317,14 @@ static int cmd_setip(const struct shell *shell, size_t argc, char *argv[])
return 0;
}
static int cmd_udp_download(const struct shell *shell, size_t argc,
static int cmd_udp_download(const struct shell *sh, size_t argc,
char *argv[])
{
if (IS_ENABLED(CONFIG_NET_UDP)) {
static bool udp_stopped = true;
int port, start = 0;
do_init(shell);
do_init(sh);
if (argc >= 2) {
port = strtoul(argv[start + 1], NULL, 10);
@ -333,18 +333,18 @@ static int cmd_udp_download(const struct shell *shell, size_t argc,
}
if (!udp_stopped) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"UDP server already started!\n");
return -ENOEXEC;
}
zperf_udp_receiver_init(shell, port);
zperf_udp_receiver_init(sh, port);
k_yield();
udp_stopped = false;
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"UDP server started on port %u\n", port);
return 0;
@ -353,13 +353,13 @@ static int cmd_udp_download(const struct shell *shell, size_t argc,
}
}
static void shell_udp_upload_print_stats(const struct shell *shell,
static void shell_udp_upload_print_stats(const struct shell *sh,
struct zperf_results *results)
{
if (IS_ENABLED(CONFIG_NET_UDP)) {
unsigned int rate_in_kbps, client_rate_in_kbps;
shell_fprintf(shell, SHELL_NORMAL, "-\nUpload completed!\n");
shell_fprintf(sh, SHELL_NORMAL, "-\nUpload completed!\n");
if (results->time_in_us != 0U) {
rate_in_kbps = (uint32_t)
@ -381,50 +381,50 @@ static void shell_udp_upload_print_stats(const struct shell *shell,
}
if (!rate_in_kbps) {
shell_fprintf(shell, SHELL_ERROR,
shell_fprintf(sh, SHELL_ERROR,
"LAST PACKET NOT RECEIVED!!!\n");
}
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Statistics:\t\tserver\t(client)\n");
shell_fprintf(shell, SHELL_NORMAL, "Duration:\t\t");
print_number(shell, results->time_in_us, TIME_US,
shell_fprintf(sh, SHELL_NORMAL, "Duration:\t\t");
print_number(sh, results->time_in_us, TIME_US,
TIME_US_UNIT);
shell_fprintf(shell, SHELL_NORMAL, "\t(");
print_number(shell, results->client_time_in_us, TIME_US,
shell_fprintf(sh, SHELL_NORMAL, "\t(");
print_number(sh, results->client_time_in_us, TIME_US,
TIME_US_UNIT);
shell_fprintf(shell, SHELL_NORMAL, ")\n");
shell_fprintf(sh, SHELL_NORMAL, ")\n");
shell_fprintf(shell, SHELL_NORMAL, "Num packets:\t\t%u\t(%u)\n",
shell_fprintf(sh, SHELL_NORMAL, "Num packets:\t\t%u\t(%u)\n",
results->nb_packets_rcvd,
results->nb_packets_sent);
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Num packets out order:\t%u\n",
results->nb_packets_outorder);
shell_fprintf(shell, SHELL_NORMAL, "Num packets lost:\t%u\n",
shell_fprintf(sh, SHELL_NORMAL, "Num packets lost:\t%u\n",
results->nb_packets_lost);
shell_fprintf(shell, SHELL_NORMAL, "Jitter:\t\t\t");
print_number(shell, results->jitter_in_us, TIME_US,
shell_fprintf(sh, SHELL_NORMAL, "Jitter:\t\t\t");
print_number(sh, results->jitter_in_us, TIME_US,
TIME_US_UNIT);
shell_fprintf(shell, SHELL_NORMAL, "\n");
shell_fprintf(sh, SHELL_NORMAL, "\n");
shell_fprintf(shell, SHELL_NORMAL, "Rate:\t\t\t");
print_number(shell, rate_in_kbps, KBPS, KBPS_UNIT);
shell_fprintf(shell, SHELL_NORMAL, "\t(");
print_number(shell, client_rate_in_kbps, KBPS, KBPS_UNIT);
shell_fprintf(shell, SHELL_NORMAL, ")\n");
shell_fprintf(sh, SHELL_NORMAL, "Rate:\t\t\t");
print_number(sh, rate_in_kbps, KBPS, KBPS_UNIT);
shell_fprintf(sh, SHELL_NORMAL, "\t(");
print_number(sh, client_rate_in_kbps, KBPS, KBPS_UNIT);
shell_fprintf(sh, SHELL_NORMAL, ")\n");
}
}
static void shell_tcp_upload_print_stats(const struct shell *shell,
static void shell_tcp_upload_print_stats(const struct shell *sh,
struct zperf_results *results)
{
if (IS_ENABLED(CONFIG_NET_TCP)) {
unsigned int client_rate_in_kbps;
shell_fprintf(shell, SHELL_NORMAL, "-\nUpload completed!\n");
shell_fprintf(sh, SHELL_NORMAL, "-\nUpload completed!\n");
if (results->client_time_in_us != 0U) {
client_rate_in_kbps = (uint32_t)
@ -436,22 +436,22 @@ static void shell_tcp_upload_print_stats(const struct shell *shell,
client_rate_in_kbps = 0U;
}
shell_fprintf(shell, SHELL_NORMAL, "Duration:\t");
print_number(shell, results->client_time_in_us,
shell_fprintf(sh, SHELL_NORMAL, "Duration:\t");
print_number(sh, results->client_time_in_us,
TIME_US, TIME_US_UNIT);
shell_fprintf(shell, SHELL_NORMAL, "\n");
shell_fprintf(shell, SHELL_NORMAL, "Num packets:\t%u\n",
shell_fprintf(sh, SHELL_NORMAL, "\n");
shell_fprintf(sh, SHELL_NORMAL, "Num packets:\t%u\n",
results->nb_packets_sent);
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Num errors:\t%u (retry or fail)\n",
results->nb_packets_errors);
shell_fprintf(shell, SHELL_NORMAL, "Rate:\t\t");
print_number(shell, client_rate_in_kbps, KBPS, KBPS_UNIT);
shell_fprintf(shell, SHELL_NORMAL, "\n");
shell_fprintf(sh, SHELL_NORMAL, "Rate:\t\t");
print_number(sh, client_rate_in_kbps, KBPS, KBPS_UNIT);
shell_fprintf(sh, SHELL_NORMAL, "\n");
}
}
static int setup_upload_sockets(const struct shell *shell,
static int setup_upload_sockets(const struct shell *sh,
int *sock6,
int *sock4,
sa_family_t family,
@ -466,7 +466,7 @@ static int setup_upload_sockets(const struct shell *shell,
is_udp ? SOCK_DGRAM : SOCK_STREAM,
is_udp ? IPPROTO_UDP : IPPROTO_TCP);
if (*sock6 < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Cannot create IPv6 network socket (%d)\n",
errno);
return -ENOEXEC;
@ -481,7 +481,7 @@ static int setup_upload_sockets(const struct shell *shell,
is_udp ? SOCK_DGRAM : SOCK_STREAM,
is_udp ? IPPROTO_UDP : IPPROTO_TCP);
if (*sock4 < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Cannot create IPv4 network socket (%d)\n",
errno);
return -ENOEXEC;
@ -492,7 +492,7 @@ static int setup_upload_sockets(const struct shell *shell,
}
if ((*sock6 < 0) && (*sock4 < 0)) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Fail to create network socket(s)\n");
return -ENOEXEC;
}
@ -500,7 +500,7 @@ static int setup_upload_sockets(const struct shell *shell,
return 0;
}
static int execute_upload(const struct shell *shell,
static int execute_upload(const struct shell *sh,
int sock6,
int sock4,
sa_family_t family,
@ -516,15 +516,15 @@ static int execute_upload(const struct shell *shell,
struct zperf_results results = { };
int ret;
shell_fprintf(shell, SHELL_NORMAL, "Duration:\t");
print_number(shell, duration_in_ms * USEC_PER_MSEC, TIME_US,
shell_fprintf(sh, SHELL_NORMAL, "Duration:\t");
print_number(sh, duration_in_ms * USEC_PER_MSEC, TIME_US,
TIME_US_UNIT);
shell_fprintf(shell, SHELL_NORMAL, "\n");
shell_fprintf(shell, SHELL_NORMAL, "Packet size:\t%u bytes\n",
shell_fprintf(sh, SHELL_NORMAL, "\n");
shell_fprintf(sh, SHELL_NORMAL, "Packet size:\t%u bytes\n",
packet_size);
shell_fprintf(shell, SHELL_NORMAL, "Rate:\t\t%u kbps\n",
shell_fprintf(sh, SHELL_NORMAL, "Rate:\t\t%u kbps\n",
rate_in_kbps);
shell_fprintf(shell, SHELL_NORMAL, "Starting...\n");
shell_fprintf(sh, SHELL_NORMAL, "Starting...\n");
if (IS_ENABLED(CONFIG_NET_IPV6) && family == AF_INET6 && sock6 >= 0) {
/* For IPv6, we should make sure that neighbor discovery
@ -538,24 +538,24 @@ static int execute_upload(const struct shell *shell,
}
if (is_udp && IS_ENABLED(CONFIG_NET_UDP)) {
shell_fprintf(shell, SHELL_NORMAL, "Rate:\t\t");
print_number(shell, rate_in_kbps, KBPS, KBPS_UNIT);
shell_fprintf(shell, SHELL_NORMAL, "\n");
shell_fprintf(sh, SHELL_NORMAL, "Rate:\t\t");
print_number(sh, rate_in_kbps, KBPS, KBPS_UNIT);
shell_fprintf(sh, SHELL_NORMAL, "\n");
if (family == AF_INET6 && sock6 >= 0) {
ret = connect(sock6,
(struct sockaddr *)ipv6,
sizeof(*ipv6));
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"IPv6 connect failed (%d)\n",
errno);
goto out;
}
zperf_udp_upload(shell, sock6, port, duration_in_ms,
zperf_udp_upload(sh, sock6, port, duration_in_ms,
packet_size, rate_in_kbps, &results);
shell_udp_upload_print_stats(shell, &results);
shell_udp_upload_print_stats(sh, &results);
}
if (family == AF_INET && sock4 >= 0) {
@ -563,19 +563,19 @@ static int execute_upload(const struct shell *shell,
(struct sockaddr *)ipv4,
sizeof(*ipv4));
if (ret < 0) {
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"IPv4 connect failed (%d)\n",
errno);
goto out;
}
zperf_udp_upload(shell, sock4, port, duration_in_ms,
zperf_udp_upload(sh, sock4, port, duration_in_ms,
packet_size, rate_in_kbps, &results);
shell_udp_upload_print_stats(shell, &results);
shell_udp_upload_print_stats(sh, &results);
}
} else {
if (!IS_ENABLED(CONFIG_NET_UDP)) {
shell_fprintf(shell, SHELL_INFO,
shell_fprintf(sh, SHELL_INFO,
"UDP not supported\n");
}
}
@ -586,7 +586,7 @@ static int execute_upload(const struct shell *shell,
(struct sockaddr *)ipv6,
sizeof(*ipv6));
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"IPv6 connect failed (%d)\n",
errno);
goto out;
@ -600,10 +600,10 @@ static int execute_upload(const struct shell *shell,
sock4 = -1;
}
zperf_tcp_upload(shell, sock6, duration_in_ms,
zperf_tcp_upload(sh, sock6, duration_in_ms,
packet_size, &results);
shell_tcp_upload_print_stats(shell, &results);
shell_tcp_upload_print_stats(sh, &results);
}
if (family == AF_INET && sock4 >= 0) {
@ -611,7 +611,7 @@ static int execute_upload(const struct shell *shell,
(struct sockaddr *)ipv4,
sizeof(*ipv4));
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"IPv4 connect failed (%d)\n",
errno);
goto out;
@ -622,14 +622,14 @@ static int execute_upload(const struct shell *shell,
sock6 = -1;
}
zperf_tcp_upload(shell, sock4, duration_in_ms,
zperf_tcp_upload(sh, sock4, duration_in_ms,
packet_size, &results);
shell_tcp_upload_print_stats(shell, &results);
shell_tcp_upload_print_stats(sh, &results);
}
} else {
if (!IS_ENABLED(CONFIG_NET_TCP)) {
shell_fprintf(shell, SHELL_INFO,
shell_fprintf(sh, SHELL_INFO,
"TCP not supported\n");
}
}
@ -648,7 +648,7 @@ out:
return 0;
}
static int shell_cmd_upload(const struct shell *shell, size_t argc,
static int shell_cmd_upload(const struct shell *sh, size_t argc,
char *argv[], enum net_ip_protocol proto)
{
struct sockaddr_in6 ipv6 = { .sin6_family = AF_INET6 };
@ -664,17 +664,17 @@ static int shell_cmd_upload(const struct shell *shell, size_t argc,
is_udp = proto == IPPROTO_UDP;
if (argc < 2) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Not enough parameters.\n");
if (is_udp) {
if (IS_ENABLED(CONFIG_NET_UDP)) {
shell_help(shell);
shell_help(sh);
return -ENOEXEC;
}
} else {
if (IS_ENABLED(CONFIG_NET_TCP)) {
shell_help(shell);
shell_help(sh);
return -ENOEXEC;
}
}
@ -684,7 +684,7 @@ static int shell_cmd_upload(const struct shell *shell, size_t argc,
if (argc > 2) {
port = strtoul(argv[start + 2], NULL, 10);
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Remote port is %u\n", port);
port_str = argv[start + 2];
} else {
@ -693,53 +693,53 @@ static int shell_cmd_upload(const struct shell *shell, size_t argc,
}
if (IS_ENABLED(CONFIG_NET_IPV6) && !IS_ENABLED(CONFIG_NET_IPV4)) {
if (parse_ipv6_addr(shell, argv[start + 1], port_str,
if (parse_ipv6_addr(sh, argv[start + 1], port_str,
&ipv6) < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Please specify the IP address of the "
"remote server.\n");
return -ENOEXEC;
}
shell_fprintf(shell, SHELL_WARNING, "Connecting to %s\n",
shell_fprintf(sh, SHELL_WARNING, "Connecting to %s\n",
net_sprint_ipv6_addr(&ipv6.sin6_addr));
family = AF_INET6;
}
if (IS_ENABLED(CONFIG_NET_IPV4) && !IS_ENABLED(CONFIG_NET_IPV6)) {
if (parse_ipv4_addr(shell, argv[start + 1], port_str,
if (parse_ipv4_addr(sh, argv[start + 1], port_str,
&ipv4) < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Please specify the IP address of the "
"remote server.\n");
return -ENOEXEC;
}
shell_fprintf(shell, SHELL_NORMAL, "Connecting to %s\n",
shell_fprintf(sh, SHELL_NORMAL, "Connecting to %s\n",
net_sprint_ipv4_addr(&ipv4.sin_addr));
family = AF_INET;
}
if (IS_ENABLED(CONFIG_NET_IPV6) && IS_ENABLED(CONFIG_NET_IPV4)) {
if (parse_ipv6_addr(shell, argv[start + 1], port_str,
if (parse_ipv6_addr(sh, argv[start + 1], port_str,
&ipv6) < 0) {
if (parse_ipv4_addr(shell, argv[start + 1], port_str,
if (parse_ipv4_addr(sh, argv[start + 1], port_str,
&ipv4) < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Please specify the IP address "
"of the remote server.\n");
return -ENOEXEC;
}
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Connecting to %s\n",
net_sprint_ipv4_addr(&ipv4.sin_addr));
family = AF_INET;
} else {
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Connecting to %s\n",
net_sprint_ipv6_addr(&ipv6.sin6_addr));
@ -747,7 +747,7 @@ static int shell_cmd_upload(const struct shell *shell, size_t argc,
}
}
if (setup_upload_sockets(shell, &sock6, &sock4, family, &in6_addr_my,
if (setup_upload_sockets(sh, &sock6, &sock4, family, &in6_addr_my,
&in4_addr_my, port, is_udp, argv[start]) < 0) {
return -ENOEXEC;
}
@ -773,26 +773,26 @@ static int shell_cmd_upload(const struct shell *shell, size_t argc,
rate_in_kbps = 10U;
}
return execute_upload(shell, sock6, sock4, family, &ipv6, &ipv4,
return execute_upload(sh, sock6, sock4, family, &ipv6, &ipv4,
is_udp, port, argv[start], duration_in_ms,
packet_size, rate_in_kbps);
}
static int cmd_tcp_upload(const struct shell *shell, size_t argc, char *argv[])
static int cmd_tcp_upload(const struct shell *sh, size_t argc, char *argv[])
{
do_init(shell);
do_init(sh);
return shell_cmd_upload(shell, argc, argv, IPPROTO_TCP);
return shell_cmd_upload(sh, argc, argv, IPPROTO_TCP);
}
static int cmd_udp_upload(const struct shell *shell, size_t argc, char *argv[])
static int cmd_udp_upload(const struct shell *sh, size_t argc, char *argv[])
{
do_init(shell);
do_init(sh);
return shell_cmd_upload(shell, argc, argv, IPPROTO_UDP);
return shell_cmd_upload(sh, argc, argv, IPPROTO_UDP);
}
static int shell_cmd_upload2(const struct shell *shell, size_t argc,
static int shell_cmd_upload2(const struct shell *sh, size_t argc,
char *argv[], enum net_ip_protocol proto)
{
int sock6 = -1, sock4 = -1;
@ -805,17 +805,17 @@ static int shell_cmd_upload2(const struct shell *shell, size_t argc,
is_udp = proto == IPPROTO_UDP;
if (argc < 2) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Not enough parameters.\n");
if (is_udp) {
if (IS_ENABLED(CONFIG_NET_UDP)) {
shell_help(shell);
shell_help(sh);
return -ENOEXEC;
}
} else {
if (IS_ENABLED(CONFIG_NET_TCP)) {
shell_help(shell);
shell_help(sh);
return -ENOEXEC;
}
}
@ -835,39 +835,39 @@ static int shell_cmd_upload2(const struct shell *shell, size_t argc,
if (family == AF_INET6) {
if (net_ipv6_is_addr_unspecified(&in6_addr_my.sin6_addr)) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Invalid local IPv6 address.\n");
return -ENOEXEC;
}
if (net_ipv6_is_addr_unspecified(&in6_addr_dst.sin6_addr)) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Invalid destination IPv6 address.\n");
return -ENOEXEC;
}
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Connecting to %s\n",
net_sprint_ipv6_addr(&in6_addr_dst.sin6_addr));
} else {
if (net_ipv4_is_addr_unspecified(&in4_addr_my.sin_addr)) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Invalid local IPv4 address.\n");
return -ENOEXEC;
}
if (net_ipv4_is_addr_unspecified(&in4_addr_dst.sin_addr)) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Invalid destination IPv4 address.\n");
return -ENOEXEC;
}
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Connecting to %s\n",
net_sprint_ipv4_addr(&in4_addr_dst.sin_addr));
}
if (setup_upload_sockets(shell, &sock6, &sock4, family, &in6_addr_my,
if (setup_upload_sockets(sh, &sock6, &sock4, family, &in6_addr_my,
&in4_addr_my, port, is_udp, argv[start]) < 0) {
return -ENOEXEC;
}
@ -893,60 +893,60 @@ static int shell_cmd_upload2(const struct shell *shell, size_t argc,
rate_in_kbps = 10U;
}
return execute_upload(shell, sock6, sock4, family, &in6_addr_dst,
return execute_upload(sh, sock6, sock4, family, &in6_addr_dst,
&in4_addr_dst, is_udp, port, argv[start],
duration_in_ms, packet_size, rate_in_kbps);
}
static int cmd_tcp_upload2(const struct shell *shell, size_t argc,
static int cmd_tcp_upload2(const struct shell *sh, size_t argc,
char *argv[])
{
do_init(shell);
do_init(sh);
return shell_cmd_upload2(shell, argc, argv, IPPROTO_TCP);
return shell_cmd_upload2(sh, argc, argv, IPPROTO_TCP);
}
static int cmd_udp_upload2(const struct shell *shell, size_t argc,
static int cmd_udp_upload2(const struct shell *sh, size_t argc,
char *argv[])
{
do_init(shell);
do_init(sh);
return shell_cmd_upload2(shell, argc, argv, IPPROTO_UDP);
return shell_cmd_upload2(sh, argc, argv, IPPROTO_UDP);
}
static int cmd_tcp(const struct shell *shell, size_t argc, char *argv[])
static int cmd_tcp(const struct shell *sh, size_t argc, char *argv[])
{
if (IS_ENABLED(CONFIG_NET_TCP)) {
do_init(shell);
do_init(sh);
shell_help(shell);
shell_help(sh);
return -ENOEXEC;
}
shell_fprintf(shell, SHELL_INFO, "TCP support is not enabled. "
shell_fprintf(sh, SHELL_INFO, "TCP support is not enabled. "
"Set CONFIG_NET_TCP=y in your config file.\n");
return -ENOTSUP;
}
static int cmd_udp(const struct shell *shell, size_t argc, char *argv[])
static int cmd_udp(const struct shell *sh, size_t argc, char *argv[])
{
if (IS_ENABLED(CONFIG_NET_UDP)) {
do_init(shell);
do_init(sh);
shell_help(shell);
shell_help(sh);
return -ENOEXEC;
}
shell_fprintf(shell, SHELL_INFO, "UDP support is not enabled. "
shell_fprintf(sh, SHELL_INFO, "UDP support is not enabled. "
"Set CONFIG_NET_UDP=y in your config file.\n");
return -ENOTSUP;
}
static int cmd_connectap(const struct shell *shell, size_t argc, char *argv[])
static int cmd_connectap(const struct shell *sh, size_t argc, char *argv[])
{
shell_fprintf(shell, SHELL_INFO,
shell_fprintf(sh, SHELL_INFO,
"Zephyr has not been built with Wi-Fi support.\n");
return 0;
@ -964,13 +964,13 @@ void zperf_tcp_started(void)
tcp_running = true;
}
static int cmd_tcp_download(const struct shell *shell, size_t argc,
static int cmd_tcp_download(const struct shell *sh, size_t argc,
char *argv[])
{
if (IS_ENABLED(CONFIG_NET_TCP)) {
int port;
do_init(shell);
do_init(sh);
if (argc >= 2) {
port = strtoul(argv[1], NULL, 10);
@ -979,14 +979,14 @@ static int cmd_tcp_download(const struct shell *shell, size_t argc,
}
if (tcp_running) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"TCP server already started!\n");
return -ENOEXEC;
}
zperf_tcp_receiver_init(shell, port);
zperf_tcp_receiver_init(sh, port);
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"TCP server started on port %u\n", port);
return 0;
@ -995,27 +995,27 @@ static int cmd_tcp_download(const struct shell *shell, size_t argc,
}
}
static int cmd_version(const struct shell *shell, size_t argc, char *argv[])
static int cmd_version(const struct shell *sh, size_t argc, char *argv[])
{
shell_fprintf(shell, SHELL_NORMAL, "Version: %s\nConfig: %s\n",
shell_fprintf(sh, SHELL_NORMAL, "Version: %s\nConfig: %s\n",
VERSION, CONFIG);
return 0;
}
static void zperf_init(const struct shell *shell)
static void zperf_init(const struct shell *sh)
{
int ret;
shell_fprintf(shell, SHELL_NORMAL, "\n");
shell_fprintf(sh, SHELL_NORMAL, "\n");
if (IS_ENABLED(CONFIG_NET_IPV6) && MY_IP6ADDR) {
if (zperf_get_ipv6_addr(shell, MY_IP6ADDR, MY_PREFIX_LEN_STR,
if (zperf_get_ipv6_addr(sh, MY_IP6ADDR, MY_PREFIX_LEN_STR,
&ipv6) < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Unable to set IP\n");
} else {
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Setting IP address %s\n",
net_sprint_ipv6_addr(&ipv6));
@ -1025,11 +1025,11 @@ static void zperf_init(const struct shell *shell)
ret = net_addr_pton(AF_INET6, DST_IP6ADDR,
&in6_addr_dst.sin6_addr);
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Unable to set IP %s\n",
DST_IP6ADDR);
} else {
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Setting destination IP address %s\n",
net_sprint_ipv6_addr(
&in6_addr_dst.sin6_addr));
@ -1037,11 +1037,11 @@ static void zperf_init(const struct shell *shell)
}
if (IS_ENABLED(CONFIG_NET_IPV4) && MY_IP4ADDR) {
if (zperf_get_ipv4_addr(shell, MY_IP4ADDR, &ipv4) < 0) {
shell_fprintf(shell, SHELL_WARNING,
if (zperf_get_ipv4_addr(sh, MY_IP4ADDR, &ipv4) < 0) {
shell_fprintf(sh, SHELL_WARNING,
"Unable to set IP\n");
} else {
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Setting IP address %s\n",
net_sprint_ipv4_addr(&ipv4));
@ -1051,18 +1051,18 @@ static void zperf_init(const struct shell *shell)
ret = net_addr_pton(AF_INET, DST_IP4ADDR,
&in4_addr_dst.sin_addr);
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Unable to set IP %s\n",
DST_IP4ADDR);
} else {
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Setting destination IP address %s\n",
net_sprint_ipv4_addr(
&in4_addr_dst.sin_addr));
}
}
shell_fprintf(shell, SHELL_NORMAL, "\n");
shell_fprintf(sh, SHELL_NORMAL, "\n");
zperf_session_init();
}

View file

@ -49,7 +49,7 @@ static bool init_done;
K_THREAD_STACK_DEFINE(tcp_receiver_stack_area, TCP_RECEIVER_STACK_SIZE);
struct k_thread tcp_receiver_thread_data;
static void tcp_received(const struct shell *shell, int sock, size_t datalen)
static void tcp_received(const struct shell *sh, int sock, size_t datalen)
{
struct session *session;
int64_t time;
@ -58,7 +58,7 @@ static void tcp_received(const struct shell *shell, int sock, size_t datalen)
session = get_tcp_session(sock);
if (!session) {
shell_fprintf(shell, SHELL_WARNING, "Cannot get a session!\n");
shell_fprintf(sh, SHELL_WARNING, "Cannot get a session!\n");
return;
}
@ -66,7 +66,7 @@ static void tcp_received(const struct shell *shell, int sock, size_t datalen)
case STATE_COMPLETED:
break;
case STATE_NULL:
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"New TCP session started\n");
zperf_reset_session_stats(session);
session->start_time = k_uptime_ticks();
@ -95,17 +95,17 @@ static void tcp_received(const struct shell *shell, int sock, size_t datalen)
rate_in_kbps = 0U;
}
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"TCP session ended\n");
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
" Duration:\t\t");
print_number(shell, duration, TIME_US, TIME_US_UNIT);
shell_fprintf(shell, SHELL_NORMAL, "\n");
print_number(sh, duration, TIME_US, TIME_US_UNIT);
shell_fprintf(sh, SHELL_NORMAL, "\n");
shell_fprintf(shell, SHELL_NORMAL, " rate:\t\t\t");
print_number(shell, rate_in_kbps, KBPS, KBPS_UNIT);
shell_fprintf(shell, SHELL_NORMAL, "\n");
shell_fprintf(sh, SHELL_NORMAL, " rate:\t\t\t");
print_number(sh, rate_in_kbps, KBPS, KBPS_UNIT);
shell_fprintf(sh, SHELL_NORMAL, "\n");
zperf_tcp_stopped();
@ -117,7 +117,7 @@ static void tcp_received(const struct shell *shell, int sock, size_t datalen)
case STATE_LAST_PACKET_RECEIVED:
break;
default:
shell_fprintf(shell, SHELL_WARNING, "Unsupported case\n");
shell_fprintf(sh, SHELL_WARNING, "Unsupported case\n");
}
}
@ -126,7 +126,7 @@ void tcp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
ARG_UNUSED(ptr3);
static uint8_t buf[TCP_RECEIVER_BUF_SIZE];
const struct shell *shell = ptr1;
const struct shell *sh = ptr1;
int port = POINTER_TO_INT(ptr2);
struct pollfd fds[SOCK_ID_MAX] = { 0 };
int ret;
@ -143,17 +143,17 @@ void tcp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
fds[SOCK_ID_IPV4_LISTEN].fd = socket(AF_INET, SOCK_STREAM,
IPPROTO_TCP);
if (fds[SOCK_ID_IPV4_LISTEN].fd < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Cannot create IPv4 network socket.\n");
goto cleanup;
}
if (MY_IP4ADDR && strlen(MY_IP4ADDR)) {
/* Use Setting IP */
ret = zperf_get_ipv4_addr(shell, MY_IP4ADDR,
ret = zperf_get_ipv4_addr(sh, MY_IP4ADDR,
&in4_addr_my->sin_addr);
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Unable to set IPv4\n");
goto use_existing_ipv4;
}
@ -162,7 +162,7 @@ void tcp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
/* Use existing IP */
in4_addr = zperf_get_default_if_in4_addr();
if (!in4_addr) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Unable to get IPv4 by default\n");
return;
}
@ -172,14 +172,14 @@ void tcp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
in4_addr_my->sin_port = htons(port);
shell_fprintf(shell, SHELL_NORMAL, "Binding to %s\n",
shell_fprintf(sh, SHELL_NORMAL, "Binding to %s\n",
net_sprint_ipv4_addr(&in4_addr_my->sin_addr));
ret = bind(fds[SOCK_ID_IPV4_LISTEN].fd,
(struct sockaddr *)in4_addr_my,
sizeof(struct sockaddr_in));
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Cannot bind IPv4 UDP port %d (%d)\n",
ntohs(in4_addr_my->sin_port),
errno);
@ -188,7 +188,7 @@ void tcp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
ret = listen(fds[SOCK_ID_IPV4_LISTEN].fd, 1);
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Cannot listen IPv4 TCP (%d)", errno);
goto cleanup;
}
@ -204,18 +204,18 @@ void tcp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
fds[SOCK_ID_IPV6_LISTEN].fd = socket(AF_INET6, SOCK_STREAM,
IPPROTO_TCP);
if (fds[SOCK_ID_IPV6_LISTEN].fd < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Cannot create IPv6 network socket.\n");
goto cleanup;
}
if (MY_IP6ADDR && strlen(MY_IP6ADDR)) {
/* Use Setting IP */
ret = zperf_get_ipv6_addr(shell, MY_IP6ADDR,
ret = zperf_get_ipv6_addr(sh, MY_IP6ADDR,
MY_PREFIX_LEN_STR,
&in6_addr_my->sin6_addr);
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Unable to set IPv6\n");
goto use_existing_ipv6;
}
@ -224,7 +224,7 @@ void tcp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
/* Use existing IP */
in6_addr = zperf_get_default_if_in6_addr();
if (!in6_addr) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Unable to get IPv4 by default\n");
return;
}
@ -234,14 +234,14 @@ void tcp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
in6_addr_my->sin6_port = htons(port);
shell_fprintf(shell, SHELL_NORMAL, "Binding to %s\n",
shell_fprintf(sh, SHELL_NORMAL, "Binding to %s\n",
net_sprint_ipv6_addr(&in6_addr_my->sin6_addr));
ret = bind(fds[SOCK_ID_IPV6_LISTEN].fd,
(struct sockaddr *)in6_addr_my,
sizeof(struct sockaddr_in6));
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Cannot bind IPv6 UDP port %d (%d)\n",
ntohs(in6_addr_my->sin6_port),
errno);
@ -250,7 +250,7 @@ void tcp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
ret = listen(fds[SOCK_ID_IPV6_LISTEN].fd, 1);
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Cannot listen IPv6 TCP (%d)", errno);
goto cleanup;
}
@ -258,7 +258,7 @@ void tcp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
fds[SOCK_ID_IPV6_LISTEN].events = POLLIN;
}
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Listening on port %d\n", port);
/* TODO Investigate started/stopped logic */
@ -268,7 +268,7 @@ void tcp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
while (true) {
ret = poll(fds, ARRAY_SIZE(fds), -1);
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"TCP receiver poll error (%d)\n",
errno);
goto cleanup;
@ -281,7 +281,7 @@ void tcp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
if ((fds[i].revents & POLLERR) ||
(fds[i].revents & POLLNVAL)) {
shell_fprintf(
shell, SHELL_WARNING,
sh, SHELL_WARNING,
"TCP receiver IPv%d socket error\n",
(i <= SOCK_ID_IPV4_DATA) ? 4 : 6);
goto cleanup;
@ -298,7 +298,7 @@ void tcp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
if (sock < 0) {
shell_fprintf(
shell, SHELL_WARNING,
sh, SHELL_WARNING,
"TCP receiver IPv%d accept error\n",
(i <= SOCK_ID_IPV4_DATA) ? 4 : 6);
goto cleanup;
@ -326,14 +326,14 @@ void tcp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
ret = recv(fds[i].fd, buf, sizeof(buf), 0);
if (ret < 0) {
shell_fprintf(
shell, SHELL_WARNING,
sh, SHELL_WARNING,
"recv failed on IPv%d socket (%d)\n",
(i <= SOCK_ID_IPV4_DATA) ? 4 : 6,
errno);
goto cleanup;
}
tcp_received(shell, fds[i].fd, ret);
tcp_received(sh, fds[i].fd, ret);
if (ret == 0) {
close(fds[i].fd);
@ -353,7 +353,7 @@ cleanup:
}
}
void zperf_tcp_receiver_init(const struct shell *shell, int port)
void zperf_tcp_receiver_init(const struct shell *sh, int port)
{
if (init_done) {
zperf_tcp_started();
@ -364,7 +364,7 @@ void zperf_tcp_receiver_init(const struct shell *shell, int port)
tcp_receiver_stack_area,
K_THREAD_STACK_SIZEOF(tcp_receiver_stack_area),
tcp_receiver_thread,
(void *)shell, INT_TO_POINTER(port), NULL,
(void *)sh, INT_TO_POINTER(port), NULL,
TCP_RECEIVER_THREAD_PRIORITY,
IS_ENABLED(CONFIG_USERSPACE) ? K_USER |
K_INHERIT_PERMS : 0,

View file

@ -19,7 +19,7 @@ LOG_MODULE_DECLARE(net_zperf_sample, LOG_LEVEL_DBG);
static char sample_packet[PACKET_SIZE_MAX];
void zperf_tcp_upload(const struct shell *shell,
void zperf_tcp_upload(const struct shell *sh,
int sock,
unsigned int duration_in_ms,
unsigned int packet_size,
@ -31,7 +31,7 @@ void zperf_tcp_upload(const struct shell *shell,
uint32_t alloc_errors = 0U;
if (packet_size > PACKET_SIZE_MAX) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Packet size too large! max size: %u\n",
PACKET_SIZE_MAX);
packet_size = PACKET_SIZE_MAX;
@ -41,7 +41,7 @@ void zperf_tcp_upload(const struct shell *shell,
start_time = k_uptime_ticks();
last_print_time = start_time;
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"New session started\n");
(void)memset(sample_packet, 'z', sizeof(sample_packet));
@ -59,7 +59,7 @@ void zperf_tcp_upload(const struct shell *shell,
ret = send(sock, sample_packet, packet_size, 0);
if (ret < 0) {
if (nb_errors == 0 && ret != -ENOMEM) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Failed to send the packet (%d)\n",
errno);
}
@ -99,7 +99,7 @@ void zperf_tcp_upload(const struct shell *shell,
results->nb_packets_errors = nb_errors;
if (alloc_errors > 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"There was %u network buffer allocation "
"errors during send.\nConsider increasing the "
"value of CONFIG_NET_BUF_TX_COUNT and\n"

View file

@ -72,7 +72,7 @@ static inline void build_reply(struct zperf_udp_datagram *hdr,
#define BUF_SIZE sizeof(struct zperf_udp_datagram) + \
sizeof(struct zperf_server_hdr)
static int zperf_receiver_send_stat(const struct shell *shell,
static int zperf_receiver_send_stat(const struct shell *sh,
int sock, const struct sockaddr *addr,
struct zperf_udp_datagram *hdr,
struct zperf_server_hdr *stat)
@ -87,14 +87,14 @@ static int zperf_receiver_send_stat(const struct shell *shell,
sizeof(struct sockaddr_in6) :
sizeof(struct sockaddr_in));
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
" Cannot send data to peer (%d)", errno);
}
return ret;
}
static void udp_received(const struct shell *shell, int sock,
static void udp_received(const struct shell *sh, int sock,
const struct sockaddr *addr, uint8_t *data,
size_t datalen)
{
@ -105,7 +105,7 @@ static void udp_received(const struct shell *shell, int sock,
int32_t id;
if (datalen < sizeof(struct zperf_udp_datagram)) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Short iperf packet!\n");
return;
}
@ -115,7 +115,7 @@ static void udp_received(const struct shell *shell, int sock,
session = get_session(addr, SESSION_UDP);
if (!session) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Cannot get a session!\n");
return;
}
@ -129,14 +129,14 @@ static void udp_received(const struct shell *shell, int sock,
/* Session is already completed: Resend the stat packet
* and continue
*/
if (zperf_receiver_send_stat(shell, sock, addr, hdr,
if (zperf_receiver_send_stat(sh, sock, addr, hdr,
&session->stat) < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Failed to send the packet\n");
}
} else {
/* Start a new session! */
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"New session started.\n");
zperf_reset_session_stats(session);
@ -149,7 +149,7 @@ static void udp_received(const struct shell *shell, int sock,
uint32_t rate_in_kbps;
uint32_t duration;
shell_fprintf(shell, SHELL_NORMAL, "End of session!\n");
shell_fprintf(sh, SHELL_NORMAL, "End of session!\n");
duration = k_ticks_to_us_ceil32(time -
session->start_time);
@ -180,37 +180,37 @@ static void udp_received(const struct shell *shell, int sock,
session->stat.jitter1 = 0;
session->stat.jitter2 = session->jitter;
if (zperf_receiver_send_stat(shell, sock, addr, hdr,
if (zperf_receiver_send_stat(sh, sock, addr, hdr,
&session->stat) < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Failed to send the packet\n");
}
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
" duration:\t\t");
print_number(shell, duration, TIME_US, TIME_US_UNIT);
shell_fprintf(shell, SHELL_NORMAL, "\n");
print_number(sh, duration, TIME_US, TIME_US_UNIT);
shell_fprintf(sh, SHELL_NORMAL, "\n");
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
" received packets:\t%u\n",
session->counter);
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
" nb packets lost:\t%u\n",
session->outorder);
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
" nb packets outorder:\t%u\n",
session->error);
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
" jitter:\t\t\t");
print_number(shell, session->jitter, TIME_US,
print_number(sh, session->jitter, TIME_US,
TIME_US_UNIT);
shell_fprintf(shell, SHELL_NORMAL, "\n");
shell_fprintf(sh, SHELL_NORMAL, "\n");
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
" rate:\t\t\t");
print_number(shell, rate_in_kbps, KBPS, KBPS_UNIT);
shell_fprintf(shell, SHELL_NORMAL, "\n");
print_number(sh, rate_in_kbps, KBPS, KBPS_UNIT);
shell_fprintf(sh, SHELL_NORMAL, "\n");
} else {
/* Update counter */
session->counter++;
@ -258,7 +258,7 @@ void udp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
ARG_UNUSED(ptr3);
static uint8_t buf[UDP_RECEIVER_BUF_SIZE];
const struct shell *shell = ptr1;
const struct shell *sh = ptr1;
int port = POINTER_TO_INT(ptr2);
struct pollfd fds[SOCK_ID_MAX] = { 0 };
int ret;
@ -274,17 +274,17 @@ void udp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
fds[SOCK_ID_IPV4].fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (fds[SOCK_ID_IPV4].fd < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Cannot create IPv4 network socket.\n");
goto cleanup;
}
if (MY_IP4ADDR && strlen(MY_IP4ADDR)) {
/* Use setting IP */
ret = zperf_get_ipv4_addr(shell, MY_IP4ADDR,
ret = zperf_get_ipv4_addr(sh, MY_IP4ADDR,
&in4_addr_my->sin_addr);
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Unable to set IPv4\n");
goto use_existing_ipv4;
}
@ -293,7 +293,7 @@ void udp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
/* Use existing IP */
in4_addr = zperf_get_default_if_in4_addr();
if (!in4_addr) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Unable to get IPv4 by default\n");
goto cleanup;
}
@ -301,7 +301,7 @@ void udp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
sizeof(struct in_addr));
}
shell_fprintf(shell, SHELL_NORMAL, "Binding to %s\n",
shell_fprintf(sh, SHELL_NORMAL, "Binding to %s\n",
net_sprint_ipv4_addr(&in4_addr_my->sin_addr));
in4_addr_my->sin_port = htons(port);
@ -310,7 +310,7 @@ void udp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
(struct sockaddr *)in4_addr_my,
sizeof(struct sockaddr_in));
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Cannot bind IPv4 UDP port %d (%d)\n",
ntohs(in4_addr_my->sin_port),
errno);
@ -327,18 +327,18 @@ void udp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
fds[SOCK_ID_IPV6].fd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
if (fds[SOCK_ID_IPV6].fd < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Cannot create IPv4 network socket.\n");
goto cleanup;
}
if (MY_IP6ADDR && strlen(MY_IP6ADDR)) {
/* Use setting IP */
ret = zperf_get_ipv6_addr(shell, MY_IP6ADDR,
ret = zperf_get_ipv6_addr(sh, MY_IP6ADDR,
MY_PREFIX_LEN_STR,
&in6_addr_my->sin6_addr);
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Unable to set IPv6\n");
goto use_existing_ipv6;
}
@ -347,7 +347,7 @@ void udp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
/* Use existing IP */
in6_addr = zperf_get_default_if_in6_addr();
if (!in6_addr) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Unable to get IPv4 by default\n");
goto cleanup;
}
@ -355,7 +355,7 @@ void udp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
sizeof(struct in6_addr));
}
shell_fprintf(shell, SHELL_NORMAL, "Binding to %s\n",
shell_fprintf(sh, SHELL_NORMAL, "Binding to %s\n",
net_sprint_ipv6_addr(&in6_addr_my->sin6_addr));
in6_addr_my->sin6_port = htons(port);
@ -364,7 +364,7 @@ void udp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
(struct sockaddr *)in6_addr_my,
sizeof(struct sockaddr_in6));
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Cannot bind IPv6 UDP port %d (%d)\n",
ntohs(in6_addr_my->sin6_port),
ret);
@ -374,13 +374,13 @@ void udp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
fds[SOCK_ID_IPV6].events = POLLIN;
}
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Listening on port %d\n", port);
while (true) {
ret = poll(fds, ARRAY_SIZE(fds), -1);
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"UDP receiver poll error (%d)\n",
errno);
goto cleanup;
@ -393,7 +393,7 @@ void udp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
if ((fds[i].revents & POLLERR) ||
(fds[i].revents & POLLNVAL)) {
shell_fprintf(
shell, SHELL_WARNING,
sh, SHELL_WARNING,
"UDP receiver IPv%d socket error\n",
(i == SOCK_ID_IPV4) ? 4 : 6);
goto cleanup;
@ -407,13 +407,13 @@ void udp_receiver_thread(void *ptr1, void *ptr2, void *ptr3)
&addrlen);
if (ret < 0) {
shell_fprintf(
shell, SHELL_WARNING,
sh, SHELL_WARNING,
"recv failed on IPv%d socket (%d)\n",
(i == SOCK_ID_IPV4) ? 4 : 6, errno);
goto cleanup;
}
udp_received(shell, fds[i].fd, &addr, buf, ret);
udp_received(sh, fds[i].fd, &addr, buf, ret);
}
}
@ -425,13 +425,13 @@ cleanup:
}
}
void zperf_udp_receiver_init(const struct shell *shell, int port)
void zperf_udp_receiver_init(const struct shell *sh, int port)
{
k_thread_create(&udp_receiver_thread_data,
udp_receiver_stack_area,
K_THREAD_STACK_SIZEOF(udp_receiver_stack_area),
udp_receiver_thread,
(void *)shell, INT_TO_POINTER(port), NULL,
(void *)sh, INT_TO_POINTER(port), NULL,
UDP_RECEIVER_THREAD_PRIORITY,
IS_ENABLED(CONFIG_USERSPACE) ? K_USER |
K_INHERIT_PERMS : 0,

View file

@ -20,7 +20,7 @@ static uint8_t sample_packet[sizeof(struct zperf_udp_datagram) +
sizeof(struct zperf_client_hdr_v1) +
PACKET_SIZE_MAX];
static inline void zperf_upload_decode_stat(const struct shell *shell,
static inline void zperf_upload_decode_stat(const struct shell *sh,
const uint8_t *data,
size_t datalen,
struct zperf_results *results)
@ -29,7 +29,7 @@ static inline void zperf_upload_decode_stat(const struct shell *shell,
if (datalen < sizeof(struct zperf_udp_datagram) +
sizeof(struct zperf_server_hdr)) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Network packet too short\n");
}
@ -47,7 +47,7 @@ static inline void zperf_upload_decode_stat(const struct shell *shell,
ntohl(UNALIGNED_GET(&stat->jitter1)) * USEC_PER_SEC;
}
static inline void zperf_upload_fin(const struct shell *shell,
static inline void zperf_upload_fin(const struct shell *sh,
int sock,
uint32_t nb_packets,
uint64_t end_time,
@ -94,7 +94,7 @@ static inline void zperf_upload_fin(const struct shell *shell,
/* Send the packet */
ret = send(sock, sample_packet, packet_size, 0);
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Failed to send the packet (%d)\n",
errno);
continue;
@ -104,7 +104,7 @@ static inline void zperf_upload_fin(const struct shell *shell,
ret = setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &rcvtimeo,
sizeof(rcvtimeo));
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"setsockopt error (%d)\n",
errno);
continue;
@ -112,10 +112,10 @@ static inline void zperf_upload_fin(const struct shell *shell,
ret = recv(sock, stats, sizeof(stats), 0);
if (ret == -EAGAIN) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Stats receive timeout\n");
} else if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Failed to receive packet (%d)\n",
errno);
}
@ -123,7 +123,7 @@ static inline void zperf_upload_fin(const struct shell *shell,
/* Decode statistics */
if (ret > 0) {
zperf_upload_decode_stat(shell, stats, ret, results);
zperf_upload_decode_stat(sh, stats, ret, results);
}
/* Drain RX */
@ -133,12 +133,12 @@ static inline void zperf_upload_fin(const struct shell *shell,
break;
}
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Drain one spurious stat packet!\n");
}
}
void zperf_udp_upload(const struct shell *shell,
void zperf_udp_upload(const struct shell *sh,
int sock,
int port,
unsigned int duration_in_ms,
@ -157,23 +157,23 @@ void zperf_udp_upload(const struct shell *shell,
int64_t remaining, print_info;
if (packet_size > PACKET_SIZE_MAX) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Packet size too large! max size: %u\n",
PACKET_SIZE_MAX);
packet_size = PACKET_SIZE_MAX;
} else if (packet_size < sizeof(struct zperf_udp_datagram)) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Packet size set to the min size: %zu\n",
sizeof(struct zperf_udp_datagram));
packet_size = sizeof(struct zperf_udp_datagram);
}
if (packet_duration > 1000U) {
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Packet duration %u ms\n",
(unsigned int)(packet_duration / 1000U));
} else {
shell_fprintf(shell, SHELL_NORMAL,
shell_fprintf(sh, SHELL_NORMAL,
"Packet duration %u us\n",
(unsigned int)packet_duration);
}
@ -240,7 +240,7 @@ void zperf_udp_upload(const struct shell *shell,
/* Send the packet */
ret = send(sock, sample_packet, packet_size, 0);
if (ret < 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"Failed to send the packet (%d)\n",
errno);
break;
@ -251,7 +251,7 @@ void zperf_udp_upload(const struct shell *shell,
/* Print log every seconds */
print_info = print_interval - k_uptime_ticks();
if (print_info <= 0) {
shell_fprintf(shell, SHELL_WARNING,
shell_fprintf(sh, SHELL_WARNING,
"nb_packets=%u\tdelay=%u\tadjust=%d\n",
nb_packets, (unsigned int)delay,
(int)adjust);
@ -276,7 +276,7 @@ void zperf_udp_upload(const struct shell *shell,
end_time = k_uptime_ticks();
zperf_upload_fin(shell, sock, nb_packets, end_time, packet_size,
zperf_upload_fin(sh, sock, nb_packets, end_time, packet_size,
results);
/* Add result coming from the client */