02 January 2013

Raspberry PiでUSB WifiアダプタRTL8188CUSを使う

Raspberry Piに400円程度で売られているUSB Wifiアダプタ(チップセットがRTL8188CUSのもの)を挿して使う場合、ドライバはカーネルにすでに組み込まれているので、非常に簡単なセットアップだ。

Raspberry Piが起動中にWifiアダプタをUSBに挿し込むとシステムがシャットダウンするので、電源を入れる前からUSBポート(本体に直挿しでも、USBハブをハブをはさんでいても動作可能だった)に挿し込んでおく必要があった。

システム起動後にUSB IDを表示してみる


$ lsusb

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0bda:8176 Realtek Semiconductor Corp. RTL8188CUS 802.11n WLAN Adapter

モジュールの読み込み状態は


$ lsmod

Module Size Used by
evdev 8682 0
snd_bcm2835 12808 0
snd_pcm 74834 1 snd_bcm2835
snd_seq 52536 0
snd_timer 19698 2 snd_seq,snd_pcm
snd_seq_device 6300 1 snd_seq
snd 52489 5 snd_seq_device,snd_timer,snd_seq,snd_pcm,snd_bcm2835
snd_page_alloc 4951 1 snd_pcm
8192cu 485042 0

念の為、ドライバの組み込みやアップデートが必要ないかを確認するため、RPi VerifiedPeripheralsを確認してみる。

RTL8188CUS の情報は…

AirLink101
AWLL5099: Tested on Raspian Wheezy. Step-by-step installation and configuration instructions with screenshots can be found here. This adapter is based on the Realtek RTL8188CUS chipset. The rtl8192cu kernel driver is loaded automatically in the latest Raspian distribution.

Comfast
WU710N: chipset RTL8188CUS. The rtl8192cu kernel driver is loaded automatically in the latest Raspian distribution.

GMYLE
Wireless 11n USB Adapter. Uses RTL8188CUS chipset - cheap on eBay. Installs and works using the install-rtl8188cus-latest.sh script.

Micronet
Micronet SP907NS, 11N Wireless LAN USB Adapter (uses Realtek RTL8188CUS) works plugged directly into Raspberry Pi USB (B) Debian installation instructions IMPORTANT: read the instructions first to avoid problems, and Auto-install script. The script has been used to install other adapters using the RTL8188CUS chip. Updated driver that handles the latest rpi-updates that kill the original driver, download for manual installation, automatically installed by the Auto-install script.

のように書かれていて、私が使っている最新のファームウエア(2012-12-16-wheezy-raspbian.zip)ではドライバはカーネルに組み込まれているはずだが、念の為上の記事にある説明書「An idiot's guide to RTL8188CUS wifi adapter setup」とインストーラinstall-rtl8188cus-latest.shを読んでみる。

install-rtl8188cus-latest.sh

#!/bin/bash

if [[ ${EUID} -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi

# Check for new wifi setup with built in driver. Don't run script if it is.

if [ -f /lib/modules/$(uname -r)/kernel/drivers/net/wireless/rtl8192cu/8192cu.ko ] && grep -q "iface wlan0 inet manual" /etc/network/interfaces > /dev/null 2>&1; then
echo
echo "Looks like you're using the new 2012-09-18-wheezy-raspbian image."
echo
echo "Sorry but the script will not currently set up the wifi on this image."
echo "You need to start the GUI using command startx and set it up using WiFi Config."
echo
read -p "The script will now terminate. Press any key to continue ... " -n1 -s
echo
exit
fi

上で青く着色したところのモジュールがあるか調べてみると、確かにある。ドライバのインストールは不要だ。

GUIを起動して、デスクトップ上のWifi Configを利用しろと書いてあるので、素直にそれに従ってセットアップを行う。

20130102-wlanconf01.jpg
Wifi Config画面

この画面はセットアップ後のものなので「Network」ドロップダウンリストにAPのSSIDが既に入力されているが、初回セットアップ時は何も入っていないはずなので、Scanボタンを押してAPを検索する。


20130102-wlanconf02.jpg

接続したいAPを選択すると、暗号キー入力画面に進む

20130102-wlanconf03.jpg

WPA2 AESの場合は、この画面のように暗号化にCCMPを選択する。

■ 上記セットアップを適用後のシステム設定ファイルの状態など

/etc/network/interfaces

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

iface default inet dhcp

赤の部分がWifi Configで追加された。

wpa_supplicantの設定ファイルは次のようになっている

/etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
ssid="SSID名"
psk="平文でパスワード"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
}

パスワードが平文…。暗号化してみるなら、次のコマンドで出力されるものに書き換えれば良い。


$ wpa_passphrase myssid mypassword

network={
ssid="myssid"
#psk="mypassword"
psk=2f0568b3492812bd56b946dbaf3fd7dd669b9a4602a09aa6462ff057949b025c
}

■ 参考にしたWebページ
Raspberry Pi - Installing the Airlink 101 Wireless N 150 Ultra Mini-USB Adapter (AWLL5099)