#ifndef _M2UA_STRUCT__H
#define _M2UA_STRUCT__H

#include "m2ua_const.h"

#ifndef _LKSCTP

typedef union _m2ua_sctp_cmd
{
	union T_primitives  tpi;
	BYTE		    	cbuf[M2UA_SCTP_CMD_BUFSIZE];
}m2ua_sctp_cmd_t;

// Data Options
typedef struct _m2ua_sctp_opt_data
{
	struct t_opthdr	sid_hdr		__attribute__((packed));
	t_scalar_t	sid_val			__attribute__((packed));
}m2ua_sctp_opt_data_t;

// Connect Options
typedef struct _m2ua_sctp_opt_conn
{
	struct t_opthdr	ist_hdr		__attribute__((packed));
	t_scalar_t	ist_val			__attribute__((packed));
	struct t_opthdr	ost_hdr		__attribute__((packed));
	t_scalar_t	ost_val			__attribute__((packed));
}m2ua_sctp_opt_conn_t;

// Management Options
typedef struct _m2ua_sctp_opt_optm
{
	struct t_opthdr	nod_hdr		__attribute__((packed));
	t_scalar_t	nod_val			__attribute__((packed));
	struct t_opthdr	crk_hdr		__attribute__((packed));
	t_scalar_t	crk_val			__attribute__((packed));
	struct t_opthdr	ppi_hdr		__attribute__((packed));
	t_scalar_t	ppi_val			__attribute__((packed));
	struct t_opthdr	sid_hdr		__attribute__((packed));
	t_scalar_t	sid_val			__attribute__((packed));
	struct t_opthdr	rcv_hdr		__attribute__((packed));
	t_scalar_t	rcv_val			__attribute__((packed));
	struct t_opthdr	ckl_hdr		__attribute__((packed));
	t_scalar_t	ckl_val			__attribute__((packed));
	struct t_opthdr	skd_hdr		__attribute__((packed));
	t_scalar_t	skd_val			__attribute__((packed));
	struct t_opthdr	prt_hdr		__attribute__((packed));
	t_scalar_t	prt_val			__attribute__((packed));
	struct t_opthdr	art_hdr		__attribute__((packed));
	t_scalar_t	art_val			__attribute__((packed));
	struct t_opthdr	irt_hdr		__attribute__((packed));
	t_scalar_t	irt_val			__attribute__((packed));
	struct t_opthdr	hbi_hdr		__attribute__((packed));
	t_scalar_t	hbi_val			__attribute__((packed));
	struct t_opthdr	rin_hdr		__attribute__((packed));
	t_scalar_t	rin_val			__attribute__((packed));
	struct t_opthdr	rmn_hdr		__attribute__((packed));
	t_scalar_t	rmn_val			__attribute__((packed));
	struct t_opthdr	rmx_hdr		__attribute__((packed));
	t_scalar_t	rmx_val			__attribute__((packed));
	struct t_opthdr	ist_hdr		__attribute__((packed));
	t_scalar_t	ist_val			__attribute__((packed));
	struct t_opthdr	ost_hdr		__attribute__((packed));
	t_scalar_t	ost_val			__attribute__((packed));
	struct t_opthdr	cin_hdr		__attribute__((packed));
	t_scalar_t	cin_val			__attribute__((packed));
	struct t_opthdr	tin_hdr		__attribute__((packed));
	t_scalar_t	tin_val			__attribute__((packed));
	struct t_opthdr	mac_hdr		__attribute__((packed));
	t_scalar_t	mac_val			__attribute__((packed));
	struct t_opthdr	dbg_hdr		__attribute__((packed));
	t_scalar_t	dbg_val			__attribute__((packed));
}m2ua_sctp_opt_optm_t;

#else

typedef union _m2ua_sctp_cmd
{
	struct 	cmsghdr	 cmsg					__attribute__((packed));
	BYTE	cbuf[M2UA_SCTP_CMD_BUFSIZE]		__attribute__((packed));
}m2ua_sctp_cmd_t;

typedef struct _m2ua_sctp_data
{
	int 	len								__attribute__((packed));
	int		sid								__attribute__((packed));
	BYTE	*buf							__attribute__((packed));
}m2ua_sctp_data_t;

#endif

typedef struct _m2ua_sctp_addr
{
	uint16_t					port	__attribute__((packed));
	struct in_addr		addr	__attribute__((packed));
}m2ua_sctp_addr_t;


typedef struct _m2ua_lk_info
{
	BYTE	enable							__attribute__((packed));
	BYTE	lk_st								__attribute__((packed));
	WORD	sid									__attribute__((packed));
	DWORD	lk_timer						__attribute__((packed));
	BYTE	alarm_code					__attribute__((packed));
	BYTE	lk_act							__attribute__((packed));
}m2ua_lk_info_t;

