From 89eeb7eba75856ba1b0bc85fa45dc6207adfb0ac Mon Sep 17 00:00:00 2001 From: luisan00 Date: Fri, 23 Sep 2022 13:29:23 +0200 Subject: [PATCH 1/3] firmware/sys/shell_extended: Add net_tools cmds --- examples/shell_extended/Makefile | 2 + firmware/sys/shell_extended/Makefile | 4 ++ firmware/sys/shell_extended/se_net_tools.c | 48 ++++++++++++++++++++ firmware/sys/shell_extended/shell_extended.c | 9 ++++ 4 files changed, 63 insertions(+) create mode 100644 firmware/sys/shell_extended/se_net_tools.c diff --git a/examples/shell_extended/Makefile b/examples/shell_extended/Makefile index 8b146f979..a6cffe5d5 100644 --- a/examples/shell_extended/Makefile +++ b/examples/shell_extended/Makefile @@ -5,7 +5,9 @@ include ../Makefile.common # Include the shell extended module, shell and shell commands modules # will be implicitly included. USEMODULE += shell_extended + # Include desired modules where shell extended is enabled. USEMODULE += uniqueid +USEMODULE += net_tools include $(RIOTBASE)/Makefile.include diff --git a/firmware/sys/shell_extended/Makefile b/firmware/sys/shell_extended/Makefile index baa9472a8..cbe246fd6 100644 --- a/firmware/sys/shell_extended/Makefile +++ b/firmware/sys/shell_extended/Makefile @@ -6,4 +6,8 @@ ifneq (,$(filter uniqueid,$(USEMODULE))) SRC += se_uniqueid.c endif +ifneq (,$(filter net_tools,$(USEMODULE))) + SRC += se_net_tools.c +endif + include $(RIOTBASE)/Makefile.base diff --git a/firmware/sys/shell_extended/se_net_tools.c b/firmware/sys/shell_extended/se_net_tools.c new file mode 100644 index 000000000..4ad5f9331 --- /dev/null +++ b/firmware/sys/shell_extended/se_net_tools.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 Mesh4all + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @brief Extends the shell functionality for uniqueid + * @author Luis A. Ruiz + * @author Eduardo Azócar + */ + +#include +#include +#include "net_tools.h" + +void net_tools_usage(void) { + puts("net-tools usage:"); + puts("\t ToDo: list-of-commands"); + puts("\t ToDo: example-of-use"); + puts(""); +} + +int net_tools_cmd(int argc, char **argv) { + (void)argc; + (void)argv; + + if ((argc < 2) || (argc > 2)) { + puts("net-tools command needs at least one argument"); + net_tools_usage(); + return 1; + } + + if ((strcmp(argv[1], "help") == 0)) { + net_tools_usage(); + return 0; + } + return 0; +} diff --git a/firmware/sys/shell_extended/shell_extended.c b/firmware/sys/shell_extended/shell_extended.c index cb4e872b9..ba8ea906a 100644 --- a/firmware/sys/shell_extended/shell_extended.c +++ b/firmware/sys/shell_extended/shell_extended.c @@ -22,11 +22,20 @@ #include "shell_extended.h" #include "kernel_defines.h" +/* important: please keep the used modules alphabetically sorted */ +#if IS_USED(MODULE_NET_TOOLS) +int net_tools_cmd(int argc, char **argv); +#endif + #if IS_USED(MODULE_UNIQUEID) int uid_cmd(int argc, char **argv); #endif const shell_command_t shell_extended_commands[] = { +/* important: please keep the used modules alphabetically sorted */ +#if IS_USED(MODULE_NET_TOOLS) + {"net_tools", "net_tools commands", net_tools_cmd}, +#endif #if IS_USED(MODULE_UNIQUEID) {"uid", "uniqueid commands", uid_cmd}, #endif From 9a35cf1ccdee9919b56990e04ea0e8eaa6005d34 Mon Sep 17 00:00:00 2001 From: eduazocar Date: Mon, 26 Sep 2022 17:19:40 -0400 Subject: [PATCH 2/3] firmware/sys/shell_extended: Added net_tools functionalities --- examples/shell_extended/Kconfig | 1 + firmware/sys/shell_extended/se_net_tools.c | 75 ++++++++++++++++++-- firmware/sys/shell_extended/shell_extended.c | 2 +- 3 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 examples/shell_extended/Kconfig diff --git a/examples/shell_extended/Kconfig b/examples/shell_extended/Kconfig new file mode 100644 index 000000000..740600b7a --- /dev/null +++ b/examples/shell_extended/Kconfig @@ -0,0 +1 @@ +rsource "../../firmware/sys/Kconfig" diff --git a/firmware/sys/shell_extended/se_net_tools.c b/firmware/sys/shell_extended/se_net_tools.c index 4ad5f9331..ab7f9929e 100644 --- a/firmware/sys/shell_extended/se_net_tools.c +++ b/firmware/sys/shell_extended/se_net_tools.c @@ -22,11 +22,23 @@ #include #include #include "net_tools.h" +#if MODULE_UNIQUEID +#include "uniqueid.h" +#endif + +#define ENABLE_DEBUG 0 +#include "debug.h" + +void check_inp_addr(char *addr, ipv6_addr_t *ip, uint8_t *pfx); void net_tools_usage(void) { puts("net-tools usage:"); - puts("\t ToDo: list-of-commands"); - puts("\t ToDo: example-of-use"); + puts("\tlist-of-commands"); + puts("\t if [iface id] [add]"); + puts("\t\t\t -[ipv6 unicast addr/network prefix length]"); +#if MODULE_UNIQUEID + puts("\t\t\t -[ipuid] [header/prefix] [static|random]"); +#endif puts(""); } @@ -34,15 +46,64 @@ int net_tools_cmd(int argc, char **argv) { (void)argc; (void)argv; - if ((argc < 2) || (argc > 2)) { - puts("net-tools command needs at least one argument"); + if ((strcmp(argv[1], "help") == 0)) { net_tools_usage(); - return 1; + return 0; + } + if ((strcmp(argv[2], "add") == 0)) { + int if_idx = atoi(argv[1]); + char ip[40] = ""; + ipv6_addr_t addr; + uint8_t prefix; + if ((netif_get_by_id(if_idx)) == NULL) { + puts("Interface doesn't exist"); + return -1; + } +#if MODULE_UNIQUEID + if (strcmp(argv[3], "ipuid") == 0) { + check_inp_addr(argv[4], &addr, &prefix); + if ((strcmp(argv[5], "static") == 0)) { + set_ipv6_by_uid(if_idx, &addr, prefix, UNIQUEID_STATIC_MODE); + DEBUG("ipv6 address: %s\n", ipv6_addr_to_str(ip, &addr, sizeof(ip))); + return 0; + } + if ((strcmp(argv[5], "random") == 0)) { + set_ipv6_by_uid(if_idx, &addr, prefix, UNIQUEID_RANDOM_MODE); + DEBUG("ipv6 address: %s\n", ipv6_addr_to_str(ip, &addr, sizeof(ip))); + return 0; + } else { + puts("Ipuid (Ip by Unique ID) mode wasn't selected"); + return -1; + } + } +#endif + check_inp_addr(argv[3], &addr, &prefix); + set_ipv6_global(if_idx, addr, prefix); + DEBUG("ipv6 address: %s\n", ipv6_addr_to_str(ip, &addr, sizeof(ip))); + return 0; } - if ((strcmp(argv[1], "help") == 0)) { + if ((argc < 5) || (argc > 5)) { + puts("net-tools command needs at least one argument"); net_tools_usage(); - return 0; + return 1; } return 0; } + +void check_inp_addr(char *addr, ipv6_addr_t *ip, uint8_t *pfx) { + uint8_t strlen = 0; + char *prefix; + while (*(addr + strlen) != '/') { + strlen++; + if (*(addr + strlen) == '\0') { + printf("Wrong input address. Address must be e.g: 2001:db8::/64\n"); + return; + } + } + strlen++; + prefix = addr + strlen; + *(addr + strlen - 1) = '\0'; + ipv6_addr_from_str(ip, addr); + *pfx = atoi(prefix); +} diff --git a/firmware/sys/shell_extended/shell_extended.c b/firmware/sys/shell_extended/shell_extended.c index ba8ea906a..1728896b4 100644 --- a/firmware/sys/shell_extended/shell_extended.c +++ b/firmware/sys/shell_extended/shell_extended.c @@ -34,7 +34,7 @@ int uid_cmd(int argc, char **argv); const shell_command_t shell_extended_commands[] = { /* important: please keep the used modules alphabetically sorted */ #if IS_USED(MODULE_NET_TOOLS) - {"net_tools", "net_tools commands", net_tools_cmd}, + {"if", "net_tools commands", net_tools_cmd}, #endif #if IS_USED(MODULE_UNIQUEID) {"uid", "uniqueid commands", uid_cmd}, From 3ee76f8503cd985119a039781c2b605f96617268 Mon Sep 17 00:00:00 2001 From: eduazocar Date: Tue, 27 Sep 2022 13:15:57 -0400 Subject: [PATCH 3/3] added mockup to show info of interface --- firmware/sys/shell_extended/se_net_tools.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/firmware/sys/shell_extended/se_net_tools.c b/firmware/sys/shell_extended/se_net_tools.c index ab7f9929e..45f604f05 100644 --- a/firmware/sys/shell_extended/se_net_tools.c +++ b/firmware/sys/shell_extended/se_net_tools.c @@ -29,6 +29,7 @@ #define ENABLE_DEBUG 0 #include "debug.h" +void show_iface_info(kernel_pid_t iface_idx); void check_inp_addr(char *addr, ipv6_addr_t *ip, uint8_t *pfx); void net_tools_usage(void) { @@ -82,6 +83,15 @@ int net_tools_cmd(int argc, char **argv) { DEBUG("ipv6 address: %s\n", ipv6_addr_to_str(ip, &addr, sizeof(ip))); return 0; } + if (strcmp(argv[2], "show") == 0) { + uint8_t if_idx = atoi(argv[1]); + if ((netif_get_by_id(if_idx)) == NULL) { + puts("Interface doesn't exist"); + return -1; + } + show_iface_info(if_idx); + return 0; + } if ((argc < 5) || (argc > 5)) { puts("net-tools command needs at least one argument"); @@ -91,6 +101,14 @@ int net_tools_cmd(int argc, char **argv) { return 0; } +void show_iface_info(kernel_pid_t iface_idx) { + /*ToDo show of an interface its specifications -> Physical info*/ + printf("ToDo: Show an interface\n"); + if (iface_idx == 0) { + /*ToDo show all interfaces and their physical features.*/ + } +} + void check_inp_addr(char *addr, ipv6_addr_t *ip, uint8_t *pfx) { uint8_t strlen = 0; char *prefix;