2022年6月7日星期二

Debian install config Freeswitch (spa3000 for gateway)

1. Installation preparation for freeswitch
a. download gpg file
TOKEN=your_token
wget --http-user=yourname --http-password=$TOKEN -O /usr/share/keyrings/signalwire-freeswitch-repo.gpg https://freeswitch.signalwire.com/repo/deb/debian-unstable/signalwire-freeswitch-repo.gpg
b. generate auth file
echo "machine freeswitch.signalwire.com login silentxo password $TOKEN" > /etc/apt/auth.conf.d/freeswitch.conf
c. generate apt list file
echo "deb [signed-by=/usr/share/keyrings/signalwire-freeswitch-repo.gpg] https://freeswitch.signalwire.com/repo/deb/debian-release/ `lsb_release -sc` main" > /etc/apt/sources.list.d/freeswitch.list
echo "deb-src [signed-by=/usr/share/keyrings/signalwire-freeswitch-repo.gpg] https://freeswitch.signalwire.com/repo/deb/debian-release/ `lsb_release -sc` main" >> /etc/apt/sources.list.d/freeswitch.list
--------------------------------------------------------------------------------------------
2.install freeswitch
apt update
apt install freeswitch-meta-all
if install complete, use the command
systemctl status freeswitch.service to view freeswitch service status 
the output info:
● freeswitch.service - freeswitch
     Loaded: loaded (/lib/systemd/system/freeswitch.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Mon 2022-06-06 21:21:50 CST; 2min 59s ago
    Process: 25942 ExecStartPre=/bin/chown -R ${USER}:${GROUP} /var/lib/freeswitch /var/log/freeswitch /etc/freeswitch /usr/sha>
        CPU: 2ms
Jun 06 21:21:50 pbx systemd[1]: Failed to start freeswitch.
Jun 06 21:21:50 pbx systemd[1]: freeswitch.service: Scheduled restart job, restart counter is at 15.
Jun 06 21:21:50 pbx systemd[1]: Stopped freeswitch.
Jun 06 21:21:50 pbx systemd[1]: freeswitch.service: Start request repeated too quickly.
Jun 06 21:21:50 pbx systemd[1]: freeswitch.service: Failed with result 'exit-code'.
Jun 06 21:21:50 pbx systemd[1]: Failed to start freeswitch.
no problem, just reboot the server!
when server reboot, use ss -tln |grep 5060
you will find port 5060 is listening and freeswitch service is running
----------------------------------------------------------------------------
note: when install complete, the configuration file are in path /etc/freeswitch
3.fs_cli not connect
when you type fs_cli command, 
[ERROR] fs_cli.c:1691 main() Error Connecting [] will appear
now watch you /etc/freeswitch/autoload_configs/event_socket.conf.xml
The original configuration was 
<param name="listen-ip" value="::"/>
now change it in
<param name="listen-ip" value="0.0.0.0"/>
now systemctl restart freeswitch.service
then type fs_cli you will into the fs_cli interface
---------------------------------------------------------------------------
4. change the sip client login defaul password
freeswitch default config 1000-1019 extensions, you must chang the default password 1234, Otherwise the connection is very slow。
to change /etc/freeswitch/vars.xml line 15 1234 to other password
15   <X-PRE-PROCESS cmd="set" data="default_password=1234"/>
login fs_cli, press F6 to reloadxml, make the configuration take effect
----------------------------------------------------------------------------
5. now you can config your sip client to test dial eachother
path/dialplan/default.xml 
/var/log/freeswitch/freeswitch.xml.fsxml are load into memory xml file
------------------------------------------------------------------------------
6. connect linksys spa3000 to freeswitch in three way
a. pstn line not config proxy, user id and password (spa3000 connect to freeswitch) server 5080 port, it's external
spa3000 pstn line config
subscriber information
display name: you-like-name
dial plans
dial plan number: (s0<:67865558@192.168.199.99:5080>)
67865558 is my did number
192.168.199.99 is my freeswitch server ip
PSTN-To-VoIP Gateway Setup
PSTN Caller Default DP: same as the up dial plan number
freeswitch config
/etc/freeswitch/dialplan/public/00_inbound_did.xml
<include>
  <extension name="public_did">
    <condition field="destination_number" expression="^(67865558)$">
           <action application="set" data="domain_name=$${domain}"/>
           <action application="transfer" data="1001 XML default"/>
    </condition>
  </extension>
</include>

when you call the pstn to spa3000, the 1001 entention will ring and you can answer
the call, the pstn cid number is correct. but after 32 second , the session will interrupt.
those info by ngrep catched

U 192.168.199.99:5080 -> 192.168.199.21:5061 #4
SIP/2.0 200 OK.
Via: SIP/2.0/UDP 192.168.199.21:5061;branch=z9hG4bK-a3cf63ca.
From: sp3000-1 <sip:18580621902@192.168.199.21>;tag=71d39ddefecc07f3o1.
To: <sip:67865558@192.168.199.99:5080>;tag=4Qj5rZHF60UmF.
Call-ID: 5b20687a-e8665e07@192.168.199.21.
CSeq: 101 INVITE.
Contact: <sip:67865558@14.107.72.100:5080;transport=udp>.
User-Agent: FreeSWITCH-mod_sofia/1.10.7-release-19-883d2cb662~64bit.
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY.
Supported: timer, path, replaces.
Allow-Events: talk, hold, conference, refer.
Content-Type: application/sdp.
Content-Disposition: session.
Content-Length: 224.
Remote-Party-ID: "Outbound Call" <sip:1001@192.168.199.99>;party=calling;privacy=off;screen=no.

because the freeswitch send 200 ok to spa3000, but spa3000 not return ack info.
the contact: sip:67865558@14.107.72.100:5080 14.107.72.100 is my external ip, this is not correct. 

use sofia status in fs_cli, you will find that:
internal profile is sip:mod_sofia@14.107.72.100:5060
external profile is sip:mod_sofia@14.107.72.100:5080

edit /etc/freeswitch/vars.xml
<X-PRE-PROCESS cmd="stun-set" data="external_rtp_ip=stun:stun.freeswitch.org"/>
<X-PRE-PROCESS cmd="stun-set" data="external_sip_ip=stun:stun.freeswitch.org"/>
changed into
<X-PRE-PROCESS cmd="set" data="external_rtp_ip=192.168.199.99"/>
<X-PRE-PROCESS cmd="set" data="external_sip_ip=192.168.199.99"/>

systemctl restart freeswitch.service
use sofia status in fs_cli, you will find that:
external  profile is sip:mod_sofia@192.168.199.99:5080

and ngrep info are:
U 192.168.199.99:5080 -> 192.168.199.21:5061 #4
SIP/2.0 200 OK.
Via: SIP/2.0/UDP 192.168.199.21:5061;branch=z9hG4bK-b20f123a.
From: sp3000-1 <sip:18580621902@192.168.199.21>;tag=86bf70199215a3e2o1.
To: <sip:67865558@192.168.199.99:5080>;tag=ZeZaNag0vXHFD.
Call-ID: 1daf41a5-e8d71fc6@192.168.199.21.
CSeq: 101 INVITE.
Contact: <sip:67865558@192.168.199.99:5080;transport=udp>.
User-Agent: FreeSWITCH-mod_sofia/1.10.7-release-19-883d2cb662~64bit.
Allow: INVITE, ACK, BYE, CANCEL, OPTIONS, MESSAGE, INFO, UPDATE, REGISTER, REFER, NOTIFY.
Supported: timer, path, replaces.
Allow-Events: talk, hold, conference, refer.
Content-Type: application/sdp.
Content-Disposition: session.
Content-Length: 224.
Remote-Party-ID: "Outbound Call" <sip:1001@192.168.199.99>;party=calling;privacy=off;screen=no.

U 192.168.199.21:5061 -> 192.168.199.99:5080 #5
ACK sip:67865558@192.168.199.99:5080;transport=udp SIP/2.0.
Via: SIP/2.0/UDP 192.168.199.21:5061;branch=z9hG4bK-d659015f.
From: sp3000-1 <sip:18580621902@192.168.199.21>;tag=86bf70199215a3e2o1.
To: <sip:67865558@192.168.199.99:5080>;tag=ZeZaNag0vXHFD.
Call-ID: 1daf41a5-e8d71fc6@192.168.199.21.
CSeq: 101 ACK.
Max-Forwards: 70.
Contact: sp3000-1 <sip:18580621902@192.168.199.21:5061>.
User-Agent: Linksys/SPA3000-3.1.10(GWd).
Content-Length: 0.

So, problem solved.
from freeswitch dial out to spa3000
no config for spa3000
in freeswitch side
generate a file named /etc/freeswitch/dialplan/default/00_pstn5558.xml
<include>
  <extension name="To_67865558">
    <condition field="destination_number" expression="^0(.*)$">
      <action application="bridge" data="sofia/external/$1@192.168.199.21:5061"/>
    </condition>
  </extension>
</include>
after that relaos the config
that's ok
b. pstn line config proxy, user id and password
Proxy and Registration
Proxy:192.168.199.99
Subscriber Information
Display Name:you-like-name
User ID:1000
Password:same as the extenson 1000
Auth ID:1000
Dial Plan number:(S0<:67855878>)
PSTN-To-VoIP Gateway Setup
PSTN Caller Default DP:same as the up dial plan numbe

edit /dialplan/default.xml add green line, when comming a call, 1001 extension will ring.

<context name="default">

    <extension name="unloop">
      <condition field="${unroll_loops}" expression="^true$"/>
      <condition field="${sip_looped_call}" expression="^true$">
        <action application="deflect" data="${destination_number}"/>
      </condition>
    </extension>

    <extension name="did_67855878">
      <condition field="destination_number" expression="^67855878$">
       <action application="transfer" data="1001 XML default"/>
      </condition>
    </extension>
now the incomming call can ring on 1001 extension
when ring the cid is 1000, if you want to the cid correct, you must edit /etc/freeswitch/directory/default/1000.xml, comment out these lines.
<!-- variable name="effective_caller_id_name" value="Extension 1000"/ -->
<!-- variable name="effective_caller_id_number" value="1000"/ -->
about after 32 second , the session will interrupt, you must comment out /etc/freeswitch/sip_profiles/internal.xml those lines
 <!-- param name="ext-rtp-ip" value="$${external_rtp_ip}"/ -->
 <!-- param name="ext-sip-ip" value="$${external_sip_ip}"/ -->
from freeswitch dial out to spa3000
see the above example config
c. same config as above and change the dial plan to Dial Plan number: (<:1001>S0),when call comming,the spa3000 call 1001 ectension
--------------------------------------------------------------------------------
two line inbound
/etc/freeswitch/dialplan/public/00_inbound_did.xml 
<include>
  <extension name="public_did">
    <condition field="destination_number" expression="^67865558|67855878$">
       <action application="set" data="domain_name=$${domain}"/>
       <action application="transfer" data="1001 XML default"/> #ring 1001
         <action application="bridge" data="${group_call(sales@${domain_name})}"/>#ring group 2000 sales
    </condition>
  </extension>
</include>

two line outbound
/etc/freeswitch/dialplan/default/00_pstn.xml 
<include>
  <extension name="To_pstn">
    <condition field="destination_number" expression="^0(.*)$">
      <action application="bridge" data="sofia/external/$1@192.168.199.21:5061|sofia/external/$1@192.168.199.22:5061"/>
    </condition>
  </extension>
</include>

















path=/etc/freeswitch

.




没有评论: