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

#ifndef SVC_IFACE_H_
#define SVC_IFACE_H_

#include <api_oam_sdk/common/types/inc/mr_api_types.h>
#include <api_oam_sdk/service_bwp/inc/svc_bwp.h>
#include <api_oam_sdk/service_l2cp/inc/svc_l2cp.h>
#include "egl_types.h"

typedef enum {
	bUni1d1 	= 1,
	bUni1d2		= 2,
	bUni2d1		= 4,
	bUni2d2		= 8,
	bEnni		= 16,
	bEnniVuni	= 32
} svcIfaceType_t;							// These are used as bit masks

typedef enum {
	ff_noTag	= 1,
	ff_ctag		= 2,
	ff_stag		= 3,
	ff_stagCtag	= 4
} frameFormat_t;

typedef enum {
	ifaceParam_svcIfaceType			= 1,	// The write parameter value to select the interface type.
	ifaceParam_frameFormat			= 2,	// The write parameter value to select the interface frame format type that the interface can recognise.
	ifaceParam_ingressBwpGrpIndex	= 3,	// The write parameter value to select the index number of the associated ingress bandwidth profile group.
	ifaceParam_egressBwpGrpIndex	= 4,	// The write parameter value to select the index number of the associated egress bandwidth profile group.
	ifaceParam_l2cpGrpIndex			= 5,	// The write parameter value to select the index number of the associated l2cp profile group.
	ifaceParam_pcpEncoderMap		= 6,
	ifaceParam_pcpDecoderMap		= 7,
	ifaceParam_ingressDscpMap		= 8,
	ifaceParam_vLanFilterList		= 9,
	ifaceParam_admittance			= 10,
	ifaceParam_useDEI				= 11,
	ifaceParam_colorAware			= 12,
	ifaceParam_colorForward			= 13
} svcIfaceWrParam_t;

typedef struct svcIfaceCfg_s{
	bwpGrpIndex_t	ingressBwpGrpIndex;		// The index number of the associated ingress bandwidth profile group. A value of 0 indicates that there is no associated bwpGrp.
	bwpGrpIndex_t	egressBwpGrpIndex;		// The index number of the associated egress bandwidth profile group. A value of 0 indicates that there is no associated bwpGrp.
	l2cpGrpIndex_t	l2cpGrpIndex;			// The index number of the associated l2cp profile group. A value of 0 indicates that there is no associated l2cpGrp.
	svcIfaceType_t	svcIfaceType;			// The configured interface type. One bit in the vector can be set at one time.
	frameFormat_t	frameFormat;			// The interface frame format type that the interface can recognise.
} svcIfaceCfg_t;

typedef struct svcIfaceStatus_s{
	uint32_t	maxVc;						// Indicates the maximum number of virtual channels that the interface can support. Fixed to MAX_EVC.
	uint32_t	maxEndPointPerVc;			// Not relevant for this device - will be fixed at 0
	uint8_t		type;						// This object is a vector of bits that indicates the possible interface types that an interface can be configured to
} svcIfaceStatus_t;

typedef enum {
	admitAll				= 0,
	admitPrioUntaggedOnly	= 1,
	admitVlanOnly			= 2
} admittance_t;

typedef struct svcIfaceEglCfg_s{
	char			pcpEncoderMap[32];		// Defines the ingress COS mapping for the interface (default = "0,2,4,6,8,10,12,14")
	char			pcpDecoderMap[32];		// Defines the egress COS mapping for the interface  (default = "0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7")
	char			ingressDscpMap[192];	// Defines the ingress DSCP mapping for the interface (default = ??) comma separated set of 64 1 or 2 digit values. Each digit is the priority*2+color e.g. prio4+yellow=9
	char			vLanFilterList[256];	// A List of all VLan that should be filtered (dropped) at the interface (default = "")
	admittance_t	admittance;				// Defines the admittance rules for ingress packets	(default = admitAll)
	bool			useDEI;					// Set whether to use the DEI option or not (default = false)
	bool			colorAware;				// Set to control if the interface should be color aware or not.
	bool			colorForward;			// Set to control if the interface should be forward the color bit or not.
} svcIfaceEglCfg_t;
/*
 * @brief Read the service Interface configuration, status and stats for the specified interface.
 *
 * Read information related to this service Interface. If a NULL pointer is supplied for svcIfaceCfg,
 * svcIfaceStatus or svcIfaceStats then no information is returned for that parameter.
 * Information is only valid if the return value is 2.
 *
 * @param[in] iFace The index value of the interface to read from.
 * @param[out] svcIfaceCfg A pointer to a svcIfaceCfg_t data type or NULL. If not NULL its values will be updated.
 * @param[out] svcIfaceStatus A pointer to a svcIfaceStatus_t data type or NULL. If not NULL its values will be updated.
 * @return
 * \li 1: Operation rejected due to invalid or nonexistent interface.
 * \li 2: Operation accepted.
 */
int svcIfaceRead(iFace_t iFace, svcIfaceCfg_t *svcIfaceCfg, svcIfaceEglCfg_t *svcIfaceEglCfg, svcIfaceStatus_t *svcIfaceStatus);

/**
 * @brief	Write a new value to the selected service Interface parameter.
 *
 * The writable parameters for an service Interface and the associated data type are:
	ifaceParam_svcIfaceType			svcIfaceType_t
	ifaceParam_frameFormat			frameFormat_t
	ifaceParam_ngressBwpGrpIndex	bwpGrpIndex_t
	ifaceParam_egressBwpGrpIndex	bwpGrpIndex_t
	ifaceParam_l2cpGrpIndex			l2cpGrpIndex_t
	ifaceParam_pcpEncoderMap		char[48]
	ifaceParam_pcpDecoderMap		char[48]
	ifaceParam_ingressDscpMap		char[128]
	ifaceParam_vLanFilterList		char[256]
	ifaceParam_admittance			admittance_t
	ifaceParam_useDEI				bool
 *
 * Write a new value to a writable parameter of the service Interface. The ifaceParam value
 * is used to select one of the valid writable parameters (listed above) and the paramValue
 * is a pointer to the new value. The data type of the parameter (also listed above)
 * must be valid for the parameter or errors/misconfigurations may occur.
 *
 * @param[in] iFace selects the interface to write the parameter to.
 * @param[in] ifaceParam Is an enum value that identifies the service Interface parameter to write to.
 * @param[in] paramValue Is a pointer to the new value for the selected parameter
 * @returns
 * \li 1: Operation rejected due to invalid or nonexistent iFace
 * \li 2: Operation rejected due to the selected managed object being Read-Only
 * \li 3: Operation rejected due to invalid value for parameter
 * \li 4: Operation accepted
 *
 */
int svcIfaceWrite(iFace_t iFace, svcIfaceWrParam_t wrParam, void *paramValue);

#endif /* SVC_IFACE_H_ */
