Home | History | Annotate | Download | only in network
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROMEOS_NETWORK_CROS_NETWORK_FUNCTIONS_H_
      6 #define CHROMEOS_NETWORK_CROS_NETWORK_FUNCTIONS_H_
      7 
      8 // This header is introduced to make it easy to switch from chromeos_network.cc
      9 // to Chrome's own DBus code.  crosbug.com/16557
     10 //
     11 // All calls to functions in chromeos_network.h should be made through
     12 // functions provided by this header.
     13 //
     14 // DO NOT INCLUDE THIS HEADER DIRECTLY, THESE FUNCTIONS ARE BEING DEPRECATED.
     15 // Contact stevenjb (at) chromium.org and/or see crbug.com/154852
     16 
     17 #include <vector>
     18 
     19 #include "base/callback.h"
     20 #include "chromeos/chromeos_export.h"
     21 #include "chromeos/network/network_ip_config.h"
     22 #include "chromeos/network/network_util.h"
     23 
     24 namespace base {
     25 
     26 class DictionaryValue;
     27 class Value;
     28 
     29 }  // namespace base
     30 
     31 namespace chromeos {
     32 
     33 // Callback to be called when receiving a SMS.
     34 typedef base::Callback<void(const std::string& modem_device_path,
     35                             const SMS& message)> MonitorSMSCallback;
     36 
     37 // Callback for asynchronous getters.
     38 typedef base::Callback<void(
     39     const std::string& path,
     40     const base::DictionaryValue* properties)> NetworkPropertiesCallback;
     41 
     42 // Callback for network properties watchers.
     43 typedef base::Callback<void(
     44     const std::string& path,
     45     const std::string& key,
     46     const base::Value& value)> NetworkPropertiesWatcherCallback;
     47 
     48 // Base class of signal watchers.
     49 class CHROMEOS_EXPORT CrosNetworkWatcher {
     50  public:
     51   virtual ~CrosNetworkWatcher() {}
     52 
     53  protected:
     54   CrosNetworkWatcher() {}
     55 };
     56 
     57 // Activates the cellular modem specified by |service_path| with carrier
     58 // specified by |carrier|.
     59 // |carrier| is NULL or an empty string, this will activate with the currently
     60 // active carrier.
     61 // Returns false on failure and true on success.
     62 CHROMEOS_EXPORT bool CrosActivateCellularModem(const std::string& service_path,
     63                                                const std::string& carrier);
     64 
     65 // Completes the activation for the cellular modem specified by |service_path|.
     66 CHROMEOS_EXPORT void CrosCompleteCellularActivation(
     67     const std::string& service_path);
     68 
     69 // Sets a property of a service to the provided value.
     70 // Success is indicated by the receipt of a matching PropertyChanged signal.
     71 CHROMEOS_EXPORT void CrosSetNetworkServiceProperty(
     72     const std::string& service_path,
     73     const std::string& property,
     74     const base::Value& value);
     75 
     76 // Clears a property of a service.
     77 CHROMEOS_EXPORT void CrosClearNetworkServiceProperty(
     78     const std::string& service_path,
     79     const std::string& property);
     80 
     81 // Sets a property of a device to the provided value.
     82 // Success is indicated by the receipt of a matching PropertyChanged signal.
     83 CHROMEOS_EXPORT void CrosSetNetworkDeviceProperty(
     84     const std::string& device_path,
     85     const std::string& property,
     86     const base::Value& value);
     87 
     88 // Sets a property of an ip config to the provided value.
     89 // Success is indicated by the receipt of a matching PropertyChanged signal.
     90 CHROMEOS_EXPORT void CrosSetNetworkIPConfigProperty(
     91     const std::string& ipconfig_path,
     92     const std::string& property,
     93     const base::Value& value);
     94 
     95 // Sets a property of a manager to the provided value.
     96 // Success is indicated by the receipt of a matching PropertyChanged signal.
     97 CHROMEOS_EXPORT void CrosSetNetworkManagerProperty(const std::string& property,
     98                                                    const base::Value& value);
     99 
    100 // Deletes a remembered service from a profile.
    101 CHROMEOS_EXPORT void CrosDeleteServiceFromProfile(
    102     const std::string& profile_path,
    103     const std::string& service_path);
    104 
    105 // Sets up monitoring of the PropertyChanged signal on the shill manager.
    106 // The provided |callback| will be called whenever a manager property changes.
    107 CHROMEOS_EXPORT CrosNetworkWatcher* CrosMonitorNetworkManagerProperties(
    108     const NetworkPropertiesWatcherCallback& callback);
    109 
    110 // Similar to MonitorNetworkManagerProperties for a specified network service.
    111 CHROMEOS_EXPORT CrosNetworkWatcher* CrosMonitorNetworkServiceProperties(
    112     const NetworkPropertiesWatcherCallback& callback,
    113     const std::string& service_path);
    114 
    115 // Similar to MonitorNetworkManagerProperties for a specified network device.
    116 CHROMEOS_EXPORT CrosNetworkWatcher* CrosMonitorNetworkDeviceProperties(
    117     const NetworkPropertiesWatcherCallback& callback,
    118     const std::string& device_path);
    119 
    120 // Similar to MonitorNetworkManagerProperties for a specified network device.
    121 CHROMEOS_EXPORT CrosNetworkWatcher* CrosMonitorSMS(
    122     const std::string& modem_device_path,
    123     MonitorSMSCallback callback);
    124 
    125 // Connects to the service with the |service_path|.
    126 // Service parameters such as authentication must already be configured.
    127 // Note, a successful invocation of the callback only indicates that
    128 // the connection process has started. You will have to query the
    129 // connection state to determine if the connection was established
    130 // successfully.
    131 CHROMEOS_EXPORT void CrosRequestNetworkServiceConnect(
    132     const std::string& service_path,
    133     const NetworkOperationCallback& callback);
    134 
    135 // Retrieves the latest info for the manager.
    136 CHROMEOS_EXPORT void CrosRequestNetworkManagerProperties(
    137     const NetworkPropertiesCallback& callback);
    138 
    139 // Retrieves the latest info for a service.
    140 CHROMEOS_EXPORT void CrosRequestNetworkServiceProperties(
    141     const std::string& service_path,
    142     const NetworkPropertiesCallback& callback);
    143 
    144 // Retrieves the latest info for a particular device.
    145 CHROMEOS_EXPORT void CrosRequestNetworkDeviceProperties(
    146     const std::string& device_path,
    147     const NetworkPropertiesCallback& callback);
    148 
    149 // Retrieves the list of remembered services for a profile.
    150 CHROMEOS_EXPORT void CrosRequestNetworkProfileProperties(
    151     const std::string& profile_path,
    152     const NetworkPropertiesCallback& callback);
    153 
    154 // Retrieves the latest info for a profile service entry.
    155 CHROMEOS_EXPORT void CrosRequestNetworkProfileEntryProperties(
    156     const std::string& profile_path,
    157     const std::string& profile_entry_path,
    158     const NetworkPropertiesCallback& callback);
    159 
    160 // Requests a wifi service not in the network list (i.e. hidden).
    161 CHROMEOS_EXPORT void CrosRequestHiddenWifiNetworkProperties(
    162     const std::string& ssid,
    163     const std::string& security,
    164     const NetworkPropertiesCallback& callback);
    165 
    166 // Requests a new VPN service.
    167 CHROMEOS_EXPORT void CrosRequestVirtualNetworkProperties(
    168     const std::string& service_name,
    169     const std::string& server_hostname,
    170     const std::string& provider_type,
    171     const NetworkPropertiesCallback& callback);
    172 
    173 // Disconnects from network service asynchronously.
    174 CHROMEOS_EXPORT void CrosRequestNetworkServiceDisconnect(
    175     const std::string& service_path);
    176 
    177 // Removes an exisiting network service (e.g. after forgetting a VPN).
    178 CHROMEOS_EXPORT void CrosRequestRemoveNetworkService(
    179     const std::string& service_path);
    180 
    181 // Requests a scan of services of |type|.
    182 // |type| should be is a string recognized by shill's Manager API.
    183 CHROMEOS_EXPORT void CrosRequestNetworkScan(const std::string& network_type);
    184 
    185 // Requests enabling or disabling a device.
    186 CHROMEOS_EXPORT void CrosRequestNetworkDeviceEnable(
    187     const std::string& network_type,
    188     bool enable);
    189 
    190 // Enables or disables PIN protection for a SIM card.
    191 CHROMEOS_EXPORT void CrosRequestRequirePin(
    192     const std::string& device_path,
    193     const std::string& pin,
    194     bool enable,
    195     const NetworkOperationCallback& callback);
    196 
    197 // Enters a PIN to unlock a SIM card.
    198 CHROMEOS_EXPORT void CrosRequestEnterPin(
    199     const std::string& device_path,
    200     const std::string& pin,
    201     const NetworkOperationCallback& callback);
    202 
    203 // Enters a PUK to unlock a SIM card whose PIN has been entered
    204 // incorrectly too many times. A new |pin| must be supplied
    205 // along with the |unblock_code| (PUK).
    206 CHROMEOS_EXPORT void CrosRequestUnblockPin(
    207     const std::string& device_path,
    208     const std::string& unblock_code,
    209     const std::string& pin,
    210     const NetworkOperationCallback& callback);
    211 
    212 // Changes the PIN used to unlock a SIM card.
    213 CHROMEOS_EXPORT void CrosRequestChangePin(
    214     const std::string& device_path,
    215     const std::string& old_pin,
    216     const std::string& new_pin,
    217     const NetworkOperationCallback& callback);
    218 
    219 // Proposes to trigger a scan transaction. For cellular networks scan result
    220 // is set in the property Cellular.FoundNetworks.
    221 CHROMEOS_EXPORT void CrosProposeScan(const std::string& device_path);
    222 
    223 // Initiates registration on the network specified by network_id, which is in
    224 // the form MCCMNC. If the network ID is the empty string, then switch back to
    225 // automatic registration mode before initiating registration.
    226 CHROMEOS_EXPORT void CrosRequestCellularRegister(
    227     const std::string& device_path,
    228     const std::string& network_id,
    229     const NetworkOperationCallback& callback);
    230 
    231 // Gets a list of all the NetworkIPConfigs using a given device path,
    232 // and returns the information via callback.
    233 CHROMEOS_EXPORT void CrosListIPConfigs(
    234     const std::string& device_path,
    235     const NetworkGetIPConfigsCallback& callback);
    236 
    237 // Refreshes the IP config |ipconfig_path| to pick up changes in
    238 // configuration, and renew the DHCP lease, if any.
    239 CHROMEOS_EXPORT void CrosRequestIPConfigRefresh(
    240     const std::string& ipconfig_path);
    241 
    242 // Configures the network service specified by |properties|.
    243 CHROMEOS_EXPORT void CrosConfigureService(
    244     const base::DictionaryValue& properties);
    245 
    246 // Changes the active cellular carrier.
    247 CHROMEOS_EXPORT void CrosSetCarrier(const std::string& device_path,
    248                                     const std::string& carrier,
    249                                     const NetworkOperationCallback& callback);
    250 
    251 }  // namespace chromeos
    252 
    253 #endif  // CHROMEOS_NETWORK_CROS_NETWORK_FUNCTIONS_H_
    254