Example #1
0
 def __init__(self, ifname):
     self.ifname = ifname
     self.ctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
     if "PONG" not in self.ctrl.request("PING"):
         raise Exception("Failed to connect to eapol_test (%s)" % ifname)
     self.mon = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
     self.mon.attach()
Example #2
0
 def __init__(self, ifname, bssidx=0):
     self.ifname = ifname
     self.ctrl = wpaspy.Ctrl(os.path.join(hapd_ctrl, ifname))
     self.mon = wpaspy.Ctrl(os.path.join(hapd_ctrl, ifname))
     self.mon.attach()
     self.bssid = None
     self.bssidx = bssidx
Example #3
0
    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
        self.host = remotehost.Host(hostname, ifname)
        self._group_dbg = None
        if ifname:
            self.set_ifname(ifname, hostname, port)
            res = self.get_driver_status()
            if 'capa.flags' in res and int(res['capa.flags'], 0) & 0x20000000:
                self.p2p_dev_ifname = 'p2p-dev-' + self.ifname
            else:
                self.p2p_dev_ifname = ifname
        else:
            self.ifname = None

        self.global_iface = global_iface
        if global_iface:
            if hostname != None:
                self.global_ctrl = wpaspy.Ctrl(hostname, global_port)
                self.global_mon = wpaspy.Ctrl(hostname, global_port)
                self.global_dbg = hostname + "/" + str(global_port) + "/"
            else:
                self.global_ctrl = wpaspy.Ctrl(global_iface)
                self.global_mon = wpaspy.Ctrl(global_iface)
                self.global_dbg = ""
            self.global_mon.attach()
        else:
            self.global_mon = None
Example #4
0
    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, hostname, port)
        else:
            self.ifname = None

        self.global_iface = global_iface
        if 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
Example #5
0
def wpas_connect(host=None, port=9877):
    ifaces = []

    if host != None:
        try:
            wpas = wpaspy.Ctrl(host, port)
            return wpas
        except:
            print("Could not connect to host: ", host)
            return None

    if os.path.isdir(wpas_ctrl):
        try:
            ifaces = [
                os.path.join(wpas_ctrl, i) for i in os.listdir(wpas_ctrl)
            ]
        except OSError as error:
            print("Could not find wpa_supplicant: ", error)
            return None

    if len(ifaces) < 1:
        print("No wpa_supplicant control interface found")
        return None

    for ctrl in ifaces:
        try:
            wpas = wpaspy.Ctrl(ctrl)
            return wpas
        except Exception as e:
            pass
    return 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
        self.host = remotehost.Host(hostname, ifname)
        if ifname:
            self.set_ifname(ifname, hostname, port)
        else:
            self.ifname = None

        self.global_iface = global_iface
        if global_iface:
            if hostname != None:
                self.global_ctrl = wpaspy.Ctrl(hostname, global_port)
                self.global_mon = wpaspy.Ctrl(hostname, global_port)
                self.global_dbg = hostname + "/" + str(global_port) + "/"
            else:
                self.global_ctrl = wpaspy.Ctrl(global_iface)
                self.global_mon = wpaspy.Ctrl(global_iface)
                self.global_dbg = ""
            self.global_mon.attach()
        else:
            self.global_mon = None
Example #7
0
 def set_ifname(self, ifname, hostname=None, port=9877):
     self.ifname = 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()
Example #8
0
 def group_request(self, cmd):
     if self.group_ifname and self.group_ifname != self.ifname:
         if self.hostname is None:
             gctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, self.group_ifname))
         else:
             port = self.get_ctrl_iface_port(self.group_ifname)
             gctrl = wpaspy.Ctrl(self.hostname, port)
         logger.debug(self.group_dbg + ": CTRL(group): " + cmd)
         return gctrl.request(cmd)
     return self.request(cmd)
Example #9
0
 def __init__(self, hostname=None, port=8878):
     self.hostname = hostname
     self.port = port
     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()
Example #10
0
 def __init__(self, ifname, bssidx=0, hostname=None, port=8877):
     self.ifname = 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
    def __init__(self, ifname, global_iface=None):
        self.ifname = ifname
        self.group_ifname = None
        self.ctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
        self.mon = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
        self.mon.attach()

        self.global_iface = global_iface
        if global_iface:
            self.global_ctrl = wpaspy.Ctrl(global_iface)
            self.global_mon = wpaspy.Ctrl(global_iface)
            self.global_mon.attach()
Example #12
0
 def __init__(self, ifname, bssidx=0, hostname=None, port=8877):
     self.hostname = hostname
     self.host = remotehost.Host(hostname, ifname)
     self.ifname = ifname
     print hapd_ctrl
     print ifname
     self.ctrl = wpaspy.Ctrl(os.path.join(hapd_ctrl, ifname))
     self.mon = wpaspy.Ctrl(os.path.join(hapd_ctrl, ifname))
     self.dbg = ifname
     self.mon.attach()
     self.bssid = None
     self.bssidx = bssidx
