TCP connection issue (SYN lost)

I try to run MQTT agent demo with plain_text transport on my cortex m4 board. Board succesfully receive DHCP, DNS requests but i did not see any SYN packets in wireshark. How i can trace more detailed my issue? This part of debug output. I make breakpoint in NetworkInterfaceOutput function but the entry into this function did not occur

FreeRTOS_connect: 43709 to c0a8585bip:1883Socket 43709 -> [192.168.88.91]:1883 State eCLOSED->eCONNECT_SYNConnect[c0a8585bip:1883]: next timeout 0: 500 msConnect[c0a8585bip:1883]: next timeout 0: 500 msConnect[c0a8585bip:1883]: next timeout 0: 500 msConnect[c0a8585bip:1883]: next timeout 0: 500 msConnect[c0a8585bip:1883]: next timeout 0: 500 msConnect[c0a8585bip:1883]: next timeout 0: 500 msConnect[c0a8585bip:1883]: next timeout 0: 500 msConnect[c0a8585bip:1883]: next timeout 0: 500 msConnect[c0a8585bip:1883]: next timeout 0: 500 msConnect[c0a8585bip:1883]: next timeout 0: 500 ms[ERROR] [SocketsWrapper] [Sockets_Connect:123] Failed to connect to server: FreeRTOS_Connect failed: ReturnCode=-116, Hostname=192.168.88.91, Port=1883.
FreeRTOS_closesocket[0ip port 43709 to c0a8585bip port 1883]: buffers 56 socks 0[ERROR] [MQTT] [Plaintext_FreeRTOS_Connect:70] Failed to connect to 192.168.88.91 with error -116.

And another question - what is Zero packets in wireshark? I capture packets in router (on the connection port of the board) and send captured file to wireshark for analyze

2024-06-14_16-02-45

Seems like TCP connection is not working? Can you first try the TCP echo demo to ensure that that TCP is working?

Please share the complete output.

A quick google search give this link which may be useful - Wireshark Q&A.

1 Like

I attach the file with log info
20240617123406.c (10.4 KB)

Yes, i will try this. I did not try TCP but dhcp, dns work fine

I set the breakpoint on function: socketStatus = FreeRTOS_connect( tcpSocket, &serverAddress, sizeof( serverAddress ) );

and breakpoint in NetworkInterfaceOutput but code execution does not fall within this function.

I just take using_plaintext.c code to implement transport layer. i use zero copy driver implementation. Does i need some modification in using_plaingtest for zero_copy driver type?
I suppouse FreeRTOS_connect function call must refer to the function NetworkInterfaceOutput to transmit the packet,
but this is not happening

I attach log with network event trace code. And i can not see any eNetworkTxEvent, =/ 2:* when FreeRtos try to connect to socket
20240617164257.c (9.6 KB)

Please enable FreeRTOS-Plus-TCP debug logging by setting ipconfigHAS_DEBUG_PRINTF and ipconfigHAS_PRINTF to 1 in your FreeRTOSIPConfig.h. Youโ€™ll also need to define FreeRTOS_debug_printf and FreeRTOS_printf

Do.you see attached files from my previous post? In this files log from app

Hi @pistoletov1974,
Based on the log, it appears that the device is unable to receive the SYN-ACK response from the server. The log indicates that the network capabilities on the device itself seem to be functioning correctly, as evidenced by the successful DHCP and ARP processes. However, it would be advisable to investigate potential issues within the network environment along the path to the server. Specifically, it would be prudent to examine the firewall configurations and network settings to ensure that there are no obstructions or restrictions preventing the device from establishing a successful connection with the server. Your assistance in conducting this analysis would be greatly appreciated.

Reference: -116 is pdFREERTOS_ERRNO_ETIMEDOUT

[ERROR] [MQTT] [Plaintext_FreeRTOS_Connect:70] Failed to connect to 192.168.88.91 with error -116.

Thank you.

1 Like

Thank.you @ActoryOu for reply. I suppose that problem in the stack that not send tcp-syn packet. Broker and my device in local network. In the first post I attach screen from wireshark. In this log I did not see any outgoing tcp packets. May be problem is some timers inside in stack? I see in log connection attempts is too fast.

