[PATCH v2 21/22] tests: hostapd.py add get_ctrl_iface_port
Janusz Dziedzic
janusz.dziedzic at tieto.com
Sun Feb 7 05:07:54 PST 2016
Add method to get UDP port for required iface.
Signed-off-by: Janusz Dziedzic <janusz.dziedzic at tieto.com>
---
tests/hwsim/hostapd.py | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py
index 13a3fb1..1c0f9c2 100644
--- a/tests/hwsim/hostapd.py
+++ b/tests/hwsim/hostapd.py
@@ -82,6 +82,25 @@ class HostapdGlobal:
def flush(self):
self.ctrl.request("FLUSH")
+ def get_ctrl_iface_port(self, ifname):
+ res = -1
+ if self.hostname is None:
+ return None
+
+ res = self.ctrl.request("INTERFACES")
+ lines = res.splitlines()
+ for line in lines:
+ words = line.split()
+ if words[0] == ifname:
+ res = 1
+ break
+ if res == -1:
+ raise Exception("Could not find UDP port for " + ifname)
+ res = line.find("ctrl_iface=udp:")
+ if res == -1:
+ raise Exception("Wrong ctrl_interace format")
+ words = line.split(":")
+ return int(words[1])
class Hostapd:
def __init__(self, ifname, bssidx=0, hostname=None, port=8877):
@@ -293,7 +312,8 @@ def add_ap(ifname, params, wait_enabled=True, no_enable=False, timeout=30, hostn
hapd_global = HostapdGlobal(hostname=hostname, port=port)
hapd_global.remove(ifname)
hapd_global.add(ifname)
- hapd = Hostapd(ifname, hostname=hostname)
+ port = hapd_global.get_ctrl_iface_port(ifname)
+ hapd = Hostapd(ifname, hostname=hostname, port=port)
if not hapd.ping():
raise Exception("Could not ping hostapd")
hapd.set_defaults()
@@ -327,7 +347,8 @@ def add_bss(phy, ifname, confname, ignore_error=False, hostname=None, port=8878)
logger.info("Starting BSS phy=" + phy + " ifname=" + ifname)
hapd_global = HostapdGlobal(hostname=hostname, port=port)
hapd_global.add_bss(phy, confname, ignore_error)
- hapd = Hostapd(ifname, hostname=hostname)
+ port = hapd_global.get_ctrl_iface_port(ifname)
+ hapd = Hostapd(ifname, hostname=hostname, port=port)
if not hapd.ping():
raise Exception("Could not ping hostapd")
@@ -335,7 +356,8 @@ def add_iface(ifname, confname, hostname=None, port=8878):
logger.info("Starting interface " + ifname)
hapd_global = HostapdGlobal(hostname=hostname, port=port)
hapd_global.add_iface(ifname, confname)
- hapd = Hostapd(ifname, hostname=hostname)
+ port = hapd_global.get_ctrl_iface_port(ifname)
+ hapd = Hostapd(ifname, hostname=hostname, port=port)
if not hapd.ping():
raise Exception("Could not ping hostapd")
--
1.9.1
More information about the Hostap
mailing list