diff --git a/main.cpp b/main.cpp index be52c42..9f10e4d 100644 --- a/main.cpp +++ b/main.cpp @@ -28,8 +28,6 @@ #include #include #include -#include -#include #include #include "wificond/ipc_constants.h" @@ -40,8 +38,6 @@ #include "wificond/server.h" using android::net::wifi::IWificond; -using android::wifi_hal::DriverTool; -using android::wifi_system::HalTool; using android::wifi_system::HostapdManager; using android::wifi_system::InterfaceTool; using android::wifi_system::SupplicantManager; @@ -101,10 +97,6 @@ void RegisterServiceOrCrash(const android::sp& service) { android::NO_ERROR); } -void DoPrivilegedSetupOrCrash() { - CHECK(DriverTool::TakeOwnershipOfFirmwareReload()); -} - void DropPrivilegesOrCrash() { minijail* j = minijail_new(); 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)); LOG(INFO) << "wificond is starting up..."; - DoPrivilegedSetupOrCrash(); DropPrivilegesOrCrash(); unique_ptr event_dispatcher( @@ -145,9 +136,7 @@ int main(int argc, char** argv) { android::wificond::ScanUtils scan_utils(&netlink_manager); unique_ptr server(new android::wificond::Server( - unique_ptr(new HalTool), unique_ptr(new InterfaceTool), - unique_ptr(new DriverTool), unique_ptr(new SupplicantManager()), unique_ptr(new HostapdManager()), &netlink_utils, diff --git a/server.cpp b/server.cpp index afaba8e..79e270b 100644 --- a/server.cpp +++ b/server.cpp @@ -31,8 +31,6 @@ using android::net::wifi::IClientInterface; using android::net::wifi::IInterfaceEventCallback; using android::net::wifi::IRttClient; using android::net::wifi::IRttController; -using android::wifi_hal::DriverTool; -using android::wifi_system::HalTool; using android::wifi_system::HostapdManager; using android::wifi_system::InterfaceTool; using android::wifi_system::SupplicantManager; @@ -46,16 +44,12 @@ using std::vector; namespace android { namespace wificond { -Server::Server(unique_ptr hal_tool, - unique_ptr if_tool, - unique_ptr driver_tool, +Server::Server(unique_ptr if_tool, unique_ptr supplicant_manager, unique_ptr hostapd_manager, NetlinkUtils* netlink_utils, ScanUtils* scan_utils) - : hal_tool_(std::move(hal_tool)), - if_tool_(std::move(if_tool)), - driver_tool_(std::move(driver_tool)), + : if_tool_(std::move(if_tool)), supplicant_manager_(std::move(supplicant_manager)), hostapd_manager_(std::move(hostapd_manager)), netlink_utils_(netlink_utils), @@ -112,8 +106,7 @@ Status Server::createApInterface(sp* created_interface) { string interface_name; uint32_t interface_index; vector interface_mac_addr; - if (!SetupInterfaceForMode(DriverTool::kFirmwareModeAp, - &interface_name, + if (!SetupInterface(&interface_name, &interface_index, &interface_mac_addr)) { return Status::ok(); // Logging was done internally @@ -136,8 +129,7 @@ Status Server::createClientInterface(sp* created_interface) { string interface_name; uint32_t interface_index; vector interface_mac_addr; - if (!SetupInterfaceForMode(DriverTool::kFirmwareModeSta, - &interface_name, + if (!SetupInterface(&interface_name, &interface_index, &interface_mac_addr)) { return Status::ok(); // Logging was done internally @@ -172,9 +164,6 @@ Status Server::tearDownInterfaces() { netlink_utils_->UnsubscribeRegDomainChange(wiphy_index_); - if (!driver_tool_->UnloadDriver()) { - LOG(ERROR) << "Failed to unload WiFi driver!"; - } return Status::ok(); } @@ -212,15 +201,11 @@ void Server::CleanUpSystemState() { // as a client. 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, - string* interface_name, - uint32_t* interface_index, - vector* interface_mac_addr) { +bool Server::SetupInterface(string* interface_name, + uint32_t* interface_index, + vector* interface_mac_addr) { if (!ap_interfaces_.empty() || !client_interfaces_.empty()) { // In the future we may support multiple interfaces at once. However, // today, we support just one. @@ -228,16 +213,6 @@ bool Server::SetupInterfaceForMode(int mode, 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()) { return false; } diff --git a/server.h b/server.h index 709e723..5ceca25 100644 --- a/server.h +++ b/server.h @@ -22,8 +22,6 @@ #include #include -#include -#include #include #include "android/net/wifi/BnWificond.h" @@ -44,9 +42,7 @@ class ScanUtils; class Server : public android::net::wifi::BnWificond { public: - Server(std::unique_ptr hal_tool, - std::unique_ptr if_tool, - std::unique_ptr driver_tool, + Server(std::unique_ptr if_tool, std::unique_ptr supplicant_man, std::unique_ptr hostapd_man, NetlinkUtils* netlink_utils, @@ -90,17 +86,14 @@ class Server : public android::net::wifi::BnWificond { void CleanUpSystemState(); private: - // Does the actual work of setting up an interface for a particular mode. - // - // |mode| is one of WIFI_GET_FW_PATH_* defined in hardware_legacy/wifi.h. - // |interface_name| is a pointer to a string to store the name of Linux - // network interface that has been setup. - // + // Request interface information from kernel and setup local interface object. + // This assumes that interface should be in STATION mode. Even if we setup + // interface on behalf of createApInterace(), it is Hostapd that configure + // the interface to Ap mode later. // Returns true on success, false otherwise. - bool SetupInterfaceForMode(int mode, - std::string* interface_name, - uint32_t* interface_index, - std::vector* interface_mac_addr); + bool SetupInterface(std::string* interface_name, + uint32_t* interface_index, + std::vector* interface_mac_addr); bool RefreshWiphyIndex(); void LogSupportedBands(); void OnRegDomainChanged(std::string& country_code); @@ -113,9 +106,7 @@ class Server : public android::net::wifi::BnWificond { void BroadcastApInterfaceTornDown( android::sp network_interface); - const std::unique_ptr hal_tool_; const std::unique_ptr if_tool_; - const std::unique_ptr driver_tool_; const std::unique_ptr supplicant_manager_; const std::unique_ptr hostapd_manager_; NetlinkUtils* const netlink_utils_; diff --git a/tests/server_unittest.cpp b/tests/server_unittest.cpp index ef21045..e9d2175 100644 --- a/tests/server_unittest.cpp +++ b/tests/server_unittest.cpp @@ -18,8 +18,6 @@ #include #include -#include -#include #include #include #include @@ -31,12 +29,8 @@ #include "wificond/server.h" 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::InterfaceTool; -using android::wifi_system::MockHalTool; using android::wifi_system::MockHostapdManager; using android::wifi_system::MockInterfaceTool; using android::wifi_system::MockSupplicantManager; @@ -54,18 +48,13 @@ namespace { class ServerTest : public ::testing::Test { protected: 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(*netlink_utils_, GetWiphyIndex(_)).WillByDefault(Return(true)); ON_CALL(*netlink_utils_, GetInterfaceInfo(_, _, _, _)) .WillByDefault(Return(true)); } - NiceMock* hal_tool_ = new NiceMock; NiceMock* if_tool_ = new NiceMock; - NiceMock* driver_tool_ = new NiceMock; NiceMock* supplicant_manager_ = new NiceMock; NiceMock* hostapd_manager_ = @@ -80,9 +69,7 @@ class ServerTest : public ::testing::Test { new NiceMock(netlink_manager_.get())}; - Server server_{unique_ptr(hal_tool_), - unique_ptr(if_tool_), - unique_ptr(driver_tool_), + Server server_{unique_ptr(if_tool_), unique_ptr(supplicant_manager_), unique_ptr(hostapd_manager_), netlink_utils_.get(), @@ -94,12 +81,6 @@ class ServerTest : public ::testing::Test { TEST_F(ServerTest, CanSetUpApInterface) { sp ap_if; 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(_)) .InSequence(sequence) .WillOnce(Return(true)); @@ -131,12 +112,10 @@ TEST_F(ServerTest, CanDestroyInterfaces) { sp ap_if; EXPECT_CALL(*netlink_utils_, GetWiphyIndex(_)).Times(2); EXPECT_CALL(*netlink_utils_, GetInterfaceInfo(_, _, _, _)).Times(2); - EXPECT_CALL(*driver_tool_, UnloadDriver()).Times(0); EXPECT_TRUE(server_.createApInterface(&ap_if).isOk()); // 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_TRUE(server_.tearDownInterfaces().isOk()); // After a teardown, we should be able to create another interface.