/***********************************************************
Copyright (C), LGC Wireless.
File Name:		isdn_ie.h
Description:	ISDN information elements structure
Version:		v9.0.0
Author:			Gengxin Chen
Create Date:	2008-1-17
Remark:			M:mandatory, O:optional
History:
	<author>	<date>		<version>		<desc>
	
************************************************************/
#ifndef _ISDN_IE_H
#define _ISDN_IE_H

#include "isdn_public.h"


/************************************************************
ISDN information elements structure
************************************************************/

typedef struct _brCap_b4	//Bearer capability octets 4
{
	u8 tran_mode;		//Transfer mode							M
	u8 tran_rate;		//Information transfer rate				M
	u8 rate_mul;		//Rate multiplier						O
}brCap_b4;
typedef struct _brCap_b5	//Bearer capability octets 5
{
	u8 usr_layer1;		//User information layer 1 protocol
	u8 has_ext_a;			//
	u8 syn_asy;			//Synch/asynch (0/1)
	u8 neg;				//Negot
	u8 usr_rate;		//User rate
	u8 has_ext_b;			//
	u8 inter_rate;		//Intermediate rate
	u8 nic_tx;			//NIC on Tx
	u8 nic_rx;			//NIC on Rx
	u8 ctl_tx;			//Flow control on Tx
	u8 ctl_rx;			//Flow control on Rx
//	u8 ext_b;			//
	u8 hdr;				//Hdr/no Hdr
	u8 mul_fra;			//Multiframe;
	u8 mode;			//Mode
	u8 lli_neg;			//LLI negot.
	u8 assign;			//Assignor/ee
	u8 inband;			//In-band neg.
	u8 has_ext_c;			//
	u8 stop_bit;		//Number of stop bits
	u8 data_bit;		//Number of data bits
	u8 par;				//Parity
	u8 has_ext_d;
	u8 du_mode;			//Duplex Mode
	u8 mod_type;		//Modem type
}brCap_b5;
typedef struct _brCap_b7	//Bearer capability octets 7
{
	u8 usr_layer3;		//User information layer 3 protocol
	u8 has_ext_a;			//
	u8 layer3_a;		//Additional layer 3 protocol information (most significant bits)
	u8 has_ext_b;			//
	u8 layer3_b;		//Additional layer 3 protocol information (most significant bits)
}brCap_b7;
typedef struct _brCap		//Bearer capability 
{/*可能得把每个可选八比特放到一个结构体中，而一个八比特组需要在另外的地方处理成一个数组*/
	u8 pres;				//element header
	u32 ext_flag;		//extension domain flag					M
	u8 code_stan;		//Coding standard (00)					M
	u8 tran_cap;		//Information transfer capability		M
	brCap_b4 b4;		//octets 4
	brCap_b5 b5;		//octets 5 group
	u8 usr_layer2;		//User information layer 2 protocol
	u8 usr_layer3;		//User information layer 3 protocol
//	brCap_b7 b7;		//octets 7
}BrCap;

typedef struct _callId		//Call identity
{
	u8 pres;				//element header
	u8 call_id_len;
	u8 call_id[8];		//Call identity(IA5)
}CallId;

typedef struct _callStat	//Call state
{
	u8 pres;				//element header
	u8 code_stan;		//Coding standard
	u8 stat_val;		//Call state value/global interface state value(state value is coded in binary)
}CallStat;

typedef struct _cdPtyNum	//Called party number
{
	u8 pres;				//element header
	u8 num_type;		//Type of number
	u8 num_plan_id;		//Numbering plan identification
	u8 num_digit_len;
	u8 num_digit[32];	//Number digits(IA5)
}CdPtyNum;

typedef struct _cdPtyAddr	//Called party subaddress
{
	u8 pres;				//element header
	u8 addr_type;		//Type of subaddress
	u8 odd_even;		//Odd/even indicator
	u8 addr_info_len;
	u8 addr_info[20];	//Subaddress information
}CdPtyAddr;

typedef struct _cgPtyNum_b3
{
	u8 num_type;		//Type of number
	u8 num_plan_id;		//Numbering plan identification
	u8 has_ext_a;		//
	u8 pres_ind;		//Presentation indicator
	u8 screen_ind;		//Screening indicator
}cgPtyNum_b3;
typedef struct _cgPtyNum	//Calling party number
{
	u8 pres;				//element header
	u32 ext_flag;		//extension domain flag					M
	cgPtyNum_b3 b3;
	u8 num_digit_len;
	u8 num_digit[32];	//Number digits(IA5)
}CgPtyNum, ConnNum;

typedef struct _cgPtyAddr	//Calling party subaddress
{
	u8 pres;				//element header
	u8 addr_type;		//Type of subaddress
	u8 odd_even;		//Odd/even indicator
	u8 addr_info_len;
	u8 addr_info[20];	//subaddress information
}CgPtyAddr;

