本文译至:http://wireless.kernel.org/en/users/Documentation/iw
关于 iw
iw 是一种新的基于 nl80211 的用于无线设备的CLI配置实用程序。它支持最近已添加到内核所有新的驱动程序。采用无线扩展接口的旧工具iwconfig已被废弃,强烈建议切换到 iw 和 nl80211。
像Linux内核的其余部分,iw 仍处于开发阶段。功能被随时添加。 iw 的唯一文档就是此页和“iw help”的输出。 请帮助扩大这个页面。
有一个页面列出iwconfig和iw的用例:替换 iwconfig。
获得 iw
iw发布压缩包可以从这里获取: http://kernel.org/pub/software/network/iw/.
另外,你也可以从 git 下载 iw: http://git.kernel.org/?p=linux/kernel/git/jberg/iw.git.
编译要求
- libnl >= libnl1
- libnl-dev >= libnl-dev-1
- pkg-config
为了使用 iw 你需要有libnl,第一个工作版本是1.0 pre8,因为此版本中引入了 genl, Generic Netlink,它是nl80211所依赖的。如果你的发行版的libnl是一个错误的版本,那么你就必须下载并自己编译libnl(http://www.infradead.org/~tgr/libnl/)。
帮助
在命令行输入
iw help
它会打印出它所支持的命令。
获取设备的功能
的功能,如带宽信息(2.4GHz,和5GHz),和802.11n的信息:
iw list
扫描
iw dev wlan0 scan
监听事件
只要使用
iw event
auth/assoc/deauth/disassoc帧可能有帮助,使用
iw event -f
有时时间信息也是有用的:
iw event -t
获得链路状态
为了确定您是否连接到一个AP上,如果你是最后一个使用的发送速率,您可以使用下面的命令。
iw dev wlan0 link
Connected to 04:21:b0:e8:c8:8b (on wlan0)
SSID: attwifi
freq: 2437
RX: 2272 bytes (18 packets)
TX: 232 bytes (3 packets)
signal: -57 dBm
tx bitrate: 36.0 MBit/s
关联到802.11n的AP的输出示例:
iw dev wlan0 link
Connected to 68:7f:74:3b:b0:01 (on wlan0)
SSID: tesla-5g-bcm
freq: 5745
RX: 30206 bytes (201 packets)
TX: 4084 bytes (23 packets)
signal: -31 dBm
tx bitrate: 300.0 MBit/s MCS 15 40Mhz short GI
当输出没有连接到一个AP的例子:
iw dev wlan0 link
Not connected.
这会发生在当你没有连接到一个AP的情况下。 要连接到一个AP可以使用 iw connect ,如果连接要求:
- 无加密
- 使用WEP加密
建立基本连接
当且仅当AP:
- 无加密
- 使用WEP加密
然而应该指出的是,如果你断开AP的连接时,这可以在一个繁忙的环境中频繁发生,你将需要重新发出命令。 如果你不想这样做,你可以使用wpa_supplicant,它会在你断开连接后自动尝试重新连接。
如果您选择自己处理断开连接,你可以使用 iw connect 如下所示。
如要连接到已禁用加密的AP,这里它的SSID是foo :
iw wlan0 connect foo
假设你有两个AP SSID 都是 foo ,你知道你要连接的是在 2432 频道,你可以指定使用的频率:
iw wlan0 connect foo 2432
iw wlan0 connect foo keys 0:abcde d:1:0011223344
获取station统计数据
$ iw dev wlan1 station dump
Station 12:34:56:78:9a:bc (on wlan0)
inactive time: 304 ms
rx bytes: 18816
rx packets: 75
tx bytes: 5386
tx packets: 21
signal: -29 dBm
tx bitrate: 54.0 MBit/s
获得station对应的peer统计信息
sudo iw dev wlan1 station get <peer-MAC-address>
peer-MAC-address>将是你的AP的MAC地址。
修改传输比特率
修改TX传统的比特率
性能。 例如:
iw wlan0 set bitrates legacy-2.4 12 18 24
iw wlan0 set bitrates legacy-2.4 6 12 24
修改tx HT MCS的比特率
设置使用MCS率传输的能力是通过让你指定频段和MCS率来实现。 注意,是否该设备实际上监听你的请求将根据设备驱动程序和固件的配合而变化。 例如:
iw dev wlan0 set bitrates mcs-5 4
iw dev wlan0 set bitrates mcs-2.4 10
iw dev wlan0 set bitrates mcs-2.4
iw dev wlan0 set bitrates mcs-5
设置传输功率
设置 txpower 。
iw dev <devname> set txpower <auto|fixed|limit> [<tx power in mBm>]
iw phy <phyname> set txpower <auto|fixed|limit> [<tx power in mBm>]
省电
在默认情况下使能 power save,你可以使用:
sudo iw dev wlan0 set power_save on
对于mac80211驱动程序,这意味着动态节电模式被启用。
查询当前的节电设定,您可以使用:
iw dev wlan0 get power_save
iw添加接口
有几种模式可以支持。 支持的模式包括:
- monitor
- managed [also station]
- wds
- mesh [also mp]
- ibss [also adhoc]
iw phy phy0 interface add moni0 type monitor
monitor by anything else and moni0 by the interface name, and need to replacephy0 by the PHY name for your hardware (usually phy0 will be correct unless you hotplugged or reloaded any modules.) If your udev is configured incorrectly, the newly created virtual interface may be renamed by it right away, use ip link to list all interfaces.
iw dev <devname> set freq <freq> [HT20|HT40+|HT40-]
iw phy <phyname> set freq <freq> [HT20|HT40+|HT40-]
iw phy <phyname> set channel <channel> [HT20|HT40+|HT40-]
iw dev <devname> set channel <channel> [HT20|HT40+|HT40-]
iw phy phy0 interface add wlan10 type managed
Modifying monitor interface flags
iw dev wlan0 interface add fish0 type monitor flags none
tcpdump -i fish0 -s 65000 -p -U -w /tmp/fishing.dump
The nice thing about these type of alternative monitor interfaces is you can further extend radiotap even with vendor extensions to add more data to radiotap to help debug device specific features.
Monitor flags possible
- none
- fcsfail
- plcpfail
- control
- otherbss
- cook
Deleting interfaces with iw
iw dev moni0 del
Virtual vif support
There is a dedicated section for virtual vif support, see the iw vif page.
Setting frequency with iw
iw dev wlan0 set freq 2412 [HT20|HT40+|HT40-]
Setting channel with iw
iw dev wlan0 set channel 1 [HT20|HT40+|HT40-]
Updating your regulatory domain
iw reg set alpha2
Where "alpha2" is the ISO/IEC 3166 alpha2 country code. The information used and set comes from our regulatory infrastructure.
Creating and inspecting Mesh Point interfaces with iw
You may add a mesh interface to drivers that support Mesh Point operation. Mesh Point interfaces have a mesh_id parameter which may be up to 32 bytes long. For example, to add an interface "mesh0" to device phy0 with mesh_id "mymesh",
iw phy phy0 interface add mesh0 type mp mesh_id mymesh
Mesh Point interfaces, by default, are configured on Channel 1. Mesh Point operation begins when the interface is brought up. In the default configuration, Mesh Point interfaces will automatically detect and attempt to create Peer Links with other Mesh Points (peers) having the same mesh ID. Use the station list and station statistics to see the peer list and Peer Link status.
iw dev mesh0 mpath dump
Please see the open80211s.org HOWTO for further details on Mesh Point related commands and their output, as well as more examples. iw also provides commands for advanced Mesh Point configuration. These are documented in the Advanced Tinkering section of the open80211s HOWTO.
Setting up a WDS peer
iw phy phy0 interface add wds0 type wds
iw dev wds0 set peer <MAC address>
Using 4-address for AP and client mode
In some situations it might be useful to run a network with an Access Point and multiple clients, but with each client bridged to a network behind it. For this to work, both the client and the AP need to transmit 4-address frames, containing both source and destination MAC addresses. 4-address mode is howOpenWrt supports WDS mode for mac80211 drivers, that is if you enable wds option on your OpenWrt OpenWrt wireless configuration you will end up using 4-address mode. 4-address mode is not compatible with other WDS implementations, ie, you'll need all endpoints using this mode in order for WDS to work appropriately.
To enable 4-address mode when creating an interface you should add 4addr on, for example:
iw phy phy0 interface add moni0 type managed 4addr on
When the client side interface is included in a bridge, add -b <bridge_interface> when runningwpa_supplicant.
wds_sta=1
Please note 4-address mode is currently broken on 3.9 because of commit 576eb62598f10c8c7fd75703fe89010cdcfff596 , this topic is currently being addressed on the mailing lists for a resolution.
Creating packet coalesce rules
- Expiration of hardware timer whose expiration time is set to maximum coalescing delay of matching coalesce rule.
- Coalescing buffer in hardware reaches it's limit.
- Packet doesn't match any of the configured coalesce rules.
'iw phy0 info'. Here is an example output:
Coalesce support:
* Maximum 8 coalesce rules supported
* Each rule contains upto 4 patterns of 1-4 bytes,
maximum packet offset 50 bytes
* Maximum supported coalescing delay 100 msecs
rule.
- Maximum coalescing delay
- List of packet patterns which needs to be matched
- Condition for coalescence. pattern 'match' or 'no match'
iw phy phy0 enable coalesce.conf
delay=25
condition=0
patterns=8+34:xx:ad:22,10+23:45:67,59:33:xx:25,ff:ff:ff:ff
delay=40
condition=1
patterns=12+00:xx:12,23:45:67,46:61:xx:50
$ iw phy phy0 coalesce show
Coalesce is enabled:
Rule - max coalescing delay: 25msec condition:match
* packet offset: 8 pattern: 34:--:ad:22
* packet offset: 10 pattern: 23:45:67
* packet offset: 0 pattern: 59:33:--:25
* packet offset: 0 pattern: ff:ff:ff:ff
Rule - max coalescing delay: 40msec condition:not match
* packet offset: 12 pattern: 00:--:12
* packet offset: 0 pattern: 23:45:67
* packet offset: 0 pattern: 46:61:--:50
iw phy phy0 coalesce disable
$ iw phy phy0 coalesce show
Coalesce is disabled.