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

#ifndef SVC_L2CP_H_
#define SVC_L2CP_H_

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

typedef uint32_t	l2cpGrpIndex_t;		// Define the data type for the L2CP Group Index
typedef uint32_t	l2cpIndex_t;		// Define the data type for the L2CP (Configuration) Index

typedef enum {
	l2cp_discard	= 1,		// The indicated L2CP is discarded
	l2cp_tunnel		= 2,		// The indicated L2CP is tunneled (passed)
	l2cp_peer		= 3,		// The indicated L2CP is peered with the NE
	l2cp_passToEvc	= 4,		// The indicated L2CP is passed to the EVC for EVC processing of the L2CP. Final L2CP disposition is based the L2CP profile for the EVC to be tunneled, discarded, or peered. This value is not valid for EVC based L2CP.
} l2cpType_t;

typedef enum {
	destinationAddressOnly		= 1,		// L2CP selection is determined by MAC Destination Address only
	daPlusProtocol				= 2,		// L2CP selection is determined by MAC Destination Address plus Ethernet protocol
	daPlusProtocolPlusSubtype	= 3,		// L2CP selection is determined by MAC Destination Address plus Ethernet protocol plus subtype
} matchScope_t;

typedef struct svcL2cpCfg_s {
	uint32_t		protocol;				// Configures the L2CP Ethernet protocol.
	uint32_t		subType;				// Configures the L2CP subtype protocol.
	macAddress_t	macAddress;				// Configures the L2CP Destination MAC address.
	l2cpType_t		l2cpType;				// Configures the L2CP processing type setting.
	matchScope_t	matchScope;				// Configures the L2CP selection matching scope.
} svcL2cpCfg_t;

/**
 * @brief Returns the next available L2CP GRP index
 *
 * @return The next available L2CP GRP index.
 */
l2cpGrpIndex_t	svcL2cpGrpGetNextIndex(void);


/**
 * @brief Read the next entry in the list of configured L2CP GRPs.
 *
 * Read the next entry in the list of configured L2CP GRPs. If l2cpGrpIndex is 0 it
 * returns the l2cpGrpIndex of the first L2CP GRP entry or 0 if there are
 * no L2CP GRP entries. If a valid l2cpGrpIndex is provided it returns
 * the l2cpGrpIndex of the next L2CP GRP in the list.
 *
 * @param[in] nextL2cpGrpIdx The L2CP GRP Index from a previous call to this function or 0.
 * @return	l2cpGrpIndex of the next entry or 0 if no more entries.
 *
 */
l2cpGrpIndex_t svcL2cpGrpReadList(l2cpGrpIndex_t nextL2cpGrpIdx);

/**
 * @brief Create a new service L2CP GRP .
 *
 * Create a new service L2CP GRP using the configuration
 * parameters provided.
 *
 * @param[in] l2cpGrpIndex the index value of the L2CP GRP to create. Usually obtained by calling svcL2cpGrpGetNextIndex()
 * @return
 * \li -1: Operation rejected due to insufficient resources
 * \li  1: Operation rejected due to invalid or nonexistent BWP GRP index.
 * \li  2: Operation accepted.
 */
int svcL2cpGrpCreate(l2cpGrpIndex_t l2cpGrpIndex);

/**
 * @brief	Delete the L2CP GRP with the supplied l2cpGrpIndex.
 *
 * This will delete the selected L2CP GRP and its associations with all EVCs.
 *
 * @param[in] l2cpGrpIndex the index value of L2CP GRP to delete.
 * @returns
 * \li 1: Operation rejected due to invalid or nonexistent L2CP GRP index.
 * \li 2: Operation accepted
 *
 */
int svcL2cpGrpDelete(l2cpGrpIndex_t l2cpGrpIndex);

// ========================================================================

/**
 * @brief Returns the next available L2CP GRP index
 *
 * @param[in] l2cpGrpIndex The L2CP GRP Index for which the 'next L2CP' is required.
 * @return The next available L2CP Index for the specified L2CP GRP index.
 */
