From 5d303ec17efc511d8cfe0919a790b44e24a8aad9 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 1 Sep 2007 18:06:15 +0000 Subject: Added support for socket descriptors git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@318 42af7a65-404d-4744-a932-0658087f49c3 --- nuttx/Documentation/NuttxPortingGuide.html | 43 +-- nuttx/Makefile | 4 +- nuttx/arch/sim/src/Makefile | 2 +- nuttx/arch/sim/src/up_idle.c | 2 +- nuttx/arch/sim/src/up_initialize.c | 2 +- nuttx/arch/sim/src/up_internal.h | 4 +- nuttx/arch/sim/src/up_uipdriver.c | 10 +- nuttx/configs/README.txt | 41 +-- nuttx/configs/c5471evm/defconfig | 80 +++-- nuttx/configs/m68332evb/defconfig | 80 +++-- nuttx/configs/mcu123-lpc214x/defconfig | 80 +++-- nuttx/configs/ntosd-dm320/defconfig | 80 +++-- nuttx/configs/pjrc-8051/defconfig | 80 +++-- nuttx/configs/sim/defconfig | 80 +++-- nuttx/examples/uip/main.c | 30 +- nuttx/include/net/uip/dhcpc.h | 72 ++++ nuttx/include/net/uip/psock.h | 40 ++- nuttx/include/net/uip/uip.h | 74 ++-- nuttx/include/net/uip/uipopt.h | 319 ++++++++--------- nuttx/include/nuttx/net.h | 101 ++++++ nuttx/include/nuttx/sched.h | 13 +- nuttx/lib/lib_dirname.c | 2 +- nuttx/net/Makefile | 6 +- nuttx/net/net_internal.h | 82 +++++ nuttx/net/net_sockets.c | 171 +++++++++ nuttx/net/uip/psock.c | 3 +- nuttx/net/uip/uip-fw.c | 4 +- nuttx/net/uip/uip-neighbor.c | 143 ++++---- nuttx/net/uip/uip-split.c | 20 +- nuttx/net/uip/uip.c | 432 +++++++++++++--------- nuttx/netutils/Makefile | 4 +- nuttx/netutils/dhcpc/Make.defs | 2 +- nuttx/netutils/dhcpc/dhcpc.c | 246 +++++++------ nuttx/netutils/dhcpc/dhcpc.h | 58 --- nuttx/netutils/resolv/Make.defs | 2 +- nuttx/netutils/resolv/resolv.c | 553 +++++++++++++++-------------- nuttx/netutils/smtp/smtp.c | 11 + nuttx/sched/Makefile | 6 +- nuttx/sched/os_internal.h | 6 +- nuttx/sched/sched_getsockets.c | 76 ++++ nuttx/sched/sched_releasefiles.c | 18 +- nuttx/sched/sched_setupidlefiles.c | 27 +- nuttx/sched/sched_setuppthreadfiles.c | 19 +- nuttx/sched/sched_setupstreams.c | 5 +- nuttx/sched/sched_setuptaskfiles.c | 28 +- 45 files changed, 1928 insertions(+), 1233 deletions(-) create mode 100644 nuttx/include/net/uip/dhcpc.h create mode 100644 nuttx/include/nuttx/net.h create mode 100644 nuttx/net/net_internal.h create mode 100644 nuttx/net/net_sockets.c delete mode 100644 nuttx/netutils/dhcpc/dhcpc.h create mode 100644 nuttx/sched/sched_getsockets.c diff --git a/nuttx/Documentation/NuttxPortingGuide.html b/nuttx/Documentation/NuttxPortingGuide.html index 26bf11055..03e76cd07 100644 --- a/nuttx/Documentation/NuttxPortingGuide.html +++ b/nuttx/Documentation/NuttxPortingGuide.html @@ -1295,68 +1295,71 @@ The system can be re-made subsequently by just typing make.

Network Support

-

TCP/IP support via uIP

+

TCP/IP and UDP support via uIP

UIP Network Utilities

