]>
Commit | Line | Data |
---|---|---|
9f46d57f | 1 | # TDLS tests |
538da4f4 | 2 | # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi> |
81266da7 JM |
3 | # |
4 | # This software may be distributed under the terms of the BSD license. | |
5 | # See README for more details. | |
6 | ||
7 | import time | |
81266da7 | 8 | import logging |
c9aa4308 | 9 | logger = logging.getLogger() |
538da4f4 | 10 | import subprocess |
81266da7 JM |
11 | |
12 | import hwsim_utils | |
b8cd4c54 JM |
13 | from hostapd import HostapdGlobal |
14 | from hostapd import Hostapd | |
e259d186 | 15 | import hostapd |
a1eabc74 | 16 | from utils import HwsimSkip, skip_with_fips |
835a546b | 17 | from wlantest import Wlantest |
d386a9ac | 18 | from test_ap_vht import vht_supported |
b8cd4c54 | 19 | |
b8cd4c54 | 20 | def start_ap_wpa2_psk(ifname): |
e259d186 | 21 | params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678") |
a8375c94 | 22 | return hostapd.add_ap(ifname, params) |
0165c4be | 23 | |
a8375c94 | 24 | def connectivity(dev, hapd): |
e492837b | 25 | hwsim_utils.test_connectivity_sta(dev[0], dev[1]) |
a8375c94 JM |
26 | hwsim_utils.test_connectivity(dev[0], hapd) |
27 | hwsim_utils.test_connectivity(dev[1], hapd) | |
e492837b | 28 | |
a8375c94 | 29 | def connect_2sta(dev, ssid, hapd): |
c65f23ab JM |
30 | dev[0].connect(ssid, psk="12345678", scan_freq="2412") |
31 | dev[1].connect(ssid, psk="12345678", scan_freq="2412") | |
a8375c94 | 32 | connectivity(dev, hapd) |
b61e418c | 33 | |
a8375c94 JM |
34 | def connect_2sta_wpa2_psk(dev, hapd): |
35 | connect_2sta(dev, "test-wpa2-psk", hapd) | |
e492837b | 36 | |
a8375c94 JM |
37 | def connect_2sta_wpa_psk(dev, hapd): |
38 | connect_2sta(dev, "test-wpa-psk", hapd) | |
e492837b | 39 | |
a8375c94 | 40 | def connect_2sta_wpa_psk_mixed(dev, hapd): |
c65f23ab JM |
41 | dev[0].connect("test-wpa-mixed-psk", psk="12345678", proto="WPA", |
42 | scan_freq="2412") | |
43 | dev[1].connect("test-wpa-mixed-psk", psk="12345678", proto="WPA2", | |
44 | scan_freq="2412") | |
a8375c94 | 45 | connectivity(dev, hapd) |
0165c4be | 46 | |
a8375c94 | 47 | def connect_2sta_wep(dev, hapd): |
c65f23ab JM |
48 | dev[0].connect("test-wep", key_mgmt="NONE", wep_key0='"hello"', |
49 | scan_freq="2412") | |
50 | dev[1].connect("test-wep", key_mgmt="NONE", wep_key0='"hello"', | |
51 | scan_freq="2412") | |
a8375c94 | 52 | connectivity(dev, hapd) |
0165c4be | 53 | |
8916857d JM |
54 | def connect_2sta_open(dev, hapd, scan_freq="2412"): |
55 | dev[0].connect("test-open", key_mgmt="NONE", scan_freq=scan_freq) | |
56 | dev[1].connect("test-open", key_mgmt="NONE", scan_freq=scan_freq) | |
a8375c94 | 57 | connectivity(dev, hapd) |
81266da7 | 58 | |
81266da7 | 59 | def wlantest_setup(): |
835a546b JM |
60 | wt = Wlantest() |
61 | wt.flush() | |
62 | wt.add_passphrase("12345678") | |
63 | wt.add_wepkey("68656c6c6f") | |
81266da7 | 64 | |
dc4e222c | 65 | def wlantest_tdls_packet_counters(bssid, addr0, addr1): |
835a546b JM |
66 | wt = Wlantest() |
67 | dl = wt.get_tdls_counter("valid_direct_link", bssid, addr0, addr1) | |
68 | inv_dl = wt.get_tdls_counter("invalid_direct_link", bssid, addr0, addr1) | |
69 | ap = wt.get_tdls_counter("valid_ap_path", bssid, addr0, addr1) | |
70 | inv_ap = wt.get_tdls_counter("invalid_ap_path", bssid, addr0, addr1) | |
dc4e222c JM |
71 | return [dl,inv_dl,ap,inv_ap] |
72 | ||
73 | def tdls_check_dl(sta0, sta1, bssid, addr0, addr1): | |
835a546b JM |
74 | wt = Wlantest() |
75 | wt.tdls_clear(bssid, addr0, addr1) | |
dc4e222c JM |
76 | hwsim_utils.test_connectivity_sta(sta0, sta1) |
77 | [dl,inv_dl,ap,inv_ap] = wlantest_tdls_packet_counters(bssid, addr0, addr1) | |
78 | if dl == 0: | |
79 | raise Exception("No valid frames through direct link") | |
80 | if inv_dl > 0: | |
81 | raise Exception("Invalid frames through direct link") | |
82 | if ap > 0: | |
83 | raise Exception("Unexpected frames through AP path") | |
84 | if inv_ap > 0: | |
85 | raise Exception("Invalid frames through AP path") | |
86 | ||
87 | def tdls_check_ap(sta0, sta1, bssid, addr0, addr1): | |
835a546b JM |
88 | wt = Wlantest() |
89 | wt.tdls_clear(bssid, addr0, addr1); | |
dc4e222c JM |
90 | hwsim_utils.test_connectivity_sta(sta0, sta1) |
91 | [dl,inv_dl,ap,inv_ap] = wlantest_tdls_packet_counters(bssid, addr0, addr1) | |
92 | if dl > 0: | |
93 | raise Exception("Unexpected frames through direct link") | |
94 | if inv_dl > 0: | |
95 | raise Exception("Invalid frames through direct link") | |
96 | if ap == 0: | |
97 | raise Exception("No valid frames through AP path") | |
98 | if inv_ap > 0: | |
99 | raise Exception("Invalid frames through AP path") | |
100 | ||
a8375c94 | 101 | def check_connectivity(sta0, sta1, hapd): |
9d86f37f | 102 | hwsim_utils.test_connectivity_sta(sta0, sta1) |
a8375c94 JM |
103 | hwsim_utils.test_connectivity(sta0, hapd) |
104 | hwsim_utils.test_connectivity(sta1, hapd) | |
9d86f37f | 105 | |
c4a8c173 | 106 | def setup_tdls(sta0, sta1, ap, reverse=False, expect_fail=False): |
81266da7 | 107 | logger.info("Setup TDLS") |
a8375c94 JM |
108 | hapd = hostapd.Hostapd(ap['ifname']) |
109 | check_connectivity(sta0, sta1, hapd) | |
ec9589fd | 110 | bssid = ap['bssid'] |
81266da7 JM |
111 | addr0 = sta0.p2p_interface_addr() |
112 | addr1 = sta1.p2p_interface_addr() | |
835a546b JM |
113 | wt = Wlantest() |
114 | wt.tdls_clear(bssid, addr0, addr1); | |
115 | wt.tdls_clear(bssid, addr1, addr0); | |
81266da7 JM |
116 | sta0.tdls_setup(addr1) |
117 | time.sleep(1) | |
a9bdfd49 JM |
118 | if expect_fail: |
119 | tdls_check_ap(sta0, sta1, bssid, addr0, addr1) | |
120 | return | |
81266da7 JM |
121 | if reverse: |
122 | addr1 = sta0.p2p_interface_addr() | |
123 | addr0 = sta1.p2p_interface_addr() | |
c4a8c173 | 124 | conf = wt.get_tdls_counter("setup_conf_ok", bssid, addr0, addr1); |
81266da7 JM |
125 | if conf == 0: |
126 | raise Exception("No TDLS Setup Confirm (success) seen") | |
dc4e222c | 127 | tdls_check_dl(sta0, sta1, bssid, addr0, addr1) |
a8375c94 | 128 | check_connectivity(sta0, sta1, hapd) |
81266da7 | 129 | |
7fd5fd03 | 130 | def teardown_tdls(sta0, sta1, ap, responder=False, wildcard=False): |
81266da7 | 131 | logger.info("Teardown TDLS") |
a8375c94 JM |
132 | hapd = hostapd.Hostapd(ap['ifname']) |
133 | check_connectivity(sta0, sta1, hapd) | |
ec9589fd | 134 | bssid = ap['bssid'] |
81266da7 JM |
135 | addr0 = sta0.p2p_interface_addr() |
136 | addr1 = sta1.p2p_interface_addr() | |
77835ae9 AN |
137 | if responder: |
138 | sta1.tdls_teardown(addr0) | |
7fd5fd03 JM |
139 | elif wildcard: |
140 | sta0.tdls_teardown("*") | |
77835ae9 AN |
141 | else: |
142 | sta0.tdls_teardown(addr1) | |
81266da7 | 143 | time.sleep(1) |
835a546b JM |
144 | wt = Wlantest() |
145 | teardown = wt.get_tdls_counter("teardown", bssid, addr0, addr1); | |
81266da7 JM |
146 | if teardown == 0: |
147 | raise Exception("No TDLS Setup Teardown seen") | |
dc4e222c | 148 | tdls_check_ap(sta0, sta1, bssid, addr0, addr1) |
a8375c94 | 149 | check_connectivity(sta0, sta1, hapd) |
81266da7 | 150 | |
2380d804 OG |
151 | def check_tdls_link(sta0, sta1, connected=True): |
152 | addr0 = sta0.own_addr() | |
153 | addr1 = sta1.own_addr() | |
154 | status0 = sta0.tdls_link_status(addr1).rstrip() | |
155 | status1 = sta1.tdls_link_status(addr0).rstrip() | |
156 | logger.info("%s: %s" % (sta0.ifname, status0)) | |
157 | logger.info("%s: %s" % (sta1.ifname, status1)) | |
158 | if status0 != status1: | |
159 | raise Exception("TDLS link status differs between stations") | |
160 | if "status: connected" in status0: | |
161 | if not connected: | |
162 | raise Exception("Expected TDLS link status NOT to be connected") | |
163 | else: | |
164 | if connected: | |
165 | raise Exception("Expected TDLS link status to be connected") | |
166 | ||
77b4a711 JM |
167 | def test_ap_tdls_discovery(dev, apdev): |
168 | """WPA2-PSK AP and two stations using TDLS discovery""" | |
a8375c94 | 169 | hapd = start_ap_wpa2_psk(apdev[0]['ifname']) |
77b4a711 | 170 | wlantest_setup() |
a8375c94 | 171 | connect_2sta_wpa2_psk(dev, hapd) |
77b4a711 JM |
172 | dev[0].request("TDLS_DISCOVER " + dev[1].p2p_interface_addr()) |
173 | time.sleep(0.2) | |
174 | ||
ae3ad328 | 175 | def test_ap_wpa2_tdls(dev, apdev): |
81266da7 | 176 | """WPA2-PSK AP and two stations using TDLS""" |
a8375c94 | 177 | hapd = start_ap_wpa2_psk(apdev[0]['ifname']) |
81266da7 | 178 | wlantest_setup() |
a8375c94 | 179 | connect_2sta_wpa2_psk(dev, hapd) |
ec9589fd JM |
180 | setup_tdls(dev[0], dev[1], apdev[0]) |
181 | teardown_tdls(dev[0], dev[1], apdev[0]) | |
182 | setup_tdls(dev[1], dev[0], apdev[0]) | |
183 | #teardown_tdls(dev[0], dev[1], apdev[0]) | |
81266da7 | 184 | |
ae3ad328 | 185 | def test_ap_wpa2_tdls_concurrent_init(dev, apdev): |
81266da7 | 186 | """Concurrent TDLS setup initiation""" |
a8375c94 | 187 | hapd = start_ap_wpa2_psk(apdev[0]['ifname']) |
81266da7 | 188 | wlantest_setup() |
a8375c94 | 189 | connect_2sta_wpa2_psk(dev, hapd) |
81266da7 | 190 | dev[0].request("SET tdls_testing 0x80") |
c4a8c173 | 191 | setup_tdls(dev[1], dev[0], apdev[0], reverse=True) |
81266da7 | 192 | |
ae3ad328 | 193 | def test_ap_wpa2_tdls_concurrent_init2(dev, apdev): |
81266da7 | 194 | """Concurrent TDLS setup initiation (reverse)""" |
a8375c94 | 195 | hapd = start_ap_wpa2_psk(apdev[0]['ifname']) |
81266da7 | 196 | wlantest_setup() |
a8375c94 | 197 | connect_2sta_wpa2_psk(dev, hapd) |
81266da7 | 198 | dev[1].request("SET tdls_testing 0x80") |
ec9589fd | 199 | setup_tdls(dev[0], dev[1], apdev[0]) |
81266da7 | 200 | |
ae3ad328 | 201 | def test_ap_wpa2_tdls_decline_resp(dev, apdev): |
a9bdfd49 | 202 | """Decline TDLS Setup Response""" |
a8375c94 | 203 | hapd = start_ap_wpa2_psk(apdev[0]['ifname']) |
a9bdfd49 | 204 | wlantest_setup() |
a8375c94 | 205 | connect_2sta_wpa2_psk(dev, hapd) |
a9bdfd49 | 206 | dev[1].request("SET tdls_testing 0x200") |
ec9589fd | 207 | setup_tdls(dev[1], dev[0], apdev[0], expect_fail=True) |
a9bdfd49 | 208 | |
ae3ad328 | 209 | def test_ap_wpa2_tdls_long_lifetime(dev, apdev): |
a9bdfd49 | 210 | """TDLS with long TPK lifetime""" |
a8375c94 | 211 | hapd = start_ap_wpa2_psk(apdev[0]['ifname']) |
a9bdfd49 | 212 | wlantest_setup() |
a8375c94 | 213 | connect_2sta_wpa2_psk(dev, hapd) |
a9bdfd49 | 214 | dev[1].request("SET tdls_testing 0x40") |
ec9589fd | 215 | setup_tdls(dev[1], dev[0], apdev[0]) |
a9bdfd49 | 216 | |
ae3ad328 | 217 | def test_ap_wpa2_tdls_long_frame(dev, apdev): |
a9bdfd49 | 218 | """TDLS with long setup/teardown frames""" |
a8375c94 | 219 | hapd = start_ap_wpa2_psk(apdev[0]['ifname']) |
a9bdfd49 | 220 | wlantest_setup() |
a8375c94 | 221 | connect_2sta_wpa2_psk(dev, hapd) |
a9bdfd49 JM |
222 | dev[0].request("SET tdls_testing 0x1") |
223 | dev[1].request("SET tdls_testing 0x1") | |
ec9589fd JM |
224 | setup_tdls(dev[1], dev[0], apdev[0]) |
225 | teardown_tdls(dev[1], dev[0], apdev[0]) | |
226 | setup_tdls(dev[0], dev[1], apdev[0]) | |
a9bdfd49 | 227 | |
ae3ad328 | 228 | def test_ap_wpa2_tdls_reneg(dev, apdev): |
a9bdfd49 | 229 | """Renegotiate TDLS link""" |
a8375c94 | 230 | hapd = start_ap_wpa2_psk(apdev[0]['ifname']) |
a9bdfd49 | 231 | wlantest_setup() |
a8375c94 | 232 | connect_2sta_wpa2_psk(dev, hapd) |
ec9589fd JM |
233 | setup_tdls(dev[1], dev[0], apdev[0]) |
234 | setup_tdls(dev[0], dev[1], apdev[0]) | |
a9bdfd49 | 235 | |
ae3ad328 | 236 | def test_ap_wpa2_tdls_wrong_lifetime_resp(dev, apdev): |
a9bdfd49 | 237 | """Incorrect TPK lifetime in TDLS Setup Response""" |
a8375c94 | 238 | hapd = start_ap_wpa2_psk(apdev[0]['ifname']) |
a9bdfd49 | 239 | wlantest_setup() |
a8375c94 | 240 | connect_2sta_wpa2_psk(dev, hapd) |
a9bdfd49 | 241 | dev[1].request("SET tdls_testing 0x10") |
ec9589fd | 242 | setup_tdls(dev[0], dev[1], apdev[0], expect_fail=True) |
a9bdfd49 | 243 | |
ae3ad328 | 244 | def test_ap_wpa2_tdls_diff_rsnie(dev, apdev): |
a9bdfd49 | 245 | """TDLS with different RSN IEs""" |
a8375c94 | 246 | hapd = start_ap_wpa2_psk(apdev[0]['ifname']) |
a9bdfd49 | 247 | wlantest_setup() |
a8375c94 | 248 | connect_2sta_wpa2_psk(dev, hapd) |
a9bdfd49 | 249 | dev[1].request("SET tdls_testing 0x2") |
ec9589fd JM |
250 | setup_tdls(dev[1], dev[0], apdev[0]) |
251 | teardown_tdls(dev[1], dev[0], apdev[0]) | |
a9bdfd49 | 252 | |
67935bc3 JM |
253 | def test_ap_wpa2_tdls_wrong_tpk_m2_mic(dev, apdev): |
254 | """Incorrect MIC in TDLS Setup Response""" | |
a8375c94 | 255 | hapd = start_ap_wpa2_psk(apdev[0]['ifname']) |
67935bc3 | 256 | wlantest_setup() |
a8375c94 | 257 | connect_2sta_wpa2_psk(dev, hapd) |
67935bc3 JM |
258 | dev[0].request("SET tdls_testing 0x800") |
259 | addr0 = dev[0].p2p_interface_addr() | |
260 | dev[1].tdls_setup(addr0) | |
261 | time.sleep(1) | |
262 | ||
263 | def test_ap_wpa2_tdls_wrong_tpk_m3_mic(dev, apdev): | |
264 | """Incorrect MIC in TDLS Setup Confirm""" | |
a8375c94 | 265 | hapd = start_ap_wpa2_psk(apdev[0]['ifname']) |
67935bc3 | 266 | wlantest_setup() |
a8375c94 | 267 | connect_2sta_wpa2_psk(dev, hapd) |
67935bc3 JM |
268 | dev[1].request("SET tdls_testing 0x800") |
269 | addr0 = dev[0].p2p_interface_addr() | |
270 | dev[1].tdls_setup(addr0) | |
271 | time.sleep(1) | |
272 | ||
ae3ad328 | 273 | def test_ap_wpa_tdls(dev, apdev): |
e492837b | 274 | """WPA-PSK AP and two stations using TDLS""" |
a1eabc74 | 275 | skip_with_fips(dev[0]) |
8b8a1864 | 276 | hapd = hostapd.add_ap(apdev[0], |
a8375c94 JM |
277 | hostapd.wpa_params(ssid="test-wpa-psk", |
278 | passphrase="12345678")) | |
e492837b | 279 | wlantest_setup() |
a8375c94 | 280 | connect_2sta_wpa_psk(dev, hapd) |
ec9589fd JM |
281 | setup_tdls(dev[0], dev[1], apdev[0]) |
282 | teardown_tdls(dev[0], dev[1], apdev[0]) | |
283 | setup_tdls(dev[1], dev[0], apdev[0]) | |
e492837b | 284 | |
ae3ad328 | 285 | def test_ap_wpa_mixed_tdls(dev, apdev): |
e492837b | 286 | """WPA+WPA2-PSK AP and two stations using TDLS""" |
a1eabc74 | 287 | skip_with_fips(dev[0]) |
8b8a1864 | 288 | hapd = hostapd.add_ap(apdev[0], |
a8375c94 JM |
289 | hostapd.wpa_mixed_params(ssid="test-wpa-mixed-psk", |
290 | passphrase="12345678")) | |
e492837b | 291 | wlantest_setup() |
a8375c94 | 292 | connect_2sta_wpa_psk_mixed(dev, hapd) |
ec9589fd JM |
293 | setup_tdls(dev[0], dev[1], apdev[0]) |
294 | teardown_tdls(dev[0], dev[1], apdev[0]) | |
295 | setup_tdls(dev[1], dev[0], apdev[0]) | |
e492837b | 296 | |
ae3ad328 | 297 | def test_ap_wep_tdls(dev, apdev): |
0165c4be | 298 | """WEP AP and two stations using TDLS""" |
8b8a1864 | 299 | hapd = hostapd.add_ap(apdev[0], |
a8375c94 | 300 | { "ssid": "test-wep", "wep_key0": '"hello"' }) |
0165c4be | 301 | wlantest_setup() |
a8375c94 | 302 | connect_2sta_wep(dev, hapd) |
ec9589fd JM |
303 | setup_tdls(dev[0], dev[1], apdev[0]) |
304 | teardown_tdls(dev[0], dev[1], apdev[0]) | |
305 | setup_tdls(dev[1], dev[0], apdev[0]) | |
0165c4be | 306 | |
ae3ad328 | 307 | def test_ap_open_tdls(dev, apdev): |
0165c4be | 308 | """Open AP and two stations using TDLS""" |
8b8a1864 | 309 | hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" }) |
0165c4be | 310 | wlantest_setup() |
a8375c94 | 311 | connect_2sta_open(dev, hapd) |
ec9589fd JM |
312 | setup_tdls(dev[0], dev[1], apdev[0]) |
313 | teardown_tdls(dev[0], dev[1], apdev[0]) | |
314 | setup_tdls(dev[1], dev[0], apdev[0]) | |
7fd5fd03 | 315 | teardown_tdls(dev[1], dev[0], apdev[0], wildcard=True) |
538da4f4 JM |
316 | |
317 | def test_ap_wpa2_tdls_bssid_mismatch(dev, apdev): | |
318 | """TDLS failure due to BSSID mismatch""" | |
319 | try: | |
320 | ssid = "test-wpa2-psk" | |
321 | passphrase = "12345678" | |
322 | params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase) | |
323 | params['bridge'] = 'ap-br0' | |
8b8a1864 JD |
324 | hapd = hostapd.add_ap(apdev[0], params) |
325 | hostapd.add_ap(apdev[1], params) | |
538da4f4 | 326 | wlantest_setup() |
c4668009 JM |
327 | subprocess.call(['brctl', 'setfd', 'ap-br0', '0']) |
328 | subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up']) | |
538da4f4 JM |
329 | dev[0].connect(ssid, psk=passphrase, scan_freq="2412", |
330 | bssid=apdev[0]['bssid']) | |
331 | dev[1].connect(ssid, psk=passphrase, scan_freq="2412", | |
332 | bssid=apdev[1]['bssid']) | |
a8375c94 | 333 | hwsim_utils.test_connectivity_sta(dev[0], dev[1]) |
1131a1c8 JM |
334 | hwsim_utils.test_connectivity_iface(dev[0], hapd, "ap-br0") |
335 | hwsim_utils.test_connectivity_iface(dev[1], hapd, "ap-br0") | |
a8375c94 | 336 | |
538da4f4 JM |
337 | addr0 = dev[0].p2p_interface_addr() |
338 | dev[1].tdls_setup(addr0) | |
339 | time.sleep(1) | |
340 | hwsim_utils.test_connectivity_sta(dev[0], dev[1]) | |
341 | finally: | |
c4668009 JM |
342 | subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down']) |
343 | subprocess.call(['brctl', 'delbr', 'ap-br0']) | |
77835ae9 AN |
344 | |
345 | def test_ap_wpa2_tdls_responder_teardown(dev, apdev): | |
346 | """TDLS teardown from responder with WPA2-PSK AP""" | |
a8375c94 | 347 | hapd = start_ap_wpa2_psk(apdev[0]['ifname']) |
77835ae9 | 348 | wlantest_setup() |
a8375c94 | 349 | connect_2sta_wpa2_psk(dev, hapd) |
77835ae9 AN |
350 | setup_tdls(dev[0], dev[1], apdev[0]) |
351 | teardown_tdls(dev[0], dev[1], apdev[0], responder=True) | |
8916857d JM |
352 | |
353 | def test_ap_open_tdls_vht(dev, apdev): | |
354 | """Open AP and two stations using TDLS""" | |
355 | params = { "ssid": "test-open", | |
356 | "country_code": "DE", | |
357 | "hw_mode": "a", | |
358 | "channel": "36", | |
359 | "ieee80211n": "1", | |
360 | "ieee80211ac": "1", | |
361 | "ht_capab": "", | |
362 | "vht_capab": "", | |
363 | "vht_oper_chwidth": "0", | |
364 | "vht_oper_centr_freq_seg0_idx": "0" } | |
365 | try: | |
8b8a1864 | 366 | hapd = hostapd.add_ap(apdev[0], params) |
8916857d JM |
367 | wlantest_setup() |
368 | connect_2sta_open(dev, hapd, scan_freq="5180") | |
369 | setup_tdls(dev[0], dev[1], apdev[0]) | |
370 | teardown_tdls(dev[0], dev[1], apdev[0]) | |
371 | setup_tdls(dev[1], dev[0], apdev[0]) | |
372 | teardown_tdls(dev[1], dev[0], apdev[0], wildcard=True) | |
373 | finally: | |
374 | dev[0].request("DISCONNECT") | |
375 | dev[1].request("DISCONNECT") | |
376 | if hapd: | |
377 | hapd.request("DISABLE") | |
c4668009 | 378 | subprocess.call(['iw', 'reg', 'set', '00']) |
8916857d JM |
379 | dev[0].flush_scan_cache() |
380 | dev[1].flush_scan_cache() | |
5434f07c | 381 | |
d386a9ac JM |
382 | def test_ap_open_tdls_vht80(dev, apdev): |
383 | """Open AP and two stations using TDLS with VHT 80""" | |
384 | params = { "ssid": "test-open", | |
385 | "country_code": "US", | |
386 | "hw_mode": "a", | |
387 | "channel": "36", | |
388 | "ht_capab": "[HT40+]", | |
389 | "ieee80211n": "1", | |
390 | "ieee80211ac": "1", | |
391 | "vht_capab": "", | |
392 | "vht_oper_chwidth": "1", | |
393 | "vht_oper_centr_freq_seg0_idx": "42" } | |
394 | try: | |
395 | hapd = None | |
8b8a1864 | 396 | hapd = hostapd.add_ap(apdev[0], params) |
d386a9ac JM |
397 | wlantest_setup() |
398 | connect_2sta_open(dev, hapd, scan_freq="5180") | |
399 | sig = dev[0].request("SIGNAL_POLL").splitlines() | |
400 | if "WIDTH=80 MHz" not in sig: | |
401 | raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig)) | |
402 | setup_tdls(dev[0], dev[1], apdev[0]) | |
403 | for i in range(10): | |
404 | check_connectivity(dev[0], dev[1], hapd) | |
405 | for i in range(2): | |
406 | cmd = subprocess.Popen(['iw', dev[0].ifname, 'station', 'dump'], | |
407 | stdout=subprocess.PIPE) | |
408 | res = cmd.stdout.read() | |
409 | cmd.stdout.close() | |
410 | logger.info("Station dump on dev[%d]:\n%s" % (i, res)) | |
411 | except Exception, e: | |
412 | if isinstance(e, Exception) and str(e) == "AP startup failed": | |
413 | if not vht_supported(): | |
414 | raise HwsimSkip("80/160 MHz channel not supported in regulatory information") | |
415 | raise | |
416 | finally: | |
417 | dev[0].request("DISCONNECT") | |
418 | dev[1].request("DISCONNECT") | |
419 | if hapd: | |
420 | hapd.request("DISABLE") | |
421 | subprocess.call(['iw', 'reg', 'set', '00']) | |
422 | dev[0].flush_scan_cache() | |
423 | dev[1].flush_scan_cache() | |
424 | ||
425 | def test_ap_open_tdls_vht80plus80(dev, apdev): | |
426 | """Open AP and two stations using TDLS with VHT 80+80""" | |
427 | params = { "ssid": "test-open", | |
428 | "country_code": "US", | |
429 | "hw_mode": "a", | |
430 | "channel": "36", | |
431 | "ht_capab": "[HT40+]", | |
432 | "ieee80211n": "1", | |
433 | "ieee80211ac": "1", | |
434 | "vht_capab": "", | |
435 | "vht_oper_chwidth": "3", | |
436 | "vht_oper_centr_freq_seg0_idx": "42", | |
437 | "vht_oper_centr_freq_seg1_idx": "155" } | |
438 | try: | |
439 | hapd = None | |
8b8a1864 | 440 | hapd = hostapd.add_ap(apdev[0], params) |
d386a9ac JM |
441 | wlantest_setup() |
442 | connect_2sta_open(dev, hapd, scan_freq="5180") | |
443 | sig = dev[0].request("SIGNAL_POLL").splitlines() | |
444 | if "FREQUENCY=5180" not in sig: | |
445 | raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig)) | |
446 | if "WIDTH=80+80 MHz" not in sig: | |
447 | raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig)) | |
448 | if "CENTER_FRQ1=5210" not in sig: | |
449 | raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig)) | |
450 | if "CENTER_FRQ2=5775" not in sig: | |
451 | raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig)) | |
452 | setup_tdls(dev[0], dev[1], apdev[0]) | |
453 | for i in range(10): | |
454 | check_connectivity(dev[0], dev[1], hapd) | |
455 | for i in range(2): | |
456 | cmd = subprocess.Popen(['iw', dev[0].ifname, 'station', 'dump'], | |
457 | stdout=subprocess.PIPE) | |
458 | res = cmd.stdout.read() | |
459 | cmd.stdout.close() | |
460 | logger.info("Station dump on dev[%d]:\n%s" % (i, res)) | |
461 | except Exception, e: | |
462 | if isinstance(e, Exception) and str(e) == "AP startup failed": | |
463 | if not vht_supported(): | |
464 | raise HwsimSkip("80/160 MHz channel not supported in regulatory information") | |
465 | raise | |
466 | finally: | |
467 | dev[0].request("DISCONNECT") | |
468 | dev[1].request("DISCONNECT") | |
469 | if hapd: | |
470 | hapd.request("DISABLE") | |
471 | subprocess.call(['iw', 'reg', 'set', '00']) | |
472 | dev[0].flush_scan_cache() | |
473 | dev[1].flush_scan_cache() | |
474 | ||
475 | def test_ap_open_tdls_vht160(dev, apdev): | |
476 | """Open AP and two stations using TDLS with VHT 160""" | |
477 | params = { "ssid": "test-open", | |
478 | "country_code": "ZA", | |
479 | "hw_mode": "a", | |
480 | "channel": "104", | |
481 | "ht_capab": "[HT40-]", | |
482 | "ieee80211n": "1", | |
483 | "ieee80211ac": "1", | |
484 | "vht_oper_chwidth": "2", | |
485 | "vht_oper_centr_freq_seg0_idx": "114" } | |
486 | try: | |
487 | hapd = None | |
8b8a1864 | 488 | hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False) |
d386a9ac JM |
489 | ev = hapd.wait_event(["AP-ENABLED"], timeout=2) |
490 | if not ev: | |
491 | cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE) | |
492 | reg = cmd.stdout.readlines() | |
493 | for r in reg: | |
494 | if "5490" in r and "DFS" in r: | |
495 | raise HwsimSkip("ZA regulatory rule did not have DFS requirement removed") | |
496 | raise Exception("AP setup timed out") | |
497 | wlantest_setup() | |
498 | connect_2sta_open(dev, hapd, scan_freq="5520") | |
499 | sig = dev[0].request("SIGNAL_POLL").splitlines() | |
500 | if "WIDTH=160 MHz" not in sig: | |
501 | raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig)) | |
502 | setup_tdls(dev[0], dev[1], apdev[0]) | |
503 | for i in range(10): | |
504 | check_connectivity(dev[0], dev[1], hapd) | |
505 | for i in range(2): | |
506 | cmd = subprocess.Popen(['iw', dev[0].ifname, 'station', 'dump'], | |
507 | stdout=subprocess.PIPE) | |
508 | res = cmd.stdout.read() | |
509 | cmd.stdout.close() | |
510 | logger.info("Station dump on dev[%d]:\n%s" % (i, res)) | |
511 | except Exception, e: | |
512 | if isinstance(e, Exception) and str(e) == "AP startup failed": | |
513 | if not vht_supported(): | |
514 | raise HwsimSkip("80/160 MHz channel not supported in regulatory information") | |
515 | raise | |
516 | finally: | |
517 | dev[0].request("DISCONNECT") | |
518 | dev[1].request("DISCONNECT") | |
519 | if hapd: | |
520 | hapd.request("DISABLE") | |
521 | subprocess.call(['iw', 'reg', 'set', '00']) | |
522 | dev[0].flush_scan_cache() | |
523 | dev[1].flush_scan_cache() | |
524 | ||
5434f07c JM |
525 | def test_tdls_chan_switch(dev, apdev): |
526 | """Open AP and two stations using TDLS""" | |
527 | flags = int(dev[0].get_driver_status_field('capa.flags'), 16) | |
528 | if flags & 0x800000000 == 0: | |
81e787b7 | 529 | raise HwsimSkip("Driver does not support TDLS channel switching") |
5434f07c | 530 | |
8b8a1864 | 531 | hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" }) |
5434f07c JM |
532 | connect_2sta_open(dev, hapd) |
533 | setup_tdls(dev[0], dev[1], apdev[0]) | |
534 | if "OK" not in dev[0].request("TDLS_CHAN_SWITCH " + dev[1].own_addr() + " 81 2462"): | |
535 | raise Exception("Failed to enable TDLS channel switching") | |
536 | if "OK" not in dev[0].request("TDLS_CANCEL_CHAN_SWITCH " + dev[1].own_addr()): | |
537 | raise Exception("Could not disable TDLS channel switching") | |
538 | if "FAIL" not in dev[0].request("TDLS_CANCEL_CHAN_SWITCH " + dev[1].own_addr()): | |
539 | raise Exception("TDLS_CANCEL_CHAN_SWITCH accepted even though channel switching was already disabled") | |
2380d804 OG |
540 | |
541 | def test_ap_tdls_link_status(dev, apdev): | |
542 | """Check TDLS link status between two stations""" | |
543 | hapd = start_ap_wpa2_psk(apdev[0]['ifname']) | |
544 | wlantest_setup() | |
545 | connect_2sta_wpa2_psk(dev, hapd) | |
546 | check_tdls_link(dev[0], dev[1], connected=False) | |
547 | setup_tdls(dev[0], dev[1], apdev[0]) | |
548 | check_tdls_link(dev[0], dev[1], connected=True) | |
549 | teardown_tdls(dev[0], dev[1], apdev[0]) | |
550 | check_tdls_link(dev[0], dev[1], connected=False) | |
551 | if "FAIL" not in dev[0].request("TDLS_LINK_STATUS foo"): | |
552 | raise Exception("Unexpected TDLS_LINK_STATUS response for invalid argument") |