Skip to content

Commit 38db074

Browse files
author
liuxianliang
committed
[update] Added custom functions for RT-Thread.
Signed-off-by: liuxianliang <[email protected]>
1 parent de1fd2b commit 38db074

File tree

9 files changed

+112
-7
lines changed

9 files changed

+112
-7
lines changed

components/net/lwip-2.1.2/src/api/sockets.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,25 @@ tryget_socket(int fd)
469469
return NULL;
470470
}
471471

472+
/**
473+
* Same as tryget_socket but a global routine.
474+
*
475+
* @param fd externally used socket index
476+
* @return struct lwip_sock for the socket or NULL if not found
477+
*/
478+
struct lwip_sock *
479+
lwip_tryget_socket(int fd)
480+
{
481+
struct lwip_sock *sock = tryget_socket_unconn(fd);
482+
if (sock != NULL) {
483+
if (sock->conn) {
484+
return sock;
485+
}
486+
done_socket(sock);
487+
}
488+
return NULL;
489+
}
490+
472491
/**
473492
* Map a externally used socket index to the internal socket representation.
474493
*
@@ -530,6 +549,9 @@ alloc_socket(struct netconn *newconn, int accepted)
530549
sockets[i].sendevent = (NETCONNTYPE_GROUP(newconn->type) == NETCONN_TCP ? (accepted != 0) : 1);
531550
sockets[i].errevent = 0;
532551
#endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */
552+
#ifdef SAL_USING_POSIX
553+
rt_wqueue_init(&sockets[i].wait_head);
554+
#endif
533555
return i + LWIP_SOCKET_OFFSET;
534556
}
535557
SYS_ARCH_UNPROTECT(lev);

components/net/lwip-2.1.2/src/core/dns.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797

9898
#include <string.h>
9999

100+
#include <rtthread.h>
101+
100102
/** Random generator function to create random TXIDs and source ports for queries */
101103
#ifndef DNS_RAND_TXID
102104
#if ((LWIP_DNS_SECURE & LWIP_DNS_SECURE_RAND_XID) != 0)
@@ -363,6 +365,18 @@ dns_setserver(u8_t numdns, const ip_addr_t *dnsserver)
363365
if (numdns < DNS_MAX_SERVERS) {
364366
if (dnsserver != NULL) {
365367
dns_servers[numdns] = (*dnsserver);
368+
369+
#ifdef RT_USING_NETDEV
370+
extern struct netif *netif_list;
371+
extern struct netdev *netdev_get_by_name(const char *name);
372+
extern void netdev_low_level_set_dns_server(struct netdev *netdev, uint8_t dns_num, const ip_addr_t *dns_server);
373+
struct netif *netif = NULL;
374+
375+
/* set network interface device DNS server address */
376+
for (netif = netif_list; netif != NULL; netif = netif->next) {
377+
netdev_low_level_set_dns_server(netdev_get_by_name(netif->name), numdns, dnsserver);
378+
}
379+
#endif /* RT_USING_NETDEV */
366380
} else {
367381
dns_servers[numdns] = *IP_ADDR_ANY;
368382
}

components/net/lwip-2.1.2/src/core/netif.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@
9090
#include "lwip/nd6.h"
9191
#endif
9292

93+
#include <rtthread.h>
94+
95+
#ifdef RT_USING_NETDEV
96+
#include "lwip/netdb.h"
97+
#include <netdev.h>
98+
#endif /* RT_USING_NETDEV */
99+
93100
#if LWIP_NETIF_STATUS_CALLBACK
94101
#define NETIF_STATUS_CALLBACK(n) do{ if (n->status_callback) { (n->status_callback)(n); }}while(0)
95102
#else
@@ -481,6 +488,12 @@ netif_do_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr, ip_addr_t *ol
481488
netif_issue_reports(netif, NETIF_REPORT_TYPE_IPV4);
482489

483490
NETIF_STATUS_CALLBACK(netif);
491+
492+
#ifdef RT_USING_NETDEV
493+
/* rt-thread sal network interface device set IP address operations */
494+
netdev_low_level_set_ipaddr(netdev_get_by_name(netif->name), &netif->ip_addr);
495+
#endif /* RT_USING_NETDEV */
496+
484497
return 1; /* address changed */
485498
}
486499
return 0; /* address unchanged */
@@ -541,6 +554,12 @@ netif_do_set_netmask(struct netif *netif, const ip4_addr_t *netmask, ip_addr_t *
541554
ip4_addr2_16(netif_ip4_netmask(netif)),
542555
ip4_addr3_16(netif_ip4_netmask(netif)),
543556
ip4_addr4_16(netif_ip4_netmask(netif))));
557+
558+
#ifdef RT_USING_NETDEV
559+
/* rt-thread network interface device set netmask address */
560+
netdev_low_level_set_netmask(netdev_get_by_name(netif->name), &netif->netmask);
561+
#endif /* RT_USING_NETDEV */
562+
544563
return 1; /* netmask changed */
545564
}
546565
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)
603622
ip4_addr2_16(netif_ip4_gw(netif)),
604623
ip4_addr3_16(netif_ip4_gw(netif)),
605624
ip4_addr4_16(netif_ip4_gw(netif))));
625+
626+
#ifdef RT_USING_NETDEV
627+
/* rt_thread network interface device set gateway address */
628+
netdev_low_level_set_gw(netdev_get_by_name(netif->name), &netif->gw);
629+
#endif /* RT_USING_NETDEV */
630+
606631
return 1; /* gateway changed */
607632
}
608633
return 0; /* gateway unchanged */
@@ -866,6 +891,11 @@ netif_set_up(struct netif *netif)
866891
#if LWIP_IPV6
867892
nd6_restart_netif(netif);
868893
#endif /* LWIP_IPV6 */
894+
895+
#ifdef RT_USING_NETDEV
896+
/* rt-thread network interface device set up status */
897+
netdev_low_level_set_status(netdev_get_by_name(netif->name), RT_TRUE);
898+
#endif /* RT_USING_NETDEV */
869899
}
870900
}
871901

@@ -945,6 +975,11 @@ netif_set_down(struct netif *netif)
945975
#endif /* LWIP_IPV6 */
946976

947977
NETIF_STATUS_CALLBACK(netif);
978+
979+
#ifdef RT_USING_NETDEV
980+
/* rt-thread network interface device set down status */
981+
netdev_low_level_set_status(netdev_get_by_name(netif->name), RT_FALSE);
982+
#endif /* RT_USING_NETDEV */
948983
}
949984
}
950985

@@ -1015,6 +1050,11 @@ netif_set_link_up(struct netif *netif)
10151050
netif_invoke_ext_callback(netif, LWIP_NSC_LINK_CHANGED, &args);
10161051
}
10171052
#endif
1053+
1054+
#ifdef RT_USING_NETDEV
1055+
/* rt-thread network interface device set link up status */
1056+
netdev_low_level_set_link_status(netdev_get_by_name(netif->name), RT_TRUE);
1057+
#endif /* RT_USING_NETDEV */
10181058
}
10191059
}
10201060

@@ -1039,6 +1079,11 @@ netif_set_link_down(struct netif *netif)
10391079
netif_invoke_ext_callback(netif, LWIP_NSC_LINK_CHANGED, &args);
10401080
}
10411081
#endif
1082+
1083+
#ifdef RT_USING_NETDEV
1084+
/* rt-thread network interface device set link down status */
1085+
netdev_low_level_set_link_status(netdev_get_by_name(netif->name), RT_FALSE);
1086+
#endif /* RT_USING_NETDEV */
10421087
}
10431088
}
10441089

@@ -1541,6 +1586,11 @@ netif_create_ip6_linklocal_address(struct netif *netif, u8_t from_mac_48bit)
15411586
* zone field, so this should not create any compatibility problems. */
15421587
ip6_addr_assign_zone(ip_2_ip6(&netif->ip6_addr[0]), IP6_UNICAST, netif);
15431588

