[update] Added custom functions for RT-Thread.

Signed-off-by: liuxianliang <liuxianliang@rt-thread.com>
This commit is contained in:
liuxianliang 2020-06-20 14:09:33 +08:00
parent de1fd2bfc4
commit 38db074fca
9 changed files with 112 additions and 7 deletions

View File

@ -469,6 +469,25 @@ tryget_socket(int fd)
return NULL; return NULL;
} }
/**
* Same as tryget_socket but a global routine.
*
* @param fd externally used socket index
* @return struct lwip_sock for the socket or NULL if not found
*/
struct lwip_sock *
lwip_tryget_socket(int fd)
{
struct lwip_sock *sock = tryget_socket_unconn(fd);
if (sock != NULL) {
if (sock->conn) {
return sock;
}
done_socket(sock);
}
return NULL;
}
/** /**
* Map a externally used socket index to the internal socket representation. * Map a externally used socket index to the internal socket representation.
* *
@ -530,6 +549,9 @@ alloc_socket(struct netconn *newconn, int accepted)
sockets[i].sendevent = (NETCONNTYPE_GROUP(newconn->type) == NETCONN_TCP ? (accepted != 0) : 1); sockets[i].sendevent = (NETCONNTYPE_GROUP(newconn->type) == NETCONN_TCP ? (accepted != 0) : 1);
sockets[i].errevent = 0; sockets[i].errevent = 0;
#endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */ #endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */
#ifdef SAL_USING_POSIX
rt_wqueue_init(&sockets[i].wait_head);
#endif
return i + LWIP_SOCKET_OFFSET; return i + LWIP_SOCKET_OFFSET;
} }
SYS_ARCH_UNPROTECT(lev); SYS_ARCH_UNPROTECT(lev);

View File

@ -97,6 +97,8 @@
#include <string.h> #include <string.h>
#include <rtthread.h>
/** Random generator function to create random TXIDs and source ports for queries */ /** Random generator function to create random TXIDs and source ports for queries */
#ifndef DNS_RAND_TXID #ifndef DNS_RAND_TXID
#if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_XID) != 0) #if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_XID) != 0)
@ -363,6 +365,18 @@ dns_setserver(u8_t numdns, const ip_addr_t *dnsserver)
if (numdns < DNS_MAX_SERVERS) { if (numdns < DNS_MAX_SERVERS) {
if (dnsserver != NULL) { if (dnsserver != NULL) {
dns_servers[numdns] = (*dnsserver); dns_servers[numdns] = (*dnsserver);
#ifdef RT_USING_NETDEV
extern struct netif *netif_list;
extern struct netdev *netdev_get_by_name(const char *name);
extern void netdev_low_level_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_t *dns_server);
struct netif *netif = NULL;
/* set network interface device DNS server address */
for (netif = netif_list; netif != NULL; netif = netif->next) {
netdev_low_level_set_dns_server(netdev_get_by_name(netif->name), numdns, dnsserver);
}
#endif /* RT_USING_NETDEV */
} else { } else {
dns_servers[numdns] = *IP_ADDR_ANY; dns_servers[numdns] = *IP_ADDR_ANY;
} }

View File

@ -90,6 +90,13 @@
#include "lwip/nd6.h" #include "lwip/nd6.h"
#endif #endif
#include <rtthread.h>
#ifdef RT_USING_NETDEV
#include "lwip/netdb.h"
#include <netdev.h>
#endif /* RT_USING_NETDEV */
#if LWIP_NETIF_STATUS_CALLBACK #if LWIP_NETIF_STATUS_CALLBACK
#define NETIF_STATUS_CALLBACK(n) do{ if (n->status_callback) { (n->status_callback)(n); }}while(0) #define NETIF_STATUS_CALLBACK(n) do{ if (n->status_callback) { (n->status_callback)(n); }}while(0)
#else #else
@ -481,6 +488,12 @@ netif_do_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr, ip_addr_t *ol
netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV4); netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV4);
NETIF_STATUS_CALLBACK(netif); NETIF_STATUS_CALLBACK(netif);
#ifdef RT_USING_NETDEV
/* rt-thread sal network interface device set IP address operations */
netdev_low_level_set_ipaddr(netdev_get_by_name(netif->name), &netif->ip_addr);
#endif /* RT_USING_NETDEV */
return 1; /* address changed */ return 1; /* address changed */
} }
return 0; /* address unchanged */ return 0; /* address unchanged */
@ -541,6 +554,12 @@ netif_do_set_netmask(struct netif *netif, const ip4_addr_t *netmask, ip_addr_t *
ip4_addr2_16(netif_ip4_netmask(netif)), ip4_addr2_16(netif_ip4_netmask(netif)),
ip4_addr3_16(netif_ip4_netmask(netif)), ip4_addr3_16(netif_ip4_netmask(netif)),
ip4_addr4_16(netif_ip4_netmask(netif)))); ip4_addr4_16(netif_ip4_netmask(netif))));
#ifdef RT_USING_NETDEV
/* rt-thread network interface device set netmask address */
netdev_low_level_set_netmask(netdev_get_by_name(netif->name), &netif->netmask);
#endif /* RT_USING_NETDEV */
return 1; /* netmask changed */ return 1; /* netmask changed */
} }
return 0; /* netmask unchanged */ return 0; /* netmask unchanged */
@ -603,6 +622,12 @@ netif_do_set_gw(struct netif *netif, const ip4_addr_t *gw, ip_addr_t *old_gw)
ip4_addr2_16(netif_ip4_gw(netif)), ip4_addr2_16(netif_ip4_gw(netif)),
ip4_addr3_16(netif_ip4_gw(netif)), ip4_addr3_16(netif_ip4_gw(netif)),
ip4_addr4_16(netif_ip4_gw(netif)))); ip4_addr4_16(netif_ip4_gw(netif))));
#ifdef RT_USING_NETDEV
/* rt_thread network interface device set gateway address */
netdev_low_level_set_gw(netdev_get_by_name(netif->name), &netif->gw);
#endif /* RT_USING_NETDEV */
return 1; /* gateway changed */ return 1; /* gateway changed */
} }
return 0; /* gateway unchanged */ return 0; /* gateway unchanged */
@ -866,6 +891,11 @@ netif_set_up(struct netif *netif)
#if LWIP_IPV6 #if LWIP_IPV6
nd6_restart_netif(netif); nd6_restart_netif(netif);
#endif /* LWIP_IPV6 */ #endif /* LWIP_IPV6 */
#ifdef RT_USING_NETDEV
/* rt-thread network interface device set up status */
netdev_low_level_set_status(netdev_get_by_name(netif->name), RT_TRUE);
#endif /* RT_USING_NETDEV */
} }
} }
@ -945,6 +975,11 @@ netif_set_down(struct netif *netif)
#endif /* LWIP_IPV6 */ #endif /* LWIP_IPV6 */
NETIF_STATUS_CALLBACK(netif); NETIF_STATUS_CALLBACK(netif);
#ifdef RT_USING_NETDEV
/* rt-thread network interface device set down status */
netdev_low_level_set_status(netdev_get_by_name(netif->name), RT_FALSE);
#endif /* RT_USING_NETDEV */
} }
} }
@ -1015,6 +1050,11 @@ netif_set_link_up(struct netif *netif)
netif_invoke_ext_callback(netif, LWIP_NSC_LINK_CHANGED, &args); netif_invoke_ext_callback(netif, LWIP_NSC_LINK_CHANGED, &args);
} }
#endif #endif
#ifdef RT_USING_NETDEV
/* rt-thread network interface device set link up status */
netdev_low_level_set_link_status(netdev_get_by_name(netif->name), RT_TRUE);
#endif /* RT_USING_NETDEV */
} }
} }
@ -1039,6 +1079,11 @@ netif_set_link_down(struct netif *netif)
netif_invoke_ext_callback(netif, LWIP_NSC_LINK_CHANGED, &args); netif_invoke_ext_callback(netif, LWIP_NSC_LINK_CHANGED, &args);
} }
#endif #endif
#ifdef RT_USING_NETDEV
/* rt-thread network interface device set link down status */
netdev_low_level_set_link_status(netdev_get_by_name(netif->name), RT_FALSE);
#endif /* RT_USING_NETDEV */
} }
} }
@ -1541,6 +1586,11 @@ netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit)
* zone field, so this should not create any compatibility problems. */ * zone field, so this should not create any compatibility problems. */
ip6_addr_assign_zone(ip_2_ip6(&netif->ip6_addr[0]), IP6_UNICAST, netif); ip6_addr_assign_zone(ip_2_ip6(&netif->ip6_addr[0]), IP6_UNICAST, netif);
#ifdef RT_USING_NETDEV
/* rt-thread network interface device set ipv6 address */
ip_addr_copy(netdev_get_by_name(netif->name)->ip6_addr[0], netif->ip6_addr[0]);
#endif /* RT_USING_NETDEV */
/* Set address state. */ /* Set address state. */
#if LWIP_IPV6_DUP_DETECT_ATTEMPTS #if LWIP_IPV6_DUP_DETECT_ATTEMPTS
/* Will perform duplicate address detection (DAD). */ /* Will perform duplicate address detection (DAD). */
@ -1584,6 +1634,10 @@ netif_add_ip6_address(struct netif *netif, const ip6_addr_t *ip6addr, s8_t *chos
for (i = ip6_addr_islinklocal(ip6addr) ? 0 : 1; i < LWIP_IPV6_NUM_ADDRESSES; i++) { for (i = ip6_addr_islinklocal(ip6addr) ? 0 : 1; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
if (ip6_addr_isinvalid(netif_ip6_addr_state(netif, i))) { if (ip6_addr_isinvalid(netif_ip6_addr_state(netif, i))) {
ip_addr_copy_from_ip6(netif->ip6_addr[i], *ip6addr); ip_addr_copy_from_ip6(netif->ip6_addr[i], *ip6addr);
#ifdef RT_USING_NETDEV
/* rt-thread network interface device set ipv6 address */
ip_addr_copy(netdev_get_by_name(netif->name)->ip6_addr[i], netif->ip6_addr[i]);
#endif /* RT_USING_NETDEV */
ip6_addr_assign_zone(ip_2_ip6(&netif->ip6_addr[i]), IP6_UNICAST, netif); ip6_addr_assign_zone(ip_2_ip6(&netif->ip6_addr[i]), IP6_UNICAST, netif);
netif_ip6_addr_set_state(netif, i, IP6_ADDR_TENTATIVE); netif_ip6_addr_set_state(netif, i, IP6_ADDR_TENTATIVE);
if (chosen_idx != NULL) { if (chosen_idx != NULL) {

View File

@ -196,7 +196,9 @@ typedef uintptr_t mem_ptr_t;
#define LWIP_NO_UNISTD_H 0 #define LWIP_NO_UNISTD_H 0
#endif #endif
#if !LWIP_NO_UNISTD_H #if !LWIP_NO_UNISTD_H
#include <unistd.h> #include "sys/types.h"
#else
typedef int ssize_t;
#endif #endif
#else /* SSIZE_MAX */ #else /* SSIZE_MAX */
typedef int ssize_t; typedef int ssize_t;

View File

@ -50,20 +50,20 @@ extern "C" {
*/ */
/** X.x.x: Major version of the stack */ /** X.x.x: Major version of the stack */
#define LWIP_VERSION_MAJOR 2 #define LWIP_VERSION_MAJOR 2U
/** x.X.x: Minor version of the stack */ /** x.X.x: Minor version of the stack */
#define LWIP_VERSION_MINOR 1 #define LWIP_VERSION_MINOR 1U
/** x.x.X: Revision of the stack */ /** x.x.X: Revision of the stack */
#define LWIP_VERSION_REVISION 2 #define LWIP_VERSION_REVISION 2U
/** For release candidates, this is set to 1..254 /** For release candidates, this is set to 1..254
* For official releases, this is set to 255 (LWIP_RC_RELEASE) * For official releases, this is set to 255 (LWIP_RC_RELEASE)
* For development versions (Git), this is set to 0 (LWIP_RC_DEVELOPMENT) */ * For development versions (Git), this is set to 0 (LWIP_RC_DEVELOPMENT) */
#define LWIP_VERSION_RC LWIP_RC_RELEASE #define LWIP_VERSION_RC LWIP_RC_RELEASE
/** LWIP_VERSION_RC is set to LWIP_RC_RELEASE for official releases */ /** LWIP_VERSION_RC is set to LWIP_RC_RELEASE for official releases */
#define LWIP_RC_RELEASE 255 #define LWIP_RC_RELEASE 255U
/** LWIP_VERSION_RC is set to LWIP_RC_DEVELOPMENT for Git versions */ /** LWIP_VERSION_RC is set to LWIP_RC_DEVELOPMENT for Git versions */
#define LWIP_RC_DEVELOPMENT 0 #define LWIP_RC_DEVELOPMENT 0U
#define LWIP_VERSION_IS_RELEASE (LWIP_VERSION_RC == LWIP_RC_RELEASE) #define LWIP_VERSION_IS_RELEASE (LWIP_VERSION_RC == LWIP_RC_RELEASE)
#define LWIP_VERSION_IS_DEVELOPMENT (LWIP_VERSION_RC == LWIP_RC_DEVELOPMENT) #define LWIP_VERSION_IS_DEVELOPMENT (LWIP_VERSION_RC == LWIP_RC_DEVELOPMENT)

View File

@ -63,6 +63,11 @@ union lwip_sock_lastdata {
struct pbuf *pbuf; struct pbuf *pbuf;
}; };
#include <rtthread.h>
#ifdef SAL_USING_POSIX
#include <ipc/waitqueue.h>
#endif
/** Contains all internal pointers and states used for a socket */ /** Contains all internal pointers and states used for a socket */
struct lwip_sock { struct lwip_sock {
/** sockets currently are built on netconns, each socket has one netconn */ /** sockets currently are built on netconns, each socket has one netconn */
@ -89,6 +94,10 @@ struct lwip_sock {
#define LWIP_SOCK_FD_FREE_TCP 1 #define LWIP_SOCK_FD_FREE_TCP 1
#define LWIP_SOCK_FD_FREE_FREE 2 #define LWIP_SOCK_FD_FREE_FREE 2
#endif #endif
#ifdef SAL_USING_POSIX
rt_wqueue_t wait_head;
#endif
}; };
#ifndef set_errno #ifndef set_errno

View File

@ -68,6 +68,8 @@ enum lwip_ieee_eth_type {
ETHTYPE_PPPOE = 0x8864U, ETHTYPE_PPPOE = 0x8864U,
/** Jumbo Frames */ /** Jumbo Frames */
ETHTYPE_JUMBO = 0x8870U, ETHTYPE_JUMBO = 0x8870U,
/** EAPOL, EAP over LAN */
ETHTYPE_EAPOL = 0x888EU,
/** Process field network */ /** Process field network */
ETHTYPE_PROFINET = 0x8892U, ETHTYPE_PROFINET = 0x8892U,
/** Ethernet for control automation technology */ /** Ethernet for control automation technology */

View File

@ -489,6 +489,7 @@ typedef struct fd_set
#define LWIP_SELECT_MAXNFDS FD_SETSIZE #define LWIP_SELECT_MAXNFDS FD_SETSIZE
#endif /* FD_SET */ #endif /* FD_SET */
#if LWIP_SOCKET_SELECT
/* poll-related defines and types */ /* poll-related defines and types */
/* @todo: find a better way to guard the definition of these defines and types if already defined */ /* @todo: find a better way to guard the definition of these defines and types if already defined */
#if !defined(POLLIN) && !defined(POLLOUT) #if !defined(POLLIN) && !defined(POLLOUT)
@ -511,6 +512,7 @@ struct pollfd
short revents; short revents;
}; };
#endif #endif
#endif
/** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided
* by your system, set this to 0 and include <sys/time.h> in cc.h */ * by your system, set this to 0 and include <sys/time.h> in cc.h */

View File

@ -50,7 +50,7 @@
#include "netif/lowpan6.h" #include "netif/lowpan6.h"
#if LWIP_IPV6 #if LWIP_IPV6 && LWIP_6LOWPAN
#include "lwip/ip.h" #include "lwip/ip.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"