#Using Wi-Fi USB adapters

<span class="abstract">
This article explains how to use the following USB Wi-Fi adapters on 
your Acme Board.
</span>

The USB Wi-Fi adapter tested, based on Realtek 8188su or 8188csu chips, are:

*  DWA-131 D-Link WirelessN Nano USB adapter (HW Ver A1, F/W Ver 1.20)
*  DWA-131 D-Link WirelessN Nano USB adapter (HW Ver B1, F/W Ver 2.01)
*  Digicom USB Wave 150 nano dongle
*  Digitus USB wireless adapter 150N

<img src="./wifi_adapters.jpg"/>

Insert the Wi-Fi USB adapter on your Acme Board. These messages should 
appear on the debug port or by typing **dmesg** command:

<pre class="minicom">
~# <b>dmesg</b>
usb 2-3: USB disconnect, device number 5
usb 2-3: new full-speed USB device number 6 using at91_ohci
usb 2-3: not running at top speed; connect to a high speed hub
usb 2-3: New USB device found, idVendor=2001, idProduct=330d
usb 2-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 2-3: Product: 802.11n WLAN Adapter
usb 2-3: Manufacturer: Realtek
usb 2-3: SerialNumber: 00e04c000001
</pre>

If the driver is correctly present the messages continue with this part:

<pre class="minicom">
r8712u: DriverVersion: v7_0.20100831
r8712u: register rtl8712_netdev_ops to netdev_ops
r8712u: USB_SPEED_LOW with 4 endpoints
r8712u: Boot from EFUSE: Autoload OK
r8712u: CustomerID = 0x0000
r8712u: MAC Address from efuse = 00:1f:1f:75:28:93
</pre>

If you don't obtain these messages probably you need to change your
Kernel configuration (see the **Kernel configuration** below).

When you get the right messages try to type this command:

<pre class="minicom">
debarm:~# <b>cat /proc/net/wireless</b>
Inter-| sta-|   Quality        |   Discarded packets               | Missed | WE
 face | tus | link level noise |  nwid  crypt   frag  retry   misc | beacon | 22
 wlan0: 0000    0.    0.    0.       0      0      0      0      0        0
</pre>


## Install the Wireless-tools

To configure and use the Wi-Fi adapter you need to install the <a href="http://en.wikipedia.org/wiki/Wireless_tools_for_Linux">Wireless tools for Linux</a>, a package of Linux commands intended to support 
and facilitate the configuration of wireless devices.

To install this package type:

<pre class="minicom">
debarm:~# <b>apt-get update</b>
debarm:~# <b>apt-get install wireless-tools</b>
</pre>

When finished type:

<pre class="minicom">
debarm:~# <b>iwconfig</b>
lo        no wireless extensions.
 
eth0      no wireless extensions.
 
wlan0     unassociated  Nickname:"rtl_wifi"
          Mode:Auto  Access Point: Not-Associated   Sensitivity:0/0  
          Retry:off   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off
          Link Quality:0  Signal level:0  Noise level:0
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0
</pre>

which provides info about the wireless extensions of each network adapter (in this case wlan0).

## Network configuration

As a first configuration example, we'll show you how to get access to
an open Wi-Fi LAN. Edit the file <b>/etc/network/interfaces</b> and 
add these lines:

<pre class="minicom">
auto wlan0
iface wlan0 inet dhcp
  wireless-essid [your_essid] 
  wireless-mode managed 
</pre>

Restart the network services typing:

<pre class="minicom">
debarm:~# <b>/etc/init.d/networking restart</b>
...
Listening on LPF/wlan0/5c:d9:98:a7:3a:fe                                        
Sending on   LPF/wlan0/5c:d9:98:a7:3a:fe                                        
Sending on   Socket/fallback                                                    
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 5                     
DHCPOFFER from 192.168.1.1                                                      
DHCPREQUEST on wlan0 to 255.255.255.255 port 67                                 
DHCPACK from 192.168.1.1                                                        
bound to 192.168.1.2 -- renewal in 8171 seconds.                                
done.    
</pre>

