Raspberry Pi 2でWiFiを使う

Raspberry Pi 2 のRaspbian jessie を使っています。
まずは、Linuxカーネルで標準サポートされているであろう少し古いWiFiドングルで試します。今回使用したのはBUFFALOのWLI-UC-GN。

WiFiドングルを挿してみてカーネルの反応を見ます。

$ dmesg |tail -20
  ... 
[ 1143.178911] usb 1-1.5: new high-speed USB device number 4 using dwc_otg
[ 1143.296458] usb 1-1.5: New USB device found, idVendor=0411, idProduct=015d
[ 1143.296485] usb 1-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1143.296502] usb 1-1.5: Product: 802.11 n WLAN
[ 1143.296519] usb 1-1.5: Manufacturer: Ralink
[ 1143.296534] usb 1-1.5: SerialNumber: 1.0
[ 1143.718897] usb 1-1.5: reset high-speed USB device number 4 using dwc_otg
[ 1143.829525] ieee80211 phy0: rt2x00_set_rt: Info - RT chipset 3070, rev 0201 detected
[ 1143.883948] ieee80211 phy0: rt2x00_set_rf: Info - RF chipset 0005 detected
[ 1144.082664] ieee80211 phy0: Selected rate control algorithm 'minstrel_ht'
[ 1144.084402] usbcore: registered new interface driver rt2800usb
[ 1144.314294] ieee80211 phy0: rt2x00lib_request_firmware: Info - Loading firmware file 'rt2870.bin'
[ 1144.328254] ieee80211 phy0: rt2x00lib_request_firmware: Info - Firmware detected - version: 0.29
[ 1144.777172] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready

認識したようです。

$ iwconfig
wlan0     IEEE 802.11bgn  ESSID:off/any  
          Mode:Managed  Access Point: Not-Associated   Tx-Power=20 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Power Management:off
          
lo        no wireless extensions.

eth0      no wireless extensions.

wlan0 というのができています。

$ sudo iwlist wlan0 scan |grep ESSID
                    ...
                    ESSID:"0024A52FB295-1"
                    ESSID:"0024A52FB295"
                    ...

こんなふうにこれから接続しようとするWiFiアクセスポイントが見えていればOK。WiFiのドライバは正しく動いていそうです。

$ ps ax |grep wpa
 2273 ?        Ss     0:00 /sbin/wpa_supplicant -s -B -P /run/wpa_supplicant.wlan0.pid -i wlan0 -D nl80211,wext -c /etc/wpa_supplicant/wpa_supplicant.conf
 3018 ttyAMA0  S+     0:00 grep --color=auto wpa

wpa_supplicant も起動済みなので、後はWiFiの認証だけです。

GUIは使わずにwpa_cliを使います。

$ wpa_cli
wpa_cli v2.3
Copyright (c) 2004-2014, Jouni Malinen  and contributors

This software may be distributed under the terms of the BSD license.
See README for more details.


Selected interface 'wlan0'

Interactive mode

> 

'>' のプロンプトにコマンドを入力していきます。
アクセスポイントの確認。(入力したのは赤字の部分。)

    
OK <3>CTRL-EVENT-SCAN-STARTED <3>CTRL-EVENT-SCAN-RESULTS <3>WPS-AP-AVAILABLE
bssid / frequency / signal level / flags / ssid 06:24:a5:2f:b2:95 2447 -49 [WPA-PSK-CCMP][ESS] 0024A52FB295-1 00:24:a5:2f:b2:95 2447 -49 [WPA-PSK-CCMP+TKIP][WPA2-PSK-CCMP+TKIP][WPS][ESS] 0024A52FB295 >
SSID "0024A52FB295", パスワード "xxxxxxxx" を登録します。
    
OK
OK
OK <3>CTRL-EVENT-SCAN-STARTED <3>CTRL-EVENT-SCAN-RESULTS <3>WPS-AP-AVAILABLE <3>SME: Trying to authenticate with 00:24:a5:2f:b2:95 (SSID='0024A52FB295' freq=2447 MHz) <3>Trying to associate with 00:24:a5:2f:b2:95 (SSID='0024A52FB295' freq=2447 MHz) <3>Associated with 00:24:a5:2f:b2:95 <3>WPA: Key negotiation completed with 00:24:a5:2f:b2:95 [PTK=CCMP GTK=TKIP] <3>CTRL-EVENT-CONNECTED - Connection to 00:24:a5:2f:b2:95 completed [id=0 id_str=]
OK
$
wlan0の接続は成功して、以下のようにIPアドレスが割り当てられています。
$ ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr 00:24:a5:7e:e4:7f  
          inet addr:192.168.0.8  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::a1d:3d6f:e6df:ae25/64 Scope:Link
          inet6 addr: 240f:16:6d51:1:a15a:8fe7:49dd:ae77/64 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:313 errors:0 dropped:0 overruns:0 frame:0
          TX packets:54 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:89509 (87.4 KiB)  TX bytes:11524 (11.2 KiB)
設定は以下のところに保存されています。次回からはWiFiドングルを挿したら自動的にこの設定で接続されます。
$ sudo cat /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
	ssid="0024A52FB295"
	psk="xxxxxxxx"
}
参考にしたのは以下のページ。 https://wiki.archlinuxjp.org/index.php/WPA_supplicant