/**
 * @file   libipmi_session.h
 * @author Rajasekhar (rajasekharj@amiindia.co.in)
 * @date   02-Sep-2004
 *
 * @brief  Contains function definitions & data structures
 *			required for establishing a session
 *			
 */

#ifndef __LIBIPMI_SESSION_H__
#define __LIBIPMI_SESSION_H__

#include <stdio.h>
#include "libipmi_struct.h"
#include "libipmi_errorcodes.h"
//#include "libipmiifc.h"
//#include "libipmi_version.h"



//#include "IPMI_RMCP.h"
//#include "IPMI_App.h"
//#include "IPMI_AppDevice.h"
//#include "IPMI_RMCP+.h"
//#include "IPMI_AMI.h"
//#include "AES.h"
//#include "hmac.h"
//#include "sha1.h"
//#include <time.h>
//
//typedef struct
//{
//    uint32_t      Param;                    /* Parameter */
//    uint8_t       Channel;                  /* Originator's channel number */
//    uint8_t       SrcQ [64];     /* Originator Queue */
//    uint8_t       Cmd;                      /* Command that needs to be processed*/
//    uint8_t       NetFnLUN;                 /* Net function and LUN of command   */
//    uint8_t       Privilege;                /* Current privilege level */
//    uint32_t      SessionID;                /* Session ID if any */
//    time_t      ReqTime;                  /* Request Timestamp */
//    uint16_t       ResTimeOut;              /* response timeout in secs */
//    uint16_t      SessionType;               /* Session Type */
//    uint8_t       IPAddr [16];    /* IPv6 Address */
//    uint16_t      UDPPort;                  /* UDP Port Number  */
//    uint16_t      Socket;                   /* socket handle    */
//    uint32_t      Size;                     /* Size of the data */
//    uint8_t       Data [1024 * 60];  /* Data */
//} PACKED MsgPkt_T;
//
//typedef union
//{
//    IPMIMsgHdr_T        IPMIMsgHdr;
//    IPMIUDSMsg_T        UDSMsgHdr;
//}PACKED ResMsgHdr_T;
//#include "BridgeMsgAPI.h"

/* Undefine PACK so that it can be redefined in other header files */


#ifdef  __cplusplus
extern "C" {
#endif

// extern uint16_t Create_IPMI20_UDS_Session(IPMI20_SESSION_T *pSession, char *pszSocketPath,
// 				char *pszUserName, char *pszPassword, uint8_t *byPrivLevel,
// 				char *pUserName, uint8_t *ipaddr, int timeout, uint8_t ChannelNum);


/**
This function is used to get the UserID for given Username and Password.
It compares all IPMI username with the IN argument Username.
If it matches, then it checks for the password.
If password also matches, it will return SUCCESS and corresponding User ID.
Since duplicate username is supported in IPMI specification,
It will executes unless it gets SUCCESS or reaches MAX_USERS_COUNT.
Username and Password are IN arguments, UserID is OUT argument.
**/
extern int LIBIPMI_GetUserIDForUserName(IPMI20_SESSION_T *pSession, 
							char *UserName, char *Password, 
							uint8_t *UserID,int timeout);


/**
\breif	Create UDS session to comunitation with BMC
 @param	pSession			[in]Session Info handle
 @param	timeout				[in]timeout value in seconds.

 @retval Returns LIBIPMI_E_SUCCESS on success and error codes on failure
*/
uint16_t LIBIPMI_CreateSession(IPMI20_SESSION_T *pSession, int timeout);

/**
\breif	Sends RAW IPMI Command to the BMC
 @param	pSession			[in]Session Info handle
 @param	byPayLoadType		[in]Pay Load Type in NETWORK_MEDIUM.
								shd be 0 in case of serial and kcs mediums.
 @param	byNetFnLUN			[in] Net Function and LUN for the given byCommand
 @param byCommand			[in] Command number.
 @param pszReqData			[in] Command Request Data
 @param dwReqDataLen		[in] size of Command Request data.
 @param pszResData			[in] Command Response Data
 @param	pdwResDataLen		[in] size of Command Response data.
 @param	timeout				[in]timeout value in seconds.

 @retval Returns LIBIPMI_E_SUCCESS on success and error codes on failure
*/
extern uint16_t LIBIPMI_Send_RAW_IPMI2_0_Command(IPMI20_SESSION_T *pSession,
									uint8_t byNetFnLUN, uint8_t byCommand,
									uint8_t *pszReqData, uint32_t dwReqDataLen,
									uint8_t *pszResData, uint32_t *pdwResDataLen,
									int	timeout);


/**
\breif	Closes the IPMI 2.0 Session
 @param	pSession			[in]Session Info handle

 @retval Returns LIBIPMI_E_SUCCESS on success and error codes on failure
*/
extern uint16_t LIBIPMI_CloseSession( IPMI20_SESSION_T *pSession );

/**
\breif	returns status whether the session is started or not
 @param	pSession			[in]Session Info handle
 
 @retval 1 if session is started and 0 if not
*/
extern uint8_t	IsSessionStarted(IPMI20_SESSION_T *pSession);

/**
\brief  Sets the Cmd Retry Count and Interval
 @param pSession                        [in]Session Info handle
 @retval Returns LIBIPMI_E_SUCCESS on success and error codes on failure
 @note This function is not implemented 
*/

extern uint16_t LIBIPMI_SetRetryCfg( IPMI20_SESSION_T *pSession, 
										int nCmdRetryCount, 
										int nCmdRetryInterval);

#ifdef  __cplusplus
}
#endif


#endif /* __LIBIPMI_SESSION_H__ */
