test_hapd_ctrl.py 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  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, alloc_fail, fail_test, HwsimSkip
  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 " + addr + " foo"):
  64. raise Exception("Unexpected STA-foo success")
  65. if "FAIL" not in hapd.request("STA 00:11:22:33:44"):
  66. raise Exception("Unexpected STA success")
  67. if "FAIL" not in hapd.request("STA 00:11:22:33:44:55"):
  68. raise Exception("Unexpected STA success")
  69. if len(hapd.request("STA-NEXT " + addr).splitlines()) > 0:
  70. raise Exception("Unexpected STA-NEXT result")
  71. if "FAIL" not in hapd.request("STA-NEXT 00:11:22:33:44"):
  72. raise Exception("Unexpected STA-NEXT success")
  73. @remote_compatible
  74. def test_hapd_ctrl_disconnect(dev, apdev):
  75. """hostapd and disconnection ctrl_iface commands"""
  76. ssid = "hapd-ctrl"
  77. passphrase = "12345678"
  78. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  79. hapd = hostapd.add_ap(apdev[0], params)
  80. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  81. addr = dev[0].p2p_dev_addr()
  82. if "FAIL" not in hapd.request("DEAUTHENTICATE 00:11:22:33:44"):
  83. raise Exception("Unexpected DEAUTHENTICATE success")
  84. if "OK" not in hapd.request("DEAUTHENTICATE ff:ff:ff:ff:ff:ff"):
  85. raise Exception("Unexpected DEAUTHENTICATE failure")
  86. dev[0].wait_disconnected(timeout=5)
  87. dev[0].wait_connected(timeout=10, error="Re-connection timed out")
  88. if "FAIL" not in hapd.request("DISASSOCIATE 00:11:22:33:44"):
  89. raise Exception("Unexpected DISASSOCIATE success")
  90. if "OK" not in hapd.request("DISASSOCIATE ff:ff:ff:ff:ff:ff"):
  91. raise Exception("Unexpected DISASSOCIATE failure")
  92. dev[0].wait_disconnected(timeout=5)
  93. dev[0].wait_connected(timeout=10, error="Re-connection timed out")
  94. @remote_compatible
  95. def test_hapd_ctrl_chan_switch(dev, apdev):
  96. """hostapd and CHAN_SWITCH ctrl_iface command"""
  97. ssid = "hapd-ctrl"
  98. params = { "ssid": ssid }
  99. hapd = hostapd.add_ap(apdev[0], params)
  100. if "FAIL" not in hapd.request("CHAN_SWITCH "):
  101. raise Exception("Unexpected CHAN_SWITCH success")
  102. if "FAIL" not in hapd.request("CHAN_SWITCH qwerty 2422"):
  103. raise Exception("Unexpected CHAN_SWITCH success")
  104. if "FAIL" not in hapd.request("CHAN_SWITCH 5 qwerty"):
  105. raise Exception("Unexpected CHAN_SWITCH success")
  106. if "FAIL" not in hapd.request("CHAN_SWITCH 0 2432 center_freq1=123 center_freq2=234 bandwidth=1000 sec_channel_offset=20 ht vht"):
  107. raise Exception("Unexpected CHAN_SWITCH success")
  108. @remote_compatible
  109. def test_hapd_ctrl_level(dev, apdev):
  110. """hostapd and LEVEL ctrl_iface command"""
  111. ssid = "hapd-ctrl"
  112. params = { "ssid": ssid }
  113. hapd = hostapd.add_ap(apdev[0], params)
  114. if "FAIL" not in hapd.request("LEVEL 0"):
  115. raise Exception("Unexpected LEVEL success on non-monitor interface")
  116. @remote_compatible
  117. def test_hapd_ctrl_new_sta(dev, apdev):
  118. """hostapd and NEW_STA ctrl_iface command"""
  119. ssid = "hapd-ctrl"
  120. params = { "ssid": ssid }
  121. hapd = hostapd.add_ap(apdev[0], params)
  122. if "FAIL" not in hapd.request("NEW_STA 00:11:22:33:44"):
  123. raise Exception("Unexpected NEW_STA success")
  124. if "OK" not in hapd.request("NEW_STA 00:11:22:33:44:55"):
  125. raise Exception("Unexpected NEW_STA failure")
  126. if "AUTHORIZED" not in hapd.request("STA 00:11:22:33:44:55"):
  127. raise Exception("Unexpected NEW_STA STA status")
  128. if "OK" not in hapd.request("NEW_STA 00:11:22:33:44:55"):
  129. raise Exception("Unexpected NEW_STA failure")
  130. with alloc_fail(hapd, 1, "ap_sta_add;hostapd_ctrl_iface_new_sta"):
  131. if "FAIL" not in hapd.request("NEW_STA 00:11:22:33:44:66"):
  132. raise Exception("Unexpected NEW_STA success during OOM")
  133. @remote_compatible
  134. def test_hapd_ctrl_get(dev, apdev):
  135. """hostapd and GET 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("GET foo"):
  140. raise Exception("Unexpected GET success")
  141. if "FAIL" in hapd.request("GET version"):
  142. raise Exception("Unexpected GET version failure")
  143. @remote_compatible
  144. def test_hapd_ctrl_unknown(dev, apdev):
  145. """hostapd and unknown ctrl_iface command"""
  146. ssid = "hapd-ctrl"
  147. params = { "ssid": ssid }
  148. hapd = hostapd.add_ap(apdev[0], params)
  149. if "UNKNOWN COMMAND" not in hapd.request("FOO"):
  150. raise Exception("Unexpected response")
  151. @remote_compatible
  152. def test_hapd_ctrl_hs20_wnm_notif(dev, apdev):
  153. """hostapd and HS20_WNM_NOTIF ctrl_iface command"""
  154. ssid = "hapd-ctrl"
  155. params = { "ssid": ssid }
  156. hapd = hostapd.add_ap(apdev[0], params)
  157. if "FAIL" not in hapd.request("HS20_WNM_NOTIF 00:11:22:33:44 http://example.com/"):
  158. raise Exception("Unexpected HS20_WNM_NOTIF success")
  159. if "FAIL" not in hapd.request("HS20_WNM_NOTIF 00:11:22:33:44:55http://example.com/"):
  160. raise Exception("Unexpected HS20_WNM_NOTIF success")
  161. @remote_compatible
  162. def test_hapd_ctrl_hs20_deauth_req(dev, apdev):
  163. """hostapd and HS20_DEAUTH_REQ ctrl_iface command"""
  164. ssid = "hapd-ctrl"
  165. params = { "ssid": ssid }
  166. hapd = hostapd.add_ap(apdev[0], params)
  167. if "FAIL" not in hapd.request("HS20_DEAUTH_REQ 00:11:22:33:44 1 120 http://example.com/"):
  168. raise Exception("Unexpected HS20_DEAUTH_REQ success")
  169. if "FAIL" not in hapd.request("HS20_DEAUTH_REQ 00:11:22:33:44:55"):
  170. raise Exception("Unexpected HS20_DEAUTH_REQ success")
  171. if "FAIL" not in hapd.request("HS20_DEAUTH_REQ 00:11:22:33:44:55 1"):
  172. raise Exception("Unexpected HS20_DEAUTH_REQ success")
  173. @remote_compatible
  174. def test_hapd_ctrl_disassoc_imminent(dev, apdev):
  175. """hostapd and DISASSOC_IMMINENT ctrl_iface command"""
  176. ssid = "hapd-ctrl"
  177. params = { "ssid": ssid }
  178. hapd = hostapd.add_ap(apdev[0], params)
  179. if "FAIL" not in hapd.request("DISASSOC_IMMINENT 00:11:22:33:44"):
  180. raise Exception("Unexpected DISASSOC_IMMINENT success")
  181. if "FAIL" not in hapd.request("DISASSOC_IMMINENT 00:11:22:33:44:55"):
  182. raise Exception("Unexpected DISASSOC_IMMINENT success")
  183. if "FAIL" not in hapd.request("DISASSOC_IMMINENT 00:11:22:33:44:55 2"):
  184. raise Exception("Unexpected DISASSOC_IMMINENT success")
  185. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  186. addr = dev[0].p2p_interface_addr()
  187. if "OK" not in hapd.request("DISASSOC_IMMINENT " + addr + " 2"):
  188. raise Exception("Unexpected DISASSOC_IMMINENT failure")
  189. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
  190. if ev is None:
  191. raise Exception("Scan timed out")
  192. @remote_compatible
  193. def test_hapd_ctrl_ess_disassoc(dev, apdev):
  194. """hostapd and ESS_DISASSOC ctrl_iface command"""
  195. ssid = "hapd-ctrl"
  196. params = { "ssid": ssid }
  197. hapd = hostapd.add_ap(apdev[0], params)
  198. if "FAIL" not in hapd.request("ESS_DISASSOC 00:11:22:33:44"):
  199. raise Exception("Unexpected ESS_DISASSOCT success")
  200. if "FAIL" not in hapd.request("ESS_DISASSOC 00:11:22:33:44:55"):
  201. raise Exception("Unexpected ESS_DISASSOC success")
  202. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  203. addr = dev[0].p2p_interface_addr()
  204. if "FAIL" not in hapd.request("ESS_DISASSOC " + addr):
  205. raise Exception("Unexpected ESS_DISASSOC success")
  206. if "FAIL" not in hapd.request("ESS_DISASSOC " + addr + " -1"):
  207. raise Exception("Unexpected ESS_DISASSOC success")
  208. if "FAIL" not in hapd.request("ESS_DISASSOC " + addr + " 1"):
  209. raise Exception("Unexpected ESS_DISASSOC success")
  210. if "OK" not in hapd.request("ESS_DISASSOC " + addr + " 20 http://example.com/"):
  211. raise Exception("Unexpected ESS_DISASSOC failure")
  212. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
  213. if ev is None:
  214. raise Exception("Scan timed out")
  215. def test_hapd_ctrl_set_deny_mac_file(dev, apdev):
  216. """hostapd and SET deny_mac_file ctrl_iface command"""
  217. ssid = "hapd-ctrl"
  218. params = { "ssid": ssid }
  219. hapd = hostapd.add_ap(apdev[0], params)
  220. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  221. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  222. if "OK" not in hapd.request("SET deny_mac_file hostapd.macaddr"):
  223. raise Exception("Unexpected SET failure")
  224. dev[0].wait_disconnected(timeout=15)
  225. ev = dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"], 1)
  226. if ev is not None:
  227. raise Exception("Unexpected disconnection")
  228. def test_hapd_ctrl_set_accept_mac_file(dev, apdev):
  229. """hostapd and SET accept_mac_file ctrl_iface command"""
  230. ssid = "hapd-ctrl"
  231. params = { "ssid": ssid }
  232. hapd = hostapd.add_ap(apdev[0], params)
  233. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  234. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  235. hapd.request("SET macaddr_acl 1")
  236. if "OK" not in hapd.request("SET accept_mac_file hostapd.macaddr"):
  237. raise Exception("Unexpected SET failure")
  238. dev[1].wait_disconnected(timeout=15)
  239. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], 1)
  240. if ev is not None:
  241. raise Exception("Unexpected disconnection")
  242. def test_hapd_ctrl_set_accept_mac_file_vlan(dev, apdev):
  243. """hostapd and SET accept_mac_file ctrl_iface command (VLAN ID)"""
  244. ssid = "hapd-ctrl"
  245. params = { "ssid": ssid }
  246. hapd = hostapd.add_ap(apdev[0], params)
  247. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  248. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  249. hapd.request("SET macaddr_acl 1")
  250. if "OK" not in hapd.request("SET accept_mac_file hostapd.accept"):
  251. raise Exception("Unexpected SET failure")
  252. dev[1].wait_disconnected(timeout=15)
  253. dev[0].wait_disconnected(timeout=15)
  254. @remote_compatible
  255. def test_hapd_ctrl_set_error_cases(dev, apdev):
  256. """hostapd and SET error cases"""
  257. ssid = "hapd-ctrl"
  258. params = { "ssid": ssid }
  259. hapd = hostapd.add_ap(apdev[0], params)
  260. errors = [ "wpa_key_mgmt FOO",
  261. "wpa_key_mgmt WPA-PSK \t FOO",
  262. "wpa_key_mgmt \t ",
  263. "wpa_pairwise FOO",
  264. "wpa_pairwise \t ",
  265. 'wep_key0 "',
  266. 'wep_key0 "abcde',
  267. "wep_key0 1",
  268. "wep_key0 12q3456789",
  269. "wep_key_len_broadcast 20",
  270. "wep_rekey_period -1",
  271. "wep_default_key 4",
  272. "r0kh 02:00:00:00:03:0q nas1.w1.fi 100102030405060708090a0b0c0d0e0f100102030405060708090a0b0c0d0e0f",
  273. "r0kh 02:00:00:00:03:00 12345678901234567890123456789012345678901234567890.nas1.w1.fi 100102030405060708090a0b0c0d0e0f100102030405060708090a0b0c0d0e0f",
  274. "r0kh 02:00:00:00:03:00 nas1.w1.fi 100q02030405060708090a0b0c0d0e0f100q02030405060708090a0b0c0d0e0f",
  275. "r1kh 02:00:00:00:04:q0 00:01:02:03:04:06 200102030405060708090a0b0c0d0e0f200102030405060708090a0b0c0d0e0f",
  276. "r1kh 02:00:00:00:04:00 00:01:02:03:04:q6 200102030405060708090a0b0c0d0e0f200102030405060708090a0b0c0d0e0f",
  277. "r1kh 02:00:00:00:04:00 00:01:02:03:04:06 2q0102030405060708090a0b0c0d0e0f2q0102030405060708090a0b0c0d0e0f",
  278. "roaming_consortium 1",
  279. "roaming_consortium 12",
  280. "roaming_consortium 112233445566778899aabbccddeeff00",
  281. 'venue_name P"engExample venue"',
  282. 'venue_name P"engExample venue',
  283. "venue_name engExample venue",
  284. "venue_name e:Example venue",
  285. "venue_name eng1:Example venue",
  286. "venue_name eng:Example venue 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
  287. "anqp_3gpp_cell_net abc",
  288. "anqp_3gpp_cell_net ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;",
  289. "anqp_3gpp_cell_net 244",
  290. "anqp_3gpp_cell_net 24,123",
  291. "anqp_3gpp_cell_net 244,1",
  292. "anqp_3gpp_cell_net 244,1234",
  293. "nai_realm 0",
  294. "nai_realm 0,1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.nas1.w1.fi",
  295. "nai_realm 0,example.org,1,2,3,4,5,6,7,8",
  296. "nai_realm 0,example.org,1[1:1][2:2][3:3][4:4][5:5]",
  297. "nai_realm 0,example.org,1[1]",
  298. "nai_realm 0,example.org,1[1:1",
  299. "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",
  300. "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",
  301. "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,300",
  302. "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,-1",
  303. "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,255,1",
  304. "qos_map_set 1",
  305. "qos_map_set 1,2",
  306. "hs20_conn_capab 1",
  307. "hs20_conn_capab 6:22",
  308. "hs20_wan_metrics 0q:8000:1000:80:240:3000",
  309. "hs20_wan_metrics 01",
  310. "hs20_wan_metrics 01:8000",
  311. "hs20_wan_metrics 01:8000:1000",
  312. "hs20_wan_metrics 01:8000:1000:80",
  313. "hs20_wan_metrics 01:8000:1000:80:240",
  314. "hs20_oper_friendly_name eng1:Example",
  315. "hs20_icon 32",
  316. "hs20_icon 32:32",
  317. "hs20_icon 32:32:eng",
  318. "hs20_icon 32:32:eng:image/png",
  319. "hs20_icon 32:32:eng:image/png:icon32",
  320. "hs20_icon 32:32:eng:image/png:123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890:/tmp/icon32.png",
  321. "hs20_icon 32:32:eng:image/png:name:/tmp/123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.png",
  322. "osu_ssid ",
  323. "osu_ssid P",
  324. 'osu_ssid P"abc',
  325. 'osu_ssid "1234567890123456789012345678901234567890"',
  326. "osu_friendly_name eng:Example",
  327. "osu_nai anonymous@example.com",
  328. "osu_method_list 1 0",
  329. "osu_icon foo",
  330. "osu_service_desc eng:Example services",
  331. "ssid 1234567890123456789012345678901234567890",
  332. "pac_opaque_encr_key 123456",
  333. "eap_fast_a_id 12345",
  334. "eap_fast_a_id 12345q",
  335. "own_ip_addr foo",
  336. "auth_server_addr foo2",
  337. "auth_server_shared_secret ",
  338. "acct_server_addr foo3",
  339. "acct_server_shared_secret ",
  340. "radius_auth_req_attr 123::",
  341. "radius_acct_req_attr 123::",
  342. "radius_das_client 192.168.1.123",
  343. "radius_das_client 192.168.1.1a foo",
  344. "auth_algs 0",
  345. "max_num_sta -1",
  346. "max_num_sta 1000000",
  347. "wpa_passphrase 1234567",
  348. "wpa_passphrase 1234567890123456789012345678901234567890123456789012345678901234",
  349. "wpa_psk 1234567890123456789012345678901234567890123456789012345678901234a",
  350. "wpa_psk 12345678901234567890123456789012345678901234567890123456789012",
  351. "wpa_psk_radius 123",
  352. "wpa_pairwise NONE",
  353. "wpa_pairwise WEP40",
  354. "wpa_pairwise WEP104",
  355. "rsn_pairwise NONE",
  356. "rsn_pairwise WEP40",
  357. "rsn_pairwise WEP104",
  358. "mobility_domain 01",
  359. "r1_key_holder 0011223344",
  360. "ctrl_interface_group nosuchgrouphere",
  361. "hw_mode foo",
  362. "wps_rf_bands foo",
  363. "beacon_int 0",
  364. "beacon_int 65536",
  365. "acs_num_scans 0",
  366. "acs_num_scans 101",
  367. "rts_threshold -2",
  368. "rts_threshold 65536",
  369. "fragm_threshold -2",
  370. "fragm_threshold 2347",
  371. "send_probe_response -1",
  372. "send_probe_response 2",
  373. "vlan_naming -1",
  374. "vlan_naming 10000000",
  375. "group_mgmt_cipher FOO",
  376. "assoc_sa_query_max_timeout 0",
  377. "assoc_sa_query_retry_timeout 0",
  378. "wps_state -1",
  379. "wps_state 3",
  380. "uuid FOO",
  381. "device_name 1234567890123456789012345678901234567890",
  382. "manufacturer 1234567890123456789012345678901234567890123456789012345678901234567890",
  383. "model_name 1234567890123456789012345678901234567890",
  384. "model_number 1234567890123456789012345678901234567890",
  385. "serial_number 1234567890123456789012345678901234567890",
  386. "device_type FOO",
  387. "os_version 1",
  388. "ap_settings /tmp/does/not/exist/ap-settings.foo",
  389. "wps_nfc_dev_pw_id 4",
  390. "wps_nfc_dev_pw_id 100000",
  391. "time_zone A",
  392. "access_network_type -1",
  393. "access_network_type 16",
  394. "hessid 00:11:22:33:44",
  395. "network_auth_type 0q",
  396. "ipaddr_type_availability 1q",
  397. "hs20_operating_class 0",
  398. "hs20_operating_class 0q",
  399. "bss_load_test ",
  400. "bss_load_test 12",
  401. "bss_load_test 12:80",
  402. "vendor_elements 0",
  403. "vendor_elements 0q",
  404. "assocresp_elements 0",
  405. "assocresp_elements 0q",
  406. "local_pwr_constraint -1",
  407. "local_pwr_constraint 256",
  408. "wmm_ac_bk_cwmin -1",
  409. "wmm_ac_be_cwmin 16",
  410. "wmm_ac_vi_cwmax -1",
  411. "wmm_ac_vo_cwmax 16",
  412. "wmm_ac_foo_cwmax 6",
  413. "wmm_ac_bk_aifs 0",
  414. "wmm_ac_bk_aifs 256",
  415. "wmm_ac_bk_txop_limit -1",
  416. "wmm_ac_bk_txop_limit 65536",
  417. "wmm_ac_bk_acm -1",
  418. "wmm_ac_bk_acm 2",
  419. "wmm_ac_bk_foo 2",
  420. "tx_queue_foo_aifs 3",
  421. "tx_queue_data3_cwmin 4",
  422. "tx_queue_data3_cwmax 4",
  423. "tx_queue_data3_aifs -4",
  424. "tx_queue_data3_foo 1" ]
  425. for e in errors:
  426. if "FAIL" not in hapd.request("SET " + e):
  427. raise Exception("Unexpected SET success: '%s'" % e)
  428. if "OK" not in hapd.request("SET osu_server_uri https://example.com/"):
  429. raise Exception("Unexpected SET osu_server_uri failure")
  430. if "OK" not in hapd.request("SET osu_friendly_name eng:Example"):
  431. raise Exception("Unexpected SET osu_friendly_name failure")
  432. errors = [ "osu_friendly_name eng1:Example",
  433. "osu_service_desc eng1:Example services" ]
  434. for e in errors:
  435. if "FAIL" not in hapd.request("SET " + e):
  436. raise Exception("Unexpected SET success: '%s'" % e)
  437. no_err = [ "wps_nfc_dh_pubkey 0",
  438. "wps_nfc_dh_privkey 0q",
  439. "wps_nfc_dev_pw 012",
  440. "manage_p2p 0",
  441. "disassoc_low_ack 0",
  442. "network_auth_type 01",
  443. "tdls_prohibit 0",
  444. "tdls_prohibit_chan_switch 0" ]
  445. for e in no_err:
  446. if "OK" not in hapd.request("SET " + e):
  447. raise Exception("Unexpected SET failure: '%s'" % e)
  448. @remote_compatible
  449. def test_hapd_ctrl_global(dev, apdev):
  450. """hostapd and GET ctrl_iface command"""
  451. ssid = "hapd-ctrl"
  452. params = { "ssid": ssid }
  453. ifname = apdev[0]['ifname']
  454. hapd = hostapd.add_ap(apdev[0], params)
  455. hapd_global = hostapd.HostapdGlobal(apdev[0])
  456. res = hapd_global.request("IFNAME=" + ifname + " PING")
  457. if "PONG" not in res:
  458. raise Exception("Could not ping hostapd interface " + ifname + " via global control interface")
  459. res = hapd_global.request("IFNAME=" + ifname + " GET version")
  460. if "FAIL" in res:
  461. raise Exception("Could not get hostapd version for " + ifname + " via global control interface")
  462. res = hapd_global.request("IFNAME=no-such-ifname GET version")
  463. if "FAIL-NO-IFNAME-MATCH" not in res:
  464. raise Exception("Invalid ifname not reported")
  465. res = hapd_global.request("INTERFACES")
  466. if "FAIL" in res:
  467. raise Exception("INTERFACES command failed")
  468. if apdev[0]['ifname'] not in res.splitlines():
  469. raise Exception("AP interface missing from INTERFACES")
  470. res = hapd_global.request("INTERFACES ctrl")
  471. if "FAIL" in res:
  472. raise Exception("INTERFACES ctrl command failed")
  473. if apdev[0]['ifname'] + " ctrl_iface=" not in res:
  474. raise Exception("AP interface missing from INTERFACES ctrl")
  475. if "FAIL" not in hapd_global.request("DETACH"):
  476. raise Exception("DETACH succeeded unexpectedly")
  477. def dup_network(hapd_global, src, dst, param):
  478. res = hapd_global.request("DUP_NETWORK %s %s %s" % (src, dst, param))
  479. if "OK" not in res:
  480. raise Exception("Could not dup %s param from %s to %s" % (param, src,
  481. dst))
  482. def test_hapd_dup_network_global_wpa2(dev, apdev):
  483. """hostapd and DUP_NETWORK command (WPA2)"""
  484. passphrase="12345678"
  485. src_ssid = "hapd-ctrl-src"
  486. dst_ssid = "hapd-ctrl-dst"
  487. src_params = hostapd.wpa2_params(ssid=src_ssid, passphrase=passphrase)
  488. src_ifname = apdev[0]['ifname']
  489. src_hapd = hostapd.add_ap(apdev[0], src_params)
  490. dst_params = { "ssid": dst_ssid }
  491. dst_ifname = apdev[1]['ifname']
  492. dst_hapd = hostapd.add_ap(apdev[1], dst_params, no_enable=True)
  493. hapd_global = hostapd.HostapdGlobal()
  494. for param in [ "wpa", "wpa_passphrase", "wpa_key_mgmt", "rsn_pairwise" ]:
  495. dup_network(hapd_global, src_ifname, dst_ifname, param)
  496. dst_hapd.enable()
  497. dev[0].connect(dst_ssid, psk=passphrase, proto="RSN", pairwise="CCMP",
  498. scan_freq="2412")
  499. addr = dev[0].own_addr()
  500. if "FAIL" in dst_hapd.request("STA " + addr):
  501. raise Exception("Could not connect using duplicated wpa params")
  502. tests = [ "a",
  503. "no-such-ifname no-such-ifname",
  504. src_ifname + " no-such-ifname",
  505. src_ifname + " no-such-ifname no-such-param",
  506. src_ifname + " " + dst_ifname + " no-such-param" ]
  507. for t in tests:
  508. if "FAIL" not in hapd_global.request("DUP_NETWORK " + t):
  509. raise Exception("Invalid DUP_NETWORK accepted: " + t)
  510. with alloc_fail(src_hapd, 1, "hostapd_ctrl_iface_dup_param"):
  511. if "FAIL" not in hapd_global.request("DUP_NETWORK %s %s wpa" % (src_ifname, dst_ifname)):
  512. raise Exception("DUP_NETWORK accepted during OOM")
  513. def test_hapd_dup_network_global_wpa(dev, apdev):
  514. """hostapd and DUP_NETWORK command (WPA)"""
  515. skip_with_fips(dev[0])
  516. psk = '602e323e077bc63bd80307ef4745b754b0ae0a925c2638ecd13a794b9527b9e6'
  517. src_ssid = "hapd-ctrl-src"
  518. dst_ssid = "hapd-ctrl-dst"
  519. src_params = hostapd.wpa_params(ssid=src_ssid)
  520. src_params['wpa_psk'] = psk
  521. src_ifname = apdev[0]['ifname']
  522. src_hapd = hostapd.add_ap(apdev[0], src_params)
  523. dst_params = { "ssid": dst_ssid }
  524. dst_ifname = apdev[1]['ifname']
  525. dst_hapd = hostapd.add_ap(apdev[1], dst_params, no_enable=True)
  526. hapd_global = hostapd.HostapdGlobal()
  527. for param in [ "wpa", "wpa_psk", "wpa_key_mgmt", "wpa_pairwise" ]:
  528. dup_network(hapd_global, src_ifname, dst_ifname, param)
  529. dst_hapd.enable()
  530. dev[0].connect(dst_ssid, raw_psk=psk, proto="WPA", pairwise="TKIP",
  531. scan_freq="2412")
  532. addr = dev[0].own_addr()
  533. if "FAIL" in dst_hapd.request("STA " + addr):
  534. raise Exception("Could not connect using duplicated wpa params")
  535. @remote_compatible
  536. def test_hapd_ctrl_log_level(dev, apdev):
  537. """hostapd ctrl_iface LOG_LEVEL"""
  538. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  539. level = hapd.request("LOG_LEVEL")
  540. if "Current level: MSGDUMP" not in level:
  541. raise Exception("Unexpected debug level(1): " + level)
  542. if "Timestamp: 1" not in level:
  543. raise Exception("Unexpected timestamp(1): " + level)
  544. if "OK" not in hapd.request("LOG_LEVEL MSGDUMP 0"):
  545. raise Exception("LOG_LEVEL failed")
  546. level = hapd.request("LOG_LEVEL")
  547. if "Current level: MSGDUMP" not in level:
  548. raise Exception("Unexpected debug level(2): " + level)
  549. if "Timestamp: 0" not in level:
  550. raise Exception("Unexpected timestamp(2): " + level)
  551. if "OK" not in hapd.request("LOG_LEVEL MSGDUMP 1"):
  552. raise Exception("LOG_LEVEL failed")
  553. level = hapd.request("LOG_LEVEL")
  554. if "Current level: MSGDUMP" not in level:
  555. raise Exception("Unexpected debug level(3): " + level)
  556. if "Timestamp: 1" not in level:
  557. raise Exception("Unexpected timestamp(3): " + level)
  558. if "FAIL" not in hapd.request("LOG_LEVEL FOO"):
  559. raise Exception("Invalid LOG_LEVEL accepted")
  560. for lev in [ "EXCESSIVE", "MSGDUMP", "DEBUG", "INFO", "WARNING", "ERROR" ]:
  561. if "OK" not in hapd.request("LOG_LEVEL " + lev):
  562. raise Exception("LOG_LEVEL failed for " + lev)
  563. level = hapd.request("LOG_LEVEL")
  564. if "Current level: " + lev not in level:
  565. raise Exception("Unexpected debug level: " + level)
  566. if "OK" not in hapd.request("LOG_LEVEL MSGDUMP 1"):
  567. raise Exception("LOG_LEVEL failed")
  568. level = hapd.request("LOG_LEVEL")
  569. if "Current level: MSGDUMP" not in level:
  570. raise Exception("Unexpected debug level(3): " + level)
  571. if "Timestamp: 1" not in level:
  572. raise Exception("Unexpected timestamp(3): " + level)
  573. @remote_compatible
  574. def test_hapd_ctrl_disconnect_no_tx(dev, apdev):
  575. """hostapd disconnecting STA without transmitting Deauth/Disassoc"""
  576. ssid = "hapd-test"
  577. passphrase = "12345678"
  578. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  579. hapd = hostapd.add_ap(apdev[0], params)
  580. bssid = apdev[0]['bssid']
  581. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  582. addr0 = dev[0].own_addr()
  583. dev[1].connect(ssid, psk=passphrase, scan_freq="2412")
  584. addr1 = dev[1].own_addr()
  585. # Disconnect the STA without sending out Deauthentication frame
  586. if "OK" not in hapd.request("DEAUTHENTICATE " + addr0 + " tx=0"):
  587. raise Exception("DEAUTHENTICATE command failed")
  588. # Force disconnection due to AP receiving a frame from not-asssociated STA
  589. dev[0].request("DATA_TEST_CONFIG 1")
  590. dev[0].request("DATA_TEST_TX " + bssid + " " + addr0)
  591. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
  592. dev[0].request("DATA_TEST_CONFIG 0")
  593. if ev is None:
  594. raise Exception("Disconnection event not seen after TX attempt")
  595. if "reason=7" not in ev:
  596. raise Exception("Unexpected disconnection reason: " + ev)
  597. # Disconnect the STA without sending out Disassociation frame
  598. if "OK" not in hapd.request("DISASSOCIATE " + addr1 + " tx=0"):
  599. raise Exception("DISASSOCIATE command failed")
  600. # Force disconnection due to AP receiving a frame from not-asssociated STA
  601. dev[1].request("DATA_TEST_CONFIG 1")
  602. dev[1].request("DATA_TEST_TX " + bssid + " " + addr1)
  603. ev = dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
  604. dev[1].request("DATA_TEST_CONFIG 0")
  605. if ev is None:
  606. raise Exception("Disconnection event not seen after TX attempt")
  607. if "reason=7" not in ev:
  608. raise Exception("Unexpected disconnection reason: " + ev)
  609. def test_hapd_ctrl_mib(dev, apdev):
  610. """hostapd and MIB ctrl_iface command with open network"""
  611. ssid = "hapd-ctrl"
  612. params = { "ssid": ssid }
  613. hapd = hostapd.add_ap(apdev[0], params)
  614. mib = hapd.request("MIB")
  615. if len(mib) != 0:
  616. raise Exception("Unexpected MIB response: " + mib)
  617. mib = hapd.request("MIB radius_server")
  618. if len(mib) != 0:
  619. raise Exception("Unexpected 'MIB radius_server' response: " + mib)
  620. if "FAIL" not in hapd.request("MIB foo"):
  621. raise Exception("'MIB foo' succeeded")
  622. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  623. mib = hapd.request("MIB")
  624. if "FAIL" in mib:
  625. raise Exception("Unexpected MIB response: " + mib)
  626. mib = hapd.request("MIB radius_server")
  627. if len(mib) != 0:
  628. raise Exception("Unexpected 'MIB radius_server' response: " + mib)
  629. if "FAIL" not in hapd.request("MIB foo"):
  630. raise Exception("'MIB foo' succeeded")
  631. def test_hapd_ctrl_not_yet_fully_enabled(dev, apdev):
  632. """hostapd and ctrl_iface commands when BSS not yet fully enabled"""
  633. ssid = "hapd-ctrl"
  634. params = { "ssid": ssid }
  635. hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
  636. if not hapd.ping():
  637. raise Exception("PING failed")
  638. if "FAIL" in hapd.request("MIB"):
  639. raise Exception("MIB failed")
  640. if len(hapd.request("MIB radius_server")) != 0:
  641. raise Exception("Unexpected 'MIB radius_server' response")
  642. if "state=UNINITIALIZED" not in hapd.request("STATUS"):
  643. raise Exception("Unexpected STATUS response")
  644. if "FAIL" not in hapd.request("STATUS-DRIVER"):
  645. raise Exception("Unexpected response to STATUS-DRIVER")
  646. if len(hapd.request("STA-FIRST")) != 0:
  647. raise Exception("Unexpected response to STA-FIRST")
  648. if "FAIL" not in hapd.request("STA ff:ff:ff:ff:ff:ff"):
  649. raise Exception("Unexpected response to STA")
  650. cmds = [ "NEW_STA 02:ff:ff:ff:ff:ff",
  651. "DEAUTHENTICATE 02:ff:ff:ff:ff:ff",
  652. "DEAUTHENTICATE 02:ff:ff:ff:ff:ff test=0",
  653. "DEAUTHENTICATE 02:ff:ff:ff:ff:ff p2p=0",
  654. "DEAUTHENTICATE 02:ff:ff:ff:ff:ff tx=0",
  655. "DISASSOCIATE 02:ff:ff:ff:ff:ff",
  656. "DISASSOCIATE 02:ff:ff:ff:ff:ff test=0",
  657. "DISASSOCIATE 02:ff:ff:ff:ff:ff p2p=0",
  658. "DISASSOCIATE 02:ff:ff:ff:ff:ff tx=0",
  659. "SA_QUERY 02:ff:ff:ff:ff:ff",
  660. "WPS_PIN any 12345670",
  661. "WPS_PBC",
  662. "WPS_CANCEL",
  663. "WPS_AP_PIN random",
  664. "WPS_AP_PIN disable",
  665. "WPS_CHECK_PIN 123456789",
  666. "WPS_GET_STATUS",
  667. "WPS_NFC_TAG_READ 00",
  668. "WPS_NFC_CONFIG_TOKEN NDEF",
  669. "WPS_NFC_TOKEN WPS",
  670. "NFC_GET_HANDOVER_SEL NDEF WPS-CR",
  671. "NFC_REPORT_HANDOVER RESP WPS 00 00",
  672. "SET_QOS_MAP_SET 22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,48,55",
  673. "SEND_QOS_MAP_CONF 02:ff:ff:ff:ff:ff",
  674. "HS20_WNM_NOTIF 02:ff:ff:ff:ff:ff https://example.com/",
  675. "HS20_DEAUTH_REQ 02:ff:ff:ff:ff:ff 1 120 https://example.com/",
  676. "DISASSOC_IMMINENT 02:ff:ff:ff:ff:ff 10",
  677. "ESS_DISASSOC 02:ff:ff:ff:ff:ff 10 https://example.com/",
  678. "BSS_TM_REQ 02:ff:ff:ff:ff:ff",
  679. "GET_CONFIG",
  680. "RADAR DETECTED freq=5260 ht_enabled=1 chan_width=1",
  681. "CHAN_SWITCH 5 5200 ht sec_channel_offset=-1 bandwidth=40",
  682. "TRACK_STA_LIST",
  683. "PMKSA",
  684. "PMKSA_FLUSH",
  685. "SET_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1\"",
  686. "REMOVE_NEIGHBOR 00:11:22:33:44:55 ssid=\"test1\"",
  687. "REQ_LCI 00:11:22:33:44:55",
  688. "REQ_RANGE 00:11:22:33:44:55",
  689. "DRIVER_FLAGS",
  690. "STOP_AP" ]
  691. for cmd in cmds:
  692. hapd.request(cmd)
  693. def test_hapd_ctrl_set(dev, apdev):
  694. """hostapd and SET ctrl_iface command"""
  695. ssid = "hapd-ctrl"
  696. params = { "ssid": ssid }
  697. hapd = hostapd.add_ap(apdev[0], params)
  698. tests = [ "foo",
  699. "wps_version_number 300",
  700. "gas_frag_limit 0",
  701. "mbo_assoc_disallow 0" ]
  702. for t in tests:
  703. if "FAIL" not in hapd.request("SET " + t):
  704. raise Exception("Invalid SET command accepted: " + t)
  705. def test_hapd_ctrl_radar(dev, apdev):
  706. """hostapd and RADAR ctrl_iface command"""
  707. ssid = "hapd-ctrl"
  708. params = { "ssid": ssid }
  709. hapd = hostapd.add_ap(apdev[0], params)
  710. tests = [ "foo", "foo bar" ]
  711. for t in tests:
  712. if "FAIL" not in hapd.request("RADAR " + t):
  713. raise Exception("Invalid RADAR command accepted: " + t)
  714. tests = [ "DETECTED freq=2412 chan_offset=12 cf1=1234 cf2=2345",
  715. "CAC-FINISHED freq=2412",
  716. "CAC-ABORTED freq=2412",
  717. "NOP-FINISHED freq=2412" ]
  718. for t in tests:
  719. hapd.request("RADAR " + t)
  720. def test_hapd_ctrl_ext_io_errors(dev, apdev):
  721. """hostapd and external I/O errors"""
  722. ssid = "hapd-ctrl"
  723. params = { "ssid": ssid }
  724. hapd = hostapd.add_ap(apdev[0], params)
  725. tests = [ "MGMT_TX 1",
  726. "MGMT_TX 1q",
  727. "MGMT_RX_PROCESS freq=2412",
  728. "EAPOL_RX foo",
  729. "EAPOL_RX 00:11:22:33:44:55 1",
  730. "EAPOL_RX 00:11:22:33:44:55 1q" ]
  731. for t in tests:
  732. if "FAIL" not in hapd.request(t):
  733. raise Exception("Invalid command accepted: " + t)
  734. with alloc_fail(hapd, 1, "=hostapd_ctrl_iface_mgmt_tx"):
  735. if "FAIL" not in hapd.request("MGMT_TX 12"):
  736. raise Exception("MGMT_TX accepted during OOM")
  737. with alloc_fail(hapd, 1, "=hostapd_ctrl_iface_eapol_rx"):
  738. if "FAIL" not in hapd.request("EAPOL_RX 00:11:22:33:44:55 11"):
  739. raise Exception("EAPOL_RX accepted during OOM")
  740. hapd.set("ext_mgmt_frame_handling", "1")
  741. tests = [ "MGMT_RX_PROCESS freq=2412",
  742. "MGMT_RX_PROCESS freq=2412 ssi_signal=0",
  743. "MGMT_RX_PROCESS freq=2412 frame=1",
  744. "MGMT_RX_PROCESS freq=2412 frame=1q" ]
  745. for t in tests:
  746. if "FAIL" not in hapd.request(t):
  747. raise Exception("Invalid command accepted: " + t)
  748. with alloc_fail(hapd, 1, "=hostapd_ctrl_iface_mgmt_rx_process"):
  749. if "FAIL" not in hapd.request("MGMT_RX_PROCESS freq=2412 frame=11"):
  750. raise Exception("MGMT_RX_PROCESS accepted during OOM")
  751. hapd.set("ext_mgmt_frame_handling", "0")
  752. if "OK" not in hapd.request("DATA_TEST_CONFIG 1"):
  753. raise Exception("Failed to enable l2_test")
  754. if "OK" not in hapd.request("DATA_TEST_CONFIG 1"):
  755. raise Exception("Failed to enable l2_test(2)")
  756. tests = [ "DATA_TEST_TX foo",
  757. "DATA_TEST_TX 00:11:22:33:44:55 foo",
  758. "DATA_TEST_TX 00:11:22:33:44:55 00:11:22:33:44:55 -1",
  759. "DATA_TEST_TX 00:11:22:33:44:55 00:11:22:33:44:55 256" ]
  760. for t in tests:
  761. if "FAIL" not in hapd.request(t):
  762. raise Exception("Invalid command accepted: " + t)
  763. if "OK" not in hapd.request("DATA_TEST_CONFIG 0"):
  764. raise Exception("Failed to disable l2_test")
  765. tests = [ "DATA_TEST_TX 00:11:22:33:44:55 00:11:22:33:44:55 0",
  766. "DATA_TEST_FRAME ifname=foo",
  767. "DATA_TEST_FRAME 1",
  768. "DATA_TEST_FRAME 11",
  769. "DATA_TEST_FRAME 112233445566778899aabbccddeefq" ]
  770. for t in tests:
  771. if "FAIL" not in hapd.request(t):
  772. raise Exception("Invalid command accepted: " + t)
  773. with alloc_fail(hapd, 1, "=hostapd_ctrl_iface_data_test_frame"):
  774. if "FAIL" not in hapd.request("DATA_TEST_FRAME 112233445566778899aabbccddeeff"):
  775. raise Exception("DATA_TEST_FRAME accepted during OOM")
  776. def test_hapd_ctrl_vendor_errors(dev, apdev):
  777. """hostapd and VENDOR errors"""
  778. ssid = "hapd-ctrl"
  779. params = { "ssid": ssid }
  780. hapd = hostapd.add_ap(apdev[0], params)
  781. tests = [ "q",
  782. "10q",
  783. "10 10q",
  784. "10 10 123q",
  785. "10 10" ]
  786. for t in tests:
  787. if "FAIL" not in hapd.request("VENDOR " + t):
  788. raise Exception("Invalid VENDOR command accepted: " + t)
  789. with alloc_fail(hapd, 1, "=hostapd_ctrl_iface_vendor"):
  790. if "FAIL" not in hapd.request("VENDOR 10 10 10"):
  791. raise Exception("VENDOR accepted during OOM")
  792. with alloc_fail(hapd, 1, "wpabuf_alloc;hostapd_ctrl_iface_vendor"):
  793. if "FAIL" not in hapd.request("VENDOR 10 10"):
  794. raise Exception("VENDOR accepted during OOM")
  795. def test_hapd_ctrl_eapol_reauth_errors(dev, apdev):
  796. """hostapd and EAPOL_REAUTH errors"""
  797. ssid = "hapd-ctrl"
  798. params = { "ssid": ssid }
  799. hapd = hostapd.add_ap(apdev[0], params)
  800. tests = [ "foo",
  801. "11:22:33:44:55:66" ]
  802. for t in tests:
  803. if "FAIL" not in hapd.request("EAPOL_REAUTH " + t):
  804. raise Exception("Invalid EAPOL_REAUTH command accepted: " + t)
  805. def test_hapd_ctrl_eapol_relog(dev, apdev):
  806. """hostapd and RELOG"""
  807. ssid = "hapd-ctrl"
  808. params = { "ssid": ssid }
  809. hapd = hostapd.add_ap(apdev[0], params)
  810. if "OK" not in hapd.request("RELOG"):
  811. raise Exception("RELOG failed")
  812. def test_hapd_ctrl_poll_sta_errors(dev, apdev):
  813. """hostapd and POLL_STA errors"""
  814. ssid = "hapd-ctrl"
  815. params = { "ssid": ssid }
  816. hapd = hostapd.add_ap(apdev[0], params)
  817. tests = [ "foo",
  818. "11:22:33:44:55:66" ]
  819. for t in tests:
  820. if "FAIL" not in hapd.request("POLL_STA " + t):
  821. raise Exception("Invalid POLL_STA command accepted: " + t)
  822. def test_hapd_ctrl_update_beacon(dev, apdev):
  823. """hostapd and UPDATE_BEACON"""
  824. ssid = "hapd-ctrl"
  825. params = { "ssid": ssid }
  826. hapd = hostapd.add_ap(apdev[0], params)
  827. if "OK" not in hapd.request("UPDATE_BEACON"):
  828. raise Exception("UPDATE_BEACON failed")
  829. with fail_test(hapd, 1, "ieee802_11_set_beacon"):
  830. if "FAIL" not in hapd.request("UPDATE_BEACON"):
  831. raise Exception("UPDATE_BEACON succeeded unexpectedly")
  832. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  833. def test_hapd_ctrl_test_fail(dev, apdev):
  834. """hostapd and TEST_ALLOC_FAIL/TEST_FAIL"""
  835. ssid = "hapd-ctrl"
  836. params = { "ssid": ssid }
  837. hapd = hostapd.add_ap(apdev[0], params)
  838. if "OK" not in hapd.request("TEST_ALLOC_FAIL 1:unknownfunc"):
  839. raise HwsimSkip("TEST_ALLOC_FAIL not supported")
  840. if "OK" not in hapd.request("TEST_ALLOC_FAIL "):
  841. raise Exception("TEST_ALLOC_FAIL clearing failed")
  842. if "OK" not in hapd.request("TEST_FAIL "):
  843. raise Exception("TEST_FAIL clearing failed")