//////////////////////////////////////////////////
//Title    : SCCP_if.h
//Auhtor   : Liu Wei
//Desc     : SCOC interface header   
//Created  : 2007-05-07
//Revision :
//
//Revision :
//
//////////////////////////////////////////////////

#ifndef _SCCP_IF_H_
#define _SCCP_IF_H_

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

#define MAX_DIGITS		10
#define SP_REF_LEN 3

///////////////////////////////////////////////////
typedef struct SCCP_ADDRESS
{
    DWORD ip;
    int DPC;
    BYTE NetID;
    BYTE SSN;
    BYTE RI;
    BYTE GTI;
    BYTE TT;
    BYTE NP;
    BYTE ES;
    BYTE NAI;
    BYTE len;
    BYTE GTAI[MAX_DIGITS];
    BYTE AI;
}
SCCP_ADDR;

typedef enum SCCP_LI_MTP_PRIMITIVE
{
    MTP_TARNSFER,
    MTP_RESUME,
    MTP_STATUS,
    MTP_UPU,
}
SP_LiMTPPri;

typedef enum SCCP_UI_N_PRIMITIVE
{
	N_UNITDATA_REQ,
	N_UNITDATA_IND,
	N_NOTICE_IND,
	N_CONNECT_REQ,
	N_CONNECT_IND,
	N_CONNECT_RSP,
	N_CONNECT_CFM,
	N_DISCONNECT_REQ,
	N_DISCONNECT_IND,
	N_DATA_REQ,
	N_DATA_IND,
	N_DATAAK_REQ,
	N_DATAAK_IND,
	N_EDATA_REQ,
	N_EDATA_IND,
	N_RESET_REQ,
	N_RESET_IND,
	N_RESET_RSP,
	N_RESET_CFM,
	N_INFORM_REQ,
	N_INFORM_IND,
	SPUI_PRI_MAX,

	R_CR   ,					/* connection request         */
	R_CC   ,                    /* connection confirm         */
	R_CREF ,                    /* connection refused         */
	R_RLSD ,                    /* release request            */
	R_RLC  ,                    /* release confirm            */
	R_DT1  ,                    /* Data Form 1                */
	R_DT2  ,                    /* Data Form 2                */
	R_AK   ,                    /* Data acknowledge           */
	R_UDT  ,                    /* Unit data                  */
	R_UDTS ,                    /* Unit data                  */
	R_ED   ,                    /* Expedited data             */
	R_EA   ,                    /* Expedited data acknowledge */
	R_RSR  ,                    /* Reset request              */
	R_RSC  ,                    /* Reset confirm              */
	R_ERR  ,                    /* PDU error                  */
	R_IT   ,                    /* Inactivity test            */
	R_XUDT ,                    /* XUDT                       */
	R_XUDTS,                    /* XUDTS                      */
	R_LUDT ,                    /* LUDT                       */
	R_LUDTS,                    /* LUDTS                      */
	R_RF   ,                    /* Routing Fail               */
	R_RLS_ERR,                  /* Release err                */
	R_CR2  ,                    /* connection request type 2  */
	SPCR_PRI_MAX  ,             /* MAX CR2CO Primitive        */

	T_CONNEST_OUT,
	T_IAS_OUT,
	T_IAR_OUT,
	T_REPEATE_RLS_OUT,
	T_RLS_OUT,
	T_RESET_OUT,
	T_GUARD_OUT,
	T_INTERNAL_OUT,
	SPTM_PRI_MAX,

	N_CONNECT_T1,
	RELAY,
	TRAFFIC,
	NO_TRAFFIC,
	I_DISCONNECT,
	I_RESET,
	I_CONGESTED,
	I_UNCONGESTED,
	I_RESET_REQ,
	SP_PRI_MAX,
}
SP_Pri;

/*
   *  /SCOC upper layer primitive parameters
   *
   *  /CDA :  Called address  CGA : Calling address  
   *  /CI  :  Connection identification
   *  /CRS :  Confirm request slecttion 
   *  /EDS :  Expedited data selection
   *  /QOS :  Quality of service parameter set
   *  /OR  :  Originator      RA  : Responding address
   *  /RCS :  Receipt confirmation selection                 
   *  /REA :  Reason          OR  : Originator 
   *  /RR  :  Return Resaon   SEQ : Sequence Control  
   *  /UD  :  User data       RO  : Return Optinal selection 
   *
 */

