diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-11-08 16:01:18 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-11-08 16:01:18 +0000 |
commit | 2239a0abb6976e310df0eb3307f089fdb23a3bbf (patch) | |
tree | 4de7080546c2d3472da727766e8d9d9a26db5f53 /nuttx/net | |
parent | 4bbf891c9446414a9a1641a70bc90d294115bd6f (diff) | |
download | px4-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')
-rw-r--r-- | nuttx/net/accept.c | 30 | ||||
-rw-r--r-- | nuttx/net/connect.c | 37 | ||||
-rw-r--r-- | nuttx/net/recvfrom.c | 353 | ||||
-rw-r--r-- | nuttx/net/send.c | 31 | ||||
-rw-r--r-- | nuttx/net/sendto.c | 13 | ||||
-rw-r--r-- | nuttx/net/uip/uip-initialize.c | 14 | ||||
-rw-r--r-- | nuttx/net/uip/uip-internal.h | 8 | ||||
-rw-r--r-- | nuttx/net/uip/uip-listen.c | 4 | ||||
-rw-r--r-- | nuttx/net/uip/uip-poll.c | 6 | ||||
-rw-r--r-- | nuttx/net/uip/uip-tcpcallback.c | 36 | ||||
-rw-r--r-- | nuttx/net/uip/uip-tcpinput.c | 286 | ||||
-rw-r--r-- | nuttx/net/uip/uip-tcppoll.c | 7 | ||||
-rw-r--r-- | nuttx/net/uip/uip-tcptimer.c | 22 | ||||
-rw-r--r-- | nuttx/net/uip/uip-udpcallback.c | 9 | ||||
-rw-r--r-- | nuttx/net/uip/uip-udpinput.c | 16 | ||||
-rw-r--r-- | nuttx/net/uip/uip-udppoll.c | 10 |
16 files changed, 474 insertions, 408 deletions
diff --git a/nuttx/net/accept.c b/nuttx/net/accept.c index 66c05e989..34318190d 100644 --- a/nuttx/net/accept.c +++ b/nuttx/net/accept.c @@ -61,7 +61,6 @@ struct accept_s #else FAR const struct sockaddr_in *acpt_addr; /* Return connection adress */ #endif - FAR struct uip_conn *acpt_listenconn; /* The listener connection */ FAR struct uip_conn *acpt_newconn; /* The accepted connection */ int acpt_result; /* The result of the wait */ }; @@ -80,11 +79,21 @@ struct accept_s * Description: * Receive interrupt level callbacks when connections occur * + * Parameters: + * listener The conection stucture of the listener + * conn The connection stucture that was just accepted + * + * Returned Value: + * None + * + * Assumptions: + * Running at the interrupt level + * ****************************************************************************/ -static int accept_interrupt(void *private, struct uip_conn *conn) +static int accept_interrupt(struct uip_conn *listener, struct uip_conn *conn) { - struct accept_s *pstate = (struct accept_s *)private; + struct accept_s *pstate = (struct accept_s *)listener->accept_private; int ret = -EINVAL; if (pstate) { @@ -92,16 +101,16 @@ static int accept_interrupt(void *private, struct uip_conn *conn) #warning "need to return the address of the connection" /* Save the connection structure */ - - pstate->acpt_newconn = conn; - pstate->acpt_result = OK; + + pstate->acpt_newconn = conn; + pstate->acpt_result = OK; sem_post(&pstate->acpt_sem); - + /* Stop any further callbacks */ - pstate->acpt_listenconn->accept_private = NULL; - pstate->acpt_listenconn->accept = NULL; - ret = OK; + listener->accept_private = NULL; + listener->accept = NULL; + ret = OK; } return ret; } @@ -275,7 +284,6 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) save = irqsave(); state.acpt_addr = inaddr; - state.acpt_listenconn = psock->s_conn; state.acpt_newconn = NULL; state.acpt_result = OK; diff --git a/nuttx/net/connect.c b/nuttx/net/connect.c index 47047b3cf..56aee612c 100644 --- a/nuttx/net/connect.c +++ b/nuttx/net/connect.c @@ -65,11 +65,12 @@ struct tcp_connect_s * Private Function Prototypes ****************************************************************************/ -static void connection_event(void *private); +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); static inline void tcp_teardown_callbacks(struct uip_conn *conn, int status); -static void tcp_connect_interrupt(struct uip_driver_s *dev, void *private); +static uint8 tcp_connect_interrupt(struct uip_driver_s *dev, + struct uip_conn *conn, uint8 flags); #ifdef CONFIG_NET_IPv6 static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in6 *inaddr); #else @@ -87,7 +88,8 @@ static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in * * Parameters: * dev The sructure of the network driver that caused the interrupt - * private An instance of struct recvfrom_s cast to void* + * conn The connection structure associated with the socket + * flags Set of events describing why the callback was invoked * * Returned Value: * None @@ -97,19 +99,19 @@ static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in * ****************************************************************************/ -static void connection_event(void *private) +static void connection_event(struct uip_conn *conn, uint8 flags) { - FAR struct socket *psock = (FAR struct socket *)private; + FAR struct socket *psock = (FAR struct socket *)conn->connection_private; if (psock) { - vdbg("uip_flags: %02x s_flags: %02x\n", uip_flags, psock->s_flags); + vdbg("flags: %02x s_flags: %02x\n", flags, psock->s_flags); /* UIP_CLOSE: The remote host has closed the connection * UIP_ABORT: The remote host has aborted the connection * UIP_TIMEDOUT: Connection aborted due to too many retransmissions. */ - if ((uip_flags & (UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT)) != 0) + if ((flags & (UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT)) != 0) { /* Indicate that the socket is no longer connected */ @@ -118,7 +120,7 @@ static void connection_event(void *private) /* UIP_CONNECTED: The socket is successfully connected */ - else if ((uip_flags & UIP_CONNECTED) != 0) + else if ((flags & UIP_CONNECTED) != 0) { /* Indicate that the socket is now connected */ @@ -178,7 +180,8 @@ static inline void tcp_teardown_callbacks(struct uip_conn *conn, int status) * * Parameters: * dev The sructure of the network driver that caused the interrupt - * private An instance of struct recvfrom_s cast to void* + * conn The connection structure associated with the socket + * flags Set of events describing why the callback was invoked * * Returned Value: * None @@ -188,11 +191,12 @@ static inline void tcp_teardown_callbacks(struct uip_conn *conn, int status) * ****************************************************************************/ -static void tcp_connect_interrupt(struct uip_driver_s *dev, void *private) +static uint8 tcp_connect_interrupt(struct uip_driver_s *dev, + struct uip_conn *conn, uint8 flags) { - struct tcp_connect_s *pstate = (struct tcp_connect_s *)private; + struct tcp_connect_s *pstate = (struct tcp_connect_s *)conn->data_private; - vdbg("uip_flags: %02x\n", uip_flags); + vdbg("flags: %02x\n", flags); /* 'private' might be null in some race conditions (?) */ @@ -213,7 +217,7 @@ static void tcp_connect_interrupt(struct uip_driver_s *dev, void *private) * UIP_ABORT: The remote host has aborted the connection */ - if ((uip_flags & (UIP_CLOSE|UIP_ABORT)) != 0) + if ((flags & (UIP_CLOSE|UIP_ABORT)) != 0) { /* Indicate that remote host refused the connection */ @@ -222,7 +226,7 @@ static void tcp_connect_interrupt(struct uip_driver_s *dev, void *private) /* UIP_TIMEDOUT: Connection aborted due to too many retransmissions. */ - else if ((uip_flags & UIP_TIMEDOUT) != 0) + else if ((flags & UIP_TIMEDOUT) != 0) { /* Indicate that the remote host is unreachable (or should this be timedout?) */ @@ -231,7 +235,7 @@ static void tcp_connect_interrupt(struct uip_driver_s *dev, void *private) /* UIP_CONNECTED: The socket is successfully connected */ - else if ((uip_flags & UIP_CONNECTED) != 0) + else if ((flags & UIP_CONNECTED) != 0) { /* Indicate that the socket is no longer connected */ @@ -242,7 +246,7 @@ static void tcp_connect_interrupt(struct uip_driver_s *dev, void *private) else { - return; + return 0; } vdbg("Resuming: %d\n", pstate->tc_result); @@ -255,6 +259,7 @@ static void tcp_connect_interrupt(struct uip_driver_s *dev, void *private) sem_post(&pstate->tc_sem); } + return 0; } /**************************************************************************** diff --git a/nuttx/net/recvfrom.c b/nuttx/net/recvfrom.c index 149abc10b..579013913 100644 --- a/nuttx/net/recvfrom.c +++ b/nuttx/net/recvfrom.c @@ -81,15 +81,14 @@ struct recvfrom_s ****************************************************************************/ /**************************************************************************** - * Function: recvfrom_interrupt + * Function: recvfrom_newdata * * Description: - * This function is called from the interrupt level to perform the actual - * receive operation via by the uIP layer. + * Copy the read data from the packet * * Parameters: * dev The sructure of the network driver that caused the interrupt - * private An instance of struct recvfrom_s cast to void* + * pstate recvfrom state structure * * Returned Value: * None @@ -99,81 +98,140 @@ struct recvfrom_s * ****************************************************************************/ -static void recvfrom_interrupt(struct uip_driver_s *dev, void *private) +static void recvfrom_newdata(struct uip_driver_s *dev, struct recvfrom_s *pstate) { - struct recvfrom_s *pstate = (struct recvfrom_s *)private; -#if defined(CONFIG_NET_SOCKOPTS) && !defined(CONFIG_DISABLE_CLOCK) - FAR struct socket *psock; -#endif size_t recvlen; - vdbg("uip_flags: %02x\n", uip_flags); - - /* 'private' might be null in some race conditions (?) */ + /* Get the length of the data to return */ - if (pstate) + if (dev->d_len > pstate->rf_buflen) { + recvlen = pstate->rf_buflen; + } + else + { + recvlen = dev->d_len; + } + + /* Copy the new appdata into the user buffer */ + + memcpy(pstate->rf_buffer, dev->d_appdata, recvlen); + vdbg("Received %d bytes (of %d)\n", recvlen, dev->d_len); + + /* Update the accumulated size of the data read */ + + pstate->rf_recvlen += recvlen; + pstate->rf_buffer += recvlen; + pstate->rf_buflen -= recvlen; +} + +/**************************************************************************** + * Function: recvfrom_timeout + * + * Description: + * Check for recvfrom timeout. + * + * Parameters: + * pstate recvfrom state structure + * + * Returned Value: + * TRUE:timeout FALSE:no timeout + * + * Assumptions: + * Running at the interrupt level + * + ****************************************************************************/ + #if defined(CONFIG_NET_SOCKOPTS) && !defined(CONFIG_DISABLE_CLOCK) +static int recvfrom_timeout(struct recvfrom_s *pstate) +{ + FAR struct socket *psock = 0; + socktimeo_t timeo = 0; + + /* If this is a TCP socket that has already received some data, + * than we will always use a short timeout. + */ + + if (pstate->rf_recvlen > 0) + { + /* Use the short timeout */ + + timeo = TCP_TIMEO; + } + + /* No.. check for a timeout configured via setsockopts(SO_RCVTIMEO). + * If none... we well let the read hang forever. + */ + + else + { /* Get the socket reference from the private data */ psock = pstate->rf_sock; -#endif + if (psock) + { + timeo = psock->s_rcvtimeo; + } + } - /* If new data is available, then complete the read action. */ + /* Is there an effective timeout? */ - if (uip_newdata_event()) - { - /* Get the length of the data to return */ + if (timeo) + { + /* Yes.. Check if the timeout has elapsed */ - if (dev->d_len > pstate->rf_buflen) - { - recvlen = pstate->rf_buflen; - } - else - { - recvlen = dev->d_len; - } + return net_timeo(pstate->rf_starttime, timeo); + } - /* Copy the new appdata into the user buffer */ + /* No timeout */ - memcpy(pstate->rf_buffer, dev->d_appdata, recvlen); - vdbg("Received %d bytes (of %d)\n", recvlen, dev->d_len); + return FALSE; +} +#endif /* CONFIG_NET_SOCKOPTS && !CONFIG_DISABLE_CLOCK */ - /* Update the accumulated size of the data read */ +/**************************************************************************** + * Function: recvfrom_tcpinterrupt + * + * Description: + * This function is called from the interrupt level to perform the actual + * TCP receive operation via by the uIP layer. + * + * Parameters: + * dev The sructure of the network driver that caused the interrupt + * conn The connection structure associated with the socket + * flags Set of events describing why the callback was invoked + * + * Returned Value: + * None + * + * Assumptions: + * Running at the interrupt level + * + ****************************************************************************/ - pstate->rf_recvlen += recvlen; - pstate->rf_buffer += recvlen; - pstate->rf_buflen -= recvlen; +static uint8 recvfrom_tcpinterrupt(struct uip_driver_s *dev, + struct uip_conn *conn, uint8 flags) +{ + struct recvfrom_s *pstate = (struct recvfrom_s *)conn->data_private; - /* Are we finished? If this is a UDP socket or if the user - * buffer has been filled, then we are finished. - */ + vdbg("flags: %02x\n", flags); -#ifdef CONFIG_NET_UDP - if (psock->s_type == SOCK_DGRAM) - { - struct uip_udp_conn *udp_conn; + /* 'private' might be null in some race conditions (?) */ - vdbg("UDP resume\n"); + if (pstate) + { + /* If new data is available, then complete the read action. */ - /* Don't allow any further UDP call backs. */ + if (uip_newdata_event(flags)) + { + /* Copy the data from the packet */ - udp_conn = (struct uip_udp_conn *)psock->s_conn; - udp_conn->private = NULL; - udp_conn->event = NULL; + recvfrom_newdata(dev, pstate); - /* Wake up the waiting thread, returning the number of bytes - * actually read. - */ + /* If the user buffer has been filled, then we are finished. */ - sem_post(&pstate->rf_sem); - } - else -#endif if (pstate->rf_buflen == 0) { - struct uip_conn *conn; - vdbg("TCP resume\n"); /* The TCP receive buffer is full. Return now, perhaps truncating @@ -182,7 +240,6 @@ static void recvfrom_interrupt(struct uip_driver_s *dev, void *private) * Don't allow any further TCP call backs. */ - conn = (struct uip_conn *)psock->s_conn; conn->data_private = NULL; conn->data_event = NULL; @@ -204,26 +261,14 @@ static void recvfrom_interrupt(struct uip_driver_s *dev, void *private) /* Check for a loss of connection */ - else if ((uip_flags & (UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT)) != 0) + else if ((flags & (UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT)) != 0) { vdbg("error\n"); /* Stop further callbacks */ -#ifdef CONFIG_NET_UDP - if (psock->s_type == SOCK_DGRAM) - { - struct uip_udp_conn *udp_conn = (struct uip_udp_conn *)psock->s_conn; - udp_conn->private = NULL; - udp_conn->event = NULL; - } - else -#endif - { - struct uip_conn *conn = (struct uip_conn *)psock->s_conn; - conn->data_private = NULL; - conn->data_event = NULL; - } + conn->data_private = NULL; + conn->data_event = NULL; /* Report not connected */ @@ -239,92 +284,140 @@ static void recvfrom_interrupt(struct uip_driver_s *dev, void *private) */ #if defined(CONFIG_NET_SOCKOPTS) && !defined(CONFIG_DISABLE_CLOCK) - else + else if (recvfrom_timeout(pstate)) { - socktimeo_t timeo; - - /* If this is a TCP socket that has already received some data, - * than we will always use a short timeout. + /* Yes.. the timeout has elapsed... do not allow any further + * callbacks */ - if (pstate->rf_recvlen > 0) - { - /* Use the short timeout */ + vdbg("TCP timeout\n"); - timeo = TCP_TIMEO; - } + conn->data_private = NULL; + conn->data_event = NULL; - /* No.. check for a timeout configured via setsockopts(SO_RCVTIMEO). - * If none... we well let the read hang forever. - */ + /* Report an error only if no data has been received */ - else + if (pstate->rf_recvlen == 0) { - timeo = psock->s_rcvtimeo; + /* Report the timeout error */ + + pstate->rf_result = -EAGAIN; } - /* Is there an effective timeout? */ + /* Wake up the waiting thread, returning either the error -EAGAIN + * that signals the timeout event or the data received up to + * the point tht the timeout occured (no error). + */ - if (timeo) - { - /* Yes.. Check if the timeout has elapsed */ + sem_post(&pstate->rf_sem); + } +#endif /* CONFIG_NET_SOCKOPTS && !CONFIG_DISABLE_CLOCK */ + } + return 0; +} - if (net_timeo(pstate->rf_starttime, timeo)) - { - /* Yes.. the timeout has elapsed... do not allow any further - * callbacks - */ +/**************************************************************************** + * Function: recvfrom_udpinterrupt + * + * Description: + * This function is called from the interrupt level to perform the actual + * UDP receive operation via by the uIP layer. + * + * Parameters: + * dev The sructure of the network driver that caused the interrupt + * conn The connection structure associated with the socket + * flags Set of events describing why the callback was invoked + * + * Returned Value: + * None + * + * Assumptions: + * Running at the interrupt level + * + ****************************************************************************/ #ifdef CONFIG_NET_UDP - if (psock->s_type == SOCK_DGRAM) - { - struct uip_udp_conn *udp_conn; +static void recvfrom_udpinterrupt(struct uip_driver_s *dev, + struct uip_udp_conn *conn, uint8 flags) +{ + struct recvfrom_s *pstate = (struct recvfrom_s *)conn->private; - vdbg("UDP timeout\n"); + vdbg("flags: %02x\n", flags); - /* Stop further callbacks */ + /* 'private' might be null in some race conditions (?) */ - udp_conn = (struct uip_udp_conn *)psock->s_conn; - udp_conn->private = NULL; - udp_conn->event = NULL; + if (pstate) + { + /* If new data is available, then complete the read action. */ - /* Report a timeout error */ + if (uip_newdata_event(flags)) + { + /* Copy the data from the packet */ - pstate->rf_result = -EAGAIN; - } - else -#endif - { - struct uip_conn *conn; + recvfrom_newdata(dev, pstate); + + /* We are finished. */ - vdbg("TCP timeout\n"); + vdbg("UDP resume\n"); - conn = (struct uip_conn *)psock->s_conn; - conn->data_private = NULL; - conn->data_event = NULL; + /* Don't allow any further UDP call backs. */ - /* Report an error only if no data has been received */ + conn->private = NULL; + conn->event = NULL; - if (pstate->rf_recvlen == 0) - { - /* Report the timeout error */ + /* Wake up the waiting thread, returning the number of bytes + * actually read. + */ - pstate->rf_result = -EAGAIN; - } - } + sem_post(&pstate->rf_sem); + } - /* Wake up the waiting thread, returning either the error -EAGAIN - * that signals the timeout event or the data received up to - * the point tht the timeout occured (no error). - */ + /* Check for a loss of connection */ - sem_post(&pstate->rf_sem); - } - } + else if ((flags & (UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT)) != 0) + { + vdbg("error\n"); + + /* Stop further callbacks */ + + conn->private = NULL; + conn->event = NULL; + + /* Report not connected */ + + pstate->rf_result = -ENOTCONN; + + /* Wake up the waiting thread */ + + sem_post(&pstate->rf_sem); } -#endif + + /* No data has been received -- this is some other event... probably a + * poll -- check for a timeout. + */ + +#if defined(CONFIG_NET_SOCKOPTS) && !defined(CONFIG_DISABLE_CLOCK) + else if (recvfrom_timeout(pstate)) + { + /* Yes.. the timeout has elapsed... do not allow any further + * callbacks + */ + + vdbg("UDP timeout\n"); + + /* Stop further callbacks */ + + conn->private = NULL; + conn->event = NULL; + + /* Report a timeout error */ + + pstate->rf_result = -EAGAIN; + } +#endif /* CONFIG_NET_SOCKOPTS && !CONFIG_DISABLE_CLOCK */ } } +#endif /**************************************************************************** * Function: recvfrom_init @@ -468,7 +561,7 @@ static ssize_t udp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, udp_conn = (struct uip_udp_conn *)psock->s_conn; udp_conn->private = (void*)&state; - udp_conn->event = recvfrom_interrupt; + udp_conn->event = recvfrom_udpinterrupt; /* Enable the UDP socket */ @@ -549,7 +642,7 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, conn = (struct uip_conn *)psock->s_conn; conn->data_private = (void*)&state; - conn->data_event = recvfrom_interrupt; + conn->data_event = recvfrom_tcpinterrupt; /* Wait for either the receive to complete or for an error/timeout to occur. * NOTES: (1) sem_wait will also terminate if a signal is received, (2) diff --git a/nuttx/net/send.c b/nuttx/net/send.c index 84c6757b0..98dcec352 100644 --- a/nuttx/net/send.c +++ b/nuttx/net/send.c @@ -89,7 +89,8 @@ struct send_s * * Parameters: * dev The sructure of the network driver that caused the interrupt - * private An instance of struct send_s cast to void* + * conn The connection structure associated with the socket + * flags Set of events describing why the callback was invoked * * Returned Value: * None @@ -99,22 +100,21 @@ struct send_s * ****************************************************************************/ -static void send_interrupt(struct uip_driver_s *dev, void *private) +static uint8 send_interrupt(struct uip_driver_s *dev, struct uip_conn *conn, uint8 flags) { - struct send_s *pstate = (struct send_s *)private; - struct uip_conn *conn; + struct send_s *pstate = (struct send_s *)conn->data_private; - vdbg("uip_flags: %02x state: %d\n", uip_flags, pstate->snd_state); + vdbg("flags: %02x state: %d\n", flags, pstate->snd_state); /* If the data has not been sent OR if it needs to be retransmitted, * then send it now. */ - if (pstate->snd_state != STATE_DATA_SENT || uip_rexmit_event()) + if (pstate->snd_state != STATE_DATA_SENT || uip_rexmit_event(flags)) { - if (pstate->snd_buflen > uip_mss()) + if (pstate->snd_buflen > uip_mss(conn)) { - uip_send(dev, pstate->snd_buffer, uip_mss()); + uip_send(dev, pstate->snd_buffer, uip_mss(conn)); } else { @@ -126,17 +126,17 @@ static void send_interrupt(struct uip_driver_s *dev, void *private) /* Check if all data has been sent and acknowledged */ - else if (pstate->snd_state == STATE_DATA_SENT && uip_ack_event()) + else if (pstate->snd_state == STATE_DATA_SENT && uip_ack_event(flags)) { /* Yes.. the data has been sent AND acknowledged */ - if (pstate->snd_buflen > uip_mss()) + if (pstate->snd_buflen > uip_mss(conn)) { /* Not all data has been sent */ - pstate->snd_sent += uip_mss(); - pstate->snd_buflen -= uip_mss(); - pstate->snd_buffer += uip_mss(); + pstate->snd_sent += uip_mss(conn); + pstate->snd_buflen -= uip_mss(conn); + pstate->snd_buffer += uip_mss(conn); /* Send again on the next poll */ @@ -152,7 +152,6 @@ static void send_interrupt(struct uip_driver_s *dev, void *private) /* Don't allow any further call backs. */ - conn = (struct uip_conn *)pstate->snd_sock->s_conn; conn->data_private = NULL; conn->data_event = NULL; @@ -166,11 +165,10 @@ static void send_interrupt(struct uip_driver_s *dev, void *private) /* Check for a loss of connection */ - else if ((uip_flags & (UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT)) != 0) + else if ((flags & (UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT)) != 0) { /* Stop further callbacks */ - conn = (struct uip_conn *)pstate->snd_sock->s_conn; conn->data_private = NULL; conn->data_event = NULL; @@ -182,6 +180,7 @@ static void send_interrupt(struct uip_driver_s *dev, void *private) sem_post(&pstate->snd_sem); } + return 0; } /**************************************************************************** diff --git a/nuttx/net/sendto.c b/nuttx/net/sendto.c index 0d03252f5..d18ea8e3d 100644 --- a/nuttx/net/sendto.c +++ b/nuttx/net/sendto.c @@ -79,6 +79,7 @@ struct sendto_s * Parameters: * dev The sructure of the network driver that caused the interrupt * private An instance of struct sendto_s cast to void* + * flags Set of events describing why the callback was invoked * * Returned Value: * None @@ -89,14 +90,14 @@ struct sendto_s ****************************************************************************/ #ifdef CONFIG_NET_UDP -void sendto_interrupt(struct uip_driver_s *dev, void *private) +void sendto_interrupt(struct uip_driver_s *dev, struct uip_udp_conn *conn, uint8 flags) { - struct sendto_s *pstate = (struct sendto_s *)private; - if (private) + struct sendto_s *pstate = (struct sendto_s *)conn->private; + if (pstate) { /* Check if the connectin was rejected */ - if ((uip_flags & (UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT)) != 0) + if ((flags & (UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT)) != 0) { pstate->st_sndlen = -ENOTCONN; } @@ -111,8 +112,8 @@ void sendto_interrupt(struct uip_driver_s *dev, void *private) /* Don't allow any further call backs. */ - uip_udp_conn->private = NULL; - uip_udp_conn->event = NULL; + conn->private = NULL; + conn->event = NULL; /* Wake up the waiting thread */ 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 */ |