/*****************************************************************
 *****************************************************************
 ***                                                            **
 ***    (C)Copyright 2005-2006, American Megatrends Inc.        **
 ***                                                            **
 ***            All Rights Reserved.                            **
 ***                                                            **
 ***        6145-F, Northbelt Parkway, Norcross,                **
 ***                                                            **
 ***        Georgia - 30071, USA. Phone-(770)-246-8600.         **
 ***                                                            **
 *****************************************************************
 *****************************************************************
 *****************************************************************
 ******************************************************************
 *
 * SDRRecord.h
 * SDR record structures.
 *
 *  Author: Govind Kothandapani <govindk@ami.com>
 *
 ******************************************************************/
#ifndef IPMI_SDR_RECORD_H
#define IPMI_SDR_RECORD_H

#include "com_IPMIDefs.h"

#ifndef uint8_t
  #define uint8_t unsigned char
#endif
#ifndef uint16_t
  #define uint16_t unsigned short
#endif
#ifndef uint32_t
  #define uint32_t unsigned long
#endif

#ifndef int8_t
  #define int8_t signed char
#endif
#ifndef int16_t
  #define int16_t signed short
#endif
#ifndef int32_t
  #define int32_t signed long
#endif

#pragma pack( 1 )

/**
 * @brief SDR Type
**/
#define FULL_SDR_REC                    0x01
#define COMPACT_SDR_REC                 0x02
#define EVENT_ONLY_SDR_REC              0x03
#define ENTITY_ASSOCIATION_SDR_REC      0x08
#define DEV_REL_ENTITY_ASSOCIATION_SDR_REC 0x09
#define GENERIC_DEVICE_LOCATOR_SDR_REC  0x10
#define FRU_DEVICE_LOCATOR_SDR_REC      0x11
#define MGMT_CTRL_DEV_LOCATOR_SDR_REC   0x12
#define MGMT_CTRL_CONFIRMATION_SDR_REC  0x13
#define BMC_MSG_CHANNEL_INFO_REC        0x14  
#define OEM_SDRFRU_REC                  0xD0
#define OEM_SDRNM_REC                   0xC0

/**
 * @struct SDRRecHdr_T
 * @brief SDR Record Header
**/
typedef struct
{
    uint16_t  ID;
    uint8_t   Version;
    uint8_t   Type;
    uint8_t   Len;

} SDRRecHdr_T;


/**
 * @struct FullSensorRec_T
 * @brief Full Sensor Record
**/
typedef struct
{
    /* SENSOR RECORD HEADER */
    SDRRecHdr_T     hdr;

    /* RECORD KEY BYTES */
    uint8_t           OwnerID;
    uint8_t           OwnerLUN;
    uint8_t           SensorNum;

    /* RECORD BODY BYTES */
    uint8_t           EntityID;
    uint8_t           EntityIns;
    uint8_t           SensorInit;
    uint8_t           SensorCaps;
    uint8_t           SensorType;
    uint8_t           EventTypeCode;
    uint16_t          AssertionEventMask;
    uint16_t          DeAssertionEventMask;
    uint16_t          DiscreteReadingMask;
    uint8_t           Units1;
    uint8_t           Units2;
    uint8_t           Units3;
    uint8_t           Linearization;
    uint8_t           M;
    uint8_t           M_Tolerance;
    uint8_t           B;
    uint8_t           B_Accuracy;
    uint8_t           Accuracy;
    uint8_t           R_B_Exp;
    uint8_t           Flags;
    uint8_t           NominalReading;
    uint8_t           NormalMax;
    uint8_t           NormalMin;
    uint8_t           MaxReading;
    uint8_t           MinReading;
    uint8_t           UpperNonRecoverable;
    uint8_t           UpperCritical;
    uint8_t           UpperNonCritical;
    uint8_t           LowerNonRecoverable;
    uint8_t           LowerCritical;
    uint8_t           LowerNonCritical;
    uint8_t           PositiveHysterisis;
    uint8_t           NegativeHysterisis;
    uint8_t           Reserved1;
    uint8_t           Reserved2;
    uint8_t           OEMField;
    uint8_t           IDStrTypeLen;
    int8_t           IDStr [MAX_ID_STR_LEN];

}    FullSensorRec_T;

