blob: 13d62fb8dc2c891a0320602ee2d74125b92f24c0 [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;
Sunil Ravief97d232022-01-24 10:39:56 -0800163 Return<void> getSupportedRadioCombinationsMatrix(
164 getSupportedRadioCombinationsMatrix_cb hidl_status_cb) override;
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800165
166 private:
167 void invalidateAndRemoveAllIfaces();
168 // When a STA iface is removed any dependent NAN-ifaces/RTT-controllers are
169 // invalidated & removed.
170 void invalidateAndRemoveDependencies(const std::string& removed_iface_name);
171
172 // Corresponding worker functions for the HIDL methods.
173 std::pair<WifiStatus, ChipId> getIdInternal();
174 // Deprecated support for this callback
175 WifiStatus registerEventCallbackInternal(
176 const sp<V1_0::IWifiChipEventCallback>& event_callback);
177 std::pair<WifiStatus, uint32_t> getCapabilitiesInternal();
178 std::pair<WifiStatus, std::vector<ChipMode>> getAvailableModesInternal();
179 WifiStatus configureChipInternal(std::unique_lock<std::recursive_mutex>* lock,
180 ChipModeId mode_id);
181 std::pair<WifiStatus, uint32_t> getModeInternal();
182 std::pair<WifiStatus, IWifiChip::ChipDebugInfo> requestChipDebugInfoInternal();
183 std::pair<WifiStatus, std::vector<uint8_t>> requestDriverDebugDumpInternal();
184 std::pair<WifiStatus, std::vector<uint8_t>> requestFirmwareDebugDumpInternal();
185 sp<WifiApIface> newWifiApIface(std::string& ifname);
186 WifiStatus createVirtualApInterface(const std::string& apVirtIf);
187 std::pair<WifiStatus, sp<V1_5::IWifiApIface>> createApIfaceInternal();
188 std::pair<WifiStatus, sp<V1_5::IWifiApIface>> createBridgedApIfaceInternal();
189 std::pair<WifiStatus, std::vector<hidl_string>> getApIfaceNamesInternal();
190 std::pair<WifiStatus, sp<V1_5::IWifiApIface>> getApIfaceInternal(const std::string& ifname);
191 WifiStatus removeApIfaceInternal(const std::string& ifname);
192 WifiStatus removeIfaceInstanceFromBridgedApIfaceInternal(const std::string& brIfaceName,
193 const std::string& ifInstanceName);
194 std::pair<WifiStatus, sp<V1_4::IWifiNanIface>> createNanIfaceInternal();
195 std::pair<WifiStatus, std::vector<hidl_string>> getNanIfaceNamesInternal();
196 std::pair<WifiStatus, sp<V1_4::IWifiNanIface>> getNanIfaceInternal(const std::string& ifname);
197 WifiStatus removeNanIfaceInternal(const std::string& ifname);
198 std::pair<WifiStatus, sp<IWifiP2pIface>> createP2pIfaceInternal();
199 std::pair<WifiStatus, std::vector<hidl_string>> getP2pIfaceNamesInternal();
200 std::pair<WifiStatus, sp<IWifiP2pIface>> getP2pIfaceInternal(const std::string& ifname);
201 WifiStatus removeP2pIfaceInternal(const std::string& ifname);
Ahmed ElArabawy05571e42022-01-19 11:54:11 -0800202 std::pair<WifiStatus, sp<V1_6::IWifiStaIface>> createStaIfaceInternal();
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800203 std::pair<WifiStatus, std::vector<hidl_string>> getStaIfaceNamesInternal();
Ahmed ElArabawy05571e42022-01-19 11:54:11 -0800204 std::pair<WifiStatus, sp<V1_6::IWifiStaIface>> getStaIfaceInternal(const std::string& ifname);
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800205 WifiStatus removeStaIfaceInternal(const std::string& ifname);
206 std::pair<WifiStatus, sp<V1_0::IWifiRttController>> createRttControllerInternal(
207 const sp<IWifiIface>& bound_iface);
208 std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>>
209 getDebugRingBuffersStatusInternal();
210 WifiStatus startLoggingToDebugRingBufferInternal(const hidl_string& ring_name,
211 WifiDebugRingBufferVerboseLevel verbose_level,
212 uint32_t max_interval_in_sec,
213 uint32_t min_data_size_in_bytes);
214 WifiStatus forceDumpToDebugRingBufferInternal(const hidl_string& ring_name);
215 WifiStatus flushRingBufferToFileInternal();
216 WifiStatus stopLoggingToDebugRingBufferInternal();
217 std::pair<WifiStatus, WifiDebugHostWakeReasonStats> getDebugHostWakeReasonStatsInternal();
218 WifiStatus enableDebugErrorAlertsInternal(bool enable);
219 WifiStatus selectTxPowerScenarioInternal(V1_1::IWifiChip::TxPowerScenario scenario);
220 WifiStatus resetTxPowerScenarioInternal();
221 WifiStatus setLatencyModeInternal(LatencyMode mode);
222 WifiStatus registerEventCallbackInternal_1_2(
223 const sp<V1_2::IWifiChipEventCallback>& event_callback);
224 WifiStatus selectTxPowerScenarioInternal_1_2(TxPowerScenario scenario);
225 std::pair<WifiStatus, uint32_t> getCapabilitiesInternal_1_3();
226 std::pair<WifiStatus, uint32_t> getCapabilitiesInternal_1_5();
227 std::pair<WifiStatus, sp<V1_4::IWifiRttController>> createRttControllerInternal_1_4(
228 const sp<IWifiIface>& bound_iface);
229 WifiStatus registerEventCallbackInternal_1_4(
230 const sp<V1_4::IWifiChipEventCallback>& event_callback);
231 WifiStatus setMultiStaPrimaryConnectionInternal(const std::string& ifname);
232 WifiStatus setMultiStaUseCaseInternal(MultiStaUseCase use_case);
233 WifiStatus setCoexUnsafeChannelsInternal(std::vector<CoexUnsafeChannel> unsafe_channels,
234 uint32_t restrictions);
235 WifiStatus setCountryCodeInternal(const std::array<int8_t, 2>& code);
Ahmed ElArabawy05571e42022-01-19 11:54:11 -0800236 std::pair<WifiStatus, std::vector<V1_5::WifiUsableChannel>> getUsableChannelsInternal(
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800237 WifiBand band, uint32_t ifaceModeMask, uint32_t filterMask);
238 WifiStatus handleChipConfiguration(std::unique_lock<std::recursive_mutex>* lock,
239 ChipModeId mode_id);
240 WifiStatus registerDebugRingBufferCallback();
241 WifiStatus registerRadioModeChangeCallback();
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800242 std::vector<V1_4::IWifiChip::ChipIfaceCombination> getCurrentModeIfaceCombinations();
243 std::map<IfaceType, size_t> getCurrentIfaceCombination();
244 std::vector<std::map<IfaceType, size_t>> expandIfaceCombinations(
245 const V1_4::IWifiChip::ChipIfaceCombination& combination);
246 bool canExpandedIfaceComboSupportIfaceOfTypeWithCurrentIfaces(
247 const std::map<IfaceType, size_t>& expanded_combo, IfaceType requested_type);
248 bool canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(IfaceType requested_type);
249 bool canExpandedIfaceComboSupportIfaceCombo(const std::map<IfaceType, size_t>& expanded_combo,
250 const std::map<IfaceType, size_t>& req_combo);
251 bool canCurrentModeSupportIfaceCombo(const std::map<IfaceType, size_t>& req_combo);
252 bool canCurrentModeSupportIfaceOfType(IfaceType requested_type);
253 bool isValidModeId(ChipModeId mode_id);
254 bool isStaApConcurrencyAllowedInCurrentMode();
255 bool isDualStaConcurrencyAllowedInCurrentMode();
256 uint32_t startIdxOfApIface();
257 std::string getFirstActiveWlanIfaceName();
258 std::string allocateApOrStaIfaceName(IfaceType type, uint32_t start_idx);
259 std::string allocateApIfaceName();
260 std::vector<std::string> allocateBridgedApInstanceNames();
261 std::string allocateStaIfaceName();
262 bool writeRingbufferFilesInternal();
263 std::string getWlanIfaceNameWithType(IfaceType type, unsigned idx);
264 void invalidateAndClearBridgedApAll();
265 void invalidateAndClearBridgedAp(const std::string& br_name);
266 bool findUsingNameFromBridgedApInstances(const std::string& name);
267 WifiStatus triggerSubsystemRestartInternal();
Ahmed ElArabawy05571e42022-01-19 11:54:11 -0800268 std::pair<WifiStatus, sp<V1_6::IWifiRttController>> createRttControllerInternal_1_6(
269 const sp<IWifiIface>& bound_iface);
270 std::pair<WifiStatus, std::vector<V1_6::WifiUsableChannel>> getUsableChannelsInternal_1_6(
271 WifiBand band, uint32_t ifaceModeMask, uint32_t filterMask);
Sunil Ravief97d232022-01-24 10:39:56 -0800272 std::pair<WifiStatus, WifiRadioCombinationMatrix> getSupportedRadioCombinationsMatrixInternal();
Ahmed ElArabawy687ce132022-01-11 16:42:48 -0800273
274 ChipId chip_id_;
275 std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
276 std::weak_ptr<mode_controller::WifiModeController> mode_controller_;
277 std::shared_ptr<iface_util::WifiIfaceUtil> iface_util_;
278 std::vector<sp<WifiApIface>> ap_ifaces_;
279 std::vector<sp<WifiNanIface>> nan_ifaces_;
280 std::vector<sp<WifiP2pIface>> p2p_ifaces_;
281 std::vector<sp<WifiStaIface>> sta_ifaces_;
282 std::vector<sp<WifiRttController>> rtt_controllers_;
283 std::map<std::string, Ringbuffer> ringbuffer_map_;
284 bool is_valid_;
285 // Members pertaining to chip configuration.
286 uint32_t current_mode_id_;
287 std::mutex lock_t;
288 std::vector<V1_4::IWifiChip::ChipMode> modes_;
289 // The legacy ring buffer callback API has only a global callback
290 // registration mechanism. Use this to check if we have already
291 // registered a callback.
292 bool debug_ring_buffer_cb_registered_;
293 hidl_callback_util::HidlCallbackHandler<V1_4::IWifiChipEventCallback> event_cb_handler_;
294
295 const std::function<void(const std::string&)> subsystemCallbackHandler_;
296 std::map<std::string, std::vector<std::string>> br_ifaces_ap_instances_;
297 DISALLOW_COPY_AND_ASSIGN(WifiChip);
298};
299
300} // namespace implementation
301} // namespace V1_6
302} // namespace wifi
303} // namespace hardware
304} // namespace android
305
306#endif // WIFI_CHIP_H_