OSDN Git Service

Merge "Add function StopScheduledScan()"
[android-x86/system-connectivity-wificond.git] / client_interface_impl.cpp
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 #include "wificond/client_interface_impl.h"
18
19 #include <vector>
20
21 #include <android-base/logging.h>
22 #include <wifi_system/supplicant_manager.h>
23 #include <wifi_system/wifi.h>
24
25 #include "wificond/client_interface_binder.h"
26 #include "wificond/scanning/scan_result.h"
27 #include "wificond/scanning/scan_utils.h"
28
29 using android::net::wifi::IClientInterface;
30 using android::sp;
31 using android::wifi_system::SupplicantManager;
32
33 using namespace std::placeholders;
34 using std::string;
35 using std::vector;
36
37 namespace android {
38 namespace wificond {
39
40 ClientInterfaceImpl::ClientInterfaceImpl(
41     const std::string& interface_name,
42     uint32_t interface_index,
43     const std::vector<uint8_t>& interface_mac_addr,
44     SupplicantManager* supplicant_manager,
45     ScanUtils* scan_utils)
46     : interface_name_(interface_name),
47       interface_index_(interface_index),
48       interface_mac_addr_(interface_mac_addr),
49       supplicant_manager_(supplicant_manager),
50       scan_utils_(scan_utils),
51       binder_(new ClientInterfaceBinder(this)) {
52   scan_utils_->SubscribeScanResultNotification(
53       interface_index_,
54       std::bind(&ClientInterfaceImpl::OnScanResultsReady, this, _1, _2, _3));
55 }
56
57 ClientInterfaceImpl::~ClientInterfaceImpl() {
58   binder_->NotifyImplDead();
59   DisableSupplicant();
60   scan_utils_->UnsubscribeScanResultNotification(interface_index_);
61 }
62
63 sp<android::net::wifi::IClientInterface> ClientInterfaceImpl::GetBinder() const {
64   return binder_;
65 }
66
67 bool ClientInterfaceImpl::EnableSupplicant() {
68   return supplicant_manager_->StartSupplicant();
69 }
70
71 bool ClientInterfaceImpl::DisableSupplicant() {
72   return supplicant_manager_->StopSupplicant();
73 }
74
75 void ClientInterfaceImpl::OnScanResultsReady(
76                          uint32_t interface_index,
77                          std::vector<std::vector<uint8_t>>& ssids,
78                          std::vector<uint32_t>& frequencies) {
79   vector<ScanResult> scan_results;
80   // TODO(nywang): Find a way to differentiate scan results for
81   // internel/external scan request. This is useful when location is
82   // scanning using regular NL80211 commands.
83   scan_utils_->GetScanResult(interface_index, &scan_results);
84   // TODO(nywang): Send these scan results back to java framework.
85 }
86
87 }  // namespace wificond
88 }  // namespace android