Index: src/zap_isdn.c
===================================================================
--- src/zap_isdn.c	(revision 495)
+++ src/zap_isdn.c	(working copy)
@@ -44,6 +44,10 @@
 #define LINE "--------------------------------------------------------------------------------"
 //#define IODEBUG
 
+/* helper macros */
+#define ZAP_SPAN_IS_BRI(x)	((x)->trunk_type == ZAP_TRUNK_BRI || (x)->trunk_type == ZAP_TRUNK_BRI_PTMP)
+#define ZAP_SPAN_IS_ALAW(x)	((x)->trunk_type == ZAP_TRUNK_E1 || (x)->trunk_type == ZAP_TRUNK_BRI || (x)->trunk_type == ZAP_TRUNK_BRI_PTMP)	/* TODO: baaaad hack */
+
 static L2ULONG zap_time_now(void)
 {
 	return (L2ULONG)zap_current_time_in_ms();
@@ -67,84 +71,113 @@
 	Q931ie_CalledNum CalledNum;
 	Q931ie_CalledNum *ptrCalledNum;
 	Q931ie_Display Display, *ptrDisplay;
+	Q931ie_HLComp HLComp;			/* High-Layer Compatibility IE */
 	zap_status_t status = ZAP_FAIL;
 	zap_isdn_data_t *isdn_data = span->signal_data;
 	int sanity = 60000;
 
-	Q931InitIEBearerCap(&BearerCap);
-	Q931InitIEChanID(&ChanID);
-	Q931InitIECallingNum(&CallingNum);
-	Q931InitIECalledNum(&CalledNum);
-	Q931InitIEDisplay(&Display);
-
 	Q931InitMesGeneric(gen);
 	gen->MesType = Q931mes_SETUP;
 
-	BearerCap.CodStand = 0; /* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */
-	BearerCap.ITC = 0; /* Speech */
-	BearerCap.TransMode = 0; /* Circuit = 0, Packet = 1 */
-	BearerCap.ITR = 16; /* 64k */
+	/*
+	 * Bearer Capability IE
+	 */
+	Q931InitIEBearerCap(&BearerCap);
+	BearerCap.CodStand = 0;			/* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */
+	BearerCap.ITC = 0;			/* Speech */
+	BearerCap.TransMode = 0;		/* Circuit = 0, Packet = 1 */
+	BearerCap.ITR = 16;			/* 64k */
 	BearerCap.Layer1Ident = 1;
-	BearerCap.UIL1Prot = 2; /* U-law (a-law = 3)*/
-
+	BearerCap.UIL1Prot = ZAP_SPAN_IS_ALAW(span) ? 3 : 2;	/* U-law = 2, A-law = 3 */
 	gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap);
 
-	ChanID.IntType = 1; /* PRI = 1, BRI = 0 */
-	ChanID.PrefExcl = (isdn_data->opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL) ? 0 : 1; /* 0 = preferred, 1 exclusive */
-	ChanID.InfoChanSel = 1;
-	ChanID.ChanMapType = 3; /* B-Chan */
-	ChanID.ChanSlot = chan_id;
+	/*
+	 * Channel ID IE
+	 */
+	Q931InitIEChanID(&ChanID);
+	ChanID.IntType = ZAP_SPAN_IS_BRI(span) ? 1 : 0;		/* PRI = 1, BRI = 0 */
+	ChanID.PrefExcl = (isdn_data->opts & ZAP_ISDN_OPT_SUGGEST_CHANNEL) ? 0 : 1;	/* 0 = preferred, 1 exclusive */
+	if(ChanID.IntType) {
+		ChanID.InfoChanSel = 1;				/* None = 0, See Slot = 1, Any = 3 */
+		ChanID.ChanMapType = 3;				/* B-Chan */
+		ChanID.ChanSlot = (unsigned char)chan_id;
+	} else {
+		ChanID.InfoChanSel = (unsigned char)chan_id & 0x03;	/* None = 0, B1 = 1, B2 = 2, Any = 3 */
+	}
 	gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID);
-			
+
+	/*
+	 * Display IE
+	 */
+	Q931InitIEDisplay(&Display);
 	Display.Size = Display.Size + (unsigned char)strlen(caller_data->cid_name);
 	gen->Display = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &Display);			
 	ptrDisplay = Q931GetIEPtr(gen->Display, gen->buf);
 	zap_copy_string((char *)ptrDisplay->Display, caller_data->cid_name, strlen(caller_data->cid_name)+1);
 
-	/* TypNum: Type of number		*/
-	/* Bits 7 6 5					*/
-	/* 000	Unknown					*/
+	/*
+	 * High-Layer Compatibility IE   (Note: Required for AVM FritzBox)
+	 */
+	Q931InitIEHLComp(&HLComp);
+	HLComp.CodStand  = 0;	/* ITU */
+	HLComp.Interpret = 4;	/* only possible value */
+	HLComp.PresMeth  = 1;   /* High-layer protocol profile */
+	HLComp.HLCharID  = 0;	/* Telephony = 0, Fax G2+3 = 4, Fax G4 = 65 (Class I)/ 68 (Class II or III) */
+	gen->HLComp = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &HLComp);
+
+	/*
+	 * Calling Number IE
+	 */
+	Q931InitIECallingNum(&CallingNum);
+	/* TypNum: Type of number	*/
+	/* Bits 7 6 5			*/
+	/* 000	Unknown			*/
 	/* 001	International number	*/
-	/* 010	National number			*/
+	/* 010	National number		*/
 	/* 011	Network Specific number */
-	/* 100	Subscriber mumber		*/
-	/* 110	Abbreviated number		*/
+	/* 100	Subscriber mumber	*/
+	/* 110	Abbreviated number	*/
 	/* 111	Reserved for extension	*/
-	/* All other values are reserved */
+	/* All other values are reserved*/
 	CallingNum.TypNum = 2;
 
-	/* NumPlanID									*/
-	/* Bits 4 3 2 1									*/
-	/* 0000	Unknown									*/
+	/* NumPlanID					*/
+	/* Bits 4 3 2 1					*/
+	/* 0000	Unknown					*/
 	/* 0001	ISDN/telephony numbering plan (E.164)	*/
-	/* 0011	Data numbering plan (X.121)				*/
-	/* 0100	Telex numbering plan (F.69)				*/
-	/* 1000	National standard numbering plan		*/
-	/* 1001	Private numbering plan					*/
-	/* 1111	Reserved for extension					*/
-	/* All other valures are reserved				*/
+	/* 0011	Data numbering plan (X.121)		*/
+	/* 0100	Telex numbering plan (F.69)		*/
+	/* 1000	National standard numbering plan	*/
+	/* 1001	Private numbering plan			*/
+	/* 1111	Reserved for extension			*/
+	/* All other valures are reserved		*/
 	CallingNum.NumPlanID = 1;
 
-	/* Presentation indicator		*/
+	/* Presentation indicator				*/
 	/* Bits 7 6						*/
-	/* 00	Presenation Allowed		*/
-	/* 01	Presentation Restricted	*/
+	/* 00	Presenation Allowed				*/
+	/* 01	Presentation Restricted				*/
 	/* 10	Number not available due to internetworking	*/
-	/* 11	Reserved				*/
+	/* 11	Reserved					*/
 	CallingNum.PresInd = 0;
 
-	/* Screening Indicator						*/
-	/* Bits 2 1									*/
-	/* 00	User-provided, not screened			*/
+	/* Screening Indicator				*/
+	/* Bits 2 1					*/
+	/* 00	User-provided, not screened		*/
 	/* 01	User-provided, verified and passed	*/
 	/* 10	User-provided, verified and failed	*/
-	/* 11	Network provided					*/
+	/* 11	Network provided			*/
 	CallingNum.ScreenInd = 0;
 	CallingNum.Size = CallingNum.Size + (unsigned char)strlen(caller_data->cid_num.digits);
 	gen->CallingNum = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &CallingNum);			
 	ptrCallingNum = Q931GetIEPtr(gen->CallingNum, gen->buf);
 	zap_copy_string((char *)ptrCallingNum->Digit, caller_data->cid_num.digits, strlen(caller_data->cid_num.digits)+1);
 
+
+	/*
+	 * Called number IE
+	 */
+	Q931InitIECalledNum(&CalledNum);
 	CalledNum.TypNum = 2;
 	CalledNum.NumPlanID = 1;
 	CalledNum.Size = CalledNum.Size + (unsigned char)strlen(caller_data->ani.digits);
@@ -207,11 +240,11 @@
 				memset(&new_chan->caller_data, 0, sizeof(new_chan->caller_data));
 				zap_set_flag(new_chan, ZAP_CHANNEL_OUTBOUND);
 				zap_set_state_locked(new_chan, ZAP_CHANNEL_STATE_DIALING);
+
 				switch(gen->MesType) {
 				case Q931mes_ALERTING:
 					new_chan->init_state = ZAP_CHANNEL_STATE_PROGRESS_MEDIA;
 					break;
-					break;
 				case Q931mes_CONNECT:
 					new_chan->init_state = ZAP_CHANNEL_STATE_UP;
 					break;
@@ -229,7 +262,9 @@
 			return ZAP_SUCCESS;
 		} else {
 			Q931ie_Cause cause;
+
 			gen->MesType = Q931mes_DISCONNECT;
+
 			cause.IEId = Q931ie_CAUSE;
 			cause.Size = sizeof(Q931ie_Cause);
 			cause.CodStand  = 0;
@@ -239,6 +274,7 @@
 			cause.Value = (unsigned char) ZAP_CAUSE_WRONG_CALL_STATE;
 			*cause.Diag = '\0';
 			gen->Cause = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &cause);
+
 			Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size);
 
 			if (gen->CRV) {
@@ -258,6 +294,12 @@
 
 }
 
+static L3INT zap_isdn_q931_log(void *pvt, Q931LogLevel_t level, char *msg, L3INT size)
+{
+	zap_log(__FILE__, "Q.931", __LINE__, ZAP_LOG_LEVEL_DEBUG, "%s", msg);
+	return 0;
+}
+
 static L3INT zap_isdn_931_err(void *pvt, L3INT id, L3INT p1, L3INT p2)
 {
 	zap_log(ZAP_LOG_ERROR, "ERROR: [%s] [%d] [%d]\n", q931_error_to_name(id), p1, p2);
@@ -275,7 +317,11 @@
 
 	if (Q931IsIEPresent(gen->ChanID)) {
 		Q931ie_ChanID *chanid = Q931GetIEPtr(gen->ChanID, gen->buf);
-		chan_id = chanid->ChanSlot;
+
+		if(chanid->IntType)
+			chan_id = chanid->ChanSlot;
+		else
+			chan_id = chanid->InfoChanSel;
 	}
 
 	assert(span != NULL);
@@ -295,9 +341,7 @@
 		case Q931mes_ALERTING:
 		case Q931mes_PROGRESS:
 		case Q931mes_CONNECT:
-			{
-				caller_data->call_state = ZAP_CALLER_STATE_SUCCESS;
-			}
+			caller_data->call_state = ZAP_CALLER_STATE_SUCCESS;
 			break;
 		default:
 			caller_data->call_state = ZAP_CALLER_STATE_FAIL;
@@ -313,9 +357,6 @@
 		zchan = isdn_data->channels_remote_crv[gen->CRV];
 	}
 
-
-
-
 	if (gen->ProtDisc == 3) {
 		switch(gen->MesType) {
 		case Q931mes_SERVICE:
@@ -431,13 +472,20 @@
 				zap_status_t status;
 				int fail = 1;
 				uint32_t cplen = mlen;
-				
+
+				zap_log(ZAP_LOG_DEBUG, "Q.931 SETUP Message recived, requested Channel ID: %d (available on span: %d)\n", chan_id, span->chan_count);
+
 				zchan = NULL;
 				if (chan_id < ZAP_MAX_CHANNELS_SPAN && chan_id <= span->chan_count) {
 					zchan = &span->channels[chan_id];
 				}
 
 				if (zchan && (status = zap_channel_open_chan(zchan) == ZAP_SUCCESS)) {
+					zap_log(ZAP_LOG_DEBUG, "Successfully opened requested channel %d [inuse: %s, state: %d]\n",
+										chan_id,
+										zap_test_flag(zchan, ZAP_CHANNEL_INUSE) ? "yes" : "no",
+										zchan->state);
+
 					if (zap_test_flag(zchan, ZAP_CHANNEL_INUSE) || zchan->state != ZAP_CHANNEL_STATE_DOWN) {
 						if (zchan->state == ZAP_CHANNEL_STATE_DOWN || zchan->state >= ZAP_CHANNEL_STATE_TERMINATING) {
 							int x = 0;
@@ -462,6 +510,8 @@
 					}
 
 					if (zchan && zchan->state == ZAP_CHANNEL_STATE_DOWN) {
+						zap_log(ZAP_LOG_DEBUG, "Request channel is down, preparing for activation\n");
+
 						isdn_data->channels_remote_crv[gen->CRV] = zchan;
 						memset(&zchan->caller_data, 0, sizeof(zchan->caller_data));
 
@@ -485,6 +535,7 @@
 				if (fail) {
 					Q931ie_Cause cause;
 					gen->MesType = Q931mes_DISCONNECT;
+
 					cause.IEId = Q931ie_CAUSE;
 					cause.Size = sizeof(Q931ie_Cause);
 					cause.CodStand  = 0;
@@ -494,6 +545,7 @@
 					cause.Value = (unsigned char) ZAP_CAUSE_WRONG_CALL_STATE;
 					*cause.Diag = '\0';
 					gen->Cause = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &cause);
+
 					Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size);
 
 					if (gen->CRV) {
@@ -518,16 +570,23 @@
 	return 0;
 }
 
-static int zap_isdn_921_23(void *pvt, L2UCHAR *msg, L2INT mlen)
+static int zap_isdn_921_23(void *pvt, Q921DLMsg_t ind, L2UCHAR *msg, L2INT mlen)
 {
-	int ret;
+	int ret, offset = (ind == Q921_DL_DATA) ? 4 : 3;
 	char bb[4096] = "";
-	print_hex_bytes(msg+4, mlen-2, bb, sizeof(bb));
-	zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen-2, LINE, bb);
 
-	ret = Q931Rx23(pvt, msg, mlen);
-	if (ret != 0)
-		zap_log(ZAP_LOG_DEBUG, "931 parse error [%d] [%s]\n", ret, q931_error_to_name(ret));
+	switch(ind) {
+	case Q921_DL_DATA:
+	case Q921_DL_UNIT_DATA:
+		print_hex_bytes(msg + offset, mlen - offset, bb, sizeof(bb));
+		zap_log(ZAP_LOG_DEBUG, "READ %d\n%s\n%s\n\n", (int)mlen - offset, LINE, bb);
+	default:
+		ret = Q931Rx23(pvt, ind, msg, mlen);
+		if (ret != 0)
+			zap_log(ZAP_LOG_DEBUG, "931 parse error [%d] [%s]\n", ret, q931_error_to_name(ret));
+		break;
+	}
+
 	return ((ret >= 0) ? 1 : 0);
 }
 
@@ -542,7 +601,6 @@
 	print_hex_bytes(msg, len, bb, sizeof(bb));
 	print_bits(msg, (int)len, bb, sizeof(bb), ZAP_ENDIAN_LITTLE, 0);
 	zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)len, LINE, bb);
-
 #endif
 
 	assert(span != NULL);
@@ -641,36 +699,51 @@
 			Q931ie_CalledNum CalledNum;
 			Q931ie_CalledNum *ptrCalledNum;
 			Q931ie_Display Display, *ptrDisplay;
-			
-			Q931InitIEBearerCap(&BearerCap);
-			Q931InitIEChanID(&ChanID);
-			Q931InitIECallingNum(&CallingNum);
-			Q931InitIECalledNum(&CalledNum);
-			Q931InitIEDisplay(&Display);
+			Q931ie_HLComp HLComp;			/* High-Layer Compatibility IE */
 
 			Q931InitMesGeneric(gen);
 			gen->MesType = Q931mes_SETUP;
 
-			BearerCap.CodStand = 0; /* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */
-			BearerCap.ITC = 0; /* Speech */
-			BearerCap.TransMode = 0; /* Circuit = 0, Packet = 1 */
-			BearerCap.ITR = 16; /* 64k */
+			/*
+			 * Bearer Capability IE
+			 */
+			Q931InitIEBearerCap(&BearerCap);
+			BearerCap.CodStand = 0;			/* ITU-T = 0, ISO/IEC = 1, National = 2, Network = 3 */
+			BearerCap.ITC = 0;			/* Speech */
+			BearerCap.TransMode = 0;		/* Circuit = 0, Packet = 1 */
+			BearerCap.ITR = 16;			/* 64k = 16, Packet mode = 0 */
 			BearerCap.Layer1Ident = 1;
-			BearerCap.UIL1Prot = 2; /* U-law (a-law = 3)*/
+			BearerCap.UIL1Prot = ZAP_SPAN_IS_ALAW(zchan->span) ? 3 : 2;	/* U-law = 2, A-law = 3 */
 			gen->BearerCap = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &BearerCap);
 
-			//is cast right here?
-			ChanID.IntType = 1; /* PRI = 1, BRI = 0 */
-			ChanID.InfoChanSel = 1;
-			ChanID.ChanMapType = 3; /* B-Chan */
-			ChanID.ChanSlot = (unsigned char)zchan->chan_id;
+			/*
+			 * ChannelID IE
+			 */
+			Q931InitIEChanID(&ChanID);
+			ChanID.IntType = ZAP_SPAN_IS_BRI(zchan->span) ? 0 : 1;	/* PRI = 1, BRI = 0 */
+			if(ChanID.IntType) {
+				ChanID.InfoChanSel = 1;		/* None = 0, See Slot = 1, Any = 3 */
+				ChanID.ChanMapType = 3;		/* B-Chan */
+				ChanID.ChanSlot = (unsigned char)zchan->chan_id;
+			} else {
+				ChanID.InfoChanSel = (unsigned char)zchan->chan_id & 0x03;	/* None = 0, B1 = 1, B2 = 2, Any = 3 */
+			}
 			gen->ChanID = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &ChanID);
-			
+
+			/*
+			 * Display IE
+			 */			
+			Q931InitIEDisplay(&Display);
 			Display.Size = Display.Size + (unsigned char)strlen(zchan->caller_data.cid_name);
 			gen->Display = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &Display);
 			ptrDisplay = Q931GetIEPtr(gen->Display, gen->buf);
 			zap_copy_string((char *)ptrDisplay->Display, zchan->caller_data.cid_name, strlen(zchan->caller_data.cid_name)+1);
 
+			/*
+			 * CallingNum IE
+			 */ 
+			Q931InitIECallingNum(&CallingNum);
+
 			/* TypNum: Type of number*/
 			/* Bits 7 6 5*/
 			/* 000Unknown*/
@@ -715,6 +788,10 @@
 			ptrCallingNum = Q931GetIEPtr(gen->CallingNum, gen->buf);
 			zap_copy_string((char *)ptrCallingNum->Digit, zchan->caller_data.cid_num.digits, strlen(zchan->caller_data.cid_num.digits)+1);
 
+			/*
+			 * CalledNum IE
+			 */
+			Q931InitIECalledNum(&CalledNum);
 			CalledNum.TypNum = 2;
 			CalledNum.NumPlanID = 1;
 			CalledNum.Size = CalledNum.Size + (unsigned char)strlen(zchan->caller_data.ani.digits);
@@ -722,6 +799,16 @@
 			ptrCalledNum = Q931GetIEPtr(gen->CalledNum, gen->buf);
 			zap_copy_string((char *)ptrCalledNum->Digit, zchan->caller_data.ani.digits, strlen(zchan->caller_data.ani.digits)+1);
 
+			/*
+			 * High-Layer Compatibility IE   (Note: Required for AVM FritzBox)
+			 */
+			Q931InitIEHLComp(&HLComp);
+			HLComp.CodStand  = 0;	/* ITU */
+			HLComp.Interpret = 4;	/* only possible value */
+			HLComp.PresMeth  = 1;   /* High-layer protocol profile */
+			HLComp.HLCharID  = 0;	/* Telephony = 0, Fax G2+3 = 4, Fax G4 = 65 (Class I)/ 68 (Class II or III) */   /* TODO: make accessible from user layer */
+			gen->HLComp = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &HLComp);
+
 			Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size);
 			isdn_data->channels_local_crv[gen->CRV] = zchan;
 		}
@@ -735,6 +822,7 @@
 		{
 			Q931ie_Cause cause;
 			gen->MesType = Q931mes_DISCONNECT;
+
 			cause.IEId = Q931ie_CAUSE;
 			cause.Size = sizeof(Q931ie_Cause);
 			cause.CodStand  = 0;
@@ -744,6 +832,7 @@
 			cause.Value = (unsigned char) zchan->caller_data.hangup_cause;
 			*cause.Diag = '\0';
 			gen->Cause = Q931AppendIE((L3UCHAR *) gen, (L3UCHAR *) &cause);
+
 			Q931Rx43(&isdn_data->q931, (L3UCHAR *) gen, gen->Size);
 		}
 		break;
@@ -752,6 +841,7 @@
 			sig.event_id = ZAP_SIGEVENT_STOP;
 			status = isdn_data->sig_cb(&sig);
 			gen->MesType = Q931mes_RELEASE;
+
 			Q931Rx43(&isdn_data->q931, (void *)gen, gen->Size);
 		}
 	default:
@@ -859,7 +949,7 @@
 	int errs = 0;
 
 #ifdef WIN32
-    timeBeginPeriod(1);
+	timeBeginPeriod(1);
 #endif
 
 	zap_log(ZAP_LOG_DEBUG, "ISDN thread starting.\n");
@@ -925,7 +1015,7 @@
 	zap_clear_flag(isdn_data, ZAP_ISDN_RUNNING);
 
 #ifdef WIN32
-    timeEndPeriod(1);
+	timeEndPeriod(1);
 #endif
 
 	zap_log(ZAP_LOG_DEBUG, "ISDN thread ended.\n");
@@ -948,17 +1038,61 @@
 	return zap_thread_create_detached(zap_isdn_run, span);
 }
 
-static int q931_rx_32(void *pvt,L3UCHAR *msg, L3INT mlen)
+static int q931_rx_32(void *pvt, Q921DLMsg_t ind, L3UCHAR *msg, L3INT mlen)
 {
-	int ret;
+	int offset = 4;
 	char bb[4096] = "";
-	ret = Q921Rx32(pvt, msg, mlen);
-	print_hex_bytes(msg, mlen, bb, sizeof(bb));
-	zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)mlen, LINE, bb);
-	return ret;
+
+	switch(ind) {
+	case Q921_DL_UNIT_DATA:
+		offset = 3;
+
+	case Q921_DL_DATA:
+		print_hex_bytes(msg + offset, mlen - offset, bb, sizeof(bb));
+		zap_log(ZAP_LOG_DEBUG, "WRITE %d\n%s\n%s\n\n", (int)mlen - offset, LINE, bb);
+		break;
+
+	default:
+		break;
+	}
+
+	return Q921Rx32(pvt, ind, msg, mlen);
 }
 
