diff options
author | Gabriel Biren <gbiren@google.com> | 2021-10-26 21:00:47 +0000 |
---|---|---|
committer | Gabriel Biren <gbiren@google.com> | 2021-12-14 23:45:07 +0000 |
commit | 28a4812752d834547aa32836a4eefde5ed76956e (patch) | |
tree | 804d4287546fbdcc9b1b6024431dad75cfe1c5a7 /wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h | |
parent | 391a7723003d1bfd3f52aa9e663abf1a23adf4a6 (diff) |
Add Wifi HAL supplicant AIDL interface definitions.
Converted from android.hardware.wifi.supplicant@1.4 HIDL interface.
Bug: 196235436
Test: m android.hardware.wifi.supplicant-update-api
BYPASS_INCLUSIVE_LANGUAGE_REASON=HE refers to High Efficiency
Change-Id: I9872f297450457c347fb5fe8cf4005b01d3ab1f6
Diffstat (limited to 'wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h')
-rw-r--r-- | wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h b/wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h new file mode 100644 index 0000000000..b7e1a800b7 --- /dev/null +++ b/wifi/supplicant/aidl/vts/functional/supplicant_test_utils.h @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SUPPLICANT_TEST_UTILS_H +#define SUPPLICANT_TEST_UTILS_H + +#include <VtsCoreUtil.h> +#include <android-base/logging.h> +#include <wifi_system/supplicant_manager.h> + +using aidl::android::hardware::wifi::supplicant::ISupplicantStaIface; +using aidl::android::hardware::wifi::supplicant::KeyMgmtMask; +using android::wifi_system::SupplicantManager; + +std::string getStaIfaceName() { + std::array<char, PROPERTY_VALUE_MAX> buffer; + property_get("wifi.interface", buffer.data(), "wlan0"); + return std::string(buffer.data()); +} + +std::string getP2pIfaceName() { + std::array<char, PROPERTY_VALUE_MAX> buffer; + property_get("wifi.direct.interface", buffer.data(), "p2p0"); + return std::string(buffer.data()); +} + +bool keyMgmtSupported(std::shared_ptr<ISupplicantStaIface> iface, + KeyMgmtMask expected) { + KeyMgmtMask caps; + if (!iface->getKeyMgmtCapabilities(&caps).isOk()) { + return false; + } + return !!(static_cast<uint32_t>(caps) & static_cast<uint32_t>(expected)); +} + +bool isFilsSupported(std::shared_ptr<ISupplicantStaIface> iface) { + KeyMgmtMask filsMask = static_cast<KeyMgmtMask>( + static_cast<uint32_t>(KeyMgmtMask::FILS_SHA256) | + static_cast<uint32_t>(KeyMgmtMask::FILS_SHA384)); + return keyMgmtSupported(iface, filsMask); +} + +bool waitForSupplicantState(bool is_running) { + SupplicantManager supplicant_manager; + int count = 50; /* wait at most 5 seconds for completion */ + while (count-- > 0) { + if (supplicant_manager.IsSupplicantRunning() == is_running) { + return true; + } + usleep(100000); + } + LOG(ERROR) << "Supplicant not " << (is_running ? "running" : "stopped"); + return false; +} + +bool waitForFrameworkReady() { + int waitCount = 15; + do { + // Check whether package service is ready or not. + if (!testing::checkSubstringInCommandOutput( + "/system/bin/service check package", ": not found")) { + return true; + } + LOG(INFO) << "Framework is not ready"; + sleep(1); + } while (waitCount-- > 0); + return false; +} + +bool waitForSupplicantStart() { return waitForSupplicantState(true); } + +bool waitForSupplicantStop() { return waitForSupplicantState(false); } + +void stopSupplicant() { + SupplicantManager supplicant_manager; + ASSERT_TRUE(supplicant_manager.StopSupplicant()); + ASSERT_FALSE(supplicant_manager.IsSupplicantRunning()); +} + +bool startWifiFramework() { + std::system("svc wifi enable"); + std::system("cmd wifi set-scan-always-available enabled"); + return waitForSupplicantStart(); +} + +bool stopWifiFramework() { + std::system("svc wifi disable"); + std::system("cmd wifi set-scan-always-available disabled"); + return waitForSupplicantStop(); +} + +void initializeService() { + ASSERT_TRUE(stopWifiFramework()); + std::system("/system/bin/start"); + ASSERT_TRUE(waitForFrameworkReady()); + stopSupplicant(); +} + +#endif // SUPPLICANT_TEST_UTILS_H
\ No newline at end of file |