PJSIP isn't following 302 response

Hello, currently we use Asterisk with SIP and I’m trying to set up an Asterisk 18 server using PJSIP and realtime configuration.

The realtime configuration is progressing (got phoneprov working today), but I’m having trouble to interact with one of our OpenSIPS servers. When the OpenSIPS server receives an INVITE, it checks the number and, if it’s available on any of our servers, it will send a 302 with the Contact header with the correct server and the number in the correct format to Dial.

Unfortunately, PJSIP isn’t following the Contact sent in the 302 and the call fails.

Comparing to a successful call using SIP, the difference I found are the two notices. I don’t understand why it’s being set to Local/32142@default. With SIP, it would be something like SIP/32142::::UDP@172.16.0.3:5060.

It seems that what I want on PJSIP is what promiscredir is on SIP. How do I configure PJSIP to follow the 302 as SIP did? And if this isn’t possible, what is the approach to deal with 302 using PJSIP?

In the PJSIP log, 172.16.0.3:5063 is the OpenSIPS server that sends the 302, 172.16.0.3:5060 is the Asterisk server which has the phone number on this case, 172.16.21.1 is the Asterisk test server and 172.16.21.133 is an IP phone.

PJSIP Logging enabled
<--- Received SIP request (1343 bytes) from UDP:172.16.21.133:5062 --->
INVITE sip:0385432142@dev-301.internal SIP/2.0
Via: SIP/2.0/UDP 172.16.21.133:5062;branch=z9hG4bK472351992
From: "1002" <sip:1002@dev-301.internal>;tag=972451302
To: <sip:0385432142@dev-301.internal>
Call-ID: 62290256@172.16.21.133
CSeq: 1 INVITE
Contact: <sip:1002@172.16.21.133:5062>
Content-Type: application/sdp
Allow: INVITE, INFO, PRACK, ACK, BYE, CANCEL, OPTIONS, NOTIFY, REGISTER, SUBSCRIBE, REFER, PUBLISH, UPDATE, MESSAGE
Max-Forwards: 70
User-Agent: VP530P 23.70.0.40
Supported: replaces,100rel
Allow-Events: talk,hold,conference,refer
Content-Length: 720

v=0
o=- 20143 20143 IN IP4 172.16.21.133
s=SDP data
c=IN IP4 172.16.21.133
b=AS:1024
t=0 0
m=audio 11780 RTP/AVP 0 18 8 9 101
b=AS:1024
a=rtpmap:0 PCMU/8000
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=rtpmap:8 PCMA/8000
a=rtpmap:9 G722/8000
a=fmtp:101 0-15
a=rtpmap:101 telephone-event/8000
a=ptime:20
a=sendrecv
m=video 11782 RTP/AVP 99 34 102
b=AS:1024
a=rtpmap:99 H264/90000
a=fmtp:99 profile-level-id=42800D; packetization-mode=0; max-mbps=11880; MaxBR=10240
a=rtpmap:34 H263/90000
a=fmtp:34 profile-level-id=42800D; packetization-mode=0; max-mbps=11880; MaxBR=10240
a=rtpmap:102 mp4v-es/90000
a=fmtp:102 profile-level-id=42800D; packetization-mode=0; max-mbps=11880 MaxBR=10240
a=sendrecv

<--- Transmitting SIP response (510 bytes) to UDP:172.16.21.133:5062 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 172.16.21.133:5062;rport=5062;received=172.16.21.133;branch=z9hG4bK472351992
Call-ID: 62290256@172.16.21.133
From: "1002" <sip:1002@dev-301.internal>;tag=972451302
To: <sip:0385432142@dev-301.internal>;tag=z9hG4bK472351992
CSeq: 1 INVITE
WWW-Authenticate: Digest realm="asterisk",nonce="166501/08bfab81bb698a0ac6b5af4cf85",opaque="0e21f7cf",algorithm=md5,qop="auth"
Server: Asterisk PBX 18.4.0
Content-Length:  0


<--- Received SIP request (329 bytes) from UDP:172.16.21.133:5062 --->
ACK sip:0385432142@dev-301.internal SIP/2.0
Via: SIP/2.0/UDP 172.16.21.133:5062;branch=z9hG4bK472351992
From: "1002" <sip:1002@dev-301.internal>;tag=972451302
To: <sip:0385432142@dev-301.internal>;tag=z9hG4bK472351992
Call-ID: 62290256@172.16.21.133
CSeq: 1 ACK
Content-Length: 0


