blob: 588d5ab30278b21122332ee2c0b7b341b303a70b [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 Petkov9893d9c2012-05-17 15:27:31 -070013#include "shill/scope_logger.h"
Ben Chan99c8a4d2012-05-01 08:11:53 -070014#include "shill/technology.h"
15#include "shill/wimax.h"
Darin Petkov9893d9c2012-05-17 15:27:31 -070016#include "shill/wimax_network_proxy_interface.h"
Ben Chan99c8a4d2012-05-01 08:11:53 -070017
Darin Petkov9893d9c2012-05-17 15:27:31 -070018using std::replace_if;
Ben Chanc07362b2012-05-12 10:54:11 -070019using std::string;
20
Ben Chan99c8a4d2012-05-01 08:11:53 -070021namespace shill {
22
23WiMaxService::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 Petkove4b27022012-05-16 13:28:50 +020029 wimax_(wimax),
Ben Chan4e5c1312012-05-18 18:45:38 -070030 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 Chan99c8a4d2012-05-01 08:11:53 -070037
38WiMaxService::~WiMaxService() {}
39
Ben Chan4e5c1312012-05-18 18:45:38 -070040void 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
51DBus::Path WiMaxService::GetNetworkObjectPath() const {
52 CHECK(proxy_.get());
53 return proxy_->proxy_object_path();
54}
55
Darin Petkov9893d9c2012-05-17 15:27:31 -070056bool 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 Chanac6e8362012-05-20 00:39:58 -070070 int signal_strength = proxy_->SignalStrength(&error);
71 if (!error.IsSuccess()) {
72 return false;
73 }
74 SetStrength(signal_strength);
75
Darin Petkov9893d9c2012-05-17 15:27:31 -070076 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 Chan99c8a4d2012-05-01 08:11:53 -070089bool WiMaxService::TechnologyIs(const Technology::Identifier type) const {
90 return type == Technology::kWiMax;
91}
92
93void WiMaxService::Connect(Error *error) {
94 Service::Connect(error);
Darin Petkov9893d9c2012-05-17 15:27:31 -070095 wimax_->ConnectTo(this, error);
Ben Chan99c8a4d2012-05-01 08:11:53 -070096}
97
98void WiMaxService::Disconnect(Error *error) {
99 Service::Disconnect(error);
Darin Petkov9893d9c2012-05-17 15:27:31 -0700100 wimax_->DisconnectFrom(this, error);
Ben Chan99c8a4d2012-05-01 08:11:53 -0700101}
102
Ben Chanc07362b2012-05-12 10:54:11 -0700103string WiMaxService::GetStorageIdentifier() const {
Darin Petkove4b27022012-05-16 13:28:50 +0200104 return storage_id_;
Ben Chanc07362b2012-05-12 10:54:11 -0700105}
106
107string WiMaxService::GetDeviceRpcId(Error *error) {
Darin Petkove4b27022012-05-16 13:28:50 +0200108 return wimax_->GetRpcIdentifier();
Ben Chanc07362b2012-05-12 10:54:11 -0700109}
110
Ben Chan99c8a4d2012-05-01 08:11:53 -0700111} // namespace shill