Browse Source

gnrc_tcp: cleanup: Enforce coding convention

pr/rotary
Simon Brummer 6 years ago
parent
commit
7e7b832219
  1. 2
      sys/include/net/gnrc/tcp.h
  2. 16
      sys/include/net/gnrc/tcp/config.h
  3. 86
      sys/net/gnrc/transport_layer/tcp/gnrc_tcp.c
  4. 17
      sys/net/gnrc/transport_layer/tcp/gnrc_tcp_eventloop.c
  5. 146
      sys/net/gnrc/transport_layer/tcp/gnrc_tcp_fsm.c
  6. 14
      sys/net/gnrc/transport_layer/tcp/gnrc_tcp_option.c
  7. 46
      sys/net/gnrc/transport_layer/tcp/gnrc_tcp_pkt.c
  8. 10
      sys/net/gnrc/transport_layer/tcp/gnrc_tcp_rcvbuf.c
  9. 13
      sys/net/gnrc/transport_layer/tcp/internal/fsm.h
  10. 15
      sys/net/gnrc/transport_layer/tcp/internal/option.h
  11. 10
      sys/net/gnrc/transport_layer/tcp/internal/pkt.h
  12. 4
      sys/net/gnrc/transport_layer/tcp/internal/rcvbuf.h
  13. 18
      tests/gnrc_tcp_client/main.c
  14. 16
      tests/gnrc_tcp_server/main.c

2
sys/include/net/gnrc/tcp.h

@ -51,7 +51,7 @@ int gnrc_tcp_init(void);
*
* @param[in,out] tcb Transmission that should be initialized.
*/
void gnrc_tcp_tcb_init(gnrc_tcp_tcb_t* tcb);
void gnrc_tcp_tcb_init(gnrc_tcp_tcb_t *tcb);
/**
* @brief Opens a connection actively.

16
sys/include/net/gnrc/tcp/config.h

@ -32,14 +32,14 @@ extern "C" {
* @brief Timeout Duration for user calls. Default 2 minutes
*/
#ifndef GNRC_TCP_CONNECTION_TIMEOUT_DURATION
#define GNRC_TCP_CONNECTION_TIMEOUT_DURATION (120 * US_PER_SEC)
#define GNRC_TCP_CONNECTION_TIMEOUT_DURATION (120U * US_PER_SEC)
#endif
/**
* @brief Maximum Segment Lifetime. Default 30 secounds
*/
#ifndef GNRC_TCP_MSL
#define GNRC_TCP_MSL (30 * US_PER_SEC)
#define GNRC_TCP_MSL (30U * US_PER_SEC)
#endif
/**
@ -71,7 +71,7 @@ extern "C" {
* @brief Number of preallocated receive buffers
*/
#ifndef GNRC_TCP_RCV_BUFFERS
#define GNRC_TCP_RCV_BUFFERS 1
#define GNRC_TCP_RCV_BUFFERS (1U)
#endif
/**
@ -85,21 +85,21 @@ extern "C" {
* @brief Lower Bound for RTO = 1 sec (see RFC 6298)
*/
#ifndef GNRC_TCP_RTO_LOWER_BOUND
#define GNRC_TCP_RTO_LOWER_BOUND (1 * US_PER_SEC)
#define GNRC_TCP_RTO_LOWER_BOUND (1U * US_PER_SEC)
#endif
/**
* @brief Upper Bound for RTO = 60 sec (see RFC 6298)
*/
#ifndef GNRC_TCP_RTO_UPPER_BOUND
#define GNRC_TCP_RTO_UPPER_BOUND (60 * US_PER_SEC)
#define GNRC_TCP_RTO_UPPER_BOUND (60U * US_PER_SEC)
#endif
/**
* @brief Assumes clock granularity for TCP of 10 ms (see RFC 6298)
*/
#ifndef GNRC_TCP_RTO_GRANULARITY
#define GNRC_TCP_RTO_GRANULARITY (10 * MS_PER_SEC)
#define GNRC_TCP_RTO_GRANULARITY (10U * MS_PER_SEC)
#endif
/**
@ -127,14 +127,14 @@ extern "C" {
* @brief Lower Bound for the duration between probes
*/
#ifndef GNRC_TCP_PROBE_LOWER_BOUND
#define GNRC_TCP_PROBE_LOWER_BOUND (1 * US_PER_SEC)
#define GNRC_TCP_PROBE_LOWER_BOUND (1U * US_PER_SEC)
#endif
/**
* @brief Upper Bound for the duration between probes
*/
#ifndef GNRC_TCP_PROBE_UPPER_BOUND
#define GNRC_TCP_PROBE_UPPER_BOUND (60 * US_PER_SEC)
#define GNRC_TCP_PROBE_UPPER_BOUND (60U * US_PER_SEC)
#endif
#ifdef __cplusplus

86
sys/net/gnrc/transport_layer/tcp/gnrc_tcp.c

