Пример #1
0
    def test_connection_success(self):
        hostapd = None

        for wname in wiphy_map:
            wiphy = wiphy_map[wname]
            intf = list(wiphy.values())[0]
            if intf.use == 'hostapd':
                hostapd = HostapdCLI(intf)
                break

        hwsim = Hwsim()
        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_networks = device.get_ordered_networks()
        ordered_network = ordered_networks[0]

        self.assertEqual(ordered_network.name, "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)

        # Make AP go down ungracefully, when hostapd comes back up it should
        # send an unprotected disassociate frame so the client will re-auth.
        # This will kick off the SA Query procedure
        hostapd.ungraceful_restart()

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

        # IWD should now try and re-connect to the AP

        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)
Пример #2
0
    def test_connection_success(self):
        wd = IWD()

        psk_agent = PSKAgent("InvalidPassword")
        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()
        ordered_network = ordered_networks[0]

        self.assertEqual(ordered_network.name, "ssidCCMP")
        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)
Пример #3
0
    def test_connection_success(self):
        wd = IWD(True)

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

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

        wd.unregister_psk_agent(psk_agent)

        del wd
Пример #4
0
    def test_connection_failure(self):
        wd = IWD()

        dev1, dev2 = wd.list_devices(2)

        self.client_connect(wd, dev1)

        dev1.start_ap('TestAP2', 'Password2')

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

            ordered_networks = dev2.get_ordered_networks()
            networks = {n.name: n for n in ordered_networks}
            self.assertEqual(networks['TestAP1'].type, NetworkType.psk)
            self.assertEqual(networks['TestAP2'].type, NetworkType.psk)

            psk_agent = PSKAgent('InvalidPassword')
            wd.register_psk_agent(psk_agent)

            with self.assertRaises(iwd.FailedEx):
                networks['TestAP2'].network_object.connect()

            wd.unregister_psk_agent(psk_agent)
        finally:
            dev1.stop_ap()

        # Finally test dev1 can go to client mode and connect again
        self.client_connect(wd, dev1)
Пример #5
0
    def test_connection_success(self):
        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)

        device.disconnect()

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

        wd.unregister_psk_agent(psk_agent)
Пример #6
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
Пример #7
0
    def test_connection_success(self):
        hapd = HostapdCLI(config='ssidFILS-256.conf')

        wd = IWD(True)

        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('ssidFILS-256')

        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)

        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)

        ordered_network = device.get_ordered_network('ssidFILS-256')

        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)

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

        device.disconnect()

        wd.unregister_psk_agent(psk_agent)
Пример #8
0
    def test_connection_success(self):
        wd = IWD()

        dev1, dev2 = wd.list_devices(2)
        dev1.disconnect()
        dev2.disconnect()

        self.client_connect(wd, dev1)

        dev1.start_ap('TestAP2', 'Password2')

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

            ordered_networks = dev2.get_ordered_networks()
            self.assertEqual(len(ordered_networks), 2)
            networks = {n.name: n for n in ordered_networks}
            self.assertEqual(networks['TestAP1'].type, NetworkType.psk)
            self.assertEqual(networks['TestAP2'].type, NetworkType.psk)

            psk_agent = PSKAgent('Password2')
            wd.register_psk_agent(psk_agent)

            try:
                dev2.disconnect()
                condition = 'not obj.connected'
                wd.wait_for_object_condition(dev2, condition)
            except:
                pass

            networks['TestAP2'].network_object.connect()

            condition = 'obj.connected'
            wd.wait_for_object_condition(networks['TestAP2'].network_object,
                                         condition)

            testutil.test_iface_operstate(dev2.name)
            testutil.test_ifaces_connected(dev1.name, dev2.name)

            wd.unregister_psk_agent(psk_agent)

            dev2.disconnect()

            condition = 'not obj.connected'
            wd.wait_for_object_condition(networks['TestAP2'].network_object,
                                         condition)
        finally:
            dev1.stop_ap()

        # Finally test dev1 can go to client mode and connect again
        self.client_connect(wd, dev1)
