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

#ifndef LB_TYPES_H_
#define LB_TYPES_H_

#include <api_oam_sdk/loopback/inc/lb.h>
#include "egl_log.h"

/*
 * TODO: add comment
 */
void lbInit(void);

/*
 * TODO: add comment
 */
void setLBLogLevel(log_level_t logLevel);

/*
 * @brief Read all Loopback related parameters for the selected local MEP
 *
 * @param[in] mdIndex of the parent MD
 * @param[in] maIndex of the parent MA
 * @param[in] lMepId is the MEPID of the local MEP this Loopback service is on
 * @param[out] mepLbInfo is a pointer to mepLbInfo_t struct that will be updated if it's a non NULL value
 *
 * Read the loopback information for the selected local MEP. If Loopback is still
 * running (active) then the information will be read directly from the LB hardware
 * otherwise it is copied from the loopback Information Array.
 * If the mepLbInfo is NULL then it will not be updated.
 * This function forms a subsection of the local MEP lMepRead() function. That function handles the
 * return values.
 */
void lbRead(mdIndex_t mdIndex, maIndex_t maIndex, mepId_t lMepId, mepLbInfo_t *mepLbInfo, mepLbMefInfo_t *mepLbMefInfo);

/*
 * @brief Provide a means to write to the MEF specific configuration parameters for loopback
 */
int lbWrite(mdIndex_t mdIndex, maIndex_t maIndex, mepId_t lMepId, mepLbMefInfo_t *mepLbMefInfo);

void _lbFreeChannel(lMepNum_t lMepNum);
int8_t _lbLockChannel(uint8_t chnlNum, lMepNum_t lMepNum);
int8_t _lbUnLockChannel(uint8_t chnlNum, lMepNum_t lMepNum);
int8_t _lbRequestChannel(lMepNum_t lMepNum);
void _lbClearStats(uint8_t lbChnl, uint32_t seqNum, svcDir_t selDir);

void _configLBSvcOnLMep(uint16_t lMepNum,uint8_t multiCast,txTemplateEntry_t *txLbTempl,templateType_t templType,svcDir_t svcDir, uint8_t lbChnl);
void _lbSetRate(uint8_t lbChnl, uint16_t lbRate);
void _lbSetMode(uint8_t lbChnl, lbMode_t lbMode, iFace_t iFace);
void _lbConfigureBurst(uint8_t lbChnl, uint16_t pktsPerBurst,uint16_t numBursts,uint32_t interBurstTime);

void generateLBMTemplate(
		lMepNum_t			lMepNum,
		rMepNum_t			rMepNum,
		macAddress_t		destMacAddress,
		iFace_t				iFace,
		uint16_t			dataTlvLength,
		uint8_t				mdLevel,
		tagEntry_t			*innerTag,
		tagEntry_t			*outerTag,
		bool				multicast,
		txTemplateEntry_t	*txLBMTempl);

#endif /* LB_TYPES_H_ */
