Hi all,
My project involves manually setting the IP for the device. Lets say I have 2 devices with identical IP. When I power up both system, I should be able to see that one can bind with the static IP and the other should throw an error. However on my module below, it is not. Is there any setting I need to do to perform these?
error = RTCS_create();
if ((ipcfg_init_device(BSP_DEFAULT_ENET_DEVICE, enet_address)) != IPCFG_OK) //my enet_address is unique in every device
errorNet();
if ((ipcfg_bind_staticip(BSP_DEFAULT_ENET_DEVICE, &ipDataGlobal)) != IPCFG_OK)// i set 2 devices with same IP
errorNet();
Isn't it the bind static IP function should throw an error? Correct me if I am wrong, when I power up both devices, there will be a race condition and whichever comes first binds the IP. Is it a correct assumption?
FYI
I am debugging and it is not going into errorNet function.
Thanks.
Hi Vines,
The example code for the RTCS examples should be working as you expect. Have you tried for instance to flash the example code C:\Freescale\Freescale_MQX_4_0\rtcs\examples\eth_to_serial code to your two devices?
The code should fail when the second device connected to the same router calls the function ipcfg_bind_staticip().
I hope this helps you.
Regards,
Garabo
Hi Garabo,
I actually did tried sample programs before. It didn't work. Ok maybe I clarify something regarding this statement. Given the scenario below:
Scenario 1
1. Device A already powered on and successfully binded to IP1.
2. Powered on Device B with same IP1. When I run through the code it wont enter an error.
Scenario 2
1. Device A already powered on and successfully binded to IP1.
2. Powered on Device B with same IP1. I put a long delay in between RTCS_create and succeeding lines. I was just playing around with this when I notice it.
3. ipcfg_bind_staticip works perfectly. It will have an error if duplicate IP.
4. Now you might mention just put a delay for the solution. This is not viable on my side. The delay of course differs depending on the network. On 1 network 30 seconds delay another is 10 seconds, etc (not consistent).
I initially suspect might be my hardware setup. I am not using the tower. I am using our own hardware. Please dn't frown just yet. You might say it has nothing to do with it. The reason I say this is because previously I have problems getting a correct response with ipcfg_get_link_active with my old phy chip. But when I switch to the PHY chip used by tower I managed to make it work.
Consequently I did a test with the tower modeule with the same codes above. Howerver the result is still the same.
Next I thought might be our network. So I connected only 2 devices on a router. The result is still the same.
All other TCP/IP and UDP works perfect. For some reason only the binding without any delays is not working.
I actually did another test of DHCP binding. This solves the problem. What I did is try binding with ipcfg_bind_dhcp_wait. Once it returns, I know the network is ready. Thus I will unbind the DHCP IP (whatever IP this maybe). Then I try ipcfg_bind_staticip again and it works. It can determine whether IP is available or not.
This is not an efficient way of handling things but I don't know why the static can't work. I have to go through DHCP first. Another drawback is my code size increase because of adding DHCP.
Regards,
vines
Hi Vines,
I did a test and it is working on my side. I am able to see in a few seconds that the router is rejecting the request of the same IP address. I did this test with no time delay added. Take a look to my wireshark screenshot:
The only change I did was to give static MAC address to each code I flashed in the two different tower systems. That is something I missed in my previous replay. You need to make sure the MAC address are different for each tower. Other way the router will believe it is the same FEC asking again for the same IP so, that of course has sense.
| /* Bind IP address for each interface */ | ||
| for (i = 0; (i < n_devices) && (n_devices != 0); i++) | ||
| { | ||
| //_enet_address | address; | |
| _enet_address | address = { 0x00, 0xcf, 0x52, 0x53, 0x54, 0xBB }; | |
| uint_32 | phy_addr; | |
| #if RTCSCFG_ENABLE_IP4 | ||
| IPCFG_IP_ADDRESS_DATA ip_data; | ||
| #endif | ||
| phy_addr = i; | ||
| ip_addr[i] = IPADDR(A,B,C+i,D); |
| //ENET_get_mac_address(phy_addr, ip_addr[i], address); |
The other tower used 0xCC as the last byte in the "address" array.
Try that. It should give this error immediately:
Regards,
Garabo
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Garabo,
I am using a unique MAC for every device because this is written somewhere else (external).
As I was reading my earlier reply to you I found a problem on 1 of my statement which is
"Next I thought might be our network. So I connected only 2 devices on a router. The result is still the same."
Here is the current update on what I am doing.
All along I am using our network and device1 connected to Router A and device2 connected to router B.
I will list out here my setup:
Scenario 1 (connected to network and gateway)
1. Device 1 connected to router A
2. Device 2 connected to router B
3. both router A and B connected in the local network
4. for ipcfg_bind_staticip to work, there needs to be a delay
Scenario 2
(connected to network and gateway)
1. Device 1 connected to router A
2. Device 2 connected to router A
3. Router A connected in the local network
3. ipcfg_bind_staticip works perfectly (no delay needed)
Scenario 3
(not connected with network and gateway)
1. Device 1 connected to router/switch
2. Device 2 connected to router/switch
3. router/switch not connected to our network. Purely for connection between device 1 and device 2
3. ipcfg_bind_staticip works perfectly (no delay needed)
Scenario 2 and 3 screenshot:
Scenario 1 screenshot:
As you can see there is no request captured in wireshark even though I am using exact codes from scenario 2 and 3.
So I guess that explain why ipcfg_bind_staticip wasn't able to capture an error in Scenario 1. The big question is why is it behaving differently on this setup. I read somewhere that some experienced this problem before with different routers. I just don't know how true. I am using MQX4.0
Further on scenario 1, I can ping PC connected in router B if my PC is connected in router A. I can share resources as well.
I tried ipcfg_bind_dhcp_wait on devices connected to both routers A and B just to get returned IP settings(ipcfg_get_ip). Both have the same netmask and gateway.
Any ideas where can I start to debug?
Thank you very much for the help.
Regards,
vines
Hi Vines,
I believe this is more a network issue/configuration than a MCU problem. If you are not seen that the router is rejecting the IP assignation then the MCU will not fail. Have you tried to verify that your two routers are coordinated and making sure they receive IP only in the range of the subnet they own?
Regards,
Garabo
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------