Making the connection of Ethernet using TCP protocol.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Making the connection of Ethernet using TCP protocol.

5,419 Views
Malaysia
Contributor I
Hi,
 
    Now I'm using the OpenTCP from FreeScale to make the connection between the PC and the Eval from Axiom, EVB9S12NE64. The attached files were used for implement the OpenTCP into the MCU, besides the files were downloaded from FreeScale website.
 
   Initially, the example implementing the UDP connection between PC and devices. In the attached file I've include the ultilities given by Softec. I'm using the software to make the UDP connection and send UDP data to devices to control it. Besides, I'm also using the Ethereal Network Protocol Analyzer from http://www.ethereal.com to keep track the data that I send to the board.
 
   Currently, I'm trying to connect the devices using the TCP connection, but I failed to do it. From the packet capture, the devices send back the packet to told the PC to reset the connection.
 
   How I going to make the TCP connection for this example? How I going to make the modification in order can used the TCP to control the board? Thanks.
 
Regards
 
Kahjoo
 
Message Edited by t.dowe on 2009-10-20 11:06 PM
Labels (1)
0 Kudos
4 Replies

666 Views
mjbcswitzerland
Specialist V

Hi

If you are getting a connection reset then it means that the TCP frame is arriving correctly at the destination IP address correctly and also has been seen as a valid TCP frame.

A reset will be sent in several circumstances:
- There is no socket to handle the frame (do you have a socket on the port you are using?)
- there is no socket listening on the port (have you set the socket to the listening state?)
- the socket is already being used (have you set multiple sockets to handle multiple connections to a single port?)
- the SYN has been correctly received but the application/service using the socket refuses to accept the connection (have you set up the call back function to correctly accept connection requests?)

Assuming that you have a debugger, simply put a break point in the TCP reception routine and step through the code. The reason for the RESET should then be clear. In open TCP the routine is called "process_tcp_in()".

Regards

Mark Butcher
www.mjbc.ch

 


 

0 Kudos

666 Views
Malaysia
Contributor I

Hi,

   Thanks for your repply. I've set the breakpoint in the process_tcp_in() function and the code was enter to this routine:-

sochandle = tcp_mapsocket(frame, &received_tcp_packet);
 
 if(sochandle < 0) {
  TCP_DEBUGOUT("ERROR: Processing TCP packet failed\r\n");
  tcp_sendreset(&received_tcp_packet, frame->sip);
  return(-1);
 }

   From the routine, the TCP packet received from PC was able to be process, and I don't know why it's comes to here and connot proceed to the following?

   From your replied, I'm not sure how to check wheather the functions that you mentioned were been set or not. This is due to I'm just learn how to use the device and not familiar with the Internet protocol. Can you show me how to verified the point that you have mentioned? Thanks.

 

Regards

kahjoo

0 Kudos

666 Views
rocco
Senior Contributor II
Hi, Kahjoo:

You are getting the error because the routine "tcp_mapsocket" has returned a negative value. You need to trace into tcp_mapsocket to see which one of the four conditions that Mark listed is your problem.

But it sounds to me like you simply haven't setup a socket to hand the packet to.
0 Kudos

666 Views
Malaysia
Contributor I
Hi,
 
   Thanks for your information. From your information, I've trace back the data and from here the function returns back -1:-
 
INT8 tcp_mapsocket (struct ip_frame* ipframe, struct tcp_frame* tcpframe)
{
 struct tcb* soc;
 UINT8 i;
 
 /* Check if there is already connection on */
 
 for( i=0; i < NO_OF_TCPSOCKETS; i++) {
  soc = &tcp_socket[i];     /* Get socket */
  
  if(soc->state == TCP_STATE_LISTENING)
   continue;       /* No match  */
  if(soc->remport != tcpframe->sport)
   continue;      
  if(soc->locport != tcpframe->dport)
   continue;      
  if(soc->rem_ip != ipframe->sip) 
   continue;      
  /* There is connection on already */
  
  TCP_DEBUGOUT("Active connection socket found\r\n");
  
  return(i);
 }
 
 /* Allocate listening one if SYN packet (Connection Request) */
 
 TCP_DEBUGOUT("No active connection, checking if SYN packet\r\n");
 
 /* Is it SYN? */
 
 if( (tcpframe->hlen_flags & TCP_FLAG_SYN) == 0 )
  return(-1);
 if( tcpframe->hlen_flags & TCP_FLAG_ACK )
  return(-1);
 if( tcpframe->hlen_flags & TCP_FLAG_RESET )
  return(-1);
 if( tcpframe->hlen_flags & TCP_FLAG_FIN )
  return(-1);
 
 TCP_DEBUGOUT("Trying to allocate listening one for SYN packet\r\n");
 
 /* Search listening sockets */
 
 for( i=0; i < NO_OF_TCPSOCKETS; i++) {
  soc = &tcp_socket[i];    /* Get socket */
 
  if(soc->state != TCP_STATE_LISTENING)
   continue; 
  
  if(soc->locport != tcpframe->dport)
   continue;
  
  /* Bind it */
  
  soc->rem_ip = ipframe->sip;
  soc->remport = tcpframe->sport;
  
  TCP_DEBUGOUT("Allocated new socket\r\n");
  
  return(i);  
 }
return(-1);
}
 
   From what I've study from the source code, the program was jump out of the loop after the RED line. When I put the breakpoint on the RED line, I found out the value of soc->locport  and  tcpframe->dport are not same, and I don't know why the program jump out from the loop and maybe there is somewhere wrong on the setting.
 
   Can you show me how to set the setting so that the program can connect using the TCP connection, because I still study the devices? Thanks.
 
Regards
 
kahjoo
0 Kudos