Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/wimax_service.h" |
| 6 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 9 | #include <base/string_util.h> |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 10 | #include <base/stringprintf.h> |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 11 | #include <chromeos/dbus/service_constants.h> |
| 12 | |
Darin Petkov | 25665aa | 2012-05-21 14:08:12 +0200 | [diff] [blame^] | 13 | #include "shill/key_value_store.h" |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 14 | #include "shill/scope_logger.h" |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 15 | #include "shill/technology.h" |
| 16 | #include "shill/wimax.h" |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 17 | #include "shill/wimax_network_proxy_interface.h" |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 18 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 19 | using std::replace_if; |
Ben Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 20 | using std::string; |
| 21 | |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 22 | namespace shill { |
| 23 | |
| 24 | WiMaxService::WiMaxService(ControlInterface *control, |
| 25 | EventDispatcher *dispatcher, |
| 26 | Metrics *metrics, |
| 27 | Manager *manager, |
| 28 | const WiMaxRefPtr &wimax) |
| 29 | : Service(control, dispatcher, metrics, manager, Technology::kWiMax), |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 30 | wimax_(wimax), |
Ben Chan | 4e5c131 | 2012-05-18 18:45:38 -0700 | [diff] [blame] | 31 | network_identifier_(0), |
| 32 | need_passphrase_(true) { |
| 33 | PropertyStore *store = this->mutable_store(); |
| 34 | // TODO(benchan): Support networks that require no user credentials or |
| 35 | // implicitly defined credentials. |
| 36 | store->RegisterBool(flimflam::kPassphraseRequiredProperty, &need_passphrase_); |
| 37 | } |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 38 | |
| 39 | WiMaxService::~WiMaxService() {} |
| 40 | |
Darin Petkov | 25665aa | 2012-05-21 14:08:12 +0200 | [diff] [blame^] | 41 | void WiMaxService::GetConnectParameters(KeyValueStore *parameters) const { |
Ben Chan | 4e5c131 | 2012-05-18 18:45:38 -0700 | [diff] [blame] | 42 | CHECK(parameters); |
Darin Petkov | 25665aa | 2012-05-21 14:08:12 +0200 | [diff] [blame^] | 43 | if (!eap().anonymous_identity.empty()) { |
| 44 | parameters->SetString(wimax_manager::kEAPAnonymousIdentity, |
| 45 | eap().anonymous_identity); |
| 46 | } |
| 47 | if (!eap().identity.empty()) { |
| 48 | parameters->SetString(wimax_manager::kEAPUserIdentity, eap().identity); |
| 49 | } |
| 50 | if (!eap().password.empty()) { |
| 51 | parameters->SetString(wimax_manager::kEAPUserPassword, eap().password); |
| 52 | } |
Ben Chan | 4e5c131 | 2012-05-18 18:45:38 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Darin Petkov | 1e52a1b | 2012-05-21 10:35:56 +0200 | [diff] [blame] | 55 | RpcIdentifier WiMaxService::GetNetworkObjectPath() const { |
Ben Chan | 4e5c131 | 2012-05-18 18:45:38 -0700 | [diff] [blame] | 56 | CHECK(proxy_.get()); |
Darin Petkov | 1e52a1b | 2012-05-21 10:35:56 +0200 | [diff] [blame] | 57 | return proxy_->path(); |
Ben Chan | 4e5c131 | 2012-05-18 18:45:38 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 60 | bool WiMaxService::Start(WiMaxNetworkProxyInterface *proxy) { |
| 61 | SLOG(WiMax, 2) << __func__; |
Darin Petkov | 1e52a1b | 2012-05-21 10:35:56 +0200 | [diff] [blame] | 62 | CHECK(proxy); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 63 | proxy_.reset(proxy); |
| 64 | |
| 65 | Error error; |
| 66 | network_name_ = proxy_->Name(&error); |
| 67 | if (!error.IsSuccess()) { |
| 68 | return false; |
| 69 | } |
| 70 | network_identifier_ = proxy_->Identifier(&error); |
| 71 | if (!error.IsSuccess()) { |
| 72 | return false; |
| 73 | } |
| 74 | |
Ben Chan | ac6e836 | 2012-05-20 00:39:58 -0700 | [diff] [blame] | 75 | int signal_strength = proxy_->SignalStrength(&error); |
| 76 | if (!error.IsSuccess()) { |
| 77 | return false; |
| 78 | } |
| 79 | SetStrength(signal_strength); |
Darin Petkov | 1e52a1b | 2012-05-21 10:35:56 +0200 | [diff] [blame] | 80 | proxy_->set_signal_strength_changed_callback( |
| 81 | Bind(&WiMaxService::OnSignalStrengthChanged, Unretained(this))); |
Ben Chan | ac6e836 | 2012-05-20 00:39:58 -0700 | [diff] [blame] | 82 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 83 | set_friendly_name(network_name_); |
| 84 | storage_id_ = |
| 85 | StringToLowerASCII(base::StringPrintf("%s_%s_%08x_%s", |
| 86 | flimflam::kTypeWimax, |
| 87 | network_name_.c_str(), |
| 88 | network_identifier_, |
| 89 | wimax_->address().c_str())); |
| 90 | replace_if( |
| 91 | storage_id_.begin(), storage_id_.end(), &Service::IllegalChar, '_'); |
| 92 | set_connectable(true); |
| 93 | return true; |
| 94 | } |
| 95 | |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 96 | bool WiMaxService::TechnologyIs(const Technology::Identifier type) const { |
| 97 | return type == Technology::kWiMax; |
| 98 | } |
| 99 | |
| 100 | void WiMaxService::Connect(Error *error) { |
| 101 | Service::Connect(error); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 102 | wimax_->ConnectTo(this, error); |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void WiMaxService::Disconnect(Error *error) { |
| 106 | Service::Disconnect(error); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 107 | wimax_->DisconnectFrom(this, error); |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Ben Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 110 | string WiMaxService::GetStorageIdentifier() const { |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 111 | return storage_id_; |
Ben Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | string WiMaxService::GetDeviceRpcId(Error *error) { |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 115 | return wimax_->GetRpcIdentifier(); |
Ben Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Darin Petkov | 1e52a1b | 2012-05-21 10:35:56 +0200 | [diff] [blame] | 118 | void WiMaxService::OnSignalStrengthChanged(int strength) { |
| 119 | SLOG(WiMax, 2) << __func__ << "(" << strength << ")"; |
| 120 | SetStrength(strength); |
| 121 | } |
| 122 | |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 123 | } // namespace shill |