#ifndef ppsParam_H
#define ppsParam_H
#include <sys/types.h>

#include "crd.h"
#include "ppsMibTable.h"
#include "voiceID.h"

#define		MSISDN_LENGTH			11




typedef enum _SERVICE_KEY
{
	HELP=0,
	INQUIRY_SERVICE,
	SCRATCH_CARD_RECHARGE,
	CREDIT_CARD_RECHARGE,
	FAVORITE_NUMBER_SERVICE,
	LANGUAGE_MANAGEMENT,
	PIN_MANAGEMENT,
	SERVICE_9,
	SERVICE_10,
	SERVICE_11,
}SERVICE_KEY;


typedef struct _file_operation
{
	u_char		uploadUserData;
	u_char		uploadPrepaidCard;
   	u_char		uploadTariffPlan;
   	u_long		nextTariffStartTime;
}PPSFileOperation;

enum _statistics_enum{
    MIBPPS_CAPOPEN = 0,
	MIBPPS_INITIALDP ,
    MIBPPS_REQUESTBCSM,
    MIBPPS_APPLYCHARGING,
	MIBPPS_CONTINUE,
	MIBPPS_ACTIVITYS,
	MIBPPS_ACTIVITYR,
    MIBPPS_REPORTBCSM,
    MIBPPS_CHARGINGREPORT,
	MIBPPS_ANSWERED,
	MIBPPS_DISCONNECT,
	MIBPPS_RELEASECALL,
	MIBPPS_INQUIRE,
	MIBPPS_RECHARGE,
   	MIBPPS_READCARD,
	MIBPPS_READCARDRSP,
	MIBPPS_WRITECARD,
	MIBPPS_WRITECARDRSP,
	MIBPPS_PLAYANNOUNCE,
	MIBPPS_ACCOUNTINFO,
	MIBPPS_ACCINFOACK,
	MIBPPS_CDRNUMBER,
	MIBPPS_CSTANUMBER,
	MIBPPS_CDROVERFLOW,
	MIBPPS_BLACKLIST,
    MIBPPS_SUSPEND,
    MIBPPS_INITIALDP_SMS,
    MIBPPS_REQUEST_SMS,
    MIBPPS_CONTINUE_SMS,
    MIBPPS_REPORT_SMS,
    MIBPPS_RELEASE_SMS,
	MIBPPS_CONFERENCE,
	MIBPPS_THIRD_PARTY,
	MIBPPS_CONNECT_TO_RESOURCE,
	MIBPPS_PLAY_ANNOUNCEMENT,
	MIBPPS_EST_TMP_CNT,
	MIBPPS_AST_INS,
	MIBPPS_PCUI,
	MIBPPS_PCUI_RES,
	MIBPPS_SPE_RUS_RPT,
	MIBPPS_DISCNT_FWD_CNT,
	MIBPPS_SM_INQUIRY,
	MIBPPS_SM_RECHARGE,
};

typedef struct _msg_statistics_ 
{
    u_long  CapOpen;
	u_long  Initialdp[2];
    u_long  RequestBCSM[2];
    u_long  ApplyCharging[2];
	u_long  Continue[2];
	u_long  ActivityS;
	u_long	ActivityR;
    u_long  ReportBCSM[2];
	u_long  ChargingReport[2];
	u_long  Answered[2];
	u_long  Disconnect[2];
	u_long  Releasecall[2];
	u_long  Inquire;
	u_long  Recharge;
    u_long  ReadCard;
	u_long  ReadCardRsp;
	u_long  WriteCard;
	u_long  WriteCardRsp;
	u_long  Playannounce;
	u_long  Accountinfo;
	u_long  Accinfoack;
    u_long  InitialDP_SMS;
    u_long  Request_SMS;
    u_long  Continue_SMS;
    u_long  Report_SMS;
    u_long  Release_SMS;    
	u_long	Conference;
	u_long	ThirdParty;
	u_long	ConnectToResource;
	u_long  PlayAnnouncement;
	u_long	EstablishTemporaryConnection;
	u_long	AssistInstructions;
	u_long	PCUI;
	u_long	PCUI_rsp;
	u_long	SpecialResourceReport;
	u_long	DisconnectForwardConnection;
	u_long	smInquiry;
	u_long    smRecharge;
	u_long	send_sync[4];
	u_long	recv_sync[4];
	u_long	update_card_request;
	u_long    update_card_error_msg;
	u_long    update_card_ok;
	u_long    update_card_no_card;
	u_long    update_card_used;
	u_long    update_card_expired;
	u_long    update_card_sys_failure;
	char		ussd_operation_date[7][16];
	u_long	ussd_operation[7][3*4]; /* 7*3 */
}_msg_statistics;

