From d850fff673f0a1a2b9c2c91d8330bdbb4c32ea90 Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 23 Nov 2018 09:55:52 +0100 Subject: [PATCH 1/3] Make it possible to use shell without IPv6 --- os/services/shell/shell-commands.c | 19 +++++++++++++++++-- os/services/shell/shell.c | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/os/services/shell/shell-commands.c b/os/services/shell/shell-commands.c index c8b7d862e..331d674de 100644 --- a/os/services/shell/shell-commands.c +++ b/os/services/shell/shell-commands.c @@ -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,7 @@ ds6_nbr_state_to_str(uint8_t state) return "Unknown"; } } +#endif /* NETSTACK_CONF_WITH_IPV6 */ #if ROUTING_CONF_RPL_LITE /*---------------------------------------------------------------------------*/ static const char * @@ -219,6 +223,7 @@ PT_THREAD(cmd_rpl_status(struct pt *pt, shell_output_func output, char *args)) PT_END(pt); } #endif /* ROUTING_CONF_RPL_LITE */ +#if NETSTACK_CONF_WITH_IPV6 /*---------------------------------------------------------------------------*/ static void echo_reply_handler(uip_ipaddr_t *source, uint8_t ttl, uint8_t *data, uint16_t datalen) @@ -275,6 +280,7 @@ PT_THREAD(cmd_ping(struct pt *pt, shell_output_func output, char *args)) PT_END(pt); } +#endif /* NETSTACK_CONF_WITH_IPV6 */ /*---------------------------------------------------------------------------*/ static void shell_output_log_levels(shell_output_func output) @@ -457,6 +463,7 @@ PT_THREAD(cmd_rpl_refresh_routes(struct pt *pt, shell_output_func output, char * } #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 +485,6 @@ PT_THREAD(cmd_ipaddr(struct pt *pt, shell_output_func output, char *args)) } PT_END(pt); - } /*---------------------------------------------------------------------------*/ static @@ -509,6 +515,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 @@ -591,6 +598,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)) @@ -656,6 +664,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)) @@ -804,9 +813,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 @@ -846,10 +857,12 @@ 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." }, +#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'" }, +#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" }, @@ -862,7 +875,9 @@ const struct shell_command_t builtin_shell_commands[] = { { "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 */ +#if NETSTACK_CONF_WITH_IPV6 { "routes", cmd_routes, "'> routes': Shows the route entries" }, +#endif /* NETSTACK_CONF_WITH_IPV6 */ #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" }, diff --git a/os/services/shell/shell.c b/os/services/shell/shell.c index 5347080a8..f5383ee5f 100644 --- a/os/services/shell/shell.c +++ b/os/services/shell/shell.c @@ -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) From 36ee548b51b9606041d5b7416a54b9ca3f560cfe Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 23 Nov 2018 09:56:02 +0100 Subject: [PATCH 2/3] Shell: add mac-addr command --- os/services/shell/shell-commands.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/os/services/shell/shell-commands.c b/os/services/shell/shell-commands.c index 331d674de..512c60b6f 100644 --- a/os/services/shell/shell-commands.c +++ b/os/services/shell/shell-commands.c @@ -463,6 +463,18 @@ PT_THREAD(cmd_rpl_refresh_routes(struct pt *pt, shell_output_func output, char * } #endif /* ROUTING_CONF_RPL_LITE */ #endif /* UIP_CONF_IPV6_RPL */ +/*---------------------------------------------------------------------------*/ +static +PT_THREAD(cmd_macaddr(struct pt *pt, shell_output_func output, char *args)) +{ + PT_BEGIN(pt); + + SHELL_OUTPUT(output, "Node MAC address: "); + shell_output_lladdr(output, &linkaddr_node_addr); + SHELL_OUTPUT(output, "\n"); + + PT_END(pt); +} #if NETSTACK_CONF_WITH_IPV6 /*---------------------------------------------------------------------------*/ static @@ -858,6 +870,7 @@ 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" }, From 5c206691a3e3967721def08e9b6a23eb27f1188b Mon Sep 17 00:00:00 2001 From: Simon Duquennoy Date: Fri, 11 Jan 2019 21:22:16 +0100 Subject: [PATCH 3/3] Shell: group IPv6 and RPL-Lite commands --- os/services/shell/shell-commands.c | 135 ++++++++++++++--------------- 1 file changed, 64 insertions(+), 71 deletions(-) diff --git a/os/services/shell/shell-commands.c b/os/services/shell/shell-commands.c index 512c60b6f..c5bffe619 100644 --- a/os/services/shell/shell-commands.c +++ b/os/services/shell/shell-commands.c @@ -104,7 +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 * @@ -222,65 +279,18 @@ PT_THREAD(cmd_rpl_status(struct pt *pt, shell_output_func output, char *args)) PT_END(pt); } -#endif /* ROUTING_CONF_RPL_LITE */ -#if NETSTACK_CONF_WITH_IPV6 -/*---------------------------------------------------------------------------*/ -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 /* NETSTACK_CONF_WITH_IPV6 */ +#endif /* ROUTING_CONF_RPL_LITE */ /*---------------------------------------------------------------------------*/ static void shell_output_log_levels(shell_output_func output) @@ -449,19 +459,6 @@ PT_THREAD(cmd_rpl_local_repair(struct pt *pt, shell_output_func output, char *ar PT_END(pt); } -/*---------------------------------------------------------------------------*/ -#if ROUTING_CONF_RPL_LITE -static -PT_THREAD(cmd_rpl_refresh_routes(struct pt *pt, shell_output_func output, char *args)) -{ - PT_BEGIN(pt); - - SHELL_OUTPUT(output, "Triggering routes refresh\n"); - rpl_refresh_routes("Shell"); - - PT_END(pt); -} -#endif /* ROUTING_CONF_RPL_LITE */ #endif /* UIP_CONF_IPV6_RPL */ /*---------------------------------------------------------------------------*/ static @@ -875,22 +872,18 @@ const struct shell_command_t builtin_shell_commands[] = { { "ip-addr", cmd_ipaddr, "'> ip-addr': Shows all IPv6 addresses" }, { "ip-nbr", cmd_ip_neighbors, "'> ip-nbr': Shows all IPv6 neighbors" }, { "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 */ -#if NETSTACK_CONF_WITH_IPV6 - { "routes", cmd_routes, "'> routes': Shows the route entries" }, -#endif /* NETSTACK_CONF_WITH_IPV6 */ + { "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" },