blob: 323c1b0dc3756c482e9d32d794ea076b3241d7a5 [file] [log] [blame]
Ben Chan99c8a4d2012-05-01 08:11:53 -07001// 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 Petkov9893d9c2012-05-17 15:27:31 -07007#include <algorithm>
8
Darin Petkove4b27022012-05-16 13:28:50 +02009#include <base/string_util.h>
Darin Petkov9893d9c2012-05-17 15:27:31 -070010#include <base/stringprintf.h>
Darin Petkove4b27022012-05-16 13:28:50 +020011#include <chromeos/dbus/service_constants.h>
12
Darin Petkov25665aa2012-05-21 14:08:12 +020013#include "shill/key_value_store.h"
Darin Petkov9893d9c2012-05-17 15:27:31 -070014#include "shill/scope_logger.h"
Ben Chan99c8a4d2012-05-01 08:11:53 -070015#include "shill/technology.h"
16#include "shill/wimax.h"
Darin Petkov9893d9c2012-05-17 15:27:31 -070017#include "shill/wimax_network_proxy_interface.h"
Ben Chan99c8a4d2012-05-01 08:11:53 -070018
Darin Petkov9893d9c2012-05-17 15:27:31 -070019using std::replace_if;
Ben Chanc07362b2012-05-12 10:54:11 -070020using std::string;
21
Ben Chan99c8a4d2012-05-01 08:11:53 -070022namespace shill {
23
24WiMaxService::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 Petkove4b27022012-05-16 13:28:50 +020030 wimax_(wimax),
Ben Chan4e5c1312012-05-18 18:45:38 -070031 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 Chan99c8a4d2012-05-01 08:11:53 -070038
39WiMaxService::~WiMaxService() {}
40
Darin Petkov25665aa2012-05-21 14:08:12 +020041void WiMaxService::GetConnectParameters(KeyValueStore *parameters) const {
Ben Chan4e5c1312012-05-18 18:45:38 -070042 CHECK(parameters);
Darin Petkov25665aa2012-05-21 14:08:12 +020043 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 Chan4e5c1312012-05-18 18:45:38 -070053}
54
Darin Petkov1e52a1b2012-05-21 10:35:56 +020055RpcIdentifier WiMaxService::GetNetworkObjectPath() const {
Ben Chan4e5c1312012-05-18 18:45:38 -070056 CHECK(proxy_.get());
Darin Petkov1e52a1b2012-05-21 10:35:56 +020057 return proxy_->path();
Ben Chan4e5c1312012-05-18 18:45:38 -070058}
59
Darin Petkov9893d9c2012-05-17 15:27:31 -070060bool WiMaxService::Start(WiMaxNetworkProxyInterface *proxy) {
61 SLOG(WiMax, 2) << __func__;
Darin Petkov1e52a1b2012-05-21 10:35:56 +020062 CHECK(proxy);
Darin Petkov9893d9c2012-05-17 15:27:31 -070063 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 Chanac6e8362012-05-20 00:39:58 -070075 int signal_strength = proxy_->SignalStrength(&error);
76 if (!error.IsSuccess()) {
77 return false;
78 }
79 SetStrength(signal_strength);
Darin Petkov1e52a1b2012-05-21 10:35:56 +020080 proxy_->set_signal_strength_changed_callback(
81 Bind(&WiMaxService::OnSignalStrengthChanged, Unretained(this)));
Ben Chanac6e8362012-05-20 00:39:58 -070082
Darin Petkov9893d9c2012-05-17 15:27:31 -070083 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, '_');
Darin Petkov8021e7f2012-05-21 12:15:00 +020092 UpdateConnectable();
Darin Petkov9893d9c2012-05-17 15:27:31 -070093 return true;
94}
95
Ben Chan99c8a4d2012-05-01 08:11:53 -070096bool WiMaxService::TechnologyIs(const Technology::Identifier type) const {
97 return type == Technology::kWiMax;
98}
99
100void WiMaxService::Connect(Error *error) {
101 Service::Connect(error);
Darin Petkov9893d9c2012-05-17 15:27:31 -0700102 wimax_->ConnectTo(this, error);
Ben Chan99c8a4d2012-05-01 08:11:53 -0700103}
104
105void WiMaxService::Disconnect(Error *error) {
106 Service::Disconnect(error);
Darin Petkov9893d9c2012-05-17 15:27:31 -0700107 wimax_->DisconnectFrom(this, error);
Ben Chan99c8a4d2012-05-01 08:11:53 -0700108}
109
Ben Chanc07362b2012-05-12 10:54:11 -0700110string WiMaxService::GetStorageIdentifier() const {
Darin Petkove4b27022012-05-16 13:28:50 +0200111 return storage_id_;
Ben Chanc07362b2012-05-12 10:54:11 -0700112}
113
114string WiMaxService::GetDeviceRpcId(Error *error) {
Darin Petkove4b27022012-05-16 13:28:50 +0200115 return wimax_->GetRpcIdentifier();
Ben Chanc07362b2012-05-12 10:54:11 -0700116}
117
Darin Petkov8021e7f2012-05-21 12:15:00 +0200118bool WiMaxService::Is8021x() const {
119 return true;
120}
121
122void WiMaxService::set_eap(const EapCredentials &eap) {
123 Service::set_eap(eap);
124 UpdateConnectable();
125}
126
127void WiMaxService::UpdateConnectable() {
128 // Don't use Service::Is8021xConnectable because we don't support the full set
129 // of authentication methods.
130 bool is_connectable = false;
131 if (!eap().identity.empty()) {
132 is_connectable = !eap().password.empty();
133 }
134 set_connectable(is_connectable);
135}
136
Darin Petkov1e52a1b2012-05-21 10:35:56 +0200137void WiMaxService::OnSignalStrengthChanged(int strength) {
138 SLOG(WiMax, 2) << __func__ << "(" << strength << ")";
139 SetStrength(strength);
140}
141
Ben Chan99c8a4d2012-05-01 08:11:53 -0700142} // namespace shill