Usb Wireless Adapter quick howto

A quick howto for debian and ubuntu based systems for setting up usb wireless adapters. Just plug in the usb adaptor and do the following (All commands must be run as root user or prefixed with sudo)

apt-get install linux-wlan-ng pcmciautils wireless-tools

Then, shut down all your network interfaces. Suppose you have eth0 and eth1

ifconfig eth0 down
ifconfig eth1 down

Then,

modprobe prism2_usb prism2_doreset=1
wlanctl-ng wlan0 lnxreq_ifstate ifstate=enable

If the above did not return any errors, then you are almost through. Now, you need to scan your wireless network for any access points to connect to. To do this run the following command

iwlist wlan0 scan

This should return all access points in your network, For example,

wlan0     Scan completed :
          Cell 01 - Address: 00:0D:88:EA:E2:46
                    ESSID:"ZION"
                    Mode:Master
                    Encryption key:off
                    Channel:11
                    Quality:50/92  Signal level:-37 dBm  Noise level:-87 dBm

In the above case, look at the line ESSID:"ZION". ZION is the SSID of the access point we will connect to and and we also need to specify the authentication type. In this case, no encryption and hence it will be opensystem. So, now run

wlanctl-ng wlan0 lnxreq_autojoin ssid=ZION authtype=opensystem

Possible values for authtype are opensystem, sharedkey or not_set. After running the above command, in case you have DHCP enabled on the router,

dhclient
ifconfig wlan0

wlan0 must be assigned a IP address. In case, no IP is assigned, assign it with ifconfig. Something like,

ifconfig wlan0 192.168.1.3 up

Thats it! Your wireless adapter should be up and running. In case all of the above worked and still you are not able to browse wirelessly, check your routes. Remove all possible routes and add a default route through the wireless interface. For example, if 192.168.1.1 if the IP of the router,

route add default gw 192.168.1.1 wlan0

For the wireless adapter to be up and running on a reboot, this is the script i use. Modify it to suit your needs. Save the below script as /etc/init.d/mywlan

#!/bin/sh
. /lib/lsb/init-functions

do_start() {
        ifconfig eth0 down
        modprobe prism2_usb prism2_doreset=1
        wlanctl-ng wlan0 lnxreq_ifstate ifstate=enable
        wlanctl-ng wlan0 lnxreq_autojoin ssid=ZION authtype=opensystem
        dhclient
        echo "done"
}

do_stop() {
        ifconfig wlan0 down
        ifconfig eth0 up
        echo "done"
}

case "$1" in
  start)
        do_start
        exit 0
        ;;
  stop)
        do_stop
        exit 0
        ;;
  restart)
        do_stop || true
        do_start
        exit 0
        ;;
  *)
        log_warning_msg"Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac

Now, make the script run on startup

chmod 755 /etc/init.d/mywlan
update-rc.d mywlan defaults 90

Thats it! Reboot and your wireless network should be up and running.