+static int zap_isdn_q921_log(void *pvt, Q921LogLevel_t level, char *msg, L2INT size)
+{
+	int loglevel = ZAP_LOG_LEVEL_DEBUG;
 
+	switch(level) {
+	case Q921_LOG_DEBUG:
+		loglevel = ZAP_LOG_LEVEL_DEBUG;
+		break;
+
+	case Q921_LOG_INFO:
+		loglevel = ZAP_LOG_LEVEL_INFO;
+		break;
+
+	case Q921_LOG_NOTICE:
+		loglevel = ZAP_LOG_LEVEL_NOTICE;
+		break;
+
+	case Q921_LOG_WARNING:
+		loglevel = ZAP_LOG_LEVEL_WARNING;
+		break;
+
+	case Q921_LOG_ERROR:
+		loglevel = ZAP_LOG_LEVEL_ERROR;
+		break;
+
+	default:
+		return 0;
+	}
+
+	zap_log(__FILE__, "Q.921", __LINE__, loglevel, "%s", msg);
+
+	return 0;
+}
+
 static zap_state_map_t isdn_state_map = {
 	{
 		{
@@ -1113,22 +1247,29 @@
 				   0,
 				   0,
 				   mode,
+				   span->trunk_type == ZAP_TRUNK_BRI_PTMP ? Q921_PTMP : Q921_PTP,
 				   0,
 				   zap_isdn_921_21,
-				   (Q921TxCB_t)zap_isdn_921_23,
+				   (Q921Tx23CB_t)zap_isdn_921_23,
 				   span,
 				   &isdn_data->q931);
+
+	Q921SetLogCB(&isdn_data->q921, &zap_isdn_q921_log, isdn_data);
+	Q921SetLogLevel(&isdn_data->q921, Q921_LOG_DEBUG);
 	
 	Q931Api_InitTrunk(&isdn_data->q931,
 					  dialect,
 					  mode,
 					  span->trunk_type,
 					  zap_isdn_931_34,
-					  (Q931TxCB_t)q931_rx_32,
+					  (Q931Tx32CB_t)q931_rx_32,
 					  zap_isdn_931_err,
 					  &isdn_data->q921,
 					  span);
 
+	Q931SetLogCB(&isdn_data->q931, &zap_isdn_q931_log, isdn_data);
+	Q931SetLogLevel(&isdn_data->q931, Q931_LOG_DEBUG);
+
 	isdn_data->q931.autoRestartAck = 1;
 	isdn_data->q931.autoConnectAck = 1;
 	isdn_data->q931.autoServiceAck = 1;
Index: src/include/zap_types.h
===================================================================
--- src/include/zap_types.h	(revision 495)
+++ src/include/zap_types.h	(working copy)
@@ -117,11 +117,12 @@
 	ZAP_TRUNK_T1,
 	ZAP_TRUNK_J1,
 	ZAP_TRUNK_BRI,
+	ZAP_TRUNK_BRI_PTMP,
 	ZAP_TRUNK_FXO,
 	ZAP_TRUNK_FXS,
 	ZAP_TRUNK_NONE
 } zap_trunk_type_t;
-#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "FXO", "FXS", "NONE"
+#define TRUNK_STRINGS "E1", "T1", "J1", "BRI", "BRI_PTMP", "FXO", "FXS", "NONE"
 ZAP_STR2ENUM_P(zap_str2zap_trunk_type, zap_trunk_type2str, zap_trunk_type_t)
 
 typedef enum {
Index: src/isdn/Q931.c
===================================================================
--- src/isdn/Q931.c	(revision 495)
+++ src/isdn/Q931.c	(working copy)
@@ -36,6 +36,7 @@
   POSSIBILITY OF SUCH DAMAGE.
 *****************************************************************************/
 
+#include "Q921.h"
 #include "Q931.h"
 #include "national.h"
 #include "DMS.h"
@@ -93,10 +94,9 @@
 
 *****************************************************************************/
 
-Q931ErrorCB_t Q931ErrorProc;
-                                    /* callback for error messages.         */
+Q931ErrorCB_t Q931ErrorProc;			/* callback for error messages.         */
 
-L3ULONG (*Q931GetTimeProc) (void) = NULL; /* callback for func reading time in ms */
+L3ULONG (*Q931GetTimeProc) (void) = NULL;	/* callback for func reading time in ms */
 
 /*****************************************************************************
 
@@ -331,36 +331,44 @@
                 see q931errors.h for details.
 
 *****************************************************************************/
-L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT Size)
+L3INT Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT ind, L3UCHAR * buf, L3INT Size)
 {
-    L3UCHAR *Mes = &buf[Q931L2HeaderSpace];
-    L3INT RetCode = Q931E_NO_ERROR;
-    Q931mes_Generic *m = (Q931mes_Generic *) pTrunk->L3Buf;
-    L3INT ISize;
+	L3UCHAR *Mes = buf;
+	L3INT RetCode = Q931E_NO_ERROR;
+	Q931mes_Generic *m = (Q931mes_Generic *) pTrunk->L3Buf;
+	L3INT ISize;
+	L3INT IOff = Q931L2HeaderSpace;
 
-    L3INT IOff = 0;
+	Q931Log(pTrunk, Q931_LOG_DEBUG, "Received message from Q.921 (%d) size: %d\n", ind, Size);
 
-    /* Protocol Discriminator */
-    m->ProtDisc = Mes[IOff++];
+	switch(ind) {
+	case Q921_DL_UNIT_DATA:		/* DL-UNITDATA indication (UI frame, 3 byte header) */
+		IOff = 3;
 
-    /* CRV */
-    m->CRVFlag = Mes[IOff + 1] & 0x80;
-    m->CRV = Q931Uie_CRV(pTrunk, Mes, m->buf, &IOff, &ISize);
+	case Q921_DL_DATA:		/* DL-DATA indication (I frame, 4 byte header) */
+		/* Protocol Discriminator */
+		m->ProtDisc = Mes[IOff++];
 
-    /* Message Type */
-    m->MesType = Mes[IOff++];
+		/* CRV */
+		m->CRVFlag = Mes[IOff + 1] & 0x80;
+		m->CRV = Q931Uie_CRV(pTrunk, Mes, m->buf, &IOff, &ISize);
 
-    /* Call table proc to unpack codec message */
-    /*debug */
-    /* printf("\n\nQ931Rx23-  Dialect: %d, MsgType: %d\n",pTrunk->Dialect,m->MesType); */
-    RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, (Q931mes_Generic *)pTrunk->L3Buf, Q931L4HeaderSpace + IOff , Size - Q931L4HeaderSpace - IOff + 1);
+		/* Message Type */
+		m->MesType = Mes[IOff++];
 
-    if(RetCode >= Q931E_NO_ERROR)
-    {
-        RetCode = Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2);
-    }
+		RetCode = Q931Umes[pTrunk->Dialect][m->MesType](pTrunk, Mes, (Q931mes_Generic *)pTrunk->L3Buf, IOff, Size - IOff + 1);
 
-    return RetCode;
+		if(RetCode >= Q931E_NO_ERROR)
+		{
+			RetCode = Q931Proc[pTrunk->Dialect][m->MesType](pTrunk, pTrunk->L3Buf, 2);
+		}
+		break;
+
+	default:
+		break;
+	}
+
+	return RetCode;
 }
 
 /*****************************************************************************
@@ -378,10 +386,12 @@
 *****************************************************************************/
 L3INT Q931Tx34(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size)
 {
-    if (pTrunk->Q931Tx34CBProc) {
-        return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData34, Mes, Size);
-    }
-    return Q931E_MISSING_CB;    
+	Q931Log(pTrunk, Q931_LOG_DEBUG, "Sending message to Layer4 (size: %d)\n", Size);
+
+	if (pTrunk->Q931Tx34CBProc) {
+		return pTrunk->Q931Tx34CBProc(pTrunk->PrivateData34, Mes, Size);
+	}
+	return Q931E_MISSING_CB;    
 }
 
 /*****************************************************************************
@@ -400,19 +410,18 @@
 *****************************************************************************/
 L3INT Q931Rx43(Q931_TrunkInfo_t *pTrunk,L3UCHAR * buf, L3INT Size)
 {
-    Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
-    L3INT RetCode = Q931E_NO_ERROR;
+	Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
 
-    RetCode=Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk,buf,4);
+	Q931Log(pTrunk, Q931_LOG_DEBUG, "Receiving message from Layer4 (size: %d)\n", Size);
 
-    return RetCode;
+	return Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk,buf,4);;
 }
 
 /*****************************************************************************
 
-  Function:     Q931Tx32
+  Function:     Q931Tx32Data
 
-  Description:  Called from the stack to send a message to L2. The input is 
+  Description:  Called from the stack to send a DL-DATA message to L2. The input is 
                 always a non-packed message so it will first make a proper
                 call to create a packed message before it transmits that
                 message to layer 2.
@@ -425,28 +434,56 @@
                 see q931errors.h for details.
 
 *****************************************************************************/
-L3INT Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size)
+L3INT Q931Tx32Data(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size)
 {
-    L3INT     OSize;
-    Q931mes_Generic *ptr = (Q931mes_Generic*)Mes;
-    L3INT RetCode = Q931E_NO_ERROR;
-    L3INT iDialect = pTrunk->Dialect;
+	Q931mes_Generic *ptr = (Q931mes_Generic*)Mes;
+	L3INT RetCode = Q931E_NO_ERROR;
+	L3INT iDialect = pTrunk->Dialect;
+	L3INT OSize;
 
-    /* Call pack function through table. */
-    RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk, (Q931mes_Generic *)Mes, Size, &pTrunk->L2Buf[Q931L2HeaderSpace], &OSize);
-    if(RetCode >= Q931E_NO_ERROR)
-    {
-        if (pTrunk->Q931Tx32CBProc) {
-            RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData32, pTrunk->L2Buf, OSize + Q931L2HeaderSpace);
-        } else {
-            RetCode = Q931E_MISSING_CB;
-        }
-    }
+	Q931Log(pTrunk, Q931_LOG_DEBUG, "Sending DL-DATA request message to Q.921 (size: %d)\n", Size);
 
-    return RetCode;
+	/* Call pack function through table. */
+	RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk, (Q931mes_Generic *)Mes, Size, &pTrunk->L2Buf[Q931L2HeaderSpace], &OSize);
+	if(RetCode >= Q931E_NO_ERROR)
+	{
+		if (pTrunk->Q931Tx32CBProc) {
+			RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData32, Q921_DL_DATA, pTrunk->L2Buf, OSize + Q931L2HeaderSpace);
+		} else {
+			RetCode = Q931E_MISSING_CB;
+		}
+	}
+
+	return RetCode;
 }
 
+/**
+ * Q931Tx32UnitData
+ * \brief	Used to send a DL-UNIT DATA Request to Layer2
+ */
+L3INT Q931Tx32UnitData(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size)
+{
+	Q931mes_Generic *ptr = (Q931mes_Generic*)Mes;
+	L3INT RetCode = Q931E_NO_ERROR;
+	L3INT iDialect = pTrunk->Dialect;
+	L3INT OSize;
 
+	Q931Log(pTrunk, Q931_LOG_DEBUG, "Sending DL-UNIT DATA request message to Q.921 (size: %d)\n", Size);
+
+	/* Call pack function through table. */
+	RetCode = Q931Pmes[iDialect][ptr->MesType](pTrunk, (Q931mes_Generic *)Mes, Size, &pTrunk->L2Buf[Q931L2HeaderSpace-1], &OSize);
+	if(RetCode >= Q931E_NO_ERROR)
+	{
+		if (pTrunk->Q931Tx32CBProc) {
+			RetCode = pTrunk->Q931Tx32CBProc(pTrunk->PrivateData32, Q921_DL_UNIT_DATA, pTrunk->L2Buf, OSize + Q931L2HeaderSpace - 1);
+		} else {
+			RetCode = Q931E_MISSING_CB;
+		}
+	}
+
+	return RetCode;
+}
+
 /*****************************************************************************
 
   Function:     Q931SetError
@@ -461,16 +498,16 @@
 *****************************************************************************/
 void Q931SetError(Q931_TrunkInfo_t *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2)
 {
-    if (pTrunk->Q931ErrorCBProc) {
-        pTrunk->Q931ErrorCBProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2);
-    } else {
-        Q931ErrorProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2);
-    }
+	if (pTrunk->Q931ErrorCBProc) {
+		pTrunk->Q931ErrorCBProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2);
+	} else {
+		Q931ErrorProc(pTrunk->PrivateData34, ErrID, ErrPar1, ErrPar2);
+	}
 }
 
 void Q931SetDefaultErrorCB(Q931ErrorCB_t Q931ErrorPar)
 {
-    Q931ErrorProc = Q931ErrorPar;
+	Q931ErrorProc = Q931ErrorPar;
 }
 
 /*****************************************************************************
@@ -488,15 +525,15 @@
                 see q931errors.h for details.
 
 *****************************************************************************/
-L3INT    Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex)
+L3INT Q931CreateCRV(Q931_TrunkInfo_t *pTrunk, L3INT * callIndex)
 {
-    L3INT CRV = Q931GetUniqueCRV(pTrunk);
+	L3INT CRV = Q931GetUniqueCRV(pTrunk);
 
-    return Q931AllocateCRV(pTrunk, CRV, callIndex);
+	return Q931AllocateCRV(pTrunk, CRV, callIndex);
 }
 
 
-L3INT	Q931ReleaseCRV(Q931_TrunkInfo_t *pTrunk, L3INT CRV)
+L3INT Q931ReleaseCRV(Q931_TrunkInfo_t *pTrunk, L3INT CRV)
 {
 	int callIndex;
 	
@@ -757,3 +794,51 @@
 }
 
 
+/*
+ * Logging
+ */
+#include <stdarg.h>
+
+L3INT Q931Log(Q931_TrunkInfo_t *trunk, Q931LogLevel_t level, const char *fmt, ...)
+{
+	char  buf[Q931_LOGBUFSIZE];
+	L3INT len;
+	va_list ap;
+
+	if(!trunk->Q931LogCBProc)
+		return 0;
+
+	if(trunk->loglevel < level)
+		return 0;
+
+	va_start(ap, fmt);
+
+	len = vsnprintf(buf, sizeof(buf)-1, fmt, ap);
+	if(len <= 0) {
+		/* TODO: error handling */
+		return -1;
+	}
+
+	va_end(ap);
+
+	return trunk->Q931LogCBProc(trunk->PrivateDataLog, level, buf, strnlen(buf, sizeof(buf)-1));
+}
+
+/**
+ * Q921SetLogCB
+ * \brief	Set Logging callback function and private data
+ */
+void Q931SetLogCB(Q931_TrunkInfo_t *trunk, Q931LogCB_t func, void *priv)
+{
+	trunk->Q931LogCBProc = func;
+	trunk->PrivateDataLog = priv;
+}
+
+/**
+ * Q921SetLogLevel
+ * \brief	Set Loglevel
+ */
+void Q931SetLogLevel(Q931_TrunkInfo_t *trunk, Q931LogLevel_t level)
+{
+	trunk->loglevel = level;
+}
Index: src/isdn/Q931StateNT.c
===================================================================
--- src/isdn/Q931StateNT.c	(revision 495)
+++ src/isdn/Q931StateNT.c	(working copy)
@@ -56,65 +56,65 @@
 *****************************************************************************/
 void Q931CreateNT(L3UCHAR i)
 {
-    Q931SetMesProc(Q931mes_ALERTING,            i,Q931ProcAlertingNT,          Q931Umes_Alerting,          Q931Pmes_Alerting);
-    Q931SetMesProc(Q931mes_CALL_PROCEEDING,     i,Q931ProcCallProceedingNT,    Q931Umes_CallProceeding,    Q931Pmes_CallProceeding);
-    Q931SetMesProc(Q931mes_CONNECT,             i,Q931ProcConnectNT,           Q931Umes_Connect,           Q931Pmes_Connect);
-    Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i,Q931ProcConnectAckNT,        Q931Umes_ConnectAck,        Q931Pmes_ConnectAck);
-    Q931SetMesProc(Q931mes_PROGRESS,            i,Q931ProcProgressNT,          Q931Umes_Progress,          Q931Pmes_Progress);
-    Q931SetMesProc(Q931mes_SETUP,               i,Q931ProcSetupNT,             Q931Umes_Setup,             Q931Pmes_Setup);
-    Q931SetMesProc(Q931mes_SETUP_ACKNOWLEDGE,   i,Q931ProcSetupAckNT,          Q931Umes_SetupAck,          Q931Pmes_SetupAck);
-    Q931SetMesProc(Q931mes_RESUME,              i,Q931ProcResumeNT,            Q931Umes_Resume,            Q931Pmes_Resume);
-    Q931SetMesProc(Q931mes_RESUME_ACKNOWLEDGE,  i,Q931ProcResumeAckNT,         Q931Umes_ResumeAck,         Q931Pmes_ResumeAck);
-    Q931SetMesProc(Q931mes_RESUME_REJECT,       i,Q931ProcResumeRejectNT,      Q931Umes_ResumeReject,      Q931Pmes_ResumeReject);
-    Q931SetMesProc(Q931mes_SUSPEND,             i,Q931ProcSuspendNT,           Q931Umes_Suspend,           Q931Pmes_Suspend);
-    Q931SetMesProc(Q931mes_SUSPEND_ACKNOWLEDGE, i,Q931ProcSuspendAckNT,        Q931Umes_SuspendAck,        Q931Pmes_SuspendAck);
-    Q931SetMesProc(Q931mes_SUSPEND_REJECT,      i,Q931ProcSuspendRejectNT,     Q931Umes_SuspendReject,     Q931Pmes_SuspendReject);
-    Q931SetMesProc(Q931mes_USER_INFORMATION,    i,Q931ProcUserInformationNT,   Q931Umes_UserInformation,   Q931Pmes_UserInformation);
-    Q931SetMesProc(Q931mes_DISCONNECT,          i,Q931ProcDisconnectNT,        Q931Umes_Disconnect,        Q931Pmes_Disconnect);
-    Q931SetMesProc(Q931mes_RELEASE,             i,Q931ProcReleaseNT,           Q931Umes_Release,           Q931Pmes_Release);
-    Q931SetMesProc(Q931mes_RELEASE_COMPLETE,    i,Q931ProcReleaseCompleteNT,   Q931Umes_ReleaseComplete,   Q931Pmes_ReleaseComplete);
-    Q931SetMesProc(Q931mes_RESTART,             i,Q931ProcRestartNT,           Q931Umes_Restart,           Q931Pmes_Restart);
-    Q931SetMesProc(Q931mes_RESTART_ACKNOWLEDGE, i,Q931ProcRestartAckNT,        Q931Umes_RestartAck,        Q931Pmes_RestartAck);
-    Q931SetMesProc(Q931mes_CONGESTION_CONTROL,  i,Q931ProcCongestionControlNT, Q931Umes_CongestionControl, Q931Pmes_CongestionControl);
-    Q931SetMesProc(Q931mes_INFORMATION,         i,Q931ProcInformationNT,       Q931Umes_Information,       Q931Pmes_Information);
-    Q931SetMesProc(Q931mes_NOTIFY,              i,Q931ProcNotifyNT,            Q931Umes_Notify,            Q931Pmes_Notify);
-    Q931SetMesProc(Q931mes_STATUS,              i,Q931ProcStatusNT,            Q931Umes_Status,            Q931Pmes_Status);
-    Q931SetMesProc(Q931mes_STATUS_ENQUIRY,      i,Q931ProcStatusEnquiryNT,     Q931Umes_StatusEnquiry,     Q931Pmes_StatusEnquiry);
-    Q931SetMesProc(Q931mes_SEGMENT,             i,Q931ProcSegmentNT,           Q931Umes_Segment,           Q931Pmes_Segment);
+	Q931SetMesProc(Q931mes_ALERTING,            i,Q931ProcAlertingNT,          Q931Umes_Alerting,          Q931Pmes_Alerting);
+	Q931SetMesProc(Q931mes_CALL_PROCEEDING,     i,Q931ProcCallProceedingNT,    Q931Umes_CallProceeding,    Q931Pmes_CallProceeding);
+	Q931SetMesProc(Q931mes_CONNECT,             i,Q931ProcConnectNT,           Q931Umes_Connect,           Q931Pmes_Connect);
+	Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i,Q931ProcConnectAckNT,        Q931Umes_ConnectAck,        Q931Pmes_ConnectAck);
+	Q931SetMesProc(Q931mes_PROGRESS,            i,Q931ProcProgressNT,          Q931Umes_Progress,          Q931Pmes_Progress);
+	Q931SetMesProc(Q931mes_SETUP,               i,Q931ProcSetupNT,             Q931Umes_Setup,             Q931Pmes_Setup);
+	Q931SetMesProc(Q931mes_SETUP_ACKNOWLEDGE,   i,Q931ProcSetupAckNT,          Q931Umes_SetupAck,          Q931Pmes_SetupAck);
+	Q931SetMesProc(Q931mes_RESUME,              i,Q931ProcResumeNT,            Q931Umes_Resume,            Q931Pmes_Resume);
+	Q931SetMesProc(Q931mes_RESUME_ACKNOWLEDGE,  i,Q931ProcResumeAckNT,         Q931Umes_ResumeAck,         Q931Pmes_ResumeAck);
+	Q931SetMesProc(Q931mes_RESUME_REJECT,       i,Q931ProcResumeRejectNT,      Q931Umes_ResumeReject,      Q931Pmes_ResumeReject);
+	Q931SetMesProc(Q931mes_SUSPEND,             i,Q931ProcSuspendNT,           Q931Umes_Suspend,           Q931Pmes_Suspend);
+	Q931SetMesProc(Q931mes_SUSPEND_ACKNOWLEDGE, i,Q931ProcSuspendAckNT,        Q931Umes_SuspendAck,        Q931Pmes_SuspendAck);
+	Q931SetMesProc(Q931mes_SUSPEND_REJECT,      i,Q931ProcSuspendRejectNT,     Q931Umes_SuspendReject,     Q931Pmes_SuspendReject);
+	Q931SetMesProc(Q931mes_USER_INFORMATION,    i,Q931ProcUserInformationNT,   Q931Umes_UserInformation,   Q931Pmes_UserInformation);
+	Q931SetMesProc(Q931mes_DISCONNECT,          i,Q931ProcDisconnectNT,        Q931Umes_Disconnect,        Q931Pmes_Disconnect);
+	Q931SetMesProc(Q931mes_RELEASE,             i,Q931ProcReleaseNT,           Q931Umes_Release,           Q931Pmes_Release);
+	Q931SetMesProc(Q931mes_RELEASE_COMPLETE,    i,Q931ProcReleaseCompleteNT,   Q931Umes_ReleaseComplete,   Q931Pmes_ReleaseComplete);
+	Q931SetMesProc(Q931mes_RESTART,             i,Q931ProcRestartNT,           Q931Umes_Restart,           Q931Pmes_Restart);
+	Q931SetMesProc(Q931mes_RESTART_ACKNOWLEDGE, i,Q931ProcRestartAckNT,        Q931Umes_RestartAck,        Q931Pmes_RestartAck);
+	Q931SetMesProc(Q931mes_CONGESTION_CONTROL,  i,Q931ProcCongestionControlNT, Q931Umes_CongestionControl, Q931Pmes_CongestionControl);
+	Q931SetMesProc(Q931mes_INFORMATION,         i,Q931ProcInformationNT,       Q931Umes_Information,       Q931Pmes_Information);
+	Q931SetMesProc(Q931mes_NOTIFY,              i,Q931ProcNotifyNT,            Q931Umes_Notify,            Q931Pmes_Notify);
+	Q931SetMesProc(Q931mes_STATUS,              i,Q931ProcStatusNT,            Q931Umes_Status,            Q931Pmes_Status);
+	Q931SetMesProc(Q931mes_STATUS_ENQUIRY,      i,Q931ProcStatusEnquiryNT,     Q931Umes_StatusEnquiry,     Q931Pmes_StatusEnquiry);
+	Q931SetMesProc(Q931mes_SEGMENT,             i,Q931ProcSegmentNT,           Q931Umes_Segment,           Q931Pmes_Segment);
 
-    Q931SetMesProc(Q932mes_FACILITY,            i,Q932ProcFacilityNT,          Q932Umes_Facility,          Q932Pmes_Facility);
-    Q931SetMesProc(Q932mes_HOLD,                i,Q932ProcHoldNT,		       Q932Umes_Hold,              Q932Pmes_Hold);
-    Q931SetMesProc(Q932mes_HOLD_ACKNOWLEDGE,    i,Q932ProcHoldAckNT,           Q932Umes_HoldAck,           Q932Pmes_HoldAck);
-    Q931SetMesProc(Q932mes_HOLD_REJECT,         i,Q932ProcHoldRejectNT,        Q932Umes_HoldReject,        Q932Pmes_HoldReject);
-    Q931SetMesProc(Q932mes_REGISTER,            i,Q932ProcRegisterNT,          Q932Umes_Register,          Q932Pmes_Register);
-    Q931SetMesProc(Q932mes_RETRIEVE,            i,Q932ProcRetrieveNT,          Q932Umes_Retrieve,          Q932Pmes_Retrieve);
-    Q931SetMesProc(Q932mes_RETRIEVE_ACKNOWLEDGE,i,Q932ProcRetrieveAckNT,       Q932Umes_RetrieveAck,       Q932Pmes_RetrieveAck);
-    Q931SetMesProc(Q932mes_RETRIEVE_REJECT,     i,Q932ProcRetrieveRejectNT,    Q932Umes_RetrieveReject,    Q932Pmes_RetrieveReject);
+	Q931SetMesProc(Q932mes_FACILITY,            i,Q932ProcFacilityNT,          Q932Umes_Facility,          Q932Pmes_Facility);
+	Q931SetMesProc(Q932mes_HOLD,                i,Q932ProcHoldNT,		       Q932Umes_Hold,              Q932Pmes_Hold);
+	Q931SetMesProc(Q932mes_HOLD_ACKNOWLEDGE,    i,Q932ProcHoldAckNT,           Q932Umes_HoldAck,           Q932Pmes_HoldAck);
+	Q931SetMesProc(Q932mes_HOLD_REJECT,         i,Q932ProcHoldRejectNT,        Q932Umes_HoldReject,        Q932Pmes_HoldReject);
+	Q931SetMesProc(Q932mes_REGISTER,            i,Q932ProcRegisterNT,          Q932Umes_Register,          Q932Pmes_Register);
+	Q931SetMesProc(Q932mes_RETRIEVE,            i,Q932ProcRetrieveNT,          Q932Umes_Retrieve,          Q932Pmes_Retrieve);
+	Q931SetMesProc(Q932mes_RETRIEVE_ACKNOWLEDGE,i,Q932ProcRetrieveAckNT,       Q932Umes_RetrieveAck,       Q932Pmes_RetrieveAck);
+	Q931SetMesProc(Q932mes_RETRIEVE_REJECT,     i,Q932ProcRetrieveRejectNT,    Q932Umes_RetrieveReject,    Q932Pmes_RetrieveReject);
 
 	/* Set up the IE encoder/decoder handle table.*/ 
