aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJanusz Dziedzic <janusz.dziedzic@tieto.com>2016-03-04 09:20:34 (GMT)
committerJouni Malinen <j@w1.fi>2016-03-05 15:44:51 (GMT)
commit0fd4792b48f9de3ba7ce03649cff10f166a2908a (patch)
treec70358b002c4cd434b0b5eb2062c3eb2a15c3d36
parenta2c88a8025b2d76718e862489c37c5252ffc4a67 (diff)
downloadhostap-0fd4792b48f9de3ba7ce03649cff10f166a2908a.zip
hostap-0fd4792b48f9de3ba7ce03649cff10f166a2908a.tar.gz
hostap-0fd4792b48f9de3ba7ce03649cff10f166a2908a.tar.bz2
tests: Add UDP ctrl_iface support to wpasupplicant.py
Allow use of a remote host using wpaspy.Ctrl with UDP ctrl_iface support. Signed-off-by: Janusz Dziedzic <janusz.dziedzic@tieto.com>
-rw-r--r--tests/hwsim/wpasupplicant.py47
1 files changed, 39 insertions, 8 deletions
diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py
index 13a93ec..e5a07e2 100644
--- a/tests/hwsim/wpasupplicant.py
+++ b/tests/hwsim/wpasupplicant.py
@@ -17,18 +17,24 @@ logger = logging.getLogger()
wpas_ctrl = '/var/run/wpa_supplicant'
class WpaSupplicant:
- def __init__(self, ifname=None, global_iface=None):
+ def __init__(self, ifname=None, global_iface=None, hostname=None,
+ port=9877, global_port=9878):
+ self.hostname = hostname
self.group_ifname = None
self.gctrl_mon = None
if ifname:
- self.set_ifname(ifname)
+ self.set_ifname(ifname, hostname, port)
else:
self.ifname = None
self.global_iface = global_iface
if global_iface:
- self.global_ctrl = wpaspy.Ctrl(global_iface)
- self.global_mon = wpaspy.Ctrl(global_iface)
+ if hostname != None:
+ self.global_ctrl = wpaspy.Ctrl(hostname, global_port)
+ self.global_mon = wpaspy.Ctrl(hostname, global_port)
+ else:
+ self.global_ctrl = wpaspy.Ctrl(global_iface)
+ self.global_mon = wpaspy.Ctrl(global_iface)
self.global_mon.attach()
else:
self.global_mon = None
@@ -40,10 +46,14 @@ class WpaSupplicant:
self.global_ctrl = None
self.remove_ifname()
- def set_ifname(self, ifname):
+ def set_ifname(self, ifname, hostname=None, port=9877):
self.ifname = ifname
- self.ctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
- self.mon = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
+ if hostname != None:
+ self.ctrl = wpaspy.Ctrl(hostname, port)
+ self.mon = wpaspy.Ctrl(hostname, port)
+ else:
+ self.ctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
+ self.mon = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
self.mon.attach()
def remove_ifname(self):
@@ -53,6 +63,26 @@ class WpaSupplicant:
self.ctrl = None
self.ifname = None
+ def get_ctrl_iface_port(self, ifname):
+ if self.hostname is None:
+ return None
+
+ res = self.global_request("INTERFACES ctrl")
+ lines = res.splitlines()
+ found = False
+ for line in lines:
+ words = line.split()
+ if words[0] == ifname:
+ found = True
+ break
+ if not found:
+ raise Exception("Could not find UDP port for " + ifname)
+ res = line.find("ctrl_iface=udp:")
+ if res == -1:
+ raise Exception("Wrong ctrl_interface format")
+ words = line.split(":")
+ return int(words[1])
+
def interface_add(self, ifname, config="", driver="nl80211",
drv_params=None, br_ifname=None, create=False,
set_ifname=True, all_params=False, if_type=None):
@@ -85,7 +115,8 @@ class WpaSupplicant:
if "FAIL" in self.global_request(cmd):
raise Exception("Failed to add a dynamic wpa_supplicant interface")
if not create and set_ifname:
- self.set_ifname(ifname)
+ port = self.get_ctrl_iface_port(ifname)
+ self.set_ifname(ifname, self.hostname, port)
def interface_remove(self, ifname):
self.remove_ifname()