diff options
| author | yangjie11 <[email protected]> | 2020-11-18 09:56:35 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-11-18 09:56:35 +0800 |
| commit | d4a682e8d97fa131e5a8d795f8c5451d55cdd5b0 (patch) | |
| tree | 4773b40cb012475c5daf74bfd55707e141477669 /components/net/sal_socket/impl | |
| parent | 2b98f4720c827ae1850df78299f6b273d568c8c7 (diff) | |
| parent | 2ef3c9d861f55253620996a94831a4be31ca6620 (diff) | |
Merge pull request #3 from RT-Thread/master
sync
Diffstat (limited to 'components/net/sal_socket/impl')
| -rw-r--r-- | components/net/sal_socket/impl/af_inet.h | 16 | ||||
| -rw-r--r-- | components/net/sal_socket/impl/af_inet_at.c | 28 | ||||
| -rw-r--r-- | components/net/sal_socket/impl/af_inet_lwip.c | 56 | ||||
| -rw-r--r-- | components/net/sal_socket/impl/proto_mbedtls.c | 12 |
4 files changed, 67 insertions, 45 deletions
diff --git a/components/net/sal_socket/impl/af_inet.h b/components/net/sal_socket/impl/af_inet.h index 8b7bf9d2a6..caffbe1400 100644 --- a/components/net/sal_socket/impl/af_inet.h +++ b/components/net/sal_socket/impl/af_inet.h @@ -18,14 +18,18 @@ extern "C" { #endif #ifdef SAL_USING_LWIP -/* lwIP protocol family register */ -int lwip_inet_init(void); -#endif + +/* Set lwIP network interface device protocol family information */ +int sal_lwip_netdev_set_pf_info(struct netdev *netdev); + +#endif /* SAL_USING_LWIP */ #ifdef SAL_USING_AT -/* AT protocol family register */ -int at_inet_init(void); -#endif + +/* Set AT network interface device protocol family information */ +int sal_at_netdev_set_pf_info(struct netdev *netdev); + +#endif /* SAL_USING_AT */ #ifdef __cplusplus } diff --git a/components/net/sal_socket/impl/af_inet_at.c b/components/net/sal_socket/impl/af_inet_at.c index 90d1537967..135e4183c4 100644 --- a/components/net/sal_socket/impl/af_inet_at.c +++ b/components/net/sal_socket/impl/af_inet_at.c @@ -16,6 +16,8 @@ #include <at_socket.h> #include <af_inet.h> +#include <netdev.h> + #ifdef SAL_USING_POSIX #include <dfs_poll.h> #endif @@ -78,24 +80,12 @@ static const struct sal_socket_ops at_socket_ops = NULL, NULL, NULL, - #ifdef SAL_USING_POSIX at_poll, #endif /* SAL_USING_POSIX */ }; -static int at_create(struct sal_socket *socket, int type, int protocol) -{ - RT_ASSERT(socket); - - //TODO Check type & protocol - - socket->ops = &at_socket_ops; - - return 0; -} - -static struct sal_proto_ops at_proto_ops = +static const struct sal_netdb_ops at_netdb_ops = { at_gethostbyname, NULL, @@ -107,16 +97,18 @@ static const struct sal_proto_family at_inet_family = { AF_AT, AF_INET, - at_create, - &at_proto_ops, + &at_socket_ops, + &at_netdb_ops, }; -int at_inet_init(void) + +/* Set AT network interface device protocol family information */ +int sal_at_netdev_set_pf_info(struct netdev *netdev) { - sal_proto_family_register(&at_inet_family); + RT_ASSERT(netdev); + netdev->sal_user_data = (void *) &at_inet_family; return 0; } -INIT_COMPONENT_EXPORT(at_inet_init); #endif /* SAL_USING_AT */ diff --git a/components/net/sal_socket/impl/af_inet_lwip.c b/components/net/sal_socket/impl/af_inet_lwip.c index 0826b052ab..56df735ab9 100644 --- a/components/net/sal_socket/impl/af_inet_lwip.c +++ b/components/net/sal_socket/impl/af_inet_lwip.c @@ -14,6 +14,7 @@ #include <lwip/netdb.h> #include <lwip/api.h> #include <lwip/init.h> +#include <lwip/netif.h> #ifdef SAL_USING_POSIX #include <dfs_poll.h> @@ -22,6 +23,14 @@ #include <sal.h> #include <af_inet.h> +#include <netdev.h> + +#if (LWIP_VERSION < 0x2000000) && NETDEV_IPV6 +#error "The lwIP version is not support IPV6, please disable netdev IPV6 configuration " +#elif (LWIP_VERSION > 0x2000000) && (NETDEV_IPV6 != LWIP_IPV6) +#error "IPV6 configuration error, Please check and synchronize netdev and lwip IPV6 configuration." +#endif + #if LWIP_VERSION < 0x2000000 #define SELWAIT_T int #else @@ -214,6 +223,19 @@ static int inet_getsockname(int socket, struct sockaddr *name, socklen_t *namele return lwip_getsockname(socket, name, namelen); } +int inet_ioctlsocket(int socket, long cmd, void *arg) +{ + switch (cmd) + { + case F_GETFL: + case F_SETFL: + return lwip_fcntl(socket, cmd, (int) arg); + + default: + return lwip_ioctl(socket, cmd, arg); + } +} + #ifdef SAL_USING_POSIX static int inet_poll(struct dfs_fd *file, struct rt_pollreq *req) { @@ -251,6 +273,8 @@ static int inet_poll(struct dfs_fd *file, struct rt_pollreq *req) if (sock->errevent) { mask |= POLLERR; + /* clean error event */ + sock->errevent = 0; } rt_hw_interrupt_enable(level); } @@ -275,24 +299,13 @@ static const struct sal_socket_ops lwip_socket_ops = lwip_shutdown, lwip_getpeername, inet_getsockname, - lwip_ioctl, + inet_ioctlsocket, #ifdef SAL_USING_POSIX inet_poll, #endif }; -static int inet_create(struct sal_socket *socket, int type, int protocol) -{ - RT_ASSERT(socket); - - //TODO Check type & protocol - - socket->ops = &lwip_socket_ops; - - return 0; -} - -static struct sal_proto_ops lwip_proto_ops = +static const struct sal_netdb_ops lwip_netdb_ops = { lwip_gethostbyname, lwip_gethostbyname_r, @@ -303,17 +316,22 @@ static struct sal_proto_ops lwip_proto_ops = static const struct sal_proto_family lwip_inet_family = { AF_INET, +#if LWIP_VERSION > 0x2000000 + AF_INET6, +#else AF_INET, - inet_create, - &lwip_proto_ops, +#endif + &lwip_socket_ops, + &lwip_netdb_ops, }; -int lwip_inet_init(void) +/* Set lwIP network interface device protocol family information */ +int sal_lwip_netdev_set_pf_info(struct netdev *netdev) { - sal_proto_family_register(&lwip_inet_family); - + RT_ASSERT(netdev); + + netdev->sal_user_data = (void *) &lwip_inet_family; return 0; } -INIT_COMPONENT_EXPORT(lwip_inet_init); #endif /* SAL_USING_LWIP */ diff --git a/components/net/sal_socket/impl/proto_mbedtls.c b/components/net/sal_socket/impl/proto_mbedtls.c index 8ed9f67ff1..3472bbeaf5 100644 --- a/components/net/sal_socket/impl/proto_mbedtls.c +++ b/components/net/sal_socket/impl/proto_mbedtls.c @@ -20,6 +20,8 @@ #include <netdb.h> #include <sal.h> +#include <netdev.h> + #ifdef SAL_USING_TLS #if !defined(MBEDTLS_CONFIG_FILE) @@ -76,6 +78,7 @@ int mbedtls_net_send_cb(void *ctx, const unsigned char *buf, size_t len) { struct sal_socket *sock; int socket, ret; + struct sal_proto_family *pf; RT_ASSERT(ctx); RT_ASSERT(buf); @@ -86,9 +89,11 @@ int mbedtls_net_send_cb(void *ctx, const unsigned char *buf, size_t len) { return -1; } + + pf = (struct sal_proto_family *)sock->netdev->sal_user_data; /* Register scoket sendto option to TLS send data callback */ - ret = sock->ops->sendto((int) sock->user_data, (void *)buf, len, 0, RT_NULL, RT_NULL); + ret = pf->skt_ops->sendto((int) sock->user_data, (void *)buf, len, 0, RT_NULL, RT_NULL); if (ret < 0) { #ifdef RT_USING_DFS @@ -109,6 +114,7 @@ int mbedtls_net_send_cb(void *ctx, const unsigned char *buf, size_t len) int mbedtls_net_recv_cb( void *ctx, unsigned char *buf, size_t len) { struct sal_socket *sock; + struct sal_proto_family *pf; int socket, ret; RT_ASSERT(ctx); @@ -121,8 +127,10 @@ int mbedtls_net_recv_cb( void *ctx, unsigned char *buf, size_t len) return -1; } + pf = (struct sal_proto_family *)sock->netdev->sal_user_data; + /* Register scoket recvfrom option to TLS recv data callback */ - ret = sock->ops->recvfrom((int) sock->user_data, (void *)buf, len, 0, RT_NULL, RT_NULL); + ret = pf->skt_ops->recvfrom((int) sock->user_data, (void *)buf, len, 0, RT_NULL, RT_NULL); if (ret < 0) { #ifdef RT_USING_DFS |
