/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"

[scriptable, function, uuid(91824160-fb25-11e1-a21f-0800200c9a66)]
interface nsIWifiTetheringCallback : nsISupports
{
  /**
   * Callback function used to report status to WifiManager.
   *
   * @param error
   *        An error message if the operation wasn't successful,
   *        or `null` if it was.
   */
  void wifiTetheringEnabledChange(in jsval error);
};

[scriptable, function, uuid(9c128e68-5e4b-4626-bb88-84ec54cce5d8)]
interface nsINetworkStatsCallback : nsISupports
{
  void networkStatsAvailable(in boolean success,
                             in unsigned long rxBytes,
                             in unsigned long txBytes,
                             in unsigned long long timestamp);
};

[scriptable, function, uuid(0706bfa2-ac2d-11e2-9a8d-7b6d988d4767)]
interface nsINetworkUsageAlarmCallback : nsISupports
{
  void networkUsageAlarmResult(in jsval error);
};

[scriptable, function, uuid(9ede8720-f8bc-11e2-b778-0800200c9a66)]
interface nsIWifiOperationModeCallback : nsISupports
{
  /**
   * Callback function used to report result to WifiManager.
   *
   * @param error
   *        An error message if the operation wasn't successful,
   *        or `null` if it was.
   */
  void wifiOperationModeResult(in jsval error);
};

[scriptable, function, uuid(097878b0-19fc-11e3-8ffd-0800200c9a66)]
interface nsISetDhcpServerCallback : nsISupports
{
  /**
   * Callback function used to report the DHCP server set result
   *
   * @param error
   *        An error message if the operation wasn't successful,
   *        or `null` if it was.
   */
  void dhcpServerResult(in jsval error);
};

[scriptable, function, uuid(32407c50-46c7-11e3-8f96-0800200c9a66)]
interface nsIUsbTetheringCallback : nsISupports
{
  /**
   * Callback function used to report status of enabling usb tethering.
   *
   * @param error
   *        An error message if the operation wasn't successful,
   *        or `null` if it was.
   */
  void usbTetheringEnabledChange(in jsval error);
};

[scriptable, function, uuid(055fd560-46ad-11e3-8f96-0800200c9a66)]
interface nsIEnableUsbRndisCallback : nsISupports
{
  /**
   * Callback function used to report the status of enabling/disabling usb rndis.
   *
   * @param success
   *        Boolean to indicate the operation is successful or not.
   * @param enable
   *        Boolean to indicate if we are enabling or disabling usb rndis.
   */
  void enableUsbRndisResult(in boolean success, in boolean enable);
};

[scriptable, function, uuid(4f08cc30-46ad-11e3-8f96-0800200c9a66)]
interface nsIUpdateUpStreamCallback : nsISupports
{
  /**
   * Callback function used to report the result of updating upstream.
   *
   * @param success
   *        Boolean to indicate the operation is successful or not.
   * @param externalIfname
   *        The external interface name.
   */
  void updateUpStreamResult(in boolean success, in DOMString externalIfname);
};

[scriptable, function, uuid(eedca6c0-1310-11e4-9191-0800200c9a66)]
interface nsISetDnsCallback : nsISupports
{
  /**
   * Callback function used to report the result of setting DNS server.
   *
   * @param error
   *        An error message if the operation wasn't successful,
   *        or `null` if it was.
   */
  void setDnsResult(in jsval error);
};

[scriptable, function, uuid(5d0e1a60-1187-11e4-9191-0800200c9a66)]
interface nsINativeCommandCallback : nsISupports
{
  /**
   * Callback function used to report the result of a network native command.
   *
   * @param success
   *        Boolean to indicate the operation is successful or not.
   */
  void nativeCommandResult(in boolean success);
};

[scriptable, function, uuid(694abb80-1187-11e4-9191-0800200c9a66)]
interface nsIDhcpRequestCallback : nsISupports
{
  /**
   * Callback function used to report the result of DHCP client request.
   *
   * @param success
   *        Boolean to indicate the operation is successful or not.
   *
   * @param dhcpInfo
   *        An object to represent the successful DHCP request:
   *
   *          - gateway_str: string
   *          - dns1_str:    string
   *          - dns2_str:    string
   *          - mask_str:    string
   *          - server_str:  string
   *          - vendor_str:  string
   *          - lease:       long
   *          - mask:        long
   *          - ipaddr:      long
   *          - gateway:     long
   *          - dns1:        long
   *          - dns2:        long
   *          - server:      long
   */
  void dhcpRequestResult(in boolean success, in jsval dhcpInfo);
};

