当前位置

树莓派做路由器 2018.03 (Part 2) hostapd 和 RTL8188CUS 网卡,如何在 Raspbian Stretch/Kernel 4.9.x 下工作?

注意:自从 Raspbian 更新内核到 4.14.x 后,下面说的方法已经不能用了,启动 hostapd 会报错;似乎 https://forum.odroid.com/viewtopic.php?f=146&t=29195#p209268 这里给了一个解法,测试中... 2018.06.07
前言:写于 2018.03,分成三篇blog,介绍为了在家里使用 Google Home Mini 而进行的一系列努力;
本文为第二部分,关于用 RTL8188CUS USB 无线网卡启动热点中的坑,使用 Pi 3B 的大可跳过这一部分;注意 RTL 8188/8192 系列USB无线网卡现在仅仅也就是日常可用而已,见最后 "Update"
第一部分:树莓派做路由器 2018.03 (Part 1) 最基础的Hotspot配置知识
第三部分:树莓派做路由器 2018.03 (Part 3) Google 硬件(Home/Wear/Chromecast...)上网配置

RTL8188CUS 是在 lsusb 里看到的名字,它和 RTL8192CU 用的是同一个驱动,8192cu.ko (https://wiki.debian.org/rtl819x#supported-rtl8192cu)

上文提到,AP 的工作原理是 hostapd + Kernel Driver 在数据链路层上同客户机通信完成身份认证;那么如果设备驱动没实现好、或者 hostapd 没有正确地和设备驱动交互都会导致同客户机的通信失败。
在 Raspbian Stretch/Kernel 4.9.x 里,Realtek 网卡驱动和 hostapd 都有问题!!下面是解决方案

  1. hostapd 无法同 Realtek 网卡驱动通信是老生常谈的故障了;当前最新的 hostapd 是 2.6,patch 方案参考 https://wiki.odroid.com/accessory/connectivity/wifi/wlan_ap
  2. 如果只配置一个无需密码的开放热点,现在光靠 hostapd 已经可用了;据说在老版本内核网卡驱动下,也能把 WPA2 热点跑起来。但恰恰就是我手里的 4.9.x 内核需要换掉驱动,以支持 WPA2 Hotspot
    • sudo apt install raspberrypi-kernel-headers dkms
    • git clone https://github.com/pvaret/rtl8192cu-fixes.git
    • vi rtl8192cu-fixes/include/rtw_version.h #提高版本号,否则 dkms install 有问题
    • sudo dkms add ./rtl8192cu-fixes

      Creating symlink /var/lib/dkms/8192cu/1.11/source ->
      /usr/src/8192cu-1.11

      DKMS: add completed.

    • sudo dkms build 8192cu/1.11
    • sudo dkms install 8192cu/1.11

      8192cu:
      Running module version sanity check.
      - Original module
      - Found /lib/modules/4.9.59-v7+/kernel/drivers/net/wireless/realtek/rtl8192cu/8192cu.ko
      - Storing in /var/lib/dkms/8192cu/original_module/4.9.59-v7+/armv7l/
      - Archiving for uninstallation purposes
      - Installation
      - Installing to /lib/modules/4.9.59-v7+/kernel/drivers/net/wireless//

      depmod...

      Warning: Unable to find an initial ram disk that I know how to handle.
      Will not try to make an initrd.

      DKMS: install completed.

    • sudo depmod -a
    • sudo cp ./rtl8192cu-fixes/blacklist-native-rtl8192.conf /etc/modprobe.d/

    重启系统

在我这里这样就一切OK;可能树莓派刚刚完成重启时去连接热点会出现密码不正确的响应——也许是 driver/firmware 还没有热身完毕?但等2-3分钟就正常了。本系列最后一篇介绍如何让 Google 系列硬件通过这个无线路由上网

附录:其它相关的链接

Update: 热点运行时间长了以后,还是会发生无法连接的情况。登录到树莓派上执行 hostapd 观察输出会看到 l2_packet_send - send: No buffer space available 这样的信息,卸载再重新装载 8192cu 就又好了;说明问题出在驱动,而不是 hostapd。网上搜了一下亦有其他人碰到问题,包括清华某哥们,因为驱动无人维护,似乎无解。简单应用重启即可,或者在 2018 年的今天去买个内核支持更完善、速度也更快信号更好的外设吧
https://github.com/pvaret/rtl8192cu-fixes/issues/85
https://github.com/tuna/collection/issues/73
https://github.com/tuna/collection/issues/79
https://github.com/tuna/collection/issues/103
https://gist.github.com/huiyiqun/9c9b00631768bc5b31971235462eba62

Topic: