diff options
43 files changed, 1046 insertions, 596 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index f14df48b5..fd6223bea 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -237,3 +237,5 @@ * Add TX notification to driver so that it can respond faster to the availability of TX data. * Moved urgent data info into device structure. + * TCP and ICMP protocols can now be disabled. + diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index f024189e0..77cdee1f7 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -708,6 +708,7 @@ Other memory: * Add TX notification to driver so that it can respond faster to the availability of TX data. * Moved urgent data info into device structure. + * TCP and ICMP protocols can now be disabled. </pre></ul> <table width ="100%"> diff --git a/nuttx/Documentation/NuttxPortingGuide.html b/nuttx/Documentation/NuttxPortingGuide.html index 98af10dae..afe1aafa3 100644 --- a/nuttx/Documentation/NuttxPortingGuide.html +++ b/nuttx/Documentation/NuttxPortingGuide.html @@ -1353,16 +1353,16 @@ The system can be re-made subsequently by just typing <code>make</code>. <code>CONFIG_NSOCKET_DESCRIPTORS</code>: Maximum number of socket descriptors per task/thread. </li> <li> - <code>CONFIG_NET_TCP_CONNS</code>: Maximum number of TCP connections (all tasks). + <code>CONFIG_NET_SOCKOPTS</code>: Enable or disable support for socket options. </li> <li> - <code>CONFIG_NET_MAX_LISTENPORTS</code>: Maximum number of listening TCP ports (all tasks). + <code>CONFIG_NET_BUFSIZE</code>: uIP buffer size </li> <li> - <code>CONFIG_NET_SOCKOPTS</code>: Enable or disable support for socket options. + <code>CONFIG_NET_TCP</code>: TCP support on or off </li> <li> - <code>CONFIG_NET_BUFSIZE</code>: uIP buffer size + <code>CONFIG_NET_TCP_CONNS</code>: Maximum number of TCP connections (all tasks). </li> <li> <code>CONFIG_NET_TCP_READAHEAD_BUFSIZE</code>: Size of TCP read-ahead buffers @@ -1371,6 +1371,9 @@ The system can be re-made subsequently by just typing <code>make</code>. <code>CONFIG_NET_NTCP_READAHEAD_BUFFERS</code>: Number of TCP read-ahead buffers (may be zero) </li> <li> + <code>CONFIG_NET_MAX_LISTENPORTS</code>: Maximum number of listening TCP ports (all tasks). + </li> + <li> <code>CONFIG_NET_TCPURGDATA</code>: 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 is very seldom would be required. @@ -1385,12 +1388,15 @@ The system can be re-made subsequently by just typing <code>make</code>. <code>CONFIG_NET_UDP_CONNS</code>: The maximum amount of concurrent UDP connections </li> <li> - <code>CONFIG_NET_STATISTICS</code>: uIP statistics on or off + <code>CONFIG_NET_ICMP</code>: ICMP ping support on or off </li> <li> <code>CONFIG_NET_PINGADDRCONF</code>: Use "ping" packet for setting IP address </li> <li> + <code>CONFIG_NET_STATISTICS</code>: uIP statistics on or off + </li> + <li> <code>CONFIG_NET_RECEIVE_WINDOW</code>: The size of the advertised receiver's window </li> <li> diff --git a/nuttx/TODO b/nuttx/TODO index 3c9d5ead7..90c9d123b 100644 --- a/nuttx/TODO +++ b/nuttx/TODO @@ -29,6 +29,7 @@ o C++ Support - Need to call static constructors o Network +- UDP is untested. - Did not implement send() and sendto() timeouts. Option is setable via setsockopt, but is not implemented. - uIP's netutils/telnetd (and maybe others) are seriously broken. @@ -38,6 +39,8 @@ o Network - Should implement SOCK_RAW - accept() and recvfrom() need to return connection address - Performance Improvements (uIP is not very fast): + Need to extend logic so that uIP can have more than on packet in flight and to + handle deferred acknowledgements. - uIP polling issues: (1) Current logic will not support multiple ethernet drivers. Each driver should poll on TCP connections connect on the network supported by the driver; UDP diff --git a/nuttx/configs/README.txt b/nuttx/configs/README.txt index df5a53b43..03d6aad8b 100644 --- a/nuttx/configs/README.txt +++ b/nuttx/configs/README.txt @@ -213,23 +213,25 @@ defconfig -- This is a configuration file similar to the Linux CONFIG_NET_IPv6 - Build in support for IPv6 CONFIG_NSOCKET_DESCRIPTORS - Maximum number of socket descriptors per task/thread. - CONFIG_NET_TCP_CONNS - Maximum number of TCP connections (all tasks) - CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) CONFIG_NET_SOCKOPTS - Enable or disable support for socket options CONFIG_NET_BUFSIZE - uIP buffer size - CONFIG_NET_TCP_READAHEAD_BUFSIZE - Size of TCP read-ahead buffers - CONFIG_NET_NTCP_READAHEAD_BUFFERS - Number of TCP read-ahead buffers - (may be zero) CONFIG_NET_TCPURGDATA - 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 is very seldom would be required. + CONFIG_NET_TCP - TCP support on or off + CONFIG_NET_TCP_CONNS - Maximum number of TCP connections (all tasks) + CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) + CONFIG_NET_TCP_READAHEAD_BUFSIZE - Size of TCP read-ahead buffers + CONFIG_NET_NTCP_READAHEAD_BUFFERS - Number of TCP read-ahead buffers + (may be zero) 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_ICMP - ICMP ping support on or off CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address + CONFIG_NET_STATISTICS - uIP statistics on or off CONFIG_NET_RECEIVE_WINDOW - The size of the advertised receiver's window CONFIG_NET_ARPTAB_SIZE - The size of the ARP table diff --git a/nuttx/configs/c5471evm/defconfig b/nuttx/configs/c5471evm/defconfig index 2bc085041..2a567f13b 100644 --- a/nuttx/configs/c5471evm/defconfig +++ b/nuttx/configs/c5471evm/defconfig @@ -254,17 +254,19 @@ CONFIG_PREALLOC_TIMERS=8 # 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_TCP_CONNS - Maximum number of TCP connections (all tasks) -# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # CONFIG_NET_SOCKOPTS - Enable or disable support for socket options # CONFIG_NET_BUFSIZE - uIP buffer size +# CONFIG_NET_TCP - TCP support on or off +# CONFIG_NET_TCP_CONNS - Maximum number of TCP connections (all tasks) # CONFIG_NET_TCP_READAHEAD_BUFSIZE - Size of TCP read-ahead buffers # CONFIG_NET_NTCP_READAHEAD_BUFFERS - Number of TCP read-ahead buffers (may be zero) +# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # 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_ICMP - ICMP ping support on or off # CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address +# CONFIG_NET_STATISTICS - uIP statistics on or off # 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 @@ -273,15 +275,17 @@ CONFIG_PREALLOC_TIMERS=8 CONFIG_NET=n CONFIG_NET_IPv6=n CONFIG_NSOCKET_DESCRIPTORS=0 -CONFIG_NET_TCP_CONNS=40 -CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_SOCKOPTS=y CONFIG_NET_BUFSIZE=420 +CONFIG_NET_TCP=n +CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_UDP=n CONFIG_NET_UDP_CHECKSUMS=y #CONFIG_NET_UDP_CONNS=10 -CONFIG_NET_STATISTICS=y +CONFIG_NET_ICMP=n #CONFIG_NET_PINGADDRCONF=0 +CONFIG_NET_STATISTICS=y #CONFIG_NET_RECEIVE_WINDOW= #CONFIG_NET_ARPTAB_SIZE=8 CONFIG_NET_BROADCAST=n diff --git a/nuttx/configs/m68332evb/defconfig b/nuttx/configs/m68332evb/defconfig index b07ac62a0..f909f455d 100644 --- a/nuttx/configs/m68332evb/defconfig +++ b/nuttx/configs/m68332evb/defconfig @@ -243,17 +243,19 @@ CONFIG_PREALLOC_TIMERS=8 # 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_TCP_CONNS - Maximum number of TCP connections (all tasks) -# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # CONFIG_NET_SOCKOPTS - Enable or disable support for socket options # CONFIG_NET_BUFSIZE - uIP buffer size +# CONFIG_NET_TCP - TCP support on or off +# CONFIG_NET_TCP_CONNS - Maximum number of TCP connections (all tasks) # CONFIG_NET_TCP_READAHEAD_BUFSIZE - Size of TCP read-ahead buffers # CONFIG_NET_NTCP_READAHEAD_BUFFERS - Number of TCP read-ahead buffers (may be zero) +# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # 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_ICMP - ICMP ping support on or off # CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address +# CONFIG_NET_STATISTICS - uIP statistics on or off # 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 @@ -262,15 +264,17 @@ CONFIG_PREALLOC_TIMERS=8 CONFIG_NET=n CONFIG_NET_IPv6=n CONFIG_NSOCKET_DESCRIPTORS=0 -CONFIG_NET_TCP_CONNS=40 -CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_SOCKOPTS=y CONFIG_NET_BUFSIZE=420 +CONFIG_NET_TCP=n +CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_UDP=n CONFIG_NET_UDP_CHECKSUMS=y #CONFIG_NET_UDP_CONNS=10 -CONFIG_NET_STATISTICS=y +CONFIG_NET_ICMP=n #CONFIG_NET_PINGADDRCONF=0 +CONFIG_NET_STATISTICS=y #CONFIG_NET_RECEIVE_WINDOW= #CONFIG_NET_ARPTAB_SIZE=8 CONFIG_NET_BROADCAST=n diff --git a/nuttx/configs/mcu123-lpc214x/defconfig b/nuttx/configs/mcu123-lpc214x/defconfig index fe6a93801..5af107ef5 100644 --- a/nuttx/configs/mcu123-lpc214x/defconfig +++ b/nuttx/configs/mcu123-lpc214x/defconfig @@ -267,17 +267,19 @@ CONFIG_PREALLOC_TIMERS=8 # 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_TCP_CONNS - Maximum number of TCP connections (all tasks) -# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # CONFIG_NET_SOCKOPTS - Enable or disable support for socket options # CONFIG_NET_BUFSIZE - uIP buffer size +# CONFIG_NET_TCP - TCP support on or off +# CONFIG_NET_TCP_CONNS - Maximum number of TCP connections (all tasks) # CONFIG_NET_TCP_READAHEAD_BUFSIZE - Size of TCP read-ahead buffers # CONFIG_NET_NTCP_READAHEAD_BUFFERS - Number of TCP read-ahead buffers (may be zero) +# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # 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_ICMP - ICMP ping support on or off # CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address +# CONFIG_NET_STATISTICS - uIP statistics on or off # 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 @@ -286,15 +288,17 @@ CONFIG_PREALLOC_TIMERS=8 CONFIG_NET=n CONFIG_NET_IPv6=n CONFIG_NSOCKET_DESCRIPTORS=0 -CONFIG_NET_TCP_CONNS=40 -CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_SOCKOPTS=y CONFIG_NET_BUFSIZE=420 +CONFIG_NET_TCP=n +CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_UDP=n CONFIG_NET_UDP_CHECKSUMS=y #CONFIG_NET_UDP_CONNS=10 -CONFIG_NET_STATISTICS=y +CONFIG_NET_ICMP=n #CONFIG_NET_PINGADDRCONF=0 +CONFIG_NET_STATISTICS=y #CONFIG_NET_RECEIVE_WINDOW= #CONFIG_NET_ARPTAB_SIZE=8 CONFIG_NET_BROADCAST=n diff --git a/nuttx/configs/ntosd-dm320/defconfig b/nuttx/configs/ntosd-dm320/defconfig index d7ae85b3b..318124ca9 100644 --- a/nuttx/configs/ntosd-dm320/defconfig +++ b/nuttx/configs/ntosd-dm320/defconfig @@ -252,17 +252,19 @@ CONFIG_PREALLOC_TIMERS=8 # 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_TCP_CONNS - Maximum number of TCP connections (all tasks) -# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # CONFIG_NET_SOCKOPTS - Enable or disable support for socket options # CONFIG_NET_BUFSIZE - uIP buffer size +# CONFIG_NET_TCP - TCP support on or off +# CONFIG_NET_TCP_CONNS - Maximum number of TCP connections (all tasks) # CONFIG_NET_TCP_READAHEAD_BUFSIZE - Size of TCP read-ahead buffers # CONFIG_NET_NTCP_READAHEAD_BUFFERS - Number of TCP read-ahead buffers (may be zero) +# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # 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_ICMP - ICMP ping support on or off # CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address +# CONFIG_NET_STATISTICS - uIP statistics on or off # 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 @@ -271,15 +273,17 @@ CONFIG_PREALLOC_TIMERS=8 CONFIG_NET=n CONFIG_NET_IPv6=n CONFIG_NSOCKET_DESCRIPTORS=0 -CONFIG_NET_TCP_CONNS=40 -CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_SOCKOPTS=y CONFIG_NET_BUFSIZE=420 +CONFIG_NET_TCP=n +CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_UDP=n CONFIG_NET_UDP_CHECKSUMS=y #CONFIG_NET_UDP_CONNS=10 -CONFIG_NET_STATISTICS=y +CONFIG_NET_ICMP=n #CONFIG_NET_PINGADDRCONF=0 +CONFIG_NET_STATISTICS=y #CONFIG_NET_RECEIVE_WINDOW= #CONFIG_NET_ARPTAB_SIZE=8 CONFIG_NET_BROADCAST=n diff --git a/nuttx/configs/ntosd-dm320/netconfig b/nuttx/configs/ntosd-dm320/netconfig index f45c136c9..b5013165d 100644 --- a/nuttx/configs/ntosd-dm320/netconfig +++ b/nuttx/configs/ntosd-dm320/netconfig @@ -252,17 +252,19 @@ CONFIG_PREALLOC_TIMERS=8 # 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_TCP_CONNS - Maximum number of TCP connections (all tasks) -# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # CONFIG_NET_SOCKOPTS - Enable or disable support for socket options # CONFIG_NET_BUFSIZE - uIP buffer size +# CONFIG_NET_TCP - TCP support on or off +# CONFIG_NET_TCP_CONNS - Maximum number of TCP connections (all tasks) # CONFIG_NET_TCP_READAHEAD_BUFSIZE - Size of TCP read-ahead buffers # CONFIG_NET_NTCP_READAHEAD_BUFFERS - Number of TCP read-ahead buffers (may be zero) +# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # 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_ICMP - ICMP ping support on or off # CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address +# CONFIG_NET_STATISTICS - uIP statistics on or off # 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 @@ -271,15 +273,17 @@ CONFIG_PREALLOC_TIMERS=8 CONFIG_NET=y CONFIG_NET_IPv6=n CONFIG_NSOCKET_DESCRIPTORS=8 -CONFIG_NET_TCP_CONNS=8 -CONFIG_NET_MAX_LISTENPORTS=8 CONFIG_NET_SOCKOPTS=y CONFIG_NET_BUFSIZE=420 -CONFIG_NET_UDP=y +CONFIG_NET_TCP=y +CONFIG_NET_TCP_CONNS=8 +CONFIG_NET_MAX_LISTENPORTS=8 +CONFIG_NET_UDP=n CONFIG_NET_UDP_CHECKSUMS=y #CONFIG_NET_UDP_CONNS=10 -CONFIG_NET_STATISTICS=n +CONFIG_NET_ICMP=y #CONFIG_NET_PINGADDRCONF=0 +CONFIG_NET_STATISTICS=n #CONFIG_NET_RECEIVE_WINDOW= #CONFIG_NET_ARPTAB_SIZE=8 CONFIG_NET_BROADCAST=n diff --git a/nuttx/configs/ntosd-dm320/uipconfig b/nuttx/configs/ntosd-dm320/uipconfig index dffba8250..0e36ffb36 100644 --- a/nuttx/configs/ntosd-dm320/uipconfig +++ b/nuttx/configs/ntosd-dm320/uipconfig @@ -252,17 +252,19 @@ CONFIG_PREALLOC_TIMERS=8 # 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_TCP_CONNS - Maximum number of TCP connections (all tasks) -# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # CONFIG_NET_SOCKOPTS - Enable or disable support for socket options # CONFIG_NET_BUFSIZE - uIP buffer size +# CONFIG_NET_TCP - TCP support on or off +# CONFIG_NET_TCP_CONNS - Maximum number of TCP connections (all tasks) # CONFIG_NET_TCP_READAHEAD_BUFSIZE - Size of TCP read-ahead buffers # CONFIG_NET_NTCP_READAHEAD_BUFFERS - Number of TCP read-ahead buffers (may be zero) +# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # 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_ICMP - ICMP ping support on or off # CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address +# CONFIG_NET_STATISTICS - uIP statistics on or off # 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 @@ -271,15 +273,17 @@ CONFIG_PREALLOC_TIMERS=8 CONFIG_NET=y CONFIG_NET_IPv6=n CONFIG_NSOCKET_DESCRIPTORS=8 -CONFIG_NET_TCP_CONNS=8 -CONFIG_NET_MAX_LISTENPORTS=8 CONFIG_NET_SOCKOPTS=y CONFIG_NET_BUFSIZE=420 -CONFIG_NET_UDP=y +CONFIG_NET_TCP=y +CONFIG_NET_TCP_CONNS=8 +CONFIG_NET_MAX_LISTENPORTS=8 +CONFIG_NET_UDP=n CONFIG_NET_UDP_CHECKSUMS=y #CONFIG_NET_UDP_CONNS=10 -CONFIG_NET_STATISTICS=n +CONFIG_NET_ICMP=y #CONFIG_NET_PINGADDRCONF=0 +CONFIG_NET_STATISTICS=n #CONFIG_NET_RECEIVE_WINDOW= #CONFIG_NET_ARPTAB_SIZE=8 CONFIG_NET_BROADCAST=n diff --git a/nuttx/configs/pjrc-8051/defconfig b/nuttx/configs/pjrc-8051/defconfig index d3abb4e9d..4714590ee 100644 --- a/nuttx/configs/pjrc-8051/defconfig +++ b/nuttx/configs/pjrc-8051/defconfig @@ -240,17 +240,19 @@ CONFIG_PREALLOC_TIMERS=0 # 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_TCP_CONNS - Maximum number of TCP connections (all tasks) -# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # CONFIG_NET_SOCKOPTS - Enable or disable support for socket options # CONFIG_NET_BUFSIZE - uIP buffer size +# CONFIG_NET_TCP - TCP support on or off +# CONFIG_NET_TCP_CONNS - Maximum number of TCP connections (all tasks) # CONFIG_NET_TCP_READAHEAD_BUFSIZE - Size of TCP read-ahead buffers # CONFIG_NET_NTCP_READAHEAD_BUFFERS - Number of TCP read-ahead buffers (may be zero) +# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # 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_ICMP - ICMP ping support on or off # CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address +# CONFIG_NET_STATISTICS - uIP statistics on or off # 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 @@ -259,15 +261,17 @@ CONFIG_PREALLOC_TIMERS=0 CONFIG_NET=n CONFIG_NET_IPv6=n CONFIG_NSOCKET_DESCRIPTORS=0 -CONFIG_NET_TCP_CONNS=40 -CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_SOCKOPTS=y CONFIG_NET_BUFSIZE=420 +CONFIG_NET_TCP=n +CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_UDP=n CONFIG_NET_UDP_CHECKSUMS=y #CONFIG_NET_UDP_CONNS=10 -CONFIG_NET_STATISTICS=y +CONFIG_NET_ICMP=n #CONFIG_NET_PINGADDRCONF=0 +CONFIG_NET_STATISTICS=y #CONFIG_NET_RECEIVE_WINDOW= #CONFIG_NET_ARPTAB_SIZE=8 CONFIG_NET_BROADCAST=n diff --git a/nuttx/configs/sim/defconfig b/nuttx/configs/sim/defconfig index 45b338948..4510227ac 100644 --- a/nuttx/configs/sim/defconfig +++ b/nuttx/configs/sim/defconfig @@ -214,17 +214,19 @@ CONFIG_FS_FAT=y # 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_TCP_CONNS - Maximum number of TCP connections (all tasks) -# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # CONFIG_NET_SOCKOPTS - Enable or disable support for socket options # CONFIG_NET_BUFSIZE - uIP buffer size +# CONFIG_NET_TCP - TCP support on or off +# CONFIG_NET_TCP_CONNS - Maximum number of TCP connections (all tasks) # CONFIG_NET_TCP_READAHEAD_BUFSIZE - Size of TCP read-ahead buffers # CONFIG_NET_NTCP_READAHEAD_BUFFERS - Number of TCP read-ahead buffers (may be zero) +# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # 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_ICMP - ICMP ping support on or off # CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address +# CONFIG_NET_STATISTICS - uIP statistics on or off # 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 @@ -233,15 +235,17 @@ CONFIG_FS_FAT=y CONFIG_NET=n CONFIG_NET_IPv6=n CONFIG_NSOCKET_DESCRIPTORS=0 -CONFIG_NET_TCP_CONNS=40 -CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_SOCKOPTS=y CONFIG_NET_BUFSIZE=420 +CONFIG_NET_TCP=n +CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_UDP=n CONFIG_NET_UDP_CHECKSUMS=y #CONFIG_NET_UDP_CONNS=10 -CONFIG_NET_STATISTICS=y +CONFIG_NET_ICMP=n #CONFIG_NET_PINGADDRCONF=0 +CONFIG_NET_STATISTICS=y #CONFIG_NET_RECEIVE_WINDOW= #CONFIG_NET_ARPTAB_SIZE=8 CONFIG_NET_BROADCAST=n diff --git a/nuttx/configs/sim/netconfig b/nuttx/configs/sim/netconfig index 781a4d8c0..163c0c27f 100644 --- a/nuttx/configs/sim/netconfig +++ b/nuttx/configs/sim/netconfig @@ -215,17 +215,19 @@ CONFIG_FS_FAT=y # 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_TCP_CONNS - Maximum number of TCP connections (all tasks) -# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # CONFIG_NET_SOCKOPTS - Enable or disable support for socket options # CONFIG_NET_BUFSIZE - uIP buffer size +# CONFIG_NET_TCP - TCP support on or off +# CONFIG_NET_TCP_CONNS - Maximum number of TCP connections (all tasks) # CONFIG_NET_TCP_READAHEAD_BUFSIZE - Size of TCP read-ahead buffers # CONFIG_NET_NTCP_READAHEAD_BUFFERS - Number of TCP read-ahead buffers (may be zero) +# CONFIG_NET_MAX_LISTENPORTS - Maximum number of listening TCP ports (all tasks) # 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_ICMP - ICMP ping support on or off # CONFIG_NET_PINGADDRCONF - Use "ping" packet for setting IP address +# CONFIG_NET_STATISTICS - uIP statistics on or off # 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 @@ -234,15 +236,17 @@ CONFIG_FS_FAT=y CONFIG_NET=y CONFIG_NET_IPv6=n CONFIG_NSOCKET_DESCRIPTORS=8 -CONFIG_NET_TCP_CONNS=40 -CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_SOCKOPTS=y CONFIG_NET_BUFSIZE=420 +CONFIG_NET_TCP=y +CONFIG_NET_TCP_CONNS=40 +CONFIG_NET_MAX_LISTENPORTS=40 CONFIG_NET_UDP=y CONFIG_NET_UDP_CHECKSUMS=y #CONFIG_NET_UDP_CONNS=10 -CONFIG_NET_STATISTICS=y +CONFIG_NET_ICMP=y #CONFIG_NET_PINGADDRCONF=0 +CONFIG_NET_STATISTICS=y #CONFIG_NET_RECEIVE_WINDOW= #CONFIG_NET_ARPTAB_SIZE=8 CONFIG_NET_BROADCAST=n diff --git a/nuttx/include/net/uip/uip-icmp.h b/nuttx/include/net/uip/uip-icmp.h new file mode 100644 index 000000000..816da04ab --- /dev/null +++ b/nuttx/include/net/uip/uip-icmp.h @@ -0,0 +1,139 @@ +/**************************************************************************** + * net/uip/uip-icmp.h + * Header file for the uIP ICMP stack. + * + * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * This logic was leveraged from uIP which also has a BSD-style license: + * + * Author Adam Dunkels <adam@dunkels.com> + * 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 + * 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. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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_UIP_ICMP_H +#define __NET_UIP_UIP_ICMP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <sys/types.h> +#include <net/uip/uipopt.h> + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/* The ICMP and IP headers */ + +struct uip_icmpip_hdr +{ +#ifdef CONFIG_NET_IPv6 + + /* IPv6 Ip header */ + + uint8 vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */ + uint8 tcf; /* Bits 0-3: traffic class (LS), bits 4-7: flow label (MS) */ + uint16 flow; /* 16-bit flow label (LS) */ + uint8 len[2]; /* 16-bit Payload length */ + uint8 proto; /* 8-bit Next header (same as IPv4 protocol field) */ + uint8 ttl; /* 8-bit Hop limit (like IPv4 TTL field) */ + uip_ip6addr_t srcipaddr; /* 128-bit Source address */ + uip_ip6addr_t destipaddr; /* 128-bit Destination address */ + +#else /* CONFIG_NET_IPv6 */ + + /* IPv4 IP header */ + + uint8 vhl; /* 8-bit Version (4) and header length (5 or 6) */ + uint8 tos; /* 8-bit Type of service (e.g., 6=TCP) */ + uint8 len[2]; /* 16-bit Total length */ + uint8 ipid[2]; /* 16-bit Identification */ + uint8 ipoffset[2]; /* 16-bit IP flags + fragment offset */ + uint8 ttl; /* 8-bit Time to Live */ + uint8 proto; /* 8-bit Protocol */ + uint16 ipchksum; /* 16-bit Header checksum */ + uint16 srcipaddr[2]; /* 32-bit Source IP address */ + uint16 destipaddr[2]; /* 32-bit Destination IP address */ + +#endif /* CONFIG_NET_IPv6 */ + + /* ICMP (echo) header */ + + uint8 type; + uint8 icode; + uint16 icmpchksum; + +#ifndef CONFIG_NET_IPv6 + + uint16 id; + uint16 seqno; + +#else /* !CONFIG_NET_IPv6 */ + + uint8 flags; + uint8 reserved1; + uint8 reserved2; + uint8 reserved3; + uint8 icmp6data[16]; + uint8 options[1]; + +#endif /* !CONFIG_NET_IPv6 */ +}; + +/* The structure holding the ICMP statistics that are gathered if + * CONFIG_NET_STATISTICS is defined. + */ + +#ifdef CONFIG_NET_STATISTICS +struct uip_icmp_stats_s +{ + uip_stats_t drop; /* Number of dropped ICMP packets */ + uip_stats_t recv; /* Number of received ICMP packets */ + uip_stats_t sent; /* Number of sent ICMP packets */ + uip_stats_t typeerr; /* Number of ICMP packets with a wrong type */ +}; +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#endif /* __NET_UIP_UIP_ICMP_H */ diff --git a/nuttx/include/net/uip/uip-tcp.h b/nuttx/include/net/uip/uip-tcp.h new file mode 100644 index 000000000..8d7db5c35 --- /dev/null +++ b/nuttx/include/net/uip/uip-tcp.h @@ -0,0 +1,361 @@ +/**************************************************************************** + * net/uip/uip-tcp.h + * Header file for the uIP TCP/IP stack. + * + * 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) 2007 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * This logic was leveraged from uIP which also has a BSD-style license: + * + * Author Adam Dunkels <adam@dunkels.com> + * 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 + * 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. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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_UIP_TCP_H +#define __NET_UIP_UIP_TCP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#ifdef CONFIG_NET_TCP + +#include <sys/types.h> +#include <net/uip/uipopt.h> + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/* The TCP states used in the struct uip_conn tcpstateflags field */ + +#define UIP_CLOSED 0 /* The connection is not in use and available */ +#define UIP_ALLOCATED 1 /* The connection is allocated, but not yet initialized */ +#define UIP_SYN_RCVD 2 +#define UIP_SYN_SENT 3 +#define UIP_ESTABLISHED 4 +#define UIP_FIN_WAIT_1 5 +#define UIP_FIN_WAIT_2 6 +#define UIP_CLOSING 7 +#define UIP_TIME_WAIT 8 +#define UIP_LAST_ACK 9 + +#define UIP_TS_MASK 15 +#define UIP_STOPPED 16 + +/* Header sizes */ + +#define UIP_TCPH_LEN 20 /* Size of TCP header */ +#define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP + TCP header */ +#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/* Representation of a uIP TCP connection. + * + * The uip_conn structure is used for identifying a connection. All + * but one field in the structure are to be considered read-only by an + * application. The only exception is the "private: field whos purpose + * is to let the application store application-specific state (e.g., + * file pointers) for the connection. + */ + +struct uip_driver_s; /* Forward reference */ +struct uip_conn +{ + dq_entry_t node; /* Implements a doubly linked list */ +#if 0 /* Not used */ + uip_ipaddr_t lipaddr; /* The local IP address */ +#endif + uip_ipaddr_t ripaddr; /* The IP address of the remote host */ + uint16 lport; /* The local TCP port, in network byte order */ + uint16 rport; /* The remoteTCP port, in network byte order */ + uint8 rcv_nxt[4]; /* The sequence number that we expect to + * receive next */ + uint8 snd_nxt[4]; /* The sequence number that was last sent by us */ + uint16 len; /* Length of the data that was previously sent */ + uint16 mss; /* Current maximum segment size for the + * connection */ + uint16 initialmss; /* Initial maximum segment size for the + * connection */ + uint8 sa; /* Retransmission time-out calculation state + * variable */ + uint8 sv; /* Retransmission time-out calculation state + * variable */ + uint8 rto; /* Retransmission time-out */ + uint8 tcpstateflags; /* TCP state and flags */ + uint8 timer; /* The retransmission timer (units: half-seconds) */ + uint8 nrtx; /* The number of retransmissions for the last + * segment sent */ + + /* Read-ahead buffering */ + +#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 + sq_queue_t readahead; +#endif + + /* Higher level logic can retain application specific information + * in the following: + * + * data_event() is called on all events. Normally, the input flags are + * returned, however, the implemenation may set one of the following: + * + * UIP_CLOSE - Gracefully close the current connection + * UIP_ABORT - Abort (reset) the current connection on an error that + * prevents UIP_CLOSE from working. + * + * Or clear the following: + * + * UIP_NEWDATA - May be cleared to suppress returning the ACK response. + * (dev->d_len should also be set to zero in this case). + * + * accept() is called when the TCP logic has created a connection + * connection_event() is called on any of the subset of connection-related events + */ + + void *data_private; + uint8 (*data_event)(struct uip_driver_s *dev, struct uip_conn *conn, uint8 flags); + + void *accept_private; + int (*accept)(struct uip_conn *listener, struct uip_conn *conn); + + void *connection_private; + void (*connection_event)(struct uip_conn *conn, uint8 flags); +}; + +/* The following structure is used to handle read-ahead buffering for TCP + * connection. When incoming TCP data is received while no application is + * listening for the data, that data will be retained in these read-ahead + * buffers so that no data is lost. + */ + +#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 +struct uip_readahead_s +{ + sq_entry_t rh_node; /* Supports a singly linked list */ + uint16 rh_nbytes; /* Number of bytes available in this buffer */ + uint8 rh_buffer[CONFIG_NET_TCP_READAHEAD_BUFSIZE]; +}; +#endif + +/* The structure holding the TCP/IP statistics that are gathered if + * CONFIG_NET_STATISTICS is defined. + */ + +#ifdef CONFIG_NET_STATISTICS +struct uip_tcp_stats_s +{ + uip_stats_t drop; /* Number of dropped TCP segments */ + uip_stats_t recv; /* Number of received TCP segments */ + uip_stats_t sent; /* Number of sent TCP segments */ + uip_stats_t chkerr; /* Number of TCP segments with a bad checksum */ + uip_stats_t ackerr; /* Number of TCP segments with a bad ACK number */ + uip_stats_t rst; /* Number of recevied TCP RST (reset) segments */ + uip_stats_t rexmit; /* Number of retransmitted TCP segments */ + uip_stats_t syndrop; /* Number of dropped SYNs due to too few + available connections */ + uip_stats_t synrst; /* Number of SYNs for closed ports triggering a RST */ +}; +#endif + +/* The TCP and IP headers */ + +struct uip_tcpip_hdr +{ +#ifdef CONFIG_NET_IPv6 + + /* IPv6 Ip header */ + + uint8 vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */ + uint8 tcf; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */ + uint16 flow; /* 16-bit flow label (LS) */ + uint8 len[2]; /* 16-bit Payload length */ + uint8 proto; /* 8-bit Next header (same as IPv4 protocol field) */ + uint8 ttl; /* 8-bit Hop limit (like IPv4 TTL field) */ + uip_ip6addr_t srcipaddr; /* 128-bit Source address */ + uip_ip6addr_t destipaddr; /* 128-bit Destination address */ + +#else /* CONFIG_NET_IPv6 */ + + /* IPv4 IP header */ + + uint8 vhl; /* 8-bit Version (4) and header length (5 or 6) */ + uint8 tos; /* 8-bit Type of service (e.g., 6=TCP) */ + uint8 len[2]; /* 16-bit Total length */ + uint8 ipid[2]; /* 16-bit Identification */ + uint8 ipoffset[2]; /* 16-bit IP flags + fragment offset */ + uint8 ttl; /* 8-bit Time to Live */ + uint8 proto; /* 8-bit Protocol */ + uint16 ipchksum; /* 16-bit Header checksum */ + uint16 srcipaddr[2]; /* 32-bit Source IP address */ + uint16 destipaddr[2]; /* 32-bit Destination IP address */ + +#endif /* CONFIG_NET_IPv6 */ + + /* TCP header */ + + uint16 srcport; + uint16 destport; + uint8 seqno[4]; + uint8 ackno[4]; + uint8 tcpoffset; + uint8 flags; + uint8 wnd[2]; + uint16 tcpchksum; + uint8 urgp[2]; + uint8 optdata[4]; +}; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/* uIP application functions + * + * Functions used by an application running of top of uIP. This includes + * functions for opening and closing connections, sending and receiving + * data, etc. + * + * Find a free connection structure and allocate it for use. This is + * normally something done by the implementation of the socket() API + */ + +extern struct uip_conn *uip_tcpalloc(void); + +/* Free a connection structure that is no longer in use. This should + * be done by the implementation of close() + */ + +extern void uip_tcpfree(struct uip_conn *conn); + +/* Bind a TCP connection to a local address */ + +#ifdef CONFIG_NET_IPv6 +extern int uip_tcpbind(struct uip_conn *conn, const struct sockaddr_in6 *addr); +#else +extern int uip_tcpbind(struct uip_conn *conn, const struct sockaddr_in *addr); +#endif + +/* This function implements the UIP specific parts of the standard + * TCP connect() operation: It connects to a remote host using TCP. + * + * This function is used to start a new connection to the specified + * port on the specied host. It uses the connection structure that was + * allocated by a preceding socket() call. It sets the connection to + * the SYN_SENT state and sets the retransmission timer to 0. This will + * cause a TCP SYN segment to be sent out the next time this connection + * is periodically processed, which usually is done within 0.5 seconds + * after the call to uip_tcpconnect(). + * + * This function is called from normal user level code. + */ + +#ifdef CONFIG_NET_IPv6 +extern int uip_tcpconnect(struct uip_conn *conn, const struct sockaddr_in6 *addr); +#else +extern int uip_tcpconnect(struct uip_conn *conn, const struct sockaddr_in *addr); +#endif + +/* Start listening to the port bound to the specified TCP connection */ + +extern int uip_listen(struct uip_conn *conn); + +/* Stop listening to the port bound to the specified TCP connection */ + +extern int uip_unlisten(struct uip_conn *conn); + +/* Check if a connection has outstanding (i.e., unacknowledged) data */ + +#define uip_outstanding(conn) ((conn)->len) + +/* Access to TCP read-ahead buffers */ + +#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 +extern struct uip_readahead_s *uip_tcpreadaheadalloc(void); +extern void uip_tcpreadaheadrelease(struct uip_readahead_s *buf); +#endif /* CONFIG_NET_NTCP_READAHEAD_BUFFERS */ + +/* Tell the sending host to stop sending data. + * + * This function will close our receiver's window so that we stop + * receiving data for the current connection. + */ + +#define uip_stop(conn) ((conn)->tcpstateflags |= UIP_STOPPED) + +/* Find out if the current connection has been previously stopped with + * uip_stop(). + */ + +#define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED) + +/* Restart the current connection, if is has previously been stopped + * with uip_stop(). + * + * This function will open the receiver's window again so that we + * start receiving data for the current connection. + */ + +#define uip_restart(conn,f) \ + do { \ + (f) |= UIP_NEWDATA; \ + (conn)->tcpstateflags &= ~UIP_STOPPED; \ + } while(0) + +/* Get the initial maxium segment size (MSS) of the current + * connection. + */ + +#define uip_initialmss(conn) ((conn)->initialmss) + +/* Get the current maxium segment size that can be sent on the current + * connection. + * + * The current maxiumum segment size that can be sent on the + * connection is computed from the receiver's window and the MSS of + * the connection (which also is available by calling + * uip_initialmss()). + */ + +#define uip_mss(conn) ((conn)->mss) + +#endif /* CONFIG_NET_TCP */ +#endif /* __NET_UIP_UIP_TCP_H */ diff --git a/nuttx/include/net/uip/uip-udp.h b/nuttx/include/net/uip/uip-udp.h new file mode 100644 index 000000000..e7a5b1766 --- /dev/null +++ b/nuttx/include/net/uip/uip-udp.h @@ -0,0 +1,199 @@ +/**************************************************************************** + * net/uip/uip-udp.h + * Header file for the uIP UDP stack. + * + * The uIP UDP stack header file contains definitions for a number + * of C macros that are used by uIP programs as well as internal uIP + * structures, UDP header structures and function declarations. + * + * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * This logic was leveraged from uIP which also has a BSD-style license: + * + * Author Adam Dunkels <adam@dunkels.com> + * 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 + * 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. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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_UIP_UDP_H +#define __NET_UIP_UIP_UDP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> +#include <sys/types.h> +#include <net/uip/uipopt.h> + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/* Header sizes */ + +#define UIP_UDPH_LEN 8 /* Size of UDP header */ +#define UIP_IPUDPH_LEN (UIP_UDPH_LEN + UIP_IPH_LEN) /* Size of IP + UDP header */ + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/* Representation of a uIP UDP connection */ + +struct uip_driver_s; /* Forward reference */ +struct uip_udp_conn +{ + dq_entry_t node; /* Supports a doubly linked list */ + uip_ipaddr_t ripaddr; /* The IP address of the remote peer */ + uint16 lport; /* The local port number in network byte order */ + uint16 rport; /* The remote port number in network byte order */ + uint8 ttl; /* Default time-to-live */ + + /* Defines the UDP callback */ + + void *private; + void (*event)(struct uip_driver_s *dev, struct uip_udp_conn *conn, uint8 flags); +}; + +/* The UDP and IP headers */ + +struct uip_udpip_hdr +{ +#ifdef CONFIG_NET_IPv6 + + /* IPv6 Ip header */ + + uint8 vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */ + uint8 tcf; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */ + uint16 flow; /* 16-bit flow label (LS) */ + uint8 len[2]; /* 16-bit Payload length */ + uint8 proto; /* 8-bit Next header (same as IPv4 protocol field) */ + uint8 ttl; /* 8-bit Hop limit (like IPv4 TTL field) */ + uip_ip6addr_t srcipaddr; /* 128-bit Source address */ + uip_ip6addr_t destipaddr; /* 128-bit Destination address */ + +#else /* CONFIG_NET_IPv6 */ + + /* IPv4 header */ + + uint8 vhl; /* 8-bit Version (4) and header length (5 or 6) */ + uint8 tos; /* 8-bit Type of service (e.g., 6=TCP) */ + uint8 len[2]; /* 16-bit Total length */ + uint8 ipid[2]; /* 16-bit Identification */ + uint8 ipoffset[2]; /* 16-bit IP flags + fragment offset */ + uint8 ttl; /* 8-bit Time to Live */ + uint8 proto; /* 8-bit Protocol */ + uint16 ipchksum; /* 16-bit Header checksum */ + uint16 srcipaddr[2]; /* 32-bit Source IP address */ + uint16 destipaddr[2]; /* 32-bit Destination IP address */ + +#endif /* CONFIG_NET_IPv6 */ + + /* UDP header */ + + uint16 srcport; + uint16 destport; + uint16 udplen; + uint16 udpchksum; +}; + +/* The structure holding the UDP statistics that are gathered if + * CONFIG_NET_STATISTICS is defined. + */ + +#ifdef CONFIG_NET_STATISTICS +struct uip_udp_stats_s +{ + uip_stats_t drop; /* Number of dropped UDP segments */ + uip_stats_t recv; /* Number of recived UDP segments */ + uip_stats_t sent; /* Number of sent UDP segments */ + uip_stats_t chkerr; /* Number of UDP segments with a bad checksum */ +}; +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/* uIP application functions + * + * Functions used by an application running of top of uIP. This includes + * functions for opening and closing connections, sending and receiving + * data, etc. + * + * Find a free connection structure and allocate it for use. This is + * normally something done by the implementation of the socket() API + */ + +extern struct uip_udp_conn *uip_udpalloc(void); + +/* Free a connection structure that is no longer in use. This should + * be done by the implementation of close() + */ + +extern void uip_udpfree(struct uip_udp_conn *conn); + +/* Bind a UDP connection to a local address */ + +#ifdef CONFIG_NET_IPv6 +extern int uip_udpbind(struct uip_udp_conn *conn, const struct sockaddr_in6 *addr); +#else +extern int uip_udpbind(struct uip_udp_conn *conn, const struct sockaddr_in *addr); +#endif + +/* This function sets up a new UDP connection. The function will + * automatically allocate an unused local port for the new + * connection. However, another port can be chosen by using the + * uip_udpbind() call, after the uip_udpconnect() function has been + * called. + * + * This function is called as part of the implementation of sendto + * and recvfrom. + * + * addr The address of the remote host. + */ + +#ifdef CONFIG_NET_IPv6 +extern int uip_udpconnect(struct uip_udp_conn *conn, const struct sockaddr_in6 *addr); +#else +extern int uip_udpconnect(struct uip_udp_conn *conn, const struct sockaddr_in *addr); +#endif + +/* Enable/disable UDP callbacks on a connection */ + +extern void uip_udpenable(struct uip_udp_conn *conn); +extern void uip_udpdisable(struct uip_udp_conn *conn); + +#endif /* __NET_UIP_UIP_UDP_H */ diff --git a/nuttx/include/net/uip/uip.h b/nuttx/include/net/uip/uip.h index 59bd615bc..e2f171253 100644 --- a/nuttx/include/net/uip/uip.h +++ b/nuttx/include/net/uip/uip.h @@ -1,10 +1,9 @@ /**************************************************************************** - * uip.h - * Header file for the uIP TCP/IP stack. + * net/uip/uip.h * - * 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. + * The uIP header file contains definitions for a number of C macros that + * are used by uIP programs as well as internal uIP structures and function + * declarations. * * Copyright (C) 2007 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> @@ -18,6 +17,7 @@ * 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 @@ -49,11 +49,12 @@ ****************************************************************************/ #include <nuttx/config.h> + #include <sys/types.h> #include <queue.h> #include <arpa/inet.h> -#include <net/uip/uipopt.h> +#include <net/uip/uipopt.h> /**************************************************************************** * Definitions ****************************************************************************/ @@ -85,22 +86,6 @@ #define UIP_DATA_EVENTS (UIP_ACKDATA|UIP_NEWDATA|UIP_REXMIT|UIP_POLL) #define UIP_CONN_EVENTS (UIP_CLOSE|UIP_ABORT|UIP_CONNECTED|UIP_TIMEDOUT) -/* The TCP states used in the struct uip_conn tcpstateflags field */ - -#define UIP_CLOSED 0 /* The connection is not in use and available */ -#define UIP_ALLOCATED 1 /* The connection is allocated, but not yet initialized */ -#define UIP_SYN_RCVD 2 -#define UIP_SYN_SENT 3 -#define UIP_ESTABLISHED 4 -#define UIP_FIN_WAIT_1 5 -#define UIP_FIN_WAIT_2 6 -#define UIP_CLOSING 7 -#define UIP_TIME_WAIT 8 -#define UIP_LAST_ACK 9 - -#define UIP_TS_MASK 15 -#define UIP_STOPPED 16 - /* The buffer size available for user data in the d_buf buffer. * * This macro holds the available size for user data in the @@ -122,16 +107,10 @@ /* Header sizes */ #ifdef CONFIG_NET_IPv6 -# define UIP_IPH_LEN 40 -#else /* CONFIG_NET_IPv6 */ +# define UIP_IPH_LEN 40 /* Size of IP header */ +#else # define UIP_IPH_LEN 20 /* Size of IP header */ -#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 */ -#define UIP_IPTCPH_LEN (UIP_TCPH_LEN + UIP_IPH_LEN) /* Size of IP + TCP header */ -#define UIP_TCPIP_HLEN UIP_IPTCPH_LEN +#endif /**************************************************************************** * Public Type Definitions @@ -144,176 +123,13 @@ typedef uint16 uip_ip6addr_t[8]; #ifdef CONFIG_NET_IPv6 typedef uip_ip6addr_t uip_ipaddr_t; -#else /* CONFIG_NET_IPv6 */ +#else typedef uip_ip4addr_t uip_ipaddr_t; -#endif /* CONFIG_NET_IPv6 */ - -/* Representation of a uIP TCP connection. - * - * The uip_conn structure is used for identifying a connection. All - * but one field in the structure are to be considered read-only by an - * application. The only exception is the "private: field whos purpose - * is to let the application store application-specific state (e.g., - * file pointers) for the connection. - */ - -struct uip_driver_s; /* Forward reference */ -struct uip_conn -{ - dq_entry_t node; /* Implements a doubly linked list */ -#if 0 /* Not used */ - uip_ipaddr_t lipaddr; /* The local IP address */ -#endif - uip_ipaddr_t ripaddr; /* The IP address of the remote host */ - uint16 lport; /* The local TCP port, in network byte order */ - uint16 rport; /* The remoteTCP port, in network byte order */ - uint8 rcv_nxt[4]; /* The sequence number that we expect to - * receive next */ - uint8 snd_nxt[4]; /* The sequence number that was last sent by us */ - uint16 len; /* Length of the data that was previously sent */ - uint16 mss; /* Current maximum segment size for the - * connection */ - uint16 initialmss; /* Initial maximum segment size for the - * connection */ - uint8 sa; /* Retransmission time-out calculation state - * variable */ - uint8 sv; /* Retransmission time-out calculation state - * variable */ - uint8 rto; /* Retransmission time-out */ - uint8 tcpstateflags; /* TCP state and flags */ - uint8 timer; /* The retransmission timer (units: half-seconds) */ - uint8 nrtx; /* The number of retransmissions for the last - * segment sent */ - - /* Read-ahead buffering */ - -#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 - sq_queue_t readahead; -#endif - - /* Higher level logic can retain application specific information - * in the following: - * - * data_event() is called on all events. Normally, the input flags are - * returned, however, the implemenation may set one of the following: - * - * UIP_CLOSE - Gracefully close the current connection - * UIP_ABORT - Abort (reset) the current connection on an error that - * prevents UIP_CLOSE from working. - * - * Or clear the following: - * - * UIP_NEWDATA - May be cleared to suppress returning the ACK response. - * (dev->d_len should also be set to zero in this case). - * - * accept() is called when the TCP logic has created a connection - * connection_event() is called on any of the subset of connection-related events - */ - - void *data_private; - uint8 (*data_event)(struct uip_driver_s *dev, struct uip_conn *conn, uint8 flags); - - void *accept_private; - int (*accept)(struct uip_conn *listener, struct uip_conn *conn); - - void *connection_private; - void (*connection_event)(struct uip_conn *conn, uint8 flags); -}; - -/* The following structure is used to handle read-ahead buffering for TCP - * connection. When incoming TCP data is received while no application is - * listening for the data, that data will be retained in these read-ahead - * buffers so that no data is lost. - */ - -#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 -struct uip_readahead_s -{ - sq_entry_t rh_node; /* Supports a singly linked list */ - uint16 rh_nbytes; /* Number of bytes available in this buffer */ - uint8 rh_buffer[CONFIG_NET_TCP_READAHEAD_BUFSIZE]; -}; #endif -#ifdef CONFIG_NET_UDP -/* Representation of a uIP UDP connection */ - -struct uip_udp_conn -{ - dq_entry_t node; /* Supports a doubly linked list */ - uip_ipaddr_t ripaddr; /* The IP address of the remote peer */ - uint16 lport; /* The local port number in network byte order */ - uint16 rport; /* The remote port number in network byte order */ - uint8 ttl; /* Default time-to-live */ - - /* Defines the UDP callback */ - - void *private; - void (*event)(struct uip_driver_s *dev, struct uip_udp_conn *conn, uint8 flags); -}; -#endif /* CONFIG_NET_UDP */ - -/* The structure holding the TCP/IP statistics that are gathered if - * CONFIG_NET_STATISTICS is defined. - */ - -struct uip_stats -{ - struct - { - uip_stats_t drop; /* Number of dropped packets at the IP layer */ - uip_stats_t recv; /* Number of received packets at the IP layer */ - uip_stats_t sent; /* Number of sent packets at the IP layer */ - uip_stats_t vhlerr; /* Number of packets dropped due to wrong - IP version or header length */ - uip_stats_t hblenerr; /* Number of packets dropped due to wrong - IP length, high byte */ - uip_stats_t lblenerr; /* Number of packets dropped due to wrong - IP length, low byte */ - uip_stats_t fragerr; /* Number of packets dropped since they - were IP fragments */ - uip_stats_t chkerr; /* Number of packets dropped due to IP - checksum errors */ - uip_stats_t protoerr; /* Number of packets dropped since they - were neither ICMP, UDP nor TCP */ - } ip; /* IP statistics */ - - struct - { - uip_stats_t drop; /* Number of dropped ICMP packets */ - uip_stats_t recv; /* Number of received ICMP packets */ - uip_stats_t sent; /* Number of sent ICMP packets */ - uip_stats_t typeerr; /* Number of ICMP packets with a wrong type */ - } icmp; /* ICMP statistics */ - - struct - { - uip_stats_t drop; /* Number of dropped TCP segments */ - uip_stats_t recv; /* Number of received TCP segments */ - uip_stats_t sent; /* Number of sent TCP segments */ - uip_stats_t chkerr; /* Number of TCP segments with a bad checksum */ - uip_stats_t ackerr; /* Number of TCP segments with a bad ACK number */ - uip_stats_t rst; /* Number of recevied TCP RST (reset) segments */ - uip_stats_t rexmit; /* Number of retransmitted TCP segments */ - uip_stats_t syndrop; /* Number of dropped SYNs due to too few - available connections */ - uip_stats_t synrst; /* Number of SYNs for closed ports triggering a RST */ - } tcp; /* TCP statistics */ - -#ifdef CONFIG_NET_UDP - struct - { - uip_stats_t drop; /* Number of dropped UDP segments */ - uip_stats_t recv; /* Number of recived UDP segments */ - uip_stats_t sent; /* Number of sent UDP segments */ - uip_stats_t chkerr; /* Number of UDP segments with a bad checksum */ - } udp; /* UDP statistics */ -#endif /* CONFIG_NET_UDP */ -}; - -/* The TCP and IP headers */ +/* The IP header */ -struct uip_tcpip_hdr +struct uip_ip_hdr { #ifdef CONFIG_NET_IPv6 @@ -344,119 +160,55 @@ struct uip_tcpip_hdr uint16 destipaddr[2]; /* 32-bit Destination IP address */ #endif /* CONFIG_NET_IPv6 */ - - /* TCP header */ - - uint16 srcport; - uint16 destport; - uint8 seqno[4]; - uint8 ackno[4]; - uint8 tcpoffset; - uint8 flags; - uint8 wnd[2]; - uint16 tcpchksum; - uint8 urgp[2]; - uint8 optdata[4]; }; -/* The ICMP and IP headers */ - -struct uip_icmpip_hdr -{ -#ifdef CONFIG_NET_IPv6 - - /* IPv6 Ip header */ - - uint8 vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */ - uint8 tcf; /* Bits 0-3: traffic class (LS), bits 4-7: flow label (MS) */ - uint16 flow; /* 16-bit flow label (LS) */ - uint8 len[2]; /* 16-bit Payload length */ - uint8 proto; /* 8-bit Next header (same as IPv4 protocol field) */ - uint8 ttl; /* 8-bit Hop limit (like IPv4 TTL field) */ - uip_ip6addr_t srcipaddr; /* 128-bit Source address */ - uip_ip6addr_t destipaddr; /* 128-bit Destination address */ - -#else /* CONFIG_NET_IPv6 */ - - /* IPv4 IP header */ - - uint8 vhl; /* 8-bit Version (4) and header length (5 or 6) */ - uint8 tos; /* 8-bit Type of service (e.g., 6=TCP) */ - uint8 len[2]; /* 16-bit Total length */ - uint8 ipid[2]; /* 16-bit Identification */ - uint8 ipoffset[2]; /* 16-bit IP flags + fragment offset */ - uint8 ttl; /* 8-bit Time to Live */ - uint8 proto; /* 8-bit Protocol */ - uint16 ipchksum; /* 16-bit Header checksum */ - uint16 srcipaddr[2]; /* 32-bit Source IP address */ - uint16 destipaddr[2]; /* 32-bit Destination IP address */ - -#endif /* CONFIG_NET_IPv6 */ - - /* ICMP (echo) header */ - - uint8 type; - uint8 icode; - uint16 icmpchksum; +/* Protocol-specific support */ -#ifndef CONFIG_NET_IPv6 - - uint16 id; - uint16 seqno; - -#else /* !CONFIG_NET_IPv6 */ +#include <net/uip/uip-tcp.h> +#include <net/uip/uip-udp.h> +#include <net/uip/uip-icmp.h> - uint8 flags; - uint8 reserved1; - uint8 reserved2; - uint8 reserved3; - uint8 icmp6data[16]; - uint8 options[1]; +/* The structure holding the uIP statistics that are gathered if + * CONFIG_NET_STATISTICS is defined. + */ -#endif /* !CONFIG_NET_IPv6 */ +#ifdef CONFIG_NET_STATISTICS +struct uip_ip_stats_s +{ + uip_stats_t drop; /* Number of dropped packets at the IP layer */ + uip_stats_t recv; /* Number of received packets at the IP layer */ + uip_stats_t sent; /* Number of sent packets at the IP layer */ + uip_stats_t vhlerr; /* Number of packets dropped due to wrong + IP version or header length */ + uip_stats_t hblenerr; /* Number of packets dropped due to wrong + IP length, high byte */ + uip_stats_t lblenerr; /* Number of packets dropped due to wrong + IP length, low byte */ + uip_stats_t fragerr; /* Number of packets dropped since they + were IP fragments */ + uip_stats_t chkerr; /* Number of packets dropped due to IP + checksum errors */ + uip_stats_t protoerr; /* Number of packets dropped since they + were neither ICMP, UDP nor TCP */ }; -/* The UDP and IP headers */ - -struct uip_udpip_hdr +struct uip_stats { -#ifdef CONFIG_NET_IPv6 - - /* IPv6 Ip header */ + struct uip_ip_stats_s ip; /* IP statistics */ - uint8 vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */ - uint8 tcf; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */ - uint16 flow; /* 16-bit flow label (LS) */ - uint8 len[2]; /* 16-bit Payload length */ - uint8 proto; /* 8-bit Next header (same as IPv4 protocol field) */ - uint8 ttl; /* 8-bit Hop limit (like IPv4 TTL field) */ - uip_ip6addr_t srcipaddr; /* 128-bit Source address */ - uip_ip6addr_t destipaddr; /* 128-bit Destination address */ - -#else /* CONFIG_NET_IPv6 */ - - /* IPv4 header */ - - uint8 vhl; /* 8-bit Version (4) and header length (5 or 6) */ - uint8 tos; /* 8-bit Type of service (e.g., 6=TCP) */ - uint8 len[2]; /* 16-bit Total length */ - uint8 ipid[2]; /* 16-bit Identification */ - uint8 ipoffset[2]; /* 16-bit IP flags + fragment offset */ - uint8 ttl; /* 8-bit Time to Live */ - uint8 proto; /* 8-bit Protocol */ - uint16 ipchksum; /* 16-bit Header checksum */ - uint16 srcipaddr[2]; /* 32-bit Source IP address */ - uint16 destipaddr[2]; /* 32-bit Destination IP address */ - -#endif /* CONFIG_NET_IPv6 */ +#ifdef CONFIG_NET_ICMP + struct uip_icmp_stats_s icmp; /* ICMP statistics */ +#endif - /* UDP header */ +#ifdef CONFIG_NET_TCP + struct uip_tcp_stats_s tcp; /* TCP statistics */ +#endif - uint16 srcport; - uint16 destport; - uint16 udplen; - uint16 udpchksum; +#ifdef CONFIG_NET_UDP + struct uip_udp_stats_s udp; /* UDP statistics */ +#endif }; +#endif /* CONFIG_NET_STATISTICS */ /* Representation of a 48-bit Ethernet address */ @@ -469,18 +221,11 @@ struct uip_eth_addr * Public Data ****************************************************************************/ -/* The current UDP connection */ - -#ifdef CONFIG_NET_UDP -extern struct uip_udp_conn *uip_udp_conn; -#endif /* CONFIG_NET_UDP */ - -/* The uIP TCP/IP statistics. - * - * This is the variable in which the uIP TCP/IP statistics are gathered. - */ +/* This is the structure in which the statistics are gathered. */ +#ifdef CONFIG_NET_STATISTICS extern struct uip_stats uip_stat; +#endif /**************************************************************************** * Public Function Prototypes @@ -505,65 +250,8 @@ extern void uip_setipid(uint16 id); * Functions used by an application running of top of uIP. This includes * functions for opening and closing connections, sending and receiving * data, etc. - * - * Find a free connection structure and allocate it for use. This is - * normally something done by the implementation of the socket() API - */ - -extern struct uip_conn *uip_tcpalloc(void); -#ifdef CONFIG_NET_UDP -extern struct uip_udp_conn *uip_udpalloc(void); -#endif - -/* Free a connection structure that is no longer in use. This should - * be done by the implementation of close() - */ - -extern void uip_tcpfree(struct uip_conn *conn); -#ifdef CONFIG_NET_UDP -extern void uip_udpfree(struct uip_udp_conn *conn); -#endif - -/* Bind a TCP connection to a local address */ - -#ifdef CONFIG_NET_IPv6 -extern int uip_tcpbind(struct uip_conn *conn, const struct sockaddr_in6 *addr); -#else -extern int uip_tcpbind(struct uip_conn *conn, const struct sockaddr_in *addr); -#endif - -/* This function implements the UIP specific parts of the standard - * TCP connect() operation: It connects to a remote host using TCP. - * - * This function is used to start a new connection to the specified - * port on the specied host. It uses the connection structure that was - * allocated by a preceding socket() call. It sets the connection to - * the SYN_SENT state and sets the retransmission timer to 0. This will - * cause a TCP SYN segment to be sent out the next time this connection - * is periodically processed, which usually is done within 0.5 seconds - * after the call to uip_tcpconnect(). - * - * This function is called from normal user level code. */ -#ifdef CONFIG_NET_IPv6 -extern int uip_tcpconnect(struct uip_conn *conn, const struct sockaddr_in6 *addr); -#else -extern int uip_tcpconnect(struct uip_conn *conn, const struct sockaddr_in *addr); -#endif - -/* Start listening to the port bound to the specified TCP connection */ - -extern int uip_listen(struct uip_conn *conn); - -/* Stop listening to the port bound to the specified TCP connection */ - -extern int uip_unlisten(struct uip_conn *conn); - -/* Check if a connection has outstanding (i.e., unacknowledged) data */ - -#define uip_outstanding(conn) ((conn)->len) - /* Send data on the current connection. * * This function is used to send out a single segment of TCP @@ -589,13 +277,6 @@ extern int uip_unlisten(struct uip_conn *conn); extern void uip_send(struct uip_driver_s *dev, const void *buf, int len); -/* Access to TCP read-ahead buffers */ - -#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 -extern struct uip_readahead_s *uip_tcpreadaheadalloc(void); -extern void uip_tcpreadaheadrelease(struct uip_readahead_s *buf); -#endif /* CONFIG_NET_NTCP_READAHEAD_BUFFERS */ - /* The length of any incoming data that is currently avaliable (if avaliable) * in the d_appdata buffer. * @@ -605,34 +286,6 @@ extern void uip_tcpreadaheadrelease(struct uip_readahead_s *buf); #define uip_datalen(dev) ((dev)->d_len) -/* Tell the sending host to stop sending data. - * - * This function will close our receiver's window so that we stop - * receiving data for the current connection. - */ - -#define uip_stop(conn) ((conn)->tcpstateflags |= UIP_STOPPED) - -/* Find out if the current connection has been previously stopped with - * uip_stop(). - */ - -#define uip_stopped(conn) ((conn)->tcpstateflags & UIP_STOPPED) - -/* Restart the current connection, if is has previously been stopped - * with uip_stop(). - * - * This function will open the receiver's window again so that we - * start receiving data for the current connection. - */ - -#define uip_restart(conn,f) \ - do { \ - (f) |= UIP_NEWDATA; \ - (conn)->tcpstateflags &= ~UIP_STOPPED; \ - } while(0) - - /* uIP tests that can be made to determine in what state the current * connection is, and what the application function should do. * @@ -710,54 +363,6 @@ extern void uip_tcpreadaheadrelease(struct uip_readahead_s *buf); #define uip_poll_event(f) ((f) & UIP_POLL) -/* Get the initial maxium segment size (MSS) of the current - * connection. - */ - -#define uip_initialmss(conn) ((conn)->initialmss) - -/* Get the current maxium segment size that can be sent on the current - * connection. - * - * The current maxiumum segment size that can be sent on the - * connection is computed from the receiver's window and the MSS of - * the connection (which also is available by calling - * uip_initialmss()). - */ - -#define uip_mss(conn) ((conn)->mss) - -/* Bind a UDP connection to a local address */ - -#ifdef CONFIG_NET_IPv6 -extern int uip_udpbind(struct uip_udp_conn *conn, const struct sockaddr_in6 *addr); -#else -extern int uip_udpbind(struct uip_udp_conn *conn, const struct sockaddr_in *addr); -#endif - -/* This function sets up a new UDP connection. The function will - * automatically allocate an unused local port for the new - * connection. However, another port can be chosen by using the - * uip_udpbind() call, after the uip_udpconnect() function has been - * called. - * - * This function is called as part of the implementation of sendto - * and recvfrom. - * - * addr The address of the remote host. - */ - -#ifdef CONFIG_NET_IPv6 -extern int uip_udpconnect(struct uip_udp_conn *conn, const struct sockaddr_in6 *addr); -#else -extern int uip_udpconnect(struct uip_udp_conn *conn, const struct sockaddr_in *addr); -#endif - -/* Enable/disable UDP callbacks on a connection */ - -extern void uip_udpenable(struct uip_udp_conn *conn); -extern void uip_udpdisable(struct uip_udp_conn *conn); - /* uIP convenience and converting functions. * * These functions can be used for converting between different data diff --git a/nuttx/net/Makefile b/nuttx/net/Makefile index e429d6236..082b0a0d7 100644 --- a/nuttx/net/Makefile +++ b/nuttx/net/Makefile @@ -40,8 +40,12 @@ MKDEP = $(TOPDIR)/tools/mkdeps.sh ifeq ($(CONFIG_NET),y) SOCK_ASRCS = -SOCK_CSRCS = socket.c bind.c connect.c listen.c accept.c send.c sendto.c \ - recv.c recvfrom.c net-sockets.c net-close.c +SOCK_CSRCS = socket.c bind.c connect.c sendto.c recv.c recvfrom.c \ + net-sockets.c net-close.c + +ifeq ($(CONFIG_NET_TCP),y) +SOCK_CSRCS += send.c listen.c accept.c +endif ifeq ($(CONFIG_NET_SOCKOPTS),y) SOCK_CSRCS += setsockopt.c getsockopt.c diff --git a/nuttx/net/accept.c b/nuttx/net/accept.c index 02557d6fc..a348953f6 100644 --- a/nuttx/net/accept.c +++ b/nuttx/net/accept.c @@ -38,7 +38,7 @@ ****************************************************************************/ #include <nuttx/config.h> -#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 +#if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 && defined(CONFIG_NET_TCP) #include <sys/types.h> #include <sys/socket.h> @@ -354,4 +354,4 @@ errout: return ERROR; } -#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS */ +#endif /* CONFIG_NET && CONFIG_NSOCKET_DESCRIPTORS && CONFIG_NET_TCP*/ diff --git a/nuttx/net/bind.c b/nuttx/net/bind.c index f5d36a9f1..d75245c8a 100644 --- a/nuttx/net/bind.c +++ b/nuttx/net/bind.c @@ -85,11 +85,15 @@ int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { FAR struct socket *psock = sockfd_socket(sockfd); + +#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_UDP) #ifdef CONFIG_NET_IPv6 FAR const struct sockaddr_in6 *inaddr = (const struct sockaddr_in6 *)addr; #else FAR const struct sockaddr_in *inaddr = (const struct sockaddr_in *)addr; #endif +#endif + int err; int ret; @@ -117,16 +121,19 @@ int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen) switch (psock->s_type) { +#ifdef CONFIG_NET_TCP case SOCK_STREAM: ret = uip_tcpbind(psock->s_conn, inaddr); psock->s_flags |= _SF_BOUND; break; +#endif #ifdef CONFIG_NET_UDP case SOCK_DGRAM: ret = uip_udpbind(psock->s_conn, inaddr); break; #endif + default: err = EBADF; goto errout; diff --git a/nuttx/net/connect.c b/nuttx/net/connect.c index d4f40b30f..c0c722e99 100644 --- a/nuttx/net/connect.c +++ b/nuttx/net/connect.c @@ -54,17 +54,20 @@ * Private Types ****************************************************************************/ +#ifdef CONFIG_NET_TCP struct tcp_connect_s { FAR struct uip_conn *tc_conn; /* Reference to TCP connection structure */ sem_t tc_sem; /* Semaphore signals recv completion */ int tc_result; /* OK on success, otherwise a negated errno. */ }; +#endif /**************************************************************************** * Private Function Prototypes ****************************************************************************/ +#ifdef CONFIG_NET_TCP static void connection_event(struct uip_conn *conn, uint8 flags); static inline void tcp_setup_callbacks(struct uip_conn *conn, FAR struct socket *psock, FAR struct tcp_connect_s *pstate); @@ -76,6 +79,7 @@ static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in #else static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in *inaddr); #endif +#endif /* CONFIG_NET_TCP */ /**************************************************************************** * Private Functions @@ -99,6 +103,7 @@ static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in * ****************************************************************************/ +#ifdef CONFIG_NET_TCP static void connection_event(struct uip_conn *conn, uint8 flags) { FAR struct socket *psock = (FAR struct socket *)conn->connection_private; @@ -128,11 +133,13 @@ static void connection_event(struct uip_conn *conn, uint8 flags) } } } +#endif /* CONFIG_NET_TCP */ /**************************************************************************** * Function: tcp_setup_callbacks ****************************************************************************/ +#ifdef CONFIG_NET_TCP static inline void tcp_setup_callbacks(struct uip_conn *conn, FAR struct socket *psock, FAR struct tcp_connect_s *pstate) { @@ -146,11 +153,13 @@ static inline void tcp_setup_callbacks(struct uip_conn *conn, FAR struct socket conn->connection_private = (void*)psock; conn->connection_event = connection_event; } +#endif /* CONFIG_NET_TCP */ /**************************************************************************** * Function: tcp_teardown_callbacks ****************************************************************************/ +#ifdef CONFIG_NET_TCP static inline void tcp_teardown_callbacks(struct uip_conn *conn, int status) { /* Make sure that no further interrupts are processed */ @@ -170,6 +179,7 @@ static inline void tcp_teardown_callbacks(struct uip_conn *conn, int status) conn->connection_event = NULL; } } +#endif /* CONFIG_NET_TCP */ /**************************************************************************** * Function: tcp_connect_interrupt @@ -191,6 +201,7 @@ static inline void tcp_teardown_callbacks(struct uip_conn *conn, int status) * ****************************************************************************/ +#ifdef CONFIG_NET_TCP static uint8 tcp_connect_interrupt(struct uip_driver_s *dev, struct uip_conn *conn, uint8 flags) { @@ -262,6 +273,7 @@ static uint8 tcp_connect_interrupt(struct uip_driver_s *dev, return flags; } +#endif /* CONFIG_NET_TCP */ /**************************************************************************** * Function: tcp_connect @@ -281,6 +293,7 @@ static uint8 tcp_connect_interrupt(struct uip_driver_s *dev, * ****************************************************************************/ +#ifdef CONFIG_NET_TCP #ifdef CONFIG_NET_IPv6 static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in6 *inaddr) #else @@ -367,6 +380,7 @@ static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in irqrestore(flags); return ret; } +#endif /* CONFIG_NET_TCP */ /**************************************************************************** * Public Functions @@ -443,13 +457,17 @@ static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { FAR struct socket *psock = sockfd_socket(sockfd); + +#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_UDP) #ifdef CONFIG_NET_IPv6 FAR const struct sockaddr_in6 *inaddr = (const struct sockaddr_in6 *)addr; #else FAR const struct sockaddr_in *inaddr = (const struct sockaddr_in *)addr; #endif - int err; int ret; +#endif + + int err; /* Verify that the sockfd corresponds to valid, allocated socket */ @@ -475,6 +493,7 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) switch (psock->s_type) { +#ifdef CONFIG_NET_TCP case SOCK_STREAM: { /* Verify that the socket is not already connected */ @@ -495,6 +514,7 @@ int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) } } break; +#endif #ifdef CONFIG_NET_UDP case SOCK_DGRAM: diff --git a/nuttx/net/net-close.c b/nuttx/net/net-close.c index c06e635d1..76dd7693f 100644 --- a/nuttx/net/net-close.c +++ b/nuttx/net/net-close.c @@ -83,6 +83,7 @@ int net_close(int sockfd) switch (psock->s_type) { +#ifdef CONFIG_NET_TCP case SOCK_STREAM: { struct uip_conn *conn = psock->s_conn; @@ -90,12 +91,14 @@ int net_close(int sockfd) uip_tcpfree(conn); } break; +#endif #ifdef CONFIG_NET_UDP case SOCK_DGRAM: uip_udpfree(psock->s_conn); break; #endif + default: err = -EBADF; goto errout; diff --git a/nuttx/net/recvfrom.c b/nuttx/net/recvfrom.c index 906b5aa6e..0d4e1bf30 100644 --- a/nuttx/net/recvfrom.c +++ b/nuttx/net/recvfrom.c @@ -63,6 +63,7 @@ * Private Types ****************************************************************************/ +#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP) struct recvfrom_s { #if defined(CONFIG_NET_SOCKOPTS) && !defined(CONFIG_DISABLE_CLOCK) @@ -75,6 +76,7 @@ struct recvfrom_s size_t rf_recvlen; /* The received length */ int rf_result; /* OK on success, otherwise a negated errno. */ }; +#endif /* CONFIG_NET_UDP || CONFIG_NET_TCP */ /**************************************************************************** * Private Functions @@ -98,6 +100,7 @@ struct recvfrom_s * ****************************************************************************/ +#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP) static void recvfrom_newdata(struct uip_driver_s *dev, struct recvfrom_s *pstate) { size_t recvlen; @@ -128,6 +131,7 @@ static void recvfrom_newdata(struct uip_driver_s *dev, struct recvfrom_s *pstate dev->d_len = 0; } +#endif /* CONFIG_NET_UDP || CONFIG_NET_TCP */ /**************************************************************************** * Function: recvfrom_readahead @@ -147,7 +151,7 @@ static void recvfrom_newdata(struct uip_driver_s *dev, struct recvfrom_s *pstate * ****************************************************************************/ -#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 +#if defined(CONFIG_NET_TCP) && CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 static inline void recvfrom_readahead(struct recvfrom_s *pstate) { struct uip_conn *conn = (struct uip_conn *)pstate->rf_sock->s_conn; @@ -214,7 +218,7 @@ static inline void recvfrom_readahead(struct recvfrom_s *pstate) } while (readahead && pstate->rf_buflen > 0); } -#endif +#endif /* CONFIG_NET_UDP || CONFIG_NET_TCP */ /**************************************************************************** * Function: recvfrom_timeout @@ -233,6 +237,7 @@ static inline void recvfrom_readahead(struct recvfrom_s *pstate) * ****************************************************************************/ +#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP) #if defined(CONFIG_NET_SOCKOPTS) && !defined(CONFIG_DISABLE_CLOCK) static int recvfrom_timeout(struct recvfrom_s *pstate) { @@ -279,6 +284,7 @@ static int recvfrom_timeout(struct recvfrom_s *pstate) return FALSE; } #endif /* CONFIG_NET_SOCKOPTS && !CONFIG_DISABLE_CLOCK */ +#endif /* CONFIG_NET_UDP || CONFIG_NET_TCP */ /**************************************************************************** * Function: recvfrom_tcpinterrupt @@ -300,6 +306,7 @@ static int recvfrom_timeout(struct recvfrom_s *pstate) * ****************************************************************************/ +#ifdef CONFIG_NET_TCP static uint8 recvfrom_tcpinterrupt(struct uip_driver_s *dev, struct uip_conn *conn, uint8 flags) { @@ -406,6 +413,7 @@ static uint8 recvfrom_tcpinterrupt(struct uip_driver_s *dev, } return flags; } +#endif /* CONFIG_NET_TCP */ /**************************************************************************** * Function: recvfrom_udpinterrupt @@ -508,7 +516,7 @@ static void recvfrom_udpinterrupt(struct uip_driver_s *dev, #endif /* CONFIG_NET_SOCKOPTS && !CONFIG_DISABLE_CLOCK */ } } -#endif +#endif /* CONFIG_NET_UDP */ /**************************************************************************** * Function: recvfrom_init @@ -529,6 +537,7 @@ static void recvfrom_udpinterrupt(struct uip_driver_s *dev, * ****************************************************************************/ +#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP) static void recvfrom_init(FAR struct socket *psock, FAR void *buf, size_t len, struct recvfrom_s *pstate) { @@ -546,6 +555,7 @@ static void recvfrom_init(FAR struct socket *psock, FAR void *buf, size_t len, pstate->rf_starttime = g_system_timer; #endif } +#endif /* CONFIG_NET_UDP || CONFIG_NET_TCP */ /**************************************************************************** * Function: recvfrom_result @@ -564,6 +574,7 @@ static void recvfrom_init(FAR struct socket *psock, FAR void *buf, size_t len, * ****************************************************************************/ +#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP) static ssize_t recvfrom_result(int result, struct recvfrom_s *pstate) { int save_errno = *get_errno_ptr(); /* In case something we do changes it */ @@ -594,6 +605,7 @@ static ssize_t recvfrom_result(int result, struct recvfrom_s *pstate) return pstate->rf_recvlen; } +#endif /* CONFIG_NET_UDP || CONFIG_NET_TCP */ /**************************************************************************** * Function: udp_recvfrom @@ -698,6 +710,7 @@ static ssize_t udp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, * ****************************************************************************/ +#ifdef CONFIG_NET_TCP #ifdef CONFIG_NET_IPv6 static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, FAR const struct sockaddr_in6 *infrom ) @@ -766,6 +779,7 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, #warning "Needs to return server address" return recvfrom_result(ret, &state); } +#endif /* CONFIG_NET_TCP */ /**************************************************************************** * Global Functions @@ -827,11 +841,15 @@ ssize_t recvfrom(int sockfd, FAR void *buf, size_t len, int flags, FAR struct so FAR socklen_t *fromlen) { FAR struct socket *psock; + +#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_TCP) #ifdef CONFIG_NET_IPv6 FAR const struct sockaddr_in6 *infrom = (const struct sockaddr_in6 *)from; #else FAR const struct sockaddr_in *infrom = (const struct sockaddr_in *)from; #endif +#endif + ssize_t ret; int err; @@ -874,17 +892,21 @@ ssize_t recvfrom(int sockfd, FAR void *buf, size_t len, int flags, FAR struct so /* Perform the TCP/IP or UDP recv() operation */ -#ifdef CONFIG_NET_UDP +#if defined(CONFIG_NET_UDP) && defined(CONFIG_NET_TCP) if (psock->s_type == SOCK_STREAM) -#endif { ret = tcp_recvfrom(psock, buf, len, infrom); } -#ifdef CONFIG_NET_UDP else { ret = udp_recvfrom(psock, buf, len, infrom); } +#elif defined(CONFIG_NET_TCP) + ret = tcp_recvfrom(psock, buf, len, infrom); +#elif defined(CONFIG_NET_UDP) + ret = udp_recvfrom(psock, buf, len, infrom); +#else + ret = -ENOSYS; #endif /* Set the socket state to idle */ diff --git a/nuttx/net/send.c b/nuttx/net/send.c index 29633b380..6ded49e0e 100644 --- a/nuttx/net/send.c +++ b/nuttx/net/send.c @@ -38,7 +38,7 @@ ****************************************************************************/ #include <nuttx/config.h> -#ifdef CONFIG_NET +#if defined(CONFIG_NET) && defined(CONFIG_NET_TCP) #include <sys/types.h> #include <sys/socket.h> @@ -358,4 +358,4 @@ errout: return ERROR; } -#endif /* CONFIG_NET */ +#endif /* CONFIG_NET && CONFIG_NET_TCP */ diff --git a/nuttx/net/socket.c b/nuttx/net/socket.c index d7c21d01b..644f5a8c2 100644 --- a/nuttx/net/socket.c +++ b/nuttx/net/socket.c @@ -43,6 +43,7 @@ #include <sys/types.h> #include <sys/socket.h> #include <errno.h> +#include <debug.h> #include "net-internal.h" @@ -106,10 +107,12 @@ int socket(int domain, int type, int protocol) /* Only SOCK_STREAM and possible SOCK_DRAM are supported */ -#ifdef CONFIG_NET_UDP +#if defined(CONFIG_NET_UDP) && defined(CONFIG_NET_TCP) if (protocol != 0 || (type != SOCK_STREAM && type != SOCK_DGRAM)) -#else +#elif defined(CONFIG_NET_TCP) if (protocol != 0 || type != SOCK_STREAM) +#elif defined(CONFIG_NET_UDP) + if (protocol != 0 || type != SOCK_DGRAM) #endif { err = EPROTONOSUPPORT; @@ -128,43 +131,49 @@ int socket(int domain, int type, int protocol) /* Initialize the socket structure */ psock = sockfd_socket(sockfd); - if (psock) + if (!psock) { - /* Save the protocol type */ + err = ENOSYS; /* should not happen */ + goto errout; + } + + /* Save the protocol type */ - psock->s_type = type; - psock->s_conn = NULL; + psock->s_type = type; + psock->s_conn = NULL; - /* Allocate the appropriate connection structure. This reserves the - * the connection structure is is unallocated at this point. It will - * not actually be initialized until the socket is connected. - */ + /* Allocate the appropriate connection structure. This reserves the + * the connection structure is is unallocated at this point. It will + * not actually be initialized until the socket is connected. + */ - switch (type) - { - case SOCK_STREAM: - psock->s_conn = uip_tcpalloc(); - break; + switch (type) + { +#ifdef CONFIG_NET_TCP + case SOCK_STREAM: + psock->s_conn = uip_tcpalloc(); + break; +#endif #ifdef CONFIG_NET_UDP - case SOCK_DGRAM: - psock->s_conn = uip_udpalloc(); - break; + case SOCK_DGRAM: + psock->s_conn = uip_udpalloc(); + break; #endif - default: - break; - } - /* Did we succesfully allocate some kind of connection structure? */ + default: + break; + } + + /* Did we succesfully allocate some kind of connection structure? */ - if (!psock->s_conn) - { - /* Failed to reserve a connection structure */ + if (!psock->s_conn) + { + /* Failed to reserve a connection structure */ - sockfd_release(sockfd); - err = ENFILE; - goto errout; - } + sockfd_release(sockfd); + err = ENFILE; + goto errout; } return sockfd; diff --git a/nuttx/net/uip/Make.defs b/nuttx/net/uip/Make.defs index 4256e72e9..c6a7f4d74 100644 --- a/nuttx/net/uip/Make.defs +++ b/nuttx/net/uip/Make.defs @@ -38,10 +38,10 @@ UIP_CSRCS = ifeq ($(CONFIG_NET),y) -# Common network source files +# Common IP source files UIP_CSRCS += uip-initialize.c uip-setipid.c uip-arp.c uip-input.c uip-send.c \ - uip-fw.c uip-split.c uip-poll.c uip-chksum.c + uip-poll.c uip-chksum.c ifeq ($(CONFIG_NET_IPv6),y) UIP_CSRCS += uip-neighbor.c @@ -49,10 +49,19 @@ endif # TCP source files +ifeq ($(CONFIG_NET_TCP),y) + UIP_CSRCS += uip-tcpconn.c uip-tcppoll.c uip-tcptimer.c uip-tcpsend.c \ uip-tcpinput.c uip-tcpappsend.c uip-listen.c uip-tcpcallback.c \ uip-tcpreadahead.c +# Follow can be used to add support for the "uipsplit uIP TCP throughput booster hack" +# but are not currently used + +UIP_CSRCS += uip-fw.c uip-split.c + +endif + # UDP source files ifeq ($(CONFIG_NET_UDP),y) @@ -64,8 +73,11 @@ endif #ICMP source files +ifeq ($(CONFIG_NET_ICMP),y) + UIP_CSRCS += uip-icmpinput.c endif +endif diff --git a/nuttx/net/uip/uip-arp.c b/nuttx/net/uip/uip-arp.c index 4d95d16d3..9b74d0507 100644 --- a/nuttx/net/uip/uip-arp.c +++ b/nuttx/net/uip/uip-arp.c @@ -364,8 +364,8 @@ void uip_arp_arpin(struct uip_driver_s *dev) uiphdr_ipaddr_copy(ARPBUF->ah_sipaddr, &dev->d_ipaddr); uip_arp_dump(ARPBUF); - ETHBUF->type = HTONS(UIP_ETHTYPE_ARP); - dev->d_len = sizeof(struct arp_hdr) + UIP_LLH_LEN; + ETHBUF->type = HTONS(UIP_ETHTYPE_ARP); + dev->d_len = sizeof(struct arp_hdr) + UIP_LLH_LEN; } break; @@ -482,8 +482,6 @@ void uip_arp_out(struct uip_driver_s *dev) uip_arp_dump(ARPBUF); ETHBUF->type = HTONS(UIP_ETHTYPE_ARP); - - dev->d_appdata = &dev->d_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN]; dev->d_len = sizeof(struct arp_hdr) + UIP_LLH_LEN; return; } diff --git a/nuttx/net/uip/uip-chksum.c b/nuttx/net/uip/uip-chksum.c index 6faaf9817..50602f481 100644 --- a/nuttx/net/uip/uip-chksum.c +++ b/nuttx/net/uip/uip-chksum.c @@ -54,7 +54,7 @@ * Definitions ****************************************************************************/ -#define BUF ((struct uip_tcpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) +#define BUF ((struct uip_ip_hdr *)&dev->d_buf[UIP_LLH_LEN]) /**************************************************************************** * Private Data diff --git a/nuttx/net/uip/uip-initialize.c b/nuttx/net/uip/uip-initialize.c index a3338d082..decc60ff8 100644 --- a/nuttx/net/uip/uip-initialize.c +++ b/nuttx/net/uip/uip-initialize.c @@ -116,6 +116,7 @@ void uip_initialize(void) { /* Initialize the listening port structures */ +#ifdef CONFIG_NET_TCP uip_listeninit(); /* Initialize the TCP/IP connection structures */ @@ -127,14 +128,13 @@ void uip_initialize(void) #if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 uip_tcpreadaheadinit(); #endif +#endif /* CONFIG_NET_TCP */ /* Initialize the UDP connection structures */ #ifdef CONFIG_NET_UDP uip_udpinit(); #endif - - /* IPv4 initialization. */ } #endif /* CONFIG_NET */ diff --git a/nuttx/net/uip/uip-input.c b/nuttx/net/uip/uip-input.c index b8d8ebb7e..6ee748c89 100644 --- a/nuttx/net/uip/uip-input.c +++ b/nuttx/net/uip/uip-input.c @@ -102,8 +102,8 @@ /* Macros. */ -#define BUF ((struct uip_tcpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) -#define FBUF ((struct uip_tcpip_hdr *)&uip_reassbuf[0]) +#define BUF ((struct uip_ip_hdr *)&dev->d_buf[UIP_LLH_LEN]) +#define FBUF ((struct uip_ip_hdr *)&uip_reassbuf[0]) /* IP fragment re-assembly */ @@ -294,9 +294,6 @@ nullreturn: void uip_input(struct uip_driver_s *dev) { - dev->d_snddata = &dev->d_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN]; - dev->d_appdata = &dev->d_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN]; - /* This is where the input processing starts. */ #ifdef CONFIG_NET_STATISTICS @@ -468,9 +465,11 @@ void uip_input(struct uip_driver_s *dev) switch (BUF->proto) { +#ifdef CONFIG_NET_TCP case UIP_PROTO_TCP: /* TCP input */ uip_tcpinput(dev); break; +#endif #ifdef CONFIG_NET_UDP case UIP_PROTO_UDP: /* UDP input */ @@ -480,6 +479,7 @@ void uip_input(struct uip_driver_s *dev) /* Check for ICMP input */ +#ifdef CONFIG_NET_ICMP #ifndef CONFIG_NET_IPv6 case UIP_PROTO_ICMP: /* ICMP input */ #else @@ -487,6 +487,7 @@ void uip_input(struct uip_driver_s *dev) #endif uip_icmpinput(dev); break; +#endif default: /* Unrecognized/unsupported protocol */ #ifdef CONFIG_NET_STATISTICS diff --git a/nuttx/net/uip/uip-internal.h b/nuttx/net/uip/uip-internal.h index ccc1c86bd..2aab6fbe3 100644 --- a/nuttx/net/uip/uip-internal.h +++ b/nuttx/net/uip/uip-internal.h @@ -118,6 +118,7 @@ extern "C" { #define EXTERN extern #endif +#ifdef CONFIG_NET_TCP /* Defined in uip_tcpconn.c *************************************************/ EXTERN void uip_tcpinit(void); @@ -165,6 +166,16 @@ EXTERN void uip_tcpinput(struct uip_driver_s *dev); EXTERN uint8 uip_tcpcallback(struct uip_driver_s *dev, struct uip_conn *conn, uint8 flags); +/* Defined in uip-tcpreadahead.c ********************************************/ + +#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 +EXTERN void uip_tcpreadaheadinit(void); +EXTERN struct uip_readahead_s *uip_tcpreadaheadalloc(void); +EXTERN void uip_tcpreadaheadrelease(struct uip_readahead_s *buf); +#endif /* CONFIG_NET_NTCP_READAHEAD_BUFFERS */ + +#endif /* CONFIG_NET_TCP */ + #ifdef CONFIG_NET_UDP /* Defined in uip_udpconn.c *************************************************/ @@ -190,17 +201,11 @@ EXTERN void uip_udpcallback(struct uip_driver_s *dev, struct uip_udp_conn *conn, uint8 flags); #endif /* CONFIG_NET_UDP */ +#ifdef CONFIG_NET_ICMP /* Defined in uip-icmpinput.c ***********************************************/ EXTERN void uip_icmpinput(struct uip_driver_s *dev); - -/* Defined in uip-tcpreadahead.c ********************************************/ - -#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0 -EXTERN void uip_tcpreadaheadinit(void); -EXTERN struct uip_readahead_s *uip_tcpreadaheadalloc(void); -EXTERN void uip_tcpreadaheadrelease(struct uip_readahead_s *buf); -#endif /* CONFIG_NET_NTCP_READAHEAD_BUFFERS */ +#endif /* CONFIG_NET_ICMP */ #undef EXTERN #ifdef __cplusplus diff --git a/nuttx/net/uip/uip-poll.c b/nuttx/net/uip/uip-poll.c index f17f42e75..1e8483ea6 100644 --- a/nuttx/net/uip/uip-poll.c +++ b/nuttx/net/uip/uip-poll.c @@ -108,6 +108,7 @@ static int uip_polludpconnections(struct uip_driver_s *dev, * ****************************************************************************/ +#ifdef CONFIG_NET_TCP static inline int uip_polltcpconnections(struct uip_driver_s *dev, uip_poll_callback_t callback) { @@ -129,6 +130,9 @@ static inline int uip_polltcpconnections(struct uip_driver_s *dev, return bstop; } +#else +# define uip_polltcpconnections(dev, callback) (0) +#endif /**************************************************************************** * Function: uip_polltcptimer @@ -143,6 +147,7 @@ static inline int uip_polltcpconnections(struct uip_driver_s *dev, * ****************************************************************************/ +#ifdef CONFIG_NET_TCP static inline int uip_polltcptimer(struct uip_driver_s *dev, uip_poll_callback_t callback, int hsec) { @@ -164,6 +169,9 @@ static inline int uip_polltcptimer(struct uip_driver_s *dev, return bstop; } +#else +# define uip_polltcptimer(dev, callback, hsec) (0) +#endif /**************************************************************************** * Public Functions diff --git a/nuttx/net/uip/uip-tcpappsend.c b/nuttx/net/uip/uip-tcpappsend.c index fa19c23f0..f26f897bb 100644 --- a/nuttx/net/uip/uip-tcpappsend.c +++ b/nuttx/net/uip/uip-tcpappsend.c @@ -42,7 +42,7 @@ ****************************************************************************/ #include <nuttx/config.h> -#ifdef CONFIG_NET +#if defined(CONFIG_NET) && defined(CONFIG_NET_TCP) #include <sys/types.h> #include <debug.h> @@ -235,4 +235,4 @@ void uip_tcprexmit(struct uip_driver_s *dev, struct uip_conn *conn, uint8 result dev->d_len = 0; } } -#endif /* CONFIG_NET */ +#endif /* CONFIG_NET && CONFIG_NET_TCP */ diff --git a/nuttx/net/uip/uip-tcpcallback.c b/nuttx/net/uip/uip-tcpcallback.c index 311323059..1694a9ab4 100644 --- a/nuttx/net/uip/uip-tcpcallback.c +++ b/nuttx/net/uip/uip-tcpcallback.c @@ -39,7 +39,7 @@ ****************************************************************************/ #include <nuttx/config.h> -#ifdef CONFIG_NET +#if defined(CONFIG_NET) && defined(CONFIG_NET_TCP) #include <sys/types.h> #include <string.h> @@ -210,4 +210,4 @@ uint8 uip_tcpcallback(struct uip_driver_s *dev, struct uip_conn *conn, uint8 fla return ret; } -#endif /* CONFIG_NET */ +#endif /* CONFIG_NET && CONFIG_NET_TCP */ diff --git a/nuttx/net/uip/uip-tcpconn.c b/nuttx/net/uip/uip-tcpconn.c index eb84d8f31..d2e211232 100644 --- a/nuttx/net/uip/uip-tcpconn.c +++ b/nuttx/net/uip/uip-tcpconn.c @@ -45,7 +45,7 @@ ****************************************************************************/ #include <nuttx/config.h> -#ifdef CONFIG_NET +#if defined(CONFIG_NET) && defined(CONFIG_NET_TCP) #include <sys/types.h> #include <string.h> @@ -655,4 +655,4 @@ int uip_tcpconnect(struct uip_conn *conn, const struct sockaddr_in *addr) return OK; } -#endif /* CONFIG_NET */ +#endif /* CONFIG_NET && CONFIG_NET_TCP */ diff --git a/nuttx/net/uip/uip-tcpinput.c b/nuttx/net/uip/uip-tcpinput.c index ba11fcb81..e3271263a 100644 --- a/nuttx/net/uip/uip-tcpinput.c +++ b/nuttx/net/uip/uip-tcpinput.c @@ -43,7 +43,7 @@ ****************************************************************************/ #include <nuttx/config.h> -#ifdef CONFIG_NET +#if defined(CONFIG_NET) && defined(CONFIG_NET_TCP) #include <sys/types.h> #include <debug.h> @@ -103,6 +103,9 @@ void uip_tcpinput(struct uip_driver_s *dev) int len; int i; + dev->d_snddata = &dev->d_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN]; + dev->d_appdata = &dev->d_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN]; + #ifdef CONFIG_NET_STATISTICS uip_stat.tcp.recv++; #endif @@ -741,4 +744,4 @@ drop: dev->d_len = 0; } -#endif /* CONFIG_NET */ +#endif /* CONFIG_NET && CONFIG_NET_TCP */ diff --git a/nuttx/net/uip/uip-tcppoll.c b/nuttx/net/uip/uip-tcppoll.c index 9b66ef707..18aa9541d 100644 --- a/nuttx/net/uip/uip-tcppoll.c +++ b/nuttx/net/uip/uip-tcppoll.c @@ -43,7 +43,7 @@ ****************************************************************************/ #include <nuttx/config.h> -#ifdef CONFIG_NET +#if defined(CONFIG_NET) && defined(CONFIG_NET_TCP) #include <sys/types.h> #include <debug.h> @@ -127,4 +127,4 @@ void uip_tcppoll(struct uip_driver_s *dev, struct uip_conn *conn) } } -#endif /* CONFIG_NET */ +#endif /* CONFIG_NET && CONFIG_NET_TCP */ diff --git a/nuttx/net/uip/uip-tcpreadahead.c b/nuttx/net/uip/uip-tcpreadahead.c index 6c4c78f1e..abadb4f50 100644 --- a/nuttx/net/uip/uip-tcpreadahead.c +++ b/nuttx/net/uip/uip-tcpreadahead.c @@ -39,7 +39,7 @@ ****************************************************************************/ #include <net/uip/uipopt.h> -#if defined(CONFIG_NET) && (CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0) +#if defined(CONFIG_NET) && defined(CONFIG_NET_TCP) && (CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0) #include <sys/types.h> #include <queue.h> @@ -129,4 +129,4 @@ void uip_tcpreadaheadrelease(struct uip_readahead_s *buf) sq_addfirst(&buf->rh_node, &g_freebuffers); } -#endif /* CONFIG_NET && CONFIG_NET_NTCP_READAHEAD_BUFFERS*/ +#endif /* CONFIG_NET && CONFIG_NET_TCP && CONFIG_NET_NTCP_READAHEAD_BUFFERS*/ diff --git a/nuttx/net/uip/uip-tcpsend.c b/nuttx/net/uip/uip-tcpsend.c index ef4a1b7af..1729dd75b 100644 --- a/nuttx/net/uip/uip-tcpsend.c +++ b/nuttx/net/uip/uip-tcpsend.c @@ -42,7 +42,7 @@ ****************************************************************************/ #include <nuttx/config.h> -#ifdef CONFIG_NET +#if defined(CONFIG_NET) && defined(CONFIG_NET_TCP) #include <sys/types.h> #include <debug.h> @@ -362,4 +362,4 @@ void uip_tcpack(struct uip_driver_s *dev, struct uip_conn *conn, uint8 ack) uip_tcpsendcommon(dev, conn); } -#endif /* CONFIG_NET */ +#endif /* CONFIG_NET && CONFIG_NET_TCP */ diff --git a/nuttx/net/uip/uip-tcptimer.c b/nuttx/net/uip/uip-tcptimer.c index beb16bc0f..3679808d3 100644 --- a/nuttx/net/uip/uip-tcptimer.c +++ b/nuttx/net/uip/uip-tcptimer.c @@ -43,7 +43,7 @@ ****************************************************************************/ #include <nuttx/config.h> -#ifdef CONFIG_NET +#if defined(CONFIG_NET) && defined(CONFIG_NET_TCP) #include <sys/types.h> #include <debug.h> @@ -247,4 +247,4 @@ done: return; } -#endif /* CONFIG_NET */ +#endif /* CONFIG_NET && CONFIG_NET_TCP */ diff --git a/nuttx/netutils/Makefile b/nuttx/netutils/Makefile index df164a4a7..a95a0f818 100644 --- a/nuttx/netutils/Makefile +++ b/nuttx/netutils/Makefile @@ -38,11 +38,13 @@ MKDEP = $(TOPDIR)/tools/mkdeps.sh ifeq ($(CONFIG_NET),y) +ifeq ($(CONFIG_NET_TCP),y) include uiplib/Make.defs include smtp/Make.defs include telnetd/Make.defs include webclient/Make.defs include webserver/Make.defs +endif ifeq ($(CONFIG_NET_UDP),y) include dhcpc/Make.defs include resolv/Make.defs diff --git a/nuttx/tools/mkconfig.c b/nuttx/tools/mkconfig.c index ccd8a077a..c1653f308 100644 --- a/nuttx/tools/mkconfig.c +++ b/nuttx/tools/mkconfig.c @@ -257,9 +257,11 @@ int main(int argc, char **argv, char **envp) printf("# undef CONFIG_NSOCKET_DESCRIPTORS\n"); printf("# define CONFIG_NSOCKET_DESCRIPTORS 0\n"); printf("#endif\n\n"); - printf("/* UDP support can only be provided on top of basic network support */\n\n"); + printf("/* Protocol support can only be provided on top of basic network support */\n\n"); printf("#ifndef CONFIG_NET\n"); + printf("# undef CONFIG_NET_TCP\n"); printf("# undef CONFIG_NET_UDP\n"); + printf("# undef CONFIG_NET_ICMP\n"); printf("#endif\n\n"); printf("/* Verbose debug only makes sense if debug is enabled */\n\n"); printf("#ifndef CONFIG_DEBUG\n"); |