Allow to use UDP CTRL (wpaspy) with remote client. Signed-off-by: Janusz Dziedzic <janusz.dziedzic@xxxxxxxxx> --- tests/hwsim/hostapd.py | 44 +++++++++++++++++++++++++++----------------- tests/hwsim/wpasupplicant.py | 24 +++++++++++++++++------- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py index 4613efe..3b097ac 100644 --- a/tests/hwsim/hostapd.py +++ b/tests/hwsim/hostapd.py @@ -19,9 +19,14 @@ def mac2tuple(mac): return struct.unpack('6B', binascii.unhexlify(mac.replace(':',''))) class HostapdGlobal: - def __init__(self): - self.ctrl = wpaspy.Ctrl(hapd_global) - self.mon = wpaspy.Ctrl(hapd_global) + def __init__(self, hostname=None, port=8878): + self.host = wpaspy.Host(hostname) + if hostname is None: + self.ctrl = wpaspy.Ctrl(hapd_global) + self.mon = wpaspy.Ctrl(hapd_global) + else: + self.ctrl = wpaspy.Ctrl(hostname, port) + self.mon = wpaspy.Ctrl(hostname, port) self.mon.attach() def request(self, cmd): @@ -77,10 +82,15 @@ class HostapdGlobal: class Hostapd: - def __init__(self, ifname, bssidx=0): + def __init__(self, ifname, bssidx=0, hostname=None, port=8877): self.ifname = ifname - self.ctrl = wpaspy.Ctrl(os.path.join(hapd_ctrl, ifname)) - self.mon = wpaspy.Ctrl(os.path.join(hapd_ctrl, ifname)) + + if hostname is None: + self.ctrl = wpaspy.Ctrl(os.path.join(hapd_ctrl, ifname)) + self.mon = wpaspy.Ctrl(os.path.join(hapd_ctrl, ifname)) + else: + self.ctrl = wpaspy.Ctrl(hostname, port) + self.mon = wpaspy.Ctrl(hostname, port) self.mon.attach() self.bssid = None self.bssidx = bssidx @@ -275,12 +285,12 @@ class Hostapd: vals[name_val[0]] = name_val[1] return vals -def add_ap(ifname, params, wait_enabled=True, no_enable=False, timeout=30): +def add_ap(ifname, params, wait_enabled=True, no_enable=False, timeout=30, hostname=None): logger.info("Starting AP " + ifname) - hapd_global = HostapdGlobal() + hapd_global = HostapdGlobal(hostname=hostname) hapd_global.remove(ifname) hapd_global.add(ifname) - hapd = Hostapd(ifname) + hapd = Hostapd(ifname, hostname=hostname) if not hapd.ping(): raise Exception("Could not ping hostapd") hapd.set_defaults() @@ -310,25 +320,25 @@ def add_ap(ifname, params, wait_enabled=True, no_enable=False, timeout=30): raise Exception("AP startup failed") return hapd -def add_bss(phy, ifname, confname, ignore_error=False): +def add_bss(phy, ifname, confname, ignore_error=False, hostname=None): logger.info("Starting BSS phy=" + phy + " ifname=" + ifname) - hapd_global = HostapdGlobal() + hapd_global = HostapdGlobal(hostname=hostname) hapd_global.add_bss(phy, confname, ignore_error) - hapd = Hostapd(ifname) + hapd = Hostapd(ifname, hostname=hostname) if not hapd.ping(): raise Exception("Could not ping hostapd") -def add_iface(ifname, confname): +def add_iface(ifname, confname, hostname=None): logger.info("Starting interface " + ifname) - hapd_global = HostapdGlobal() + hapd_global = HostapdGlobal(hostname=hostname) hapd_global.add_iface(ifname, confname) - hapd = Hostapd(ifname) + hapd = Hostapd(ifname, hostname=hostname) if not hapd.ping(): raise Exception("Could not ping hostapd") -def remove_bss(ifname): +def remove_bss(ifname, hostname=None): logger.info("Removing BSS " + ifname) - hapd_global = HostapdGlobal() + hapd_global = HostapdGlobal(hostname=hostname) hapd_global.remove(ifname) def wpa2_params(ssid=None, passphrase=None): diff --git a/tests/hwsim/wpasupplicant.py b/tests/hwsim/wpasupplicant.py index da90ffd..57d66a4 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.host = wpaspy.Host(hostname, ifname) + 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, port): 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): -- 1.9.1 _______________________________________________ Hostap mailing list Hostap@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/hostap