Using The iw Tool#

iw is a new nl80211 based CLI configuration utility for wireless devices. It is used to set/get various parameters of a wireless network interface. This section covers the usage of 'iw' when used with the driver. For more information, see the relevant Linux man pages. The list of supported commands via "iw" tool are listed below.

Scan

Description

This command is used to scan for the Access points nearby our device.

Default Value

-

Input Parameters

Interface name on which scan has to be performed

Output Parameter

List of APs scanned

Reset Required

No

Usage

$ iw dev < interface_name > scan

Example

$ iw dev wifi0 scan

Connect

Description

This command is used to connect devices to the Access points in open mode.

Default Value

-

Input Parameters

SSID, BSSID, key_index, key of AP.

Output Parameter

None

Reset Required

No

Usage

Open mode: $ iw dev <interface_name> connect $SSID_NAME $BSSID.

Example

iw dev wifi0 connect TEST_AP ec:f6:4c:a0:3f:10

The above command connects to TEST_AP access point in open mode

Disconnect

Description

This command is used to disconnect our device from the connected network.

Default Value

-

Input Parameters

Interface name

Output Parameter

-

Reset Required

No

Usage

iw dev <interface_name> disconnect

Example

$ iw dev wifi0 disconnect

The above command disconnects our device from the connected Access point.

Link Status

Description

This command is used to get the connection status of our device.

Default Value

-

Input Parameters

Interface name.

Output Parameter

Connection status.

Reset Required

No

Usage

iw dev <interface_name> link

Example

iw dev wifi0 link

Interface Info

Description

This command is used to get information about the device .

Default Value

-

Input Parameters

Interface name.

Output Parameter

Interface mac address, type, operating mode etc.

Reset Required

No

Usage

iw dev <interface_name> info

Example

iw dev wifi0 info

Station Dump

Description

This command is used to station statistic information such as the amount of tx/rx bytes, the last TX bitrate (including MCS rate)

Default Value

-

Input Parameters

Interface name.

Output Parameter

Connected Stations/AP mac address,tx bytes, rx bytes, signal level etc,. will be displayed.

Reset Required

No

Usage

iw dev <interface_name> station dump

Example

iw dev wifi0 station dump

Set Power save mode

Description

This command is used to set power save mode on/off in station mode.

Default Value

-

Input Parameters

Interface name.

Output Parameter

No

Reset Required

No

Usage

iw dev <interface_name> set power_save <on | off>

Example

iw dev wifi0 set power_save <on | off>

Get Power save mode

Description

This command is used to get power save mode on/off in station mode.

Default Value

-

Input Parameters

Interface name.

Output Parameter

Shows whether power save mode is on | off in station mode

Reset Required

No

Usage

iw dev <interface_name> get power_save

Example

iw dev wifi0 get power_save

Set Rate

Description

This command is used to fix data rate.

Default Value

-

Input Parameters

Interface name, rate

Output Parameter

-

Reset Required

No

Usage

iw dev <interface_name> set bitrates legacy-<2.4|5> <legacy rate in Mbps>

For mcs rates, in iw versions below 3.14 use:

iw dev <interface_name> set bitrates mcs-<2.4|5> <mcs rate in Mbps>

In iw versions above 3.14 use:

iw dev <interface_name> set bitrates ht-mcs-<2.4|5> <mcs rate in Mbps>

Above command(s) with no rate specified is used to set things to normal (auto rate).

Ex: iw dev <interface_name> set bitrates mcs-<2.4|5> OR iw dev <interface_name> set bitrates ht-mcs-<2.4|5>

Note: 1. Driver supports only single rate to be set using above commands. Multiple rate setting is not supported.

2. For kernel version greater than 4.13.16 setting bitrate legacy will take only basic rates.

3. iw version can be obtained using below command # iw --version

Example

iw dev wlan0 set bitrates legacy-2.4 12

iw dev wlan0 set bitrates mcs-2.4 1

iw dev wlan0 set bitrates ht-mcs-5 4

Set country code

Description

This command is used to set the country code.

Default Value

-

Input Parameters

country_code

Output Parameter

-

Reset Required

-

Usage

iw reg set <country_code>

Example

iw reg set IN (For India) , iw reg set JP (For Japan), iw reg set GE (For Germany)

Get country code

Description

This command is used to get the country code.

Default Value

-

Input Parameters

-

Output Parameter

country domain

Reset Required

-

Usage

iw reg get

Example

output : country IN: DFS-JP (2402 - 2482 @ 40), (N/A, 20)

(5170 - 5250 @ 80), (N/A, 20)

(5250 - 5330 @ 80), (N/A, 20)

DFS (5735 - 5835 @ 80), (N/A, 20)

Set Tx Power

Description

This command is used to set the Tx Power.

Default Value

-

Input Parameters

tx power value

Output Parameter

-

Reset Required

-

Usage

iwconfig <interface_name> txpower <NmW|NdBm|off|auto>

Example

iwconfig wlan0 txpower 11

For the list of channels allowed in the current regulatory domain, see Wikipedia - List of WLAN channels.