From 7946988b164240aeb4bae8c99638e03255b68434 Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Wed, 30 Mar 2022 14:55:35 +0200 Subject: [PATCH] net: sockets: Add separate macro for registering offloaded sockets Add a separate macro for registering offloaded sockets implementation, along with information in the structure whether the implementation is offloaded or not. This allows to differentiate between native and offloaded socket implementations, which is critical for binding socket API with an interface. Signed-off-by: Robert Lubos --- drivers/modem/quectel-bg9x.c | 4 ++-- drivers/modem/simcom-sim7080.c | 4 ++-- drivers/modem/ublox-sara-r4.c | 4 ++-- drivers/wifi/eswifi/eswifi_socket_offload.c | 4 ++-- drivers/wifi/simplelink/simplelink_sockets.c | 4 ++-- include/zephyr/net/socket.h | 12 ++++++++++-- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/drivers/modem/quectel-bg9x.c b/drivers/modem/quectel-bg9x.c index c34ea88c58..219683546e 100644 --- a/drivers/modem/quectel-bg9x.c +++ b/drivers/modem/quectel-bg9x.c @@ -1207,5 +1207,5 @@ NET_DEVICE_DT_INST_OFFLOAD_DEFINE(0, modem_init, NULL, &api_funcs, MDM_MAX_DATA_LENGTH); /* Register NET sockets. */ -NET_SOCKET_REGISTER(quectel_bg9x, CONFIG_NET_SOCKETS_OFFLOAD_PRIORITY, AF_UNSPEC, - offload_is_supported, offload_socket); +NET_SOCKET_OFFLOAD_REGISTER(quectel_bg9x, CONFIG_NET_SOCKETS_OFFLOAD_PRIORITY, + AF_UNSPEC, offload_is_supported, offload_socket); diff --git a/drivers/modem/simcom-sim7080.c b/drivers/modem/simcom-sim7080.c index 59954bf21b..2e148553a0 100644 --- a/drivers/modem/simcom-sim7080.c +++ b/drivers/modem/simcom-sim7080.c @@ -2399,5 +2399,5 @@ NET_DEVICE_DT_INST_OFFLOAD_DEFINE(0, modem_init, NULL, &mdata, NULL, CONFIG_MODEM_SIMCOM_SIM7080_INIT_PRIORITY, &api_funcs, MDM_MAX_DATA_LENGTH); -NET_SOCKET_REGISTER(simcom_sim7080, CONFIG_NET_SOCKETS_OFFLOAD_PRIORITY, AF_UNSPEC, - offload_is_supported, offload_socket); +NET_SOCKET_OFFLOAD_REGISTER(simcom_sim7080, CONFIG_NET_SOCKETS_OFFLOAD_PRIORITY, + AF_UNSPEC, offload_is_supported, offload_socket); diff --git a/drivers/modem/ublox-sara-r4.c b/drivers/modem/ublox-sara-r4.c index cbe1ddcd9f..df61da72c7 100644 --- a/drivers/modem/ublox-sara-r4.c +++ b/drivers/modem/ublox-sara-r4.c @@ -1966,8 +1966,8 @@ static bool offload_is_supported(int family, int type, int proto) return true; } -NET_SOCKET_REGISTER(ublox_sara_r4, CONFIG_NET_SOCKETS_OFFLOAD_PRIORITY, AF_UNSPEC, - offload_is_supported, offload_socket); +NET_SOCKET_OFFLOAD_REGISTER(ublox_sara_r4, CONFIG_NET_SOCKETS_OFFLOAD_PRIORITY, + AF_UNSPEC, offload_is_supported, offload_socket); #if defined(CONFIG_DNS_RESOLVER) /* TODO: This is a bare-bones implementation of DNS handling diff --git a/drivers/wifi/eswifi/eswifi_socket_offload.c b/drivers/wifi/eswifi/eswifi_socket_offload.c index 0b82801ec9..685f460436 100644 --- a/drivers/wifi/eswifi/eswifi_socket_offload.c +++ b/drivers/wifi/eswifi/eswifi_socket_offload.c @@ -588,8 +588,8 @@ static const struct socket_op_vtable eswifi_socket_fd_op_vtable = { }; #ifdef CONFIG_NET_SOCKETS_OFFLOAD -NET_SOCKET_REGISTER(eswifi, CONFIG_NET_SOCKETS_OFFLOAD_PRIORITY, AF_UNSPEC, - eswifi_socket_is_supported, eswifi_socket_create); +NET_SOCKET_OFFLOAD_REGISTER(eswifi, CONFIG_NET_SOCKETS_OFFLOAD_PRIORITY, AF_UNSPEC, + eswifi_socket_is_supported, eswifi_socket_create); #endif static int eswifi_off_getaddrinfo(const char *node, const char *service, diff --git a/drivers/wifi/simplelink/simplelink_sockets.c b/drivers/wifi/simplelink/simplelink_sockets.c index 275f65b06c..f65495d3bc 100644 --- a/drivers/wifi/simplelink/simplelink_sockets.c +++ b/drivers/wifi/simplelink/simplelink_sockets.c @@ -1304,8 +1304,8 @@ static int simplelink_socket_accept(void *obj, struct sockaddr *addr, } #ifdef CONFIG_NET_SOCKETS_OFFLOAD -NET_SOCKET_REGISTER(simplelink, CONFIG_NET_SOCKETS_OFFLOAD_PRIORITY, AF_UNSPEC, - simplelink_is_supported, simplelink_socket_create); +NET_SOCKET_OFFLOAD_REGISTER(simplelink, CONFIG_NET_SOCKETS_OFFLOAD_PRIORITY, AF_UNSPEC, + simplelink_is_supported, simplelink_socket_create); #endif void simplelink_sockets_init(void) diff --git a/include/zephyr/net/socket.h b/include/zephyr/net/socket.h index 4bcf36f3f6..492a8cd19d 100644 --- a/include/zephyr/net/socket.h +++ b/include/zephyr/net/socket.h @@ -934,6 +934,7 @@ struct ifreq { */ struct net_socket_register { int family; + bool is_offloaded; bool (*is_supported)(int family, int type, int proto); int (*handler)(int family, int type, int proto); }; @@ -943,14 +944,21 @@ struct net_socket_register { #define NET_SOCKET_GET_NAME(socket_name, prio) \ __net_socket_register_##prio##_##socket_name -#define NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler) \ +#define _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, _is_offloaded) \ static const STRUCT_SECTION_ITERABLE(net_socket_register, \ - NET_SOCKET_GET_NAME(socket_name, prio)) = { \ + NET_SOCKET_GET_NAME(socket_name, prio)) = { \ .family = _family, \ + .is_offloaded = _is_offloaded, \ .is_supported = _is_supported, \ .handler = _handler, \ } +#define NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler) \ + _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, false) + +#define NET_SOCKET_OFFLOAD_REGISTER(socket_name, prio, _family, _is_supported, _handler) \ + _NET_SOCKET_REGISTER(socket_name, prio, _family, _is_supported, _handler, true) + /** @endcond */ #ifdef __cplusplus