test_wpas_ap.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. # wpa_supplicant AP mode tests
  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 time
  8. import logging
  9. logger = logging.getLogger()
  10. import hwsim_utils
  11. from utils import HwsimSkip, alloc_fail
  12. from wpasupplicant import WpaSupplicant
  13. from test_p2p_channel import set_country
  14. def wait_ap_ready(dev):
  15. ev = dev.wait_event(["CTRL-EVENT-CONNECTED"])
  16. if ev is None:
  17. raise Exception("AP failed to start")
  18. def test_wpas_ap_open(dev):
  19. """wpa_supplicant AP mode - open network"""
  20. if "FAIL" not in dev[0].request("DEAUTHENTICATE 00:11:22:33:44:55"):
  21. raise Exception("Unexpected DEAUTHENTICATE accepted")
  22. if "FAIL" not in dev[0].request("DISASSOCIATE 00:11:22:33:44:55"):
  23. raise Exception("Unexpected DISASSOCIATE accepted")
  24. if "FAIL" not in dev[0].request("CHAN_SWITCH 0 2432"):
  25. raise Exception("Unexpected CHAN_SWITCH accepted")
  26. id = dev[0].add_network()
  27. dev[0].set_network(id, "mode", "2")
  28. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  29. dev[0].set_network(id, "key_mgmt", "NONE")
  30. dev[0].set_network(id, "frequency", "2412")
  31. dev[0].set_network(id, "scan_freq", "2412")
  32. dev[0].select_network(id)
  33. wait_ap_ready(dev[0])
  34. if "FAIL" not in dev[0].request("DEAUTHENTICATE foo"):
  35. raise Exception("Invalid DEAUTHENTICATE accepted")
  36. if "FAIL" not in dev[0].request("DISASSOCIATE foo"):
  37. raise Exception("Invalid DISASSOCIATE accepted")
  38. dev[1].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412")
  39. dev[2].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412")
  40. hwsim_utils.test_connectivity(dev[0], dev[1])
  41. hwsim_utils.test_connectivity(dev[1], dev[2])
  42. addr1 = dev[1].p2p_interface_addr()
  43. addr2 = dev[2].p2p_interface_addr()
  44. addrs = [ addr1, addr2 ]
  45. sta = dev[0].get_sta(None)
  46. if sta['addr'] not in addrs:
  47. raise Exception("Unexpected STA address")
  48. sta1 = dev[0].get_sta(sta['addr'])
  49. if sta1['addr'] not in addrs:
  50. raise Exception("Unexpected STA address")
  51. sta2 = dev[0].get_sta(sta['addr'], next=True)
  52. if sta2['addr'] not in addrs:
  53. raise Exception("Unexpected STA2 address")
  54. sta3 = dev[0].get_sta(sta2['addr'], next=True)
  55. if len(sta3) != 0:
  56. raise Exception("Unexpected STA iteration result (did not stop)")
  57. status = dev[0].get_status()
  58. if status['mode'] != "AP":
  59. raise Exception("Unexpected status mode")
  60. dev[1].dump_monitor()
  61. dev[2].dump_monitor()
  62. dev[0].request("DEAUTHENTICATE " + addr1)
  63. dev[0].request("DISASSOCIATE " + addr2)
  64. dev[1].wait_disconnected(timeout=10)
  65. dev[2].wait_disconnected(timeout=10)
  66. dev[1].wait_connected(timeout=10, error="Reconnection timed out")
  67. dev[2].wait_connected(timeout=10, error="Reconnection timed out")
  68. dev[1].request("DISCONNECT")
  69. dev[2].request("DISCONNECT")
  70. def test_wpas_ap_open_isolate(dev):
  71. """wpa_supplicant AP mode - open network with client isolation"""
  72. try:
  73. dev[0].set("ap_isolate", "1")
  74. id = dev[0].add_network()
  75. dev[0].set_network(id, "mode", "2")
  76. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  77. dev[0].set_network(id, "key_mgmt", "NONE")
  78. dev[0].set_network(id, "frequency", "2412")
  79. dev[0].set_network(id, "scan_freq", "2412")
  80. dev[0].select_network(id)
  81. wait_ap_ready(dev[0])
  82. dev[1].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412")
  83. dev[2].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412")
  84. hwsim_utils.test_connectivity(dev[0], dev[1])
  85. hwsim_utils.test_connectivity(dev[0], dev[2])
  86. hwsim_utils.test_connectivity(dev[1], dev[2], success_expected=False,
  87. timeout=1)
  88. finally:
  89. dev[0].set("ap_isolate", "0")
  90. @remote_compatible
  91. def test_wpas_ap_wep(dev):
  92. """wpa_supplicant AP mode - WEP"""
  93. id = dev[0].add_network()
  94. dev[0].set_network(id, "mode", "2")
  95. dev[0].set_network_quoted(id, "ssid", "wpas-ap-wep")
  96. dev[0].set_network(id, "key_mgmt", "NONE")
  97. dev[0].set_network(id, "frequency", "2412")
  98. dev[0].set_network(id, "scan_freq", "2412")
  99. dev[0].set_network_quoted(id, "wep_key0", "hello")
  100. dev[0].select_network(id)
  101. wait_ap_ready(dev[0])
  102. dev[1].connect("wpas-ap-wep", key_mgmt="NONE", wep_key0='"hello"',
  103. scan_freq="2412")
  104. hwsim_utils.test_connectivity(dev[0], dev[1])
  105. dev[1].request("DISCONNECT")
  106. @remote_compatible
  107. def test_wpas_ap_no_ssid(dev):
  108. """wpa_supplicant AP mode - invalid network configuration"""
  109. id = dev[0].add_network()
  110. dev[0].set_network(id, "mode", "2")
  111. dev[0].set_network(id, "key_mgmt", "NONE")
  112. dev[0].set_network(id, "frequency", "2412")
  113. dev[0].set_network(id, "scan_freq", "2412")
  114. dev[0].select_network(id)
  115. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  116. if ev is not None:
  117. raise Exception("Unexpected AP start")
  118. @remote_compatible
  119. def test_wpas_ap_default_frequency(dev):
  120. """wpa_supplicant AP mode - default frequency"""
  121. id = dev[0].add_network()
  122. dev[0].set_network(id, "mode", "2")
  123. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  124. dev[0].set_network(id, "key_mgmt", "NONE")
  125. dev[0].set_network(id, "scan_freq", "2412")
  126. dev[0].select_network(id)
  127. wait_ap_ready(dev[0])
  128. dev[1].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2462")
  129. dev[1].request("DISCONNECT")
  130. @remote_compatible
  131. def test_wpas_ap_invalid_frequency(dev):
  132. """wpa_supplicant AP mode - invalid frequency configuration"""
  133. id = dev[0].add_network()
  134. dev[0].set_network(id, "mode", "2")
  135. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  136. dev[0].set_network(id, "key_mgmt", "NONE")
  137. dev[0].set_network(id, "frequency", "2413")
  138. dev[0].set_network(id, "scan_freq", "2412")
  139. dev[0].select_network(id)
  140. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  141. if ev is not None:
  142. raise Exception("Unexpected AP start")
  143. def test_wpas_ap_wps(dev):
  144. """wpa_supplicant AP mode - WPS operations"""
  145. id = dev[0].add_network()
  146. dev[0].set_network(id, "mode", "2")
  147. dev[0].set_network_quoted(id, "ssid", "wpas-ap-wps")
  148. dev[0].set_network_quoted(id, "psk", "1234567890")
  149. dev[0].set_network(id, "frequency", "2412")
  150. dev[0].set_network(id, "scan_freq", "2412")
  151. dev[0].select_network(id)
  152. wait_ap_ready(dev[0])
  153. bssid = dev[0].p2p_interface_addr()
  154. logger.info("Test PBC mode start/stop")
  155. if "FAIL" not in dev[0].request("WPS_CANCEL"):
  156. raise Exception("Unexpected WPS_CANCEL success")
  157. dev[0].request("WPS_PBC")
  158. ev = dev[0].wait_event(["WPS-PBC-ACTIVE"])
  159. if ev is None:
  160. raise Exception("PBC mode start timeout")
  161. if "OK" not in dev[0].request("WPS_CANCEL"):
  162. raise Exception("Unexpected WPS_CANCEL failure")
  163. ev = dev[0].wait_event(["WPS-TIMEOUT"])
  164. if ev is None:
  165. raise Exception("PBC mode disabling timeout")
  166. logger.info("Test PBC protocol run")
  167. dev[0].request("WPS_PBC")
  168. ev = dev[0].wait_event(["WPS-PBC-ACTIVE"])
  169. if ev is None:
  170. raise Exception("PBC mode start timeout")
  171. dev[1].request("WPS_PBC")
  172. dev[1].wait_connected(timeout=30, error="WPS PBC operation timed out")
  173. hwsim_utils.test_connectivity(dev[0], dev[1])
  174. logger.info("Test AP PIN to learn configuration")
  175. pin = dev[0].request("WPS_AP_PIN random")
  176. if "FAIL" in pin:
  177. raise Exception("Could not generate random AP PIN")
  178. if pin not in dev[0].request("WPS_AP_PIN get"):
  179. raise Exception("Could not fetch current AP PIN")
  180. dev[2].wps_reg(bssid, pin)
  181. hwsim_utils.test_connectivity(dev[1], dev[2])
  182. dev[1].request("REMOVE_NETWORK all")
  183. dev[2].request("REMOVE_NETWORK all")
  184. logger.info("Test AP PIN operations")
  185. dev[0].request("WPS_AP_PIN disable")
  186. dev[0].request("WPS_AP_PIN set " + pin + " 1")
  187. time.sleep(1.1)
  188. if "FAIL" not in dev[0].request("WPS_AP_PIN get"):
  189. raise Exception("AP PIN unexpectedly still enabled")
  190. pin = dev[1].wps_read_pin()
  191. dev[0].request("WPS_PIN any " + pin)
  192. dev[1].request("WPS_PIN any " + pin)
  193. dev[1].wait_connected(timeout=30)
  194. dev[1].request("REMOVE_NETWORK all")
  195. dev[1].dump_monitor()
  196. dev[0].request("WPS_PIN any " + pin + " 100")
  197. dev[1].request("WPS_PIN any " + pin)
  198. dev[1].wait_connected(timeout=30)
  199. dev[1].request("REMOVE_NETWORK all")
  200. dev[1].dump_monitor()
  201. dev[0].request("WPS_AP_PIN set 12345670")
  202. dev[0].dump_monitor()
  203. runs = ("88887777", "12340000", "00000000", "12345670")
  204. for pin in runs:
  205. logger.info("Try AP PIN " + pin)
  206. dev[2].dump_monitor()
  207. dev[2].request("WPS_REG " + bssid + " " + pin)
  208. ev = dev[2].wait_event(["WPS-SUCCESS", "WPS-FAIL msg"], timeout=15)
  209. if ev is None:
  210. raise Exception("WPS operation timed out")
  211. if "WPS-SUCCESS" in ev:
  212. raise Exception("WPS operation succeeded unexpectedly")
  213. dev[2].wait_disconnected(timeout=10)
  214. dev[2].request("WPS_CANCEL")
  215. dev[2].request("REMOVE_NETWORK all")
  216. ev = dev[0].wait_event(["WPS-AP-SETUP-LOCKED"])
  217. if ev is None:
  218. raise Exception("WPS AP PIN not locked")
  219. dev[0].dump_monitor()
  220. logger.info("Test random AP PIN timeout")
  221. pin = dev[0].request("WPS_AP_PIN random 1")
  222. if "FAIL" in pin:
  223. raise Exception("Could not generate random AP PIN")
  224. res = dev[0].request("WPS_AP_PIN get")
  225. if pin not in res:
  226. raise Exception("Could not fetch current AP PIN")
  227. for i in range(10):
  228. time.sleep(0.2)
  229. res = dev[0].request("WPS_AP_PIN get")
  230. if "FAIL" in res:
  231. break
  232. if "FAIL" not in res:
  233. raise Exception("WPS_AP_PIN random timeout did not work")
  234. if "FAIL" not in dev[0].request("WPS_AP_PIN foo"):
  235. raise Exception("Invalid WPS_AP_PIN command not rejected")
  236. if "FAIL" not in dev[0].request("WPS_AP_PIN set"):
  237. raise Exception("Invalid WPS_AP_PIN command not rejected")
  238. def test_wpas_ap_wps_frag(dev):
  239. """wpa_supplicant AP mode - WPS operations with fragmentation"""
  240. id = dev[0].add_network()
  241. dev[0].set_network(id, "mode", "2")
  242. dev[0].set_network_quoted(id, "ssid", "wpas-ap-wps")
  243. dev[0].set_network_quoted(id, "psk", "1234567890")
  244. dev[0].set_network(id, "frequency", "2412")
  245. dev[0].set_network(id, "scan_freq", "2412")
  246. dev[0].set_network(id, "fragment_size", "300")
  247. dev[0].select_network(id)
  248. wait_ap_ready(dev[0])
  249. bssid = dev[0].own_addr()
  250. pin = dev[1].wps_read_pin()
  251. dev[0].request("WPS_PIN any " + pin)
  252. dev[1].scan_for_bss(bssid, freq="2412")
  253. dev[1].request("WPS_PIN " + bssid + " " + pin)
  254. dev[1].wait_connected(timeout=30)
  255. def test_wpas_ap_wps_pbc_overlap(dev):
  256. """wpa_supplicant AP mode - WPS operations with PBC overlap"""
  257. id = dev[0].add_network()
  258. dev[0].set_network(id, "mode", "2")
  259. dev[0].set_network_quoted(id, "ssid", "wpas-ap-wps")
  260. dev[0].set_network_quoted(id, "psk", "1234567890")
  261. dev[0].set_network(id, "frequency", "2412")
  262. dev[0].set_network(id, "scan_freq", "2412")
  263. dev[0].select_network(id)
  264. wait_ap_ready(dev[0])
  265. bssid = dev[0].p2p_interface_addr()
  266. dev[1].scan_for_bss(bssid, freq="2412")
  267. dev[1].dump_monitor()
  268. dev[2].scan_for_bss(bssid, freq="2412")
  269. dev[2].dump_monitor()
  270. dev[0].request("WPS_PBC")
  271. dev[1].request("WPS_PBC " + bssid)
  272. dev[2].request("WPS_PBC " + bssid)
  273. ev = dev[1].wait_event(["WPS-M2D"], timeout=15)
  274. if ev is None:
  275. raise Exception("PBC session overlap not detected (dev1)")
  276. if "config_error=12" not in ev:
  277. raise Exception("PBC session overlap not correctly reported (dev1)")
  278. ev = dev[2].wait_event(["WPS-M2D"], timeout=15)
  279. if ev is None:
  280. raise Exception("PBC session overlap not detected (dev2)")
  281. if "config_error=12" not in ev:
  282. raise Exception("PBC session overlap not correctly reported (dev2)")
  283. if "FAIL-PBC-OVERLAP" not in dev[0].request("WPS_PBC"):
  284. raise Exception("WPS_PBC(AP) accepted during overlap")
  285. if "FAIL-PBC-OVERLAP" not in dev[0].request("WPS_PBC any"):
  286. raise Exception("WPS_PBC(AP) accepted during overlap")
  287. dev[0].request("WPS_CANCEL")
  288. dev[1].request("WPS_CANCEL")
  289. dev[2].request("WPS_CANCEL")
  290. @remote_compatible
  291. def test_wpas_ap_wps_disabled(dev):
  292. """wpa_supplicant AP mode - WPS disabled"""
  293. id = dev[0].add_network()
  294. dev[0].set_network(id, "mode", "2")
  295. dev[0].set_network_quoted(id, "ssid", "wpas-ap-no-wps")
  296. dev[0].set_network_quoted(id, "psk", "12345678")
  297. dev[0].set_network(id, "frequency", "2412")
  298. dev[0].set_network(id, "scan_freq", "2412")
  299. dev[0].set_network(id, "wps_disabled", "1")
  300. dev[0].select_network(id)
  301. wait_ap_ready(dev[0])
  302. dev[1].connect("wpas-ap-no-wps", psk="12345678", scan_freq="2412")
  303. dev[1].request("DISCONNECT")
  304. dev[1].wait_disconnected()
  305. def test_wpas_ap_dfs(dev):
  306. """wpa_supplicant AP mode - DFS"""
  307. if dev[0].get_mcc() > 1:
  308. raise HwsimSkip("DFS is not supported with multi channel contexts")
  309. try:
  310. _test_wpas_ap_dfs(dev)
  311. finally:
  312. set_country("00")
  313. dev[0].request("SET country 00")
  314. dev[1].flush_scan_cache()
  315. def _test_wpas_ap_dfs(dev):
  316. set_country("US")
  317. dev[0].request("SET country US")
  318. id = dev[0].add_network()
  319. dev[0].set_network(id, "mode", "2")
  320. dev[0].set_network_quoted(id, "ssid", "wpas-ap-dfs")
  321. dev[0].set_network(id, "key_mgmt", "NONE")
  322. dev[0].set_network(id, "frequency", "5260")
  323. dev[0].set_network(id, "scan_freq", "5260")
  324. dev[0].select_network(id)
  325. ev = dev[0].wait_event(["DFS-CAC-START"])
  326. if ev is None:
  327. # For now, assume DFS is not supported by all kernel builds.
  328. raise HwsimSkip("CAC did not start - assume not supported")
  329. ev = dev[0].wait_event(["DFS-CAC-COMPLETED"], timeout=70)
  330. if ev is None:
  331. raise Exception("CAC did not complete")
  332. if "success=1" not in ev:
  333. raise Exception("CAC failed")
  334. if "freq=5260" not in ev:
  335. raise Exception("Unexpected DFS freq result")
  336. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"])
  337. if ev is None:
  338. raise Exception("AP failed to start")
  339. dev[1].connect("wpas-ap-dfs", key_mgmt="NONE")
  340. dev[1].request("DISCONNECT")
  341. dev[1].wait_disconnected()
  342. @remote_compatible
  343. def test_wpas_ap_disable(dev):
  344. """wpa_supplicant AP mode - DISABLE_NETWORK"""
  345. id = dev[0].add_network()
  346. dev[0].set_network(id, "mode", "2")
  347. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  348. dev[0].set_network(id, "key_mgmt", "NONE")
  349. dev[0].set_network(id, "scan_freq", "2412")
  350. dev[0].select_network(id)
  351. ev = dev[0].wait_event(["AP-ENABLED"])
  352. if ev is None:
  353. raise Exception("AP-ENABLED event not seen")
  354. wait_ap_ready(dev[0])
  355. dev[0].request("DISABLE_NETWORK %d" % id)
  356. ev = dev[0].wait_event(["AP-DISABLED"])
  357. if ev is None:
  358. raise Exception("AP-DISABLED event not seen")
  359. dev[0].wait_disconnected()
  360. def test_wpas_ap_acs(dev):
  361. """wpa_supplicant AP mode - ACS"""
  362. res = dev[0].get_capability("acs")
  363. if res is None or "ACS" not in res:
  364. raise HwsimSkip("ACS not supported")
  365. # For now, make sure the last operating channel was on 2.4 GHz band to get
  366. # sufficient survey data from mac80211_hwsim.
  367. id = dev[0].add_network()
  368. dev[0].set_network(id, "mode", "2")
  369. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  370. dev[0].set_network(id, "key_mgmt", "NONE")
  371. dev[0].set_network(id, "frequency", "2412")
  372. dev[0].set_network(id, "scan_freq", "2412")
  373. dev[0].select_network(id)
  374. wait_ap_ready(dev[0])
  375. dev[0].request("REMOVE_NETWORK all")
  376. dev[0].wait_disconnected()
  377. id = dev[0].add_network()
  378. dev[0].set_network(id, "mode", "2")
  379. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  380. dev[0].set_network(id, "key_mgmt", "NONE")
  381. dev[0].set_network(id, "frequency", "2417")
  382. dev[0].set_network(id, "scan_freq", "2417")
  383. dev[0].set_network(id, "acs", "1")
  384. dev[0].select_network(id)
  385. wait_ap_ready(dev[0])
  386. # ACS prefers channels 1, 6, 11
  387. freq = dev[0].get_status_field('freq')
  388. if freq == "2417":
  389. raise Exception("Unexpected operating channel selected")
  390. dev[1].connect("wpas-ap-open", key_mgmt="NONE", scan_freq=freq)
  391. @remote_compatible
  392. def test_wpas_ap_and_assoc_req_p2p_ie(dev):
  393. """wpa_supplicant AP mode - unexpected P2P IE in Association Request"""
  394. try:
  395. _test_wpas_ap_and_assoc_req_p2p_ie(dev)
  396. finally:
  397. dev[1].request("VENDOR_ELEM_REMOVE 13 *")
  398. dev[0].request("P2P_SET disabled 0")
  399. def _test_wpas_ap_and_assoc_req_p2p_ie(dev):
  400. dev[0].request("P2P_SET disabled 1")
  401. id = dev[0].add_network()
  402. dev[0].set_network(id, "mode", "2")
  403. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  404. dev[0].set_network(id, "key_mgmt", "NONE")
  405. dev[0].set_network(id, "frequency", "2412")
  406. dev[0].set_network(id, "scan_freq", "2412")
  407. dev[0].select_network(id)
  408. wait_ap_ready(dev[0])
  409. dev[1].request("VENDOR_ELEM_ADD 13 dd04506f9a09")
  410. dev[1].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412")
  411. dev[1].request("DISCONNECT")
  412. dev[1].wait_disconnected()
  413. dev[0].request("DISCONNECT")
  414. dev[0].wait_disconnected()
  415. @remote_compatible
  416. def test_wpas_ap_open_ht_disabled(dev):
  417. """wpa_supplicant AP mode - open network and HT disabled"""
  418. id = dev[0].add_network()
  419. dev[0].set_network(id, "mode", "2")
  420. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  421. dev[0].set_network(id, "key_mgmt", "NONE")
  422. dev[0].set_network(id, "frequency", "2412")
  423. dev[0].set_network(id, "scan_freq", "2412")
  424. dev[0].set_network(id, "disable_ht", "1")
  425. dev[0].select_network(id)
  426. wait_ap_ready(dev[0])
  427. dev[1].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412")
  428. hwsim_utils.test_connectivity(dev[0], dev[1])
  429. def test_wpas_ap_failures(dev):
  430. """wpa_supplicant AP mode - failures"""
  431. # No SSID configured for AP mode
  432. id = dev[0].add_network()
  433. dev[0].set_network(id, "mode", "2")
  434. dev[0].set_network(id, "key_mgmt", "NONE")
  435. dev[0].set_network(id, "frequency", "2412")
  436. dev[0].set_network(id, "scan_freq", "2412")
  437. dev[0].select_network(id)
  438. ev = dev[0].wait_event([ "CTRL-EVENT-CONNECTED" ], timeout=0.1)
  439. if ev is not None:
  440. raise Exception("Unexpected connection event")
  441. dev[0].request("REMOVE_NETWORK all")
  442. # Invalid pbss value(2) for AP mode
  443. dev[0].dump_monitor()
  444. id = dev[0].add_network()
  445. dev[0].set_network(id, "mode", "2")
  446. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  447. dev[0].set_network(id, "key_mgmt", "NONE")
  448. dev[0].set_network(id, "frequency", "2412")
  449. dev[0].set_network(id, "scan_freq", "2412")
  450. dev[0].set_network(id, "pbss", "2")
  451. dev[0].select_network(id)
  452. ev = dev[0].wait_event([ "CTRL-EVENT-CONNECTED",
  453. "CTRL-EVENT-DISCONNECTED" ], timeout=0.1)
  454. if ev is not None and "CTRL-EVENT-CONNECTED" in ev:
  455. raise Exception("Unexpected connection event(2)")
  456. dev[0].request("REMOVE_NETWORK all")
  457. def test_wpas_ap_oom(dev):
  458. """wpa_supplicant AP mode - OOM"""
  459. id = dev[0].add_network()
  460. dev[0].set_network(id, "mode", "2")
  461. dev[0].set_network_quoted(id, "ssid", "wpas-ap")
  462. dev[0].set_network_quoted(id, "psk", "1234567890")
  463. dev[0].set_network(id, "frequency", "2412")
  464. dev[0].set_network(id, "scan_freq", "2412")
  465. with alloc_fail(dev[0], 1, "=wpa_supplicant_conf_ap"):
  466. dev[0].select_network(id)
  467. dev[0].wait_disconnected()
  468. dev[0].request("REMOVE_NETWORK all")
  469. id = dev[0].add_network()
  470. dev[0].set_network(id, "mode", "2")
  471. dev[0].set_network_quoted(id, "ssid", "wpas-ap")
  472. dev[0].set_network(id, "psk", "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef")
  473. dev[0].set_network(id, "frequency", "2412")
  474. dev[0].set_network(id, "scan_freq", "2412")
  475. with alloc_fail(dev[0], 1, "=wpa_supplicant_conf_ap"):
  476. dev[0].select_network(id)
  477. dev[0].wait_disconnected()
  478. dev[0].request("REMOVE_NETWORK all")
  479. id = dev[0].add_network()
  480. dev[0].set_network(id, "mode", "2")
  481. dev[0].set_network_quoted(id, "ssid", "wpas-ap")
  482. dev[0].set_network(id, "key_mgmt", "NONE")
  483. dev[0].set_network_quoted(id, "wep_key0", "hello")
  484. dev[0].set_network(id, "frequency", "2412")
  485. dev[0].set_network(id, "scan_freq", "2412")
  486. with alloc_fail(dev[0], 1, "=wpa_supplicant_conf_ap"):
  487. dev[0].select_network(id)
  488. dev[0].wait_disconnected()
  489. dev[0].request("REMOVE_NETWORK all")
  490. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  491. wpas.interface_add("wlan5")
  492. wpas.request("SET manufacturer test")
  493. wpas.request("SET model_name test")
  494. wpas.request("SET model_number test")
  495. wpas.request("SET serial_number test")
  496. wpas.request("SET serial_number test")
  497. wpas.request("SET serial_number test")
  498. wpas.request("SET ap_vendor_elements dd0411223301")
  499. id = wpas.add_network()
  500. wpas.set_network(id, "mode", "2")
  501. wpas.set_network_quoted(id, "ssid", "wpas-ap")
  502. wpas.set_network(id, "key_mgmt", "NONE")
  503. wpas.set_network(id, "frequency", "2412")
  504. wpas.set_network(id, "scan_freq", "2412")
  505. for i in range(5):
  506. with alloc_fail(wpas, i, "=wpa_supplicant_conf_ap"):
  507. wpas.select_network(id)
  508. ev = dev[0].wait_event([ "CTRL-EVENT-CONNECTED",
  509. "CTRL-EVENT-DISCONNECTED" ], timeout=1)
  510. wpas.request("DISCONNECT")
  511. wpas.wait_disconnected()
  512. def test_wpas_ap_params(dev):
  513. """wpa_supplicant AP mode - parameters"""
  514. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  515. wpas.interface_add("wlan5")
  516. wpas.request("SET manufacturer test")
  517. wpas.request("SET model_name test")
  518. wpas.request("SET model_number test")
  519. wpas.request("SET serial_number test")
  520. wpas.request("SET serial_number test")
  521. wpas.request("SET serial_number test")
  522. wpas.request("SET ap_vendor_elements dd0411223301")
  523. id = wpas.add_network()
  524. wpas.set_network(id, "mode", "2")
  525. wpas.set_network_quoted(id, "ssid", "wpas-ap")
  526. wpas.set_network(id, "key_mgmt", "NONE")
  527. wpas.set_network(id, "frequency", "2412")
  528. wpas.set_network(id, "scan_freq", "2412")
  529. wpas.select_network(id)
  530. wpas.wait_connected()
  531. wpas.request("DISCONNECT")
  532. wpas.wait_disconnected()
  533. wpas.request("SET beacon_int 200 3")
  534. wpas.request("SET dtim_period 3")
  535. wpas.select_network(id)
  536. wpas.wait_connected()
  537. wpas.request("DISCONNECT")
  538. wpas.wait_disconnected()
  539. wpas.set_network(id, "beacon_int", "300")
  540. wpas.set_network(id, "dtim_period", "2")
  541. wpas.select_network(id)
  542. wpas.wait_connected()
  543. if "---- AP ----" not in wpas.request("PMKSA"):
  544. raise Exception("AP section missing from PMKSA output")
  545. if "OK" not in wpas.request("PMKSA_FLUSH"):
  546. raise Exception("PMKSA_FLUSH failed")
  547. wpas.request("DISCONNECT")
  548. wpas.wait_disconnected()
  549. def test_wpas_ap_global_sta(dev):
  550. """wpa_supplicant AP mode - STA commands on global control interface"""
  551. id = dev[0].add_network()
  552. dev[0].set_network(id, "mode", "2")
  553. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  554. dev[0].set_network(id, "key_mgmt", "NONE")
  555. dev[0].set_network(id, "frequency", "2412")
  556. dev[0].set_network(id, "scan_freq", "2412")
  557. dev[0].select_network(id)
  558. wait_ap_ready(dev[0])
  559. dev[1].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412")
  560. addr1 = dev[1].own_addr()
  561. res = dev[0].global_request("STA " + addr1)
  562. if "UNKNOWN COMMAND" in res:
  563. raise Exception("STA command not known on global control interface")
  564. res = dev[0].global_request("STA-FIRST")
  565. if "UNKNOWN COMMAND" in res:
  566. raise Exception("STA-FIRST command not known on global control interface")
  567. res = dev[0].global_request("STA-NEXT " + addr1)
  568. if "UNKNOWN COMMAND" in res:
  569. raise Exception("STA-NEXT command not known on global control interface")
  570. dev[1].request("DISCONNECT")
  571. dev[1].wait_disconnected()
  572. dev[0].request("DISCONNECT")
  573. dev[0].wait_disconnected()
  574. def test_wpas_ap_5ghz(dev):
  575. """wpa_supplicant AP mode - 5 GHz"""
  576. try:
  577. _test_wpas_ap_5ghz(dev)
  578. finally:
  579. set_country("00")
  580. dev[0].request("SET country 00")
  581. dev[1].flush_scan_cache()
  582. def _test_wpas_ap_5ghz(dev):
  583. set_country("US")
  584. dev[0].request("SET country US")
  585. id = dev[0].add_network()
  586. dev[0].set_network(id, "mode", "2")
  587. dev[0].set_network_quoted(id, "ssid", "wpas-ap-5ghz")
  588. dev[0].set_network(id, "key_mgmt", "NONE")
  589. dev[0].set_network(id, "frequency", "5180")
  590. dev[0].set_network(id, "scan_freq", "5180")
  591. dev[0].select_network(id)
  592. wait_ap_ready(dev[0])
  593. dev[1].connect("wpas-ap-5ghz", key_mgmt="NONE", scan_freq="5180")
  594. dev[1].request("DISCONNECT")
  595. dev[1].wait_disconnected()
  596. def test_wpas_ap_open_vht80(dev):
  597. """wpa_supplicant AP mode - VHT 80 MHz"""
  598. id = dev[0].add_network()
  599. dev[0].set("country", "FI")
  600. try:
  601. dev[0].set_network(id, "mode", "2")
  602. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  603. dev[0].set_network(id, "key_mgmt", "NONE")
  604. dev[0].set_network(id, "frequency", "5180")
  605. dev[0].set_network(id, "scan_freq", "5180")
  606. dev[0].set_network(id, "vht", "1")
  607. dev[0].set_network(id, "vht_center_freq1", "5210")
  608. dev[0].set_network(id, "max_oper_chwidth", "1")
  609. dev[0].set_network(id, "ht40", "1")
  610. dev[0].select_network(id)
  611. wait_ap_ready(dev[0])
  612. dev[1].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="5180")
  613. sig = dev[1].request("SIGNAL_POLL").splitlines()
  614. hwsim_utils.test_connectivity(dev[0], dev[1])
  615. dev[1].request("DISCONNECT")
  616. dev[1].wait_disconnected()
  617. if "FREQUENCY=5180" not in sig:
  618. raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
  619. if "WIDTH=80 MHz" not in sig:
  620. raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
  621. finally:
  622. set_country("00")
  623. dev[0].set("country", "00")
  624. dev[1].flush_scan_cache()
  625. def test_wpas_ap_no_ht(dev):
  626. """wpa_supplicant AP mode - HT disabled"""
  627. id = dev[0].add_network()
  628. dev[0].set_network(id, "mode", "2")
  629. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  630. dev[0].set_network(id, "key_mgmt", "NONE")
  631. dev[0].set_network(id, "frequency", "2412")
  632. dev[0].set_network(id, "scan_freq", "2412")
  633. dev[0].set_network(id, "ht", "0")
  634. dev[0].set_network(id, "wps_disabled", "1")
  635. dev[0].select_network(id)
  636. wait_ap_ready(dev[0])
  637. dev[1].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412")
  638. sig = dev[1].request("SIGNAL_POLL").splitlines()
  639. dev[1].request("DISCONNECT")
  640. dev[1].wait_disconnected()
  641. dev[0].request("REMOVE_NETWORK all")
  642. dev[0].wait_disconnected()
  643. id = dev[0].add_network()
  644. dev[0].set_network(id, "mode", "2")
  645. dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
  646. dev[0].set_network(id, "key_mgmt", "NONE")
  647. dev[0].set_network(id, "frequency", "2412")
  648. dev[0].set_network(id, "scan_freq", "2412")
  649. dev[0].set_network(id, "wps_disabled", "1")
  650. dev[0].select_network(id)
  651. wait_ap_ready(dev[0])
  652. dev[1].flush_scan_cache()
  653. dev[1].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412")
  654. sig2 = dev[1].request("SIGNAL_POLL").splitlines()
  655. dev[1].request("DISCONNECT")
  656. dev[1].wait_disconnected()
  657. dev[0].request("REMOVE_NETWORK all")
  658. dev[0].wait_disconnected()
  659. if "WIDTH=20 MHz (no HT)" not in sig:
  660. raise Exception("HT was not disabled: " + str(sig))
  661. if "WIDTH=20 MHz" not in sig2:
  662. raise Exception("HT was not enabled: " + str(sig2))