Freepbx not seeing DID's

Hey All,

I have a new build. Everything is working great except for the inbound routes I have setup. The box for some reason is not seeing the right did.

I am currently using Nextiva as the trunk provider.

I have tried changing the context in the incoming trunk sip settings from “from-internal” to “from-pstn-toheader” with no luck. I have the dumps from my CDR, console and from nextiva.
All my box is seeing is the DID ending in 8743 which is the reg for the sip trunk. I can not get it to go to any of the other inbound routes because it will only see the DID ending in 8743.

I have obfuscated part of the numbers and ip address with “X”, but other then that is is intact.

This call was made to the number ending in 8731 but te box picked it up as 8743
Here is what nextiva is sending to the box.


INVITE sip:[email protected]:5160 SIP/2.0
Via: SIP/2.0/UDP 208.73.144.74:5060;branch=z9hG4bK0b5shn106o2979v18je0.1
From: <sip:[email protected];user=phone>;tag=1935862829-1552878140829-
To: "XXXXXX8731 XXXXXX8731"sip:[email protected]
Call-ID: [email protected]
CSeq: 123731663 INVITE
Contact: <sip:[email protected]:5060;transport=udp>
Supported: 100rel
Allow: ACK,BYE,CANCEL,INFO,INVITE,OPTIONS,PRACK,REFER,NOTIFY,UPDATE
Recv-Info: x-broadworks-client-session-info
X-BroadWorks-Correlation-Info: 2d33d9d5-cbf2-4f29-a023-dae0b67d19f7
Accept: application/media_control+xml,application/sdp,multipart/mixed
Max-Forwards: 19
Content-Type: application/sdp
Content-Disposition: session;handling=required
Content-Length: 263

v=0
o=BroadWorks 8476254 1 IN IP4 208.73.144.74
s=-
c=IN IP4 208.73.144.74
t=0 0
m=audio 20948 RTP/AVP 0 18 101
a=rtpmap:0 PCMU/8000
a=rtpmap:18 G729/8000
a=fmtp:18 annexb=no
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=sendrecv
a=maxptime:20


Here is the console dump


