// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Next MinVersion: 9

module arc.mojom;

[Extensible]
enum NetworkResult {
  SUCCESS = 0,
  FAILURE = 1,
};

[Extensible]
enum GetNetworksRequestType {
  CONFIGURED_ONLY = 0,
  VISIBLE_ONLY = 1,
};

[Extensible]
enum ConnectionStateType {
  CONNECTED = 0,
  CONNECTING = 1,
  NOT_CONNECTED = 2,
};

struct VisibleNetworkDetails {
  int32 frequency;
  int32 signal_strength;
  string bssid;
};

struct ConfiguredNetworkDetails {
  string? passphrase;
  bool autoconnect;
};

union NetworkDetails {
  VisibleNetworkDetails visible;
  ConfiguredNetworkDetails configured;
};

[Extensible]
enum IPAddressType {
  IPV4,
  IPV6,
};

struct IPConfiguration {
  string gateway;
  string ip_address;
  array<string> name_servers;
  int32 routing_prefix;
  IPAddressType type;
  string web_proxy_auto_discovery_url;
};

[Extensible]
enum SecurityType {
  NONE,
  WEP_PSK,
  WEP_8021X,
  WPA_PSK,
  WPA_EAP,
};

struct WiFi {
  string bssid;
  int32 frequency;
  string hex_ssid;
  bool hidden_ssid;
  SecurityType security;
  int32 signal_strength;
};

[Extensible]
enum NetworkType {
  CELLULAR,
  ETHERNET,
  VPN,
  WIFI,
  WIMAX,
};

struct NetworkConfiguration {
  // These correspond to ONC properties returned by
  // chrome.networkingPrivate.getProperties().
  // See components/onc/docs/onc_spec.html
  ConnectionStateType connection_state;
  string guid;
  array<IPConfiguration>? ip_configs;
  string? mac_address;
  NetworkType type;
  WiFi? wifi;
};

struct WifiConfiguration {
  // These correspond to ONC properties returned by
  // chrome.networkingPrivate.getNetworks() and createNetwork().
  // See components/onc/docs/onc_spec.html

  // SSID encoded as a series of hex bytes, e.g. "61626364"
  // This allows for handling SSIDs which are not valid UTF-8 strings.
  [MinVersion=2] string? hexssid@6;

  [MinVersion=1] string? guid@5;
  string security@4;

  // Fields specific to either visible or configured networks.
  [MinVersion=2] NetworkDetails? details@7;

  // Deprecated.  These will be removed when both sides support NetworkDetails.
  int32 frequency@1;
  int32 signal_strength@2;
  string bssid@3;

  // Deprecated. |hexssid| will be used, going forward.
  string ssid@0;
};

struct NetworkData {
  NetworkResult status;
  array<WifiConfiguration> networks;
};

struct GetNetworksResponseType {
  NetworkResult status;
  array<NetworkConfiguration> networks;
};

struct AndroidVpnConfiguration {
  // The canonical name of the VPN app (e.g. "com.android.myvpn").
  string app_name@0;

  // The human-readable name of the VPN app (e.g. "OpenVPN").
  string app_label@1;

  // The name of the VPN session, as set by the app using setSession().
  // The app does not need to call setSession() so this may be empty.
  string session_name@2;

  // True if Chrome browser traffic should be sent through the VPN.
  bool tunnel_chrome_traffic@3;

  // The next hop for IPv4 traffic originating on the host.  Currently this
  // will be set to arc0's IP address.
  string ipv4_gateway@4;

  // A list of IPv4 and IPv6 ranges to route through the VPN.  e.g.
  // ["0.0.0.0/0"] or ["192.168.1.0/24", "10.1.0.0/16"].
  array<string> split_include@5;

  // A list of IPv4 and IPv6 ranges to exclude from the VPN.  If specified,
  // all traffic that does not fall into these ranges will use the VPN.
  array<string> split_exclude@6;

  // A list of DNS servers.
  array<string> nameservers@7;

  // A list of search domains for DNS resolution.
  array<string> domains@8;
};

// Next Method ID: 13
interface NetHost {
  // Sends a request to get enabled / disabled status of WiFi.
  GetWifiEnabledState@1() => (bool is_enabled);

  // Sends a request to start scan of WiFi APs.
  [MinVersion=1] StartScan@2();

  // Sends a request to get configured or visible WiFi networks based on the
  // request type.
  [MinVersion=2] GetNetworksDeprecated@3(GetNetworksRequestType type) => (NetworkData data);

  // Sends a request to enable or disable WiFi. The |result| is true when the
  // the state has been successfully set or WiFi is already in the desired
  // state. It is false if WiFi manipulation is prohibited due to a policy or
  // its current state.
  [MinVersion=3] SetWifiEnabledState@4(bool is_enabled) => (bool result);

  // Creates a new network and returns the GUID.  If an error occurs,
  // |guid| will be an empty string.
  [MinVersion=4] CreateNetwork@5(WifiConfiguration cfg) => (string guid);

  // Deletes an existing network.
  [MinVersion=4] ForgetNetwork@6(string guid) => (NetworkResult status);

  // Initiates a network connection.  If called when connected to a different
  // network, it will drop the current connection first.
  [MinVersion=4] StartConnect@7(string guid) => (NetworkResult status);

  // Disconnects from network |guid|.
  [MinVersion=4] StartDisconnect@8(string guid) => (NetworkResult status);

  // Retrieve details (IP, SSID, etc.) about the current network connection.
  [MinVersion=5] GetDefaultNetwork@9() => (
      NetworkConfiguration? logical_default,
      NetworkConfiguration? physical_default);

  // Sends a request to get configured or visible WiFi networks based on the
  // request type.
  [MinVersion=6] GetNetworks@10(GetNetworksRequestType type) =>
      (GetNetworksResponseType response);

  // Inform Chrome OS that a VPN has connected.
  [MinVersion=7] AndroidVpnConnected@11(AndroidVpnConfiguration cfg);

  // Inform Chrome OS that a VPN is disconnected, reconnecting, or reconnected.
  [MinVersion=7] AndroidVpnStateChanged@12(ConnectionStateType state);
};

// Next Method ID: 7
interface NetInstance {
  // DEPRECATED: Please use Init@6 instead.
  InitDeprecated@0(NetHost host_ptr);

  // Establishes full-duplex communication with the host.
  [MinVersion=8] Init@6(NetHost host_ptr) => ();

  // Notifies the instance of a WiFI AP scan being completed.
  [MinVersion=1] ScanCompleted@1();

  [MinVersion=2] DefaultNetworkChanged@2(
      NetworkConfiguration? logical_default,
      NetworkConfiguration? physical_default);

  [MinVersion=3] WifiEnabledStateChanged@3(bool is_enabled);

  // Ask Android to disconnect the VPN, per user request.
  [MinVersion=7] DisconnectAndroidVpn@4();

  // Ask Android to pop up a VPN configuration dialog, per user request.
  [MinVersion=7] ConfigureAndroidVpn@5();
};