OSDN Git Service

Add getMacAddress() to wificond binder interface am: cc77f636f4
[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/net/netlink_utils.h"
27 #include "wificond/scanning/scan_result.h"
28 #include "wificond/scanning/scan_utils.h"
29
30 using android::net::wifi::IClientInterface;
31 using android::sp;
32 using android::wifi_system::SupplicantManager;
33
34 using namespace std::placeholders;
35 using std::string;
36 using std::unique_ptr;
37 using std::vector;
38
39 namespace android {
40 namespace wificond {
41
42 ClientInterfaceImpl::ClientInterfaceImpl(
43     const std::string& interface_name,
44     uint32_t interface_index,
45     const std::vector<uint8_t>& interface_mac_addr,
46     SupplicantManager* supplicant_manager,
47     NetlinkUtils* netlink_utils,
48     ScanUtils* scan_utils)
49     : interface_name_(interface_name),
50       interface_index_(interface_index),
51       interface_mac_addr_(interface_mac_addr),
52       supplicant_manager_(supplicant_manager),
53       netlink_utils_(netlink_utils),
54       scan_utils_(scan_utils),
55       binder_(new ClientInterfaceBinder(this)) {
56   scan_utils_->SubscribeScanResultNotification(
57       interface_index_,
58       std::bind(&ClientInterfaceImpl::OnScanResultsReady,
59                 this,
60                 _1, _2, _3, _4));
61 }
62
63 ClientInterfaceImpl::~ClientInterfaceImpl() {
64   binder_->NotifyImplDead();
65   DisableSupplicant();
66   scan_utils_->UnsubscribeScanResultNotification(interface_index_);
67 }
68
69 sp<android::net::wifi::IClientInterface> ClientInterfaceImpl::GetBinder() const {
70   return binder_;
71 }
72
73 bool ClientInterfaceImpl::EnableSupplicant() {
74   return supplicant_manager_->StartSupplicant();
75 }
76
77 bool ClientInterfaceImpl::DisableSupplicant() {
78   return supplicant_manager_->StopSupplicant();
79 }
80
81 bool ClientInterfaceImpl::GetPacketCounters(vector<int32_t>* out_packet_counters) {
82   StationInfo station_info;
83   if(!netlink_utils_->GetStationInfo(interface_index_,
84                                      interface_mac_addr_,
85                                      &station_info)) {
86     return false;
87   }
88   out_packet_counters->push_back(station_info.station_tx_packets);
89   out_packet_counters->push_back(station_info.station_tx_failed);
90   return true;
91 }
92
93 const vector<uint8_t>& ClientInterfaceImpl::GetMacAddress() {
94   return interface_mac_addr_;
95 }
96
97 void ClientInterfaceImpl::OnScanResultsReady(
98                          uint32_t interface_index,
99                          bool aborted,
100                          std::vector<std::vector<uint8_t>>& ssids,
101                          std::vector<uint32_t>& frequencies) {
102   if (aborted) {
103     LOG(ERROR) << "Scan aborted";
104     return;
105   }
106   vector<ScanResult> scan_results;
107   // TODO(nywang): Find a way to differentiate scan results for
108   // internel/external scan request. This is useful when location is
109   // scanning using regular NL80211 commands.
110   scan_utils_->GetScanResult(interface_index, &scan_results);
111   // TODO(nywang): Send these scan results back to java framework.
112 }
113
114 }  // namespace wificond
115 }  // namespace android