blob: 12575ef7f6245390bd9e49da86bc7db5bed059ee [file] [log] [blame]
[email protected]353e0dd82010-11-22 08:39:311 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]7598ab52009-10-08 01:33:212// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]268b02f2010-02-04 21:07:155#ifndef CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_
6#define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]7598ab52009-10-08 01:33:218
9#include <string>
10#include <vector>
11
[email protected]0aadb272010-11-17 09:33:0812#include "base/gtest_prod_util.h"
[email protected]7598ab52009-10-08 01:33:2113#include "base/observer_list.h"
[email protected]633e5c02010-11-19 22:11:3514#include "base/scoped_vector.h"
[email protected]7598ab52009-10-08 01:33:2115#include "base/singleton.h"
[email protected]f0053942010-11-13 02:33:5416#include "base/string16.h"
[email protected]1f410002009-10-28 04:11:0017#include "base/timer.h"
[email protected]583dca282010-12-17 01:12:0518#include "third_party/cros/chromeos_network.h"
[email protected]7598ab52009-10-08 01:33:2119
[email protected]3c1139f2010-10-22 06:17:4220class Value;
21
[email protected]b22c21c2009-10-30 00:35:0022namespace chromeos {
23
[email protected]543a79a2010-10-20 01:14:5824// Cellular network is considered low data when less than 60 minues.
25static const int kCellularDataLowSecs = 60 * 60;
26
27// Cellular network is considered low data when less than 30 minues.
28static const int kCellularDataVeryLowSecs = 30 * 60;
29
30// Cellular network is considered low data when less than 100MB.
31static const int kCellularDataLowBytes = 100 * 1024 * 1024;
32
33// Cellular network is considered very low data when less than 50MB.
34static const int kCellularDataVeryLowBytes = 50 * 1024 * 1024;
35
[email protected]00e17562010-05-06 18:59:2536class Network {
37 public:
38 const std::string& service_path() const { return service_path_; }
39 const std::string& device_path() const { return device_path_; }
40 const std::string& ip_address() const { return ip_address_; }
[email protected]5a1c2dd2010-05-11 22:52:3041 ConnectionType type() const { return type_; }
[email protected]9a24152e2010-10-08 23:15:3142 ConnectionState connection_state() const { return state_; }
[email protected]5a1c2dd2010-05-11 22:52:3043 bool connecting() const { return state_ == STATE_ASSOCIATION ||
44 state_ == STATE_CONFIGURATION || state_ == STATE_CARRIER; }
[email protected]8df038b2010-10-28 22:56:4645 bool configuring() const { return state_ == STATE_CONFIGURATION; }
[email protected]5a1c2dd2010-05-11 22:52:3046 bool connected() const { return state_ == STATE_READY; }
47 bool connecting_or_connected() const { return connecting() || connected(); }
48 bool failed() const { return state_ == STATE_FAILURE; }
[email protected]3c1139f2010-10-22 06:17:4249 bool failed_or_disconnected() const { return failed() ||
50 state_ == STATE_IDLE; }
[email protected]5a1c2dd2010-05-11 22:52:3051 ConnectionError error() const { return error_; }
[email protected]89ccd242010-10-12 08:58:2752 ConnectionState state() const { return state_; }
[email protected]ca9f6702010-11-17 01:28:1453 // Is this network connectable. Some networks are not yet ready to be
54 // connected. For example, an 8021X network without certificates.
55 bool connectable() const { return connectable_; }
[email protected]ceaf8f12010-11-04 20:37:3256 // Is this the active network, i.e, the one through which
57 // network traffic is being routed? A network can be connected,
58 // but not be carrying traffic.
59 bool is_active() const { return is_active_; }
[email protected]00e17562010-05-06 18:59:2560
61 // Clear the fields.
62 virtual void Clear();
63
[email protected]5a1c2dd2010-05-11 22:52:3064 // Return a string representation of the state code.
[email protected]caf063d2010-10-11 18:58:2265 std::string GetStateString() const;
[email protected]5a1c2dd2010-05-11 22:52:3066
67 // Return a string representation of the error code.
[email protected]caf063d2010-10-11 18:58:2268 std::string GetErrorString() const;
[email protected]5a1c2dd2010-05-11 22:52:3069
[email protected]00e17562010-05-06 18:59:2570 protected:
71 Network()
[email protected]5a1c2dd2010-05-11 22:52:3072 : type_(TYPE_UNKNOWN),
73 state_(STATE_UNKNOWN),
[email protected]ceaf8f12010-11-04 20:37:3274 error_(ERROR_UNKNOWN),
[email protected]ca9f6702010-11-17 01:28:1475 connectable_(true),
[email protected]ceaf8f12010-11-04 20:37:3276 is_active_(false) {}
[email protected]45066d52010-10-29 17:24:5777 explicit Network(const Network& network);
78 explicit Network(const ServiceInfo* service);
[email protected]00e17562010-05-06 18:59:2579 virtual ~Network() {}
80
[email protected]00e17562010-05-06 18:59:2581 std::string service_path_;
82 std::string device_path_;
83 std::string ip_address_;
[email protected]5a1c2dd2010-05-11 22:52:3084 ConnectionType type_;
[email protected]9a24152e2010-10-08 23:15:3185 ConnectionState state_;
[email protected]5a1c2dd2010-05-11 22:52:3086 ConnectionError error_;
[email protected]ca9f6702010-11-17 01:28:1487 bool connectable_;
[email protected]ceaf8f12010-11-04 20:37:3288 bool is_active_;
89
90 private:
91 void set_service_path(const std::string& service_path) {
92 service_path_ = service_path; }
93 void set_connecting(bool connecting) { state_ = (connecting ?
94 STATE_ASSOCIATION : STATE_IDLE); }
95 void set_connected(bool connected) { state_ = (connected ?
96 STATE_READY : STATE_IDLE); }
97 void set_state(ConnectionState state) { state_ = state; }
[email protected]ca9f6702010-11-17 01:28:1498 void set_connectable(bool connectable) { connectable_ = connectable; }
[email protected]ceaf8f12010-11-04 20:37:3299 void set_active(bool is_active) { is_active_ = is_active; }
[email protected]fe3a05092010-11-24 23:53:16100 void set_error(ConnectionError error) { error_ = error; }
[email protected]ceaf8f12010-11-04 20:37:32101
[email protected]9e320292010-11-18 00:52:29102 // Initialize the IP address field
103 void InitIPAddress();
104
[email protected]ceaf8f12010-11-04 20:37:32105 friend class NetworkLibraryImpl;
[email protected]0fb499a2009-11-10 21:03:33106};
107
[email protected]00e17562010-05-06 18:59:25108class EthernetNetwork : public Network {
109 public:
[email protected]caf063d2010-10-11 18:58:22110 EthernetNetwork() : Network() {
111 type_ = TYPE_ETHERNET;
112 }
[email protected]45066d52010-10-29 17:24:57113
114 explicit EthernetNetwork(const EthernetNetwork& network)
115 : Network(network) {
116 type_ = TYPE_ETHERNET;
117 }
118
119 explicit EthernetNetwork(const ServiceInfo* service) : Network(service) {
120 type_ = TYPE_ETHERNET;
121 }
[email protected]00e17562010-05-06 18:59:25122};
123
124class WirelessNetwork : public Network {
125 public:
126 // WirelessNetwork are sorted by name.
127 bool operator< (const WirelessNetwork& other) const {
128 return name_ < other.name();
129 }
130
[email protected]f9384b552010-06-28 23:02:26131 // We frequently want to compare networks by service path.
132 struct ServicePathEq {
133 explicit ServicePathEq(const std::string& path_in) : path(path_in) {}
[email protected]45066d52010-10-29 17:24:57134 bool operator()(const WirelessNetwork* a) {
135 return a->service_path().compare(path) == 0;
[email protected]f9384b552010-06-28 23:02:26136 }
137 const std::string& path;
138 };
139
[email protected]00e17562010-05-06 18:59:25140 const std::string& name() const { return name_; }
141 int strength() const { return strength_; }
142 bool auto_connect() const { return auto_connect_; }
[email protected]be3c882c2010-09-07 16:40:02143 bool favorite() const { return favorite_; }
[email protected]00e17562010-05-06 18:59:25144
[email protected]00e17562010-05-06 18:59:25145 void set_auto_connect(bool auto_connect) { auto_connect_ = auto_connect; }
[email protected]0aadb272010-11-17 09:33:08146 // We don't have a setter for |favorite_| because to unfavorite a network is
147 // equivalent to forget a network, so we call forget network on cros for
148 // that. See ForgetWifiNetwork().
[email protected]00e17562010-05-06 18:59:25149
150 // Network overrides.
151 virtual void Clear();
[email protected]00e17562010-05-06 18:59:25152
153 protected:
154 WirelessNetwork()
155 : Network(),
156 strength_(0),
[email protected]be3c882c2010-09-07 16:40:02157 auto_connect_(false),
158 favorite_(false) {}
[email protected]45066d52010-10-29 17:24:57159 explicit WirelessNetwork(const WirelessNetwork& network);
160 explicit WirelessNetwork(const ServiceInfo* service);
[email protected]05f06df2010-11-04 17:31:16161 virtual ~WirelessNetwork() {}
[email protected]00e17562010-05-06 18:59:25162 std::string name_;
163 int strength_;
164 bool auto_connect_;
[email protected]be3c882c2010-09-07 16:40:02165 bool favorite_;
[email protected]ceaf8f12010-11-04 20:37:32166
167 private:
[email protected]0aadb272010-11-17 09:33:08168 // ChangeAutoConnectSaveTest accesses |favorite_|.
169 FRIEND_TEST_ALL_PREFIXES(WifiConfigViewTest, ChangeAutoConnectSaveTest);
170
[email protected]ceaf8f12010-11-04 20:37:32171 void set_name(const std::string& name) { name_ = name; }
172 void set_strength(int strength) { strength_ = strength; }
173
174 friend class NetworkLibraryImpl;
[email protected]00e17562010-05-06 18:59:25175};
176
[email protected]05f06df2010-11-04 17:31:16177class CellularDataPlan {
178 public:
179 CellularDataPlan() :
180 plan_name("Unknown"),
181 plan_type(CELLULAR_DATA_PLAN_UNLIMITED),
182 plan_data_bytes(0),
183 data_bytes_used(0) { }
184 explicit CellularDataPlan(const CellularDataPlanInfo &plan) :
185 plan_name(plan.plan_name?plan.plan_name:""),
186 plan_type(plan.plan_type),
187 update_time(base::Time::FromInternalValue(plan.update_time)),
188 plan_start_time(base::Time::FromInternalValue(plan.plan_start_time)),
189 plan_end_time(base::Time::FromInternalValue(plan.plan_end_time)),
190 plan_data_bytes(plan.plan_data_bytes),
191 data_bytes_used(plan.data_bytes_used) { }
[email protected]f0053942010-11-13 02:33:54192 // Formats cellular plan description.
193 string16 GetPlanDesciption() const;
194 // Evaluates cellular plans status and returns warning string if it is near
195 // expiration.
196 string16 GetRemainingWarning() const;
197 // Formats remaining plan data description.
198 string16 GetDataRemainingDesciption() const;
199 // Formats plan expiration description.
200 string16 GetPlanExpiration() const;
201 // Formats plan usage info.
202 string16 GetUsageInfo() const;
[email protected]633e5c02010-11-19 22:11:35203 base::TimeDelta remaining_time() const;
[email protected]f0053942010-11-13 02:33:54204 int64 remaining_minutes() const;
[email protected]633e5c02010-11-19 22:11:35205 int64 remaining_data() const;
[email protected]f0053942010-11-13 02:33:54206 int64 remaining_mbytes() const;
[email protected]05f06df2010-11-04 17:31:16207 std::string plan_name;
208 CellularDataPlanType plan_type;
209 base::Time update_time;
210 base::Time plan_start_time;
211 base::Time plan_end_time;
212 int64 plan_data_bytes;
213 int64 data_bytes_used;
214};
215
[email protected]633e5c02010-11-19 22:11:35216typedef ScopedVector<CellularDataPlan> CellularDataPlanVector;
[email protected]05f06df2010-11-04 17:31:16217
[email protected]00e17562010-05-06 18:59:25218class CellularNetwork : public WirelessNetwork {
219 public:
[email protected]543a79a2010-10-20 01:14:58220 enum DataLeft {
[email protected]eda4d0c2011-01-24 19:52:02221 DATA_UNKNOWN,
[email protected]543a79a2010-10-20 01:14:58222 DATA_NORMAL,
223 DATA_LOW,
224 DATA_VERY_LOW,
225 DATA_NONE
226 };
227
[email protected]caf063d2010-10-11 18:58:22228 CellularNetwork();
[email protected]45066d52010-10-29 17:24:57229 explicit CellularNetwork(const CellularNetwork& network);
230 explicit CellularNetwork(const ServiceInfo* service);
[email protected]05f06df2010-11-04 17:31:16231 virtual ~CellularNetwork();
[email protected]9d3f7d5e2010-09-25 06:17:04232 // Starts device activation process. Returns false if the device state does
233 // not permit activation.
234 bool StartActivation() const;
[email protected]ad75cda2010-09-28 23:18:46235 const ActivationState activation_state() const { return activation_state_; }
[email protected]17cc0522010-10-01 20:19:12236 const NetworkTechnology network_technology() const {
[email protected]caf063d2010-10-11 18:58:22237 return network_technology_;
238 }
[email protected]17cc0522010-10-01 20:19:12239 const NetworkRoamingState roaming_state() const { return roaming_state_; }
[email protected]353e0dd82010-11-22 08:39:31240 const ConnectivityState connectivity_state() const {
241 return connectivity_state_;
242 }
243 bool restricted_pool() const {
244 return connectivity_state() == CONN_STATE_RESTRICTED;
245 }
[email protected]f0053942010-11-13 02:33:54246 bool needs_new_plan() const {
247 return restricted_pool() && connected() &&
248 activation_state() == ACTIVATION_STATE_ACTIVATED;
249 }
[email protected]caf063d2010-10-11 18:58:22250 const std::string& service_name() const { return service_name_; }
[email protected]9a24152e2010-10-08 23:15:31251 const std::string& operator_name() const { return operator_name_; }
252 const std::string& operator_code() const { return operator_code_; }
[email protected]9d3f7d5e2010-09-25 06:17:04253 const std::string& payment_url() const { return payment_url_; }
254 const std::string& meid() const { return meid_; }
255 const std::string& imei() const { return imei_; }
256 const std::string& imsi() const { return imsi_; }
257 const std::string& esn() const { return esn_; }
258 const std::string& mdn() const { return mdn_; }
[email protected]7b947813da2010-10-07 23:47:42259 const std::string& min() const { return min_; }
260 const std::string& model_id() const { return model_id_; }
261 const std::string& manufacturer() const { return manufacturer_; }
262 const std::string& firmware_revision() const { return firmware_revision_; }
263 const std::string& hardware_revision() const { return hardware_revision_; }
264 const std::string& last_update() const { return last_update_; }
[email protected]caf063d2010-10-11 18:58:22265 const unsigned int prl_version() const { return prl_version_; }
[email protected]633e5c02010-11-19 22:11:35266 bool is_gsm() const {
267 return network_technology_ != NETWORK_TECHNOLOGY_EVDO &&
268 network_technology_ != NETWORK_TECHNOLOGY_1XRTT &&
269 network_technology_ != NETWORK_TECHNOLOGY_UNKNOWN;
270 }
[email protected]3cc2e592010-06-21 13:45:43271
272 // WirelessNetwork overrides.
273 virtual void Clear();
[email protected]9d3f7d5e2010-09-25 06:17:04274
[email protected]05f06df2010-11-04 17:31:16275 const CellularDataPlanVector& GetDataPlans() const {
[email protected]38017612010-10-13 18:46:00276 return data_plans_;
277 }
278
[email protected]05f06df2010-11-04 17:31:16279 void SetDataPlans(const CellularDataPlanList* data_plan_list) {
[email protected]633e5c02010-11-19 22:11:35280 data_plans_.reset();
[email protected]05f06df2010-11-04 17:31:16281 for (size_t i = 0; i < data_plan_list->plans_size; i++) {
282 const CellularDataPlanInfo* info(data_plan_list->GetCellularDataPlan(i));
[email protected]633e5c02010-11-19 22:11:35283 data_plans_.push_back(new CellularDataPlan(*info));
[email protected]05f06df2010-11-04 17:31:16284 }
[email protected]38017612010-10-13 18:46:00285 }
[email protected]633e5c02010-11-19 22:11:35286
287 // This returns the significant data plan. If the user only has the
288 // base data plan, then return that. If there is a base and a paid data plan,
289 // then the significant one is the paid one. So return the paid plan.
290 // If there are no data plans, then this method returns NULL.
291 // This returns a pointer to a member of data_plans_, so if SetDataPlans()
292 // gets called, the result becomes invalid.
293 const CellularDataPlan* GetSignificantDataPlan() const;
294
295 DataLeft GetDataLeft() const;
296
[email protected]caf063d2010-10-11 18:58:22297 // Return a string representation of network technology.
298 std::string GetNetworkTechnologyString() const;
[email protected]353e0dd82010-11-22 08:39:31299 // Return a string representation of connectivity state.
300 std::string GetConnectivityStateString() const;
[email protected]caf063d2010-10-11 18:58:22301 // Return a string representation of activation state.
302 std::string GetActivationStateString() const;
303 // Return a string representation of roaming state.
304 std::string GetRoamingStateString() const;
305
[email protected]3c1139f2010-10-22 06:17:42306 // Return a string representation of |activation_state|.
307 static std::string ActivationStateToString(ActivationState activation_state);
308
[email protected]9d3f7d5e2010-09-25 06:17:04309 protected:
[email protected]45066d52010-10-29 17:24:57310
[email protected]ad75cda2010-09-28 23:18:46311 ActivationState activation_state_;
[email protected]17cc0522010-10-01 20:19:12312 NetworkTechnology network_technology_;
313 NetworkRoamingState roaming_state_;
[email protected]353e0dd82010-11-22 08:39:31314 ConnectivityState connectivity_state_;
[email protected]caf063d2010-10-11 18:58:22315 std::string service_name_;
[email protected]7b947813da2010-10-07 23:47:42316 // Carrier Info
317 std::string operator_name_;
318 std::string operator_code_;
[email protected]9d3f7d5e2010-09-25 06:17:04319 std::string payment_url_;
[email protected]7b947813da2010-10-07 23:47:42320 // Device Info
[email protected]9d3f7d5e2010-09-25 06:17:04321 std::string meid_;
322 std::string imei_;
323 std::string imsi_;
324 std::string esn_;
325 std::string mdn_;
[email protected]7b947813da2010-10-07 23:47:42326 std::string min_;
327 std::string model_id_;
328 std::string manufacturer_;
329 std::string firmware_revision_;
330 std::string hardware_revision_;
331 std::string last_update_;
[email protected]caf063d2010-10-11 18:58:22332 unsigned int prl_version_;
[email protected]05f06df2010-11-04 17:31:16333 CellularDataPlanVector data_plans_;
[email protected]ceaf8f12010-11-04 20:37:32334
335 private:
336 void set_activation_state(ActivationState state) {
337 activation_state_ = state;
338 }
339 void set_payment_url(const std::string& url) {
340 payment_url_ = url;
341 }
342 void set_network_technology(NetworkTechnology technology) {
343 network_technology_ = technology;
344 }
345 void set_roaming_state(NetworkRoamingState state) {
346 roaming_state_ = state;
347 }
[email protected]353e0dd82010-11-22 08:39:31348 void set_connectivity_state(ConnectivityState connectivity_state) {
349 connectivity_state_ = connectivity_state;
[email protected]ceaf8f12010-11-04 20:37:32350 }
351
352 friend class NetworkLibraryImpl;
[email protected]00e17562010-05-06 18:59:25353};
354
355class WifiNetwork : public WirelessNetwork {
356 public:
[email protected]caf063d2010-10-11 18:58:22357 WifiNetwork();
[email protected]45066d52010-10-29 17:24:57358 explicit WifiNetwork(const WifiNetwork& network);
359 explicit WifiNetwork(const ServiceInfo* service);
[email protected]7598ab52009-10-08 01:33:21360
[email protected]00e17562010-05-06 18:59:25361 bool encrypted() const { return encryption_ != SECURITY_NONE; }
362 ConnectionSecurity encryption() const { return encryption_; }
363 const std::string& passphrase() const { return passphrase_; }
[email protected]d47313852010-05-11 23:01:04364 const std::string& identity() const { return identity_; }
365 const std::string& cert_path() const { return cert_path_; }
[email protected]00e17562010-05-06 18:59:25366
367 void set_encryption(ConnectionSecurity encryption) {
368 encryption_ = encryption;
369 }
370 void set_passphrase(const std::string& passphrase) {
371 passphrase_ = passphrase;
372 }
[email protected]d47313852010-05-11 23:01:04373 void set_identity(const std::string& identity) {
374 identity_ = identity;
375 }
376 void set_cert_path(const std::string& cert_path) {
377 cert_path_ = cert_path;
378 }
[email protected]00e17562010-05-06 18:59:25379
380 // WirelessNetwork overrides.
381 virtual void Clear();
[email protected]00e17562010-05-06 18:59:25382
[email protected]5a1c2dd2010-05-11 22:52:30383 // Return a string representation of the encryption code.
384 // This not translated and should be only used for debugging purposes.
385 std::string GetEncryptionString();
386
[email protected]84161362010-12-15 16:50:33387 // Return true if a passphrase or other input is required to connect.
388 bool IsPassphraseRequired() const;
389
[email protected]c1ee0062010-10-14 18:37:22390 // Return true if cert_path_ indicates that we have loaded the certificate.
391 bool IsCertificateLoaded() const;
392
[email protected]5a1c2dd2010-05-11 22:52:30393 protected:
[email protected]00e17562010-05-06 18:59:25394 ConnectionSecurity encryption_;
395 std::string passphrase_;
[email protected]e027da192010-11-08 21:35:08396 bool passphrase_required_;
[email protected]d47313852010-05-11 23:01:04397 std::string identity_;
398 std::string cert_path_;
[email protected]7598ab52009-10-08 01:33:21399};
[email protected]00e17562010-05-06 18:59:25400
[email protected]45066d52010-10-29 17:24:57401typedef std::vector<chromeos::WifiNetwork*> WifiNetworkVector;
402typedef std::vector<chromeos::CellularNetwork*> CellularNetworkVector;
[email protected]38d387cd2010-01-14 01:00:39403
[email protected]63259a52010-07-15 10:55:38404struct CellTower {
405 enum RadioType {
406 RADIOTYPE_GSM,
407 RADIOTYPE_CDMA,
408 RADIOTYPE_WCDMA,
409 } radio_type; // GSM/WCDMA CDMA
410 int mobile_country_code; // MCC MCC
411 int mobile_network_code; // MNC SID
412 int location_area_code; // LAC NID
413 int cell_id; // CID BID
[email protected]17f12b52010-10-02 02:08:16414 base::Time timestamp; // Timestamp when this cell was primary
415 int signal_strength; // Radio signal strength measured in dBm.
416 int timing_advance; // Represents the distance from the cell tower.
417 // Each unit is roughly 550 meters.
[email protected]63259a52010-07-15 10:55:38418};
419
420struct WifiAccessPoint {
421 std::string mac_address; // The mac address of the WiFi node.
422 std::string name; // The SSID of the WiFi node.
423 base::Time timestamp; // Timestamp when this AP was detected.
424 int signal_strength; // Radio signal strength measured in dBm.
425 int signal_to_noise; // Current signal to noise ratio measured in dB.
426 int channel; // Wifi channel number.
427};
428
429typedef std::vector<CellTower> CellTowerVector;
430typedef std::vector<WifiAccessPoint> WifiAccessPointVector;
431
[email protected]3fb19f5c2010-02-17 00:49:50432struct NetworkIPConfig {
433 NetworkIPConfig(const std::string& device_path, IPConfigType type,
434 const std::string& address, const std::string& netmask,
435 const std::string& gateway, const std::string& name_servers)
436 : device_path(device_path),
437 type(type),
438 address(address),
439 netmask(netmask),
440 gateway(gateway),
441 name_servers(name_servers) {}
442
443 // NetworkIPConfigs are sorted by tyoe.
444 bool operator< (const NetworkIPConfig& other) const {
445 return type < other.type;
446 }
447
448 std::string device_path;
449 IPConfigType type;
[email protected]ea21f9c2010-10-21 08:26:54450 std::string address; // This looks like "/device/0011aa22bb33"
[email protected]3fb19f5c2010-02-17 00:49:50451 std::string netmask;
452 std::string gateway;
453 std::string name_servers;
454};
455typedef std::vector<NetworkIPConfig> NetworkIPConfigVector;
456
[email protected]819a43862010-08-12 10:09:21457// This class handles the interaction with the ChromeOS network library APIs.
458// Classes can add themselves as observers. Users can get an instance of the
459// library like this: chromeos::CrosLibrary::Get()->GetNetworkLibrary()
[email protected]62c7ef32010-03-23 23:44:24460class NetworkLibrary {
[email protected]7598ab52009-10-08 01:33:21461 public:
[email protected]ceaf8f12010-11-04 20:37:32462 class NetworkManagerObserver {
[email protected]7598ab52009-10-08 01:33:21463 public:
[email protected]ceaf8f12010-11-04 20:37:32464 // Called when the state of the network manager has changed,
465 // for example, networks have appeared or disappeared.
466 virtual void OnNetworkManagerChanged(NetworkLibrary* obj) = 0;
[email protected]7c3cc8a32010-11-03 06:58:14467 };
468
[email protected]ceaf8f12010-11-04 20:37:32469 class NetworkObserver {
[email protected]7c3cc8a32010-11-03 06:58:14470 public:
[email protected]ceaf8f12010-11-04 20:37:32471 // Called when the state of a single network has changed,
472 // for example signal strength or connection state.
473 virtual void OnNetworkChanged(NetworkLibrary* cros,
474 const Network* network) = 0;
475 };
476
477 class CellularDataPlanObserver {
478 public:
479 // Called when the cellular data plan has changed.
480 virtual void OnCellularDataPlanChanged(NetworkLibrary* obj) = 0;
[email protected]3c1139f2010-10-22 06:17:42481 };
482
[email protected]62c7ef32010-03-23 23:44:24483 virtual ~NetworkLibrary() {}
[email protected]ceaf8f12010-11-04 20:37:32484
485 virtual void AddNetworkManagerObserver(NetworkManagerObserver* observer) = 0;
486 virtual void RemoveNetworkManagerObserver(
487 NetworkManagerObserver* observer) = 0;
488
489 // An attempt to add an observer that has already been added for a
490 // give service path will be ignored.
491 virtual void AddNetworkObserver(const std::string& service_path,
492 NetworkObserver* observer) = 0;
493 // Remove an observer of a single network
494 virtual void RemoveNetworkObserver(const std::string& service_path,
495 NetworkObserver* observer) = 0;
496 // Stop |observer| from observing any networks
497 virtual void RemoveObserverForAllNetworks(NetworkObserver* observer) = 0;
498
[email protected]1b57b4c2011-01-21 21:43:11499 // Temporarily locks down certain functionality in network library to prevent
500 // unplanned side effects. During the lock down, Enable*Device() calls cannot
501 // be made.
502 virtual void Lock() = 0;
503 // Removes temporarily lock of network library.
504 virtual void Unlock() = 0;
505 // Checks if access to network library is locked.
506 virtual bool IsLocked() = 0;
507
[email protected]ceaf8f12010-11-04 20:37:32508 virtual void AddCellularDataPlanObserver(
509 CellularDataPlanObserver* observer) = 0;
510 virtual void RemoveCellularDataPlanObserver(
511 CellularDataPlanObserver* observer) = 0;
[email protected]62c7ef32010-03-23 23:44:24512
[email protected]21e744602010-10-16 03:16:53513 // Return the active Ethernet network (or a default structure if inactive).
[email protected]37eec142010-12-02 18:47:09514 virtual const EthernetNetwork* ethernet_network() const = 0;
[email protected]62c7ef32010-03-23 23:44:24515 virtual bool ethernet_connecting() const = 0;
516 virtual bool ethernet_connected() const = 0;
517
[email protected]21e744602010-10-16 03:16:53518 // Return the active Wifi network (or a default structure if none active).
[email protected]37eec142010-12-02 18:47:09519 virtual const WifiNetwork* wifi_network() const = 0;
[email protected]62c7ef32010-03-23 23:44:24520 virtual bool wifi_connecting() const = 0;
521 virtual bool wifi_connected() const = 0;
[email protected]62c7ef32010-03-23 23:44:24522
[email protected]21e744602010-10-16 03:16:53523 // Return the active Cellular network (or a default structure if none active).
[email protected]37eec142010-12-02 18:47:09524 virtual const CellularNetwork* cellular_network() const = 0;
[email protected]62c7ef32010-03-23 23:44:24525 virtual bool cellular_connecting() const = 0;
526 virtual bool cellular_connected() const = 0;
[email protected]62c7ef32010-03-23 23:44:24527
528 // Return true if any network is currently connected.
529 virtual bool Connected() const = 0;
530
531 // Return true if any network is currently connecting.
532 virtual bool Connecting() const = 0;
533
534 // Returns the current IP address if connected. If not, returns empty string.
[email protected]460c3f12010-11-08 18:20:58535 virtual const std::string& IPAddress() const = 0;
[email protected]62c7ef32010-03-23 23:44:24536
537 // Returns the current list of wifi networks.
538 virtual const WifiNetworkVector& wifi_networks() const = 0;
539
[email protected]665d7d62010-04-20 23:32:49540 // Returns the list of remembered wifi networks.
541 virtual const WifiNetworkVector& remembered_wifi_networks() const = 0;
542
[email protected]62c7ef32010-03-23 23:44:24543 // Returns the current list of cellular networks.
544 virtual const CellularNetworkVector& cellular_networks() const = 0;
545
[email protected]d1dae8a52010-12-02 21:27:42546 // Search the current list of networks by path and if the network
547 // is available, copy the result and return true.
[email protected]45066d52010-10-29 17:24:57548 virtual WifiNetwork* FindWifiNetworkByPath(const std::string& path) = 0;
549 virtual CellularNetwork* FindCellularNetworkByPath(
550 const std::string& path) = 0;
551
[email protected]f9384b552010-06-28 23:02:26552
[email protected]62c7ef32010-03-23 23:44:24553 // Request a scan for new wifi networks.
554 virtual void RequestWifiScan() = 0;
555
[email protected]63259a52010-07-15 10:55:38556 // Reads out the results of the last wifi scan. These results are not
557 // pre-cached in the library, so the call may block whilst the results are
558 // read over IPC.
559 // Returns false if an error occurred in reading the results. Note that
560 // a true return code only indicates the result set was successfully read,
561 // it does not imply a scan has successfully completed yet.
562 virtual bool GetWifiAccessPoints(WifiAccessPointVector* result) = 0;
563
564 // TODO(joth): Add GetCellTowers to retrieve a CellTowerVector.
565
[email protected]62c7ef32010-03-23 23:44:24566 // Connect to the specified wireless network with password.
[email protected]fe3a05092010-11-24 23:53:16567 // Returns false if the attempt fails immediately (e.g. passphrase too short)
568 // and sets network->error().
569 virtual bool ConnectToWifiNetwork(WifiNetwork* network,
[email protected]4a5c59c82010-06-30 21:03:34570 const std::string& password,
571 const std::string& identity,
572 const std::string& certpath) = 0;
[email protected]62c7ef32010-03-23 23:44:24573
[email protected]0673a282010-11-02 20:41:44574 // Connect to the specified network with security, ssid, and password.
[email protected]e027da192010-11-08 21:35:08575 // Returns false if the attempt fails immediately (e.g. passphrase too short).
576 virtual bool ConnectToWifiNetwork(ConnectionSecurity security,
[email protected]0673a282010-11-02 20:41:44577 const std::string& ssid,
[email protected]4a5c59c82010-06-30 21:03:34578 const std::string& password,
579 const std::string& identity,
580 const std::string& certpath,
[email protected]88908d62010-04-30 21:50:45581 bool auto_connect) = 0;
[email protected]62c7ef32010-03-23 23:44:24582
583 // Connect to the specified cellular network.
[email protected]e027da192010-11-08 21:35:08584 // Returns false if the attempt fails immediately.
585 virtual bool ConnectToCellularNetwork(const CellularNetwork* network) = 0;
[email protected]62c7ef32010-03-23 23:44:24586
[email protected]38017612010-10-13 18:46:00587 // Initiates cellular data plan refresh. Plan data will be passed through
588 // Network::Observer::CellularDataPlanChanged callback.
[email protected]45066d52010-10-29 17:24:57589 virtual void RefreshCellularDataPlans(const CellularNetwork* network) = 0;
[email protected]38017612010-10-13 18:46:00590
[email protected]c3a54e4b2011-01-18 04:37:05591 // Records information that cellular play payment had happened.
592 virtual void SignalCellularPlanPayment() = 0;
593
594 // Returns true if cellular plan payment had been recorded recently.
595 virtual bool HasRecentCellularPlanPayment() = 0;
596
[email protected]00e17562010-05-06 18:59:25597 // Disconnect from the specified wireless (either cellular or wifi) network.
598 virtual void DisconnectFromWirelessNetwork(
[email protected]45066d52010-10-29 17:24:57599 const WirelessNetwork* network) = 0;
[email protected]d1958fe2010-04-30 22:29:42600
[email protected]f49a0c882010-07-15 23:35:00601 // Save network information including passwords (wifi) and auto-connect.
[email protected]45066d52010-10-29 17:24:57602 virtual void SaveCellularNetwork(const CellularNetwork* network) = 0;
603 virtual void SaveWifiNetwork(const WifiNetwork* network) = 0;
[email protected]88908d62010-04-30 21:50:45604
[email protected]45066d52010-10-29 17:24:57605 // Forget the wifi network corresponding to service_path.
606 virtual void ForgetWifiNetwork(const std::string& service_path) = 0;
[email protected]665d7d62010-04-20 23:32:49607
[email protected]62c7ef32010-03-23 23:44:24608 virtual bool ethernet_available() const = 0;
609 virtual bool wifi_available() const = 0;
610 virtual bool cellular_available() const = 0;
611
612 virtual bool ethernet_enabled() const = 0;
613 virtual bool wifi_enabled() const = 0;
614 virtual bool cellular_enabled() const = 0;
615
[email protected]d3f9b882010-11-18 22:30:40616 virtual bool wifi_scanning() const = 0;
617
[email protected]ceaf8f12010-11-04 20:37:32618 virtual const Network* active_network() const = 0;
619
[email protected]62c7ef32010-03-23 23:44:24620 virtual bool offline_mode() const = 0;
621
622 // Enables/disables the ethernet network device.
623 virtual void EnableEthernetNetworkDevice(bool enable) = 0;
624
625 // Enables/disables the wifi network device.
626 virtual void EnableWifiNetworkDevice(bool enable) = 0;
627
628 // Enables/disables the cellular network device.
629 virtual void EnableCellularNetworkDevice(bool enable) = 0;
630
631 // Enables/disables offline mode.
632 virtual void EnableOfflineMode(bool enable) = 0;
633
[email protected]ea21f9c2010-10-21 08:26:54634 // Fetches IP configs and hardware address for a given device_path.
635 // The hardware address is usually a MAC address like "0011AA22BB33".
636 // |hardware_address| will be an empty string, if no hardware address is
637 // found.
[email protected]62c7ef32010-03-23 23:44:24638 virtual NetworkIPConfigVector GetIPConfigs(
[email protected]ea21f9c2010-10-21 08:26:54639 const std::string& device_path,
640 std::string* hardware_address) = 0;
[email protected]5a1c2dd2010-05-11 22:52:30641
642 // Fetches debug network info for display in about:network.
643 // The page will have a meta refresh of |refresh| seconds if |refresh| > 0.
644 virtual std::string GetHtmlInfo(int refresh) = 0;
[email protected]62c7ef32010-03-23 23:44:24645
[email protected]819a43862010-08-12 10:09:21646 // Factory function, creates a new instance and returns ownership.
647 // For normal usage, access the singleton via CrosLibrary::Get().
[email protected]617fd0d2010-08-04 20:05:17648 static NetworkLibrary* GetImpl(bool stub);
[email protected]7598ab52009-10-08 01:33:21649};
650
[email protected]b22c21c2009-10-30 00:35:00651} // namespace chromeos
652
[email protected]268b02f2010-02-04 21:07:15653#endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_