typedef struct _cause_b3
{
	u8 code_stan;		//Coding standard
	u8 loc;				//Location
	u8 has_ext_a;	//
	u8 rec;				//Recommendation
}cause_b3;
typedef struct _cause_b5	//diagnostic
{
	u8 attrib_num;		//attribute number
//	u8 has_ext_a;
	u8 rej_attrib;		//rejected attribute
	u8 has_ext_b;
	u8 avail_attrib;		//available attribute
	//Call rejected diagnostic for cause number 21 TODO
}cause_b5;
typedef struct _causeStr	//Cause
{
	u8 pres;				//element header
	u32 ext_flag;		//
	cause_b3 b3;			//octet 3
	u8 cause_val;		//Cause value
	u8 dia_num;
	cause_b5 dia[8];		//diagnostic
}CauseStr;

typedef struct _chnlId_b3	//Channel identification octets 3
{
	u8 int_id_pre;		//Interface identifier present			M
	u8 int_type;		//Interface type						M
	u8 pref_excl;		//Preferable/Exclusive					M
	u8 chnl_ind;		//D-channel indicator					M
	u8 info_chnl_sel;	//Infomation channel selection			M

	u8 int_id;			//Interface identifier;

	u8 has_chnl;			// 1:wiith 3.2 and 3.3,  0:without 3.2 nor 3.3
	u8 code_stan;		//Coding standard
	u8 num_map;			//Number/Map
	u8 chnl_type;		//Channel type/Map element type
	u8 chnl_num;		//Channel number/Slot map	ect
}chnlId_b3;
typedef struct _chnlId		//Channel identification
{
	u8 pres;				//element header
	chnlId_b3 b3;		//octets 3
}ChnlId;

typedef struct _conLev		//Congestion level
{
	u8 pres;				//element header
	u8 con_lev;			//Congestion level
}ConLev;

typedef struct _dtTime		//Date/time
{
	u8 pres;				//element header
	u8 ext_flag;
	u8 year;
	u8 month;
	u8 day;					//M
	u8 hour;				//O
	u8 minute;			//	O
	u8 second;				//O
}DtTime;

typedef struct _disp		//Display
{
	u8 pres;				//element header
	u8 disp_info_len;
	u8 disp_info[18];	//Display information(IA5)

	//ansi
	u8 asso_info;		//Associated information
	u8 disp_type;		//display type
}Disp;

typedef struct _hLComp_b4	//High layer compatibility octets 4
{
	u8 hl_ch_id;		//High layer characteristies identification
	u8 ex_hl_ch_id;		//Extended high layer characteristics identification
	u8 ex_vid_ch_id;		//EXtended videotelephony characteristics identification
}hLComp_b4;
typedef struct _hLComp		//High layer compatibility
{
	u8 pres;				//element header
	u8 code_stan;		//Coding standard
	u8 intpr;			//Interpretation
	u8 pre_meth;		//Presentation method of protocol profile
	hLComp_b4 b4;		//octets 4
}HLComp;

typedef struct _kpdFac		//Keypad facility
{
	u8 pres;				//element header
	u8 keyfac_info_len;
	u8 key_fac_info[32];//Keypad facility information(IA5)
}KpdFac;

