Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 1 | // Copyright (c) 2011 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/cellular_capability_gsm.h" |
| 6 | |
| 7 | #include <base/logging.h> |
| 8 | |
| 9 | #include "shill/cellular.h" |
| 10 | #include "shill/proxy_factory.h" |
| 11 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 12 | using std::string; |
| 13 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 14 | namespace shill { |
| 15 | |
| 16 | CellularCapabilityGSM::CellularCapabilityGSM(Cellular *cellular) |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 17 | : CellularCapability(cellular), |
| 18 | task_factory_(this) {} |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 19 | |
| 20 | void CellularCapabilityGSM::InitProxies() { |
| 21 | VLOG(2) << __func__; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame^] | 22 | card_proxy_.reset( |
| 23 | proxy_factory()->CreateModemGSMCardProxy(this, |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 24 | cellular()->dbus_path(), |
| 25 | cellular()->dbus_owner())); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame^] | 26 | // TODO(petkov): Move GSM-specific proxy ownership from Cellular to this. |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 27 | cellular()->set_modem_gsm_network_proxy( |
| 28 | proxy_factory()->CreateModemGSMNetworkProxy(cellular(), |
| 29 | cellular()->dbus_path(), |
| 30 | cellular()->dbus_owner())); |
| 31 | } |
| 32 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame^] | 33 | void CellularCapabilityGSM::GetIdentifiers() { |
| 34 | VLOG(2) << __func__; |
| 35 | if (cellular()->imei().empty()) { |
| 36 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 37 | cellular()->set_imei(card_proxy_->GetIMEI()); |
| 38 | VLOG(2) << "IMEI: " << cellular()->imei(); |
| 39 | } |
| 40 | if (cellular()->imsi().empty()) { |
| 41 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 42 | cellular()->set_imsi(card_proxy_->GetIMSI()); |
| 43 | VLOG(2) << "IMSI: " << cellular()->imsi(); |
| 44 | } |
| 45 | if (cellular()->spn().empty()) { |
| 46 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 47 | try { |
| 48 | cellular()->set_spn(card_proxy_->GetSPN()); |
| 49 | VLOG(2) << "SPN: " << cellular()->spn(); |
| 50 | } catch (const DBus::Error e) { |
| 51 | // Some modems don't support this call so catch the exception explicitly. |
| 52 | LOG(WARNING) << "Unable to obtain SPN: " << e.what(); |
| 53 | } |
| 54 | } |
| 55 | if (cellular()->mdn().empty()) { |
| 56 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 57 | cellular()->set_mdn(card_proxy_->GetMSISDN()); |
| 58 | VLOG(2) << "MSISDN/MDN: " << cellular()->mdn(); |
| 59 | } |
| 60 | } |
| 61 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 62 | void CellularCapabilityGSM::RequirePIN( |
| 63 | const string &pin, bool require, Error */*error*/) { |
| 64 | VLOG(2) << __func__ << "(" << pin << ", " << require << ")"; |
| 65 | // Defer because we may be in a dbus-c++ callback. |
| 66 | dispatcher()->PostTask( |
| 67 | task_factory_.NewRunnableMethod( |
| 68 | &CellularCapabilityGSM::RequirePINTask, pin, require)); |
| 69 | } |
| 70 | |
| 71 | void CellularCapabilityGSM::RequirePINTask(const string &pin, bool require) { |
| 72 | VLOG(2) << __func__ << "(" << pin << ", " << require << ")"; |
| 73 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame^] | 74 | card_proxy_->EnablePIN(pin, require); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void CellularCapabilityGSM::EnterPIN(const string &pin, Error */*error*/) { |
| 78 | VLOG(2) << __func__ << "(" << pin << ")"; |
| 79 | // Defer because we may be in a dbus-c++ callback. |
| 80 | dispatcher()->PostTask( |
| 81 | task_factory_.NewRunnableMethod( |
| 82 | &CellularCapabilityGSM::EnterPINTask, pin)); |
| 83 | } |
| 84 | |
| 85 | void CellularCapabilityGSM::EnterPINTask(const string &pin) { |
| 86 | VLOG(2) << __func__ << "(" << pin << ")"; |
| 87 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame^] | 88 | card_proxy_->SendPIN(pin); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | void CellularCapabilityGSM::UnblockPIN( |
| 92 | const string &unblock_code, const string &pin, Error */*error*/) { |
| 93 | VLOG(2) << __func__ << "(" << unblock_code << ", " << pin << ")"; |
| 94 | // Defer because we may be in a dbus-c++ callback. |
| 95 | dispatcher()->PostTask( |
| 96 | task_factory_.NewRunnableMethod( |
| 97 | &CellularCapabilityGSM::UnblockPINTask, unblock_code, pin)); |
| 98 | } |
| 99 | |
| 100 | void CellularCapabilityGSM::UnblockPINTask( |
| 101 | const string &unblock_code, const string &pin) { |
| 102 | VLOG(2) << __func__ << "(" << unblock_code << ", " << pin << ")"; |
| 103 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame^] | 104 | card_proxy_->SendPUK(unblock_code, pin); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void CellularCapabilityGSM::ChangePIN( |
| 108 | const string &old_pin, const string &new_pin, Error */*error*/) { |
| 109 | VLOG(2) << __func__ << "(" << old_pin << ", " << new_pin << ")"; |
| 110 | // Defer because we may be in a dbus-c++ callback. |
| 111 | dispatcher()->PostTask( |
| 112 | task_factory_.NewRunnableMethod( |
| 113 | &CellularCapabilityGSM::ChangePINTask, old_pin, new_pin)); |
| 114 | } |
| 115 | |
| 116 | void CellularCapabilityGSM::ChangePINTask( |
| 117 | const string &old_pin, const string &new_pin) { |
| 118 | VLOG(2) << __func__ << "(" << old_pin << ", " << new_pin << ")"; |
| 119 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame^] | 120 | card_proxy_->ChangePIN(old_pin, new_pin); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 121 | } |
| 122 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 123 | } // namespace shill |