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)
def validate_connection(self, wd): hostapd = None for hostapd_if in list(hostapd_map.values()): hpd = HostapdCLI(hostapd_if) if hpd.get_config_value('ssid') == 'ssidEAP-PWD': hostapd = hpd break self.assertIsNotNone(hostapd) psk_agent = PSKAgent('eap-pwd-identity', ('eap-pwd-identity', '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() ordered_network = None for o_n in ordered_networks: if o_n.name == "ssidEAP-PWD": ordered_network = o_n break self.assertEqual(ordered_network.name, "ssidEAP-PWD") 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) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) wd.unregister_psk_agent(psk_agent)
def test_disconnect(self): wd = IWD() devices = wd.list_devices(1) device = devices[0] hostapd_if = list(hostapd_map.values())[0] hostapd = HostapdCLI(hostapd_if) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network('ssidOpen') ordered_network.network_object.connect() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) hostapd.deauthenticate(device.address) condition = 'obj.state == DeviceState.connecting' wd.wait_for_object_condition(device, condition) condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) device.disconnect() condition = 'obj.state == DeviceState.disconnected' wd.wait_for_object_condition(device, condition)
def setUpClass(cls): hwsim = Hwsim() cls.bss_hostapd = [ HostapdCLI(config='ft-psk-ccmp-1.conf'), HostapdCLI(config='ft-psk-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')
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()
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)
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')
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)
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)
def test_connection_success(self): hostapd = HostapdCLI(list(hostapd_map.values())[0]) 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) # 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)
def validate_connection(self, wd): hostapd = None for hostapd_if in list(hostapd_map.values()): hpd = HostapdCLI(hostapd_if) if hpd.get_config_value('ssid') == 'ssidEAP-PEAPv0-NoISK': hostapd = hpd break self.assertIsNotNone(hostapd) 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_network = device.get_ordered_network('ssidEAP-PEAPv0-NoISK') 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)
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)
def validate_connection(self, wd): hostapd = HostapdCLI(config='ssidEAP-TTLS-MSCHAPv2.conf') self.assertIsNotNone(hostapd) psk_agent = PSKAgent('abc', ('domain\\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-MSCHAPv2") 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)
def validate_connection(self, wd): hostapd = HostapdCLI(config='ssidEAP-TTLS-MSCHAPv2.conf') self.assertIsNotNone(hostapd) psk_agent = PSKAgent('abc', ('user', 'incorrect_password')) 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-MSCHAPv2") self.assertEqual(ordered_network.type, NetworkType.eap) 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)
def test_connection_success(self): hapd = HostapdCLI(config='ssidGroup20.conf') 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('ssidGroup20') self.assertEqual(ordered_network.type, NetworkType.open) 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) 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)
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)
def setUpClass(cls): hwsim = Hwsim() cls.bss_hostapd = [None, None, None] cls.bss_radio = [None, None, None] for wname in wiphy_map: wiphy = wiphy_map[wname] intf = list(wiphy.values())[0] if intf.config and '1' in intf.config: bss_idx = 0 elif intf.config and '2' in intf.config: bss_idx = 1 elif intf.config and '3' in intf.config: bss_idx = 2 else: continue for path in hwsim.radios: radio = hwsim.radios[path] if radio.name == wname: break cls.bss_hostapd[bss_idx] = HostapdCLI(intf) cls.bss_radio[bss_idx] = radio # 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') os.system('ifconfig "' + cls.bss_hostapd[2].ifname + '" down hw ether 12:00:00:00:00:03 up') cls.bss_hostapd[0].reload() cls.bss_hostapd[1].reload() cls.bss_hostapd[2].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[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')
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)
def setUpClass(cls): hapd = HostapdCLI() # TODO: This could be moved into test-runner itself if other tests ever # require this functionality (p2p, FILS, etc.). Since its simple # enough it can stay here for now. ctx.start_process([ 'ifconfig', hapd.ifname, '192.168.1.1', 'netmask', '255.255.255.0' ], wait=True) ctx.start_process(['touch', '/tmp/dhcpd.leases'], wait=True) cls.dhcpd_pid = ctx.start_process([ 'dhcpd', '-f', '-cf', '/tmp/dhcpd.conf', '-lf', '/tmp/dhcpd.leases', hapd.ifname ])
def validate_connection(self, wd): hostapd = HostapdCLI(config='ssidSAE.conf') psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) devices = wd.list_devices(4) self.assertIsNotNone(devices) device = devices[0] # 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() 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) network.network_object.connect() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) wd.wait(2) testutil.test_iface_operstate(intf=device.name) testutil.test_ifaces_connected(if0=device.name, if1=hostapd.ifname) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(network.network_object, condition) wd.unregister_psk_agent(psk_agent)
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)
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)
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 validate_connection(self, wd): hostapd = HostapdCLI(config='ssidEAP-PWD.conf') self.assertIsNotNone(hostapd) psk_agent = PSKAgent('eap-pwd-identity', ('eap-pwd-identity', '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_network = device.get_ordered_network('ssidEAP-PWD') 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) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) wd.unregister_psk_agent(psk_agent)
def validate_connection(self, wd): hostapd = HostapdCLI(config='ssidEAP-PEAPv0-NoISK.conf') self.assertIsNotNone(hostapd) 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_network = device.get_ordered_network('ssidEAP-PEAPv0-NoISK') 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)
def client_connect(self, wd, dev): hostapd = HostapdCLI(config='psk-ccmp.conf') ordered_network = dev.get_ordered_network('TestAP1', True) self.assertEqual(ordered_network.type, NetworkType.psk) psk_agent = PSKAgent('Password1') wd.register_psk_agent(psk_agent) ordered_network.network_object.connect() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(dev, condition) wd.unregister_psk_agent(psk_agent) testutil.test_iface_operstate(dev.name) testutil.test_ifaces_connected(hostapd.ifname, dev.name) dev.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition)
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()
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()
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)
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)