Issue with Setting __FROM_DID for Processing Inbound Calls

I am experiencing an issue with setting the __FROM_DID variable for processing inbound calls. This issue started occurring after switching to a new provider, who sends the DID via the “To” header. Although I can successfully capture the DID from the “To” header, the __FROM_DID variable does not retain the expected value throughout the call processing.

Context:

  • I have one main PBX which acts as a trunk to receive signals from my provider. This main PBX then routes the calls to multiple other PBX installations via extensions.
  • The other PBX installations are configured to use the extension details of the main PBX as their trunk settings, with the trunk context set to from-pstn.
  • This setup has worked flawlessly with my previous provider. However, since switching to the new provider, I am facing issues with the DID handling.
  • The new provider sends the DID information in the “To” header of the SIP INVITE.
  • Despite successfully capturing the DID from the “To” header, the __FROM_DID variable does not retain its value as expected.
  • I am running FreePBX version 16.0.40.7.

Here’s my complete “extensions_custom.conf” dial plan configuration:

[from-pstn-e164-europe]
exten => _.,1,NoOp(Attempting to extract DID from SIP To header)
exten => _.,n,GotoIf($["${CHANNEL(channeltype)}"="SIP"]?handle-sip)
exten => _.,n,GotoIf($["${CHANNEL(channeltype)}"="PJSIP"]?handle-pjsip)
exten => _.,n,NoOp(Unable to determine SIP channel type)
exten => _.,n,Goto(from-pstn,${EXTEN},1)

exten => _.,n(handle-sip),NoOp(SIP To Header: ${SIP_HEADER(To)})
exten => _.,n,Set(DID=${CUT(CUT(SIP_HEADER(To),@,1),:,2)})
exten => _.,n,NoOp(Extracted DID: ${DID})
exten => _.,n,Goto(did-processing,${DID},1)

exten => _.,n(handle-pjsip),NoOp(PJSIP To Header: ${PJSIP_HEADER(read,To)})
exten => _.,n,Set(DID=${CUT(CUT(PJSIP_HEADER(read,To),@,1),:,2)})
exten => _.,n,NoOp(Extracted DID: ${DID})
exten => _.,n,Goto(did-processing,${DID},1)

[did-processing]
exten => _X.,1,NoOp(Processing DID: ${EXTEN})
exten => _X.,n,Set(__FROM_DID=${EXTEN})
exten => _X.,n,NoOp(FROM_DID set to: ${__FROM_DID})

; Retrieve the original CALLERID
exten => _X.,n,NoOp(Original CALLERID: ${CALLERID(all)})

; Add P-Asserted-Identity header
exten => _X.,n,Set(PJSIP_HEADER(add,P-Asserted-Identity)=sip:${DID}@${SIPDOMAIN})
exten => _X.,n,NoOp(P-Asserted-Identity set to: ${PJSIP_HEADER(read,P-Asserted-Identity)})

; Correct the Diversion header
exten => _X.,n,Set(PJSIP_HEADER(add,Diversion)=sip:${DID}@${SIPDOMAIN})
exten => _X.,n,NoOp(Diversion set to: ${PJSIP_HEADER(read,Diversion)})

; Add To header
exten => _X.,n,Set(PJSIP_HEADER(add,To)=<sip:${DID}@${SIPDOMAIN}>)
exten => _X.,n,NoOp(To header set to: ${PJSIP_HEADER(read,To)})

; Use REDIRECTING function for Diversion header
exten => _X.,n,Set(REDIRECTING(from-num)=${DID})
exten => _X.,n,Set(REDIRECTING(reason)=unconditional)
exten => _X.,n,NoOp(REDIRECTING set to: ${REDIRECTING(from-num)} for reason: ${REDIRECTING(reason)})

; Continue with regular processing
exten => _X.,n,GotoIf($["${EXTEN:0:1}" = "+"]?remove-plus)
exten => _X.,n,Goto(from-pstn,${EXTEN},1)

exten => _X.,n(remove-plus),Set(DID=${EXTEN:1})
exten => _X.,n,NoOp(Removed plus: ${DID})
exten => _X.,n,Goto(from-pstn,${DID},1)

[E164-Other]
exten => _X.,1,NoOp(Routing E164 Other DID: ${EXTEN})
exten => _X.,n,NoOp(FROM_DID set to: ${FROM_DID} in E164-Other)
exten => _X.,n,Set(__FROM_DID=${EXTEN})
exten => _X.,n,Goto(from-pstn,${EXTEN},1)

[macro-dialout-trunk-predial-hook]
exten => s,1,NoOp(Entering user defined context [macro-dialout-trunk-predial-hook] in extensions_custom.conf)
exten => s,n,NoOp(Adding P-Asserted-Identity and From Headers)
exten => s,n,Set(DOMAIN=${SIPDOMAIN})
exten => s,n,Set(PJSIP_HEADER(add,P-Asserted-Identity)=sip:${CALLERID(num)}@${DOMAIN})
exten => s,n,NoOp(P-Asserted-Identity set to: ${PJSIP_HEADER(read,P-Asserted-Identity)})
exten => s,n,Set(HASH(__SIPHEADERS,P-Asserted-Identity)=${CALLERID(num)}@${DOMAIN})
exten => s,n,Set(PJSIP_HEADER(add,From)=${CALLERID(num)}@${DOMAIN})
exten => s,n,NoOp(From set to: ${PJSIP_HEADER(read,From)})
exten => s,n,MacroExit()

[macro-outbound-callerid]
exten => s,1,NoOp(Custom Macro-Outbound-CallerID)
exten => s,n,NoOp(Current CallerID Name: ${CALLERID(name)})
exten => s,n,NoOp(Current CallerID Number: ${CALLERID(num)})
exten => s,n,Set(CALLERID(all)=${CALLERID(name)} <${CALLERID(num)}>)
exten => s,n,NoOp(CallerID set to: ${CALLERID(all)})
exten => s,n,MacroExit()

Example Logs:

-- Executing [123456789@did-processing:1] NoOp("SIP/Provider-00000001", "Processing DID: 123456789") in new stack
-- Executing [123456789@did-processing:2] Set("SIP/Provider-00000001", "__FROM_DID=123456789") in new stack
-- Executing [123456789@did-processing:3] NoOp("SIP/Provider-00000001", "FROM_DID set to: ") in new stack

Additional Information:

  • Incoming traffic on the main BPX works, and I can also make outbound calls.
  • My provider requires specific headers to be included for outbound calls, which is functioning correctly.
  • The main issue is that the main PBX, which acts as a sort of trunk provider for multiple other PBX installations, cannot successfully communicate the DID to these secondary PBX systems. This setup has always worked until I switched providers, and now the DID is not being passed through correctly to the other PBX installations.

Below is the log output from a secondary PBX configured with extension 2001 as the trunk. This extension corresponds to the main PBX. The logs show that the secondary PBX is not receiving the DID correctly:

