/**
 * \file    prl_msg_defs.h
 * \brief   Protocol layer message definitions
 *
 * \par     Copyright (c) 2018 UWE Technologies Corp., Ltd. All Rights Reserved.
 * \author  James
 * \date    2018-03-17
 * \version 
 * 
 * \history 
 *  Date        Note
 *  2018-03-17  Original Creation
 * 
 */
 
#ifndef __PRL_MSG_DEFS_H_
#define __PRL_MSG_DEFS_H_

#include "arch.h"
#include "types.h"

#pragma pack(1)

#define UPD_MSG_HEAD_LEN 2
#define UPD_MSG_EXT_HEAD_LEN 2
#define UPD_MSG_EXT_MAX_CHUNK_LEN 26
#define UPD_MSG_DATA_OBJ_SIZE 4
#define UPD_MSG_VDM_HEAD_LEN 4

/* UPD message header, Supported R3.0 */
typedef struct UPD_MSG_HEAD_s 
{
#if __LITTLE_ENDIAN__
    u16_t msg_type:5;            /* Message Type */
    u16_t port_dr:1;             /* Port Data Role; or Reserved 0 */
    u16_t spec_rev:2;            /* Specification Revision */
    u16_t cbl_plg_or_port_pr:1;  /* Cable Plug or Port Power Role */
    u16_t msg_id:3;              /* MessageID */
    u16_t data_obj_num:3;        /* Number of Data Objects */
    u16_t extended:1;            /* Extended */
#else
    u16_t extended:1;            /* Extended */
    u16_t data_obj_num:3;        /* Number of Data Objects */
    u16_t msg_id:3;              /* MessageID */
    u16_t cbl_plg_or_port_pr:1;  /* Cable Plug or Port Power Role */
    u16_t spec_rev:2;            /* Specification Revision */
    u16_t port_dr:1;             /* Port Data Role; or Reserved 0 */
    u16_t msg_type:5;            /* Message Type */
#endif
} UPD_MSG_HEAD_t;

/* UPD extended message header */
typedef struct UPD_MSG_EXT_HEAD_s 
{
#if __LITTLE_ENDIAN__
    u16_t data_size:9;          /* Data Size */
    u16_t resv:1;               /* Reserved */
    u16_t req_chunk:1;          /* Request Chunk */
    u16_t chunk_num:4;          /* Chunk Number */
    u16_t chunked:1;            /* Chunked */
#else
    u16_t chunked:1;            /* Chunked */
    u16_t chunk_num:4;          /* Chunk Number */
    u16_t req_chunk:1;          /* Request Chunk */
    u16_t resv:1;               /* Reserved */
    u16_t data_size:9;          /* Data Size */
#endif
} UPD_MSG_EXT_HEAD_t;

typedef enum UPD_CTRL_MSG_e
{
    UPD_CTRL_MSG_RESV           = 0x00, /* All values not explicitly defined
                                           are Reserved and Shall Not be used. 
                                         */
    UPD_CTRL_MSG_GOOD_CRC       = 0x01, /* Send by Source; Sink or Cable Plug */
    UPD_CTRL_MSG_GOTO_MIN       = 0x02, /* Send by Source only */
    UPD_CTRL_MSG_ACCEPT         = 0x03, /* Send by Source; Sink or Cable Plug */
    UPD_CTRL_MSG_REJECT         = 0x04, /* Send by Source or Sink */
    UPD_CTRL_MSG_PING           = 0x05, /* Send by Source only */
    UPD_CTRL_MSG_PS_RDY         = 0x06, /* Send by Source or Sink */
    UPD_CTRL_MSG_GET_SOURCE_CAP = 0x07, /* Send by Sink or DRP */
    UPD_CTRL_MSG_GET_SINK_CAP   = 0x08, /* Send by Source or DRP */ 
    UPD_CTRL_MSG_DR_SWAP        = 0x09, /* Send by Source or Sink */ 
    UPD_CTRL_MSG_PR_SWAP        = 0x0A, /* Send by Source or Sink */ 
    UPD_CTRL_MSG_VCONN_SWAP     = 0x0B, /* Send by Source or Sink */ 
    UPD_CTRL_MSG_WAIT           = 0x0C, /* Send by Source or Sink */ 
    UPD_CTRL_MSG_SOFT_RESET     = 0x0D, /* Send by Source or Sink */  
    UPD_CTRL_MSG_NOT_SUPPORTED  = 0x10, /* Send by Source, Sink or Cable Plug */  
    UPD_CTRL_MSG_GET_SOURCE_CAP_EXT = 0x11, /* Send by Sink or DRP */  
    UPD_CTRL_MSG_GET_STATUS     = 0x12, /* Send by Source or Sink */  
    UPD_CTRL_MSG_FR_SWAP        = 0x13, /* Send by Sink */  
    UPD_CTRL_MSG_GET_PPS_STATUS     = 0x14, /* Send by Sink */  
    UPD_CTRL_MSG_GET_COUNTRY_CODES  = 0x15, /* Send by Source or Sink */  
    UPD_CTRL_MSG_GET_SINK_CAP_EXT   = 0x16, /* Send by Source or DRP */  
    UPD_CTRL_MSG_END
} UPD_CTRL_MSG_t;

typedef enum UPD_DATA_MSG_e
{
    UPD_DATA_MSG_SOURCE_CAP     = 0x01, /* Send by Source or Dual-Role operating as Sink */
    UPD_DATA_MSG_REQUEST        = 0x02, /* Send by Sink only */
    UPD_DATA_MSG_BIST           = 0x03, /* Send by Tester, Source or Sink */
    UPD_DATA_MSG_SINK_CAP       = 0x04, /* Send by Sink or DRP */
    UPD_DATA_MSG_BATTERY_STATUS = 0x05, /* Send by Source or Sink */
    UPD_DATA_MSG_ALERT          = 0x06, /* Send by Source or Sink */
    UPD_DATA_MSG_GET_COUNTRY_INFO   = 0x07, /* Send by Source or Sink */
    UPD_DATA_MSG_VENDOR_DEFINED = 0x0F  /* Send by Source; Sink or Cable Plug */
} UPD_DATA_MSG_t;

typedef struct UPD_DATA_MSG_SOURCE_CAP_s
{
#if __LITTLE_ENDIAN__
    u32_t supply_obj:30;        /* Specific Power Capabilities */
    u32_t supply_obj_type:2;    /* Power Data Object */
#else
    u32_t supply_obj_type:2;    /* Power Data Object */
    u32_t supply_obj:30;        /* Specific Power Capabilities */
#endif
} UPD_DATA_MSG_SOURCE_CAP_t;

typedef enum UPD_DATA_MSG_SOURCE_CAP_SUPPLY_OBJ_TYPE_e
{
    UPD_DATA_MSG_SOURCE_CAP_FIXED_SUPPLY,
    UPD_DATA_MSG_SOURCE_CAP_BATTERY,
    UPD_DATA_MSG_SOURCE_CAP_VARIABLE_SUPPLY,
    UPD_DATA_MSG_SOURCE_CAP_APDU
} UPD_DATA_MSG_SOURCE_CAP_SUPPLY_OBJ_TYPE_t;

typedef struct UPD_DATA_MSG_SOURCE_CAP_FIXED_SUPPLY_s
{
#if __LITTLE_ENDIAN__
    u32_t max_curr:10;           /* Maximum Current in 10mA units */
    u32_t volt:10;               /* Voltage in 50mV units */
    u32_t peak_curr:2;           /* Peak Current */
    u32_t resv0:3;               /* Reserved - shall be set to zero. */
    u32_t drs_cap:1;             /* Data Role Swap */
    u32_t usb_comm_cap:1;        /* USB Communications Capable */
    u32_t ext_pwr:1;             /* Unconstrained Power */
    u32_t usb_susp_supp:1;       /* USB Suspend Supported */
    u32_t dual_role_pwr:1;       /* Dual-Role Power */
    u32_t supply_type:2;         /* Fixed supply */
#else
    u32_t supply_type:2;         /* Fixed supply */
    u32_t dual_role_pwr:1;       /* Dual-Role Power */
    u32_t usb_susp_supp:1;       /* USB Suspend Supported */
    u32_t ext_pwr:1;             /* Unconstrained Power */
    u32_t usb_comm_cap:1;        /* USB Communications Capable */
    u32_t drs_cap:1;             /* Data Role Swap */
    u32_t resv0:3;               /* Reserved - shall be set to zero. */
    u32_t peak_curr:2;           /* Peak Current */
    u32_t volt:10;               /* Voltage in 50mV units */
    u32_t max_curr:10;           /* Maximum Current in 10mA units */
#endif
} UPD_DATA_MSG_SOURCE_CAP_FIXED_SUPPLY_t;

