[net][netdev]add network interface device components, SAL component adaptation netdev change

This commit is contained in:
chenyong
2019-04-16 18:24:55 +08:00
parent c8870b4268
commit 3d6e0ea374
18 changed files with 2077 additions and 730 deletions
+10 -6
View File
@@ -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
}
+11 -19
View File
@@ -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)
{
sal_proto_family_register(&at_inet_family);
/* Set AT network interface device protocol family information */
int sal_at_netdev_set_pf_info(struct netdev *netdev)
{
RT_ASSERT(netdev);
netdev->sal_user_data = (void *) &at_inet_family;
return 0;
}
INIT_COMPONENT_EXPORT(at_inet_init);
#endif /* SAL_USING_AT */
+11 -18
View File
@@ -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 */
+10 -2
View File
@@ -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