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/ap_interface_binder.h" 18 19 #include <android-base/logging.h> 20 #include <wifi_system/hostapd_manager.h> 21 22 #include "wificond/ap_interface_impl.h" 23 24 using android::wifi_system::HostapdManager; 25 26 namespace android { 27 namespace wificond { 28 29 ApInterfaceBinder::ApInterfaceBinder(ApInterfaceImpl* impl) : impl_{impl} { 30 } 31 32 ApInterfaceBinder::~ApInterfaceBinder() { 33 } 34 35 binder::Status ApInterfaceBinder::startHostapd(bool* out_success) { 36 *out_success = false; 37 if (!impl_) { 38 LOG(WARNING) << "Cannot start hostapd on dead ApInterface."; 39 return binder::Status::ok(); 40 } 41 *out_success = impl_->StartHostapd(); 42 return binder::Status::ok(); 43 } 44 45 binder::Status ApInterfaceBinder::stopHostapd(bool* out_success) { 46 *out_success = false; 47 if (!impl_) { 48 LOG(WARNING) << "Cannot stop hostapd on dead ApInterface."; 49 return binder::Status::ok(); 50 } 51 *out_success = impl_->StopHostapd(); 52 return binder::Status::ok(); 53 } 54 55 binder::Status ApInterfaceBinder::writeHostapdConfig( 56 const std::vector<uint8_t>& ssid, 57 bool is_hidden, 58 int32_t channel, 59 int32_t binder_encryption_type, 60 const std::vector<uint8_t>& passphrase, 61 bool* out_success) { 62 *out_success = false; 63 if (!impl_) { 64 LOG(WARNING) << "Cannot set config on dead ApInterface."; 65 return binder::Status::ok(); 66 } 67 68 HostapdManager::EncryptionType encryption_type; 69 switch (binder_encryption_type) { 70 case IApInterface::ENCRYPTION_TYPE_NONE: 71 encryption_type = HostapdManager::EncryptionType::kOpen; 72 break; 73 case IApInterface::ENCRYPTION_TYPE_WPA: 74 encryption_type = HostapdManager::EncryptionType::kWpa; 75 break; 76 case IApInterface::ENCRYPTION_TYPE_WPA2: 77 encryption_type = HostapdManager::EncryptionType::kWpa2; 78 break; 79 default: 80 LOG(ERROR) << "Unknown encryption type: " << binder_encryption_type; 81 return binder::Status::ok(); 82 } 83 84 *out_success = impl_->WriteHostapdConfig( 85 ssid, is_hidden, channel, encryption_type, passphrase); 86 87 return binder::Status::ok(); 88 } 89 90 binder::Status ApInterfaceBinder::getInterfaceName(std::string* out_name) { 91 if (!impl_) { 92 LOG(WARNING) << "Cannot get interface name from dead ApInterface"; 93 return binder::Status::ok(); 94 } 95 *out_name = impl_->GetInterfaceName(); 96 return binder::Status::ok(); 97 } 98 99 binder::Status ApInterfaceBinder::getNumberOfAssociatedStations( 100 int* out_num_of_stations) { 101 if (!impl_) { 102 LOG(WARNING) << "Cannot get number of associated stations " 103 << "from dead ApInterface"; 104 *out_num_of_stations = -1; 105 return binder::Status::ok(); 106 } 107 *out_num_of_stations = impl_->GetNumberOfAssociatedStations(); 108 return binder::Status::ok(); 109 } 110 111 } // namespace wificond 112 } // namespace android 113