WiFi

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Wifi and the translation is 83% complete.
Outdated translations are marked like this.
Other languages:
English • ‎español • ‎français • ‎русский • ‎中文(中国大陆)‎ • ‎日本語 • ‎한국어

Warning: Display title "WiFi" overrides earlier display title "无线网络(Wifi)".

Resources

这篇文章介绍了 WiFi(无线)网卡的设置

安装系统时的WiFi设置

如果在安装 Gentoo 过程中需要设置 WiFi 连接,需要提醒一下的是 Gentoo 最小安装光盘只支持一部分的无线网卡驱动,并且只提供 wpa_cli 命令(不提供 wpa_gui)来设置 WPA/WPA2/Enterprise 等无线连接。

如果Gentoo最小安装光盘没有包含您需要设置的网卡驱动或者您需要 wpa_supplicant 的图形界面来设置,可以选择其他的live CD,例如System Rescue CD。需要提醒一下的是当使用non-Gentoo live CD的时候可能需要这些特殊步骤

硬件检测

首先检测 WiFi 控制器。lspci 或者 lsusb 是可用于此任务的命令行工具。

如果 Linux(LiveCD/USB)启动并建立 WiFi 连接:

root #lspci -k

则你的驱动能在相应的以Kernel driver in use:开头的输出信息中找到。

如果启动的系统没有建立 WiFi 连接,需要从当前系统获取完整的硬件标识符列表。此列表可用于稍后识别正确的驱动程序:

root #lspci -n

复制以上命令输出的对应的 PCIID 部分,然后把它粘贴到 https://kmuto.jp/debian/hcl/。

对于USB网卡来说,过程也是大致相同的。首先拿到系统中所有的USB设备信息:

user $lsusb

这个命令会生成对应的PCI ID,生产商(manufacturer),make,模型(model),还有USB设备对应的系统的芯片组(chipset)。在所有的信息中,可能芯片组(chipset)是最有用的信息。网上搜索一下 "linuxwireless.org <对应的chipset>" 通常是最找到对应的USB NIC驱动和固件 (firmware) 名字的最快方式。

另外,lshw也能用于获取相应的信息:

root #lshw | grep -i driver | perl -pe 's/^.*driver=(\S+).*$/$1/g;' | sort -u

这个命令会生成所有驱动信息的列表,无论是PCI网卡还是USB网卡。

内核

确定了驱动程序之后,现在是配置Linux内核的时候了。

IEEE 802.11

至少激活cfg80211mac80211

