关于 iw

2023-10-27

本文转自: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.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

关于 iw 的相关文章

随机推荐

  • 【华为OD机试真题 Python语言】107、 查找重复代码

    文章目录 一 题目 题目描述 输入输出 样例1 样例2 二 思路参考 三 代码参考 作者 鲨鱼狼臧 个人博客首页 鲨鱼狼臧 专栏介绍 2023华为OD机试真题 使用Python进行解答 专栏每篇文章都包括真题 思路参考 代码分析 订阅有问题
  • Android 动态更新Menu菜单

    1 需求描述 Android Menu菜单是比较常见的功能 在ActionBar or ToolBar上显示 点击更多 3个点 会有下拉列表菜单展示 在工作项目中有个小需求改动 在 ToolBar上添加一个图标 点击后会切换图标状态 界面也
  • 如何利用python解方程_Python 解方程的三种方法

    首发于我的博客 The North 新年第一篇 搞起 这回写一个好久之前想做 一直搁着没做的东西 Python 解方程 其实是放假回家 趁着家里电脑重装 LOL 的时间过来写一篇 咱这回用三种不同的方法 来应对平常碰到的简单方程 Numpy
  • SpringBoot自定义数据源

    在SpringBoot中 我们可以自定义数据源以后就可以通过更改配置文件来替代复杂的代码文件 首先我们需要引入maven文件
  • 【VUE基础知识】

    VUE基础知识 代码基本结构 每一个vue文件由三部分组成 template script style 分别对应html js css 另外需要注意的是 template中只允许有一个块状元素 通常情况下是div 其他所有元素的标签都在这个
  • DVWA 三个等级的XSS

    XSS DOM LOW 这个难度极其简单 直接url注入一个scrip的命令 default medium 首先 用low的情况加个大小写混写 看看情况 default 结果 结果直接把我的代码给去掉了 再猜一下别的代码 default i
  • video thumbnails

    http www cyberciti biz tips howto linux creating a image thumbnails from shell prompt html http forum xbmc org showthrea
  • 超实用AI工具汇总

    如今 AI 已经渗透到我们生活的方方面面 很多集成AI的工具也发挥出了类人甚至超越人类的效用 下面本人就使用经历分享一些实用的 AI 工具 辅助大家提升工作效率和生活满意度 一 DOWNNI 其实很多时候可以看到某一些短视频想要保存起来 但
  • Android10.0系统启动之Launcher(桌面)启动流程-[Android取经之路]

    Android取经之路 系列文章 系统启动篇 Android系统架构Android是怎么启动的Android 10 0系统启动之init进程Android10 0系统启动之Zygote进程Android 10 0 系统启动之SystemSe
  • 博彦科技:区块链建立优质农产品“信任链”

    公众号对话框回复 阳光农安 获取演讲材料 自古以来 我国就是一个农业大国 农业整体发展状况对社会安定 国民经济增长都起着十分重要的作用 如今 在多方共同推动下 我国农业正向着精准化 智慧化方向转型升级 农业发展的质量和效益也得到了新的提升
  • gpt3是什么?和你有关系吗

    GPT 3 是一种大规模的自然语言处理模型 由OpenAI开发 它可以帮助用户解决自然语言处理任务 包括文本生成 问答 机器翻译等 与我相关 GPT 3 可以帮助我更好地理解自然语言 从而更好地回答用户的问题
  • SpringBoot 打包异常:Unable to find main class

    打包出现 原因是我service 工程没有 main 启动类 但是 pom 文件里有打包的依赖 去掉就行了
  • qtablewidget 设置列宽行高遇到的问题

    1 设置行高和列宽后 点击网格线不完整的item时候 item不触发 滚动条滚动 1 隐藏最后空列 有标题最后一行自动拉伸 2 ui QTableWidget gt horizontalHeader gt setStretchLastSec
  • 【python】冒泡法--详细讲解(python实现)

    博 主 米码收割机 技 能 C Python语言 公众号 测试开发自动化 获取源码 商业合作 荣 誉 阿里云博客专家博主 51CTO技术博主 专 注 专注主流机器人 人工智能等相关领域的开发 测试技术 python 冒泡法详解 python
  • 怎么复制Vmware虚拟机文件到其他的机器、别的硬盘目录

    Vmware虚拟机安装完之后有的时候需要挪动 备份虚拟机文件 比如 从公司电脑复制到家里电脑 或者将已安装好的虚拟机拷贝给同事使用 或者原来磁盘空间满了需要换一个磁盘等等 Vmware提供了相应的迁移和复制分发机制 避免了我们再次安装虚拟机
  • ubuntu 使用apt-get install安装特定版本 (boost)

    比如 安装libboost atomic1 58 可以使用aptitude search boost grep 1 58 查询 然后执行sudo apt get install libboost atomic1 58 dev 就可以进行安装
  • 7. 布隆过滤器BloomFilter

    概念 由一个初值都为零的bit数组和多个哈希函数构成 用来快速判断某个数据是否存在 类似set的数据结构 只是统计的结果不太准确 特点 高效的插入和查询 占用空间少 返回的结果是不确定的 一个元素如果判断结果为存在的时候元素不一定存在 但是
  • vue--element表格切换数据,选中不生效

    问题 点击 仅显示已选择 时 toggleRowSelection 无效 原因 可能是在修改后的table的数据里 有什么和之前不一样了 导致匹配不到对应的列 解决方案 使用find或者别的数组检索函数 找到table里的那一条数据 而不是
  • springboot整合swagger2+跨域问题

    前言 本篇文章主要介绍的是springboot整合swagger2 swagger2是一个规范和完整的框架 用于生成 描述 调用和可视化Restful风格的web服务 这里介绍两种方式实现 第一种是在yml中添加配置 第二种是添加配置类 G
  • 关于 iw

    本文转自 http blog csdn net robertsong2004 article details 40044947 关于 iw iw 是一种新的基于 nl80211 的用于无线设备的CLI配置实用程序 它支持最近已添加到内核所有