Using SIP RTP TOS bits 184
== Using SIP RTP CoS mark 5
> 0x7f047c00a700 – Strict RTP learning after remote address set to: 208.73.144.74:19006
– Executing [XXXXXX8743@from-trunk-sip-Nextiva:1] Set(“SIP/Nextiva-00000002”, “GROUP()=OUT_1”) in new stack
– Executing [XXXXXX8743@from-trunk-sip-Nextiva:2] Goto(“SIP/Nextiva-00000002”, “from-trunk,XXXXXX8743,1”) in new stack
– Goto (from-trunk,XXXXXX8743,1)
– Executing [XXXXXX8743@from-trunk:1] NoOp(“SIP/Nextiva-00000002”, “Catch-All DID Match - Found XXXXXX8743 - You probably want a DID for this.”) in new stack
– Executing [XXXXXX8743@from-trunk:2] Log(“SIP/Nextiva-00000002”, “WARNING,Friendly Scanner from 208.73.144.74”) in new stack
[2019-03-17 21:37:07] WARNING[7565][C-00000002]: Ext. XXXXXX8743:2 @ from-trunk: Friendly Scanner from 208.73.144.74
– Executing [XXXXXX8743@from-trunk:3] Set(“SIP/Nextiva-00000002”, “__FROM_DID=XXXXXX8743”) in new stack
– Executing [XXXXXX8743@from-trunk:4] Goto(“SIP/Nextiva-00000002”, “ext-did,s,1”) in new stack
– Goto (ext-did,s,1)
– Executing [s@ext-did:1] Set(“SIP/Nextiva-00000002”, “__DIRECTION=INBOUND”) in new stack
– Executing [s@ext-did:2] Set(“SIP/Nextiva-00000002”, “CHANNEL(tonezone)=us”) in new stack
– Executing [s@ext-did:3] ExecIf(“SIP/Nextiva-00000002”, “0?Set(__FROM_DID=s)”) in new stack
– Executing [s@ext-did:4] Set(“SIP/Nextiva-00000002”, “returnhere=1”) in new stack
– Executing [s@ext-did:5] Gosub(“SIP/Nextiva-00000002”, “app-blacklist-check,s,1()”) in new stack
– Executing [s@app-blacklist-check:1] GotoIf(“SIP/Nextiva-00000002”, “0?blacklisted”) in new stack
– Executing [s@app-blacklist-check:2] Set(“SIP/Nextiva-00000002”, “CALLED_BLACKLIST=1”) in new stack
– Executing [s@app-blacklist-check:3] Return(“SIP/Nextiva-00000002”, “”) in new stack
– Executing [s@ext-did:6] Set(“SIP/Nextiva-00000002”, “CDR(did)=XXXXXX8743”) in new stack
– Executing [s@ext-did:7] GotoIf(“SIP/Nextiva-00000002”, “0?”) in new stack
– Executing [s@ext-did:8] ExecIf(“SIP/Nextiva-00000002”, “1 ?Set(CALLERID(name)=XXXXXX6958)”) in new stack
– Executing [s@ext-did:9] Set(“SIP/Nextiva-00000002”, “__MOHCLASS=”) in new stack
– Executing [s@ext-did:10] Set(“SIP/Nextiva-00000002”, “__REVERSAL_REJECT=FALSE”) in new stack
– Executing [s@ext-did:11] GotoIf(“SIP/Nextiva-00000002”, “1?post-reverse-charge”) in new stack
– Goto (ext-did,s,13)
– Executing [s@ext-did:13] NoOp(“SIP/Nextiva-00000002”, “”) in new stack
– Executing [s@ext-did:14] Set(“SIP/Nextiva-00000002”, “__CALLINGNAMEPRES_SV=allowed_not_screened”) in new stack
– Executing [s@ext-did:15] Set(“SIP/Nextiva-00000002”, “__CALLINGNUMPRES_SV=allowed_not_screened”) in new stack
– Executing [s@ext-did:16] Set(“SIP/Nextiva-00000002”, “CALLERID(name-pres)=allowed_not_screened”) in new stack
– Executing [s@ext-did:17] Set(“SIP/Nextiva-00000002”, “CALLERID(num-pres)=allowed_not_screened”) in new stack
– Executing [s@ext-did:18] NoOp(“SIP/Nextiva-00000002”, “CallerID Entry Point”) in new stack
– Executing [s@ext-did:19] Set(“SIP/Nextiva-00000002”, “__CRM_DIRECTION=INBOUND”) in new stack
– Executing [s@ext-did:20] Set(“SIP/Nextiva-00000002”, “__CRM_SOURCE=XXXXXX6958”) in new stack
– Executing [s@ext-did:21] Set(“SIP/Nextiva-00000002”, “__CRM_LINKEDID=1552883827.2”) in new stack
– Executing [s@ext-did:22] ExecIf(“SIP/Nextiva-00000002”, “1?Set(CHANNEL(hangup_handler_push)=crm-hangup,s,1)”) in new stack
– Executing [s@ext-did:23] Goto(“SIP/Nextiva-00000002”, “app-daynight,99,1”) in new stack
– Goto (app-daynight,99,1)
– Executing [99@app-daynight:1] GotoIf(“SIP/Nextiva-00000002”, “0?app-announcement-1,s,1:timeconditions,5,1”) in new stack
– Goto (timeconditions,5,1)
– Executing [5@timeconditions:1] Set(“SIP/Nextiva-00000002”, “DB(TC/5/INUSESTATE)=INUSE”) in new stack
– Executing [5@timeconditions:2] Set(“SIP/Nextiva-00000002”, “DB(TC/5/NOT_INUSESTATE)=NOT_INUSE”) in new stack
– Executing [5@timeconditions:3] NoOp(“SIP/Nextiva-00000002”, “TIMENOW: 21:37,Sun,17,Mar”) in new stack
– Executing [5@timeconditions:4] NoOp(“SIP/Nextiva-00000002”, “TIMEMATCHED: FALSE”) in new stack
– Executing [5@timeconditions:5] GotoIfTime(“SIP/Nextiva-00000002”, “08:00-15:00,sun,,?truestate”) in new stack
– Executing [5@timeconditions:6] NoOp(“SIP/Nextiva-00000002”, “TIMENOW: 21:37,Sun,17,Mar”) in new stack
– Executing [5@timeconditions:7] NoOp(“SIP/Nextiva-00000002”, “TIMEMATCHED: FALSE”) in new stack
– Executing [5@timeconditions:8] GotoIfTime(“SIP/Nextiva-00000002”, “06:30-18:30,mon-fri,,?truestate”) in new stack
– Executing [5@timeconditions:9] NoOp(“SIP/Nextiva-00000002”, “TIMENOW: 21:37,Sun,17,Mar”) in new stack
– Executing [5@timeconditions:10] NoOp(“SIP/Nextiva-00000002”, “TIMEMATCHED: FALSE”) in new stack
– Executing [5@timeconditions:11] GotoIfTime(“SIP/Nextiva-00000002”, “07:30-17:30,sat,,?truestate”) in new stack
– Executing [5@timeconditions:12] GotoIf(“SIP/Nextiva-00000002”, “0?truegoto”) in new stack
– Executing [5@timeconditions:13] ExecIf(“SIP/Nextiva-00000002”, “0?Set(DB(TC/5)=)”) in new stack
– Executing [5@timeconditions:14] Set(“SIP/Nextiva-00000002”, “DEVICE_STATE(Custom:TC5)=INUSE”) in new stack
– Executing [5@timeconditions:15] ExecIf(“SIP/Nextiva-00000002”, “0?Set(DEVICE_STATE(Custom:TCSTICKY)=INUSE)”) in new stack
– Executing [5@timeconditions:16] GotoIf(“SIP/Nextiva-00000002”, “1?ivr-2,s,1”) in new stack
– Goto (ivr-2,s,1)
– Executing [s@ivr-2:1] Set(“SIP/Nextiva-00000002”, “TIMEOUT_LOOPCOUNT=0”) in new stack
– Executing [s@ivr-2:2] Set(“SIP/Nextiva-00000002”, “INVALID_LOOPCOUNT=0”) in new stack
– Executing [s@ivr-2:3] Set(“SIP/Nextiva-00000002”, “_IVR_CONTEXT_ivr-2=”) in new stack
– Executing [s@ivr-2:4] Set(“SIP/Nextiva-00000002”, “_IVR_CONTEXT=ivr-2”) in new stack
– Executing [s@ivr-2:5] Set(“SIP/Nextiva-00000002”, “__IVR_RETVM=”) in new stack
– Executing [s@ivr-2:6] GotoIf(“SIP/Nextiva-00000002”, “0?skip”) in new stack
– Executing [s@ivr-2:7] Answer(“SIP/Nextiva-00000002”, “”) in new stack
– Executing [s@ivr-2:8] Wait(“SIP/Nextiva-00000002”, “1”) in new stack
> 0x7f047c00a700 – Strict RTP switching to RTP target address 208.73.144.74:19006 as source
– Executing [s@ivr-2:9] Set(“SIP/Nextiva-00000002”, “IVR_MSG=custom/After_Hours_IVR-2”) in new stack
– Executing [s@ivr-2:10] Set(“SIP/Nextiva-00000002”, “TIMEOUT(digit)=3”) in new stack
– Digit timeout set to 3.000
– Executing [s@ivr-2:11] ExecIf(“SIP/Nextiva-00000002”, “1?Background(custom/After_Hours_IVR-2)”) in new stack
– <SIP/Nextiva-00000002> Playing ‘custom/After_Hours_IVR-2.slin’ (language ‘en’)
> 0x7f047c00a700 – Strict RTP learning complete - Locking on source address 208.73.144.74:19006
== Spawn extension (ivr-2, s, 11) exited non-zero on ‘SIP/Nextiva-00000002’
– Executing [h@ivr-2:1] Hangup(“SIP/Nextiva-00000002”, “”) in new stack
== Spawn extension (ivr-2, h, 1) exited non-zero on ‘SIP/Nextiva-00000002’
– SIP/Nextiva-00000002 Internal Gosub(crm-hangup,s,1) start
– Executing [s@crm-hangup:1] NoOp(“SIP/Nextiva-00000002”, “Sending Hangup to CRM”) in new stack
– Executing [s@crm-hangup:2] NoOp(“SIP/Nextiva-00000002”, “HANGUP CAUSE: 16”) in new stack
– Executing [s@crm-hangup:3] ExecIf(“SIP/Nextiva-00000002”, “0?Set(__CRM_VOICEMAIL=)”) in new stack
– Executing [s@crm-hangup:4] NoOp(“SIP/Nextiva-00000002”, “MASTER CHANNEL: 1552883827.2 = 1552883827.2”) in new stack
– Executing [s@crm-hangup:5] GotoIf(“SIP/Nextiva-00000002”, “0?return”) in new stack
– Executing [s@crm-hangup:6] Set(“SIP/Nextiva-00000002”, “__CRM_HANGUP=1”) in new stack
– Executing [s@crm-hangup:7] AGI(“SIP/Nextiva-00000002”, “sangomacrm.agi”) in new stack
– Launched AGI Script /var/lib/asterisk/agi-bin/sangomacrm.agi
– <SIP/Nextiva-00000002>AGI Script sangomacrm.agi completed, returning 0
– Executing [s@crm-hangup:8] Return(“SIP/Nextiva-00000002”, “”) in new stack
== Spawn extension (ivr-2, h, 1) exited non-zero on ‘SIP/Nextiva-00000002’
– SIP/Nextiva-00000002 Internal Gosub(crm-hangup,s,1) complete GOSUB_RETVAL=


