// Copyright 2020 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.secure_channel.mojom;
import "chromeos/ash/services/secure_channel/public/mojom/secure_channel_types.mojom";
// Service ID to use. Nearby Connections requires a service ID to be associated
// with each connection request.
const string kServiceId = "secure_channel";
// Emitted with Structured Metrics, do not modify existing values
enum NearbyConnectionStep {
kDiscoveringEndpointStarted = 0,
kDiscoveringEndpointEnded = 1,
kRequestingConnectionStarted = 2,
kRequestingConnectionEnded = 3,
kAcceptingConnectionStarted = 4,
kAcceptingConnectionFinished = 5,
kWaitingForConnectionToBeAcceptedByRemoteDeviceStarted = 6,
kWaitingForConnectionToBeAcceptedByRemoteDeviceEnded = 7,
kConnected = 8,
kUpgradedToWebRtc = 9,
kDisconnectionStarted = 10,
kDisconnectionFinished = 11
};
// Emitted with Structured Metrics, do not modify existing values
enum NearbyConnectionStepResult {
kSuccess = 0,
// The operation to transition to another NearbyConnectionState timeout.
kTimeoutTransitionState = 1,
// The error codes below map to error status of
// nearby.connections.mojom::Status
kError = 2,
kOutOfOrderApiCall = 3,
kAlreadyHaveActiveStrategy = 4,
kAlreadyAdvertising = 5,
kAlreadyDiscovering = 6,
kEndpointIOError = 7,
kEndpointUnknown = 8,
kConnectionRejected = 9,
kAlreadyConnectedToEndpoint = 10,
kNotConnectedToEndpoint = 11,
kBluetoothError = 12,
kBleError = 13,
kWifiLanError = 14,
kPayloadUnknown = 15,
kAlreadyListening = 16,
kReset = 17,
kTimeout = 18,
kUnknown = 19,
};
// Listens to Nearby Connection state change. This is called from non-service
// browser process code, where the NearbyConnector runs, into SecureChannel
// service, which runs in the browser process.
interface NearbyConnectionStateListener {
// Called whenever Nearby Connection state changes.
OnNearbyConnectionStateChanged(NearbyConnectionStep step,
NearbyConnectionStepResult result);
};
// Sends messages over a Nearby Connection.
interface NearbyMessageSender {
// Sends |message|, returning whether the message was sent successfully.
SendMessage(string message) => (bool success);
};
// Receives messages over a Nearby connection.
interface NearbyMessageReceiver {
// Called whenever a message is received over the connection.
OnMessageReceived(string message);
};
// Registers incoming file transfers over a Nearby Connection, and allows
// callers to listen to progress information about those transfers.
interface NearbyFilePayloadHandler {
// Registers |payload_files| to receive an incoming file transfer with
// the given |payload_id|. Callers can listen to progress information about
// the transfer through the |listener|. Returns whether the file was
// successfully registered.
RegisterPayloadFile(int64 payload_id,
PayloadFiles payload_files,
pending_remote<FilePayloadListener> listener)
=> (bool success);
};
// Provides an interface to make a SecureChannel connection over the Nearby
// Connections library. This is called from the SecureChannel service (which
// runs in the browser process) into non-service browser process code, where
// the NearbyConnector runs. The NearbyConnector then delegates to the Nearby
// utility process to make the connection to the remote device.
interface NearbyConnector {
// Starts a connection attempt to the device with the provided address, using
// |kServiceId| as the service ID for the connection and |eid| as the data
// sent in the connection initiation attempt. The EID is the same EID that
// was detected in the remote device's BLE advertisement. If the attempt
// succeeds, a NearbyMessageSender and a NearbyFilePayloadHandler are returned
// to the caller, enabling the caller to send messages and register incoming
// file transfers over the connection. If the attempt fails, null is returned.
//
// To disconnect an active connection, disconnect either |message_receiver| or
// |message_sender|. If the remote device disconnects an active connection,
// these are both disconnected; clients should set disconnection handlers to
// be notified if a disconnection should occur.
Connect(array<uint8, 6> bluetooth_public_address,
array<uint8, 2> eid,
pending_remote<NearbyMessageReceiver> message_receiver,
pending_remote<NearbyConnectionStateListener>
nearby_connection_state_listener) =>
(pending_remote<NearbyMessageSender>? message_sender,
pending_remote<NearbyFilePayloadHandler>? file_payload_handler);
};