Find out what we can send and send it
Aborts the connection by sending a RST (reset) segment to the remote host. The pcb is deallocated. This function never fails. ATTENTION: When calling this from one of the TCP callbacks, make sure you always return ERR_ABRT (and never return ERR_ABRT otherwise or you will risk accessing deallocated memory or memory leaks!
Purges a TCP PCB. Removes any buffered data and frees the buffer memory (pcb->ooseq, pcb->unsent and pcb->unacked are freed).
Send an ACK without data.
Purges the PCB and removes it from a PCB list. Any delayed ACKs are sent first.
Send a TCP RESET packet (empty segment with RST flag set) to abort a connection. Called by tcp_abort() (to abort a local connection), tcp_closen() (if not all data has been received by the application), tcp_timewait_input() (if a SYN is received) and tcp_process() (received segment in the wrong state). Since a RST segment is in most cases not sent for an active connection, tcp_rst() has a number of arguments that are taken from a tcp_pcb for most other segment output functions.
Called by tcp_process. Checks if the given segment is an ACK for outstanding data, and if so frees the memory of the buffered data. Next, it places the segment on any of the receive queues (pcb->recved or pcb->ooseq). If the segment is buffered, the pbuf is referenced by pbuf_ref so that it will not be freed until it has been removed from the buffer. If the incoming segment constitutes an ACK for a segment that was used for RTT estimation, the RTT is estimated here as well. Called from tcp_process().
Specifies the program specific state that should be passed to all other callback functions. The "pcb" argument is the current TCP connection control block, and the "arg" argument is the argument that will be passed to the callbacks.
A delayed-accept a connection is accepted (or closed/aborted): decreases the number of outstanding connections after calling tcp_backlog_delayed(). ATTENTION: the caller is responsible for calling tcp_backlog_accepted() or else the backlog feature will get out of sync!
Specifies the callback function that should be called when data has successfully been received (i.e., acknowledged) by the remote host. The len argument passed to the callback function gives the amount bytes that was acknowledged by the last acknowledgment.
Used to specify the function that should be called when a fatal error has occurred on the connection. If a connection is aborted because of an error, the application is alerted of this event by the err callback. Errors that might abort a connection are when there is a shortage of memory. The callback function to be called is set using the tcp_err() function.
Specifies the polling interval and the callback function that should be called to poll the application. The interval is specified in number of TCP coarse grained timer shots, which typically occurs twice a second. An interval of 10 means that the application would be polled every 5 seconds. When a connection is idle (i.e., no data is either transmitted or received), lwIP will repeatedly poll the application by calling a specified callback function. This can be used either as a watchdog timer for killing connections that have stayed idle for too long, or as a method of waiting for memory to become available. For instance, if a call to tcp_write() has failed because memory wasn't available, the application may use the polling functionality to call tcp_write() again when the connection has been idle for a while.
Sets the callback function that will be called when new data arrives. The callback function will be passed a NULL pbuf to indicate that the remote host has closed the connection. If the callback function returns ERR_OK or ERR_ABRT it must have freed the pbuf, otherwise it must not have freed it.
Used for specifying the function that should be called when a LISTENing connection has been connected to another host. @see MEMP_NUM_TCP_PCB_LISTEN and MEMP_NUM_TCP_PCB
This function should be called by the application when it has processed the data. The purpose is to advertise a larger window when the data has been processed.
Abandons a connection and optionally sends a RST to the remote host. Deletes the local protocol control block. This is done when a connection is killed because of shortage of memory.
Update the state that tracks the available window space to advertise. Returns how much extra window would be advertised if we sent an update now.
Called by tcp_close() to send a segment including FIN flag but not data. This FIN may be added to an existing segment or a new, otherwise empty segment is enqueued.
Enqueue SYN or FIN for transmission. Called by tcp_connect, tcp_listen_input, and tcp_close (via tcp_send_fin)
Default receive callback that is called if the user didn't register a recv callback for the pcb.
Output a control segment pbuf to IP. Called from tcp_rst, tcp_send_empty_ack, tcp_keepalive and tcp_zero_window_probe, this function combines selecting a netif for transmission, generating the tcp header checksum and calling ip_output_if while handling netif hints and stats.
Binds the connection to a netif and IP address. After calling this function, all packets received via this PCB are guaranteed to have come in via the specified netif, and all outgoing packets will go out via the specified netif.
Set the state of the connection to be LISTEN, which means that it is able to accept incoming connections. The protocol control block is reallocated in order to consume less memory. Setting the connection to LISTEN is an irreversible process.
Closes the connection held by the PCB. Listening pcbs are freed and may not be referenced any more. Connection pcbs are freed if not yet connected and may not be referenced any more. If a connection is established (at least SYN received or in a closing state), the connection is closed, and put in a closing state. The pcb is then automatically freed in tcp_slowtmr(). It is therefore unsafe to reference it (unless an error is returned). The function may return ERR_MEM if no memory was available for closing the connection. If so, the application should wait and try again either by using the acknowledgment callback or the polling functionality. If the close succeeds, the function returns ERR_OK.
Causes all or part of a full-duplex connection of this PCB to be shut down. This doesn't deallocate the PCB unless shutting down both sides! Shutting down both sides is the same as calling tcp_close, so if it succeeds (i.e. returns ER_OK), the PCB must not be referenced any more!
Requeue the first unacked segment for retransmission Called by tcp_receive() for fast retransmit.
Requeue all unacked segments for retransmission Called by tcp_slowtmr() for slow retransmission.
Requeue all unacked segments for retransmission Called by tcp_slowtmr() for slow retransmission.
Pass pcb->refused_data to the recv callback
Calculates a new initial sequence number for new connections.
Parses the options contained in the incoming segment. Called from tcp_listen_input() and tcp_process(). Currently, only the MSS option is supported!
Called from tcp_input to check for TF_CLOSED flag. This results in closing and deallocating a pcb at the correct place to ensure no one references it any more.
Create a TCP segment with prefilled header. Called by tcp_write, tcp_enqueue_flags and tcp_split_unsent_seg
Allocate a pbuf and create a tcphdr at p->payload, used for output functions other than the default tcp_output -> tcp_output_segment (e.g. tcp_send_empty_ack, etc.)
Output a control segment pbuf to IP. Called instead of tcp_output_control_segment when we don't have a pcb but we do know the interface to send to.
Closes the TX side of a connection held by the PCB. For tcp_close(), a RST is sent if the application didn't receive all data (tcp_recved() not called for all data passed to recv callback). Listening pcbs are freed and may not be referenced any more. Connection pcbs are freed if not yet connected and may not be referenced any more. If a connection is established (at least SYN received or in a closing state), the connection is closed, and put in a closing state. The pcb is then automatically freed in tcp_slowtmr(). It is therefore unsafe to reference it.
Delay accepting a connection in respect to the listen backlog: the number of outstanding connections is increased until tcp_backlog_accepted() is called. ATTENTION: the caller is responsible for calling tcp_backlog_accepted() or else the backlog feature will get out of sync!
Binds the connection to a local port number and IP address. If the IP address is not given (i.e., ipaddr == IP_ANY_TYPE), the connection is bound to all local IP addresses. If another connection is bound to the same port, the function will return ERR_USE, otherwise ERR_OK is returned. @see MEMP_NUM_TCP_PCB_LISTEN and MEMP_NUM_TCP_PCB
Write data for sending (but does not send it immediately). It waits in the expectation of more data being sent soon (as it can send them more efficiently by combining them together). To prompt the system to send data now, call tcp_output() after calling tcp_write(). This function enqueues the data pointed to by the argument dataptr. The length of the data is passed as the len parameter. The apiflags can be one or more of: - TCP_WRITE_FLAG_COPY: indicates whether the new memory should be allocated for the data to be copied into. If this flag is not given, no new memory should be allocated and the data should only be referenced by pointer. This also means that the memory behind dataptr must not change until the data is ACKed by the remote host - TCP_WRITE_FLAG_MORE: indicates that more data follows. If this is omitted, the PSH flag is set in the last segment created by this call to tcp_write. If this flag is given, the PSH flag is not set. The tcp_write() function will fail and return ERR_MEM if the length of the data exceeds the current send buffer size or if the length of the queue of outgoing segment is larger than the upper limit defined in lwipopts.h. The number of bytes available in the output queue can be retrieved with the tcp_sndbuf() function. The proper way to use this function is to call the function with at most tcp_sndbuf() bytes of data. If the function returns ERR_MEM, the application should wait until some of the currently enqueued data has been successfully received by the other host and try again.
Requeue all unacked segments for retransmission Called by tcp_process() only, tcp_slowtmr() needs to do some things between "prepare" and "commit".
Handle retransmission after three dupacks received
Send keepalive packets to keep a connection active although no data is sent over it. Called by tcp_slowtmr()
Split segment on the head of the unsent queue. If return is not ERR_OK, existing head remains intact The split is accomplished by creating a new TCP segment and pbuf which holds the remainder payload after the split. The original pbuf is trimmed to new length. This allows splitting of read-only pbufs
Send persist timer zero-window probes to keep a connection active when a window update is lost. Called by tcp_slowtmr()
Poll callback function for TCP netconns. Wakes up an application thread that waits for a connection to close or data to be sent. The application thread then takes the appropriate action to go on. Signals the conn->sem. netconn_close waits for conn->sem if closing failed. @see tcp.h (struct tcp_pcb.poll) for parameters and return value
Sent callback function for TCP netconns. Signals the conn->sem and calls API_EVENT. netconn_write waits for conn->sem if send buffer is low. @see tcp.h (struct tcp_pcb.sent) for parameters and return value
Called by tcp_input() when a segment arrives for a connection in TIME_WAIT.
Implements the TCP state machine. Called by tcp_input. In some states tcp_receive() is called to receive data. The tcp_seg argument will be freed by the caller (tcp_input()) unless the recv_data pointer in the pcb is set.
Remove segments from a list if the incoming ACK acknowledges them
Called by tcp_output() to actually send a TCP segment over IP.
Helper function for tcp_netif_ip_addr_changed() that iterates a pcb list
Set the state of the connection to be LISTEN, which means that it is able to accept incoming connections. The protocol control block is reallocated in order to consume less memory. Setting the connection to LISTEN is an irreversible process. When an incoming connection is accepted, the function specified with the tcp_accept() function will be called. The pcb has to be bound to a local port with the tcp_bind() function. The tcp_listen() function returns a new connection identifier, and the one passed as an argument to the function will be deallocated. The reason for this behavior is that less memory is needed for a connection that is listening, so tcp_listen() will reclaim the memory needed for the original connection and allocate a new smaller memory block for the listening connection. tcp_listen() may return NULL if no memory was available for the listening connection. If so, the memory associated with the pcb passed as an argument to tcp_listen() will not be deallocated. The backlog limits the number of outstanding connections in the listen queue to the value specified by the backlog argument. To use it, your need to set TCP_LISTEN_BACKLOG=1 in your lwipopts.h.
Sets the priority of a connection.
Accept callback function for TCP netconns. Allocates a new netconn and posts that to conn->acceptmbox. @see tcp.h (struct tcp_pcb_listen.accept) for parameters and return value
TCP callback function if a connection (opened by tcp_connect/lwip_netconn_do_connect) has been established (or reset by the remote host). @see tcp.h (struct tcp_pcb.connected) for parameters and return values
Receive callback function for TCP netconns. Posts the packet to conn->recvmbox, but doesn't delete it on errors. @see tcp.h (struct tcp_pcb.recv) for parameters and return value
Allocate a PBUF_RAM pbuf, perhaps with extra space at the end. This function is like pbuf_alloc(layer, length, PBUF_RAM) except there may be extra bytes available at the end. Called by tcp_write
Checks if tcp_write is allowed or not (checks state, snd_buf and snd_queuelen).
Called when a listen pcb is closed. Iterates one pcb list and removes the closed listener pcb from pcb->listener if matching.
Called when a listen pcb is closed. Iterates all pcb lists and removes the closed listener pcb from pcb->listener if matching.
Default accept callback if no accept callback is specified by the user.