2017-01-11 00:42:53 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.append('../util')
|
|
|
|
import iwd
|
|
|
|
from iwd import IWD
|
|
|
|
from iwd import PSKAgent
|
|
|
|
from iwd import NetworkType
|
|
|
|
|
|
|
|
class TestMFP(unittest.TestCase):
|
|
|
|
'''
|
2024-11-07 14:26:12 +01:00
|
|
|
The below test cases excesise the following MFP option setting scenarios:
|
2017-01-11 00:42:53 +01:00
|
|
|
|
|
|
|
IWD_MFP: AP_MFP: Result:
|
|
|
|
0 0 No MFP, connection succeeds
|
|
|
|
0 1 No MFP, connection succeeds
|
|
|
|
0 2 Not capable error
|
|
|
|
1 0 No MFP, connection succeeds
|
|
|
|
1 1 MFP enabled, connection succeeds
|
|
|
|
1 2 MFP enabled, connection succeeds
|
|
|
|
2 0 Not capable error
|
|
|
|
2 1 MFP enabled, connection succeeds
|
|
|
|
2 2 MFP enabled, connection succeeds
|
|
|
|
|
|
|
|
where:
|
|
|
|
0 - MFP is disabled
|
|
|
|
1 - MFP is optional
|
|
|
|
2 - MFP is required
|
|
|
|
'''
|
|
|
|
|
|
|
|
def check_mfp_connection(self, wd, device, ssid, throws_exception):
|
2018-12-14 20:15:28 +01:00
|
|
|
ordered_network = device.get_ordered_network(ssid)
|
2017-01-11 00:42:53 +01:00
|
|
|
|
|
|
|
condition = 'not obj.connected'
|
|
|
|
wd.wait_for_object_condition(ordered_network.network_object, condition)
|
|
|
|
|
|
|
|
if throws_exception:
|
|
|
|
with self.assertRaises(iwd.NotSupportedEx):
|
|
|
|
ordered_network.network_object.connect()
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
ordered_network.network_object.connect()
|
|
|
|
|
2020-09-14 23:02:33 +02:00
|
|
|
condition = 'obj.state == DeviceState.connected'
|
|
|
|
wd.wait_for_object_condition(device, condition)
|
2017-01-11 00:42:53 +01:00
|
|
|
|
|
|
|
device.disconnect()
|
|
|
|
|
|
|
|
condition = 'not obj.connected'
|
|
|
|
wd.wait_for_object_condition(ordered_network.network_object, condition)
|
|
|
|
|
2018-05-21 22:35:00 +02:00
|
|
|
IWD.clear_storage()
|
2017-01-11 00:42:53 +01:00
|
|
|
|
2018-05-21 22:35:00 +02:00
|
|
|
def stage_iwd(self, wd, config_dir):
|
|
|
|
psk_agent = PSKAgent( ['secret123', 'secret123', 'secret123'] )
|
2017-01-11 00:42:53 +01:00
|
|
|
wd.register_psk_agent(psk_agent)
|
|
|
|
|
2018-12-14 20:15:26 +01:00
|
|
|
devices = wd.list_devices(1)
|
2017-01-11 00:42:53 +01:00
|
|
|
self.assertIsNotNone(devices)
|
|
|
|
device = devices[0]
|
|
|
|
|
|
|
|
if config_dir == '/tmp/IWD-MFP2':
|
|
|
|
self.check_mfp_connection(wd, device, 'ssidMFP0', True)
|
|
|
|
else:
|
|
|
|
self.check_mfp_connection(wd, device, 'ssidMFP0', False)
|
|
|
|
|
|
|
|
self.check_mfp_connection(wd, device, 'ssidMFP1', False)
|
|
|
|
|
|
|
|
if config_dir == '/tmp/IWD-MFP0':
|
|
|
|
self.check_mfp_connection(wd, device, 'ssidMFP2', True)
|
|
|
|
else:
|
|
|
|
self.check_mfp_connection(wd, device, 'ssidMFP2', False)
|
|
|
|
|
|
|
|
wd.unregister_psk_agent(psk_agent)
|
|
|
|
|
2018-05-21 22:35:00 +02:00
|
|
|
def test_iwd_mfp0(self):
|
|
|
|
wd = IWD(True, '/tmp/IWD-MFP0')
|
2017-01-11 00:42:53 +01:00
|
|
|
|
2019-04-20 22:29:05 +02:00
|
|
|
self.stage_iwd(wd, '/tmp/IWD-MFP0')
|
2017-01-11 00:42:53 +01:00
|
|
|
|
|
|
|
def test_iwd_mfp1(self):
|
2018-05-21 22:35:00 +02:00
|
|
|
wd = IWD(True, '/tmp/IWD-MFP1')
|
|
|
|
|
2019-04-20 22:29:05 +02:00
|
|
|
self.stage_iwd(wd, '/tmp/IWD-MFP1')
|
2017-01-11 00:42:53 +01:00
|
|
|
|
|
|
|
def test_iwd_mfp2(self):
|
2018-05-21 22:35:00 +02:00
|
|
|
wd = IWD(True, '/tmp/IWD-MFP2')
|
|
|
|
|
2019-04-20 22:29:05 +02:00
|
|
|
self.stage_iwd(wd, '/tmp/IWD-MFP2')
|
2017-01-11 00:42:53 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main(exit=True)
|