typedef struct _measurement
{
	u_long	cdrnumber;
	u_long  balance;
	u_long  duration;
	u_long  cstanumber;
	u_long  cdroverflow;
    u_long  blacklist;
    u_long  suspend;
    u_long  usernumber;
//    u_long  headnumber;
    u_char  user_number[8];
	u_long	peer_usernumber;	
//    u_char  head_prefix[1000][4];
	u_int	free_index;
	u_long  cardnumber;
	u_long  cardheadnumber;
	u_char  card_number[8];
	u_char  card_prefix[2000][4];
	u_long  sysCapability;
	u_char  sys_capability[4];
	u_char  licensed_user[4];
	u_char	index_alarm;
	u_int	search_table_result[4];
	u_char	mt_release_flag;
}_measurement;

typedef struct _display	
{
	char    sysState;
	char	   peer_state;
	char	   peer_state_counter;
	char    dataSrc;
	char    initProgress;
	char    control_state;
	u_long masterIP;
	char    rechargeDigitals[8];
	char    inquiryDigitals[8];
	u_short proc_used;
	u_short proc_begin[7];
	u_short ro_used;
	u_short gy_used;
	u_long  totalCharge;	
	u_long  control_state_ts;
	char    asciiIn[128];
	char	   asciiOut[8192];
	char	   reserved0[8192];
	int	   reserved1[8192];
	long	   reserved2[8192];
}_display;

typedef struct _debug_mib
{
	_msg_statistics msgstatistics;
	_measurement	measurement;
	u_char			watch_dog[4*16];
	int				report_sum[7][4];
	_display	    display;
}_debug_mib;

// fix multiple definition====================================
extern _debug_mib  debugmib;
//

typedef struct _PpsParam
{
	u_char				ppsNumber[MSISDN_LENGTH];    /* byte0 = length */
   	u_char				smscNumber[MSISDN_LENGTH];
   	u_char				esmeNumber[MSISDN_LENGTH];	

	u8					param_ver;
   	u8					reserve[127];
	
	PpsServiceConrol	serviceControl;	
	VmsRouteParam	routeParam;
	PPSFileOperation	fileOperation;	
	PpsTable			ppsTables;
	u_long			rcm_ip;
	int				max_call_duration;
	long				max_quota_per_request;
	int				scf_work_as_adaptor;
	int				scf_work_as_adaptor_with_vcs;	
	int				data_quota_as_postpaid;
	int				new_flags[31];
	_ocsCRMConrol	ocs_crm_control;
}PPSParamStruct;


int SetDefaultParam();
int DecodePPSAsciiIn(int pageno, char *cmd);
int GetCDR_Record();

void  SetLoadFileFlag(int dataID);
void  AddPPSStatistics(int index,int dir);

int pps_debug_set();
int GetCSTA_Record();
int GetMO_CDR();
int GetMT_CDR();
int ppsDeubgRt();
int pps_smppInit();
int PeerServerRamInitRequest(u_char oidLen, DWORD *oid,
							 u_char *pdata,BYTE *vartype);
int reportCDRIncrement(int calltype,int duration, float charge,ulong gprsVolume);
int SetCSTASyncFlag(int instance);

void PrepaidAction();
int  MessageProc();
void CallProc();
int  SystemInit();
int  WaitingforAnsweredProc(u_short);
int  BeatTrans();
void SetServerFlag(int flag);
int  SetServerID();
void SetActiveDataServer(int flag);
void TariffPlanProc();
void PeriodicChargeProc();
void CheckLoadFile();
void SysGuard(int sig);
void ReleaseAll(u_short portid);
int  RequestBCSMEvent(u_short portid);
int  WaitingForInitialDP(u_short portid);
int  WaitingForEventsReport(u_short portid);
int  ppsBackupRamDataToFile();
int  ppsBackupRamDataToOMCServer();
void PeriodicSyncRamData();
int  smppMonitor();
void capMessageProc();
int  SyncDailyReport();
int  ReadDataFromOMCServer();
int  LoadDataFromBackfile();
int  ReadDataFromPeerSever();
int  ReadPeroidicSyncData();
int  LoadPPSParam();
int  ppsInitCSTA();
void DisplayVoiceOperationCode();
int  UserHeadIncrement();
int  UserNumberIncrement();
int  UserHeadDecrement();
int  UserNumberDecrement();
int  ReadTariffDataFromFile(int  tbindex);
int  ReadIvrSyntaxDataFromFile(FILE *fp);
int  ReadDigitalSyntaxDataFromFile(FILE *fp);
int  WaitingforAnsweredProc(u_short portid);
int  WaitingForEventsReport(u_short portid);
int  ReleasePortStatus(u_short invoke_id);
int  ConferenceRequest(u_char oidLen, DWORD *oid,
					  u_char *pdata,u_short dataLen);















































#endif
