#ifndef __COM_BMC_TYPE_H__
#define __COM_BMC_TYPE_H__

#include "com_IPMI_ChassisDevice.h"
#include "com_IPMI_FRU.h"
#include "com_IPMIDefs.h"
#include "com_IPMI_SEL.h"
#include "com_IPMI_SDRRecord.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


#pragma pack(1)

typedef struct{
	uint8_t	sensorNum;
	uint8_t supportHistory;
	uint8_t	sensorHistoryEn;
} OEM_SENSOR_CAPABILITY_T;


/***************************************** FRU ******************************************************/

/*
 * Common Header: 		offset = 0,		len = 8
 * chassis info area	offset = 1,		len = 64
 * Board info area:		offset = 9,		len = 96
 * product info area:	offset = 21, 	len = 88
 * ------------------------------------------------------------------
 * 										total = 256 		
 */
#define FRU_CHASSIS_SIZE	64
#define FRU_BOARD_SIZE		96
#define FRU_PRODUCT_SIZE	88
#define FRU_TOTAL_SIZE		256

typedef struct	
{
    uint8_t		ChassisInfoAreaFormatVersion;
    uint8_t		ChassisInfoAreaLength;	/* In multiple of 8 bytes. */
    uint8_t		ChassisType;
    uint8_t   	Data[FRU_CHASSIS_SIZE-6];
    uint8_t		type_length;
	uint8_t		Y;
	uint8_t		checksum;
}  OemFRUChassisInfo_T;

typedef struct
{
    uint8_t		BoardInfoAreaFormatVersion;
    uint8_t		BoardInfoAreaLength;	/* In multiple of 8 bytes. */
    uint8_t		Language;
    uint8_t   	MfgDateTime[3];
    uint8_t		Data[FRU_BOARD_SIZE - 21];
    uint8_t		PowerOnCounts[4];
    uint8_t		TotalWorkTime[4];
    uint8_t		ThisWorkTime[4];
    uint8_t		type_length;
    uint8_t		Y;
    uint8_t		checksum;
}  OemFRUBoardInfo_T;

/* Product Info Area */
typedef struct
{
    uint8_t		ProductInfoAreaFormatVersion;
    uint8_t		ProductInfoAreaLength;	/* In multiple of 8 bytes. */
    uint8_t		Language;
    uint8_t		Data[FRU_PRODUCT_SIZE - 6];
    uint8_t		type_length;
    uint8_t		Y;
	uint8_t		checksum;
}  OemFRUProductInfo_T;


/* Complete FRU Data */
typedef struct
{
    FRUCommonHeader_T   		CommonHeader;
    OemFRUChassisInfo_T			ChassisInfo;
    OemFRUBoardInfo_T			BoardInfo;
    OemFRUProductInfo_T			ProductInfo;
}  OemFRUData_T;


typedef struct{
//    uint8_t   DeviceID;       /* FRU Device ID                                */
//    uint8_t   IsInternalFRU;  /* Flag to hide FRU					*/
    uint8_t   Type;           /* FRU type NVR/EEPROM/....                     */
    uint16_t  Size;           /* FRU Device size                              */
    uint8_t   AccessType;     /* FRU device access type BYTE/WORD             */
    uint8_t   BusNumber;      /* Bus number if FRU is EEPROM                  */
    uint8_t   SlaveAddr;      /* FRU device slave address if FRU is EEPROM    */
    uint8_t   DeviceType;     /* FRU device type if FRU is EEPROM             */
} FRUInfo_T;

/**************************************** sensor **********************************************/
typedef struct
{
    uint16_t 		NumThreshSensors;
    uint16_t 		NumNonThreshSensors;
    int 			MonitorBusy;//=0;
 //   uint16_t 		SensorMonitorLoopCount;		//nessary ?
    uint8_t  		InitAgentRearm; // = FALSE;	nessary??
    uint16_t 		ValidSensorCnt;
    uint8_t 		ValidSensorList[MAX_SENSOR_NUMBERS];
//    HealthState_T  	HealthState;
    uint32_t 		PowerOnTick;
    uint32_t 		SysResetTick;
    
} SENSOR_T;