diff --git a/nuttx/Makefile b/nuttx/Makefile index 5050b3086..0f8704a80 100644 --- a/nuttx/Makefile +++ b/nuttx/Makefile @@ -51,7 +51,7 @@ BOARD_DIR = configs/$(CONFIG_ARCH_BOARD) NONFSDIRS = sched lib $(ARCH_SRC) mm examples/$(CONFIG_EXAMPLE) FSDIRS = fs drivers -ifeq ($(CONFIG_NET_UIP),y) +ifeq ($(CONFIG_NET),y) NONFSDIRS += net netutils endif @@ -79,7 +79,7 @@ ifneq ($(CONFIG_NFILE_DESCRIPTORS),0) LINKLIBS += fs/libfs$(LIBEXT) drivers/libdrivers$(LIBEXT) endif -ifeq ($(CONFIG_NET_UIP),y) +ifeq ($(CONFIG_NET),y) LINKLIBS += net/libnet$(LIBEXT) netutils/libnetutils$(LIBEXT) endif diff --git a/nuttx/arch/sim/src/Makefile b/nuttx/arch/sim/src/Makefile index f9eaeac49..75ea07eee 100644 --- a/nuttx/arch/sim/src/Makefile +++ b/nuttx/arch/sim/src/Makefile @@ -49,7 +49,7 @@ CSRCS = up_initialize.c up_idle.c up_interruptcontext.c \ ifeq ($(CONFIG_FS_FAT),y) CSRCS += up_blockdevice.c up_deviceimage.c endif -ifeq ($(CONFIG_NET_UIP),y) +ifeq ($(CONFIG_NET),y) CSRCS += up_uipdriver.c SPECSRCS += up_tapdev.c endif diff --git a/nuttx/arch/sim/src/up_idle.c b/nuttx/arch/sim/src/up_idle.c index 95e119240..01457962e 100644 --- a/nuttx/arch/sim/src/up_idle.c +++ b/nuttx/arch/sim/src/up_idle.c @@ -83,7 +83,7 @@ void up_idle(void) /* Run the network if enabled */ -#ifdef CONFIG_NET_UIP +#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 427360c10..a7faa5032 100644 --- a/nuttx/arch/sim/src/up_initialize.c +++ b/nuttx/arch/sim/src/up_initialize.c @@ -86,7 +86,7 @@ void up_initialize(void) devnull_register(); /* Standard /dev/null */ up_devconsole(); /* Our private /dev/console */ up_registerblockdevice(); /* Our simulated block device /dev/blkdev */ -#ifdef CONFIG_NET_UIP +#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 f2a7512a0..f2a2b65cb 100644 --- a/nuttx/arch/sim/src/up_internal.h +++ b/nuttx/arch/sim/src/up_internal.h @@ -109,7 +109,7 @@ extern char *up_deviceimage(void); /* up_tapdev.c ************************************************************/ -#ifdef CONFIG_NET_UIP +#ifdef CONFIG_NET extern unsigned long up_getwalltime( void ); extern void tapdev_init(void); extern unsigned int tapdev_read(char *buf, unsigned int buflen); @@ -118,7 +118,7 @@ extern void tapdev_send(char *buf, unsigned int buflen); /* up_uipdriver.c *********************************************************/ -#ifdef CONFIG_NET_UIP +#ifdef CONFIG_NET extern int uipdriver_init(void); extern void uipdriver_loop(void); #endif diff --git a/nuttx/arch/sim/src/up_uipdriver.c b/nuttx/arch/sim/src/up_uipdriver.c index 883207ab4..5309b89c4 100644 --- a/nuttx/arch/sim/src/up_uipdriver.c +++ b/nuttx/arch/sim/src/up_uipdriver.c @@ -106,7 +106,7 @@ void uipdriver_loop(void) { int i; - uip_len = tapdev_read(uip_buf, UIP_BUFSIZE); + uip_len = tapdev_read((char*)uip_buf, UIP_BUFSIZE); if (uip_len > 0) { if (BUF->type == htons(UIP_ETHTYPE_IP)) @@ -122,7 +122,7 @@ void uipdriver_loop(void) if (uip_len > 0) { uip_arp_out(); - tapdev_send(uip_buf, uip_len); + tapdev_send((char*)uip_buf, uip_len); } } else if (BUF->type == htons(UIP_ETHTYPE_ARP)) @@ -136,7 +136,7 @@ void uipdriver_loop(void) if (uip_len > 0) { - tapdev_send(uip_buf, uip_len); + tapdev_send((char*)uip_buf, uip_len); } } } @@ -155,7 +155,7 @@ void uipdriver_loop(void) if (uip_len > 0) { uip_arp_out(); - tapdev_send(uip_buf, uip_len); + tapdev_send((char*)uip_buf, uip_len); } } @@ -172,7 +172,7 @@ void uipdriver_loop(void) if (uip_len > 0) { uip_arp_out(); - tapdev_send(uip_buf, uip_len); + tapdev_send((char*)uip_buf, uip_len); } } #endif /* UIP_UDP */ diff --git a/nuttx/configs/README.txt b/nuttx/configs/README.txt index 3d7cc69db..ffba46227 100644 --- a/nuttx/configs/README.txt +++ b/nuttx/configs/README.txt @@ -208,32 +208,33 @@ defconfig -- This is a configuration file similar to the Linux structures. The system manages a pool of preallocated watchdog structures to minimize dynamic allocations - TCP/IP support via uIP - CONFIG_NET_UIP - Enable or disable all uIP features - CONFIG_NET_UIP_IPv6 - Build in support for IPv6 - CONFIG_UIP_MAX_CONNECTIONS - Maximum number of TCP connections - CONFIG_UIP_MAX_LISTENPORTS - Maximum number of listening TCP ports - CONFIG_UIP_BUFFER_SIZE - uIP buffer size - CONFIG_UIP_LOGGING - Logging on or off - CONFIG_UIP_UDP - UDP support on or off - CONFIG_UIP_UDP_CHECKSUMS - UDP checksums on or off - CONFIG_UIP_UDP_CONNS - The maximum amount of concurrent UDP + TCP/IP and UDP support via uIP + CONFIG_NET - Enable or disable all network features + CONFIG_NET_IPv6 - Build in support for IPv6 + CONFIG_NSOCKET_DESCRIPTORS - Maximum number of socket descriptors per task/thread. + CONFIG_NET_MAX_CONNECTIONS - Maximum number of TCP connections + CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports + CONFIG_NET_BUFFER_SIZE - uIP buffer size + CONFIG_NET_LOGGING - Logging on or off + CONFIG_NET_UDP - UDP support on or off + CONFIG_NET_UDP_CHECKSUMS - UDP checksums on or off + CONFIG_NET_UDP_CONNS - The maximum amount of concurrent UDP connections - CONFIG_UIP_STATISTICS - uIP statistics on or off - CONFIG_UIP_PINGADDRCONF - Use "ping" packet for setting IP address - CONFIG_UIP_RECEIVE_WINDOW - The size of the advertised receiver's + CONFIG_NET_STATISTICS - uIP statistics on or off + CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address + CONFIG_NET_RECEIVE_WINDOW - The size of the advertised receiver's window - CONFIG_UIP_ARPTAB_SIZE - The size of the ARP table - CONFIG_UIP_BROADCAST - Broadcast support - CONFIG_UIP_LLH_LEN - The link level header length - CONFIG_UIP_EXTERNAL_BUFFER - Incoming packet buffer (uip_buf) + CONFIG_NET_ARPTAB_SIZE - The size of the ARP table + CONFIG_NET_BROADCAST - Broadcast support + CONFIG_NET_LLH_LEN - The link level header length + CONFIG_NET_EXTERNAL_BUFFER - Incoming packet buffer (uip_buf) is defined externally - CONFIG_UIP_FWCACHE_SIZE - number of packets to remember when + CONFIG_NET_FWCACHE_SIZE - number of packets to remember when looking for duplicates UIP Network Utilities - CONFIG_UIP_DHCP_LIGHT - Reduces size of DHCP - CONFIG_UIP_RESOLV_ENTRIES - Number of resolver entries + CONFIG_NET_DHCP_LIGHT - Reduces size of DHCP + CONFIG_NET_RESOLV_ENTRIES - Number of resolver entries Stack and heap information diff --git a/nuttx/configs/c5471evm/defconfig b/nuttx/configs/c5471evm/defconfig index 4c7acd09a..cad404821 100644 --- a/nuttx/configs/c5471evm/defconfig +++ b/nuttx/configs/c5471evm/defconfig @@ -250,48 +250,50 @@ CONFIG_PREALLOC_WDOGS=32 CONFIG_PREALLOC_TIMERS=8 # -# TCP/IP support via uIP -# CONFIG_NET_UIP - Enable or disable all uIP features -# CONFIG_NET_UIP_IPv6 - Build in support for IPv6 -# CONFIG_UIP_MAX_CONNECTIONS - Maximum number of TCP connections -# CONFIG_UIP_MAX_LISTENPORTS - Maximum number of listening TCP ports -# CONFIG_UIP_BUFFER_SIZE - uIP buffer size -# CONFIG_UIP_LOGGING - Logging on or off -# CONFIG_UIP_UDP - UDP support on or off -# CONFIG_UIP_UDP_CHECKSUMS - UDP checksums on or off -# CONFIG_UIP_UDP_CONNS - The maximum amount of concurrent UDP connections -# CONFIG_UIP_STATISTICS - uIP statistics on or off -# CONFIG_UIP_PINGADDRCONF - Use "ping" packet for setting IP address -# CONFIG_UIP_RECEIVE_WINDOW - The size of the advertised receiver's window -# CONFIG_UIP_ARPTAB_SIZE - The size of the ARP table -# CONFIG_UIP_BROADCAST - Broadcast support -# CONFIG_UIP_LLH_LEN - The link level header length -# CONFIG_UIP_EXTERNAL_BUFFER - Incoming packet buffer (uip_buf) is defined externally -# CONFIG_UIP_FWCACHE_SIZE - number of packets to remember when looking for duplicates -CONFIG_NET_UIP=n -CONFIG_NET_UIP_IPv6=n -CONFIG_UIP_MAX_CONNECTIONS=40 -CONFIG_UIP_MAX_LISTENPORTS=40 -CONFIG_UIP_BUFFER_SIZE=420 -CONFIG_UIP_LOGGING=y -CONFIG_UIP_UDP=n -CONFIG_UIP_UDP_CHECKSUMS=y -#CONFIG_UIP_UDP_CONNS=10 -CONFIG_UIP_STATISTICS=y -#CONFIG_UIP_PINGADDRCONF=0 -#CONFIG_UIP_RECEIVE_WINDOW= -#CONFIG_UIP_ARPTAB_SIZE=8 -CONFIG_UIP_BROADCAST=n -#CONFIG_UIP_LLH_LEN=14 -CONFIG_UIP_EXTERNAL_BUFFER=n -#CONFIG_UIP_FWCACHE_SIZE=2 +# TCP/IP and UDP support via uIP +# CONFIG_NET - Enable or disable all network features +# CONFIG_NET_IPv6 - Build in support for IPv6 +# CONFIG_NSOCKET_DESCRIPTORS - Maximum number of socket descriptors per task/thread. +# CONFIG_NET_MAX_CONNECTIONS - Maximum number of TCP connections +# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports +# CONFIG_NET_BUFFER_SIZE - uIP buffer size +# CONFIG_NET_LOGGING - Logging on or off +# CONFIG_NET_UDP - UDP support on or off +# CONFIG_NET_UDP_CHECKSUMS - UDP checksums on or off +# CONFIG_NET_UDP_CONNS - The maximum amount of concurrent UDP connections +# CONFIG_NET_STATISTICS - uIP statistics on or off +# CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address +# CONFIG_NET_RECEIVE_WINDOW - The size of the advertised receiver's window +# CONFIG_NET_ARPTAB_SIZE - The size of the ARP table +# CONFIG_NET_BROADCAST - Broadcast support +# CONFIG_NET_LLH_LEN - The link level header length +# CONFIG_NET_EXTERNAL_BUFFER - Incoming packet buffer (uip_buf) is defined externally +# CONFIG_NET_FWCACHE_SIZE - number of packets to remember when looking for duplicates +CONFIG_NET=n +CONFIG_NET_IPv6=n +CONFIG_NSOCKET_DESCRIPTORS=0 +CONFIG_NET_MAX_CONNECTIONS=40 +CONFIG_NET_MAX_LISTENPORTS=40 +CONFIG_NET_BUFFER_SIZE=420 +CONFIG_NET_LOGGING=y +CONFIG_NET_UDP=n +CONFIG_NET_UDP_CHECKSUMS=y +#CONFIG_NET_UDP_CONNS=10 +CONFIG_NET_STATISTICS=y +#CONFIG_NET_PINGADDRCONF=0 +#CONFIG_NET_RECEIVE_WINDOW= +#CONFIG_NET_ARPTAB_SIZE=8 +CONFIG_NET_BROADCAST=n +#CONFIG_NET_LLH_LEN=14 +CONFIG_NET_EXTERNAL_BUFFER=n +#CONFIG_NET_FWCACHE_SIZE=2 # # UIP Network Utilities -# CONFIG_UIP_DHCP_LIGHT - Reduces size of DHCP -# CONFIG_UIP_RESOLV_ENTRIES - Number of resolver entries -CONFIG_UIP_DHCP_LIGHT=n -CONFIG_UIP_RESOLV_ENTRIES=4 +# CONFIG_NET_DHCP_LIGHT - Reduces size of DHCP +# CONFIG_NET_RESOLV_ENTRIES - Number of resolver entries +CONFIG_NET_DHCP_LIGHT=n +CONFIG_NET_RESOLV_ENTRIES=4 # # Stack and heap information diff --git a/nuttx/configs/m68332evb/defconfig b/nuttx/configs/m68332evb/defconfig index 2621de854..15ba43500 100644 --- a/nuttx/configs/m68332evb/defconfig +++ b/nuttx/configs/m68332evb/defconfig @@ -239,48 +239,50 @@ CONFIG_PREALLOC_WDOGS=32 CONFIG_PREALLOC_TIMERS=8 # -# TCP/IP support via uIP -# CONFIG_NET_UIP - Enable or disable all uIP features -# CONFIG_NET_UIP_IPv6 - Build in support for IPv6 -# CONFIG_UIP_MAX_CONNECTIONS - Maximum number of TCP connections -# CONFIG_UIP_MAX_LISTENPORTS - Maximum number of listening TCP ports -# CONFIG_UIP_BUFFER_SIZE - uIP buffer size -# CONFIG_UIP_LOGGING - Logging on or off -# CONFIG_UIP_UDP - UDP support on or off -# CONFIG_UIP_UDP_CHECKSUMS - UDP checksums on or off -# CONFIG_UIP_UDP_CONNS - The maximum amount of concurrent UDP connections -# CONFIG_UIP_STATISTICS - uIP statistics on or off -# CONFIG_UIP_PINGADDRCONF - Use "ping" packet for setting IP address -# CONFIG_UIP_RECEIVE_WINDOW - The size of the advertised receiver's window -# CONFIG_UIP_ARPTAB_SIZE - The size of the ARP table -# CONFIG_UIP_BROADCAST - Broadcast support -# CONFIG_UIP_LLH_LEN - The link level header length -# CONFIG_UIP_EXTERNAL_BUFFER - Incoming packet buffer (uip_buf) is defined externally -# CONFIG_UIP_FWCACHE_SIZE - number of packets to remember when looking for duplicates -CONFIG_NET_UIP=n -CONFIG_NET_UIP_IPv6=n -CONFIG_UIP_MAX_CONNECTIONS=40 -CONFIG_UIP_MAX_LISTENPORTS=40 -CONFIG_UIP_BUFFER_SIZE=420 -CONFIG_UIP_LOGGING=y -CONFIG_UIP_UDP=n -CONFIG_UIP_UDP_CHECKSUMS=y -#CONFIG_UIP_UDP_CONNS=10 -CONFIG_UIP_STATISTICS=y -#CONFIG_UIP_PINGADDRCONF=0 -#CONFIG_UIP_RECEIVE_WINDOW= -#CONFIG_UIP_ARPTAB_SIZE=8 -CONFIG_UIP_BROADCAST=n -#CONFIG_UIP_LLH_LEN=14 -CONFIG_UIP_EXTERNAL_BUFFER=n -#CONFIG_UIP_FWCACHE_SIZE=2 +# TCP/IP and UDP support via uIP +# CONFIG_NET - Enable or disable all network features +# CONFIG_NET_IPv6 - Build in support for IPv6 +# CONFIG_NSOCKET_DESCRIPTORS - Maximum number of socket descriptors per task/thread. +# CONFIG_NET_MAX_CONNECTIONS - Maximum number of TCP connections +# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports +# CONFIG_NET_BUFFER_SIZE - uIP buffer size +# CONFIG_NET_LOGGING - Logging on or off +# CONFIG_NET_UDP - UDP support on or off +# CONFIG_NET_UDP_CHECKSUMS - UDP checksums on or off +# CONFIG_NET_UDP_CONNS - The maximum amount of concurrent UDP connections +# CONFIG_NET_STATISTICS - uIP statistics on or off +# CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address +# CONFIG_NET_RECEIVE_WINDOW - The size of the advertised receiver's window +# CONFIG_NET_ARPTAB_SIZE - The size of the ARP table +# CONFIG_NET_BROADCAST - Broadcast support +# CONFIG_NET_LLH_LEN - The link level header length +# CONFIG_NET_EXTERNAL_BUFFER - Incoming packet buffer (uip_buf) is defined externally +# CONFIG_NET_FWCACHE_SIZE - number of packets to remember when looking for duplicates +CONFIG_NET=n +CONFIG_NET_IPv6=n +CONFIG_NSOCKET_DESCRIPTORS=0 +CONFIG_NET_MAX_CONNECTIONS=40 +CONFIG_NET_MAX_LISTENPORTS=40 +CONFIG_NET_BUFFER_SIZE=420 +CONFIG_NET_LOGGING=y +CONFIG_NET_UDP=n +CONFIG_NET_UDP_CHECKSUMS=y +#CONFIG_NET_UDP_CONNS=10 +CONFIG_NET_STATISTICS=y +#CONFIG_NET_PINGADDRCONF=0 +#CONFIG_NET_RECEIVE_WINDOW= +#CONFIG_NET_ARPTAB_SIZE=8 +CONFIG_NET_BROADCAST=n +#CONFIG_NET_LLH_LEN=14 +CONFIG_NET_EXTERNAL_BUFFER=n +#CONFIG_NET_FWCACHE_SIZE=2 # # UIP Network Utilities -# CONFIG_UIP_DHCP_LIGHT - Reduces size of DHCP -# CONFIG_UIP_RESOLV_ENTRIES - Number of resolver entries -CONFIG_UIP_DHCP_LIGHT=n -CONFIG_UIP_RESOLV_ENTRIES=4 +# CONFIG_NET_DHCP_LIGHT - Reduces size of DHCP +# CONFIG_NET_RESOLV_ENTRIES - Number of resolver entries +CONFIG_NET_DHCP_LIGHT=n +CONFIG_NET_RESOLV_ENTRIES=4 # # Stack and heap information diff --git a/nuttx/configs/mcu123-lpc214x/defconfig b/nuttx/configs/mcu123-lpc214x/defconfig index 40692b853..f8874256a 100644 --- a/nuttx/configs/mcu123-lpc214x/defconfig +++ b/nuttx/configs/mcu123-lpc214x/defconfig @@ -263,48 +263,50 @@ CONFIG_PREALLOC_WDOGS=32 CONFIG_PREALLOC_TIMERS=8 # -# TCP/IP support via uIP -# CONFIG_NET_UIP - Enable or disable all uIP features -# CONFIG_NET_UIP_IPv6 - Build in support for IPv6 -# CONFIG_UIP_MAX_CONNECTIONS - Maximum number of TCP connections -# CONFIG_UIP_MAX_LISTENPORTS - Maximum number of listening TCP ports -# CONFIG_UIP_BUFFER_SIZE - uIP buffer size -# CONFIG_UIP_LOGGING - Logging on or off -# CONFIG_UIP_UDP - UDP support on or off -# CONFIG_UIP_UDP_CHECKSUMS - UDP checksums on or off -# CONFIG_UIP_UDP_CONNS - The maximum amount of concurrent UDP connections -# CONFIG_UIP_STATISTICS - uIP statistics on or off -# CONFIG_UIP_PINGADDRCONF - Use "ping" packet for setting IP address -# CONFIG_UIP_RECEIVE_WINDOW - The size of the advertised receiver's window -# CONFIG_UIP_ARPTAB_SIZE - The size of the ARP table -# CONFIG_UIP_BROADCAST - Broadcast support -# CONFIG_UIP_LLH_LEN - The link level header length -# CONFIG_UIP_EXTERNAL_BUFFER - Incoming packet buffer (uip_buf) is defined externally -# CONFIG_UIP_FWCACHE_SIZE - number of packets to remember when looking for duplicates -CONFIG_NET_UIP=n -CONFIG_NET_UIP_IPv6=n -CONFIG_UIP_MAX_CONNECTIONS=40 -CONFIG_UIP_MAX_LISTENPORTS=40 -CONFIG_UIP_BUFFER_SIZE=420 -CONFIG_UIP_LOGGING=y -CONFIG_UIP_UDP=n -CONFIG_UIP_UDP_CHECKSUMS=y -#CONFIG_UIP_UDP_CONNS=10 -CONFIG_UIP_STATISTICS=y -#CONFIG_UIP_PINGADDRCONF=0 -#CONFIG_UIP_RECEIVE_WINDOW= -#CONFIG_UIP_ARPTAB_SIZE=8 -CONFIG_UIP_BROADCAST=n -#CONFIG_UIP_LLH_LEN=14 -CONFIG_UIP_EXTERNAL_BUFFER=n -#CONFIG_UIP_FWCACHE_SIZE=2 +# TCP/IP and UDP support via uIP +# CONFIG_NET - Enable or disable all network features +# CONFIG_NET_IPv6 - Build in support for IPv6 +# CONFIG_NSOCKET_DESCRIPTORS - Maximum number of socket descriptors per task/thread. +# CONFIG_NET_MAX_CONNECTIONS - Maximum number of TCP connections +# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports +# CONFIG_NET_BUFFER_SIZE - uIP buffer size +# CONFIG_NET_LOGGING - Logging on or off +# CONFIG_NET_UDP - UDP support on or off +# CONFIG_NET_UDP_CHECKSUMS - UDP checksums on or off +# CONFIG_NET_UDP_CONNS - The maximum amount of concurrent UDP connections +# CONFIG_NET_STATISTICS - uIP statistics on or off +# CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address +# CONFIG_NET_RECEIVE_WINDOW - The size of the advertised receiver's window +# CONFIG_NET_ARPTAB_SIZE - The size of the ARP table +# CONFIG_NET_BROADCAST - Broadcast support +# CONFIG_NET_LLH_LEN - The link level header length +# CONFIG_NET_EXTERNAL_BUFFER - Incoming packet buffer (uip_buf) is defined externally +# CONFIG_NET_FWCACHE_SIZE - number of packets to remember when looking for duplicates +CONFIG_NET=n +CONFIG_NET_IPv6=n +CONFIG_NSOCKET_DESCRIPTORS=0 +CONFIG_NET_MAX_CONNECTIONS=40 +CONFIG_NET_MAX_LISTENPORTS=40 +CONFIG_NET_BUFFER_SIZE=420 +CONFIG_NET_LOGGING=y +CONFIG_NET_UDP=n +CONFIG_NET_UDP_CHECKSUMS=y +#CONFIG_NET_UDP_CONNS=10 +CONFIG_NET_STATISTICS=y +#CONFIG_NET_PINGADDRCONF=0 +#CONFIG_NET_RECEIVE_WINDOW= +#CONFIG_NET_ARPTAB_SIZE=8 +CONFIG_NET_BROADCAST=n +#CONFIG_NET_LLH_LEN=14 +CONFIG_NET_EXTERNAL_BUFFER=n +#CONFIG_NET_FWCACHE_SIZE=2 # # UIP Network Utilities -# CONFIG_UIP_DHCP_LIGHT - Reduces size of DHCP -# CONFIG_UIP_RESOLV_ENTRIES - Number of resolver entries -CONFIG_UIP_DHCP_LIGHT=n -CONFIG_UIP_RESOLV_ENTRIES=4 +# CONFIG_NET_DHCP_LIGHT - Reduces size of DHCP +# CONFIG_NET_RESOLV_ENTRIES - Number of resolver entries +CONFIG_NET_DHCP_LIGHT=n +CONFIG_NET_RESOLV_ENTRIES=4 # # Stack and heap information diff --git a/nuttx/configs/ntosd-dm320/defconfig b/nuttx/configs/ntosd-dm320/defconfig index 0a95f364d..7e1d182f1 100644 --- a/nuttx/configs/ntosd-dm320/defconfig +++ b/nuttx/configs/ntosd-dm320/defconfig @@ -248,48 +248,50 @@ CONFIG_PREALLOC_WDOGS=32 CONFIG_PREALLOC_TIMERS=8 # -# TCP/IP support via uIP -# CONFIG_NET_UIP - Enable or disable all uIP features -# CONFIG_NET_UIP_IPv6 - Build in support for IPv6 -# CONFIG_UIP_MAX_CONNECTIONS - Maximum number of TCP connections -# CONFIG_UIP_MAX_LISTENPORTS - Maximum number of listening TCP ports -# CONFIG_UIP_BUFFER_SIZE - uIP buffer size -# CONFIG_UIP_LOGGING - Logging on or off -# CONFIG_UIP_UDP - UDP support on or off -# CONFIG_UIP_UDP_CHECKSUMS - UDP checksums on or off -# CONFIG_UIP_UDP_CONNS - The maximum amount of concurrent UDP connections -# CONFIG_UIP_STATISTICS - uIP statistics on or off -# CONFIG_UIP_PINGADDRCONF - Use "ping" packet for setting IP address -# CONFIG_UIP_RECEIVE_WINDOW - The size of the advertised receiver's window -# CONFIG_UIP_ARPTAB_SIZE - The size of the ARP table -# CONFIG_UIP_BROADCAST - Broadcast support -# CONFIG_UIP_LLH_LEN - The link level header length -# CONFIG_UIP_EXTERNAL_BUFFER - Incoming packet buffer (uip_buf) is defined externally -# CONFIG_UIP_FWCACHE_SIZE - number of packets to remember when looking for duplicates -CONFIG_NET_UIP=y -CONFIG_NET_UIP_IPv6=n -CONFIG_UIP_MAX_CONNECTIONS=40 -CONFIG_UIP_MAX_LISTENPORTS=40 -CONFIG_UIP_BUFFER_SIZE=420 -CONFIG_UIP_LOGGING=y -CONFIG_UIP_UDP=n -CONFIG_UIP_UDP_CHECKSUMS=y -#CONFIG_UIP_UDP_CONNS=10 -CONFIG_UIP_STATISTICS=y -#CONFIG_UIP_PINGADDRCONF=0 -#CONFIG_UIP_RECEIVE_WINDOW= -#CONFIG_UIP_ARPTAB_SIZE=8 -CONFIG_UIP_BROADCAST=n -#CONFIG_UIP_LLH_LEN=14 -CONFIG_UIP_EXTERNAL_BUFFER=n -#CONFIG_UIP_FWCACHE_SIZE=2 +# TCP/IP and UDP support via uIP +# CONFIG_NET - Enable or disable all network features +# CONFIG_NET_IPv6 - Build in support for IPv6 +# CONFIG_NSOCKET_DESCRIPTORS - Maximum number of socket descriptors per task/thread. +# CONFIG_NET_MAX_CONNECTIONS - Maximum number of TCP connections +# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports +# CONFIG_NET_BUFFER_SIZE - uIP buffer size +# CONFIG_NET_LOGGING - Logging on or off +# CONFIG_NET_UDP - UDP support on or off +# CONFIG_NET_UDP_CHECKSUMS - UDP checksums on or off +# CONFIG_NET_UDP_CONNS - The maximum amount of concurrent UDP connections +# CONFIG_NET_STATISTICS - uIP statistics on or off +# CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address +# CONFIG_NET_RECEIVE_WINDOW - The size of the advertised receiver's window +# CONFIG_NET_ARPTAB_SIZE - The size of the ARP table +# CONFIG_NET_BROADCAST - Broadcast support +# CONFIG_NET_LLH_LEN - The link level header length +# CONFIG_NET_EXTERNAL_BUFFER - Incoming packet buffer (uip_buf) is defined externally +# CONFIG_NET_FWCACHE_SIZE - number of packets to remember when looking for duplicates +CONFIG_NET=y +CONFIG_NET_IPv6=n +CONFIG_NSOCKET_DESCRIPTORS=0 +CONFIG_NET_MAX_CONNECTIONS=40 +CONFIG_NET_MAX_LISTENPORTS=40 +CONFIG_NET_BUFFER_SIZE=420 +CONFIG_NET_LOGGING=y +CONFIG_NET_UDP=n +CONFIG_NET_UDP_CHECKSUMS=y +#CONFIG_NET_UDP_CONNS=10 +CONFIG_NET_STATISTICS=y +#CONFIG_NET_PINGADDRCONF=0 +#CONFIG_NET_RECEIVE_WINDOW= +#CONFIG_NET_ARPTAB_SIZE=8 +CONFIG_NET_BROADCAST=n +#CONFIG_NET_LLH_LEN=14 +CONFIG_NET_EXTERNAL_BUFFER=n +#CONFIG_NET_FWCACHE_SIZE=2 # # UIP Network Utilities -# CONFIG_UIP_DHCP_LIGHT - Reduces size of DHCP -# CONFIG_UIP_RESOLV_ENTRIES - Number of resolver entries -CONFIG_UIP_DHCP_LIGHT=n -CONFIG_UIP_RESOLV_ENTRIES=4 +# CONFIG_NET_DHCP_LIGHT - Reduces size of DHCP +# CONFIG_NET_RESOLV_ENTRIES - Number of resolver entries +CONFIG_NET_DHCP_LIGHT=n +CONFIG_NET_RESOLV_ENTRIES=4 # # Stack and heap information diff --git a/nuttx/configs/pjrc-8051/defconfig b/nuttx/configs/pjrc-8051/defconfig index 3857c85d8..1af793bd4 100644 --- a/nuttx/configs/pjrc-8051/defconfig +++ b/nuttx/configs/pjrc-8051/defconfig @@ -236,48 +236,50 @@ CONFIG_PREALLOC_WDOGS=4 CONFIG_PREALLOC_TIMERS=0 # -# TCP/IP support via uIP -# CONFIG_NET_UIP - Enable or disable all uIP features -# CONFIG_NET_UIP_IPv6 - Build in support for IPv6 -# CONFIG_UIP_MAX_CONNECTIONS - Maximum number of TCP connections -# CONFIG_UIP_MAX_LISTENPORTS - Maximum number of listening TCP ports -# CONFIG_UIP_BUFFER_SIZE - uIP buffer size -# CONFIG_UIP_LOGGING - Logging on or off -# CONFIG_UIP_UDP - UDP support on or off -# CONFIG_UIP_UDP_CHECKSUMS - UDP checksums on or off -# CONFIG_UIP_UDP_CONNS - The maximum amount of concurrent UDP connections -# CONFIG_UIP_STATISTICS - uIP statistics on or off -# CONFIG_UIP_PINGADDRCONF - Use "ping" packet for setting IP address -# CONFIG_UIP_RECEIVE_WINDOW - The size of the advertised receiver's window -# CONFIG_UIP_ARPTAB_SIZE - The size of the ARP table -# CONFIG_UIP_BROADCAST - Broadcast support -# CONFIG_UIP_LLH_LEN - The link level header length -# CONFIG_UIP_EXTERNAL_BUFFER - Incoming packet buffer (uip_buf) is defined externally -# CONFIG_UIP_FWCACHE_SIZE - number of packets to remember when looking for duplicates -CONFIG_NET_UIP=y -CONFIG_NET_UIP_IPv6=n -CONFIG_UIP_MAX_CONNECTIONS=40 -CONFIG_UIP_MAX_LISTENPORTS=40 -CONFIG_UIP_BUFFER_SIZE=420 -CONFIG_UIP_LOGGING=y -CONFIG_UIP_UDP=n -CONFIG_UIP_UDP_CHECKSUMS=y -#CONFIG_UIP_UDP_CONNS=10 -CONFIG_UIP_STATISTICS=y -#CONFIG_UIP_PINGADDRCONF=0 -#CONFIG_UIP_RECEIVE_WINDOW= -#CONFIG_UIP_ARPTAB_SIZE=8 -CONFIG_UIP_BROADCAST=n -#CONFIG_UIP_LLH_LEN=14 -CONFIG_UIP_EXTERNAL_BUFFER=n -#CONFIG_UIP_FWCACHE_SIZE=2 +# TCP/IP and UDP support via uIP +# CONFIG_NET - Enable or disable all network features +# CONFIG_NET_IPv6 - Build in support for IPv6 +# CONFIG_NSOCKET_DESCRIPTORS - Maximum number of socket descriptors per task/thread. +# CONFIG_NET_MAX_CONNECTIONS - Maximum number of TCP connections +# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports +# CONFIG_NET_BUFFER_SIZE - uIP buffer size +# CONFIG_NET_LOGGING - Logging on or off +# CONFIG_NET_UDP - UDP support on or off +# CONFIG_NET_UDP_CHECKSUMS - UDP checksums on or off +# CONFIG_NET_UDP_CONNS - The maximum amount of concurrent UDP connections +# CONFIG_NET_STATISTICS - uIP statistics on or off +# CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address +# CONFIG_NET_RECEIVE_WINDOW - The size of the advertised receiver's window +# CONFIG_NET_ARPTAB_SIZE - The size of the ARP table +# CONFIG_NET_BROADCAST - Broadcast support +# CONFIG_NET_LLH_LEN - The link level header length +# CONFIG_NET_EXTERNAL_BUFFER - Incoming packet buffer (uip_buf) is defined externally +# CONFIG_NET_FWCACHE_SIZE - number of packets to remember when looking for duplicates +CONFIG_NET=y +CONFIG_NET_IPv6=n +CONFIG_NSOCKET_DESCRIPTORS=0 +CONFIG_NET_MAX_CONNECTIONS=40 +CONFIG_NET_MAX_LISTENPORTS=40 +CONFIG_NET_BUFFER_SIZE=420 +CONFIG_NET_LOGGING=y +CONFIG_NET_UDP=n +CONFIG_NET_UDP_CHECKSUMS=y +#CONFIG_NET_UDP_CONNS=10 +CONFIG_NET_STATISTICS=y +#CONFIG_NET_PINGADDRCONF=0 +#CONFIG_NET_RECEIVE_WINDOW= +#CONFIG_NET_ARPTAB_SIZE=8 +CONFIG_NET_BROADCAST=n +#CONFIG_NET_LLH_LEN=14 +CONFIG_NET_EXTERNAL_BUFFER=n +#CONFIG_NET_FWCACHE_SIZE=2 # # UIP Network Utilities -# CONFIG_UIP_DHCP_LIGHT - Reduces size of DHCP -# CONFIG_UIP_RESOLV_ENTRIES - Number of resolver entries -CONFIG_UIP_DHCP_LIGHT=n -CONFIG_UIP_RESOLV_ENTRIES=4 +# CONFIG_NET_DHCP_LIGHT - Reduces size of DHCP +# CONFIG_NET_RESOLV_ENTRIES - Number of resolver entries +CONFIG_NET_DHCP_LIGHT=n +CONFIG_NET_RESOLV_ENTRIES=4 # # Stack and heap information diff --git a/nuttx/configs/sim/defconfig b/nuttx/configs/sim/defconfig index e2cd2a3a9..8dff468a9 100644 --- a/nuttx/configs/sim/defconfig +++ b/nuttx/configs/sim/defconfig @@ -210,48 +210,50 @@ CONFIG_PREALLOC_TIMERS=8 CONFIG_FS_FAT=y # -# TCP/IP support via uIP -# CONFIG_NET_UIP - Enable or disable all uIP features -# CONFIG_NET_UIP_IPv6 - Build in support for IPv6 -# CONFIG_UIP_MAX_CONNECTIONS - Maximum number of TCP connections -# CONFIG_UIP_MAX_LISTENPORTS - Maximum number of listening TCP ports -# CONFIG_UIP_BUFFER_SIZE - uIP buffer size -# CONFIG_UIP_LOGGING - Logging on or off -# CONFIG_UIP_UDP - UDP support on or off -# CONFIG_UIP_UDP_CHECKSUMS - UDP checksums on or off -# CONFIG_UIP_UDP_CONNS - The maximum amount of concurrent UDP connections -# CONFIG_UIP_STATISTICS - uIP statistics on or off -# CONFIG_UIP_PINGADDRCONF - Use "ping" packet for setting IP address -# CONFIG_UIP_RECEIVE_WINDOW - The size of the advertised receiver's window -# CONFIG_UIP_ARPTAB_SIZE - The size of the ARP table -# CONFIG_UIP_BROADCAST - Broadcast support -# CONFIG_UIP_LLH_LEN - The link level header length -# CONFIG_UIP_EXTERNAL_BUFFER - Incoming packet buffer (uip_buf) is defined externally -# CONFIG_UIP_FWCACHE_SIZE - number of packets to remember when looking for duplicates -CONFIG_NET_UIP=n -CONFIG_NET_UIP_IPv6=n -CONFIG_UIP_MAX_CONNECTIONS=40 -CONFIG_UIP_MAX_LISTENPORTS=40 -CONFIG_UIP_BUFFER_SIZE=420 -CONFIG_UIP_LOGGING=y -CONFIG_UIP_UDP=n -CONFIG_UIP_UDP_CHECKSUMS=y -#CONFIG_UIP_UDP_CONNS=10 -CONFIG_UIP_STATISTICS=y -#CONFIG_UIP_PINGADDRCONF=0 -#CONFIG_UIP_RECEIVE_WINDOW= -#CONFIG_UIP_ARPTAB_SIZE=8 -CONFIG_UIP_BROADCAST=n -#CONFIG_UIP_LLH_LEN=14 -CONFIG_UIP_EXTERNAL_BUFFER=n -#CONFIG_UIP_FWCACHE_SIZE=2 +# TCP/IP and UDP support via uIP +# CONFIG_NET - Enable or disable all network features +# CONFIG_NET_IPv6 - Build in support for IPv6 +# CONFIG_NSOCKET_DESCRIPTORS - Maximum number of socket descriptors per task/thread. +# CONFIG_NET_MAX_CONNECTIONS - Maximum number of TCP connections +# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports +# CONFIG_NET_BUFFER_SIZE - uIP buffer size +# CONFIG_NET_LOGGING - Logging on or off +# CONFIG_NET_UDP - UDP support on or off +# CONFIG_NET_UDP_CHECKSUMS - UDP checksums on or off +# CONFIG_NET_UDP_CONNS - The maximum amount of concurrent UDP connections +# CONFIG_NET_STATISTICS - uIP statistics on or off +# CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address +# CONFIG_NET_RECEIVE_WINDOW - The size of the advertised receiver's window +# CONFIG_NET_ARPTAB_SIZE - The size of the ARP table +# CONFIG_NET_BROADCAST - Broadcast support +# CONFIG_NET_LLH_LEN - The link level header length +# CONFIG_NET_EXTERNAL_BUFFER - Incoming packet buffer (uip_buf) is defined externally +# CONFIG_NET_FWCACHE_SIZE - number of packets to remember when looking for duplicates +CONFIG_NET=n +CONFIG_NET_IPv6=n +CONFIG_NSOCKET_DESCRIPTORS=8 +CONFIG_NET_MAX_CONNECTIONS=40 +CONFIG_NET_MAX_LISTENPORTS=40 +CONFIG_NET_BUFFER_SIZE=420 +CONFIG_NET_LOGGING=y +CONFIG_NET_UDP=n +CONFIG_NET_UDP_CHECKSUMS=y +#CONFIG_NET_UDP_CONNS=10 +CONFIG_NET_STATISTICS=y +#CONFIG_NET_PINGADDRCONF=0 +#CONFIG_NET_RECEIVE_WINDOW= +#CONFIG_NET_ARPTAB_SIZE=8 +CONFIG_NET_BROADCAST=n +#CONFIG_NET_LLH_LEN=14 +CONFIG_NET_EXTERNAL_BUFFER=n +#CONFIG_NET_FWCACHE_SIZE=2 # # UIP Network Utilities -# CONFIG_UIP_DHCP_LIGHT - Reduces size of DHCP -# CONFIG_UIP_RESOLV_ENTRIES - Number of resolver entries -CONFIG_UIP_DHCP_LIGHT=n -CONFIG_UIP_RESOLV_ENTRIES=4 +# CONFIG_NET_DHCP_LIGHT - Reduces size of DHCP +# CONFIG_NET_RESOLV_ENTRIES - Number of resolver entries +CONFIG_NET_DHCP_LIGHT=n +CONFIG_NET_RESOLV_ENTRIES=4 # # Stack and heap information diff --git a/nuttx/examples/uip/main.c b/nuttx/examples/uip/main.c index 1f88936a6..367e7e1c1 100644 --- a/nuttx/examples/uip/main.c +++ b/nuttx/examples/uip/main.c @@ -31,11 +31,12 @@ * * This file is part of the uIP TCP/IP stack. * - * $Id: main.c,v 1.2 2007-08-30 23:57:58 patacongo Exp $ + * $Id: main.c,v 1.3 2007-09-01 18:06:12 patacongo Exp $ * */ #include +#include #include #include @@ -63,12 +64,11 @@ int user_start(int argc, char *argv[]) { - int i; uip_ipaddr_t ipaddr; #if defined(CONFIG_EXAMPLE_UIP_DHCPC) uint16 mac[6] = {1, 2, 3, 4, 5, 6}; #endif -#ifdef CONFIG_EXAMPLE_UIP_SMTP +#if defined(CONFIG_EXAMPLE_UIP_DHCPC) || defined(CONFIG_EXAMPLE_UIP_SMTP) void *handle; #endif @@ -84,10 +84,20 @@ int user_start(int argc, char *argv[]) #elif defined(CONFIG_EXAMPLE_UIP_TELNETD) telnetd_init(); #elif defined(CONFIG_EXAMPLE_UIP_DHCPC) - dhcpc_init(&mac, 6); + handle = dhcpc_open(&mac, 6); + if (handle) + { + struct dhcpc_state ds; + (void)dhcpc_request(handle, &ds); + uip_sethostaddr(ds.ipaddr); + uip_setnetmask(ds.netmask); + uip_setdraddr(ds.default_router); + resolv_conf(ds.dnsaddr); + dhcpc_close(handle); + } #elif defined(CONFIG_EXAMPLE_UIP_SMTP) uip_ipaddr(ipaddr, 127, 0, 0, 1); - handle = smtp_init(); + handle = smtp_open(); if (handle) { smtp_configure("localhost", ipaddr); @@ -131,16 +141,6 @@ void resolv_found(char *name, uint16 *ipaddr) } } -#ifdef __DHCPC_H__ -void dhcpc_configured(const struct dhcpc_state *s) -{ - uip_sethostaddr(s->ipaddr); - uip_setnetmask(s->netmask); - uip_setdraddr(s->default_router); - resolv_conf(s->dnsaddr); -} -#endif /* __DHCPC_H__ */ - void webclient_closed(void) { printf("Webclient: connection closed\n"); diff --git a/nuttx/include/net/uip/dhcpc.h b/nuttx/include/net/uip/dhcpc.h new file mode 100644 index 000000000..f598c00ad --- /dev/null +++ b/nuttx/include/net/uip/dhcpc.h @@ -0,0 +1,72 @@ +/**************************************************************************** + * dhcpc.c + * + * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * This logic was leveraged from uIP which also has a BSD-style license: + * + * Copyright (c) 2005, 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. + */ + +#ifndef NET_UIP_DHCP_H__ +#define NET_UIP_DHCP_H__ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct dhcpc_state +{ + uint16 lease_time[2]; + uint8 serverid[4]; + uint16 ipaddr[2]; + uint16 netmask[2]; + uint16 dnsaddr[2]; + uint16 default_router[2]; +}; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +void *dhcpc_open(const void *mac_addr, int mac_len); +int dhcpc_request(void *handle, struct dhcpc_state *ds); +void dhcpc_close(void *handle); + +#endif /* NET_UIP_DHCP_H__ */ diff --git a/nuttx/include/net/uip/psock.h b/nuttx/include/net/uip/psock.h index 9e505c970..3ecc7abdc 100644 --- a/nuttx/include/net/uip/psock.h +++ b/nuttx/include/net/uip/psock.h @@ -1,9 +1,15 @@ -/* psock.h +/**************************************************************************** + * psock.h * Protosocket library header file - * Author: Adam Dunkels * - * Copyright (c) 2004, Swedish Institute of Computer Science. - * All rights reserved. + * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * This logic was leveraged from uIP which also has a BSD-style license: + * + * Author: Adam Dunkels + * Copyright (c) 2004, 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 @@ -28,7 +34,10 @@ * 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. - */ + ****************************************************************************/ + +#ifndef __NET_UIP_PSOCK_H +#define __NET_UIP_PSOCK_H /* psock Protosockets library * @@ -65,12 +74,20 @@ * */ -#ifndef __PSOCK_H__ -#define __PSOCK_H__ +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#ifdef CONFIG_NET #include #include +/**************************************************************************** + * Public Types + ****************************************************************************/ + /* The structure that holds the state of a buffer. * * This structure holds the state of a uIP buffer. The structure has @@ -103,6 +120,10 @@ struct psock unsigned char state; /* The state of the protosocket. */ }; +/**************************************************************************** + * Public FunctionPrototypes + ****************************************************************************/ + /* Initialize a protosocket. * * Initializes a protosocket and must be called before the @@ -232,6 +253,5 @@ extern boolean psock_checknewdata(struct psock *s); extern void psock_waitnewdata(struct psock *s); -#endif /* __PSOCK_H__ */ - -/** @} */ +#endif /* CONFIG_NET */ +#endif /* __NET_UIP_PSOCK_H */ diff --git a/nuttx/include/net/uip/uip.h b/nuttx/include/net/uip/uip.h index 0185a8da0..eddae8a66 100644 --- a/nuttx/include/net/uip/uip.h +++ b/nuttx/include/net/uip/uip.h @@ -1,14 +1,19 @@ -/** +/**************************************************************************** * uip.h * Header file for the uIP TCP/IP stack. - * author Adam Dunkels * * The uIP TCP/IP stack header file contains definitions for a number * of C macros that are used by uIP programs as well as internal uIP * structures, TCP/IP header structures and function declarations. * - * Copyright (c) 2001-2003, Adam Dunkels. - * All rights reserved. + * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * This logic was leveraged from uIP which also has a BSD-style license: + * + * Author Adam Dunkels + * Copyright (c) 2001-2003, Adam Dunkels. + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,14 +39,10 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * This file is part of the uIP TCP/IP stack. - * - * $Id: uip.h,v 1.1.1.1 2007-08-26 23:12:16 patacongo Exp $ - * ****************************************************************************/ -#ifndef __UIP_H__ -#define __UIP_H__ +#ifndef __NET_UIP_UIP_H +#define __NET_UIP_UIP_H /**************************************************************************** * Included Files @@ -117,11 +118,11 @@ #define UIP_PROTO_ICMP6 58 /* Header sizes. */ -#ifdef CONFIG_NET_UIP_IPv6 +#ifdef CONFIG_NET_IPv6 # define UIP_IPH_LEN 40 -#else /* CONFIG_NET_UIP_IPv6 */ +#else /* CONFIG_NET_IPv6 */ # define UIP_IPH_LEN 20 /* Size of IP header */ -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ #define UIP_UDPH_LEN 8 /* Size of UDP header */ #define UIP_TCPH_LEN 20 /* Size of TCP header */ #define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP + UDP header */ @@ -137,11 +138,11 @@ typedef uint16 uip_ip4addr_t[2]; typedef uint16 uip_ip6addr_t[8]; -#ifdef CONFIG_NET_UIP_IPv6 +#ifdef CONFIG_NET_IPv6 typedef uip_ip6addr_t uip_ipaddr_t; -#else /* CONFIG_NET_UIP_IPv6 */ +#else /* CONFIG_NET_IPv6 */ typedef uip_ip4addr_t uip_ipaddr_t; -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ /* Representation of a uIP TCP connection. * @@ -259,7 +260,7 @@ struct uip_stats { /* The TCP and IP headers. */ struct uip_tcpip_hdr { -#ifdef CONFIG_NET_UIP_IPv6 +#ifdef CONFIG_NET_IPv6 /* IPv6 header. */ uint8 vtc, @@ -268,7 +269,7 @@ struct uip_tcpip_hdr { uint8 len[2]; uint8 proto, ttl; uip_ip6addr_t srcipaddr, destipaddr; -#else /* CONFIG_NET_UIP_IPv6 */ +#else /* CONFIG_NET_IPv6 */ /* IPv4 header. */ uint8 vhl, @@ -281,7 +282,7 @@ struct uip_tcpip_hdr { uint16 ipchksum; uint16 srcipaddr[2], destipaddr[2]; -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ /* TCP header. */ @@ -300,7 +301,7 @@ struct uip_tcpip_hdr { /* The ICMP and IP headers. */ struct uip_icmpip_hdr { -#ifdef CONFIG_NET_UIP_IPv6 +#ifdef CONFIG_NET_IPv6 /* IPv6 header. */ uint8 vtc, @@ -309,7 +310,7 @@ struct uip_icmpip_hdr { uint8 len[2]; uint8 proto, ttl; uip_ip6addr_t srcipaddr, destipaddr; -#else /* CONFIG_NET_UIP_IPv6 */ +#else /* CONFIG_NET_IPv6 */ /* IPv4 header. */ uint8 vhl, @@ -322,24 +323,24 @@ struct uip_icmpip_hdr { uint16 ipchksum; uint16 srcipaddr[2], destipaddr[2]; -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ /* ICMP (echo) header. */ uint8 type, icode; uint16 icmpchksum; -#ifndef CONFIG_NET_UIP_IPv6 +#ifndef CONFIG_NET_IPv6 uint16 id, seqno; -#else /* !CONFIG_NET_UIP_IPv6 */ +#else /* !CONFIG_NET_IPv6 */ uint8 flags, reserved1, reserved2, reserved3; uint8 icmp6data[16]; uint8 options[1]; -#endif /* !CONFIG_NET_UIP_IPv6 */ +#endif /* !CONFIG_NET_IPv6 */ }; /* The UDP and IP headers. */ struct uip_udpip_hdr { -#ifdef CONFIG_NET_UIP_IPv6 +#ifdef CONFIG_NET_IPv6 /* IPv6 header. */ uint8 vtc, @@ -348,7 +349,7 @@ struct uip_udpip_hdr { uint8 len[2]; uint8 proto, ttl; uip_ip6addr_t srcipaddr, destipaddr; -#else /* CONFIG_NET_UIP_IPv6 */ +#else /* CONFIG_NET_IPv6 */ /* IP header. */ uint8 vhl, @@ -361,7 +362,7 @@ struct uip_udpip_hdr { uint16 ipchksum; uint16 srcipaddr[2], destipaddr[2]; -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ /* UDP header. */ @@ -634,9 +635,6 @@ void uip_unlisten(uint16 port); * which usually is done within 0.5 seconds after the call to * uip_connect(). * - * Note: This function is avaliable only if support for active open - * has been configured by defining UIP_ACTIVE_OPEN to 1 in uipopt.h. - * * Note: Since this function requires the port number to be in network * byte order, a conversion using HTONS() or htons() is necessary. * @@ -972,14 +970,14 @@ struct uip_udp_conn *uip_udp_new(uip_ipaddr_t *ripaddr, uint16 rport); * src The source from where to copy. */ -#ifndef CONFIG_NET_UIP_IPv6 +#ifndef CONFIG_NET_IPv6 #define uip_ipaddr_copy(dest, src) do { \ ((uint16 *)dest)[0] = ((uint16 *)src)[0]; \ ((uint16 *)dest)[1] = ((uint16 *)src)[1]; \ } while(0) -#else /* !CONFIG_NET_UIP_IPv6 */ +#else /* !CONFIG_NET_IPv6 */ #define uip_ipaddr_copy(dest, src) memcpy(dest, src, sizeof(uip_ip6addr_t)) -#endif /* !CONFIG_NET_UIP_IPv6 */ +#endif /* !CONFIG_NET_IPv6 */ /* Compare two IP addresses * @@ -996,12 +994,12 @@ struct uip_udp_conn *uip_udp_new(uip_ipaddr_t *ripaddr, uint16 rport); * addr2 The second IP address. */ -#ifndef CONFIG_NET_UIP_IPv6 +#ifndef CONFIG_NET_IPv6 #define uip_ipaddr_cmp(addr1, addr2) (((uint16 *)addr1)[0] == ((uint16 *)addr2)[0] && \ ((uint16 *)addr1)[1] == ((uint16 *)addr2)[1]) -#else /* !CONFIG_NET_UIP_IPv6 */ +#else /* !CONFIG_NET_IPv6 */ #define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0) -#endif /* !CONFIG_NET_UIP_IPv6 */ +#endif /* !CONFIG_NET_IPv6 */ /** * Compare two IP addresses with netmasks @@ -1169,4 +1167,4 @@ extern int uip_event_timedwait(uint16 waitflags, int timeout); extern void uip_event_signal(void); -#endif /* __UIP_H__ */ +#endif /* __NET_UIP_UIP_H */ diff --git a/nuttx/include/net/uip/uipopt.h b/nuttx/include/net/uip/uipopt.h index 1e468f6d8..5d19c778e 100644 --- a/nuttx/include/net/uip/uipopt.h +++ b/nuttx/include/net/uip/uipopt.h @@ -1,7 +1,6 @@ /**************************************************************************** * uipopt.h * Configuration options for uIP. - * author Adam Dunkels * * This file is used for tweaking various configuration options for * uIP. You should make a copy of this file into one of your project's @@ -17,8 +16,14 @@ * Note: Most of the configuration options in the uipopt.h should not * be changed, but rather the per-project defconfig file. * - * Copyright (c) 2001-2003, Adam Dunkels. - * All rights reserved. + * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * This logic was leveraged from uIP which also has a BSD-style license: + * + * Author: Adam Dunkels + * Copyright (c) 2001-2003, Adam Dunkels. + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -44,22 +49,27 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * This file is part of the uIP TCP/IP stack. - * - * $Id: uipopt.h,v 1.1.1.1 2007-08-26 23:12:17 patacongo Exp $ - * - */ + ****************************************************************************/ #ifndef __UIPOPT_H__ #define __UIPOPT_H__ +/**************************************************************************** + * Included Files + ****************************************************************************/ + #include #include -/*------------------------------------------------------------------------------*/ +/**************************************************************************** + * Public Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ -/** - * \name Static configuration options +/* Static configuration options * * These configuration options can be used for setting the IP address * settings statically, but only if UIP_FIXEDADDR is set to 1. The @@ -69,64 +79,52 @@ * if uIP should be run over Ethernet. * * All of these should be changed to suit your project. -*/ - -/** - * Statistics datatype - * - * This typedef defines the dataype used for keeping statistics in - * uIP. */ -typedef uint16 uip_stats_t; -/** - * Determines if uIP should use a fixed IP address or not. +/* Determines if uIP should use a fixed IP address or not. * * If uIP should use a fixed IP address, the settings are set in the * uipopt.h file. If not, the macros uip_sethostaddr(), * uip_setdraddr() and uip_setnetmask() should be used instead. */ + #define UIP_FIXEDADDR 0 -/** - * Ping IP address asignment. +/* Ping IP address asignment. * * uIP uses a "ping" packets for setting its own IP address if this * option is set. If so, uIP will start with an empty IP address and * the destination IP address of the first incoming "ping" (ICMP echo) * packet will be used for setting the hosts IP address. * - * \note This works only if UIP_FIXEDADDR is 0. + * Note: This works only if UIP_FIXEDADDR is 0. */ -#ifdef CONFIG_UIP_PINGADDRCONF -#define UIP_PINGADDRCONF CONFIG_UIP_PINGADDRCONF -#else /* CONFIG_UIP_PINGADDRCONF */ +#ifdef CONFIG_NET_PINGADDRCONF +#define UIP_PINGADDRCONF CONFIG_NET_PINGADDRCONF +#else /* CONFIG_NET_PINGADDRCONF */ #define UIP_PINGADDRCONF 0 -#endif /* CONFIG_UIP_PINGADDRCONF */ +#endif /* CONFIG_NET_PINGADDRCONF */ -/** - * Specifies if the uIP ARP module should be compiled with a fixed +/* Specifies if the uIP ARP module should be compiled with a fixed * Ethernet MAC address or not. * * If this configuration option is 0, the macro uip_setethaddr() can * be used to specify the Ethernet address at run-time. */ + #define UIP_FIXEDETHADDR 0 -/*------------------------------------------------------------------------------*/ -/** - * \name IP configuration options - */ -/** - * The IP TTL (time to live) of IP packets sent by uIP. +/* IP configuration options */ + +/* The IP TTL (time to live) of IP packets sent by uIP. * * This should normally not be changed. */ + #define UIP_TTL 64 -/** - * Turn on support for IP packet reassembly. +/* Turn on support for IP packet reassembly. * * uIP supports reassembly of fragmented IP packets. This features * requires an additonal amount of RAM to hold the reassembly buffer @@ -134,268 +132,222 @@ typedef uint16 uip_stats_t; * reassembly buffer is of the same size as the uip_buf buffer * (configured by UIP_BUFSIZE). * - * \note IP packet reassembly is not heavily tested. + * Note: IP packet reassembly is not heavily tested. */ + #define UIP_REASSEMBLY 0 -/** - * The maximum time an IP fragment should wait in the reassembly +/* The maximum time an IP fragment should wait in the reassembly * buffer before it is dropped. - * */ + #define UIP_REASS_MAXAGE 40 -/*------------------------------------------------------------------------------*/ -/** - * \name UDP configuration options - */ +/* UDP configuration options */ -/** - * Toggles wether UDP support should be compiled in or not. - */ -#ifdef CONFIG_UIP_UDP -# define UIP_UDP CONFIG_UIP_UDP -#else /* CONFIG_UIP_UDP */ +/* Toggles wether UDP support should be compiled in or not. */ + +#ifdef CONFIG_NET_UDP +# define UIP_UDP CONFIG_NET_UDP +#else /* CONFIG_NET_UDP */ # define UIP_UDP 0 -#endif /* CONFIG_UIP_UDP */ +#endif /* CONFIG_NET_UDP */ -/** - * Toggles if UDP checksums should be used or not. +/* Toggles if UDP checksums should be used or not. * - * \note Support for UDP checksums is currently not included in uIP, + * Note: Support for UDP checksums is currently not included in uIP, * so this option has no function. */ -#ifdef CONFIG_UIP_UDP_CHECKSUMS -# define UIP_UDP_CHECKSUMS CONFIG_UIP_UDP_CHECKSUMS + +#ifdef CONFIG_NET_UDP_CHECKSUMS +# define UIP_UDP_CHECKSUMS CONFIG_NET_UDP_CHECKSUMS #else # define UIP_UDP_CHECKSUMS 0 #endif -/** - * The maximum amount of concurrent UDP connections. - */ -#ifdef CONFIG_UIP_UDP_CONNS -# define UIP_UDP_CONNS CONFIG_UIP_UDP_CONNS -#else /* CONFIG_UIP_UDP_CONNS */ -# define UIP_UDP_CONNS 10 -#endif /* CONFIG_UIP_UDP_CONNS */ - -/** - * The name of the function that should be called when UDP datagrams arrive. - */ +/* The maximum amount of concurrent UDP connections. */ +#ifdef CONFIG_NET_UDP_CONNS +# define UIP_UDP_CONNS CONFIG_NET_UDP_CONNS +#else /* CONFIG_NET_UDP_CONNS */ +# define UIP_UDP_CONNS 10 +#endif /* CONFIG_NET_UDP_CONNS */ -/*------------------------------------------------------------------------------*/ -/** - * \name TCP configuration options - */ +/* TCP configuration options */ -/** - * Determines if support for opening connections from uIP should be - * compiled in. - * - * If the applications that are running on top of uIP for this project - * do not need to open outgoing TCP connections, this configration - * option can be turned off to reduce the code size of uIP. - */ -#define UIP_ACTIVE_OPEN 1 - -/** - * The maximum number of simultaneously open TCP connections. +/* The maximum number of simultaneously open TCP connections. * * Since the TCP connections are statically allocated, turning this * configuration knob down results in less RAM used. Each TCP * connection requires approximatly 30 bytes of memory. */ -#ifndef CONFIG_UIP_MAX_CONNECTIONS + +#ifndef CONFIG_NET_MAX_CONNECTIONS # define UIP_CONNS 10 -#else /* CONFIG_UIP_MAX_CONNECTIONS */ -# define UIP_CONNS CONFIG_UIP_MAX_CONNECTIONS -#endif /* CONFIG_UIP_MAX_CONNECTIONS */ +#else /* CONFIG_NET_MAX_CONNECTIONS */ +# define UIP_CONNS CONFIG_NET_MAX_CONNECTIONS +#endif /* CONFIG_NET_MAX_CONNECTIONS */ -/** - * The maximum number of simultaneously listening TCP ports. +/* The maximum number of simultaneously listening TCP ports. * * Each listening TCP port requires 2 bytes of memory. */ -#ifndef CONFIG_UIP_MAX_LISTENPORTS + +#ifndef CONFIG_NET_MAX_LISTENPORTS # define UIP_LISTENPORTS 20 -#else /* CONFIG_UIP_MAX_LISTENPORTS */ -# define UIP_LISTENPORTS CONFIG_UIP_MAX_LISTENPORTS -#endif /* CONFIG_UIP_MAX_LISTENPORTS */ +#else /* CONFIG_NET_MAX_LISTENPORTS */ +# define UIP_LISTENPORTS CONFIG_NET_MAX_LISTENPORTS +#endif /* CONFIG_NET_MAX_LISTENPORTS */ -/** - * Determines if support for TCP urgent data notification should be +/* Determines if support for TCP urgent data notification should be * compiled in. * * Urgent data (out-of-band data) is a rarely used TCP feature that * very seldom would be required. */ + #define UIP_URGDATA 0 -/** - * The initial retransmission timeout counted in timer pulses. +/* The initial retransmission timeout counted in timer pulses. * * This should not be changed. */ + #define UIP_RTO 3 -/** - * The maximum number of times a segment should be retransmitted +/* The maximum number of times a segment should be retransmitted * before the connection should be aborted. * * This should not be changed. */ + #define UIP_MAXRTX 8 -/** - * The maximum number of times a SYN segment should be retransmitted +/* The maximum number of times a SYN segment should be retransmitted * before a connection request should be deemed to have been * unsuccessful. * * This should not need to be changed. */ + #define UIP_MAXSYNRTX 5 -/** - * The TCP maximum segment size. +/* The TCP maximum segment size. * * This is should not be to set to more than * UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN. */ + #define UIP_TCP_MSS (UIP_BUFSIZE - UIP_LLH_LEN - UIP_TCPIP_HLEN) -/** - * The size of the advertised receiver's window. +/* The size of the advertised receiver's window. * * Should be set low (i.e., to the size of the uip_buf buffer) is the * application is slow to process incoming data, or high (32768 bytes) * if the application processes data quickly. */ -#ifndef CONFIG_UIP_RECEIVE_WINDOW + +#ifndef CONFIG_NET_RECEIVE_WINDOW # define UIP_RECEIVE_WINDOW UIP_TCP_MSS #else -# define UIP_RECEIVE_WINDOW CONFIG_UIP_RECEIVE_WINDOW +# define UIP_RECEIVE_WINDOW CONFIG_NET_RECEIVE_WINDOW #endif -/** - * How long a connection should stay in the TIME_WAIT state. +/* How long a connection should stay in the TIME_WAIT state. * * This configiration option has no real implication, and it should be * left untouched. */ + #define UIP_TIME_WAIT_TIMEOUT 120 +/* ARP configuration options */ -/*------------------------------------------------------------------------------*/ -/** - * \name ARP configuration options - */ - -/** - * The size of the ARP table. +/* The size of the ARP table. * * This option should be set to a larger value if this uIP node will * have many connections from the local network. */ -#ifdef CONFIG_UIP_ARPTAB_SIZE -# define UIP_ARPTAB_SIZE CONFIG_UIP_ARPTAB_SIZE + +#ifdef CONFIG_NET_ARPTAB_SIZE +# define UIP_ARPTAB_SIZE CONFIG_NET_ARPTAB_SIZE #else # define UIP_ARPTAB_SIZE 8 #endif -/** - * The maxium age of ARP table entries measured in 10ths of seconds. +/* The maxium age of ARP table entries measured in 10ths of seconds. * * An UIP_ARP_MAXAGE of 120 corresponds to 20 minutes (BSD * default). */ -#define UIP_ARP_MAXAGE 120 -/*------------------------------------------------------------------------------*/ +#define UIP_ARP_MAXAGE 120 -/** - * \name General configuration options - */ +/* General configuration options */ -/** - * The size of the uIP packet buffer. +/* The size of the uIP packet buffer. * * The uIP packet buffer should not be smaller than 60 bytes, and does * not need to be larger than 1500 bytes. Lower size results in lower * TCP throughput, larger size results in higher TCP throughput. */ -#ifndef CONFIG_UIP_BUFFER_SIZE -# define UIP_BUFSIZE 400 -#else /* CONFIG_UIP_BUFFER_SIZE */ -# define UIP_BUFSIZE CONFIG_UIP_BUFFER_SIZE -#endif /* CONFIG_UIP_BUFFER_SIZE */ +#ifndef CONFIG_NET_BUFFER_SIZE +# define UIP_BUFSIZE 400 +#else /* CONFIG_NET_BUFFER_SIZE */ +# define UIP_BUFSIZE CONFIG_NET_BUFFER_SIZE +#endif /* CONFIG_NET_BUFFER_SIZE */ -/** - * Determines if statistics support should be compiled in. +/* Determines if statistics support should be compiled in. * * The statistics is useful for debugging and to show the user. */ -#ifndef CONFIG_UIP_STATISTICS +#ifndef CONFIG_NET_STATISTICS # define UIP_STATISTICS 0 -#else /* CONFIG_UIP_STATISTICS */ -# define UIP_STATISTICS CONFIG_UIP_STATISTICS -#endif /* CONFIG_UIP_STATISTICS */ +#else /* CONFIG_NET_STATISTICS */ +# define UIP_STATISTICS CONFIG_NET_STATISTICS +#endif /* CONFIG_NET_STATISTICS */ -/** - * Determines if logging of certain events should be compiled in. +/* Determines if logging of certain events should be compiled in. * * This is useful mostly for debugging. The function uip_log() * must be implemented to suit the architecture of the project, if * logging is turned on. */ -#ifndef CONFIG_UIP_LOGGING +#ifndef CONFIG_NET_LOGGING # define UIP_LOGGING 0 -#else /* CONFIG_UIP_LOGGING */ -# define UIP_LOGGING CONFIG_UIP_LOGGING -#endif /* CONFIG_UIP_LOGGING */ +#else /* CONFIG_NET_LOGGING */ +# define UIP_LOGGING CONFIG_NET_LOGGING +#endif /* CONFIG_NET_LOGGING */ -/** - * Broadcast support. +/* Broadcast support. * * This flag configures IP broadcast support. This is useful only * together with UDP. */ -#ifndef CONFIG_UIP_BROADCAST +#ifndef CONFIG_NET_BROADCAST # define UIP_BROADCAST 0 -#else /* CONFIG_UIP_BROADCAST */ -# define UIP_BROADCAST CONFIG_UIP_BROADCAST -#endif /* CONFIG_UIP_BROADCAST */ +#else /* CONFIG_NET_BROADCAST */ +# define UIP_BROADCAST CONFIG_NET_BROADCAST +#endif /* CONFIG_NET_BROADCAST */ -/** - * Print out a uIP log message. - * - * This function must be implemented by the module that uses uIP, and - * is called by uIP whenever a log message is generated. - */ -void uip_log(char *msg); - -/** - * The link level header length. +/* The link level header length. * * This is the offset into the uip_buf where the IP header can be * found. For Ethernet, this should be set to 14. For SLIP, this * should be set to 0. */ -#ifdef CONFIG_UIP_LLH_LEN -# define UIP_LLH_LEN CONFIG_UIP_LLH_LEN -#else /* CONFIG_UIP_LLH_LEN */ +#ifdef CONFIG_NET_LLH_LEN +# define UIP_LLH_LEN CONFIG_NET_LLH_LEN +#else /* CONFIG_NET_LLH_LEN */ # define UIP_LLH_LEN 14 -#endif /* CONFIG_UIP_LLH_LEN */ +#endif /* CONFIG_NET_LLH_LEN */ -/*------------------------------------------------------------------------------*/ -/** - * \name CPU architecture configuration +/* CPU architecture configuration * * The CPU architecture configuration is where the endianess of the * CPU on which uIP is to be run is specified. Most CPUs today are @@ -404,8 +356,7 @@ void uip_log(char *msg); * if uIP is to be run on a big endian architecture. */ -/** - * The byte order of the CPU architecture on which uIP is to be run. +/* The byte order of the CPU architecture on which uIP is to be run. * * This option can be either CONFIG_ENDIAN_BIG (Motorola byte order) or * default little endian byte order (Intel byte order). @@ -420,4 +371,28 @@ void uip_log(char *msg); # define UIP_BYTE_ORDER UIP_LITTLE_ENDIAN #endif +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/* Statistics datatype + * + * This typedef defines the dataype used for keeping statistics in + * uIP. + */ + +typedef uint16 uip_stats_t; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/* Print out a uIP log message. + * + * This function must be implemented by the module that uses uIP, and + * is called by uIP whenever a log message is generated. + */ + +void uip_log(char *msg); + #endif /* __UIPOPT_H__ */ diff --git a/nuttx/include/nuttx/net.h b/nuttx/include/nuttx/net.h new file mode 100644 index 000000000..afeab94d5 --- /dev/null +++ b/nuttx/include/nuttx/net.h @@ -0,0 +1,101 @@ +/**************************************************************************** + * net.h + * + * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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. + * + ****************************************************************************/ + +#ifndef __NUTTX_NET_H +#define __NUTTX_NET_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#ifdef CONFIG_NET + +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* This is the internal representation of a socket reference by a file + * descriptor. + */ + +struct socket +{ + /* Proto-socket */ + + struct psock psock; +}; + +/* This defines a list of sockets indexed by the socket descriptor */ + +#if CONFIG_NSOCKET_DESCRIPTORS > 0 +struct socketlist +{ + sem_t sl_sem; /* Manage access to the socket list */ + sint16 sl_crefs; /* Reference count */ + struct socket sl_sockets[CONFIG_NSOCKET_DESCRIPTORS]; +}; +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/* net_sockets.c *************************************************************/ + +EXTERN FAR struct socketlist *net_alloclist(void); +EXTERN int net_addreflist(FAR struct socketlist *list); +EXTERN int net_releaselist(FAR struct socketlist *list); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_NET */ +#endif /* __NUTTX_NET_H */ diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h index 84a8026b2..1de713843 100644 --- a/nuttx/include/nuttx/sched.h +++ b/nuttx/include/nuttx/sched.h @@ -48,6 +48,7 @@ #include #include #include +#include /******************************************************************************** * Definitions @@ -166,7 +167,7 @@ struct _TCB { /* Fields used to support list management *************************************/ - FAR struct _TCB *flink; /* link in DQ of TCBs */ + FAR struct _TCB *flink; /* link in DQ of TCBs */ FAR struct _TCB *blink; /* Task Management Fields *****************************************************/ @@ -247,6 +248,12 @@ struct _TCB FAR struct streamlist *streams; /* Holds C buffered I/O info */ #endif + /* Network socket *************************************************************/ + +#if CONFIG_NSOCKET_DESCRIPTORS > 0 + FAR struct socketlist *sockets; /* Maps file descriptor to file */ +#endif + /* State save areas ***********************************************************/ /* The form and content of these fields are processor-specific. */ @@ -287,6 +294,10 @@ EXTERN FAR struct streamlist *sched_getstreams(void); #endif /* CONFIG_NFILE_STREAMS */ #endif /* CONFIG_NFILE_DESCRIPTORS */ +#if CONFIG_NSOCKET_DESCRIPTORS > 0 +EXTERN FAR struct socketlist *sched_getsockets(void); +#endif /* CONFIG_NSOCKET_DESCRIPTORS */ + /* sched_foreach will enumerate over each task and provide the * TCB of each task to a user callback functions. Interrupts * will be disabled throughout this enumeration! diff --git a/nuttx/lib/lib_dirname.c b/nuttx/lib/lib_dirname.c index 06328a2d6..b77a0b689 100644 --- a/nuttx/lib/lib_dirname.c +++ b/nuttx/lib/lib_dirname.c @@ -100,7 +100,7 @@ char *dirname(char *path) /* Check for trailing slash characters */ len = strlen(path); - while (path[len-1] = '/') + while (path[len-1] == '/') { /* Remove trailing '/' UNLESS this would make a zero length string */ if (len > 1) diff --git a/nuttx/net/Makefile b/nuttx/net/Makefile index 52c055014..3f5103872 100644 --- a/nuttx/net/Makefile +++ b/nuttx/net/Makefile @@ -37,9 +37,9 @@ MKDEP = $(TOPDIR)/tools/mkdeps.sh -ifeq ($(CONFIG_NET_UIP),y) +ifeq ($(CONFIG_NET),y) STD_ASRCS = -STD_CSRCS = socket.c bind.c +STD_CSRCS = socket.c bind.c net_sockets.c include uip/Make.defs endif @@ -71,7 +71,7 @@ $(BIN): $(OBJS) done ; ) .depend: Makefile $(SRCS) -ifeq ($(CONFIG_NET_UIP),y) +ifeq ($(CONFIG_NET),y) $(MKDEP) --dep-path . --dep-path uip $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep endif touch $@ diff --git a/nuttx/net/net_internal.h b/nuttx/net/net_internal.h new file mode 100644 index 000000000..6d388d44f --- /dev/null +++ b/nuttx/net/net_internal.h @@ -0,0 +1,82 @@ +/**************************************************************************** + * net_internal.h + * + * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 Gregory Nutt 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. + * + ****************************************************************************/ + +#ifndef __NET_INTERNAL_H +#define __NET_INTERNAL_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#ifdef CONFIG_NET + +#include + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Variables + ****************************************************************************/ + +/**************************************************************************** + * Pulblic Function Prototypes + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/* net_sockets.c *************************************************************/ + +EXTERN void weak_function net_initialize(void); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* CONFIG_NET */ +#endif /* __NET_INTERNAL_H */ diff --git a/nuttx/net/net_sockets.c b/nuttx/net/net_sockets.c new file mode 100644 index 000000000..fb4927e72 --- /dev/null +++ b/nuttx/net/net_sockets.c @@ -0,0 +1,171 @@ +/**************************************************************************** + * net_sockets.c + * + * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 Gregory Nutt 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 +#include +#include +#include +#include +#include +#include +#include +#include "net_internal.h" + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static void _net_semtake(FAR struct socketlist *list) +{ + /* Take the semaphore (perhaps waiting) */ + + while (sem_wait(&list->sl_sem) != 0) + { + /* The only case that an error should occr here is if + * the wait was awakened by a signal. + */ + + ASSERT(*get_errno_ptr() == EINTR); + } +} + +#define _net_semgive(list) sem_post(&list->sl_sem) + +/**************************************************************************** + * Pulblic Functions + ****************************************************************************/ + +/* This is called from the initialization logic to configure the socket layer */ + +void net_initialize(void) +{ +} + +/* Allocate a list of files for a new task */ + +FAR struct socketlist *net_alloclist(void) +{ + FAR struct socketlist *list; + list = (FAR struct socketlist*)kzmalloc(sizeof(struct socketlist)); + if (list) + { + /* Start with a reference count of one */ + + list->sl_crefs = 1; + + /* Initialize the list access mutex */ + + (void)sem_init(&list->sl_sem, 0, 1); + } + return list; +} + +/* Increase the reference count on a file list */ + +int net_addreflist(FAR struct socketlist *list) +{ + if (list) + { + /* Increment the reference count on the list. + * NOTE: that we disable interrupts to do this + * (vs. taking the list semaphore). We do this + * because file cleanup operations often must be + * done from the IDLE task which cannot wait + * on semaphores. + */ + + register irqstate_t flags = irqsave(); + list->sl_crefs++; + irqrestore(flags); + } + return OK; +} + +/* Release a reference to the file list */ + +int net_releaselist(FAR struct socketlist *list) +{ + int crefs; + if (list) + { + /* Decrement the reference count on the list. + * NOTE: that we disable interrupts to do this + * (vs. taking the list semaphore). We do this + * because file cleanup operations often must be + * done from the IDLE task which cannot wait + * on semaphores. + */ + + irqstate_t flags = irqsave(); + crefs = --(list->sl_crefs); + irqrestore(flags); + + /* If the count decrements to zero, then there is no reference + * to the structure and it should be deallocated. Since there + * are references, it would be an error if any task still held + * a reference to the list's semaphore. + */ + + if (crefs <= 0) + { + /* Destroy the semaphore and release the filelist */ + + (void)sem_destroy(&list->sl_sem); + sched_free(list); + } + } + return OK; +} + diff --git a/nuttx/net/uip/psock.c b/nuttx/net/uip/psock.c index 892c97602..24269a60a 100644 --- a/nuttx/net/uip/psock.c +++ b/nuttx/net/uip/psock.c @@ -30,7 +30,7 @@ * * Author: Adam Dunkels * - * $Id: psock.c,v 1.1.1.1 2007-08-26 23:04:11 patacongo Exp $ + * $Id: psock.c,v 1.2 2007-09-01 18:06:13 patacongo Exp $ */ #include @@ -375,3 +375,4 @@ void psock_init(register struct psock *psock, char *buffer, unsigned int buffers psock->bufsize = buffersize; buf_setup(&psock->buf, (uint8*)buffer, buffersize); } + diff --git a/nuttx/net/uip/uip-fw.c b/nuttx/net/uip/uip-fw.c index 7e5356f56..8914994ea 100644 --- a/nuttx/net/uip/uip-fw.c +++ b/nuttx/net/uip/uip-fw.c @@ -136,8 +136,8 @@ struct fwcache_entry { /* * The number of packets to remember when looking for duplicates. */ -#ifdef CONFIG_UIP_FWCACHE_SIZE -# define FWCACHE_SIZE CONFIG_UIP_FWCACHE_SIZE +#ifdef CONFIG_NET_FWCACHE_SIZE +# define FWCACHE_SIZE CONFIG_NET_FWCACHE_SIZE #else # define FWCACHE_SIZE 2 #endif diff --git a/nuttx/net/uip/uip-neighbor.c b/nuttx/net/uip/uip-neighbor.c index 6da1a891d..d2fb74304 100644 --- a/nuttx/net/uip/uip-neighbor.c +++ b/nuttx/net/uip/uip-neighbor.c @@ -1,6 +1,11 @@ /* - * Copyright (c) 2006, Swedish Institute of Computer Science. - * All rights reserved. + * uip-neighbor.c + * Database of link-local neighbors, used by IPv6 code and to be used by + * a future ARP code rewrite. + * + * Author: Adam Dunkels + * Copyright (c) 2006, 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 @@ -25,23 +30,12 @@ * 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. - * - * This file is part of the uIP TCP/IP stack - * - * $Id: uip-neighbor.c,v 1.1.1.1 2007-08-26 23:04:08 patacongo Exp $ - */ - -/** - * \file - * Database of link-local neighbors, used by IPv6 code and - * to be used by a future ARP code rewrite. - * \author - * Adam Dunkels */ #include "uip-neighbor.h" #include +#include #define MAX_TIME 128 @@ -51,108 +45,115 @@ #define ENTRIES 8 #endif /* UIP_NEIGHBOR_CONF_ENTRIES */ -struct neighbor_entry { +struct neighbor_entry +{ uip_ipaddr_t ipaddr; struct uip_neighbor_addr addr; uint8 time; }; static struct neighbor_entry entries[ENTRIES]; -/*---------------------------------------------------------------------------*/ -void -uip_neighbor_init(void) +void uip_neighbor_init(void) { int i; - for(i = 0; i < ENTRIES; ++i) { - entries[i].time = MAX_TIME; - } + for(i = 0; i < ENTRIES; ++i) + { + entries[i].time = MAX_TIME; + } } -/*---------------------------------------------------------------------------*/ -void -uip_neighbor_periodic(void) + +void uip_neighbor_periodic(void) { int i; - for(i = 0; i < ENTRIES; ++i) { - if(entries[i].time < MAX_TIME) { - entries[i].time++; + for(i = 0; i < ENTRIES; ++i) + { + if (entries[i].time < MAX_TIME) + { + entries[i].time++; + } } - } } -/*---------------------------------------------------------------------------*/ -void -uip_neighbor_add(uip_ipaddr_t ipaddr, struct uip_neighbor_addr *addr) + +void uip_neighbor_add(uip_ipaddr_t ipaddr, struct uip_neighbor_addr *addr) { int i, oldest; uint8 oldest_time; - printf("Adding neighbor with link address %02x:%02x:%02x:%02x:%02x:%02x\n", - addr->addr.addr[0], addr->addr.addr[1], addr->addr.addr[2], addr->addr.addr[3], - addr->addr.addr[4], addr->addr.addr[5]); - + dbg("Adding neighbor with link address %02x:%02x:%02x:%02x:%02x:%02x\n", + addr->addr.addr[0], addr->addr.addr[1], addr->addr.addr[2], addr->addr.addr[3], + addr->addr.addr[4], addr->addr.addr[5]); + /* Find the first unused entry or the oldest used entry. */ + oldest_time = 0; oldest = 0; - for(i = 0; i < ENTRIES; ++i) { - if(entries[i].time == MAX_TIME) { - oldest = i; - break; - } - if(uip_ipaddr_cmp(entries[i].ipaddr, addr)) { - oldest = i; - break; - } - if(entries[i].time > oldest_time) { - oldest = i; - oldest_time = entries[i].time; + for (i = 0; i < ENTRIES; ++i) + { + if (entries[i].time == MAX_TIME) + { + oldest = i; + break; + } + if (uip_ipaddr_cmp(entries[i].ipaddr, addr)) + { + oldest = i; + break; + } + if (entries[i].time > oldest_time) + { + oldest = i; + oldest_time = entries[i].time; + } } - } /* Use the oldest or first free entry (either pointed to by the - "oldest" variable). */ + * "oldest" variable). + */ + entries[oldest].time = 0; uip_ipaddr_copy(entries[oldest].ipaddr, ipaddr); memcpy(&entries[oldest].addr, addr, sizeof(struct uip_neighbor_addr)); } -/*---------------------------------------------------------------------------*/ -static struct neighbor_entry * -find_entry(uip_ipaddr_t ipaddr) + +static struct neighbor_entry *find_entry(uip_ipaddr_t ipaddr) { int i; - - for(i = 0; i < ENTRIES; ++i) { - if(uip_ipaddr_cmp(entries[i].ipaddr, ipaddr)) { - return &entries[i]; + + for(i = 0; i < ENTRIES; ++i) + { + if (uip_ipaddr_cmp(entries[i].ipaddr, ipaddr)) + { + return &entries[i]; + } } - } return NULL; } -/*---------------------------------------------------------------------------*/ -void -uip_neighbor_update(uip_ipaddr_t ipaddr) + +void uip_neighbor_update(uip_ipaddr_t ipaddr) { struct neighbor_entry *e; e = find_entry(ipaddr); - if(e != NULL) { - e->time = 0; - } + if (e != NULL) + { + e->time = 0; + } } -/*---------------------------------------------------------------------------*/ -struct uip_neighbor_addr * -uip_neighbor_lookup(uip_ipaddr_t ipaddr) + +struct uip_neighbor_addr *uip_neighbor_lookup(uip_ipaddr_t ipaddr) { struct neighbor_entry *e; e = find_entry(ipaddr); - if(e != NULL) { - /* printf("Lookup neighbor with link address %02x:%02x:%02x:%02x:%02x:%02x\n", - e->addr.addr.addr[0], e->addr.addr.addr[1], e->addr.addr.addr[2], e->addr.addr.addr[3], - e->addr.addr.addr[4], e->addr.addr.addr[5]);*/ + if (e != NULL) + { + dbg("Lookup neighbor with link address %02x:%02x:%02x:%02x:%02x:%02x\n", + e->addr.addr.addr[0], e->addr.addr.addr[1], e->addr.addr.addr[2], e->addr.addr.addr[3], + e->addr.addr.addr[4], e->addr.addr.addr[5]); return &e->addr; } return NULL; } -/*---------------------------------------------------------------------------*/ diff --git a/nuttx/net/uip/uip-split.c b/nuttx/net/uip/uip-split.c index 155418a9c..a85a8db96 100644 --- a/nuttx/net/uip/uip-split.c +++ b/nuttx/net/uip/uip-split.c @@ -61,25 +61,25 @@ uip_split_output(void) /* Create the first packet. This is done by altering the length field of the IP header and updating the checksums. */ uip_len = len1 + UIP_TCPIP_HLEN; -#ifdef CONFIG_NET_UIP_IPv6 +#ifdef CONFIG_NET_IPv6 /* For IPv6, the IP length field does not include the IPv6 IP header length. */ BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8); BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff); -#else /* CONFIG_NET_UIP_IPv6 */ +#else /* CONFIG_NET_IPv6 */ BUF->len[0] = uip_len >> 8; BUF->len[1] = uip_len & 0xff; -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ /* Recalculate the TCP checksum. */ BUF->tcpchksum = 0; BUF->tcpchksum = ~(uip_tcpchksum()); -#ifndef CONFIG_NET_UIP_IPv6 +#ifndef CONFIG_NET_IPv6 /* Recalculate the IP checksum. */ BUF->ipchksum = 0; BUF->ipchksum = ~(uip_ipchksum()); -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ /* Transmit the first packet. */ /* uip_fw_output();*/ @@ -91,15 +91,15 @@ uip_split_output(void) memory. This place is detemined by the length of the first packet (len1). */ uip_len = len2 + UIP_TCPIP_HLEN; -#ifdef CONFIG_NET_UIP_IPv6 +#ifdef CONFIG_NET_IPv6 /* For IPv6, the IP length field does not include the IPv6 IP header length. */ BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8); BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff); -#else /* CONFIG_NET_UIP_IPv6 */ +#else /* CONFIG_NET_IPv6 */ BUF->len[0] = uip_len >> 8; BUF->len[1] = uip_len & 0xff; -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ /* uip_appdata += len1;*/ memcpy(uip_appdata, (uint8 *)uip_appdata + len1, len2); @@ -114,11 +114,11 @@ uip_split_output(void) BUF->tcpchksum = 0; BUF->tcpchksum = ~(uip_tcpchksum()); -#ifndef CONFIG_NET_UIP_IPv6 +#ifndef CONFIG_NET_IPv6 /* Recalculate the IP checksum. */ BUF->ipchksum = 0; BUF->ipchksum = ~(uip_ipchksum()); -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ /* Transmit the second packet. */ /* uip_fw_output();*/ diff --git a/nuttx/net/uip/uip.c b/nuttx/net/uip/uip.c index b81c85cd9..81208a8b5 100644 --- a/nuttx/net/uip/uip.c +++ b/nuttx/net/uip/uip.c @@ -79,9 +79,9 @@ #include #include -#ifdef CONFIG_NET_UIP_IPv6 +#ifdef CONFIG_NET_IPv6 # include "uip-neighbor.h" -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ #include @@ -125,10 +125,11 @@ extern void uip_log(char *msg); #define ICMP6_OPTION_TARGET_LINK_ADDRESS 2 /* Macros. */ -#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN]) -#define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0]) + +#define BUF ((struct uip_tcpip_hdr *)&uip_buf[UIP_LLH_LEN]) +#define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0]) #define ICMPBUF ((struct uip_icmpip_hdr *)&uip_buf[UIP_LLH_LEN]) -#define UDPBUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN]) +#define UDPBUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN]) /**************************************************************************** * Public Variables @@ -153,9 +154,9 @@ const uip_ipaddr_t uip_netmask = uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask; #endif /* UIP_FIXEDADDR */ -#ifndef CONFIG_UIP_EXTERNAL_BUFFER +#ifndef CONFIG_NET_EXTERNAL_BUFFER uint8 uip_buf[UIP_BUFSIZE + 2]; /* The packet buffer that contains incoming packets. */ -#endif /* CONFIG_UIP_EXTERNAL_BUFFER */ +#endif /* CONFIG_NET_EXTERNAL_BUFFER */ void *uip_appdata; /* The uip_appdata pointer points to application data. */ void *uip_sappdata; /* The uip_appdata pointer points to the application @@ -198,18 +199,18 @@ struct uip_stats uip_stat; ****************************************************************************/ static const uip_ipaddr_t all_ones_addr = -#ifdef CONFIG_NET_UIP_IPv6 +#ifdef CONFIG_NET_IPv6 {0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff,0xffff}; -#else /* CONFIG_NET_UIP_IPv6 */ +#else /* CONFIG_NET_IPv6 */ {0xffff,0xffff}; -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ static const uip_ipaddr_t all_zeroes_addr = -#ifdef CONFIG_NET_UIP_IPv6 +#ifdef CONFIG_NET_IPv6 {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000}; -#else /* CONFIG_NET_UIP_IPv6 */ +#else /* CONFIG_NET_IPv6 */ {0x0000,0x0000}; -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ #if UIP_FIXEDETHADDR const struct uip_eth_addr uip_ethaddr = @@ -224,10 +225,8 @@ static uint16 ipid; /* Ths ipid variable is an increasing number th static uint8 iss[4]; /* The iss variable is used for the TCP initial * sequence number. */ -#if UIP_ACTIVE_OPEN static uint16 lastport; /* Keeps track of the last port used for a new * connection. */ -#endif /* UIP_ACTIVE_OPEN */ /* Temporary variables. */ static uint8 c, opt; @@ -245,22 +244,27 @@ static void uip_add32(uint8 *op32, uint16 op16) uip_acc32[1] = op32[1]; uip_acc32[0] = op32[0]; - if (uip_acc32[2] < (op16 >> 8)) { - ++uip_acc32[1]; - if (uip_acc32[1] == 0) { - ++uip_acc32[0]; + if (uip_acc32[2] < (op16 >> 8)) + { + ++uip_acc32[1]; + if (uip_acc32[1] == 0) + { + ++uip_acc32[0]; + } } - } - if (uip_acc32[3] < (op16 & 0xff)) { - ++uip_acc32[2]; - if (uip_acc32[2] == 0) { - ++uip_acc32[1]; - if (uip_acc32[1] == 0) { - ++uip_acc32[0]; - } + if (uip_acc32[3] < (op16 & 0xff)) + { + ++uip_acc32[2]; + if (uip_acc32[2] == 0) + { + ++uip_acc32[1]; + if (uip_acc32[1] == 0) + { + ++uip_acc32[0]; + } + } } - } } #endif /* UIP_ARCH_ADD32 */ @@ -274,25 +278,31 @@ static uint16 chksum(uint16 sum, const uint8 *data, uint16 len) dataptr = data; last_byte = data + len - 1; - while(dataptr < last_byte) { - /* At least two more bytes */ - t = (dataptr[0] << 8) + dataptr[1]; - sum += t; - if (sum < t) { - sum++; /* carry */ + while(dataptr < last_byte) + { + /* At least two more bytes */ + + t = (dataptr[0] << 8) + dataptr[1]; + sum += t; + if (sum < t) + { + sum++; /* carry */ + } + dataptr += 2; } - dataptr += 2; - } - if (dataptr == last_byte) { - t = (dataptr[0] << 8) + 0; - sum += t; - if (sum < t) { - sum++; /* carry */ + if (dataptr == last_byte) + { + t = (dataptr[0] << 8) + 0; + sum += t; + if (sum < t) + { + sum++; /* carry */ + } } - } /* Return sum in host byte order. */ + return sum; } @@ -301,11 +311,11 @@ static uint16 upper_layer_chksum(uint8 proto) uint16 upper_layer_len; uint16 sum; -#ifdef CONFIG_NET_UIP_IPv6 +#ifdef CONFIG_NET_IPv6 upper_layer_len = (((uint16)(BUF->len[0]) << 8) + BUF->len[1]); -#else /* CONFIG_NET_UIP_IPv6 */ +#else /* CONFIG_NET_IPv6 */ upper_layer_len = (((uint16)(BUF->len[0]) << 8) + BUF->len[1]) - UIP_IPH_LEN; -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ /* First sum pseudoheader. */ @@ -321,15 +331,60 @@ static uint16 upper_layer_chksum(uint8 proto) return (sum == 0) ? 0xffff : htons(sum); } -#ifdef CONFIG_NET_UIP_IPv6 +#ifdef CONFIG_NET_IPv6 static uint16 uip_icmp6chksum(void) { return upper_layer_chksum(UIP_PROTO_ICMP6); } -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ #endif /* UIP_ARCH_CHKSUM */ +/* Given a port number, find the socket bound to the port number. + * Primary use: to determine if a port number is available. + */ + +struct uip_conn *uip_find_conn( uint16 portno ) +{ + struct uip_conn *conn; + int i; + + /* Check if this port number is already in use, and if so try to find + * another one. + */ + + for (i = 0; i < UIP_CONNS; i++) + { + conn = &uip_conns[i]; + if (conn->tcpstateflags != UIP_CLOSED && conn->lport == htons(lastport)) + { + /* The portnumber is in use */ + + return conn; + } + } + + return NULL; +} + +#if UIP_UDP +struct uip_udp_conn *uip_find_udp_conn( uint16 portno ) +{ + struct uip_udp_conn *conn; + int i; + + for (i = 0; i < UIP_UDP_CONNS; i++) + { + if (uip_udp_conns[i].lport == htons(lastport)) + { + return conn; + } + } + + return NULL; +} +#endif /* UIP_UDP */ + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -381,69 +436,84 @@ uint16 uip_udpchksum(void) void uip_init(void) { - for(c = 0; c < UIP_LISTENPORTS; ++c) { - uip_listenports[c] = 0; - } - for(c = 0; c < UIP_CONNS; ++c) { - uip_conns[c].tcpstateflags = UIP_CLOSED; - } -#if UIP_ACTIVE_OPEN + for (c = 0; c < UIP_LISTENPORTS; ++c) + { + uip_listenports[c] = 0; + } + + for (c = 0; c < UIP_CONNS; ++c) + { + uip_conns[c].tcpstateflags = UIP_CLOSED; + } lastport = 1024; -#endif /* UIP_ACTIVE_OPEN */ #if UIP_UDP - for(c = 0; c < UIP_UDP_CONNS; ++c) { - uip_udp_conns[c].lport = 0; - } + for (c = 0; c < UIP_UDP_CONNS; ++c) + { + uip_udp_conns[c].lport = 0; + } #endif /* UIP_UDP */ /* IPv4 initialization. */ #if UIP_FIXEDADDR == 0 /* uip_hostaddr[0] = uip_hostaddr[1] = 0;*/ #endif /* UIP_FIXEDADDR */ - } -#if UIP_ACTIVE_OPEN struct uip_conn *uip_connect(uip_ipaddr_t *ripaddr, uint16 rport) { - register struct uip_conn *conn, *cconn; + struct uip_conn *conn, *cconn; + int i; - /* Find an unused local port. */ - again: - ++lastport; + /* Find an unused local port number. Loop until we find a valid listen port + * number that is not being used by any other connection. + */ - if (lastport >= 32000) { - lastport = 4096; - } + do + { + /* Guess that the next available port number will be the one after + * the last port number assigned. + */ + + ++lastport; - /* Check if this port is already in use, and if so try to find - another one. */ - for(c = 0; c < UIP_CONNS; ++c) { - conn = &uip_conns[c]; - if (conn->tcpstateflags != UIP_CLOSED && - conn->lport == htons(lastport)) { - goto again; + /* Make sure that the port number is within range */ + if (lastport >= 32000) + { + lastport = 4096; + } } - } + while (uip_find_conn(lastport)); + + /* Now find an available connection structure */ conn = 0; - for(c = 0; c < UIP_CONNS; ++c) { - cconn = &uip_conns[c]; - if (cconn->tcpstateflags == UIP_CLOSED) { - conn = cconn; - break; + for (i = 0; i < UIP_CONNS; i++) + { + cconn = &uip_conns[i]; + if (cconn->tcpstateflags == UIP_CLOSED) + { + conn = cconn; + break; + } + + if (cconn->tcpstateflags == UIP_TIME_WAIT) + { + if (conn == 0 || cconn->timer > conn->timer) + { + conn = cconn; + } + } } - if (cconn->tcpstateflags == UIP_TIME_WAIT) { - if (conn == 0 || cconn->timer > conn->timer) { - conn = cconn; - } + + /* Return an error if no connection is available */ + + if (conn == 0) + { + return 0; } - } - if (conn == 0) { - return 0; - } + /* Initialize and return the connection structure, bind it to the port number */ conn->tcpstateflags = UIP_SYN_SENT; @@ -454,60 +524,78 @@ struct uip_conn *uip_connect(uip_ipaddr_t *ripaddr, uint16 rport) conn->initialmss = conn->mss = UIP_TCP_MSS; - conn->len = 1; /* TCP length of the SYN is one. */ - conn->nrtx = 0; - conn->timer = 1; /* Send the SYN next time around. */ - conn->rto = UIP_RTO; - conn->sa = 0; - conn->sv = 16; /* Initial value of the RTT variance. */ + conn->len = 1; /* TCP length of the SYN is one. */ + conn->nrtx = 0; + conn->timer = 1; /* Send the SYN next time around. */ + conn->rto = UIP_RTO; + conn->sa = 0; + conn->sv = 16; /* Initial value of the RTT variance. */ conn->lport = htons(lastport); conn->rport = rport; uip_ipaddr_copy(&conn->ripaddr, ripaddr); return conn; } -#endif /* UIP_ACTIVE_OPEN */ #if UIP_UDP -struct uip_udp_conn * -uip_udp_new(uip_ipaddr_t *ripaddr, uint16 rport) +struct uip_udp_conn *uip_udp_new(uip_ipaddr_t *ripaddr, uint16 rport) { - register struct uip_udp_conn *conn; + struct uip_udp_conn *conn; + int i; - /* Find an unused local port. */ - again: - ++lastport; + /* Find an unused local port number. Loop until we find a valid listen port + * number that is not being used by any other connection. + */ - if (lastport >= 32000) { - lastport = 4096; - } + do + { + /* Guess that the next available port number will be the one after + * the last port number assigned. + */ - for(c = 0; c < UIP_UDP_CONNS; ++c) { - if (uip_udp_conns[c].lport == htons(lastport)) { - goto again; + ++lastport; + + /* Make sure that the port number is within range */ + if (lastport >= 32000) + { + lastport = 4096; + } } - } + while (uip_find_udp_conn(lastport)); + /* Now find an available UDP connection structure */ conn = 0; - for(c = 0; c < UIP_UDP_CONNS; ++c) { - if (uip_udp_conns[c].lport == 0) { - conn = &uip_udp_conns[c]; - break; + for (i = 0; i < UIP_UDP_CONNS; i++) + { + if (uip_udp_conns[c].lport == 0) + { + conn = &uip_udp_conns[c]; + break; + } } - } - if (conn == 0) { - return 0; - } + /* Return an error if no connection is available */ + + if (conn == 0) + { + return 0; + } + + /* Initialize and return the connection structure, bind it to the port number */ conn->lport = HTONS(lastport); conn->rport = rport; - if (ripaddr == NULL) { - memset(conn->ripaddr, 0, sizeof(uip_ipaddr_t)); - } else { - uip_ipaddr_copy(&conn->ripaddr, ripaddr); - } + + if (ripaddr == NULL) + { + memset(conn->ripaddr, 0, sizeof(uip_ipaddr_t)); + } + else + { + uip_ipaddr_copy(&conn->ripaddr, ripaddr); + } + conn->ttl = UIP_TTL; return conn; @@ -516,17 +604,19 @@ uip_udp_new(uip_ipaddr_t *ripaddr, uint16 rport) void uip_unlisten(uint16 port) { - for(c = 0; c < UIP_LISTENPORTS; ++c) { - if (uip_listenports[c] == port) { - uip_listenports[c] = 0; - return; + for (c = 0; c < UIP_LISTENPORTS; ++c) + { + if (uip_listenports[c] == port) + { + uip_listenports[c] = 0; + return; + } } - } } void uip_listen(uint16 port) { - for(c = 0; c < UIP_LISTENPORTS; ++c) { + for (c = 0; c < UIP_LISTENPORTS; ++c) { if (uip_listenports[c] == 0) { uip_listenports[c] = port; return; @@ -536,7 +626,7 @@ void uip_listen(uint16 port) /* XXX: IP fragment reassembly: not well-tested. */ -#if UIP_REASSEMBLY && !defined(CONFIG_NET_UIP_IPv6) +#if UIP_REASSEMBLY && !defined(CONFIG_NET_IPv6) #define UIP_REASS_BUFSIZE (UIP_BUFSIZE - UIP_LLH_LEN) static uint8 uip_reassbuf[UIP_REASS_BUFSIZE]; static uint8 uip_reassbitmap[UIP_REASS_BUFSIZE / (8 * 8)]; @@ -605,7 +695,7 @@ static uint8 uip_reass(void) 0xff. */ uip_reassbitmap[offset / (8 * 8)] |= bitmap_bits[(offset / 8 ) & 7]; - for(i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) { + for (i = 1 + offset / (8 * 8); i < (offset + len) / (8 * 8); ++i) { uip_reassbitmap[i] = 0xff; } uip_reassbitmap[(offset + len) / (8 * 8)] |= @@ -629,7 +719,7 @@ static uint8 uip_reass(void) if (uip_reassflags & UIP_REASS_FLAG_LASTFRAG) { /* Check all bytes up to and including all but the last byte in the bitmap. */ - for(i = 0; i < uip_reasslen / (8 * 8) - 1; ++i) { + for (i = 0; i < uip_reasslen / (8 * 8) - 1; ++i) { if (uip_reassbitmap[i] != 0xff) { goto nullreturn; } @@ -804,12 +894,10 @@ void uip_interrupt(uint8 flag) goto tcp_send_synack; -#if UIP_ACTIVE_OPEN case UIP_SYN_SENT: /* In the SYN_SENT state, we retransmit out SYN. */ BUF->flags = 0; goto tcp_send_syn; -#endif /* UIP_ACTIVE_OPEN */ case UIP_ESTABLISHED: /* In the ESTABLISHED state, we call upon the application @@ -872,7 +960,7 @@ void uip_interrupt(uint8 flag) /* Start of IP input header processing code. */ -#ifdef CONFIG_NET_UIP_IPv6 +#ifdef CONFIG_NET_IPv6 /* Check validity of the IP header. */ if ((BUF->vtc & 0xf0) != 0x60) { @@ -882,7 +970,7 @@ void uip_interrupt(uint8 flag) UIP_LOG("ipv6: invalid version."); goto drop; } -#else /* CONFIG_NET_UIP_IPv6 */ +#else /* CONFIG_NET_IPv6 */ /* Check validity of the IP header. */ if (BUF->vhl != 0x45) { @@ -892,7 +980,7 @@ void uip_interrupt(uint8 flag) UIP_LOG("ip: invalid version or header length."); goto drop; } -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ /* Check the size of the packet. If the size reported to us in uip_len is smaller the size reported in the IP header, we assume @@ -904,7 +992,7 @@ void uip_interrupt(uint8 flag) if ((BUF->len[0] << 8) + BUF->len[1] <= uip_len) { uip_len = (BUF->len[0] << 8) + BUF->len[1]; -#ifdef CONFIG_NET_UIP_IPv6 +#ifdef CONFIG_NET_IPv6 uip_len += 40; /* The length reported in the IPv6 header is the length of the payload that follows the header. However, uIP uses the uip_len variable @@ -914,7 +1002,7 @@ void uip_interrupt(uint8 flag) contains the length of the entire packet. But for IPv6 we need to add the size of the IPv6 header (40 bytes). */ -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ } else { @@ -922,7 +1010,7 @@ void uip_interrupt(uint8 flag) goto drop; } -#ifndef CONFIG_NET_UIP_IPv6 +#ifndef CONFIG_NET_IPv6 /* Check the fragment flag. */ if ((BUF->ipoffset[0] & 0x3f) != 0 || @@ -941,14 +1029,14 @@ void uip_interrupt(uint8 flag) goto drop; #endif /* UIP_REASSEMBLY */ } -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ if (uip_ipaddr_cmp(uip_hostaddr, all_zeroes_addr)) { /* If we are configured to use ping IP address configuration and hasn't been assigned an IP address yet, we accept all ICMP packets. */ -#if UIP_PINGADDRCONF && !CONFIG_NET_UIP_IPv6 +#if UIP_PINGADDRCONF && !CONFIG_NET_IPv6 if (BUF->proto == UIP_PROTO_ICMP) { UIP_LOG("ip: possible ping config packet received."); @@ -977,13 +1065,13 @@ void uip_interrupt(uint8 flag) #endif /* UIP_BROADCAST */ /* Check if the packet is destined for our IP address. */ -#ifndef CONFIG_NET_UIP_IPv6 +#ifndef CONFIG_NET_IPv6 if (!uip_ipaddr_cmp(BUF->destipaddr, uip_hostaddr)) { UIP_STAT(++uip_stat.ip.drop); goto drop; } -#else /* CONFIG_NET_UIP_IPv6 */ +#else /* CONFIG_NET_IPv6 */ /* For IPv6, packet reception is a little trickier as we need to make sure that we listen to certain multicast addresses (all hosts multicast address, and the solicited-node multicast @@ -995,10 +1083,10 @@ void uip_interrupt(uint8 flag) UIP_STAT(++uip_stat.ip.drop); goto drop; } -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ } -#ifndef CONFIG_NET_UIP_IPv6 +#ifndef CONFIG_NET_IPv6 if (uip_ipchksum() != 0xffff) { /* Compute and check the IP header checksum. */ @@ -1008,7 +1096,7 @@ void uip_interrupt(uint8 flag) UIP_LOG("ip: bad checksum."); goto drop; } -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ if (BUF->proto == UIP_PROTO_TCP) { @@ -1024,7 +1112,7 @@ void uip_interrupt(uint8 flag) } #endif /* UIP_UDP */ -#ifndef CONFIG_NET_UIP_IPv6 +#ifndef CONFIG_NET_IPv6 /* ICMPv4 processing code follows. */ if (BUF->proto != UIP_PROTO_ICMP) { @@ -1083,7 +1171,7 @@ void uip_interrupt(uint8 flag) goto send; /* End of IPv4 input header processing code. */ -#else /* !CONFIG_NET_UIP_IPv6 */ +#else /* !CONFIG_NET_IPv6 */ /* This is IPv6 ICMPv6 processing code. */ dbg("icmp6_input: length %d\n", uip_len); @@ -1157,7 +1245,7 @@ void uip_interrupt(uint8 flag) /* End of IPv6 ICMP processing. */ -#endif /* !CONFIG_NET_UIP_IPv6 */ +#endif /* !CONFIG_NET_IPv6 */ #if UIP_UDP /* UDP input processing. */ @@ -1186,12 +1274,14 @@ void uip_interrupt(uint8 flag) ++uip_udp_conn) { /* If the local UDP port is non-zero, the connection is considered - to be used. If so, the local port number is checked against the - destination port number in the received packet. If the two port - numbers match, the remote port number is checked if the - connection is bound to a remote port. Finally, if the - connection is bound to a remote IP address, the source IP - address of the packet is checked. */ + * to be used. If so, the local port number is checked against the + * destination port number in the received packet. If the two port + * numbers match, the remote port number is checked if the + * connection is bound to a remote port. Finally, if the + * connection is bound to a remote IP address, the source IP + * address of the packet is checked. + */ + if (uip_udp_conn->lport != 0 && UDPBUF->destport == uip_udp_conn->lport && (uip_udp_conn->rport == 0 || @@ -1203,6 +1293,7 @@ void uip_interrupt(uint8 flag) goto udp_found; } } + UIP_LOG("udp: no matching connection found"); goto drop; @@ -1221,15 +1312,15 @@ void uip_interrupt(uint8 flag) } uip_len = uip_slen + UIP_IPUDPH_LEN; -#ifdef CONFIG_NET_UIP_IPv6 +#ifdef CONFIG_NET_IPv6 /* For IPv6, the IP length field does not include the IPv6 IP header length. */ BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8); BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff); -#else /* CONFIG_NET_UIP_IPv6 */ +#else /* CONFIG_NET_IPv6 */ BUF->len[0] = (uip_len >> 8); BUF->len[1] = (uip_len & 0xff); -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ BUF->ttl = uip_udp_conn->ttl; BUF->proto = UIP_PROTO_UDP; @@ -1298,7 +1389,7 @@ void uip_interrupt(uint8 flag) tmp16 = BUF->destport; /* Next, check listening connections. */ - for(c = 0; c < UIP_LISTENPORTS; ++c) + for (c = 0; c < UIP_LISTENPORTS; ++c) { if (tmp16 == uip_listenports[c]) goto found_listen; @@ -1374,7 +1465,7 @@ void uip_interrupt(uint8 flag) CLOSED connections are found. Thanks to Eddie C. Dost for a very nice algorithm for the TIME_WAIT search. */ uip_connr = 0; - for(c = 0; c < UIP_CONNS; ++c) + for (c = 0; c < UIP_CONNS; ++c) { if (uip_conns[c].tcpstateflags == UIP_CLOSED) { @@ -1427,7 +1518,7 @@ void uip_interrupt(uint8 flag) /* Parse the TCP MSS option, if present. */ if ((BUF->tcpoffset & 0xf0) > 0x50) { - for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) + for (c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) { opt = uip_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + c]; if (opt == TCP_OPT_END) @@ -1468,16 +1559,11 @@ void uip_interrupt(uint8 flag) } /* Our response will be a SYNACK. */ -#if UIP_ACTIVE_OPEN tcp_send_synack: BUF->flags = TCP_ACK; tcp_send_syn: BUF->flags |= TCP_SYN; -#else /* UIP_ACTIVE_OPEN */ - tcp_send_synack: - BUF->flags = TCP_SYN | TCP_ACK; -#endif /* UIP_ACTIVE_OPEN */ /* We send out the TCP Maximum Segment Size option with our SYNACK. */ @@ -1620,7 +1706,6 @@ void uip_interrupt(uint8 flag) } goto drop; -#if UIP_ACTIVE_OPEN case UIP_SYN_SENT: /* In SYN_SENT, we wait for a SYNACK that is sent in response to our SYN. The rcv_nxt is set to sequence number in the SYNACK @@ -1632,7 +1717,7 @@ void uip_interrupt(uint8 flag) /* Parse the TCP MSS option, if present. */ if ((BUF->tcpoffset & 0xf0) > 0x50) { - for(c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) + for (c = 0; c < ((BUF->tcpoffset >> 4) - 5) << 2 ;) { opt = uip_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + c]; if (opt == TCP_OPT_END) @@ -1694,7 +1779,6 @@ void uip_interrupt(uint8 flag) /* The connection is closed after we send the RST */ uip_conn->tcpstateflags = UIP_CLOSED; goto reset; -#endif /* UIP_ACTIVE_OPEN */ case UIP_ESTABLISHED: /* In the ESTABLISHED state, we call upon the application to feed @@ -2019,15 +2103,15 @@ void uip_interrupt(uint8 flag) tcp_send_noconn: BUF->ttl = UIP_TTL; -#ifdef CONFIG_NET_UIP_IPv6 +#ifdef CONFIG_NET_IPv6 /* For IPv6, the IP length field does not include the IPv6 IP header length. */ BUF->len[0] = ((uip_len - UIP_IPH_LEN) >> 8); BUF->len[1] = ((uip_len - UIP_IPH_LEN) & 0xff); -#else /* CONFIG_NET_UIP_IPv6 */ +#else /* CONFIG_NET_IPv6 */ BUF->len[0] = (uip_len >> 8); BUF->len[1] = (uip_len & 0xff); -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ BUF->urgp[0] = BUF->urgp[1] = 0; @@ -2039,11 +2123,11 @@ void uip_interrupt(uint8 flag) ip_send_nolen: #endif /* UIP_UDP */ -#ifdef CONFIG_NET_UIP_IPv6 +#ifdef CONFIG_NET_IPv6 BUF->vtc = 0x60; BUF->tcflow = 0x00; BUF->flow = 0x00; -#else /* CONFIG_NET_UIP_IPv6 */ +#else /* CONFIG_NET_IPv6 */ BUF->vhl = 0x45; BUF->tos = 0; BUF->ipoffset[0] = BUF->ipoffset[1] = 0; @@ -2055,7 +2139,7 @@ void uip_interrupt(uint8 flag) BUF->ipchksum = 0; BUF->ipchksum = ~(uip_ipchksum()); dbg("uip ip_send_nolen: chkecum 0x%04x\n", uip_ipchksum()); -#endif /* CONFIG_NET_UIP_IPv6 */ +#endif /* CONFIG_NET_IPv6 */ UIP_STAT(++uip_stat.tcp.sent); send: diff --git a/nuttx/netutils/Makefile b/nuttx/netutils/Makefile index 0534f59d1..acb62dcd6 100644 --- a/nuttx/netutils/Makefile +++ b/nuttx/netutils/Makefile @@ -37,7 +37,7 @@ MKDEP = $(TOPDIR)/tools/mkdeps.sh -ifeq ($(CONFIG_NET_UIP),y) +ifeq ($(CONFIG_NET),y) include uiplib/Make.defs include dhcpc/Make.defs include resolv/Make.defs @@ -77,7 +77,7 @@ $(BIN): $(OBJS) done ; ) .depend: Makefile $(SRCS) -ifeq ($(CONFIG_NET_UIP),y) +ifeq ($(CONFIG_NET),y) $(MKDEP) --dep-path uiplib --dep-path dhcpc --dep-path smtp --dep-path webclient \ --dep-path resolv --dep-path telnetd --dep-path webserver \ $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep diff --git a/nuttx/netutils/dhcpc/Make.defs b/nuttx/netutils/dhcpc/Make.defs index b4aa9acbf..a275a9fbb 100644 --- a/nuttx/netutils/dhcpc/Make.defs +++ b/nuttx/netutils/dhcpc/Make.defs @@ -33,7 +33,7 @@ # ############################################################################ -ifeq ($(CONFIG_UIP_UDP),y) +ifeq ($(CONFIG_NET_UDP),y) DHCPC_ASRCS = DHCPC_CSRCS = dhcpc.c endif \ No newline at end of file diff --git a/nuttx/netutils/dhcpc/dhcpc.c b/nuttx/netutils/dhcpc/dhcpc.c index 096649b68..1fc64cf1b 100644 --- a/nuttx/netutils/dhcpc/dhcpc.c +++ b/nuttx/netutils/dhcpc/dhcpc.c @@ -1,4 +1,4 @@ -/************************************************************ +/**************************************************************************** * dhcpc.c * * Copyright (C) 2007 Gregory Nutt. All rights reserved. @@ -9,55 +9,56 @@ * Copyright (c) 2005, Swedish Institute of Computer Science * All rights reserved. * + * Copyright (c) 2005, 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 NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software + * 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 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. + * 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. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include -#include +#include #include #include +#include #include #include #include +#include -#include "dhcpc.h" - -/************************************************************ +/**************************************************************************** * Definitions - ************************************************************/ + ****************************************************************************/ /* CLK_TCK is the frequency of the system clock (typically 100Hz) */ + #define CLOCK_SECOND CLK_TCK #define STATE_INITIAL 0 @@ -94,9 +95,20 @@ #define DHCP_OPTION_REQ_LIST 55 #define DHCP_OPTION_END 255 -/************************************************************ +/**************************************************************************** * Private Types - ************************************************************/ + ****************************************************************************/ + +struct dhcpc_state_internal +{ + char state; + sem_t sem; + struct uip_udp_conn *conn; + uint16 ticks; + const void *mac_addr; + int mac_len; + struct dhcpc_state *result; +}; struct dhcp_msg { @@ -108,25 +120,24 @@ struct dhcp_msg uint8 siaddr[4]; uint8 giaddr[4]; uint8 chaddr[16]; -#ifndef CONFIG_UIP_DHCP_LIGHT +#ifndef CONFIG_NET_DHCP_LIGHT uint8 sname[64]; uint8 file[128]; #endif uint8 options[312]; }; -/************************************************************ +/**************************************************************************** * Private Data - ************************************************************/ - -static struct dhcpc_state s; + ****************************************************************************/ static const uint8 xid[4] = {0xad, 0xde, 0x12, 0x23}; static const uint8 magic_cookie[4] = {99, 130, 83, 99}; +static volatile struct dhcpc_state_internal *gpdhcpc; -/************************************************************ +/**************************************************************************** * Private Functions - ************************************************************/ + ****************************************************************************/ static uint8 *add_msg_type(uint8 *optptr, uint8 type) { @@ -136,19 +147,19 @@ static uint8 *add_msg_type(uint8 *optptr, uint8 type) return optptr; } -static uint8 *add_server_id(uint8 *optptr) +static uint8 *add_server_id(struct dhcpc_state *presult, uint8 *optptr) { *optptr++ = DHCP_OPTION_SERVER_ID; *optptr++ = 4; - memcpy(optptr, s.serverid, 4); + memcpy(optptr, presult->serverid, 4); return optptr + 4; } -static uint8 *add_req_ipaddr(uint8 *optptr) +static uint8 *add_req_ipaddr(struct dhcpc_state *presult, uint8 *optptr) { *optptr++ = DHCP_OPTION_REQ_IPADDR; *optptr++ = 4; - memcpy(optptr, s.ipaddr, 4); + memcpy(optptr, presult->ipaddr, 4); return optptr + 4; } @@ -168,11 +179,11 @@ static uint8 *add_end(uint8 *optptr) return optptr; } -static void create_msg(register struct dhcp_msg *m) +static void create_msg(struct dhcpc_state_internal *pdhcpc, struct dhcp_msg *m) { m->op = DHCP_REQUEST; m->htype = DHCP_HTYPE_ETHERNET; - m->hlen = s.mac_len; + m->hlen = pdhcpc->mac_len; m->hops = 0; memcpy(m->xid, xid, sizeof(m->xid)); m->secs = 0; @@ -182,9 +193,9 @@ static void create_msg(register struct dhcp_msg *m) memset(m->yiaddr, 0, sizeof(m->yiaddr)); memset(m->siaddr, 0, sizeof(m->siaddr)); memset(m->giaddr, 0, sizeof(m->giaddr)); - memcpy(m->chaddr, s.mac_addr, s.mac_len); - memset(&m->chaddr[s.mac_len], 0, sizeof(m->chaddr) - s.mac_len); -#ifndef CONFIG_UIP_DHCP_LIGHT + memcpy(m->chaddr, pdhcpc->mac_addr, pdhcpc->mac_len); + memset(&m->chaddr[pdhcpc->mac_len], 0, sizeof(m->chaddr) - pdhcpc->mac_len); +#ifndef CONFIG_NET_DHCP_LIGHT memset(m->sname, 0, sizeof(m->sname)); memset(m->file, 0, sizeof(m->file)); #endif @@ -192,12 +203,12 @@ static void create_msg(register struct dhcp_msg *m) memcpy(m->options, magic_cookie, sizeof(magic_cookie)); } -static void send_discover(void) +static void send_discover(struct dhcpc_state_internal *pdhcpc) { uint8 *end; struct dhcp_msg *m = (struct dhcp_msg *)uip_appdata; - create_msg(m); + create_msg(pdhcpc, m); end = add_msg_type(&m->options[4], DHCPDISCOVER); end = add_req_options(end); @@ -206,22 +217,22 @@ static void send_discover(void) uip_send(uip_appdata, end - (uint8 *)uip_appdata); } -static void send_request(void) +static void send_request(struct dhcpc_state_internal *pdhcpc) { uint8 *end; struct dhcp_msg *m = (struct dhcp_msg *)uip_appdata; - create_msg(m); + create_msg(pdhcpc, m); end = add_msg_type(&m->options[4], DHCPREQUEST); - end = add_server_id(end); - end = add_req_ipaddr(end); + end = add_server_id(pdhcpc->result, end); + end = add_req_ipaddr(pdhcpc->result, end); end = add_end(end); uip_send(uip_appdata, end - (uint8 *)uip_appdata); } -static uint8 parse_options(uint8 *optptr, int len) +static uint8 parse_options(struct dhcpc_state *presult, uint8 *optptr, int len) { uint8 *end = optptr + len; uint8 type = 0; @@ -231,22 +242,22 @@ static uint8 parse_options(uint8 *optptr, int len) switch(*optptr) { case DHCP_OPTION_SUBNET_MASK: - memcpy(s.netmask, optptr + 2, 4); + memcpy(presult->netmask, optptr + 2, 4); break; case DHCP_OPTION_ROUTER: - memcpy(s.default_router, optptr + 2, 4); + memcpy(presult->default_router, optptr + 2, 4); break; case DHCP_OPTION_DNS_SERVER: - memcpy(s.dnsaddr, optptr + 2, 4); + memcpy(presult->dnsaddr, optptr + 2, 4); break; case DHCP_OPTION_MSG_TYPE: type = *(optptr + 2); break; case DHCP_OPTION_SERVER_ID: - memcpy(s.serverid, optptr + 2, 4); + memcpy(presult->serverid, optptr + 2, 4); break; case DHCP_OPTION_LEASE_TIME: - memcpy(s.lease_time, optptr + 2, 4); + memcpy(presult->lease_time, optptr + 2, 4); break; case DHCP_OPTION_END: return type; @@ -257,115 +268,131 @@ static uint8 parse_options(uint8 *optptr, int len) return type; } -static uint8 parse_msg(void) +static uint8 parse_msg(struct dhcpc_state_internal *pdhcpc) { + struct dhcpc_state *presult = pdhcpc->result; struct dhcp_msg *m = (struct dhcp_msg *)uip_appdata; if (m->op == DHCP_REPLY && - memcmp(m->xid, xid, sizeof(xid)) == 0 && - memcmp(m->chaddr, s.mac_addr, s.mac_len) == 0) + memcmp(m->xid, xid, sizeof(xid)) == 0 && + memcmp(m->chaddr, pdhcpc->mac_addr, pdhcpc->mac_len) == 0) { - memcpy(s.ipaddr, m->yiaddr, 4); - return parse_options(&m->options[4], uip_datalen()); + memcpy(presult->ipaddr, m->yiaddr, 4); + return parse_options(presult, &m->options[4], uip_datalen()); } return 0; } -static void handle_dhcp(void) +static void handle_dhcp(struct dhcpc_state_internal *pdhcpc) { + struct dhcpc_state *presult = pdhcpc->result; + restart: - s.state = STATE_SENDING; - s.ticks = CLOCK_SECOND; + pdhcpc->state = STATE_SENDING; + pdhcpc->ticks = CLOCK_SECOND; do { /* Send the command */ - send_discover(); + send_discover(pdhcpc); /* Wait for the response */ uip_event_timedwait(UIP_NEWDATA, CLOCK_SECOND); - if (uip_newdata() && parse_msg() == DHCPOFFER) + if (uip_newdata() && parse_msg(pdhcpc) == DHCPOFFER) { - s.state = STATE_OFFER_RECEIVED; + pdhcpc->state = STATE_OFFER_RECEIVED; break; } - if (s.ticks < CLOCK_SECOND * 60) + if (pdhcpc->ticks < CLOCK_SECOND * 60) { - s.ticks *= 2; + pdhcpc->ticks *= 2; } } - while(s.state != STATE_OFFER_RECEIVED); + while(pdhcpc->state != STATE_OFFER_RECEIVED); - s.ticks = CLOCK_SECOND; + pdhcpc->ticks = CLOCK_SECOND; do { /* Send the request */ - send_request(); + send_request(pdhcpc); /* Then wait to received the response */ uip_event_timedwait(UIP_NEWDATA, CLOCK_SECOND); - if (uip_newdata() && parse_msg() == DHCPACK) + if (uip_newdata() && parse_msg(pdhcpc) == DHCPACK) { - s.state = STATE_CONFIG_RECEIVED; + pdhcpc->state = STATE_CONFIG_RECEIVED; break; } - if (s.ticks <= CLOCK_SECOND * 10) + if (pdhcpc->ticks <= CLOCK_SECOND * 10) { - s.ticks += CLOCK_SECOND; + pdhcpc->ticks += CLOCK_SECOND; } else { goto restart; } } - while(s.state != STATE_CONFIG_RECEIVED); + while(pdhcpc->state != STATE_CONFIG_RECEIVED); dbg("Got IP address %d.%d.%d.%d\n", - uip_ipaddr1(s.ipaddr), uip_ipaddr2(s.ipaddr), - uip_ipaddr3(s.ipaddr), uip_ipaddr4(s.ipaddr)); + uip_ipaddr1(presult->ipaddr), uip_ipaddr2(presult->ipaddr), + uip_ipaddr3(presult->ipaddr), uip_ipaddr4(presult->ipaddr)); dbg("Got netmask %d.%d.%d.%d\n", - uip_ipaddr1(s.netmask), uip_ipaddr2(s.netmask), - uip_ipaddr3(s.netmask), uip_ipaddr4(s.netmask)); + uip_ipaddr1(presult->netmask), uip_ipaddr2(presult->netmask), + uip_ipaddr3(presult->netmask), uip_ipaddr4(presult->netmask)); dbg("Got DNS server %d.%d.%d.%d\n", - uip_ipaddr1(s.dnsaddr), uip_ipaddr2(s.dnsaddr), - uip_ipaddr3(s.dnsaddr), uip_ipaddr4(s.dnsaddr)); + uip_ipaddr1(presult->dnsaddr), uip_ipaddr2(presult->dnsaddr), + uip_ipaddr3(presult->dnsaddr), uip_ipaddr4(presult->dnsaddr)); dbg("Got default router %d.%d.%d.%d\n", - uip_ipaddr1(s.default_router), uip_ipaddr2(s.default_router), - uip_ipaddr3(s.default_router), uip_ipaddr4(s.default_router)); + uip_ipaddr1(presult->default_router), uip_ipaddr2(presult->default_router), + uip_ipaddr3(presult->default_router), uip_ipaddr4(presult->default_router)); dbg("Lease expires in %ld seconds\n", - ntohs(s.lease_time[0])*65536ul + ntohs(s.lease_time[1])); - - dhcpc_configured(&s); - - pthread_exit(NULL); + ntohs(presult->lease_time[0])*65536ul + ntohs(presult->lease_time[1])); } -/************************************************************ +/**************************************************************************** * Global Functions - ************************************************************/ + ****************************************************************************/ -void dhcpc_init(const void *mac_addr, int mac_len) +void *dhcpc_open(const void *mac_addr, int mac_len) { uip_ipaddr_t addr; + struct dhcpc_state_internal *pdhcpc; - s.mac_addr = mac_addr; - s.mac_len = mac_len; + pdhcpc = (struct dhcpc_state_internal *)malloc(sizeof(struct dhcpc_state_internal)); + if (pdhcpc) + { + memset(pdhcpc, 0, sizeof(struct dhcpc_state_internal)); + pdhcpc->mac_addr = mac_addr; + pdhcpc->mac_len = mac_len; + pdhcpc->state = STATE_INITIAL; + sem_init(&pdhcpc->sem, 0, 0); + + uip_ipaddr(addr, 255,255,255,255); + pdhcpc->conn = uip_udp_new(&addr, HTONS(DHCPC_SERVER_PORT)); + if (pdhcpc->conn != NULL) + { + uip_udp_bind(pdhcpc->conn, HTONS(DHCPC_CLIENT_PORT)); + } + } + return (void*)pdhcpc; +} - s.state = STATE_INITIAL; - uip_ipaddr(addr, 255,255,255,255); - s.conn = uip_udp_new(&addr, HTONS(DHCPC_SERVER_PORT)); - if (s.conn != NULL) +void dhcpc_close(void *handle) +{ + struct dchcpc_state_internal *pdhcpc = (struct dchcpc_state_internal *)handle; + if (pdhcpc) { - uip_udp_bind(s.conn, HTONS(DHCPC_CLIENT_PORT)); + free(pdhcpc); } } @@ -375,16 +402,27 @@ void dhcpc_init(const void *mac_addr, int mac_len) void uip_interrupt_udp_event(void) { - handle_dhcp(); + if (gpdhcpc) + { + sem_post(&gpdhcpc->sem); + } } -void dhcpc_request(void) +int dhcpc_request(void *handle, struct dhcpc_state *ds) { + struct dhcpc_state_internal *pdhcpc = (struct dhcpc_state_internal *)handle; uint16 ipaddr[2]; - if (s.state == STATE_INITIAL) + if (pdhcpc->state == STATE_INITIAL) { uip_ipaddr(ipaddr, 0,0,0,0); uip_sethostaddr(ipaddr); } + + pdhcpc->result = ds; + gpdhcpc = pdhcpc; + sem_wait(&pdhcpc->sem); + gpdhcpc = NULL; + handle_dhcp(pdhcpc); + return OK; } diff --git a/nuttx/netutils/dhcpc/dhcpc.h b/nuttx/netutils/dhcpc/dhcpc.h deleted file mode 100644 index b46ae4dfd..000000000 --- a/nuttx/netutils/dhcpc/dhcpc.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2005, 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. - * - * This file is part of the uIP TCP/IP stack - * - * @(#)$Id: dhcpc.h,v 1.1.1.1 2007-08-26 23:07:02 patacongo Exp $ - */ -#ifndef __DHCPC_H__ -#define __DHCPC_H__ - -#include - -struct dhcpc_state { - char state; - struct uip_udp_conn *conn; - uint16 ticks; - const void *mac_addr; - int mac_len; - - uint8 serverid[4]; - - uint16 lease_time[2]; - uint16 ipaddr[2]; - uint16 netmask[2]; - uint16 dnsaddr[2]; - uint16 default_router[2]; -}; - -void dhcpc_init(const void *mac_addr, int mac_len); -void dhcpc_request(void); -void dhcpc_configured(const struct dhcpc_state *s); - -#endif /* __DHCPC_H__ */ diff --git a/nuttx/netutils/resolv/Make.defs b/nuttx/netutils/resolv/Make.defs index e83757d36..0ca95b94e 100644 --- a/nuttx/netutils/resolv/Make.defs +++ b/nuttx/netutils/resolv/Make.defs @@ -33,7 +33,7 @@ # ############################################################################ -ifeq ($(CONFIG_UIP_UDP),y) +ifeq ($(CONFIG_NET_UDP),y) RESOLV_ASRCS = RESOLV_CSRCS = resolv.c endif diff --git a/nuttx/netutils/resolv/resolv.c b/nuttx/netutils/resolv/resolv.c index 0a38faea8..14159e906 100644 --- a/nuttx/netutils/resolv/resolv.c +++ b/nuttx/netutils/resolv/resolv.c @@ -1,6 +1,5 @@ /* uip-resolv.c * DNS host name to IP address resolver. - * Author: Adam Dunkels * * The uIP DNS resolver functions are used to lookup a hostname and * map it to a numerical IP address. It maintains a list of resolved @@ -12,8 +11,14 @@ * the resolver code calls a callback function called resolv_found() * that must be implemented by the module that uses the resolver. * - * Copyright (c) 2002-2003, Adam Dunkels. - * All rights reserved. + * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Based heavily on portions of uIP: + * + * Author: Adam Dunkels + * Copyright (c) 2002-2003, Adam Dunkels. + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,11 +44,11 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * This file is part of the uIP TCP/IP stack. - * - * $Id: resolv.c,v 1.1.1.1 2007-08-26 23:07:05 patacongo Exp $ - * - */ + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ #include #include @@ -51,17 +56,24 @@ #include #include +/**************************************************************************** + * Definitions + ****************************************************************************/ + +#ifndef CONFIG_NET_RESOLV_ENTRIES +#define RESOLV_ENTRIES 4 +#else /* CONFIG_NET_RESOLV_ENTRIES */ +#define RESOLV_ENTRIES CONFIG_NET_RESOLV_ENTRIES +#endif /* CONFIG_NET_RESOLV_ENTRIES */ + #ifndef NULL #define NULL (void *)0 #endif /* NULL */ -/** \internal The maximum number of retries when asking for a name. */ +/* The maximum number of retries when asking for a name */ + #define MAX_RETRIES 8 -/** \internal The DNS message header. */ -struct dns_hdr { - uint16 id; - uint8 flags1, flags2; #define DNS_FLAG1_RESPONSE 0x80 #define DNS_FLAG1_OPCODE_STATUS 0x10 #define DNS_FLAG1_OPCODE_INVERSE 0x08 @@ -73,16 +85,37 @@ struct dns_hdr { #define DNS_FLAG2_ERR_MASK 0x0f #define DNS_FLAG2_ERR_NONE 0x00 #define DNS_FLAG2_ERR_NAME 0x03 + +#define STATE_UNUSED 0 +#define STATE_NEW 1 +#define STATE_ASKING 2 +#define STATE_DONE 3 +#define STATE_ERROR 4 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/* The DNS message header */ + +struct dns_hdr +{ + uint16 id; + uint8 flags1, flags2; uint16 numquestions; uint16 numanswers; uint16 numauthrr; uint16 numextrarr; }; -/** \internal The DNS answer message structure. */ -struct dns_answer { +/* The DNS answer message structure */ + +struct dns_answer +{ /* DNS answer record starts with either a domain name or a pointer - to a name already present somewhere in the packet. */ + * to a name already present somewhere in the packet. + */ + uint16 type; uint16 class; uint16 ttl[2]; @@ -90,12 +123,8 @@ struct dns_answer { uip_ipaddr_t ipaddr; }; -struct namemap { -#define STATE_UNUSED 0 -#define STATE_NEW 1 -#define STATE_ASKING 2 -#define STATE_DONE 3 -#define STATE_ERROR 4 +struct namemap +{ uint8 state; uint8 tmr; uint8 retries; @@ -105,51 +134,43 @@ struct namemap { uip_ipaddr_t ipaddr; }; -#ifndef CONFIG_UIP_RESOLV_ENTRIES -#define RESOLV_ENTRIES 4 -#else /* CONFIG_UIP_RESOLV_ENTRIES */ -#define RESOLV_ENTRIES CONFIG_UIP_RESOLV_ENTRIES -#endif /* CONFIG_UIP_RESOLV_ENTRIES */ - +/**************************************************************************** + * Private Data + ****************************************************************************/ static struct namemap names[RESOLV_ENTRIES]; - static uint8 seqno; - static struct uip_udp_conn *resolv_conn = NULL; +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/* Walk through a compact encoded DNS name and return the end of it. */ -/*---------------------------------------------------------------------------*/ -/** \internal - * Walk through a compact encoded DNS name and return the end of it. - * - * \return The end of the name. - */ -/*---------------------------------------------------------------------------*/ static unsigned char *parse_name(unsigned char *query) { unsigned char n; - do { - n = *query++; + do + { + n = *query++; - while(n > 0) - { - ++query; - --n; - }; - } while(*query != 0); + while(n > 0) + { + ++query; + --n; + } + } + while(*query != 0); return query + 1; } -/*---------------------------------------------------------------------------*/ -/** \internal - * Runs through the list of names to see if there are any that have +/* Runs through the list of names to see if there are any that have * not yet been queried and, if so, sends out a query. */ -/*---------------------------------------------------------------------------*/ -static void -check_entries(void) + +static void check_entries(void) { register struct dns_hdr *hdr; char *query, *nptr, *nameptr; @@ -157,66 +178,73 @@ check_entries(void) static uint8 n; register struct namemap *namemapptr; - for(i = 0; i < RESOLV_ENTRIES; ++i) { - namemapptr = &names[i]; - if(namemapptr->state == STATE_NEW || - namemapptr->state == STATE_ASKING) { - if(namemapptr->state == STATE_ASKING) { - if(--namemapptr->tmr == 0) { - if(++namemapptr->retries == MAX_RETRIES) { - namemapptr->state = STATE_ERROR; - resolv_found(namemapptr->name, NULL); - continue; - } - namemapptr->tmr = namemapptr->retries; - } else { - /* printf("Timer %d\n", namemapptr->tmr);*/ - /* Its timer has not run out, so we move on to next - entry. */ - continue; - } - } else { - namemapptr->state = STATE_ASKING; - namemapptr->tmr = 1; - namemapptr->retries = 0; - } - hdr = (struct dns_hdr *)uip_appdata; - memset(hdr, 0, sizeof(struct dns_hdr)); - hdr->id = htons(i); - hdr->flags1 = DNS_FLAG1_RD; - hdr->numquestions = HTONS(1); - query = (char *)uip_appdata + 12; - nameptr = namemapptr->name; - --nameptr; - /* Convert hostname into suitable query format. */ - do { - ++nameptr; - nptr = query; - ++query; - for(n = 0; *nameptr != '.' && *nameptr != 0; ++nameptr) { - *query = *nameptr; - ++query; - ++n; - } - *nptr = n; - } while(*nameptr != 0); - { - static unsigned char endquery[] = - {0,0,1,0,1}; - memcpy(query, endquery, 5); - } - uip_udp_send((unsigned char)(query + 5 - (char *)uip_appdata)); - break; + for(i = 0; i < RESOLV_ENTRIES; ++i) + { + namemapptr = &names[i]; + if (namemapptr->state == STATE_NEW || + namemapptr->state == STATE_ASKING) + { + if (namemapptr->state == STATE_ASKING) + { + if (--namemapptr->tmr == 0) + { + if (++namemapptr->retries == MAX_RETRIES) + { + namemapptr->state = STATE_ERROR; + resolv_found(namemapptr->name, NULL); + continue; + } + namemapptr->tmr = namemapptr->retries; + } + else + { + /* Its timer has not run out, so we move on to next entry. */ + continue; + } + } + else + { + namemapptr->state = STATE_ASKING; + namemapptr->tmr = 1; + namemapptr->retries = 0; + } + hdr = (struct dns_hdr *)uip_appdata; + memset(hdr, 0, sizeof(struct dns_hdr)); + hdr->id = htons(i); + hdr->flags1 = DNS_FLAG1_RD; + hdr->numquestions = HTONS(1); + query = (char *)uip_appdata + 12; + nameptr = namemapptr->name; + --nameptr; + + /* Convert hostname into suitable query format. */ + do + { + ++nameptr; + nptr = query; + ++query; + for (n = 0; *nameptr != '.' && *nameptr != 0; ++nameptr) + { + *query = *nameptr; + ++query; + ++n; + } + *nptr = n; + } + while(*nameptr != 0); + { + static unsigned char endquery[] = {0,0,1,0,1}; + memcpy(query, endquery, 5); + } + uip_udp_send((unsigned char)(query + 5 - (char *)uip_appdata)); + break; + } } - } } -/*---------------------------------------------------------------------------*/ -/** \internal - * Called when new UDP data arrives. - */ -/*---------------------------------------------------------------------------*/ -static void -newdata(void) + +/* Called when new UDP data arrives */ + +static void newdata(void) { unsigned char *nameptr; struct dns_answer *ans; @@ -226,114 +254,127 @@ newdata(void) register struct namemap *namemapptr; hdr = (struct dns_hdr *)uip_appdata; - /* printf("ID %d\n", htons(hdr->id)); - printf("Query %d\n", hdr->flags1 & DNS_FLAG1_RESPONSE); - printf("Error %d\n", hdr->flags2 & DNS_FLAG2_ERR_MASK); - printf("Num questions %d, answers %d, authrr %d, extrarr %d\n", - htons(hdr->numquestions), - htons(hdr->numanswers), - htons(hdr->numauthrr), - htons(hdr->numextrarr)); - */ + + dbg( "ID %d\n", htons(hdr->id)); + dbg( "Query %d\n", hdr->flags1 & DNS_FLAG1_RESPONSE); + dbg( "Error %d\n", hdr->flags2 & DNS_FLAG2_ERR_MASK); + dbg( "Num questions %d, answers %d, authrr %d, extrarr %d\n", + htons(hdr->numquestions), htons(hdr->numanswers), + htons(hdr->numauthrr), htons(hdr->numextrarr)); /* The ID in the DNS header should be our entry into the name - table. */ + * table. + */ + i = htons(hdr->id); namemapptr = &names[i]; - if(i < RESOLV_ENTRIES && - namemapptr->state == STATE_ASKING) { - - /* This entry is now finished. */ - namemapptr->state = STATE_DONE; - namemapptr->err = hdr->flags2 & DNS_FLAG2_ERR_MASK; - - /* Check for error. If so, call callback to inform. */ - if(namemapptr->err != 0) { - namemapptr->state = STATE_ERROR; - resolv_found(namemapptr->name, NULL); - return; - } + if (i < RESOLV_ENTRIES && namemapptr->state == STATE_ASKING) + { + /* This entry is now finished */ - /* We only care about the question(s) and the answers. The authrr - and the extrarr are simply discarded. */ - nquestions = htons(hdr->numquestions); - nanswers = htons(hdr->numanswers); - - /* Skip the name in the question. XXX: This should really be - checked agains the name in the question, to be sure that they - match. */ - nameptr = parse_name((unsigned char *)uip_appdata + 12) + 4; - - while(nanswers > 0) { - /* The first byte in the answer resource record determines if it - is a compressed record or a normal one. */ - if(*nameptr & 0xc0) { - /* Compressed name. */ - nameptr +=2; - /* printf("Compressed anwser\n");*/ - } else { - /* Not compressed name. */ - nameptr = parse_name(nameptr); - } - - ans = (struct dns_answer *)nameptr; - /* printf("Answer: type %x, class %x, ttl %x, length %x\n", - htons(ans->type), htons(ans->class), (htons(ans->ttl[0]) - << 16) | htons(ans->ttl[1]), htons(ans->len));*/ - - /* Check for IP address type and Internet class. Others are - discarded. */ - if(ans->type == HTONS(1) && - ans->class == HTONS(1) && - ans->len == HTONS(4)) { - /* printf("IP address %d.%d.%d.%d\n", - htons(ans->ipaddr[0]) >> 8, - htons(ans->ipaddr[0]) & 0xff, - htons(ans->ipaddr[1]) >> 8, - htons(ans->ipaddr[1]) & 0xff);*/ - /* XXX: we should really check that this IP address is the one - we want. */ - namemapptr->ipaddr[0] = ans->ipaddr[0]; - namemapptr->ipaddr[1] = ans->ipaddr[1]; - - resolv_found(namemapptr->name, namemapptr->ipaddr); - return; - } else { - nameptr = nameptr + 10 + htons(ans->len); - } - --nanswers; - } - } + namemapptr->state = STATE_DONE; + namemapptr->err = hdr->flags2 & DNS_FLAG2_ERR_MASK; + + /* Check for error. If so, call callback to inform */ + + if (namemapptr->err != 0) + { + namemapptr->state = STATE_ERROR; + resolv_found(namemapptr->name, NULL); + return; + } + + /* We only care about the question(s) and the answers. The authrr + * and the extrarr are simply discarded. + */ + + nquestions = htons(hdr->numquestions); + nanswers = htons(hdr->numanswers); + + /* Skip the name in the question. XXX: This should really be + * checked agains the name in the question, to be sure that they + * match. + */ + + nameptr = parse_name((unsigned char *)uip_appdata + 12) + 4; + while(nanswers > 0) + { + /* The first byte in the answer resource record determines if it + * is a compressed record or a normal one. + */ + + if (*nameptr & 0xc0) + { + /* Compressed name. */ + + nameptr +=2; + dbg("Compressed anwser\n"); + } + else + { + /* Not compressed name. */ + nameptr = parse_name(nameptr); + } + + ans = (struct dns_answer *)nameptr; + dbg("Answer: type %x, class %x, ttl %x, length %x\n", + htons(ans->type), htons(ans->class), (htons(ans->ttl[0]) << 16) | htons(ans->ttl[1]), + htons(ans->len)); + + /* Check for IP address type and Internet class. Others are discarded. */ + + if (ans->type == HTONS(1) && ans->class == HTONS(1) && ans->len == HTONS(4)) + { + dbg("IP address %d.%d.%d.%d\n", + htons(ans->ipaddr[0]) >> 8, htons(ans->ipaddr[0]) & 0xff, + htons(ans->ipaddr[1]) >> 8, htons(ans->ipaddr[1]) & 0xff); + + /* XXX: we should really check that this IP address is the one + * we want. + */ + + namemapptr->ipaddr[0] = ans->ipaddr[0]; + namemapptr->ipaddr[1] = ans->ipaddr[1]; + + resolv_found(namemapptr->name, namemapptr->ipaddr); + return; + } + else + { + nameptr = nameptr + 10 + htons(ans->len); + } + --nanswers; + } + } } +/**************************************************************************** + * Private Functions + ****************************************************************************/ + /* This function is called by the UIP interrupt handling logic whenevent an * event of interest occurs. */ void uip_interrupt_udp_event(void) { - if(uip_udp_conn->rport == HTONS(53)) + if (uip_udp_conn->rport == HTONS(53)) { - if(uip_poll()) + if (uip_poll()) { check_entries(); } - if(uip_newdata()) + if (uip_newdata()) { newdata(); } } } -/** - * Queues a name so that a question for the name will be sent out. - * - * \param name The hostname that is to be queried. - */ -/*---------------------------------------------------------------------------*/ -void -resolv_query(char *name) +/* Queues a name so that a question for the name will be sent out. */ + +void resolv_query(char *name) { static uint8 i; static uint8 lseq, lseqi; @@ -341,110 +382,106 @@ resolv_query(char *name) lseq = lseqi = 0; - for(i = 0; i < RESOLV_ENTRIES; ++i) { - nameptr = &names[i]; - if(nameptr->state == STATE_UNUSED) { - break; - } - if(seqno - nameptr->seqno > lseq) { - lseq = seqno - nameptr->seqno; - lseqi = i; + for(i = 0; i < RESOLV_ENTRIES; ++i) + { + nameptr = &names[i]; + if (nameptr->state == STATE_UNUSED) + { + break; + } + if (seqno - nameptr->seqno > lseq) + { + lseq = seqno - nameptr->seqno; + lseqi = i; + } } - } - if(i == RESOLV_ENTRIES) { - i = lseqi; - nameptr = &names[i]; - } + if (i == RESOLV_ENTRIES) + { + i = lseqi; + nameptr = &names[i]; + } - /* printf("Using entry %d\n", i);*/ + dbg("Using entry %d\n", i); strcpy(nameptr->name, name); nameptr->state = STATE_NEW; nameptr->seqno = seqno; ++seqno; } -/*---------------------------------------------------------------------------*/ -/** - * Look up a hostname in the array of known hostnames. + +/* Look up a hostname in the array of known hostnames. * - * \note This function only looks in the internal array of known + * Note: This function only looks in the internal array of known * hostnames, it does not send out a query for the hostname if none * was found. The function resolv_query() can be used to send a query * for a hostname. * - * \return A pointer to a 4-byte representation of the hostname's IP + * Return A pointer to a 4-byte representation of the hostname's IP * address, or NULL if the hostname was not found in the array of * hostnames. */ -/*---------------------------------------------------------------------------*/ -uint16 * -resolv_lookup(char *name) + +uint16 *resolv_lookup(char *name) { static uint8 i; struct namemap *nameptr; /* Walk through the list to see if the name is in there. If it is - not, we return NULL. */ - for(i = 0; i < RESOLV_ENTRIES; ++i) { - nameptr = &names[i]; - if(nameptr->state == STATE_DONE && - strcmp(name, nameptr->name) == 0) { - return nameptr->ipaddr; + * not, we return NULL. + */ + + for(i = 0; i < RESOLV_ENTRIES; ++i) + { + nameptr = &names[i]; + if (nameptr->state == STATE_DONE && strcmp(name, nameptr->name) == 0) + { + return nameptr->ipaddr; + } } - } return NULL; } -/*---------------------------------------------------------------------------*/ -/** - * Obtain the currently configured DNS server. + +/* Obtain the currently configured DNS server. * - * \return A pointer to a 4-byte representation of the IP address of + * Return: A pointer to a 4-byte representation of the IP address of * the currently configured DNS server or NULL if no DNS server has * been configured. */ -/*---------------------------------------------------------------------------*/ -uint16 * -resolv_getserver(void) + +uint16 *resolv_getserver(void) { - if(resolv_conn == NULL) { - return NULL; - } + if (resolv_conn == NULL) + { + return NULL; + } return resolv_conn->ripaddr; } -/*---------------------------------------------------------------------------*/ -/** - * Configure which DNS server to use for queries. + +/* Configure which DNS server to use for queries. * - * \param dnsserver A pointer to a 4-byte representation of the IP + * dnsserver A pointer to a 4-byte representation of the IP * address of the DNS server to be configured. */ -/*---------------------------------------------------------------------------*/ -void -resolv_conf(uint16 *dnsserver) + +void resolv_conf(uint16 *dnsserver) { - if(resolv_conn != NULL) { - uip_udp_remove(resolv_conn); - } - + if (resolv_conn != NULL) + { + uip_udp_remove(resolv_conn); + } + resolv_conn = uip_udp_new(dnsserver, HTONS(53)); } -/*---------------------------------------------------------------------------*/ -/** - * Initalize the resolver. - */ -/*---------------------------------------------------------------------------*/ -void -resolv_init(void) + +/* Initalize the resolver. */ + +void resolv_init(void) { static uint8 i; - for(i = 0; i < RESOLV_ENTRIES; ++i) { - names[i].state = STATE_DONE; - } - + for(i = 0; i < RESOLV_ENTRIES; ++i) + { + names[i].state = STATE_DONE; + } } -/*---------------------------------------------------------------------------*/ - -/** @} */ -/** @} */ diff --git a/nuttx/netutils/smtp/smtp.c b/nuttx/netutils/smtp/smtp.c index d4d8feee0..8ea6ca275 100644 --- a/nuttx/netutils/smtp/smtp.c +++ b/nuttx/netutils/smtp/smtp.c @@ -262,6 +262,10 @@ int smtp_send(void *handle, char *to, char *cc, char *from, char *subject, char struct smtp_state *psmtp = (struct smtp_state *)handle; struct uip_conn *conn; + /* This is the moral equivalent of socket() + bind(). It returns the + * initialized connection structure + */ + conn = uip_connect(&psmtp->smtpserver, HTONS(25)); if (conn == NULL) { @@ -277,14 +281,21 @@ int smtp_send(void *handle, char *to, char *cc, char *from, char *subject, char psmtp->msglen = msglen; psmtp->result = OK; + /* Make this instance globally visible */ + gpsmtp = psmtp; + + /* Initialized the psock structure inside the smtp state structure */ + psock_init(&psmtp->psock, psmtp->buffer, SMTP_INPUT_BUFFER_SIZE); /* And wait for the the socket to be connected */ + sem_wait(&psmtp->sem); gpsmtp = 0; /* Was an error reported by interrupt handler? */ + if (psmtp->result == OK ) { /* No... Send the message */ diff --git a/nuttx/sched/Makefile b/nuttx/sched/Makefile index 56bcb3a90..eb0473f66 100644 --- a/nuttx/sched/Makefile +++ b/nuttx/sched/Makefile @@ -1,4 +1,4 @@ -############################################################ +############################################################################ # Makefile # # Copyright (C) 2007 Gregory Nutt. All rights reserved. @@ -31,7 +31,7 @@ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # -############################################################ +############################################################################ -include $(TOPDIR)/Make.defs @@ -41,7 +41,7 @@ ASRCS = AOBJS = $(ASRCS:.S=$(OBJEXT)) MISC_SRCS = os_start.c get_errno_ptr.c \ - sched_setupstreams.c sched_getfiles.c sched_getstreams.c \ + sched_setupstreams.c sched_getfiles.c sched_getsockets.c sched_getstreams.c \ sched_setupidlefiles.c sched_setuptaskfiles.c sched_setuppthreadfiles.c \ sched_releasefiles.c TSK_SRCS = task_create.c task_init.c task_setup.c task_activate.c \ diff --git a/nuttx/sched/os_internal.h b/nuttx/sched/os_internal.h index da6974066..94da9bbbc 100644 --- a/nuttx/sched/os_internal.h +++ b/nuttx/sched/os_internal.h @@ -96,7 +96,7 @@ enum os_crash_codes_e /* Stubs used when there are no file descriptors */ -#if CONFIG_NFILE_DESCRIPTORS <= 0 +#if CONFIG_NFILE_DESCRIPTORS <= 0 && CONFIG_NSOCKET_DESCRIPTORS <= 0 # define sched_setupidlefiles(t) (OK) # define sched_setuptaskfiles(t) (OK) # define sched_setuppthreadfiles(t) (OK) @@ -254,11 +254,11 @@ extern void sched_addblocked(FAR _TCB *btcb, tstate_t task_state); extern void sched_removeblocked(FAR _TCB *btcb); extern FAR _TCB *sched_gettcb(pid_t pid); -#if CONFIG_NFILE_DESCRIPTORS > 0 +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 extern int sched_setupidlefiles(FAR _TCB *tcb); extern int sched_setuptaskfiles(FAR _TCB *tcb); extern int sched_setuppthreadfiles(FAR _TCB *tcb); -#if CONFIG_NFILE_STREAMS > 0 +#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 extern int sched_setupstreams(FAR _TCB *tcb); extern int sched_flushfiles(FAR _TCB *tcb); #endif diff --git a/nuttx/sched/sched_getsockets.c b/nuttx/sched/sched_getsockets.c new file mode 100644 index 000000000..c54c5f236 --- /dev/null +++ b/nuttx/sched/sched_getsockets.c @@ -0,0 +1,76 @@ +/************************************************************ + * sched_getsockets.c + * + * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * 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 Gregory Nutt 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 +#if CONFIG_NSOCKET_DESCRIPTORS > 0 + +#include +#include "os_internal.h" + +/************************************************************ + * Private Functions + ************************************************************/ + +/************************************************************ + * Public Functions + ************************************************************/ + +/************************************************************ + * Function: sched_getsockets + * + * Description: + * Return a pointer to the socket list for this thread + * + * Parameters: + * None + * + * Return Value: + * A pointer to the errno. + * + * Assumptions: + * + ************************************************************/ + +FAR struct socketlist *sched_getsockets(void) +{ + FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; + return rtcb->sockets; +} + +#endif /* CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/sched/sched_releasefiles.c b/nuttx/sched/sched_releasefiles.c index c511bdb54..707e8636a 100644 --- a/nuttx/sched/sched_releasefiles.c +++ b/nuttx/sched/sched_releasefiles.c @@ -38,8 +38,11 @@ ************************************************************/ #include +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 + #include #include +#include #include /************************************************************ @@ -66,12 +69,11 @@ * ************************************************************/ -#if CONFIG_NFILE_DESCRIPTORS > 0 - int sched_releasefiles(_TCB *tcb) { if (tcb) { +#if CONFIG_NFILE_DESCRIPTORS > 0 /* Free the file descriptor list */ files_releaselist(tcb->filelist); @@ -83,7 +85,17 @@ int sched_releasefiles(_TCB *tcb) lib_releaselist(tcb->streams); tcb->streams = NULL; #endif /* CONFIG_NFILE_STREAMS */ +#endif /* CONFIG_NFILE_DESCRIPTORS */ + +#if CONFIG_NSOCKET_DESCRIPTORS > 0 + /* Free the file descriptor list */ + + net_releaselist(tcb->sockets); + tcb->sockets = NULL; + +#endif /* CONFIG_NSOCKET_DESCRIPTORS */ } return OK; } -#endif /* CONFIG_NFILE_DESCRIPTORS */ + +#endif /* CONFIG_NFILE_DESCRIPTORS || CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/sched/sched_setupidlefiles.c b/nuttx/sched/sched_setupidlefiles.c index 78d8d60ad..4949779af 100644 --- a/nuttx/sched/sched_setupidlefiles.c +++ b/nuttx/sched/sched_setupidlefiles.c @@ -38,11 +38,17 @@ ************************************************************/ #include +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 + #include #include #include #include #include + +#include +#include + #include "os_internal.h" /************************************************************ @@ -69,12 +75,11 @@ * ************************************************************/ -#if CONFIG_NFILE_DESCRIPTORS > 0 - int sched_setupidlefiles(FAR _TCB *tcb) { int fd; +#if CONFIG_NFILE_DESCRIPTORS > 0 /* Allocate file descriptors for the TCB */ tcb->filelist = files_alloclist(); @@ -83,8 +88,20 @@ int sched_setupidlefiles(FAR _TCB *tcb) *get_errno_ptr() = ENOMEM; return ERROR; } +#endif /* CONFIG_NFILE_DESCRIPTORS */ + +#if CONFIG_NSOCKET_DESCRIPTORS > 0 + /* Allocate socket descriptors for the TCB */ + + tcb->sockets = net_alloclist(); + if (!tcb->sockets) + { + *get_errno_ptr() = ENOMEM; + return ERROR; + } +#endif /* CONFIG_NSOCKET_DESCRIPTORS */ -#ifdef CONFIG_DEV_CONSOLE +#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_DEV_CONSOLE) /* Open stdin, dup to get stdout and stderr. */ fd = open("/dev/console", O_RDWR); @@ -107,7 +124,7 @@ int sched_setupidlefiles(FAR _TCB *tcb) #else return OK; #endif /* CONFIG_NFILE_STREAMS */ -#endif /* CONFIG_DEV_CONSOLE */ +#endif /* CONFIG_NFILE_DESCRIPTORS && CONFIG_DEV_CONSOLE */ } -#endif /* CONFIG_NFILE_DESCRIPTORS */ +#endif /* CONFIG_NFILE_DESCRIPTORS || CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/sched/sched_setuppthreadfiles.c b/nuttx/sched/sched_setuppthreadfiles.c index 91dfd850f..e5f035afa 100644 --- a/nuttx/sched/sched_setuppthreadfiles.c +++ b/nuttx/sched/sched_setuppthreadfiles.c @@ -38,9 +38,14 @@ ************************************************************/ #include +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 + #include + #include +#include #include + #include "os_internal.h" /************************************************************ @@ -68,12 +73,11 @@ * ************************************************************/ -#if CONFIG_NFILE_DESCRIPTORS > 0 - int sched_setuppthreadfiles(FAR _TCB *tcb) { FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; +#if CONFIG_NFILE_DESCRIPTORS > 0 /* The child thread inherits the parent file descriptors */ tcb->filelist = rtcb->filelist; @@ -86,8 +90,17 @@ int sched_setuppthreadfiles(FAR _TCB *tcb) lib_addreflist(tcb->streams); #endif /* CONFIG_NFILE_STREAMS */ +#endif /* CONFIG_NFILE_DESCRIPTORS */ + +#if CONFIG_NSOCKET_DESCRIPTORS > 0 + /* The child thread inherits the parent file descriptors */ + + tcb->sockets = rtcb->sockets; + net_addreflist(tcb->sockets); + +#endif /* CONFIG_NSOCKET_DESCRIPTORS */ return OK; } -#endif /* CONFIG_NFILE_DESCRIPTORS */ +#endif /* CONFIG_NFILE_DESCRIPTORS || CONFIG_NSOCKET_DESCRIPTORS */ diff --git a/nuttx/sched/sched_setupstreams.c b/nuttx/sched/sched_setupstreams.c index a19dd0bf1..1429ece31 100644 --- a/nuttx/sched/sched_setupstreams.c +++ b/nuttx/sched/sched_setupstreams.c @@ -38,8 +38,11 @@ ************************************************************/ #include +#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 + #include #include +#include #include /************************************************************ @@ -50,8 +53,6 @@ * Public Functions ************************************************************/ -#if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0 - int sched_setupstreams(FAR _TCB *tcb) { /* Allocate file strems for the TCB */ diff --git a/nuttx/sched/sched_setuptaskfiles.c b/nuttx/sched/sched_setuptaskfiles.c index 9fef59278..203a06b44 100644 --- a/nuttx/sched/sched_setuptaskfiles.c +++ b/nuttx/sched/sched_setuptaskfiles.c @@ -38,9 +38,14 @@ ************************************************************/ #include +#if CONFIG_NFILE_DESCRIPTORS > 0 || CONFIG_NSOCKET_DESCRIPTORS > 0 + #include #include + #include +#include + #include "os_internal.h" /************************************************************ @@ -68,16 +73,15 @@ * ************************************************************/ -#if CONFIG_NFILE_DESCRIPTORS > 0 - int sched_setuptaskfiles(FAR _TCB *tcb) { -#ifdef CONFIG_DEV_CONSOLE +#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_DEV_CONSOLE) FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; int i; #endif /* CONFIG_DEV_CONSOLE */ int ret = OK; +#if CONFIG_NFILE_DESCRIPTORS > 0 /* Allocate file descriptors for the TCB */ tcb->filelist = files_alloclist(); @@ -86,8 +90,20 @@ int sched_setuptaskfiles(FAR _TCB *tcb) *get_errno_ptr() = ENOMEM; return ERROR; } +#endif /* CONFIG_NFILE_DESCRIPTORS */ + +#if CONFIG_NSOCKET_DESCRIPTORS > 0 + /* Allocate socket descriptors for the TCB */ + + tcb->sockets = net_alloclist(); + if (!tcb->sockets) + { + *get_errno_ptr() = ENOMEM; + return ERROR; + } +#endif /* CONFIG_NSOCKET_DESCRIPTORS */ -#ifdef CONFIG_DEV_CONSOLE +#if CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_DEV_CONSOLE) /* Duplicate the first three file descriptors */ if (rtcb->filelist) @@ -104,8 +120,8 @@ int sched_setuptaskfiles(FAR _TCB *tcb) ret = sched_setupstreams(tcb); #endif /* CONFIG_NFILE_STREAMS */ -#endif /* CONFIG_DEV_CONSOLE */ +#endif /* CONFIG_NFILE_DESCRIPTORS && CONFIG_DEV_CONSOLE */ return ret; } -#endif /* CONFIG_NFILE_DESCRIPTORS */ +#endif /* CONFIG_NFILE_DESCRIPTORS || CONFIG_NSOCKET_DESCRIPTORS */ -- cgit v1.2.3