[scriptable, function, uuid(88e3ee22-f1b3-4fa0-8a5d-793fb827c42c)]
interface nsIGetInterfacesCallback : nsISupports
{
  /**
   * Callback function used to return the list of existing network interfaces.
   *
   * @param success
   *        Boolean to indicate the operation is successful or not.
   * @param interfaceList
   *        An array of interface name.
   */
  void getInterfacesResult(in boolean success, in jsval interfaceList);
};

[scriptable, function, uuid(064e02a3-d2c0-42c5-a293-1efa84056100)]
interface nsIGetInterfaceConfigCallback : nsISupports
{
  /**
   * Callback function used to return the network config of a given interface.
   *
   * @param success
   *        Boolean to indicate the operation is successful or not.
   * @param result
   *        .ip: Ip address.
   *        .prefix: mask length.
   *        .link: network link properties.
   *        .mac: mac address.
   */
  void getInterfaceConfigResult(in boolean success, in jsval result);
};

[scriptable, function, uuid(b370f360-6ba8-4517-a4f9-31e8f004ee91)]
interface nsISetInterfaceConfigCallback : nsISupports
{
  /**
   * Callback function used to set network config for a specified interface.
   *
   * @param success
   *        Boolean to indicate the operation is successful or not.
   */
  void setInterfaceConfigResult(in boolean success);
};

/**
 * Provide network services.
 */
[scriptable, uuid(e16fe98f-9f63-48fe-82ba-8d1a1b7c6a57)]
interface nsINetworkService : nsISupports
{
  const long MODIFY_ROUTE_ADD    = 0;
  const long MODIFY_ROUTE_REMOVE = 1;

  /**
   * Enable or disable Wifi Tethering
   *
   * @param enabled
   *        Boolean that indicates whether tethering should be enabled (true) or disabled (false).
   * @param config
   *        The Wifi Tethering configuration from settings db.
   * @param callback
   *        Callback function used to report status to WifiManager.
   */
  void setWifiTethering(in boolean enabled,
                        in jsval config,
                        in nsIWifiTetheringCallback callback);

  /**
   * Enable or disable DHCP server
   *
   * @param enabled
   *        Boolean that indicates enabling or disabling DHCP server.
   *
   * @param config
   *        Config used to enable the DHCP server. It contains
   *        .startIp    start of the ip lease range (string)
   *        .endIp      end of the ip lease range (string)
   *        .serverIp   ip of the DHCP server (string)
   *        .maskLength the length of the subnet mask
   *        .ifname     the interface name
   *
   *        As for disabling the DHCP server, put this value |null|.
   *
   * @param callback
   *        Callback function used to report status.
   */
  void setDhcpServer(in boolean enabled,
                     in jsval config,
                     in nsISetDhcpServerCallback callback);


  /**
   * Retrieve network interface stats.
   *
   * @param networkName
   *        Select the Network interface to request estats.
   *
   * @param callback
   *        Callback to notify result and provide stats, connectionType
   *        and the date when stats are retrieved
   */
  void getNetworkInterfaceStats(in DOMString networkName, in nsINetworkStatsCallback callback);

  /**
   * Set Alarm of usage per interface
   *
   * @param networkName
   *        Select the Network interface to set an alarm.
   *
   * @param threshold
   *        Amount of data that will trigger the alarm.
   *
   * @param callback
   *        Callback to notify the result.
   *
   * @return false if there is no interface registered for the networkType param.
   */
  boolean setNetworkInterfaceAlarm(in DOMString networkName,
                                   in long long threshold,
                                   in nsINetworkUsageAlarmCallback callback);

  /**
   * Reload Wifi firmware to specific operation mode.
   *
   * @param interfaceName
   *        Wifi Network interface name.
   *
   * @param mode
   *        AP  - Access pointer mode.
   *        P2P - Peer to peer connection mode.
   *        STA - Station mode.
   *
   * @param callback
   *        Callback to notify Wifi firmware reload result.
   */
  void setWifiOperationMode(in DOMString interfaceName,
                            in DOMString mode,
                            in nsIWifiOperationModeCallback callback);

