Beispiel #1
0
    def validate(self, ssid, autoconnect, throws=None, use_agent=False):

        wd = IWD(True)
        wd.wait(1)

        if use_agent:
            psk_agent = PSKAgent("secret123")
            wd.register_psk_agent(psk_agent)

        devices = wd.list_devices()
        self.assertIsNotNone(devices)
        device = devices[0]

        if autoconnect:
            self.check_autoconnect(wd, device, ssid, throws)
        else:
            condition = 'not obj.scanning'
            wd.wait_for_object_condition(device, condition)

            device.scan()

            condition = 'not obj.scanning'
            wd.wait_for_object_condition(device, condition)

            self.check_connect(wd, device, ssid, throws)

        if use_agent:
            wd.unregister_psk_agent(psk_agent)

        del wd
Beispiel #2
0
    def test_connection_success(self):
        hostapd = None

        for hostapd_if in list(hostapd_map.values()):
            hpd = HostapdCLI(hostapd_if)
            if hpd.get_config_value('ssid') == 'ssidEAP-AKA':
                hostapd = hpd
                break

        self.assertIsNotNone(hostapd)

        auth = AuthCenter('/tmp/hlrauc.sock', '/tmp/sim.db')

        wd = IWD()

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

        condition = 'not obj.scanning'
        wd.wait_for_object_condition(device, condition)

        device.scan()

        condition = 'not obj.scanning'
        wd.wait_for_object_condition(device, condition)

        ordered_networks = device.get_ordered_networks()
        ordered_network = ordered_networks[0]

        self.assertEqual(ordered_network.name, "ssidEAP-AKA")
        self.assertEqual(ordered_network.type, NetworkType.eap)

        condition = 'not obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        try:
            ordered_network.network_object.connect()
        except:
            auth.stop()
            raise

        condition = 'obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        hostapd.eapol_reauth(device.address)

        wd.wait(10)

        condition = 'obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        device.disconnect()

        condition = 'not obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        auth.stop()
Beispiel #3
0
    def test_connection_success(self):
        hostapd = None

        for hostapd_if in list(hostapd_map.values()):
            hpd = HostapdCLI(hostapd_if)
            if hpd.get_config_value('ssid') == 'ssidEAP-TTLS-MSCHAP':
                hostapd = hpd
                break

        self.assertIsNotNone(hostapd)

        wd = IWD()

        psk_agent = PSKAgent('abc', ('user', 'testpasswd'))
        wd.register_psk_agent(psk_agent)

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

        condition = 'not obj.scanning'
        wd.wait_for_object_condition(device, condition)

        device.scan()

        condition = 'not obj.scanning'
        wd.wait_for_object_condition(device, condition)

        ordered_networks = device.get_ordered_networks()
        ordered_network = ordered_networks[0]

        self.assertEqual(ordered_network.name, "ssidEAP-TTLS-MSCHAP")
        self.assertEqual(ordered_network.type, NetworkType.eap)

        condition = 'not obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        ordered_network.network_object.connect()

        condition = 'obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        hostapd.eapol_reauth(device.address)

        wd.wait(10)

        condition = 'obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        testutil.test_iface_operstate()
        testutil.test_ifaces_connected()

        device.disconnect()

        condition = 'not obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        wd.unregister_psk_agent(psk_agent)
Beispiel #4
0
    def test_connection_success(self):
        hostapd_if = None

        for hostapd in list(hostapd_map.values()):
            if hostapd.config == 'ssidSAE.conf':
                hostapd_if = hostapd.name

        wd = IWD(True)

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

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

        condition = 'not obj.scanning'
        wd.wait_for_object_condition(device, condition)

        device.scan()

        condition = 'not obj.scanning'
        wd.wait_for_object_condition(device, condition)

        ordered_networks = device.get_ordered_networks()

        network = [x for x in ordered_networks if x.name == "ssidSAE"][0]

        self.assertIsNotNone(network)
        self.assertEqual(network.name, "ssidSAE")
        self.assertEqual(network.type, NetworkType.psk)

        condition = 'not obj.connected'
        wd.wait_for_object_condition(network.network_object, condition)

        network.network_object.connect()

        condition = 'obj.connected'
        wd.wait_for_object_condition(network.network_object, condition)

        wd.wait(2)

        testutil.test_iface_operstate(intf=device.name)
        testutil.test_ifaces_connected(if0=device.name, if1=hostapd_if)

        device.disconnect()

        condition = 'not obj.connected'
        wd.wait_for_object_condition(network.network_object, condition)

        wd.unregister_psk_agent(psk_agent)

        del wd