/**
 * @struct CompactSensorRec_T
 * @brief Compact Sensor Record
**/
typedef struct
{
    /* SENSOR RECORD HEADER */
    SDRRecHdr_T     hdr;

    /* RECORD KEY BYTES */
    uint8_t           OwnerID;
    uint8_t           OwnerLUN;
    uint8_t           SensorNum;

    /* RECORD BODY BYTES */
    uint8_t           EntityID;
    uint8_t           EntityIns;
    uint8_t           SensorInit;
    uint8_t           SensorCaps;
    uint8_t           SensorType;
    uint8_t           EventTypeCode;
    uint16_t          AssertionEventMask;
    uint16_t          DeAssertionEventMask;
    uint16_t          DiscreteReadingMask;
    uint8_t           Units1;
    uint8_t           Units2;
    uint8_t           Units3;
    uint16_t          RecordSharing;
    uint8_t           PositiveHysteris;
    uint8_t           NegativeHysterisis;
    uint8_t           Reserved1;
    uint8_t           Reserved2;
    uint8_t           Reserved3;
    uint8_t           OEMField;
    uint8_t           IDStrTypeLen;
    int8_t           IDStr [MAX_ID_STR_LEN];

}    CompactSensorRec_T;

/**
 * @struct
 * @brief Common structure for both Full and Compact sensor Record.
 */
typedef struct
{
    /* SENSOR RECORD HEADER */
    SDRRecHdr_T     hdr;

    /* RECORD KEY BYTES */
    uint8_t           OwnerID;
    uint8_t           OwnerLUN;
    uint8_t           SensorNum;

    /* RECORD BODY BYTES */
    uint8_t           EntityID;
    uint8_t           EntityIns;
    uint8_t           SensorInit;
    uint8_t           SensorCaps;
    uint8_t           SensorType;
    uint8_t           EventTypeCode;
    uint16_t          AssertionEventMask;
    uint16_t          DeAssertionEventMask;
    uint16_t          DiscreteReadingMask;
    uint8_t           Units1;
    uint8_t           Units2;
    uint8_t           Units3;
}   CommonSensorRec_T;

/**
 * @struct EvtOnlySensorRec_T
 * @brief Event only Sensor Record
**/
typedef struct
{
    /* SENSOR RECORD HEADER */
    SDRRecHdr_T     hdr;

    /* RECORD KEY BYTES */
    uint8_t           OwnerID;
    uint8_t           OwnerLUN;
    uint8_t           SensorNum;

    /* RECORD BODY BYTES */
    uint8_t           EntityID;
    uint8_t           EntityIns;
    uint8_t           SensorType;
    uint8_t           EventTypeCode;
    uint16_t          RecordSharing;
    uint8_t           Reserved1;
    uint8_t           OEMField;
    uint8_t           IDStrTypeLen;
    char            IDStr [MAX_ID_STR_LEN];
}    EvtOnlySensorRec_T;

/**
 * @struct MgmtCtrlrConfirmRec_T
 * @brief Management Controller Confirmation Record
**/
typedef struct
{
    /* SENSOR RECORD HEADER */
    SDRRecHdr_T     hdr;

    /* RECORD KEY BYTES */
    uint8_t           DevSlaveAddr;
    uint8_t           DevID;
    uint8_t           ChannelNum;

    /* RECORD BODY BYTES */
    uint8_t           FirmwareRev1;
    uint8_t           FirmwareRev2;
    uint8_t           IPMIVer;
    uint8_t           MftrID [3];
    uint8_t           ProdID [2];
    uint8_t           DevGUID [MAX_ID_STR_LEN];

}    MgmtCtrlrConfirmRec_T;


/**
 * @struct MgmtCtrlrDevLocator_T
 * @brief Management Controller Device Locator Record
**/
typedef struct
{
    /* SENSOR RECORD HEADER */
    SDRRecHdr_T     hdr;

    /* RECORD KEY BYTES */
    uint8_t           DevSlaveAddr;
    uint8_t           ChannelNum;

    /* RECORD BODY BYTES */
    uint8_t           PowerStateNotification;
    uint8_t           DeviceCaps;
    uint8_t           reserved [3];
    uint8_t           EntityID;
    uint8_t           EntityIns;
    uint8_t           OEMField;
    uint8_t           IDStrLen;
    int8_t           DevIdStr [MAX_ID_STR_LEN];

}    MgmtCtrlrDevLocator_T;


/**
 * @struct GnrcDevLocatorRec_T
 * @brief Generic Device Locator Record
**/
typedef struct
{
    /* SENSOR RECORD HEADER */
    SDRRecHdr_T     hdr;

    /* RECORD KEY BYTES */
    uint8_t           DevAccessAddr;
    uint8_t           DevSlaveAddr;
    uint8_t           LUNBusID;

    /* RECORD BODY BYTES */
    uint8_t           AddrSpan;
    uint8_t           Reserved;
    uint8_t           DevType;
    uint8_t           DevTypeModifier;
    uint8_t           EntityID;
    uint8_t           EntityIns;
    uint8_t           OEMField;
    uint8_t           IDStrLen;
    int8_t           DevIdStr [MAX_ID_STR_LEN];

}    GnrcDevLocatorRec_T;

