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 | #ifndef SHILL_CELLULAR_CAPABILITY_GSM_ |
| 6 | #define SHILL_CELLULAR_CAPABILITY_GSM_ |
| 7 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 8 | #include <base/memory/scoped_ptr.h> |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 9 | #include <base/task.h> |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 10 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 11 | |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 12 | #include "shill/accessor_interface.h" |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 13 | #include "shill/cellular.h" |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 14 | #include "shill/cellular_capability.h" |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 15 | #include "shill/modem_gsm_card_proxy_interface.h" |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 16 | #include "shill/modem_gsm_network_proxy_interface.h" |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 17 | |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 18 | struct mobile_provider; |
| 19 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 20 | namespace shill { |
| 21 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 22 | class CellularCapabilityGSM : public CellularCapability, |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 23 | public ModemGSMCardProxyDelegate, |
| 24 | public ModemGSMNetworkProxyDelegate { |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 25 | public: |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 26 | static const char kPropertyUnlockRequired[]; |
| 27 | static const char kPropertyUnlockRetries[]; |
| 28 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 29 | CellularCapabilityGSM(Cellular *cellular); |
| 30 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 31 | // Inherited from CellularCapability. |
Darin Petkov | 5f316f6 | 2011-11-18 12:10:26 +0100 | [diff] [blame] | 32 | virtual void OnDeviceStarted(); |
| 33 | virtual void OnDeviceStopped(); |
| 34 | virtual void OnServiceCreated(); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 35 | virtual void UpdateStatus(const DBusPropertiesMap &properties); |
| 36 | virtual void SetupConnectProperties(DBusPropertiesMap *properties); |
Darin Petkov | 3e50924 | 2011-11-10 14:46:44 +0100 | [diff] [blame] | 37 | virtual void GetSignalQuality(); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 38 | virtual void GetRegistrationState(); |
| 39 | virtual void GetProperties(); |
| 40 | virtual void Register(); |
| 41 | virtual void RegisterOnNetwork(const std::string &network_id, Error *error); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 42 | 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 Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 50 | virtual void Scan(Error *error); |
Darin Petkov | 20c13ec | 2011-11-09 15:07:15 +0100 | [diff] [blame] | 51 | virtual std::string GetNetworkTechnologyString() const; |
| 52 | virtual std::string GetRoamingStateString() const; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 53 | virtual void OnModemManagerPropertiesChanged( |
| 54 | const DBusPropertiesMap &properties); |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 55 | |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 56 | // Obtains the IMEI, IMSI, SPN and MSISDN. |
| 57 | virtual void GetIdentifiers(); |
| 58 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 59 | const std::string &spn() const { return spn_; } |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 60 | 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 Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 64 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 65 | private: |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 66 | friend class CellularCapabilityGSMTest; |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame^] | 67 | FRIEND_TEST(CellularCapabilityGSMTest, InitAPNList); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 68 | FRIEND_TEST(CellularCapabilityGSMTest, ParseScanResult); |
| 69 | FRIEND_TEST(CellularCapabilityGSMTest, ParseScanResultProviderLookup); |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 70 | FRIEND_TEST(CellularCapabilityGSMTest, RegisterOnNetwork); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 71 | FRIEND_TEST(CellularCapabilityGSMTest, Scan); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 72 | FRIEND_TEST(CellularCapabilityGSMTest, SetAccessTechnology); |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 73 | FRIEND_TEST(CellularCapabilityGSMTest, SetHomeProvider); |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 74 | FRIEND_TEST(CellularCapabilityGSMTest, UpdateOperatorInfo); |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 75 | |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 76 | 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 Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 87 | 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 Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 92 | static const char kPhoneNumber[]; |
| 93 | static const char kPropertyAccessTechnology[]; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 94 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 95 | void RegisterOnNetworkTask(const std::string &network_id); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 96 | 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 Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 100 | void ScanTask(); |
| 101 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 102 | void SetAccessTechnology(uint32 access_technology); |
| 103 | |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 104 | // Sets the upper level information about the home cellular provider from the |
| 105 | // modem's IMSI and SPN. |
| 106 | void SetHomeProvider(); |
| 107 | |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 108 | // 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 Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame^] | 115 | // Initializes the |apn_list_| property based on the current |home_provider_|. |
| 116 | void InitAPNList(); |
| 117 | |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 118 | Stringmap ParseScanResult( |
| 119 | const ModemGSMNetworkProxyInterface::ScanResult &result); |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 120 | |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 121 | 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 Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 128 | // 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 Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 135 | scoped_ptr<ModemGSMCardProxyInterface> card_proxy_; |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 136 | scoped_ptr<ModemGSMNetworkProxyInterface> network_proxy_; |
Darin Petkov | cb54773 | 2011-11-09 13:55:26 +0100 | [diff] [blame] | 137 | |
Darin Petkov | b05315f | 2011-11-07 10:14:25 +0100 | [diff] [blame] | 138 | ScopedRunnableMethodFactory<CellularCapabilityGSM> task_factory_; |
| 139 | |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 140 | uint32 registration_state_; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 141 | uint32 access_technology_; |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 142 | Cellular::Operator serving_operator_; |
Darin Petkov | ae0c64e | 2011-11-15 15:50:27 +0100 | [diff] [blame] | 143 | std::string spn_; |
Darin Petkov | 0a4dfeb | 2011-11-18 19:36:13 +0100 | [diff] [blame] | 144 | mobile_provider *home_provider_; |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 145 | |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 146 | // Properties. |
Darin Petkov | 184c54e | 2011-11-15 12:44:39 +0100 | [diff] [blame] | 147 | std::string selected_network_; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 148 | Stringmaps found_networks_; |
| 149 | bool scanning_; |
| 150 | uint16 scan_interval_; |
Darin Petkov | 721ac93 | 2011-11-16 15:43:09 +0100 | [diff] [blame] | 151 | SimLockStatus sim_lock_status_; |
Darin Petkov | 3cfbf21 | 2011-11-21 16:02:09 +0100 | [diff] [blame^] | 152 | Stringmaps apn_list_; |
Darin Petkov | 1272a43 | 2011-11-10 15:53:37 +0100 | [diff] [blame] | 153 | |
Darin Petkov | daf4386 | 2011-10-27 11:37:28 +0200 | [diff] [blame] | 154 | DISALLOW_COPY_AND_ASSIGN(CellularCapabilityGSM); |
| 155 | }; |
| 156 | |
| 157 | } // namespace shill |
| 158 | |
| 159 | #endif // SHILL_CELLULAR_CAPABILITY_GSM_ |