<--- Received SIP request (1634 bytes) from UDP:172.16.21.133:5062 --->
INVITE sip:0385432142@dev-301.internal SIP/2.0
Via: SIP/2.0/UDP 172.16.21.133:5062;branch=z9hG4bK630027285
From: "1002" <sip:1002@dev-301.internal>;tag=972451302
To: <sip:0385432142@dev-301.internal>
Call-ID: 62290256@172.16.21.133
CSeq: 2 INVITE
Contact: <sip:1002@172.16.21.133:5062>
Authorization: Digest username="1002", realm="asterisk", nonce="166751/08bfab8d7501bb0ac6b5af4cf85", uri="sip:0385432142@dev-301.internal", response="0de334fb82e84b309d09dd05076f", algorithm=MD5, cnonce="0a4f13b", opaque="0be487cf", qop=auth, nc=00000001
Content-Type: application/sdp
Allow: INVITE, INFO, PRACK, ACK, BYE, CANCEL, OPTIONS, NOTIFY, REGISTER, SUBSCRIBE, REFER, PUBLISH, UPDATE, MESSAGE
Max-Forwards: 70
User-Agent: VP530P 23.70.0.40
Supported: replaces,100rel
Allow-Events: talk,hold,conference,refer
Content-Length: 720

v=0
o=- 20143 20143 IN IP4 172.16.21.133
s=SDP data
c=IN IP4 172.16.21.133
b=AS:1024
t=0 0
m=audio 11780 RTP/AVP 0 18 8 9 101
b=AS:1024
a=rtpmap:0 PCMU/8000
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=rtpmap:8 PCMA/8000
a=rtpmap:9 G722/8000
a=fmtp:101 0-15
a=rtpmap:101 telephone-event/8000
a=ptime:20
a=sendrecv
m=video 11782 RTP/AVP 99 34 102
b=AS:1024
a=rtpmap:99 H264/90000
a=fmtp:99 profile-level-id=42800D; packetization-mode=0; max-mbps=11880; MaxBR=10240
a=rtpmap:34 H263/90000
a=fmtp:34 profile-level-id=42800D; packetization-mode=0; max-mbps=11880; MaxBR=10240
a=rtpmap:102 mp4v-es/90000
a=fmtp:102 profile-level-id=42800D; packetization-mode=0; max-mbps=11880 MaxBR=10240
a=sendrecv

<--- Transmitting SIP response (337 bytes) to UDP:172.16.21.133:5062 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 172.16.21.133:5062;rport=5062;received=172.16.21.133;branch=z9hG4bK630027285
Call-ID: 62290256@172.16.21.133
From: "1002" <sip:1002@dev-301.internal>;tag=972451302
To: <sip:0385432142@dev-301.internal>
CSeq: 2 INVITE
Server: Asterisk PBX 18.4.0
Content-Length:  0


<--- Transmitting SIP request (1042 bytes) to UDP:172.16.0.3:5063 --->
INVITE sip:+156385432142@172.16.0.3:5063 SIP/2.0
Via: SIP/2.0/UDP 172.16.21.1:5060;rport;branch=z9hG4bKPja87a3993-d571-482e-811d-67ebcdc09215
From: "1002" <sip:1002@dev-301.internal>;tag=50cd1470-b42c-4ca0-8751-a74fb7d900eb
To: <sip:+156385432142@172.16.0.3>
Contact: <sip:asterisk@172.16.21.1:5060>
Call-ID: 695616d9-4372-480c-8e3c-26f9b93b13b4
CSeq: 11989 INVITE
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER
Supported: 100rel, timer, replaces, norefersub, histinfo
Session-Expires: 1800
Min-SE: 90
X-Orig-URI: 1002@172.16.0.3:5060
Max-Forwards: 70
User-Agent: Asterisk PBX 18.4.0
Content-Type: application/sdp
Content-Length:   306

v=0
o=- 648839767 648839767 IN IP4 172.16.21.1
s=Asterisk
c=IN IP4 172.16.21.1
t=0 0
m=audio 11884 RTP/AVP 9 8 0 3 101
a=rtpmap:9 G722/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:3 GSM/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:150
a=sendrecv

<--- Received SIP response (496 bytes) from UDP:172.16.0.3:5063 --->
SIP/2.0 302 Moved Temporarily
Via: SIP/2.0/UDP 172.16.21.1:5060;received=172.16.21.1;rport=5060;branch=z9hG4bKPja87a3993-d571-482e-811d-67ebcdc09215
From: "1002" <sip:1002@dev-301.internal>;tag=50cd1470-b42c-4ca0-8751-a74fb7d900eb
To: <sip:+156385432142@172.16.0.3>;tag=6caf44c6847be57cb93883f0ab66ee1c.fea5
Call-ID: 695616d9-4372-480c-8e3c-26f9b93b13b4
CSeq: 11989 INVITE
Contact: <sip:32142@172.16.0.3:5060>
Server: OpenSIPS ((x86_64/linux))
Content-Length: 0


