/**
 * @file   libipmi_StorDevice.h
 * @author Anurag Bhatia
 * @date   15-Sep-2004
 *
 * @brief  Contains exported APIs by LIBIPMI for
 *  		communicating with the BMC for NetFn type Storage.
 *
 */

#ifndef __LIBIPMI_STORDEVICE_H__
#define __LIBIPMI_STORDEVICE_H__

/* LIIPMI core header files */
#include "libipmi_session.h"
#include "libipmi_errorcodes.h"
#include "libipmiifc.h"

/* command specific header files */
#include "IPMI_SEL.h"
#include "IPMI_FRU.h"
#include "IPMI_IPMB.h"
#include "IPMI_Storage.h"
//#include "IPMIConf.h"
#include "SELRecord.h"

#include "libipmi_sdr.h"
#include "std_macros.h"

#ifdef  __cplusplus
extern "C" {
#endif

/*****************************************************************************
	System Event Log
******************************************************************************/
LIBIPMI_API uint16_t IPMICMD_GetSELInfo(IPMI20_SESSION_T *pSession,
					SELInfo_T *pResGetSELInfo,
					int timeout);
LIBIPMI_API uint16_t IPMICMD_GetSELAllocationInfo(IPMI20_SESSION_T *pSession,
					SELAllocInfo_T *pResGetSELAllocInfo,
					int timeout);
LIBIPMI_API uint16_t IPMICMD_ReserveSEL(IPMI20_SESSION_T *pSession,
					ReserveSELRes_T* pReserveSelRes,
					int timeout);
LIBIPMI_API uint16_t IPMICMD_GetSELEntry(IPMI20_SESSION_T *pSession,
					GetSELReq_T* pGetSELReqData,
					uint8_t* pGetSELResData,
					uint32_t ResDataLen,
					int timeout);
LIBIPMI_API uint16_t IPMICMD_AddSELEntry(IPMI20_SESSION_T *pSession,
					SELEventRecord_T* pSELReqData,
					AddSELRes_T* pSELResData,
					int timeout);
LIBIPMI_API uint16_t IPMICMD_DeleteSELEntry(IPMI20_SESSION_T *pSession,
					uint16_t RecordID,
					int timeout);

/*---------- LIBIPMI Higher level routines -----------*/
LIBIPMI_API uint16_t LIBIPMI_HL_GetNumOfSELEntries(IPMI20_SESSION_T *pSession,
					uint16_t* nNumOfSELEntries,
					int timeout);
LIBIPMI_API uint16_t LIBIPMI_HL_GetMaxPossibleSELEntries(IPMI20_SESSION_T *pSession,
					uint16_t* nMaxPossibleSELEntries,
					int timeout);
LIBIPMI_API uint16_t LIBIPMI_HL_GetAllSELEntries(IPMI20_SESSION_T *pSession,
					SELEventRecord_T *pSELEntriesBuffer,
					int timeout);

LIBIPMI_API uint16_t LIBIPMI_HL_GetAllSensorInfo(IPMI20_SESSION_T *pSession,
					uint8_t **SDRBuff,
					int *SDRCount,
					int *MaxSDRLen,
					int timeout);
LIBIPMI_API uint16_t LIBIPMI_HL_GetSensorName(IPMI20_SESSION_T *pSession,
					uint8_t SlaveAdd,
					uint8_t LUNid,
					uint8_t SensorNum,
					uint8_t *SensorName,
					int timeout);
uint16_t LIBIPMI_HL_GetAllFRUDevice(IPMI20_SESSION_T *pSession,
					uint8_t *pFRUIDs,
					uint8_t *nFRUs,
					uint8_t nFRUsName[][16],
					int timeout);

/*****************************************************************************
	Field Replacement Unit (FRU)
******************************************************************************/

#pragma pack(1)
/*this is a structure used by an abstraction function
for getallselentries
we want all sel entires but we also want sensor names*/
typedef struct _SELEventRecordWithSensorName
{
	SELRec_T EventRecord;
	uint8_t SensorName[65]; //65 is the max possible because SensorName len in SDR is indicated by 6 bits
} PACKED
SELEventRecordWithSensorName_T;

#ifndef MAX_FRU_DEVICES
#define MAX_FRU_DEVICES	32
#endif

#pragma pack(1)
typedef struct _SDRHeader
{
    /** The ID of this SDR, LSB first */
    uint8_t RecordID[ 2 ];
    /** Version of this SDR (Not always the same as the IPMI version!) */
    uint8_t SDRVersion;
    /** The type of this SDR, usually \ref SDR_FULL or \ref SDR_COMPACT */
    uint8_t RecordType;
    /** The length of the SDR that follows this header */
    uint8_t RecordLength;
}PACKED  SDRHeader;

#pragma pack()

uint8_t libipmi_GetBits(uint8_t orig, uint8_t startbit, uint8_t endbit);

//Having this for backward compatibility. Projects still using GetBits
//Will remove this macro when all projects stop using it
#define GetBits libipmi_GetBits

LIBIPMI_API uint16_t IPMICMD_GetFRUInventoryAreaInfo(IPMI20_SESSION_T *pSession,
				FRUInventoryAreaInfoReq_T *pReqFRUInventoryAreaInfo,
				FRUInventoryAreaInfoRes_T *pResFRUInventoryAreaInfo,
				int timeout);

LIBIPMI_API uint16_t IPMICMD_ReadFRUData(IPMI20_SESSION_T *pSession,
				FRUReadReq_T* pFRUReadReqData,
				FRUReadRes_T* pFRUReadResData,
				int timeout);

LIBIPMI_API uint16_t IPMICMD_WriteFRUData(IPMI20_SESSION_T *pSession,
				FRUWriteReq_T* pFRUWriteReqData,
				uint32_t ReqDataLen /* Bytes to be written + sizeof(FRUWriteReq_T) */,
				FRUWriteRes_T* pFRUWriteResData,
				int timeout);

LIBIPMI_API uint16_t LIBIPMI_HL_GetAllFRUDevices(IPMI20_SESSION_T *pSession,
				uint8_t *pFRUIDs,
				uint8_t *pFRUNames,
				uint8_t *nFRUs,
				int timeout);

LIBIPMI_API uint16_t LIBIPMI_HL_GetAllSelEntriesWithSensorNames(IPMI20_SESSION_T *pSession,
	SELEventRecordWithSensorName_T *pSELEntriesBuffer,
	int timeout);

LIBIPMI_API uint16_t IPMICMD_ClearSEL(IPMI20_SESSION_T *pSession,
				int timeout);

LIBIPMI_API uint8_t IPMICMD_GetSELTime(IPMI20_SESSION_T *pSession,
				GetSELTimeRes_T *pGetSELTimeRes, int timeout);

LIBIPMI_API uint8_t IPMICMD_SetSELTime(IPMI20_SESSION_T *pSession,
				SetSELTimeReq_T *pSetSELTimeReq, int timeout);

LIBIPMI_API uint8_t IPMICMD_GetSELTimeUTCOffset(IPMI20_SESSION_T *pSession,
				GetSELTimeUTCOffsetRes_T *pGetSELTimeUTCOffsetRes, int timeout);

LIBIPMI_API uint8_t IPMICMD_SetSELTimeUTCOffset(IPMI20_SESSION_T *pSession,
				SetSELTimeUTCOffsetReq_T *pSetSELTimeUTCOffsetReq, int timeout);


#ifdef  __cplusplus
}
#endif

#endif
