summaryrefslogtreecommitdiffstats
blob: e97e967870c91281577cb552a86dd592d93ca638 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef WIFICOND_SCANNER_IMPL_H_
#define WIFICOND_SCANNER_IMPL_H_

#include <vector>

#include <android-base/macros.h>
#include <binder/Status.h>

#include "android/net/wifi/BnWifiScannerImpl.h"
#include "wificond/net/netlink_utils.h"
#include "wificond/scanning/offload/offload_scan_manager.h"
#include "wificond/scanning/scan_utils.h"
#include "wificond/scanning/offload_scan_callback_interface_impl.h"

namespace android {
namespace wificond {

class ClientInterfaceImpl;
class OffloadServiceUtils;
class ScanUtils;
class OffloadScanCallbackInterfaceImpl;

class ScannerImpl : public android::net::wifi::BnWifiScannerImpl {
 public:
  ScannerImpl(uint32_t wiphy_index, uint32_t interface_index,
              const ScanCapabilities& scan_capabilities,
              const WiphyFeatures& wiphy_features,
              ClientInterfaceImpl* client_interface,
              NetlinkUtils* netlink_utils, ScanUtils* scan_utils,
              std::weak_ptr<OffloadServiceUtils> offload_service_utils);
  ~ScannerImpl();
  // Returns a vector of available frequencies for 2.4GHz channels.
  ::android::binder::Status getAvailable2gChannels(
      ::std::unique_ptr<::std::vector<int32_t>>* out_frequencies) override;
  // Returns a vector of available frequencies for 5GHz non-DFS channels.
  ::android::binder::Status getAvailable5gNonDFSChannels(
      ::std::unique_ptr<::std::vector<int32_t>>* out_frequencies) override;
  // Returns a vector of available frequencies for DFS channels.
  ::android::binder::Status getAvailableDFSChannels(
      ::std::unique_ptr<::std::vector<int32_t>>* out_frequencies) override;
  // Get the latest scan results from kernel.
  ::android::binder::Status getScanResults(
      std::vector<com::android::server::wifi::wificond::NativeScanResult>*
          out_scan_results) override;
  ::android::binder::Status scan(
      const ::com::android::server::wifi::wificond::SingleScanSettings&
          scan_settings,
      bool* out_success) override;
  ::android::binder::Status startPnoScan(
      const ::com::android::server::wifi::wificond::PnoSettings& pno_settings,
      bool* out_success) override;
  ::android::binder::Status stopPnoScan(bool* out_success) override;
  ::android::binder::Status abortScan() override;

  ::android::binder::Status subscribeScanEvents(
      const ::android::sp<::android::net::wifi::IScanEvent>& handler) override;
  ::android::binder::Status unsubscribeScanEvents() override;
  ::android::binder::Status subscribePnoScanEvents(
      const ::android::sp<::android::net::wifi::IPnoScanEvent>& handler)
      override;
  ::android::binder::Status unsubscribePnoScanEvents() override;
  void OnOffloadScanResult();
  void OnOffloadError(
      OffloadScanCallbackInterface::AsyncErrorReason error_code);
  void Invalidate();

 private:
  bool CheckIsValid();
  void OnScanResultsReady(uint32_t interface_index, bool aborted,
                          std::vector<std::vector<uint8_t>>& ssids,
                          std::vector<uint32_t>& frequencies);
  void OnSchedScanResultsReady(uint32_t interface_index, bool scan_stopped);
  void LogSsidList(std::vector<std::vector<uint8_t>>& ssid_list,
                   std::string prefix);
  bool StartPnoScanDefault(
      const ::com::android::server::wifi::wificond::PnoSettings& pno_settings);
  bool StartPnoScanOffload(
      const ::com::android::server::wifi::wificond::PnoSettings& pno_settings);
  bool StopPnoScanDefault();
  bool StopPnoScanOffload();
  void ParsePnoSettings(
      const ::com::android::server::wifi::wificond::PnoSettings& pno_settings,
      std::vector<std::vector<uint8_t>>* scan_ssids,
      std::vector<std::vector<uint8_t>>* match_ssids,
      std::vector<uint32_t>* freqs, std::vector<uint8_t>* match_security);
  SchedScanIntervalSetting GenerateIntervalSetting(
    const ::com::android::server::wifi::wificond::PnoSettings& pno_settings) const;

  // Boolean variables describing current scanner status.
  bool valid_;
  bool scan_started_;
  bool pno_scan_started_;
  bool offload_scan_supported_;
  bool pno_scan_running_over_offload_;
  ::com::android::server::wifi::wificond::PnoSettings pno_settings_;

  const uint32_t wiphy_index_;
  const uint32_t interface_index_;

  // Scanning relevant capability information for this wiphy/interface.
  ScanCapabilities scan_capabilities_;
  WiphyFeatures wiphy_features_;

  ClientInterfaceImpl* client_interface_;
  NetlinkUtils* const netlink_utils_;
  ScanUtils* const scan_utils_;
  ::android::sp<::android::net::wifi::IPnoScanEvent> pno_scan_event_handler_;
  ::android::sp<::android::net::wifi::IScanEvent> scan_event_handler_;
  std::unique_ptr<OffloadScanManager> offload_scan_manager_;

  DISALLOW_COPY_AND_ASSIGN(ScannerImpl);
};

}  // namespace wificond
}  // namespace android

#endif  // WIFICOND_SCANNER_IMPL_H_