PJSIP - no incoming calls.... outgoing call OK

Hello

I have a FreePBX 16 installed on my home server with Matrix FXO-FXS gateway (for converting CO lines to SIP trunks)

My setup

FreePBX - 192.168.1.81
Matrix Gateway -192.168.1.240 - connected to FreePBX using Peer-to-Peer trunk
Pfsense+ firewall with NAT and firewall rules
Dynamic public IP allocation by ISP - attached to DDNS domain by pfsense.
softphone - GSwave Lite on android and on iOS

I have been trying to switch matrix gateway from chan to pjsip… i am able to make outgoing calls on the pjsip but incoming calls are not getting anywhere.
in my chan_sip setup, all incomings calls are getting diverted to IVR and it works fine.

Any help is appreciated…

Incoming call sngrep Trace


2024/11/01 14:28:27.185643 192.168.1.240:5060 -> 192.168.1.81:5060

INVITE sip:[email protected] SIP/2.0

From: <sip:[email protected]>;tag=6bddf0-f001a8c0-13c4-672497d6-29c1790d-672497d6

To: <sip:[email protected]>

Call-ID: 6c2968-f001a8c0-13c4-672497d6-4073ab77-672497d6

CSeq: 1 INVITE

Via: SIP/2.0/UDP 192.168.1.240:5060;rport;branch=z9hG4bK-672497d6-e6f11c4e-6916e712

Max-Forwards: 70

Supported: replaces

User-Agent: Matrix-SETUVGFXNG

Contact: <sip:192.168.1.240:5060;transport=udp>

Allow: INVITE,BYE,ACK,CANCEL,REFER,NOTIFY,OPTIONS

Content-Type: application/sdp

Content-Length: 464

v=0

o=- 1323421410 1323421410 IN IP4 192.168.1.240

s=Matrix-SETUVGFXNG

c=IN IP4 192.168.1.240

t=0 0

m=audio 8062 RTP/AVP 18 4 3 100 99 0 8 101

a=rtpmap:18 G729/8000

a=fmtp:18 annexb=no

a=rtpmap:4 G723/8000

OUTGOING CALL sngrep trace


2024/11/01 14:27:48.275293 192.168.1.90:57587 -> 192.168.1.81:5160

INVITE sip:[email protected]:5160 SIP/2.0

Via: SIP/2.0/UDP 192.168.1.90:57587;rport;branch=z9hG4bKPjz8-9Wfrb0Gtz1lUOG0vTkeoG6Hap8AVM

Max-Forwards: 70

From: "Puneet Maheshwari" <sip:[email protected]>;tag=Iiqxrz6593M0Nnjn99nRp5BgYi71NFXf

To: sip:[email protected]

Contact: "Puneet Maheshwari" <sip:[email protected]:57587;ob>

Call-ID: VZR7mdI6Mb0iBI668qcHePM1vimwSY7X

CSeq: 9315 INVITE

Allow: PRACK, INVITE, ACK, BYE, CANCEL, UPDATE, INFO, SUBSCRIBE, NOTIFY, REFER, MESSAGE, OPTIONS

Supported: replaces, 100rel, norefersub

User-Agent: Telephone 1.6

Content-Type: application/sdp

Content-Length: 476

v=0

o=- 3939440268 3939440268 IN IP4 192.168.1.90

s=pjmedia

b=AS:117

t=0 0

a=X-nat:0

m=audio 4000 RTP/AVP 96 9 8 0 101 102

c=IN IP4 192.168.1.90

b=TIAS:96000

a=rtcp:4001 IN IP4 192.168.1.90

a=sendrecv

a=rtpmap:96 opus/48000/2

a=fmtp:96 useinbandfec=1

a=rtpmap:9 G722/8000

a=rtpmap:8 PCMA/8000

a=rtpmap:0 PCMU/8000

a=rtpmap:101 telephone-event/48000

a=fmtp:101 0-16

a=rtpmap:102 telephone-event/8000

a=fmtp:102 0-16

a=ssrc:402538590 cname:795399525f7714b8


2024/11/01 14:27:48.801700 192.168.1.81:5160 -> 192.168.1.240:5060

INVITE sip:[email protected]:5060 SIP/2.0

Via: SIP/2.0/UDP 192.168.1.81:5160;rport;branch=z9hG4bKPj0dc7afa1-d24a-4f1d-92f4-3a72a8ab4fe7

From: "Puneet_Devices" <sip:[email protected]>;tag=9e95ee78-2b9b-4963-9ad4-582b50350f82

To: <sip:[email protected]>

Contact: <sip:[email protected]:5160>

Call-ID: fee5865d-9917-4c5c-bb3e-43c3abf380d4

CSeq: 11545 INVITE

Allow: OPTIONS, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, MESSAGE, REFER

Supported: 100rel, timer, replaces, norefersub, histinfo

Session-Expires: 1800

Min-SE: 90

Max-Forwards: 70

User-Agent: FPBX-16.0.40.8(18.20.2)

Content-Type: application/sdp

Content-Length: 498

v=0

o=- 1247773936 1247773936 IN IP4 192.168.1.81

