wificond: Use Vendor HAL for mode change

Also,
Removed the usage of DriverTool & HalTool from wificond.

Bug: 35765841
Test: Will send for integration tests.
Change-Id: Ie029816bec5b168e34b3b18892b9da82285c66c0
This commit is contained in:
Roshan Pius 2017-03-01 17:13:40 -08:00
parent 58271c3933
commit b5c68afba4
4 changed files with 16 additions and 82 deletions

View File

@ -28,8 +28,6 @@
#include <cutils/properties.h> #include <cutils/properties.h>
#include <libminijail.h> #include <libminijail.h>
#include <utils/String16.h> #include <utils/String16.h>
#include <wifi_hal/driver_tool.h>
#include <wifi_system/hal_tool.h>
#include <wifi_system/interface_tool.h> #include <wifi_system/interface_tool.h>
#include "wificond/ipc_constants.h" #include "wificond/ipc_constants.h"
@ -40,8 +38,6 @@
#include "wificond/server.h" #include "wificond/server.h"
using android::net::wifi::IWificond; using android::net::wifi::IWificond;
using android::wifi_hal::DriverTool;
using android::wifi_system::HalTool;
using android::wifi_system::HostapdManager; using android::wifi_system::HostapdManager;
using android::wifi_system::InterfaceTool; using android::wifi_system::InterfaceTool;
using android::wifi_system::SupplicantManager; using android::wifi_system::SupplicantManager;
@ -101,10 +97,6 @@ void RegisterServiceOrCrash(const android::sp<android::IBinder>& service) {
android::NO_ERROR); android::NO_ERROR);
} }
void DoPrivilegedSetupOrCrash() {
CHECK(DriverTool::TakeOwnershipOfFirmwareReload());
}
void DropPrivilegesOrCrash() { void DropPrivilegesOrCrash() {
minijail* j = minijail_new(); minijail* j = minijail_new();
CHECK(minijail_change_user(j, "wifi") == 0); CHECK(minijail_change_user(j, "wifi") == 0);
@ -126,7 +118,6 @@ int main(int argc, char** argv) {
android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM)); android::base::InitLogging(argv, android::base::LogdLogger(android::base::SYSTEM));
LOG(INFO) << "wificond is starting up..."; LOG(INFO) << "wificond is starting up...";
DoPrivilegedSetupOrCrash();
DropPrivilegesOrCrash(); DropPrivilegesOrCrash();
unique_ptr<android::wificond::LooperBackedEventLoop> event_dispatcher( unique_ptr<android::wificond::LooperBackedEventLoop> event_dispatcher(
@ -145,9 +136,7 @@ int main(int argc, char** argv) {
android::wificond::ScanUtils scan_utils(&netlink_manager); android::wificond::ScanUtils scan_utils(&netlink_manager);
unique_ptr<android::wificond::Server> server(new android::wificond::Server( unique_ptr<android::wificond::Server> server(new android::wificond::Server(
unique_ptr<HalTool>(new HalTool),
unique_ptr<InterfaceTool>(new InterfaceTool), unique_ptr<InterfaceTool>(new InterfaceTool),
unique_ptr<DriverTool>(new DriverTool),
unique_ptr<SupplicantManager>(new SupplicantManager()), unique_ptr<SupplicantManager>(new SupplicantManager()),
unique_ptr<HostapdManager>(new HostapdManager()), unique_ptr<HostapdManager>(new HostapdManager()),
&netlink_utils, &netlink_utils,

View File

@ -31,8 +31,6 @@ using android::net::wifi::IClientInterface;
using android::net::wifi::IInterfaceEventCallback; using android::net::wifi::IInterfaceEventCallback;
using android::net::wifi::IRttClient; using android::net::wifi::IRttClient;
using android::net::wifi::IRttController; using android::net::wifi::IRttController;
using android::wifi_hal::DriverTool;
using android::wifi_system::HalTool;
using android::wifi_system::HostapdManager; using android::wifi_system::HostapdManager;
using android::wifi_system::InterfaceTool; using android::wifi_system::InterfaceTool;
using android::wifi_system::SupplicantManager; using android::wifi_system::SupplicantManager;
@ -46,16 +44,12 @@ using std::vector;
namespace android { namespace android {
namespace wificond { namespace wificond {
Server::Server(unique_ptr<HalTool> hal_tool, Server::Server(unique_ptr<InterfaceTool> if_tool,
unique_ptr<InterfaceTool> if_tool,
unique_ptr<DriverTool> driver_tool,
unique_ptr<SupplicantManager> supplicant_manager, unique_ptr<SupplicantManager> supplicant_manager,
unique_ptr<HostapdManager> hostapd_manager, unique_ptr<HostapdManager> hostapd_manager,
NetlinkUtils* netlink_utils, NetlinkUtils* netlink_utils,
ScanUtils* scan_utils) ScanUtils* scan_utils)
: hal_tool_(std::move(hal_tool)), : if_tool_(std::move(if_tool)),
if_tool_(std::move(if_tool)),
driver_tool_(std::move(driver_tool)),
supplicant_manager_(std::move(supplicant_manager)), supplicant_manager_(std::move(supplicant_manager)),
hostapd_manager_(std::move(hostapd_manager)), hostapd_manager_(std::move(hostapd_manager)),
netlink_utils_(netlink_utils), netlink_utils_(netlink_utils),
@ -112,8 +106,7 @@ Status Server::createApInterface(sp<IApInterface>* created_interface) {
string interface_name; string interface_name;
uint32_t interface_index; uint32_t interface_index;
vector<uint8_t> interface_mac_addr; vector<uint8_t> interface_mac_addr;
if (!SetupInterfaceForMode(DriverTool::kFirmwareModeAp, if (!SetupInterface(&interface_name,
&interface_name,
&interface_index, &interface_index,
&interface_mac_addr)) { &interface_mac_addr)) {
return Status::ok(); // Logging was done internally return Status::ok(); // Logging was done internally
@ -136,8 +129,7 @@ Status Server::createClientInterface(sp<IClientInterface>* created_interface) {
string interface_name; string interface_name;
uint32_t interface_index; uint32_t interface_index;
vector<uint8_t> interface_mac_addr; vector<uint8_t> interface_mac_addr;
if (!SetupInterfaceForMode(DriverTool::kFirmwareModeSta, if (!SetupInterface(&interface_name,
&interface_name,
&interface_index, &interface_index,
&interface_mac_addr)) { &interface_mac_addr)) {
return Status::ok(); // Logging was done internally return Status::ok(); // Logging was done internally
@ -172,9 +164,6 @@ Status Server::tearDownInterfaces() {
netlink_utils_->UnsubscribeRegDomainChange(wiphy_index_); netlink_utils_->UnsubscribeRegDomainChange(wiphy_index_);
if (!driver_tool_->UnloadDriver()) {
LOG(ERROR) << "Failed to unload WiFi driver!";
}
return Status::ok(); return Status::ok();
} }
@ -212,15 +201,11 @@ void Server::CleanUpSystemState() {
// as a client. // as a client.
if_tool_->SetUpState(if_name.c_str(), false); if_tool_->SetUpState(if_name.c_str(), false);
} }
// "unloading the driver" is frequently a no-op in systems that
// don't have kernel modules, but just in case.
driver_tool_->UnloadDriver();
} }
bool Server::SetupInterfaceForMode(int mode, bool Server::SetupInterface(string* interface_name,
string* interface_name, uint32_t* interface_index,
uint32_t* interface_index, vector<uint8_t>* interface_mac_addr) {
vector<uint8_t>* interface_mac_addr) {
if (!ap_interfaces_.empty() || !client_interfaces_.empty()) { if (!ap_interfaces_.empty() || !client_interfaces_.empty()) {
// In the future we may support multiple interfaces at once. However, // In the future we may support multiple interfaces at once. However,
// today, we support just one. // today, we support just one.
@ -228,16 +213,6 @@ bool Server::SetupInterfaceForMode(int mode,
return false; return false;
} }
string result;
if (!driver_tool_->LoadDriver()) {
LOG(ERROR) << "Failed to load WiFi driver!";
return false;
}
if (!driver_tool_->ChangeFirmwareMode(mode)) {
LOG(ERROR) << "Failed to change WiFi firmware mode!";
return false;
}
if (!RefreshWiphyIndex()) { if (!RefreshWiphyIndex()) {
return false; return false;
} }

View File

@ -22,8 +22,6 @@
#include <vector> #include <vector>
#include <android-base/macros.h> #include <android-base/macros.h>
#include <wifi_hal/driver_tool.h>
#include <wifi_system/hal_tool.h>
#include <wifi_system/interface_tool.h> #include <wifi_system/interface_tool.h>
#include "android/net/wifi/BnWificond.h" #include "android/net/wifi/BnWificond.h"
@ -44,9 +42,7 @@ class ScanUtils;
class Server : public android::net::wifi::BnWificond { class Server : public android::net::wifi::BnWificond {
public: public:
Server(std::unique_ptr<wifi_system::HalTool> hal_tool, Server(std::unique_ptr<wifi_system::InterfaceTool> if_tool,
std::unique_ptr<wifi_system::InterfaceTool> if_tool,
std::unique_ptr<wifi_hal::DriverTool> driver_tool,
std::unique_ptr<wifi_system::SupplicantManager> supplicant_man, std::unique_ptr<wifi_system::SupplicantManager> supplicant_man,
std::unique_ptr<wifi_system::HostapdManager> hostapd_man, std::unique_ptr<wifi_system::HostapdManager> hostapd_man,
NetlinkUtils* netlink_utils, NetlinkUtils* netlink_utils,
@ -90,17 +86,14 @@ class Server : public android::net::wifi::BnWificond {
void CleanUpSystemState(); void CleanUpSystemState();
private: private:
// Does the actual work of setting up an interface for a particular mode. // Request interface information from kernel and setup local interface object.
// // This assumes that interface should be in STATION mode. Even if we setup
// |mode| is one of WIFI_GET_FW_PATH_* defined in hardware_legacy/wifi.h. // interface on behalf of createApInterace(), it is Hostapd that configure
// |interface_name| is a pointer to a string to store the name of Linux // the interface to Ap mode later.
// network interface that has been setup.
//
// Returns true on success, false otherwise. // Returns true on success, false otherwise.
bool SetupInterfaceForMode(int mode, bool SetupInterface(std::string* interface_name,
std::string* interface_name, uint32_t* interface_index,
uint32_t* interface_index, std::vector<uint8_t>* interface_mac_addr);
std::vector<uint8_t>* interface_mac_addr);
bool RefreshWiphyIndex(); bool RefreshWiphyIndex();
void LogSupportedBands(); void LogSupportedBands();
void OnRegDomainChanged(std::string& country_code); void OnRegDomainChanged(std::string& country_code);
@ -113,9 +106,7 @@ class Server : public android::net::wifi::BnWificond {
void BroadcastApInterfaceTornDown( void BroadcastApInterfaceTornDown(
android::sp<android::net::wifi::IApInterface> network_interface); android::sp<android::net::wifi::IApInterface> network_interface);
const std::unique_ptr<wifi_system::HalTool> hal_tool_;
const std::unique_ptr<wifi_system::InterfaceTool> if_tool_; const std::unique_ptr<wifi_system::InterfaceTool> if_tool_;
const std::unique_ptr<wifi_hal::DriverTool> driver_tool_;
const std::unique_ptr<wifi_system::SupplicantManager> supplicant_manager_; const std::unique_ptr<wifi_system::SupplicantManager> supplicant_manager_;
const std::unique_ptr<wifi_system::HostapdManager> hostapd_manager_; const std::unique_ptr<wifi_system::HostapdManager> hostapd_manager_;
NetlinkUtils* const netlink_utils_; NetlinkUtils* const netlink_utils_;

View File

@ -18,8 +18,6 @@
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <wifi_hal_test/mock_driver_tool.h>
#include <wifi_system_test/mock_hal_tool.h>
#include <wifi_system_test/mock_hostapd_manager.h> #include <wifi_system_test/mock_hostapd_manager.h>
#include <wifi_system_test/mock_interface_tool.h> #include <wifi_system_test/mock_interface_tool.h>
#include <wifi_system_test/mock_supplicant_manager.h> #include <wifi_system_test/mock_supplicant_manager.h>
@ -31,12 +29,8 @@
#include "wificond/server.h" #include "wificond/server.h"
using android::net::wifi::IApInterface; using android::net::wifi::IApInterface;
using android::wifi_hal::DriverTool;
using android::wifi_hal::MockDriverTool;
using android::wifi_system::HalTool;
using android::wifi_system::HostapdManager; using android::wifi_system::HostapdManager;
using android::wifi_system::InterfaceTool; using android::wifi_system::InterfaceTool;
using android::wifi_system::MockHalTool;
using android::wifi_system::MockHostapdManager; using android::wifi_system::MockHostapdManager;
using android::wifi_system::MockInterfaceTool; using android::wifi_system::MockInterfaceTool;
using android::wifi_system::MockSupplicantManager; using android::wifi_system::MockSupplicantManager;
@ -54,18 +48,13 @@ namespace {
class ServerTest : public ::testing::Test { class ServerTest : public ::testing::Test {
protected: protected:
void SetUp() override { void SetUp() override {
ON_CALL(*driver_tool_, LoadDriver()).WillByDefault(Return(true));
ON_CALL(*driver_tool_, UnloadDriver()).WillByDefault(Return(true));
ON_CALL(*driver_tool_, ChangeFirmwareMode(_)).WillByDefault(Return(true));
ON_CALL(*if_tool_, SetWifiUpState(_)).WillByDefault(Return(true)); ON_CALL(*if_tool_, SetWifiUpState(_)).WillByDefault(Return(true));
ON_CALL(*netlink_utils_, GetWiphyIndex(_)).WillByDefault(Return(true)); ON_CALL(*netlink_utils_, GetWiphyIndex(_)).WillByDefault(Return(true));
ON_CALL(*netlink_utils_, GetInterfaceInfo(_, _, _, _)) ON_CALL(*netlink_utils_, GetInterfaceInfo(_, _, _, _))
.WillByDefault(Return(true)); .WillByDefault(Return(true));
} }
NiceMock<MockHalTool>* hal_tool_ = new NiceMock<MockHalTool>;
NiceMock<MockInterfaceTool>* if_tool_ = new NiceMock<MockInterfaceTool>; NiceMock<MockInterfaceTool>* if_tool_ = new NiceMock<MockInterfaceTool>;
NiceMock<MockDriverTool>* driver_tool_ = new NiceMock<MockDriverTool>;
NiceMock<MockSupplicantManager>* supplicant_manager_ = NiceMock<MockSupplicantManager>* supplicant_manager_ =
new NiceMock<MockSupplicantManager>; new NiceMock<MockSupplicantManager>;
NiceMock<MockHostapdManager>* hostapd_manager_ = NiceMock<MockHostapdManager>* hostapd_manager_ =
@ -80,9 +69,7 @@ class ServerTest : public ::testing::Test {
new NiceMock<MockScanUtils>(netlink_manager_.get())}; new NiceMock<MockScanUtils>(netlink_manager_.get())};
Server server_{unique_ptr<HalTool>(hal_tool_), Server server_{unique_ptr<InterfaceTool>(if_tool_),
unique_ptr<InterfaceTool>(if_tool_),
unique_ptr<DriverTool>(driver_tool_),
unique_ptr<SupplicantManager>(supplicant_manager_), unique_ptr<SupplicantManager>(supplicant_manager_),
unique_ptr<HostapdManager>(hostapd_manager_), unique_ptr<HostapdManager>(hostapd_manager_),
netlink_utils_.get(), netlink_utils_.get(),
@ -94,12 +81,6 @@ class ServerTest : public ::testing::Test {
TEST_F(ServerTest, CanSetUpApInterface) { TEST_F(ServerTest, CanSetUpApInterface) {
sp<IApInterface> ap_if; sp<IApInterface> ap_if;
Sequence sequence; Sequence sequence;
EXPECT_CALL(*driver_tool_, LoadDriver())
.InSequence(sequence)
.WillOnce(Return(true));
EXPECT_CALL(*driver_tool_, ChangeFirmwareMode(DriverTool::kFirmwareModeAp))
.InSequence(sequence)
.WillOnce(Return(true));
EXPECT_CALL(*netlink_utils_, GetWiphyIndex(_)) EXPECT_CALL(*netlink_utils_, GetWiphyIndex(_))
.InSequence(sequence) .InSequence(sequence)
.WillOnce(Return(true)); .WillOnce(Return(true));
@ -131,12 +112,10 @@ TEST_F(ServerTest, CanDestroyInterfaces) {
sp<IApInterface> ap_if; sp<IApInterface> ap_if;
EXPECT_CALL(*netlink_utils_, GetWiphyIndex(_)).Times(2); EXPECT_CALL(*netlink_utils_, GetWiphyIndex(_)).Times(2);
EXPECT_CALL(*netlink_utils_, GetInterfaceInfo(_, _, _, _)).Times(2); EXPECT_CALL(*netlink_utils_, GetInterfaceInfo(_, _, _, _)).Times(2);
EXPECT_CALL(*driver_tool_, UnloadDriver()).Times(0);
EXPECT_TRUE(server_.createApInterface(&ap_if).isOk()); EXPECT_TRUE(server_.createApInterface(&ap_if).isOk());
// When we tear down the interface, we expect the driver to be unloaded. // When we tear down the interface, we expect the driver to be unloaded.
EXPECT_CALL(*driver_tool_, UnloadDriver()).Times(1).WillOnce(Return(true));
EXPECT_CALL(*netlink_utils_, UnsubscribeRegDomainChange(_)); EXPECT_CALL(*netlink_utils_, UnsubscribeRegDomainChange(_));
EXPECT_TRUE(server_.tearDownInterfaces().isOk()); EXPECT_TRUE(server_.tearDownInterfaces().isOk());
// After a teardown, we should be able to create another interface. // After a teardown, we should be able to create another interface.