summaryrefslogtreecommitdiff
path: root/components/net/sal_socket/impl
diff options
context:
space:
mode:
authorchenyong <[email protected]>2019-04-16 18:24:55 +0800
committerchenyong <[email protected]>2019-04-16 18:24:55 +0800
commit3d6e0ea3746215e4391dd56e373ad78c9689be5c (patch)
treebe7c89592f561a34bd7a8cf0e0b66ba6bf9e81d9 /components/net/sal_socket/impl
parentc8870b4268d3125e002a533823fa61891d6a3982 (diff)
[net][netdev]add network interface device components, SAL component adaptation netdev change
Diffstat (limited to 'components/net/sal_socket/impl')
-rw-r--r--components/net/sal_socket/impl/af_inet.h16
-rw-r--r--components/net/sal_socket/impl/af_inet_at.c28
-rw-r--r--components/net/sal_socket/impl/af_inet_lwip.c29
-rw-r--r--components/net/sal_socket/impl/proto_mbedtls.c12
4 files changed, 41 insertions, 44 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..cb271a55e0 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,8 @@
#include <sal.h>
#include <af_inet.h>
+#include <netdev.h>
+
#if LWIP_VERSION < 0x2000000
#define SELWAIT_T int
#else
@@ -281,18 +284,7 @@ static const struct sal_socket_ops lwip_socket_ops =
#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,
@@ -304,16 +296,17 @@ static const struct sal_proto_family lwip_inet_family =
{
AF_INET,
AF_INET,
- inet_create,
- &lwip_proto_ops,
+ &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