s=Asterisk

c=IN IP4 192.168.1.81

t=0 0

m=audio 11962 RTP/AVP 0 8 9 3 111 4 110 117 119 18 101

a=rtpmap:0 PCMU/8000

a=rtpmap:8 PCMA/8000

a=rtpmap:9 G722/8000

a=rtpmap:3 GSM/8000

a=rtpmap:111 G726-32/8000

a=rtpmap:4 G723/8000

a=rtpmap:110 speex/8000

a=rtpmap:117 speex/16000

a=rtpmap:119 speex/32000

a=rtpmap:18 G729/8000

a=fmtp:18 annexb=no

a=rtpmap:101 telephone-event/8000

a=fmtp:101 0-16

a=ptime:20

a=maxptime:60

a=sendrecv

By default, FreePBX 16 has pjsip (UDP transport) binding to port 5060 (in Asterisk SIP Settings, this is called Port to Listen On) and chan_sip Bind Port set to 5160. Possibly, you changed these.

On your working outgoing call, Asterisk is sending from port 5160, but on the failing incoming call, Matrix is sending to port 5060, so it’s attempting to use the opposite driver.

If you are using the default port settings, it appears that outbound is using a chan_sip trunk and the pjsip trunk (if it exists) is not being used at all.

If you switched the port settings, then outbound is fine and you need to change a setting in the Matrix to send inbound calls to port 5160, where you now have pjsip listening.

As per the freepbx settings
chan_sip is on port 5060
chan_pjsip is on port 5160

sngrep trace of incoming call in chan_sip (pjsip also enabled)

2024/11/04 10:55:22.392407 192.168.1.240:5060 -> 192.168.1.81:5060
INVITE sip:[email protected] SIP/2.0
From: "PSTN"<sip:[email protected]>;tag=6ba6e8-f001a8c0-13c4-67285aa7-744dceeb-67285aa7
To: <sip:[email protected]>
Call-ID: 6c2960-f001a8c0-13c4-67285aa7-52f8967d-67285aa7
CSeq: 1 INVITE
Via: SIP/2.0/UDP 192.168.1.240:5060;rport;branch=z9hG4bK-67285aa7-f5a21f37-fd1f361
Max-Forwards: 70
Supported: replaces
User-Agent: Matrix-SETUVGFXNG
Contact: <sip:192.168.1.240:5060;transport=udp>
Allow: INVITE,BYE,ACK,CANCEL,REFER,NOTIFY,OPTIONS
Content-Type: application/sdp
Content-Length: 464

v=0
o=- 3951848288 3951848288 IN IP4 192.168.1.240
s=Matrix-SETUVGFXNG
c=IN IP4 192.168.1.240
t=0 0
m=audio 8034 RTP/AVP 18 4 3 100 99 0 8 101
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=rtpmap:4 G723/8000
a=rtpmap:3 GSM/8000
a=rtpmap:100 iLBC/8000
a=fmtp:100 mode=30
a=rtpmap:99 iLBC/8000
a=fmtp:99 mode=20
a=rtpmap:0 PCMU/8000
2024/11/04 10:56:03.988462 192.168.1.81:5160 -> 192.168.1.240:5060
INVITE sip:[email protected]:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.1.81:5160;rport;branch=z9hG4bKPj3ef320c0-cb35-4354-81de-ca08dfca4568
From: "PSTN" <sip:[email protected]>;tag=3b2d609d-62d4-422e-b7cd-fff273d78999
To: <sip:[email protected]>
Contact: <sip:[email protected]:5160>
Call-ID: b8eeb7ec-0169-49f3-8089-7c3d1039e757
CSeq: 14592 INVITE
Allow: OPTIONS, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, MESSAGE, REFER
Supported: 100rel, timer, replaces, norefersub, histinfo
Session-Expires: 1800
Min-SE: 90
Max-Forwards: 70
User-Agent: FPBX-16.0.40.8(18.20.2)
Content-Type: application/sdp
Content-Length:   496

v=0
o=- 992087513 992087513 IN IP4 192.168.1.81
s=Asterisk
c=IN IP4 192.168.1.81
t=0 0
m=audio 16014 RTP/AVP 3 0 8 111 9 4 110 117 119 18 101
a=rtpmap:3 GSM/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:111 G726-32/8000
a=rtpmap:9 G722/8000
a=rtpmap:4 G723/8000
a=rtpmap:110 speex/8000
a=rtpmap:117 speex/16000
a=rtpmap:119 speex/32000
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:60
a=sendrecv

Call is going to chan_sip.

Via: SIP/2.0/UDP 192.168.1.81:5160;rport;branch=z9hG4bKPj3ef320c0-cb35-4354-81de-ca08dfca4568

why is this stating port 5160? (in last trace)

Because the outgoing call is using PJSIP, which is port 5160, and thus that goes in the Via header.

changed port of pjsip to 5060 and chan_sip to 5061
disabled chan_sip trunk…

still incoming call is not getting diverted to extension 989…

