SIP Trunk, Outbound Hidden CID, rewrite PAI, From and To Headers

Hi,
I am slowly building up a [macro-dialout-trunk-predial-hook] dial plan to send exactly what our trunk provider requires but have hit another snag, if anyone can help steer me in the right direction.

Normal calls out get the PAI paid header added via the trunk configuration and all works well.

CHAN_SIP Trunk to provider

type=peer
trustrpid=yes
send_pai=yes
sendrpid=pai
qualify=yes
nat=yes
insecure=very
host=VOIP_Provider_IP
fromdomain=PBX_IP
dtmfmode=rfc2833
context=from-internal
canreinvite=no

The issue only arises when calling out hidden, called withheld.
I have an outbound route created with
Route CID - “hidden”
Override Extension - Yes
Dial Pattern - Prefix 141 so the user dials 141 to dial out with a withheld number.

Dialling out caller withheld without any [macro-dialout-trunk-predial-hook] code, it doesn’t add a P-Asserted-Identity into the header and the call gets refused by the trunk provider.

My code is below, it looks for a hidden call and creates a P-Asserted-Identity for it. My next issue is the From field is going through as “Anonymous” sip:anonymous@PBX_IP:PORT;tag=ad54277d86

How can I get this to go through as “Anonymous” sip:[email protected]

