3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-29 13:59:24 +01:00

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.
This commit is contained in:
James Prestwood 2018-01-30 11:19:49 -08:00 committed by Denis Kenzior
parent 17f55f3b4a
commit fe616fbfa5

View File

@ -1,6 +1,25 @@
#!/usr/bin/python3 #!/usr/bin/python3
import os, os.path import os, os.path
import wiphy 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() hostapd_map = {ifname: intf for wname, wiphy in wiphy.wiphy_map.items()
for ifname, intf in wiphy.items() if intf.use == 'hostapd'} for ifname, intf in wiphy.items() if intf.use == 'hostapd'}
@ -73,6 +92,21 @@ class HostapdCLI:
def kill_all(): def kill_all():
os.system('killall hostapd') 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): def ungraceful_restart(self):
''' '''
Ungracefully kill and restart hostapd Ungracefully kill and restart hostapd