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 <aidl/android/hardware/wifi/IWifi.h> 20 #include <android-base/logging.h> 21 22 #include "wifi_aidl_test_utils.h" 23 24 namespace { 25 26 const std::string kWifiInstanceNameStr = std::string() + IWifi::descriptor + "/default"; 27 const char* kWifiInstanceName = kWifiInstanceNameStr.c_str(); 28 29 } // namespace 30 31 namespace HostapdAidlTestUtils { 32 useAidlService()33bool useAidlService() { 34 return isAidlServiceAvailable(kWifiInstanceName); 35 } 36 startAndConfigureVendorHal()37void startAndConfigureVendorHal() { 38 if (getWifi(kWifiInstanceName) != nullptr) { 39 std::shared_ptr<IWifiChip> wifi_chip = getWifiChip(kWifiInstanceName); 40 int mode_id; 41 EXPECT_TRUE(configureChipToSupportConcurrencyType(wifi_chip, IfaceConcurrencyType::AP, 42 &mode_id)); 43 } else { 44 LOG(ERROR) << "Unable to initialize Vendor HAL"; 45 } 46 } 47 stopVendorHal()48void stopVendorHal() { 49 if (getWifi(kWifiInstanceName) != nullptr) { 50 stopWifiService(kWifiInstanceName); 51 } else { 52 LOG(ERROR) << "Unable to stop Vendor HAL"; 53 } 54 } 55 setupApIfaceAndGetName(bool isBridged)56std::string setupApIfaceAndGetName(bool isBridged) { 57 std::shared_ptr<IWifiApIface> wifi_ap_iface; 58 if (isBridged) { 59 wifi_ap_iface = getBridgedWifiApIface(kWifiInstanceName); 60 } else { 61 wifi_ap_iface = getWifiApIface(kWifiInstanceName); 62 } 63 64 EXPECT_TRUE(wifi_ap_iface.get() != nullptr); 65 if (!wifi_ap_iface.get()) { 66 LOG(ERROR) << "Unable to create iface. isBridged=" << isBridged; 67 return ""; 68 } 69 70 std::string ap_iface_name; 71 auto status = wifi_ap_iface->getName(&ap_iface_name); 72 EXPECT_TRUE(status.isOk()); 73 if (!status.isOk()) { 74 LOG(ERROR) << "Unable to retrieve iface name. isBridged=" << isBridged; 75 return ""; 76 } 77 return ap_iface_name; 78 } 79 80 } // namespace HostapdAidlTestUtils 81