WiFi Driver & Command(iw)

最後更新: 2022-07-02

目錄

  • 功能
  • Get Hardware Info.
  • Commands
  • Get Info
  • Station(clients) statistics
  • Regulatory Domain
  • Debugging
  • Set channel width
  • Set Power
  • Connecting AP
  • Virtual Interface
  • Openwrt - Get 300Mbps
  • Doc

 


firmware

 

載入 firmware 失敗時的 dmesg

... usb 3-2: new high-speed USB device number 2 using xhci_hcd
... usb 3-2: New USB device found, idVendor=0bda, idProduct=8176, bcdDevice= 2.00
... usb 3-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
... usb 3-2: Product: 802.11n WLAN Adapter
... usb 3-2: Manufacturer: Realtek
... usb 3-2: SerialNumber: 00e04c000001
... rtl8192cu: Chip version 0x10
... rtl8192cu: Board Type 0
... rtl_usb: rx_max_size 15360, rx_urb_num 8, in_ep 1
...
... rtl8192cu: Loading firmware rtlwifi/rtl8192cufw_TMSC.bin
... usb 3-2: firmware: failed to load rtlwifi/rtl8192cufw_TMSC.bin (-2)
... usb 3-2: Direct firmware load for rtlwifi/rtl8192cufw_TMSC.bin failed with error -2
...
... usb 3-2: firmware: failed to load rtlwifi/rtl8192cufw.bin (-2)
... usb 3-2: Direct firmware load for rtlwifi/rtl8192cufw.bin failed with error -2
... rtlwifi: Loading alternative firmware rtlwifi/rtl8192cufw.bin
...
... ieee80211 phy0: Selected rate control algorithm 'rtl_rc'
... usbcore: registered new interface driver rtl8192cu
... rtl8192cu 3-2:1.0 wlxAABBCCDDEEFF: renamed from wlan0
... rtl8192cu: MAC auto ON okay!
... rtl8192cu: Tx queue select: 0x05

# This package contains the binary firmware for Realtek Ethernet, wifi and
# Bluetooth adapters supported by various drivers.

apt install firmware-realtek

成功的 dmesg

... rtl8192cu: Loading firmware rtlwifi/rtl8192cufw_TMSC.bin
... usb 3-1: firmware: direct-loading firmware rtlwifi/rtl8192cufw_TMSC.bin

 


介紹

nl80211 based CLI configuration utility ( 它的上一代是 iwconfing )

iw --version

iw version 4.14

 


功能

 

Disassociate On X

disassoc_low_ack # Default: 1

Disassociate stations based on excessive transmission failures or other indications of connection loss.
(Low Acknowledgement)

max_inactivity # Default: 300

If a station does not send anything in ap_max_inactivity seconds,
 an empty data frame is sent to it in order to verify whether it is still in range.

Preamble Type

adds some additional data header strings to help check the wifi data transmission errors.

Long Preamble

  • You are using wifi in an area with high interference or low signal strength.
  • outdated equipment

Short Preamble

  • uses shorter data strings that adds less data to transmit the error redundancy check
    which means that it is much faster.

 


Commands

 

  • help [command]
  • event [-t] [-r] [-f]
  • phy
  • list
  • phy []            <-- hardware device
  • dev []            <-- interface name
  • reg [ get | set ]

 

 


Get Info

 

Get device capabilities

iw list

Wiphy phy0
        max # scan SSIDs: 4
        ...
        Supported interface modes:
                 * IBSS
                 * managed
                 * AP
                 ...
        Band 1:
                Capabilities: 0x11ef
                        RX LDPC
                        HT20/HT40
                        ...
                Frequencies:
                        * 2412 MHz [1] (20.0 dBm)
                        * 2417 MHz [2] (20.0 dBm)
                        ...
                ...

Get dev info

iw dev

phy#0
        Interface wlan0
                ifindex 42
                wdev 0x26
                addr 90:f6:52:21:44:e2
                type AP
                channel 4 (2427 MHz) HT20

iw dev wlan0 info

Interface wlan0
        ifindex 42
        wdev 0x26
        addr 90:f6:52:21:44:e2
        type AP
        wiphy 0
        channel 4 (2427 MHz) HT20

是否有連 AP

iw dev wlan0 link

#

Not connected.

#

Connected to ?:?:?:?:?:? (on wlan0)
        SSID: OpenWrt
        freq: 2412
        RX: 248394 bytes (2437 packets)
        TX: 3392 bytes (37 packets)
        signal: -51 dBm
        tx bitrate: 57.8 MBit/s MCS 5 short GI

        bss flags:      short-preamble short-slot-time
        dtim period:    0
        beacon int:     100

 


Station(clients) statistics

 

查看所有 station 的情況

iw dev wlan0 station dump

Station 2c:9e:fc:?:?:?(on wlan0)
        inactive time:  10 ms
        rx bytes:       85148197
        rx packets:     231566
        tx bytes:       75925050
        tx packets:     228584
        tx retries:     12007
        tx failed:      0
        signal:         -48 [-48] dBm
        signal avg:     -47 [-47] dBm
        tx bitrate:     58.5 MBit/s MCS 6
        rx bitrate:     72.2 MBit/s MCS 7 short GI
        authorized:     yes
        authenticated:  yes
        preamble:       short
        WMM/WME:        yes
        MFP:            no
        TDLS peer:      no
.....................................

 

Peer Statistic

usage:

iw dev wlan0 station get <peer-MAC-address>

e.g.

root@WiFi:~# iw dev wlan0 station get 5c:e2:f4:?:?:?

