From b7ac5f4236f1cc55078aeaf99be2c2f941199ca9 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sat, 7 Oct 2017 12:43:22 +0000 Subject: lwIP 2.0.3 integrated git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10790 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- ext/lwip-2.0.3-patched.7z | Bin 0 -> 2506479 bytes os/various/lwip_bindings/arch/cc.h | 22 +------ os/various/lwip_bindings/lwip.mk | 52 +++------------ os/various/lwip_bindings/lwipthread.c | 119 ++++++++++++++++++++++------------ os/various/lwip_bindings/lwipthread.h | 2 +- readme.txt | 1 + 6 files changed, 91 insertions(+), 105 deletions(-) create mode 100644 ext/lwip-2.0.3-patched.7z diff --git a/ext/lwip-2.0.3-patched.7z b/ext/lwip-2.0.3-patched.7z new file mode 100644 index 000000000..39c12e7e9 Binary files /dev/null and b/ext/lwip-2.0.3-patched.7z differ diff --git a/os/various/lwip_bindings/arch/cc.h b/os/various/lwip_bindings/arch/cc.h index 4c1d4f379..50c677a03 100644 --- a/os/various/lwip_bindings/arch/cc.h +++ b/os/various/lwip_bindings/arch/cc.h @@ -53,28 +53,10 @@ #include -typedef uint8_t u8_t; -typedef int8_t s8_t; -typedef uint16_t u16_t; -typedef int16_t s16_t; -typedef uint32_t u32_t; -typedef int32_t s32_t; -typedef uint32_t mem_ptr_t; - -#define PACK_STRUCT_STRUCT __attribute__((packed)) - -#ifndef BYTE_ORDER -#define BYTE_ORDER LITTLE_ENDIAN -#endif +/* Use errno provided by system. */ +#define LWIP_ERRNO_INCLUDE /** - * @brief Use lwIP provided error codes by default. - */ -#ifndef LWIP_PROVIDE_ERRNO -#define LWIP_PROVIDE_ERRNO 1 -#endif - -/** * @brief Use system provided struct timeval by default. */ #ifndef LWIP_TIMEVAL_PRIVATE diff --git a/os/various/lwip_bindings/lwip.mk b/os/various/lwip_bindings/lwip.mk index 2ab332a09..7674931f3 100644 --- a/os/various/lwip_bindings/lwip.mk +++ b/os/various/lwip_bindings/lwip.mk @@ -1,54 +1,18 @@ # List of the required lwIP files. -LWIP = $(CHIBIOS)/ext/lwip +LWIPDIR = $(CHIBIOS)/ext/lwip/src + +# The various blocks of files are outlined in Filelists.mk. +include $(LWIPDIR)/Filelists.mk LWBINDSRC = \ $(CHIBIOS)/os/various/lwip_bindings/lwipthread.c \ $(CHIBIOS)/os/various/lwip_bindings/arch/sys_arch.c -LWNETIFSRC = \ - $(LWIP)/src/netif/etharp.c - -LWCORESRC = \ - $(LWIP)/src/core/dhcp.c \ - $(LWIP)/src/core/dns.c \ - $(LWIP)/src/core/init.c \ - $(LWIP)/src/core/mem.c \ - $(LWIP)/src/core/memp.c \ - $(LWIP)/src/core/netif.c \ - $(LWIP)/src/core/pbuf.c \ - $(LWIP)/src/core/raw.c \ - $(LWIP)/src/core/stats.c \ - $(LWIP)/src/core/sys.c \ - $(LWIP)/src/core/tcp.c \ - $(LWIP)/src/core/tcp_in.c \ - $(LWIP)/src/core/tcp_out.c \ - $(LWIP)/src/core/udp.c - -LWIPV4SRC = \ - $(LWIP)/src/core/ipv4/autoip.c \ - $(LWIP)/src/core/ipv4/icmp.c \ - $(LWIP)/src/core/ipv4/igmp.c \ - $(LWIP)/src/core/ipv4/inet.c \ - $(LWIP)/src/core/ipv4/inet_chksum.c \ - $(LWIP)/src/core/ipv4/ip.c \ - $(LWIP)/src/core/ipv4/ip_addr.c \ - $(LWIP)/src/core/ipv4/ip_frag.c \ - $(LWIP)/src/core/def.c \ - $(LWIP)/src/core/timers.c - -LWAPISRC = \ - $(LWIP)/src/api/api_lib.c \ - $(LWIP)/src/api/api_msg.c \ - $(LWIP)/src/api/err.c \ - $(LWIP)/src/api/netbuf.c \ - $(LWIP)/src/api/netdb.c \ - $(LWIP)/src/api/netifapi.c \ - $(LWIP)/src/api/sockets.c \ - $(LWIP)/src/api/tcpip.c -LWSRC = $(LWBINDSRC) $(LWNETIFSRC) $(LWCORESRC) $(LWIPV4SRC) $(LWAPISRC) +# Add blocks of files from Filelists.mk as required for enabled options +LWSRC = $(COREFILES) $(CORE4FILES) $(APIFILES) $(LWBINDSRC) $(NETIFFILES) $(HTTPDFILES) LWINC = \ $(CHIBIOS)/os/various/lwip_bindings \ - $(LWIP)/src/include \ - $(LWIP)/src/include/ipv4 + $(LWIPDIR)/include \ + $(LWIPDIR)/include/lwip/apps diff --git a/os/various/lwip_bindings/lwipthread.c b/os/various/lwip_bindings/lwipthread.c index b638c7a7e..3e23118a8 100644 --- a/os/various/lwip_bindings/lwipthread.c +++ b/os/various/lwip_bindings/lwipthread.c @@ -69,7 +69,11 @@ #include #include #include +#include + +#if PPPOE_SUPPORT #include +#endif #if LWIP_DHCP #include @@ -141,6 +145,17 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) { macWriteTransmitDescriptor(&td, (uint8_t *)q->payload, (size_t)q->len); macReleaseTransmitDescriptor(&td); + MIB2_STATS_NETIF_ADD(netif, ifoutoctets, p->tot_len); + if (((u8_t*)p->payload)[0] & 1) { + /* broadcast or multicast packet*/ + MIB2_STATS_NETIF_INC(netif, ifoutnucastpkts); + } + else { + /* unicast packet */ + MIB2_STATS_NETIF_INC(netif, ifoutucastpkts); + } + /* increase ifoutdiscards or ifouterrors on error */ + #if ETH_PAD_SIZE pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ #endif @@ -152,48 +167,69 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) { /* * Receives a frame. + * Allocates a pbuf and transfers the bytes of the incoming + * packet from the interface into the pbuf. + * + * @param netif the lwip network interface structure for this ethernetif + * @return a pbuf filled with the received packet (including MAC header) + * NULL on memory error */ -static struct pbuf *low_level_input(struct netif *netif) { +static bool low_level_input(struct netif *netif, struct pbuf **pbuf) { MACReceiveDescriptor rd; - struct pbuf *p, *q; + struct pbuf *q; u16_t len; (void)netif; - if (macWaitReceiveDescriptor(ÐD1, &rd, TIME_IMMEDIATE) == MSG_OK) { - len = (u16_t)rd.size; -#if ETH_PAD_SIZE - len += ETH_PAD_SIZE; /* allow room for Ethernet padding */ -#endif + osalDbgAssert(pbuf != NULL, "invalid null pointer"); - /* We allocate a pbuf chain of pbufs from the pool. */ - p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); + if (macWaitReceiveDescriptor(ÐD1, &rd, TIME_IMMEDIATE) != MSG_OK) + return false; - if (p != NULL) { + len = (u16_t)rd.size; #if ETH_PAD_SIZE - pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */ + len += ETH_PAD_SIZE; /* allow room for Ethernet padding */ #endif - /* Iterates through the pbuf chain. */ - for(q = p; q != NULL; q = q->next) - macReadReceiveDescriptor(&rd, (uint8_t *)q->payload, (size_t)q->len); - macReleaseReceiveDescriptor(&rd); + /* We allocate a pbuf chain of pbufs from the pool. */ + *pbuf = pbuf_alloc(PBUF_RAW, len, PBUF_POOL); + if (*pbuf != NULL) { #if ETH_PAD_SIZE - pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */ + pbuf_header(pbuf, -ETH_PAD_SIZE); /* drop the padding word */ #endif - LINK_STATS_INC(link.recv); - } + /* Iterates through the pbuf chain. */ + for(q = *pbuf; q != NULL; q = q->next) + macReadReceiveDescriptor(&rd, (uint8_t *)q->payload, (size_t)q->len); + macReleaseReceiveDescriptor(&rd); + + MIB2_STATS_NETIF_ADD(netif, ifinoctets, *pbuf->tot_len); + + if (*(uint8_t *)((*pbuf)->payload) & 1) { + /* broadcast or multicast packet*/ + MIB2_STATS_NETIF_INC(netif, ifinnucastpkts); + } else { - macReleaseReceiveDescriptor(&rd); - LINK_STATS_INC(link.memerr); - LINK_STATS_INC(link.drop); + /* unicast packet*/ + MIB2_STATS_NETIF_INC(netif, ifinucastpkts); } - return p; + +#if ETH_PAD_SIZE + pbuf_header(pbuf, ETH_PAD_SIZE); /* reclaim the padding word */ +#endif + + LINK_STATS_INC(link.recv); } - return NULL; + else { + macReleaseReceiveDescriptor(&rd); // Drop packet + LINK_STATS_INC(link.memerr); + LINK_STATS_INC(link.drop); + MIB2_STATS_NETIF_INC(netif, ifindiscards); + } + + return true; } /* @@ -216,7 +252,7 @@ static err_t ethernetif_init(struct netif *netif) { * The last argument should be replaced with your link speed, in units * of bits per second. */ - NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, LWIP_LINK_SPEED); + MIB2_INIT_NETIF(netif, snmp_ifType_ethernet_csmacd, LWIP_LINK_SPEED); netif->state = NULL; netif->name[0] = LWIP_IFNAME0; @@ -301,7 +337,7 @@ static THD_FUNCTION(lwip_thread, p) { }; netif_set_default(&thisif); - + switch (addressMode) { #if LWIP_AUTOIP @@ -349,26 +385,29 @@ static THD_FUNCTION(lwip_thread, p) { } } } + if (mask & FRAME_RECEIVED_ID) { struct pbuf *p; - while ((p = low_level_input(&thisif)) != NULL) { - struct eth_hdr *ethhdr = p->payload; - switch (htons(ethhdr->type)) { - /* IP or ARP packet? */ - case ETHTYPE_IP: - case ETHTYPE_ARP: + while (low_level_input(&thisif, &p)) { + if (p != NULL) { + struct eth_hdr *ethhdr = p->payload; + switch (htons(ethhdr->type)) { + /* IP or ARP packet? */ + case ETHTYPE_IP: + case ETHTYPE_ARP: #if PPPOE_SUPPORT - /* PPPoE packet? */ - case ETHTYPE_PPPOEDISC: - case ETHTYPE_PPPOE: + /* PPPoE packet? */ + case ETHTYPE_PPPOEDISC: + case ETHTYPE_PPPOE: #endif /* PPPOE_SUPPORT */ - /* full packet send to tcpip_thread to process */ - if (thisif.input(p, &thisif) == ERR_OK) - break; - LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); + /* full packet send to tcpip_thread to process */ + if (thisif.input(p, &thisif) == ERR_OK) + break; + LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n")); /* Falls through */ - default: - pbuf_free(p); + default: + pbuf_free(p); + } } } } diff --git a/os/various/lwip_bindings/lwipthread.h b/os/various/lwip_bindings/lwipthread.h index 947d0afd7..61eb1b2dd 100644 --- a/os/various/lwip_bindings/lwipthread.h +++ b/os/various/lwip_bindings/lwipthread.h @@ -58,7 +58,7 @@ * @brief lwIP thread stack size. */ #if !defined(LWIP_THREAD_STACK_SIZE) || defined(__DOXYGEN__) -#define LWIP_THREAD_STACK_SIZE 576 +#define LWIP_THREAD_STACK_SIZE 672 #endif /** diff --git a/readme.txt b/readme.txt index edc1c2c2a..8aaf58b0a 100644 --- a/readme.txt +++ b/readme.txt @@ -89,6 +89,7 @@ ***************************************************************************** *** Next *** +- NEW: Integrated lwIP 2.0.3 and improved lwIP bindings. - NEW: The chconf.h configuration files now are tagged with the version number for safety. The system rejects obsolete files during compilation. -- cgit v1.2.3