blob: c7ba8cf7ef26ff3cf2f5d2bd46e5ad79ed438c2e [file] [log] [blame]
Jason Glasgow74f5ef22012-03-29 16:15:04 -04001// 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/mm1_sim_proxy.h"
6
7#include <base/logging.h>
8
Ben Chanfad4a0b2012-04-18 15:49:59 -07009#include "shill/cellular_error.h"
10#include "shill/scope_logger.h"
Jason Glasgow74f5ef22012-03-29 16:15:04 -040011
12using std::string;
13
14namespace shill {
15namespace mm1 {
16
17SimProxy::SimProxy(DBus::Connection *connection,
18 const string &path,
19 const string &service)
20 : proxy_(connection, path, service) {}
21
22SimProxy::~SimProxy() {}
23
24
25void SimProxy::SendPin(const string &pin,
26 Error *error,
27 const ResultCallback &callback,
28 int timeout) {
29 // pin is intentionally not logged.
Ben Chanfad4a0b2012-04-18 15:49:59 -070030 SLOG(Modem, 2) << __func__ << "( XXX, " << timeout << ")";
Jason Glasgow74f5ef22012-03-29 16:15:04 -040031 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
32 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070033 SLOG(DBus, 2) << __func__;
Jason Glasgow74f5ef22012-03-29 16:15:04 -040034 proxy_.SendPin(pin, cb.get(), timeout);
35 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070036 } catch (const DBus::Error &e) {
Jason Glasgow74f5ef22012-03-29 16:15:04 -040037 if (error)
38 CellularError::FromDBusError(e, error);
39 }
40}
41
42void SimProxy::SendPuk(const string &puk,
43 const string &pin,
44 Error *error,
45 const ResultCallback &callback,
46 int timeout) {
47 // pin and puk are intentionally not logged.
Ben Chanfad4a0b2012-04-18 15:49:59 -070048 SLOG(Modem, 2) << __func__ << "( XXX, XXX, " << timeout << ")";
Jason Glasgow74f5ef22012-03-29 16:15:04 -040049 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
50 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070051 SLOG(DBus, 2) << __func__;
Jason Glasgow74f5ef22012-03-29 16:15:04 -040052 proxy_.SendPuk(puk, pin, cb.get(), timeout);
53 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070054 } catch (const DBus::Error &e) {
Jason Glasgow74f5ef22012-03-29 16:15:04 -040055 if (error)
56 CellularError::FromDBusError(e, error);
57 }
58}
59
60void SimProxy::EnablePin(const string &pin,
61 const bool enabled,
62 Error *error,
63 const ResultCallback &callback,
64 int timeout) {
65 // pin is intentionally not logged.
Ben Chanfad4a0b2012-04-18 15:49:59 -070066 SLOG(Modem, 2) << __func__ << "( XXX, " << enabled << ", " << timeout << ")";
Jason Glasgow74f5ef22012-03-29 16:15:04 -040067 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
68 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070069 SLOG(DBus, 2) << __func__;
Jason Glasgow74f5ef22012-03-29 16:15:04 -040070 proxy_.EnablePin(pin, enabled, cb.get(), timeout);
71 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070072 } catch (const DBus::Error &e) {
Jason Glasgow74f5ef22012-03-29 16:15:04 -040073 if (error)
74 CellularError::FromDBusError(e, error);
75 }
76}
77
78void SimProxy::ChangePin(const string &old_pin,
79 const string &new_pin,
80 Error *error,
81 const ResultCallback &callback,
82 int timeout) {
83 // old_pin and new_pin are intentionally not logged.
Ben Chanfad4a0b2012-04-18 15:49:59 -070084 SLOG(Modem, 2) << __func__ << "( XXX, XXX, " << timeout << ")";
Jason Glasgow74f5ef22012-03-29 16:15:04 -040085 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
86 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070087 SLOG(DBus, 2) << __func__;
Jason Glasgow74f5ef22012-03-29 16:15:04 -040088 proxy_.ChangePin(old_pin, new_pin, cb.get(), timeout);
89 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070090 } catch (const DBus::Error &e) {
Jason Glasgow74f5ef22012-03-29 16:15:04 -040091 if (error)
92 CellularError::FromDBusError(e, error);
93 }
94}
95
96// Inherited properties from SimProxyInterface.
97const string SimProxy::SimIdentifier() {
mukesh agrawal06175d72012-04-23 16:46:01 -070098 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070099 try {
100 return proxy_.SimIdentifier();
101 } catch (const DBus::Error &e) {
102 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
103 return string(); // Make the compiler happy.
104 }
Jason Glasgow74f5ef22012-03-29 16:15:04 -0400105}
106
107const string SimProxy::Imsi() {
mukesh agrawal06175d72012-04-23 16:46:01 -0700108 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -0700109 try {
110 return proxy_.Imsi();
111 } catch (const DBus::Error &e) {
112 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
113 return string(); // Make the compiler happy.
114 }
Jason Glasgow74f5ef22012-03-29 16:15:04 -0400115}
116
117const string SimProxy::OperatorIdentifier() {
mukesh agrawal06175d72012-04-23 16:46:01 -0700118 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -0700119 try {
120 return proxy_.OperatorIdentifier();
121 } catch (const DBus::Error &e) {
122 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
123 return string(); // Make the compiler happy.
124 }
Jason Glasgow74f5ef22012-03-29 16:15:04 -0400125}
126
127const string SimProxy::OperatorName() {
mukesh agrawal06175d72012-04-23 16:46:01 -0700128 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -0700129 try {
130 return proxy_.OperatorName();
131 } catch (const DBus::Error &e) {
132 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
133 return string(); // Make the compiler happy.
134 }
Jason Glasgow74f5ef22012-03-29 16:15:04 -0400135}
136
137SimProxy::Proxy::Proxy(DBus::Connection *connection,
138 const string &path,
139 const string &service)
140 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
141
142SimProxy::Proxy::~Proxy() {}
143
144
145// Method callbacks inherited from
146// org::freedesktop::ModemManager1::SimProxy
147void SimProxy::Proxy::SendPinCallback(const ::DBus::Error &dberror,
148 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700149 SLOG(DBus, 2) << __func__;
Jason Glasgow74f5ef22012-03-29 16:15:04 -0400150 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
151 Error error;
152 CellularError::FromDBusError(dberror, &error);
153 callback->Run(error);
154}
155
156void SimProxy::Proxy::SendPukCallback(const ::DBus::Error &dberror,
mukesh agrawal06175d72012-04-23 16:46:01 -0700157 void *data) {
158 SLOG(DBus, 2) << __func__;
Jason Glasgow74f5ef22012-03-29 16:15:04 -0400159 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
160 Error error;
161 CellularError::FromDBusError(dberror, &error);
162 callback->Run(error);
163}
164
Gary Morainabb30da2012-05-08 16:59:59 -0700165void SimProxy::Proxy::EnablePinCallback(const ::DBus::Error &dberror,
166 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700167 SLOG(DBus, 2) << __func__;
Jason Glasgow74f5ef22012-03-29 16:15:04 -0400168 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
169 Error error;
170 CellularError::FromDBusError(dberror, &error);
171 callback->Run(error);
172}
173
Gary Morainabb30da2012-05-08 16:59:59 -0700174void SimProxy::Proxy::ChangePinCallback(const ::DBus::Error &dberror,
175 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700176 SLOG(DBus, 2) << __func__;
Jason Glasgow74f5ef22012-03-29 16:15:04 -0400177 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
178 Error error;
179 CellularError::FromDBusError(dberror, &error);
180 callback->Run(error);
181}
182
183} // namespace mm1
184} // namespace shill