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