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

syntax = "proto3";

package chromiumos.test.lab.api;

option go_package = "go.chromium.org/chromiumos/config/go/test/lab/api";

import "chromiumos/config/api/device_config_id.proto";
import "chromiumos/test/lab/api/ip_endpoint.proto";
import "chromiumos/test/lab/api/pasit_host.proto";
import "chromiumos/test/lab/api/rpm.proto";
import "chromiumos/test/lab/api/wifi_router.proto";

// Specification of Device Under Test.
// Next Tag: 8
message Dut {
  // Unique identifier for the lab device. It can be the DUT serial number
  // (e.g. "C144091") derived from the DUT itself or some other unique value
  // regarding different contexts.
  message Id {
    string value = 1;
  }

  Id id = 1;

  oneof dut_type {
    ChromeOS chromeos = 2;
    Android android = 3;
    Devboard devboard = 5;
  }

  // Chrome OS specific DUT details
  // Populated by and should be kept in sync with UFS adapter in:
  // https://source.chromium.org/chromium/infra/infra/+/main:go/src/infra/cros/cmd/labservice/internal/ufs/ufs.go
  // NEXT TAG: 24
  message ChromeOS {
    // Unique identifiers around the device's hardware, manufacturing, and brand
    // configuration.
    chromiumos.config.api.DeviceConfigId device_config_id = 3;
    // Endpoint for ssh service running on the device
    IpEndpoint ssh = 2;

    // ChromeOS DUT name that is usually associated with the hostname.
    // Example: "chromeos6-row16-rack11-host1"
    string name = 15;

    DutModel dut_model = 14;
    Servo servo = 4;
    Chameleon chameleon = 5;
    RPM rpm = 6;
    repeated ExternalCamera external_cameras = 7;
    Audio audio = 8;
    Wifi wifi = 9;
    Touch touch = 10;
    Camerabox camerabox = 11;
    repeated Cable cables = 12;
    Cellular cellular = 13;
    repeated string hwid_component = 16;
    repeated BluetoothPeer bluetooth_peers = 17;
    string sku = 18;
    string hwid = 19;
    Phase phase = 20;
    repeated SIMInfo sim_infos = 21;
    ModemInfo modem_info = 22;
    // The host and topology used in peripheral interop test beds.
    PasitHost pasit_host = 23;

    reserved 1;
  }

  // Android specific DUT details
  message Android {
    // A hostname of the device that the Android DUT is attached to.
    IpEndpoint associated_hostname = 1;
    // Android DUT name.
    string name = 2;
    // A string created by adb to uniquely identify the device.
    string serial_number = 3;
    DutModel dut_model = 4;
    Servo servo = 5;
  }

  // Devboard specific DUT details
  message Devboard {
    // The type of devboard, e.g., andreiboard.
    string board_type = 1;
    // Serial for the UltraDebug interface, if present.
    // Deprecated, use debugger_serial.
    string ultradebug_serial = 2;
    Servo servo = 3;
    // An ID string for the fingerprint module.
    string fingerprint_module_id = 4;
    // Devboard DUT name.
    string name = 5;
    DutModel dut_model = 6;
    string gsc_serial = 7;
    // Serial for the debugger interface.
    string debugger_serial = 8;
  }

  // Cache server for downloading artifacts related to this DUT.
  CacheServer cache_server = 4;

  // The secret for wifi tests.
  WifiSecret wifi_secret = 6;
  // Pools related to the DUT.
  repeated string pools = 7;
}

// Defines the build target/board and model of the Dut
message DutModel {
  string build_target = 1;
  string model_name = 2;
}

// Defines the topology of connected devices under test
message DutTopology {
  // Unique identifier for a given dut topology (schedulable lab unit)
  message Id {
    string value = 1;
  }
  Id id = 3;

  // Collection of devices that are used in a given test.
  // Generally, this will contain a single Dut for an functional test that
  // doesn't depend on other devices, but can include a collection of devices
  // used in multi-dut testing (e.g. ChromeOS to ChromeOS, ChromeOS to Android,
  // etc...)
  repeated Dut duts = 4;

  reserved 1, 2;
}

