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>
This commit is contained in:
parent
53fbf40227
commit
fa8ba73833
10 changed files with 69 additions and 5 deletions
|
@ -1066,6 +1066,8 @@ static const struct socket_op_vtable offload_socket_fd_op_vtable = {
|
||||||
.setsockopt = NULL,
|
.setsockopt = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int offload_socket(int family, int type, int proto);
|
||||||
|
|
||||||
/* Setup the Modem NET Interface. */
|
/* Setup the Modem NET Interface. */
|
||||||
static void modem_net_iface_init(struct net_if *iface)
|
static void modem_net_iface_init(struct net_if *iface)
|
||||||
{
|
{
|
||||||
|
@ -1077,6 +1079,8 @@ static void modem_net_iface_init(struct net_if *iface)
|
||||||
sizeof(data->mac_addr),
|
sizeof(data->mac_addr),
|
||||||
NET_LINK_ETHERNET);
|
NET_LINK_ETHERNET);
|
||||||
data->net_iface = iface;
|
data->net_iface = iface;
|
||||||
|
|
||||||
|
net_if_socket_offload_set(iface, offload_socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct net_if_api api_funcs = {
|
static struct net_if_api api_funcs = {
|
||||||
|
|
|
@ -62,6 +62,8 @@ static inline uint8_t *modem_get_mac(const struct device *dev)
|
||||||
return data->mac_addr;
|
return data->mac_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int offload_socket(int family, int type, int proto);
|
||||||
|
|
||||||
/* Setup the Modem NET Interface. */
|
/* Setup the Modem NET Interface. */
|
||||||
static void modem_net_iface_init(struct net_if *iface)
|
static void modem_net_iface_init(struct net_if *iface)
|
||||||
{
|
{
|
||||||
|
@ -73,6 +75,8 @@ static void modem_net_iface_init(struct net_if *iface)
|
||||||
data->netif = iface;
|
data->netif = iface;
|
||||||
|
|
||||||
socket_offload_dns_register(&offload_dns_ops);
|
socket_offload_dns_register(&offload_dns_ops);
|
||||||
|
|
||||||
|
net_if_socket_offload_set(iface, offload_socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2097,6 +2097,8 @@ static inline uint8_t *modem_get_mac(const struct device *dev)
|
||||||
return data->mac_addr;
|
return data->mac_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int offload_socket(int family, int type, int proto);
|
||||||
|
|
||||||
static void modem_net_iface_init(struct net_if *iface)
|
static void modem_net_iface_init(struct net_if *iface)
|
||||||
{
|
{
|
||||||
const struct device *dev = net_if_get_device(iface);
|
const struct device *dev = net_if_get_device(iface);
|
||||||
|
@ -2111,6 +2113,8 @@ static void modem_net_iface_init(struct net_if *iface)
|
||||||
#ifdef CONFIG_DNS_RESOLVER
|
#ifdef CONFIG_DNS_RESOLVER
|
||||||
socket_offload_dns_register(&offload_dns_ops);
|
socket_offload_dns_register(&offload_dns_ops);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
net_if_socket_offload_set(iface, offload_socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct net_if_api api_funcs = {
|
static struct net_if_api api_funcs = {
|
||||||
|
|
|
@ -130,6 +130,7 @@ struct eswifi_dev *eswifi_by_iface_idx(uint8_t iface);
|
||||||
int eswifi_at_cmd_rsp(struct eswifi_dev *eswifi, char *cmd, char **rsp);
|
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_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);
|
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);
|
int eswifi_socket_type_from_zephyr(int proto, enum eswifi_transport_type *type);
|
||||||
|
|
||||||
|
|
|
@ -411,6 +411,8 @@ static void eswifi_iface_init(struct net_if *iface)
|
||||||
eswifi_offload_init(eswifi);
|
eswifi_offload_init(eswifi);
|
||||||
#if defined(CONFIG_NET_SOCKETS_OFFLOAD)
|
#if defined(CONFIG_NET_SOCKETS_OFFLOAD)
|
||||||
eswifi_socket_offload_init(eswifi);
|
eswifi_socket_offload_init(eswifi);
|
||||||
|
|
||||||
|
net_if_socket_offload_set(iface, eswifi_socket_create);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -512,7 +512,7 @@ static bool eswifi_socket_is_supported(int family, int type, int proto)
|
||||||
return true;
|
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 fd = z_reserve_fd();
|
||||||
int sock;
|
int sock;
|
||||||
|
|
|
@ -258,6 +258,8 @@ static void simplelink_iface_init(struct net_if *iface)
|
||||||
/* Direct socket offload: */
|
/* Direct socket offload: */
|
||||||
socket_offload_dns_register(&simplelink_dns_ops);
|
socket_offload_dns_register(&simplelink_dns_ops);
|
||||||
simplelink_sockets_init();
|
simplelink_sockets_init();
|
||||||
|
|
||||||
|
net_if_socket_offload_set(iface, simplelink_socket_create);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1258,7 +1258,7 @@ static bool simplelink_is_supported(int family, int type, int proto)
|
||||||
return true;
|
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 fd = z_reserve_fd();
|
||||||
int sock;
|
int sock;
|
||||||
|
|
|
@ -45,6 +45,8 @@ extern int z_simplelink_init(simplelink_wifi_cb_t wifi_cb);
|
||||||
extern int z_simplelink_connect(struct wifi_connect_req_params *params);
|
extern int z_simplelink_connect(struct wifi_connect_req_params *params);
|
||||||
extern int z_simplelink_disconnect(void);
|
extern int z_simplelink_disconnect(void);
|
||||||
|
|
||||||
|
int simplelink_socket_create(int family, int type, int proto);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -411,6 +411,14 @@ struct net_traffic_class {
|
||||||
k_thread_stack_t *stack;
|
k_thread_stack_t *stack;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef net_socket_create_t
|
||||||
|
|
||||||
|
* @brief A function prototype to create an offloaded socket. The prototype is
|
||||||
|
* compatible with socket() function.
|
||||||
|
*/
|
||||||
|
typedef int (*net_socket_create_t)(int, int, int);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Network Interface Device structure
|
* @brief Network Interface Device structure
|
||||||
*
|
*
|
||||||
|
@ -453,8 +461,10 @@ struct net_if_dev {
|
||||||
uint16_t mtu;
|
uint16_t mtu;
|
||||||
|
|
||||||
#if defined(CONFIG_NET_SOCKETS_OFFLOAD)
|
#if defined(CONFIG_NET_SOCKETS_OFFLOAD)
|
||||||
/** Indicate whether interface is offloaded at socket level. */
|
/** A function pointer to create an offloaded socket.
|
||||||
bool offloaded;
|
* If non-NULL, the interface is considered offloaded at socket level.
|
||||||
|
*/
|
||||||
|
net_socket_create_t socket_offload;
|
||||||
#endif /* CONFIG_NET_SOCKETS_OFFLOAD */
|
#endif /* CONFIG_NET_SOCKETS_OFFLOAD */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -662,7 +672,7 @@ static inline struct net_offload *net_if_offload(struct net_if *iface)
|
||||||
static inline bool net_if_is_socket_offloaded(struct net_if *iface)
|
static inline bool net_if_is_socket_offloaded(struct net_if *iface)
|
||||||
{
|
{
|
||||||
#if defined(CONFIG_NET_SOCKETS_OFFLOAD)
|
#if defined(CONFIG_NET_SOCKETS_OFFLOAD)
|
||||||
return iface->if_dev->offloaded;
|
return (iface->if_dev->socket_offload != NULL);
|
||||||
#else
|
#else
|
||||||
ARG_UNUSED(iface);
|
ARG_UNUSED(iface);
|
||||||
|
|
||||||
|
@ -670,6 +680,41 @@ static inline bool net_if_is_socket_offloaded(struct net_if *iface)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set the function to create an offloaded socket
|
||||||
|
*
|
||||||
|
* @param iface Network interface
|
||||||
|
* @param socket_offload A function to create an offloaded socket
|
||||||
|
*/
|
||||||
|
static inline void net_if_socket_offload_set(
|
||||||
|
struct net_if *iface, net_socket_create_t socket_offload)
|
||||||
|
{
|
||||||
|
#if defined(CONFIG_NET_SOCKETS_OFFLOAD)
|
||||||
|
iface->if_dev->socket_offload = socket_offload;
|
||||||
|
#else
|
||||||
|
ARG_UNUSED(iface);
|
||||||
|
ARG_UNUSED(socket_offload);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return the function to create an offloaded socket
|
||||||
|
*
|
||||||
|
* @param iface Network interface
|
||||||
|
*
|
||||||
|
* @return NULL if the interface is not socket offloaded, valid pointer otherwise
|
||||||
|
*/
|
||||||
|
static inline net_socket_create_t net_if_socket_offload(struct net_if *iface)
|
||||||
|
{
|
||||||
|
#if defined(CONFIG_NET_SOCKETS_OFFLOAD)
|
||||||
|
return iface->if_dev->socket_offload;
|
||||||
|
#else
|
||||||
|
ARG_UNUSED(iface);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get an network interface's link address
|
* @brief Get an network interface's link address
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue