diff --git a/components/net/lwip-2.1.2/src/api/sockets.c b/components/net/lwip-2.1.2/src/api/sockets.c index cb7df914fa..4fea5b3727 100644 --- a/components/net/lwip-2.1.2/src/api/sockets.c +++ b/components/net/lwip-2.1.2/src/api/sockets.c @@ -469,6 +469,25 @@ tryget_socket(int fd) 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. * @@ -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].errevent = 0; #endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */ +#ifdef SAL_USING_POSIX + rt_wqueue_init(&sockets[i].wait_head); +#endif return i + LWIP_SOCKET_OFFSET; } SYS_ARCH_UNPROTECT(lev); diff --git a/components/net/lwip-2.1.2/src/core/dns.c b/components/net/lwip-2.1.2/src/core/dns.c index 9d2f61ed86..c688cb2205 100644 --- a/components/net/lwip-2.1.2/src/core/dns.c +++ b/components/net/lwip-2.1.2/src/core/dns.c @@ -97,6 +97,8 @@ #include +#include + /** Random generator function to create random TXIDs and source ports for queries */ #ifndef DNS_RAND_TXID #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 (dnsserver != NULL) { 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 { dns_servers[numdns] = *IP_ADDR_ANY; } diff --git a/components/net/lwip-2.1.2/src/core/netif.c b/components/net/lwip-2.1.2/src/core/netif.c index 15200a2740..b2b4adf85b 100644 --- a/components/net/lwip-2.1.2/src/core/netif.c +++ b/components/net/lwip-2.1.2/src/core/netif.c @@ -90,6 +90,13 @@ #include "lwip/nd6.h" #endif +#include + +#ifdef RT_USING_NETDEV +#include "lwip/netdb.h" +#include +#endif /* RT_USING_NETDEV */ + #if LWIP_NETIF_STATUS_CALLBACK #define NETIF_STATUS_CALLBACK(n) do{ if (n->status_callback) { (n->status_callback)(n); }}while(0) #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_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 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_addr3_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 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_addr3_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 0; /* gateway unchanged */ @@ -866,6 +891,11 @@ netif_set_up(struct netif *netif) #if LWIP_IPV6 nd6_restart_netif(netif); #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 */ 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); } #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); } #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. */ 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. */ #if LWIP_IPV6_DUP_DETECT_ATTEMPTS /* 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++) { if (ip6_addr_isinvalid(netif_ip6_addr_state(netif, i))) { 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); netif_ip6_addr_set_state(netif, i, IP6_ADDR_TENTATIVE); if (chosen_idx != NULL) { diff --git a/components/net/lwip-2.1.2/src/include/lwip/arch.h b/components/net/lwip-2.1.2/src/include/lwip/arch.h index 58dae33aa1..1606d4faab 100644 --- a/components/net/lwip-2.1.2/src/include/lwip/arch.h +++ b/components/net/lwip-2.1.2/src/include/lwip/arch.h @@ -196,7 +196,9 @@ typedef uintptr_t mem_ptr_t; #define LWIP_NO_UNISTD_H 0 #endif #if !LWIP_NO_UNISTD_H -#include +#include "sys/types.h" +#else +typedef int ssize_t; #endif #else /* SSIZE_MAX */ typedef int ssize_t; diff --git a/components/net/lwip-2.1.2/src/include/lwip/init.h b/components/net/lwip-2.1.2/src/include/lwip/init.h index a149be1848..b2c385c3bb 100644 --- a/components/net/lwip-2.1.2/src/include/lwip/init.h +++ b/components/net/lwip-2.1.2/src/include/lwip/init.h @@ -50,20 +50,20 @@ extern "C" { */ /** 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 */ -#define LWIP_VERSION_MINOR 1 +#define LWIP_VERSION_MINOR 1U /** 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 official releases, this is set to 255 (LWIP_RC_RELEASE) * For development versions (Git), this is set to 0 (LWIP_RC_DEVELOPMENT) */ #define LWIP_VERSION_RC LWIP_RC_RELEASE /** 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 */ -#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_DEVELOPMENT (LWIP_VERSION_RC == LWIP_RC_DEVELOPMENT) diff --git a/components/net/lwip-2.1.2/src/include/lwip/priv/sockets_priv.h b/components/net/lwip-2.1.2/src/include/lwip/priv/sockets_priv.h index d8f9904dcf..9193fa0c1b 100644 --- a/components/net/lwip-2.1.2/src/include/lwip/priv/sockets_priv.h +++ b/components/net/lwip-2.1.2/src/include/lwip/priv/sockets_priv.h @@ -63,6 +63,11 @@ union lwip_sock_lastdata { struct pbuf *pbuf; }; +#include +#ifdef SAL_USING_POSIX +#include +#endif + /** Contains all internal pointers and states used for a socket */ struct lwip_sock { /** 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_FREE 2 #endif + +#ifdef SAL_USING_POSIX + rt_wqueue_t wait_head; +#endif }; #ifndef set_errno diff --git a/components/net/lwip-2.1.2/src/include/lwip/prot/ieee.h b/components/net/lwip-2.1.2/src/include/lwip/prot/ieee.h index abbb9e31d1..db865635be 100644 --- a/components/net/lwip-2.1.2/src/include/lwip/prot/ieee.h +++ b/components/net/lwip-2.1.2/src/include/lwip/prot/ieee.h @@ -68,6 +68,8 @@ enum lwip_ieee_eth_type { ETHTYPE_PPPOE = 0x8864U, /** Jumbo Frames */ ETHTYPE_JUMBO = 0x8870U, + /** EAPOL, EAP over LAN */ + ETHTYPE_EAPOL = 0x888EU, /** Process field network */ ETHTYPE_PROFINET = 0x8892U, /** Ethernet for control automation technology */ diff --git a/components/net/lwip-2.1.2/src/include/lwip/sockets.h b/components/net/lwip-2.1.2/src/include/lwip/sockets.h index d70d36c4d2..12ffbddccc 100644 --- a/components/net/lwip-2.1.2/src/include/lwip/sockets.h +++ b/components/net/lwip-2.1.2/src/include/lwip/sockets.h @@ -489,6 +489,7 @@ typedef struct fd_set #define LWIP_SELECT_MAXNFDS FD_SETSIZE #endif /* FD_SET */ +#if LWIP_SOCKET_SELECT /* poll-related defines and types */ /* @todo: find a better way to guard the definition of these defines and types if already defined */ #if !defined(POLLIN) && !defined(POLLOUT) @@ -511,6 +512,7 @@ struct pollfd short revents; }; #endif +#endif /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided * by your system, set this to 0 and include in cc.h */ diff --git a/components/net/lwip-2.1.2/src/netif/lowpan6.c b/components/net/lwip-2.1.2/src/netif/lowpan6.c index 7f0d276766..b180b0c2e7 100644 --- a/components/net/lwip-2.1.2/src/netif/lowpan6.c +++ b/components/net/lwip-2.1.2/src/netif/lowpan6.c @@ -50,7 +50,7 @@ #include "netif/lowpan6.h" -#if LWIP_IPV6 +#if LWIP_IPV6 && LWIP_6LOWPAN #include "lwip/ip.h" #include "lwip/pbuf.h"