Need to pass a valid external CID over an intra-company outbound route

I have a PJSIP trunk setup between two FreePBX 15 systems. trunk works perfectly for all scenarios the users need except one, Find Me/Follow Me.

Normally, calling from extension 121 to extension 5120 shows the CID of 121 on the screen for 5120. But when 5120 has their FMFM active to their cell phone, the call fails because almost no carriers allow invalid CID to be sent any more.

The problem is than a route marked intra-company drops all other CID info except the local CID info.

@lgaetz told me to check out this post for the same thing related to an IAX trunk.

Well that logic makes sense, but what can I do with a PJSIP trunk to pass the info? Setting a SIP header is easy enough, but then I need to know how to read it on the other side during the inbound call handling. Is there some other variable I can use that would hang around like the IAXVAR does?

Knowing we are going out an intra-company trunk is easy. Added a pjsip header was easy. I can confirm on the inbound call I see the header.

[macro-dialout-trunk-predial-hook]
exten => s,1,NoOp(Entering user defined context [macro-dialout-trunk-predial-hook] in extensions_custom.conf)
; Determine if call is on an intra-company route or not
exten => s,n,GotoIf($["${INTRACOMPANYROUTE}"="YES"]?intra_call:pstn_call)

; This is an intracompany call note the outbound CID in the sip header X-OUTBOUND-CID
exten => s,n(intra_call),Noop(This call uses an Intra-Company route)
; If the calling extension has an outbound CID specified, use it
exten => s,n,ExecIf($[${DB_EXISTS(AMPUSER/${AMPUSER}/outboundcid)}]?Set(x_out_cid=${DB(AMPUSER/${AMPUSER}/outboundcid)}))
; If there was no CID found, get the CID specified on the outbound route (yes labeled TRUNKCIDOVERRIDE when found in the route)
exten => s,n,ExecIf("${x_out_cid}"=="")?Set(x_out_cid=${TRUNKCIDOVERRIDE}))
; Add the result as a sip header, change to variable?
exten => s,n,GoSub(func-set-sipheader,s,1(X-Outbound-CID,${x_out_cid}))
exten => s,n,goto(exit_macro)
; This is not an intra-company call. Check for the outbound CID to have been sent along
exten => s,n(pstn_call),NoOp(This call is heading for the PSTN)
;exten => s,n, ;what to do here is the question.

; <snip> unrelated code for setting a header specific to a sip provider </snip>
exten => s,n(exit_macro),MacroExit()
1 Like

Rough guess, not tested, add this to the pstn_call path:

exten => s,n,Set(x_out_cid=${PJSIP_HEADER(read,X-OUTBOUND-CID)})
exten => s,n,ExecIf("${x-out-cid}"!="")?Set(CALLERID(all)=${x-out-cid}))

This is unfortunately after the CDR outbound_cnum and outbound_cnam would have been set, so you may want additional code to deal with that, if you care.

2 Likes

I tried that last night. was not sure I had the syntax right so left it out of my post.

But the header did not appear to be there. Will do some more testing later today.

Any reason you are doing this with a PJSIP trunk instead of an IAX? IAX was designed for type of intra-company purpose, after all. PJSIP was not. :man_shrugging:

Any reason I should not be able to use a PJSIP trunk for this? IAX2 cannot natively do what is needed either.

So with the above code setting a sip header, the inbound call shows this in a channel dump, if I make a new context to handle it.

[from-intra-comp]
exten => _[*0-9]!,1,NoOp(Entering user defined context [from-intra-comp] in extensions_custom.conf)
exten => _[*0-9]!,n,Set(x_passed_cid=${PJSIP_HEADER(read,X-OUTBOUND-CID)})
exten => _[*0-9]!,n,DumpChan()
; exten => _[*0-9]!,n,Hangup()
exten => _[*0-9]!,n,Goto(from-internal,${EXTEN},1)
    -- Executing [5120@from-intra-comp:1] NoOp("PJSIP/Bundy-00007495", "Entering user defined context [from-intra-comp] in extensions_custom.conf") in new stack
    -- Executing [5120@from-intra-comp:2] Set("PJSIP/Bundy-00007495", "x_passed_cid=<http://127.0.0.1><http://127.0.0.1>;info="Route set CID" <13125551212>") in new stack
    -- Executing [5120@from-intra-comp:3] DumpChan("PJSIP/Bundy-00007495", "") in new stack

Dumping Info For Channel: PJSIP/Bundy-00007495:
================================================================================
Info:
Name=               PJSIP/Bundy-00007495
Type=               PJSIP
UniqueID=           1599967326.41133
LinkedID=           1599967326.41133
CallerIDNum=        121
CallerIDName=       Test_Extension
ConnectedLineIDNum= (N/A)
ConnectedLineIDName=(N/A)
DNIDDigits=         5120
RDNIS=              (N/A)
Parkinglot=         
Language=           en
State=              Ring (4)
Rings=              1
NativeFormat=       (ulaw)
WriteFormat=        ulaw
ReadFormat=         ulaw
RawWriteFormat=     ulaw
RawReadFormat=      ulaw
WriteTranscode=     No 
ReadTranscode=      No 
1stFileDescriptor=  -1
Framesin=           0 
Framesout=          0 
TimetoHangup=       0
ElapsedTime=        0h0m0s
BridgeID=           (Not bridged)
Context=            from-intra-comp
Extension=          5120
Priority=           3
CallGroup=          
PickupGroup=        
Application=        DumpChan
Data=               (Empty)
Blocking_in=        (Not Blocking)

Variables:
x_passed_cid=<http://127.0.0.1><http://127.0.0.1>;info="Route set CID" <13125551212>
================================================================================
    -- Executing [5120@from-intra-comp:4] Goto("PJSIP/Bundy-00007495", "from-internal,5120,1") in new stack
    -- Goto (from-internal,5120,1)

So where could I stick he CID information to be picked up later when (if) the call hits FMFM?

Also, what is up with the URL in the XML?

Using similar logic to add this header does not cause that.
image

Still no idea how to get this accomplished. Had only a short time to work on this today so far.

But I did discover that Follow Me is broken in respect to ringing all the AOR for a PJSIP extension.

Same issue as park return had. It uses dial.
Ticket opened: https://issues.freepbx.org/browse/FREEPBX-21869

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