// Peripherals related to audio input and output from the Device.
message Audio {
  // Device is housed in an audio box to record / replay audio
  // for audio testing.
  bool audio_box = 1;
  // Device is connected to Atrus speakermic.
  bool atrus = 2;
}

// A cable connecting the device to audio, printer and other peripherals.
message Cable {
  enum Type {
    TYPE_UNSPECIFIED = 0;
    AUDIOJACK = 1;
    USBAUDIO = 2;
    USBPRINTING = 3;
    HDMIAUDIO = 4;
  }
  Type type = 1;
}

// A cache server for downloading artifacts.
//
// The server should support the following HTTP requests:
//
// GET /download/GS_BUCKET/GS_PATH
// Download a file from Google Storage.
//
// GET /extract/GS_BUCKET/GS_PATH?file=TAR_PATH
// Download a file within a (possibly compressed) TAR archive stored
// in Google Storage.
//
// GET /decompress/GS_BUCKET/GS_PATH
// Download the decompressed data of a compressed file from Google Storage.
message CacheServer {
  // HTTP address for the cache server.
  IpEndpoint address = 1;
}

// A steady and controllable camera box environment for the device, used by
// camera test automation. http://go/cros-camera-box
message Camerabox {
  // Facing of DUT's camera to be tested whose FOV should cover chart tablet's
  // screen.
  enum Facing {
    FACING_UNSPECIFIED = 0;
    // DUT's back camera faces the chart tablet.
    BACK = 1;
    // DUT's front camera faces to chart tablet.
    FRONT = 2;
  }
  Facing facing = 1;
}

message Cellular {
  enum Operator {
    OPERATOR_UNSPECIFIED = 0;
    ATT = 1;
    VERIZON = 2;
    TMOBILE = 3;
  }
  // Cellular operators supported by the SIM installed in the device.
  // Note this is not used as it has been superseded by SimInfo.
  repeated Operator operators = 1;

  // Carrier is the DUTs carrier name/type from:
  // https://source.chromium.org/chromium/infra/infra/+/main:go/src/infra/unifiedfleet/api/v1/models/chromeos/lab/peripherals.proto;l=31
  string carrier = 2;
}

// ModemInfo is adapted from ufs and should be kept in sync with:
// https://source.chromium.org/chromium/infra/infra/+/main:go/src/infra/unifiedfleet/api/v1/models/chromeos/lab/modeminfo.proto
// Next Tag: 6
message ModemInfo {
  ModemType type = 1;
  string imei = 2;
  string supported_bands = 3;
  int32 sim_count = 4;
  string model_variant = 5;
}

// Next Tag: 13
enum ModemType {
  MODEM_TYPE_UNSPECIFIED = 0;
  MODEM_TYPE_UNSUPPORTED = 8;
  MODEM_TYPE_QUALCOMM_SC7180 = 1;
  MODEM_TYPE_FIBOCOMM_L850GL = 2;
  MODEM_TYPE_NL668 = 3;
  MODEM_TYPE_FM350 = 4;
  MODEM_TYPE_FM101 = 5;
  MODEM_TYPE_QUALCOMM_SC7280 = 6;
  MODEM_TYPE_EM060 = 7;
  MODEM_TYPE_RW101 = 9;
  MODEM_TYPE_RW135 = 10;
  MODEM_TYPE_LCUK54 = 11;
  MODEM_TYPE_RW350 = 12;
}

message SIMInfo {
  int32 slot_id = 1;
  SIMType type = 2;
  string eid = 3;
  bool test_esim = 4;
  repeated SIMProfileInfo profile_info = 5;
}

message SIMProfileInfo {
  string iccid = 1;
  string sim_pin = 2;
  string sim_puk = 3;
  NetworkProvider carrier_name = 4;
  string own_number = 5;
  // The SIM state as reported by the cellular modem.
  State state = 6;

  // Possible states of the SIM profile.
  enum State {
    // State not set.
    UNSPECIFIED = 0;
    // The device is unusable.
    BROKEN = 1;
    // The device needs to be unlocked.
    LOCKED = 2;
    // No data connection available and not in a failed state.
    NO_NETWORK = 3;
    // The device is registered with a network provider, and data connections
    // and messaging may be available for use.
    WORKING = 4;
    // The device has an invalid configuration in UFS.
    WRONG_CONFIG = 5;
  }

  // Features supported by the profile.
  // These features are used to determine what tests can be run against which
  // SIMs in the lab, see go/cros-cellular-features for more information. File
  // bugs against buganizer component: 979102.
  repeated Feature features = 7;

  // Possible features that the SIM supports.
  enum Feature {
    // Unset feature.
    FEATURE_UNSPECIFIED = 0;
    // The SIM supports a generic live network.
    FEATURE_LIVE_NETWORK = 1;
    // The SIM supports SMS messaging.
    FEATURE_SMS = 2;
  }
}

enum NetworkProvider {
  NETWORK_OTHER = 0;
  NETWORK_UNSUPPORTED = 5;
  NETWORK_TEST = 1;
  NETWORK_ATT = 2;
  NETWORK_TMOBILE = 3;
  NETWORK_VERIZON = 4;
  NETWORK_SPRINT = 6;
  NETWORK_DOCOMO = 7;
  NETWORK_SOFTBANK = 8;
  NETWORK_KDDI = 9;
  NETWORK_RAKUTEN = 10;
  NETWORK_VODAFONE = 11;
  NETWORK_EE = 12;
  NETWORK_AMARISOFT = 13;
  NETWORK_ROGER = 14;
  NETWORK_BELL = 15;
  NETWORK_TELUS = 16;
  NETWORK_FI = 17;
  NETWORK_CBRS = 18;
  NETWORK_LINEMO = 19;
  NETWORK_POVO = 20;
  NETWORK_HANSHIN = 21;
}

enum SIMType {
  SIM_UNKNOWN = 0;
  SIM_PHYSICAL = 1;
  SIM_DIGITAL = 2;
}

// See https://sites.google.com/a/google.com/cros-chameleon/home
message Chameleon {
  enum Peripheral {
    // TODO(b/268202522): remove obsolete chameleon types
    PERIPHERAL_UNSPECIFIED = 0;
    BT_HID = 1;
    // Display Port
    DP = 2;
    DP_HDMI = 3;
    VGA = 4;
    // High Definition Multimedia Interface
    HDMI = 5;
    BT_BLE_HID = 6;
    BT_A2DP_SINK = 7;
    BT_PEER = 8;
    // Raspberry Pi
    RPI = 9;
  }
  repeated Peripheral peripherals = 1;
  // Indicate if there's an audio_board in the chameleon.
  bool audio_board = 2;
  PeripheralState state = 3;
  string hostname = 4;
  enum Type {
    TYPE_UNSPECIFIED = 0;
    V2 = 1;
    V3 = 2;
  }
  repeated Type types = 5;
}

// External camera connected to the device.
message ExternalCamera {
  enum Type {
    TYPE_UNSPECIFIED = 0;
    // camera Huddly GO
    HUDDLY = 1;
    // camera Logitech PTZ Pro 2
    PTZPRO2 = 2;
  }
  Type type = 1;
}

// Servo control of the device.
message Servo {
  bool present = 1;
  // Address to the host running the servod daemon.
  // Port number servod is listening on.
  IpEndpoint servod_address = 2;
  // Serial number of the servo.
  string serial = 3;
  // Current state of the servo, updated by latest auto-repair.
  PeripheralState state = 4;
  // The name for the container that runs the servod.
  string container_name = 5;
}

