client_interface_binder.cpp 3.2 KB

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