typedef struct UPD_DATA_MSG_SOURCE_CAP_VARIABLE_SUPPLY_s
{
#if __LITTLE_ENDIAN__
    u32_t max_curr:10;           /* Maximum Current in 10mA units */
    u32_t min_volt:10;           /* Minimum Voltage in 50mV units */
    u32_t max_volt:10;           /* Maximum Voltage in 50mV units */
    u32_t supply_type:2;         /* Variable supply */
#else
    u32_t supply_type:2;         /* Variable supply */
    u32_t max_volt:10;           /* Maximum Voltage in 50mV units */
    u32_t min_volt:10;           /* Minimum Voltage in 50mV units */
    u32_t max_curr:10;           /* Maximum Current in 10mA units */
#endif
} UPD_DATA_MSG_SOURCE_CAP_VARIABLE_SUPPLY_t;

typedef struct UPD_DATA_MSG_SOURCE_CAP_BATTERY_SUPPLY_s
{
#if __LITTLE_ENDIAN__
    u32_t max_allow_pwr:10;       /* Maximum Allowable Power in 250mW units */
    u32_t min_volt:10;            /* Minimum Voltage in 50mV units */
    u32_t max_volt:10;            /* Maximum Voltage in 50mV units */
    u32_t supply_type:2;          /* Battery supply */
#else
    u32_t supply_type:2;          /* Battery supply */
    u32_t max_volt:10;            /* Maximum Voltage in 50mV units */
    u32_t min_volt:10;            /* Minimum Voltage in 50mV units */
    u32_t max_allow_pwr:10;       /* Maximum Allowable Power in 250mW units */
#endif
} UPD_DATA_MSG_SOURCE_CAP_BATTERY_SUPPLY_t;


typedef struct UPD_DATA_MSG_SOURCE_CAP_PPS_APDU_s
{
#if __LITTLE_ENDIAN__
    u32_t max_curr:7;           /* Maximum Voltage in 50mA increments */
    u32_t resv1:1;              /* Reserved - shall be set to zero. */
    u32_t min_volt:8;           /* Minimum Current in 100mV increments */
    u32_t resv2:1;              /* Reserved - shall be set to zero. */
    u32_t max_volt:8;           /* Maximum Voltage in 100mV increments */
    u32_t resv3:2;              /* Reserved - shall be set to zero. */
    u32_t power_limited:1;      /* PPS Power Limited */
    u32_t pps:2;                /* 00b -Programmable Power Supply */
    u32_t supply_type:2;        /* 11b - Augmented Power Data Object (APDO) */
#else
    u32_t supply_type:2;        /* 11b - Augmented Power Data Object (APDO) */
    u32_t pps:2;                /* 00b -Programmable Power Supply */
    u32_t power_limited:1;      /* PPS Power Limited */
    u32_t resv3:2;              /* Reserved - shall be set to zero. */
    u32_t max_volt:8;           /* Maximum Voltage in 100mV increments */
    u32_t resv2:1;              /* Reserved - shall be set to zero. */
    u32_t min_volt:8;           /* Minimum Current in 100mV increments */
    u32_t resv1:1;              /* Reserved - shall be set to zero. */
    u32_t max_curr:7;           /* Maximum Voltage in 50mA increments */
#endif
} UPD_DATA_MSG_SOURCE_CAP_PPS_APDU_t;


typedef struct UPD_DATA_MSG_SINK_CAP_s
{
#if __LITTLE_ENDIAN__
    u32_t supply_obj:30;          /* Specific Power Capabilities */
    u32_t supply_type:2;         /* Power Data Object */
#else
    u32_t supply_type:2;         /* Power Data Object */
    u32_t supply_obj:30;          /* Specific Power Capabilities */
#endif
} UPD_DATA_MSG_SINK_CAP_t;

typedef enum UPD_DATA_MSG_SINK_CAP_SUPPLY_OBJ_TYPE_e
{
    UPD_DATA_MSG_SINK_CAP_FIXED_SUPPLY,
    UPD_DATA_MSG_SINK_CAP_BATTERY,
    UPD_DATA_MSG_SINK_CAP_VARIABLE_SUPPLY,
    UPD_DATA_MSG_SINK_CAP_APDU
} UPD_DATA_MSG_SINK_CAP_SUPPLY_OBJ_TYPE_t;

typedef struct UPD_DATA_MSG_SINK_CAP_FIXED_SUPPLY_s
{
#if __LITTLE_ENDIAN__
    u32_t max_curr:10;            /* Maximum Current in 10mA units */
    u32_t volt:10;               /* Voltage in 50mV units */
    u32_t resv:3;                /* Reserved - shall be set to zero. */
    u32_t fr_swap_req_curr:2;    /* Fast Role Swap required USB Type-C Current */
    u32_t drs_cap:1;             /* Data Role Swap */
    u32_t usb_comm_cap:1;        /* USB Communications Capable */
    u32_t ext_pwr:1;             /* Unconstrained Power */
    u32_t higher_cap:1;          /* Higher Capability */
    u32_t dual_role_pwr:1;       /* Dual-Role Power */
    u32_t supply_type:2;         /* Fixed supply */
#else
    u32_t supply_type:2;         /* Fixed supply */
    u32_t dual_role_pwr:1;       /* Dual-Role Power */
    u32_t higher_cap:1;          /* Higher Capability */
    u32_t ext_pwr:1;             /* Unconstrained Power */
    u32_t usb_comm_cap:1;        /* USB Communications Capable */
    u32_t drs_cap:1;             /* Data Role Swap */
    u32_t fr_swap_req_curr:2;    /* Fast Role Swap required USB Type-C Current */
    u32_t resv:3;               /* Reserved - shall be set to zero. */
    u32_t volt:10;              /* Voltage in 50mV units */
    u32_t max_curr:10;            /* Maximum Current in 10mA units */
#endif
} UPD_DATA_MSG_SINK_CAP_FIXED_SUPPLY_t;

typedef struct UPD_DATA_MSG_SINK_CAP_VARIABLE_SUPPLY_s
{
#if __LITTLE_ENDIAN__
    u32_t max_curr:10;           /* Maximum Current in 10mA units */
    u32_t min_volt:10;           /* Minimum Voltage in 50mV units */
    u32_t max_volt:10;           /* Maximum Voltage in 50mV units */
    u32_t supply_type:2;         /* Variable supply */
#else
    u32_t supply_type:2;         /* Variable supply */
    u32_t max_volt:10;           /* Maximum Voltage in 50mV units */
    u32_t min_volt:10;           /* Minimum Voltage in 50mV units */
    u32_t max_curr:10;           /* Maximum Current in 10mA units */
#endif
} UPD_DATA_MSG_SINK_CAP_VARIABLE_SUPPLY_t;

typedef struct UPD_DATA_MSG_SINK_CAP_BATTERY_SUPPLY_s
{
#if __LITTLE_ENDIAN__
    u32_t max_allow_pwr:10;       /* Maximum Allowable Power in 250mW units */
    u32_t min_volt:10;            /* Minimum Voltage in 50mV units */
    u32_t max_volt:10;            /* Maximum Voltage in 50mV units */
    u32_t supply_type:2;          /* Battery supply */
#else
    u32_t supply_type:2;          /* Battery supply */
    u32_t max_volt:10;            /* Maximum Voltage in 50mV units */
    u32_t min_volt:10;            /* Minimum Voltage in 50mV units */
    u32_t max_allow_pwr:10;       /* Maximum Allowable Power in 250mW units */
#endif
} UPD_DATA_MSG_SINK_CAP_BATTERY_SUPPLY_t;

