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

Detailed Description

RIOT's TCP implementation for the GNRC network stack.

Modules

 GNRC TCP compile configurations
 

Files

file  config.h
 GNRC TCP configuration.
 
file  tcb.h
 GNRC TCP transmission control block (TCB)
 
file  tcp.h
 GNRC TCP API.
 
file  gnrc_tcp_common.h
 Internally used defines, macros and variable declarations.
 
file  gnrc_tcp_eventloop.h
 TCP event loop declarations.
 
file  gnrc_tcp_fsm.h
 TCP finite state maschine declarations.
 
file  gnrc_tcp_option.h
 TCP option handling declarations.
 
file  gnrc_tcp_pkt.h
 TCP packet handling declarations.
 
file  gnrc_tcp_rcvbuf.h
 Functions for allocating and freeing the receive buffer.
 

Data Structures

struct  gnrc_tcp_ep_t
 Address information for a single TCP connection endpoint. More...
 

Functions

int gnrc_tcp_ep_init (gnrc_tcp_ep_t *ep, int family, const uint8_t *addr, size_t addr_size, uint16_t port, uint16_t netif)
 Initialize TCP connection endpoint. More...
 
int gnrc_tcp_ep_from_str (gnrc_tcp_ep_t *ep, const char *str)
 Construct TCP connection endpoint from string. More...
 
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, const gnrc_tcp_ep_t *remote, uint16_t local_port)
 Opens a connection actively. More...
 
int gnrc_tcp_open_passive (gnrc_tcp_tcb_t *tcb, const gnrc_tcp_ep_t *local)
 Opens a connection passively, by waiting for an incoming 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_ms)
 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_ms)
 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 success.
-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_ep_from_str()

int gnrc_tcp_ep_from_str ( gnrc_tcp_ep_t ep,
const char *  str 
)

Construct TCP connection endpoint from string.

Note
This function expects str in the IPv6 "URL" notation. The following strings specify a valid endpoint:
  • [fe80::0a00:27ff:fe9f:7a5b%5]:8080 (with Port and Interface)
  • [2001::0200:f8ff:fe21:67cf]:8080 (with Port)
  • [2001::0200:f8ff:fe21:67cf] (addr only)
Parameters
[in,out]epEndpoint to initialize.
[in]strString containing IPv6-Address to parse.
Returns
0 on success.
-EINVAL if parsing of str failed.

◆ gnrc_tcp_ep_init()

int gnrc_tcp_ep_init ( gnrc_tcp_ep_t ep,
int  family,
const uint8_t *  addr,
size_t  addr_size,
uint16_t  port,
uint16_t  netif 
)

Initialize TCP connection endpoint.

Parameters
[in,out]epEndpoint to initialize.
[in]familyAddress family of addr.
[in]addrAddress for endpoint.
[in]addr_sizeSize of addr.
[in]portPort number for endpoint.
[in]netifNetwork interface to use.
Returns
0 on success.
-EAFNOSUPPORT if address_family is not supported.
-EINVAL if addr_size does not match family.

◆ 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,
const gnrc_tcp_ep_t remote,
uint16_t  local_port 
)

Opens a connection actively.

Precondition
gnrc_tcp_tcb_init() must have been successfully called.
tcb must not be NULL
remote must not be NULL.
Note
Blocks until a connection has been established or an error occurred.
Parameters
[in,out]tcbTCB holding the connection information.
[in]remoteRemote endpoint of the host to connect to.
[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 reset by the peer.

◆ gnrc_tcp_open_passive()

int gnrc_tcp_open_passive ( gnrc_tcp_tcb_t tcb,
const gnrc_tcp_ep_t local 
)

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

Precondition
gnrc_tcp_tcb_init() must have been successfully called.
tcb must not be NULL.
local must not be NULL.
port in local must not be zero.
Note
Blocks until a connection has been established (incoming connection request to local_port) or an error occurred.
Parameters
[in,out]tcbTCB holding the connection information.
[in]localEndpoint specifying the port and address used to wait for incoming connections.
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 the address in local is invalid.
-EISCONN if TCB is already in use.
-ENOMEM if the receive buffer for the TCB could not be allocated. Hint: Increase "CONFIG_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_ms 
)

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_msTimeout for receive in milliseconds. 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_ms milliseconds passed.
Returns
The number of bytes read into data.
0, if the connection is closing and no further data can be read.
-ENOTCONN if connection is not established.
-EAGAIN if user_timeout_duration_us is zero and no data is available.
-ECONNRESET if connection was reset by the peer.
-ECONNABORTED if the connection was aborted.
-ETIMEDOUT if user_timeout_duration_ms 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_ms 
)

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 occurred.
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_msIf not zero and there was not data transmitted the function returns after user_timeout_duration_ms. If zero, no timeout will be triggered.
Returns
The number of successfully transmitted bytes.
-ENOTCONN if connection is not established.
-ECONNRESET if connection was reset by the peer.
-ECONNABORTED if the connection was aborted.
-ETIMEDOUT if user_timeout_duration_ms 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.