Merge changes I6e276f31,I63859b5b

* changes:
  wifi_files: don't touch update.new too often.
  wifi_files: escape SSID for JSON.
diff --git a/wifi/iw.py b/wifi/iw.py
index b1d49b5..db6590f 100644
--- a/wifi/iw.py
+++ b/wifi/iw.py
@@ -46,11 +46,15 @@
 
 
 def _info(interface, **kwargs):
-  return subprocess.check_output(('iw', interface, 'info'), **kwargs)
+  return subprocess.check_output(('iw', 'dev', interface, 'info'), **kwargs)
 
 
 def _link(interface, **kwargs):
-  return subprocess.check_output(('iw', interface, 'link'), **kwargs)
+  return subprocess.check_output(('iw', 'dev', interface, 'link'), **kwargs)
+
+
+def _scan(interface, **kwargs):
+  return subprocess.check_output(('iw', 'dev', interface, 'scan'), **kwargs)
 
 
 _WIPHY_RE = re.compile(r'Wiphy (?P<phy>\S+)')
@@ -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..1f81458 100755
--- a/wifi/wifi.py
+++ b/wifi/wifi.py
@@ -30,8 +30,9 @@
 {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]
+b,band=                           Wifi band(s) to use (5 GHz and/or 2.4 GHz).  set, setclient, and scan have a default of 2.4 and cannot take multiple-band values.  [2.4 5]
 c,channel=                        Channel to use [auto]
 a,autotype=                       Autochannel method to use (LOW, HIGH, DFS, NONDFS, ANY,OVERLAP) [NONDFS]
 s,ssid=                           SSID to use [{ssid}]
@@ -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.ap, 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])