test_hapd_ctrl.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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. import hostapd
  7. import hwsim_utils
  8. from utils import skip_with_fips
  9. def test_hapd_ctrl_status(dev, apdev):
  10. """hostapd ctrl_iface STATUS commands"""
  11. ssid = "hapd-ctrl"
  12. bssid = apdev[0]['bssid']
  13. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  14. hapd = hostapd.add_ap(apdev[0], params)
  15. status = hapd.get_status()
  16. driver = hapd.get_driver_status()
  17. if status['bss[0]'] != apdev[0]['ifname']:
  18. raise Exception("Unexpected bss[0]")
  19. if status['ssid[0]'] != ssid:
  20. raise Exception("Unexpected ssid[0]")
  21. if status['bssid[0]'] != bssid:
  22. raise Exception("Unexpected bssid[0]")
  23. if status['freq'] != "2412":
  24. raise Exception("Unexpected freq")
  25. if driver['beacon_set'] != "1":
  26. raise Exception("Unexpected beacon_set")
  27. if driver['addr'] != bssid:
  28. raise Exception("Unexpected addr")
  29. def test_hapd_ctrl_p2p_manager(dev, apdev):
  30. """hostapd as P2P Device manager"""
  31. ssid = "hapd-p2p-mgr"
  32. passphrase = "12345678"
  33. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  34. params['manage_p2p'] = '1'
  35. params['allow_cross_connection'] = '0'
  36. hapd = hostapd.add_ap(apdev[0], params)
  37. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  38. addr = dev[0].own_addr()
  39. if "OK" not in hapd.request("DEAUTHENTICATE " + addr + " p2p=2"):
  40. raise Exception("DEAUTHENTICATE command failed")
  41. dev[0].wait_disconnected(timeout=5)
  42. dev[0].wait_connected(timeout=10, error="Re-connection timed out")
  43. if "OK" not in hapd.request("DISASSOCIATE " + addr + " p2p=2"):
  44. raise Exception("DISASSOCIATE command failed")
  45. dev[0].wait_disconnected(timeout=5)
  46. dev[0].wait_connected(timeout=10, error="Re-connection timed out")
  47. def test_hapd_ctrl_sta(dev, apdev):
  48. """hostapd and STA ctrl_iface commands"""
  49. ssid = "hapd-ctrl-sta"
  50. passphrase = "12345678"
  51. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  52. hapd = hostapd.add_ap(apdev[0], params)
  53. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  54. addr = dev[0].own_addr()
  55. if "FAIL" in hapd.request("STA " + addr):
  56. raise Exception("Unexpected STA failure")
  57. if "FAIL" not in hapd.request("STA " + addr + " eapol"):
  58. raise Exception("Unexpected STA-eapol success")
  59. if "FAIL" not in hapd.request("STA 00:11:22:33:44"):
  60. raise Exception("Unexpected STA success")
  61. if "FAIL" not in hapd.request("STA 00:11:22:33:44:55"):
  62. raise Exception("Unexpected STA success")
  63. if len(hapd.request("STA-NEXT " + addr).splitlines()) > 0:
  64. raise Exception("Unexpected STA-NEXT result")
  65. if "FAIL" not in hapd.request("STA-NEXT 00:11:22:33:44"):
  66. raise Exception("Unexpected STA-NEXT success")
  67. def test_hapd_ctrl_disconnect(dev, apdev):
  68. """hostapd and disconnection ctrl_iface commands"""
  69. ssid = "hapd-ctrl"
  70. passphrase = "12345678"
  71. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  72. hapd = hostapd.add_ap(apdev[0], params)
  73. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  74. addr = dev[0].p2p_dev_addr()
  75. if "FAIL" not in hapd.request("DEAUTHENTICATE 00:11:22:33:44"):
  76. raise Exception("Unexpected DEAUTHENTICATE success")
  77. if "OK" not in hapd.request("DEAUTHENTICATE ff:ff:ff:ff:ff:ff"):
  78. raise Exception("Unexpected DEAUTHENTICATE failure")
  79. dev[0].wait_disconnected(timeout=5)
  80. dev[0].wait_connected(timeout=10, error="Re-connection timed out")
  81. if "FAIL" not in hapd.request("DISASSOCIATE 00:11:22:33:44"):
  82. raise Exception("Unexpected DISASSOCIATE success")
  83. if "OK" not in hapd.request("DISASSOCIATE ff:ff:ff:ff:ff:ff"):
  84. raise Exception("Unexpected DISASSOCIATE failure")
  85. dev[0].wait_disconnected(timeout=5)
  86. dev[0].wait_connected(timeout=10, error="Re-connection timed out")
  87. def test_hapd_ctrl_chan_switch(dev, apdev):
  88. """hostapd and CHAN_SWITCH ctrl_iface command"""
  89. ssid = "hapd-ctrl"
  90. params = { "ssid": ssid }
  91. hapd = hostapd.add_ap(apdev[0], params)
  92. if "FAIL" not in hapd.request("CHAN_SWITCH "):
  93. raise Exception("Unexpected CHAN_SWITCH success")
  94. if "FAIL" not in hapd.request("CHAN_SWITCH qwerty 2422"):
  95. raise Exception("Unexpected CHAN_SWITCH success")
  96. if "FAIL" not in hapd.request("CHAN_SWITCH 5 qwerty"):
  97. raise Exception("Unexpected CHAN_SWITCH success")
  98. if "FAIL" not in hapd.request("CHAN_SWITCH 0 2432 center_freq1=123 center_freq2=234 bandwidth=1000 sec_channel_offset=20 ht vht"):
  99. raise Exception("Unexpected CHAN_SWITCH success")
  100. def test_hapd_ctrl_level(dev, apdev):
  101. """hostapd and LEVEL ctrl_iface command"""
  102. ssid = "hapd-ctrl"
  103. params = { "ssid": ssid }
  104. hapd = hostapd.add_ap(apdev[0], params)
  105. if "FAIL" not in hapd.request("LEVEL 0"):
  106. raise Exception("Unexpected LEVEL success on non-monitor interface")
  107. def test_hapd_ctrl_new_sta(dev, apdev):
  108. """hostapd and NEW_STA ctrl_iface command"""
  109. ssid = "hapd-ctrl"
  110. params = { "ssid": ssid }
  111. hapd = hostapd.add_ap(apdev[0], params)
  112. if "FAIL" not in hapd.request("NEW_STA 00:11:22:33:44"):
  113. raise Exception("Unexpected NEW_STA success")
  114. if "OK" not in hapd.request("NEW_STA 00:11:22:33:44:55"):
  115. raise Exception("Unexpected NEW_STA failure")
  116. if "AUTHORIZED" not in hapd.request("STA 00:11:22:33:44:55"):
  117. raise Exception("Unexpected NEW_STA STA status")
  118. def test_hapd_ctrl_get(dev, apdev):
  119. """hostapd and GET ctrl_iface command"""
  120. ssid = "hapd-ctrl"
  121. params = { "ssid": ssid }
  122. hapd = hostapd.add_ap(apdev[0], params)
  123. if "FAIL" not in hapd.request("GET foo"):
  124. raise Exception("Unexpected GET success")
  125. if "FAIL" in hapd.request("GET version"):
  126. raise Exception("Unexpected GET version failure")
  127. def test_hapd_ctrl_unknown(dev, apdev):
  128. """hostapd and unknown ctrl_iface command"""
  129. ssid = "hapd-ctrl"
  130. params = { "ssid": ssid }
  131. hapd = hostapd.add_ap(apdev[0], params)
  132. if "UNKNOWN COMMAND" not in hapd.request("FOO"):
  133. raise Exception("Unexpected response")
  134. def test_hapd_ctrl_hs20_wnm_notif(dev, apdev):
  135. """hostapd and HS20_WNM_NOTIF ctrl_iface command"""
  136. ssid = "hapd-ctrl"
  137. params = { "ssid": ssid }
  138. hapd = hostapd.add_ap(apdev[0], params)
  139. if "FAIL" not in hapd.request("HS20_WNM_NOTIF 00:11:22:33:44 http://example.com/"):
  140. raise Exception("Unexpected HS20_WNM_NOTIF success")
  141. if "FAIL" not in hapd.request("HS20_WNM_NOTIF 00:11:22:33:44:55http://example.com/"):
  142. raise Exception("Unexpected HS20_WNM_NOTIF success")
  143. def test_hapd_ctrl_hs20_deauth_req(dev, apdev):
  144. """hostapd and HS20_DEAUTH_REQ ctrl_iface command"""
  145. ssid = "hapd-ctrl"
  146. params = { "ssid": ssid }
  147. hapd = hostapd.add_ap(apdev[0], params)
  148. if "FAIL" not in hapd.request("HS20_DEAUTH_REQ 00:11:22:33:44 1 120 http://example.com/"):
  149. raise Exception("Unexpected HS20_DEAUTH_REQ success")
  150. if "FAIL" not in hapd.request("HS20_DEAUTH_REQ 00:11:22:33:44:55"):
  151. raise Exception("Unexpected HS20_DEAUTH_REQ success")
  152. if "FAIL" not in hapd.request("HS20_DEAUTH_REQ 00:11:22:33:44:55 1"):
  153. raise Exception("Unexpected HS20_DEAUTH_REQ success")
  154. def test_hapd_ctrl_disassoc_imminent(dev, apdev):
  155. """hostapd and DISASSOC_IMMINENT ctrl_iface command"""
  156. ssid = "hapd-ctrl"
  157. params = { "ssid": ssid }
  158. hapd = hostapd.add_ap(apdev[0], params)
  159. if "FAIL" not in hapd.request("DISASSOC_IMMINENT 00:11:22:33:44"):
  160. raise Exception("Unexpected DISASSOC_IMMINENT success")
  161. if "FAIL" not in hapd.request("DISASSOC_IMMINENT 00:11:22:33:44:55"):
  162. raise Exception("Unexpected DISASSOC_IMMINENT success")
  163. if "FAIL" not in hapd.request("DISASSOC_IMMINENT 00:11:22:33:44:55 2"):
  164. raise Exception("Unexpected DISASSOC_IMMINENT success")
  165. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  166. addr = dev[0].p2p_interface_addr()
  167. if "OK" not in hapd.request("DISASSOC_IMMINENT " + addr + " 2"):
  168. raise Exception("Unexpected DISASSOC_IMMINENT failure")
  169. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
  170. if ev is None:
  171. raise Exception("Scan timed out")
  172. def test_hapd_ctrl_ess_disassoc(dev, apdev):
  173. """hostapd and ESS_DISASSOC ctrl_iface command"""
  174. ssid = "hapd-ctrl"
  175. params = { "ssid": ssid }
  176. hapd = hostapd.add_ap(apdev[0], params)
  177. if "FAIL" not in hapd.request("ESS_DISASSOC 00:11:22:33:44"):
  178. raise Exception("Unexpected ESS_DISASSOCT success")
  179. if "FAIL" not in hapd.request("ESS_DISASSOC 00:11:22:33:44:55"):
  180. raise Exception("Unexpected ESS_DISASSOC success")
  181. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  182. addr = dev[0].p2p_interface_addr()
  183. if "FAIL" not in hapd.request("ESS_DISASSOC " + addr):
  184. raise Exception("Unexpected ESS_DISASSOC success")
  185. if "FAIL" not in hapd.request("ESS_DISASSOC " + addr + " -1"):
  186. raise Exception("Unexpected ESS_DISASSOC success")
  187. if "FAIL" not in hapd.request("ESS_DISASSOC " + addr + " 1"):
  188. raise Exception("Unexpected ESS_DISASSOC success")
  189. if "OK" not in hapd.request("ESS_DISASSOC " + addr + " 20 http://example.com/"):
  190. raise Exception("Unexpected ESS_DISASSOC failure")
  191. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
  192. if ev is None:
  193. raise Exception("Scan timed out")
  194. def test_hapd_ctrl_set_deny_mac_file(dev, apdev):
  195. """hostapd and SET deny_mac_file ctrl_iface command"""
  196. ssid = "hapd-ctrl"
  197. params = { "ssid": ssid }
  198. hapd = hostapd.add_ap(apdev[0], params)
  199. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  200. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  201. if "OK" not in hapd.request("SET deny_mac_file hostapd.macaddr"):
  202. raise Exception("Unexpected SET failure")
  203. dev[0].wait_disconnected(timeout=15)
  204. ev = dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"], 1)
  205. if ev is not None:
  206. raise Exception("Unexpected disconnection")
  207. def test_hapd_ctrl_set_accept_mac_file(dev, apdev):
  208. """hostapd and SET accept_mac_file ctrl_iface command"""
  209. ssid = "hapd-ctrl"
  210. params = { "ssid": ssid }
  211. hapd = hostapd.add_ap(apdev[0], params)
  212. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  213. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  214. hapd.request("SET macaddr_acl 1")
  215. if "OK" not in hapd.request("SET accept_mac_file hostapd.macaddr"):
  216. raise Exception("Unexpected SET failure")
  217. dev[1].wait_disconnected(timeout=15)
  218. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], 1)
  219. if ev is not None:
  220. raise Exception("Unexpected disconnection")
  221. def test_hapd_ctrl_set_error_cases(dev, apdev):
  222. """hostapd and SET error cases"""
  223. ssid = "hapd-ctrl"
  224. params = { "ssid": ssid }
  225. hapd = hostapd.add_ap(apdev[0], params)
  226. errors = [ "wpa_key_mgmt FOO",
  227. "wpa_key_mgmt WPA-PSK \t FOO",
  228. "wpa_key_mgmt \t ",
  229. "wpa_pairwise FOO",
  230. "wpa_pairwise \t ",
  231. 'wep_key0 "',
  232. 'wep_key0 "abcde',
  233. "wep_key0 1",
  234. "wep_key0 12q3456789",
  235. "wep_key_len_broadcast 20",
  236. "wep_rekey_period -1",
  237. "wep_default_key 4",
  238. "r0kh 02:00:00:00:03:0q nas1.w1.fi 100102030405060708090a0b0c0d0e0f",
  239. "r0kh 02:00:00:00:03:00 12345678901234567890123456789012345678901234567890.nas1.w1.fi 100102030405060708090a0b0c0d0e0f",
  240. "r0kh 02:00:00:00:03:00 nas1.w1.fi 100q02030405060708090a0b0c0d0e0f",
  241. "r1kh 02:00:00:00:04:q0 00:01:02:03:04:06 200102030405060708090a0b0c0d0e0f",
  242. "r1kh 02:00:00:00:04:00 00:01:02:03:04:q6 200102030405060708090a0b0c0d0e0f",
  243. "r1kh 02:00:00:00:04:00 00:01:02:03:04:06 2q0102030405060708090a0b0c0d0e0f",
  244. "roaming_consortium 1",
  245. "roaming_consortium 12",
  246. "roaming_consortium 112233445566778899aabbccddeeff00",
  247. 'venue_name P"engExample venue"',
  248. 'venue_name P"engExample venue',
  249. "venue_name engExample venue",
  250. "venue_name e:Example venue",
  251. "venue_name eng1:Example venue",
  252. "venue_name eng:Example venue 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
  253. "anqp_3gpp_cell_net abc",
  254. "anqp_3gpp_cell_net ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;",
  255. "anqp_3gpp_cell_net 244",
  256. "anqp_3gpp_cell_net 24,123",
  257. "anqp_3gpp_cell_net 244,1",
  258. "anqp_3gpp_cell_net 244,1234",
  259. "nai_realm 0",
  260. "nai_realm 0,1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.nas1.w1.fi",
  261. "nai_realm 0,example.org,1,2,3,4,5,6,7,8",
  262. "nai_realm 0,example.org,1[1:1][2:2][3:3][4:4][5:5]",
  263. "nai_realm 0,example.org,1[1]",
  264. "nai_realm 0,example.org,1[1:1",
  265. "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",
  266. "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",
  267. "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,300",
  268. "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,-1",
  269. "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,255,1",
  270. "qos_map_set 1",
  271. "qos_map_set 1,2",
  272. "hs20_conn_capab 1",
  273. "hs20_conn_capab 6:22",
  274. "hs20_wan_metrics 0q:8000:1000:80:240:3000",
  275. "hs20_wan_metrics 01",
  276. "hs20_wan_metrics 01:8000",
  277. "hs20_wan_metrics 01:8000:1000",
  278. "hs20_wan_metrics 01:8000:1000:80",
  279. "hs20_wan_metrics 01:8000:1000:80:240",
  280. "hs20_oper_friendly_name eng1:Example",
  281. "hs20_icon 32",
  282. "hs20_icon 32:32",
  283. "hs20_icon 32:32:eng",
  284. "hs20_icon 32:32:eng:image/png",
  285. "hs20_icon 32:32:eng:image/png:icon32",
  286. "hs20_icon 32:32:eng:image/png:123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890:/tmp/icon32.png",
  287. "hs20_icon 32:32:eng:image/png:name:/tmp/123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.png",
  288. "osu_ssid ",
  289. "osu_ssid P",
  290. 'osu_ssid P"abc',
  291. 'osu_ssid "1234567890123456789012345678901234567890"',
  292. "osu_friendly_name eng:Example",
  293. "osu_nai anonymous@example.com",
  294. "osu_method_list 1 0",
  295. "osu_icon foo",
  296. "osu_service_desc eng:Example services",
  297. "ssid 1234567890123456789012345678901234567890",
  298. "pac_opaque_encr_key 123456",
  299. "eap_fast_a_id 12345",
  300. "eap_fast_a_id 12345q",
  301. "own_ip_addr foo",
  302. "auth_server_addr foo2",
  303. "auth_server_shared_secret ",
  304. "acct_server_addr foo3",
  305. "acct_server_shared_secret ",
  306. "radius_auth_req_attr 123::",
  307. "radius_acct_req_attr 123::",
  308. "radius_das_client 192.168.1.123",
  309. "radius_das_client 192.168.1.1a foo",
  310. "auth_algs 0",
  311. "max_num_sta -1",
  312. "max_num_sta 1000000",
  313. "wpa_passphrase 1234567",
  314. "wpa_passphrase 1234567890123456789012345678901234567890123456789012345678901234",
  315. "wpa_psk 1234567890123456789012345678901234567890123456789012345678901234a",
  316. "wpa_psk 12345678901234567890123456789012345678901234567890123456789012",
  317. "wpa_psk_radius 123",
  318. "wpa_pairwise NONE",
  319. "wpa_pairwise WEP40",
  320. "wpa_pairwise WEP104",
  321. "rsn_pairwise NONE",
  322. "rsn_pairwise WEP40",
  323. "rsn_pairwise WEP104",
  324. "mobility_domain 01",
  325. "r1_key_holder 0011223344",
  326. "ctrl_interface_group nosuchgrouphere",
  327. "hw_mode foo",
  328. "wps_rf_bands foo",
  329. "beacon_int 0",
  330. "beacon_int 65536",
  331. "acs_num_scans 0",
  332. "acs_num_scans 101",
  333. "rts_threshold -2",
  334. "rts_threshold 65536",
  335. "fragm_threshold -2",
  336. "fragm_threshold 2347",
  337. "send_probe_response -1",
  338. "send_probe_response 2",
  339. "vlan_naming -1",
  340. "vlan_naming 10000000",
  341. "group_mgmt_cipher FOO",
  342. "assoc_sa_query_max_timeout 0",
  343. "assoc_sa_query_retry_timeout 0",
  344. "wps_state -1",
  345. "wps_state 3",
  346. "uuid FOO",
  347. "device_name 1234567890123456789012345678901234567890",
  348. "manufacturer 1234567890123456789012345678901234567890123456789012345678901234567890",
  349. "model_name 1234567890123456789012345678901234567890",
  350. "model_number 1234567890123456789012345678901234567890",
  351. "serial_number 1234567890123456789012345678901234567890",
  352. "device_type FOO",
  353. "os_version 1",
  354. "ap_settings /tmp/does/not/exist/ap-settings.foo",
  355. "wps_nfc_dev_pw_id 4",
  356. "wps_nfc_dev_pw_id 100000",
  357. "time_zone A",
  358. "access_network_type -1",
  359. "access_network_type 16",
  360. "hessid 00:11:22:33:44",
  361. "network_auth_type 0q",
  362. "ipaddr_type_availability 1q",
  363. "hs20_operating_class 0",
  364. "hs20_operating_class 0q",
  365. "bss_load_test ",
  366. "bss_load_test 12",
  367. "bss_load_test 12:80",
  368. "vendor_elements 0",
  369. "vendor_elements 0q",
  370. "assocresp_elements 0",
  371. "assocresp_elements 0q",
  372. "local_pwr_constraint -1",
  373. "local_pwr_constraint 256",
  374. "wmm_ac_bk_cwmin -1",
  375. "wmm_ac_be_cwmin 16",
  376. "wmm_ac_vi_cwmax -1",
  377. "wmm_ac_vo_cwmax 16",
  378. "wmm_ac_foo_cwmax 6",
  379. "wmm_ac_bk_aifs 0",
  380. "wmm_ac_bk_aifs 256",
  381. "wmm_ac_bk_txop_limit -1",
  382. "wmm_ac_bk_txop_limit 65536",
  383. "wmm_ac_bk_acm -1",
  384. "wmm_ac_bk_acm 2",
  385. "wmm_ac_bk_foo 2",
  386. "tx_queue_foo_aifs 3",
  387. "tx_queue_data3_cwmin 4",
  388. "tx_queue_data3_cwmax 4",
  389. "tx_queue_data3_aifs -4",
  390. "tx_queue_data3_foo 1" ]
  391. for e in errors:
  392. if "FAIL" not in hapd.request("SET " + e):
  393. raise Exception("Unexpected SET success: '%s'" % e)
  394. if "OK" not in hapd.request("SET osu_server_uri https://example.com/"):
  395. raise Exception("Unexpected SET osu_server_uri failure")
  396. if "OK" not in hapd.request("SET osu_friendly_name eng:Example"):
  397. raise Exception("Unexpected SET osu_friendly_name failure")
  398. errors = [ "osu_friendly_name eng1:Example",
  399. "osu_service_desc eng1:Example services" ]
  400. for e in errors:
  401. if "FAIL" not in hapd.request("SET " + e):
  402. raise Exception("Unexpected SET success: '%s'" % e)
  403. no_err = [ "wps_nfc_dh_pubkey 0",
  404. "wps_nfc_dh_privkey 0q",
  405. "wps_nfc_dev_pw 012",
  406. "manage_p2p 0",
  407. "disassoc_low_ack 0",
  408. "network_auth_type 01",
  409. "tdls_prohibit 0",
  410. "tdls_prohibit_chan_switch 0" ]
  411. for e in no_err:
  412. if "OK" not in hapd.request("SET " + e):
  413. raise Exception("Unexpected SET failure: '%s'" % e)
  414. def test_hapd_ctrl_global(dev, apdev):
  415. """hostapd and GET ctrl_iface command"""
  416. ssid = "hapd-ctrl"
  417. params = { "ssid": ssid }
  418. ifname = apdev[0]['ifname']
  419. hapd = hostapd.add_ap(apdev[0], params)
  420. hapd_global = hostapd.HostapdGlobal(apdev[0])
  421. res = hapd_global.request("IFNAME=" + ifname + " PING")
  422. if "PONG" not in res:
  423. raise Exception("Could not ping hostapd interface " + ifname + " via global control interface")
  424. res = hapd_global.request("IFNAME=" + ifname + " GET version")
  425. if "FAIL" in res:
  426. raise Exception("Could not get hostapd version for " + ifname + " via global control interface")
  427. def dup_network(hapd_global, src, dst, param):
  428. res = hapd_global.request("DUP_NETWORK %s %s %s" % (src, dst, param))
  429. if "OK" not in res:
  430. raise Exception("Could not dup %s param from %s to %s" % (param, src,
  431. dst))
  432. def test_hapd_dup_network_global_wpa2(dev, apdev):
  433. """hostapd and DUP_NETWORK command (WPA2"""
  434. passphrase="12345678"
  435. src_ssid = "hapd-ctrl-src"
  436. dst_ssid = "hapd-ctrl-dst"
  437. src_params = hostapd.wpa2_params(ssid=src_ssid, passphrase=passphrase)
  438. src_ifname = apdev[0]['ifname']
  439. src_hapd = hostapd.add_ap(apdev[0], src_params)
  440. dst_params = { "ssid": dst_ssid }
  441. dst_ifname = apdev[1]['ifname']
  442. dst_hapd = hostapd.add_ap(apdev[1], dst_params, no_enable=True)
  443. hapd_global = hostapd.HostapdGlobal()
  444. for param in [ "wpa", "wpa_passphrase", "wpa_key_mgmt", "rsn_pairwise" ]:
  445. dup_network(hapd_global, src_ifname, dst_ifname, param)
  446. dst_hapd.enable()
  447. dev[0].connect(dst_ssid, psk=passphrase, proto="RSN", pairwise="CCMP",
  448. scan_freq="2412")
  449. addr = dev[0].own_addr()
  450. if "FAIL" in dst_hapd.request("STA " + addr):
  451. raise Exception("Could not connect using duplicated wpa params")
  452. def test_hapd_dup_network_global_wpa(dev, apdev):
  453. """hostapd and DUP_NETWORK command (WPA)"""
  454. skip_with_fips(dev[0])
  455. psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
  456. src_ssid = "hapd-ctrl-src"
  457. dst_ssid = "hapd-ctrl-dst"
  458. src_params = hostapd.wpa_params(ssid=src_ssid)
  459. src_params['wpa_psk'] = psk
  460. src_ifname = apdev[0]['ifname']
  461. src_hapd = hostapd.add_ap(apdev[0], src_params)
  462. dst_params = { "ssid": dst_ssid }
  463. dst_ifname = apdev[1]['ifname']
  464. dst_hapd = hostapd.add_ap(apdev[1], dst_params, no_enable=True)
  465. hapd_global = hostapd.HostapdGlobal()
  466. for param in [ "wpa", "wpa_psk", "wpa_key_mgmt", "wpa_pairwise" ]:
  467. dup_network(hapd_global, src_ifname, dst_ifname, param)
  468. dst_hapd.enable()
  469. dev[0].connect(dst_ssid, raw_psk=psk, proto="WPA", pairwise="TKIP",
  470. scan_freq="2412")
  471. addr = dev[0].own_addr()
  472. if "FAIL" in dst_hapd.request("STA " + addr):
  473. raise Exception("Could not connect using duplicated wpa params")
  474. def test_hapd_ctrl_log_level(dev, apdev):
  475. """hostapd ctrl_iface LOG_LEVEL"""
  476. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  477. level = hapd.request("LOG_LEVEL")
  478. if "Current level: MSGDUMP" not in level:
  479. raise Exception("Unexpected debug level(1): " + level)
  480. if "Timestamp: 1" not in level:
  481. raise Exception("Unexpected timestamp(1): " + level)
  482. if "OK" not in hapd.request("LOG_LEVEL MSGDUMP 0"):
  483. raise Exception("LOG_LEVEL failed")
  484. level = hapd.request("LOG_LEVEL")
  485. if "Current level: MSGDUMP" not in level:
  486. raise Exception("Unexpected debug level(2): " + level)
  487. if "Timestamp: 0" not in level:
  488. raise Exception("Unexpected timestamp(2): " + level)
  489. if "OK" not in hapd.request("LOG_LEVEL MSGDUMP 1"):
  490. raise Exception("LOG_LEVEL failed")
  491. level = hapd.request("LOG_LEVEL")
  492. if "Current level: MSGDUMP" not in level:
  493. raise Exception("Unexpected debug level(3): " + level)
  494. if "Timestamp: 1" not in level:
  495. raise Exception("Unexpected timestamp(3): " + level)
  496. if "FAIL" not in hapd.request("LOG_LEVEL FOO"):
  497. raise Exception("Invalid LOG_LEVEL accepted")
  498. for lev in [ "EXCESSIVE", "MSGDUMP", "DEBUG", "INFO", "WARNING", "ERROR" ]:
  499. if "OK" not in hapd.request("LOG_LEVEL " + lev):
  500. raise Exception("LOG_LEVEL failed for " + lev)
  501. level = hapd.request("LOG_LEVEL")
  502. if "Current level: " + lev not in level:
  503. raise Exception("Unexpected debug level: " + level)
  504. if "OK" not in hapd.request("LOG_LEVEL MSGDUMP 1"):
  505. raise Exception("LOG_LEVEL failed")
  506. level = hapd.request("LOG_LEVEL")
  507. if "Current level: MSGDUMP" not in level:
  508. raise Exception("Unexpected debug level(3): " + level)
  509. if "Timestamp: 1" not in level:
  510. raise Exception("Unexpected timestamp(3): " + level)
  511. def test_hapd_ctrl_disconnect_no_tx(dev, apdev):
  512. """hostapd disconnecting STA without transmitting Deauth/Disassoc"""
  513. ssid = "hapd-test"
  514. passphrase = "12345678"
  515. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  516. hapd = hostapd.add_ap(apdev[0], params)
  517. bssid = apdev[0]['bssid']
  518. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  519. addr0 = dev[0].own_addr()
  520. dev[1].connect(ssid, psk=passphrase, scan_freq="2412")
  521. addr1 = dev[1].own_addr()
  522. # Disconnect the STA without sending out Deauthentication frame
  523. if "OK" not in hapd.request("DEAUTHENTICATE " + addr0 + " tx=0"):
  524. raise Exception("DEAUTHENTICATE command failed")
  525. # Force disconnection due to AP receiving a frame from not-asssociated STA
  526. dev[0].request("DATA_TEST_CONFIG 1")
  527. dev[0].request("DATA_TEST_TX " + bssid + " " + addr0)
  528. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
  529. dev[0].request("DATA_TEST_CONFIG 0")
  530. if ev is None:
  531. raise Exception("Disconnection event not seen after TX attempt")
  532. if "reason=7" not in ev:
  533. raise Exception("Unexpected disconnection reason: " + ev)
  534. # Disconnect the STA without sending out Disassociation frame
  535. if "OK" not in hapd.request("DISASSOCIATE " + addr1 + " tx=0"):
  536. raise Exception("DISASSOCIATE command failed")
  537. # Force disconnection due to AP receiving a frame from not-asssociated STA
  538. dev[1].request("DATA_TEST_CONFIG 1")
  539. dev[1].request("DATA_TEST_TX " + bssid + " " + addr1)
  540. ev = dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
  541. dev[1].request("DATA_TEST_CONFIG 0")
  542. if ev is None:
  543. raise Exception("Disconnection event not seen after TX attempt")
  544. if "reason=7" not in ev:
  545. raise Exception("Unexpected disconnection reason: " + ev)