typedef struct SCCP_QUALITY_OF_SERVICE
{
    //reserved
    u8  uQOS;
}
SP_QOS;                         //Quality of service parameter set

typedef enum SCCP_ORIGINATOR
{
    NSP,                        //the network service provider
    NSU,                        //the network service user
    UNDEFINED,                  //undefined
}
SP_OR;                          //Originator

typedef struct SCCP_REQUEST_CONFIRM_SELECTION
{
    //reserved
    u8  uRCS;
}
SP_RCS;                         //Confirm request slecttion

/*
   *  Reason parameter
   *
   *  Note: coGetReasonStr(u8 Reason , char *pReasonStr)
   *         
 */

typedef enum SCCP_REASON
{
    //reason : originated network serice provider
    REA_PDISC_ACNN,             //Disconn ¨Cabnormal condition of non-transient nature
    REA_PDISC_ACTN,             //Disconn ¨Cabnormal condition of transient nature
    REA_PDISC_IS,               //Disconn ¨Cinvalid state1
    REA_PDISC_RIP,              //Disconn -release in progress1
    REA_PCREF_DAU,              //CREF ¨Cdestination address unknown(non-transient condition)
    REA_PCREF_DINC,             //CREF2 ¨Cdestination inaccessible/non-transient condition
    REA_PCREF_DITCs,            //CREF2 ¨Cdestination inaccessible/transient condition
    REA_PCREF_QNANC,            //CREF2 ¨CQOS not available/non-transient condition
    REA_PCREF_QNATC,            //CREF2 ¨CQOS not available/transient condition;
    REA_PCREF_RUNC,             //CREF2 ¨Creason unspecified/non-transient condition
    REA_PCREF_RUTC,             //CREF2 ¨Creason unspecified/transient condition;
    REA_PCREF_LE,               //CREF2 ¨Clocal error1;
    REA_PCREF_IS,               //CREF2 ¨Cinvalid state1;
    REA_PCREF_NT,               //CREF2 ¨Cno translation1;
    REA_PCREF_IRP,              //CREF2 ¨Cin restart phase1;
    REA_PCREF_HCV,              //CREF2 ¨Chop counter violation.

    //reason : originated network serice user
    REA_UDISC_NC,               //Disconn ¨Cnormal condition;
    REA_UDISC_ABC,              //Disconn ¨Cabnormal condition;
    REA_UDISC_EUC,              //Disconn ¨Cend user congestion;
    REA_UDISC_EUF,              //Disconn ¨Cend user failure;
    REA_UDISC_SUO,              //Disconn ¨CSCCP user originated;
    REA_UDISC_ACC,              //Disconn ¨Caccess congestion;
    REA_UDISC_AF,               //Disconn ¨Caccess failure;
    REA_UDISC_SC,               //Disconn ¨Csubsystem congestion;
    REA_UCREF_NTC,              //CREF2 -non-transient condition;
    REA_UCREF_TC,               //CREF2 -transient condition;
    REA_UCREF_IIIN,             //CREF2 -incompatible information in NSDUs;
    REA_UCREF_EUO,              //CREF2 -end user originated;
    REA_UCREF_EUC,              //CREF2 -end user congestion;
    REA_UCREF_EUF,              //CREF2 -end user failure;
    REA_UCREF_SUO,              //CREF2 ¨CSCCP user originated;
    REA_UCREF_ACC,              //CREF2 ¨Caccess congestion;
    REA_UCREF_AF,               //CREF2 ¨Caccess failure;
    REA_UCREF_SC,               //CREF2 ¨Csubsystem congestion.

    //Notice service reason : N-inform values
    REA_NINFO_FAIL,             //N-Inform ¨C network service provider failure;
    REA_NINFO_CONG,             //N-Inform ¨C network service congestion;
    REA_NINFO_PQC,              //N-Inform ¨C network service provider QOS change;
    REA_UINFO_FAIL,             //N-Inform ¨C network service user failure;
    REA_UINFO_CONG,             //N-Inform ¨C network service user congestion;
    REA_UINFO_PQC,              //N-Inform ¨C network service user QOS change;
    REA_INFO_USPC,              //N-Inform ¨C reason unspecified.

    REA_UNDEFINED,              //undefined
}
SP_REA;                         //Reason

typedef struct SCCP_RETURN_OPTINAL
{
    //reserved
    u8  uRO;
}
SP_RO;                          //return Optinal

typedef struct SCCP_RETURN_REASON
{
    //reserved
    u8  uRR;
}
SP_RR;                          //Return Reason

