blob: c51f6b1e2793c3581e075aceed69546742fe64da [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>
Etan Cohen9649e542017-12-21 08:41:34 -080024#include <android/hardware/wifi/1.2/IWifiChip.h>
Roshan Pius3c4e8a32016-10-03 14:53:58 -070025
Roshan Piusd37341f2017-01-31 13:13:28 -080026#include "hidl_callback_util.h"
xshu5899e8e2018-01-09 15:36:03 -080027#include "ringbuffer.h"
Roshan Pius35d958c2016-10-06 16:47:38 -070028#include "wifi_ap_iface.h"
Roshan Pius200a17d2017-11-01 13:03:35 -070029#include "wifi_feature_flags.h"
Roshan Piusaabe5752016-09-29 09:03:59 -070030#include "wifi_legacy_hal.h"
Roshan Pius52947fb2016-11-18 11:38:07 -080031#include "wifi_mode_controller.h"
Roshan Pius35d958c2016-10-06 16:47:38 -070032#include "wifi_nan_iface.h"
33#include "wifi_p2p_iface.h"
Roshan Pius59268282016-10-06 20:23:47 -070034#include "wifi_rtt_controller.h"
Roshan Pius35d958c2016-10-06 16:47:38 -070035#include "wifi_sta_iface.h"
Roshan Pius3c4e8a32016-10-03 14:53:58 -070036
37namespace android {
38namespace hardware {
39namespace wifi {
Etan Cohen6ce50902017-09-14 07:30:57 -070040namespace V1_2 {
Roshan Pius79a99752016-10-04 13:03:58 -070041namespace implementation {
Roshan Piusdbd83ef2017-06-20 12:05:40 -070042using namespace android::hardware::wifi::V1_0;
Roshan Pius3c4e8a32016-10-03 14:53:58 -070043
Roshan Piusaabe5752016-09-29 09:03:59 -070044/**
45 * HIDL interface object used to control a Wifi HAL chip instance.
46 * Since there is only a single chip instance used today, there is no
47 * identifying handle information stored here.
48 */
Etan Cohen9649e542017-12-21 08:41:34 -080049class WifiChip : public V1_2::IWifiChip {
Roshan Piusabcf78f2017-10-06 16:30:38 -070050 public:
Roshan Pius200a17d2017-11-01 13:03:35 -070051 WifiChip(
52 ChipId chip_id,
53 const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal,
54 const std::weak_ptr<mode_controller::WifiModeController>
55 mode_controller,
56 const std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags);
Roshan Piusabcf78f2017-10-06 16:30:38 -070057 // HIDL does not provide a built-in mechanism to let the server invalidate
58 // a HIDL interface object after creation. If any client process holds onto
59 // a reference to the object in their context, any method calls on that
60 // reference will continue to be directed to the server.
61 //
62 // However Wifi HAL needs to control the lifetime of these objects. So, add
63 // a public |invalidate| method to |WifiChip| and it's child objects. This
64 // will be used to mark an object invalid when either:
65 // a) Wifi HAL is stopped, or
66 // b) Wifi Chip is reconfigured.
67 //
68 // All HIDL method implementations should check if the object is still
69 // marked valid before processing them.
70 void invalidate();
71 bool isValid();
72 std::set<sp<IWifiChipEventCallback>> getEventCallbacks();
Roshan Pius3c4e8a32016-10-03 14:53:58 -070073
Roshan Piusabcf78f2017-10-06 16:30:38 -070074 // HIDL methods exposed.
75 Return<void> getId(getId_cb hidl_status_cb) override;
76 Return<void> registerEventCallback(
Roshan Pius1ce92cf2018-01-22 16:12:19 -080077 const sp<V1_0::IWifiChipEventCallback>& event_callback,
Roshan Piusabcf78f2017-10-06 16:30:38 -070078 registerEventCallback_cb hidl_status_cb) override;
79 Return<void> getCapabilities(getCapabilities_cb hidl_status_cb) override;
80 Return<void> getAvailableModes(
81 getAvailableModes_cb hidl_status_cb) override;
82 Return<void> configureChip(ChipModeId mode_id,
83 configureChip_cb hidl_status_cb) override;
84 Return<void> getMode(getMode_cb hidl_status_cb) override;
85 Return<void> requestChipDebugInfo(
86 requestChipDebugInfo_cb hidl_status_cb) override;
87 Return<void> requestDriverDebugDump(
88 requestDriverDebugDump_cb hidl_status_cb) override;
89 Return<void> requestFirmwareDebugDump(
90 requestFirmwareDebugDump_cb hidl_status_cb) override;
91 Return<void> createApIface(createApIface_cb hidl_status_cb) override;
92 Return<void> getApIfaceNames(getApIfaceNames_cb hidl_status_cb) override;
93 Return<void> getApIface(const hidl_string& ifname,
94 getApIface_cb hidl_status_cb) override;
95 Return<void> removeApIface(const hidl_string& ifname,
96 removeApIface_cb hidl_status_cb) override;
97 Return<void> createNanIface(createNanIface_cb hidl_status_cb) override;
98 Return<void> getNanIfaceNames(getNanIfaceNames_cb hidl_status_cb) override;
99 Return<void> getNanIface(const hidl_string& ifname,
100 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,
106 getP2pIface_cb hidl_status_cb) override;
107 Return<void> removeP2pIface(const hidl_string& ifname,
108 removeP2pIface_cb hidl_status_cb) override;
109 Return<void> createStaIface(createStaIface_cb hidl_status_cb) override;
110 Return<void> getStaIfaceNames(getStaIfaceNames_cb hidl_status_cb) override;
111 Return<void> getStaIface(const hidl_string& ifname,
112 getStaIface_cb hidl_status_cb) override;
113 Return<void> removeStaIface(const hidl_string& ifname,
114 removeStaIface_cb hidl_status_cb) override;
115 Return<void> createRttController(
116 const sp<IWifiIface>& bound_iface,
117 createRttController_cb hidl_status_cb) override;
118 Return<void> getDebugRingBuffersStatus(
119 getDebugRingBuffersStatus_cb hidl_status_cb) override;
120 Return<void> startLoggingToDebugRingBuffer(
121 const hidl_string& ring_name,
122 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(
126 const hidl_string& ring_name,
127 forceDumpToDebugRingBuffer_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(
133 bool enable, enableDebugErrorAlerts_cb hidl_status_cb) override;
134 Return<void> selectTxPowerScenario(
135 TxPowerScenario scenario,
136 selectTxPowerScenario_cb hidl_status_cb) override;
137 Return<void> resetTxPowerScenario(
138 resetTxPowerScenario_cb hidl_status_cb) override;
xshu5899e8e2018-01-09 15:36:03 -0800139 Return<void> debug(const hidl_handle& handle,
140 const hidl_vec<hidl_string>& options) override;
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800141 Return<void> registerEventCallback_1_2(
142 const sp<IWifiChipEventCallback>& event_callback,
143 registerEventCallback_1_2_cb hidl_status_cb) override;
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700144
Roshan Piusabcf78f2017-10-06 16:30:38 -0700145 private:
146 void invalidateAndRemoveAllIfaces();
Roshan Pius35d958c2016-10-06 16:47:38 -0700147
Roshan Piusabcf78f2017-10-06 16:30:38 -0700148 // Corresponding worker functions for the HIDL methods.
149 std::pair<WifiStatus, ChipId> getIdInternal();
150 WifiStatus registerEventCallbackInternal(
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800151 const sp<V1_0::IWifiChipEventCallback>& event_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700152 std::pair<WifiStatus, uint32_t> getCapabilitiesInternal();
153 std::pair<WifiStatus, std::vector<ChipMode>> getAvailableModesInternal();
Roshan Piusba38d9c2017-12-08 07:32:08 -0800154 WifiStatus configureChipInternal(
155 std::unique_lock<std::recursive_mutex>* lock, ChipModeId mode_id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700156 std::pair<WifiStatus, uint32_t> getModeInternal();
157 std::pair<WifiStatus, IWifiChip::ChipDebugInfo>
158 requestChipDebugInfoInternal();
159 std::pair<WifiStatus, std::vector<uint8_t>>
160 requestDriverDebugDumpInternal();
161 std::pair<WifiStatus, std::vector<uint8_t>>
162 requestFirmwareDebugDumpInternal();
163 std::pair<WifiStatus, sp<IWifiApIface>> createApIfaceInternal();
164 std::pair<WifiStatus, std::vector<hidl_string>> getApIfaceNamesInternal();
165 std::pair<WifiStatus, sp<IWifiApIface>> getApIfaceInternal(
166 const std::string& ifname);
167 WifiStatus removeApIfaceInternal(const std::string& ifname);
168 std::pair<WifiStatus, sp<IWifiNanIface>> createNanIfaceInternal();
169 std::pair<WifiStatus, std::vector<hidl_string>> getNanIfaceNamesInternal();
170 std::pair<WifiStatus, sp<IWifiNanIface>> getNanIfaceInternal(
171 const std::string& ifname);
172 WifiStatus removeNanIfaceInternal(const std::string& ifname);
173 std::pair<WifiStatus, sp<IWifiP2pIface>> createP2pIfaceInternal();
174 std::pair<WifiStatus, std::vector<hidl_string>> getP2pIfaceNamesInternal();
175 std::pair<WifiStatus, sp<IWifiP2pIface>> getP2pIfaceInternal(
176 const std::string& ifname);
177 WifiStatus removeP2pIfaceInternal(const std::string& ifname);
178 std::pair<WifiStatus, sp<IWifiStaIface>> createStaIfaceInternal();
179 std::pair<WifiStatus, std::vector<hidl_string>> getStaIfaceNamesInternal();
180 std::pair<WifiStatus, sp<IWifiStaIface>> getStaIfaceInternal(
181 const std::string& ifname);
182 WifiStatus removeStaIfaceInternal(const std::string& ifname);
183 std::pair<WifiStatus, sp<IWifiRttController>> createRttControllerInternal(
184 const sp<IWifiIface>& bound_iface);
185 std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>>
186 getDebugRingBuffersStatusInternal();
187 WifiStatus startLoggingToDebugRingBufferInternal(
188 const hidl_string& ring_name,
189 WifiDebugRingBufferVerboseLevel verbose_level,
190 uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes);
191 WifiStatus forceDumpToDebugRingBufferInternal(const hidl_string& ring_name);
192 WifiStatus stopLoggingToDebugRingBufferInternal();
193 std::pair<WifiStatus, WifiDebugHostWakeReasonStats>
194 getDebugHostWakeReasonStatsInternal();
195 WifiStatus enableDebugErrorAlertsInternal(bool enable);
196 WifiStatus selectTxPowerScenarioInternal(TxPowerScenario scenario);
197 WifiStatus resetTxPowerScenarioInternal();
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800198 WifiStatus registerEventCallbackInternal_1_2(
199 const sp<IWifiChipEventCallback>& event_callback);
Roshan Pius3c868522016-10-27 12:43:49 -0700200
Roshan Piusba38d9c2017-12-08 07:32:08 -0800201 WifiStatus handleChipConfiguration(
202 std::unique_lock<std::recursive_mutex>* lock, ChipModeId mode_id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700203 WifiStatus registerDebugRingBufferCallback();
Roshan Pius2c06a3f2016-12-15 17:51:40 -0800204
Roshan Piuscc338202017-11-02 13:54:09 -0700205 void populateModes();
206 std::vector<IWifiChip::ChipIfaceCombination>
207 getCurrentModeIfaceCombinations();
208 std::map<IfaceType, size_t> getCurrentIfaceCombination();
209 std::vector<std::map<IfaceType, size_t>> expandIfaceCombinations(
210 const IWifiChip::ChipIfaceCombination& combination);
211 bool canExpandedIfaceCombinationSupportIfaceOfType(
212 const std::map<IfaceType, size_t>& combo, IfaceType type);
213 bool canCurrentModeSupportIfaceOfType(IfaceType type);
214 bool isValidModeId(ChipModeId mode_id);
Roshan Pius8e3c7ef2017-11-03 09:43:08 -0700215 std::string allocateApOrStaIfaceName();
xshu5899e8e2018-01-09 15:36:03 -0800216 bool writeRingbufferFilesInternal();
Roshan Piuscc338202017-11-02 13:54:09 -0700217
Roshan Piusabcf78f2017-10-06 16:30:38 -0700218 ChipId chip_id_;
219 std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
220 std::weak_ptr<mode_controller::WifiModeController> mode_controller_;
Roshan Pius200a17d2017-11-01 13:03:35 -0700221 std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags_;
Roshan Pius675609b2017-10-31 14:24:58 -0700222 std::vector<sp<WifiApIface>> ap_ifaces_;
223 std::vector<sp<WifiNanIface>> nan_ifaces_;
224 std::vector<sp<WifiP2pIface>> p2p_ifaces_;
225 std::vector<sp<WifiStaIface>> sta_ifaces_;
Roshan Piusabcf78f2017-10-06 16:30:38 -0700226 std::vector<sp<WifiRttController>> rtt_controllers_;
xshu5899e8e2018-01-09 15:36:03 -0800227 std::map<std::string, Ringbuffer> ringbuffer_map_;
Roshan Piusabcf78f2017-10-06 16:30:38 -0700228 bool is_valid_;
Roshan Piuscc338202017-11-02 13:54:09 -0700229 // Members pertaining to chip configuration.
Roshan Piusabcf78f2017-10-06 16:30:38 -0700230 uint32_t current_mode_id_;
Roshan Piuscc338202017-11-02 13:54:09 -0700231 std::vector<IWifiChip::ChipMode> modes_;
Roshan Piusabcf78f2017-10-06 16:30:38 -0700232 // The legacy ring buffer callback API has only a global callback
233 // registration mechanism. Use this to check if we have already
234 // registered a callback.
235 bool debug_ring_buffer_cb_registered_;
236 hidl_callback_util::HidlCallbackHandler<IWifiChipEventCallback>
237 event_cb_handler_;
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700238
Roshan Piusabcf78f2017-10-06 16:30:38 -0700239 DISALLOW_COPY_AND_ASSIGN(WifiChip);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700240};
241
Roshan Pius79a99752016-10-04 13:03:58 -0700242} // namespace implementation
Etan Cohen6ce50902017-09-14 07:30:57 -0700243} // namespace V1_2
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700244} // namespace wifi
245} // namespace hardware
246} // namespace android
247
248#endif // WIFI_CHIP_H_