def flush(self):
self.ctrl.request("FLUSH")
+ def get_ctrl_iface_port(self, ifname):
+ if self.hostname is None:
+ return None
+
+ res = self.ctrl.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])
class Hostapd:
def __init__(self, ifname, bssidx=0, hostname=None, port=8877):
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()
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")
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")