<pre class="minicom">
debarm:~# <b>ifconfig</b>
...
wlan0     Link encap:Ethernet  HWaddr 5c:d9:98:a7:3a:fe                         
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0        
          inet6 addr: fe80::5ed9:98ff:fea7:3afe/64 Scope:Link                   
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1                    
          RX packets:4057 errors:0 dropped:0 overruns:0 frame:0                 
          TX packets:327 errors:0 dropped:0 overruns:0 carrier:0                
          collisions:0 txqueuelen:1000                                          
          RX bytes:287147 (280.4 KiB)  TX bytes:21864 (21.3 KiB)         
</pre>

## Connect to a WEP-protected LAN

Edit the file <b>/etc/network/interfaces</b> and set <b>wireless-key</b>:

<pre class="minicom">
auto wlan0
iface wlan0 inet dhcp
  wireless-essid [your_essid]
  wireless-key [your_wep_key]
</pre>

Restart the network services as in the previous section.

## Install the wpa_supplicant for encrypt access

<a href="http://en.wikipedia.org/wiki/Wpa_supplicant">Wpa supplicant</a> is a software implementation of an IEEE 802.11i supplicant 
for Linux that manages the authentication on the Wi-Fi link.

To install these packages type:

<pre class="minicom">
debarm:~# <b>apt-get update</b>
debarm:~# <b>apt-get install wpasupplicant</b>
</pre>

Now add in the file <b>/etc/network/interfaces</b> the configuration for the <b>wlan0</b> 
network adapter to add Wi-Fi Protected Access (WPA) or Wi-Fi Protected Access II (WPA2).

<pre class="minicom">
auto wlan0
iface wlan0 inet dhcp
wpa-driver wext
wpa-ssid [your_essid]
wpa-ap-scan 2
wpa-proto RSN
wpa-pairwise CCMP
wpa-group CCMP
wpa-key-mgmt WPA-PSK
wpa-psk [your_hex_key]
</pre>

Change the fields <b>[your_essid]</b> with the SSID of your access point and 
<b>[your_hex_key]</b> with the WPA-PSK key.

To generate a WPA-PSK key from WPA ascii key use this command:

<pre class="minicom">
wpa_passphrase [your_essid] [your_ascii_key]
</pre>

For example on my access point called "acme" that uses the ascii key 
"netusg20" the command is this:

<pre class="minicom">
debarm:/etc/init.d# <b>wpa_passphrase acme netusg20</b>
network={
        ssid="acme"
        #psk="netusg20"
        psk=38c309a773a6c936c31aeb8bcb5bc44d60539715524e77464759f29095bfc1f3
}
</pre>

Copying the psk code the <b>/etc/network/interfaces</b> file becomes:

<pre class="minicom">
auto wlan0
iface wlan0 inet dhcp
wpa-driver wext
wpa-ssid acme
wpa-ap-scan 2
wpa-proto RSN
wpa-pairwise CCMP
wpa-group CCMP
wpa-key-mgmt WPA-PSK
wpa-psk 38c309a773a6c936c31aeb8bcb5bc44d60539715524e77464759f29095bfc1f3
</pre>

Now type:

<pre class="minicom">
debarm:~# <b>/etc/init.d/networking restart</b>
</pre>

After a while if the dhcp are working well you will obtain your interface up. 
You can also detach the eth0 lan cable to try to access your FOXG20 directly from the Wi-Fi link.

<pre class="minicom">
debarm:~# <b>iwconfig wlan0</b>
wlan0     IEEE 802.11bg  ESSID:"acme"  Nickname:"rtl_wifi"
          Mode:Managed  Frequency:2.447 GHz  Access Point: 00:21:29:69:C2:D8   
          Bit Rate:54 Mb/s   Sensitivity:0/0  
          Retry:off   RTS thr:off   Fragment thr:off
          Encryption key:****-****-****-****-****-****-****-****   Security mode:open
          Power Management:off
          Link Quality=100/100  Signal level=100/100  Noise level=0/100
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0
</pre>

