OSDN Git Service

wificond: Dump interface list
authorNingyuan Wang <nywang@google.com>
Wed, 5 Apr 2017 00:36:34 +0000 (17:36 -0700)
committerNingyuan Wang <nywang@google.com>
Wed, 5 Apr 2017 18:17:26 +0000 (11:17 -0700)
Bug: 31336376
Test: compile
Test: manual test, check bug report
For example, I can see the following dump state:
Cached interfaces list from kernel message:
Interface index: 23, name: p2p0, mac address: 66:bc:0c:47:df:00
Interface index: 22, name: wlan0, mac address: 64:bc:0c:47:df:00

Change-Id: Iae02bc85a73f211aa39fb16d77eb17d399651dce

server.cpp
server.h

index 434b44a..808f3bc 100644 (file)
@@ -23,6 +23,7 @@
 #include <binder/IPCThreadState.h>
 #include <binder/PermissionCache.h>
 
+#include "wificond/logging_utils.h"
 #include "wificond/net/netlink_utils.h"
 #include "wificond/scanning/scan_utils.h"
 
@@ -198,6 +199,13 @@ status_t Server::dump(int fd, const Vector<String16>& /*args*/) {
 
   stringstream ss;
   ss << "Current wiphy index: " << wiphy_index_ << endl;
+  ss << "Cached interfaces list from kernel message: " << endl;
+  for (const auto& iface : interfaces_) {
+    ss << "Interface index: " << iface.index
+       << ", name: " << iface.name
+       << ", mac address: "
+       << LoggingUtils::GetMacString(iface.mac_address) << endl;
+  }
 
   if (!WriteStringToFd(ss.str(), fd)) {
     PLOG(ERROR) << "Failed to dump state to fd " << fd;
@@ -242,13 +250,13 @@ bool Server::SetupInterface(InterfaceInfo* interface) {
           this,
           _1));
 
-  vector<InterfaceInfo> interfaces;
-  if (!netlink_utils_->GetInterfaces(wiphy_index_, &interfaces)) {
+  interfaces_.clear();
+  if (!netlink_utils_->GetInterfaces(wiphy_index_, &interfaces_)) {
     LOG(ERROR) << "Failed to get interfaces info from kernel";
     return false;
   }
 
-  for (InterfaceInfo& iface : interfaces) {
+  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.
index f4f71d9..8fc3d77 100644 (file)
--- a/server.h
+++ b/server.h
@@ -122,6 +122,9 @@ class Server : public android::net::wifi::BnWificond {
 
   std::unique_ptr<RttControllerImpl> rtt_controller_;
 
+  // Cached interface list from kernel.
+  std::vector<InterfaceInfo> interfaces_;
+
   DISALLOW_COPY_AND_ASSIGN(Server);
 };