diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-01-23 17:40:10 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-01-23 17:40:10 +0000 |
commit | 5541ec017e6dbdf6ca9c81ab58401579f94b01ec (patch) | |
tree | 559dbf5ee5030a970fbffb50af3a125a6b21071f /nuttx | |
parent | 34ac2896338a1c4f3e953cdf13c2583c4ccf218c (diff) | |
download | px4-nuttx-5541ec017e6dbdf6ca9c81ab58401579f94b01ec.tar.gz px4-nuttx-5541ec017e6dbdf6ca9c81ab58401579f94b01ec.tar.bz2 px4-nuttx-5541ec017e6dbdf6ca9c81ab58401579f94b01ec.zip |
Incorporate uIP patches
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3274 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx')
-rw-r--r-- | nuttx/ChangeLog | 5 | ||||
-rw-r--r-- | nuttx/Documentation/NuttX.html | 7 | ||||
-rw-r--r-- | nuttx/arch/sim/src/Makefile | 56 | ||||
-rw-r--r-- | nuttx/arch/sim/src/up_idle.c | 4 | ||||
-rw-r--r-- | nuttx/arch/sim/src/up_initialize.c | 4 | ||||
-rw-r--r-- | nuttx/arch/sim/src/up_internal.h | 29 | ||||
-rw-r--r-- | nuttx/arch/sim/src/up_netdev.c | 72 | ||||
-rw-r--r-- | nuttx/arch/sim/src/up_tapdev.c | 78 | ||||
-rw-r--r-- | nuttx/arch/sim/src/up_uipdriver.c | 27 | ||||
-rw-r--r-- | nuttx/arch/sim/src/up_wpcap.c | 312 | ||||
-rw-r--r-- | nuttx/net/uip/uip_tcpappsend.c | 1 | ||||
-rw-r--r-- | nuttx/net/uip/uip_tcpinput.c | 46 | ||||
-rw-r--r-- | nuttx/net/uip/uip_udpinput.c | 6 | ||||
-rw-r--r-- | nuttx/net/uip/uip_udpsend.c | 2 |
14 files changed, 554 insertions, 95 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 43007c753..d9a8f7a4d 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -1439,3 +1439,8 @@ fixed several errors in the code identified by the tool. 5.18 2011-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> + + * Incorporate several uIP patches from http://gitweb.aeruder.net/?p=uip.git;a=summary. + - Lost SYNACK causes connection reset + - Fix missing UDP stats for sent/received packets + - Added support for Cygwin as development/test platform. diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index c7ad3a5ec..aac2bbe3e 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -8,7 +8,7 @@ <tr align="center" bgcolor="#e4e4e4"> <td> <h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1> - <p>Last Updated: January 19, 2011</p> + <p>Last Updated: January 23, 2011</p> </td> </tr> </table> @@ -2016,6 +2016,11 @@ buildroot-1.8 2009-12-21 <spudmonkey@racsa.co.cr> <ul><pre> nuttx-5.18 2011-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> + * Incorporate several uIP patches from http://gitweb.aeruder.net/?p=uip.git;a=summary. + - Lost SYNACK causes connection reset + - Fix missing UDP stats for sent/received packets + - Added support for Cygwin as development/test platform. + pascal-2.1 2010-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr> buildroot-1.9 2010-xx-xx <spudmonkey@racsa.co.cr> diff --git a/nuttx/arch/sim/src/Makefile b/nuttx/arch/sim/src/Makefile index 54cde18c2..8e2fc56de 100644 --- a/nuttx/arch/sim/src/Makefile +++ b/nuttx/arch/sim/src/Makefile @@ -40,58 +40,66 @@ ifneq ($(HOSTOS),Cygwin) ifeq ($(CONFIG_SIM_X11FB),y) - USEX = y + USEX = y else - USEX = n + USEX = n endif else - USEX = n + USEX = n + CFLAGS += -DCYGWIN + HOSTCFLAGS += -DCYGWIN endif -CFLAGS += -I$(TOPDIR)/sched +CFLAGS += -I$(TOPDIR)/sched -ASRCS = up_setjmp.S -AOBJS = $(ASRCS:.S=$(OBJEXT)) -CSRCS = up_initialize.c up_idle.c up_interruptcontext.c \ +ASRCS = up_setjmp.S +AOBJS = $(ASRCS:.S=$(OBJEXT)) +CSRCS = up_initialize.c up_idle.c up_interruptcontext.c \ up_initialstate.c up_createstack.c up_usestack.c \ up_releasestack.c up_unblocktask.c up_blocktask.c \ up_releasepending.c up_reprioritizertr.c \ up_exit.c up_schedulesigaction.c up_allocateheap.c \ up_devconsole.c up_framebuffer.c -HOSTSRCS = up_stdio.c up_hostusleep.c +HOSTSRCS = up_stdio.c up_hostusleep.c ifeq ($(USEX),y) - HOSTSRCS += up_x11framebuffer.c + HOSTSRCS += up_x11framebuffer.c endif ifeq ($(CONFIG_FS_FAT),y) -CSRCS += up_blockdevice.c up_deviceimage.c +CSRCS += up_blockdevice.c up_deviceimage.c endif ifeq ($(CONFIG_NET),y) -CSRCS += up_uipdriver.c -HOSTSRCS += up_tapdev.c +CSRCS += up_uipdriver.c +HOSTCFLAGS += -DNETDEV_BUFSIZE=$(CONFIG_NET_BUFSIZE) +ifneq ($(HOSTOS),Cygwin) +HOSTSRCS += up_tapdev.c up_netdev.c +else +HOSTSRCS += up_wpcap.c up_netdev.c +DRVLIB = /lib/w32api/libws2_32.a /lib/w32api/libiphlpapi.a +endif endif -COBJS = $(CSRCS:.c=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) -NXOBJS = $(AOBJS) $(COBJS) -HOSTOBJS = $(HOSTSRCS:.c=$(OBJEXT)) +NXOBJS = $(AOBJS) $(COBJS) +HOSTOBJS = $(HOSTSRCS:.c=$(OBJEXT)) -SRCS = $(ASRCS) $(CSRCS) $(HOSTSRCS) -OBJS = $(AOBJS) $(COBJS) $(HOSTOBJS) +SRCS = $(ASRCS) $(CSRCS) $(HOSTSRCS) +OBJS = $(AOBJS) $(COBJS) $(HOSTOBJS) -LDFLAGS = $(ARCHSCRIPT) +LDFLAGS = $(ARCHSCRIPT) ifeq ($(USEX),y) - STDLIBS = -lX11 -lXext -lc + STDLIBS = -lX11 -lXext -lc else - STDLIBS = -lc + STDLIBS = -lc endif ifeq ($(CONFIG_FS_FAT),y) STDLIBS += -lz endif -LINKOBJS = up_head$(OBJEXT) -LINKLIBS = +LINKOBJS = up_head$(OBJEXT) +LINKLIBS = LDPATHS = $(addprefix -L$(TOPDIR)/,$(dir $(LINKLIBS))) -LDLIBS = $(patsubst lib%,-l%,$(basename $(notdir $(LINKLIBS)))) +LDLIBS = $(patsubst lib%,-l%,$(basename $(notdir $(LINKLIBS)))) all: up_head$(OBJEXT) libarch$(LIBEXT) .PHONY: clean distclean cleanrel depend @@ -134,7 +142,7 @@ nuttx.rel : libarch$(LIBEXT) $(HOSTOS)-names.dat $(LINKOBJS) nuttx$(EXEEXT): cleanrel nuttx.rel $(HOSTOBJS) @echo "LD: nuttx$(EXEEXT)" - @$(CC) $(LDFLAGS) $(LDPATHS) -o $(TOPDIR)/$@ nuttx.rel $(HOSTOBJS) $(STDLIBS) + @$(CC) $(LDFLAGS) $(LDPATHS) -o $(TOPDIR)/$@ nuttx.rel $(HOSTOBJS) $(DRVLIB) $(STDLIBS) @$(NM) $(TOPDIR)/$@ | \ grep -v '\(compiled\)\|\(\.o$$\)\|\( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | \ sort > $(TOPDIR)/System.map diff --git a/nuttx/arch/sim/src/up_idle.c b/nuttx/arch/sim/src/up_idle.c index 686be307a..32efaa11b 100644 --- a/nuttx/arch/sim/src/up_idle.c +++ b/nuttx/arch/sim/src/up_idle.c @@ -1,7 +1,7 @@ /**************************************************************************** * up_idle.c * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -99,7 +99,7 @@ void up_idle(void) /* Run the network if enabled */ -#if defined(CONFIG_NET) && defined(linux) +#ifdef CONFIG_NET uipdriver_loop(); #endif diff --git a/nuttx/arch/sim/src/up_initialize.c b/nuttx/arch/sim/src/up_initialize.c index eeea2abed..257be8ab5 100644 --- a/nuttx/arch/sim/src/up_initialize.c +++ b/nuttx/arch/sim/src/up_initialize.c @@ -1,7 +1,7 @@ /**************************************************************************** * up_initialize.c * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -101,7 +101,7 @@ void up_initialize(void) #if defined(CONFIG_FS_FAT) && !defined(CONFIG_DISABLE_MOUNTPOINT) up_registerblockdevice(); /* Our FAT ramdisk at /dev/ram0 */ #endif -#if defined(CONFIG_NET) && defined(linux) +#ifdef CONFIG_NET uipdriver_init(); /* Our "real" netwok driver */ #endif } diff --git a/nuttx/arch/sim/src/up_internal.h b/nuttx/arch/sim/src/up_internal.h index 1b90c3809..e22422aea 100644 --- a/nuttx/arch/sim/src/up_internal.h +++ b/nuttx/arch/sim/src/up_internal.h @@ -113,20 +113,41 @@ extern char *up_deviceimage(void); extern size_t up_hostread(void *buffer, size_t len); extern size_t up_hostwrite(const void *buffer, size_t len); -/* up_tapdev.c ************************************************************/ +/* up_netdev.c ************************************************************/ -#ifdef CONFIG_NET +#ifdef CONFIG_NET extern unsigned long up_getwalltime( void ); +#endif + +/* up_tapdev.c ************************************************************/ + +#if defined(CONFIG_NET) && !defined(CYGWIN) extern void tapdev_init(void); -extern int tapdev_getmacaddr(unsigned char *macaddr); extern unsigned int tapdev_read(unsigned char *buf, unsigned int buflen); extern void tapdev_send(unsigned char *buf, unsigned int buflen); + +#define netdev_init() tapdev_init() +#define netdev_read(buf,buflen) tapdev_read(buf,buflen) +#define netdev_send(buf,buflen) tapdev_send(buf,buflen) +#endif + +/* up_wpcap.c *************************************************************/ + +#if defined(CONFIG_NET) && defined(CYGWIN) +extern void wpcap_init(void); +extern unsigned int wpcap_read(unsigned char *buf, unsigned int buflen); +extern void wpcap_send(unsigned char *buf, unsigned int buflen); + +#define netdev_init() wpcap_init() +#define netdev_read(buf,buflen) wpcap_read(buf,buflen) +#define netdev_send(buf,buflen) wpcap_send(buf,buflen) #endif /* up_uipdriver.c *********************************************************/ -#if defined(CONFIG_NET) && defined(linux) +#ifdef CONFIG_NET extern int uipdriver_init(void); +extern int uipdriver_setmacaddr(unsigned char *macaddr); extern void uipdriver_loop(void); #endif diff --git a/nuttx/arch/sim/src/up_netdev.c b/nuttx/arch/sim/src/up_netdev.c new file mode 100644 index 000000000..742492971 --- /dev/null +++ b/nuttx/arch/sim/src/up_netdev.c @@ -0,0 +1,72 @@ +/**************************************************************************** + * up_tapdev.c + * + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/types.h> +#include <sys/time.h> + +/**************************************************************************** + * Private Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +unsigned long up_getwalltime( void ) +{ + struct timeval tm; + (void)gettimeofday(&tm, NULL); + return tm.tv_sec*1000 + tm.tv_usec/1000; +} diff --git a/nuttx/arch/sim/src/up_tapdev.c b/nuttx/arch/sim/src/up_tapdev.c index 2c9d5c646..fd85a973e 100644 --- a/nuttx/arch/sim/src/up_tapdev.c +++ b/nuttx/arch/sim/src/up_tapdev.c @@ -1,8 +1,7 @@ - /**************************************************************************** * up_tapdev.c * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Based on code from uIP which also has a BSD-like license: @@ -39,7 +38,7 @@ * ****************************************************************************/ -#ifdef linux +#ifndef CYGWIN /**************************************************************************** * Included Files @@ -63,6 +62,7 @@ #include <linux/net.h> extern int lib_rawprintf(const char *format, ...); +extern int uipdriver_setmacaddr(unsigned char *macaddr); /**************************************************************************** * Private Definitions @@ -133,17 +133,42 @@ static inline void dump_ethhdr(const char *msg, unsigned char *buf, int buflen) # define dump_ethhdr(m,b,l) #endif +static int up_setmacaddr(void) +{ + unsigned char macaddr[6]; + int ret = -1; + if (macaddr) + { + /* Get a socket (only so that we get access to the INET subsystem) */ + + int sockfd = socket(PF_INET, SOCK_DGRAM, 0); + if (sockfd >= 0) + { + struct ifreq req; + memset(&req, 0, sizeof(struct ifreq)); + + /* Put the driver name into the request */ + + strncpy(req.ifr_name, "tap0", IFNAMSIZ); + + /* Perform the ioctl to get the MAC address */ + + ret = ioctl(sockfd, SIOCGIFHWADDR, (unsigned long)&req); + if (!ret) + { + /* Set the MAC address */ + + ret = uipdriver_setmacaddr(&req.ifr_hwaddr.sa_data); + } + } + } + return ret; +} + /**************************************************************************** * Public Functions ****************************************************************************/ -unsigned long up_getwalltime( void ) -{ - struct timeval tm; - (void)gettimeofday(&tm, NULL); - return tm.tv_sec*1000 + tm.tv_usec/1000; -} - void tapdev_init(void) { struct ifreq ifr; @@ -175,37 +200,10 @@ void tapdev_init(void) snprintf(buf, sizeof(buf), "/sbin/ifconfig tap0 inet %d.%d.%d.%d\n", UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3); system(buf); -} - -int tapdev_getmacaddr(unsigned char *macaddr) -{ - int ret = -1; - if (macaddr) - { - /* Get a socket (only so that we get access to the INET subsystem) */ - - int sockfd = socket(PF_INET, SOCK_DGRAM, 0); - if (sockfd >= 0) - { - struct ifreq req; - memset (&req, 0, sizeof(struct ifreq)); - - /* Put the driver name into the request */ - - strncpy(req.ifr_name, "tap0", IFNAMSIZ); - - /* Perform the ioctl to get the MAC address */ - ret = ioctl(sockfd, SIOCGIFHWADDR, (unsigned long)&req); - if (!ret) - { - /* Return the MAC address */ + /* Set the MAC address */ - memcpy(macaddr, &req.ifr_hwaddr.sa_data, IFHWADDRLEN); - } - } - } - return ret; + up_setmacaddr(); } unsigned int tapdev_read(unsigned char *buf, unsigned int buflen) @@ -269,6 +267,6 @@ void tapdev_send(unsigned char *buf, unsigned int buflen) dump_ethhdr("write", buf, buflen); } -#endif /* linux */ +#endif /* !CYGWIN */ diff --git a/nuttx/arch/sim/src/up_uipdriver.c b/nuttx/arch/sim/src/up_uipdriver.c index 5258022e2..e6dec219d 100644 --- a/nuttx/arch/sim/src/up_uipdriver.c +++ b/nuttx/arch/sim/src/up_uipdriver.c @@ -1,7 +1,7 @@ /**************************************************************************** * up_uipdriver.c * - * Copyright (C) 2007, 2009-2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009-2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Based on code from uIP which also has a BSD-like license: @@ -38,14 +38,14 @@ * ****************************************************************************/ -#ifdef linux - /**************************************************************************** * Included Files ****************************************************************************/ #include <nuttx/config.h> +#ifdef CONFIG_NET + #include <stdint.h> #include <stdbool.h> #include <string.h> @@ -124,7 +124,7 @@ static int sim_uiptxpoll(struct uip_driver_s *dev) if (g_sim_dev.d_len > 0) { uip_arp_out(&g_sim_dev); - tapdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); + netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); } /* If zero is returned, the polling will continue until all connections have @@ -140,9 +140,9 @@ static int sim_uiptxpoll(struct uip_driver_s *dev) void uipdriver_loop(void) { - /* tapdev_read will return 0 on a timeout event and >0 on a data received event */ + /* netdev_read will return 0 on a timeout event and >0 on a data received event */ - g_sim_dev.d_len = tapdev_read((unsigned char*)g_sim_dev.d_buf, CONFIG_NET_BUFSIZE); + g_sim_dev.d_len = netdev_read((unsigned char*)g_sim_dev.d_buf, CONFIG_NET_BUFSIZE); /* Disable preemption through to the following so that it behaves a little more * like an interrupt (otherwise, the following logic gets pre-empted an behaves @@ -177,7 +177,7 @@ void uipdriver_loop(void) if (g_sim_dev.d_len > 0) { uip_arp_out(&g_sim_dev); - tapdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); + netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); } } else if (BUF->ether_type == htons(UIP_ETHTYPE_ARP)) @@ -191,7 +191,7 @@ void uipdriver_loop(void) if (g_sim_dev.d_len > 0) { - tapdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); + netdev_send(g_sim_dev.d_buf, g_sim_dev.d_len); } } } @@ -212,8 +212,7 @@ int uipdriver_init(void) /* Internal initalization */ timer_set(&g_periodic_timer, 500); - tapdev_init(); - (void)tapdev_getmacaddr(g_sim_dev.d_mac.ether_addr_octet); + netdev_init(); /* Register the device with the OS so that socket IOCTLs can be performed */ @@ -221,5 +220,11 @@ int uipdriver_init(void) return OK; } -#endif /* linux */ +int uipdriver_setmacaddr(unsigned char *macaddr) +{ + (void)memcpy(g_sim_dev.d_mac.ether_addr_octet, macaddr, IFHWADDRLEN); + return 0; +} + +#endif /* CONFIG_NET */ diff --git a/nuttx/arch/sim/src/up_wpcap.c b/nuttx/arch/sim/src/up_wpcap.c new file mode 100644 index 000000000..9fd9e5064 --- /dev/null +++ b/nuttx/arch/sim/src/up_wpcap.c @@ -0,0 +1,312 @@ +/**************************************************************************** + * up_wcap.c + * + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Based on code from uIP which also has a BSD-like license: + * + * Copyright (c) 2007, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + ****************************************************************************/ + +#ifdef CYGWIN + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#define WIN32_LEAN_AND_MEAN +#define _WIN32_WINNT 0x0501 +#include <windows.h> +#include <winsock2.h> +#include <iphlpapi.h> + +#include <stdio.h> +#include <stdlib.h> +#include <malloc.h> + +extern int uipdriver_setmacaddr(unsigned char *macaddr); + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define BUF ((struct uip_eth_hdr *)&uip_buf[0]) + +#ifndef CONFIG_EXAMPLE_UIP_DHCPC +# define UIP_IPADDR (10 << 24 | 0 << 16 | 0 << 8 | 1) +#else +# define UIP_IPADDR (0) +#endif + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +__attribute__ ((dllimport)) extern char **__argv[]; + +struct pcap; + +struct pcap_if +{ + struct pcap_if *next; + char *name; + char *description; + struct pcap_addr + { + struct pcap_addr *next; + struct sockaddr *addr; + struct sockaddr *netmask; + struct sockaddr *broadaddr; + struct sockaddr *dstaddr; + } *addresses; + DWORD flags; +}; + +struct pcap_pkthdr +{ + struct timeval ts; + DWORD caplen; + DWORD len; +}; + +/* DLL function types (for casting) */ + +typedef int (*pcap_findalldevs_t)(struct pcap_if **, char *); +typedef struct pcap *(*pcap_open_live_t)(char *, int, int, int, char *); +typedef int (*pcap_next_ex_t)(struct pcap *, struct pcap_pkthdr **, + unsigned char **); +typedef int (*pcap_sendpacket_t)(struct pcap *, unsigned char *, int); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +HMODULE wpcap; +static struct pcap *pcap; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static pcap_findalldevs_t pcap_findalldevs; +static pcap_open_live_t pcap_open_live; +static pcap_next_ex_t pcap_next_ex; +static pcap_sendpacket_t pcap_sendpacket; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static void error_exit(char *message) +{ + printf("error_exit: %s", message); + exit(EXIT_FAILURE); +} + +static void init_pcap(struct in_addr addr) +{ + struct pcap_if *interfaces; + char error[256]; + + if (pcap_findalldevs(&interfaces, error) == -1) + { + error_exit(error); + } + + while (interfaces != NULL) + { + printf("init_pcap: found interface: %s\n", interfaces->description); + + if (interfaces->addresses != NULL && + interfaces->addresses->addr != NULL && + interfaces->addresses->addr->sa_family == AF_INET) + { + + struct in_addr interface_addr; + interface_addr = + ((struct sockaddr_in *)interfaces->addresses->addr)->sin_addr; + printf("init_pcap: with address: %s\n", inet_ntoa(interface_addr)); + + if (interface_addr.s_addr == addr.s_addr) + { + break; + } + } + interfaces = interfaces->next; + } + + if (interfaces == NULL) + { + error_exit("No interface found with IP address\n"); + } + + pcap = pcap_open_live(interfaces->name, NETDEV_BUFSIZE, 0, -1, error); + if (pcap == NULL) + { + error_exit(error); + } +} + +static void set_ethaddr(struct in_addr addr) +{ + PIP_ADAPTER_ADDRESSES adapters; + ULONG size = 0; + + if (GetAdaptersAddresses(AF_INET, GAA_FLAG_SKIP_ANYCAST | + GAA_FLAG_SKIP_MULTICAST | + GAA_FLAG_SKIP_DNS_SERVER, + NULL, NULL, &size) != ERROR_BUFFER_OVERFLOW) + { + error_exit("error on access to adapter list size\n"); + } + adapters = alloca(size); + if (GetAdaptersAddresses(AF_INET, GAA_FLAG_SKIP_ANYCAST | + GAA_FLAG_SKIP_MULTICAST | + GAA_FLAG_SKIP_DNS_SERVER, + NULL, adapters, &size) != ERROR_SUCCESS) + { + error_exit("error on access to adapter list\n"); + } + + while (adapters != NULL) + { + + char buffer[256]; + WideCharToMultiByte(CP_ACP, 0, adapters->Description, -1, + buffer, sizeof(buffer), NULL, NULL); + printf("set_ethaddr: found adapter: %s\n", buffer); + + if (adapters->FirstUnicastAddress != NULL && + adapters->FirstUnicastAddress->Address.lpSockaddr != NULL && + adapters->FirstUnicastAddress->Address.lpSockaddr->sa_family == + AF_INET) + { + + struct in_addr adapter_addr; + adapter_addr = + ((struct sockaddr_in *)adapters->FirstUnicastAddress->Address. + lpSockaddr)->sin_addr; + printf("set_ethaddr: with address: %s\n", inet_ntoa(adapter_addr)); + + if (adapter_addr.s_addr == addr.s_addr) + { + if (adapters->PhysicalAddressLength != 6) + { + error_exit + ("ip addr specified does not belong to an ethernet card\n"); + } + printf + ("set_ethaddr: ethernetaddr: %02X-%02X-%02X-%02X-%02X-%02X\n", + adapters->PhysicalAddress[0], adapters->PhysicalAddress[1], + adapters->PhysicalAddress[2], adapters->PhysicalAddress[3], + adapters->PhysicalAddress[4], adapters->PhysicalAddress[5]); + + (void)uipdriver_setmacaddr(adapters->PhysicalAddress); + break; + } + } + adapters = adapters->Next; + } + + if (adapters == NULL) + { + error_exit("No adaptor found with IP address\n"); + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void wpcap_init(void) +{ + struct in_addr addr; + FARPROC dlladdr; + + addr.s_addr = htonl(UIP_IPADDR); + printf("wpcap_init: IP address: %s\n", inet_ntoa(addr)); + + wpcap = LoadLibrary("wpcap.dll"); + dlladdr = GetProcAddress(wpcap, "pcap_findalldevs"); + pcap_findalldevs = (pcap_findalldevs_t)dlladdr; + + dlladdr = GetProcAddress(wpcap, "pcap_open_live"); + pcap_open_live = (pcap_open_live_t)dlladdr; + + dlladdr = GetProcAddress(wpcap, "pcap_next_ex"); + pcap_next_ex = (pcap_next_ex_t)dlladdr; + + dlladdr = GetProcAddress(wpcap, "pcap_sendpacket"); + pcap_sendpacket = (pcap_sendpacket_t)dlladdr; + + if (pcap_findalldevs == NULL || pcap_open_live == NULL || + pcap_next_ex == NULL || pcap_sendpacket == NULL) + { + error_exit("error on access to winpcap library\n"); + } + + init_pcap(addr); + set_ethaddr(addr); +} + +unsigned int wpcap_read(unsigned char *buf, unsigned int buflen) +{ + struct pcap_pkthdr *packet_header; + unsigned char *packet; + + switch (pcap_next_ex(pcap, &packet_header, &packet)) + { + case -1: + error_exit("error on read\n"); + case 0: + return 0; + } + + if (packet_header->caplen > buflen) + { + return 0; + } + + memcpy(buf, packet, packet_header->caplen); + return packet_header->caplen; +} + +void wpcap_send(unsigned char *buf, unsigned int buflen) +{ + if (pcap_sendpacket(pcap, buf, buflen) == -1) + { + error_exit("error on send\n"); + } +} + +#endif /* CYGWIN */ diff --git a/nuttx/net/uip/uip_tcpappsend.c b/nuttx/net/uip/uip_tcpappsend.c index 9a09e0997..e887e9efc 100644 --- a/nuttx/net/uip/uip_tcpappsend.c +++ b/nuttx/net/uip/uip_tcpappsend.c @@ -45,6 +45,7 @@ #if defined(CONFIG_NET) && defined(CONFIG_NET_TCP) #include <stdint.h> +#include <assert.h> #include <debug.h> #include <net/uip/uipopt.h> diff --git a/nuttx/net/uip/uip_tcpinput.c b/nuttx/net/uip/uip_tcpinput.c index e95ded119..f7811cdf7 100644 --- a/nuttx/net/uip/uip_tcpinput.c +++ b/nuttx/net/uip/uip_tcpinput.c @@ -2,7 +2,7 @@ * net/uip/uip_tcpinput.c * Handling incoming TCP input * - * Copyright (C) 2007-2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Adapted for NuttX from logic in uIP which also has a BSD-like license: @@ -131,7 +131,21 @@ void uip_tcpinput(struct uip_driver_s *dev) conn = uip_tcpactive(pbuf); if (conn) { - goto found; + /* We found an active connection.. Check for the subsequent SYN + * arriving in UIP_SYN_RCVD state after the SYNACK packet was + * lost. To avoid other issues, reset any active connection + * where a SYN arrives in a state != UIP_SYN_RCVD. + */ + + if ((conn->tcpstateflags & UIP_TS_MASK) != UIP_SYN_RCVD && + (BUF->flags & TCP_CTL) == TCP_SYN) + { + goto reset; + } + else + { + goto found; + } } /* If we didn't find and active connection that expected the packet, @@ -259,6 +273,8 @@ void uip_tcpinput(struct uip_driver_s *dev) * no matching listener found. Send RST packet in either case. */ +reset: + /* We do not send resets in response to resets. */ if ((pbuf->flags & TCP_RST) != 0) @@ -278,7 +294,7 @@ found: /* We do a very naive form of TCP reset processing; we just accept * any RST and kill our connection. We should in fact check if the - * sequence number of this reset is wihtin our advertised window + * sequence number of this reset is within our advertised window * before we accept the reset. */ @@ -306,17 +322,21 @@ found: /* First, check if the sequence number of the incoming packet is * what we're expecting next. If not, we send out an ACK with the - * correct numbers in. + * correct numbers in, unless we are in the SYN_RCVD state and + * receive a SYN, in which case we should retransmit our SYNACK + * (which is done further down). */ - if (!(((conn->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) && - ((pbuf->flags & TCP_CTL) == (TCP_SYN | TCP_ACK)))) + if (!((((conn->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) && + ((pbuf->flags & TCP_CTL) == (TCP_SYN | TCP_ACK))) || + (((conn->tcpstateflags & UIP_TS_MASK) == UIP_SYN_RCVD) && + ((pbuf->flags & TCP_CTL) == TCP_SYN)))) { if ((dev->d_len > 0 || ((pbuf->flags & (TCP_SYN | TCP_FIN)) != 0)) && memcmp(pbuf->seqno, conn->rcvseq, 4) != 0) { - uip_tcpsend(dev, conn, TCP_ACK, UIP_IPTCPH_LEN); - return; + uip_tcpsend(dev, conn, TCP_ACK, UIP_IPTCPH_LEN); + return; } } @@ -444,6 +464,14 @@ found: uip_tcpappsend(dev, conn, result); return; } + + /* We need to retransmit the SYNACK */ + + if ((pbuf->flags & TCP_CTL) == TCP_SYN) + { + uip_tcpack(dev, conn, TCP_ACK | TCP_SYN); + return; + } goto drop; case UIP_SYN_SENT: @@ -617,7 +645,7 @@ found: * remote host. */ - if (dev->d_len > 0 && !(conn->tcpstateflags & UIP_STOPPED)) + if (dev->d_len > 0 && (conn->tcpstateflags & UIP_STOPPED) == 0) { flags |= UIP_NEWDATA; uip_incr32(conn->rcvseq, dev->d_len); diff --git a/nuttx/net/uip/uip_udpinput.c b/nuttx/net/uip/uip_udpinput.c index e6f52f86c..839508334 100644 --- a/nuttx/net/uip/uip_udpinput.c +++ b/nuttx/net/uip/uip_udpinput.c @@ -2,7 +2,7 @@ * net/uip/uip_udpinput.c * Handling incoming UDP input * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Adapted for NuttX from logic in uIP which also has a BSD-like license: @@ -97,6 +97,10 @@ void uip_udpinput(struct uip_driver_s *dev) struct uip_udp_conn *conn; struct uip_udpip_hdr *pbuf = UDPBUF; +#ifdef CONFIG_NET_STATISTICS + uip_stat.udp.recv++; +#endif + /* UDP processing is really just a hack. We don't do anything to the UDP/IP * headers, but let the UDP application do all the hard work. If the * application sets d_sndlen, it has a packet to send. diff --git a/nuttx/net/uip/uip_udpsend.c b/nuttx/net/uip/uip_udpsend.c index 7fedfc14a..fbdfa89ae 100644 --- a/nuttx/net/uip/uip_udpsend.c +++ b/nuttx/net/uip/uip_udpsend.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/uip/uip_udpsend.c * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Adapted for NuttX from logic in uIP which also has a BSD-like license: |