]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_hapd_ctrl.py
6ed8270725d8e7c332c71e873b5346f387eb8956
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.
9 def test_hapd_ctrl_status(dev
, apdev
):
10 """hostapd ctrl_iface STATUS commands"""
12 bssid
= apdev
[0]['bssid']
13 params
= hostapd
.wpa2_params(ssid
=ssid
, passphrase
="12345678")
14 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
15 status
= hapd
.get_status()
16 driver
= hapd
.get_driver_status()
18 if status
['bss[0]'] != apdev
[0]['ifname']:
19 raise Exception("Unexpected bss[0]")
20 if status
['ssid[0]'] != ssid
:
21 raise Exception("Unexpected ssid[0]")
22 if status
['bssid[0]'] != bssid
:
23 raise Exception("Unexpected bssid[0]")
24 if status
['freq'] != "2412":
25 raise Exception("Unexpected freq")
27 if driver
['beacon_set'] != "1":
28 raise Exception("Unexpected beacon_set")
29 if driver
['addr'] != bssid
:
30 raise Exception("Unexpected addr")
32 def test_hapd_ctrl_p2p_manager(dev
, apdev
):
33 """hostapd as P2P Device manager"""
35 passphrase
= "12345678"
36 params
= hostapd
.wpa2_params(ssid
=ssid
, passphrase
=passphrase
)
37 params
['manage_p2p'] = '1'
38 params
['allow_cross_connection'] = '0'
39 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
40 dev
[0].connect(ssid
, psk
=passphrase
, scan_freq
="2412")
41 addr
= dev
[0].p2p_dev_addr()
42 if "OK" not in hapd
.request("DEAUTHENTICATE " + addr
+ " p2p=2"):
43 raise Exception("DEAUTHENTICATE command failed")
44 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout
=5)
46 raise Exception("Disconnection event timed out")
47 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"])
49 raise Exception("Re-connection timed out")
51 if "OK" not in hapd
.request("DISASSOCIATE " + addr
+ " p2p=2"):
52 raise Exception("DISASSOCIATE command failed")
53 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout
=5)
55 raise Exception("Disconnection event timed out")
56 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"])
58 raise Exception("Re-connection timed out")
60 def test_hapd_ctrl_sta(dev
, apdev
):
61 """hostapd and STA ctrl_iface commands"""
62 ssid
= "hapd-ctrl-sta"
63 passphrase
= "12345678"
64 params
= hostapd
.wpa2_params(ssid
=ssid
, passphrase
=passphrase
)
65 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
66 dev
[0].connect(ssid
, psk
=passphrase
, scan_freq
="2412")
67 addr
= dev
[0].p2p_dev_addr()
68 if "FAIL" in hapd
.request("STA " + addr
):
69 raise Exception("Unexpected STA failure")
70 if "FAIL" not in hapd
.request("STA " + addr
+ " eapol"):
71 raise Exception("Unexpected STA-eapol success")
72 if "FAIL" not in hapd
.request("STA 00:11:22:33:44"):
73 raise Exception("Unexpected STA success")
74 if "FAIL" not in hapd
.request("STA 00:11:22:33:44:55"):
75 raise Exception("Unexpected STA success")
77 if len(hapd
.request("STA-NEXT " + addr
).splitlines()) > 0:
78 raise Exception("Unexpected STA-NEXT result")
79 if "FAIL" not in hapd
.request("STA-NEXT 00:11:22:33:44"):
80 raise Exception("Unexpected STA-NEXT success")
82 def test_hapd_ctrl_disconnect(dev
, apdev
):
83 """hostapd and disconnection ctrl_iface commands"""
85 passphrase
= "12345678"
86 params
= hostapd
.wpa2_params(ssid
=ssid
, passphrase
=passphrase
)
87 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
88 dev
[0].connect(ssid
, psk
=passphrase
, scan_freq
="2412")
89 addr
= dev
[0].p2p_dev_addr()
91 if "FAIL" not in hapd
.request("DEAUTHENTICATE 00:11:22:33:44"):
92 raise Exception("Unexpected DEAUTHENTICATE success")
94 if "OK" not in hapd
.request("DEAUTHENTICATE ff:ff:ff:ff:ff:ff"):
95 raise Exception("Unexpected DEAUTHENTICATE failure")
96 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout
=5)
98 raise Exception("Disconnection event timed out")
99 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"])
101 raise Exception("Re-connection timed out")
103 if "FAIL" not in hapd
.request("DISASSOCIATE 00:11:22:33:44"):
104 raise Exception("Unexpected DISASSOCIATE success")
106 if "OK" not in hapd
.request("DISASSOCIATE ff:ff:ff:ff:ff:ff"):
107 raise Exception("Unexpected DISASSOCIATE failure")
108 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout
=5)
110 raise Exception("Disconnection event timed out")
111 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"])
113 raise Exception("Re-connection timed out")
115 def test_hapd_ctrl_chan_switch(dev
, apdev
):
116 """hostapd and CHAN_SWITCH ctrl_iface command"""
118 params
= { "ssid": ssid
}
119 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
120 if "FAIL" not in hapd
.request("CHAN_SWITCH "):
121 raise Exception("Unexpected CHAN_SWITCH success")
122 if "FAIL" not in hapd
.request("CHAN_SWITCH qwerty 2422"):
123 raise Exception("Unexpected CHAN_SWITCH success")
124 if "FAIL" not in hapd
.request("CHAN_SWITCH 5 qwerty"):
125 raise Exception("Unexpected CHAN_SWITCH success")
126 if "FAIL" not in hapd
.request("CHAN_SWITCH 0 2432 center_freq1=123 center_freq2=234 bandwidth=1000 sec_channel_offset=20 ht vht"):
127 raise Exception("Unexpected CHAN_SWITCH success")
129 def test_hapd_ctrl_level(dev
, apdev
):
130 """hostapd and LEVEL ctrl_iface command"""
132 params
= { "ssid": ssid
}
133 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
134 if "FAIL" not in hapd
.request("LEVEL 0"):
135 raise Exception("Unexpected LEVEL success on non-monitor interface")
137 def test_hapd_ctrl_new_sta(dev
, apdev
):
138 """hostapd and NEW_STA ctrl_iface command"""
140 params
= { "ssid": ssid
}
141 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
142 if "FAIL" not in hapd
.request("NEW_STA 00:11:22:33:44"):
143 raise Exception("Unexpected NEW_STA success")
144 if "OK" not in hapd
.request("NEW_STA 00:11:22:33:44:55"):
145 raise Exception("Unexpected NEW_STA failure")
146 if "AUTHORIZED" not in hapd
.request("STA 00:11:22:33:44:55"):
147 raise Esception("Unexpected NEW_STA STA status")
149 def test_hapd_ctrl_get(dev
, apdev
):
150 """hostapd and GET ctrl_iface command"""
152 params
= { "ssid": ssid
}
153 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
154 if "FAIL" not in hapd
.request("GET foo"):
155 raise Exception("Unexpected GET success")
156 if "FAIL" in hapd
.request("GET version"):
157 raise Exception("Unexpected GET version failure")
159 def test_hapd_ctrl_unknown(dev
, apdev
):
160 """hostapd and unknown ctrl_iface command"""
162 params
= { "ssid": ssid
}
163 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
164 if "UNKNOWN COMMAND" not in hapd
.request("FOO"):
165 raise Exception("Unexpected response")
167 def test_hapd_ctrl_hs20_wnm_notif(dev
, apdev
):
168 """hostapd and HS20_WNM_NOTIF ctrl_iface command"""
170 params
= { "ssid": ssid
}
171 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
172 if "FAIL" not in hapd
.request("HS20_WNM_NOTIF 00:11:22:33:44 http://example.com/"):
173 raise Exception("Unexpected HS20_WNM_NOTIF success")
174 if "FAIL" not in hapd
.request("HS20_WNM_NOTIF 00:11:22:33:44:55http://example.com/"):
175 raise Exception("Unexpected HS20_WNM_NOTIF success")
177 def test_hapd_ctrl_hs20_deauth_req(dev
, apdev
):
178 """hostapd and HS20_DEAUTH_REQ ctrl_iface command"""
180 params
= { "ssid": ssid
}
181 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
182 if "FAIL" not in hapd
.request("HS20_DEAUTH_REQ 00:11:22:33:44 1 120 http://example.com/"):
183 raise Exception("Unexpected HS20_DEAUTH_REQ success")
184 if "FAIL" not in hapd
.request("HS20_DEAUTH_REQ 00:11:22:33:44:55"):
185 raise Exception("Unexpected HS20_DEAUTH_REQ success")
186 if "FAIL" not in hapd
.request("HS20_DEAUTH_REQ 00:11:22:33:44:55 1"):
187 raise Exception("Unexpected HS20_DEAUTH_REQ success")
189 def test_hapd_ctrl_disassoc_imminent(dev
, apdev
):
190 """hostapd and DISASSOC_IMMINENT ctrl_iface command"""
192 params
= { "ssid": ssid
}
193 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
194 if "FAIL" not in hapd
.request("DISASSOC_IMMINENT 00:11:22:33:44"):
195 raise Exception("Unexpected DISASSOC_IMMINENT success")
196 if "FAIL" not in hapd
.request("DISASSOC_IMMINENT 00:11:22:33:44:55"):
197 raise Exception("Unexpected DISASSOC_IMMINENT success")
198 if "FAIL" not in hapd
.request("DISASSOC_IMMINENT 00:11:22:33:44:55 2"):
199 raise Exception("Unexpected DISASSOC_IMMINENT success")
200 dev
[0].connect(ssid
, key_mgmt
="NONE", scan_freq
="2412")
201 addr
= dev
[0].p2p_interface_addr()
202 if "OK" not in hapd
.request("DISASSOC_IMMINENT " + addr
+ " 2"):
203 raise Exception("Unexpected DISASSOC_IMMINENT failure")
204 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
206 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]['ifname'], 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]['ifname'], 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 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"], 15)
242 raise Exception("Disconnection timeout")
243 ev
= dev
[1].wait_event(["CTRL-EVENT-DISCONNECTED"], 1)
245 raise Exception("Unexpected disconnection")
247 def test_hapd_ctrl_set_accept_mac_file(dev
, apdev
):
248 """hostapd and SET accept_mac_file ctrl_iface command"""
250 params
= { "ssid": ssid
}
251 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
252 dev
[0].connect(ssid
, key_mgmt
="NONE", scan_freq
="2412")
253 dev
[1].connect(ssid
, key_mgmt
="NONE", scan_freq
="2412")
254 hapd
.request("SET macaddr_acl 1")
255 if "OK" not in hapd
.request("SET accept_mac_file hostapd.macaddr"):
256 raise Exception("Unexpected SET failure")
257 ev
= dev
[1].wait_event(["CTRL-EVENT-DISCONNECTED"], 15)
259 raise Exception("Disconnection timeout")
260 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"], 1)
262 raise Exception("Unexpected disconnection")
264 def test_hapd_ctrl_set_error_cases(dev
, apdev
):
265 """hostapd and SET error cases"""
267 params
= { "ssid": ssid
}
268 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
269 errors
= [ "wpa_key_mgmt FOO",
270 "wpa_key_mgmt WPA-PSK \t FOO",
277 "wep_key0 12q3456789",
278 "wep_key_len_broadcast 20",
279 "wep_rekey_period -1",
281 "r0kh 02:00:00:00:03:0q nas1.w1.fi 100102030405060708090a0b0c0d0e0f",
282 "r0kh 02:00:00:00:03:00 12345678901234567890123456789012345678901234567890.nas1.w1.fi 100102030405060708090a0b0c0d0e0f",
283 "r0kh 02:00:00:00:03:00 nas1.w1.fi 100q02030405060708090a0b0c0d0e0f",
284 "r1kh 02:00:00:00:04:q0 00:01:02:03:04:06 200102030405060708090a0b0c0d0e0f",
285 "r1kh 02:00:00:00:04:00 00:01:02:03:04:q6 200102030405060708090a0b0c0d0e0f",
286 "r1kh 02:00:00:00:04:00 00:01:02:03:04:06 2q0102030405060708090a0b0c0d0e0f",
287 "roaming_consortium 1",
288 "roaming_consortium 12",
289 "roaming_consortium 112233445566778899aabbccddeeff00",
290 'venue_name P"engExample venue"',
291 'venue_name P"engExample venue',
292 "venue_name engExample venue",
293 "venue_name e:Example venue",
294 "venue_name eng1:Example venue",
295 "venue_name eng:Example venue 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
296 "anqp_3gpp_cell_net abc",
297 "anqp_3gpp_cell_net ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;",
298 "anqp_3gpp_cell_net 244",
299 "anqp_3gpp_cell_net 24,123",
300 "anqp_3gpp_cell_net 244,1",
301 "anqp_3gpp_cell_net 244,1234",
303 "nai_realm 0,1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.nas1.w1.fi",
304 "nai_realm 0,example.org,1,2,3,4,5,6,7,8",
305 "nai_realm 0,example.org,1[1:1][2:2][3:3][4:4][5:5]",
306 "nai_realm 0,example.org,1[1]",
307 "nai_realm 0,example.org,1[1:1",
308 "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",
309 "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",
310 "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,300",
311 "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,-1",
312 "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,255,1",
316 "hs20_conn_capab 6:22",
317 "hs20_wan_metrics 0q:8000:1000:80:240:3000",
318 "hs20_wan_metrics 01",
319 "hs20_wan_metrics 01:8000",
320 "hs20_wan_metrics 01:8000:1000",
321 "hs20_wan_metrics 01:8000:1000:80",
322 "hs20_wan_metrics 01:8000:1000:80:240",
323 "hs20_oper_friendly_name eng1:Example",
326 "hs20_icon 32:32:eng",
327 "hs20_icon 32:32:eng:image/png",
328 "hs20_icon 32:32:eng:image/png:icon32",
329 "hs20_icon 32:32:eng:image/png:123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890:/tmp/icon32.png",
330 "hs20_icon 32:32:eng:image/png:name:/tmp/123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.png",
334 'osu_ssid "1234567890123456789012345678901234567890"',
335 "osu_friendly_name eng:Example",
336 "osu_nai anonymous@example.com",
337 "osu_method_list 1 0",
339 "osu_service_desc eng:Example services",
340 "ssid 1234567890123456789012345678901234567890",
341 "pac_opaque_encr_key 123456",
342 "eap_fast_a_id 12345",
343 "eap_fast_a_id 12345q",
345 "auth_server_addr foo2",
346 "auth_server_shared_secret ",
347 "acct_server_addr foo3",
348 "acct_server_shared_secret ",
349 "radius_auth_req_attr 123::",
350 "radius_acct_req_attr 123::",
351 "radius_das_client 192.168.1.123",
352 "radius_das_client 192.168.1.1a foo",
355 "max_num_sta 1000000",
356 "wpa_passphrase 1234567",
357 "wpa_passphrase 1234567890123456789012345678901234567890123456789012345678901234",
358 "wpa_psk 1234567890123456789012345678901234567890123456789012345678901234a",
359 "wpa_psk 12345678901234567890123456789012345678901234567890123456789012",
360 "wpa_psk_radius 123",
362 "wpa_pairwise WEP40",
363 "wpa_pairwise WEP104",
365 "rsn_pairwise WEP40",
366 "rsn_pairwise WEP104",
367 "mobility_domain 01",
368 "r1_key_holder 0011223344",
369 "ctrl_interface_group nosuchgrouphere",
377 "rts_threshold 2348",
378 "fragm_threshold -1",
379 "fragm_threshold 2347",
380 "send_probe_response -1",
381 "send_probe_response 2",
383 "vlan_naming 10000000",
384 "group_mgmt_cipher FOO",
385 "assoc_sa_query_max_timeout 0",
386 "assoc_sa_query_retry_timeout 0",
390 "device_name 1234567890123456789012345678901234567890",
391 "manufacturer 1234567890123456789012345678901234567890123456789012345678901234567890",
392 "model_name 1234567890123456789012345678901234567890",
393 "model_number 1234567890123456789012345678901234567890",
394 "serial_number 1234567890123456789012345678901234567890",
397 "ap_settings /tmp/does/not/exist/ap-settings.foo",
398 "wps_nfc_dev_pw_id 4",
399 "wps_nfc_dev_pw_id 100000",
401 "access_network_type -1",
402 "access_network_type 16",
403 "hessid 00:11:22:33:44",
404 "network_auth_type 0q",
405 "ipaddr_type_availability 1q",
406 "hs20_operating_class 0",
407 "hs20_operating_class 0q",
410 "bss_load_test 12:80",
412 "vendor_elements 0q",
413 "local_pwr_constraint -1",
414 "local_pwr_constraint 256",
415 "wmm_ac_bk_cwmin -1",
416 "wmm_ac_be_cwmin 13",
417 "wmm_ac_vi_cwmax -1",
418 "wmm_ac_vo_cwmax 13",
419 "wmm_ac_foo_cwmax 6",
421 "wmm_ac_bk_aifs 256",
422 "wmm_ac_bk_txop_limit -1",
423 "wmm_ac_bk_txop_limit 65536",
427 "tx_queue_foo_aifs 3",
428 "tx_queue_data3_cwmin 4",
429 "tx_queue_data3_cwmax 4",
430 "tx_queue_data3_aifs -4",
431 "tx_queue_data3_foo 1" ]
433 if "FAIL" not in hapd
.request("SET " + e
):
434 raise Exception("Unexpected SET success: '%s'" % e
)
436 if "OK" not in hapd
.request("SET osu_server_uri https://example.com/"):
437 raise Exception("Unexpected SET osu_server_uri failure")
438 if "OK" not in hapd
.request("SET osu_friendly_name eng:Example"):
439 raise Exception("Unexpected SET osu_friendly_name failure")
441 errors
= [ "osu_friendly_name eng1:Example",
442 "osu_service_desc eng1:Example services" ]
444 if "FAIL" not in hapd
.request("SET " + e
):
445 raise Exception("Unexpected SET success: '%s'" % e
)
447 no_err
= [ "wps_nfc_dh_pubkey 0",
448 "wps_nfc_dh_privkey 0q",
449 "wps_nfc_dev_pw 012",
451 "disassoc_low_ack 0",
452 "network_auth_type 01",
454 "tdls_prohibit_chan_switch 0" ]
456 if "OK" not in hapd
.request("SET " + e
):
457 raise Exception("Unexpected SET failure: '%s'" % e
)