eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

disconnect_during_handshake_test.py (3639B)


      1 #! /usr/bin/python3
      2 
      3 import unittest
      4 import sys, os
      5 
      6 sys.path.append('../util')
      7 import iwd
      8 from iwd import IWD
      9 from iwd import PSKAgent
     10 from iwd import NetworkType
     11 from hwsim import Hwsim
     12 from hostapd import HostapdCLI
     13 import testutil
     14 
     15 class Test(unittest.TestCase):
     16     def validate_connection(self, wd):
     17         device = wd.list_devices(1)[0]
     18 
     19         ordered_network = device.get_ordered_network('TestFT', full_scan=True)
     20 
     21         self.assertEqual(ordered_network.type, NetworkType.psk)
     22 
     23         condition = 'not obj.connected'
     24         wd.wait_for_object_condition(ordered_network.network_object, condition)
     25 
     26         self.assertFalse(self.bss_hostapd[0].list_sta())
     27         self.assertFalse(self.bss_hostapd[1].list_sta())
     28 
     29         device.connect_bssid(self.bss_hostapd[0].bssid)
     30 
     31         condition = 'obj.state == DeviceState.connected'
     32         wd.wait_for_object_condition(device, condition)
     33 
     34         self.bss_hostapd[0].wait_for_event('AP-STA-CONNECTED %s' % device.address)
     35 
     36         testutil.test_iface_operstate(device.name)
     37         testutil.test_ifaces_connected(self.bss_hostapd[0].ifname, device.name)
     38         self.assertRaises(Exception, testutil.test_ifaces_connected,
     39                           (self.bss_hostapd[1].ifname, device.name, True, True))
     40 
     41         self.rule0.enabled = True
     42 
     43         device.roam(self.bss_hostapd[1].bssid)
     44 
     45         device.clear_events()
     46         device.wait_for_event("handshake-started")
     47         self.bss_hostapd[1].deauthenticate(device.address, reason=15, test=1)
     48 
     49         # Check that iwd is on BSS 1 once out of roaming state and doesn't
     50         # go through 'disconnected', 'autoconnect', 'connecting' in between
     51         from_condition = 'obj.state == DeviceState.roaming'
     52         to_condition = 'obj.state == DeviceState.disconnected'
     53         wd.wait_for_object_change(device, from_condition, to_condition)
     54 
     55     def test_disconnect_during_handshake(self):
     56         self.bss_hostapd[0].set_value('wpa_key_mgmt', 'WPA-PSK')
     57         self.bss_hostapd[0].reload()
     58         self.bss_hostapd[0].wait_for_event("AP-ENABLED")
     59 
     60         self.bss_hostapd[1].set_value('wpa_key_mgmt', 'WPA-PSK')
     61         self.bss_hostapd[1].reload()
     62         self.bss_hostapd[1].wait_for_event("AP-ENABLED")
     63 
     64         self.validate_connection(self.wd)
     65 
     66     def tearDown(self):
     67         os.system('ip link set "' + self.bss_hostapd[0].ifname + '" down')
     68         os.system('ip link set "' + self.bss_hostapd[1].ifname + '" down')
     69         os.system('ip link set "' + self.bss_hostapd[0].ifname + '" up')
     70         os.system('ip link set "' + self.bss_hostapd[1].ifname + '" up')
     71 
     72         for hapd in self.bss_hostapd:
     73             hapd.default()
     74 
     75         self.wd.stop()
     76         self.wd = None
     77 
     78     def setUp(self):
     79         self.wd = IWD(True)
     80 
     81     @classmethod
     82     def setUpClass(cls):
     83         hwsim = Hwsim()
     84 
     85         IWD.copy_to_storage('TestFT.psk')
     86 
     87         cls.bss_hostapd = [ HostapdCLI(config='ft-psk-ccmp-1.conf'),
     88                             HostapdCLI(config='ft-psk-ccmp-2.conf') ]
     89 
     90         unused = HostapdCLI(config='ft-psk-ccmp-3.conf')
     91         unused.disable()
     92 
     93         cls.bss_hostapd[0].set_address('12:00:00:00:00:01')
     94         cls.bss_hostapd[1].set_address('12:00:00:00:00:02')
     95 
     96         rad1 = hwsim.get_radio('rad1')
     97 
     98         cls.rule0 = hwsim.rules.create()
     99         cls.rule0.destination = rad1.addresses[0]
    100         cls.rule0.prefix = '08'
    101         cls.rule0.drop = True
    102 
    103         HostapdCLI.group_neighbors(*cls.bss_hostapd)
    104 
    105     @classmethod
    106     def tearDownClass(cls):
    107         IWD.clear_storage()
    108         cls.bss_hostapd = None
    109         cls.rule0.remove()
    110 
    111 if __name__ == '__main__':
    112     unittest.main(exit=True)