2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "wificond/ap_interface_binder.h"
19 #include <android-base/logging.h>
20 #include <wifi_system/hostapd_manager.h>
22 #include "wificond/ap_interface_impl.h"
24 using android::wifi_system::HostapdManager;
29 ApInterfaceBinder::ApInterfaceBinder(ApInterfaceImpl* impl) : impl_{impl} {
32 ApInterfaceBinder::~ApInterfaceBinder() {
35 binder::Status ApInterfaceBinder::startHostapd(bool* out_success) {
38 LOG(WARNING) << "Cannot start hostapd on dead ApInterface.";
39 return binder::Status::ok();
41 *out_success = impl_->StartHostapd();
42 return binder::Status::ok();
45 binder::Status ApInterfaceBinder::stopHostapd(bool* out_success) {
48 LOG(WARNING) << "Cannot stop hostapd on dead ApInterface.";
49 return binder::Status::ok();
51 *out_success = impl_->StopHostapd();
52 return binder::Status::ok();
55 binder::Status ApInterfaceBinder::writeHostapdConfig(
56 const std::vector<uint8_t>& ssid,
59 int32_t binder_encryption_type,
60 const std::vector<uint8_t>& passphrase,
64 LOG(WARNING) << "Cannot set config on dead ApInterface.";
65 return binder::Status::ok();
68 HostapdManager::EncryptionType encryption_type;
69 switch (binder_encryption_type) {
70 case IApInterface::ENCRYPTION_TYPE_NONE:
71 encryption_type = HostapdManager::EncryptionType::kOpen;
73 case IApInterface::ENCRYPTION_TYPE_WPA:
74 encryption_type = HostapdManager::EncryptionType::kWpa;
76 case IApInterface::ENCRYPTION_TYPE_WPA2:
77 encryption_type = HostapdManager::EncryptionType::kWpa2;
80 LOG(ERROR) << "Unknown encryption type: " << binder_encryption_type;
81 return binder::Status::ok();
84 *out_success = impl_->WriteHostapdConfig(
85 ssid, is_hidden, channel, encryption_type, passphrase);
87 return binder::Status::ok();
90 binder::Status ApInterfaceBinder::getInterfaceName(std::string* out_name) {
92 LOG(WARNING) << "Cannot get interface name from dead ApInterface";
93 return binder::Status::ok();
95 *out_name = impl_->GetInterfaceName();
96 return binder::Status::ok();
99 binder::Status ApInterfaceBinder::getNumberOfAssociatedStations(
100 int* out_num_of_stations) {
102 LOG(WARNING) << "Cannot get number of associated stations "
103 << "from dead ApInterface";
104 *out_num_of_stations = -1;
105 return binder::Status::ok();
107 *out_num_of_stations = impl_->GetNumberOfAssociatedStations();
108 return binder::Status::ok();
111 } // namespace wificond
112 } // namespace android