Place a breakpoint at this line to ensure that a timer event is sent to the IP task. The following callstack in the IP task should lead to xWinPcap_NetworkInterfaceOutput:

prvIPTask โ†’ prvProcessIPEventsAndTimers โ†’ vCheckNetworkTimers โ†’ xTCPTimerCheck โ†’ xTCPSocketCheck โ†’ prvTCPSendPacket โ†’ prvTCPReturnPacket โ†’ prvTCPReturnPacket_IPV4 โ†’ xWinPcap_NetworkInterfaceOutput.

Place breakpoints at these lines and try to see why the xWinPcap_NetworkInterfaceOutput function in not getting called to put the SYN packet on the wire.

Thank you, @aggarg . A small note - I run the stack on my m4 board. I ported the driver myself according to the documentation from FreeRTOS. Sending the event to the task is successful

                if( xSendEventToIPTask( eTCPTimerEvent ) != pdPASS )
                {
                    xResult = -pdFREERTOS_ERRNO_ECANCELED;
                }

. Below I attach the result of debugging output at the execution step:
if( xSendEventToIPTask( eTCPTimerEvent ) != pdPASS ).

4:55:32.656> pxEasyFit: ARP c0a85801ip -> c0a85873ip
14:55:32.656> pxEasyFit: ARP c0a85801ip -> c0a85873ip
14:55:32.656> pxEasyFit: ARP c0a85801ip -> c0a85873ip
14:55:32.656> Network buffers: 50 lowest 50
14:55:32.656> Heap: current 51760 lowest 51760
14:55:32.656> net_ev 1
14:55:32.656> 
14:55:32.656> ipARP_REQUEST from c0a85801ip to c0a85873ip end-point c0a85873ip
14:55:32.656> ipARP_REQUEST from c0a85801ip to c0a85873ip end-point c0a85873ip
14:55:32.656> ipARP_REQUEST from c0a85801ip to c0a85873ip end-point c0a85873ip
14:55:32.656> ARP c0a8585bip miss using c0a8585bip
14:55:32.656> ARP for c0a8585bip (using c0a8585bip): rc=0 00-00-00-00-00-00
14:55:32.656> ConnectpxEasyFit: ARP c0a85873ip -> c0a8585bip
14:55:32.656> [c0a8585bip:1883]: next timeout 1: 500 ms
14:55:32.656> net_ev 1
14:55:32.656> 
14:55:32.656> ipARP_REPLY from c0a8585bip to c0a85873ip end-point c0a85873ip
14:55:32.656> net_ev 6
14:55:32.656> 

I added timestamps to the terminal program. I attach the full log as a file. Extension C since the forum does not allow you to attach files with another extension.
log_file.c (13.4 KB)

the code stuck in this code. pxIterator = pxEnd and the code does not go into this while cycle. xBoundTCPSocketsList.uxNumberOffitems=0. No socket bounded. This is problem?
In FreeRTOSIPConfig.h macro is :slight_smile:

#define ipconfigALLOW_SOCKET_SEND_WITHOUT_BIND 1

May be my problem is in empty body of function - ulApplicationGetNextSequenceNumber
UPD: add return rand(); and this fix the problem!

1 Like

Note that rand() should produce REAL random numbers.
Many MCUs have a RNG which can be used.

Edit: There are some posts regarding proper

ipconfigRAND32

Thank you for sharing your solution!

Yes, i know about it and use miliseconds in rts to seed random generator. The prototype of function is

uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
                                                    uint16_t usSourcePort,
                                                    uint32_t ulDestinationAddress,
                                                    uint16_t usDestinationPort )

why do we need the transmitted parameters if the output of the function does not depend on them?

You can ignore these parameters - FreeRTOS/FreeRTOS-Plus/VisualStudio_StaticProjects/FreeRTOS+TCP/plus_tcp_hooks_winsim.c at main ยท FreeRTOS/FreeRTOS ยท GitHub.