RIOT's TCP implementation for the GNRC network stack.
More...
RIOT's TCP implementation for the GNRC network stack.
|
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_t * | gnrc_tcp_hdr_build (gnrc_pktsnip_t *payload, uint16_t src, uint16_t dst) |
| Adds a TCP header to a given payload. More...
|
|
◆ gnrc_tcp_abort()
Abort a TCP connection.
- Precondition
- gnrc_tcp_tcb_init() must have been successfully called.
-
tcb
must not be NULL.
- Parameters
-
[in,out] | tcb | TCB holding the connection information. |
◆ gnrc_tcp_calc_csum()
Calculate and set checksum in TCP header.
- Parameters
-
[in] | hdr | Gnrc_pktsnip that contains TCP header. |
[in] | pseudo_hdr | Gnrc_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()
Close a TCP connection.
- Precondition
- gnrc_tcp_tcb_init() must have been successfully called.
-
tcb
must not be NULL.
- Parameters
-
[in,out] | tcb | TCB 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] | ep | Endpoint to initialize. |
[in] | str | String 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] | ep | Endpoint to initialize. |
[in] | family | Address family of addr . |
[in] | addr | Address for endpoint. |
[in] | addr_size | Size of addr . |
[in] | port | Port number for endpoint. |
[in] | netif | Network 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()
Adds a TCP header to a given payload.
- Parameters
-
[in] | payload | Payload that follows the TCP header. |
[in] | src | Source port number. |
[in] | dst | Destination 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()
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] | tcb | TCB holding the connection information. |
[in] | remote | Remote endpoint of the host to connect to. |
[in] | local_port | If 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()
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] | tcb | TCB holding the connection information. |
[in] | local | Endpoint 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] | tcb | TCB holding the connection information. |
[out] | data | Pointer to the buffer where the received data should be copied into. |
[in] | max_len | Maximum amount to bytes that should be read into data . |
[in] | user_timeout_duration_ms | Timeout 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] | tcb | TCB holding the connection information. |
[in] | data | Pointer to the data that should be transmitted. |
[in] | len | Number of bytes that should be transmitted. |
[in] | user_timeout_duration_ms | If 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()
Initialize Transmission Control Block (TCB)
- Precondition
tcb
must not be NULL.
- Parameters
-
[in,out] | tcb | TCB that should be initialized. |