This is what the CDR see’s


Call Date - Sun, 17 Mar 2019 21:37
System - 1552883827.2
Caller ID - XXXXXX6958
DID - XXXXXX8743
App - BackGround
Destination - s [ivr-2]
Disposition - ANSWERED
Duration - 00:05


Any help would be greatly appreciated.

In the PEER Details section of your trunk, add
context=from-pstn-toheader

If it’s already there, please post (redacted) trunk settings.

If it doesn’t help, report whether the console dump now shows the from-pstn-toheader context. If so, post another dump.

I got it to work.

I had to edit the several settings.

Not sure why but I had to add this line to “Peer Details” I also used “context=from-trunk” in the user details.


context=custom-get-did-from-sip


Then I had to modify the “extensions_custom.conf”


[custom-get-did-from-sip]
exten => _X!,1,Goto(from-trunk,${CUT(CUT(SIP_HEADER(To),@,1),:,2)},1)


I would love if someone could point me to some docs on what the syntax of that last section is. I would like to know so if I ever run into a similar issue I could modify it to what I need.

Glad that you got it to work.

Your custom code seems like it does the same thing (for a chan_sip trunk) as from-pstn-toheader. What went wrong when you tried that?

If the hosts are the same, chan_sip can’t distinguish peer from user, since it’s just looking at the IP address. Best practice for two-way trunks is to put everything in the peer details, leaving the incoming section blank, except for the register string.