1589+
#ifdef RT_USING_NETDEV
1590+
/* rt-thread network interface device set ipv6 address */
1591+
ip_addr_copy(netdev_get_by_name(netif->name)->ip6_addr[0], netif->ip6_addr[0]);
1592+
#endif /* RT_USING_NETDEV */
1593+
15441594
/* Set address state. */
15451595
#if LWIP_IPV6_DUP_DETECT_ATTEMPTS
15461596
/* 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
15841634
for (i = ip6_addr_islinklocal(ip6addr) ? 0 : 1; i < LWIP_IPV6_NUM_ADDRESSES; i++) {
15851635
if (ip6_addr_isinvalid(netif_ip6_addr_state(netif, i))) {
15861636
ip_addr_copy_from_ip6(netif->ip6_addr[i], *ip6addr);
1637+
#ifdef RT_USING_NETDEV
1638+
/* rt-thread network interface device set ipv6 address */
1639+
ip_addr_copy(netdev_get_by_name(netif->name)->ip6_addr[i], netif->ip6_addr[i]);
1640+
#endif /* RT_USING_NETDEV */
15871641
ip6_addr_assign_zone(ip_2_ip6(&netif->ip6_addr[i]), IP6_UNICAST, netif);
15881642
netif_ip6_addr_set_state(netif, i, IP6_ADDR_TENTATIVE);
15891643
if (chosen_idx != NULL) {

components/net/lwip-2.1.2/src/include/lwip/arch.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ typedef uintptr_t mem_ptr_t;
196196
#define LWIP_NO_UNISTD_H 0
197197
#endif
198198
#if !LWIP_NO_UNISTD_H
199-
#include <unistd.h>
199+
#include "sys/types.h"
200+
#else
201+
typedef int ssize_t;
200202
#endif
201203
#else /* SSIZE_MAX */
202204
typedef int ssize_t;

components/net/lwip-2.1.2/src/include/lwip/init.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ extern "C" {
5050
*/
5151

5252
/** X.x.x: Major version of the stack */
53-
#define LWIP_VERSION_MAJOR 2
53+
#define LWIP_VERSION_MAJOR 2U
5454
/** x.X.x: Minor version of the stack */
55-
#define LWIP_VERSION_MINOR 1
55+
#define LWIP_VERSION_MINOR 1U
5656
/** x.x.X: Revision of the stack */
57-
#define LWIP_VERSION_REVISION 2
57+
#define LWIP_VERSION_REVISION 2U
5858
/** For release candidates, this is set to 1..254
5959
* For official releases, this is set to 255 (LWIP_RC_RELEASE)
6060
* For development versions (Git), this is set to 0 (LWIP_RC_DEVELOPMENT) */
6161
#define LWIP_VERSION_RC LWIP_RC_RELEASE
6262

6363
/** LWIP_VERSION_RC is set to LWIP_RC_RELEASE for official releases */
64-
#define LWIP_RC_RELEASE 255
64+
#define LWIP_RC_RELEASE 255U
6565
/** LWIP_VERSION_RC is set to LWIP_RC_DEVELOPMENT for Git versions */
66-
#define LWIP_RC_DEVELOPMENT 0
66+
#define LWIP_RC_DEVELOPMENT 0U
6767

6868
#define LWIP_VERSION_IS_RELEASE (LWIP_VERSION_RC == LWIP_RC_RELEASE)
6969
#define LWIP_VERSION_IS_DEVELOPMENT (LWIP_VERSION_RC == LWIP_RC_DEVELOPMENT)

components/net/lwip-2.1.2/src/include/lwip/priv/sockets_priv.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ union lwip_sock_lastdata {
6363
struct pbuf *pbuf;
6464
};
6565

66+
#include <rtthread.h>
67+
#ifdef SAL_USING_POSIX
68+
#include <ipc/waitqueue.h>
69+
#endif
70+
6671
/** Contains all internal pointers and states used for a socket */
6772
struct lwip_sock {
6873
/** sockets currently are built on netconns, each socket has one netconn */
@@ -89,6 +94,10 @@ struct lwip_sock {
8994
#define LWIP_SOCK_FD_FREE_TCP 1
9095
#define LWIP_SOCK_FD_FREE_FREE 2
9196
#endif
97+
98+
#ifdef SAL_USING_POSIX
99+
rt_wqueue_t wait_head;
100+
#endif
92101
};
93102

94103
#ifndef set_errno

components/net/lwip-2.1.2/src/include/lwip/prot/ieee.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ enum lwip_ieee_eth_type {
6868
ETHTYPE_PPPOE = 0x8864U,
6969
/** Jumbo Frames */
7070
ETHTYPE_JUMBO = 0x8870U,
71+
/** EAPOL, EAP over LAN */
72+
ETHTYPE_EAPOL = 0x888EU,
7173
/** Process field network */
7274
ETHTYPE_PROFINET = 0x8892U,
7375
/** Ethernet for control automation technology */

components/net/lwip-2.1.2/src/include/lwip/sockets.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ typedef struct fd_set
489489
#define LWIP_SELECT_MAXNFDS FD_SETSIZE
490490
#endif /* FD_SET */
491491

492+
#if LWIP_SOCKET_SELECT
492493
/* poll-related defines and types */
493494
/* @todo: find a better way to guard the definition of these defines and types if already defined */
494495
#if !defined(POLLIN) && !defined(POLLOUT)
@@ -511,6 +512,7 @@ struct pollfd
511512
short revents;
512513
};
513514
#endif
515+
#endif
514516

515517
/** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided
516518
* by your system, set this to 0 and include <sys/time.h> in cc.h */

components/net/lwip-2.1.2/src/netif/lowpan6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
#include "netif/lowpan6.h"
5252

53-
#if LWIP_IPV6
53+
#if LWIP_IPV6 && LWIP_6LOWPAN
5454

5555
#include "lwip/ip.h"
5656
#include "lwip/pbuf.h"

0 commit comments

Comments
 (0)