typedef struct UPD_DATA_MSG_SINK_CAP_PPS_APDU_s
{
#if __LITTLE_ENDIAN__
    u32_t max_curr:7;           /* Maximum Voltage in 50mA increments */
    u32_t resv1:1;              /* Reserved - shall be set to zero. */
    u32_t min_volt:8;           /* Minimum Current in 100mV increments */
    u32_t resv2:1;              /* Reserved - shall be set to zero. */
    u32_t max_volt:8;           /* Maximum Voltage in 100mV increments */
    u32_t resv3:3;              /* Reserved - shall be set to zero. */
    u32_t pps:2;                /* Programmable Power Supply */
    u32_t supply_type:2;        /* 11b - Augmented Power Data Object (APDO) */
#else
    u32_t supply_type:2;        /* 11b - Augmented Power Data Object (APDO) */
    u32_t pps:2;                /* Programmable Power Supply */
    u32_t resv3:3;              /* Reserved - shall be set to zero. */
    u32_t max_volt:8;           /* Maximum Voltage in 100mV increments */
    u32_t resv2:1;              /* Reserved - shall be set to zero. */
    u32_t min_volt:8;           /* Minimum Current in 100mV increments */
    u32_t resv1:1;              /* Reserved - shall be set to zero. */
    u32_t max_curr:7;           /* Maximum Voltage in 50mA increments */
#endif
} UPD_DATA_MSG_SINK_CAP_PPS_APDU_t;

typedef struct UPD_DATA_MSG_REQUEST_FIXED_VARIABLE_s
{
#if __LITTLE_ENDIAN__
    u32_t max_opr_curr:10;      /* Maximum Operating Current 10mA units */
    u32_t opr_curr:10;          /* Operating current in 10mA units */
    u32_t resv1:3;               /* Reserved - shall be set to zero. */
    u32_t unchunked:1;          /* Unchunked Extended Messages Supported */
    u32_t no_usb_susp:1;         /* No USB Suspend */
    u32_t usb_comm_cap:1;        /* USB Communications Capable */
    u32_t cap_mismatch:1;        /* Capability Mismatch */
    u32_t give_back_flag:1;      /* GiveBack flag */
    u32_t obj_pos:3;             /* Object position (000b is resv) */
    u32_t resv2:1;               /* Reserved - shall be set to zero. */
#else
    u32_t resv2:1;               /* Reserved - shall be set to zero. */
    u32_t obj_pos:3;             /* Object position (000b is resv) */
    u32_t give_back_flag:1;      /* GiveBack flag */
    u32_t cap_mismatch:1;        /* Capability Mismatch */
    u32_t usb_comm_cap:1;        /* USB Communications Capable */
    u32_t no_usb_susp:1;         /* No USB Suspend */
    u32_t unchunked:1;          /* Unchunked Extended Messages Supported */
    u32_t resv1:3;               /* Reserved - shall be set to zero. */
    u32_t opr_curr:10;          /* Operating current in 10mA units */
    u32_t max_opr_curr:10;      /* Maximum Operating Current 10mA units */
#endif
} UPD_DATA_MSG_REQUEST_FIXED_VARIABLE_t;

typedef struct UPD_DATA_MSG_REQUEST_BATTERY_s
{
#if __LITTLE_ENDIAN__
    u32_t max_opr_pwr:10;       /* Maximum Operating Power in 250mW units */
    u32_t opr_pwr:10;           /* Operating Power in 250mW units */
    u32_t resv1:3;               /* Reserved - shall be set to zero. */
    u32_t unchunked:1;          /* Unchunked Extended Messages Supported */
    u32_t no_usb_susp:1;         /* No USB Suspend */
    u32_t usb_comm_cap:1;        /* USB Communications Capable */
    u32_t cap_mismatch:1;        /* Capability Mismatch */
    u32_t give_back_flag:1;      /* GiveBack flag = 0 */
    u32_t obj_pos:3;             /* Object position (000b is resv) */
    u32_t resv2:1;               /* Reserved - shall be set to zero. */
#else
    u32_t resv2:1;               /* Reserved - shall be set to zero. */
    u32_t obj_pos:3;             /* Object position (000b is resv) */
    u32_t give_back_flag:1;      /* GiveBack flag */
    u32_t cap_mismatch:1;        /* Capability Mismatch */
    u32_t usb_comm_cap:1;        /* USB Communications Capable */
    u32_t no_usb_susp:1;         /* No USB Suspend */
    u32_t unchunked:1;          /* Unchunked Extended Messages Supported */
    u32_t resv1:3;               /* Reserved - shall be set to zero. */
    u32_t opr_pwr:10;          /* Operating Power in 250mW units */
    u32_t max_opr_pwr:10;      /* Maximum Operating Power in 250mW units */
#endif
} UPD_DATA_MSG_REQUEST_BATTERY_t;

typedef struct UPD_DATA_MSG_REQUEST_PPS_s
{
#if __LITTLE_ENDIAN__
    u32_t opr_curr:7;           /* Operating current in 50mA units */
    u32_t resv4:2;              /* Reserved - shall be set to zero. */
    u32_t output_volt:11;       /* Output voltage in 20mV units */
    u32_t resv1:3;              /* Reserved - shall be set to zero. */
    u32_t unchunked:1;          /* Unchunked Extended Messages Supported */
    u32_t no_usb_susp:1;        /* No USB Suspend */
    u32_t usb_comm_cap:1;       /* USB Communications Capable */
    u32_t cap_mismatch:1;       /* Capability Mismatch */
    u32_t resv3:1;              /* Reserved - shall be set to zero. */
    u32_t obj_pos:3;            /* Object position (000b is resv) */
    u32_t resv2:1;              /* Reserved - shall be set to zero. */
#else
    u32_t resv2:1;              /* Reserved - shall be set to zero. */
    u32_t obj_pos:3;            /* Object position (000b is resv) */
    u32_t resv3:1;              /* Reserved - shall be set to zero. */
    u32_t cap_mismatch:1;       /* Capability Mismatch */
    u32_t usb_comm_cap:1;       /* USB Communications Capable */
    u32_t no_usb_susp:1;        /* No USB Suspend */
    u32_t unchunked:1;          /* Unchunked Extended Messages Supported */
    u32_t resv1:3;              /* Reserved - shall be set to zero. */
    u32_t output_volt:11;       /* Output voltage in 20mV units */
    u32_t resv4:2;              /* Reserved - shall be set to zero. */
    u32_t opr_curr:7;           /* Operating current in 50mA units */
#endif
} UPD_DATA_MSG_REQUEST_PPS_t;

#define REQ_PPS_OUTPUT_VOLT_GET(obj)        ((u32_t)(((UPD_DATA_MSG_REQUEST_PPS_t *)(obj))->output_volt))
#define REQ_PPS_OPR_CURR_GET(obj)           ((u32_t)(((UPD_DATA_MSG_REQUEST_PPS_t *)(obj))->opr_curr))


typedef enum UPD_DATA_MSG_BIST_TYPE_e
{
    UPD_BIST_MSG_RECEIVER_MODE  = 0x00, /* Requests receiver to enter BIST Receiver Mode */
    UPD_BIST_MSG_TRANSMIT_MODE  = 0x01, /* Requests receiver to enter BIST Transmit Mode */
    UPD_BIST_MSG_RET_ERR_CNT    = 0x02, /* Returned error counters */
    UPD_BIST_MSG_CARRIER_MODE_0 = 0x03, /* Requests transmitter to enter BIST Carrier Mode 0 */
    UPD_BIST_MSG_CARRIER_MODE_1 = 0x04, /* Requests transmitter to enter BIST Carrier Mode 1 */
    UPD_BIST_MSG_CARRIER_MODE_2 = 0x05, /* Request Transmitter to enter BIST Carrier Mode 2 */
    UPD_BIST_MSG_CARRIER_MODE_3 = 0x06, /* Request Transmitter to enter BIST Carrier Mode 3 */
    UPD_BIST_MSG_EYE_PATTERN    = 0x07, /* Requests transmitter to enter BIST Eye Pattern. */
    UPD_BIST_MSG_TEST_DATA      = 0x08, /* Sends a Test Data Frame. */ 
    UPD_BIST_MSG_END
} UPD_DATA_MSG_BIST_TYPE_t;

typedef struct UPD_DATA_MSG_BIST_s
{
#if __LITTLE_ENDIAN__
    u32_t bist_err_cnt:16;     /* When Request Type is Returned BIST Counters; 
                                 * this field shall contain the contents of bist_err_cnt 
                                 * otherwise it shall be set to zero. */
    u32_t resv0:12;           /* All values not explicitly defined are resv and shall not be used. */
    u32_t type:4;            /* BIST Type */
#else
    u32_t type:4;            /* BIST Type */
    u32_t resv0:12;           /* All values not explicitly defined are resv and shall not be used. */
    u32_t bist_err_cnt:16;     /* When Request Type is Returned BIST Counters; 
                                 * this field shall contain the contents of bist_err_cnt 
                                 * otherwise it shall be set to zero. */
#endif
} UPD_DATA_MSG_BIST_t;

