--- ProxyChannel.cxx.orig	2010-02-10 07:09:52.000000000 +0500
+++ ProxyChannel.cxx	2010-02-16 17:59:30.000000000 +0500
@@ -1224,6 +1224,43 @@
 
 	PTRACE(4, "H245\tReceived from " << GetName() << ": " << setprecision(2) << h245msg);
 
+	/*
+		Avaya Communication Manager 3.1 equipped by TN2602AP media processor becomes confused
+		when it receives t38FaxUdpOptions in t38FaxProfile of H.245 RequestMode. For example,
+		AddPac VoiceFinder does so. After that TN2602AP starts to send larger T.38 packets than
+		receiver can process. This results in facsimile document distortion. So we need to remove
+		t38FaxUdpOptions from RM to make ACM3.1+TN2602AP become compatible with endpoints which send
+		t38FaxUdpOptions in RM.
+		
+		This code is executed only if [RoutedMode] RemoveFaxUDPOptionsFromRM option is set to 1.
+		
+		d.kochmashev
+	*/
+	
+        if (h245msg.GetTag() == H245_MultimediaSystemControlMessage::e_request
+    		&& ((H245_RequestMessage &) h245msg).GetTag() == H245_RequestMessage::e_requestMode
+		&& Toolkit::AsBool(GkConfig()->GetString(RoutedSec, "RemoveFaxUDPOptionsFromRM", "0"))
+        ) {
+                H245_RequestMode & rm = (H245_RequestMessage &) h245msg;
+                for(PINDEX i = 0; i < rm.m_requestedModes.GetSize(); i++) {
+                        for(PINDEX j = 0; j < rm.m_requestedModes[i].GetSize(); j++) {
+                                if(rm.m_requestedModes[i][j].m_type.GetTag() == H245_ModeElementType::e_dataMode) {
+                                        H245_DataMode & dm = (H245_DataMode &) rm.m_requestedModes[i][j].m_type;
+                                        if(dm.m_application.GetTag() == H245_DataMode_application::e_t38fax) {
+                                                H245_DataMode_application_t38fax & t38fax = (H245_DataMode_application_t38fax &) dm.m_application;
+                                                if(
+                                                        t38fax.m_t38FaxProtocol.GetTag() == H245_DataProtocolCapability::e_udp
+                                                        && t38fax.m_t38FaxProfile.HasOptionalField(H245_T38FaxProfile::e_t38FaxUdpOptions)
+                                                ) {
+                                                        PTRACE(2, "H245\tRemoving t38FaxUdpOptions received in RM from " << GetName());
+                                                        t38fax.m_t38FaxProfile.RemoveOptionalField(H245_T38FaxProfile::e_t38FaxUdpOptions);
+                                                }
+                                        }
+                                }
+                        }
+                }
+        }
+
 	if (h245msg.GetTag() == H245_MultimediaSystemControlMessage::e_request
 			&& ((H245_RequestMessage&)h245msg).GetTag() == H245_RequestMessage::e_openLogicalChannel) {
 		H245_OpenLogicalChannel &olc = (H245_RequestMessage&)h245msg;
@@ -4362,7 +4399,9 @@
 	if (hnat && Request.GetTag() == H245_RequestMessage::e_openLogicalChannel) {
 		return hnat->HandleOpenLogicalChannel(Request);
 	} else if  (Request.GetTag() == H245_RequestMessage::e_terminalCapabilitySet) {
-       return true;
+    		return true;
+	} else if  (Request.GetTag() == H245_RequestMessage::e_requestMode) {
+    		return true;
 	} else {
 		return false;
 	}