  /**
   * Set USB tethering.
   *
   * @param enabled
   *        Boolean to indicate we are going to enable or disable usb tethering.
   * @param config
   *        The usb tethering configuration.
   * @param callback
   *        Callback function used to report the result enabling/disabling usb tethering.
   */
  void setUSBTethering(in boolean enabled,
                       in jsval config,
                       in nsIUsbTetheringCallback callback);

  /**
   * Reset routing table.
   *
   * @param interfaceName
   *        The name of the network interface we want to remove from the routing
   *        table.
   *
   * @param callback
   *        Callback to notify the result of resetting routing table.
   */
  void resetRoutingTable(in DOMString interfaceName,
                         in nsINativeCommandCallback callback);

  /**
   * Set DNS.
   *
   * @param interfaceName
   *        The network interface name of the DNS we want to set.
   * @param dnsesCount
   *        Number of elements in dnses.
   * @param dnses
   *        Dnses to set.
   * @param gatewaysCount
   *        Number of elements in gateways.
   * @param gateways
   *        Gateways for the dnses, the most suitable, usually the one with the
   *        same address family, will be selected for each dns.
   *
   * @param callback
   *        Callback to notify the result of setting DNS server.
   */
  void setDNS(in DOMString interfaceName,
              in unsigned long dnsesCount,
              [array, size_is(dnsesCount)] in wstring dnses,
              in unsigned long gatewaysCount,
              [array, size_is(gatewaysCount)] in wstring gateways,
              in nsISetDnsCallback callback);

  /**
   * Set default route.
   *
   * @param interfaceName
   *        The network interface name of the default route we want to set.
   * @param count
   *        Number of elements in gateways.
   * @param gateways
   *        Default gateways for setting default route.
   *
   * @param callback
   *        Callback to notify the result of setting default route.
   */
  void setDefaultRoute(in DOMString interfaceName,
                       in unsigned long count,
                       [array, size_is(count)] in wstring gateways,
                       in nsINativeCommandCallback callback);

  /**
   * Remove default route.
   *
   * @param interfaceName
   *        The network interface name of the default route we want to remove.
   * @param count
   *        Number of elements in gateways.
   * @param gatways
   *        Default gateways for removing default route.
   *
   * @param callback
   *        Callback to notify the result of removing default route.
   */
  void removeDefaultRoute(in DOMString interfaceName,
                          in unsigned long count,
                          [array, size_is(count)] in wstring gateways,
                          in nsINativeCommandCallback callback);

  /**
   * Modify route.
   *
   * @param action
   *        nsINetworkService.MODIFY_ROUTE_ADD to add route and
   *        nsINetworkService.MODIFY_ROUTE_REMOVE to remove.
   * @param interfaceName
   *        Network interface name for the output of the host route.
   * @param host
   *        Host ip we want to remove route for.
   * @param prefixLength
   *        The prefix length of the route we'd like to modify.
   * @param [optional] gateway
   *        Gateway ip for the output of the host route.
   *
   * @return A deferred promise that resolves on success or rejects with a
   *         specified reason otherwise.
   */
  jsval modifyRoute(in long      action,
                    in DOMString interfaceName,
                    in DOMString host,
                    in long      prefixLength,
                    [optional] in DOMString gateway);

  /**
   * Add route to secondary routing table.
   *
   * @param interfaceName
   *        The network interface for this route.
   * @param route
   *        The route info should have the following fields:
   *        .ip: destination ip address
   *        .prefix: destination prefix
   *        .gateway: gateway ip address
   */
  void addSecondaryRoute(in DOMString interfaceName, in jsval route,
                         in nsINativeCommandCallback callback);

  /**
   * Remove route from secondary routing table.
   *
   * @param interfaceName
   *        The network interface for the route we want to remove.
   * @param route
   *        The route info should have the following fields:
   *        .ip: destination ip address
   *        .prefix: destination prefix
   *        .gateway: gateway ip address
   */
  void removeSecondaryRoute(in DOMString interfaceName, in jsval route,
                            in nsINativeCommandCallback callback);

  /**
   * Enable or disable usb rndis.
   *
   * @param enable
   *        Boolean to indicate we want enable or disable usb rndis.
   * @param callback
   *        Callback function to report the result.
   */
  void enableUsbRndis(in boolean enable,
                      in nsIEnableUsbRndisCallback callback);