Station 5c:e2:f4:d1:d6:29 (on wlan0)
        inactive time:  490 ms
        rx bytes:       204702
        rx packets:     5403
        tx bytes:       589174
        tx packets:     2780
        tx retries:     55
        tx failed:      0
        signal:         -50 [-50] dBm
        signal avg:     -52 [-52] dBm
        tx bitrate:     65.0 MBit/s MCS 7
        rx bitrate:     1.0 MBit/s
        authorized:     yes
        authenticated:  yes
        preamble:       long
        WMM/WME:        yes
        MFP:            no
        TDLS peer:      no

 


Regulatory Domain

 

Get

iw reg get

country US:
        (2402 - 2472 @ 40), (3, 27)
        (5170 - 5250 @ 40), (3, 17)
        (5250 - 5330 @ 40), (3, 20), DFS
        (5490 - 5600 @ 40), (3, 20), DFS
        (5650 - 5710 @ 40), (3, 20), DFS
        (5735 - 5835 @ 40), (3, 30)

DFS & TPC

In 2007 the FCC (United States) began requiring that devices operating on 5.250–5.350 GHz and 5.470–5.725 GHz

must employ dynamic frequency selection (DFS) and transmit power control (TPC) capabilities.

Fixed:

FCA, fixed channel allocation: Manually assigned by the network operator

Dynamic:

DCA, dynamic channel allocation, (DCA also handles bursty cell traffic and utilizes the cellular radio resources more efficiently)

DFS, dynamic frequency selection

Spread spectrum (considered as an alternative to complex DCA algorithms)
 

Set

iw reg set XX

 


Debugging

 

iw event -f

 


Set channel width

 

iw dev wlan0 set channel 1 [HT20|HT40+|HT40-]
 


Set Power

 

txpower:

iw dev <devname> set txpower <auto|fixed|limit> [<tx power in mBm>]

power_save:

iw dev wlan0 get power_save

Power save: on

e.g.

iw dev wlan0 set power_save on

command failed: Operation not supported (-122)

 


Connecting AP

 

Scanning AP

iw dev wlan0 scan

其中一個附近 AP 的 result

.............................

BSS 90:18:7c:b4:e7:21 (on wlan0)
        TSF: 31998259587 usec (0d, 08:53:18)
        freq: 2462
        beacon interval: 100
        capability: ESS Privacy SpectrumMgmt ShortSlotTime (0x0511)
        signal: -68.00 dBm
        last seen: 10 ms ago
        SSID: Jenny
        Supported rates: 1.0* 2.0* 5.5* 11.0* 18.0 24.0 36.0 54.0
        DS Parameter set: channel 11
        TIM: DTIM Count 1 DTIM Period 2 Bitmap Control 0x0 Bitmap[0] 0x0
        Country: HK     Environment: Indoor/Outdoor
                Channels [1 - 13] @ 36 dBm
        Power constraint: 0 dB
        ERP: <no flags>
        RSN:     * Version: 1
                 * Group cipher: CCMP
                 * Pairwise ciphers: CCMP
                 * Authentication suites: PSK
                 * Capabilities: 16-PTKSA-RC (0x000c)
        Extended supported rates: 6.0 9.0 12.0 48.0
        HT capabilities:
                Capabilities: 0x1020
                        HT20
                        Static SM Power Save
                        RX HT20 SGI
                        No RX STBC
                        Max AMSDU length: 3839 bytes
                        DSSS/CCK HT40
                Maximum RX AMPDU length 32767 bytes (exponent: 0x002)
                Minimum RX AMPDU time spacing: 8 usec (0x06)
                HT RX MCS rate indexes supported: 0-7
                HT TX MCS rate indexes are undefined
        HT operation:
                 * primary channel: 11
                 * secondary channel offset: no secondary
                 * STA channel width: 20 MHz
                 * RIFS: 1
                 * HT protection: nonmember
                 * non-GF present: 1
                 * OBSS non-GF present: 1
                 * dual beacon: 0
                 * dual CTS protection: 0
                 * STBC beacon: 0
                 * L-SIG TXOP Prot: 0
                 * PCO active: 0
                 * PCO phase: 0
        WMM:     * Parameter version 1
                 * u-APSD
                 * BE: CW 15-63, AIFSN 3
                 * BK: CW 15-1023, AIFSN 7
                 * VI: CW 7-15, AIFSN 1, TXOP 3008 usec
                 * VO: CW 3-7, AIFSN 1, TXOP 1504 usec

.............................

Associate

iw dev wlan0 link

Not connected.

設定 WEP Key

iw wlan0 connect foo keys 0:abcde d:1:0011223344

Connect

iw wlan0 connect foo

Disconnect

iw dev <devname> disconnect

If you need to connect to an AP with WPA or WPA2 encryption requirements

then you must use wpa_supplicant.

 


Virtual Interface

 

Valid interface types are: managed, ibss, monitor, mesh, wds.

managed

ibss

monitor

mesh

wds

 


Openwrt - Get 300Mbps

 

HT: High Throughput

HT40+ (for channels 1-7) or HT40- (for channels 5-11)

HT40- (2x 20MHz channels, primary/control channel is upper, secondary channel is below)

HT40+ (2x 20MHz channels, primary/control channel is lower, secondary channel is above)

cli 設定:

uci set wireless.radio0.htmode=HT40+

# Do not scan for overlapping BSSs in HT40+/- mode

uci set wireless.radio0.noscan=1

uci commit wireless;

wifi

11n 有兩種頻寬模式:On IEEE 802.11n

  • HT20 (HT20 refers to a 20Mhz spectrum)
  • HT40

* This is not channel bonding, but a single channel with double the older 20 MHz channel width,
  thus using two adjacent 20 MHz bands.

在 2.4G 使用 HT40, 則有效通道有3~13, 非重疊的只有 3 及 11

 


Doc

https://wireless.wiki.kernel.org/en/users/documentation/iw