blob: 45d9a53b00162d0e37e30e2a790893d09bd1fd19 [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
Ben Chanfad4a0b2012-04-18 15:49:59 -07007#include "shill/cellular_error.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -07008#include "shill/logging.h"
Jason Glasgow74f5ef22012-03-29 16:15:04 -04009
10using std::string;
11
12namespace shill {
13namespace mm1 {
14
15SimProxy::SimProxy(DBus::Connection *connection,
16 const string &path,
17 const string &service)
18 : proxy_(connection, path, service) {}
19
20SimProxy::~SimProxy() {}
21
22
23void SimProxy::SendPin(const string &pin,
24 Error *error,
25 const ResultCallback &callback,
26 int timeout) {
27 // pin is intentionally not logged.
Ben Chanfad4a0b2012-04-18 15:49:59 -070028 SLOG(Modem, 2) << __func__ << "( XXX, " << timeout << ")";
Jason Glasgow74f5ef22012-03-29 16:15:04 -040029 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
30 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070031 SLOG(DBus, 2) << __func__;
Jason Glasgow74f5ef22012-03-29 16:15:04 -040032 proxy_.SendPin(pin, cb.get(), timeout);
33 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070034 } catch (const DBus::Error &e) {
Jason Glasgow74f5ef22012-03-29 16:15:04 -040035 if (error)
36 CellularError::FromDBusError(e, error);
37 }
38}
39
40void SimProxy::SendPuk(const string &puk,
41 const string &pin,
42 Error *error,
43 const ResultCallback &callback,
44 int timeout) {
45 // pin and puk are intentionally not logged.
Ben Chanfad4a0b2012-04-18 15:49:59 -070046 SLOG(Modem, 2) << __func__ << "( XXX, XXX, " << timeout << ")";
Jason Glasgow74f5ef22012-03-29 16:15:04 -040047 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
48 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070049 SLOG(DBus, 2) << __func__;
Jason Glasgow74f5ef22012-03-29 16:15:04 -040050 proxy_.SendPuk(puk, pin, cb.get(), timeout);
51 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070052 } catch (const DBus::Error &e) {
Jason Glasgow74f5ef22012-03-29 16:15:04 -040053 if (error)
54 CellularError::FromDBusError(e, error);
55 }
56}
57
58void SimProxy::EnablePin(const string &pin,
59 const bool enabled,
60 Error *error,
61 const ResultCallback &callback,
62 int timeout) {
63 // pin is intentionally not logged.
Ben Chanfad4a0b2012-04-18 15:49:59 -070064 SLOG(Modem, 2) << __func__ << "( XXX, " << enabled << ", " << timeout << ")";
Jason Glasgow74f5ef22012-03-29 16:15:04 -040065 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
66 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070067 SLOG(DBus, 2) << __func__;
Jason Glasgow74f5ef22012-03-29 16:15:04 -040068 proxy_.EnablePin(pin, enabled, cb.get(), timeout);
69 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070070 } catch (const DBus::Error &e) {
Jason Glasgow74f5ef22012-03-29 16:15:04 -040071 if (error)
72 CellularError::FromDBusError(e, error);
73 }
74}
75
76void SimProxy::ChangePin(const string &old_pin,
77 const string &new_pin,
78 Error *error,
79 const ResultCallback &callback,
80 int timeout) {
81 // old_pin and new_pin are intentionally not logged.
Ben Chanfad4a0b2012-04-18 15:49:59 -070082 SLOG(Modem, 2) << __func__ << "( XXX, XXX, " << timeout << ")";
Jason Glasgow74f5ef22012-03-29 16:15:04 -040083 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
84 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070085 SLOG(DBus, 2) << __func__;
Jason Glasgow74f5ef22012-03-29 16:15:04 -040086 proxy_.ChangePin(old_pin, new_pin, cb.get(), timeout);
87 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070088 } catch (const DBus::Error &e) {
Jason Glasgow74f5ef22012-03-29 16:15:04 -040089 if (error)
90 CellularError::FromDBusError(e, error);
91 }
92}
93
94// Inherited properties from SimProxyInterface.
95const string SimProxy::SimIdentifier() {
mukesh agrawal06175d72012-04-23 16:46:01 -070096 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -070097 try {
98 return proxy_.SimIdentifier();
99 } catch (const DBus::Error &e) {
100 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
101 return string(); // Make the compiler happy.
102 }
Jason Glasgow74f5ef22012-03-29 16:15:04 -0400103}
104
105const string SimProxy::Imsi() {
mukesh agrawal06175d72012-04-23 16:46:01 -0700106 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -0700107 try {
108 return proxy_.Imsi();
109 } catch (const DBus::Error &e) {
110 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
111 return string(); // Make the compiler happy.
112 }
Jason Glasgow74f5ef22012-03-29 16:15:04 -0400113}
114
115const string SimProxy::OperatorIdentifier() {
mukesh agrawal06175d72012-04-23 16:46:01 -0700116 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -0700117 try {
118 return proxy_.OperatorIdentifier();
119 } catch (const DBus::Error &e) {
120 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
121 return string(); // Make the compiler happy.
122 }
Jason Glasgow74f5ef22012-03-29 16:15:04 -0400123}
124
125const string SimProxy::OperatorName() {
mukesh agrawal06175d72012-04-23 16:46:01 -0700126 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -0700127 try {
128 return proxy_.OperatorName();
129 } catch (const DBus::Error &e) {
130 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
131 return string(); // Make the compiler happy.
132 }
Jason Glasgow74f5ef22012-03-29 16:15:04 -0400133}
134
135SimProxy::Proxy::Proxy(DBus::Connection *connection,
136 const string &path,
137 const string &service)
138 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
139
140SimProxy::Proxy::~Proxy() {}
141
142
143// Method callbacks inherited from
144// org::freedesktop::ModemManager1::SimProxy
145void SimProxy::Proxy::SendPinCallback(const ::DBus::Error &dberror,
146 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700147 SLOG(DBus, 2) << __func__;
Jason Glasgow74f5ef22012-03-29 16:15:04 -0400148 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
149 Error error;
150 CellularError::FromDBusError(dberror, &error);
151 callback->Run(error);
152}
153
154void SimProxy::Proxy::SendPukCallback(const ::DBus::Error &dberror,
mukesh agrawal06175d72012-04-23 16:46:01 -0700155 void *data) {
156 SLOG(DBus, 2) << __func__;
Jason Glasgow74f5ef22012-03-29 16:15:04 -0400157 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
158 Error error;
159 CellularError::FromDBusError(dberror, &error);
160 callback->Run(error);
161}
162
Gary Morainabb30da2012-05-08 16:59:59 -0700163void SimProxy::Proxy::EnablePinCallback(const ::DBus::Error &dberror,
164 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700165 SLOG(DBus, 2) << __func__;
Jason Glasgow74f5ef22012-03-29 16:15:04 -0400166 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
167 Error error;
168 CellularError::FromDBusError(dberror, &error);
169 callback->Run(error);
170}
171
Gary Morainabb30da2012-05-08 16:59:59 -0700172void SimProxy::Proxy::ChangePinCallback(const ::DBus::Error &dberror,
173 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700174 SLOG(DBus, 2) << __func__;
Jason Glasgow74f5ef22012-03-29 16:15:04 -0400175 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
176 Error error;
177 CellularError::FromDBusError(dberror, &error);
178 callback->Run(error);
179}
180
181} // namespace mm1
182} // namespace shill