l2cpIndex_t	svcL2cpGetNextL2cpIndex(l2cpGrpIndex_t l2cpGrpIndex);

/**
 * @brief Read the next entry in the list of configured L2CPs.
 *
 * Read the next entry in the list of configured L2CPs. If l2cpIndex is 0 it
 * returns the l2cpIndex of the first L2CP entry or 0 if there are
 * no L2CP GRP entries. If a valid l2cpIndex is provided it returns
 * the mdIndex of the next MD in the list.
 *
 * @param[in] l2cpGrpIndex Selects the index of L2CP GRP to read the L2CPs from.
 * @param[in] prevL2cpIndex The L2CP Index from a previous call to this function or 0.
 * @return	l2cpIndex of the next entry or 0 if no more entries.
 *
 */
l2cpIndex_t svcL2cpReadList(l2cpGrpIndex_t l2cpGrpIndex, l2cpIndex_t prevL2cpIndex);

/**
 * @brief Create a new service L2CP in the specified L2CP GRP.
 *
 * Create a new service L2CP in the specified L2CP GRP using the configuration
 * parameters provided.
 *
 * @param[in] l2cpGrpIndex Selects the index of L2CP GRP to create the new L2CPs on.
 * @param[in] l2cpIndex the index value of the L2CP to create. Usually obtained by calling svcL2cpGetNextIndex()
 * @param[in] svcL2cpCfg A pointer to a svcL2cpCfg_t data type containing configuration values.
 * @return
 * \li -2: Operation rejected due to insufficient resources
 * \li -1: Operation rejected due to invalid/NULL svcBwpCfg pointer
 * \li  1: Operation rejected due to invalid or nonexistent BWP or BWP GRP index.
 * \li  2: Operation rejected due to invalid L2CP type.
 * \li  3: Operation Operation rejected due to invalid L2CP matchScope (only 'destinationAddressOnly' supported).
 * \li  4: Operation accepted.
 */
int svcL2cpCreate(l2cpGrpIndex_t l2cpGrpIndex, l2cpIndex_t l2cpIndex, svcL2cpCfg_t *svcL2cpCfg);

/**
 * @brief	Delete the L2CP with the supplied l2cpGrpIndex and l2cpIndex.
 *
 * This will delete the selected L2CP and its associations with all EVCs and Ifaces.
 *
 * @param[in] l2cpGrpIndex Selects the index of L2CP GRP to delete the L2CPs from.
 * @param[in] l2cpIndex the index value of L2CP to delete.
 * @returns
 * \li 1: Operation rejected due to invalid or nonexistent L2CP or L2CP GRP index.
 * \li 2: Operation rejected because the L2CP is in use by an EVC or Interface
 * \li 3: Operation accepted
 *
 */
int svcL2cpDelete(l2cpGrpIndex_t l2cpGrpIndex, l2cpIndex_t l2cpIndex);

/**
 * @brief Read the service L2CP configuration.
 *
 * Read information related to this service L2CP. If a NULL pointer is supplied for
 * svcL2cpCfg then no information is returned for that parameter.
 * Information is only valid if the return value is 2.
 *
 * @param[in] l2cpGrpIndex Selects the index of L2CP GRP to which the L2CP belongs.
 * @param[in] l2cpIndex the index value of L2CP to read from.
 * @param[out] svcL2cpCfg A pointer to a svcL2cpCfg_t data type or NULL. If not NULL its values will be updated.
 * @return
 * \li 1: Operation rejected due to invalid or nonexistent L2CP index.
 * \li 2: Operation accepted.
 */
int svcL2cpRead(l2cpGrpIndex_t l2cpGrpIndex, l2cpIndex_t l2cpIndex, svcL2cpCfg_t *svcL2cpCfg);

#endif /* SVC_L2CP_H_ */
