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