-    Q931SetIEProc(Q931ie_SEGMENTED_MESSAGE,                i,Q931Pie_Segment,			Q931Uie_Segment);
-    Q931SetIEProc(Q931ie_BEARER_CAPABILITY,                i,Q931Pie_BearerCap,			Q931Uie_BearerCap);
-    Q931SetIEProc(Q931ie_CAUSE,                            i,Q931Pie_Cause,				Q931Uie_Cause);
-    Q931SetIEProc(Q931ie_CALL_IDENTITY,                    i,Q931Pie_CallID,			Q931Uie_CallID);
-    Q931SetIEProc(Q931ie_CALL_STATE,                       i,Q931Pie_CallState,			Q931Uie_CallState);
-    Q931SetIEProc(Q931ie_CHANNEL_IDENTIFICATION,           i,Q931Pie_ChanID,			Q931Uie_ChanID);
-    Q931SetIEProc(Q931ie_PROGRESS_INDICATOR,               i,Q931Pie_ProgInd,			Q931Uie_ProgInd);
-    Q931SetIEProc(Q931ie_NETWORK_SPECIFIC_FACILITIES,      i,Q931Pie_NetFac,			Q931Uie_NetFac);
-    Q931SetIEProc(Q931ie_NOTIFICATION_INDICATOR,           i,Q931Pie_NotifInd,			Q931Uie_NotifInd);
-    Q931SetIEProc(Q931ie_DISPLAY,                          i,Q931Pie_Display,			Q931Uie_Display);
-    Q931SetIEProc(Q931ie_DATETIME,                         i,Q931Pie_DateTime,			Q931Uie_DateTime);
-    Q931SetIEProc(Q931ie_KEYPAD_FACILITY,                  i,Q931Pie_KeypadFac,			Q931Uie_KeypadFac);
-    Q931SetIEProc(Q931ie_SIGNAL,                           i,Q931Pie_Signal,			Q931Uie_Signal);
-    Q931SetIEProc(Q931ie_TRANSIT_DELAY_SELECTION_AND_IND,  i,Q931Pie_TransNetSel,		Q931Uie_TransNetSel);
-    Q931SetIEProc(Q931ie_CALLING_PARTY_NUMBER,             i,Q931Pie_CallingNum,		Q931Uie_CallingNum);
-    Q931SetIEProc(Q931ie_CALLING_PARTY_SUBADDRESS,         i,Q931Pie_CallingSub,		Q931Uie_CallingSub);
-    Q931SetIEProc(Q931ie_CALLED_PARTY_NUMBER,              i,Q931Pie_CalledNum,			Q931Uie_CalledNum);
-    Q931SetIEProc(Q931ie_CALLED_PARTY_SUBADDRESS,          i,Q931Pie_CalledSub,			Q931Uie_CalledSub);
-    Q931SetIEProc(Q931ie_TRANSIT_NETWORK_SELECTION,        i,Q931Pie_TransNetSel,		Q931Uie_TransNetSel);
-    Q931SetIEProc(Q931ie_RESTART_INDICATOR,                i,Q931Pie_RestartInd,		Q931Uie_RestartInd);
-    Q931SetIEProc(Q931ie_LOW_LAYER_COMPATIBILITY,          i,Q931Pie_LLComp,			Q931Uie_LLComp);
-    Q931SetIEProc(Q931ie_HIGH_LAYER_COMPATIBILITY,         i,Q931Pie_HLComp,			Q931Uie_HLComp);
-    Q931SetIEProc(Q931ie_USER_USER,                        i,Q931Pie_UserUser,			Q931Uie_UserUser);
+	Q931SetIEProc(Q931ie_SEGMENTED_MESSAGE,                i,Q931Pie_Segment,			Q931Uie_Segment);
+	Q931SetIEProc(Q931ie_BEARER_CAPABILITY,                i,Q931Pie_BearerCap,			Q931Uie_BearerCap);
+	Q931SetIEProc(Q931ie_CAUSE,                            i,Q931Pie_Cause,				Q931Uie_Cause);
+	Q931SetIEProc(Q931ie_CALL_IDENTITY,                    i,Q931Pie_CallID,			Q931Uie_CallID);
+	Q931SetIEProc(Q931ie_CALL_STATE,                       i,Q931Pie_CallState,			Q931Uie_CallState);
+	Q931SetIEProc(Q931ie_CHANNEL_IDENTIFICATION,           i,Q931Pie_ChanID,			Q931Uie_ChanID);
+	Q931SetIEProc(Q931ie_PROGRESS_INDICATOR,               i,Q931Pie_ProgInd,			Q931Uie_ProgInd);
+	Q931SetIEProc(Q931ie_NETWORK_SPECIFIC_FACILITIES,      i,Q931Pie_NetFac,			Q931Uie_NetFac);
+	Q931SetIEProc(Q931ie_NOTIFICATION_INDICATOR,           i,Q931Pie_NotifInd,			Q931Uie_NotifInd);
+	Q931SetIEProc(Q931ie_DISPLAY,                          i,Q931Pie_Display,			Q931Uie_Display);
+	Q931SetIEProc(Q931ie_DATETIME,                         i,Q931Pie_DateTime,			Q931Uie_DateTime);
+	Q931SetIEProc(Q931ie_KEYPAD_FACILITY,                  i,Q931Pie_KeypadFac,			Q931Uie_KeypadFac);
+	Q931SetIEProc(Q931ie_SIGNAL,                           i,Q931Pie_Signal,			Q931Uie_Signal);
+	Q931SetIEProc(Q931ie_TRANSIT_DELAY_SELECTION_AND_IND,  i,Q931Pie_TransNetSel,		Q931Uie_TransNetSel);
+	Q931SetIEProc(Q931ie_CALLING_PARTY_NUMBER,             i,Q931Pie_CallingNum,		Q931Uie_CallingNum);
+	Q931SetIEProc(Q931ie_CALLING_PARTY_SUBADDRESS,         i,Q931Pie_CallingSub,		Q931Uie_CallingSub);
+	Q931SetIEProc(Q931ie_CALLED_PARTY_NUMBER,              i,Q931Pie_CalledNum,			Q931Uie_CalledNum);
+	Q931SetIEProc(Q931ie_CALLED_PARTY_SUBADDRESS,          i,Q931Pie_CalledSub,			Q931Uie_CalledSub);
+	Q931SetIEProc(Q931ie_TRANSIT_NETWORK_SELECTION,        i,Q931Pie_TransNetSel,		Q931Uie_TransNetSel);
+	Q931SetIEProc(Q931ie_RESTART_INDICATOR,                i,Q931Pie_RestartInd,		Q931Uie_RestartInd);
+	Q931SetIEProc(Q931ie_LOW_LAYER_COMPATIBILITY,          i,Q931Pie_LLComp,			Q931Uie_LLComp);
+	Q931SetIEProc(Q931ie_HIGH_LAYER_COMPATIBILITY,         i,Q931Pie_HLComp,			Q931Uie_HLComp);
+	Q931SetIEProc(Q931ie_USER_USER,                        i,Q931Pie_UserUser,			Q931Uie_UserUser);
 
 	/* The following define a state machine. The point is that the Message	*/
 	/* procs can when search this to find out if the message/state			*/
@@ -130,8 +130,8 @@
 *****************************************************************************/
 L3INT Q931ProcAlertingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -140,14 +140,14 @@
 		return ret;
 
 	/* Reset 4 sec timer. */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -159,8 +159,8 @@
 *****************************************************************************/
 L3INT Q931ProcCallProceedingNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -168,19 +168,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -192,8 +192,8 @@
 *****************************************************************************/
 L3INT Q931ProcConnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -201,19 +201,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
 		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
 		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -225,8 +225,8 @@
 *****************************************************************************/
 L3INT Q931ProcConnectAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -234,19 +234,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -258,8 +258,8 @@
 *****************************************************************************/
 L3INT Q931ProcProgressNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -267,19 +267,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -293,70 +293,67 @@
  *****************************************************************************/
 L3INT Q931ProcSetupNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT rc=0;
+	L3INT rc=0;
 	Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace];
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 
-    /* Reject SETUP on existing calls */
-    if(Q931GetCallState(pTrunk, pMes->CRV) != Q931_U0)
-    {
-        Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81);
-        return Q931E_UNEXPECTED_MESSAGE;
-    }
+	/* Reject SETUP on existing calls */
+	if(Q931GetCallState(pTrunk, pMes->CRV) != Q931_U0)
+	{
+		Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81);
+		return Q931E_UNEXPECTED_MESSAGE;
+	}
 
 	/* outgoing call */
-    if(iFrom == 4)
-    {
-        ret = Q931CreateCRV(pTrunk, &callIndex);
-        if(ret)
-            return ret;
-        pMes->CRV = pTrunk->call[callIndex].CRV;
+	if(iFrom == 4)
+	{
+		ret = Q931CreateCRV(pTrunk, &callIndex);
+		if(ret)
+			return ret;
+		pMes->CRV = pTrunk->call[callIndex].CRV;
 
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
-        if(ret)
-            return ret;
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
+		if(ret)
+			return ret;
 
-        Q931StartTimer(pTrunk, callIndex, 303);
+		Q931StartTimer(pTrunk, callIndex, 303);
 
-        Q931SetState(pTrunk, callIndex, Q931_U1);
-    }
+		Q931SetState(pTrunk, callIndex, Q931_U1);
+	}
 	/* incoming call */
-    else 
-    {
-        /* Locate free CRV entry and store info */
-        ret = Q931AllocateCRV(pTrunk, pMes->CRV, &callIndex);
-        if(ret != Q931E_NO_ERROR)
-        {
-            /* Not possible to allocate CRV entry, so must reject call */
+	else 
+	{
+		/* Locate free CRV entry and store info */
+		ret = Q931AllocateCRV(pTrunk, pMes->CRV, &callIndex);
+		if(ret != Q931E_NO_ERROR)
+		{
+			/* Not possible to allocate CRV entry, so must reject call */
+			Q931Disconnect(pTrunk, iFrom, pMes->CRV, 42);
 
-            Q931Disconnect(pTrunk, iFrom, pMes->CRV, 42);
+			return ret;
+		}
 
-            return ret;
-        }
-
-        /* Send setup indication to user */
-        ret = Q931Tx34(pTrunk,(L3UCHAR*)pMes,pMes->Size);
-        if(ret != Q931E_NO_ERROR)
-            return ret;
+		/* Send setup indication to user */
+		ret = Q931Tx34(pTrunk,(L3UCHAR*)pMes,pMes->Size);
+		if(ret != Q931E_NO_ERROR)
+			return ret;
 		else
 		{
 			/* Must be full queue, meaning we can't process the call */
 			/* so we must disconnect */
-	        Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81);
-	        return ret;
+			Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81);
+			return ret;
 		}
 
 #if 0
 		/* TODO: Unreachable code??? */
-        /* Set state U6 */
-        Q931SetState(pTrunk, callIndex, Q931_U6);
+		/* Set state U6 */
+		Q931SetState(pTrunk, callIndex, Q931_U6);
 
-        Q931StartTimer(pTrunk, callIndex, 303);
+		Q931StartTimer(pTrunk, callIndex, 303);
 #endif
-
 	}
-
 	return rc;
 }
 
@@ -373,8 +370,8 @@
 *****************************************************************************/
 L3INT Q931ProcSetupAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -382,19 +379,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -406,8 +403,8 @@
 *****************************************************************************/
 L3INT Q931ProcResumeNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -415,19 +412,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -439,8 +436,8 @@
 *****************************************************************************/
 L3INT Q931ProcResumeAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -448,19 +445,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -472,8 +469,8 @@
 *****************************************************************************/
 L3INT Q931ProcResumeRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -481,19 +478,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -505,8 +502,8 @@
 *****************************************************************************/
 L3INT Q931ProcSuspendNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -514,19 +511,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -538,8 +535,8 @@
 *****************************************************************************/
 L3INT Q931ProcSuspendAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -547,19 +544,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -571,8 +568,8 @@
 *****************************************************************************/
 L3INT Q931ProcSuspendRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -583,16 +580,16 @@
 	/* TODO chack against state table for illegal or unexpected message here*/
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -604,8 +601,8 @@
 *****************************************************************************/
 L3INT Q931ProcUserInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -613,19 +610,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -637,8 +634,8 @@
 *****************************************************************************/
 L3INT Q931ProcDisconnectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -646,19 +643,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -670,8 +667,8 @@
 *****************************************************************************/
 L3INT Q931ProcReleaseNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -679,19 +676,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -703,8 +700,8 @@
 *****************************************************************************/
 L3INT Q931ProcReleaseCompleteNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -712,19 +709,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -736,8 +733,8 @@
 *****************************************************************************/
 L3INT Q931ProcRestartNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -745,19 +742,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -769,8 +766,8 @@
 *****************************************************************************/
 L3INT Q931ProcRestartAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -778,19 +775,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -802,8 +799,8 @@
 *****************************************************************************/
 L3INT Q931ProcCongestionControlNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -811,19 +808,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -835,8 +832,8 @@
 *****************************************************************************/
 L3INT Q931ProcInformationNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -844,19 +841,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -868,8 +865,8 @@
 *****************************************************************************/
 L3INT Q931ProcNotifyNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -877,19 +874,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -901,8 +898,8 @@
 *****************************************************************************/
 L3INT Q931ProcStatusNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -910,19 +907,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -934,8 +931,8 @@
 *****************************************************************************/
 L3INT Q931ProcStatusEnquiryNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -943,19 +940,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -967,8 +964,8 @@
 *****************************************************************************/
 L3INT Q931ProcSegmentNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -976,19 +973,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1004,8 +1001,8 @@
 *****************************************************************************/
 L3INT Q932ProcFacilityNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1013,19 +1010,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1037,8 +1034,8 @@
 *****************************************************************************/
 L3INT Q932ProcHoldNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1046,19 +1043,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1070,8 +1067,8 @@
 *****************************************************************************/
 L3INT Q932ProcHoldAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1079,19 +1076,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1103,8 +1100,8 @@
 *****************************************************************************/
 L3INT Q932ProcHoldRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1112,19 +1109,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1136,8 +1133,8 @@
 *****************************************************************************/
 L3INT Q932ProcRegisterNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1145,19 +1142,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1169,8 +1166,8 @@
 *****************************************************************************/
 L3INT Q932ProcRetrieveNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1178,19 +1175,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1202,8 +1199,8 @@
 *****************************************************************************/
 L3INT Q932ProcRetrieveAckNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1211,19 +1208,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1235,8 +1232,8 @@
 *****************************************************************************/
 L3INT Q932ProcRetrieveRejectNT(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1244,19 +1241,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
Index: src/isdn/Q931StateTE.c
===================================================================
--- src/isdn/Q931StateTE.c	(revision 495)
+++ src/isdn/Q931StateTE.c	(working copy)
@@ -63,65 +63,65 @@
 *****************************************************************************/
 void Q931CreateTE(L3UCHAR i)
 {
-    Q931SetMesProc(Q931mes_ALERTING,            i,Q931ProcAlertingTE,          Q931Umes_Alerting,          Q931Pmes_Alerting);
-    Q931SetMesProc(Q931mes_CALL_PROCEEDING,     i,Q931ProcCallProceedingTE,    Q931Umes_CallProceeding,    Q931Pmes_CallProceeding);
-    Q931SetMesProc(Q931mes_CONNECT,             i,Q931ProcConnectTE,           Q931Umes_Connect,           Q931Pmes_Connect);
-    Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i,Q931ProcConnectAckTE,        Q931Umes_ConnectAck,        Q931Pmes_ConnectAck);
-    Q931SetMesProc(Q931mes_PROGRESS,            i,Q931ProcProgressTE,          Q931Umes_Progress,          Q931Pmes_Progress);
-    Q931SetMesProc(Q931mes_SETUP,               i,Q931ProcSetupTE,             Q931Umes_Setup,             Q931Pmes_Setup);
-    Q931SetMesProc(Q931mes_SETUP_ACKNOWLEDGE,   i,Q931ProcSetupAckTE,          Q931Umes_SetupAck,          Q931Pmes_SetupAck);
-    Q931SetMesProc(Q931mes_RESUME,              i,Q931ProcResumeTE,            Q931Umes_Resume,            Q931Pmes_Resume);
-    Q931SetMesProc(Q931mes_RESUME_ACKNOWLEDGE,  i,Q931ProcResumeAckTE,         Q931Umes_ResumeAck,         Q931Pmes_ResumeAck);
-    Q931SetMesProc(Q931mes_RESUME_REJECT,       i,Q931ProcResumeRejectTE,      Q931Umes_ResumeReject,      Q931Pmes_ResumeReject);
-    Q931SetMesProc(Q931mes_SUSPEND,             i,Q931ProcSuspendTE,           Q931Umes_Suspend,           Q931Pmes_Suspend);
-    Q931SetMesProc(Q931mes_SUSPEND_ACKNOWLEDGE, i,Q931ProcSuspendAckTE,        Q931Umes_SuspendAck,        Q931Pmes_SuspendAck);
-    Q931SetMesProc(Q931mes_SUSPEND_REJECT,      i,Q931ProcSuspendRejectTE,     Q931Umes_SuspendReject,     Q931Pmes_SuspendReject);
-    Q931SetMesProc(Q931mes_USER_INFORMATION,    i,Q931ProcUserInformationTE,   Q931Umes_UserInformation,   Q931Pmes_UserInformation);
-    Q931SetMesProc(Q931mes_DISCONNECT,          i,Q931ProcDisconnectTE,        Q931Umes_Disconnect,        Q931Pmes_Disconnect);
-    Q931SetMesProc(Q931mes_RELEASE,             i,Q931ProcReleaseTE,           Q931Umes_Release,           Q931Pmes_Release);
-    Q931SetMesProc(Q931mes_RELEASE_COMPLETE,    i,Q931ProcReleaseCompleteTE,   Q931Umes_ReleaseComplete,   Q931Pmes_ReleaseComplete);
-    Q931SetMesProc(Q931mes_RESTART,             i,Q931ProcRestartTE,           Q931Umes_Restart,           Q931Pmes_Restart);
-    Q931SetMesProc(Q931mes_RESTART_ACKNOWLEDGE, i,Q931ProcRestartAckTE,        Q931Umes_RestartAck,        Q931Pmes_RestartAck);
-    Q931SetMesProc(Q931mes_CONGESTION_CONTROL,  i,Q931ProcCongestionControlTE, Q931Umes_CongestionControl, Q931Pmes_CongestionControl);
-    Q931SetMesProc(Q931mes_INFORMATION,         i,Q931ProcInformationTE,       Q931Umes_Information,       Q931Pmes_Information);
-    Q931SetMesProc(Q931mes_NOTIFY,              i,Q931ProcNotifyTE,            Q931Umes_Notify,            Q931Pmes_Notify);
-    Q931SetMesProc(Q931mes_STATUS,              i,Q931ProcStatusTE,            Q931Umes_Status,            Q931Pmes_Status);
-    Q931SetMesProc(Q931mes_STATUS_ENQUIRY,      i,Q931ProcStatusEnquiryTE,     Q931Umes_StatusEnquiry,     Q931Pmes_StatusEnquiry);
-    Q931SetMesProc(Q931mes_SEGMENT,             i,Q931ProcSegmentTE,           Q931Umes_Segment,           Q931Pmes_Segment);
+	Q931SetMesProc(Q931mes_ALERTING,            i,Q931ProcAlertingTE,          Q931Umes_Alerting,          Q931Pmes_Alerting);
+	Q931SetMesProc(Q931mes_CALL_PROCEEDING,     i,Q931ProcCallProceedingTE,    Q931Umes_CallProceeding,    Q931Pmes_CallProceeding);
+	Q931SetMesProc(Q931mes_CONNECT,             i,Q931ProcConnectTE,           Q931Umes_Connect,           Q931Pmes_Connect);
+	Q931SetMesProc(Q931mes_CONNECT_ACKNOWLEDGE, i,Q931ProcConnectAckTE,        Q931Umes_ConnectAck,        Q931Pmes_ConnectAck);
+	Q931SetMesProc(Q931mes_PROGRESS,            i,Q931ProcProgressTE,          Q931Umes_Progress,          Q931Pmes_Progress);
+	Q931SetMesProc(Q931mes_SETUP,               i,Q931ProcSetupTE,             Q931Umes_Setup,             Q931Pmes_Setup);
+	Q931SetMesProc(Q931mes_SETUP_ACKNOWLEDGE,   i,Q931ProcSetupAckTE,          Q931Umes_SetupAck,          Q931Pmes_SetupAck);
+	Q931SetMesProc(Q931mes_RESUME,              i,Q931ProcResumeTE,            Q931Umes_Resume,            Q931Pmes_Resume);
+	Q931SetMesProc(Q931mes_RESUME_ACKNOWLEDGE,  i,Q931ProcResumeAckTE,         Q931Umes_ResumeAck,         Q931Pmes_ResumeAck);
+	Q931SetMesProc(Q931mes_RESUME_REJECT,       i,Q931ProcResumeRejectTE,      Q931Umes_ResumeReject,      Q931Pmes_ResumeReject);
+	Q931SetMesProc(Q931mes_SUSPEND,             i,Q931ProcSuspendTE,           Q931Umes_Suspend,           Q931Pmes_Suspend);
+	Q931SetMesProc(Q931mes_SUSPEND_ACKNOWLEDGE, i,Q931ProcSuspendAckTE,        Q931Umes_SuspendAck,        Q931Pmes_SuspendAck);
+	Q931SetMesProc(Q931mes_SUSPEND_REJECT,      i,Q931ProcSuspendRejectTE,     Q931Umes_SuspendReject,     Q931Pmes_SuspendReject);
+	Q931SetMesProc(Q931mes_USER_INFORMATION,    i,Q931ProcUserInformationTE,   Q931Umes_UserInformation,   Q931Pmes_UserInformation);
+	Q931SetMesProc(Q931mes_DISCONNECT,          i,Q931ProcDisconnectTE,        Q931Umes_Disconnect,        Q931Pmes_Disconnect);
+	Q931SetMesProc(Q931mes_RELEASE,             i,Q931ProcReleaseTE,           Q931Umes_Release,           Q931Pmes_Release);
+	Q931SetMesProc(Q931mes_RELEASE_COMPLETE,    i,Q931ProcReleaseCompleteTE,   Q931Umes_ReleaseComplete,   Q931Pmes_ReleaseComplete);
+	Q931SetMesProc(Q931mes_RESTART,             i,Q931ProcRestartTE,           Q931Umes_Restart,           Q931Pmes_Restart);
+	Q931SetMesProc(Q931mes_RESTART_ACKNOWLEDGE, i,Q931ProcRestartAckTE,        Q931Umes_RestartAck,        Q931Pmes_RestartAck);
+	Q931SetMesProc(Q931mes_CONGESTION_CONTROL,  i,Q931ProcCongestionControlTE, Q931Umes_CongestionControl, Q931Pmes_CongestionControl);
+	Q931SetMesProc(Q931mes_INFORMATION,         i,Q931ProcInformationTE,       Q931Umes_Information,       Q931Pmes_Information);
+	Q931SetMesProc(Q931mes_NOTIFY,              i,Q931ProcNotifyTE,            Q931Umes_Notify,            Q931Pmes_Notify);
+	Q931SetMesProc(Q931mes_STATUS,              i,Q931ProcStatusTE,            Q931Umes_Status,            Q931Pmes_Status);
+	Q931SetMesProc(Q931mes_STATUS_ENQUIRY,      i,Q931ProcStatusEnquiryTE,     Q931Umes_StatusEnquiry,     Q931Pmes_StatusEnquiry);
+	Q931SetMesProc(Q931mes_SEGMENT,             i,Q931ProcSegmentTE,           Q931Umes_Segment,           Q931Pmes_Segment);
 
-    Q931SetMesProc(Q932mes_FACILITY,            i,Q932ProcFacilityTE,          Q932Umes_Facility,          Q932Pmes_Facility);
-    Q931SetMesProc(Q932mes_HOLD,                i,Q932ProcHoldTE,		       Q932Umes_Hold,              Q932Pmes_Hold);
-    Q931SetMesProc(Q932mes_HOLD_ACKNOWLEDGE,    i,Q932ProcHoldAckTE,           Q932Umes_HoldAck,           Q932Pmes_HoldAck);
-    Q931SetMesProc(Q932mes_HOLD_REJECT,         i,Q932ProcHoldRejectTE,        Q932Umes_HoldReject,        Q932Pmes_HoldReject);
-    Q931SetMesProc(Q932mes_REGISTER,            i,Q932ProcRegisterTE,          Q932Umes_Register,          Q932Pmes_Register);
-    Q931SetMesProc(Q932mes_RETRIEVE,            i,Q932ProcRetrieveTE,          Q932Umes_Retrieve,          Q932Pmes_Retrieve);
-    Q931SetMesProc(Q932mes_RETRIEVE_ACKNOWLEDGE,i,Q932ProcRetrieveAckTE,       Q932Umes_RetrieveAck,       Q932Pmes_RetrieveAck);
-    Q931SetMesProc(Q932mes_RETRIEVE_REJECT,     i,Q932ProcRetrieveRejectTE,    Q932Umes_RetrieveReject,    Q932Pmes_RetrieveReject);
+	Q931SetMesProc(Q932mes_FACILITY,            i,Q932ProcFacilityTE,          Q932Umes_Facility,          Q932Pmes_Facility);
+	Q931SetMesProc(Q932mes_HOLD,                i,Q932ProcHoldTE,		       Q932Umes_Hold,              Q932Pmes_Hold);
+	Q931SetMesProc(Q932mes_HOLD_ACKNOWLEDGE,    i,Q932ProcHoldAckTE,           Q932Umes_HoldAck,           Q932Pmes_HoldAck);
+	Q931SetMesProc(Q932mes_HOLD_REJECT,         i,Q932ProcHoldRejectTE,        Q932Umes_HoldReject,        Q932Pmes_HoldReject);
+	Q931SetMesProc(Q932mes_REGISTER,            i,Q932ProcRegisterTE,          Q932Umes_Register,          Q932Pmes_Register);
+	Q931SetMesProc(Q932mes_RETRIEVE,            i,Q932ProcRetrieveTE,          Q932Umes_Retrieve,          Q932Pmes_Retrieve);
+	Q931SetMesProc(Q932mes_RETRIEVE_ACKNOWLEDGE,i,Q932ProcRetrieveAckTE,       Q932Umes_RetrieveAck,       Q932Pmes_RetrieveAck);
+	Q931SetMesProc(Q932mes_RETRIEVE_REJECT,     i,Q932ProcRetrieveRejectTE,    Q932Umes_RetrieveReject,    Q932Pmes_RetrieveReject);
 
 	/* Set up the IE encoder/decoder handle table.*/ 
-    Q931SetIEProc(Q931ie_SEGMENTED_MESSAGE,                i,Q931Pie_Segment,			Q931Uie_Segment);
-    Q931SetIEProc(Q931ie_BEARER_CAPABILITY,                i,Q931Pie_BearerCap,			Q931Uie_BearerCap);
-    Q931SetIEProc(Q931ie_CAUSE,                            i,Q931Pie_Cause,				Q931Uie_Cause);
-    Q931SetIEProc(Q931ie_CALL_IDENTITY,                    i,Q931Pie_CallID,			Q931Uie_CallID);
-    Q931SetIEProc(Q931ie_CALL_STATE,                       i,Q931Pie_CallState,			Q931Uie_CallState);
-    Q931SetIEProc(Q931ie_CHANNEL_IDENTIFICATION,           i,Q931Pie_ChanID,			Q931Uie_ChanID);
-    Q931SetIEProc(Q931ie_PROGRESS_INDICATOR,               i,Q931Pie_ProgInd,			Q931Uie_ProgInd);
-    Q931SetIEProc(Q931ie_NETWORK_SPECIFIC_FACILITIES,      i,Q931Pie_NetFac,			Q931Uie_NetFac);
-    Q931SetIEProc(Q931ie_NOTIFICATION_INDICATOR,           i,Q931Pie_NotifInd,			Q931Uie_NotifInd);
-    Q931SetIEProc(Q931ie_DISPLAY,                          i,Q931Pie_Display,			Q931Uie_Display);
-    Q931SetIEProc(Q931ie_DATETIME,                         i,Q931Pie_DateTime,			Q931Uie_DateTime);
-    Q931SetIEProc(Q931ie_KEYPAD_FACILITY,                  i,Q931Pie_KeypadFac,			Q931Uie_KeypadFac);
-    Q931SetIEProc(Q931ie_SIGNAL,                           i,Q931Pie_Signal,			Q931Uie_Signal);
-    Q931SetIEProc(Q931ie_TRANSIT_DELAY_SELECTION_AND_IND,  i,Q931Pie_TransNetSel,		Q931Uie_TransNetSel);
-    Q931SetIEProc(Q931ie_CALLING_PARTY_NUMBER,             i,Q931Pie_CallingNum,		Q931Uie_CallingNum);
-    Q931SetIEProc(Q931ie_CALLING_PARTY_SUBADDRESS,         i,Q931Pie_CallingSub,		Q931Uie_CallingSub);
-    Q931SetIEProc(Q931ie_CALLED_PARTY_NUMBER,              i,Q931Pie_CalledNum,			Q931Uie_CalledNum);
-    Q931SetIEProc(Q931ie_CALLED_PARTY_SUBADDRESS,          i,Q931Pie_CalledSub,			Q931Uie_CalledSub);
-    Q931SetIEProc(Q931ie_TRANSIT_NETWORK_SELECTION,        i,Q931Pie_TransNetSel,		Q931Uie_TransNetSel);
-    Q931SetIEProc(Q931ie_RESTART_INDICATOR,                i,Q931Pie_RestartInd,		Q931Uie_RestartInd);
-    Q931SetIEProc(Q931ie_LOW_LAYER_COMPATIBILITY,          i,Q931Pie_LLComp,			Q931Uie_LLComp);
-    Q931SetIEProc(Q931ie_HIGH_LAYER_COMPATIBILITY,         i,Q931Pie_HLComp,			Q931Uie_HLComp);
-    Q931SetIEProc(Q931ie_USER_USER,                        i,Q931Pie_UserUser,			Q931Uie_UserUser);
+	Q931SetIEProc(Q931ie_SEGMENTED_MESSAGE,                i,Q931Pie_Segment,			Q931Uie_Segment);
+	Q931SetIEProc(Q931ie_BEARER_CAPABILITY,                i,Q931Pie_BearerCap,			Q931Uie_BearerCap);
+	Q931SetIEProc(Q931ie_CAUSE,                            i,Q931Pie_Cause,				Q931Uie_Cause);
+	Q931SetIEProc(Q931ie_CALL_IDENTITY,                    i,Q931Pie_CallID,			Q931Uie_CallID);
+	Q931SetIEProc(Q931ie_CALL_STATE,                       i,Q931Pie_CallState,			Q931Uie_CallState);
+	Q931SetIEProc(Q931ie_CHANNEL_IDENTIFICATION,           i,Q931Pie_ChanID,			Q931Uie_ChanID);
+	Q931SetIEProc(Q931ie_PROGRESS_INDICATOR,               i,Q931Pie_ProgInd,			Q931Uie_ProgInd);
+	Q931SetIEProc(Q931ie_NETWORK_SPECIFIC_FACILITIES,      i,Q931Pie_NetFac,			Q931Uie_NetFac);
+	Q931SetIEProc(Q931ie_NOTIFICATION_INDICATOR,           i,Q931Pie_NotifInd,			Q931Uie_NotifInd);
+	Q931SetIEProc(Q931ie_DISPLAY,                          i,Q931Pie_Display,			Q931Uie_Display);
+	Q931SetIEProc(Q931ie_DATETIME,                         i,Q931Pie_DateTime,			Q931Uie_DateTime);
+	Q931SetIEProc(Q931ie_KEYPAD_FACILITY,                  i,Q931Pie_KeypadFac,			Q931Uie_KeypadFac);
+	Q931SetIEProc(Q931ie_SIGNAL,                           i,Q931Pie_Signal,			Q931Uie_Signal);
+	Q931SetIEProc(Q931ie_TRANSIT_DELAY_SELECTION_AND_IND,  i,Q931Pie_TransNetSel,		Q931Uie_TransNetSel);
+	Q931SetIEProc(Q931ie_CALLING_PARTY_NUMBER,             i,Q931Pie_CallingNum,		Q931Uie_CallingNum);
+	Q931SetIEProc(Q931ie_CALLING_PARTY_SUBADDRESS,         i,Q931Pie_CallingSub,		Q931Uie_CallingSub);
+	Q931SetIEProc(Q931ie_CALLED_PARTY_NUMBER,              i,Q931Pie_CalledNum,			Q931Uie_CalledNum);
+	Q931SetIEProc(Q931ie_CALLED_PARTY_SUBADDRESS,          i,Q931Pie_CalledSub,			Q931Uie_CalledSub);
+	Q931SetIEProc(Q931ie_TRANSIT_NETWORK_SELECTION,        i,Q931Pie_TransNetSel,		Q931Uie_TransNetSel);
+	Q931SetIEProc(Q931ie_RESTART_INDICATOR,                i,Q931Pie_RestartInd,		Q931Uie_RestartInd);
+	Q931SetIEProc(Q931ie_LOW_LAYER_COMPATIBILITY,          i,Q931Pie_LLComp,			Q931Uie_LLComp);
+	Q931SetIEProc(Q931ie_HIGH_LAYER_COMPATIBILITY,         i,Q931Pie_HLComp,			Q931Uie_HLComp);
+	Q931SetIEProc(Q931ie_USER_USER,                        i,Q931Pie_UserUser,			Q931Uie_UserUser);
 
 	/* The following define a state machine. The point is that the Message	*/
 	/* procs can when search this to find out if the message/state			*/
@@ -214,8 +214,8 @@
 *****************************************************************************/
 L3INT Q931ProcAlertingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -224,14 +224,14 @@
 		return ret;
 
 	/* Reset 4 sec timer. */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -243,8 +243,8 @@
 *****************************************************************************/
 L3INT Q931ProcCallProceedingTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -252,19 +252,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -276,8 +276,8 @@
 *****************************************************************************/
 L3INT Q931ProcConnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -285,19 +285,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 		if (pTrunk->autoConnectAck) {
 			Q931AckConnect(pTrunk, buf);
 		}
@@ -313,8 +313,8 @@
 *****************************************************************************/
 L3INT Q931ProcConnectAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -322,19 +322,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -346,8 +346,8 @@
 *****************************************************************************/
 L3INT Q931ProcProgressTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -355,19 +355,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -379,73 +379,78 @@
 *****************************************************************************/
 L3INT Q931ProcSetupTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT rc=0;
+	L3INT rc=0;
 	Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace];
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 
-    /* Reject SETUP on existing calls */
-    if(Q931GetCallState(pTrunk, pMes->CRV) != Q931_U0)
-    {
-        Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81);
-        return Q931E_UNEXPECTED_MESSAGE;
-    }
+	/* Reject SETUP on existing calls */
+	if(Q931GetCallState(pTrunk, pMes->CRV) != Q931_U0)
+	{
+		Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81);
+		return Q931E_UNEXPECTED_MESSAGE;
+	}
 
 	/* outgoing call */
