#include <sstream>
+#include <android-base/file.h>
#include <android-base/logging.h>
+#include <android-base/strings.h>
+#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"
+using android::base::WriteStringToFd;
using android::binder::Status;
using android::sp;
using android::IBinder;
using android::net::wifi::IApInterface;
using android::net::wifi::IClientInterface;
using android::net::wifi::IInterfaceEventCallback;
-using android::net::wifi::IRttClient;
-using android::net::wifi::IRttController;
using android::wifi_system::HostapdManager;
using android::wifi_system::InterfaceTool;
using android::wifi_system::SupplicantManager;
+using std::endl;
using std::placeholders::_1;
using std::string;
using std::stringstream;
namespace android {
namespace wificond {
+namespace {
+
+constexpr const char* kPermissionDump = "android.permission.DUMP";
+
+} // namespace
+
Server::Server(unique_ptr<InterfaceTool> if_tool,
unique_ptr<SupplicantManager> supplicant_manager,
unique_ptr<HostapdManager> hostapd_manager,
return Status::ok();
}
-Status Server::registerRttClient(const sp<IRttClient>& rtt_client,
- sp<IRttController>* out_rtt_controller) {
- if (rtt_controller_ == nullptr) {
- rtt_controller_.reset(new RttControllerImpl());
- }
- rtt_controller_->RegisterRttClient(rtt_client);
-
- *out_rtt_controller = rtt_controller_->GetBinder();
- return Status::ok();
-}
-
-Status Server::unregisterRttClient(const sp<IRttClient>& rttClient) {
- rtt_controller_->UnregisterRttClient(rttClient);
- if (rtt_controller_->GetClientCount() == 0) {
- rtt_controller_.reset();
- }
- return Status::ok();
-}
-
Status Server::createApInterface(sp<IApInterface>* created_interface) {
InterfaceInfo interface;
if (!SetupInterface(&interface)) {
return binder::Status::ok();
}
+status_t Server::dump(int fd, const Vector<String16>& /*args*/) {
+ if (!PermissionCache::checkCallingPermission(String16(kPermissionDump))) {
+ IPCThreadState* ipc = android::IPCThreadState::self();
+ LOG(ERROR) << "Caller (uid: " << ipc->getCallingUid()
+ << ") is not permitted to dump wificond state";
+ return PERMISSION_DENIED;
+ }
+
+ 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;
+ }
+
+ for (const auto& iface : client_interfaces_) {
+ iface->Dump(&ss);
+ }
+
+ for (const auto& iface : ap_interfaces_) {
+ iface->Dump(&ss);
+ }
+
+ if (!WriteStringToFd(ss.str(), fd)) {
+ PLOG(ERROR) << "Failed to dump state to fd " << fd;
+ return FAILED_TRANSACTION;
+ }
+
+ return OK;
+}
+
void Server::MarkDownAllInterfaces() {
uint32_t wiphy_index;
vector<InterfaceInfo> interfaces;
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.
- if (iface.name != "p2p0") {
+ // 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")) {
*interface = iface;
return true;
}