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

#ifndef MD_TYPES_H_
#define MD_TYPES_H_

#include <api_oam_sdk/common/types/inc/linked_list.h>
#include <api_oam_sdk/common/types/inc/mr_api_types.h>
#include <api_oam_sdk/maintenance_association/src/ma_types.h>
#include <api_oam_sdk/maintenance_domain/inc/md.h>
#include "egl_types.h"
#include "egl_log.h"

typedef struct
{
	mdIndex_t	mibIdx;									// The MIB index for this MD
	mdNum_t		mdNum;									// Hardware index associated with this MD
	bool		inUse;									// Used to indicate that an entry is in use
} mdCtxt_t;

struct mdEntry_s
{
	TAILQ_ENTRY(struct mdEntry_s,) 	ll;
	mdMibInfo_t						mdMibInfo;
	mdCtxt_t						mdCtxt;
	networkAddress_t 				alarmNetAddress;
	TAILQ_HEAD(llMaHead_s,struct maEntry_s,)	llMaHead;	// The Linked list head, used to access the MA list for this MD
};

typedef struct mdEntry_s mdEntry_t;

typedef struct
{
	TAILQ_HEAD(llMdHead_s,struct mdEntry_s,)	llMdHead;	// The Linked list head, used to access the MD list
	mdIndex_t							mdNextMibIdx;		// The MIB index to use for the next MD created
	mdNum_t								mdCount;			// Count of the number of configured MDs
} mdList_t;

#define MAX_NUM_MD		(MAX_NUM_MA)						// The Maximum number of MDs supported by the system
#define INVALID_MD_NUM	0xFFFF

extern void setMdLogLevel(log_level_t logLevel);

/*
 * @brief Initialise Maintenance Domain (MD) module
 *
 * Must be called at device startup to initialise Maintenance Domain (MD) module.
 * It is safe to call multiple times.
 */
extern void mdInit(void);
extern mdNum_t	_mdMibIndexToMdNum(mdIndex_t mdIndex);
extern mdIndex_t _mdNumToMibIndex(mdNum_t mdNum);
extern void _mdIncNextMaIdx(mdIndex_t mdIndex, maIndex_t maIndex);
extern struct llMaHead_s* _getMaListHead(mdIndex_t mdIndex);

extern void lockMDBranch(mdIndex_t mdIndex, uint32_t timeout);
extern void unlockMDBranch(mdIndex_t mdIndex);
extern void _mdUpdateCCMTLVs(mdIndex_t mdIndex, iFace_t iFace, tlvType_t type,uint8_t length,void *value);

#endif /* MD_TYPES_H_ */