typedef struct _lLComp_b3	//Low layer compatibility octets 3
{
	u8 code_stan;		//Coding standard						M
	u8 tran_cap;		//Information transfer capability		M
	u8 has_ext_a;	
	u8 neg_ind;			//Negot indicator						O
}lLComp_b3;
typedef struct _lLComp_b4	//Low layer compatibility octets 4
{
	u8 tran_mode;		//Transfer mode
	u8 tran_rate;		//Information transfer rate
	u8 rate_mul;		//Rate multiplier
}lLComp_b4;
typedef struct _lLComp_b5	//Low layer compatibility octets 5
{
	u8 layer1_id;		//Layer 1 identifier
	u8 usr_layer1;		//User information layer 1 protocol
	u8 has_ext_a;			//
	u8 syn_asy;			//Synch./asynch.
	u8 neg;				//Negot.
	u8 usr_rate;		//User Rate
	u8 has_ext_b;			//
	u8 inter_rate;		//intermediate rate
	u8 nic_tx;			//NIC on Tx
	u8 nic_rx;			//NIC on Rx
	u8 ctl_tx;			//Flow control on Tx
	u8 ctl_rx;			//Flow control on Rx
//	u8 ext_b;			//
	u8 hdr;				//Hdr/no Hdr
	u8 mul_fra;			//Multiframe;
	u8 mode;			//Mode
	u8 lli_neg;			//LLI negot.
	u8 assign;			//Assignor/ee
	u8 inband;			//In-band negot.
	u8 has_ext_c;			//
	u8 stop_bit;		//Number of stop bits
	u8 data_bit;		//Number of data bits
	u8 par;				//Parity
	u8 has_ext_d;
	u8 du_mode;			//Duplex Mode
	u8 mod_type;		//Modem type
}lLComp_b5;
typedef struct _lLComp_b6	//Low layer compatibility octets 6
{
	u8 layer2_id;		//layer 2 identifier
	u8 usr_layer2;		//User information layer 2 protocol
	u8 mode;			//Mode
	u8 q933_use;		//Q.933 use
	u8 usr_layer2_info;	//User specification layer 2 protocol information
	u8 win_size;		//Window size(k)
}lLComp_b6;
typedef struct _lLComp_b7	//Low layer compatibility octets 7
{
	u8 layer3_id;		//layer 3 identifier
	u8 usr_layer3;		//User information layer 3 protocol

	u8 usr_layer3_info;	//Optional layer 3 protocol information
	u8 mode;			//Mode
	u8 def_pac_size;		//Default packet size
	u8 pac_win_size;	//Packet window size
	u8 layer3_a;		//Additional layer 3 protocol information (most significant bits)
	u8 layer3_b;		//Additional layer 3 protocol information (most significant bits)
}lLComp_b7;
typedef struct _lLComp		//Low layer compatibility
{
	u8 pres;				//element header
	u32 ext_flag;
	lLComp_b3 b3;		//octets 3						M
	lLComp_b4 b4;		//octets 4						O
	lLComp_b5 b5;		//octets 5
	lLComp_b6 b6;		//octets 6
	lLComp_b7 b7;		//octets 7

	//ansi TODO
}LLComp;

typedef struct _ntSpFac_b3	//Network-specific facilities octets 3
{
	u8 len_net_id;		//Length of network identification	M	//不为0则含有下面两个比特组
	u8 net_id_type;		//Type of network identification	O
	u8 net_id_plan;		//Network identification plan
	u8 net_id;			//Network identification(IA5) ect
}ntSpFac_b3;
typedef struct _ntSpFac		//Network-specific facilities
{
	u8 pres;				//element header
	ntSpFac_b3 b3;		//octets 3											M

	u8 spec;			//Network-specific facility specification			M
	//ansi
	u8 fac_val;		//Facility coding value
	u8 ser_par;		//Service parameters
}NtSpFac;

typedef struct _notifyInd	//Notification indicator
{
	u8 pres;				//element header
	u8 notify_descr;		//Notification description
	//ansi TODO
}NotifyInd;

typedef struct _prgInd		//Progress indicator
{
	u8 pres;				//element header
	u8 code_stan;		//Coding standard
	u8 loc;				//Location
	u8 prg_descr;		//Progress description
}PrgInd;

typedef struct _rptInd		//Repeat indicator
{
	u8 pres;				//element header
//	u8 rpt_ind;			//Repeat indication	
}RptInd;

typedef struct _restartInd	//Restart indicator
{
	u8 pres;				//element header
	u8 clas;			//class
}RestartInd;

typedef struct _segMsg		//Segmented message
{
	u8 pres;				//element header
	u8 seg_ind;			//First segment indicator
	u8 other_num;		//Number of segments remaining
	u8 seg_type;		//Segmented message type
}SegMsg;

typedef struct _sdComp		//Sending complete
{
	u8 pres;				//element header
//	u8 sd_comp;			//sending complete	常量
}SdComp;

typedef struct _sign		//Signal
{
	u8 pres;				//element header
	u8 sign_val;		//Signal value
}Sign;

typedef struct _tranNtSel	//Transit network selection
{
	u8 pres;				//element header
	u8 net_id_type;		//Type of network identification
	u8 net_id_plan;		//Network identification plan
	u8 net_id;			//Network identification(IA5)	ect
}TranNtSel;

typedef struct _usrUsr		//User-user
{
	u8 pres;				//element header
	u8 pro_discr;		//Protocol discriminator
	u8 usr_info_len;
	u8 usr_info[258];	//User information
}UsrUsr;


//supplementary services		ansi
typedef struct _fac			//facility
{

}Fac;
/* the same to the CgPtyNum
typedef struct _connNum	//connected number
{
}ConnNum;*/

typedef struct _redirNum_b3	//redirection number octet 3
{
	u8 num_type;		//Type of number
	u8 num_plan_id;		//Numbering plan identification
	
	u8 org_num_stat;	//Origin of number and presentation status
	
	u8 redir_rs;			//Reason for redirection
}redirNum_b3;
typedef struct _redirNum		//redirection number
{
	u8 pres;				//element header
	redirNum_b3 b3;		//octet 3
	u8 num_digit_len;
	u8 num_digit[32];	//Number digits(IA5)
}RedirNum;

typedef struct _chgStat			//change status
{
	u8 pres;				//element header
	u8 pref;				//Preference
	u8 new_stat;			//New status
}ChgStat;


