Exemplo n.º 1
0
    def setUpClass(cls):
        os.system('ifconfig lo up')
        IWD.copy_to_storage('TestFT.8021x')

        hwsim = Hwsim()

        cls.bss_hostapd = [
            HostapdCLI(config='ft-eap-ccmp-1.conf'),
            HostapdCLI(config='ft-eap-ccmp-2.conf')
        ]
        cls.bss_radio = [hwsim.get_radio('rad0'), hwsim.get_radio('rad1')]

        # Set interface addresses to those expected by hostapd config files
        os.system('ifconfig "' + cls.bss_hostapd[0].ifname +
                  '" down hw ether 12:00:00:00:00:01 up')
        os.system('ifconfig "' + cls.bss_hostapd[1].ifname +
                  '" down hw ether 12:00:00:00:00:02 up')

        cls.bss_hostapd[0].reload()
        cls.bss_hostapd[1].reload()

        # 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[1].set_neighbor(
            '12:00:00:00:00:01', 'TestFT',
            '1200000000018f0000005101060603000000')
Exemplo n.º 2
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')
Exemplo n.º 3
0
    def test_connection_success(self):
        hwsim = Hwsim()
        non_ht_hostapd = HostapdCLI(config='non-ht-vht.conf')
        ht_hostapd = HostapdCLI(config='ht.conf')
        vht_hostapd = HostapdCLI(config='vht.conf')
        non_ht_radio = hwsim.get_radio('rad0')
        ht_radio = hwsim.get_radio('rad1')
        vht_radio = hwsim.get_radio('rad2')

        self.assertIsNotNone(non_ht_hostapd)
        self.assertIsNotNone(ht_hostapd)
        self.assertIsNotNone(vht_hostapd)

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

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

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

        wd = IWD()

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

        device = wd.list_devices(1)[0]

        self.do_connect(wd, device, vht_hostapd)

        # lower VHT BSS signal, HT should now be preferred
        rule0.signal = -6000

        self.do_connect(wd, device, ht_hostapd)

        # lower HT BSS signal, basic rate BSS should now be preferred
        rule1.signal = -6000

        self.do_connect(wd, device, non_ht_hostapd)

        wd.unregister_psk_agent(psk_agent)
Exemplo n.º 4
0
    def test_connection_success(self):
        hwsim = Hwsim()

        bss_radio = hwsim.get_radio('rad0')

        self.assertIsNotNone(bss_radio)

        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_network = device.get_ordered_network('ssidOWE')

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

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

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

        with self.assertRaises(iwd.FailedEx):
            ordered_network.network_object.connect()
Exemplo n.º 5
0
    def test_connection_success(self):
        hwsim = Hwsim()

        hostapd = HostapdCLI(config='ssidCCMP.conf')
        radio = hwsim.get_radio('rad0')

        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('ssidCCMP')

        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.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

        # TODO: for some reason hostapd does not respond to SA query if done
        #       too soon after connection.
        sleep(1)

        # Spoof a disassociate frame. This will kick off SA Query procedure.
        hwsim.spoof_disassociate(radio, hostapd.get_freq(), device.address)

        # sleep to ensure hostapd responds and SA Query does not timeout
        sleep(4)

        # Since disassociate was spoofed we should still be connected
        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)

        wd.unregister_psk_agent(psk_agent)
Exemplo n.º 6
0
    def test_connection_success(self):
        hwsim = Hwsim()

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

        wd = IWD(True)

        hapd = HostapdCLI(config='ssidHotspot.conf')

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

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

        # We are dependent on a periodic scan here. We want to wait for this
        # because this is the first opportunity IWD has to do ANQP. Once ANQP
        # has been done once the network is set up and we cannot simulate the
        # 'Connect() before ANQP' race condition anymore.
        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('Hotspot')

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

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

        # Force the case where ANQP does not finish before Connect() comes in
        rule0.delay = 100

        ordered_network.network_object.connect()

        rule0.delay = 1

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

        testutil.test_iface_operstate()
        testutil.test_ifaces_connected(device.name, hapd.ifname)

        device.disconnect()

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

        wd.unregister_psk_agent(psk_agent)
Exemplo n.º 7
0
    def validate_connection(self, wd):
        hwsim = Hwsim()
        bss_radio = hwsim.get_radio('rad0')

        psk_agent = PSKAgent(["secret123", "secret123"])
        wd.register_psk_agent(psk_agent)

        devices = wd.list_devices(4)

        # These devices aren't used in this test, this makes logs a bit nicer
        # since these devices would presumably start autoconnecting.
        devices[1].disconnect()
        devices[2].disconnect()
        devices[3].disconnect()

        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)

        network = device.get_ordered_network('ssidSAE')

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

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

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

        wd.wait(1)
        print(rule0)

        with self.assertRaises(iwd.FailedEx):
            network.network_object.connect()

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

        rule0.prefix = '00'
        with self.assertRaises(iwd.FailedEx):
            network.network_object.connect()

        wd.unregister_psk_agent(psk_agent)
Exemplo n.º 8
0
    def test_connection_success(self):
        hwsim = Hwsim()

        hostapd = HostapdCLI(config='ssidCCMP.conf')
        radio = hwsim.get_radio('rad0')

        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)

        ordered_network = device.get_ordered_network('ssidCCMP', 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)

        ordered_network.network_object.connect()

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

        # Ensure IWD is not scanning. This causes problems with mac80211_hwsim
        # where CMD_FRAME will fail during a scan. This is due to the frame not
        # having the same frequency as the radio (since hwsim is off-channel)
        if device.scanning:
            condition = 'not obj.scanning'
            wd.wait_for_object_condition(device, condition)

        # Spoof a disassociate frame. This will kick off SA Query procedure.
        hwsim.spoof_disassociate(radio, hostapd.get_freq(), device.address)

        # sleep to ensure hostapd responds and SA Query does not timeout
        sleep(4)

        # Since disassociate was spoofed we should still be connected
        condition = 'obj.state == DeviceState.connected'
        wd.wait_for_object_condition(device, condition)

        device.disconnect()

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

        wd.unregister_psk_agent(psk_agent)
