How do I modify the P-asserted Identity

Hi Everyone,

I am new to the FreePBX world. Our office has recently got a VOIP line from Vodafone.
We need to forward all the calls received on this Vodafone number to an external landline number in a another Country, this is a rather basic function, so, instead of buying an expensive PBX, I decided to try with the FreePBX first.
I have got the FreePBX installed and incoming and outgoing calls are working as expected, I can even forward calls to the correct destination, but somehow I couldn’t get the caller ID displayed correctly on the remote side.
Let’s say the office VOIP line is 1111 and the remote number is 2222, and my mobile phone is 3333, if I call 1111 on my mobile, the 2222 rings, but the caller ID is displayed as “1111”, which is not what I want, I want 3333 to be displayed.
So, I called Vodafone, they said that they authenticates the outbound calls via the SIP header, that is:
1, the “from” tag in the SIP header has to be “5800 or 5801”
2, add a “P asserted Identity” to the header and assigned a value of “5800 or 5801”

So, I enabled “send PAI” on the FreePBX UI, it did then send the P-asserted-Identity, but it just simply copies it from the “From” tag, which doesn’t work at all.
I need to somehow find a way to modity and fix the “P-asserted-Identity” value to “5800 or 5801”

A lot of the threads suggested to change the dialplan in the extension_custom.conf, which i did, but it did not work, it appears that the dialplan did not take effect at all.

By the way, I am using Chan-PJSIP, would it be the cause why the dialplan doesn’t work?
Would someone help me to change the dialplan for Chan-PJSIP? I’d really appreciate it.

If you want to modify a dial-plan, you add something like this:

SipAddHeader(P-Asserted-Identity: sip:${CALLERIDNUM})

If you want to do it in a dial-hook, you could use this:

If this is a one-off, you could create a new outbound route and specify the outbound caller ID in that, and set it so that only your extension is identified as a possible caller.

Thank you for the quick response, I tried your method, I have modified the extension_custom.conf as below:
exten => s,1,SipAddHeader(P-Asserted-Identity: sip:061229580(@)
From the cli monitor, I see this marco being executed.
However, the header did not actually updated, when I do a wireshark capture, I see in the SIP invite, the P-Asserted-Identity header still being “15114646XXX(@)”, the “15114646XXX” being my mobile number, thus it still cannot get authenticated from Vodafone, the fowarding still doesn’t work.

Could it because somewhere deep in the asterisk kernal, it forbids me to update the P-asserted-identity?

The P-Asserted-Header is setting set right before the Trunk is being called. Are you setting a Caller ID in the Trunk definition?

Talks about setting the PAID for normal calls. He’s having problems with called where the CID is anonymous, but provides some additional information about other settings you might need to modify,

Well since the trunk has the option Send PAI for it that means this is a PJSIP trunk so using SIPAddHeader() isn’t going to work because that’s a Chan_SIP setting.

As well, setting the PAI in the hook macro and then having Send PAI=yes on the trunk is going to override what the dialplan did. Well may not override per se but it will just add a new PAI header and then push the one set in the dialplan to the 1 position (because you can have multiple PAI headers)

If this is a FollowMe or a Call Forwarded call then the original CallerID is going to be honored unless something else overrides it. So if the provider is saying a specific DID (or DIDs) must be used as Outbound CallerID then you need to make sure those are set.

If they are rejecting your call due to an auth issue, PAI is really not used for that. If they are using it for that, get another provider. Plus we really should be seeing a rejected call to make sure it’s formatted right.

thank you for your reply, here are my detailed configuration:


Could anyone help, I really need to get the numbers displayed correctly here.
Update: I tried disabling “sendPAI” both in the extension and the SIP trunk, and then I added this line in the extension_custom.conf:
exten => 1,1,Set(PJSIP_HEADER(add,P-Asserted-Identity)=sip:[email protected])

When I do a wireshark capture, I still can’t see the P-Asserted-Identity being added.

Update again:
I just find out I couldn’t add any header to the SIP packet through the extension_custom.conf, this is really bugging me, here’s my code in the conf file:
exten => s,1,Set(PJSIP_HEADER(add,P-Asserted-Identity)=sip:mike(@)
exten => s,n,Set(PJSIP_HEADER(add,Diversion)=sip:mike(@)

from the CLI i can see these are being executed:
– Executing [[email protected]:1] Set(“Local/[email protected];2”, “PJSIP_HEADER(add,P-Asserted-Identity)=sip:mike(@)”) in new stack

[2019-08-13 10:34:26] ERROR[21758][C-00000049]: res_pjsip_header_funcs.c:513 func_write_header: This function requires a PJSIP channel.

-- Executing [[email protected]:3] Set("Local/00XXXXXXXX(@)from-internal-00000023;2", "PJSIP_HEADER(add,Diversion)=sip:mike(@)") in new stack

[2019-08-13 10:34:26] ERROR[21758][C-00000049]: res_pjsip_header_funcs.c:513 func_write_header: This function requires a PJSIP channel.

The error says it requires a PJSIP Channel, but I am using PJSIP. there’s got be something I am not doing it correct, would someone please help, I am really desperate!!

OK, I’m not sure where the disconnect is here but you were told why this is happening.

You have ZERO configuration to force the CallerID to be what you want it to be. If Vodafone is saying the CallerID has to be one or another DID then you need to pick one and force that CID for each outbound call.

Again, FollowMe and Call Forward by default will keep the original CallerID and pass that through as the CallerID of the call which Vodafone is probably denying because it’s not one of their DIDs.

That is what is happening correct?!

Thank you for the input!
Update, I’ve finally got it right, the reason why the above code doesn’t work is becasue I was using PJSIP for the vodafone trunk.
Today I switched it to Chan-SIP, and the marco worked, I can manipulate the SIP header as expected.
Then, in the inbound route, I pointed the call to a ring group, with the external number being the only extension in the ring group, I now can forward calls to the external number with the original number displayed correctly on the remote site.
Thank you all for the great help!!

The reason it didn’t work for PJSIP is that PJSIP must have the headers applied on the called channel not the calling channel. So the headers were being put on the wrong channel with your code.

Again, all of this could have been solved in the GUI and didn’t require this custom code. But if this is how you want it and it works, go for it.

Hi Blaze,

Thank you for the explanation.
If all this can be accomplished in the GUI, I’d preferred to do in this way when I put this into production.
Would you please share your thoughts on how to do it via GUI.
Again, appreciate the help!

I’ve also run into this problem. I’d MUCH rather solve it through the GUI than delve into the config files. The SIP trunk is working using chan_sip, but I’ve been unable to make it function with pjsip.

Tom, could you post a synopsis of how to accomplish this through the GUI? I see no box in the chan_sip trunk for sending the PAI as there is in pjsip.

The reason why this doesn’t work is because adding custom sip headers to the called channel in pjsip works differently than in chansip. The way you were doing it you were adding the header to the calling channel instead of the called channel.
In pjsip the header has to be added via a predial handler, meaning the header has to be added after the dial application is executed.

FreePBX has a something built in to accomplish that, the func-set-sipheader GoSub that you add to the macro-dialout-trunk-predial-hook in extensions_custom.conf.

Your dialplan would have had to look like this:

exten => s,1,GoSub(func-set-sipheader,s,1(Diversion,sip:mike(@)
exten => s,n,Macroexit()
1 Like

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