/************************************************************
ISDN information elements functions interface
************************************************************/
u8 itu_encode_br_cap(u8 *dst, BrCap *src);
int itu_decode_br_cap(BrCap *dst, u8 *src, u8 len);
u8 isdn_encode_br_cap(u8 *dst, BrCap *src);
int isdn_decode_br_cap(BrCap *dst, u8 *src, u8 len);
u8 isdn_encode_cause(u8 *dst, CauseStr *src);
int isdn_decode_cause(CauseStr *dst, u8 *src, u8 len);
u8 isdn_encode_call_id(u8 *dst, CallId *src);
int isdn_decode_call_id(CallId *dst, u8 *src, u8 len);
u8 isdn_encode_call_stat(u8 *dst, CallStat *src);
int isdn_decode_call_stat(CallStat *dst, u8 *src, u8 len);
u8 qsig_encode_chnl_id(u8 *dst, ChnlId *src);
int qsig_decode_chnl_id(ChnlId *dst, u8 *src, u8 len);
u8 isdn_encode_chnl_id(u8 *dst, ChnlId *src);
int isdn_decode_chnl_id(ChnlId *dst, u8 *src, u8 len);
u8 isdn_encode_prg_ind(u8 *dst, PrgInd *src);
int isdn_decode_prg_ind(PrgInd *dst, u8 *src, u8 len);
u8 ansi_encode_ntsp_fac(u8 *dst, NtSpFac *src);
int ansi_decode_ntsp_fac(NtSpFac *dst, u8 *src, u8 len);
u8 isdn_encode_ntsp_fac(u8 *dst, NtSpFac *src);
int isdn_decode_ntsp_fac(NtSpFac *dst, u8 *src, u8 len);
u8 ansi_encode_notify_ind(u8 *dst, NotifyInd *src);
int ansi_decode_notify_ind(NotifyInd *dst, u8 *src, u8 len);
u8 isdn_encode_notify_ind(u8 *dst, NotifyInd *src);
int isdn_decode_notify_ind(NotifyInd *dst, u8 *src, u8 len);
u8 isdn_encode_disp(u8 *dst, Disp *src);
int isdn_decode_disp(Disp *dst, u8 *src, u8 len);
u8 isdn_encode_dt_time(u8 *dst, DtTime *src);
int isdn_decode_dt_time(DtTime *dst, u8 *src, u8 len);
u8 isdn_encode_kpd_fac(u8 *dst, KpdFac *src);
int isdn_decode_kpd_fac(KpdFac *dst, u8 *src, u8 len);
u8 isdn_encode_sign(u8 *dst, Sign *src);
int isdn_decode_sign(Sign *dst, u8 *src, u8 len);
u8 isdn_encode_cg_num(u8 *dst, CgPtyNum *src);
int isdn_decode_cg_num(CgPtyNum *dst, u8 *src, u8 len);
u8 isdn_encode_cg_addr(u8 *dst, CgPtyAddr *src);
int isdn_decode_cg_addr(CgPtyAddr *dst, u8 *src, u8 len);
u8 isdn_encode_cd_num(u8 *dst, CdPtyNum *src);
int isdn_decode_cd_num(CdPtyNum *dst, u8 *src, u8 len);
u8 isdn_encode_cd_addr(u8 *dst, CdPtyAddr *src);
int isdn_decode_cd_addr(CdPtyAddr *dst, u8 *src, u8 len);
u8 isdn_encode_tran_sel(u8 *dst, TranNtSel *src);
int isdn_decode_tran_sel(TranNtSel *dst, u8 *src, u8 len);
u8 isdn_encode_restart_ind(u8 *dst, RestartInd *src);
int isdn_decode_restart_ind(RestartInd *dst, u8 *src, u8 len);
u8 isdn_encode_ll_comp(u8 *dst, LLComp *src);
int isdn_decode_ll_comp(LLComp *dst, u8 *src, u8 len);
u8 isdn_encode_hl_comp(u8 *dst, HLComp *src);
int isdn_decode_hl_comp(HLComp *dst, u8 *src, u8 len);
u8 isdn_encode_usr_usr(u8 *dst, UsrUsr *src);
int isdn_decode_usr_usr(UsrUsr *dst, u8 *src, u8 len);
//ansi
u8 ansi_encode_chg_stat(u8 *dst, ChgStat *src);
int ansi_decode_chg_stat(ChgStat *dst, u8 *src, u8 len);
u8 ansi_encode_redir_num(u8 *dst, RedirNum *src);
int ansi_decode_redir_num(RedirNum *dst, u8 *src, u8 len);
//QSIG
u8 qsig_encode_conn_num(u8 *dst, ConnNum *src);
int qsig_decode_conn_num(ConnNum *dst, u8 *src, u8 len);


#endif
