1 /* 2 * Copyright (C) 2023 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 */ 16 17 #pragma once 18 19 #include <android-base/logging.h> 20 21 #include "hostapd_hidl_test_utils.h" 22 #include "wifi_hidl_test_utils.h" 23 24 using ::android::hardware::wifi::V1_0::WifiStatus; 25 26 namespace { 27 getWifiInstanceName()28std::string getWifiInstanceName() { 29 const std::vector<std::string> instances = android::hardware::getAllHalInstanceNames( 30 ::android::hardware::wifi::V1_0::IWifi::descriptor); 31 EXPECT_NE(0, instances.size()); 32 return instances.size() != 0 ? instances[0] : ""; 33 } 34 35 } // namespace 36 37 namespace HostapdLegacyTestUtils { 38 startAndConfigureVendorHal()39void startAndConfigureVendorHal() { 40 initializeDriverAndFirmware(getWifiInstanceName()); 41 } 42 stopVendorHal()43void stopVendorHal() { 44 deInitializeDriverAndFirmware(getWifiInstanceName()); 45 } 46 setupApIfaceAndGetName(bool isBridged)47std::string setupApIfaceAndGetName(bool isBridged) { 48 android::sp<::android::hardware::wifi::V1_0::IWifiApIface> wifi_ap_iface; 49 if (isBridged) { 50 wifi_ap_iface = getBridgedWifiApIface_1_6(getWifiInstanceName()); 51 } else { 52 wifi_ap_iface = getWifiApIface_1_5(getWifiInstanceName()); 53 } 54 55 EXPECT_TRUE(wifi_ap_iface.get() != nullptr); 56 if (!wifi_ap_iface.get()) { 57 LOG(ERROR) << "Unable to create iface. isBridged=" << isBridged; 58 return ""; 59 } 60 61 const auto& status_and_name = HIDL_INVOKE(wifi_ap_iface, getName); 62 EXPECT_TRUE(status_and_name.first.code == 63 android::hardware::wifi::V1_0::WifiStatusCode::SUCCESS); 64 if (status_and_name.first.code != android::hardware::wifi::V1_0::WifiStatusCode::SUCCESS) { 65 LOG(ERROR) << "Unable to retrieve iface name. isBridged=" << isBridged; 66 return ""; 67 } 68 return status_and_name.second; 69 } 70 71 } // namespace HostapdLegacyTestUtils 72