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