blob: c76eabf18e6d02fbdf754161cf6e70b94e229a81 [file] [log] [blame]
Roshan Pius3c4e8a32016-10-03 14:53:58 -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#ifndef WIFI_CHIP_H_
18#define WIFI_CHIP_H_
19
xshu5899e8e2018-01-09 15:36:03 -080020#include <list>
Roshan Pius35d958c2016-10-06 16:47:38 -070021#include <map>
Roshan Pius3c4e8a32016-10-03 14:53:58 -070022
Roshan Pius3c4e8a32016-10-03 14:53:58 -070023#include <android-base/macros.h>
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -070024#include <android/hardware/wifi/1.4/IWifiChip.h>
25#include <android/hardware/wifi/1.4/IWifiRttController.h>
Roshan Pius3c4e8a32016-10-03 14:53:58 -070026
Roshan Piusd37341f2017-01-31 13:13:28 -080027#include "hidl_callback_util.h"
xshu5899e8e2018-01-09 15:36:03 -080028#include "ringbuffer.h"
Roshan Pius35d958c2016-10-06 16:47:38 -070029#include "wifi_ap_iface.h"
Roshan Pius200a17d2017-11-01 13:03:35 -070030#include "wifi_feature_flags.h"
Roshan Piusaabe5752016-09-29 09:03:59 -070031#include "wifi_legacy_hal.h"
Roshan Pius52947fb2016-11-18 11:38:07 -080032#include "wifi_mode_controller.h"
Roshan Pius35d958c2016-10-06 16:47:38 -070033#include "wifi_nan_iface.h"
34#include "wifi_p2p_iface.h"
Roshan Pius59268282016-10-06 20:23:47 -070035#include "wifi_rtt_controller.h"
Roshan Pius35d958c2016-10-06 16:47:38 -070036#include "wifi_sta_iface.h"
Roshan Pius3c4e8a32016-10-03 14:53:58 -070037
38namespace android {
39namespace hardware {
40namespace wifi {
Ahmed ElArabawyf501a982019-07-23 15:02:22 -070041namespace V1_4 {
Roshan Pius79a99752016-10-04 13:03:58 -070042namespace implementation {
Roshan Piusdbd83ef2017-06-20 12:05:40 -070043using namespace android::hardware::wifi::V1_0;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070044
Roshan Piusaabe5752016-09-29 09:03:59 -070045/**
46 * HIDL interface object used to control a Wifi HAL chip instance.
47 * Since there is only a single chip instance used today, there is no
48 * identifying handle information stored here.
49 */
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -070050class WifiChip : public V1_4::IWifiChip {
Roshan Piusabcf78f2017-10-06 16:30:38 -070051 public:
Roshan Pius200a17d2017-11-01 13:03:35 -070052 WifiChip(
53 ChipId chip_id,
54 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
55 const std::weak_ptr<mode_controller::WifiModeController>
56 mode_controller,
Roshan Pius99dab382019-02-14 07:57:10 -080057 const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util,
Roshan Pius200a17d2017-11-01 13:03:35 -070058 const std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags);
Roshan Piusabcf78f2017-10-06 16:30:38 -070059 // HIDL does not provide a built-in mechanism to let the server invalidate
60 // a HIDL interface object after creation. If any client process holds onto
61 // a reference to the object in their context, any method calls on that
62 // reference will continue to be directed to the server.
63 //
64 // However Wifi HAL needs to control the lifetime of these objects. So, add
65 // a public |invalidate| method to |WifiChip| and it's child objects. This
66 // will be used to mark an object invalid when either:
67 // a) Wifi HAL is stopped, or
68 // b) Wifi Chip is reconfigured.
69 //
70 // All HIDL method implementations should check if the object is still
71 // marked valid before processing them.
72 void invalidate();
73 bool isValid();
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -080074 std::set<sp<IWifiChipEventCallback>> getEventCallbacks();
Roshan Pius3c4e8a32016-10-03 14:53:58 -070075
Roshan Piusabcf78f2017-10-06 16:30:38 -070076 // HIDL methods exposed.
77 Return<void> getId(getId_cb hidl_status_cb) override;
Jong Wook Kimda830c92018-07-23 15:29:38 -070078 // Deprecated support for this callback
Roshan Piusabcf78f2017-10-06 16:30:38 -070079 Return<void> registerEventCallback(
Roshan Pius1ce92cf2018-01-22 16:12:19 -080080 const sp<V1_0::IWifiChipEventCallback>& event_callback,
Roshan Piusabcf78f2017-10-06 16:30:38 -070081 registerEventCallback_cb hidl_status_cb) override;
82 Return<void> getCapabilities(getCapabilities_cb hidl_status_cb) override;
83 Return<void> getAvailableModes(
84 getAvailableModes_cb hidl_status_cb) override;
85 Return<void> configureChip(ChipModeId mode_id,
86 configureChip_cb hidl_status_cb) override;
87 Return<void> getMode(getMode_cb hidl_status_cb) override;
88 Return<void> requestChipDebugInfo(
89 requestChipDebugInfo_cb hidl_status_cb) override;
90 Return<void> requestDriverDebugDump(
91 requestDriverDebugDump_cb hidl_status_cb) override;
92 Return<void> requestFirmwareDebugDump(
93 requestFirmwareDebugDump_cb hidl_status_cb) override;
94 Return<void> createApIface(createApIface_cb hidl_status_cb) override;
95 Return<void> getApIfaceNames(getApIfaceNames_cb hidl_status_cb) override;
96 Return<void> getApIface(const hidl_string& ifname,
97 getApIface_cb hidl_status_cb) override;
98 Return<void> removeApIface(const hidl_string& ifname,
99 removeApIface_cb hidl_status_cb) override;
100 Return<void> createNanIface(createNanIface_cb hidl_status_cb) override;
101 Return<void> getNanIfaceNames(getNanIfaceNames_cb hidl_status_cb) override;
102 Return<void> getNanIface(const hidl_string& ifname,
103 getNanIface_cb hidl_status_cb) override;
104 Return<void> removeNanIface(const hidl_string& ifname,
105 removeNanIface_cb hidl_status_cb) override;
106 Return<void> createP2pIface(createP2pIface_cb hidl_status_cb) override;
107 Return<void> getP2pIfaceNames(getP2pIfaceNames_cb hidl_status_cb) override;
108 Return<void> getP2pIface(const hidl_string& ifname,
109 getP2pIface_cb hidl_status_cb) override;
110 Return<void> removeP2pIface(const hidl_string& ifname,
111 removeP2pIface_cb hidl_status_cb) override;
112 Return<void> createStaIface(createStaIface_cb hidl_status_cb) override;
113 Return<void> getStaIfaceNames(getStaIfaceNames_cb hidl_status_cb) override;
114 Return<void> getStaIface(const hidl_string& ifname,
115 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(
119 const sp<IWifiIface>& bound_iface,
120 createRttController_cb hidl_status_cb) override;
121 Return<void> getDebugRingBuffersStatus(
122 getDebugRingBuffersStatus_cb hidl_status_cb) override;
123 Return<void> startLoggingToDebugRingBuffer(
124 const hidl_string& ring_name,
125 WifiDebugRingBufferVerboseLevel verbose_level,
126 uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes,
127 startLoggingToDebugRingBuffer_cb hidl_status_cb) override;
128 Return<void> forceDumpToDebugRingBuffer(
129 const hidl_string& ring_name,
130 forceDumpToDebugRingBuffer_cb hidl_status_cb) override;
Roger Wangb294c762018-11-02 15:34:39 +0800131 Return<void> flushRingBufferToFile(
132 flushRingBufferToFile_cb hidl_status_cb) override;
Roshan Piusabcf78f2017-10-06 16:30:38 -0700133 Return<void> stopLoggingToDebugRingBuffer(
134 stopLoggingToDebugRingBuffer_cb hidl_status_cb) override;
135 Return<void> getDebugHostWakeReasonStats(
136 getDebugHostWakeReasonStats_cb hidl_status_cb) override;
137 Return<void> enableDebugErrorAlerts(
138 bool enable, enableDebugErrorAlerts_cb hidl_status_cb) override;
139 Return<void> selectTxPowerScenario(
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -0800140 V1_1::IWifiChip::TxPowerScenario scenario,
Roshan Piusabcf78f2017-10-06 16:30:38 -0700141 selectTxPowerScenario_cb hidl_status_cb) override;
142 Return<void> resetTxPowerScenario(
143 resetTxPowerScenario_cb hidl_status_cb) override;
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700144 Return<void> setLatencyMode(LatencyMode mode,
145 setLatencyMode_cb hidl_status_cb) override;
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800146 Return<void> registerEventCallback_1_2(
Jong Wook Kimda830c92018-07-23 15:29:38 -0700147 const sp<V1_2::IWifiChipEventCallback>& event_callback,
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800148 registerEventCallback_1_2_cb hidl_status_cb) override;
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -0800149 Return<void> selectTxPowerScenario_1_2(
150 TxPowerScenario scenario,
151 selectTxPowerScenario_cb hidl_status_cb) override;
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700152 Return<void> getCapabilities_1_3(
153 getCapabilities_cb hidl_status_cb) override;
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -0800154 Return<void> debug(const hidl_handle& handle,
155 const hidl_vec<hidl_string>& options) override;
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700156 Return<void> createRttController_1_4(
157 const sp<IWifiIface>& bound_iface,
158 createRttController_1_4_cb hidl_status_cb) override;
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -0800159 Return<void> registerEventCallback_1_4(
160 const sp<IWifiChipEventCallback>& event_callback,
161 registerEventCallback_1_4_cb hidl_status_cb) override;
Jong Wook Kimda830c92018-07-23 15:29:38 -0700162
Roshan Piusabcf78f2017-10-06 16:30:38 -0700163 private:
164 void invalidateAndRemoveAllIfaces();
Roshan Pius82368502019-05-16 12:53:02 -0700165 // When a STA iface is removed any dependent NAN-ifaces/RTT-controllers are
166 // invalidated & removed.
167 void invalidateAndRemoveDependencies(const std::string& removed_iface_name);
Roshan Pius35d958c2016-10-06 16:47:38 -0700168
Roshan Piusabcf78f2017-10-06 16:30:38 -0700169 // Corresponding worker functions for the HIDL methods.
170 std::pair<WifiStatus, ChipId> getIdInternal();
Jong Wook Kimda830c92018-07-23 15:29:38 -0700171 // Deprecated support for this callback
Roshan Piusabcf78f2017-10-06 16:30:38 -0700172 WifiStatus registerEventCallbackInternal(
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800173 const sp<V1_0::IWifiChipEventCallback>& event_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700174 std::pair<WifiStatus, uint32_t> getCapabilitiesInternal();
175 std::pair<WifiStatus, std::vector<ChipMode>> getAvailableModesInternal();
Roshan Piusba38d9c2017-12-08 07:32:08 -0800176 WifiStatus configureChipInternal(
177 std::unique_lock<std::recursive_mutex>* lock, ChipModeId mode_id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700178 std::pair<WifiStatus, uint32_t> getModeInternal();
179 std::pair<WifiStatus, IWifiChip::ChipDebugInfo>
180 requestChipDebugInfoInternal();
181 std::pair<WifiStatus, std::vector<uint8_t>>
182 requestDriverDebugDumpInternal();
183 std::pair<WifiStatus, std::vector<uint8_t>>
184 requestFirmwareDebugDumpInternal();
185 std::pair<WifiStatus, sp<IWifiApIface>> createApIfaceInternal();
186 std::pair<WifiStatus, std::vector<hidl_string>> getApIfaceNamesInternal();
187 std::pair<WifiStatus, sp<IWifiApIface>> getApIfaceInternal(
188 const std::string& ifname);
189 WifiStatus removeApIfaceInternal(const std::string& ifname);
190 std::pair<WifiStatus, sp<IWifiNanIface>> createNanIfaceInternal();
191 std::pair<WifiStatus, std::vector<hidl_string>> getNanIfaceNamesInternal();
192 std::pair<WifiStatus, sp<IWifiNanIface>> getNanIfaceInternal(
193 const std::string& ifname);
194 WifiStatus removeNanIfaceInternal(const std::string& ifname);
195 std::pair<WifiStatus, sp<IWifiP2pIface>> createP2pIfaceInternal();
196 std::pair<WifiStatus, std::vector<hidl_string>> getP2pIfaceNamesInternal();
197 std::pair<WifiStatus, sp<IWifiP2pIface>> getP2pIfaceInternal(
198 const std::string& ifname);
199 WifiStatus removeP2pIfaceInternal(const std::string& ifname);
200 std::pair<WifiStatus, sp<IWifiStaIface>> createStaIfaceInternal();
201 std::pair<WifiStatus, std::vector<hidl_string>> getStaIfaceNamesInternal();
202 std::pair<WifiStatus, sp<IWifiStaIface>> getStaIfaceInternal(
203 const std::string& ifname);
204 WifiStatus removeStaIfaceInternal(const std::string& ifname);
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700205 std::pair<WifiStatus, sp<V1_0::IWifiRttController>>
206 createRttControllerInternal(const sp<IWifiIface>& bound_iface);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700207 std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>>
208 getDebugRingBuffersStatusInternal();
209 WifiStatus startLoggingToDebugRingBufferInternal(
210 const hidl_string& ring_name,
211 WifiDebugRingBufferVerboseLevel verbose_level,
212 uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes);
213 WifiStatus forceDumpToDebugRingBufferInternal(const hidl_string& ring_name);
Roger Wangb294c762018-11-02 15:34:39 +0800214 WifiStatus flushRingBufferToFileInternal();
Roshan Piusabcf78f2017-10-06 16:30:38 -0700215 WifiStatus stopLoggingToDebugRingBufferInternal();
216 std::pair<WifiStatus, WifiDebugHostWakeReasonStats>
217 getDebugHostWakeReasonStatsInternal();
218 WifiStatus enableDebugErrorAlertsInternal(bool enable);
Jong Wook Kimda830c92018-07-23 15:29:38 -0700219 WifiStatus selectTxPowerScenarioInternal(
220 V1_1::IWifiChip::TxPowerScenario scenario);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700221 WifiStatus resetTxPowerScenarioInternal();
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700222 WifiStatus setLatencyModeInternal(LatencyMode mode);
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800223 WifiStatus registerEventCallbackInternal_1_2(
Jong Wook Kimda830c92018-07-23 15:29:38 -0700224 const sp<V1_2::IWifiChipEventCallback>& event_callback);
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -0800225 WifiStatus selectTxPowerScenarioInternal_1_2(TxPowerScenario scenario);
Ahmed ElArabawyeaf82402018-10-26 09:46:04 -0700226 std::pair<WifiStatus, uint32_t> getCapabilitiesInternal_1_3();
Ahmed ElArabawyeeb53382019-10-10 20:18:31 -0700227 std::pair<WifiStatus, sp<IWifiRttController>>
228 createRttControllerInternal_1_4(const sp<IWifiIface>& bound_iface);
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -0800229 WifiStatus registerEventCallbackInternal_1_4(
230 const sp<IWifiChipEventCallback>& event_callback);
231
Roshan Piusba38d9c2017-12-08 07:32:08 -0800232 WifiStatus handleChipConfiguration(
233 std::unique_lock<std::recursive_mutex>* lock, ChipModeId mode_id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700234 WifiStatus registerDebugRingBufferCallback();
Roshan Pius85c64412018-01-22 17:58:40 -0800235 WifiStatus registerRadioModeChangeCallback();
Roshan Pius2c06a3f2016-12-15 17:51:40 -0800236
Roshan Piuscc338202017-11-02 13:54:09 -0700237 std::vector<IWifiChip::ChipIfaceCombination>
238 getCurrentModeIfaceCombinations();
239 std::map<IfaceType, size_t> getCurrentIfaceCombination();
240 std::vector<std::map<IfaceType, size_t>> expandIfaceCombinations(
241 const IWifiChip::ChipIfaceCombination& combination);
Roshan Piusa3e5b7f2019-03-25 13:52:45 -0700242 bool canExpandedIfaceComboSupportIfaceOfTypeWithCurrentIfaces(
243 const std::map<IfaceType, size_t>& expanded_combo,
244 IfaceType requested_type);
245 bool canCurrentModeSupportIfaceOfTypeWithCurrentIfaces(
246 IfaceType requested_type);
247 bool canExpandedIfaceComboSupportIfaceCombo(
248 const std::map<IfaceType, size_t>& expanded_combo,
249 const std::map<IfaceType, size_t>& req_combo);
250 bool canCurrentModeSupportIfaceCombo(
251 const std::map<IfaceType, size_t>& req_combo);
252 bool canCurrentModeSupportIfaceOfType(IfaceType requested_type);
Roshan Piuscc338202017-11-02 13:54:09 -0700253 bool isValidModeId(ChipModeId mode_id);
Roshan Piusa3e5b7f2019-03-25 13:52:45 -0700254 bool isStaApConcurrencyAllowedInCurrentMode();
James Mattisd2e4c072019-05-22 16:14:48 -0700255 bool isDualApAllowedInCurrentMode();
Roshan Pius6036c022019-03-27 10:41:58 -0700256 std::string getFirstActiveWlanIfaceName();
Roshan Piusa3e5b7f2019-03-25 13:52:45 -0700257 std::string allocateApOrStaIfaceName(uint32_t start_idx);
258 std::string allocateApIfaceName();
259 std::string allocateStaIfaceName();
xshu5899e8e2018-01-09 15:36:03 -0800260 bool writeRingbufferFilesInternal();
Roshan Piuscc338202017-11-02 13:54:09 -0700261
Roshan Piusabcf78f2017-10-06 16:30:38 -0700262 ChipId chip_id_;
263 std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
264 std::weak_ptr<mode_controller::WifiModeController> mode_controller_;
Roshan Pius99dab382019-02-14 07:57:10 -0800265 std::weak_ptr<iface_util::WifiIfaceUtil> iface_util_;
Roshan Pius675609b2017-10-31 14:24:58 -0700266 std::vector<sp<WifiApIface>> ap_ifaces_;
267 std::vector<sp<WifiNanIface>> nan_ifaces_;
268 std::vector<sp<WifiP2pIface>> p2p_ifaces_;
269 std::vector<sp<WifiStaIface>> sta_ifaces_;
Roshan Piusabcf78f2017-10-06 16:30:38 -0700270 std::vector<sp<WifiRttController>> rtt_controllers_;
xshu5899e8e2018-01-09 15:36:03 -0800271 std::map<std::string, Ringbuffer> ringbuffer_map_;
Roshan Piusabcf78f2017-10-06 16:30:38 -0700272 bool is_valid_;
Roshan Piuscc338202017-11-02 13:54:09 -0700273 // Members pertaining to chip configuration.
Roshan Piusabcf78f2017-10-06 16:30:38 -0700274 uint32_t current_mode_id_;
Roshan Piuscc338202017-11-02 13:54:09 -0700275 std::vector<IWifiChip::ChipMode> modes_;
Roshan Piusabcf78f2017-10-06 16:30:38 -0700276 // The legacy ring buffer callback API has only a global callback
277 // registration mechanism. Use this to check if we have already
278 // registered a callback.
279 bool debug_ring_buffer_cb_registered_;
Ahmed ElArabawyfd809fc2019-11-15 18:19:15 -0800280 hidl_callback_util::HidlCallbackHandler<IWifiChipEventCallback>
Roshan Piusabcf78f2017-10-06 16:30:38 -0700281 event_cb_handler_;
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700282
Roshan Piusabcf78f2017-10-06 16:30:38 -0700283 DISALLOW_COPY_AND_ASSIGN(WifiChip);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700284};
285
Roshan Pius79a99752016-10-04 13:03:58 -0700286} // namespace implementation
Ahmed ElArabawyf501a982019-07-23 15:02:22 -0700287} // namespace V1_4
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700288} // namespace wifi
289} // namespace hardware
290} // namespace android
291
292#endif // WIFI_CHIP_H_