[2024-06-22 21:25:44] VERBOSE[25376] res_pjsip_logger.c: <--- Received SIP request (1126 bytes) from UDP:XXX.XXX.XXX.XXX:5060 --->
123258    INVITE sip:[email protected]:5060;line=stzijaa SIP/2.0    
123259    Via: SIP/2.0/UDP XXX.XXX.XXX.XXX:5060;rport;branch=z9hG4bKPj433d6227-c6ce-4fb9-8c79-e724492d6510    
123260    From: "+31XXXXXXXXX" <sip:[email protected]>;tag=cfe3d9d9-6ac3-455e-9bcb-b988fd403e34    
123261    To: <sip:[email protected];line=stzijaa>    
123262    Contact: <sip:[email protected]:5060>    
123263    Call-ID: 560e1e13-ec07-4644-9408-f81e93559786    
123264    CSeq: 20452 INVITE    
123265    Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER    
123266    Supported: 100rel, timer, replaces, norefersub, histinfo    
123267    Session-Expires: 1800    
123268    Min-SE: 90    
123269    P-Asserted-Identity: "+31XXXXXXXXX" <sip:[email protected]>    
123270    Max-Forwards: 70    
123271    User-Agent: FPBX-16.0.40.8(19.8.0)    
123272    Content-Type: application/sdp    
123273    Content-Length: 341    
123274        
123275    v=0    
123276    o=- 674850139 674850139 IN IP4 XXX.XXX.XXX.XXX    
123277    s=Asterisk    
123278    c=IN IP4 XXX.XXX.XXX.XXX    
123279    t=0 0    
123280    m=audio 11342 RTP/AVP 8 0 3 111 9 101    
123281    a=rtpmap:8 PCMA/8000    
123282    a=rtpmap:0 PCMU/8000    
123283    a=rtpmap:3 GSM/8000    
123284    a=rtpmap:111 G726-32/8000    
123285    a=rtpmap:9 G722/8000    
123286    a=rtpmap:101 telephone-event/8000    
123287    a=fmtp:101 0-16    
123288    a=ptime:20    
123289    a=maxptime:150    
123290    a=sendrecv    
123291        
123292    [2024-06-22 21:25:44] VERBOSE[25765] res_pjsip_logger.c: <--- Transmitting SIP response (405 bytes) to UDP:XXX.XXX.XXX.XXX:5060 --->
123293    SIP/2.0 100 Trying    
123294    Via: SIP/2.0/UDP XXX.XXX.XXX.XXX:5060;rport=5060;received=XXX.XXX.XXX.XXX;branch=z9hG4bKPj433d6227-c6ce-4fb9-8c79-e724492d6510    
123295    Call-ID: 560e1e13-ec07-4644-9408-f81e93559786    
123296    From: "+31XXXXXXXXX" <sip:[email protected]>;tag=cfe3d9d9-6ac3-455e-9bcb-b988fd403e34    
123297    To: <sip:[email protected];line=stzijaa>    
123298    CSeq: 20452 INVITE    
123299    Server: FPBX-16.0.40.7(18.20.2)    
123300    Content-Length: 0    
123301        
123302        
123303    [2024-06-22 21:25:44] VERBOSE[25303][C-000001a1] pbx.c: Executing [s@from-pstn:1] NoOp("PJSIP/2001-00000207", "No DID or CID Match") in new stack    
123304    [2024-06-22 21:25:44] VERBOSE[25303][C-000001a1] pbx.c: Executing [s@from-pstn:2] Answer("PJSIP/2001-00000207", "") in new stack    
123305    [2024-06-22 21:25:44] VERBOSE[9578] res_pjsip_logger.c: <--- Transmitting SIP response (1065 bytes) to UDP:XXX.XXX.XXX.XXX:5060 --->
123306    SIP/2.0 200 OK    
123307    Via: SIP/2.0/UDP XXX.XXX.XXX.XXX:5060;rport=5060;received=XXX.XXX.XXX.XXX;branch=z9hG4bKPj433d6227-c6ce-4fb9-8c79-e724492d6510    
123308    Call-ID: 560e1e13-ec07-4644-9408-f81e93559786    
123309    From: "+31XXXXXXXXX" <sip:[email protected]>;tag=cfe3d9d9-6ac3-455e-9bcb-b988fd403e34    
123310    To: <sip:[email protected];line=stzijaa>;tag=6a1bf753-efe1-4deb-9010-164bd3b2592d    
123311    CSeq: 20452 INVITE    
123312    Server: FPBX-16.0.40.7(18.20.2)    
123313    Contact: <sip:XXX.XXX.XXX.XXX:5060>    
123314    Allow: OPTIONS, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, MESSAGE, REFER    
123315    Supported: 100rel, timer, replaces, norefersub    
123316    Session-Expires: 1800;refresher=uac    
123317    Require: timer    
123318    Content-Type: application/sdp    
123319    Content-Length: 341    
123320        
123321    v=0    
123322    o=- 674850139 674850141 IN IP4 XXX.XXX.XXX.XXX    
123323    s=Asterisk    
123324    c=IN IP4 XXX.XXX.XXX.XXX    
123325    t=0 0    
123326    m=audio 16508 RTP/AVP 0 8 3 111 9 101    
123327    a=rtpmap:0 PCMU/8000    
123328    a=rtpmap:8 PCMA/8000    
123329    a=rtpmap:3 GSM/8000    
123330    a=rtpmap:111 G726-32/8000    
123331    a=rtpmap:9 G722/8000    
123332    a=rtpmap:101 telephone-event/8000    
123333    a=fmtp:101 0-16    
123334    a=ptime:20    
123335    a=maxptime:150    
123336    a=sendrecv    
123337        
123338    [2024-06-22 21:25:45] VERBOSE[25376] res_pjsip_logger.c: <--- Received SIP request (452 bytes) from UDP:XXX.XXX.XXX.XXX:5060 --->
123339    ACK sip:XXX.XXX.XXX.XXX:5060 SIP/2.0    
123340    Via: SIP/2.0/UDP XXX.XXX.XXX.XXX:5060;rport;branch=z9hG4bKPjf57f9222-23a9-4587-b8ec-9152945c95a0    
123341    From: "+31XXXXXXXXX" <sip:[email protected]>;tag=cfe3d9d9-6ac3-455e-9bcb-b988fd403e34    
123342    To: <sip:[email protected];line=stzijaa>;tag=6a1bf753-efe1-4deb-9010-164bd3b2592d    
123343    Call-ID: 560e1e13-ec07-4644-9408-f81e93559786    
123344    CSeq: 20452 ACK    
123345    Max-Forwards: 70    
123346    User-Agent: FPBX-16.0.40.8(19.8.0)    
123347    Content-Length: 0    
123348        
123349        
123350    [2024-06-22 21:25:45] ERROR[25303][C-000001a1] pbx_functions.c: Function SIP_HEADER not registered    
123351    [2024-06-22 21:25:45] VERBOSE[25303][C-000001a1] pbx.c: Executing [s@from-pstn:3] Log("PJSIP/2001-00000207", "WARNING,Friendly Scanner from ") in new stack    
123352    [2024-06-22 21:25:45] WARNING[25303][C-000001a1] Ext. s: Friendly Scanner from    
123353    [2024-06-22 21:25:45] VERBOSE[25303][C-000001a1] pbx.c: Executing [s@from-pstn:4] Wait("PJSIP/2001-00000207", "2") in new stack    
123354    [2024-06-22 21:25:47] VERBOSE[25303][C-000001a1] pbx.c: Executing [s@from-pstn:5] Playback("PJSIP/2001-00000207", "ss-noservice") in new stack    
123355    [2024-06-22 21:25:47] VERBOSE[25303][C-000001a1] file.c: <PJSIP/2001-00000207> Playing 'ss-noservice.ulaw' (language 'nl')    
123356    [2024-06-22 21:25:50] VERBOSE[25376] res_pjsip_logger.c: <--- Received SIP request (476 bytes) from UDP:XXX.XXX.XXX.XXX:5060 --->
123357    BYE sip:XXX.XXX.XXX.XXX:5060 SIP/2.0    
123358    Via: SIP/2.0/UDP XXX.XXX.XXX.XXX:5060;rport;branch=z9hG4bKPj85c3ffc5-1be8-4fe4-9e08-d2e1af27b1a8    
123359    From: "+31XXXXXXXXX" <sip:[email protected]>;tag=cfe3d9d9-6ac3-455e-9bcb-b988fd403e34    
123360    To: <sip:[email protected];line=stzijaa>;tag=6a1bf753-efe1-4deb-9010-164bd3b2592d    
123361    Call-ID: 560e1e13-ec07-4644-9408-f81e93559786    
123362    CSeq: 20453 BYE    
123363    Reason: Q.850;cause=16    
123364    Max-Forwards: 70    
123365    User-Agent: FPBX-16.0.40.8(19.8.0)    
123366    Content-Length: 0    
123367        
123368        
123369    [2024-06-22 21:25:50] VERBOSE[25765] res_pjsip_logger.c: <--- Transmitting SIP response (439 bytes) to UDP:XXX.XXX.XXX.XXX:5060 --->
123370    SIP/2.0 200 OK    
123371    Via: SIP/2.0/UDP XXX.XXX.XXX.XXX:5060;rport=5060;received=XXX.XXX.XXX.XXX;branch=z9hG4bKPj85c3ffc5-1be8-4fe4-9e08-d2e1af27b1a8    
123372    Call-ID: 560e1e13-ec07-4644-9408-f81e93559786    
123373    From: "+31XXXXXXXXX" <sip:[email protected]>;tag=cfe3d9d9-6ac3-455e-9bcb-b988fd403e34    
123374    To: <sip:[email protected];line=stzijaa>;tag=6a1bf753-efe1-4deb-9010-164bd3b2592d    
123375    CSeq: 20453 BYE    
123376    Server: FPBX-16.0.40.7(18.20.2)    
123377    Content-Length: 0    
123378        
123379        
123380    [2024-06-22 21:25:50] VERBOSE[25303][C-000001a1] pbx.c: Spawn extension (from-pstn, s, 5) exited non-zero on 'PJSIP/2001-00000207'    
123381    [2024-06-22 21:25:50] VERBOSE[25303][C-000001a1] pbx.c: Executing [h@from-pstn:1] Macro("PJSIP/2001-00000207", "hangupcall,") in new stack    
123382    [2024-06-22 21:25:50] VERBOSE[25303][C-000001a1] pbx.c: Executing [s@macro-hangupcall:1] Gosub("PJSIP/2001-00000207", "app-missedcall-hangup,s,1()") in new stack    
123383    [2024-06-22 21:25:50] VERBOSE[25303][C-000001a1] pbx.c: Executing [s@app-missedcall-hangup:1] NoOp("PJSIP/2001-00000207", "Callee: s") in new stack    
123384    [2024-06-22 21:25:50] VERBOSE[25303][C-000001a1] pbx.c: Executing [s@app-missedcall-hangup:2] NoOp("PJSIP/2001-00000207", "Caller: ") in new stack    
123385    [2024-06-22 21:25:50] VERBOSE[25303][C-000001a1] pbx.c: Executing [s@app-missedcall-hangup:3] AGI("PJSIP/2001-00000207", "agi://127.0.0.1/missedcallnotify.php,,,s,0,,PJSIP/2001-00000207,,") in new stack    
123386    [2024-06-22 21:25:50] VERBOSE[25303][C-000001a1] res_agi.c: agi://127.0.0.1/missedcallnotify.php,,,s,0,,PJSIP/2001-00000207,,: As a minimum this script requires extension or 's' as argument    
123387    [2024-06-22 21:25:50] VERBOSE[25303][C-000001a1] res_agi.c: <PJSIP/2001-00000207>AGI Script agi://127.0.0.1/missedcallnotify.php completed, returning 0    
123388    [2024-06-22 21:25:50] VERBOSE[25303][C-000001a1] pbx.c: Executing [s@app-missedcall-hangup:4] Return("PJSIP/2001-00000207", "") in new stack    
123389    [2024-06-22 21:25:50] VERBOSE[25303][C-000001a1] pbx.c: Executing [s@macro-hangupcall:2] GotoIf("PJSIP/2001-00000207", "1?theend") in new stack    
123390    [2024-06-22 21:25:50] VERBOSE[25303][C-000001a1] pbx_builtins.c: Goto (macro-hangupcall,s,4)    
123391    [2024-06-22 21:25:50] VERBOSE[25303][C-000001a1] pbx.c: Executing [s@macro-hangupcall:4] ExecIf("PJSIP/2001-00000207", "0?Set(CDR(recordingfile)=)") in new stack    
123392    [2024-06-22 21:25:50] VERBOSE[25303][C-000001a1] pbx.c: Executing [s@macro-hangupcall:5] Hangup("PJSIP/2001-00000207", "") in new stack    
123393    [2024-06-22 21:25:50] VERBOSE[25303][C-000001a1] app_macro.c: Spawn extension (macro-hangupcall, s, 5) exited non-zero on 'PJSIP/2001-00000207' in macro 'hangupcall'    
123394    [2024-06-22 21:25:50] VERBOSE[25303][C-000001a1] pbx.c: Spawn extension (from-pstn, h, 1) exited non-zero on 'PJSIP/2001-00000207'    
123395    [2024-06-22 21:26:01] VERBOSE[25376] res_pjsip_logger.c: <--- Received SIP request (453 bytes) from UDP:XXX.XXX.XXX.XXX:5060 --->


Questions:

  1. Is there a specific way to set and retain the __FROM_DID variable across different contexts or subroutines in FreePBX?
  2. Are there any common pitfalls or best practices when dealing with the __FROM_DID variable that I should be aware of?
  3. Could there be an issue with the way my inbound routes or trunks are configured that might be affecting the __FROM_DID variable?
  4. Is there a recommended method for debugging variable assignments and scope issues in FreePBX/Asterisk?

Any insights or guidance to help resolve this issue would be greatly appreciated.

This is supposed to be without the leading underscores: ${FROM_DID}

Finally, most of what you are doing in the custom dialplan is doable using the GUI or some out of the box context that already exists within FreePBX.

Thank you for the quick response, @PitzKey

You are right about the leading underscores; I have made the adjustment and now see the value correctly in the NoOp. However, despite this adjustment, I am still not seeing the DID on PBX2. PBX1 should be sending this (PBX1 is the main PBX).

Here is my adjusted dialplan:

[from-pstn-e164-europe]
exten => _.,1,NoOp(Attempting to extract DID from SIP To header)
exten => _.,n,GotoIf($["${CHANNEL(channeltype)}"="SIP"]?handle-sip)
exten => _.,n,GotoIf($["${CHANNEL(channeltype)}"="PJSIP"]?handle-pjsip)
exten => _.,n,NoOp(Unable to determine SIP channel type)
exten => _.,n,Goto(from-pstn,${EXTEN},1)

exten => _.,n(handle-sip),NoOp(SIP To Header: ${SIP_HEADER(To)})
exten => _.,n,Set(DID=${CUT(CUT(SIP_HEADER(To),@,1),:,2)})
exten => _.,n,NoOp(Extracted DID: ${DID})
exten => _.,n,Goto(did-processing,${DID},1)

exten => _.,n(handle-pjsip),NoOp(PJSIP To Header: ${PJSIP_HEADER(read,To)})
exten => _.,n,Set(DID=${CUT(CUT(PJSIP_HEADER(read,To),@,1),:,2)})
exten => _.,n,NoOp(Extracted DID: ${DID})
exten => _.,n,Goto(did-processing,${DID},1)

[did-processing]
exten => _X.,1,NoOp(Processing DID: ${EXTEN})
exten => _X.,n,Set(FROM_DID=${EXTEN})
exten => _X.,n,NoOp(FROM_DID set to: ${FROM_DID})

; Additional debugging
exten => _X.,n,NoOp(Debug: Checking FROM_DID in did-processing: ${FROM_DID})
exten => _X.,n,NoOp(Debug: CallerID: ${CALLERID(all)})

; Set P-Asserted-Identity and From headers
exten => _X.,n,Set(PJSIP_HEADER(add,P-Asserted-Identity)=sip:${FROM_DID}@${SIPDOMAIN})
exten => _X.,n,NoOp(P-Asserted-Identity set to: ${PJSIP_HEADER(read,P-Asserted-Identity)})
exten => _X.,n,Set(PJSIP_HEADER(add,From)=<sip:${CALLERID(num)}@${SIPDOMAIN}>)
exten => _X.,n,NoOp(From set to: ${PJSIP_HEADER(read,From)})

; Continue with regular processing
exten => _X.,n,GotoIf($["${EXTEN:0:1}" = "+"]?remove-plus)
exten => _X.,n,Goto(from-pstn,${EXTEN},1)

exten => _X.,n(remove-plus),Set(DID=${EXTEN:1})
exten => _X.,n,NoOp(Removed plus: ${DID})
exten => _X.,n,Goto(from-pstn,${DID},1)

[E164-Other]
exten => _X.,1,NoOp(Routing E164 Other DID: ${EXTEN})
exten => _X.,n,NoOp(FROM_DID set to: ${FROM_DID} in E164-Other)
exten => _X.,n,Set(FROM_DID=${EXTEN})
exten => _X.,n,NoOp(Debug: Checking FROM_DID in E164-Other: ${FROM_DID})
exten => _X.,n,Goto(from-pstn,${EXTEN},1)

[macro-dialout-trunk-predial-hook]
exten => s,1,NoOp(Entering user defined context [macro-dialout-trunk-predial-hook] in extensions_custom.conf)
exten => s,n,NoOp(Adding P-Asserted-Identity and From Headers)
exten => s,n,Set(DOMAIN=${SIPDOMAIN})
exten => s,n,Set(PJSIP_HEADER(add,P-Asserted-Identity)=sip:${CALLERID(num)}@${DOMAIN})
exten => s,n,NoOp(P-Asserted-Identity set to: ${PJSIP_HEADER(read,P-Asserted-Identity)})
exten => s,n,Set(HASH(__SIPHEADERS,P-Asserted-Identity)=${CALLERID(num)}@${DOMAIN})
exten => s,n,Set(PJSIP_HEADER(add,From)=${CALLERID(num)}@${DOMAIN})
exten => s,n,NoOp(From set to: ${PJSIP_HEADER(read,From)})
exten => s,n,MacroExit()

