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