blob: b34b5bc368bba46c4770a677bce2c19c15b48fcc [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
70 set_friendly_name(network_name_);
71 storage_id_ =
72 StringToLowerASCII(base::StringPrintf("%s_%s_%08x_%s",
73 flimflam::kTypeWimax,
74 network_name_.c_str(),
75 network_identifier_,
76 wimax_->address().c_str()));
77 replace_if(
78 storage_id_.begin(), storage_id_.end(), &Service::IllegalChar, '_');
79 set_connectable(true);
80 return true;
81}
82
Ben Chan99c8a4d2012-05-01 08:11:53 -070083bool WiMaxService::TechnologyIs(const Technology::Identifier type) const {
84 return type == Technology::kWiMax;
85}
86
87void WiMaxService::Connect(Error *error) {
88 Service::Connect(error);
Darin Petkov9893d9c2012-05-17 15:27:31 -070089 wimax_->ConnectTo(this, error);
Ben Chan99c8a4d2012-05-01 08:11:53 -070090}
91
92void WiMaxService::Disconnect(Error *error) {
93 Service::Disconnect(error);
Darin Petkov9893d9c2012-05-17 15:27:31 -070094 wimax_->DisconnectFrom(this, error);
Ben Chan99c8a4d2012-05-01 08:11:53 -070095}
96
Ben Chanc07362b2012-05-12 10:54:11 -070097string WiMaxService::GetStorageIdentifier() const {
Darin Petkove4b27022012-05-16 13:28:50 +020098 return storage_id_;
Ben Chanc07362b2012-05-12 10:54:11 -070099}
100
101string WiMaxService::GetDeviceRpcId(Error *error) {
Darin Petkove4b27022012-05-16 13:28:50 +0200102 return wimax_->GetRpcIdentifier();
Ben Chanc07362b2012-05-12 10:54:11 -0700103}
104
Ben Chan99c8a4d2012-05-01 08:11:53 -0700105} // namespace shill