/***********************************************************
File Name:		isdn_rm.h
Description:	ISDN Resource Management declaration
Version:		v9.0.0
Author:			Gengxin Chen
Create Date:	2008-1-23
************************************************************/
#ifndef _ISDN_RM_H
#define _ISDN_RM_H

#include "isdn_if.h"
#include "isdn_inc.h"

/************************************************************
ISDN Resource structure
************************************************************/
#define ISDN_MAX_SAP				16
#define ISDN_MAX_CG				256
#define ISDN_MAX_CIRCUIT			256
#define ISDN_MAX_PORT				8192
#define ISDN_CIRCUIT_CIC			32
/*
typedef struct _isdn_cg_attrib_
{
//	u8						variant_type;
	u8						priority;	//0:reattempt; 1:discard
	u8						network_id;	//Network identifier
	u32						tg_id;
}ISDN_Cg_Attrib_;

typedef struct _isdn_circuit_attrib_
{
	u8						plat_id;
	u8						cic_range;
	u32						head_cic;
	u32					circuit_id;
}ISDN_Circuit_Attrib_;

typedef struct _isdn_sap_struct
{
	u8						enable;
	ISDN_Sap_Attrib_			attrib;
}ISDN_Sap_struct;

typedef struct _isdn_cg_struct
{
	u8						enable;
	u8						sap_id;
	u8						circuit_num;
	u8						circuit_used[ISDN_MAX_CIRCUIT];
	Cg_Attrib_struct			attrib;
}ISDN_Cg_struct;

typedef struct _isdn_circuit_struct
{
	u8						enable;
	u16						cg_id;
	u8						user_network_if;
	u8						interface_id;
	u8						restart_clas;	//restart indicator class
	u8						lk3_status;
	u8						lk2_status;
	u8						dc_status;		//ansi maintenance D-channel status
	u8						heartbeat_time;
	Circuit_Attrib_struct		attrib;
}ISDN_Circuit_struct;
*/


typedef struct _isdn_cic_state_
{
	u8						call_state;
	u8						maintenance_state;	//ansi maintenance B-channel state		blo_state
}ISDN_CIC_state_;

typedef struct _isdn_fsm_state_
{
	int						cpc_state;
	int						m_state;	//bls_state and blr_state
	
}ISDN_Fsm_state_;

typedef struct _isdn_link_struct
{
	u8						enable;
//	u8						circuit_id;
	u8						restart_clas;	//restart indicator class
	u8						lk3_status;
	u8						lk2_status;
	u8						dc_status;		//ansi maintenance D-channel status
	u16						plat_heartbeat_time;		//to another plat
	u16						link_heartbeat_time;		//from iua 
}ISDN_Link_struct;

typedef struct _isdn_port_struct
{
	u8						enable;

	u16						call_ref;
	u8						callout_fg;	//最高位, 辨别是主叫发起的还是别叫发起的
	u16						timer_flag;
	u32						w_time;
	u32						su_proc_id;		//for normal call

	u8						pre_send_msg;
	u8						msg_cmd;
	u8						primitive_cmd;
	u8						g_pri_cmd;
	u8						timeout_fg;		//0:never timeout,  1:once timeout
	u32						cic_val;
	
	ISDN_CIC_state_			cic_state;
	ISDN_Fsm_state_			fsm_state;
	
	int						trace_flag;
}ISDN_Port_struct;

typedef struct _isdn_attrib_struct
{
	u8						systemID;
	u8						isdn_run_mode;
	u32						isdn_remote_ip;
}ISDN_Attrib_struct;


typedef struct _isdn_resource_pond
{
//	ISDN_Sap_struct			sap_pond[ISDN_MAX_SAP];
//	ISDN_Cg_struct			cg_pond[ISDN_MAX_CG];
//	ISDN_Circuit_struct		circuit_pond[ISDN_MAX_CIRCUIT];
	ISDN_Link_struct			link_pond[ISDN_MAX_CIRCUIT];
//	u8						e1_start;
	ISDN_Port_struct		port_pond[ISDN_MAX_PORT];
	ISDN_Attrib_struct		attrib;
}ISDN_Resource_Pond;

ISDN_Resource_Pond isdn_rs;



/************************************************************
ISDN Resource functions interface
************************************************************/
u32 find_port_by_callref(u16 cref, u16 circuit_id);
extern int find_port_by_sap(Pst *pst);
extern u32 isdn_assign_port(u16 circuit_id);
extern u32 find_port_by_cic(u32 cic, u16 circuit_id);
extern int find_circuit_by_interfaceId(int cg_id, u8 interface_id);


#endif
