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