bad_neighbor_report_test.py (5603B)
1 #!/usr/bin/python3 2 3 import unittest 4 import sys 5 6 sys.path.append('../util') 7 import iwd 8 from iwd import IWD 9 from iwd import NetworkType 10 11 from hostapd import HostapdCLI 12 13 class Test(unittest.TestCase): 14 def initial_connection(self): 15 ordered_network = self.device.get_ordered_network('TestAPRoam') 16 17 self.assertEqual(ordered_network.type, NetworkType.psk) 18 19 condition = 'not obj.connected' 20 self.wd.wait_for_object_condition(ordered_network.network_object, condition) 21 22 self.device.connect_bssid(self.bss_hostapd[0].bssid) 23 24 condition = 'obj.state == DeviceState.connected' 25 self.wd.wait_for_object_condition(self.device, condition) 26 27 self.bss_hostapd[0].wait_for_event('AP-STA-CONNECTED') 28 29 self.assertFalse(self.bss_hostapd[1].list_sta()) 30 31 def test_full_scan(self): 32 """ 33 Tests that IWD first tries a limited scan, then a full scan after 34 an AP directed roam. After the full scan yields no results IWD 35 should stop trying to roam. 36 """ 37 self.initial_connection() 38 39 # Disable other APs, so the scans come up empty 40 self.bss_hostapd[1].disable() 41 self.bss_hostapd[2].disable() 42 43 # Send a bad candidate list with the BSS TM request which contains a 44 # channel with no AP operating on it. 45 self.bss_hostapd[0].send_bss_transition( 46 self.device.address, 47 [(self.bss_hostapd[1].bssid, "8f0000005105060603000000")] 48 ) 49 self.device.wait_for_event("roam-scan-triggered") 50 self.device.wait_for_event("no-roam-candidates") 51 # IWD should then trigger a full scan 52 self.device.wait_for_event("full-roam-scan") 53 self.device.wait_for_event("no-roam-candidates", timeout=30) 54 55 # IWD should not trigger a roam again after the above 2 failures. 56 with self.assertRaises(TimeoutError): 57 self.device.wait_for_event("roam-scan-triggered", timeout=60) 58 59 def test_bad_candidate_list(self): 60 """ 61 Tests behavior when the AP sends a candidate list but the scan 62 finds no BSS's. IWD should fall back to a full scan after. 63 """ 64 self.initial_connection() 65 66 # Send a bad candidate list with the BSS TM request which contains a 67 # channel with no AP operating on it. 68 self.bss_hostapd[0].send_bss_transition( 69 self.device.address, 70 [(self.bss_hostapd[1].bssid, "8f0000005105060603000000")] 71 ) 72 self.device.wait_for_event("roam-scan-triggered") 73 self.device.wait_for_event("no-roam-candidates") 74 # IWD should then trigger a full scan 75 self.device.wait_for_event("full-roam-scan") 76 self.device.wait_for_event("roaming", timeout=30) 77 self.device.wait_for_event("connected") 78 79 def test_bad_neighbor_report(self): 80 """ 81 Tests behavior when the AP sends no candidate list. IWD should 82 request a neighbor report. If the limited scan yields no BSS's IWD 83 should fall back to a full scan. 84 """ 85 86 # Set a bad neighbor (channel that no AP is on) to force the limited 87 # roam scan to fail 88 self.bss_hostapd[0].set_neighbor( 89 self.bss_hostapd[1].bssid, 90 "TestAPRoam", 91 '%s8f000000%s%s060603000000' % (self.bss_hostapd[1].bssid.replace(':', ''), "51", "0b") 92 ) 93 94 self.initial_connection() 95 96 self.bss_hostapd[0].send_bss_transition(self.device.address, []) 97 self.device.wait_for_event("roam-scan-triggered") 98 # The AP will have sent a neighbor report with a single BSS but on 99 # channel 11 which no AP is on. This should result in a limited scan 100 # picking up no candidates. 101 self.device.wait_for_event("no-roam-candidates", timeout=30) 102 # IWD should then trigger a full scan 103 self.device.wait_for_event("full-roam-scan") 104 self.device.wait_for_event("roaming", timeout=30) 105 self.device.wait_for_event("connected") 106 107 def test_ignore_candidate_list_quirk(self): 108 """ 109 Tests that IWD ignores the candidate list sent by the AP since its 110 OUI indicates it should be ignored. 111 """ 112 113 # Set the OUI so the candidate list should be ignored 114 for hapd in self.bss_hostapd: 115 hapd.set_value('vendor_elements', 'dd0400180a01') 116 117 self.initial_connection() 118 119 # Send with a candidate list (should be ignored) 120 self.bss_hostapd[0].send_bss_transition( 121 self.device.address, 122 [(self.bss_hostapd[1].bssid, "8f0000005105060603000000")] 123 ) 124 # IWD should ignore the list and trigger a full scan since we have not 125 # set any neighbors 126 self.device.wait_for_event("full-roam-scan") 127 self.device.wait_for_event("roaming", timeout=30) 128 self.device.wait_for_event("connected") 129 130 def setUp(self): 131 self.wd = IWD(True) 132 133 devices = self.wd.list_devices(1) 134 self.device = devices[0] 135 136 def tearDown(self): 137 self.wd = None 138 self.device = None 139 140 for hapd in self.bss_hostapd: 141 hapd.reload() 142 143 @classmethod 144 def setUpClass(cls): 145 IWD.copy_to_storage('TestAPRoam.psk') 146 147 cls.bss_hostapd = [ HostapdCLI(config='ssid1.conf'), 148 HostapdCLI(config='ssid2.conf'), 149 HostapdCLI(config='ssid3.conf') ] 150 151 @classmethod 152 def tearDownClass(cls): 153 IWD.clear_storage() 154 155 if __name__ == '__main__': 156 unittest.main(exit=True)