1 /*
2 * Copyright (C) 2016, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <string>
18 #include <vector>
19
20 #include <gtest/gtest.h>
21 #include <utils/StrongPointer.h>
22 #include <wifi_system/interface_tool.h>
23
24 #include "android/net/wifi/nl80211/IClientInterface.h"
25 #include "android/net/wifi/nl80211/IWificond.h"
26 #include "wificond/tests/integration/process_utils.h"
27
28 using android::net::wifi::nl80211::IClientInterface;
29 using android::net::wifi::nl80211::IWificond;
30 using android::wifi_system::InterfaceTool;
31 using android::wificond::tests::integration::ScopedDevModeWificond;
32 using std::string;
33 using std::vector;
34
35 namespace android {
36 namespace wificond {
37 namespace {
38
39 const char kInterfaceName[] = "wlan0";
40 } // namespace
41
TEST(ClientInterfaceTest,CanCreateClientInterfaces)42 TEST(ClientInterfaceTest, CanCreateClientInterfaces) {
43 ScopedDevModeWificond dev_mode;
44 sp<IWificond> service = dev_mode.EnterDevModeOrDie();
45
46 // We should be able to create an client interface.
47 sp<IClientInterface> client_interface;
48 EXPECT_TRUE(service->createClientInterface(
49 kInterfaceName, &client_interface).isOk());
50 EXPECT_NE(nullptr, client_interface.get());
51
52 // The interface should start out down.
53 string if_name;
54 EXPECT_TRUE(client_interface->getInterfaceName(&if_name).isOk());
55 EXPECT_TRUE(!if_name.empty());
56 InterfaceTool if_tool;
57 EXPECT_FALSE(if_tool.GetUpState(if_name.c_str()));
58
59 // Mark the interface as up, just to test that we mark it down on tearDown.
60 EXPECT_TRUE(if_tool.SetUpState(if_name.c_str(), true));
61 EXPECT_TRUE(if_tool.GetUpState(if_name.c_str()));
62
63 // We should not be able to create two client interfaces.
64 sp<IClientInterface> client_interface2;
65 EXPECT_TRUE(service->createClientInterface(
66 kInterfaceName, &client_interface2).isOk());
67 EXPECT_EQ(nullptr, client_interface2.get());
68
69 // We can tear down the created interface.
70 bool succes = false;
71 EXPECT_TRUE(service->tearDownClientInterface(kInterfaceName, &succes).isOk());
72 EXPECT_TRUE(succes);
73 EXPECT_FALSE(if_tool.GetUpState(if_name.c_str()));
74
75 // Teardown everything at the end of the test.
76 EXPECT_TRUE(service->tearDownInterfaces().isOk());
77 }
78
TEST(ClientInterfaceTest,CanGetMacAddress)79 TEST(ClientInterfaceTest, CanGetMacAddress) {
80 ScopedDevModeWificond dev_mode;
81 sp<IWificond> service = dev_mode.EnterDevModeOrDie();
82 sp<IClientInterface> client_interface;
83 EXPECT_TRUE(service->createClientInterface(
84 kInterfaceName, &client_interface).isOk());
85 ASSERT_NE(nullptr, client_interface.get());
86 vector<uint8_t> mac_address;
87 EXPECT_TRUE(client_interface->getMacAddress(&mac_address).isOk());
88 EXPECT_TRUE(mac_address.size() == 6);
89 }
90
91 } // namespace wificond
92 } // namespace android
93