[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [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 | |
[email protected] | 268b02f | 2010-02-04 21:07:15 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |
| 6 | #define CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 8 | |
| 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
[email protected] | 0aadb27 | 2010-11-17 09:33:08 | [diff] [blame] | 12 | #include "base/gtest_prod_util.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame^] | 13 | #include "base/memory/scoped_vector.h" |
| 14 | #include "base/memory/singleton.h" |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 15 | #include "base/observer_list.h" |
[email protected] | f005394 | 2010-11-13 02:33:54 | [diff] [blame] | 16 | #include "base/string16.h" |
[email protected] | 1f41000 | 2009-10-28 04:11:00 | [diff] [blame] | 17 | #include "base/timer.h" |
[email protected] | 583dca28 | 2010-12-17 01:12:05 | [diff] [blame] | 18 | #include "third_party/cros/chromeos_network.h" |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 19 | |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 20 | class DictionaryValue; |
[email protected] | 3c1139f | 2010-10-22 06:17:42 | [diff] [blame] | 21 | class Value; |
| 22 | |
[email protected] | b22c21c | 2009-10-30 00:35:00 | [diff] [blame] | 23 | namespace chromeos { |
| 24 | |
[email protected] | 51f6caa | 2011-03-04 18:16:25 | [diff] [blame] | 25 | // Connection enums (see flimflam/include/service.h) |
| 26 | enum ConnectionType { |
| 27 | TYPE_UNKNOWN = 0, |
| 28 | TYPE_ETHERNET = 1, |
| 29 | TYPE_WIFI = 2, |
| 30 | TYPE_WIMAX = 3, |
| 31 | TYPE_BLUETOOTH = 4, |
| 32 | TYPE_CELLULAR = 5, |
[email protected] | 83c8265 | 2011-03-05 01:59:34 | [diff] [blame] | 33 | TYPE_VPN = 6, |
[email protected] | 51f6caa | 2011-03-04 18:16:25 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | enum ConnectionMode { |
| 37 | MODE_UNKNOWN = 0, |
| 38 | MODE_MANAGED = 1, |
| 39 | MODE_ADHOC = 2, |
| 40 | }; |
| 41 | |
| 42 | enum ConnectionSecurity { |
| 43 | SECURITY_UNKNOWN = 0, |
| 44 | SECURITY_NONE = 1, |
| 45 | SECURITY_WEP = 2, |
| 46 | SECURITY_WPA = 3, |
| 47 | SECURITY_RSN = 4, |
| 48 | SECURITY_8021X = 5, |
| 49 | }; |
| 50 | |
| 51 | enum ConnectionState { |
| 52 | STATE_UNKNOWN = 0, |
| 53 | STATE_IDLE = 1, |
| 54 | STATE_CARRIER = 2, |
| 55 | STATE_ASSOCIATION = 3, |
| 56 | STATE_CONFIGURATION = 4, |
| 57 | STATE_READY = 5, |
| 58 | STATE_DISCONNECT = 6, |
| 59 | STATE_FAILURE = 7, |
| 60 | STATE_ACTIVATION_FAILURE = 8 |
| 61 | }; |
| 62 | |
| 63 | enum ConnectivityState { |
| 64 | CONN_STATE_UNKNOWN = 0, |
| 65 | CONN_STATE_UNRESTRICTED = 1, |
| 66 | CONN_STATE_RESTRICTED = 2, |
| 67 | CONN_STATE_NONE = 3 |
| 68 | }; |
| 69 | |
| 70 | // Network enums (see flimflam/include/network.h) |
| 71 | enum NetworkTechnology { |
| 72 | NETWORK_TECHNOLOGY_UNKNOWN = 0, |
| 73 | NETWORK_TECHNOLOGY_1XRTT = 1, |
| 74 | NETWORK_TECHNOLOGY_EVDO = 2, |
| 75 | NETWORK_TECHNOLOGY_GPRS = 3, |
| 76 | NETWORK_TECHNOLOGY_EDGE = 4, |
| 77 | NETWORK_TECHNOLOGY_UMTS = 5, |
| 78 | NETWORK_TECHNOLOGY_HSPA = 6, |
| 79 | NETWORK_TECHNOLOGY_HSPA_PLUS = 7, |
| 80 | NETWORK_TECHNOLOGY_LTE = 8, |
| 81 | NETWORK_TECHNOLOGY_LTE_ADVANCED = 9, |
| 82 | }; |
| 83 | |
| 84 | enum ActivationState { |
| 85 | ACTIVATION_STATE_UNKNOWN = 0, |
| 86 | ACTIVATION_STATE_ACTIVATED = 1, |
| 87 | ACTIVATION_STATE_ACTIVATING = 2, |
| 88 | ACTIVATION_STATE_NOT_ACTIVATED = 3, |
| 89 | ACTIVATION_STATE_PARTIALLY_ACTIVATED = 4, |
| 90 | }; |
| 91 | |
| 92 | enum NetworkRoamingState { |
| 93 | ROAMING_STATE_UNKNOWN = 0, |
| 94 | ROAMING_STATE_HOME = 1, |
| 95 | ROAMING_STATE_ROAMING = 2, |
| 96 | }; |
| 97 | |
| 98 | // connection errors (see flimflam/include/service.h) |
| 99 | enum ConnectionError { |
| 100 | ERROR_UNKNOWN = 0, |
| 101 | ERROR_OUT_OF_RANGE = 1, |
| 102 | ERROR_PIN_MISSING = 2, |
| 103 | ERROR_DHCP_FAILED = 3, |
| 104 | ERROR_CONNECT_FAILED = 4, |
| 105 | ERROR_BAD_PASSPHRASE = 5, |
| 106 | ERROR_BAD_WEPKEY = 6, |
| 107 | ERROR_ACTIVATION_FAILED = 7, |
| 108 | ERROR_NEED_EVDO = 8, |
| 109 | ERROR_NEED_HOME_NETWORK = 9, |
| 110 | ERROR_OTASP_FAILED = 10, |
| 111 | ERROR_AAA_FAILED = 11, |
| 112 | }; |
| 113 | |
[email protected] | 9100a36 | 2011-03-22 08:20:26 | [diff] [blame] | 114 | // We are currently only supporting setting a single EAP Method. |
| 115 | enum EAPMethod { |
| 116 | EAP_METHOD_UNKNOWN = 0, |
| 117 | EAP_METHOD_PEAP = 1, |
| 118 | EAP_METHOD_TLS = 2, |
| 119 | EAP_METHOD_TTLS = 3, |
| 120 | EAP_METHOD_LEAP = 4 |
| 121 | }; |
| 122 | |
| 123 | // We are currently only supporting setting a single EAP phase 2 authentication. |
| 124 | enum EAPPhase2Auth { |
| 125 | EAP_PHASE_2_AUTH_AUTO = 0, |
| 126 | EAP_PHASE_2_AUTH_MD5 = 1, |
| 127 | EAP_PHASE_2_AUTH_MSCHAPV2 = 2, |
| 128 | EAP_PHASE_2_AUTH_MSCHAP = 3, |
| 129 | EAP_PHASE_2_AUTH_PAP = 4, |
| 130 | EAP_PHASE_2_AUTH_CHAP = 5 |
| 131 | }; |
| 132 | |
[email protected] | 543a79a | 2010-10-20 01:14:58 | [diff] [blame] | 133 | // Cellular network is considered low data when less than 60 minues. |
| 134 | static const int kCellularDataLowSecs = 60 * 60; |
| 135 | |
| 136 | // Cellular network is considered low data when less than 30 minues. |
| 137 | static const int kCellularDataVeryLowSecs = 30 * 60; |
| 138 | |
| 139 | // Cellular network is considered low data when less than 100MB. |
| 140 | static const int kCellularDataLowBytes = 100 * 1024 * 1024; |
| 141 | |
| 142 | // Cellular network is considered very low data when less than 50MB. |
| 143 | static const int kCellularDataVeryLowBytes = 50 * 1024 * 1024; |
| 144 | |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 145 | // Contains data related to the flimflam.Device interface, |
| 146 | // e.g. ethernet, wifi, cellular. |
| 147 | class NetworkDevice { |
| 148 | public: |
| 149 | explicit NetworkDevice(const std::string& device_path); |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 150 | |
| 151 | // Device info. |
| 152 | const std::string& device_path() const { return device_path_; } |
| 153 | const std::string& name() const { return name_; } |
| 154 | ConnectionType type() const { return type_; } |
| 155 | bool scanning() const { return scanning_; } |
| 156 | const std::string& meid() const { return MEID_; } |
| 157 | const std::string& imei() const { return IMEI_; } |
| 158 | const std::string& imsi() const { return IMSI_; } |
| 159 | const std::string& esn() const { return ESN_; } |
| 160 | const std::string& mdn() const { return MDN_; } |
| 161 | const std::string& min() const { return MIN_; } |
| 162 | const std::string& model_id() const { return model_id_; } |
| 163 | const std::string& manufacturer() const { return manufacturer_; } |
| 164 | const std::string& firmware_revision() const { return firmware_revision_; } |
| 165 | const std::string& hardware_revision() const { return hardware_revision_; } |
| 166 | const std::string& last_update() const { return last_update_; } |
| 167 | const unsigned int prl_version() const { return PRL_version_; } |
| 168 | |
[email protected] | 07ed5c08 | 2011-03-02 19:50:18 | [diff] [blame] | 169 | private: |
| 170 | bool ParseValue(int index, const Value* value); |
| 171 | void ParseInfo(const DictionaryValue* info); |
| 172 | |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 173 | // General device info. |
| 174 | std::string device_path_; |
| 175 | std::string name_; |
| 176 | ConnectionType type_; |
| 177 | bool scanning_; |
| 178 | // Cellular specific device info. |
| 179 | std::string carrier_; |
| 180 | std::string MEID_; |
| 181 | std::string IMEI_; |
| 182 | std::string IMSI_; |
| 183 | std::string ESN_; |
| 184 | std::string MDN_; |
| 185 | std::string MIN_; |
| 186 | std::string model_id_; |
| 187 | std::string manufacturer_; |
| 188 | std::string firmware_revision_; |
| 189 | std::string hardware_revision_; |
| 190 | std::string last_update_; |
| 191 | int PRL_version_; |
[email protected] | 07ed5c08 | 2011-03-02 19:50:18 | [diff] [blame] | 192 | |
| 193 | friend class NetworkLibraryImpl; |
| 194 | DISALLOW_COPY_AND_ASSIGN(NetworkDevice); |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 195 | }; |
| 196 | |
| 197 | // Contains data common to all network service types. |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 198 | class Network { |
| 199 | public: |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 200 | virtual ~Network() {} |
| 201 | |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 202 | const std::string& service_path() const { return service_path_; } |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 203 | const std::string& name() const { return name_; } |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 204 | const std::string& device_path() const { return device_path_; } |
| 205 | const std::string& ip_address() const { return ip_address_; } |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 206 | ConnectionType type() const { return type_; } |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 207 | ConnectionMode mode() const { return mode_; } |
[email protected] | 9a24152e | 2010-10-08 23:15:31 | [diff] [blame] | 208 | ConnectionState connection_state() const { return state_; } |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 209 | bool connecting() const { return state_ == STATE_ASSOCIATION || |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 210 | state_ == STATE_CONFIGURATION || |
| 211 | state_ == STATE_CARRIER; } |
[email protected] | 8df038b | 2010-10-28 22:56:46 | [diff] [blame] | 212 | bool configuring() const { return state_ == STATE_CONFIGURATION; } |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 213 | bool connected() const { return state_ == STATE_READY; } |
| 214 | bool connecting_or_connected() const { return connecting() || connected(); } |
| 215 | bool failed() const { return state_ == STATE_FAILURE; } |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 216 | bool failed_or_disconnected() const { |
| 217 | return failed() || state_ == STATE_IDLE; |
| 218 | } |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 219 | ConnectionError error() const { return error_; } |
[email protected] | 89ccd24 | 2010-10-12 08:58:27 | [diff] [blame] | 220 | ConnectionState state() const { return state_; } |
[email protected] | 9100a36 | 2011-03-22 08:20:26 | [diff] [blame] | 221 | // Is this network connectable. Currently, this is mainly used by 802.1x |
| 222 | // networks to specify that the network is not configured yet. |
[email protected] | ca9f670 | 2010-11-17 01:28:14 | [diff] [blame] | 223 | bool connectable() const { return connectable_; } |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 224 | // Is this the active network, i.e, the one through which |
| 225 | // network traffic is being routed? A network can be connected, |
| 226 | // but not be carrying traffic. |
| 227 | bool is_active() const { return is_active_; } |
[email protected] | 07ed5c08 | 2011-03-02 19:50:18 | [diff] [blame] | 228 | bool favorite() const { return favorite_; } |
| 229 | bool auto_connect() const { return auto_connect_; } |
| 230 | ConnectivityState connectivity_state() const { return connectivity_state_; } |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 231 | |
[email protected] | 07ed5c08 | 2011-03-02 19:50:18 | [diff] [blame] | 232 | // We don't have a setter for |favorite_| because to unfavorite a network is |
| 233 | // equivalent to forget a network, so we call forget network on cros for |
| 234 | // that. See ForgetWifiNetwork(). |
[email protected] | d63f475 | 2011-03-07 21:37:18 | [diff] [blame] | 235 | void SetAutoConnect(bool auto_connect); |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 236 | |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 237 | // Return a string representation of the state code. |
[email protected] | caf063d | 2010-10-11 18:58:22 | [diff] [blame] | 238 | std::string GetStateString() const; |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 239 | |
| 240 | // Return a string representation of the error code. |
[email protected] | caf063d | 2010-10-11 18:58:22 | [diff] [blame] | 241 | std::string GetErrorString() const; |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 242 | |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 243 | protected: |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 244 | Network(const std::string& service_path, ConnectionType type) |
| 245 | : state_(STATE_UNKNOWN), |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 246 | error_(ERROR_UNKNOWN), |
[email protected] | ca9f670 | 2010-11-17 01:28:14 | [diff] [blame] | 247 | connectable_(true), |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 248 | is_active_(false), |
[email protected] | 07ed5c08 | 2011-03-02 19:50:18 | [diff] [blame] | 249 | favorite_(false), |
| 250 | auto_connect_(false), |
| 251 | connectivity_state_(CONN_STATE_UNKNOWN), |
[email protected] | 83c8265 | 2011-03-05 01:59:34 | [diff] [blame] | 252 | priority_(0), |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 253 | service_path_(service_path), |
[email protected] | 07ed5c08 | 2011-03-02 19:50:18 | [diff] [blame] | 254 | type_(type) {} |
| 255 | |
| 256 | // Parse name/value pairs from libcros. |
| 257 | virtual bool ParseValue(int index, const Value* value); |
| 258 | void ParseInfo(const DictionaryValue* info); |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 259 | |
[email protected] | ebbdaaba | 2011-03-24 17:45:16 | [diff] [blame] | 260 | // Methods to asynchronously set network service properties |
[email protected] | d63f475 | 2011-03-07 21:37:18 | [diff] [blame] | 261 | virtual void SetStringProperty(const char* prop, const std::string& str); |
| 262 | virtual void SetBooleanProperty(const char* prop, bool b); |
| 263 | virtual void SetIntegerProperty(const char* prop, int i); |
[email protected] | ebbdaaba | 2011-03-24 17:45:16 | [diff] [blame] | 264 | virtual void ClearProperty(const char* prop); |
| 265 | // This will clear the property if string is empty. Otherwise, it will set it. |
| 266 | virtual void SetOrClearStringProperty(const char* prop, |
| 267 | const std::string& str); |
[email protected] | d63f475 | 2011-03-07 21:37:18 | [diff] [blame] | 268 | |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 269 | std::string device_path_; |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 270 | std::string name_; |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 271 | std::string ip_address_; |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 272 | ConnectionMode mode_; |
[email protected] | 9a24152e | 2010-10-08 23:15:31 | [diff] [blame] | 273 | ConnectionState state_; |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 274 | ConnectionError error_; |
[email protected] | ca9f670 | 2010-11-17 01:28:14 | [diff] [blame] | 275 | bool connectable_; |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 276 | bool is_active_; |
[email protected] | 07ed5c08 | 2011-03-02 19:50:18 | [diff] [blame] | 277 | bool favorite_; |
| 278 | bool auto_connect_; |
| 279 | ConnectivityState connectivity_state_; |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 280 | |
| 281 | private: |
[email protected] | 07ed5c08 | 2011-03-02 19:50:18 | [diff] [blame] | 282 | void set_name(const std::string& name) { name_ = name; } |
| 283 | void set_connecting(bool connecting) { |
| 284 | state_ = (connecting ? STATE_ASSOCIATION : STATE_IDLE); |
| 285 | } |
| 286 | void set_connected(bool connected) { |
| 287 | state_ = (connected ? STATE_READY : STATE_IDLE); |
| 288 | } |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 289 | void set_state(ConnectionState state) { state_ = state; } |
[email protected] | ca9f670 | 2010-11-17 01:28:14 | [diff] [blame] | 290 | void set_connectable(bool connectable) { connectable_ = connectable; } |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 291 | void set_active(bool is_active) { is_active_ = is_active; } |
[email protected] | fe3a0509 | 2010-11-24 23:53:16 | [diff] [blame] | 292 | void set_error(ConnectionError error) { error_ = error; } |
[email protected] | 07ed5c08 | 2011-03-02 19:50:18 | [diff] [blame] | 293 | void set_connectivity_state(ConnectivityState connectivity_state) { |
| 294 | connectivity_state_ = connectivity_state; |
| 295 | } |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 296 | |
[email protected] | ebbdaaba | 2011-03-24 17:45:16 | [diff] [blame] | 297 | virtual void SetValueProperty(const char* prop, Value* val); |
| 298 | |
[email protected] | 9e32029 | 2010-11-18 00:52:29 | [diff] [blame] | 299 | // Initialize the IP address field |
| 300 | void InitIPAddress(); |
| 301 | |
[email protected] | 83c8265 | 2011-03-05 01:59:34 | [diff] [blame] | 302 | // Priority value, corresponds to index in list from flimflam (0 = highest) |
| 303 | int priority_; |
| 304 | |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 305 | // These must not be modified after construction. |
| 306 | std::string service_path_; |
| 307 | ConnectionType type_; |
| 308 | |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 309 | friend class NetworkLibraryImpl; |
[email protected] | 07ed5c08 | 2011-03-02 19:50:18 | [diff] [blame] | 310 | // ChangeAutoConnectSaveTest accesses |favorite_|. |
| 311 | FRIEND_TEST_ALL_PREFIXES(WifiConfigViewTest, ChangeAutoConnectSaveTest); |
[email protected] | 0fb499a | 2009-11-10 21:03:33 | [diff] [blame] | 312 | }; |
| 313 | |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 314 | // Class for networks of TYPE_ETHERNET. |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 315 | class EthernetNetwork : public Network { |
| 316 | public: |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 317 | explicit EthernetNetwork(const std::string& service_path) : |
| 318 | Network(service_path, TYPE_ETHERNET) { |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 319 | } |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 320 | }; |
| 321 | |
[email protected] | 83c8265 | 2011-03-05 01:59:34 | [diff] [blame] | 322 | // Class for networks of TYPE_VPN. |
| 323 | class VirtualNetwork : public Network { |
| 324 | public: |
| 325 | explicit VirtualNetwork(const std::string& service_path) : |
| 326 | Network(service_path, TYPE_VPN) { |
| 327 | } |
| 328 | }; |
| 329 | typedef std::vector<VirtualNetwork*> VirtualNetworkVector; |
| 330 | |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 331 | // Base class for networks of TYPE_WIFI or TYPE_CELLULAR. |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 332 | class WirelessNetwork : public Network { |
| 333 | public: |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 334 | int strength() const { return strength_; } |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 335 | |
| 336 | protected: |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 337 | WirelessNetwork(const std::string& service_path, ConnectionType type) |
| 338 | : Network(service_path, type), |
[email protected] | 07ed5c08 | 2011-03-02 19:50:18 | [diff] [blame] | 339 | strength_(0) {} |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 340 | int strength_; |
[email protected] | 07ed5c08 | 2011-03-02 19:50:18 | [diff] [blame] | 341 | |
| 342 | // Network overrides. |
| 343 | virtual bool ParseValue(int index, const Value* value); |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 344 | |
| 345 | private: |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 346 | void set_strength(int strength) { strength_ = strength; } |
| 347 | |
| 348 | friend class NetworkLibraryImpl; |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 349 | }; |
| 350 | |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 351 | // Class for networks of TYPE_CELLULAR. |
| 352 | class CellularDataPlan; |
[email protected] | 170d19c | 2011-03-03 20:42:08 | [diff] [blame] | 353 | |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 354 | class CellularNetwork : public WirelessNetwork { |
| 355 | public: |
[email protected] | 543a79a | 2010-10-20 01:14:58 | [diff] [blame] | 356 | enum DataLeft { |
[email protected] | eda4d0c | 2011-01-24 19:52:02 | [diff] [blame] | 357 | DATA_UNKNOWN, |
[email protected] | 543a79a | 2010-10-20 01:14:58 | [diff] [blame] | 358 | DATA_NORMAL, |
| 359 | DATA_LOW, |
| 360 | DATA_VERY_LOW, |
| 361 | DATA_NONE |
| 362 | }; |
| 363 | |
[email protected] | 05f06df | 2010-11-04 17:31:16 | [diff] [blame] | 364 | virtual ~CellularNetwork(); |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 365 | |
| 366 | explicit CellularNetwork(const std::string& service_path) |
| 367 | : WirelessNetwork(service_path, TYPE_CELLULAR), |
| 368 | activation_state_(ACTIVATION_STATE_UNKNOWN), |
| 369 | network_technology_(NETWORK_TECHNOLOGY_UNKNOWN), |
| 370 | roaming_state_(ROAMING_STATE_UNKNOWN), |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 371 | data_left_(DATA_UNKNOWN) { |
| 372 | } |
[email protected] | 9d3f7d5e | 2010-09-25 06:17:04 | [diff] [blame] | 373 | // Starts device activation process. Returns false if the device state does |
| 374 | // not permit activation. |
| 375 | bool StartActivation() const; |
[email protected] | a4a89cf | 2011-03-16 18:17:54 | [diff] [blame] | 376 | // Requests data plans if the network is conencted and activated. |
| 377 | // Plan data will be passed through Network::Observer::CellularDataPlanChanged |
| 378 | // callback. |
| 379 | void RefreshDataPlansIfNeeded() const; |
| 380 | |
[email protected] | ad75cda | 2010-09-28 23:18:46 | [diff] [blame] | 381 | const ActivationState activation_state() const { return activation_state_; } |
[email protected] | a4a89cf | 2011-03-16 18:17:54 | [diff] [blame] | 382 | bool activated() const { |
| 383 | return activation_state() == ACTIVATION_STATE_ACTIVATED; |
| 384 | } |
[email protected] | 17cc052 | 2010-10-01 20:19:12 | [diff] [blame] | 385 | const NetworkTechnology network_technology() const { |
[email protected] | caf063d | 2010-10-11 18:58:22 | [diff] [blame] | 386 | return network_technology_; |
| 387 | } |
[email protected] | 17cc052 | 2010-10-01 20:19:12 | [diff] [blame] | 388 | const NetworkRoamingState roaming_state() const { return roaming_state_; } |
[email protected] | 353e0dd8 | 2010-11-22 08:39:31 | [diff] [blame] | 389 | bool restricted_pool() const { |
| 390 | return connectivity_state() == CONN_STATE_RESTRICTED; |
| 391 | } |
[email protected] | f005394 | 2010-11-13 02:33:54 | [diff] [blame] | 392 | bool needs_new_plan() const { |
[email protected] | a4a89cf | 2011-03-16 18:17:54 | [diff] [blame] | 393 | return restricted_pool() && connected() && activated(); |
[email protected] | f005394 | 2010-11-13 02:33:54 | [diff] [blame] | 394 | } |
[email protected] | 9a24152e | 2010-10-08 23:15:31 | [diff] [blame] | 395 | const std::string& operator_name() const { return operator_name_; } |
| 396 | const std::string& operator_code() const { return operator_code_; } |
[email protected] | 9d3f7d5e | 2010-09-25 06:17:04 | [diff] [blame] | 397 | const std::string& payment_url() const { return payment_url_; } |
[email protected] | 07ed5c08 | 2011-03-02 19:50:18 | [diff] [blame] | 398 | const std::string& usage_url() const { return usage_url_; } |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 399 | DataLeft data_left() const { return data_left_; } |
| 400 | |
| 401 | // Misc. |
[email protected] | 633e5c0 | 2010-11-19 22:11:35 | [diff] [blame] | 402 | bool is_gsm() const { |
| 403 | return network_technology_ != NETWORK_TECHNOLOGY_EVDO && |
| 404 | network_technology_ != NETWORK_TECHNOLOGY_1XRTT && |
| 405 | network_technology_ != NETWORK_TECHNOLOGY_UNKNOWN; |
| 406 | } |
[email protected] | 3cc2e59 | 2010-06-21 13:45:43 | [diff] [blame] | 407 | |
[email protected] | caf063d | 2010-10-11 18:58:22 | [diff] [blame] | 408 | // Return a string representation of network technology. |
| 409 | std::string GetNetworkTechnologyString() const; |
[email protected] | 353e0dd8 | 2010-11-22 08:39:31 | [diff] [blame] | 410 | // Return a string representation of connectivity state. |
| 411 | std::string GetConnectivityStateString() const; |
[email protected] | caf063d | 2010-10-11 18:58:22 | [diff] [blame] | 412 | // Return a string representation of activation state. |
| 413 | std::string GetActivationStateString() const; |
| 414 | // Return a string representation of roaming state. |
| 415 | std::string GetRoamingStateString() const; |
| 416 | |
[email protected] | 3c1139f | 2010-10-22 06:17:42 | [diff] [blame] | 417 | // Return a string representation of |activation_state|. |
| 418 | static std::string ActivationStateToString(ActivationState activation_state); |
| 419 | |
[email protected] | 9d3f7d5e | 2010-09-25 06:17:04 | [diff] [blame] | 420 | protected: |
[email protected] | 07ed5c08 | 2011-03-02 19:50:18 | [diff] [blame] | 421 | // WirelessNetwork overrides. |
| 422 | virtual bool ParseValue(int index, const Value* value); |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 423 | |
[email protected] | ad75cda | 2010-09-28 23:18:46 | [diff] [blame] | 424 | ActivationState activation_state_; |
[email protected] | 17cc052 | 2010-10-01 20:19:12 | [diff] [blame] | 425 | NetworkTechnology network_technology_; |
| 426 | NetworkRoamingState roaming_state_; |
[email protected] | 7b947813da | 2010-10-07 23:47:42 | [diff] [blame] | 427 | // Carrier Info |
| 428 | std::string operator_name_; |
| 429 | std::string operator_code_; |
[email protected] | 9d3f7d5e | 2010-09-25 06:17:04 | [diff] [blame] | 430 | std::string payment_url_; |
[email protected] | 07ed5c08 | 2011-03-02 19:50:18 | [diff] [blame] | 431 | std::string usage_url_; |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 432 | // Cached values |
| 433 | DataLeft data_left_; // Updated when data plans are updated. |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 434 | |
| 435 | private: |
| 436 | void set_activation_state(ActivationState state) { |
| 437 | activation_state_ = state; |
| 438 | } |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 439 | void set_payment_url(const std::string& url) { payment_url_ = url; } |
[email protected] | 07ed5c08 | 2011-03-02 19:50:18 | [diff] [blame] | 440 | void set_usage_url(const std::string& url) { usage_url_ = url; } |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 441 | void set_network_technology(NetworkTechnology technology) { |
| 442 | network_technology_ = technology; |
| 443 | } |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 444 | void set_roaming_state(NetworkRoamingState state) { roaming_state_ = state; } |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 445 | void set_data_left(DataLeft data_left) { data_left_ = data_left; } |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 446 | |
| 447 | friend class NetworkLibraryImpl; |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 448 | }; |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 449 | typedef std::vector<CellularNetwork*> CellularNetworkVector; |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 450 | |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 451 | // Class for networks of TYPE_WIFI. |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 452 | class WifiNetwork : public WirelessNetwork { |
| 453 | public: |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 454 | explicit WifiNetwork(const std::string& service_path) |
| 455 | : WirelessNetwork(service_path, TYPE_WIFI), |
[email protected] | d63f475 | 2011-03-07 21:37:18 | [diff] [blame] | 456 | encryption_(SECURITY_NONE), |
[email protected] | 9100a36 | 2011-03-22 08:20:26 | [diff] [blame] | 457 | passphrase_required_(false), |
| 458 | eap_method_(EAP_METHOD_UNKNOWN), |
| 459 | eap_phase_2_auth_(EAP_PHASE_2_AUTH_AUTO), |
| 460 | eap_use_system_cas_(true) { |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 461 | } |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 462 | |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 463 | bool encrypted() const { return encryption_ != SECURITY_NONE; } |
| 464 | ConnectionSecurity encryption() const { return encryption_; } |
| 465 | const std::string& passphrase() const { return passphrase_; } |
[email protected] | d4731385 | 2010-05-11 23:01:04 | [diff] [blame] | 466 | const std::string& identity() const { return identity_; } |
| 467 | const std::string& cert_path() const { return cert_path_; } |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 468 | |
[email protected] | 9100a36 | 2011-03-22 08:20:26 | [diff] [blame] | 469 | EAPMethod eap_method() const { return eap_method_; } |
| 470 | EAPPhase2Auth eap_phase_2_auth() const { return eap_phase_2_auth_; } |
| 471 | const std::string& eap_server_ca_cert() const { |
| 472 | return eap_server_ca_cert_path_; } |
| 473 | const std::string& eap_client_cert() const { return eap_client_cert_path_; } |
| 474 | const bool eap_use_system_cas() const { return eap_use_system_cas_; } |
| 475 | const std::string& eap_identity() const { return eap_identity_; } |
| 476 | const std::string& eap_anonymous_identity() const { |
| 477 | return eap_anonymous_identity_; } |
| 478 | const std::string& eap_passphrase() const { return eap_passphrase_; } |
| 479 | |
[email protected] | 2f5a9a85 | 2011-03-19 00:54:34 | [diff] [blame] | 480 | const std::string& GetPassphrase() const; |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 481 | |
[email protected] | d63f475 | 2011-03-07 21:37:18 | [diff] [blame] | 482 | void SetPassphrase(const std::string& passphrase); |
| 483 | void SetIdentity(const std::string& identity); |
| 484 | void SetCertPath(const std::string& cert_path); |
| 485 | |
[email protected] | 9100a36 | 2011-03-22 08:20:26 | [diff] [blame] | 486 | // 802.1x properties |
| 487 | void SetEAPMethod(EAPMethod method); |
| 488 | void SetEAPPhase2Auth(EAPPhase2Auth auth); |
| 489 | void SetEAPServerCACert(const std::string& cert_path); |
| 490 | void SetEAPClientCert(const std::string& cert_path); |
| 491 | void SetEAPUseSystemCAs(bool use_system_cas); |
| 492 | void SetEAPIdentity(const std::string& identity); |
| 493 | void SetEAPAnonymousIdentity(const std::string& identity); |
| 494 | void SetEAPPassphrase(const std::string& passphrase); |
| 495 | |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 496 | // Return a string representation of the encryption code. |
| 497 | // This not translated and should be only used for debugging purposes. |
| 498 | std::string GetEncryptionString(); |
| 499 | |
[email protected] | 8416136 | 2010-12-15 16:50:33 | [diff] [blame] | 500 | // Return true if a passphrase or other input is required to connect. |
| 501 | bool IsPassphraseRequired() const; |
| 502 | |
[email protected] | c1ee006 | 2010-10-14 18:37:22 | [diff] [blame] | 503 | // Return true if cert_path_ indicates that we have loaded the certificate. |
| 504 | bool IsCertificateLoaded() const; |
| 505 | |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 506 | protected: |
[email protected] | 07ed5c08 | 2011-03-02 19:50:18 | [diff] [blame] | 507 | // WirelessNetwork overrides. |
| 508 | virtual bool ParseValue(int index, const Value* value); |
| 509 | |
[email protected] | d63f475 | 2011-03-07 21:37:18 | [diff] [blame] | 510 | private: |
[email protected] | 2f5a9a85 | 2011-03-19 00:54:34 | [diff] [blame] | 511 | void set_encryption(ConnectionSecurity encryption) { |
| 512 | encryption_ = encryption; |
| 513 | } |
| 514 | void set_passphrase(const std::string& passphrase) { |
| 515 | passphrase_ = passphrase; |
| 516 | } |
[email protected] | d63f475 | 2011-03-07 21:37:18 | [diff] [blame] | 517 | void set_passphrase_required(bool passphrase_required) { |
| 518 | passphrase_required_ = passphrase_required; |
| 519 | } |
[email protected] | 2f5a9a85 | 2011-03-19 00:54:34 | [diff] [blame] | 520 | void set_identity(const std::string& identity) { |
| 521 | identity_ = identity; |
| 522 | } |
| 523 | void set_cert_path(const std::string& cert_path) { |
| 524 | cert_path_ = cert_path; |
| 525 | } |
[email protected] | d63f475 | 2011-03-07 21:37:18 | [diff] [blame] | 526 | |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 527 | ConnectionSecurity encryption_; |
| 528 | std::string passphrase_; |
[email protected] | e027da19 | 2010-11-08 21:35:08 | [diff] [blame] | 529 | bool passphrase_required_; |
[email protected] | d4731385 | 2010-05-11 23:01:04 | [diff] [blame] | 530 | std::string identity_; |
| 531 | std::string cert_path_; |
[email protected] | d63f475 | 2011-03-07 21:37:18 | [diff] [blame] | 532 | |
[email protected] | 9100a36 | 2011-03-22 08:20:26 | [diff] [blame] | 533 | EAPMethod eap_method_; |
| 534 | EAPPhase2Auth eap_phase_2_auth_; |
| 535 | std::string eap_server_ca_cert_path_; |
| 536 | std::string eap_client_cert_path_; |
| 537 | bool eap_use_system_cas_; |
| 538 | std::string eap_identity_; |
| 539 | std::string eap_anonymous_identity_; |
| 540 | std::string eap_passphrase_; |
| 541 | |
[email protected] | 2f5a9a85 | 2011-03-19 00:54:34 | [diff] [blame] | 542 | // Internal state (not stored in flimflam). |
| 543 | // Passphrase set by user (stored for UI). |
| 544 | std::string user_passphrase_; |
| 545 | |
[email protected] | d63f475 | 2011-03-07 21:37:18 | [diff] [blame] | 546 | friend class NetworkLibraryImpl; |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 547 | }; |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 548 | typedef std::vector<WifiNetwork*> WifiNetworkVector; |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 549 | |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 550 | // Cellular Data Plan management. |
| 551 | class CellularDataPlan { |
| 552 | public: |
| 553 | CellularDataPlan() |
| 554 | : plan_name("Unknown"), |
| 555 | plan_type(CELLULAR_DATA_PLAN_UNLIMITED), |
| 556 | plan_data_bytes(0), |
| 557 | data_bytes_used(0) { } |
| 558 | explicit CellularDataPlan(const CellularDataPlanInfo &plan) |
| 559 | : plan_name(plan.plan_name ? plan.plan_name : ""), |
| 560 | plan_type(plan.plan_type), |
| 561 | update_time(base::Time::FromInternalValue(plan.update_time)), |
| 562 | plan_start_time(base::Time::FromInternalValue(plan.plan_start_time)), |
| 563 | plan_end_time(base::Time::FromInternalValue(plan.plan_end_time)), |
| 564 | plan_data_bytes(plan.plan_data_bytes), |
| 565 | data_bytes_used(plan.data_bytes_used) { } |
| 566 | // Formats cellular plan description. |
| 567 | string16 GetPlanDesciption() const; |
| 568 | // Evaluates cellular plans status and returns warning string if it is near |
| 569 | // expiration. |
| 570 | string16 GetRemainingWarning() const; |
| 571 | // Formats remaining plan data description. |
| 572 | string16 GetDataRemainingDesciption() const; |
| 573 | // Formats plan expiration description. |
| 574 | string16 GetPlanExpiration() const; |
| 575 | // Formats plan usage info. |
| 576 | string16 GetUsageInfo() const; |
| 577 | // Returns a unique string for this plan that can be used for comparisons. |
| 578 | std::string GetUniqueIdentifier() const; |
| 579 | base::TimeDelta remaining_time() const; |
| 580 | int64 remaining_minutes() const; |
[email protected] | 170d19c | 2011-03-03 20:42:08 | [diff] [blame] | 581 | // Returns plan data remaining in bytes. |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 582 | int64 remaining_data() const; |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 583 | // TODO(stevenjb): Make these private with accessors and properly named. |
| 584 | std::string plan_name; |
| 585 | CellularDataPlanType plan_type; |
| 586 | base::Time update_time; |
| 587 | base::Time plan_start_time; |
| 588 | base::Time plan_end_time; |
| 589 | int64 plan_data_bytes; |
| 590 | int64 data_bytes_used; |
| 591 | }; |
| 592 | typedef ScopedVector<CellularDataPlan> CellularDataPlanVector; |
[email protected] | 38d387cd | 2010-01-14 01:00:39 | [diff] [blame] | 593 | |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 594 | // Geolocation data. |
[email protected] | 63259a5 | 2010-07-15 10:55:38 | [diff] [blame] | 595 | struct CellTower { |
| 596 | enum RadioType { |
| 597 | RADIOTYPE_GSM, |
| 598 | RADIOTYPE_CDMA, |
| 599 | RADIOTYPE_WCDMA, |
| 600 | } radio_type; // GSM/WCDMA CDMA |
| 601 | int mobile_country_code; // MCC MCC |
| 602 | int mobile_network_code; // MNC SID |
| 603 | int location_area_code; // LAC NID |
| 604 | int cell_id; // CID BID |
[email protected] | 17f12b5 | 2010-10-02 02:08:16 | [diff] [blame] | 605 | base::Time timestamp; // Timestamp when this cell was primary |
| 606 | int signal_strength; // Radio signal strength measured in dBm. |
| 607 | int timing_advance; // Represents the distance from the cell tower. |
| 608 | // Each unit is roughly 550 meters. |
[email protected] | 63259a5 | 2010-07-15 10:55:38 | [diff] [blame] | 609 | }; |
| 610 | |
| 611 | struct WifiAccessPoint { |
| 612 | std::string mac_address; // The mac address of the WiFi node. |
| 613 | std::string name; // The SSID of the WiFi node. |
| 614 | base::Time timestamp; // Timestamp when this AP was detected. |
| 615 | int signal_strength; // Radio signal strength measured in dBm. |
| 616 | int signal_to_noise; // Current signal to noise ratio measured in dB. |
| 617 | int channel; // Wifi channel number. |
| 618 | }; |
| 619 | |
| 620 | typedef std::vector<CellTower> CellTowerVector; |
| 621 | typedef std::vector<WifiAccessPoint> WifiAccessPointVector; |
| 622 | |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 623 | // IP Configuration. |
[email protected] | 3fb19f5c | 2010-02-17 00:49:50 | [diff] [blame] | 624 | struct NetworkIPConfig { |
| 625 | NetworkIPConfig(const std::string& device_path, IPConfigType type, |
| 626 | const std::string& address, const std::string& netmask, |
| 627 | const std::string& gateway, const std::string& name_servers) |
| 628 | : device_path(device_path), |
| 629 | type(type), |
| 630 | address(address), |
| 631 | netmask(netmask), |
| 632 | gateway(gateway), |
| 633 | name_servers(name_servers) {} |
| 634 | |
| 635 | // NetworkIPConfigs are sorted by tyoe. |
| 636 | bool operator< (const NetworkIPConfig& other) const { |
| 637 | return type < other.type; |
| 638 | } |
| 639 | |
| 640 | std::string device_path; |
| 641 | IPConfigType type; |
[email protected] | ea21f9c | 2010-10-21 08:26:54 | [diff] [blame] | 642 | std::string address; // This looks like "/device/0011aa22bb33" |
[email protected] | 3fb19f5c | 2010-02-17 00:49:50 | [diff] [blame] | 643 | std::string netmask; |
| 644 | std::string gateway; |
| 645 | std::string name_servers; |
| 646 | }; |
| 647 | typedef std::vector<NetworkIPConfig> NetworkIPConfigVector; |
| 648 | |
[email protected] | 819a4386 | 2010-08-12 10:09:21 | [diff] [blame] | 649 | // This class handles the interaction with the ChromeOS network library APIs. |
| 650 | // Classes can add themselves as observers. Users can get an instance of the |
| 651 | // library like this: chromeos::CrosLibrary::Get()->GetNetworkLibrary() |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 652 | class NetworkLibrary { |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 653 | public: |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 654 | class NetworkManagerObserver { |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 655 | public: |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 656 | // Called when the state of the network manager has changed, |
| 657 | // for example, networks have appeared or disappeared. |
| 658 | virtual void OnNetworkManagerChanged(NetworkLibrary* obj) = 0; |
[email protected] | 7c3cc8a3 | 2010-11-03 06:58:14 | [diff] [blame] | 659 | }; |
| 660 | |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 661 | class NetworkObserver { |
[email protected] | 7c3cc8a3 | 2010-11-03 06:58:14 | [diff] [blame] | 662 | public: |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 663 | // Called when the state of a single network has changed, |
| 664 | // for example signal strength or connection state. |
| 665 | virtual void OnNetworkChanged(NetworkLibrary* cros, |
| 666 | const Network* network) = 0; |
| 667 | }; |
| 668 | |
| 669 | class CellularDataPlanObserver { |
| 670 | public: |
| 671 | // Called when the cellular data plan has changed. |
| 672 | virtual void OnCellularDataPlanChanged(NetworkLibrary* obj) = 0; |
[email protected] | 3c1139f | 2010-10-22 06:17:42 | [diff] [blame] | 673 | }; |
| 674 | |
[email protected] | bd57d93 | 2011-02-15 19:40:26 | [diff] [blame] | 675 | class UserActionObserver { |
| 676 | public: |
| 677 | // Called when user initiates a new connection. |
| 678 | // Network is NULL when we don't have an associated Network object. |
| 679 | virtual void OnConnectionInitiated(NetworkLibrary* cros, |
| 680 | const Network* network) = 0; |
| 681 | }; |
| 682 | |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 683 | virtual ~NetworkLibrary() {} |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 684 | |
| 685 | virtual void AddNetworkManagerObserver(NetworkManagerObserver* observer) = 0; |
| 686 | virtual void RemoveNetworkManagerObserver( |
| 687 | NetworkManagerObserver* observer) = 0; |
| 688 | |
| 689 | // An attempt to add an observer that has already been added for a |
| 690 | // give service path will be ignored. |
| 691 | virtual void AddNetworkObserver(const std::string& service_path, |
| 692 | NetworkObserver* observer) = 0; |
| 693 | // Remove an observer of a single network |
| 694 | virtual void RemoveNetworkObserver(const std::string& service_path, |
| 695 | NetworkObserver* observer) = 0; |
| 696 | // Stop |observer| from observing any networks |
| 697 | virtual void RemoveObserverForAllNetworks(NetworkObserver* observer) = 0; |
| 698 | |
[email protected] | 1b57b4c | 2011-01-21 21:43:11 | [diff] [blame] | 699 | // Temporarily locks down certain functionality in network library to prevent |
| 700 | // unplanned side effects. During the lock down, Enable*Device() calls cannot |
| 701 | // be made. |
| 702 | virtual void Lock() = 0; |
| 703 | // Removes temporarily lock of network library. |
| 704 | virtual void Unlock() = 0; |
| 705 | // Checks if access to network library is locked. |
| 706 | virtual bool IsLocked() = 0; |
| 707 | |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 708 | virtual void AddCellularDataPlanObserver( |
| 709 | CellularDataPlanObserver* observer) = 0; |
| 710 | virtual void RemoveCellularDataPlanObserver( |
| 711 | CellularDataPlanObserver* observer) = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 712 | |
[email protected] | bd57d93 | 2011-02-15 19:40:26 | [diff] [blame] | 713 | virtual void AddUserActionObserver(UserActionObserver* observer) = 0; |
| 714 | virtual void RemoveUserActionObserver(UserActionObserver* observer) = 0; |
| 715 | |
[email protected] | 83c8265 | 2011-03-05 01:59:34 | [diff] [blame] | 716 | // Return the active or default Ethernet network (or NULL if none). |
[email protected] | 37eec14 | 2010-12-02 18:47:09 | [diff] [blame] | 717 | virtual const EthernetNetwork* ethernet_network() const = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 718 | virtual bool ethernet_connecting() const = 0; |
| 719 | virtual bool ethernet_connected() const = 0; |
| 720 | |
[email protected] | 83c8265 | 2011-03-05 01:59:34 | [diff] [blame] | 721 | // Return the active Wifi network (or NULL if none active). |
[email protected] | 37eec14 | 2010-12-02 18:47:09 | [diff] [blame] | 722 | virtual const WifiNetwork* wifi_network() const = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 723 | virtual bool wifi_connecting() const = 0; |
| 724 | virtual bool wifi_connected() const = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 725 | |
[email protected] | 83c8265 | 2011-03-05 01:59:34 | [diff] [blame] | 726 | // Return the active Cellular network (or NULL if none active). |
[email protected] | 37eec14 | 2010-12-02 18:47:09 | [diff] [blame] | 727 | virtual const CellularNetwork* cellular_network() const = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 728 | virtual bool cellular_connecting() const = 0; |
| 729 | virtual bool cellular_connected() const = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 730 | |
[email protected] | 83c8265 | 2011-03-05 01:59:34 | [diff] [blame] | 731 | // Return the active virtual network (or NULL if none active). |
| 732 | virtual const VirtualNetwork* virtual_network() const = 0; |
| 733 | virtual bool virtual_network_connecting() const = 0; |
| 734 | virtual bool virtual_network_connected() const = 0; |
| 735 | |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 736 | // Return true if any network is currently connected. |
| 737 | virtual bool Connected() const = 0; |
| 738 | |
| 739 | // Return true if any network is currently connecting. |
| 740 | virtual bool Connecting() const = 0; |
| 741 | |
| 742 | // Returns the current IP address if connected. If not, returns empty string. |
[email protected] | 460c3f1 | 2010-11-08 18:20:58 | [diff] [blame] | 743 | virtual const std::string& IPAddress() const = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 744 | |
| 745 | // Returns the current list of wifi networks. |
| 746 | virtual const WifiNetworkVector& wifi_networks() const = 0; |
| 747 | |
[email protected] | 665d7d6 | 2010-04-20 23:32:49 | [diff] [blame] | 748 | // Returns the list of remembered wifi networks. |
| 749 | virtual const WifiNetworkVector& remembered_wifi_networks() const = 0; |
| 750 | |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 751 | // Returns the current list of cellular networks. |
| 752 | virtual const CellularNetworkVector& cellular_networks() const = 0; |
| 753 | |
[email protected] | 83c8265 | 2011-03-05 01:59:34 | [diff] [blame] | 754 | // Returns the current list of virtual networks. |
| 755 | virtual const VirtualNetworkVector& virtual_networks() const = 0; |
| 756 | |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 757 | // Return a pointer to the device, if it exists, or NULL. |
| 758 | virtual const NetworkDevice* FindNetworkDeviceByPath( |
| 759 | const std::string& path) const = 0; |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 760 | |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 761 | // Return a pointer to the network, if it exists, or NULL. |
[email protected] | 2f5a9a85 | 2011-03-19 00:54:34 | [diff] [blame] | 762 | // NOTE: Never store these results, store service paths instead. |
| 763 | // The pattern for doing an operation on a Network is: |
| 764 | // Network* network = cros->FindNetworkByPath(service_path); |
| 765 | // network->SetFoo(); |
| 766 | // network->Connect(); |
| 767 | // As long as this is done in sequence on the UI thread it will be safe; |
| 768 | // the network list only gets updated on the UI thread. |
| 769 | virtual Network* FindNetworkByPath(const std::string& path) const = 0; |
| 770 | virtual WifiNetwork* FindWifiNetworkByPath(const std::string& path) const = 0; |
[email protected] | d63f475 | 2011-03-07 21:37:18 | [diff] [blame] | 771 | virtual CellularNetwork* FindCellularNetworkByPath( |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 772 | const std::string& path) const = 0; |
| 773 | |
| 774 | // Retrieves the data plans associated with |path|, NULL if there are no |
| 775 | // associated plans. |
| 776 | virtual const CellularDataPlanVector* GetDataPlans( |
| 777 | const std::string& path) const = 0; |
| 778 | |
| 779 | // This returns the significant data plan. If the user only has the |
| 780 | // base data plan, then return that. If there is a base and a paid data plan, |
| 781 | // then the significant one is the paid one. So return the paid plan. |
| 782 | // If there are no data plans, then this method returns NULL. |
| 783 | // This returns a pointer to a member of data_plans_, so if SetDataPlans() |
| 784 | // gets called, the result becomes invalid. |
| 785 | virtual const CellularDataPlan* GetSignificantDataPlan( |
| 786 | const std::string& path) const = 0; |
[email protected] | f9384b55 | 2010-06-28 23:02:26 | [diff] [blame] | 787 | |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 788 | // Request a scan for new wifi networks. |
[email protected] | a4a89cf | 2011-03-16 18:17:54 | [diff] [blame] | 789 | virtual void RequestNetworkScan() = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 790 | |
[email protected] | 63259a5 | 2010-07-15 10:55:38 | [diff] [blame] | 791 | // Reads out the results of the last wifi scan. These results are not |
| 792 | // pre-cached in the library, so the call may block whilst the results are |
| 793 | // read over IPC. |
| 794 | // Returns false if an error occurred in reading the results. Note that |
| 795 | // a true return code only indicates the result set was successfully read, |
| 796 | // it does not imply a scan has successfully completed yet. |
| 797 | virtual bool GetWifiAccessPoints(WifiAccessPointVector* result) = 0; |
| 798 | |
| 799 | // TODO(joth): Add GetCellTowers to retrieve a CellTowerVector. |
| 800 | |
[email protected] | 2f5a9a85 | 2011-03-19 00:54:34 | [diff] [blame] | 801 | // Connect to the specified wireless network. |
[email protected] | 8ceaf0c | 2011-03-14 22:26:52 | [diff] [blame] | 802 | virtual void ConnectToWifiNetwork(WifiNetwork* network) = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 803 | |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 804 | // Same as above but searches for an existing network by name. |
[email protected] | 8ceaf0c | 2011-03-14 22:26:52 | [diff] [blame] | 805 | virtual void ConnectToWifiNetwork(const std::string& service_path) = 0; |
[email protected] | 894ee39 | 2011-02-25 21:05:02 | [diff] [blame] | 806 | |
[email protected] | 2f5a9a85 | 2011-03-19 00:54:34 | [diff] [blame] | 807 | // Connect to the specified network with security, ssid, and passphrase. |
[email protected] | 8ceaf0c | 2011-03-14 22:26:52 | [diff] [blame] | 808 | virtual void ConnectToWifiNetwork(ConnectionSecurity security, |
[email protected] | 0673a28 | 2010-11-02 20:41:44 | [diff] [blame] | 809 | const std::string& ssid, |
[email protected] | 2f5a9a85 | 2011-03-19 00:54:34 | [diff] [blame] | 810 | const std::string& passphrase, |
[email protected] | 4a5c59c8 | 2010-06-30 21:03:34 | [diff] [blame] | 811 | const std::string& identity, |
| 812 | const std::string& certpath, |
[email protected] | 88908d6 | 2010-04-30 21:50:45 | [diff] [blame] | 813 | bool auto_connect) = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 814 | |
| 815 | // Connect to the specified cellular network. |
[email protected] | 2f5a9a85 | 2011-03-19 00:54:34 | [diff] [blame] | 816 | virtual void ConnectToCellularNetwork(CellularNetwork* network) = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 817 | |
[email protected] | c3a54e4b | 2011-01-18 04:37:05 | [diff] [blame] | 818 | // Records information that cellular play payment had happened. |
| 819 | virtual void SignalCellularPlanPayment() = 0; |
| 820 | |
| 821 | // Returns true if cellular plan payment had been recorded recently. |
| 822 | virtual bool HasRecentCellularPlanPayment() = 0; |
| 823 | |
[email protected] | 00e1756 | 2010-05-06 18:59:25 | [diff] [blame] | 824 | // Disconnect from the specified wireless (either cellular or wifi) network. |
| 825 | virtual void DisconnectFromWirelessNetwork( |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 826 | const WirelessNetwork* network) = 0; |
[email protected] | d1958fe | 2010-04-30 22:29:42 | [diff] [blame] | 827 | |
[email protected] | 45066d5 | 2010-10-29 17:24:57 | [diff] [blame] | 828 | // Forget the wifi network corresponding to service_path. |
| 829 | virtual void ForgetWifiNetwork(const std::string& service_path) = 0; |
[email protected] | 665d7d6 | 2010-04-20 23:32:49 | [diff] [blame] | 830 | |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 831 | virtual bool ethernet_available() const = 0; |
| 832 | virtual bool wifi_available() const = 0; |
| 833 | virtual bool cellular_available() const = 0; |
| 834 | |
| 835 | virtual bool ethernet_enabled() const = 0; |
| 836 | virtual bool wifi_enabled() const = 0; |
| 837 | virtual bool cellular_enabled() const = 0; |
| 838 | |
[email protected] | d3f9b88 | 2010-11-18 22:30:40 | [diff] [blame] | 839 | virtual bool wifi_scanning() const = 0; |
| 840 | |
[email protected] | ceaf8f1 | 2010-11-04 20:37:32 | [diff] [blame] | 841 | virtual const Network* active_network() const = 0; |
| 842 | |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 843 | virtual bool offline_mode() const = 0; |
| 844 | |
| 845 | // Enables/disables the ethernet network device. |
| 846 | virtual void EnableEthernetNetworkDevice(bool enable) = 0; |
| 847 | |
| 848 | // Enables/disables the wifi network device. |
| 849 | virtual void EnableWifiNetworkDevice(bool enable) = 0; |
| 850 | |
| 851 | // Enables/disables the cellular network device. |
| 852 | virtual void EnableCellularNetworkDevice(bool enable) = 0; |
| 853 | |
| 854 | // Enables/disables offline mode. |
| 855 | virtual void EnableOfflineMode(bool enable) = 0; |
| 856 | |
[email protected] | ea21f9c | 2010-10-21 08:26:54 | [diff] [blame] | 857 | // Fetches IP configs and hardware address for a given device_path. |
| 858 | // The hardware address is usually a MAC address like "0011AA22BB33". |
| 859 | // |hardware_address| will be an empty string, if no hardware address is |
| 860 | // found. |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 861 | virtual NetworkIPConfigVector GetIPConfigs( |
[email protected] | ea21f9c | 2010-10-21 08:26:54 | [diff] [blame] | 862 | const std::string& device_path, |
| 863 | std::string* hardware_address) = 0; |
[email protected] | 5a1c2dd | 2010-05-11 22:52:30 | [diff] [blame] | 864 | |
| 865 | // Fetches debug network info for display in about:network. |
| 866 | // The page will have a meta refresh of |refresh| seconds if |refresh| > 0. |
| 867 | virtual std::string GetHtmlInfo(int refresh) = 0; |
[email protected] | 62c7ef3 | 2010-03-23 23:44:24 | [diff] [blame] | 868 | |
[email protected] | 819a4386 | 2010-08-12 10:09:21 | [diff] [blame] | 869 | // Factory function, creates a new instance and returns ownership. |
| 870 | // For normal usage, access the singleton via CrosLibrary::Get(). |
[email protected] | 617fd0d | 2010-08-04 20:05:17 | [diff] [blame] | 871 | static NetworkLibrary* GetImpl(bool stub); |
[email protected] | 7598ab5 | 2009-10-08 01:33:21 | [diff] [blame] | 872 | }; |
| 873 | |
[email protected] | b22c21c | 2009-10-30 00:35:00 | [diff] [blame] | 874 | } // namespace chromeos |
| 875 | |
[email protected] | 268b02f | 2010-02-04 21:07:15 | [diff] [blame] | 876 | #endif // CHROME_BROWSER_CHROMEOS_CROS_NETWORK_LIBRARY_H_ |