from wlantest import Wlantest
from wpasupplicant import WpaSupplicant
+KT_PTK, KT_GTK = range(2)
+
def check_cipher(dev, ap, cipher, group_cipher=None):
if cipher not in dev.get_capability("pairwise"):
raise HwsimSkip("Cipher %s not supported" % cipher)
dev[0].select_network(id)
dev[0].wait_connected()
-def get_rx_spec(phy, gtk=False):
+def get_rx_spec(phy, keytype=KT_PTK):
keys = "/sys/kernel/debug/ieee80211/%s/keys" % (phy)
try:
for key in os.listdir(keys):
keydir = keys + "/" + key
files = os.listdir(keydir)
- if not gtk and "station" not in files:
+ if keytype == KT_PTK and "station" not in files:
continue
- if gtk and "station" in files:
+ if keytype != KT_PTK and "station" in files:
continue
with open(keydir + "/rx_spec") as f:
return f.read()
raise HwsimSkip("debugfs not supported in mac80211")
return None
-def get_tk_replay_counter(phy, gtk=False):
+def get_tk_replay_counter(phy, keytype=KT_PTK):
keys = "/sys/kernel/debug/ieee80211/%s/keys" % (phy)
try:
for key in os.listdir(keys):
keydir = keys + "/" + key
files = os.listdir(keydir)
- if not gtk and "station" not in files:
+ if keytype == KT_PTK and "station" not in files:
continue
- if gtk and "station" in files:
+ if keytype != KT_PTK and "station" in files:
continue
with open(keydir + "/replays") as f:
return int(f.read())
def test_ap_cipher_replay_protection_sta_gtk_ccmp(dev, apdev):
"""CCMP replay protection on STA (GTK)"""
- run_ap_cipher_replay_protection_sta(dev, apdev, "CCMP", gtk=True)
+ run_ap_cipher_replay_protection_sta(dev, apdev, "CCMP", keytype=KT_GTK)
def test_ap_cipher_replay_protection_sta_gtk_tkip(dev, apdev):
"""TKIP replay protection on STA (GTK)"""
skip_without_tkip(dev[0])
- run_ap_cipher_replay_protection_sta(dev, apdev, "TKIP", gtk=True)
+ run_ap_cipher_replay_protection_sta(dev, apdev, "TKIP", keytype=KT_GTK)
def test_ap_cipher_replay_protection_sta_gtk_gcmp(dev, apdev):
"""GCMP replay protection on STA (GTK)"""
if "GCMP" not in dev[0].get_capability("pairwise"):
raise HwsimSkip("GCMP not supported")
- run_ap_cipher_replay_protection_sta(dev, apdev, "GCMP", gtk=True)
+ run_ap_cipher_replay_protection_sta(dev, apdev, "GCMP", keytype=KT_GTK)
-def run_ap_cipher_replay_protection_sta(dev, apdev, cipher, gtk=False):
+def run_ap_cipher_replay_protection_sta(dev, apdev, cipher, keytype=KT_PTK):
params = {"ssid": "test-wpa2-psk",
"wpa_passphrase": "12345678",
"wpa": "2",
hapd.wait_sta()
if cipher != "TKIP":
- replays = get_tk_replay_counter(phy, gtk)
+ replays = get_tk_replay_counter(phy, keytype)
if replays != 0:
raise Exception("Unexpected replay reported (1)")
hwsim_utils.test_connectivity(dev[0], hapd)
if cipher != "TKIP":
- replays = get_tk_replay_counter(phy, gtk)
+ replays = get_tk_replay_counter(phy, keytype)
if replays != 0:
raise Exception("Unexpected replay reported (2)")
- addr = "ff:ff:ff:ff:ff:ff" if gtk else dev[0].own_addr()
+ addr = "ff:ff:ff:ff:ff:ff" if keytype != KT_PTK else dev[0].own_addr()
if "OK" not in hapd.request("RESET_PN " + addr):
raise Exception("RESET_PN failed")
time.sleep(0.1)
success_expected=False)
if cipher != "TKIP":
- replays = get_tk_replay_counter(phy, gtk)
+ replays = get_tk_replay_counter(phy, keytype)
if replays < 1:
raise Exception("Replays not reported")
hwsim_utils.test_connectivity(dev[0], hapd)
time.sleep(0.1)
- before_tk = get_rx_spec(phy, gtk=False).splitlines()
- before_gtk = get_rx_spec(phy, gtk=True).splitlines()
+ before_tk = get_rx_spec(phy, keytype=KT_PTK).splitlines()
+ before_gtk = get_rx_spec(phy, keytype=KT_GTK).splitlines()
addr = dev[0].own_addr()
if "OK" not in hapd.request("RESEND_M3 " + addr):
raise Exception("RESEND_M3 failed")
time.sleep(0.1)
- after_tk = get_rx_spec(phy, gtk=False).splitlines()
- after_gtk = get_rx_spec(phy, gtk=True).splitlines()
+ after_tk = get_rx_spec(phy, keytype=KT_PTK).splitlines()
+ after_gtk = get_rx_spec(phy, keytype=KT_GTK).splitlines()
if "OK" not in hapd.request("RESET_PN " + addr):
raise Exception("RESET_PN failed")
hwsim_utils.test_connectivity(dev[0], hapd)
time.sleep(0.1)
- before_tk = get_rx_spec(phy, gtk=False).splitlines()
- before_gtk = get_rx_spec(phy, gtk=True).splitlines()
+ before_tk = get_rx_spec(phy, keytype=KT_PTK).splitlines()
+ before_gtk = get_rx_spec(phy, keytype=KT_GTK).splitlines()
addr = dev[0].own_addr()
if change_m1_anonce:
if "OK" not in hapd.request("RESEND_M1 " + addr + " change-anonce"):
if "OK" not in hapd.request("RESEND_M3 " + addr):
raise Exception("RESEND_M3 failed")
time.sleep(0.1)
- after_tk = get_rx_spec(phy, gtk=False).splitlines()
- after_gtk = get_rx_spec(phy, gtk=True).splitlines()
+ after_tk = get_rx_spec(phy, keytype=KT_PTK).splitlines()
+ after_gtk = get_rx_spec(phy, keytype=KT_GTK).splitlines()
if "OK" not in hapd.request("RESET_PN " + addr):
raise Exception("RESET_PN failed")
hwsim_utils.test_connectivity(dev[0], hapd)
time.sleep(0.1)
- before = get_rx_spec(phy, gtk=True).splitlines()
+ before = get_rx_spec(phy, keytype=KT_GTK).splitlines()
addr = dev[0].own_addr()
if "OK" not in hapd.request("RESEND_GROUP_M1 " + addr):
raise Exception("RESEND_GROUP_M1 failed")
time.sleep(0.1)
- after = get_rx_spec(phy, gtk=True).splitlines()
+ after = get_rx_spec(phy, keytype=KT_GTK).splitlines()
if "OK" not in hapd.request("RESET_PN " + addr):
raise Exception("RESET_PN failed")