-    if(iFrom == 4)
-    {
-        ret = Q931CreateCRV(pTrunk, &callIndex);
-        if(ret)
-            return ret;
-        pMes->CRV = pTrunk->call[callIndex].CRV;
+	if(iFrom == 4)
+	{
+		ret = Q931CreateCRV(pTrunk, &callIndex);
+		if(ret)
+			return ret;
+		pMes->CRV = pTrunk->call[callIndex].CRV;
 
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
-        if(ret)
-            return ret;
+		/*
+		 * PTMP NT should use DL-UNIT DATA broadcast (?)
+		 */ 
+		if(pTrunk->TrunkType == Q931_TrType_BRI_PTMP && pTrunk->NetUser == Q931_NT)
+			ret = Q931Tx32UnitData(pTrunk,buf,pMes->Size);
+		else
+			ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 
-        Q931StartTimer(pTrunk, callIndex, 303);
+		if(ret)
+			return ret;
 
+		Q931StartTimer(pTrunk, callIndex, 303);
+
 		/* TODO: Add this back when we get the state stuff more filled out */
-        //Q931SetState(pTrunk, callIndex, Q931_U1);
-    }
+		//Q931SetState(pTrunk, callIndex, Q931_U1);
+	}
 	/* incoming call */
-    else 
-    {
-        /* Locate free CRV entry and store info */
-        ret = Q931AllocateCRV(pTrunk, pMes->CRV, &callIndex);
-        if(ret != Q931E_NO_ERROR)
-        {
-            /* Not possible to allocate CRV entry, so must reject call */
+	else 
+	{
+		/* Locate free CRV entry and store info */
+		ret = Q931AllocateCRV(pTrunk, pMes->CRV, &callIndex);
+		if(ret != Q931E_NO_ERROR)
+		{
+			/* Not possible to allocate CRV entry, so must reject call */
+			Q931Disconnect(pTrunk, iFrom, pMes->CRV, 42);
 
-            Q931Disconnect(pTrunk, iFrom, pMes->CRV, 42);
+			return ret;
+		}
 
-            return ret;
-        }
-
-        /* Send setup indication to user */
-        ret = Q931Tx34(pTrunk,(L3UCHAR*)pMes,pMes->Size);
+		/* Send setup indication to user */
+		ret = Q931Tx34(pTrunk,(L3UCHAR*)pMes,pMes->Size);
 		if(ret != Q931E_NO_ERROR) {
 			if (pTrunk->autoSetupAck) {
 				Q931AckSetup(pTrunk, buf);
 			}
-            return ret;
+			return ret;
 		}
 		else
 		{
 			/* Must be full queue, meaning we can't process the call */
 			/* so we must disconnect */
-	        Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81);
-	        return ret;
+		        Q931Disconnect(pTrunk, iFrom, pMes->CRV, 81);
+		        return ret;
 		}
 #if 0
 		/* TODO: Unreachable code??? */
-        /* Set state U6 */
-        Q931SetState(pTrunk, callIndex, Q931_U6);
+		/* Set state U6 */
+		Q931SetState(pTrunk, callIndex, Q931_U6);
 
-        Q931StartTimer(pTrunk, callIndex, 303);
+		Q931StartTimer(pTrunk, callIndex, 303);
 #endif
-    }
-
+	}
 	return rc;
 }
 
@@ -464,22 +469,22 @@
 *****************************************************************************/
 L3INT Q931ProcSetupAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-        Q931StartTimer(pTrunk, callIndex, 303);
+		Q931StartTimer(pTrunk, callIndex, 303);
 	}
 	return ret;
 }
@@ -491,34 +496,34 @@
 *****************************************************************************/
 L3INT Q931ProcResumeTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    Q931mes_Generic * pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace];
-    L3INT callIndex;
-    L3INT ret = Q931E_NO_ERROR;
+	Q931mes_Generic * pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace];
+	L3INT callIndex;
+	L3INT ret = Q931E_NO_ERROR;
 
-    if(Q931GetCallState(pTrunk,pMes->CRV) == Q931_U0 && iFrom == 4)
-    {
-        /* Call reference selection */
-        ret = Q931CreateCRV(pTrunk, &callIndex);
-        if(ret != Q931E_NO_ERROR)
-            return ret;
-        pMes->CRV = pTrunk->call[callIndex].CRV;
+	if(Q931GetCallState(pTrunk,pMes->CRV) == Q931_U0 && iFrom == 4)
+	{
+		/* Call reference selection */
+		ret = Q931CreateCRV(pTrunk, &callIndex);
+		if(ret != Q931E_NO_ERROR)
+			return ret;
+		pMes->CRV = pTrunk->call[callIndex].CRV;
 
-        /* Send RESUME to network */
-        ret=Q931Tx32(pTrunk,buf, pMes->Size);
-        if(ret != Q931E_NO_ERROR)
-            return ret;
+		/* Send RESUME to network */
+		ret=Q931Tx32Data(pTrunk,buf, pMes->Size);
+		if(ret != Q931E_NO_ERROR)
+			return ret;
 
-        /* Start timer T318 */
-        Q931StartTimer(pTrunk, callIndex, 318);
+		/* Start timer T318 */
+		Q931StartTimer(pTrunk, callIndex, 318);
 
-        /*set state U17 */
-        Q931SetState(pTrunk, callIndex, Q931_U17);
-    }
-    else
-    {
-        return Q931E_ILLEGAL_MESSAGE;
-    }
-    return ret;
+		/*set state U17 */
+		Q931SetState(pTrunk, callIndex, Q931_U17);
+	}
+	else
+	{
+		return Q931E_ILLEGAL_MESSAGE;
+	}
+	return ret;
 }
 
 /*****************************************************************************
@@ -528,8 +533,8 @@
 *****************************************************************************/
 L3INT Q931ProcResumeAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -537,19 +542,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -561,8 +566,8 @@
 *****************************************************************************/
 L3INT Q931ProcResumeRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -570,19 +575,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -594,8 +599,8 @@
 *****************************************************************************/
 L3INT Q931ProcSuspendTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -603,19 +608,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -627,8 +632,8 @@
 *****************************************************************************/
 L3INT Q931ProcSuspendAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -636,19 +641,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -660,8 +665,8 @@
 *****************************************************************************/
 L3INT Q931ProcSuspendRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -669,19 +674,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -693,8 +698,8 @@
 *****************************************************************************/
 L3INT Q931ProcUserInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -702,19 +707,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -726,8 +731,8 @@
 *****************************************************************************/
 L3INT Q931ProcDisconnectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -735,19 +740,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -759,19 +764,19 @@
 *****************************************************************************/
 L3INT Q931ProcReleaseTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace];
