Introducing mIP - A 100% Managed TCP/IP Stack for .NET MF

[quote]Try this:

Inside the mIP Networking.cs file, at the end of the Networking.Adapter.Start method, add this line:
if (Adapter.DhcpDisabled) PollingTimer.Change(10, 10000);[/quote]

I still get the error. I should perhaps point out that the CerbuinoBee is connected directly to my PC (Win7) and not to a router. This however worked well with a FEZ Domino and the W5100 ethernet shield. I will check with a router later today. In Windows I have configured the LAN connection to use an fixed IP/Subnet/Default gateway.

Here is my main()


public static void Main()
        {
            Networking.Adapter.IPAddress = new byte[] { 192, 168, 100, 8 };
            Networking.Adapter.DomainNameServer = new byte[] { 192, 168, 0, 254 };
            Networking.Adapter.Gateway = new byte[] { 192, 168, 100, 1 };
            Networking.Adapter.DhcpDisabled = true;

            Networking.Adapter.Start(new byte[] { 0x5c, 0x86, 0x4a, 0x00, 0x00, 0xdd }, "mip", InterfaceProfile.CerbuinoBee_Socket1_ENC28);
            Thread.Sleep(2000); //GatewayMAC hack

            Networking.Adapter.OnUdpReceivedPacketEvent += new Adapter.UdpPacketReceivedEventHandler(Adapter_OnUdpReceivedPacketEvent);
            Networking.Adapter.ListenToPort(10291);
            int i = 0;
            while (true)
            {
                i++;
                string s = i.ToString();
                byte[] msg = Encoding.UTF8.GetBytes(s);
                Debug.Print("TX'ing: " + s);

                UDP.SendUDPMessage(msg, new byte[4] { 192, 168, 100, 3 }, 10290, 10293);
                Thread.Sleep(1000);
            }
        }

Yeah, connecting to the PC should definitely be fine since all my development is done that way so that I can sniff the packets with wireshark. I am almost done with what I think is a beta-quality build of the stack. I have also gotten some code contributions.

I will try out your code and see what happensā€¦

Success with a vanilla Discovery loaded with Oberonā€™s firmware.
Didnā€™t work with SPI1 but did with SPI2. I randomly chose PD0 & PD1 for CS & INT.

Would it be possible to use your ENC28J60 driver with the LWIP in the 4.2 firmware? The Oberon firmware doesnā€™t have a built in ENC28J60 driver.

2 Valkyrie-MT: many thanks to you !

I think it needs to be fixed - GatewayMac isnt used.


        private static void SendPING_Reply(byte[] destinationMac, byte[] destinationIP, byte[] id, byte[] seq)
        {
//            if (Adapter.GatewayMac == null || Adapter.IPAddress == null) return;
            if (Adapter.IPAddress == null)
                return;

New Beta Version of mip is now available on Codeplex at http://mip.codeplex.com

It has a large number of fixes and enhancements. Ultimately, though it is working so well for me right now that I felt comfortable calling it a Beta. I have a web server using (an earlier build) that has been running flawlessly for 4 weeks now. And, I am getting more confident that it is really getting stable. Many of the changes were specifically made to support a robust Web Server. I added a lot of code to detect anomolies in the reading of packets before I ultimately found that the cause was the SPI speed was just too high. I lowered the speed and this dramatically improved things without any noticeable performance loss. But before that, I had already implemented some automatic recovery code. Now both changes are implemented, which should lead to a robust solution. Also, I implemented packet throttling. Basically, this has 3 levels. When there is high traffic, only directed IP messages are allowed. All Broadcast and Multicast messages are ignored until the traffic is lower. Now, it only does this in extreme cases and allows the stack to continue to function under stressful conditions. Otherwise, the buffer would fill with likely useless broadcast traffic and drop all new packets until space is clear. One of my favorite tests is to open a web browser and hold down the F5 (refresh) button. This always crashed LWIP, so it was always a goal to make this work. mIP keeps running without problems through this test. If the stack falls behind, packets may get dropped, but the stack keeps running.

Anyway, here is a list of some improvements:
[ul]Fixed Static address support (no need for any Thread.Sleeps anymore, the Start method blocks until the connections is ready to use (about 200 milliseconds))
Added a Adapter.ConnectedToInternet Property that checks for Internet Connectivity just like a Windows PC using
Added automatic driver recovery when bad bytes are encountered over SPI
Added Throttling to skip packets that are not directly addressed during heavy traffic
Added DNS caching
Added Support for Secondary DNS server
Better handles TCP retransmission requests
Using MultiSPI library to share the SPI bus
Added method for synchronous DNS Lookup with timeout
Added method for HttpRequest support GET and POST (Synchronous and Asynchronous)
Fixed response to TCP RESET messages
And a variety of smaller bugs fixes[/ul]

Iā€™m sorry to say that I still have difficulties using mip with a static configuration.

First I uncommented the static IP example code, and changed the line " Networking.Adapter.DnsServer" to ā€œNetworking.Adapter.DomainNameServerā€ as ā€œDnsServerā€ doesnā€™t exist.

I use this on my Win7 machine


Networking.Adapter.IPAddress = new byte[] { 0xc0, 0xa8, 0x00, 0x5f };  //192.168.0.95
Networking.Adapter.DomainNameServer = new byte[] { 0xc0, 0xa8, 0x00, 0xfe };  // 192.168.0.254
Networking.Adapter.Gateway = new byte[] { 0xc0, 0xa8, 0x00, 0xfe };  // 192.168.0.254
Networking.Adapter.DhcpDisabled = true;

I then setup my PC lan with IP: 192.168.0.96 Subnet mask: 255.255.255.0 and default gateway: 192.168.0.254
But Iā€™m unable to establish any connection
Do I do anything ovbiously wrong?

\Martin

I downloaded mip0.3, but when deploying to a Netduino Mini (latest 4.2 firmware) I am having problems. Specifically, in ENC28J60Driver_MC.cs,

A first chance exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll
An unhandled exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.Hardware.dll

 Uncaught exception 

]at,

