How to set up an Ethernet over USB connection between the Sharp Zaurus SL-5000D and a Linux machine.

Author: Charles-Edouard Ruault
Version: 1.4, 02/19/2002
Credit: Thanks to the people who sent me remarks and asked questions, they helped me improve this document !

This Document assumes that the Linux machine is running a Linux kernel 2.4.x, with x>=14 This document describes the setup for a Zaurus ROM version lower than 1.10, for ROMs version 1.10 or newer, check this page.
DISCLAIMER: Use this patch at your own risk. It has received very limited testing and comes with no warranty !

1) Patch the linux kernel
The patch has been tested against kernel 2.4.14 and up.
Download the patch ( latest version can be found here )

Assuming your Linux sources are in /usr/src/linux do the following :
cp Zaurus-ethernet-over-usb.patch /usr/src
cd /usr/src
patch -p0 < Zaurus-ethernet-over-usb.patch

Now reconfigure the kernel to support CDCEthernet :
cd /usr/src/linux
make menuconfig
in "Code maturity level options", select "Prompt for development and/or incomplete code/drivers"
in "USB support", section "USB Network adaptors", select (as a module if you want) "USB Communication Class Ethernet device support (EXPERIMENTAL)"

If you've selected to add the driver as a module rebuild and install the modules ( cd /usr/src/linux && make dep && make clean && make modules && make modules_install ), then load the module : insmod CDCEther ( you should make sure that the core usb support is already active in your kernel : modules usbcore and usb-uhci should be loaded, if not run modprobe usb-uhci), otherwise rebuild the kernel and reboot.

2) Put the Zaurus on the cradle.
You should see a message like this in /var/log/messages :

now do ifconfig -a
you should see a new ethernet interface ( probably eth1 ), you can now configure it :

ifconfig eth1 192.168.1.200 netmask 255.255.255.0 broadcast 192.168.1.255 up

then try : ping 192.168.1.201 , if you've got a reply, you've won !

Note : if your PC is already on the 192.168.1.0/24 subnet ( it looks like it's common, given the number of people that reported this ), you should add a route to the zaurus in order for this to work : run route add -host 192.168.1.201 eth1

3) If you want to be able to connect to the internet from the Zaurus

You'll need to masquerade the Zaurus's IP from your machine.
Let's say that the ethernet interface that connects you to the internet is ethX and that it's IP is MY_IP, you would need to do the following :

make sure you enable the following options in the kernel : in "Networking options", select :

Then recompile your kernel & modules .... and reboot

then do the following :
route delete -net 192.168.1.0/24 eth1
route add -host 192.168.1.201 eth1
iptables -t nat -F
iptables -t nat -A POSTROUTING -j SNAT -o ethX --to MY_IP
echo 1 > /proc/sys/net/ipv4/ip_forward

on the Zaurus side :
add a default route pointing to your linux PC :
route add -host 192.168.1.200 usbd0
route delete -net 192.168.1.0/24 usbd0
route add default gw 192.168.1.200

then edit /etc/resolv.conf to add the IP of your DNS:
add a line like this nameserver xxx.xxx.xxx.xxx where xxx.xxx.xxx.xxx is the address of your nameserver.

4) If you're using hotplug, you can automate everything !

In order to have hotplug setup everything when you plug your Zaurus on your PC, you'll need to create a script /etc/hotplug/usb/CDCEther that should look like this ( feel free to adapt it to your needs )

#! /bin/bash
typeset -i num
num=`ifconfig | grep eth1 | wc -l`
if [ $num -eq 0 ] ; then
	ifconfig eth1 192.168.1.200 up
	route delete -net 192.168.1.0/24 eth1
	route add -host 192.168.1.201 eth1
fi
iptables  -t nat -F
iptables  -t nat -A POSTROUTING -j SNAT -o eth0 --to 192.168.109.201
echo 1 > /proc/sys/net/ipv4/ip_forward

This will automatically do the dirty work for you !

have fun !
Comments are weclome !