/* VMD header include support unstructured VMD header */
typedef struct UPD_DATA_MSG_VDM_HEADER_s
{
#if __LITTLE_ENDIAN__
    u32_t content:15;           /* Content of this field is defined by the vendor. */
    u32_t type:1;                /* VDM Type */
    u32_t svid:16;                 /* Unique 16-bit unsigned integer. 
                                 * Assigned by the USB-IF to the Vendor. */
#else
    u32_t svid:16;                 /* Unique 16-bit unsigned integer. 
                                 * Assigned by the USB-IF to the Vendor. */
    u32_t type:1;                /* VDM Type */
    u32_t content:15;           /* Content of this field is defined by the vendor. */
#endif
} UPD_DATA_MSG_VDM_HEADER_t;

typedef enum UPD_DATA_MSG_VDM_CMD_e
{
    UPD_VDM_MSG_CMD_RESERVED            = 0x00, 
    UPD_VDM_MSG_CMD_DISCOVER_IDENTITY   = 0x01,
    UPD_VDM_MSG_CMD_DISCOVER_SVID       = 0x02,
    UPD_VDM_MSG_CMD_DISCOVER_MODE       = 0x03,
    UPD_VDM_MSG_CMD_ENTER_MODE          = 0x04,
    UPD_VDM_MSG_CMD_EXIT_MODE           = 0x05,
    UPD_VDM_MSG_CMD_ATTENTION           = 0x06,
    UPD_VDM_MSG_CMD_SVID_SPECIFIC_CMD_START = 0x10,
    UPD_VDM_MSG_CMD_SVID_SPECIFIC_CMD2 = 0x11,
    UPD_VDM_MSG_CMD_END
} UPD_DATA_MSG_VDM_CMD_t;

typedef enum UPD_DATA_MSG_VDM_CMD_TYPE_e
{
    UPD_VDM_MSG_CMD_INITIATOR           = 0x00, 
    UPD_VDM_MSG_CMD_RESPONDER_ACK       = 0x01,
    UPD_VDM_MSG_CMD_RESPONDER_NAK       = 0x02,
    UPD_VDM_MSG_CMD_RESPONDER_BUSY      = 0x03
} UPD_DATA_MSG_VDM_CMD_TYPE_t;

typedef struct UPD_DATA_MSG_VDM_UNSTRUCTURED_s
{
    UPD_MSG_HEAD_t head;
    UPD_DATA_MSG_VDM_HEADER_t vdm_head;
    union {
        u8_t bytes[24];
        u32_t u32[6];
    } data_objs;
} UPD_DATA_MSG_VDM_UNSTRUCTURED_t;

typedef struct UPD_DATA_MSG_VDM_STRUCTURED_HEADER_s
{
#if __LITTLE_ENDIAN__
    u32_t command:5;                /* Command */
    u32_t resv1:1;                  /* Reserved */
    u32_t cmd_type:2;               /* Command Type */
    u32_t obj_pos:3;                /* Object position (000b is resv) */
    u32_t resv2:2;                  /* Reserved */
    u32_t version:2;                /* Structured VDM Version */
    u32_t type:1;                   /* VDM Type */
    u32_t svid:16;                  /* Unique 16-bit unsigned integer. 
                                     * Assigned by the USB-IF to the Vendor. */
#else
    u32_t svid:16;                  /* Unique 16-bit unsigned integer. 
                                     * Assigned by the USB-IF to the Vendor. */
    u32_t type:1;                   /* VDM Type */
    u32_t version:2;                /* Structured VDM Version */
    u32_t resv2:2;                  /* Reserved */
    u32_t obj_pos:3;                /* Object position (000b is resv) */
    u32_t cmd_type:2;               /* Command Type */
    u32_t resv1:1;                  /* Reserved */
    u32_t command:5;                /* Command */
#endif
} UPD_DATA_MSG_VDM_STRUCTURED_HEADER_t;

#define UPD_DATA_MSG_VDM_STRUCTURED_OBJ_POS_EXIT_ALL_MODES      (0x7)

typedef enum UPD_PRODUCT_TYPE_e
{
    UPD_PRODUCT_UNDEF = 0,
    UPD_PRODUCT_HUB = 1,
    UPD_PRODUCT_PERIPHERAL = 2,
    UPD_PRODUCT_PSD = 3,
    UPD_PRODUCT_RESV1 = 4,
    UPD_PRODUCT_AMA = 5,
    UPD_PRODUCT_VPD = 6,
    UPD_PRODUCT_END = 7
} UPD_PRODUCT_TYPE_t;

typedef enum UPD_CBL_PROD_TYPE_e
{
    UPD_CBL_PROD_UNDEF = 0,
    UPD_CBL_PROD_RESV1 = 1,
    UPD_CBL_PROD_RESV2 = 2,
    UPD_CBL_PROD_PASSIVE_CBL = 3,
    UPD_CBL_PROD_ACTIVE_CBL = 4,
    UPD_CBL_PROD_END
} UPD_CBL_PROD_TYPE_t;

typedef enum UPD_DFP_PROD_TYPE_e
{
    UPD_DFP_PROD_UNDEF = 0,
    UPD_DFP_PROD_HUB = 1,
    UPD_DFP_PROD_HOST = 2,
    UPD_DFP_PROD_PWR_BRICK = 3,
    UPD_DFP_PROD_AMC = 4,
    UPD_DFP_PROD_END
} UPD_DFP_PROD_TYPE_t;

typedef struct UPD_DATA_MSG_VDM_ID_HEADER_s
{
#if __LITTLE_ENDIAN__
    u32_t vid:16;                   /* 16-bit unsigned integer. USB Vendor ID. */
    u32_t resv1:7;                  /* Reserved */
    u32_t dfp_prod_type:3;          /* Product Type (DFP)  */
    u32_t modal_opr_supp:1;         /* Modal Operation Supported */
    u32_t prod_type:3;              /* Product Type (UFP or Cable plug) */
    u32_t usb_dev_data_cap:1;       /* Data Capable as a USB Device */
    u32_t usb_host_data_cap:1;      /* Data Capable as USB Host */
#else
    u32_t usb_host_data_cap:1;      /* Data Capable as USB Host */
    u32_t usb_dev_data_cap:1;       /* Data Capable as a USB Device */
    u32_t prod_type:3;              /* Product Type */
    u32_t modal_opr_supp:1;         /* Modal Operation Supported */
    u32_t dfp_prod_type:3;          /* Product Type (DFP)  */
    u32_t resv1:7;                  /* Reserved */
    u32_t vid:16;                   /* 16-bit unsigned integer. USB Vendor ID. */
#endif
} UPD_DATA_MSG_VDM_ID_HEADER_t;

typedef struct UPD_DATA_MSG_VDM_CERT_STAT_VDO_s
{
    u32_t tid;                  /* Test ID */
} UPD_DATA_MSG_VDM_CERT_STAT_VDO_t;

typedef struct UPD_DATA_MSG_VDM_PRODUCT_VDO_s
{
#if __LITTLE_ENDIAN__
    u32_t bcd_device:16;           /* bcd_device */
    u32_t prod_id:16;              /* USB Product ID */
#else
    u32_t prod_id:16;              /* USB Product ID */
    u32_t bcd_device:16;           /* bcd_device */
#endif
} UPD_DATA_MSG_VDM_PRODUCT_VDO_t;

typedef struct UPD_DATA_MSG_VDM_CABLE_VDO_s
{
#if __LITTLE_ENDIAN__
    u32_t usb_ss_sig_supp:3;    /* USB Superspeed Signaling Support */
    u32_t sop2_ctrler_pres:1;   /* SOP" controller present? */
    u32_t vbus_thr_cbl:1;       /* VBUS through cable, Active cable only */
    u32_t vbus_curr_cap:2;      /* VBUS Current Handling Capability */
    u32_t resv2:2;              /* Reserved - shall be set to zero. */
    u32_t max_vbus_volt:2;      /* Maximum Cable VBUS Voltage, 0-20V, 1-30V, 2-40V, 3-50V */
    u32_t cbl_term_type:2;                
    u32_t cbl_latency:4;        /* cable latency */
    u32_t resv1:1;              /* Reserved - shall be set to zero. */
    u32_t cbl_type:2;           /* 00b = Type-A
                                   01b = Type-B
                                   10b = Type-C
                                   11b = resv. */
    u32_t resv:1;               /* Reserved - shall be set to zero. */
    u32_t vdo_ver:3;            /* Version Number of the VDO, Version 1.0 = 000b, Values 001b~111b are Reserved and Shall Not be used */
    u32_t fw_ver:4;         /* Firmware version, 0000b..1111b assigned by the VID owner */
    u32_t hw_ver:4;         /* Hardware version, 0000b..1111b assigned by the VID owner */
#else
    u32_t hw_ver:4;         /* Hardware version, 0000b..1111b assigned by the VID owner */
    u32_t fw_ver:4;         /* Firmware version, 0000b..1111b assigned by the VID owner */
    u32_t vdo_ver:3;            /* Version Number of the VDO, Version 1.0 = 000b, Values 001b~111b are Reserved and Shall Not be used */
    u32_t resv:1;               /* Reserved - shall be set to zero. */
    u32_t cbl_type:2;           /* 00b = Type-A
                                   01b = Type-B
                                   10b = Type-C
                                   11b = resv. */
    u32_t resv1:1;              /* Reserved - shall be set to zero. */
    u32_t cbl_latency:4;        /* cable latency */
    u32_t cbl_term_type:2; 
    u32_t max_vbus_volt:2;      /* Maximum Cable VBUS Voltage, 0-20V, 1-30V, 2-40V, 3-50V */
    u32_t resv2:2;              /* Reserved - shall be set to zero. */
    u32_t vbus_curr_cap:2;      /* VBUS Current Handling Capability */
    u32_t vbus_thr_cbl:1;       /* VBUS through cable, Active cable only */
    u32_t sop2_ctrler_pres:1;   /* SOP" controller present? */
    u32_t usb_ss_sig_supp:3;    /* USB Superspeed Signaling Support */
#endif
} UPD_DATA_MSG_VDM_CABLE_VDO_t;    

typedef struct UPD_DATA_MSG_VDM_AMA_VDO_s
{
#if __LITTLE_ENDIAN__
    u32_t usb_ss_sig_supp:3;    /* USB Superspeed Signaling Support */
    u32_t vbus_req:1;           /* VBUS required */
    u32_t vcon_req:1;           /* VCONN required */
    u32_t vcon_pwr:3;           /* VCONN power needed by adapter for full functionality */
    u32_t resv:13;              /* Reserved - shall be set to zero. */
    u32_t vdo_ver:3;            /* Version Number of the VDO, Version 1.0 = 000b, Values 001b~111b are Reserved and Shall Not be used */
    u32_t fw_ver:4;         /* Firmware version, 0000b..1111b assigned by the VID owner */
    u32_t hw_ver:4;         /* Hardware version, 0000b..1111b assigned by the VID owner */
#else
    u32_t hw_ver:4;         /* Hardware version, 0000b..1111b assigned by the VID owner */
    u32_t fw_ver:4;         /* Firmware version, 0000b..1111b assigned by the VID owner */
    u32_t vdo_ver:3;            /* Version Number of the VDO, Version 1.0 = 000b, Values 001b~111b are Reserved and Shall Not be used */
    u32_t resv:13;              /* Reserved - shall be set to zero. */
    u32_t vcon_pwr:3;           /* VCONN power needed by adapter for full functionality */
    u32_t vcon_req:1;           /* VCONN required */
    u32_t vbus_req:1;           /* VBUS required */
    u32_t usb_ss_sig_supp:3;    /* USB Superspeed Signaling Support */
#endif
} UPD_DATA_MSG_VDM_AMA_VDO_t;    

typedef struct UPD_DATA_MSG_VDM_DP_CAPABILITIES_VDO_s
{
#if __LITTLE_ENDIAN__
    u32_t port_cap:2;                
    u32_t dp_ver:4;                  
    u32_t recp_indn:1;               
    u32_t usb2_not_use:1;            
    u32_t dfp_d_ass_supp:8;                  
    u32_t ufp_d_ass_supp:8;                
    u32_t resv:8;                   
#else
    u32_t resv:8;                  /* Reserved (always 0) */
    u32_t ufp_d_ass_supp:8;        /* 00000000 = UFP_D pinouts not supported 
                                    *xxxxxxx1 = Pinout A supported
                                    xxxxxx1x = Pinout B supported (1)
                                    xxxxx1xx = Pinout C supported
                                    xxxx1xxx = Pinout D supported (1)
                                    xxx1xxxx = Pinout E supported
                                    xx1xxxxx = Reserved
                                    x1xxxxxx = Reserved
                                    1xxxxxxx = Reserved */
    u32_t dfp_d_ass_supp:8;        /* 00000000 = DFP_D pinouts not supported 
                                    *xxxxxxx1 = Pinout A supported
                                    xxxxxx1x = Pinout B supported (1)
                                    xxxxx1xx = Pinout C supported
                                    xxxx1xxx = Pinout D supported (1)
                                    xxx1xxxx = Pinout E supported
                                    xx1xxxxx = Pinout F supported (1)
                                    x1xxxxxx = Reserved
                                    1xxxxxxx = Reserved */
    u32_t usb2_not_use:1;           /* USB 2.0 signaling may be / not required on A6/A7 or B6/B7 while configured to DisplayPort */
    u32_t recp_indn:1;              /* DisplayPort interface is presented on a USB Type-C plug/ receptacle(0/1)*/
    u32_t dp_ver:4;               /* xxx1 = dp1.3,xx1x usb gen2 x1xx,1xxx reserved */
    u32_t port_cap:2;             /* 00 resv, 01 = UFP_D ,10 = DFP_D ,11 = Both DFP_D and UFP_D*/
#endif
} UPD_DATA_MSG_VDM_DP_CAPABILITIES_VDO_t;

typedef struct UPD_DATA_MSG_VDM_DP_STA_VDO_s
{
#if __LITTLE_ENDIAN__
    u32_t ufp_dfp_connect:2;    
    u32_t power_low:1;           
    u32_t dp_en:1;           
    u32_t multi_func:1;           
    u32_t usb_cfg_req:1;             
    u32_t dp_exit:1;
    u32_t hpd_sta:1; 
    u32_t irq_hpd:1;                       
    u32_t resv:23;         
#else
    u32_t resv:23;              /* Reserved (always 0) */
    u32_t irq_hpd:1;            /* irq_hpd 1 and 0 */
    u32_t hpd_sta:1;            /* hpd 1 and 0 */
    u32_t dp_exit:1;            /* request exit from DisplayPort Mode  */
    u32_t usb_cfg_req:1;        /* request switch to USB configuration */
    u32_t multi_func:1;         /* Multi-Function preferred */
    u32_t dp_en:1;               /* Adapter DisplayPort functionality is enabled and operational */
    u32_t power_low:1;           /*  Adapter has detected low power and has disabled DisplayPort support */
    u32_t ufp_dfp_connect:2;     /* 00 =  no DFP_D UFP_D , 01 = DFP_D ,10 = UFP_D , 11 = Both DFP_D and UFP_D Connected */
#endif
} UPD_DATA_MSG_VDM_DP_STA_VDO_t; 

typedef struct UPD_DATA_MSG_VDM_DP_CONFIG_VDO_s
{
#if __LITTLE_ENDIAN__
    u32_t select_cfg:2;                
    u32_t dp_ver:4;                  
    u32_t resv1:2;               
    u32_t cfg_ufp_u_ass:8;                                             
    u32_t resv0:16;                   
#else
    u32_t resv0:16;                 /* Reserved (always 0) */
    u32_t cfg_ufp_u_ass:8;        /* 00000000 = Deselect DFP_D Assignment
                                    *00000001 = Select Assignment A
                                    00000010 = Select Assignment B
                                    00000100 = Select Assignment C
                                    00001000 = Select Assignment D
                                    00010000 = Select Assignment E
                                    00100000 = Select Assignment F
                                    All other values reserved */
    u32_t resv1:2;              /* Reserved (always 0) */
    u32_t dp_ver:4;             /* 0001 = dp1.3,0010 usb gen2 x1xx,1xxx reserved */
    u32_t select_cfg:2;         /* 00 resv, 01 = dFP_D ,10 = uFP_D ,11 = resv*/
#endif
} UPD_DATA_MSG_VDM_DP_CONFIG_VDO_t;

