4 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
6 # This software may be distributed under the terms of the BSD license.
7 # See README for more details.
12 logger = logging.getLogger()
17 def check_cipher(dev, ap, cipher):
18 if cipher not in dev.get_capability("pairwise"):
20 params = { "ssid": "test-wpa2-psk",
21 "wpa_passphrase": "12345678",
23 "wpa_key_mgmt": "WPA-PSK",
24 "rsn_pairwise": cipher }
25 hostapd.add_ap(ap['ifname'], params)
26 dev.connect("test-wpa2-psk", psk="12345678",
27 pairwise=cipher, group=cipher, scan_freq="2412")
28 hwsim_utils.test_connectivity(dev.ifname, ap['ifname'])
30 def test_ap_cipher_tkip(dev, apdev):
31 """WPA2-PSK/TKIP connection"""
32 check_cipher(dev[0], apdev[0], "TKIP")
34 def test_ap_cipher_ccmp(dev, apdev):
35 """WPA2-PSK/CCMP connection"""
36 check_cipher(dev[0], apdev[0], "CCMP")
38 def test_ap_cipher_gcmp(dev, apdev):
39 """WPA2-PSK/GCMP connection"""
40 check_cipher(dev[0], apdev[0], "GCMP")
42 def test_ap_cipher_ccmp_256(dev, apdev):
43 """WPA2-PSK/CCMP-256 connection"""
44 check_cipher(dev[0], apdev[0], "CCMP-256")
46 def test_ap_cipher_gcmp_256(dev, apdev):
47 """WPA2-PSK/GCMP-256 connection"""
48 check_cipher(dev[0], apdev[0], "GCMP-256")
50 def test_ap_cipher_mixed_wpa_wpa2(dev, apdev):
51 """WPA2-PSK/CCMP/ and WPA-PSK/TKIP mixed configuration"""
52 ssid = "test-wpa-wpa2-psk"
53 passphrase = "12345678"
54 params = { "ssid": ssid,
55 "wpa_passphrase": passphrase,
57 "wpa_key_mgmt": "WPA-PSK",
58 "rsn_pairwise": "CCMP",
59 "wpa_pairwise": "TKIP" }
60 hostapd.add_ap(apdev[0]['ifname'], params)
61 dev[0].connect(ssid, psk=passphrase, proto="WPA2",
62 pairwise="CCMP", group="TKIP", scan_freq="2412")
63 status = dev[0].get_status()
64 if status['key_mgmt'] != 'WPA2-PSK':
65 raise Exception("Incorrect key_mgmt reported")
66 if status['pairwise_cipher'] != 'CCMP':
67 raise Exception("Incorrect pairwise_cipher reported")
68 if status['group_cipher'] != 'TKIP':
69 raise Exception("Incorrect group_cipher reported")
70 bss = dev[0].get_bss(apdev[0]['bssid'])
71 if bss['ssid'] != ssid:
72 raise Exception("Unexpected SSID in the BSS entry")
73 if "[WPA-PSK-TKIP]" not in bss['flags']:
74 raise Exception("Missing BSS flag WPA-PSK-TKIP")
75 if "[WPA2-PSK-CCMP]" not in bss['flags']:
76 raise Exception("Missing BSS flag WPA2-PSK-CCMP")
77 hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
79 dev[1].connect(ssid, psk=passphrase, proto="WPA",
80 pairwise="TKIP", group="TKIP", scan_freq="2412")
81 status = dev[1].get_status()
82 if status['key_mgmt'] != 'WPA-PSK':
83 raise Exception("Incorrect key_mgmt reported")
84 if status['pairwise_cipher'] != 'TKIP':
85 raise Exception("Incorrect pairwise_cipher reported")
86 if status['group_cipher'] != 'TKIP':
87 raise Exception("Incorrect group_cipher reported")
88 hwsim_utils.test_connectivity(dev[1].ifname, apdev[0]['ifname'])
89 hwsim_utils.test_connectivity(dev[0].ifname, dev[1].ifname)