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_scan_callback_interface.h" 28 #include "wificond/scanning/scan_utils.h" 29 30 namespace android { 31 namespace wificond { 32 33 class ClientInterfaceImpl; 34 class OffloadServiceUtils; 35 class ScanUtils; 36 class OffloadScanCallbackInterfaceImpl; 37 class OffloadScanManager; 38 39 class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { 40 public: 41 ScannerImpl(uint32_t interface_index, 42 const ScanCapabilities& scan_capabilities, 43 const WiphyFeatures& wiphy_features, 44 ClientInterfaceImpl* client_interface, 45 ScanUtils* scan_utils, 46 std::weak_ptr<OffloadServiceUtils> offload_service_utils); 47 ~ScannerImpl(); 48 // Get the latest single scan results from kernel. 49 ::android::binder::Status getScanResults( 50 std::vector<com::android::server::wifi::wificond::NativeScanResult>* 51 out_scan_results) override; 52 // Get the latest pno scan results from the interface that most recently 53 // completed PNO scans 54 ::android::binder::Status getPnoScanResults( 55 std::vector<com::android::server::wifi::wificond::NativeScanResult>* 56 out_scan_results) override; 57 ::android::binder::Status scan( 58 const ::com::android::server::wifi::wificond::SingleScanSettings& 59 scan_settings, 60 bool* out_success) override; 61 ::android::binder::Status startPnoScan( 62 const ::com::android::server::wifi::wificond::PnoSettings& pno_settings, 63 bool* out_success) override; 64 ::android::binder::Status stopPnoScan(bool* out_success) override; 65 ::android::binder::Status abortScan() override; 66 67 ::android::binder::Status subscribeScanEvents( 68 const ::android::sp<::android::net::wifi::IScanEvent>& handler) override; 69 ::android::binder::Status unsubscribeScanEvents() override; 70 ::android::binder::Status subscribePnoScanEvents( 71 const ::android::sp<::android::net::wifi::IPnoScanEvent>& handler) 72 override; 73 ::android::binder::Status unsubscribePnoScanEvents() override; 74 void OnOffloadScanResult(); 75 void OnOffloadError( 76 OffloadScanCallbackInterface::AsyncErrorReason error_code); 77 void Invalidate(); 78 79 private: 80 bool CheckIsValid(); 81 void OnScanResultsReady(uint32_t interface_index, bool aborted, 82 std::vector<std::vector<uint8_t>>& ssids, 83 std::vector<uint32_t>& frequencies); 84 void OnSchedScanResultsReady(uint32_t interface_index, bool scan_stopped); 85 void LogSsidList(std::vector<std::vector<uint8_t>>& ssid_list, 86 std::string prefix); 87 bool StartPnoScanDefault( 88 const ::com::android::server::wifi::wificond::PnoSettings& pno_settings); 89 bool StartPnoScanOffload( 90 const ::com::android::server::wifi::wificond::PnoSettings& pno_settings); 91 bool StopPnoScanDefault(); 92 bool StopPnoScanOffload(); 93 void ParsePnoSettings( 94 const ::com::android::server::wifi::wificond::PnoSettings& pno_settings, 95 std::vector<std::vector<uint8_t>>* scan_ssids, 96 std::vector<std::vector<uint8_t>>* match_ssids, 97 std::vector<uint32_t>* freqs, std::vector<uint8_t>* match_security); 98 SchedScanIntervalSetting GenerateIntervalSetting( 99 const ::com::android::server::wifi::wificond::PnoSettings& pno_settings) const; 100 101 // Boolean variables describing current scanner status. 102 bool valid_; 103 bool scan_started_; 104 bool pno_scan_started_; 105 bool offload_scan_supported_; 106 bool pno_scan_running_over_offload_; 107 bool pno_scan_results_from_offload_; 108 ::com::android::server::wifi::wificond::PnoSettings pno_settings_; 109 110 const uint32_t interface_index_; 111 112 // Scanning relevant capability information for this wiphy/interface. 113 ScanCapabilities scan_capabilities_; 114 WiphyFeatures wiphy_features_; 115 116 ClientInterfaceImpl* client_interface_; 117 ScanUtils* const scan_utils_; 118 ::android::sp<::android::net::wifi::IPnoScanEvent> pno_scan_event_handler_; 119 ::android::sp<::android::net::wifi::IScanEvent> scan_event_handler_; 120 std::shared_ptr<OffloadScanManager> offload_scan_manager_; 121 122 DISALLOW_COPY_AND_ASSIGN(ScannerImpl); 123 }; 124 125 } // namespace wificond 126 } // namespace android 127 128 #endif // WIFICOND_SCANNER_IMPL_H_ 129