//////////////////////////////////////////////////
//Title    : scoc.h
//Auhtor   : Liu Wei
//Desc     : SCCP Connection-Oriented Control   
//Created  : 2007-04-22
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////

#ifndef _SCOC_H_
#define _SCOC_H_

#include    "scoc_if.h"
#include    "../../../public/src/include/pub_list.h"

#define spLogDebug_STATIC

typedef struct SCCP_PRIMITIVE_CR_PRIMITIVE
{
	u8   uUiPri;
    u8   uAnsiFlag;
    u16  wConnId;
    Intra_Msg tIntraMsg;
}
SP_CrPriPara;

typedef union SCCP_PRIMITVE_POOL_Elemnet
{
    SP_UiPriPara tUiPri;
    SP_CrPriPara tCrPri;
}
SP_PriPoolEle;

typedef enum SCOC_FSM_ERROR
{
    ERR_NONE,         //show state string
	ERR_FSM_DISCARD,
	ERR_FSM_ERROR,
	ERR_FSM_FATAL,
	ERR_FSM_UNEXPECT_SIDE,
	ERR_FSM_RESERVED,
	ERR_FSM_UNEXPECT_PRI,
	ERR_FSM_UNKOWN_ERROR_CODE,
	ERR_TIMER_OUT,
}
CO_FsmErr;

typedef struct SCOC_QOS
{
    u8  uInSequence;
    u8  uReturnOnErr;
    u8  uImportance;
    u8  uHopcount;
    u8  uMbit;
    u8  uRecvSequnce;
    u8  uSendSequnce;
}
CO_Qos;

typedef struct SCOC_CAUSE
{
    u8  uRelCause;
    u8  uReturnCause;
    u8  uResetCause;
    u8  uErrorCause;
    u8  uRejectCause;
}
CO_Cause;

#define MAX_SCCP_MSG 256

typedef struct SCOC_Message
{
    u8  uMsgType;
    u8  uMsgClass;
    u8  uMsgFlag;
    u8  aSLR[SP_REF_LEN];       //  0x01 SLR   present
    u8  aDLR[SP_REF_LEN];       //  0x02 DLR   present
    SCCP_ADDR tCDA;                //  0x04 CDA   present
    SCCP_ADDR tCGA;                //  0x08 CGA   present
    CO_Qos tQos;                   //  0x10 QOS   present
    CO_Cause tCause;               //  0x20 CAUSE present
    u8  aMsgConent[MAX_SCCP_MSG];  //  0x40 DATA  present
}
CO_Msg;

typedef struct CO_TIMER
{
    u32 tmConnEst;
    u32 tmIas;                  
    u32 tmIar;                  
    u32 tmRepeatRel;
    u32 tmRel;
    u32 tmReset;                //unsupportted now
    u32 tmGuard;                //unsupportted now
    //u32 tmIas;
    //u32 tmIar;
    //u32 tmIT;
    u32 tmInternal;
}
CO_Timer;

typedef struct CO_CONNECTION_Section
{
    CO_Status	uCState;
    SP_Pri		uPri;
    u8			uAnsiFlag;
    CO_InstSide	uSide;
    
    u8  uSLS;
    
    u8  uNetId;
    int nDPC;
    int nOPC;
    u8  aSLR[SP_REF_LEN];
    u8  aDLR[SP_REF_LEN];
    u8  uClass;
    u8  uCredit;
    u8  eREA;
    u8  eOR;
    
    SCCP_ADDR tCDA;
    SCCP_ADDR tCGA;
    SCCP_ADDR tSPA;

    SP_UD tUD;
    
    CO_Timer tmSCOC;
}
CO_ConnSection;

typedef struct SCOC_POOL_PRIMITIVE_IN
{
	
}
CO_PoolPriIn;


typedef struct SCLC_DATA_BLOCK
{

}
CL_DataBlock;

typedef struct SCRC_DATA_BLOCK
{

}
CR_DataBlock;

typedef struct SCMG_DATA_BLOCK
{

}
CM_DataBlock;

#define CO_CS_MPORT   8192

#ifdef DEBUG

typedef enum SCOC_DEBUG_STATIC_VALUE
{
     GET_IN_POOL  = 30,
	 PUT_IN_POOL,
	 READ_IN_POOL,
	 WRITE_IN_POOL,
	 GET_OUT_POOL,
	 PUT_OUT_POOL,
	 PUT_ELE_APT,
	 PUT_ELE_SUC,
	 UL_POST_CO_APT,
	 UL_POST_CO,
     CO_SUBMIT_UL_APT,
     CO_SUBMIT_UL,
     CO_TO_CR_APT,
     CO_TO_CR,
     CR_TO_CO_APT,
     CR_TO_CO,
     SP_TIMER_OUT,
}
CO_DebugStaticVal;


typedef struct SCOC_DEBUG_STATIC
{
    u32 dGetInPool;
    u32 dPutInPool;
    u32 dReadInPool;
    u32 dWriteInPool;

    u32 dGetOutPool;
    u32 dPutOutPool;
    u32 dPutEleApt;
    u32 dPutEleSuc;
    
	u32 dCoSubmitUlApt;
	u32 dCoSubmitUl;
	u32 dUlPostCoApt;
	u32 dUlPostCo;

	u32 dCo2CrApt;
	u32 dCo2Cr;
	u32 dCr2CoApt;
    u32 dCr2Co;
    
    u32 dTimerOut;
	u32 dbusyElem;
}
CO_DebugStatic;
#endif



typedef struct SCOC_DATA_BLOCK
{
    u32 wConnIdCount;
    CO_ConnSection tCSInst[CO_CS_MPORT];
    CO_DebugStatic tCoDebugStatic;
}
CO_DataBlock;

typedef struct SCCP_ENTITY
{
	u32			    dLocalIP;
	u32				dAlterIP;
	u32				dSysID;	
    CL_DataBlock	tCl;
    CO_DataBlock	tCo;
    CR_DataBlock	tCr;
    CM_DataBlock	tCm;
}
SP_Entity;

//SP_Entity tSpEntity;
//SP_Entity *pSp;


typedef enum SCOC_POOL_OP
{
    CO_GET_POOL,
    CO_READ_POOL,
    CO_PUT_POOL,
    CO_WRITE_POOL,
}
CO_PoolOp;

typedef struct SCOC_POOL_ELEMENT
{
	POOL_ENTRY ( SCOC_POOL_ELEMENT ) tPointer;
    SP_PriPoolEle tPri;
	BYTE flag;
}
CO_PoolEle;

typedef struct SCOC_POOL
{
    POOL_HEAD ( CO_PriPool, SCOC_POOL_ELEMENT ) tPoolHead;
    struct CO_PriPool *pPoolHead;
    int uMaxPoolSize;
    int uPoolCount;
}
CO_Pool;

#define MAX_IN_POOL  1024
#define MAX_OUT_POOL 512

extern CO_Pool *pInCoPool;
extern CO_Pool *pOutCoPool[SP_POOL_SIZE];



#endif