[macro-outbound-callerid]
exten => s,1,NoOp(Custom Macro-Outbound-CallerID)
exten => s,n,NoOp(Current CallerID Name: ${CALLERID(name)})
exten => s,n,NoOp(Current CallerID Number: ${CALLERID(num)})
exten => s,n,Set(CALLERID(all)=${CALLERID(name)} <${CALLERID(num)}>)
exten => s,n,NoOp(CallerID set to: ${CALLERID(all)})
exten => s,n,MacroExit()

Here is the anonymized log from PBX1 processing the DID:

Log PBX1
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx.c: Executing [s@from-pstn-e164-europe:2] GotoIf("PJSIP/VoipProvider-00000186", "0?handle-sip") in new stack
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx.c: Executing [s@from-pstn-e164-europe:3] GotoIf("PJSIP/VoipProvider-00000186", "1?handle-pjsip") in new stack
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx_builtins.c: Goto (from-pstn-e164-europe,s,10)
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx.c: Executing [s@from-pstn-e164-europe:10] NoOp("PJSIP/VoipProvider-00000186", "PJSIP To Header: <sip:[email protected]>") in new stack
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx.c: Executing [s@from-pstn-e164-europe:11] Set("PJSIP/VoipProvider-00000186", "DID=31xxxxxxx56") in new stack
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx.c: Executing [s@from-pstn-e164-europe:12] NoOp("PJSIP/VoipProvider-00000186", "Extracted DID: 31xxxxxxx56") in new stack
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx.c: Executing [s@from-pstn-e164-europe:13] Goto("PJSIP/VoipProvider-00000186", "did-processing,31xxxxxxx56,1") in new stack
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx_builtins.c: Goto (did-processing,31xxxxxxx56,1)
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx.c: Executing [31xxxxxxx56@did-processing:1] NoOp("PJSIP/VoipProvider-00000186", "Processing DID: 31xxxxxxx56") in new stack
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx.c: Executing [31xxxxxxx56@did-processing:2] Set("PJSIP/VoipProvider-00000186", "FROM_DID=31xxxxxxx56") in new stack
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx.c: Executing [31xxxxxxx56@did-processing:3] NoOp("PJSIP/VoipProvider-00000186", "FROM_DID set to: 31xxxxxxx56") in new stack
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx.c: Executing [31xxxxxxx56@did-processing:4] NoOp("PJSIP/VoipProvider-00000186", "Debug: Checking FROM_DID in did-processing: 31xxxxxxx56") in new stack
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx.c: Executing [31xxxxxxx56@did-processing:5] NoOp("PJSIP/VoipProvider-00000186", "Debug: CallerID: "+316xxxxxx77" <316xxxxxx77>") in new stack
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx.c: Executing [31xxxxxxx56@did-processing:6] Set("PJSIP/VoipProvider-00000186", "PJSIP_HEADER(add,P-Asserted-Identity)=sip:[email protected]") in new stack
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx.c: Executing [31xxxxxxx56@did-processing:7] NoOp("PJSIP/VoipProvider-00000186", "P-Asserted-Identity set to: +316xxxxxx77 <sip:[email protected]>") in new stack
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx.c: Executing [31xxxxxxx56@did-processing:8] Set("PJSIP/VoipProvider-00000186", "PJSIP_HEADER(add,From)=<sip:[email protected]>") in new stack
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx.c: Executing [31xxxxxxx56@did-processing:9] NoOp("PJSIP/VoipProvider-00000186", "From set to: "+316xxxxxx77" <sip:[email protected]>;tag=yzus4q1.o") in new stack
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx.c: Executing [31xxxxxxx56@did-processing:10] GotoIf("PJSIP/VoipProvider-00000186", "0?remove-plus") in new stack
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx.c: Executing [31xxxxxxx56@did-processing:11] Goto("PJSIP/VoipProvider-00000186", "from-pstn,31xxxxxxx56,1") in new stack
[2024-06-23 10:41:03] VERBOSE[6590][C-000000c9] pbx_builtins.c: Goto (from-pstn,31xxxxxxx56,1)

Here is a portion of the logging from PBX2 (anonymized):

Log BPX2
[2024-06-23 08:44:00] VERBOSE[25376] res_pjsip_logger.c: <--- Received SIP request (451 bytes) from UDP:xx.xxx.xxx.xxx:5060 --->
ACK sip:xx.xxx.xxx.xxx:5060 SIP/2.0
Via: SIP/2.0/UDP xx.xxx.xxx.xxx:5060;rport;branch=z9hG4bKPjb812926b-af34-4129-a95c-29737b1f74d9
From: "+31xxxxxx977" <sip:[email protected]>;tag=42d004ce-304b-490d-88b4-b6c8e9fd1c2a
To: <sip:[email protected];line=stzijaa>;tag=1c2744b9-f200-4a91-8f09-a6c307780819
Call-ID: 746c5514-5291-46a7-bf56-947c19b4e908
CSeq: 2399 ACK
Max-Forwards: 70
User-Agent: FPBX-16.0.40.8(19.8.0)
Content-Length: 0

[2024-06-23 08:44:00] ERROR[29913][C-000001a5] pbx_functions.c: Function SIP_HEADER not registered
[2024-06-23 08:44:00] VERBOSE[29913][C-000001a5] pbx.c: Executing [s@from-pstn:3] Log("PJSIP/2001-0000020b", "WARNING,Friendly Scanner from ") in new stack
[2024-06-23 08:44:00] WARNING[29913][C-000001a5] Ext. s: Friendly Scanner from
[2024-06-23 08:44:00] VERBOSE[29913][C-000001a5] pbx.c: Executing [s@from-pstn:4] Wait("PJSIP/2001-0000020b", "2") in new stack
[2024-06-23 08:44:01] VERBOSE[25376] res_pjsip_logger.c: <--- Received SIP request (453 bytes) from UDP:xx.xxx.xxx.xxx:5060 --->
OPTIONS sip:[email protected]:5060;line=stzijaa SIP/2.0
Via: SIP/2.0/UDP xx.xxx.xxx.xxx:5060;rport;branch=z9hG4bKPjf674e244-f3cb-42cf-b6ea-558249881dc7
From: <sip:[email protected]>;tag=03b6ee68-d73c-40ef-985a-25fdf19571a8
To: <sip:[email protected];line=stzijaa>
Contact: <sip:[email protected]:5060>
Call-ID: 3385c803-482b-4d84-a31e-19bfde99e5b3
CSeq: 62065 OPTIONS
Max-Forwards: 70
User-Agent: FPBX-16.0.40.8(19.8.0)
Content-Length: 0

[2024-06-23 08:44:01] VERBOSE[16247] res_pjsip_logger.c: <--- Transmitting SIP response (915 bytes) to UDP:xx.xxx.xxx.xxx:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP xx.xxx.xxx.xxx:5060;rport=5060;received=xx.xxx.xxx.xxx;branch=z9hG4bKPjf674e244-f3cb-42cf-b6ea-558249881dc7
Call-ID: 3385c803-482b-4d84-a31e-19bfde99e5b3
From: <sip:[email protected]>;tag=03b6ee68-d73c-40ef-985a-25fdf19571a8
To: <sip:[email protected];line=stzijaa>;tag=z9hG4bKPjf674e244-f3cb-42cf-b6ea-558249881dc7
CSeq: 62065 OPTIONS
Accept: application/sdp, application/simple-message-summary, application/dialog-info+xml, application/xpidf+xml, application/cpim-pidf+xml, application/pidf+xml, application/pidf+xml, application/dialog-info+xml, application/simple-message-summary, message/sipfrag;version=2.0
Allow: OPTIONS, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, MESSAGE, REFER
Supported: 100rel, timer, replaces, norefersub
Accept-Encoding: identity
Accept-Language: en
Server: FPBX-16.0.40.7(18.20.2)
Content-Length: 0

[2024-06-23 08:44:02] VERBOSE[29913][C-000001a5] pbx.c: Executing [s@from-pstn:5] Playback("PJSIP/2001-0000020b", "ss-noservice") in new stack
[2024-06-23 08:44:02] VERBOSE[29913][C-000001a5] file.c: <PJSIP/2001-0000020b> Playing 'ss-noservice.ulaw' (language 'nl')
[2024-06-23 08:44:05] VERBOSE[25376] res_pjsip_logger.c: <--- Received SIP request (475 bytes) from UDP:xx.xxx.xxx.xxx:5060 --->
BYE sip:xx.xxx.xxx.xxx:5060 SIP/2.0
Via: SIP/2.0/UDP xx.xxx.xxx.xxx:5060;rport;branch=z9hG4bKPjb0f60df1-f352-4075-80c5-c748f85fc35f
From: "+31xxxxxx977" <sip:[email protected]>;tag=42d004ce-304b-490d-88b4-b6c8e9fd1c2a
To: <sip:[email protected];line=stzijaa>;tag=1c2744b9-f200-4a91-8f09-a6c307780819
Call-ID: 746c5514-5291-46a7-bf56-947c19b4e908
CSeq: 2400 BYE
Reason: Q.850;cause=16
Max-Forwards: 70
User-Agent: FPBX-16.0.40.8(19.8.0)
Content-Length: 0

[2024-06-23 08:44:05] VERBOSE[25765] res_pjsip_logger.c: <--- Transmitting SIP response (438 bytes) to UDP:xx.xxx.xxx.xxx:5060 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP xx.xxx.xxx.xxx:5060;rport=5060;received=xx.xxx.xxx.xxx;branch=z9hG4bKPjb0f60df1-f352-4075-80c5-c748f85fc35f
Call-ID: 746c5514-5291-46a7-bf56-947c19b4e908
From: "+31xxxxxx977" <sip:[email protected]>;tag=42d004ce-304b-490d-88b4-b6c8e9fd1c2a
To: <sip:[email protected];line=stzijaa>;tag=1c2744b9-f200-4a91-8f09-a6c307780819
CSeq: 2400 BYE
Server: FPBX-16.0.40.7(18.20.2)
Content-Length: 0

[2024-06-23 08:44:05] VERBOSE[29913][C-000001a5] pbx.c: Spawn extension (from-pstn, s, 5) exited non-zero on 'PJSIP/2001-0000020b'
[2024-06-23 08:44:05] VERBOSE[29913][C-000001a5] pbx.c: Executing [h@from-pstn:1] Macro("PJSIP/2001-0000020b", "hangupcall,") in new stack
[2024-06-23 08:44:05] VERBOSE[29913][C-000001a5] pbx.c: Executing [s@macro-hangupcall:1] Gosub("PJSIP/2001-0000020b", "app-missedcall-hangup,s,1()") in new stack

...

I understand that much of what I’m trying to do can be configured via the GUI or using existing contexts within FreePBX like from-pstn-toheader. However, I noticed that the default FreePBX rules were not correctly forwarding the DID to the extension, which is why I attempted a custom rule.

I think that something is wrong with the “To” header when I try to route the call to extension 2001, because I don’t see any DID information in the log of PBX2.

Assuming the system was previously working, changing the Context for the trunk to from-pstn-toheader should take care of that. If the old provider sent the destination number starting with 31 and the new sends +31, you could make a custom version of from-pstn-toheader that removes the +.

Not surprising, each Inbound Route normally sets __FROM_DID, so it overwrites whatever you put there.

This is somewhat strange; normally you would set up each end as a trunk, though I have seen setups using an extension at the central end. This is typically when the branch system is residential or a very small business, because on incoming there is only one “DID” (the extension number) and on outgoing there is no control over caller ID. You could work around this using P-Asserted-Identity or similar, but why did you choose this architecture?

However, if you had it working, I don’t see why using from-pstn-toheader or similar should have broken it. There is little info in your PBX1 log, because it ends at Goto from-pstn. Does the log show a call to extension 2001? And I’d expect the INVITE sent to PBX2 to have INVITE sip:[email protected], which (based on the ACK sent) it apparently didn’t.

Thx for your reply @Stewart1

For convenience, I discarded my dial plan except for the [macro-dialout-trunk-predial-hook], which I need for outbound traffic to my new provider. This allows us to dynamically provide the number we want to use for outgoing calls (at the extension level) in the P-Asserted-Identity and FROM header to the provider.

I have always had one main PBX that is connected to the provider with a trunk, and from this PBX, I distribute the connections. I don’t have multiple trunks on all PBXs purely due to the high costs, as I unfortunately pay €180 per trunk. This does include unlimited calling on six channels within my country. By sharing the trunk from my main PBX, I save costs, as I have a total of four other PBXs running where the main PBX provides an extension, set up as a PJSIP trunk on the other PBXs.

