]> git.ipfire.org Git - thirdparty/hostap.git/blame - tests/hwsim/test_wnm.py
WNM: Fix deinit path to clean neighbor report count
[thirdparty/hostap.git] / tests / hwsim / test_wnm.py
CommitLineData
6435799b
JM
1# WNM tests
2# Copyright (c) 2013, 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
7import time
8import logging
9logger = logging.getLogger()
10
11import hostapd
b2edaa43 12from wlantest import Wlantest
6435799b
JM
13
14def test_wnm_bss_transition_mgmt(dev, apdev):
15 """WNM BSS Transition Management"""
16 params = { "ssid": "test-wnm",
17 "time_advertisement": "2",
18 "time_zone": "EST5",
19 "wnm_sleep_mode": "1",
20 "bss_transition": "1" }
21 hostapd.add_ap(apdev[0]['ifname'], params)
22
23 dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412")
24 dev[0].request("WNM_BSS_QUERY 0")
25
26def test_wnm_disassoc_imminent(dev, apdev):
27 """WNM Disassociation Imminent"""
28 params = { "ssid": "test-wnm",
29 "time_advertisement": "2",
30 "time_zone": "EST5",
31 "wnm_sleep_mode": "1",
32 "bss_transition": "1" }
33 hostapd.add_ap(apdev[0]['ifname'], params)
34 hapd = hostapd.Hostapd(apdev[0]['ifname'])
35
36 dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412")
37 addr = dev[0].p2p_interface_addr()
38 hapd.request("DISASSOC_IMMINENT " + addr + " 10")
39 ev = dev[0].wait_event(["WNM: Disassociation Imminent"])
40 if ev is None:
41 raise Exception("Timeout while waiting for disassociation imminent")
42 if "Disassociation Timer 10" not in ev:
43 raise Exception("Unexpected disassociation imminent contents")
44 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
45 if ev is None:
46 raise Exception("Timeout while waiting for re-connection scan")
47
48def test_wnm_ess_disassoc_imminent(dev, apdev):
49 """WNM ESS Disassociation Imminent"""
50 params = { "ssid": "test-wnm",
51 "time_advertisement": "2",
52 "time_zone": "EST5",
53 "wnm_sleep_mode": "1",
54 "bss_transition": "1" }
55 hostapd.add_ap(apdev[0]['ifname'], params)
56 hapd = hostapd.Hostapd(apdev[0]['ifname'])
57
58 dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412")
59 addr = dev[0].p2p_interface_addr()
60 hapd.request("ESS_DISASSOC " + addr + " 10 http://example.com/session-info")
61 ev = dev[0].wait_event(["ESS-DISASSOC-IMMINENT"])
62 if ev is None:
63 raise Exception("Timeout while waiting for ESS disassociation imminent")
64 if "0 1024 http://example.com/session-info" not in ev:
65 raise Exception("Unexpected ESS disassociation imminent message contents")
66 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
67 if ev is None:
68 raise Exception("Timeout while waiting for re-connection scan")
69
70def test_wnm_ess_disassoc_imminent_pmf(dev, apdev):
71 """WNM ESS Disassociation Imminent"""
72 params = hostapd.wpa2_params("test-wnm-rsn", "12345678")
73 params["wpa_key_mgmt"] = "WPA-PSK-SHA256";
74 params["ieee80211w"] = "2";
75 params["bss_transition"] = "1"
76 hostapd.add_ap(apdev[0]['ifname'], params)
77 hapd = hostapd.Hostapd(apdev[0]['ifname'])
78
79 dev[0].connect("test-wnm-rsn", psk="12345678", ieee80211w="2",
80 key_mgmt="WPA-PSK-SHA256", proto="WPA2", scan_freq="2412")
81 addr = dev[0].p2p_interface_addr()
82 hapd.request("ESS_DISASSOC " + addr + " 10 http://example.com/session-info")
83 ev = dev[0].wait_event(["ESS-DISASSOC-IMMINENT"])
84 if ev is None:
85 raise Exception("Timeout while waiting for ESS disassociation imminent")
86 if "1 1024 http://example.com/session-info" not in ev:
87 raise Exception("Unexpected ESS disassociation imminent message contents")
88 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"])
89 if ev is None:
90 raise Exception("Timeout while waiting for re-connection scan")
91
92def check_wnm_sleep_mode_enter_exit(hapd, dev):
93 addr = dev.p2p_interface_addr()
94 sta = hapd.get_sta(addr)
95 if "[WNM_SLEEP_MODE]" in sta['flags']:
96 raise Exception("Station unexpectedly in WNM-Sleep Mode")
97 logger.info("Going to WNM Sleep Mode")
98 dev.request("WNM_SLEEP enter")
99 time.sleep(0.5)
100 sta = hapd.get_sta(addr)
101 if "[WNM_SLEEP_MODE]" not in sta['flags']:
102 raise Exception("Station failed to enter WNM-Sleep Mode")
103 logger.info("Waking up from WNM Sleep Mode")
104 dev.request("WNM_SLEEP exit")
105 time.sleep(0.5)
106 sta = hapd.get_sta(addr)
107 if "[WNM_SLEEP_MODE]" in sta['flags']:
108 raise Exception("Station failed to exit WNM-Sleep Mode")
109
110def test_wnm_sleep_mode_open(dev, apdev):
111 """WNM Sleep Mode - open"""
112 params = { "ssid": "test-wnm",
113 "time_advertisement": "2",
114 "time_zone": "EST5",
115 "wnm_sleep_mode": "1",
116 "bss_transition": "1" }
117 hostapd.add_ap(apdev[0]['ifname'], params)
118 hapd = hostapd.Hostapd(apdev[0]['ifname'])
119
120 dev[0].connect("test-wnm", key_mgmt="NONE", scan_freq="2412")
121 check_wnm_sleep_mode_enter_exit(hapd, dev[0])
122
123def test_wnm_sleep_mode_rsn(dev, apdev):
124 """WNM Sleep Mode - RSN"""
125 params = hostapd.wpa2_params("test-wnm-rsn", "12345678")
126 params["time_advertisement"] = "2"
127 params["time_zone"] = "EST5"
128 params["wnm_sleep_mode"] = "1"
129 params["bss_transition"] = "1"
130 hostapd.add_ap(apdev[0]['ifname'], params)
131 hapd = hostapd.Hostapd(apdev[0]['ifname'])
132
133 dev[0].connect("test-wnm-rsn", psk="12345678", scan_freq="2412")
134 check_wnm_sleep_mode_enter_exit(hapd, dev[0])
135
136def test_wnm_sleep_mode_rsn_pmf(dev, apdev):
137 """WNM Sleep Mode - RSN with PMF"""
b2edaa43
JM
138 wt = Wlantest()
139 wt.flush()
140 wt.add_passphrase("12345678")
6435799b
JM
141 params = hostapd.wpa2_params("test-wnm-rsn", "12345678")
142 params["wpa_key_mgmt"] = "WPA-PSK-SHA256";
143 params["ieee80211w"] = "2";
144 params["time_advertisement"] = "2"
145 params["time_zone"] = "EST5"
146 params["wnm_sleep_mode"] = "1"
147 params["bss_transition"] = "1"
148 hostapd.add_ap(apdev[0]['ifname'], params)
149 hapd = hostapd.Hostapd(apdev[0]['ifname'])
150
151 dev[0].connect("test-wnm-rsn", psk="12345678", ieee80211w="2",
152 key_mgmt="WPA-PSK-SHA256", proto="WPA2", scan_freq="2412")
153 check_wnm_sleep_mode_enter_exit(hapd, dev[0])