2013-03-30 12:47:22 +01:00
|
|
|
# Protected management frames tests
|
|
|
|
# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
|
|
|
|
#
|
|
|
|
# This software may be distributed under the terms of the BSD license.
|
|
|
|
# See README for more details.
|
|
|
|
|
|
|
|
import time
|
|
|
|
import subprocess
|
|
|
|
import logging
|
2013-10-31 11:46:42 +01:00
|
|
|
logger = logging.getLogger()
|
2013-03-30 12:47:22 +01:00
|
|
|
|
|
|
|
import hwsim_utils
|
|
|
|
import hostapd
|
|
|
|
from wlantest import Wlantest
|
|
|
|
|
2013-03-31 15:16:37 +02:00
|
|
|
def test_ap_pmf_required(dev, apdev):
|
2013-03-30 12:47:22 +01:00
|
|
|
"""WPA2-PSK AP with PMF required"""
|
|
|
|
ssid = "test-pmf-required"
|
|
|
|
wt = Wlantest()
|
|
|
|
wt.flush()
|
|
|
|
wt.add_passphrase("12345678")
|
|
|
|
params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
|
|
|
|
params["wpa_key_mgmt"] = "WPA-PSK-SHA256";
|
|
|
|
params["ieee80211w"] = "2";
|
2013-03-31 15:16:37 +02:00
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
dev[0].connect(ssid, psk="12345678", ieee80211w="1",
|
2013-11-02 10:22:16 +01:00
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2013-03-31 15:16:37 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
|
|
|
|
dev[1].connect(ssid, psk="12345678", ieee80211w="2",
|
2013-11-02 10:22:16 +01:00
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2013-03-31 15:16:37 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[1].ifname, apdev[0]['ifname'])
|
|
|
|
hapd = hostapd.Hostapd(apdev[0]['ifname'])
|
2013-03-30 14:31:50 +01:00
|
|
|
hapd.request("SA_QUERY " + dev[0].p2p_interface_addr())
|
|
|
|
hapd.request("SA_QUERY " + dev[1].p2p_interface_addr())
|
2013-03-31 15:16:37 +02:00
|
|
|
wt.require_ap_pmf_mandatory(apdev[0]['bssid'])
|
|
|
|
wt.require_sta_pmf(apdev[0]['bssid'], dev[0].p2p_interface_addr())
|
|
|
|
wt.require_sta_pmf_mandatory(apdev[0]['bssid'], dev[1].p2p_interface_addr())
|
2013-03-30 14:31:50 +01:00
|
|
|
time.sleep(0.1)
|
2013-03-31 15:16:37 +02:00
|
|
|
if wt.get_sta_counter("valid_saqueryresp_tx", apdev[0]['bssid'],
|
2013-03-30 14:31:50 +01:00
|
|
|
dev[0].p2p_interface_addr()) < 1:
|
|
|
|
raise Exception("STA did not reply to SA Query")
|
2013-03-31 15:16:37 +02:00
|
|
|
if wt.get_sta_counter("valid_saqueryresp_tx", apdev[0]['bssid'],
|
2013-03-30 14:31:50 +01:00
|
|
|
dev[1].p2p_interface_addr()) < 1:
|
|
|
|
raise Exception("STA did not reply to SA Query")
|
2013-03-30 12:47:22 +01:00
|
|
|
|
2013-03-31 15:16:37 +02:00
|
|
|
def test_ap_pmf_optional(dev, apdev):
|
2013-03-30 12:47:22 +01:00
|
|
|
"""WPA2-PSK AP with PMF optional"""
|
|
|
|
ssid = "test-pmf-optional"
|
|
|
|
wt = Wlantest()
|
|
|
|
wt.flush()
|
|
|
|
wt.add_passphrase("12345678")
|
|
|
|
params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
|
|
|
|
params["wpa_key_mgmt"] = "WPA-PSK";
|
|
|
|
params["ieee80211w"] = "1";
|
2013-03-31 15:16:37 +02:00
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
dev[0].connect(ssid, psk="12345678", ieee80211w="1",
|
2013-11-02 10:22:16 +01:00
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2013-03-31 15:16:37 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
|
|
|
|
dev[1].connect(ssid, psk="12345678", ieee80211w="2",
|
2013-11-02 10:22:16 +01:00
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2013-03-31 15:16:37 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[1].ifname, apdev[0]['ifname'])
|
|
|
|
wt.require_ap_pmf_optional(apdev[0]['bssid'])
|
|
|
|
wt.require_sta_pmf(apdev[0]['bssid'], dev[0].p2p_interface_addr())
|
|
|
|
wt.require_sta_pmf_mandatory(apdev[0]['bssid'], dev[1].p2p_interface_addr())
|
2013-03-30 12:47:22 +01:00
|
|
|
|
2013-03-31 15:16:37 +02:00
|
|
|
def test_ap_pmf_optional_2akm(dev, apdev):
|
2013-03-30 12:47:22 +01:00
|
|
|
"""WPA2-PSK AP with PMF optional (2 AKMs)"""
|
|
|
|
ssid = "test-pmf-optional-2akm"
|
|
|
|
wt = Wlantest()
|
|
|
|
wt.flush()
|
|
|
|
wt.add_passphrase("12345678")
|
|
|
|
params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
|
|
|
|
params["wpa_key_mgmt"] = "WPA-PSK WPA-PSK-SHA256";
|
|
|
|
params["ieee80211w"] = "1";
|
2013-03-31 15:16:37 +02:00
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
dev[0].connect(ssid, psk="12345678", ieee80211w="1",
|
2013-11-02 10:22:16 +01:00
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2013-03-31 15:16:37 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
|
|
|
|
dev[1].connect(ssid, psk="12345678", ieee80211w="2",
|
2013-11-02 10:22:16 +01:00
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2013-03-31 15:16:37 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[1].ifname, apdev[0]['ifname'])
|
|
|
|
wt.require_ap_pmf_optional(apdev[0]['bssid'])
|
|
|
|
wt.require_sta_pmf(apdev[0]['bssid'], dev[0].p2p_interface_addr())
|
|
|
|
wt.require_sta_key_mgmt(apdev[0]['bssid'], dev[0].p2p_interface_addr(),
|
|
|
|
"PSK-SHA256")
|
|
|
|
wt.require_sta_pmf_mandatory(apdev[0]['bssid'], dev[1].p2p_interface_addr())
|
|
|
|
wt.require_sta_key_mgmt(apdev[0]['bssid'], dev[1].p2p_interface_addr(),
|
|
|
|
"PSK-SHA256")
|
2013-03-30 12:47:22 +01:00
|
|
|
|
2013-03-31 15:16:37 +02:00
|
|
|
def test_ap_pmf_negative(dev, apdev):
|
2013-03-30 12:47:22 +01:00
|
|
|
"""WPA2-PSK AP without PMF (negative test)"""
|
|
|
|
ssid = "test-pmf-negative"
|
|
|
|
wt = Wlantest()
|
|
|
|
wt.flush()
|
|
|
|
wt.add_passphrase("12345678")
|
|
|
|
params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
|
2013-03-31 15:16:37 +02:00
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
dev[0].connect(ssid, psk="12345678", ieee80211w="1",
|
2013-11-02 10:22:16 +01:00
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2013-03-31 15:16:37 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
|
2013-03-30 12:47:22 +01:00
|
|
|
try:
|
2013-03-31 15:16:37 +02:00
|
|
|
dev[1].connect(ssid, psk="12345678", ieee80211w="2",
|
2013-11-02 10:22:16 +01:00
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2013-03-31 15:16:37 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[1].ifname, apdev[0]['ifname'])
|
2013-03-30 12:47:22 +01:00
|
|
|
raise Exception("PMF required STA connected to no PMF AP")
|
|
|
|
except Exception, e:
|
|
|
|
logger.debug("Ignore expected exception: " + str(e))
|
2013-03-31 15:16:37 +02:00
|
|
|
wt.require_ap_no_pmf(apdev[0]['bssid'])
|