// Copyright 2024 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.wifi_direct.mojom;
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum WifiDirectOperationResult {
kSuccess,
// Wifi Direct is disallowed in platform per Manager.P2PAllowed.
kNotAllowed,
// Wifi Direct operation is not supported in the platform.
kNotSupported,
// Not currently connected to a P2P group.
kNotConnected,
// Creating Wifi Direct interface is not possible with existing interfaces.
kConcurrencyNotSupported,
// The requested frequency is not supported.
kFrequencyNotSupported,
// Wifi Direct group rejects the authentication attempt.
kAuthFailure,
// Didn't discover the Wifi Direct group.
kGroupNotFound,
// Already connected to the Wifi Direct group.
kAlreadyConnected,
kOperationInProgress,
kInvalidArguments,
// Wifi Direct operation timed out.
kTimeout,
// Wifi Direct operation response has an invalid result code.
kInvalidResultCode,
// Wifi Direct group miss or has invalid properties.
kInvalidGroupProperties,
kUnknownFailure,
};
struct WifiP2PCapabilities {
// Boolean indicating if the device is ready to create a P2P group.
bool is_owner_ready;
// Boolean indicating if the device is ready to connect to a P2P group.
bool is_client_ready;
// Boolean indicating if the device supports P2P capabilities.
bool is_p2p_supported;
};
struct WifiCredentials {
string ssid;
string passphrase;
};
// WifiDirectManager provides Wifi Direct management methods. An instance of
// this interface is owned in the browser process in Ash.
interface WifiDirectManager {
// Creates a WifiDirectConnection as group owner and returns a result along
// with a pending remote of WifiDirectConnection object (a NullRemote will be
// returned if the result is anything but kSuccess). Disconnecting from the
// remote object will invoke the disconnect handler in WifiDirectConnection
// that will in turn tear down the WiFi Direct group. Callers should also
// register a disconnect handler on the remote side to be notified and handle
// the case where the Wifi Direct group is disconnected by Shill internally.
// If the credentials are not provided, it will be generated by the system.
// If the credentials are provided, the SSID should be a UTF8 string that
// must match the requirements for a WiFi Direct ssid per WiFi Direct
// v1.9 3.2.1 (i.e. must begin with DIRECT-xy where x and y are random
// letters/numbers). The passphrase must be at least 8 characters long.
CreateWifiDirectGroup(WifiCredentials? credentials) =>
(WifiDirectOperationResult result,
pending_remote<WifiDirectConnection>? wifi_direct_connection);
// Connects to the Wifi Direct Group as group client and returns a result
// along with a pending remote of WifiDirectConnection object (a NullRemote
// will be returned if the result is anything but kSuccess). Disconnecting
// from the remote object will invoke the disconnect handler in
// WifiDirectConnection that will in turn disconnect to the WiFi Direct group.
// Callers should also register a disconnect handler on the remote side to be
// notified and handle the case where the Wifi Direct group is disconnected by
// Shill internally. If the frequency is provided, the operation will fail
// when the group is not found at the specified frequency. If the frequency
// is omitted, system will scan all supported channels to find the group.
ConnectToWifiDirectGroup(WifiCredentials credentials, uint32? frequency) =>
(WifiDirectOperationResult result,
pending_remote<WifiDirectConnection>? wifi_direct_connection);
// Fetches the current P2P capabilities of the devices, namely is the device
// ready to become a group owner and is the device ready to connect to an
// existing P2P group. The structure WifiP2PCapabilities will have two boolean
// flags indicating group and client readiness.
GetWifiP2PCapabilities() => (WifiP2PCapabilities capabilities);
};
struct WifiDirectConnectionProperties {
WifiCredentials credentials;
uint32 frequency;
string ipv4_address;
};
// WifiDirectConnection represents an active Wifi Direct group that was created
// or connected to from WifiDirectManager. This interface should only be
// accessed by Nearby share process and Lacros browser (for WiFi Direct
// streaming).
interface WifiDirectConnection {
// Returns the properties of the Wifi Direct network group.
GetProperties() => (WifiDirectConnectionProperties properties);
// Associate the TCP/UDP socket to the WiFi Direct group network so that
// traffic can consistently be sent and received on the WiFi Direct
// connection.
AssociateSocket(handle<platform> socket) => (bool success);
};