예제 #1
0
    def test_invalid_command_line_option(self):
        ssid = 'ssidPassphrase'

        device = self.wd.list_devices(1)[0]

        with self.assertRaises(subprocess.CalledProcessError):
            ctx.start_process(['iwctl', '-z', 'station', device.name, 'connect', ssid], check=True)
예제 #2
0
파일: hostapd.py 프로젝트: ernestsora/iwd
 def set_neighbor(self, addr, ssid, nr):
     cmd = self.cmdline + [
         'set_neighbor', addr,
         'ssid="%s"' % ssid,
         'nr=%s' % nr
     ]
     ctx.start_process(cmd, wait=True)
예제 #3
0
    def test_connection_failure(self):
        ssid = 'ssidPassphrase'

        device = self.wd.list_devices(1)[0]

        with self.assertRaises(subprocess.CalledProcessError):
            ctx.start_process(['iwctl', '-P', 'incorrect_passphrase', 'station', device.name, \
                                'connect', ssid], check=True)
예제 #4
0
    def test_connection_with_username_and_password(self):
        ssid = 'ssidUNameAndPWord'

        device = self.wd.list_devices(1)[0]

        ctx.start_process(['iwctl', '-u', 'user', '-p', 'password', 'station', \
                            device.name, 'connect', ssid], check=True)
        self.check_connection_success(ssid)
예제 #5
0
    def test_connection_with_passphrase(self):
        ssid = 'ssidPassphrase'

        device = self.wd.list_devices(1)[0]

        # Use --dontaks cmd-line option
        with self.assertRaises(subprocess.CalledProcessError):
            ctx.start_process(['iwctl', 'd', 'station', device.name, 'connect', ssid],  check=True)

        ctx.start_process(['iwctl', '-P', 'passphrase', 'station', device.name, 'connect', ssid],
                                check=True)

        self.check_connection_success(ssid)
예제 #6
0
 def setUpClass(cls):
     hapd = HostapdCLI()
     # TODO: This could be moved into test-runner itself if other tests ever
     #       require this functionality (p2p, FILS, etc.). Since its simple
     #       enough it can stay here for now.
     ctx.start_process([
         'ifconfig', hapd.ifname, '192.168.1.1', 'netmask', '255.255.255.0'
     ],
                       wait=True)
     ctx.start_process(['touch', '/tmp/dhcpd.leases'], wait=True)
     cls.dhcpd_pid = ctx.start_process([
         'dhcpd', '-f', '-cf', '/tmp/dhcpd.conf', '-lf',
         '/tmp/dhcpd.leases', hapd.ifname
     ])
예제 #7
0
파일: hostapd.py 프로젝트: ernestsora/iwd
    def list_sta(self):
        proc = ctx.start_process(self.cmdline + ['list_sta'],
                                 wait=True,
                                 need_out=True)

        if not proc.out:
            return []

        return [line for line in proc.out.split('\n') if line]
예제 #8
0
    def test_connection_with_other_agent(self):
        wd = IWD()

        iwctl = ctx.start_process(['iwctl', '-P', 'secret_ssid2']).pid
        # Let iwctl to start and register its agent.
        wd.wait(2)

        self.check_connection(wd, 'ssid2')

        iwctl.terminate()
        iwctl.communicate()

        IWD.clear_storage()
예제 #9
0
    def test_connection_success(self):
        env = os.environ.copy()
        env['STATE_DIRECTORY'] = '/tmp/ead'
        p = ctx.start_process(['ead', '-i', 'eth1', '-d'], env=env)

        ead = EAD()

        adapter = ead.list_adapters(1)[0]

        condition = 'obj.connected == True'
        ead.wait_for_object_condition(adapter, condition)

        condition = 'obj.authenticated == True'
        ead.wait_for_object_condition(adapter, condition)

        ctx.stop_process(p)
