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