namespace android {
namespace wificond {
-ClientInterfaceImpl::ClientInterfaceImpl(const std::string& interface_name,
- uint32_t interface_index,
- ScanUtils* scan_utils)
+ClientInterfaceImpl::ClientInterfaceImpl(
+ const std::string& interface_name,
+ uint32_t interface_index,
+ const std::vector<uint8_t>& interface_mac_addr,
+ ScanUtils* scan_utils)
: interface_name_(interface_name),
interface_index_(interface_index),
+ interface_mac_addr_(interface_mac_addr),
scan_utils_(scan_utils),
binder_(new ClientInterfaceBinder(this)) {
scan_utils_->SubscribeScanResultNotification(
public:
ClientInterfaceImpl(const std::string& interface_name,
uint32_t interface_index,
+ const std::vector<uint8_t>& interface_mac_addr,
ScanUtils* scan_utils);
~ClientInterfaceImpl();
const std::string interface_name_;
const uint32_t interface_index_;
+ const std::vector<uint8_t> interface_mac_addr_;
ScanUtils* const scan_utils_;
const android::sp<ClientInterfaceBinder> binder_;
return true;
}
-bool NetlinkUtils::GetInterfaceNameAndIndex(uint32_t wiphy_index,
- string* interface_name,
- uint32_t* interface_index) {
+bool NetlinkUtils::GetInterfaceInfo(uint32_t wiphy_index,
+ string* name,
+ uint32_t* index,
+ vector<uint8_t>* mac_addr) {
NL80211Packet get_interface(
netlink_manager_->GetFamilyId(),
NL80211_CMD_GET_INTERFACE,
LOG(DEBUG) << "Failed to get interface index";
continue;
}
- *interface_name = if_name;
- *interface_index = if_index;
+
+ vector<uint8_t> if_mac_addr;
+ if (!packet->GetAttributeValue(NL80211_ATTR_MAC, &if_mac_addr)) {
+ LOG(DEBUG) << "Failed to get interface mac address";
+ continue;
+ }
+
+ *name = if_name;
+ *index = if_index;
+ *mac_addr = if_mac_addr;
return true;
}
// Returns true on success.
virtual bool GetWiphyIndex(uint32_t* out_wiphy_index);
- // Get wifi interface name from kernel.
+ // Get wifi interface info from kernel.
// |wiphy_index| is the wiphy index we get using GetWiphyIndex().
// Returns true on success.
- virtual bool GetInterfaceNameAndIndex(uint32_t wiphy_index,
- std::string* interface_name,
- uint32_t* interface_index);
+ virtual bool GetInterfaceInfo(uint32_t wiphy_index,
+ std::string* name,
+ uint32_t* index,
+ std::vector<uint8_t>* mac_addr);
private:
NetlinkManager* netlink_manager_;
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,
- &interface_index)) {
+ &interface_index,
+ &interface_mac_addr)) {
return Status::ok(); // Logging was done internally
}
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,
- &interface_index)) {
+ &interface_index,
+ &interface_mac_addr)) {
return Status::ok(); // Logging was done internally
}
unique_ptr<ClientInterfaceImpl> client_interface(new ClientInterfaceImpl(
interface_name,
interface_index,
+ interface_mac_addr,
scan_utils_));
*created_interface = client_interface->GetBinder();
client_interfaces_.push_back(std::move(client_interface));
bool Server::SetupInterfaceForMode(int mode,
string* interface_name,
- uint32_t* interface_index) {
+ 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.
return false;
}
- if (!netlink_utils_->GetInterfaceNameAndIndex(wiphy_index_,
- interface_name,
- interface_index)) {
+ if (!netlink_utils_->GetInterfaceInfo(wiphy_index_,
+ interface_name,
+ interface_index,
+ interface_mac_addr)) {
return false;
}
// Returns true on success, false otherwise.
bool SetupInterfaceForMode(int mode,
std::string* interface_name,
- uint32_t* interface_index);
+ uint32_t* interface_index,
+ std::vector<uint8_t>* interface_mac_addr);
bool RefreshWiphyIndex();
const std::unique_ptr<wifi_system::HalTool> hal_tool_;
~MockNetlinkUtils() override = default;
MOCK_METHOD1(GetWiphyIndex, bool(uint32_t* out_wiphy_index));
- MOCK_METHOD3(GetInterfaceNameAndIndex, bool(uint32_t wiphy_index,
- std::string* interface_name,
- uint32_t* interface_index));
+ MOCK_METHOD4(GetInterfaceInfo,
+ bool(uint32_t wiphy_index,
+ std::string* name,
+ uint32_t* index,
+ std::vector<uint8_t>* mac_address));
}; // class MockNetlinkUtils
constexpr int kFakeErrorCode = EIO;
const char kFakeInterfaceName[] = "testif0";
const uint32_t kFakeInterfaceIndex = 34;
+const uint8_t kFakeInterfaceMacAddress[] = {0x45, 0x54, 0xad, 0x67, 0x98, 0xf6};
// Currently, control messages are only created by the kernel and sent to us.
// Therefore NL80211Packet doesn't have corresponding constructor.
EXPECT_FALSE(netlink_utils_->GetWiphyIndex(&wiphy_index));
}
-TEST_F(NetlinkUtilsTest, CanGetInterfaceNameAndIndex) {
+TEST_F(NetlinkUtilsTest, CanGetInterfaceInfo) {
NL80211Packet new_interface(
netlink_manager_->GetFamilyId(),
NL80211_CMD_NEW_INTERFACE,
// Insert interface index attribute.
NL80211Attr<uint32_t> if_index_attr(NL80211_ATTR_IFINDEX, kFakeInterfaceIndex);
new_interface.AddAttribute(if_index_attr);
+ // Insert mac address attribute.
+ std::vector<uint8_t> if_mac_addr;
+ if_mac_addr.assign(
+ kFakeInterfaceMacAddress,
+ kFakeInterfaceMacAddress + sizeof(kFakeInterfaceMacAddress));
+ NL80211Attr<vector<uint8_t>> if_mac_attr(NL80211_ATTR_MAC, if_mac_addr);
+ new_interface.AddAttribute(if_mac_attr);
// Mock a valid response from kernel.
vector<NL80211Packet> response = {new_interface};
string interface_name;
uint32_t interface_index;
- EXPECT_TRUE(netlink_utils_->GetInterfaceNameAndIndex(kFakeWiphyIndex,
- &interface_name,
- &interface_index));
+ vector<uint8_t> interface_mac_addr;
+ EXPECT_TRUE(netlink_utils_->GetInterfaceInfo(kFakeWiphyIndex,
+ &interface_name,
+ &interface_index,
+ &interface_mac_addr));
EXPECT_EQ(string(kFakeInterfaceName), interface_name);
EXPECT_EQ(kFakeInterfaceIndex, interface_index);
+ EXPECT_EQ(if_mac_addr, interface_mac_addr);
}
-TEST_F(NetlinkUtilsTest, HandlesPseudoDevicesInInterfaceNameAndIndexQuery) {
+TEST_F(NetlinkUtilsTest, HandlesPseudoDevicesInInterfaceInfoQuery) {
// Some kernels will have extra responses ahead of the expected packet.
NL80211Packet psuedo_interface(
netlink_manager_->GetFamilyId(),
NL80211_ATTR_IFNAME, string(kFakeInterfaceName)));
expected_interface.AddAttribute(NL80211Attr<uint32_t>(
NL80211_ATTR_IFINDEX, kFakeInterfaceIndex));
+ std::vector<uint8_t> if_mac_addr;
+ if_mac_addr.assign(
+ kFakeInterfaceMacAddress,
+ kFakeInterfaceMacAddress + sizeof(kFakeInterfaceMacAddress));
+ expected_interface.AddAttribute(
+ NL80211Attr<vector<uint8_t>>(NL80211_ATTR_MAC, if_mac_addr));
// Kernel can send us the pseduo interface packet first
vector<NL80211Packet> response = {psuedo_interface, expected_interface};
string interface_name;
uint32_t interface_index;
- EXPECT_TRUE(netlink_utils_->GetInterfaceNameAndIndex(kFakeWiphyIndex,
- &interface_name,
- &interface_index));
+ vector<uint8_t> interface_mac_addr;
+ EXPECT_TRUE(netlink_utils_->GetInterfaceInfo(
+ kFakeWiphyIndex, &interface_name, &interface_index, &interface_mac_addr));
EXPECT_EQ(string(kFakeInterfaceName), interface_name);
EXPECT_EQ(kFakeInterfaceIndex, interface_index);
+ EXPECT_EQ(if_mac_addr, interface_mac_addr);
}
-TEST_F(NetlinkUtilsTest, HandleP2p0WhenGetInterfaceNameAndIndex) {
+TEST_F(NetlinkUtilsTest, HandleP2p0WhenGetInterfaceInfo) {
NL80211Packet new_interface(
netlink_manager_->GetFamilyId(),
NL80211_CMD_NEW_INTERFACE,
// Insert interface index attribute.
NL80211Attr<uint32_t> if_index_attr(NL80211_ATTR_IFINDEX, kFakeInterfaceIndex);
new_interface.AddAttribute(if_index_attr);
+ // Insert mac address attribute.
+ std::vector<uint8_t> if_mac_addr;
+ if_mac_addr.assign(
+ kFakeInterfaceMacAddress,
+ kFakeInterfaceMacAddress + sizeof(kFakeInterfaceMacAddress));
+ NL80211Attr<vector<uint8_t>> if_mac_attr(NL80211_ATTR_MAC, if_mac_addr);
+ new_interface.AddAttribute(if_mac_attr);
// Create a new interface packet for p2p0.
NL80211Packet new_interface_p2p0(
string interface_name;
uint32_t interface_index;
- EXPECT_TRUE(netlink_utils_->GetInterfaceNameAndIndex(kFakeWiphyIndex,
- &interface_name,
- &interface_index));
+ vector<uint8_t> interface_mac_addr;
+ EXPECT_TRUE(netlink_utils_->GetInterfaceInfo(kFakeWiphyIndex,
+ &interface_name,
+ &interface_index,
+ &interface_mac_addr));
EXPECT_EQ(string(kFakeInterfaceName), interface_name);
EXPECT_EQ(kFakeInterfaceIndex, interface_index);
+ EXPECT_EQ(if_mac_addr, interface_mac_addr);
}
-TEST_F(NetlinkUtilsTest, CanHandleGetInterfaceNameAndIndexError) {
+TEST_F(NetlinkUtilsTest, CanHandleGetInterfaceInfoError) {
// Mock an error response from kernel.
vector<NL80211Packet> response = {CreateControlMessageError(kFakeErrorCode)};
string interface_name;
uint32_t interface_index;
- EXPECT_FALSE(netlink_utils_->GetInterfaceNameAndIndex(kFakeWiphyIndex,
- &interface_name,
- &interface_index));
+ vector<uint8_t> interface_mac_addr;
+ EXPECT_FALSE(netlink_utils_->GetInterfaceInfo(kFakeWiphyIndex,
+ &interface_name,
+ &interface_index,
+ &interface_mac_addr));
}
} // namespace wificond
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_, GetInterfaceNameAndIndex(_, _, _)).
- WillByDefault(Return(true));
+ ON_CALL(*netlink_utils_, GetInterfaceInfo(_, _, _, _))
+ .WillByDefault(Return(true));
}
NiceMock<MockHalTool>* hal_tool_ = new NiceMock<MockHalTool>;
EXPECT_CALL(*netlink_utils_, GetWiphyIndex(_))
.InSequence(sequence)
.WillOnce(Return(true));
- EXPECT_CALL(*netlink_utils_, GetInterfaceNameAndIndex(_, _, _))
+ EXPECT_CALL(*netlink_utils_, GetInterfaceInfo(_, _, _, _))
.InSequence(sequence)
.WillOnce(Return(true));
TEST_F(ServerTest, DoesNotSupportMultipleInterfaces) {
sp<IApInterface> ap_if;
EXPECT_CALL(*netlink_utils_, GetWiphyIndex(_)).Times(1);
- EXPECT_CALL(*netlink_utils_, GetInterfaceNameAndIndex(_, _, _)).Times(1);
+ EXPECT_CALL(*netlink_utils_, GetInterfaceInfo(_, _, _, _)).Times(1);
EXPECT_TRUE(server_.createApInterface(&ap_if).isOk());
EXPECT_NE(nullptr, ap_if.get());
TEST_F(ServerTest, CanDestroyInterfaces) {
sp<IApInterface> ap_if;
EXPECT_CALL(*netlink_utils_, GetWiphyIndex(_)).Times(2);
- EXPECT_CALL(*netlink_utils_, GetInterfaceNameAndIndex(_, _, _)).Times(2);
+ EXPECT_CALL(*netlink_utils_, GetInterfaceInfo(_, _, _, _)).Times(2);
EXPECT_CALL(*driver_tool_, UnloadDriver()).Times(0);
EXPECT_TRUE(server_.createApInterface(&ap_if).isOk());