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 | |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 20 | #include <map> |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 21 | |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 22 | #include <android-base/macros.h> |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 23 | #include <android/hardware/wifi/1.1/IWifiChip.h> |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 24 | |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 25 | #include "hidl_callback_util.h" |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 26 | #include "wifi_ap_iface.h" |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 27 | #include "wifi_legacy_hal.h" |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 28 | #include "wifi_mode_controller.h" |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 29 | #include "wifi_nan_iface.h" |
| 30 | #include "wifi_p2p_iface.h" |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 31 | #include "wifi_rtt_controller.h" |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 32 | #include "wifi_sta_iface.h" |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 33 | |
| 34 | namespace android { |
| 35 | namespace hardware { |
| 36 | namespace wifi { |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 37 | namespace V1_1 { |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 38 | namespace implementation { |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 39 | using namespace android::hardware::wifi::V1_0; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 40 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 41 | /** |
| 42 | * HIDL interface object used to control a Wifi HAL chip instance. |
| 43 | * Since there is only a single chip instance used today, there is no |
| 44 | * identifying handle information stored here. |
| 45 | */ |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 46 | class WifiChip : public V1_1::IWifiChip { |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 47 | public: |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 48 | WifiChip( |
| 49 | ChipId chip_id, |
| 50 | const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal, |
| 51 | const std::weak_ptr<mode_controller::WifiModeController> mode_controller); |
Roshan Pius | 3e2d671 | 2016-10-06 13:16:23 -0700 | [diff] [blame] | 52 | // HIDL does not provide a built-in mechanism to let the server invalidate |
| 53 | // a HIDL interface object after creation. If any client process holds onto |
| 54 | // a reference to the object in their context, any method calls on that |
| 55 | // reference will continue to be directed to the server. |
| 56 | // |
| 57 | // However Wifi HAL needs to control the lifetime of these objects. So, add |
| 58 | // a public |invalidate| method to |WifiChip| and it's child objects. This |
| 59 | // will be used to mark an object invalid when either: |
| 60 | // a) Wifi HAL is stopped, or |
| 61 | // b) Wifi Chip is reconfigured. |
| 62 | // |
| 63 | // All HIDL method implementations should check if the object is still marked |
| 64 | // valid before processing them. |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 65 | void invalidate(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 66 | bool isValid(); |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 67 | std::set<sp<IWifiChipEventCallback>> getEventCallbacks(); |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 68 | |
Roshan Pius | aabe575 | 2016-09-29 09:03:59 -0700 | [diff] [blame] | 69 | // HIDL methods exposed. |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 70 | Return<void> getId(getId_cb hidl_status_cb) override; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 71 | Return<void> registerEventCallback( |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 72 | const sp<IWifiChipEventCallback>& event_callback, |
| 73 | registerEventCallback_cb hidl_status_cb) override; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 74 | Return<void> getCapabilities(getCapabilities_cb hidl_status_cb) override; |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 75 | Return<void> getAvailableModes(getAvailableModes_cb hidl_status_cb) override; |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 76 | Return<void> configureChip(ChipModeId mode_id, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 77 | configureChip_cb hidl_status_cb) override; |
| 78 | Return<void> getMode(getMode_cb hidl_status_cb) override; |
| 79 | Return<void> requestChipDebugInfo( |
| 80 | requestChipDebugInfo_cb hidl_status_cb) override; |
| 81 | Return<void> requestDriverDebugDump( |
| 82 | requestDriverDebugDump_cb hidl_status_cb) override; |
| 83 | Return<void> requestFirmwareDebugDump( |
| 84 | requestFirmwareDebugDump_cb hidl_status_cb) override; |
| 85 | Return<void> createApIface(createApIface_cb hidl_status_cb) override; |
| 86 | Return<void> getApIfaceNames(getApIfaceNames_cb hidl_status_cb) override; |
| 87 | Return<void> getApIface(const hidl_string& ifname, |
| 88 | getApIface_cb hidl_status_cb) override; |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 89 | Return<void> removeApIface(const hidl_string& ifname, |
| 90 | removeApIface_cb hidl_status_cb) override; |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 91 | Return<void> createNanIface(createNanIface_cb hidl_status_cb) override; |
| 92 | Return<void> getNanIfaceNames(getNanIfaceNames_cb hidl_status_cb) override; |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 93 | Return<void> getNanIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 94 | getNanIface_cb hidl_status_cb) override; |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 95 | Return<void> removeNanIface(const hidl_string& ifname, |
| 96 | removeNanIface_cb hidl_status_cb) override; |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 97 | Return<void> createP2pIface(createP2pIface_cb hidl_status_cb) override; |
| 98 | Return<void> getP2pIfaceNames(getP2pIfaceNames_cb hidl_status_cb) override; |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 99 | Return<void> getP2pIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 100 | getP2pIface_cb hidl_status_cb) override; |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 101 | Return<void> removeP2pIface(const hidl_string& ifname, |
| 102 | removeP2pIface_cb hidl_status_cb) override; |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 103 | Return<void> createStaIface(createStaIface_cb hidl_status_cb) override; |
| 104 | Return<void> getStaIfaceNames(getStaIfaceNames_cb hidl_status_cb) override; |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 105 | Return<void> getStaIface(const hidl_string& ifname, |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 106 | getStaIface_cb hidl_status_cb) override; |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 107 | Return<void> removeStaIface(const hidl_string& ifname, |
| 108 | removeStaIface_cb hidl_status_cb) override; |
Roshan Pius | 5c05546 | 2016-10-11 08:27:27 -0700 | [diff] [blame] | 109 | Return<void> createRttController( |
| 110 | const sp<IWifiIface>& bound_iface, |
| 111 | createRttController_cb hidl_status_cb) override; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 112 | Return<void> getDebugRingBuffersStatus( |
| 113 | getDebugRingBuffersStatus_cb hidl_status_cb) override; |
| 114 | Return<void> startLoggingToDebugRingBuffer( |
| 115 | const hidl_string& ring_name, |
| 116 | WifiDebugRingBufferVerboseLevel verbose_level, |
| 117 | uint32_t max_interval_in_sec, |
| 118 | uint32_t min_data_size_in_bytes, |
| 119 | startLoggingToDebugRingBuffer_cb hidl_status_cb) override; |
| 120 | Return<void> forceDumpToDebugRingBuffer( |
| 121 | const hidl_string& ring_name, |
| 122 | forceDumpToDebugRingBuffer_cb hidl_status_cb) override; |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 123 | Return<void> stopLoggingToDebugRingBuffer( |
| 124 | stopLoggingToDebugRingBuffer_cb hidl_status_cb) override; |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 125 | Return<void> getDebugHostWakeReasonStats( |
| 126 | getDebugHostWakeReasonStats_cb hidl_status_cb) override; |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 127 | Return<void> enableDebugErrorAlerts( |
| 128 | bool enable, enableDebugErrorAlerts_cb hidl_status_cb) override; |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 129 | Return<void> setTxPowerLimit( |
| 130 | int32_t powerInDbm, setTxPowerLimit_cb hidl_status_cb) override; |
| 131 | Return<void> resetTxPowerLimit(resetTxPowerLimit_cb hidl_status_cb) override; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 132 | |
| 133 | private: |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 134 | void invalidateAndRemoveAllIfaces(); |
| 135 | |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 136 | // Corresponding worker functions for the HIDL methods. |
| 137 | std::pair<WifiStatus, ChipId> getIdInternal(); |
| 138 | WifiStatus registerEventCallbackInternal( |
| 139 | const sp<IWifiChipEventCallback>& event_callback); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 140 | std::pair<WifiStatus, uint32_t> getCapabilitiesInternal(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 141 | std::pair<WifiStatus, std::vector<ChipMode>> getAvailableModesInternal(); |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 142 | WifiStatus configureChipInternal(ChipModeId mode_id); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 143 | std::pair<WifiStatus, uint32_t> getModeInternal(); |
| 144 | std::pair<WifiStatus, IWifiChip::ChipDebugInfo> |
| 145 | requestChipDebugInfoInternal(); |
| 146 | std::pair<WifiStatus, std::vector<uint8_t>> requestDriverDebugDumpInternal(); |
| 147 | std::pair<WifiStatus, std::vector<uint8_t>> |
| 148 | requestFirmwareDebugDumpInternal(); |
| 149 | std::pair<WifiStatus, sp<IWifiApIface>> createApIfaceInternal(); |
| 150 | std::pair<WifiStatus, std::vector<hidl_string>> getApIfaceNamesInternal(); |
| 151 | std::pair<WifiStatus, sp<IWifiApIface>> getApIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 152 | const std::string& ifname); |
| 153 | WifiStatus removeApIfaceInternal(const std::string& ifname); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 154 | std::pair<WifiStatus, sp<IWifiNanIface>> createNanIfaceInternal(); |
| 155 | std::pair<WifiStatus, std::vector<hidl_string>> getNanIfaceNamesInternal(); |
| 156 | std::pair<WifiStatus, sp<IWifiNanIface>> getNanIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 157 | const std::string& ifname); |
| 158 | WifiStatus removeNanIfaceInternal(const std::string& ifname); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 159 | std::pair<WifiStatus, sp<IWifiP2pIface>> createP2pIfaceInternal(); |
| 160 | std::pair<WifiStatus, std::vector<hidl_string>> getP2pIfaceNamesInternal(); |
| 161 | std::pair<WifiStatus, sp<IWifiP2pIface>> getP2pIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 162 | const std::string& ifname); |
| 163 | WifiStatus removeP2pIfaceInternal(const std::string& ifname); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 164 | std::pair<WifiStatus, sp<IWifiStaIface>> createStaIfaceInternal(); |
| 165 | std::pair<WifiStatus, std::vector<hidl_string>> getStaIfaceNamesInternal(); |
| 166 | std::pair<WifiStatus, sp<IWifiStaIface>> getStaIfaceInternal( |
Roshan Pius | 8b55e6f | 2016-12-09 12:05:12 -0800 | [diff] [blame] | 167 | const std::string& ifname); |
| 168 | WifiStatus removeStaIfaceInternal(const std::string& ifname); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 169 | std::pair<WifiStatus, sp<IWifiRttController>> createRttControllerInternal( |
| 170 | const sp<IWifiIface>& bound_iface); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 171 | std::pair<WifiStatus, std::vector<WifiDebugRingBufferStatus>> |
| 172 | getDebugRingBuffersStatusInternal(); |
| 173 | WifiStatus startLoggingToDebugRingBufferInternal( |
| 174 | const hidl_string& ring_name, |
| 175 | WifiDebugRingBufferVerboseLevel verbose_level, |
| 176 | uint32_t max_interval_in_sec, |
| 177 | uint32_t min_data_size_in_bytes); |
| 178 | WifiStatus forceDumpToDebugRingBufferInternal(const hidl_string& ring_name); |
Roshan Pius | 8c0c8e9 | 2017-02-24 08:07:42 -0800 | [diff] [blame] | 179 | WifiStatus stopLoggingToDebugRingBufferInternal(); |
Roshan Pius | 7d08d7a | 2016-10-27 14:35:05 -0700 | [diff] [blame] | 180 | std::pair<WifiStatus, WifiDebugHostWakeReasonStats> |
| 181 | getDebugHostWakeReasonStatsInternal(); |
Roshan Pius | 203cb03 | 2016-12-14 17:41:20 -0800 | [diff] [blame] | 182 | WifiStatus enableDebugErrorAlertsInternal(bool enable); |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 183 | WifiStatus setTxPowerLimitInternal(int32_t powerInDbm); |
| 184 | WifiStatus resetTxPowerLimitInternal(); |
Roshan Pius | 3c86852 | 2016-10-27 12:43:49 -0700 | [diff] [blame] | 185 | |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 186 | WifiStatus handleChipConfiguration(ChipModeId mode_id); |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 187 | WifiStatus registerDebugRingBufferCallback(); |
Roshan Pius | 2c06a3f | 2016-12-15 17:51:40 -0800 | [diff] [blame] | 188 | |
Roshan Pius | cd566bd | 2016-10-10 08:03:42 -0700 | [diff] [blame] | 189 | ChipId chip_id_; |
Roshan Pius | 6cedc97 | 2016-10-28 10:11:17 -0700 | [diff] [blame] | 190 | std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_; |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 191 | std::weak_ptr<mode_controller::WifiModeController> mode_controller_; |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 192 | sp<WifiApIface> ap_iface_; |
| 193 | sp<WifiNanIface> nan_iface_; |
| 194 | sp<WifiP2pIface> p2p_iface_; |
| 195 | sp<WifiStaIface> sta_iface_; |
Roshan Pius | 5926828 | 2016-10-06 20:23:47 -0700 | [diff] [blame] | 196 | std::vector<sp<WifiRttController>> rtt_controllers_; |
Roshan Pius | 35d958c | 2016-10-06 16:47:38 -0700 | [diff] [blame] | 197 | bool is_valid_; |
Roshan Pius | 52947fb | 2016-11-18 11:38:07 -0800 | [diff] [blame] | 198 | uint32_t current_mode_id_; |
Roshan Pius | 48185b2 | 2016-12-15 19:10:30 -0800 | [diff] [blame] | 199 | // The legacy ring buffer callback API has only a global callback |
| 200 | // registration mechanism. Use this to check if we have already |
| 201 | // registered a callback. |
| 202 | bool debug_ring_buffer_cb_registered_; |
Roshan Pius | d37341f | 2017-01-31 13:13:28 -0800 | [diff] [blame] | 203 | hidl_callback_util::HidlCallbackHandler<IWifiChipEventCallback> |
| 204 | event_cb_handler_; |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 205 | |
| 206 | DISALLOW_COPY_AND_ASSIGN(WifiChip); |
| 207 | }; |
| 208 | |
Roshan Pius | 79a9975 | 2016-10-04 13:03:58 -0700 | [diff] [blame] | 209 | } // namespace implementation |
Roshan Pius | dbd83ef | 2017-06-20 12:05:40 -0700 | [diff] [blame] | 210 | } // namespace V1_1 |
Roshan Pius | 3c4e8a3 | 2016-10-03 14:53:58 -0700 | [diff] [blame] | 211 | } // namespace wifi |
| 212 | } // namespace hardware |
| 213 | } // namespace android |
| 214 | |
| 215 | #endif // WIFI_CHIP_H_ |