PJSIP_HEADER – Diversion Header Manipulation
Hi all,
I’m trying to rewrite Diversion header when call forwarding is done on the phone. The phone sends “302 Moved Temporarily” response and sets Diversion header to a local number, but before Asterisk sends this call towards TSP provider I need to change Diversion header to a full PSTN
number. I am using PJSIP_HEADER in a pre-dial handler (configuration is below). On the same call I can add some other custom headers (logs are below).
Is there any chance I can rewrite Diversion header in this scenario with PJSIP_HEADER function? Asterisk version is 16.0.1 built from source on Debian 9.
Thank you
Davor
# Outgoing context – TSP provider
[outgoing]
exten =>
0123456789,1,Dial(PJSIP/${EXTEN}@${SBC_1},,b(add_diversion^FWDdiver^1))
same => n,Hangup()
# Diversion manipulation context
[add_diversion]
exten =>
FWDdiver,1,Set(PJSIP_HEADER(add,Diversion)=
exten =>
FWDdiver,2,Set(PJSIP_HEADER(add,CustomOne)=
exten =>
FWDdiver,3,Set(PJSIP_HEADER(add,CustomTwo)=
exten => FWDdiver,4,Return()
Asterisk*CLI>
— Now forwarding PJSIP/527-00000168 to ‘Local/0123456789@outgoing’
(thanks to PJSIP/836-00000169)
[Dec 10 10:25:08] NOTICE[26309][C-000000c0]: app_dial.c:1005 do_forward:
Not accepting call completion offers from call-forward recipient Local/0123456789@outgoing-0000002c;1
— Executing [0123456789@outgoing:1]
Dial(“Local/0123456789@outgoing-0000002c;2”,
“PJSIP/0123456789@SBC1,,b(add_diversion^FWDdiver^1)”) in new stack
— PJSIP/SBC1-0000016a Internal Gosub(add_diversion,FWDdiver,1) start
— Executing [FWDdiver@add_diversion:1] Set(“PJSIP/SBC1-0000016a”,
“PJSIP_HEADER(add,Diversion)=
in new stack
— Executing [FWDdiver@add_diversion:2] Set(“PJSIP/SBC1-0000016a”,
“PJSIP_HEADER(add,CustomOne)=
in new stack
— Executing [FWDdiver@add_diversion:3] Set(“PJSIP/SBC1-0000016a”,
“PJSIP_HEADER(add,CustomTwo)=
in new stack
— Executing [FWDdiver@add_diversion:4]
Return(“PJSIP/SBC1-0000016a”, “”) in new stack
Phone => Asterisk U 10.201.8.192:5060 -> 10.201.1.19:5060
SIP/2.0 302 Moved Temporarily. Diversion:
Asterisk => TSP provider U 10.201.1.19:5060 -> 10.201.1.15:5060
CustomOne:
—
4 thoughts on - PJSIP_HEADER – Diversion Header Manipulation
Davor,
Have you attempted to do a Set(PJSIP_HEADER(remove,Diversion)=)) in your add_diversion context to remove the header Asterisk is passing through?
Hi John,
yes I tried to do “remove” and “update” of the Diversion header but I
get “No headers had been previously added to this session” error. As you can see from the configuration and logs below I can successfully add another From: header and make update to that additional From header.
I previously missed to notice change in the domain part of SIP URI in Diversion header. Phone sets Diversion header to “836@10.201.1.19” and Asterisk makes change in domain part of Diversion hdr in INVITE message to “192.168.1.101”. This server has two network interfaces and
192.168.1.101 is set on eth0. So, Asterisk makes a change to Diversion header but not the one set by PJSIP_HEADER function.
Davor
#1 Phone -> Asterisk U 10.201.8.192:5060 -> 10.201.1.19:5060;reason=unconditional. Server: Linksys/SPA922-6.1.5(a). Content-Length: 0.
SIP/2.0 302 Moved Temporarily. Diversion:
#2 Asterisk -> TSP provider U 10.201.1.19:5060 -> 10.201.1.15:5060;tag=629ca252-0930-404b-9f58-f921ed264ebf. From: Update to From Header. Custom–
INVITE sip:0123456789@10.201.1.15:5060 SIP/2.0. From:
The Diversion header is created and managed by the implementation in PJSIP itself. It can’t be edited using the PJSIP_HEADER dialplan function, but can be manipulated using the normal core mechanisms[1].
[1] https://wiki.asterisk.org/wiki/display/AST/Manipulating+Party+ID+Information#ManipulatingPartyIDInformation-REDIRECTINGdialplanfunction
—
Joshua C. Colp Digium – A Sangoma Company | Senior Software Developer
445 Jan Davis Drive NW – Huntsville, AL 35806 – US
Check us out at: http://www.digium.com & http://www.asterisk.org
—
got it working by using REDIRECTING function, thank you.
Davor
—