-    L3INT state = Q931GetCallState(pTrunk, pMes->CRV);
-    L3INT ret = Q931E_NO_ERROR;
-    if(iFrom == 4) {
-		/* TODO Add proc here*/
-		ret = Q931Tx32(pTrunk,buf,pMes->Size);
+	L3INT callIndex;
+	Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace];
+	L3INT state = Q931GetCallState(pTrunk, pMes->CRV);
+	L3INT ret = Q931E_NO_ERROR;
+	if(iFrom == 4) {
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	} else if(state == Q931_U0 && iFrom == 2) {
 		Q931Tx34(pTrunk,buf,pMes->Size);
-        ret = Q931ReleaseComplete(pTrunk, buf);
-    } else {
-        ret = Q931ProcUnexpectedMessage(pTrunk, buf, iFrom);
-    }
+		ret = Q931ReleaseComplete(pTrunk, buf);
+	} else {
+		ret = Q931ProcUnexpectedMessage(pTrunk, buf, iFrom);
+	}
 	if (pMes->CRV && iFrom == 2) {
 		/* Find the call using CRV */
 		if ((Q931FindCRV(pTrunk, pMes->CRV, &callIndex)) != Q931E_NO_ERROR)
@@ -789,16 +794,15 @@
 *****************************************************************************/
 L3INT Q931ProcReleaseCompleteTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Generic *pMes = (Q931mes_Generic *)&buf[Q931L4HeaderSpace];
 
-    if(iFrom == 2)
-    {
-        /* TODO Add proc here*/
+	if(iFrom == 2)
+	{
+		/* TODO Add proc here */
 		ret = Q931Tx34(pTrunk,buf,pMes->Size);
-    } else {
-
+	} else {
 		if (pMes->CRV) {
 			/* Find the call using CRV */
 			ret = Q931FindCRV(pTrunk, pMes->CRV, &callIndex);
@@ -818,8 +822,8 @@
 *****************************************************************************/
 L3INT Q931ProcRestartTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 
@@ -833,17 +837,17 @@
 		Q931StartTimer(pTrunk, callIndex, 303);
 	}
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 
 		if (pTrunk->autoRestartAck) {
 			Q931AckRestart(pTrunk, buf);
@@ -859,8 +863,8 @@
 *****************************************************************************/
 L3INT Q931ProcRestartAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	if (pMes->CRV) {
@@ -872,17 +876,17 @@
 		Q931StartTimer(pTrunk, callIndex, 303);
 	}
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -894,8 +898,8 @@
 *****************************************************************************/
 L3INT Q931ProcCongestionControlTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -903,19 +907,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -927,8 +931,8 @@
 *****************************************************************************/
 L3INT Q931ProcInformationTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -936,19 +940,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -960,8 +964,8 @@
 *****************************************************************************/
 L3INT Q931ProcNotifyTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -969,19 +973,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -993,8 +997,8 @@
 *****************************************************************************/
 L3INT Q931ProcStatusTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1002,19 +1006,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1026,8 +1030,8 @@
 *****************************************************************************/
 L3INT Q931ProcStatusEnquiryTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1035,19 +1039,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1059,8 +1063,8 @@
 *****************************************************************************/
 L3INT Q931ProcSegmentTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1068,19 +1072,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1096,8 +1100,8 @@
 *****************************************************************************/
 L3INT Q932ProcFacilityTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1105,19 +1109,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1129,8 +1133,8 @@
 *****************************************************************************/
 L3INT Q932ProcHoldTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1138,19 +1142,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1162,8 +1166,8 @@
 *****************************************************************************/
 L3INT Q932ProcHoldAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1171,19 +1175,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1195,8 +1199,8 @@
 *****************************************************************************/
 L3INT Q932ProcHoldRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1204,19 +1208,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1228,8 +1232,8 @@
 *****************************************************************************/
 L3INT Q932ProcRegisterTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1237,19 +1241,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1261,8 +1265,8 @@
 *****************************************************************************/
 L3INT Q932ProcRetrieveTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1270,19 +1274,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1294,8 +1298,8 @@
 *****************************************************************************/
 L3INT Q932ProcRetrieveAckTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1303,19 +1307,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
@@ -1327,8 +1331,8 @@
 *****************************************************************************/
 L3INT Q932ProcRetrieveRejectTE(Q931_TrunkInfo_t *pTrunk, L3UCHAR * buf, L3INT iFrom)
 {
-    L3INT callIndex;
-    L3INT ret=Q931E_NO_ERROR;
+	L3INT callIndex;
+	L3INT ret=Q931E_NO_ERROR;
 	Q931mes_Header *pMes = (Q931mes_Header *)&buf[Q931L4HeaderSpace];
 
 	/* Find the call using CRV */
@@ -1336,19 +1340,19 @@
 	if(ret != Q931E_NO_ERROR)
 		return ret;
 
-	/* TODO chack against state table for illegal or unexpected message here*/
+	/* TODO chack against state table for illegal or unexpected message here */
 
 	/* TODO - Set correct timer here */
-    Q931StartTimer(pTrunk, callIndex, 303);
+	Q931StartTimer(pTrunk, callIndex, 303);
 	if(iFrom == 4)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx32(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx32Data(pTrunk,buf,pMes->Size);
 	}
-	else if (iFrom ==2)
+	else if (iFrom == 2)
 	{
-		/* TODO Add proc here*/
-        ret = Q931Tx34(pTrunk,buf,pMes->Size);
+		/* TODO Add proc here */
+		ret = Q931Tx34(pTrunk,buf,pMes->Size);
 	}
 	return ret;
 }
Index: src/isdn/Q931api.c
===================================================================
--- src/isdn/Q931api.c	(revision 495)
+++ src/isdn/Q931api.c	(working copy)
@@ -74,8 +74,8 @@
 						Q931Dialect_t Dialect,
 						Q931NetUser_t NetUser,
 						Q931_TrunkType_t TrunkType,
-						Q931TxCB_t Q931Tx34CBProc,
-						Q931TxCB_t Q931Tx32CBProc,
+						Q931Tx34CB_t Q931Tx34CBProc,
+						Q931Tx32CB_t Q931Tx32CBProc,
 						Q931ErrorCB_t Q931ErrorCBProc,
 						void *PrivateData32,
 						void *PrivateData34)
@@ -97,6 +97,7 @@
 		break;
 
 	case Q931_TrType_BRI:
+	case Q931_TrType_BRI_PTMP:
 		dchannel = 3;
 		maxchans = 3;
 		break;
@@ -221,7 +222,7 @@
 {
 	memset(pMes, 0, sizeof(*pMes));
 	pMes->ProtDisc		= 0x08;
-	pMes->Size			= Q931GetMesSize(pMes);
+	pMes->Size		= Q931GetMesSize(pMes);
 
 	return 0;
 }
@@ -229,22 +230,22 @@
 L3INT Q931InitMesResume(Q931mes_Generic * pMes)
 {
 	pMes->ProtDisc		= 0x08;
-	pMes->CRV			= 0;		/* CRV to be allocated, might be receive*/
+	pMes->CRV		= 0;		/* CRV to be allocated, might be receive*/
 	pMes->MesType		= Q931mes_RESUME;
 
-	pMes->Size			= Q931GetMesSize(pMes);
-    pMes->CallID        = 0;        /* Channel Identification               */
+	pMes->Size		= Q931GetMesSize(pMes);
+	pMes->CallID		= 0;        /* Channel Identification               */
 	return 0;
 }
 
 L3INT Q931InitMesRestartAck(Q931mes_Generic * pMes)
 {
 	pMes->ProtDisc		= 0x08;
-	pMes->CRV			= 0;		/* CRV to be allocated, might be receive*/
+	pMes->CRV		= 0;		/* CRV to be allocated, might be receive*/
 	pMes->MesType		= Q931mes_RESTART_ACKNOWLEDGE;
 
-	pMes->Size			= Q931GetMesSize(pMes);
-    pMes->ChanID        = 0;        /* Channel Identification               */
+	pMes->Size		= Q931GetMesSize(pMes);
+	pMes->ChanID		= 0;        /* Channel Identification               */
 	pMes->Display		= 0;
 	pMes->RestartInd	= 0;
 	pMes->RestartWin	= 0;
@@ -323,59 +324,59 @@
 
 L3INT Q931InitIENetFac(Q931ie_NetFac * pIE)
 {
-	pIE->IEId			= Q931ie_NETWORK_SPECIFIC_FACILITIES;
-	pIE->Size			= sizeof(Q931ie_NetFac);
+	pIE->IEId		= Q931ie_NETWORK_SPECIFIC_FACILITIES;
+	pIE->Size		= sizeof(Q931ie_NetFac);
 	pIE->LenNetID		= 0;        /* Length of network facilities id.     */
 	pIE->TypeNetID		= 0;        /* Type of network identification       */
 	pIE->NetIDPlan		= 0;        /* Network identification plan.         */
-	pIE->NetFac			= 0;        /* Network specific facility spec.      */
+	pIE->NetFac		= 0;        /* Network specific facility spec.      */
 	pIE->NetID[0]		= 0;
 	return 0;
 }
 
 L3INT Q931InitIEDisplay(Q931ie_Display * pIE)
 {
-	pIE->IEId			= Q931ie_DISPLAY;
-	pIE->Size			= sizeof(Q931ie_Display);
+	pIE->IEId		= Q931ie_DISPLAY;
+	pIE->Size		= sizeof(Q931ie_Display);
 	pIE->Display[0]		= 0;
 	return 0;
 }
 
 L3INT Q931InitIEDateTime(Q931ie_DateTime * pIE)
 {
-	pIE->IEId			= Q931ie_DATETIME;
-	pIE->Size			= sizeof(Q931ie_DateTime);
-	pIE->Year			= 0;        /* Year                                 */
-	pIE->Month			= 0;        /* Month                                */
-	pIE->Day			= 0;        /* Day                                  */
-	pIE->Hour			= 0;        /* Hour                                 */
-	pIE->Minute			= 0;        /* Minute                               */
-	pIE->Second			= 0;        /* Second                               */
+	pIE->IEId		= Q931ie_DATETIME;
+	pIE->Size		= sizeof(Q931ie_DateTime);
+	pIE->Year		= 0;        /* Year                                 */
+	pIE->Month		= 0;        /* Month                                */
+	pIE->Day		= 0;        /* Day                                  */
+	pIE->Hour		= 0;        /* Hour                                 */
+	pIE->Minute		= 0;        /* Minute                               */
+	pIE->Second		= 0;        /* Second                               */
 
 	return 0;
 }
 
 L3INT Q931InitIEKeypadFac(Q931ie_KeypadFac * pIE)
 {
-	pIE->IEId			= Q931ie_KEYPAD_FACILITY;
-	pIE->Size			= sizeof(Q931ie_KeypadFac);
+	pIE->IEId		= Q931ie_KEYPAD_FACILITY;
+	pIE->Size		= sizeof(Q931ie_KeypadFac);
 	pIE->KeypadFac[0]	= 0;
 	return 0;
 }
 
 L3INT Q931InitIESignal(Q931ie_Signal * pIE)
 {
-	pIE->IEId			= Q931ie_SIGNAL;
-	pIE->Size			= sizeof(Q931ie_Signal);
-	pIE->Signal			= 0;
+	pIE->IEId		= Q931ie_SIGNAL;
+	pIE->Size		= sizeof(Q931ie_Signal);
+	pIE->Signal		= 0;
 	return 0;
 }
 
 L3INT Q931InitIECallingNum(Q931ie_CallingNum * pIE)
 {
-	pIE->IEId			= Q931ie_CALLING_PARTY_NUMBER;
-	pIE->Size			= sizeof(Q931ie_CallingNum);
-	pIE->TypNum			= 0;        /* Type of number                       */
+	pIE->IEId		= Q931ie_CALLING_PARTY_NUMBER;
+	pIE->Size		= sizeof(Q931ie_CallingNum);
+	pIE->TypNum		= 0;        /* Type of number                       */
 	pIE->NumPlanID		= 0;        /* Numbering plan identification        */
 	pIE->PresInd		= 0;        /* Presentation indicator               */
 	pIE->ScreenInd		= 0;        /* Screening indicator                  */
@@ -386,9 +387,9 @@
 
 L3INT Q931InitIECallingSub(Q931ie_CallingSub * pIE)
 {
-	pIE->IEId			= Q931ie_CALLING_PARTY_SUBADDRESS;
-	pIE->Size			= sizeof(Q931ie_CallingSub);
-	pIE->TypNum			= 0;        /* Type of subaddress                   */
+	pIE->IEId		= Q931ie_CALLING_PARTY_SUBADDRESS;
+	pIE->Size		= sizeof(Q931ie_CallingSub);
+	pIE->TypNum		= 0;        /* Type of subaddress                   */
 	pIE->OddEvenInd		= 0;        /* Odd/Even indicator                   */
 	pIE->Digit[0]		= 0;        /* Digits                               */
 
@@ -397,9 +398,9 @@
 
 L3INT Q931InitIECalledNum(Q931ie_CalledNum * pIE)
 {
-	pIE->IEId			= Q931ie_CALLED_PARTY_NUMBER;
-	pIE->Size			= sizeof(Q931ie_CalledNum);
-	pIE->TypNum			= 0;        /* Type of Number                       */
+	pIE->IEId		= Q931ie_CALLED_PARTY_NUMBER;
+	pIE->Size		= sizeof(Q931ie_CalledNum);
+	pIE->TypNum		= 0;        /* Type of Number                       */
 	pIE->NumPlanID		= 0;        /* Numbering plan identification        */
 	pIE->Digit[0]		= 0;        /* Digit (IA5)                          */
 
@@ -408,9 +409,9 @@
 
 L3INT Q931InitIECalledSub(Q931ie_CalledSub * pIE)
 {
-	pIE->IEId			= Q931ie_CALLED_PARTY_SUBADDRESS;
-	pIE->Size			= sizeof(Q931ie_CalledSub);
-	pIE->TypNum			= 0;        /* Type of subaddress                   */
+	pIE->IEId		= Q931ie_CALLED_PARTY_SUBADDRESS;
+	pIE->Size		= sizeof(Q931ie_CalledSub);
+	pIE->TypNum		= 0;        /* Type of subaddress                   */
 	pIE->OddEvenInd		= 0;        /* Odd/Even indicator                   */
 	pIE->Digit[0]		= 0;        /* Digits                               */
 
@@ -419,9 +420,9 @@
 
 L3INT Q931InitIETransNetSel(Q931ie_TransNetSel * pIE)
 {
-	pIE->IEId			= Q931ie_TRANSIT_NETWORK_SELECTION;
-	pIE->Size			= sizeof(Q931ie_TransNetSel);
-	pIE->Type			= 0;        /* Type of network identifier           */
+	pIE->IEId		= Q931ie_TRANSIT_NETWORK_SELECTION;
+	pIE->Size		= sizeof(Q931ie_TransNetSel);
+	pIE->Type		= 0;        /* Type of network identifier           */
 	pIE->NetIDPlan		= 0;        /* Network idetification plan           */
 	pIE->NetID[0]		= 0;        /* Network identification(IA5)          */
 
@@ -430,8 +431,8 @@
 
 L3INT Q931InitIELLComp(Q931ie_LLComp * pIE)
 {
-	pIE->IEId			= Q931ie_LOW_LAYER_COMPATIBILITY;
-	pIE->Size			= sizeof(Q931ie_LLComp);
+	pIE->IEId		= Q931ie_LOW_LAYER_COMPATIBILITY;
+	pIE->Size		= sizeof(Q931ie_LLComp);
 
 	pIE->CodStand		= 0;        /* Coding standard                      */
 	pIE->ITransCap		= 0;        /* Information transfer capability      */
@@ -442,33 +443,33 @@
 	pIE->Layer1Ident	= 0;        /* Layer 1 ident.                       */
 	pIE->UIL1Prot		= 0;        /* User information layer 1 protocol    */
 	pIE->SyncAsync		= 0;        /* Synch/asynch                         */
-	pIE->Negot			= 0;        /* Negot                                */
+	pIE->Negot		= 0;        /* Negot                                */
 	pIE->UserRate		= 0;        /* User rate                            */
 	pIE->InterRate		= 0;        /* Intermediate rate                    */
 	pIE->NIConTx		= 0;        /* NIC on Tx                            */
 	pIE->NIConRx		= 0;        /* NIC on Rx                            */
 	pIE->FlowCtlTx		= 0;        /* Flow control on Tx                   */
 	pIE->FlowCtlRx		= 0;        /* Flow control on Rx                   */
-	pIE->HDR			= 0;        /* Hdr/no hdr                           */
+	pIE->HDR		= 0;        /* Hdr/no hdr                           */
 	pIE->MultiFrame		= 0;        /* Multiframe                           */
-	pIE->ModeL1			= 0;		/* Mode L1								*/
+	pIE->ModeL1		= 0;		/* Mode L1								*/
 	pIE->NegotLLI		= 0;        /* Negot. LLI                           */
 	pIE->Assignor		= 0;        /* Assignor/Assignor ee                 */
 	pIE->InBandNeg		= 0;        /* In-band negot.                       */
 	pIE->NumStopBits	= 0;        /* Number of stop bits                  */
 	pIE->NumDataBits	= 0;        /* Number of data bits                  */
-	pIE->Parity			= 0;        /* Parity                               */
+	pIE->Parity		= 0;        /* Parity                               */
 	pIE->DuplexMode		= 0;        /* Duplex Mode                          */
 	pIE->ModemType		= 0;        /* Modem type                           */
 	pIE->Layer2Ident	= 0;        /* Layer 2 ident.                       */
 	pIE->UIL2Prot		= 0;        /* User information layer 2 protocol    */
-	pIE->ModeL2			= 0;        /* ModeL2                               */
+	pIE->ModeL2		= 0;        /* ModeL2                               */
 	pIE->Q933use		= 0;        /* Q.9333 use                           */
 	pIE->UsrSpcL2Prot	= 0;        /* User specified layer 2 protocol info */
 	pIE->WindowSize		= 0;        /* Window size (k)                      */
 	pIE->Layer3Ident	= 0;        /* Layer 3 ident                        */
 	pIE->OptL3Info		= 0;        /* Optional layer 3 protocol info.      */
-	pIE->ModeL3			= 0;        /* Mode of operation                    */
+	pIE->ModeL3		= 0;        /* Mode of operation                    */
 #if 0
 	pIE->ModeX25op		= 0;        /* Mode of operation X.25               */
 #endif
@@ -481,8 +482,8 @@
 
 L3INT Q931InitIEHLComp(Q931ie_HLComp * pIE)
 {
-	pIE->IEId			= Q931ie_HIGH_LAYER_COMPATIBILITY;
-	pIE->Size			= sizeof(Q931ie_HLComp);
+	pIE->IEId		= Q931ie_HIGH_LAYER_COMPATIBILITY;
+	pIE->Size		= sizeof(Q931ie_HLComp);
 
 	return 0;
 }
@@ -504,7 +505,7 @@
 	(void)b;
 	(void)iFrom;
 
-    return 0;
+	return 0;
 }
 
 L3INT Q931Disconnect(Q931_TrunkInfo_t *pTrunk, L3INT iTo, L3INT iCRV, L3INT iCause)
@@ -515,22 +516,24 @@
 	(void)iCRV;
 	(void)iCause;
 
-    return 0;
+	return 0;
 }
 
 L3INT Q931ReleaseComplete(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf)
 {
-    Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
+	Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
+
 	ptr->MesType = Q931mes_RELEASE_COMPLETE;
 	ptr->CRVFlag = !(ptr->CRVFlag);
-	return Q931Tx32(pTrunk,buf,ptr->Size);
+
+	return Q931Tx32Data(pTrunk,buf,ptr->Size);
 }
 
 L3INT Q931AckRestart(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf)
 {
 	L3INT RetCode;
+	Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
 
-    Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
 	ptr->MesType = Q931mes_RESTART_ACKNOWLEDGE;
 	//if (ptr->CRV) {
 		ptr->CRVFlag = !(ptr->CRVFlag);
@@ -538,38 +541,38 @@
 
 	RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4);
 
-    return RetCode;
+	return RetCode;
 }
 
 L3INT Q931AckSetup(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf)
 {
 	L3INT RetCode;
+	Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
 
-    Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
 	ptr->MesType = Q931mes_SETUP_ACKNOWLEDGE;
 
 	RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4);
 
-    return RetCode;
+	return RetCode;
 }
 
 L3INT Q931AckConnect(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf)
 {
 	L3INT RetCode;
+	Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
 
-    Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
 	ptr->MesType = Q931mes_CONNECT_ACKNOWLEDGE;
 
 	RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4);
 
-    return RetCode;
+	return RetCode;
 }
 
 L3INT Q931AckService(Q931_TrunkInfo_t *pTrunk, L3UCHAR *buf)
 {
 	L3INT RetCode;
+	Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
 
-    Q931mes_Header *ptr = (Q931mes_Header*)&buf[Q931L4HeaderSpace];
 	ptr->MesType = Q931mes_SERVICE_ACKNOWLEDGE;
 	if (ptr->CRV) {
 		ptr->CRVFlag = !(ptr->CRVFlag);
@@ -577,7 +580,7 @@
 
 	RetCode = Q931Proc[pTrunk->Dialect][ptr->MesType](pTrunk, buf, 4);
 
-    return RetCode;
+	return RetCode;
 }
 
 Q931_ENUM_NAMES(DIALECT_TYPE_NAMES, DIALECT_STRINGS)
Index: src/isdn/Q931ie.c
===================================================================
--- src/isdn/Q931ie.c	(revision 495)
+++ src/isdn/Q931ie.c	(working copy)
@@ -70,13 +70,12 @@
 *****************************************************************************/
 #define Q931MoreIE() (Octet+Off - 2 < IESize)
 
-#define Q931IESizeTest(x)   {\
-                            if(Octet+Off-2 != IESize)\
-                            {\
-                                Q931SetError(pTrunk,x, Octet, Off);\
-                                return x;\
-                            }\
-                            }
+#define Q931IESizeTest(x) {\
+		if(Octet+Off-2 != IESize) {\
+			Q931SetError(pTrunk,x, Octet, Off);\
+			return x;\
+		}\
+	}
 
 /*****************************************************************************
 
@@ -100,7 +99,7 @@
 
 L3INT Q931ReadExt(L3UCHAR * IBuf, L3INT Off)
 {
-    L3INT c =0;
+    L3INT c = 0;
     while((IBuf[c] & 0x80) == 0)
         c++;
 
@@ -128,171 +127,165 @@
 
 L3INT Q931Uie_BearerCap(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff) 
 {
-    Q931ie_BearerCap * pie = (Q931ie_BearerCap*)OBuf;
+	Q931ie_BearerCap *pie = (Q931ie_BearerCap*)OBuf;
 	ie *pIE = &pMsg->BearerCap;
-    L3INT Off = 0;
-    L3INT Octet = 0;
-    L3INT IESize;
-    *pIE=0;
+	L3INT Off = 0;
+	L3INT Octet = 0;
+	L3INT IESize;
+	*pIE=0;
 
-    /* Octet 1 */
-    pie->IEId        = IBuf[Octet];
-    Octet ++;
+	Q931Log(pTrunk, Q931_LOG_DEBUG, "Decoding Bearer Capability IE\n");
 
-    /* Octet 2 */
-    IESize = IBuf[Octet ++]; 
+	/* Octet 1 */
+	pie->IEId = IBuf[Octet++];
 
-    /* Octet 3 */
-    pie->CodStand    = ieGetOctet((IBuf[Octet] & 0x60) >> 5);
-    pie->ITC         = ieGetOctet(IBuf[Octet] & 0x1f);
-    Off = Q931ReadExt(&IBuf[Octet], Off);
-    Octet++;
+	/* Octet 2 */
+	IESize    = IBuf[Octet++]; 
 
-    /* Octet 4 */
-    pie->TransMode   = ieGetOctet((IBuf[Octet+Off] & 0x60) >> 5);
-    pie->ITR         = ieGetOctet(IBuf[Octet+Off] & 0x1f);
-    Off = Q931ReadExt(&IBuf[Octet+Off], Off);
-    Octet++;
+	/* Octet 3 */
+	pie->CodStand = ieGetOctet((IBuf[Octet] & 0x60) >> 5);
+	pie->ITC      = ieGetOctet(IBuf[Octet] & 0x1f);
+	Off = Q931ReadExt(&IBuf[Octet], Off);
+	Octet++;
 
-    /* Octet 4.1. Rate multiplier is only present if ITR = Multirate        */
-    if(pie->ITR == 0x18)
-    {
-        pie->RateMul = ieGetOctet(IBuf[Octet+Off] & 0x7f);
-        Off = Q931ReadExt(&IBuf[Octet+Off], Off);
-        Off ++;
-    }
+	/* Octet 4 */
+	pie->TransMode = ieGetOctet((IBuf[Octet+Off] & 0x60) >> 5);
+	pie->ITR       = ieGetOctet(IBuf[Octet+Off] & 0x1f);
+	Off = Q931ReadExt(&IBuf[Octet+Off], Off);
+	Octet++;
 
-    /* Octet 5 */
-    if((IBuf[Octet+Off] & 0x60) == 0x20 && Q931MoreIE())
-    {
-        pie->Layer1Ident = ieGetOctet((IBuf[Octet+Off] & 0x60) >> 5);
-        pie->UIL1Prot    = ieGetOctet(IBuf[Octet+Off] & 0x1f);
-        Octet++;
+	/* Octet 4.1. Rate multiplier is only present if ITR = Multirate        */
+	if(pie->ITR == 0x18)
+	{
+		pie->RateMul = ieGetOctet(IBuf[Octet+Off] & 0x7f);
+		Off = Q931ReadExt(&IBuf[Octet+Off], Off);
+		Off++;
+	}
 
-        /* Octet 5a. The octet may be present if ITC is unrestrictd digital info*/
-        /* and UIL1Prot is either V.110, I.460 and X.30 or V.120. It may also   */
-        /* be present if ITC = 3.1 kHz audio and UIL1Prot is G.711.             */
-        /* Bit 8 of Octet 5 = 0 indicates that 5a is present.                   */
+	/* Octet 5 */
+	if((IBuf[Octet+Off] & 0x60) == 0x20 && Q931MoreIE())
+	{
+		pie->Layer1Ident = ieGetOctet((IBuf[Octet+Off] & 0x60) >> 5);
+		pie->UIL1Prot    = ieGetOctet(IBuf[Octet+Off] & 0x1f);
+		Octet++;
 
-        if(IsQ931Ext(IBuf[Octet+Off-1]))
-        {
-            if(((pie->ITC == 0x08) && (pie->UIL1Prot == 0x01 || pie->UIL1Prot == 0x08))
-            || ((pie->ITC == 0x10) && (pie->UIL1Prot == 0x02 || pie->UIL1Prot == 0x03)))
-            {
-                pie->SyncAsync   = ieGetOctet((IBuf[Octet+Off] & 0x40) >> 6);
-                pie->Negot       = ieGetOctet((IBuf[Octet+Off] & 0x20) >> 5);
-                pie->UserRate    = ieGetOctet(IBuf[Octet+Off] & 0x1f);
-                Off ++;
-            }
-            else
-            {
-                /* We have detected bit 8 = 0, but no setting that require the  */
-                /* additional octets ???                                        */
-                Q931SetError(pTrunk, Q931E_BEARERCAP, 5,Off);
-                return Q931E_BEARERCAP;
-            }
+		/* Octet 5a. The octet may be present if ITC is unrestrictd digital info*/
+		/* and UIL1Prot is either V.110, I.460 and X.30 or V.120. It may also   */
+		/* be present if ITC = 3.1 kHz audio and UIL1Prot is G.711.             */
+		/* Bit 8 of Octet 5 = 0 indicates that 5a is present.                   */
 
-            /* Octet 5b. Two different structures used.                         */
-            if(IsQ931Ext(IBuf[Octet+Off-1]))
-            {
-                if(pie->UIL1Prot == 0x01) /* ITU V.110, I.460 and X.30           */
-                {
-                    pie->InterRate   = ieGetOctet((IBuf[Octet+Off] & 0x60) >> 5);
-                    pie->NIConTx     = ieGetOctet((IBuf[Octet+Off] & 0x10) >> 4);
-                    pie->NIConRx     = ieGetOctet((IBuf[Octet+Off] & 0x08) >> 3);
-                    pie->FlowCtlTx   = ieGetOctet((IBuf[Octet+Off] & 0x04) >> 2);
-                    pie->FlowCtlRx   = ieGetOctet((IBuf[Octet+Off] & 0x20) >> 1);
-                    Off++;
-                }
-                else if(pie->UIL1Prot == 0x08) /* ITU V.120                      */
-                {
-                    pie->HDR         = ieGetOctet((IBuf[Octet+Off] & 0x40) >> 6);
-                    pie->MultiFrame  = ieGetOctet((IBuf[Octet+Off] & 0x20) >> 5);
-                    pie->Mode        = ieGetOctet((IBuf[Octet+Off] & 0x10) >> 4);
-                    pie->LLInegot    = ieGetOctet((IBuf[Octet+Off] & 0x08) >> 3);
-                    pie->Assignor    = ieGetOctet((IBuf[Octet+Off] & 0x04) >> 2);
-                    pie->InBandNeg   = ieGetOctet((IBuf[Octet+Off] & 0x02) >> 1);
-                    Off++;
-                }
-                else
-                {
-                    Q931SetError(pTrunk,Q931E_BEARERCAP, 5,Off);
-                    return Q931E_BEARERCAP;
+		if(IsQ931Ext(IBuf[Octet+Off-1]))
+		{
+			if(((pie->ITC == 0x08) && (pie->UIL1Prot == 0x01 || pie->UIL1Prot == 0x08)) ||
+			   ((pie->ITC == 0x10) && (pie->UIL1Prot == 0x02 || pie->UIL1Prot == 0x03)))
+			{
+				pie->SyncAsync   = ieGetOctet((IBuf[Octet+Off] & 0x40) >> 6);
+				pie->Negot       = ieGetOctet((IBuf[Octet+Off] & 0x20) >> 5);
+				pie->UserRate    = ieGetOctet(IBuf[Octet+Off] & 0x1f);
+				Off++;
+			}
+			else {
+				/* We have detected bit 8 = 0, but no setting that require the  */
+				/* additional octets ???                                        */
+				Q931SetError(pTrunk, Q931E_BEARERCAP, 5,Off);
+				return Q931E_BEARERCAP;
+			}
 
-                }
+			/* Octet 5b. Two different structures used.                         */
+			if(IsQ931Ext(IBuf[Octet+Off-1]))
+			{
+				if(pie->UIL1Prot == 0x01) /* ITU V.110, I.460 and X.30           */
+				{
+					pie->InterRate   = ieGetOctet((IBuf[Octet+Off] & 0x60) >> 5);
+					pie->NIConTx     = ieGetOctet((IBuf[Octet+Off] & 0x10) >> 4);
+					pie->NIConRx     = ieGetOctet((IBuf[Octet+Off] & 0x08) >> 3);
+					pie->FlowCtlTx   = ieGetOctet((IBuf[Octet+Off] & 0x04) >> 2);
+					pie->FlowCtlRx   = ieGetOctet((IBuf[Octet+Off] & 0x20) >> 1);
+					Off++;
+				}
+				else if(pie->UIL1Prot == 0x08) /* ITU V.120                      */
+				{
+					pie->HDR         = ieGetOctet((IBuf[Octet+Off] & 0x40) >> 6);
+					pie->MultiFrame  = ieGetOctet((IBuf[Octet+Off] & 0x20) >> 5);
+					pie->Mode        = ieGetOctet((IBuf[Octet+Off] & 0x10) >> 4);
+					pie->LLInegot    = ieGetOctet((IBuf[Octet+Off] & 0x08) >> 3);
+					pie->Assignor    = ieGetOctet((IBuf[Octet+Off] & 0x04) >> 2);
+					pie->InBandNeg   = ieGetOctet((IBuf[Octet+Off] & 0x02) >> 1);
+					Off++;
+				}
+				else {
+					Q931SetError(pTrunk,Q931E_BEARERCAP, 5,Off);
+					return Q931E_BEARERCAP;
+				}
 
-                /* Octet 5c */
-                if(IsQ931Ext(IBuf[Octet+Off-1]))
-                {
+				/* Octet 5c */
+				if(IsQ931Ext(IBuf[Octet+Off-1]))
+				{
+					pie->NumStopBits = ieGetOctet((IBuf[Octet+Off] & 0x60) >> 5);
+					pie->NumDataBits = ieGetOctet((IBuf[Octet+Off] & 0x18) >> 3);
+					pie->Parity      = ieGetOctet(IBuf[Octet+Off] & 0x07);
+					Off++;
 
-                    pie->NumStopBits = ieGetOctet((IBuf[Octet+Off] & 0x60) >> 5);
-                    pie->NumDataBits = ieGetOctet((IBuf[Octet+Off] & 0x18) >> 3);
-                    pie->Parity      = ieGetOctet(IBuf[Octet+Off] & 0x07);
-                    Off++;
+					/* Octet 5d */
+					if(IsQ931Ext(IBuf[Octet+Off-1]))
+					{
+						pie->DuplexMode  = ieGetOctet((IBuf[Octet+Off] & 0x40) >> 6);
+						pie->ModemType   = ieGetOctet(IBuf[Octet+Off] & 0x3f);
+						Off++;
+					}
+				}
+			}
+		}
+	}
 
-                    /* Octet 5d */
-                    if(IsQ931Ext(IBuf[Octet+Off-1]))
-                    {
+	/* Octet 6 */
+	if((IBuf[Octet+Off] & 0x60) == 0x40 && Q931MoreIE())
+	{
+		pie->Layer2Ident = ieGetOctet((IBuf[Octet+Off] & 0x60) >> 5);
+		pie->UIL2Prot    = ieGetOctet(IBuf[Octet+Off] & 0x1f);
 
-                        pie->DuplexMode  = ieGetOctet((IBuf[Octet+Off] & 0x40) >> 6);
-                        pie->ModemType   = ieGetOctet(IBuf[Octet+Off] & 0x3f);
-                        Off ++;
-                    }
-                }
-            }
-        }
-    }
+		Off = Q931ReadExt(&IBuf[Octet+Off], Off);
+		Octet++;
+	}
 
-    /* Octet 6 */
-    if((IBuf[Octet+Off] & 0x60) == 0x40 && Q931MoreIE())
-    {
-        pie->Layer2Ident = ieGetOctet((IBuf[Octet+Off] & 0x60) >> 5);
-        pie->UIL2Prot    = ieGetOctet(IBuf[Octet+Off] & 0x1f);
+	/* Octet 7 */
+	if((IBuf[Octet+Off] & 0x60) == 0x60 && Q931MoreIE()) 
+	{
+		pie->Layer3Ident = ieGetOctet((IBuf[Octet+Off] & 0x60) >> 5);
+		pie->UIL3Prot    = ieGetOctet(IBuf[Octet+Off] & 0x1f);
+		Octet++;
 
-        Off = Q931ReadExt(&IBuf[Octet+Off], Off);
-        Octet ++;
-    }
+		/* Octet 7a */
+		if(IsQ931Ext(IBuf[Octet+Off-1]))
+		{
+			if(pie->UIL3Prot == 0x0c)
+			{
+				pie->AL3Info1 = ieGetOctet(IBuf[Octet+Off] & 0x0f);
+				Off++;
 
-    /* Octet 7 */
-    if((IBuf[Octet+Off] & 0x60) == 0x60 && Q931MoreIE()) 
-    {
-        pie->Layer3Ident = ieGetOctet((IBuf[Octet+Off] & 0x60) >> 5);
-        pie->UIL3Prot    = ieGetOctet(IBuf[Octet+Off] & 0x1f);
-        Octet++;
+				/* Octet 7b */
+				if(IsQ931Ext(IBuf[Octet+Off]))
+				{
+					pie->AL3Info2 = ieGetOctet(IBuf[Octet+Off] & 0x0f);
+					Off++;
+				}
+			}
+			else {
+				Q931SetError(pTrunk,Q931E_BEARERCAP, 7, Off);
+				return Q931E_BEARERCAP;
+			}
+		}
+	}
 
-        /* Octet 7a */
-        if(IsQ931Ext(IBuf[Octet+Off-1]))
-        {
-            if(pie->UIL3Prot == 0x0c)
-            {
-                pie->AL3Info1 = ieGetOctet(IBuf[Octet+Off] & 0x0f);
-                Off++;
+	Q931IESizeTest(Q931E_BEARERCAP);
 
-                /* Octet 7b */
-                if(IsQ931Ext(IBuf[Octet+Off]))
-                {
-                    pie->AL3Info2 = ieGetOctet(IBuf[Octet+Off] & 0x0f);
-                    Off++;
-                }
-            }
-            else
-            {
-                Q931SetError(pTrunk,Q931E_BEARERCAP, 7, Off);
-                return Q931E_BEARERCAP;
+	Q931SetIE(*pIE, *OOff);
 
-            }
-        }
-    }
-
-    Q931IESizeTest(Q931E_BEARERCAP);
-
-    Q931SetIE(*pIE, *OOff);
-
 	*IOff = (*IOff) + Octet + Off;
-    *OOff = (*OOff) + sizeof(Q931ie_BearerCap);
-    pie->Size = sizeof(Q931ie_BearerCap);
+	*OOff = (*OOff) + sizeof(Q931ie_BearerCap);
+	pie->Size = sizeof(Q931ie_BearerCap);
 
-    return Q931E_NO_ERROR;
+	return Q931E_NO_ERROR;
 }
 
 /*****************************************************************************
@@ -313,101 +306,102 @@
 
 L3INT Q931Pie_BearerCap(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
 {
-    Q931ie_BearerCap * pIE = (Q931ie_BearerCap*)IBuf;
-    L3INT rc=0;
-    L3INT Beg=*Octet;/* remember current offset */
-    L3INT li;
+	Q931ie_BearerCap * pIE = (Q931ie_BearerCap*)IBuf;
+	L3INT rc=0;
+	L3INT Beg=*Octet;/* remember current offset */
+	L3INT li;
 
-    OBuf[(*Octet)++] = Q931ie_BEARER_CAPABILITY ;
-    li=(*Octet)++;    /* remember length position */
+	Q931Log(pTrunk, Q931_LOG_DEBUG, "Encoding Bearer Capability IE\n");
 
-    /* Octet 3 - Coding standard / Information transfer capability */
-    OBuf[(*Octet)++] = 0x80 | (pIE->CodStand<<5) | (pIE->ITC & 0x1f);
+	OBuf[(*Octet)++] = Q931ie_BEARER_CAPABILITY ;
+	li=(*Octet)++;    /* remember length position */
 
-    /* Octet 4 - Transfer mode / Information transfer rate */
-	OBuf[(*Octet)++] = 0x80 | (pIE->TransMode<<5) | (pIE->ITR & 0x1f);
-    if(pIE->ITR == 0x18)
-    {
-        /* Octet 4.1 - Rate Multiplier */
-        OBuf[(*Octet)++] = 0x80 | pIE->RateMul;
-    }
+	/* Octet 3 - Coding standard / Information transfer capability */
+	OBuf[(*Octet)++] = 0x80 | ((pIE->CodStand << 5) & 0x60) | (pIE->ITC & 0x1f);
 
-    /* Octet 5 - Layer 1 Ident / User information layer 1 protocol*/
-    if(pIE->Layer1Ident == 0x01)
-    {
-        if(((pIE->ITC == 0x08) && (pIE->UIL1Prot == 0x01 || pIE->UIL1Prot == 0x08))
-        || ((pIE->ITC == 0x10) && (pIE->UIL1Prot == 0x02 || pIE->UIL1Prot == 0x03)))
-        {
-            OBuf[(*Octet)++] = 0x00 | (pIE->Layer1Ident<<5) | (pIE->UIL1Prot & 0x15);
+	/* Octet 4 - Transfer mode / Information transfer rate */
+	OBuf[(*Octet)++] = 0x80 | ((pIE->TransMode << 5) & 0x60) | (pIE->ITR & 0x1f);
+
+	if(pIE->ITR == 0x18)
+	{
+		/* Octet 4.1 - Rate Multiplier */
+		OBuf[(*Octet)++] = 0x80 | (pIE->RateMul & 0x7f);
+	}
+
+	/* Octet 5 - Layer 1 Ident / User information layer 1 protocol */
+	if(pIE->Layer1Ident == 0x01)
+	{
+		if(((pIE->ITC == 0x08) && (pIE->UIL1Prot == 0x01 || pIE->UIL1Prot == 0x08)) ||
+		   ((pIE->ITC == 0x10) && (pIE->UIL1Prot == 0x02 || pIE->UIL1Prot == 0x03)))
+		{
+			OBuf[(*Octet)++] = 0x00 | ((pIE->Layer1Ident << 5) & 0x60) | (pIE->UIL1Prot & 0x15);
             
-            /* Octet 5a - SyncAsync/Negot/UserRate */
-            OBuf[(*Octet)++] = 0x00 | (pIE->SyncAsync<<6) | (pIE->Negot<<5) | (pIE->UserRate&0x1f);
+			/* Octet 5a - SyncAsync/Negot/UserRate */
+			OBuf[(*Octet)++] = 0x00 | ((pIE->SyncAsync << 6) & 0x40) | ((pIE->Negot << 5) & 0x20) | (pIE->UserRate & 0x1f);
 
-            /* Octet 5b - one of two types */
-            if(pIE->UIL1Prot == 0x01) /* ITU V.110, I.460 and X.30           */
-            {
-                /* Octet 5b - Intermed rate/ Nic on Tx/Nix on Rx/FlowCtlTx/FlowCtlRx */
-                OBuf[(*Octet)++] = 0x00 
-                                | (pIE->InterRate<<6)
-                                | (pIE->NIConTx << 4)
-                                | (pIE->NIConRx << 3)
-                                | (pIE->FlowCtlTx << 2)
-                                | (pIE->FlowCtlRx << 1);
-            }
-            else if(pIE->UIL1Prot == 0x08) /* ITU V.120                      */
-            {
-                /* Octet 5b - HDR/Multiframe/Mode/LLINegot/Assignor/Inbandneg*/
-                OBuf[(*Octet)++] = 0x00
-                                | (pIE->InterRate << 6)
-                                | (pIE->MultiFrame << 5)
-                                | (pIE->Mode << 4)
-                                | (pIE->LLInegot << 3)
-                                | (pIE->Assignor << 2)
-                                | (pIE->InBandNeg << 1);
-            }
+			/* Octet 5b - one of two types */
+			if(pIE->UIL1Prot == 0x01) /* ITU V.110, I.460 and X.30           */
+			{
+				/* Octet 5b - Intermed rate/ Nic on Tx/Nix on Rx/FlowCtlTx/FlowCtlRx */
+				OBuf[(*Octet)++] = 0x00 
+						| ((pIE->InterRate << 6) & 0x60)
+						| ((pIE->NIConTx   << 4) & 0x10)
+						| ((pIE->NIConRx   << 3) & 0x08)
+						| ((pIE->FlowCtlTx << 2) & 0x04)
+						| ((pIE->FlowCtlRx << 1) & 0x02);
+			}
+			else if(pIE->UIL1Prot == 0x08) /* ITU V.120                      */
+			{
+				/* Octet 5b - HDR/Multiframe/Mode/LLINegot/Assignor/Inbandneg*/
+				OBuf[(*Octet)++] = 0x00
+						| ((pIE->InterRate  << 6) & 0x60)
+						| ((pIE->MultiFrame << 5) & 0x20)
+						| ((pIE->Mode       << 4) & 0x10)
+						| ((pIE->LLInegot   << 3) & 0x08)
+						| ((pIE->Assignor   << 2) & 0x04)
+						| ((pIE->InBandNeg  << 1) & 0x02);
+			}
 
-            /* Octet 5c - NumStopBits/NumStartBits/Parity                    */
-            OBuf[(*Octet)++] = 0x00 
-                            | (pIE->NumStopBits << 5 )
-                            | (pIE->NumDataBits << 3 )
-                            | (pIE->Parity);
+			/* Octet 5c - NumStopBits/NumStartBits/Parity                    */
+			OBuf[(*Octet)++] = 0x00 
+					| ((pIE->NumStopBits << 5) & 0x60)
+					| ((pIE->NumDataBits << 3) & 0x18)
+					| (pIE->Parity & 0x07);
 
-            /* Octet 5d - Duplex Mode/Modem Type */
-            OBuf[(*Octet)++] = 0x80 | (pIE->DuplexMode<<6) | (pIE->ModemType);
-        }
-        else
-        {
-            OBuf[(*Octet)++] = 0x80 | (pIE->Layer1Ident<<5) | (pIE->UIL1Prot & 0x1F);
-        }
-    }
+			/* Octet 5d - Duplex Mode/Modem Type */
+			OBuf[(*Octet)++] = 0x80 | ((pIE->DuplexMode << 6) & 0x40) | (pIE->ModemType & 0x3f);
+		}
+		else {
+			OBuf[(*Octet)++] = 0x80 | ((pIE->Layer1Ident << 5) & 0x60) | (pIE->UIL1Prot & 0x1f);
+		}
+	}
 
-    /* Octet 6 - Layer2Ident/User information layer 2 prtocol */
-    if(pIE->Layer2Ident == 0x02)
-    {
-        OBuf[(*Octet)++] = 0x80 | (pIE->Layer2Ident<<5) | (pIE->UIL2Prot);
-    }
+	/* Octet 6 - Layer2Ident/User information layer 2 prtocol */
+	if(pIE->Layer2Ident == 0x02) {
+		OBuf[(*Octet)++] = 0x80 | ((pIE->Layer2Ident << 5) & 0x60) | (pIE->UIL2Prot & 0x1f);
+	}
 
-    /* Octet 7 - Layer 3 Ident/ User information layer 3 protocol */
-    if(pIE->Layer3Ident == 0x03)
-    {
-        if(pIE->UIL3Prot == 0x0c)
-        {
-            OBuf[(*Octet)++] = 0x00 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot);
+	/* Octet 7 - Layer 3 Ident/ User information layer 3 protocol */
+	if(pIE->Layer3Ident == 0x03)
+	{
+		if(pIE->UIL3Prot == 0x0c)
+		{
+			OBuf[(*Octet)++] = 0x00 | ((pIE->Layer3Ident << 5) & 0x60) | (pIE->UIL3Prot & 0x1f);
 
-            /* Octet 7a - Additional information layer 3 msb */
-            OBuf[(*Octet)++] = 0x00 | (pIE->AL3Info1);
+			/* Octet 7a - Additional information layer 3 msb */
+			OBuf[(*Octet)++] = 0x00 | (pIE->AL3Info1 & 0x0f);
 
-            /* Octet 7b - Additional information layer 3 lsb */
-            OBuf[(*Octet)++] = 0x80 | (pIE->AL3Info2);
-        }
-        else
-        {
-            OBuf[(*Octet)++] = 0x80 | (pIE->Layer3Ident<<5) | (pIE->UIL3Prot);
-        }
-    }
+			/* Octet 7b - Additional information layer 3 lsb */
+			OBuf[(*Octet)++] = 0x80 | (pIE->AL3Info2 & 0x0f);
+		}
+		else {
+			OBuf[(*Octet)++] = 0x80 | ((pIE->Layer3Ident << 5) & 0x60) | (pIE->UIL3Prot & 0x1f);
+		}
+	}
 
-    OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2;
-    return rc;
+	OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2;
+
+	return rc;
 }
 
 /*****************************************************************************
@@ -1152,76 +1146,107 @@
 *****************************************************************************/
 L3INT Q931Uie_ChanID(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff)
 {
-    Q931ie_ChanID * pie = (Q931ie_ChanID*)OBuf;
+	Q931ie_ChanID *pie = (Q931ie_ChanID*)OBuf;
 	ie *pIE = &pMsg->ChanID;
-    L3INT Off = 0;
-    L3INT Octet = 0;
-    L3INT IESize;
+	L3INT Off = 0;
+	L3INT Octet = 0;
+	L3INT IESize;
 //18 04 e1 80 83 01
-    *pIE=0;
+	*pIE = 0;
 
-    /* Octet 1 */
-    pie->IEId        = IBuf[Octet];
-    Octet ++;
+	Q931Log(pTrunk, Q931_LOG_DEBUG, "Decoding Channel ID IE\n");
 
-    /* Octet 2 */
-    IESize = IBuf[Octet ++]; 
+	/* Octet 1 */
+	pie->IEId = IBuf[Octet++];
 
-    /* Octet 3 */
-    pie->IntIDPresent    = (IBuf[Octet] >> 6) & 0x01;
-    pie->IntType        = (IBuf[Octet] >> 5) & 0x01;
-    pie->PrefExcl        = (IBuf[Octet] >> 3) & 0x01;
-    pie->DChanInd        = (IBuf[Octet] >> 2) & 0x01;
-    pie->InfoChanSel    = IBuf[Octet] & 0x03;
+	/* Octet 2 */
+	IESize    = IBuf[Octet++]; 
 
-    Off = Q931ReadExt(&IBuf[Octet+Off], Off);
-    Octet++;
+	/* Octet 3 */
+	pie->IntIDPresent = (IBuf[Octet] >> 6) & 0x01;
+	pie->IntType      = (IBuf[Octet] >> 5) & 0x01;
+	pie->PrefExcl     = (IBuf[Octet] >> 3) & 0x01;
+	pie->DChanInd     = (IBuf[Octet] >> 2) & 0x01;
+	pie->InfoChanSel  =  IBuf[Octet] & 0x03;
 
-    /* Octet 3.1 */
+	Off = Q931ReadExt(&IBuf[Octet++], Off);
 
-    if(pie->IntIDPresent)
-    {
-        pie->InterfaceID    = IBuf[Octet+Off] & 0x7f;
+	/* Octet 3.1 */
+	if(pie->IntIDPresent)
+	{
+		pie->InterfaceID = IBuf[Octet+Off] & 0x7f;
 
-        /* Temp fix. Interface id can be extended using the extension bit */
-        /* this will read the octets, but do nothing with them. this is done */
-        /* because the usage of this field is a little unclear */
-        /* 30.jan.2001/JVB */
-        Off = Q931ReadExt(&IBuf[Octet+Off], Off);
-        Off++;
-    }
+		/* Temp fix. Interface id can be extended using the extension bit */
+		/* this will read the octets, but do nothing with them. this is done */
+		/* because the usage of this field is a little unclear */
+		/* 30.jan.2001/JVB */
+		Off = Q931ReadExt(&IBuf[Octet+Off], Off);
+		Off++;
+	}
 
-    if (Octet + Off -2 != IESize) {
-        /* Octet 3.2 */
-        if(pie->IntType == 1)        /* PRI etc */
-        {
-            pie->CodStand    = (IBuf[Octet + Off] >> 5) & 0x03;
-            pie->NumMap        = (IBuf[Octet + Off] >> 4) & 0x01;
-            pie->ChanMapType= IBuf[Octet + Off] & 0x0f;
+	if ((Octet + Off - 2) != IESize) {
+		/* Octet 3.2 */
+		if(pie->IntType == 1)        /* PRI etc */
+		{
+			pie->CodStand    = (IBuf[Octet + Off] >> 5) & 0x03;
+			pie->NumMap      = (IBuf[Octet + Off] >> 4) & 0x01;
+			pie->ChanMapType =  IBuf[Octet + Off] & 0x0f;
+			Off++;
 
-            Off ++;
+			/* Octet 3.3 */
+			/* TODO: Temp fix. Assume B channel. H channels not supported */
+			pie->ChanSlot = IBuf[Octet+Off] & 0x7f;
 
-
-            /* Octet 3.3 */
-            /* Temp fix. Assume B channel. H channels not supported */
-            pie->ChanSlot = IBuf[Octet+Off] & 0x7f;
 			/* Some dialects don't follow the extension coding properly for this, but this should be safe for all */
-			if (Octet + Off -1 != IESize) {
+			if (Octet + Off - 1 != IESize) {
 				Off = Q931ReadExt(&IBuf[Octet+Off], Off);
 			}
-            Off++;
-        }
-    }
+			Off++;
+		}
+	}
 
-    Q931IESizeTest(Q931E_CHANID);
+	Q931IESizeTest(Q931E_CHANID);
 
-    Q931SetIE(*pIE, *OOff);
+	Q931SetIE(*pIE, *OOff);
 
-    *IOff = (*IOff) + Octet + Off;
-    *OOff = (*OOff) + sizeof(Q931ie_BearerCap);
-    pie->Size = sizeof(Q931ie_BearerCap);
+	*IOff = (*IOff) + Octet + Off;
+	*OOff = (*OOff) + sizeof(Q931ie_BearerCap);
+	pie->Size = sizeof(Q931ie_BearerCap);
 
-    return Q931E_NO_ERROR;
+	if(pTrunk->loglevel == Q931_LOG_DEBUG)
+	{
+		const char *iface;
+		char tmp[100] = "";
+
+		if(!pie->IntType) {
+			switch(pie->InfoChanSel) {
+			case 0x0:
+				iface = "None";
+				break;
+			case 0x1:
+				iface = "B1";
+				break;
+			case 0x2:
+				iface = "B2";
+				break;
+			default:
+				iface = "Any Channel";
+			}
+
+			snprintf(tmp, sizeof(tmp)-1, "InfoChanSel: %d (%s)", pie->InfoChanSel, iface);
+		}
+
+		Q931Log(pTrunk, Q931_LOG_DEBUG,
+			"\n\n-------------------------- Q.931 Channel ID ------------------------\n"
+			"    Pref/Excl: %s, Interface Type: %s\n"
+			"    %s\n"
+			"--------------------------------------------------------------------\n\n",
+			((pie->PrefExcl) ? "Preferred" : "Exclusive"),
+			((pie->IntType) ? "PRI/Other" : "BRI"),
+			tmp);
+	}
+
+	return Q931E_NO_ERROR;
 }
 
 /*****************************************************************************
@@ -1237,43 +1262,52 @@
 *****************************************************************************/
 L3INT Q931Pie_ChanID(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
 {
-    Q931ie_ChanID * pIE = (Q931ie_ChanID*)IBuf;
-    L3INT rc=Q931E_NO_ERROR;
-    L3INT Beg=*Octet;/* remember current offset */
-    L3INT li;
+	Q931ie_ChanID * pIE = (Q931ie_ChanID*)IBuf;
+	L3INT rc = Q931E_NO_ERROR;
+	L3INT Beg = *Octet;	/* remember current offset */
+	L3INT li;
 
-    OBuf[(*Octet)++] = Q931ie_CHANNEL_IDENTIFICATION;
-    li=(*Octet)++;    /* remember length position */
+	OBuf[(*Octet)++] = Q931ie_CHANNEL_IDENTIFICATION;
+	li = (*Octet)++;	/* remember length position */
 
-    /* Octet 3 flags & BRI chan # */
-    OBuf[(*Octet)++] = 0x80 
-                    | (pIE->IntIDPresent << 6) 
-                    | (pIE->IntType<<5)
-                    | (pIE->PrefExcl<<3) 
-                    | pIE->InfoChanSel;
+	/* Octet 3 flags & BRI chan # */
+	OBuf[(*Octet)++] = 0x80 
+			| ((pIE->IntIDPresent << 6) & 0x40)
+			| ((pIE->IntType << 5) & 0x20)
+			| ((pIE->PrefExcl << 3) & 0x08)
+			|  (pIE->InfoChanSel & 0x03);
 
-    /* Octet 3.1 - Interface Identifier */
-    if(pIE->IntIDPresent)
-    {
-        OBuf[(*Octet)++] = 0x80 | pIE->InterfaceID;
-    }
-    else
-    {
-        /* Octet 3.2 & 3.3 - PRI */
-        if(pIE->IntType == 1)
-        {
-            OBuf[(*Octet)++]  = 0x80
-                            | (pIE->CodStand << 5)
-                            | (pIE->NumMap << 4)
-                            | pIE->ChanMapType;
+	/* Octet 3.1 - Interface Identifier */
+	if(pIE->IntIDPresent)
+	{
+		OBuf[(*Octet)++] = 0x80 | (pIE->InterfaceID & 0x7f);
+	}
+	else
+	{
+		/* Octet 3.2 & 3.3 - PRI */
+		if(pIE->IntType == 1)
+		{
+			OBuf[(*Octet)++] = 0x80
+					| ((pIE->CodStand << 5) & 0x60)
+					| ((pIE->NumMap << 4) & 0x10)
+					|  (pIE->ChanMapType & 0x0f);		/* TODO: support all possible channel map types */
 
-            /* Octet 3.2 Channel number/slot map */
-            OBuf[(*Octet)++] = 0x80 | pIE->ChanSlot;
-        }
-    }
+			/* Octet 3.3 Channel number */
+			switch(pIE->ChanMapType) {
+			case 0x6:	/* Slot map: H0 Channel Units */	/* unsupported, Octets 3.3.1 - 3.3.3 */
+				return Q931E_CHANID;
 
-    OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2;
-    return rc;
+			case 0x8:	/* Slot map: H11 Channel Units */
+			case 0x9:	/* Slot map: H12 Channel Units */
+			default:	/* Channel number */
+				OBuf[(*Octet)++] = 0x80 | (pIE->ChanSlot & 0x7f);
+				break;
+			}
+		}
+	}
+
+	OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2;
+	return rc;
 }
 
 
@@ -1302,30 +1336,29 @@
 *****************************************************************************/
 L3USHORT Q931Uie_CRV(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff)
 {
+    L3USHORT CRV = 0;
     L3INT Octet = *IOff;
-    L3INT l = IBuf[Octet]; 
-    L3USHORT CRV;
-    Octet++; /*Octet 2 is length indicator */
+    L3INT l = IBuf[Octet++]; 
 
-    if(l == 1) /* One octet CRV */
+    if(l == 1)		/* One octet CRV */
     {
-        CRV = IBuf[Octet] & 0x7F;
-        Octet++;
+        CRV = IBuf[Octet++] & 0x7F;
     }
-    else if(l==2) /* two octet CRV */
+    else if(l == 2)	/* two octet CRV */
     {
-        CRV = (IBuf[Octet] & 0x7f) << 8;
-        CRV = CRV + IBuf[Octet+1];
-        Octet += 2;
+        CRV  = (IBuf[Octet++] & 0x7f) << 8;
+        CRV |=  IBuf[Octet++];
     }
     else
     {
-		/* Long CRV is not used, so we skip this */
-		/* TODO: is it right to set to 0 here? */
-		CRV = 0;
-        Octet+=l;
+	/* Long CRV is not used, so we skip this */
+	/* TODO: is it right to set to 0 here? */
+	CRV = 0;
+        Octet += l;
     }
 
+	Q931Log(pTrunk, Q931_LOG_DEBUG, "Call reference Value: %d (%#x)\n", CRV);
+
     *IOff = Octet;
     return CRV;
 }
@@ -1335,11 +1368,11 @@
   Function:     Q931Uie_DateTime
 
   Parameters:   pTrunk		[IN]		Ptr to trunk information.
-				pIE			[OUT]       ptr to Information Element id.
-                IBuf		[IN]        ptr to a packed ie.
-                OBuf		[OUT]       ptr to buffer for Unpacked ie.
-                IOff		[IN\OUT]    Input buffer offset
-                OOff		[IN\OUT]    Output buffer offset
+		pIE		[OUT]		ptr to Information Element id.
+                IBuf		[IN]		ptr to a packed ie.
+                OBuf		[OUT]		ptr to buffer for Unpacked ie.
+                IOff		[IN\OUT]	Input buffer offset
+                OOff		[IN\OUT]	Output buffer offset
 
                 Ibuf and OBuf points directly to buffers. The IOff and OOff
                 must be updated, but are otherwise not used in the ie unpack.
@@ -1349,65 +1382,64 @@
 *****************************************************************************/
 L3INT Q931Uie_DateTime(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *IOff, L3INT *OOff)
 {
-    Q931ie_DateTime * pie = (Q931ie_DateTime*)OBuf;
+	Q931ie_DateTime *pie = (Q931ie_DateTime*)OBuf;
 	ie *pIE = &pMsg->DateTime;
-    L3INT Off = 0;
-    L3INT Octet = 0;
-    L3INT IESize=0;
+	L3INT Off = 0;
+	L3INT Octet = 0;
+	L3INT IESize = 0;
+	*pIE=0;
 
-    *pIE=0;
+	/* Octet 1: ID */
+	pie->IEId  = IBuf[Octet++];
 
-    pie->IEId        = IBuf[Octet];
-    IESize = IBuf[Octet ++];
-    
-    /* Octet 2 */
-    IESize = IBuf[Octet ++]; 
+	/* Octet 2: Size */
+	IESize     = IBuf[Octet++]; 
 
-    /* Octet 3 - Year */
-    pie->Year = IBuf[Octet++];
+	/* Octet 3: Year */
+	pie->Year  = IBuf[Octet++];
 
-    /* Octet 4 - Month */
-    pie->Month = IBuf[Octet++];
+	/* Octet 4: Month */
+	pie->Month = IBuf[Octet++];
 
-    /* Octet 5 - Day */
-    pie->Day = IBuf[Octet++];
+	/* Octet 5: Day */
+	pie->Day   = IBuf[Octet++];
 
-    /*******************************************************************
-        The remaining part of the IE are optioinal, but only the length 
-        can now tell us wherever these fields are present or not
-    ********************************************************************/
-    pie->Format=0;
+	/*******************************************************************
+		The remaining part of the IE are optional, but only the length 
+		can now tell us wherever these fields are present or not
+	 ********************************************************************/
+	pie->Format=0;
 
-    /* Octet 6 - Hour (optional)*/
-    if(IESize >= 6)
-    {
-        pie->Format = 1;
-        pie->Hour = IBuf[Octet++];
+	/* Octet 6 - Hour (optional)*/
+	if(IESize >= 4)
+	{
+		pie->Format = 1;
+		pie->Hour = IBuf[Octet++];
+	}
 
-        /* Octet 7 - Minute (optional)*/
-        if(IESize >= 7)
-        {
-            pie->Format = 2;
-            pie->Minute = IBuf[Octet++];
+	/* Octet 7 - Minute (optional)*/
+	if(IESize >= 5)
+	{
+		pie->Format = 2;
+		pie->Minute = IBuf[Octet++];
+	}
 
-            /* Octet 8 - Second (optional)*/
-            if(IESize >= 8)
-            {
-                pie->Format = 3;
-                pie->Second = IBuf[Octet++];
-            }
-        }
-    }
+	/* Octet 8 - Second (optional)*/
+	if(IESize >= 6)
+	{
+		pie->Format = 3;
+		pie->Second = IBuf[Octet++];
+	}
 
-    Q931IESizeTest(Q931E_DATETIME);
+	Q931IESizeTest(Q931E_DATETIME);
 
-    Q931SetIE(*pIE, *OOff);
+	Q931SetIE(*pIE, *OOff);
 
-    *IOff = (*IOff) + Octet + Off;
-    *OOff = (*OOff) + sizeof(Q931ie_DateTime);
-    pie->Size = sizeof(Q931ie_DateTime);
+	*IOff = (*IOff) + Octet + Off;
+	*OOff = (*OOff) + sizeof(Q931ie_DateTime);
+	pie->Size = sizeof(Q931ie_DateTime);
 
-    return Q931E_NO_ERROR;
+	return Q931E_NO_ERROR;
 }
 
 /*****************************************************************************
@@ -1423,32 +1455,34 @@
 *****************************************************************************/
 L3INT Q931Pie_DateTime(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, L3UCHAR *OBuf, L3INT *Octet)
 {
-    Q931ie_DateTime * pIE = (Q931ie_DateTime*)IBuf;
-    L3INT rc=0;
-    L3INT Beg=*Octet;
-    L3INT li;
+	Q931ie_DateTime *pIE = (Q931ie_DateTime*)IBuf;
+	L3INT rc=0;
+	L3INT Beg=*Octet;
+	L3INT li;
 
-    OBuf[(*Octet)++] = Q931ie_DATETIME;
-    li=(*Octet)++;
+	OBuf[(*Octet)++] = Q931ie_DATETIME;
+	li=(*Octet)++;
 
-    OBuf[(*Octet)++] = pIE->Year;
-    OBuf[(*Octet)++] = pIE->Month;
-    OBuf[(*Octet)++] = pIE->Day;
-    if(pIE->Format >= 1)
-    {
-        OBuf[(*Octet)++] = pIE->Hour;
-        if(pIE->Format >= 2)
-        {
-            OBuf[(*Octet)++] = pIE->Minute;
-            if(pIE->Format >= 3)
-            {
-            OBuf[(*Octet)++] = pIE->Second;
-            }
-        }
-    }
+	OBuf[(*Octet)++] = pIE->Year;
+	OBuf[(*Octet)++] = pIE->Month;
+	OBuf[(*Octet)++] = pIE->Day;
 
-    OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2;
-    return rc;
+	/* optional fields */
+	if(pIE->Format >= 1)
+	{
+		OBuf[(*Octet)++] = pIE->Hour;
+		if(pIE->Format >= 2)
+		{
+			OBuf[(*Octet)++] = pIE->Minute;
+			if(pIE->Format >= 3)
+			{
+				OBuf[(*Octet)++] = pIE->Second;
+			}
+		}
+	}
+
+	OBuf[li] = (L3UCHAR)((*Octet)-Beg) - 2;
+	return rc;
 }
 
 /*****************************************************************************
@@ -1469,35 +1503,32 @@
 *****************************************************************************/
 L3INT Q931Uie_Display(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *pMsg, L3UCHAR * IBuf, L3UCHAR * OBuf, L3INT *IOff, L3INT *OOff)
 {
-    Q931ie_Display * pie = (Q931ie_Display*)OBuf;
+	Q931ie_Display * pie = (Q931ie_Display*)OBuf;
 	ie *pIE = &pMsg->Display;
-    L3INT Off = 0;
-    L3INT Octet = 0;
-    L3INT IESize;
-    L3INT x;
+	L3INT Off = 0;
+	L3INT Octet = 0;
+	L3INT IESize;
+	L3INT x;
+	*pIE=0;
 
-    *pIE=0;
+	pie->IEId = IBuf[Octet++];
+	IESize    = IBuf[Octet++]; 
 
-    pie->IEId        = IBuf[Octet];
-    Octet ++;
+	for(x=0; x<IESize; x++)
+	{
+		pie->Display[x] = IBuf[Octet+Off] & 0x7f;
+		Off++;
+	}
 
-    IESize = IBuf[Octet ++]; 
+	Q931IESizeTest(Q931E_DISPLAY);
 
-    for(x=0; x<IESize; x++)
-    {
-        pie->Display[x] = IBuf[Octet+Off] & 0x7f;
-        Off++;
-    }
+	Q931SetIE(*pIE, *OOff);
 
-    Q931IESizeTest(Q931E_DISPLAY);
+	*IOff = (*IOff) + Octet + Off;
+	*OOff = (*OOff) + sizeof(Q931ie_Display) + x - 1;
+	pie->Size = (L3UCHAR)(sizeof(Q931ie_Display) + x - 1);
 
-    Q931SetIE(*pIE, *OOff);
-
-    *IOff = (*IOff) + Octet + Off;
-    *OOff = (*OOff) + sizeof(Q931ie_Display) + x - 1;
-    pie->Size = (L3UCHAR)(sizeof(Q931ie_Display) + x - 1);
-
-    return Q931E_NO_ERROR;
+	return Q931E_NO_ERROR;
 }
 
 /*****************************************************************************
@@ -1634,7 +1665,7 @@
     li=(*Octet)++;
 
     /* Octet 3 */
-    OBuf[(*Octet)++] = 0x80 | (pIE->CodStand << 5) | (pIE->Interpret << 2) | pIE->PresMeth;
+    OBuf[(*Octet)++] = 0x80 | ((pIE->CodStand << 5) & 0x60) | ((pIE->Interpret << 2) & 0x1c) | (pIE->PresMeth & 0x03);
 
     /* Octet 4 */
     OBuf[(*Octet)++] = pIE->HLCharID;
@@ -1642,11 +1673,11 @@
     /* Octet 4a */
     if(pIE->HLCharID == 0x5e || pIE->HLCharID == 0x5f)
     {
-        OBuf[(*Octet)++] = 0x80 | pIE->EHLCharID;
+        OBuf[(*Octet)++] = 0x80 | (pIE->EHLCharID & 0x7f);
     }
     else if( pIE->HLCharID >= 0xc3 && pIE->HLCharID <= 0xcf)
     {
-        OBuf[(*Octet)++] = 0x80 | pIE->EVideoTlfCharID;
+        OBuf[(*Octet)++] = 0x80 | (pIE->EVideoTlfCharID & 0x7f);
     }
     else
     {
Index: src/isdn/Q931mes.c
===================================================================
--- src/isdn/Q931mes.c	(revision 495)
+++ src/isdn/Q931mes.c	(working copy)
@@ -43,6 +43,33 @@
 
 #include "Q931.h"
 
+/**
+ * Q931MesgHeader
+ * \brief	Create Q.931 Message header
+ */
+L3INT Q931MesgHeader(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *mes, L3UCHAR *OBuf, L3INT Size, L3INT *IOff)
+{
+	L3INT Octet = *IOff;
+
+	Q931Log(pTrunk, Q931_LOG_DEBUG, "Creating Q.931 Message Header:\n    ProtDisc %d (%#x), CRV %d (%#x), CRVflag: %d (%#x), MesType: %d (%#x)\n", mes->ProtDisc, mes->CRV, mes->CRVFlag, mes->MesType);
+
+	OBuf[Octet++] = mes->ProtDisc;				/* Protocol discriminator		*/
+	if(mes->CRV > 127) {
+		OBuf[Octet++] = 2;									/* length is 2 octets			*/
+		OBuf[Octet++] = (L3UCHAR)((mes->CRV>>8) & 0x7f) | ((mes->CRVFlag << 7) & 0x80);	/* msb					*/
+		OBuf[Octet++] = (L3UCHAR) (mes->CRV & 0xff);						/* lsb					*/
+	} else {
+		OBuf[Octet++] = 1;									/* length is 1 octet			*/
+		OBuf[Octet++] = (L3UCHAR) (mes->CRV & 0x7f) | ((mes->CRVFlag << 7) & 0x80);		/* CRV & flag				*/
+	}
+	OBuf[Octet++] = mes->MesType;				/* message header			*/
+
+	*IOff = Octet;
+
+	return 0;
+}
+
+
 /*****************************************************************************
 
   Function:     Q931Umes_Alerting
@@ -84,17 +111,12 @@
 *****************************************************************************/
 L3INT Q931Pmes_Alerting(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
 {
-    L3INT rc = Q931E_NO_ERROR;
+	L3INT rc = Q931E_NO_ERROR;
 	Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Bearer capability */
 	if(Q931IsIEPresent(pMes->BearerCap))
@@ -177,12 +199,7 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Bearer capability */
 	if(Q931IsIEPresent(pMes->BearerCap))
@@ -280,8 +297,10 @@
 			break;
 		}
 	}
-    mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
-    return Q931E_NO_ERROR;
+
+	mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
+
+	return Q931E_NO_ERROR;
 }
 
 /*****************************************************************************
@@ -296,12 +315,7 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Bearer capability */
 	if(Q931IsIEPresent(pMes->BearerCap))
@@ -392,12 +406,7 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Display */
 	if(Q931IsIEPresent(pMes->Display))
@@ -457,12 +466,7 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Cause */
 	if(Q931IsIEPresent(pMes->Cause))
@@ -516,8 +520,10 @@
 			break;
 		}
 	}
-    mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
-    return Q931E_NO_ERROR;
+
+	mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
+
+	return Q931E_NO_ERROR;
 }
 
 /*****************************************************************************
@@ -532,13 +538,8 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
-	
 	/* Sending Complete				*/
 	if(Q931IsIEPresent(pMes->SendComplete))
 		OBuf[Octet++]	= (L3UCHAR)(pMes->SendComplete & 0x00ff);
