blob: 71319e1e90f307ed8d87fbe0ce240277faec36bb [file] [log] [blame]
Roshan Pius200a17d2017-11-01 13:03:35 -07001/*
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 Pius2272ff82020-11-12 09:37:40 -080017#include <string>
18
19#include <android-base/logging.h>
20#include <cutils/properties.h>
21
Roshan Pius200a17d2017-11-01 13:03:35 -070022#include "wifi_feature_flags.h"
23
Roshan Pius200a17d2017-11-01 13:03:35 -070024namespace android {
25namespace hardware {
26namespace wifi {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080027namespace V1_6 {
Roshan Pius200a17d2017-11-01 13:03:35 -070028namespace implementation {
29namespace feature_flags {
30
Tomasz Wasilczykb424da72018-11-15 11:52:57 -080031using V1_0::ChipModeId;
32using V1_0::IfaceType;
33using V1_0::IWifiChip;
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:
45 * Interface combination 1: 1 STA or AP and 1 P2P or NAN concurrent iface
46 * operations.
47 * Interface combination 2: 1 STA and 2 AP concurrent iface operations.
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
56 * two interface combinations:
57 * Interface Combination 1: Will support 1 STA and 1 P2P or NAN (optional)
58 * concurrent iface operations.
59 * Interface Combination 2: Will support 1 STA and 1 AP concurrent
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
64 * modes of operation with 1 interface combination each:
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 *
69 * If Aware is enabled, the iface combination will be modified to support either
70 * P2P or NAN in place of just P2P.
71 */
72// clang-format off
73#ifdef WIFI_HAL_INTERFACE_COMBINATIONS
74constexpr ChipModeId kMainModeId = chip_mode_ids::kV3;
75#elif defined(WIFI_HIDL_FEATURE_DUAL_INTERFACE)
76// former V2 (fixed dual interface) setup expressed as V3
77constexpr 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)
99constexpr 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 */
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800120struct ChipIfaceCombination : public hidl_vec<IWifiChip::ChipIfaceCombinationLimit> {
121 ChipIfaceCombination(const std::initializer_list<IWifiChip::ChipIfaceCombinationLimit> list)
Tomasz Wasilczykb424da72018-11-15 11:52:57 -0800122 : hidl_vec(list) {}
123
124 operator IWifiChip::ChipIfaceCombination() const { return {*this}; }
125
126 static hidl_vec<IWifiChip::ChipIfaceCombination> make_vec(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800127 const std::initializer_list<ChipIfaceCombination> list) {
Tomasz Wasilczykb424da72018-11-15 11:52:57 -0800128 return hidl_vec<IWifiChip::ChipIfaceCombination>( //
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800129 std::begin(list), std::end(list));
Tomasz Wasilczykb424da72018-11-15 11:52:57 -0800130 }
131};
132
133#define STA IfaceType::STA
134#define AP IfaceType::AP
135#define P2P IfaceType::P2P
136#define NAN IfaceType::NAN
Roshan Pius2272ff82020-11-12 09:37:40 -0800137static const std::vector<IWifiChip::ChipMode> kChipModesPrimary{
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800138 {kMainModeId, ChipIfaceCombination::make_vec({WIFI_HAL_INTERFACE_COMBINATIONS})},
Tomasz Wasilczykb424da72018-11-15 11:52:57 -0800139#ifdef WIFI_HAL_INTERFACE_COMBINATIONS_AP
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800140 {chip_mode_ids::kV1Ap,
141 ChipIfaceCombination::make_vec({WIFI_HAL_INTERFACE_COMBINATIONS_AP})},
Tomasz Wasilczykb424da72018-11-15 11:52:57 -0800142#endif
143};
Jimmy Chen2dddd792019-12-23 17:50:39 +0200144
145static const std::vector<IWifiChip::ChipMode> kChipModesSecondary{
146#ifdef WIFI_HAL_INTERFACE_COMBINATIONS_SECONDARY_CHIP
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800147 {chip_mode_ids::kV3,
148 ChipIfaceCombination::make_vec({WIFI_HAL_INTERFACE_COMBINATIONS_SECONDARY_CHIP})},
Jimmy Chen2dddd792019-12-23 17:50:39 +0200149#endif
150};
Roshan Pius2272ff82020-11-12 09:37:40 -0800151
152constexpr char kDebugPresetInterfaceCombinationIdxProperty[] =
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800153 "persist.vendor.debug.wifi.hal.preset_interface_combination_idx";
Roshan Pius2272ff82020-11-12 09:37:40 -0800154// List of pre-defined interface combinations that can be enabled at runtime via
155// setting the property: "kDebugPresetInterfaceCombinationIdxProperty" to the
156// corresponding index value.
Etan Cohenfcf07852021-12-26 07:13:20 +0000157static const std::vector<std::pair<std::string, std::vector<IWifiChip::ChipMode>>> kDebugChipModes{
Roshan Pius2272ff82020-11-12 09:37:40 -0800158 // Legacy combination - No STA/AP concurrencies.
159 // 0 - (1 AP) or (1 STA + 1 of (P2P or NAN))
160 {"No STA/AP Concurrency",
161 {{kMainModeId,
Etan Cohenfcf07852021-12-26 07:13:20 +0000162 ChipIfaceCombination::make_vec({{{{AP}, 1}}, {{{STA}, 1}, {{P2P, NAN}, 1}}})}}},
Roshan Pius2272ff82020-11-12 09:37:40 -0800163
164 // STA + AP concurrency
165 // 1 - (1 STA + 1 AP) or (1 STA + 1 of (P2P or NAN))
166 {"STA + AP Concurrency",
Etan Cohenfcf07852021-12-26 07:13:20 +0000167 {{kMainModeId, ChipIfaceCombination::make_vec(
168 {{{{STA}, 1}, {{AP}, 1}}, {{{STA}, 1}, {{P2P, NAN}, 1}}})}}},
Roshan Pius2272ff82020-11-12 09:37:40 -0800169
170 // STA + STA concurrency
171 // 2 - (1 STA + 1 AP) or (2 STA + 1 of (P2P or NAN))
172 {"Dual STA Concurrency",
Etan Cohenfcf07852021-12-26 07:13:20 +0000173 {{kMainModeId, ChipIfaceCombination::make_vec(
174 {{{{STA}, 1}, {{AP}, 1}}, {{{STA}, 2}, {{P2P, NAN}, 1}}})}}},
Roshan Pius2272ff82020-11-12 09:37:40 -0800175
176 // AP + AP + STA concurrency
177 // 3 - (1 STA + 2 AP) or (1 STA + 1 of (P2P or NAN))
178 {"Dual AP Concurrency",
Etan Cohenfcf07852021-12-26 07:13:20 +0000179 {{kMainModeId, ChipIfaceCombination::make_vec(
180 {{{{STA}, 1}, {{AP}, 2}}, {{{STA}, 1}, {{P2P, NAN}, 1}}})}}},
Roshan Pius2272ff82020-11-12 09:37:40 -0800181
182 // STA + STA concurrency and AP + AP + STA concurrency
183 // 4 - (1 STA + 2 AP) or (2 STA + 1 of (P2P or NAN))
184 {"Dual STA & Dual AP Concurrency",
Etan Cohenfcf07852021-12-26 07:13:20 +0000185 {{kMainModeId, ChipIfaceCombination::make_vec(
186 {{{{STA}, 1}, {{AP}, 2}}, {{{STA}, 2}, {{P2P, NAN}, 1}}})}}},
187
188 // STA + STA concurrency
189 // 5 - (1 STA + 1 AP (bridged or single) | P2P | NAN), or (2 STA))
190 {"Dual STA or STA plus single other interface",
Roshan Pius2272ff82020-11-12 09:37:40 -0800191 {{kMainModeId,
Etan Cohenfcf07852021-12-26 07:13:20 +0000192 ChipIfaceCombination::make_vec({{{{STA}, 1}, {{P2P, NAN, AP}, 1}}, {{{STA}, 2}}})}}}};
Roshan Pius2272ff82020-11-12 09:37:40 -0800193
Tomasz Wasilczykb424da72018-11-15 11:52:57 -0800194#undef STA
195#undef AP
196#undef P2P
197#undef NAN
198
Roshan Pius3b6705f2019-02-14 09:43:43 -0800199#ifdef WIFI_HIDL_FEATURE_DISABLE_AP_MAC_RANDOMIZATION
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800200#pragma message \
201 "WIFI_HIDL_FEATURE_DISABLE_AP_MAC_RANDOMIZATION is deprecated; override " \
202 "'config_wifi_ap_randomization_supported' in " \
203 "frameworks/base/core/res/res/values/config.xml in the device overlay " \
204 "instead"
Patrik Fimml6beae322019-10-09 17:34:01 +0200205#endif // WIFI_HIDL_FEATURE_DISABLE_AP_MAC_RANDOMIZATION
Roshan Pius3b6705f2019-02-14 09:43:43 -0800206
Roshan Pius200a17d2017-11-01 13:03:35 -0700207WifiFeatureFlags::WifiFeatureFlags() {}
Tomasz Wasilczykb424da72018-11-15 11:52:57 -0800208
Roshan Pius2272ff82020-11-12 09:37:40 -0800209std::vector<IWifiChip::ChipMode> WifiFeatureFlags::getChipModesForPrimary() {
210 std::array<char, PROPERTY_VALUE_MAX> buffer;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800211 auto res = property_get(kDebugPresetInterfaceCombinationIdxProperty, buffer.data(), nullptr);
Roshan Pius2272ff82020-11-12 09:37:40 -0800212 // Debug propety not set, use the device preset interface combination.
213 if (res <= 0) return kChipModesPrimary;
214
215 // Debug propety set, use one of the debug preset interface combination.
216 unsigned long idx = std::stoul(buffer.data());
217 if (idx >= kDebugChipModes.size()) {
218 LOG(ERROR) << "Invalid index set in property: "
219 << kDebugPresetInterfaceCombinationIdxProperty;
220 return kChipModesPrimary;
221 }
222 std::string name;
223 std::vector<IWifiChip::ChipMode> chip_modes;
224 std::tie(name, chip_modes) = kDebugChipModes[idx];
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800225 LOG(INFO) << "Using debug chip mode: <" << name
226 << "> set via property: " << kDebugPresetInterfaceCombinationIdxProperty;
Roshan Pius2272ff82020-11-12 09:37:40 -0800227 return chip_modes;
228}
229
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800230std::vector<IWifiChip::ChipMode> WifiFeatureFlags::getChipModes(bool is_primary) {
Roshan Pius2272ff82020-11-12 09:37:40 -0800231 return (is_primary) ? getChipModesForPrimary() : kChipModesSecondary;
Roshan Piuscc338202017-11-02 13:54:09 -0700232}
Roshan Pius200a17d2017-11-01 13:03:35 -0700233
234} // namespace feature_flags
235} // namespace implementation
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800236} // namespace V1_6
Roshan Pius200a17d2017-11-01 13:03:35 -0700237} // namespace wifi
238} // namespace hardware
239} // namespace android