/* 
** 
**
** file name: cdrme.h
**
** Defination for CDR(call detail record) management entity (cdrme.c).
*/

#ifndef CDRME__H
#define CDRME__H

#include "report.h"

#define MO_CDR_TYPE       0x00
#define MT_CDR_TYPE       0x01	
#define SC_CDR_TYPE       0x02// selfcare cdr
#define MAX_CDR_LEN	  8192
#define MAX_CSTA_LEN      96

typedef struct _tocdr_record {
	char      mtype[2];
	char      type[4];
	char      imsi[16];
	char      msisdn[18];
	char      msrn[18];
	char      caller[18];
	char      called[24];
	char      re[16];
	char      intkgp[6];
	char      outkgp[6];
	char      lac[10];
	char      bs[4];
	char      ss[4];
	char      mobclassmark[16];
	char      seizuretime[18];
	char      answertime[18];
	char      releasetime[18];
	char      duration[8];
	char      tcos[4];
	char      ssa[4];
	char      ssparam[16];
	char      ssr[4];
	char      cr[4];
	char      rcu[2];
	char      charge[8];
	char      balance[8];
} _tocdr_record;

typedef struct _tocdr_report {
	u_long    squence;
	BYTE      mtype;   
	BYTE      type[2];
	BYTE      imsi[8];
	BYTE      msisdn[9];
	BYTE      msrn[9];
	BYTE      caller[9];
	BYTE      called[12];
	BYTE      re[8];
	BYTE      intkgp[3];
	BYTE      outkgp[3];
	BYTE      lac[5];
	BYTE      bs[2];
	BYTE      ss[2];
	BYTE      mobclassmark[8];
	BYTE      seizuretime[9];
	BYTE      answertime[9];
	BYTE      releasetime[9];
	BYTE      duration[4];
	BYTE      tcos[2];
	BYTE      ssa[2];
	BYTE      ssparam[8];
	BYTE      ssr[2];
	BYTE      cr[2];
	BYTE      rcu;
	BYTE      charge[4];
	BYTE      balance[4];
	BYTE	cos_id;
	BYTE	gprsSgsnIP[64];
	BYTE	gprsGgsnIP[64];
	BYTE	gprsDestIP[64];
	BYTE	gprsVolume[4];
	BYTE	peerAddress[128];
	BYTE	plan_id[4];
} _tocdr_report;

/*
typedef struct _pps_cdr_buffer{
    u_short       pReadSub;
    u_short       pWriteSub;
    _tocdr_report cdr_record[MAX_CDR_LEN];  
    u_char	  flag[MAX_CDR_LEN];
}_pps_cdr_buffer;
*/
typedef struct _pps_cdr_buffer{
    u_short       pReadSub;
    u_short       pWriteSub;
    u_char	  flag[MAX_CDR_LEN];
    u_char	  cdrMsg[MAX_CDR_LEN][256]; /* byte0=len; byte1-255=msg */
}_pps_cdr_buffer;


#define		PPS_CSTA_TYPES       MAX_SERVICE_TYPE //MAX_CALL_TYPE
#define		PPS_CSTA_TYPE_BASE   100 
typedef struct _pps_csta_items
{
    	long	number;
	long	charge;
	long	duration;
	long	gprsVolume;
}_pps_csta_items;

typedef struct _pps_vas_csta_items
{
    u_long	smsNumber;
	long	smsCharge;
	u_long	mmsSendNumber;
	long	mmsSendCharge;
	u_long	mmsRetrieveNumber;
	long	mmsRetrieveCharge;
	u_long	mmsEmailNumber;
	long	mmsEmailCharge;
}_pps_vas_csta_items;

typedef struct _pps_csta_record
{
	u_long	           	timestamp;
	_pps_csta_items    	csta_type[PPS_CSTA_TYPES];
	_pps_csta_items	   	gprsCsta;
	_pps_vas_csta_items	vasCsta;
}_pps_csta_record;

typedef struct _pps_csta_buffer
{
	_pps_csta_record  csta_record[MAX_CSTA_LEN];
}_pps_csta_buffer;

// fix multiple definition====================================
extern _pps_cdr_buffer   pps_cdr_buffer;
extern _pps_csta_buffer  pps_csta_buffer;
//

int encodePPS_MO_CDR(_tocdr_report *pcdr,u_char *pdata);
int encodePPS_MT_CDR(_tocdr_report *pcdr,u_char *pdata);
#endif /* CDRME__H */
