Inbound DID not being recognized on SIP Trunks

I have a trunk from a provider which does not provide the DDI number, in the inbound route if I give th DDI number, calls don’t get through to the extension.
But, if I leave the inbound route blank, it goes through. I have two trunks which need to be routed to two different extensions.

What changes must I make to obtain a DDI number when the call reaches the trunk ?

This is the registration on the system :

pjsip show contacts

  Contact:  <Aor/ContactUri...................................>  <Status....>  <RTT(ms)..>
 =========================================================================================

  Contact:  10/sip:[email protected]:5060;rinstance=62b68e6e25e  Avail             121.661
  Contact:  easybell/sip:[email protected]:5060     Avail              29.262
  Contact:  11/sip:[email protected]:52490;rinstance=3ab7c6907b  Avail               1.332

When I make calls this is what happens :

OPTIONS sip:[email protected]:5060 SIP/2.0
I get s as the number instead of the DID number here ?

<--- Transmitting SIP response (396 bytes) to UDP:192.168.99.134:52490 --->
SIP/2.0 489 Bad Event
Via: SIP/2.0/UDP 192.168.99.134:52490;rport=52490;received=192.168.99.134;branch=z9hG4bK-d8754z-86b14e6b89e9dc81-1---d8754z-
Call-ID: OWZmNzJkNjkzNDJiMmI2ZmMzZjhjMjk4ZGUxZTIyOTI.
From: <sip:[email protected]>;tag=6581d370
To: <sip:[email protected]>;tag=z9hG4bK-d8754z-86b14e6b89e9dc81-1---d8754z-
CSeq: 2 SUBSCRIBE
Server: FPBX-12.0.76.2(13.1)
Content-Length:  0


<--- Transmitting SIP request (546 bytes) to UDP:192.168.99.134:52490 --->
OPTIONS sip:[email protected]:52490;rinstance=3ab7c6907b216249 SIP/2.0
Via: SIP/2.0/UDP 77.179.197.153:5060;rport;branch=z9hG4bKPj4ae2828d-39cc-4826-ab8a-7c1e32c63e13
From: <sip:[email protected]>;tag=5c9b18be-21cc-4f43-bba9-d7ded9802313
To: <sip:[email protected];rinstance=3ab7c6907b216249>
Contact: <sip:[email protected]:5060>
Call-ID: beaa5aa8-866b-4953-be39-6e642cb08070
CSeq: 55658 OPTIONS
Max-Forwards: 70
User-Agent: FPBX-12.0.76.2(13.1)
Content-Length:  0


<--- Received SIP response (727 bytes) from UDP:192.168.99.134:52490 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 77.179.197.153:5060;rport=5060;branch=z9hG4bKPj4ae2828d-39cc-4826-ab8a-7c1e32c63e13;received=192.168.99.134
Contact: <sip:192.168.99.134:52490>
To: <sip:[email protected];rinstance=3ab7c6907b216249>;tag=f1b92b43
From: <sip:[email protected]>;tag=5c9b18be-21cc-4f43-bba9-d7ded9802313
Call-ID: beaa5aa8-866b-4953-be39-6e642cb08070
CSeq: 55658 OPTIONS
Accept: application/sdp, application/sdp
Accept-Language: en
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
Supported: replaces, norefersub, extended-refer, timer, X-cisco-serviceuri
User-Agent: Z 3.3.25608 r25552
Allow-Events: presence, kpml
Content-Length: 0


<--- Received SIP request (564 bytes) from UDP:212.172.97.124:5060 --->
OPTIONS sip:[email protected]:5060 SIP/2.0
Max-Forwards: 25
Record-Route: <sip:212.172.97.124;r2=on;lr=on;ftag=22923327;ngcplb=yes;socket=sip:212.172.97.124:5060>
Record-Route: <sip:127.0.0.1;r2=on;lr=on;ftag=22923327;ngcplb=yes;socket=sip:212.172.97.124:5060>
Via: SIP/2.0/UDP 212.172.97.124;branch=z9hG4bKf81c.44c3ae1d8f5b39e7b8fcb39c703a5dd8.0
Via: SIP/2.0/UDP 127.0.0.1:5062;rport=5062;branch=0
From: sip:[email protected];tag=22923327
To: sip:[email protected]:5060
Call-ID: [email protected]
CSeq: 1 OPTIONS
Content-Length: 0

I tried giving a custom extension, but I still keep getting the s-extension error and call does not connect to extension 11, which is in the inbound route.

The extension_custom.conf file :

context=custom-get-did-from-sip
exten => 00493012219327,1,Noop(Fixing DID using information from SIP TO header)
exten => 00493012219327,n,Set(pseudodid=${SIP_HEADER(To)})
exten => 00493012219327,n,Set(pseudodid=${CUT(pseudodid,@,1)})
exten => 00493012219327,n,Set(pseudodid=${CUT(pseudodid,:,2)})
exten => 00493012219327,n,Goto(from-trunk,${pseudodid},1)

[2016-02-18 10:21:27] NOTICE[12981]: res_pjsip_session.c:1587 new_invite: Call from 'easybell' (UDP:208.172.67.164:5060) to extension 's' rejected because extension not found in context 'custom-get-did-from-sip'.

Try adding something like:

exten => s,1,Goto([email protected])

or replace all of the 00493012219327 entries with ‘s’

@cynjut : Thanks!

But, the SIP header is coming as null in the trunk. I tried with s, I checked if there is a DNID or DID or any other information that I could use, all I was getting was the CALLER_ID.

[easybell-incoming] 
exten => s,1,NoOp(${SIP_HEADER(Via)}) ;Even tried NoOp(${SIP_HEADER(To)})
exten => s,2,goto(${CUT(CUT(SIP_HEADER(To),@,1),:,2)},1)
exten => 493012219327,NoOp(Incoming call on DDI 1)
exten => 493012219327,n,Ringing
exten => 493012219327,n,Wait(1)
exten => 493012219327,n,Dial(PJSIP/11)

You missed the 1, before the Noop.

Also, a “s,2,NoOp(${CUT(CUT(SIP_HEADER(To),@,1),:,2)},1)” might be enlightening. Obviously, put it before the GoTo. That should give you some information in your logs that you can use.