Mark De Ruyter | 1a7ae57 | 2018-03-02 15:35:36 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 2 | # |
| 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 Mahadev | 2ebdcec | 2018-05-03 19:51:24 +0000 | [diff] [blame] | 16 | """ |
| 17 | Base Class for Defining Common WiFi Test Functionality |
| 18 | """ |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 19 | |
Bindu Mahadev | 1f227e0 | 2017-07-06 00:24:58 +0000 | [diff] [blame] | 20 | import copy |
| 21 | import itertools |
Hsiu-Chang Chen | 5579e1a | 2020-10-21 10:40:12 +0800 | [diff] [blame] | 22 | import os |
Bindu Mahadev | 2ebdcec | 2018-05-03 19:51:24 +0000 | [diff] [blame] | 23 | import time |
| 24 | |
| 25 | import acts.controllers.access_point as ap |
Bindu Mahadev | edf1716 | 2017-07-07 03:46:55 +0000 | [diff] [blame] | 26 | |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 27 | from acts import asserts |
Girish Moturu | e6ccc7a | 2019-09-19 11:00:21 -0700 | [diff] [blame] | 28 | from acts import signals |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 29 | from acts import utils |
| 30 | from acts.base_test import BaseTestClass |
Bindu Mahadev | 2ebdcec | 2018-05-03 19:51:24 +0000 | [diff] [blame] | 31 | from acts.signals import TestSignal |
| 32 | from acts.controllers import android_device |
Girish Moturu | 27ff0b3 | 2019-08-03 21:44:59 -0700 | [diff] [blame] | 33 | from acts.controllers.access_point import AccessPoint |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 34 | from acts.controllers.ap_lib import hostapd_ap_preset |
| 35 | from acts.controllers.ap_lib import hostapd_bss_settings |
| 36 | from acts.controllers.ap_lib import hostapd_constants |
| 37 | from acts.controllers.ap_lib import hostapd_security |
Hsiu-Chang Chen | 5579e1a | 2020-10-21 10:40:12 +0800 | [diff] [blame] | 38 | from acts.keys import Config |
| 39 | from acts_contrib.test_utils.net import net_test_utils as nutils |
| 40 | from acts_contrib.test_utils.wifi import wifi_test_utils as wutils |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 41 | |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 42 | AP_1 = 0 |
| 43 | AP_2 = 1 |
| 44 | MAX_AP_COUNT = 2 |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 45 | |
Nate Jiang | 8bbc94f | 2019-06-11 19:13:51 -0700 | [diff] [blame] | 46 | |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 47 | class WifiBaseTest(BaseTestClass): |
Hsiu-Chang Chen | 5579e1a | 2020-10-21 10:40:12 +0800 | [diff] [blame] | 48 | 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 Jia | 168103b | 2019-09-06 12:22:52 -0700 | [diff] [blame] | 54 | def setup_class(self): |
Bindu Mahadev | d3eaf5d | 2018-05-08 15:32:26 -0700 | [diff] [blame] | 55 | if hasattr(self, 'attenuators') and self.attenuators: |
Bindu Mahadev | 3bb29fa | 2017-08-10 16:08:20 +0000 | [diff] [blame] | 56 | for attenuator in self.attenuators: |
| 57 | attenuator.set_atten(0) |
Hsiu-Chang Chen | 5579e1a | 2020-10-21 10:40:12 +0800 | [diff] [blame] | 58 | 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): |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 73 | 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 Chen | 5579e1a | 2020-10-21 10:40:12 +0800 | [diff] [blame] | 78 | 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"): |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 84 | self.packet_log_pid = wutils.start_pcap(self.packet_logger, 'dual', |
| 85 | self.test_name) |
Hsiu-Chang Chen | 5579e1a | 2020-10-21 10:40:12 +0800 | [diff] [blame] | 86 | |
| 87 | def teardown_test(self): |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 88 | if (hasattr(self, "android_devices") |
| 89 | and hasattr(self, "cnss_diag_file") |
| 90 | and hasattr(self, "pixel_models")): |
Hsiu-Chang Chen | 5579e1a | 2020-10-21 10:40:12 +0800 | [diff] [blame] | 91 | wutils.stop_cnss_diags(self.android_devices, self.pixel_models) |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 92 | 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 Chen | 5579e1a | 2020-10-21 10:40:12 +0800 | [diff] [blame] | 98 | if hasattr(self, "packet_logger") and self.packet_log_pid: |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 99 | wutils.stop_pcap(self.packet_logger, |
| 100 | self.packet_log_pid, |
| 101 | test_status=True) |
Hsiu-Chang Chen | 5579e1a | 2020-10-21 10:40:12 +0800 | [diff] [blame] | 102 | 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) |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 110 | if (hasattr(self, "cnss_diag_file") |
| 111 | and hasattr(self, "pixel_models")): |
Hsiu-Chang Chen | 5579e1a | 2020-10-21 10:40:12 +0800 | [diff] [blame] | 112 | wutils.stop_cnss_diags(self.android_devices, self.pixel_models) |
| 113 | for ad in self.android_devices: |
| 114 | wutils.get_cnss_diag_log(ad) |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 115 | for proc in self.tcpdump_proc: |
| 116 | nutils.stop_tcpdump(proc[0], proc[1], self.test_name) |
| 117 | self.tcpdump_proc = [] |
Hsiu-Chang Chen | 5579e1a | 2020-10-21 10:40:12 +0800 | [diff] [blame] | 118 | if hasattr(self, "packet_logger") and self.packet_log_pid: |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 119 | wutils.stop_pcap(self.packet_logger, |
| 120 | self.packet_log_pid, |
| 121 | test_status=False) |
Hsiu-Chang Chen | 5579e1a | 2020-10-21 10:40:12 +0800 | [diff] [blame] | 122 | self.packet_log_pid = {} |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 123 | |
Hsiu-Chang Chen | 8106175 | 2018-08-15 13:49:23 +0800 | [diff] [blame] | 124 | def get_psk_network( |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 125 | self, |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 126 | mirror_ap, |
| 127 | reference_networks, |
Bindu Mahadev | 1c895c2 | 2018-01-18 18:20:43 -0800 | [diff] [blame] | 128 | hidden=False, |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 129 | same_ssid=False, |
Hsiu-Chang Chen | 8106175 | 2018-08-15 13:49:23 +0800 | [diff] [blame] | 130 | security_mode=hostapd_constants.WPA2_STRING, |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 131 | 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 Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 135 | """Generates SSID and passphrase for a WPA2 network using random |
| 136 | generator. |
| 137 | |
| 138 | Args: |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 139 | 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 Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 145 | 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 Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 148 | |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 149 | Returns: A dict of 2G and 5G network lists for hostapd configuration. |
| 150 | |
| 151 | """ |
| 152 | network_dict_2g = {} |
| 153 | network_dict_5g = {} |
Hsiu-Chang Chen | 8106175 | 2018-08-15 13:49:23 +0800 | [diff] [blame] | 154 | ref_5g_security = security_mode |
| 155 | ref_2g_security = security_mode |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 156 | |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 157 | if same_ssid: |
| 158 | ref_2g_ssid = 'xg_%s' % utils.rand_ascii_str(ssid_length_2g) |
| 159 | ref_5g_ssid = ref_2g_ssid |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 160 | |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 161 | 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 Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 170 | |
Hsiu-Chang Chen | 8d8bbbf | 2018-08-02 11:37:11 +0800 | [diff] [blame] | 171 | network_dict_2g = { |
| 172 | "SSID": ref_2g_ssid, |
| 173 | "security": ref_2g_security, |
| 174 | "password": ref_2g_passphrase, |
| 175 | "hiddenSSID": hidden |
| 176 | } |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 177 | |
Hsiu-Chang Chen | 8d8bbbf | 2018-08-02 11:37:11 +0800 | [diff] [blame] | 178 | network_dict_5g = { |
| 179 | "SSID": ref_5g_ssid, |
| 180 | "security": ref_5g_security, |
| 181 | "password": ref_5g_passphrase, |
| 182 | "hiddenSSID": hidden |
| 183 | } |
Bindu Mahadev | 1c895c2 | 2018-01-18 18:20:43 -0800 | [diff] [blame] | 184 | |
Bindu Mahadev | d07198d | 2017-09-15 14:06:54 -0700 | [diff] [blame] | 185 | ap = 0 |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 186 | 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 Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 190 | }) |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 191 | if not mirror_ap: |
| 192 | break |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 193 | return {"2g": network_dict_2g, "5g": network_dict_5g} |
| 194 | |
markdr | 5693901 | 2017-07-26 12:48:43 -0700 | [diff] [blame] | 195 | def get_open_network(self, |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 196 | mirror_ap, |
| 197 | open_network, |
Bindu Mahadev | 1c895c2 | 2018-01-18 18:20:43 -0800 | [diff] [blame] | 198 | hidden=False, |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 199 | same_ssid=False, |
markdr | 5693901 | 2017-07-26 12:48:43 -0700 | [diff] [blame] | 200 | ssid_length_2g=hostapd_constants.AP_SSID_LENGTH_2G, |
Girish Moturu | 4bf0b93 | 2020-09-25 11:17:22 -0700 | [diff] [blame] | 201 | ssid_length_5g=hostapd_constants.AP_SSID_LENGTH_5G, |
| 202 | security_mode='none'): |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 203 | """Generates SSIDs for a open network using a random generator. |
| 204 | |
| 205 | Args: |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 206 | 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 Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 211 | 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 Moturu | 4bf0b93 | 2020-09-25 11:17:22 -0700 | [diff] [blame] | 213 | security_mode: 'none' for open and 'OWE' for WPA3 OWE. |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 214 | |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 215 | Returns: A dict of 2G and 5G network lists for hostapd configuration. |
| 216 | |
| 217 | """ |
| 218 | network_dict_2g = {} |
| 219 | network_dict_5g = {} |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 220 | |
| 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 Chen | 8d8bbbf | 2018-08-02 11:37:11 +0800 | [diff] [blame] | 229 | network_dict_2g = { |
Bindu Mahadev | 2ebdcec | 2018-05-03 19:51:24 +0000 | [diff] [blame] | 230 | "SSID": open_2g_ssid, |
Girish Moturu | 4bf0b93 | 2020-09-25 11:17:22 -0700 | [diff] [blame] | 231 | "security": security_mode, |
Hsiu-Chang Chen | 8d8bbbf | 2018-08-02 11:37:11 +0800 | [diff] [blame] | 232 | "hiddenSSID": hidden |
| 233 | } |
Bindu Mahadev | 1c895c2 | 2018-01-18 18:20:43 -0800 | [diff] [blame] | 234 | |
Hsiu-Chang Chen | 8d8bbbf | 2018-08-02 11:37:11 +0800 | [diff] [blame] | 235 | network_dict_5g = { |
Bindu Mahadev | 2ebdcec | 2018-05-03 19:51:24 +0000 | [diff] [blame] | 236 | "SSID": open_5g_ssid, |
Girish Moturu | 4bf0b93 | 2020-09-25 11:17:22 -0700 | [diff] [blame] | 237 | "security": security_mode, |
Hsiu-Chang Chen | 8d8bbbf | 2018-08-02 11:37:11 +0800 | [diff] [blame] | 238 | "hiddenSSID": hidden |
| 239 | } |
Bindu Mahadev | 1c895c2 | 2018-01-18 18:20:43 -0800 | [diff] [blame] | 240 | |
Bindu Mahadev | d07198d | 2017-09-15 14:06:54 -0700 | [diff] [blame] | 241 | ap = 0 |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 242 | 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 Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 246 | }) |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 247 | if not mirror_ap: |
| 248 | break |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 249 | return {"2g": network_dict_2g, "5g": network_dict_5g} |
| 250 | |
Hsiu-Chang Chen | 8106175 | 2018-08-15 13:49:23 +0800 | [diff] [blame] | 251 | 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 Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 321 | 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 Chen | 8106175 | 2018-08-15 13:49:23 +0800 | [diff] [blame] | 337 | 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 Moturu | dcd73f6 | 2018-10-18 09:49:32 -0700 | [diff] [blame] | 341 | if network["security"] == hostapd_constants.ENT_STRING: |
Girish Moturu | f1ce420 | 2018-10-20 21:33:00 -0700 | [diff] [blame] | 342 | 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 Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 346 | if network["security"] == 'none': |
| 347 | self.open_network[ap_instance][band]["bssid"] = bssid |
| 348 | |
Bindu Mahadev | 2ebdcec | 2018-05-03 19:51:24 +0000 | [diff] [blame] | 349 | def populate_bssid(self, ap_instance, ap, networks_5g, networks_2g): |
Bindu Mahadev | 1f227e0 | 2017-07-06 00:24:58 +0000 | [diff] [blame] | 350 | """Get bssid for a given SSID and add it to the network dictionary. |
| 351 | |
| 352 | Args: |
Bindu Mahadev | d07198d | 2017-09-15 14:06:54 -0700 | [diff] [blame] | 353 | ap_instance: Accesspoint index that was configured. |
| 354 | ap: Accesspoint object corresponding to ap_instance. |
Mark De Ruyter | dee24c2 | 2018-04-13 17:34:44 -0700 | [diff] [blame] | 355 | networks_5g: List of 5g networks configured on the APs. |
Bindu Mahadev | 2ebdcec | 2018-05-03 19:51:24 +0000 | [diff] [blame] | 356 | networks_2g: List of 2g networks configured on the APs. |
Bindu Mahadev | 1f227e0 | 2017-07-06 00:24:58 +0000 | [diff] [blame] | 357 | |
| 358 | """ |
| 359 | |
Bindu Mahadev | 2ebdcec | 2018-05-03 19:51:24 +0000 | [diff] [blame] | 360 | if not (networks_5g or networks_2g): |
Bindu Mahadev | 1f227e0 | 2017-07-06 00:24:58 +0000 | [diff] [blame] | 361 | return |
| 362 | |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 363 | for network in networks_5g: |
Bindu Mahadev | 1f227e0 | 2017-07-06 00:24:58 +0000 | [diff] [blame] | 364 | if 'channel' in network: |
| 365 | continue |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 366 | self.update_bssid(ap_instance, ap, network, |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 367 | hostapd_constants.BAND_5G) |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 368 | |
| 369 | for network in networks_2g: |
| 370 | if 'channel' in network: |
| 371 | continue |
| 372 | self.update_bssid(ap_instance, ap, network, |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 373 | hostapd_constants.BAND_2G) |
Bindu Mahadev | 1f227e0 | 2017-07-06 00:24:58 +0000 | [diff] [blame] | 374 | |
Girish Moturu | 3175865 | 2020-09-22 09:10:48 -0700 | [diff] [blame] | 375 | 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 Moturu | ddb8973 | 2021-01-24 14:11:26 -0800 | [diff] [blame] | 379 | channel_5g_ap2=None, |
| 380 | channel_2g_ap2=None, |
Girish Moturu | 3175865 | 2020-09-22 09:10:48 -0700 | [diff] [blame] | 381 | 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 Chen | 310f7ff | 2021-01-26 20:36:09 +0800 | [diff] [blame] | 389 | wpa1_network=False, |
Girish Moturu | 3175865 | 2020-09-22 09:10:48 -0700 | [diff] [blame] | 390 | wpa_network=False, |
| 391 | wep_network=False, |
| 392 | ent_network=False, |
| 393 | ent_network_pwd=False, |
Girish Moturu | 4bf0b93 | 2020-09-25 11:17:22 -0700 | [diff] [blame] | 394 | owe_network=False, |
| 395 | sae_network=False, |
Girish Moturu | 3175865 | 2020-09-22 09:10:48 -0700 | [diff] [blame] | 396 | 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 Moturu | ddb8973 | 2021-01-24 14:11:26 -0800 | [diff] [blame] | 405 | channel_5g_ap2: 5G channel to configure on AP2. |
| 406 | channel_2g_ap2: 2G channel to configure on AP2. |
Girish Moturu | 3175865 | 2020-09-22 09:10:48 -0700 | [diff] [blame] | 407 | 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 Moturu | 4bf0b93 | 2020-09-25 11:17:22 -0700 | [diff] [blame] | 417 | owe_network: Boolean, to check if owe network should be configured. |
| 418 | sae_network: Boolean, to check if sae network should be configured. |
Girish Moturu | 3175865 | 2020-09-22 09:10:48 -0700 | [diff] [blame] | 419 | 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 Moturu | 8ff7d97 | 2020-09-18 22:53:46 -0700 | [diff] [blame] | 424 | if mirror_ap and ap_count == 1: |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 425 | raise ValueError("ap_count cannot be 1 if mirror_ap is True.") |
Roshan Pius | 5561d23 | 2021-01-22 16:34:39 -0800 | [diff] [blame] | 426 | if (channel_5g_ap2 or channel_2g_ap2) and ap_count == 1: |
Girish Moturu | ddb8973 | 2021-01-24 14:11:26 -0800 | [diff] [blame] | 427 | 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 Moturu | 8ff7d97 | 2020-09-18 22:53:46 -0700 | [diff] [blame] | 438 | |
Girish Moturu | 3175865 | 2020-09-22 09:10:48 -0700 | [diff] [blame] | 439 | self.reference_networks = [] |
Alfie Chen | 310f7ff | 2021-01-26 20:36:09 +0800 | [diff] [blame] | 440 | self.wpa1_networks = [] |
Girish Moturu | 3175865 | 2020-09-22 09:10:48 -0700 | [diff] [blame] | 441 | self.wpa_networks = [] |
| 442 | self.wep_networks = [] |
| 443 | self.ent_networks = [] |
| 444 | self.ent_networks_pwd = [] |
| 445 | self.open_network = [] |
Girish Moturu | 4bf0b93 | 2020-09-25 11:17:22 -0700 | [diff] [blame] | 446 | self.owe_networks = [] |
| 447 | self.sae_networks = [] |
Girish Moturu | 8ff7d97 | 2020-09-18 22:53:46 -0700 | [diff] [blame] | 448 | self.bssid_map = [] |
| 449 | for i in range(ap_count): |
Girish Moturu | 3175865 | 2020-09-22 09:10:48 -0700 | [diff] [blame] | 450 | network_list = [] |
Alfie Chen | 310f7ff | 2021-01-26 20:36:09 +0800 | [diff] [blame] | 451 | 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 Moturu | 3175865 | 2020-09-22 09:10:48 -0700 | [diff] [blame] | 462 | if wpa_network: |
| 463 | wpa_dict = self.get_psk_network(mirror_ap, |
| 464 | self.reference_networks, |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 465 | hidden, same_ssid, |
| 466 | ssid_length_2g, ssid_length_5g, |
Girish Moturu | 3175865 | 2020-09-22 09:10:48 -0700 | [diff] [blame] | 467 | 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: |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 474 | wep_dict = self.get_wep_network(mirror_ap, self.wep_networks, |
| 475 | hidden, same_ssid, |
| 476 | ssid_length_2g, ssid_length_5g) |
Girish Moturu | 3175865 | 2020-09-22 09:10:48 -0700 | [diff] [blame] | 477 | network_list.append(wep_dict) |
| 478 | if ent_network: |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 479 | ent_dict = self.get_open_network(mirror_ap, self.ent_networks, |
| 480 | hidden, same_ssid, |
Girish Moturu | 3175865 | 2020-09-22 09:10:48 -0700 | [diff] [blame] | 481 | 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, |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 491 | hidden, same_ssid, |
Girish Moturu | 3175865 | 2020-09-22 09:10:48 -0700 | [diff] [blame] | 492 | 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: |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 500 | open_dict = self.get_open_network(mirror_ap, self.open_network, |
| 501 | hidden, same_ssid, |
Girish Moturu | 3175865 | 2020-09-22 09:10:48 -0700 | [diff] [blame] | 502 | ssid_length_2g, |
| 503 | ssid_length_5g) |
| 504 | network_list.append(open_dict) |
Girish Moturu | 4bf0b93 | 2020-09-25 11:17:22 -0700 | [diff] [blame] | 505 | if owe_network: |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 506 | owe_dict = self.get_open_network(mirror_ap, self.owe_networks, |
| 507 | hidden, same_ssid, |
Girish Moturu | 4bf0b93 | 2020-09-25 11:17:22 -0700 | [diff] [blame] | 508 | ssid_length_2g, |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 509 | ssid_length_5g, "OWE") |
Girish Moturu | 4bf0b93 | 2020-09-25 11:17:22 -0700 | [diff] [blame] | 510 | 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 Nix | ce65f9f | 2021-01-12 22:41:36 +0000 | [diff] [blame] | 514 | 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 Moturu | 4bf0b93 | 2020-09-25 11:17:22 -0700 | [diff] [blame] | 520 | sae_dict[hostapd_constants.BAND_2G]["security"] = "sae" |
| 521 | sae_dict[hostapd_constants.BAND_5G]["security"] = "sae" |
| 522 | network_list.append(sae_dict) |
Girish Moturu | ddb8973 | 2021-01-24 14:11:26 -0800 | [diff] [blame] | 523 | self.access_points[i].configure_ap(network_list, channels_2g[i], |
| 524 | channels_5g[i]) |
Girish Moturu | 8ff7d97 | 2020-09-18 22:53:46 -0700 | [diff] [blame] | 525 | 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: |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 529 | self.access_points[i + 1].configure_ap(network_list, |
Girish Moturu | ddb8973 | 2021-01-24 14:11:26 -0800 | [diff] [blame] | 530 | channels_2g[i+1], |
| 531 | channels_5g[i+1]) |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 532 | self.access_points[i + 1].start_ap() |
Hsiu-Chang Chen | 5579e1a | 2020-10-21 10:40:12 +0800 | [diff] [blame] | 533 | self.bssid_map.append( |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 534 | self.access_points[i + 1].get_bssids_for_wifi_networks()) |
Hsiu-Chang Chen | 5579e1a | 2020-10-21 10:40:12 +0800 | [diff] [blame] | 535 | break |
Girish Moturu | 3175865 | 2020-09-22 09:10:48 -0700 | [diff] [blame] | 536 | |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 537 | def legacy_configure_ap_and_start( |
| 538 | self, |
Mark De Ruyter | dee24c2 | 2018-04-13 17:34:44 -0700 | [diff] [blame] | 539 | channel_5g=hostapd_constants.AP_DEFAULT_CHANNEL_5G, |
Bindu Mahadev | 2ebdcec | 2018-05-03 19:51:24 +0000 | [diff] [blame] | 540 | 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 Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 548 | same_ssid=False, |
| 549 | mirror_ap=True, |
Hsiu-Chang Chen | 8106175 | 2018-08-15 13:49:23 +0800 | [diff] [blame] | 550 | wpa_network=False, |
| 551 | wep_network=False, |
Girish Moturu | dcd73f6 | 2018-10-18 09:49:32 -0700 | [diff] [blame] | 552 | ent_network=False, |
| 553 | radius_conf_2g=None, |
| 554 | radius_conf_5g=None, |
Girish Moturu | f1ce420 | 2018-10-20 21:33:00 -0700 | [diff] [blame] | 555 | ent_network_pwd=False, |
| 556 | radius_conf_pwd=None, |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 557 | ap_count=1): |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 558 | |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 559 | config_count = 1 |
| 560 | count = 0 |
| 561 | |
Bindu Mahadev | 9c5a7d2 | 2018-07-16 12:08:35 -0700 | [diff] [blame] | 562 | # 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: |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 565 | raise ValueError("ap_count cannot be 1 if mirror_ap is False.") |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 566 | |
| 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 Chen | 8106175 | 2018-08-15 13:49:23 +0800 | [diff] [blame] | 572 | if wpa_network: |
| 573 | self.user_params["wpa_networks"] = [] |
| 574 | if wep_network: |
| 575 | self.user_params["wep_networks"] = [] |
Girish Moturu | dcd73f6 | 2018-10-18 09:49:32 -0700 | [diff] [blame] | 576 | if ent_network: |
| 577 | self.user_params["ent_networks"] = [] |
Girish Moturu | f1ce420 | 2018-10-20 21:33:00 -0700 | [diff] [blame] | 578 | if ent_network_pwd: |
| 579 | self.user_params["ent_networks_pwd"] = [] |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 580 | |
Girish Moturu | 25e8bb0 | 2019-08-28 17:17:41 -0700 | [diff] [blame] | 581 | # 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 Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 586 | 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 Chen | 8106175 | 2018-08-15 13:49:23 +0800 | [diff] [blame] | 597 | networks_dict = self.get_psk_network( |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 598 | mirror_ap, |
| 599 | self.user_params["reference_networks"], |
| 600 | hidden=hidden, |
| 601 | same_ssid=same_ssid) |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 602 | self.reference_networks = self.user_params["reference_networks"] |
| 603 | |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 604 | network_list_2g.append(networks_dict["2g"]) |
| 605 | network_list_5g.append(networks_dict["5g"]) |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 606 | |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 607 | # 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( |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 614 | mirror_ap, |
| 615 | self.user_params["open_network"], |
| 616 | hidden=hidden, |
| 617 | same_ssid=same_ssid) |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 618 | self.open_network = self.user_params["open_network"] |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 619 | |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 620 | network_list_2g.append(networks_dict["2g"]) |
| 621 | network_list_5g.append(networks_dict["5g"]) |
Bindu Mahadev | 1f227e0 | 2017-07-06 00:24:58 +0000 | [diff] [blame] | 622 | |
Hsiu-Chang Chen | 8106175 | 2018-08-15 13:49:23 +0800 | [diff] [blame] | 623 | if wpa_network: |
| 624 | networks_dict = self.get_psk_network( |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 625 | 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 Chen | 8106175 | 2018-08-15 13:49:23 +0800 | [diff] [blame] | 630 | 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( |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 637 | mirror_ap, |
| 638 | self.user_params["wep_networks"], |
| 639 | hidden=hidden, |
| 640 | same_ssid=same_ssid) |
Hsiu-Chang Chen | 8106175 | 2018-08-15 13:49:23 +0800 | [diff] [blame] | 641 | 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 Moturu | dcd73f6 | 2018-10-18 09:49:32 -0700 | [diff] [blame] | 646 | if ent_network: |
| 647 | networks_dict = self.get_open_network( |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 648 | 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 Moturu | dcd73f6 | 2018-10-18 09:49:32 -0700 | [diff] [blame] | 654 | networks_dict["2g"].update(radius_conf_2g) |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 655 | networks_dict["5g"][ |
| 656 | "security"] = hostapd_constants.ENT_STRING |
Girish Moturu | dcd73f6 | 2018-10-18 09:49:32 -0700 | [diff] [blame] | 657 | 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 Moturu | f1ce420 | 2018-10-20 21:33:00 -0700 | [diff] [blame] | 663 | if ent_network_pwd: |
| 664 | networks_dict = self.get_open_network( |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 665 | 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 Moturu | f1ce420 | 2018-10-20 21:33:00 -0700 | [diff] [blame] | 671 | networks_dict["2g"].update(radius_conf_pwd) |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 672 | networks_dict["5g"][ |
| 673 | "security"] = hostapd_constants.ENT_STRING |
Girish Moturu | f1ce420 | 2018-10-20 21:33:00 -0700 | [diff] [blame] | 674 | networks_dict["5g"].update(radius_conf_pwd) |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 675 | self.ent_networks_pwd = self.user_params[ |
| 676 | "ent_networks_pwd"] |
Girish Moturu | f1ce420 | 2018-10-20 21:33:00 -0700 | [diff] [blame] | 677 | |
| 678 | network_list_2g.append(networks_dict["2g"]) |
| 679 | network_list_5g.append(networks_dict["5g"]) |
| 680 | |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 681 | 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: |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 685 | self.config_5g = self._generate_legacy_ap_config( |
| 686 | network_list_5g) |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 687 | if len(network_list_2g) > 1: |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 688 | self.config_2g = self._generate_legacy_ap_config( |
| 689 | network_list_2g) |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 690 | |
| 691 | self.access_points[count].start_ap(self.config_2g) |
| 692 | self.access_points[count].start_ap(self.config_5g) |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 693 | self.populate_bssid(count, self.access_points[count], |
| 694 | orig_network_list_5g, orig_network_list_2g) |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 695 | |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 696 | # 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], |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 701 | orig_network_list_5g, orig_network_list_2g) |
Bindu Mahadev | e7d47c3 | 2018-07-03 16:48:03 -0700 | [diff] [blame] | 702 | |
Girish Moturu | 27ff0b3 | 2019-08-03 21:44:59 -0700 | [diff] [blame] | 703 | 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'): |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 751 | raise ("Failed to cleanup AP") |
Girish Moturu | 27ff0b3 | 2019-08-03 21:44:59 -0700 | [diff] [blame] | 752 | |
| 753 | ap.__init__(self.user_params['AccessPoint'][count]) |
| 754 | |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 755 | def _generate_legacy_ap_config(self, network_list): |
| 756 | bss_settings = [] |
Bindu Mahadev | 071af26 | 2018-10-17 16:42:06 -0700 | [diff] [blame] | 757 | wlan_2g = self.access_points[AP_1].wlan_2g |
| 758 | wlan_5g = self.access_points[AP_1].wlan_5g |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 759 | ap_settings = network_list.pop(0) |
Bindu Mahadev | 1f227e0 | 2017-07-06 00:24:58 +0000 | [diff] [blame] | 760 | # 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 Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 764 | hostapd_config_settings = network_list.pop(0) |
| 765 | for network in network_list: |
Hsiu-Chang Chen | 8d8bbbf | 2018-08-02 11:37:11 +0800 | [diff] [blame] | 766 | if "password" in network: |
Bindu Mahadev | 1c895c2 | 2018-01-18 18:20:43 -0800 | [diff] [blame] | 767 | bss_settings.append( |
| 768 | hostapd_bss_settings.BssSettings( |
| 769 | name=network["SSID"], |
| 770 | ssid=network["SSID"], |
Hsiu-Chang Chen | 8d8bbbf | 2018-08-02 11:37:11 +0800 | [diff] [blame] | 771 | hidden=network["hiddenSSID"], |
Bindu Mahadev | 1c895c2 | 2018-01-18 18:20:43 -0800 | [diff] [blame] | 772 | security=hostapd_security.Security( |
| 773 | security_mode=network["security"], |
| 774 | password=network["password"]))) |
Hsiu-Chang Chen | 8106175 | 2018-08-15 13:49:23 +0800 | [diff] [blame] | 775 | 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 Moturu | dcd73f6 | 2018-10-18 09:49:32 -0700 | [diff] [blame] | 784 | 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"], |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 794 | radius_server_secret=network[ |
| 795 | "radius_server_secret"]))) |
Hsiu-Chang Chen | 8106175 | 2018-08-15 13:49:23 +0800 | [diff] [blame] | 796 | else: |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 797 | bss_settings.append( |
| 798 | hostapd_bss_settings.BssSettings( |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 799 | name=network["SSID"], |
| 800 | ssid=network["SSID"], |
Hsiu-Chang Chen | 8d8bbbf | 2018-08-02 11:37:11 +0800 | [diff] [blame] | 801 | hidden=network["hiddenSSID"])) |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 802 | if "password" in hostapd_config_settings: |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 803 | config = hostapd_ap_preset.create_ap_preset( |
Bindu Mahadev | 071af26 | 2018-10-17 16:42:06 -0700 | [diff] [blame] | 804 | iface_wlan_2g=wlan_2g, |
| 805 | iface_wlan_5g=wlan_5g, |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 806 | channel=ap_settings["channel"], |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 807 | ssid=hostapd_config_settings["SSID"], |
Hsiu-Chang Chen | 8d8bbbf | 2018-08-02 11:37:11 +0800 | [diff] [blame] | 808 | hidden=hostapd_config_settings["hiddenSSID"], |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 809 | security=hostapd_security.Security( |
| 810 | security_mode=hostapd_config_settings["security"], |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 811 | password=hostapd_config_settings["password"]), |
Bindu Mahadev | 071af26 | 2018-10-17 16:42:06 -0700 | [diff] [blame] | 812 | bss_settings=bss_settings) |
Hsiu-Chang Chen | 8106175 | 2018-08-15 13:49:23 +0800 | [diff] [blame] | 813 | elif "wepKeys" in hostapd_config_settings: |
| 814 | config = hostapd_ap_preset.create_ap_preset( |
Bindu Mahadev | 071af26 | 2018-10-17 16:42:06 -0700 | [diff] [blame] | 815 | iface_wlan_2g=wlan_2g, |
| 816 | iface_wlan_5g=wlan_5g, |
Hsiu-Chang Chen | 8106175 | 2018-08-15 13:49:23 +0800 | [diff] [blame] | 817 | 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 Mahadev | 071af26 | 2018-10-17 16:42:06 -0700 | [diff] [blame] | 823 | bss_settings=bss_settings) |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 824 | else: |
| 825 | config = hostapd_ap_preset.create_ap_preset( |
Bindu Mahadev | 071af26 | 2018-10-17 16:42:06 -0700 | [diff] [blame] | 826 | iface_wlan_2g=wlan_2g, |
| 827 | iface_wlan_5g=wlan_5g, |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 828 | channel=ap_settings["channel"], |
Bindu Mahadev | 72725d1 | 2017-06-05 03:11:30 +0000 | [diff] [blame] | 829 | ssid=hostapd_config_settings["SSID"], |
Hsiu-Chang Chen | 8d8bbbf | 2018-08-02 11:37:11 +0800 | [diff] [blame] | 830 | hidden=hostapd_config_settings["hiddenSSID"], |
Bindu Mahadev | 071af26 | 2018-10-17 16:42:06 -0700 | [diff] [blame] | 831 | bss_settings=bss_settings) |
Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame] | 832 | return config |
Girish Moturu | cf4dccd | 2018-08-27 12:22:00 -0700 | [diff] [blame] | 833 | |
| 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 Moturu | e6ccc7a | 2019-09-19 11:00:21 -0700 | [diff] [blame] | 854 | |
| 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: |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 868 | log_string = "[Test Case] RETRY:%s %s" % (i, |
| 869 | self.test_name) |
Girish Moturu | e6ccc7a | 2019-09-19 11:00:21 -0700 | [diff] [blame] | 870 | 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 | |
tturney | fd69793 | 2020-11-24 11:43:44 -0800 | [diff] [blame] | 897 | return _safe_wrap_test_case |