net: if: Connect interface with offloaded socket implementation

Instead of keeping a boolean informing whether a network interface is
offloaded at socket layer or not, keep a pointer to a function which
allows to create an offloaded socket. Native interfaces keep this as
NULL, while for offloaded interfaces it allows to connect an offloaded
socket implementation with an interface.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
diff --git a/drivers/modem/quectel-bg9x.c b/drivers/modem/quectel-bg9x.c
index fcae3c6..c34ea88 100644
--- a/drivers/modem/quectel-bg9x.c
+++ b/drivers/modem/quectel-bg9x.c
@@ -1066,6 +1066,8 @@
 	.setsockopt	= NULL,
 };
 
+static int offload_socket(int family, int type, int proto);
+
 /* Setup the Modem NET Interface. */
 static void modem_net_iface_init(struct net_if *iface)
 {
@@ -1077,6 +1079,8 @@
 			     sizeof(data->mac_addr),
 			     NET_LINK_ETHERNET);
 	data->net_iface = iface;
+
+	net_if_socket_offload_set(iface, offload_socket);
 }
 
 static struct net_if_api api_funcs = {
diff --git a/drivers/modem/simcom-sim7080.c b/drivers/modem/simcom-sim7080.c
index f563706..59954bf 100644
--- a/drivers/modem/simcom-sim7080.c
+++ b/drivers/modem/simcom-sim7080.c
@@ -62,6 +62,8 @@
 	return data->mac_addr;
 }
 
+static int offload_socket(int family, int type, int proto);
+
 /* Setup the Modem NET Interface. */
 static void modem_net_iface_init(struct net_if *iface)
 {
@@ -73,6 +75,8 @@
 	data->netif = iface;
 
 	socket_offload_dns_register(&offload_dns_ops);
+
+	net_if_socket_offload_set(iface, offload_socket);
 }
 
 /**
diff --git a/drivers/modem/ublox-sara-r4.c b/drivers/modem/ublox-sara-r4.c
index c62cef4..cbe1ddc 100644
--- a/drivers/modem/ublox-sara-r4.c
+++ b/drivers/modem/ublox-sara-r4.c
@@ -2097,6 +2097,8 @@
 	return data->mac_addr;
 }
 
+static int offload_socket(int family, int type, int proto);
+
 static void modem_net_iface_init(struct net_if *iface)
 {
 	const struct device *dev = net_if_get_device(iface);
@@ -2111,6 +2113,8 @@
 #ifdef CONFIG_DNS_RESOLVER
 	socket_offload_dns_register(&offload_dns_ops);
 #endif
+
+	net_if_socket_offload_set(iface, offload_socket);
 }
 
 static struct net_if_api api_funcs = {
diff --git a/drivers/wifi/eswifi/eswifi.h b/drivers/wifi/eswifi/eswifi.h
index b81eb39..ebe30a1 100644
--- a/drivers/wifi/eswifi/eswifi.h
+++ b/drivers/wifi/eswifi/eswifi.h
@@ -130,6 +130,7 @@
 int eswifi_at_cmd_rsp(struct eswifi_dev *eswifi, char *cmd, char **rsp);
 void eswifi_async_msg(struct eswifi_dev *eswifi, char *msg, size_t len);
 void eswifi_offload_async_msg(struct eswifi_dev *eswifi, char *msg, size_t len);
+int eswifi_socket_create(int family, int type, int proto);
 
 int eswifi_socket_type_from_zephyr(int proto, enum eswifi_transport_type *type);
 
diff --git a/drivers/wifi/eswifi/eswifi_core.c b/drivers/wifi/eswifi/eswifi_core.c
index 42ef3f2..88041fc 100644
--- a/drivers/wifi/eswifi/eswifi_core.c
+++ b/drivers/wifi/eswifi/eswifi_core.c
@@ -411,6 +411,8 @@
 	eswifi_offload_init(eswifi);
 #if defined(CONFIG_NET_SOCKETS_OFFLOAD)
 	eswifi_socket_offload_init(eswifi);
+
+	net_if_socket_offload_set(iface, eswifi_socket_create);
 #endif
 
 }
diff --git a/drivers/wifi/eswifi/eswifi_socket_offload.c b/drivers/wifi/eswifi/eswifi_socket_offload.c
index c3616b7..0b82801 100644
--- a/drivers/wifi/eswifi/eswifi_socket_offload.c
+++ b/drivers/wifi/eswifi/eswifi_socket_offload.c
@@ -512,7 +512,7 @@
 	return true;
 }
 
-static int eswifi_socket_create(int family, int type, int proto)
+int eswifi_socket_create(int family, int type, int proto)
 {
 	int fd = z_reserve_fd();
 	int sock;
diff --git a/drivers/wifi/simplelink/simplelink.c b/drivers/wifi/simplelink/simplelink.c
index 07af865..23c12f2 100644
--- a/drivers/wifi/simplelink/simplelink.c
+++ b/drivers/wifi/simplelink/simplelink.c
@@ -258,6 +258,8 @@
 	/* Direct socket offload: */
 	socket_offload_dns_register(&simplelink_dns_ops);
 	simplelink_sockets_init();
+
+	net_if_socket_offload_set(iface, simplelink_socket_create);
 #endif
 
 }
diff --git a/drivers/wifi/simplelink/simplelink_sockets.c b/drivers/wifi/simplelink/simplelink_sockets.c
index 92b6b7c..275f65b 100644
--- a/drivers/wifi/simplelink/simplelink_sockets.c
+++ b/drivers/wifi/simplelink/simplelink_sockets.c
@@ -1258,7 +1258,7 @@
 	return true;
 }
 
-static int simplelink_socket_create(int family, int type, int proto)
+int simplelink_socket_create(int family, int type, int proto)
 {
 	int fd = z_reserve_fd();
 	int sock;
diff --git a/drivers/wifi/simplelink/simplelink_support.h b/drivers/wifi/simplelink/simplelink_support.h
index 5ec6fd0..273aeab 100644
--- a/drivers/wifi/simplelink/simplelink_support.h
+++ b/drivers/wifi/simplelink/simplelink_support.h
@@ -45,6 +45,8 @@
 extern int z_simplelink_connect(struct wifi_connect_req_params *params);
 extern int z_simplelink_disconnect(void);
 
+int simplelink_socket_create(int family, int type, int proto);
+
 #ifdef __cplusplus
 }
 #endif