Example #13
0
 def set_ifname(self, ifname, hostname=None, port=9877):
     self.ifname = ifname
     if hostname != None:
         self.ctrl = wpaspy.Ctrl(hostname, port)
         self.mon = wpaspy.Ctrl(hostname, port)
         self.host = remotehost.Host(hostname, ifname)
         self.dbg = hostname + "/" + ifname
     else:
         self.ctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
         self.mon = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
         self.dbg = ifname
     self.mon.attach()
Example #14
0
    def __init__(self, ifname=None, global_iface=None):
        self.group_ifname = None
        if ifname:
            self.set_ifname(ifname)
        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)
            self.global_mon.attach()
Example #15
0
 def __init__(self, hostname=None, port=8878):
     self.host = remotehost.Host(hostname)
     self.hostname = hostname
     self.port = port
     if hostname is None:
         self.ctrl = wpaspy.Ctrl(hapd_global)
         self.mon = wpaspy.Ctrl(hapd_global)
         self.dbg = ""
     else:
         self.ctrl = wpaspy.Ctrl(hostname, port)
         self.mon = wpaspy.Ctrl(hostname, port)
         self.dbg = hostname + "/" + str(port)
     self.mon.attach()
Example #16
0
def wpas_connect():
    ifaces = []
    if os.path.isdir(wpas_ctrl):
        try:
            ifaces = [os.path.join(wpas_ctrl, i) for i in os.listdir(wpas_ctrl)]
        except OSError as error:
            summary("Could not find wpa_supplicant: %s", str(error))
            return None

    if len(ifaces) < 1:
        summary("No wpa_supplicant control interface found")
        return None

    for ctrl in ifaces:
        if ifname and ifname not in ctrl:
            continue
        if os.path.basename(ctrl).startswith("p2p-dev-"):
            # skip P2P management interface
            continue
        try:
            summary("Trying to use control interface " + ctrl)
            wpas = wpaspy.Ctrl(ctrl)
            return wpas
        except Exception as e:
            pass
    summary("Could not connect to wpa_supplicant")
    return None
Example #17
0
def wpas_connect(host=None, port=9877):
    try:
        wpas = wpaspy.Ctrl(host, port)
        return wpas
    except:
        print("Could not connect to host: ", host)
        return None
Example #18
0
def wpas_connect():
    ifaces = []
    if os.path.isdir(wpas_ctrl):
        try:
            ifaces = [
                os.path.join(wpas_ctrl, i) for i in os.listdir(wpas_ctrl)
            ]
        except OSError as error:
            print("Could not find wpa_supplicant: ", error)
            return None

    if len(ifaces) < 1:
        print("No wpa_supplicant control interface found")
        return None

    for ctrl in ifaces:
        if ifname:
            if ifname not in ctrl:
                continue
        try:
            print("Trying to use control interface " + ctrl)
            wpas = wpaspy.Ctrl(ctrl)
            return wpas
        except Exception as e:
            pass
    return None
Example #19
0
 def __init__(self, apdev=None):
     try:
         hostname = apdev['hostname']
         port = apdev['port']
     except:
         hostname = None
         port = 8878
     self.host = remotehost.Host(hostname)
     self.hostname = hostname
     self.port = port
     if hostname is None:
         self.ctrl = wpaspy.Ctrl(hapd_global)
         self.mon = wpaspy.Ctrl(hapd_global)
         self.dbg = ""
     else:
         self.ctrl = wpaspy.Ctrl(hostname, port)
         self.mon = wpaspy.Ctrl(hostname, port)
         self.dbg = hostname + "/" + str(port)
     self.mon.attach()
Example #20
0
def wpas_connect(host=None, port=9877):
    ifaces = []

    if host != None:
        try:
            wpas = wpaspy.Ctrl(host, port)
            return wpas
        except:
            print "Could not connect to host: ", host
            return None

    if os.path.isdir(wpas_ctrl):
        try:
            ifaces = [
                os.path.join(wpas_ctrl, i) for i in os.listdir(wpas_ctrl)
            ]
        except OSError, error:
            print "Could not find wpa_supplicant: ", error
            return None
Example #21
0
def wpas_connect():
    ifaces = []
    if os.path.isdir(wpas_ctrl):
        try:
            ifaces = [
                os.path.join(wpas_ctrl, i) for i in os.listdir(wpas_ctrl)
            ]
        except OSError as error:
            print("Could not find hostapd: ", error)
            return None

    if len(ifaces) < 1:
        print("No hostapd control interface found")
        return None

    for ctrl in ifaces:
        try:
            wpas = wpaspy.Ctrl(ctrl)
            return wpas
        except Exception as e:
            pass
    return None
Example #22
0
 def __init__(self, ifname):
     self.ifname = ifname
     self.group_ifname = None
     self.ctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
     self.mon = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
     self.mon.attach()
