15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chromeos/network/network_device_handler_impl.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/bind.h" 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/location.h" 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/message_loop/message_loop_proxy.h" 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/time/time.h" 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/values.h" 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chromeos/dbus/dbus_thread_manager.h" 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chromeos/dbus/shill_device_client.h" 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chromeos/dbus/shill_ipconfig_client.h" 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chromeos/network/device_state.h" 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chromeos/network/network_event_log.h" 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chromeos/network/network_handler_callbacks.h" 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chromeos/network/network_state_handler.h" 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "dbus/object_path.h" 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "third_party/cros_system_api/dbus/service_constants.h" 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace chromeos { 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace { 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)std::string GetErrorNameForShillError(const std::string& shill_error_name) { 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (shill_error_name == shill::kErrorResultFailure) 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NetworkDeviceHandler::kErrorFailure; 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (shill_error_name == shill::kErrorResultNotSupported) 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NetworkDeviceHandler::kErrorNotSupported; 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (shill_error_name == shill::kErrorResultIncorrectPin) 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NetworkDeviceHandler::kErrorIncorrectPin; 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (shill_error_name == shill::kErrorResultPinBlocked) 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NetworkDeviceHandler::kErrorPinBlocked; 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (shill_error_name == shill::kErrorResultPinRequired) 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NetworkDeviceHandler::kErrorPinRequired; 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (shill_error_name == shill::kErrorResultNotFound) 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NetworkDeviceHandler::kErrorDeviceMissing; 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NetworkDeviceHandler::kErrorUnknown; 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void InvokeErrorCallback(const std::string& service_path, 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback, 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& error_name) { 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string error_msg = "Device Error: " + error_name; 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NET_LOG_ERROR(error_msg, service_path); 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) network_handler::RunErrorCallback( 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) error_callback, service_path, error_name, error_msg); 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void HandleShillCallFailure( 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback, 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& shill_error_name, 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& shill_error_message) { 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) network_handler::ShillErrorCallbackFunction( 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetErrorNameForShillError(shill_error_name), 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_path, 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) error_callback, 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) shill_error_name, 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) shill_error_message); 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void IPConfigRefreshCallback(const std::string& ipconfig_path, 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DBusMethodCallStatus call_status) { 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (call_status != DBUS_METHOD_CALL_SUCCESS) { 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NET_LOG_ERROR( 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::StringPrintf("IPConfigs.Refresh Failed: %d", call_status), 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ipconfig_path); 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else { 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NET_LOG_EVENT("IPConfigs.Refresh Succeeded", ipconfig_path); 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void RefreshIPConfigsCallback( 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Closure& callback, 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback, 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::DictionaryValue& properties) { 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::ListValue* ip_configs; 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!properties.GetListWithoutPathExpansion( 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) shill::kIPConfigsProperty, &ip_configs)) { 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NET_LOG_ERROR("RequestRefreshIPConfigs Failed", device_path); 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) network_handler::ShillErrorCallbackFunction( 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "RequestRefreshIPConfigs Failed", 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_path, 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) error_callback, 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string("Missing ") + shill::kIPConfigsProperty, ""); 895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (size_t i = 0; i < ip_configs->GetSize(); i++) { 935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string ipconfig_path; 945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!ip_configs->GetString(i, &ipconfig_path)) 955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) continue; 965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DBusThreadManager::Get()->GetShillIPConfigClient()->Refresh( 975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dbus::ObjectPath(ipconfig_path), 985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&IPConfigRefreshCallback, ipconfig_path)); 995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // It is safe to invoke |callback| here instead of waiting for the 1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // IPConfig.Refresh callbacks to complete because the Refresh DBus calls will 1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // be executed in order and thus before any further DBus requests that 1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // |callback| may issue. 1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!callback.is_null()) 1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) callback.Run(); 1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void ProposeScanCallback( 1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Closure& callback, 1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback, 1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DBusMethodCallStatus call_status) { 1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (call_status != DBUS_METHOD_CALL_SUCCESS) { 1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) network_handler::ShillErrorCallbackFunction( 1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Device.ProposeScan Failed", 1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_path, 1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) error_callback, 1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::StringPrintf("DBus call failed: %d", call_status), ""); 1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NET_LOG_EVENT("Device.ProposeScan succeeded.", device_path); 1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!callback.is_null()) 1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) callback.Run(); 1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void SetDevicePropertyInternal( 1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& property_name, 1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Value& value, 1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Closure& callback, 1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback) { 1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DBusThreadManager::Get()->GetShillDeviceClient()->SetProperty( 1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dbus::ObjectPath(device_path), 1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) property_name, 1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) value, 1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) callback, 1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&HandleShillCallFailure, device_path, error_callback)); 1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Struct containing TDLS Operation parameters. 1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)struct TDLSOperationParams { 1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TDLSOperationParams() : retry_count(0) {} 1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string operation; 1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string ip_or_mac_address; 1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int retry_count; 1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Forward declare for PostDelayedTask. 1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void CallPerformTDLSOperation( 1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const TDLSOperationParams& params, 1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::StringResultCallback& callback, 1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback); 1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TDLSSuccessCallback( 1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const TDLSOperationParams& params, 1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::StringResultCallback& callback, 1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback, 1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& result) { 1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string event_desc = "TDLSSuccessCallback: " + params.operation; 1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!result.empty()) 1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) event_desc += ": " + result; 1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NET_LOG_EVENT(event_desc, device_path); 1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (params.operation != shill::kTDLSSetupOperation) { 1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!callback.is_null()) 1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) callback.Run(result); 1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!result.empty()) 1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NET_LOG_ERROR("Unexpected TDLS result: " + result, device_path); 1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Send a delayed Status request after a successful Setup call. 1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TDLSOperationParams status_params; 1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) status_params.operation = shill::kTDLSStatusOperation; 1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) status_params.ip_or_mac_address = params.ip_or_mac_address; 1785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const int64 kRequestStatusDelayMs = 500; 1805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::TimeDelta request_delay; 1815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()) 1825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) request_delay = base::TimeDelta::FromMilliseconds(kRequestStatusDelayMs); 1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::MessageLoopProxy::current()->PostDelayedTask( 1855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FROM_HERE, 1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&CallPerformTDLSOperation, 1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_path, status_params, callback, error_callback), 1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) request_delay); 1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TDLSErrorCallback( 1925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const TDLSOperationParams& params, 1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::StringResultCallback& callback, 1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback, 1965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& dbus_error_name, 1975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& dbus_error_message) { 1985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // If a Setup operation receives an InProgress error, retry. 1995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const int kMaxRetries = 5; 2005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (params.operation == shill::kTDLSSetupOperation && 2015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dbus_error_name == shill::kErrorResultInProgress && 2025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.retry_count < kMaxRetries) { 2035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TDLSOperationParams retry_params = params; 2045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ++retry_params.retry_count; 2055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NET_LOG_EVENT(base::StringPrintf("TDLS Retry: %d", params.retry_count), 2065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_path); 2075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const int64 kReRequestDelayMs = 1000; 2085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::TimeDelta request_delay; 2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()) 2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) request_delay = base::TimeDelta::FromMilliseconds(kReRequestDelayMs); 2115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::MessageLoopProxy::current()->PostDelayedTask( 2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) FROM_HERE, 2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&CallPerformTDLSOperation, 2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_path, retry_params, callback, error_callback), 2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) request_delay); 2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 2195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NET_LOG_ERROR("TDLS Error:" + dbus_error_name + ":" + dbus_error_message, 2215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_path); 2225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (error_callback.is_null()) 2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 2245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string error_name = 2265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dbus_error_name == shill::kErrorResultInProgress ? 2275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NetworkDeviceHandler::kErrorTimeout : NetworkDeviceHandler::kErrorUnknown; 2285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& error_detail = params.ip_or_mac_address; 2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<base::DictionaryValue> error_data( 2305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) network_handler::CreateDBusErrorData( 2315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_path, error_name, error_detail, 2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dbus_error_name, dbus_error_message)); 2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) error_callback.Run(error_name, error_data.Pass()); 2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void CallPerformTDLSOperation( 2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const TDLSOperationParams& params, 2395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::StringResultCallback& callback, 2405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback) { 2415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NET_LOG_EVENT("CallPerformTDLSOperation: " + params.operation, device_path); 2425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DBusThreadManager::Get()->GetShillDeviceClient()->PerformTDLSOperation( 2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dbus::ObjectPath(device_path), 2445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.operation, 2455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.ip_or_mac_address, 2465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&TDLSSuccessCallback, 2475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_path, params, callback, error_callback), 2485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&TDLSErrorCallback, 2495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_path, params, callback, error_callback)); 2505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace 2535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)NetworkDeviceHandlerImpl::~NetworkDeviceHandlerImpl() { 2555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) network_state_handler_->RemoveObserver(this, FROM_HERE); 2565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void NetworkDeviceHandlerImpl::GetDeviceProperties( 2595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 2605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::DictionaryResultCallback& callback, 2615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback) const { 2625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DBusThreadManager::Get()->GetShillDeviceClient()->GetProperties( 2635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dbus::ObjectPath(device_path), 2645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&network_handler::GetPropertiesCallback, 2655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) callback, error_callback, device_path)); 2665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void NetworkDeviceHandlerImpl::SetDeviceProperty( 2695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 2705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& property_name, 2715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Value& value, 2725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Closure& callback, 2735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback) { 2745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const char* const property_blacklist[] = { 2755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Must only be changed by policy/owner through. 2765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) shill::kCellularAllowRoamingProperty 2775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 2785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (size_t i = 0; i < arraysize(property_blacklist); ++i) { 2805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (property_name == property_blacklist[i]) { 2815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) InvokeErrorCallback( 2825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_path, 2835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) error_callback, 2845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "SetDeviceProperty called on blacklisted property " + property_name); 2855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 2865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 2875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 2885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetDevicePropertyInternal( 2905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_path, property_name, value, callback, error_callback); 2915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 2925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void NetworkDeviceHandlerImpl::RequestRefreshIPConfigs( 2945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 2955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Closure& callback, 2965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback) { 2975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetDeviceProperties(device_path, 2985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&RefreshIPConfigsCallback, 2995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) callback, error_callback), 3005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) error_callback); 3015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void NetworkDeviceHandlerImpl::ProposeScan( 3045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 3055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Closure& callback, 3065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback) { 3075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DBusThreadManager::Get()->GetShillDeviceClient()->ProposeScan( 3085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dbus::ObjectPath(device_path), 3095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&ProposeScanCallback, device_path, callback, error_callback)); 3105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void NetworkDeviceHandlerImpl::RegisterCellularNetwork( 3135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 3145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& network_id, 3155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Closure& callback, 3165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback) { 3175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DBusThreadManager::Get()->GetShillDeviceClient()->Register( 3185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dbus::ObjectPath(device_path), 3195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) network_id, 3205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) callback, 3215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&HandleShillCallFailure, device_path, error_callback)); 3225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void NetworkDeviceHandlerImpl::SetCarrier( 3255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 3265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& carrier, 3275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Closure& callback, 3285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback) { 3295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DBusThreadManager::Get()->GetShillDeviceClient()->SetCarrier( 3305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dbus::ObjectPath(device_path), 3315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) carrier, 3325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) callback, 3335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&HandleShillCallFailure, device_path, error_callback)); 3345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void NetworkDeviceHandlerImpl::RequirePin( 3375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 3385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool require_pin, 3395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& pin, 3405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Closure& callback, 3415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback) { 3425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DBusThreadManager::Get()->GetShillDeviceClient()->RequirePin( 3435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dbus::ObjectPath(device_path), 3445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) pin, 3455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) require_pin, 3465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) callback, 3475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&HandleShillCallFailure, device_path, error_callback)); 3485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void NetworkDeviceHandlerImpl::EnterPin( 3515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 3525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& pin, 3535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Closure& callback, 3545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback) { 3555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DBusThreadManager::Get()->GetShillDeviceClient()->EnterPin( 3565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dbus::ObjectPath(device_path), 3575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) pin, 3585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) callback, 3595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&HandleShillCallFailure, device_path, error_callback)); 3605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void NetworkDeviceHandlerImpl::UnblockPin( 3635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 3645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& puk, 3655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& new_pin, 3665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Closure& callback, 3675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback) { 3685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DBusThreadManager::Get()->GetShillDeviceClient()->UnblockPin( 3695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dbus::ObjectPath(device_path), 3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) puk, 3715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new_pin, 3725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) callback, 3735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&HandleShillCallFailure, device_path, error_callback)); 3745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void NetworkDeviceHandlerImpl::ChangePin( 3775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& device_path, 3785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& old_pin, 3795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& new_pin, 3805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Closure& callback, 3815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback) { 3825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DBusThreadManager::Get()->GetShillDeviceClient()->ChangePin( 3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) dbus::ObjectPath(device_path), 3845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) old_pin, 3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new_pin, 3865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) callback, 3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&HandleShillCallFailure, device_path, error_callback)); 3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void NetworkDeviceHandlerImpl::SetCellularAllowRoaming( 3915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const bool allow_roaming) { 3925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cellular_allow_roaming_ = allow_roaming; 3935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ApplyCellularAllowRoamingToShill(); 3945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 3955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void NetworkDeviceHandlerImpl::SetWifiTDLSEnabled( 3975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& ip_or_mac_address, 3985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool enabled, 3995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::StringResultCallback& callback, 4005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback) { 4015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const DeviceState* device_state = 4025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi()); 4035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!device_state) { 4045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (error_callback.is_null()) 4055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 4065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue); 4075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing); 4085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) error_callback.Run(kErrorDeviceMissing, error_data.Pass()); 4095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 4105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TDLSOperationParams params; 4125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.operation = enabled ? shill::kTDLSSetupOperation 4135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : shill::kTDLSTeardownOperation; 4145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.ip_or_mac_address = ip_or_mac_address; 4155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CallPerformTDLSOperation( 4165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_state->path(), params, callback, error_callback); 4175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 4185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void NetworkDeviceHandlerImpl::GetWifiTDLSStatus( 4205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& ip_or_mac_address, 4215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::StringResultCallback& callback, 4225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const network_handler::ErrorCallback& error_callback) { 4235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const DeviceState* device_state = 4245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) network_state_handler_->GetDeviceStateByType(NetworkTypePattern::WiFi()); 4255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!device_state) { 4265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (error_callback.is_null()) 4275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 4285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<base::DictionaryValue> error_data(new base::DictionaryValue); 4295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) error_data->SetString(network_handler::kErrorName, kErrorDeviceMissing); 4305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) error_callback.Run(kErrorDeviceMissing, error_data.Pass()); 4315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 4325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TDLSOperationParams params; 4345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.operation = shill::kTDLSStatusOperation; 4355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) params.ip_or_mac_address = ip_or_mac_address; 4365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) CallPerformTDLSOperation( 4375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_state->path(), params, callback, error_callback); 4385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 4395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void NetworkDeviceHandlerImpl::DeviceListChanged() { 4415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ApplyCellularAllowRoamingToShill(); 4425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 4435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)NetworkDeviceHandlerImpl::NetworkDeviceHandlerImpl() 4455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : network_state_handler_(NULL), 4465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) cellular_allow_roaming_(false) {} 4475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void NetworkDeviceHandlerImpl::Init( 4495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NetworkStateHandler* network_state_handler) { 4505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DCHECK(network_state_handler); 4515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) network_state_handler_ = network_state_handler; 4525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) network_state_handler_->AddObserver(this, FROM_HERE); 4535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 4545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void NetworkDeviceHandlerImpl::ApplyCellularAllowRoamingToShill() { 4565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NetworkStateHandler::DeviceStateList list; 4575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) network_state_handler_->GetDeviceListByType(NetworkTypePattern::Cellular(), 4585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) &list); 4595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (list.empty()) { 4605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NET_LOG_DEBUG("No cellular device is available", 4615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Roaming is only supported by cellular devices."); 4625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return; 4635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (NetworkStateHandler::DeviceStateList::const_iterator it = list.begin(); 4655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) it != list.end(); ++it) { 4665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const DeviceState* device_state = *it; 467010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) bool current_allow_roaming = device_state->allow_roaming(); 4685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // If roaming is required by the provider, always try to set to true. 4705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool new_device_value = 4715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_state->provider_requires_roaming() || cellular_allow_roaming_; 4725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Only set the value if the current value is different from 4745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // |new_device_value|. 475010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) if (new_device_value == current_allow_roaming) 4765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) continue; 4775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SetDevicePropertyInternal(device_state->path(), 4795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) shill::kCellularAllowRoamingProperty, 4805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::FundamentalValue(new_device_value), 4815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Bind(&base::DoNothing), 4825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) network_handler::ErrorCallback()); 4835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 4845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 4855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace chromeos 487