message Touch {
  // Has touch monitor mimo.
  bool mimo = 1;
}

// Wifi environment of the device.
message Wifi {
  enum Environment {
    ENVIRONMENT_UNSPECIFIED = 0;
    // Device is setup without any special wifi environment.
    STANDARD = 1;
    // Device is inside a hermetic wifi cell.
    WIFI_CELL = 2;
    // Device is setup in a chaos environment. It's a special settings for
    // running wifi interop tests.
    CHAOS = 3;
    // In an environment where the AP is 802.11ax compliant.
    // Context: crbug.com/1044786
    ROUTER_802_11AX = 4;
  }
  Environment environment = 1;
  WifiAntenna antenna = 2;

  // WiFi APs assigned to the device.
  repeated WifiRouter wifi_routers = 3;
}

message WifiAntenna {
  // DUT's WiFi antenna's connection.
  enum Connection {
    CONNECTION_UNSPECIFIED = 0;
    // WIFI antenna is connected conductively.
    CONDUCTIVE = 1;
    // WIFI antenna is connected over-the-air.
    OTA = 2;
  }
  Connection connection = 1;
}

// WiFi APs attached to the DUT.
// Note: Define here rather than in wifi_router.proto so we can reference RPM in
// the future even though it's not used at the moment.
//
// Source of truth:
// https://source.chromium.org/chromium/infra/infra_superproject/+/main:infra/go/src/infra/unifiedfleet/api/v1/models/chromeos/lab/peripherals.proto
message WifiRouter {
  string hostname = 1;
  PeripheralState state = 2;
  // Model of the router (e.g. OPENWRT[Ubiquiti_UniFi_6_Lite], gale).
  string model = 3;

  // RPM to perform remote power management.
  RPM rpm = 4;

  // Supported test router hardware and software features.
  repeated WifiRouterFeature supported_features = 5;

  // The type of router device this is (e.g. OpenWrt-based, ChromeOS Gale).
  WifiRouterDeviceType device_type = 6;
}

// Bluetooth Peers attached to the DUT.
message BluetoothPeer {
  string hostname = 1;
  PeripheralState state = 2;
}

// Next Tag: 3
enum PeripheralState {
  PERIPHERAL_STATE_UNSPECIFIED = 0;
  WORKING = 1;
  BROKEN = 2;
  NOT_APPLICABLE = 3;
}

// Next Tag: 34
enum Phase {
  PHASE_UNSPECIFIED = 0;
  DVT = 1;
  DVT_2 = 2;
  DVT_2_MPS_LTE = 3;
  DVT_BIPSHIP = 4;
  DVT_BOOKEM = 5;
  DVT_ELECTRO = 6;
  DVT_LOCKE = 7;
  DVT_OSCINO = 8;
  DVT_REKS14 = 9;
  DVT_REKS14_TOUCH = 10;
  DVT_TOUCH = 11;
  EVT = 12;
  EVT_FLEEX_LTE = 13;
  EVT_HQ = 14;
  EVT_LTE = 15;
  EVT_MAPLE = 16;
  EVT_PUJJO = 17;
  PROTO = 18;
  PROTO1 = 19;
  PVT = 20;
  PVT_TERRA3 = 21;
  PVT_US = 22;
  PVT_2 = 23;
  PVT_BOOKEM = 24;
  PVT_ELECTRO = 25;
  PVT_GIK360 = 26;
  PVT_LILI = 27;
  PVT_LTE = 28;
  PVT_NEW_CPU = 29;
  PVT_SAND = 30;
  PVT_TUNE_BITS = 31;
  PVT_TELESU = 32;
  SR = 33;
}

// Next Tag: 4
// WifiSecret is the secret used for wifi tests.
message WifiSecret {
  string ssid = 1;      // wifi SSID
  string security = 2;  // security protocol, e.g. WEP, WPA, etc.
  string password = 3;  // wifi password
}
