it is not quite clear to me which mode I should use. I want to have the w5200 with one entry point let’s say. To this, I want to be able to send and receive messages from different peers. Therefore, I believe I should use MACRAW so I can choose destination IP and port when I want to send and filter it (my self via software) from which IP and port the message comes from.
This is what I want to achieve:
As you can see, I would need more than 8 sockets to achieve having the w5200 receiving and sending messages to different applications from different peers. So, each peer will have a unique IP but can communicate to the w5200 through different ports to send, receive or send and receive. So, that is why there are multiple peers (=multiple ips) and multiple ports per IP. I can do this with the hardwired TCP/IP stack but I am limited to 8.
As it can be seen in the diagram, some applications can only send, others can only receive and some can send an receive.
Checking the documentation, I understood that this is what it is referred to “software TCP/IP stack”, but my problem to understand is that in MACRAW mode, I will have 6 bytes which refer to the mac.
How can I know the IP and port where a message comes from or how to tell the w5200 to which IP address and port send the message to?
There is a limitation of up to 1500 bytes. What if I need to send more than that? Would it be possible to send chunks of 1500 bytes but have on the receiving end like it was one send instead of multiple ones?
Thank you for the help.
EDIT: So the answer to question 1 is in the tcp header that I will receive by reading the raw data.
However, I opened the socket in MACRAW, tried to connect from a PC but the w5200 never answers. I want to send data over TCP/IP so I have a simple python code for this. I see on wireshark that only the packets going out of the PC to open the socket are present but there is no response from the w5200. Do I need to first have socket 1 to 7 in used before I can start with MACRAW?
If you use 8 or less sockets, you just use “TCP” socket mode, don’t need to use “MACRAW” mode.
I’m not sure you’ve already known about the TCP/IP protocols, TCP is a connection based communication. So, before data transmission, connection process should be completed between W5200 and App1,2,3…
Assume that W5200 socket 0 is a server.(listen socket)
Assume that W5200 socket 1 is a server.(listen socket)
App1(IP1,Port1) is a client.(connect)
App5(IP3,Port1) is a client.(connect)
App1(IP1,Port1) try to connect to W5200 socket 0 and accept the connection (connection established)
App5(IP3,Port1) try to connect to W5200 socket 1 and accept the connection (connection established)
in case of App1(IP1,Port1), you can send/recv data through W5200 socket 0.
in case of App5(IP3,Port1), you can send/recv data through W5200 socket 1.
1 TCP connection supports one peer socket(IP, Port).
If you want to change peer ( ex) Peer1->Peer2 ),
you must disconnect the exist connection from current peer(Peer1).
you need a new connect process between W5200 and another peer(Peer2).
If you need more detail information for TCP/IP and socket programming, I think, you’d better search another simple & good materials from Internet world (google it )
*) W5200, W5500, W6100 can support 8 sockets (8 TCP connections). Please don’t use W5200 for your new design. please use W5500 or W6100.
That is the issue I am trying to circumvent, when I need more than 8. Now I have it working with all sockets, but I need to have more connections. That is what I wanted to say with the diagram and why I thought about the MACRAW mode.
I cannot disconnect an existing connection from a current peer as I need that connection later again.
Wouldn’t then be an option the MACRAW mode when I need more than 8 sockets?
No, you don’t need to use 1~7 socket, Just use “MACRAW” socket 0 for all connections.(but you need to port S/W TCP/IP stack)
If you use only MACRAW mode, S/W TCP/IP stack could send response packets. Please check the software part.
I recommend, test simple ARP send()/recv() function first with S/W stack.
Following the datasheet, from the w5200 side, setting the mode and opening the socket, shouldn’t I have been able to receive an ethernet package? From the sender part, I know the w5200 IP and I chose a port number from 0xc000 to 0xf00. Then I should be able to filter these when I receive the ethernet package only by opening the port…right?
No, No, when you use “MACRAW”, W5200 just check you MAC address.
All Broadcast packet and packets with having destination MAC address same as your setting on W5200 will be received.
W5200 don’t see any port number & IP address. just look for MAC.
In case of “MACRAW” mode, S/W stack should care for IP, Port filter and processing.
Yes, I know…but from the pc I can send over tcp/ip by choosing ip and port which will be in the ethernet package that I will read in the w5200, or not? Or it means that from the PC as well, I cannot use standard tcp/ip socket functions?
But after I opened the socket on the w5200 I sent the same way I did before to receive with the hardwire tcp/ip stack but this time, I can see the package from the pc to the w5200 (to connect to) but when I check if I receive something, there are no new bytes on the w5200’s RX buffer. So the question is if I need to do something different then on the PC side as I do when I have a socket with the hardwire tcp/ip?
no, pc side same.
pls check MAC address on W5200. is it same when you used H/W stack?
Just for your reference, our team member upload very old reference source code with MACRAW. I hope, it could be more help.
It’s strange, if you set the MAC address, there is no problem to get packet.
I don’t know exactly why there is no receiving data.
Could you try it without any switch? Direct connect btw PC & W5200 board.
PS) Sorry, I will check this issue on Monday again. please leave the result & any feedback.
So there is actually always something on the receiving buffer. I have a router where I connect the w5200 and the PC. The data is either something from the router or from the PC. I can see their MAC addresses.
I believe there is something to do with the protocol before being able to send and receive any information and that is what the hardwire tcp/ip stack takes care of before I can open a new socket. And that is all the data that I am seeing there. Please let me know if that is correct.
If it is, I would need to process all that by myself before I am able to open a new socket on the pc to send/receive information from/to the w5200.
Just in case, I attached a log file with data from the router and data from the pc. macraw.hex (19.0 KB)
One thing that is not clear is that I have in the buffer, for example, 2009 bytes but the first 2 ones (byte size of DATA packet) is 0x00 0x3e = 63 bytes. Why is the difference so big between these two?
Then I should now do something like LwIP then with that incoming data or something like @irina_kim uploaded.
and what about the size of data I can send? If it is limited to 1500 bytes…how is it possible to send bigger packages than that? Let’s say I have 5000 bytes to send. Then, it will be splitted in 3x1500 and 1x500 but will that represent that on the receiving peer it will be like receiving 4 different packages or it is possible to see it as one big 5000 bytes one?
EDIT: Given that case…it would be possible to subdivide the data to send and establish in the protocol header that the complete message will be sub-divided, right? So it is not up to the w5200 but how the protocol’s header is built