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