Go Down

Topic: W5100/Ethernet cannot use socket as UDP after using it as TCP (Read 5651 times) previous topic - next topic

zimm0who0net

Wow,  OK.  Still not to the bottom of this, but I just had a pretty big discovery.  When I get the DNS failure, the packet actually goes to the wrong machine!  In my example I posted the DNS server was outside my network, so it should have been sent to the gateway MAC address.  However, with a packet capture I found that it actually ended up going to the same machine that my TCP request came from!!!

That's exactly why this isn't working right.  For some reason the W5100 gets confused and doesn't update the IP->MAC port for that socket.  I'm going to delve into this a bit more to see if I can get to the bottom of what's going on...

sonnyyu

Some background information about  NTP, DNS, and DHCP use UDP;-

DNS  works on both TCP and UDP

DHCP works on UDP only

Its use is in a typical local area network (LAN). The packet sequencing is never problem.

NTP

It used work both TCP and UDP [RFC0793] , UDP/TCP Port 123 was previously assigned by IANA for NTP. The new [RFC5905] drop TCP support. Here is the reason;- "Reliable message delivery such as TCP [RFC0793] can actually make the delivered NTP packet less reliable since retries would increase the delay value and other errors."  obviously implement correctly UDP client is needed to take care the issue.

Now the question is "What Arduino NTP client does ?"





SurferTim

That could be it. I just tried the same test using a remote dns server and my domain, and it crashed like the Hindenberg.  :(

Now I am back to a localnet dns server and it is ok.

@sonnyyu: No question there. Arduino NTP uses UDP.

sonnyyu

#33
Apr 28, 2013, 07:48 pm Last Edit: Apr 28, 2013, 08:00 pm by sonnyyu Reason: 1

That could be it. I just tried the same test using a remote dns server and my domain, and it crashed like the Hindenberg.  :(

Now I am back to a localnet dns server and it is ok.

@sonnyyu: No question there. Arduino NTP uses UDP.



My fault, the complete question is;

What Arduino NTP client does to take care reliable NTP packet deliver?

This might hijack the thread, I might start new thread about it.

SurferTim

It does nothing for "reliable". It waits 1 second. If no response, it bails.

And the remote server thing just went out the window. I forgot to remove my SD card again, and you code does not disable it. It is working fine with my domain and a remote dns server.

tomtek

I have also hit this bug along with this thread in searching for an answer.

I can add a couple of things I have found trying to fix this.

It appears to be any protocol TCP then UDP or TCP then ICMP are the 2 bugs I have encountered.  If the Wiznet socket is used for TCP it can't do ICMP reliably either to a different IP then TCP was connected with.  I haven't proven it out for 100% sure but I do believe this bug is true for UDP first then ICMP on the same socket.

I have also had it ping the wrong IP (always the GW IP) I believe this is a known bug that is in the latest Wiznet errata stating that you need to leave the GW and mask set to zeros until you open connections this prevents the ARP request returning the GW MAC as a default.

Multiple other bugs in the Arduino Ethernet library.  DNS returning positive results with the wrong IP if the lookup failed.  Ethernet client connections that only work through a GW but not on the same subnet.

Arduino Due is  @ 192.168.20.151 with a valid unique MAC Address

socket 0 -> TCP with 192.168.20.2 ->close TCP -> ICMP Ping to 192.168.20.254(works once then fails)
socket  1 -> TCP with 192.168.20.2 - >open,close,open close TCP always works
socket 2 - > TCP with 192.168.20.2 always works
socket 3 -> ICMP Ping to 192.168.20.254 always works never has TCP on it.

Here is something additional that leans towards an ARP table problem.

socket 0 -> TCP with 192.168.20.2 ->close TCP -> ICMP Ping to 192.168.20.2(Works fine)
socket  1 -> TCP with 192.168.20.2 - >open,close,open close TCP always works
socket 2 - > TCP with 192.168.20.2 always works
socket 3 -> ICMP Ping to 192.168.20.254 always works never has TCP on it.

Its like all 4 sockets share the same ARP table that is too short to stay updated for multiple connections on multiple sockets.

If TCP and ICMP are trying to talk to the same IP and of course MAC address all works no failures.

I tried watching the states that show the MAC address has been resolved.

I think a TCP/IP stack that just uses the MAC Raw mode is the only true solution.  I need TCP/UDP/ICMP/Multicast UDP to function at any given time on any given open Wiznet socket.

Tom

zimm0who0net

Tom,  I never did get a solution to this W5100 bug.  I ended up implementing a workaround that just kept re-trying on failures.  I agree 100% that this is an ARP issue that seems to manifest itself when you switch from TCP to UDP on the same socket.

Wish I could be of more help. 

the_sensor

So it looks like the Wiznet errata (http://www.wiznet.co.kr/Admin_Root/UpLoad_Files/BoardFiles/3150Aplus_5100_errata_en_v2.4.pdf) does show a fix for this problem. However if I look in the Arduino libraries which I'm using (Arduino 1.0.5) I'm not able to find the implementation of this fix. Has anyone ever tried to implement this fix ? At first sight it shouldn't be it too difficult as it involves just a few fixes in libraries/Ethernet/utility/socket.cpp.

FYI: I ended up on this thread as I'm having problems with UDP and TCP connections, but I'm not yet sure if the problem in this thread is the same as my problem. I have not debugged it that far yet...

Go Up