Beispiel #5
0
    def test_connection_with_other_agent(self):
        wd = IWD()

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

        self.check_connection(wd, 'ssid2')

        iwctl.terminate()
        iwctl.communicate()

        IWD.clear_storage()
Beispiel #6
0
    def test_connection_use_own_agent_from_multiple_registered(self):

        wd = IWD()

        iwctl = subprocess.Popen(['iwctl', '-P', 'secret_ssid2'])
        # 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()
Beispiel #7
0
    def test_fast_retry(self):
        hwsim = Hwsim()

        bss_hostapd = [
            HostapdCLI(config='ssid1.conf'),
            HostapdCLI(config='ssid2.conf')
        ]
        bss_radio = [hwsim.get_radio('rad0'), hwsim.get_radio('rad1')]

        rule0 = hwsim.rules.create()
        rule0.source = bss_radio[0].addresses[0]
        rule0.bidirectional = True

        rule1 = hwsim.rules.create()
        rule1.source = bss_radio[1].addresses[0]
        rule1.bidirectional = True

        # Fill in the neighbor AP tables in both BSSes.  By default each
        # instance knows only about current BSS, even inside one hostapd
        # process.
        # Roaming still works without the neighbor AP table but neighbor
        # reports have to be disabled in the .conf files
        bss0_nr = ''.join(bss_radio[0].addresses[0].split(':')) + \
                '8f0000005101060603000000'
        bss1_nr = ''.join(bss_radio[1].addresses[0].split(':')) + \
                '8f0000005102060603000000'

        bss_hostapd[0].set_neighbor(bss_radio[1].addresses[0], 'TestRoamRetry',
                                    bss1_nr)
        bss_hostapd[1].set_neighbor(bss_radio[0].addresses[0], 'TestRoamRetry',
                                    bss0_nr)

        # Start in the vicinity of BSS 0, check that iwd connects to BSS 0
        rule0.signal = -2000
        rule1.signal = -8500

        wd = IWD()

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

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

        condition = 'not obj.scanning'
        wd.wait_for_object_condition(device, condition)

        device.scan()

        condition = 'not obj.scanning'
        wd.wait_for_object_condition(device, condition)

        ordered_network = device.get_ordered_network('TestRoamRetry')

        self.assertEqual(ordered_network.type, NetworkType.psk)

        condition = 'not obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        ordered_network.network_object.connect()

        condition = 'obj.state == DeviceState.connected'
        wd.wait_for_object_condition(device, condition)

        self.assertTrue(bss_hostapd[0].list_sta())
        self.assertFalse(bss_hostapd[1].list_sta())

        wd.wait(5)

        # Now push the signal LOW, wait for iwd to attempt a roam, fail, and
        # schedule another attempt for 60 seconds later
        rule0.signal = -8000

        wd.wait(20)

        self.assertEqual(device.state, iwd.DeviceState.connected)
        self.assertTrue(bss_hostapd[0].list_sta())
        self.assertFalse(bss_hostapd[1].list_sta())

        testutil.test_iface_operstate(device.name)
        testutil.test_ifaces_connected(bss_hostapd[0].ifname, device.name)

        # Assert high signal for BSS 0 again. This clears the way for a faster
        # roam attempt on LOW again
        rule0.signal = -5000

        # Wait a little for signal recognition
        wd.wait(1)

        # Assert low signal for BSS 0, check that iwd starts transition to BSS 1
        # in less than 10 seconds. Because of the neighbor report a scan should
        # not be necessary.
        rule0.signal = -8000
        rule1.signal = -2000

        condition = 'obj.state == DeviceState.roaming'
        wd.wait_for_object_condition(device, condition, max_wait=10)

        # Check that iwd is on BSS 1 once out of roaming state and doesn't
        # go through 'disconnected', 'autoconnect', 'connecting' in between
        from_condition = 'obj.state == DeviceState.roaming'
        to_condition = 'obj.state == DeviceState.connected'
        wd.wait_for_object_change(device, from_condition, to_condition)

        self.assertTrue(bss_hostapd[1].list_sta())

        device.disconnect()

        condition = 'not obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        wd.unregister_psk_agent(psk_agent)

        rule0.remove()
        rule1.remove()
