[beagleboard] g_ether automatic IP configuration

Hello,

I want to connect multiple beagleboards (running Angstrong) to my
laptop (windows) and access them using a usb link. G_ether module is
loaded automatically and drivers on my laptop are working. But the
problem is I've to configure a static ip-address (using serial port)
every time I connect the beagleboard.

I've tried configuring the IP address when booting, prior and after
the g_ether module is loaded, but these settings are reset when the
usb cable is plugged in

Plugging in the usb cable before booting won't work since the BB
crashes on boot.

I've tried configuring the g_ether module, but could only find ways to
set MAC address and vendor specifications.

I've also tried using udev, but plugging in usb didn't generate an
udev event.

Does anyone know a way to set the IP address after connecting the usb
cable?

Thanks in advance,

Marcel

There’s a number of problems you’ll hit doing this (especially trying to get it to be done automagically). First of all you should have a quick re-read of TCP/IP subnetting as each BeagleBoard will need to sit on a separate network with no overlaps. Second you need to configure the BeagleBoards and the host’s usb network interfaces so that the BeagleBoard and the appropriate host side usb interface are on the same network. The main problem comes if you connect the boards in a different order each time as usb0 on the host can change…

The static IP address configuration is kept in /etc/network/interfaces on most distros including Angstrom and Ubuntu, so:

On BeagleBoard 1 put/edit these entries in /etc/network/interfaces:
auto usb0
iface usb0 inet static
address 192.168.100.1
netmask 255.255.255.252
network 192.168.100.0
gateway 192.168.100.2

On BeagleBoard 2 put/edit these entries in /etc/network/interfaces:
auto usb0
iface usb0 inet static
address 192.168.100.5
netmask 255.255.255.252
network 192.168.100.4
gateway 192.168.100.6

On the host PC put/edit these entries in /etc/network/interfaces:
auto usb0
iface usb0 inet static
address 192.168.100.2
netmask 255.255.255.252
network 192.168.100.0
auto usb1
iface usb1 inet static
address 192.168.100.6
netmask 255.255.255.252
network 192.168.100.4

Then connect BeagleBoard 1 and check both computer’s have the right ip address configuration (ifconfig -a). Make sure you can ping each address from each computer. Then connect BeagleBoard 2 and redo the checks to make sure everything is set up right. If you need to add more BeagleBoards then add 4 to each of the IP addresses to get to the next mini subnet.

If you have a lot of BeagleBoards to connect then you can use DHCP to automate the assignment of IP addresses. That way all the BeagleBoards can use a single generic image. However, I’ve found this to be somewhat unreliable (because the BeagleBoard sends out a dhcp request before the host’s new usb interface is ready). To get it working I needed to create a bridge and change the ifup/ifdown scripts to plumb the new usb interfaces into the br0 interface and have dhcpd listening to br0.

All of this is from my head so some of my IP addressing/masks could well be wrong. Finally, if you want the BeagleBoards to be able to talk to each other as well as the host computer then you’ll need to enable IP forwarding / routing on the host and probably change the firewall to enable the relevant traffic. (Do a google for “linux IP routing” for more info).

Hi this works pretty well I use it to mount my host pc shares.
On the other hand I never had luck in bridging the usb network to the ethernet, so that the beagle eventually connects to the internet. I must be missign something…
Can you help me?

Fabio

...so what happens if you configure the g_ether device directly into
the kernel and avoid the absurd loading of the module nonsense?

(ah, the good old days of sysgen)

Windows doesn't know what to do with the USB Composite Gadget so that
has to go first.

Once you get into it, one would think that a statically configured
kernel would be more predictable anyway...

- dan

What is missing is that the host is typically not routing.

The Beagleboard needs a route through the host and then to the same
default gateway used by the host.

'netstat -rn' is your friend.

...don't forget that the Angstrom distribution is also running the X
server on the VNC port.

It is really cool to run the BB from one USB cable for power, network
and display...

- dan

Let me understand :

on the PC I'll add a bridge that bridges the say 192.168.4.1 (host PC
usb_g) to the ethernet 192.168.0.46 (host PC eth0), brctl will help.
My beagle will be 192.168.4.100 and the beagle routing table will have a
default gateway entry that is 192.168.0.46.
Will this work?

Thanks

Fabio

Nope - you are mixing bridging and routing. Bridging connects two bits of the same network whereas routing is used to connect different networks together. Technically either could be used in your situation. The best solution in this case would be to use routing with address translation. Have a look here: http://www.linux-magazine.com/Online/Blogs/Beagleblog/Connecting-to-the-world

…so what happens if you configure the g_ether device directly into
the kernel and avoid the absurd loading of the module nonsense?

Once you get into it, one would think that a statically configured
kernel would be more predictable anyway…

Its just quicker by a few milliseconds as the module doesn’t need to be loaded from disk. Its more reliable as you can’t get confused with incorrect module versions but then the cost is that it is less flexible as you can’t change the USB-OTG behaviour without a recompile and reboot.

Thanks for all the info, but my main question isn't answered yet. So
let me rephrase it.

I've loads of experience with networking and bridging or basic routing
in windows XP on my host pc is quite easy. Last time I've worked with
Linux was around ten years ago, so these skills might lack a little.

DHCP works sometimes, but isn't really reliable, hence I want to use
static IP's.

I've configured /etc/default/usb-gadget so g_ether loads and
beagleboard works with windows xp

I've configured /etc/network/interfaces:
iface usb0 inet static
        address 192.168.0.11
        netmask 255.255.255.0
        network 192.168.0.0
        gateway 192.168.0.1

Before plugging in usb:
ifconfig:
lo .....(nothing special here so I skipped it)
usb0 Link encap:Ethernet HWaddr 00:00:00:00:00:10
          UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

After plugging in usb:
[ 1161.503417] g_ether gadget: high speed config #2: RNDIS
[ 1161.509063] ADDRCONF(NETDEV_CHANGE): usb0: link becomes ready

and ifconfig:
lo ...
usb0 Link encap:Ethernet HWaddr 00:00:00:00:00:10
          inet6 addr: fe80::200:ff:fe00:10/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
          RX packets:18 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:824 (824.0 b) TX bytes:748 (748.0 b)
(so no ipv4 is configured)

After ifup usb0:
ifconfig:
lo ......
usb0 Link encap:Ethernet HWaddr 00:00:00:00:00:10
          inet addr:192.168.0.11 Bcast:192.168.0.255 Mask:
255.255.255.0
          inet6 addr: fe80::200:ff:fe00:10/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
          RX packets:54 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:4682 (4.5 KiB) TX bytes:6347 (6.1 KiB)

So now everything works fine, but I don't like to run ifup usb0
manually everytime I reboot or reconnect a BB because I have to
connect the BB to the serial port to do so. I want this step
"automated", how do I configure this?

You need “auto usb0” in /etc/network/interfaces to have the interface come up automatically.

You need "auto usb0" in /etc/network/interfaces to have the interface come up automatically.

Also tried that, but didn't work. When booting, the network interfaces
are configured before g_ether module is loaded, so the device doesn't
exist yet. It would also be possible to configure usb0 after g_ether
module is loaded, but when plugging in the usb-cable, the
configuration of usb0 is reset en ip-address is loss.

Hmmm… it works for me using the latest Angstrom. I’ve had similar race conditions during boot in the past which were hacked/fixed by using an rc.local script to run the relevant commands. If things still aren’t ready in time for rc.local then just stick a sleep statement in there.

Disabling NetworkManager and connman did the job :slight_smile: