From a0687c403abfb1605c7afbe100e30f3d884587ca Mon Sep 17 00:00:00 2001 From: Ningyuan Wang Date: Fri, 9 Dec 2016 11:53:12 -0800 Subject: [PATCH] Add scan() to wificond scanner Bug: 33398008 Change-Id: Ib2009547ccc8fc368bd92e88a216b61cefe9a8ad Test: compile --- aidl/android/net/wifi/IWifiScannerImpl.aidl | 3 ++ .../server/wifi/wificond/SingleScanSettings.aidl | 19 ++++++++++++ scanning/scanner_impl.cpp | 35 ++++++++++++++++++++++ scanning/scanner_impl.h | 4 +++ 4 files changed, 61 insertions(+) create mode 100644 aidl/com/android/server/wifi/wificond/SingleScanSettings.aidl diff --git a/aidl/android/net/wifi/IWifiScannerImpl.aidl b/aidl/android/net/wifi/IWifiScannerImpl.aidl index d799330..4306826 100644 --- a/aidl/android/net/wifi/IWifiScannerImpl.aidl +++ b/aidl/android/net/wifi/IWifiScannerImpl.aidl @@ -17,6 +17,7 @@ package android.net.wifi; import com.android.server.wifi.wificond.NativeScanResult; +import com.android.server.wifi.wificond.SingleScanSettings; interface IWifiScannerImpl { // Returns an array of available frequencies for 2.4GHz channels. @@ -27,5 +28,7 @@ interface IWifiScannerImpl { int[] getAvailableDFSChannels(); // Get the latest scan results from kernel. NativeScanResult[] getScanResults(); + // Request a single scan using a SingleScanSettings parcelable object. + boolean scan(in SingleScanSettings scanSettings); // TODO(nywang) add more interfaces. } diff --git a/aidl/com/android/server/wifi/wificond/SingleScanSettings.aidl b/aidl/com/android/server/wifi/wificond/SingleScanSettings.aidl new file mode 100644 index 0000000..abae5fe --- /dev/null +++ b/aidl/com/android/server/wifi/wificond/SingleScanSettings.aidl @@ -0,0 +1,19 @@ +/* + * 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. + */ + +package com.android.server.wifi.wificond; + +parcelable SingleScanSettings cpp_header "wificond/scanning/single_scan_settings.h"; diff --git a/scanning/scanner_impl.cpp b/scanning/scanner_impl.cpp index 8f389c7..aac2b05 100644 --- a/scanning/scanner_impl.cpp +++ b/scanning/scanner_impl.cpp @@ -16,6 +16,7 @@ #include "wificond/scanning/scanner_impl.h" +#include #include #include @@ -23,7 +24,10 @@ #include "wificond/scanning/scan_utils.h" using android::binder::Status; +using android::String16; using com::android::server::wifi::wificond::NativeScanResult; +using com::android::server::wifi::wificond::SingleScanSettings; +using std::string; using std::vector; namespace android { @@ -91,5 +95,36 @@ Status ScannerImpl::getScanResults(vector* out_scan_results) { return Status::ok(); } +Status ScannerImpl::scan(const SingleScanSettings& scan_settings, + bool* out_success) { + if (!CheckIsValid()) { + return Status::ok(); + } + if (scan_settings.is_full_scan_) { + if (!scan_utils_->StartFullScan(interface_index_)) { + *out_success = false; + return Status::ok(); + } + } + + // Initialize it with an empty ssid for a wild card scan. + vector> ssids = {{0}}; + for (auto& network : scan_settings.hidden_networks_) { + ssids.push_back(network.ssid_); + } + vector freqs; + for (auto& channel : scan_settings.channel_settings_) { + freqs.push_back(channel.frequency_); + } + + if (!scan_utils_->Scan(interface_index_, ssids, freqs)) { + *out_success = false; + LOG(ERROR) << "Failed to start a scan"; + return Status::ok(); + } + *out_success = true; + return Status::ok(); +} + } // namespace wificond } // namespace android diff --git a/scanning/scanner_impl.h b/scanning/scanner_impl.h index b0b31aa..945195f 100644 --- a/scanning/scanner_impl.h +++ b/scanning/scanner_impl.h @@ -51,6 +51,10 @@ class ScannerImpl : public android::net::wifi::BnWifiScannerImpl { ::android::binder::Status getScanResults( std::vector* out_scan_results) override; + ::android::binder::Status scan( + const ::com::android::server::wifi::wificond::SingleScanSettings& + scan_settings, + bool* out_success) override; void Invalidate() { valid_ = false; } private: -- 2.11.0