/********************************************************************
Copyright ?2007 LGC Wireless, Inc. All rights reserved
File Name: 		aifg_var_ext.h
Description:	Public variant definition of AIFG module
Version:		v9.0.0
Author:			Roy Jiang
Create Date:	2007-3-12

History:
2007-3-6		v9.0.12	Create
*********************************************************************/
#ifndef _WXC2_AIFG_VAR_EXT_H
#define _WXC2_AIFG_VAR_EXT_H
#include <assert.h>
#include "aifg_type_def.h"

//Variant declaration
extern aifg_circuit_group cg[AIFG_MAX_CG];
extern aifg_sap sap[AIFG_MAX_SAP];
extern aifg_dual_server dual_server;
extern aifg_port aifg_pcb[AIFG_MAX_PORT];
extern aifg_event_code aifg_event;
extern aifg_msg_t sd_msg;
aifg_msg_pre_decoded rv_msg;
extern int cur_port;	//current processing port
extern aifg_link_info link_info[SCCP_MAX_LINK];

extern int msg_statistics[AIFG_MAX_MESSAGE][2];

int aifg_ie_encode(aifg_msg_protocol protocol, int ie_id, ie_u *src, BYTE *dst, int m_o_flag);
int aifg_ie_decode(aifg_ie_ptr *src, aifg_ie *dst);
int aifg_msgtype_to_localid(aifg_pd pd, int msg_type);

int aifg_send_cr(int sapid, int cgid, aifg_msg_t *msg);
void aifg_send_dt1(int linkid, aifg_msg_t *msg, int ti);
void aifg_send_udt(int cgid, aifg_msg_t *msg, SP_UiPriPara *buf_ptr);

void aifg_mpp_init();
int aifg_mpp_proc();

void aifg_port_proc(aifg_port *pPort, aifg_msg_t *upper_msg, aifg_msg_pre_decoded *peer_msg);
inline int aifg_port_assign(int sapid, int cgid, int linkid);
inline void aifg_port_release(aifg_port *pPort);
inline int aifg_get_local_port(int u_port);
inline int aifg_get_paging_port(int cgid, BYTE *imsi_ptr, int imsi_len);
inline int aifg_ti2lport(int ti, int link_id, int pd);

inline int aifg_get_link(int u_port);
inline int aifg_add_link(int linkid, int sapid);
inline int aifg_del_link(int sccp_link_id);
inline void aifg_link_release(int link_id);
inline aifg_link_info *aifg_get_link_info(int link_id);

inline int aifg_get_cg(int dpc, int ni);

inline void aifg_add_ti(int link_id, int ti, int ti_type, int port);
inline int aifg_get_ti(int link_id, int port, int ti_type);
inline int aifg_del_ti(int link_id, int ti, int ti_type);

void aifg_send_rlsd(int linkid);

void aifg_debug_init();
void aifg_debug_timer();
void aifg_debug_print(int port, aifg_event_code event, void *msg, int o_info);

void aifg_log(char *info);
#endif