Beispiel #8
0
    def test_connection_success(self):
        wd = IWD(True, iwd_storage_dir='/tmp/storage')

        ns0 = ctx.get_namespace('ns0')

        wd_ns0 = IWD(True, namespace=ns0)

        psk_agent = PSKAgent("secret123")
        psk_agent_ns0 = PSKAgent("secret123", namespace=ns0)
        wd.register_psk_agent(psk_agent)
        wd_ns0.register_psk_agent(psk_agent_ns0)

        dev1 = wd.list_devices(1)[0]
        dev2 = wd_ns0.list_devices(1)[0]

        condition = 'not obj.scanning'
        wd.wait_for_object_condition(dev1, condition)

        dev1.scan()

        condition = 'not obj.scanning'
        wd.wait_for_object_condition(dev1, condition)

        ordered_network = dev1.get_ordered_network('ssidTKIP')

        self.assertEqual(ordered_network.type, NetworkType.psk)

        condition = 'not obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        ordered_network.network_object.connect()

        condition = 'obj.state == DeviceState.connected'
        wd.wait_for_object_condition(dev1, condition)

        testutil.test_iface_operstate()
        testutil.test_ifaces_connected()

        testutil.test_ip_address_match(dev1.name, '192.168.1.10')

        dev2.scan()

        condition = 'not obj.scanning'
        wd_ns0.wait_for_object_condition(dev2, condition)

        ordered_network = dev2.get_ordered_network('ssidTKIP',
                                                   scan_if_needed=True)

        condition = 'not obj.connected'
        wd_ns0.wait_for_object_condition(ordered_network.network_object,
                                         condition)

        ordered_network.network_object.connect()

        condition = 'obj.state == DeviceState.connected'
        wd_ns0.wait_for_object_condition(dev2, condition)

        wd.wait(1)
        testutil.test_ip_address_match(dev1.name, None)

        dev1.disconnect()
        dev2.disconnect()

        condition = 'not obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        wd.unregister_psk_agent(psk_agent)
