1# hostapd control interface 2# Copyright (c) 2014, Qualcomm Atheros, Inc. 3# 4# This software may be distributed under the terms of the BSD license. 5# See README for more details. 6 7import logging 8logger = logging.getLogger() 9import os 10from remotehost import remote_compatible 11import hostapd 12import hwsim_utils 13from utils import * 14 15@remote_compatible 16def test_hapd_ctrl_status(dev, apdev): 17 """hostapd ctrl_iface STATUS commands""" 18 ssid = "hapd-ctrl" 19 bssid = apdev[0]['bssid'] 20 params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678") 21 hapd = hostapd.add_ap(apdev[0], params) 22 status = hapd.get_status() 23 logger.info("STATUS: " + str(status)) 24 driver = hapd.get_driver_status() 25 logger.info("STATUS-DRIVER: " + str(driver)) 26 27 if status['bss[0]'] != apdev[0]['ifname']: 28 raise Exception("Unexpected bss[0]") 29 if status['ssid[0]'] != ssid: 30 raise Exception("Unexpected ssid[0]") 31 if status['bssid[0]'] != bssid: 32 raise Exception("Unexpected bssid[0]") 33 if status['freq'] != "2412": 34 raise Exception("Unexpected freq") 35 if status['beacon_int'] != "100": 36 raise Exception("Unexpected beacon_int") 37 if status['dtim_period'] != "2": 38 raise Exception("Unexpected dtim_period") 39 if "max_txpower" not in status: 40 raise Exception("Missing max_txpower") 41 if "ht_caps_info" not in status: 42 raise Exception("Missing ht_caps_info") 43 44 if driver['beacon_set'] != "1": 45 raise Exception("Unexpected beacon_set") 46 if driver['addr'] != bssid: 47 raise Exception("Unexpected addr") 48 49@remote_compatible 50def test_hapd_ctrl_p2p_manager(dev, apdev): 51 """hostapd as P2P Device manager""" 52 ssid = "hapd-p2p-mgr" 53 passphrase = "12345678" 54 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase) 55 params['manage_p2p'] = '1' 56 params['allow_cross_connection'] = '0' 57 hapd = hostapd.add_ap(apdev[0], params) 58 dev[0].connect(ssid, psk=passphrase, scan_freq="2412") 59 addr = dev[0].own_addr() 60 if "OK" not in hapd.request("DEAUTHENTICATE " + addr + " p2p=2"): 61 raise Exception("DEAUTHENTICATE command failed") 62 dev[0].wait_disconnected(timeout=5) 63 dev[0].wait_connected(timeout=10, error="Re-connection timed out") 64 65 if "OK" not in hapd.request("DISASSOCIATE " + addr + " p2p=2"): 66 raise Exception("DISASSOCIATE command failed") 67 dev[0].wait_disconnected(timeout=5) 68 dev[0].wait_connected(timeout=10, error="Re-connection timed out") 69 70@remote_compatible 71def test_hapd_ctrl_sta(dev, apdev): 72 """hostapd and STA ctrl_iface commands""" 73 try: 74 run_hapd_ctrl_sta(dev, apdev) 75 finally: 76 dev[0].request("VENDOR_ELEM_REMOVE 13 *") 77 78def run_hapd_ctrl_sta(dev, apdev): 79 ssid = "hapd-ctrl-sta" 80 passphrase = "12345678" 81 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase) 82 hapd = hostapd.add_ap(apdev[0], params) 83 hglobal = hostapd.HostapdGlobal(apdev[0]) 84 dev[0].request("VENDOR_ELEM_ADD 13 2102ff02") 85 dev[0].connect(ssid, psk=passphrase, scan_freq="2412") 86 addr = dev[0].own_addr() 87 ev = hapd.wait_event(["AP-STA-CONNECTED"], timeout=2) 88 if ev is None: 89 raise Exception("No hostapd per-interface event reported") 90 ev2 = hglobal.wait_event(["AP-STA-CONNECTED"], timeout=2) 91 if ev2 is None: 92 raise Exception("No hostapd global event reported") 93 if not ev2.startswith("IFNAME=" + apdev[0]['ifname'] + " <"): 94 raise Exception("Unexpected global event prefix: " + ev2) 95 if ev not in ev2: 96 raise Exception("Event mismatch (%s,%s)" % (ev, ev2)) 97 if "FAIL" in hapd.request("STA " + addr): 98 raise Exception("Unexpected STA failure") 99 if "FAIL" not in hapd.request("STA " + addr + " eapol"): 100 raise Exception("Unexpected STA-eapol success") 101 if "FAIL" not in hapd.request("STA " + addr + " foo"): 102 raise Exception("Unexpected STA-foo success") 103 if "FAIL" not in hapd.request("STA 00:11:22:33:44"): 104 raise Exception("Unexpected STA success") 105 if "FAIL" not in hapd.request("STA 00:11:22:33:44:55"): 106 raise Exception("Unexpected STA success") 107 108 if len(hapd.request("STA-NEXT " + addr).splitlines()) > 0: 109 raise Exception("Unexpected STA-NEXT result") 110 if "FAIL" not in hapd.request("STA-NEXT 00:11:22:33:44"): 111 raise Exception("Unexpected STA-NEXT success") 112 113 sta = hapd.get_sta(addr) 114 logger.info("STA: " + str(sta)) 115 if "ext_capab" not in sta: 116 raise Exception("Missing ext_capab in STA output") 117 if 'ht_caps_info' not in sta: 118 raise Exception("Missing ht_caps_info in STA output") 119 if 'min_txpower' not in sta: 120 raise Exception("Missing min_txpower in STA output") 121 if 'max_txpower' not in sta: 122 raise Exception("Missing min_txpower in STA output") 123 if sta['min_txpower'] != '-1': 124 raise Exception("Unxpected min_txpower value: " + sta['min_txpower']) 125 if sta['max_txpower'] != '2': 126 raise Exception("Unxpected max_txpower value: " + sta['max_txpower']) 127 128@remote_compatible 129def test_hapd_ctrl_disconnect(dev, apdev): 130 """hostapd and disconnection ctrl_iface commands""" 131 ssid = "hapd-ctrl" 132 passphrase = "12345678" 133 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase) 134 hapd = hostapd.add_ap(apdev[0], params) 135 dev[0].connect(ssid, psk=passphrase, scan_freq="2412") 136 addr = dev[0].p2p_dev_addr() 137 138 if "FAIL" not in hapd.request("DEAUTHENTICATE 00:11:22:33:44"): 139 raise Exception("Unexpected DEAUTHENTICATE success") 140 141 if "OK" not in hapd.request("DEAUTHENTICATE ff:ff:ff:ff:ff:ff"): 142 raise Exception("Unexpected DEAUTHENTICATE failure") 143 dev[0].wait_disconnected(timeout=5) 144 dev[0].wait_connected(timeout=10, error="Re-connection timed out") 145 146 if "FAIL" not in hapd.request("DISASSOCIATE 00:11:22:33:44"): 147 raise Exception("Unexpected DISASSOCIATE success") 148 149 if "OK" not in hapd.request("DISASSOCIATE ff:ff:ff:ff:ff:ff"): 150 raise Exception("Unexpected DISASSOCIATE failure") 151 dev[0].wait_disconnected(timeout=5) 152 dev[0].wait_connected(timeout=10, error="Re-connection timed out") 153 154@remote_compatible 155def test_hapd_ctrl_chan_switch(dev, apdev): 156 """hostapd and CHAN_SWITCH ctrl_iface command""" 157 ssid = "hapd-ctrl" 158 params = {"ssid": ssid} 159 hapd = hostapd.add_ap(apdev[0], params) 160 if "FAIL" not in hapd.request("CHAN_SWITCH "): 161 raise Exception("Unexpected CHAN_SWITCH success") 162 if "FAIL" not in hapd.request("CHAN_SWITCH qwerty 2422"): 163 raise Exception("Unexpected CHAN_SWITCH success") 164 if "FAIL" not in hapd.request("CHAN_SWITCH 5 qwerty"): 165 raise Exception("Unexpected CHAN_SWITCH success") 166 if "FAIL" not in hapd.request("CHAN_SWITCH 0 2432 center_freq1=123 center_freq2=234 bandwidth=1000 sec_channel_offset=20 ht vht"): 167 raise Exception("Unexpected CHAN_SWITCH success") 168 169@remote_compatible 170def test_hapd_ctrl_level(dev, apdev): 171 """hostapd and LEVEL ctrl_iface command""" 172 ssid = "hapd-ctrl" 173 params = {"ssid": ssid} 174 hapd = hostapd.add_ap(apdev[0], params) 175 if "FAIL" not in hapd.request("LEVEL 0"): 176 raise Exception("Unexpected LEVEL success on non-monitor interface") 177 178@remote_compatible 179def test_hapd_ctrl_new_sta(dev, apdev): 180 """hostapd and NEW_STA ctrl_iface command""" 181 ssid = "hapd-ctrl" 182 params = {"ssid": ssid} 183 hapd = hostapd.add_ap(apdev[0], params) 184 if "FAIL" not in hapd.request("NEW_STA 00:11:22:33:44"): 185 raise Exception("Unexpected NEW_STA success") 186 if "OK" not in hapd.request("NEW_STA 00:11:22:33:44:55"): 187 raise Exception("Unexpected NEW_STA failure") 188 if "AUTHORIZED" not in hapd.request("STA 00:11:22:33:44:55"): 189 raise Exception("Unexpected NEW_STA STA status") 190 if "OK" not in hapd.request("NEW_STA 00:11:22:33:44:55"): 191 raise Exception("Unexpected NEW_STA failure") 192 with alloc_fail(hapd, 1, "ap_sta_add;hostapd_ctrl_iface_new_sta"): 193 if "FAIL" not in hapd.request("NEW_STA 00:11:22:33:44:66"): 194 raise Exception("Unexpected NEW_STA success during OOM") 195 196@remote_compatible 197def test_hapd_ctrl_get(dev, apdev): 198 """hostapd and GET ctrl_iface command""" 199 ssid = "hapd-ctrl" 200 params = {"ssid": ssid} 201 hapd = hostapd.add_ap(apdev[0], params) 202 if "FAIL" not in hapd.request("GET foo"): 203 raise Exception("Unexpected GET success") 204 if "FAIL" in hapd.request("GET version"): 205 raise Exception("Unexpected GET version failure") 206 207@remote_compatible 208def test_hapd_ctrl_unknown(dev, apdev): 209 """hostapd and unknown ctrl_iface command""" 210 ssid = "hapd-ctrl" 211 params = {"ssid": ssid} 212 hapd = hostapd.add_ap(apdev[0], params) 213 if "UNKNOWN COMMAND" not in hapd.request("FOO"): 214 raise Exception("Unexpected response") 215 216@remote_compatible 217def test_hapd_ctrl_hs20_deauth_req(dev, apdev): 218 """hostapd and HS20_DEAUTH_REQ ctrl_iface command""" 219 ssid = "hapd-ctrl" 220 params = {"ssid": ssid} 221 hapd = hostapd.add_ap(apdev[0], params) 222 if "FAIL" not in hapd.request("HS20_DEAUTH_REQ 00:11:22:33:44 1 120 http://example.com/"): 223 raise Exception("Unexpected HS20_DEAUTH_REQ success") 224 if "FAIL" not in hapd.request("HS20_DEAUTH_REQ 00:11:22:33:44:55"): 225 raise Exception("Unexpected HS20_DEAUTH_REQ success") 226 if "FAIL" not in hapd.request("HS20_DEAUTH_REQ 00:11:22:33:44:55 1"): 227 raise Exception("Unexpected HS20_DEAUTH_REQ success") 228 229@remote_compatible 230def test_hapd_ctrl_disassoc_imminent(dev, apdev): 231 """hostapd and DISASSOC_IMMINENT ctrl_iface command""" 232 ssid = "hapd-ctrl" 233 params = {"ssid": ssid} 234 hapd = hostapd.add_ap(apdev[0], params) 235 if "FAIL" not in hapd.request("DISASSOC_IMMINENT 00:11:22:33:44"): 236 raise Exception("Unexpected DISASSOC_IMMINENT success") 237 if "FAIL" not in hapd.request("DISASSOC_IMMINENT 00:11:22:33:44:55"): 238 raise Exception("Unexpected DISASSOC_IMMINENT success") 239 if "FAIL" not in hapd.request("DISASSOC_IMMINENT 00:11:22:33:44:55 2"): 240 raise Exception("Unexpected DISASSOC_IMMINENT success") 241 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412") 242 addr = dev[0].p2p_interface_addr() 243 if "OK" not in hapd.request("DISASSOC_IMMINENT " + addr + " 2"): 244 raise Exception("Unexpected DISASSOC_IMMINENT failure") 245 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15) 246 if ev is None: 247 raise Exception("Scan timed out") 248 249@remote_compatible 250def test_hapd_ctrl_ess_disassoc(dev, apdev): 251 """hostapd and ESS_DISASSOC ctrl_iface command""" 252 ssid = "hapd-ctrl" 253 params = {"ssid": ssid} 254 hapd = hostapd.add_ap(apdev[0], params) 255 if "FAIL" not in hapd.request("ESS_DISASSOC 00:11:22:33:44"): 256 raise Exception("Unexpected ESS_DISASSOCT success") 257 if "FAIL" not in hapd.request("ESS_DISASSOC 00:11:22:33:44:55"): 258 raise Exception("Unexpected ESS_DISASSOC success") 259 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412") 260 addr = dev[0].p2p_interface_addr() 261 if "FAIL" not in hapd.request("ESS_DISASSOC " + addr): 262 raise Exception("Unexpected ESS_DISASSOC success") 263 if "FAIL" not in hapd.request("ESS_DISASSOC " + addr + " -1"): 264 raise Exception("Unexpected ESS_DISASSOC success") 265 if "FAIL" not in hapd.request("ESS_DISASSOC " + addr + " 1"): 266 raise Exception("Unexpected ESS_DISASSOC success") 267 if "OK" not in hapd.request("ESS_DISASSOC " + addr + " 20 http://example.com/"): 268 raise Exception("Unexpected ESS_DISASSOC failure") 269 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15) 270 if ev is None: 271 raise Exception("Scan timed out") 272 273def test_hapd_ctrl_set_deny_mac_file(dev, apdev): 274 """hostapd and SET deny_mac_file ctrl_iface command""" 275 ssid = "hapd-ctrl" 276 filename = hostapd.acl_file(dev, apdev, 'hostapd.macaddr') 277 params = {"ssid": ssid} 278 hapd = hostapd.add_ap(apdev[0], params) 279 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412") 280 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412") 281 hapd.send_file(filename, filename) 282 if "OK" not in hapd.request("SET deny_mac_file " + filename): 283 raise Exception("Unexpected SET failure") 284 dev[0].wait_disconnected(timeout=15) 285 ev = dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"], 1) 286 if ev is not None: 287 raise Exception("Unexpected disconnection") 288 if filename.startswith('/tmp/'): 289 os.unlink(filename) 290 291def test_hapd_ctrl_set_accept_mac_file(dev, apdev): 292 """hostapd and SET accept_mac_file ctrl_iface command""" 293 ssid = "hapd-ctrl" 294 filename = hostapd.acl_file(dev, apdev, 'hostapd.macaddr') 295 params = {"ssid": ssid} 296 hapd = hostapd.add_ap(apdev[0], params) 297 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412") 298 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412") 299 hapd.send_file(filename, filename) 300 hapd.request("SET macaddr_acl 1") 301 if "OK" not in hapd.request("SET accept_mac_file " + filename): 302 raise Exception("Unexpected SET failure") 303 dev[1].wait_disconnected(timeout=15) 304 ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], 1) 305 if ev is not None: 306 raise Exception("Unexpected disconnection") 307 if filename.startswith('/tmp/'): 308 os.unlink(filename) 309 310def test_hapd_ctrl_set_accept_mac_file_vlan(dev, apdev): 311 """hostapd and SET accept_mac_file ctrl_iface command (VLAN ID)""" 312 ssid = "hapd-ctrl" 313 filename = hostapd.acl_file(dev, apdev, 'hostapd.accept') 314 params = {"ssid": ssid} 315 hapd = hostapd.add_ap(apdev[0], params) 316 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412") 317 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412") 318 hapd.send_file(filename, filename) 319 hapd.request("SET macaddr_acl 1") 320 if "OK" not in hapd.request("SET accept_mac_file " + filename): 321 raise Exception("Unexpected SET failure") 322 dev[1].wait_disconnected(timeout=15) 323 dev[0].wait_disconnected(timeout=15) 324 if filename.startswith('/tmp/'): 325 os.unlink(filename) 326 327@remote_compatible 328def test_hapd_ctrl_set_error_cases(dev, apdev): 329 """hostapd and SET error cases""" 330 ssid = "hapd-ctrl" 331 params = {"ssid": ssid} 332 hapd = hostapd.add_ap(apdev[0], params) 333 errors = ["wpa_key_mgmt FOO", 334 "wpa_key_mgmt WPA-PSK \t FOO", 335 "wpa_key_mgmt \t ", 336 "wpa_pairwise FOO", 337 "wpa_pairwise \t ", 338 'wep_key0 "', 339 'wep_key0 "abcde', 340 "wep_key0 1", 341 "wep_key0 12q3456789", 342 "wep_key_len_broadcast 20", 343 "wep_rekey_period -1", 344 "wep_default_key 4", 345 "r0kh 02:00:00:00:03:0q nas1.w1.fi 100102030405060708090a0b0c0d0e0f100102030405060708090a0b0c0d0e0f", 346 "r0kh 02:00:00:00:03:00 12345678901234567890123456789012345678901234567890.nas1.w1.fi 100102030405060708090a0b0c0d0e0f100102030405060708090a0b0c0d0e0f", 347 "r0kh 02:00:00:00:03:00 nas1.w1.fi 100q02030405060708090a0b0c0d0e0f100q02030405060708090a0b0c0d0e0f", 348 "r1kh 02:00:00:00:04:q0 00:01:02:03:04:06 200102030405060708090a0b0c0d0e0f200102030405060708090a0b0c0d0e0f", 349 "r1kh 02:00:00:00:04:00 00:01:02:03:04:q6 200102030405060708090a0b0c0d0e0f200102030405060708090a0b0c0d0e0f", 350 "r1kh 02:00:00:00:04:00 00:01:02:03:04:06 2q0102030405060708090a0b0c0d0e0f2q0102030405060708090a0b0c0d0e0f", 351 "roaming_consortium 1", 352 "roaming_consortium 12", 353 "roaming_consortium 112233445566778899aabbccddeeff00", 354 'venue_name P"engExample venue"', 355 'venue_name P"engExample venue', 356 "venue_name engExample venue", 357 "venue_name e:Example venue", 358 "venue_name eng1:Example venue", 359 "venue_name eng:Example venue 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", 360 "anqp_3gpp_cell_net abc", 361 "anqp_3gpp_cell_net ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;", 362 "anqp_3gpp_cell_net 244", 363 "anqp_3gpp_cell_net 24,123", 364 "anqp_3gpp_cell_net 244,1", 365 "anqp_3gpp_cell_net 244,1234", 366 "nai_realm 0", 367 "nai_realm 0,1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.nas1.w1.fi", 368 "nai_realm 0,example.org,1,2,3,4,5,6,7,8", 369 "nai_realm 0,example.org,1[1:1][2:2][3:3][4:4][5:5]", 370 "nai_realm 0,example.org,1[1]", 371 "nai_realm 0,example.org,1[1:1", 372 "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", 373 "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", 374 "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,300", 375 "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,-1", 376 "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,255,1", 377 "qos_map_set 1", 378 "qos_map_set 1,2", 379 "hs20_conn_capab 1", 380 "hs20_conn_capab 6:22", 381 "hs20_wan_metrics 0q:8000:1000:80:240:3000", 382 "hs20_wan_metrics 01", 383 "hs20_wan_metrics 01:8000", 384 "hs20_wan_metrics 01:8000:1000", 385 "hs20_wan_metrics 01:8000:1000:80", 386 "hs20_wan_metrics 01:8000:1000:80:240", 387 "hs20_oper_friendly_name eng1:Example", 388 "hs20_icon 32", 389 "hs20_icon 32:32", 390 "hs20_icon 32:32:eng", 391 "hs20_icon 32:32:eng:image/png", 392 "hs20_icon 32:32:eng:image/png:icon32", 393 "hs20_icon 32:32:eng:image/png:123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890:/tmp/icon32.png", 394 "hs20_icon 32:32:eng:image/png:name:/tmp/123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.png", 395 "ssid 1234567890123456789012345678901234567890", 396 "pac_opaque_encr_key 123456", 397 "eap_fast_a_id 12345", 398 "eap_fast_a_id 12345q", 399 "own_ip_addr foo", 400 "auth_server_addr foo2", 401 "auth_server_shared_secret ", 402 "acct_server_addr foo3", 403 "acct_server_shared_secret ", 404 "radius_auth_req_attr 123::", 405 "radius_acct_req_attr 123::", 406 "radius_das_client 192.168.1.123", 407 "radius_das_client 192.168.1.1a foo", 408 "auth_algs 0", 409 "max_num_sta -1", 410 "max_num_sta 1000000", 411 "wpa_passphrase 1234567", 412 "wpa_passphrase 1234567890123456789012345678901234567890123456789012345678901234", 413 "wpa_psk 1234567890123456789012345678901234567890123456789012345678901234a", 414 "wpa_psk 12345678901234567890123456789012345678901234567890123456789012", 415 "wpa_psk_radius 123", 416 "wpa_pairwise NONE", 417 "wpa_pairwise WEP40", 418 "wpa_pairwise WEP104", 419 "rsn_pairwise NONE", 420 "rsn_pairwise WEP40", 421 "rsn_pairwise WEP104", 422 "mobility_domain 01", 423 "r1_key_holder 0011223344", 424 "ctrl_interface_group nosuchgrouphere", 425 "hw_mode foo", 426 "wps_rf_bands foo", 427 "beacon_int 0", 428 "beacon_int 65536", 429 "acs_num_scans 0", 430 "acs_num_scans 101", 431 "rts_threshold -2", 432 "rts_threshold 65536", 433 "fragm_threshold -2", 434 "fragm_threshold 2347", 435 "send_probe_response -1", 436 "send_probe_response 2", 437 "vlan_naming -1", 438 "vlan_naming 10000000", 439 "group_mgmt_cipher FOO", 440 "assoc_sa_query_max_timeout 0", 441 "assoc_sa_query_retry_timeout 0", 442 "wps_state -1", 443 "wps_state 3", 444 "uuid FOO", 445 "device_name 1234567890123456789012345678901234567890", 446 "manufacturer 1234567890123456789012345678901234567890123456789012345678901234567890", 447 "model_name 1234567890123456789012345678901234567890", 448 "model_number 1234567890123456789012345678901234567890", 449 "serial_number 1234567890123456789012345678901234567890", 450 "device_type FOO", 451 "os_version 1", 452 "ap_settings /tmp/does/not/exist/ap-settings.foo", 453 "wps_nfc_dev_pw_id 4", 454 "wps_nfc_dev_pw_id 100000", 455 "time_zone A", 456 "access_network_type -1", 457 "access_network_type 16", 458 "hessid 00:11:22:33:44", 459 "network_auth_type 0q", 460 "ipaddr_type_availability 1q", 461 "hs20_operating_class 0", 462 "hs20_operating_class 0q", 463 "bss_load_test ", 464 "bss_load_test 12", 465 "bss_load_test 12:80", 466 "vendor_elements 0", 467 "vendor_elements 0q", 468 "assocresp_elements 0", 469 "assocresp_elements 0q", 470 "local_pwr_constraint -1", 471 "local_pwr_constraint 256", 472 "wmm_ac_bk_cwmin -1", 473 "wmm_ac_be_cwmin 16", 474 "wmm_ac_vi_cwmax -1", 475 "wmm_ac_vo_cwmax 16", 476 "wmm_ac_foo_cwmax 6", 477 "wmm_ac_bk_aifs 0", 478 "wmm_ac_bk_aifs 256", 479 "wmm_ac_bk_txop_limit -1", 480 "wmm_ac_bk_txop_limit 65536", 481 "wmm_ac_bk_acm -1", 482 "wmm_ac_bk_acm 2", 483 "wmm_ac_bk_foo 2", 484 "tx_queue_foo_aifs 3", 485 "tx_queue_data3_cwmin 4", 486 "tx_queue_data3_cwmax 4", 487 "tx_queue_data3_aifs -4", 488 "tx_queue_data3_foo 1"] 489 for e in errors: 490 if "FAIL" not in hapd.request("SET " + e): 491 raise Exception("Unexpected SET success: '%s'" % e) 492 493 no_err = ["wps_nfc_dh_pubkey 0", 494 "wps_nfc_dh_privkey 0q", 495 "wps_nfc_dev_pw 012", 496 "manage_p2p 0", 497 "disassoc_low_ack 0", 498 "network_auth_type 01", 499 "tdls_prohibit 0", 500 "tdls_prohibit_chan_switch 0"] 501 for e in no_err: 502 if "OK" not in hapd.request("SET " + e): 503 raise Exception("Unexpected SET failure: '%s'" % e) 504 505@remote_compatible 506def test_hapd_ctrl_global(dev, apdev): 507 """hostapd and GET ctrl_iface command""" 508 ssid = "hapd-ctrl" 509 params = {"ssid": ssid} 510 ifname = apdev[0]['ifname'] 511 hapd = hostapd.add_ap(apdev[0], params) 512 hapd_global = hostapd.HostapdGlobal(apdev[0]) 513 res = hapd_global.request("IFNAME=" + ifname + " PING") 514 if "PONG" not in res: 515 raise Exception("Could not ping hostapd interface " + ifname + " via global control interface") 516 res = hapd_global.request("IFNAME=" + ifname + " GET version") 517 if "FAIL" in res: 518 raise Exception("Could not get hostapd version for " + ifname + " via global control interface") 519 res = hapd_global.request("IFNAME=no-such-ifname GET version") 520 if "FAIL-NO-IFNAME-MATCH" not in res: 521 raise Exception("Invalid ifname not reported") 522 res = hapd_global.request("INTERFACES") 523 if "FAIL" in res: 524 raise Exception("INTERFACES command failed") 525 if apdev[0]['ifname'] not in res.splitlines(): 526 raise Exception("AP interface missing from INTERFACES") 527 res = hapd_global.request("INTERFACES ctrl") 528 if "FAIL" in res: 529 raise Exception("INTERFACES ctrl command failed") 530 if apdev[0]['ifname'] + " ctrl_iface=" not in res: 531 raise Exception("AP interface missing from INTERFACES ctrl") 532 533 if "FAIL" not in hapd_global.request("DETACH"): 534 raise Exception("DETACH succeeded unexpectedly") 535 536def dup_network(hapd_global, src, dst, param): 537 res = hapd_global.request("DUP_NETWORK %s %s %s" % (src, dst, param)) 538 if "OK" not in res: 539 raise Exception("Could not dup %s param from %s to %s" % (param, src, 540 dst)) 541 542def test_hapd_dup_network_global_wpa2(dev, apdev): 543 """hostapd and DUP_NETWORK command (WPA2)""" 544 passphrase = "12345678" 545 src_ssid = "hapd-ctrl-src" 546 dst_ssid = "hapd-ctrl-dst" 547 548 src_params = hostapd.wpa2_params(ssid=src_ssid, passphrase=passphrase) 549 src_ifname = apdev[0]['ifname'] 550 src_hapd = hostapd.add_ap(apdev[0], src_params) 551 552 dst_params = {"ssid": dst_ssid} 553 dst_ifname = apdev[1]['ifname'] 554 dst_hapd = hostapd.add_ap(apdev[1], dst_params, no_enable=True) 555 556 hapd_global = hostapd.HostapdGlobal() 557 558 for param in ["wpa", "wpa_passphrase", "wpa_key_mgmt", "rsn_pairwise"]: 559 dup_network(hapd_global, src_ifname, dst_ifname, param) 560 561 dst_hapd.enable() 562 563 dev[0].connect(dst_ssid, psk=passphrase, proto="RSN", pairwise="CCMP", 564 scan_freq="2412") 565 addr = dev[0].own_addr() 566 if "FAIL" in dst_hapd.request("STA " + addr): 567 raise Exception("Could not connect using duplicated wpa params") 568 569 tests = ["a", 570 "no-such-ifname no-such-ifname", 571 src_ifname + " no-such-ifname", 572 src_ifname + " no-such-ifname no-such-param", 573 src_ifname + " " + dst_ifname + " no-such-param"] 574 for t in tests: 575 if "FAIL" not in hapd_global.request("DUP_NETWORK " + t): 576 raise Exception("Invalid DUP_NETWORK accepted: " + t) 577 with alloc_fail(src_hapd, 1, "hostapd_ctrl_iface_dup_param"): 578 if "FAIL" not in hapd_global.request("DUP_NETWORK %s %s wpa" % (src_ifname, dst_ifname)): 579 raise Exception("DUP_NETWORK accepted during OOM") 580 581def test_hapd_dup_network_global_wpa(dev, apdev): 582 """hostapd and DUP_NETWORK command (WPA)""" 583 skip_with_fips(dev[0]) 584 skip_without_tkip(dev[0]) 585 psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6' 586 src_ssid = "hapd-ctrl-src" 587 dst_ssid = "hapd-ctrl-dst" 588 589 src_params = hostapd.wpa_params(ssid=src_ssid) 590 src_params['wpa_psk'] = psk 591 src_ifname = apdev[0]['ifname'] 592 src_hapd = hostapd.add_ap(apdev[0], src_params) 593 594 dst_params = {"ssid": dst_ssid} 595 dst_ifname = apdev[1]['ifname'] 596 dst_hapd = hostapd.add_ap(apdev[1], dst_params, no_enable=True) 597 598 hapd_global = hostapd.HostapdGlobal() 599 600 for param in ["wpa", "wpa_psk", "wpa_key_mgmt", "wpa_pairwise"]: 601 dup_network(hapd_global, src_ifname, dst_ifname, param) 602 603 dst_hapd.enable() 604 605 dev[0].connect(dst_ssid, raw_psk=psk, proto="WPA", pairwise="TKIP", 606 scan_freq="2412") 607 addr = dev[0].own_addr() 608 if "FAIL" in dst_hapd.request("STA " + addr): 609 raise Exception("Could not connect using duplicated wpa params") 610 611@remote_compatible 612def test_hapd_ctrl_log_level(dev, apdev): 613 """hostapd ctrl_iface LOG_LEVEL""" 614 hapd = hostapd.add_ap(apdev[0], {"ssid": "open"}) 615 level = hapd.request("LOG_LEVEL") 616 if "Current level: MSGDUMP" not in level: 617 raise Exception("Unexpected debug level(1): " + level) 618 if "Timestamp: 1" not in level: 619 raise Exception("Unexpected timestamp(1): " + level) 620 621 if "OK" not in hapd.request("LOG_LEVEL MSGDUMP 0"): 622 raise Exception("LOG_LEVEL failed") 623 level = hapd.request("LOG_LEVEL") 624 if "Current level: MSGDUMP" not in level: 625 raise Exception("Unexpected debug level(2): " + level) 626 if "Timestamp: 0" not in level: 627 raise Exception("Unexpected timestamp(2): " + level) 628 629 if "OK" not in hapd.request("LOG_LEVEL MSGDUMP 1"): 630 raise Exception("LOG_LEVEL failed") 631 level = hapd.request("LOG_LEVEL") 632 if "Current level: MSGDUMP" not in level: 633 raise Exception("Unexpected debug level(3): " + level) 634 if "Timestamp: 1" not in level: 635 raise Exception("Unexpected timestamp(3): " + level) 636 637 if "FAIL" not in hapd.request("LOG_LEVEL FOO"): 638 raise Exception("Invalid LOG_LEVEL accepted") 639 640 for lev in ["EXCESSIVE", "MSGDUMP", "DEBUG", "INFO", "WARNING", "ERROR"]: 641 if "OK" not in hapd.request("LOG_LEVEL " + lev): 642 raise Exception("LOG_LEVEL failed for " + lev) 643 level = hapd.request("LOG_LEVEL") 644 if "Current level: " + lev not in level: 645 raise Exception("Unexpected debug level: " + level) 646 647 if "OK" not in hapd.request("LOG_LEVEL MSGDUMP 1"): 648 raise Exception("LOG_LEVEL failed") 649 level = hapd.request("LOG_LEVEL") 650 if "Current level: MSGDUMP" not in level: 651 raise Exception("Unexpected debug level(3): " + level) 652 if "Timestamp: 1" not in level: 653 raise Exception("Unexpected timestamp(3): " + level) 654 655@remote_compatible 656def test_hapd_ctrl_disconnect_no_tx(dev, apdev): 657 """hostapd disconnecting STA without transmitting Deauth/Disassoc""" 658 ssid = "hapd-test" 659 passphrase = "12345678" 660 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase) 661 hapd = hostapd.add_ap(apdev[0], params) 662 bssid = apdev[0]['bssid'] 663 dev[0].connect(ssid, psk=passphrase, scan_freq="2412") 664 addr0 = dev[0].own_addr() 665 dev[1].connect(ssid, psk=passphrase, scan_freq="2412") 666 addr1 = dev[1].own_addr() 667 668 # Disconnect the STA without sending out Deauthentication frame 669 if "OK" not in hapd.request("DEAUTHENTICATE " + addr0 + " tx=0"): 670 raise Exception("DEAUTHENTICATE command failed") 671 # Force disconnection due to AP receiving a frame from not-asssociated STA 672 dev[0].request("DATA_TEST_CONFIG 1") 673 dev[0].request("DATA_TEST_TX " + bssid + " " + addr0) 674 ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5) 675 dev[0].request("DATA_TEST_CONFIG 0") 676 if ev is None: 677 raise Exception("Disconnection event not seen after TX attempt") 678 if "reason=7" not in ev: 679 raise Exception("Unexpected disconnection reason: " + ev) 680 681 # Disconnect the STA without sending out Disassociation frame 682 if "OK" not in hapd.request("DISASSOCIATE " + addr1 + " tx=0"): 683 raise Exception("DISASSOCIATE command failed") 684 # Force disconnection due to AP receiving a frame from not-asssociated STA 685 dev[1].request("DATA_TEST_CONFIG 1") 686 dev[1].request("DATA_TEST_TX " + bssid + " " + addr1) 687 ev = dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5) 688 dev[1].request("DATA_TEST_CONFIG 0") 689 if ev is None: 690 raise Exception("Disconnection event not seen after TX attempt") 691 if "reason=7" not in ev: 692 raise Exception("Unexpected disconnection reason: " + ev) 693 694def test_hapd_ctrl_mib(dev, apdev): 695 """hostapd and MIB ctrl_iface command with open network""" 696 ssid = "hapd-ctrl" 697 params = {"ssid": ssid} 698 hapd = hostapd.add_ap(apdev[0], params) 699 700 mib = hapd.request("MIB") 701 if len(mib) != 0: 702 raise Exception("Unexpected MIB response: " + mib) 703 704 mib = hapd.request("MIB radius_server") 705 if len(mib) != 0: 706 raise Exception("Unexpected 'MIB radius_server' response: " + mib) 707 708 if "FAIL" not in hapd.request("MIB foo"): 709 raise Exception("'MIB foo' succeeded") 710 711 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412") 712 713 mib = hapd.request("MIB") 714 if "FAIL" in mib: 715 raise Exception("Unexpected MIB response: " + mib) 716 717 mib = hapd.request("MIB radius_server") 718 if len(mib) != 0: 719 raise Exception("Unexpected 'MIB radius_server' response: " + mib) 720 721 if "FAIL" not in hapd.request("MIB foo"): 722 raise Exception("'MIB foo' succeeded") 723 724def test_hapd_ctrl_not_yet_fully_enabled(dev, apdev): 725 """hostapd and ctrl_iface commands when BSS not yet fully enabled""" 726 ssid = "hapd-ctrl" 727 params = {"ssid": ssid} 728 hapd = hostapd.add_ap(apdev[0], params, no_enable=True) 729 730 if not hapd.ping(): 731 raise Exception("PING failed") 732 if "FAIL" in hapd.request("MIB"): 733 raise Exception("MIB failed") 734 if len(hapd.request("MIB radius_server")) != 0: 735 raise Exception("Unexpected 'MIB radius_server' response") 736 if "state=UNINITIALIZED" not in hapd.request("STATUS"): 737 raise Exception("Unexpected STATUS response") 738 if "FAIL" not in hapd.request("STATUS-DRIVER"): 739 raise Exception("Unexpected response to STATUS-DRIVER") 740 if len(hapd.request("STA-FIRST")) != 0: 741 raise Exception("Unexpected response to STA-FIRST") 742 if "FAIL" not in hapd.request("STA ff:ff:ff:ff:ff:ff"): 743 raise Exception("Unexpected response to STA") 744 cmds = ["NEW_STA 02:ff:ff:ff:ff:ff", 745 "DEAUTHENTICATE 02:ff:ff:ff:ff:ff", 746 "DEAUTHENTICATE 02:ff:ff:ff:ff:ff test=0", 747 "DEAUTHENTICATE 02:ff:ff:ff:ff:ff p2p=0", 748 "DEAUTHENTICATE 02:ff:ff:ff:ff:ff tx=0", 749 "DISASSOCIATE 02:ff:ff:ff:ff:ff", 750 "DISASSOCIATE 02:ff:ff:ff:ff:ff test=0", 751 "DISASSOCIATE 02:ff:ff:ff:ff:ff p2p=0", 752 "DISASSOCIATE 02:ff:ff:ff:ff:ff tx=0", 753 "SA_QUERY 02:ff:ff:ff:ff:ff", 754 "WPS_PIN any 12345670", 755 "WPS_PBC", 756 "WPS_CANCEL", 757 "WPS_AP_PIN random", 758 "WPS_AP_PIN disable", 759 "WPS_CHECK_PIN 123456789", 760 "WPS_GET_STATUS", 761 "WPS_NFC_TAG_READ 00", 762 "WPS_NFC_CONFIG_TOKEN NDEF", 763 "WPS_NFC_TOKEN WPS", 764 "NFC_GET_HANDOVER_SEL NDEF WPS-CR", 765 "NFC_REPORT_HANDOVER RESP WPS 00 00", 766 "SET_QOS_MAP_SET 22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,48,55", 767 "SEND_QOS_MAP_CONF 02:ff:ff:ff:ff:ff", 768 "HS20_WNM_NOTIF 02:ff:ff:ff:ff:ff https://example.com/", 769 "HS20_DEAUTH_REQ 02:ff:ff:ff:ff:ff 1 120 https://example.com/", 770 "DISASSOC_IMMINENT 02:ff:ff:ff:ff:ff 10", 771 "ESS_DISASSOC 02:ff:ff:ff:ff:ff 10 https://example.com/", 772 "BSS_TM_REQ 02:ff:ff:ff:ff:ff", 773 "GET_CONFIG", 774 "RADAR DETECTED freq=5260 ht_enabled=1 chan_width=1", 775 "CHAN_SWITCH 5 5200 ht sec_channel_offset=-1 bandwidth=40", 776 "TRACK_STA_LIST", 777 "PMKSA", 778 "PMKSA_FLUSH", 779 "SET_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1\"", 780 "REMOVE_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1\"", 781 "REQ_LCI 00:11:22:33:44:55", 782 "REQ_RANGE 00:11:22:33:44:55", 783 "DRIVER_FLAGS", 784 "STOP_AP"] 785 for cmd in cmds: 786 hapd.request(cmd) 787 788def test_hapd_ctrl_set(dev, apdev): 789 """hostapd and SET ctrl_iface command""" 790 ssid = "hapd-ctrl" 791 params = {"ssid": ssid} 792 hapd = hostapd.add_ap(apdev[0], params) 793 tests = ["foo", 794 "wps_version_number 300", 795 "gas_frag_limit 0", 796 "mbo_assoc_disallow 0"] 797 for t in tests: 798 if "FAIL" not in hapd.request("SET " + t): 799 raise Exception("Invalid SET command accepted: " + t) 800 801def test_hapd_ctrl_radar(dev, apdev): 802 """hostapd and RADAR ctrl_iface command""" 803 ssid = "hapd-ctrl" 804 params = {"ssid": ssid} 805 hapd = hostapd.add_ap(apdev[0], params) 806 807 tests = ["foo", "foo bar"] 808 for t in tests: 809 if "FAIL" not in hapd.request("RADAR " + t): 810 raise Exception("Invalid RADAR command accepted: " + t) 811 812 tests = ["DETECTED freq=2412 chan_offset=12 cf1=1234 cf2=2345", 813 "CAC-FINISHED freq=2412", 814 "CAC-ABORTED freq=2412", 815 "NOP-FINISHED freq=2412"] 816 for t in tests: 817 hapd.request("RADAR " + t) 818 819def test_hapd_ctrl_ext_io_errors(dev, apdev): 820 """hostapd and external I/O errors""" 821 ssid = "hapd-ctrl" 822 params = {"ssid": ssid} 823 hapd = hostapd.add_ap(apdev[0], params) 824 tests = ["MGMT_TX 1", 825 "MGMT_TX 1q", 826 "MGMT_RX_PROCESS freq=2412", 827 "MGMT_TX_STATUS_PROCESS style=1 ok=0 buf=12345678", 828 "EAPOL_RX foo", 829 "EAPOL_RX 00:11:22:33:44:55 1", 830 "EAPOL_RX 00:11:22:33:44:55 1q"] 831 for t in tests: 832 if "FAIL" not in hapd.request(t): 833 raise Exception("Invalid command accepted: " + t) 834 with alloc_fail(hapd, 1, "=hostapd_ctrl_iface_mgmt_tx"): 835 if "FAIL" not in hapd.request("MGMT_TX 12"): 836 raise Exception("MGMT_TX accepted during OOM") 837 with alloc_fail(hapd, 1, "=hostapd_ctrl_iface_eapol_rx"): 838 if "FAIL" not in hapd.request("EAPOL_RX 00:11:22:33:44:55 11"): 839 raise Exception("EAPOL_RX accepted during OOM") 840 841 hapd.set("ext_mgmt_frame_handling", "1") 842 tests = ["MGMT_RX_PROCESS freq=2412", 843 "MGMT_RX_PROCESS freq=2412 ssi_signal=0", 844 "MGMT_RX_PROCESS freq=2412 frame=1", 845 "MGMT_RX_PROCESS freq=2412 frame=1q", 846 "MGMT_TX_STATUS_PROCESS style=1 ok=0", 847 "MGMT_TX_STATUS_PROCESS style=1 ok=0 buf=1234567", 848 "MGMT_TX_STATUS_PROCESS style=1 ok=0 buf=1234567q"] 849 for t in tests: 850 if "FAIL" not in hapd.request(t): 851 raise Exception("Invalid command accepted: " + t) 852 with alloc_fail(hapd, 1, "=hostapd_ctrl_iface_mgmt_rx_process"): 853 if "FAIL" not in hapd.request("MGMT_RX_PROCESS freq=2412 frame=11"): 854 raise Exception("MGMT_RX_PROCESS accepted during OOM") 855 hapd.set("ext_mgmt_frame_handling", "0") 856 857 if "OK" not in hapd.request("DATA_TEST_CONFIG 1"): 858 raise Exception("Failed to enable l2_test") 859 if "OK" not in hapd.request("DATA_TEST_CONFIG 1"): 860 raise Exception("Failed to enable l2_test(2)") 861 tests = ["DATA_TEST_TX foo", 862 "DATA_TEST_TX 00:11:22:33:44:55 foo", 863 "DATA_TEST_TX 00:11:22:33:44:55 00:11:22:33:44:55 -1", 864 "DATA_TEST_TX 00:11:22:33:44:55 00:11:22:33:44:55 256"] 865 for t in tests: 866 if "FAIL" not in hapd.request(t): 867 raise Exception("Invalid command accepted: " + t) 868 if "OK" not in hapd.request("DATA_TEST_CONFIG 0"): 869 raise Exception("Failed to disable l2_test") 870 tests = ["DATA_TEST_TX 00:11:22:33:44:55 00:11:22:33:44:55 0", 871 "DATA_TEST_FRAME ifname=foo", 872 "DATA_TEST_FRAME 1", 873 "DATA_TEST_FRAME 11", 874 "DATA_TEST_FRAME 112233445566778899aabbccddeefq"] 875 for t in tests: 876 if "FAIL" not in hapd.request(t): 877 raise Exception("Invalid command accepted: " + t) 878 with alloc_fail(hapd, 1, "=hostapd_ctrl_iface_data_test_frame"): 879 if "FAIL" not in hapd.request("DATA_TEST_FRAME 112233445566778899aabbccddeeff"): 880 raise Exception("DATA_TEST_FRAME accepted during OOM") 881 882def test_hapd_ctrl_vendor_test(dev, apdev): 883 """hostapd and VENDOR test command""" 884 ssid = "hapd-ctrl" 885 params = {"ssid": ssid} 886 hapd = hostapd.add_ap(apdev[0], params) 887 888 OUI_QCA = 0x001374 889 QCA_NL80211_VENDOR_SUBCMD_TEST = 1 890 QCA_WLAN_VENDOR_ATTR_TEST = 8 891 attr = struct.pack("@HHI", 4 + 4, QCA_WLAN_VENDOR_ATTR_TEST, 123) 892 cmd = "VENDOR %x %d %s" % (OUI_QCA, QCA_NL80211_VENDOR_SUBCMD_TEST, binascii.hexlify(attr).decode()) 893 894 res = hapd.request(cmd) 895 if "FAIL" in res: 896 raise Exception("VENDOR command failed") 897 val, = struct.unpack("@I", binascii.unhexlify(res)) 898 if val != 125: 899 raise Exception("Incorrect response value") 900 901 res = hapd.request(cmd + " nested=1") 902 if "FAIL" in res: 903 raise Exception("VENDOR command failed") 904 val, = struct.unpack("@I", binascii.unhexlify(res)) 905 if val != 125: 906 raise Exception("Incorrect response value") 907 908 res = hapd.request(cmd + " nested=0") 909 if "FAIL" not in res: 910 raise Exception("VENDOR command with invalid (not nested) data accepted") 911 912def test_hapd_ctrl_vendor_errors(dev, apdev): 913 """hostapd and VENDOR errors""" 914 ssid = "hapd-ctrl" 915 params = {"ssid": ssid} 916 hapd = hostapd.add_ap(apdev[0], params) 917 tests = ["q", 918 "10q", 919 "10 10q", 920 "10 10 123q", 921 "10 10"] 922 for t in tests: 923 if "FAIL" not in hapd.request("VENDOR " + t): 924 raise Exception("Invalid VENDOR command accepted: " + t) 925 with alloc_fail(hapd, 1, "=hostapd_ctrl_iface_vendor"): 926 if "FAIL" not in hapd.request("VENDOR 10 10 10"): 927 raise Exception("VENDOR accepted during OOM") 928 with alloc_fail(hapd, 1, "wpabuf_alloc;hostapd_ctrl_iface_vendor"): 929 if "FAIL" not in hapd.request("VENDOR 10 10"): 930 raise Exception("VENDOR accepted during OOM") 931 932def test_hapd_ctrl_eapol_reauth_errors(dev, apdev): 933 """hostapd and EAPOL_REAUTH errors""" 934 ssid = "hapd-ctrl" 935 params = {"ssid": ssid} 936 hapd = hostapd.add_ap(apdev[0], params) 937 tests = ["foo", 938 "11:22:33:44:55:66"] 939 for t in tests: 940 if "FAIL" not in hapd.request("EAPOL_REAUTH " + t): 941 raise Exception("Invalid EAPOL_REAUTH command accepted: " + t) 942 943def test_hapd_ctrl_eapol_relog(dev, apdev): 944 """hostapd and RELOG""" 945 ssid = "hapd-ctrl" 946 params = {"ssid": ssid} 947 hapd = hostapd.add_ap(apdev[0], params) 948 if "OK" not in hapd.request("RELOG"): 949 raise Exception("RELOG failed") 950 951def test_hapd_ctrl_poll_sta_errors(dev, apdev): 952 """hostapd and POLL_STA errors""" 953 ssid = "hapd-ctrl" 954 params = {"ssid": ssid} 955 hapd = hostapd.add_ap(apdev[0], params) 956 tests = ["foo", 957 "11:22:33:44:55:66"] 958 for t in tests: 959 if "FAIL" not in hapd.request("POLL_STA " + t): 960 raise Exception("Invalid POLL_STA command accepted: " + t) 961 962def test_hapd_ctrl_update_beacon(dev, apdev): 963 """hostapd and UPDATE_BEACON""" 964 ssid = "hapd-ctrl" 965 params = {"ssid": ssid} 966 hapd = hostapd.add_ap(apdev[0], params) 967 if "OK" not in hapd.request("UPDATE_BEACON"): 968 raise Exception("UPDATE_BEACON failed") 969 with fail_test(hapd, 1, "ieee802_11_set_beacon"): 970 if "FAIL" not in hapd.request("UPDATE_BEACON"): 971 raise Exception("UPDATE_BEACON succeeded unexpectedly") 972 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412") 973 dev[0].request("DISCONNECT") 974 if "OK" not in hapd.request("UPDATE_BEACON"): 975 raise Exception("UPDATE_BEACON failed") 976 hapd.disable() 977 if "FAIL" not in hapd.request("UPDATE_BEACON"): 978 raise Exception("UPDATE_BEACON did not indicate failure when disabled") 979 980def test_hapd_ctrl_test_fail(dev, apdev): 981 """hostapd and TEST_ALLOC_FAIL/TEST_FAIL""" 982 ssid = "hapd-ctrl" 983 params = {"ssid": ssid} 984 hapd = hostapd.add_ap(apdev[0], params) 985 if "OK" not in hapd.request("TEST_ALLOC_FAIL 1:unknownfunc"): 986 raise HwsimSkip("TEST_ALLOC_FAIL not supported") 987 if "OK" not in hapd.request("TEST_ALLOC_FAIL "): 988 raise Exception("TEST_ALLOC_FAIL clearing failed") 989 if "OK" not in hapd.request("TEST_FAIL "): 990 raise Exception("TEST_FAIL clearing failed") 991 992def test_hapd_ctrl_setband(dev, apdev): 993 """hostapd and setband""" 994 ssid = "hapd-ctrl" 995 params = {"ssid": ssid} 996 hapd = hostapd.add_ap(apdev[0], params) 997 # The actual setband driver operations are not supported without vendor 998 # commands, so only check minimal parsing items here. 999 if "FAIL" not in hapd.request("SET setband foo"): 1000 raise Exception("Invalid setband value accepted") 1001 vals = ["5G", "6G", "2G", "2G,6G", "2G,5G,6G", "AUTO"] 1002 for val in vals: 1003 if "OK" not in hapd.request("SET setband " + val): 1004 raise Exception("SET setband %s failed" % val) 1005 1006def test_hapd_ctrl_get_capability(dev, apdev): 1007 """hostapd GET_CAPABILITY""" 1008 ssid = "hapd-ctrl" 1009 params = {"ssid": ssid} 1010 hapd = hostapd.add_ap(apdev[0], params) 1011 if "FAIL" not in hapd.request("GET_CAPABILITY "): 1012 raise Exception("Invalid GET_CAPABILITY accepted") 1013 res = hapd.request("GET_CAPABILITY dpp") 1014 logger.info("DPP capability: " + res) 1015 1016def test_hapd_ctrl_pmksa_add_failures(dev, apdev): 1017 """hostapd PMKSA_ADD failures""" 1018 ssid = "hapd-ctrl" 1019 params = {"ssid": ssid} 1020 hapd = hostapd.add_ap(apdev[0], params) 1021 tests = ["q", 1022 "22:22:22:22:22:22", 1023 "22:22:22:22:22:22 q", 1024 "22:22:22:22:22:22 " + 16*'00', 1025 "22:22:22:22:22:22 " + 16*"00" + " " + 10*"00", 1026 "22:22:22:22:22:22 " + 16*"00" + " q", 1027 "22:22:22:22:22:22 " + 16*"00" + " " + 200*"00", 1028 "22:22:22:22:22:22 " + 16*"00" + " " + 32*"00" + " 12345", 1029 "22:22:22:22:22:22 " + 16*"00" + " " + 32*"00" + " 12345 1", 1030 ""] 1031 for t in tests: 1032 if "FAIL" not in hapd.request("PMKSA_ADD " + t): 1033 raise Exception("Invalid PMKSA_ADD accepted: " + t) 1034 1035def test_hapd_ctrl_attach_errors(dev, apdev): 1036 """hostapd ATTACH errors""" 1037 params = {"ssid": "hapd-ctrl"} 1038 hapd = hostapd.add_ap(apdev[0], params) 1039 hglobal = hostapd.HostapdGlobal(apdev[0]) 1040 with alloc_fail(hapd, 1, "ctrl_iface_attach"): 1041 if "FAIL" not in hapd.request("ATTACH foo"): 1042 raise Exception("Invalid ATTACH accepted") 1043 with alloc_fail(hapd, 1, "ctrl_iface_attach"): 1044 if "FAIL" not in hglobal.request("ATTACH foo"): 1045 raise Exception("Invalid ATTACH accepted") 1046