tcp.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2015-2017 Simon Brummer
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
21 #include <stdint.h>
22 #include "net/gnrc/pkt.h"
23 #include "net/gnrc/tcp/tcb.h"
24 
25 #ifdef SOCK_HAS_IPV6
26 #include "net/sock.h"
27 #else
28 #ifdef MODULE_GNRC_IPV6
29 #include "net/gnrc/ipv6.h"
30 #endif
31 #endif
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 /* Note: This value if configurable for test purposes. Do not override it.
38  * Changing this value may lead to errors that are hard to track down.
39  */
40 #ifndef GNRC_TCP_NO_TIMEOUT
44 #define GNRC_TCP_NO_TIMEOUT (UINT32_MAX)
45 #endif
46 
47 #ifdef SOCK_HAS_IPV6
48 /* Reuse sock endpoint if sock is available and supporting IPv6. */
49 typedef struct _sock_tl_ep gnrc_tcp_ep_t;
50 
51 #else
56 typedef struct {
57  int family;
58  union {
59 #ifdef MODULE_GNRC_IPV6
60  uint8_t ipv6[sizeof(ipv6_addr_t)];
61 #endif
62  uint8_t dummy;
63  } addr;
64  uint16_t netif;
65  uint16_t port;
67 #endif
68 
83 int gnrc_tcp_ep_init(gnrc_tcp_ep_t *ep, int family, const uint8_t *addr, size_t addr_size,
84  uint16_t port, uint16_t netif);
85 
100 int gnrc_tcp_ep_from_str(gnrc_tcp_ep_t *ep, const char *str);
101 
110 int gnrc_tcp_init(void);
111 
119 
127 
154 int gnrc_tcp_open(gnrc_tcp_tcb_t *tcb, const gnrc_tcp_ep_t *remote, uint16_t local_port);
155 
178 int gnrc_tcp_listen(gnrc_tcp_tcb_queue_t *queue, gnrc_tcp_tcb_t *tcbs, size_t tcbs_len,
179  const gnrc_tcp_ep_t *local);
180 
203  const uint32_t user_timeout_duration_ms);
204 
230 ssize_t gnrc_tcp_send(gnrc_tcp_tcb_t *tcb, const void *data, const size_t len,
231  const uint32_t user_timeout_duration_ms);
232 
264 ssize_t gnrc_tcp_recv(gnrc_tcp_tcb_t *tcb, void *data, const size_t max_len,
265  const uint32_t user_timeout_duration_ms);
266 
276 
286 
298 
312 
326 
340 
352 int gnrc_tcp_calc_csum(const gnrc_pktsnip_t *hdr, const gnrc_pktsnip_t *pseudo_hdr);
353 
364 gnrc_pktsnip_t *gnrc_tcp_hdr_build(gnrc_pktsnip_t *payload, uint16_t src, uint16_t dst);
365 
366 #ifdef __cplusplus
367 }
368 #endif
369 
Definitions for GNRC's IPv6 implementation.
void gnrc_tcp_close(gnrc_tcp_tcb_t *tcb)
Close a TCP connection.
void gnrc_tcp_tcb_queue_init(gnrc_tcp_tcb_queue_t *queue)
Initialize Transmission Control Block (TCB) queue.
void gnrc_tcp_stop_listen(gnrc_tcp_tcb_queue_t *queue)
Close connections and stop listening on TCB queue.
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.
int gnrc_tcp_init(void)
Initialize TCP.
int gnrc_tcp_queue_get_local(gnrc_tcp_tcb_queue_t *queue, gnrc_tcp_ep_t *ep)
Gets the local end point of a TCB queue.
int gnrc_tcp_calc_csum(const gnrc_pktsnip_t *hdr, const gnrc_pktsnip_t *pseudo_hdr)
Calculate and set checksum in TCP header.
int gnrc_tcp_get_local(gnrc_tcp_tcb_t *tcb, gnrc_tcp_ep_t *ep)
Get the local end point of a connected TCB.
int gnrc_tcp_accept(gnrc_tcp_tcb_queue_t *queue, gnrc_tcp_tcb_t **tcb, const uint32_t user_timeout_duration_ms)
Accept TCP connection from listening queue.
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.
int gnrc_tcp_ep_from_str(gnrc_tcp_ep_t *ep, const char *str)
Construct TCP connection endpoint from string.
int gnrc_tcp_get_remote(gnrc_tcp_tcb_t *tcb, gnrc_tcp_ep_t *ep)
Get the remote end point of a connected TCB.
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.
int gnrc_tcp_listen(gnrc_tcp_tcb_queue_t *queue, gnrc_tcp_tcb_t *tcbs, size_t tcbs_len, const gnrc_tcp_ep_t *local)
Configures a sequence of TCBs to wait for incoming connections.
void gnrc_tcp_abort(gnrc_tcp_tcb_t *tcb)
Abort a TCP connection.
int gnrc_tcp_open(gnrc_tcp_tcb_t *tcb, const gnrc_tcp_ep_t *remote, uint16_t local_port)
Opens a connection.
void gnrc_tcp_tcb_init(gnrc_tcp_tcb_t *tcb)
Initialize Transmission Control Block (TCB)
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.
General definitions for network packets and their helper functions.
Common sock API definitions.
Common IP-based transport layer end point.
Definition: sock.h:211
union _sock_tl_ep::@390 addr
address
uint8_t ipv6[16]
IPv6 address mode.
Definition: sock.h:226
Type to represent parts (either headers or payload) of a packet, called snips.
Definition: pkt.h:105
Address information for a single TCP connection endpoint.
Definition: tcp.h:56
uint16_t netif
Network interface ID.
Definition: tcp.h:64
int family
IP address family.
Definition: tcp.h:57
uint16_t port
Port number (in host byte order)
Definition: tcp.h:65
uint8_t dummy
Enable build without network module.
Definition: tcp.h:62
TCP queue type.
Definition: sock_types.h:114
TCP sock type.
Definition: sock_types.h:101
GNRC TCP transmission control block (TCB)
Data type to represent an IPv6 address.
Definition: addr.h:64