Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame^] | 20 | #include <list> |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 21 | #include <map> |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 22 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 23 | #include <android-base/macros.h> |
Etan Cohen | 9649e54 | 2017-12-21 08:41:34 -0800 | [diff] [blame] | 24 | #include <android/hardware/wifi/1.2/IWifiChip.h> |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 25 | |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 26 | #include "hidl_callback_util.h" |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame^] | 27 | #include "ringbuffer.h" |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 28 | #include "wifi_ap_iface.h" |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 29 | #include "wifi_feature_flags.h" |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 30 | #include "wifi_legacy_hal.h" |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 31 | #include "wifi_mode_controller.h" |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 32 | #include "wifi_nan_iface.h" |
| 33 | #include "wifi_p2p_iface.h" |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 34 | #include "wifi_rtt_controller.h" |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 35 | #include "wifi_sta_iface.h" |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 36 | |
| 37 | namespace android { |
| 38 | namespace hardware { |
| 39 | namespace wifi { |
Etan Cohen | 6ce5090 | 2017-09-14 07:30:57 -0700 | [diff] [blame] | 40 | namespace V1_2 { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 41 | namespace implementation { |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 42 | using namespace android::hardware::wifi::V1_0; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 43 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 44 | /** |
| 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 Cohen | 9649e54 | 2017-12-21 08:41:34 -0800 | [diff] [blame] | 49 | class WifiChip : public V1_2::IWifiChip { |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 50 | public: |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 51 | 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 Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 57 | // 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 Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 73 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 74 | // HIDL methods exposed. |
| 75 | Return<void> getId(getId_cb hidl_status_cb) override; |
| 76 | Return<void> registerEventCallback( |
| 77 | const sp<IWifiChipEventCallback>& event_callback, |
| 78 | 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; |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame^] | 139 | Return<void> debug(const hidl_handle& handle, |
| 140 | const hidl_vec<hidl_string>& options) override; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 141 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 142 | private: |
| 143 | void invalidateAndRemoveAllIfaces(); |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 144 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 145 | // Corresponding worker functions for the HIDL methods. |
| 146 | std::pair<WifiStatus, ChipId> getIdInternal(); |
| 147 | WifiStatus registerEventCallbackInternal( |
| 148 | const sp<IWifiChipEventCallback>& event_callback); |
| 149 | std::pair<WifiStatus, uint32_t> getCapabilitiesInternal(); |
| 150 | std::pair<WifiStatus, std::vector<ChipMode>> getAvailableModesInternal(); |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 151 | WifiStatus configureChipInternal( |
| 152 | std::unique_lock<std::recursive_mutex>* lock, ChipModeId mode_id); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 153 | std::pair<WifiStatus, uint32_t> getModeInternal(); |
| 154 | std::pair<WifiStatus, IWifiChip::ChipDebugInfo> |
| 155 | requestChipDebugInfoInternal(); |
| 156 | std::pair<WifiStatus, std::vector<uint8_t>> |
| 157 | requestDriverDebugDumpInternal(); |
| 158 | std::pair<WifiStatus, std::vector<uint8_t>> |
| 159 | requestFirmwareDebugDumpInternal(); |
| 160 | std::pair<WifiStatus, sp<IWifiApIface>> createApIfaceInternal(); |
| 161 | std::pair<WifiStatus, std::vector<hidl_string>> getApIfaceNamesInternal(); |
| 162 | std::pair<WifiStatus, sp<IWifiApIface>> getApIfaceInternal( |
| 163 | const std::string& ifname); |
| 164 | WifiStatus removeApIfaceInternal(const std::string& ifname); |
| 165 | std::pair<WifiStatus, sp<IWifiNanIface>> createNanIfaceInternal(); |
| 166 | std::pair<WifiStatus, std::vector<hidl_string>> getNanIfaceNamesInternal(); |
| 167 | std::pair<WifiStatus, sp<IWifiNanIface>> getNanIfaceInternal( |
| 168 | const std::string& ifname); |
| 169 | WifiStatus removeNanIfaceInternal(const std::string& ifname); |
| 170 | std::pair<WifiStatus, sp<IWifiP2pIface>> createP2pIfaceInternal(); |
| 171 | std::pair<WifiStatus, std::vector<hidl_string>> getP2pIfaceNamesInternal(); |
| 172 | std::pair<WifiStatus, sp<IWifiP2pIface>> getP2pIfaceInternal( |
| 173 | const std::string& ifname); |
| 174 | WifiStatus removeP2pIfaceInternal(const std::string& ifname); |
| 175 | std::pair<WifiStatus, sp<IWifiStaIface>> createStaIfaceInternal(); |
| 176 | std::pair<WifiStatus, std::vector<hidl_string>> getStaIfaceNamesInternal(); |
| 177 | std::pair<WifiStatus, sp<IWifiStaIface>> getStaIfaceInternal( |
| 178 | const std::string& ifname); |
| 179 | WifiStatus removeStaIfaceInternal(const std::string& ifname); |
| 180 | std::pair<WifiStatus, sp<IWifiRttController>> createRttControllerInternal( |
| 181 | const sp<IWifiIface>& bound_iface); |
| 182 | std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>> |
| 183 | getDebugRingBuffersStatusInternal(); |
| 184 | WifiStatus startLoggingToDebugRingBufferInternal( |
| 185 | const hidl_string& ring_name, |
| 186 | WifiDebugRingBufferVerboseLevel verbose_level, |
| 187 | uint32_t max_interval_in_sec, uint32_t min_data_size_in_bytes); |
| 188 | WifiStatus forceDumpToDebugRingBufferInternal(const hidl_string& ring_name); |
| 189 | WifiStatus stopLoggingToDebugRingBufferInternal(); |
| 190 | std::pair<WifiStatus, WifiDebugHostWakeReasonStats> |
| 191 | getDebugHostWakeReasonStatsInternal(); |
| 192 | WifiStatus enableDebugErrorAlertsInternal(bool enable); |
| 193 | WifiStatus selectTxPowerScenarioInternal(TxPowerScenario scenario); |
| 194 | WifiStatus resetTxPowerScenarioInternal(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 195 | |
Roshan Pius | ba38d9c | 2017-12-08 07:32:08 -0800 | [diff] [blame] | 196 | WifiStatus handleChipConfiguration( |
| 197 | std::unique_lock<std::recursive_mutex>* lock, ChipModeId mode_id); |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 198 | WifiStatus registerDebugRingBufferCallback(); |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 199 | |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 200 | void populateModes(); |
| 201 | std::vector<IWifiChip::ChipIfaceCombination> |
| 202 | getCurrentModeIfaceCombinations(); |
| 203 | std::map<IfaceType, size_t> getCurrentIfaceCombination(); |
| 204 | std::vector<std::map<IfaceType, size_t>> expandIfaceCombinations( |
| 205 | const IWifiChip::ChipIfaceCombination& combination); |
| 206 | bool canExpandedIfaceCombinationSupportIfaceOfType( |
| 207 | const std::map<IfaceType, size_t>& combo, IfaceType type); |
| 208 | bool canCurrentModeSupportIfaceOfType(IfaceType type); |
| 209 | bool isValidModeId(ChipModeId mode_id); |
Roshan Pius | 8e3c7ef | 2017-11-03 09:43:08 -0700 | [diff] [blame] | 210 | std::string allocateApOrStaIfaceName(); |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame^] | 211 | bool writeRingbufferFilesInternal(); |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 212 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 213 | ChipId chip_id_; |
| 214 | std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_; |
| 215 | std::weak_ptr<mode_controller::WifiModeController> mode_controller_; |
Roshan Pius | 200a17d | 2017-11-01 13:03:35 -0700 | [diff] [blame] | 216 | std::weak_ptr<feature_flags::WifiFeatureFlags> feature_flags_; |
Roshan Pius | 675609b | 2017-10-31 14:24:58 -0700 | [diff] [blame] | 217 | std::vector<sp<WifiApIface>> ap_ifaces_; |
| 218 | std::vector<sp<WifiNanIface>> nan_ifaces_; |
| 219 | std::vector<sp<WifiP2pIface>> p2p_ifaces_; |
| 220 | std::vector<sp<WifiStaIface>> sta_ifaces_; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 221 | std::vector<sp<WifiRttController>> rtt_controllers_; |
xshu | 5899e8e | 2018-01-09 15:36:03 -0800 | [diff] [blame^] | 222 | std::map<std::string, Ringbuffer> ringbuffer_map_; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 223 | bool is_valid_; |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 224 | // Members pertaining to chip configuration. |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 225 | uint32_t current_mode_id_; |
Roshan Pius | cc33820 | 2017-11-02 13:54:09 -0700 | [diff] [blame] | 226 | std::vector<IWifiChip::ChipMode> modes_; |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 227 | // The legacy ring buffer callback API has only a global callback |
| 228 | // registration mechanism. Use this to check if we have already |
| 229 | // registered a callback. |
| 230 | bool debug_ring_buffer_cb_registered_; |
| 231 | hidl_callback_util::HidlCallbackHandler<IWifiChipEventCallback> |
| 232 | event_cb_handler_; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 233 | |
Roshan Pius | abcf78f | 2017-10-06 16:30:38 -0700 | [diff] [blame] | 234 | DISALLOW_COPY_AND_ASSIGN(WifiChip); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 235 | }; |
| 236 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 237 | } // namespace implementation |
Etan Cohen | 6ce5090 | 2017-09-14 07:30:57 -0700 | [diff] [blame] | 238 | } // namespace V1_2 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 239 | } // namespace wifi |
| 240 | } // namespace hardware |
| 241 | } // namespace android |
| 242 | |
| 243 | #endif // WIFI_CHIP_H_ |