Beispiel #9
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()
Beispiel #10
0
    def test_roam_success(self):
        hwsim = Hwsim()

        rule0 = hwsim.rules.create()
        rule0.source = self.bss_radio[0].addresses[0]
        rule0.bidirectional = True

        rule1 = hwsim.rules.create()
        rule1.source = self.bss_radio[1].addresses[0]
        rule1.bidirectional = True

        rule2 = hwsim.rules.create()
        rule2.source = self.bss_radio[2].addresses[0]
        rule2.bidirectional = True

        # Check that iwd selects BSS 0 first
        rule0.signal = -2000
        rule1.signal = -6900
        rule2.signal = -7200

        wd = IWD(True)

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

        device = wd.list_devices(1)[0]

        condition = 'not obj.scanning'
        wd.wait_for_object_condition(device, condition)

        device.scan()

        condition = 'obj.scanning'
        wd.wait_for_object_condition(device, condition)

        condition = 'not obj.scanning'
        wd.wait_for_object_condition(device, condition)

        ordered_network = device.get_ordered_network('TestFT')

        self.assertEqual(ordered_network.type, NetworkType.psk)
        self.assertEqual(ordered_network.signal_strength, -2000)

        condition = 'not obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        self.assertFalse(self.bss_hostapd[0].list_sta())
        self.assertFalse(self.bss_hostapd[1].list_sta())

        ordered_network.network_object.connect()

        condition = 'obj.state == DeviceState.connected'
        wd.wait_for_object_condition(device, condition)

        self.assertTrue(self.bss_hostapd[0].list_sta())
        self.assertFalse(self.bss_hostapd[1].list_sta())

        wd.unregister_psk_agent(psk_agent)

        testutil.test_iface_operstate(device.name)
        testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name)
        self.assertRaises(Exception, testutil.test_ifaces_connected,
                          (self.bss_hostapd[1].ifname, device.name))

        # Check that iwd starts transition to BSS 1 in less than 10 seconds.
        # The 10 seconds is longer than needed to scan on just two channels
        # but short enough that a full scan on the 2.4 + 5.8 bands supported
        # by mac80211_hwsim will not finish.  If this times out then, but
        # device_roam_trigger_cb has happened, it probably means that
        # Neighbor Reports are broken.
        rule0.signal = -8000

        condition = 'obj.state == DeviceState.roaming'
        wd.wait_for_object_condition(device, condition)

        # Check that iwd is on BSS 1 once out of roaming state and doesn't
        # go through 'disconnected', 'autoconnect', 'connecting' in between
        from_condition = 'obj.state == DeviceState.roaming'
        to_condition = 'obj.state == DeviceState.connected'
        wd.wait_for_object_change(device, from_condition, to_condition)

        rule1.signal = -2000

        # wait for IWD's signal levels to recover
        wd.wait(5)

        self.assertTrue(self.bss_hostapd[1].list_sta())

        testutil.test_iface_operstate(device.name)
        testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name)
        self.assertRaises(Exception, testutil.test_ifaces_connected,
                          (self.bss_hostapd[0].ifname, device.name))

        # test FT-PSK after FT-SAE
        rule1.signal = -8000
        rule0.signal = -8000
        rule2.signal = -1000

        condition = 'obj.state == DeviceState.roaming'
        wd.wait_for_object_condition(device, condition)

        condition = 'obj.state != DeviceState.roaming'
        wd.wait_for_object_condition(device, condition)

        self.assertEqual(device.state, iwd.DeviceState.connected)
        self.assertTrue(self.bss_hostapd[2].list_sta())

        testutil.test_iface_operstate(device.name)
        testutil.test_ifaces_connected(self.bss_hostapd[2].ifname, device.name)
        self.assertRaises(Exception, testutil.test_ifaces_connected,
                          (self.bss_hostapd[1].ifname, device.name))
Beispiel #11
0
    def test_connection_success(self):
        hwsim = Hwsim()

        bss_hostapd = [
            HostapdCLI(config='ssid1.conf'),
            HostapdCLI(config='ssid2.conf'),
            HostapdCLI(config='ssid3.conf')
        ]
        bss_radio = [
            hwsim.get_radio('rad0'),
            hwsim.get_radio('rad1'),
            hwsim.get_radio('rad2')
        ]

        rule0 = hwsim.rules.create()
        rule0.source = bss_radio[0].addresses[0]
        rule0.bidirectional = True
        rule0.signal = -2000

        rule1 = hwsim.rules.create()
        rule1.source = bss_radio[1].addresses[0]
        rule1.bidirectional = True
        rule1.signal = -3000

        rule2 = hwsim.rules.create()
        rule2.source = bss_radio[2].addresses[0]
        rule2.bidirectional = True
        rule2.signal = -4000

        wd = IWD(True)

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

        devices = wd.list_devices(2)
        device = devices[0]

        devices[1].disconnect()

        ordered_network = device.get_ordered_network("TestBlacklist",
                                                     scan_if_needed=True)

        self.assertEqual(ordered_network.type, NetworkType.psk)

        condition = 'not obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        rule0.drop = True

        ordered_network.network_object.connect(wait=False)

        # Have AP1 drop all packets, should result in a connection timeout
        rule0.drop = True

        # Note the time so later we don't sleep any longer than required
        start = time.time()

        condition = 'obj.state == DeviceState.connected'
        wd.wait_for_object_condition(device, condition)

        # IWD should have attempted to connect to bss_hostapd[0], since its
        # signal strength was highest. But since we dropped all packets this
        # connect should fail, and the BSS should be blacklisted. Then we
        # should automatically try the next BSS in the list, which is
        # bss_hostapd[1]
        self.assertNotIn(device.address, bss_hostapd[0].list_sta())
        self.assertIn(device.address, bss_hostapd[1].list_sta())

        rule0.drop = False

        # Next try autoconnecting to a network with a blacklisted BSS. Since an
        # explicit disconnect call would disable autoconnect we reset
        # hostapd which will disconnect IWD.
        bss_hostapd[1].reload()

        condition = 'not obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        # Now we wait... AutoConnect should take over

        condition = 'obj.state == DeviceState.connecting'
        wd.wait_for_object_condition(device, condition)

        condition = 'obj.state == DeviceState.connected'
        wd.wait_for_object_condition(device, condition)

        # Same as before, make sure we didn't connect to the blacklisted AP.
        self.assertNotIn(device.address, bss_hostapd[0].list_sta())
        self.assertIn(device.address, bss_hostapd[1].list_sta())

        # Wait for the blacklist to expire (10 seconds)
        elapsed = time.time() - start

        if elapsed < 15:
            wd.wait(15 - elapsed)

        device.disconnect()

        condition = 'not obj.scanning'
        wd.wait_for_object_condition(device, condition)

        device.scan()

        condition = 'not obj.scanning'
        wd.wait_for_object_condition(device, condition)

        ordered_network = device.get_ordered_network("TestBlacklist")

        self.assertEqual(ordered_network.type, NetworkType.psk)

        condition = 'not obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        ordered_network.network_object.connect()

        condition = 'obj.state == DeviceState.connected'
        wd.wait_for_object_condition(device, condition)

        self.assertIn(device.address, bss_hostapd[0].list_sta())

        wd.unregister_psk_agent(psk_agent)

        rule0.remove()
        rule1.remove()
        rule2.remove()
