def test_roam_success(self): hwsim = Hwsim() rule0 = hwsim.rules.create() rule0.source = self.bss_radio[0].addresses[0] rule0.bidirectional = True rule1 = hwsim.rules.create() rule1.source = self.bss_radio[1].addresses[0] rule1.bidirectional = True wd = IWD() device = wd.list_devices(1)[0] # Check that iwd selects BSS 0 first rule0.signal = -2000 rule1.signal = -2500 condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'obj.scanning' wd.wait_for_object_condition(device, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network('TestFT') self.assertEqual(ordered_network.type, NetworkType.eap) self.assertEqual(ordered_network.signal_strength, -2000) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) self.assertFalse(self.bss_hostapd[0].list_sta()) self.assertFalse(self.bss_hostapd[1].list_sta()) ordered_network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) self.assertTrue(self.bss_hostapd[0].list_sta()) self.assertFalse(self.bss_hostapd[1].list_sta()) testutil.test_iface_operstate(device.name) testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) self.assertRaises(Exception, testutil.test_ifaces_connected, (self.bss_hostapd[1].ifname, device.name)) # Check that iwd starts transition to BSS 1 in less than 10 seconds. # The 10 seconds is longer than needed to scan on just two channels # but short enough that a full scan on the 2.4 + 5.8 bands supported # by mac80211_hwsim will not finish. If this times out then, but # device_roam_trigger_cb has happened, it probably means that # Neighbor Reports are broken. rule0.signal = -8000 condition = 'obj.state == DeviceState.roaming' wd.wait_for_object_condition(device, condition, 10) # Check that iwd is on BSS 1 once out of roaming state and doesn't # go through 'disconnected', 'autoconnect', 'connecting' in between condition = 'obj.state != DeviceState.roaming' wd.wait_for_object_condition(device, condition, 5) self.assertEqual(device.state, iwd.DeviceState.connected) self.assertTrue(self.bss_hostapd[1].list_sta()) testutil.test_iface_operstate(device.name) testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) self.assertRaises(Exception, testutil.test_ifaces_connected, (self.bss_hostapd[0].ifname, device.name))
def test_roam_on_beacon_loss(self): hwsim = Hwsim() rule0 = hwsim.rules.create() rule0.source = self.bss_radio[0].addresses[0] rule0.bidirectional = True rule1 = hwsim.rules.create() rule1.source = self.bss_radio[1].addresses[0] rule1.bidirectional = True wd = IWD() device = wd.list_devices(1)[0] # Check that iwd selects BSS 0 first rule0.signal = -2000 rule1.signal = -2500 condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'obj.scanning' wd.wait_for_object_condition(device, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network("TestFT") self.assertEqual(ordered_network.type, NetworkType.eap) self.assertEqual(ordered_network.signal_strength, -2000) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) self.assertFalse(self.bss_hostapd[0].list_sta()) self.assertFalse(self.bss_hostapd[1].list_sta()) ordered_network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) self.assertTrue(self.bss_hostapd[0].list_sta()) self.assertFalse(self.bss_hostapd[1].list_sta()) testutil.test_iface_operstate(device.name) testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) self.assertRaises(Exception, testutil.test_ifaces_connected, (self.bss_hostapd[1].ifname, device.name)) # Check that iwd starts transition to BSS 1 in less than 20 seconds # from a beacon loss event rule0.drop = True rule0.signal = -3000 wd.wait(2) rule0.drop = False condition = 'obj.state == DeviceState.roaming' wd.wait_for_object_condition(device, condition, 20) # Check that iwd is on BSS 1 once out of roaming state and doesn't # go through 'disconnected', 'autoconnect', 'connecting' in between condition = 'obj.state != DeviceState.roaming' wd.wait_for_object_condition(device, condition, 5) self.assertEqual(device.state, iwd.DeviceState.connected) self.assertTrue(self.bss_hostapd[1].list_sta()) testutil.test_iface_operstate(device.name) testutil.test_ifaces_connected(self.bss_hostapd[1].ifname, device.name) self.assertRaises(Exception, testutil.test_ifaces_connected, (self.bss_hostapd[0].ifname, device.name))
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 do_test_connection_success(self, ssid, passphrase=None): hostapd = 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.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) testutil.test_iface_operstate() testutil.test_ifaces_connected(hostapd.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 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)
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)
def test_connection_success(self): wd = IWD(True, '/tmp') hapd_hotspot = HostapdCLI(config='ssidHotspot.conf') hapd_wpa = HostapdCLI(config='ssidWPA2-1.conf') self.assertEqual(len(wd.list_known_networks()), 2) devices = wd.list_devices(1) device = devices[0] condition = 'obj.scanning' wd.wait_for_object_condition(device, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) wpa_network = device.get_ordered_network("ssidWPA2-1") self.assertEqual(wpa_network.type, NetworkType.psk) # # First make sure we can connect to a provisioned, non-Hotspot network, # while there are hotspot networks in range. This should result in # autoconnect *after* ANQP is performed # condition = 'obj.connected' wd.wait_for_object_condition(wpa_network.network_object, condition) sleep(2) testutil.test_iface_operstate() testutil.test_ifaces_connected(device.name, hapd_wpa.ifname) # # Remove provisioning file, this should cause a disconnect. # os.remove("/var/lib/iwd/ssidWPA2-1.psk") self.assertEqual(len(wd.list_known_networks()), 1) condition = 'not obj.connected' wd.wait_for_object_condition(wpa_network.network_object, condition) condition = 'obj.scanning' wd.wait_for_object_condition(device, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) hotspot_network = device.get_ordered_network("Hotspot") self.assertEqual(hotspot_network.type, NetworkType.eap) # # Since there are no other provisioned networks, we should do ANQP and # autoconnect to the hotspot network. # condition = 'obj.connected' wd.wait_for_object_condition(hotspot_network.network_object, condition) sleep(2) testutil.test_iface_operstate() testutil.test_ifaces_connected(device.name, hapd_hotspot.ifname) os.remove('/var/lib/iwd/hotspot/autoconnect.conf') IWD.copy_to_storage('ssidWPA2-1.psk') self.assertEqual(len(wd.list_known_networks()), 1) # # make sure removal of hotspot conf file resulted in disconnect # condition = 'not obj.connected' wd.wait_for_object_condition(wpa_network.network_object, condition) condition = 'obj.scanning' wd.wait_for_object_condition(device, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) hotspot_network = device.get_ordered_network("ssidWPA2-1") self.assertEqual(hotspot_network.type, NetworkType.psk) condition = 'obj.connected' wd.wait_for_object_condition(hotspot_network.network_object, condition) sleep(2) testutil.test_iface_operstate() testutil.test_ifaces_connected(device.name, hapd_wpa.ifname)
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)
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.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) open_net = device.get_ordered_network('ssidOpen') self.assertEqual(open_net.type, NetworkType.open) open_net.network_object.connect() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, 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)
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)
def test_connection_success(self): wd = IWD(True, '/tmp') 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) # # Connect to the PSK network, then Hotspot so IWD creates 2 entries in # the known frequency file. # self.connect_network(wd, device, 'ssidCCMP') wd.unregister_psk_agent(psk_agent) psk_agent = PSKAgent('abc', ('domain\\user', 'testpasswd')) wd.register_psk_agent(psk_agent) self.connect_network(wd, device, 'Hotspot') wd.unregister_psk_agent(psk_agent) psk_freqs = None psk_uuid = None hs20_freqs = None hs20_uuid = None config = ConfigParser() config.read('/tmp/iwd/.known_network.freq') for s in config.sections(): if os.path.basename(config[s]['name']) == 'ssidCCMP.psk': psk_freqs = config[s]['list'] psk_freqs = psk_freqs.split(' ') psk_uuid = s elif os.path.basename(config[s]['name']) == 'example.conf': hs20_freqs = config[s]['list'] hs20_freqs = hs20_freqs.split(' ') hs20_uuid = s # # Verify the frequencies are what we expect # self.assertIsNotNone(psk_freqs) self.assertIsNotNone(psk_uuid) self.assertIn('5180', psk_freqs) self.assertIn('2412', psk_freqs) self.assertIsNotNone(hs20_freqs) self.assertIsNotNone(hs20_uuid) self.assertIn('2412', hs20_freqs) # # Forget all know networks, this should remove all entries in the # known frequencies file. # for n in wd.list_known_networks(): n.forget() psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) # # Reconnect, this should generate a completely new UUID since we # previously forgot the network. # self.connect_network(wd, device, 'ssidCCMP') wd.unregister_psk_agent(psk_agent) # # Ensure that a new UUID was created and that we still have the same # frequencies listed. # psk_freqs = None psk_uuid2 = None hs20_freqs = None config = ConfigParser() config.read('/tmp/iwd/.known_network.freq') for s in config.sections(): self.assertNotEqual(os.path.basename(config[s]['name']), 'example.conf') if os.path.basename(config[s]['name']) == 'ssidCCMP.psk': psk_freqs = config[s]['list'] psk_freqs = psk_freqs.split(' ') psk_uuid2 = s self.assertIsNotNone(psk_freqs) self.assertIsNotNone(psk_uuid2) self.assertNotEqual(psk_uuid, psk_uuid2) self.assertIn('5180', psk_freqs) self.assertIn('2412', psk_freqs)
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-SIM': hostapd = hpd break 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-SIM") 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): wd = IWD(True, '/tmp/dhcp') # dev1, dev3, and dev4 are all AP's # The configured IP range only supports 2 subnets, so dev4 should fail # to start AP. dev1, dev2, dev3, dev4 = wd.list_devices(4) dev1.start_ap('TestAP2', "Password2") dev3.start_ap('TestAP3', 'Password3') with self.assertRaises(iwd.AlreadyExistsEx): dev4.start_ap('TestAP4', 'Password4') 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['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.state == DeviceState.connected' wd.wait_for_object_condition(dev2, condition) testutil.test_iface_operstate(dev2.name) testutil.test_ifaces_connected(dev1.name, dev2.name, group=False) testutil.test_ip_address_match(dev1.name, "192.168.80.1") testutil.test_ip_address_match(dev2.name, "192.168.80.2") wd.unregister_psk_agent(psk_agent) dev2.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(networks['TestAP2'].network_object, condition) # This should release the IP */ dev1.stop_ap() # This should now succeed and the IP should match the old IP dev1 # got initially. dev4.start_ap('TestAP4', 'Password4') testutil.test_ip_address_match(dev4.name, "192.168.80.1") finally: dev1.stop_ap()
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 test_preauth_success(self): hwsim = Hwsim() bss_hostapd = [None, None] bss_radio = [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 else: continue for path in hwsim.radios: radio = hwsim.radios[path] if radio.name == wname: break bss_hostapd[bss_idx] = HostapdCLI(intf) bss_radio[bss_idx] = radio 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()[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_networks = device.get_ordered_networks() self.assertEqual(len(ordered_networks), 1) ordered_network = ordered_networks[0] self.assertEqual(ordered_network.name, "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)
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)
def test_connection_success(self): hapd = HostapdCLI(config='ssidFILS-384.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-384') 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) 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-384') 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) testutil.test_iface_operstate() testutil.test_ifaces_connected(device.name, hapd.ifname) device.disconnect() 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 = -3000 rule2 = hwsim.rules.create() rule2.source = bss_radio[2].addresses[0] rule2.bidirectional = True rule2.signal = -4000 wd = IWD(True, '/tmp') 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("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(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, 15) condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition, 15) # 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 < 11: time.sleep(11 - 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.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)
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)