Exemplo n.º 9
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')
        ]

        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('TestAPRoam')

        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.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)

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

        bss_hostapd[0].send_bss_transition(
            device.address,
            [(bss_radio[1].addresses[0], '8f0000005102060603000000'),
             (bss_radio[2].addresses[0], '8f0000005103060603000000')])

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

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

        self.assertEqual(device.state, iwd.DeviceState.connected)
        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)
Exemplo n.º 10
0
    def test_stop_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 = -5000

        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())

        # Now push the signal below the RSSI threshold and check that iwd
        # connects to BSS 1
        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)

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

        # Now make sure that we don't roam anymore. In order to catch this via
        # DeviceState, a suitable roaming target needs to be available. So jack
        # up the RSSI of BSS 0 again. The retry interval is 60 seconds, so we
        # should have roamed within that timeframe. Wait just a little longer
        # to account for the slowness of the autotest environment.
        rule0.signal = -2000

        condition = 'obj.state == DeviceState.roaming'
        self.assertRaises(TimeoutError,
                          wd.wait_for_object_condition,
                          device,
                          condition,
                          max_wait=70)

        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()
Exemplo n.º 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

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

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

        rule0.signal = -2000
        rule1.signal = -2500
        rule2.signal = -3000

        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('TestAPRoam')

        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)

        bss_hostapd[0].wait_for_event('AP-STA-CONNECTED')

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

        bss_hostapd[0].send_bss_transition(
            device.address,
            [(bss_radio[1].addresses[0], '8f0000005102060603000000'),
             (bss_radio[2].addresses[0], '8f0000005103060603000000')])

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

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

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

        self.assertEqual(device.state, iwd.DeviceState.connected)
        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()
        rule2.remove()
Exemplo n.º 12
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 = -8000

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

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

        wd = IWD(True, '/tmp')

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

        dev1, dev2 = wd.list_devices(2)

        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("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()

        self.assertIn(dev1.address, bss_hostapd[2].list_sta())

        # dev1 now connected, this should max out the first AP, causing the next
        # connection to fail to this AP.

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

        dev2.scan()

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

        ordered_network = dev2.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()

        # We should have temporarily blacklisted the first BSS, and connected
        # to this one.
        self.assertIn(dev2.address, bss_hostapd[1].list_sta())

        # Now check that the first BSS is still not blacklisted. We can
        # disconnect dev1, opening up the AP for more connections
        dev1.disconnect()
        dev2.disconnect()

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

        dev2.scan()

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

        ordered_network = dev2.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()

        self.assertIn(dev2.address, bss_hostapd[2].list_sta())

        wd.unregister_psk_agent(psk_agent)
Exemplo n.º 13
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 = -8000

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

        wd = IWD(True, '/tmp')

        psk_agent = PSKAgent("wrong_password")
        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("TestBlacklist")

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

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

        with self.assertRaises(iwd.FailedEx):
            ordered_network.network_object.connect()

        wd.unregister_psk_agent(psk_agent)

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

        ordered_network.network_object.connect()

        # We failed to connect bss_hostapd[0], but with a bad password. Verify
        # that this did not trigger a blacklist and that we did reconnect
        # successfully to bss_hostapd[0]
        self.assertIn(device.address, bss_hostapd[0].list_sta())

        condition = 'obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)
Exemplo n.º 14
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()
Exemplo n.º 15
0
Arquivo: test.py Projeto: siho22/eiwd
    def test_preauth_success(self):
        hwsim = Hwsim()

        bss_hostapd = [ HostapdCLI(config='eaptls-preauth-1.conf'),
                        HostapdCLI(config='eaptls-preauth-2.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], 'TestPreauth',
                bss1_nr)
        bss_hostapd[1].set_neighbor(bss_radio[0].addresses[0], 'TestPreauth',
                bss0_nr)

        wd = IWD()

        device = wd.list_devices(1)[0]

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

        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('TestPreauth')

        self.assertEqual(ordered_network.type, NetworkType.eap)
        self.assertEqual(ordered_network.signal_strength, -2500)

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

        self.assertFalse(bss_hostapd[0].list_sta())
        self.assertFalse(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(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)
        self.assertRaises(Exception, testutil.test_ifaces_connected,
                          bss_hostapd[1].ifname, device.name)

        # Check that iwd starts transition to BSS 1 in less than 15 seconds
        rule0.signal = -8000

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

        # TODO: verify that the PMK from preauthentication was used

        # 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(bss_hostapd[1].list_sta())

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

        device.disconnect()

        condition = 'not obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)
Exemplo n.º 16
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()
Exemplo n.º 17
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 = -8000

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

        wd = IWD(True)

        psk_agent = PSKAgent(["secret123", '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("TestBlacklist")

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

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

        # Have both APs drop all packets, both should get blacklisted
        rule0.drop = True
        rule1.drop = True
        rule2.drop = True

        with self.assertRaises(iwd.FailedEx):
            ordered_network.network_object.connect()

        rule0.drop = False
        rule1.drop = False

        # This connect should work
        ordered_network.network_object.connect()

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

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

        wd.unregister_psk_agent(psk_agent)