From 90f3c150846673942f2a154c7c5adf9c4e4fbf80 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 29 Oct 2020 18:37:05 +0100 Subject: [PATCH] socket_zep: send dummy HELLO packet on connect --- cpu/native/include/socket_zep.h | 33 ++++++++++++++++++++++++++++++ cpu/native/socket_zep/socket_zep.c | 23 ++++++++++++++++++++- makefiles/pseudomodules.inc.mk | 1 + 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/cpu/native/include/socket_zep.h b/cpu/native/include/socket_zep.h index 01bbad616c..7529e7d8ef 100644 --- a/cpu/native/include/socket_zep.h +++ b/cpu/native/include/socket_zep.h @@ -13,6 +13,39 @@ * * @see @ref net_zep for protocol definitions * + * This ZEP implementation can send a dummy HELLO packet on startup. + * This is used to make dispatchers aware of the node. + * To enable this behavior, add + * + * ``` + * USEMODULE += socket_zep_hello + * ``` + * + * to your Makefile. + * + * A ZEP dispatcher can just drop those packets (ZEP type 0xFF) if it + * chooses to parse the ZEP header. + * + * The header of the HELLO packet will look like this: + * + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Preamble (EX) | Version (2) | Type (255) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | | + * + + + * | | + * + Reserved (0) + + * | | + * + + + * | | + * + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | | 'H' | 'E' | 'L' | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | 'L' | 'O' | 0 | 0 | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | 0 | 0 | 0 | 0 | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * * @{ * * @file diff --git a/cpu/native/socket_zep/socket_zep.c b/cpu/native/socket_zep/socket_zep.c index 487a145393..f88b2c3608 100644 --- a/cpu/native/socket_zep/socket_zep.c +++ b/cpu/native/socket_zep/socket_zep.c @@ -40,6 +40,9 @@ * (https://pubs.opengroup.org/onlinepubs/9699919799.2016edition/basedefs/time.h.html) */ #define TV_USEC_PER_SEC (1000000L) +/* dummy packet to register with ZEP dispatcher */ +#define SOCKET_ZEP_V2_TYPE_HELLO (255) + static size_t _zep_hdr_fill_v2_data(socket_zep_t *dev, zep_v2_data_hdr_t *hdr, size_t payload_len) { @@ -390,6 +393,21 @@ static int _connect_remote(socket_zep_t *dev, const socket_zep_params_t *params) return res; } +static void _send_zep_hello(socket_zep_t *dev) +{ + if (IS_USED(MODULE_SOCKET_ZEP_HELLO)) { + /* dummy packet */ + zep_v2_data_hdr_t hdr = { + .hdr.preamble = "EX", + .hdr.version = 2, + .type = SOCKET_ZEP_V2_TYPE_HELLO, + .resv = "HELLO", + }; + + real_write(dev->sock_fd, &hdr, sizeof(hdr)); + } +} + void socket_zep_setup(socket_zep_t *dev, const socket_zep_params_t *params) { int res; @@ -408,7 +426,10 @@ void socket_zep_setup(socket_zep_t *dev, const socket_zep_params_t *params) dev->sock_fd = res; } - _connect_remote(dev, params); + if (_connect_remote(dev, params) == 0) { + /* send dummy data to connect to dispatcher */ + _send_zep_hello(dev); + } /* generate hardware address from local address */ uint8_t ss_array[sizeof(struct sockaddr_storage)] = { 0 }; diff --git a/makefiles/pseudomodules.inc.mk b/makefiles/pseudomodules.inc.mk index 388dcf4dc4..4e29d69dc9 100644 --- a/makefiles/pseudomodules.inc.mk +++ b/makefiles/pseudomodules.inc.mk @@ -116,6 +116,7 @@ PSEUDOMODULES += sock_dtls PSEUDOMODULES += sock_ip PSEUDOMODULES += sock_tcp PSEUDOMODULES += sock_udp +PSEUDOMODULES += socket_zep_hello PSEUDOMODULES += soft_uart_modecfg PSEUDOMODULES += stdin PSEUDOMODULES += stdio_cdc_acm