@@ -607,12 +608,7 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Bearer capability */
 	if(Q931IsIEPresent(pMes->BearerCap))
@@ -675,12 +671,7 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Bearer capability */
 	if(Q931IsIEPresent(pMes->BearerCap))
@@ -753,12 +744,7 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Cause */
 	if(Q931IsIEPresent(pMes->Cause))
@@ -820,12 +806,7 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Cause */
 	if(Q931IsIEPresent(pMes->Cause))
@@ -882,34 +863,29 @@
 *****************************************************************************/
 L3INT Q931Pmes_Restart(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
 {
-    L3INT rc = Q931E_NO_ERROR;
-    Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
-    L3INT Octet = 0;
+	L3INT rc = Q931E_NO_ERROR;
+	Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
+	L3INT Octet = 0;
 
-    /* Q931 Message Header */
+	/* Q931 Message Header */
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
+   
+	/* ChanID */
+	if(Q931IsIEPresent(pMes->ChanID))
+		if((rc=Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0)
+			return rc;
+	/* Display */
+	if(Q931IsIEPresent(pMes->Display))
+		if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0)
+			return rc;
+	/* RestartInd */
+	if(Q931IsIEPresent(pMes->RestartInd))
+		if((rc=Q931Pie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0)
+			return rc;
 
-    OBuf[Octet++]    = pMes->ProtDisc;        /* Protocol discriminator        */
-    OBuf[Octet++]    = 2;                    /* length is 2 octets            */
-    OBuf[Octet++]    = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);    /* msb                            */
-    OBuf[Octet++]    = (L3UCHAR)(pMes->CRV);    /* lsb                            */
-    OBuf[Octet++]    = pMes->MesType;        /* message header                */
-    
-    /* ChanID */
-    if(Q931IsIEPresent(pMes->ChanID))
-        if((rc=Q931Pie[pTrunk->Dialect][Q931ie_CHANNEL_IDENTIFICATION](pTrunk, Q931GetIEPtr(pMes->ChanID,pMes->buf), OBuf, &Octet))!=0)
-            return rc;
-    /* Display */
-    if(Q931IsIEPresent(pMes->Display))
-        if((rc=Q931Pie[pTrunk->Dialect][Q931ie_DISPLAY](pTrunk, Q931GetIEPtr(pMes->Display,pMes->buf), OBuf, &Octet))!=0)
-            return rc;
-    /* RestartInd */
-    if(Q931IsIEPresent(pMes->RestartInd))
-        if((rc=Q931Pie[pTrunk->Dialect][Q931ie_RESTART_INDICATOR](pTrunk, Q931GetIEPtr(pMes->RestartInd,pMes->buf), OBuf, &Octet))!=0)
-            return rc;
-
 	*OSize = Octet;	
 
-    return rc;
+	return rc;
 }
 
 /*****************************************************************************
@@ -953,13 +929,8 @@
     Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
     L3INT Octet = 0;
 
-    /* Q931 Message Header */
-
-    OBuf[Octet++]    = pMes->ProtDisc;        /* Protocol discriminator        */
-    OBuf[Octet++]    = 2;                    /* length is 2 octets            */
-    OBuf[Octet++]    = (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);    /* msb                            */
-    OBuf[Octet++]    = (L3UCHAR)(pMes->CRV);    /* lsb                            */
-    OBuf[Octet++]    = pMes->MesType;        /* message header                */
+	/* Q931 Message Header */
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
     
     /* ChanID */
     if(Q931IsIEPresent(pMes->ChanID))
@@ -1019,13 +990,8 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
-	
 	/* Call Identity */
 	if(Q931IsIEPresent(pMes->CallID))
 		if((rc=Q931Pie[pTrunk->Dialect][Q931ie_CALL_IDENTITY](pTrunk, Q931GetIEPtr(pMes->CallID,pMes->buf), OBuf, &Octet))!=0)
@@ -1061,8 +1027,10 @@
 			break;
 		}
 	}