typedef struct
{
    uint8_t   SensorNum;
    uint8_t   SensorTypeCode;
    uint8_t   LowerNonCritical;
    uint8_t   LowerCritical;
    uint8_t   LowerNonRecoverable;
    uint8_t   UpperNonCritical;
    uint8_t   UpperCritical;
    uint8_t   UpperNonRecoverable;

} SensorThresholds;

/* SDRRepositoryAllocInfo_T */
typedef struct
{
    uint8_t   CompletionCode;
    uint16_t  NumAllocUnits;      /* Number of possible allocation units */
    uint16_t  AllocUnitSize;      /* Allocation unit size in bytes */
    uint16_t  NumFreeAllocUnits;  /* Number of free allocation units */
    uint16_t  LargestFreeBlock;   /* Largest free block in allocation units */
    uint8_t   MaxRecSize;         /* Maximimum record size in allocation units */

}   SDRRepositoryAllocInfo_T;

/* SDRRepositoryInfo_T */
typedef struct
{
    uint8_t   CompletionCode;     /* Completion Code */
    uint8_t   Version;            /* Version of the SDR 0x51 */
    uint16_t  RecCt;              /* Record Count */
    uint16_t  FreeSpace;          /* Free space LSB first */
    uint32_t  AddTimeStamp;       /* Most recent addition timestamp */
    uint32_t  EraseTimeStamp;     /* Most recent erase timestamp */
    uint8_t   OpSupport;          /* Operation Support */

}   SDRRepositoryInfo_T;

/**
 * @struct SDRRepository_T
 * @brief SDR Repository organisation
**/
typedef struct
{
    uint8_t   Signature [4];      /* $SDR */

    uint16_t  NumRecords;         /* Number of records */
    uint16_t  Size;               /* Size of the SDR Records Data */

    uint32_t  AddTimeStamp;       /* Most recent addition timestamp */
    uint32_t  EraseTimeStamp;     /* Most recent erase timestamp */

}   SDRRepository_T;

typedef struct
{
    uint8_t     				SDRError;
    uint8_t      					UpdatingSDR;
    uint8_t     				UpdatingChannel;
    SDRRepositoryAllocInfo_T    RepositoryAllocInfo;
    SDRRepositoryInfo_T       	RepositoryInfo;
    uint8_t   					TrackPOffset;
    uint16_t  					TrackRecID;
    uint16_t  					ReservationID;
    uint8_t 					IPMB_Seqnum;
    uint8_t     				PartAddbytes;
    uint16_t 					LatestRecordID;
    uint16_t 					NumMarkedRecords;
    SDRRepository_T*   			SDRRAM;
} SDR_T;

/******************************************* SEL *******************************************/
typedef struct
{
    uint16_t  	SelReservationID;
    uint32_t  	LastEvtTS;
//    uint8_t   	SELLimit;
    uint16_t  	PartialAddRecordID;
    uint8_t   	PartialAddRecOffset;
    uint8_t   	PartialAdd;
    uint8_t   	SenMonSELFlag;
    uint16_t  	MaxSELRecord;
//    uint8_t    	RsrvIDCancelled;
    uint8_t 		SELOverFlow;
    SELEventRecord_T  SelPartialAddRecord;
    uint8_t 	SELEventMsg [16];
    int 		selalmostfull;
} SEL_T;

