blob: 45e9fb46587d94f44b96c05e0f14de79c03a6424 [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#ifndef SHILL_CELLULAR_CAPABILITY_GSM_
6#define SHILL_CELLULAR_CAPABILITY_GSM_
7
Darin Petkovcb547732011-11-09 13:55:26 +01008#include <base/memory/scoped_ptr.h>
Darin Petkovb05315f2011-11-07 10:14:25 +01009#include <base/task.h>
Darin Petkov1272a432011-11-10 15:53:37 +010010#include <gtest/gtest_prod.h> // for FRIEND_TEST
Darin Petkovb05315f2011-11-07 10:14:25 +010011
Darin Petkov1272a432011-11-10 15:53:37 +010012#include "shill/accessor_interface.h"
Darin Petkov0a4dfeb2011-11-18 19:36:13 +010013#include "shill/cellular.h"
Darin Petkovdaf43862011-10-27 11:37:28 +020014#include "shill/cellular_capability.h"
Darin Petkovcb547732011-11-09 13:55:26 +010015#include "shill/modem_gsm_card_proxy_interface.h"
Darin Petkov1272a432011-11-10 15:53:37 +010016#include "shill/modem_gsm_network_proxy_interface.h"
Darin Petkovdaf43862011-10-27 11:37:28 +020017
Darin Petkov0a4dfeb2011-11-18 19:36:13 +010018struct mobile_provider;
19
Darin Petkovdaf43862011-10-27 11:37:28 +020020namespace shill {
21
Darin Petkovcb547732011-11-09 13:55:26 +010022class CellularCapabilityGSM : public CellularCapability,
Darin Petkov184c54e2011-11-15 12:44:39 +010023 public ModemGSMCardProxyDelegate,
24 public ModemGSMNetworkProxyDelegate {
Darin Petkovdaf43862011-10-27 11:37:28 +020025 public:
Darin Petkov721ac932011-11-16 15:43:09 +010026 static const char kPropertyUnlockRequired[];
27 static const char kPropertyUnlockRetries[];
28
Darin Petkovdaf43862011-10-27 11:37:28 +020029 CellularCapabilityGSM(Cellular *cellular);
30
Darin Petkovb05315f2011-11-07 10:14:25 +010031 // Inherited from CellularCapability.
Darin Petkov5f316f62011-11-18 12:10:26 +010032 virtual void OnDeviceStarted();
33 virtual void OnDeviceStopped();
34 virtual void OnServiceCreated();
Darin Petkovae0c64e2011-11-15 15:50:27 +010035 virtual void UpdateStatus(const DBusPropertiesMap &properties);
36 virtual void SetupConnectProperties(DBusPropertiesMap *properties);
Darin Petkov3e509242011-11-10 14:46:44 +010037 virtual void GetSignalQuality();
Darin Petkov184c54e2011-11-15 12:44:39 +010038 virtual void GetRegistrationState();
39 virtual void GetProperties();
40 virtual void Register();
41 virtual void RegisterOnNetwork(const std::string &network_id, Error *error);
Darin Petkovb05315f2011-11-07 10:14:25 +010042 virtual void RequirePIN(const std::string &pin, bool require, Error *error);
43 virtual void EnterPIN(const std::string &pin, Error *error);
44 virtual void UnblockPIN(const std::string &unblock_code,
45 const std::string &pin,
46 Error *error);
47 virtual void ChangePIN(const std::string &old_pin,
48 const std::string &new_pin,
49 Error *error);
Darin Petkov1272a432011-11-10 15:53:37 +010050 virtual void Scan(Error *error);
Darin Petkov20c13ec2011-11-09 15:07:15 +010051 virtual std::string GetNetworkTechnologyString() const;
52 virtual std::string GetRoamingStateString() const;
Darin Petkovae0c64e2011-11-15 15:50:27 +010053 virtual void OnModemManagerPropertiesChanged(
54 const DBusPropertiesMap &properties);
Darin Petkovdaf43862011-10-27 11:37:28 +020055
Darin Petkovcb547732011-11-09 13:55:26 +010056 // Obtains the IMEI, IMSI, SPN and MSISDN.
57 virtual void GetIdentifiers();
58
Darin Petkovae0c64e2011-11-15 15:50:27 +010059 const std::string &spn() const { return spn_; }
Darin Petkov721ac932011-11-16 15:43:09 +010060 const std::string &sim_lock_type() const {
61 return sim_lock_status_.lock_type;
62 }
63 uint32 sim_lock_retries_left() const { return sim_lock_status_.retries_left; }
Darin Petkovae0c64e2011-11-15 15:50:27 +010064
Darin Petkovdaf43862011-10-27 11:37:28 +020065 private:
Darin Petkovcb547732011-11-09 13:55:26 +010066 friend class CellularCapabilityGSMTest;
Darin Petkov3cfbf212011-11-21 16:02:09 +010067 FRIEND_TEST(CellularCapabilityGSMTest, InitAPNList);
Darin Petkov1272a432011-11-10 15:53:37 +010068 FRIEND_TEST(CellularCapabilityGSMTest, ParseScanResult);
69 FRIEND_TEST(CellularCapabilityGSMTest, ParseScanResultProviderLookup);
Darin Petkov184c54e2011-11-15 12:44:39 +010070 FRIEND_TEST(CellularCapabilityGSMTest, RegisterOnNetwork);
Darin Petkov1272a432011-11-10 15:53:37 +010071 FRIEND_TEST(CellularCapabilityGSMTest, Scan);
Darin Petkovae0c64e2011-11-15 15:50:27 +010072 FRIEND_TEST(CellularCapabilityGSMTest, SetAccessTechnology);
Darin Petkov0a4dfeb2011-11-18 19:36:13 +010073 FRIEND_TEST(CellularCapabilityGSMTest, SetHomeProvider);
Darin Petkovae0c64e2011-11-15 15:50:27 +010074 FRIEND_TEST(CellularCapabilityGSMTest, UpdateOperatorInfo);
Darin Petkov1272a432011-11-10 15:53:37 +010075
Darin Petkov721ac932011-11-16 15:43:09 +010076 struct SimLockStatus {
77 public:
78 SimLockStatus() : retries_left(0) {}
79 SimLockStatus(const std::string &in_lock_type, uint32 in_retries_left)
80 : lock_type(in_lock_type),
81 retries_left(in_retries_left) {}
82
83 std::string lock_type;
84 uint32 retries_left;
85 };
86
Darin Petkov1272a432011-11-10 15:53:37 +010087 static const char kNetworkPropertyAccessTechnology[];
88 static const char kNetworkPropertyID[];
89 static const char kNetworkPropertyLongName[];
90 static const char kNetworkPropertyShortName[];
91 static const char kNetworkPropertyStatus[];
Darin Petkovae0c64e2011-11-15 15:50:27 +010092 static const char kPhoneNumber[];
93 static const char kPropertyAccessTechnology[];
Darin Petkovcb547732011-11-09 13:55:26 +010094
Darin Petkov184c54e2011-11-15 12:44:39 +010095 void RegisterOnNetworkTask(const std::string &network_id);
Darin Petkovb05315f2011-11-07 10:14:25 +010096 void RequirePINTask(const std::string &pin, bool require);
97 void EnterPINTask(const std::string &pin);
98 void UnblockPINTask(const std::string &unblock_code, const std::string &pin);
99 void ChangePINTask(const std::string &old_pin, const std::string &new_pin);
Darin Petkov1272a432011-11-10 15:53:37 +0100100 void ScanTask();
101
Darin Petkovae0c64e2011-11-15 15:50:27 +0100102 void SetAccessTechnology(uint32 access_technology);
103
Darin Petkov0a4dfeb2011-11-18 19:36:13 +0100104 // Sets the upper level information about the home cellular provider from the
105 // modem's IMSI and SPN.
106 void SetHomeProvider();
107
Darin Petkovae0c64e2011-11-15 15:50:27 +0100108 // Updates the GSM operator name and country based on a newly obtained network
109 // id.
110 void UpdateOperatorInfo();
111
112 // Updates the serving operator on the active service.
113 void UpdateServingOperator();
114
Darin Petkov3cfbf212011-11-21 16:02:09 +0100115 // Initializes the |apn_list_| property based on the current |home_provider_|.
116 void InitAPNList();
117
Darin Petkov1272a432011-11-10 15:53:37 +0100118 Stringmap ParseScanResult(
119 const ModemGSMNetworkProxyInterface::ScanResult &result);
Darin Petkovb05315f2011-11-07 10:14:25 +0100120
Darin Petkov721ac932011-11-16 15:43:09 +0100121 StrIntPair SimLockStatusToProperty(Error *error);
122
123 void HelpRegisterDerivedStrIntPair(
124 const std::string &name,
125 StrIntPair(CellularCapabilityGSM::*get)(Error *),
126 void(CellularCapabilityGSM::*set)(const StrIntPair&, Error *));
127
Darin Petkov184c54e2011-11-15 12:44:39 +0100128 // Signal callbacks inherited from ModemGSMNetworkProxyDelegate.
129 virtual void OnGSMNetworkModeChanged(uint32 mode);
130 virtual void OnGSMRegistrationInfoChanged(uint32 status,
131 const std::string &operator_code,
132 const std::string &operator_name);
133 virtual void OnGSMSignalQualityChanged(uint32 quality);
134
Darin Petkovcb547732011-11-09 13:55:26 +0100135 scoped_ptr<ModemGSMCardProxyInterface> card_proxy_;
Darin Petkov184c54e2011-11-15 12:44:39 +0100136 scoped_ptr<ModemGSMNetworkProxyInterface> network_proxy_;
Darin Petkovcb547732011-11-09 13:55:26 +0100137
Darin Petkovb05315f2011-11-07 10:14:25 +0100138 ScopedRunnableMethodFactory<CellularCapabilityGSM> task_factory_;
139
Darin Petkov184c54e2011-11-15 12:44:39 +0100140 uint32 registration_state_;
Darin Petkovae0c64e2011-11-15 15:50:27 +0100141 uint32 access_technology_;
Darin Petkov0a4dfeb2011-11-18 19:36:13 +0100142 Cellular::Operator serving_operator_;
Darin Petkovae0c64e2011-11-15 15:50:27 +0100143 std::string spn_;
Darin Petkov0a4dfeb2011-11-18 19:36:13 +0100144 mobile_provider *home_provider_;
Darin Petkov184c54e2011-11-15 12:44:39 +0100145
Darin Petkov1272a432011-11-10 15:53:37 +0100146 // Properties.
Darin Petkov184c54e2011-11-15 12:44:39 +0100147 std::string selected_network_;
Darin Petkov1272a432011-11-10 15:53:37 +0100148 Stringmaps found_networks_;
149 bool scanning_;
150 uint16 scan_interval_;
Darin Petkov721ac932011-11-16 15:43:09 +0100151 SimLockStatus sim_lock_status_;
Darin Petkov3cfbf212011-11-21 16:02:09 +0100152 Stringmaps apn_list_;
Darin Petkov1272a432011-11-10 15:53:37 +0100153
Darin Petkovdaf43862011-10-27 11:37:28 +0200154 DISALLOW_COPY_AND_ASSIGN(CellularCapabilityGSM);
155};
156
157} // namespace shill
158
159#endif // SHILL_CELLULAR_CAPABILITY_GSM_