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/nl80211/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::nl80211::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<android::net::wifi::nl80211::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<android::net::wifi::nl80211::NativeScanResult>* 51 out_scan_results) override; 52 ::android::binder::Status getMaxSsidsPerScan( 53 int32_t* out_max_ssids_per_scan) override; 54 ::android::binder::Status scan( 55 const android::net::wifi::nl80211::SingleScanSettings& 56 scan_settings, 57 bool* out_success) override; 58 ::android::binder::Status scanRequest( 59 const android::net::wifi::nl80211::SingleScanSettings& 60 scan_settings, 61 int* status) override; 62 ::android::binder::Status startPnoScan( 63 const android::net::wifi::nl80211::PnoSettings& pno_settings, 64 bool* out_success) override; 65 ::android::binder::Status stopPnoScan(bool* out_success) override; 66 ::android::binder::Status abortScan() override; 67 68 ::android::binder::Status subscribeScanEvents( 69 const ::android::sp<::android::net::wifi::nl80211::IScanEvent>& handler) override; 70 ::android::binder::Status unsubscribeScanEvents() override; 71 ::android::binder::Status subscribePnoScanEvents( 72 const ::android::sp<::android::net::wifi::nl80211::IPnoScanEvent>& handler) 73 override; 74 ::android::binder::Status unsubscribePnoScanEvents() override; 75 void Invalidate(); 76 77 private: 78 bool CheckIsValid(); 79 void OnScanResultsReady(uint32_t interface_index, bool aborted, 80 std::vector<std::vector<uint8_t>>& ssids, 81 std::vector<uint32_t>& frequencies); 82 void OnSchedScanResultsReady(uint32_t interface_index, bool scan_stopped); 83 void LogSsidList(std::vector<std::vector<uint8_t>>& ssid_list, 84 std::string prefix); 85 bool StartPnoScanDefault( 86 const android::net::wifi::nl80211::PnoSettings& pno_settings); 87 bool StopPnoScanDefault(); 88 void ParsePnoSettings( 89 const android::net::wifi::nl80211::PnoSettings& pno_settings, 90 std::vector<std::vector<uint8_t>>* scan_ssids, 91 std::vector<std::vector<uint8_t>>* match_ssids, 92 std::vector<uint32_t>* freqs, std::vector<uint8_t>* match_security); 93 SchedScanIntervalSetting GenerateIntervalSetting( 94 const android::net::wifi::nl80211::PnoSettings& pno_settings) const; 95 96 // Boolean variables describing current scanner status. 97 bool valid_; 98 bool scan_started_; 99 bool pno_scan_started_; 100 android::net::wifi::nl80211::PnoSettings pno_settings_; 101 102 uint32_t nodev_counter_; 103 const uint32_t interface_index_; 104 105 // Scanning relevant capability information for this wiphy/interface. 106 ScanCapabilities scan_capabilities_; 107 WiphyFeatures wiphy_features_; 108 109 ClientInterfaceImpl* client_interface_; 110 ScanUtils* const scan_utils_; 111 ::android::sp<::android::net::wifi::nl80211::IPnoScanEvent> pno_scan_event_handler_; 112 ::android::sp<::android::net::wifi::nl80211::IScanEvent> scan_event_handler_; 113 114 DISALLOW_COPY_AND_ASSIGN(ScannerImpl); 115 }; 116 117 } // namespace wificond 118 } // namespace android 119 120 #endif // WIFICOND_SCANNER_IMPL_H_ 121