lin
2025-03-11 6f4f7a76e03a46fefb056a4b18197f1d9e8aa939
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 * 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.
 */
 
#include "wificond/client_interface_binder.h"
 
#include <algorithm>
#include <vector>
 
#include <linux/if_ether.h>
 
#include <android-base/logging.h>
 
#include <binder/Status.h>
 
#include "wificond/client_interface_impl.h"
 
using android::binder::Status;
using android::net::wifi::ISendMgmtFrameEvent;
using android::net::wifi::IWifiScannerImpl;
using std::vector;
 
namespace android {
namespace wificond {
 
ClientInterfaceBinder::ClientInterfaceBinder(ClientInterfaceImpl* impl)
    : impl_(impl) {
}
 
ClientInterfaceBinder::~ClientInterfaceBinder() {
}
 
Status ClientInterfaceBinder::getPacketCounters(
    vector<int32_t>* out_packet_counters) {
  if (impl_ == nullptr) {
    return Status::ok();
  }
  impl_->GetPacketCounters(out_packet_counters);
  return Status::ok();
}
 
Status ClientInterfaceBinder::signalPoll(
    vector<int32_t>* out_signal_poll_results) {
  if (impl_ == nullptr) {
    return Status::ok();
  }
  impl_->SignalPoll(out_signal_poll_results);
  return Status::ok();
}
 
Status ClientInterfaceBinder::getMacAddress(vector<uint8_t>* out_mac_address) {
  if (impl_ == nullptr) {
    return Status::ok();
  }
  const std::array<uint8_t, ETH_ALEN>& mac = impl_->GetMacAddress();
  *out_mac_address = vector<uint8_t>(mac.begin(), mac.end());
  return Status::ok();
}
 
Status ClientInterfaceBinder::getInterfaceName(std::string* out_name) {
  if (impl_ == nullptr) {
    return Status::ok();
  }
  *out_name = impl_->GetInterfaceName();
  return Status::ok();
}
 
Status ClientInterfaceBinder::getWifiScannerImpl(
    sp<IWifiScannerImpl>* out_wifi_scanner_impl) {
  if (impl_ == nullptr) {
    *out_wifi_scanner_impl = nullptr;
    return Status::ok();
  }
  *out_wifi_scanner_impl = impl_->GetScanner();
  return Status::ok();
}
 
 
Status ClientInterfaceBinder::setMacAddress(const vector<uint8_t>& mac, bool* success) {
  if (impl_ == nullptr) {
    *success = false;
    return Status::ok();
  }
  if (mac.size() != ETH_ALEN) {
    LOG(ERROR) << "Invalid MAC length " << mac.size();
    *success = false;
    return Status::ok();
  }
  std::array<uint8_t, ETH_ALEN> mac_array;
  std::copy_n(mac.begin(), ETH_ALEN, mac_array.begin());
  *success = impl_->SetMacAddress(mac_array);
  return Status::ok();
}
 
Status ClientInterfaceBinder::SendMgmtFrame(const vector<uint8_t>& frame,
    const sp<ISendMgmtFrameEvent>& callback, int32_t mcs) {
  if (impl_ == nullptr) {
    callback->OnFailure(ISendMgmtFrameEvent::SEND_MGMT_FRAME_ERROR_UNKNOWN);
    return Status::ok();
  }
  // TODO (b/112029045) validate mcs
  impl_->SendMgmtFrame(frame, callback, mcs);
  return Status::ok();
}
 
}  // namespace wificond
}  // namespace android