Beispiel #12
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()
Beispiel #13
0
    def test_roam_on_beacon_loss(self):
        hwsim = Hwsim()

        rule0 = hwsim.rules.create()
        rule0.source = self.bss_radio[0].addresses[0]
        rule0.bidirectional = True

        rule1 = hwsim.rules.create()
        rule1.source = self.bss_radio[1].addresses[0]
        rule1.bidirectional = True

        wd = IWD()

        device = wd.list_devices(1)[0]

        # Check that iwd selects BSS 0 first
        rule0.signal = -2000
        rule1.signal = -2500

        condition = 'not obj.scanning'
        wd.wait_for_object_condition(device, condition)

        device.scan()

        condition = 'obj.scanning'
        wd.wait_for_object_condition(device, condition)

        condition = 'not obj.scanning'
        wd.wait_for_object_condition(device, condition)

        ordered_network = device.get_ordered_network("TestFT")
        self.assertEqual(ordered_network.type, NetworkType.eap)
        self.assertEqual(ordered_network.signal_strength, -2000)

        condition = 'not obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        self.assertFalse(self.bss_hostapd[0].list_sta())
        self.assertFalse(self.bss_hostapd[1].list_sta())

        ordered_network.network_object.connect()

        condition = 'obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        self.assertTrue(self.bss_hostapd[0].list_sta())
        self.assertFalse(self.bss_hostapd[1].list_sta())

        testutil.test_iface_operstate(device.name)
        testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name)
        self.assertRaises(Exception, testutil.test_ifaces_connected,
                          (self.bss_hostapd[1].ifname, device.name))

        # Check that iwd starts transition to BSS 1 in less than 20 seconds
        # from a beacon loss event
        rule0.drop = True
        rule0.signal = -3000
        wd.wait(2)
        rule0.drop = False

        condition = 'obj.state == DeviceState.roaming'
        wd.wait_for_object_condition(device, condition, 20)

        # Check that iwd is on BSS 1 once out of roaming state and doesn't
        # go through 'disconnected', 'autoconnect', 'connecting' in between
        condition = 'obj.state != DeviceState.roaming'
        wd.wait_for_object_condition(device, condition, 5)

        self.assertEqual(device.state, iwd.DeviceState.connected)
        self.assertTrue(self.bss_hostapd[1].list_sta())

        testutil.test_iface_operstate(device.name)
        testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name)
        self.assertRaises(Exception, testutil.test_ifaces_connected,
                          (self.bss_hostapd[0].ifname, device.name))