typedef struct SCCP_SEQUENCE
{
    //reserved
    u8  uSEQ;
}
SP_SEQ;                         //Sequence control

#define SP_MAX_UD 256

typedef struct SCCP_USER_DATA
{
    u8  uDataLen;
    u8  aUserData[SP_MAX_UD];
}
SP_UD;                          //User data

typedef union SCCP_UI_PRIMITIVE_UNION
{
    struct PriNUnitDataReq      //reserved for sclc ,not used now
    {
        u8   uSLS;
        SP_SEQ tSEQ;
        SCCP_ADDR tCDA;
        SCCP_ADDR tCGA;
        SP_RO tRO;
        SP_UD tUD;
    }
    tPriNUDataReq;

    struct PriNUnitDataInd      //reserved for sclc  ,not used now
    {
        u8    uSLS;
        SP_UD tUD;
        SCCP_ADDR tCDA;
        SCCP_ADDR tCGA;
    }
    tPriNUDataInd;

    struct PriNNoticeInd        //reserved for sclc  ,not used now
    {
        SP_RR tRR;
        SP_UD tUD;
        SCCP_ADDR tCDA;
        SCCP_ADDR tCGA;
    }
    tPriNNoticeInd;

    struct PriNConnectReq
    {
        //Mandatory            
        SCCP_ADDR tCDA;
        SP_QOS tQOS;
        //Optianal
        u8  uOptFlag;
        u8  tEDS;
        u8  uImp;
        SCCP_ADDR tCGA;
        SP_UD tUD;
    }
    tPriNConnReq;

    struct PriNConnectInd
    {
        //Mandatory
        SCCP_ADDR tCDA;
		SP_QOS tQOS;
		u8	aSLR[SP_REF_LEN];
		u8  uSLS;
		u32 OPC;
		u8	NetID;

        //Optianal
        u8  uOptFlag;
		u8  uImp;
        SCCP_ADDR tCGA;
        SP_UD tUD;
    }
    tPriNConnInd;

    struct PriNConnectRsp
    {
        //Mandatory
        SP_QOS tQOS;

        //Optianal
        u8  uOptFlag;
        u8  tEDS;
        u8  uImp;
        SCCP_ADDR tRA;
        SP_UD tUD;
    }
    tPriNConnRsp;

    struct PriNConnectCfm
    {
        //Mandatory
        SP_QOS tQOS;

        //Optianal
        u8  uOptFlag;
        u8  uImp;
        SCCP_ADDR tRA;
        SP_UD tUD;
    }
    tPriNConnCfm;

    struct PriNDisconnectReq
    {
        //Mandatory
        //SP_OR       eOR;  //always NSU
        SP_REA eREA;

        //Optianal
        u8  uOptFlag;
        u8  uImp;
        SCCP_ADDR tRA;
        SP_UD tUD;
    }
    tPriNDisconnReq;

    struct PriNDisconnectInd
    {
        //Mandatory
        SP_OR eOR;
        SP_REA eREA;

        //Optianal
        u8  uOptFlag;
        u8  uImp;
        SCCP_ADDR tRA;
        SP_UD tUD;
    }
    tPriNDisconnInd;

    struct PriNDataReq
    {
        //Mandatory
        SP_UD tUD;

        //Optianal
        u8  uImp;
    }
    tPriNDataReq;

    struct PriNDataInd
    {
        //Mandatory
        SP_UD tUD;

        //Optianal
        u8  uImp;
    }
    tPriNDataInd;

    struct PriNDataAkReq
    {
    }
    tPriNDataAkReq;

    struct PriNDataAkInd
    {
    }
    tPriNDataAkInd;

    struct PriNEDataReq
    {
        SP_UD tUD;
    }
    tPriNEDataReq;

    struct PriNEDataInd
    {
        SP_UD tUD;
    }
    tPriNEDataInd;

    struct PriNResetReq
    {
        //SP_OR     tOR;  //always NSU
        SP_REA eREA;
    }
    tPriNResetReq;

    struct PriNResetInd
    {
        SP_REA eREA;
        SP_OR tOR;
    }
    tPriNResetInd;

    struct PriNResetRsp
    {
    }
    tPriNResetRsp;

    struct PriNResetCfm
    {
    }
    tPriNResetCfm;

    struct PriNInformReq
    {
        SP_SEQ tQOS;
        SP_REA eREA;
    }
    tPriNInformRsp;

    struct PriNInformInd
    {
        SP_SEQ tQOS;
        SP_REA eREA;
    }
    tPriNInformInd;
}
SP_UiPriUnion;

