1 # Test various AP mode parameters
2 # Copyright (c) 2014, Qualcomm Atheros, Inc.
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
8 logger = logging.getLogger()
14 def test_ap_fragmentation_rts_set_high(dev, apdev):
15 """WPA2-PSK AP with fragmentation and RTS thresholds larger than frame length"""
16 ssid = "test-wpa2-psk"
17 passphrase = 'qwertyuiop'
18 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
19 params['rts_threshold'] = "1000"
20 params['fragm_threshold'] = "2000"
21 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
22 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
23 hwsim_utils.test_connectivity(dev[0], hapd)
25 def test_ap_fragmentation_open(dev, apdev):
26 """Open AP with fragmentation threshold"""
27 ssid = "fragmentation"
30 params['fragm_threshold'] = "1000"
31 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
32 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
33 hwsim_utils.test_connectivity(dev[0], hapd)
35 def test_ap_fragmentation_wpa2(dev, apdev):
36 """WPA2-PSK AP with fragmentation threshold"""
37 ssid = "test-wpa2-psk"
38 passphrase = 'qwertyuiop'
39 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
40 params['fragm_threshold'] = "1000"
41 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
42 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
43 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 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
53 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
54 bss = dev[0].get_bss(bssid)
55 if "dd0411223301" not in bss['ie']:
56 raise Exception("Vendor element not shown in scan results")
58 hapd.set('vendor_elements', 'dd051122330203')
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")
68 def test_ap_country(dev, apdev):
69 """WPA2-PSK AP setting country code and using 5 GHz band"""
72 bssid = apdev[0]['bssid']
73 ssid = "test-wpa2-psk"
74 passphrase = 'qwertyuiop'
75 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
76 params['country_code'] = 'FI'
77 params['ieee80211d'] = '1'
78 params['hw_mode'] = 'a'
79 params['channel'] = '36'
80 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
81 dev[0].connect(ssid, psk=passphrase, scan_freq="5180")
82 hwsim_utils.test_connectivity(dev[0], hapd)
84 dev[0].request("DISCONNECT")
86 hapd.request("DISABLE")
87 subprocess.call(['iw', 'reg', 'set', '00'])
88 dev[0].flush_scan_cache()
90 def test_ap_acl_accept(dev, apdev):
91 """MAC ACL accept list"""
95 params['accept_mac_file'] = "hostapd.macaddr"
96 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
97 dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
98 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
99 dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
100 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
101 dev[0].request("REMOVE_NETWORK all")
102 dev[1].request("REMOVE_NETWORK all")
103 hapd.request("SET macaddr_acl 1")
104 dev[1].dump_monitor()
105 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
106 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
107 ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
109 raise Exception("Unexpected association")
111 def test_ap_acl_deny(dev, apdev):
112 """MAC ACL deny list"""
115 params['ssid'] = ssid
116 params['deny_mac_file'] = "hostapd.macaddr"
117 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
118 dev[0].scan_for_bss(apdev[0]['bssid'], freq="2412")
119 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
120 dev[1].scan_for_bss(apdev[0]['bssid'], freq="2412")
121 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
122 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
124 raise Exception("Unexpected association")
126 def test_ap_wds_sta(dev, apdev):
127 """WPA2-PSK AP with STA using 4addr mode"""
128 ssid = "test-wpa2-psk"
129 passphrase = 'qwertyuiop'
130 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
131 params['wds_sta'] = "1"
132 params['wds_bridge'] = "wds-br0"
133 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
136 subprocess.call(['brctl', 'addbr', 'wds-br0'])
137 subprocess.call(['brctl', 'setfd', 'wds-br0', '0'])
138 subprocess.call(['ip', 'link', 'set', 'dev', 'wds-br0', 'up'])
139 subprocess.call(['iw', dev[0].ifname, 'set', '4addr', 'on'])
140 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
141 hwsim_utils.test_connectivity_iface(dev[0], hapd, "wds-br0",
144 subprocess.call(['iw', dev[0].ifname, 'set', '4addr', 'off'])
145 subprocess.call(['ip', 'link', 'set', 'dev', 'wds-br0', 'down'])
146 subprocess.call(['brctl', 'delbr', 'wds-br0'])
148 def test_ap_inactivity_poll(dev, apdev):
149 """AP using inactivity poll"""
150 ssid = "test-wpa2-psk"
151 passphrase = 'qwertyuiop'
152 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
153 params['ap_max_inactivity'] = "1"
154 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
155 dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
156 hapd.set("ext_mgmt_frame_handling", "1")
157 dev[0].request("DISCONNECT")
158 ev = hapd.wait_event(["MGMT-RX"], timeout=5)
160 raise Exception("MGMT RX wait timed out for Deauth")
161 hapd.set("ext_mgmt_frame_handling", "0")
162 ev = hapd.wait_event(["AP-STA-DISCONNECTED"], timeout=30)
164 raise Exception("STA disconnection on inactivity was not reported")
166 def test_ap_inactivity_disconnect(dev, apdev):
167 """AP using inactivity disconnect"""
168 ssid = "test-wpa2-psk"
169 passphrase = 'qwertyuiop'
170 params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
171 params['ap_max_inactivity'] = "1"
172 params['skip_inactivity_poll'] = "1"
173 hapd = hostapd.add_ap(apdev[0]['ifname'], 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)
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)
183 raise Exception("STA disconnection on inactivity was not reported")
185 def test_ap_basic_rates(dev, apdev):
186 """Open AP with lots of basic rates"""
189 params['ssid'] = ssid
190 params['basic_rates'] = "10 20 55 110 60 90 120 180 240 360 480 540"
191 hostapd.add_ap(apdev[0]['ifname'], params)
192 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
194 def test_ap_short_preamble(dev, apdev):
195 """Open AP with short preamble"""
196 ssid = "short preamble"
198 params['ssid'] = ssid
199 params['preamble'] = "1"
200 hostapd.add_ap(apdev[0]['ifname'], params)
201 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
203 def test_ap_spectrum_management_required(dev, apdev):
204 """Open AP with spectrum management required"""
205 ssid = "spectrum mgmt"
207 params['ssid'] = ssid
208 params["country_code"] = "JP"
209 params["hw_mode"] = "a"
210 params["channel"] = "36"
211 params["ieee80211d"] = "1"
212 params["local_pwr_constraint"] = "3"
213 params['spectrum_mgmt_required'] = "1"
216 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
217 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="5180")
219 dev[0].request("DISCONNECT")
221 hapd.request("DISABLE")
222 subprocess.call(['iw', 'reg', 'set', '00'])
223 dev[0].flush_scan_cache()
225 def test_ap_max_listen_interval(dev, apdev):
226 """Open AP with maximum listen interval limit"""
229 params['ssid'] = ssid
230 params['max_listen_interval'] = "1"
231 hostapd.add_ap(apdev[0]['ifname'], params)
232 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
233 ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
235 raise Exception("Association rejection not reported")
236 if "status_code=51" not in ev:
237 raise Exception("Unexpected ASSOC-REJECT reason")
239 def test_ap_max_num_sta(dev, apdev):
240 """Open AP with maximum STA count"""
243 params['ssid'] = ssid
244 params['max_num_sta'] = "1"
245 hostapd.add_ap(apdev[0]['ifname'], params)
246 dev[1].connect(ssid, key_mgmt="NONE", scan_freq="2412")
247 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412", wait_connect=False)
248 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
250 raise Exception("Unexpected association")
252 def test_ap_tx_queue_params(dev, apdev):
253 """Open AP with TX queue params set"""
256 params['ssid'] = ssid
257 params['tx_queue_data2_aifs'] = "4"
258 params['tx_queue_data2_cwmin'] = "7"
259 params['tx_queue_data2_cwmax'] = "1023"
260 params['tx_queue_data2_burst'] = "4.2"
261 params['tx_queue_data1_aifs'] = "4"
262 params['tx_queue_data1_cwmin'] = "7"
263 params['tx_queue_data1_cwmax'] = "1023"
264 params['tx_queue_data1_burst'] = "2"
265 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
266 dev[0].connect(ssid, key_mgmt="NONE", scan_freq="2412")
267 hwsim_utils.test_connectivity(dev[0], hapd)