1. 程式人生 > >FreeSWITCH 處理Refer盲轉時,UUI傳遞不對(沒有將SIP 訊息頭Refer-To中的User-to-User傳遞給B-Leg)

FreeSWITCH 處理Refer盲轉時,UUI傳遞不對(沒有將SIP 訊息頭Refer-To中的User-to-User傳遞給B-Leg)

執行環境:     CentOS 7.6     FreeSWICH 1.6.18   一、問題場景:     FreeSWITCH收到REFER命令後,重新發起的INVITE訊息中的 "User-to-User" 訊息頭資訊不對,跟REFER命令的 "Refer-To" 訊息頭中的User-to-User引數值不同。     具體報文情況如下(省略了部分SIP資訊):
REFER sip:[email protected]:5080 SIP/2.0
Via: SIP/2.0/UDP 10.2.32.116:5080;rport;branch=z9hG4bKryvUZZerH16DN
From: <sip:[email protected]:5080>;tag=XH27mSc4ZyjaF
To: "Extension 296898" <sip:[email protected]>;tag=6g430SNK5Be3m
Call-ID: 46eda73c-76b2-1239-e1b5-487b6b8ad630
Contact: <sip:[email protected]:5080;transport=udp>
Refer-To: <sip:[email protected]?User-to-User=00C82b264F7267416E693D3131313337303035303030303139393433333634264F7267446E69733D333030393637%3Bencoding%3Dhex>
Referred-By: <sip:10.2.32.116:5080>
User-to-User: 00C8426613D31%3Bencoding%3Dhex


INVITE sip:[email protected]:50078;rinstance=b4e528536c8c5a3d SIP/2.0
Via: SIP/2.0/UDP 10.2.32.90;rport;branch=z9hG4bKtK4yS4SH849vD
Route: <sip:[email protected]:50078>;rinstance=b4e528536c8c5a3d
From: "Extension 296898" <sip:[email protected]>;tag=ymDeQZt2ZcK1B
To: <sip:[email protected]:50078;rinstance=b4e528536c8c5a3d>
Call-ID: 4992bbb6-76b2-1239-e1b5-487b6b8ad630
Contact: <sip:[email protected]:5060>
Referred-By: <sip:10.2.32.116:5080>
User-to-User: 00C8426613D31%3Bencoding%3Dhex
Remote-Party-ID: "Extension 296898" <sip:[email protected]>;party=calling;screen=yes;privacy=off

 

二、問題原因:     FreeSWICH預設情況下,處理REFER命令進行盲轉時,新發起的INVITE訊息中的 "User-to-User" 是從REFER的 "User-to-User" 頭中獲取的,而非"Refer-to"裡的引數       FS處理Refer命令的邏輯:
  • 信令互動邏輯
             
  • 信令處理邏輯
    • REFER的SIP訊息頭"Refer-To"中的資訊,只提取盲轉的被叫號碼,忽略其他引數(如User-to-User),然後發起新的INVITE
    • 新的INVITE訊息中的“User-to-User”頭,是根據REFER命令中的“User-to-User”頭獲取,非“Refer-To”裡的引數值

 

三、解決方案     FreeSWITCH 收到 REFER 後,取出sip_refer_to頭中的值,執行export nolocal 命令,將值設定到未來bridge的B-leg通道上即可。     增加下面撥號方案即可:
  <extension name="refer request" continue="true">
    <condition field="${sip_refer_to}" expression=".+User-to-User=(.+)%3B">
       <action application="log" data="INFO yuxiu:change User-to-User by sip_refer_to : sip_refer-to [$1]"/>
       <action application="export" data="nolocal:sip_h_User-to-User=$1;encoding=hex"/>
    </condition>
  </extension>
    通過上面方式,如果FS收到的REFER命令的“Refer-To”頭中有User-to-User引數,就取該引數作為後續INVITE的“User-to-User”頭,否則依舊取REFER命令中的“User-to-User”頭     修改後,盲轉報文將變成下面形式:
REFER sip:[email protected]:5080 SIP/2.0
From: <sip:[email protected]:5080>;tag=XH27mSc4ZyjaF
To: "Extension 296898" <sip:[email protected]>;tag=6g430SNK5Be3m
Refer-To: <sip:[email protected]?User-to-User=00C82b264F7267416E693D3131313337303035303030303139393433333634264F7267446E69733D333030393637%3Bencoding%3Dhex>
User-to-User: 00C8426613D31%3Bencoding%3Dhex

INVITE sip:[email protected]:50078;rinstance=b4e528536c8c5a3d SIP/2.0
From: "Extension 296898" <sip:[email protected]>;tag=ymDeQZt2ZcK1B
To: <sip:[email protected]:50078;rinstance=b4e528536c8c5a3d>
User-to-User:  00C82b264F7267416E693D3131313337303035303030303139393433333634264F7267446E69733D333030393637%3Bencoding%3Dhex
Remote-Party-ID: "Extension 296898" <sip:[email protected]>;party=calling;screen=yes;privacy=off

 

四、模擬的呼叫場景:

       

 

4.1、PBX-FS機器:充當分機註冊伺服器      在PBX-FS (10.2.32.90:5060)上註冊兩個分機:296896 和 296898      然後讓296989 呼叫 449998 進行測試
  • 撥號方案詳情:default.xml 
  <!-- 處理refer訊息頭 -->
  <extension name="refer request" continue="true">
    <condition field="${sip_refer_to}" expression=".+User-to-User=(.+)%3B">
       <action application="log" data="WARNING yuxiu:change User-to-User by sip_refer_to : sip_refer-to [$1]"/>
       <action application="export" data="nolocal:sip_h_User-to-User=$1;encoding=hex"/>
    </condition>
  </extension>

  <!-- 模擬呼叫IVR -->
  <extension name="outbound-ivr">
    <condition field="destination_number" expression="^(449998)$">
      <action application="bridge" data="sofia/external/[email protected]:5080"/>
      <action application="hangup" data="Esl Server ERROR"/>
    </condition>
  </extension>

  <!-- 模擬呼叫PBX分機 -->
  <extension name="outbound-pbx">
    <condition field="destination_number" expression="^(296\d{3})$">
      <action application="bridge" data="user/${1}"/>
      <action application="hangup" data="Esl Server ERROR"/>
    </condition>
  </extension>
  4.2、IVR-FS機器:充當IVR導航伺服器     收到來電後,自動應答,然後播放一段提示音後,refer 盲轉到296896
  <extension name="outbound-test2">
    <condition field="destination_number" expression="^449998$">
      <action application="log" data="INFO  uui=${sip_h_User-to-User}"/>
      <action application="answer"/>
      <action application="playback" data="/usr/local/freeswitch/sounds/welcom_to_call_yuxiu_ivr.wav"/>
      <action application="deflect" data="sip:[email protected]?User-to-User=00C82b264F7267416E693D3131313337303035303030303139393433333634264F7267446E69733D333030393637%3Bencoding%3Dhex"/>
      <action application="log" data="WARNING refer finished"/>
      <action application="hangup" data="refer finished"/>
    </condition>
  </extension>

 

4.3、FS測試日誌

EXECUTE sofia/internal/[email protected] bridge(sofia/external_90/[email protected]:5080)

[DEBUG]  sofia.c:8544 Process REFER to [[email protected]]
[INFO] mod_dialplan_xml.c:637 Processing 296898 <296898>->296896 in context default
EXECUTE sofia/internal/[email protected] bridge(user/296896)