public ENC28J60Driver(Cpu.Pin irqPin, Cpu.Pin csPin, SPI.SPI_module spiModule)
{
EXCEPTION --> irq = new InterruptPort(irqPin, true, Port.ResistorMode.PullDown, Port.InterruptMode.InterruptEdgeLevelLow);[/code

I am using,


case InterfaceProfile.NetduinoMini_ENC28:
//GPIO_PIN_5 = 59 and GPIO_PIN_7 = 61
Start(MacAddress, name, SPI.SPI_module.SPI1, (Cpu.Pin)59, (Cpu.Pin)61); //Interrupt, /CS


and Locals reports: irqPin = 59 and csPin = 61. 

I know that the ENC28J60 is hooked up correctly because the the driver posted by hanzibal on the Netduino Forum runs just fine with this pin configuration and produces output such as this,

 ################################ Program.Main[06/01/2011 00:51:33] --> Received frame data of length 148
ENC28j60[06/01/2011 00:51:35] --> IRQ occurred
ENC28j60[06/01/2011 00:51:35] --> IRQ_PKT: frame(s) arrived


Any ideas about what is wrong?

Baxter

I just read all your posts again. So, you donā€™t have any router here, just computer Ethernet to ENC28J60 Ethernet? Is the GatewayMac still null? Is your computer connected to the Internet? Have you bridged the ethernet connections in Windows?

Go into a command prompt and type ā€œarp -a 192.168.0.254ā€. That should return the gateway Mac. Then try setting the Networking.Adapter.GatewayMac = new byte { }

-Valkyrie-MT

The exception is on that line? I wonder if ā€œInterruptEdgeLevelLowā€ is not a valid value for the NetduinoMini. Try InterruptEdgeLow. If that doesnā€™t work, try changing each argument to see if you can figure out which one is the problem.

Why should GatewayMac be used there? Isnā€™t ping a direct communication between two device IPs?

@ Valkyrie-MT

mip0.3 is up and running on Netduino Mini!!! See Post 5,

It has been up for 3 days now and seems stable. I just connected with MFDeploy and did a
ping mip. Here is the response,

C:\Users\beb\Desktop>ping mip

Pinging mip [192.168.0.40] with 32 bytes of data:
Reply from 192.168.0.40: bytes=32 time=104ms TTL=128
Reply from 192.168.0.40: bytes=32 time=58ms TTL=128
Reply from 192.168.0.40: bytes=32 time=58ms TTL=128
Reply from 192.168.0.40: bytes=32 time=58ms TTL=128

Ping statistics for 192.168.0.40:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 58ms, Maximum = 104ms, Average = 69ms

LLMNR Response sent
Sending Response to Ping request
Sending Response to Ping request
Sending Response to Ping request
Sending Response to Ping request
Dropping 0 packet(s)
Packet Count is3: 0
1*** ERXRDPT: 0
1*** ERXWRPT: 1818
2*** ERXRDPT: 0
2*** ERXWRPT: 1818

Thanks for this wonderful software. Any plans to modify the software for a WIZ820io which has a wiz5200?
I just ordered one from Mouser. parallax has a driver that I might try to translate,

http://code.google.com/p/propeller-w5200-driver/

best regards,

Baxter

Why should GatewayMac be used there?
If source and destination devices lie in a common subnet, they communicate directly, otherwise through gateway.

Is not ping a direct communication between two device IPs?
Ping is too.

Any plans to modify the software for a WIZ820io which has a wiz5200?
A support of wiz5200 is good idea!

Iā€™ve been trying for the past couple nights to get mIP to work with my Cerberus + ENC28 with very few successes. My first step is to just run the WebServerProgram successfully for more than a few hits. It actually worked perfectly the first time that I ran it and almost every attempt since then has not worked. I can occasionally get it to work in DHCP for just a few hits and then it dies. I have not had it work successfully with a static IP yet. In DHCP, I can see it grab an IP if I look at the admin of my router. However, most of the time Iā€™m unable to get anything returned from the web server. With a static IP, I have yet to have it register an IP with my router.

My hardware configuration - ENC28 to gigabit switch in my office -> gigabit switch in my garage -> wireless router/DHCP -> Internet

This is my output from my last DHCP test. It got an IP from the router but the web server never responded. Any ideas on how to get this working? I only have a short window to get this up & working or Iā€™m going to have to fall back to a solution less interesting :frowning:

[quote]Program Started.
Link is now up :slight_smile:
TX Error Detected

Dropping 0 packets ## - Experimental

Dropping 0 packets ## - Experimental

WARNING! Time out while waiting for DHCP, check your Interface Profile and connections to ENC28J60 Controller

Dropping 0 packets ## - Experimental

Dropping 0 packets ## - Experimental

Dropping 0 packets ## - Experimental

Dropping 0 packets ## - Experimental

Dropping 0 packets ## - Experimental

Dropping 0 packets ## - Experimental

Dropping 0 packets ## - Experimental

Dropping 0 packet(s)
Packet Count is3: 0
1*** ERXRDPT: 0
1*** ERXWRPT: 770
2*** ERXRDPT: 0
2*** ERXWRPT: 770
Packet Count is4: 0
Packet Count is5: 0
3*** ERXRDPT: 0
3*** ERXWRPT: 770
4*** ERXRDPT: 0
4*** ERXWRPT: 770
4*** Setting Next Packet Pointer to: 0

Dropping 0 packets ## - Experimental

Dropping 0 packets ## - Experimental

Dropping 0 packets ## - Experimental

Dropping 0 packets ## - Experimental

Dropping 0 packets ## - Experimental

Dropping 0 packet(s)
Packet Count is3: 0
1*** ERXRDPT: 0
1*** ERXWRPT: 3902
2*** ERXRDPT: 0
2*** ERXWRPT: 3902
Packet Count is4: 0
Packet Count is5: 0
3*** ERXRDPT: 0
3*** ERXWRPT: 3902
4*** ERXRDPT: 0
4*** ERXWRPT: 3902
4*** Setting Next Packet Pointer to: 0

Dropping 0 packets ## - Experimental

Dropping 0 packets ## - Experimental

Dropping 0 packets ## - Experimental

Dropping 1 packets ## - Experimental

Dropping 0 packets ## - Experimental

[/quote]

FYI - I believe I figured out what my problem was. I had the Cerberus ethernet version of the firmware installed. Installing the non-ethernet version seems to have me moving again. :slight_smile:

Is the ethernet version of the Cerberus firmware good for anything at this point? If not, Iā€™d recommend removing it from the SDK until itā€™s finished.

What do you mean by till it is finished?

Whew. Iā€™m glad you figured that out. Iā€™ve been thinking about your problem since you posted. That does make sense because the ethernet libs in the firmware and mIP would both be communicating with the same SPI device. .NET MF should have a MultiSPI library built-in. mIP uses one right now, but if other devices donā€™t use it, there could be trouble. If someone intentionally tries to control two seperate ethernet cotnrollers, you would have to make sure to use different ChipSelect (CS) outputs, or use 2 completely independent SPI interfaces. In this case, they were the same and thatā€™s not gonna work.

With respect to the Cerberus firmware with Ethernet, I believe it is finished and should be faster than mIP. I wrote mIP from scratch as the stack for a simple web server with local name resolution. It was probably overkill, but I was irked by the fact that some LWIP method calls would never return/timeout. I wrote it almost entirely from looking at communication over Wireshark :).

@ Gus - What MAC address is used when you plug in an ENC28 module into a Cerb-Family device? Does the developer have to supply a MAC, or does the ENC28 come with one? I have an ENC28 and I donā€™t remember it coming with a piece of paper of any label with a MACā€¦

I have a side question:
For a potential project we would need a G120 with 2 ethernet Ports: one Network goes to an machine which wants to read write to an FTP server, the other one is the normal shop floor network.

With mIP we could run on ENC28 with the firmware IP stack and the 2nd one with mIP.

But how does it work exactly (to be honest I did not look into this so far).
If I connect to some IP addres, how does it select the firmware or the mIP stack?
If I create a FTPListener, does it respond to requests from both stacks?
ā€¦

@ Reinhard Ostermeier - I have never tried two ENC28s on a single device, but it should work fine. The libraries should not conflict because they are completely independent. mIP uses none of the .NET MF networking classes. The Ethernet classes built into the framework will use the default SPI and CS, so all you should have to do is configure the other ENC28 with mIP using the constructor overload that allows you to manually configure the SPI and CS, instead of using the enumeration. Also, there is not FTP support with mIP, so you would have to use the integrated stack for the FTP part or write an FTP class for the mIP stack. Note: writing FTP for mIP would be a challenge because I didnā€™t write the TCP to support receiving a stream of multiple packets. The TCP sending was hard enough.

@ Valkyrie-MT: Thany you for your answer: so in short: using mIP for the 2nd Network would work as long as you stick to simple TCP or UDP on this port. right?