Example #23
0
    def group_form_result(self, ev, expect_failure=False, go_neg_res=None):
        if expect_failure:
            if "P2P-GROUP-STARTED" in ev:
                raise Exception(
                    "Group formation succeeded when expecting failure")
            exp = r'<.>(P2P-GO-NEG-FAILURE) status=([0-9]*)'
            s = re.split(exp, ev)
            if len(s) < 3:
                return None
            res = {}
            res['result'] = 'go-neg-failed'
            res['status'] = int(s[2])
            return res

        if "P2P-GROUP-STARTED" not in ev:
            raise Exception("No P2P-GROUP-STARTED event seen")

        exp = r'<.>(P2P-GROUP-STARTED) ([^ ]*) ([^ ]*) ssid="(.*)" freq=([0-9]*) ((?:psk=.*)|(?:passphrase=".*")) go_dev_addr=([0-9a-f:]*) ip_addr=([0-9.]*) ip_mask=([0-9.]*) go_ip_addr=([0-9.]*)'
        s = re.split(exp, ev)
        if len(s) < 11:
            exp = r'<.>(P2P-GROUP-STARTED) ([^ ]*) ([^ ]*) ssid="(.*)" freq=([0-9]*) ((?:psk=.*)|(?:passphrase=".*")) go_dev_addr=([0-9a-f:]*)'
            s = re.split(exp, ev)
            if len(s) < 8:
                raise Exception("Could not parse P2P-GROUP-STARTED")
        res = {}
        res['result'] = 'success'
        res['ifname'] = s[2]
        self.group_ifname = s[2]
        try:
            if self.hostname is None:
                self.gctrl_mon = wpaspy.Ctrl(
                    os.path.join(wpas_ctrl, self.group_ifname))
            else:
                port = self.get_ctrl_iface_port(self.group_ifname)
                self.gctrl_mon = wpaspy.Ctrl(self.hostname, port)
            self.gctrl_mon.attach()
        except:
            logger.debug("Could not open monitor socket for group interface")
            self.gctrl_mon = None
        res['role'] = s[3]
        res['ssid'] = s[4]
        res['freq'] = s[5]
        if "[PERSISTENT]" in ev:
            res['persistent'] = True
        else:
            res['persistent'] = False
        p = re.match(r'psk=([0-9a-f]*)', s[6])
        if p:
            res['psk'] = p.group(1)
        p = re.match(r'passphrase="(.*)"', s[6])
        if p:
            res['passphrase'] = p.group(1)
        res['go_dev_addr'] = s[7]

        if len(s) > 8 and len(s[8]) > 0:
            res['ip_addr'] = s[8]
        if len(s) > 9:
            res['ip_mask'] = s[9]
        if len(s) > 10:
            res['go_ip_addr'] = s[10]

        if go_neg_res:
            exp = r'<.>(P2P-GO-NEG-SUCCESS) role=(GO|client) freq=([0-9]*)'
            s = re.split(exp, go_neg_res)
            if len(s) < 4:
                raise Exception("Could not parse P2P-GO-NEG-SUCCESS")
            res['go_neg_role'] = s[2]
            res['go_neg_freq'] = s[3]

        return res
Example #24
0
 def __init__(self):
     self.ctrl = wpaspy.Ctrl(hapd_global)
     self.mon = wpaspy.Ctrl(hapd_global)
     self.mon.attach()
Example #25
0
    if os.path.isdir(wpas_ctrl):
        try:
            ifaces = [
                os.path.join(wpas_ctrl, i) for i in os.listdir(wpas_ctrl)
            ]
        except OSError, error:
            print "Could not find wpa_supplicant: ", error
            return None

    if len(ifaces) < 1:
        print "No wpa_supplicant control interface found"
        return None

    for ctrl in ifaces:
        try:
            wpas = wpaspy.Ctrl(ctrl)
            return wpas
        except Exception, e:
            pass
    return None


def main(host=None, port=9877):
    print "Testing wpa_supplicant control interface connection"
    wpas = wpas_connect(host, port)
    if wpas is None:
        return
    print "Connected to wpa_supplicant"
    print wpas.request('PING')

    mon = wpas_connect(host, port)
Example #26
0
 def __init__(self):
     self.ctrl = wpaspy.Ctrl(hapd_global)
Example #27
0
 def group_request(self, cmd):
     if self.group_ifname and self.group_ifname != self.ifname:
         logger.debug(self.group_ifname + ": CTRL: " + cmd)
         gctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, self.group_ifname))
         return gctrl.request(cmd)
     return self.request(cmd)
Example #28
0
 def set_ifname(self, ifname):
     self.ifname = ifname
     self.ctrl = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
     self.mon = wpaspy.Ctrl(os.path.join(wpas_ctrl, ifname))
     self.mon.attach()
Example #29
0
 def __init__(self, ifname):
     self.ifname = ifname
     self.ctrl = wpaspy.Ctrl(os.path.join(hapd_ctrl, ifname))
     self.mon = wpaspy.Ctrl(os.path.join(hapd_ctrl, ifname))
     self.mon.attach()