OSDN Git Service

Wificond: Converting Offload scan results update
[android-x86/system-connectivity-wificond.git] / scanning / scanner_impl.h
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 WIFICOND_SCANNER_IMPL_H_
18 #define WIFICOND_SCANNER_IMPL_H_
19
20 #include <vector>
21
22 #include <android-base/macros.h>
23 #include <binder/Status.h>
24
25 #include "android/net/wifi/BnWifiScannerImpl.h"
26 #include "wificond/net/netlink_utils.h"
27 #include "wificond/scanning/offload/offload_scan_manager.h"
28 #include "wificond/scanning/scan_utils.h"
29
30 namespace android {
31 namespace wificond {
32
33 class ClientInterfaceImpl;
34 class OffloadServiceUtils;
35
36 class ScannerImpl : public android::net::wifi::BnWifiScannerImpl {
37  public:
38   ScannerImpl(uint32_t wiphy_index,
39               uint32_t interface_index,
40               const ScanCapabilities& scan_capabilities,
41               const WiphyFeatures& wiphy_features,
42               ClientInterfaceImpl* client_interface,
43               NetlinkUtils* netlink_utils,
44               ScanUtils* scan_utils,
45               std::weak_ptr<OffloadServiceUtils> offload_service_utils);
46   ~ScannerImpl();
47   // Returns a vector of available frequencies for 2.4GHz channels.
48   ::android::binder::Status getAvailable2gChannels(
49       ::std::unique_ptr<::std::vector<int32_t>>* out_frequencies) override;
50   // Returns a vector of available frequencies for 5GHz non-DFS channels.
51   ::android::binder::Status getAvailable5gNonDFSChannels(
52       ::std::unique_ptr<::std::vector<int32_t>>* out_frequencies) override;
53   // Returns a vector of available frequencies for DFS channels.
54   ::android::binder::Status getAvailableDFSChannels(
55       ::std::unique_ptr<::std::vector<int32_t>>* out_frequencies) override;
56   // Get the latest scan results from kernel.
57   ::android::binder::Status getScanResults(
58       std::vector<com::android::server::wifi::wificond::NativeScanResult>*
59           out_scan_results) override;
60   ::android::binder::Status scan(
61       const ::com::android::server::wifi::wificond::SingleScanSettings&
62           scan_settings,
63       bool* out_success) override;
64   ::android::binder::Status startPnoScan(
65       const ::com::android::server::wifi::wificond::PnoSettings& pno_settings,
66       bool* out_success) override;
67   ::android::binder::Status stopPnoScan(bool* out_success) override;
68   ::android::binder::Status abortScan() override;
69
70   ::android::binder::Status subscribeScanEvents(
71       const ::android::sp<::android::net::wifi::IScanEvent>& handler) override;
72   ::android::binder::Status unsubscribeScanEvents() override;
73   ::android::binder::Status subscribePnoScanEvents(
74       const ::android::sp<::android::net::wifi::IPnoScanEvent>& handler) override;
75   ::android::binder::Status unsubscribePnoScanEvents() override;
76   void Invalidate();
77
78  private:
79   bool CheckIsValid();
80   void OnOffloadScanResult(
81       std::vector<::com::android::server::wifi::wificond::NativeScanResult>);
82   void OnScanResultsReady(
83       uint32_t interface_index,
84       bool aborted,
85       std::vector<std::vector<uint8_t>>& ssids,
86       std::vector<uint32_t>& frequencies);
87   void OnSchedScanResultsReady(uint32_t interface_index, bool scan_stopped);
88   void LogSsidList(std::vector<std::vector<uint8_t>>& ssid_list,
89                    std::string prefix);
90   bool StartPnoScanDefault(
91       const ::com::android::server::wifi::wificond::PnoSettings& pno_settings);
92   bool StartPnoScanOffload(
93       const ::com::android::server::wifi::wificond::PnoSettings& pno_settings);
94   bool StopPnoScanDefault();
95   bool StopPnoScanOffload();
96   void ParsePnoSettings(
97     const ::com::android::server::wifi::wificond::PnoSettings& pno_settings,
98     std::vector<std::vector<uint8_t>>* scan_ssids,
99     std::vector<std::vector<uint8_t>>* match_ssids,
100     std::vector<uint32_t>* freqs,
101     std::vector<uint8_t>* match_security);
102   SchedScanIntervalSetting GenerateIntervalSetting(
103     const ::com::android::server::wifi::wificond::PnoSettings& pno_settings) const;
104
105   // Boolean variables describing current scanner status.
106   bool valid_;
107   bool scan_started_;
108   bool pno_scan_started_;
109   bool offload_scan_supported_;
110
111   const uint32_t wiphy_index_;
112   const uint32_t interface_index_;
113
114   // Scanning relevant capability information for this wiphy/interface.
115   ScanCapabilities scan_capabilities_;
116   WiphyFeatures wiphy_features_;
117
118   ClientInterfaceImpl* client_interface_;
119   NetlinkUtils* const netlink_utils_;
120   ScanUtils* const scan_utils_;
121   ::android::sp<::android::net::wifi::IPnoScanEvent> pno_scan_event_handler_;
122   ::android::sp<::android::net::wifi::IScanEvent> scan_event_handler_;
123   std::unique_ptr<OffloadScanManager> offload_scan_manager_;
124
125   DISALLOW_COPY_AND_ASSIGN(ScannerImpl);
126 };
127
128 }  // namespace wificond
129 }  // namespace android
130
131 #endif  // WIFICOND_SCANNER_IMPL_H_