test_hapd_ctrl.py 31 KB

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