HOWTO Compile rt73usb from rt2x00 sources under Ubuntu 7.04 (Feisty Fawn)

Install the neccesary build tools:
apt-get install kernel-package gcc binutils libc6-dev libssl-dev
Use aphost and rt2x00 snapshots:
cd /tmp/src
wget http://hostap.epitest.fi/releases/snapshots/hostapd-0.6-2007-03-25.tar.gz
wget http://rt2x00.serialmonkey.com/rt2x00-cvs-daily.tar.gz (
Unpack both into /tmp/src
tar xvzf rt2x00-cvs-daily.tar.gz
tar xvzf hostapd-0.6-2007-03-25.tar.gz
and edit hostap defconfig file: Replace
# Driver interface for drivers using Devicescape IEEE 802.11 stack
#CONFIG_DRIVER_DEVICESCAPE=y
# Currently, driver_devicescape.c build requires some additional parameters
# to be able to include some of the kernel header files. Following lines can
# be used to set these (WIRELESS_DEV must point to the root directory of the
# wireless-dev.git tree).
#WIRELESS_DEV=/usr/src/wireless-dev
#CFLAGS += -I$(WIRELESS_DEV)/include
#CFLAGS += -I$(WIRELESS_DEV)/net/d80211
#CFLAGS += -D_LINUX_TYPES_H
with
# Driver interface for drivers using Devicescape IEEE 802.11 stack
CONFIG_DRIVER_DEVICESCAPE=y
# Currently, driver_devicescape.c build requires some additional parameters
# to be able to include some of the kernel header files. Following lines can
# be used to set these (WIRELESS_DEV must point to the root directory of the
# wireless-dev.git tree).
WIRELESS_DEV=/tmp/src/rt2x00-cvs-2007041802/ieee80211
CFLAGS += -I$(WIRELESS_DEV)
CFLAGS += -I$(WIRELESS_DEV)/net/d80211
After that
cp defconfig .config && make
and voila, it compiles! Go grab a green tea in the mean time, and once it finalises, adapt the Makefile for Debian/Ubuntu standards to
install: all
        for i in $(ALL); do cp $$i /usr/sbin/$$i; done 