2024/11/04 18:17:12.486452 192.168.1.240:5060 -> 192.168.1.81:5060
INVITE sip:[email protected] SIP/2.0
From: "PSTN"<sip:[email protected]>;tag=6b7da8-f001a8c0-13c4-6728c237-d14b02e-6728c237
To: <sip:[email protected]>
Call-ID: 6c3ae8-f001a8c0-13c4-6728c237-70ca0288-6728c237
CSeq: 1 INVITE
Via: SIP/2.0/UDP 192.168.1.240:5060;rport;branch=z9hG4bK-6728c237-f736aab0-12d76e1f
Max-Forwards: 70
Supported: replaces
User-Agent: Matrix-SETUVGFXNG
Contact: <sip:192.168.1.240:5060;transport=udp>
Allow: INVITE,BYE,ACK,CANCEL,REFER,NOTIFY,OPTIONS
Content-Type: application/sdp
Content-Length: 464

v=0
o=- 2728508799 2728508799 IN IP4 192.168.1.240
s=Matrix-SETUVGFXNG
c=IN IP4 192.168.1.240
t=0 0
m=audio 8056 RTP/AVP 18 4 3 100 99 0 8 101
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=rtpmap:4 G723/8000
a=rtpmap:3 GSM/8000
a=rtpmap:100 iLBC/8000
a=fmtp:100 mode=30
a=rtpmap:99 iLBC/8000
a=fmtp:99 mode=20
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=rtcp:8057 IN IP4 192.168.1.240
a=sendrecv

so i found my mistake…
had to restart the asterisk and not just reload…

now have a new error

trace from asterisk CLI

[2024-11-04 18:32:31] NOTICE[7851]: res_pjsip_session.c:4027 new_invite:  matrix_pjsip: Call (UDP:192.168.1.240:5060) to extension '989' rejected because extension not found in context 'from-external'.

sngrep trace

2024/11/04 18:34:57.762070 192.168.1.240:5060 -> 192.168.1.81:5060
INVITE sip:[email protected] SIP/2.0
From: <sip:[email protected]>;tag=6ba428-f001a8c0-13c4-6728c66e-3b1e6c2f-6728c66e
To: <sip:[email protected]>
Call-ID: 6c4610-f001a8c0-13c4-6728c66e-633e5079-6728c66e
CSeq: 1 INVITE
Via: SIP/2.0/UDP 192.168.1.240:5060;rport;branch=z9hG4bK-6728c66e-f747205b-4e0ac88c
Max-Forwards: 70
Supported: replaces
User-Agent: Matrix-SETUVGFXNG
Contact: <sip:192.168.1.240:5060;transport=udp>
Allow: INVITE,BYE,ACK,CANCEL,REFER,NOTIFY,OPTIONS
Content-Type: application/sdp
Content-Length: 464

v=0
o=- 1869743115 1869743115 IN IP4 192.168.1.240
s=Matrix-SETUVGFXNG
c=IN IP4 192.168.1.240
t=0 0
m=audio 8002 RTP/AVP 18 4 3 100 99 0 8 101
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=rtpmap:4 G723/8000
a=rtpmap:3 GSM/8000
a=rtpmap:100 iLBC/8000
a=fmtp:100 mode=30
a=rtpmap:99 iLBC/8000
a=fmtp:99 mode=20
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=rtcp:8003 IN IP4 192.168.1.240
a=sendrecv

2024/11/04 18:34:57.763833 192.168.1.81:5060 -> 192.168.1.240:5060
SIP/2.0 404 Not Found
Via: SIP/2.0/UDP 192.168.1.240:5060;rport=5060;received=192.168.1.240;branch=z9hG4bK-6728c66e-f747205b-4e0ac88c
Call-ID: 6c4610-f001a8c0-13c4-6728c66e-633e5079-6728c66e
From: <sip:[email protected]>;tag=6ba428-f001a8c0-13c4-6728c66e-3b1e6c2f-6728c66e
To: <sip:[email protected]>;tag=6312f547-9366-458a-a103-bed46d733ead
CSeq: 1 INVITE
Server: FPBX-16.0.40.8(18.20.2)
Content-Length:  0


2024/11/04 18:34:57.779409 192.168.1.240:5060 -> 192.168.1.81:5060
ACK sip:[email protected] SIP/2.0
From: <sip:[email protected]>;tag=6ba428-f001a8c0-13c4-6728c66e-3b1e6c2f-6728c66e
To: <sip:[email protected]>;tag=6312f547-9366-458a-a103-bed46d733ead
Call-ID: 6c4610-f001a8c0-13c4-6728c66e-633e5079-6728c66e
CSeq: 1 ACK
Via: SIP/2.0/UDP 192.168.1.240:5060;rport;branch=z9hG4bK-6728c66e-f747205b-4e0ac88c
Max-Forwards: 70
User-Agent: Matrix-SETUVGFXNG
Contact: <sip:192.168.1.240:5060;transport=udp>
Allow: INVITE,BYE,ACK,CANCEL,REFER,NOTIFY,OPTIONS
Content-Length: 0

new update

so i removed the context option from the pjsip settings…
i think everything is working as of now… will test for some days and post a update.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.