#ifndef _PSTN_CLIENT_H
#define _PSTN_CLIENT_H

#define MAX_COMMAND_LEN    2048
#define MAX_PSTN_PROCS		8
#define MSG_TIMER			6000
#define MSG_WAIT_TIMER	      400
#define MSG_WAIT_LTIMER	1600

#define MAX_SLOTS			100


typedef struct msan_param_t
{
	u_char server_enable;
	char server_ip[16];
	u_short server_port;
	char user_name[16];
	char password[16];
}_msan_param_t;

typedef struct pair_2_slot_param_t
{
	int used;
	int pair_group; /* every 64 pairs is a group */
	int msan_id; /*1/2 */
	int slot_id;   /* paris are mapped to :  slot+port */
}_pair_2_slot_param_t;

typedef struct pstn_server_param_t
{
	char local_ip[16];
	u_short local_port;
	u_char server_enable;
	char server_ip[16];
	u_short server_port;
	char user_name[16];
	char password[16];

	int krone_pair_id_in_crm;
	int ss_entry_id_in_crm;
	
	_msan_param_t   msan[2];
	_pair_2_slot_param_t  pair_slot_info[MAX_SLOTS];
	
}_pstn_server_param_t;

typedef enum PORT_STATE
{
	PS_NULL,
	PS_CREATE,
	PS_UPDATE,
	PS_DELETE,
	PS_BAR_OUT,
	PS_UNBAR_OUT,
	PS_BAR_IN,
	PS_UNBAR_IN,
	PS_CREATE_MSAN,
	PS_DELETE_MSAN,
	PS_RELEASE,
}_PORT_STATE;

typedef enum PORT_CRT_STATE
{
	PCS_NULL,
	PCS_INIT,
	PCS_ECHO,
	PCS_LOGIN,
	PCS_PSSWD,
	PCS_NOGUI,
	PCS_QUERY_DSTN,
	PCS_ENTRY,
	PCS_STATION,
	PCS_DSTN,
	PCS_NAME,
	PCS_SIGNAL,
	PCS_SIP_USER,
	PCS_VOIP_GRP,
	PCS_TOLL,
	PCS_EXTI,
	PCS_ACTIVE,
	PCS_LOGOUT,
	PCS_LOGOUT_AGAIN,
	PCS_TRANS_TO_MSAN,
//	PCS_ENTRY,
//	PCS_VOIP_GRP,
	
	PCS_MAX,
}_PORT_CRT_STATE;

typedef enum PORT_UPDATE_STATE
{
	PUS_NULL,
	PUS_INIT,
	PUS_LOGIN,
	PUS_PSSWD,
	PUS_NOGUI,
	PUS_DSTN,	
	PUS_TOLL,
	PUS_LOCKI,
	PUS_EXTI,
	PUS_ACTIVATE,
	PUS_LOGOUT,
	PUS_MAX,
}_PORT_UPDATE_STATE;

typedef enum PORT_DEL_STATE
{
	PDS_NULL,
	PDS_INIT,
	PDS_LOGIN,
	PDS_PSSWD,
	PDS_NOGUI,
	PDS_DSTN,
	PDS_ENTRY,
	PDS_DEL,	
	PDS_EXTI,
	PDS_LOGOUT,
	PDS_LOGOUT_AGAIN,	
	PDS_MAX,
}_PORT_DEL_STATE;


typedef enum MSAN_CRT_STATE
{
	MCS_NULL,
	MCS_INIT,
	MCS_ECHO,
	MCS_LOGIN,
	MCS_PSSWD,
	MCS_CREATE,
	MCS_BRING_UP,
	MCS_SAVE,
	MCS_EXIT,
	MCS_WAIT_EXIT,
	MCS_MAX,
}_MSAN_CRT_STATE;

typedef enum MSAN_DEL_STATE
{
	MDS_NULL,
	MDS_INIT,
	MDS_LOGIN,
	MDS_PSSWD,
	MDS_DELETE,
	MDS_BRING_DOWN,
	MDS_SAVE,
	MDS_LOGOUT,
	MDS_MAX,
}_MSAN_DEL_STATE;



typedef enum PSTN_PROV_CMD
{
	PC_NULL,
	PC_CREATE,
	PC_UPDATE,
	PC_DELETE,
	PC_BAR,
	PC_UNBAR,
}_PSTN_PROV_CMD;

typedef struct pstn_prov_t
{
	int   command; 
	long  pre_id;
	char isdn_number[16];
	char user_name[64];
	int    ss_entry;
	int   krone_pair_id;
	int   msan_id;
	int	msan_slot_id;
	int   msan_slot_port_id;
	int   update_status;
}_pstn_prov_t;

typedef struct pstn_proc_t
{
	char flag;
	int   id;
	int   tcp_port_id;	
	int   state;
	int   sub_state;
	int   timer;
	int   dstn_entry;
	int   recv_msg_flag;
	int   msg_len;
	char recv_msg[MAX_COMMAND_LEN];
	_pstn_prov_t prov;
}_pstn_proc_t;


typedef struct pstn_procs_t
{
	_pstn_proc_t procs[MAX_PSTN_PROCS];
}_pstn_procs_t;

#endif
