summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-11-15 13:13:23 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-11-15 13:13:23 -0600
commit24a33a43436bcc8430c5c1e6707dedc8c2531171 (patch)
treebf837b9244093960c729978056c8097c198541a0
parentcf1c261a3dccb0f1ab7c98f1ad3900417b1d8262 (diff)
downloadnuttx-24a33a43436bcc8430c5c1e6707dedc8c2531171.tar.gz
nuttx-24a33a43436bcc8430c5c1e6707dedc8c2531171.tar.bz2
nuttx-24a33a43436bcc8430c5c1e6707dedc8c2531171.zip
Network: All logic will now handle varialbe length link layer protocol headers within incoming packets. This permits use of multiple network interfaces with differing data links. For example, ETHERNET + SLIP
-rw-r--r--apps/include/netutils/httpd.h7
-rw-r--r--apps/netutils/tftpc/tftpc_internal.h13
-rw-r--r--nuttx/fs/nfs/nfs_vfsops.c12
-rw-r--r--nuttx/include/nuttx/net/netconfig.h59
-rw-r--r--nuttx/include/nuttx/net/netdev.h2
-rw-r--r--nuttx/include/nuttx/net/tcp.h10
-rw-r--r--nuttx/net/devif/devif_input.c4
-rw-r--r--nuttx/net/icmp/icmp_input.c2
-rw-r--r--nuttx/net/icmp/icmp_ping.c4
-rw-r--r--nuttx/net/icmp/icmp_poll.c4
-rw-r--r--nuttx/net/icmp/icmp_send.c2
-rw-r--r--nuttx/net/igmp/igmp_input.c4
-rw-r--r--nuttx/net/igmp/igmp_poll.c4
-rw-r--r--nuttx/net/igmp/igmp_send.c2
-rw-r--r--nuttx/net/pkt/pkt_poll.c4
-rw-r--r--nuttx/net/socket/connect.c15
-rw-r--r--nuttx/net/socket/net_sendfile.c4
-rw-r--r--nuttx/net/socket/recvfrom.c6
-rw-r--r--nuttx/net/tcp/tcp.h3
-rw-r--r--nuttx/net/tcp/tcp_conn.c13
-rw-r--r--nuttx/net/tcp/tcp_input.c40
-rw-r--r--nuttx/net/tcp/tcp_poll.c4
-rw-r--r--nuttx/net/tcp/tcp_send.c6
-rw-r--r--nuttx/net/tcp/tcp_send_buffered.c2
-rw-r--r--nuttx/net/tcp/tcp_send_unbuffered.c2
-rw-r--r--nuttx/net/tcp/tcp_timer.c4
-rw-r--r--nuttx/net/udp/udp_input.c8
-rw-r--r--nuttx/net/udp/udp_poll.c4
-rw-r--r--nuttx/net/udp/udp_send.c2
-rw-r--r--nuttx/net/utils/net_chksum.c8
30 files changed, 159 insertions, 95 deletions
diff --git a/apps/include/netutils/httpd.h b/apps/include/netutils/httpd.h
index d5a9b21c4..1ae9b7c1e 100644
--- a/apps/include/netutils/httpd.h
+++ b/apps/include/netutils/httpd.h
@@ -77,9 +77,14 @@
/* For efficiency reasons, the size of the IO buffer should be a multiple
* of the TCP MSS value. Also, the current design requires that the IO
* buffer be sufficiently large to contain the entire GET request.
+ *
+ * In the case where there are multiple network devices with different
+ * link layer protocols (CONFIG_NET_MULTILINK), each network device
+ * may support a different TCP MSS value. Here we arbitrarily select
+ * the minimum MSS for that case.
*/
-#define HTTPD_IOBUFFER_SIZE (3*TCP_MSS)
+#define HTTPD_IOBUFFER_SIZE (3*MIN_TCP_MSS)
/* This is the maximum size of a file path */
diff --git a/apps/netutils/tftpc/tftpc_internal.h b/apps/netutils/tftpc/tftpc_internal.h
index 436090193..31a3faade 100644
--- a/apps/netutils/tftpc/tftpc_internal.h
+++ b/apps/netutils/tftpc/tftpc_internal.h
@@ -84,15 +84,20 @@
#define TFTP_ERRHEADERSIZE 4
#define TFTP_DATAHEADERSIZE 4
-/* The maximum size for TFTP data is determined by the configured uIP packet
- * size (but cannot exceed 512 + sizeof(TFTP_DATA header).
+/* The maximum size for TFTP data is determined by the configured UDP packet
+ * payload size (UDP_MSS), but cannot exceed 512 + sizeof(TFTP_DATA header).
+ *
+ * In the case where there are multiple network devices with different
+ * link layer protocols (CONFIG_NET_MULTILINK), each network device
+ * may support a different UDP MSS value. Here we arbitrarily select
+ * the minimum MSS for that case.
*/
#define TFTP_DATAHEADERSIZE 4
#define TFTP_MAXPACKETSIZE (TFTP_DATAHEADERSIZE+512)
-#if UDP_MSS < TFTP_MAXPACKETSIZE
-# define TFTP_PACKETSIZE UDP_MSS
+#if MIN_UDP_MSS < TFTP_MAXPACKETSIZE
+# define TFTP_PACKETSIZE MIN_UDP_MSS
# ifdef CONFIG_CPP_HAVE_WARNING
# warning "uIP MSS is too small for TFTP"
# endif
diff --git a/nuttx/fs/nfs/nfs_vfsops.c b/nuttx/fs/nfs/nfs_vfsops.c
index 362343d01..fe7a77f0d 100644
--- a/nuttx/fs/nfs/nfs_vfsops.c
+++ b/nuttx/fs/nfs/nfs_vfsops.c
@@ -1713,11 +1713,17 @@ static int nfs_bind(FAR struct inode *blkdriver, FAR const void *data,
buflen = tmp;
}
- /* But don't let the buffer size exceed the MSS of the socket type */
+ /* But don't let the buffer size exceed the MSS of the socket type.
+ *
+ * In the case where there are multiple network devices with different
+ * link layer protocols (CONFIG_NET_MULTILINK), each network device
+ * may support a different UDP MSS value. Here we arbitrarily select
+ * the minimum MSS for that case.
+ */
- if (buflen > UDP_MSS)
+ if (buflen > MIN_UDP_MSS)
{
- buflen = UDP_MSS;
+ buflen = MIN_UDP_MSS;
}
/* Create an instance of the mountpt state structure */
diff --git a/nuttx/include/nuttx/net/netconfig.h b/nuttx/include/nuttx/net/netconfig.h
index c5c69b2c7..fef0294c3 100644
--- a/nuttx/include/nuttx/net/netconfig.h
+++ b/nuttx/include/nuttx/net/netconfig.h
@@ -86,16 +86,16 @@
* varies and is obtained from the network device structure.
*/
-#ifdef CONFIG_NET_MULTILINK
-/* We are supporting multiple network devices and using different link
- * level protocols. Get the size of the link layer header from the
- * device structure.
- */
+#if defined(CONFIG_NET_MULTILINK)
+ /* We are supporting multiple network devices using different link layer
+ * protocols. Get the size of the link layer header from the device
+ * structure.
+ */
# define NET_LL_HDRLEN(d) ((d)->d_llhdrlen)
-#if defined(CONFIG_NET_SLIP)
-/* There is no link layer header with SLIP */
+#elif defined(CONFIG_NET_SLIP)
+ /* There is no link layer header with SLIP */
# ifdef CONFIG_NET_IPv6
# error SLIP is not available for IPv6
@@ -103,11 +103,11 @@
# define NET_LL_HDRLEN(d) 0
#else /* if defined(CONFIG_NET_ETHERNET) */
-/* Assume standard Ethernet header */
+ /* Assume standard Ethernet link layer header */
# define NET_LL_HDRLEN(d) 14
-#endif
+#endif /* MULTILINK or SLIP or ETHERNET */
/* Layer 3/4 Configuration Options ******************************************/
@@ -162,10 +162,22 @@
#endif
/* The UDP maximum packet size. This is should not be to set to more
- * than CONFIG_NET_BUFSIZE - NET_LL_HDRLEN - IPUDP_HDRLEN.
+ * than CONFIG_NET_BUFSIZE - NET_LL_HDRLEN(dev) - IPUDP_HDRLEN.
*/
-#define UDP_MSS(d) (CONFIG_NET_BUFSIZE - NET_LL_HDRLEN(d) - IPUDP_HDRLEN)
+#define UDP_MSS(d) (CONFIG_NET_BUFSIZE - NET_LL_HDRLEN(d) - IPUDP_HDRLEN)
+
+#ifdef CONFIG_NET_ETHERNET
+# define MIN_UDP_MSS (CONFIG_NET_BUFSIZE - ETH_HDRLEN - IPUDP_HDRLEN)
+#else /* if defined(CONFIG_NET_SLIP) */
+# define MIN_UDP_MSS (CONFIG_NET_BUFSIZE - IPUDP_HDRLEN)
+#endif
+
+#ifdef CONFIG_NET_SLIP
+# define MAX_UDP_MSS (CONFIG_NET_BUFSIZE - IPUDP_HDRLEN)
+#else /* if defined(CONFIG_NET_ETHERNET) */
+# define MAX_UDP_MSS (CONFIG_NET_BUFSIZE - ETH_HDRLEN - IPUDP_HDRLEN)
+#endif
/* TCP configuration options */
@@ -227,20 +239,39 @@
#define TCP_MAXSYNRTX 5
/* The TCP maximum segment size. This is should not be set to more
- * than CONFIG_NET_BUFSIZE - NET_LL_HDRLEN - IPTCP_HDRLEN.
+ * than CONFIG_NET_BUFSIZE - NET_LL_HDRLEN(dev) - IPTCP_HDRLEN.
+ *
+ * In the case where there are multiple network devices with different
+ * link layer protocols (CONFIG_NET_MULTILINK), each network device
+ * may support a different UDP MSS value. Here we arbitrarily select
+ * the minimum MSS for that case.
*/
-#define TCP_MSS (CONFIG_NET_BUFSIZE - NET_LL_HDRLEN - IPTCP_HDRLEN)
+#define TCP_MSS(d) (CONFIG_NET_BUFSIZE - NET_LL_HDRLEN(d) - IPTCP_HDRLEN)
+
+#ifdef CONFIG_NET_ETHERNET
+# define MIN_TCP_MSS (CONFIG_NET_BUFSIZE - ETH_HDRLEN - IPTCP_HDRLEN)
+#else /* if defined(CONFIG_NET_SLIP) */
+# define MIN_TCP_MSS (CONFIG_NET_BUFSIZE - IPTCP_HDRLEN)
+#endif
+
+#ifdef CONFIG_NET_SLIP
+# define MAX_TCP_MSS (CONFIG_NET_BUFSIZE - IPTCP_HDRLEN)
+#else /* if defined(CONFIG_NET_ETHERNET) */
+# define MAX_TCP_MSS (CONFIG_NET_BUFSIZE - ETH_HDRLEN - IPTCP_HDRLEN)
+#endif
/* The size of the advertised receiver's window.
*
* Should be set low (i.e., to the size of the d_buf buffer) is the
* application is slow to process incoming data, or high (32768 bytes)
* if the application processes data quickly.
+ *
+ * See the note above regarding the TCP MSS and CONFIG_NET_MULTILINK.
*/
#ifndef CONFIG_NET_RECEIVE_WINDOW
-# define CONFIG_NET_RECEIVE_WINDOW TCP_MSS
+# define CONFIG_NET_RECEIVE_WINDOW MIN_TCP_MSS
#endif
/* How long a connection should stay in the TIME_WAIT state.
diff --git a/nuttx/include/nuttx/net/netdev.h b/nuttx/include/nuttx/net/netdev.h
index 2899170a2..92146b179 100644
--- a/nuttx/include/nuttx/net/netdev.h
+++ b/nuttx/include/nuttx/net/netdev.h
@@ -119,7 +119,7 @@ struct net_driver_s
* driver should place incoming data into this buffer. When sending data,
* the device driver should read the link level headers and the TCP/IP
* headers from this buffer. The size of the link level headers is
- * configured by the NET_LL_HDRLEN define.
+ * configured by the NET_LL_HDRLEN(dev) define.
*
* uIP will handle only a single buffer for both incoming and outgoing
* packets. However, the drive design may be concurrently send and
diff --git a/nuttx/include/nuttx/net/tcp.h b/nuttx/include/nuttx/net/tcp.h
index da768bd7c..db511cee9 100644
--- a/nuttx/include/nuttx/net/tcp.h
+++ b/nuttx/include/nuttx/net/tcp.h
@@ -56,6 +56,7 @@
#include <stdint.h>
#include <nuttx/net/netconfig.h>
+#include <nuttx/net/arp.h>
#include <nuttx/net/ip.h>
/****************************************************************************
@@ -117,11 +118,10 @@
* This is a long established rule.
*/
-#if TCP_MSS > 576
-# define TCP_INITIAL_MSS 576
-#else
-# define TCP_INITIAL_MSS TCP_MSS
-#endif
+#define TCP_INITIAL_MSS(d) (TCP_MSS(d) > 576 ? 576 : TCP_MSS(d))
+
+#define MIN_TCP_INITIAL_MSS (MIN_TCP_MSS > 576 ? 576 : MIN_TCP_MSS)
+#define MAX_TCP_INITIAL_MSS (MAX_TCP_MSS > 576 ? 576 : MAX_TCP_MSS)
/****************************************************************************
* Public Type Definitions
diff --git a/nuttx/net/devif/devif_input.c b/nuttx/net/devif/devif_input.c
index f97911f74..03b5f64ca 100644
--- a/nuttx/net/devif/devif_input.c
+++ b/nuttx/net/devif/devif_input.c
@@ -107,13 +107,13 @@
/* Macros */
-#define BUF ((FAR struct net_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
+#define BUF ((FAR struct net_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
#define FBUF ((FAR struct net_iphdr_s *)&g_reassembly_buffer[0])
/* IP fragment re-assembly */
#define IP_MF 0x20
-#define TCP_REASS_BUFSIZE (CONFIG_NET_BUFSIZE - NET_LL_HDRLEN)
+#define TCP_REASS_BUFSIZE (CONFIG_NET_BUFSIZE - NET_LL_HDRLEN(dev))
#define TCP_REASS_LASTFRAG 0x01
/****************************************************************************
diff --git a/nuttx/net/icmp/icmp_input.c b/nuttx/net/icmp/icmp_input.c
index 778ce4dee..154bd384f 100644
--- a/nuttx/net/icmp/icmp_input.c
+++ b/nuttx/net/icmp/icmp_input.c
@@ -66,7 +66,7 @@
* Pre-processor Definitions
****************************************************************************/
-#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
+#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Public Variables
diff --git a/nuttx/net/icmp/icmp_ping.c b/nuttx/net/icmp/icmp_ping.c
index 3cd900b94..be80b1b0a 100644
--- a/nuttx/net/icmp/icmp_ping.c
+++ b/nuttx/net/icmp/icmp_ping.c
@@ -65,8 +65,8 @@
* Pre-processor Definitions
****************************************************************************/
-#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
-#define ICMPDAT (&dev->d_buf[NET_LL_HDRLEN + sizeof(struct icmp_iphdr_s)])
+#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
+#define ICMPDAT (&dev->d_buf[NET_LL_HDRLEN(dev) + sizeof(struct icmp_iphdr_s)])
/* Allocate a new ICMP data callback */
diff --git a/nuttx/net/icmp/icmp_poll.c b/nuttx/net/icmp/icmp_poll.c
index 16f4abf00..6c3f63b26 100644
--- a/nuttx/net/icmp/icmp_poll.c
+++ b/nuttx/net/icmp/icmp_poll.c
@@ -90,8 +90,8 @@ void icmp_poll(FAR struct net_driver_s *dev)
{
/* Setup for the application callback */
- dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN + IPICMP_HDRLEN];
- dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN + IPICMP_HDRLEN];
+ dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPICMP_HDRLEN];
+ dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPICMP_HDRLEN];
dev->d_len = 0;
dev->d_sndlen = 0;
diff --git a/nuttx/net/icmp/icmp_send.c b/nuttx/net/icmp/icmp_send.c
index 18de2c01a..be6621839 100644
--- a/nuttx/net/icmp/icmp_send.c
+++ b/nuttx/net/icmp/icmp_send.c
@@ -57,7 +57,7 @@
* Pre-processor Definitions
****************************************************************************/
-#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
+#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Public Variables
diff --git a/nuttx/net/igmp/igmp_input.c b/nuttx/net/igmp/igmp_input.c
index 04ec4709c..14bd531ef 100644
--- a/nuttx/net/igmp/igmp_input.c
+++ b/nuttx/net/igmp/igmp_input.c
@@ -62,7 +62,7 @@
* Pre-processor Definitions
****************************************************************************/
-#define IGMPBUF ((struct igmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
+#define IGMPBUF ((struct igmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Private Functions
@@ -125,7 +125,7 @@ void igmp_input(struct net_driver_s *dev)
/* Verify the message length */
- if (dev->d_len < NET_LL_HDRLEN+IPIGMP_HDRLEN)
+ if (dev->d_len < NET_LL_HDRLEN(dev) + IPIGMP_HDRLEN)
{
IGMP_STATINCR(g_netstats.igmp.length_errors);
nlldbg("Length error\n");
diff --git a/nuttx/net/igmp/igmp_poll.c b/nuttx/net/igmp/igmp_poll.c
index 147f9f810..cb20a81c0 100644
--- a/nuttx/net/igmp/igmp_poll.c
+++ b/nuttx/net/igmp/igmp_poll.c
@@ -151,8 +151,8 @@ void igmp_poll(FAR struct net_driver_s *dev)
/* Setup the poll operation */
- dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN + IPIGMP_HDRLEN];
- dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN + IPIGMP_HDRLEN];
+ dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPIGMP_HDRLEN];
+ dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPIGMP_HDRLEN];
dev->d_len = 0;
dev->d_sndlen = 0;
diff --git a/nuttx/net/igmp/igmp_send.c b/nuttx/net/igmp/igmp_send.c
index bb827029d..cc5430f90 100644
--- a/nuttx/net/igmp/igmp_send.c
+++ b/nuttx/net/igmp/igmp_send.c
@@ -76,7 +76,7 @@
/* Buffer layout */
#define RASIZE (4)
-#define IGMPBUF ((struct igmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
+#define IGMPBUF ((struct igmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Public Variables
diff --git a/nuttx/net/pkt/pkt_poll.c b/nuttx/net/pkt/pkt_poll.c
index 0b7c6f08d..7c8384268 100644
--- a/nuttx/net/pkt/pkt_poll.c
+++ b/nuttx/net/pkt/pkt_poll.c
@@ -102,8 +102,8 @@ void pkt_poll(FAR struct net_driver_s *dev, FAR struct pkt_conn_s *conn)
{
/* Setup for the application callback */
- dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN + IPUDP_HDRLEN];
- dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN + IPUDP_HDRLEN];
+ dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPUDP_HDRLEN];
+ dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPUDP_HDRLEN];
dev->d_len = 0;
dev->d_sndlen = 0;
diff --git a/nuttx/net/socket/connect.c b/nuttx/net/socket/connect.c
index d88961e4d..291a16008 100644
--- a/nuttx/net/socket/connect.c
+++ b/nuttx/net/socket/connect.c
@@ -169,7 +169,7 @@ static inline void psock_teardown_callbacks(FAR struct tcp_connect_s *pstate,
* connection operation via by the lower, device interfacing layer.
*
* Parameters:
- * dev The sructure of the network driver that caused the interrupt
+ * dev The structure of the network driver that caused the interrupt
* pvconn The connection structure associated with the socket
* flags Set of events describing why the callback was invoked
*
@@ -250,6 +250,17 @@ static uint16_t psock_connect_interrupt(FAR struct net_driver_s *dev,
psock_teardown_callbacks(pstate, pstate->tc_result);
+#ifdef CONFIG_NET_MULTILINK
+ /* When we set up the connection structure, we did not know the size
+ * of the initial MSS. Now that the connection is associated with a
+ * network device, we now know the size of link layer header and can
+ * determine the correct initial MSS.
+ */
+
+ DEBUGASSERT(psock->s_conn);
+ psock->s_conn->mss = TCP_INITIAL_MSS(dev);
+#endif
+
/* Wake up the waiting thread */
sem_post(&pstate->tc_sem);
@@ -305,7 +316,7 @@ static inline int psock_tcp_connect(FAR struct socket *psock,
}
else
{
- /* Perform the uIP connection operation */
+ /* Perform the TCP connection operation */
ret = tcp_connect(psock->s_conn, inaddr);
}
diff --git a/nuttx/net/socket/net_sendfile.c b/nuttx/net/socket/net_sendfile.c
index de5a01efc..807bdcc7d 100644
--- a/nuttx/net/socket/net_sendfile.c
+++ b/nuttx/net/socket/net_sendfile.c
@@ -70,14 +70,14 @@
#include "socket/socket.h"
/****************************************************************************
- * Definitions
+ * Pre-processor Definitions
****************************************************************************/
#if defined(CONFIG_NET_TCP_SPLIT) && !defined(CONFIG_NET_TCP_SPLIT_SIZE)
# define CONFIG_NET_TCP_SPLIT_SIZE 40
#endif
-#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
+#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Private Types
diff --git a/nuttx/net/socket/recvfrom.c b/nuttx/net/socket/recvfrom.c
index aeffcba32..992eb40b3 100644
--- a/nuttx/net/socket/recvfrom.c
+++ b/nuttx/net/socket/recvfrom.c
@@ -71,11 +71,11 @@
#include "socket/socket.h"
/****************************************************************************
- * Definitions
+ * Pre-processor Definitions
****************************************************************************/
-#define UDPBUF ((struct udp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
-#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
+#define UDPBUF ((struct udp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
+#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Private Types
diff --git a/nuttx/net/tcp/tcp.h b/nuttx/net/tcp/tcp.h
index 72116e523..67d902126 100644
--- a/nuttx/net/tcp/tcp.h
+++ b/nuttx/net/tcp/tcp.h
@@ -358,7 +358,8 @@ FAR struct tcp_conn_s *tcp_listener(uint16_t portno);
*
****************************************************************************/
-FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct tcp_iphdr_s *buf);
+FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev,
+ FAR struct tcp_iphdr_s *buf);
/****************************************************************************
* Name: tcp_bind()
diff --git a/nuttx/net/tcp/tcp_conn.c b/nuttx/net/tcp/tcp_conn.c
index a505cc221..666480012 100644
--- a/nuttx/net/tcp/tcp_conn.c
+++ b/nuttx/net/tcp/tcp_conn.c
@@ -508,7 +508,8 @@ FAR struct tcp_conn_s *tcp_listener(uint16_t portno)
*
****************************************************************************/
-FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct tcp_iphdr_s *buf)
+FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev,
+ FAR struct tcp_iphdr_s *buf)
{
FAR struct tcp_conn_s *conn = tcp_alloc();
if (conn)
@@ -522,7 +523,7 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct tcp_iphdr_s *buf)
conn->nrtx = 0;
conn->lport = buf->destport;
conn->rport = buf->srcport;
- conn->mss = TCP_INITIAL_MSS;
+ conn->mss = TCP_INITIAL_MSS(dev);
net_ipaddr_copy(conn->ripaddr, net_ip4addr_conv32(buf->srcipaddr));
conn->tcpstateflags = TCP_SYN_RCVD;
@@ -670,12 +671,16 @@ int tcp_connect(FAR struct tcp_conn_s *conn,
return port;
}
- /* Initialize and return the connection structure, bind it to the port number */
+ /* Initialize and return the connection structure, bind it to the port
+ * number. At this point, we do not know the size of the initial MSS We
+ * know the total size of the packet buffer, but we don't yet know the
+ * size of link layer header.
+ */
conn->tcpstateflags = TCP_SYN_SENT;
tcp_initsequence(conn->sndseq);
- conn->mss = TCP_INITIAL_MSS;
+ conn->mss = MIN_TCP_INITIAL_MSS;
conn->unacked = 1; /* TCP length of the SYN is one. */
conn->nrtx = 0;
conn->timer = 1; /* Send the SYN next time around. */
diff --git a/nuttx/net/tcp/tcp_input.c b/nuttx/net/tcp/tcp_input.c
index c84777c39..0106c390f 100644
--- a/nuttx/net/tcp/tcp_input.c
+++ b/nuttx/net/tcp/tcp_input.c
@@ -64,7 +64,7 @@
* Pre-processor Definitions
****************************************************************************/
-#define BUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
+#define BUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Public Variables
@@ -110,8 +110,8 @@ void tcp_input(FAR struct net_driver_s *dev)
int len;
int i;
- dev->d_snddata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN];
- dev->d_appdata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN];
+ dev->d_snddata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev)];
+ dev->d_appdata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev)];
#ifdef CONFIG_NET_STATISTICS
g_netstats.tcp.recv++;
@@ -177,7 +177,7 @@ void tcp_input(FAR struct net_driver_s *dev)
* user application to accept it.
*/
- conn = tcp_alloc_accept(pbuf);
+ conn = tcp_alloc_accept(dev, pbuf);
if (conn)
{
/* The connection structure was successfully allocated. Now see if
@@ -219,7 +219,7 @@ void tcp_input(FAR struct net_driver_s *dev)
{
for (i = 0; i < ((pbuf->tcpoffset >> 4) - 5) << 2 ;)
{
- opt = dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + i];
+ opt = dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + i];
if (opt == TCP_OPT_END)
{
/* End of options. */
@@ -233,13 +233,13 @@ void tcp_input(FAR struct net_driver_s *dev)
++i;
}
else if (opt == TCP_OPT_MSS &&
- dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 1 + i] == TCP_OPT_MSS_LEN)
+ dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 1 + i] == TCP_OPT_MSS_LEN)
{
/* An MSS option with the right option length. */
- tmp16 = ((uint16_t)dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 2 + i] << 8) |
- (uint16_t)dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 3 + i];
- conn->mss = tmp16 > TCP_MSS ? TCP_MSS : tmp16;
+ tmp16 = ((uint16_t)dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 2 + i] << 8) |
+ (uint16_t)dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 3 + i];
+ conn->mss = tmp16 > TCP_MSS(dev) ? TCP_MSS(dev) : tmp16;
/* And we are done processing options. */
@@ -251,7 +251,7 @@ void tcp_input(FAR struct net_driver_s *dev)
* can skip past them.
*/
- if (dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 1 + i] == 0)
+ if (dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 1 + i] == 0)
{
/* If the length field is zero, the options are malformed
* and we don't process them further.
@@ -259,7 +259,7 @@ void tcp_input(FAR struct net_driver_s *dev)
break;
}
- i += dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 1 + i];
+ i += dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 1 + i];
}
}
}
@@ -509,7 +509,7 @@ found:
{
for (i = 0; i < ((pbuf->tcpoffset >> 4) - 5) << 2 ;)
{
- opt = dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + i];
+ opt = dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + i];
if (opt == TCP_OPT_END)
{
/* End of options. */
@@ -523,14 +523,14 @@ found:
++i;
}
else if (opt == TCP_OPT_MSS &&
- dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 1 + i] == TCP_OPT_MSS_LEN)
+ dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 1 + i] == TCP_OPT_MSS_LEN)
{
/* An MSS option with the right option length. */
tmp16 =
- (dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 2 + i] << 8) |
- dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 3 + i];
- conn->mss = tmp16 > TCP_MSS ? TCP_MSS : tmp16;
+ (dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 2 + i] << 8) |
+ dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 3 + i];
+ conn->mss = tmp16 > TCP_MSS(dev) ? TCP_MSS(dev) : tmp16;
/* And we are done processing options. */
@@ -542,7 +542,7 @@ found:
* easily can skip past them.
*/
- if (dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 1 + i] == 0)
+ if (dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 1 + i] == 0)
{
/* If the length field is zero, the options are
* malformed and we don't process them further.
@@ -550,7 +550,7 @@ found:
break;
}
- i += dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN + 1 + i];
+ i += dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev) + 1 + i];
}
}
}
@@ -692,8 +692,8 @@ found:
* When the application is called, the d_len field
* contains the length of the incoming data. The application can
* access the incoming data through the global pointer
- * d_appdata, which usually points IPTCP_HDRLEN + NET_LL_HDRLEN
- * bytes into the d_buf array.
+ * d_appdata, which usually points IPTCP_HDRLEN + NET_LL_HDRLEN(dev)
+ * bytes into the d_buf array.
*
* If the application wishes to send any data, this data should be
* put into the d_appdata and the length of the data should be
diff --git a/nuttx/net/tcp/tcp_poll.c b/nuttx/net/tcp/tcp_poll.c
index ad1012970..0c2ea66f5 100644
--- a/nuttx/net/tcp/tcp_poll.c
+++ b/nuttx/net/tcp/tcp_poll.c
@@ -103,8 +103,8 @@ void tcp_poll(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn)
{
/* Set up for the callback */
- dev->d_snddata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN];
- dev->d_appdata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN];
+ dev->d_snddata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev)];
+ dev->d_appdata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev)];
dev->d_len = 0;
dev->d_sndlen = 0;
diff --git a/nuttx/net/tcp/tcp_send.c b/nuttx/net/tcp/tcp_send.c
index 4f615721e..d68855511 100644
--- a/nuttx/net/tcp/tcp_send.c
+++ b/nuttx/net/tcp/tcp_send.c
@@ -62,7 +62,7 @@
* Pre-processor Definitions
****************************************************************************/
-#define BUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
+#define BUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Public Variables
@@ -360,8 +360,8 @@ void tcp_ack(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
pbuf->optdata[0] = TCP_OPT_MSS;
pbuf->optdata[1] = TCP_OPT_MSS_LEN;
- pbuf->optdata[2] = (TCP_MSS) / 256;
- pbuf->optdata[3] = (TCP_MSS) & 255;
+ pbuf->optdata[2] = TCP_MSS(dev) / 256;
+ pbuf->optdata[3] = TCP_MSS(dev) & 255;
dev->d_len = IPTCP_HDRLEN + TCP_OPT_MSS_LEN;
pbuf->tcpoffset = ((TCP_HDRLEN + TCP_OPT_MSS_LEN) / 4) << 4;
diff --git a/nuttx/net/tcp/tcp_send_buffered.c b/nuttx/net/tcp/tcp_send_buffered.c
index 231eeebe7..d516262fa 100644
--- a/nuttx/net/tcp/tcp_send_buffered.c
+++ b/nuttx/net/tcp/tcp_send_buffered.c
@@ -79,7 +79,7 @@
* Pre-processor Definitions
****************************************************************************/
-#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
+#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/* Debug */
diff --git a/nuttx/net/tcp/tcp_send_unbuffered.c b/nuttx/net/tcp/tcp_send_unbuffered.c
index 22f686082..3590024ec 100644
--- a/nuttx/net/tcp/tcp_send_unbuffered.c
+++ b/nuttx/net/tcp/tcp_send_unbuffered.c
@@ -71,7 +71,7 @@
# define CONFIG_NET_TCP_SPLIT_SIZE 40
#endif
-#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
+#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Private Types
diff --git a/nuttx/net/tcp/tcp_timer.c b/nuttx/net/tcp/tcp_timer.c
index 0a10fffbf..c0482380c 100644
--- a/nuttx/net/tcp/tcp_timer.c
+++ b/nuttx/net/tcp/tcp_timer.c
@@ -100,8 +100,8 @@ void tcp_timer(FAR struct net_driver_s *dev, FAR struct tcp_conn_s *conn,
{
uint8_t result;
- dev->d_snddata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN];
- dev->d_appdata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN];
+ dev->d_snddata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev)];
+ dev->d_appdata = &dev->d_buf[IPTCP_HDRLEN + NET_LL_HDRLEN(dev)];
/* Increase the TCP sequence number */
diff --git a/nuttx/net/udp/udp_input.c b/nuttx/net/udp/udp_input.c
index 07699c8f6..5a78baa1f 100644
--- a/nuttx/net/udp/udp_input.c
+++ b/nuttx/net/udp/udp_input.c
@@ -60,7 +60,7 @@
* Pre-processor Definitions
****************************************************************************/
-#define UDPBUF ((struct udp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
+#define UDPBUF ((struct udp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Public Variables
@@ -114,7 +114,7 @@ int udp_input(FAR struct net_driver_s *dev)
dev->d_len -= IPUDP_HDRLEN;
#ifdef CONFIG_NET_UDP_CHECKSUMS
- dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN + IPUDP_HDRLEN];
+ dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPUDP_HDRLEN];
if (pbuf->udpchksum != 0 && udp_chksum(dev) != 0xffff)
{
#ifdef CONFIG_NET_STATISTICS
@@ -136,8 +136,8 @@ int udp_input(FAR struct net_driver_s *dev)
/* Set-up for the application callback */
- dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN + IPUDP_HDRLEN];
- dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN + IPUDP_HDRLEN];
+ dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPUDP_HDRLEN];
+ dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPUDP_HDRLEN];
dev->d_sndlen = 0;
/* Perform the application callback */
diff --git a/nuttx/net/udp/udp_poll.c b/nuttx/net/udp/udp_poll.c
index 1007adff0..e490b88ab 100644
--- a/nuttx/net/udp/udp_poll.c
+++ b/nuttx/net/udp/udp_poll.c
@@ -100,8 +100,8 @@ void udp_poll(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn)
{
/* Set-up for the application callback */
- dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN + IPUDP_HDRLEN];
- dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN + IPUDP_HDRLEN];
+ dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPUDP_HDRLEN];
+ dev->d_snddata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPUDP_HDRLEN];
dev->d_len = 0;
dev->d_sndlen = 0;
diff --git a/nuttx/net/udp/udp_send.c b/nuttx/net/udp/udp_send.c
index 4b5e81ab5..52951d536 100644
--- a/nuttx/net/udp/udp_send.c
+++ b/nuttx/net/udp/udp_send.c
@@ -62,7 +62,7 @@
* Pre-processor Definitions
****************************************************************************/
-#define UDPBUF ((struct udp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
+#define UDPBUF ((struct udp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Public Variables
diff --git a/nuttx/net/utils/net_chksum.c b/nuttx/net/utils/net_chksum.c
index a2eadf1bc..1fc85a7c2 100644
--- a/nuttx/net/utils/net_chksum.c
+++ b/nuttx/net/utils/net_chksum.c
@@ -54,8 +54,8 @@
* Pre-processor Definitions
****************************************************************************/
-#define BUF ((struct net_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
-#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
+#define BUF ((struct net_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
+#define ICMPBUF ((struct icmp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN(dev)])
/****************************************************************************
* Private Data
@@ -145,7 +145,7 @@ static uint16_t upper_layer_chksum(FAR struct net_driver_s *dev, uint8_t proto)
/* Sum TCP header and data. */
- sum = chksum(sum, &dev->d_buf[IP_HDRLEN + NET_LL_HDRLEN], upper_layer_len);
+ sum = chksum(sum, &dev->d_buf[IP_HDRLEN + NET_LL_HDRLEN(dev)], upper_layer_len);
return (sum == 0) ? 0xffff : htons(sum);
}
@@ -285,7 +285,7 @@ uint16_t ip_chksum(FAR struct net_driver_s *dev)
{
uint16_t sum;
- sum = chksum(0, &dev->d_buf[NET_LL_HDRLEN], IP_HDRLEN);
+ sum = chksum(0, &dev->d_buf[NET_LL_HDRLEN(dev)], IP_HDRLEN);
return (sum == 0) ? 0xffff : htons(sum);
}
#endif /* CONFIG_NET_ARCH_CHKSUM */