typedef struct UPD_DATA_MSG_VDM_DISCOVER_IDENTITY_s
{
    UPD_MSG_HEAD_t head;
    UPD_DATA_MSG_VDM_STRUCTURED_HEADER_t vdm_head;
    UPD_DATA_MSG_VDM_ID_HEADER_t vdm_id_head;
    UPD_DATA_MSG_VDM_CERT_STAT_VDO_t cert_stat_vdo;
    UPD_DATA_MSG_VDM_PRODUCT_VDO_t prod_vdo;
    u32_t prod_type_vdo[3];
} UPD_DATA_MSG_VDM_DISCOVER_IDENTITY_t;

typedef struct UPD_DATA_MSG_VDM_DISCOVER_SVID_VDO_s
{
#if __LITTLE_ENDIAN__
    u32_t sVIDn1:16;               /* svid n + 1 */
    u32_t sVIDn:16;                /* svid n */
#else
    u32_t sVIDn:16;                /* svid n */
    u32_t sVIDn1:16;               /* svid n + 1 */
#endif
} UPD_DATA_MSG_VDM_DISCOVER_SVID_VDO_t;

typedef struct UPD_DATA_MSG_VDM_DISCOVER_SVID_s
{
    UPD_MSG_HEAD_t head;
    UPD_DATA_MSG_VDM_STRUCTURED_HEADER_t vdm_head;
    UPD_DATA_MSG_VDM_DISCOVER_SVID_VDO_t svid_vdo[6];
} UPD_DATA_MSG_VDM_DISCOVER_SVID_t;

typedef struct UPD_DATA_MSG_VDM_SPECIFIC_s
{
    UPD_MSG_HEAD_t head;
    UPD_DATA_MSG_VDM_STRUCTURED_HEADER_t vdm_head;
    u32_t val;
} UPD_DATA_MSG_VDM_SPECIFIC_t;


typedef struct UPD_DATA_MSG_VDM_DISCOVER_MODE_VDO_s
{
    u32_t mode_obj;            /* Mode Object */
} UPD_DATA_MSG_VDM_DISCOVER_MODE_VDO_t;

typedef struct UPD_DATA_MSG_VDM_DISCOVER_MODE_s
{
    UPD_MSG_HEAD_t head;
    UPD_DATA_MSG_VDM_STRUCTURED_HEADER_t vdm_head;
    UPD_DATA_MSG_VDM_DISCOVER_MODE_VDO_t mode_vdo[6];
} UPD_DATA_MSG_VDM_DISCOVER_MODE_t;

typedef struct UPD_DATA_MSG_VDM_ENTER_MODE_s
{
    UPD_MSG_HEAD_t head;
    UPD_DATA_MSG_VDM_STRUCTURED_HEADER_t vdm_head;
} UPD_DATA_MSG_VDM_ENTER_MODE_t;

typedef struct UPD_DATA_MSG_VDM_EXIT_MODE_s
{
    UPD_MSG_HEAD_t head;
    UPD_DATA_MSG_VDM_STRUCTURED_HEADER_t vdm_head;
} UPD_DATA_MSG_VDM_EXIT_MODE_t;

typedef struct UPD_DATA_MSG_VDM_ATTENTION_s
{
    UPD_MSG_HEAD_t head;
    UPD_DATA_MSG_VDM_STRUCTURED_HEADER_t vdm_head;
    u32_t val;
} UPD_DATA_MSG_VDM_ATTENTION_t;

typedef struct UPD_DATA_MSG_BATTERY_STATUS_s
{
#if __LITTLE_ENDIAN__
    u32_t resv:8;               /* Reserved - shall be set to zero. */
    u32_t info:8;               /* Battery Info 
                                    Bit Description
                                    0   Invalid Battery reference
                                    1   Battery is present when set
                                    3~2 When Battery is present Shall contain the
                                        Battery charging status:
                                        00b: Battery is Charging
                                        01b: Battery is Discharging
                                        10b: Battery is Idle
                                        11b: Reserved, Shall Not be used
                                        When Battery is not present:
                                        11b~00b: Reserved, Shall Not be used
                                    7~4 Reserved and Shall be set to zero
                                 */
    u32_t present_capacity:16;  /* Battery's State of Charge (SoC), 0xFFFF = Battery's SOC unknown  */
#else
    u32_t present_capacity:16;  /* Battery's State of Charge (SoC), 0xFFFF = Battery's SOC unknown  */
    u32_t info:8;               /* Battery Info 
                                    Bit Description
                                    0   Invalid Battery reference
                                    1   Battery is present when set
                                    3:2 When Battery is present Shall contain the
                                        Battery charging status:
                                        00b: Battery is Charging
                                        01b: Battery is Discharging
                                        10b: Battery is Idle
                                        11b: Reserved, Shall Not be used
                                        When Battery is not present:
                                        11b~00b: Reserved, Shall Not be used
                                    7:4 Reserved and Shall be set to zero
                                 */
    u32_t resv:8;               /* Reserved - shall be set to zero. */
#endif
} UPD_DATA_MSG_BATTERY_STATUS_t;    


typedef enum UPD_ALERT_TYPE_e
{
    UPD_ALERT_TYPE_RSVD1        = 0x01,
    UPD_ALERT_TYPE_BAT_STA_CHG  = 0x02,
    UPD_ALERT_TYPE_OCP          = 0x04,
    UPD_ALERT_TYPE_OTP          = 0x08,
    UPD_ALERT_TYPE_OPR_COND_CHG = 0x10,
    UPD_ALERT_TYPE_SRC_INPT_CHG = 0x20,
    UPD_ALERT_TYPE_OVP          = 0x40,
    UPD_ALERT_TYPE_RSVD2        = 0x80
} UPD_ALERT_TYPE_t;

typedef struct UPD_DATA_MSG_ALERT_s
{
#if __LITTLE_ENDIAN__
    u32_t resv:16;               /* Reserved - shall be set to zero. */
    u32_t hot_swappable_batteries:4;    /* Hot Swappable Batteries, 
                                         * When Battery Status Change 
                                         * bit set indicates which Hot Swappable 
                                         * Batteries have had a status change. 
                                         * B16 corresponds to Battery 4 and 
                                         * B19 corresponds to Battery 7. */
    u32_t fixed_batteries:4;   /* Fixed Batteries, When Battery Status Change 
                                * bit set indicates which Fixed Batteries have 
                                * had a status change. B20 corresponds to 
                                * Battery 0 and B23 corresponds to Battery 3. */
    u32_t type:8;              /* Type of Alert  */
#else
    u32_t type:8;              /* Type of Alert 
                                    Bit Description
                                    0   Reserved and Shall be set to zero
                                    1   Battery Status Change
                                        Event(Attach/Detach/charging/discharging/idle)
                                    2   OCP event when set (Source only, for Sink
                                        Reserved and Shall be set to zero)
                                    3   OTP event when set
                                    4   Operating Condition Change when set
                                    5   Source Input Change Event when set
                                    6   OVP event when set (Sink only, for Source
                                        Reserved and Shall be set to zero)
                                    7   Reserved and Shall be set to zero
                                */

    u32_t fixed_batteries:4;   /* Fixed Batteries, When Battery Status Change 
                                * bit set indicates which Fixed Batteries have 
                                * had a status change. B20 corresponds to 
                                * Battery 0 and B23 corresponds to Battery 3. */
    u32_t hot_swappable_batteries:4;    /* Hot Swappable Batteries, 
                                         * When Battery Status Change 
                                         * bit set indicates which Hot Swappable 
                                         * Batteries have had a status change. 
                                         * B16 corresponds to Battery 4 and 
                                         * B19 corresponds to Battery 7. */
    u32_t resv:16;               /* Reserved - shall be set to zero. */
#endif
} UPD_DATA_MSG_ALERT_t;    


typedef struct UPD_DATA_MSG_GET_COUNTRY_INFO_s
{
#if __LITTLE_ENDIAN__
    u32_t resv:16;               /* Reserved - shall be set to zero. */
    u32_t alpha_2_code_2:8;     /* Second character of the Alpha-2 Country
                                 * Code defined by [ISO 3166]  
                                 */
    u32_t alpha_2_code_1:8;     /* First character of the Alpha-2 Country
                                 * Code defined by [ISO 3166]  
                                 */
#else
    u32_t alpha_2_code_1:8;     /* First character of the Alpha-2 Country
                                 * Code defined by [ISO 3166]  
                                 */
    u32_t alpha_2_code_2:8;     /* Second character of the Alpha-2 Country
                                 * Code defined by [ISO 3166]  
                                 */
    u32_t resv:16;               /* Reserved - shall be set to zero. */
#endif
} UPD_DATA_MSG_GET_COUNTRY_INFO_t;    