Пример #9
0
    def test_connection_success(self):
        networks = []

        wd = IWD(True)

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

        devices = wd.list_devices(4)
        self.assertIsNotNone(devices)

        for d in devices:
            condition = 'not obj.scanning'
            wd.wait_for_object_condition(d, condition)

            d.scan()

        for d in devices:
            condition = 'not obj.scanning'
            wd.wait_for_object_condition(d, condition)

        for i in range(len(devices)):
            ordered_networks = devices[i].get_ordered_networks()

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

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

            networks.append(network)

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

        for n in networks:
            n.network_object.connect(wait=False)

        for n in networks:
            condition = 'obj.connected'
            wd.wait_for_object_condition(n.network_object, condition)

        for d in devices:
            d.wait_for_connected()

        for d in devices:
            d.disconnect()

        for n in networks:
            condition = 'not obj.connected'
            wd.wait_for_object_condition(n.network_object, condition)

        wd.unregister_psk_agent(psk_agent)

        del wd
Пример #10
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)
Пример #11
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)
Пример #12
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)
Пример #13
0
    def test_connection_success(self):
        wd = IWD(True)

        psk_agent = PSKAgent('*****@*****.**',
                                ('*****@*****.**', 'testpasswd'))
        wd.register_psk_agent(psk_agent)

        try:
            self.validate_connection(wd)
        finally:
            wd.unregister_psk_agent(psk_agent)
Пример #14
0
    def test_connection_with_own_agent(self):

        wd = IWD()

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

        self.check_connection(wd, 'ssid1')

        wd.unregister_psk_agent(psk_agent)

        IWD.clear_storage()
Пример #15
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
Пример #16
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)
Пример #17
0
    def test_connection_success(self):
        hostapd = HostapdCLI(config='ssidCCMP.conf')

        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.state == DeviceState.connected'
        wd.wait_for_object_condition(device, condition)

        # Make AP go down ungracefully, when hostapd comes back up it should
        # send an unprotected disassociate frame so the client will re-auth.
        # This will kick off the SA Query procedure
        hostapd.ungraceful_restart()

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

        # IWD should now try and re-connect to the AP

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

        hostapd.wait_for_event('AP-STA-CONNECTED')

        device.disconnect()

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

        wd.unregister_psk_agent(psk_agent)
Пример #18
0
    def test_connection_success(self):
        hostapd = HostapdCLI(config='ssidEAP-TTLS-PAP.conf')

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

        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.state == DeviceState.connected'
        wd.wait_for_object_condition(device, condition)

        hostapd.eapol_reauth(device.address)

        hostapd.wait_for_event('CTRL-EVENT-EAP-STARTED')
        hostapd.wait_for_event('CTRL-EVENT-EAP-SUCCESS')

        condition = 'obj.state == DeviceState.connected'
        wd.wait_for_object_condition(device, 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)
Пример #19
0
    def do_test_connection_success(self, ssid, passphrase=None):
        wd = IWD()

        if passphrase:
            psk_agent = PSKAgent(passphrase)
            wd.register_psk_agent(psk_agent)

        hostapd_ifname = None
        for ifname in hostapd.hostapd_map:
            if ssid + '.conf' in hostapd.hostapd_map[ifname].config:
                hostapd_ifname = ifname
                break

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

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

        if not device.get_ordered_networks():
            device.scan()
            condition = 'obj.scanning'
            wd.wait_for_object_condition(device, condition)
            condition = 'not obj.scanning'
            wd.wait_for_object_condition(device, condition)

        ordered_networks = device.get_ordered_networks()
        ordered_network = [n for n in ordered_networks if n.name == ssid][0]

        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)

        testutil.test_iface_operstate()
        testutil.test_ifaces_connected(hostapd_ifname, 'wln3')

        device.disconnect()

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

        if passphrase:
            wd.unregister_psk_agent(psk_agent)
Пример #20
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)
Пример #21
0
    def run_connection_test(self, ssid, *secrets):
        wd = IWD()

        psk_agent = iwd.PSKAgent(*secrets)
        wd.register_psk_agent(psk_agent)

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

        try:
            device.disconnect()
        except:
            pass

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

        if not device.get_ordered_networks():
            device.scan()
            condition = 'obj.scanning'
            wd.wait_for_object_condition(device, condition)
            condition = 'not obj.scanning'
            wd.wait_for_object_condition(device, condition)

        network = None
        for ordered_network in device.get_ordered_networks():
            if ordered_network.name == ssid:
                network = ordered_network
                break
        self.assertEqual(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)

        wd.unregister_psk_agent(psk_agent)

        device.disconnect()

        condition = 'not obj.connected'
        wd.wait_for_object_condition(ordered_network.network_object, condition)
