Joe Brennan | 8c24a81 | 2017-04-13 14:27:05 -0700 | [diff] [blame^] | 1 | #!/usr/bin/env python3.4 |
| 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. |
| 16 | """ |
| 17 | Base Class for Defining Common WiFi Test Functionality |
| 18 | """ |
| 19 | |
| 20 | from acts import asserts |
| 21 | from acts import utils |
| 22 | from acts.base_test import BaseTestClass |
| 23 | from acts.signals import TestSignal |
| 24 | from acts.controllers import android_device |
| 25 | from acts.controllers.ap_lib import hostapd_ap_preset |
| 26 | from acts.controllers.ap_lib import hostapd_bss_settings |
| 27 | from acts.controllers.ap_lib import hostapd_constants |
| 28 | from acts.controllers.ap_lib import hostapd_security |
| 29 | |
| 30 | |
| 31 | class WifiBaseTest(BaseTestClass): |
| 32 | def __init__(self, controllers): |
| 33 | BaseTestClass.__init__(self, controllers) |
| 34 | |
| 35 | def legacy_configure_ap_and_start( |
| 36 | self, |
| 37 | channel_5g=hostapd_constants.AP_DEFAULT_CHANNEL_5G, |
| 38 | channel_2g=hostapd_constants.AP_DEFAULT_CHANNEL_2G, |
| 39 | max_2g_networks=hostapd_constants.AP_DEFAULT_MAX_SSIDS_2G, |
| 40 | max_5g_networks=hostapd_constants.AP_DEFAULT_MAX_SSIDS_5G, |
| 41 | ap_ssid_length_2g=hostapd_constants.AP_SSID_LENGTH_2G, |
| 42 | ap_passphrase_length_2g=hostapd_constants.AP_PASSPHRASE_LENGTH_2G, |
| 43 | ap_ssid_length_5g=hostapd_constants.AP_SSID_LENGTH_5G, |
| 44 | ap_passphrase_length_5g=hostapd_constants.AP_PASSPHRASE_LENGTH_5G, |
| 45 | ): |
| 46 | asserts.assert_true( |
| 47 | len(self.user_params["AccessPoint"]) == 2, |
| 48 | "Exactly two access points must be specified. \ |
| 49 | If the access point has two radios, the configuration \ |
| 50 | can be repeated for the second radio.") |
| 51 | network_list_2g = [] |
| 52 | network_list_5g = [] |
| 53 | self.access_point_2g = self.access_points[0] |
| 54 | self.access_point_5g = self.access_points[1] |
| 55 | network_list_2g.append({"channel": channel_2g}) |
| 56 | network_list_5g.append({"channel": channel_5g}) |
| 57 | |
| 58 | if "reference_networks" in self.user_params: |
| 59 | pass |
| 60 | else: |
| 61 | ref_5g_security = hostapd_constants.WPA2_STRING |
| 62 | ref_2g_security = hostapd_constants.WPA2_STRING |
| 63 | self.user_params["reference_networks"] = [] |
| 64 | for x in range(0, 2): |
| 65 | ref_2g_ssid = '2g_%s' % utils.rand_ascii_str(ap_ssid_length_2g) |
| 66 | ref_2g_passphrase = utils.rand_ascii_str( |
| 67 | ap_passphrase_length_2g) |
| 68 | ref_5g_ssid = '5g_%s' % utils.rand_ascii_str(ap_ssid_length_5g) |
| 69 | ref_5g_passphrase = utils.rand_ascii_str( |
| 70 | ap_passphrase_length_5g) |
| 71 | network_list_2g.append({ |
| 72 | "ssid": ref_2g_ssid, |
| 73 | "security": ref_2g_security, |
| 74 | "passphrase": ref_2g_passphrase |
| 75 | }) |
| 76 | network_list_5g.append({ |
| 77 | "ssid": ref_5g_ssid, |
| 78 | "security": ref_5g_security, |
| 79 | "passphrase": ref_5g_passphrase |
| 80 | }) |
| 81 | self.user_params["reference_networks"].append({ |
| 82 | "2g": { |
| 83 | "SSID": ref_2g_ssid, |
| 84 | "password": ref_2g_passphrase |
| 85 | }, |
| 86 | "5g": { |
| 87 | "SSID": ref_5g_ssid, |
| 88 | "password": ref_5g_passphrase |
| 89 | } |
| 90 | }) |
| 91 | self.reference_networks = self.user_params["reference_networks"] |
| 92 | |
| 93 | if "open_network" in self.user_params: |
| 94 | pass |
| 95 | else: |
| 96 | self.user_params["open_network"] = [] |
| 97 | open_2g_ssid = '2g_%s' % utils.rand_ascii_str(8) |
| 98 | network_list_2g.append({"ssid": open_2g_ssid, "security": 'none'}) |
| 99 | self.user_params["open_network"] = {"SSID": open_2g_ssid} |
| 100 | self.open_network = self.user_params["open_network"] |
| 101 | |
| 102 | if "config_store_networks" in self.user_params: |
| 103 | pass |
| 104 | else: |
| 105 | self.user_params["config_store_networks"] = [] |
| 106 | self.user_params["config_store_networks"].append(self.open_network) |
| 107 | config_store_2g_security = 'wpa2' |
| 108 | for x in range(0, 4): |
| 109 | config_store_2g_ssid = '2g_%s' % utils.rand_ascii_str(8) |
| 110 | config_store_2g_passphrase = utils.rand_ascii_str(10) |
| 111 | network_list_2g.append({ |
| 112 | "ssid": config_store_2g_ssid, |
| 113 | "security": config_store_2g_security, |
| 114 | "passphrase": config_store_2g_passphrase |
| 115 | }) |
| 116 | self.user_params["config_store_networks"].append({ |
| 117 | "SSID": config_store_2g_ssid, |
| 118 | "password": config_store_2g_passphrase |
| 119 | }) |
| 120 | self.config_store_networks = self.user_params[ |
| 121 | "config_store_networks"] |
| 122 | |
| 123 | if "iot_networks" in self.user_params: |
| 124 | pass |
| 125 | else: |
| 126 | self.user_params["iot_networks"] = [] |
| 127 | for iot_network in self.config_store_networks: |
| 128 | if "password" in iot_network: |
| 129 | self.user_params["iot_networks"].append(iot_network) |
| 130 | iot_2g_security = 'wpa2' |
| 131 | for iot_network_2g in range( |
| 132 | 0, (max_2g_networks - len(network_list_2g)) + 1): |
| 133 | iot_2g_ssid = '2g_%s' % utils.rand_ascii_str(8) |
| 134 | iot_2g_passphrase = utils.rand_ascii_str(10) |
| 135 | network_list_2g.append({ |
| 136 | "ssid": iot_2g_ssid, |
| 137 | "security": iot_2g_security, |
| 138 | "passphrase": iot_2g_passphrase |
| 139 | }) |
| 140 | self.user_params["iot_networks"].append({ |
| 141 | "SSID": iot_2g_ssid, |
| 142 | "password": iot_2g_passphrase |
| 143 | }) |
| 144 | iot_5g_security = 'wpa2' |
| 145 | for iot_network_5g in range( |
| 146 | 0, (max_5g_networks - len(network_list_5g)) + 1): |
| 147 | iot_5g_ssid = '5g_%s' % utils.rand_ascii_str(8) |
| 148 | iot_5g_passphrase = utils.rand_ascii_str(10) |
| 149 | network_list_5g.append({ |
| 150 | "ssid": iot_5g_ssid, |
| 151 | "security": iot_5g_security, |
| 152 | "passphrase": iot_5g_passphrase |
| 153 | }) |
| 154 | self.user_params["iot_networks"].append({ |
| 155 | "SSID": iot_5g_ssid, |
| 156 | "password": iot_5g_passphrase |
| 157 | }) |
| 158 | self.iot_networks = self.user_params["iot_networks"] |
| 159 | |
| 160 | if len(network_list_5g) > 1: |
| 161 | self.config_5g = self._generate_legacy_ap_config(network_list_5g) |
| 162 | self.access_point_5g.start_ap(self.config_5g) |
| 163 | |
| 164 | if len(network_list_2g) > 1: |
| 165 | self.config_2g = self._generate_legacy_ap_config(network_list_2g) |
| 166 | self.access_point_2g.start_ap(self.config_2g) |
| 167 | |
| 168 | def _generate_legacy_ap_config(self, network_list): |
| 169 | bss_settings = [] |
| 170 | ap_settings = network_list.pop(0) |
| 171 | hostapd_config_settings = network_list.pop(0) |
| 172 | for network in network_list: |
| 173 | if "passphrase" in network: |
| 174 | bss_settings.append( |
| 175 | hostapd_bss_settings.BssSettings( |
| 176 | name=network["ssid"], |
| 177 | ssid=network["ssid"], |
| 178 | security=hostapd_security.Security( |
| 179 | security_mode=network["security"], |
| 180 | password=network["passphrase"]))) |
| 181 | else: |
| 182 | bss_settings.append( |
| 183 | hostapd_bss_settings.BssSettings( |
| 184 | name=network["ssid"], ssid=network["ssid"])) |
| 185 | if "passphrase" in hostapd_config_settings: |
| 186 | config = hostapd_ap_preset.create_ap_preset( |
| 187 | channel=ap_settings["channel"], |
| 188 | ssid=hostapd_config_settings["ssid"], |
| 189 | security=hostapd_security.Security( |
| 190 | security_mode=hostapd_config_settings["security"], |
| 191 | password=hostapd_config_settings["passphrase"]), |
| 192 | bss_settings=bss_settings, |
| 193 | profile_name='whirlwind') |
| 194 | else: |
| 195 | config = hostapd_ap_preset.create_ap_preset( |
| 196 | channel=ap_settings["channel"], |
| 197 | ssid=hostapd_config_settings["ssid"], |
| 198 | bss_settings=bss_settings, |
| 199 | profile_name='whirlwind') |
| 200 | |
| 201 | return config |