Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 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/modem_gsm_card_proxy.h" |
| 6 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 7 | #include <base/bind.h> |
| 8 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 9 | #include "shill/cellular_error.h" |
| 10 | #include "shill/error.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 11 | #include "shill/logging.h" |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 12 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 13 | using base::Bind; |
| 14 | using base::Callback; |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 15 | using std::string; |
| 16 | |
| 17 | namespace shill { |
| 18 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 19 | ModemGSMCardProxy::ModemGSMCardProxy(DBus::Connection *connection, |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 20 | const string &path, |
| 21 | const string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 22 | : proxy_(connection, path, service) {} |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 23 | |
| 24 | ModemGSMCardProxy::~ModemGSMCardProxy() {} |
| 25 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 26 | void ModemGSMCardProxy::GetIMEI(Error *error, |
| 27 | const GSMIdentifierCallback &callback, |
| 28 | int timeout) { |
| 29 | scoped_ptr<GSMIdentifierCallback> cb(new GSMIdentifierCallback(callback)); |
| 30 | try { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 31 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 32 | proxy_.GetImei(cb.get(), timeout); |
| 33 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 34 | } catch (const DBus::Error &e) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 35 | if (error) |
| 36 | CellularError::FromDBusError(e, error); |
| 37 | } |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 40 | void ModemGSMCardProxy::GetIMSI(Error *error, |
| 41 | const GSMIdentifierCallback &callback, |
| 42 | int timeout) { |
| 43 | scoped_ptr<GSMIdentifierCallback> cb(new GSMIdentifierCallback(callback)); |
| 44 | try { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 45 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 46 | proxy_.GetImsi(cb.get(), timeout); |
| 47 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 48 | } catch (const DBus::Error &e) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 49 | if (error) |
| 50 | CellularError::FromDBusError(e, error); |
| 51 | } |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 54 | void ModemGSMCardProxy::GetSPN(Error *error, |
| 55 | const GSMIdentifierCallback &callback, |
| 56 | int timeout) { |
| 57 | scoped_ptr<GSMIdentifierCallback> cb(new GSMIdentifierCallback(callback)); |
| 58 | try { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 59 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 60 | proxy_.GetSpn(cb.get(), timeout); |
| 61 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 62 | } catch (const DBus::Error &e) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 63 | if (error) |
| 64 | CellularError::FromDBusError(e, error); |
| 65 | } |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 66 | } |
| 67 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 68 | void ModemGSMCardProxy::GetMSISDN(Error *error, |
| 69 | const GSMIdentifierCallback &callback, |
| 70 | int timeout) { |
| 71 | scoped_ptr<GSMIdentifierCallback> cb(new GSMIdentifierCallback(callback)); |
| 72 | try { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 73 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 74 | proxy_.GetMsIsdn(cb.get(), timeout); |
| 75 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 76 | } catch (const DBus::Error &e) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 77 | if (error) |
| 78 | CellularError::FromDBusError(e, error); |
| 79 | } |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 82 | void ModemGSMCardProxy::EnablePIN(const string &pin, bool enabled, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 83 | Error *error, |
| 84 | const ResultCallback &callback, |
| 85 | int timeout) { |
| 86 | scoped_ptr<ResultCallback> cb(new ResultCallback(callback)); |
| 87 | try { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 88 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 89 | proxy_.EnablePin(pin, enabled, cb.get(), timeout); |
| 90 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 91 | } catch (const DBus::Error &e) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 92 | if (error) |
| 93 | CellularError::FromDBusError(e, error); |
| 94 | } |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 97 | void ModemGSMCardProxy::SendPIN(const string &pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 98 | Error *error, |
| 99 | const ResultCallback &callback, |
| 100 | int timeout) { |
| 101 | scoped_ptr<ResultCallback> cb(new ResultCallback(callback)); |
| 102 | try { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 103 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 104 | proxy_.SendPin(pin, cb.get(), timeout); |
| 105 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 106 | } catch (const DBus::Error &e) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 107 | if (error) |
| 108 | CellularError::FromDBusError(e, error); |
| 109 | } |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 112 | void ModemGSMCardProxy::SendPUK(const string &puk, const string &pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 113 | Error *error, |
| 114 | const ResultCallback &callback, |
| 115 | int timeout) { |
| 116 | scoped_ptr<ResultCallback> cb(new ResultCallback(callback)); |
| 117 | try { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 118 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 119 | proxy_.SendPuk(puk, pin, cb.get(), timeout); |
| 120 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 121 | } catch (const DBus::Error &e) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 122 | if (error) |
| 123 | CellularError::FromDBusError(e, error); |
| 124 | } |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | void ModemGSMCardProxy::ChangePIN(const string &old_pin, |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 128 | const string &new_pin, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 129 | Error *error, |
| 130 | const ResultCallback &callback, |
| 131 | int timeout) { |
| 132 | scoped_ptr<ResultCallback> cb(new ResultCallback(callback)); |
| 133 | try { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 134 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 135 | proxy_.ChangePin(old_pin, new_pin, cb.get(), timeout); |
| 136 | cb.release(); |
Ben Chan | 80326f3 | 2012-05-04 17:51:32 -0700 | [diff] [blame] | 137 | } catch (const DBus::Error &e) { |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 138 | if (error) |
| 139 | CellularError::FromDBusError(e, error); |
| 140 | } |
Darin Petkov | e42e101 | 2011-08-31 12:35:04 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Darin Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 143 | uint32 ModemGSMCardProxy::EnabledFacilityLocks() { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 144 | SLOG(DBus, 2) << __func__; |
Gary Morain | 610977f | 2012-05-04 16:03:52 -0700 | [diff] [blame] | 145 | 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 Petkov | 63138a9 | 2012-02-06 14:09:15 +0100 | [diff] [blame] | 151 | } |
| 152 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 153 | ModemGSMCardProxy::Proxy::Proxy(DBus::Connection *connection, |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 154 | const string &path, |
| 155 | const string &service) |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 156 | : DBus::ObjectProxy(*connection, path, service.c_str()) {} |
| 157 | |
| 158 | void ModemGSMCardProxy::Proxy::GetIdCallback(const string &id, |
| 159 | const DBus::Error &dberror, |
| 160 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 161 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 162 | scoped_ptr<GSMIdentifierCallback> callback( |
| 163 | reinterpret_cast<GSMIdentifierCallback *>(data)); |
| 164 | Error error; |
| 165 | CellularError::FromDBusError(dberror, &error); |
| 166 | callback->Run(id, error); |
| 167 | } |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 168 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 169 | void ModemGSMCardProxy::Proxy::GetImeiCallback(const string &imei, |
| 170 | const DBus::Error &dberror, |
| 171 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 172 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 173 | GetIdCallback(imei, dberror, data); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | void ModemGSMCardProxy::Proxy::GetImsiCallback(const string &imsi, |
| 177 | const DBus::Error &dberror, |
| 178 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 179 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 180 | GetIdCallback(imsi, dberror, data); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | void ModemGSMCardProxy::Proxy::GetSpnCallback(const string &spn, |
| 184 | const DBus::Error &dberror, |
| 185 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 186 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 187 | GetIdCallback(spn, dberror, data); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 188 | } |
| 189 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 190 | void ModemGSMCardProxy::Proxy::GetMsIsdnCallback(const string &msisdn, |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 191 | const DBus::Error &dberror, |
| 192 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 193 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 194 | GetIdCallback(msisdn, dberror, data); |
| 195 | } |
| 196 | |
| 197 | void ModemGSMCardProxy::Proxy::PinCallback(const DBus::Error &dberror, |
| 198 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 199 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 200 | scoped_ptr<ResultCallback> callback(reinterpret_cast<ResultCallback *>(data)); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 201 | Error error; |
| 202 | CellularError::FromDBusError(dberror, &error); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 203 | callback->Run(error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | void ModemGSMCardProxy::Proxy::EnablePinCallback(const DBus::Error &dberror, |
| 207 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 208 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 209 | PinCallback(dberror, data); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | void ModemGSMCardProxy::Proxy::SendPinCallback(const DBus::Error &dberror, |
| 213 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 214 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 215 | PinCallback(dberror, data); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | void ModemGSMCardProxy::Proxy::SendPukCallback(const DBus::Error &dberror, |
| 219 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 220 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 221 | PinCallback(dberror, data); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | void ModemGSMCardProxy::Proxy::ChangePinCallback(const DBus::Error &dberror, |
| 225 | void *data) { |
mukesh agrawal | 06175d7 | 2012-04-23 16:46:01 -0700 | [diff] [blame] | 226 | SLOG(DBus, 2) << __func__; |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 227 | PinCallback(dberror, data); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 228 | } |
| 229 | |
Darin Petkov | 975b5e7 | 2011-08-30 11:48:08 -0700 | [diff] [blame] | 230 | ModemGSMCardProxy::Proxy::~Proxy() {} |
| 231 | |
| 232 | } // namespace shill |