mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
ba3088c4bd
into separate patch files
386 lines
13 KiB
Diff
386 lines
13 KiB
Diff
*** stock_iot-lab_M3/openwsn/04-TRAN/opentcp.c Thu Apr 24 11:01:36 2014
|
|
--- riot-openwsn-wip/openwsn/04-TRAN/opentcp.c Thu Apr 24 16:55:54 2014
|
|
***************
|
|
*** 4,10 ****
|
|
#include "openqueue.h"
|
|
#include "forwarding.h"
|
|
#include "packetfunctions.h"
|
|
! #include "bsp_timer.h"
|
|
#include "scheduler.h"
|
|
#include "opentimers.h"
|
|
//TCP applications
|
|
--- 4,10 ----
|
|
#include "openqueue.h"
|
|
#include "forwarding.h"
|
|
#include "packetfunctions.h"
|
|
! //#include "bsp_timer.h"
|
|
#include "scheduler.h"
|
|
#include "opentimers.h"
|
|
//TCP applications
|
|
***************
|
|
*** 13,53 ****
|
|
#include "tcpinject.h"
|
|
#include "tcpprint.h"
|
|
|
|
! //=========================== variables =======================================
|
|
|
|
! typedef struct {
|
|
! uint8_t state;
|
|
! uint32_t mySeqNum;
|
|
! uint16_t myPort;
|
|
! uint32_t hisNextSeqNum;
|
|
! uint16_t hisPort;
|
|
! open_addr_t hisIPv6Address;
|
|
! OpenQueueEntry_t* dataToSend;
|
|
! OpenQueueEntry_t* dataReceived;
|
|
! bool timerStarted;
|
|
! opentimer_id_t timerId;
|
|
! } tcp_vars_t;
|
|
|
|
tcp_vars_t tcp_vars;
|
|
|
|
//=========================== prototypes ======================================
|
|
|
|
void prependTCPHeader(OpenQueueEntry_t* msg, bool ack, bool push, bool rst, bool syn, bool fin);
|
|
bool containsControlBits(OpenQueueEntry_t* msg, uint8_t ack, uint8_t rst, uint8_t syn, uint8_t fin);
|
|
void tcp_change_state(uint8_t new_state);
|
|
! void reset();
|
|
! void opentcp_timer_cb();
|
|
|
|
//=========================== public ==========================================
|
|
|
|
! void opentcp_init() {
|
|
// reset local variables
|
|
memset(&tcp_vars,0,sizeof(tcp_vars_t));
|
|
// reset state machine
|
|
! reset();
|
|
}
|
|
|
|
! error_t opentcp_connect(open_addr_t* dest, uint16_t param_tcp_hisPort, uint16_t param_tcp_myPort) {
|
|
//[command] establishment
|
|
OpenQueueEntry_t* tempPkt;
|
|
if (tcp_vars.state!=TCP_STATE_CLOSED) {
|
|
--- 13,43 ----
|
|
#include "tcpinject.h"
|
|
#include "tcpprint.h"
|
|
|
|
! #include "thread.h"
|
|
|
|
! //=========================== variables =======================================
|
|
|
|
tcp_vars_t tcp_vars;
|
|
+ //static char openwsn_opentcp_stack[KERNEL_CONF_STACKSIZE_MAIN];
|
|
|
|
//=========================== prototypes ======================================
|
|
|
|
void prependTCPHeader(OpenQueueEntry_t* msg, bool ack, bool push, bool rst, bool syn, bool fin);
|
|
bool containsControlBits(OpenQueueEntry_t* msg, uint8_t ack, uint8_t rst, uint8_t syn, uint8_t fin);
|
|
void tcp_change_state(uint8_t new_state);
|
|
! void opentcp_reset(void);
|
|
! void opentcp_timer_cb(void);
|
|
|
|
//=========================== public ==========================================
|
|
|
|
! void opentcp_init(void) {
|
|
// reset local variables
|
|
memset(&tcp_vars,0,sizeof(tcp_vars_t));
|
|
// reset state machine
|
|
! opentcp_reset();
|
|
}
|
|
|
|
! owerror_t opentcp_connect(open_addr_t* dest, uint16_t param_tcp_hisPort, uint16_t param_tcp_myPort) {
|
|
//[command] establishment
|
|
OpenQueueEntry_t* tempPkt;
|
|
if (tcp_vars.state!=TCP_STATE_CLOSED) {
|
|
***************
|
|
*** 81,87 ****
|
|
return forwarding_send(tempPkt);
|
|
}
|
|
|
|
! error_t opentcp_send(OpenQueueEntry_t* msg) { //[command] data
|
|
msg->owner = COMPONENT_OPENTCP;
|
|
if (tcp_vars.state!=TCP_STATE_ESTABLISHED) {
|
|
openserial_printError(COMPONENT_OPENTCP,ERR_WRONG_TCP_STATE,
|
|
--- 71,77 ----
|
|
return forwarding_send(tempPkt);
|
|
}
|
|
|
|
! owerror_t opentcp_send(OpenQueueEntry_t* msg) { //[command] data
|
|
msg->owner = COMPONENT_OPENTCP;
|
|
if (tcp_vars.state!=TCP_STATE_ESTABLISHED) {
|
|
openserial_printError(COMPONENT_OPENTCP,ERR_WRONG_TCP_STATE,
|
|
***************
|
|
*** 114,120 ****
|
|
return forwarding_send(tcp_vars.dataToSend);
|
|
}
|
|
|
|
! void opentcp_sendDone(OpenQueueEntry_t* msg, error_t error) {
|
|
OpenQueueEntry_t* tempPkt;
|
|
msg->owner = COMPONENT_OPENTCP;
|
|
switch (tcp_vars.state) {
|
|
--- 104,110 ----
|
|
return forwarding_send(tcp_vars.dataToSend);
|
|
}
|
|
|
|
! void opentcp_sendDone(OpenQueueEntry_t* msg, owerror_t error) {
|
|
OpenQueueEntry_t* tempPkt;
|
|
msg->owner = COMPONENT_OPENTCP;
|
|
switch (tcp_vars.state) {
|
|
***************
|
|
*** 196,202 ****
|
|
openqueue_freePacketBuffer(msg);
|
|
tcp_change_state(TCP_STATE_TIME_WAIT);
|
|
//TODO implement waiting timer
|
|
! reset();
|
|
break;
|
|
|
|
case TCP_STATE_ALMOST_CLOSE_WAIT: //[sendDone] teardown
|
|
--- 186,192 ----
|
|
openqueue_freePacketBuffer(msg);
|
|
tcp_change_state(TCP_STATE_TIME_WAIT);
|
|
//TODO implement waiting timer
|
|
! opentcp_reset();
|
|
break;
|
|
|
|
case TCP_STATE_ALMOST_CLOSE_WAIT: //[sendDone] teardown
|
|
***************
|
|
*** 259,265 ****
|
|
}
|
|
if (containsControlBits(msg,TCP_ACK_WHATEVER,TCP_RST_YES,TCP_SYN_WHATEVER,TCP_FIN_WHATEVER)) {
|
|
//I receive RST[+*], I reset
|
|
! reset();
|
|
openqueue_freePacketBuffer(msg);
|
|
}
|
|
switch (tcp_vars.state) {
|
|
--- 249,255 ----
|
|
}
|
|
if (containsControlBits(msg,TCP_ACK_WHATEVER,TCP_RST_YES,TCP_SYN_WHATEVER,TCP_FIN_WHATEVER)) {
|
|
//I receive RST[+*], I reset
|
|
! opentcp_reset();
|
|
openqueue_freePacketBuffer(msg);
|
|
}
|
|
switch (tcp_vars.state) {
|
|
***************
|
|
*** 311,317 ****
|
|
tcp_change_state(TCP_STATE_ALMOST_SYN_RECEIVED);
|
|
forwarding_send(tempPkt);
|
|
} else {
|
|
! reset();
|
|
openserial_printError(COMPONENT_OPENTCP,ERR_TCP_RESET,
|
|
(errorparameter_t)tcp_vars.state,
|
|
(errorparameter_t)0);
|
|
--- 301,307 ----
|
|
tcp_change_state(TCP_STATE_ALMOST_SYN_RECEIVED);
|
|
forwarding_send(tempPkt);
|
|
} else {
|
|
! opentcp_reset();
|
|
openserial_printError(COMPONENT_OPENTCP,ERR_TCP_RESET,
|
|
(errorparameter_t)tcp_vars.state,
|
|
(errorparameter_t)0);
|
|
***************
|
|
*** 366,372 ****
|
|
tcp_change_state(TCP_STATE_ALMOST_SYN_RECEIVED);
|
|
forwarding_send(tempPkt);
|
|
} else {
|
|
! reset();
|
|
openserial_printError(COMPONENT_OPENTCP,ERR_TCP_RESET,
|
|
(errorparameter_t)tcp_vars.state,
|
|
(errorparameter_t)1);
|
|
--- 356,362 ----
|
|
tcp_change_state(TCP_STATE_ALMOST_SYN_RECEIVED);
|
|
forwarding_send(tempPkt);
|
|
} else {
|
|
! opentcp_reset();
|
|
openserial_printError(COMPONENT_OPENTCP,ERR_TCP_RESET,
|
|
(errorparameter_t)tcp_vars.state,
|
|
(errorparameter_t)1);
|
|
***************
|
|
*** 379,385 ****
|
|
//I receive ACK, the virtual circuit is established
|
|
tcp_change_state(TCP_STATE_ESTABLISHED);
|
|
} else {
|
|
! reset();
|
|
openserial_printError(COMPONENT_OPENTCP,ERR_TCP_RESET,
|
|
(errorparameter_t)tcp_vars.state,
|
|
(errorparameter_t)2);
|
|
--- 369,375 ----
|
|
//I receive ACK, the virtual circuit is established
|
|
tcp_change_state(TCP_STATE_ESTABLISHED);
|
|
} else {
|
|
! opentcp_reset();
|
|
openserial_printError(COMPONENT_OPENTCP,ERR_TCP_RESET,
|
|
(errorparameter_t)tcp_vars.state,
|
|
(errorparameter_t)2);
|
|
***************
|
|
*** 435,441 ****
|
|
tcp_vars.dataReceived = msg;
|
|
tcp_change_state(TCP_STATE_ALMOST_DATA_RECEIVED);
|
|
} else {
|
|
! reset();
|
|
openserial_printError(COMPONENT_OPENTCP,ERR_TCP_RESET,
|
|
(errorparameter_t)tcp_vars.state,
|
|
(errorparameter_t)3);
|
|
--- 425,431 ----
|
|
tcp_vars.dataReceived = msg;
|
|
tcp_change_state(TCP_STATE_ALMOST_DATA_RECEIVED);
|
|
} else {
|
|
! opentcp_reset();
|
|
openserial_printError(COMPONENT_OPENTCP,ERR_TCP_RESET,
|
|
(errorparameter_t)tcp_vars.state,
|
|
(errorparameter_t)3);
|
|
***************
|
|
*** 510,516 ****
|
|
forwarding_send(tempPkt);
|
|
tcp_change_state(TCP_STATE_ALMOST_CLOSE_WAIT);
|
|
} else {
|
|
! reset();
|
|
openserial_printError(COMPONENT_OPENTCP,ERR_TCP_RESET,
|
|
(errorparameter_t)tcp_vars.state,
|
|
(errorparameter_t)4);
|
|
--- 500,506 ----
|
|
forwarding_send(tempPkt);
|
|
tcp_change_state(TCP_STATE_ALMOST_CLOSE_WAIT);
|
|
} else {
|
|
! opentcp_reset();
|
|
openserial_printError(COMPONENT_OPENTCP,ERR_TCP_RESET,
|
|
(errorparameter_t)tcp_vars.state,
|
|
(errorparameter_t)4);
|
|
***************
|
|
*** 567,573 ****
|
|
//I receive ACK, I will receive FIN later
|
|
tcp_change_state(TCP_STATE_FIN_WAIT_2);
|
|
} else {
|
|
! reset();
|
|
openserial_printError(COMPONENT_OPENTCP,ERR_TCP_RESET,
|
|
(errorparameter_t)tcp_vars.state,
|
|
(errorparameter_t)5);
|
|
--- 557,563 ----
|
|
//I receive ACK, I will receive FIN later
|
|
tcp_change_state(TCP_STATE_FIN_WAIT_2);
|
|
} else {
|
|
! opentcp_reset();
|
|
openserial_printError(COMPONENT_OPENTCP,ERR_TCP_RESET,
|
|
(errorparameter_t)tcp_vars.state,
|
|
(errorparameter_t)5);
|
|
***************
|
|
*** 607,613 ****
|
|
//I receive ACK, I do nothing
|
|
tcp_change_state(TCP_STATE_TIME_WAIT);
|
|
//TODO implement waiting timer
|
|
! reset();
|
|
}
|
|
openqueue_freePacketBuffer(msg);
|
|
break;
|
|
--- 597,603 ----
|
|
//I receive ACK, I do nothing
|
|
tcp_change_state(TCP_STATE_TIME_WAIT);
|
|
//TODO implement waiting timer
|
|
! opentcp_reset();
|
|
}
|
|
openqueue_freePacketBuffer(msg);
|
|
break;
|
|
***************
|
|
*** 615,621 ****
|
|
case TCP_STATE_LAST_ACK: //[receive] teardown
|
|
if (containsControlBits(msg,TCP_ACK_YES,TCP_RST_NO,TCP_SYN_NO,TCP_FIN_NO)) {
|
|
//I receive ACK, I reset
|
|
! reset();
|
|
}
|
|
openqueue_freePacketBuffer(msg);
|
|
break;
|
|
--- 605,611 ----
|
|
case TCP_STATE_LAST_ACK: //[receive] teardown
|
|
if (containsControlBits(msg,TCP_ACK_YES,TCP_RST_NO,TCP_SYN_NO,TCP_FIN_NO)) {
|
|
//I receive ACK, I reset
|
|
! opentcp_reset();
|
|
}
|
|
openqueue_freePacketBuffer(msg);
|
|
break;
|
|
***************
|
|
*** 628,634 ****
|
|
}
|
|
}
|
|
|
|
! error_t opentcp_close() { //[command] teardown
|
|
OpenQueueEntry_t* tempPkt;
|
|
if ( tcp_vars.state==TCP_STATE_ALMOST_CLOSE_WAIT ||
|
|
tcp_vars.state==TCP_STATE_CLOSE_WAIT ||
|
|
--- 618,624 ----
|
|
}
|
|
}
|
|
|
|
! owerror_t opentcp_close(void) { //[command] teardown
|
|
OpenQueueEntry_t* tempPkt;
|
|
if ( tcp_vars.state==TCP_STATE_ALMOST_CLOSE_WAIT ||
|
|
tcp_vars.state==TCP_STATE_CLOSE_WAIT ||
|
|
***************
|
|
*** 660,674 ****
|
|
return forwarding_send(tempPkt);
|
|
}
|
|
|
|
! bool tcp_debugPrint() {
|
|
return FALSE;
|
|
}
|
|
|
|
//======= timer
|
|
|
|
//timer used to reset state when TCP state machine is stuck
|
|
! void timers_tcp_fired() {
|
|
! reset();
|
|
}
|
|
|
|
//=========================== private =========================================
|
|
--- 650,664 ----
|
|
return forwarding_send(tempPkt);
|
|
}
|
|
|
|
! bool tcp_debugPrint(void) {
|
|
return FALSE;
|
|
}
|
|
|
|
//======= timer
|
|
|
|
//timer used to reset state when TCP state machine is stuck
|
|
! void timers_tcp_fired(void) {
|
|
! opentcp_reset();
|
|
}
|
|
|
|
//=========================== private =========================================
|
|
***************
|
|
*** 727,733 ****
|
|
return return_value;
|
|
}
|
|
|
|
! void reset() {
|
|
tcp_change_state(TCP_STATE_CLOSED);
|
|
tcp_vars.mySeqNum = TCP_INITIAL_SEQNUM;
|
|
tcp_vars.hisNextSeqNum = 0;
|
|
--- 717,723 ----
|
|
return return_value;
|
|
}
|
|
|
|
! void opentcp_reset(void) {
|
|
tcp_change_state(TCP_STATE_CLOSED);
|
|
tcp_vars.mySeqNum = TCP_INITIAL_SEQNUM;
|
|
tcp_vars.hisNextSeqNum = 0;
|
|
***************
|
|
*** 755,760 ****
|
|
}
|
|
}
|
|
|
|
! void opentcp_timer_cb() {
|
|
! scheduler_push_task(timers_tcp_fired,TASKPRIO_TCP_TIMEOUT);
|
|
}
|
|
\ No newline at end of file
|
|
--- 745,753 ----
|
|
}
|
|
}
|
|
|
|
! void opentcp_timer_cb(void) {
|
|
! scheduler_push_task(timers_tcp_fired,TASKPRIO_TCP_TIMEOUT);
|
|
! /*thread_create(openwsn_opentcp_stack, KERNEL_CONF_STACKSIZE_MAIN,
|
|
! PRIORITY_OPENWSN_OPENTCP, CREATE_STACKTEST,
|
|
! timers_tcp_fired, "timers tcp fired");*/
|
|
}
|
|
\ No newline at end of file
|