blob: f952a6865465ecd1bcd7174c7f9a85d4b2194fec [file] [log] [blame]
Ahmed ElArabawy687ce132022-01-11 16:42:48 -08001/*
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#ifndef WIFI_CHIP_H_
18#define WIFI_CHIP_H_
19
Quang Luong5d8805e2022-01-28 15:46:40 -080020// HACK: NAN is a macro defined in math.h, which can be included in various
21// headers. This wifi HAL uses an enum called NAN, which does not compile when
22// the macro is defined. Undefine NAN to work around it.
23#undef NAN
24
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080025#include <list>
26#include <map>
27#include <mutex>
28
29#include <android-base/macros.h>
Ahmed ElArabawy05571e42022-01-19 11:54:11 -080030#include <android/hardware/wifi/1.6/IWifiChip.h>
31#include <android/hardware/wifi/1.6/IWifiRttController.h>
32#include <android/hardware/wifi/1.6/IWifiStaIface.h>
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080033
34#include "hidl_callback_util.h"
35#include "ringbuffer.h"
36#include "wifi_ap_iface.h"
37#include "wifi_feature_flags.h"
38#include "wifi_legacy_hal.h"
39#include "wifi_mode_controller.h"
40#include "wifi_nan_iface.h"
41#include "wifi_p2p_iface.h"
42#include "wifi_rtt_controller.h"
43#include "wifi_sta_iface.h"
44
45namespace android {
46namespace hardware {
47namespace wifi {
48namespace V1_6 {
49namespace implementation {
50using namespace android::hardware::wifi::V1_0;
51using V1_5::WifiBand;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080052
53/**
54 * HIDL interface object used to control a Wifi HAL chip instance.
55 * Since there is only a single chip instance used today, there is no
56 * identifying handle information stored here.
57 */
Ahmed ElArabawy05571e42022-01-19 11:54:11 -080058class WifiChip : public V1_6::IWifiChip {
Ahmed ElArabawy687ce132022-01-11 16:42:48 -080059 public:
60 WifiChip(ChipId chip_id, bool is_primary,
61 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
62 const std::weak_ptr<mode_controller::WifiModeController> mode_controller,
63 const std::shared_ptr<iface_util::WifiIfaceUtil> iface_util,
64 const std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags,
65 const std::function<void(const std::string&)>& subsystemCallbackHandler);
66 // HIDL does not provide a built-in mechanism to let the server invalidate
67 // a HIDL interface object after creation. If any client process holds onto
68 // a reference to the object in their context, any method calls on that
69 // reference will continue to be directed to the server.
70 //
71 // However Wifi HAL needs to control the lifetime of these objects. So, add
72 // a public |invalidate| method to |WifiChip| and it's child objects. This
73 // will be used to mark an object invalid when either:
74 // a) Wifi HAL is stopped, or
75 // b) Wifi Chip is reconfigured.
76 //
77 // All HIDL method implementations should check if the object is still
78 // marked valid before processing them.
79 void invalidate();
80 bool isValid();
81 std::set<sp<V1_4::IWifiChipEventCallback>> getEventCallbacks();
82
83 // HIDL methods exposed.
84 Return<void> getId(getId_cb hidl_status_cb) override;
85 // Deprecated support for this callback
86 Return<void> registerEventCallback(const sp<V1_0::IWifiChipEventCallback>& event_callback,
87 registerEventCallback_cb hidl_status_cb) override;
88 Return<void> getCapabilities(getCapabilities_cb hidl_status_cb) override;
89 Return<void> getAvailableModes(getAvailableModes_cb hidl_status_cb) override;
90 Return<void> configureChip(ChipModeId mode_id, configureChip_cb hidl_status_cb) override;
91 Return<void> getMode(getMode_cb hidl_status_cb) override;
92 Return<void> requestChipDebugInfo(requestChipDebugInfo_cb hidl_status_cb) override;
93 Return<void> requestDriverDebugDump(requestDriverDebugDump_cb hidl_status_cb) override;
94 Return<void> requestFirmwareDebugDump(requestFirmwareDebugDump_cb hidl_status_cb) override;
95 Return<void> createApIface(createApIface_cb hidl_status_cb) override;
96 Return<void> createBridgedApIface(createBridgedApIface_cb hidl_status_cb) override;
97 Return<void> getApIfaceNames(getApIfaceNames_cb hidl_status_cb) override;
98 Return<void> getApIface(const hidl_string& ifname, getApIface_cb hidl_status_cb) override;
99 Return<void> removeApIface(const hidl_string& ifname, removeApIface_cb hidl_status_cb) override;
100 Return<void> removeIfaceInstanceFromBridgedApIface(
101 const hidl_string& brIfaceName, const hidl_string& ifaceInstanceName,
102 removeIfaceInstanceFromBridgedApIface_cb hidl_status_cb) override;
103 Return<void> createNanIface(createNanIface_cb hidl_status_cb) override;
104 Return<void> getNanIfaceNames(getNanIfaceNames_cb hidl_status_cb) override;
105 Return<void> getNanIface(const hidl_string& ifname, getNanIface_cb hidl_status_cb) override;
106 Return<void> removeNanIface(const hidl_string& ifname,
107 removeNanIface_cb hidl_status_cb) override;
108 Return<void> createP2pIface(createP2pIface_cb hidl_status_cb) override;
109 Return<void> getP2pIfaceNames(getP2pIfaceNames_cb hidl_status_cb) override;
110 Return<void> getP2pIface(const hidl_string& ifname, getP2pIface_cb hidl_status_cb) override;
111 Return<void> removeP2pIface(const hidl_string& ifname,
112 removeP2pIface_cb hidl_status_cb) override;
113 Return<void> createStaIface(createStaIface_cb hidl_status_cb) override;
114 Return<void> getStaIfaceNames(getStaIfaceNames_cb hidl_status_cb) override;
115 Return<void> getStaIface(const hidl_string& ifname, getStaIface_cb hidl_status_cb) override;
116 Return<void> removeStaIface(const hidl_string& ifname,
117 removeStaIface_cb hidl_status_cb) override;
118 Return<void> createRttController(const sp<IWifiIface>& bound_iface,
119 createRttController_cb hidl_status_cb) override;
120 Return<void> getDebugRingBuffersStatus(getDebugRingBuffersStatus_cb hidl_status_cb) override;
121 Return<void> startLoggingToDebugRingBuffer(
122 const hidl_string& ring_name, WifiDebugRingBufferVerboseLevel verbose_level,
123 uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes,
124 startLoggingToDebugRingBuffer_cb hidl_status_cb) override;
125 Return<void> forceDumpToDebugRingBuffer(const hidl_string& ring_name,
126 forceDumpToDebugRingBuffer_cb hidl_status_cb) override;
127 Return<void> flushRingBufferToFile(flushRingBufferToFile_cb hidl_status_cb) override;
128 Return<void> stopLoggingToDebugRingBuffer(
129 stopLoggingToDebugRingBuffer_cb hidl_status_cb) override;
130 Return<void> getDebugHostWakeReasonStats(
131 getDebugHostWakeReasonStats_cb hidl_status_cb) override;
132 Return<void> enableDebugErrorAlerts(bool enable,
133 enableDebugErrorAlerts_cb hidl_status_cb) override;
134 Return<void> selectTxPowerScenario(V1_1::IWifiChip::TxPowerScenario scenario,
135 selectTxPowerScenario_cb hidl_status_cb) override;
136 Return<void> resetTxPowerScenario(resetTxPowerScenario_cb hidl_status_cb) override;
137 Return<void> setLatencyMode(LatencyMode mode, setLatencyMode_cb hidl_status_cb) override;
138 Return<void> registerEventCallback_1_2(const sp<V1_2::IWifiChipEventCallback>& event_callback,
139 registerEventCallback_1_2_cb hidl_status_cb) override;
140 Return<void> selectTxPowerScenario_1_2(TxPowerScenario scenario,
141 selectTxPowerScenario_cb hidl_status_cb) override;
142 Return<void> getCapabilities_1_3(getCapabilities_cb hidl_status_cb) override;
143 Return<void> getCapabilities_1_5(getCapabilities_1_5_cb hidl_status_cb) override;
144 Return<void> debug(const hidl_handle& handle, const hidl_vec<hidl_string>& options) override;
145 Return<void> createRttController_1_4(const sp<IWifiIface>& bound_iface,
146 createRttController_1_4_cb hidl_status_cb) override;
147 Return<void> registerEventCallback_1_4(const sp<V1_4::IWifiChipEventCallback>& event_callback,
148 registerEventCallback_1_4_cb hidl_status_cb) override;
149 Return<void> setMultiStaPrimaryConnection(
150 const hidl_string& ifname, setMultiStaPrimaryConnection_cb hidl_status_cb) override;
151 Return<void> setMultiStaUseCase(MultiStaUseCase use_case,
152 setMultiStaUseCase_cb hidl_status_cb) override;
153 Return<void> setCoexUnsafeChannels(const hidl_vec<CoexUnsafeChannel>& unsafe_channels,
154 hidl_bitfield<IfaceType> restrictions,
155 setCoexUnsafeChannels_cb hidl_status_cb) override;
156 Return<void> setCountryCode(const hidl_array<int8_t, 2>& code,
157 setCountryCode_cb _hidl_cb) override;
158 Return<void> getUsableChannels(WifiBand band, hidl_bitfield<V1_5::WifiIfaceMode> ifaceModeMask,
Nate Jiang6e135992022-01-24 12:14:23 -0800159 hidl_bitfield<V1_5::IWifiChip::UsableChannelFilter> filterMask,
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800160 getUsableChannels_cb _hidl_cb) override;
161 Return<void> triggerSubsystemRestart(triggerSubsystemRestart_cb hidl_status_cb) override;
Ahmed ElArabawy05571e42022-01-19 11:54:11 -0800162 Return<void> createRttController_1_6(const sp<IWifiIface>& bound_iface,
163 createRttController_1_6_cb hidl_status_cb) override;
164 Return<void> getUsableChannels_1_6(WifiBand band,
165 hidl_bitfield<V1_5::WifiIfaceMode> ifaceModeMask,
166 hidl_bitfield<UsableChannelFilter> filterMask,
167 getUsableChannels_1_6_cb _hidl_cb) override;
Sunil Ravief97d232022-01-24 10:39:56 -0800168 Return<void> getSupportedRadioCombinationsMatrix(
169 getSupportedRadioCombinationsMatrix_cb hidl_status_cb) override;
Quang Luong5d8805e2022-01-28 15:46:40 -0800170 Return<void> getAvailableModes_1_6(getAvailableModes_1_6_cb hidl_status_cb) override;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800171
172 private:
173 void invalidateAndRemoveAllIfaces();
174 // When a STA iface is removed any dependent NAN-ifaces/RTT-controllers are
175 // invalidated & removed.
176 void invalidateAndRemoveDependencies(const std::string& removed_iface_name);
177
178 // Corresponding worker functions for the HIDL methods.
179 std::pair<WifiStatus, ChipId> getIdInternal();
180 // Deprecated support for this callback
181 WifiStatus registerEventCallbackInternal(
182 const sp<V1_0::IWifiChipEventCallback>& event_callback);
183 std::pair<WifiStatus, uint32_t> getCapabilitiesInternal();
Quang Luong5d8805e2022-01-28 15:46:40 -0800184 std::pair<WifiStatus, std::vector<V1_0::IWifiChip::ChipMode>> getAvailableModesInternal();
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800185 WifiStatus configureChipInternal(std::unique_lock<std::recursive_mutex>* lock,
186 ChipModeId mode_id);
187 std::pair<WifiStatus, uint32_t> getModeInternal();
188 std::pair<WifiStatus, IWifiChip::ChipDebugInfo> requestChipDebugInfoInternal();
189 std::pair<WifiStatus, std::vector<uint8_t>> requestDriverDebugDumpInternal();
190 std::pair<WifiStatus, std::vector<uint8_t>> requestFirmwareDebugDumpInternal();
191 sp<WifiApIface> newWifiApIface(std::string& ifname);
192 WifiStatus createVirtualApInterface(const std::string& apVirtIf);
193 std::pair<WifiStatus, sp<V1_5::IWifiApIface>> createApIfaceInternal();
194 std::pair<WifiStatus, sp<V1_5::IWifiApIface>> createBridgedApIfaceInternal();
195 std::pair<WifiStatus, std::vector<hidl_string>> getApIfaceNamesInternal();
196 std::pair<WifiStatus, sp<V1_5::IWifiApIface>> getApIfaceInternal(const std::string& ifname);
197 WifiStatus removeApIfaceInternal(const std::string& ifname);
198 WifiStatus removeIfaceInstanceFromBridgedApIfaceInternal(const std::string& brIfaceName,
199 const std::string& ifInstanceName);
200 std::pair<WifiStatus, sp<V1_4::IWifiNanIface>> createNanIfaceInternal();
201 std::pair<WifiStatus, std::vector<hidl_string>> getNanIfaceNamesInternal();
202 std::pair<WifiStatus, sp<V1_4::IWifiNanIface>> getNanIfaceInternal(const std::string& ifname);
203 WifiStatus removeNanIfaceInternal(const std::string& ifname);
204 std::pair<WifiStatus, sp<IWifiP2pIface>> createP2pIfaceInternal();
205 std::pair<WifiStatus, std::vector<hidl_string>> getP2pIfaceNamesInternal();
206 std::pair<WifiStatus, sp<IWifiP2pIface>> getP2pIfaceInternal(const std::string& ifname);
207 WifiStatus removeP2pIfaceInternal(const std::string& ifname);
Ahmed ElArabawy05571e42022-01-19 11:54:11 -0800208 std::pair<WifiStatus, sp<V1_6::IWifiStaIface>> createStaIfaceInternal();
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800209 std::pair<WifiStatus, std::vector<hidl_string>> getStaIfaceNamesInternal();
Ahmed ElArabawy05571e42022-01-19 11:54:11 -0800210 std::pair<WifiStatus, sp<V1_6::IWifiStaIface>> getStaIfaceInternal(const std::string& ifname);
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800211 WifiStatus removeStaIfaceInternal(const std::string& ifname);
212 std::pair<WifiStatus, sp<V1_0::IWifiRttController>> createRttControllerInternal(
213 const sp<IWifiIface>& bound_iface);
214 std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>>
215 getDebugRingBuffersStatusInternal();
216 WifiStatus startLoggingToDebugRingBufferInternal(const hidl_string& ring_name,
217 WifiDebugRingBufferVerboseLevel verbose_level,
218 uint32_t max_interval_in_sec,
219 uint32_t min_data_size_in_bytes);
220 WifiStatus forceDumpToDebugRingBufferInternal(const hidl_string& ring_name);
221 WifiStatus flushRingBufferToFileInternal();
222 WifiStatus stopLoggingToDebugRingBufferInternal();
223 std::pair<WifiStatus, WifiDebugHostWakeReasonStats> getDebugHostWakeReasonStatsInternal();
224 WifiStatus enableDebugErrorAlertsInternal(bool enable);
225 WifiStatus selectTxPowerScenarioInternal(V1_1::IWifiChip::TxPowerScenario scenario);
226 WifiStatus resetTxPowerScenarioInternal();
227 WifiStatus setLatencyModeInternal(LatencyMode mode);
228 WifiStatus registerEventCallbackInternal_1_2(
229 const sp<V1_2::IWifiChipEventCallback>& event_callback);
230 WifiStatus selectTxPowerScenarioInternal_1_2(TxPowerScenario scenario);
231 std::pair<WifiStatus, uint32_t> getCapabilitiesInternal_1_3();
232 std::pair<WifiStatus, uint32_t> getCapabilitiesInternal_1_5();
233 std::pair<WifiStatus, sp<V1_4::IWifiRttController>> createRttControllerInternal_1_4(
234 const sp<IWifiIface>& bound_iface);
235 WifiStatus registerEventCallbackInternal_1_4(
236 const sp<V1_4::IWifiChipEventCallback>& event_callback);
237 WifiStatus setMultiStaPrimaryConnectionInternal(const std::string& ifname);
238 WifiStatus setMultiStaUseCaseInternal(MultiStaUseCase use_case);
239 WifiStatus setCoexUnsafeChannelsInternal(std::vector<CoexUnsafeChannel> unsafe_channels,
240 uint32_t restrictions);
241 WifiStatus setCountryCodeInternal(const std::array<int8_t, 2>& code);
Ahmed ElArabawy05571e42022-01-19 11:54:11 -0800242 std::pair<WifiStatus, std::vector<V1_5::WifiUsableChannel>> getUsableChannelsInternal(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800243 WifiBand band, uint32_t ifaceModeMask, uint32_t filterMask);
244 WifiStatus handleChipConfiguration(std::unique_lock<std::recursive_mutex>* lock,
245 ChipModeId mode_id);
246 WifiStatus registerDebugRingBufferCallback();
247 WifiStatus registerRadioModeChangeCallback();
Quang Luong5d8805e2022-01-28 15:46:40 -0800248 std::vector<V1_6::IWifiChip::ChipConcurrencyCombination>
249 getCurrentModeConcurrencyCombinations();
250 std::map<IfaceConcurrencyType, size_t> getCurrentConcurrencyCombination();
251 std::vector<std::map<IfaceConcurrencyType, size_t>> expandConcurrencyCombinations(
252 const V1_6::IWifiChip::ChipConcurrencyCombination& combination);
253 bool canExpandedConcurrencyComboSupportConcurrencyTypeWithCurrentTypes(
254 const std::map<IfaceConcurrencyType, size_t>& expanded_combo,
255 IfaceConcurrencyType requested_type);
256 bool canCurrentModeSupportConcurrencyTypeWithCurrentTypes(IfaceConcurrencyType requested_type);
257 bool canExpandedConcurrencyComboSupportConcurrencyCombo(
258 const std::map<IfaceConcurrencyType, size_t>& expanded_combo,
259 const std::map<IfaceConcurrencyType, size_t>& req_combo);
260 bool canCurrentModeSupportConcurrencyCombo(
261 const std::map<IfaceConcurrencyType, size_t>& req_combo);
262 bool canCurrentModeSupportConcurrencyType(IfaceConcurrencyType requested_type);
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800263 bool isValidModeId(ChipModeId mode_id);
264 bool isStaApConcurrencyAllowedInCurrentMode();
265 bool isDualStaConcurrencyAllowedInCurrentMode();
266 uint32_t startIdxOfApIface();
267 std::string getFirstActiveWlanIfaceName();
268 std::string allocateApOrStaIfaceName(IfaceType type, uint32_t start_idx);
269 std::string allocateApIfaceName();
270 std::vector<std::string> allocateBridgedApInstanceNames();
271 std::string allocateStaIfaceName();
272 bool writeRingbufferFilesInternal();
273 std::string getWlanIfaceNameWithType(IfaceType type, unsigned idx);
274 void invalidateAndClearBridgedApAll();
275 void invalidateAndClearBridgedAp(const std::string& br_name);
276 bool findUsingNameFromBridgedApInstances(const std::string& name);
277 WifiStatus triggerSubsystemRestartInternal();
Ahmed ElArabawy05571e42022-01-19 11:54:11 -0800278 std::pair<WifiStatus, sp<V1_6::IWifiRttController>> createRttControllerInternal_1_6(
279 const sp<IWifiIface>& bound_iface);
280 std::pair<WifiStatus, std::vector<V1_6::WifiUsableChannel>> getUsableChannelsInternal_1_6(
281 WifiBand band, uint32_t ifaceModeMask, uint32_t filterMask);
Sunil Ravief97d232022-01-24 10:39:56 -0800282 std::pair<WifiStatus, WifiRadioCombinationMatrix> getSupportedRadioCombinationsMatrixInternal();
Quang Luong5d8805e2022-01-28 15:46:40 -0800283 std::pair<WifiStatus, std::vector<V1_6::IWifiChip::ChipMode>> getAvailableModesInternal_1_6();
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800284
285 ChipId chip_id_;
286 std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
287 std::weak_ptr<mode_controller::WifiModeController> mode_controller_;
288 std::shared_ptr<iface_util::WifiIfaceUtil> iface_util_;
289 std::vector<sp<WifiApIface>> ap_ifaces_;
290 std::vector<sp<WifiNanIface>> nan_ifaces_;
291 std::vector<sp<WifiP2pIface>> p2p_ifaces_;
292 std::vector<sp<WifiStaIface>> sta_ifaces_;
293 std::vector<sp<WifiRttController>> rtt_controllers_;
294 std::map<std::string, Ringbuffer> ringbuffer_map_;
295 bool is_valid_;
296 // Members pertaining to chip configuration.
297 uint32_t current_mode_id_;
298 std::mutex lock_t;
Quang Luong5d8805e2022-01-28 15:46:40 -0800299 std::vector<V1_6::IWifiChip::ChipMode> modes_;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800300 // The legacy ring buffer callback API has only a global callback
301 // registration mechanism. Use this to check if we have already
302 // registered a callback.
303 bool debug_ring_buffer_cb_registered_;
304 hidl_callback_util::HidlCallbackHandler<V1_4::IWifiChipEventCallback> event_cb_handler_;
305
306 const std::function<void(const std::string&)> subsystemCallbackHandler_;
307 std::map<std::string, std::vector<std::string>> br_ifaces_ap_instances_;
308 DISALLOW_COPY_AND_ASSIGN(WifiChip);
309};
310
311} // namespace implementation
312} // namespace V1_6
313} // namespace wifi
314} // namespace hardware
315} // namespace android
316
317#endif // WIFI_CHIP_H_