<--- Transmitting SIP request (456 bytes) to UDP:172.16.0.3:5063 --->
ACK sip:+156385432142@172.16.0.3:5063 SIP/2.0
Via: SIP/2.0/UDP 172.16.21.1:5060;rport;branch=z9hG4bKPja87a3993-d571-482e-811d-67ebcdc09215
From: "1002" <sip:1002@dev-301.internal>;tag=50cd1470-b42c-4ca0-8751-a74fb7d900eb
To: <sip:+156385432142@172.16.0.3>;tag=6caf44c6847be57cb93883f0ab66ee1c.fea5
Call-ID: 695616d9-4372-480c-8e3c-26f9b93b13b4
CSeq: 11989 ACK
Max-Forwards: 70
User-Agent: Asterisk PBX 18.4.0
Content-Length:  0


[Aug 31 15:45:01] NOTICE[289851][C-00000005]: core_local.c:739 local_call: No such extension/context 32142@default while calling Local channel
[Aug 31 15:45:01] NOTICE[289851][C-00000005]: app_dial.c:1113 do_forward: Forwarding failed to dial 'Local/32142@default'
<--- Transmitting SIP response (630 bytes) to UDP:172.16.21.133:5062 --->
SIP/2.0 181 Call Is Being Forwarded
Via: SIP/2.0/UDP 172.16.21.133:5062;rport=5062;received=172.16.21.133;branch=z9hG4bK630027285
Call-ID: 62290256@172.16.21.133
From: "1002" <sip:1002@dev-301.internal>;tag=972451302
To: <sip:0385432142@dev-301.internal>;tag=84960fe7-b83a-4d48-aa76-66638eefe9bd
CSeq: 2 INVITE
Server: Asterisk PBX 18.4.0
Contact: <sip:172.16.21.1:5060>
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER
Supported: histinfo
Diversion: <sip:32142@dev-301.internal>;reason=unknown
Content-Length:  0


<--- Transmitting SIP response (604 bytes) to UDP:172.16.21.133:5062 --->
SIP/2.0 603 Decline
Via: SIP/2.0/UDP 172.16.21.133:5062;rport=5062;received=172.16.21.133;branch=z9hG4bK630027285
Call-ID: 62290256@172.16.21.133
From: "1002" <sip:1002@dev-301.internal>;tag=972451302
To: <sip:0385432142@dev-301.internal>;tag=84960fe7-b83a-4d48-aa76-66638eefe9bd
CSeq: 2 INVITE
Server: Asterisk PBX 18.4.0
Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER
Supported: histinfo
Diversion: <sip:32142@dev-301.internal>;reason=unknown
Reason: Q.850;cause=16
Content-Length:  0


<--- Received SIP request (349 bytes) from UDP:172.16.21.133:5062 --->
ACK sip:0385432142@dev-301.internal SIP/2.0
Via: SIP/2.0/UDP 172.16.21.133:5062;branch=z9hG4bK630027285
From: "1002" <sip:1002@dev-301.internal>;tag=972451302
To: <sip:0385432142@dev-301.internal>;tag=84960fe7-b83a-4d48-aa76-66638eefe9bd
Call-ID: 62290256@172.16.21.133
CSeq: 2 ACK
Content-Length: 0
; extensions.conf
[test0002]
exten => addX,1,Set(PJSIP_HEADER(add,X-Origin-URI)=${ARG1}@172.16.0.3:5060)
 same => n,Return()

exten => _0ZXXXXXXXX,1,NoOp()
 same => n,Dial(PJSIP/+156${EXTEN:1}@OSIPS,60,b(addX^1(${CALLERID(num)})))
 same => n,HangUp()
; pjsip.conf
[OSIPS]
type=endpoint
allow=!all,g722,alaw,ulaw,gsm
aors=OSIPS
from_domain=dev-301.internal

[OSIPS]
type=aor
contact=sip:172.16.0.3:5063
qualify_frequency=60

That is configured using the redirect_method option[1].

[1] https://wiki.asterisk.org/wiki/display/AST/Asterisk+20+Configuration_res_pjsip#Asterisk20Configuration_res_pjsip-endpoint_redirect_method

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