Darin Petkov | b9c9933 | 2012-01-12 13:13:00 +0100 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 5 | #ifndef SHILL_CELLULAR_SERVICE_H_ |
| 6 | #define SHILL_CELLULAR_SERVICE_H_ |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 7 | |
| 8 | #include <map> |
| 9 | #include <string> |
| 10 | |
| 11 | #include <base/basictypes.h> |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 12 | #include <base/time.h> |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 13 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 14 | |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 15 | #include "shill/cellular.h" |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 16 | #include "shill/refptr_types.h" |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 17 | #include "shill/service.h" |
| 18 | |
| 19 | namespace shill { |
| 20 | |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 21 | class ControlInterface; |
Darin Petkov | b100ae7 | 2011-08-24 16:19:45 -0700 | [diff] [blame] | 22 | class Error; |
Chris Masone | 6791a43 | 2011-07-12 13:23:19 -0700 | [diff] [blame] | 23 | class EventDispatcher; |
| 24 | class Manager; |
| 25 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 26 | class CellularService : public Service { |
| 27 | public: |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 28 | // Online payment portal. |
| 29 | class OLP { |
| 30 | public: |
| 31 | OLP(); |
| 32 | ~OLP(); |
| 33 | |
| 34 | void CopyFrom(const OLP &olp); |
| 35 | bool Equals(const OLP &olp) const; |
| 36 | |
| 37 | const std::string &GetURL() const; |
| 38 | void SetURL(const std::string &url); |
| 39 | |
| 40 | const std::string &GetMethod() const; |
| 41 | void SetMethod(const std::string &method); |
| 42 | |
| 43 | const std::string &GetPostData() const; |
| 44 | void SetPostData(const std::string &post_data); |
| 45 | |
| 46 | const Stringmap &ToDict() const; |
| 47 | |
| 48 | private: |
| 49 | Stringmap dict_; |
| 50 | |
| 51 | DISALLOW_COPY_AND_ASSIGN(OLP); |
| 52 | }; |
| 53 | |
Prathmesh Prabhu | 0d36b4f | 2013-04-01 11:45:54 -0700 | [diff] [blame] | 54 | CellularService(ModemInfo *modem_info, |
mukesh agrawal | 51a7e93 | 2011-07-27 16:18:26 -0700 | [diff] [blame] | 55 | const CellularRefPtr &device); |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 56 | virtual ~CellularService(); |
| 57 | |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 58 | // Inherited from Service. |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 59 | virtual void AutoConnect(); |
mukesh agrawal | dc7b844 | 2012-09-27 13:48:14 -0700 | [diff] [blame] | 60 | virtual void Connect(Error *error, const char *reason); |
Darin Petkov | fb0625e | 2012-01-16 13:05:56 +0100 | [diff] [blame] | 61 | virtual void Disconnect(Error *error); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 62 | virtual void ActivateCellularModem(const std::string &carrier, |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 63 | Error *error, |
| 64 | const ResultCallback &callback); |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 65 | virtual void CompleteCellularActivation(Error *error); |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 66 | virtual void SetState(ConnectState new_state); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 67 | |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 68 | virtual std::string GetStorageIdentifier() const; |
| 69 | void SetStorageIdentifier(const std::string &identifier); |
Chris Masone | 34af218 | 2011-08-22 11:59:36 -0700 | [diff] [blame] | 70 | |
Ben Chan | 3d6de0e | 2012-12-10 12:01:34 -0800 | [diff] [blame] | 71 | void SetActivateOverNonCellularNetwork(bool state); |
| 72 | bool activate_over_non_cellular_network() const { |
| 73 | return activate_over_non_cellular_network_; |
| 74 | } |
| 75 | |
Arman Uguray | c7b1560 | 2013-02-16 00:56:18 -0800 | [diff] [blame] | 76 | virtual void SetActivationState(const std::string &state); |
Darin Petkov | c408e69 | 2011-08-17 13:47:15 -0700 | [diff] [blame] | 77 | const std::string &activation_state() const { return activation_state_; } |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 78 | |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 79 | void SetOLP(const OLP &olp); |
| 80 | const OLP &olp() const { return olp_; } |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 81 | |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 82 | void SetUsageURL(const std::string &url); |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 83 | const std::string &usage_url() const { return usage_url_; } |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 84 | |
Darin Petkov | 9cb0268 | 2012-01-28 00:17:38 +0100 | [diff] [blame] | 85 | void SetServingOperator(const Cellular::Operator &oper); |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 86 | const Cellular::Operator &serving_operator() const; |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 87 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 88 | // Sets network technology to |technology| and broadcasts the property change. |
| 89 | void SetNetworkTechnology(const std::string &technology); |
| 90 | const std::string &network_technology() const { return network_technology_; } |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 91 | |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 92 | // Sets roaming state to |state| and broadcasts the property change. |
| 93 | void SetRoamingState(const std::string &state); |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 94 | const std::string &roaming_state() const { return roaming_state_; } |
Darin Petkov | d204580 | 2011-08-23 11:09:25 -0700 | [diff] [blame] | 95 | |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 96 | bool is_auto_connecting() const { |
| 97 | return is_auto_connecting_; |
| 98 | } |
| 99 | |
mukesh agrawal | 3ffe52c | 2013-06-20 15:21:29 -0700 | [diff] [blame] | 100 | const std::string &ppp_username() const { return ppp_username_; } |
| 101 | const std::string &ppp_password() const { return ppp_password_; } |
| 102 | |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 103 | void set_enforce_out_of_credits_detection(bool state) { |
| 104 | enforce_out_of_credits_detection_ = state; |
| 105 | } |
mukesh agrawal | 81599e0 | 2013-04-22 16:40:00 -0700 | [diff] [blame] | 106 | bool out_of_credits() const { return out_of_credits_; } |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 107 | void SetOutOfCredits(bool state); |
| 108 | |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 109 | // Overrides Load and Save from parent Service class. We will call |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 110 | // the parent method. |
| 111 | virtual bool Load(StoreInterface *storage); |
| 112 | virtual bool Save(StoreInterface *storage); |
| 113 | |
| 114 | Stringmap *GetUserSpecifiedApn(); |
| 115 | Stringmap *GetLastGoodApn(); |
Jason Glasgow | 1452187 | 2012-05-07 19:12:15 -0400 | [diff] [blame] | 116 | virtual void SetLastGoodApn(const Stringmap &apn_info); |
| 117 | virtual void ClearLastGoodApn(); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 118 | |
Thieu Le | 99dc56d | 2013-04-01 14:22:21 -0700 | [diff] [blame] | 119 | virtual void OnAfterResume(); |
| 120 | |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 121 | protected: |
| 122 | // Overrides IsAutoConnectable from parent Service class. |
| 123 | virtual bool IsAutoConnectable(const char **reason) const; |
| 124 | |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 125 | private: |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 126 | friend class CellularCapabilityUniversalTest; |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 127 | friend class CellularServiceTest; |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 128 | FRIEND_TEST(CellularCapabilityGSMTest, SetupApnTryList); |
| 129 | FRIEND_TEST(CellularCapabilityTest, TryApns); |
Arman Uguray | 0a3e279 | 2013-01-17 16:31:50 -0800 | [diff] [blame] | 130 | FRIEND_TEST(CellularCapabilityUniversalMainTest, |
| 131 | UpdatePendingActivationState); |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 132 | FRIEND_TEST(CellularCapabilityUniversalMainTest, UpdateServiceName); |
| 133 | FRIEND_TEST(CellularCapabilityUniversalMainTest, UpdateStorageIdentifier); |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 134 | FRIEND_TEST(CellularTest, Connect); |
mukesh agrawal | 3ffe52c | 2013-06-20 15:21:29 -0700 | [diff] [blame] | 135 | FRIEND_TEST(CellularTest, GetLogin); // ppp_username_, ppp_password_ |
Arman Uguray | f84a424 | 2013-04-09 20:01:07 -0700 | [diff] [blame] | 136 | FRIEND_TEST(CellularTest, OnConnectionHealthCheckerResult); |
Eric Shienbrood | c707330 | 2012-04-03 14:41:44 -0400 | [diff] [blame] | 137 | FRIEND_TEST(CellularServiceTest, SetApn); |
| 138 | FRIEND_TEST(CellularServiceTest, ClearApn); |
| 139 | FRIEND_TEST(CellularServiceTest, LastGoodApn); |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 140 | FRIEND_TEST(CellularServiceTest, IsAutoConnectable); |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 141 | FRIEND_TEST(CellularServiceTest, OutOfCreditsDetected); |
Thieu Le | 99dc56d | 2013-04-01 14:22:21 -0700 | [diff] [blame] | 142 | FRIEND_TEST(CellularServiceTest, |
| 143 | OutOfCreditsDetectionNotSkippedAfterSlowResume); |
Thieu Le | 3a8683d | 2013-04-17 13:57:24 -0700 | [diff] [blame] | 144 | FRIEND_TEST(CellularServiceTest, OutOfCreditsDetectionSkippedAfterResume); |
| 145 | FRIEND_TEST(CellularServiceTest, |
| 146 | OutOfCreditsDetectionSkippedAlreadyOutOfCredits); |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 147 | FRIEND_TEST(CellularServiceTest, |
| 148 | OutOfCreditsDetectionSkippedExplicitDisconnect); |
| 149 | FRIEND_TEST(CellularServiceTest, OutOfCreditsNotDetectedConnectionNotDropped); |
| 150 | FRIEND_TEST(CellularServiceTest, OutOfCreditsNotDetectedIntermittentNetwork); |
| 151 | FRIEND_TEST(CellularServiceTest, OutOfCreditsNotEnforced); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 152 | FRIEND_TEST(CellularServiceTest, CustomSetterNoopChange); |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 153 | |
Christopher Wiley | 1582bdd | 2012-11-15 11:31:14 -0800 | [diff] [blame] | 154 | static const char kAutoConnActivating[]; |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 155 | static const char kAutoConnDeviceDisabled[]; |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 156 | static const char kAutoConnOutOfCredits[]; |
| 157 | static const char kAutoConnOutOfCreditsDetectionInProgress[]; |
| 158 | static const int64 kOutOfCreditsConnectionDropSeconds; |
| 159 | static const int kOutOfCreditsMaxConnectAttempts; |
Thieu Le | 99dc56d | 2013-04-01 14:22:21 -0700 | [diff] [blame] | 160 | static const int64 kOutOfCreditsResumeIgnoreSeconds; |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 161 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 162 | void HelpRegisterDerivedStringmap( |
| 163 | const std::string &name, |
| 164 | Stringmap(CellularService::*get)(Error *error), |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 165 | bool(CellularService::*set)(const Stringmap &value, Error *error)); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 166 | |
Gaurav Shah | 1b7a616 | 2011-11-09 11:41:01 -0800 | [diff] [blame] | 167 | virtual std::string GetDeviceRpcId(Error *error); |
Paul Stewart | ac4ac00 | 2011-08-26 12:04:26 -0700 | [diff] [blame] | 168 | |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 169 | Stringmap GetApn(Error *error); |
mukesh agrawal | bebf1b8 | 2013-04-23 15:06:33 -0700 | [diff] [blame] | 170 | bool SetApn(const Stringmap &value, Error *error); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 171 | static void SaveApn(StoreInterface *storage, |
| 172 | const std::string &storage_group, |
| 173 | const Stringmap *apn_info, |
| 174 | const std::string &keytag); |
| 175 | static void SaveApnField(StoreInterface *storage, |
| 176 | const std::string &storage_group, |
| 177 | const Stringmap *apn_info, |
| 178 | const std::string &keytag, |
| 179 | const std::string &apntag); |
| 180 | static void LoadApn(StoreInterface *storage, |
| 181 | const std::string &storage_group, |
| 182 | const std::string &keytag, |
| 183 | Stringmap *apn_info); |
| 184 | static bool LoadApnField(StoreInterface *storage, |
| 185 | const std::string &storage_group, |
| 186 | const std::string &keytag, |
| 187 | const std::string &apntag, |
| 188 | Stringmap *apn_info); |
| 189 | |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 190 | void PerformOutOfCreditsDetection(ConnectState curr_state, |
| 191 | ConnectState new_state); |
| 192 | void OutOfCreditsReconnect(); |
| 193 | void ResetOutOfCreditsState(); |
| 194 | |
| 195 | base::WeakPtrFactory<CellularService> weak_ptr_factory_; |
| 196 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 197 | // Properties |
Ben Chan | 3d6de0e | 2012-12-10 12:01:34 -0800 | [diff] [blame] | 198 | bool activate_over_non_cellular_network_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 199 | std::string activation_state_; |
Darin Petkov | 3335b37 | 2011-08-22 11:05:32 -0700 | [diff] [blame] | 200 | Cellular::Operator serving_operator_; |
Darin Petkov | b72cf40 | 2011-11-22 14:51:39 +0100 | [diff] [blame] | 201 | std::string network_technology_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 202 | std::string roaming_state_; |
Darin Petkov | 381928f | 2012-02-02 23:00:12 +0100 | [diff] [blame] | 203 | OLP olp_; |
Darin Petkov | b27e544 | 2011-08-16 14:36:45 -0700 | [diff] [blame] | 204 | std::string usage_url_; |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 205 | Stringmap apn_info_; |
| 206 | Stringmap last_good_apn_info_; |
mukesh agrawal | 3ffe52c | 2013-06-20 15:21:29 -0700 | [diff] [blame] | 207 | std::string ppp_username_; |
| 208 | std::string ppp_password_; |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 209 | |
Darin Petkov | 3133241 | 2012-01-28 01:50:02 +0100 | [diff] [blame] | 210 | std::string storage_identifier_; |
| 211 | |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 212 | CellularRefPtr cellular_; |
Darin Petkov | d966195 | 2011-08-03 16:25:42 -0700 | [diff] [blame] | 213 | |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 214 | // Flag indicating that a connect request is an auto-connect request. |
| 215 | // Note: Since Connect() is asynchronous, this flag is only set during the |
| 216 | // call to Connect(). It does not remain set while the async request is |
| 217 | // in flight. |
| 218 | bool is_auto_connecting_; |
| 219 | |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 220 | // Flag indicating whether we need to perform out-of-credits detection. |
| 221 | bool enforce_out_of_credits_detection_; |
| 222 | // Time when the last connect request started. |
| 223 | base::Time connect_start_time_; |
| 224 | // Number of connect attempts. |
| 225 | int num_connect_attempts_; |
| 226 | // Flag indicating whether out-of-credits detection is in progress. |
| 227 | bool out_of_credits_detection_in_progress_; |
| 228 | // Flag indicating if the SIM is out-of-credits. |
| 229 | bool out_of_credits_; |
Thieu Le | 99dc56d | 2013-04-01 14:22:21 -0700 | [diff] [blame] | 230 | // Time when the last resume occurred. |
| 231 | base::Time resume_start_time_; |
Thieu Le | 398b1da | 2013-03-11 17:31:10 -0700 | [diff] [blame] | 232 | |
Chris Masone | 3bd3c8c | 2011-06-13 08:20:26 -0700 | [diff] [blame] | 233 | DISALLOW_COPY_AND_ASSIGN(CellularService); |
| 234 | }; |
| 235 | |
| 236 | } // namespace shill |
| 237 | |
Ben Chan | 19f8397 | 2012-10-03 23:25:56 -0700 | [diff] [blame] | 238 | #endif // SHILL_CELLULAR_SERVICE_H_ |