-    mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
-    return Q931E_NO_ERROR;
+
+	mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
+
+	return Q931E_NO_ERROR;
 }
 
 
@@ -1073,17 +1041,12 @@
 *****************************************************************************/
 L3INT Q931Pmes_ResumeAck(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
 {
-    L3INT rc = Q931E_NO_ERROR;
+	L3INT rc = Q931E_NO_ERROR;
 	Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Channel Identification */
 	if(Q931IsIEPresent(pMes->ChanID))
@@ -1096,7 +1059,7 @@
 
 	*OSize = Octet;	
 
-    return rc;
+	return rc;
 }
 
 /*****************************************************************************
@@ -1124,8 +1087,10 @@
 			break;
 		}
 	}
-    mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
-    return Q931E_NO_ERROR;
+
+	mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
+
+	return Q931E_NO_ERROR;
 }
 
 
@@ -1141,11 +1106,7 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header	*/
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb						*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 
 	/* Cause				*/
 	if(Q931IsIEPresent(pMes->Cause))
@@ -1159,23 +1120,23 @@
 
 	*OSize = Octet;	
 
-    return rc;
+	return rc;
 }
 
 L3INT Q931Umes_Segment(Q931_TrunkInfo_t *pTrunk, L3UCHAR *IBuf, Q931mes_Generic *mes, L3INT IOff, L3INT OOff)
 {
-    L3INT i = IOff;
+	L3INT i = IOff;
 
-    return IOff - i;
+	return IOff - i;
 }
 
 L3INT Q931Pmes_Segment(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
 {
-    L3BOOL RetCode = L3FALSE;
+	L3BOOL RetCode = L3FALSE;
 
 	*OSize = 0;	
 
-    return RetCode;
+	return RetCode;
 }
 
 /*****************************************************************************
@@ -1196,6 +1157,7 @@
 		case Q931ie_SENDING_COMPLETE:
 			IOff++;
 			break;
+
 		case Q931ie_BEARER_CAPABILITY:
 		case Q931ie_CHANNEL_IDENTIFICATION:
 		case Q931ie_PROGRESS_INDICATOR:
@@ -1215,6 +1177,7 @@
 			if(rc != Q931E_NO_ERROR) 
 				return rc;
 			break;
+
 		case Q931ie_REPEAT_INDICATOR:
 			if(ir < 2) {
 				rc = Q931Uie[pTrunk->Dialect][IBuf[IOff]](pTrunk, mes, &IBuf[IOff], &mes->buf[OOff], &IOff, &OOff);
@@ -1223,13 +1186,16 @@
 				return Q931E_ILLEGAL_IE;
 			}
 			break;
+
 		default:
 			return Q931E_ILLEGAL_IE;
 			break;
 		}
 	}
-    mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
-    return Q931E_NO_ERROR;
+
+	mes->Size = sizeof(Q931mes_Generic) - 1 + OOff;
+
+	return Q931E_NO_ERROR;
 }
 
 /*****************************************************************************
@@ -1252,18 +1218,13 @@
 *****************************************************************************/
 L3INT Q931Pmes_Setup(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *IBuf, L3INT ISize, L3UCHAR *OBuf, L3INT *OSize)
 {
-    L3INT rc = Q931E_NO_ERROR;
+	L3INT rc = Q931E_NO_ERROR;
 	Q931mes_Generic *pMes = (Q931mes_Generic *)IBuf;
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb						*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
-	
 	/* Sending Complete				*/
 	if(Q931IsIEPresent(pMes->SendComplete))
 		OBuf[Octet++]	= (L3UCHAR)(pMes->SendComplete & 0x00ff);
@@ -1359,7 +1320,7 @@
 
 	*OSize = Octet;	
 
-    return rc;
+	return rc;
 }
 
 /*****************************************************************************
@@ -1405,12 +1366,7 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Channel Identification */
 	if(Q931IsIEPresent(pMes->ChanID))
@@ -1480,12 +1436,7 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Cause */
 	if(Q931IsIEPresent(pMes->Cause))
@@ -1545,12 +1496,7 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Display */
 	if(Q931IsIEPresent(pMes->Display))
@@ -1602,12 +1548,7 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Call Identity */
 	if(Q931IsIEPresent(pMes->CallID))
@@ -1660,12 +1601,7 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Display */
 	if(Q931IsIEPresent(pMes->Display))
@@ -1718,12 +1654,7 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Cause */
 	if(Q931IsIEPresent(pMes->Cause))
@@ -1817,12 +1748,7 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Display */
 	if(Q931IsIEPresent(pMes->ChanID))
@@ -1883,12 +1809,7 @@
 	L3INT Octet = 0;
 
 	/* Q931 Message Header */
-
-	OBuf[Octet++]	= pMes->ProtDisc;		/* Protocol discriminator		*/
-	OBuf[Octet++]	= 2;					/* length is 2 octets			*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV>>8) | (pMes->CRVFlag << 7);	/* msb							*/
-	OBuf[Octet++]	= (L3UCHAR)(pMes->CRV);	/* lsb							*/
-	OBuf[Octet++]	= pMes->MesType;		/* message header				*/
+	Q931MesgHeader(pTrunk, pMes, OBuf, *OSize, &Octet);
 	
 	/* Display */
 	if(Q931IsIEPresent(pMes->ChanID))
Index: src/isdn/include/Q931.h
===================================================================
--- src/isdn/include/Q931.h	(revision 495)
+++ src/isdn/include/Q931.h	(working copy)
@@ -209,15 +209,15 @@
 
 *****************************************************************************/
 
-#define L3UCHAR		unsigned char		/* Min 8 bit						*/
-#define L3USHORT	unsigned short		/* Min 16 bit unsigned				*/
-#define L3UINT		unsigned int		/* Min 16 bit unsigned	            */
-#define L3INT       int                 /* Min 16 bit signed                */
-#define L3ULONG		unsigned long		/* Min 32 bit						*/
-#define L3BOOL      char				/* Min 1 bit, valuse 0 & 1 only		*/
+#define L3UCHAR		unsigned char		/* Min 8 bit			*/
+#define L3USHORT	unsigned short		/* Min 16 bit unsigned		*/
+#define L3UINT		unsigned int		/* Min 16 bit unsigned		*/
+#define L3INT		int			/* Min 16 bit signed		*/
+#define L3ULONG		unsigned long		/* Min 32 bit			*/
+#define L3BOOL		char			/* Min 1 bit, valuse 0 & 1 only	*/
 
-#define L3TRUE      1
-#define L3FALSE     0 
+#define L3TRUE		1
+#define L3FALSE		0 
 
 /*****************************************************************************
 
@@ -244,24 +244,25 @@
 
 *****************************************************************************/
 
-#define Q931L4BUF  1000             /* size of message buffer               */
+#define	Q931_LOGBUFSIZE		1024	/* size of logging buffer */
 
-#define Q931L2BUF	300				/* size of message buffer				*/
+#define Q931L4BUF		1000	/* size of message buffer               */
 
-#define Q931MAXTRUNKS	4			/* Total number of trunks that will be	*/
-									/* processed by this instance of the	*/
-									/* stack								*/
+#define Q931L2BUF		300	/* size of message buffer		*/
 
-#define Q931MAXCHPERTRUNK	32		/* Number of channels per trunk. The	*/
-									/* stack uses a static set of 32		*/
-									/* channels regardless if it is E1, T1	*/
-									/* or BRI that actually is used.		*/
+#define Q931MAXTRUNKS		4	/* Total number of trunks that will be	*/
+					/* processed by this instance of the	*/
+					/* stack				*/
 
-#define Q931MAXCALLPERTRUNK (Q931MAXCHPERTRUNK * 2)
-                                    /* Number of max active CRV per trunk.  */
-									/* Q.931 can have more calls than there */
-									/* are channels.						*/
+#define Q931MAXCHPERTRUNK	32	/* Number of channels per trunk. The	*/
+					/* stack uses a static set of 32	*/
+					/* channels regardless if it is E1, T1	*/
+					/* or BRI that actually is used.	*/
 
+#define Q931MAXCALLPERTRUNK (Q931MAXCHPERTRUNK * 2)	/* Number of max active CRV per trunk.  */
+							/* Q.931 can have more calls than there */
+							/* are channels.			*/
+
 /*****************************************************************************
 
   The following defines control the dialect switch tables and should only be
@@ -280,25 +281,26 @@
 
 *****************************************************************************/
 
-/* WARNING! Initialize Q931CreateDialectCB[] will NULL when increasing the  */
-/* Q931MAXDLCT value to avoid Q931Initialize from crashing if one entry is  */
-/* not used.																*/
-#define Q931MAXDLCT 8           /* Max dialects included in this        */
-                                /* compile. User and Network count as   */
-                                /* one dialect each.                    */
+/* WARNING! Initialize Q931CreateDialectCB[] will NULL when increasing the	*/
+/* Q931MAXDLCT value to avoid Q931Initialize from crashing if one entry is	*/
+/* not used.									*/
 
+#define Q931MAXDLCT	8		/* Max dialects included in this        */
+					/* compile. User and Network count as   */
+					/* one dialect each.                    */
 
-#define Q931MAXMES  128         /* Number of messages							*/
 
-#define Q931MAXIE  255          /* Number of IE									*/
+#define Q931MAXMES	128		/* Number of messages			*/
 
-#define Q931MAXUSEDIE 50		/* Maximum number of ie types per Dialect		*/
+#define Q931MAXIE	255		/* Number of IE				*/
 
-#define Q931MAXCODESETS 7		/* Maximum number of codests (by spec, 0-7)		*/
+#define Q931MAXUSEDIE	50		/* Maximum number of ie types per Dialect	*/
 
-#define Q931MAXSTATE 100		/* Size of state tables					        */
+#define Q931MAXCODESETS	7		/* Maximum number of codests (by spec, 0-7)	*/
 
+#define Q931MAXSTATE	100		/* Size of state tables			*/
 
+
 /*****************************************************************************
 
   Call States for ITU-T Q.931 TE (User Mode)
@@ -371,7 +373,7 @@
 #define Q931mes_RESTART              0x46 /* 0100 0110                   */
 #define Q931mes_RESTART_ACKNOWLEDGE  0x4e /* 0100 1110                   */
 #define Q931mes_CONGESTION_CONTROL   0x79 /* 0111 1001                   */
-#define Q931mes_INFORMATION          0x7a /* 0111 1011                   */
+#define Q931mes_INFORMATION          0x7b /* 0111 1011                   */
 #define Q931mes_NOTIFY               0x6e /* 0110 1110                   */
 #define Q931mes_STATUS               0x7d /* 0111 1101                   */
 #define Q931mes_STATUS_ENQUIRY       0x75 /* 0111 0101                   */
@@ -390,12 +392,12 @@
 *****************************************************************************/
 typedef struct
 {
-    L3UINT			Size;           /* Size of message in bytes             */
-    L3UCHAR         ProtDisc;       /* Protocol Discriminator               */
-    L3UCHAR         MesType;        /* Message type                         */
-    L3UCHAR         CRVFlag;        /* Call reference value flag            */
-    L3INT           CRV;            /* Call reference value                 */
-}Q931mes_Header;
+	L3UINT		Size;		/* Size of message in bytes             */
+	L3UCHAR		ProtDisc;	/* Protocol Discriminator               */
+	L3UCHAR		MesType;	/* Message type                         */
+	L3UCHAR		CRVFlag;	/* Call reference value flag            */
+	L3INT		CRV;		/* Call reference value                 */
+} Q931mes_Header;
 
 /*****************************************************************************
 
@@ -407,53 +409,53 @@
 *****************************************************************************/
 typedef struct
 {
-    L3UINT			Size;           /* Size of message in bytes             */
-    L3UCHAR         ProtDisc;       /* Protocol Discriminator               */
-    L3UCHAR         MesType;        /* Message type                         */
-    L3UCHAR         CRVFlag;        /* Call reference value flag            */
-    L3INT           CRV;            /* Call reference value                 */
+	L3UINT		Size;           /* Size of message in bytes             */
+	L3UCHAR         ProtDisc;       /* Protocol Discriminator               */
+	L3UCHAR         MesType;        /* Message type                         */
+	L3UCHAR         CRVFlag;        /* Call reference value flag            */
+	L3INT           CRV;            /* Call reference value                 */
 
-    ie              Shift;
-    ie              MoreData;
-    ie              SendComplete;
-    ie              CongestionLevel;
-    ie              RepeatInd;
+	ie              Shift;
+	ie              MoreData;
+	ie              SendComplete;
+	ie              CongestionLevel;
+	ie              RepeatInd;
 
-    ie              Segment;        /* Segmented message                    */
-    ie              BearerCap;      /* Bearer Capability                    */
-    ie              Cause;          /* Cause                                */
-    ie              CallState;      /* Call State                           */
-    ie              CallID;			/* Call Identity                        */
-    ie              ChanID;         /* Channel Identification               */
-    ie              ChangeStatus;   /* Change Staus                         */
-    ie              ProgInd;        /* Progress Indicator                   */
-    ie              NetFac;         /* Network Spesific Facilities          */
-    ie              NotifInd;       /* Notification Indicator               */
-    ie              Display;        /* Display                              */
-    ie              DateTime;       /* Date/Time                            */
-    ie              KeypadFac;      /* Keypad Facility                      */
-    ie              Signal;         /* Signal                               */
-    ie              InfoRate;       /* Information rate                     */
-    ie              EndEndTxDelay;  /* End to End Transmit Delay            */
-    ie              TransDelSelInd; /* Transmit Delay Sel. and Ind.         */
-    ie              PackParam;      /* Packed Layer Binary parameters       */
-    ie              PackWinSize;    /* Packet Layer Window Size             */
-    ie              PackSize;       /* Packed Size                          */
-    ie              ClosedUserGrp;  /* Closed User Group                    */
-    ie              RevChargeInd;   /* Reverse Charging Indicator           */
-    ie              CalledNum;      /* Called Party Number                  */
-    ie              CalledSub;      /* Called Party subaddress              */
-    ie              CallingNum;     /* Calling Party Number                 */
-    ie              CallingSub;     /* Calling Party Subaddress             */
-    ie              RedirNum;       /* Redirection Number                   */
-    ie              TransNetSel;    /* Transmit Network Selection           */
-    ie              LLRepeatInd;    /* Repeat Indicator 2 LLComp            */
-    ie              RestartWin;     /* Restart Window                       */
-    ie              RestartInd;     /* Restart Indicator                    */
-    ie              LLComp;         /* Low Layer Compatibility              */
-    ie              HLComp;         /* High Layer Compatibility             */
-    ie              UserUser;       /* User-user                            */
-    ie              Escape;         /* Escape for extension                 */
+	ie              Segment;        /* Segmented message                    */
+	ie              BearerCap;      /* Bearer Capability                    */
+	ie              Cause;          /* Cause                                */
+	ie              CallState;      /* Call State                           */
+	ie              CallID;		/* Call Identity                        */
+	ie              ChanID;         /* Channel Identification               */
+	ie              ChangeStatus;   /* Change Staus                         */
+	ie              ProgInd;        /* Progress Indicator                   */
+	ie              NetFac;         /* Network Spesific Facilities          */
+	ie              NotifInd;       /* Notification Indicator               */
+	ie              Display;        /* Display                              */
+	ie              DateTime;       /* Date/Time                            */
+	ie              KeypadFac;      /* Keypad Facility                      */
+	ie              Signal;         /* Signal                               */
+	ie              InfoRate;       /* Information rate                     */
+	ie              EndEndTxDelay;  /* End to End Transmit Delay            */
+	ie              TransDelSelInd; /* Transmit Delay Sel. and Ind.         */
+	ie              PackParam;      /* Packed Layer Binary parameters       */
+	ie              PackWinSize;    /* Packet Layer Window Size             */
+	ie              PackSize;       /* Packed Size                          */
+	ie              ClosedUserGrp;  /* Closed User Group                    */
+	ie              RevChargeInd;   /* Reverse Charging Indicator           */
+	ie              CalledNum;      /* Called Party Number                  */
+	ie              CalledSub;      /* Called Party subaddress              */
+	ie              CallingNum;     /* Calling Party Number                 */
+	ie              CallingSub;     /* Calling Party Subaddress             */
+	ie              RedirNum;       /* Redirection Number                   */
+	ie              TransNetSel;    /* Transmit Network Selection           */
+	ie              LLRepeatInd;    /* Repeat Indicator 2 LLComp            */
+	ie              RestartWin;     /* Restart Window                       */
+	ie              RestartInd;     /* Restart Indicator                    */
+	ie              LLComp;         /* Low Layer Compatibility              */
+	ie              HLComp;         /* High Layer Compatibility             */
+	ie              UserUser;       /* User-user                            */
+	ie              Escape;         /* Escape for extension                 */
 	ie				Switchhook;
 	ie				FeatAct;
 	ie				FeatInd;
@@ -461,7 +463,7 @@
 
 	L3UCHAR			buf[1];			/* Buffer for IE's						*/
 
-}Q931mes_Generic;
+} Q931mes_Generic;
 
 
 /*****************************************************************************
@@ -479,13 +481,28 @@
 *****************************************************************************/
 typedef struct Q931_TrunkInfo Q931_TrunkInfo_t;
 
