T38 Fax not working  due to wrong SDP ?

Symptoms:  In case of MSBG , SIP signalling also gets transmit between SBC and TDM gateway for T38 REINVITE.
If SBC is sending below format m lines in SDP then "TDM gateway" will send invalid SDP, due to which T.38 Fax will not work.
T.38 REINIVTE from SBC to TDM gateway has two m lines where for audio m line port is 0.

m=audio 0 RTP/AVP 19
m=image 61192 udptl t38

TDM gateway response would be something like below where TDM gateway is setting port to 0 for both m lines.

m=image 0 udptl t38
m=image 0 udptl 19

Note: wireshark on all interface (including TDM gateway local ip) can show above call flow. 

Solution -  In order to resolve this error condition , we need to set below parameter within TDM to SIP Routing Dialplan SBC dialplan while bridging call coming from TDM gateway to External SIP trunk.

 <condition field="destination_number" expression="(.*)" break="on-true">
  <action application="export" data="t38_only_image_media_in_sdp_offer=true"/>
  <action application="bridge" data="sip/trunk/xx.xxx.xx.xxx/$1"/>
</condition>

T38 Fax failing due to not receiving cng tone?

We might not receive CNG tone for FAX and if you see TDM gateway is not responding to T.38 REINIVITE then, below parameters needs to be incorporated within to-sip context of TDM Gateway dial plan 

GUI -> Configuration -> Gateway -> Dialplan

<context name="from-pstn-to-sip">
  <extension name="to-sip">
     <condition field="${destination_number}" expression="^(.*)$" break="on-true">
       <action application="set" data="hangup_after_bridge=yes" />
       <action application="set" data="tone_detect_hits=1" />
       <action application="export" data="fax_enable_t38_request=true" />
       <action application="export" data="fax_enable_t38=true" />
       <action application="tone_detect" data="faxdisable 1100 r +5000 disable_ec 1"/>
       <!-- <action application="export" data="execute_on_answer=tone_detect fax_disable_ec 2100 r +5000 t38_gateway 'self nocng'" /> -->  < !– Remove/Comment this line -->
       <action application="set" data="hangup_after_bridge=yes"/>
       <action application="bridge" data="{sip_execute_on_image='t38_gateway self nocng'}sofia/internal/${destnum}@${sip_remote_ip}:${sip_remote_port}"/>
       <action application="hangup" data="${originate_disposition}"/>
     </condition>
  </extension>
</context>