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): hwsim = Hwsim() bss_radio = hwsim.get_radio('rad0') self.assertIsNotNone(bss_radio) wd = IWD() devices = wd.list_devices(1) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network('ssidOWE') self.assertEqual(ordered_network.type, NetworkType.open) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) rule0 = hwsim.rules.create() rule0.source = bss_radio.addresses[0] rule0.bidirectional = True rule0.drop = True with self.assertRaises(iwd.FailedEx): ordered_network.network_object.connect()
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() 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 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 validate_connection(self, wd): hwsim = Hwsim() bss_radio = hwsim.get_radio('rad0') psk_agent = PSKAgent(["secret123", "secret123"]) wd.register_psk_agent(psk_agent) devices = wd.list_devices(4) # These devices aren't used in this test, this makes logs a bit nicer # since these devices would presumably start autoconnecting. devices[1].disconnect() devices[2].disconnect() devices[3].disconnect() self.assertIsNotNone(devices) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) network = device.get_ordered_network('ssidSAE') self.assertEqual(network.type, NetworkType.psk) condition = 'not obj.connected' wd.wait_for_object_condition(network.network_object, condition) rule0 = hwsim.rules.create() rule0.source = bss_radio.addresses[0] rule0.bidirectional = True rule0.drop = True rule0.prefix = 'b0' wd.wait(1) print(rule0) with self.assertRaises(iwd.FailedEx): network.network_object.connect() condition = 'not obj.connected' wd.wait_for_object_condition(network.network_object, condition) rule0.prefix = '00' with self.assertRaises(iwd.FailedEx): network.network_object.connect() wd.unregister_psk_agent(psk_agent)
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): 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 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 tearDown(self): os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" down') os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" down') os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" up') os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up') hwsim = Hwsim() for rule in list(hwsim.rules.keys()): del hwsim.rules[rule]
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 tearDown(self): os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" down') os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" down') os.system('ifconfig "' + self.bss_hostapd[0].ifname + '" up') os.system('ifconfig "' + self.bss_hostapd[1].ifname + '" up') hwsim = Hwsim() wd = IWD() device = wd.list_devices(1)[0] try: device.disconnect() except: pass condition = 'obj.state == DeviceState.disconnected' wd.wait_for_object_condition(device, condition) for rule in list(hwsim.rules.keys()): del hwsim.rules[rule]
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)
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_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() psk_agent = PSKAgent("EasilyGuessedPassword") wd.register_psk_agent(psk_agent) 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.psk) self.assertEqual(ordered_network.signal_strength, -2000) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) self.assertFalse(self.bss_hostapd[0].list_sta()) self.assertFalse(self.bss_hostapd[1].list_sta()) ordered_network.network_object.connect() condition = 'obj.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()) wd.unregister_psk_agent(psk_agent) testutil.test_iface_operstate(device.name) testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) self.assertRaises(Exception, testutil.test_ifaces_connected, (self.bss_hostapd[1].ifname, device.name)) # Check that iwd starts transition to BSS 1 in less than 10 seconds. # The 10 seconds is longer than needed to scan on just two channels # but short enough that a full scan on the 2.4 + 5.8 bands supported # by mac80211_hwsim will not finish. If this times out then, but # device_roam_trigger_cb has happened, it probably means that # Neighbor Reports are broken. rule0.signal = -8000 condition = 'obj.state == DeviceState.roaming' wd.wait_for_object_condition(device, condition, 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_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_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 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)
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_preauth_success(self): hwsim = Hwsim() bss_hostapd = [ HostapdCLI(config='eaptls-preauth-1.conf'), HostapdCLI(config='eaptls-preauth-2.conf') ] bss_radio = [ hwsim.get_radio('rad0'), hwsim.get_radio('rad1') ] rule0 = hwsim.rules.create() rule0.source = bss_radio[0].addresses[0] rule0.bidirectional = True rule1 = hwsim.rules.create() rule1.source = bss_radio[1].addresses[0] rule1.bidirectional = True # Fill in the neighbor AP tables in both BSSes. By default each # instance knows only about current BSS, even inside one hostapd # process. # Roaming still works without the neighbor AP table but neighbor # reports have to be disabled in the .conf files bss0_nr = ''.join(bss_radio[0].addresses[0].split(':')) + \ '8f0000005101060603000000' bss1_nr = ''.join(bss_radio[1].addresses[0].split(':')) + \ '8f0000005102060603000000' bss_hostapd[0].set_neighbor(bss_radio[1].addresses[0], 'TestPreauth', bss1_nr) bss_hostapd[1].set_neighbor(bss_radio[0].addresses[0], 'TestPreauth', bss0_nr) wd = IWD() device = wd.list_devices(1)[0] # Check that iwd selects BSS 0 first rule0.signal = -2500 rule1.signal = -3500 condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'obj.scanning' wd.wait_for_object_condition(device, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network('TestPreauth') self.assertEqual(ordered_network.type, NetworkType.eap) self.assertEqual(ordered_network.signal_strength, -2500) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) self.assertFalse(bss_hostapd[0].list_sta()) self.assertFalse(bss_hostapd[1].list_sta()) ordered_network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) self.assertTrue(bss_hostapd[0].list_sta()) self.assertFalse(bss_hostapd[1].list_sta()) testutil.test_iface_operstate(device.name) testutil.test_ifaces_connected(bss_hostapd[0].ifname, device.name) self.assertRaises(Exception, testutil.test_ifaces_connected, bss_hostapd[1].ifname, device.name) # Check that iwd starts transition to BSS 1 in less than 15 seconds rule0.signal = -8000 condition = 'obj.state == DeviceState.roaming' wd.wait_for_object_condition(device, condition, 15) # TODO: verify that the PMK from preauthentication was used # Check that iwd is on BSS 1 once out of roaming state and doesn't # go through 'disconnected', 'autoconnect', 'connecting' in between condition = 'obj.state != DeviceState.roaming' wd.wait_for_object_condition(device, condition, 5) self.assertEqual(device.state, iwd.DeviceState.connected) self.assertTrue(bss_hostapd[1].list_sta()) testutil.test_iface_operstate(device.name) testutil.test_ifaces_connected(bss_hostapd[1].ifname, device.name) self.assertRaises(Exception, testutil.test_ifaces_connected, (bss_hostapd[0].ifname, device.name)) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition)
def test_fast_retry(self): hwsim = Hwsim() bss_hostapd = [ HostapdCLI(config='ssid1.conf'), HostapdCLI(config='ssid2.conf') ] bss_radio = [hwsim.get_radio('rad0'), hwsim.get_radio('rad1')] rule0 = hwsim.rules.create() rule0.source = bss_radio[0].addresses[0] rule0.bidirectional = True rule1 = hwsim.rules.create() rule1.source = bss_radio[1].addresses[0] rule1.bidirectional = True # Fill in the neighbor AP tables in both BSSes. By default each # instance knows only about current BSS, even inside one hostapd # process. # Roaming still works without the neighbor AP table but neighbor # reports have to be disabled in the .conf files bss0_nr = ''.join(bss_radio[0].addresses[0].split(':')) + \ '8f0000005101060603000000' bss1_nr = ''.join(bss_radio[1].addresses[0].split(':')) + \ '8f0000005102060603000000' bss_hostapd[0].set_neighbor(bss_radio[1].addresses[0], 'TestRoamRetry', bss1_nr) bss_hostapd[1].set_neighbor(bss_radio[0].addresses[0], 'TestRoamRetry', bss0_nr) # Start in the vicinity of BSS 0, check that iwd connects to BSS 0 rule0.signal = -2000 rule1.signal = -8500 wd = IWD() psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network('TestRoamRetry') self.assertEqual(ordered_network.type, NetworkType.psk) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) self.assertTrue(bss_hostapd[0].list_sta()) self.assertFalse(bss_hostapd[1].list_sta()) wd.wait(5) # Now push the signal LOW, wait for iwd to attempt a roam, fail, and # schedule another attempt for 60 seconds later rule0.signal = -8000 wd.wait(20) self.assertEqual(device.state, iwd.DeviceState.connected) self.assertTrue(bss_hostapd[0].list_sta()) self.assertFalse(bss_hostapd[1].list_sta()) testutil.test_iface_operstate(device.name) testutil.test_ifaces_connected(bss_hostapd[0].ifname, device.name) # Assert high signal for BSS 0 again. This clears the way for a faster # roam attempt on LOW again rule0.signal = -5000 # Wait a little for signal recognition wd.wait(1) # Assert low signal for BSS 0, check that iwd starts transition to BSS 1 # in less than 10 seconds. Because of the neighbor report a scan should # not be necessary. rule0.signal = -8000 rule1.signal = -2000 condition = 'obj.state == DeviceState.roaming' wd.wait_for_object_condition(device, condition, max_wait=10) # Check that iwd is on BSS 1 once out of roaming state and doesn't # go through 'disconnected', 'autoconnect', 'connecting' in between from_condition = 'obj.state == DeviceState.roaming' to_condition = 'obj.state == DeviceState.connected' wd.wait_for_object_change(device, from_condition, to_condition) self.assertTrue(bss_hostapd[1].list_sta()) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) wd.unregister_psk_agent(psk_agent) rule0.remove() rule1.remove()
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): hwsim = Hwsim() bss_hostapd = [None, None, None] 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 bss_hostapd[bss_idx] = HostapdCLI(intf) bss_radio[bss_idx] = radio 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, "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)
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 # Check that iwd selects BSS 0 first rule0.signal = -2000 rule1.signal = -6900 wd = IWD(True) psk_agent = PSKAgent("EasilyGuessedPassword") wd.register_psk_agent(psk_agent) device = wd.list_devices(1)[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'obj.scanning' wd.wait_for_object_condition(device, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network('TestFT') self.assertEqual(ordered_network.type, NetworkType.psk) self.assertEqual(ordered_network.signal_strength, -2000) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) self.assertFalse(self.bss_hostapd[0].list_sta()) self.assertFalse(self.bss_hostapd[1].list_sta()) ordered_network.network_object.connect() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) self.bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address) # list_sta actually reports any authenticated stations. Due to the # nature of FT-over-DS IWD should authenticate to all stations with # the same mobility domain. This means both APs should show our station. self.assertTrue(self.bss_hostapd[0].list_sta()) self.assertTrue(self.bss_hostapd[1].list_sta()) wd.unregister_psk_agent(psk_agent) testutil.test_iface_operstate(device.name) testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name) self.assertRaises(Exception, testutil.test_ifaces_connected, (self.bss_hostapd[1].ifname, device.name)) # Check that iwd starts transition to BSS 1 in less than 10 seconds. # The 10 seconds is longer than needed to scan on just two channels # but short enough that a full scan on the 2.4 + 5.8 bands supported # by mac80211_hwsim will not finish. If this times out then, but # device_roam_trigger_cb has happened, it probably means that # Neighbor Reports are broken. rule0.signal = -8000 condition = 'obj.state == DeviceState.roaming' wd.wait_for_object_condition(device, condition) # Check that iwd is on BSS 1 once out of roaming state and doesn't # go through 'disconnected', 'autoconnect', 'connecting' in between from_condition = 'obj.state == DeviceState.roaming' to_condition = 'obj.state == DeviceState.connected' wd.wait_for_object_change(device, from_condition, to_condition) 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_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(1)[0] # Check that iwd selects BSS 0 first rule0.signal = -2500 rule1.signal = -3500 condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'obj.scanning' wd.wait_for_object_condition(device, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_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): hwsim = Hwsim() bss_hostapd = [ HostapdCLI(config='ssid1.conf'), HostapdCLI(config='ssid2.conf'), HostapdCLI(config='ssid3.conf') ] bss_radio = [ hwsim.get_radio('rad0'), hwsim.get_radio('rad1'), hwsim.get_radio('rad2') ] rule0 = hwsim.rules.create() rule0.source = bss_radio[0].addresses[0] rule0.bidirectional = True rule0.signal = -2000 rule1 = hwsim.rules.create() rule1.source = bss_radio[1].addresses[0] rule1.bidirectional = True rule1.signal = -3000 rule2 = hwsim.rules.create() rule2.source = bss_radio[2].addresses[0] rule2.bidirectional = True rule2.signal = -4000 wd = IWD(True) psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) devices = wd.list_devices(2) device = devices[0] devices[1].disconnect() ordered_network = device.get_ordered_network("TestBlacklist", scan_if_needed=True) self.assertEqual(ordered_network.type, NetworkType.psk) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) rule0.drop = True ordered_network.network_object.connect(wait=False) # Have AP1 drop all packets, should result in a connection timeout rule0.drop = True # Note the time so later we don't sleep any longer than required start = time.time() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) # IWD should have attempted to connect to bss_hostapd[0], since its # signal strength was highest. But since we dropped all packets this # connect should fail, and the BSS should be blacklisted. Then we # should automatically try the next BSS in the list, which is # bss_hostapd[1] self.assertNotIn(device.address, bss_hostapd[0].list_sta()) self.assertIn(device.address, bss_hostapd[1].list_sta()) rule0.drop = False # Next try autoconnecting to a network with a blacklisted BSS. Since an # explicit disconnect call would disable autoconnect we reset # hostapd which will disconnect IWD. bss_hostapd[1].reload() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) # Now we wait... AutoConnect should take over condition = 'obj.state == DeviceState.connecting' wd.wait_for_object_condition(device, condition) condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) # Same as before, make sure we didn't connect to the blacklisted AP. self.assertNotIn(device.address, bss_hostapd[0].list_sta()) self.assertIn(device.address, bss_hostapd[1].list_sta()) # Wait for the blacklist to expire (10 seconds) elapsed = time.time() - start if elapsed < 15: wd.wait(15 - elapsed) device.disconnect() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network("TestBlacklist") self.assertEqual(ordered_network.type, NetworkType.psk) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) self.assertIn(device.address, bss_hostapd[0].list_sta()) wd.unregister_psk_agent(psk_agent) rule0.remove() rule1.remove() rule2.remove()
def test_rssi_agent(self): rule = Hwsim().rules.create() rule.signal = -4000 wd = IWD() device = wd.list_devices(1)[0] # Register agent early to catch any unexpected notifications agent = TstAgent() agent.calls = 0 device.register_signal_agent(agent, [-20, -40, -60, -80]) 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, "TestOpen") self.assertEqual(ordered_network.type, NetworkType.open) self.assertEqual(ordered_network.signal_strength, -4000) 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) # Test with 5 signal strength levels first, then with 3 def test_list(rssi_pairs): # Roughly test big jumps in RSSI value that cross from one # level range to another, then with small changes that shouldn't # cause any notification. # Allow 3 secs for the agent to receive the final signal # strength level number and allow more than one notification # until it reaches the target value because the kernel (mac80211 # at least) uses a moving-window average value over the last RSSI # measurements received from the driver and it changes gradually. # Normally 1 second is enough. self.assertEqual(agent.calls, 0) for centre, level in rssi_pairs: rule.signal = centre agent.level = -1 condition = 'obj.level == ' + str(level) wd.wait_for_object_condition(agent, condition, 3) self.assertTrue(agent.calls > 0) self.assertEqual(agent.device_path, device.device_path) agent.calls = 0 for offset in [-900, 500, -100, 900]: rule.signal = centre - offset wd.wait(0.5) self.assertEqual(agent.calls, 0) test_list([(-7000, 3), (-1000, 0), (-3000, 1), (-5000, 2), (-7000, 3), (-1000, 0), (-5000, 2)]) device.unregister_signal_agent(agent) device.register_signal_agent(agent, [-35, -65]) test_list([(-1500, 0), (-5000, 1), (-7500, 2), (-1500, 0)]) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) self.assertEqual(agent.calls, 0) device.unregister_signal_agent(agent)
def test_connection_success(self): hwsim = Hwsim() hostapd = None radio = None for wname in wiphy_map: wiphy = wiphy_map[wname] intf = list(wiphy.values())[0] if intf.use == 'hostapd': hostapd = HostapdCLI(intf) for path in hwsim.radios: if hwsim.radios[path].name == wname: radio = hwsim.radios[path] break 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) # 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)