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 | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 13 | #include "shill/scope_logger.h" |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 14 | #include "shill/technology.h" |
| 15 | #include "shill/wimax.h" |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 16 | #include "shill/wimax_network_proxy_interface.h" |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 17 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 18 | using std::replace_if; |
Ben Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 19 | using std::string; |
| 20 | |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 21 | namespace shill { |
| 22 | |
| 23 | WiMaxService::WiMaxService(ControlInterface *control, |
| 24 | EventDispatcher *dispatcher, |
| 25 | Metrics *metrics, |
| 26 | Manager *manager, |
| 27 | const WiMaxRefPtr &wimax) |
| 28 | : Service(control, dispatcher, metrics, manager, Technology::kWiMax), |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 29 | wimax_(wimax), |
Ben Chan | 4e5c131 | 2012-05-18 18:45:38 -0700 | [diff] [blame] | 30 | network_identifier_(0), |
| 31 | need_passphrase_(true) { |
| 32 | PropertyStore *store = this->mutable_store(); |
| 33 | // TODO(benchan): Support networks that require no user credentials or |
| 34 | // implicitly defined credentials. |
| 35 | store->RegisterBool(flimflam::kPassphraseRequiredProperty, &need_passphrase_); |
| 36 | } |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 37 | |
| 38 | WiMaxService::~WiMaxService() {} |
| 39 | |
Ben Chan | 4e5c131 | 2012-05-18 18:45:38 -0700 | [diff] [blame] | 40 | void WiMaxService::GetConnectParameters(DBusPropertiesMap *parameters) const { |
| 41 | CHECK(parameters); |
| 42 | |
| 43 | (*parameters)[wimax_manager::kEAPAnonymousIdentity].writer() |
| 44 | .append_string(eap().anonymous_identity.c_str()); |
| 45 | (*parameters)[wimax_manager::kEAPUserIdentity].writer() |
| 46 | .append_string(eap().identity.c_str()); |
| 47 | (*parameters)[wimax_manager::kEAPUserPassword].writer() |
| 48 | .append_string(eap().password.c_str()); |
| 49 | } |
| 50 | |
| 51 | DBus::Path WiMaxService::GetNetworkObjectPath() const { |
| 52 | CHECK(proxy_.get()); |
| 53 | return proxy_->proxy_object_path(); |
| 54 | } |
| 55 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 56 | bool WiMaxService::Start(WiMaxNetworkProxyInterface *proxy) { |
| 57 | SLOG(WiMax, 2) << __func__; |
| 58 | proxy_.reset(proxy); |
| 59 | |
| 60 | Error error; |
| 61 | network_name_ = proxy_->Name(&error); |
| 62 | if (!error.IsSuccess()) { |
| 63 | return false; |
| 64 | } |
| 65 | network_identifier_ = proxy_->Identifier(&error); |
| 66 | if (!error.IsSuccess()) { |
| 67 | return false; |
| 68 | } |
| 69 | |
Ben Chan | ac6e836 | 2012-05-20 00:39:58 -0700 | [diff] [blame^] | 70 | int signal_strength = proxy_->SignalStrength(&error); |
| 71 | if (!error.IsSuccess()) { |
| 72 | return false; |
| 73 | } |
| 74 | SetStrength(signal_strength); |
| 75 | |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 76 | set_friendly_name(network_name_); |
| 77 | storage_id_ = |
| 78 | StringToLowerASCII(base::StringPrintf("%s_%s_%08x_%s", |
| 79 | flimflam::kTypeWimax, |
| 80 | network_name_.c_str(), |
| 81 | network_identifier_, |
| 82 | wimax_->address().c_str())); |
| 83 | replace_if( |
| 84 | storage_id_.begin(), storage_id_.end(), &Service::IllegalChar, '_'); |
| 85 | set_connectable(true); |
| 86 | return true; |
| 87 | } |
| 88 | |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 89 | bool WiMaxService::TechnologyIs(const Technology::Identifier type) const { |
| 90 | return type == Technology::kWiMax; |
| 91 | } |
| 92 | |
| 93 | void WiMaxService::Connect(Error *error) { |
| 94 | Service::Connect(error); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 95 | wimax_->ConnectTo(this, error); |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | void WiMaxService::Disconnect(Error *error) { |
| 99 | Service::Disconnect(error); |
Darin Petkov | 9893d9c | 2012-05-17 15:27:31 -0700 | [diff] [blame] | 100 | wimax_->DisconnectFrom(this, error); |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Ben Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 103 | string WiMaxService::GetStorageIdentifier() const { |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 104 | return storage_id_; |
Ben Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | string WiMaxService::GetDeviceRpcId(Error *error) { |
Darin Petkov | e4b2702 | 2012-05-16 13:28:50 +0200 | [diff] [blame] | 108 | return wimax_->GetRpcIdentifier(); |
Ben Chan | c07362b | 2012-05-12 10:54:11 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Ben Chan | 99c8a4d | 2012-05-01 08:11:53 -0700 | [diff] [blame] | 111 | } // namespace shill |