KERNEL linux-4.1
[*] Networking support  --->
    [*] Wireless  --->
        <M/*>   cfg80211 - wireless configuration API
        [ ]     nl80211 testmode command
        [ ]     enable developer warnings
        [ ]     cfg80211 regulatory debugging
        [ ]     cfg80211 certification onus
        [*]     enable powersave by default
        [ ]     cfg80211 DebugFS entries
        [ ]     use statically compiled regulatory rules database
        [ ]     cfg80211 wireless extensions compatibility
        <M/*>   Generic IEEE 802.11 Networking Stack (mac80211)
        [*]   Minstrel
        [*]     Minstrel 802.11n support
        [ ]       Minstrel 802.11ac support
              Default rate control algorithm (Minstrel)  --->
        [ ]   Enable mac80211 mesh networking (pre-802.11s) support
        -*-   Enable LED triggers
        [ ]   Export mac80211 internals in DebugFS
        [ ]   Trace all mac80211 debug messages
        [ ]   Select mac80211 debugging features  ----

Minstrel 和 its 802.11n 支持 rate control algorithm. 一些无线设备可能需要开启这个选项。

Important
In case the wireless configuration API (CONFIG_CFG80211) is built into the kernel (<*>) instead as a module (<M>), the driver won't be able to load regulatory.db from /lib/firmware resulting in broken regulatory domain support. Please set CONFIG_CFG80211=m or add regulatory.db and regulatory.db.p7s to CONFIG_EXTRA_FIRMWARE.

WEXT

"cfg80211 wireless extensions compatibility" 选项又称 WEXT 支持老旧的 无线工具iwconfig.

KERNEL
[*] Networking support  --->
    [*] Wireless  --->
        [*]     cfg80211 wireless extensions compatibility

设备驱动程序

接下来,需要根据先前检测到的驱动程序和硬件启用相应内核选项的正确集合。推荐驱动程序构建为模块. 如果无线网络使用 WPA 或 WPA2 加密,还要确保在内核中启用 AES 密码支持。

KERNEL
Device Drivers  --->
    [*] Network device support  --->
        [*] Wireless LAN  --->
 
            Select the driver for your Wifi network device, e.g.:
            <M> Broadcom 43xx wireless support (mac80211 stack) (b43)
            [M]    Support for 802.11n (N-PHY) devices
            [M]    Support for low-power (LP-PHY) devices
            [M]    Support for HT-PHY (high throughput) devices
            <M> Intel Wireless WiFi Next Gen AGN - Wireless-N/Advanced-N/Ultimate-N (iwlwifi)
            <M>    Intel Wireless WiFi DVM Firmware support                             
            <M>    Intel Wireless WiFi MVM Firmware support
            <M> Intel Wireless WiFi 4965AGN (iwl4965)
            <M> Intel PRO/Wireless 3945ABG/BG Network Connection (iwl3945)
            <M> Ralink driver support  --->
                <M>   Ralink rt27xx/rt28xx/rt30xx (USB) support (rt2800usb)
 
-*- Cryptographic API --->
    -*- AES cipher algorithms
    -*- AES cipher algorithms (x86_64)
    <*> AES cipher algorithms (AES-NI)
Important
In case the driver is built into the kernel (<*>) instead of as a module (<M>), then the firmware needs to be built into the kernel as well.
Do not forget to rebuild the kernel after changing its configuration.

LED支持

要启用不同数据包接收/发送事件的LED触发器,请使用以下选项编译内核:

KERNEL
Device Drivers  --->
    [*] LED Support  --->
        <*>   LED Class Support
 
[*] Networking support  --->
    [*] Wireless  --->
        [*] Enable LED triggers

硬件

除了内核驱动程序,一些芯片组还需要固件。如果需要,请在以下列表中找到它并安装它:

root #emerge --ask sys-kernel/linux-firmware
WiFi device Driver Firmware Note
Atheros AR9271 & AR7010 ath9k_htc sys-kernel/linux-firmware
Broadcom 43xx wireless support b43 / b43legacy sys-firmware/b43-firmware Aircrack-ng ready, most probably the best choice if your bcm43xx device is supported
Broadcom PCIe and SDIO/USB devices brcmsmac / brcmfmac sys-kernel/linux-firmware Lacks powersaving, LED support and other features
Broadcom 43xx wireless support wl net-wireless/broadcom-sta Proprietary, no AP or Monitor modes, Comparison of bcm43xx drivers
Intel PRO/Wireless 2200BG ipw2200 sys-firmware/ipw2200-firmware
Intel PRO/Wireless 3945ABG/BG iwlegacy sys-kernel/linux-firmware
Intel Wireless WiFi 4965AGN iwl4965 sys-kernel/linux-firmware
All other Intel Wireless devices iwlwifi sys-kernel/linux-firmware See the iwlwifi article for detailed instructions.
Qualcomm Atheros QCA6174 ath10k_pci ath10k-firmware See Qualcomm_Atheros_QCA6174#Firmware
Ralink/MediaTek USB devices e.g. rt2800usb sys-kernel/linux-firmware
Realtek RTL8191SE & RTL8192SE rtl8192se sys-kernel/linux-firmware
Realtek 8723AU/8723BU/8191EU/8192EU/8188EU/8188RU rtl8xxxu sys-kernel/linux-firmware May need the CONFIG_RTL8XXXU_UNTESTED kernel option to find all devices. Only those verified by kernel developers are enabled by default.

如果驱动所需固件没有在列表中,那么需要您手动去下载并把它放在/lib/firmware下。

网络设备名称

内核提供的网络设备名称列入eth0 或 wlan0 等通常可以通过 /lib/udev/rules.d/80-net-name-slot.rules udev 规则在系统启动时更改参见 dmesg

为了保持传统命名,这个规则可以用 /etc/udev/rules.d 目录中用同样命名的空文件覆盖:

root #touch /etc/udev/rules.d/80-net-name-slot.rules

无线网请求程序

如果用 WPA 或 WPA2 设置无线网络,需要使用 无线网络发起程序类似 wpa_supplicantiwd。若要获取更多在 Gentoo Linux 中配置无线网络的信息,请阅读 Gentoo 手册中的无线网络章节


测试

使用新内核重新引导后或加载模块后,可以使用以下方法检查设备的可用性:

/sys 文件系统

通过使用 ls -altree 命令(由app-text/tree 包提供))列出 /sys/class/net 目录内容来获取设备名称:

user $tree /sys/class/net
/sys/class/net/
├── enp2s14 -> ../../devices/pci0000:00/0000:00:1e.0/0000:02:0e.0/net/enp2s14
├── lo -> ../../devices/virtual/net/lo
├── sit0 -> ../../devices/virtual/net/sit0
└── wlp8s0 -> ../../devices/pci0000:00/0000:00:1c.0/0000:08:00.0/net/wlp8s0

ip命令

要获取设备名称并验证是否检测到无线网卡,执行下面的 ip 命令

user $ip addr
3: wlan0:   ...

ifconfig 命令

ifconfig 命令是 sys-apps/net-tools 包提供的。使用 ifconfig -a 列出所有检测到的网卡,包括那些尚未启用/尚未活动的网卡:

user $ifconfig -a
wlan0     ...

网卡可以用下面的方法激活:

root #ifconfig -v wlan0 up
SIOCSIFFLAGS: Operation not possible due to RF-kill
WARNING: at least one error occurred. (-1)

In this example, enabling the wireless card failed as a radio frequency kill state is set (usually to keep power consumption at bay and not connect by accident to a wireless network).

iw命令

如果无线网卡支持 nl80211 stack,net-wireless/iw 软件包提供的 iw 命令可以显示检测到的无线卡:

root #iw dev
   phy#0
	Interface wlan0
		ifindex 4
		type managed

dmesg

检查 dmesg 的输出。

user $dmesg | grep -i -E 'xx:xx.x|wlan|iwl|80211'

确保

故障排除

Finding missing firmware

At system boot, the kernel will attempt to probe firmware as appropriate for each card. This can be discovered by searching dmesg or journalctl's (systemd) output from the current boot.

user $journalctl -b 0 --dmesg | grep -i firmware
Oct 05 14:51:09 maffbook kernel: Spectre V2 : Enabling Restricted Speculation for firmware calls

Oct 05 14:51:09 maffbook kernel: ACPI: [Firmware Bug]: BIOS _OSI(Linux) query ignored Oct 05 14:51:09 maffbook kernel: sgx: [Firmware Bug]: Unable to map EPC section to online node. Fallback to the NUMA node 0. Oct 05 14:51:09 maffbook kernel: i915 0000:00:02.0: [drm] Finished loading DMC firmware i915/kbl_dmc_ver1_04.bin (v1.4) Oct 05 14:51:09 maffbook kernel: ACPI: video: [Firmware Bug]: ACPI(PEGP) defines _DOD but not _DOS Oct 05 14:51:09 maffbook kernel: iwlwifi 0000:00:14.3: loaded firmware version 46.6b541b68.0 9000-pu-b0-jf-b0-46.ucode op_mode iwlmvm Oct 05 14:51:09 maffbook kernel: psmouse serio1: elantech: assuming hardware version 4 (with firmware version 0x5f2001) Oct 05 14:51:09 maffbook kernel: Bluetooth: hci0: Firmware revision 0.1 build 6 week 12 2021 Oct 06 17:26:26 maffbook kernel: Bluetooth: hci0: Minimum firmware build 1 week 10 2014 Oct 06 17:26:26 maffbook kernel: Bluetooth: hci0: Found device firmware: intel/ibt-17-16-1.sfi Oct 06 17:26:28 maffbook kernel: Bluetooth: hci0: Waiting for firmware download to complete Oct 06 17:26:28 maffbook kernel: Bluetooth: hci0: Firmware loaded in 1484394 usecs

Oct 06 17:26:28 maffbook kernel: Bluetooth: hci0: Firmware revision 0.1 build 6 week 12 2021

Forum threads

另请参阅

外部资源