RIOT's TCP implementation for the GNRC network stack. More...

Detailed Description

RIOT's TCP implementation for the GNRC network stack.

Files

file  config.h
 GNRC TCP configuration.
 
file  tcb.h
 GNRC TCP transmission control block (TCB)
 
file  tcp.h
 GNRC TCP API.
 
file  common.h
 Internally used defines, macros and variable declarations.
 
file  eventloop.h
 TCP event loop delarations.
 
file  fsm.h
 TCP finite state maschine declarations.
 
file  option.h
 TCP option handling declarations.
 
file  pkt.h
 TCP paket handling declarations.
 
file  rcvbuf.h
 Functions for allocating and freeing the receive buffer.
 

Functions

int gnrc_tcp_init (void)
 Initialize TCP. More...
 
void gnrc_tcp_tcb_init (gnrc_tcp_tcb_t *tcb)
 Initialize Transmission Control Block (TCB) More...
 
int gnrc_tcp_open_active (gnrc_tcp_tcb_t *tcb, uint8_t address_family, char *target_addr, uint16_t target_port, uint16_t local_port)
 Opens a connection actively. More...
 
int gnrc_tcp_open_passive (gnrc_tcp_tcb_t *tcb, uint8_t address_family, const char *local_addr, uint16_t local_port)
 Opens a connection passively, by waiting for an incomming request. More...
 
ssize_t gnrc_tcp_send (gnrc_tcp_tcb_t *tcb, const void *data, const size_t len, const uint32_t user_timeout_duration_us)
 Transmit data to connected peer. More...
 
ssize_t gnrc_tcp_recv (gnrc_tcp_tcb_t *tcb, void *data, const size_t max_len, const uint32_t user_timeout_duration_us)
 Receive Data from the peer. More...
 
void gnrc_tcp_close (gnrc_tcp_tcb_t *tcb)
 Close a TCP connection. More...
 
void gnrc_tcp_abort (gnrc_tcp_tcb_t *tcb)
 Abort a TCP connection. More...
 
int gnrc_tcp_calc_csum (const gnrc_pktsnip_t *hdr, const gnrc_pktsnip_t *pseudo_hdr)
 Calculate and set checksum in TCP header. More...
 
gnrc_pktsnip_tgnrc_tcp_hdr_build (gnrc_pktsnip_t *payload, uint16_t src, uint16_t dst)
 Adds a TCP header to a given payload. More...
 

Function Documentation

◆ gnrc_tcp_abort()

void gnrc_tcp_abort ( gnrc_tcp_tcb_t tcb)

Abort a TCP connection.

Precondition
gnrc_tcp_tcb_init() must have been successfully called.
tcb must not be NULL.
Parameters
[in,out]tcbTCB holding the connection information.

◆ gnrc_tcp_calc_csum()

int gnrc_tcp_calc_csum ( const gnrc_pktsnip_t hdr,
const gnrc_pktsnip_t pseudo_hdr 
)

Calculate and set checksum in TCP header.

Parameters
[in]hdrGnrc_pktsnip that contains TCP header.
[in]pseudo_hdrGnrc_pktsnip that contains network layer header.
Returns
0 on succees. -EFAULT if hdr or pseudo_hdr were NULL -EBADMSG if hdr is not of type GNRC_NETTYPE_TCP -ENOENT if pseudo_hdr protocol is unsupported.

◆ gnrc_tcp_close()

void gnrc_tcp_close ( gnrc_tcp_tcb_t tcb)

Close a TCP connection.

Precondition
gnrc_tcp_tcb_init() must have been successfully called.
tcb must not be NULL.
Parameters
[in,out]tcbTCB holding the connection information.

◆ gnrc_tcp_hdr_build()

gnrc_pktsnip_t* gnrc_tcp_hdr_build ( gnrc_pktsnip_t payload,
uint16_t  src,
uint16_t  dst 
)

Adds a TCP header to a given payload.

Parameters
[in]payloadPayload that follows the TCP header.
[in]srcSource port number.
[in]dstDestination port number.
Returns
Not NULL on success. NULL if TCP header was not allocated.

◆ gnrc_tcp_init()

int gnrc_tcp_init ( void  )

Initialize TCP.

Returns
PID of TCP thread on success -1 if TCB is already running. -EINVAL, if priority is greater than or equal SCHED_PRIO_LEVELS -EOVERFLOW, if there are too many threads running.

◆ gnrc_tcp_open_active()

int gnrc_tcp_open_active ( gnrc_tcp_tcb_t tcb,
uint8_t  address_family,
char *  target_addr,
uint16_t  target_port,
uint16_t  local_port 
)

Opens a connection actively.

Precondition
gnrc_tcp_tcb_init() must have been successfully called.
tcb must not be NULL
target_addr must not be NULL.
target_port must not be 0.
Note
Blocks until a connection has been established or an error occured.
Parameters
[in,out]tcbTCB holding the connection information.
[in]address_familyAddress family of target_addr.
[in]target_addrPointer to target address.
[in]target_portTarget port number.
[in]local_portIf zero or PORT_UNSPEC, the connections source port is randomly chosen. If local_port is non-zero the local_port is used as source port.
Returns
0 on success. -EAFNOSUPPORT if address_family is not supported. -EINVAL if address_family is not the same the address_family use by the TCB. or target_addr is invalid. -EISCONN if TCB is already in use. -ENOMEM if the receive buffer for the TCB could not be allocated. -EADDRINUSE if local_port is already used by another connection. -ETIMEDOUT if the connection could not be opened. -ECONNREFUSED if the connection was resetted by the peer.

◆ gnrc_tcp_open_passive()

int gnrc_tcp_open_passive ( gnrc_tcp_tcb_t tcb,
uint8_t  address_family,
const char *  local_addr,
uint16_t  local_port 
)

Opens a connection passively, by waiting for an incomming request.

Precondition
gnrc_tcp_tcb_init() must have been successfully called.
tcb must not be NULL.
if local_addr is not NULL, local_addr must be assigned to a network interface.
if local_port is not zero.
Note
Blocks until a connection has been established (incomming connection request to local_port) or an error occured.
Parameters
[in,out]tcbTCB holding the connection information.
[in]address_familyAddress family of local_addr. If local_addr == NULL, address_family is ignored.
[in]local_addrIf not NULL the connection is bound to local_addr. If NULL a connection request to all local ip addresses is valied.
[in]local_portPort number to listen on.
Returns
0 on success. -EAFNOSUPPORT if local_addr != NULL and address_family is not supported. -EINVAL if address_family is not the same the address_family used in TCB. or target_addr is invalid. -EISCONN if TCB is already in use. -ENOMEM if the receive buffer for the TCB could not be allocated. Hint: Increase "GNRC_TCP_RCV_BUFFERS".

◆ gnrc_tcp_recv()

ssize_t gnrc_tcp_recv ( gnrc_tcp_tcb_t tcb,
void *  data,
const size_t  max_len,
const uint32_t  user_timeout_duration_us 
)

Receive Data from the peer.

Precondition
gnrc_tcp_tcb_init() must have been successfully called.
tcb must not be NULL.
data must not be NULL.
Note
Function blocks if user_timeout_duration_us is not zero.
Parameters
[in,out]tcbTCB holding the connection information.
[out]dataPointer to the buffer where the received data should be copied into.
[in]max_lenMaximum amount to bytes that should be read into data.
[in]user_timeout_duration_usTimeout for receive in microseconds. If zero and no data is available, the function returns immediately. If not zero the function blocks until data is available or user_timeout_duration_us microseconds passed.
Returns
The number of bytes read into data. -ENOTCONN if connection is not established. -EAGAIN if user_timeout_duration_us is zero and no data is available. -ECONNRESET if connection was resetted by the peer. -ECONNABORTED if the connection was aborted. -ETIMEDOUT if user_timeout_duration_us expired.

◆ gnrc_tcp_send()

ssize_t gnrc_tcp_send ( gnrc_tcp_tcb_t tcb,
const void *  data,
const size_t  len,
const uint32_t  user_timeout_duration_us 
)

Transmit data to connected peer.

Precondition
gnrc_tcp_tcb_init() must have been successfully called.
tcb must not be NULL.
data must not be NULL.
Note
Blocks until up to len bytes were transmitted or an error occured.
Parameters
[in,out]tcbTCB holding the connection information.
[in]dataPointer to the data that should be transmitted.
[in]lenNumber of bytes that should be transmitted.
[in]user_timeout_duration_usIf not zero and there was not data transmitted the function returns after user_timeout_duration_us. If zero, no timeout will be triggered.
Returns
The number of successfully transmitted bytes. -ENOTCONN if connection is not established. -ECONNRESET if connection was resetted by the peer. -ECONNABORTED if the connection was aborted. -ETIMEDOUT if user_timeout_duration_us expired.

◆ gnrc_tcp_tcb_init()

void gnrc_tcp_tcb_init ( gnrc_tcp_tcb_t tcb)

Initialize Transmission Control Block (TCB)

Precondition
tcb must not be NULL.
Parameters
[in,out]tcbTCB that should be initialized.