#Kernel configuration

If this tutorial doesn't work on your Acme Board probably you have to change 
the Kernel configuration and compile it from source as explained on the articles
available from the [tutorials page index)[/tutorials].

Access to the Kernel configuration panel using __make menuconfig__ command and 
enable the following items:

##For the D-Link/Realtek mini USB adapter

<pre class="minicom">
Device Drivers  --->
  [*] USB support  ---> 
    <*> USB Wireless Device Management support
</pre>

You also have to verify whether the usb device ID detected by the FOX Board is known by the Kernel.

To do that type the command:

<pre class="minicom">
debarm:~# <b>lsusb</b>
Bus 001 Device 002: ID 0bda:8171 Realtek Semiconductor Corp. RTL8188SU 802.11n r
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
</pre>

then get the id <b>0bda:8171</b> and check if it is listed into the file 
<a href="http://lxr.linux.no/linux+v2.6.38/drivers/staging/rtl8712/usb_intf.c">drivers/staging/rtl8712/usb_intf.c</a> if not apply a patch like this and recompile 
the Kernel uImage:

<pre class="minicom">
diff --git a/drivers/staging/rtl8712/usb_intf.c b/drivers/staging/rtl8712/usb_in
index 21ce2af..bfa5458 100644
--- a/drivers/staging/rtl8712/usb_intf.c
+++ b/drivers/staging/rtl8712/usb_intf.c
@@ -49,6 +49,11 @@ static void r871xu_dev_remove(struct usb_interface *pusb_intf
 static struct usb_device_id rtl871x_usb_id_tbl[] = {
 
 /* RTL8188SU */
+       /* Digitus */
+       {USB_DEVICE(0x0BDA, 0x8171)},
+       /* Digicom */
+       {USB_DEVICE(0x0BDA, 0x8171)},
+       {USB_DEVICE(0x0BDA, 0x8176)},
        /* Realtek */
        {USB_DEVICE(0x0BDA, 0x8171)},
        {USB_DEVICE(0x0bda, 0x8173)},
</pre>

then enable the staging driver for RealTek RTL8712U:

<pre class="minicom">
Device Drivers  ---&gt;
  [*] Staging drivers  ---&gt;  
     &lt;*&gt; RealTek RTL8712U (RTL8192SU) Wireless LAN NIC driver
</pre> 

Install RealTek firmware from the debian package __firmware-realtek__.

I found it on:

* [http://packages.debian.org/squeeze/all/firmware-realtek/download](http://packages.debian.org/squeeze/all/firmware-realtek/download)

Dowload it by typing: 

<pre class="minicom">
debarm:~# <b>wget http://ftp.de.debian.org/debian/pool/non-free/f/firmware-nonfree/firmware-realtek_0.28+squeeze1_all.deb</b>
debarm:~# <b>dpkg -i firmware-realtek_0.28+squeeze1_all.deb</b>
</pre>

## Related links

*  @article='webapp_server'
*  <a href="/WIFI-1">WIFI-1 Mini WiFi USB module</a>
*  <a href="http://wiki.debian.org/WiFi">Debian Wi-Fi wiki page</a>
*  <a href="http://manpages.debian.net/cgi-bin/man.cgi?query=iwconfig">iwconfig man page</a>
*  <a href="http://manpages.debian.net/cgi-bin/man.cgi?query=iwlist">iwlist man page</a></li>
*  <a href="http://ubuntuforums.org/showthread.php?t=318539">HOWTO: Wireless Security - WPA1, WPA2, LEAP, etc.</a>
*  <a href="http://en.wikipedia.org/wiki/Wireless_tools_for_Linux">Wireless tools for Linux</a>
*  <a href="http://en.wikipedia.org/wiki/Wpa_supplicant">Wpa supplican</a>

## Credits

Thanks to <a href="http://vincent-jacques.net">Vincent Jacques</a> for his contributions to this article.

@shop='WIFI-2'
@shop='WIFI-2-COMBO'
@shop='DWA-131'
