blob: ada945885e18651920c45a3cb791dbcf651fc83a [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(
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -0800135 V1_1::IWifiChip::TxPowerScenario scenario,
Roshan Piusabcf78f2017-10-06 16:30:38 -0700136 selectTxPowerScenario_cb hidl_status_cb) override;
137 Return<void> resetTxPowerScenario(
138 resetTxPowerScenario_cb hidl_status_cb) override;
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800139 Return<void> registerEventCallback_1_2(
140 const sp<IWifiChipEventCallback>& event_callback,
141 registerEventCallback_1_2_cb hidl_status_cb) override;
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -0800142 Return<void> selectTxPowerScenario_1_2(
143 TxPowerScenario scenario,
144 selectTxPowerScenario_cb hidl_status_cb) override;
145 Return<void> debug(const hidl_handle& handle,
146 const hidl_vec<hidl_string>& options) override;
Roshan Piusabcf78f2017-10-06 16:30:38 -0700147 private:
148 void invalidateAndRemoveAllIfaces();
Roshan Pius35d958c2016-10-06 16:47:38 -0700149
Roshan Piusabcf78f2017-10-06 16:30:38 -0700150 // Corresponding worker functions for the HIDL methods.
151 std::pair<WifiStatus, ChipId> getIdInternal();
152 WifiStatus registerEventCallbackInternal(
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800153 const sp<V1_0::IWifiChipEventCallback>& event_callback);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700154 std::pair<WifiStatus, uint32_t> getCapabilitiesInternal();
155 std::pair<WifiStatus, std::vector<ChipMode>> getAvailableModesInternal();
Roshan Piusba38d9c2017-12-08 07:32:08 -0800156 WifiStatus configureChipInternal(
157 std::unique_lock<std::recursive_mutex>* lock, ChipModeId mode_id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700158 std::pair<WifiStatus, uint32_t> getModeInternal();
159 std::pair<WifiStatus, IWifiChip::ChipDebugInfo>
160 requestChipDebugInfoInternal();
161 std::pair<WifiStatus, std::vector<uint8_t>>
162 requestDriverDebugDumpInternal();
163 std::pair<WifiStatus, std::vector<uint8_t>>
164 requestFirmwareDebugDumpInternal();
165 std::pair<WifiStatus, sp<IWifiApIface>> createApIfaceInternal();
166 std::pair<WifiStatus, std::vector<hidl_string>> getApIfaceNamesInternal();
167 std::pair<WifiStatus, sp<IWifiApIface>> getApIfaceInternal(
168 const std::string& ifname);
169 WifiStatus removeApIfaceInternal(const std::string& ifname);
170 std::pair<WifiStatus, sp<IWifiNanIface>> createNanIfaceInternal();
171 std::pair<WifiStatus, std::vector<hidl_string>> getNanIfaceNamesInternal();
172 std::pair<WifiStatus, sp<IWifiNanIface>> getNanIfaceInternal(
173 const std::string& ifname);
174 WifiStatus removeNanIfaceInternal(const std::string& ifname);
175 std::pair<WifiStatus, sp<IWifiP2pIface>> createP2pIfaceInternal();
176 std::pair<WifiStatus, std::vector<hidl_string>> getP2pIfaceNamesInternal();
177 std::pair<WifiStatus, sp<IWifiP2pIface>> getP2pIfaceInternal(
178 const std::string& ifname);
179 WifiStatus removeP2pIfaceInternal(const std::string& ifname);
180 std::pair<WifiStatus, sp<IWifiStaIface>> createStaIfaceInternal();
181 std::pair<WifiStatus, std::vector<hidl_string>> getStaIfaceNamesInternal();
182 std::pair<WifiStatus, sp<IWifiStaIface>> getStaIfaceInternal(
183 const std::string& ifname);
184 WifiStatus removeStaIfaceInternal(const std::string& ifname);
185 std::pair<WifiStatus, sp<IWifiRttController>> createRttControllerInternal(
186 const sp<IWifiIface>& bound_iface);
187 std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>>
188 getDebugRingBuffersStatusInternal();
189 WifiStatus startLoggingToDebugRingBufferInternal(
190 const hidl_string& ring_name,
191 WifiDebugRingBufferVerboseLevel verbose_level,
192 uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes);
193 WifiStatus forceDumpToDebugRingBufferInternal(const hidl_string& ring_name);
194 WifiStatus stopLoggingToDebugRingBufferInternal();
195 std::pair<WifiStatus, WifiDebugHostWakeReasonStats>
196 getDebugHostWakeReasonStatsInternal();
197 WifiStatus enableDebugErrorAlertsInternal(bool enable);
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -0800198 WifiStatus selectTxPowerScenarioInternal(V1_1::IWifiChip::TxPowerScenario scenario);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700199 WifiStatus resetTxPowerScenarioInternal();
Roshan Pius1ce92cf2018-01-22 16:12:19 -0800200 WifiStatus registerEventCallbackInternal_1_2(
201 const sp<IWifiChipEventCallback>& event_callback);
Ahmed ElArabawy6a1accf2018-01-23 10:57:29 -0800202 WifiStatus selectTxPowerScenarioInternal_1_2(TxPowerScenario scenario);
Roshan Piusba38d9c2017-12-08 07:32:08 -0800203 WifiStatus handleChipConfiguration(
204 std::unique_lock<std::recursive_mutex>* lock, ChipModeId mode_id);
Roshan Piusabcf78f2017-10-06 16:30:38 -0700205 WifiStatus registerDebugRingBufferCallback();
Roshan Pius85c64412018-01-22 17:58:40 -0800206 WifiStatus registerRadioModeChangeCallback();
Roshan Pius2c06a3f2016-12-15 17:51:40 -0800207
Roshan Piuscc338202017-11-02 13:54:09 -0700208 void populateModes();
209 std::vector<IWifiChip::ChipIfaceCombination>
210 getCurrentModeIfaceCombinations();
211 std::map<IfaceType, size_t> getCurrentIfaceCombination();
212 std::vector<std::map<IfaceType, size_t>> expandIfaceCombinations(
213 const IWifiChip::ChipIfaceCombination& combination);
214 bool canExpandedIfaceCombinationSupportIfaceOfType(
215 const std::map<IfaceType, size_t>& combo, IfaceType type);
216 bool canCurrentModeSupportIfaceOfType(IfaceType type);
217 bool isValidModeId(ChipModeId mode_id);
Roshan Pius8e3c7ef2017-11-03 09:43:08 -0700218 std::string allocateApOrStaIfaceName();
xshu5899e8e2018-01-09 15:36:03 -0800219 bool writeRingbufferFilesInternal();
Roshan Piuscc338202017-11-02 13:54:09 -0700220
Roshan Piusabcf78f2017-10-06 16:30:38 -0700221 ChipId chip_id_;
222 std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
223 std::weak_ptr<mode_controller::WifiModeController> mode_controller_;
Roshan Pius200a17d2017-11-01 13:03:35 -0700224 std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags_;
Roshan Pius675609b2017-10-31 14:24:58 -0700225 std::vector<sp<WifiApIface>> ap_ifaces_;
226 std::vector<sp<WifiNanIface>> nan_ifaces_;
227 std::vector<sp<WifiP2pIface>> p2p_ifaces_;
228 std::vector<sp<WifiStaIface>> sta_ifaces_;
Roshan Piusabcf78f2017-10-06 16:30:38 -0700229 std::vector<sp<WifiRttController>> rtt_controllers_;
xshu5899e8e2018-01-09 15:36:03 -0800230 std::map<std::string, Ringbuffer> ringbuffer_map_;
Roshan Piusabcf78f2017-10-06 16:30:38 -0700231 bool is_valid_;
Roshan Piuscc338202017-11-02 13:54:09 -0700232 // Members pertaining to chip configuration.
Roshan Piusabcf78f2017-10-06 16:30:38 -0700233 uint32_t current_mode_id_;
Roshan Piuscc338202017-11-02 13:54:09 -0700234 std::vector<IWifiChip::ChipMode> modes_;
Roshan Piusabcf78f2017-10-06 16:30:38 -0700235 // The legacy ring buffer callback API has only a global callback
236 // registration mechanism. Use this to check if we have already
237 // registered a callback.
238 bool debug_ring_buffer_cb_registered_;
239 hidl_callback_util::HidlCallbackHandler<IWifiChipEventCallback>
240 event_cb_handler_;
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700241
Roshan Piusabcf78f2017-10-06 16:30:38 -0700242 DISALLOW_COPY_AND_ASSIGN(WifiChip);
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700243};
244
Roshan Pius79a99752016-10-04 13:03:58 -0700245} // namespace implementation
Etan Cohen6ce50902017-09-14 07:30:57 -0700246} // namespace V1_2
Roshan Pius3c4e8a32016-10-03 14:53:58 -0700247} // namespace wifi
248} // namespace hardware
249} // namespace android
250
251#endif // WIFI_CHIP_H_