Networking a Balloon over USB

The standard method of connecting a Balloon to the world without adding any extra hardware is using USB to connect it to a PC and running a network connection over this cable. This page describes how to set this up and use it. The details depend on which hardware you have (balloon3 or balloon2) whther the PC end is Linux or Windows, and which kernel version you have on the balloon and the host (because the names of modules and interfaces change).

Note there are also many other ways of connecting up the balloon - USBserial, USB<->Ethernet adaptor, CF ethernet or wireless adaptor, zigbee, and plain serial. See BalloonConnectivity. This networking method is not particularly fast (nominal 1Mb/sec) but it's simple - all you need is a suitable socket/cable and a bit of config. For faster networking that loads the CPU less plug a CF ethernet card into the CF slot, or include an ethernet chip on your expansion board.

How it fits together

The way this all works is a bit complicated so here is an explanation of what is going on (very helpful if it isn't working).

The usb-client side of the interface (the Balloon) exists as soon as the necessary modules are loaded (and it is configured). The USB-host side of the interface (normally a PC) does not exist until the cable is connected, even though it is configured with a static address. A much simpler set-up is possible with both side being statically configured, but the problem there is that something needs to do 'ifup usb0' (or 'ifup usbf' on kernel 2.4) on the balloon end, and unless you have a serial connection, or a keyboard and display login, there is no way to do that. Using dhcp the interface is prodded to configure itself as soon as the cable is plugged in.

The host-side config is set to run the dhcp server as soon as the usb0 interface comes up, and to dish out exactly one address to each usb'n' interface. So this is effectively static configuration using DHCP. The max lease time is set low so that that address is always available; the downside being that the balloon asks to renew its address very often. Each time the balloon powers up its usb-client interface has a different MAC address because there is no real hardware, so it is randomly generated - this means that the PC-side thinks it is a new machine each time so won't hand out the same IP address unless the previouslease has expired.

The dhcp client on the balloon side will give up some time after power-up (15 mins?) so you may need to reboot if plugging the usb cable in a long time after powering-up.

If you want to support multiple balloons being plugged into one host then you need to configure multiple usb interfaces (usb0, usb1, usb2 etc) and corresponding dhcp-server stanzas. You also need to enable each one in /etc/default/dhcp3-server.

Configuration package

If you have a Debian machine then we have a package ('tcl-usbnet') which will try to do the necessary config as decribed below and 'just make it work' for you. It will only try to do so if your network config has no obvious usb0 config in there already. It's not terribly clever so may not actually work if your network config is clever but it works here pretty well: http://balloonboard.org/files/balloon3/misc/tcl-usbnet_0.6_all.deb

Wiring

You cannot connect a USB cable directly to a balloon 3: a socket and terminator chip (or at least resistor) is required. Normally a CUED or Balloonz IO board is required. We are using the slave socket in the mechanism described on this page.

The balloon has both host and slave USB sockets. For this scheme we need to use the slave socket [(J7) | http://www.balloonboard.org/hardware/205/con/usbs.html] (the one that's next-but-one to the serial/jtag socket). The other end (type A plug) goes in your PC or hub.

http://balloonboard.org/hardware/205/topconnslv.png

Software Setup

This page tells you all about the usbnet driver and what it can do, including configuration, but here's the potted version for the Balloon. Resort to the above page if this info doesn't do it for you, and you might also find the BalloonUSBDebugging page helpful, where people record their problems and solutions - put yours here if you had trouble.

Note that kernel 2.6 is different kernel 2.4 due to changes in names of modules and interfaces. You can have a 2.4 kernel balloon and a 2.6 kernel PC and it will still work - just choose the right instructions.

kernel 2.6

PC side config

Your kernel must support the ethernet gadget interface. This was true from the 2.6.16.5 balloon port for balloon3. This only ever worked on the 2.6.12 port for balloon2, (and needs updating).

The allow-hotplug line enables the dhcp-server lines to be run when the usb0 interface comes up (even when using udev).

If your PC is an Ubuntu system, there are a few other steps required to get this to work. See USBNetworkingUbuntu.

The last two lines are to support the fully automatic DHCP configuration. For this to work you need to configure DHCP on this interface, as follows.

Note that the usb0 interface will not appear until the cable is plugged into a properly configured balloon (because there is no real interface until that connection is made).

IMPORTANT You must configure it to make sure it is only operating on usb0 otherwise you can cause huge problems on your subnet. Edit /etc/default/dhcp3-server:

INTERFACES="usb0"

Then add the following to /etc/dhcp3/dhcpd.conf:

subnet 10.1.1.0 netmask 255.255.255.0 {
  range 10.1.1.2 10.1.1.2;
  option routers 10.1.1.1;
} 

You need to set standard info for your network in here, and a short lease time can be helpful, e.g.:

option domain-name "a.real.domain";
option domain-name-servers 192.168.10.3;
option subnet-mask 255.255.255.0;
default-lease-time 600;
max-lease-time 120;

Alternatively you can set up manual forwarding for a specific interface. You can do this for a session with

iptables -P FORWARD ACCEPT

Balloon side config

Balloons are normally configured to load either this or g_serial by default in /etc/modules. This modules brings in pxa27x_udc too.

The usb0 interface should now be shown by ifconfig -a

Use

Once it is set up then as soon as the USB cable is plugged into the balloon the g_ether module brings up the usb0 interface on the balloon side, and the usb0 interface on the PC end is created and also brought up, at which point the dhcp server starts and provides an IP address and config to the balloon. If for any reason stuff was not working (e.g. the DHCP timed out) then replugging the USB cable once the config is fiddled with should make it all try again.

If you have trouble check these things:

* modprobe g_ether on balloon should produce output like this:

usb0: Ethernet Gadget, version: May Day 2005
usb0: using pxa27x_udc, OUT Bulk-out-5 IN Bulk-in-4 STATUS Interrupt-in-6
usb0: MAC 66:31:da:44:94:64
usb0: HOST MAC 2a:24:eb:8d:2b:6b
usb0: RNDIS ready
udc: registered gadget driver 'ether'

Plugging in the USB cable should produce this sort of output on the balloon:

usb0: full speed config #1: 100 mA, Ethernet Gadget, using CDC Ethernet Subset


CategoryDocumentation

Balloonboard: BalloonDevelopment/USBNetworking (last edited 2011-04-05 15:09:34 by NeilWilliams)