test_ap_params.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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 hwsim_utils
  11. import hostapd
  12. from tshark import run_tshark
  13. from utils import alloc_fail
  14. @remote_compatible
  15. def test_ap_fragmentation_rts_set_high(dev, apdev):
  16. """WPA2-PSK AP with fragmentation and RTS thresholds larger than frame length"""
  17. ssid = "test-wpa2-psk"
  18. passphrase = 'qwertyuiop'
  19. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  20. params['rts_threshold'] = "1000"
  21. params['fragm_threshold'] = "2000"
  22. hapd = hostapd.add_ap(apdev[0], params)
  23. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  24. hwsim_utils.test_connectivity(dev[0], hapd)
  25. @remote_compatible
  26. def test_ap_fragmentation_open(dev, apdev):
  27. """Open AP with fragmentation threshold"""
  28. ssid = "fragmentation"
  29. params = {}
  30. params['ssid'] = ssid
  31. params['fragm_threshold'] = "1000"
  32. hapd = hostapd.add_ap(apdev[0], params)
  33. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  34. hwsim_utils.test_connectivity(dev[0], hapd)
  35. @remote_compatible
  36. def test_ap_fragmentation_wpa2(dev, apdev):
  37. """WPA2-PSK AP with fragmentation threshold"""
  38. ssid = "test-wpa2-psk"
  39. passphrase = 'qwertyuiop'
  40. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  41. params['fragm_threshold'] = "1000"
  42. hapd = hostapd.add_ap(apdev[0], params)
  43. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  44. hwsim_utils.test_connectivity(dev[0], hapd)
  45. def test_ap_vendor_elements(dev, apdev):
  46. """WPA2-PSK AP with vendor elements added"""
  47. bssid = apdev[0]['bssid']
  48. ssid = "test-wpa2-psk"
  49. passphrase = 'qwertyuiop'
  50. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  51. params['vendor_elements'] = "dd0411223301"
  52. params['assocresp_elements'] = "dd0411223302"
  53. hapd = hostapd.add_ap(apdev[0], params)
  54. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  55. bss = dev[0].get_bss(bssid)
  56. if "dd0411223301" not in bss['ie']:
  57. raise Exception("Vendor element not shown in scan results")
  58. hapd.set('vendor_elements', 'dd051122330203dd0400137400dd04001374ff')
  59. if "OK" not in hapd.request("UPDATE_BEACON"):
  60. raise Exception("UPDATE_BEACON failed")
  61. dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
  62. bss = dev[1].get_bss(bssid)
  63. if "dd0411223301" in bss['ie']:
  64. raise Exception("Old vendor element still in scan results")
  65. if "dd051122330203" not in bss['ie']:
  66. raise Exception("New vendor element not shown in scan results")
  67. def test_ap_element_parse(dev, apdev):
  68. """Information element parsing - extra coverage"""
  69. bssid = apdev[0]['bssid']
  70. ssid = "test-wpa2-psk"
  71. params = { 'ssid': ssid,
  72. 'vendor_elements': "380501020304059e009e009e009e009e009e00" }
  73. hapd = hostapd.add_ap(apdev[0], params)
  74. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  75. bss = dev[0].get_bss(bssid)
  76. if "38050102030405" not in bss['ie']:
  77. raise Exception("Timeout element not shown in scan results")
  78. @remote_compatible
  79. def test_ap_element_parse_oom(dev, apdev):
  80. """Information element parsing OOM"""
  81. bssid = apdev[0]['bssid']
  82. ssid = "test-wpa2-psk"
  83. params = { 'ssid': ssid,
  84. 'vendor_elements': "dd0d506f9a0a00000600411c440028" }
  85. hapd = hostapd.add_ap(apdev[0], params)
  86. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  87. with alloc_fail(dev[0], 1, "wpabuf_alloc;ieee802_11_vendor_ie_concat"):
  88. bss = dev[0].get_bss(bssid)
  89. logger.info(str(bss))
  90. def test_ap_country(dev, apdev):
  91. """WPA2-PSK AP setting country code and using 5 GHz band"""
  92. try:
  93. hapd = None
  94. bssid = apdev[0]['bssid']
  95. ssid = "test-wpa2-psk"
  96. passphrase = 'qwertyuiop'
  97. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  98. params['country_code'] = 'FI'
  99. params['ieee80211d'] = '1'
  100. params['hw_mode'] = 'a'
  101. params['channel'] = '36'
  102. hapd = hostapd.add_ap(apdev[0], params)
  103. dev[0].connect(ssid, psk=passphrase, scan_freq="5180")
  104. hwsim_utils.test_connectivity(dev[0], hapd)
  105. finally:
  106. dev[0].request("DISCONNECT")
  107. if hapd:
  108. hapd.request("DISABLE")
  109. hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
  110. dev[0].flush_scan_cache()
  111. def test_ap_acl_accept(dev, apdev):
  112. """MAC ACL accept list"""
  113. ssid = "acl"
  114. params = {}
  115. params['ssid'] = ssid
  116. params['accept_mac_file'] = "hostapd.macaddr"
  117. hapd = hostapd.add_ap(apdev[0], params)
  118. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  119. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  120. dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
  121. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  122. dev[0].request("REMOVE_NETWORK all")
  123. dev[1].request("REMOVE_NETWORK all")
  124. hapd.request("SET macaddr_acl 1")
  125. dev[1].dump_monitor()
  126. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  127. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  128. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  129. if ev is not None:
  130. raise Exception("Unexpected association")
  131. def test_ap_acl_deny(dev, apdev):
  132. """MAC ACL deny list"""
  133. ssid = "acl"
  134. params = {}
  135. params['ssid'] = ssid
  136. params['deny_mac_file'] = "hostapd.macaddr"
  137. hapd = hostapd.add_ap(apdev[0], params)
  138. dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
  139. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  140. dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
  141. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  142. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  143. if ev is not None:
  144. raise Exception("Unexpected association")
  145. @remote_compatible
  146. def test_ap_wds_sta(dev, apdev):
  147. """WPA2-PSK AP with STA using 4addr mode"""
  148. ssid = "test-wpa2-psk"
  149. passphrase = 'qwertyuiop'
  150. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  151. params['wds_sta'] = "1"
  152. params['wds_bridge'] = "wds-br0"
  153. hapd = hostapd.add_ap(apdev[0], params)
  154. try:
  155. dev[0].cmd_execute(['brctl', 'addbr', 'wds-br0'])
  156. dev[0].cmd_execute(['brctl', 'setfd', 'wds-br0', '0'])
  157. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'up'])
  158. dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'on'])
  159. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  160. hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
  161. max_tries=15)
  162. finally:
  163. dev[0].cmd_execute(['iw', dev[0].ifname, 'set', '4addr', 'off'])
  164. dev[0].cmd_execute(['ip', 'link', 'set', 'dev', 'wds-br0', 'down'])
  165. dev[0].cmd_execute(['brctl', 'delbr', 'wds-br0'])
  166. @remote_compatible
  167. def test_ap_inactivity_poll(dev, apdev):
  168. """AP using inactivity poll"""
  169. ssid = "test-wpa2-psk"
  170. passphrase = 'qwertyuiop'
  171. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  172. params['ap_max_inactivity'] = "1"
  173. hapd = hostapd.add_ap(apdev[0], params)
  174. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  175. hapd.set("ext_mgmt_frame_handling", "1")
  176. dev[0].request("DISCONNECT")
  177. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  178. if ev is None:
  179. raise Exception("MGMT RX wait timed out for Deauth")
  180. hapd.set("ext_mgmt_frame_handling", "0")
  181. ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=30)
  182. if ev is None:
  183. raise Exception("STA disconnection on inactivity was not reported")
  184. @remote_compatible
  185. def test_ap_inactivity_disconnect(dev, apdev):
  186. """AP using inactivity disconnect"""
  187. ssid = "test-wpa2-psk"
  188. passphrase = 'qwertyuiop'
  189. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  190. params['ap_max_inactivity'] = "1"
  191. params['skip_inactivity_poll'] = "1"
  192. hapd = hostapd.add_ap(apdev[0], params)
  193. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  194. hapd.set("ext_mgmt_frame_handling", "1")
  195. dev[0].request("DISCONNECT")
  196. ev = hapd.wait_event(["MGMT-RX"], timeout=5)
  197. if ev is None:
  198. raise Exception("MGMT RX wait timed out for Deauth")
  199. hapd.set("ext_mgmt_frame_handling", "0")
  200. ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=30)
  201. if ev is None:
  202. raise Exception("STA disconnection on inactivity was not reported")
  203. @remote_compatible
  204. def test_ap_basic_rates(dev, apdev):
  205. """Open AP with lots of basic rates"""
  206. ssid = "basic rates"
  207. params = {}
  208. params['ssid'] = ssid
  209. params['basic_rates'] = "10 20 55 110 60 90 120 180 240 360 480 540"
  210. hostapd.add_ap(apdev[0], params)
  211. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  212. @remote_compatible
  213. def test_ap_short_preamble(dev, apdev):
  214. """Open AP with short preamble"""
  215. ssid = "short preamble"
  216. params = {}
  217. params['ssid'] = ssid
  218. params['preamble'] = "1"
  219. hostapd.add_ap(apdev[0], params)
  220. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  221. def test_ap_spectrum_management_required(dev, apdev):
  222. """Open AP with spectrum management required"""
  223. ssid = "spectrum mgmt"
  224. params = {}
  225. params['ssid'] = ssid
  226. params["country_code"] = "JP"
  227. params["hw_mode"] = "a"
  228. params["channel"] = "36"
  229. params["ieee80211d"] = "1"
  230. params["local_pwr_constraint"] = "3"
  231. params['spectrum_mgmt_required'] = "1"
  232. try:
  233. hapd = None
  234. hapd = hostapd.add_ap(apdev[0], params)
  235. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="5180")
  236. finally:
  237. dev[0].request("DISCONNECT")
  238. if hapd:
  239. hapd.request("DISABLE")
  240. hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
  241. dev[0].flush_scan_cache()
  242. @remote_compatible
  243. def test_ap_max_listen_interval(dev, apdev):
  244. """Open AP with maximum listen interval limit"""
  245. ssid = "listen"
  246. params = {}
  247. params['ssid'] = ssid
  248. params['max_listen_interval'] = "1"
  249. hostapd.add_ap(apdev[0], params)
  250. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  251. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  252. if ev is None:
  253. raise Exception("Association rejection not reported")
  254. if "status_code=51" not in ev:
  255. raise Exception("Unexpected ASSOC-REJECT reason")
  256. @remote_compatible
  257. def test_ap_max_num_sta(dev, apdev):
  258. """Open AP with maximum STA count"""
  259. ssid = "max"
  260. params = {}
  261. params['ssid'] = ssid
  262. params['max_num_sta'] = "1"
  263. hostapd.add_ap(apdev[0], params)
  264. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  265. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
  266. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  267. if ev is not None:
  268. raise Exception("Unexpected association")
  269. def test_ap_max_num_sta_no_probe_resp(dev, apdev, params):
  270. """Maximum STA count and limit on Probe Response frames"""
  271. logdir = params['logdir']
  272. dev[0].flush_scan_cache()
  273. ssid = "max"
  274. params = {}
  275. params['ssid'] = ssid
  276. params['beacon_int'] = "2000"
  277. params['max_num_sta'] = "1"
  278. params['no_probe_resp_if_max_sta'] = "1"
  279. hostapd.add_ap(apdev[0], params)
  280. dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  281. dev[0].scan(freq=2412, type="ONLY")
  282. dev[0].scan(freq=2412, type="ONLY")
  283. seen = dev[0].get_bss(apdev[0]['bssid']) != None
  284. dev[1].scan(freq=2412, type="ONLY")
  285. if seen:
  286. out = run_tshark(os.path.join(logdir, "hwsim0.pcapng"),
  287. "wlan.fc.type_subtype == 5", ["wlan.da" ])
  288. if out:
  289. if dev[0].own_addr() not in out:
  290. # Discovery happened through Beacon frame reception. That's not
  291. # an error case.
  292. seen = False
  293. if dev[1].own_addr() not in out:
  294. raise Exception("No Probe Response frames to dev[1] seen")
  295. if seen:
  296. raise Exception("AP found unexpectedly")
  297. @remote_compatible
  298. def test_ap_tx_queue_params(dev, apdev):
  299. """Open AP with TX queue params set"""
  300. ssid = "tx"
  301. params = {}
  302. params['ssid'] = ssid
  303. params['tx_queue_data2_aifs'] = "4"
  304. params['tx_queue_data2_cwmin'] = "7"
  305. params['tx_queue_data2_cwmax'] = "1023"
  306. params['tx_queue_data2_burst'] = "4.2"
  307. params['tx_queue_data1_aifs'] = "4"
  308. params['tx_queue_data1_cwmin'] = "7"
  309. params['tx_queue_data1_cwmax'] = "1023"
  310. params['tx_queue_data1_burst'] = "2"
  311. hapd = hostapd.add_ap(apdev[0], params)
  312. dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
  313. hwsim_utils.test_connectivity(dev[0], hapd)