tests: Add support for wlantest for remote hwsim tests
[mech_eap.git] / tests / hwsim / test_peerkey.py
1 # PeerKey tests
2 # Copyright (c) 2013-2015, Jouni Malinen <j@w1.fi>
3 #
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
6
7 import logging
8 logger = logging.getLogger()
9 import time
10
11 import hwsim_utils
12 import hostapd
13 from utils import skip_with_fips
14 from wlantest import Wlantest
15
16 def test_peerkey(dev, apdev):
17     """RSN AP and PeerKey between two STAs"""
18     ssid = "test-peerkey"
19     passphrase = "12345678"
20     params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
21     params['peerkey'] = "1"
22     hostapd.add_ap(apdev[0], params)
23
24     dev[0].connect(ssid, psk=passphrase, scan_freq="2412", peerkey=True)
25     dev[1].connect(ssid, psk=passphrase, scan_freq="2412", peerkey=True)
26     hwsim_utils.test_connectivity_sta(dev[0], dev[1])
27
28     dev[0].request("STKSTART " + dev[1].p2p_interface_addr())
29     time.sleep(0.5)
30     # NOTE: Actual use of the direct link (DLS) is not supported in
31     # mac80211_hwsim, so this operation fails at setting the keys after
32     # successfully completed 4-way handshake. This test case does allow the
33     # key negotiation part to be tested for coverage, though.
34
35 def test_peerkey_unknown_peer(dev, apdev):
36     """RSN AP and PeerKey attempt with unknown peer"""
37     ssid = "test-peerkey"
38     passphrase = "12345678"
39     params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
40     params['peerkey'] = "1"
41     hostapd.add_ap(apdev[0], params)
42
43     dev[0].connect(ssid, psk=passphrase, scan_freq="2412", peerkey=True)
44     dev[1].connect(ssid, psk=passphrase, scan_freq="2412", peerkey=True)
45     hwsim_utils.test_connectivity_sta(dev[0], dev[1])
46
47     dev[0].request("STKSTART " + dev[2].p2p_interface_addr())
48     time.sleep(0.5)
49
50 def test_peerkey_pairwise_mismatch(dev, apdev):
51     """RSN TKIP+CCMP AP and PeerKey between two STAs using different ciphers"""
52     skip_with_fips(dev[0])
53     ssid = "test-peerkey"
54     passphrase = "12345678"
55     params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
56     params['peerkey'] = "1"
57     params['rsn_pairwise'] = "TKIP CCMP"
58     hapd = hostapd.add_ap(apdev[0], params)
59
60     Wlantest.setup(hapd)
61     wt = Wlantest()
62     wt.flush()
63     wt.add_passphrase("12345678")
64
65     dev[0].connect(ssid, psk=passphrase, scan_freq="2412", peerkey=True,
66                    pairwise="CCMP")
67     dev[1].connect(ssid, psk=passphrase, scan_freq="2412", peerkey=True,
68                    pairwise="TKIP")
69     hwsim_utils.test_connectivity_sta(dev[0], dev[1])
70
71     dev[0].request("STKSTART " + dev[1].p2p_interface_addr())
72     time.sleep(0.5)
73     dev[1].request("STKSTART " + dev[0].p2p_interface_addr())
74     time.sleep(0.5)