summaryrefslogtreecommitdiff
path: root/nuttx/net/tcp
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 /nuttx/net/tcp
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
Diffstat (limited to 'nuttx/net/tcp')
-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
8 files changed, 40 insertions, 34 deletions
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 */