Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
Roshan Pius | 2272ff8 | 2020-11-12 09:37:40 -0800 | [diff] [blame] | 17 | #include <string> |
| 18 | |
| 19 | #include <android-base/logging.h> |
| 20 | #include <cutils/properties.h> |
| 21 | |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 22 | #include "wifi_feature_flags.h" |
| 23 | |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace wifi { |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 27 | namespace V1_6 { |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 28 | namespace implementation { |
| 29 | namespace feature_flags { |
| 30 | |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 31 | using V1_0::ChipModeId; |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 32 | using V1_0::IWifiChip; |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 33 | using V1_6::IfaceConcurrencyType; |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 34 | |
| 35 | /* The chip may either have a single mode supporting any number of combinations, |
| 36 | * or a fixed dual-mode (so it involves firmware loading to switch between |
| 37 | * modes) setting. If there is a need to support more modes, it needs to be |
| 38 | * implemented manually in WiFi HAL (see changeFirmwareMode in |
| 39 | * WifiChip::handleChipConfiguration). |
| 40 | * |
| 41 | * Supported combinations are defined in device's makefile, for example: |
| 42 | * WIFI_HAL_INTERFACE_COMBINATIONS := {{{STA, AP}, 1}, {{P2P, NAN}, 1}}, |
| 43 | * WIFI_HAL_INTERFACE_COMBINATIONS += {{{STA}, 1}, {{AP}, 2}} |
| 44 | * What means: |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 45 | * Interface concurrency combination 1: 1 STA or AP and 1 P2P or NAN concurrent iface |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 46 | * operations. |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 47 | * Interface concurrency combination 2: 1 STA and 2 AP concurrent iface operations. |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 48 | * |
| 49 | * For backward compatibility, the following makefile flags can be used to |
| 50 | * generate combinations list: |
| 51 | * - WIFI_HIDL_FEATURE_DUAL_INTERFACE |
| 52 | * - WIFI_HIDL_FEATURE_DISABLE_AP |
| 53 | * - WIFI_HIDL_FEATURE_AWARE |
| 54 | * However, they are ignored if WIFI_HAL_INTERFACE_COMBINATIONS was provided. |
| 55 | * With WIFI_HIDL_FEATURE_DUAL_INTERFACE flag set, there is a single mode with |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 56 | * two concurrency combinations: |
| 57 | * Interface Concurrency Combination 1: Will support 1 STA and 1 P2P or NAN (optional) |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 58 | * concurrent iface operations. |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 59 | * Interface Concurrency Combination 2: Will support 1 STA and 1 AP concurrent |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 60 | * iface operations. |
| 61 | * |
| 62 | * The only dual-mode configuration supported is for alternating STA and AP |
| 63 | * mode, that may involve firmware reloading. In such case, there are 2 separate |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 64 | * modes of operation with 1 concurrency combination each: |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 65 | * Mode 1 (STA mode): Will support 1 STA and 1 P2P or NAN (optional) |
| 66 | * concurrent iface operations. |
| 67 | * Mode 2 (AP mode): Will support 1 AP iface operation. |
| 68 | * |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 69 | * If Aware is enabled, the concurrency combination will be modified to support either |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 70 | * P2P or NAN in place of just P2P. |
| 71 | */ |
| 72 | // clang-format off |
| 73 | #ifdef WIFI_HAL_INTERFACE_COMBINATIONS |
| 74 | constexpr ChipModeId kMainModeId = chip_mode_ids::kV3; |
| 75 | #elif defined(WIFI_HIDL_FEATURE_DUAL_INTERFACE) |
| 76 | // former V2 (fixed dual interface) setup expressed as V3 |
| 77 | constexpr ChipModeId kMainModeId = chip_mode_ids::kV3; |
| 78 | # ifdef WIFI_HIDL_FEATURE_DISABLE_AP |
| 79 | # ifdef WIFI_HIDL_FEATURE_AWARE |
| 80 | // 1 STA + 1 of (P2P or NAN) |
| 81 | # define WIFI_HAL_INTERFACE_COMBINATIONS {{{STA}, 1}, {{P2P, NAN}, 1}} |
| 82 | # else |
| 83 | // 1 STA + 1 P2P |
| 84 | # define WIFI_HAL_INTERFACE_COMBINATIONS {{{STA}, 1}, {{P2P}, 1}} |
| 85 | # endif |
| 86 | # else |
| 87 | # ifdef WIFI_HIDL_FEATURE_AWARE |
| 88 | // (1 STA + 1 AP) or (1 STA + 1 of (P2P or NAN)) |
| 89 | # define WIFI_HAL_INTERFACE_COMBINATIONS {{{STA}, 1}, {{AP}, 1}},\ |
| 90 | {{{STA}, 1}, {{P2P, NAN}, 1}} |
| 91 | # else |
| 92 | // (1 STA + 1 AP) or (1 STA + 1 P2P) |
| 93 | # define WIFI_HAL_INTERFACE_COMBINATIONS {{{STA}, 1}, {{AP}, 1}},\ |
| 94 | {{{STA}, 1}, {{P2P}, 1}} |
| 95 | # endif |
| 96 | # endif |
| 97 | #else |
| 98 | // V1 (fixed single interface, dual-mode chip) |
| 99 | constexpr ChipModeId kMainModeId = chip_mode_ids::kV1Sta; |
| 100 | # ifdef WIFI_HIDL_FEATURE_AWARE |
| 101 | // 1 STA + 1 of (P2P or NAN) |
| 102 | # define WIFI_HAL_INTERFACE_COMBINATIONS {{{STA}, 1}, {{P2P, NAN}, 1}} |
| 103 | # else |
| 104 | // 1 STA + 1 P2P |
| 105 | # define WIFI_HAL_INTERFACE_COMBINATIONS {{{STA}, 1}, {{P2P}, 1}} |
| 106 | # endif |
| 107 | |
| 108 | # ifndef WIFI_HIDL_FEATURE_DISABLE_AP |
| 109 | # define WIFI_HAL_INTERFACE_COMBINATIONS_AP {{{AP}, 1}} |
| 110 | # endif |
| 111 | #endif |
| 112 | // clang-format on |
| 113 | |
| 114 | /** |
| 115 | * Helper class to convert a collection of combination limits to a combination. |
| 116 | * |
| 117 | * The main point here is to simplify the syntax required by |
| 118 | * WIFI_HAL_INTERFACE_COMBINATIONS. |
| 119 | */ |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 120 | struct ChipConcurrencyCombination |
| 121 | : public hidl_vec<V1_6::IWifiChip::ChipConcurrencyCombinationLimit> { |
| 122 | ChipConcurrencyCombination( |
| 123 | const std::initializer_list<V1_6::IWifiChip::ChipConcurrencyCombinationLimit> list) |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 124 | : hidl_vec(list) {} |
| 125 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 126 | operator V1_6::IWifiChip::ChipConcurrencyCombination() const { return {*this}; } |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 127 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 128 | static hidl_vec<V1_6::IWifiChip::ChipConcurrencyCombination> make_vec( |
| 129 | const std::initializer_list<ChipConcurrencyCombination> list) { |
| 130 | return hidl_vec<V1_6::IWifiChip::ChipConcurrencyCombination>( // |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 131 | std::begin(list), std::end(list)); |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 132 | } |
| 133 | }; |
| 134 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 135 | #define STA IfaceConcurrencyType::STA |
| 136 | #define AP IfaceConcurrencyType::AP |
| 137 | #define AP_BRIDGED IfaceConcurrencyType::AP_BRIDGED |
| 138 | #define P2P IfaceConcurrencyType::P2P |
| 139 | #define NAN IfaceConcurrencyType::NAN |
| 140 | static const std::vector<V1_6::IWifiChip::ChipMode> kChipModesPrimary{ |
| 141 | {kMainModeId, ChipConcurrencyCombination::make_vec({WIFI_HAL_INTERFACE_COMBINATIONS})}, |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 142 | #ifdef WIFI_HAL_INTERFACE_COMBINATIONS_AP |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 143 | {chip_mode_ids::kV1Ap, |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 144 | ChipConcurrencyCombination::make_vec({WIFI_HAL_INTERFACE_COMBINATIONS_AP})}, |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 145 | #endif |
| 146 | }; |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 147 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 148 | static const std::vector<V1_6::IWifiChip::ChipMode> kChipModesSecondary{ |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 149 | #ifdef WIFI_HAL_INTERFACE_COMBINATIONS_SECONDARY_CHIP |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 150 | {chip_mode_ids::kV3, |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 151 | ChipConcurrencyCombination::make_vec({WIFI_HAL_INTERFACE_COMBINATIONS_SECONDARY_CHIP})}, |
Jimmy Chen | 2dddd79 | 2019-12-23 17:50:39 +0200 | [diff] [blame] | 152 | #endif |
| 153 | }; |
Roshan Pius | 2272ff8 | 2020-11-12 09:37:40 -0800 | [diff] [blame] | 154 | |
| 155 | constexpr char kDebugPresetInterfaceCombinationIdxProperty[] = |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 156 | "persist.vendor.debug.wifi.hal.preset_interface_combination_idx"; |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 157 | // List of pre-defined concurrency combinations that can be enabled at runtime via |
Roshan Pius | 2272ff8 | 2020-11-12 09:37:40 -0800 | [diff] [blame] | 158 | // setting the property: "kDebugPresetInterfaceCombinationIdxProperty" to the |
| 159 | // corresponding index value. |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 160 | static const std::vector<std::pair<std::string, std::vector<V1_6::IWifiChip::ChipMode>>> |
| 161 | kDebugChipModes{// Legacy combination - No STA/AP concurrencies. |
| 162 | // 0 - (1 AP) or (1 STA + 1 of (P2P or NAN)) |
| 163 | {"No STA/AP Concurrency", |
| 164 | {{kMainModeId, ChipConcurrencyCombination::make_vec( |
| 165 | {{{{AP}, 1}}, {{{STA}, 1}, {{P2P, NAN}, 1}}})}}}, |
Roshan Pius | 2272ff8 | 2020-11-12 09:37:40 -0800 | [diff] [blame] | 166 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 167 | // STA + AP concurrency |
| 168 | // 1 - (1 STA + 1 AP) or (1 STA + 1 of (P2P or NAN)) |
| 169 | {"STA + AP Concurrency", |
| 170 | {{kMainModeId, |
| 171 | ChipConcurrencyCombination::make_vec( |
| 172 | {{{{STA}, 1}, {{AP}, 1}}, {{{STA}, 1}, {{P2P, NAN}, 1}}})}}}, |
Roshan Pius | 2272ff8 | 2020-11-12 09:37:40 -0800 | [diff] [blame] | 173 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 174 | // STA + STA concurrency |
| 175 | // 2 - (1 STA + 1 AP) or (2 STA + 1 of (P2P or NAN)) |
| 176 | {"Dual STA Concurrency", |
| 177 | {{kMainModeId, |
| 178 | ChipConcurrencyCombination::make_vec( |
| 179 | {{{{STA}, 1}, {{AP}, 1}}, {{{STA}, 2}, {{P2P, NAN}, 1}}})}}}, |
Roshan Pius | 2272ff8 | 2020-11-12 09:37:40 -0800 | [diff] [blame] | 180 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 181 | // AP + AP + STA concurrency |
| 182 | // 3 - (1 STA + 2 AP) or (1 STA + 1 of (P2P or NAN)) |
| 183 | {"Dual AP Concurrency", |
| 184 | {{kMainModeId, |
| 185 | ChipConcurrencyCombination::make_vec( |
| 186 | {{{{STA}, 1}, {{AP}, 2}}, {{{STA}, 1}, {{P2P, NAN}, 1}}})}}}, |
Roshan Pius | 2272ff8 | 2020-11-12 09:37:40 -0800 | [diff] [blame] | 187 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 188 | // STA + STA concurrency and AP + AP + STA concurrency |
| 189 | // 4 - (1 STA + 2 AP) or (2 STA + 1 of (P2P or NAN)) |
| 190 | {"Dual STA & Dual AP Concurrency", |
| 191 | {{kMainModeId, |
| 192 | ChipConcurrencyCombination::make_vec( |
| 193 | {{{{STA}, 1}, {{AP}, 2}}, {{{STA}, 2}, {{P2P, NAN}, 1}}})}}}, |
Etan Cohen | fcf0785 | 2021-12-26 07:13:20 +0000 | [diff] [blame] | 194 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 195 | // STA + STA concurrency |
| 196 | // 5 - (1 STA + 1 AP (bridged or single) | P2P | NAN), or (2 STA)) |
| 197 | {"Dual STA or STA plus single other interface", |
| 198 | {{kMainModeId, ChipConcurrencyCombination::make_vec( |
| 199 | {{{{STA}, 1}, {{P2P, NAN, AP, AP_BRIDGED}, 1}}, |
| 200 | {{{STA}, 2}}})}}}}; |
Roshan Pius | 2272ff8 | 2020-11-12 09:37:40 -0800 | [diff] [blame] | 201 | |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 202 | #undef STA |
| 203 | #undef AP |
| 204 | #undef P2P |
| 205 | #undef NAN |
| 206 | |
Roshan Pius | 3b6705f | 2019-02-14 09:43:43 -0800 | [diff] [blame] | 207 | #ifdef WIFI_HIDL_FEATURE_DISABLE_AP_MAC_RANDOMIZATION |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 208 | #pragma message \ |
| 209 | "WIFI_HIDL_FEATURE_DISABLE_AP_MAC_RANDOMIZATION is deprecated; override " \ |
| 210 | "'config_wifi_ap_randomization_supported' in " \ |
| 211 | "frameworks/base/core/res/res/values/config.xml in the device overlay " \ |
| 212 | "instead" |
Patrik Fimml | 6beae32 | 2019-10-09 17:34:01 +0200 | [diff] [blame] | 213 | #endif // WIFI_HIDL_FEATURE_DISABLE_AP_MAC_RANDOMIZATION |
Roshan Pius | 3b6705f | 2019-02-14 09:43:43 -0800 | [diff] [blame] | 214 | |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 215 | WifiFeatureFlags::WifiFeatureFlags() {} |
Tomasz Wasilczyk | b424da7 | 2018-11-15 11:52:57 -0800 | [diff] [blame] | 216 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 217 | std::vector<V1_6::IWifiChip::ChipMode> WifiFeatureFlags::getChipModesForPrimary() { |
Roshan Pius | 2272ff8 | 2020-11-12 09:37:40 -0800 | [diff] [blame] | 218 | std::array<char, PROPERTY_VALUE_MAX> buffer; |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 219 | auto res = property_get(kDebugPresetInterfaceCombinationIdxProperty, buffer.data(), nullptr); |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 220 | // Debug property not set, use the device preset concurrency combination. |
Roshan Pius | 2272ff8 | 2020-11-12 09:37:40 -0800 | [diff] [blame] | 221 | if (res <= 0) return kChipModesPrimary; |
| 222 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 223 | // Debug property set, use one of the debug preset concurrency combination. |
Roshan Pius | 2272ff8 | 2020-11-12 09:37:40 -0800 | [diff] [blame] | 224 | unsigned long idx = std::stoul(buffer.data()); |
| 225 | if (idx >= kDebugChipModes.size()) { |
| 226 | LOG(ERROR) << "Invalid index set in property: " |
| 227 | << kDebugPresetInterfaceCombinationIdxProperty; |
| 228 | return kChipModesPrimary; |
| 229 | } |
| 230 | std::string name; |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 231 | std::vector<V1_6::IWifiChip::ChipMode> chip_modes; |
Roshan Pius | 2272ff8 | 2020-11-12 09:37:40 -0800 | [diff] [blame] | 232 | std::tie(name, chip_modes) = kDebugChipModes[idx]; |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 233 | LOG(INFO) << "Using debug chip mode: <" << name |
| 234 | << "> set via property: " << kDebugPresetInterfaceCombinationIdxProperty; |
Roshan Pius | 2272ff8 | 2020-11-12 09:37:40 -0800 | [diff] [blame] | 235 | return chip_modes; |
| 236 | } |
| 237 | |
Quang Luong | 5d8805e | 2022-01-28 15:46:40 -0800 | [diff] [blame^] | 238 | std::vector<V1_6::IWifiChip::ChipMode> WifiFeatureFlags::getChipModes(bool is_primary) { |
Roshan Pius | 2272ff8 | 2020-11-12 09:37:40 -0800 | [diff] [blame] | 239 | return (is_primary) ? getChipModesForPrimary() : kChipModesSecondary; |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 240 | } |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 241 | |
| 242 | } // namespace feature_flags |
| 243 | } // namespace implementation |
Ahmed ElArabawy | 687ce13 | 2022-01-11 16:42:48 -0800 | [diff] [blame] | 244 | } // namespace V1_6 |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 245 | } // namespace wifi |
| 246 | } // namespace hardware |
| 247 | } // namespace android |