blob: 1862e3e82fbf0f9e714f701406bfda5c743bade5 [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>
8
9#include "shill/cellular.h"
10#include "shill/proxy_factory.h"
11
Darin Petkovb05315f2011-11-07 10:14:25 +010012using std::string;
13
Darin Petkovdaf43862011-10-27 11:37:28 +020014namespace shill {
15
16CellularCapabilityGSM::CellularCapabilityGSM(Cellular *cellular)
Darin Petkovb05315f2011-11-07 10:14:25 +010017 : CellularCapability(cellular),
18 task_factory_(this) {}
Darin Petkovdaf43862011-10-27 11:37:28 +020019
20void CellularCapabilityGSM::InitProxies() {
21 VLOG(2) << __func__;
Darin Petkovcb547732011-11-09 13:55:26 +010022 card_proxy_.reset(
23 proxy_factory()->CreateModemGSMCardProxy(this,
Darin Petkovdaf43862011-10-27 11:37:28 +020024 cellular()->dbus_path(),
25 cellular()->dbus_owner()));
Darin Petkovcb547732011-11-09 13:55:26 +010026 // TODO(petkov): Move GSM-specific proxy ownership from Cellular to this.
Darin Petkovdaf43862011-10-27 11:37:28 +020027 cellular()->set_modem_gsm_network_proxy(
28 proxy_factory()->CreateModemGSMNetworkProxy(cellular(),
29 cellular()->dbus_path(),
30 cellular()->dbus_owner()));
31}
32
Darin Petkovcb547732011-11-09 13:55:26 +010033void 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 Petkovb05315f2011-11-07 10:14:25 +010062void 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
71void CellularCapabilityGSM::RequirePINTask(const string &pin, bool require) {
72 VLOG(2) << __func__ << "(" << pin << ", " << require << ")";
73 // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583).
Darin Petkovcb547732011-11-09 13:55:26 +010074 card_proxy_->EnablePIN(pin, require);
Darin Petkovb05315f2011-11-07 10:14:25 +010075}
76
77void 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
85void CellularCapabilityGSM::EnterPINTask(const string &pin) {
86 VLOG(2) << __func__ << "(" << pin << ")";
87 // TODO(petkov): Switch to asynchronous calls (crosbug.com/17583).
Darin Petkovcb547732011-11-09 13:55:26 +010088 card_proxy_->SendPIN(pin);
Darin Petkovb05315f2011-11-07 10:14:25 +010089}
90
91void 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
100void 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 Petkovcb547732011-11-09 13:55:26 +0100104 card_proxy_->SendPUK(unblock_code, pin);
Darin Petkovb05315f2011-11-07 10:14:25 +0100105}
106
107void 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
116void 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 Petkovcb547732011-11-09 13:55:26 +0100120 card_proxy_->ChangePIN(old_pin, new_pin);
Darin Petkovb05315f2011-11-07 10:14:25 +0100121}
122
Darin Petkovdaf43862011-10-27 11:37:28 +0200123} // namespace shill