關於 iw

本文轉自:http://blog.csdn.net/robertsong2004/article/details/40044947


關於 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上,如果你是最後一個使用的發送速率,您可以使用下面的命令。

關聯到傳統(非802.11n標準)的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要求使用WPA或WPA2,那麼你必須使用wpa_supplicant 。

建立基本連接

你可以使用iw直接連接到一個AP上,當且僅當AP:

  • 無加密
  • 使用WEP加密

然而應該指出的是,如果你斷開AP的連接時,這可以在一個繁忙的環境中頻繁發生,你將需要重新發出命令。 如果你不想這樣做,你可以使用wpa_supplicant,它會在你斷開連接後自動嘗試重新連接。 

如果您選擇自己處理斷開連接,你可以使用 iw connect 如下所示。 

如要連接到已禁用加密的AP,這裏它的SSID是foo : 

iw wlan0 connect foo

假設你有兩個AP SSID 都是 foo ,你知道你要連接的是在 2432 頻道,你可以指定使用的頻率: 

iw wlan0 connect foo 2432

要連接到使用WEP的AP,則可以使用:

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

獲取station統計數據

要獲取station 的統計信息,如發送/接收的字節,最後發送的比特率(包括MCS率),你可以執行下面的命令:

$ 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統計信息

如果你想獲得 station 對應的 peer的統計信息,你可以使用下面的命令:

sudo iw dev wlan1 station get <peer-MAC-address>

在STA的情況下,上述的<peer-MAC-address>將是你的AP的MAC地址。

修改傳輸比特率

iw 支持修改發送的比特率,假託傳統和 HT MCS速率。 這是通過設定允許的比特率掩碼來實現,你也可以清除該掩碼。

修改TX傳統的比特率

您可以設定用於使用某些傳統的比特率傳輸的性能。 例如:

iw wlan0 set bitrates legacy-2.4 12 18 24

以下是如何使能一些人所說的“Purge G”來禁用802.11b 關聯:

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

清除所有 tx 比特率和設置的東西來恢復正常:

iw dev wlan0 set bitrates mcs-2.4
iw dev wlan0 set bitrates mcs-5

設置傳輸功率

可以通過使用各自的phy的任一設備接口名稱來設置 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]

要查看這些說明,請閱讀我們的模式文檔 。

例如,要添加一個 monitor 接口:

iw phy phy0 interface add moni0 type monitor

where you can replace 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.

Note that in case you want to monitor 802.11n you will need to specify channel width (20 or 20/40MHz) and in case of 20/40MHz if the upper or lower channel is being used. To do so you would use:

iw dev <devname> set freq <freq> [HT20|HT40+|HT40-]

or

iw phy <phyname> set freq <freq> [HT20|HT40+|HT40-]

You can also specify channel instead of frequency:

iw phy <phyname> set channel <channel> [HT20|HT40+|HT40-]
iw dev <devname> set channel <channel> [HT20|HT40+|HT40-]

To create a new managed mode interface you would use:

iw phy phy0 interface add wlan10 type managed

Note that the interface is automatically put into AP mode when using hostapd.

Modifying monitor interface flags

You can customize the type of monitor interface you create. This can be very useful for debugging purposes on end user systems. For example suppose you want to help a user you can take advantage of the fact that a monitor interface in mac80211 uses radiotap to pass up to userspace additional data. Say we want to help a user fish out data without affecting the device's performance by setting it it to a full monitor interface an monitor interface with no additional monitor flags can be created as follows:

iw dev wlan0 interface add fish0 type monitor flags none

You can then request the user to use tcpdump on a session:

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.

Keep in mind this requires drivers to honor mac80211's flag requests strictly, so drivers like ath5k and ath9k which still enable flags based on operation mode need to be fixed to take advantage of this.

Monitor flags possible

The following are flags you can specify:

  • none
  • fcsfail
  • plcpfail
  • control
  • otherbss
  • cook

Deleting interfaces with iw

The command line is:

iw dev moni0 del

Where "moni0" was the virtual interface interface that was created with the first command

Virtual vif support

There is a dedicated section for virtual vif support, see the iw vif page.

Setting frequency with iw

The command line is:

iw dev wlan0 set freq 2412 [HT20|HT40+|HT40-]

Setting channel with iw

The command line is:

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

Updating your regulatory domain

The command line is:

iw reg set alpha2

Where "alpha2" is the ISO/IEC 3166 alpha2 country code. The information used and set comes from our regulatory infrastructure.

You can also use the latest wpa_supplicant (as of 0.6.7) now to change your regulatory domain, to do so just add a "COUNTRY=US" entry into your configuration for example.

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.

After sending traffic (ex: pinging another mesh node), you may wish to see a list of Mesh Paths:

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

WDS mode is a non-standard extension to the IEEE 802.11 standard to allow transparent Ethernet bridging on the station and to implement seamingless hand-over for wireless clients roaming between different access points. Due to its non-standard nature, WDS is often implemented differently in wireless drivers and vendor firmwares making them incompatible with each other. In order to use WDS, one should use the same hardware and software on all deployed wireless devices to maintain compatibility.

To create a WDS peer you will first need to create an interface of WDS type, and then set the peer:

iw phy phy0 interface add wds0 type wds
iw dev wds0 set peer <MAC address>

In order for this to work the driver must implement the cfg80211 callback set_wds_peer(). mac80211 implements this callback, so the respective mac80211 driver would just need to support WDS type interfaces. What WDS will do is replace the first address on the 802.11 header with the peer address when TXing frames. Instead of using WDS though you may want to consider using 4-address mode described below if you have control over the software running on the AP and respective clients/peers connected.

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.

Linux wireless has support for 4-address mode for AP and STAs but each driver needs to define this capability explicitly. All mac80211 drivers support 4-address mode if AP or STA modes of operation are supported respectively.

On the AP side you can enable 4-address frames for individual clients by isolating them in separate AP VLANs which are configured in 4-address mode. Such an AP VLAN will be limited to one client only, and this client will be used as the destination for all traffic on its interface, regardless of the destination MAC address in the packet headers. The advantage of this mode compared to regular WDS mode is that it's easier to configure and does not require a static list of peer MAC addresses on any side. 4-address mode is incompatible with WDS.

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.

In hostapd you can enable this with the flag on hostapd.conf:

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

In most cases, host that receives IPv4 and IPv6 multicast/broadcast packets does not do anything with these packets. Therefore the reception of these unwanted packets causes unnecessary processing and power consumption.

Packet coalesce feature helps to reduce number of receive interrupts to host by buffering these packets in firmware/hardware for some predefined time. Receive interrupt will be generated when one of the following events occur.

  • 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.

To view coalesce configuration support information, you can use '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

You need to configure following parameters for creating a coalesce rule.

  • Maximum coalescing delay
  • List of packet patterns which needs to be matched
  • Condition for coalescence. pattern 'match' or 'no match'

Multiple such rules can be provided through a configuration file.

To enable coalesce feature using rules listed in coalesce.conf file, you can use:

iw phy phy0 enable coalesce.conf

Where coalesce.conf contains:

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

To display current coalesce configuration, you can use:

$ 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

To disable coalesce feature, you can use:

iw phy phy0 coalesce disable

'iw display' output when coalesce is not configured:

$ iw phy phy0 coalesce show
Coalesce is disabled.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章