test_ap_params.py 11 KB

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