I have tried a few lines like Set(CALLERID… but wireshark still shows anonymous@PBX_IP:PORT

[macro-dialout-trunk-predial-hook]
exten => s,1,NoOp(hidden number check predial hook)
exten => s,n,GotoIf($["${CALLERID(num)}" = ""]?hidden:nothidden)
exten => s,n,GotoIf($["${CALLERID(name):0:9}" = "anonymous"]?hidden:nothidden)
exten => s,n,GotoIf($["${CALLERID(name):0:6}" = "hidden"]?hidden:nothidden)
exten => s,n(hidden),NoOp(The call IS hidden)
exten => s,n,Set(CALLERID(pres)=prohib)
exten => s,n,Set(CALLERID(num-pres)=prohib)
exten => s,n,Set(CALLERID(name-pres)=prohib)
exten => s,n,SipAddHeader(P-Asserted-Identity: sip:${CALLERID(num)}@PBX_IP)
exten => s,n,SipAddHeader(Privacy:id)
exten => s,n,MacroExit()
exten => s,n(nothidden),NoOp(The call is NOT hidden)
exten => s,n,MacroExit()

The code currently does hide the called ID when dialling other SIP providers, and some mobile phone providers in the UK, however there are some mobile providers that still display the Caller ID and my provider is now pointing me to the FROM header as its not exactly what they require.

Thanks
D

Wrong format. Format is the same as a From Header: "Name" <sip:user@domain:port> so something like "Anonymous" <sip:[email protected]:5060>

Hi Tom,
Sorry I dont fully understand, I tried changing my line to

exten => s,n,SipAddHeader(P-Asserted-Identity: "anonymous" sip:${CALLERID(num)}@PBX_IP)

but it wouldn’t dial out.

With the first code, my from header shows as

"Anonymous" <sip:anonymous@PBX_IP:5160>;tag=ad54277d86

So it seems to be getting most of the code, just need the domain PBX_IP part to change to anonymous.local to give the provider the exact code the ask for.

If I cant get this into my head soon I shall go to Sangoma support and use some of my platinum PBXact support credits. Was hoping to work it out myself with help from the community but I feel I need a lot more training lol.

Thanks for your help,
D

OK so first, please use the formatting tools here, the quote or code formatting options because your brackets are being processed as HTML code and makes it hard to tell if what you have pasted are in the correct format or not. Right now it still looks like the wrong format.

Second, Asterisk could be doing this. Would need to see the output of a call with “sip set debug on” to see what is happening with the headers.

Hi Ray,
Sorry, its possible I broke my code trying put simplify it for this post, here is my actual full code which includes IAX variables for when I send the CID through IAX trunks.

[macro-dialout-trunk-predial-hook]
exten => s,1,NoOp(hidden number check predial hook)
exten => s,n,ExecIf($[${DB_EXISTS(AMPUSER/${AMPUSER}/outboundcid)}]?set(IAXVAR(X-OUTBOUND-CID)=${DB(AMPUSER/${AMPUSER}/outboundcid)}))
exten => s,n,ExecIf($[${DB_EXISTS(AMPUSER/${AMPUSER}/outboundcid)}]?Noop(Storing outbound cid for remote use: ${IAXVAR(X-OUTBOUND-CID)}))
exten => s,n,GotoIf($["${CALLERID(num)}" = ""]?hidden:nothidden)
exten => s,n,GotoIf($["${CALLERID(name):0:9}" = "anonymous"]?hidden:nothidden)
exten => s,n,GotoIf($["${CALLERID(name):0:6}" = "hidden"]?hidden:nothidden)
exten => s,n(hidden),NoOp(The call IS hidden)
exten => s,n,Set(CALLERID(pres)=prohib)
exten => s,n,Set(CALLERID(num-pres)=prohib)
exten => s,n,Set(CALLERID(name-pres)=prohib)
exten => s,n,SipAddHeader(P-Asserted-Identity:sip:${IAXVAR(X-OUTBOUND-CID)}@PBX_IP)
exten => s,n,SipAddHeader(Privacy:id)
exten => s,n,MacroExit()
exten => s,n(nothidden),NoOp(The call is NOT hidden)
exten => s,n,MacroExit()

Hopefully this looks better, I shall upload the results of the SIP debug next

How much of the SIP call do you require… here is the bit where the PAI and From headers are

Audio is at 14844
Adding codec ulaw to SDP
Adding codec alaw to SDP
Adding codec gsm to SDP
Adding codec g726 to SDP
Adding codec g722 to SDP
Adding non-codec 0x1 (telephone-event) to SDP
Reliably Transmitting (NAT) to VOIP_PROVIDER_IP:5060:
INVITE sip:078XXXXXXXX@VOIP_PROVIDER_IP SIP/2.0
Via: SIP/2.0/UDP PBX_IP:5160;branch=z9hG4bK5400bcc5;rport
Max-Forwards: 70
From: "Anonymous" <sip:anonymous@PBX_IP:5160>;tag=as791e5a63
To: <sip:078XXXXXXXX@VOIP_PROVIDER_IP>
Contact: <sip:anonymous@PBX_IP:5160>
Call-ID: 5f73a36c5c1349fe70e56e4a231acf89@PBX_IP
CSeq: 102 INVITE
User-Agent: FPBX-14.0.13.4(13.22.0)
Date: Wed, 23 Oct 2019 00:22:56 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Privacy: id
P-Asserted-Identity: sip:028XXXXXXXX@PBX_IP
Content-Type: application/sdp
Content-Length: 354

Try:

exten => s,n,SipAddHeader(P-Asserted-Identity: "anonymous" <sip:${CALLERID(num)}@PBX_IP>)

It’s almost like someone posted that before saying the format was wrong and provided examples.

Hi Stewart and Tom,
When I use

exten => s,n,SipAddHeader(P-Asserted-Identity: "anonymous" (sip:${CALLERID(num)}@PBX_IP))

or if I try to use

exten => s,n,SipAddHeader(P-Asserted-Identity: "anonymous" sip:${IAXVAR(X-OUTBOUND-CID)}@PBX_IP)

the call doesnt happen, here are the logs when using
exten => s,n,SipAddHeader(P-Asserted-Identity: "anonymous" (sip:${CALLERID(num)}@PBX_IP))

[root@PBXname ~]# asterisk -r
Asterisk 13.22.0, Copyright (C) 1999 - 2014, Digium, Inc. and others.
Created by Mark Spencer <[email protected]>
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Connected to Asterisk 13.22.0 currently running on PBXname (pid = 10520)
PBXname*CLI> sip set debug on
SIP Debugging re-enabled

<--- SIP read from UDP:phone_public_IP:50628 --->


<------------->

<--- SIP read from UDP:phone_public_IP:50628 --->
INVITE sip:[email protected]:5160 SIP/2.0
Via: SIP/2.0/UDP 10.10.20.100:5060;branch=z9hG4bK764587136
From: "4000" <sip:[email protected]:5160>;tag=2093903271
To: <sip:[email protected]:5160>
Call-ID: [email protected]
CSeq: 1 INVITE
Contact: <sip:[email protected]:5060>
Content-Type: application/sdp
Allow: INVITE, INFO, PRACK, ACK, BYE, CANCEL, OPTIONS, NOTIFY, REGISTER, SUBSCRIBE, REFER, PUBLISH, UPDATE, MESSAGE
Max-Forwards: 70
User-Agent: Yealink SIP-T42G 29.83.0.50
Allow-Events: talk,hold,conference,refer,check-sync
Supported: replaces
Content-Length: 306

v=0
o=- 20072 20072 IN IP4 10.10.20.100
s=SDP data
c=IN IP4 10.10.20.100
t=0 0
m=audio 11894 RTP/AVP 9 0 8 18 101
a=rtpmap:9 G722/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=ptime:20
a=sendrecv
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
<------------->
--- (14 headers 15 lines) ---
Sending to phone_public_IP:50628 (NAT)
Sending to phone_public_IP:50628 (NAT)
Using INVITE request as basis request - [email protected]
Found peer '4000' for '4000' from phone_public_IP:50628

<--- Reliably Transmitting (NAT) to phone_public_IP:50628 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 10.10.20.100:5060;branch=z9hG4bK764587136;received=phone_public_IP;rport=50628
From: "4000" <sip:[email protected]:5160>;tag=2093903271
To: <sip:[email protected]:5160>;tag=as060dfaed
Call-ID: [email protected]
CSeq: 1 INVITE
Server: FPBX-14.0.13.4(13.22.0)
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
WWW-Authenticate: Digest algorithm=MD5, realm="asterisk", nonce="12a9189f"
Content-Length: 0


<------------>
Scheduling destruction of SIP dialog '[email protected]' in 6400 ms (Method: INVITE)

<--- SIP read from UDP:phone_public_IP:50628 --->
ACK sip:[email protected]:5160 SIP/2.0
Via: SIP/2.0/UDP 10.10.20.100:5060;branch=z9hG4bK764587136
From: "4000" <sip:[email protected]:5160>;tag=2093903271
To: <sip:[email protected]:5160>;tag=as060dfaed
Call-ID: [email protected]
CSeq: 1 ACK
Content-Length: 0

<------------->
--- (7 headers 0 lines) ---

<--- SIP read from UDP:phone_public_IP:50628 --->
INVITE sip:[email protected]:5160 SIP/2.0
Via: SIP/2.0/UDP 10.10.20.100:5060;branch=z9hG4bK4045341704
From: "4000" <sip:[email protected]:5160>;tag=2093903271
To: <sip:[email protected]:5160>
Call-ID: [email protected]
CSeq: 2 INVITE
Contact: <sip:[email protected]:5060>
Authorization: Digest username="4000", realm="asterisk", nonce="12a9189f", uri="sip:[email protected]:5160", response="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", algorithm=MD5
Content-Type: application/sdp
Allow: INVITE, INFO, PRACK, ACK, BYE, CANCEL, OPTIONS, NOTIFY, REGISTER, SUBSCRIBE, REFER, PUBLISH, UPDATE, MESSAGE
Max-Forwards: 70
User-Agent: Yealink SIP-T42G 29.83.0.50
Allow-Events: talk,hold,conference,refer,check-sync
Supported: replaces
Content-Length: 306

v=0
o=- 20072 20072 IN IP4 10.10.20.100
s=SDP data
c=IN IP4 10.10.20.100
t=0 0
m=audio 11894 RTP/AVP 9 0 8 18 101
a=rtpmap:9 G722/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=ptime:20
a=sendrecv
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
<------------->
--- (15 headers 15 lines) ---
Sending to phone_public_IP:50628 (NAT)
Using INVITE request as basis request - [email protected]
Found peer '4000' for '4000' from phone_public_IP:50628
Found RTP audio format 9
Found RTP audio format 0
Found RTP audio format 8
Found RTP audio format 18
Found RTP audio format 101
Found audio description format G722 for ID 9
Found audio description format PCMU for ID 0
Found audio description format PCMA for ID 8
Found audio description format G729 for ID 18
Found audio description format telephone-event for ID 101
Capabilities: us - (ulaw|alaw|gsm|g726|g722), peer - audio=(ulaw|alaw|g722|g729)/video=(nothing)/text=(nothing), combined - (ulaw|alaw|g722)
Non-codec capabilities (dtmf): us - 0x1 (telephone-event|), peer - 0x1 (telephone-event|), combined - 0x1 (telephone-event|)
Peer audio RTP is at port 10.10.20.100:11894
Looking for 141078XXXXXXXX in from-internal (domain PBXname.domain.co.uk)
sip_route_dump: route/path hop: <sip:[email protected]:5060>

<--- Transmitting (NAT) to phone_public_IP:50628 --->
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 10.10.20.100:5060;branch=z9hG4bK4045341704;received=phone_public_IP;rport=50628
From: "4000" <sip:[email protected]:5160>;tag=2093903271
To: <sip:[email protected]:5160>
Call-ID: [email protected]
CSeq: 2 INVITE
Server: FPBX-14.0.13.4(13.22.0)
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Contact: <sip:141078XXXXXXXX@PBX_IP:5160>
Content-Length: 0


<------------>
Audio is at 18970
Adding codec ulaw to SDP
Adding codec alaw to SDP
Adding codec gsm to SDP
Adding codec g726 to SDP
Adding codec g722 to SDP
Adding non-codec 0x1 (telephone-event) to SDP
Reliably Transmitting (NAT) to VOIP_PROVIDER_IP:5060:
INVITE sip:078XXXXXXXX@VOIP_PROVIDER_IP SIP/2.0
Via: SIP/2.0/UDP PBX_IP:5160;branch=z9hG4bK5305f273;rport
Max-Forwards: 70
From: "Anonymous" <sip:anonymous@PBX_IP:5160>;tag=as3a122d80
To: <sip:078XXXXXXXX@VOIP_PROVIDER_IP>
Contact: <sip:anonymous@PBX_IP:5160>
Call-ID: 4189fdd36bf2a7c0700b5c394d81e0f2@PBX_IP
CSeq: 102 INVITE
User-Agent: FPBX-14.0.13.4(13.22.0)
Date: Wed, 23 Oct 2019 07:38:37 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Privacy: id
P-Asserted-Identity: "anonymous" (sip:@PBX_IP)
Content-Type: application/sdp
Content-Length: 352

v=0
o=root 406134749 406134749 IN IP4 PBX_IP
s=Asterisk PBX 13.22.0
c=IN IP4 PBX_IP
t=0 0
m=audio 18970 RTP/AVP 0 8 3 111 9 101
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:3 GSM/8000
a=rtpmap:111 G726-32/8000
a=rtpmap:9 G722/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=ptime:20
a=maxptime:150
a=sendrecv

---

<--- SIP read from UDP:VOIP_PROVIDER_IP:5060 --->
SIP/2.0 400 Bad Request
Via: SIP/2.0/UDP PBX_IP:5160;branch=z9hG4bK5305f273;rport
From: "Anonymous" <sip:anonymous@PBX_IP:5160>;tag=as3a122d80
Call-ID: 4189fdd36bf2a7c0700b5c394d81e0f2@PBX_IP
CSeq: 102 INVITE
To: <sip:078XXXXXXXX@VOIP_PROVIDER_IP>;tag=3780805117-1728066432
Content-Length: 0

<------------->
--- (7 headers 0 lines) ---

I read here https://blogs.asterisk.org/2018/03/07/asterisk-call-party-privacy-and-header-presentation/
that if you use
Set(CALLERID(pres)=prohib)
and have the from_domain blank it fills it in with @anonymous.invalid
but I have no idea how to do this.
Should I have my domain blank in the freepbx settings, then inject the domain IP for normal calls and PAI via dial plan code?

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