typedef struct _m2ua_sg_info
{
	BYTE	enable				__attribute__((packed));
	BYTE	sctp_state		__attribute__((packed));
	BYTE	sctp_state_1	__attribute__((packed));
	BYTE	m2ua_state		__attribute__((packed));
	DWORD	sctp_cmd			__attribute__((packed));
	WORD	m2ua_cmd			__attribute__((packed));
	WORD	mtp3_cmd			__attribute__((packed));
	WORD	mgmt_cmd			__attribute__((packed));
	WORD 	fd						__attribute__((packed));
	WORD	iid						__attribute__((packed));
	DWORD	sid_st[8]			__attribute__((packed));
	BYTE 	*msg					__attribute__((packed));
	WORD	msg_len				__attribute__((packed));
	WORD	rem_ostrs			__attribute__((packed));
	WORD	T_ack					__attribute__((packed));
	WORD	T_r						__attribute__((packed));
	BYTE	con_sg				__attribute__((packed));
	BYTE	state					__attribute__((packed));
	BYTE	err_code			__attribute__((packed));
	BYTE	tra_hdl_mode	__attribute__((packed));
	WORD	act_lks				__attribute__((packed));
	WORD	istrs					__attribute__((packed));
	WORD	ostrs					__attribute__((packed));
	DWORD	status				__attribute__((packed));
	DWORD	seq						__attribute__((packed));
	DWORD 	cor_id			__attribute__((packed));
	WORD	up_lks_pre		__attribute__((packed));
	WORD	up_lks_cur		__attribute__((packed));
	DWORD	sg_timer			__attribute__((packed));
	BYTE	retrans_times	__attribute__((packed));
	WORD	rem_port			__attribute__((packed));
	BYTE	alarm_code		__attribute__((packed));
	//iua
	BYTE	rel_reason		__attribute__((packed));
	BYTE	tei_state			__attribute__((packed));
	WORD	dlci					__attribute__((packed));
	//m3ua
	DWORD dpc							__attribute__((packed));	/*Routing Label*/
	DWORD opc							__attribute__((packed));
	BYTE 	sls							__attribute__((packed));
	BYTE 	mp							__attribute__((packed));	
	BYTE 	ni							__attribute__((packed));	
	BYTE 	si							__attribute__((packed));	
	
	DWORD	net_app				__attribute__((packed));//Network_Appearance
	DWORD	rc						__attribute__((packed));//Routing_Context
	DWORD	aff_pc				__attribute__((packed));//xUA_Affected_PC
	DWORD	user_cause		__attribute__((packed));//M3UA_User_Cause
	DWORD	cong_ind			__attribute__((packed));//M3UA_Congestion_Indications
	DWORD	con_dpc				__attribute__((packed));//M3UA_Concerned_Destination
	
}m2ua_sg_info_t;

typedef struct _m2ua_comhdr
{
	BYTE 	version			__attribute__((packed));
	BYTE	spare				__attribute__((packed));
	BYTE	msg_class		__attribute__((packed));
	BYTE	msg_type		__attribute__((packed));
	DWORD	len					__attribute__((packed));
}m2ua_comhdr_t;

typedef struct _m2ua_par_hdr
{
	WORD 	tag					__attribute__((packed));
	WORD	len					__attribute__((packed));
}m2ua_par_hdr_t;

typedef struct _m2ua_var_par
{
	m2ua_par_hdr_t	hdr						__attribute__((packed));
	BYTE			val[M2UA_MAX_MSG_LEN]	__attribute__((packed));
}m2ua_var_par_t;

typedef struct _m2ua_msg
{
	m2ua_comhdr_t	comhdr					__attribute__((packed));
	BYTE			msg[M2UA_MAX_MSG_LEN]	__attribute__((packed));
}m2ua_msg_t;

typedef struct _sg_para
{
	BYTE	enable							__attribute__((packed));
	BYTE	server							__attribute__((packed));
	BYTE	xUA_ack							__attribute__((packed));	//BIT 1-7:xUA_type,0/1/2:M2UA/IUA/M3UA	,Bit 0: ACK	
	DWORD	ip									__attribute__((packed));	
	WORD	plat_port[2]				__attribute__((packed));
}sg_para_t;

typedef struct _lk_para
{
	BYTE	enable							__attribute__((packed));
	WORD	lk_sg								__attribute__((packed));
	BYTE	iid									__attribute__((packed));
	WORD	dlci								__attribute__((packed));
}lk_para_t;

typedef struct _m2ua_para
{
	sg_para_t				sg_para[M2UA_MAX_SG_NUM]	__attribute__((packed));
	lk_para_t				lk_para[M2UA_MAX_LK_NUM]	__attribute__((packed));
	BYTE		cmd							__attribute__((packed));
}m2ua_para_t;

typedef struct _m2ua_lk_pro
{
	BYTE 	e1_to_linkset					__attribute__((packed));
	BYTE 	e1_to_slc						__attribute__((packed));
	DWORD 	e1_to_mtp3						__attribute__((packed));
	BYTE 	e1_lk_type						__attribute__((packed));
	BYTE 	e1_to_sg						__attribute__((packed));
	BYTE 	e1_to_iid						__attribute__((packed));
	DWORD 	remote_ip						__attribute__((packed));
	BYTE  	inactive						__attribute__((packed));
	BYTE  	inactive_tm						__attribute__((packed));
	DWORD 	e1_to_alterMTP3					__attribute__((packed));
}m2ua_lk_pro_t;

typedef struct _m2ua_sg_csta
{
	DWORD timestamp						__attribute__((packed));
	DWORD sg_out_msg					__attribute__((packed));
	DWORD sg_in_msg						__attribute__((packed));
	DWORD sg_out_bytes					__attribute__((packed));
	DWORD sg_in_bytes					__attribute__((packed));
	DWORD sg_asp_dn_times			__attribute__((packed));
}m2ua_sg_csta_t;

typedef struct _m2ua_lk_csta
{
	DWORD	timestamp						__attribute__((packed));
	DWORD	lk_out_msg						__attribute__((packed));
	DWORD	lk_in_msg						__attribute__((packed));
	DWORD	lk_out_bytes					__attribute__((packed));
	DWORD	lk_in_bytes						__attribute__((packed));
	DWORD	lk_dn_times					__attribute__((packed));
}m2ua_lk_csta_t;

typedef struct _m2ua_csta
{
	m2ua_sg_csta_t	sg_csta[M2UA_MAX_SG_NUM]		__attribute__((packed));
	m2ua_lk_csta_t	lk_csta[M2UA_MAX_LK_NUM]		__attribute__((packed));
}m2ua_csta_t;

#endif