typedef struct SCCP_UI_PRIMITIVE_PARAMETERS
{
    u8  uUiPri;
    u8  uAnsiFlag;
    u16 wConnId;                //return by SCCP while PostSp for N_CONN_REQ
	SP_UiPriUnion tPriUnion;
}
SP_UiPriPara;

///////////////////////////////////////////////////////////////////////////
//
// Name     : PostSp
// Function : Upper layer post request/response primitive to sccp
// Parameter: pUiPriParam [sccp UL primitive buffer pointer]
// Note     : Sccp Connid is implicit returned in "pUiPriParam" buffer  
//          : while N-Connect requesing 
// Return   : 0 Post Fail   1 Post Successful
//   
///////////////////////////////////////////////////////////////////////////
int PostSp ( SP_UiPriPara * pUiPriParam );

///////////////////////////////////////////////////////////////////////////
//
// Name     : SpSubmit
// Function : Upper layer fetch indicate/confirm primitive submited from sccp
// Parameter: pUiPriParam [sccp UL primitive buffer pointer]
//            uUlSapId [upper layer sap id [0 tcap 1 pps 2 smsc 3 aif 4 ranap 5 reserved] ]
// Return   : 0 Fetch Fail   1 Fetch Successful
//
///////////////////////////////////////////////////////////////////////////
int SpSubmit ( SP_UiPriPara * pUiPriParam, u8 uUlSapId );

/////////////////////Below is reserved, do not need to read/////////////////////

/*
 * \Inter-Layer Communication interface mode
 * \
 * \Loose coupling mode : 
 *        interface implementation based on message pool engine
 * \Tight coupling mode : 
 *        interface implementation based on function call and callback
 *
 * \Note : In order to be compatible with old user , use Loose coupling mode now
 * 
 */

#define LOOSE_COUPLING_MODE  0  //Loose coupling mode
//#define TIGHT_COUPING_MODE

#ifdef LOOSE_COUPLING_MODE      //Loose coupling mode

#else

#ifdef  TIGHT_COUPING_MODE      //Tight coupling mode

#error "Do not support Tight coupling mode ,please use \"LOOSE_COUPLING_MODE\" flag \n"

/*
 * \CFS(CallBack function Set) for SCCP sumbit primitives to SCCP user
 *
 * \The following Callback Fucntion set define the mapping of the primitives
 * \which is submited to SCCP serivce user(s). It is used in tight coupling mode.
 *
 * \User A : Reserved for ISUP
 * \User B : Q.711 Page 2 user part B not define
 * \User C : Other SCCCP user e.g. AIF
 */

typedef struct SCCP_SUBMIT_USERA_CFS
{
    //For Isup ,Not supported now
}
SP_UserA_CFS;

typedef struct SCCP_SUBMIT_USERB_CFS
{
    //NULL Undefined in Q.711
}
SP_UserB_CFS;

typedef struct SCCP_SUBMIT_USERC_CFS
{
    void ( *spCBUi_N_UnitDataInd ) ( SCCP_ADDR * pCDA, SCCP_ADDR * pCGA, SP_UD * pUD );

    void ( *spCBUi_N_NoticeInd ) ( SCCP_ADDR * pCDA, SCCP_ADDR * pCGA, SP_RR * pRR, SP_UD * pUD );

    void ( *spCBUi_N_ConnectInd ) ( SP_QOS * pQOS, SP_UD * pUD, u8 uCI );

    void ( *spCBUi_N_ConnectCfm ) ( SP_QOS * pQOS, SP_UD * pUD, u8 uCI );

    void ( *spCBUi_N_DisconnectInd ) ( SP_OR * pOR, SP_OR * pRA, SP_REA * pREA, SP_UD * pUD, u8 uCI );

    void ( *spCBUi_N_DataInd ) (  );

    void ( *spCBUi_N_DataAkInd ) (  );

    void ( *spCBUi_N_EDataInd ) (  );

    void ( *spCBUi_N_ResetInd ) ( SP_OR * pOR, SP_REA * pREA, u8 uCI );

    void ( *spCBUi_N_ResetCfm ) (  );

    void ( *spCBUi_N_InformInd ) (  );
}
SP_UserC_CFS;

#endif

#endif
/////////////////////Above is reserved, do not need to read/////////////////////

#endif