예제 #10
0
    def setUpClass(cls):
        hwsim = Hwsim()

        cls.bss_hostapd = [
            HostapdCLI(config='ft-sae-1.conf'),
            HostapdCLI(config='ft-sae-2.conf'),
            HostapdCLI(config='ft-psk-3.conf')
        ]
        cls.bss_radio = [
            hwsim.get_radio('rad0'),
            hwsim.get_radio('rad1'),
            hwsim.get_radio('rad2')
        ]

        ctx.start_process(['ifconfig', cls.bss_hostapd[0].ifname, 'down', 'hw', \
                                'ether', '12:00:00:00:00:01', 'up'], wait=True)
        ctx.start_process(['ifconfig', cls.bss_hostapd[1].ifname, 'down', 'hw', \
                                'ether', '12:00:00:00:00:02', 'up'], wait=True)
        ctx.start_process(['ifconfig', cls.bss_hostapd[2].ifname, 'down', 'hw', \
                                'ether', '12:00:00:00:00:03', 'up'], wait=True)

        # Set interface addresses to those expected by hostapd config files
        cls.bss_hostapd[0].reload()
        cls.bss_hostapd[0].wait_for_event("AP-ENABLED")
        cls.bss_hostapd[1].reload()
        cls.bss_hostapd[1].wait_for_event("AP-ENABLED")
        cls.bss_hostapd[2].reload()
        cls.bss_hostapd[2].wait_for_event("AP-ENABLED")

        # Fill in the neighbor AP tables in both BSSes.  By default each
        # instance knows only about current BSS, even inside one hostapd
        # process.
        # FT still works without the neighbor AP table but neighbor reports
        # have to be disabled in the .conf files
        cls.bss_hostapd[0].set_neighbor(
            '12:00:00:00:00:02', 'TestFT',
            '1200000000028f0000005102060603000000')
        cls.bss_hostapd[0].set_neighbor(
            '12:00:00:00:00:03', 'TestFT',
            '1200000000038f0000005102060603000000')

        cls.bss_hostapd[1].set_neighbor(
            '12:00:00:00:00:01', 'TestFT',
            '1200000000018f0000005101060603000000')
        cls.bss_hostapd[1].set_neighbor(
            '12:00:00:00:00:03', 'TestFT',
            '1200000000038f0000005101060603000000')

        cls.bss_hostapd[2].set_neighbor(
            '12:00:00:00:00:01', 'TestFT',
            '1200000000018f0000005101060603000000')
        cls.bss_hostapd[2].set_neighbor(
            '12:00:00:00:00:02', 'TestFT',
            '1200000000028f0000005101060603000000')
예제 #11
0
파일: wpas.py 프로젝트: illiliti/eiwd
    def _start_wpas(self, config_name=None, p2p=False):
        main_interface = None
        for interface in ctx.wpas_interfaces:
            if config_name is None or interface.config == config_name:
                if main_interface is not None:
                    raise Exception(
                        'More than one wpa_supplicant interface matches given config'
                    )
                main_interface = interface

        if main_interface is None:
            raise Exception('No matching wpa_supplicant interface')

        ifname = main_interface.name
        if p2p:
            ifname = 'p2p-dev-' + ifname

        self.interface = main_interface
        self.ifname = ifname
        self.config_path = '/tmp/' + self.interface.config
        self.config = self._get_config()
        self.socket_path = self.config['ctrl_interface']
        self.io_watch = None

        cmd = [
            'wpa_supplicant', '-i', self.interface.name, '-c', self.config_path
        ]
        if ctx.is_verbose('wpa_supplicant-dbg'):
            cmd += ['-d']

        self.wpa_supplicant = ctx.start_process(cmd)

        self.sockets = {}
        self.cleanup_paths = []
        self.io_watch = GLib.io_add_watch(self._get_socket(), GLib.IO_IN,
                                          self._handle_data_in)

        self.p2p_peers = {}
        self.p2p_go_neg_requests = {}
        self.p2p_clients = {}
        self.p2p_group = None

        self._rx_data = []
        self._ctrl_request('ATTACH')
        self.wait_for_event('OK')
예제 #12
0
    def test_connection_use_own_agent_from_multiple_registered(self):

        wd = IWD()

        iwctl = ctx.start_process(['iwctl', '-P', 'secret_ssid2']).pid
        # Let iwctl to start and register its agent.
        wd.wait(2)

        psk_agent = PSKAgent("secret_ssid1")
        wd.register_psk_agent(psk_agent)

        self.check_connection(wd, 'ssid1')

        wd.unregister_psk_agent(psk_agent)

        iwctl.terminate()
        iwctl.communicate()

        IWD.clear_storage()
예제 #13
0
파일: hostapd.py 프로젝트: ernestsora/iwd
 def reload(self):
     # Seemingly all three commands needed for the instance to notice
     # interface's address change
     ctx.start_process(self.cmdline + ['reload'], wait=True)
     ctx.start_process(self.cmdline + ['disable'], wait=True)
     ctx.start_process(self.cmdline + ['enable'], wait=True)
예제 #14
0
파일: hostapd.py 프로젝트: ernestsora/iwd
 def deauthenticate(self, client_address):
     cmd = self.cmdline + ['deauthenticate', client_address]
     ctx.start_process(cmd, wait=True)
예제 #15
0
파일: hostapd.py 프로젝트: ernestsora/iwd
 def wps_pin(self, pin):
     cmd = self.cmdline + ['wps_pin', 'any', pin]
     ctx.start_process(cmd, wait=True)
예제 #16
0
파일: hostapd.py 프로젝트: ernestsora/iwd
 def wps_push_button(self):
     ctx.start_process(self.cmdline + ['wps_pbc'], wait=True)
예제 #17
0
    def p2p_client_test(self, preauthorize):
        wpas = Wpas(p2p=True)
        wd = IWD()

        # Not strictly necessary but prevents the station interface from queuing its scans
        # in the wiphy radio work queue and delaying P2P scans.
        wd.list_devices(1)[0].disconnect()

        devices = wd.list_p2p_devices(1)
        p2p = devices[0]
        p2p.enabled = True
        p2p.name = 'testdev1'

        wpas.p2p_find()
        p2p.discovery_request = True
        wd.wait(5)
        wd.wait_for_object_condition(wpas,
                                     'len(obj.p2p_peers) == 1',
                                     max_wait=20)
        p2p.discovery_request = False
        wpas.p2p_listen()

        peers = p2p.get_peers()
        self.assertEqual(len(peers), 1)
        peer = next(iter(peers.values()))
        self.assertEqual(peer.name, wpas.config['device_name'])
        self.assertEqual(peer.category, 'display')
        self.assertEqual(peer.subcategory, 'monitor')

        wpas_peer = next(iter(wpas.p2p_peers.values()))
        self.assertEqual(wpas_peer['name'], p2p.name)
        self.assertEqual(wpas_peer['pri_dev_type'],
                         '1-0050F204-6')  # 1 == Computer, 6 == Desktop
        self.assertEqual(wpas_peer['config_methods'], '0x1080')

        if preauthorize:
            wpas.p2p_authorize(wpas_peer)

        peer.connect(wait=False)

        self.assertEqual(len(wpas.p2p_go_neg_requests), 0)
        self.assertEqual(len(wpas.p2p_clients), 0)
        wd.wait_for_object_condition(wpas,
                                     'len(obj.p2p_go_neg_requests) == 1',
                                     max_wait=3)
        request = wpas.p2p_go_neg_requests[wpas_peer['p2p_dev_addr']]

        if not preauthorize:
            self.assertEqual(request['dev_passwd_id'], '4')
            self.assertEqual(request['go_intent'],
                             '2')  # Hardcoded in src/p2p.c

            wpas.p2p_accept_go_neg_request(request)

        wd.wait_for_object_condition(request, '\'success\' in obj', max_wait=3)
        self.assertEqual(request['success'], True)
        self.assertEqual(request['role'], 'GO')
        self.assertEqual(request['wps_method'], 'PBC')
        self.assertEqual(request['p2p_dev_addr'], wpas_peer['p2p_dev_addr'])

        wd.wait_for_object_condition(wpas,
                                     'obj.p2p_group is not None',
                                     max_wait=3)
        go_ifname = wpas.p2p_group['ifname']
        ctx.start_process([
            'ifconfig', go_ifname, '192.168.1.20', 'netmask', '255.255.255.0'
        ],
                          wait=True)
        os.system('> /tmp/dhcpd.leases')
        dhcpd = ctx.start_process([
            'dhcpd', '-f', '-cf', '/tmp/dhcpd.conf', '-lf',
            '/tmp/dhcpd.leases', go_ifname
        ])

        wd.wait_for_object_condition(wpas,
                                     'len(obj.p2p_clients) == 1',
                                     max_wait=3)
        client = wpas.p2p_clients[request['peer_iface']]
        self.assertEqual(client['p2p_dev_addr'], wpas_peer['p2p_dev_addr'])

        wd.wait_for_object_condition(peer, 'obj.connected', max_wait=15)
        our_ip = netifaces.ifaddresses(
            peer.connected_interface)[netifaces.AF_INET][0]['addr']
        self.assertEqual(peer.connected_ip, '192.168.1.20')
        self.assertEqual(our_ip, '192.168.1.30')

        testutil.test_iface_operstate(peer.connected_interface)
        testutil.test_ifaces_connected(peer.connected_interface, go_ifname)

        peer.disconnect()
        wd.wait_for_object_condition(wpas,
                                     'len(obj.p2p_clients) == 0',
                                     max_wait=3)
        self.assertEqual(peer.connected, False)

        p2p.enabled = False
        ctx.stop_process(dhcpd)
        wpas.clean_up()
예제 #18
0
    def test_invalid_command(self):
        device = self.wd.list_devices(1)[0]

        with self.assertRaises(subprocess.CalledProcessError):
            ctx.start_process(['iwctl', 'inexistent', 'command'], check=True)
예제 #19
0
    def p2p_connect_test(self, preauthorize, go):
        wd = IWD()
        wpas = Wpas(p2p=True)
        wpas_go_intent = 10 if not go else 1

        # Not strictly necessary but prevents the station interface from queuing its scans
        # in the wiphy radio work queue and delaying P2P scans.
        wd.list_devices(1)[0].disconnect()

        devices = wd.list_p2p_devices(1)
        p2p = devices[0]
        p2p.enabled = True
        p2p.name = 'testdev1'

        wpas.p2p_find()
        p2p.discovery_request = True
        wd.wait(5)
        wd.wait_for_object_condition(wpas,
                                     'len(obj.p2p_peers) == 1',
                                     max_wait=20)
        p2p.discovery_request = False
        wpas.p2p_listen()

        peers = p2p.get_peers()
        self.assertEqual(len(peers), 1)
        peer = next(iter(peers.values()))
        self.assertEqual(peer.name, wpas.config['device_name'])
        self.assertEqual(peer.category, 'display')
        self.assertEqual(peer.subcategory, 'monitor')

        wpas_peer = next(iter(wpas.p2p_peers.values()))
        self.assertEqual(wpas_peer['name'], p2p.name)
        self.assertEqual(wpas_peer['pri_dev_type'],
                         '1-0050F204-6')  # 1 == Computer, 6 == Desktop
        self.assertEqual(wpas_peer['config_methods'], '0x1080')

        if preauthorize:
            wpas.p2p_authorize(wpas_peer, go_intent=wpas_go_intent)

        peer.connect(wait=False)

        self.assertEqual(len(wpas.p2p_go_neg_requests), 0)
        self.assertEqual(len(wpas.p2p_clients), 0)
        wd.wait_for_object_condition(wpas,
                                     'len(obj.p2p_go_neg_requests) == 1',
                                     max_wait=3)
        request = wpas.p2p_go_neg_requests[wpas_peer['p2p_dev_addr']]

        if not preauthorize:
            self.assertEqual(request['dev_passwd_id'], '4')
            self.assertEqual(request['go_intent'],
                             '2')  # Hardcoded in src/p2p.c

            wpas.p2p_accept_go_neg_request(request, go_intent=wpas_go_intent)

        wd.wait_for_object_condition(request, '\'success\' in obj', max_wait=3)
        self.assertEqual(request['success'], True)
        self.assertEqual(request['role'], 'GO' if not go else 'client')
        self.assertEqual(request['wps_method'], 'PBC')
        self.assertEqual(request['p2p_dev_addr'], wpas_peer['p2p_dev_addr'])

        if go:
            # For some reason wpa_supplicant's newly created P2P-client interface doesn't inherit
            # the settings from the main interface which were loaded from the config file
            # (P2P-device and P2P-GO interfaces do), we need to set config_methods again.
            peer_ifname = 'p2p-' + wpas.interface.name + '-0'
            wpas.set('config_methods',
                     wpas.config['config_methods'],
                     ifname=peer_ifname)
            wpas.set('device_name',
                     wpas.config['device_name'],
                     ifname=peer_ifname)
            wpas.set('device_type',
                     wpas.config['device_type'],
                     ifname=peer_ifname)

        wd.wait_for_object_condition(wpas,
                                     'obj.p2p_group is not None',
                                     max_wait=3)
        peer_ifname = wpas.p2p_group['ifname']

        if not go:
            ctx.start_process([
                'ifconfig', peer_ifname, '192.168.1.20', 'netmask',
                '255.255.255.0'
            ],
                              wait=True)
            os.system('> /tmp/dhcpd.leases')
            dhcp = ctx.start_process([
                'dhcpd', '-f', '-cf', '/tmp/dhcpd.conf', '-lf',
                '/tmp/dhcpd.leases', peer_ifname
            ])

            wd.wait_for_object_condition(wpas,
                                         'len(obj.p2p_clients) == 1',
                                         max_wait=3)
            client = wpas.p2p_clients[request['peer_iface']]
            self.assertEqual(client['p2p_dev_addr'], wpas_peer['p2p_dev_addr'])
        else:
            dhcp = ctx.start_process([
                'dhclient', '-v', '-d', '--no-pid', '-cf', '/dev/null', '-lf',
                '/tmp/dhcpd.leases', '-sf', '/tmp/dhclient-script', peer_ifname
            ])

        wd.wait_for_object_condition(peer, 'obj.connected', max_wait=15)
        time.sleep(1)  # Give the client time to set the IP
        our_ip = netifaces.ifaddresses(
            peer.connected_interface)[netifaces.AF_INET][0]['addr']
        peer_ip = netifaces.ifaddresses(peer_ifname)[
            netifaces.AF_INET][0]['addr']
        self.assertEqual(peer.connected_ip, peer_ip)

        if not go:
            self.assertEqual(our_ip, '192.168.1.30')
            self.assertEqual(peer_ip, '192.168.1.20')
        else:
            self.assertEqual(our_ip, '192.168.1.1')
            self.assertEqual(peer_ip, '192.168.1.2')

        testutil.test_iface_operstate(peer.connected_interface)
        testutil.test_ifaces_connected(peer.connected_interface, peer_ifname)

        peer.disconnect()
        if not go:
            wd.wait_for_object_condition(wpas,
                                         'len(obj.p2p_clients) == 0',
                                         max_wait=3)
        else:
            wd.wait_for_object_condition(wpas,
                                         'obj.p2p_group is None',
                                         max_wait=3)
        self.assertEqual(peer.connected, False)

        p2p.enabled = False
        ctx.stop_process(dhcp)
        wpas.clean_up()