With the from-pstn-toheader context, incoming traffic works as it did with my custom configuration. It recognizes the DID and routes it to the correct inbound route settings. However, I see in the log of PBX2 that the call is not processed successfully. Below, you will find the complete log from both PBX1 and PBX2 with a test call.

Log Test call - PBX1 (main)
pbx.c: Executing [s@from-pstn-toheader:1] NoOp("PJSIP/Provider-000001a4", "Attempting to extract DID from SIP To header") in new stack	
pbx.c: Executing [s@from-pstn-toheader:2] GotoIf("PJSIP/Provider-000001a4", "0?SIP") in new stack	
pbx.c: Executing [s@from-pstn-toheader:3] GotoIf("PJSIP/Provider-000001a4", "1?PJSIP") in new stack	
pbx_builtins.c: Goto (from-pstn-toheader,s,7)	
pbx.c: Executing [s@from-pstn-toheader:7] Goto("PJSIP/Provider-000001a4", "from-pstn,31xxxxxxx56,1") in new stack	
pbx_builtins.c: Goto (from-pstn,31xxxxxxx56,1)	
pbx.c: Executing [31xxxxxxx56@from-pstn:1] Set("PJSIP/Provider-000001a4", "__DIRECTION=INBOUND") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:2] Gosub("PJSIP/Provider-000001a4", "sub-record-check,s,1(in,31xxxxxxx56,dontcare)") in new stack	
pbx.c: Executing [s@sub-record-check:1] GotoIf("PJSIP/Provider-000001a4", "0?initialized") in new stack	
pbx.c: Executing [s@sub-record-check:2] Set("PJSIP/Provider-000001a4", "__REC_STATUS=INITIALIZED") in new stack	
pbx.c: Executing [s@sub-record-check:3] Set("PJSIP/Provider-000001a4", "NOW=1719155479") in new stack	
pbx.c: Executing [s@sub-record-check:4] Set("PJSIP/Provider-000001a4", "__DAY=23") in new stack	
pbx.c: Executing [s@sub-record-check:5] Set("PJSIP/Provider-000001a4", "__MONTH=06") in new stack	
pbx.c: Executing [s@sub-record-check:6] Set("PJSIP/Provider-000001a4", "__YEAR=2024") in new stack	
pbx.c: Executing [s@sub-record-check:7] Set("PJSIP/Provider-000001a4", "__TIMESTR=20240623-171119") in new stack	
pbx.c: Executing [s@sub-record-check:8] Set("PJSIP/Provider-000001a4", "__FROMEXTEN=unknown") in new stack	
pbx.c: Executing [s@sub-record-check:9] Set("PJSIP/Provider-000001a4", "__MON_FMT=wav") in new stack	
pbx.c: Executing [s@sub-record-check:10] NoOp("PJSIP/Provider-000001a4", "Recordings initialized") in new stack	
pbx.c: Executing [s@sub-record-check:11] ExecIf("PJSIP/Provider-000001a4", "0?Set(ARG3=dontcare)") in new stack	
pbx.c: Executing [s@sub-record-check:12] Set("PJSIP/Provider-000001a4", "REC_POLICY_MODE_SAVE=") in new stack	
pbx.c: Executing [s@sub-record-check:13] ExecIf("PJSIP/Provider-000001a4", "0?Set(REC_STATUS=NO)") in new stack	
pbx.c: Executing [s@sub-record-check:14] GotoIf("PJSIP/Provider-000001a4", "2?checkaction") in new stack	
pbx_builtins.c: Goto (sub-record-check,s,17)	
pbx.c: Executing [s@sub-record-check:17] GotoIf("PJSIP/Provider-000001a4", "1?sub-record-check,in,1") in new stack	
pbx_builtins.c: Goto (sub-record-check,in,1)	
pbx.c: Executing [in@sub-record-check:1] NoOp("PJSIP/Provider-000001a4", "Inbound Recording Check to 31xxxxxxx56") in new stack	
pbx.c: Executing [in@sub-record-check:2] Set("PJSIP/Provider-000001a4", "FROMEXTEN=unknown") in new stack	
pbx.c: Executing [in@sub-record-check:3] ExecIf("PJSIP/Provider-000001a4", "11?Set(FROMEXTEN=3168xxxx977)") in new stack	
pbx.c: Executing [in@sub-record-check:4] Gosub("PJSIP/Provider-000001a4", "recordcheck,1(dontcare,in,31xxxxxxx56)") in new stack	
pbx.c: Executing [recordcheck@sub-record-check:1] NoOp("PJSIP/Provider-000001a4", "Starting recording check against dontcare") in new stack	
pbx.c: Executing [recordcheck@sub-record-check:2] Goto("PJSIP/Provider-000001a4", "dontcare") in new stack	
pbx_builtins.c: Goto (sub-record-check,recordcheck,3)	
pbx.c: Executing [recordcheck@sub-record-check:3] Return("PJSIP/Provider-000001a4", "") in new stack	
pbx.c: Executing [in@sub-record-check:5] Return("PJSIP/Provider-000001a4", "") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:3] Set("PJSIP/Provider-000001a4", "CHANNEL(tonezone)=us") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:4] Set("PJSIP/Provider-000001a4", "__FROM_DID=31xxxxxxx56") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:5] Set("PJSIP/Provider-000001a4", "returnhere=1") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:6] Gosub("PJSIP/Provider-000001a4", "app-blacklist-check,s,1()") in new stack	
pbx.c: Executing [s@app-blacklist-check:1] GotoIf("PJSIP/Provider-000001a4", "0?blacklisted") in new stack	
pbx.c: Executing [s@app-blacklist-check:2] Set("PJSIP/Provider-000001a4", "CALLED_BLACKLIST=1") in new stack	
pbx.c: Executing [s@app-blacklist-check:3] Return("PJSIP/Provider-000001a4", "") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:7] Set("PJSIP/Provider-000001a4", "CDR(did)=31xxxxxxx56") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:8] GotoIf("PJSIP/Provider-000001a4", "0?") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:9] ExecIf("PJSIP/Provider-000001a4", "0 ?Set(CALLERID(name)=3168xxxx977)") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:10] Set("PJSIP/Provider-000001a4", "__MOHCLASS=") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:11] Set("PJSIP/Provider-000001a4", "__REVERSAL_REJECT=FALSE") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:12] GotoIf("PJSIP/Provider-000001a4", "1?post-reverse-charge") in new stack	
pbx_builtins.c: Goto (from-pstn,31xxxxxxx56,14)	
pbx.c: Executing [31xxxxxxx56@from-pstn:14] NoOp("PJSIP/Provider-000001a4", "") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:15] Set("PJSIP/Provider-000001a4", "__CALLINGNAMEPRES_SV=allowed_not_screened") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:16] Set("PJSIP/Provider-000001a4", "__CALLINGNUMPRES_SV=allowed_not_screened") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:17] Set("PJSIP/Provider-000001a4", "CALLERID(name-pres)=allowed_not_screened") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:18] Set("PJSIP/Provider-000001a4", "CALLERID(num-pres)=allowed_not_screened") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:19] NoOp("PJSIP/Provider-000001a4", "CallerID Entry Point") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:20] Set("PJSIP/Provider-000001a4", "__CRM_DIRECTION=INBOUND") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:21] Set("PJSIP/Provider-000001a4", "__CRM_SOURCE=3168xxxx977") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:22] Set("PJSIP/Provider-000001a4", "__CRM_LINKEDID=1719155479.420") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:23] AGI("PJSIP/Provider-000001a4", "agi://127.0.0.1/sangomacrm.agi,true") in new stack	
res_agi.c: <PJSIP/Provider-000001a4>AGI Script agi://127.0.0.1/sangomacrm.agi completed, returning 0	
pbx.c: Executing [31xxxxxxx56@from-pstn:24] ExecIf("PJSIP/Provider-000001a4", "1?Set(CHANNEL(hangup_handler_push)=crm-hangup,s,1)") in new stack	
pbx.c: Executing [31xxxxxxx56@from-pstn:25] Goto("PJSIP/Provider-000001a4", "from-did-direct,2001,1") in new stack	
pbx_builtins.c: Goto (from-did-direct,2001,1)	
pbx.c: Executing [2001@from-did-direct:1] GotoIf("PJSIP/Provider-000001a4", "0?ext-local,*2001,1") in new stack	
pbx.c: Executing [2001@from-did-direct:2] GotoIf("PJSIP/Provider-000001a4", "1?ext-local,2001,1:followme-check,2001,1") in new stack	
pbx_builtins.c: Goto (ext-local,2001,1)	
pbx.c: Executing [2001@ext-local:1] Set("PJSIP/Provider-000001a4", "__RINGTIMER=15") in new stack	
pbx.c: Executing [2001@ext-local:2] ExecIf("PJSIP/Provider-000001a4", "0?Set(__CWIGNORE=)") in new stack	
pbx.c: Executing [2001@ext-local:3] Macro("PJSIP/Provider-000001a4", "exten-vm,novm,2001,0,0,0") in new stack	
pbx.c: Executing [s@macro-exten-vm:1] Macro("PJSIP/Provider-000001a4", "user-callerid,") in new stack	
pbx.c: Executing [s@macro-user-callerid:1] Set("PJSIP/Provider-000001a4", "TOUCH_MONITOR=1719155479.420") in new stack	
pbx.c: Executing [s@macro-user-callerid:2] Set("PJSIP/Provider-000001a4", "CHANCONTEXT=") in new stack	
pbx.c: Executing [s@macro-user-callerid:3] Progress("PJSIP/Provider-000001a4", "") in new stack	
pbx.c: Executing [s@macro-user-callerid:4] Set("PJSIP/Provider-000001a4", "CHANCONTEXT=") in new stack	
pbx.c: Executing [s@macro-user-callerid:5] Set("PJSIP/Provider-000001a4", "CHANEXTENCONTEXT=Provider-000001a4") in new stack	
pbx.c: Executing [s@macro-user-callerid:6] Set("PJSIP/Provider-000001a4", "CHANEXTEN=Provider-000001a4") in new stack	
pbx.c: Executing [s@macro-user-callerid:7] Set("PJSIP/Provider-000001a4", "CALLERID(number)=3168xxxx977") in new stack	
pbx.c: Executing [s@macro-user-callerid:8] Set("PJSIP/Provider-000001a4", "AMPUSER=3168xxxx977") in new stack	
pbx.c: Executing [s@macro-user-callerid:9] Set("PJSIP/Provider-000001a4", "HOTDESCKCHAN=Provider-000001a4") in new stack	
pbx.c: Executing [s@macro-user-callerid:10] Set("PJSIP/Provider-000001a4", "HOTDESKEXTEN=Provider") in new stack	
pbx.c: Executing [s@macro-user-callerid:11] Set("PJSIP/Provider-000001a4", "HOTDESKCALL=0") in new stack	
pbx.c: Executing [s@macro-user-callerid:12] ExecIf("PJSIP/Provider-000001a4", "0?Set(HOTDESKCALL=1)") in new stack	
pbx.c: Executing [s@macro-user-callerid:13] ExecIf("PJSIP/Provider-000001a4", "0?Set(CALLERID(name)=)") in new stack	
pbx.c: Executing [s@macro-user-callerid:14] GotoIf("PJSIP/Provider-000001a4", "0?report") in new stack	
pbx.c: Executing [s@macro-user-callerid:15] ExecIf("PJSIP/Provider-000001a4", "1?Set(REALCALLERIDNUM=3168xxxx977)") in new stack	
pbx.c: Executing [s@macro-user-callerid:16] Set("PJSIP/Provider-000001a4", "AMPUSER=") in new stack	
pbx.c: Executing [s@macro-user-callerid:17] GotoIf("PJSIP/Provider-000001a4", "0?limit") in new stack	
pbx.c: Executing [s@macro-user-callerid:18] Set("PJSIP/Provider-000001a4", "AMPUSERCIDNAME=") in new stack	
pbx.c: Executing [s@macro-user-callerid:19] ExecIf("PJSIP/Provider-000001a4", "0?Set(__CIDMASQUERADING=TRUE)") in new stack	
pbx.c: Executing [s@macro-user-callerid:20] GotoIf("PJSIP/Provider-000001a4", "1?report") in new stack	
pbx_builtins.c: Goto (macro-user-callerid,s,29)	
pbx.c: Executing [s@macro-user-callerid:29] NoOp("PJSIP/Provider-000001a4", "Macro Depth is 2") in new stack	
pbx.c: Executing [s@macro-user-callerid:30] GotoIf("PJSIP/Provider-000001a4", "1?report2:macroerror") in new stack	
pbx_builtins.c: Goto (macro-user-callerid,s,31)	
pbx.c: Executing [s@macro-user-callerid:31] GotoIf("PJSIP/Provider-000001a4", "0?continue") in new stack	
pbx.c: Executing [s@macro-user-callerid:32] ExecIf("PJSIP/Provider-000001a4", "1?Set(__CALLEE_ACCOUNCODE=)") in new stack	
pbx.c: Executing [s@macro-user-callerid:33] Set("PJSIP/Provider-000001a4", "__TTL=64") in new stack	
pbx.c: Executing [s@macro-user-callerid:34] GotoIf("PJSIP/Provider-000001a4", "1?continue") in new stack	
pbx_builtins.c: Goto (macro-user-callerid,s,50)	
pbx.c: Executing [s@macro-user-callerid:50] Set("PJSIP/Provider-000001a4", "CALLERID(number)=3168xxxx977") in new stack	
pbx.c: Executing [s@macro-user-callerid:51] Set("PJSIP/Provider-000001a4", "CALLERID(name)=+3168xxxx977") in new stack	
pbx.c: Executing [s@macro-user-callerid:52] GotoIf("PJSIP/Provider-000001a4", "0?cnum") in new stack	
pbx.c: Executing [s@macro-user-callerid:53] Set("PJSIP/Provider-000001a4", "__MCNUM=3168xxxx977") in new stack	
pbx.c: Executing [s@macro-user-callerid:54] Set("PJSIP/Provider-000001a4", "__MCNAME=+3168xxxx977") in new stack	
pbx.c: Executing [s@macro-user-callerid:55] Set("PJSIP/Provider-000001a4", "__MCEXTEN=") in new stack	
pbx.c: Executing [s@macro-user-callerid:56] Set("PJSIP/Provider-000001a4", "__MCORGCHAN=PJSIP/Provider-000001a4") in new stack	
pbx.c: Executing [s@macro-user-callerid:57] Set("PJSIP/Provider-000001a4", "CDR(cnam)=+3168xxxx977") in new stack	
pbx.c: Executing [s@macro-user-callerid:58] Set("PJSIP/Provider-000001a4", "CDR(cnum)=3168xxxx977") in new stack	
pbx.c: Executing [s@macro-user-callerid:59] Set("PJSIP/Provider-000001a4", "CHANNEL(language)=en") in new stack	
pbx.c: Executing [s@macro-exten-vm:2] Set("PJSIP/Provider-000001a4", "RingGroupMethod=none") in new stack	
pbx.c: Executing [s@macro-exten-vm:3] Set("PJSIP/Provider-000001a4", "__EXTTOCALL=2001") in new stack	
pbx.c: Executing [s@macro-exten-vm:4] Set("PJSIP/Provider-000001a4", "__PICKUPMARK=2001") in new stack	
pbx.c: Executing [s@macro-exten-vm:5] Set("PJSIP/Provider-000001a4", "RT=") in new stack	
pbx.c: Executing [s@macro-exten-vm:6] GotoIf("PJSIP/Provider-000001a4", "1?startcheck:exitcheck") in new stack	
pbx_builtins.c: Goto (macro-exten-vm,s,7)	
pbx.c: Executing [s@macro-exten-vm:7] GotoIf("PJSIP/Provider-000001a4", "0?featureSIP:featurePJSIP") in new stack	
pbx_builtins.c: Goto (macro-exten-vm,s,11)	
pbx.c: Executing [s@macro-exten-vm:11] ExecIf("PJSIP/Provider-000001a4", "0?Macro(vm,novm,DIRECTDIAL,)") in new stack	
pbx.c: Executing [s@macro-exten-vm:12] ExecIf("PJSIP/Provider-000001a4", "0?MacroExit()") in new stack	
pbx.c: Executing [s@macro-exten-vm:13] GotoIf("PJSIP/Provider-000001a4", "1?featuremoniPJSIP:featuremoniSIP") in new stack	
pbx_builtins.c: Goto (macro-exten-vm,s,14)	
pbx.c: Executing [s@macro-exten-vm:14] ExecIf("PJSIP/Provider-000001a4", "0?ChanSpy(PJSIP/2001,q)") in new stack	
pbx.c: Executing [s@macro-exten-vm:15] ExecIf("PJSIP/Provider-000001a4", "0?MacroExit()") in new stack	
pbx.c: Executing [s@macro-exten-vm:16] GotoIf("PJSIP/Provider-000001a4", "1?check-ext-intercom:featuremoniSIP") in new stack	
pbx_builtins.c: Goto (macro-exten-vm,s,19)	
pbx.c: Executing [s@macro-exten-vm:19] GotoIf("PJSIP/Provider-000001a4", "0?ext-intercomSIP:ext-intercomPJSIP") in new stack	
pbx_builtins.c: Goto (macro-exten-vm,s,20)	
pbx.c: Executing [s@macro-exten-vm:20] ExecIf("PJSIP/Provider-000001a4", "0?Gosub(ext-intercom,*802001,1())") in new stack	
pbx.c: Executing [s@macro-exten-vm:21] ExecIf("PJSIP/Provider-000001a4", "0?MacroExit()") in new stack	
pbx.c: Executing [s@macro-exten-vm:22] GotoIf("PJSIP/Provider-000001a4", "1?exitcheck:ext-intercomSIP") in new stack	
pbx_builtins.c: Goto (macro-exten-vm,s,25)	
pbx.c: Executing [s@macro-exten-vm:25] NoOp("PJSIP/Provider-000001a4", "Exiting Checks") in new stack	
pbx.c: Executing [s@macro-exten-vm:26] Gosub("PJSIP/Provider-000001a4", "sub-record-check,s,1(exten,2001,dontcare)") in new stack	
pbx.c: Executing [s@sub-record-check:1] GotoIf("PJSIP/Provider-000001a4", "11?initialized") in new stack	
pbx_builtins.c: Goto (sub-record-check,s,10)	
pbx.c: Executing [s@sub-record-check:10] NoOp("PJSIP/Provider-000001a4", "Recordings initialized") in 
pbx.c: Executing [exten@sub-record-check:12] Return("PJSIP/Provider-000001a4", "") in new stack	
pbx.c: Executing [s@macro-exten-vm:27] GotoIf("PJSIP/Provider-000001a4", "1?macrodial") in new stack	
pbx_builtins.c: Goto (macro-exten-vm,s,33)	
pbx.c: Executing [s@macro-exten-vm:33] GosubIf("PJSIP/Provider-000001a4", "0?clrheader,1()") in new stack	
pbx.c: Executing [s@macro-exten-vm:34] Macro("PJSIP/Provider-000001a4", "dial-one,,HhTtr,2001") in new stack	
pbx.c: Executing [s@macro-dial-one:1] Set("PJSIP/Provider-000001a4", "DEXTEN=2001") in new stack	
pbx.c: Executing [s@macro-dial-one:2] Set("PJSIP/Provider-000001a4", "__CRM_SOURCE=3168xxxx977") in new stack	
pbx.c: Executing [s@macro-dial-one:3] Set("PJSIP/Provider-000001a4", "__MCEXTTOCALL=2001") in new stack	
pbx.c: Executing [s@macro-dial-one:4] Set("PJSIP/Provider-000001a4", "__MCMULTI=44e0a94b70c41f7b094725961e39b4ed") in new stack	
pbx.c: Executing [s@macro-dial-one:5] ExecIf("PJSIP/Provider-000001a4", "0?Set(__EXTTOCALL=2001)") in new stack	
pbx.c: Executing [s@macro-dial-one:6] Set("PJSIP/Provider-000001a4", "DIALSTATUS_CW=") in new stack	
pbx.c: Executing [s@macro-dial-one:7] GosubIf("PJSIP/Provider-000001a4", "0?screen,1()") in new stack	
pbx.c: Executing [s@macro-dial-one:8] GosubIf("PJSIP/Provider-000001a4", "0?cf,1()") in new stack	
pbx.c: Executing [s@macro-dial-one:9] GotoIf("PJSIP/Provider-000001a4", "1?skip1") in new stack	
pbx_builtins.c: Goto (macro-dial-one,s,12)	
pbx.c: Executing [s@macro-dial-one:12] GotoIf("PJSIP/Provider-000001a4", "0?nodial") in new stack	
pbx.c: Executing [s@macro-dial-one:13] GotoIf("PJSIP/Provider-000001a4", "0?continue") in new stack	
pbx.c: Executing [s@macro-dial-one:14] Set("PJSIP/Provider-000001a4", "EXTHASCW=ENABLED") in new stack	
pbx.c: Executing [s@macro-dial-one:15] GotoIf("PJSIP/Provider-000001a4", "0?next1:cwinusebusy") in new stack	
pbx_builtins.c: Goto (macro-dial-one,s,27)	
pbx.c: Executing [s@macro-dial-one:27] GotoIf("PJSIP/Provider-000001a4", "0?next3:continue") in new stack	
pbx_builtins.c: Goto (macro-dial-one,s,29)	
pbx.c: Executing [s@macro-dial-one:29] GotoIf("PJSIP/Provider-000001a4", "0?nodial") in new stack	
pbx.c: Executing [s@macro-dial-one:30] GosubIf("PJSIP/Provider-000001a4", "1?dstring,1():dlocal,1()") in new stack	
pbx.c: Executing [dstring@macro-dial-one:1] Set("PJSIP/Provider-000001a4", "DSTRING=") in new stack	
pbx.c: Executing [dstring@macro-dial-one:2] Set("PJSIP/Provider-000001a4", "DEVICES=2001") in new stack	
pbx.c: Executing [dstring@macro-dial-one:3] ExecIf("PJSIP/Provider-000001a4", "0?Return()") in new stack	
pbx.c: Executing [dstring@macro-dial-one:4] ExecIf("PJSIP/Provider-000001a4", "0?Set(DEVICES=001)") in new stack	
pbx.c: Executing [dstring@macro-dial-one:5] Set("PJSIP/Provider-000001a4", "LOOPCNT=1") in new stack	
pbx.c: Executing [dstring@macro-dial-one:6] Set("PJSIP/Provider-000001a4", "ITER=1") in new stack	
pbx.c: Executing [dstring@macro-dial-one:7] Set("PJSIP/Provider-000001a4", "THISDIAL=PJSIP/2001") in new stack	
pbx.c: Executing [dstring@macro-dial-one:8] GotoIf("PJSIP/Provider-000001a4", "0?docheck") in new stack	
pbx.c: Executing [dstring@macro-dial-one:9] NoOp("PJSIP/Provider-000001a4", "Debug: Found PJSIP Destination PJSIP/2001") in new stack	
pbx.c: Executing [dstring@macro-dial-one:10] GotoIf("PJSIP/Provider-000001a4", "0?doset") in new stack	
pbx.c: Executing [dstring@macro-dial-one:11] NoOp("PJSIP/Provider-000001a4", "Debug: Updating PJSIP Destination with PJSIP_DIAL_CONTACTS") in new stack	
pbx.c: Executing [dstring@macro-dial-one:12] Set("PJSIP/Provider-000001a4", "THISDIAL=PJSIP/2001/sip:[email protected]:5060;line=stzijaa") in new stack	
pbx.c: Executing [dstring@macro-dial-one:13] ExecIf("PJSIP/Provider-000001a4", "0?Set(DIALSTATUS=CHANUNAVAIL)") in new stack	
pbx.c: Executing [dstring@macro-dial-one:14] GotoIf("PJSIP/Provider-000001a4", "0?skipset") in new stack	
pbx.c: Executing [dstring@macro-dial-one:15] Set("PJSIP/Provider-000001a4", "DSTRING=PJSIP/2001/sip:[email protected]:5060;line=stzijaa&") in new stack	
pbx.c: Executing [dstring@macro-dial-one:16] Set("PJSIP/Provider-000001a4", "ITER=2") in new stack	
pbx.c: Executing [dstring@macro-dial-one:17] GotoIf("PJSIP/Provider-000001a4", "0?begin") in new stack	
pbx.c: Executing [dstring@macro-dial-one:18] ExecIf("PJSIP/Provider-000001a4", "0?Return()") in new stack	
pbx.c: Executing [dstring@macro-dial-one:19] Set("PJSIP/Provider-000001a4", "DSTRING=PJSIP/2001/sip:[email protected]:5060;line=stzijaa") in new stack	
pbx.c: Executing [dstring@macro-dial-one:20] Return("PJSIP/Provider-000001a4", "") in new stack	
pbx.c: Executing [s@macro-dial-one:31] GotoIf("PJSIP/Provider-000001a4", "0?nodial") in new stack	
pbx.c: Executing [s@macro-dial-one:32] GotoIf("PJSIP/Provider-000001a4", "0?skiptrace") in new stack	
pbx.c: Executing [s@macro-dial-one:33] GosubIf("PJSIP/Provider-000001a4", "1?ctset,1():ctclear,1()") in new stack	
pbx.c: Executing [ctset@macro-dial-one:1] Set("PJSIP/Provider-000001a4", "DB(CALLTRACE/2001)=3168xxxx977") in new stack	
pbx.c: Executing [ctset@macro-dial-one:2] Return("PJSIP/Provider-000001a4", "") in new stack	
pbx.c: Executing [s@macro-dial-one:34] Set("PJSIP/Provider-000001a4", "D_OPTIONS=HhTtr") in new stack	
pbx.c: Executing [s@macro-dial-one:35] GosubIf("PJSIP/Provider-000001a4", "0?func-set-sipheader,s,1(Alert-Info,)") in new stack	
pbx.c: Executing [s@macro-dial-one:36] NoOp("PJSIP/Provider-000001a4", "Blind Transfer: , Attended Transfer: , User: , Alert Info: ") in new stack	
pbx.c: Executing [s@macro-dial-one:37] ExecIf("PJSIP/Provider-000001a4", "0?Set(ALERT_INFO=)") in new stack	
pbx.c: Executing [s@macro-dial-one:38] ExecIf("PJSIP/Provider-000001a4", "0?Set(ALERT_INFO=)") in new stack	
pbx.c: Executing [s@macro-dial-one:39] ExecIf("PJSIP/Provider-000001a4", "0?Set(ALERT_INFO=)") in new stack	
pbx.c: Executing [s@macro-dial-one:40] ExecIf("PJSIP/Provider-000001a4", "0?Set(ALERT_INFO=Normal;volume=)") in new stack	
pbx.c: Executing [s@macro-dial-one:41] ExecIf("PJSIP/Provider-000001a4", "0?Set(ALERT_INFO=Normal;volume=)") in new stack	
pbx.c: Executing [s@macro-dial-one:42] GosubIf("PJSIP/Provider-000001a4", "0?func-set-sipheader,s,1(Alert-Info,)") in new stack	
pbx.c: Executing [s@macro-dial-one:43] ExecIf("PJSIP/Provider-000001a4", "0?Set(CHANNEL(musicclass)=)") in new stack	
pbx.c: Executing [s@macro-dial-one:44] GosubIf("PJSIP/Provider-000001a4", "0?qwait,1()") in new stack	
pbx.c: Executing [s@macro-dial-one:45] Set("PJSIP/Provider-000001a4", "__CWIGNORE=") in new stack	
pbx.c: Executing [s@macro-dial-one:46] Set("PJSIP/Provider-000001a4", "__KEEPCID=TRUE") in new stack	
pbx.c: Executing [s@macro-dial-one:47] GotoIf("PJSIP/Provider-000001a4", "0?usegoto,1") in new stack	
pbx.c: Executing [s@macro-dial-one:48] GotoIf("PJSIP/Provider-000001a4", "1?godial") in new stack	
pbx_builtins.c: Goto (macro-dial-one,s,53)	
pbx.c: Executing [s@macro-dial-one:53] Macro("PJSIP/Provider-000001a4", "dialout-one-predial-hook,") in new stack	
pbx.c: Executing [s@macro-dialout-one-predial-hook:1] MacroExit("PJSIP/Provider-000001a4", "") in new stack	
pbx.c: Executing [s@macro-dial-one:54] ExecIf("PJSIP/Provider-000001a4", "1?Set(D_OPTIONS=HhtrI)") in new stack	
pbx.c: Executing [s@macro-dial-one:55] ExecIf("PJSIP/Provider-000001a4", "0?Set(CWRING=r(callwaiting)):Set(CWRING=)") in new stack	
pbx.c: Executing [s@macro-dial-one:56] NoOp("PJSIP/Provider-000001a4", "") in new stack	
pbx.c: Executing [s@macro-dial-one:57] ExecIf("PJSIP/Provider-000001a4", "0?Set(D_OPTIONS=HhtrIg)") in new stack	
pbx.c: Executing [s@macro-dial-one:58] Dial("PJSIP/Provider-000001a4", "PJSIP/2001/sip:[email protected]:5060;line=stzijaa,,HhtrIb(func-apply-sipheaders^s^1)") in new stack	
app_stack.c: PJSIP/2001-000001a5 Internal Gosub(func-apply-sipheaders,s,1) start	
pbx.c: Executing [s@func-apply-sipheaders:1] ExecIf("PJSIP/2001-000001a5", "1?Set(CHANNEL(hangup_handler_push)=crm-hangup,s,1)") in new stack	
pbx.c: Executing [s@func-apply-sipheaders:2] NoOp("PJSIP/2001-000001a5", "Applying SIP Headers to channel PJSIP/2001-000001a5") in new stack	
pbx.c: Executing [s@func-apply-sipheaders:3] Set("PJSIP/2001-000001a5", "localchan=2001-000001a5") in new stack	
pbx.c: Executing [s@func-apply-sipheaders:4] Set("PJSIP/2001-000001a5", "DialMCEXT=2001") in new stack	
pbx.c: Executing [s@func-apply-sipheaders:5] Set("PJSIP/2001-000001a5", "CHANNEL(hangup_handler_push)=app-missedcall-hangup,2001,1") in new stack	
pbx.c: Executing [s@func-apply-sipheaders:6] Set("PJSIP/2001-000001a5", "TECH=PJSIP") in new stack	
pbx.c: Executing [s@func-apply-sipheaders:7] Set("PJSIP/2001-000001a5", "SIPHEADERKEYS=") in new stack	
pbx.c: Executing [s@func-apply-sipheaders:8] While("PJSIP/2001-000001a5", "0") in new stack	
app_while.c: Jumping to priority 14	
pbx.c: Executing [s@func-apply-sipheaders:15] Return("PJSIP/2001-000001a5", "") in new stack	
app_stack.c: Spawn extension (from-internal, 2001, 1) exited non-zero on 'PJSIP/2001-000001a5'	
app_stack.c: PJSIP/2001-000001a5 Internal Gosub(func-apply-sipheaders,s,1) complete GOSUB_RETVAL=	
app_dial.c: Called PJSIP/2001/sip:[email protected]:5060;line=stzijaa	
netsock2.c: Using SIP RTP Audio TOS bits 184	
netsock2.c: Using SIP RTP Audio TOS bits 184 in TCLASS field.	
netsock2.c: Using SIP RTP Audio CoS mark 5	
app_dial.c: Connected line update to PJSIP/Provider-000001a4 prevented.	
app_dial.c: PJSIP/2001-000001a5 answered PJSIP/Provider-000001a4	
bridge_channel.c: Channel PJSIP/2001-000001a5 joined 'simple_bridge' basic-bridge <aa12d9a3-3da0-4d0e-b33e-a671ee6da275>	
bridge_channel.c: Channel PJSIP/Provider-000001a4 joined 'simple_bridge' basic-bridge <aa12d9a3-3da0-4d0e-b33e-a671ee6da275>	
bridge_channel.c: Channel PJSIP/2001-000001a5 left 'simple_bridge' basic-bridge <aa12d9a3-3da0-4d0e-b33e-a671ee6da275>	
app_stack.c: PJSIP/2001-000001a5 Internal Gosub(app-missedcall-hangup,2001,1) start	
pbx.c: Executing [2001@app-missedcall-hangup:1] NoOp("PJSIP/2001-000001a5", "Dialed: 2001") in new stack	
pbx.c: Executing [2001@app-missedcall-hangup:2] NoOp("PJSIP/2001-000001a5", "Caller: ") in new stack	
pbx.c: Executing [2001@app-missedcall-hangup:3] GotoIf("PJSIP/2001-000001a5", "0?exit") in new stack	
pbx.c: Executing [2001@app-missedcall-hangup:4] Set("PJSIP/2001-000001a5", "EXTENNUM=2001") in new stack	
pbx.c: Executing [2001@app-missedcall-hangup:5] Set("PJSIP/2001-000001a5", "FEXTENNUM=2001") in new stack	
pbx.c: Executing [2001@app-missedcall-hangup:6] GotoIf("PJSIP/2001-000001a5", "1?exit") in new stack	
pbx_builtins.c: Goto (app-missedcall-hangup,2001,8)	
pbx.c: Executing [2001@app-missedcall-hangup:8] Return("PJSIP/2001-000001a5", "") in new stack	
app_stack.c: Spawn extension (from-internal, , 1) exited non-zero on 'PJSIP/2001-000001a5'	
app_stack.c: PJSIP/2001-000001a5 Internal Gosub(app-missedcall-hangup,2001,1) complete GOSUB_RETVAL=	
app_stack.c: PJSIP/2001-000001a5 Internal Gosub(crm-hangup,s,1) start	
pbx.c: Executing [s@crm-hangup:1] NoOp("PJSIP/2001-000001a5", "Sending Hangup to CRM") in new stack	
pbx.c: Executing [s@crm-hangup:2] NoOp("PJSIP/2001-000001a5", "HANGUP CAUSE: 16") in new stack	
pbx.c: Executing [s@crm-hangup:3] ExecIf("PJSIP/2001-000001a5", "0?Set(__CRM_VOICEMAIL=)") in new stack	
pbx.c: Executing [s@crm-hangup:4] NoOp("PJSIP/2001-000001a5", "MASTER CHANNEL: 1719155479.421 = 1719155479.420") in new stack	
pbx.c: Executing [s@crm-hangup:5] GotoIf("PJSIP/2001-000001a5", "1?return") in new stack	
pbx_builtins.c: Goto (crm-hangup,s,8)	
pbx.c: Executing [s@crm-hangup:8] Return("PJSIP/2001-000001a5", "") in new stack	
app_stack.c: Spawn extension (from-internal, , 1) exited non-zero on 'PJSIP/2001-000001a5'	
app_stack.c: PJSIP/2001-000001a5 Internal Gosub(crm-hangup,s,1) complete GOSUB_RETVAL=	
bridge_channel.c: Channel PJSIP/Provider-000001a4 left 'simple_bridge' basic-bridge <aa12d9a3-3da0-4d0e-b33e-a671ee6da275>	
app_macro.c: Spawn extension (macro-dial-one, s, 58) exited non-zero on 'PJSIP/Provider-000001a4' in macro 'dial-one'	
app_macro.c: Spawn extension (macro-exten-vm, s, 34) exited non-zero on 'PJSIP/Provider-000001a4' in macro 'exten-vm'	
pbx.c: Spawn extension (ext-local, 2001, 3) exited non-zero on 'PJSIP/Provider-000001a4'	
pbx.c: Executing [h@ext-local:1] Macro("PJSIP/Provider-000001a4", "hangupcall,") in new stack	
pbx.c: Executing [s@macro-hangupcall:1] Set("PJSIP/Provider-000001a4", "__MCVMSTATUS=") in new stack	
pbx.c: Executing [s@macro-hangupcall:2] Gosub("PJSIP/Provider-000001a4", "app-missedcall-hangup,s,1()") in new stack	
pbx.c: Executing [s@app-missedcall-hangup:1] NoOp("PJSIP/Provider-000001a4", "Dialed: s") in new stack	
pbx.c: Executing [s@app-missedcall-hangup:2] NoOp("PJSIP/Provider-000001a4", "Caller: ") in new stack	
pbx.c: Executing [s@app-missedcall-hangup:3] GotoIf("PJSIP/Provider-000001a4", "0?exit") in new stack	
pbx.c: Executing [s@app-missedcall-hangup:4] Set("PJSIP/Provider-000001a4", "EXTENNUM=s") in new stack	
pbx.c: Executing [s@app-missedcall-hangup:5] Set("PJSIP/Provider-000001a4", "FEXTENNUM=s") in new stack	
pbx.c: Executing [s@app-missedcall-hangup:6] GotoIf("PJSIP/Provider-000001a4", "0?exit") in new stack	
pbx.c: Executing [s@app-missedcall-hangup:7] AGI("PJSIP/Provider-000001a4", "agi://127.0.0.1/missedcallnotify.php,s,,s,0,,PJSIP/Provider-000001a4,ANSWER,,,") in new stack	
res_agi.c: <PJSIP/Provider-000001a4>AGI Script agi://127.0.0.1/missedcallnotify.php completed, returning 0	
pbx.c: Executing [s@app-missedcall-hangup:8] Return("PJSIP/Provider-000001a4", "") in new stack	
pbx.c: Executing [s@macro-hangupcall:3] GotoIf("PJSIP/Provider-000001a4", "1?theend") in new stack	
pbx_builtins.c: Goto (macro-hangupcall,s,5)	
pbx.c: Executing [s@macro-hangupcall:5] ExecIf("PJSIP/Provider-000001a4", "0?Set(CDR(recordingfile)=)") in new stack	
pbx.c: Executing [s@macro-hangupcall:6] Hangup("PJSIP/Provider-000001a4", "") in new stack	
app_macro.c: Spawn extension (macro-hangupcall, s, 6) exited non-zero on 'PJSIP/Provider-000001a4' in macro 'hangupcall'	
pbx.c: Spawn extension (ext-local, h, 1) exited non-zero on 'PJSIP/Provider-000001a4'	
app_stack.c: PJSIP/Provider-000001a4 Internal Gosub(crm-hangup,s,1) start	
pbx.c: Executing [s@crm-hangup:1] NoOp("PJSIP/Provider-000001a4", "Sending Hangup to CRM") in new stack	
pbx.c: Executing [s@crm-hangup:2] NoOp("PJSIP/Provider-000001a4", "HANGUP CAUSE: 16") in new stack	
pbx.c: Executing [s@crm-hangup:3] ExecIf("PJSIP/Provider-000001a4", "0?Set(__CRM_VOICEMAIL=)") in new stack	
pbx.c: Executing [s@crm-hangup:4] NoOp("PJSIP/Provider-000001a4", "MASTER CHANNEL: 1719155479.420 = 1719155479.420") in new stack	
pbx.c: Executing [s@crm-hangup:5] GotoIf("PJSIP/Provider-000001a4", "0?return") in new stack	
pbx.c: Executing [s@crm-hangup:6] Set("PJSIP/Provider-000001a4", "__CRM_HANGUP=1") in new stack	
pbx.c: Executing [s@crm-hangup:7] AGI("PJSIP/Provider-000001a4", "agi://127.0.0.1/sangomacrm.agi") in new stack	
res_agi.c: <PJSIP/Provider-000001a4>AGI Script agi://127.0.0.1/sangomacrm.agi completed, returning 0	
pbx.c: Executing [s@crm-hangup:8] Return("PJSIP/Provider-000001a4", "") in new stack	
app_stack.c: Spawn extension (ext-local, h, 1) exited non-zero on 'PJSIP/Provider-000001a4'	
app_stack.c: PJSIP/Provider-000001a4 Internal Gosub(crm-hangup,s,1) complete GOSUB_RETVAL=
Log Test call - PBX2
2	[15:11:19] VERBOSE[25376] res_pjsip_logger.c: <--- Received SIP request (1128 bytes) from UDP:95.xxx.xxx.142:5060 --->	
3	INVITE sip:[email protected]:5060;line=stzijaa SIP/2.0	
4	Via: SIP/2.0/UDP 95.xxx.xxx.142:5060;rport;branch=z9hG4bKPj3ba6b1bf-da00-474a-b41e-409b1aa5b371	
5	From: "+3168xxxx977" <sip:[email protected]>;tag=7249f7a3-7908-4226-b0ef-51f4f0b9cd3b	
6	To: <sip:[email protected];line=stzijaa>	
7	Contact: <sip:[email protected]:5060>	
8	Call-ID: b8afa245-8e42-404e-9571-e0f13de3decc	
9	CSeq: 15423 INVITE	
10	Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER	
11	Supported: 100rel, timer, replaces, norefersub, histinfo	
12	Session-Expires: 1800	
13	Min-SE: 90	
14	P-Asserted-Identity: "+3168xxxx977" <sip:[email protected]>	
15	Max-Forwards: 70	
16	User-Agent: FPBX-16.0.40.8(19.8.0)	
17	Content-Type: application/sdp	
18	Content-Length: 343	
19		
20	v=0	
21	o=- 1744717747 1744717747 IN IP4 95.xxx.xxx.142	
22	s=Asterisk	
23	c=IN IP4 95.xxx.xxx.142	
24	t=0 0	
25	m=audio 14814 RTP/AVP 8 0 3 111 9 101	
26	a=rtpmap:8 PCMA/8000	
27	a=rtpmap:0 PCMU/8000	
28	a=rtpmap:3 GSM/8000	
29	a=rtpmap:111 G726-32/8000	
30	a=rtpmap:9 G722/8000	
31	a=rtpmap:101 telephone-event/8000	
32	a=fmtp:101 0-16	
33	a=ptime:20	
34	a=maxptime:150	
35	a=sendrecv	
36		
37	[15:11:19] VERBOSE[16247] res_pjsip_logger.c: <--- Transmitting SIP response (405 bytes) to UDP:95.xxx.xxx.142:5060 --->	
38	SIP/2.0 100 Trying	
39	Via: SIP/2.0/UDP 95.xxx.xxx.142:5060;rport=5060;received=95.xxx.xxx.142;branch=z9hG4bKPj3ba6b1bf-da00-474a-b41e-409b1aa5b371	
40	Call-ID: b8afa245-8e42-404e-9571-e0f13de3decc	
41	From: "+3168xxxx977" <sip:[email protected]>;tag=7249f7a3-7908-4226-b0ef-51f4f0b9cd3b	
42	To: <sip:[email protected];line=stzijaa>	
43	CSeq: 15423 INVITE	
44	Server: FPBX-16.0.40.7(18.20.2)	
45	Content-Length: 0	
46		
47		
48	[15:11:19] VERBOSE[29272][C-000001ae] pbx.c: Executing [s@from-pstn:1] NoOp("PJSIP/2001-00000214", "No DID or CID Match") in new stack	
49	[15:11:19] VERBOSE[29272][C-000001ae] pbx.c: Executing [s@from-pstn:2] Answer("PJSIP/2001-00000214", "") in new stack	
50	[15:11:19] VERBOSE[25765] res_pjsip_logger.c: <--- Transmitting SIP response (1067 bytes) to UDP:95.xxx.xxx.142:5060 --->	
51	SIP/2.0 200 OK	
52	Via: SIP/2.0/UDP 95.xxx.xxx.142:5060;rport=5060;received=95.xxx.xxx.142;branch=z9hG4bKPj3ba6b1bf-da00-474a-b41e-409b1aa5b371	
53	Call-ID: b8afa245-8e42-404e-9571-e0f13de3decc	
54	From: "+3168xxxx977" <sip:[email protected]>;tag=7249f7a3-7908-4226-b0ef-51f4f0b9cd3b	
55	To: <sip:[email protected];line=stzijaa>;tag=fef1e48c-a1d1-4858-8b60-dcd67b73e346	
56	CSeq: 15423 INVITE	
57	Server: FPBX-16.0.40.7(18.20.2)	
58	Contact: <sip:158.xxx.xxx.68:5060>	
59	Allow: OPTIONS, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, MESSAGE, REFER	
60	Supported: 100rel, timer, replaces, norefersub	
61	Session-Expires: 1800;refresher=uac	
62	Require: timer	
63	Content-Type: application/sdp	
64	Content-Length: 343	
65		
66	v=0	
67	o=- 1744717747 1744717749 IN IP4 158.xxx.xxx.68	
68	s=Asterisk	
69	c=IN IP4 158.xxx.xxx.68	
70	t=0 0	
71	m=audio 12930 RTP/AVP 0 8 3 111 9 101	
72	a=rtpmap:0 PCMU/8000	
73	a=rtpmap:8 PCMA/8000	
74	a=rtpmap:3 GSM/8000	
75	a=rtpmap:111 G726-32/8000	
76	a=rtpmap:9 G722/8000	
77	a=rtpmap:101 telephone-event/8000	
78	a=fmtp:101 0-16	
79	a=ptime:20	
80	a=maxptime:150	
81	a=sendrecv	
82		
83	[15:11:20] VERBOSE[25376] res_pjsip_logger.c: <--- Received SIP request (452 bytes) from UDP:95.xxx.xxx.142:5060 --->	
84	ACK sip:158.xxx.xxx.68:5060 SIP/2.0	
85	Via: SIP/2.0/UDP 95.xxx.xxx.142:5060;rport;branch=z9hG4bKPj42ecffcc-1ef4-48fe-a95c-45df2f5fe679	
86	From: "+3168xxxx977" <sip:[email protected]>;tag=7249f7a3-7908-4226-b0ef-51f4f0b9cd3b	
87	To: <sip:[email protected];line=stzijaa>;tag=fef1e48c-a1d1-4858-8b60-dcd67b73e346	
88	Call-ID: b8afa245-8e42-404e-9571-e0f13de3decc	
89	CSeq: 15423 ACK	
90	Max-Forwards: 70	
91	User-Agent: FPBX-16.0.40.8(19.8.0)	
92	Content-Length: 0	
93		
94		
95	[15:11:20] ERROR[29272][C-000001ae] pbx_functions.c: Function SIP_HEADER not registered	
96	[15:11:20] VERBOSE[29272][C-000001ae] pbx.c: Executing [s@from-pstn:3] Log("PJSIP/2001-00000214", "WARNING,Friendly Scanner from ") in new stack	
97	[15:11:20] WARNING[29272][C-000001ae] Ext. s: Friendly Scanner from	
98	[15:11:20] VERBOSE[29272][C-000001ae] pbx.c: Executing [s@from-pstn:4] Wait("PJSIP/2001-00000214", "2") in new stack	
99	[15:11:22] VERBOSE[29272][C-000001ae] pbx.c: Executing [s@from-pstn:5] Playback("PJSIP/2001-00000214", "ss-noservice") in new stack	
100	[15:11:22] VERBOSE[29272][C-000001ae] file.c: <PJSIP/2001-00000214> Playing 'ss-noservice.ulaw' (language 'nl')	
101	[15:11:24] VERBOSE[25765] res_pjsip_logger.c: <--- Transmitting SIP request (440 bytes) to UDP:95.xxx.xxx.142:5060 --->	
102	OPTIONS sip:[email protected]:5060 SIP/2.0	
103	Via: SIP/2.0/UDP 158.xxx.xxx.68:5060;rport;branch=z9hG4bKPj55b5ad0e-ffb0-45d1-af09-8b24741f2f63	
104	From: <sip:[email protected]>;tag=cd4c9a39-16ea-45f0-8e5b-13a75a3a2a3a	
105	To: <sip:[email protected]>	
106	Contact: <sip:[email protected]:5060>	
107	Call-ID: 82b8e8bd-8704-440e-9128-9a6b01def636	
108	CSeq: 36351 OPTIONS	
109	Max-Forwards: 70	
110	User-Agent: FPBX-16.0.40.7(18.20.2)	
111	Content-Length: 0	
112		
113		
114	[15:11:24] VERBOSE[25376] res_pjsip_logger.c: <--- Received SIP response (578 bytes) from UDP:95.xxx.xxx.142:5060 --->	
115	SIP/2.0 401 Unauthorized	
116	Via: SIP/2.0/UDP 158.xxx.xxx.68:5060;rport=5060;received=158.xxx.xxx.68;branch=z9hG4bKPj55b5ad0e-ffb0-45d1-af09-8b24741f2f63	
117	Call-ID: 82b8e8bd-8704-440e-9128-9a6b01def636	
118	From: <sip:[email protected]>;tag=cd4c9a39-16ea-45f0-8e5b-13a75a3a2a3a	
119	To: <sip:[email protected]>;tag=z9hG4bKPj55b5ad0e-ffb0-45d1-af09-8b24741f2f63	
120	CSeq: 36351 OPTIONS	
121	WWW-Authenticate: Digest realm="asterisk",nonce="1719155484/fb9f5924d14fe308875d529baf360cb8",opaque="2531593a5171fd1d",algorithm=MD5,qop="auth"	
122	Server: FPBX-16.0.40.8(19.8.0)	
123	Content-Length: 0	
124		
125		
126	[15:11:24] VERBOSE[9578] res_pjsip_logger.c: <--- Transmitting SIP request (742 bytes) to UDP:95.xxx.xxx.142:5060 --->	
127	OPTIONS sip:[email protected]:5060 SIP/2.0	
128	Via: SIP/2.0/UDP 158.xxx.xxx.68:5060;rport;branch=z9hG4bKPj19db9fc8-b48b-41bc-bfa8-9ac56694fce3	
129	From: <sip:[email protected]>;tag=cd4c9a39-16ea-45f0-8e5b-13a75a3a2a3a	
130	To: <sip:[email protected]>	
131	Contact: <sip:[email protected]:5060>	
132	Call-ID: 82b8e8bd-8704-440e-9128-9a6b01def636	
133	CSeq: 36352 OPTIONS	
134	Max-Forwards: 70	
135	User-Agent: FPBX-16.0.40.7(18.20.2)	
136	Authorization: Digest username="2001", realm="asterisk", nonce="1719155484/fb9f5924d14fe308875d529baf360cb8", uri="sip:[email protected]:5060", response="9e8254e6f6277d2fdff8ad76f53ed2e6", algorithm=MD5, cnonce="bd880e2fd5f7456e89731ef26de63e55", opaque="2531593a5171fd1d", qop=auth, nc=00000001	
137	Content-Length: 0	
138		
139		
140	[15:11:24] VERBOSE[25376] res_pjsip_logger.c: <--- Received SIP response (907 bytes) from UDP:95.xxx.xxx.142:5060 --->	
141	SIP/2.0 200 OK	
142	Via: SIP/2.0/UDP 158.xxx.xxx.68:5060;rport=5060;received=158.xxx.xxx.68;branch=z9hG4bKPj19db9fc8-b48b-41bc-bfa8-9ac56694fce3	
143	Call-ID: 82b8e8bd-8704-440e-9128-9a6b01def636	
144	From: <sip:[email protected]>;tag=cd4c9a39-16ea-45f0-8e5b-13a75a3a2a3a	
145	To: <sip:[email protected]>;tag=z9hG4bKPj19db9fc8-b48b-41bc-bfa8-9ac56694fce3	
146	CSeq: 36352 OPTIONS	
147	Accept: application/xpidf+xml, application/cpim-pidf+xml, application/dialog-info+xml, application/simple-message-summary, application/pidf+xml, application/pidf+xml, application/dialog-info+xml, application/simple-message-summary, application/sdp, message/sipfrag;version=2.0	
148	Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, REFER	
149	Supported: 100rel, timer, replaces, norefersub	
150	Accept-Encoding: identity	
151	Accept-Language: en	
152	Server: FPBX-16.0.40.8(19.8.0)	
153	Content-Length: 0	
154		
155		
156	[15:11:29] VERBOSE[29272][C-000001ae] pbx.c: Executing [s@from-pstn:6] SayAlpha("PJSIP/2001-00000214", "") in new stack	
157	[15:11:29] VERBOSE[29272][C-000001ae] pbx.c: Executing [s@from-pstn:7] Hangup("PJSIP/2001-00000214", "") in new stack	
158	[15:11:29] VERBOSE[29272][C-000001ae] pbx.c: Spawn extension (from-pstn, s, 7) exited non-zero on 'PJSIP/2001-00000214'	
159	[15:11:29] VERBOSE[29272][C-000001ae] pbx.c: Executing [h@from-pstn:1] Macro("PJSIP/2001-00000214", "hangupcall,") in new stack	
160	[15:11:29] VERBOSE[29272][C-000001ae] pbx.c: Executing [s@macro-hangupcall:1] Gosub("PJSIP/2001-00000214", "app-missedcall-hangup,s,1()") in new stack	
161	[15:11:29] VERBOSE[29272][C-000001ae] pbx.c: Executing [s@app-missedcall-hangup:1] NoOp("PJSIP/2001-00000214", "Callee: s") in new stack	
162	[15:11:29] VERBOSE[29272][C-000001ae] pbx.c: Executing [s@app-missedcall-hangup:2] NoOp("PJSIP/2001-00000214", "Caller: ") in new stack	
163	[15:11:29] VERBOSE[29272][C-000001ae] pbx.c: Executing [s@app-missedcall-hangup:3] AGI("PJSIP/2001-00000214", "agi://127.0.0.1/missedcallnotify.php,,,s,0,,PJSIP/2001-00000214,,") in new stack	
164	[15:11:29] VERBOSE[29272][C-000001ae] res_agi.c: agi://127.0.0.1/missedcallnotify.php,,,s,0,,PJSIP/2001-00000214,,: As a minimum this script requires extension or 's' as argument	
165	[15:11:29] VERBOSE[29272][C-000001ae] res_agi.c: <PJSIP/2001-00000214>AGI Script agi://127.0.0.1/missedcallnotify.php completed, returning 0	
166	[15:11:29] VERBOSE[29272][C-000001ae] pbx.c: Executing [s@app-missedcall-hangup:4] Return("PJSIP/2001-00000214", "") in new stack	
167	[15:11:29] VERBOSE[29272][C-000001ae] pbx.c: Executing [s@macro-hangupcall:2] GotoIf("PJSIP/2001-00000214", "1?theend") in new stack	
168	[15:11:29] VERBOSE[29272][C-000001ae] pbx_builtins.c: Goto (macro-hangupcall,s,4)	
169	[15:11:29] VERBOSE[29272][C-000001ae] pbx.c: Executing [s@macro-hangupcall:4] ExecIf("PJSIP/2001-00000214", "0?Set(CDR(recordingfile)=)") in new stack	
170	[15:11:29] VERBOSE[29272][C-000001ae] pbx.c: Executing [s@macro-hangupcall:5] Hangup("PJSIP/2001-00000214", "") in new stack	
171	[15:11:29] VERBOSE[29272][C-000001ae] app_macro.c: Spawn extension (macro-hangupcall, s, 5) exited non-zero on 'PJSIP/2001-00000214' in macro 'hangupcall'	
172	[15:11:29] VERBOSE[29272][C-000001ae] pbx.c: Spawn extension (from-pstn, h, 1) exited non-zero on 'PJSIP/2001-00000214'	
173	[15:11:29] VERBOSE[25765] res_pjsip_logger.c: <--- Transmitting SIP request (486 bytes) to UDP:95.xxx.xxx.142:5060 --->	
174	BYE sip:[email protected]:5060 SIP/2.0	
175	Via: SIP/2.0/UDP 158.xxx.xxx.68:5060;rport;branch=z9hG4bKPj21161db5-c966-4bba-83ed-647ee709e722	
176	From: <sip:[email protected];line=stzijaa>;tag=fef1e48c-a1d1-4858-8b60-dcd67b73e346	
177	To: "+3168xxxx977" <sip:[email protected]>;tag=7249f7a3-7908-4226-b0ef-51f4f0b9cd3b	
178	Call-ID: b8afa245-8e42-404e-9571-e0f13de3decc	
179	CSeq: 11172 BYE	
180	Reason: Q.850;cause=16	
181	Max-Forwards: 70	
182	User-Agent: FPBX-16.0.40.7(18.20.2)	
183	Content-Length: 0	
184		
185		
186	[15:11:29] VERBOSE[25376] res_pjsip_logger.c: <--- Received SIP response (438 bytes) from UDP:95.xxx.xxx.142:5060 --->	
187	SIP/2.0 200 OK	
188	Via: SIP/2.0/UDP 158.xxx.xxx.68:5060;rport=5060;received=158.xxx.xxx.68;branch=z9hG4bKPj21161db5-c966-4bba-83ed-647ee709e722	
189	Call-ID: b8afa245-8e42-404e-9571-e0f13de3decc	
190	From: <sip:[email protected];line=stzijaa>;tag=fef1e48c-a1d1-4858-8b60-dcd67b73e346	
191	To: "+3168xxxx977" <sip:[email protected]>;tag=7249f7a3-7908-4226-b0ef-51f4f0b9cd3b	
192	CSeq: 11172 BYE	
193	Server: FPBX-16.0.40.8(19.8.0)	
194	Content-Length: 0	

