1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-24 22:13:52 +01:00

gnrc_tcp: cleanup: internal/common.h added

This commit is contained in:
Simon Brummer 2017-02-01 15:09:46 +01:00
parent 964a7b3e3b
commit 67ed2a0ad8
13 changed files with 237 additions and 248 deletions

View File

@ -35,23 +35,6 @@
extern "C" {
#endif
/**
* @brief Port unspecified.
*
* @note PORT 0 is reserved, according to rfc 1700(https://www.ietf.org/rfc/rfc1700.txt)
*/
#define GNRC_TCP_PORT_UNSPEC 0
/**
* @brief Head of conn linked list.
*/
extern gnrc_tcp_tcb_t *_list_gnrc_tcp_tcb_head;
/**
* @brief Mutex to protect linked list.
*/
extern mutex_t _list_gnrc_tcp_tcb_lock;
/**
* @brief Initialize and start TCP
*

View File

@ -28,15 +28,6 @@
extern "C" {
#endif
/**
* @brief Status Flags for TCP
* @{
*/
#define GNRC_TCP_STATUS_PASSIVE (1 << 0)
#define GNRC_TCP_STATUS_ACCEPTED (1 << 1)
#define GNRC_TCP_STATUS_ALLOW_ANY_ADDR (1 << 2)
/** @} */
/**
* @brief Timeout Duration for user calls. Default 2 minutes
*/
@ -51,27 +42,6 @@ extern "C" {
#define GNRC_TCP_MSL (30 * US_PER_SEC)
#endif
/**
* @brief Message queue size for the TCP handling thread
*/
#ifndef GNRC_TCP_MSG_QUEUE_SIZE
#define GNRC_TCP_MSG_QUEUE_SIZE (8U)
#endif
/**
* @brief Priority of the tcp handling thread, must be lower than the applications prio.
*/
#ifndef GNRC_TCP_PRIO
#define GNRC_TCP_PRIO (THREAD_PRIORITY_MAIN - 2U)
#endif
/**
* @brief Default stack size for the TCP handling thread
*/
#ifndef GNRC_TCP_STACK_SIZE
#define GNRC_TCP_STACK_SIZE (THREAD_STACKSIZE_DEFAULT)
#endif
/**
* @brief Maximum Segement Size
*/
@ -153,13 +123,6 @@ extern "C" {
#define GNRC_TCP_RTO_K (4U)
#endif
/**
* @brief Macro to mark is the time measurement is uninitialized
*/
#ifndef GNRC_TCP_RTO_UNINITIALIZED
#define GNRC_TCP_RTO_UNINITIALIZED (-1)
#endif
/**
* @brief Lower Bound for the duration between probes
*/

View File

@ -39,44 +39,49 @@
extern "C" {
#endif
/**
* @brief Size of the tcbs internal message queue
*/
#define GNRC_TCP_TCB_MSG_QUEUE_SIZE (8U)
/**
* @brief transmission control block of gnrc_tcp
*/
typedef struct _transmission_control_block {
uint8_t address_family; /**< Address Family of local_addr and peer_addr */
uint8_t address_family; /**< Address Family of local_addr and peer_addr */
#ifdef MODULE_GNRC_IPV6
uint8_t local_addr[sizeof(ipv6_addr_t)]; /**< local IP address */
uint8_t peer_addr[sizeof(ipv6_addr_t)]; /**< peer IP address */
uint8_t local_addr[sizeof(ipv6_addr_t)]; /**< local IP address */
uint8_t peer_addr[sizeof(ipv6_addr_t)]; /**< peer IP address */
#endif
uint16_t local_port; /**< local connections port number */
uint16_t peer_port; /**< port connections port number */
gnrc_tcp_fsm_state_t state; /**< Connections state */
uint8_t status; /**< A connections status flags */
uint32_t snd_una; /**< Send Unacknowledged */
uint32_t snd_nxt; /**< Send Next */
uint16_t snd_wnd; /**< Send Window */
uint32_t snd_wl1; /**< SeqNo. Last Windowupdate */
uint32_t snd_wl2; /**< AckNo. Last Windowupdate */
uint32_t rcv_nxt; /**< Receive Next */
uint16_t rcv_wnd; /**< Receive Window */
uint32_t iss; /**< Initial Sequence Number */
uint32_t irs; /**< Initial Received Sequence Number */
uint16_t mss; /**< The peers MSS */
uint32_t rtt_start; /**< Timer value for rtt estimation */
int32_t rtt_var; /**< Round Trip Time variance */
int32_t srtt; /**< Smoothed Round Trip Time */
int32_t rto; /**< Retransmission Timeout Duration */
uint8_t retries; /**< Number of Retransmissions */
xtimer_t tim_tout; /**< Timer struct for timeouts */
msg_t msg_tout; /**< Message, sent on timeouts */
gnrc_pktsnip_t *pkt_retransmit; /**< Pointer to Packet in "retransmit queue" */
kernel_pid_t owner; /**< PID of this connection handling thread */
msg_t msg_queue[GNRC_TCP_MSG_QUEUE_SIZE]; /**< Message queue used for asynchronious operation */
uint8_t *rcv_buf_raw; /**< Pointer to the receive buffer */
ringbuffer_t rcv_buf; /**< Receive Buffer data structure */
mutex_t fsm_lock; /**< Mutex for FSM access synchronization */
mutex_t function_lock; /**< Mutex for Function call synchronization */
struct _transmission_control_block *next; /**< Pointer next TCP connection */
uint16_t local_port; /**< local connections port number */
uint16_t peer_port; /**< port connections port number */
gnrc_tcp_fsm_state_t state; /**< Connections state */
uint8_t status; /**< A connections status flags */
uint32_t snd_una; /**< Send Unacknowledged */
uint32_t snd_nxt; /**< Send Next */
uint16_t snd_wnd; /**< Send Window */
uint32_t snd_wl1; /**< SeqNo. Last Windowupdate */
uint32_t snd_wl2; /**< AckNo. Last Windowupdate */
uint32_t rcv_nxt; /**< Receive Next */
uint16_t rcv_wnd; /**< Receive Window */
uint32_t iss; /**< Initial Sequence Number */
uint32_t irs; /**< Initial Received Sequence Number */
uint16_t mss; /**< The peers MSS */
uint32_t rtt_start; /**< Timer value for rtt estimation */
int32_t rtt_var; /**< Round Trip Time variance */
int32_t srtt; /**< Smoothed Round Trip Time */
int32_t rto; /**< Retransmission Timeout Duration */
uint8_t retries; /**< Number of Retransmissions */
xtimer_t tim_tout; /**< Timer struct for timeouts */
msg_t msg_tout; /**< Message, sent on timeouts */
gnrc_pktsnip_t *pkt_retransmit; /**< Pointer to Packet in "retransmit queue" */
kernel_pid_t owner; /**< PID of this connection handling thread */
msg_t msg_queue[GNRC_TCP_TCB_MSG_QUEUE_SIZE]; /**< Message queue used for asynchronious operation */
uint8_t *rcv_buf_raw; /**< Pointer to the receive buffer */
ringbuffer_t rcv_buf; /**< Receive Buffer data structure */
mutex_t fsm_lock; /**< Mutex for FSM access synchronization */
mutex_t function_lock; /**< Mutex for Function call synchronization */
struct _transmission_control_block *next; /**< Pointer next TCP connection */
} gnrc_tcp_tcb_t;
#ifdef __cplusplus

View File

@ -35,10 +35,10 @@
#include "net/gnrc/pktbuf.h"
#include "net/gnrc/tcp.h"
#include "internal/common.h"
#include "internal/fsm.h"
#include "internal/pkt.h"
#include "internal/option.h"
#include "internal/helper.h"
#include "internal/eventloop.h"
#include "internal/rcvbuf.h"
@ -53,25 +53,25 @@
* @brief Allocate memory for TCP thread's stack
*/
#if ENABLE_DEBUG
static char _stack[GNRC_TCP_STACK_SIZE + THREAD_EXTRA_STACKSIZE_PRINTF];
static char _stack[TCP_EVENTLOOP_STACK_SIZE + THREAD_EXTRA_STACKSIZE_PRINTF];
#else
static char _stack[GNRC_TCP_STACK_SIZE];
static char _stack[TCP_EVENTLOOP_STACK_SIZE];
#endif
/**
* @brief TCPs eventloop pid, declared externally
*/
kernel_pid_t _gnrc_tcp_pid = KERNEL_PID_UNDEF;
kernel_pid_t gnrc_tcp_pid = KERNEL_PID_UNDEF;
/**
* @brief Head of liked list of active connections
*/
gnrc_tcp_tcb_t *_list_gnrc_tcp_tcb_head;
gnrc_tcp_tcb_t *_list_tcb_head;
/**
* @brief Mutex to protect the connection list
*/
mutex_t _list_gnrc_tcp_tcb_lock;
mutex_t _list_tcb_lock;
/**
* @brief Establishes a new TCP connection
@ -109,15 +109,15 @@ static int _gnrc_tcp_open(gnrc_tcp_tcb_t *tcb, const uint8_t *target_addr, uint1
}
/* Setup connection (common parts) */
msg_init_queue(tcb->msg_queue, GNRC_TCP_MSG_QUEUE_SIZE);
msg_init_queue(tcb->msg_queue, GNRC_TCP_TCB_MSG_QUEUE_SIZE);
tcb->owner = thread_getpid();
/* Setup passive connection */
if (passive){
/* Set Status Flags */
tcb->status |= GNRC_TCP_STATUS_PASSIVE;
tcb->status |= STATUS_PASSIVE;
if (local_addr == NULL) {
tcb->status |= GNRC_TCP_STATUS_ALLOW_ANY_ADDR;
tcb->status |= STATUS_ALLOW_ANY_ADDR;
}
/* If local address is specified: Copy it into tcb: only connections to this addr are ok */
else {
@ -199,21 +199,22 @@ static int _gnrc_tcp_open(gnrc_tcp_tcb_t *tcb, const uint8_t *target_addr, uint1
int gnrc_tcp_init(void)
{
/* Guard: Check if thread is already running */
if (_gnrc_tcp_pid != KERNEL_PID_UNDEF) {
if (gnrc_tcp_pid != KERNEL_PID_UNDEF) {
return -1;
}
/* Initialize Mutex for linked-list synchronization */
mutex_init(&(_list_gnrc_tcp_tcb_lock));
mutex_init(&(_list_tcb_lock));
/* Initialize Linked-List for connection storage */
_list_gnrc_tcp_tcb_head = NULL;
_list_tcb_head = NULL;
/* Initialize receive buffers */
_rcvbuf_init();
/* Start TCP processing loop */
return thread_create(_stack, sizeof(_stack), GNRC_TCP_PRIO, 0, _event_loop, NULL, "gnrc_tcp");
return thread_create(_stack, sizeof(_stack), TCP_EVENTLOOP_PRIO, 0, _event_loop, NULL,
"gnrc_tcp");
}
void gnrc_tcp_tcb_init(gnrc_tcp_tcb_t* tcb)
@ -226,8 +227,8 @@ void gnrc_tcp_tcb_init(gnrc_tcp_tcb_t* tcb)
tcb->address_family = AF_UNSPEC;
DEBUG("gnrc_tcp.c : gnrc_tcp_tcb_init() : Address unspec, add netlayer module to makefile\n");
#endif
tcb->local_port = GNRC_TCP_PORT_UNSPEC;
tcb->peer_port = GNRC_TCP_PORT_UNSPEC;
tcb->local_port = PORT_UNSPEC;
tcb->peer_port = PORT_UNSPEC;
tcb->state = GNRC_TCP_FSM_STATE_CLOSED;
tcb->status = 0;
tcb->snd_una = 0;
@ -241,9 +242,9 @@ void gnrc_tcp_tcb_init(gnrc_tcp_tcb_t* tcb)
tcb->irs = 0;
tcb->mss = 0;
tcb->rtt_start = 0;
tcb->rtt_var = GNRC_TCP_RTO_UNINITIALIZED;
tcb->srtt = GNRC_TCP_RTO_UNINITIALIZED;
tcb->rto = GNRC_TCP_RTO_UNINITIALIZED;
tcb->rtt_var = RTO_UNINITIALIZED;
tcb->srtt = RTO_UNINITIALIZED;
tcb->rto = RTO_UNINITIALIZED;
tcb->retries = 0;
tcb->pkt_retransmit = NULL;
tcb->owner = KERNEL_PID_UNDEF;
@ -259,7 +260,7 @@ int gnrc_tcp_open_active(gnrc_tcp_tcb_t *tcb, const uint8_t address_family,
{
assert(tcb != NULL);
assert(target_addr != NULL);
assert(target_port != GNRC_TCP_PORT_UNSPEC);
assert(target_port != PORT_UNSPEC);
/* Check AF-Family Support from target_addr */
switch (address_family) {
@ -330,7 +331,7 @@ ssize_t gnrc_tcp_send(gnrc_tcp_tcb_t *tcb, const void *data, const size_t len,
}
/* Re-init message queue, take ownership. FSM can send Messages to this thread now */
msg_init_queue(tcb->msg_queue, GNRC_TCP_MSG_QUEUE_SIZE);
msg_init_queue(tcb->msg_queue, GNRC_TCP_TCB_MSG_QUEUE_SIZE);
tcb->owner = thread_getpid();
/* Setup Connection Timeout */
@ -464,7 +465,7 @@ ssize_t gnrc_tcp_recv(gnrc_tcp_tcb_t *tcb, void *data, const size_t max_len,
}
/* If this call is blocking, setup messages and timers */
msg_init_queue(tcb->msg_queue, GNRC_TCP_MSG_QUEUE_SIZE);
msg_init_queue(tcb->msg_queue, GNRC_TCP_TCB_MSG_QUEUE_SIZE);
tcb->owner = thread_getpid();
/* Setup Connection Timeout */
@ -535,7 +536,7 @@ int gnrc_tcp_close(gnrc_tcp_tcb_t *tcb)
/* Start connection teardown if the connection was not closed before */
if (tcb->state != GNRC_TCP_FSM_STATE_CLOSED) {
/* Take ownership */
msg_init_queue(tcb->msg_queue, GNRC_TCP_MSG_QUEUE_SIZE);
msg_init_queue(tcb->msg_queue, GNRC_TCP_TCB_MSG_QUEUE_SIZE);
tcb->owner = thread_getpid();
/* Setup Connection Timeout */

View File

@ -23,9 +23,9 @@
#include "net/tcp.h"
#include "net/gnrc/pkt.h"
#include "net/gnrc/tcp.h"
#include "internal/common.h"
#include "internal/pkt.h"
#include "internal/fsm.h"
#include "internal/helper.h"
#include "internal/option.h"
#include "internal/eventloop.h"
@ -155,8 +155,8 @@ static int _receive(gnrc_pktsnip_t *pkt)
}
/* Find tcb to de-multiplex this packet to */
mutex_lock(&_list_gnrc_tcp_tcb_lock);
tcb = _list_gnrc_tcp_tcb_head;
mutex_lock(&_list_tcb_lock);
tcb = _list_tcb_head;
while (tcb) {
#ifdef MODULE_GNRC_IPV6
/* Check if current tcb is fitting for the incomming packet */
@ -190,7 +190,7 @@ static int _receive(gnrc_pktsnip_t *pkt)
#endif
tcb = tcb->next;
}
mutex_unlock(&_list_gnrc_tcp_tcb_lock);
mutex_unlock(&_list_tcb_lock);
/* Call FSM with event RCVD_PKT if a fitting connection was found */
if (tcb != NULL) {
@ -201,7 +201,7 @@ static int _receive(gnrc_pktsnip_t *pkt)
DEBUG("gnrc_tcp_eventloop.c : _receive() : Can't find fitting connection\n");
if ((ctl & MSK_RST) != MSK_RST) {
_pkt_build_reset_from_pkt(&reset, pkt);
gnrc_netapi_send(_gnrc_tcp_pid, reset);
gnrc_netapi_send(gnrc_tcp_pid, reset);
}
return -ENOTCONN;
}
@ -213,21 +213,21 @@ void *_event_loop(__attribute__((unused)) void *arg)
{
msg_t msg;
msg_t reply;
msg_t msg_queue[GNRC_TCP_MSG_QUEUE_SIZE];
msg_t msg_queue[TCP_EVENTLOOP_MSG_QUEUE_SIZE];
/* Store pid */
_gnrc_tcp_pid = thread_getpid();
gnrc_tcp_pid = thread_getpid();
/* Setup reply message */
reply.type = GNRC_NETAPI_MSG_TYPE_ACK;
reply.content.value = (uint32_t)-ENOTSUP;
/* Init message queue*/
msg_init_queue(msg_queue, GNRC_TCP_MSG_QUEUE_SIZE);
msg_init_queue(msg_queue, TCP_EVENTLOOP_MSG_QUEUE_SIZE);
/* Register GNRC_tcp in netreg */
gnrc_netreg_entry_t entry;
gnrc_netreg_entry_init_pid(&entry, GNRC_NETREG_DEMUX_CTX_ALL, _gnrc_tcp_pid);
gnrc_netreg_entry_init_pid(&entry, GNRC_NETREG_DEMUX_CTX_ALL, gnrc_tcp_pid);
gnrc_netreg_register(GNRC_NETTYPE_TCP, &entry);
/* dispatch NETAPI Messages */

View File

@ -22,10 +22,10 @@
#include "ringbuffer.h"
#include "net/af.h"
#include "internal/common.h"
#include "internal/fsm.h"
#include "internal/pkt.h"
#include "internal/option.h"
#include "internal/helper.h"
#include "internal/rcvbuf.h"
#ifdef MODULE_GNRC_IPV6
@ -48,7 +48,7 @@
static int _is_local_port_in_use(const uint16_t portnumber)
{
gnrc_tcp_tcb_t *iter = NULL;
LL_FOREACH(_list_gnrc_tcp_tcb_head, iter) {
LL_FOREACH(_list_tcb_head, iter) {
if (iter->local_port == portnumber) {
return 1;
}
@ -102,7 +102,7 @@ static int _restart_timewait_timer(gnrc_tcp_tcb_t* tcb)
xtimer_remove(&tcb->tim_tout);
tcb->msg_tout.type = MSG_TYPE_TIMEWAIT;
tcb->msg_tout.content.ptr = (void *)tcb;
xtimer_set_msg(&tcb->tim_tout, 2 * GNRC_TCP_MSL, &tcb->msg_tout, _gnrc_tcp_pid);
xtimer_set_msg(&tcb->tim_tout, 2 * GNRC_TCP_MSL, &tcb->msg_tout, gnrc_tcp_pid);
return 0;
}
@ -126,16 +126,16 @@ static int _transition_to(gnrc_tcp_tcb_t* tcb, gnrc_tcp_fsm_state_t state, bool
_clear_retransmit(tcb);
/* Remove from Connection from active connections */
mutex_lock(&_list_gnrc_tcp_tcb_lock);
LL_FOREACH(_list_gnrc_tcp_tcb_head, iter) {
mutex_lock(&_list_tcb_lock);
LL_FOREACH(_list_tcb_head, iter) {
if (iter == tcb) {
found = 1;
}
}
if (found) {
LL_DELETE(_list_gnrc_tcp_tcb_head, iter);
LL_DELETE(_list_tcb_head, iter);
}
mutex_unlock(&_list_gnrc_tcp_tcb_lock);
mutex_unlock(&_list_tcb_lock);
/* Free potencially allocated Receive Buffer */
_rcvbuf_release_buffer(tcb);
@ -147,7 +147,7 @@ static int _transition_to(gnrc_tcp_tcb_t* tcb, gnrc_tcp_fsm_state_t state, bool
switch (tcb->address_family) {
#ifdef MODULE_GNRC_IPV6
case AF_INET6:
if (tcb->status & GNRC_TCP_STATUS_ALLOW_ANY_ADDR) {
if (tcb->status & STATUS_ALLOW_ANY_ADDR) {
ipv6_addr_set_unspecified((ipv6_addr_t *) tcb->local_addr);
}
ipv6_addr_set_unspecified((ipv6_addr_t *) tcb->peer_addr);
@ -157,7 +157,7 @@ static int _transition_to(gnrc_tcp_tcb_t* tcb, gnrc_tcp_fsm_state_t state, bool
DEBUG("gnrc_tcp_fsm.c : _transition_to() : Undefined Addresses\n");
break;
}
tcb->peer_port = GNRC_TCP_PORT_UNSPEC;
tcb->peer_port = PORT_UNSPEC;
/* Allocate rcv Buffer */
if (_rcvbuf_get_buffer(tcb) == -ENOMEM) {
@ -165,16 +165,16 @@ static int _transition_to(gnrc_tcp_tcb_t* tcb, gnrc_tcp_fsm_state_t state, bool
}
/* Add to Connection to active connections (if not already active) */
mutex_lock(&_list_gnrc_tcp_tcb_lock);
LL_FOREACH(_list_gnrc_tcp_tcb_head, iter) {
mutex_lock(&_list_tcb_lock);
LL_FOREACH(_list_tcb_head, iter) {
if (iter == tcb) {
found = 1;
}
}
if (!found) {
LL_APPEND(_list_gnrc_tcp_tcb_head, tcb);
LL_APPEND(_list_tcb_head, tcb);
}
mutex_unlock(&_list_gnrc_tcp_tcb_lock);
mutex_unlock(&_list_tcb_lock);
break;
case GNRC_TCP_FSM_STATE_SYN_SENT:
@ -184,8 +184,8 @@ static int _transition_to(gnrc_tcp_tcb_t* tcb, gnrc_tcp_fsm_state_t state, bool
}
/* Add to Connections to active connection (if not already active) */
mutex_lock(&_list_gnrc_tcp_tcb_lock);
LL_FOREACH(_list_gnrc_tcp_tcb_head, iter) {
mutex_lock(&_list_tcb_lock);
LL_FOREACH(_list_tcb_head, iter) {
if (iter == tcb) {
found = 1;
}
@ -193,11 +193,11 @@ static int _transition_to(gnrc_tcp_tcb_t* tcb, gnrc_tcp_fsm_state_t state, bool
/* If not already active: Apped tcb but check portnumber first */
if (!found) {
/* Check if Port Number is not in use */
if (tcb->local_port != GNRC_TCP_PORT_UNSPEC ) {
if (tcb->local_port != PORT_UNSPEC ) {
/* If Portnumber is used: return error and release buffer */
if (_is_local_port_in_use(tcb->local_port)) {
mutex_unlock(&_list_gnrc_tcp_tcb_lock);
mutex_unlock(&_list_tcb_lock);
_rcvbuf_release_buffer(tcb);
return -EADDRINUSE;
}
@ -206,9 +206,9 @@ static int _transition_to(gnrc_tcp_tcb_t* tcb, gnrc_tcp_fsm_state_t state, bool
else {
tcb->local_port = _get_random_local_port();
}
LL_APPEND(_list_gnrc_tcp_tcb_head, tcb);
LL_APPEND(_list_tcb_head, tcb);
}
mutex_unlock(&_list_gnrc_tcp_tcb_lock);
mutex_unlock(&_list_tcb_lock);
break;
case GNRC_TCP_FSM_STATE_ESTABLISHED:
@ -249,7 +249,7 @@ static int _fsm_call_open(gnrc_tcp_tcb_t* tcb, bool *notify_owner)
DEBUG("gnrc_tcp_fsm.c : _fsm_call_open()\n");
tcb->rcv_wnd = GNRC_TCP_DEFAULT_WINDOW;
if (tcb->status & GNRC_TCP_STATUS_PASSIVE) {
if (tcb->status & STATUS_PASSIVE) {
/* Passive Open, T: CLOSED -> LISTEN */
if (_transition_to(tcb, GNRC_TCP_FSM_STATE_LISTEN, notify_owner) == -ENOMEM){
_transition_to(tcb, GNRC_TCP_FSM_STATE_CLOSED, notify_owner);
@ -465,7 +465,7 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *in_pkt, bool *noti
uint16_t dst = byteorder_ntohs(tcp_hdr->dst_port);
/* Check if SYN Request is handled by another connection */
lst = _list_gnrc_tcp_tcb_head;
lst = _list_tcb_head;
while (lst) {
/* Compare Portnumbers and Network Layer Adresses */
/* Note: Packets without ip-header were discarded earlier */
@ -600,7 +600,7 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *in_pkt, bool *noti
if (ctl & MSK_RST) {
/* .. and State is SYN_RCVD and passive Open: SYN_RCVD -> LISTEN */
if (tcb->state == GNRC_TCP_FSM_STATE_SYN_RCVD
&& (tcb->status & GNRC_TCP_STATUS_PASSIVE)
&& (tcb->status & STATUS_PASSIVE)
) {
if (_transition_to(tcb, GNRC_TCP_FSM_STATE_LISTEN, notify_owner) == -ENOMEM) {
_transition_to(tcb, GNRC_TCP_FSM_STATE_CLOSED, notify_owner);

View File

@ -17,6 +17,7 @@
* @}
*/
#include "assert.h"
#include "internal/common.h"
#include "internal/option.h"
#define ENABLE_DEBUG (0)

View File

@ -23,17 +23,14 @@
#include "net/inet_csum.h"
#include "net/gnrc/pktbuf.h"
#include "net/gnrc/tcp.h"
#include "internal/common.h"
#include "internal/pkt.h"
#include "internal/helper.h"
#include "internal/option.h"
#include "internal/eventloop.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
/* Check if a sequence number, falls into the receive window */
#define INSIDE_WND(l_ed, seq_num, r_ed) (LEQ_32_BIT(l_ed, seq_num) && LSS_32_BIT(seq_num, r_ed))
/**
* @brief Calculates the maximum of two unsigned numbers
*
@ -227,7 +224,7 @@ int _pkt_send(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *out_pkt, const uint16_t seq_c
}
/* Pass packet down the network stack */
gnrc_netapi_send(_gnrc_tcp_pid, out_pkt);
gnrc_netapi_send(gnrc_tcp_pid, out_pkt);
return 0;
}
@ -331,7 +328,7 @@ int _pkt_setup_retransmit(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *pkt, const bool r
/* RTO Adjustment */
if (!retransmit) {
/* If this is the first transmission: rto is 1 sec (Lower Bound) */
if (tcb->srtt == GNRC_TCP_RTO_UNINITIALIZED || tcb->rtt_var == GNRC_TCP_RTO_UNINITIALIZED) {
if (tcb->srtt == RTO_UNINITIALIZED || tcb->rtt_var == RTO_UNINITIALIZED) {
tcb->rto = GNRC_TCP_RTO_LOWER_BOUND;
}
else {
@ -345,8 +342,8 @@ int _pkt_setup_retransmit(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *pkt, const bool r
/* If the transmission has been tried five times, we assume srtt and rtt_var are bogus */
/* New measurements must be taken */
if (tcb->retries >= 5) {
tcb->srtt = GNRC_TCP_RTO_UNINITIALIZED;
tcb->rtt_var = GNRC_TCP_RTO_UNINITIALIZED;
tcb->srtt = RTO_UNINITIALIZED;
tcb->rtt_var = RTO_UNINITIALIZED;
}
}
@ -361,7 +358,7 @@ int _pkt_setup_retransmit(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *pkt, const bool r
/* Setup retransmission timer, msg to TCP thread with ptr to tcb */
tcb->msg_tout.type = MSG_TYPE_RETRANSMISSION;
tcb->msg_tout.content.ptr = (void *)tcb;
xtimer_set_msg(&tcb->tim_tout, tcb->rto, &tcb->msg_tout, _gnrc_tcp_pid);
xtimer_set_msg(&tcb->tim_tout, tcb->rto, &tcb->msg_tout, gnrc_tcp_pid);
return 0;
}
@ -395,8 +392,8 @@ int _pkt_acknowledge(gnrc_tcp_tcb_t* tcb, const uint32_t ack)
/* Use sample only if ther was no timeroverflow and no retransmission (Karns Alogrithm) */
if (tcb->retries == 0 && rtt > 0) {
/* If this is the first sample taken */
if (tcb->srtt == GNRC_TCP_RTO_UNINITIALIZED
&& tcb->rtt_var == GNRC_TCP_RTO_UNINITIALIZED
if (tcb->srtt == RTO_UNINITIALIZED
&& tcb->rtt_var == RTO_UNINITIALIZED
) {
tcb->srtt = rtt;
tcb->rtt_var = (rtt >> 1);
@ -448,6 +445,3 @@ uint16_t _pkt_calc_csum(const gnrc_pktsnip_t *hdr,
}
return ~csum;
}
/* Cleanup, defines */
#undef INSIDE_WND

View File

@ -0,0 +1,137 @@
/*
* Copyright (C) 2015 Simon Brummer
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup net_gnrc_tcp TCP
* @ingroup net_gnrc
* @brief RIOT's tcp implementation for the gnrc stack
*
* @{
*
* @file
* @brief Helperfunctions and defines
*
* @author Simon Brummer <brummer.simon@googlemail.com>
*/
#ifndef GNRC_TCP_INTERNAL_COMMON_H_
#define GNRC_TCP_INTERNAL_COMMON_H_
#include <stdint.h>
#include "kernel_types.h"
#include "thread.h"
#include "mutex.h"
#include "net/gnrc/netapi.h"
#include "net/gnrc/tcp/tcb.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Port unspecified.
*
* @note PORT 0 is unspecified (@see https://www.ietf.org/rfc/rfc1700.txt)
*/
#define PORT_UNSPEC (0)
/**
* @brief Status Flags for TCP
* @{
*/
#define STATUS_PASSIVE (1 << 0)
#define STATUS_ALLOW_ANY_ADDR (1 << 1)
/** @} */
/**
* @brief Defines for gnrc tcps "eventloop" thread
* @{
*/
#define TCP_EVENTLOOP_MSG_QUEUE_SIZE (8U)
#define TCP_EVENTLOOP_PRIO (THREAD_PRIORITY_MAIN - 2U)
#define TCP_EVENTLOOP_STACK_SIZE (THREAD_STACKSIZE_DEFAULT)
/** @} */
/**
* @brief Bitmasks for control bit handling
* @{
*/
#define MSK_FIN (0x0001)
#define MSK_SYN (0x0002)
#define MSK_RST (0x0004)
#define MSK_PSH (0x0008)
#define MSK_ACK (0x0010)
#define MSK_URG (0x0020)
#define MSK_FIN_ACK (0x0011)
#define MSK_SYN_ACK (0x0012)
#define MSK_RST_ACK (0x0014)
#define MSK_SYN_FIN_ACK (0x0013)
#define MSK_FIN_ACK_PSH (0x0019)
#define MSK_CTL (0x003F)
#define MSK_OFFSET (0xF000)
/** @} */
/**
* @brief Type field values for TCP internal Message Passing.
* @{
*/
#define MSG_TYPE_CONNECTION_TIMEOUT (GNRC_NETAPI_MSG_TYPE_ACK + 101)
#define MSG_TYPE_PROBE_TIMEOUT (GNRC_NETAPI_MSG_TYPE_ACK + 102)
#define MSG_TYPE_USER_SPEC_TIMEOUT (GNRC_NETAPI_MSG_TYPE_ACK + 103)
#define MSG_TYPE_RETRANSMISSION (GNRC_NETAPI_MSG_TYPE_ACK + 104)
#define MSG_TYPE_TIMEWAIT (GNRC_NETAPI_MSG_TYPE_ACK + 105)
#define MSG_TYPE_NOTIFY_USER (GNRC_NETAPI_MSG_TYPE_ACK + 106)
/** @} */
/**
* @brief Macro to mark is the time measurement is uninitialized
*/
#define RTO_UNINITIALIZED (-1)
/**
* @brief Overflow tolerant comparision operators for sequence and
acknowledgement number comparision
* @{
*/
#define LSS_32_BIT(x, y) (((int32_t) (x)) - ((int32_t) (y)) < 0)
#define LEQ_32_BIT(x, y) (((int32_t) (x)) - ((int32_t) (y)) <= 0)
#define GRT_32_BIT(x, y) (!LEQ_32_BIT(x, y))
#define GEQ_32_BIT(x, y) (!LSS_32_BOT(x, y))
/** @} */
/**
* @brief Check if a given sequence number, falls into the a receive window
*/
#define INSIDE_WND(l_ed, seq_num, r_ed) (LEQ_32_BIT(l_ed, seq_num) && LSS_32_BIT(seq_num, r_ed))
/**
* @brief Extract offset value from "offctl"-header field.
*/
#define GET_OFFSET( x ) (((x) & MSK_OFFSET) >> 12)
/**
* @brief PID of tcp event handling thread
*/
extern kernel_pid_t gnrc_tcp_pid;
/**
* @brief Head of conn linked list.
*/
extern gnrc_tcp_tcb_t *_list_tcb_head;
/**
* @brief Mutex to protect linked list.
*/
extern mutex_t _list_tcb_lock;
#ifdef __cplusplus
}
#endif
#endif /* GNRC_TCP_INTERNAL_COMMON_H_ */
/** @} */

View File

@ -26,11 +26,6 @@
extern "C" {
#endif
/**
* @brief PID of tcp event handling thread
*/
extern kernel_pid_t _gnrc_tcp_pid;
/**
* @brief TCP's mein processing thread.
*

View File

@ -32,11 +32,6 @@
extern "C" {
#endif
/**
* @brief PID of tcp event handling thread
*/
extern kernel_pid_t _gnrc_tcp_pid;
/**
* @brief TCP finite state maschine
*

View File

@ -1,79 +0,0 @@
/*
* Copyright (C) 2015 Simon Brummer
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup net_gnrc_tcp TCP
* @ingroup net_gnrc
* @brief RIOT's tcp implementation for the gnrc stack
*
* @{
*
* @file
* @brief Helperfunctions and defines
*
* @author Simon Brummer <brummer.simon@googlemail.com>
*/
#ifndef GNRC_TCP_INTERNAL_HELPER_H_
#define GNRC_TCP_INTERNAL_HELPER_H_
#include "net/tcp.h"
#include "net/gnrc/netapi.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Bitmasks for control bit handling
* @{
*/
#define MSK_FIN 0x0001
#define MSK_SYN 0x0002
#define MSK_RST 0x0004
#define MSK_PSH 0x0008
#define MSK_ACK 0x0010
#define MSK_URG 0x0020
#define MSK_FIN_ACK 0x0011
#define MSK_SYN_ACK 0x0012
#define MSK_RST_ACK 0x0014
#define MSK_SYN_FIN_ACK 0x0013
#define MSK_FIN_ACK_PSH 0x0019
#define MSK_CTL 0x003F
#define MSK_OFFSET 0xF000
/** @} */
/**
* @brief Type field values for TCP internal Message Passing.
* @{
*/
#define MSG_TYPE_CONNECTION_TIMEOUT (GNRC_NETAPI_MSG_TYPE_ACK + 101)
#define MSG_TYPE_PROBE_TIMEOUT (GNRC_NETAPI_MSG_TYPE_ACK + 102)
#define MSG_TYPE_USER_SPEC_TIMEOUT (GNRC_NETAPI_MSG_TYPE_ACK + 103)
#define MSG_TYPE_RETRANSMISSION (GNRC_NETAPI_MSG_TYPE_ACK + 104)
#define MSG_TYPE_TIMEWAIT (GNRC_NETAPI_MSG_TYPE_ACK + 105)
#define MSG_TYPE_NOTIFY_USER (GNRC_NETAPI_MSG_TYPE_ACK + 106)
/** @} */
/**
* @brief Overflow tolerant comparision operators for sequence and
acknowledgement number comparision
* @{
*/
#define LSS_32_BIT(x, y) (((int32_t) (x)) - ((int32_t) (y)) < 0)
#define LEQ_32_BIT(x, y) (((int32_t) (x)) - ((int32_t) (y)) <= 0)
#define GRT_32_BIT(x, y) (!LEQ_32_BIT(x, y))
#define GEQ_32_BIT(x, y) (!LSS_32_BOT(x, y))
/** @} */
#ifdef __cplusplus
}
#endif
#endif /* GNRC_TCP_INTERNAL_HELPER_H_ */
/** @} */

View File

@ -22,7 +22,6 @@
#ifndef GNRC_TCP_INTERNAL_OPTION_H_
#define GNRC_TCP_INTERNAL_OPTION_H_
#include "helper.h"
#include "net/tcp.h"
#include "net/gnrc/tcp.h"
@ -30,11 +29,6 @@
extern "C" {
#endif
/**
* @brief Extract offset value from offet and ctl bit field.
*/
#define GET_OFFSET( x ) (((x) & MSK_OFFSET) >> 12)
/**
* @brief Helper Function to build the MSS Option
*