blob: 89380867e48fb92f048545b0c53df23feb97c92f [file] [log] [blame]
Mark De Ruyter1a7ae572018-03-02 15:35:36 -08001#!/usr/bin/env python3
Joe Brennan8c24a812017-04-13 14:27:05 -07002#
3# Copyright 2017 - Google
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Bindu Mahadev2ebdcec2018-05-03 19:51:24 +000016"""
17 Base Class for Defining Common WiFi Test Functionality
18"""
Joe Brennan8c24a812017-04-13 14:27:05 -070019
Bindu Mahadev1f227e02017-07-06 00:24:58 +000020import copy
21import itertools
Hsiu-Chang Chen5579e1a2020-10-21 10:40:12 +080022import os
Bindu Mahadev2ebdcec2018-05-03 19:51:24 +000023import time
24
25import acts.controllers.access_point as ap
Bindu Mahadevedf17162017-07-07 03:46:55 +000026
Joe Brennan8c24a812017-04-13 14:27:05 -070027from acts import asserts
Girish Moturue6ccc7a2019-09-19 11:00:21 -070028from acts import signals
Joe Brennan8c24a812017-04-13 14:27:05 -070029from acts import utils
30from acts.base_test import BaseTestClass
Bindu Mahadev2ebdcec2018-05-03 19:51:24 +000031from acts.signals import TestSignal
32from acts.controllers import android_device
Girish Moturu27ff0b32019-08-03 21:44:59 -070033from acts.controllers.access_point import AccessPoint
Joe Brennan8c24a812017-04-13 14:27:05 -070034from acts.controllers.ap_lib import hostapd_ap_preset
35from acts.controllers.ap_lib import hostapd_bss_settings
36from acts.controllers.ap_lib import hostapd_constants
37from acts.controllers.ap_lib import hostapd_security
Hsiu-Chang Chen5579e1a2020-10-21 10:40:12 +080038from acts.keys import Config
39from acts_contrib.test_utils.net import net_test_utils as nutils
40from acts_contrib.test_utils.wifi import wifi_test_utils as wutils
Joe Brennan8c24a812017-04-13 14:27:05 -070041
Bindu Mahadeve7d47c32018-07-03 16:48:03 -070042AP_1 = 0
43AP_2 = 1
44MAX_AP_COUNT = 2
Joe Brennan8c24a812017-04-13 14:27:05 -070045
Nate Jiang8bbc94f2019-06-11 19:13:51 -070046
Joe Brennan8c24a812017-04-13 14:27:05 -070047class WifiBaseTest(BaseTestClass):
Hsiu-Chang Chen5579e1a2020-10-21 10:40:12 +080048 def __init__(self, configs):
49 super().__init__(configs)
50 self.enable_packet_log = False
51 self.packet_log_2g = hostapd_constants.AP_DEFAULT_CHANNEL_2G
52 self.packet_log_5g = hostapd_constants.AP_DEFAULT_CHANNEL_5G
53
Xianyuan Jia168103b2019-09-06 12:22:52 -070054 def setup_class(self):
Bindu Mahadevd3eaf5d2018-05-08 15:32:26 -070055 if hasattr(self, 'attenuators') and self.attenuators:
Bindu Mahadev3bb29fa2017-08-10 16:08:20 +000056 for attenuator in self.attenuators:
57 attenuator.set_atten(0)
Hsiu-Chang Chen5579e1a2020-10-21 10:40:12 +080058 opt_param = ["pixel_models", "cnss_diag_file"]
59 self.unpack_userparams(opt_param_names=opt_param)
60 if hasattr(self, "cnss_diag_file"):
61 if isinstance(self.cnss_diag_file, list):
62 self.cnss_diag_file = self.cnss_diag_file[0]
63 if not os.path.isfile(self.cnss_diag_file):
64 self.cnss_diag_file = os.path.join(
65 self.user_params[Config.key_config_path.value],
66 self.cnss_diag_file)
67 if self.enable_packet_log and hasattr(self, "packet_capture"):
68 self.packet_logger = self.packet_capture[0]
69 self.packet_logger.configure_monitor_mode("2G", self.packet_log_2g)
70 self.packet_logger.configure_monitor_mode("5G", self.packet_log_5g)
71
72 def setup_test(self):
tturneyfd697932020-11-24 11:43:44 -080073 if (hasattr(self, "android_devices")
74 and hasattr(self, "cnss_diag_file")
75 and hasattr(self, "pixel_models")):
76 wutils.start_cnss_diags(self.android_devices, self.cnss_diag_file,
77 self.pixel_models)
Hsiu-Chang Chen5579e1a2020-10-21 10:40:12 +080078 self.tcpdump_proc = []
79 if hasattr(self, "android_devices"):
80 for ad in self.android_devices:
81 proc = nutils.start_tcpdump(ad, self.test_name)
82 self.tcpdump_proc.append((ad, proc))
83 if hasattr(self, "packet_logger"):
tturneyfd697932020-11-24 11:43:44 -080084 self.packet_log_pid = wutils.start_pcap(self.packet_logger, 'dual',
85 self.test_name)
Hsiu-Chang Chen5579e1a2020-10-21 10:40:12 +080086
87 def teardown_test(self):
tturneyfd697932020-11-24 11:43:44 -080088 if (hasattr(self, "android_devices")
89 and hasattr(self, "cnss_diag_file")
90 and hasattr(self, "pixel_models")):
Hsiu-Chang Chen5579e1a2020-10-21 10:40:12 +080091 wutils.stop_cnss_diags(self.android_devices, self.pixel_models)
tturneyfd697932020-11-24 11:43:44 -080092 for proc in self.tcpdump_proc:
93 nutils.stop_tcpdump(proc[0],
94 proc[1],
95 self.test_name,
96 pull_dump=False)
97 self.tcpdump_proc = []
Hsiu-Chang Chen5579e1a2020-10-21 10:40:12 +080098 if hasattr(self, "packet_logger") and self.packet_log_pid:
tturneyfd697932020-11-24 11:43:44 -080099 wutils.stop_pcap(self.packet_logger,
100 self.packet_log_pid,
101 test_status=True)
Hsiu-Chang Chen5579e1a2020-10-21 10:40:12 +0800102 self.packet_log_pid = {}
103
104 def on_fail(self, test_name, begin_time):
105 if hasattr(self, "android_devices"):
106 for ad in self.android_devices:
107 ad.take_bug_report(test_name, begin_time)
108 ad.cat_adb_log(test_name, begin_time)
109 wutils.get_ssrdumps(ad)
tturneyfd697932020-11-24 11:43:44 -0800110 if (hasattr(self, "cnss_diag_file")
111 and hasattr(self, "pixel_models")):
Hsiu-Chang Chen5579e1a2020-10-21 10:40:12 +0800112 wutils.stop_cnss_diags(self.android_devices, self.pixel_models)
113 for ad in self.android_devices:
114 wutils.get_cnss_diag_log(ad)
tturneyfd697932020-11-24 11:43:44 -0800115 for proc in self.tcpdump_proc:
116 nutils.stop_tcpdump(proc[0], proc[1], self.test_name)
117 self.tcpdump_proc = []
Hsiu-Chang Chen5579e1a2020-10-21 10:40:12 +0800118 if hasattr(self, "packet_logger") and self.packet_log_pid:
tturneyfd697932020-11-24 11:43:44 -0800119 wutils.stop_pcap(self.packet_logger,
120 self.packet_log_pid,
121 test_status=False)
Hsiu-Chang Chen5579e1a2020-10-21 10:40:12 +0800122 self.packet_log_pid = {}
Joe Brennan8c24a812017-04-13 14:27:05 -0700123
Hsiu-Chang Chen81061752018-08-15 13:49:23 +0800124 def get_psk_network(
Bindu Mahadev72725d12017-06-05 03:11:30 +0000125 self,
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700126 mirror_ap,
127 reference_networks,
Bindu Mahadev1c895c22018-01-18 18:20:43 -0800128 hidden=False,
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700129 same_ssid=False,
Hsiu-Chang Chen81061752018-08-15 13:49:23 +0800130 security_mode=hostapd_constants.WPA2_STRING,
Bindu Mahadev72725d12017-06-05 03:11:30 +0000131 ssid_length_2g=hostapd_constants.AP_SSID_LENGTH_2G,
132 ssid_length_5g=hostapd_constants.AP_SSID_LENGTH_5G,
133 passphrase_length_2g=hostapd_constants.AP_PASSPHRASE_LENGTH_2G,
134 passphrase_length_5g=hostapd_constants.AP_PASSPHRASE_LENGTH_5G):
Bindu Mahadev72725d12017-06-05 03:11:30 +0000135 """Generates SSID and passphrase for a WPA2 network using random
136 generator.
137
138 Args:
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700139 mirror_ap: Boolean, determines if both APs use the same hostapd
140 config or different configs.
141 reference_networks: List of PSK networks.
142 same_ssid: Boolean, determines if both bands on AP use the same
143 SSID.
144 ssid_length_2gecond AP Int, number of characters to use for 2G SSID.
Bindu Mahadev72725d12017-06-05 03:11:30 +0000145 ssid_length_5g: Int, number of characters to use for 5G SSID.
146 passphrase_length_2g: Int, length of password for 2G network.
147 passphrase_length_5g: Int, length of password for 5G network.
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700148
Bindu Mahadev72725d12017-06-05 03:11:30 +0000149 Returns: A dict of 2G and 5G network lists for hostapd configuration.
150
151 """
152 network_dict_2g = {}
153 network_dict_5g = {}
Hsiu-Chang Chen81061752018-08-15 13:49:23 +0800154 ref_5g_security = security_mode
155 ref_2g_security = security_mode
Bindu Mahadev72725d12017-06-05 03:11:30 +0000156
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700157 if same_ssid:
158 ref_2g_ssid = 'xg_%s' % utils.rand_ascii_str(ssid_length_2g)
159 ref_5g_ssid = ref_2g_ssid
Bindu Mahadev72725d12017-06-05 03:11:30 +0000160
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700161 ref_2g_passphrase = utils.rand_ascii_str(passphrase_length_2g)
162 ref_5g_passphrase = ref_2g_passphrase
163
164 else:
165 ref_2g_ssid = '2g_%s' % utils.rand_ascii_str(ssid_length_2g)
166 ref_2g_passphrase = utils.rand_ascii_str(passphrase_length_2g)
167
168 ref_5g_ssid = '5g_%s' % utils.rand_ascii_str(ssid_length_5g)
169 ref_5g_passphrase = utils.rand_ascii_str(passphrase_length_5g)
Bindu Mahadev72725d12017-06-05 03:11:30 +0000170
Hsiu-Chang Chen8d8bbbf2018-08-02 11:37:11 +0800171 network_dict_2g = {
172 "SSID": ref_2g_ssid,
173 "security": ref_2g_security,
174 "password": ref_2g_passphrase,
175 "hiddenSSID": hidden
176 }
Bindu Mahadev72725d12017-06-05 03:11:30 +0000177
Hsiu-Chang Chen8d8bbbf2018-08-02 11:37:11 +0800178 network_dict_5g = {
179 "SSID": ref_5g_ssid,
180 "security": ref_5g_security,
181 "password": ref_5g_passphrase,
182 "hiddenSSID": hidden
183 }
Bindu Mahadev1c895c22018-01-18 18:20:43 -0800184
Bindu Mahadevd07198d2017-09-15 14:06:54 -0700185 ap = 0
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700186 for ap in range(MAX_AP_COUNT):
187 reference_networks.append({
188 "2g": copy.copy(network_dict_2g),
189 "5g": copy.copy(network_dict_5g)
Bindu Mahadev72725d12017-06-05 03:11:30 +0000190 })
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700191 if not mirror_ap:
192 break
Bindu Mahadev72725d12017-06-05 03:11:30 +0000193 return {"2g": network_dict_2g, "5g": network_dict_5g}
194
markdr56939012017-07-26 12:48:43 -0700195 def get_open_network(self,
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700196 mirror_ap,
197 open_network,
Bindu Mahadev1c895c22018-01-18 18:20:43 -0800198 hidden=False,
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700199 same_ssid=False,
markdr56939012017-07-26 12:48:43 -0700200 ssid_length_2g=hostapd_constants.AP_SSID_LENGTH_2G,
Girish Moturu4bf0b932020-09-25 11:17:22 -0700201 ssid_length_5g=hostapd_constants.AP_SSID_LENGTH_5G,
202 security_mode='none'):
Bindu Mahadev72725d12017-06-05 03:11:30 +0000203 """Generates SSIDs for a open network using a random generator.
204
205 Args:
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700206 mirror_ap: Boolean, determines if both APs use the same hostapd
207 config or different configs.
208 open_network: List of open networks.
209 same_ssid: Boolean, determines if both bands on AP use the same
210 SSID.
Bindu Mahadev72725d12017-06-05 03:11:30 +0000211 ssid_length_2g: Int, number of characters to use for 2G SSID.
212 ssid_length_5g: Int, number of characters to use for 5G SSID.
Girish Moturu4bf0b932020-09-25 11:17:22 -0700213 security_mode: 'none' for open and 'OWE' for WPA3 OWE.
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700214
Bindu Mahadev72725d12017-06-05 03:11:30 +0000215 Returns: A dict of 2G and 5G network lists for hostapd configuration.
216
217 """
218 network_dict_2g = {}
219 network_dict_5g = {}
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700220
221 if same_ssid:
222 open_2g_ssid = 'xg_%s' % utils.rand_ascii_str(ssid_length_2g)
223 open_5g_ssid = open_2g_ssid
224
225 else:
226 open_2g_ssid = '2g_%s' % utils.rand_ascii_str(ssid_length_2g)
227 open_5g_ssid = '5g_%s' % utils.rand_ascii_str(ssid_length_5g)
228
Hsiu-Chang Chen8d8bbbf2018-08-02 11:37:11 +0800229 network_dict_2g = {
Bindu Mahadev2ebdcec2018-05-03 19:51:24 +0000230 "SSID": open_2g_ssid,
Girish Moturu4bf0b932020-09-25 11:17:22 -0700231 "security": security_mode,
Hsiu-Chang Chen8d8bbbf2018-08-02 11:37:11 +0800232 "hiddenSSID": hidden
233 }
Bindu Mahadev1c895c22018-01-18 18:20:43 -0800234
Hsiu-Chang Chen8d8bbbf2018-08-02 11:37:11 +0800235 network_dict_5g = {
Bindu Mahadev2ebdcec2018-05-03 19:51:24 +0000236 "SSID": open_5g_ssid,
Girish Moturu4bf0b932020-09-25 11:17:22 -0700237 "security": security_mode,
Hsiu-Chang Chen8d8bbbf2018-08-02 11:37:11 +0800238 "hiddenSSID": hidden
239 }
Bindu Mahadev1c895c22018-01-18 18:20:43 -0800240
Bindu Mahadevd07198d2017-09-15 14:06:54 -0700241 ap = 0
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700242 for ap in range(MAX_AP_COUNT):
243 open_network.append({
244 "2g": copy.copy(network_dict_2g),
245 "5g": copy.copy(network_dict_5g)
Bindu Mahadev72725d12017-06-05 03:11:30 +0000246 })
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700247 if not mirror_ap:
248 break
Bindu Mahadev72725d12017-06-05 03:11:30 +0000249 return {"2g": network_dict_2g, "5g": network_dict_5g}
250
Hsiu-Chang Chen81061752018-08-15 13:49:23 +0800251 def get_wep_network(
252 self,
253 mirror_ap,
254 networks,
255 hidden=False,
256 same_ssid=False,
257 ssid_length_2g=hostapd_constants.AP_SSID_LENGTH_2G,
258 ssid_length_5g=hostapd_constants.AP_SSID_LENGTH_5G,
259 passphrase_length_2g=hostapd_constants.AP_PASSPHRASE_LENGTH_2G,
260 passphrase_length_5g=hostapd_constants.AP_PASSPHRASE_LENGTH_5G):
261 """Generates SSID and passphrase for a WEP network using random
262 generator.
263
264 Args:
265 mirror_ap: Boolean, determines if both APs use the same hostapd
266 config or different configs.
267 networks: List of WEP networks.
268 same_ssid: Boolean, determines if both bands on AP use the same
269 SSID.
270 ssid_length_2gecond AP Int, number of characters to use for 2G SSID.
271 ssid_length_5g: Int, number of characters to use for 5G SSID.
272 passphrase_length_2g: Int, length of password for 2G network.
273 passphrase_length_5g: Int, length of password for 5G network.
274
275 Returns: A dict of 2G and 5G network lists for hostapd configuration.
276
277 """
278 network_dict_2g = {}
279 network_dict_5g = {}
280 ref_5g_security = hostapd_constants.WEP_STRING
281 ref_2g_security = hostapd_constants.WEP_STRING
282
283 if same_ssid:
284 ref_2g_ssid = 'xg_%s' % utils.rand_ascii_str(ssid_length_2g)
285 ref_5g_ssid = ref_2g_ssid
286
287 ref_2g_passphrase = utils.rand_hex_str(passphrase_length_2g)
288 ref_5g_passphrase = ref_2g_passphrase
289
290 else:
291 ref_2g_ssid = '2g_%s' % utils.rand_ascii_str(ssid_length_2g)
292 ref_2g_passphrase = utils.rand_hex_str(passphrase_length_2g)
293
294 ref_5g_ssid = '5g_%s' % utils.rand_ascii_str(ssid_length_5g)
295 ref_5g_passphrase = utils.rand_hex_str(passphrase_length_5g)
296
297 network_dict_2g = {
298 "SSID": ref_2g_ssid,
299 "security": ref_2g_security,
300 "wepKeys": [ref_2g_passphrase] * 4,
301 "hiddenSSID": hidden
302 }
303
304 network_dict_5g = {
305 "SSID": ref_5g_ssid,
306 "security": ref_5g_security,
307 "wepKeys": [ref_2g_passphrase] * 4,
308 "hiddenSSID": hidden
309 }
310
311 ap = 0
312 for ap in range(MAX_AP_COUNT):
313 networks.append({
314 "2g": copy.copy(network_dict_2g),
315 "5g": copy.copy(network_dict_5g)
316 })
317 if not mirror_ap:
318 break
319 return {"2g": network_dict_2g, "5g": network_dict_5g}
320
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700321 def update_bssid(self, ap_instance, ap, network, band):
322 """Get bssid and update network dictionary.
323
324 Args:
325 ap_instance: Accesspoint index that was configured.
326 ap: Accesspoint object corresponding to ap_instance.
327 network: Network dictionary.
328 band: Wifi networks' band.
329
330 """
331 bssid = ap.get_bssid_from_ssid(network["SSID"], band)
332
333 if network["security"] == hostapd_constants.WPA2_STRING:
334 # TODO:(bamahadev) Change all occurances of reference_networks
335 # to wpa_networks.
336 self.reference_networks[ap_instance][band]["bssid"] = bssid
Hsiu-Chang Chen81061752018-08-15 13:49:23 +0800337 if network["security"] == hostapd_constants.WPA_STRING:
338 self.wpa_networks[ap_instance][band]["bssid"] = bssid
339 if network["security"] == hostapd_constants.WEP_STRING:
340 self.wep_networks[ap_instance][band]["bssid"] = bssid
Girish Moturudcd73f62018-10-18 09:49:32 -0700341 if network["security"] == hostapd_constants.ENT_STRING:
Girish Moturuf1ce4202018-10-20 21:33:00 -0700342 if "bssid" not in self.ent_networks[ap_instance][band]:
343 self.ent_networks[ap_instance][band]["bssid"] = bssid
344 else:
345 self.ent_networks_pwd[ap_instance][band]["bssid"] = bssid
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700346 if network["security"] == 'none':
347 self.open_network[ap_instance][band]["bssid"] = bssid
348
Bindu Mahadev2ebdcec2018-05-03 19:51:24 +0000349 def populate_bssid(self, ap_instance, ap, networks_5g, networks_2g):
Bindu Mahadev1f227e02017-07-06 00:24:58 +0000350 """Get bssid for a given SSID and add it to the network dictionary.
351
352 Args:
Bindu Mahadevd07198d2017-09-15 14:06:54 -0700353 ap_instance: Accesspoint index that was configured.
354 ap: Accesspoint object corresponding to ap_instance.
Mark De Ruyterdee24c22018-04-13 17:34:44 -0700355 networks_5g: List of 5g networks configured on the APs.
Bindu Mahadev2ebdcec2018-05-03 19:51:24 +0000356 networks_2g: List of 2g networks configured on the APs.
Bindu Mahadev1f227e02017-07-06 00:24:58 +0000357
358 """
359
Bindu Mahadev2ebdcec2018-05-03 19:51:24 +0000360 if not (networks_5g or networks_2g):
Bindu Mahadev1f227e02017-07-06 00:24:58 +0000361 return
362
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700363 for network in networks_5g:
Bindu Mahadev1f227e02017-07-06 00:24:58 +0000364 if 'channel' in network:
365 continue
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700366 self.update_bssid(ap_instance, ap, network,
tturneyfd697932020-11-24 11:43:44 -0800367 hostapd_constants.BAND_5G)
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700368
369 for network in networks_2g:
370 if 'channel' in network:
371 continue
372 self.update_bssid(ap_instance, ap, network,
tturneyfd697932020-11-24 11:43:44 -0800373 hostapd_constants.BAND_2G)
Bindu Mahadev1f227e02017-07-06 00:24:58 +0000374
Girish Moturu31758652020-09-22 09:10:48 -0700375 def configure_openwrt_ap_and_start(
376 self,
377 channel_5g=hostapd_constants.AP_DEFAULT_CHANNEL_5G,
378 channel_2g=hostapd_constants.AP_DEFAULT_CHANNEL_2G,
Girish Moturuddb89732021-01-24 14:11:26 -0800379 channel_5g_ap2=None,
380 channel_2g_ap2=None,
Girish Moturu31758652020-09-22 09:10:48 -0700381 ssid_length_2g=hostapd_constants.AP_SSID_LENGTH_2G,
382 passphrase_length_2g=hostapd_constants.AP_PASSPHRASE_LENGTH_2G,
383 ssid_length_5g=hostapd_constants.AP_SSID_LENGTH_5G,
384 passphrase_length_5g=hostapd_constants.AP_PASSPHRASE_LENGTH_5G,
385 mirror_ap=False,
386 hidden=False,
387 same_ssid=False,
388 open_network=False,
Alfie Chen310f7ff2021-01-26 20:36:09 +0800389 wpa1_network=False,
Girish Moturu31758652020-09-22 09:10:48 -0700390 wpa_network=False,
391 wep_network=False,
392 ent_network=False,
393 ent_network_pwd=False,
Girish Moturu4bf0b932020-09-25 11:17:22 -0700394 owe_network=False,
395 sae_network=False,
Girish Moturu31758652020-09-22 09:10:48 -0700396 radius_conf_2g=None,
397 radius_conf_5g=None,
398 radius_conf_pwd=None,
399 ap_count=1):
400 """Create, configure and start OpenWrt AP.
401
402 Args:
403 channel_5g: 5G channel to configure.
404 channel_2g: 2G channel to configure.
Girish Moturuddb89732021-01-24 14:11:26 -0800405 channel_5g_ap2: 5G channel to configure on AP2.
406 channel_2g_ap2: 2G channel to configure on AP2.
Girish Moturu31758652020-09-22 09:10:48 -0700407 ssid_length_2g: Int, number of characters to use for 2G SSID.
408 passphrase_length_2g: Int, length of password for 2G network.
409 ssid_length_5g: Int, number of characters to use for 5G SSID.
410 passphrase_length_5g: Int, length of password for 5G network.
411 same_ssid: Boolean, determines if both bands on AP use the same SSID.
412 open_network: Boolean, to check if open network should be configured.
413 wpa_network: Boolean, to check if wpa network should be configured.
414 wep_network: Boolean, to check if wep network should be configured.
415 ent_network: Boolean, to check if ent network should be configured.
416 ent_network_pwd: Boolean, to check if ent pwd network should be configured.
Girish Moturu4bf0b932020-09-25 11:17:22 -0700417 owe_network: Boolean, to check if owe network should be configured.
418 sae_network: Boolean, to check if sae network should be configured.
Girish Moturu31758652020-09-22 09:10:48 -0700419 radius_conf_2g: dictionary with enterprise radius server details.
420 radius_conf_5g: dictionary with enterprise radius server details.
421 radius_conf_pwd: dictionary with enterprise radiuse server details.
422 ap_count: APs to configure.
423 """
Girish Moturu8ff7d972020-09-18 22:53:46 -0700424 if mirror_ap and ap_count == 1:
tturneyfd697932020-11-24 11:43:44 -0800425 raise ValueError("ap_count cannot be 1 if mirror_ap is True.")
Roshan Pius5561d232021-01-22 16:34:39 -0800426 if (channel_5g_ap2 or channel_2g_ap2) and ap_count == 1:
Girish Moturuddb89732021-01-24 14:11:26 -0800427 raise ValueError(
428 "ap_count cannot be 1 if channels of AP2 are provided.")
429 # we are creating a channel list for 2G and 5G bands. The list is of
430 # size 2 and this is based on the assumption that each testbed will have
431 # at most 2 APs.
432 if not channel_5g_ap2:
433 channel_5g_ap2 = channel_5g
434 if not channel_2g_ap2:
435 channel_2g_ap2 = channel_2g
436 channels_2g = [channel_2g, channel_2g_ap2]
437 channels_5g = [channel_5g, channel_5g_ap2]
Girish Moturu8ff7d972020-09-18 22:53:46 -0700438
Girish Moturu31758652020-09-22 09:10:48 -0700439 self.reference_networks = []
Alfie Chen310f7ff2021-01-26 20:36:09 +0800440 self.wpa1_networks = []
Girish Moturu31758652020-09-22 09:10:48 -0700441 self.wpa_networks = []
442 self.wep_networks = []
443 self.ent_networks = []
444 self.ent_networks_pwd = []
445 self.open_network = []
Girish Moturu4bf0b932020-09-25 11:17:22 -0700446 self.owe_networks = []
447 self.sae_networks = []
Girish Moturu8ff7d972020-09-18 22:53:46 -0700448 self.bssid_map = []
449 for i in range(ap_count):
Girish Moturu31758652020-09-22 09:10:48 -0700450 network_list = []
Alfie Chen310f7ff2021-01-26 20:36:09 +0800451 if wpa1_network:
452 wpa1_dict = self.get_psk_network(mirror_ap,
453 self.wpa1_networks,
454 hidden, same_ssid,
455 ssid_length_2g, ssid_length_5g,
456 passphrase_length_2g,
457 passphrase_length_5g)
458 wpa1_dict[hostapd_constants.BAND_2G]["security"] = "psk"
459 wpa1_dict[hostapd_constants.BAND_5G]["security"] = "psk"
460 self.wpa1_networks.append(wpa1_dict)
461 network_list.append(wpa1_dict)
Girish Moturu31758652020-09-22 09:10:48 -0700462 if wpa_network:
463 wpa_dict = self.get_psk_network(mirror_ap,
464 self.reference_networks,
tturneyfd697932020-11-24 11:43:44 -0800465 hidden, same_ssid,
466 ssid_length_2g, ssid_length_5g,
Girish Moturu31758652020-09-22 09:10:48 -0700467 passphrase_length_2g,
468 passphrase_length_5g)
469 wpa_dict[hostapd_constants.BAND_2G]["security"] = "psk2"
470 wpa_dict[hostapd_constants.BAND_5G]["security"] = "psk2"
471 self.wpa_networks.append(wpa_dict)
472 network_list.append(wpa_dict)
473 if wep_network:
tturneyfd697932020-11-24 11:43:44 -0800474 wep_dict = self.get_wep_network(mirror_ap, self.wep_networks,
475 hidden, same_ssid,
476 ssid_length_2g, ssid_length_5g)
Girish Moturu31758652020-09-22 09:10:48 -0700477 network_list.append(wep_dict)
478 if ent_network:
tturneyfd697932020-11-24 11:43:44 -0800479 ent_dict = self.get_open_network(mirror_ap, self.ent_networks,
480 hidden, same_ssid,
Girish Moturu31758652020-09-22 09:10:48 -0700481 ssid_length_2g,
482 ssid_length_5g)
483 ent_dict["2g"]["security"] = "wpa2"
484 ent_dict["2g"].update(radius_conf_2g)
485 ent_dict["5g"]["security"] = "wpa2"
486 ent_dict["5g"].update(radius_conf_5g)
487 network_list.append(ent_dict)
488 if ent_network_pwd:
489 ent_pwd_dict = self.get_open_network(mirror_ap,
490 self.ent_networks_pwd,
tturneyfd697932020-11-24 11:43:44 -0800491 hidden, same_ssid,
Girish Moturu31758652020-09-22 09:10:48 -0700492 ssid_length_2g,
493 ssid_length_5g)
494 ent_pwd_dict["2g"]["security"] = "wpa2"
495 ent_pwd_dict["2g"].update(radius_conf_pwd)
496 ent_pwd_dict["5g"]["security"] = "wpa2"
497 ent_pwd_dict["5g"].update(radius_conf_pwd)
498 network_list.append(ent_pwd_dict)
499 if open_network:
tturneyfd697932020-11-24 11:43:44 -0800500 open_dict = self.get_open_network(mirror_ap, self.open_network,
501 hidden, same_ssid,
Girish Moturu31758652020-09-22 09:10:48 -0700502 ssid_length_2g,
503 ssid_length_5g)
504 network_list.append(open_dict)
Girish Moturu4bf0b932020-09-25 11:17:22 -0700505 if owe_network:
tturneyfd697932020-11-24 11:43:44 -0800506 owe_dict = self.get_open_network(mirror_ap, self.owe_networks,
507 hidden, same_ssid,
Girish Moturu4bf0b932020-09-25 11:17:22 -0700508 ssid_length_2g,
tturneyfd697932020-11-24 11:43:44 -0800509 ssid_length_5g, "OWE")
Girish Moturu4bf0b932020-09-25 11:17:22 -0700510 owe_dict[hostapd_constants.BAND_2G]["security"] = "owe"
511 owe_dict[hostapd_constants.BAND_5G]["security"] = "owe"
512 network_list.append(owe_dict)
513 if sae_network:
Hayden Nixce65f9f2021-01-12 22:41:36 +0000514 sae_dict = self.get_psk_network(mirror_ap, self.sae_networks,
515 hidden, same_ssid,
516 hostapd_constants.SAE_KEY_MGMT,
517 ssid_length_2g, ssid_length_5g,
518 passphrase_length_2g,
519 passphrase_length_5g)
Girish Moturu4bf0b932020-09-25 11:17:22 -0700520 sae_dict[hostapd_constants.BAND_2G]["security"] = "sae"
521 sae_dict[hostapd_constants.BAND_5G]["security"] = "sae"
522 network_list.append(sae_dict)
Girish Moturuddb89732021-01-24 14:11:26 -0800523 self.access_points[i].configure_ap(network_list, channels_2g[i],
524 channels_5g[i])
Girish Moturu8ff7d972020-09-18 22:53:46 -0700525 self.access_points[i].start_ap()
526 self.bssid_map.append(
527 self.access_points[i].get_bssids_for_wifi_networks())
528 if mirror_ap:
tturneyfd697932020-11-24 11:43:44 -0800529 self.access_points[i + 1].configure_ap(network_list,
Girish Moturuddb89732021-01-24 14:11:26 -0800530 channels_2g[i+1],
531 channels_5g[i+1])
tturneyfd697932020-11-24 11:43:44 -0800532 self.access_points[i + 1].start_ap()
Hsiu-Chang Chen5579e1a2020-10-21 10:40:12 +0800533 self.bssid_map.append(
tturneyfd697932020-11-24 11:43:44 -0800534 self.access_points[i + 1].get_bssids_for_wifi_networks())
Hsiu-Chang Chen5579e1a2020-10-21 10:40:12 +0800535 break
Girish Moturu31758652020-09-22 09:10:48 -0700536
Joe Brennan8c24a812017-04-13 14:27:05 -0700537 def legacy_configure_ap_and_start(
538 self,
Mark De Ruyterdee24c22018-04-13 17:34:44 -0700539 channel_5g=hostapd_constants.AP_DEFAULT_CHANNEL_5G,
Bindu Mahadev2ebdcec2018-05-03 19:51:24 +0000540 channel_2g=hostapd_constants.AP_DEFAULT_CHANNEL_2G,
541 max_2g_networks=hostapd_constants.AP_DEFAULT_MAX_SSIDS_2G,
542 max_5g_networks=hostapd_constants.AP_DEFAULT_MAX_SSIDS_5G,
543 ap_ssid_length_2g=hostapd_constants.AP_SSID_LENGTH_2G,
544 ap_passphrase_length_2g=hostapd_constants.AP_PASSPHRASE_LENGTH_2G,
545 ap_ssid_length_5g=hostapd_constants.AP_SSID_LENGTH_5G,
546 ap_passphrase_length_5g=hostapd_constants.AP_PASSPHRASE_LENGTH_5G,
547 hidden=False,
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700548 same_ssid=False,
549 mirror_ap=True,
Hsiu-Chang Chen81061752018-08-15 13:49:23 +0800550 wpa_network=False,
551 wep_network=False,
Girish Moturudcd73f62018-10-18 09:49:32 -0700552 ent_network=False,
553 radius_conf_2g=None,
554 radius_conf_5g=None,
Girish Moturuf1ce4202018-10-20 21:33:00 -0700555 ent_network_pwd=False,
556 radius_conf_pwd=None,
Bindu Mahadev72725d12017-06-05 03:11:30 +0000557 ap_count=1):
Joe Brennan8c24a812017-04-13 14:27:05 -0700558
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700559 config_count = 1
560 count = 0
561
Bindu Mahadev9c5a7d22018-07-16 12:08:35 -0700562 # For example, the NetworkSelector tests use 2 APs and require that
563 # both APs are not mirrored.
564 if not mirror_ap and ap_count == 1:
tturneyfd697932020-11-24 11:43:44 -0800565 raise ValueError("ap_count cannot be 1 if mirror_ap is False.")
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700566
567 if not mirror_ap:
568 config_count = ap_count
569
570 self.user_params["reference_networks"] = []
571 self.user_params["open_network"] = []
Hsiu-Chang Chen81061752018-08-15 13:49:23 +0800572 if wpa_network:
573 self.user_params["wpa_networks"] = []
574 if wep_network:
575 self.user_params["wep_networks"] = []
Girish Moturudcd73f62018-10-18 09:49:32 -0700576 if ent_network:
577 self.user_params["ent_networks"] = []
Girish Moturuf1ce4202018-10-20 21:33:00 -0700578 if ent_network_pwd:
579 self.user_params["ent_networks_pwd"] = []
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700580
Girish Moturu25e8bb02019-08-28 17:17:41 -0700581 # kill hostapd & dhcpd if the cleanup was not successful
582 for i in range(len(self.access_points)):
583 self.log.debug("Check ap state and cleanup")
584 self._cleanup_hostapd_and_dhcpd(i)
585
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700586 for count in range(config_count):
587
588 network_list_2g = []
589 network_list_5g = []
590
591 orig_network_list_2g = []
592 orig_network_list_5g = []
593
594 network_list_2g.append({"channel": channel_2g})
595 network_list_5g.append({"channel": channel_5g})
596
Hsiu-Chang Chen81061752018-08-15 13:49:23 +0800597 networks_dict = self.get_psk_network(
tturneyfd697932020-11-24 11:43:44 -0800598 mirror_ap,
599 self.user_params["reference_networks"],
600 hidden=hidden,
601 same_ssid=same_ssid)
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700602 self.reference_networks = self.user_params["reference_networks"]
603
Bindu Mahadev72725d12017-06-05 03:11:30 +0000604 network_list_2g.append(networks_dict["2g"])
605 network_list_5g.append(networks_dict["5g"])
Joe Brennan8c24a812017-04-13 14:27:05 -0700606
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700607 # When same_ssid is set, only configure one set of WPA networks.
608 # We cannot have more than one set because duplicate interface names
609 # are not allowed.
610 # TODO(bmahadev): Provide option to select the type of network,
611 # instead of defaulting to WPA.
612 if not same_ssid:
613 networks_dict = self.get_open_network(
tturneyfd697932020-11-24 11:43:44 -0800614 mirror_ap,
615 self.user_params["open_network"],
616 hidden=hidden,
617 same_ssid=same_ssid)
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700618 self.open_network = self.user_params["open_network"]
Joe Brennan8c24a812017-04-13 14:27:05 -0700619
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700620 network_list_2g.append(networks_dict["2g"])
621 network_list_5g.append(networks_dict["5g"])
Bindu Mahadev1f227e02017-07-06 00:24:58 +0000622
Hsiu-Chang Chen81061752018-08-15 13:49:23 +0800623 if wpa_network:
624 networks_dict = self.get_psk_network(
tturneyfd697932020-11-24 11:43:44 -0800625 mirror_ap,
626 self.user_params["wpa_networks"],
627 hidden=hidden,
628 same_ssid=same_ssid,
629 security_mode=hostapd_constants.WPA_STRING)
Hsiu-Chang Chen81061752018-08-15 13:49:23 +0800630 self.wpa_networks = self.user_params["wpa_networks"]
631
632 network_list_2g.append(networks_dict["2g"])
633 network_list_5g.append(networks_dict["5g"])
634
635 if wep_network:
636 networks_dict = self.get_wep_network(
tturneyfd697932020-11-24 11:43:44 -0800637 mirror_ap,
638 self.user_params["wep_networks"],
639 hidden=hidden,
640 same_ssid=same_ssid)
Hsiu-Chang Chen81061752018-08-15 13:49:23 +0800641 self.wep_networks = self.user_params["wep_networks"]
642
643 network_list_2g.append(networks_dict["2g"])
644 network_list_5g.append(networks_dict["5g"])
645
Girish Moturudcd73f62018-10-18 09:49:32 -0700646 if ent_network:
647 networks_dict = self.get_open_network(
tturneyfd697932020-11-24 11:43:44 -0800648 mirror_ap,
649 self.user_params["ent_networks"],
650 hidden=hidden,
651 same_ssid=same_ssid)
652 networks_dict["2g"][
653 "security"] = hostapd_constants.ENT_STRING
Girish Moturudcd73f62018-10-18 09:49:32 -0700654 networks_dict["2g"].update(radius_conf_2g)
tturneyfd697932020-11-24 11:43:44 -0800655 networks_dict["5g"][
656 "security"] = hostapd_constants.ENT_STRING
Girish Moturudcd73f62018-10-18 09:49:32 -0700657 networks_dict["5g"].update(radius_conf_5g)
658 self.ent_networks = self.user_params["ent_networks"]
659
660 network_list_2g.append(networks_dict["2g"])
661 network_list_5g.append(networks_dict["5g"])
662
Girish Moturuf1ce4202018-10-20 21:33:00 -0700663 if ent_network_pwd:
664 networks_dict = self.get_open_network(
tturneyfd697932020-11-24 11:43:44 -0800665 mirror_ap,
666 self.user_params["ent_networks_pwd"],
667 hidden=hidden,
668 same_ssid=same_ssid)
669 networks_dict["2g"][
670 "security"] = hostapd_constants.ENT_STRING
Girish Moturuf1ce4202018-10-20 21:33:00 -0700671 networks_dict["2g"].update(radius_conf_pwd)
tturneyfd697932020-11-24 11:43:44 -0800672 networks_dict["5g"][
673 "security"] = hostapd_constants.ENT_STRING
Girish Moturuf1ce4202018-10-20 21:33:00 -0700674 networks_dict["5g"].update(radius_conf_pwd)
tturneyfd697932020-11-24 11:43:44 -0800675 self.ent_networks_pwd = self.user_params[
676 "ent_networks_pwd"]
Girish Moturuf1ce4202018-10-20 21:33:00 -0700677
678 network_list_2g.append(networks_dict["2g"])
679 network_list_5g.append(networks_dict["5g"])
680
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700681 orig_network_list_5g = copy.copy(network_list_5g)
682 orig_network_list_2g = copy.copy(network_list_2g)
683
684 if len(network_list_5g) > 1:
tturneyfd697932020-11-24 11:43:44 -0800685 self.config_5g = self._generate_legacy_ap_config(
686 network_list_5g)
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700687 if len(network_list_2g) > 1:
tturneyfd697932020-11-24 11:43:44 -0800688 self.config_2g = self._generate_legacy_ap_config(
689 network_list_2g)
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700690
691 self.access_points[count].start_ap(self.config_2g)
692 self.access_points[count].start_ap(self.config_5g)
tturneyfd697932020-11-24 11:43:44 -0800693 self.populate_bssid(count, self.access_points[count],
694 orig_network_list_5g, orig_network_list_2g)
Bindu Mahadev72725d12017-06-05 03:11:30 +0000695
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700696 # Repeat configuration on the second router.
697 if mirror_ap and ap_count == 2:
698 self.access_points[AP_2].start_ap(self.config_2g)
699 self.access_points[AP_2].start_ap(self.config_5g)
700 self.populate_bssid(AP_2, self.access_points[AP_2],
tturneyfd697932020-11-24 11:43:44 -0800701 orig_network_list_5g, orig_network_list_2g)
Bindu Mahadeve7d47c32018-07-03 16:48:03 -0700702
Girish Moturu27ff0b32019-08-03 21:44:59 -0700703 def _kill_processes(self, ap, daemon):
704 """ Kill hostapd and dhcpd daemons
705
706 Args:
707 ap: AP to cleanup
708 daemon: process to kill
709
710 Returns: True/False if killing process is successful
711 """
712 self.log.info("Killing %s" % daemon)
713 pids = ap.ssh.run('pidof %s' % daemon, ignore_status=True)
714 if pids.stdout:
715 ap.ssh.run('kill %s' % pids.stdout, ignore_status=True)
716 time.sleep(3)
717 pids = ap.ssh.run('pidof %s' % daemon, ignore_status=True)
718 if pids.stdout:
719 return False
720 return True
721
722 def _cleanup_hostapd_and_dhcpd(self, count):
723 """ Check if AP was cleaned up properly
724
725 Kill hostapd and dhcpd processes if cleanup was not successful in the
726 last run
727
728 Args:
729 count: AP to check
730
731 Returns:
732 New AccessPoint object if AP required cleanup
733
734 Raises:
735 Error: if the AccessPoint timed out to setup
736 """
737 ap = self.access_points[count]
738 phy_ifaces = ap.interfaces.get_physical_interface()
739 kill_hostapd = False
740 for iface in phy_ifaces:
741 if '2g_' in iface or '5g_' in iface or 'xg_' in iface:
742 kill_hostapd = True
743 break
744
745 if not kill_hostapd:
746 return
747
748 self.log.debug("Cleanup AP")
749 if not self._kill_processes(ap, 'hostapd') or \
750 not self._kill_processes(ap, 'dhcpd'):
tturneyfd697932020-11-24 11:43:44 -0800751 raise ("Failed to cleanup AP")
Girish Moturu27ff0b32019-08-03 21:44:59 -0700752
753 ap.__init__(self.user_params['AccessPoint'][count])
754
Joe Brennan8c24a812017-04-13 14:27:05 -0700755 def _generate_legacy_ap_config(self, network_list):
756 bss_settings = []
Bindu Mahadev071af262018-10-17 16:42:06 -0700757 wlan_2g = self.access_points[AP_1].wlan_2g
758 wlan_5g = self.access_points[AP_1].wlan_5g
Joe Brennan8c24a812017-04-13 14:27:05 -0700759 ap_settings = network_list.pop(0)
Bindu Mahadev1f227e02017-07-06 00:24:58 +0000760 # TODO:(bmahadev) This is a bug. We should not have to pop the first
761 # network in the list and treat it as a separate case. Instead,
762 # create_ap_preset() should be able to take NULL ssid and security and
763 # build config based on the bss_Settings alone.
Joe Brennan8c24a812017-04-13 14:27:05 -0700764 hostapd_config_settings = network_list.pop(0)
765 for network in network_list:
Hsiu-Chang Chen8d8bbbf2018-08-02 11:37:11 +0800766 if "password" in network:
Bindu Mahadev1c895c22018-01-18 18:20:43 -0800767 bss_settings.append(
768 hostapd_bss_settings.BssSettings(
769 name=network["SSID"],
770 ssid=network["SSID"],
Hsiu-Chang Chen8d8bbbf2018-08-02 11:37:11 +0800771 hidden=network["hiddenSSID"],
Bindu Mahadev1c895c22018-01-18 18:20:43 -0800772 security=hostapd_security.Security(
773 security_mode=network["security"],
774 password=network["password"])))
Hsiu-Chang Chen81061752018-08-15 13:49:23 +0800775 elif "wepKeys" in network:
776 bss_settings.append(
777 hostapd_bss_settings.BssSettings(
778 name=network["SSID"],
779 ssid=network["SSID"],
780 hidden=network["hiddenSSID"],
781 security=hostapd_security.Security(
782 security_mode=network["security"],
783 password=network["wepKeys"][0])))
Girish Moturudcd73f62018-10-18 09:49:32 -0700784 elif network["security"] == hostapd_constants.ENT_STRING:
785 bss_settings.append(
786 hostapd_bss_settings.BssSettings(
787 name=network["SSID"],
788 ssid=network["SSID"],
789 hidden=network["hiddenSSID"],
790 security=hostapd_security.Security(
791 security_mode=network["security"],
792 radius_server_ip=network["radius_server_ip"],
793 radius_server_port=network["radius_server_port"],
tturneyfd697932020-11-24 11:43:44 -0800794 radius_server_secret=network[
795 "radius_server_secret"])))
Hsiu-Chang Chen81061752018-08-15 13:49:23 +0800796 else:
Joe Brennan8c24a812017-04-13 14:27:05 -0700797 bss_settings.append(
798 hostapd_bss_settings.BssSettings(
Bindu Mahadev72725d12017-06-05 03:11:30 +0000799 name=network["SSID"],
800 ssid=network["SSID"],
Hsiu-Chang Chen8d8bbbf2018-08-02 11:37:11 +0800801 hidden=network["hiddenSSID"]))
Bindu Mahadev72725d12017-06-05 03:11:30 +0000802 if "password" in hostapd_config_settings:
Joe Brennan8c24a812017-04-13 14:27:05 -0700803 config = hostapd_ap_preset.create_ap_preset(
Bindu Mahadev071af262018-10-17 16:42:06 -0700804 iface_wlan_2g=wlan_2g,
805 iface_wlan_5g=wlan_5g,
Joe Brennan8c24a812017-04-13 14:27:05 -0700806 channel=ap_settings["channel"],
Bindu Mahadev72725d12017-06-05 03:11:30 +0000807 ssid=hostapd_config_settings["SSID"],
Hsiu-Chang Chen8d8bbbf2018-08-02 11:37:11 +0800808 hidden=hostapd_config_settings["hiddenSSID"],
Joe Brennan8c24a812017-04-13 14:27:05 -0700809 security=hostapd_security.Security(
810 security_mode=hostapd_config_settings["security"],
Bindu Mahadev72725d12017-06-05 03:11:30 +0000811 password=hostapd_config_settings["password"]),
Bindu Mahadev071af262018-10-17 16:42:06 -0700812 bss_settings=bss_settings)
Hsiu-Chang Chen81061752018-08-15 13:49:23 +0800813 elif "wepKeys" in hostapd_config_settings:
814 config = hostapd_ap_preset.create_ap_preset(
Bindu Mahadev071af262018-10-17 16:42:06 -0700815 iface_wlan_2g=wlan_2g,
816 iface_wlan_5g=wlan_5g,
Hsiu-Chang Chen81061752018-08-15 13:49:23 +0800817 channel=ap_settings["channel"],
818 ssid=hostapd_config_settings["SSID"],
819 hidden=hostapd_config_settings["hiddenSSID"],
820 security=hostapd_security.Security(
821 security_mode=hostapd_config_settings["security"],
822 password=hostapd_config_settings["wepKeys"][0]),
Bindu Mahadev071af262018-10-17 16:42:06 -0700823 bss_settings=bss_settings)
Joe Brennan8c24a812017-04-13 14:27:05 -0700824 else:
825 config = hostapd_ap_preset.create_ap_preset(
Bindu Mahadev071af262018-10-17 16:42:06 -0700826 iface_wlan_2g=wlan_2g,
827 iface_wlan_5g=wlan_5g,
Joe Brennan8c24a812017-04-13 14:27:05 -0700828 channel=ap_settings["channel"],
Bindu Mahadev72725d12017-06-05 03:11:30 +0000829 ssid=hostapd_config_settings["SSID"],
Hsiu-Chang Chen8d8bbbf2018-08-02 11:37:11 +0800830 hidden=hostapd_config_settings["hiddenSSID"],
Bindu Mahadev071af262018-10-17 16:42:06 -0700831 bss_settings=bss_settings)
Joe Brennan8c24a812017-04-13 14:27:05 -0700832 return config
Girish Moturucf4dccd2018-08-27 12:22:00 -0700833
834 def configure_packet_capture(
835 self,
836 channel_5g=hostapd_constants.AP_DEFAULT_CHANNEL_5G,
837 channel_2g=hostapd_constants.AP_DEFAULT_CHANNEL_2G):
838 """Configure packet capture for 2G and 5G bands.
839
840 Args:
841 channel_5g: Channel to set the monitor mode to for 5G band.
842 channel_2g: Channel to set the monitor mode to for 2G band.
843 """
844 self.packet_capture = self.packet_capture[0]
845 result = self.packet_capture.configure_monitor_mode(
846 hostapd_constants.BAND_2G, channel_2g)
847 if not result:
848 raise ValueError("Failed to configure channel for 2G band")
849
850 result = self.packet_capture.configure_monitor_mode(
851 hostapd_constants.BAND_5G, channel_5g)
852 if not result:
853 raise ValueError("Failed to configure channel for 5G band.")
Girish Moturue6ccc7a2019-09-19 11:00:21 -0700854
855 @staticmethod
856 def wifi_test_wrap(fn):
857 def _safe_wrap_test_case(self, *args, **kwargs):
858 test_id = "%s:%s:%s" % (self.__class__.__name__, self.test_name,
859 self.log_begin_time.replace(' ', '-'))
860 self.test_id = test_id
861 self.result_detail = ""
862 tries = int(self.user_params.get("wifi_auto_rerun", 3))
863 for ad in self.android_devices:
864 ad.log_path = self.log_path
865 for i in range(tries + 1):
866 result = True
867 if i > 0:
tturneyfd697932020-11-24 11:43:44 -0800868 log_string = "[Test Case] RETRY:%s %s" % (i,
869 self.test_name)
Girish Moturue6ccc7a2019-09-19 11:00:21 -0700870 self.log.info(log_string)
871 self._teardown_test(self.test_name)
872 self._setup_test(self.test_name)
873 try:
874 result = fn(self, *args, **kwargs)
875 except signals.TestFailure as e:
876 self.log.warn("Error msg: %s" % e)
877 if self.result_detail:
878 signal.details = self.result_detail
879 result = False
880 except signals.TestSignal:
881 if self.result_detail:
882 signal.details = self.result_detail
883 raise
884 except Exception as e:
885 self.log.exception(e)
886 asserts.fail(self.result_detail)
887 if result is False:
888 if i < tries:
889 continue
890 else:
891 break
892 if result is not False:
893 asserts.explicit_pass(self.result_detail)
894 else:
895 asserts.fail(self.result_detail)
896
tturneyfd697932020-11-24 11:43:44 -0800897 return _safe_wrap_test_case