typedef struct
{
    SDRRecHdr_T    hdr;
    uint8_t               OwnerID;
    uint8_t               OwnerLUN;
    uint8_t               SensorNumber;
    uint8_t               SensorReading;
    uint8_t               MaxReading;
    uint8_t               MinReading;
    uint8_t               Flags;
    uint8_t               ComparisonStatus;
    uint8_t               OptionalStatus;
    uint8_t               SensorTypeCode;
    uint8_t               EventTypeCode;
    uint8_t               Units1;
    uint8_t               Units2;
    uint8_t               Units3;
    uint8_t               Linearization;
    uint8_t               M_LSB;
    uint8_t               M_MSB_Tolerance;
    uint8_t               B_LSB;
    uint8_t               B_MSB_Accuracy;
    uint8_t               Accuracy_MSB_Exp;
    uint8_t               RExp_BExp;
    uint8_t               LowerNonCritical;
    uint8_t               LowerCritical;
    uint8_t               LowerNonRecoverable;
    uint8_t               UpperNonCritical;
    uint8_t               UpperCritical;
    uint8_t               UpperNonRecoverable;
    uint8_t               AssertionEventByte1;
    uint8_t               AssertionEventByte2;
    uint8_t               DeassertionEventByte1;
    uint8_t               DeassertionEventByte2;
    char                SensorName[MAX_ID_STR_LEN];
    uint16_t              Settable_Readable_ThreshMask;    

}SenInfo_T;

typedef struct
{
    uint8_t   CompletionCode;
    SenInfo_T SensorInfo;
    //uint16_t   Noofentries;
} StorleadGetSensorInfoRes_T;


/**
 * @struct UserInfo_T
 * Structure for user information.
**/
typedef struct
{
//    uint32_t  ID;
    uint8_t   UserId;
    uint8_t   UserName [MAX_USERNAME_LEN];
    uint8_t   UserPassword [MAX_PASSWORD_LEN];
//    uint8_t   MaxPasswordSize;                /**< Maximum password size                  */
//  uint8_t   ChannelAccess;                /** reserve,Call back, Link Auth, Ipmi Msg, Priv[3:0]. **/
//    uint8_t   UserShell;                      /**< user shell type                        */      
//    uint8_t   UserEMailID [EMAIL_ADDR_SIZE];  /**< Email-ID registered for the user       */
//    uint8_t   MaxSession;                     /**< max No of session allowed for User.    */
//    uint8_t   CurrentSession;                 /**< No Current session for the User.       */
    uint8_t    UserStatus;                  /**< User Enabled/Disabled Status.          */
//    uint32_t    FixedUser:1;                  /**< Is this user name fixed                */
//    uint8_t  EmailFormat[EMAIL_FORMAT_SIZE]; /** Email Alert format                       */
//    uint32_t  ExtendedPrivilege;                       /** User Enhanced Privilege Flags           */
//    uint8_t   UserPasswdConfigured;           /*  Flag to allow default Empty Password  */
}   UserInfo_T;



typedef struct
{
    uint32_t Noofentretrieved;  //offset
}AMIGetSELEntriesReq_T;

typedef struct
{
    uint8_t   CompletionCode;
    uint32_t   Noofentries;
    uint16_t   LastRecID;
    uint8_t   Status;
}AMIGetSELEntriesRes_T;

typedef struct 
{
    char name[MAX_USERNAME_LEN];
    char password[MAX_PASSWORD_LEN];
} AuthorVerify_T;

typedef struct 
{
    uint8_t SensorNum;
    uint8_t History[HISTORY_DATA_SIZE];
} SensorHistoryInfo_T;

typedef struct{
    uint8_t index;
    uint8_t name[MAX_ID_STR_LEN];
    uint8_t mode;
    uint8_t level;    //duty 0% - 100%
    uint32_t speed;   //RPM 
} FanInfo_T;

typedef struct{
    uint8_t healthStatus;   //0: 未知（灰色） 1：健康（绿色） 2：警告（黄色）3：错误（红色）
    uint8_t bladeName[31];  //10个汉字或30个字符
    uint8_t slotID;         
    uint8_t pwrStatus;      //0：未上电（灰色）     1：已上电（绿色）
} BladeStatus_T;


typedef struct{
    uint8_t EthName[20];
    uint8_t IPAddrSrc;  //0:unspecified 1:Static 2:DHCP  3:BIOS 4:other
    uint8_t IPAddr[4];
    uint8_t BroadCast[4];
    uint8_t NetMask[4];
    uint8_t DefaultGW[4];
    uint8_t MACAddr[6];
} LanInfo_T;

#pragma pack()
#endif /* __BMC_TYPE_H__ */