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> |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame^] | 8 | #include <chromeos/dbus/service_constants.h> |
| 9 | #include <mm/mm-modem.h> |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 10 | |
| 11 | #include "shill/cellular.h" |
| 12 | #include "shill/proxy_factory.h" |
| 13 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 14 | using std::string; |
| 15 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 16 | namespace shill { |
| 17 | |
| 18 | CellularCapabilityGSM::CellularCapabilityGSM(Cellular *cellular) |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 19 | : CellularCapability(cellular), |
| 20 | task_factory_(this) {} |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 21 | |
| 22 | void CellularCapabilityGSM::InitProxies() { |
| 23 | VLOG(2) << __func__; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 24 | card_proxy_.reset( |
| 25 | proxy_factory()->CreateModemGSMCardProxy(this, |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 26 | cellular()->dbus_path(), |
| 27 | cellular()->dbus_owner())); |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 28 | // TODO(petkov): Move GSM-specific proxy ownership from Cellular to this. |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 29 | cellular()->set_modem_gsm_network_proxy( |
| 30 | proxy_factory()->CreateModemGSMNetworkProxy(cellular(), |
| 31 | cellular()->dbus_path(), |
| 32 | cellular()->dbus_owner())); |
| 33 | } |
| 34 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 35 | void CellularCapabilityGSM::GetIdentifiers() { |
| 36 | VLOG(2) << __func__; |
| 37 | if (cellular()->imei().empty()) { |
| 38 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 39 | cellular()->set_imei(card_proxy_->GetIMEI()); |
| 40 | VLOG(2) << "IMEI: " << cellular()->imei(); |
| 41 | } |
| 42 | if (cellular()->imsi().empty()) { |
| 43 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 44 | cellular()->set_imsi(card_proxy_->GetIMSI()); |
| 45 | VLOG(2) << "IMSI: " << cellular()->imsi(); |
| 46 | } |
| 47 | if (cellular()->spn().empty()) { |
| 48 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 49 | try { |
| 50 | cellular()->set_spn(card_proxy_->GetSPN()); |
| 51 | VLOG(2) << "SPN: " << cellular()->spn(); |
| 52 | } catch (const DBus::Error e) { |
| 53 | // Some modems don't support this call so catch the exception explicitly. |
| 54 | LOG(WARNING) << "Unable to obtain SPN: " << e.what(); |
| 55 | } |
| 56 | } |
| 57 | if (cellular()->mdn().empty()) { |
| 58 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 59 | cellular()->set_mdn(card_proxy_->GetMSISDN()); |
| 60 | VLOG(2) << "MSISDN/MDN: " << cellular()->mdn(); |
| 61 | } |
| 62 | } |
| 63 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 64 | void CellularCapabilityGSM::RequirePIN( |
| 65 | const string &pin, bool require, Error */*error*/) { |
| 66 | VLOG(2) << __func__ << "(" << pin << ", " << require << ")"; |
| 67 | // Defer because we may be in a dbus-c++ callback. |
| 68 | dispatcher()->PostTask( |
| 69 | task_factory_.NewRunnableMethod( |
| 70 | &CellularCapabilityGSM::RequirePINTask, pin, require)); |
| 71 | } |
| 72 | |
| 73 | void CellularCapabilityGSM::RequirePINTask(const string &pin, bool require) { |
| 74 | VLOG(2) << __func__ << "(" << pin << ", " << require << ")"; |
| 75 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 76 | card_proxy_->EnablePIN(pin, require); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void CellularCapabilityGSM::EnterPIN(const string &pin, Error */*error*/) { |
| 80 | VLOG(2) << __func__ << "(" << pin << ")"; |
| 81 | // Defer because we may be in a dbus-c++ callback. |
| 82 | dispatcher()->PostTask( |
| 83 | task_factory_.NewRunnableMethod( |
| 84 | &CellularCapabilityGSM::EnterPINTask, pin)); |
| 85 | } |
| 86 | |
| 87 | void CellularCapabilityGSM::EnterPINTask(const string &pin) { |
| 88 | VLOG(2) << __func__ << "(" << pin << ")"; |
| 89 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 90 | card_proxy_->SendPIN(pin); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | void CellularCapabilityGSM::UnblockPIN( |
| 94 | const string &unblock_code, const string &pin, Error */*error*/) { |
| 95 | VLOG(2) << __func__ << "(" << unblock_code << ", " << pin << ")"; |
| 96 | // Defer because we may be in a dbus-c++ callback. |
| 97 | dispatcher()->PostTask( |
| 98 | task_factory_.NewRunnableMethod( |
| 99 | &CellularCapabilityGSM::UnblockPINTask, unblock_code, pin)); |
| 100 | } |
| 101 | |
| 102 | void CellularCapabilityGSM::UnblockPINTask( |
| 103 | const string &unblock_code, const string &pin) { |
| 104 | VLOG(2) << __func__ << "(" << unblock_code << ", " << pin << ")"; |
| 105 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 106 | card_proxy_->SendPUK(unblock_code, pin); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | void CellularCapabilityGSM::ChangePIN( |
| 110 | const string &old_pin, const string &new_pin, Error */*error*/) { |
| 111 | VLOG(2) << __func__ << "(" << old_pin << ", " << new_pin << ")"; |
| 112 | // Defer because we may be in a dbus-c++ callback. |
| 113 | dispatcher()->PostTask( |
| 114 | task_factory_.NewRunnableMethod( |
| 115 | &CellularCapabilityGSM::ChangePINTask, old_pin, new_pin)); |
| 116 | } |
| 117 | |
| 118 | void CellularCapabilityGSM::ChangePINTask( |
| 119 | const string &old_pin, const string &new_pin) { |
| 120 | VLOG(2) << __func__ << "(" << old_pin << ", " << new_pin << ")"; |
| 121 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 122 | card_proxy_->ChangePIN(old_pin, new_pin); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 123 | } |
| 124 | |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame^] | 125 | string CellularCapabilityGSM::GetNetworkTechnologyString() const { |
| 126 | if (cellular()->gsm_registration_state() == |
| 127 | MM_MODEM_GSM_NETWORK_REG_STATUS_HOME || |
| 128 | cellular()->gsm_registration_state() == |
| 129 | MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING) { |
| 130 | switch (cellular()->gsm_access_technology()) { |
| 131 | case MM_MODEM_GSM_ACCESS_TECH_GSM: |
| 132 | case MM_MODEM_GSM_ACCESS_TECH_GSM_COMPACT: |
| 133 | return flimflam::kNetworkTechnologyGsm; |
| 134 | case MM_MODEM_GSM_ACCESS_TECH_GPRS: |
| 135 | return flimflam::kNetworkTechnologyGprs; |
| 136 | case MM_MODEM_GSM_ACCESS_TECH_EDGE: |
| 137 | return flimflam::kNetworkTechnologyEdge; |
| 138 | case MM_MODEM_GSM_ACCESS_TECH_UMTS: |
| 139 | return flimflam::kNetworkTechnologyUmts; |
| 140 | case MM_MODEM_GSM_ACCESS_TECH_HSDPA: |
| 141 | case MM_MODEM_GSM_ACCESS_TECH_HSUPA: |
| 142 | case MM_MODEM_GSM_ACCESS_TECH_HSPA: |
| 143 | return flimflam::kNetworkTechnologyHspa; |
| 144 | case MM_MODEM_GSM_ACCESS_TECH_HSPA_PLUS: |
| 145 | return flimflam::kNetworkTechnologyHspaPlus; |
| 146 | default: |
| 147 | NOTREACHED(); |
| 148 | } |
| 149 | } |
| 150 | return ""; |
| 151 | } |
| 152 | |
| 153 | string CellularCapabilityGSM::GetRoamingStateString() const { |
| 154 | switch (cellular()->gsm_registration_state()) { |
| 155 | case MM_MODEM_GSM_NETWORK_REG_STATUS_HOME: |
| 156 | return flimflam::kRoamingStateHome; |
| 157 | case MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING: |
| 158 | return flimflam::kRoamingStateRoaming; |
| 159 | default: |
| 160 | break; |
| 161 | } |
| 162 | return flimflam::kRoamingStateUnknown; |
| 163 | } |
| 164 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 165 | } // namespace shill |