chromium/chromeos/ash/services/hotspot_config/public/mojom/cros_hotspot_config.mojom

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

module ash.hotspot_config.mojom;

enum HotspotState {
  kDisabled,
  kEnabled,
  kEnabling,
  kDisabling,
};

// Represents security modes for WiFi downstream.
enum WiFiSecurityMode {
  kWpa2,
  kWpa3,
  kWpa2Wpa3,
};

// Represents bandwidth for WiFi downstream.
enum WiFiBand {
  // 2.4GHz bandwidth
  k2_4GHz,
  // Bandwidth auto chosen based on the device. Could either be 2.4GHz or 5GHz.
  kAutoChoose,
};

// Configuration properties for Hotspot.
struct HotspotConfig {
  // When set Hotspot will disable automatically when inactive for a fixed
  // amount of time.
  bool auto_disable;
  // Security mode for WiFi downstream.
  WiFiSecurityMode security;
  // The tethering WiFi band preference.
  WiFiBand band;
  // SSID of WiFi downstream.
  string ssid;
  // Passphrase for WiFi downstream.
  string passphrase;
  // When set to true, a new randomized BSSID will be used every time the
  // hotspot starts up, even if no other configuration metadata (e.g.: SSID)
  // has changed.
  bool bssid_randomization;
};

// Result code when setting hotspot configuration.
enum SetHotspotConfigResult {
  // Operation succeeded.
  kSuccess,
  // Failed because the user is not logged in.
  kFailedNotLogin,
  // Failed for invalid hotspot configuration.
  kFailedInvalidConfiguration,
  // Failed due to Shill operation failure.
  kFailedShillOperation,
};

// Status about whether Hotspot is allowed or not.
enum HotspotAllowStatus {
  // Disallowed because Cellular is not a supported upstream technology.
  kDisallowedNoCellularUpstream,
  // Disallowed because WiFi is not a supported downstream technology.
  kDisallowedNoWiFiDownstream,
  // Disallowed because no WiFi security modes are supported.
  kDisallowedNoWiFiSecurityModes,
  // Disallowed because there's no upstream mobile data connectivity.
  kDisallowedNoMobileData,
  // Disallowed because the tethering readiness check failed.
  kDisallowedReadinessCheckFail,
  // Disallowed because policy prohibited.
  kDisallowedByPolicy,
  kAllowed,
};

// Result code when enabling/disabling hotspot.
enum HotspotControlResult {
  // Operation succeeded.
  kSuccess,
  // Hotspot capabilities not allowed.
  kNotAllowed,
  // Tethering readiness check failed.
  kReadinessCheckFailed,
  // Couldn't disable Wifi before enabling hotspot.
  kDisableWifiFailed,
  // Invalid tethering configuration.
  kInvalidConfiguration,
  // Upstream network is not available.
  kUpstreamNotAvailable,
  // Failed to setup or tear down network layer for hotspot.
  kNetworkSetupFailure,
  // Downstream WiFi operation failure.
  kDownstreamWifiFailure,
  // Upstream network operation failure.
  kUpstreamFailure,
  // Failed due to Shill operation error.
  kShillOperationFailed,
  // The hotspot's current state is the same as the state requested.
  kAlreadyFulfilled,
  // Hotspot enable request has been aborted.
  kAborted,
  // Invalid hotspot enable request.
  kInvalid,
  kUnknownFailure,
};

// Reason for why hotspot was turned off.
enum DisableReason {
  // Disabled automatically because no clients were connected for a
  // fixed amount of time. Note that HotspotConfig’s |auto_disabled|
  // has to be true for this to have happened.
  kAutoDisabled,
  // Disabled because of an internal reason.
  kInternalError,
  // Disabled because user switched off Hotspot tethering manually.
  kUserInitiated,
  // Disabled because WiFi was enabled.
  kWifiEnabled,
  // Disabled because Hotspot was prohibited by policy.
  kProhibitedByPolicy,
  // Disabled because there is no Mobile Data.
  kUpstreamNetworkNotAvailable,
  // Disabled because the device has been suspended.
  kSuspended,
  // Disabled because hotspot need to be restarted.
  kRestart,
  // Disabled because the upstream network doesn't have Internet connectivity.
  kUpstreamNoInternet,
  // Disabled because the downstream link disconnected.
  kDownstreamLinkDisconnect,
  // Disabled because the downstream network disconnected.
  kDownstreamNetworkDisconnect,
  // Failed to start tethering within given time.
  kStartTimeout,
  // Upstream network not available.
  kUpstreamNotAvailable,
  // Received an unknown error from shill.
  kUnknownError,
};

// Information about Hotspot feature including current state, active client
// count, supported security modes and configuration.
struct HotspotInfo {
  // Current Hotspot state.
  HotspotState state;
  // Total number clients currently connected.
  uint32 client_count;
  // Indicates whether hotspot is allowed.
  HotspotAllowStatus allow_status;
  // Supported WiFi security modes for WiFi downstream.
  array<WiFiSecurityMode> allowed_wifi_security_modes;
  // Hotspot configuration properties. Null if the user is not logged in or
  // initialization has not completed. Observers listen for this value to be set
  // later by implementing the OnHotspotInfoChanged() method.
  HotspotConfig? config;
};

// CrosHotspotConfig interface provides methods to get current hotspot status,
// configure, enable or disable hotspot.
interface CrosHotspotConfig {
  // Adds an observer that can listen to hotspot related events. Invokes
  // OnHotspotInfoChange() when observer is added.
  AddObserver(pending_remote<CrosHotspotConfigObserver> observer);

  // Adds an observer to listen to hotspot turned on/off events.
  ObserveEnabledStateChanges(
    pending_remote<HotspotEnabledStateObserver> observer);

  // Returns HotspotInfo structure containing state, client count, capabilities,
  // supported security modes and configuration properties of Hotspot.
  GetHotspotInfo() => (HotspotInfo hotspot_info);

  // Sets configuration properties for hotspot.
  SetHotspotConfig(HotspotConfig config) => (SetHotspotConfigResult result);

  // Attempts to enable hotspot.
  EnableHotspot() => (HotspotControlResult result);

  // Disables hotspot if already enabled. This is a no-op if hotspot is already
  // disabled.
  DisableHotspot() => (HotspotControlResult result);
};

// CrosHotspotConfigObserver is implemented by any module that needs to observe
// changes to the hotspot status.
interface CrosHotspotConfigObserver {
  // Called when there is a state, client count, configuration or capability
  // change within Hotspot.
  OnHotspotInfoChanged();
};

// HotspotEnabledStateObserver is implemented by any module that needs
// to observe changes to the hotspot enabled state.
interface HotspotEnabledStateObserver {
  // Called when Hotspot is successfully turned on.
  OnHotspotTurnedOn();

  // Called when Hotspot is successfully turned off. `disable_reason`
  // indicates the reason why Hotspot was turned off.
  OnHotspotTurnedOff(DisableReason reason);
};