#include <android-base/logging.h>
+#include "wificond/net/netlink_utils.h"
+
#include "wificond/ap_interface_binder.h"
using android::net::wifi::IApInterface;
using android::wifi_system::HostapdManager;
+using android::wifi_system::InterfaceTool;
using std::string;
using std::unique_ptr;
using std::vector;
namespace wificond {
ApInterfaceImpl::ApInterfaceImpl(const string& interface_name,
- unique_ptr<HostapdManager> hostapd_manager)
+ uint32_t interface_index,
+ NetlinkUtils* netlink_utils,
+ InterfaceTool* if_tool,
+ HostapdManager* hostapd_manager)
: interface_name_(interface_name),
- hostapd_manager_(std::move(hostapd_manager)) {
- binder_ = new ApInterfaceBinder(this);
+ interface_index_(interface_index),
+ netlink_utils_(netlink_utils),
+ if_tool_(if_tool),
+ hostapd_manager_(hostapd_manager),
+ binder_(new ApInterfaceBinder(this)) {
+ // This log keeps compiler happy.
+ LOG(DEBUG) << "Created ap interface " << interface_name_
+ << " with index " << interface_index_;
}
ApInterfaceImpl::~ApInterfaceImpl() {
binder_->NotifyImplDead();
+ if_tool_->SetUpState(interface_name_.c_str(), false);
}
sp<IApInterface> ApInterfaceImpl::GetBinder() const {
}
bool ApInterfaceImpl::StopHostapd() {
- pid_t hostapd_pid;
- if (hostapd_manager_->GetHostapdPid(&hostapd_pid)) {
- // We do this because it was found that hostapd would leave the driver in a
- // bad state if init killed it harshly with a SIGKILL. b/30311493
- if (kill(hostapd_pid, SIGTERM) == -1) {
- LOG(ERROR) << "Error delivering signal to hostapd: " << strerror(errno);
- }
- // This should really be asynchronous: b/30465379
- for (int tries = 0; tries < 10; tries++) {
- // Try to give hostapd some time to go down.
- if (!hostapd_manager_->IsHostapdRunning()) {
- break;
- }
- usleep(10 * 1000); // Don't busy wait.
- }
+ // Drop SIGKILL on hostapd.
+ if (!hostapd_manager_->StopHostapd()) {
+ // Logging was done internally.
+ return false;
+ }
+
+ // Take down the interface.
+ if (!if_tool_->SetUpState(interface_name_.c_str(), false)) {
+ // Logging was done internally.
+ return false;
+ }
+
+ // Since wificond SIGKILLs hostapd, hostapd has no chance to handle
+ // the cleanup.
+ // Besides taking down the interface, we also need to set the interface mode
+ // back to station mode for the cleanup.
+ if (!netlink_utils_->SetInterfaceMode(interface_index_,
+ NetlinkUtils::STATION_MODE)) {
+ LOG(ERROR) << "Failed to set interface back to station mode";
+ return false;
}
- // Always drop a SIGKILL on hostapd on the way out, just in case.
- return hostapd_manager_->StopHostapd();
+ return true;
}
bool ApInterfaceImpl::WriteHostapdConfig(const vector<uint8_t>& ssid,