/*******************************************************************************
 * (c) Copyright 2015 Microsemi Corporation.  All rights reserved.
 *
 *
 *
 * SVN $Revision: $
 * SVN $Date: $
 */

#ifndef RMEP_DB_H_
#define RMEP_DB_H_

#include <api_oam_sdk/common/types/inc/mr_api_types.h>
#include <api_oam_sdk/mep/inc/mep.h>
#include "egl_types.h"

typedef enum
{
	rMepIdle	= 1,
	rMepStart	= 2,
	rMepFailed	= 3,
	rMepOk		= 4
} rMepState_t;

typedef struct
{
	uint32_t		_lastReceivedSeqNum;// ** Custom parameter that has the value of the last received sequence number received by this remote MEP
	rMepState_t		state;
	bool			rdi;				// State of the RDI bit in the last received CCM (true for RDI=1), or false if none has been received
	psValue_t		portStatusTlv;		// the Port status TLV received in the last CCM from the remote MEP or the default value psNoPortStateTLV
	isValue_t		interfaceStatusTlv;	// the Interface status TLV received in the last CCM from the remote MEP or the default value isNoInterfaceStatus
	time_t			failedOkTime;		// The time (SysUpTime) at which the IFF Remote MEP state machine last entered either the RMEP_FAILED or RMEP_OK state
	macAddress_t	macAddress;			// MAC address of this remote MEP
	bool			rMepIsActive;		// A Boolean value stating if the remote MEP is active.
	chassisIdSub_t	chassisIdSubType;	// specifies the format of the Chassis ID received in the last CCM
	chassisId_t		chassisId;			// The Chassis ID. The format of this object is determined by chassisIdSubType
	manAddrDomain_t	manAddrDomain;		// The TDomain that identifies the type and format of the related manAddress object, used to access the SNMP agent of the system transmitting the CCM
	manAddr_t		manAddress;			// The TAddress that can be used to access the SNMP agent of the system transmitting the CCM, received in the CCM Sender ID TLV from that system
	orgTlv_t		_orgTlv;			// ** Custom parameter to allow support for reporting a received Organisational TLV
} rMepDB_t;

/*
 * @brief Read the next entry in the Remote Mep List
 *
 * @param[in] mdIndex of the parent MD
 * @param[in] maIndex of the parent MA
 * @param[in] lMepId is the MEP ID of the local MEP
 * @param[in] nextRMepId is the previously returned remote MEP ID from this function or 0
 * @return	mepId of the next entry or 0 if no more entries
 *
 * Read the next entry in the rMep List. If nextRMepId is 0 it
 * returns the mepId of the first remote Mep entry or 0 if there are
 * no remote Mep entries. If a valid nextRMepId is provided it returns
 * the mepId of the next remote Mep in the list.
 */
mepId_t rMepReadList(mdIndex_t mdIndex, maIndex_t maIndex, mepId_t lMepId, mepId_t nextRMepId);

/*
 * @brief	Read the database information for the Remote MEP
 *
 * @param[in] mdIndex of the parent MD
 * @param[in] maIndex of the parent MA
 * @param[in] lMepId is the MEPID of the parent local MEP
 * @param[in] rMepId is the MEPID of the Remote MEP to read from
 * @param[out] A pointer to a rMepDB data type or NULL. If not NULL its values will be updated

 * return values:
 * 1: Operation rejected due to invalid or nonexistent MEPID
 * 2: Operation rejected due to remote MEPID not configured on MA
 * 3: Operation accepted
 *
 * Read the remote MEP Database information for the remote MEP with the specified rMepId.
 * If the rMepDB pointer is NULL no information will be returned, but the function may still
 * return 3.
 */
int rMepDBRead(mdIndex_t mdIndex, maIndex_t maIndex, mepId_t lMepId, mepId_t rMepId, rMepDB_t *rMepDB);

#endif /* RMEP_DB_H_ */
