Diversion Header

Setting diversion headers in the GUI is covered a lot. This is just an example.

That post had nothing to do with Diversion headers.

Why is your PBX sending Diversion headers back to your ITSP? Why isn’t the PBX answering the calls and dealing with them? How does a cell provider get involved in rejecting Diversion headers that were between your PBX and your provider?

Perhaps the OP should confirm this before we waste time on a solution, but my understanding is:

An incoming call is routed to a PBX extension, which is not answered. Using Follow Me or Unavailable Forward, the call is forwarded to the user’s mobile, sending the number of the original caller as caller ID. The provider handling the outbound leg routes the call onward to the user’s cell carrier. To reduce the number of spam/scam calls with spoofed caller ID, the cell carrier rejects calls from an unexpected source, unless the forwarding number (DID called) is properly presented in a Diversion header.

@ Stewart1,
Yes, that’s exactly what happens.
The inbound caller ID will always change, so when the call is diverted to the cellular number of the recipient, the diversion header sends the original number that was dialled along but it’s in the incorrect format. This specific cellular provider has simply stated that unless the call is in the correct format, the call will be dropped.
For this reason, I need to change the diversion header to drop the 0 on the number and replace it with +27

Is Adding a custom diversion header useful?
If not, is the trunk pjsip or chan_sip? What have you already tried?

Sigh. Not a single part of that process requires a Diversion Header. In fact the only way FreePBX will even send Diversion Headers is if the feature is explicitly turn on, which by default it is not.

Also why does the destination carrier care?! It doesn’t, stop referring to the “cell carrier” unless that “cell carrier” is somehow the ITSP as well. The only party that is going to care about the Diversion Headers is going to the the ITSP that the call is going out of. The destination carrier has nothing to do with this, nor will it care about Diversion Headers because PSTN.

When the PBX “forwards” is opens a new channel and to the PBX that is just a regular ole call that is going to be sent out the proper trunk. Adding the Diversion Headers to that call is to mimic what proxies do, actual divert the call, as opposed to what B2BUA’s do. Which is answer the call and create new calls/channels for the second (or more) legs. Not new branches of the same call.

@Stewart1 the trunk is chan_sip
I have tried creating a custom extension, which works when I dial the custom extension from another extension, but not when I divert an inbound call to the custom extension.
I have also tried FollowMe, but so far I’m not getting it to work.

@Tom Ray - that’s exactly the fight we are having with the cellular carrier (the destination) as they shouldn’t care, but for some weird reason, they are the ones insisting on the Diversion Header.

We place direct calls to them without any issue as the trunk manipulates the number correctly and changes it to the international format, but on a diverted call, they are blocking it because the diversion header is not in the correct format for them to accept the call.

So your provider, the one that provides you the SIP Trunk to the PSTN, they have no issues with your call? Because you understand at that point the call is going to between your provider and the destination carrier.

You in no way deliver calls directly to the cell provider unless you have some direct peering agreement with them. Are you peering with this cell provider directly or do all your calls go through your SIP provider?

Do they reject the call if you don’t send a Diversion header at all, but supply the number of the original caller in the correct international format? Can you post your trunk settings (except of course for username, secret, etc.)?

Do a test where you temporarily set Outbound CID for your extension to a number that is not yours. From that extension, dial your mobile directly. Does the call complete and does the number you set show on the mobile?

@Tom Ray
Yes, my provider as no issues with my call, but the destination carrier insists on a diversion header, and then proceeds to block it as it’s in the incorrect format. We do not connect to or have any agreements with the cell provider, they are just being ridiculous.

They reject the call if there is no diversion header
I did a test with an extension set to use a number that is not with us, and it went through to my cell, which is with a different provider without any issue, displaying the “wrong” CLID
I then dialled a cell that is with that specific carrier, and the number they display is the first number on the list of numbers that belong to us.

