/*****************************************************************
 *****************************************************************
 ***                                                            **
 ***    (C)Copyright 2005-2006, American Megatrends Inc.        **
 ***                                                            **
 ***            All Rights Reserved.                            **
 ***                                                            **
 ***        6145-F, Northbelt Parkway, Norcross,                **
 ***                                                            **
 ***        Georgia - 30071, USA. Phone-(770)-246-8600.         **
 ***                                                            **
 *****************************************************************
 ******************************************************************
 *
 * SDR.h
 * SDR functions.
 *
 *  Author: Rama Bisa <ramab@ami.com>
 *
 ******************************************************************/
#ifndef SDR_H
#define SDR_H

#include "com_IPMI_SDR.h"
#include "SDRRecord.h"
//#include "main.h"

#pragma pack( 1 )

/**
 * @struct E2ROMHdr_T
 * @brief EEROM Header.
**/
typedef struct
{
    uint8_t Valid;
    uint8_t Len;

}   E2ROMHdr_T;

#pragma pack( )

/**
 * @var g_SDRRAM
 * @brief SDR Repository.
**/
extern  SDRRepository_T*      g_SDRRAM;


/**
 * @defgroup src SDR Repository Command handlers
 * @ingroup storage
 * IPMI Sensor Data Records Repository interface commands.
 * These commands provide read/write access to BMC's SDR repository.
 * @{
**/
 int GetSDRRepositoryInfo      ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
 int GetSDRRepositoryAllocInfo ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
 int ReserveSDRRepository      ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
 int GetSDR                    ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
 int AddSDR                    ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
 int PartialAddSDR             ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
 int DeleteSDR                 ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
 int ClearSDRRepository        ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
 int GetSDRRepositoryTime      ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
 int SetSDRRepositoryTime      ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
 int EnterSDRUpdateMode        ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
 int ExitSDRUpdateMode         ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
 int RunInitializationAgent    ( uint8_t* pReq, uint8_t ReqLen,  uint8_t* pRes);
/** @} */

/**
 * @brief Get the next SDR record ID.
 * @param RecID - Current SDR record ID.
 * @return the next SDR record ID.
**/
 uint16_t   SDR_GetNextSDRId     (uint16_t RecID);

/**
 * @brief Reads SDR Repository contents.
 * @param pSDRRec - Current SDR Record header.
 * @return the next SDR Record header.
**/
  SDRRecHdr_T*   ReadSDRRepository ( SDRRecHdr_T* pSDRRec);

/**
 * @brief Write into SDR Repository.
 * @param pSDRRec - Record to be written.
 * @param Offset  - Write offset.
 * @param Size    - Size of write.
 * @return the SDR Record header.
**/
 void WriteSDRRepository ( SDRRecHdr_T* pSDRRec, uint8_t Offset, uint8_t Size,uint8_t SdrSize);

/**
 * @brief Get the SDR Record.
 * @param RecID - SDR Record ID.
 * @return the SDR Record.
**/
  SDRRecHdr_T* GetSDRRec  (uint16_t RecID);

/**
 * @brief Initialize SDR Repository.
 * @return 0 if success, -1 if error
**/
  int  InitSDR (void);


#endif /* SDR_H */
