blob: 4fa1f5cec9ed34e8ce55b03a868e76fc6de82701 [file] [log] [blame]
Darin Petkovdaf43862011-10-27 11:37:28 +02001// 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 Petkov20c13ec2011-11-09 15:07:15 +01008#include <chromeos/dbus/service_constants.h>
9#include <mm/mm-modem.h>
Darin Petkovdaf43862011-10-27 11:37:28 +020010
11#include "shill/cellular.h"
12#include "shill/proxy_factory.h"
13
Darin Petkovb05315f2011-11-07 10:14:25 +010014using std::string;
15
Darin Petkovdaf43862011-10-27 11:37:28 +020016namespace shill {
17
18CellularCapabilityGSM::CellularCapabilityGSM(Cellular *cellular)
Darin Petkovb05315f2011-11-07 10:14:25 +010019 : CellularCapability(cellular),
20 task_factory_(this) {}
Darin Petkovdaf43862011-10-27 11:37:28 +020021
22void CellularCapabilityGSM::InitProxies() {
23 VLOG(2) << __func__;
Darin Petkovcb547732011-11-09 13:55:26 +010024 card_proxy_.reset(
25 proxy_factory()->CreateModemGSMCardProxy(this,
Darin Petkovdaf43862011-10-27 11:37:28 +020026 cellular()->dbus_path(),
27 cellular()->dbus_owner()));
Darin Petkovcb547732011-11-09 13:55:26 +010028 // TODO(petkov): Move GSM-specific proxy ownership from Cellular to this.
Darin Petkovdaf43862011-10-27 11:37:28 +020029 cellular()->set_modem_gsm_network_proxy(
30 proxy_factory()->CreateModemGSMNetworkProxy(cellular(),
31 cellular()->dbus_path(),
32 cellular()->dbus_owner()));
33}
34
Darin Petkovcb547732011-11-09 13:55:26 +010035void 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 Petkovb05315f2011-11-07 10:14:25 +010064void 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
73void CellularCapabilityGSM::RequirePINTask(const string &pin, bool require) {
74 VLOG(2) << __func__ << "(" << pin << ", " << require << ")";
75 // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583).
Darin Petkovcb547732011-11-09 13:55:26 +010076 card_proxy_->EnablePIN(pin, require);
Darin Petkovb05315f2011-11-07 10:14:25 +010077}
78
79void 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
87void CellularCapabilityGSM::EnterPINTask(const string &pin) {
88 VLOG(2) << __func__ << "(" << pin << ")";
89 // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583).
Darin Petkovcb547732011-11-09 13:55:26 +010090 card_proxy_->SendPIN(pin);
Darin Petkovb05315f2011-11-07 10:14:25 +010091}
92
93void 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
102void 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 Petkovcb547732011-11-09 13:55:26 +0100106 card_proxy_->SendPUK(unblock_code, pin);
Darin Petkovb05315f2011-11-07 10:14:25 +0100107}
108
109void 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
118void 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 Petkovcb547732011-11-09 13:55:26 +0100122 card_proxy_->ChangePIN(old_pin, new_pin);
Darin Petkovb05315f2011-11-07 10:14:25 +0100123}
124
Darin Petkov20c13ec2011-11-09 15:07:15 +0100125string 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
153string 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 Petkovdaf43862011-10-27 11:37:28 +0200165} // namespace shill