7
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ラズパイでRTL8812AU USB WLANを使う

Last updated at Posted at 2019-02-09

ラズパイ2の無線化のためにRTL8812AU搭載のUSB WLANモジュールを購入してみたところ、ドライバを入れないと認識しなかったのでそのやり方の記録です。ドライバモジュールのビルド・インストールを行うdkmsの使い方の参考にもなりそう。
なお、このUSB WLANはその後技適がないことが発覚して処分することに…

実施環境

  • HW: Raspberry Pi 2 Model B
  • OS: Raspbian Stretch (image: 2018-11-13-raspbian-stretch-lite.img)
  • USB NIC: WAVLINK WL-WN688U3D (chipset: RTL8812AU)
カーネルバージョン
$ uname -a
Linux pi2 4.14.79-v7+ #1159 SMP Sun Nov 4 17:50:20 GMT 2018 armv7l GNU/Linux

インストール手順

新規に起動イメージを書き込んだSDカードでブートしたところから作業スタート。USB NICのドライバのインストールが終わるまではeth0経由でインターネットに接続してます。rebootかけたところでeth0のケーブルを抜いて無線化。

ソフトウェア更新、インストール

$ sudo apt update && sudo apt upgrade -y
$ sudo apt install build-essential git dkms

カーネルソースの取得

$ sudo apt install raspberrypi-kernel-headers
$ cd /usr/src/
$ sudo ln -s linux-headers-4.14.79-v7+ linux
$ ls -la
total 16
drwxr-xr-x  4 root root 4096 Feb  9 06:27 .
drwxr-xr-x 10 root root 4096 Nov 13 12:56 ..
lrwxrwxrwx  1 root root   25 Feb  9 06:27 linux -> linux-headers-4.14.79-v7+
drwxr-xr-x 24 root root 4096 Feb  9 06:26 linux-headers-4.14.79+
drwxr-xr-x 24 root root 4096 Feb  9 06:26 linux-headers-4.14.79-v7+

ドライバーのソースコード取得 (git)

$ pwd
/usr/src
$ sudo git clone https://github.com/diederikdehaas/rtl8812AU
Cloning into 'rtl8812AU'...
$ sudo mv rtl8812AU rtl8812AU-4.3.20  ## dkms用にバージョン番号を付けておく
$ ls -la
total 20
drwxr-xr-x  5 root root 4096 Feb  9 06:28 .
drwxr-xr-x 10 root root 4096 Nov 13 12:56 ..
lrwxrwxrwx  1 root root   25 Feb  9 06:27 linux -> linux-headers-4.14.79-v7+
drwxr-xr-x 24 root root 4096 Feb  9 06:26 linux-headers-4.14.79+
drwxr-xr-x 24 root root 4096 Feb  9 06:30 linux-headers-4.14.79-v7+
drwxr-xr-x  8 root root 4096 Feb  9 06:31 rtl8812AU-4.3.20

ドライバーのビルド・インストール (dkms)

RPi2でコンパイルすると10分程度かかる。

ビルド・インストール
$ pwd
/usr/src
$ sudo vi rtl8812AU-4.3.20/Makefile  ## プラットフォーム指定を変更しておく
CONFIG_PLATFORM_I386_PC = n  ## y -> n
CONFIG_PLATFORM_ARM_RPI = y  ## n -> y
$ 
$ DRV_NAME=rtl8812AU
$ DRV_VERSION=4.3.20
$ sudo dkms add -m ${DRV_NAME} -v ${DRV_VERSION}
$ sudo dkms build -m ${DRV_NAME} -v ${DRV_VERSION}
$ sudo dkms install -m ${DRV_NAME} -v ${DRV_VERSION}

デバイスの接続

lsusb
$ lsusb
Bus 001 Device 005: ID 0bda:8812 Realtek Semiconductor Corp. RTL8812AU 802.11a/b/g/n/ac WLAN Adapter
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
dmesg
$ dmesg | tail
[ 2083.565802] usb 1-1.4: new high-speed USB device number 5 using dwc_otg
[ 2083.696418] usb 1-1.4: New USB device found, idVendor=0bda, idProduct=8812
[ 2083.696435] usb 1-1.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 2083.696447] usb 1-1.4: Product: 802.11n NIC
[ 2083.696457] usb 1-1.4: Manufacturer: Realtek
[ 2083.696467] usb 1-1.4: SerialNumber: 123456
[ 2083.864475] RTL871X: rtw_ndev_init(wlan0) if1 mac_addr=80:3f:5d:11:c2:d5
[ 2084.509770] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
iwconfig
$ iwconfig wlan0
wlan0     unassociated  Nickname:"<WIFI@REALTEK>"
          Mode:Managed  Frequency=2.412 GHz  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

APへの接続設定 (rpi-config)

$ sudo raspi-config  ## 2 Network Options -> N2 Wi-fi でSSIDとPassphraseを入力
$ cat /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=JP

network={
        ssid="SSID-NAME"
        psk="PASSPHRASE"
}

再起動

$ sudo reboot

動作確認

無線LAN接続の状態確認
$ iwconfig wlan0
wlan0     IEEE 802.11bgn  ESSID:"SSID-NAME"  Nickname:"<WIFI@REALTEK>"
          Mode:Managed  Frequency:2.472 GHz  Access Point: 38:D5:47:07:0E:xx
          Bit Rate:144.4 Mb/s   Sensitivity:0/0
          Retry:off   RTS thr:off   Fragment thr:off
          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
無線LANインタフェースの状態確認
$ ifconfig wlan0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.10.7  netmask 255.255.255.0  broadcast 192.168.10.255
        inet6 fe80::a668:a947:aa8:1a09  prefixlen 64  scopeid 0x20<link>
        ether 80:3f:5d:11:c2:d5  txqueuelen 1000  (Ethernet)
        RX packets 157  bytes 21661 (21.1 KiB)
        RX errors 0  dropped 22  overruns 0  frame 0
        TX packets 33  bytes 5426 (5.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
GW(DHCP)の確認
$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         router.asus.com 0.0.0.0         UG    304    0        0 wlan0
192.168.10.0    0.0.0.0         255.255.255.0   U     304    0        0 wlan0
外部との疎通確認
$ ping www.google.com
PING www.google.com (216.58.196.228) 56(84) bytes of data.
64 bytes from kix06s01-in-f228.1e100.net (216.58.196.228): icmp_seq=1 ttl=55 time=13.4 ms
64 bytes from kix06s01-in-f228.1e100.net (216.58.196.228): icmp_seq=2 ttl=55 time=20.4 ms
64 bytes from kix06s01-in-f228.1e100.net (216.58.196.228): icmp_seq=3 ttl=55 time=10.4 ms
64 bytes from kix06s01-in-f228.1e100.net (216.58.196.228): icmp_seq=4 ttl=55 time=10.6 ms
^C
--- www.google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 10.473/13.756/20.466/4.048 ms

参考URL

その他

この続きでhostapdでアクセスポイント化も試したものの、ドライバの問題かACS(自動チャネル選択)が動かなかった。あれこれ調べてる間に技適の問題に気付いてしまい終了。

7
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?