and run
sudo make install
We now need to compile a vanilla kernel (without ubuntu's -mm patches) to make rt2x00 work (source: http://rt2x00.serialmonkey.com/phpBB2/viewtopic.php?t=3547)
cd /usr/src
sudo wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.20.7.tar.bz2
sudo tar xjf linux-2.6.20.7.tar.bz2 
sudo apt-get install kernel-package libncurses5-dev fakeroot wget bzip2
sudo cp /boot/config-`uname -r` ./.config
sudo make menuconfig
Go to Load an Alternate Configuration File and choose .config (which contains the configuration of the current Ubuntu kernel you are running). Then browse through the kernel configuration menu and make your choices (or do it in vi and check .config). For 2.6.20, all required options were already set in the original Ubuntu configuration (either set to y or m) as you can see from the .config extract below:
        Kernel config option            Required for component
        ------------------------------------------------------------------
        # CONFIG_NET_RADIO              all
        # CONFIG_PCI                    rt2400pci, rt2500pci, rt61pci
        # CONFIG_USB                    rt2500usb, rt73usb
        # CONFIG_HOTPLUG                rt61pci, rt73usb
        # CONFIG_FW_LOADER              rt61pci, rt73usb
        # CONFIG_DEBUG_FS               rt2x00 (optional, only for debug)
        # CONFIG_INPUT                  rfkill
        # CONFIG_CRYPTO                 d80211
        # CONFIG_CRYPTO_AES             d80211
        # CONFIG_CRYPTO_AES_586         d80211 (optional, only for x86)
        # CONFIG_CRYPTO_AES_X86_64      d80211 (optional, only for x86_64)
        # CONFIG_CRYPTO_ARC4            d80211
        # CONFIG_CRYPTO_ECB             d80211 (Only for kernels > 2.6.19)
Make the vanilla kernel with the Ubuntu configuration:
make-kpkg clean 
fakeroot make-kpkg --initrd --append-to-version=-rt2x00-attempt kernel_image kernel_headers
Create a symlink for the proprietary firmware in /lib/firmware. Note that the link target "2.6.20.7-rt2x00-attempt" is a result of the used kernel source (in our case linux-2.6.20.7.tar.bz2) and the make-kpkg argument "--append-to-version=-rt2x00-attempt"!
ln -s 2.6.20-15-powerpc/  2.6.20.7-rt2x00-attempt
and install the kernel packages you just created (through compilation):
sudo dpkg -i ../linux-image-2.6.20.7-rt2x00-attempt_2.6.20.7-rt2x00-attempt-10.00.Custom_powerpc.deb 
No changes are required in /etc/yaboot.conf (since the newly installed kernel becomes the default kernel anyway), but just in case, run
sudo ybin -v

Congratulations: Reboot and enjoy new vanilla Kernel that is ready for the rt2x00 compilation as outlined in the next steps.

IvD (rt2x00 maintainer) suggests enabling mac80211 inside the Ubuntu kernel (source: same thread as above). Fortunately for us, the stock Ubuntu .config that we used before for compiling the kernel contains already
CONFIG_IEEE80211=m
# CONFIG_IEEE80211_DEBUG is not set
CONFIG_IEEE80211_CRYPT_WEP=m
CONFIG_IEEE80211_CRYPT_CCMP=m
CONFIG_IEEE80211_CRYPT_TKIP=m
CONFIG_IEEE80211_SOFTMAC=m
# CONFIG_IEEE80211_SOFTMAC_DEBUG is not set
so we must disable CONFIG_MAC80211 in the rt2x00 config file named rt2x00_compat.h by removing (or commenting) the line containing ax25_ptr.

Apply patch from http://rt2x00.serialmonkey.com/phpBB2/viewtopic.php?t=3616 (direct download link for the patch file: http://rt2x00.serialmonkey.com/phpBB2/download.php?id=1225) and apply the patch via:

patch -p0 < fix.patch

make

sudo make install
rmmod the old modules, and install the new ones (modprobe rt73usb)

This is my simple configuration for the wlan card in /etc/network/interfaces (without any WEP or WPA configuration):

# The wlan interface
auto wlan0 
iface wlan0 inet static
pre-up iwconfig wlan0 mode master essid "YOUR_ESSID"
address 192.168.1.254
netmask 255.255.255.0
To test the card manually, use the following set of commands in a shell:
ifconfig wlan0 down
iwconfig wlan0 mode master essid "YOUR_ESSID"
ifconfig wlan0 192.168.1.254 
ifconfig wlan0 up
Once you confirmed via ifconfig that the card is detected and runs fine, you can change the settings for the freshly compiled hostapd in /etc/hostapd/hostapd.conf to:
interface=wlan0
driver=devicescape
hw_mode=g
channel=4
debug=2
beacon_int=100
dtim_period=2
ssid=YOUR_ESSID
and finally launch hostap with
hostapd -dd /etc/hostapd/hostapd.conf
For hostap to launch automatically on system startup, edit /etc/default/hostapd to read:
RUN_DAEMON="yes"
DAEMON_CONF="/etc/hostapd/hostapd.conf"
In case you still have trouble, you can try with IPv4 only by putting the ipv6 module in the modules blacklist to increase simplicity. Add in /etc/modprobe.d/blacklist
blacklist ipv6

Good luck, and have fun!

Some additional observations: The WLAN is detected on my triple-boot MacBook by Ubuntu 7.04, OS X 10.4.9 and Windows XP. However, I can only get a stable connection under XP, while OS X and Ubuntu keep dropping the connection (and sometimes do not even obtain a DHCP lease). On another Windows XP laptop (Toshiba M30 with Intel Centrino chipset), the connection is also stable, but packets over 1024 bytes (including 8 byte ICMP header information) get dropped. I verified this via
ping -s 1016 www.latz.cc
This works perfectly fine and all packets arrive. However,
ping -s 1017 www.latz.cc
(and any other packet size bigger than 1017 excluding the 8 byte ICMP information for that matter) fails. Packages are simply dropped (again: only on the Toshiba, the MacBook under XP does not exhibit this behaviour). Any suggestions and ideas are welcome!

Achim J. Latz, achim@latz.cc, 01.12.2008