PJSIP how to modify the first part of the From: header in INVITE?

Hello,

I need to modify the first part of a From: header in INVITES for outgoing calls.

From: “Need to set this” <sip:12345@sipprovider.com:5060>;tag=1799533534

The part in the <brackets> can be changed with the from_user and from_domain options.
from_user = 12345
from_domain = sipprovider.com

But how would I change the part between the quotation marks “Need to set this” ?

Thank you very much.

That is the display name, and there is no explicit configuration option for it. It generally maps to the callerid name though.

1 Like

Thank you.
Now i tried this right before the dial:
same => n,Set(CALLERID(name)=“1234567890”)

It doesn’t work. The Display name doesn’t appear in the From header. It still looks like this:

From: <sip:12345@sipprovider.com:5060>;tag=1799533534

You need to use the pre-dial handler and set them on the newly created channel in chan_pjsip. That’s one of the differences between chan_sip and chan_pjsip.

1 Like

All right, now I tried this:

same => n,Dial(PJSIP/123456789@provider,200,gtTb(add_callerid_header^1^1))
.
more stuff here
.

[add_callerid_header]
exten => 1,1,Set(PJSIP_HEADER(add,From)=“1234567890”)
exten => 1,2,Return()

This produces the following error in the Asterisx CLI:

[Apr 9 15:06:26] WARNING[29926]: pjproject: <?>: sip_transport.c Dropping 409 bytes packet from TCP 1.2.3.4:5060 : PJSIP syntax error exception when parsing ‘From’ header on line 7 col -1

Am I on the right track with using the “b” option in Dial? Whats still going wrong?

The From header is fundamental to SIP. You should never try to set it manually. You should only ever set it using various component parts. Trying to set it manually, if not rejected early, will result in two From headers, which is invalid.

(In my view, the same should apply to RPID, and PAI, although it is possible to suppress automatic generation of these, and I would expect it to apply, unconditionally, to Call-ID, Allow, Supports, Content-Type, Via, Referrer, Contact, etc.)

It was where you set the CallerID. The same thing you tried before on the wrong channel.

My problem here is, that the sipprovider expects the From Header in a specific way. They told me to set it like this:

“CLIP phone number” <userid@siprovider.com>

I have to do this because Asterisks standard behavior without further configuration triggered some fraud detection mechanism on their side that resulted in an IP-ban.

So if I don’t send the headers the way they want it might trigger the ban again.

@BlazeStudios Sorry, I don’t understand what you mean. Could you explain further please?

You put this in the predial gosub. You set the caller ID name during the predial gosub.

The provider is abusing the From display name to carry the actual caller ID, and using the From user field as an account code.

I’m not sure if there is an additional constraint here that that the Display Name should be an approved caller ID for the account.

A sufficient reason for the OPs last error is that the provider returned the bogus From header, unchanged, in their response, and Asterisk failed to find the from tag value, let alone find one that matched one that it had sent. This is one reason why you can never manually add a From header, as the dialplan code cannot know the correct from tag to add.

This would stop Asterisk successfully processing even a refusal by the provider.

I see. Yes the Display Name must be an approved caller ID for the account name. I set it in the correct way they told me.

I really hate to fiddle around like that with them, but it’s impossible to change the provider right now. Sadly it’s me they call @ 6:30 in the morning when “the phone is not working”.

Could it be an option to set the expected value directly in the configurations for all the peers (phones)?

@BlazeStudio

All right, I did this now:

same => n,Dial(PJSIP/123456789@provider,200,gtTb(add_callerid_header^1^1))
.
.
[add_callerid_header]
exten => 1,1,Set(CALLERID(name)=“1234567890”)
exten => 1,2,Return()

Sadly this still does not put the Display Name into the From: field of the INVITE
It still looks like this:

From: <sip:12345@sipprovider.com:5060>;tag=1799533534

Upon reading the code, it looks like we drop the display name if you configure from_user so there is no current way to do what you want.

1 Like

Thank you. Bad news but at least something I can tell the telco.

Though if you didn’t set from_user on the endpoint, and instead set callerid in the dialplan of both name and number it should be equivalent.

This is very much in strange requirement territory though.

All right, I will try.

OK. Now I tried this:

I removed from_user and from_domain.

same => n,Dial(PJSIP/123456789@provider,200,gtTb(add_callerid_header^1^1))
.
[add_callerid_header]
exten => 1,1,Set(CALLERID(name)=“0123456789” <sip:userid@sipprovider.com:5060>)
exten => 1,2,Set(CALLERID(num)=“0123456789” <sip:userid@sipprovider.com:5060>)

This resulted in:

From: “local peer name” <sip:local peer name@IP of asterisk in local LAN>

You’re trying to cram an entire From header into those. That’s wrong. They’re literally the values for the name and number parts. Or in From header speak, display name and URI user portion.

Set(CALLERID(name)=Hello World)
Set(CALLERID(num)=5551212)

And try not doing it in the pre-dial handler.