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_impl.h"
19 #include <android-base/logging.h>
21 #include "wificond/ap_interface_binder.h"
23 using android::net::wifi::IApInterface;
24 using android::wifi_system::HostapdManager;
25 using android::wifi_system::InterfaceTool;
27 using std::unique_ptr;
30 using EncryptionType = android::wifi_system::HostapdManager::EncryptionType;
35 ApInterfaceImpl::ApInterfaceImpl(const string& interface_name,
36 uint32_t interface_index,
37 InterfaceTool* if_tool,
38 HostapdManager* hostapd_manager)
39 : interface_name_(interface_name),
40 interface_index_(interface_index),
42 hostapd_manager_(hostapd_manager),
43 binder_(new ApInterfaceBinder(this)) {
44 // This log keeps compiler happy.
45 LOG(DEBUG) << "Created ap interface " << interface_name_
46 << " with index " << interface_index_;
49 ApInterfaceImpl::~ApInterfaceImpl() {
50 binder_->NotifyImplDead();
51 if_tool_->SetUpState(interface_name_.c_str(), false);
54 sp<IApInterface> ApInterfaceImpl::GetBinder() const {
58 bool ApInterfaceImpl::StartHostapd() {
59 return hostapd_manager_->StartHostapd();
62 bool ApInterfaceImpl::StopHostapd() {
63 // Drop SIGKILL on hostapd.
64 bool success = hostapd_manager_->StopHostapd();
66 // Take down the interface. This has the pleasant side effect of
67 // letting the driver know that we don't want any lingering AP logic
68 // running in the driver.
69 success = if_tool_->SetUpState(interface_name_.c_str(), false) && success;
74 bool ApInterfaceImpl::WriteHostapdConfig(const vector<uint8_t>& ssid,
77 EncryptionType encryption_type,
78 const vector<uint8_t>& passphrase) {
79 string config = hostapd_manager_->CreateHostapdConfig(
80 interface_name_, ssid, is_hidden, channel, encryption_type, passphrase);
86 return hostapd_manager_->WriteHostapdConfig(config);
89 } // namespace wificond
90 } // namespace android