From d64f073df735e29063f7e59a1548d741ee7729f8 Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Mon, 13 Sep 2021 11:02:12 +0200 Subject: [PATCH 1/7] net/link_layer/l2util: initial Kconfig modeling --- sys/net/link_layer/Kconfig | 1 + sys/net/link_layer/l2util/Kconfig | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 sys/net/link_layer/l2util/Kconfig diff --git a/sys/net/link_layer/Kconfig b/sys/net/link_layer/Kconfig index bb915b4e01..7b0c2c7794 100644 --- a/sys/net/link_layer/Kconfig +++ b/sys/net/link_layer/Kconfig @@ -8,4 +8,5 @@ rsource "csma_sender/Kconfig" rsource "eui_provider/Kconfig" rsource "ieee802154/Kconfig" rsource "l2filter/Kconfig" +rsource "l2util/Kconfig" rsource "Kconfig.lorawan" diff --git a/sys/net/link_layer/l2util/Kconfig b/sys/net/link_layer/l2util/Kconfig new file mode 100644 index 0000000000..44d77fb200 --- /dev/null +++ b/sys/net/link_layer/l2util/Kconfig @@ -0,0 +1,10 @@ +# Copyright (c) 2021 HAW Hamburg +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# + +config MODULE_L2UTIL + bool "Link layer utils" + select MODULE_FMT From d12d514d7c7cc28f4ba7ffed3447e01456c3a909 Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Wed, 29 Sep 2021 11:18:00 +0200 Subject: [PATCH 2/7] test/ieee802154_hal: rename packet to frame --- tests/ieee802154_hal/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ieee802154_hal/main.c b/tests/ieee802154_hal/main.c index 35dcf33b55..b751dc38b2 100644 --- a/tests/ieee802154_hal/main.c +++ b/tests/ieee802154_hal/main.c @@ -57,7 +57,7 @@ static void _print_packet(size_t size, uint8_t lqi, int16_t rssi) printf("Received valid ACK with sqn %i\n", buffer[2]); } else { - puts("Packet received:"); + puts("Frame received:"); for (unsigned i=0;i Date: Wed, 29 Sep 2021 11:18:52 +0200 Subject: [PATCH 3/7] test/ieee802154_hal/Makefile: add shell_commands --- tests/ieee802154_hal/Makefile | 1 + tests/ieee802154_hal/app.config.test | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/ieee802154_hal/Makefile b/tests/ieee802154_hal/Makefile index 434bb3fe8b..729a783ef6 100644 --- a/tests/ieee802154_hal/Makefile +++ b/tests/ieee802154_hal/Makefile @@ -23,6 +23,7 @@ USEMODULE += od USEMODULE += luid USEMODULE += ieee802154 USEMODULE += shell +USEMODULE += shell_commands USEMODULE += ps USEMODULE += event_thread_highest USEMODULE += event_callback diff --git a/tests/ieee802154_hal/app.config.test b/tests/ieee802154_hal/app.config.test index 5366bdab71..bd31fdbb23 100644 --- a/tests/ieee802154_hal/app.config.test +++ b/tests/ieee802154_hal/app.config.test @@ -4,6 +4,7 @@ CONFIG_MODULE_OD=y CONFIG_MODULE_LUID=y CONFIG_MODULE_IEEE802154=y CONFIG_MODULE_SHELL=y +CONFIG_MODULE_SHELL_COMMANDS=y CONFIG_MODULE_PS=y CONFIG_MODULE_EVENT=y From 57ee43a048a1b3b58d58eab604efd2e3562363e6 Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Wed, 29 Sep 2021 11:19:37 +0200 Subject: [PATCH 4/7] test/ieee802154_hal/Makefile: use regular event_thread --- tests/ieee802154_hal/Makefile | 4 ++-- tests/ieee802154_hal/app.config.test | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/ieee802154_hal/Makefile b/tests/ieee802154_hal/Makefile index 729a783ef6..2680bf1683 100644 --- a/tests/ieee802154_hal/Makefile +++ b/tests/ieee802154_hal/Makefile @@ -25,11 +25,11 @@ USEMODULE += ieee802154 USEMODULE += shell USEMODULE += shell_commands USEMODULE += ps -USEMODULE += event_thread_highest +USEMODULE += event_thread USEMODULE += event_callback USEMODULE += xtimer USEMODULE += netdev_default -CFLAGS += -DEVENT_THREAD_HIGHEST_STACKSIZE=1024 +CFLAGS += -DEVENT_THREAD_MEDIUM_STACKSIZE=1024 include $(RIOTBASE)/Makefile.include diff --git a/tests/ieee802154_hal/app.config.test b/tests/ieee802154_hal/app.config.test index bd31fdbb23..ed23213287 100644 --- a/tests/ieee802154_hal/app.config.test +++ b/tests/ieee802154_hal/app.config.test @@ -9,7 +9,6 @@ CONFIG_MODULE_PS=y CONFIG_MODULE_EVENT=y CONFIG_MODULE_EVENT_THREAD=y -CONFIG_MODULE_EVENT_THREAD_HIGHEST=y CONFIG_MODULE_EVENT_CALLBACK=y CONFIG_MODULE_XTIMER=y From 3b4240dd228c00c86c68f5e6837aaa782aba7f60 Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Wed, 29 Sep 2021 11:21:38 +0200 Subject: [PATCH 5/7] test/ieee802154_hal: use l2util where possible --- tests/ieee802154_hal/Makefile | 1 + tests/ieee802154_hal/app.config.test | 1 + tests/ieee802154_hal/main.c | 83 +++------------------------- 3 files changed, 11 insertions(+), 74 deletions(-) diff --git a/tests/ieee802154_hal/Makefile b/tests/ieee802154_hal/Makefile index 2680bf1683..3f2ae06c03 100644 --- a/tests/ieee802154_hal/Makefile +++ b/tests/ieee802154_hal/Makefile @@ -21,6 +21,7 @@ DISABLE_MODULE += auto_init_at86rf2xx auto_init_nrf802154 USEMODULE += od USEMODULE += luid +USEMODULE += l2util USEMODULE += ieee802154 USEMODULE += shell USEMODULE += shell_commands diff --git a/tests/ieee802154_hal/app.config.test b/tests/ieee802154_hal/app.config.test index ed23213287..1c9285f9bc 100644 --- a/tests/ieee802154_hal/app.config.test +++ b/tests/ieee802154_hal/app.config.test @@ -5,6 +5,7 @@ CONFIG_MODULE_LUID=y CONFIG_MODULE_IEEE802154=y CONFIG_MODULE_SHELL=y CONFIG_MODULE_SHELL_COMMANDS=y +CONFIG_MODULE_L2UTIL=y CONFIG_MODULE_PS=y CONFIG_MODULE_EVENT=y diff --git a/tests/ieee802154_hal/main.c b/tests/ieee802154_hal/main.c index b751dc38b2..4b0f5691c0 100644 --- a/tests/ieee802154_hal/main.c +++ b/tests/ieee802154_hal/main.c @@ -27,6 +27,7 @@ #include "event/thread.h" #include "luid.h" +#include "net/l2util.h" #include "net/ieee802154.h" #include "net/ieee802154/radio.h" @@ -37,6 +38,8 @@ #define SYMBOL_TIME (16U) /**< 16 us */ #define ACK_TIMEOUT_TIME (40 * SYMBOL_TIME) +#define IEEE802154_LONG_ADDRESS_LEN_STR_MAX \ + (sizeof("00:00:00:00:00:00:00:00")) static inline void _set_trx_state(int state, bool verbose); @@ -69,13 +72,11 @@ static void _print_packet(size_t size, uint8_t lqi, int16_t rssi) static int print_addr(int argc, char **argv) { - (void) argc; - (void) argv; - uint8_t *_p = (uint8_t*) &ext_addr; - for(int i=0;i<8;i++) { - printf("%02x", *_p++); - } - printf("\n"); + (void)argc; + (void)argv; + char addr_str[IEEE802154_LONG_ADDRESS_LEN_STR_MAX]; + printf("%s\n", l2util_addr_to_str( + ext_addr.uint8, IEEE802154_LONG_ADDRESS_LEN, addr_str)); return 0; } @@ -356,72 +357,6 @@ static int send(uint8_t *dst, size_t dst_len, return 0; } -static inline int _dehex(char c, int default_) -{ - if ('0' <= c && c <= '9') { - return c - '0'; - } - else if ('A' <= c && c <= 'F') { - return c - 'A' + 10; - } - else if ('a' <= c && c <= 'f') { - return c - 'a' + 10; - } - else { - return default_; - } -} - -static size_t _parse_addr(uint8_t *out, size_t out_len, const char *in) -{ - const char *end_str = in; - uint8_t *out_end = out; - size_t count = 0; - int assert_cell = 1; - - if (!in || !*in) { - return 0; - } - while (end_str[1]) { - ++end_str; - } - - while (end_str >= in) { - int a = 0, b = _dehex(*end_str--, -1); - if (b < 0) { - if (assert_cell) { - return 0; - } - else { - assert_cell = 1; - continue; - } - } - assert_cell = 0; - - if (end_str >= in) { - a = _dehex(*end_str--, 0); - } - - if (++count > out_len) { - return 0; - } - *out_end++ = (a << 4) | b; - } - if (assert_cell) { - return 0; - } - /* out is reversed */ - - while (out < --out_end) { - uint8_t tmp = *out_end; - *out_end = *out; - *out++ = tmp; - } - - return count; -} - int _cca(int argc, char **argv) { (void) argc; @@ -508,7 +443,7 @@ int txtsnd(int argc, char **argv) return 1; } - res = _parse_addr(addr, sizeof(addr), argv[1]); + res = l2util_addr_from_str(argv[ 1], addr); if (res == 0) { puts("Usage: txtsnd "); return 1; From a8b19a1c76051dd6b67fccd497307b2f47e394f6 Mon Sep 17 00:00:00 2001 From: Jose Alamos Date: Wed, 29 Sep 2021 11:21:59 +0200 Subject: [PATCH 6/7] test/ieee802154_hal: use od where possible --- tests/ieee802154_hal/main.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/ieee802154_hal/main.c b/tests/ieee802154_hal/main.c index 4b0f5691c0..4c033f1113 100644 --- a/tests/ieee802154_hal/main.c +++ b/tests/ieee802154_hal/main.c @@ -26,6 +26,7 @@ #include "errno.h" #include "event/thread.h" #include "luid.h" +#include "od.h" #include "net/l2util.h" #include "net/ieee802154.h" @@ -61,11 +62,8 @@ static void _print_packet(size_t size, uint8_t lqi, int16_t rssi) } else { puts("Frame received:"); - for (unsigned i=0;i Date: Wed, 29 Sep 2021 11:22:32 +0200 Subject: [PATCH 7/7] test/ieee802154_hal: rename long_addr into ext_addr --- tests/ieee802154_hal/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ieee802154_hal/main.c b/tests/ieee802154_hal/main.c index 4c033f1113..c1043fb7ba 100644 --- a/tests/ieee802154_hal/main.c +++ b/tests/ieee802154_hal/main.c @@ -437,13 +437,13 @@ int txtsnd(int argc, char **argv) size_t res; if (argc != 3) { - puts("Usage: txtsnd "); + puts("Usage: txtsnd "); return 1; } res = l2util_addr_from_str(argv[ 1], addr); if (res == 0) { - puts("Usage: txtsnd "); + puts("Usage: txtsnd "); return 1; } len = atoi(argv[2]);