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 #include <VtsHalHidlTargetCallbackBase.h>
18
19 #undef NAN // NAN is defined in bionic/libc/include/math.h:38
20
21 #include <android/hardware/wifi/1.5/IWifiApIface.h>
22 #include <android/hardware/wifi/1.6/IWifiChip.h>
23 #include <gtest/gtest.h>
24 #include <hidl/GtestPrinter.h>
25 #include <hidl/ServiceManagement.h>
26
27 #include "wifi_hidl_call_util.h"
28 #include "wifi_hidl_test_utils.h"
29
30 using ::android::sp;
31 using ::android::hardware::wifi::V1_0::ChipModeId;
32 using ::android::hardware::wifi::V1_0::WifiStatusCode;
33 using ::android::hardware::wifi::V1_5::IWifiApIface;
34 using ::android::hardware::wifi::V1_6::IfaceConcurrencyType;
35 using ::android::hardware::wifi::V1_6::IWifiChip;
36
37 namespace {
38
findAnyModeSupportingConcurrencyType(IfaceConcurrencyType desired_type,const std::vector<IWifiChip::ChipMode> & modes,ChipModeId * mode_id)39 bool findAnyModeSupportingConcurrencyType(IfaceConcurrencyType desired_type,
40 const std::vector<IWifiChip::ChipMode>& modes,
41 ChipModeId* mode_id) {
42 for (const auto& mode : modes) {
43 for (const auto& combination : mode.availableCombinations) {
44 for (const auto& iface_limit : combination.limits) {
45 const auto& iface_types = iface_limit.types;
46 if (std::find(iface_types.begin(), iface_types.end(), desired_type) !=
47 iface_types.end()) {
48 *mode_id = mode.id;
49 return true;
50 }
51 }
52 }
53 }
54 return false;
55 }
56
configureChipToSupportConcurrencyType(const sp<IWifiChip> & wifi_chip,IfaceConcurrencyType type,ChipModeId * configured_mode_id)57 bool configureChipToSupportConcurrencyType(const sp<IWifiChip>& wifi_chip,
58 IfaceConcurrencyType type,
59 ChipModeId* configured_mode_id) {
60 const auto& status_and_modes = HIDL_INVOKE(wifi_chip, getAvailableModes_1_6);
61 if (status_and_modes.first.code != WifiStatusCode::SUCCESS) {
62 return false;
63 }
64 if (!findAnyModeSupportingConcurrencyType(type, status_and_modes.second, configured_mode_id)) {
65 return false;
66 }
67 if (HIDL_INVOKE(wifi_chip, configureChip, *configured_mode_id).code !=
68 WifiStatusCode::SUCCESS) {
69 return false;
70 }
71 return true;
72 }
73
getWifiChip_1_6(const std::string & instance_name)74 sp<IWifiChip> getWifiChip_1_6(const std::string& instance_name) {
75 return IWifiChip::castFrom(getWifiChip(instance_name));
76 }
77
78 } // namespace
79
getBridgedWifiApIface_1_6(const std::string & instance_name)80 sp<IWifiApIface> getBridgedWifiApIface_1_6(const std::string& instance_name) {
81 ChipModeId mode_id;
82 sp<IWifiChip> wifi_chip = getWifiChip_1_6(instance_name);
83 if (!wifi_chip.get()) return nullptr;
84 configureChipToSupportConcurrencyType(wifi_chip, IfaceConcurrencyType::AP_BRIDGED, &mode_id);
85 const auto& status_and_iface = HIDL_INVOKE(wifi_chip, createBridgedApIface);
86 return IWifiApIface::castFrom(status_and_iface.second);
87 }
88