Handhelds.org - Open source for handheld devices

UserPreferences

UsbNet


Connecting Your Linux Handheld to a Linux Desktop via USB

  1. Connecting Your Linux Handheld to a Linux Desktop via USB
    1. Introduction
    2. Kernel support
      1. Recompiling the kernel with USB networking support
    3. Setting up Hotplug
      1. Gentoo
      2. Red Hat, Fedora and other similar distributions
      3. Fedora Core 4
      4. Fedora Core 3
      5. Mandrake 10.1 with Kernel 2.6.x
      6. Debian
      7. Ubuntu Breezy (5.10)
      8. Ubuntu Edgy (6.10)
      9. Unsupported distro
    4. Testing
    5. Setting up IP-Masquerading (NAT)
      1. Debian
      2. Mandriva/Mandrake
      3. Gentoo
    6. Notes

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 [Self]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):

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

  1. Add usbnet to autoloaded modules:

    echo "usbnet" >> /etc/modules.autoload.d/kernel-2.6 

  2. 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" ) 

  3. 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.

- JelleKalf

Red Hat, Fedora and other similar distributions

  1. Add usbnet to be autoloaded on startup to the according file /etc/modules.conf

  2. 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.

  3. Make sure the next line is in ifcfg-usb0:

    ONBOOT=yes 

  4. restart hotplug to be sure it works :)

    service hotplug restart
    

- JelleKalf

Fedora Core 4

This shall work for FC4 & FC5 - CarlNordbeck

- PatrickErnzer

Fedora Core 3

  1. Do a "modprobe usbnet" before attempting to use on FC3 (not sure what the equivalent of "/etc/modules.conf" is in FC3 yet).

  2. 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
    

  3. Plug in the handheld

  4. If the network isn't established automatically, use

    ifup usb0

  5. To enable routing from the handheld through the LINUX host, set the "fowarding flag":

    echo 1 > /proc/sys/net/ipv4/ip_forward

  6. [Optional] Copy the '/etc/resolv.conf' file on the LINUX host to the handheld to allow for DNS lookups.

- CharlieLindahl

Mandrake 10.1 with Kernel 2.6.x

  1. 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 

  2. 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
    

  3. Restart hotplug to make sure it works

  4. The interface should appear active once the service is required

  5. Finally, use the appropriate Control Center wizard to share your internet connection.

- LeopoldoAraujo

Debian

This works for me, might break for others:

  1. Add usbnet to be autoloaded on startup:

    echo "usbnet" > /etc/modutils/usbnet
    update-modules 
    

  2. 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
    

  3. 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.

--HenryPauli

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).

  1. Add usbnet to be autoloaded on startup:

    echo "usbnet" > /etc/modutils/usbnet
    update-modules 
    

  2. 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
    

  3. Add script /etc/network/ipaq

     #!/bin/sh
     sleep 5
     exit 0
    

  4. Ensure that /etc/network/ipaq is executable

     chmod a+x /etc/network/ipaq
    

--MartynWelch

Ubuntu Edgy (6.10)

--JuanPabloRamirez

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.

--StéphaneTudoret

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

- ArjanSchrijver

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

Mandriva/Mandrake

1. Install iptables (as root):
urpmi iptables
2. Make sure it is started at boot:
chkconfig --add iptables
3. 'Start' iptables:
/etc/rc.d/init.d/iptables start
4. Turn on ip forwarding:
echo '1' > /proc/sys/net/ipv4/ip_forward
5. 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 [WWW]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.