summaryrefslogtreecommitdiff
path: root/nuttx/net/uip
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-11-08 16:01:18 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-11-08 16:01:18 +0000
commit2239a0abb6976e310df0eb3307f089fdb23a3bbf (patch)
tree4de7080546c2d3472da727766e8d9d9a26db5f53 /nuttx/net/uip
parent4bbf891c9446414a9a1641a70bc90d294115bd6f (diff)
downloadpx4-nuttx-2239a0abb6976e310df0eb3307f089fdb23a3bbf.tar.gz
px4-nuttx-2239a0abb6976e310df0eb3307f089fdb23a3bbf.tar.bz2
px4-nuttx-2239a0abb6976e310df0eb3307f089fdb23a3bbf.zip
Eliminate most uIP globals
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@378 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/net/uip')
-rw-r--r--nuttx/net/uip/uip-initialize.c14
-rw-r--r--nuttx/net/uip/uip-internal.h8
-rw-r--r--nuttx/net/uip/uip-listen.c4
-rw-r--r--nuttx/net/uip/uip-poll.c6
-rw-r--r--nuttx/net/uip/uip-tcpcallback.c36
-rw-r--r--nuttx/net/uip/uip-tcpinput.c286
-rw-r--r--nuttx/net/uip/uip-tcppoll.c7
-rw-r--r--nuttx/net/uip/uip-tcptimer.c22
-rw-r--r--nuttx/net/uip/uip-udpcallback.c9
-rw-r--r--nuttx/net/uip/uip-udpinput.c16
-rw-r--r--nuttx/net/uip/uip-udppoll.c10
11 files changed, 189 insertions, 229 deletions
diff --git a/nuttx/net/uip/uip-initialize.c b/nuttx/net/uip/uip-initialize.c
index 42778d2c1..baed0f878 100644
--- a/nuttx/net/uip/uip-initialize.c
+++ b/nuttx/net/uip/uip-initialize.c
@@ -62,20 +62,6 @@ void *uip_urgdata; /* urgent data (out-of-band data), if present. */
uint16 uip_urglen; /* Length of (received) urgent data */
#endif
-/* The uip_flags variable is used for communication between the TCP/IP
- * stack and the application program.
- */
-
-uint8 uip_flags;
-
-/* uip_conn always points to the current connection. */
-
-struct uip_conn *uip_conn;
-
-#ifdef CONFIG_NET_UDP
-struct uip_udp_conn *uip_udp_conn;
-#endif /* CONFIG_NET_UDP */
-
#ifdef CONFIG_NET_STATISTICS
struct uip_stats uip_stat;
#endif
diff --git a/nuttx/net/uip/uip-internal.h b/nuttx/net/uip/uip-internal.h
index 4d7309f29..118ccd53f 100644
--- a/nuttx/net/uip/uip-internal.h
+++ b/nuttx/net/uip/uip-internal.h
@@ -160,9 +160,10 @@ EXTERN void uip_tcprexmit(struct uip_driver_s *dev, struct uip_conn *conn,
EXTERN void uip_tcpinput(struct uip_driver_s *dev);
-/* Defined in uip_uipcallback.c *********************************************/
+/* Defined in uip_tcpcallback.c *********************************************/
-EXTERN void uip_tcpcallback(struct uip_driver_s *dev);
+EXTERN uint8 uip_tcpcallback(struct uip_driver_s *dev,
+ struct uip_conn *conn, uint8 flags);
#ifdef CONFIG_NET_UDP
/* Defined in uip_udpconn.c *************************************************/
@@ -185,7 +186,8 @@ EXTERN void uip_udpinput(struct uip_driver_s *dev);
/* Defined in uip_uipcallback.c *********************************************/
-EXTERN void uip_udpcallback(struct uip_driver_s *dev);
+EXTERN void uip_udpcallback(struct uip_driver_s *dev,
+ struct uip_udp_conn *conn, uint8 flags);
#endif /* CONFIG_NET_UDP */
/* Defined in uip-icmpinput.c ***********************************************/
diff --git a/nuttx/net/uip/uip-listen.c b/nuttx/net/uip/uip-listen.c
index edbb9d469..f1097c40c 100644
--- a/nuttx/net/uip/uip-listen.c
+++ b/nuttx/net/uip/uip-listen.c
@@ -187,7 +187,7 @@ int uip_accept(struct uip_conn *conn, uint16 portno)
{
struct uip_conn *listener;
int ret = ERROR;
-
+
/* The interrupt logic has already allocated and initialized a TCP
* connection -- now check if is an application in place to accept the
* connection.
@@ -198,7 +198,7 @@ int uip_accept(struct uip_conn *conn, uint16 portno)
{
/* Yes.. accept the connection */
- ret = listener->accept(listener->accept_private, conn);
+ ret = listener->accept(listener, conn);
}
return ret;
}
diff --git a/nuttx/net/uip/uip-poll.c b/nuttx/net/uip/uip-poll.c
index d80b77995..f17f42e75 100644
--- a/nuttx/net/uip/uip-poll.c
+++ b/nuttx/net/uip/uip-poll.c
@@ -83,7 +83,6 @@ static int uip_polludpconnections(struct uip_driver_s *dev,
{
/* Perform the UDP TX poll */
- uip_udp_conn = udp_conn;
uip_udppoll(dev, udp_conn);
/* Call back into the driver */
@@ -91,7 +90,6 @@ static int uip_polludpconnections(struct uip_driver_s *dev,
bstop = callback(dev);
}
- uip_udp_conn = NULL;
return bstop;
}
#else
@@ -122,7 +120,6 @@ static inline int uip_polltcpconnections(struct uip_driver_s *dev,
{
/* Perform the TCP TX poll */
- uip_conn = conn;
uip_tcppoll(dev, conn);
/* Call back into the driver */
@@ -130,7 +127,6 @@ static inline int uip_polltcpconnections(struct uip_driver_s *dev,
bstop = callback(dev);
}
- uip_conn = NULL;
return bstop;
}
@@ -159,7 +155,6 @@ static inline int uip_polltcptimer(struct uip_driver_s *dev,
{
/* Perform the TCP timer poll */
- uip_conn = conn;
uip_tcptimer(dev, conn, hsec);
/* Call back into the driver */
@@ -167,7 +162,6 @@ static inline int uip_polltcptimer(struct uip_driver_s *dev,
bstop = callback(dev);
}
- uip_conn = NULL;
return bstop;
}
diff --git a/nuttx/net/uip/uip-tcpcallback.c b/nuttx/net/uip/uip-tcpcallback.c
index ad1822712..4a314e997 100644
--- a/nuttx/net/uip/uip-tcpcallback.c
+++ b/nuttx/net/uip/uip-tcpcallback.c
@@ -73,33 +73,33 @@
*
****************************************************************************/
-void uip_tcpcallback(struct uip_driver_s *dev)
+uint8 uip_tcpcallback(struct uip_driver_s *dev, struct uip_conn *conn, uint8 flags)
{
- vdbg("uip_flags: %02x\n", uip_flags);
+ uint8 ret = 0;
- /* Some sanity checking */
+ vdbg("flags: %02x\n", flags);
- if (uip_conn)
+ /* Check if there is a data callback */
+
+ if (conn->data_event)
{
- /* Check if there is a data callback */
+ /* Perform the callback */
- if (uip_conn->data_event)
- {
- /* Perform the callback */
+ ret = conn->data_event(dev, conn, flags);
+ }
- uip_conn->data_event(dev, uip_conn->data_private);
- }
+ /* Check if there is a connection-related event and a connection
+ * callback.
+ */
- /* Check if there is a connection-related event and a connection
- * callback.
- */
- if (((uip_flags & UIP_CONN_EVENTS) != 0) && uip_conn->connection_event)
- {
- /* Perform the callback */
+ if (((flags & UIP_CONN_EVENTS) != 0) && conn->connection_event)
+ {
+ /* Perform the callback */
- uip_conn->connection_event(uip_conn->connection_private);
- }
+ conn->connection_event(conn, flags);
}
+
+ return ret;
}
#endif /* CONFIG_NET */
diff --git a/nuttx/net/uip/uip-tcpinput.c b/nuttx/net/uip/uip-tcpinput.c
index 71cd54d9e..2ecd23d98 100644
--- a/nuttx/net/uip/uip-tcpinput.c
+++ b/nuttx/net/uip/uip-tcpinput.c
@@ -95,9 +95,11 @@
void uip_tcpinput(struct uip_driver_s *dev)
{
- register struct uip_conn *uip_connr = uip_conn;
+ struct uip_conn *conn = NULL;
uint16 tmp16;
uint8 opt;
+ uint8 flags;
+ uint8 result;
int len;
int i;
@@ -121,8 +123,8 @@ void uip_tcpinput(struct uip_driver_s *dev)
/* Demultiplex this segment. First check any active connections. */
- uip_connr = uip_tcpactive(BUF);
- if (uip_connr)
+ conn = uip_tcpactive(BUF);
+ if (conn)
{
goto found;
}
@@ -135,40 +137,40 @@ void uip_tcpinput(struct uip_driver_s *dev)
if ((BUF->flags & TCP_CTL) == TCP_SYN)
{
- /* This is a SYN packet for a connection. Find the connection
- * listening on this port.
- */
+ /* This is a SYN packet for a connection. Find the connection
+ * listening on this port.
+ */
- tmp16 = BUF->destport;
- if (uip_islistener(tmp16))
- {
- /* We matched the incoming packet with a connection in LISTEN.
- * We now need to create a new connection and send a SYNACK in
- * response.
- */
+ tmp16 = BUF->destport;
+ if (uip_islistener(tmp16))
+ {
+ /* We matched the incoming packet with a connection in LISTEN.
+ * We now need to create a new connection and send a SYNACK in
+ * response.
+ */
/* First allocate a new connection structure and see if there is any
* user application to accept it.
*/
- uip_connr = uip_tcpaccept(BUF);
- if (uip_connr)
+ conn = uip_tcpaccept(BUF);
+ if (conn)
{
/* The connection structure was successfully allocated. Now see
* there is an application waiting to accept the connection (or at
* least queue it it for acceptance).
*/
- if (uip_accept(uip_connr, tmp16) != OK)
+ if (uip_accept(conn, tmp16) != OK)
{
/* No, then we have to give the connection back */
- uip_tcpfree(uip_connr);
- uip_connr = NULL;
+ uip_tcpfree(conn);
+ conn = NULL;
}
}
- if (!uip_connr)
+ if (!conn)
{
/* Either (1) all available connections are in use, or (2) there is no
* application in place to accept the connection. We drop packet and hope that
@@ -183,8 +185,7 @@ void uip_tcpinput(struct uip_driver_s *dev)
goto drop;
}
- uip_incr32(uip_conn->rcv_nxt, 1);
- uip_conn = uip_connr;
+ uip_incr32(conn->rcv_nxt, 1);
/* Parse the TCP MSS option, if present. */
@@ -212,7 +213,7 @@ void uip_tcpinput(struct uip_driver_s *dev)
tmp16 = ((uint16)dev->d_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + i] << 8) |
(uint16)dev->d_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN + 3 + i];
- uip_connr->initialmss = uip_connr->mss =
+ conn->initialmss = conn->mss =
tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
/* And we are done processing options. */
@@ -240,8 +241,8 @@ void uip_tcpinput(struct uip_driver_s *dev)
/* Our response will be a SYNACK. */
- uip_tcpack(dev, uip_connr, TCP_ACK | TCP_SYN);
- goto done;
+ uip_tcpack(dev, conn, TCP_ACK | TCP_SYN);
+ return;
}
}
@@ -260,12 +261,11 @@ void uip_tcpinput(struct uip_driver_s *dev)
uip_stat.tcp.synrst++;
#endif
uip_tcpreset(dev);
- goto done;
+ return;
found:
- uip_conn = uip_connr;
- uip_flags = 0;
+ flags = 0;
/* We do a very naive form of TCP reset processing; we just accept
* any RST and kill our connection. We should in fact check if the
@@ -275,11 +275,10 @@ found:
if (BUF->flags & TCP_RST)
{
- uip_connr->tcpstateflags = UIP_CLOSED;
+ conn->tcpstateflags = UIP_CLOSED;
dbg("Recvd reset - TCP state: UIP_CLOSED\n");
- uip_flags = UIP_ABORT;
- uip_tcpcallback(dev);
+ (void)uip_tcpcallback(dev, conn, UIP_ABORT);
goto drop;
}
@@ -301,17 +300,17 @@ found:
* correct numbers in.
*/
- if (!(((uip_connr->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) &&
+ if (!(((conn->tcpstateflags & UIP_TS_MASK) == UIP_SYN_SENT) &&
((BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK))))
{
if ((dev->d_len > 0 || ((BUF->flags & (TCP_SYN | TCP_FIN)) != 0)) &&
- (BUF->seqno[0] != uip_connr->rcv_nxt[0] ||
- BUF->seqno[1] != uip_connr->rcv_nxt[1] ||
- BUF->seqno[2] != uip_connr->rcv_nxt[2] ||
- BUF->seqno[3] != uip_connr->rcv_nxt[3]))
+ (BUF->seqno[0] != conn->rcv_nxt[0] ||
+ BUF->seqno[1] != conn->rcv_nxt[1] ||
+ BUF->seqno[2] != conn->rcv_nxt[2] ||
+ BUF->seqno[3] != conn->rcv_nxt[3]))
{
- uip_tcpsend(dev, uip_connr, TCP_ACK, UIP_IPTCPH_LEN);
- goto done;
+ uip_tcpsend(dev, conn, TCP_ACK, UIP_IPTCPH_LEN);
+ return;
}
}
@@ -321,61 +320,61 @@ found:
* retransmission timer.
*/
- if ((BUF->flags & TCP_ACK) && uip_outstanding(uip_connr))
+ if ((BUF->flags & TCP_ACK) && uip_outstanding(conn))
{
/* Temporary variables. */
uint8 acc32[4];
- uip_add32(uip_connr->snd_nxt, uip_connr->len, acc32);
+ uip_add32(conn->snd_nxt, conn->len, acc32);
if (BUF->ackno[0] == acc32[0] && BUF->ackno[1] == acc32[1] &&
BUF->ackno[2] == acc32[2] && BUF->ackno[3] == acc32[3])
{
/* Update sequence number. */
- uip_connr->snd_nxt[0] = acc32[0];
- uip_connr->snd_nxt[1] = acc32[1];
- uip_connr->snd_nxt[2] = acc32[2];
- uip_connr->snd_nxt[3] = acc32[3];
+ conn->snd_nxt[0] = acc32[0];
+ conn->snd_nxt[1] = acc32[1];
+ conn->snd_nxt[2] = acc32[2];
+ conn->snd_nxt[3] = acc32[3];
/* Do RTT estimation, unless we have done retransmissions. */
- if (uip_connr->nrtx == 0)
+ if (conn->nrtx == 0)
{
signed char m;
- m = uip_connr->rto - uip_connr->timer;
+ m = conn->rto - conn->timer;
/* This is taken directly from VJs original code in his paper */
- m = m - (uip_connr->sa >> 3);
- uip_connr->sa += m;
+ m = m - (conn->sa >> 3);
+ conn->sa += m;
if (m < 0)
{
m = -m;
}
- m = m - (uip_connr->sv >> 2);
- uip_connr->sv += m;
- uip_connr->rto = (uip_connr->sa >> 3) + uip_connr->sv;
+ m = m - (conn->sv >> 2);
+ conn->sv += m;
+ conn->rto = (conn->sa >> 3) + conn->sv;
}
/* Set the acknowledged flag. */
- uip_flags = UIP_ACKDATA;
+ flags = UIP_ACKDATA;
/* Reset the retransmission timer. */
- uip_connr->timer = uip_connr->rto;
+ conn->timer = conn->rto;
/* Reset length of outstanding data. */
- uip_connr->len = 0;
+ conn->len = 0;
}
}
/* Do different things depending on in what state the connection is. */
- switch(uip_connr->tcpstateflags & UIP_TS_MASK)
+ switch (conn->tcpstateflags & UIP_TS_MASK)
{
/* CLOSED and LISTEN are not handled here. CLOSE_WAIT is not
* implemented, since we force the application to close when the
@@ -390,24 +389,24 @@ found:
* flag set. If so, we enter the ESTABLISHED state.
*/
- if (uip_flags & UIP_ACKDATA)
+ if (flags & UIP_ACKDATA)
{
- uip_connr->tcpstateflags = UIP_ESTABLISHED;
- uip_connr->len = 0;
+ conn->tcpstateflags = UIP_ESTABLISHED;
+ conn->len = 0;
vdbg("TCP state: UIP_ESTABLISHED\n");
- uip_flags = UIP_CONNECTED;
+ flags = UIP_CONNECTED;
if (dev->d_len > 0)
{
- uip_flags |= UIP_NEWDATA;
- uip_incr32(uip_conn->rcv_nxt, dev->d_len);
+ flags |= UIP_NEWDATA;
+ uip_incr32(conn->rcv_nxt, dev->d_len);
}
- dev->d_sndlen = 0;
- uip_tcpcallback(dev);
- uip_tcpappsend(dev, uip_connr, uip_flags);
- goto done;
+ dev->d_sndlen = 0;
+ result = uip_tcpcallback(dev, conn, flags);
+ uip_tcpappsend(dev, conn, result);
+ return;
}
goto drop;
@@ -418,8 +417,7 @@ found:
* state.
*/
- if ((uip_flags & UIP_ACKDATA) &&
- (BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK))
+ if ((flags & UIP_ACKDATA) && (BUF->flags & TCP_CTL) == (TCP_SYN | TCP_ACK))
{
/* Parse the TCP MSS option, if present. */
@@ -448,8 +446,8 @@ found:
tmp16 =
(dev->d_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 2 + i] << 8) |
dev->d_buf[UIP_TCPIP_HLEN + UIP_LLH_LEN + 3 + i];
- uip_connr->initialmss =
- uip_connr->mss =
+ conn->initialmss =
+ conn->mss =
tmp16 > UIP_TCP_MSS? UIP_TCP_MSS: tmp16;
/* And we are done processing options. */
@@ -475,31 +473,29 @@ found:
}
}
- uip_connr->tcpstateflags = UIP_ESTABLISHED;
- uip_connr->rcv_nxt[0] = BUF->seqno[0];
- uip_connr->rcv_nxt[1] = BUF->seqno[1];
- uip_connr->rcv_nxt[2] = BUF->seqno[2];
- uip_connr->rcv_nxt[3] = BUF->seqno[3];
+ conn->tcpstateflags = UIP_ESTABLISHED;
+ conn->rcv_nxt[0] = BUF->seqno[0];
+ conn->rcv_nxt[1] = BUF->seqno[1];
+ conn->rcv_nxt[2] = BUF->seqno[2];
+ conn->rcv_nxt[3] = BUF->seqno[3];
vdbg("TCP state: UIP_ESTABLISHED\n");
- uip_incr32(uip_conn->rcv_nxt, 1);
- uip_flags = UIP_CONNECTED | UIP_NEWDATA;
- uip_connr->len = 0;
- dev->d_len = 0;
- dev->d_sndlen = 0;
- uip_tcpcallback(dev);
- uip_tcpappsend(dev, uip_connr, uip_flags);
- goto done;
+ uip_incr32(conn->rcv_nxt, 1);
+ conn->len = 0;
+ dev->d_len = 0;
+ dev->d_sndlen = 0;
+ result = uip_tcpcallback(dev, conn, UIP_CONNECTED | UIP_NEWDATA);
+ uip_tcpappsend(dev, conn, result);
+ return;
}
/* Inform the application that the connection failed */
- uip_flags = UIP_ABORT;
- uip_tcpcallback(dev);
+ (void)uip_tcpcallback(dev, conn, UIP_ABORT);
/* The connection is closed after we send the RST */
- uip_conn->tcpstateflags = UIP_CLOSED;
+ conn->tcpstateflags = UIP_CLOSED;
vdbg("TCP state: UIP_CLOSED\n");
/* We do not send resets in response to resets. */
@@ -509,7 +505,7 @@ found:
goto drop;
}
uip_tcpreset(dev);
- goto done;
+ return;
case UIP_ESTABLISHED:
/* In the ESTABLISHED state, we call upon the application to feed
@@ -524,30 +520,30 @@ found:
* sequence numbers will be screwed up.
*/
- if (BUF->flags & TCP_FIN && !(uip_connr->tcpstateflags & UIP_STOPPED))
+ if (BUF->flags & TCP_FIN && !(conn->tcpstateflags & UIP_STOPPED))
{
- if (uip_outstanding(uip_connr))
+ if (uip_outstanding(conn))
{
goto drop;
}
- uip_incr32(uip_conn->rcv_nxt, dev->d_len + 1);
- uip_flags |= UIP_CLOSE;
+ uip_incr32(conn->rcv_nxt, dev->d_len + 1);
+ flags |= UIP_CLOSE;
if (dev->d_len > 0)
{
- uip_flags |= UIP_NEWDATA;
+ flags |= UIP_NEWDATA;
}
- uip_tcpcallback(dev);
+ (void)uip_tcpcallback(dev, conn, flags);
- uip_connr->tcpstateflags = UIP_LAST_ACK;
- uip_connr->len = 1;
- uip_connr->nrtx = 0;
+ conn->tcpstateflags = UIP_LAST_ACK;
+ conn->len = 1;
+ conn->nrtx = 0;
vdbg("TCP state: UIP_LAST_ACK\n");
- uip_tcpsend(dev, uip_connr, TCP_FIN | TCP_ACK, UIP_IPTCPH_LEN);
- goto done;
+ uip_tcpsend(dev, conn, TCP_FIN | TCP_ACK, UIP_IPTCPH_LEN);
+ return;
}
/* Check the URG flag. If this is set, the segment carries urgent
@@ -563,7 +559,7 @@ found:
uip_urglen = dev->d_len;
}
- uip_incr32(uip_conn->rcv_nxt, uip_urglen);
+ uip_incr32(conn->rcv_nxt, uip_urglen);
dev->d_len -= uip_urglen;
uip_urgdata = dev->d_appdata;
dev->d_appdata += uip_urglen;
@@ -586,10 +582,10 @@ found:
* remote host.
*/
- if (dev->d_len > 0 && !(uip_connr->tcpstateflags & UIP_STOPPED))
+ if (dev->d_len > 0 && !(conn->tcpstateflags & UIP_STOPPED))
{
- uip_flags |= UIP_NEWDATA;
- uip_incr32(uip_conn->rcv_nxt, dev->d_len);
+ flags |= UIP_NEWDATA;
+ uip_incr32(conn->rcv_nxt, dev->d_len);
}
/* Check if the available buffer space advertised by the other end
@@ -606,11 +602,11 @@ found:
*/
tmp16 = ((uint16)BUF->wnd[0] << 8) + (uint16)BUF->wnd[1];
- if (tmp16 > uip_connr->initialmss || tmp16 == 0)
+ if (tmp16 > conn->initialmss || tmp16 == 0)
{
- tmp16 = uip_connr->initialmss;
+ tmp16 = conn->initialmss;
}
- uip_connr->mss = tmp16;
+ conn->mss = tmp16;
/* If this packet constitutes an ACK for outstanding data (flagged
* by the UIP_ACKDATA flag, we should call the application since it
@@ -630,12 +626,12 @@ found:
* send, d_len must be set to 0.
*/
- if (uip_flags & (UIP_NEWDATA | UIP_ACKDATA))
+ if (flags & (UIP_NEWDATA | UIP_ACKDATA))
{
dev->d_sndlen = 0;
- uip_tcpcallback(dev);
- uip_tcpappsend(dev, uip_connr, uip_flags);
- goto done;
+ result = uip_tcpcallback(dev, conn, flags);
+ uip_tcpappsend(dev, conn, result);
+ return;
}
goto drop;
@@ -644,13 +640,12 @@ found:
* FIN. This is indicated by the UIP_ACKDATA flag.
*/
- if (uip_flags & UIP_ACKDATA)
+ if (flags & UIP_ACKDATA)
{
- uip_connr->tcpstateflags = UIP_CLOSED;
+ conn->tcpstateflags = UIP_CLOSED;
vdbg("TCP state: UIP_CLOSED\n");
- uip_flags = UIP_CLOSE;
- uip_tcpcallback(dev);
+ (void)uip_tcpcallback(dev, conn, UIP_CLOSE);
}
break;
@@ -662,90 +657,85 @@ found:
if (dev->d_len > 0)
{
- uip_incr32(uip_conn->rcv_nxt, dev->d_len);
+ uip_incr32(conn->rcv_nxt, dev->d_len);
}
if (BUF->flags & TCP_FIN)
{
- if (uip_flags & UIP_ACKDATA)
+ if (flags & UIP_ACKDATA)
{
- uip_connr->tcpstateflags = UIP_TIME_WAIT;
- uip_connr->timer = 0;
- uip_connr->len = 0;
+ conn->tcpstateflags = UIP_TIME_WAIT;
+ conn->timer = 0;
+ conn->len = 0;
vdbg("TCP state: UIP_TIME_WAIT\n");
}
else
{
- uip_connr->tcpstateflags = UIP_CLOSING;
+ conn->tcpstateflags = UIP_CLOSING;
vdbg("TCP state: UIP_CLOSING\n");
}
- uip_incr32(uip_conn->rcv_nxt, 1);
- uip_flags = UIP_CLOSE;
- uip_tcpcallback(dev);
- uip_tcpsend(dev, uip_connr, TCP_ACK, UIP_IPTCPH_LEN);
- goto done;
+ uip_incr32(conn->rcv_nxt, 1);
+ (void)uip_tcpcallback(dev, conn, UIP_CLOSE);
+ uip_tcpsend(dev, conn, TCP_ACK, UIP_IPTCPH_LEN);
+ return;
}
- else if (uip_flags & UIP_ACKDATA)
+ else if (flags & UIP_ACKDATA)
{
- uip_connr->tcpstateflags = UIP_FIN_WAIT_2;
- uip_connr->len = 0;
+ conn->tcpstateflags = UIP_FIN_WAIT_2;
+ conn->len = 0;
vdbg("TCP state: UIP_FIN_WAIT_2\n");
goto drop;
}
if (dev->d_len > 0)
{
- uip_tcpsend(dev, uip_connr, TCP_ACK, UIP_IPTCPH_LEN);
- goto done;
+ uip_tcpsend(dev, conn, TCP_ACK, UIP_IPTCPH_LEN);
+ return;
}
goto drop;
case UIP_FIN_WAIT_2:
if (dev->d_len > 0)
{
- uip_incr32(uip_conn->rcv_nxt, dev->d_len);
+ uip_incr32(conn->rcv_nxt, dev->d_len);
}
if (BUF->flags & TCP_FIN)
{
- uip_connr->tcpstateflags = UIP_TIME_WAIT;
- uip_connr->timer = 0;
+ conn->tcpstateflags = UIP_TIME_WAIT;
+ conn->timer = 0;
vdbg("TCP state: UIP_TIME_WAIT\n");
- uip_incr32(uip_conn->rcv_nxt, 1);
- uip_flags = UIP_CLOSE;
- uip_tcpcallback(dev);
- uip_tcpsend(dev, uip_connr, TCP_ACK, UIP_IPTCPH_LEN);
- goto done;
+ uip_incr32(conn->rcv_nxt, 1);
+ (void)uip_tcpcallback(dev, conn, UIP_CLOSE);
+ uip_tcpsend(dev, conn, TCP_ACK, UIP_IPTCPH_LEN);
+ return;
}
if (dev->d_len > 0)
{
- uip_tcpsend(dev, uip_connr, TCP_ACK, UIP_IPTCPH_LEN);
- goto done;
+ uip_tcpsend(dev, conn, TCP_ACK, UIP_IPTCPH_LEN);
+ return;
}
goto drop;
case UIP_TIME_WAIT:
- uip_tcpsend(dev, uip_connr, TCP_ACK, UIP_IPTCPH_LEN);
- goto done;
+ uip_tcpsend(dev, conn, TCP_ACK, UIP_IPTCPH_LEN);
+ return;
case UIP_CLOSING:
- if (uip_flags & UIP_ACKDATA)
+ if (flags & UIP_ACKDATA)
{
- uip_connr->tcpstateflags = UIP_TIME_WAIT;
- uip_connr->timer = 0;
+ conn->tcpstateflags = UIP_TIME_WAIT;
+ conn->timer = 0;
vdbg("TCP state: UIP_TIME_WAIT\n");
}
- }
- goto drop;
-done:
- uip_flags = 0;
- return;
+ default:
+ break;
+ }
drop:
- uip_flags = 0;
dev->d_len = 0;
}
diff --git a/nuttx/net/uip/uip-tcppoll.c b/nuttx/net/uip/uip-tcppoll.c
index f2deac0fa..9b66ef707 100644
--- a/nuttx/net/uip/uip-tcppoll.c
+++ b/nuttx/net/uip/uip-tcppoll.c
@@ -94,6 +94,8 @@
void uip_tcppoll(struct uip_driver_s *dev, struct uip_conn *conn)
{
+ uint8 result;
+
/* Verify that the connection is established and if the connection has
* oustanding (unacknowledged) sent data.
*/
@@ -111,12 +113,11 @@ void uip_tcppoll(struct uip_driver_s *dev, struct uip_conn *conn)
/* Perfom the callback */
- uip_flags = UIP_POLL;
- uip_tcpcallback(dev);
+ result = uip_tcpcallback(dev, conn, UIP_POLL);
/* Handle the callback response */
- uip_tcpappsend(dev, conn, uip_flags);
+ uip_tcpappsend(dev, conn, result);
}
else
{
diff --git a/nuttx/net/uip/uip-tcptimer.c b/nuttx/net/uip/uip-tcptimer.c
index 66210e246..beb16bc0f 100644
--- a/nuttx/net/uip/uip-tcptimer.c
+++ b/nuttx/net/uip/uip-tcptimer.c
@@ -95,6 +95,8 @@
void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn, int hsec)
{
+ uint8 result;
+
dev->d_snddata = &dev->d_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN];
dev->d_appdata = &dev->d_buf[UIP_IPTCPH_LEN + UIP_LLH_LEN];
@@ -157,13 +159,12 @@ void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn, int hsec)
conn->tcpstateflags = UIP_CLOSED;
vdbg("TCP state: UIP_CLOSED\n");
- /* We call uip_tcpcallback() with uip_flags set to
- * UIP_TIMEDOUT to inform the application that the
- * connection has timed out.
+ /* We call uip_tcpcallback() with UIP_TIMEDOUT to
+ * inform the application that the connection has
+ * timed out.
*/
- uip_flags = UIP_TIMEDOUT;
- uip_tcpcallback(dev);
+ result = uip_tcpcallback(dev, conn, UIP_TIMEDOUT);
/* We also send a reset packet to the remote host. */
@@ -209,9 +210,8 @@ void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn, int hsec)
* the code for sending out the packet.
*/
- uip_flags = UIP_REXMIT;
- uip_tcpcallback(dev);
- uip_tcprexmit(dev, conn, uip_flags);
+ result = uip_tcpcallback(dev, conn, UIP_REXMIT);
+ uip_tcprexmit(dev, conn, result);
goto done;
case UIP_FIN_WAIT_1:
@@ -233,9 +233,8 @@ void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn, int hsec)
* application for new data.
*/
- uip_flags = UIP_POLL;
- uip_tcpcallback(dev);
- uip_tcpappsend(dev, conn, uip_flags);
+ result = uip_tcpcallback(dev, conn, UIP_POLL);
+ uip_tcpappsend(dev, conn, result);
goto done;
}
}
@@ -245,7 +244,6 @@ void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn, int hsec)
dev->d_len = 0;
done:
- uip_flags = 0;
return;
}
diff --git a/nuttx/net/uip/uip-udpcallback.c b/nuttx/net/uip/uip-udpcallback.c
index ed283d193..29ee7d736 100644
--- a/nuttx/net/uip/uip-udpcallback.c
+++ b/nuttx/net/uip/uip-udpcallback.c
@@ -73,17 +73,18 @@
*
****************************************************************************/
-void uip_udpcallback(struct uip_driver_s *dev)
+void uip_udpcallback(struct uip_driver_s *dev, struct uip_udp_conn *conn,
+ uint8 flags)
{
- vdbg("uip_flags: %02x\n", uip_flags);
+ vdbg("flags: %02x\n", flags);
/* Some sanity checking */
- if (uip_udp_conn && uip_udp_conn->event)
+ if (conn && conn->event)
{
/* Perform the callback */
- uip_udp_conn->event(dev, uip_udp_conn->private);
+ conn->event(dev, conn, flags);
}
}
diff --git a/nuttx/net/uip/uip-udpinput.c b/nuttx/net/uip/uip-udpinput.c
index 6bd347355..46e673402 100644
--- a/nuttx/net/uip/uip-udpinput.c
+++ b/nuttx/net/uip/uip-udpinput.c
@@ -95,6 +95,8 @@
void uip_udpinput(struct uip_driver_s *dev)
{
+ struct uip_udp_conn *conn;
+
/* UDP processing is really just a hack. We don't do anything to the UDP/IP
* headers, but let the UDP application do all the hard work. If the
* application sets d_sndlen, it has a packet to send.
@@ -117,31 +119,25 @@ void uip_udpinput(struct uip_driver_s *dev)
{
/* Demultiplex this UDP packet between the UDP "connections". */
- uip_udp_conn = uip_udpactive(UDPBUF);
- if (uip_udp_conn)
+ conn = uip_udpactive(UDPBUF);
+ if (conn)
{
/* Setup for the application callback */
- uip_conn = NULL;
-
dev->d_appdata = &dev->d_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
dev->d_snddata = &dev->d_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
dev->d_sndlen = 0;
/* Perform the application callback */
- uip_flags = UIP_NEWDATA;
- uip_udpcallback(dev);
- uip_flags = 0;
+ uip_udpcallback(dev, conn, UIP_NEWDATA);
/* If the application has data to send, setup the UDP/IP header */
if (dev->d_sndlen > 0)
{
- uip_udpsend(dev, uip_udp_conn);
+ uip_udpsend(dev, conn);
}
-
- uip_udp_conn = NULL;
}
else
{
diff --git a/nuttx/net/uip/uip-udppoll.c b/nuttx/net/uip/uip-udppoll.c
index aa5a205bc..e664fcd73 100644
--- a/nuttx/net/uip/uip-udppoll.c
+++ b/nuttx/net/uip/uip-udppoll.c
@@ -100,9 +100,6 @@ void uip_udppoll(struct uip_driver_s *dev, struct uip_udp_conn *conn)
{
/* Setup for the application callback */
- uip_conn = NULL;
- uip_udp_conn = conn;
-
dev->d_appdata = &dev->d_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
dev->d_snddata = &dev->d_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN];
@@ -111,16 +108,13 @@ void uip_udppoll(struct uip_driver_s *dev, struct uip_udp_conn *conn)
/* Perform the application callback */
- uip_flags = UIP_POLL;
- uip_udpcallback(dev);
+ uip_udpcallback(dev, conn, UIP_POLL);
/* If the application has data to send, setup the UDP/IP header */
if (dev->d_sndlen > 0)
{
uip_udpsend(dev, conn);
- uip_udp_conn = NULL;
- uip_flags = 0;
return;
}
}
@@ -128,8 +122,6 @@ void uip_udppoll(struct uip_driver_s *dev, struct uip_udp_conn *conn)
/* Make sure that d_len is zerp meaning that there is nothing to be sent */
dev->d_len = 0;
- uip_udp_conn = NULL;
- uip_flags = 0;
}
#endif /* CONFIG_NET && CONFIG_NET_UDP */