blob: abb5f4e641ff80f2ddd0b573b0625e7e106cacf6 [file] [log] [blame]
Arman Ugurayf4c61812013-01-10 18:58:39 -08001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
Ben Chanb39cb312012-11-01 22:55:25 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Arman Uguray73a83e62013-02-12 18:51:33 -08005// 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 Chanb39cb312012-11-01 22:55:25 -070010#ifndef SHILL_CELLULAR_OPERATOR_INFO_H_
11#define SHILL_CELLULAR_OPERATOR_INFO_H_
12
Arman Ugurayf4c61812013-01-10 18:58:39 -080013#include <map>
Ben Chanb39cb312012-11-01 22:55:25 -070014#include <string>
Arman Ugurayf4c61812013-01-10 18:58:39 -080015#include <vector>
Ben Chanb39cb312012-11-01 22:55:25 -070016
17#include <base/basictypes.h>
18#include <base/file_path.h>
Arman Uguray73a83e62013-02-12 18:51:33 -080019#include <base/memory/scoped_ptr.h>
Arman Ugurayf4c61812013-01-10 18:58:39 -080020#include <base/memory/scoped_vector.h>
21#include <gtest/gtest_prod.h> // for FRIEND_TEST
Ben Chanb39cb312012-11-01 22:55:25 -070022
23#include "shill/cellular_service.h"
Arman Ugurayf4c61812013-01-10 18:58:39 -080024#include "shill/file_reader.h"
Ben Chanb39cb312012-11-01 22:55:25 -070025
26namespace shill {
27
Arman Uguray73a83e62013-02-12 18:51:33 -080028class 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 Chanb39cb312012-11-01 22:55:25 -070033class CellularOperatorInfo {
34 public:
Arman Uguray73a83e62013-02-12 18:51:33 -080035 // 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 Ugurayf4c61812013-01-10 18:58:39 -080038 struct LocalizedName {
Arman Uguray72fab6a2013-01-10 19:32:42 -080039 LocalizedName();
40 LocalizedName(std::string name, std::string language);
41
Arman Uguray73a83e62013-02-12 18:51:33 -080042 // The name as it appears in the corresponding language.
Arman Ugurayf4c61812013-01-10 18:58:39 -080043 std::string name;
Arman Uguray73a83e62013-02-12 18:51:33 -080044
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 Ugurayf4c61812013-01-10 18:58:39 -080050 std::string language;
51 };
52
Arman Uguray73a83e62013-02-12 18:51:33 -080053 // 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 Ugurayf4c61812013-01-10 18:58:39 -080059
Arman Uguray73a83e62013-02-12 18:51:33 -080060 // 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 Ugurayf4c61812013-01-10 18:58:39 -080063
Arman Uguray73a83e62013-02-12 18:51:33 -080064 // 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 Ugurayf4c61812013-01-10 18:58:39 -080071 };
72
Arman Uguray73a83e62013-02-12 18:51:33 -080073 // This class contains all the necessary information for shill to register
74 // with and establish a connection to a mobile network.
Arman Ugurayf4c61812013-01-10 18:58:39 -080075 class CellularOperator {
76 public:
77 CellularOperator();
Arman Ugurayf4c61812013-01-10 18:58:39 -080078
Arman Uguray73a83e62013-02-12 18:51:33 -080079 // 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 Ugurayf4c61812013-01-10 18:58:39 -080082 const std::string &country() const { return country_; }
Arman Uguray73a83e62013-02-12 18:51:33 -080083
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 Ugurayc9533572013-01-22 17:34:20 -080087 const std::string &identifier() const { return identifier_; }
Arman Uguray73a83e62013-02-12 18:51:33 -080088
Arman Uguray8ec7ea52013-04-30 02:00:23 -070089 // The number to dial for automatic activation.
90 const std::string &activation_code() const { return activation_code_; }
91
Arman Uguray73a83e62013-02-12 18:51:33 -080092 // 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 Ugurayf4c61812013-01-10 18:58:39 -080097 const std::vector<std::string> &mccmnc_list() const {
98 return mccmnc_list_;
99 }
Arman Uguray73a83e62013-02-12 18:51:33 -0800100
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 Ugurayf4c61812013-01-10 18:58:39 -0800107 const std::vector<std::string> &sid_list() const { return sid_list_; }
Arman Uguray73a83e62013-02-12 18:51:33 -0800108
109 // All localized names associated with this carrier entry.
Arman Ugurayf4c61812013-01-10 18:58:39 -0800110 const std::vector<LocalizedName> &name_list() const { return name_list_; }
Arman Uguray73a83e62013-02-12 18:51:33 -0800111
112 // All access point names associated with this carrier entry.
Arman Ugurayf4c61812013-01-10 18:58:39 -0800113 const ScopedVector<MobileAPN> &apn_list() const { return apn_list_; }
Arman Uguray73a83e62013-02-12 18:51:33 -0800114
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 Ugurayf4c61812013-01-10 18:58:39 -0800118 const ScopedVector<CellularService::OLP> &olp_list() const {
119 return olp_list_;
120 }
Arman Uguray73a83e62013-02-12 18:51:33 -0800121
122 // This flag is declared for certain carriers in the underlying database.
123 // Shill currently does not use it.
Arman Ugurayf4c61812013-01-10 18:58:39 -0800124 bool is_primary() const { return is_primary_; }
Arman Uguray73a83e62013-02-12 18:51:33 -0800125
126 // Some carriers are only available while roaming. This is mainly used by
127 // Chrome.
Arman Ugurayf4c61812013-01-10 18:58:39 -0800128 bool requires_roaming() const { return requires_roaming_; }
129
130 private:
131 friend class CellularOperatorInfo;
Arman Uguray73a83e62013-02-12 18:51:33 -0800132 friend class CellularOperatorInfoImpl;
Arman Uguray72fab6a2013-01-10 19:32:42 -0800133 friend class CellularCapabilityUniversalCDMATest;
Arman Ugurayf3070622013-10-03 20:27:42 -0700134 friend class MobileOperatorTest;
Arman Uguray0a3e2792013-01-17 16:31:50 -0800135 FRIEND_TEST(CellularCapabilityUniversalCDMAMainTest,
136 CreateFriendlyServiceName);
137 FRIEND_TEST(CellularCapabilityUniversalCDMAMainTest,
138 OnCDMARegistrationChanged);
Ben Chan07193fd2013-07-12 22:10:55 -0700139 FRIEND_TEST(CellularCapabilityUniversalCDMAMainTest, UpdateOLP);
Arman Uguray0a3e2792013-01-17 16:31:50 -0800140 FRIEND_TEST(CellularCapabilityUniversalCDMAMainTest, UpdateOperatorInfo);
Arman Ugurayc5391232013-09-23 21:30:46 -0700141 FRIEND_TEST(CellularCapabilityUniversalCDMAMainTest,
142 UpdateStorageIdentifier);
143 FRIEND_TEST(CellularCapabilityUniversalMainTest, GetMdnForOLP);
144 FRIEND_TEST(CellularCapabilityUniversalMainTest, UpdateOLP);
145 FRIEND_TEST(CellularCapabilityUniversalMainTest, UpdateStorageIdentifier);
Arman Ugurayf4c61812013-01-10 18:58:39 -0800146
147 std::string country_;
Arman Ugurayc9533572013-01-22 17:34:20 -0800148 std::string identifier_;
Arman Uguray8ec7ea52013-04-30 02:00:23 -0700149 std::string activation_code_;
Arman Ugurayf4c61812013-01-10 18:58:39 -0800150 std::vector<std::string> mccmnc_list_;
151 std::vector<std::string> sid_list_;
152 std::vector<LocalizedName> name_list_;
153 ScopedVector<MobileAPN> apn_list_;
154 ScopedVector<CellularService::OLP> olp_list_;
155 std::map<std::string, uint32> mccmnc_to_olp_idx_;
156 std::map<std::string, uint32> sid_to_olp_idx_;
157 bool is_primary_;
158 bool requires_roaming_;
159
160 DISALLOW_COPY_AND_ASSIGN(CellularOperator);
161 };
162
Arman Uguray73a83e62013-02-12 18:51:33 -0800163 // The class Constructor and Destructor don't perform any special
164 // initialization or cleanup. The primary initializer is the Load()
165 // method.
166 CellularOperatorInfo();
167 virtual ~CellularOperatorInfo();
168
Ben Chanb39cb312012-11-01 22:55:25 -0700169 // Loads the operator info from |info_file_path|. Returns true on success.
Albert Chaulk0e1cdea2013-02-27 15:32:55 -0800170 bool Load(const base::FilePath &info_file_path);
Ben Chanb39cb312012-11-01 22:55:25 -0700171
Arman Ugurayf4c61812013-01-10 18:58:39 -0800172 // Gets the cellular operator info of the operator with MCCMNC |mccmnc|.
173 // If found, returns a pointer to the matching operator.
Arman Uguray73a83e62013-02-12 18:51:33 -0800174 virtual const CellularOperator *GetCellularOperatorByMCCMNC(
175 const std::string &mccmnc) const;
Arman Ugurayf4c61812013-01-10 18:58:39 -0800176
177 // Gets the cellular operator info of the operator with SID |sid|.
178 // If found, returns a pointer to the matching operator.
Arman Uguray73a83e62013-02-12 18:51:33 -0800179 virtual const CellularOperator *GetCellularOperatorBySID(
180 const std::string &sid) const;
Arman Ugurayf4c61812013-01-10 18:58:39 -0800181
182 // Gets the cellular operator info of the operators that match the name
183 // |name|, such that each element contains information about the operator
184 // in different countries. The given name must be the first enumerated name
185 // for the operator in the operator database.
186 // If found, returns a pointer to a vector containing the matching operators.
Arman Uguray73a83e62013-02-12 18:51:33 -0800187 virtual const std::vector<const CellularOperator *> *GetCellularOperators(
188 const std::string &name) const;
Arman Ugurayf4c61812013-01-10 18:58:39 -0800189
190 // Gets the online payment portal info of the operator with MCCMNC |mccmnc|.
191 // If found, returns a pointer to the matching OLP.
Arman Uguray73a83e62013-02-12 18:51:33 -0800192 virtual const CellularService::OLP *GetOLPByMCCMNC(
193 const std::string &mccmnc) const;
Arman Ugurayf4c61812013-01-10 18:58:39 -0800194
195 // Gets the online payment portal info of the operator with SID |sid|.
196 // If found, returns a pointer to the matching OLP.
Arman Uguray73a83e62013-02-12 18:51:33 -0800197 virtual const CellularService::OLP *GetOLPBySID(const std::string &sid) const;
Arman Ugurayf4c61812013-01-10 18:58:39 -0800198
199 // Returns a list of all operators.
Arman Uguray73a83e62013-02-12 18:51:33 -0800200 const ScopedVector<CellularOperator> &operators() const;
Ben Chanb39cb312012-11-01 22:55:25 -0700201
202 private:
Arman Uguray73a83e62013-02-12 18:51:33 -0800203 scoped_ptr<CellularOperatorInfoImpl> impl_;
Ben Chanb39cb312012-11-01 22:55:25 -0700204
205 DISALLOW_COPY_AND_ASSIGN(CellularOperatorInfo);
206};
207
208} // namespace shill
209
210#endif // SHILL_CELLULAR_OPERATOR_INFO_H_