1
µTasker general / TCP ARP resolution issue
« on: March 15, 2011, 02:49:47 PM »
Hello
We were testing our uTasker telnet implementation over internet. As internet gateway is used GPRS modem. After reset of module, on received SYNC from telnet client uTasker had sent ARP resolution to find MAC of gateway. On reception of ARP resolution from gateway uTasker didn't send SYC ACK frame. To fix this situation I have changed tcp.c code:
extern void fnTaskTCP(TTASKTABLE *ptrTaskTable)
{
QUEUE_HANDLE PortIDInternal = ptrTaskTable->TaskID; // queue ID for task input
unsigned char ucInputMessage[MEDIUM_MESSAGE]; // reserve space for receiving messages
while ( fnRead( PortIDInternal, ucInputMessage, HEADER_LENGTH )) { // check input queue
switch ( ucInputMessage[ MSG_SOURCE_TASK ] ) {
case TIMER_EVENT:
fnPollTCP(); // do TCP management on a periodic basis
uTaskerMonoTimer( OWN_TASK, T_TCP_PERIOD, E_POLL_TCP ); // restart the timer
break;
case TASK_ARP:
{
TCP_CONTROL *ptr_TCP = tTCP;
fnRead( PortIDInternal, ucInputMessage, ucInputMessage[MSG_CONTENT_LENGTH]);// read the contents
switch (ucInputMessage[ 0 ]) { // ARP sends us either ARP resolution success or failed
case ARP_RESOLUTION_SUCCESS: // a TCP socket is owner of resolved address
ptr_TCP += ucInputMessage[ 1 ]; // extract the socket reference
if (ptr_TCP->ucTCP_state == TCP_STATE_SYN_SENT) { // ARP resolve on connection establishment
#ifdef ANNOUNCE_MAX_SEGMENT_SIZE // TCP socket waiting for connection
fnSendSyn(ptr_TCP, TCP_FLAG_SYN); // send SYN with MSS announcement
#else
fnSendTCPControl(ptr_TCP); // resent because IP address has just been resolved
#endif
}
else if (ptr_TCP->ucTCP_state == TCP_STATE_SYN_RCVD) { // next state is SYN_RCVD where an ACK will establish the connection
#ifdef ANNOUNCE_MAX_SEGMENT_SIZE
fnSendSyn(ptr_TCP, (TCP_FLAG_SYN | TCP_FLAG_ACK)); // send SYN, ACK with MSS announcement
#else
ptr_TCP->ucSendFlags = (TCP_FLAG_SYN | TCP_FLAG_ACK); // prepare flags to be transmitted
fnSendTCPControl(ptr_TCP); // send SYN, ACK
#endif
}
else {
.
.
.
Is this correction OK? With this adaptation everything works fine.
We were testing our uTasker telnet implementation over internet. As internet gateway is used GPRS modem. After reset of module, on received SYNC from telnet client uTasker had sent ARP resolution to find MAC of gateway. On reception of ARP resolution from gateway uTasker didn't send SYC ACK frame. To fix this situation I have changed tcp.c code:
extern void fnTaskTCP(TTASKTABLE *ptrTaskTable)
{
QUEUE_HANDLE PortIDInternal = ptrTaskTable->TaskID; // queue ID for task input
unsigned char ucInputMessage[MEDIUM_MESSAGE]; // reserve space for receiving messages
while ( fnRead( PortIDInternal, ucInputMessage, HEADER_LENGTH )) { // check input queue
switch ( ucInputMessage[ MSG_SOURCE_TASK ] ) {
case TIMER_EVENT:
fnPollTCP(); // do TCP management on a periodic basis
uTaskerMonoTimer( OWN_TASK, T_TCP_PERIOD, E_POLL_TCP ); // restart the timer
break;
case TASK_ARP:
{
TCP_CONTROL *ptr_TCP = tTCP;
fnRead( PortIDInternal, ucInputMessage, ucInputMessage[MSG_CONTENT_LENGTH]);// read the contents
switch (ucInputMessage[ 0 ]) { // ARP sends us either ARP resolution success or failed
case ARP_RESOLUTION_SUCCESS: // a TCP socket is owner of resolved address
ptr_TCP += ucInputMessage[ 1 ]; // extract the socket reference
if (ptr_TCP->ucTCP_state == TCP_STATE_SYN_SENT) { // ARP resolve on connection establishment
#ifdef ANNOUNCE_MAX_SEGMENT_SIZE // TCP socket waiting for connection
fnSendSyn(ptr_TCP, TCP_FLAG_SYN); // send SYN with MSS announcement
#else
fnSendTCPControl(ptr_TCP); // resent because IP address has just been resolved
#endif
}
else if (ptr_TCP->ucTCP_state == TCP_STATE_SYN_RCVD) { // next state is SYN_RCVD where an ACK will establish the connection
#ifdef ANNOUNCE_MAX_SEGMENT_SIZE
fnSendSyn(ptr_TCP, (TCP_FLAG_SYN | TCP_FLAG_ACK)); // send SYN, ACK with MSS announcement
#else
ptr_TCP->ucSendFlags = (TCP_FLAG_SYN | TCP_FLAG_ACK); // prepare flags to be transmitted
fnSendTCPControl(ptr_TCP); // send SYN, ACK
#endif
}
else {
.
.
.
Is this correction OK? With this adaptation everything works fine.