Commit 98cebc4c authored by Adam Wujek's avatar Adam Wujek 💬

lib/netconsole: add command to configure netconsole

add CMD_NETCONSOLE
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 76980ba4
......@@ -386,6 +386,13 @@ config NETCONSOLE
help
Include netconsole to be run via UDP
config CMD_NETCONSOLE
depends on NETCONSOLE
boolean "Include command to configure netconsole"
default y
help
Include command to configure netconsole
#
# This is a set of configuration options that should not be changed by
# normal users. If the "developer" menu is used, the binary is tainted.
......
......@@ -1918,6 +1918,17 @@ tools used to build and run it, you can write to our mailing list
clock (requires external 10MHz and 1-PPS reference), Master or Slave.
After setting the mode, \texttt{ptp start} must be re-issued \\
\code{netconsole} & prints peer's MAC, IP and port number used by
the netconsole \\
\code{netconsole <MAC> <IP> <PORT>} & sets peer's MAC, IP and port number for
the netconsole \\
\code{netconsole off} & turn off the netconsole, will be turned on again when
next netconsole's packet arrives to WRPC \\
\code{netconsole disable} & disable netconsole until enabled manually \\
\code{pll cl <channel>} & checks if SoftPLL is locked for the channel \\
\code{pll gdac <index>} & gets dac's value \\
......
......@@ -6,10 +6,21 @@
#ifndef __NETCONSOLE_H__
#define __NETCONSOLE_H__
#define NETCONSOLE_ENABLED 0
#define NETCONSOLE_DISABLED 1
#define NETCONSOLE_OFF 2
#define NETCONSOLE_PORT 55
extern struct wr_sockaddr netconsole_sock_addr;
extern int netconsole_status;
extern struct wr_udp_addr netconsole_udp_addr;
void netconsole_init(void);
int netconsole_poll(void);
int netconsole_read_byte(void);
int netconsole_write_string(const char *s);
#endif /* __NETCONSOLE_H__ */
......@@ -27,7 +27,7 @@ static unsigned char *cmd_rx_p = NULL;
static uint8_t tx_buf[UDP_END + SH_MAX_LINE_LEN + 1];
static uint8_t rx_buf[UDP_END + SH_MAX_LINE_LEN + 1];
struct wr_sockaddr netconsole_sock_addr;
static int netconsole_has_peer = 0;
int netconsole_status = NETCONSOLE_OFF;
struct wr_udp_addr netconsole_udp_addr;
......@@ -35,8 +35,7 @@ void netconsole_init(void)
{
netconsole_socket = ptpd_netif_create_socket(
&__static_netconsole_socket, NULL,
PTPD_SOCK_UDP, 55);
/* TODO: find a better port number */
PTPD_SOCK_UDP, NETCONSOLE_PORT);
}
int netconsole_read_byte(void)
......@@ -54,13 +53,13 @@ int netconsole_write_string(const char *s)
const uint8_t *p;
static uint8_t *d = NULL;
if (!netconsole_has_peer)
if (netconsole_status != NETCONSOLE_ENABLED)
return 0;
/* Prevent recursive calls when net verbose configured.
* NOTE: Even with the following if, NET_IS_VERBOSE does not work
* with netconsole */
if (NET_IS_VERBOSE)
netconsole_has_peer = 0;
netconsole_status = NETCONSOLE_DISABLED;
p = (uint8_t *)s;
while (1) {
if (!d) {
......@@ -75,6 +74,8 @@ int netconsole_write_string(const char *s)
len++;
if (*d == '\n' || len == SH_MAX_LINE_LEN) {
len += UDP_END;
netconsole_udp_addr.sport = htons(NETCONSOLE_PORT);
getIP((void *)&netconsole_udp_addr.saddr);
fill_udp((uint8_t *)tx_buf, len, &netconsole_udp_addr);
ptpd_netif_sendto(netconsole_socket,
&netconsole_sock_addr, tx_buf, len,
......@@ -89,7 +90,7 @@ int netconsole_write_string(const char *s)
}
if (NET_IS_VERBOSE)
netconsole_has_peer = 1;
netconsole_status = NETCONSOLE_ENABLED;
return 0;
}
......@@ -98,8 +99,12 @@ int netconsole_poll(void)
{
int len;
if (ip_status == IP_TRAINING)
return 0; /* can't do netconsole w/o an address... */
if (ip_status == IP_TRAINING
|| netconsole_status == NETCONSOLE_DISABLED) {
/* can't do netconsole w/o an address...
* or netconsole disabled */
return 0;
}
if ((len = ptpd_netif_recvfrom(netconsole_socket,
&netconsole_sock_addr, rx_buf,
......@@ -112,15 +117,13 @@ int netconsole_poll(void)
rx_buf[len] = 0;
/* copy source and destination address */
/* copy peer's IP address and port */
memcpy(&netconsole_udp_addr.daddr, rx_buf + IP_SOURCE, 4);
memcpy(&netconsole_udp_addr.saddr, rx_buf + IP_DEST, 4);
memcpy(&netconsole_udp_addr.dport, rx_buf + UDP_SPORT, 2);
memcpy(&netconsole_udp_addr.sport, rx_buf + UDP_DPORT, 2);
cmd_rx_p = &rx_buf[UDP_END];
netconsole_has_peer = 1;
netconsole_status = NETCONSOLE_ENABLED;
return 1;
}
......
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2012 GSI (www.gsi.de)
* Author: Wesley W. Terpstra <w.terpstra@gsi.de>
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <wrc.h>
#include <lib/ipv4.h>
#include <netconsole.h>
#include <shell.h>
static void print_netconsole_status(void) {
char buf[20];
/* print netconsole's status */
switch (netconsole_status) {
case NETCONSOLE_ENABLED:
/* Print peer's MAC and IP */
pp_printf("netconsole's peer: ");
format_mac(buf, (void *)&netconsole_sock_addr.mac);
pp_printf("MAC: %s ", buf);
format_ip(buf, (void *)&netconsole_udp_addr.daddr);
pp_printf("IP: %s ", buf);
pp_printf("port: %d\n", netconsole_udp_addr.dport);
break;
case NETCONSOLE_OFF:
pp_printf("netconsole turned off\n");
break;
case NETCONSOLE_DISABLED:
pp_printf("netconsole disabled\n");
break;
default:
break;
}
}
static int cmd_netconsole(const char *args[])
{
if (!args[0]) {
/* do nothing here, later print status */
} else if (!strcasecmp(args[0], "off")) {
/* Disable netconsole */
netconsole_status = NETCONSOLE_OFF;
} else if (!strcasecmp(args[0], "disable")) {
/* Disable permanently netconsole */
netconsole_status = NETCONSOLE_DISABLED;
} else if (args[0] && args[1] && args[2]) {
/* Set MAC and IP for netconsole peer */
decode_mac(args[0], (void *)&netconsole_sock_addr.mac);
decode_ip(args[1], (void *)&netconsole_udp_addr.daddr);
netconsole_udp_addr.dport = atoi(args[2]);
netconsole_status = NETCONSOLE_ENABLED;
} else {
pp_printf("uage: netconsole off | disable | "
"<MAC> <IP> <port> \n");
return -EINVAL;
}
print_netconsole_status();
return 0;
}
DEFINE_WRC_COMMAND(netconsole) = {
.name = "netconsole",
.exec = cmd_netconsole,
};
......@@ -51,6 +51,14 @@
#define HAS_CMD_LEAPSEC 0
#endif
#ifdef CONFIG_CMD_NETCONSOLE
#define HAS_CMD_NETCONSOLE 1
#else
#define HAS_CMD_NETCONSOLE 0
#endif
static char cmd_buf[SH_MAX_LINE_LEN + 1];
static int cmd_pos = 0, cmd_len = 0;
......@@ -393,4 +401,6 @@ void shell_register_commands(void)
REGISTER_WRC_COMMAND(pps);
if (HAS_CMD_LEAPSEC)
REGISTER_WRC_COMMAND(leapsec);
if (HAS_CMD_NETCONSOLE)
REGISTER_WRC_COMMAND(netconsole);
}
......@@ -24,6 +24,7 @@ obj-$(CONFIG_IP) += shell/cmd_ip.o
obj-$(CONFIG_PPSI) += shell/cmd_verbose.o
obj-$(CONFIG_CMD_CONFIG) += shell/cmd_config.o
obj-$(CONFIG_CMD_SLEEP) += shell/cmd_sleep.o
obj-$(CONFIG_CMD_NETCONSOLE) += shell/cmd_netconsole.o
obj-$(CONFIG_CMD_LL) += shell/cmd_ll.o
obj-$(CONFIG_CMD_PPS) += shell/cmd_pps.o
obj-$(CONFIG_CMD_LEAPSEC) += shell/cmd_leapsec.o
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment