From fe616fbfa5b42d91ba801ff78b09d65824c6e152 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Tue, 30 Jan 2018 11:19:49 -0800 Subject: [PATCH] auto-t: hostapd util get_config_value and get_freq The hwsim SendFrame method requires the radio frequency which is obtained from the hostapd config file. This adds a generic API to get any config value from the hostapd config, as well as a get_freq API that converts the channel number to a frequency. --- autotests/util/hostapd.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/autotests/util/hostapd.py b/autotests/util/hostapd.py index ed04391d..5cea7fd7 100644 --- a/autotests/util/hostapd.py +++ b/autotests/util/hostapd.py @@ -1,6 +1,25 @@ #!/usr/bin/python3 import os, os.path import wiphy +import re + +chan_freq_map = [ + None, + 2412, + 2417, + 2422, + 2427, + 2432, + 2437, + 2442, + 2447, + 2452, + 2457, + 2462, + 2467, + 2472, + 2484 +] hostapd_map = {ifname: intf for wname, wiphy in wiphy.wiphy_map.items() for ifname, intf in wiphy.items() if intf.use == 'hostapd'} @@ -73,6 +92,21 @@ class HostapdCLI: def kill_all(): os.system('killall hostapd') + def get_config_value(self, key): + # first find the right config file + for wname in hostapd_map: + if wname == self.ifname: + with open(hostapd_map[wname].config, 'r') as f: + # read in config file and search for key + cfg = f.read(); + match = re.search(r'%s=.*' % key, cfg) + if match: + return match.group(0).split('=')[1] + return None + + def get_freq(self): + return chan_freq_map[int(self.get_config_value('channel'))] + def ungraceful_restart(self): ''' Ungracefully kill and restart hostapd