Asterisk 14.2.1 PJSIP – Is It Possible To Retrieve A PJSIP Header To Field For The SIP OK Response To Trying?

Home » Asterisk Users » Asterisk 14.2.1 PJSIP – Is It Possible To Retrieve A PJSIP Header To Field For The SIP OK Response To Trying?
Asterisk Users 3 Comments

I place a call into Asterisk (from SIP phone) and the To header does not have a tag. Asterisk then sends it’s Trying response, still no tag in the To header. The phone then replies with OK, this time the To header includes a tag.

Is there any way to retrieve this response To header (including the tag field) from the dial plan?
I have tried the PJSIP-HEADER read of the To header, but it seems to only have access to the initial To header. I even tried reading multiple layers of the To header, but it still didn’t retrieve the newer dialog To headers.

I am including the SIP messages reported by Asterisk for the call coming in…

*** Phone sends INVITE to Asterisk ***

INVITE sip:333@xxx.xxx.xxx.xxx SIP/2.0^M
Via: SIP/2.0/UDP yyy.yyy.yyy.yyy:5063;branch=z9hG4bK-18e552c3^M
From: “1004” ;tag=79e7940882a792ao2^M
To: ^M
Call-ID: 3162d378-ea2b2452@yyy.yyy.yyy.yyy^M
CSeq: 102 INVITE^M
Max-Forwards: 70^M
Authorization: Digest username=”1004″,realm=”asterisk”,nonce=”1485271992/b1bebde5cb4a763ed85b1d8e52c8e30d”,uri=”sip:333@xxx.xxx.xxx.xxx”,algorithm=MD5,response=”8dd827e9910c2446fb0b8497f5944b81″,opaque=”66e52\
68a2111e777″,qop=auth,nc=00000001,cnonce=”9dda9e0d”^M
Contact: “1004” ^M
Expires: 240^M
User-Agent: Cisco/SPA504G-7.4.8a^M
Content-Length: 401^M
Allow: ACK, BYE, CANCEL, INFO, INVITE, NOTIFY, OPTIONS, REFER, UPDATE^M
Supported: replaces^M
Content-Type: application/sdp^M
^M
v=0^M
o=- 32730859 32730859 IN IP4 yyy.yyy.yyy.yyy^M
s=-^M
c=IN IP4 yyy.yyy.yyy.yyy^M
t=0 0^M
m=audio 16436 RTP/AVP 0 2 8 9 18 96 97 98 101^M
a=rtpmap:0 PCMU/8000^M
a=rtpmap:2 G726-32/8000^M
a=rtpmap:8 PCMA/8000^M
a=rtpmap:9 G722/8000^M
a=rtpmap:18 G729a/8000^M
a=rtpmap:96 G726-40/8000^M
a=rtpmap:97 G726-24/8000^M
a=rtpmap:98 G726-16/8000^M
a=rtpmap:101 telephone-event/8000^M
a=fmtp:101 0-15^M
a=ptime:30^M
a=sendrecv^M

*** reply from Asterisk to phone ***

SIP/2.0 100 Trying^M
Via: SIP/2.0/UDP yyy.yyy.yyy.yyy:5063;received=yyy.yyy.yyy.yyy;branch=z9hG4bK-18e552c3^M
Call-ID: 3162d378-ea2b2452@yyy.yyy.yyy.yyy^M
From: “1004” ;tag=79e7940882a792ao2^M
To: ^M
CSeq: 102 INVITE^M
Server: Asterisk PBX 14.2.1^M
Content-Length: 0^M
^M

******
Asterisk receives this packet in response to the Trying. Is it possible to retrieve this To header via the dial plan? Specifically, I need the tag portion of the From
******

