1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/ash/components/network/network_connection_handler.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
#include "chromeos/ash/components/dbus/shill/shill_manager_client.h"
#include "chromeos/ash/components/dbus/shill/shill_service_client.h"
#include "chromeos/ash/components/network/client_cert_resolver.h"
#include "chromeos/ash/components/network/client_cert_util.h"
#include "chromeos/ash/components/network/managed_network_configuration_handler.h"
#include "chromeos/ash/components/network/network_configuration_handler.h"
#include "chromeos/ash/components/network/network_connection_handler_impl.h"
#include "chromeos/ash/components/network/network_event_log.h"
#include "chromeos/ash/components/network/network_profile_handler.h"
#include "chromeos/ash/components/network/network_state.h"
#include "chromeos/ash/components/network/network_state_handler.h"
#include "chromeos/ash/components/network/shill_property_util.h"
#include "dbus/object_path.h"
#include "net/cert/x509_certificate.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
namespace ash {
// Static constants.
const char NetworkConnectionHandler::kErrorNotFound[] = "not-found";
const char NetworkConnectionHandler::kErrorConnected[] = "connected";
const char NetworkConnectionHandler::kErrorConnecting[] = "connecting";
const char NetworkConnectionHandler::kErrorNotConnected[] = "not-connected";
const char NetworkConnectionHandler::kErrorPassphraseRequired[] =
"passphrase-required";
const char NetworkConnectionHandler::kErrorBadPassphrase[] = "bad-passphrase";
const char NetworkConnectionHandler::kErrorCertificateRequired[] =
"certificate-required";
const char NetworkConnectionHandler::kErrorConfigurationRequired[] =
"configuration-required";
const char NetworkConnectionHandler::kErrorAuthenticationRequired[] =
"authentication-required";
const char NetworkConnectionHandler::kErrorConnectFailed[] = "connect-failed";
const char NetworkConnectionHandler::kErrorDisconnectFailed[] =
"disconnect-failed";
const char NetworkConnectionHandler::kErrorConfigureFailed[] =
"configure-failed";
const char NetworkConnectionHandler::kErrorConnectCanceled[] =
"connect-canceled";
const char NetworkConnectionHandler::kErrorCertLoadTimeout[] =
"cert-load-timeout";
const char NetworkConnectionHandler::kErrorBlockedByPolicy[] =
"blocked-by-policy";
const char NetworkConnectionHandler::kErrorHexSsidRequired[] =
"hex-ssid-required";
const char NetworkConnectionHandler::kErrorActivateFailed[] = "activate-failed";
const char NetworkConnectionHandler::kErrorEnabledOrDisabledWhenNotAvailable[] =
"not-available";
const char NetworkConnectionHandler::kErrorTetherAttemptWithNoDelegate[] =
"tether-with-no-delegate";
const char NetworkConnectionHandler::kErrorCellularInhibitFailure[] =
"cellular-inhibit-failure";
const char NetworkConnectionHandler::kErrorCellularOutOfCredits[] =
"cellular-out-of-credits";
const char NetworkConnectionHandler::kErrorESimProfileIssue[] =
"esim-profile-issue";
const char NetworkConnectionHandler::kErrorSimPinPukLocked[] = "sim-locked";
const char NetworkConnectionHandler::kErrorSimCarrierLocked[] =
"sim-carrier-locked";
const char NetworkConnectionHandler::kErrorCellularDeviceBusy[] =
"cellular-device-busy";
const char NetworkConnectionHandler::kErrorConnectTimeout[] = "connect-timeout";
const char NetworkConnectionHandler::kConnectableCellularTimeout[] =
"connectable-timeout";
NetworkConnectionHandler::NetworkConnectionHandler()
: tether_delegate_(nullptr) {}
NetworkConnectionHandler::~NetworkConnectionHandler() = default;
void NetworkConnectionHandler::AddObserver(
NetworkConnectionObserver* observer) {
observers_.AddObserver(observer);
}
void NetworkConnectionHandler::RemoveObserver(
NetworkConnectionObserver* observer) {
observers_.RemoveObserver(observer);
}
void NetworkConnectionHandler::SetTetherDelegate(
TetherDelegate* tether_delegate) {
tether_delegate_ = tether_delegate;
}
void NetworkConnectionHandler::InvokeConnectSuccessCallback(
const std::string& service_path,
base::OnceClosure success_callback) {
NET_LOG(EVENT) << "Connect Request Succeeded" << NetworkPathId(service_path);
if (!success_callback.is_null())
std::move(success_callback).Run();
for (auto& observer : observers_)
observer.ConnectSucceeded(service_path);
}
void NetworkConnectionHandler::InvokeConnectErrorCallback(
const std::string& service_path,
network_handler::ErrorCallback error_callback,
const std::string& error_name) {
NET_LOG(ERROR) << "Connect Failure: " << error_name << " for "
<< NetworkPathId(service_path);
network_handler::RunErrorCallback(std::move(error_callback), error_name);
for (auto& observer : observers_)
observer.ConnectFailed(service_path, error_name);
}
void NetworkConnectionHandler::InitiateTetherNetworkConnection(
const std::string& tether_network_guid,
base::OnceClosure success_callback,
network_handler::ErrorCallback error_callback) {
DCHECK(tether_delegate_);
tether_delegate_->ConnectToNetwork(
tether_network_guid,
base::BindOnce(&NetworkConnectionHandler::InvokeConnectSuccessCallback,
weak_ptr_factory_.GetWeakPtr(), tether_network_guid,
std::move(success_callback)),
base::BindOnce(&NetworkConnectionHandler::InvokeConnectErrorCallback,
weak_ptr_factory_.GetWeakPtr(), tether_network_guid,
std::move(error_callback)));
}
void NetworkConnectionHandler::InitiateTetherNetworkDisconnection(
const std::string& tether_network_guid,
base::OnceClosure success_callback,
network_handler::ErrorCallback error_callback) {
DCHECK(tether_delegate_);
tether_delegate_->DisconnectFromNetwork(
tether_network_guid,
base::BindOnce(&NetworkConnectionHandler::InvokeConnectSuccessCallback,
weak_ptr_factory_.GetWeakPtr(), tether_network_guid,
std::move(success_callback)),
base::BindOnce(&NetworkConnectionHandler::InvokeConnectErrorCallback,
weak_ptr_factory_.GetWeakPtr(), tether_network_guid,
std::move(error_callback)));
}
// static
std::unique_ptr<NetworkConnectionHandler>
NetworkConnectionHandler::InitializeForTesting(
NetworkStateHandler* network_state_handler,
NetworkConfigurationHandler* network_configuration_handler,
ManagedNetworkConfigurationHandler* managed_network_configuration_handler,
CellularConnectionHandler* cellular_connection_handler) {
NetworkConnectionHandlerImpl* handler = new NetworkConnectionHandlerImpl();
handler->Init(network_state_handler, network_configuration_handler,
managed_network_configuration_handler,
cellular_connection_handler);
return base::WrapUnique(handler);
}
} // namespace ash
|