/** Extended message defintion below */

typedef enum UPD_EXT_MSG_e
{
    UPD_EXT_MSG_RESV            = 0x00, /* All values not explicitly defined
                                         * are Reserved and Shall Not be used. 
                                         */
    UPD_EXT_MSG_SRC_CAP         = 0x01, /* Send by Source; DRP */
    UPD_EXT_MSG_STATUS          = 0x02, /* Send by Source only */
    UPD_EXT_MSG_GET_BAT_CAP     = 0x03, /* Send by Source; Sink or Cable Plug */
    UPD_EXT_MSG_GET_BAT_STATUS  = 0x04, /* Send by Source or Sink */
    UPD_EXT_MSG_BAT_CAP         = 0x05, /* Send by Source only */
    UPD_EXT_MSG_GET_MFR_INFO    = 0x06, /* Send by Source or Sink */
    UPD_EXT_MSG_MFR_INFO        = 0x07, /* Send by Sink or DRP */
    UPD_EXT_MSG_SECUR_REQ       = 0x08, /* Send by Source or DRP */ 
    UPD_EXT_MSG_SECUR_RESP      = 0x09, /* Send by Source or Sink */ 
    UPD_EXT_MSG_FW_UP_REQ       = 0x0A, /* Send by Source or Sink */ 
    UPD_EXT_MSG_FW_UP_RESP      = 0x0B, /* Send by Source or Sink */ 
    UPD_EXT_MSG_PPS_STATUS      = 0x0C, /* Send by Source or Sink */ 
    UPD_EXT_MSG_COUNTRY_INFO    = 0x0D, /* Send by Source or Sink */  
    UPD_EXT_MSG_COUNTRY_CODES   = 0x0E, /* Send by Source or Sink */  
    UPD_EXT_MSG_SNK_CAP         = 0x0F, /* Send by Sink; DRP */
    UPD_EXT_MSG_END
} UPD_EXT_MSG_t;


typedef struct UPD_EXT_MSG_SRC_CAP_s
{
    u16_t vid;              /* Vendor ID (assigned by the USB-IF)   */
    u16_t pid;              /* Product ID (assigned by the manufacturer) */
    u32_t xid;              /* Value provided by the USB-IF assigned to the product */
    u8_t fw_ver;            /* Firmware version number */
    u8_t hw_ver;            /* Hardware version number */
    u8_t volt_regulation;   /* Voltage Regulation
                                Bit Description
                                1~0 00b: 150mA/us Load Step (default)
                                    01b: 500mA/us Load Step
                                    11b~10b:    Reserved and Shall Not be used
                                2   0b: 25% IoC (default)
                                    1b: 90% IoC
                                3~7 Reserved and Shall be set to zero
                             */
    u8_t holdup_time;       /* Holdup Time
                             * Output will stay with regulated limits for this number of
                             * milliseconds after removal of the AC from the input.
                             * 0x00 = feature not supported
                             * Note: a value of 3ms Should be used
                             */
    u8_t compliance;        /*  Bit Description
                                0   LPS compliant when set
                                1   PS1 compliant when set
                                2   PS2 compliant when set
                                3~7 Reserved and Shall be set to zero
                                */
    u8_t touch_current;     /*  Bit Description
                                0   Low touch Current EPS when set
                                1   Ground pin supported when set
                                2   Ground pin intended for protective earth when set
                                3~7 Reserved and Shall be set to zero
                                */
    u16_t peak_current1;    /*  Bit     Description
                                0~4     Percent overload in 10% increments, Values higher than 25 (11001b) are clipped to 250%.
                                5~10    Overload period in 20ms
                                11~14   Duty cycle in 5% increments
                                15      VBUS Voltage droop
                             */
    u16_t peak_current2;    /*  Bit     Description
                                0~4     Percent overload in 10% increments, Values higher than 25 (11001b) are clipped to 250%.
                                5~10    Overload period in 20ms
                                11~14   Duty cycle in 5% increments
                                15      VBUS Voltage droop
                             */
    u16_t peak_current3;    /*  Bit     Description
                                0~4     Percent overload in 10% increments, Values higher than 25 (11001b) are clipped to 250%.
                                5~10    Overload period in 20ms
                                11~14   Duty cycle in 5% increments
                                15      VBUS Voltage droop
                             */
    u8_t touch_temp;        /* Temperature conforms to:
                                0 = [IEC 60950-1] (default)
                                1 = [IEC 62368-1] TS1
                                2 = [IEC 62368-1] TS2
                                Note: All other values Reserved */
    u8_t src_inputs;        /*  Bit Description
                                0   0b: No external supply
                                    1b: External supply present
                                1   If bit 0 is set:
                                    0b: External supply is constrained
                                    1b: External supply is unconstrained
                                    If bit 0 is not set Reserved and Shall be set to zero
                                2   0b: No internal Battery
                                    1b: Internal Battery present
                                3~7 Reserved and Shall be set to zero */
    u8_t batteries;         /*  Upper Nibble = Number of Hot Swappable Batteries (0~4)
                                Lower Nibble = Number of Fixed Batteries (0~4) */
    u8_t src_pdp;           /*  0~6: Source's rated PDP
                                7: Reserved and Shall be set to zero */
} UPD_EXT_MSG_SRC_CAP_t;


typedef struct UPD_EXT_MSG_STATUS_s
{
    u8_t internal_temp;     /* Source or Sink's internal temperature in degrees centigrade.
                                0 = feature not supported
                                1 = temperature is less than 2¡ãC.
                                2-255 = temperature in ¡ãC. */
    u8_t present_input;     /*  Bit Description
                                0   Reserved and Shall be set to zero
                                1   External Power when set
                                2   External Power AC/DC (Valid when Bit 1 set)
                                    0: DC
                                    1: AC
                                    Reserved when Bit 1 is zero
                                3   Internal Power from Battery when set
                                4   Internal Power from non-Battery power source when set
                                5~7 Reserved and Shall be set to zero */
    u8_t present_bat_input; /* When Present Input field bit 3 set Shall contain the bit corresponding to the Battery or Batteries providing power:
                                Upper nibble = Hot Swappable Battery (b7~4)
                                Lower nibble = Fixed Battery (b3~0)
                                When Present Source Input field bit 3 is not set this field is Reserved and Shall be set to zero. */
    u8_t event_flags;       /*  Bit Description
                                0   Reserved and Shall be set to zero
                                1   OCP event when set
                                2   OTP event when set
                                3   OVP event when set (Sink only, for Source Reserved and Shall be set to zero)
                                4   CF mode when set, CV mode when cleared
                                5~7 Reserved and Shall be set to zero */
    u8_t temp_status;       /*  Bit Description
                                0   Reserved and Shall be set to zero
                                1~2 00 - Not Supported
                                    01 - Normal
                                    10 - Warning
                                    11 - Over temperature
                                3~7 Reserved and Shall be set to zero */
    u8_t power_status;      /*  Bit Description
                                0   Reserved and Shall be set to zero
                                1   Source power limited due to cable supported current
                                2   Source power limited due to insufficient power available while sourcing other ports
                                3   Source power limited due to insufficient external power
                                4   Source power limited due to Event Flags in place (Event Flags must also be set)
                                5   Source power limited due to temperature
                                6~7 Reserved and Shall be set to zero */
} UPD_EXT_MSG_STATUS_t;


typedef struct UPD_EXT_MSG_STATUS_SOP12_s
{
    u8_t internal_temp;     /* Source or Sink's internal temperature in degrees centigrade.
                                0 = feature not supported
                                1 = temperature is less than 2¡ãC.
                                2-255 = temperature in ¡ãC. */
    u8_t flags;             /*  Bit Description
                                0   Thermal Shutdown
                                1~7 Reserved and Shall be set to zero */
} UPD_EXT_MSG_STATUS_SOP12_t;