Well that doesn’t make any sense. The call is going to go from your PBX to your carrier. Once your carrier has the call, they decide what to do with it. They could end up routing directly to the cell carrier if they have a peering agreement with them or they will route it to a partner peer that can send the call to the destination carrier.

So clearly someone has something completely messed up or your provider is just really crappy.

I’m not sure that this is correct, but try putting this into /etc/asterisk/extensions_override_freepbx.conf :

exten => s,1,Set(DIVERSION_REASON=${IF($[${LEN(${DIVERSION_REASON})}=0]?no-answer:${DIVERSION_REASON})})
exten => s,n,Gosub(func-set-sipheader,s,1(Diversion,<tel:+27${FROM_DID:1}>\;reason=${DIVERSION_REASON}\;screen=no\;privacy=off))
exten => s,n,Return()

then restart Asterisk.

If no luck, check the outgoing SIP to see whether the Diversion header is present and has been properly formatted.

Sorry, my last post was garbled – check edited version of file.

I now get:
Executing [[email protected]:2] Gosub(“SIP/ECNTRUNK-00000008”, “func-set-sipheader,s,1(Diversion,<tel:+27422933723>;reason=no-answer;screen=no;privacy=off)”) in new stack
[2018-12-15 11:23:40] ERROR[2413][C-00000006] app_stack.c: Attempt to reach a non-existent destination for Gosub: (Context:func-set-sipheader, Extension:s, Priority:1)

The call simply cuts off now when it starts diverting

I’m very puzzled. Possibly the code is different in the version you are running. Take a look at the sub-diversion-header subroutine in your /etc/asterisk/extensions_additional.conf . My intent was that the replacement code be identical except for inserting a modified value of FROM_DID.

If you can’t easily spot the trouble, report whether a truly identical replacement also causes the error.

@Stewart1Thanks for the help so far.

Whilst looking through extensions_additional.conf I found this:

[outrt-10] ; ECN_only
include => outrt-10-custom
exten => _XZ.,1,Macro(user-callerid,LIMIT,EXTERNAL,)
exten => _XZ.,n,Gosub(sub-record-check,s,1(out,${EXTEN},dontcare))
exten => _XZ.,n,ExecIf($[ “${CALLEE_ACCOUNCODE}” != “” ] ?Set(CDR(accountcode)=${CALLEE_ACCOUNCODE}))
exten => _XZ.,n,GosubIf($[${LEN(${FROM_DID})}>0 & “${FROM_DID}”!=“s”]?sub-diversion-header,s,1())
exten => _XZ.,n,Set(MOHCLASS=${IF($["${MOHCLASS}"=""]?default:${MOHCLASS})})
exten => _XZ.,n,Set(_NODEST=)
exten => _XZ.,n,Macro(dialout-trunk,2,${EXTEN},off)
exten => _XZ.,n,Macro(outisbusy,)

;–== end of [outrt-10] ==–;

That is on the specific route linked to the provider in question.
Can that be modified to change the diversion header on that route only?
Apologies, I am very unfamiliar with Asterisk, so learning as I’m going

the sub-diversion-header function itself looks like this:

include => sub-diversion-header-custom
exten => s,1,Set(DIVERSION_REASON=${IF($[${LEN(${DIVERSION_REASON})}=0]?no-answer:${DIVERSION_REASON})})
exten => s,n,SIPAddHeader(Diversion: tel:${FROM_DID};reason=${DIVERSION_REASON};screen=no;privacy=off)
exten => s,n,Return()

;–== end of [sub-diversion-header] ==–;


I modified it to look like this:

exten => s,1,Set(DIVERSION_REASON=${IF($[${LEN(${DIVERSION_REASON})}=0]?no-answer:${DIVERSION_REASON})})
exten => s,n,SIPAddHeader(Diversion: tel:+27${FROM_DID:1};reason=${DIVERSION_REASON};screen=no;privacy=off))
exten => s,n,Return()

Working perfectly!!!

Thank you Stewart1!!!