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 | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame^] | 64 | void CellularCapabilityGSM::GetSignalQuality() { |
| 65 | VLOG(2) << __func__; |
| 66 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
| 67 | uint32 strength = cellular()->modem_gsm_network_proxy()->GetSignalQuality(); |
| 68 | cellular()->HandleNewSignalQuality(strength); |
| 69 | } |
| 70 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 71 | void CellularCapabilityGSM::RequirePIN( |
| 72 | const string &pin, bool require, Error */*error*/) { |
| 73 | VLOG(2) << __func__ << "(" << pin << ", " << require << ")"; |
| 74 | // Defer because we may be in a dbus-c++ callback. |
| 75 | dispatcher()->PostTask( |
| 76 | task_factory_.NewRunnableMethod( |
| 77 | &CellularCapabilityGSM::RequirePINTask, pin, require)); |
| 78 | } |
| 79 | |
| 80 | void CellularCapabilityGSM::RequirePINTask(const string &pin, bool require) { |
| 81 | VLOG(2) << __func__ << "(" << pin << ", " << require << ")"; |
| 82 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 83 | card_proxy_->EnablePIN(pin, require); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void CellularCapabilityGSM::EnterPIN(const string &pin, Error */*error*/) { |
| 87 | VLOG(2) << __func__ << "(" << pin << ")"; |
| 88 | // Defer because we may be in a dbus-c++ callback. |
| 89 | dispatcher()->PostTask( |
| 90 | task_factory_.NewRunnableMethod( |
| 91 | &CellularCapabilityGSM::EnterPINTask, pin)); |
| 92 | } |
| 93 | |
| 94 | void CellularCapabilityGSM::EnterPINTask(const string &pin) { |
| 95 | VLOG(2) << __func__ << "(" << pin << ")"; |
| 96 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 97 | card_proxy_->SendPIN(pin); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | void CellularCapabilityGSM::UnblockPIN( |
| 101 | const string &unblock_code, const string &pin, Error */*error*/) { |
| 102 | VLOG(2) << __func__ << "(" << unblock_code << ", " << pin << ")"; |
| 103 | // Defer because we may be in a dbus-c++ callback. |
| 104 | dispatcher()->PostTask( |
| 105 | task_factory_.NewRunnableMethod( |
| 106 | &CellularCapabilityGSM::UnblockPINTask, unblock_code, pin)); |
| 107 | } |
| 108 | |
| 109 | void CellularCapabilityGSM::UnblockPINTask( |
| 110 | const string &unblock_code, const string &pin) { |
| 111 | VLOG(2) << __func__ << "(" << unblock_code << ", " << pin << ")"; |
| 112 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 113 | card_proxy_->SendPUK(unblock_code, pin); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void CellularCapabilityGSM::ChangePIN( |
| 117 | const string &old_pin, const string &new_pin, Error */*error*/) { |
| 118 | VLOG(2) << __func__ << "(" << old_pin << ", " << new_pin << ")"; |
| 119 | // Defer because we may be in a dbus-c++ callback. |
| 120 | dispatcher()->PostTask( |
| 121 | task_factory_.NewRunnableMethod( |
| 122 | &CellularCapabilityGSM::ChangePINTask, old_pin, new_pin)); |
| 123 | } |
| 124 | |
| 125 | void CellularCapabilityGSM::ChangePINTask( |
| 126 | const string &old_pin, const string &new_pin) { |
| 127 | VLOG(2) << __func__ << "(" << old_pin << ", " << new_pin << ")"; |
| 128 | // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583). |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 129 | card_proxy_->ChangePIN(old_pin, new_pin); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 130 | } |
| 131 | |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 132 | string CellularCapabilityGSM::GetNetworkTechnologyString() const { |
| 133 | if (cellular()->gsm_registration_state() == |
| 134 | MM_MODEM_GSM_NETWORK_REG_STATUS_HOME || |
| 135 | cellular()->gsm_registration_state() == |
| 136 | MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING) { |
| 137 | switch (cellular()->gsm_access_technology()) { |
| 138 | case MM_MODEM_GSM_ACCESS_TECH_GSM: |
| 139 | case MM_MODEM_GSM_ACCESS_TECH_GSM_COMPACT: |
| 140 | return flimflam::kNetworkTechnologyGsm; |
| 141 | case MM_MODEM_GSM_ACCESS_TECH_GPRS: |
| 142 | return flimflam::kNetworkTechnologyGprs; |
| 143 | case MM_MODEM_GSM_ACCESS_TECH_EDGE: |
| 144 | return flimflam::kNetworkTechnologyEdge; |
| 145 | case MM_MODEM_GSM_ACCESS_TECH_UMTS: |
| 146 | return flimflam::kNetworkTechnologyUmts; |
| 147 | case MM_MODEM_GSM_ACCESS_TECH_HSDPA: |
| 148 | case MM_MODEM_GSM_ACCESS_TECH_HSUPA: |
| 149 | case MM_MODEM_GSM_ACCESS_TECH_HSPA: |
| 150 | return flimflam::kNetworkTechnologyHspa; |
| 151 | case MM_MODEM_GSM_ACCESS_TECH_HSPA_PLUS: |
| 152 | return flimflam::kNetworkTechnologyHspaPlus; |
| 153 | default: |
| 154 | NOTREACHED(); |
| 155 | } |
| 156 | } |
| 157 | return ""; |
| 158 | } |
| 159 | |
| 160 | string CellularCapabilityGSM::GetRoamingStateString() const { |
| 161 | switch (cellular()->gsm_registration_state()) { |
| 162 | case MM_MODEM_GSM_NETWORK_REG_STATUS_HOME: |
| 163 | return flimflam::kRoamingStateHome; |
| 164 | case MM_MODEM_GSM_NETWORK_REG_STATUS_ROAMING: |
| 165 | return flimflam::kRoamingStateRoaming; |
| 166 | default: |
| 167 | break; |
| 168 | } |
| 169 | return flimflam::kRoamingStateUnknown; |
| 170 | } |
| 171 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 172 | } // namespace shill |