diff mbox

[v5,22/25] tests: hostapd.py add get_ctrl_iface_port

Message ID 1457083241-7492-23-git-send-email-janusz.dziedzic@tieto.com
State Accepted
Headers show

Commit Message

Janusz.Dziedzic@tieto.com March 4, 2016, 9:20 a.m. UTC
Add method to get UDP port for required iface.

Signed-off-by: Janusz Dziedzic <janusz.dziedzic@tieto.com>
---
 tests/hwsim/hostapd.py | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py
index 5368386..e4d6bc8 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 ctrl")
+        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")