Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 1 | // Copyright (c) 2014 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 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 5 | #ifndef SHILL_MOBILE_OPERATOR_INFO_H_ |
| 6 | #define SHILL_MOBILE_OPERATOR_INFO_H_ |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
Ben Chan | 11c213f | 2014-09-05 08:21:06 -0700 | [diff] [blame] | 11 | #include <base/files/file_util.h> |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 12 | #include <base/memory/scoped_ptr.h> |
| 13 | #include <base/memory/scoped_vector.h> |
| 14 | |
| 15 | namespace shill { |
| 16 | |
| 17 | class EventDispatcher; |
| 18 | class MobileOperatorInfoImpl; |
| 19 | |
| 20 | // An MobileOperatorInfo object encapsulates the knowledge pertaining to all |
| 21 | // mobile operators. Typical usage consists of three steps: |
| 22 | // - Initialize the object, set database file paths for the operator |
| 23 | // information. |
| 24 | // - Add observers to be notified whenever an M[V]NO has been determined / any |
| 25 | // information about the M[V]NO changes. |
| 26 | // - Send operator information updates to the object. |
| 27 | // |
| 28 | // So a class Foo that wants to use this object typically looks like: |
| 29 | // |
| 30 | // class Foo { |
| 31 | // class OperatorObserver : public MobileOperatorInfoObserver { |
| 32 | // // Implement all Observer functions. |
| 33 | // } |
| 34 | // ... |
| 35 | // |
| 36 | // MobileOperatorInfo operator_info; |
| 37 | // // Optional: Set a non-default database file. |
| 38 | // operator_info.ClearDatabasePaths(); |
| 39 | // operator_info.AddDatabasePath(some_path); |
| 40 | // |
| 41 | // operator_info.Init(); // Required. |
| 42 | // |
| 43 | // OperatorObserver my_observer; |
| 44 | // operator_info.AddObserver(my_observer); |
| 45 | // ... |
| 46 | // operator_info.UpdateIMSI(some_imsi); |
| 47 | // operator_info.UpdateName(some_name); |
| 48 | // ... |
| 49 | // // Whenever enough information is available, |operator_info| notifies us |
| 50 | // through |my_observer|. |
| 51 | // }; |
| 52 | // |
| 53 | class MobileOperatorInfo { |
| 54 | public: |
| 55 | class Observer { |
| 56 | public: |
Ben Chan | 5ea763b | 2014-08-13 11:07:54 -0700 | [diff] [blame] | 57 | virtual ~Observer() {} |
| 58 | |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 59 | // This event fires when |
| 60 | // - A mobile [virtual] network operator |
| 61 | // - is first determined. |
| 62 | // - changes. |
| 63 | // - becomes invalid. |
| 64 | // - Some information about the known operator changes. |
| 65 | virtual void OnOperatorChanged() = 0; |
| 66 | }; |
| 67 | |
| 68 | // |Init| must be called on the constructed object before it is used. |
| 69 | // This object does not take ownership of dispatcher, and |dispatcher| is |
| 70 | // expected to outlive this object. |
Miao-chen Chou | 70190b3 | 2014-05-14 18:24:30 -0700 | [diff] [blame] | 71 | MobileOperatorInfo(EventDispatcher *dispatcher, |
| 72 | const std::string &info_owner); |
Prathmesh Prabhu | 95afcbb | 2014-04-08 16:05:42 -0700 | [diff] [blame] | 73 | virtual ~MobileOperatorInfo(); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 74 | |
| 75 | // These functions can be called before Init to read non default database |
| 76 | // file(s). |
| 77 | void ClearDatabasePaths(); |
| 78 | void AddDatabasePath(const base::FilePath &absolute_path); |
| 79 | |
Prathmesh Prabhu | 347ff6d | 2014-05-09 09:28:02 -0700 | [diff] [blame] | 80 | std::string GetLogPrefix(const char *func) const; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 81 | bool Init(); |
| 82 | |
| 83 | // Add/remove observers to subscribe to notifications. |
| 84 | void AddObserver(MobileOperatorInfo::Observer *observer); |
| 85 | void RemoveObserver(MobileOperatorInfo::Observer *observer); |
| 86 | |
| 87 | // /////////////////////////////////////////////////////////////////////////// |
| 88 | // Objects that encapsulate related information about the mobile operator. |
| 89 | |
| 90 | // Encapsulates a name and the language that name has been localized to. |
| 91 | // The name can be a carrier name, or the name that a cellular carrier |
| 92 | // prefers to show for a certain access point. |
| 93 | struct LocalizedName { |
| 94 | // The name as it appears in the corresponding language. |
| 95 | std::string name; |
| 96 | // The language of this localized name. The format of a language is a two |
| 97 | // letter language code, e.g. 'en' for English. |
| 98 | // It is legal for an instance of LocalizedName to have an empty |language| |
| 99 | // field, as sometimes the underlying database does not contain that |
| 100 | // information. |
| 101 | std::string language; |
| 102 | }; |
| 103 | |
| 104 | // Encapsulates information on a mobile access point name. This information |
| 105 | // is usually necessary for 3GPP networks to be able to connect to a mobile |
| 106 | // network. So far, CDMA networks don't use this information. |
| 107 | struct MobileAPN { |
| 108 | // The access point url, which is fed to the modemmanager while connecting. |
| 109 | std::string apn; |
| 110 | // A list of localized names for this access point. Usually there is only |
| 111 | // one for each country that the associated cellular carrier operates in. |
| 112 | std::vector<LocalizedName> operator_name_list; |
| 113 | // The username and password fields that are required by the modemmanager. |
| 114 | // Either of these values can be empty if none is present. If a MobileAPN |
| 115 | // instance that is obtained from this parser contains a non-empty value |
| 116 | // for username/password, this usually means that the carrier requires |
| 117 | // a certain default pair. |
| 118 | std::string username; |
| 119 | std::string password; |
| 120 | }; |
| 121 | |
| 122 | // Encapsulates information about the Online payment portal used by chrome to |
| 123 | // redirect users for some carriers. |
| 124 | struct OnlinePortal { |
| 125 | std::string url; |
| 126 | std::string method; |
| 127 | std::string post_data; |
| 128 | }; |
| 129 | |
| 130 | // /////////////////////////////////////////////////////////////////////////// |
| 131 | // Functions to obtain information about the current mobile operator. |
| 132 | // Any of these accessors can return an emtpy response if the information is |
| 133 | // not available. Use |IsMobileNetworkOperatorKnown| and |
| 134 | // |IsMobileVirtualNetworkOperatorKnown| to determine if a fix on the operator |
| 135 | // has been made. Note that the information returned by the other accessors is |
| 136 | // only valid when at least |IsMobileNetworkOperatorKnown| returns true. Their |
| 137 | // values are undefined otherwise. |
| 138 | |
| 139 | // Query whether a mobile network operator has been successfully determined. |
Prathmesh Prabhu | 95afcbb | 2014-04-08 16:05:42 -0700 | [diff] [blame] | 140 | virtual bool IsMobileNetworkOperatorKnown() const; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 141 | // Query whether a mobile network operator has been successfully |
| 142 | // determined. |
| 143 | bool IsMobileVirtualNetworkOperatorKnown() const; |
| 144 | |
| 145 | |
| 146 | // The unique identifier of this carrier. This is primarily used to |
| 147 | // identify the user profile in store for each carrier. This identifier is |
| 148 | // access technology agnostic and should be the same across 3GPP and CDMA. |
Prathmesh Prabhu | 401a5b9 | 2014-04-29 17:37:55 -0700 | [diff] [blame] | 149 | virtual const std::string &uuid() const; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 150 | |
Prathmesh Prabhu | 95afcbb | 2014-04-08 16:05:42 -0700 | [diff] [blame] | 151 | virtual const std::string &operator_name() const; |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 152 | virtual const std::string &country() const; |
Prathmesh Prabhu | 95afcbb | 2014-04-08 16:05:42 -0700 | [diff] [blame] | 153 | virtual const std::string &mccmnc() const; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 154 | const std::string &sid() const; |
| 155 | const std::string &nid() const; |
| 156 | |
| 157 | // A given MVNO can be associated with multiple mcc/mnc pairs. A list of all |
| 158 | // associated mcc/mnc pairs concatenated together. |
| 159 | const std::vector<std::string> &mccmnc_list() const; |
| 160 | // A given MVNO can be associated with multiple sid(s). A list of all |
| 161 | // associated sid(s). |
| 162 | // There are likely many SID values associated with a CDMA carrier as they |
| 163 | // vary across regions and are more fine grained than countries. An important |
| 164 | // thing to keep in mind is that, since an SID contains fine grained |
| 165 | // information on where a modem is physically located, it should be regarded |
| 166 | // as user-sensitive information. |
| 167 | const std::vector<std::string> &sid_list() const; |
| 168 | // All localized names associated with this carrier entry. |
| 169 | const std::vector<LocalizedName> &operator_name_list() const; |
| 170 | // All access point names associated with this carrier entry. |
| 171 | const ScopedVector<MobileAPN> &apn_list() const; |
| 172 | // All Online Payment Portal URLs associated with this carrier entry. There |
| 173 | // are usually multiple OLPs based on access technology and it is up to the |
| 174 | // application to use the appropriate one. |
Prathmesh Prabhu | 92df619 | 2014-04-29 18:08:08 -0700 | [diff] [blame] | 175 | virtual const std::vector<OnlinePortal> &olp_list() const; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 176 | |
| 177 | // The number to dial for automatic activation. |
Prathmesh Prabhu | f228821 | 2014-05-21 19:19:19 -0700 | [diff] [blame] | 178 | virtual const std::string &activation_code() const; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 179 | // Some carriers are only available while roaming. This is mainly used by |
| 180 | // Chrome. |
| 181 | bool requires_roaming() const; |
| 182 | |
| 183 | // /////////////////////////////////////////////////////////////////////////// |
| 184 | // Functions used to notify this object of operator data changes. |
| 185 | // The Update* methods update the corresponding property of the network |
| 186 | // operator, and this value may be used to determine the M[V]NO. |
| 187 | // These values are also the values reported through accessors, overriding any |
| 188 | // information from the database. |
| 189 | |
| 190 | // Throw away all information provided to the object, and start from top. |
| 191 | void Reset(); |
| 192 | |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 193 | // Both MCCMNC and SID correspond to operator code in the different |
| 194 | // technologies. They are never to be used together. If you want to use SID |
| 195 | // after MCCMNC (or vice-versa), ensure a call to |Reset| to clear state. |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 196 | virtual void UpdateMCCMNC(const std::string &mccmnc); |
| 197 | virtual void UpdateSID(const std::string &sid); |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 198 | |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 199 | virtual void UpdateIMSI(const std::string &imsi); |
Prathmesh Prabhu | c1175bf | 2014-04-15 16:58:05 -0700 | [diff] [blame] | 200 | void UpdateICCID(const std::string &iccid); |
Prathmesh Prabhu | 6e0a8ef | 2014-05-05 22:30:07 -0700 | [diff] [blame] | 201 | virtual void UpdateNID(const std::string &nid); |
| 202 | virtual void UpdateOperatorName(const std::string &operator_name); |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 203 | void UpdateOnlinePortal(const std::string &url, |
| 204 | const std::string &method, |
| 205 | const std::string &post_data); |
| 206 | |
| 207 | // /////////////////////////////////////////////////////////////////////////// |
| 208 | // Expose implementation for test purposes only. |
| 209 | MobileOperatorInfoImpl * impl() { return impl_.get(); } |
| 210 | |
| 211 | private: |
| 212 | scoped_ptr<MobileOperatorInfoImpl> impl_; |
Prathmesh Prabhu | 28b4a3b | 2014-03-28 11:52:09 -0700 | [diff] [blame] | 213 | DISALLOW_COPY_AND_ASSIGN(MobileOperatorInfo); |
| 214 | }; |
| 215 | |
| 216 | } // namespace shill |
| 217 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 218 | #endif // SHILL_MOBILE_OPERATOR_INFO_H_ |