Пример #22
0
    def test_connection_success(self):
        wd = IWD()

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

        wpa_net = device.get_ordered_network('ssidTKIP')
        self.assertEqual(wpa_net.type, NetworkType.psk)

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

        wpa_net.network_object.connect()

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

        open_net = device.get_ordered_network('ssidOpen')
        self.assertEqual(open_net.type, NetworkType.open)

        open_net.network_object.connect()

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

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

        device.disconnect()

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

        wd.unregister_psk_agent(psk_agent)
Пример #23
0
    def do_test_connection_success(self, ssid, passphrase=None):
        hapd = HostapdCLI(config=ssid + '.conf')
        wd = IWD()

        if passphrase:
            psk_agent = PSKAgent(passphrase)
            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)

        if not device.get_ordered_networks():
            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(ssid)

        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)

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

        device.disconnect()

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

        if passphrase:
            wd.unregister_psk_agent(psk_agent)
Пример #24
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()
Пример #25
0
    def test_connection_success(self):
        wd = IWD()

        psk_agent = PSKAgent('abc', ('user', 'testpasswd'))
        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)

        if not device.get_ordered_networks():
            device.scan()
            condition = 'obj.scanning'
            wd.wait_for_object_condition(device, condition)
            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")
        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)

        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)
Пример #26
0
    def test_connection_success(self):
        wd = IWD()

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

        devices = wd.list_devices()
        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()
        ordered_network = ordered_networks[0]

        self.assertEqual(ordered_network.name, "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)

        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)
Пример #27
0
    def test_connection_success(self):
        wd = IWD(True, '/tmp')

        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]

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

        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)

        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)
    def test_connection(self):
        wd = IWD(True)

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

        device = wd.list_devices(1)[0]
        ordered_network = device.get_ordered_network('ssidOpen',
                                                     scan_if_needed=True)

        device.connect_hidden_network_async(name='ssidSomeHidden',
                                            reply_handler=self._success,
                                            error_handler=self._failure)

        ordered_network.network_object.connect()

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

        condition = 'obj.connected_network is not None'
        wd.wait_for_object_condition(device, condition)

        testutil.test_iface_operstate(device.name)
        device.disconnect()

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

        wd.unregister_psk_agent(psk_agent)

        IWD.clear_storage()

        while not self._done:
            time.sleep(.300)

        if self._ex is not None:
            if self._ex.get_dbus_name() != 'net.connman.iwd.Failed':
                raise self._ex
Пример #29
0
    def test_connection_success(self):
        wd = IWD()

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

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

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

        if not device.get_ordered_networks():
            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("ssidCCMP")
        self.assertEqual(ordered_network.type, NetworkType.psk)
        network = ordered_network.network_object

        # 0 chars
        psk_agent = PSKAgent("")
        wd.register_psk_agent(psk_agent)
        self.assertRaises(iwd.InvalidFormatEx, network.connect)
        wd.unregister_psk_agent(psk_agent)

        # 7 chars
        psk_agent = PSKAgent("a" * 7)
        wd.register_psk_agent(psk_agent)
        self.assertRaises(iwd.InvalidFormatEx, network.connect)
        wd.unregister_psk_agent(psk_agent)

        # 64 chars
        psk_agent = PSKAgent("a" * 64)
        wd.register_psk_agent(psk_agent)
        self.assertRaises(iwd.InvalidFormatEx, network.connect)
        wd.unregister_psk_agent(psk_agent)

        # 64k chars
        psk_agent = PSKAgent("a" * 65536)
        wd.register_psk_agent(psk_agent)
        self.assertRaises(iwd.InvalidFormatEx, network.connect)
        wd.unregister_psk_agent(psk_agent)
Пример #30
0
    def run_connection_test(self, ssid, *secrets):
        wd = IWD()

        psk_agent = iwd.PSKAgent(*secrets)
        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)

        if not device.get_ordered_networks():
            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(ssid)

        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.state == DeviceState.connected'
        wd.wait_for_object_condition(device, condition)

        wd.unregister_psk_agent(psk_agent)

        device.disconnect()

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