Commit a47e8d6f authored by Abhishek Bhardwaj's avatar Abhishek Bhardwaj Committed by Commit Bot

Network: Add plumbing for wake on packet type D-Bus API

This change adds AddWakeOnWifiPacketTypes and
RemoveWakeOnWifiPacketTypes to the shill D-Bus API. These APIs program
what type of packets the NIC should wake the system on.

BUG=891143
TEST=chromeos_unittests.

Change-Id: I21d779ed450ae8f682d2dd5d9f90aef0ee0a2360
Reviewed-on: https://chromium-review.googlesource.com/c/1269114Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarDan Erat <derat@chromium.org>
Commit-Queue: Abhishek Bhardwaj <abhishekbh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599799}
parent c15e89cc
......@@ -343,6 +343,20 @@ void FakeShillDeviceClient::AddWakeOnPacketConnection(
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
}
void FakeShillDeviceClient::AddWakeOnPacketOfTypes(
const dbus::ObjectPath& device_path,
const std::vector<std::string>& types,
const base::Closure& callback,
const ErrorCallback& error_callback) {
if (!stub_devices_.HasKey(device_path.value())) {
PostNotFoundError(error_callback);
return;
}
wake_on_packet_types_[device_path].insert(types.begin(), types.end());
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
}
void FakeShillDeviceClient::RemoveWakeOnPacketConnection(
const dbus::ObjectPath& device_path,
const net::IPEndPoint& ip_endpoint,
......@@ -366,6 +380,29 @@ void FakeShillDeviceClient::RemoveWakeOnPacketConnection(
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
}
void FakeShillDeviceClient::RemoveWakeOnPacketOfTypes(
const dbus::ObjectPath& device_path,
const std::vector<std::string>& types,
const base::Closure& callback,
const ErrorCallback& error_callback) {
if (!stub_devices_.HasKey(device_path.value())) {
PostNotFoundError(error_callback);
return;
}
const auto registered_types_iter = wake_on_packet_types_.find(device_path);
if (registered_types_iter == wake_on_packet_types_.end()) {
PostNotFoundError(error_callback);
return;
}
std::set<std::string>& registered_types = registered_types_iter->second;
for (auto it = types.begin(); it != types.end(); it++)
registered_types.erase(*it);
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
}
void FakeShillDeviceClient::RemoveAllWakeOnPacketConnections(
const dbus::ObjectPath& device_path,
const base::Closure& callback,
......
......@@ -9,6 +9,7 @@
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "base/macros.h"
#include "chromeos/chromeos_export.h"
......@@ -82,11 +83,19 @@ class CHROMEOS_EXPORT FakeShillDeviceClient
const net::IPEndPoint& ip_endpoint,
const base::Closure& callback,
const ErrorCallback& error_callback) override;
void AddWakeOnPacketOfTypes(const dbus::ObjectPath& device_path,
const std::vector<std::string>& types,
const base::Closure& callback,
const ErrorCallback& error_callback) override;
void RemoveWakeOnPacketConnection(
const dbus::ObjectPath& device_path,
const net::IPEndPoint& ip_endpoint,
const base::Closure& callback,
const ErrorCallback& error_callback) override;
void RemoveWakeOnPacketOfTypes(const dbus::ObjectPath& device_path,
const std::vector<std::string>& types,
const base::Closure& callback,
const ErrorCallback& error_callback) override;
void RemoveAllWakeOnPacketConnections(
const dbus::ObjectPath& device_path,
const base::Closure& callback,
......@@ -167,6 +176,11 @@ class CHROMEOS_EXPORT FakeShillDeviceClient
std::map<dbus::ObjectPath, std::set<net::IPEndPoint>>
wake_on_packet_connections_;
// Wake on packet types for each device. The string types in the value set
// correspond to "Wake on WiFi Packet Type Constants." in
// third_party/cros_system_api/dbus/shill/dbus-constants.h.
std::map<dbus::ObjectPath, std::set<std::string>> wake_on_packet_types_;
// Current SIM PIN per device path.
std::map<std::string, std::string> sim_pin_;
......
......@@ -214,6 +214,19 @@ class ShillDeviceClientImpl : public ShillDeviceClient {
error_callback);
}
void AddWakeOnPacketOfTypes(const dbus::ObjectPath& device_path,
const std::vector<std::string>& types,
const base::Closure& callback,
const ErrorCallback& error_callback) override {
dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
shill::kAddWakeOnPacketOfTypesFunction);
dbus::MessageWriter writer(&method_call);
writer.AppendArrayOfStrings(types);
GetHelper(device_path)
->CallVoidMethodWithErrorCallback(&method_call, callback,
error_callback);
}
void RemoveWakeOnPacketConnection(
const dbus::ObjectPath& device_path,
const net::IPEndPoint& ip_endpoint,
......@@ -232,6 +245,19 @@ class ShillDeviceClientImpl : public ShillDeviceClient {
error_callback);
}
void RemoveWakeOnPacketOfTypes(const dbus::ObjectPath& device_path,
const std::vector<std::string>& types,
const base::Closure& callback,
const ErrorCallback& error_callback) override {
dbus::MethodCall method_call(shill::kFlimflamDeviceInterface,
shill::kRemoveWakeOnPacketOfTypesFunction);
dbus::MessageWriter writer(&method_call);
writer.AppendArrayOfStrings(types);
GetHelper(device_path)
->CallVoidMethodWithErrorCallback(&method_call, callback,
error_callback);
}
void RemoveAllWakeOnPacketConnections(
const dbus::ObjectPath& device_path,
const base::Closure& callback,
......
......@@ -6,6 +6,7 @@
#define CHROMEOS_DBUS_SHILL_DEVICE_CLIENT_H_
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/macros.h"
......@@ -174,6 +175,15 @@ class CHROMEOS_EXPORT ShillDeviceClient : public DBusClient {
const base::Closure& callback,
const ErrorCallback& error_callback) = 0;
// Adds |types| to the list of packet types that the device should monitor to
// wake the system from suspend. |types| corresponds to "Wake on WiFi Packet
// Type Constants." in
// third_party/cros_system_api/dbus/shill/dbus-constants.h.
virtual void AddWakeOnPacketOfTypes(const dbus::ObjectPath& device_path,
const std::vector<std::string>& types,
const base::Closure& callback,
const ErrorCallback& error_callback) = 0;
// Removes |ip_endpoint| from the list of tcp connections that the device
// should monitor to wake the system from suspend.
virtual void RemoveWakeOnPacketConnection(
......@@ -182,6 +192,16 @@ class CHROMEOS_EXPORT ShillDeviceClient : public DBusClient {
const base::Closure& callback,
const ErrorCallback& error_callback) = 0;
// Removes |types| from the list of packet types that the device should
// monitor to wake the system from suspend. |types| corresponds to "Wake on
// WiFi Packet Type Constants." in
// third_party/cros_system_api/dbus/shill/dbus-constants.h.
virtual void RemoveWakeOnPacketOfTypes(
const dbus::ObjectPath& device_path,
const std::vector<std::string>& types,
const base::Closure& callback,
const ErrorCallback& error_callback) = 0;
// Clears the list of tcp connections that the device should monitor to wake
// the system from suspend.
virtual void RemoveAllWakeOnPacketConnections(
......
......@@ -84,11 +84,21 @@ void FakeNetworkDeviceHandler::AddWifiWakeOnPacketConnection(
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) {}
void FakeNetworkDeviceHandler::AddWifiWakeOnPacketOfTypes(
const std::vector<std::string>& types,
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) {}
void FakeNetworkDeviceHandler::RemoveWifiWakeOnPacketConnection(
const net::IPEndPoint& ip_endpoint,
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) {}
void FakeNetworkDeviceHandler::RemoveWifiWakeOnPacketOfTypes(
const std::vector<std::string>& types,
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) {}
void FakeNetworkDeviceHandler::RemoveAllWifiWakeOnPacketConnections(
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) {}
......
......@@ -5,6 +5,9 @@
#ifndef CHROMEOS_NETWORK_FAKE_NETWORK_DEVICE_HANDLER_H_
#define CHROMEOS_NETWORK_FAKE_NETWORK_DEVICE_HANDLER_H_
#include <string>
#include <vector>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "chromeos/chromeos_export.h"
......@@ -92,11 +95,21 @@ class CHROMEOS_EXPORT FakeNetworkDeviceHandler : public NetworkDeviceHandler {
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) override;
void AddWifiWakeOnPacketOfTypes(
const std::vector<std::string>& types,
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) override;
void RemoveWifiWakeOnPacketConnection(
const net::IPEndPoint& ip_endpoint,
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) override;
void RemoveWifiWakeOnPacketOfTypes(
const std::vector<std::string>& types,
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) override;
void RemoveAllWifiWakeOnPacketConnections(
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) override;
......
......@@ -6,6 +6,7 @@
#define CHROMEOS_NETWORK_MOCK_NETWORK_DEVICE_HANDLER_H_
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/macros.h"
......@@ -100,6 +101,16 @@ class CHROMEOS_EXPORT MockNetworkDeviceHandler : public NetworkDeviceHandler {
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback));
MOCK_METHOD3(AddWifiWakeOnPacketOfTypes,
void(const std::vector<std::string>& types,
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback));
MOCK_METHOD3(RemoveWifiWakeOnPacketOfTypes,
void(const std::vector<std::string>& types,
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback));
MOCK_METHOD3(RemoveWifiWakeOnPacketConnection,
void(const net::IPEndPoint& ip_endpoint,
const base::Closure& callback,
......
......@@ -6,6 +6,7 @@
#define CHROMEOS_NETWORK_NETWORK_DEVICE_HANDLER_H_
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/macros.h"
......@@ -210,6 +211,13 @@ class CHROMEOS_EXPORT NetworkDeviceHandler {
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) = 0;
// Adds |types| to the list of packet types that the device should monitor to
// wake the system from suspend.
virtual void AddWifiWakeOnPacketOfTypes(
const std::vector<std::string>& types,
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) = 0;
// Removes |ip_endpoint| from the list of tcp connections that the wifi device
// should monitor to wake the system from suspend.
virtual void RemoveWifiWakeOnPacketConnection(
......@@ -217,6 +225,13 @@ class CHROMEOS_EXPORT NetworkDeviceHandler {
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) = 0;
// Removes |types| from the list of packet types that the device should
// monitor to wake the system from suspend.
virtual void RemoveWifiWakeOnPacketOfTypes(
const std::vector<std::string>& types,
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) = 0;
// Clears the list of tcp connections that the wifi device should monitor to
// wake the system from suspend.
virtual void RemoveAllWifiWakeOnPacketConnections(
......
......@@ -6,12 +6,15 @@
#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <utility>
#include <vector>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/sys_info.h"
#include "base/threading/thread_task_runner_handle.h"
......@@ -31,8 +34,10 @@ namespace chromeos {
namespace {
std::string GetErrorNameForShillError(const std::string& shill_error_name) {
if (shill_error_name == shill::kErrorResultFailure)
if (shill_error_name == shill::kErrorResultFailure ||
shill_error_name == shill::kErrorResultInvalidArguments) {
return NetworkDeviceHandler::kErrorFailure;
}
if (shill_error_name == shill::kErrorResultNotSupported)
return NetworkDeviceHandler::kErrorNotSupported;
if (shill_error_name == shill::kErrorResultIncorrectPin)
......@@ -431,6 +436,22 @@ void NetworkDeviceHandlerImpl::AddWifiWakeOnPacketConnection(
error_callback));
}
void NetworkDeviceHandlerImpl::AddWifiWakeOnPacketOfTypes(
const std::vector<std::string>& types,
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) {
const DeviceState* device_state = GetWifiDeviceState(error_callback);
if (!device_state)
return;
NET_LOG(USER) << "Device.AddWifiWakeOnPacketOfTypes: " << device_state->path()
<< " Types: " << base::JoinString(types, " ");
DBusThreadManager::Get()->GetShillDeviceClient()->AddWakeOnPacketOfTypes(
dbus::ObjectPath(device_state->path()), types, callback,
base::Bind(&HandleShillCallFailure, device_state->path(),
error_callback));
}
void NetworkDeviceHandlerImpl::RemoveWifiWakeOnPacketConnection(
const net::IPEndPoint& ip_endpoint,
const base::Closure& callback,
......@@ -448,6 +469,23 @@ void NetworkDeviceHandlerImpl::RemoveWifiWakeOnPacketConnection(
error_callback));
}
void NetworkDeviceHandlerImpl::RemoveWifiWakeOnPacketOfTypes(
const std::vector<std::string>& types,
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) {
const DeviceState* device_state = GetWifiDeviceState(error_callback);
if (!device_state)
return;
NET_LOG(USER) << "Device.RemoveWifiWakeOnPacketOfTypes: "
<< device_state->path()
<< " Types: " << base::JoinString(types, " ");
DBusThreadManager::Get()->GetShillDeviceClient()->RemoveWakeOnPacketOfTypes(
dbus::ObjectPath(device_state->path()), types, callback,
base::Bind(&HandleShillCallFailure, device_state->path(),
error_callback));
}
void NetworkDeviceHandlerImpl::RemoveAllWifiWakeOnPacketConnections(
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) {
......
......@@ -7,6 +7,7 @@
#include <map>
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/compiler_specific.h"
......@@ -103,11 +104,21 @@ class CHROMEOS_EXPORT NetworkDeviceHandlerImpl
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) override;
void AddWifiWakeOnPacketOfTypes(
const std::vector<std::string>& types,
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) override;
void RemoveWifiWakeOnPacketConnection(
const net::IPEndPoint& ip_endpoint,
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) override;
void RemoveWifiWakeOnPacketOfTypes(
const std::vector<std::string>& types,
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) override;
void RemoveAllWifiWakeOnPacketConnections(
const base::Closure& callback,
const network_handler::ErrorCallback& error_callback) override;
......
......@@ -16,6 +16,7 @@
#include "chromeos/network/network_state_handler.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
#include "third_party/cros_system_api/dbus/shill/dbus-constants.h"
namespace chromeos {
......@@ -390,4 +391,30 @@ TEST_F(NetworkDeviceHandlerTest, ChangePin) {
EXPECT_EQ(NetworkDeviceHandler::kErrorIncorrectPin, result_);
}
TEST_F(NetworkDeviceHandlerTest, AddWifiWakeOnPacketOfTypes) {
std::vector<std::string> valid_packet_types = {shill::kWakeOnTCP,
shill::kWakeOnUDP};
network_device_handler_->AddWifiWakeOnPacketOfTypes(
valid_packet_types, success_callback_, error_callback_);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(kResultSuccess, result_);
}
TEST_F(NetworkDeviceHandlerTest, AddAndRemoveWifiWakeOnPacketOfTypes) {
std::vector<std::string> valid_packet_types = {shill::kWakeOnTCP,
shill::kWakeOnUDP};
std::vector<std::string> remove_packet_types = {shill::kWakeOnTCP};
network_device_handler_->AddWifiWakeOnPacketOfTypes(
valid_packet_types, success_callback_, error_callback_);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(kResultSuccess, result_);
network_device_handler_->RemoveWifiWakeOnPacketOfTypes(
remove_packet_types, success_callback_, error_callback_);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(kResultSuccess, result_);
}
} // namespace chromeos
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment