blob: c06f7c4ea32d694b7f8f488e86003984327eaf46 [file] [log] [blame]
Eric Shienbrood5de44ab2011-12-05 10:46:27 -05001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkov975b5e72011-08-30 11:48:08 -07002// 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/modem_gsm_card_proxy.h"
6
Eric Shienbrood9a245532012-03-07 14:20:39 -05007#include <base/bind.h>
8
Eric Shienbrood5de44ab2011-12-05 10:46:27 -05009#include "shill/cellular_error.h"
10#include "shill/error.h"
mukesh agrawal06175d72012-04-23 16:46:01 -070011#include "shill/scope_logger.h"
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050012
Eric Shienbrood9a245532012-03-07 14:20:39 -050013using base::Bind;
14using base::Callback;
Darin Petkov975b5e72011-08-30 11:48:08 -070015using std::string;
16
17namespace shill {
18
Eric Shienbrood9a245532012-03-07 14:20:39 -050019ModemGSMCardProxy::ModemGSMCardProxy(DBus::Connection *connection,
Darin Petkov975b5e72011-08-30 11:48:08 -070020 const string &path,
21 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -050022 : proxy_(connection, path, service) {}
Darin Petkov975b5e72011-08-30 11:48:08 -070023
24ModemGSMCardProxy::~ModemGSMCardProxy() {}
25
Eric Shienbrood9a245532012-03-07 14:20:39 -050026void ModemGSMCardProxy::GetIMEI(Error *error,
27 const GSMIdentifierCallback &callback,
28 int timeout) {
29 scoped_ptr<GSMIdentifierCallback> cb(new GSMIdentifierCallback(callback));
30 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070031 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050032 proxy_.GetImei(cb.get(), timeout);
33 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070034 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050035 if (error)
36 CellularError::FromDBusError(e, error);
37 }
Darin Petkov975b5e72011-08-30 11:48:08 -070038}
39
Eric Shienbrood9a245532012-03-07 14:20:39 -050040void ModemGSMCardProxy::GetIMSI(Error *error,
41 const GSMIdentifierCallback &callback,
42 int timeout) {
43 scoped_ptr<GSMIdentifierCallback> cb(new GSMIdentifierCallback(callback));
44 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070045 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050046 proxy_.GetImsi(cb.get(), timeout);
47 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070048 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050049 if (error)
50 CellularError::FromDBusError(e, error);
51 }
Darin Petkov975b5e72011-08-30 11:48:08 -070052}
53
Eric Shienbrood9a245532012-03-07 14:20:39 -050054void ModemGSMCardProxy::GetSPN(Error *error,
55 const GSMIdentifierCallback &callback,
56 int timeout) {
57 scoped_ptr<GSMIdentifierCallback> cb(new GSMIdentifierCallback(callback));
58 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070059 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050060 proxy_.GetSpn(cb.get(), timeout);
61 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070062 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050063 if (error)
64 CellularError::FromDBusError(e, error);
65 }
Darin Petkov975b5e72011-08-30 11:48:08 -070066}
67
Eric Shienbrood9a245532012-03-07 14:20:39 -050068void ModemGSMCardProxy::GetMSISDN(Error *error,
69 const GSMIdentifierCallback &callback,
70 int timeout) {
71 scoped_ptr<GSMIdentifierCallback> cb(new GSMIdentifierCallback(callback));
72 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070073 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050074 proxy_.GetMsIsdn(cb.get(), timeout);
75 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070076 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050077 if (error)
78 CellularError::FromDBusError(e, error);
79 }
Darin Petkov975b5e72011-08-30 11:48:08 -070080}
81
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050082void ModemGSMCardProxy::EnablePIN(const string &pin, bool enabled,
Eric Shienbrood9a245532012-03-07 14:20:39 -050083 Error *error,
84 const ResultCallback &callback,
85 int timeout) {
86 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
87 try {
mukesh agrawal06175d72012-04-23 16:46:01 -070088 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -050089 proxy_.EnablePin(pin, enabled, cb.get(), timeout);
90 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -070091 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -050092 if (error)
93 CellularError::FromDBusError(e, error);
94 }
Darin Petkove42e1012011-08-31 12:35:04 -070095}
96
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050097void ModemGSMCardProxy::SendPIN(const string &pin,
Eric Shienbrood9a245532012-03-07 14:20:39 -050098 Error *error,
99 const ResultCallback &callback,
100 int timeout) {
101 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
102 try {
mukesh agrawal06175d72012-04-23 16:46:01 -0700103 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500104 proxy_.SendPin(pin, cb.get(), timeout);
105 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -0700106 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500107 if (error)
108 CellularError::FromDBusError(e, error);
109 }
Darin Petkove42e1012011-08-31 12:35:04 -0700110}
111
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500112void ModemGSMCardProxy::SendPUK(const string &puk, const string &pin,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500113 Error *error,
114 const ResultCallback &callback,
115 int timeout) {
116 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
117 try {
mukesh agrawal06175d72012-04-23 16:46:01 -0700118 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500119 proxy_.SendPuk(puk, pin, cb.get(), timeout);
120 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -0700121 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500122 if (error)
123 CellularError::FromDBusError(e, error);
124 }
Darin Petkove42e1012011-08-31 12:35:04 -0700125}
126
127void ModemGSMCardProxy::ChangePIN(const string &old_pin,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500128 const string &new_pin,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500129 Error *error,
130 const ResultCallback &callback,
131 int timeout) {
132 scoped_ptr<ResultCallback> cb(new ResultCallback(callback));
133 try {
mukesh agrawal06175d72012-04-23 16:46:01 -0700134 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500135 proxy_.ChangePin(old_pin, new_pin, cb.get(), timeout);
136 cb.release();
Ben Chan80326f32012-05-04 17:51:32 -0700137 } catch (const DBus::Error &e) {
Eric Shienbrood9a245532012-03-07 14:20:39 -0500138 if (error)
139 CellularError::FromDBusError(e, error);
140 }
Darin Petkove42e1012011-08-31 12:35:04 -0700141}
142
Darin Petkov63138a92012-02-06 14:09:15 +0100143uint32 ModemGSMCardProxy::EnabledFacilityLocks() {
mukesh agrawal06175d72012-04-23 16:46:01 -0700144 SLOG(DBus, 2) << __func__;
Gary Morain610977f2012-05-04 16:03:52 -0700145 try {
146 return proxy_.EnabledFacilityLocks();
147 } catch (const DBus::Error &e) {
148 LOG(FATAL) << "DBus exception: " << e.name() << ": " << e.what();
149 return 0; // Make the compiler happy.
150 }
Darin Petkov63138a92012-02-06 14:09:15 +0100151}
152
Eric Shienbrood9a245532012-03-07 14:20:39 -0500153ModemGSMCardProxy::Proxy::Proxy(DBus::Connection *connection,
Darin Petkov975b5e72011-08-30 11:48:08 -0700154 const string &path,
155 const string &service)
Eric Shienbrood9a245532012-03-07 14:20:39 -0500156 : DBus::ObjectProxy(*connection, path, service.c_str()) {}
157
158void ModemGSMCardProxy::Proxy::GetIdCallback(const string &id,
159 const DBus::Error &dberror,
160 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700161 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500162 scoped_ptr<GSMIdentifierCallback> callback(
163 reinterpret_cast<GSMIdentifierCallback *>(data));
164 Error error;
165 CellularError::FromDBusError(dberror, &error);
166 callback->Run(id, error);
167}
Darin Petkov975b5e72011-08-30 11:48:08 -0700168
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500169void ModemGSMCardProxy::Proxy::GetImeiCallback(const string &imei,
170 const DBus::Error &dberror,
171 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700172 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500173 GetIdCallback(imei, dberror, data);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500174}
175
176void ModemGSMCardProxy::Proxy::GetImsiCallback(const string &imsi,
177 const DBus::Error &dberror,
178 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700179 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500180 GetIdCallback(imsi, dberror, data);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500181}
182
183void ModemGSMCardProxy::Proxy::GetSpnCallback(const string &spn,
184 const DBus::Error &dberror,
185 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700186 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500187 GetIdCallback(spn, dberror, data);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500188}
189
Eric Shienbrood9a245532012-03-07 14:20:39 -0500190void ModemGSMCardProxy::Proxy::GetMsIsdnCallback(const string &msisdn,
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500191 const DBus::Error &dberror,
192 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700193 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500194 GetIdCallback(msisdn, dberror, data);
195}
196
197void ModemGSMCardProxy::Proxy::PinCallback(const DBus::Error &dberror,
198 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700199 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500200 scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data));
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500201 Error error;
202 CellularError::FromDBusError(dberror, &error);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500203 callback->Run(error);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500204}
205
206void ModemGSMCardProxy::Proxy::EnablePinCallback(const DBus::Error &dberror,
207 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700208 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500209 PinCallback(dberror, data);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500210}
211
212void ModemGSMCardProxy::Proxy::SendPinCallback(const DBus::Error &dberror,
213 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700214 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500215 PinCallback(dberror, data);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500216}
217
218void ModemGSMCardProxy::Proxy::SendPukCallback(const DBus::Error &dberror,
219 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700220 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500221 PinCallback(dberror, data);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500222}
223
224void ModemGSMCardProxy::Proxy::ChangePinCallback(const DBus::Error &dberror,
225 void *data) {
mukesh agrawal06175d72012-04-23 16:46:01 -0700226 SLOG(DBus, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500227 PinCallback(dberror, data);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -0500228}
229
Darin Petkov975b5e72011-08-30 11:48:08 -0700230ModemGSMCardProxy::Proxy::~Proxy() {}
231
232} // namespace shill