blob: 195b460dfe05e88baef3f732483ea4d5919ae857 [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
17#include "wifi_feature_flags.h"
18
Roshan Pius200a17d2017-11-01 13:03:35 -070019namespace android {
20namespace hardware {
21namespace wifi {
Ahmed ElArabawyf501a982019-07-23 15:02:22 -070022namespace V1_4 {
Roshan Pius200a17d2017-11-01 13:03:35 -070023namespace implementation {
24namespace feature_flags {
25
Tomasz Wasilczykb424da72018-11-15 11:52:57 -080026using V1_0::ChipModeId;
27using V1_0::IfaceType;
28using V1_0::IWifiChip;
29
30/* The chip may either have a single mode supporting any number of combinations,
31 * or a fixed dual-mode (so it involves firmware loading to switch between
32 * modes) setting. If there is a need to support more modes, it needs to be
33 * implemented manually in WiFi HAL (see changeFirmwareMode in
34 * WifiChip::handleChipConfiguration).
35 *
36 * Supported combinations are defined in device's makefile, for example:
37 * WIFI_HAL_INTERFACE_COMBINATIONS := {{{STA, AP}, 1}, {{P2P, NAN}, 1}},
38 * WIFI_HAL_INTERFACE_COMBINATIONS += {{{STA}, 1}, {{AP}, 2}}
39 * What means:
40 * Interface combination 1: 1 STA or AP and 1 P2P or NAN concurrent iface
41 * operations.
42 * Interface combination 2: 1 STA and 2 AP concurrent iface operations.
43 *
44 * For backward compatibility, the following makefile flags can be used to
45 * generate combinations list:
46 * - WIFI_HIDL_FEATURE_DUAL_INTERFACE
47 * - WIFI_HIDL_FEATURE_DISABLE_AP
48 * - WIFI_HIDL_FEATURE_AWARE
49 * However, they are ignored if WIFI_HAL_INTERFACE_COMBINATIONS was provided.
50 * With WIFI_HIDL_FEATURE_DUAL_INTERFACE flag set, there is a single mode with
51 * two interface combinations:
52 * Interface Combination 1: Will support 1 STA and 1 P2P or NAN (optional)
53 * concurrent iface operations.
54 * Interface Combination 2: Will support 1 STA and 1 AP concurrent
55 * iface operations.
56 *
57 * The only dual-mode configuration supported is for alternating STA and AP
58 * mode, that may involve firmware reloading. In such case, there are 2 separate
59 * modes of operation with 1 interface combination each:
60 * Mode 1 (STA mode): Will support 1 STA and 1 P2P or NAN (optional)
61 * concurrent iface operations.
62 * Mode 2 (AP mode): Will support 1 AP iface operation.
63 *
64 * If Aware is enabled, the iface combination will be modified to support either
65 * P2P or NAN in place of just P2P.
66 */
67// clang-format off
68#ifdef WIFI_HAL_INTERFACE_COMBINATIONS
69constexpr ChipModeId kMainModeId = chip_mode_ids::kV3;
70#elif defined(WIFI_HIDL_FEATURE_DUAL_INTERFACE)
71// former V2 (fixed dual interface) setup expressed as V3
72constexpr ChipModeId kMainModeId = chip_mode_ids::kV3;
73# ifdef WIFI_HIDL_FEATURE_DISABLE_AP
74# ifdef WIFI_HIDL_FEATURE_AWARE
75// 1 STA + 1 of (P2P or NAN)
76# define WIFI_HAL_INTERFACE_COMBINATIONS {{{STA}, 1}, {{P2P, NAN}, 1}}
77# else
78// 1 STA + 1 P2P
79# define WIFI_HAL_INTERFACE_COMBINATIONS {{{STA}, 1}, {{P2P}, 1}}
80# endif
81# else
82# ifdef WIFI_HIDL_FEATURE_AWARE
83// (1 STA + 1 AP) or (1 STA + 1 of (P2P or NAN))
84# define WIFI_HAL_INTERFACE_COMBINATIONS {{{STA}, 1}, {{AP}, 1}},\
85 {{{STA}, 1}, {{P2P, NAN}, 1}}
86# else
87// (1 STA + 1 AP) or (1 STA + 1 P2P)
88# define WIFI_HAL_INTERFACE_COMBINATIONS {{{STA}, 1}, {{AP}, 1}},\
89 {{{STA}, 1}, {{P2P}, 1}}
90# endif
91# endif
92#else
93// V1 (fixed single interface, dual-mode chip)
94constexpr ChipModeId kMainModeId = chip_mode_ids::kV1Sta;
95# ifdef WIFI_HIDL_FEATURE_AWARE
96// 1 STA + 1 of (P2P or NAN)
97# define WIFI_HAL_INTERFACE_COMBINATIONS {{{STA}, 1}, {{P2P, NAN}, 1}}
98# else
99// 1 STA + 1 P2P
100# define WIFI_HAL_INTERFACE_COMBINATIONS {{{STA}, 1}, {{P2P}, 1}}
101# endif
102
103# ifndef WIFI_HIDL_FEATURE_DISABLE_AP
104# define WIFI_HAL_INTERFACE_COMBINATIONS_AP {{{AP}, 1}}
105# endif
106#endif
107// clang-format on
108
109/**
110 * Helper class to convert a collection of combination limits to a combination.
111 *
112 * The main point here is to simplify the syntax required by
113 * WIFI_HAL_INTERFACE_COMBINATIONS.
114 */
115struct ChipIfaceCombination
116 : public hidl_vec<IWifiChip::ChipIfaceCombinationLimit> {
117 ChipIfaceCombination(
118 const std::initializer_list<IWifiChip::ChipIfaceCombinationLimit> list)
119 : hidl_vec(list) {}
120
121 operator IWifiChip::ChipIfaceCombination() const { return {*this}; }
122
123 static hidl_vec<IWifiChip::ChipIfaceCombination> make_vec(
124 const std::initializer_list<ChipIfaceCombination> list) {
125 return hidl_vec<IWifiChip::ChipIfaceCombination>( //
126 std::begin(list), std::end(list));
127 }
128};
129
130#define STA IfaceType::STA
131#define AP IfaceType::AP
132#define P2P IfaceType::P2P
133#define NAN IfaceType::NAN
134static const std::vector<IWifiChip::ChipMode> kChipModes{
135 {kMainModeId,
136 ChipIfaceCombination::make_vec({WIFI_HAL_INTERFACE_COMBINATIONS})},
137#ifdef WIFI_HAL_INTERFACE_COMBINATIONS_AP
138 {chip_mode_ids::kV1Ap,
139 ChipIfaceCombination::make_vec({WIFI_HAL_INTERFACE_COMBINATIONS_AP})},
140#endif
141};
142#undef STA
143#undef AP
144#undef P2P
145#undef NAN
146
Roshan Pius3b6705f2019-02-14 09:43:43 -0800147#ifdef WIFI_HIDL_FEATURE_DISABLE_AP_MAC_RANDOMIZATION
Patrik Fimml6beae322019-10-09 17:34:01 +0200148#pragma message \
149 "WIFI_HIDL_FEATURE_DISABLE_AP_MAC_RANDOMIZATION is deprecated; override " \
150 "'config_wifi_ap_randomization_supported' in " \
151 "frameworks/base/core/res/res/values/config.xml in the device overlay " \
152 "instead"
153#endif // WIFI_HIDL_FEATURE_DISABLE_AP_MAC_RANDOMIZATION
Roshan Pius3b6705f2019-02-14 09:43:43 -0800154
Roshan Pius200a17d2017-11-01 13:03:35 -0700155WifiFeatureFlags::WifiFeatureFlags() {}
Tomasz Wasilczykb424da72018-11-15 11:52:57 -0800156
157std::vector<IWifiChip::ChipMode> WifiFeatureFlags::getChipModes() {
158 return kChipModes;
Roshan Piuscc338202017-11-02 13:54:09 -0700159}
Roshan Pius200a17d2017-11-01 13:03:35 -0700160
161} // namespace feature_flags
162} // namespace implementation
Ahmed ElArabawyf501a982019-07-23 15:02:22 -0700163} // namespace V1_4
Roshan Pius200a17d2017-11-01 13:03:35 -0700164} // namespace wifi
165} // namespace hardware
166} // namespace android