Connecting Your Linux Handheld to a Linux Desktop via USB
- Connecting Your Linux Handheld to a Linux Desktop via USB
Introduction
This document describes how to set up USB networking between a Linux system and a handheld running Familiar.
Manually configuring usbnet every time is too slow. The kernel boots within seconds and wants usb0 on your desktop to already be online by then. The only solution is a proper hotplug configuration, so that all setup of the connection is handled automatically. Hotplug is available in almost every distribution. For internet access from your handheld through your desktop machine, you will also need to set up NAT (ip-masquerading) on your desktop computer.
Note: all of the changes in this document are to be performed on your desktop machine (ie, not on the handheld). However, if you are using Familiar 0.8.0 there are some things that need to be fixed before usbnet will work properly - see
FamiliarReleaseNotes. Newer versions already have these fixes applied.
Note2: It doesn't have to be usb0 - you might already have usb0 interface configured for something else even not knowing about it. Check dmesg for details.
Note3: If you have reliability problems and use an iPAQ 39xx with the old usb-eth module, then switching to the newer USB gadget g_ether module might help. This is described in WindowsXpUsbNetworkHowTo. It is listed there because it was originally considered more important for Windows, however, for me it was also more reliable in combination with Linux. -- PatrickOhly
Kernel support
For this to work, you must have USB networking enabled in the kernel. Most distributions already include this as a module. If you have compiled your own custom kernel, the following section describes how to enable USB networking in the configuration. Otherwise skip down to the section on setting up Hotplug.
Recompiling the kernel with USB networking support
If you have previously compiled your own custom kernel, to add support for USB networking you will need to enable the following options using make menuconfig (in this order):
-
For the 2.4 kernel:
-
Code Maturity Level Options --->
-
[*] Prompt for development and/or incomplete code/drivers
-
USB support --->
-
<M> USB-to-USB Networking cables, Linux PDAs, ... (EXPERIMENTAL)
-
For the 2.6 kernel:
-
Device Drivers ---> USB support ---> USB Network Adapters --->
-
<M> Multi-purpose USB Networking Framework
-
<M> Simple USB Network Links (CDC Ethernet subset)
-
[*] Embedded ARM Linux links (iPaq, ...)
Once you have selected these options, recompile and install the kernel modules as you would normally. If you are just turning these options on and no others, you might not need to reboot, as the modules will already be available for immediate use.
Setting up Hotplug
Gentoo
-
Add usbnet to autoloaded modules:
echo "usbnet" >> /etc/modules.autoload.d/kernel-2.6
-
Configure /etc/conf.d/net and create and entry for usb0 like:
config_usb0=( "192.168.0.200 broadcast 192.168.0.255 netmask 255.255.255.0" )
-
Create a symlink from net.lo to net.usb0
ln -sf /etc/init.d/net.lo /etc/init.d/net.usb0
Udev will try to execute every /etc/init.d/net.$INTERFACE that comes online. So after loading the usbnet module, the interface will still be down. It will wait until usbnet on the handheld is started and then it will see usb0 coming online. Make sure you then have your configuration ready.
Red Hat, Fedora and other similar distributions
-
Add usbnet to be autoloaded on startup to the according file /etc/modules.conf
-
Create an file in /etc/sysconfig/network-scripts/ called ifcfg-usb0 Check ifcfg-eth0 for an example and use the IP values written above in the gentoo section.
-
Make sure the next line is in ifcfg-usb0:
ONBOOT=yes
-
restart hotplug to be sure it works
service hotplug restart
Fedora Core 4
-
Create a file /etc/sysconfig/network-scripts/ifcfg-usb0 with the following contents:
# USB configuration for iPAQ DEVICE=usb0 BOOTPROTO=none IPADDR=192.168.0.220 NETMASK=255.255.255.255 ONBOOT=yes MII_NOT_SUPPORTED=no
-
Create a file /etc/sysconfig/network-scripts/route-usb0 with the following contents:
192.168.0.202 scope host dev usb0
-
Plug in the handheld
-
To enable routing from the handheld through the LINUX host.
-
Edit /etc/sysctl.conf and change line "net.ipv4.ip_forward = 0" to "net.ipv4.ip_forward = 1".
sudo /sbin/sysctl -p /etc/sysctl.conf sudo /sbin/iptables -t nat -F sudo /sbin/iptables -t nat -A POSTROUTING -j SNAT -o eth0 --to 192.168.1.1 sudo /etc/init.d/iptables save
This shall work for FC4 & FC5 - CarlNordbeck
-
Configure your IP (192.168.0.202), gateway (192.168.0.200) and DNS on the handheld
Fedora Core 3
-
Do a "modprobe usbnet" before attempting to use on FC3 (not sure what the equivalent of "/etc/modules.conf" is in FC3 yet).
-
Create a file /etc/sysconfig/network/scripts/ifcfg-usb0 with the following contents:
# USB configuration for IPAQ DEVICE=usb0 BOOTPROTO=static IPADDR=192.168.0.200 NETMASK=255.255.255.0 NETWORK=192.168.0.0 BROADCAST=192.168.0.255 ONBOOT=yes MII_NOT_SUPPORTED=no
-
Plug in the handheld
-
If the network isn't established automatically, use
ifup usb0
-
To enable routing from the handheld through the LINUX host, set the "fowarding flag":
echo 1 > /proc/sys/net/ipv4/ip_forward
-
[Optional] Copy the '/etc/resolv.conf' file on the LINUX host to the handheld to allow for DNS lookups.
Mandrake 10.1 with Kernel 2.6.x
-
Add usbnet to be automatically loaded on startup by adding or modifing the install interface line in the file /etc/modprobe.conf which should look like the following line:
install usb-interface /sbin/modprobe uhci-hcd usbnet; /sbin/modprobe ehci-hcd usbnet; /bin/true
-
Create a file called /etc/sysconfig/network-scripts/ifcfg-usb0 An example on ifcfg-usb0 parameters would be:
DEVICE=usb0 BOOTPROTO=static IPADDR=192.168.0.200 NETMASK=255.255.255.0 NETWORK=192.168.0.0 BROADCAST=192.168.0.255 ONBOOT=yes MII_NOT_SUPPORTED=no
-
Restart hotplug to make sure it works
-
The interface should appear active once the service is required
-
Finally, use the appropriate Control Center wizard to share your internet connection.
Debian
This works for me, might break for others:
-
Add usbnet to be autoloaded on startup:
echo "usbnet" > /etc/modutils/usbnet update-modules
-
Add the following to /etc/network/interfaces
mapping hotplug script grep map usb0 iface usb0 inet static address 192.168.0.200 netmask 255.255.255.0 broadcast 192.168.0.255
-
Run
/etc/init.d/networking restart
Note, if your computer is already on a home network, you might need to use a different IP address configuration in /etc/network/interfaces. You could use, say, 192.168.1.200 for 'address' and 192.168.1.255 for 'broadcast'.
- KoenKooi
See http://www.handhelds.org/moin/moin.cgi/UsbNetHotplug
Make (or change to, if you have installed synce) /etc/hotplug/usb/ipaq (Also for (K)Ubuntu)
#!/bin/sh
# iPAQ - ${DEVICE} USB Event: ${ACTION}
if [ -x /etc/init.d/SA1100-USB-NIC ]; then
if [ "${ACTION}" = "add" ]; then
sleep 5
/home/draak/ipaqnet start && exit 0
else
/home/draak/ipaqnet stop && exit 0
fi
fi
The "sleep 5" is importent, otherwise your Handheld will freeze upon connect.
Ubuntu Breezy (5.10)
This is similar to the Debian example, the process needs to be slowed down to get it to work (as suggested by HenryPauli).
-
Add usbnet to be autoloaded on startup:
echo "usbnet" > /etc/modutils/usbnet update-modules
-
Add the following to /etc/network/interfaces
mapping hotplug script grep map usb0 iface usb0 inet static address 192.168.0.200 netmask 255.255.255.0 broadcast 192.168.0.255 pre-up /etc/network/ipaq
-
Add script /etc/network/ipaq
#!/bin/sh sleep 5 exit 0
-
Ensure that /etc/network/ipaq is executable
chmod a+x /etc/network/ipaq
Ubuntu Edgy (6.10)
-
This version of Ubuntu includes a newer kernel (2.6.17+) that breaks the compatibility with Familiar 0.8.4 (as it ships). You have to follow the steps outlined in WindowsXpUsbNetworkHowTo to enable the backported g_ether driver instead of usb-net. Ubuntu loads the cdc_subset driver automatically when the PDA is connected. You might have to manually load cdc_ether and usbnet on the Ubuntu host.
Another solution is to bridge the PDA with the ubuntu host as described in "Configuring the Ubuntu machine" section of http://wiki.openzaurus.org/HowTos/Bridging_with_Ubuntu. That is running well without g_ether with my Ipaq 3850.
Unsupported distro
If you want, you can also set up the usbnet by hand.
Execute the following commands to set it up after connecting the device:
/sbin/modprobe usbnet /sbin/ifconfig usb0 192.168.1.200
Testing
You should now be able to plug in the handheld and ping it from your desktop machine (and vice versa).
Setting up IP-Masquerading (NAT)
In order to access the internet from your handheld through your desktop machine (eg. for installing packages with ipkg) you will need to set up NAT on your desktop. Instructions follow for various distributions. See also your distribution's own documentation.
Debian
-
Note that I did this on Sarge, but as far as I know, it should work on Woody and Sid similarly.
-
Install ipmasq:
apt-get install ipmasq
Debconf will ask you a few questions. Answer "no" to the question about ppp, unless you plan to use ipmasq for some other purpose. From here on out, I'll assume you aren't planning any such thing. Next, it will ask you if you want to start it at boot. It should be safe to say yes to this, although I did not. If not, you can start it manually by doing this:/etc/init.d/ipmasq start /etc/init.d/ipmasq-kmod start
When Debconf asks you if you want to start ipmasq, answer "no."Also, you will need some modules in your kernel before you can use ipmasq. Consult the html documentation in /usr/share/doc/ipmasq/ipmasq.html to find out if you have the correct modules for your kernel.
-
Configure ipmasq for usb0:
cp /etc/ipmasq/rules/A01interfaces.def /etc/ipmasq/rules/A01interfaces.rul
Now, edit the file you just created and change this line:INTERNAL=$(enumerate-if | sort -u | grep -v lo)
to this:INTERNAL=$(enumerate-if | sort -u | grep usb)
-
Start ipmasq. NAT should be up and running for your handheld USB internet connection.
As always, however, your mileage may vary.
--Brian Drell
-
Apart from the ipmasq-method, there is an other easy method that doesn't require ipmasq, only iptables:
-
Turn on ip forwarding:
echo 1 > /proc/sys/net/ipv4/ip_forward
-
Add an NAT rule:
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to-source 192.168.0.10
The "eth0" is the interface through which your pc is accessing the network. "192.168.0.10" is your ip address for that interface.To have this started at boot:
-
Copy-paste the 2 previous commands in a file, make it executable and place it in the /etc/init.d-directory
chmod u+x filename mv filename /etc/init.d/
-
Get the current runlevel and make a symbolic link in the cron-directory corresponding to your runlevel (replace the X with the number that the runlevel-command returned)
runlevel ln -s /etc/init.d/filename /etc/rcX.d/S99filename
The filename in the /etc/rcX.d-dir doesn't have to be the same than in the /etc/init.d-dir, but it's easier if you're looking for it.-- Ruben Troncon
-
Do all of this as root.
-
Do all of the following actions as root.
Mandriva/Mandrake
1. Install iptables (as root):urpmi iptables2. Make sure it is started at boot:
chkconfig --add iptables3. 'Start' iptables:
/etc/rc.d/init.d/iptables start4. Turn on ip forwarding:
echo '1' > /proc/sys/net/ipv4/ip_forward5. Add tables for NATing your handheld:
iptables -t nat -A POSTROUTING -o eth0 -s 192.168.0.202/32 -j MASQUERADE iptables -A INPUT -i eth0 -m state --state NEW,INVALID -j DROP iptables -A FORWARD -i eth0 -m state --state NEW,INVALID -j DROP
6. Ping away using either your handheld or your host computer.
7. If it works, save the rules/tables:/etc/rc.d/init.d/iptables save
8. Make sure that ip forwarding happens at the next boot. Edit the file /etc/sysconfig/network. Make sure that there is a line that says FORWARD_IPV4="yes". If that line says 'no', change it to yes. Save the file.
Gentoo
There is a lovely NAT howto for Gentoo
here. Note that you will need to make a few substitutions -- substitute "usb0" for "eth0" and substitute "eth0" for "eth1", unless your main internet connection is something else. But, you're running Gentoo, so you probably knew that already.
Notes
If you use a Kernel greater then 2.6.16, you need to load the modules cdc_subset and cdc_ether besides usbnet, otherwise it won't work.