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