SIP/2.0 200 OK^M
Via: SIP/2.0/UDP yyy.yyy.yyy.yyy:5063;received=yyy.yyy.yyy.yyy;branch=z9hG4bK-18e552c3^M
Call-ID: 3162d378-ea2b2452@yyy.yyy.yyy.yyy^M
From: “1004” ;tag=79e7940882a792ao2^M
To: ;tag=96156bd7-9e8e-4077-b6e4-f3eb12e39069^M
CSeq: 102 INVITE^M
Server: Asterisk PBX 14.2.1^M
Contact: ^M
Allow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, MESSAGE, REFER^M
Supported: 100rel, timer, replaces, norefersub^M
Content-Type: application/sdp^M
Content-Length: 179^M
^M
v=0^M
o=- 32730859 32730861 IN IP4 xxx.xxx.xxx.xxx^M
s=Asterisk^M
c=IN IP4 xxx.xxx.xxx.xxx^M
t=0 0^M
m=audio 19384 RTP/AVP 0^M
a=rtpmap:0 PCMU/8000^M
a=ptime:20^M
a=maxptime:150^M
a=sendrecv^M

ACK sip:xxx.xxx.xxx.xxx:5060 SIP/2.0^M
Via: SIP/2.0/UDP yyy.yyy.yyy.yyy:5063;branch=z9hG4bK-c38362b^M
From: “1004” ;tag=79e7940882a792ao2^M
To: ;tag=96156bd7-9e8e-4077-b6e4-f3eb12e39069^M
Call-ID: 3162d378-ea2b2452@yyy.yyy.yyy.yyy^M
CSeq: 102 ACK^M
Max-Forwards: 70^M
Authorization: Digest username=”1004″,realm=”asterisk”,nonce=”1485271992/b1bebde5cb4a763ed85b1d8e52c8e30d”,uri=”sip:333@xxx.xxx.xxx.xxx”,algorithm=MD5,response=”8dd827e9910c2446fb0b8497f5944b81″,opaque=”66e52\
68a2111e777″,qop=auth,nc=00000001,cnonce=”9dda9e0d”^M
Contact: “1004” ^M
User-Agent: Cisco/SPA504G-7.4.8a^M
Content-Length: 0^M
^M

SIP/2.0 200 OK^M
Via: SIP/2.0/UDP 192.168.35.91:5063;received=192.168.35.91;branch=z9hG4bK-18e552c3^M
Call-ID: 3162d378-ea2b2452@192.168.35.91^M
From: “1004” ;tag=79e7940882a792ao2^M
To: ;tag=96156bd7-9e8e-4077-b6e4-f3eb12e39069^M
CSeq: 102 INVITE^M
Server: Asterisk PBX 14.2.1^M
Contact: ^M
Allow: OPTIONS, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, MESSAGE, REFER^M
Supported: 100rel, timer, replaces, norefersub^M
Content-Type: application/sdp^M
Content-Length: 179^M
^M
v=0^M
o=- 32730859 32730861 IN IP4 192.168.33.30^M
s=Asterisk^M
c=IN IP4 192.168.33.30^M
t=0 0^M
m=audio 19384 RTP/AVP 0^M
a=rtpmap:0 PCMU/8000^M
a=ptime:20^M
a=maxptime:150^M
a=sendrecv^M

3 thoughts on - Asterisk 14.2.1 PJSIP – Is It Possible To Retrieve A PJSIP Header To Field For The SIP OK Response To Trying?

  • The PJSIP_HEADER dialplan function currently only looks at the initial message. It does not allow access to subsequent ones.

  • Thank you Joshua.

    So there is no way to retrieve header information which may come in on subsequent packages?

    If not, is there any way to make an Attended Transfer following the RFC5589?
    https://tools.ietf.org/html/rfc5589

    Asking because we have a hospital with a Cisco switch. Hospital has two calls from their Cisco switch into an Asterisk box. Operator handling the two calls and needs to transfer Call A to be connected to call B. Can obviously be patched inside of Asterisk. However, the hospital wants the call to be Attended Transferred. Basically, we need to send the Transfer (REFER) with the Replaces containing the call ID, From tag, and the To Tag.

    I am able to gather everything needed for the REFER field and pass that to the Transfer command (via AMI), except the To tag.

    —–Original Message—

  • There isn’t that I can think of. Even if you are able to construct such a REFER I’m not sure what exactly will happen inside of Asterisk with the legs.