  /**
   * Update upstream.
   *
   * @param previous
   *        The previous internal and external interface.
   * @param current
   *        The current internal and external interface.
   * @param callback
   *        Callback function to report the result.
   */
  void updateUpStream(in jsval previous,
                      in jsval current,
                      in nsIUpdateUpStreamCallback callback);

  /*
   * Obtain interfaces list.
   *
   * @param callback
   *        Callback function to return the result.
   */
  void getInterfaces(in nsIGetInterfacesCallback callback);

  /**
   * Get config of a network interface.
   *
   * @param ifname
   *        Target interface.
   * @param callback
   *        Callback function to report the result.
   */
  void getInterfaceConfig(in DOMString ifname, in nsIGetInterfaceConfigCallback callback);

  /**
   * Set config for a network interface.
   *
   * @param config
   *        .ifname: Target interface.
   *        .ip: Ip address.
   *        .prefix: mask length.
   *        .link: network link properties.
   * @param callback
   *        Callback function to report the result.
   */
  void setInterfaceConfig(in jsval config, in nsISetInterfaceConfigCallback callback);

  /**
   * Configure a network interface.
   *
   * @param config
   *        An object containing the detail that we want to configure the interface:
   *
   *          - ifname:  string
   *          - ipaddr:  long
   *          - mask:    long
   *          - gateway: long
   *          - dns1:    long
   *          - dns2:    long
   *
   * @param callback
   *        Callback to notify the result of configurating network interface.
   */
  void configureInterface(in jsval config,
                          in nsINativeCommandCallback callback);

  /**
   * Issue a DHCP client request.
   *
   * @param networkInterface
   *        The network interface which we wnat to do the DHCP request on.
   *
   * @param callback
   *        Callback to notify the result of the DHCP request.
   */
  void dhcpRequest(in DOMString interfaceName,
                   in nsIDhcpRequestCallback callback);

  /**
   * Stop Dhcp daemon.
   *
   * @param ifname
   *        Target interface.
   *
   * @param callback
   *        Callback to notify the result of stopping dhcp request.
   */
  void stopDhcp(in DOMString ifname,
                in nsINativeCommandCallback callback);

  /**
   * Enable a network interface.
   *
   * @param networkInterface
   *        The network interface name which we want to enable.
   *
   * @param callback
   *        Callback to notify the result of disabling network interface.
   */
  void enableInterface(in DOMString interfaceName,
                       in nsINativeCommandCallback callback);

  /**
   * Disable a network interface.
   *
   * @param networkInterface
   *        The network interface name which we want to disable.
   *
   * @param callback
   *        Callback to notify the result of disabling network interface.
   */
  void disableInterface(in DOMString interfaceName,
                        in nsINativeCommandCallback callback);

  /**
   * Reset all connections on a specified network interface.
   *
   * @param interfaceName
   *        The network interface name which we want to reset.
   *
   * @param callback
   *        Callback to notify the result of resetting connections.
   */
  void resetConnections(in DOMString interfaceName,
                        in nsINativeCommandCallback callback);

  /**
   * Create network (required to call prior to any networking operation).
   *
   * @param interfaceName
   *        The network interface name which we want to create network for.
   *
   * @param callback
   *        Callback to notify the result of creating network.
   */
  void createNetwork(in DOMString interfaceName,
                     in nsINativeCommandCallback callback);

  /**
   * Destroy network.
   *
   * @param interfaceName
   *        The network interface name of the network we want to destroy.
   *
   * @param callback
   *        Callback to notify the result of destroying network.
   */
  void destroyNetwork(in DOMString interfaceName,
                      in nsINativeCommandCallback callback);

  /**
   * Query the netId associated with given network interface name.
   *
   * @param interfaceName
   *        The network interface name which we want to query.
   *
   * @return A deferred promise that resolves with a string to indicate.
   *         the queried netId on success and rejects if the interface name
   *         is invalid.
   *
   */
  jsval getNetId(in DOMString interfaceName);

  /**
   * Set maximum transmission unit on a network interface.
   *
   * @param interfaceName
   *        The name of the network interface that we want to set mtu.
   * @param mtu
   *        Size of maximum tranmission unit.
   *
   * @param callback
   *        Callback to notify the result of setting mtu.
   */
  void setMtu(in DOMString interfaceName, in long mtu,
              in nsINativeCommandCallback callback);
};