test_ap_params.py 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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. def test_ap_acl_mgmt(dev, apdev):
  149. """MAC ACL accept/deny management"""
  150. ssid = "acl"
  151. params = {}
  152. params['ssid'] = ssid
  153. params['deny_mac_file'] = "hostapd.macaddr"
  154. hapd = hostapd.add_ap(apdev[0], params)
  155. accept = hapd.request("ACCEPT_ACL SHOW").splitlines()
  156. logger.info("accept: " + str(accept))
  157. deny = hapd.request("DENY_ACL SHOW").splitlines()
  158. logger.info("deny: " + str(deny))
  159. if len(accept) != 0:
  160. raise Exception("Unexpected number of accept entries")
  161. if len(deny) != 3:
  162. raise Exception("Unexpected number of deny entries")
  163. if "01:01:01:01:01:01 VLAN_ID=0" not in deny:
  164. raise Exception("Missing deny entry")
  165. hapd.request("ACCEPT_ACL ADD_MAC 22:33:44:55:66:77")
  166. hapd.request("DENY_ACL ADD_MAC 22:33:44:55:66:88 VLAN_ID=2")
  167. accept = hapd.request("ACCEPT_ACL SHOW").splitlines()
  168. logger.info("accept: " + str(accept))
  169. deny = hapd.request("DENY_ACL SHOW").splitlines()
  170. logger.info("deny: " + str(deny))
  171. if len(accept) != 1:
  172. raise Exception("Unexpected number of accept entries (2)")
  173. if len(deny) != 4:
  174. raise Exception("Unexpected number of deny entries (2)")
  175. if "01:01:01:01:01:01 VLAN_ID=0" not in deny:
  176. raise Exception("Missing deny entry (2)")
  177. if "22:33:44:55:66:88 VLAN_ID=2" not in deny:
  178. raise Exception("Missing deny entry (2)")
  179. if "22:33:44:55:66:77 VLAN_ID=0" not in accept:
  180. raise Exception("Missing accept entry (2)")
  181. hapd.request("ACCEPT_ACL DEL_MAC 22:33:44:55:66:77")
  182. hapd.request("DENY_ACL DEL_MAC 22:33:44:55:66:88")
  183. accept = hapd.request("ACCEPT_ACL SHOW").splitlines()
  184. logger.info("accept: " + str(accept))
  185. deny = hapd.request("DENY_ACL SHOW").splitlines()
  186. logger.info("deny: " + str(deny))
  187. if len(accept) != 0:
  188. raise Exception("Unexpected number of accept entries (3)")
  189. if len(deny) != 3:
  190. raise Exception("Unexpected number of deny entries (3)")
  191. if "01:01:01:01:01:01 VLAN_ID=0" not in deny:
  192. raise Exception("Missing deny entry (3)")
  193. hapd.request("ACCEPT_ACL CLEAR")
  194. hapd.request("DENY_ACL CLEAR")
  195. accept = hapd.request("ACCEPT_ACL SHOW").splitlines()
  196. logger.info("accept: " + str(accept))
  197. deny = hapd.request("DENY_ACL SHOW").splitlines()
  198. logger.info("deny: " + str(deny))
  199. if len(accept) != 0:
  200. raise Exception("Unexpected number of accept entries (4)")
  201. if len(deny) != 0:
  202. raise Exception("Unexpected number of deny entries (4)")
  203. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  204. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  205. dev[0].dump_monitor()
  206. hapd.request("DENY_ACL ADD_MAC " + dev[0].own_addr())
  207. dev[0].wait_disconnected()
  208. dev[0].request("DISCONNECT")
  209. @remote_compatible
  210. def test_ap_wds_sta(dev, apdev):
  211. """WPA2-PSK AP with STA using 4addr mode"""
  212. ssid = "test-wpa2-psk"
  213. passphrase = 'qwertyuiop'
  214. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  215. params['wds_sta'] = "1"
  216. params['wds_bridge'] = "wds-br0"
  217. hapd = hostapd.add_ap(apdev[0], params)
  218. try:
  219. dev[0].cmd_execute(['brctl', 'addbr', 'wds-br0'])
  220. dev[0].cmd_execute(['brctl', 'setfd', 'wds-br0', '0'])
  221. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'up'])
  222. dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'on'])
  223. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  224. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  225. max_tries=15)
  226. dev[0].request("REATTACH")
  227. dev[0].wait_connected()
  228. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  229. max_tries=15)
  230. dev[0].request("SET reassoc_same_bss_optim 1")
  231. dev[0].request("REATTACH")
  232. dev[0].wait_connected()
  233. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  234. max_tries=5, timeout=1)
  235. finally:
  236. dev[0].request("SET reassoc_same_bss_optim 0")
  237. dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'off'])
  238. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'down'])
  239. dev[0].cmd_execute(['brctl', 'delbr', 'wds-br0'])
  240. def test_ap_wds_sta_open(dev, apdev):
  241. """Open AP with STA using 4addr mode"""
  242. ssid = "test-wds-open"
  243. params = {}
  244. params['ssid'] = ssid
  245. params['wds_sta'] = "1"
  246. params['wds_bridge'] = "wds-br0"
  247. hapd = hostapd.add_ap(apdev[0], params)
  248. try:
  249. dev[0].cmd_execute(['brctl', 'addbr', 'wds-br0'])
  250. dev[0].cmd_execute(['brctl', 'setfd', 'wds-br0', '0'])
  251. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'up'])
  252. dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'on'])
  253. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  254. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  255. max_tries=15)
  256. dev[0].request("REATTACH")
  257. dev[0].wait_connected()
  258. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  259. max_tries=15)
  260. dev[0].request("SET reassoc_same_bss_optim 1")
  261. dev[0].request("REATTACH")
  262. dev[0].wait_connected()
  263. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  264. max_tries=5, timeout=1)
  265. finally:
  266. dev[0].request("SET reassoc_same_bss_optim 0")
  267. dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'off'])
  268. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'down'])
  269. dev[0].cmd_execute(['brctl', 'delbr', 'wds-br0'])
  270. def test_ap_wds_sta_wep(dev, apdev):
  271. """WEP AP with STA using 4addr mode"""
  272. ssid = "test-wds-wep"
  273. params = {}
  274. params['ssid'] = ssid
  275. params["ieee80211n"] = "0"
  276. params['wep_key0'] = '"hello"'
  277. params['wds_sta'] = "1"
  278. params['wds_bridge'] = "wds-br0"
  279. hapd = hostapd.add_ap(apdev[0], params)
  280. try:
  281. dev[0].cmd_execute(['brctl', 'addbr', 'wds-br0'])
  282. dev[0].cmd_execute(['brctl', 'setfd', 'wds-br0', '0'])
  283. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'up'])
  284. dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'on'])
  285. dev[0].connect(ssid, key_mgmt="NONE", wep_key0='"hello"',
  286. scan_freq="2412")
  287. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  288. max_tries=15)
  289. dev[0].request("REATTACH")
  290. dev[0].wait_connected()
  291. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  292. max_tries=15)
  293. dev[0].request("SET reassoc_same_bss_optim 1")
  294. dev[0].request("REATTACH")
  295. dev[0].wait_connected()
  296. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  297. max_tries=5, timeout=1)
  298. finally:
  299. dev[0].request("SET reassoc_same_bss_optim 0")
  300. dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'off'])
  301. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'down'])
  302. dev[0].cmd_execute(['brctl', 'delbr', 'wds-br0'])
  303. @remote_compatible
  304. def test_ap_inactivity_poll(dev, apdev):
  305. """AP using inactivity poll"""
  306. ssid = "test-wpa2-psk"
  307. passphrase = 'qwertyuiop'
  308. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  309. params['ap_max_inactivity'] = "1"
  310. hapd = hostapd.add_ap(apdev[0], params)
  311. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  312. hapd.set("ext_mgmt_frame_handling", "1")
  313. dev[0].request("DISCONNECT")
  314. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  315. if ev is None:
  316. raise Exception("MGMT RX wait timed out for Deauth")
  317. hapd.set("ext_mgmt_frame_handling", "0")
  318. ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=30)
  319. if ev is None:
  320. raise Exception("STA disconnection on inactivity was not reported")
  321. @remote_compatible
  322. def test_ap_inactivity_disconnect(dev, apdev):
  323. """AP using inactivity disconnect"""
  324. ssid = "test-wpa2-psk"
  325. passphrase = 'qwertyuiop'
  326. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  327. params['ap_max_inactivity'] = "1"
  328. params['skip_inactivity_poll'] = "1"
  329. hapd = hostapd.add_ap(apdev[0], params)
  330. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  331. hapd.set("ext_mgmt_frame_handling", "1")
  332. dev[0].request("DISCONNECT")
  333. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  334. if ev is None:
  335. raise Exception("MGMT RX wait timed out for Deauth")
  336. hapd.set("ext_mgmt_frame_handling", "0")
  337. ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=30)
  338. if ev is None:
  339. raise Exception("STA disconnection on inactivity was not reported")
  340. @remote_compatible
  341. def test_ap_basic_rates(dev, apdev):
  342. """Open AP with lots of basic rates"""
  343. ssid = "basic rates"
  344. params = {}
  345. params['ssid'] = ssid
  346. params['basic_rates'] = "10 20 55 110 60 90 120 180 240 360 480 540"
  347. hostapd.add_ap(apdev[0], params)
  348. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  349. @remote_compatible
  350. def test_ap_short_preamble(dev, apdev):
  351. """Open AP with short preamble"""
  352. ssid = "short preamble"
  353. params = {}
  354. params['ssid'] = ssid
  355. params['preamble'] = "1"
  356. hostapd.add_ap(apdev[0], params)
  357. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  358. def test_ap_spectrum_management_required(dev, apdev):
  359. """Open AP with spectrum management required"""
  360. ssid = "spectrum mgmt"
  361. params = {}
  362. params['ssid'] = ssid
  363. params["country_code"] = "JP"
  364. params["hw_mode"] = "a"
  365. params["channel"] = "36"
  366. params["ieee80211d"] = "1"
  367. params["local_pwr_constraint"] = "3"
  368. params['spectrum_mgmt_required'] = "1"
  369. try:
  370. hapd = None
  371. hapd = hostapd.add_ap(apdev[0], params)
  372. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="5180")
  373. finally:
  374. dev[0].request("DISCONNECT")
  375. if hapd:
  376. hapd.request("DISABLE")
  377. hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
  378. dev[0].flush_scan_cache()
  379. @remote_compatible
  380. def test_ap_max_listen_interval(dev, apdev):
  381. """Open AP with maximum listen interval limit"""
  382. ssid = "listen"
  383. params = {}
  384. params['ssid'] = ssid
  385. params['max_listen_interval'] = "1"
  386. hostapd.add_ap(apdev[0], params)
  387. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  388. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  389. if ev is None:
  390. raise Exception("Association rejection not reported")
  391. if "status_code=51" not in ev:
  392. raise Exception("Unexpected ASSOC-REJECT reason")
  393. @remote_compatible
  394. def test_ap_max_num_sta(dev, apdev):
  395. """Open AP with maximum STA count"""
  396. ssid = "max"
  397. params = {}
  398. params['ssid'] = ssid
  399. params['max_num_sta'] = "1"
  400. hostapd.add_ap(apdev[0], params)
  401. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  402. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  403. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  404. if ev is not None:
  405. raise Exception("Unexpected association")
  406. def test_ap_max_num_sta_no_probe_resp(dev, apdev, params):
  407. """Maximum STA count and limit on Probe Response frames"""
  408. logdir = params['logdir']
  409. dev[0].flush_scan_cache()
  410. ssid = "max"
  411. params = {}
  412. params['ssid'] = ssid
  413. params['beacon_int'] = "2000"
  414. params['max_num_sta'] = "1"
  415. params['no_probe_resp_if_max_sta'] = "1"
  416. hostapd.add_ap(apdev[0], params)
  417. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  418. dev[0].scan(freq=2412, type="ONLY")
  419. dev[0].scan(freq=2412, type="ONLY")
  420. seen = dev[0].get_bss(apdev[0]['bssid']) != None
  421. dev[1].scan(freq=2412, type="ONLY")
  422. if seen:
  423. out = run_tshark(os.path.join(logdir, "hwsim0.pcapng"),
  424. "wlan.fc.type_subtype == 5", ["wlan.da" ])
  425. if out:
  426. if dev[0].own_addr() not in out:
  427. # Discovery happened through Beacon frame reception. That's not
  428. # an error case.
  429. seen = False
  430. if dev[1].own_addr() not in out:
  431. raise Exception("No Probe Response frames to dev[1] seen")
  432. if seen:
  433. raise Exception("AP found unexpectedly")
  434. @remote_compatible
  435. def test_ap_tx_queue_params(dev, apdev):
  436. """Open AP with TX queue params set"""
  437. ssid = "tx"
  438. params = {}
  439. params['ssid'] = ssid
  440. params['tx_queue_data2_aifs'] = "4"
  441. params['tx_queue_data2_cwmin'] = "7"
  442. params['tx_queue_data2_cwmax'] = "1023"
  443. params['tx_queue_data2_burst'] = "4.2"
  444. params['tx_queue_data1_aifs'] = "4"
  445. params['tx_queue_data1_cwmin'] = "7"
  446. params['tx_queue_data1_cwmax'] = "1023"
  447. params['tx_queue_data1_burst'] = "2"
  448. hapd = hostapd.add_ap(apdev[0], params)
  449. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  450. hwsim_utils.test_connectivity(dev[0], hapd)
  451. def test_ap_tx_queue_params_invalid(dev, apdev):
  452. """Invalid TX queue params set (cwmin/cwmax)"""
  453. ssid = "tx"
  454. params = {}
  455. params['ssid'] = ssid
  456. params['tx_queue_data2_aifs'] = "4"
  457. params['tx_queue_data2_cwmin'] = "7"
  458. params['tx_queue_data2_cwmax'] = "1023"
  459. params['tx_queue_data2_burst'] = "4.2"
  460. params['wmm_ac_bk_cwmin'] = "4"
  461. params['wmm_ac_bk_cwmax'] = "10"
  462. params['wmm_ac_bk_aifs'] = "7"
  463. params['wmm_ac_bk_txop_limit'] = "0"
  464. params['wmm_ac_bk_acm'] = "0"
  465. hapd = hostapd.add_ap(apdev[0], params)
  466. # "Invalid TX queue cwMin/cwMax values. cwMin(7) greater than cwMax(3)"
  467. if "FAIL" not in hapd.request('SET tx_queue_data2_cwmax 3'):
  468. raise Exception("TX cwMax < cwMin accepted")
  469. # "Invalid WMM AC cwMin/cwMax values. cwMin(4) greater than cwMax(3)"
  470. if "FAIL" not in hapd.request('SET wmm_ac_bk_cwmax 3'):
  471. raise Exception("AC cwMax < cwMin accepted")
  472. def test_ap_beacon_rate_legacy(dev, apdev):
  473. """Open AP with Beacon frame TX rate 5.5 Mbps"""
  474. hapd = hostapd.add_ap(apdev[0], { 'ssid': 'beacon-rate' })
  475. res = hapd.get_driver_status_field('capa.flags')
  476. if (int(res, 0) & 0x0000080000000000) == 0:
  477. raise HwsimSkip("Setting Beacon frame TX rate not supported")
  478. hapd.disable()
  479. hapd.set('beacon_rate', '55')
  480. hapd.enable()
  481. dev[0].connect('beacon-rate', key_mgmt="NONE", scan_freq="2412")
  482. def test_ap_beacon_rate_legacy2(dev, apdev):
  483. """Open AP with Beacon frame TX rate 12 Mbps in VHT BSS"""
  484. hapd = hostapd.add_ap(apdev[0], { 'ssid': 'beacon-rate' })
  485. res = hapd.get_driver_status_field('capa.flags')
  486. if (int(res, 0) & 0x0000080000000000) == 0:
  487. raise HwsimSkip("Setting Beacon frame TX rate not supported")
  488. hapd.disable()
  489. hapd.set('beacon_rate', '120')
  490. hapd.set("country_code", "DE")
  491. hapd.set("hw_mode", "a")
  492. hapd.set("channel", "36")
  493. hapd.set("ieee80211n", "1")
  494. hapd.set("ieee80211ac", "1")
  495. hapd.set("ht_capab", "[HT40+]")
  496. hapd.set("vht_capab", "")
  497. hapd.set("vht_oper_chwidth", "0")
  498. hapd.set("vht_oper_centr_freq_seg0_idx", "0")
  499. try:
  500. hapd.enable()
  501. dev[0].scan_for_bss(hapd.own_addr(), freq="5180")
  502. dev[0].connect('beacon-rate', key_mgmt="NONE", scan_freq="5180")
  503. finally:
  504. dev[0].request("DISCONNECT")
  505. hapd.request("DISABLE")
  506. subprocess.call(['iw', 'reg', 'set', '00'])
  507. dev[0].flush_scan_cache()
  508. def test_ap_beacon_rate_ht(dev, apdev):
  509. """Open AP with Beacon frame TX rate HT-MCS 0"""
  510. hapd = hostapd.add_ap(apdev[0], { 'ssid': 'beacon-rate' })
  511. res = hapd.get_driver_status_field('capa.flags')
  512. if (int(res, 0) & 0x0000100000000000) == 0:
  513. raise HwsimSkip("Setting Beacon frame TX rate not supported")
  514. hapd.disable()
  515. hapd.set('beacon_rate', 'ht:0')
  516. hapd.enable()
  517. dev[0].connect('beacon-rate', key_mgmt="NONE", scan_freq="2412")
  518. def test_ap_beacon_rate_ht2(dev, apdev):
  519. """Open AP with Beacon frame TX rate HT-MCS 1 in VHT BSS"""
  520. hapd = hostapd.add_ap(apdev[0], { 'ssid': 'beacon-rate' })
  521. res = hapd.get_driver_status_field('capa.flags')
  522. if (int(res, 0) & 0x0000100000000000) == 0:
  523. raise HwsimSkip("Setting Beacon frame TX rate not supported")
  524. hapd.disable()
  525. hapd.set('beacon_rate', 'ht:1')
  526. hapd.set("country_code", "DE")
  527. hapd.set("hw_mode", "a")
  528. hapd.set("channel", "36")
  529. hapd.set("ieee80211n", "1")
  530. hapd.set("ieee80211ac", "1")
  531. hapd.set("ht_capab", "[HT40+]")
  532. hapd.set("vht_capab", "")
  533. hapd.set("vht_oper_chwidth", "0")
  534. hapd.set("vht_oper_centr_freq_seg0_idx", "0")
  535. try:
  536. hapd.enable()
  537. dev[0].scan_for_bss(hapd.own_addr(), freq="5180")
  538. dev[0].connect('beacon-rate', key_mgmt="NONE", scan_freq="5180")
  539. finally:
  540. dev[0].request("DISCONNECT")
  541. hapd.request("DISABLE")
  542. subprocess.call(['iw', 'reg', 'set', '00'])
  543. dev[0].flush_scan_cache()
  544. def test_ap_beacon_rate_vht(dev, apdev):
  545. """Open AP with Beacon frame TX rate VHT-MCS 0"""
  546. hapd = hostapd.add_ap(apdev[0], { 'ssid': 'beacon-rate' })
  547. res = hapd.get_driver_status_field('capa.flags')
  548. if (int(res, 0) & 0x0000200000000000) == 0:
  549. raise HwsimSkip("Setting Beacon frame TX rate not supported")
  550. hapd.disable()
  551. hapd.set('beacon_rate', 'vht:0')
  552. hapd.set("country_code", "DE")
  553. hapd.set("hw_mode", "a")
  554. hapd.set("channel", "36")
  555. hapd.set("ieee80211n", "1")
  556. hapd.set("ieee80211ac", "1")
  557. hapd.set("ht_capab", "[HT40+]")
  558. hapd.set("vht_capab", "")
  559. hapd.set("vht_oper_chwidth", "0")
  560. hapd.set("vht_oper_centr_freq_seg0_idx", "0")
  561. try:
  562. hapd.enable()
  563. dev[0].scan_for_bss(hapd.own_addr(), freq="5180")
  564. dev[0].connect('beacon-rate', key_mgmt="NONE", scan_freq="5180")
  565. finally:
  566. dev[0].request("DISCONNECT")
  567. hapd.request("DISABLE")
  568. subprocess.call(['iw', 'reg', 'set', '00'])
  569. dev[0].flush_scan_cache()
  570. def test_ap_wep_to_wpa(dev, apdev):
  571. """WEP to WPA2-PSK configuration change in hostapd"""
  572. hapd = hostapd.add_ap(apdev[0],
  573. { "ssid": "wep-to-wpa",
  574. "wep_key0": '"hello"' })
  575. dev[0].flush_scan_cache()
  576. dev[0].connect("wep-to-wpa", key_mgmt="NONE", wep_key0='"hello"',
  577. scan_freq="2412")
  578. hwsim_utils.test_connectivity(dev[0], hapd)
  579. dev[0].request("DISCONNECT")
  580. dev[0].wait_disconnected()
  581. hapd.disable()
  582. hapd.set("wep_key0", "")
  583. hapd.set("wpa_passphrase", "12345678")
  584. hapd.set("wpa", "2")
  585. hapd.set("wpa_key_mgmt", "WPA-PSK")
  586. hapd.set("rsn_pairwise", "CCMP")
  587. hapd.enable()
  588. dev[0].connect("wep-to-wpa", psk="12345678", scan_freq="2412")
  589. hwsim_utils.test_connectivity(dev[0], hapd)
  590. def test_ap_missing_psk(dev, apdev):
  591. """WPA2-PSK AP and no PSK configured"""
  592. ssid = "test-wpa2-psk"
  593. params = hostapd.wpa2_params(ssid=ssid)
  594. try:
  595. # "WPA-PSK enabled, but PSK or passphrase is not configured."
  596. hostapd.add_ap(apdev[0], params)
  597. raise Exception("AP setup succeeded unexpectedly")
  598. except Exception, e:
  599. if "Failed to enable hostapd" in str(e):
  600. pass
  601. else:
  602. raise
  603. def test_ap_eapol_version(dev, apdev):
  604. """hostapd eapol_version configuration"""
  605. passphrase = "asdfghjkl"
  606. params = hostapd.wpa2_params(ssid="test1", passphrase=passphrase)
  607. hapd = hostapd.add_ap(apdev[0], params)
  608. params = hostapd.wpa2_params(ssid="test2", passphrase=passphrase)
  609. params['eapol_version'] = '1'
  610. hapd2 = hostapd.add_ap(apdev[1], params)
  611. hapd.request("SET ext_eapol_frame_io 1")
  612. dev[0].connect("test1", psk=passphrase, scan_freq="2412",
  613. wait_connect=False)
  614. ev1 = hapd.wait_event(["EAPOL-TX"], timeout=15)
  615. if ev1 is None:
  616. raise Exception("Timeout on EAPOL-TX from hostapd")
  617. hapd.request("SET ext_eapol_frame_io 0")
  618. hapd2.request("SET ext_eapol_frame_io 1")
  619. dev[1].connect("test2", psk=passphrase, scan_freq="2412",
  620. wait_connect=False)
  621. ev2 = hapd2.wait_event(["EAPOL-TX"], timeout=15)
  622. if ev2 is None:
  623. raise Exception("Timeout on EAPOL-TX from hostapd")
  624. hapd2.request("SET ext_eapol_frame_io 0")
  625. dev[0].wait_connected()
  626. dev[1].wait_connected()
  627. ver1 = ev1.split(' ')[2][0:2]
  628. ver2 = ev2.split(' ')[2][0:2]
  629. if ver1 != "02":
  630. raise Exception("Unexpected default eapol_version: " + ver1)
  631. if ver2 != "01":
  632. raise Exception("eapol_version did not match configuration: " + ver2)
  633. def test_ap_dtim_period(dev, apdev):
  634. """DTIM period configuration"""
  635. ssid = "dtim-period"
  636. params = { 'ssid': ssid, 'dtim_period': "10" }
  637. hapd = hostapd.add_ap(apdev[0], params)
  638. bssid = hapd.own_addr()
  639. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  640. for i in range(10):
  641. dev[0].scan(freq="2412")
  642. bss = dev[0].get_bss(bssid)
  643. if 'beacon_ie' in bss:
  644. break
  645. time.sleep(0.2)
  646. if 'beacon_ie' not in bss:
  647. raise Exception("Did not find Beacon IEs")
  648. ie = parse_ie(bss['beacon_ie'])
  649. if 5 not in ie:
  650. raise Exception("TIM element missing")
  651. count, period = struct.unpack('BB', ie[5][0:2])
  652. logger.info("DTIM count %d DTIM period %d" % (count, period))
  653. if period != 10:
  654. raise Exception("Unexpected DTIM period: %d" % period)
  655. if count >= period:
  656. raise Exception("Unexpected DTIM count: %d" % count)
  657. def test_ap_no_probe_resp(dev, apdev):
  658. """AP with Probe Response frame sending from hostapd disabled"""
  659. ssid = "no-probe-resp"
  660. params = { 'ssid': ssid, 'send_probe_response': "0" }
  661. hapd = hostapd.add_ap(apdev[0], params)
  662. bssid = hapd.own_addr()
  663. dev[0].scan_for_bss(bssid, freq="2412", passive=True)
  664. dev[0].scan_for_bss(bssid, freq="2412", force_scan=True)
  665. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  666. bss = dev[0].get_bss(bssid)
  667. if 'ie' in bss and 'beacon_ie' in bss and \
  668. len(bss['ie']) != len(bss['beacon_ie']):
  669. raise Exception("Probe Response frames seen")
  670. def test_ap_long_preamble(dev, apdev):
  671. """AP with long preamble"""
  672. ssid = "long-preamble"
  673. params = { 'ssid': ssid, 'preamble': "0",
  674. 'hw_mode': 'b', 'ieee80211n': '0',
  675. 'supported_rates': '10', 'basic_rates': '10' }
  676. hapd = hostapd.add_ap(apdev[0], params)
  677. bssid = hapd.own_addr()
  678. dev[0].scan_for_bss(bssid, freq="2412")
  679. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  680. hwsim_utils.test_connectivity(dev[0], hapd)
  681. def test_ap_wmm_uapsd(dev, apdev):
  682. """AP with U-APSD advertisement"""
  683. ssid = "uapsd"
  684. params = { 'ssid': ssid, 'uapsd_advertisement_enabled': "1" }
  685. hapd = hostapd.add_ap(apdev[0], params)
  686. bssid = hapd.own_addr()
  687. dev[0].scan_for_bss(bssid, freq="2412")
  688. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  689. hwsim_utils.test_connectivity(dev[0], hapd)
  690. def test_ap_wowlan_triggers(dev, apdev):
  691. """AP with wowlan_triggers"""
  692. ssid = "wowlan"
  693. params = { 'ssid': ssid, 'wowlan_triggers': "any" }
  694. hapd = hostapd.add_ap(apdev[0], params)
  695. bssid = hapd.own_addr()
  696. dev[0].scan_for_bss(bssid, freq="2412")
  697. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  698. hwsim_utils.test_connectivity(dev[0], hapd)