typedef struct UPD_EXT_MSG_GET_BAT_CAP_s
{
    u8_t bat_cap_ref;       /* Number of the Battery indexed from zero:
                                 - Values 0~3 represent the Fixed Batteries.
                                 - Values 4~7 represent the Hot Swappable Batteries.
                                 - Values 8~255 are Reserved and Shall Not be used. */
} UPD_EXT_MSG_GET_BAT_CAP_t;


typedef struct UPD_EXT_MSG_GET_BAT_STATUS_s
{
    u8_t bat_status_ref;    /* Number of the Battery indexed from zero:
                                 - Values 0~3 represent the Fixed Batteries.
                                 - Values 4~7 represent the Hot Swappable Batteries.
                                 - Values 8~255 are Reserved and Shall Not be used. */
} UPD_EXT_MSG_GET_BAT_STATUS_t;


typedef struct UPD_EXT_MSG_BAT_CAP_s
{
    u16_t vid;                      /* Vendor ID (assigned by the USB-IF)   */
    u16_t pid;                      /* Product ID (assigned by the manufacturer) */
    u16_t design_capacity;          /* Battery's design capacity, 0x0000 = Battery not present
                                        0xFFFF = design capacity unknown */
    u16_t last_full_charge_capacity;/* Battery's last full capacity, 0x0000 = Battery not present
                                        0xFFFF = last full charge capacity unknown */
    u8_t type;
} UPD_EXT_MSG_BAT_CAP_t;


typedef struct UPD_EXT_MSG_GET_MFR_INFO_s
{
    u8_t mfr_info_target;   /*  0: Port/Cable Plug
                                1: Battery
                                255~2: Reserved Shall Not be used. */
    u8_t mfr_info_ref;      /*  If Manufacturer Info Target subfield is Battery (01b) the
                                Manufacturer Info Ref field Shall contain the Battery number
                                reference which is the number of the Battery indexed from zero:
                                - Values 0~3 represent the Fixed Batteries.
                                - Values 4~7 represent the Hot Swappable Batteries.
                                Otherwise this field is Reserved and Shall be set to zero. */
} UPD_EXT_MSG_GET_MFR_INFO_t;

#define UPD_EXT_MSG_MFR_MAX_STRING_LEN      (22)

typedef struct UPD_EXT_MSG_MFR_INFO_s
{
    u16_t vid;              /* Vendor ID (assigned by the USB-IF)   */
    u16_t pid;              /* Product ID (assigned by the manufacturer) */
    u8_t mfr_str[UPD_EXT_MSG_MFR_MAX_STRING_LEN];
                            /* Vendor defined byte array
                            If the Manufacturer Info Target field or Manufacturer Info Ref
                            field in the Get_Manufacturer_Info Message is unrecognized
                            return zero bytes. */
} UPD_EXT_MSG_MFR_INFO_t;

/* TODO: Security Request */
typedef struct UPD_EXT_MSG_SECURITY_REQ_s
{
    u8_t ProtocolVersion;
    u8_t MessageType;
    u8_t Param1;
    u8_t Param2;
} UPD_EXT_MSG_SECURITY_REQ_t;

/* TODO: Security Response */
typedef struct UPD_EXT_MSG_SECURITY_RESP_s
{
    u8_t ProtocolVersion;
    u8_t MessageType;
    u8_t Param1;
    u8_t Param2;
} UPD_EXT_MSG_SECURITY_RESP_t;

/* TODO: Firmware Update Request */
/* TODO: Firmware Update Response */


typedef struct UPD_EXT_MSG_PPS_STATUS_s
{
    u16_t output_volt;      /* Source's output voltage in 20mV units.
                                When set to 0xFFFF, the Source does not support this field. */
    u16_t output_current;   /* Source's output current in 50mA units.
                               When set to 0xFF, the Source does not support this field. */
    u8_t real_time_flags;   /*  Bit Description
                                0   Reserved and Shall be set to zero
                                1~2 PTF: 00 ¨C Not Supported
                                    PTF: 01 ¨C Normal
                                    PTF: 10 ¨C Warning
                                    PTF: 11 ¨C Over temperature
                                3   OMF set when operating in Current Limit mode, and cleared when operating in Constant Voltage mode.
                                4~7 Reserved and Shall be set to zero */
} UPD_EXT_MSG_PPS_STATUS_t;


#define ALPHA_2_COUNTRY_CODE_LEN    (2)
#define ALPHA_2_COUNTRY_CODES_COUNT (128)

typedef struct UPD_EXT_MSG_COUNTRY_CODE_s 
{
    u8_t alpha_2_code[ALPHA_2_COUNTRY_CODE_LEN];     /* The Alpha-2 Country Code defined by [ISO 3166]  */
} UPD_EXT_MSG_COUNTRY_CODE_t;

#define COUNTRY_SPECIFIC_DATA_LEN (256)

typedef struct UPD_EXT_MSG_COUNTRY_INFO_s
{
    UPD_EXT_MSG_COUNTRY_CODE_t country_code;  /* The Alpha-2 Country Code defined by [ISO 3166] */
    u16_t reserved;
    u8_t country_specific_data[COUNTRY_SPECIFIC_DATA_LEN]; /* 0~256 bytes of content defined by the country's authority. */
} UPD_EXT_MSG_COUNTRY_INFO_t;

typedef struct UPD_EXT_MSG_COUNTRY_CODES_s
{
    u16_t length;      /* Number of country codes in the message */
    UPD_EXT_MSG_COUNTRY_CODE_t country_codes[ALPHA_2_COUNTRY_CODES_COUNT];  /* The Alpha-2 Country Code defined by [ISO 3166] */
} UPD_EXT_MSG_COUNTRY_CODES_t;



typedef struct UPD_EXT_MSG_SNK_CAP_s
{
    u16_t vid;              /* Vendor ID (assigned by the USB-IF)   */
    u16_t pid;              /* Product ID (assigned by the manufacturer) */
    u32_t xid;              /* Value provided by the USB-IF assigned to the product */
    u8_t fw_ver;            /* Firmware version number */
    u8_t hw_ver;            /* Hardware version number */
    u8_t skedb_ver;         /* SKEDB Version */
    u8_t load_step;         /* Load Step
                                Bit Description
                                1~0 00b: 150mA/us Load Step (default)
                                    01b: 500mA/us Load Step
                                    11b~10b: Reserved and Shall Not be used
                                2~7 Reserved and Shall be set to zero
                             */
    u16_t load_characteristics; /*  Bit     Description
                                    0~4     Percent overload in 10% increments
                                            Values higher than 25 (11001b) are clipped to 250%. 00000b is the default.
                                    5~10    Overload period in 20ms when bits 0~4 non-zero.
                                    11~14   Duty cycle in 5% increments when bits 0-4 are non-zero
                                    15      Can tolerate VBUS Voltage droopd
                                 */
    u8_t compliance;        /*  Bit Description
                                0   Requires LPS source when set
                                1   Requires PS1 source when set
                                2   Requires PS2 source when set
                                3~7 Reserved and Shall be set to zero
                                */
    u8_t touch_temp;        /* Temperature conforms to:
                                0 = Not applicable
                                1 = [IEC 60950-1] (default)
                                2 = [IEC 62368-1] TS1
                                3 = [IEC 62368-1] TS2
                                Note: All other values Reserved */
    u8_t battery_info;      /*  Upper Nibble = Number of Hot Swappable Batteries (0~4)
                                Lower Nibble = Number of Fixed Batteries (0~4) */
    u8_t modes;             /*  Bit Description
                                0   1: PPS charging supported
                                1   1: VBUS powered
                                2   1: Mains powered
                                3   1: Battery powered
                                4   1: Battery essentially unlimited
                                5~7 Reserved and Shall be set to zero
                                */
    u8_t minimum_pdp;       /*  Bit     Description
                                0~6     The Minimum PDP required by the Sink to operate without consuming any power from its Battery(s) should it have one.
                                7       Reserved and Shall be set to zero
                             */
    u8_t operational_pdp;   /*  Bit     Description
                                0~6     The PDP the Sink requires to operate normally. For Sinks with a Battery, it is the PDP Rating of the charger supplied with it or recommended for it.
                                7       Reserved and Shall be set to zero
                             */
    u8_t maximum_pdp;       /*  Bit     Description
                                0~6     The Maximum PDP the Sink can consume to operate and charge its Battery(s) should it have one.
                                7       Reserved and Shall be set to zero
                             */
} UPD_EXT_MSG_SNK_CAP_t;




#pragma pack()

#endif /* #ifndef __PRL_MSG_DEFS_H_ */