Try setting Contact User on PBX2 to the DID number (that matches the Inbound Route on PBX2) and retest. If you still have trouble, post new logs.

If PBX2 has more than one DID, I strongly suggest that you give up trying to use extensions and set up trunks on PBX1, though if there are only two or three, a separate extension for each should work.

@Stewart1 I tested your suggestion, and setting the Contact User on PBX2 to the DID number that matches the Inbound Route on PBX2 works perfectly! This is fantastic news. Everything is still standard, so I’m not using any custom inbound context.

However, I have encountered a new issue: some PBXs have up to 10 numbers in use. Previously, with my old provider, this worked out of the box as the DID was dynamically passed to PBX2. Now, I need to find a way to dynamically adjust the Contact User.

You mentioned using “trunks” if there are more numbers on PBX2. What do you mean by that? Because I see a trunk as an inbound and outbound connection to a provider, but I don’t know how to create my own trunk. Is it some sort of extension type like IAX2 and DAHDi?

I’m thinking of a solution where PBX1 could pass a header or some information from which PBX2 could extract the DID and set it as the Contact User. I might need to create a custom dial plan on PBX2 to read this header and update the Contact User dynamically.

Any suggestions or best practices for implementing this are welcome.

Thanks again for your help!

Good news, I have managed to solve my problem. It might not be the ideal solution, but I’ll first explain what I initially wanted and how I eventually resolved it.

