/************************************************/
/*Title:        scfmsg.h                            */
/*Descr:        WXC2R7.0-XAP Specification          */
/*Author:       Liang Hongbin                       */
/*Create:       2003-9-17                           */
/*Modify:                                       */
/************************************************/

#include "../../../xapp/src/capp/cap_head.h"
#include "../../../tcap/src/include/tcap_public.h"

#ifndef _SCF_MESSAGE
#define _SCF_MESSAGE

#define   SCF_MAX_DLG_NUM	MAX_DIALOGUEID
#define   SCF_OPEN_LEN       	128
#define   SCF_PORT_LEN	     	4
#define   CAP_CONTENT_LEN       256
/*************************************/
/*Macro----------------------------->*/
/*************************************/

typedef struct _CAP_Message
{
        unsigned char	msgLength[2];           /* unsigned char0 is the higher part */
        unsigned char	msgServiceCode;         /* fixed as 0xAF */
        unsigned char	port_id[3];             /* unsigned char 0 is the higher part,unsigned char 1 is the lower part ,and unsigned char 2 is reserved */
        unsigned char	dialogue_id[3];
        unsigned char	msgOperaCode;           /* message type code ,e.g , InitialDP = 0x00 */
        unsigned char	msgOperaType;           /* 1/2/3/4 = request, indicate, response, confirm */
        unsigned char	msgContent[CAP_CONTENT_LEN];
        /* if the message if cap operation ,then the first unsigned char of msgContent is invoke id */
}CAP_Message, *PCAP_Message;

typedef struct _SCF_Open_Buffer
{
        unsigned char   msgReadSub;
        unsigned char   msgWriteSub;
        CAP_Message 	msgList[SCF_OPEN_LEN];   
}SCF_Open_Buffer, *PSCF_Open_Buffer;

typedef struct _SCF_HPort_Buffer
{
	unsigned char	msgReadSub;
	unsigned char	msgWriteSub;
	CAP_Message	msgList[SCF_PORT_LEN];
}SCF_HPort_Buffer, *PSCF_HPort_Buffer;

typedef struct _SCF_Port_Buffer
{
        SCF_HPort_Buffer inBuffer;   /* PPS-SCSM */
        SCF_HPort_Buffer outBuffer;  /* SCSM-PPS */
}SCF_Port_Buffer, *PSCF_Port_Buffer;

typedef struct _SCF_Buffer
{
	SCF_Open_Buffer	openBuffer;
	SCF_Port_Buffer	portBuffer[SCF_MAX_DLG_NUM];
}SCF_Buffer, *PSCF_Buffer;


enum _SCSM_STATE
{
	SCF_IDLE=0,
	SCF_INIT,
	SCF_PREPARING_SSF_INSTRUCTIONS,
	SCF_QUEUING_FSM,
	SCF_WAITING_NOTIFICATION_OR_REQUEST,
	SCF_DETERMINE_MODE,
	SCF_WAITING_DISCONNECT_FORWARD_CONNECT,
	SCF_WAITING_PLAYANNOUNCEMENT,
	SCF_VPS_PROC,
	SCF_SEND_END,
}SCSM_STATE;

//#define   MAX_EDP_NUM	19

typedef struct _SCSM_DATA
{        
    unsigned char   State;
    unsigned short  portid;  /* PPS port id */
    unsigned int	Tinit;   /* Timer waiting for InitialDP */
    unsigned int	Twm;	 /* Timer waiting for message */
    unsigned int    Tscf_ssf;
    unsigned int	Tassist;
	unsigned char	FirstResponse;
	unsigned char	endFlag;
	unsigned char	acn;
	unsigned char	acn_v;
    unsigned char	Tscf_ssfExpiryTimes;
    unsigned char	Pending;
    unsigned char	EDPs;
    unsigned char	EDP_flag[MAX_EDP_NUM];
	unsigned char	invokeid;
}SCSM_DATA;

/*** functions provided by SCSM ***/
int	PutScfOpen(CAP_Message cap_message);
int	GetScfOpen(PCAP_Message pcap_message);
int	PutScfMsg(CAP_Message cap_message);  /* SCSM -> PPS */
int	GetScfMsg(PCAP_Message pcap_message, unsigned short dlgid); /* SCSM <- PPS*/
int	WriteScfMsg(CAP_Message cap_message); /* PPS -> SCSM */
int	ReadScfMsg(PCAP_Message pcap_message, unsigned short dlgid); /* PPS <- SCSM */
int 	ClearPortSub(unsigned short dlgid);
#endif
