gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > lwIP IP stack port

#78464 - masscat - Fri Apr 07, 2006 2:20 pm

lwIP is a small IP stack for embedded systems and the like. I have done a quick port of it to the DS.
The port is still in the early stages but is usable so you can see what is done so far.

http://masscat.afraid.org/ninds/lwip.php

EDIT: Changed the topic name to let people know what lwIP is.


Last edited by masscat on Fri Apr 07, 2006 8:57 pm; edited 2 times in total

#78478 - kevinc - Fri Apr 07, 2006 4:26 pm

Nice, I'll be trying it later.

#78481 - thoduv - Fri Apr 07, 2006 4:59 pm

Great port ! Hoping it'll work perfectly someday ! :)

#78572 - splat - Sat Apr 08, 2006 3:54 am

Neat! Not sure it's working though. I can connect to my AP and give my DS a IP address but when i go to the iwLP test, i get a message saying "Test debug printing 803c88" then "Assertion "Test assert" failed at line 556 in test_lwip.c. Then it prints the IP and MAC address but I can't ping that or get to it in my browser.

#78601 - masscat - Sat Apr 08, 2006 9:27 am

splat wrote:
Neat! Not sure it's working though. I can connect to my AP and give my DS a IP address but when i go to the iwLP test, i get a message saying "Test debug printing 803c88" then "Assertion "Test assert" failed at line 556 in test_lwip.c. Then it prints the IP and MAC address but I can't ping that or get to it in my browser.


The "Assertion "Test assert" failed at line 556 in test_lwip.c" is fine as it is just some test code testing the assert printing (I have added a note to the website to avoid confusion).
To get to the IP and MAC address printing shows that you are correctly connected to your AP (the wireless side is fine) suggesting your problem maybe with routing the IP packets.
The IP address you configure for the DS must be a valid IP on your wireless network. The gateway must be the address of the router (this maybe the AP) on your network. Something on the network maybe blocking the packet (the firewall function of the router/AP). If the PC you are using is on a different network then you may need to tell it how to get to the wireless network.
Can you give some information on your network setup such as IP addresses, number of stations and which PC you are using to try to connect to the DS.

#78704 - waruwaru - Sun Apr 09, 2006 12:59 am

I can't get the htmlserver working either. I see my ip/mac address printed on top screen. I can press A and B to get some debug info, so it's not frozen. There is no firewall issue because I can ping my DS when I connect to Nintendo's wifi service. I am trying to ping from an XP-SP2. LinkSys wap11 as AP without wep. I am using a subnet on 192.168.1.*, the DS's address is 192.168.1.140. Let me know if you need more info.
_________________
DSLua - a scripting language for your DS!

#78711 - tepples - Sun Apr 09, 2006 2:11 am

Sgstair did try porting lwIP initially and abandoned it in favor of his own sgIP stack.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#78724 - masscat - Sun Apr 09, 2006 6:50 am

tepples wrote:
Sgstair did try porting lwIP initially and abandoned it in favor of his own sgIP stack.


Do you know why he abandoned it? The stack did do strange things if the memory alignment was not set to 4 bytes (appearing to reverse addresses). I am going to investigate if this is a bug in the stack source, the behaviour of the Nintendo DS's memory or something strange about the ARM code being produced by the compiler.

People with problems:
Forgot to metion this: pressing the X button when running the htmlserver program will put the program in a loop that stops the stack from being run - allows you a have a look at debug messages before they scroll off the screen. Pressing X again brings it out of the loop. But there is no indication on screen of the mode you are in.
So be careful with the X button. I will add this to the website.

waruwaru:
Is the PC you are pinging from also on the wireless network?
If not then the gateway setting on the DS may not be correct (this will normally be the IP address of the AP).
If it is then run "ipconfig" on the windows machine and it will display the settings it is using. Use the same subnet mask and default gateway settings on the DS.

Here is my layout and settings. I have not shown the DNS setting as it is not used and therefore does not matter.

Code:
Internet
 |
 |
 (adsl)
 |
 |
Router
IP: 192.168.7.1
 |
 |
 (Ethernet)
 |
 |
IP: 192.168.7.2
Windows Running SoftAP
IP: 192.168.12.1
 |
 |
 (wireless)
 |
 |
IP: 192.168.12.5
subnetmask: 255.255.255.0
gateway: 192.168.12.1
DS running lwIP stack


I can ping the DS from both a PC on the Ethernet (the adsl router has a route to the 192.168.12 network via the Windows machine) and a PC on the wireless network.

#78763 - bluescrn - Sun Apr 09, 2006 4:47 pm

It worked for me (ping response and HTTP server). Nice one :)

#78806 - waruwaru - Sun Apr 09, 2006 11:06 pm

masscat wrote:
waruwaru:
Is the PC you are pinging from also on the wireless network?
If not then the gateway setting on the DS may not be correct (this will normally be the IP address of the AP).
If it is then run "ipconfig" on the windows machine and it will display the settings it is using. Use the same subnet mask and default gateway settings on the DS.


