summaryrefslogtreecommitdiffstats
blob: c928ba9490b67fd8632020148dfb8ed0c54396f6 (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 * 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_OFFLOAD_SCAN_MANAGER_H_
#define WIFICOND_OFFLOAD_SCAN_MANAGER_H_

#include <android/hardware/wifi/offload/1.0/IOffload.h>
#include "wificond/scanning/offload/offload_callback.h"
#include "wificond/scanning/offload/offload_callback_handlers.h"
#include "wificond/scanning/offload/offload_service_utils.h"
#include "wificond/scanning/offload_scan_callback_interface.h"

#include <vector>

namespace com {
namespace android {
namespace server {
namespace wifi {
namespace wificond {

class NativeScanResult;
class NativeScanStats;

}  // namespace wificond
}  // namespace wifi
}  // namespace server
}  // namespace android
}  // namespace com

namespace android {
namespace wificond {

class OffloadScanManager;

// Provides callback interface implementation from Offload HAL
class OffloadCallbackHandlersImpl : public OffloadCallbackHandlers {
 public:
  OffloadCallbackHandlersImpl(OffloadScanManager* parent);
  ~OffloadCallbackHandlersImpl() override;

  void OnScanResultHandler(
      const std::vector<android::hardware::wifi::offload::V1_0::ScanResult>&
          scanResult) override;
  void OnErrorHandler(
      const android::hardware::wifi::offload::V1_0::OffloadStatus& status)
      override;

 private:
  OffloadScanManager* offload_scan_manager_;
};

// Provides methods to interact with Offload HAL
class OffloadScanManager {
 public:
  enum StatusCode {
    /* Corresponds to OffloadStatusCode::OK */
    kNoError,
    /* Offload HAL service not avaialble */
    kNoService,
    /* Corresponds to OffloadStatusCode::NO_CONNECTION */
    kNotConnected,
    /* Corresponds to OffloadStatusCode::TIMEOUT */
    kTimeOut,
    /* Corresponds to OffloadStatusCode::ERROR */
    kError
  };

  enum ReasonCode {
    /* Default value */
    kNone,
    /* Offload HAL scans is not available */
    kNotAvailable,
    /* Offload HAL requested operation failure */
    kOperationFailed,
    /* Binder failed to deliver message to Offload HAL*/
    kTransactionFailed,
  };

  explicit OffloadScanManager(
      std::weak_ptr<OffloadServiceUtils> utils,
      std::shared_ptr<OffloadScanCallbackInterface> callback);
  virtual ~OffloadScanManager();
  /* Request start of offload scans with scan parameters and scan filter
   * settings. Internally calls Offload HAL service with configureScans()
   * and subscribeScanResults() APIs. Reason code indicates failure reason.
   */
  bool startScan(uint32_t /* interval_ms */, int32_t /* rssi_threshold */,
                 const std::vector<std::vector<uint8_t>>& /* scan_ssids */,
                 const std::vector<std::vector<uint8_t>>& /* match_ssids */,
                 const std::vector<uint8_t>& /* match_security */,
                 const std::vector<uint32_t>& /* freqs */,
                 ReasonCode* /* failure reason */);
  /* Request stop of offload scans, returns true if the operation succeeds
   * Otherwise, returns false. Reason code is updated in case of failure.
   */
  bool stopScan(ReasonCode* /* failure reason */);
  /* Get statistics for scans performed by Offload HAL */
  bool getScanStats(
      ::com::android::server::wifi::wificond::NativeScanStats* /* scanStats */);
  /* Otain status of the Offload HAL service */
  StatusCode getOffloadStatus() const;
  /* Returns the most recent scan result available from Offload HAL */
  bool getScanResults(
      std::vector<::com::android::server::wifi::wificond::NativeScanResult>*
          out_scan_results);

 private:
  void ReportScanResults(
      const std::vector<android::hardware::wifi::offload::V1_0::ScanResult>&
          scanResult);
  void ReportError(
      const android::hardware::wifi::offload::V1_0::OffloadStatus& status);
  bool VerifyAndConvertHIDLStatus(
      std::pair<android::hardware::wifi::offload::V1_0::OffloadStatus, bool>
          result,
      OffloadScanManager::ReasonCode* reason_code);
  bool GetScanStats(
      ::com::android::server::wifi::wificond::NativeScanStats* stats);
  bool SubscribeScanResults(OffloadScanManager::ReasonCode* reason_code);
  bool ConfigureScans(android::hardware::wifi::offload::V1_0::ScanParam,
                      android::hardware::wifi::offload::V1_0::ScanFilter,
                      OffloadScanManager::ReasonCode* reason_code);
  /* Handle binder death */
  void OnObjectDeath(uint64_t /* cookie */);

  android::sp<android::hardware::wifi::offload::V1_0::IOffload>
      wifi_offload_hal_;
  android::sp<OffloadCallback> wifi_offload_callback_;
  android::sp<OffloadDeathRecipient> death_recipient_;
  StatusCode offload_status_;
  std::vector<::com::android::server::wifi::wificond::NativeScanResult>
      cached_scan_results_;

  const std::unique_ptr<OffloadCallbackHandlersImpl> offload_callback_handlers_;
  std::shared_ptr<OffloadScanCallbackInterface> event_callback_;

  friend class OffloadCallbackHandlersImpl;
};

}  // namespace wificond
}  // namespace android

#endif  // WIFICOND_OFFLOAD_SCAN_MANAGER_H_