Initial Goal:
PBX1 is connected to the Provider via a trunk with the following settings:

  • Trust RPID/PAI: Yes
  • Send RPID/PAI: Send P-Asserted-Identity
  • Inbound context: from-pstn-toheader

I aimed to solve this issue using a macro-dialout hook by extracting the To header from the existing headers and replacing it with my own, allowing PBX2 to successfully capture and process it as a DID. I also tried this with the Contact header. However, I found that I could not remove the existing To and Contact headers from the INVITE. I was able to add new headers, but this resulted in duplicate To and Contact headers. I even tried to manipulate [func-apply-sipheaders] by duplicating it in extensions_override_freepbx.conf, but this was unsuccessful.

Here was the code I initially added to extensions_custom.conf:

[macro-dialout-one-predial-hook]
exten => s,1,NoOp(Entering user defined context macro-dialout-one-predial-hook in extensions_custom.conf)
exten => s,n,Set(DID=${FROM_DID})
exten => s,n,NoOp(Using existing DID: ${DID})
exten => s,n,GoSub(func-set-sipheader,s,1(To,<sip:${DID}@${SIPDOMAIN}>))
exten => s,n,NoOp(Custom header To set to: ${PJSIP_HEADER(read,To)})
exten => s,n,MacroExit()

Final Solution:
I decided to create a custom header named X-DID that carries the number. PBX1 sends this X-DID header, which PBX2 captures. Here is the final custom dial plan on PBX1:

[macro-dialout-one-predial-hook]
exten => s,1,NoOp(Entering user defined context macro-dialout-one-predial-hook in extensions_custom.conf)
exten => s,n,Set(DID=${FROM_DID})
exten => s,n,NoOp(Using existing DID: ${DID})
exten => s,n,GoSub(func-set-sipheader,s,1(X-DID,${DID}))
exten => s,n,NoOp(Custom header X-DID set to: ${PJSIP_HEADER(read,X-DID)})
exten => s,n,MacroExit()

On PBX2, I created a custom dial plan used as the inbound context for the trunk, named [from-pstn-xdid]. This plan extracts the DID from the X-DID header and follows the normal processing logic to handle the call. I also set Trust RPID/PAI: Yes and Send RPID/PAI: Send P-Asserted-Identity on PBX2 and provided an Outbound CID at the extension level. Here is the custom dial plan used on PBX2:

[from-pstn-xdid]
exten => _.,1,NoOp(Attempting to extract DID from SIP X-DID header)
exten => _.,n,GotoIf($["${CHANNEL(channeltype)}"="PJSIP"]?PJSIP)
exten => _.,n,GotoIf($["${CHANNEL(channeltype)}"="SIP"]?SIP)
exten => _.,n,NoOp(Unable to determine SIP channel type)
exten => _.,n,Goto(from-pstn,${EXTEN},1)

exten => _.,n(PJSIP),NoOp(Extracting X-DID for PJSIP channel)
exten => _.,n,Set(XDID=${PJSIP_HEADER(read,X-DID)})
exten => _.,n,GotoIf($["${XDID}" != ""]?from-pstn,${XDID},1)
exten => _.,n,NoOp(No X-DID found, falling back to original DID)
exten => _.,n,Goto(from-pstn,${EXTEN},1)

exten => _.,n(SIP),NoOp(Extracting X-DID for SIP channel)
exten => _.,n,Set(XDID=${SIP_HEADER(X-DID)})
exten => _.,n,GotoIf($["${XDID}" != ""]?from-pstn,${XDID},1)
exten => _.,n,NoOp(No X-DID found, falling back to original DID)
exten => _.,n,Goto(from-pstn,${EXTEN},1)

Overall, this setup works well. PBX2 receives all incoming calls, processes the custom X-DID header correctly, and routes the call according to the inbound routes. Outbound calling also works perfectly, with the Send RPID ensuring PBX1 can capture and use it in its process and with the trunk invite to the Provider. I did not set an Outbound CID on PBX1, allowing PBX2 to manage how it sends this information. I have now connected a third and fourth PBX in the same way, and they also work perfectly with PBX1.

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