Merge branch 'develop' into fix-header-processing

This commit is contained in:
Joakim Eriksson 2019-01-14 13:42:22 +01:00 committed by GitHub
commit 67b62025a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 62 deletions

View File

@ -72,16 +72,19 @@
#define PING_TIMEOUT (5 * CLOCK_SECOND)
#if NETSTACK_CONF_WITH_IPV6
static struct uip_icmp6_echo_reply_notification echo_reply_notification;
static shell_output_func *curr_ping_output_func = NULL;
static struct process *curr_ping_process;
static uint8_t curr_ping_ttl;
static uint16_t curr_ping_datalen;
#endif /* NETSTACK_CONF_WITH_IPV6 */
#if TSCH_WITH_SIXTOP
static shell_command_6top_sub_cmd_t sixtop_sub_cmd = NULL;
#endif /* TSCH_WITH_SIXTOP */
static struct shell_command_set_t builtin_shell_command_set;
LIST(shell_command_sets);
#if NETSTACK_CONF_WITH_IPV6
/*---------------------------------------------------------------------------*/
static const char *
ds6_nbr_state_to_str(uint8_t state)
@ -101,6 +104,64 @@ ds6_nbr_state_to_str(uint8_t state)
return "Unknown";
}
}
/*---------------------------------------------------------------------------*/
static void
echo_reply_handler(uip_ipaddr_t *source, uint8_t ttl, uint8_t *data, uint16_t datalen)
{
if(curr_ping_output_func != NULL) {
curr_ping_output_func = NULL;
curr_ping_ttl = ttl;
curr_ping_datalen = datalen;
process_poll(curr_ping_process);
}
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(cmd_ping(struct pt *pt, shell_output_func output, char *args))
{
static uip_ipaddr_t remote_addr;
static struct etimer timeout_timer;
char *next_args;
PT_BEGIN(pt);
SHELL_ARGS_INIT(args, next_args);
/* Get argument (remote IPv6) */
SHELL_ARGS_NEXT(args, next_args);
if(args == NULL) {
SHELL_OUTPUT(output, "Destination IPv6 address is not specified\n");
PT_EXIT(pt);
} else if(uiplib_ipaddrconv(args, &remote_addr) == 0) {
SHELL_OUTPUT(output, "Invalid IPv6 address: %s\n", args);
PT_EXIT(pt);
}
SHELL_OUTPUT(output, "Pinging ");
shell_output_6addr(output, &remote_addr);
SHELL_OUTPUT(output, "\n");
/* Send ping request */
curr_ping_process = PROCESS_CURRENT();
curr_ping_output_func = output;
etimer_set(&timeout_timer, PING_TIMEOUT);
uip_icmp6_send(&remote_addr, ICMP6_ECHO_REQUEST, 0, 4);
PT_WAIT_UNTIL(pt, curr_ping_output_func == NULL || etimer_expired(&timeout_timer));
if(curr_ping_output_func != NULL) {
SHELL_OUTPUT(output, "Timeout\n");
curr_ping_output_func = NULL;
} else {
SHELL_OUTPUT(output, "Received ping reply from ");
shell_output_6addr(output, &remote_addr);
SHELL_OUTPUT(output, ", len %u, ttl %u, delay %lu ms\n",
curr_ping_datalen, curr_ping_ttl, (1000*(clock_time() - timeout_timer.timer.start))/CLOCK_SECOND);
}
PT_END(pt);
}
#endif /* NETSTACK_CONF_WITH_IPV6 */
#if ROUTING_CONF_RPL_LITE
/*---------------------------------------------------------------------------*/
static const char *
@ -218,63 +279,18 @@ PT_THREAD(cmd_rpl_status(struct pt *pt, shell_output_func output, char *args))
PT_END(pt);
}
#endif /* ROUTING_CONF_RPL_LITE */
/*---------------------------------------------------------------------------*/
static void
echo_reply_handler(uip_ipaddr_t *source, uint8_t ttl, uint8_t *data, uint16_t datalen)
{
if(curr_ping_output_func != NULL) {
curr_ping_output_func = NULL;
curr_ping_ttl = ttl;
curr_ping_datalen = datalen;
process_poll(curr_ping_process);
}
}
/*---------------------------------------------------------------------------*/
static
PT_THREAD(cmd_ping(struct pt *pt, shell_output_func output, char *args))
PT_THREAD(cmd_rpl_refresh_routes(struct pt *pt, shell_output_func output, char *args))
{
static uip_ipaddr_t remote_addr;
static struct etimer timeout_timer;
char *next_args;
PT_BEGIN(pt);
SHELL_ARGS_INIT(args, next_args);
/* Get argument (remote IPv6) */
SHELL_ARGS_NEXT(args, next_args);
if(args == NULL) {
SHELL_OUTPUT(output, "Destination IPv6 address is not specified\n");
PT_EXIT(pt);
} else if(uiplib_ipaddrconv(args, &remote_addr) == 0) {
SHELL_OUTPUT(output, "Invalid IPv6 address: %s\n", args);
PT_EXIT(pt);
}
SHELL_OUTPUT(output, "Pinging ");
shell_output_6addr(output, &remote_addr);
SHELL_OUTPUT(output, "\n");
/* Send ping request */
curr_ping_process = PROCESS_CURRENT();
curr_ping_output_func = output;
etimer_set(&timeout_timer, PING_TIMEOUT);
uip_icmp6_send(&remote_addr, ICMP6_ECHO_REQUEST, 0, 4);
PT_WAIT_UNTIL(pt, curr_ping_output_func == NULL || etimer_expired(&timeout_timer));
if(curr_ping_output_func != NULL) {
SHELL_OUTPUT(output, "Timeout\n");
curr_ping_output_func = NULL;
} else {
SHELL_OUTPUT(output, "Received ping reply from ");
shell_output_6addr(output, &remote_addr);
SHELL_OUTPUT(output, ", len %u, ttl %u, delay %lu ms\n",
curr_ping_datalen, curr_ping_ttl, (1000*(clock_time() - timeout_timer.timer.start))/CLOCK_SECOND);
}
SHELL_OUTPUT(output, "Triggering routes refresh\n");
rpl_refresh_routes("Shell");
PT_END(pt);
}
#endif /* ROUTING_CONF_RPL_LITE */
/*---------------------------------------------------------------------------*/
static void
shell_output_log_levels(shell_output_func output)
@ -443,20 +459,20 @@ PT_THREAD(cmd_rpl_local_repair(struct pt *pt, shell_output_func output, char *ar
PT_END(pt);
}
#endif /* UIP_CONF_IPV6_RPL */
/*---------------------------------------------------------------------------*/
#if ROUTING_CONF_RPL_LITE
static
PT_THREAD(cmd_rpl_refresh_routes(struct pt *pt, shell_output_func output, char *args))
PT_THREAD(cmd_macaddr(struct pt *pt, shell_output_func output, char *args))
{
PT_BEGIN(pt);
SHELL_OUTPUT(output, "Triggering routes refresh\n");
rpl_refresh_routes("Shell");
SHELL_OUTPUT(output, "Node MAC address: ");
shell_output_lladdr(output, &linkaddr_node_addr);
SHELL_OUTPUT(output, "\n");
PT_END(pt);
}
#endif /* ROUTING_CONF_RPL_LITE */
#endif /* UIP_CONF_IPV6_RPL */
#if NETSTACK_CONF_WITH_IPV6
/*---------------------------------------------------------------------------*/
static
PT_THREAD(cmd_ipaddr(struct pt *pt, shell_output_func output, char *args))
@ -478,7 +494,6 @@ PT_THREAD(cmd_ipaddr(struct pt *pt, shell_output_func output, char *args))
}
PT_END(pt);
}
/*---------------------------------------------------------------------------*/
static
@ -509,6 +524,7 @@ PT_THREAD(cmd_ip_neighbors(struct pt *pt, shell_output_func output, char *args))
PT_END(pt);
}
#endif /* NETSTACK_CONF_WITH_IPV6 */
#if MAC_CONF_WITH_TSCH
/*---------------------------------------------------------------------------*/
static
@ -595,6 +611,7 @@ PT_THREAD(cmd_tsch_status(struct pt *pt, shell_output_func output, char *args))
PT_END(pt);
}
#endif /* MAC_CONF_WITH_TSCH */
#if NETSTACK_CONF_WITH_IPV6
/*---------------------------------------------------------------------------*/
static
PT_THREAD(cmd_routes(struct pt *pt, shell_output_func output, char *args))
@ -660,6 +677,7 @@ PT_THREAD(cmd_routes(struct pt *pt, shell_output_func output, char *args))
PT_END(pt);
}
#endif /* NETSTACK_CONF_WITH_IPV6 */
/*---------------------------------------------------------------------------*/
static
PT_THREAD(cmd_reboot(struct pt *pt, shell_output_func output, char *args))
@ -808,9 +826,11 @@ shell_commands_init(void)
{
list_init(shell_command_sets);
list_add(shell_command_sets, &builtin_shell_command_set);
#if NETSTACK_CONF_WITH_IPV6
/* Set up Ping Reply callback */
uip_icmp6_echo_reply_callback_add(&echo_reply_notification,
echo_reply_handler);
#endif /* NETSTACK_CONF_WITH_IPV6 */
}
/*---------------------------------------------------------------------------*/
void
@ -850,23 +870,24 @@ shell_command_lookup(const char *name)
const struct shell_command_t builtin_shell_commands[] = {
{ "help", cmd_help, "'> help': Shows this help" },
{ "reboot", cmd_reboot, "'> reboot': Reboot the board by watchdog_reboot()" },
{ "log", cmd_log, "'> log module level': Sets log level (0--4) for a given module (or \"all\"). For module \"mac\", level 4 also enables per-slot logging." },
{ "mac-addr", cmd_macaddr, "'> mac-addr': Shows the node's MAC address" },
#if NETSTACK_CONF_WITH_IPV6
{ "ip-addr", cmd_ipaddr, "'> ip-addr': Shows all IPv6 addresses" },
{ "ip-nbr", cmd_ip_neighbors, "'> ip-nbr': Shows all IPv6 neighbors" },
{ "log", cmd_log, "'> log module level': Sets log level (0--4) for a given module (or \"all\"). For module \"mac\", level 4 also enables per-slot logging." },
{ "ping", cmd_ping, "'> ping addr': Pings the IPv6 address 'addr'" },
{ "routes", cmd_routes, "'> routes': Shows the route entries" },
#endif /* NETSTACK_CONF_WITH_IPV6 */
#if UIP_CONF_IPV6_RPL
{ "rpl-set-root", cmd_rpl_set_root, "'> rpl-set-root 0/1 [prefix]': Sets node as root (1) or not (0). A /64 prefix can be optionally specified." },
{ "rpl-local-repair", cmd_rpl_local_repair, "'> rpl-local-repair': Triggers a RPL local repair" },
#if ROUTING_CONF_RPL_LITE
{ "rpl-refresh-routes", cmd_rpl_refresh_routes, "'> rpl-refresh-routes': Refreshes all routes through a DTSN increment" },
#endif /* ROUTING_CONF_RPL_LITE */
{ "rpl-global-repair", cmd_rpl_global_repair, "'> rpl-global-repair': Triggers a RPL global repair" },
#endif /* UIP_CONF_IPV6_RPL */
#if ROUTING_CONF_RPL_LITE
{ "rpl-status", cmd_rpl_status, "'> rpl-status': Shows a summary of the current RPL state" },
{ "rpl-nbr", cmd_rpl_nbr, "'> rpl-nbr': Shows the RPL neighbor table" },
#endif /* ROUTING_CONF_RPL_LITE */
{ "routes", cmd_routes, "'> routes': Shows the route entries" },
{ "rpl-global-repair", cmd_rpl_global_repair, "'> rpl-global-repair': Triggers a RPL global repair" },
#endif /* UIP_CONF_IPV6_RPL */
#if MAC_CONF_WITH_TSCH
{ "tsch-set-coordinator", cmd_tsch_set_coordinator, "'> tsch-set-coordinator 0/1 [0/1]': Sets node as coordinator (1) or not (0). Second, optional parameter: enable (1) or disable (0) security." },
{ "tsch-schedule", cmd_tsch_schedule, "'> tsch-schedule': Shows the current TSCH schedule" },

View File

@ -52,6 +52,7 @@
#include "net/ipv6/ip64-addr.h"
#include "net/ipv6/uiplib.h"
#if NETSTACK_CONF_WITH_IPV6
/*---------------------------------------------------------------------------*/
void
shell_output_6addr(shell_output_func output, const uip_ipaddr_t *ipaddr)
@ -60,6 +61,7 @@ shell_output_6addr(shell_output_func output, const uip_ipaddr_t *ipaddr)
uiplib_ipaddr_snprint(buf, sizeof(buf), ipaddr);
SHELL_OUTPUT(output, "%s", buf);
}
#endif /* NETSTACK_CONF_WITH_IPV6 */
/*---------------------------------------------------------------------------*/
void
shell_output_lladdr(shell_output_func output, const linkaddr_t *lladdr)