test_ap_params.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. # Test various AP mode parameters
  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 logging
  8. logger = logging.getLogger()
  9. import os
  10. import struct
  11. import subprocess
  12. import time
  13. import hwsim_utils
  14. import hostapd
  15. from tshark import run_tshark
  16. from utils import alloc_fail, HwsimSkip, parse_ie
  17. @remote_compatible
  18. def test_ap_fragmentation_rts_set_high(dev, apdev):
  19. """WPA2-PSK AP with fragmentation and RTS thresholds larger than frame length"""
  20. ssid = "test-wpa2-psk"
  21. passphrase = 'qwertyuiop'
  22. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  23. params['rts_threshold'] = "1000"
  24. params['fragm_threshold'] = "2000"
  25. hapd = hostapd.add_ap(apdev[0], params)
  26. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  27. hwsim_utils.test_connectivity(dev[0], hapd)
  28. @remote_compatible
  29. def test_ap_fragmentation_open(dev, apdev):
  30. """Open AP with fragmentation threshold"""
  31. ssid = "fragmentation"
  32. params = {}
  33. params['ssid'] = ssid
  34. params['fragm_threshold'] = "1000"
  35. hapd = hostapd.add_ap(apdev[0], params)
  36. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  37. hwsim_utils.test_connectivity(dev[0], hapd)
  38. @remote_compatible
  39. def test_ap_fragmentation_wpa2(dev, apdev):
  40. """WPA2-PSK AP with fragmentation threshold"""
  41. ssid = "test-wpa2-psk"
  42. passphrase = 'qwertyuiop'
  43. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  44. params['fragm_threshold'] = "1000"
  45. hapd = hostapd.add_ap(apdev[0], params)
  46. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  47. hwsim_utils.test_connectivity(dev[0], hapd)
  48. def test_ap_vendor_elements(dev, apdev):
  49. """WPA2-PSK AP with vendor elements added"""
  50. bssid = apdev[0]['bssid']
  51. ssid = "test-wpa2-psk"
  52. passphrase = 'qwertyuiop'
  53. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  54. params['vendor_elements'] = "dd0411223301"
  55. params['assocresp_elements'] = "dd0411223302"
  56. hapd = hostapd.add_ap(apdev[0], params)
  57. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  58. bss = dev[0].get_bss(bssid)
  59. if "dd0411223301" not in bss['ie']:
  60. raise Exception("Vendor element not shown in scan results")
  61. hapd.set('vendor_elements', 'dd051122330203dd0400137400dd04001374ff')
  62. if "OK" not in hapd.request("UPDATE_BEACON"):
  63. raise Exception("UPDATE_BEACON failed")
  64. dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
  65. bss = dev[1].get_bss(bssid)
  66. if "dd0411223301" in bss['ie']:
  67. raise Exception("Old vendor element still in scan results")
  68. if "dd051122330203" not in bss['ie']:
  69. raise Exception("New vendor element not shown in scan results")
  70. def test_ap_element_parse(dev, apdev):
  71. """Information element parsing - extra coverage"""
  72. bssid = apdev[0]['bssid']
  73. ssid = "test-wpa2-psk"
  74. params = { 'ssid': ssid,
  75. 'vendor_elements': "380501020304059e009e009e009e009e009e00" }
  76. hapd = hostapd.add_ap(apdev[0], params)
  77. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  78. bss = dev[0].get_bss(bssid)
  79. if "38050102030405" not in bss['ie']:
  80. raise Exception("Timeout element not shown in scan results")
  81. @remote_compatible
  82. def test_ap_element_parse_oom(dev, apdev):
  83. """Information element parsing OOM"""
  84. bssid = apdev[0]['bssid']
  85. ssid = "test-wpa2-psk"
  86. params = { 'ssid': ssid,
  87. 'vendor_elements': "dd0d506f9a0a00000600411c440028" }
  88. hapd = hostapd.add_ap(apdev[0], params)
  89. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  90. with alloc_fail(dev[0], 1, "wpabuf_alloc;ieee802_11_vendor_ie_concat"):
  91. bss = dev[0].get_bss(bssid)
  92. logger.info(str(bss))
  93. def test_ap_country(dev, apdev):
  94. """WPA2-PSK AP setting country code and using 5 GHz band"""
  95. try:
  96. hapd = None
  97. bssid = apdev[0]['bssid']
  98. ssid = "test-wpa2-psk"
  99. passphrase = 'qwertyuiop'
  100. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  101. params['country_code'] = 'FI'
  102. params['ieee80211d'] = '1'
  103. params['hw_mode'] = 'a'
  104. params['channel'] = '36'
  105. hapd = hostapd.add_ap(apdev[0], params)
  106. dev[0].connect(ssid, psk=passphrase, scan_freq="5180")
  107. hwsim_utils.test_connectivity(dev[0], hapd)
  108. finally:
  109. dev[0].request("DISCONNECT")
  110. if hapd:
  111. hapd.request("DISABLE")
  112. hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
  113. dev[0].flush_scan_cache()
  114. def test_ap_acl_accept(dev, apdev):
  115. """MAC ACL accept list"""
  116. ssid = "acl"
  117. params = {}
  118. params['ssid'] = ssid
  119. params['accept_mac_file'] = "hostapd.macaddr"
  120. hapd = hostapd.add_ap(apdev[0], params)
  121. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  122. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  123. dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
  124. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  125. dev[0].request("REMOVE_NETWORK all")
  126. dev[1].request("REMOVE_NETWORK all")
  127. hapd.request("SET macaddr_acl 1")
  128. dev[1].dump_monitor()
  129. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  130. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  131. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  132. if ev is not None:
  133. raise Exception("Unexpected association")
  134. def test_ap_acl_deny(dev, apdev):
  135. """MAC ACL deny list"""
  136. ssid = "acl"
  137. params = {}
  138. params['ssid'] = ssid
  139. params['deny_mac_file'] = "hostapd.macaddr"
  140. hapd = hostapd.add_ap(apdev[0], params)
  141. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  142. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  143. dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
  144. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  145. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  146. if ev is not None:
  147. raise Exception("Unexpected association")
  148. @remote_compatible
  149. def test_ap_wds_sta(dev, apdev):
  150. """WPA2-PSK AP with STA using 4addr mode"""
  151. ssid = "test-wpa2-psk"
  152. passphrase = 'qwertyuiop'
  153. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  154. params['wds_sta'] = "1"
  155. params['wds_bridge'] = "wds-br0"
  156. hapd = hostapd.add_ap(apdev[0], params)
  157. try:
  158. dev[0].cmd_execute(['brctl', 'addbr', 'wds-br0'])
  159. dev[0].cmd_execute(['brctl', 'setfd', 'wds-br0', '0'])
  160. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'up'])
  161. dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'on'])
  162. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  163. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  164. max_tries=15)
  165. dev[0].request("REATTACH")
  166. dev[0].wait_connected()
  167. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  168. max_tries=15)
  169. dev[0].request("SET reassoc_same_bss_optim 1")
  170. dev[0].request("REATTACH")
  171. dev[0].wait_connected()
  172. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  173. max_tries=5, timeout=1)
  174. finally:
  175. dev[0].request("SET reassoc_same_bss_optim 0")
  176. dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'off'])
  177. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'down'])
  178. dev[0].cmd_execute(['brctl', 'delbr', 'wds-br0'])
  179. def test_ap_wds_sta_open(dev, apdev):
  180. """Open AP with STA using 4addr mode"""
  181. ssid = "test-wds-open"
  182. params = {}
  183. params['ssid'] = ssid
  184. params['wds_sta'] = "1"
  185. params['wds_bridge'] = "wds-br0"
  186. hapd = hostapd.add_ap(apdev[0], params)
  187. try:
  188. dev[0].cmd_execute(['brctl', 'addbr', 'wds-br0'])
  189. dev[0].cmd_execute(['brctl', 'setfd', 'wds-br0', '0'])
  190. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'up'])
  191. dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'on'])
  192. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  193. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  194. max_tries=15)
  195. dev[0].request("REATTACH")
  196. dev[0].wait_connected()
  197. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  198. max_tries=15)
  199. dev[0].request("SET reassoc_same_bss_optim 1")
  200. dev[0].request("REATTACH")
  201. dev[0].wait_connected()
  202. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  203. max_tries=5, timeout=1)
  204. finally:
  205. dev[0].request("SET reassoc_same_bss_optim 0")
  206. dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'off'])
  207. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'down'])
  208. dev[0].cmd_execute(['brctl', 'delbr', 'wds-br0'])
  209. def test_ap_wds_sta_wep(dev, apdev):
  210. """WEP AP with STA using 4addr mode"""
  211. ssid = "test-wds-wep"
  212. params = {}
  213. params['ssid'] = ssid
  214. params["ieee80211n"] = "0"
  215. params['wep_key0'] = '"hello"'
  216. params['wds_sta'] = "1"
  217. params['wds_bridge'] = "wds-br0"
  218. hapd = hostapd.add_ap(apdev[0], params)
  219. try:
  220. dev[0].cmd_execute(['brctl', 'addbr', 'wds-br0'])
  221. dev[0].cmd_execute(['brctl', 'setfd', 'wds-br0', '0'])
  222. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'up'])
  223. dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'on'])
  224. dev[0].connect(ssid, key_mgmt="NONE", wep_key0='"hello"',
  225. scan_freq="2412")
  226. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  227. max_tries=15)
  228. dev[0].request("REATTACH")
  229. dev[0].wait_connected()
  230. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  231. max_tries=15)
  232. dev[0].request("SET reassoc_same_bss_optim 1")
  233. dev[0].request("REATTACH")
  234. dev[0].wait_connected()
  235. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  236. max_tries=5, timeout=1)
  237. finally:
  238. dev[0].request("SET reassoc_same_bss_optim 0")
  239. dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'off'])
  240. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'down'])
  241. dev[0].cmd_execute(['brctl', 'delbr', 'wds-br0'])
  242. @remote_compatible
  243. def test_ap_inactivity_poll(dev, apdev):
  244. """AP using inactivity poll"""
  245. ssid = "test-wpa2-psk"
  246. passphrase = 'qwertyuiop'
  247. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  248. params['ap_max_inactivity'] = "1"
  249. hapd = hostapd.add_ap(apdev[0], params)
  250. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  251. hapd.set("ext_mgmt_frame_handling", "1")
  252. dev[0].request("DISCONNECT")
  253. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  254. if ev is None:
  255. raise Exception("MGMT RX wait timed out for Deauth")
  256. hapd.set("ext_mgmt_frame_handling", "0")
  257. ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=30)
  258. if ev is None:
  259. raise Exception("STA disconnection on inactivity was not reported")
  260. @remote_compatible
  261. def test_ap_inactivity_disconnect(dev, apdev):
  262. """AP using inactivity disconnect"""
  263. ssid = "test-wpa2-psk"
  264. passphrase = 'qwertyuiop'
  265. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  266. params['ap_max_inactivity'] = "1"
  267. params['skip_inactivity_poll'] = "1"
  268. hapd = hostapd.add_ap(apdev[0], params)
  269. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  270. hapd.set("ext_mgmt_frame_handling", "1")
  271. dev[0].request("DISCONNECT")
  272. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  273. if ev is None:
  274. raise Exception("MGMT RX wait timed out for Deauth")
  275. hapd.set("ext_mgmt_frame_handling", "0")
  276. ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=30)
  277. if ev is None:
  278. raise Exception("STA disconnection on inactivity was not reported")
  279. @remote_compatible
  280. def test_ap_basic_rates(dev, apdev):
  281. """Open AP with lots of basic rates"""
  282. ssid = "basic rates"
  283. params = {}
  284. params['ssid'] = ssid
  285. params['basic_rates'] = "10 20 55 110 60 90 120 180 240 360 480 540"
  286. hostapd.add_ap(apdev[0], params)
  287. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  288. @remote_compatible
  289. def test_ap_short_preamble(dev, apdev):
  290. """Open AP with short preamble"""
  291. ssid = "short preamble"
  292. params = {}
  293. params['ssid'] = ssid
  294. params['preamble'] = "1"
  295. hostapd.add_ap(apdev[0], params)
  296. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  297. def test_ap_spectrum_management_required(dev, apdev):
  298. """Open AP with spectrum management required"""
  299. ssid = "spectrum mgmt"
  300. params = {}
  301. params['ssid'] = ssid
  302. params["country_code"] = "JP"
  303. params["hw_mode"] = "a"
  304. params["channel"] = "36"
  305. params["ieee80211d"] = "1"
  306. params["local_pwr_constraint"] = "3"
  307. params['spectrum_mgmt_required'] = "1"
  308. try:
  309. hapd = None
  310. hapd = hostapd.add_ap(apdev[0], params)
  311. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="5180")
  312. finally:
  313. dev[0].request("DISCONNECT")
  314. if hapd:
  315. hapd.request("DISABLE")
  316. hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
  317. dev[0].flush_scan_cache()
  318. @remote_compatible
  319. def test_ap_max_listen_interval(dev, apdev):
  320. """Open AP with maximum listen interval limit"""
  321. ssid = "listen"
  322. params = {}
  323. params['ssid'] = ssid
  324. params['max_listen_interval'] = "1"
  325. hostapd.add_ap(apdev[0], params)
  326. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  327. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  328. if ev is None:
  329. raise Exception("Association rejection not reported")
  330. if "status_code=51" not in ev:
  331. raise Exception("Unexpected ASSOC-REJECT reason")
  332. @remote_compatible
  333. def test_ap_max_num_sta(dev, apdev):
  334. """Open AP with maximum STA count"""
  335. ssid = "max"
  336. params = {}
  337. params['ssid'] = ssid
  338. params['max_num_sta'] = "1"
  339. hostapd.add_ap(apdev[0], params)
  340. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  341. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  342. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  343. if ev is not None:
  344. raise Exception("Unexpected association")
  345. def test_ap_max_num_sta_no_probe_resp(dev, apdev, params):
  346. """Maximum STA count and limit on Probe Response frames"""
  347. logdir = params['logdir']
  348. dev[0].flush_scan_cache()
  349. ssid = "max"
  350. params = {}
  351. params['ssid'] = ssid
  352. params['beacon_int'] = "2000"
  353. params['max_num_sta'] = "1"
  354. params['no_probe_resp_if_max_sta'] = "1"
  355. hostapd.add_ap(apdev[0], params)
  356. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  357. dev[0].scan(freq=2412, type="ONLY")
  358. dev[0].scan(freq=2412, type="ONLY")
  359. seen = dev[0].get_bss(apdev[0]['bssid']) != None
  360. dev[1].scan(freq=2412, type="ONLY")
  361. if seen:
  362. out = run_tshark(os.path.join(logdir, "hwsim0.pcapng"),
  363. "wlan.fc.type_subtype == 5", ["wlan.da" ])
  364. if out:
  365. if dev[0].own_addr() not in out:
  366. # Discovery happened through Beacon frame reception. That's not
  367. # an error case.
  368. seen = False
  369. if dev[1].own_addr() not in out:
  370. raise Exception("No Probe Response frames to dev[1] seen")
  371. if seen:
  372. raise Exception("AP found unexpectedly")
  373. @remote_compatible
  374. def test_ap_tx_queue_params(dev, apdev):
  375. """Open AP with TX queue params set"""
  376. ssid = "tx"
  377. params = {}
  378. params['ssid'] = ssid
  379. params['tx_queue_data2_aifs'] = "4"
  380. params['tx_queue_data2_cwmin'] = "7"
  381. params['tx_queue_data2_cwmax'] = "1023"
  382. params['tx_queue_data2_burst'] = "4.2"
  383. params['tx_queue_data1_aifs'] = "4"
  384. params['tx_queue_data1_cwmin'] = "7"
  385. params['tx_queue_data1_cwmax'] = "1023"
  386. params['tx_queue_data1_burst'] = "2"
  387. hapd = hostapd.add_ap(apdev[0], params)
  388. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  389. hwsim_utils.test_connectivity(dev[0], hapd)
  390. def test_ap_tx_queue_params_invalid(dev, apdev):
  391. """Invalid TX queue params set (cwmin/cwmax)"""
  392. ssid = "tx"
  393. params = {}
  394. params['ssid'] = ssid
  395. params['tx_queue_data2_aifs'] = "4"
  396. params['tx_queue_data2_cwmin'] = "7"
  397. params['tx_queue_data2_cwmax'] = "1023"
  398. params['tx_queue_data2_burst'] = "4.2"
  399. params['wmm_ac_bk_cwmin'] = "4"
  400. params['wmm_ac_bk_cwmax'] = "10"
  401. params['wmm_ac_bk_aifs'] = "7"
  402. params['wmm_ac_bk_txop_limit'] = "0"
  403. params['wmm_ac_bk_acm'] = "0"
  404. hapd = hostapd.add_ap(apdev[0], params)
  405. # "Invalid TX queue cwMin/cwMax values. cwMin(7) greater than cwMax(3)"
  406. if "FAIL" not in hapd.request('SET tx_queue_data2_cwmax 3'):
  407. raise Exception("TX cwMax < cwMin accepted")
  408. # "Invalid WMM AC cwMin/cwMax values. cwMin(4) greater than cwMax(3)"
  409. if "FAIL" not in hapd.request('SET wmm_ac_bk_cwmax 3'):
  410. raise Exception("AC cwMax < cwMin accepted")
  411. def test_ap_beacon_rate_legacy(dev, apdev):
  412. """Open AP with Beacon frame TX rate 5.5 Mbps"""
  413. hapd = hostapd.add_ap(apdev[0], { 'ssid': 'beacon-rate' })
  414. res = hapd.get_driver_status_field('capa.flags')
  415. if (int(res, 0) & 0x0000080000000000) == 0:
  416. raise HwsimSkip("Setting Beacon frame TX rate not supported")
  417. hapd.disable()
  418. hapd.set('beacon_rate', '55')
  419. hapd.enable()
  420. dev[0].connect('beacon-rate', key_mgmt="NONE", scan_freq="2412")
  421. def test_ap_beacon_rate_legacy2(dev, apdev):
  422. """Open AP with Beacon frame TX rate 12 Mbps in VHT BSS"""
  423. hapd = hostapd.add_ap(apdev[0], { 'ssid': 'beacon-rate' })
  424. res = hapd.get_driver_status_field('capa.flags')
  425. if (int(res, 0) & 0x0000080000000000) == 0:
  426. raise HwsimSkip("Setting Beacon frame TX rate not supported")
  427. hapd.disable()
  428. hapd.set('beacon_rate', '120')
  429. hapd.set("country_code", "DE")
  430. hapd.set("hw_mode", "a")
  431. hapd.set("channel", "36")
  432. hapd.set("ieee80211n", "1")
  433. hapd.set("ieee80211ac", "1")
  434. hapd.set("ht_capab", "[HT40+]")
  435. hapd.set("vht_capab", "")
  436. hapd.set("vht_oper_chwidth", "0")
  437. hapd.set("vht_oper_centr_freq_seg0_idx", "0")
  438. try:
  439. hapd.enable()
  440. dev[0].scan_for_bss(hapd.own_addr(), freq="5180")
  441. dev[0].connect('beacon-rate', key_mgmt="NONE", scan_freq="5180")
  442. finally:
  443. dev[0].request("DISCONNECT")
  444. hapd.request("DISABLE")
  445. subprocess.call(['iw', 'reg', 'set', '00'])
  446. dev[0].flush_scan_cache()
  447. def test_ap_beacon_rate_ht(dev, apdev):
  448. """Open AP with Beacon frame TX rate HT-MCS 0"""
  449. hapd = hostapd.add_ap(apdev[0], { 'ssid': 'beacon-rate' })
  450. res = hapd.get_driver_status_field('capa.flags')
  451. if (int(res, 0) & 0x0000100000000000) == 0:
  452. raise HwsimSkip("Setting Beacon frame TX rate not supported")
  453. hapd.disable()
  454. hapd.set('beacon_rate', 'ht:0')
  455. hapd.enable()
  456. dev[0].connect('beacon-rate', key_mgmt="NONE", scan_freq="2412")
  457. def test_ap_beacon_rate_ht2(dev, apdev):
  458. """Open AP with Beacon frame TX rate HT-MCS 1 in VHT BSS"""
  459. hapd = hostapd.add_ap(apdev[0], { 'ssid': 'beacon-rate' })
  460. res = hapd.get_driver_status_field('capa.flags')
  461. if (int(res, 0) & 0x0000100000000000) == 0:
  462. raise HwsimSkip("Setting Beacon frame TX rate not supported")
  463. hapd.disable()
  464. hapd.set('beacon_rate', 'ht:1')
  465. hapd.set("country_code", "DE")
  466. hapd.set("hw_mode", "a")
  467. hapd.set("channel", "36")
  468. hapd.set("ieee80211n", "1")
  469. hapd.set("ieee80211ac", "1")
  470. hapd.set("ht_capab", "[HT40+]")
  471. hapd.set("vht_capab", "")
  472. hapd.set("vht_oper_chwidth", "0")
  473. hapd.set("vht_oper_centr_freq_seg0_idx", "0")
  474. try:
  475. hapd.enable()
  476. dev[0].scan_for_bss(hapd.own_addr(), freq="5180")
  477. dev[0].connect('beacon-rate', key_mgmt="NONE", scan_freq="5180")
  478. finally:
  479. dev[0].request("DISCONNECT")
  480. hapd.request("DISABLE")
  481. subprocess.call(['iw', 'reg', 'set', '00'])
  482. dev[0].flush_scan_cache()
  483. def test_ap_beacon_rate_vht(dev, apdev):
  484. """Open AP with Beacon frame TX rate VHT-MCS 0"""
  485. hapd = hostapd.add_ap(apdev[0], { 'ssid': 'beacon-rate' })
  486. res = hapd.get_driver_status_field('capa.flags')
  487. if (int(res, 0) & 0x0000200000000000) == 0:
  488. raise HwsimSkip("Setting Beacon frame TX rate not supported")
  489. hapd.disable()
  490. hapd.set('beacon_rate', 'vht:0')
  491. hapd.set("country_code", "DE")
  492. hapd.set("hw_mode", "a")
  493. hapd.set("channel", "36")
  494. hapd.set("ieee80211n", "1")
  495. hapd.set("ieee80211ac", "1")
  496. hapd.set("ht_capab", "[HT40+]")
  497. hapd.set("vht_capab", "")
  498. hapd.set("vht_oper_chwidth", "0")
  499. hapd.set("vht_oper_centr_freq_seg0_idx", "0")
  500. try:
  501. hapd.enable()
  502. dev[0].scan_for_bss(hapd.own_addr(), freq="5180")
  503. dev[0].connect('beacon-rate', key_mgmt="NONE", scan_freq="5180")
  504. finally:
  505. dev[0].request("DISCONNECT")
  506. hapd.request("DISABLE")
  507. subprocess.call(['iw', 'reg', 'set', '00'])
  508. dev[0].flush_scan_cache()
  509. def test_ap_wep_to_wpa(dev, apdev):
  510. """WEP to WPA2-PSK configuration change in hostapd"""
  511. hapd = hostapd.add_ap(apdev[0],
  512. { "ssid": "wep-to-wpa",
  513. "wep_key0": '"hello"' })
  514. dev[0].flush_scan_cache()
  515. dev[0].connect("wep-to-wpa", key_mgmt="NONE", wep_key0='"hello"',
  516. scan_freq="2412")
  517. hwsim_utils.test_connectivity(dev[0], hapd)
  518. dev[0].request("DISCONNECT")
  519. dev[0].wait_disconnected()
  520. hapd.disable()
  521. hapd.set("wep_key0", "")
  522. hapd.set("wpa_passphrase", "12345678")
  523. hapd.set("wpa", "2")
  524. hapd.set("wpa_key_mgmt", "WPA-PSK")
  525. hapd.set("rsn_pairwise", "CCMP")
  526. hapd.enable()
  527. dev[0].connect("wep-to-wpa", psk="12345678", scan_freq="2412")
  528. hwsim_utils.test_connectivity(dev[0], hapd)
  529. def test_ap_missing_psk(dev, apdev):
  530. """WPA2-PSK AP and no PSK configured"""
  531. ssid = "test-wpa2-psk"
  532. params = hostapd.wpa2_params(ssid=ssid)
  533. try:
  534. # "WPA-PSK enabled, but PSK or passphrase is not configured."
  535. hostapd.add_ap(apdev[0], params)
  536. raise Exception("AP setup succeeded unexpectedly")
  537. except Exception, e:
  538. if "Failed to enable hostapd" in str(e):
  539. pass
  540. else:
  541. raise
  542. def test_ap_eapol_version(dev, apdev):
  543. """hostapd eapol_version configuration"""
  544. passphrase = "asdfghjkl"
  545. params = hostapd.wpa2_params(ssid="test1", passphrase=passphrase)
  546. hapd = hostapd.add_ap(apdev[0], params)
  547. params = hostapd.wpa2_params(ssid="test2", passphrase=passphrase)
  548. params['eapol_version'] = '1'
  549. hapd2 = hostapd.add_ap(apdev[1], params)
  550. hapd.request("SET ext_eapol_frame_io 1")
  551. dev[0].connect("test1", psk=passphrase, scan_freq="2412",
  552. wait_connect=False)
  553. ev1 = hapd.wait_event(["EAPOL-TX"], timeout=15)
  554. if ev1 is None:
  555. raise Exception("Timeout on EAPOL-TX from hostapd")
  556. hapd.request("SET ext_eapol_frame_io 0")
  557. hapd2.request("SET ext_eapol_frame_io 1")
  558. dev[1].connect("test2", psk=passphrase, scan_freq="2412",
  559. wait_connect=False)
  560. ev2 = hapd2.wait_event(["EAPOL-TX"], timeout=15)
  561. if ev2 is None:
  562. raise Exception("Timeout on EAPOL-TX from hostapd")
  563. hapd2.request("SET ext_eapol_frame_io 0")
  564. dev[0].wait_connected()
  565. dev[1].wait_connected()
  566. ver1 = ev1.split(' ')[2][0:2]
  567. ver2 = ev2.split(' ')[2][0:2]
  568. if ver1 != "02":
  569. raise Exception("Unexpected default eapol_version: " + ver1)
  570. if ver2 != "01":
  571. raise Exception("eapol_version did not match configuration: " + ver2)
  572. def test_ap_dtim_period(dev, apdev):
  573. """DTIM period configuration"""
  574. ssid = "dtim-period"
  575. params = { 'ssid': ssid, 'dtim_period': "10" }
  576. hapd = hostapd.add_ap(apdev[0], params)
  577. bssid = hapd.own_addr()
  578. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  579. for i in range(10):
  580. dev[0].scan(freq="2412")
  581. bss = dev[0].get_bss(bssid)
  582. if 'beacon_ie' in bss:
  583. break
  584. time.sleep(0.2)
  585. if 'beacon_ie' not in bss:
  586. raise Exception("Did not find Beacon IEs")
  587. ie = parse_ie(bss['beacon_ie'])
  588. if 5 not in ie:
  589. raise Exception("TIM element missing")
  590. count, period = struct.unpack('BB', ie[5][0:2])
  591. logger.info("DTIM count %d DTIM period %d" % (count, period))
  592. if period != 10:
  593. raise Exception("Unexpected DTIM period: %d" % period)
  594. if count >= period:
  595. raise Exception("Unexpected DTIM count: %d" % count)
  596. def test_ap_no_probe_resp(dev, apdev):
  597. """AP with Probe Response frame sending from hostapd disabled"""
  598. ssid = "no-probe-resp"
  599. params = { 'ssid': ssid, 'send_probe_response': "0" }
  600. hapd = hostapd.add_ap(apdev[0], params)
  601. bssid = hapd.own_addr()
  602. dev[0].scan_for_bss(bssid, freq="2412", passive=True)
  603. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  604. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  605. bss = dev[0].get_bss(bssid)
  606. if 'ie' in bss and 'beacon_ie' in bss and \
  607. len(bss['ie']) != len(bss['beacon_ie']):
  608. raise Exception("Probe Response frames seen")
  609. def test_ap_long_preamble(dev, apdev):
  610. """AP with long preamble"""
  611. ssid = "long-preamble"
  612. params = { 'ssid': ssid, 'preamble': "0",
  613. 'hw_mode': 'b', 'ieee80211n': '0',
  614. 'supported_rates': '10', 'basic_rates': '10' }
  615. hapd = hostapd.add_ap(apdev[0], params)
  616. bssid = hapd.own_addr()
  617. dev[0].scan_for_bss(bssid, freq="2412")
  618. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  619. hwsim_utils.test_connectivity(dev[0], hapd)
  620. def test_ap_wmm_uapsd(dev, apdev):
  621. """AP with U-APSD advertisement"""
  622. ssid = "uapsd"
  623. params = { 'ssid': ssid, 'uapsd_advertisement_enabled': "1" }
  624. hapd = hostapd.add_ap(apdev[0], params)
  625. bssid = hapd.own_addr()
  626. dev[0].scan_for_bss(bssid, freq="2412")
  627. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  628. hwsim_utils.test_connectivity(dev[0], hapd)
  629. def test_ap_wowlan_triggers(dev, apdev):
  630. """AP with wowlan_triggers"""
  631. ssid = "wowlan"
  632. params = { 'ssid': ssid, 'wowlan_triggers': "any" }
  633. hapd = hostapd.add_ap(apdev[0], params)
  634. bssid = hapd.own_addr()
  635. dev[0].scan_for_bss(bssid, freq="2412")
  636. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  637. hwsim_utils.test_connectivity(dev[0], hapd)