eiwd

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

connection_test.py (3721B)


      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 PSKAgent
     10 from iwd import NetworkType
     11 from hostapd import HostapdCLI
     12 import testutil
     13 
     14 # Table beacon with wildcard BSSID
     15 basic_beacon = '51000000000002ffffffffffff020100'
     16 # Table beacon with wildcard BSSID and SSID filter
     17 beacon_with_ssid = '51000000000002ffffffffffff02010000077373696452524d'
     18 # Passive beacon with wildcard BSSID
     19 beacon_passive = '510b0000000000ffffffffffff020100'
     20 # Active beacon with wildcard BSSID
     21 beacon_active = '510b0000000001ffffffffffff020100'
     22 # Passive beacon with duration set
     23 beacon_passive_duration = '510b0000c80000ffffffffffff020100'
     24 # Passive beacon on disabled frequency (disallowed in US)
     25 beacon_passive_disabled = '520e0000c80000ffffffffffff020100'
     26 
     27 class Test(unittest.TestCase):
     28 
     29     def test_connection_success(self):
     30         hapd = HostapdCLI(config='ssidRRM.conf')
     31         wd = IWD()
     32 
     33         psk_agent = PSKAgent("secret123")
     34         wd.register_psk_agent(psk_agent)
     35 
     36         devices = wd.list_devices(1)
     37         device = devices[0]
     38 
     39         ordered_network = device.get_ordered_network('ssidRRM')
     40 
     41         self.assertEqual(ordered_network.type, NetworkType.psk)
     42 
     43         condition = 'not obj.connected'
     44         wd.wait_for_object_condition(ordered_network.network_object, condition)
     45 
     46         ordered_network.network_object.connect()
     47 
     48         condition = 'obj.state == DeviceState.connected'
     49         wd.wait_for_object_condition(device, condition)
     50 
     51         testutil.test_iface_operstate()
     52         testutil.test_ifaces_connected()
     53 
     54         hapd.wait_for_event('AP-STA-CONNECTED')
     55 
     56         wd.wait(1)
     57 
     58         # This should return both APs
     59         hapd.req_beacon(device.address, basic_beacon)
     60 
     61         for e in ['BEACON-RESP-RX', 'BEACON-RESP-RX']:
     62             event = hapd.wait_for_event(e).split(' ')
     63             self.assertTrue(event[3] == '00')
     64 
     65         wd.wait(1)
     66 
     67         # This should return just ssidRRM
     68         hapd.req_beacon(device.address, beacon_with_ssid)
     69         event = hapd.wait_for_event('BEACON-RESP-RX').split(' ')
     70         self.assertTrue(event[3] == '00')
     71 
     72         wd.wait(1)
     73 
     74         # This should passive scan on channel 11, returning otherSSID
     75         hapd.req_beacon(device.address, beacon_passive)
     76         # TODO: See if we are scanning here (scan not initiated from station)
     77 
     78         event = hapd.wait_for_event('BEACON-RESP-RX').split(' ')
     79         self.assertTrue(event[3] == '00')
     80 
     81         wd.wait(1)
     82 
     83         # This should active scan on channel 11, returning otherSSID
     84         hapd.req_beacon(device.address, beacon_active)
     85         # TODO: See if we are scanning here (scan not initiated from station)
     86 
     87         event = hapd.wait_for_event('BEACON-RESP-RX').split(' ')
     88         self.assertTrue(event[3] == '00')
     89 
     90         wd.wait(1)
     91 
     92          # This should passive scan on channel 11, returning otherSSID
     93         hapd.req_beacon(device.address, beacon_passive_duration)
     94         # TODO: See if we are scanning here (scan not initiated from station)
     95 
     96         event = hapd.wait_for_event('BEACON-RESP-RX').split(' ')
     97         self.assertTrue(event[3] == '00')
     98 
     99         wd.wait(1)
    100 
    101         hapd.req_beacon(device.address, beacon_passive_disabled)
    102 
    103         event = hapd.wait_for_event('BEACON-RESP-RX').split(' ')
    104         self.assertTrue(event[3] != '00')
    105 
    106         device.disconnect()
    107 
    108         condition = 'not obj.connected'
    109         wd.wait_for_object_condition(ordered_network.network_object, condition)
    110 
    111         wd.unregister_psk_agent(psk_agent)
    112 
    113     @classmethod
    114     def setUpClass(cls):
    115         pass
    116 
    117     @classmethod
    118     def tearDownClass(cls):
    119         IWD.clear_storage()
    120 
    121 if __name__ == '__main__':
    122     unittest.main(exit=True)