diff --git a/aidl/android/net/wifi/IWificond.aidl b/aidl/android/net/wifi/IWificond.aidl index 0b303ad..f1dd10f 100644 --- a/aidl/android/net/wifi/IWificond.aidl +++ b/aidl/android/net/wifi/IWificond.aidl @@ -25,10 +25,10 @@ import android.net.wifi.IInterfaceEventCallback; interface IWificond { // Create a network interface suitable for use as an AP. - @nullable IApInterface createApInterface(); + @nullable IApInterface createApInterface(@utf8InCpp String iface_name); // Create a network interface suitable for use as a WiFi client. - @nullable IClientInterface createClientInterface(); + @nullable IClientInterface createClientInterface(@utf8InCpp String iface_name); // Tear down all existing interfaces. This should enable clients to create // future interfaces immediately after this method returns. diff --git a/server.cpp b/server.cpp index 88010fb..82828e7 100644 --- a/server.cpp +++ b/server.cpp @@ -94,9 +94,10 @@ Status Server::UnregisterCallback(const sp& callback) { return Status::ok(); } -Status Server::createApInterface(sp* created_interface) { +Status Server::createApInterface(const std::string& iface_name, + sp* created_interface) { InterfaceInfo interface; - if (!SetupInterface(&interface)) { + if (!SetupInterface(iface_name, &interface)) { return Status::ok(); // Logging was done internally } @@ -113,9 +114,10 @@ Status Server::createApInterface(sp* created_interface) { return Status::ok(); } -Status Server::createClientInterface(sp* created_interface) { +Status Server::createClientInterface(const std::string& iface_name, + sp* created_interface) { InterfaceInfo interface; - if (!SetupInterface(&interface)) { + if (!SetupInterface(iface_name, &interface)) { return Status::ok(); // Logging was done internally } @@ -220,7 +222,8 @@ void Server::CleanUpSystemState() { MarkDownAllInterfaces(); } -bool Server::SetupInterface(InterfaceInfo* interface) { +bool Server::SetupInterface(const std::string& iface_name, + InterfaceInfo* interface) { if (!ap_interfaces_.empty() || !client_interfaces_.empty()) { // In the future we may support multiple interfaces at once. However, // today, we support just one. @@ -245,13 +248,7 @@ bool Server::SetupInterface(InterfaceInfo* interface) { } for (const auto& iface : interfaces_) { - // Some kernel/driver uses station type for p2p interface. - // In that case we can only rely on hard-coded name to exclude - // p2p interface from station interfaces. - // Currently NAN interfaces also use station type. - // We should blacklist NAN interfaces as well. - if (iface.name != "p2p0" && - !android::base::StartsWith(iface.name, "aware_data")) { + if (iface.name == iface_name) { *interface = iface; return true; } diff --git a/server.h b/server.h index 4c131d4..5b35880 100644 --- a/server.h +++ b/server.h @@ -58,10 +58,12 @@ class Server : public android::net::wifi::BnWificond { callback) override; android::binder::Status createApInterface( + const std::string& iface_name, android::sp* created_interface) override; android::binder::Status createClientInterface( + const std::string& iface_name, android::sp* created_interface) override; @@ -84,7 +86,7 @@ class Server : public android::net::wifi::BnWificond { // interface on behalf of createApInterace(), it is Hostapd that configure // the interface to Ap mode later. // Returns true on success, false otherwise. - bool SetupInterface(InterfaceInfo* interface); + bool SetupInterface(const std::string& iface_name, InterfaceInfo* interface); bool RefreshWiphyIndex(); void LogSupportedBands(); void OnRegDomainChanged(std::string& country_code); diff --git a/tests/integration/ap_interface_test.cpp b/tests/integration/ap_interface_test.cpp index 29206d0..18b9b29 100644 --- a/tests/integration/ap_interface_test.cpp +++ b/tests/integration/ap_interface_test.cpp @@ -41,6 +41,7 @@ namespace { constexpr int kHostapdStartupTimeoutSeconds = 3; constexpr int kHostapdDeathTimeoutSeconds = 3; +const char kInterfaceName[] = "wlan0"; const char kValidSsid[] = "foobar"; const char kInvalidSsid[] = "0123456789" "0123456789" @@ -56,7 +57,7 @@ TEST(ApInterfaceTest, CanCreateApInterfaces) { // We should be able to create an AP interface. sp ap_interface; - EXPECT_TRUE(service->createApInterface(&ap_interface).isOk()); + EXPECT_TRUE(service->createApInterface(kInterfaceName, &ap_interface).isOk()); EXPECT_NE(nullptr, ap_interface.get()); // The interface should start out down. @@ -72,7 +73,8 @@ TEST(ApInterfaceTest, CanCreateApInterfaces) { // We should not be able to create two AP interfaces. sp ap_interface2; - EXPECT_TRUE(service->createApInterface(&ap_interface2).isOk()); + EXPECT_TRUE(service->createApInterface( + kInterfaceName, &ap_interface2).isOk()); EXPECT_EQ(nullptr, ap_interface2.get()); // We can tear down the created interface. @@ -86,7 +88,7 @@ TEST(ApInterfaceTest, CanStartStopHostapd) { ScopedDevModeWificond dev_mode; sp service = dev_mode.EnterDevModeOrDie(); sp ap_interface; - EXPECT_TRUE(service->createApInterface(&ap_interface).isOk()); + EXPECT_TRUE(service->createApInterface(kInterfaceName, &ap_interface).isOk()); ASSERT_NE(nullptr, ap_interface.get()); // Interface should start out down. @@ -143,7 +145,7 @@ TEST(ApInterfaceTest, CanWriteHostapdConfig) { ScopedDevModeWificond dev_mode; sp service = dev_mode.EnterDevModeOrDie(); sp ap_interface; - EXPECT_TRUE(service->createApInterface(&ap_interface).isOk()); + EXPECT_TRUE(service->createApInterface(kInterfaceName, &ap_interface).isOk()); ASSERT_NE(nullptr, ap_interface.get()); bool success = false; diff --git a/tests/integration/client_interface_test.cpp b/tests/integration/client_interface_test.cpp index 6177f17..dc8ecd5 100644 --- a/tests/integration/client_interface_test.cpp +++ b/tests/integration/client_interface_test.cpp @@ -39,6 +39,7 @@ namespace android { namespace wificond { namespace { +const char kInterfaceName[] = "wlan0"; constexpr int kSupplicantStartupTimeoutSeconds = 3; constexpr int kSupplicantDeathTimeoutSeconds = 3; @@ -50,7 +51,8 @@ TEST(ClientInterfaceTest, CanCreateClientInterfaces) { // We should be able to create an client interface. sp client_interface; - EXPECT_TRUE(service->createClientInterface(&client_interface).isOk()); + EXPECT_TRUE(service->createClientInterface( + kInterfaceName, &client_interface).isOk()); EXPECT_NE(nullptr, client_interface.get()); // The interface should start out down. @@ -66,7 +68,8 @@ TEST(ClientInterfaceTest, CanCreateClientInterfaces) { // We should not be able to create two client interfaces. sp client_interface2; - EXPECT_TRUE(service->createClientInterface(&client_interface2).isOk()); + EXPECT_TRUE(service->createClientInterface( + kInterfaceName, &client_interface2).isOk()); EXPECT_EQ(nullptr, client_interface2.get()); // We can tear down the created interface. @@ -78,7 +81,8 @@ TEST(ClientInterfaceTest, CanStartStopSupplicant) { ScopedDevModeWificond dev_mode; sp service = dev_mode.EnterDevModeOrDie(); sp client_interface; - EXPECT_TRUE(service->createClientInterface(&client_interface).isOk()); + EXPECT_TRUE(service->createClientInterface( + kInterfaceName, &client_interface).isOk()); ASSERT_NE(nullptr, client_interface.get()); for (int iteration = 0; iteration < 4; iteration++) { @@ -108,7 +112,8 @@ TEST(ClientInterfaceTest, CanGetMacAddress) { ScopedDevModeWificond dev_mode; sp service = dev_mode.EnterDevModeOrDie(); sp client_interface; - EXPECT_TRUE(service->createClientInterface(&client_interface).isOk()); + EXPECT_TRUE(service->createClientInterface( + kInterfaceName, &client_interface).isOk()); ASSERT_NE(nullptr, client_interface.get()); vector mac_address; EXPECT_TRUE(client_interface->getMacAddress(&mac_address).isOk()); diff --git a/tests/integration/scanner_test.cpp b/tests/integration/scanner_test.cpp index 9e67acc..01f1fe4 100644 --- a/tests/integration/scanner_test.cpp +++ b/tests/integration/scanner_test.cpp @@ -34,11 +34,13 @@ using std::vector; namespace android { namespace wificond { namespace { +const char kInterfaceName[] = "wlan0"; sp InitInterfaceAndReturnScanner(sp service) { sp scanner; sp client_interface; - if (!service->createClientInterface(&client_interface).isOk()) { + if (!service->createClientInterface( + kInterfaceName, &client_interface).isOk()) { LOG(FATAL) << "Failed to create client interface"; return nullptr; } diff --git a/tests/integration/service_test.cpp b/tests/integration/service_test.cpp index a2b86a1..136cedc 100644 --- a/tests/integration/service_test.cpp +++ b/tests/integration/service_test.cpp @@ -37,6 +37,7 @@ namespace wificond { namespace { constexpr int kTimeoutSeconds = 3; +const char kInterfaceName[] = "wlan0"; } // namespace @@ -46,7 +47,8 @@ TEST(ServiceTest, ShouldTearDownSystemOnStartup) { sp service = dev_mode.EnterDevModeOrDie(); sp client_interface; - EXPECT_TRUE(service->createClientInterface(&client_interface).isOk()); + EXPECT_TRUE(service->createClientInterface( + kInterfaceName, &client_interface).isOk()); bool supplicant_started = false; EXPECT_TRUE(client_interface->enableSupplicant(&supplicant_started).isOk()); diff --git a/tests/server_unittest.cpp b/tests/server_unittest.cpp index 8639934..c52e8e3 100644 --- a/tests/server_unittest.cpp +++ b/tests/server_unittest.cpp @@ -125,19 +125,19 @@ TEST_F(ServerTest, CanSetUpApInterface) { sp ap_if; EXPECT_CALL(*netlink_utils_, SubscribeRegDomainChange(_, _)); - EXPECT_TRUE(server_.createApInterface(&ap_if).isOk()); + EXPECT_TRUE(server_.createApInterface(kFakeInterfaceName, &ap_if).isOk()); EXPECT_NE(nullptr, ap_if.get()); } TEST_F(ServerTest, DoesNotSupportMultipleInterfaces) { sp ap_if; - EXPECT_TRUE(server_.createApInterface(&ap_if).isOk()); + EXPECT_TRUE(server_.createApInterface(kFakeInterfaceName, &ap_if).isOk()); EXPECT_NE(nullptr, ap_if.get()); sp second_ap_if; // We won't throw on a second interface request. - EXPECT_TRUE(server_.createApInterface(&second_ap_if).isOk()); + EXPECT_TRUE(server_.createApInterface(kFakeInterfaceName, &second_ap_if).isOk()); // But this time we won't get an interface back. EXPECT_EQ(nullptr, second_ap_if.get()); } @@ -145,13 +145,13 @@ TEST_F(ServerTest, DoesNotSupportMultipleInterfaces) { TEST_F(ServerTest, CanDestroyInterfaces) { sp ap_if; - EXPECT_TRUE(server_.createApInterface(&ap_if).isOk()); + EXPECT_TRUE(server_.createApInterface(kFakeInterfaceName, &ap_if).isOk()); // When we tear down the interface, we expect the driver to be unloaded. EXPECT_CALL(*netlink_utils_, UnsubscribeRegDomainChange(_)); EXPECT_TRUE(server_.tearDownInterfaces().isOk()); // After a teardown, we should be able to create another interface. - EXPECT_TRUE(server_.createApInterface(&ap_if).isOk()); + EXPECT_TRUE(server_.createApInterface(kFakeInterfaceName, &ap_if).isOk()); } } // namespace wificond