Gabriel Biren | f3262f9 | 2022-07-15 23:25:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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_STA_IFACE_H_ |
| 18 | #define WIFI_STA_IFACE_H_ |
| 19 | |
| 20 | #include <aidl/android/hardware/wifi/BnWifiStaIface.h> |
| 21 | #include <aidl/android/hardware/wifi/IWifiStaIfaceEventCallback.h> |
| 22 | #include <android-base/macros.h> |
| 23 | |
| 24 | #include "aidl_callback_util.h" |
| 25 | #include "wifi_iface_util.h" |
| 26 | #include "wifi_legacy_hal.h" |
| 27 | |
| 28 | namespace aidl { |
| 29 | namespace android { |
| 30 | namespace hardware { |
| 31 | namespace wifi { |
| 32 | |
| 33 | /** |
| 34 | * AIDL interface object used to control a STA Iface instance. |
| 35 | */ |
| 36 | class WifiStaIface : public BnWifiStaIface { |
| 37 | public: |
| 38 | WifiStaIface(const std::string& ifname, |
| 39 | const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal, |
| 40 | const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util); |
| 41 | |
| 42 | // Factory method - use instead of default constructor. |
| 43 | static std::shared_ptr<WifiStaIface> create( |
| 44 | const std::string& ifname, const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal, |
| 45 | const std::weak_ptr<iface_util::WifiIfaceUtil> iface_util); |
| 46 | |
| 47 | // Refer to |WifiChip::invalidate()|. |
| 48 | void invalidate(); |
| 49 | bool isValid(); |
| 50 | std::set<std::shared_ptr<IWifiStaIfaceEventCallback>> getEventCallbacks(); |
| 51 | std::string getName(); |
| 52 | |
| 53 | // AIDL methods exposed. |
| 54 | ndk::ScopedAStatus getName(std::string* _aidl_return) override; |
| 55 | ndk::ScopedAStatus registerEventCallback( |
| 56 | const std::shared_ptr<IWifiStaIfaceEventCallback>& in_callback) override; |
| 57 | ndk::ScopedAStatus getCapabilities( |
| 58 | IWifiStaIface::StaIfaceCapabilityMask* _aidl_return) override; |
| 59 | ndk::ScopedAStatus getApfPacketFilterCapabilities( |
| 60 | StaApfPacketFilterCapabilities* _aidl_return) override; |
| 61 | ndk::ScopedAStatus installApfPacketFilter(const std::vector<uint8_t>& in_program) override; |
| 62 | ndk::ScopedAStatus readApfPacketFilterData(std::vector<uint8_t>* _aidl_return) override; |
| 63 | ndk::ScopedAStatus getBackgroundScanCapabilities( |
| 64 | StaBackgroundScanCapabilities* _aidl_return) override; |
| 65 | ndk::ScopedAStatus getValidFrequenciesForBand(WifiBand in_band, |
| 66 | std::vector<int32_t>* _aidl_return) override; |
| 67 | ndk::ScopedAStatus startBackgroundScan(int32_t in_cmdId, |
| 68 | const StaBackgroundScanParameters& in_params) override; |
| 69 | ndk::ScopedAStatus stopBackgroundScan(int32_t in_cmdId) override; |
| 70 | ndk::ScopedAStatus enableLinkLayerStatsCollection(bool in_debug) override; |
| 71 | ndk::ScopedAStatus disableLinkLayerStatsCollection() override; |
| 72 | ndk::ScopedAStatus getLinkLayerStats(StaLinkLayerStats* _aidl_return) override; |
| 73 | ndk::ScopedAStatus startRssiMonitoring(int32_t in_cmdId, int32_t in_maxRssi, |
| 74 | int32_t in_minRssi) override; |
| 75 | ndk::ScopedAStatus stopRssiMonitoring(int32_t in_cmdId) override; |
| 76 | ndk::ScopedAStatus getRoamingCapabilities(StaRoamingCapabilities* _aidl_return) override; |
| 77 | ndk::ScopedAStatus configureRoaming(const StaRoamingConfig& in_config) override; |
| 78 | ndk::ScopedAStatus setRoamingState(StaRoamingState in_state) override; |
| 79 | ndk::ScopedAStatus enableNdOffload(bool in_enable) override; |
| 80 | ndk::ScopedAStatus startSendingKeepAlivePackets(int32_t in_cmdId, |
| 81 | const std::vector<uint8_t>& in_ipPacketData, |
| 82 | char16_t in_etherType, |
| 83 | const std::array<uint8_t, 6>& in_srcAddress, |
| 84 | const std::array<uint8_t, 6>& in_dstAddress, |
| 85 | int32_t in_periodInMs) override; |
| 86 | ndk::ScopedAStatus stopSendingKeepAlivePackets(int32_t in_cmdId) override; |
| 87 | ndk::ScopedAStatus startDebugPacketFateMonitoring() override; |
| 88 | ndk::ScopedAStatus getDebugTxPacketFates( |
| 89 | std::vector<WifiDebugTxPacketFateReport>* _aidl_return) override; |
| 90 | ndk::ScopedAStatus getDebugRxPacketFates( |
| 91 | std::vector<WifiDebugRxPacketFateReport>* _aidl_return) override; |
| 92 | ndk::ScopedAStatus setMacAddress(const std::array<uint8_t, 6>& in_mac) override; |
| 93 | ndk::ScopedAStatus getFactoryMacAddress(std::array<uint8_t, 6>* _aidl_return) override; |
| 94 | ndk::ScopedAStatus setScanMode(bool in_enable) override; |
| 95 | |
| 96 | private: |
| 97 | // Corresponding worker functions for the AIDL methods. |
| 98 | std::pair<std::string, ndk::ScopedAStatus> getNameInternal(); |
| 99 | ndk::ScopedAStatus registerEventCallbackInternal( |
| 100 | const std::shared_ptr<IWifiStaIfaceEventCallback>& callback); |
| 101 | std::pair<IWifiStaIface::StaIfaceCapabilityMask, ndk::ScopedAStatus> getCapabilitiesInternal(); |
| 102 | std::pair<StaApfPacketFilterCapabilities, ndk::ScopedAStatus> |
| 103 | getApfPacketFilterCapabilitiesInternal(); |
| 104 | ndk::ScopedAStatus installApfPacketFilterInternal(const std::vector<uint8_t>& program); |
| 105 | std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> readApfPacketFilterDataInternal(); |
| 106 | std::pair<StaBackgroundScanCapabilities, ndk::ScopedAStatus> |
| 107 | getBackgroundScanCapabilitiesInternal(); |
| 108 | std::pair<std::vector<int32_t>, ndk::ScopedAStatus> getValidFrequenciesForBandInternal( |
| 109 | WifiBand band); |
| 110 | ndk::ScopedAStatus startBackgroundScanInternal(int32_t cmd_id, |
| 111 | const StaBackgroundScanParameters& params); |
| 112 | ndk::ScopedAStatus stopBackgroundScanInternal(int32_t cmd_id); |
| 113 | ndk::ScopedAStatus enableLinkLayerStatsCollectionInternal(bool debug); |
| 114 | ndk::ScopedAStatus disableLinkLayerStatsCollectionInternal(); |
| 115 | std::pair<StaLinkLayerStats, ndk::ScopedAStatus> getLinkLayerStatsInternal(); |
| 116 | ndk::ScopedAStatus startRssiMonitoringInternal(int32_t cmd_id, int32_t max_rssi, |
| 117 | int32_t min_rssi); |
| 118 | ndk::ScopedAStatus stopRssiMonitoringInternal(int32_t cmd_id); |
| 119 | std::pair<StaRoamingCapabilities, ndk::ScopedAStatus> getRoamingCapabilitiesInternal(); |
| 120 | ndk::ScopedAStatus configureRoamingInternal(const StaRoamingConfig& config); |
| 121 | ndk::ScopedAStatus setRoamingStateInternal(StaRoamingState state); |
| 122 | ndk::ScopedAStatus enableNdOffloadInternal(bool enable); |
| 123 | ndk::ScopedAStatus startSendingKeepAlivePacketsInternal( |
| 124 | int32_t cmd_id, const std::vector<uint8_t>& ip_packet_data, char16_t ether_type, |
| 125 | const std::array<uint8_t, 6>& src_address, const std::array<uint8_t, 6>& dst_address, |
| 126 | int32_t period_in_ms); |
| 127 | ndk::ScopedAStatus stopSendingKeepAlivePacketsInternal(int32_t cmd_id); |
| 128 | ndk::ScopedAStatus startDebugPacketFateMonitoringInternal(); |
| 129 | std::pair<std::vector<WifiDebugTxPacketFateReport>, ndk::ScopedAStatus> |
| 130 | getDebugTxPacketFatesInternal(); |
| 131 | std::pair<std::vector<WifiDebugRxPacketFateReport>, ndk::ScopedAStatus> |
| 132 | getDebugRxPacketFatesInternal(); |
| 133 | ndk::ScopedAStatus setMacAddressInternal(const std::array<uint8_t, 6>& mac); |
| 134 | std::pair<std::array<uint8_t, 6>, ndk::ScopedAStatus> getFactoryMacAddressInternal(); |
| 135 | ndk::ScopedAStatus setScanModeInternal(bool enable); |
| 136 | |
| 137 | void setWeakPtr(std::weak_ptr<WifiStaIface> ptr); |
| 138 | |
| 139 | std::string ifname_; |
| 140 | std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_; |
| 141 | std::weak_ptr<iface_util::WifiIfaceUtil> iface_util_; |
| 142 | std::weak_ptr<WifiStaIface> weak_ptr_this_; |
| 143 | bool is_valid_; |
| 144 | aidl_callback_util::AidlCallbackHandler<IWifiStaIfaceEventCallback> event_cb_handler_; |
| 145 | |
| 146 | DISALLOW_COPY_AND_ASSIGN(WifiStaIface); |
| 147 | }; |
| 148 | |
| 149 | } // namespace wifi |
| 150 | } // namespace hardware |
| 151 | } // namespace android |
| 152 | } // namespace aidl |
| 153 | |
| 154 | #endif // WIFI_STA_IFACE_H_ |