OSDN Git Service

wificond: Use Vendor HAL for mode change
authorRoshan Pius <rpius@google.com>
Thu, 2 Mar 2017 01:13:40 +0000 (17:13 -0800)
committerRoshan Pius <rpius@google.com>
Thu, 2 Mar 2017 17:49:34 +0000 (09:49 -0800)
Also,
Removed the usage of DriverTool & HalTool from wificond.

Bug: 35765841
Test: Will send for integration tests.
Change-Id: Ie029816bec5b168e34b3b18892b9da82285c66c0

main.cpp
server.cpp
server.h
tests/server_unittest.cpp

index be52c42..9f10e4d 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -28,8 +28,6 @@
 #include <cutils/properties.h>
 #include <libminijail.h>
 #include <utils/String16.h>
-#include <wifi_hal/driver_tool.h>
-#include <wifi_system/hal_tool.h>
 #include <wifi_system/interface_tool.h>
 
 #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<android::IBinder>& 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<android::wificond::LooperBackedEventLoop> event_dispatcher(
@@ -145,9 +136,7 @@ int main(int argc, char** argv) {
   android::wificond::ScanUtils scan_utils(&netlink_manager);
 
   unique_ptr<android::wificond::Server> server(new android::wificond::Server(
-      unique_ptr<HalTool>(new HalTool),
       unique_ptr<InterfaceTool>(new InterfaceTool),
-      unique_ptr<DriverTool>(new DriverTool),
       unique_ptr<SupplicantManager>(new SupplicantManager()),
       unique_ptr<HostapdManager>(new HostapdManager()),
       &netlink_utils,
index afaba8e..79e270b 100644 (file)
@@ -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<HalTool> hal_tool,
-               unique_ptr<InterfaceTool> if_tool,
-               unique_ptr<DriverTool> driver_tool,
+Server::Server(unique_ptr<InterfaceTool> if_tool,
                unique_ptr<SupplicantManager> supplicant_manager,
                unique_ptr<HostapdManager> 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<IApInterface>* created_interface) {
   string interface_name;
   uint32_t interface_index;
   vector<uint8_t> 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<IClientInterface>* created_interface) {
   string interface_name;
   uint32_t interface_index;
   vector<uint8_t> 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<uint8_t>* interface_mac_addr) {
+bool Server::SetupInterface(string* interface_name,
+                            uint32_t* interface_index,
+                            vector<uint8_t>* 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;
   }
index 709e723..5ceca25 100644 (file)
--- a/server.h
+++ b/server.h
@@ -22,8 +22,6 @@
 #include <vector>
 
 #include <android-base/macros.h>
-#include <wifi_hal/driver_tool.h>
-#include <wifi_system/hal_tool.h>
 #include <wifi_system/interface_tool.h>
 
 #include "android/net/wifi/BnWificond.h"
@@ -44,9 +42,7 @@ class ScanUtils;
 
 class Server : public android::net::wifi::BnWificond {
  public:
-  Server(std::unique_ptr<wifi_system::HalTool> hal_tool,
-         std::unique_ptr<wifi_system::InterfaceTool> if_tool,
-         std::unique_ptr<wifi_hal::DriverTool> driver_tool,
+  Server(std::unique_ptr<wifi_system::InterfaceTool> if_tool,
          std::unique_ptr<wifi_system::SupplicantManager> supplicant_man,
          std::unique_ptr<wifi_system::HostapdManager> 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<uint8_t>* interface_mac_addr);
+  bool SetupInterface(std::string* interface_name,
+                      uint32_t* interface_index,
+                      std::vector<uint8_t>* 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<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_hal::DriverTool> driver_tool_;
   const std::unique_ptr<wifi_system::SupplicantManager> supplicant_manager_;
   const std::unique_ptr<wifi_system::HostapdManager> hostapd_manager_;
   NetlinkUtils* const netlink_utils_;
index ef21045..e9d2175 100644 (file)
@@ -18,8 +18,6 @@
 
 #include <gmock/gmock.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_interface_tool.h>
 #include <wifi_system_test/mock_supplicant_manager.h>
 #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<MockHalTool>* hal_tool_ = new NiceMock<MockHalTool>;
   NiceMock<MockInterfaceTool>* if_tool_ = new NiceMock<MockInterfaceTool>;
-  NiceMock<MockDriverTool>* driver_tool_ = new NiceMock<MockDriverTool>;
   NiceMock<MockSupplicantManager>* supplicant_manager_ =
       new NiceMock<MockSupplicantManager>;
   NiceMock<MockHostapdManager>* hostapd_manager_ =
@@ -80,9 +69,7 @@ class ServerTest : public ::testing::Test {
       new NiceMock<MockScanUtils>(netlink_manager_.get())};
 
 
-  Server server_{unique_ptr<HalTool>(hal_tool_),
-                 unique_ptr<InterfaceTool>(if_tool_),
-                 unique_ptr<DriverTool>(driver_tool_),
+  Server server_{unique_ptr<InterfaceTool>(if_tool_),
                  unique_ptr<SupplicantManager>(supplicant_manager_),
                  unique_ptr<HostapdManager>(hostapd_manager_),
                  netlink_utils_.get(),
@@ -94,12 +81,6 @@ class ServerTest : public ::testing::Test {
 TEST_F(ServerTest, CanSetUpApInterface) {
   sp<IApInterface> 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<IApInterface> 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.