Yep, the laptop and DS were configured with same subnet/gateway. The same DS config works getting the DS online (Tetris/MarioKart), and also for the bafio's wifi transfer program. Just tried it again, still can't ping (not pressing any keys). I tried both the version you have on your page, and a version I built.

EDIT: I see you are using Windows as a softap, so I guess the PC you are ping from is also the gateway? My network is a bit different:

Code:

Gateway(11G Router) ----- CAT5 ------ (11B AP)
192.168.1.1                                |
 |                                         |
 |                                         |
 |                                         |
Laptop (192.168.1.136)               DS (192.168.1.140)


I can't ping from neither laptop on wireless, PC on the wired network nor the 11G router.

Thanks
_________________
DSLua - a scripting language for your DS!

#78809 - masscat - Sun Apr 09, 2006 11:28 pm

waruwaru: Not sure what your problem could be. If you are interested you can configure lots of debug messaging by editing lwip-1.1.1/src/include/lwipopts.h. To get debug out you need to change the following:
Code:
#define DBG_TYPES_ON             0
to
Code:
#define DBG_TYPES_ON             (DBG_ON | DBG_LEVEL_SEVERE)
You can then enable debug for seperate areas of the stack (there are examples commented out in the header file). May be worth enable ICMP_DEBUG to see if the stack is seeing your ping. If you enable too much it goes scrolling off the screen before you can read it (hence the X button feature).
If you do play around and find anything I would be interested to hear.

EDIT: Just seen you edit. I ping from a linux machine on the Ethernet, . Looking at your network layout I am assuming that the 11B AP is just setup to bridge its wireless interface to its ethernet interface.

#78812 - waruwaru - Sun Apr 09, 2006 11:41 pm

masscat wrote:
waruwaru: Not sure what your problem could be. If you are interested you can configure lots of debug messaging by editing lwip-1.1.1/src/include/lwipopts.h. To get debug out you need to change the following:
Code:
#define DBG_TYPES_ON             0
to
Code:
#define DBG_TYPES_ON             (DBG_ON | DBG_LEVEL_SEVERE)
You can then enable debug for seperate areas of the stack (there are examples commented out in the header file). May be worth enable ICMP_DEBUG to see if the stack is seeing your ping. If you enable too much it goes scrolling off the screen before you can read it (hence the X button feature).
If you do play around and find anything I would be interested to hear.


Hmmm, interesting, I do get the ping on the DS, I get a icmp_input: Ping. But nothing goes back to the PC. Just scrolling tcp_slowtmr: no active pcbs after the ping. I will play with it a bit more...
_________________
DSLua - a scripting language for your DS!

#78819 - waruwaru - Mon Apr 10, 2006 12:56 am

ok, I don't know much about routing/ip-header. Looks like the ip header from Ping says the source address is the gateway/router, and the dest is the DS. So, maybe that is why it's working on your setup, but not mine? Btw, the webserver also gets packets, but same issue, nothing comes back to the PC.
_________________
DSLua - a scripting language for your DS!

#78918 - masscat - Mon Apr 10, 2006 4:32 pm

To help out with debugging I have put a new version of the htmlserver app on my website. It allows you to scroll back through the printed messages. The text also turns red you you press the X button and enter the "no stack execution" mode.

waruwaru:
I think that your problem is a routing one. If you turn on IP_DEBUG in lwipopts.h it should print a message if the stack fails to route a packet.
When you say the ping has a source address of the gateway/router do you mean 192.168.1.1 as shown in your diagram?

#78922 - waruwaru - Mon Apr 10, 2006 4:42 pm

masscat wrote:
I think that your problem is a routing one. If you turn on IP_DEBUG in lwipopts.h it should print a message if the stack fails to route a packet.


Ok, I will try that when I get home tonight.

Quote:

When you say the ping has a source address of the gateway/router do you mean 192.168.1.1 as shown in your diagram?


Yep, I printed out the src and dest address in the ping handling block, the incoming packet source is the gateway, and the dest is the DS. So, when the address is swapped, the outgoing packet src is the DS, and dest is the gateway/router. But I was reading the icmp/ping spec, I think that is ok? Not sure since I don't know ip that well. :)
_________________
DSLua - a scripting language for your DS!

#79169 - dovoto - Tue Apr 11, 2006 11:52 pm

masscat wrote:
tepples wrote:
Sgstair did try porting lwIP initially and abandoned it in favor of his own sgIP stack.


Do you know why he abandoned it?



My understanding was that while the stack ported fairly easily getting a socket interface was too painful due to the threading and OS type constructs that would have to be built around it. He seemed to think implementing his own stack and socket interface would be simpler (and i tend to agree)
_________________
www.drunkencoders.com

#79220 - waruwaru - Wed Apr 12, 2006 6:26 am

masscat wrote:
I think that your problem is a routing one. If you turn on IP_DEBUG in lwipopts.h it should print a message if the stack fails to route a packet.
When you say the ping has a source address of the gateway/router do you mean 192.168.1.1 as shown in your diagram?


Hmm, I didn't get a pkt route error. Here are the msgs I get:
Code:

ip_input: packet accepted on interface wi
ip_input:
IP header:
4(v) | 5(hl) | 0x00(tos) |60(len)
18885(id) | 000(flags) | 0(offset)
128(ttl) | 1(proto) | 0x6d1e(chksum)
192.168.1.1 (src)
192.168.1.140 (dest)

ip_input: p->len 60 p->tot_len 60

icmp_input: ping
ip_output_if: wi0
IP header:
4(v) | 5(hl) | 0x00(tos) |60(len)
18885(id) | 000(flags) | 0(offset)
128(ttl) | 1(proto) | 0x6d1e(chksum)
192.168.1.140 (src)
192.168.1.1 (dest)

netif->output()


Let me know if you want me to do other testing.
_________________
DSLua - a scripting language for your DS!

#79244 - masscat - Wed Apr 12, 2006 12:59 pm

dovoto wrote:
My understanding was that while the stack ported fairly easily getting a socket interface was too painful due to the threading and OS type constructs that would have to be built around it. He seemed to think implementing his own stack and socket interface would be simpler (and i tend to agree)

I too think the socket interface in the lwIP source will a lot of hassle to port (unless anybody ports/implements some sort of OS over to the DS then it would by ideal). I was thinking of doing a different socket interface that operates in the single thread environment.
What I like about the lwIP stack (apart from the fact that it is already written) is that it is very configurable for features and buffer memory use. Therefore people can adapt it for their needs. Also the callback interface it uses as its raw api fits in nicely with an event driven design style, which I like.

waruwaru:
From that debug output the lwIP stack has received the ping, processed it, formed the reply, routed this and sent it out. So, assuming that the wireless side is working, it has got out onto the air. This suggests that the reply is getting lost somewhere. To confirm the wireless transmission of the reply you could capture the wireless frames on the channel the 11B AP is using (although I do not believe this is very easy to acheive using Windows) but I think this will be working.

Having looked at your network layout I think you may have its IP addressing misconfigured which could cause the reply to get dropped on the way back.
At the moment you have all three physical networks (Ethernet and the two wireless - physical in a sort of non physical way) configured as a single IP network - 192.168.1.0 subnet mask 255.255.255.0 (I am assuming that you have not divided this network up by uses a different subnet mask). This would only work if the two APs are configured to bridge their Ethernet and wireless interfaces which I am assuming you have not as the 11G AP is performing network address translation (NAT) on the ping packet (which is why it appears to be coming from 192.168.1.1 when it gets to the DS).

If I were configuring you network I would configure a seperate IP network to each of the physical networks. Below shows an example of this. The IP address given to the laptop and DS are just examples and, in the laptops case, could be assigned by a DHCP server on the 11G AP.

Code:

       (Ethernet 192.168.1.0 255.255.255.0)
    -----------------------------------------------(other PCs with 192.168.1.? addresses)
    |                                       |
    |                                       |
192.168.1.1                            192.168.1.2
  11G AP                                 11B AP
192.168.2.1                            192.168.3.1
    |                                       |
    |                                       |
(wireless 11G                          (wireless 11B
192.168.2.0                            192.168.3.0
255.255.255.0)                         255.255.255.0)
    |                                       |
    |                                       |
192.168.2.10                           192.168.3.10
XP Laptop                              DS

For this to work configure the 11B AP not to do NAT and not to bridge its ethernet and wireless interfaces. You will have to tell the 11G AP how to get to the 192.168.3.0 IP network. This is done by adding a route to its IP routing table (how you do this is very router dependent - you may have to do it through the routers command line interface). The information for this route is IP 192.168.3.0 netmask 255.255.255.0 gateway 192.168.1.2. You will not have to add a route to the 11B AP unless you want to access servers running on PC on the 11G wireless network.

#79284 - waruwaru - Wed Apr 12, 2006 6:09 pm

masscat wrote:
Having looked at your network layout I think you may have its IP addressing misconfigured which could cause the reply to get dropped on the way back.


Hmmm, I will take a look at what you suggested when I get some time. But pinging the DS from the same laptop works fine when I run Tetris Online, and I can use Bafio's wifi transfer program properly suggests the routing works. Looking at the user manuals for the WAP+router configs, everything should be on the same subnet without NAT getting in the way. Thank you for putting together the network graph, I will play with the routing a bit. I am leaning towards the packet getting lost/not transmitted though. Last night, I tried the ping options that bypass router (direct from a BSD box to the DS), the src/dest address shows BSD/DS properly, but the BSD didn't get any packet back either. I was thinking maybe a Ping client on the DS side would help trouble shoot the issue? Let me see if I can capture the wifi packets, that will definitely narrow down the problem.
_________________
DSLua - a scripting language for your DS!

#79286 - masscat - Wed Apr 12, 2006 6:32 pm

waruwaru wrote:
But pinging the DS from the same laptop works fine when I run Tetris Online, and I can use Bafio's wifi transfer program properly suggests the routing works.

I was glossing over that fact :).
A quick check you could do is connect your laptop to the 11B AP (i.e. the one the DS connects to) and then see if the ping works from there.