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_STA_IFACE_H_
18 #define WIFI_STA_IFACE_H_
19 
20 #include <android-base/macros.h>
21 #include <android/hardware/wifi/1.0/IWifiStaIface.h>
22 #include <android/hardware/wifi/1.0/IWifiStaIfaceEventCallback.h>
23 
24 #include "hidl_callback_util.h"
25 #include "wifi_legacy_hal.h"
26 
27 namespace android {
28 namespace hardware {
29 namespace wifi {
30 namespace V1_0 {
31 namespace implementation {
32 
33 /**
34  * HIDL interface object used to control a STA Iface instance.
35  */
36 class WifiStaIface : public IWifiStaIface {
37  public:
38   WifiStaIface(const std::string& ifname,
39                const std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal);
40   // Refer to |WifiChip::invalidate()|.
41   void invalidate();
42   bool isValid();
43   std::set<sp<IWifiStaIfaceEventCallback>> getEventCallbacks();
44 
45   // HIDL methods exposed.
46   Return<void> getName(getName_cb hidl_status_cb) override;
47   Return<void> getType(getType_cb hidl_status_cb) override;
48   Return<void> registerEventCallback(
49       const sp<IWifiStaIfaceEventCallback>& callback,
50       registerEventCallback_cb hidl_status_cb) override;
51   Return<void> getCapabilities(getCapabilities_cb hidl_status_cb) override;
52   Return<void> getApfPacketFilterCapabilities(
53       getApfPacketFilterCapabilities_cb hidl_status_cb) override;
54   Return<void> installApfPacketFilter(
55       uint32_t cmd_id,
56       const hidl_vec<uint8_t>& program,
57       installApfPacketFilter_cb hidl_status_cb) override;
58   Return<void> getBackgroundScanCapabilities(
59       getBackgroundScanCapabilities_cb hidl_status_cb) override;
60   Return<void> getValidFrequenciesForBand(
61       WifiBand band, getValidFrequenciesForBand_cb hidl_status_cb) override;
62   Return<void> startBackgroundScan(
63       uint32_t cmd_id,
64       const StaBackgroundScanParameters& params,
65       startBackgroundScan_cb hidl_status_cb) override;
66   Return<void> stopBackgroundScan(
67       uint32_t cmd_id, stopBackgroundScan_cb hidl_status_cb) override;
68   Return<void> enableLinkLayerStatsCollection(
69       bool debug, enableLinkLayerStatsCollection_cb hidl_status_cb) override;
70   Return<void> disableLinkLayerStatsCollection(
71       disableLinkLayerStatsCollection_cb hidl_status_cb) override;
72   Return<void> getLinkLayerStats(getLinkLayerStats_cb hidl_status_cb) override;
73   Return<void> startRssiMonitoring(
74       uint32_t cmd_id,
75       int32_t max_rssi,
76       int32_t min_rssi,
77       startRssiMonitoring_cb hidl_status_cb) override;
78   Return<void> stopRssiMonitoring(
79       uint32_t cmd_id, stopRssiMonitoring_cb hidl_status_cb) override;
80   Return<void> getRoamingCapabilities(
81       getRoamingCapabilities_cb hidl_status_cb) override;
82   Return<void> configureRoaming(const StaRoamingConfig& config,
83                                 configureRoaming_cb hidl_status_cb) override;
84   Return<void> setRoamingState(StaRoamingState state,
85                                setRoamingState_cb hidl_status_cb) override;
86   Return<void> enableNdOffload(bool enable,
87                                enableNdOffload_cb hidl_status_cb) override;
88   Return<void> startSendingKeepAlivePackets(
89       uint32_t cmd_id,
90       const hidl_vec<uint8_t>& ip_packet_data,
91       uint16_t ether_type,
92       const hidl_array<uint8_t, 6>& src_address,
93       const hidl_array<uint8_t, 6>& dst_address,
94       uint32_t period_in_ms,
95       startSendingKeepAlivePackets_cb hidl_status_cb) override;
96   Return<void> stopSendingKeepAlivePackets(
97       uint32_t cmd_id, stopSendingKeepAlivePackets_cb hidl_status_cb) override;
98   Return<void> setScanningMacOui(const hidl_array<uint8_t, 3>& oui,
99                                  setScanningMacOui_cb hidl_status_cb) override;
100   Return<void> startDebugPacketFateMonitoring(
101       startDebugPacketFateMonitoring_cb hidl_status_cb) override;
102   Return<void> getDebugTxPacketFates(
103       getDebugTxPacketFates_cb hidl_status_cb) override;
104   Return<void> getDebugRxPacketFates(
105       getDebugRxPacketFates_cb hidl_status_cb) override;
106 
107  private:
108   // Corresponding worker functions for the HIDL methods.
109   std::pair<WifiStatus, std::string> getNameInternal();
110   std::pair<WifiStatus, IfaceType> getTypeInternal();
111   WifiStatus registerEventCallbackInternal(
112       const sp<IWifiStaIfaceEventCallback>& callback);
113   std::pair<WifiStatus, uint32_t> getCapabilitiesInternal();
114   std::pair<WifiStatus, StaApfPacketFilterCapabilities>
115   getApfPacketFilterCapabilitiesInternal();
116   WifiStatus installApfPacketFilterInternal(
117       uint32_t cmd_id, const std::vector<uint8_t>& program);
118   std::pair<WifiStatus, StaBackgroundScanCapabilities>
119   getBackgroundScanCapabilitiesInternal();
120   std::pair<WifiStatus, std::vector<WifiChannelInMhz>>
121   getValidFrequenciesForBandInternal(WifiBand band);
122   WifiStatus startBackgroundScanInternal(
123       uint32_t cmd_id, const StaBackgroundScanParameters& params);
124   WifiStatus stopBackgroundScanInternal(uint32_t cmd_id);
125   WifiStatus enableLinkLayerStatsCollectionInternal(bool debug);
126   WifiStatus disableLinkLayerStatsCollectionInternal();
127   std::pair<WifiStatus, StaLinkLayerStats> getLinkLayerStatsInternal();
128   WifiStatus startRssiMonitoringInternal(uint32_t cmd_id,
129                                          int32_t max_rssi,
130                                          int32_t min_rssi);
131   WifiStatus stopRssiMonitoringInternal(uint32_t cmd_id);
132   std::pair<WifiStatus, StaRoamingCapabilities>
133   getRoamingCapabilitiesInternal();
134   WifiStatus configureRoamingInternal(const StaRoamingConfig& config);
135   WifiStatus setRoamingStateInternal(StaRoamingState state);
136   WifiStatus enableNdOffloadInternal(bool enable);
137   WifiStatus startSendingKeepAlivePacketsInternal(
138       uint32_t cmd_id,
139       const std::vector<uint8_t>& ip_packet_data,
140       uint16_t ether_type,
141       const std::array<uint8_t, 6>& src_address,
142       const std::array<uint8_t, 6>& dst_address,
143       uint32_t period_in_ms);
144   WifiStatus stopSendingKeepAlivePacketsInternal(uint32_t cmd_id);
145   WifiStatus setScanningMacOuiInternal(const std::array<uint8_t, 3>& oui);
146   WifiStatus startDebugPacketFateMonitoringInternal();
147   std::pair<WifiStatus, std::vector<WifiDebugTxPacketFateReport>>
148   getDebugTxPacketFatesInternal();
149   std::pair<WifiStatus, std::vector<WifiDebugRxPacketFateReport>>
150   getDebugRxPacketFatesInternal();
151 
152   std::string ifname_;
153   std::weak_ptr<legacy_hal::WifiLegacyHal> legacy_hal_;
154   bool is_valid_;
155   hidl_callback_util::HidlCallbackHandler<IWifiStaIfaceEventCallback>
156       event_cb_handler_;
157 
158   DISALLOW_COPY_AND_ASSIGN(WifiStaIface);
159 };
160 
161 }  // namespace implementation
162 }  // namespace V1_0
163 }  // namespace wifi
164 }  // namespace hardware
165 }  // namespace android
166 
167 #endif  // WIFI_STA_IFACE_H_
168