From 04985d6d1e65aaa5b232c7577dbaaaa6224c5b7f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 24 Jun 2014 18:12:49 -0600 Subject: [PATCH] Clean up all TCP-related naming --- include/nuttx/net/net.h | 2 +- include/nuttx/net/netdev.h | 2 +- include/nuttx/net/tcp.h | 90 ++++++++++++++++++---------------- include/nuttx/net/uip.h | 5 +- net/accept.c | 15 +++--- net/bind.c | 10 ++-- net/connect.c | 66 +++++++++++++------------ net/getsockname.c | 2 +- net/listen.c | 8 +-- net/net.h | 2 +- net/net_clone.c | 4 +- net/net_close.c | 26 +++++----- net/net_monitor.c | 8 +-- net/net_poll.c | 10 ++-- net/net_sendfile.c | 20 ++++---- net/pkt/pkt.h | 7 +-- net/pkt/pkt_conn.c | 2 +- net/pkt/pkt_send.c | 17 ++++--- net/recvfrom.c | 23 ++++----- net/send.c | 6 ++- net/socket.c | 2 +- net/tcp/tcp.h | 69 ++++++++++++++++++++++++-- net/tcp/tcp_appsend.c | 23 ++++----- net/tcp/tcp_backlog.c | 88 ++++++++++++++++----------------- net/tcp/tcp_callback.c | 15 +++--- net/tcp/tcp_conn.c | 92 ++++++++++++++++++----------------- net/tcp/tcp_input.c | 87 +++++++++++++++++---------------- net/tcp/tcp_listen.c | 55 +++++++++++---------- net/tcp/tcp_poll.c | 9 ++-- net/tcp/tcp_send.c | 48 +++++++++--------- net/tcp/tcp_send_buffered.c | 50 ++++++++++--------- net/tcp/tcp_send_unbuffered.c | 16 +++--- net/tcp/tcp_seqno.c | 24 ++++----- net/tcp/tcp_timer.c | 31 ++++++------ net/tcp/tcp_wrbuffer.c | 5 +- net/udp/udp.h | 79 ++++++++++++++++++++++++++++++ net/uip/uip.h | 60 ----------------------- net/uip/uip_chksum.c | 2 +- net/uip/uip_initialize.c | 4 +- net/uip/uip_input.c | 6 ++- net/uip/uip_poll.c | 9 ++-- 41 files changed, 608 insertions(+), 491 deletions(-) create mode 100644 net/udp/udp.h diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index d8b6b1f3905..bb7e73bf052 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -104,7 +104,7 @@ struct socket #endif #endif - FAR void *s_conn; /* Connection: struct uip_conn or uip_udp_conn */ + FAR void *s_conn; /* Connection: struct tcp_conn_s or uip_udp_conn */ #ifdef CONFIG_NET_TCP_WRITE_BUFFERS /* Callback instance for TCP send */ diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h index 9c6cbd44132..e2842a363a7 100644 --- a/include/nuttx/net/netdev.h +++ b/include/nuttx/net/netdev.h @@ -387,7 +387,7 @@ uint16_t uip_ipchksum(struct uip_driver_s *dev); * to by d_appdata. */ -uint16_t uip_tcpchksum(struct uip_driver_s *dev); +uint16_t tcp_chksum(struct uip_driver_s *dev); uint16_t uip_udpchksum(struct uip_driver_s *dev); uint16_t uip_icmpchksum(struct uip_driver_s *dev, int len); diff --git a/include/nuttx/net/tcp.h b/include/nuttx/net/tcp.h index b5d691b5df7..49d7a1254a4 100644 --- a/include/nuttx/net/tcp.h +++ b/include/nuttx/net/tcp.h @@ -80,7 +80,7 @@ #define TCP_OPT_MSS_LEN 4 /* Length of TCP MSS option. */ -/* The TCP states used in the struct uip_conn tcpstateflags field */ +/* The TCP states used in the struct tcp_conn_s tcpstateflags field */ #define UIP_TS_MASK 0x0f /* Bits 0-3: TCP state */ #define UIP_CLOSED 0x00 /* The connection is not in use and available */ @@ -154,7 +154,7 @@ /* Representation of a uIP TCP connection. * - * The uip_conn structure is used for identifying a connection. All + * The tcp_conn_s structure is used for identifying a connection. All * but one field in the structure are to be considered read-only by an * application. The only exception is the 'private' fields whose purpose * is to let the application store application-specific state (e.g., @@ -163,9 +163,9 @@ struct uip_driver_s; /* Forward reference */ struct uip_callback_s; /* Forward reference */ -struct uip_backlog_s; /* Forward reference */ +struct tcp_backlog_s; /* Forward reference */ -struct uip_conn +struct tcp_conn_s { dq_entry_t node; /* Implements a doubly linked list */ uip_ipaddr_t ripaddr; /* The IP address of the remote host */ @@ -227,12 +227,12 @@ struct uip_conn * structure in which this connection is backlogged. * backlog - The pending connection backlog. If this connection is * configured as a listener with backlog, then this refers to the - * struct uip_backlog_s tear-off structure that manages that backlog. + * struct tcp_backlog_s tear-off structure that manages that backlog. */ #ifdef CONFIG_NET_TCPBACKLOG - FAR struct uip_conn *blparent; - FAR struct uip_backlog_s *backlog; + FAR struct tcp_conn_s *blparent; + FAR struct tcp_backlog_s *backlog; #endif /* Application callbacks: @@ -264,14 +264,14 @@ struct uip_conn /* accept() is called when the TCP logic has created a connection */ FAR void *accept_private; - int (*accept)(FAR struct uip_conn *listener, struct uip_conn *conn); + int (*accept)(FAR struct tcp_conn_s *listener, FAR struct tcp_conn_s *conn); /* connection_event() is called on any of the subset of connection-related * events. */ FAR void *connection_private; - void (*connection_event)(FAR struct uip_conn *conn, uint16_t flags); + void (*connection_event)(FAR struct tcp_conn_s *conn, uint16_t flags); }; /* This structure supports TCP write buffering */ @@ -290,22 +290,22 @@ struct tcp_wrbuffer_s /* Support for listen backlog: * - * struct uip_blcontainer_s describes one backlogged connection - * struct uip_backlog_s is a "tear-off" describing all backlog for a + * struct tcp_blcontainer_s describes one backlogged connection + * struct tcp_backlog_s is a "tear-off" describing all backlog for a * listener connection */ #ifdef CONFIG_NET_TCPBACKLOG -struct uip_blcontainer_s +struct tcp_blcontainer_s { - sq_entry_t bc_node; /* Implements a singly linked list */ - FAR struct uip_conn *bc_conn; /* Holds reference to the new connection structure */ + sq_entry_t bc_node; /* Implements a singly linked list */ + FAR struct tcp_conn_s *bc_conn; /* Holds reference to the new connection structure */ }; -struct uip_backlog_s +struct tcp_backlog_s { - sq_queue_t bl_free; /* Implements a singly-linked list of free containers */ - sq_queue_t bl_pending; /* Implements a singly-linked list of pending connections */ + sq_queue_t bl_free; /* Implements a singly-linked list of free containers */ + sq_queue_t bl_pending; /* Implements a singly-linked list of pending connections */ }; #endif @@ -314,7 +314,7 @@ struct uip_backlog_s */ #ifdef CONFIG_NET_STATISTICS -struct uip_tcp_stats_s +struct tcp_stats_s { uip_stats_t drop; /* Number of dropped TCP segments */ uip_stats_t recv; /* Number of received TCP segments */ @@ -331,7 +331,7 @@ struct uip_tcp_stats_s /* The TCP and IP headers */ -struct uip_tcpip_hdr +struct tcp_iphdr_s { #ifdef CONFIG_NET_IPv6 @@ -395,25 +395,27 @@ struct uip_tcpip_hdr * normally something done by the implementation of the socket() API */ -struct uip_conn *uip_tcpalloc(void); +struct tcp_conn_s *tcp_alloc(void); /* Allocate a new TCP data callback */ -#define uip_tcpcallbackalloc(conn) uip_callbackalloc(&conn->list) -#define uip_tcpcallbackfree(conn,cb) uip_callbackfree(cb, &conn->list) +#define tcp_callbackalloc(conn) uip_callbackalloc(&conn->list) +#define tcp_callbackfree(conn,cb) uip_callbackfree(cb, &conn->list) /* Free a connection structure that is no longer in use. This should * be done by the implementation of close() */ -void uip_tcpfree(struct uip_conn *conn); +void tcp_free(FAR struct tcp_conn_s *conn); /* Bind a TCP connection to a local address */ #ifdef CONFIG_NET_IPv6 -int uip_tcpbind(struct uip_conn *conn, const struct sockaddr_in6 *addr); +int tcp_bind(FAR struct tcp_conn_s *conn, + FAR const struct sockaddr_in6 *addr); #else -int uip_tcpbind(struct uip_conn *conn, const struct sockaddr_in *addr); +int tcp_bind(FAR struct tcp_conn_s *conn, + FAR const struct sockaddr_in *addr); #endif /* This function implements the UIP specific parts of the standard @@ -425,50 +427,54 @@ int uip_tcpbind(struct uip_conn *conn, const struct sockaddr_in *addr); * the SYN_SENT state and sets the retransmission timer to 0. This will * cause a TCP SYN segment to be sent out the next time this connection * is periodically processed, which usually is done within 0.5 seconds - * after the call to uip_tcpconnect(). + * after the call to tcp_connect(). * * This function is called from normal user level code. */ #ifdef CONFIG_NET_IPv6 -int uip_tcpconnect(struct uip_conn *conn, const struct sockaddr_in6 *addr); +int tcp_connect(FAR struct tcp_conn_s *conn, + FAR const struct sockaddr_in6 *addr); #else -int uip_tcpconnect(struct uip_conn *conn, const struct sockaddr_in *addr); +int tcp_connect(FAR struct tcp_conn_s *conn, + FAR const struct sockaddr_in *addr); #endif /* Start listening to the port bound to the specified TCP connection */ -int uip_listen(struct uip_conn *conn); +int tcp_listen(FAR struct tcp_conn_s *conn); /* Stop listening to the port bound to the specified TCP connection */ -int uip_unlisten(struct uip_conn *conn); +int tcp_unlisten(FAR struct tcp_conn_s *conn); /* Backlog support */ #ifdef CONFIG_NET_TCPBACKLOG /* APIs to create and terminate TCP backlog support */ -int uip_backlogcreate(FAR struct uip_conn *conn, int nblg); -int uip_backlogdestroy(FAR struct uip_conn *conn); +int tcp_backlogcreate(FAR struct tcp_conn_s *conn, int nblg); +int tcp_backlogdestroy(FAR struct tcp_conn_s *conn); /* APIs to manage individual backlog actions */ -int uip_backlogadd(FAR struct uip_conn *conn, FAR struct uip_conn *blconn); +int tcp_backlogadd(FAR struct tcp_conn_s *conn, + FAR struct tcp_conn_s *blconn); #ifndef CONFIG_DISABLE_POLL -bool uip_backlogavailable(FAR struct uip_conn *conn); +bool tcp_backlogavailable(FAR struct tcp_conn_s *conn); #else -# define uip_backlogavailable(conn) (false); +# define tcp_backlogavailable(conn) (false); #endif -FAR struct uip_conn *uip_backlogremove(FAR struct uip_conn *conn); -int uip_backlogdelete(FAR struct uip_conn *conn, FAR struct uip_conn *blconn); +FAR struct tcp_conn_s *tcp_backlogremove(FAR struct tcp_conn_s *conn); +int tcp_backlogdelete(FAR struct tcp_conn_s *conn, + FAR struct tcp_conn_s *blconn); #else -# define uip_backlogcreate(conn,nblg) (-ENOSYS) -# define uip_backlogdestroy(conn) (-ENOSYS) -# define uip_backlogadd(conn,blconn) (-ENOSYS) -# define uip_backlogavailable(conn) (false); -# define uip_backlogremove(conn) (NULL) +# define tcp_backlogcreate(conn,nblg) (-ENOSYS) +# define tcp_backlogdestroy(conn) (-ENOSYS) +# define tcp_backlogadd(conn,blconn) (-ENOSYS) +# define tcp_backlogavailable(conn) (false); +# define tcp_backlogremove(conn) (NULL) #endif /* Tell the sending host to stop sending data. diff --git a/include/nuttx/net/uip.h b/include/nuttx/net/uip.h index 3725f423f72..76fdc4bce4d 100644 --- a/include/nuttx/net/uip.h +++ b/include/nuttx/net/uip.h @@ -209,7 +209,8 @@ struct uip_ip_hdr * * flink - Supports a singly linked list * event - Provides the address of the callback function entry point. - * pvconn is a pointer to one of struct uip_conn or struct uip_udp_conn. + * pvconn is a pointer to one of struct tcp_conn_s or struct + * uip_udp_conn. * priv - Holds a reference to application specific data that will * provided * flags - Set by the application to inform the uIP layer which flags @@ -280,7 +281,7 @@ struct uip_stats #endif #ifdef CONFIG_NET_TCP - struct uip_tcp_stats_s tcp; /* TCP statistics */ + struct tcp_stats_s tcp; /* TCP statistics */ #endif #ifdef CONFIG_NET_UDP diff --git a/net/accept.c b/net/accept.c index d6a4ed84edb..9fabcecd660 100644 --- a/net/accept.c +++ b/net/accept.c @@ -69,7 +69,7 @@ struct accept_s #else FAR struct sockaddr_in *acpt_addr; /* Return connection adress */ #endif - FAR struct uip_conn *acpt_newconn; /* The accepted connection */ + FAR struct tcp_conn_s *acpt_newconn; /* The accepted connection */ int acpt_result; /* The result of the wait */ }; @@ -101,7 +101,7 @@ struct accept_s #ifdef CONFIG_NET_TCP #ifdef CONFIG_NET_IPv6 -static inline void accept_tcpsender(FAR struct uip_conn *conn, +static inline void accept_tcpsender(FAR struct tcp_conn_s *conn, FAR struct sockaddr_in6 *addr) { if (addr) @@ -112,7 +112,7 @@ static inline void accept_tcpsender(FAR struct uip_conn *conn, } } #else -static inline void accept_tcpsender(FAR struct uip_conn *conn, +static inline void accept_tcpsender(FAR struct tcp_conn_s *conn, FAR struct sockaddr_in *addr) { if (addr) @@ -143,7 +143,8 @@ static inline void accept_tcpsender(FAR struct uip_conn *conn, * ****************************************************************************/ -static int accept_interrupt(struct uip_conn *listener, struct uip_conn *conn) +static int accept_interrupt(FAR struct tcp_conn_s *listener, + FAR struct tcp_conn_s *conn) { struct accept_s *pstate = (struct accept_s *)listener->accept_private; int ret = -EINVAL; @@ -255,7 +256,7 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { FAR struct socket *psock = sockfd_socket(sockfd); FAR struct socket *pnewsock; - FAR struct uip_conn *conn; + FAR struct tcp_conn_s *conn; struct accept_s state; #ifdef CONFIG_NET_IPv6 FAR struct sockaddr_in6 *inaddr = (struct sockaddr_in6 *)addr; @@ -345,10 +346,10 @@ int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen) */ save = uip_lock(); - conn = (struct uip_conn *)psock->s_conn; + conn = (struct tcp_conn_s *)psock->s_conn; #ifdef CONFIG_NET_TCPBACKLOG - state.acpt_newconn = uip_backlogremove(conn); + state.acpt_newconn = tcp_backlogremove(conn); if (state.acpt_newconn) { /* Yes... get the address of the connected client */ diff --git a/net/bind.c b/net/bind.c index 0d1a35cfead..3d4b5597c33 100644 --- a/net/bind.c +++ b/net/bind.c @@ -56,7 +56,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: pkt_rawbind + * Function: pkt_bind * * Description: * Bind a raw socket to an network device. @@ -71,8 +71,8 @@ ****************************************************************************/ #ifdef CONFIG_NET_PKT -static int pkt_rawbind(FAR struct uip_pkt_conn *conn, - FAR const struct sockaddr_ll *addr) +static int pkt_bind(FAR struct uip_pkt_conn *conn, + FAR const struct sockaddr_ll *addr) { int ifindex; #if 0 @@ -191,13 +191,13 @@ int psock_bind(FAR struct socket *psock, const struct sockaddr *addr, { #ifdef CONFIG_NET_PKT case SOCK_RAW: - ret = pkt_rawbind(psock->s_conn, lladdr); + ret = pkt_bind(psock->s_conn, lladdr); break; #endif #ifdef CONFIG_NET_TCP case SOCK_STREAM: - ret = uip_tcpbind(psock->s_conn, inaddr); + ret = tcp_bind(psock->s_conn, inaddr); psock->s_flags |= _SF_BOUND; break; #endif diff --git a/net/connect.c b/net/connect.c index 0e28d91c528..0dcc855d602 100644 --- a/net/connect.c +++ b/net/connect.c @@ -60,7 +60,7 @@ #ifdef CONFIG_NET_TCP struct tcp_connect_s { - FAR struct uip_conn *tc_conn; /* Reference to TCP connection structure */ + FAR struct tcp_conn_s *tc_conn; /* Reference to TCP connection structure */ FAR struct uip_callback_s *tc_cb; /* Reference to callback instance */ sem_t tc_sem; /* Semaphore signals recv completion */ int tc_result; /* OK on success, otherwise a negated errno. */ @@ -72,15 +72,18 @@ struct tcp_connect_s ****************************************************************************/ #ifdef CONFIG_NET_TCP -static inline int tcp_setup_callbacks(FAR struct socket *psock, - FAR struct tcp_connect_s *pstate); -static inline void tcp_teardown_callbacks(struct tcp_connect_s *pstate, int status); -static uint16_t tcp_connect_interrupt(struct uip_driver_s *dev, void *pvconn, - void *pvpriv, uint16_t flags); +static inline int psock_setup_callbacks(FAR struct socket *psock, + FAR struct tcp_connect_s *pstate); +static inline void psock_teardown_callbacks(FAR struct tcp_connect_s *pstate, + int status); +static uint16_t psock_connect_interrupt(FAR struct uip_driver_s *dev, + FAR void *pvconn, FAR void *pvpriv, + uint16_t flags); #ifdef CONFIG_NET_IPv6 -static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in6 *inaddr); +static inline int psock_tcp_connect(FAR struct socket *psock, + FAR const struct sockaddr_in6 *inaddr); #else -static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in *inaddr); +static inline int psock_tcp_connect(FAR struct socket *psock, const struct sockaddr_in *inaddr); #endif #endif /* CONFIG_NET_TCP */ @@ -88,14 +91,14 @@ static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in * Private Functions ****************************************************************************/ /**************************************************************************** - * Name: tcp_setup_callbacks + * Name: psock_setup_callbacks ****************************************************************************/ #ifdef CONFIG_NET_TCP -static inline int tcp_setup_callbacks(FAR struct socket *psock, - FAR struct tcp_connect_s *pstate) +static inline int psock_setup_callbacks(FAR struct socket *psock, + FAR struct tcp_connect_s *pstate) { - FAR struct uip_conn *conn = psock->s_conn; + FAR struct tcp_conn_s *conn = psock->s_conn; int ret = -EBUSY; /* Initialize the TCP state structure */ @@ -106,14 +109,14 @@ static inline int tcp_setup_callbacks(FAR struct socket *psock, /* Set up the callbacks in the connection */ - pstate->tc_cb = uip_tcpcallbackalloc(conn); + pstate->tc_cb = tcp_callbackalloc(conn); if (pstate->tc_cb) { /* Set up the connection "interrupt" handler */ pstate->tc_cb->flags = UIP_NEWDATA|UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT|UIP_CONNECTED; pstate->tc_cb->priv = (void*)pstate; - pstate->tc_cb->event = tcp_connect_interrupt; + pstate->tc_cb->event = psock_connect_interrupt; /* Set up the connection event monitor */ @@ -125,18 +128,18 @@ static inline int tcp_setup_callbacks(FAR struct socket *psock, #endif /* CONFIG_NET_TCP */ /**************************************************************************** - * Name: tcp_teardown_callbacks + * Name: psock_teardown_callbacks ****************************************************************************/ #ifdef CONFIG_NET_TCP -static inline void tcp_teardown_callbacks(struct tcp_connect_s *pstate, - int status) +static inline void psock_teardown_callbacks(FAR struct tcp_connect_s *pstate, + int status) { - FAR struct uip_conn *conn = pstate->tc_conn; + FAR struct tcp_conn_s *conn = pstate->tc_conn; /* Make sure that no further interrupts are processed */ - uip_tcpcallbackfree(conn, pstate->tc_cb); + tcp_callbackfree(conn, pstate->tc_cb); pstate->tc_cb = NULL; @@ -154,7 +157,7 @@ static inline void tcp_teardown_callbacks(struct tcp_connect_s *pstate, #endif /* CONFIG_NET_TCP */ /**************************************************************************** - * Name: tcp_connect_interrupt + * Name: psock_connect_interrupt * * Description: * This function is called from the interrupt level to perform the actual @@ -174,8 +177,9 @@ static inline void tcp_teardown_callbacks(struct tcp_connect_s *pstate, ****************************************************************************/ #ifdef CONFIG_NET_TCP -static uint16_t tcp_connect_interrupt(struct uip_driver_s *dev, void *pvconn, - void *pvpriv, uint16_t flags) +static uint16_t psock_connect_interrupt(FAR struct uip_driver_s *dev, + FAR void *pvconn, FAR void *pvpriv, + uint16_t flags) { struct tcp_connect_s *pstate = (struct tcp_connect_s *)pvpriv; @@ -239,7 +243,7 @@ static uint16_t tcp_connect_interrupt(struct uip_driver_s *dev, void *pvconn, /* Stop further callbacks */ - tcp_teardown_callbacks(pstate, pstate->tc_result); + psock_teardown_callbacks(pstate, pstate->tc_result); /* Wake up the waiting thread */ @@ -251,7 +255,7 @@ static uint16_t tcp_connect_interrupt(struct uip_driver_s *dev, void *pvconn, #endif /* CONFIG_NET_TCP */ /**************************************************************************** - * Name: tcp_connect + * Name: psock_tcp_connect * * Description: * Perform a TCP connection @@ -270,9 +274,11 @@ static uint16_t tcp_connect_interrupt(struct uip_driver_s *dev, void *pvconn, #ifdef CONFIG_NET_TCP #ifdef CONFIG_NET_IPv6 -static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in6 *inaddr) +static inline int psock_tcp_connect(FAR struct socket *psock, + FAR const struct sockaddr_in6 *inaddr) #else -static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in *inaddr) +static inline int psock_tcp_connect(FAR struct socket *psock, + FAR const struct sockaddr_in *inaddr) #endif { struct tcp_connect_s state; @@ -296,14 +302,14 @@ static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in { /* Perform the uIP connection operation */ - ret = uip_tcpconnect(psock->s_conn, inaddr); + ret = psock_tcp_connect(psock->s_conn, inaddr); } if (ret >= 0) { /* Set up the callbacks in the connection */ - ret = tcp_setup_callbacks(psock, &state); + ret = psock_setup_callbacks(psock, &state); if (ret >= 0) { /* Wait for either the connect to complete or for an error/timeout @@ -336,7 +342,7 @@ static inline int tcp_connect(FAR struct socket *psock, const struct sockaddr_in /* Make sure that no further interrupts are processed */ - tcp_teardown_callbacks(&state, ret); + psock_teardown_callbacks(&state, ret); } /* Mark the connection bound and connected */ @@ -475,7 +481,7 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr, /* Its not ... connect it */ - ret = tcp_connect(psock, inaddr); + ret = psock_tcp_connect(psock, inaddr); if (ret < 0) { err = -ret; diff --git a/net/getsockname.c b/net/getsockname.c index ba15055e109..650cbdd8eab 100644 --- a/net/getsockname.c +++ b/net/getsockname.c @@ -153,7 +153,7 @@ int getsockname(int sockfd, FAR struct sockaddr *addr, FAR socklen_t *addrlen) #ifdef CONFIG_NET_TCP case SOCK_STREAM: { - struct uip_conn *tcp_conn = (struct uip_conn *)psock->s_conn; + FAR struct tcp_conn_s *tcp_conn = (FAR struct tcp_conn_s *)psock->s_conn; outaddr->sin_port = tcp_conn->lport; /* Already in network byte order */ } break; diff --git a/net/listen.c b/net/listen.c index c8a1260bdaf..2c691a93d6c 100644 --- a/net/listen.c +++ b/net/listen.c @@ -88,7 +88,7 @@ int listen(int sockfd, int backlog) { FAR struct socket *psock = sockfd_socket(sockfd); - struct uip_conn *conn; + struct tcp_conn_s *conn; int err; /* Verify that the sockfd corresponds to valid, allocated socket */ @@ -115,7 +115,7 @@ int listen(int sockfd, int backlog) /* Verify that the sockfd corresponds to a connected SOCK_STREAM */ - conn = (struct uip_conn *)psock->s_conn; + conn = (FAR struct tcp_conn_s *)psock->s_conn; if (psock->s_type != SOCK_STREAM || !psock->s_conn || conn->lport <= 0) { err = EOPNOTSUPP; @@ -125,7 +125,7 @@ int listen(int sockfd, int backlog) /* Set up the backlog for this connection */ #ifdef CONFIG_NET_TCPBACKLOG - err = uip_backlogcreate(conn, backlog); + err = tcp_backlogcreate(conn, backlog); if (err < 0) { err = -err; @@ -137,7 +137,7 @@ int listen(int sockfd, int backlog) * is called and enables poll()/select() logic. */ - uip_listen(conn); + tcp_listen(conn); psock->s_flags |= _SF_LISTENING; return OK; diff --git a/net/net.h b/net/net.h index 96eddb8b248..fdf63ad93e3 100644 --- a/net/net.h +++ b/net/net.h @@ -169,7 +169,7 @@ FAR struct socket *sockfd_socket(int sockfd); #ifdef CONFIG_NET_TCP int net_startmonitor(FAR struct socket *psock); -void net_stopmonitor(FAR struct uip_conn *conn); +void net_stopmonitor(FAR struct tcp_conn_s *conn); void net_lostconnection(FAR struct socket *psock, uint16_t flags); #endif diff --git a/net/net_clone.c b/net/net_clone.c index 4f5bfe668f8..6b6fa6cf227 100644 --- a/net/net_clone.c +++ b/net/net_clone.c @@ -97,7 +97,7 @@ int net_clone(FAR struct socket *psock1, FAR struct socket *psock2) #ifdef CONFIG_NET_TCP if (psock2->s_type == SOCK_STREAM) { - struct uip_conn *conn = psock2->s_conn; + FAR struct tcp_conn_s *conn = psock2->s_conn; DEBUGASSERT(conn->crefs > 0 && conn->crefs < 255); conn->crefs++; } @@ -106,7 +106,7 @@ int net_clone(FAR struct socket *psock1, FAR struct socket *psock2) #ifdef CONFIG_NET_UDP if (psock2->s_type == SOCK_DGRAM) { - struct uip_udp_conn *conn = psock2->s_conn; + FAR struct uip_udp_conn *conn = psock2->s_conn; DEBUGASSERT(conn->crefs > 0 && conn->crefs < 255); conn->crefs++; } diff --git a/net/net_close.c b/net/net_close.c index d5a72f59dee..0d81243799b 100644 --- a/net/net_close.c +++ b/net/net_close.c @@ -153,9 +153,9 @@ static uint16_t netclose_interrupt(FAR struct uip_driver_s *dev, uint16_t flags) { #ifdef CONFIG_NET_SOLINGER - FAR struct tcp_close_s *pstate = (struct tcp_close_s *)pvpriv; + FAR struct tcp_close_s *pstate = (FAR struct tcp_close_s *)pvpriv; #endif - FAR struct uip_conn *conn = (FAR struct uip_conn *)pvconn; + FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)pvconn; DEBUGASSERT(conn != NULL); @@ -190,7 +190,7 @@ static uint16_t netclose_interrupt(FAR struct uip_driver_s *dev, { /* Free connection resources */ - uip_tcpfree(conn); + tcp_free(conn); /* Stop further callbacks */ @@ -273,7 +273,7 @@ end_wait: static inline int netclose_disconnect(FAR struct socket *psock) { struct tcp_close_s state; - FAR struct uip_conn *conn; + FAR struct tcp_conn_s *conn; uip_lock_t flags; #ifdef CONFIG_NET_SOLINGER bool linger; @@ -283,7 +283,7 @@ static inline int netclose_disconnect(FAR struct socket *psock) /* Interrupts are disabled here to avoid race conditions */ flags = uip_lock(); - conn = (struct uip_conn*)psock->s_conn; + conn = (FAR struct tcp_conn_s *)psock->s_conn; /* If we have a semi-permanent write buffer callback in place, then * release it now. @@ -292,7 +292,7 @@ static inline int netclose_disconnect(FAR struct socket *psock) #ifdef CONFIG_NET_TCP_WRITE_BUFFERS if (psock->s_sndcb) { - uip_tcpcallbackfree(conn, psock->s_sndcb); + tcp_callbackfree(conn, psock->s_sndcb); psock->s_sndcb = NULL; } #endif @@ -304,7 +304,7 @@ static inline int netclose_disconnect(FAR struct socket *psock) /* Check for the case where the host beat us and disconnected first */ if (conn->tcpstateflags == UIP_ESTABLISHED && - (state.cl_cb = uip_tcpcallbackalloc(conn)) != NULL) + (state.cl_cb = tcp_callbackalloc(conn)) != NULL) { /* Set up to receive TCP data event callbacks */ @@ -368,12 +368,12 @@ static inline int netclose_disconnect(FAR struct socket *psock) /* We are now disconnected */ sem_destroy(&state.cl_sem); - uip_tcpcallbackfree(conn, state.cl_cb); + tcp_callbackfree(conn, state.cl_cb); /* Free the connection */ - conn->crefs = 0; /* No more references on the connection */ - uip_tcpfree(conn); /* Free uIP resources */ + conn->crefs = 0; /* No more references on the connection */ + tcp_free(conn); /* Free uIP resources */ /* Get the result of the close */ @@ -383,7 +383,7 @@ static inline int netclose_disconnect(FAR struct socket *psock) } else { - uip_tcpfree(conn); + tcp_free(conn); } uip_unlock(flags); @@ -462,7 +462,7 @@ int psock_close(FAR struct socket *psock) #ifdef CONFIG_NET_TCP case SOCK_STREAM: { - struct uip_conn *conn = psock->s_conn; + FAR struct tcp_conn_s *conn = psock->s_conn; /* Is this the last reference to the connection structure (there * could be more if the socket was dup'ed). @@ -472,7 +472,7 @@ int psock_close(FAR struct socket *psock) { /* Yes... then perform the disconnection now */ - uip_unlisten(conn); /* No longer accepting connections */ + tcp_unlisten(conn); /* No longer accepting connections */ conn->crefs = 0; /* Discard our reference to the connection */ err = netclose_disconnect(psock); /* Break any current connections */ if (err < 0) diff --git a/net/net_monitor.c b/net/net_monitor.c index cc1289da364..59b1c538224 100644 --- a/net/net_monitor.c +++ b/net/net_monitor.c @@ -55,7 +55,7 @@ * Private Function Prototypes ****************************************************************************/ -static void connection_event(struct uip_conn *conn, uint16_t flags); +static void connection_event(FAR struct tcp_conn_s *conn, uint16_t flags); /**************************************************************************** * Private Functions @@ -78,7 +78,7 @@ static void connection_event(struct uip_conn *conn, uint16_t flags); * ****************************************************************************/ -static void connection_event(FAR struct uip_conn *conn, uint16_t flags) +static void connection_event(FAR struct tcp_conn_s *conn, uint16_t flags) { FAR struct socket *psock = (FAR struct socket *)conn->connection_private; @@ -124,7 +124,7 @@ static void connection_event(FAR struct uip_conn *conn, uint16_t flags) int net_startmonitor(FAR struct socket *psock) { - FAR struct uip_conn *conn = psock->s_conn; + FAR struct tcp_conn_s *conn = psock->s_conn; DEBUGASSERT(psock && conn); @@ -161,7 +161,7 @@ int net_startmonitor(FAR struct socket *psock) * ****************************************************************************/ -void net_stopmonitor(FAR struct uip_conn *conn) +void net_stopmonitor(FAR struct tcp_conn_s *conn) { DEBUGASSERT(conn); diff --git a/net/net_poll.c b/net/net_poll.c index a8f873ea707..a12b0721b55 100644 --- a/net/net_poll.c +++ b/net/net_poll.c @@ -183,7 +183,7 @@ static uint16_t poll_interrupt(FAR struct uip_driver_s *dev, FAR void *conn, static inline int net_pollsetup(FAR struct socket *psock, FAR struct pollfd *fds) { - FAR struct uip_conn *conn = psock->s_conn; + FAR struct tcp_conn_s *conn = psock->s_conn; FAR struct net_poll_s *info; FAR struct uip_callback_s *cb; uip_lock_t flags; @@ -212,7 +212,7 @@ static inline int net_pollsetup(FAR struct socket *psock, /* Allocate a TCP/IP callback structure */ - cb = uip_tcpcallbackalloc(conn); + cb = tcp_callbackalloc(conn); if (!cb) { ret = -EBUSY; @@ -243,7 +243,7 @@ static inline int net_pollsetup(FAR struct socket *psock, #ifdef CONFIG_NET_TCPBACKLOG /* Check for read data or backlogged connection availability now */ - if (!IOB_QEMPTY(&conn->readahead) || uip_backlogavailable(conn)) + if (!IOB_QEMPTY(&conn->readahead) || tcp_backlogavailable(conn)) #else /* Check for read data availability now */ @@ -342,7 +342,7 @@ errout_with_lock: static inline int net_pollteardown(FAR struct socket *psock, FAR struct pollfd *fds) { - FAR struct uip_conn *conn = psock->s_conn; + FAR struct tcp_conn_s *conn = psock->s_conn; FAR struct net_poll_s *info; uip_lock_t flags; @@ -364,7 +364,7 @@ static inline int net_pollteardown(FAR struct socket *psock, /* Release the callback */ flags = uip_lock(); - uip_tcpcallbackfree(conn, info->cb); + tcp_callbackfree(conn, info->cb); uip_unlock(flags); /* Release the poll/select data slot */ diff --git a/net/net_sendfile.c b/net/net_sendfile.c index 23d8cd1b593..ad7924d532b 100644 --- a/net/net_sendfile.c +++ b/net/net_sendfile.c @@ -72,7 +72,7 @@ # define CONFIG_NET_TCP_SPLIT_SIZE 40 #endif -#define TCPBUF ((struct uip_tcpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) +#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[UIP_LLH_LEN]) /**************************************************************************** * Private Types @@ -164,7 +164,7 @@ static uint16_t ack_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, * is the number of bytes to be acknowledged. */ - pstate->snd_acked = uip_tcpgetsequence(TCPBUF->ackno) - pstate->snd_isn; + pstate->snd_acked = tcp_getsequence(TCPBUF->ackno) - pstate->snd_isn; nllvdbg("ACK: acked=%d sent=%d flen=%d\n", pstate->snd_acked, pstate->snd_sent, pstate->snd_flen); @@ -225,7 +225,7 @@ static uint16_t ack_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, static uint16_t sendfile_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, FAR void *pvpriv, uint16_t flags) { - FAR struct uip_conn *conn = (FAR struct uip_conn*)pvconn; + FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s*)pvconn; FAR struct sendfile_s *pstate = (FAR struct sendfile_s *)pvpriv; int ret; @@ -305,7 +305,7 @@ static uint16_t sendfile_interrupt(FAR struct uip_driver_s *dev, FAR void *pvcon seqno = pstate->snd_sent + pstate->snd_isn; nllvdbg("SEND: sndseq %08x->%08x len: %d\n", conn->sndseq, seqno, ret); - uip_tcpsetsequence(conn->sndseq, seqno); + tcp_setsequence(conn->sndseq, seqno); /* Check if the destination IP address is in the ARP table. If not, * then the send won't actually make it out... it will be replaced with @@ -449,7 +449,7 @@ ssize_t net_sendfile(int outfd, struct file *infile, off_t *offset, size_t count) { FAR struct socket *psock = sockfd_socket(outfd); - FAR struct uip_conn *conn = (FAR struct uip_conn*)psock->s_conn; + FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s*)psock->s_conn; struct sendfile_s state; uip_lock_t save; int err; @@ -490,7 +490,7 @@ ssize_t net_sendfile(int outfd, struct file *infile, off_t *offset, /* Allocate resources to receive a callback */ - state.snd_datacb = uip_tcpcallbackalloc(conn); + state.snd_datacb = tcp_callbackalloc(conn); if (state.snd_datacb == NULL) { @@ -499,7 +499,7 @@ ssize_t net_sendfile(int outfd, struct file *infile, off_t *offset, goto errout_locked; } - state.snd_ackcb = uip_tcpcallbackalloc(conn); + state.snd_ackcb = tcp_callbackalloc(conn); if (state.snd_ackcb == NULL) { @@ -510,7 +510,7 @@ ssize_t net_sendfile(int outfd, struct file *infile, off_t *offset, /* Get the initial sequence number that will be used */ - state.snd_isn = uip_tcpgetsequence(conn->sndseq); + state.snd_isn = tcp_getsequence(conn->sndseq); /* There is no outstanding, unacknowledged data after this * initial sequence number. @@ -550,10 +550,10 @@ ssize_t net_sendfile(int outfd, struct file *infile, off_t *offset, psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_IDLE); - uip_tcpcallbackfree(conn, state.snd_ackcb); + tcp_callbackfree(conn, state.snd_ackcb); errout_datacb: - uip_tcpcallbackfree(conn, state.snd_datacb); + tcp_callbackfree(conn, state.snd_datacb); errout_locked: diff --git a/net/pkt/pkt.h b/net/pkt/pkt.h index b0d24f230d0..e2fa8845884 100644 --- a/net/pkt/pkt.h +++ b/net/pkt/pkt.h @@ -71,10 +71,10 @@ extern "C" ****************************************************************************/ /**************************************************************************** - * Function: pkt_send + * Function: psock_pkt_send * * Description: - * The pkt_send() call may be used only when the packet socket is in a + * The psock_pkt_send() call may be used only when the packet socket is in a * connected state (so that the intended recipient is known). * * Parameters: @@ -128,7 +128,8 @@ extern "C" ****************************************************************************/ struct socket; -ssize_t pkt_send(FAR struct socket *psock, FAR const void *buf, size_t len); +ssize_t psock_pkt_send(FAR struct socket *psock, FAR const void *buf, + size_t len); #undef EXTERN diff --git a/net/pkt/pkt_conn.c b/net/pkt/pkt_conn.c index bbaae63b322..b49d4811b9f 100644 --- a/net/pkt/pkt_conn.c +++ b/net/pkt/pkt_conn.c @@ -219,7 +219,7 @@ struct uip_pkt_conn *uip_pktactive(struct uip_eth_hdr *buf) while (conn) { - /* FIXME lmac in conn should have been set by pkt_rawbind() */ + /* FIXME lmac in conn should have been set by pkt_bind() */ if (uip_ethaddr_cmp(buf->dest, conn->lmac)) { diff --git a/net/pkt/pkt_send.c b/net/pkt/pkt_send.c index 3712c3e2905..6775b316158 100644 --- a/net/pkt/pkt_send.c +++ b/net/pkt/pkt_send.c @@ -85,12 +85,12 @@ struct send_s ****************************************************************************/ /**************************************************************************** - * Function: pktsend_interrupt + * Function: psock_send_interrupt ****************************************************************************/ -static uint16_t pktsend_interrupt(FAR struct uip_driver_s *dev, - FAR void *pvconn, - FAR void *pvpriv, uint16_t flags) +static uint16_t psock_send_interrupt(FAR struct uip_driver_s *dev, + FAR void *pvconn, + FAR void *pvpriv, uint16_t flags) { FAR struct send_s *pstate = (FAR struct send_s *)pvpriv; @@ -145,10 +145,10 @@ static uint16_t pktsend_interrupt(FAR struct uip_driver_s *dev, ****************************************************************************/ /**************************************************************************** - * Function: pkt_send + * Function: psock_pkt_send * * Description: - * The pkt_send() call may be used only when the packet socket is in a + * The psock_pkt_send() call may be used only when the packet socket is in a * connected state (so that the intended recipient is known). * * Parameters: @@ -201,7 +201,8 @@ static uint16_t pktsend_interrupt(FAR struct uip_driver_s *dev, * ****************************************************************************/ -ssize_t pkt_send(FAR struct socket *psock, FAR const void *buf, size_t len) +ssize_t psock_pkt_send(FAR struct socket *psock, FAR const void *buf, + size_t len) { struct send_s state; uip_lock_t save; @@ -249,7 +250,7 @@ ssize_t pkt_send(FAR struct socket *psock, FAR const void *buf, size_t len) state.snd_cb->flags = UIP_POLL; state.snd_cb->priv = (void*)&state; - state.snd_cb->event = pktsend_interrupt; + state.snd_cb->event = psock_send_interrupt; /* Notify the device driver of the availability of TX data */ /* TODO better lookup network interface from *psock or *conn */ diff --git a/net/recvfrom.c b/net/recvfrom.c index 5c6a5aa0706..99a79bc1a9b 100644 --- a/net/recvfrom.c +++ b/net/recvfrom.c @@ -58,13 +58,14 @@ #include "net.h" #include "uip/uip.h" +#include "tcp/tcp.h" /**************************************************************************** * Definitions ****************************************************************************/ #define UDPBUF ((struct uip_udpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) -#define TCPBUF ((struct uip_tcpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) +#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[UIP_LLH_LEN]) /**************************************************************************** * Private Types @@ -224,15 +225,15 @@ static inline void recvfrom_newtcpdata(FAR struct uip_driver_s *dev, if (recvlen < dev->d_len) { #ifdef CONFIG_NET_TCP_READAHEAD - FAR struct uip_conn *conn = (FAR struct uip_conn *)pstate->rf_sock->s_conn; - FAR uint8_t *buffer = (FAR uint8_t *)dev->d_appdata + recvlen; - uint16_t buflen = dev->d_len - recvlen; + FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)pstate->rf_sock->s_conn; + FAR uint8_t *buffer = (FAR uint8_t *)dev->d_appdata + recvlen; + uint16_t buflen = dev->d_len - recvlen; #ifdef CONFIG_DEBUG_NET - uint16_t nsaved; + uint16_t nsaved; - nsaved = uip_datahandler(conn, buffer, buflen); + nsaved = tcp_datahandler(conn, buffer, buflen); #else - (void)uip_datahandler(conn, buffer, buflen); + (void)tcp_datahandler(conn, buffer, buflen); #endif /* There are complicated buffering issues that are not addressed fully @@ -316,7 +317,7 @@ static inline void recvfrom_newudpdata(FAR struct uip_driver_s *dev, #if defined(CONFIG_NET_TCP) && defined(CONFIG_NET_TCP_READAHEAD) static inline void recvfrom_readahead(struct recvfrom_s *pstate) { - FAR struct uip_conn *conn = (FAR struct uip_conn *)pstate->rf_sock->s_conn; + FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)pstate->rf_sock->s_conn; FAR struct iob_s *iob; int recvlen; @@ -1342,11 +1343,11 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, if (state.rf_buflen > 0) #endif { - struct uip_conn *conn = (struct uip_conn *)psock->s_conn; + FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)psock->s_conn; /* Set up the callback in the connection */ - state.rf_cb = uip_tcpcallbackalloc(conn); + state.rf_cb = tcp_callbackalloc(conn); if (state.rf_cb) { state.rf_cb->flags = UIP_NEWDATA|UIP_POLL|UIP_CLOSE|UIP_ABORT|UIP_TIMEDOUT; @@ -1363,7 +1364,7 @@ static ssize_t tcp_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, /* Make sure that no further interrupts are processed */ - uip_tcpcallbackfree(conn, state.rf_cb); + tcp_callbackfree(conn, state.rf_cb); ret = recvfrom_result(ret, &state); } else diff --git a/net/send.c b/net/send.c index 6ff0d9f9875..b5219490537 100644 --- a/net/send.c +++ b/net/send.c @@ -43,6 +43,8 @@ #include #include +#include + #include "tcp/tcp.h" #include "pkt/pkt.h" #include "net.h" @@ -137,7 +139,7 @@ ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len, #if defined(CONFIG_NET_PKT) case SOCK_RAW: { - ret = pkt_send(psock, buf, len); + ret = psock_pkt_send(psock, buf, len); break; } #endif @@ -145,7 +147,7 @@ ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len, #if defined(CONFIG_NET_TCP) case SOCK_STREAM: { - ret = tcp_send(psock, buf, len); + ret = psock_tcp_send(psock, buf, len); break; } #endif diff --git a/net/socket.c b/net/socket.c index d7352c04a3e..b177e68c5be 100644 --- a/net/socket.c +++ b/net/socket.c @@ -195,7 +195,7 @@ int psock_socket(int domain, int type, int protocol, FAR struct socket *psock) * socket instance. */ - struct uip_conn *conn = uip_tcpalloc(); + FAR struct tcp_conn_s *conn = tcp_alloc(); if (!conn) { /* Failed to reserve a connection structure */ diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index b63725ac0c6..61089c90591 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -70,11 +70,73 @@ extern "C" * Public Function Prototypes ****************************************************************************/ +#ifdef CONFIG_NET_TCP +/* Defined in tcp_conn.c ****************************************************/ + +void tcp_initialize(void); +struct tcp_conn_s *tcp_active(FAR struct tcp_iphdr_s *buf); +struct tcp_conn_s *uip_nexttcpconn(FAR struct tcp_conn_s *conn); +struct tcp_conn_s *tcp_listener(uint16_t portno); +struct tcp_conn_s *tcp_alloc_accept(FAR struct tcp_iphdr_s *buf); + +/* Defined in tcp_seqno.c ***************************************************/ + +void tcp_setsequence(FAR uint8_t *seqno, uint32_t value); +uint32_t tcp_getsequence(FAR uint8_t *seqno); +uint32_t tcp_addsequence(FAR uint8_t *seqno, uint16_t len); +void tcp_initsequence(FAR uint8_t *seqno); +void tcp_nextsequence(void); + +/* Defined in tcp_poll.c ****************************************************/ + +void tcp_poll(FAR struct uip_driver_s *dev, FAR struct tcp_conn_s *conn); + +/* Defined in tcp_timer.c ***************************************************/ + +void tcp_timer(FAR struct uip_driver_s *dev, FAR struct tcp_conn_s *conn, + int hsec); + +/* Defined in tcp_listen.c **************************************************/ + +void tcp_listeninit(void); +bool tcp_islistener(uint16_t port); +int tcp_accept_connection(FAR struct uip_driver_s *dev, + FAR struct tcp_conn_s *conn, uint16_t portno); + +/* Defined in tcp_send.c ****************************************************/ + +void tcp_send(FAR struct uip_driver_s *dev, FAR struct tcp_conn_s *conn, + uint16_t flags, uint16_t len); +void tcp_reset(FAR struct uip_driver_s *dev); +void tcp_ack(FAR struct uip_driver_s *dev, FAR struct tcp_conn_s *conn, + uint8_t ack); + +/* Defined in tcp_appsend.c *************************************************/ + +void tcp_appsend(FAR struct uip_driver_s *dev, FAR struct tcp_conn_s *conn, + uint16_t result); +void tcp_rexmit(FAR struct uip_driver_s *dev, FAR struct tcp_conn_s *conn, + uint16_t result); + +/* Defined in tcp_input.c ***************************************************/ + +void tcp_input(FAR struct uip_driver_s *dev); + +/* Defined in tcp_callback.c ************************************************/ + +uint16_t tcp_callback(FAR struct uip_driver_s *dev, + FAR struct tcp_conn_s *conn, uint16_t flags); +#ifdef CONFIG_NET_TCP_READAHEAD +uint16_t tcp_datahandler(FAR struct tcp_conn_s *conn, + FAR uint8_t *buffer, uint16_t nbytes); +#endif +#endif /* CONFIG_NET_TCP */ + /**************************************************************************** - * Function: tcp_send + * Function: psock_tcp_send * * Description: - * The tcp_send() call may be used only when the TCP socket is in a + * The psock_tcp_send() call may be used only when the TCP socket is in a * connected state (so that the intended recipient is known). * * Parameters: @@ -128,7 +190,8 @@ extern "C" ****************************************************************************/ struct socket; -ssize_t tcp_send(FAR struct socket *psock, FAR const void *buf, size_t len); +ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf, + size_t len); /**************************************************************************** * Function: tcp_wrbuffer_initialize diff --git a/net/tcp/tcp_appsend.c b/net/tcp/tcp_appsend.c index 50eaf03523e..5493a4de8c0 100644 --- a/net/tcp/tcp_appsend.c +++ b/net/tcp/tcp_appsend.c @@ -53,6 +53,7 @@ #include #include "uip/uip.h" +#include "tcp/tcp.h" /**************************************************************************** * Pre-processor Definitions @@ -75,7 +76,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: uip_tcpappsend + * Name: tcp_appsend * * Description: * Handle application or TCP protocol response. If this function is called @@ -95,8 +96,8 @@ * ****************************************************************************/ -void uip_tcpappsend(struct uip_driver_s *dev, struct uip_conn *conn, - uint16_t result) +void tcp_appsend(FAR struct uip_driver_s *dev, FAR struct tcp_conn_s *conn, + uint16_t result) { /* Handle the result based on the application response */ @@ -111,7 +112,7 @@ void uip_tcpappsend(struct uip_driver_s *dev, struct uip_conn *conn, conn->tcpstateflags = UIP_CLOSED; nllvdbg("TCP state: UIP_CLOSED\n"); - uip_tcpsend(dev, conn, TCP_RST | TCP_ACK, UIP_IPTCPH_LEN); + tcp_send(dev, conn, TCP_RST | TCP_ACK, UIP_IPTCPH_LEN); } /* Check for connection closed */ @@ -124,7 +125,7 @@ void uip_tcpappsend(struct uip_driver_s *dev, struct uip_conn *conn, nllvdbg("TCP state: UIP_FIN_WAIT_1\n"); dev->d_sndlen = 0; - uip_tcpsend(dev, conn, TCP_FIN | TCP_ACK, UIP_IPTCPH_LEN); + tcp_send(dev, conn, TCP_FIN | TCP_ACK, UIP_IPTCPH_LEN); } /* None of the above */ @@ -158,12 +159,12 @@ void uip_tcpappsend(struct uip_driver_s *dev, struct uip_conn *conn, #endif /* Then handle the rest of the operation just as for the rexmit case */ - uip_tcprexmit(dev, conn, result); + tcp_rexmit(dev, conn, result); } } /**************************************************************************** - * Name: uip_tcprexmit + * Name: tcp_rexmit * * Description: * Handle application retransmission @@ -181,8 +182,8 @@ void uip_tcpappsend(struct uip_driver_s *dev, struct uip_conn *conn, * ****************************************************************************/ -void uip_tcprexmit(struct uip_driver_s *dev, struct uip_conn *conn, - uint16_t result) +void tcp_rexmit(FAR struct uip_driver_s *dev, FAR struct tcp_conn_s *conn, + uint16_t result) { nllvdbg("result: %04x d_sndlen: %d conn->unacked: %d\n", result, dev->d_sndlen, conn->unacked); @@ -203,14 +204,14 @@ void uip_tcprexmit(struct uip_driver_s *dev, struct uip_conn *conn, * the IP and TCP headers. */ - uip_tcpsend(dev, conn, TCP_ACK | TCP_PSH, dev->d_sndlen + UIP_TCPIP_HLEN); + tcp_send(dev, conn, TCP_ACK | TCP_PSH, dev->d_sndlen + UIP_TCPIP_HLEN); } /* If there is no data to send, just send out a pure ACK if one is requested`. */ else if ((result & UIP_SNDACK) != 0) { - uip_tcpsend(dev, conn, TCP_ACK, UIP_TCPIP_HLEN); + tcp_send(dev, conn, TCP_ACK, UIP_TCPIP_HLEN); } /* There is nothing to do -- drop the packet */ diff --git a/net/tcp/tcp_backlog.c b/net/tcp/tcp_backlog.c index e76af4e25ca..9899d7af04f 100644 --- a/net/tcp/tcp_backlog.c +++ b/net/tcp/tcp_backlog.c @@ -65,7 +65,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: uip_backlogcreate + * Function: tcp_backlogcreate * * Description: * Called from the listen() logic to setup the backlog as specified in the @@ -76,10 +76,10 @@ * ****************************************************************************/ -int uip_backlogcreate(FAR struct uip_conn *conn, int nblg) +int tcp_backlogcreate(FAR struct tcp_conn_s *conn, int nblg) { - FAR struct uip_backlog_s *bls = NULL; - FAR struct uip_blcontainer_s *blc; + FAR struct tcp_backlog_s *bls = NULL; + FAR struct tcp_blcontainer_s *blc; uip_lock_t flags; int size; int offset; @@ -103,18 +103,18 @@ int uip_backlogcreate(FAR struct uip_conn *conn, int nblg) * on 64-bit address machines -- REVISIT */ - offset = (sizeof(struct uip_backlog_s) + 3) & ~3; + offset = (sizeof(struct tcp_backlog_s) + 3) & ~3; /* Then determine the full size of the allocation include the - * uip_backlog_s, a pre-allocated array of struct uip_blcontainer_s + * tcp_backlog_s, a pre-allocated array of struct tcp_blcontainer_s * and alignment padding */ - size = offset + nblg * sizeof(struct uip_blcontainer_s); + size = offset + nblg * sizeof(struct tcp_blcontainer_s); /* Then allocate that much */ - bls = (FAR struct uip_backlog_s *)kzalloc(size); + bls = (FAR struct tcp_backlog_s *)kzalloc(size); if (!bls) { nlldbg("Failed to allocate backlog\n"); @@ -123,7 +123,7 @@ int uip_backlogcreate(FAR struct uip_conn *conn, int nblg) /* Then add all of the pre-allocated containers to the free list */ - blc = (FAR struct uip_blcontainer_s*)(((FAR uint8_t*)bls) + offset); + blc = (FAR struct tcp_blcontainer_s*)(((FAR uint8_t*)bls) + offset); for (i = 0; i < nblg; i++) { sq_addfirst(&blc->bc_node, &bls->bl_free); @@ -134,7 +134,7 @@ int uip_backlogcreate(FAR struct uip_conn *conn, int nblg) /* Destroy any existing backlog (shouldn't be any) */ flags = uip_lock(); - uip_backlogdestroy(conn); + tcp_backlogdestroy(conn); /* Now install the backlog tear-off in the connection. NOTE that bls may * actually be NULL if nblg is <= 0; In that case, we are disabling backlog @@ -148,13 +148,13 @@ int uip_backlogcreate(FAR struct uip_conn *conn, int nblg) } /**************************************************************************** - * Function: uip_backlogdestroy + * Function: tcp_backlogdestroy * * Description: - * (1) Called from uip_tcpfree() whenever a connection is freed. - * (2) Called from uip_backlogcreate() to destroy any old backlog + * (1) Called from tcp_free() whenever a connection is freed. + * (2) Called from tcp_backlogcreate() to destroy any old backlog * - * NOTE: This function may re-enter uip_tcpfree when a connection that + * NOTE: This function may re-enter tcp_free when a connection that * is freed that has pending connections. * * Assumptions: @@ -163,11 +163,11 @@ int uip_backlogcreate(FAR struct uip_conn *conn, int nblg) * ****************************************************************************/ -int uip_backlogdestroy(FAR struct uip_conn *conn) +int tcp_backlogdestroy(FAR struct tcp_conn_s *conn) { - FAR struct uip_backlog_s *blg; - FAR struct uip_blcontainer_s *blc; - FAR struct uip_conn *blconn; + FAR struct tcp_backlog_s *blg; + FAR struct tcp_blcontainer_s *blc; + FAR struct tcp_conn_s *blconn; nllvdbg("conn=%p\n", conn); @@ -189,7 +189,7 @@ int uip_backlogdestroy(FAR struct uip_conn *conn) /* Handle any pending connections in the backlog */ - while ((blc = (FAR struct uip_blcontainer_s*)sq_remfirst(&blg->bl_pending)) != NULL) + while ((blc = (FAR struct tcp_blcontainer_s*)sq_remfirst(&blg->bl_pending)) != NULL) { blconn = blc->bc_conn; if (blconn) @@ -199,7 +199,7 @@ int uip_backlogdestroy(FAR struct uip_conn *conn) blconn->blparent = NULL; blconn->backlog = NULL; blconn->crefs = 0; - uip_tcpfree(blconn); + tcp_free(blconn); } } @@ -212,10 +212,10 @@ int uip_backlogdestroy(FAR struct uip_conn *conn) } /**************************************************************************** - * Function: uip_backlogadd + * Function: tcp_backlogadd * * Description: - * Called uip_listen when a new connection is made with a listener socket + * Called tcp_listen when a new connection is made with a listener socket * but when there is no accept() in place to receive the connection. This * function adds the new connection to the backlog. * @@ -224,10 +224,10 @@ int uip_backlogdestroy(FAR struct uip_conn *conn) * ****************************************************************************/ -int uip_backlogadd(FAR struct uip_conn *conn, FAR struct uip_conn *blconn) +int tcp_backlogadd(FAR struct tcp_conn_s *conn, FAR struct tcp_conn_s *blconn) { - FAR struct uip_backlog_s *bls; - FAR struct uip_blcontainer_s *blc; + FAR struct tcp_backlog_s *bls; + FAR struct tcp_blcontainer_s *blc; int ret = -EINVAL; nllvdbg("conn=%p blconn=%p\n", conn, blconn); @@ -244,7 +244,7 @@ int uip_backlogadd(FAR struct uip_conn *conn, FAR struct uip_conn *blconn) { /* Allocate a container for the connection from the free list */ - blc = (FAR struct uip_blcontainer_s *)sq_remfirst(&bls->bl_free); + blc = (FAR struct tcp_blcontainer_s *)sq_remfirst(&bls->bl_free); if (!blc) { nlldbg("Failed to allocate container\n"); @@ -265,7 +265,7 @@ int uip_backlogadd(FAR struct uip_conn *conn, FAR struct uip_conn *blconn) } /**************************************************************************** - * Function: uip_backlogremove + * Function: tcp_backlogremove * * Description: * Called from poll(). Before waiting for a new connection, poll will @@ -277,14 +277,14 @@ int uip_backlogadd(FAR struct uip_conn *conn, FAR struct uip_conn *blconn) ****************************************************************************/ #ifndef CONFIG_DISABLE_POLL -bool uip_backlogavailable(FAR struct uip_conn *conn) +bool tcp_backlogavailable(FAR struct tcp_conn_s *conn) { return (conn && conn->backlog && !sq_empty(&conn->backlog->bl_pending)); } #endif /**************************************************************************** - * Function: uip_backlogremove + * Function: tcp_backlogremove * * Description: * Called from accept(). Before waiting for a new connection, accept will @@ -295,11 +295,11 @@ bool uip_backlogavailable(FAR struct uip_conn *conn) * ****************************************************************************/ -struct uip_conn *uip_backlogremove(FAR struct uip_conn *conn) +struct tcp_conn_s *tcp_backlogremove(FAR struct tcp_conn_s *conn) { - FAR struct uip_backlog_s *bls; - FAR struct uip_blcontainer_s *blc; - FAR struct uip_conn *blconn = NULL; + FAR struct tcp_backlog_s *bls; + FAR struct tcp_blcontainer_s *blc; + FAR struct tcp_conn_s *blconn = NULL; #ifdef CONFIG_DEBUG if (!conn) @@ -315,7 +315,7 @@ struct uip_conn *uip_backlogremove(FAR struct uip_conn *conn) * (FIFO) */ - blc = (FAR struct uip_blcontainer_s *)sq_remfirst(&bls->bl_pending); + blc = (FAR struct tcp_blcontainer_s *)sq_remfirst(&bls->bl_pending); if (blc) { /* Extract the connection reference from the container and put @@ -333,23 +333,23 @@ struct uip_conn *uip_backlogremove(FAR struct uip_conn *conn) } /**************************************************************************** - * Function: uip_backlogdelete + * Function: tcp_backlogdelete * * Description: - * Called from uip_tcpfree() when a connection is freed that this also - * retained in the pending connectino list of a listener. We simply need - * to remove the defunct connecton from the list. + * Called from tcp_free() when a connection is freed that this also + * retained in the pending connection list of a listener. We simply need + * to remove the defunct connection from the list. * * Assumptions: * Called from the interrupt level with interrupts disabled * ****************************************************************************/ -int uip_backlogdelete(FAR struct uip_conn *conn, FAR struct uip_conn *blconn) +int tcp_backlogdelete(FAR struct tcp_conn_s *conn, FAR struct tcp_conn_s *blconn) { - FAR struct uip_backlog_s *bls; - FAR struct uip_blcontainer_s *blc; - FAR struct uip_blcontainer_s *prev; + FAR struct tcp_backlog_s *bls; + FAR struct tcp_blcontainer_s *blc; + FAR struct tcp_blcontainer_s *prev; nllvdbg("conn=%p blconn=%p\n", conn, blconn); @@ -365,9 +365,9 @@ int uip_backlogdelete(FAR struct uip_conn *conn, FAR struct uip_conn *blconn) { /* Find the container hold the connection */ - for (blc = (FAR struct uip_blcontainer_s *)sq_peek(&bls->bl_pending), prev = NULL; + for (blc = (FAR struct tcp_blcontainer_s *)sq_peek(&bls->bl_pending), prev = NULL; blc; - prev = blc, blc = (FAR struct uip_blcontainer_s *)sq_next(&blc->bc_node)) + prev = blc, blc = (FAR struct tcp_blcontainer_s *)sq_next(&blc->bc_node)) { if (blc->bc_conn == blconn) { diff --git a/net/tcp/tcp_callback.c b/net/tcp/tcp_callback.c index f9a99d7ab8a..49b2947d871 100644 --- a/net/tcp/tcp_callback.c +++ b/net/tcp/tcp_callback.c @@ -50,6 +50,7 @@ #include #include "uip/uip.h" +#include "tcp/tcp.h" /**************************************************************************** * Private Data @@ -74,7 +75,7 @@ ****************************************************************************/ static inline uint16_t -uip_dataevent(FAR struct uip_driver_s *dev, FAR struct uip_conn *conn, +uip_dataevent(FAR struct uip_driver_s *dev, FAR struct tcp_conn_s *conn, uint16_t flags) { uint16_t ret; @@ -104,7 +105,7 @@ uip_dataevent(FAR struct uip_driver_s *dev, FAR struct uip_conn *conn, * partial packets will not be buffered. */ - recvlen = uip_datahandler(conn, buffer, buflen); + recvlen = tcp_datahandler(conn, buffer, buflen); if (recvlen < buflen) #endif { @@ -135,7 +136,7 @@ uip_dataevent(FAR struct uip_driver_s *dev, FAR struct uip_conn *conn, ****************************************************************************/ /**************************************************************************** - * Function: uip_tcpcallback + * Function: tcp_callback * * Description: * Inform the application holding the TCP socket of a change in state. @@ -145,8 +146,8 @@ uip_dataevent(FAR struct uip_driver_s *dev, FAR struct uip_conn *conn, * ****************************************************************************/ -uint16_t uip_tcpcallback(struct uip_driver_s *dev, struct uip_conn *conn, - uint16_t flags) +uint16_t tcp_callback(FAR struct uip_driver_s *dev, FAR struct tcp_conn_s *conn, + uint16_t flags) { /* Preserve the UIP_ACKDATA, UIP_CLOSE, and UIP_ABORT in the response. * These is needed by uIP to handle responses and buffer state. The @@ -206,7 +207,7 @@ uint16_t uip_tcpcallback(struct uip_driver_s *dev, struct uip_conn *conn, } /**************************************************************************** - * Function: uip_datahandler + * Function: tcp_datahandler * * Description: * Handle data that is not accepted by the application. This may be called @@ -232,7 +233,7 @@ uint16_t uip_tcpcallback(struct uip_driver_s *dev, struct uip_conn *conn, ****************************************************************************/ #ifdef CONFIG_NET_TCP_READAHEAD -uint16_t uip_datahandler(FAR struct uip_conn *conn, FAR uint8_t *buffer, +uint16_t tcp_datahandler(FAR struct tcp_conn_s *conn, FAR uint8_t *buffer, uint16_t buflen) { FAR struct iob_s *iob; diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c index 573d8cbf9b1..53ce386e442 100644 --- a/net/tcp/tcp_conn.c +++ b/net/tcp/tcp_conn.c @@ -68,7 +68,7 @@ /* The array containing all uIP TCP connections. */ -static struct uip_conn g_tcp_connections[CONFIG_NET_TCP_CONNS]; +static struct tcp_conn_s g_tcp_connections[CONFIG_NET_TCP_CONNS]; /* A list of all free TCP connections */ @@ -135,7 +135,7 @@ static int uip_selectport(uint16_t portno) g_last_tcp_port = 4096; } } - while (uip_tcplistener(htons(g_last_tcp_port))); + while (tcp_listener(htons(g_last_tcp_port))); } else { @@ -143,7 +143,7 @@ static int uip_selectport(uint16_t portno) * connection is using this local port. */ - if (uip_tcplistener(portno)) + if (tcp_listener(portno)) { /* It is in use... return EADDRINUSE */ @@ -161,7 +161,7 @@ static int uip_selectport(uint16_t portno) ****************************************************************************/ /**************************************************************************** - * Name: uip_tcpinit() + * Name: tcp_initialize() * * Description: * Initialize the TCP/IP connection structures. Called only once and only @@ -169,7 +169,7 @@ static int uip_selectport(uint16_t portno) * ****************************************************************************/ -void uip_tcpinit(void) +void tcp_initialize(void) { int i; @@ -192,7 +192,7 @@ void uip_tcpinit(void) } /**************************************************************************** - * Name: uip_tcpalloc() + * Name: tcp_alloc() * * Description: * Find a free TCP/IP connection structure and allocate it @@ -202,9 +202,9 @@ void uip_tcpinit(void) * ****************************************************************************/ -struct uip_conn *uip_tcpalloc(void) +FAR struct tcp_conn_s *tcp_alloc(void) { - struct uip_conn *conn; + FAR struct tcp_conn_s *conn; uip_lock_t flags; /* Because this routine is called from both interrupt level and @@ -216,7 +216,7 @@ struct uip_conn *uip_tcpalloc(void) /* Return the entry from the head of the free list */ - conn = (struct uip_conn *)dq_remfirst(&g_free_tcp_connections); + conn = (FAR struct tcp_conn_s *)dq_remfirst(&g_free_tcp_connections); #ifndef CONFIG_NET_SOLINGER /* Is the free list empty? */ @@ -229,8 +229,8 @@ struct uip_conn *uip_tcpalloc(void) * that is about to be closed anyway. */ - FAR struct uip_conn *tmp = - (FAR struct uip_conn *)g_active_tcp_connections.head; + FAR struct tcp_conn_s *tmp = + (FAR struct tcp_conn_s *)g_active_tcp_connections.head; while (tmp) { @@ -260,7 +260,7 @@ struct uip_conn *uip_tcpalloc(void) /* Look at the next active connection */ - tmp = (FAR struct uip_conn *)tmp->node.flink; + tmp = (FAR struct tcp_conn_s *)tmp->node.flink; } /* Did we find a connection that we can re-use? */ @@ -282,11 +282,11 @@ struct uip_conn *uip_tcpalloc(void) * waiting for it. */ - uip_tcpfree(conn); + tcp_free(conn); /* Now there is guaranteed to be one free connection. Get it! */ - conn = (struct uip_conn *)dq_remfirst(&g_free_tcp_connections); + conn = (FAR struct tcp_conn_s *)dq_remfirst(&g_free_tcp_connections); } } #endif @@ -297,7 +297,7 @@ struct uip_conn *uip_tcpalloc(void) if (conn) { - memset(conn, 0, sizeof(struct uip_conn)); + memset(conn, 0, sizeof(struct tcp_conn_s)); conn->tcpstateflags = UIP_ALLOCATED; } @@ -305,7 +305,7 @@ struct uip_conn *uip_tcpalloc(void) } /**************************************************************************** - * Name: uip_tcpfree() + * Name: tcp_free() * * Description: * Free a connection structure that is no longer in use. This should be @@ -313,7 +313,7 @@ struct uip_conn *uip_tcpalloc(void) * ****************************************************************************/ -void uip_tcpfree(struct uip_conn *conn) +void tcp_free(FAR struct tcp_conn_s *conn) { FAR struct uip_callback_s *cb; FAR struct uip_callback_s *next; @@ -337,7 +337,7 @@ void uip_tcpfree(struct uip_conn *conn) for (cb = conn->list; cb; cb = next) { next = cb->flink; - uip_tcpcallbackfree(conn, cb); + tcp_callbackfree(conn, cb); } /* UIP_ALLOCATED means that that the connection is not in the active list @@ -376,7 +376,7 @@ void uip_tcpfree(struct uip_conn *conn) if (conn->backlog) { - uip_backlogdestroy(conn); + tcp_backlogdestroy(conn); } /* If this connection is, itself, backlogged, then remove it from the @@ -385,7 +385,7 @@ void uip_tcpfree(struct uip_conn *conn) if (conn->blparent) { - uip_backlogdelete(conn->blparent, conn); + tcp_backlogdelete(conn->blparent, conn); } #endif @@ -397,7 +397,7 @@ void uip_tcpfree(struct uip_conn *conn) } /**************************************************************************** - * Name: uip_tcpactive() + * Name: tcp_active() * * Description: * Find a connection structure that is the appropriate @@ -408,10 +408,10 @@ void uip_tcpfree(struct uip_conn *conn) * ****************************************************************************/ -struct uip_conn *uip_tcpactive(struct uip_tcpip_hdr *buf) +FAR struct tcp_conn_s *tcp_active(struct tcp_iphdr_s *buf) { - struct uip_conn *conn = (struct uip_conn *)g_active_tcp_connections.head; - in_addr_t srcipaddr = uip_ip4addr_conv(buf->srcipaddr); + FAR struct tcp_conn_s *conn = (struct tcp_conn_s *)g_active_tcp_connections.head; + in_addr_t srcipaddr = uip_ip4addr_conv(buf->srcipaddr); while (conn) { @@ -430,7 +430,7 @@ struct uip_conn *uip_tcpactive(struct uip_tcpip_hdr *buf) /* Look at the next active connection */ - conn = (struct uip_conn *)conn->node.flink; + conn = (FAR struct tcp_conn_s *)conn->node.flink; } return conn; @@ -448,20 +448,20 @@ struct uip_conn *uip_tcpactive(struct uip_tcpip_hdr *buf) * ****************************************************************************/ -struct uip_conn *uip_nexttcpconn(struct uip_conn *conn) +FAR struct tcp_conn_s *uip_nexttcpconn(FAR struct tcp_conn_s *conn) { if (!conn) { - return (struct uip_conn *)g_active_tcp_connections.head; + return (FAR struct tcp_conn_s *)g_active_tcp_connections.head; } else { - return (struct uip_conn *)conn->node.flink; + return (FAR struct tcp_conn_s *)conn->node.flink; } } /**************************************************************************** - * Name: uip_tcplistener() + * Name: tcp_listener() * * Description: * Given a local port number (in network byte order), find the TCP @@ -472,9 +472,9 @@ struct uip_conn *uip_nexttcpconn(struct uip_conn *conn) * ****************************************************************************/ -struct uip_conn *uip_tcplistener(uint16_t portno) +FAR struct tcp_conn_s *tcp_listener(uint16_t portno) { - struct uip_conn *conn; + FAR struct tcp_conn_s *conn; int i; /* Check if this port number is in use by any active UIP TCP connection */ @@ -494,10 +494,10 @@ struct uip_conn *uip_tcplistener(uint16_t portno) } /**************************************************************************** - * Name: uip_tcpaccept() + * Name: tcp_alloc_accept() * * Description: - * Called when uip_interupt matches the incoming packet with a connection + * Called when uip_interrupt matches the incoming packet with a connection * in LISTEN. In that case, this function will create a new connection and * initialize it to send a SYNACK in return. * @@ -506,9 +506,9 @@ struct uip_conn *uip_tcplistener(uint16_t portno) * ****************************************************************************/ -struct uip_conn *uip_tcpaccept(struct uip_tcpip_hdr *buf) +FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct tcp_iphdr_s *buf) { - struct uip_conn *conn = uip_tcpalloc(); + FAR struct tcp_conn_s *conn = tcp_alloc(); if (conn) { /* Fill in the necessary fields for the new connection. */ @@ -524,7 +524,7 @@ struct uip_conn *uip_tcpaccept(struct uip_tcpip_hdr *buf) uip_ipaddr_copy(conn->ripaddr, uip_ip4addr_conv(buf->srcipaddr)); conn->tcpstateflags = UIP_SYN_RCVD; - uip_tcpinitsequence(conn->sndseq); + tcp_initsequence(conn->sndseq); conn->unacked = 1; #ifdef CONFIG_NET_TCP_WRITE_BUFFERS conn->expired = 0; @@ -560,7 +560,7 @@ struct uip_conn *uip_tcpaccept(struct uip_tcpip_hdr *buf) } /**************************************************************************** - * Name: uip_tcpbind() + * Name: tcp_bind() * * Description: * This function implements the UIP specific parts of the standard TCP @@ -575,9 +575,11 @@ struct uip_conn *uip_tcpaccept(struct uip_tcpip_hdr *buf) ****************************************************************************/ #ifdef CONFIG_NET_IPv6 -int uip_tcpbind(struct uip_conn *conn, const struct sockaddr_in6 *addr) +int tcp_bind(FAR struct tcp_conn_s *conn, + FAR const struct sockaddr_in6 *addr) #else -int uip_tcpbind(struct uip_conn *conn, const struct sockaddr_in *addr) +int tcp_bind(FAR struct tcp_conn_s *conn, + FAR const struct sockaddr_in *addr) #endif { uip_lock_t flags; @@ -613,7 +615,7 @@ int uip_tcpbind(struct uip_conn *conn, const struct sockaddr_in *addr) } /**************************************************************************** - * Name: uip_tcpconnect() + * Name: tcp_connect * * Description: * This function implements the UIP specific parts of the standard @@ -625,7 +627,7 @@ int uip_tcpbind(struct uip_conn *conn, const struct sockaddr_in *addr) * the SYN_SENT state and sets the retransmission timer to 0. This will * cause a TCP SYN segment to be sent out the next time this connection * is periodically processed, which usually is done within 0.5 seconds - * after the call to uip_tcpconnect(). + * after the call to tcp_connect(). * * Assumptions: * This function is called from normal user level code. @@ -633,9 +635,11 @@ int uip_tcpbind(struct uip_conn *conn, const struct sockaddr_in *addr) ****************************************************************************/ #ifdef CONFIG_NET_IPv6 -int uip_tcpconnect(struct uip_conn *conn, const struct sockaddr_in6 *addr) +int tcp_connect(FAR struct tcp_conn_s *conn, + FAR const struct sockaddr_in6 *addr) #else -int uip_tcpconnect(struct uip_conn *conn, const struct sockaddr_in *addr) +int tcp_connect(FAR struct tcp_conn_s *conn, + FAR const struct sockaddr_in *addr) #endif { uip_lock_t flags; @@ -667,7 +671,7 @@ int uip_tcpconnect(struct uip_conn *conn, const struct sockaddr_in *addr) /* Initialize and return the connection structure, bind it to the port number */ conn->tcpstateflags = UIP_SYN_SENT; - uip_tcpinitsequence(conn->sndseq); + tcp_initsequence(conn->sndseq); conn->mss = UIP_TCP_INITIAL_MSS; conn->unacked = 1; /* TCP length of the SYN is one. */ diff --git a/net/tcp/tcp_input.c b/net/tcp/tcp_input.c index 60a7151fcb3..68e500a110f 100644 --- a/net/tcp/tcp_input.c +++ b/net/tcp/tcp_input.c @@ -55,12 +55,13 @@ #include #include "uip/uip.h" +#include "tcp/tcp.h" /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ -#define BUF ((struct uip_tcpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) +#define BUF ((struct tcp_iphdr_s *)&dev->d_buf[UIP_LLH_LEN]) /**************************************************************************** * Public Variables @@ -79,7 +80,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: uip_tcpinput + * Name: tcp_input * * Description: * Handle incoming TCP input @@ -95,10 +96,10 @@ * ****************************************************************************/ -void uip_tcpinput(struct uip_driver_s *dev) +void tcp_input(struct uip_driver_s *dev) { - struct uip_conn *conn = NULL; - struct uip_tcpip_hdr *pbuf = BUF; + struct tcp_conn_s *conn = NULL; + struct tcp_iphdr_s *pbuf = BUF; uint16_t tmp16; uint16_t flags; uint8_t opt; @@ -115,7 +116,7 @@ void uip_tcpinput(struct uip_driver_s *dev) /* Start of TCP input header processing code. */ - if (uip_tcpchksum(dev) != 0xffff) + if (tcp_chksum(dev) != 0xffff) { /* Compute and check the TCP checksum. */ @@ -129,7 +130,7 @@ void uip_tcpinput(struct uip_driver_s *dev) /* Demultiplex this segment. First check any active connections. */ - conn = uip_tcpactive(pbuf); + conn = tcp_active(pbuf); if (conn) { /* We found an active connection.. Check for the subsequent SYN @@ -162,7 +163,7 @@ void uip_tcpinput(struct uip_driver_s *dev) */ tmp16 = pbuf->destport; - if (uip_islistener(tmp16)) + if (tcp_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 @@ -173,7 +174,7 @@ void uip_tcpinput(struct uip_driver_s *dev) * user application to accept it. */ - conn = uip_tcpaccept(pbuf); + conn = tcp_alloc_accept(pbuf); if (conn) { /* The connection structure was successfully allocated. Now see if @@ -182,12 +183,12 @@ void uip_tcpinput(struct uip_driver_s *dev) */ conn->crefs = 1; - if (uip_accept(dev, conn, tmp16) != OK) + if (tcp_accept_connection(dev, conn, tmp16) != OK) { /* No, then we have to give the connection back and drop the packet */ conn->crefs = 0; - uip_tcpfree(conn); + tcp_free(conn); conn = NULL; } } @@ -262,7 +263,7 @@ void uip_tcpinput(struct uip_driver_s *dev) /* Our response will be a SYNACK. */ - uip_tcpack(dev, conn, TCP_ACK | TCP_SYN); + tcp_ack(dev, conn, TCP_ACK | TCP_SYN); return; } } @@ -283,7 +284,7 @@ reset: #ifdef CONFIG_NET_STATISTICS uip_stat.tcp.synrst++; #endif - uip_tcpreset(dev); + tcp_reset(dev); return; found: @@ -305,7 +306,7 @@ found: conn->tcpstateflags = UIP_CLOSED; nlldbg("RESET - TCP state: UIP_CLOSED\n"); - (void)uip_tcpcallback(dev, conn, UIP_ABORT); + (void)tcp_callback(dev, conn, UIP_ABORT); goto drop; } @@ -337,7 +338,7 @@ found: if ((dev->d_len > 0 || ((pbuf->flags & (TCP_SYN | TCP_FIN)) != 0)) && memcmp(pbuf->seqno, conn->rcvseq, 4) != 0) { - uip_tcpsend(dev, conn, TCP_ACK, UIP_IPTCPH_LEN); + tcp_send(dev, conn, TCP_ACK, UIP_IPTCPH_LEN); return; } } @@ -361,14 +362,14 @@ found: #ifdef CONFIG_NET_TCP_WRITE_BUFFERS unackseq = conn->isn + conn->sent; #else - unackseq = uip_tcpaddsequence(conn->sndseq, conn->unacked); + unackseq = tcp_addsequence(conn->sndseq, conn->unacked); #endif /* Get the sequence number of that has just been acknowledged by this * incoming packet. */ - ackseq = uip_tcpgetsequence(pbuf->ackno); + ackseq = tcp_getsequence(pbuf->ackno); /* Check how many of the outstanding bytes have been acknowledged. For * a most uIP send operation, this should always be true. However, @@ -394,7 +395,7 @@ found: if ((conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) { nlldbg("ERROR: conn->sndseq %d, conn->unacked %d\n", - uip_tcpgetsequence(conn->sndseq), conn->unacked); + tcp_getsequence(conn->sndseq), conn->unacked); goto reset; } } @@ -406,7 +407,7 @@ found: nllvdbg("sndseq: %08x->%08x unackseq: %08x new unacked: %d\n", conn->sndseq, ackseq, unackseq, conn->unacked); - uip_tcpsetsequence(conn->sndseq, ackseq); + tcp_setsequence(conn->sndseq, ackseq); /* Do RTT estimation, unless we have done retransmissions. */ @@ -460,8 +461,8 @@ found: conn->tcpstateflags = UIP_ESTABLISHED; #ifdef CONFIG_NET_TCP_WRITE_BUFFERS - conn->isn = uip_tcpgetsequence(pbuf->ackno); - uip_tcpsetsequence(conn->sndseq, conn->isn); + conn->isn = tcp_getsequence(pbuf->ackno); + tcp_setsequence(conn->sndseq, conn->isn); conn->sent = 0; #endif conn->unacked = 0; @@ -475,8 +476,8 @@ found: } dev->d_sndlen = 0; - result = uip_tcpcallback(dev, conn, flags); - uip_tcpappsend(dev, conn, result); + result = tcp_callback(dev, conn, flags); + tcp_appsend(dev, conn, result); return; } @@ -484,7 +485,7 @@ found: if ((pbuf->flags & TCP_CTL) == TCP_SYN) { - uip_tcpack(dev, conn, TCP_ACK | TCP_SYN); + tcp_ack(dev, conn, TCP_ACK | TCP_SYN); return; } @@ -558,21 +559,21 @@ found: conn->unacked = 0; #ifdef CONFIG_NET_TCP_WRITE_BUFFERS - conn->isn = uip_tcpgetsequence(pbuf->ackno); - uip_tcpsetsequence(conn->sndseq, conn->isn); + conn->isn = tcp_getsequence(pbuf->ackno); + tcp_setsequence(conn->sndseq, conn->isn); #endif dev->d_len = 0; dev->d_sndlen = 0; nllvdbg("TCP state: UIP_ESTABLISHED\n"); - result = uip_tcpcallback(dev, conn, UIP_CONNECTED | UIP_NEWDATA); - uip_tcpappsend(dev, conn, result); + result = tcp_callback(dev, conn, UIP_CONNECTED | UIP_NEWDATA); + tcp_appsend(dev, conn, result); return; } /* Inform the application that the connection failed */ - (void)uip_tcpcallback(dev, conn, UIP_ABORT); + (void)tcp_callback(dev, conn, UIP_ABORT); /* The connection is closed after we send the RST */ @@ -586,7 +587,7 @@ found: goto drop; } - uip_tcpreset(dev); + tcp_reset(dev); return; case UIP_ESTABLISHED: @@ -628,14 +629,14 @@ found: flags |= UIP_NEWDATA; } - (void)uip_tcpcallback(dev, conn, flags); + (void)tcp_callback(dev, conn, flags); conn->tcpstateflags = UIP_LAST_ACK; conn->unacked = 1; conn->nrtx = 0; nllvdbg("TCP state: UIP_LAST_ACK\n"); - uip_tcpsend(dev, conn, TCP_FIN | TCP_ACK, UIP_IPTCPH_LEN); + tcp_send(dev, conn, TCP_FIN | TCP_ACK, UIP_IPTCPH_LEN); return; } @@ -709,12 +710,12 @@ found: /* Provide the packet to the application */ - result = uip_tcpcallback(dev, conn, flags); + result = tcp_callback(dev, conn, flags); /* If the application successfully handled the incoming data, * then UIP_SNDACK will be set in the result. In this case, * we need to update the sequence number. The ACK will be - * send by uip_tcpappsend(). + * send by tcp_appsend(). */ if ((result & UIP_SNDACK) != 0) @@ -726,7 +727,7 @@ found: /* Send the response, ACKing the data or not, as appropriate */ - uip_tcpappsend(dev, conn, result); + tcp_appsend(dev, conn, result); return; } @@ -742,7 +743,7 @@ found: conn->tcpstateflags = UIP_CLOSED; nllvdbg("UIP_LAST_ACK TCP state: UIP_CLOSED\n"); - (void)uip_tcpcallback(dev, conn, UIP_CLOSE); + (void)tcp_callback(dev, conn, UIP_CLOSE); } break; @@ -773,8 +774,8 @@ found: } uip_incr32(conn->rcvseq, 1); - (void)uip_tcpcallback(dev, conn, UIP_CLOSE); - uip_tcpsend(dev, conn, TCP_ACK, UIP_IPTCPH_LEN); + (void)tcp_callback(dev, conn, UIP_CLOSE); + tcp_send(dev, conn, TCP_ACK, UIP_IPTCPH_LEN); return; } else if ((flags & UIP_ACKDATA) != 0) @@ -787,7 +788,7 @@ found: if (dev->d_len > 0) { - uip_tcpsend(dev, conn, TCP_ACK, UIP_IPTCPH_LEN); + tcp_send(dev, conn, TCP_ACK, UIP_IPTCPH_LEN); return; } @@ -806,21 +807,21 @@ found: nllvdbg("TCP state: UIP_TIME_WAIT\n"); uip_incr32(conn->rcvseq, 1); - (void)uip_tcpcallback(dev, conn, UIP_CLOSE); - uip_tcpsend(dev, conn, TCP_ACK, UIP_IPTCPH_LEN); + (void)tcp_callback(dev, conn, UIP_CLOSE); + tcp_send(dev, conn, TCP_ACK, UIP_IPTCPH_LEN); return; } if (dev->d_len > 0) { - uip_tcpsend(dev, conn, TCP_ACK, UIP_IPTCPH_LEN); + tcp_send(dev, conn, TCP_ACK, UIP_IPTCPH_LEN); return; } goto drop; case UIP_TIME_WAIT: - uip_tcpsend(dev, conn, TCP_ACK, UIP_IPTCPH_LEN); + tcp_send(dev, conn, TCP_ACK, UIP_IPTCPH_LEN); return; case UIP_CLOSING: diff --git a/net/tcp/tcp_listen.c b/net/tcp/tcp_listen.c index daff5299692..13583287e7d 100644 --- a/net/tcp/tcp_listen.c +++ b/net/tcp/tcp_listen.c @@ -51,21 +51,22 @@ #include #include "uip/uip.h" +#include "tcp/tcp.h" /**************************************************************************** * Private Data ****************************************************************************/ -/* The uip_listenports list all currently listening ports. */ +/* The tcp_listenports list all currently listening ports. */ -static struct uip_conn *uip_listenports[CONFIG_NET_MAX_LISTENPORTS]; +static FAR struct tcp_conn_s *tcp_listenports[CONFIG_NET_MAX_LISTENPORTS]; /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** - * Function: uip_findlistener + * Function: tcp_findlistener * * Description: * Return the connection listener for connections on this port (if any) @@ -75,7 +76,7 @@ static struct uip_conn *uip_listenports[CONFIG_NET_MAX_LISTENPORTS]; * ****************************************************************************/ -struct uip_conn *uip_findlistener(uint16_t portno) +FAR struct tcp_conn_s *tcp_findlistener(uint16_t portno) { int ndx; @@ -87,7 +88,7 @@ struct uip_conn *uip_findlistener(uint16_t portno) * local port number? */ - struct uip_conn *conn = uip_listenports[ndx]; + FAR struct tcp_conn_s *conn = tcp_listenports[ndx]; if (conn && conn->lport == portno) { /* Yes.. we found a listener on this port */ @@ -106,7 +107,7 @@ struct uip_conn *uip_findlistener(uint16_t portno) ****************************************************************************/ /**************************************************************************** - * Function: uip_listeninit + * Function: tcp_listeninit * * Description: * Setup the listening data structures @@ -117,17 +118,17 @@ struct uip_conn *uip_findlistener(uint16_t portno) * ****************************************************************************/ -void uip_listeninit(void) +void tcp_listeninit(void) { int ndx; for (ndx = 0; ndx < CONFIG_NET_MAX_LISTENPORTS; ndx++) { - uip_listenports[ndx] = NULL; + tcp_listenports[ndx] = NULL; } } /**************************************************************************** - * Function: uip_unlisten + * Function: tcp_unlisten * * Description: * Stop listening to the port bound to the specified TCP connection @@ -137,7 +138,7 @@ void uip_listeninit(void) * ****************************************************************************/ -int uip_unlisten(struct uip_conn *conn) +int tcp_unlisten(FAR struct tcp_conn_s *conn) { uip_lock_t flags; int ndx; @@ -146,9 +147,9 @@ int uip_unlisten(struct uip_conn *conn) flags = uip_lock(); for (ndx = 0; ndx < CONFIG_NET_MAX_LISTENPORTS; ndx++) { - if (uip_listenports[ndx] == conn) + if (tcp_listenports[ndx] == conn) { - uip_listenports[ndx] = NULL; + tcp_listenports[ndx] = NULL; ret = OK; break; } @@ -159,7 +160,7 @@ int uip_unlisten(struct uip_conn *conn) } /**************************************************************************** - * Function: uip_listen + * Function: tcp_listen * * Description: * Start listening to the port bound to the specified TCP connection @@ -169,7 +170,7 @@ int uip_unlisten(struct uip_conn *conn) * ****************************************************************************/ -int uip_listen(struct uip_conn *conn) +int tcp_listen(FAR struct tcp_conn_s *conn) { uip_lock_t flags; int ndx; @@ -183,7 +184,7 @@ int uip_listen(struct uip_conn *conn) /* First, check if there is already a socket listening on this port */ - if (uip_islistener(conn->lport)) + if (tcp_islistener(conn->lport)) { /* Yes, then we must refuse this request */ @@ -203,11 +204,11 @@ int uip_listen(struct uip_conn *conn) { /* Is the next slot available? */ - if (!uip_listenports[ndx]) + if (!tcp_listenports[ndx]) { /* Yes.. we found it */ - uip_listenports[ndx] = conn; + tcp_listenports[ndx] = conn; ret = OK; break; } @@ -219,7 +220,7 @@ int uip_listen(struct uip_conn *conn) } /**************************************************************************** - * Function: uip_islistener + * Function: tcp_islistener * * Description: * Return true is there is a listener for the specified port @@ -229,13 +230,13 @@ int uip_listen(struct uip_conn *conn) * ****************************************************************************/ -bool uip_islistener(uint16_t portno) +bool tcp_islistener(uint16_t portno) { - return uip_findlistener(portno) != NULL; + return tcp_findlistener(portno) != NULL; } /**************************************************************************** - * Function: uip_accept + * Function: tcp_accept_connection * * Description: * Accept the new connection for the specified listening port. @@ -245,10 +246,10 @@ bool uip_islistener(uint16_t portno) * ****************************************************************************/ -int uip_accept(struct uip_driver_s *dev, struct uip_conn *conn, - uint16_t portno) +int tcp_accept_connection(FAR struct uip_driver_s *dev, + FAR struct tcp_conn_s *conn, uint16_t portno) { - struct uip_conn *listener; + FAR struct tcp_conn_s *listener; int ret = ERROR; /* The interrupt logic has already allocated and initialized a TCP @@ -256,7 +257,7 @@ int uip_accept(struct uip_driver_s *dev, struct uip_conn *conn, * connection. */ - listener = uip_findlistener(portno); + listener = tcp_findlistener(portno); if (listener) { /* Yes, there is a listener. Is it accepting connections now? */ @@ -274,10 +275,10 @@ int uip_accept(struct uip_driver_s *dev, struct uip_conn *conn, * may be waiting on poll()/select() that the connection is available. */ - ret = uip_backlogadd(listener, conn); + ret = tcp_backlogadd(listener, conn); if (ret == OK) { - (void)uip_tcpcallback(dev, listener, UIP_BACKLOG); + (void)tcp_callback(dev, listener, UIP_BACKLOG); } } #endif diff --git a/net/tcp/tcp_poll.c b/net/tcp/tcp_poll.c index e741344e8ae..cc33a00a9cd 100644 --- a/net/tcp/tcp_poll.c +++ b/net/tcp/tcp_poll.c @@ -53,6 +53,7 @@ #include #include "uip/uip.h" +#include "tcp/tcp.h" /**************************************************************************** * Pre-processor Definitions @@ -75,7 +76,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: uip_tcppoll + * Name: tcp_poll * * Description: * Poll a TCP connection structure for availability of TX data @@ -92,7 +93,7 @@ * ****************************************************************************/ -void uip_tcppoll(struct uip_driver_s *dev, struct uip_conn *conn) +void tcp_poll(FAR struct uip_driver_s *dev, FAR struct tcp_conn_s *conn) { uint8_t result; @@ -110,11 +111,11 @@ void uip_tcppoll(struct uip_driver_s *dev, struct uip_conn *conn) /* Perform the callback */ - result = uip_tcpcallback(dev, conn, UIP_POLL); + result = tcp_callback(dev, conn, UIP_POLL); /* Handle the callback response */ - uip_tcpappsend(dev, conn, result); + tcp_appsend(dev, conn, result); } else { diff --git a/net/tcp/tcp_send.c b/net/tcp/tcp_send.c index 5aa2ef59936..54f10babaa5 100644 --- a/net/tcp/tcp_send.c +++ b/net/tcp/tcp_send.c @@ -58,7 +58,7 @@ * Pre-processor Definitions ****************************************************************************/ -#define BUF ((struct uip_tcpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) +#define BUF ((struct tcp_iphdr_s *)&dev->d_buf[UIP_LLH_LEN]) /**************************************************************************** * Public Variables @@ -73,7 +73,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: uip_tcpsendcomplete + * Name: tcp_sendcomplete * * Description: * Complete the final portions of the send operation. This function sets @@ -90,9 +90,9 @@ * ****************************************************************************/ -static void uip_tcpsendcomplete(FAR struct uip_driver_s *dev) +static void tcp_sendcomplete(FAR struct uip_driver_s *dev) { - FAR struct uip_tcpip_hdr *pbuf = BUF; + FAR struct tcp_iphdr_s *pbuf = BUF; pbuf->ttl = UIP_TTL; @@ -117,7 +117,7 @@ static void uip_tcpsendcomplete(FAR struct uip_driver_s *dev) /* Calculate TCP checksum. */ pbuf->tcpchksum = 0; - pbuf->tcpchksum = ~(uip_tcpchksum(dev)); + pbuf->tcpchksum = ~(tcp_chksum(dev)); #ifdef CONFIG_NET_IPv6 @@ -152,7 +152,7 @@ static void uip_tcpsendcomplete(FAR struct uip_driver_s *dev) } /**************************************************************************** - * Name: uip_tcpsendcommon + * Name: tcp_sendcommon * * Description: * We're done with the input processing. We are now ready to send a reply @@ -171,10 +171,10 @@ static void uip_tcpsendcomplete(FAR struct uip_driver_s *dev) * ****************************************************************************/ -static void uip_tcpsendcommon(FAR struct uip_driver_s *dev, - FAR struct uip_conn *conn) +static void tcp_sendcommon(FAR struct uip_driver_s *dev, + FAR struct tcp_conn_s *conn) { - FAR struct uip_tcpip_hdr *pbuf = BUF; + FAR struct tcp_iphdr_s *pbuf = BUF; memcpy(pbuf->ackno, conn->rcvseq, 4); memcpy(pbuf->seqno, conn->sndseq, 4); @@ -205,7 +205,7 @@ static void uip_tcpsendcommon(FAR struct uip_driver_s *dev, * the message. */ - uip_tcpsendcomplete(dev); + tcp_sendcomplete(dev); } /**************************************************************************** @@ -213,7 +213,7 @@ static void uip_tcpsendcommon(FAR struct uip_driver_s *dev, ****************************************************************************/ /**************************************************************************** - * Name: uip_tcpsend + * Name: tcp_send * * Description: * Setup to send a TCP packet @@ -232,19 +232,19 @@ static void uip_tcpsendcommon(FAR struct uip_driver_s *dev, * ****************************************************************************/ -void uip_tcpsend(FAR struct uip_driver_s *dev, FAR struct uip_conn *conn, - uint16_t flags, uint16_t len) +void tcp_send(FAR struct uip_driver_s *dev, FAR struct tcp_conn_s *conn, + uint16_t flags, uint16_t len) { - FAR struct uip_tcpip_hdr *pbuf = BUF; + FAR struct tcp_iphdr_s *pbuf = BUF; pbuf->flags = flags; dev->d_len = len; pbuf->tcpoffset = (UIP_TCPH_LEN / 4) << 4; - uip_tcpsendcommon(dev, conn); + tcp_sendcommon(dev, conn); } /**************************************************************************** - * Name: uip_tcpreset + * Name: tcp_reset * * Description: * Send a TCP reset (no-data) message @@ -260,9 +260,9 @@ void uip_tcpsend(FAR struct uip_driver_s *dev, FAR struct uip_conn *conn, * ****************************************************************************/ -void uip_tcpreset(FAR struct uip_driver_s *dev) +void tcp_reset(FAR struct uip_driver_s *dev) { - FAR struct uip_tcpip_hdr *pbuf = BUF; + FAR struct tcp_iphdr_s *pbuf = BUF; uint16_t tmp16; uint8_t seqbyte; @@ -321,11 +321,11 @@ void uip_tcpreset(FAR struct uip_driver_s *dev) /* And send out the RST packet */ - uip_tcpsendcomplete(dev); + tcp_sendcomplete(dev); } /**************************************************************************** - * Name: uip_tcpack + * Name: tcp_ack * * Description: * Send the SYN or SYNACK response. @@ -343,10 +343,10 @@ void uip_tcpreset(FAR struct uip_driver_s *dev) * ****************************************************************************/ -void uip_tcpack(FAR struct uip_driver_s *dev, FAR struct uip_conn *conn, - uint8_t ack) +void tcp_ack(FAR struct uip_driver_s *dev, FAR struct tcp_conn_s *conn, + uint8_t ack) { - struct uip_tcpip_hdr *pbuf = BUF; + struct tcp_iphdr_s *pbuf = BUF; /* Save the ACK bits */ @@ -363,7 +363,7 @@ void uip_tcpack(FAR struct uip_driver_s *dev, FAR struct uip_conn *conn, /* Complete the common portions of the TCP message */ - uip_tcpsendcommon(dev, conn); + tcp_sendcommon(dev, conn); } #endif /* CONFIG_NET && CONFIG_NET_TCP */ diff --git a/net/tcp/tcp_send_buffered.c b/net/tcp/tcp_send_buffered.c index f8fcb571547..1a2e53accaa 100644 --- a/net/tcp/tcp_send_buffered.c +++ b/net/tcp/tcp_send_buffered.c @@ -75,7 +75,7 @@ * Pre-processor Definitions ****************************************************************************/ -#define TCPBUF ((struct uip_tcpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) +#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[UIP_LLH_LEN]) /* Debug */ @@ -96,7 +96,7 @@ ****************************************************************************/ /**************************************************************************** - * Function: send_insert_seqment + * Function: psock_insert_segment * * Description: * Insert a new segment in a write buffer queue, keep the segment queue in @@ -114,8 +114,8 @@ * ****************************************************************************/ -static void send_insert_seqment(FAR struct tcp_wrbuffer_s *wrb, - FAR sq_queue_t *q) +static void psock_insert_segment(FAR struct tcp_wrbuffer_s *wrb, + FAR sq_queue_t *q) { sq_entry_t *entry = (sq_entry_t*)wrb; sq_entry_t *insert = NULL; @@ -145,7 +145,7 @@ static void send_insert_seqment(FAR struct tcp_wrbuffer_s *wrb, } /**************************************************************************** - * Function: lost_connection + * Function: psock_lost_connection * * Description: * The TCP connection has been lost. Free all write buffers. @@ -159,8 +159,8 @@ static void send_insert_seqment(FAR struct tcp_wrbuffer_s *wrb, * ****************************************************************************/ -static inline void lost_connection(FAR struct socket *psock, - FAR struct uip_conn *conn) +static inline void psock_lost_connection(FAR struct socket *psock, + FAR struct tcp_conn_s *conn) { FAR sq_entry_t *entry; FAR sq_entry_t *next; @@ -192,7 +192,7 @@ static inline void lost_connection(FAR struct socket *psock, } /**************************************************************************** - * Function: send_interrupt + * Function: psock_send_interrupt * * Description: * This function is called from the interrupt level to perform the actual @@ -211,10 +211,11 @@ static inline void lost_connection(FAR struct socket *psock, * ****************************************************************************/ -static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, - FAR void *pvpriv, uint16_t flags) +static uint16_t psock_send_interrupt(FAR struct uip_driver_s *dev, + FAR void *pvconn, FAR void *pvpriv, + uint16_t flags) { - FAR struct uip_conn *conn = (FAR struct uip_conn *)pvconn; + FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)pvconn; FAR struct socket *psock = (FAR struct socket *)pvpriv; nllvdbg("flags: %04x\n", flags); @@ -230,7 +231,7 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, FAR sq_entry_t *next; uint32_t ackno; - ackno = uip_tcpgetsequence(TCPBUF->ackno); + ackno = tcp_getsequence(TCPBUF->ackno); nllvdbg("ACK: ackno=%u flags=%04x\n", ackno, flags); /* Look at every write buffer in the unacked_q. The unacked_q @@ -352,7 +353,7 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, /* Free write buffers and terminate polling */ - lost_connection(psock, conn); + psock_lost_connection(psock, conn); return flags; } @@ -498,7 +499,7 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, nllvdbg("REXMIT: Moving wrb=%p nrtx=%u\n", wrb, WRB_NRTX(wrb)); - send_insert_seqment(wrb, &conn->write_q); + psock_insert_segment(wrb, &conn->write_q); } } } @@ -590,7 +591,7 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, * before the packet is sent. */ - uip_tcpsetsequence(conn->sndseq, WRB_SEQNO(wrb) + WRB_SENT(wrb)); + tcp_setsequence(conn->sndseq, WRB_SEQNO(wrb) + WRB_SENT(wrb)); /* Then set-up to send that amount of data with the offset * corresponding to the amount of data already sent. (this @@ -637,7 +638,7 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, * segment is waiting for ACK again */ - send_insert_seqment(wrb, &conn->unacked_q); + psock_insert_segment(wrb, &conn->unacked_q); } /* Only one data can be sent by low level driver at once, @@ -658,10 +659,10 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, ****************************************************************************/ /**************************************************************************** - * Function: tcp_send + * Function: psock_tcp_send * * Description: - * The tcp_send() call may be used only when the TCP socket is in a + * The psock_tcp_send() call may be used only when the TCP socket is in a * connected state (so that the intended recipient is known). * * Parameters: @@ -714,7 +715,8 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, * ****************************************************************************/ -ssize_t tcp_send(FAR struct socket *psock, FAR const void *buf, size_t len) +ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf, + size_t len) { uip_lock_t save; ssize_t result = 0; @@ -735,7 +737,7 @@ ssize_t tcp_send(FAR struct socket *psock, FAR const void *buf, size_t len) /* Dump the incoming buffer */ - BUF_DUMP("tcp_send", buf, len); + BUF_DUMP("psock_tcp_send", buf, len); /* Set the socket state to sending */ @@ -745,13 +747,13 @@ ssize_t tcp_send(FAR struct socket *psock, FAR const void *buf, size_t len) if (len > 0) { - struct uip_conn *conn = (struct uip_conn*)psock->s_conn; + FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)psock->s_conn; /* Allocate resources to receive a callback */ if (!psock->s_sndcb) { - psock->s_sndcb = uip_tcpcallbackalloc(conn); + psock->s_sndcb = tcp_callbackalloc(conn); } /* Test if the callback has been allocated */ @@ -772,7 +774,7 @@ ssize_t tcp_send(FAR struct socket *psock, FAR const void *buf, size_t len) psock->s_sndcb->flags = (UIP_ACKDATA | UIP_REXMIT |UIP_POLL | \ UIP_CLOSE | UIP_ABORT | UIP_TIMEDOUT); psock->s_sndcb->priv = (void*)psock; - psock->s_sndcb->event = send_interrupt; + psock->s_sndcb->event = psock_send_interrupt; /* Allocate an write buffer */ @@ -789,7 +791,7 @@ ssize_t tcp_send(FAR struct socket *psock, FAR const void *buf, size_t len) WRB_DUMP("I/O buffer chain", wrb, WRB_PKTLEN(wrb), 0); - /* send_interrupt() will send data in FIFO order from the + /* psock_send_interrupt() will send data in FIFO order from the * conn->write_q */ diff --git a/net/tcp/tcp_send_unbuffered.c b/net/tcp/tcp_send_unbuffered.c index dc0cd0eb920..c0c9568e8ae 100644 --- a/net/tcp/tcp_send_unbuffered.c +++ b/net/tcp/tcp_send_unbuffered.c @@ -66,7 +66,7 @@ # define CONFIG_NET_TCP_SPLIT_SIZE 40 #endif -#define TCPBUF ((struct uip_tcpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) +#define TCPBUF ((struct tcp_iphdr_s *)&dev->d_buf[UIP_LLH_LEN]) /**************************************************************************** * Private Types @@ -163,7 +163,7 @@ static uint16_t tcpsend_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, FAR void *pvpriv, uint16_t flags) { - FAR struct uip_conn *conn = (FAR struct uip_conn*)pvconn; + FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)pvconn; FAR struct send_s *pstate = (FAR struct send_s *)pvpriv; nllvdbg("flags: %04x acked: %d sent: %d\n", @@ -187,7 +187,7 @@ static uint16_t tcpsend_interrupt(FAR struct uip_driver_s *dev, * is the number of bytes to be acknowledged. */ - pstate->snd_acked = uip_tcpgetsequence(TCPBUF->ackno) - pstate->snd_isn; + pstate->snd_acked = tcp_getsequence(TCPBUF->ackno) - pstate->snd_isn; nllvdbg("ACK: acked=%d sent=%d buflen=%d\n", pstate->snd_acked, pstate->snd_sent, pstate->snd_buflen); @@ -367,7 +367,7 @@ static uint16_t tcpsend_interrupt(FAR struct uip_driver_s *dev, seqno = pstate->snd_sent + pstate->snd_isn; nllvdbg("SEND: sndseq %08x->%08x\n", conn->sndseq, seqno); - uip_tcpsetsequence(conn->sndseq, seqno); + tcp_setsequence(conn->sndseq, seqno); /* Then set-up to send that amount of data. (this won't actually * happen until the polling cycle completes). @@ -542,16 +542,16 @@ ssize_t tcp_send(FAR struct socket *psock, FAR const void *buf, size_t len) if (len > 0) { - struct uip_conn *conn = (struct uip_conn*)psock->s_conn; + FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s *)psock->s_conn; /* Allocate resources to receive a callback */ - state.snd_cb = uip_tcpcallbackalloc(conn); + state.snd_cb = tcp_callbackalloc(conn); if (state.snd_cb) { /* Get the initial sequence number that will be used */ - state.snd_isn = uip_tcpgetsequence(conn->sndseq); + state.snd_isn = tcp_getsequence(conn->sndseq); /* There is no outstanding, unacknowledged data after this * initial sequence number. @@ -584,7 +584,7 @@ ssize_t tcp_send(FAR struct socket *psock, FAR const void *buf, size_t len) /* Make sure that no further interrupts are processed */ - uip_tcpcallbackfree(conn, state.snd_cb); + tcp_callbackfree(conn, state.snd_cb); } } diff --git a/net/tcp/tcp_seqno.c b/net/tcp/tcp_seqno.c index 6e5cb0b5c8a..c844cd903e2 100644 --- a/net/tcp/tcp_seqno.c +++ b/net/tcp/tcp_seqno.c @@ -77,7 +77,7 @@ static uint32_t g_tcpsequence; ****************************************************************************/ /**************************************************************************** - * Name: uip_tcpsetsequence + * Name: tcp_setsequence * * Description: * Set the TCP/IP sequence number @@ -87,7 +87,7 @@ static uint32_t g_tcpsequence; * ****************************************************************************/ -void uip_tcpsetsequence(FAR uint8_t *seqno, uint32_t value) +void tcp_setsequence(FAR uint8_t *seqno, uint32_t value) { /* Copy the sequence number in network (big-endian) order */ @@ -98,7 +98,7 @@ void uip_tcpsetsequence(FAR uint8_t *seqno, uint32_t value) } /**************************************************************************** - * Name: uip_tcpgetsequence + * Name: tcp_getsequence * * Description: * Get the TCP/IP sequence number @@ -108,7 +108,7 @@ void uip_tcpsetsequence(FAR uint8_t *seqno, uint32_t value) * ****************************************************************************/ -uint32_t uip_tcpgetsequence(FAR uint8_t *seqno) +uint32_t tcp_getsequence(FAR uint8_t *seqno) { uint32_t value; @@ -122,7 +122,7 @@ uint32_t uip_tcpgetsequence(FAR uint8_t *seqno) } /**************************************************************************** - * Name: uip_tcpaddsequence + * Name: tcp_addsequence * * Description: * Add the length to get the next TCP sequence number. @@ -132,13 +132,13 @@ uint32_t uip_tcpgetsequence(FAR uint8_t *seqno) * ****************************************************************************/ -uint32_t uip_tcpaddsequence(FAR uint8_t *seqno, uint16_t len) +uint32_t tcp_addsequence(FAR uint8_t *seqno, uint16_t len) { - return uip_tcpgetsequence(seqno) + (uint32_t)len; + return tcp_getsequence(seqno) + (uint32_t)len; } /**************************************************************************** - * Name: uip_tcpinitsequence + * Name: tcp_initsequence * * Description: * Set the (initial) the TCP/IP sequence number when a TCP connection is @@ -149,13 +149,13 @@ uint32_t uip_tcpaddsequence(FAR uint8_t *seqno, uint16_t len) * ****************************************************************************/ -void uip_tcpinitsequence(FAR uint8_t *seqno) +void tcp_initsequence(FAR uint8_t *seqno) { - uip_tcpsetsequence(seqno, g_tcpsequence); + tcp_setsequence(seqno, g_tcpsequence); } /**************************************************************************** - * Name: uip_tcpnextsequence + * Name: tcp_nextsequence * * Description: * Increment the TCP/IP sequence number @@ -165,7 +165,7 @@ void uip_tcpinitsequence(FAR uint8_t *seqno) * ****************************************************************************/ -void uip_tcpnextsequence(void) +void tcp_nextsequence(void) { g_tcpsequence++; } diff --git a/net/tcp/tcp_timer.c b/net/tcp/tcp_timer.c index 08614ed734b..78b7a29a6c4 100644 --- a/net/tcp/tcp_timer.c +++ b/net/tcp/tcp_timer.c @@ -53,6 +53,7 @@ #include #include "uip/uip.h" +#include "tcp/tcp.h" /**************************************************************************** * Pre-processor Definitions @@ -75,7 +76,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: uip_tcptimer + * Name: tcp_timer * * Description: * Handle a TCP timer expiration for the provided TCP connection @@ -93,8 +94,8 @@ * ****************************************************************************/ -void uip_tcptimer(FAR struct uip_driver_s *dev, FAR struct uip_conn *conn, - int hsec) +void tcp_timer(FAR struct uip_driver_s *dev, FAR struct tcp_conn_s *conn, + int hsec) { uint8_t result; @@ -103,7 +104,7 @@ void uip_tcptimer(FAR struct uip_driver_s *dev, FAR struct uip_conn *conn, /* Increase the TCP sequence number */ - uip_tcpnextsequence(); + tcp_nextsequence(); /* Reset the length variables. */ @@ -128,7 +129,7 @@ void uip_tcptimer(FAR struct uip_driver_s *dev, FAR struct uip_conn *conn, /* Notify upper layers about the timeout */ - result = uip_tcpcallback(dev, conn, UIP_TIMEDOUT); + result = tcp_callback(dev, conn, UIP_TIMEDOUT); nllvdbg("TCP state: UIP_CLOSED\n"); } @@ -172,16 +173,16 @@ void uip_tcptimer(FAR struct uip_driver_s *dev, FAR struct uip_conn *conn, conn->tcpstateflags = UIP_CLOSED; nllvdbg("TCP state: UIP_CLOSED\n"); - /* We call uip_tcpcallback() with UIP_TIMEDOUT to + /* We call tcp_callback() with UIP_TIMEDOUT to * inform the application that the connection has * timed out. */ - result = uip_tcpcallback(dev, conn, UIP_TIMEDOUT); + result = tcp_callback(dev, conn, UIP_TIMEDOUT); /* We also send a reset packet to the remote host. */ - uip_tcpsend(dev, conn, TCP_RST | TCP_ACK, UIP_IPTCPH_LEN); + tcp_send(dev, conn, TCP_RST | TCP_ACK, UIP_IPTCPH_LEN); goto done; } @@ -208,13 +209,13 @@ void uip_tcptimer(FAR struct uip_driver_s *dev, FAR struct uip_conn *conn, * SYNACK. */ - uip_tcpack(dev, conn, TCP_ACK | TCP_SYN); + tcp_ack(dev, conn, TCP_ACK | TCP_SYN); goto done; case UIP_SYN_SENT: /* In the SYN_SENT state, we retransmit out SYN. */ - uip_tcpack(dev, conn, TCP_SYN); + tcp_ack(dev, conn, TCP_SYN); goto done; case UIP_ESTABLISHED: @@ -223,8 +224,8 @@ void uip_tcptimer(FAR struct uip_driver_s *dev, FAR struct uip_conn *conn, * the code for sending out the packet. */ - result = uip_tcpcallback(dev, conn, UIP_REXMIT); - uip_tcprexmit(dev, conn, result); + result = tcp_callback(dev, conn, UIP_REXMIT); + tcp_rexmit(dev, conn, result); goto done; case UIP_FIN_WAIT_1: @@ -232,7 +233,7 @@ void uip_tcptimer(FAR struct uip_driver_s *dev, FAR struct uip_conn *conn, case UIP_LAST_ACK: /* In all these states we should retransmit a FINACK. */ - uip_tcpsend(dev, conn, TCP_FIN | TCP_ACK, UIP_IPTCPH_LEN); + tcp_send(dev, conn, TCP_FIN | TCP_ACK, UIP_IPTCPH_LEN); goto done; } } @@ -246,8 +247,8 @@ void uip_tcptimer(FAR struct uip_driver_s *dev, FAR struct uip_conn *conn, * application for new data. */ - result = uip_tcpcallback(dev, conn, UIP_POLL); - uip_tcpappsend(dev, conn, result); + result = tcp_callback(dev, conn, UIP_POLL); + tcp_appsend(dev, conn, result); goto done; } } diff --git a/net/tcp/tcp_wrbuffer.c b/net/tcp/tcp_wrbuffer.c index df73fb0499f..902b3bfb772 100644 --- a/net/tcp/tcp_wrbuffer.c +++ b/net/tcp/tcp_wrbuffer.c @@ -54,9 +54,10 @@ #include #include +#include +#include + #include "tcp/tcp.h" -#include "nuttx/net/iob.h" -#include "nuttx/net/tcp.h" /**************************************************************************** * Private Types diff --git a/net/udp/udp.h b/net/udp/udp.h new file mode 100644 index 00000000000..fe8b0d02662 --- /dev/null +++ b/net/udp/udp.h @@ -0,0 +1,79 @@ +/**************************************************************************** + * net/udp/udp.h + * + * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __NET_UDP_UDP_H +#define __NET_UDP_UDP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#ifdef CONFIG_NET_UDP + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +# define EXTERN extern "C" +extern "C" +{ +#else +# define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* CONFIG_NET_UDP */ +#endif /* __NET_UDP_UDP_H */ diff --git a/net/uip/uip.h b/net/uip/uip.h index 06c4b58eaae..413a8b75247 100644 --- a/net/uip/uip.h +++ b/net/uip/uip.h @@ -125,66 +125,6 @@ void uip_pktpoll(struct uip_driver_s *dev, struct uip_pkt_conn *conn); #endif /* CONFIG_NET_PKT */ -#ifdef CONFIG_NET_TCP -/* Defined in tcp_conn.c ****************************************************/ - -void uip_tcpinit(void); -struct uip_conn *uip_tcpactive(struct uip_tcpip_hdr *buf); -struct uip_conn *uip_nexttcpconn(struct uip_conn *conn); -struct uip_conn *uip_tcplistener(uint16_t portno); -struct uip_conn *uip_tcpaccept(struct uip_tcpip_hdr *buf); - -/* Defined in tcp_seqno.c ***************************************************/ - -void uip_tcpsetsequence(FAR uint8_t *seqno, uint32_t value); -uint32_t uip_tcpgetsequence(FAR uint8_t *seqno); -uint32_t uip_tcpaddsequence(FAR uint8_t *seqno, uint16_t len); -void uip_tcpinitsequence(FAR uint8_t *seqno); -void uip_tcpnextsequence(void); - -/* Defined in tcp_poll.c ****************************************************/ - -void uip_tcppoll(struct uip_driver_s *dev, struct uip_conn *conn); - -/* Defined in tcp_timer.c ***************************************************/ - -void uip_tcptimer(struct uip_driver_s *dev, struct uip_conn *conn, int hsec); - -/* Defined in tcp_listen.c **************************************************/ - -void uip_listeninit(void); -bool uip_islistener(uint16_t port); -int uip_accept(struct uip_driver_s *dev, struct uip_conn *conn, uint16_t portno); - -/* Defined in tcp_send.c ****************************************************/ - -void uip_tcpsend(struct uip_driver_s *dev, struct uip_conn *conn, - uint16_t flags, uint16_t len); -void uip_tcpreset(struct uip_driver_s *dev); -void uip_tcpack(struct uip_driver_s *dev, struct uip_conn *conn, - uint8_t ack); - -/* Defined in tcp_appsend.c *************************************************/ - -void uip_tcpappsend(struct uip_driver_s *dev, struct uip_conn *conn, - uint16_t result); -void uip_tcprexmit(struct uip_driver_s *dev, struct uip_conn *conn, - uint16_t result); - -/* Defined in tcp_input.c ***************************************************/ - -void uip_tcpinput(struct uip_driver_s *dev); - -/* Defined in tcp_callback.c ************************************************/ - -uint16_t uip_tcpcallback(FAR struct uip_driver_s *dev, - FAR struct uip_conn *conn, uint16_t flags); -#ifdef CONFIG_NET_TCP_READAHEAD -uint16_t uip_datahandler(FAR struct uip_conn *conn, - FAR uint8_t *buffer, uint16_t nbytes); -#endif -#endif /* CONFIG_NET_TCP */ - #ifdef CONFIG_NET_UDP /* Defined in udp_conn.c ****************************************************/ diff --git a/net/uip/uip_chksum.c b/net/uip/uip_chksum.c index f8ad769a8d3..db6eb36d0a0 100644 --- a/net/uip/uip_chksum.c +++ b/net/uip/uip_chksum.c @@ -202,7 +202,7 @@ uint16_t uip_ipchksum(struct uip_driver_s *dev) /* Calculate the TCP checksum of the packet in d_buf and d_appdata. */ -uint16_t uip_tcpchksum(struct uip_driver_s *dev) +uint16_t tcp_chksum(struct uip_driver_s *dev) { return upper_layer_chksum(dev, UIP_PROTO_TCP); } diff --git a/net/uip/uip_initialize.c b/net/uip/uip_initialize.c index 8b88d5cf85d..3504b8fa379 100644 --- a/net/uip/uip_initialize.c +++ b/net/uip/uip_initialize.c @@ -133,11 +133,11 @@ void uip_initialize(void) /* Initialize the listening port structures */ #ifdef CONFIG_NET_TCP - uip_listeninit(); + tcp_listeninit(); /* Initialize the TCP/IP connection structures */ - uip_tcpinit(); + tcp_initialize(); /* Initialize the TCP/IP write buffering */ diff --git a/net/uip/uip_input.c b/net/uip/uip_input.c index f5ee06b53a5..9fa25d4e2ab 100644 --- a/net/uip/uip_input.c +++ b/net/uip/uip_input.c @@ -54,7 +54,7 @@ * statement. While it would be possible to break the uip_input() * function into many smaller functions, this would increase the code * size because of the overhead of parameter passing and the fact that - * the optimier would not be as efficient. + * the optimizer would not be as efficient. * * The principle is that we have a small buffer, called the d_buf, * in which the device driver puts an incoming packet. The TCP/IP @@ -93,6 +93,8 @@ # include "uip_neighbor.h" #endif /* CONFIG_NET_IPv6 */ +#include "tcp/tcp.h" +#include "udp/udp.h" #include "uip.h" /**************************************************************************** @@ -506,7 +508,7 @@ int uip_input(struct uip_driver_s *dev) { #ifdef CONFIG_NET_TCP case UIP_PROTO_TCP: /* TCP input */ - uip_tcpinput(dev); + tcp_input(dev); break; #endif diff --git a/net/uip/uip_poll.c b/net/uip/uip_poll.c index a4100e57698..fad9d44f9b4 100644 --- a/net/uip/uip_poll.c +++ b/net/uip/uip_poll.c @@ -46,6 +46,7 @@ #include #include +#include "tcp/tcp.h" #include "uip.h" /**************************************************************************** @@ -196,7 +197,7 @@ static int uip_polludpconnections(FAR struct uip_driver_s *dev, static inline int uip_polltcpconnections(FAR struct uip_driver_s *dev, uip_poll_callback_t callback) { - FAR struct uip_conn *conn = NULL; + FAR struct tcp_conn_s *conn = NULL; int bstop = 0; /* Traverse all of the active TCP connections and perform the poll action */ @@ -205,7 +206,7 @@ static inline int uip_polltcpconnections(FAR struct uip_driver_s *dev, { /* Perform the TCP TX poll */ - uip_tcppoll(dev, conn); + tcp_poll(dev, conn); /* Call back into the driver */ @@ -235,7 +236,7 @@ static inline int uip_polltcpconnections(FAR struct uip_driver_s *dev, static inline int uip_polltcptimer(FAR struct uip_driver_s *dev, uip_poll_callback_t callback, int hsec) { - FAR struct uip_conn *conn = NULL; + FAR struct tcp_conn_s *conn = NULL; int bstop = 0; /* Traverse all of the active TCP connections and perform the poll action */ @@ -244,7 +245,7 @@ static inline int uip_polltcptimer(FAR struct uip_driver_s *dev, { /* Perform the TCP timer poll */ - uip_tcptimer(dev, conn, hsec); + tcp_timer(dev, conn, hsec); /* Call back into the driver */