/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.tv.cec@1.0;

enum MaxLength : int32_t {
    MESSAGE_BODY = 15,
};

enum CecDeviceType : int32_t {
    INACTIVE = -1,
    TV = 0,
    RECORDER = 1,
    TUNER = 3,
    PLAYBACK = 4,
    AUDIO_SYSTEM = 5,
    MAX = AUDIO_SYSTEM,
};

enum CecLogicalAddress : int32_t {
    TV = 0,
    RECORDER_1 = 1,
    RECORDER_2 = 2,
    TUNER_1 = 3,
    PLAYBACK_1 = 4,
    AUDIO_SYSTEM = 5,
    TUNER_2 = 6,
    TUNER_3 = 7,
    PLAYBACK_2 = 8,
    RECORDER_3 = 9,
    TUNER_4 = 10,
    PLAYBACK_3 = 11,
    FREE_USE = 14,
    UNREGISTERED = 15, // as Initiator address
    BROADCAST = 15, // as Destination address
};

/**
 * HDMI CEC message types. The assigned values represent opcode used in CEC
 * frame as specified in CEC Table 8-26 of the CEC Spec 1.4b.
 */
enum CecMessageType : int32_t {
    FEATURE_ABORT = 0x00,
    IMAGE_VIEW_ON = 0x04,
    TUNER_STEP_INCREMENT = 0x05,
    TUNER_STEP_DECREMENT = 0x06,
    TUNER_DEVICE_STATUS = 0x07,
    GIVE_TUNER_DEVICE_STATUS = 0x08,
    RECORD_ON = 0x09,
    RECORD_STATUS = 0x0A,
    RECORD_OFF = 0x0B,
    TEXT_VIEW_ON = 0x0D,
    RECORD_TV_SCREEN = 0x0F,
    GIVE_DECK_STATUS = 0x1A,
    DECK_STATUS = 0x1B,
    SET_MENU_LANGUAGE = 0x32,
    CLEAR_ANALOG_TIMER = 0x33,
    SET_ANALOG_TIMER = 0x34,
    TIMER_STATUS = 0x35,
    STANDBY = 0x36,
    PLAY = 0x41,
    DECK_CONTROL = 0x42,
    TIMER_CLEARED_STATUS = 0x43,
    USER_CONTROL_PRESSED = 0x44,
    USER_CONTROL_RELEASED = 0x45,
    GIVE_OSD_NAME = 0x46,
    SET_OSD_NAME = 0x47,
    SET_OSD_STRING = 0x64,
    SET_TIMER_PROGRAM_TITLE = 0x67,
    SYSTEM_AUDIO_MODE_REQUEST = 0x70,
    GIVE_AUDIO_STATUS = 0x71,
    SET_SYSTEM_AUDIO_MODE = 0x72,
    REPORT_AUDIO_STATUS = 0x7A,
    GIVE_SYSTEM_AUDIO_MODE_STATUS = 0x7D,
    SYSTEM_AUDIO_MODE_STATUS = 0x7E,
    ROUTING_CHANGE = 0x80,
    ROUTING_INFORMATION = 0x81,
    ACTIVE_SOURCE = 0x82,
    GIVE_PHYSICAL_ADDRESS = 0x83,
    REPORT_PHYSICAL_ADDRESS = 0x84,
    REQUEST_ACTIVE_SOURCE = 0x85,
    SET_STREAM_PATH = 0x86,
    DEVICE_VENDOR_ID = 0x87,
    VENDOR_COMMAND = 0x89,
    VENDOR_REMOTE_BUTTON_DOWN = 0x8A,
    VENDOR_REMOTE_BUTTON_UP = 0x8B,
    GIVE_DEVICE_VENDOR_ID = 0x8C,
    MENU_REQUEST = 0x8D,
    MENU_STATUS = 0x8E,
    GIVE_DEVICE_POWER_STATUS = 0x8F,
    REPORT_POWER_STATUS = 0x90,
    GET_MENU_LANGUAGE = 0x91,
    SELECT_ANALOG_SERVICE = 0x92,
    SELECT_DIGITAL_SERVICE = 0x93,
    SET_DIGITAL_TIMER = 0x97,
    CLEAR_DIGITAL_TIMER = 0x99,
    SET_AUDIO_RATE = 0x9A,
    INACTIVE_SOURCE = 0x9D,
    CEC_VERSION = 0x9E,
    GET_CEC_VERSION = 0x9F,
    VENDOR_COMMAND_WITH_ID = 0xA0,
    CLEAR_EXTERNAL_TIMER = 0xA1,
    SET_EXTERNAL_TIMER = 0xA2,
    REPORT_SHORT_AUDIO_DESCRIPTOR = 0xA3,
    REQUEST_SHORT_AUDIO_DESCRIPTOR = 0xA4,
    INITIATE_ARC = 0xC0,
    REPORT_ARC_INITIATED = 0xC1,
    REPORT_ARC_TERMINATED = 0xC2,
    REQUEST_ARC_INITIATION = 0xC3,
    REQUEST_ARC_TERMINATION = 0xC4,
    TERMINATE_ARC = 0xC5,
    ABORT = 0xFF,
};

/**
 * Operand description [Abort Reason]
 */
enum AbortReason : int32_t {
    UNRECOGNIZED_MODE = 0,
    NOT_IN_CORRECT_MODE = 1,
    CANNOT_PROVIDE_SOURCE = 2,
    INVALID_OPERAND = 3,
    REFUSED = 4,
    UNABLE_TO_DETERMINE = 5,
};

enum Result : int32_t {
    SUCCESS = 0,
    FAILURE_UNKNOWN = 1,
    FAILURE_INVALID_ARGS = 2,
    FAILURE_INVALID_STATE = 3,
    FAILURE_NOT_SUPPORTED = 4,
    FAILURE_BUSY = 5,
};

/**
 * error code used for send_message.
 */
enum SendMessageResult : int32_t {
    SUCCESS = 0,
    NACK = 1, // not acknowledged
    BUSY = 2, // bus is busy
    FAIL = 3,
};

/**
 * HDMI port type.
 */
enum HdmiPortType : int32_t {
    INPUT = 0,
    OUTPUT = 1,
};

/**
 * Options used for IHdmiCec.setOption()
 */
enum OptionKey : int32_t {
    /**
     * When set to false, HAL does not wake up the system upon receiving <Image
     * View On> or <Text View On>. Used when user changes the TV settings to
     * disable the auto TV on functionality.
     * True by default.
     */
    WAKEUP = 1,

    /**
     * When set to false, all the CEC commands are discarded. Used when user
     * changes the TV settings to disable CEC functionality.
     * True by default.
     */
    ENABLE_CEC = 2,

    /**
     * Setting this flag to false means Android system must stop handling CEC
     * service and yield the control over to the microprocessor that is powered
     * on through the standby mode. When set to true, the system must gain the
     * control over, hence telling the microprocessor to stop handling the CEC
     * commands. For example, this may be called when system goes in and out of
     * standby mode to notify the microprocessor that it should start/stop
     * handling CEC commands on behalf of the system.
     * False by default.
     */
    SYSTEM_CEC_CONTROL = 3,

    /* Option 4 not used */
};

struct CecMessage {
    /** logical address of sender */
    CecLogicalAddress initiator;

    /** logical address of receiver */
    CecLogicalAddress destination;

    /**
     * The maximum size of body is 15 (MaxLength::MESSAGE_BODY) as specified in
     * the section 6 of the CEC Spec 1.4b. Overflowed data must be ignored. */
    vec<uint8_t> body;
};

struct HotplugEvent {
    bool connected;
    uint32_t portId;
};

/**
 * HDMI port descriptor
 */
struct HdmiPortInfo {
    HdmiPortType type;
    uint32_t portId; // Should start from 1 which corresponds to HDMI "port 1".
    bool cecSupported;
    bool arcSupported;
    uint16_t physicalAddress;
};
