From 5038472d99072f42bde3488c462b10ba80ba2504 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Sat, 10 Feb 2024 00:01:28 +0900 Subject: [PATCH] net/netdev: Add ioctl for SIOCGETCONTEXT and SIOCSETCONTEXT Added ioctl to get and set the socket context held by the usrsock daemon. --- include/nuttx/net/ioctl.h | 2 ++ include/nuttx/net/net.h | 20 ++++++++++++++++++++ net/netdev/netdev_ioctl.c | 4 ++++ 3 files changed, 26 insertions(+) diff --git a/include/nuttx/net/ioctl.h b/include/nuttx/net/ioctl.h index fc59d0e48575a..5719f763b1e01 100644 --- a/include/nuttx/net/ioctl.h +++ b/include/nuttx/net/ioctl.h @@ -126,6 +126,8 @@ /* Network socket control ***************************************************/ #define SIOCDENYINETSOCK _SIOC(0x003C) /* Deny network socket. */ +#define SIOCGETCONTEXT _SIOC(0x003F) /* Get socket context */ +#define SIOCSETCONTEXT _SIOC(0x0040) /* Set socket context */ /* Bridge calls *************************************************************/ diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 739285102c82b..b7e9ee76dea62 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -253,6 +253,26 @@ struct socket FAR const struct sock_intf_s *s_sockif; }; +struct socket_ctx_data_s +{ + uint8_t s_domain; /* IP domain */ + uint8_t s_type; /* Protocol type */ + uint8_t s_proto; /* Socket Protocol */ + uint8_t s_priv[0]; /* Private socket context */ +}; + +/* NETDEV ioctl command: + * + * Command: SIOCGETCONTEXT or SIOCSETCONTEXT + * Description: Get or Set socket context. + */ + +struct socket_context_s +{ + size_t ctx_size; /* Size of socket context */ + struct socket_ctx_data_s *ctx; /* Buffer where socket context is stored */ +}; + /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index 56129d6ae6bc9..c73b4faf2c9b2 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -1710,6 +1710,10 @@ ssize_t net_ioctl_arglen(uint8_t domain, int cmd) case SIOCDENYINETSOCK: return sizeof(uint8_t); + case SIOCGETCONTEXT: + case SIOCSETCONTEXT: + return sizeof(struct socket_context_s); + default: #ifdef CONFIG_NETDEV_IOCTL # ifdef CONFIG_NETDEV_WIRELESS_IOCTL