@ -113,7 +113,7 @@ static int _gnrc_tcp_open(gnrc_tcp_tcb_t *tcb, const uint8_t *target_addr, uint1
tcb->owner = thread_getpid();
/* Setup passive connection */
if (passive){
if (passive) {
/* Set Status Flags */
tcb->status |= STATUS_PASSIVE;
if (local_addr == NULL) {
@ -133,14 +133,14 @@ static int _gnrc_tcp_open(gnrc_tcp_tcb_t *tcb, const uint8_t *target_addr, uint1
tcb->local_port = local_port;
}
/* Setup active connection */
else{
else {
/* Copy Target Address and Port into tcb structure */
if (target_addr != NULL) {
switch (tcb->address_family) {
#ifdef MODULE_GNRC_IPV6
case AF_INET6:
memcpy(tcb->peer_addr, target_addr, sizeof(ipv6_addr_t));
break;
case AF_INET6:
memcpy(tcb->peer_addr, target_addr, sizeof(ipv6_addr_t));
break;
#endif
}
}
@ -159,15 +159,14 @@ static int _gnrc_tcp_open(gnrc_tcp_tcb_t *tcb, const uint8_t *target_addr, uint1
ret = _fsm(tcb, FSM_EVENT_CALL_OPEN, NULL, NULL, 0);
if (ret == -ENOMEM) {
DEBUG("gnrc_tcp.c : gnrc_tcp_connect() : Out of receive buffers.\n");
} else if(ret == -EADDRINUSE) {
}
else if(ret == -EADDRINUSE) {
DEBUG("gnrc_tcp.c : gnrc_tcp_connect() : local_port is already in use.\n");
}
/* Wait until a connection was established or closed */
while (ret >= 0 && tcb->state != FSM_STATE_CLOSED
&& tcb->state != FSM_STATE_ESTABLISHED
&& tcb->state != FSM_STATE_CLOSE_WAIT
) {
while (ret >= 0 && tcb->state != FSM_STATE_CLOSED && tcb->state != FSM_STATE_ESTABLISHED &&
tcb->state != FSM_STATE_CLOSE_WAIT) {
msg_receive(&msg);
switch (msg.type) {
case MSG_TYPE_CONNECTION_TIMEOUT:
@ -217,7 +216,7 @@ int gnrc_tcp_init(void)
"gnrc_tcp");
}
void gnrc_tcp_tcb_init(gnrc_tcp_tcb_t* tcb)
void gnrc_tcp_tcb_init(gnrc_tcp_tcb_t *tcb)
{
#ifdef MODULE_GNRC_IPV6
tcb->address_family = AF_INET6;
@ -323,11 +322,9 @@ ssize_t gnrc_tcp_send(gnrc_tcp_tcb_t *tcb, const void *data, const size_t len,
mutex_lock(&(tcb->function_lock));
/* Check if connection is in a valid state */
if (tcb->state != FSM_STATE_ESTABLISHED
&& tcb->state != FSM_STATE_CLOSE_WAIT
) {
mutex_unlock(&(tcb->function_lock));
return -ENOTCONN;
if (tcb->state != FSM_STATE_ESTABLISHED && tcb->state != FSM_STATE_CLOSE_WAIT) {
mutex_unlock(&(tcb->function_lock));
return -ENOTCONN;
}
/* Re-init message queue, take ownership. FSM can send Messages to this thread now */
@ -349,8 +346,8 @@ ssize_t gnrc_tcp_send(gnrc_tcp_tcb_t *tcb, const void *data, const size_t len,
while (ret == 0 || tcb->pkt_retransmit != NULL) {
/* Check if the connections state is closed. If so, a reset was received */
if (tcb->state == FSM_STATE_CLOSED) {
ret = -ECONNRESET;
break;
ret = -ECONNRESET;
break;
}
/* If the send window is closed: Setup Probing */
@ -445,19 +442,16 @@ ssize_t gnrc_tcp_recv(gnrc_tcp_tcb_t *tcb, void *data, const size_t max_len,
mutex_lock(&(tcb->function_lock));
/* Check if connection is in a valid state */
if (tcb->state != FSM_STATE_ESTABLISHED
&& tcb->state != FSM_STATE_FIN_WAIT_1
&& tcb->state != FSM_STATE_FIN_WAIT_2
&& tcb->state != FSM_STATE_CLOSE_WAIT
) {
mutex_unlock(&(tcb->function_lock));
return -ENOTCONN;
if (tcb->state != FSM_STATE_ESTABLISHED && tcb->state != FSM_STATE_FIN_WAIT_1 &&
tcb->state != FSM_STATE_FIN_WAIT_2 && tcb->state != FSM_STATE_CLOSE_WAIT) {
mutex_unlock(&(tcb->function_lock));
return -ENOTCONN;
}
/* If this call is non-blocking (timeout_duration_us == 0): Try to read data and return */
if (timeout_duration_us == 0) {
ret = _fsm(tcb, FSM_EVENT_CALL_RECV, NULL, data, max_len);
if(ret == 0) {
if (ret == 0) {
ret = -EAGAIN;
}
mutex_unlock(&(tcb->function_lock));
@ -481,8 +475,8 @@ ssize_t gnrc_tcp_recv(gnrc_tcp_tcb_t *tcb, void *data, const size_t max_len,
while (ret == 0) {
/* Check if the connections state is closed. If so, a reset was received */
if (tcb->state == FSM_STATE_CLOSED) {
ret = -ECONNRESET;
break;
ret = -ECONNRESET;
break;
}
/* Try to read available data */
@ -492,24 +486,24 @@ ssize_t gnrc_tcp_recv(gnrc_tcp_tcb_t *tcb, void *data, const size_t max_len,
if (ret <= 0) {
msg_receive(&msg);
switch (msg.type) {
case MSG_TYPE_CONNECTION_TIMEOUT:
DEBUG("gnrc_tcp.c : gnrc_tcp_recv() : CONNECTION_TIMEOUT\n");
_fsm(tcb, FSM_EVENT_TIMEOUT_CONNECTION, NULL, NULL, 0);
ret = -ECONNABORTED;
break;
case MSG_TYPE_USER_SPEC_TIMEOUT:
DEBUG("gnrc_tcp.c : gnrc_tcp_send() : USER_SPEC_TIMEOUT\n");
_fsm(tcb, FSM_EVENT_CLEAR_RETRANSMIT, NULL, NULL, 0);
ret = -ETIMEDOUT;
break;
case MSG_TYPE_NOTIFY_USER:
DEBUG("gnrc_tcp.c : gnrc_tcp_recv() : NOTIFY_USER\n");
break;
default:
DEBUG("gnrc_tcp.c : gnrc_tcp_recv() : other message type\n");
case MSG_TYPE_CONNECTION_TIMEOUT:
DEBUG("gnrc_tcp.c : gnrc_tcp_recv() : CONNECTION_TIMEOUT\n");
_fsm(tcb, FSM_EVENT_TIMEOUT_CONNECTION, NULL, NULL, 0);
ret = -ECONNABORTED;
break;
case MSG_TYPE_USER_SPEC_TIMEOUT:
DEBUG("gnrc_tcp.c : gnrc_tcp_send() : USER_SPEC_TIMEOUT\n");
_fsm(tcb, FSM_EVENT_CLEAR_RETRANSMIT, NULL, NULL, 0);
ret = -ETIMEDOUT;
break;
case MSG_TYPE_NOTIFY_USER:
DEBUG("gnrc_tcp.c : gnrc_tcp_recv() : NOTIFY_USER\n");
break;
default:
DEBUG("gnrc_tcp.c : gnrc_tcp_recv() : other message type\n");
}
}
}

17
sys/net/gnrc/transport_layer/tcp/gnrc_tcp_eventloop.c

@ -114,9 +114,9 @@ static int _receive(gnrc_pktsnip_t *pkt)
/* Get TCP Header */
LL_SEARCH_SCALAR(pkt, tcp, type, GNRC_NETTYPE_TCP);
if (tcp == NULL) {
DEBUG("gnrc_tcp_eventloop.c : _receive() : pkt contains no TCP Header\n");
gnrc_pktbuf_release(pkt);
return 0;
DEBUG("gnrc_tcp_eventloop.c : _receive() : pkt contains no TCP Header\n");
gnrc_pktbuf_release(pkt);
return 0;
}
/* Extract control bits, src and dst ports and check if SYN is set (not SYN+ACK) */
@ -162,14 +162,13 @@ static int _receive(gnrc_pktsnip_t *pkt)
/* Check if current tcb is fitting for the incomming packet */
if (ip->type == GNRC_NETTYPE_IPV6 && tcb->address_family == AF_INET6) {
/* If SYN is set, a connection is listening on that port ... */
ipv6_addr_t * tmp_addr = NULL;
ipv6_addr_t *tmp_addr = NULL;
if (syn && tcb->local_port == dst && tcb->state == FSM_STATE_LISTEN) {
/* ... and local addr is unspec or preconfigured */
tmp_addr = &((ipv6_hdr_t * )ip->data)->dst;
if (ipv6_addr_equal((ipv6_addr_t *) tcb->local_addr, (ipv6_addr_t *) tmp_addr)
|| ipv6_addr_is_unspecified((ipv6_addr_t *) tcb->local_addr)
) {
break;
tmp_addr = &((ipv6_hdr_t *)ip->data)->dst;
if (ipv6_addr_equal((ipv6_addr_t *) tcb->local_addr, (ipv6_addr_t *) tmp_addr) ||
ipv6_addr_is_unspecified((ipv6_addr_t *) tcb->local_addr)) {
break;
}
}

146
sys/net/gnrc/transport_layer/tcp/gnrc_tcp_fsm.c

@ -97,7 +97,7 @@ static int _clear_retransmit(gnrc_tcp_tcb_t *tcb)
*
* @return Zero on success
*/
static int _restart_timewait_timer(gnrc_tcp_tcb_t* tcb)
static int _restart_timewait_timer(gnrc_tcp_tcb_t *tcb)
{
xtimer_remove(&tcb->tim_tout);
tcb->msg_tout.type = MSG_TYPE_TIMEWAIT;
@ -115,7 +115,7 @@ static int _restart_timewait_timer(gnrc_tcp_tcb_t* tcb)
*
* @return zero on success
*/
static int _transition_to(gnrc_tcp_tcb_t* tcb, fsm_state_t state, bool *notify_owner)
static int _transition_to(gnrc_tcp_tcb_t *tcb, fsm_state_t state, bool *notify_owner)
{
gnrc_tcp_tcb_t *iter = NULL;
uint8_t found = 0;
@ -146,16 +146,16 @@ static int _transition_to(gnrc_tcp_tcb_t* tcb, fsm_state_t state, bool *notify_o
/* Clear Adress Info */
switch (tcb->address_family) {
#ifdef MODULE_GNRC_IPV6
case AF_INET6:
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);
break;
case AF_INET6:
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);
break;
#endif
default:
DEBUG("gnrc_tcp_fsm.c : _transition_to() : Undefined Addresses\n");
break;
default:
DEBUG("gnrc_tcp_fsm.c : _transition_to() : Undefined Addresses\n");
break;
}
tcb->peer_port = PORT_UNSPEC;
@ -193,7 +193,7 @@ static int _transition_to(gnrc_tcp_tcb_t* tcb, fsm_state_t state, bool *notify_o
/* If not already active: Apped tcb but check portnumber first */
if (!found) {
/* Check if Port Number is not in use */
if (tcb->local_port != 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)) {
@ -240,7 +240,7 @@ static int _transition_to(gnrc_tcp_tcb_t* tcb, fsm_state_t state, bool *notify_o
* @return -ENOMEM Can't allocate receive buffer.
* @return -EADDRINUSE Given local port is already in use
*/
static int _fsm_call_open(gnrc_tcp_tcb_t* tcb, bool *notify_owner)
static int _fsm_call_open(gnrc_tcp_tcb_t *tcb, bool *notify_owner)
{
gnrc_pktsnip_t *out_pkt = NULL; /* Outgoing packet */
uint16_t seq_con = 0; /* Sequence number consumption (out_pkt) */
@ -251,7 +251,7 @@ static int _fsm_call_open(gnrc_tcp_tcb_t* tcb, bool *notify_owner)
if (tcb->status & STATUS_PASSIVE) {
/* Passive Open, T: CLOSED -> LISTEN */
if (_transition_to(tcb, FSM_STATE_LISTEN, notify_owner) == -ENOMEM){
if (_transition_to(tcb, FSM_STATE_LISTEN, notify_owner) == -ENOMEM) {
_transition_to(tcb, FSM_STATE_CLOSED, notify_owner);
return -ENOMEM;
}
@ -264,7 +264,7 @@ static int _fsm_call_open(gnrc_tcp_tcb_t* tcb, bool *notify_owner)
/* Translate to SYN_SENT */
ret = _transition_to(tcb, FSM_STATE_SYN_SENT, notify_owner);
if ( ret < 0) {
if (ret < 0) {
_transition_to(tcb, FSM_STATE_CLOSED, notify_owner);
return ret;
}
@ -280,13 +280,13 @@ static int _fsm_call_open(gnrc_tcp_tcb_t* tcb, bool *notify_owner)
/**
* @brief FSM Handling Function for sending data.
*
* @param[in/out] tcb Specifies tcb to use fsm on.
* @param[in/out] buf buffer containing data to send.
* @param[in] nByte Maximum Number of Bytes to send.
* @param[in/out] tcb Specifies tcb to use fsm on.
* @param[in/out] buf Buffer containing data to send.
* @param[in] len Maximum Number of Bytes to send.
*
* @return number of bytes that was sent.
*/
static int _fsm_call_send(gnrc_tcp_tcb_t* tcb, void *buf, size_t nByte)
static int _fsm_call_send(gnrc_tcp_tcb_t *tcb, void *buf, size_t len)
{
gnrc_pktsnip_t *out_pkt = NULL; /* Outgoing packet */
uint16_t seq_con = 0; /* Sequence number consumption (out_pkt) */
@ -297,9 +297,9 @@ static int _fsm_call_send(gnrc_tcp_tcb_t* tcb, void *buf, size_t nByte)
/* We are allowed to send further bytes if window is open */
if (payload > 0 && tcb->snd_wnd > 0 && tcb->pkt_retransmit == NULL) {
/* Calculate segment size */
payload = (payload < GNRC_TCP_MSS ? payload : GNRC_TCP_MSS);
payload = (payload < GNRC_TCP_MSS) ? payload : GNRC_TCP_MSS;
payload = (payload < tcb->mss) ? payload : tcb->mss;
payload = (payload < nByte) ? payload : nByte;
payload = (payload < len) ? payload : len;
/* Calculate payload size for this segment */
_pkt_build(tcb, &out_pkt, &seq_con, MSK_ACK, tcb->snd_nxt, tcb->rcv_nxt, buf, payload);
@ -313,13 +313,13 @@ static int _fsm_call_send(gnrc_tcp_tcb_t* tcb, void *buf, size_t nByte)
/**
* @brief FSM Handling Function for receiving data.
*
* @param[in/out] tcb Specifies tcb to use fsm on.
* @param[in/out] buf buffer to store received data into.
* @param[in] nByte Maximum Number of Bytes to receive.
* @param[in/out] tcb Specifies tcb to use fsm on.
* @param[in/out] buf buffer to store received data into.
* @param[in] len Maximum Number of Bytes to receive.
*
* @return number of bytes that was received.
*/
static int _fsm_call_recv(gnrc_tcp_tcb_t* tcb, void *buf, size_t nByte)
static int _fsm_call_recv(gnrc_tcp_tcb_t *tcb, void *buf, size_t len)
{
gnrc_pktsnip_t *out_pkt = NULL; /* Outgoing packet */
uint16_t seq_con = 0; /* Sequence number consumption (out_pkt) */
@ -330,14 +330,14 @@ static int _fsm_call_recv(gnrc_tcp_tcb_t* tcb, void *buf, size_t nByte)
}
/* Read up to the requesed amount of data */
size_t rcvd = ringbuffer_get(&(tcb->rcv_buf), buf, nByte);
size_t rcvd = ringbuffer_get(&(tcb->rcv_buf), buf, len);
/* If the buffer can store more than the GNRC_TCP_MSS: open Window to available buffersize */
if (ringbuffer_get_free(&tcb->rcv_buf) >= GNRC_TCP_MSS) {
tcb->rcv_wnd = ringbuffer_get_free(&(tcb->rcv_buf));
/* Send ACK to update window on reopening */
_pkt_build(tcb, &out_pkt, &seq_con, MSK_ACK, tcb->snd_nxt, tcb->rcv_nxt, 0, 0);
_pkt_build(tcb, &out_pkt, &seq_con, MSK_ACK, tcb->snd_nxt, tcb->rcv_nxt, NULL, 0);
_pkt_send(tcb, out_pkt, seq_con, false);
}
return rcvd;
@ -351,16 +351,14 @@ static int _fsm_call_recv(gnrc_tcp_tcb_t* tcb, void *buf, size_t nByte)
*
* @return zero on success.
*/
static int _fsm_call_close(gnrc_tcp_tcb_t* tcb, bool *notify_owner)
static int _fsm_call_close(gnrc_tcp_tcb_t *tcb, bool *notify_owner)
{
gnrc_pktsnip_t *out_pkt = NULL; /* Outgoing packet */
uint16_t seq_con = 0; /* Sequence number consumption (out_pkt) */
DEBUG("gnrc_tcp_fsm.c : _fsm_call_close()\n");
if (tcb->state == FSM_STATE_SYN_RCVD
|| tcb->state == FSM_STATE_ESTABLISHED
|| tcb->state == FSM_STATE_CLOSE_WAIT
) {
if (tcb->state == FSM_STATE_SYN_RCVD || tcb->state == FSM_STATE_ESTABLISHED ||
tcb->state == FSM_STATE_CLOSE_WAIT) {
/* Send FIN packet */
_pkt_build(tcb, &out_pkt, &seq_con, MSK_FIN_ACK, tcb->snd_nxt, tcb->rcv_nxt, NULL, 0);
_pkt_setup_retransmit(tcb, out_pkt, false);
@ -408,7 +406,7 @@ static int _fsm_call_abort(void)
* @return zero on success.
* @return -ENOMEM Can't allocate receive buffer.
*/
static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *in_pkt, bool *notify_owner)
static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t *tcb, gnrc_pktsnip_t *in_pkt, bool *notify_owner)
{
gnrc_pktsnip_t *out_pkt = NULL; /* Outgoing packet */
uint16_t seq_con = 0; /* Sequence number consumption (out_pkt) */
@ -475,9 +473,8 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *in_pkt, bool *noti
ipv6_addr_t *dst_addr = &((ipv6_hdr_t *)ip)->dst;
ipv6_addr_t *src_addr = &((ipv6_hdr_t *)ip)->src;
if (ipv6_addr_equal((ipv6_addr_t *)lst->local_addr, dst_addr)
&& ipv6_addr_equal((ipv6_addr_t *)lst->peer_addr, src_addr)
) {
if (ipv6_addr_equal((ipv6_addr_t *)lst->local_addr, dst_addr) &&
ipv6_addr_equal((ipv6_addr_t *)lst->peer_addr, src_addr)) {
break;
}
}
@ -563,15 +560,13 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *in_pkt, bool *noti
/* SYN has been ACKed, reply pure ACK, T: SYN_SENT -> ESTABLISHED */
if (tcb->snd_una > tcb->iss) {
_pkt_build(tcb, &out_pkt, &seq_con, MSK_ACK, tcb->snd_nxt, tcb->rcv_nxt,
NULL, 0);
_pkt_build(tcb, &out_pkt, &seq_con, MSK_ACK, tcb->snd_nxt, tcb->rcv_nxt, NULL, 0);
_pkt_send(tcb, out_pkt, seq_con, false);
_transition_to(tcb, FSM_STATE_ESTABLISHED, notify_owner);
}
/* Simultaneous SYN received send SYN+ACK, T: SYN_SENT -> SYN_RCVD */
else {
_pkt_build(tcb, &out_pkt, &seq_con, MSK_SYN_ACK, tcb->iss, tcb->rcv_nxt,
NULL, 0);
_pkt_build(tcb, &out_pkt, &seq_con, MSK_SYN_ACK, tcb->iss, tcb->rcv_nxt, NULL, 0);
_pkt_setup_retransmit(tcb, out_pkt, false);
_pkt_send(tcb, out_pkt, seq_con, false);
_transition_to(tcb, FSM_STATE_SYN_RCVD, notify_owner);
@ -590,8 +585,7 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *in_pkt, bool *noti
if (!_pkt_chk_seq_num(tcb, seg_seq, pay_len)) {
/* ... if invalid, and RST not set, reply with pure ACK, return */
if ((ctl & MSK_RST) != MSK_RST) {
_pkt_build(tcb, &out_pkt, &seq_con, MSK_ACK, tcb->snd_nxt, tcb->rcv_nxt,
NULL, 0);
_pkt_build(tcb, &out_pkt, &seq_con, MSK_ACK, tcb->snd_nxt, tcb->rcv_nxt, NULL, 0);
_pkt_send(tcb, out_pkt, seq_con, false);
}
return 0;
@ -599,9 +593,7 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *in_pkt, bool *noti
/* 2) Check RST: If RST is set ... */
if (ctl & MSK_RST) {
/* .. and State is SYN_RCVD and passive Open: SYN_RCVD -> LISTEN */
if (tcb->state == FSM_STATE_SYN_RCVD
&& (tcb->status & STATUS_PASSIVE)
) {
if (tcb->state == FSM_STATE_SYN_RCVD && (tcb->status & STATUS_PASSIVE)) {
if (_transition_to(tcb, FSM_STATE_LISTEN, notify_owner) == -ENOMEM) {
_transition_to(tcb, FSM_STATE_CLOSED, notify_owner);
return -ENOMEM;
@ -638,13 +630,9 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *in_pkt, bool *noti
}
}
/* Acknowledgment processing */
if (tcb->state == FSM_STATE_ESTABLISHED
|| tcb->state == FSM_STATE_FIN_WAIT_1
|| tcb->state == FSM_STATE_FIN_WAIT_2
|| tcb->state == FSM_STATE_CLOSE_WAIT
|| tcb->state == FSM_STATE_CLOSING
|| tcb->state == FSM_STATE_LAST_ACK
) {
if (tcb->state == FSM_STATE_ESTABLISHED || tcb->state == FSM_STATE_FIN_WAIT_1 ||
tcb->state == FSM_STATE_FIN_WAIT_2 || tcb->state == FSM_STATE_CLOSE_WAIT ||
tcb->state == FSM_STATE_CLOSING || tcb->state == FSM_STATE_LAST_ACK) {
/* Sent data has been acknowledged */
if (LSS_32_BIT(tcb->snd_una, seg_ack) && LEQ_32_BIT(seg_ack, tcb->snd_nxt)) {
tcb->snd_una = seg_ack;
@ -659,9 +647,8 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *in_pkt, bool *noti
}
/* Update Window */
if (LEQ_32_BIT(tcb->snd_una, seg_ack) && LEQ_32_BIT(seg_ack, tcb->snd_nxt)) {
if (LSS_32_BIT(tcb->snd_wl1, seg_seq) || (tcb->snd_wl1 == seg_seq
&& LEQ_32_BIT(tcb->snd_wl2, seg_ack))
) {
if (LSS_32_BIT(tcb->snd_wl1, seg_seq) || (tcb->snd_wl1 == seg_seq &&
LEQ_32_BIT(tcb->snd_wl2, seg_ack))) {
tcb->snd_wnd = seg_wnd;
tcb->snd_wl1 = seg_seq;
tcb->snd_wl2 = seg_ack;
@ -703,10 +690,8 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *in_pkt, bool *noti
/* 6) Process Payload, if existing */
if (pay_len > 0) {
/* Check if State is valid */
if (tcb->state == FSM_STATE_ESTABLISHED
|| tcb->state == FSM_STATE_FIN_WAIT_1
|| tcb->state == FSM_STATE_FIN_WAIT_2
) {
if (tcb->state == FSM_STATE_ESTABLISHED || tcb->state == FSM_STATE_FIN_WAIT_1 ||
tcb->state == FSM_STATE_FIN_WAIT_2) {
/* Search for begin of payload "chain" */
LL_SEARCH_SCALAR(in_pkt, snp, type, GNRC_NETTYPE_UNDEF);
@ -733,10 +718,8 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *in_pkt, bool *noti
}
/* 7) Check FIN */
if (ctl & MSK_FIN) {
if (tcb->state == FSM_STATE_CLOSED
|| tcb->state == FSM_STATE_LISTEN
|| tcb->state == FSM_STATE_SYN_SENT
) {
if (tcb->state == FSM_STATE_CLOSED || tcb->state == FSM_STATE_LISTEN ||
tcb->state == FSM_STATE_SYN_SENT) {
return 0;
}
/* Advance rcv_nxt over FIN bit. */
@ -744,9 +727,7 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *in_pkt, bool *noti
_pkt_build(tcb, &out_pkt, &seq_con, MSK_ACK, tcb->snd_nxt, tcb->rcv_nxt, NULL, 0);
_pkt_send(tcb, out_pkt, seq_con, false);
if (tcb->state == FSM_STATE_SYN_RCVD
|| tcb->state == FSM_STATE_ESTABLISHED
) {
if (tcb->state == FSM_STATE_SYN_RCVD || tcb->state == FSM_STATE_ESTABLISHED) {
_transition_to(tcb, FSM_STATE_CLOSE_WAIT, notify_owner);
}
else if (tcb->state == FSM_STATE_FIN_WAIT_1) {
@ -776,7 +757,7 @@ static int _fsm_rcvd_pkt(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *in_pkt, bool *noti
*
* @return zero on success.
*/
static int _fsm_timeout_timewait(gnrc_tcp_tcb_t* tcb, bool *notify_owner)
static int _fsm_timeout_timewait(gnrc_tcp_tcb_t *tcb, bool *notify_owner)
{
DEBUG("gnrc_tcp_fsm.c : _fsm_timeout_timewait()\n");
_transition_to(tcb, FSM_STATE_CLOSED, notify_owner);
@ -790,10 +771,10 @@ static int _fsm_timeout_timewait(gnrc_tcp_tcb_t* tcb, bool *notify_owner)
*
* @return zero on success.
*/
static int _fsm_timeout_retransmit(gnrc_tcp_tcb_t* tcb)
static int _fsm_timeout_retransmit(gnrc_tcp_tcb_t *tcb)
{
DEBUG("gnrc_tcp_fsm.c : _fsm_timeout_retransmit()\n");
if(tcb->pkt_retransmit != NULL){
if (tcb->pkt_retransmit != NULL) {
_pkt_setup_retransmit(tcb, tcb->pkt_retransmit, true);
_pkt_send(tcb, tcb->pkt_retransmit, 0, true);
}
@ -811,7 +792,7 @@ static int _fsm_timeout_retransmit(gnrc_tcp_tcb_t* tcb)
*
* @return zero on success.
*/
static int _fsm_timeout_connection(gnrc_tcp_tcb_t* tcb, bool *notify_owner)
static int _fsm_timeout_connection(gnrc_tcp_tcb_t *tcb, bool *notify_owner)
{
DEBUG("gnrc_tcp_fsm.c : _fsm_timeout_connection()\n");
_transition_to(tcb, FSM_STATE_CLOSED, notify_owner);
@ -825,10 +806,10 @@ static int _fsm_timeout_connection(gnrc_tcp_tcb_t* tcb, bool *notify_owner)
*
* @return zero on success.
*/
static int _fsm_send_probe(gnrc_tcp_tcb_t* tcb)
static int _fsm_send_probe(gnrc_tcp_tcb_t *tcb)
{
gnrc_pktsnip_t *out_pkt = NULL; /* Outgoing packet */
uint8_t probe_pay[] = { 1 }; /* Probe Payload */
uint8_t probe_pay[] = {1}; /* Probe Payload */
DEBUG("gnrc_tcp_fsm.c : _fsm_send_probe()\n");
/* The Probe sends a already acknowledged Sequence No. with a garbage byte */
@ -845,7 +826,7 @@ static int _fsm_send_probe(gnrc_tcp_tcb_t* tcb)
*
* @return zero on success.
*/
static int _fsm_clear_retransmit(gnrc_tcp_tcb_t* tcb)
static int _fsm_clear_retransmit(gnrc_tcp_tcb_t *tcb)
{
DEBUG("gnrc_tcp_fsm.c : _fsm_clear_retransmit()\n");
_clear_retransmit(tcb);
@ -859,18 +840,18 @@ static int _fsm_clear_retransmit(gnrc_tcp_tcb_t* tcb)
* @param[in] event current event that triggers fsm translation
* @param[in] in_pkt packet that triggered fsm event. Only in case of RCVD_PKT
* @param[in/out] buf buffer for send and receive functions
* @param[in] nByte number of bytes to send or receive atmost
* @param[in] len number of bytes to send or receive atmost
* @param[out] notify_owner non-negative if the tcb owner should be notified
*
* @return TODO zero on success
* @return Zero on success
* @return -ENOMEM Can't allocate receive buffer.
* @return -EADDRINUSE Given local port is already in use
* @return -EOPNOTSUPP If event is not implemented
*/
static int _fsm_unprotected(gnrc_tcp_tcb_t* tcb, fsm_event_t event,
gnrc_pktsnip_t *in_pkt, void *buf, size_t nByte, bool *notify_owner)
static int _fsm_unprotected(gnrc_tcp_tcb_t *tcb, fsm_event_t event, gnrc_pktsnip_t *in_pkt,
void *buf, size_t len, bool *notify_owner)
{
int ret = 0; /* Return Value */
int ret = 0;
DEBUG("gnrc_tcp_fsm.c : _fsm_unprotected()\n");
switch (event) {
@ -878,10 +859,10 @@ static int _fsm_unprotected(gnrc_tcp_tcb_t* tcb, fsm_event_t event,
ret = _fsm_call_open(tcb, notify_owner);
break;
case FSM_EVENT_CALL_SEND :
ret = _fsm_call_send(tcb, buf, nByte);
ret = _fsm_call_send(tcb, buf, len);
break;
case FSM_EVENT_CALL_RECV :
ret = _fsm_call_recv(tcb, buf, nByte);
ret = _fsm_call_recv(tcb, buf, len);
break;
case FSM_EVENT_CALL_CLOSE :
ret = _fsm_call_close(tcb, notify_owner);
@ -911,8 +892,7 @@ static int _fsm_unprotected(gnrc_tcp_tcb_t* tcb, fsm_event_t event,
return ret;
}
int _fsm(gnrc_tcp_tcb_t* tcb, fsm_event_t event, gnrc_pktsnip_t *in_pkt, void *buf,
size_t nByte)
int _fsm(gnrc_tcp_tcb_t *tcb, fsm_event_t event, gnrc_pktsnip_t *in_pkt, void *buf, size_t len)
{
msg_t msg;
int32_t result;
@ -921,7 +901,7 @@ int _fsm(gnrc_tcp_tcb_t* tcb, fsm_event_t event, gnrc_pktsnip_t *in_pkt, void *b
/* Lock FSM */
mutex_lock(&(tcb->fsm_lock));
notify_owner = false;
result = _fsm_unprotected(tcb, event, in_pkt, buf, nByte, &notify_owner);
result = _fsm_unprotected(tcb, event, in_pkt, buf, len, &notify_owner);
/* Notify owner if something interesting happend */
if (notify_owner && tcb->owner != KERNEL_PID_UNDEF) {

14
sys/net/gnrc/transport_layer/tcp/gnrc_tcp_option.c

@ -16,25 +16,13 @@
* @author Simon Brummer <simon.brummer@posteo.de>
* @}
*/
#include "assert.h"
#include "internal/common.h"
#include "internal/option.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
uint32_t _option_build_mss(uint16_t mss)
{
return (uint32_t) ((TCP_OPTION_KIND_MSS << 24) | (TCP_OPTION_LENGTH_MSS << 16) | mss);
}
uint16_t _option_build_offset_control(uint16_t nopts, uint16_t ctl)
{
assert(TCP_HDR_OFFSET_MIN <= nopts && nopts <= TCP_HDR_OFFSET_MAX);
return (nopts << 12) | ctl;
}
int _option_parse(gnrc_tcp_tcb_t* tcb, tcp_hdr_t *hdr)
int _option_parse(gnrc_tcp_tcb_t *tcb, tcp_hdr_t *hdr)
{
/* Extract Offset value. Return if no options are set */
uint8_t offset = GET_OFFSET(byteorder_ntohs(hdr->off_ctl));

46
sys/net/gnrc/transport_layer/tcp/gnrc_tcp_pkt.c

@ -113,7 +113,7 @@ int _pkt_build_reset_from_pkt(gnrc_pktsnip_t **out_pkt, gnrc_pktsnip_t *in_pkt)
return 0;
}
int _pkt_build(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t **out_pkt, uint16_t *seq_con,
int _pkt_build(gnrc_tcp_tcb_t *tcb, gnrc_pktsnip_t **out_pkt, uint16_t *seq_con,
const uint16_t ctl, const uint32_t seq_num, const uint32_t ack_num,
void *payload, const size_t payload_len)
{
@ -160,7 +160,7 @@ int _pkt_build(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t **out_pkt, uint16_t *seq_con,
else {
/* Add options if existing */
if (TCP_HDR_OFFSET_MIN < offset) {
uint8_t* opt_ptr = (uint8_t *) tcp_snp->data + sizeof(tcp_hdr);
uint8_t *opt_ptr = (uint8_t *) tcp_snp->data + sizeof(tcp_hdr);
uint8_t opt_left = (offset - TCP_HDR_OFFSET_MIN) * sizeof(network_uint32_t);
/* Init options field with 'End Of List' - option (0) */
@ -179,7 +179,7 @@ int _pkt_build(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t **out_pkt, uint16_t *seq_con,
/* Build network layer header */
#ifdef MODULE_GNRC_IPV6
gnrc_pktsnip_t* ip6_snp = gnrc_ipv6_hdr_build(tcp_snp, NULL, (ipv6_addr_t *) tcb->peer_addr);
gnrc_pktsnip_t *ip6_snp = gnrc_ipv6_hdr_build(tcp_snp, NULL, (ipv6_addr_t *) tcb->peer_addr);
if (ip6_snp == NULL) {
DEBUG("gnrc_tcp_pkt.c : _pkt_build() : Can't allocate buffer for IPv6 Header.\n");
gnrc_pktbuf_release(tcp_snp);
@ -189,7 +189,7 @@ int _pkt_build(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t **out_pkt, uint16_t *seq_con,
else {
*(out_pkt) = ip6_snp;
}
#else
#else
DEBUG("gnrc_tcp_pkt.c : _pkt_build_reset_from_pkt() : Network Layer Module Missing\n");
#endif
@ -207,7 +207,7 @@ int _pkt_build(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t **out_pkt, uint16_t *seq_con,
return 0;
}
int _pkt_send(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *out_pkt, const uint16_t seq_con,
int _pkt_send(gnrc_tcp_tcb_t *tcb, gnrc_pktsnip_t *out_pkt, const uint16_t seq_con,
const bool retransmit)
{
if (out_pkt == NULL) {
@ -230,7 +230,7 @@ int _pkt_send(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *out_pkt, const uint16_t seq_c
return 0;
}
int _pkt_chk_seq_num(const gnrc_tcp_tcb_t* tcb, const uint32_t seq_num, const uint32_t seg_len)
int _pkt_chk_seq_num(const gnrc_tcp_tcb_t *tcb, const uint32_t seq_num, const uint32_t seg_len)
{
uint32_t l_edge = tcb->rcv_nxt;
uint32_t r_edge = tcb->rcv_nxt + tcb->rcv_wnd;
@ -239,7 +239,7 @@ int _pkt_chk_seq_num(const gnrc_tcp_tcb_t* tcb, const uint32_t seq_num, const ui
/* Possible case 1 */
/* Segment contains no payload and Receive window is closed and */
/* Sequence Number is next expected number */
if (seg_len == 0 && tcb->rcv_wnd == 0 && l_edge == seq_num ) {
if (seg_len == 0 && tcb->rcv_wnd == 0 && l_edge == seq_num) {
return 1;
}
@ -253,9 +253,8 @@ int _pkt_chk_seq_num(const gnrc_tcp_tcb_t* tcb, const uint32_t seq_num, const ui
/* Possible case 3 */
/* Segment contains Payload and Receive window is open and */
/* Sequence Number overlaps with receive window */
if (seg_len > 0 && tcb->rcv_wnd > 0
&& (INSIDE_WND(l_edge, seq_num, r_edge) || INSIDE_WND(l_edge, last_seq, r_edge))
) {
if (seg_len > 0 && tcb->rcv_wnd > 0 && (INSIDE_WND(l_edge, seq_num, r_edge) ||
INSIDE_WND(l_edge, last_seq, r_edge))) {
return 1;
}
@ -295,7 +294,7 @@ uint32_t _pkt_get_pay_len(gnrc_pktsnip_t *pkt)
return seg_len;
}
int _pkt_setup_retransmit(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *pkt, const bool retransmit)
int _pkt_setup_retransmit(gnrc_tcp_tcb_t *tcb, gnrc_pktsnip_t *pkt, const bool retransmit)
{
gnrc_pktsnip_t *snp = NULL;
uint32_t ctl = 0;
@ -359,12 +358,12 @@ 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;
tcb->msg_tout.content.ptr = (void *) tcb;
xtimer_set_msg(&tcb->tim_tout, tcb->rto, &tcb->msg_tout, gnrc_tcp_pid);
return 0;
}
int _pkt_acknowledge(gnrc_tcp_tcb_t* tcb, const uint32_t ack)
int _pkt_acknowledge(gnrc_tcp_tcb_t *tcb, const uint32_t ack)
{
uint32_t seg = 0;
gnrc_pktsnip_t *snp = NULL;
@ -394,32 +393,29 @@ 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 == RTO_UNINITIALIZED
&& tcb->rtt_var == RTO_UNINITIALIZED
) {
if (tcb->srtt == RTO_UNINITIALIZED && tcb->rtt_var == RTO_UNINITIALIZED) {
tcb->srtt = rtt;
tcb->rtt_var = (rtt >> 1);
}
/* If this is a subsequent sample */
else {
tcb->rtt_var = (tcb->rtt_var / GNRC_TCP_RTO_B_DIV) * (GNRC_TCP_RTO_B_DIV-1);
tcb->rtt_var += abs(tcb->srtt - rtt) / GNRC_TCP_RTO_B_DIV;
tcb->srtt = (tcb->srtt / GNRC_TCP_RTO_A_DIV) * (GNRC_TCP_RTO_A_DIV-1);
tcb->srtt += rtt / GNRC_TCP_RTO_A_DIV;
tcb->rtt_var = (tcb->rtt_var / GNRC_TCP_RTO_B_DIV) * (GNRC_TCP_RTO_B_DIV-1);
tcb->rtt_var += abs(tcb->srtt - rtt) / GNRC_TCP_RTO_B_DIV;
tcb->srtt = (tcb->srtt / GNRC_TCP_RTO_A_DIV) * (GNRC_TCP_RTO_A_DIV-1);
tcb->srtt += rtt / GNRC_TCP_RTO_A_DIV;
}
}
}
return 0;
}
uint16_t _pkt_calc_csum(const gnrc_pktsnip_t *hdr,
const gnrc_pktsnip_t *pseudo_hdr,
uint16_t _pkt_calc_csum(const gnrc_pktsnip_t *hdr, const gnrc_pktsnip_t *pseudo_hdr,
const gnrc_pktsnip_t *payload)
{
uint16_t csum = 0;
uint16_t len = (uint16_t) hdr->size;
if(pseudo_hdr == NULL) {
if (pseudo_hdr == NULL) {
return 0;
}
@ -431,9 +427,9 @@ uint16_t _pkt_calc_csum(const gnrc_pktsnip_t *hdr,
}
/* Process tcp-header, before checksum field(Byte 16 to 18) */
csum = inet_csum(csum, (uint8_t *)hdr->data, 16);
csum = inet_csum(csum, (uint8_t *) hdr->data, 16);
/* Process tcp-header, after checksum field */
csum = inet_csum(csum, ((uint8_t *)hdr->data) + 18, hdr->size - 18);
csum = inet_csum(csum, ((uint8_t *) hdr->data) + 18, hdr->size - 18);
/* Process Network layer Header */
switch (pseudo_hdr->type) {

10
sys/net/gnrc/transport_layer/tcp/gnrc_tcp_rcvbuf.c

@ -27,7 +27,7 @@ void _rcvbuf_init(void)
{
DEBUG("gnrc_tcp_rcvbuf.c : _rcvbuf_init() : Entry\n");
mutex_init(&(_static_buf.lock));
for (int i=0; i<GNRC_TCP_RCV_BUFFERS; i++) {
for (size_t i = 0; i < GNRC_TCP_RCV_BUFFERS; ++i) {
_static_buf.entries[i].used = 0;
}
}
@ -37,7 +37,7 @@ static void* _rcvbuf_alloc(void)
void *result = NULL;
DEBUG("gnrc_tcp_rcvbuf.c : _rcvbuf_alloc() : Entry\n");
mutex_lock(&(_static_buf.lock));
for (int i=0; i<GNRC_TCP_RCV_BUFFERS; i++) {
for (size_t i = 0; i < GNRC_TCP_RCV_BUFFERS; ++i) {
if (_static_buf.entries[i].used == 0) {
_static_buf.entries[i].used = 1;
result = (void *)(_static_buf.entries[i].buffer);
@ -52,7 +52,7 @@ static void _rcvbuf_free(void * const buf)
{
DEBUG("gnrc_tcp_rcvbuf.c : _rcvbuf_free() : Entry\n");
mutex_lock(&(_static_buf.lock));
for (int i=0; i<GNRC_TCP_RCV_BUFFERS; i++) {
for (size_t i = 0; i < GNRC_TCP_RCV_BUFFERS; ++i) {
if (_static_buf.entries[i].used == 1 && buf == _static_buf.entries[i].buffer) {
_static_buf.entries[i].used = 0;
}
@ -60,7 +60,7 @@ static void _rcvbuf_free(void * const buf)
mutex_unlock(&(_static_buf.lock));
}
int _rcvbuf_get_buffer(gnrc_tcp_tcb_t* tcb)
int _rcvbuf_get_buffer(gnrc_tcp_tcb_t *tcb)
{
if (tcb->rcv_buf_raw == NULL) {
tcb->rcv_buf_raw = _rcvbuf_alloc();
@ -75,7 +75,7 @@ int _rcvbuf_get_buffer(gnrc_tcp_tcb_t* tcb)
return 0;
}
void _rcvbuf_release_buffer(gnrc_tcp_tcb_t* tcb)
void _rcvbuf_release_buffer(gnrc_tcp_tcb_t *tcb)
{
if (tcb->rcv_buf_raw != NULL) {
_rcvbuf_free(tcb->rcv_buf_raw);

13
sys/net/gnrc/transport_layer/tcp/internal/fsm.h

@ -68,18 +68,17 @@ typedef enum {
/**
* @brief TCP finite state maschine
*
* @param[in,out] tcb specifies connection to use fsm on.
* @param[in] event current event that triggers fsm translation
* @param[in] in_pkt packet that triggered fsm event. Only in case of RCVD_PKT
* @param[in,out] buf buffer for send and receive functions
* @param[in] nByte number of bytes to send or receive atmost
* @param[in,out] tcb specifies connection to use fsm on.
* @param[in] event current event that triggers fsm translation
* @param[in] in_pkt packet that triggered fsm event. Only in case of RCVD_PKT
* @param[in,out] buf buffer for send and receive functions
* @param[in] len number of bytes to send or receive atmost
*
* @return Zero on success
* @return Positive Number, number of bytes sent from or copied into buf.
* @return -ENOSYS if event is not implemented
*/
int _fsm(gnrc_tcp_tcb_t* tcb, fsm_event_t event, gnrc_pktsnip_t *in_pkt, void *buf,
size_t nByte);
int _fsm(gnrc_tcp_tcb_t *tcb, fsm_event_t event, gnrc_pktsnip_t *in_pkt, void *buf, size_t len);
#ifdef __cplusplus
}

15
sys/net/gnrc/transport_layer/tcp/internal/option.h

@ -22,6 +22,7 @@
#ifndef GNRC_TCP_INTERNAL_OPTION_H
#define GNRC_TCP_INTERNAL_OPTION_H
#include "assert.h"
#include "net/tcp.h"
#include "net/gnrc/tcp.h"
@ -36,7 +37,11 @@ extern "C" {
*
* @return Valid MSS Option.
*/
uint32_t _option_build_mss(uint16_t mss);
inline static uint32_t _option_build_mss(uint16_t mss)
{
return (((uint32_t) TCP_OPTION_KIND_MSS << 24) |
((uint32_t) TCP_OPTION_LENGTH_MSS << 16) | mss);
}
/**
* @brief Helper Function to build the combined option and control flag field
@ -46,7 +51,11 @@ uint32_t _option_build_mss(uint16_t mss);
*
* @return Valid option size and control field.
*/
uint16_t _option_build_offset_control(uint16_t nopts, uint16_t ctl);
inline static uint16_t _option_build_offset_control(uint16_t nopts, uint16_t ctl)
{
assert(TCP_HDR_OFFSET_MIN <= nopts && nopts <= TCP_HDR_OFFSET_MAX);
return (nopts << 12) | ctl;
}
/**
* @brief Parses options of a given tcp-header pktsnip.
@ -57,7 +66,7 @@ uint16_t _option_build_offset_control(uint16_t nopts, uint16_t ctl);
* @return Zero on success
* @return A negative value on error
*/
int _option_parse(gnrc_tcp_tcb_t* tcb, tcp_hdr_t *hdr);
int _option_parse(gnrc_tcp_tcb_t *tcb, tcp_hdr_t *hdr);
#ifdef __cplusplus
}

10
sys/net/gnrc/transport_layer/tcp/internal/pkt.h

@ -57,7 +57,7 @@ int _pkt_build_reset_from_pkt(gnrc_pktsnip_t **out_pkt, gnrc_pktsnip_t *in_pkt);
* @return Zero on success.
* @return -ENOMEM if pktbuf is full.
*/
int _pkt_build(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t **out_pkt, uint16_t *seq_con,
int _pkt_build(gnrc_tcp_tcb_t *tcb, gnrc_pktsnip_t **out_pkt, uint16_t *seq_con,
const uint16_t ctl, const uint32_t seq_num, const uint32_t ack_num,
void *payload, const size_t payload_len);
@ -72,7 +72,7 @@ int _pkt_build(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t **out_pkt, uint16_t *seq_con,
* @return Zero on success.
* @return -EINVAL if out_pkt was NULL
*/
int _pkt_send(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *out_pkt, const uint16_t seq_con,
int _pkt_send(gnrc_tcp_tcb_t *tcb, gnrc_pktsnip_t *out_pkt, const uint16_t seq_con,
const bool retransmit);
/**
@ -85,7 +85,7 @@ int _pkt_send(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *out_pkt, const uint16_t seq_c
* @return Zero if the sequence number is invalid
* @return Non-zero if the sequence number is acceptable
*/
int _pkt_chk_seq_num(const gnrc_tcp_tcb_t* tcb, const uint32_t seq_num, const uint32_t seg_len);
int _pkt_chk_seq_num(const gnrc_tcp_tcb_t *tcb, const uint32_t seq_num, const uint32_t seg_len);
/**
* @brief Extracts the length of a segment
@ -116,7 +116,7 @@ uint32_t _pkt_get_pay_len(gnrc_pktsnip_t *pkt);
* @return -ENOMEM if the retransmission queue is full
* @return -EINVAL if pkt is null
*/
int _pkt_setup_retransmit(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *pkt, const bool retransmit);
int _pkt_setup_retransmit(gnrc_tcp_tcb_t *tcb, gnrc_pktsnip_t *pkt, const bool retransmit);
/**
* @brief Acknowledges and removes packet from the retransmission mechanism
@ -127,7 +127,7 @@ int _pkt_setup_retransmit(gnrc_tcp_tcb_t* tcb, gnrc_pktsnip_t *pkt, const bool r
* @return Zero on success
* @return -ENODATA if there is nothing to acknowledge
*/
int _pkt_acknowledge(gnrc_tcp_tcb_t* tcb, const uint32_t ack);
int _pkt_acknowledge(gnrc_tcp_tcb_t *tcb, const uint32_t ack);
/**
* @brief Calculates checksum over payload, tcp-header and network layer header

4
sys/net/gnrc/transport_layer/tcp/internal/rcvbuf.h

@ -64,14 +64,14 @@ void _rcvbuf_init(void);
* @return zero on success
* @return -ENOMEM If receive buffer is out of memory.
*/
int _rcvbuf_get_buffer(gnrc_tcp_tcb_t* tcb);
int _rcvbuf_get_buffer(gnrc_tcp_tcb_t *tcb);
/**
* @brief Free allocated receive buffer
*
* @param[in] tcb Transmission control block that buffer should be freed.
*/
void _rcvbuf_release_buffer(gnrc_tcp_tcb_t* tcb);
void _rcvbuf_release_buffer(gnrc_tcp_tcb_t *tcb);
#ifdef __cplusplus
}

18
tests/gnrc_tcp_client/main.c

@ -17,7 +17,7 @@
/* Number of possible parallel connections */
#ifndef CONNS
#define CONNS 1
#define CONNS (1)
#endif
/* Amount of data to transmit */
@ -47,10 +47,9 @@ int main(void)
/* Start Connection Handling Threads */
for (int i = 0; i < CONNS; i += 1) {
thread_create((char *)stacks[i], sizeof(stacks[i]), THREAD_PRIORITY_MAIN, 0, cli_thread,
(void *)i, NULL);
thread_create((char *) stacks[i], sizeof(stacks[i]), THREAD_PRIORITY_MAIN, 0, cli_thread,
(void *) i, NULL);
}
return 0;
}
@ -112,8 +111,7 @@ void *cli_thread(void *arg)
return 0;
case -ETIMEDOUT:
printf("TID=%d : gnrc_tcp_open_active() : -ETIMEDOUT : retry after 10sec\n",
tid);
printf("TID=%d : gnrc_tcp_open_active() : -ETIMEDOUT : retry after 10sec\n", tid);
xtimer_sleep(10);
continue;
@ -123,7 +121,7 @@ void *cli_thread(void *arg)
}
/* Fill Buffer with a test pattern */
for (size_t i=0; i < sizeof(bufs[tid]); ++i){
for (size_t i = 0; i < sizeof(bufs[tid]); ++i){
bufs[tid][i] = TEST_PATERN_CLI;
}
@ -160,7 +158,7 @@ void *cli_thread(void *arg)
/* Receive Data, stop if errors were found */
for (size_t rcvd = 0; rcvd < sizeof(bufs[tid]) && ret >= 0; rcvd += ret) {
ret = gnrc_tcp_recv(&tcb, (void *)(bufs[tid] + rcvd), sizeof(bufs[tid]) - rcvd,
ret = gnrc_tcp_recv(&tcb, (void *) (bufs[tid] + rcvd), sizeof(bufs[tid]) - rcvd,
GNRC_TCP_CONNECTION_TIMEOUT_DURATION);
switch (ret) {
case -ENOTCONN:
@ -197,7 +195,7 @@ void *cli_thread(void *arg)
}
/* If there was no error: Check received pattern */
for (size_t i=0; i < sizeof(bufs[tid]); ++i) {
for (size_t i = 0; i < sizeof(bufs[tid]); ++i) {
if (bufs[tid][i] != TEST_PATERN_SRV) {
printf("TID=%d : Payload verfication failed\n", tid);
failed_payload_verifications += 1;
@ -210,7 +208,7 @@ void *cli_thread(void *arg)
/* Gather Data */
cycles += 1;
if(ret >= 0) {
if (ret >= 0) {
cycles_ok += 1;
}
printf("TID=%d : %"PRIi32" test cycles completed. %"PRIi32" ok, %"PRIi32" faulty",

16
tests/gnrc_tcp_server/main.c

@ -17,7 +17,7 @@
/* Number of possible parallel connections */
#ifndef CONNS
#define CONNS 1
#define CONNS (1)
#endif
/* Amount of data to transmit */
@ -54,15 +54,15 @@ int main(void)
/* Start Threads to handle each connection */
for (int i = 0; i < CONNS; i += 1) {
thread_create((char *)stacks[i], sizeof(stacks[i]), THREAD_PRIORITY_MAIN, 0, srv_thread,
(void *)i, NULL);
thread_create((char *) stacks[i], sizeof(stacks[i]), THREAD_PRIORITY_MAIN, 0, srv_thread,
(void *) i, NULL);
}
return 0;
}
void *srv_thread(void *arg)
{
int tid = (int)arg;
int tid =