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_binder.h"
18
19 #include <algorithm>
20 #include <vector>
21
22 #include <linux/if_ether.h>
23
24 #include <android-base/logging.h>
25
26 #include <binder/Status.h>
27
28 #include "wificond/client_interface_impl.h"
29
30 using android::binder::Status;
31 using android::net::wifi::nl80211::ISendMgmtFrameEvent;
32 using android::net::wifi::nl80211::IWifiScannerImpl;
33 using std::vector;
34
35 namespace android {
36 namespace wificond {
37
ClientInterfaceBinder(ClientInterfaceImpl * impl)38 ClientInterfaceBinder::ClientInterfaceBinder(ClientInterfaceImpl* impl)
39 : impl_(impl) {
40 }
41
~ClientInterfaceBinder()42 ClientInterfaceBinder::~ClientInterfaceBinder() {
43 }
44
getPacketCounters(vector<int32_t> * out_packet_counters)45 Status ClientInterfaceBinder::getPacketCounters(
46 vector<int32_t>* out_packet_counters) {
47 if (impl_ == nullptr) {
48 return Status::ok();
49 }
50 impl_->GetPacketCounters(out_packet_counters);
51 return Status::ok();
52 }
53
signalPoll(vector<int32_t> * out_signal_poll_results)54 Status ClientInterfaceBinder::signalPoll(
55 vector<int32_t>* out_signal_poll_results) {
56 if (impl_ == nullptr) {
57 return Status::ok();
58 }
59 impl_->SignalPoll(out_signal_poll_results);
60 return Status::ok();
61 }
62
getMacAddress(vector<uint8_t> * out_mac_address)63 Status ClientInterfaceBinder::getMacAddress(vector<uint8_t>* out_mac_address) {
64 if (impl_ == nullptr) {
65 return Status::ok();
66 }
67 const std::array<uint8_t, ETH_ALEN>& mac = impl_->GetMacAddress();
68 *out_mac_address = vector<uint8_t>(mac.begin(), mac.end());
69 return Status::ok();
70 }
71
getInterfaceName(std::string * out_name)72 Status ClientInterfaceBinder::getInterfaceName(std::string* out_name) {
73 if (impl_ == nullptr) {
74 return Status::ok();
75 }
76 *out_name = impl_->GetInterfaceName();
77 return Status::ok();
78 }
79
getWifiScannerImpl(sp<IWifiScannerImpl> * out_wifi_scanner_impl)80 Status ClientInterfaceBinder::getWifiScannerImpl(
81 sp<IWifiScannerImpl>* out_wifi_scanner_impl) {
82 if (impl_ == nullptr) {
83 *out_wifi_scanner_impl = nullptr;
84 return Status::ok();
85 }
86 *out_wifi_scanner_impl = impl_->GetScanner();
87 return Status::ok();
88 }
89
SendMgmtFrame(const vector<uint8_t> & frame,const sp<ISendMgmtFrameEvent> & callback,int32_t mcs)90 Status ClientInterfaceBinder::SendMgmtFrame(const vector<uint8_t>& frame,
91 const sp<ISendMgmtFrameEvent>& callback, int32_t mcs) {
92 if (impl_ == nullptr) {
93 callback->OnFailure(ISendMgmtFrameEvent::SEND_MGMT_FRAME_ERROR_UNKNOWN);
94 return Status::ok();
95 }
96 // TODO (b/112029045) validate mcs
97 impl_->SendMgmtFrame(frame, callback, mcs);
98 return Status::ok();
99 }
100
101 } // namespace wificond
102 } // namespace android
103