-typedef L3INT (*Q931TxCB_t) (void *,L3UCHAR *, L3INT);
-typedef L3INT (*Q931ErrorCB_t) (void *,L3INT,L3INT,L3INT);
+/*
+ * Logging
+ */
+typedef enum
+{
+	Q931_LOG_NONE = 0,
+	Q931_LOG_ERROR,
+	Q931_LOG_WARNING,
+	Q931_LOG_NOTICE,
+	Q931_LOG_INFO,
+	Q931_LOG_DEBUG
+} Q931LogLevel_t;
 
+typedef L3INT (*Q931Tx34CB_t) (void *, L3UCHAR *, L3INT);
+typedef L3INT (*Q931Tx32CB_t) (void *, L3INT, L3UCHAR *, L3INT);
+typedef L3INT (*Q931ErrorCB_t) (void *, L3INT, L3INT, L3INT);
+typedef L3INT (*Q931LogCB_t) (void *, Q931LogLevel_t, char *, L3INT);
+
 typedef enum						/* Network/User Mode.                   */
 {
-	Q931_TE=0,						/*  0 : User Mode                       */
-    Q931_NT=1						/*  1 : Network Mode                    */
+	Q931_TE=0,					/*  0 : User Mode                       */
+	Q931_NT=1					/*  1 : Network Mode                    */
 } Q931NetUser_t;
 
 typedef enum						/* Dialect enum                         */
@@ -493,124 +510,129 @@
 	Q931_Dialect_Q931     = 0,
 	Q931_Dialect_National = 2,
 	Q931_Dialect_DMS      = 4,
-	Q931_Dialect_5ESS     = 6,      /* Coming soon to a PRI stack near you! */
+	Q931_Dialect_5ESS     = 6,			/* Coming soon to a PRI stack near you! */
 
 	Q931_Dialect_Count
 } Q931Dialect_t;
-#define DIALECT_STRINGS "q931", "", "national", "", "dms","","5ess",""
+#define DIALECT_STRINGS "q931", "", "national", "", "dms", "", "5ess", ""
 Q931_STR2ENUM_P(q931_str2Q931Dialect_type, q931_Q931Dialect_type2str, Q931Dialect_t)
 
 typedef enum						/* Trunk Line Type.                     */
 {
 	Q931_TrType_E1=0,				/*  0 : E1 Trunk                        */
-    Q931_TrType_T1=1,				/*  1 : T1 Trunk                        */
-    Q931_TrType_J1=2,				/*  2 : J1 Trunk                        */
-    Q931_TrType_BRI=3				/*  3 : BRI Trunk                       */
+	Q931_TrType_T1=1,				/*  1 : T1 Trunk                        */
+	Q931_TrType_J1=2,				/*  2 : J1 Trunk                        */
+	Q931_TrType_BRI=3,				/*  3 : BRI Trunk                       */
+	Q931_TrType_BRI_PTMP=4				/*  4 : BRI Trunk                       */
 } Q931_TrunkType_t;
 
-typedef enum						/* Trunk State							*/
+typedef enum						/* Trunk State				*/
 {
-	Q931_TrState_NoAlignment=0,		/* Trunk not aligned					*/
-	Q931_TrState_Aligning=1,		/* Aligning in progress					*/
-	Q931_TrState_Aligned=2			/* Trunk Aligned						*/
+	Q931_TrState_NoAlignment=0,			/* Trunk not aligned			*/
+	Q931_TrState_Aligning=1,			/* Aligning in progress			*/
+	Q931_TrState_Aligned=2				/* Trunk Aligned			*/
 } Q931_TrunkState_t;
 
 typedef enum {
-	Q931_ChType_NotUsed=0,			/* Unused Channel						*/
-	Q931_ChType_B=1,				/* B Channel (Voice)					*/
-	Q931_ChType_D=2,				/* D Channel (Signalling)				*/
-	Q931_ChType_Sync=3				/* Sync Channel							*/
+	Q931_ChType_NotUsed=0,				/* Unused Channel			*/
+	Q931_ChType_B=1,				/* B Channel (Voice)			*/
+	Q931_ChType_D=2,				/* D Channel (Signalling)		*/
+	Q931_ChType_Sync=3				/* Sync Channel				*/
 } Q931_ChanType_t;
 
+
 struct Q931_TrunkInfo
 {
 	Q931NetUser_t NetUser;			/* Network/User Mode.                   */
 
-    Q931Dialect_t Dialect;			/* Q.931 Based dialect index.           */
+	Q931Dialect_t Dialect;			/* Q.931 Based dialect index.           */
 
 	Q931_TrunkType_t TrunkType;		/* Trunk Line Type.                     */
 
-	Q931TxCB_t	Q931Tx34CBProc;
-	Q931TxCB_t	Q931Tx32CBProc;
-	Q931ErrorCB_t Q931ErrorCBProc;
+	Q931Tx34CB_t	Q931Tx34CBProc;
+	Q931Tx32CB_t	Q931Tx32CBProc;
+	Q931ErrorCB_t   Q931ErrorCBProc;
+	Q931LogCB_t	Q931LogCBProc;
 	void *PrivateData32;
 	void *PrivateData34;
+	void *PrivateDataLog;
 
-	L3UCHAR     Enabled;            /* Enabled/Disabled                     */
-                                    /*  0 = Disabled                        */
-                                    /*  1 = Enabled                         */
+	Q931LogLevel_t	loglevel;
 
+	L3UCHAR     Enabled;			/* Enabled/Disabled                     */
+						/*  0 = Disabled                        */
+						/*  1 = Enabled                         */
+
 	Q931_TrunkState_t TrunkState;
 
-    L3INT       LastCRV;            /* Last used crv for the trunk.         */
+	L3INT	LastCRV;			/* Last used crv for the trunk.         */
 
-    L3UCHAR L3Buf[Q931L4BUF];		/* message buffer for messages to be    */
-                                    /* send from Q.931 L4.                  */
+	L3UCHAR L3Buf[Q931L4BUF];		/* message buffer for messages to be    */
+						/* send from Q.931 L4.                  */
 
-    L3UCHAR L2Buf[Q931L2BUF];		/* buffer for messages send to L2.      */
+	L3UCHAR L2Buf[Q931L2BUF];		/* buffer for messages send to L2.      */
 
 	/* The auto flags below switch on/off automatic Ack messages. SETUP ACK */
 	/* as an example can be sent by the stack in response to SETUP to buy   */
 	/* time in processing on L4. Setting this to true will cause the stack  */
-	/* to automatically send this.											*/
+	/* to automatically send this.						*/
 
 	L3BOOL	autoSetupAck;			/* Indicate if the stack should send    */
-									/* SETUP ACK or not. 0=No, 1 = Yes.		*/
+						/* SETUP ACK or not. 0=No, 1 = Yes.	*/
 
 	L3BOOL  autoConnectAck;			/* Indicate if the stack should send    */
-									/* CONNECT ACT or not. 0=No, 1=Yes.		*/
+						/* CONNECT ACT or not. 0=No, 1=Yes.	*/
 
 	L3BOOL  autoRestartAck;			/* Indicate if the stack should send    */
-									/* RESTART ACK or not. 0=No, 1=Yes.		*/
+						/* RESTART ACK or not. 0=No, 1=Yes.	*/
 
 	L3BOOL  autoServiceAck;			/* Indicate if the stack should send    */
-									/* SERVICE ACK or not. 0=No, 1=Yes.		*/
+						/* SERVICE ACK or not. 0=No, 1=Yes.	*/
 
 	/* channel array holding info per channel. Usually defined to 32		*/
 	/* channels to fit an E1 since T1/J1 and BRI will fit inside a E1.		*/
-    struct _charray
-    {
+	struct _charray
+	{
 		Q931_ChanType_t ChanType;	/* Unused, B, D, Sync */
 
-        L3UCHAR Available;          /* Channel Available Flag               */
-                                    /*  0 : Avaiabled                       */
-                                    /*  1 : Used                            */
+		L3UCHAR Available;		/* Channel Available Flag               */
+						/*  0 : Avaiabled                       */
+						/*  1 : Used                            */
 
-        L3INT   CRV;                /* Associated CRV                       */
+		L3INT   CRV;			/* Associated CRV                       */
 
-    }ch[Q931MAXCHPERTRUNK];
+	} ch[Q931MAXCHPERTRUNK];
 
-    /* Active Call information indentified by CRV. See Q931AllocateCRV for  */
-	/* initialization of call table.										*/
-    struct _ccarray
-    {
-        L3UCHAR InUse;              /* Indicate if entry is in use.         */
-                                    /*  0 = Not in Use                      */
-                                    /*  1 = Active Call.                    */
+	/* Active Call information indentified by CRV. See Q931AllocateCRV for  */
+	/* initialization of call table.					*/
+	struct _ccarray
+	{
+		L3UCHAR InUse;			/* Indicate if entry is in use.         */
+						/*  0 = Not in Use                      */
+						/*  1 = Active Call.                    */
 
-        L3UCHAR BChan;              /* Associated B Channel.                */
-									/* 0 - 31 valid B chan					*/
-									/* 255 = Not allocated					*/
+		L3UCHAR BChan;			/* Associated B Channel.                */
+						/* 0 - 31 valid B chan			*/
+						/* 255 = Not allocated			*/
 
-        L3INT   CRV;                /* Associated CRV.                      */
+		L3INT   CRV;			/* Associated CRV.                      */
 
-        L3UINT  State;              /* Call State.                          */
-									/*  0 is Idle, but other values are		*/
-									/*  defined per dialect.				*/
-									/*  Default usage is 1-99 for TE and    */
-									/*  101 - 199 for NT.					*/
+		L3UINT  State;			/* Call State.                          */
+						/*  0 is Idle, but other values are	*/
+						/*  defined per dialect.		*/
+						/*  Default usage is 1-99 for TE and    */
+						/*  101 - 199 for NT.			*/
         
-        L3ULONG Timer;              /* Timer in ms. The TimeTick will check */
-									/* if this has exceeded the timeout, and*/
-									/* if so call the timers timeout proc.	*/
+		L3ULONG Timer;			/* Timer in ms. The TimeTick will check */
+						/* if this has exceeded the timeout, and*/
+						/* if so call the timers timeout proc.	*/
 
-        L3USHORT TimerID;           /* Timer Identification/State           */
-									/* actual values defined by dialect		*/
-                                    /*  0 : No timer running                */
-                                    /*  ITU-T Q.931:301 - 322 Timer running */
+		L3USHORT TimerID;		/* Timer Identification/State           */
+						/* actual values defined by dialect	*/
+						/*  0 : No timer running                */
+						/*  ITU-T Q.931:301 - 322 Timer running */
+	} call[Q931MAXCALLPERTRUNK];
 
-    }call[Q931MAXCALLPERTRUNK];
-
 };
 
 /*****************************************************************************
@@ -894,8 +916,9 @@
 
 *****************************************************************************/
 void    Q931TimeTick(Q931_TrunkInfo_t *pTrunk, L3ULONG ms);
-L3INT   Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size);
-L3INT   Q931Tx32(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size);
+L3INT   Q931Rx23(Q931_TrunkInfo_t *pTrunk, L3INT, L3UCHAR * Mes, L3INT Size);
+L3INT   Q931Tx32Data(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size);
+L3INT   Q931Tx32UnitData(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size);
 L3INT   Q931Rx43(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size);
 L3INT   Q931Tx34(Q931_TrunkInfo_t *pTrunk, L3UCHAR * Mes, L3INT Size);
 void    Q931SetError(Q931_TrunkInfo_t *pTrunk,L3INT ErrID, L3INT ErrPar1, L3INT ErrPar2);
@@ -965,8 +988,8 @@
 						Q931Dialect_t Dialect,
 						Q931NetUser_t NetUser,
 						Q931_TrunkType_t TrunkType,
-						Q931TxCB_t Q931Tx34CBProc,
-						Q931TxCB_t Q931Tx32CBProc,
+						Q931Tx34CB_t Q931Tx34CBProc,
+						Q931Tx32CB_t Q931Tx32CBProc,
 						Q931ErrorCB_t Q931ErrorCBProc,
 						void *PrivateData32,
 						void *PrivateData34);
@@ -986,6 +1009,11 @@
 L3INT Q931TxDummy(Q931_TrunkInfo_t *pTrunk, L3UCHAR * b, L3INT n);
 L3INT Q931ErrorDummy(void *priv, L3INT a, L3INT b, L3INT c);
 
+L3INT Q931Log(Q931_TrunkInfo_t *trunk, Q931LogLevel_t level, const char *fmt, ...);
 
+void Q931SetLogCB(Q931_TrunkInfo_t *trunk, Q931LogCB_t func, void *priv);
+void Q931SetLogLevel(Q931_TrunkInfo_t *trunk, Q931LogLevel_t level);
 
+L3INT Q931MesgHeader(Q931_TrunkInfo_t *pTrunk, Q931mes_Generic *mes, L3UCHAR *OBuf, L3INT Size, L3INT *IOff);
+
 #endif /* _Q931_NL */
