/bin/wifi: Make 'wifi show' work for Frenzy.
This doesn't distinguish between AP and client mode; any available
information is shown as both. This will be resolved when we have
separate AP and client Frenzy interfaces; it's not worth solving it
separately in the meantime.
Change-Id: I12f6ca248e70bf2ebe1ade7f78c7896feec86a67
diff --git a/wifi/quantenna.py b/wifi/quantenna.py
index 10af967..ab45b04 100755
--- a/wifi/quantenna.py
+++ b/wifi/quantenna.py
@@ -2,6 +2,7 @@
"""Wifi commands for Quantenna using QCSAPI."""
+import json
import os
import subprocess
import time
@@ -9,6 +10,9 @@
import utils
+WIFIINFO_PATH = '/tmp/wifi/wifiinfo'
+
+
ALREADY_MEMBER_FMT = ('device %s is already a member of a bridge; '
"can't enslave it to bridge %s.")
NOT_MEMBER_FMT = 'device %s is not a slave of %s'
@@ -35,6 +39,18 @@
stderr=subprocess.STDOUT).strip()
+def info_parsed(interface):
+ """Fake version of iw.info_parsed."""
+ wifiinfo_filename = os.path.join(WIFIINFO_PATH, interface)
+
+ if not os.path.exists(wifiinfo_filename):
+ return {}
+
+ wifiinfo = json.load(open(wifiinfo_filename))
+ return {'addr' if k == 'BSSID' else k.lower(): v
+ for k, v in wifiinfo.iteritems()}
+
+
def _set_interface_in_bridge(bridge, interface, want_in_bridge):
"""Add/remove Quantenna interface from/to the bridge."""
if want_in_bridge:
diff --git a/wifi/quantenna_test.py b/wifi/quantenna_test.py
index 72f0333..12626c4 100755
--- a/wifi/quantenna_test.py
+++ b/wifi/quantenna_test.py
@@ -2,8 +2,11 @@
"""Tests for quantenna.py."""
+import json
import os
+import shutil
from subprocess import CalledProcessError
+import tempfile
from configs_test import FakeOptDict
import quantenna
@@ -191,5 +194,25 @@
wvtest.WVPASS(['rfenable', '0'] in calls)
+@wvtest.wvtest
+def info_parsed_test():
+ set_fakes()
+
+ try:
+ quantenna.WIFIINFO_PATH = tempfile.mkdtemp()
+ json.dump({
+ 'Channel': '64',
+ 'SSID': 'my ssid',
+ 'BSSID': '00:00:00:00:00:00',
+ }, open(os.path.join(quantenna.WIFIINFO_PATH, 'wlan0'), 'w'))
+
+ wvtest.WVPASSEQ(quantenna.info_parsed('wlan0'), {
+ 'ssid': 'my ssid',
+ 'addr': '00:00:00:00:00:00',
+ 'channel': '64',
+ })
+ finally:
+ shutil.rmtree(quantenna.WIFIINFO_PATH)
+
if __name__ == '__main__':
wvtest.wvtest_main()
diff --git a/wifi/wifi.py b/wifi/wifi.py
index 0000146..01bba84 100755
--- a/wifi/wifi.py
+++ b/wifi/wifi.py
@@ -459,6 +459,7 @@
True.
"""
for band in opt.band.split():
+ frenzy = False
print('Band: %s' % band)
for tokens in utils.subprocess_line_tokens(('iw', 'reg', 'get')):
if len(tokens) >= 2 and tokens[0] == 'country':
@@ -470,11 +471,20 @@
interface = iw.find_interface_from_band(
band, interface_type, opt.interface_suffix)
if interface is None:
- continue
- print('%sInterface: %s # %s GHz %s' %
- (prefix, interface, band, 'client' if 'cli' in interface else 'ap'))
+ if band == '5':
+ interface = _get_quantenna_interface()
+ if interface:
+ frenzy = True
+ if not interface:
+ continue
- info_parsed = iw.info_parsed(interface)
+ print('%sInterface: %s # %s GHz %s' %
+ (prefix, interface, band, prefix.lower() or 'ap'))
+
+ if frenzy:
+ info_parsed = quantenna.info_parsed(interface)
+ else:
+ info_parsed = iw.info_parsed(interface)
for k, label in (('channel', 'Channel'),
('ssid', 'SSID'),
('addr', 'BSSID')):
@@ -501,6 +511,13 @@
return True
+def _get_quantenna_interface():
+ try:
+ return subprocess.check_output(['get-quantenna-interface']).strip()
+ except subprocess.CalledProcessError as e:
+ utils.log('Failed to call get-quantenna-interface: %s', e)
+
+
@iw.requires_iw
def scan_wifi(opt):
"""Prints 'iw scan' results.