Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
Ben Chan | b39cb31 | 2012-11-01 22:55:25 -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 | |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 5 | // Defines shill::CellularOperatorInfo, which is meant to replace the |
| 6 | // mobile-broadband-provider-info library by providing the same mechanisms in |
| 7 | // C++. It also extends the information provided by |
| 8 | // mobile-broadband-provider-info. |
| 9 | |
Ben Chan | b39cb31 | 2012-11-01 22:55:25 -0700 | [diff] [blame] | 10 | #ifndef SHILL_CELLULAR_OPERATOR_INFO_H_ |
| 11 | #define SHILL_CELLULAR_OPERATOR_INFO_H_ |
| 12 | |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 13 | #include <map> |
Ben Chan | b39cb31 | 2012-11-01 22:55:25 -0700 | [diff] [blame] | 14 | #include <string> |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 15 | #include <vector> |
Ben Chan | b39cb31 | 2012-11-01 22:55:25 -0700 | [diff] [blame] | 16 | |
| 17 | #include <base/basictypes.h> |
| 18 | #include <base/file_path.h> |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 19 | #include <base/memory/scoped_ptr.h> |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 20 | #include <base/memory/scoped_vector.h> |
| 21 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Ben Chan | b39cb31 | 2012-11-01 22:55:25 -0700 | [diff] [blame] | 22 | |
| 23 | #include "shill/cellular_service.h" |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 24 | #include "shill/file_reader.h" |
Ben Chan | b39cb31 | 2012-11-01 22:55:25 -0700 | [diff] [blame] | 25 | |
| 26 | namespace shill { |
| 27 | |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 28 | class CellularOperatorInfoImpl; |
| 29 | |
| 30 | // CellularOperatorInfo, which is a utility class for parsing |
| 31 | // cellular carrier specific infomation from a specially formatted file that |
| 32 | // encodes carrier related data in a key-value format. |
Ben Chan | b39cb31 | 2012-11-01 22:55:25 -0700 | [diff] [blame] | 33 | class CellularOperatorInfo { |
| 34 | public: |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 35 | // Encapsulates a name and the language that name has been localized to. |
| 36 | // The name can be a carrier name, or the name that a cellular carrier |
| 37 | // prefers to show for a certain access point. |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 38 | struct LocalizedName { |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 39 | LocalizedName(); |
| 40 | LocalizedName(std::string name, std::string language); |
| 41 | |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 42 | // The name as it appears in the corresponding language. |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 43 | std::string name; |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 44 | |
| 45 | // The language of this localized name. The format of a language is a two |
| 46 | // letter language code, e.g. 'en' for English. |
| 47 | // It is legal for an instance of LocalizedName to have an empty |language| |
| 48 | // field, as sometimes the underlying database does not contain that |
| 49 | // information. |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 50 | std::string language; |
| 51 | }; |
| 52 | |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 53 | // Encapsulates information on a mobile access point name. This information |
| 54 | // is usually necessary for 3GPP networks to be able to connect to a mobile |
| 55 | // network. So far, CDMA networks don't use this information. |
| 56 | struct MobileAPN { |
| 57 | // The access point url, which is fed to the modemmanager while connecting. |
| 58 | std::string apn; |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 59 | |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 60 | // A list of localized names for this access point. Usually there is only |
| 61 | // one for each country that the associated cellular carrier operates in. |
| 62 | std::vector<LocalizedName> name_list; |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 63 | |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 64 | // The username and password fields that are required by the modemmanager. |
| 65 | // Either of these values can be empty if none is present. If a MobileAPN |
| 66 | // instance that is obtained from this parser contains a non-empty value |
| 67 | // for username/password, this usually means that the carrier requires |
| 68 | // a certain default pair. |
| 69 | std::string username; |
| 70 | std::string password; |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 73 | // This class contains all the necessary information for shill to register |
| 74 | // with and establish a connection to a mobile network. |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 75 | class CellularOperator { |
| 76 | public: |
| 77 | CellularOperator(); |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 78 | |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 79 | // For this instance, returns the primary country code that this operator |
| 80 | // serves. The underlying database sometimes contains multiple entries for |
| 81 | // the same carrier for different countries. |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 82 | const std::string &country() const { return country_; } |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 83 | |
| 84 | // The unique identifier of this carrier. This is primarily used to |
| 85 | // identify the user profile in store for each carrier. This identifier is |
| 86 | // access technology agnostic and should be the same across 3GPP and CDMA. |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 87 | const std::string &identifier() const { return identifier_; } |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 88 | |
Arman Uguray | 8ec7ea5 | 2013-04-30 02:00:23 -0700 | [diff] [blame^] | 89 | // The number to dial for automatic activation. |
| 90 | const std::string &activation_code() const { return activation_code_; } |
| 91 | |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 92 | // MCCMNC or (MCC/MNC tuple) is the combination of a "Mobile Country Code" |
| 93 | // and "Mobile Network Code" and is used to uniquely identify a carrier. |
| 94 | // ModemManager currently return MCCMNC as the primary operator code for |
| 95 | // 3GPP networks. A carrier can be associated with multiple MCCMNC values |
| 96 | // based on location and technology (e.g. 3G, LTE). |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 97 | const std::vector<std::string> &mccmnc_list() const { |
| 98 | return mccmnc_list_; |
| 99 | } |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 100 | |
| 101 | // The SID is the primary operator code currently used by ModemManager to |
| 102 | // identify CDMA networks. There are likely many SID values associated with |
| 103 | // a CDMA carrier as they vary across regions and are more fine grained |
| 104 | // than countries. An important thing to keep in mind is that, since an SID |
| 105 | // contains fine grained information on where a modem is physically |
| 106 | // located, it should be regarded as user-sensitive information. |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 107 | const std::vector<std::string> &sid_list() const { return sid_list_; } |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 108 | |
| 109 | // All localized names associated with this carrier entry. |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 110 | const std::vector<LocalizedName> &name_list() const { return name_list_; } |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 111 | |
| 112 | // All access point names associated with this carrier entry. |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 113 | const ScopedVector<MobileAPN> &apn_list() const { return apn_list_; } |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 114 | |
| 115 | // All Online Payment Portal URLs associated with this carrier entry. There |
| 116 | // are usually multiple OLPs based on access technology and it is up to the |
| 117 | // application to use the appropriate one. |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 118 | const ScopedVector<CellularService::OLP> &olp_list() const { |
| 119 | return olp_list_; |
| 120 | } |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 121 | |
| 122 | // This flag is declared for certain carriers in the underlying database. |
| 123 | // Shill currently does not use it. |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 124 | bool is_primary() const { return is_primary_; } |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 125 | |
| 126 | // Some carriers are only available while roaming. This is mainly used by |
| 127 | // Chrome. |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 128 | bool requires_roaming() const { return requires_roaming_; } |
| 129 | |
| 130 | private: |
| 131 | friend class CellularOperatorInfo; |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 132 | friend class CellularOperatorInfoImpl; |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 133 | friend class CellularCapabilityUniversalCDMATest; |
Arman Uguray | 1361c03 | 2013-02-11 17:53:39 -0800 | [diff] [blame] | 134 | FRIEND_TEST(CellularCapabilityUniversalMainTest, UpdateStorageIdentifier); |
Arman Uguray | 72fab6a | 2013-01-10 19:32:42 -0800 | [diff] [blame] | 135 | FRIEND_TEST(CellularCapabilityUniversalCDMATest, CreateFriendlyServiceName); |
| 136 | FRIEND_TEST(CellularCapabilityUniversalCDMATest, OnCDMARegistrationChanged); |
| 137 | FRIEND_TEST(CellularCapabilityUniversalCDMATest, UpdateOperatorInfo); |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 138 | |
| 139 | std::string country_; |
Arman Uguray | c953357 | 2013-01-22 17:34:20 -0800 | [diff] [blame] | 140 | std::string identifier_; |
Arman Uguray | 8ec7ea5 | 2013-04-30 02:00:23 -0700 | [diff] [blame^] | 141 | std::string activation_code_; |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 142 | std::vector<std::string> mccmnc_list_; |
| 143 | std::vector<std::string> sid_list_; |
| 144 | std::vector<LocalizedName> name_list_; |
| 145 | ScopedVector<MobileAPN> apn_list_; |
| 146 | ScopedVector<CellularService::OLP> olp_list_; |
| 147 | std::map<std::string, uint32> mccmnc_to_olp_idx_; |
| 148 | std::map<std::string, uint32> sid_to_olp_idx_; |
| 149 | bool is_primary_; |
| 150 | bool requires_roaming_; |
| 151 | |
| 152 | DISALLOW_COPY_AND_ASSIGN(CellularOperator); |
| 153 | }; |
| 154 | |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 155 | // The class Constructor and Destructor don't perform any special |
| 156 | // initialization or cleanup. The primary initializer is the Load() |
| 157 | // method. |
| 158 | CellularOperatorInfo(); |
| 159 | virtual ~CellularOperatorInfo(); |
| 160 | |
Ben Chan | b39cb31 | 2012-11-01 22:55:25 -0700 | [diff] [blame] | 161 | // Loads the operator info from |info_file_path|. Returns true on success. |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 162 | bool Load(const base::FilePath &info_file_path); |
Ben Chan | b39cb31 | 2012-11-01 22:55:25 -0700 | [diff] [blame] | 163 | |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 164 | // Gets the cellular operator info of the operator with MCCMNC |mccmnc|. |
| 165 | // If found, returns a pointer to the matching operator. |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 166 | virtual const CellularOperator *GetCellularOperatorByMCCMNC( |
| 167 | const std::string &mccmnc) const; |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 168 | |
| 169 | // Gets the cellular operator info of the operator with SID |sid|. |
| 170 | // If found, returns a pointer to the matching operator. |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 171 | virtual const CellularOperator *GetCellularOperatorBySID( |
| 172 | const std::string &sid) const; |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 173 | |
| 174 | // Gets the cellular operator info of the operators that match the name |
| 175 | // |name|, such that each element contains information about the operator |
| 176 | // in different countries. The given name must be the first enumerated name |
| 177 | // for the operator in the operator database. |
| 178 | // If found, returns a pointer to a vector containing the matching operators. |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 179 | virtual const std::vector<const CellularOperator *> *GetCellularOperators( |
| 180 | const std::string &name) const; |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 181 | |
| 182 | // Gets the online payment portal info of the operator with MCCMNC |mccmnc|. |
| 183 | // If found, returns a pointer to the matching OLP. |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 184 | virtual const CellularService::OLP *GetOLPByMCCMNC( |
| 185 | const std::string &mccmnc) const; |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 186 | |
| 187 | // Gets the online payment portal info of the operator with SID |sid|. |
| 188 | // If found, returns a pointer to the matching OLP. |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 189 | virtual const CellularService::OLP *GetOLPBySID(const std::string &sid) const; |
Arman Uguray | f4c6181 | 2013-01-10 18:58:39 -0800 | [diff] [blame] | 190 | |
| 191 | // Returns a list of all operators. |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 192 | const ScopedVector<CellularOperator> &operators() const; |
Ben Chan | b39cb31 | 2012-11-01 22:55:25 -0700 | [diff] [blame] | 193 | |
| 194 | private: |
Arman Uguray | 73a83e6 | 2013-02-12 18:51:33 -0800 | [diff] [blame] | 195 | scoped_ptr<CellularOperatorInfoImpl> impl_; |
Ben Chan | b39cb31 | 2012-11-01 22:55:25 -0700 | [diff] [blame] | 196 | |
| 197 | DISALLOW_COPY_AND_ASSIGN(CellularOperatorInfo); |
| 198 | }; |
| 199 | |
| 200 | } // namespace shill |
| 201 | |
| 202 | #endif // SHILL_CELLULAR_OPERATOR_INFO_H_ |