/**
 * @struct FRUcDevLocatorRec_T
 * @brief FRU Device Locator Record
**/
typedef struct
{
    /* SENSOR RECORD HEADER */
    SDRRecHdr_T     hdr;

    /* RECORD KEY BYTES */
    uint8_t           DevAccessAddr;
    uint8_t           FRUIDSlaveAddr;
    uint8_t           AccessLUNBusID;
    uint8_t           ChannelNumber;

    /* RECORD BODY BYTES */
    uint8_t           Reserved;
    uint8_t           DevType;
    uint8_t           DevTypeModifier;
    uint8_t           EntityID;
    uint8_t           EntityIns;
    uint8_t           OEMField;
    uint8_t           IDStrLen;
    int8_t           DevIdStr [MAX_ID_STR_LEN];

}    FRUDevLocatorRec_T;

/**
 * @struct OEM_FRURec_T
 * @brief OEM FRU Record Info
**/
typedef struct
{
    /*SENSOR RECORD HEADER*/
    SDRRecHdr_T   hdr;

    /*RECORD BODY BYTES*/
    uint8_t        Mfg_ID1;
    uint8_t        Mfg_ID2;
    uint8_t        Mfg_ID3;
    uint8_t        OEM_Fru;
    uint8_t        DeviceID;
    uint16_t       Size;
    uint8_t        AccessType;
    uint8_t        EntityID;
    uint8_t        EntityIns;
    uint8_t        IDStrLen;
    int8_t        FilePath[MAX_FRU_SDR_STR_SIZE];

}   OEM_FRURec_T;

/**
 * @struct OEM_NMRec_T
 * @brief OEM NM Record Info
**/
typedef struct
{

  /*SENSOR RECORD HEADER */
  SDRRecHdr_T hdr;

  /*RECORD BODY BYTES*/
  uint8_t  Mfg_ID1;
  uint8_t  Mfg_ID2;
  uint8_t  Mfg_ID3;
  uint8_t  RecordSubType;
  uint8_t  VersionNo;
  uint8_t  NMDevSlaveAddress;
  uint8_t  ChannelNumber;
  uint8_t  NMHealthEvtSensor;
  uint8_t  NMExceptionEvtSensor;
  uint8_t  NMOpCapSensor;
  uint8_t  NMAlertThresExSensor;

}  OEM_NMRec_T;


/**
 * @struct BMCMsgChannelInfoRec_T
 * @brief BMC Mesage Channel info Record
**/
typedef struct
{
    /* SENSOR RECORD HEADER */
    SDRRecHdr_T     hdr;

    /* RECORD BODY BYTES */
    uint8_t           MsgChannel0Info;
    uint8_t           MsgChannel1Info;
    uint8_t           MsgChannel2Info;
    uint8_t           MsgChannel3Info;
    uint8_t           MsgChannel4Info;
    uint8_t           MsgChannel5Info;
    uint8_t           MsgChannel6Info;
    uint8_t           MsgChannel7Info;
    uint8_t           MessagingINTType;
    uint8_t           EvtMsgBufINTType;
    uint8_t           Reserved;

}    BMCMsgChannelInfoRec_T;


/**
 * @struct SDRRec_T
 * @brief Complete unionized record structure with unions for
 *        easy reference to different types
**/
typedef union {
		SDRRecHdr_T					hdr;
        FullSensorRec_T 			full_sensor_rec;
        CompactSensorRec_T 			compact_sensor_rec;
        MgmtCtrlrConfirmRec_T 		mc_confim_rec;
        MgmtCtrlrDevLocator_T 		mc_dev_locator_rec;
        GnrcDevLocatorRec_T  		gen_dev_locator_rec;
        FRUDevLocatorRec_T  		fru_dev_locator_rec;
        BMCMsgChannelInfoRec_T 		bmc_msg_chnl_info_rec;
} SDRRec_T;

//typedef struct
//{
//    SDRRecHdr_T     hdr;
//    union
//    {
//        FullSensorRec_T full_sensor_rec;
//        CompactSensorRec_T compact_sensor_rec;
//        MgmtCtrlrConfirmRec_T mc_confim_rec;
//        MgmtCtrlrDevLocator_T mc_dev_locator_rec;
//        GnrcDevLocatorRec_T  gen_dev_locator_rec;
//        FRUDevLocatorRec_T  fru_dev_locator_rec;
//        BMCMsgChannelInfoRec_T bmc_msg_chnl_info_rec;

//    }
//    type;
//} SDRRec_T;

#pragma pack( )



#endif  /* IPMI_SDR_RECORD_H */
