Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Chris Ye | 02c7bb3 | 2022-01-13 12:13:48 -0800 | [diff] [blame] | 16 | #include <android/hardware/wifi/1.0/IWifi.h> |
| 17 | #include <android/hardware/wifi/hostapd/1.3/IHostapd.h> |
| 18 | |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 19 | #include <VtsCoreUtil.h> |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 20 | #include <aidl/Gtest.h> |
| 21 | #include <aidl/Vintf.h> |
Gabriel Biren | b3eb504 | 2021-11-03 19:40:44 +0000 | [diff] [blame] | 22 | #include <aidl/android/hardware/wifi/hostapd/BnHostapd.h> |
| 23 | #include <aidl/android/hardware/wifi/hostapd/BnHostapdCallback.h> |
| 24 | #include <android/binder_manager.h> |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 25 | #include <binder/IServiceManager.h> |
| 26 | #include <binder/ProcessState.h> |
Chris Ye | 02c7bb3 | 2022-01-13 12:13:48 -0800 | [diff] [blame] | 27 | #include <hidl/ServiceManagement.h> |
| 28 | #include <hostapd_hidl_call_util.h> |
| 29 | #include <hostapd_hidl_test_utils.h> |
| 30 | #include <wifi_hidl_test_utils.h> |
| 31 | #include <wifi_hidl_test_utils_1_5.h> |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 32 | |
Gabriel Biren | b3eb504 | 2021-11-03 19:40:44 +0000 | [diff] [blame] | 33 | using aidl::android::hardware::wifi::hostapd::BandMask; |
| 34 | using aidl::android::hardware::wifi::hostapd::BnHostapdCallback; |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 35 | using aidl::android::hardware::wifi::hostapd::ChannelBandwidth; |
Gabriel Biren | b3eb504 | 2021-11-03 19:40:44 +0000 | [diff] [blame] | 36 | using aidl::android::hardware::wifi::hostapd::ChannelParams; |
| 37 | using aidl::android::hardware::wifi::hostapd::DebugLevel; |
| 38 | using aidl::android::hardware::wifi::hostapd::EncryptionType; |
| 39 | using aidl::android::hardware::wifi::hostapd::FrequencyRange; |
| 40 | using aidl::android::hardware::wifi::hostapd::Ieee80211ReasonCode; |
| 41 | using aidl::android::hardware::wifi::hostapd::IfaceParams; |
| 42 | using aidl::android::hardware::wifi::hostapd::IHostapd; |
| 43 | using aidl::android::hardware::wifi::hostapd::NetworkParams; |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 44 | using android::ProcessState; |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 45 | |
| 46 | namespace { |
| 47 | const unsigned char kNwSsid[] = {'t', 'e', 's', 't', '1', '2', '3', '4', '5'}; |
Gabriel Biren | b3eb504 | 2021-11-03 19:40:44 +0000 | [diff] [blame] | 48 | const std::string kPassphrase = "test12345"; |
| 49 | const std::string kInvalidMinPassphrase = "test"; |
| 50 | const std::string kInvalidMaxPassphrase = |
| 51 | "0123456789012345678901234567890123456789012345678901234567890123456789"; |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 52 | const int kIfaceChannel = 6; |
| 53 | const int kIfaceInvalidChannel = 567; |
| 54 | const std::vector<uint8_t> kTestZeroMacAddr(6, 0x0); |
| 55 | const Ieee80211ReasonCode kTestDisconnectReasonCode = |
| 56 | Ieee80211ReasonCode::WLAN_REASON_UNSPECIFIED; |
| 57 | |
| 58 | inline BandMask operator|(BandMask a, BandMask b) { |
| 59 | return static_cast<BandMask>(static_cast<int32_t>(a) | |
| 60 | static_cast<int32_t>(b)); |
| 61 | } |
| 62 | } // namespace |
| 63 | |
| 64 | class HostapdAidl : public testing::TestWithParam<std::string> { |
| 65 | public: |
| 66 | virtual void SetUp() override { |
Gabriel Biren | b3eb504 | 2021-11-03 19:40:44 +0000 | [diff] [blame] | 67 | hostapd = IHostapd::fromBinder(ndk::SpAIBinder( |
| 68 | AServiceManager_waitForService(GetParam().c_str()))); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 69 | ASSERT_NE(hostapd, nullptr); |
| 70 | EXPECT_TRUE(hostapd->setDebugParams(DebugLevel::EXCESSIVE).isOk()); |
| 71 | isAcsSupport = testing::checkSubstringInCommandOutput( |
| 72 | "/system/bin/cmd wifi get-softap-supported-features", |
| 73 | "wifi_softap_acs_supported"); |
| 74 | isWpa3SaeSupport = testing::checkSubstringInCommandOutput( |
| 75 | "/system/bin/cmd wifi get-softap-supported-features", |
| 76 | "wifi_softap_wpa3_sae_supported"); |
| 77 | isBridgedSupport = testing::checkSubstringInCommandOutput( |
| 78 | "/system/bin/cmd wifi get-softap-supported-features", |
| 79 | "wifi_softap_bridged_ap_supported"); |
Chris Ye | 02c7bb3 | 2022-01-13 12:13:48 -0800 | [diff] [blame] | 80 | const std::vector<std::string> instances = android::hardware::getAllHalInstanceNames( |
| 81 | ::android::hardware::wifi::V1_0::IWifi::descriptor); |
| 82 | EXPECT_NE(0, instances.size()); |
| 83 | wifiInstanceName = instances[0]; |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | virtual void TearDown() override { |
Chris Ye | 02c7bb3 | 2022-01-13 12:13:48 -0800 | [diff] [blame] | 87 | if (getWifi(wifiInstanceName) != nullptr) { |
| 88 | stopWifi(wifiInstanceName); |
| 89 | } |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 90 | hostapd->terminate(); |
| 91 | // Wait 3 seconds to allow terminate to complete |
| 92 | sleep(3); |
| 93 | } |
| 94 | |
Gabriel Biren | b3eb504 | 2021-11-03 19:40:44 +0000 | [diff] [blame] | 95 | std::shared_ptr<IHostapd> hostapd; |
Chris Ye | 02c7bb3 | 2022-01-13 12:13:48 -0800 | [diff] [blame] | 96 | std::string wifiInstanceName; |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 97 | bool isAcsSupport; |
| 98 | bool isWpa3SaeSupport; |
| 99 | bool isBridgedSupport; |
| 100 | |
Chris Ye | 02c7bb3 | 2022-01-13 12:13:48 -0800 | [diff] [blame] | 101 | std::string setupApIfaceAndGetName(bool isBridged) { |
| 102 | android::sp<::android::hardware::wifi::V1_0::IWifiApIface> wifi_ap_iface; |
| 103 | if (isBridged) { |
| 104 | wifi_ap_iface = getBridgedWifiApIface_1_5(wifiInstanceName); |
| 105 | } else { |
| 106 | wifi_ap_iface = getWifiApIface_1_5(wifiInstanceName); |
| 107 | } |
| 108 | EXPECT_NE(nullptr, wifi_ap_iface.get()); |
| 109 | |
| 110 | const auto& status_and_name = HIDL_INVOKE(wifi_ap_iface, getName); |
| 111 | EXPECT_EQ(android::hardware::wifi::V1_0::WifiStatusCode::SUCCESS, |
| 112 | status_and_name.first.code); |
| 113 | return status_and_name.second; |
| 114 | } |
| 115 | |
Gabriel Biren | b3eb504 | 2021-11-03 19:40:44 +0000 | [diff] [blame] | 116 | IfaceParams getIfaceParamsWithoutAcs(std::string iface_name) { |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 117 | IfaceParams iface_params; |
| 118 | ChannelParams channelParams; |
| 119 | std::vector<ChannelParams> vec_channelParams; |
| 120 | |
| 121 | iface_params.name = iface_name; |
| 122 | iface_params.hwModeParams.enable80211N = true; |
| 123 | iface_params.hwModeParams.enable80211AC = false; |
| 124 | iface_params.hwModeParams.enable80211AX = false; |
| 125 | iface_params.hwModeParams.enable6GhzBand = false; |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 126 | iface_params.hwModeParams.maximumChannelBandwidth = ChannelBandwidth::BANDWIDTH_20; |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 127 | |
| 128 | channelParams.enableAcs = false; |
| 129 | channelParams.acsShouldExcludeDfs = false; |
| 130 | channelParams.channel = kIfaceChannel; |
| 131 | channelParams.bandMask = BandMask::BAND_2_GHZ; |
| 132 | |
| 133 | vec_channelParams.push_back(channelParams); |
| 134 | iface_params.channelParams = vec_channelParams; |
| 135 | return iface_params; |
| 136 | } |
| 137 | |
Gabriel Biren | b3eb504 | 2021-11-03 19:40:44 +0000 | [diff] [blame] | 138 | IfaceParams getIfaceParamsWithBridgedModeACS(std::string iface_name) { |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 139 | IfaceParams iface_params = getIfaceParamsWithoutAcs(iface_name); |
| 140 | iface_params.channelParams[0].enableAcs = true; |
| 141 | iface_params.channelParams[0].acsShouldExcludeDfs = true; |
| 142 | |
| 143 | std::vector<ChannelParams> vec_channelParams; |
| 144 | vec_channelParams.push_back(iface_params.channelParams[0]); |
| 145 | |
| 146 | ChannelParams second_channelParams; |
| 147 | second_channelParams.channel = 0; |
| 148 | second_channelParams.enableAcs = true; |
| 149 | second_channelParams.bandMask = BandMask::BAND_5_GHZ; |
| 150 | vec_channelParams.push_back(second_channelParams); |
| 151 | |
| 152 | iface_params.channelParams = vec_channelParams; |
| 153 | return iface_params; |
| 154 | } |
| 155 | |
Gabriel Biren | b3eb504 | 2021-11-03 19:40:44 +0000 | [diff] [blame] | 156 | IfaceParams getIfaceParamsWithAcs(std::string iface_name) { |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 157 | IfaceParams iface_params = getIfaceParamsWithoutAcs(iface_name); |
| 158 | iface_params.channelParams[0].enableAcs = true; |
| 159 | iface_params.channelParams[0].acsShouldExcludeDfs = true; |
| 160 | iface_params.channelParams[0].channel = 0; |
| 161 | iface_params.channelParams[0].bandMask = |
| 162 | iface_params.channelParams[0].bandMask | BandMask::BAND_5_GHZ; |
| 163 | return iface_params; |
| 164 | } |
| 165 | |
Gabriel Biren | b3eb504 | 2021-11-03 19:40:44 +0000 | [diff] [blame] | 166 | IfaceParams getIfaceParamsWithAcsAndFreqRange(std::string iface_name) { |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 167 | IfaceParams iface_params = getIfaceParamsWithAcs(iface_name); |
| 168 | FrequencyRange freqRange; |
| 169 | freqRange.startMhz = 2412; |
| 170 | freqRange.endMhz = 2462; |
| 171 | std::vector<FrequencyRange> vec_FrequencyRange; |
| 172 | vec_FrequencyRange.push_back(freqRange); |
| 173 | iface_params.channelParams[0].acsChannelFreqRangesMhz = |
| 174 | vec_FrequencyRange; |
| 175 | return iface_params; |
| 176 | } |
| 177 | |
Gabriel Biren | b3eb504 | 2021-11-03 19:40:44 +0000 | [diff] [blame] | 178 | IfaceParams getIfaceParamsWithAcsAndInvalidFreqRange( |
| 179 | std::string iface_name) { |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 180 | IfaceParams iface_params = |
| 181 | getIfaceParamsWithAcsAndFreqRange(iface_name); |
| 182 | iface_params.channelParams[0].acsChannelFreqRangesMhz[0].startMhz = |
| 183 | 222; |
| 184 | iface_params.channelParams[0].acsChannelFreqRangesMhz[0].endMhz = |
| 185 | 999; |
| 186 | return iface_params; |
| 187 | } |
| 188 | |
Gabriel Biren | b3eb504 | 2021-11-03 19:40:44 +0000 | [diff] [blame] | 189 | IfaceParams getIfaceParamsWithInvalidChannel(std::string iface_name) { |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 190 | IfaceParams iface_params = getIfaceParamsWithoutAcs(iface_name); |
| 191 | iface_params.channelParams[0].channel = kIfaceInvalidChannel; |
| 192 | return iface_params; |
| 193 | } |
| 194 | |
| 195 | NetworkParams getOpenNwParams() { |
| 196 | NetworkParams nw_params; |
| 197 | nw_params.ssid = |
| 198 | std::vector<uint8_t>(kNwSsid, kNwSsid + sizeof(kNwSsid)); |
| 199 | nw_params.isHidden = false; |
| 200 | nw_params.encryptionType = EncryptionType::NONE; |
| 201 | nw_params.isMetered = true; |
| 202 | return nw_params; |
| 203 | } |
| 204 | |
| 205 | NetworkParams getPskNwParamsWithNonMetered() { |
| 206 | NetworkParams nw_params = getOpenNwParams(); |
| 207 | nw_params.encryptionType = EncryptionType::WPA2; |
| 208 | nw_params.passphrase = kPassphrase; |
| 209 | nw_params.isMetered = false; |
| 210 | return nw_params; |
| 211 | } |
| 212 | |
| 213 | NetworkParams getPskNwParams() { |
| 214 | NetworkParams nw_params = getOpenNwParams(); |
| 215 | nw_params.encryptionType = EncryptionType::WPA2; |
| 216 | nw_params.passphrase = kPassphrase; |
| 217 | return nw_params; |
| 218 | } |
| 219 | |
| 220 | NetworkParams getInvalidPskNwParams() { |
| 221 | NetworkParams nw_params = getOpenNwParams(); |
| 222 | nw_params.encryptionType = EncryptionType::WPA2; |
| 223 | nw_params.passphrase = kInvalidMaxPassphrase; |
| 224 | return nw_params; |
| 225 | } |
| 226 | |
| 227 | NetworkParams getSaeTransitionNwParams() { |
| 228 | NetworkParams nw_params = getOpenNwParams(); |
| 229 | nw_params.encryptionType = EncryptionType::WPA3_SAE_TRANSITION; |
| 230 | nw_params.passphrase = kPassphrase; |
| 231 | return nw_params; |
| 232 | } |
| 233 | |
| 234 | NetworkParams getInvalidSaeTransitionNwParams() { |
| 235 | NetworkParams nw_params = getOpenNwParams(); |
| 236 | nw_params.encryptionType = EncryptionType::WPA2; |
| 237 | nw_params.passphrase = kInvalidMinPassphrase; |
| 238 | return nw_params; |
| 239 | } |
| 240 | |
| 241 | NetworkParams getSaeNwParams() { |
| 242 | NetworkParams nw_params = getOpenNwParams(); |
| 243 | nw_params.encryptionType = EncryptionType::WPA3_SAE; |
| 244 | nw_params.passphrase = kPassphrase; |
| 245 | return nw_params; |
| 246 | } |
| 247 | |
| 248 | NetworkParams getInvalidSaeNwParams() { |
| 249 | NetworkParams nw_params = getOpenNwParams(); |
| 250 | nw_params.encryptionType = EncryptionType::WPA3_SAE; |
Gabriel Biren | b3eb504 | 2021-11-03 19:40:44 +0000 | [diff] [blame] | 251 | nw_params.passphrase = ""; |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 252 | return nw_params; |
| 253 | } |
| 254 | }; |
| 255 | |
Gabriel Biren | b3eb504 | 2021-11-03 19:40:44 +0000 | [diff] [blame] | 256 | class HostapdCallback : public BnHostapdCallback { |
| 257 | public: |
| 258 | HostapdCallback() = default; |
| 259 | ::ndk::ScopedAStatus onApInstanceInfoChanged( |
| 260 | const ::aidl::android::hardware::wifi::hostapd::ApInfo &) override { |
| 261 | return ndk::ScopedAStatus::ok(); |
| 262 | } |
| 263 | ::ndk::ScopedAStatus onConnectedClientsChanged( |
| 264 | const ::aidl::android::hardware::wifi::hostapd::ClientInfo &) override { |
| 265 | return ndk::ScopedAStatus::ok(); |
| 266 | } |
Les Lee | 6645e9e | 2021-10-29 16:04:23 +0800 | [diff] [blame] | 267 | ::ndk::ScopedAStatus onFailure(const std::string&, const std::string&) override { |
Gabriel Biren | b3eb504 | 2021-11-03 19:40:44 +0000 | [diff] [blame] | 268 | return ndk::ScopedAStatus::ok(); |
| 269 | } |
| 270 | }; |
| 271 | |
| 272 | /** |
| 273 | * Register callback |
| 274 | */ |
| 275 | TEST_P(HostapdAidl, RegisterCallback) { |
| 276 | std::shared_ptr<HostapdCallback> callback = |
| 277 | ndk::SharedRefBase::make<HostapdCallback>(); |
| 278 | ASSERT_NE(callback, nullptr); |
| 279 | EXPECT_TRUE(hostapd->registerCallback(callback).isOk()); |
| 280 | } |
| 281 | |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 282 | /** |
| 283 | * Adds an access point with PSK network config & ACS enabled. |
| 284 | * Access point creation should pass. |
| 285 | */ |
| 286 | TEST_P(HostapdAidl, AddPskAccessPointWithAcs) { |
| 287 | if (!isAcsSupport) GTEST_SKIP() << "Missing ACS support"; |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 288 | std::string ifname = setupApIfaceAndGetName(false); |
| 289 | auto status = hostapd->addAccessPoint(getIfaceParamsWithAcs(ifname), getPskNwParams()); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 290 | EXPECT_TRUE(status.isOk()); |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Adds an access point with PSK network config, ACS enabled & frequency Range. |
| 295 | * Access point creation should pass. |
| 296 | */ |
| 297 | TEST_P(HostapdAidl, AddPskAccessPointWithAcsAndFreqRange) { |
| 298 | if (!isAcsSupport) GTEST_SKIP() << "Missing ACS support"; |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 299 | std::string ifname = setupApIfaceAndGetName(false); |
| 300 | auto status = |
| 301 | hostapd->addAccessPoint(getIfaceParamsWithAcsAndFreqRange(ifname), getPskNwParams()); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 302 | EXPECT_TRUE(status.isOk()); |
| 303 | } |
| 304 | |
| 305 | /** |
| 306 | * Adds an access point with invalid channel range. |
| 307 | * Access point creation should fail. |
| 308 | */ |
| 309 | TEST_P(HostapdAidl, AddPskAccessPointWithAcsAndInvalidFreqRange) { |
| 310 | if (!isAcsSupport) GTEST_SKIP() << "Missing ACS support"; |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 311 | std::string ifname = setupApIfaceAndGetName(false); |
| 312 | auto status = hostapd->addAccessPoint(getIfaceParamsWithAcsAndInvalidFreqRange(ifname), |
| 313 | getPskNwParams()); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 314 | EXPECT_FALSE(status.isOk()); |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * Adds an access point with Open network config & ACS enabled. |
| 319 | * Access point creation should pass. |
| 320 | */ |
| 321 | TEST_P(HostapdAidl, AddOpenAccessPointWithAcs) { |
| 322 | if (!isAcsSupport) GTEST_SKIP() << "Missing ACS support"; |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 323 | std::string ifname = setupApIfaceAndGetName(false); |
| 324 | auto status = hostapd->addAccessPoint(getIfaceParamsWithAcs(ifname), getOpenNwParams()); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 325 | EXPECT_TRUE(status.isOk()); |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Adds an access point with PSK network config & ACS disabled. |
| 330 | * Access point creation should pass. |
| 331 | */ |
| 332 | TEST_P(HostapdAidl, AddPskAccessPointWithoutAcs) { |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 333 | std::string ifname = setupApIfaceAndGetName(false); |
| 334 | auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), getPskNwParams()); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 335 | EXPECT_TRUE(status.isOk()); |
| 336 | } |
| 337 | |
| 338 | /** |
| 339 | * Adds an access point with PSK network config, ACS disabled & Non metered. |
| 340 | * Access point creation should pass. |
| 341 | */ |
| 342 | TEST_P(HostapdAidl, AddPskAccessPointWithoutAcsAndNonMetered) { |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 343 | std::string ifname = setupApIfaceAndGetName(false); |
| 344 | auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 345 | getPskNwParamsWithNonMetered()); |
| 346 | EXPECT_TRUE(status.isOk()); |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Adds an access point with Open network config & ACS disabled. |
| 351 | * Access point creation should pass. |
| 352 | */ |
| 353 | TEST_P(HostapdAidl, AddOpenAccessPointWithoutAcs) { |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 354 | std::string ifname = setupApIfaceAndGetName(false); |
| 355 | auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), getOpenNwParams()); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 356 | EXPECT_TRUE(status.isOk()); |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * Adds an access point with SAE Transition network config & ACS disabled. |
| 361 | * Access point creation should pass. |
| 362 | */ |
| 363 | TEST_P(HostapdAidl, AddSaeTransitionAccessPointWithoutAcs) { |
| 364 | if (!isWpa3SaeSupport) GTEST_SKIP() << "Missing SAE support"; |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 365 | std::string ifname = setupApIfaceAndGetName(false); |
| 366 | auto status = |
| 367 | hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), getSaeTransitionNwParams()); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 368 | EXPECT_TRUE(status.isOk()); |
| 369 | } |
| 370 | |
| 371 | /** |
| 372 | * Adds an access point with SAE network config & ACS disabled. |
| 373 | * Access point creation should pass. |
| 374 | */ |
| 375 | TEST_P(HostapdAidl, AddSAEAccessPointWithoutAcs) { |
| 376 | if (!isWpa3SaeSupport) GTEST_SKIP() << "Missing SAE support"; |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 377 | std::string ifname = setupApIfaceAndGetName(false); |
| 378 | auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), getSaeNwParams()); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 379 | EXPECT_TRUE(status.isOk()); |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * Adds & then removes an access point with PSK network config & ACS enabled. |
| 384 | * Access point creation & removal should pass. |
| 385 | */ |
| 386 | TEST_P(HostapdAidl, RemoveAccessPointWithAcs) { |
| 387 | if (!isAcsSupport) GTEST_SKIP() << "Missing ACS support"; |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 388 | std::string ifname = setupApIfaceAndGetName(false); |
| 389 | auto status = hostapd->addAccessPoint(getIfaceParamsWithAcs(ifname), getPskNwParams()); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 390 | EXPECT_TRUE(status.isOk()); |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 391 | EXPECT_TRUE(hostapd->removeAccessPoint(ifname).isOk()); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Adds & then removes an access point with PSK network config & ACS disabled. |
| 396 | * Access point creation & removal should pass. |
| 397 | */ |
| 398 | TEST_P(HostapdAidl, RemoveAccessPointWithoutAcs) { |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 399 | std::string ifname = setupApIfaceAndGetName(false); |
| 400 | auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), getPskNwParams()); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 401 | EXPECT_TRUE(status.isOk()); |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 402 | EXPECT_TRUE(hostapd->removeAccessPoint(ifname).isOk()); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | /** |
| 406 | * Adds an access point with invalid channel. |
| 407 | * Access point creation should fail. |
| 408 | */ |
| 409 | TEST_P(HostapdAidl, AddPskAccessPointWithInvalidChannel) { |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 410 | std::string ifname = setupApIfaceAndGetName(false); |
| 411 | auto status = |
| 412 | hostapd->addAccessPoint(getIfaceParamsWithInvalidChannel(ifname), getPskNwParams()); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 413 | EXPECT_FALSE(status.isOk()); |
| 414 | } |
| 415 | |
| 416 | /** |
| 417 | * Adds an access point with invalid PSK network config. |
| 418 | * Access point creation should fail. |
| 419 | */ |
| 420 | TEST_P(HostapdAidl, AddInvalidPskAccessPointWithoutAcs) { |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 421 | std::string ifname = setupApIfaceAndGetName(false); |
| 422 | auto status = |
| 423 | hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), getInvalidPskNwParams()); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 424 | EXPECT_FALSE(status.isOk()); |
| 425 | } |
| 426 | |
| 427 | /** |
| 428 | * Adds an access point with invalid SAE transition network config. |
| 429 | * Access point creation should fail. |
| 430 | */ |
| 431 | TEST_P(HostapdAidl, AddInvalidSaeTransitionAccessPointWithoutAcs) { |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 432 | std::string ifname = setupApIfaceAndGetName(false); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 433 | if (!isWpa3SaeSupport) GTEST_SKIP() << "Missing SAE support"; |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 434 | auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 435 | getInvalidSaeTransitionNwParams()); |
| 436 | EXPECT_FALSE(status.isOk()); |
| 437 | } |
| 438 | |
| 439 | /** |
| 440 | * Adds an access point with invalid SAE network config. |
| 441 | * Access point creation should fail. |
| 442 | */ |
| 443 | TEST_P(HostapdAidl, AddInvalidSaeAccessPointWithoutAcs) { |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 444 | std::string ifname = setupApIfaceAndGetName(false); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 445 | if (!isWpa3SaeSupport) GTEST_SKIP() << "Missing SAE support"; |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 446 | auto status = |
| 447 | hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), getInvalidSaeNwParams()); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 448 | EXPECT_FALSE(status.isOk()); |
| 449 | } |
| 450 | |
| 451 | /** |
| 452 | * forceClientDisconnect should fail when hotspot interface available. |
| 453 | */ |
| 454 | TEST_P(HostapdAidl, DisconnectClientWhenIfacAvailable) { |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 455 | std::string ifname = setupApIfaceAndGetName(false); |
| 456 | auto status = hostapd->addAccessPoint(getIfaceParamsWithoutAcs(ifname), getOpenNwParams()); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 457 | EXPECT_TRUE(status.isOk()); |
| 458 | |
Chris Ye | c04af1c | 2022-03-28 18:42:23 -0700 | [diff] [blame^] | 459 | status = hostapd->forceClientDisconnect(ifname, kTestZeroMacAddr, kTestDisconnectReasonCode); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 460 | EXPECT_FALSE(status.isOk()); |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * AddAccessPointWithDualBandConfig should pass |
| 465 | */ |
| 466 | TEST_P(HostapdAidl, AddAccessPointWithDualBandConfig) { |
| 467 | if (!isBridgedSupport) GTEST_SKIP() << "Missing Bridged AP support"; |
Chris Ye | 02c7bb3 | 2022-01-13 12:13:48 -0800 | [diff] [blame] | 468 | std::string ifname = setupApIfaceAndGetName(true); |
| 469 | auto status = |
| 470 | hostapd->addAccessPoint(getIfaceParamsWithBridgedModeACS(ifname), getOpenNwParams()); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 471 | EXPECT_TRUE(status.isOk()); |
| 472 | } |
| 473 | |
Gabriel Biren | 962d5df | 2022-01-12 23:15:17 +0000 | [diff] [blame] | 474 | GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(HostapdAidl); |
Chris Ye | d13f7b5 | 2021-06-24 12:52:55 -0700 | [diff] [blame] | 475 | INSTANTIATE_TEST_SUITE_P( |
| 476 | Hostapd, HostapdAidl, |
| 477 | testing::ValuesIn(android::getAidlHalInstanceNames(IHostapd::descriptor)), |
| 478 | android::PrintInstanceNameToString); |
| 479 | |
| 480 | int main(int argc, char **argv) { |
| 481 | ::testing::InitGoogleTest(&argc, argv); |
| 482 | ProcessState::self()->setThreadPoolMaxThreadCount(1); |
| 483 | ProcessState::self()->startThreadPool(); |
| 484 | return RUN_ALL_TESTS(); |
| 485 | } |