wificond: Create interface objects using name

Use the passed in iface name to create the corresponding interface
object.

Bug: 67365651
Test: ./system/connectivity/wificond/runtests.sh
Test: Will send for regression tests.
Change-Id: I9e8d748d47388a45567234b93f8aff854d784aea
This commit is contained in:
Roshan Pius 2017-10-03 10:53:48 -07:00
parent d3f1bf2e90
commit 47443838f7
8 changed files with 40 additions and 30 deletions

View File

@ -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.

View File

@ -94,9 +94,10 @@ Status Server::UnregisterCallback(const sp<IInterfaceEventCallback>& callback) {
return Status::ok();
}
Status Server::createApInterface(sp<IApInterface>* created_interface) {
Status Server::createApInterface(const std::string& iface_name,
sp<IApInterface>* 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<IApInterface>* created_interface) {
return Status::ok();
}
Status Server::createClientInterface(sp<IClientInterface>* created_interface) {
Status Server::createClientInterface(const std::string& iface_name,
sp<IClientInterface>* 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;
}

View File

@ -58,10 +58,12 @@ class Server : public android::net::wifi::BnWificond {
callback) override;
android::binder::Status createApInterface(
const std::string& iface_name,
android::sp<android::net::wifi::IApInterface>*
created_interface) override;
android::binder::Status createClientInterface(
const std::string& iface_name,
android::sp<android::net::wifi::IClientInterface>*
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);

View File

@ -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<IApInterface> 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<IApInterface> 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<IWificond> service = dev_mode.EnterDevModeOrDie();
sp<IApInterface> 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<IWificond> service = dev_mode.EnterDevModeOrDie();
sp<IApInterface> 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;

View File

@ -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<IClientInterface> 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<IClientInterface> 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<IWificond> service = dev_mode.EnterDevModeOrDie();
sp<IClientInterface> 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<IWificond> service = dev_mode.EnterDevModeOrDie();
sp<IClientInterface> client_interface;
EXPECT_TRUE(service->createClientInterface(&client_interface).isOk());
EXPECT_TRUE(service->createClientInterface(
kInterfaceName, &client_interface).isOk());
ASSERT_NE(nullptr, client_interface.get());
vector<uint8_t> mac_address;
EXPECT_TRUE(client_interface->getMacAddress(&mac_address).isOk());

View File

@ -34,11 +34,13 @@ using std::vector;
namespace android {
namespace wificond {
namespace {
const char kInterfaceName[] = "wlan0";
sp<IWifiScannerImpl> InitInterfaceAndReturnScanner(sp<IWificond> service) {
sp<IWifiScannerImpl> scanner;
sp<IClientInterface> client_interface;
if (!service->createClientInterface(&client_interface).isOk()) {
if (!service->createClientInterface(
kInterfaceName, &client_interface).isOk()) {
LOG(FATAL) << "Failed to create client interface";
return nullptr;
}

View File

@ -37,6 +37,7 @@ namespace wificond {
namespace {
constexpr int kTimeoutSeconds = 3;
const char kInterfaceName[] = "wlan0";
} // namespace
@ -46,7 +47,8 @@ TEST(ServiceTest, ShouldTearDownSystemOnStartup) {
sp<IWificond> service = dev_mode.EnterDevModeOrDie();
sp<IClientInterface> 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());

View File

@ -125,19 +125,19 @@ TEST_F(ServerTest, CanSetUpApInterface) {
sp<IApInterface> 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<IApInterface> ap_if;
EXPECT_TRUE(server_.createApInterface(&ap_if).isOk());
EXPECT_TRUE(server_.createApInterface(kFakeInterfaceName, &ap_if).isOk());
EXPECT_NE(nullptr, ap_if.get());
sp<IApInterface> 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<IApInterface> 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