1 # hostapd control interface
2 # Copyright (c) 2014, Qualcomm Atheros, Inc.
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
7 from remotehost import remote_compatible
10 from utils import skip_with_fips
13 def test_hapd_ctrl_status(dev, apdev):
14 """hostapd ctrl_iface STATUS commands"""
16 bssid = apdev[0]['bssid']
17 params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
18 hapd = hostapd.add_ap(apdev[0], params)
19 status = hapd.get_status()
20 driver = hapd.get_driver_status()
22 if status['bss[0]'] != apdev[0]['ifname']:
23 raise Exception("Unexpected bss[0]")
24 if status['ssid[0]'] != ssid:
25 raise Exception("Unexpected ssid[0]")
26 if status['bssid[0]'] != bssid:
27 raise Exception("Unexpected bssid[0]")
28 if status['freq'] != "2412":
29 raise Exception("Unexpected freq")
31 if driver['beacon_set'] != "1":
32 raise Exception("Unexpected beacon_set")
33 if driver['addr'] != bssid:
34 raise Exception("Unexpected addr")
37 def test_hapd_ctrl_p2p_manager(dev, apdev):
38 """hostapd as P2P Device manager"""
40 passphrase = "12345678"
41 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
42 params['manage_p2p'] = '1'
43 params['allow_cross_connection'] = '0'
44 hapd = hostapd.add_ap(apdev[0], params)
45 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
46 addr = dev[0].own_addr()
47 if "OK" not in hapd.request("DEAUTHENTICATE " + addr + " p2p=2"):
48 raise Exception("DEAUTHENTICATE command failed")
49 dev[0].wait_disconnected(timeout=5)
50 dev[0].wait_connected(timeout=10, error="Re-connection timed out")
52 if "OK" not in hapd.request("DISASSOCIATE " + addr + " p2p=2"):
53 raise Exception("DISASSOCIATE command failed")
54 dev[0].wait_disconnected(timeout=5)
55 dev[0].wait_connected(timeout=10, error="Re-connection timed out")
58 def test_hapd_ctrl_sta(dev, apdev):
59 """hostapd and STA ctrl_iface commands"""
60 ssid = "hapd-ctrl-sta"
61 passphrase = "12345678"
62 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
63 hapd = hostapd.add_ap(apdev[0], params)
64 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
65 addr = dev[0].own_addr()
66 if "FAIL" in hapd.request("STA " + addr):
67 raise Exception("Unexpected STA failure")
68 if "FAIL" not in hapd.request("STA " + addr + " eapol"):
69 raise Exception("Unexpected STA-eapol success")
70 if "FAIL" not in hapd.request("STA 00:11:22:33:44"):
71 raise Exception("Unexpected STA success")
72 if "FAIL" not in hapd.request("STA 00:11:22:33:44:55"):
73 raise Exception("Unexpected STA success")
75 if len(hapd.request("STA-NEXT " + addr).splitlines()) > 0:
76 raise Exception("Unexpected STA-NEXT result")
77 if "FAIL" not in hapd.request("STA-NEXT 00:11:22:33:44"):
78 raise Exception("Unexpected STA-NEXT success")
81 def test_hapd_ctrl_disconnect(dev, apdev):
82 """hostapd and disconnection ctrl_iface commands"""
84 passphrase = "12345678"
85 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
86 hapd = hostapd.add_ap(apdev[0], params)
87 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
88 addr = dev[0].p2p_dev_addr()
90 if "FAIL" not in hapd.request("DEAUTHENTICATE 00:11:22:33:44"):
91 raise Exception("Unexpected DEAUTHENTICATE success")
93 if "OK" not in hapd.request("DEAUTHENTICATE ff:ff:ff:ff:ff:ff"):
94 raise Exception("Unexpected DEAUTHENTICATE failure")
95 dev[0].wait_disconnected(timeout=5)
96 dev[0].wait_connected(timeout=10, error="Re-connection timed out")
98 if "FAIL" not in hapd.request("DISASSOCIATE 00:11:22:33:44"):
99 raise Exception("Unexpected DISASSOCIATE success")
101 if "OK" not in hapd.request("DISASSOCIATE ff:ff:ff:ff:ff:ff"):
102 raise Exception("Unexpected DISASSOCIATE failure")
103 dev[0].wait_disconnected(timeout=5)
104 dev[0].wait_connected(timeout=10, error="Re-connection timed out")
107 def test_hapd_ctrl_chan_switch(dev, apdev):
108 """hostapd and CHAN_SWITCH ctrl_iface command"""
110 params = { "ssid": ssid }
111 hapd = hostapd.add_ap(apdev[0], params)
112 if "FAIL" not in hapd.request("CHAN_SWITCH "):
113 raise Exception("Unexpected CHAN_SWITCH success")
114 if "FAIL" not in hapd.request("CHAN_SWITCH qwerty 2422"):
115 raise Exception("Unexpected CHAN_SWITCH success")
116 if "FAIL" not in hapd.request("CHAN_SWITCH 5 qwerty"):
117 raise Exception("Unexpected CHAN_SWITCH success")
118 if "FAIL" not in hapd.request("CHAN_SWITCH 0 2432 center_freq1=123 center_freq2=234 bandwidth=1000 sec_channel_offset=20 ht vht"):
119 raise Exception("Unexpected CHAN_SWITCH success")
122 def test_hapd_ctrl_level(dev, apdev):
123 """hostapd and LEVEL ctrl_iface command"""
125 params = { "ssid": ssid }
126 hapd = hostapd.add_ap(apdev[0], params)
127 if "FAIL" not in hapd.request("LEVEL 0"):
128 raise Exception("Unexpected LEVEL success on non-monitor interface")
131 def test_hapd_ctrl_new_sta(dev, apdev):
132 """hostapd and NEW_STA ctrl_iface command"""
134 params = { "ssid": ssid }
135 hapd = hostapd.add_ap(apdev[0], params)
136 if "FAIL" not in hapd.request("NEW_STA 00:11:22:33:44"):
137 raise Exception("Unexpected NEW_STA success")
138 if "OK" not in hapd.request("NEW_STA 00:11:22:33:44:55"):
139 raise Exception("Unexpected NEW_STA failure")
140 if "AUTHORIZED" not in hapd.request("STA 00:11:22:33:44:55"):
141 raise Exception("Unexpected NEW_STA STA status")
144 def test_hapd_ctrl_get(dev, apdev):
145 """hostapd and GET ctrl_iface command"""
147 params = { "ssid": ssid }
148 hapd = hostapd.add_ap(apdev[0], params)
149 if "FAIL" not in hapd.request("GET foo"):
150 raise Exception("Unexpected GET success")
151 if "FAIL" in hapd.request("GET version"):
152 raise Exception("Unexpected GET version failure")
155 def test_hapd_ctrl_unknown(dev, apdev):
156 """hostapd and unknown ctrl_iface command"""
158 params = { "ssid": ssid }
159 hapd = hostapd.add_ap(apdev[0], params)
160 if "UNKNOWN COMMAND" not in hapd.request("FOO"):
161 raise Exception("Unexpected response")
164 def test_hapd_ctrl_hs20_wnm_notif(dev, apdev):
165 """hostapd and HS20_WNM_NOTIF ctrl_iface command"""
167 params = { "ssid": ssid }
168 hapd = hostapd.add_ap(apdev[0], params)
169 if "FAIL" not in hapd.request("HS20_WNM_NOTIF 00:11:22:33:44 http://example.com/"):
170 raise Exception("Unexpected HS20_WNM_NOTIF success")
171 if "FAIL" not in hapd.request("HS20_WNM_NOTIF 00:11:22:33:44:55http://example.com/"):
172 raise Exception("Unexpected HS20_WNM_NOTIF success")
175 def test_hapd_ctrl_hs20_deauth_req(dev, apdev):
176 """hostapd and HS20_DEAUTH_REQ ctrl_iface command"""
178 params = { "ssid": ssid }
179 hapd = hostapd.add_ap(apdev[0], params)
180 if "FAIL" not in hapd.request("HS20_DEAUTH_REQ 00:11:22:33:44 1 120 http://example.com/"):
181 raise Exception("Unexpected HS20_DEAUTH_REQ success")
182 if "FAIL" not in hapd.request("HS20_DEAUTH_REQ 00:11:22:33:44:55"):
183 raise Exception("Unexpected HS20_DEAUTH_REQ success")
184 if "FAIL" not in hapd.request("HS20_DEAUTH_REQ 00:11:22:33:44:55 1"):
185 raise Exception("Unexpected HS20_DEAUTH_REQ success")
188 def test_hapd_ctrl_disassoc_imminent(dev, apdev):
189 """hostapd and DISASSOC_IMMINENT ctrl_iface command"""
191 params = { "ssid": ssid }
192 hapd = hostapd.add_ap(apdev[0], params)
193 if "FAIL" not in hapd.request("DISASSOC_IMMINENT 00:11:22:33:44"):
194 raise Exception("Unexpected DISASSOC_IMMINENT success")
195 if "FAIL" not in hapd.request("DISASSOC_IMMINENT 00:11:22:33:44:55"):
196 raise Exception("Unexpected DISASSOC_IMMINENT success")
197 if "FAIL" not in hapd.request("DISASSOC_IMMINENT 00:11:22:33:44:55 2"):
198 raise Exception("Unexpected DISASSOC_IMMINENT success")
199 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
200 addr = dev[0].p2p_interface_addr()
201 if "OK" not in hapd.request("DISASSOC_IMMINENT " + addr + " 2"):
202 raise Exception("Unexpected DISASSOC_IMMINENT failure")
203 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
205 raise Exception("Scan timed out")
208 def test_hapd_ctrl_ess_disassoc(dev, apdev):
209 """hostapd and ESS_DISASSOC ctrl_iface command"""
211 params = { "ssid": ssid }
212 hapd = hostapd.add_ap(apdev[0], params)
213 if "FAIL" not in hapd.request("ESS_DISASSOC 00:11:22:33:44"):
214 raise Exception("Unexpected ESS_DISASSOCT success")
215 if "FAIL" not in hapd.request("ESS_DISASSOC 00:11:22:33:44:55"):
216 raise Exception("Unexpected ESS_DISASSOC success")
217 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
218 addr = dev[0].p2p_interface_addr()
219 if "FAIL" not in hapd.request("ESS_DISASSOC " + addr):
220 raise Exception("Unexpected ESS_DISASSOC success")
221 if "FAIL" not in hapd.request("ESS_DISASSOC " + addr + " -1"):
222 raise Exception("Unexpected ESS_DISASSOC success")
223 if "FAIL" not in hapd.request("ESS_DISASSOC " + addr + " 1"):
224 raise Exception("Unexpected ESS_DISASSOC success")
225 if "OK" not in hapd.request("ESS_DISASSOC " + addr + " 20 http://example.com/"):
226 raise Exception("Unexpected ESS_DISASSOC failure")
227 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
229 raise Exception("Scan timed out")
231 def test_hapd_ctrl_set_deny_mac_file(dev, apdev):
232 """hostapd and SET deny_mac_file ctrl_iface command"""
234 params = { "ssid": ssid }
235 hapd = hostapd.add_ap(apdev[0], params)
236 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
237 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
238 if "OK" not in hapd.request("SET deny_mac_file hostapd.macaddr"):
239 raise Exception("Unexpected SET failure")
240 dev[0].wait_disconnected(timeout=15)
241 ev = dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"], 1)
243 raise Exception("Unexpected disconnection")
245 def test_hapd_ctrl_set_accept_mac_file(dev, apdev):
246 """hostapd and SET accept_mac_file ctrl_iface command"""
248 params = { "ssid": ssid }
249 hapd = hostapd.add_ap(apdev[0], params)
250 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
251 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
252 hapd.request("SET macaddr_acl 1")
253 if "OK" not in hapd.request("SET accept_mac_file hostapd.macaddr"):
254 raise Exception("Unexpected SET failure")
255 dev[1].wait_disconnected(timeout=15)
256 ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], 1)
258 raise Exception("Unexpected disconnection")
261 def test_hapd_ctrl_set_error_cases(dev, apdev):
262 """hostapd and SET error cases"""
264 params = { "ssid": ssid }
265 hapd = hostapd.add_ap(apdev[0], params)
266 errors = [ "wpa_key_mgmt FOO",
267 "wpa_key_mgmt WPA-PSK \t FOO",
274 "wep_key0 12q3456789",
275 "wep_key_len_broadcast 20",
276 "wep_rekey_period -1",
278 "r0kh 02:00:00:00:03:0q nas1.w1.fi 100102030405060708090a0b0c0d0e0f",
279 "r0kh 02:00:00:00:03:00 12345678901234567890123456789012345678901234567890.nas1.w1.fi 100102030405060708090a0b0c0d0e0f",
280 "r0kh 02:00:00:00:03:00 nas1.w1.fi 100q02030405060708090a0b0c0d0e0f",
281 "r1kh 02:00:00:00:04:q0 00:01:02:03:04:06 200102030405060708090a0b0c0d0e0f",
282 "r1kh 02:00:00:00:04:00 00:01:02:03:04:q6 200102030405060708090a0b0c0d0e0f",
283 "r1kh 02:00:00:00:04:00 00:01:02:03:04:06 2q0102030405060708090a0b0c0d0e0f",
284 "roaming_consortium 1",
285 "roaming_consortium 12",
286 "roaming_consortium 112233445566778899aabbccddeeff00",
287 'venue_name P"engExample venue"',
288 'venue_name P"engExample venue',
289 "venue_name engExample venue",
290 "venue_name e:Example venue",
291 "venue_name eng1:Example venue",
292 "venue_name eng:Example venue 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
293 "anqp_3gpp_cell_net abc",
294 "anqp_3gpp_cell_net ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;",
295 "anqp_3gpp_cell_net 244",
296 "anqp_3gpp_cell_net 24,123",
297 "anqp_3gpp_cell_net 244,1",
298 "anqp_3gpp_cell_net 244,1234",
300 "nai_realm 0,1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.nas1.w1.fi",
301 "nai_realm 0,example.org,1,2,3,4,5,6,7,8",
302 "nai_realm 0,example.org,1[1:1][2:2][3:3][4:4][5:5]",
303 "nai_realm 0,example.org,1[1]",
304 "nai_realm 0,example.org,1[1:1",
305 "nai_realm 0,a.example.org;b.example.org;c.example.org;d.example.org;e.example.org;f.example.org;g.example.org;h.example.org;i.example.org;j.example.org;k.example.org",
306 "qos_map_set 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60",
307 "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,300",
308 "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,-1",
309 "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,255,1",
313 "hs20_conn_capab 6:22",
314 "hs20_wan_metrics 0q:8000:1000:80:240:3000",
315 "hs20_wan_metrics 01",
316 "hs20_wan_metrics 01:8000",
317 "hs20_wan_metrics 01:8000:1000",
318 "hs20_wan_metrics 01:8000:1000:80",
319 "hs20_wan_metrics 01:8000:1000:80:240",
320 "hs20_oper_friendly_name eng1:Example",
323 "hs20_icon 32:32:eng",
324 "hs20_icon 32:32:eng:image/png",
325 "hs20_icon 32:32:eng:image/png:icon32",
326 "hs20_icon 32:32:eng:image/png:123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890:/tmp/icon32.png",
327 "hs20_icon 32:32:eng:image/png:name:/tmp/123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.png",
331 'osu_ssid "1234567890123456789012345678901234567890"',
332 "osu_friendly_name eng:Example",
333 "osu_nai anonymous@example.com",
334 "osu_method_list 1 0",
336 "osu_service_desc eng:Example services",
337 "ssid 1234567890123456789012345678901234567890",
338 "pac_opaque_encr_key 123456",
339 "eap_fast_a_id 12345",
340 "eap_fast_a_id 12345q",
342 "auth_server_addr foo2",
343 "auth_server_shared_secret ",
344 "acct_server_addr foo3",
345 "acct_server_shared_secret ",
346 "radius_auth_req_attr 123::",
347 "radius_acct_req_attr 123::",
348 "radius_das_client 192.168.1.123",
349 "radius_das_client 192.168.1.1a foo",
352 "max_num_sta 1000000",
353 "wpa_passphrase 1234567",
354 "wpa_passphrase 1234567890123456789012345678901234567890123456789012345678901234",
355 "wpa_psk 1234567890123456789012345678901234567890123456789012345678901234a",
356 "wpa_psk 12345678901234567890123456789012345678901234567890123456789012",
357 "wpa_psk_radius 123",
359 "wpa_pairwise WEP40",
360 "wpa_pairwise WEP104",
362 "rsn_pairwise WEP40",
363 "rsn_pairwise WEP104",
364 "mobility_domain 01",
365 "r1_key_holder 0011223344",
366 "ctrl_interface_group nosuchgrouphere",
374 "rts_threshold 65536",
375 "fragm_threshold -2",
376 "fragm_threshold 2347",
377 "send_probe_response -1",
378 "send_probe_response 2",
380 "vlan_naming 10000000",
381 "group_mgmt_cipher FOO",
382 "assoc_sa_query_max_timeout 0",
383 "assoc_sa_query_retry_timeout 0",
387 "device_name 1234567890123456789012345678901234567890",
388 "manufacturer 1234567890123456789012345678901234567890123456789012345678901234567890",
389 "model_name 1234567890123456789012345678901234567890",
390 "model_number 1234567890123456789012345678901234567890",
391 "serial_number 1234567890123456789012345678901234567890",
394 "ap_settings /tmp/does/not/exist/ap-settings.foo",
395 "wps_nfc_dev_pw_id 4",
396 "wps_nfc_dev_pw_id 100000",
398 "access_network_type -1",
399 "access_network_type 16",
400 "hessid 00:11:22:33:44",
401 "network_auth_type 0q",
402 "ipaddr_type_availability 1q",
403 "hs20_operating_class 0",
404 "hs20_operating_class 0q",
407 "bss_load_test 12:80",
409 "vendor_elements 0q",
410 "assocresp_elements 0",
411 "assocresp_elements 0q",
412 "local_pwr_constraint -1",
413 "local_pwr_constraint 256",
414 "wmm_ac_bk_cwmin -1",
415 "wmm_ac_be_cwmin 16",
416 "wmm_ac_vi_cwmax -1",
417 "wmm_ac_vo_cwmax 16",
418 "wmm_ac_foo_cwmax 6",
420 "wmm_ac_bk_aifs 256",
421 "wmm_ac_bk_txop_limit -1",
422 "wmm_ac_bk_txop_limit 65536",
426 "tx_queue_foo_aifs 3",
427 "tx_queue_data3_cwmin 4",
428 "tx_queue_data3_cwmax 4",
429 "tx_queue_data3_aifs -4",
430 "tx_queue_data3_foo 1" ]
432 if "FAIL" not in hapd.request("SET " + e):
433 raise Exception("Unexpected SET success: '%s'" % e)
435 if "OK" not in hapd.request("SET osu_server_uri https://example.com/"):
436 raise Exception("Unexpected SET osu_server_uri failure")
437 if "OK" not in hapd.request("SET osu_friendly_name eng:Example"):
438 raise Exception("Unexpected SET osu_friendly_name failure")
440 errors = [ "osu_friendly_name eng1:Example",
441 "osu_service_desc eng1:Example services" ]
443 if "FAIL" not in hapd.request("SET " + e):
444 raise Exception("Unexpected SET success: '%s'" % e)
446 no_err = [ "wps_nfc_dh_pubkey 0",
447 "wps_nfc_dh_privkey 0q",
448 "wps_nfc_dev_pw 012",
450 "disassoc_low_ack 0",
451 "network_auth_type 01",
453 "tdls_prohibit_chan_switch 0" ]
455 if "OK" not in hapd.request("SET " + e):
456 raise Exception("Unexpected SET failure: '%s'" % e)
459 def test_hapd_ctrl_global(dev, apdev):
460 """hostapd and GET ctrl_iface command"""
462 params = { "ssid": ssid }
463 ifname = apdev[0]['ifname']
464 hapd = hostapd.add_ap(apdev[0], params)
465 hapd_global = hostapd.HostapdGlobal(apdev[0])
466 res = hapd_global.request("IFNAME=" + ifname + " PING")
467 if "PONG" not in res:
468 raise Exception("Could not ping hostapd interface " + ifname + " via global control interface")
469 res = hapd_global.request("IFNAME=" + ifname + " GET version")
471 raise Exception("Could not get hostapd version for " + ifname + " via global control interface")
473 def dup_network(hapd_global, src, dst, param):
474 res = hapd_global.request("DUP_NETWORK %s %s %s" % (src, dst, param))
476 raise Exception("Could not dup %s param from %s to %s" % (param, src,
479 def test_hapd_dup_network_global_wpa2(dev, apdev):
480 """hostapd and DUP_NETWORK command (WPA2"""
481 passphrase="12345678"
482 src_ssid = "hapd-ctrl-src"
483 dst_ssid = "hapd-ctrl-dst"
485 src_params = hostapd.wpa2_params(ssid=src_ssid, passphrase=passphrase)
486 src_ifname = apdev[0]['ifname']
487 src_hapd = hostapd.add_ap(apdev[0], src_params)
489 dst_params = { "ssid": dst_ssid }
490 dst_ifname = apdev[1]['ifname']
491 dst_hapd = hostapd.add_ap(apdev[1], dst_params, no_enable=True)
493 hapd_global = hostapd.HostapdGlobal()
495 for param in [ "wpa", "wpa_passphrase", "wpa_key_mgmt", "rsn_pairwise" ]:
496 dup_network(hapd_global, src_ifname, dst_ifname, param)
500 dev[0].connect(dst_ssid, psk=passphrase, proto="RSN", pairwise="CCMP",
502 addr = dev[0].own_addr()
503 if "FAIL" in dst_hapd.request("STA " + addr):
504 raise Exception("Could not connect using duplicated wpa params")
506 def test_hapd_dup_network_global_wpa(dev, apdev):
507 """hostapd and DUP_NETWORK command (WPA)"""
508 skip_with_fips(dev[0])
509 psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
510 src_ssid = "hapd-ctrl-src"
511 dst_ssid = "hapd-ctrl-dst"
513 src_params = hostapd.wpa_params(ssid=src_ssid)
514 src_params['wpa_psk'] = psk
515 src_ifname = apdev[0]['ifname']
516 src_hapd = hostapd.add_ap(apdev[0], src_params)
518 dst_params = { "ssid": dst_ssid }
519 dst_ifname = apdev[1]['ifname']
520 dst_hapd = hostapd.add_ap(apdev[1], dst_params, no_enable=True)
522 hapd_global = hostapd.HostapdGlobal()
524 for param in [ "wpa", "wpa_psk", "wpa_key_mgmt", "wpa_pairwise" ]:
525 dup_network(hapd_global, src_ifname, dst_ifname, param)
529 dev[0].connect(dst_ssid, raw_psk=psk, proto="WPA", pairwise="TKIP",
531 addr = dev[0].own_addr()
532 if "FAIL" in dst_hapd.request("STA " + addr):
533 raise Exception("Could not connect using duplicated wpa params")
536 def test_hapd_ctrl_log_level(dev, apdev):
537 """hostapd ctrl_iface LOG_LEVEL"""
538 hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
539 level = hapd.request("LOG_LEVEL")
540 if "Current level: MSGDUMP" not in level:
541 raise Exception("Unexpected debug level(1): " + level)
542 if "Timestamp: 1" not in level:
543 raise Exception("Unexpected timestamp(1): " + level)
545 if "OK" not in hapd.request("LOG_LEVEL MSGDUMP 0"):
546 raise Exception("LOG_LEVEL failed")
547 level = hapd.request("LOG_LEVEL")
548 if "Current level: MSGDUMP" not in level:
549 raise Exception("Unexpected debug level(2): " + level)
550 if "Timestamp: 0" not in level:
551 raise Exception("Unexpected timestamp(2): " + level)
553 if "OK" not in hapd.request("LOG_LEVEL MSGDUMP 1"):
554 raise Exception("LOG_LEVEL failed")
555 level = hapd.request("LOG_LEVEL")
556 if "Current level: MSGDUMP" not in level:
557 raise Exception("Unexpected debug level(3): " + level)
558 if "Timestamp: 1" not in level:
559 raise Exception("Unexpected timestamp(3): " + level)
561 if "FAIL" not in hapd.request("LOG_LEVEL FOO"):
562 raise Exception("Invalid LOG_LEVEL accepted")
564 for lev in [ "EXCESSIVE", "MSGDUMP", "DEBUG", "INFO", "WARNING", "ERROR" ]:
565 if "OK" not in hapd.request("LOG_LEVEL " + lev):
566 raise Exception("LOG_LEVEL failed for " + lev)
567 level = hapd.request("LOG_LEVEL")
568 if "Current level: " + lev not in level:
569 raise Exception("Unexpected debug level: " + level)
571 if "OK" not in hapd.request("LOG_LEVEL MSGDUMP 1"):
572 raise Exception("LOG_LEVEL failed")
573 level = hapd.request("LOG_LEVEL")
574 if "Current level: MSGDUMP" not in level:
575 raise Exception("Unexpected debug level(3): " + level)
576 if "Timestamp: 1" not in level:
577 raise Exception("Unexpected timestamp(3): " + level)
580 def test_hapd_ctrl_disconnect_no_tx(dev, apdev):
581 """hostapd disconnecting STA without transmitting Deauth/Disassoc"""
583 passphrase = "12345678"
584 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
585 hapd = hostapd.add_ap(apdev[0], params)
586 bssid = apdev[0]['bssid']
587 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
588 addr0 = dev[0].own_addr()
589 dev[1].connect(ssid, psk=passphrase, scan_freq="2412")
590 addr1 = dev[1].own_addr()
592 # Disconnect the STA without sending out Deauthentication frame
593 if "OK" not in hapd.request("DEAUTHENTICATE " + addr0 + " tx=0"):
594 raise Exception("DEAUTHENTICATE command failed")
595 # Force disconnection due to AP receiving a frame from not-asssociated STA
596 dev[0].request("DATA_TEST_CONFIG 1")
597 dev[0].request("DATA_TEST_TX " + bssid + " " + addr0)
598 ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
599 dev[0].request("DATA_TEST_CONFIG 0")
601 raise Exception("Disconnection event not seen after TX attempt")
602 if "reason=7" not in ev:
603 raise Exception("Unexpected disconnection reason: " + ev)
605 # Disconnect the STA without sending out Disassociation frame
606 if "OK" not in hapd.request("DISASSOCIATE " + addr1 + " tx=0"):
607 raise Exception("DISASSOCIATE command failed")
608 # Force disconnection due to AP receiving a frame from not-asssociated STA
609 dev[1].request("DATA_TEST_CONFIG 1")
610 dev[1].request("DATA_TEST_TX " + bssid + " " + addr1)
611 ev = dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
612 dev[1].request("DATA_TEST_CONFIG 0")
614 raise Exception("Disconnection event not seen after TX attempt")
615 if "reason=7" not in ev:
616 raise Exception("Unexpected disconnection reason: " + ev)
618 def test_hapd_ctrl_mib(dev, apdev):
619 """hostapd and MIB ctrl_iface command with open network"""
621 params = { "ssid": ssid }
622 hapd = hostapd.add_ap(apdev[0], params)
624 mib = hapd.request("MIB")
626 raise Exception("Unexpected MIB response: " + mib)
628 mib = hapd.request("MIB radius_server")
630 raise Exception("Unexpected 'MIB radius_server' response: " + mib)
632 if "FAIL" not in hapd.request("MIB foo"):
633 raise Exception("'MIB foo' succeeded")
635 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
637 mib = hapd.request("MIB")
639 raise Exception("Unexpected MIB response: " + mib)
641 mib = hapd.request("MIB radius_server")
643 raise Exception("Unexpected 'MIB radius_server' response: " + mib)
645 if "FAIL" not in hapd.request("MIB foo"):
646 raise Exception("'MIB foo' succeeded")
648 def test_hapd_ctrl_not_yet_fully_enabled(dev, apdev):
649 """hostapd and ctrl_iface commands when BSS not yet fully enabled"""
651 params = { "ssid": ssid }
652 hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
655 raise Exception("PING failed")
656 if "FAIL" in hapd.request("MIB"):
657 raise Exception("MIB failed")
658 if len(hapd.request("MIB radius_server")) != 0:
659 raise Exception("Unexpected 'MIB radius_server' response")
660 if "state=UNINITIALIZED" not in hapd.request("STATUS"):
661 raise Exception("Unexpected STATUS response")
662 if "FAIL" not in hapd.request("STATUS-DRIVER"):
663 raise Exception("Unexpected response to STATUS-DRIVER")
664 if len(hapd.request("STA-FIRST")) != 0:
665 raise Exception("Unexpected response to STA-FIRST")
666 if "FAIL" not in hapd.request("STA ff:ff:ff:ff:ff:ff"):
667 raise Exception("Unexpected response to STA")
668 cmds = [ "NEW_STA 02:ff:ff:ff:ff:ff",
669 "DEAUTHENTICATE 02:ff:ff:ff:ff:ff",
670 "DEAUTHENTICATE 02:ff:ff:ff:ff:ff test=0",
671 "DEAUTHENTICATE 02:ff:ff:ff:ff:ff p2p=0",
672 "DEAUTHENTICATE 02:ff:ff:ff:ff:ff tx=0",
673 "DISASSOCIATE 02:ff:ff:ff:ff:ff",
674 "DISASSOCIATE 02:ff:ff:ff:ff:ff test=0",
675 "DISASSOCIATE 02:ff:ff:ff:ff:ff p2p=0",
676 "DISASSOCIATE 02:ff:ff:ff:ff:ff tx=0",
677 "SA_QUERY 02:ff:ff:ff:ff:ff",
678 "WPS_PIN any 12345670",
682 "WPS_AP_PIN disable",
683 "WPS_CHECK_PIN 123456789",
685 "WPS_NFC_TAG_READ 00",
686 "WPS_NFC_CONFIG_TOKEN NDEF",
688 "NFC_GET_HANDOVER_SEL NDEF WPS-CR",
689 "NFC_REPORT_HANDOVER RESP WPS 00 00",
690 "SET_QOS_MAP_SET 22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,48,55",
691 "SEND_QOS_MAP_CONF 02:ff:ff:ff:ff:ff",
692 "HS20_WNM_NOTIF 02:ff:ff:ff:ff:ff https://example.com/",
693 "HS20_DEAUTH_REQ 02:ff:ff:ff:ff:ff 1 120 https://example.com/",
694 "DISASSOC_IMMINENT 02:ff:ff:ff:ff:ff 10",
695 "ESS_DISASSOC 02:ff:ff:ff:ff:ff 10 https://example.com/",
696 "BSS_TM_REQ 02:ff:ff:ff:ff:ff",
698 "RADAR DETECTED freq=5260 ht_enabled=1 chan_width=1",
699 "CHAN_SWITCH 5 5200 ht sec_channel_offset=-1 bandwidth=40",
703 "SET_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1\"",
704 "REMOVE_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1\"",
705 "REQ_LCI 00:11:22:33:44:55",
706 "REQ_RANGE 00:11:22:33:44:55",