#ifndef _M2UA__H
#define _M2UA__H

//#include "m2ua_struct.h"


#ifndef M2UA_MAX_MSG_LEN
#define M2UA_MAX_MSG_LEN				300
#endif


typedef struct _m2ua_up_msg
{
	BYTE 	link					__attribute__((packed));
	WORD 	len						__attribute__((packed));
	BYTE 	sio						__attribute__((packed));
	
	union
	{
		struct
		{
			BYTE 	content[M2UA_MAX_MSG_LEN]	__attribute__((packed));
		}mtp3						__attribute__((packed));
	
		struct
		{
			BYTE	mtp3_ip			__attribute__((packed));
			BYTE	opercode		__attribute__((packed));
			BYTE	alarmcode		__attribute__((packed));
		}lm							__attribute__((packed));
	}msg							__attribute__((packed));
	
}m2ua_up_msg_t;

void m2ua_init(BYTE);
void m2ua_timer(void);

int get_m2ua_msg(m2ua_up_msg_t **data_ptr);
int put_m2ua_msg(m2ua_up_msg_t *data_ptr);


int set_m2ua_link(BYTE link, BYTE *data_ptr);
int set_m2ua_sg(WORD sg, BYTE *data_ptr);
int m2ua_restart();

typedef struct _xua_lm_lk
{	
	BYTE 	link					__attribute__((packed));
	WORD	len						__attribute__((packed)); /* len = 3 */
	BYTE	mtp3_ip				__attribute__((packed));
	BYTE	opercode			__attribute__((packed));
	BYTE	alarmcode			__attribute__((packed));	
}xua_lm_lk;

typedef struct _xua_iua_msg
{	
	BYTE 	link						__attribute__((packed));
	WORD	len							__attribute__((packed)); /* len for content */
	BYTE 	content[M2UA_MAX_MSG_LEN]		__attribute__((packed));
}xua_iua_msg;

typedef struct _xua_m2ua_msg
{	
	BYTE 	link						__attribute__((packed));
	WORD	len							__attribute__((packed)); /* len for content */
	BYTE 	content[M2UA_MAX_MSG_LEN]		__attribute__((packed));
}xua_m2ua_msg;

typedef struct _xua_m3ua_msg
{	
	BYTE 	link						__attribute__((packed));	
	WORD	len							__attribute__((packed)); 	/* len for content */		
	DWORD rc							__attribute__((packed));	
	DWORD opc							__attribute__((packed));	/* routing label*/	
	DWORD dpc							__attribute__((packed));	/* Big-Endian (WORD, DWORD) */
	BYTE 	si							__attribute__((packed));	
	BYTE 	ni							__attribute__((packed));	
	BYTE 	mp							__attribute__((packed));	
	BYTE 	sls							__attribute__((packed));
	BYTE 	content[M2UA_MAX_MSG_LEN]		__attribute__((packed)); /* mtp3-user data */
}xua_m3ua_msg;


typedef struct _xua_rc_cmd
{	
	BYTE	link						__attribute__((packed));
	WORD	len							__attribute__((packed)); 		/* len = 5 */
	DWORD	rc							__attribute__((packed));		//Routing_Context 	
	BYTE	opercode				__attribute__((packed));		//Routing_Context statue
	/*
	DWORD	aff_pc				__attribute__((packed));	//M3UA_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	
	*/
}xua_rc_cmd;

typedef struct _xua_up_msg
{	
	BYTE		msg_class								__attribute__((packed));
	union                       		
	{  
		xua_lm_lk						lm_lk			__attribute__((packed)); 
		xua_m2ua_msg				m2ua   	  __attribute__((packed));
		xua_iua_msg					iua				__attribute__((packed));		
		xua_m3ua_msg				m3ua   	  __attribute__((packed));
		xua_rc_cmd					rc_cmd 	  __attribute__((packed));
	}msg														__attribute__((packed));
}xua_up_msg_t;


int get_xua_msg(BYTE xUA_type, xua_up_msg_t **data_ptr);
int put_xua_msg(xua_up_msg_t *data_ptr);

int get_m3ua_msg(xua_up_msg_t **data_ptr);
int put_m3ua_msg(xua_up_msg_t *data_ptr);


#define	XUAHEADOFFSET						4			//msg_class(1)+lk(1)+len(2)
#define	RESERVE_FOR_IUAHEAD			(28 - XUAHEADOFFSET)
#define	RESERVE_FOR_M2UAHEAD		(20 - XUAHEADOFFSET)
#define	RESERVE_FOR_M3UAHEAD		(20 - XUAHEADOFFSET -4)


#define	IUA_QPTM_MSG				0x05
#define	M2UA_MAUP_MSG				0x06
#define	M3UA_MAUP_MSG				0x07

#define	IUA_MGMT_CMD				0xA5
#define	M2UA_MGMT_CMD				0xA6
#define	M3UA_MGMT_CMD				0xA7

#define	M3UA_RC_CMD					0xF5
	
#define 	M2UA_APP				0
#define 	IUA_APP					1
#define 	M3UA_APP				2


#endif