CUT(SIP_HEADER(To),@,1)
splits its argument on ‘@’ and takes the first field, i.e. all the stuff before the at sign.
Then,
CUT(CUT(SIP_HEADER(To),@,1),:,2)
splits its argument on ‘:’ and takes the second field, i.e. all the stuff after the colon.
What’s left is the called number.

https://wiki.asterisk.org/wiki/display/AST/Asterisk+11+Function_CUT

Did you try a pjsip trunk? That’s usually easier to set up, though a few providers have quirks it can’t handle.

Sry for the delay in response. As you stated, I think the main problem was I was putting the context string in the user details. I have been installing freepbx systems for a while but I have never jumped this deep into how the code is actually working. I am going to be onsite tomorrow. I am going to do an experiment with removing the “custom” code part and just sticking “from-pstn-toheader” in the peer details and I will let you know what happens.

Thank you very much for the link on the cut function.
So if I am to understand this correctly the “CUT” function takes a specified string “To” line on the “SIP Header” packet. The first function which I am assuming with the “1” on the second parameter is to be the first to be executed is always “before” the specified character, in this case the “@” and then when it gets nested in the second cut function it basically operates in this fashion.

Go to specified line “To”, take string characters before the “@” but only after the “:” and use this as the DID called? So on this next line it would see the line, but parse the string and first grab everything before the “@” symbol right before the IP address, but the second function would then cut off everything from the “:” and before?

To: “1234567890 1234567890” <sip:[email protected]>

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