/bin/wifi: Add 'wifi scan'.
Change-Id: Ifcd04f06b0a1c67a7957d8b05c964a06cc6130f1
diff --git a/wifi/iw.py b/wifi/iw.py
index b1d49b5..dc57666 100644
--- a/wifi/iw.py
+++ b/wifi/iw.py
@@ -53,6 +53,10 @@
return subprocess.check_output(('iw', interface, 'link'), **kwargs)
+def _scan(interface, **kwargs):
+ return subprocess.check_output(('iw', interface, 'scan'), **kwargs)
+
+
_WIPHY_RE = re.compile(r'Wiphy (?P<phy>\S+)')
_FREQUENCY_AND_CHANNEL_RE = re.compile(r'\s*\* (?P<frequency>\d+) MHz'
r' \[(?P<channel>\d+)\]')
@@ -356,3 +360,8 @@
result.add(band)
return result
+
+
+def scan(interface):
+ """Return 'iw scan' output for printing."""
+ return _scan(interface)
diff --git a/wifi/wifi.py b/wifi/wifi.py
index f57e09e..852ed02 100755
--- a/wifi/wifi.py
+++ b/wifi/wifi.py
@@ -30,6 +30,7 @@
{bin} stopclient Disable wifi clients. Takes -b, -P, -S.
{bin} restore Restore saved client and access point options. Takes -b, -S.
{bin} show Print all known parameters. Takes -b, -S.
+{bin} scan Print 'iw scan' results for a single band. Takes -b, -S.
--
b,band= Wifi band(s) to use (5 GHz and/or 2.4 GHz). set commands have a default of 2.4 and cannot take multiple-band values. [2.4 5]
c,channel= Channel to use [auto]
@@ -491,6 +492,27 @@
return True
+@iw.requires_iw
+def scan_wifi(opt):
+ """Prints 'iw scan' results.
+
+ Args:
+ opt: The OptDict parsed from command line options.
+
+ Returns:
+ True.
+ """
+ band = opt.band.split()[0]
+ interface = iw.find_interface_from_band(
+ band, iw.INTERFACE_TYPE.client, opt.interface_suffix)
+ if interface is None:
+ raise BinWifiException('No client interface for band %s', band)
+
+ print(iw.scan(interface))
+
+ return True
+
+
def _is_hostapd_running(interface):
return utils.subprocess_quiet(
('hostapd_cli', '-i', interface, 'status'), no_stdout=True) == 0
@@ -974,6 +996,7 @@
'setclient': set_client_wifi,
'stopclient': stop_client_wifi,
'stopap': stop_ap_wifi,
+ 'scan': scan_wifi,
}[extra[0]]
except KeyError:
parser.fatal('Unrecognized command %s' % extra[0])