test_hapd_ctrl.py 42 KB

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