Forwarding DID to extension


I would like to forward the original DID to an internal extension. So that in the SIP header the TO field is the DID and not the extension number. Is this possible?

Behind my FreePBX is an ISDN gateway which is connected to an old Aastra PBX. I need to forward the DID to the ISDN gateway so the gateway can handle the routing based on the DID. On the ISDN gateway the FreePBX extension is already connected as a trunk. Incoming calls are routed to the ISDN gateway successfully. But the gateway sees only the FreePBX extension number and not the original DID in the TO field. So it cannot handle the calls based on the original DID.

Is there a solution for that? Like a custome extension?

Look into the [from-did-direct] context

@dicko Thanks for the suggestion. But I am not quite sure how to solve this with the [from-did-direct] context. I have set the context on the extension under Advanced > Context but nothing changed. There is still only the extension number in the TO field.

Are you talking about transfers initiated by a SIP phone? If you use the phone’s own attended transfer feature, Asterisk doesn’t know that the call is a transfer at the point when the outbound leg is started. If you use the feature codes, it does know.

The gateway connection needs to be a trunk on the PBX side as well. Why did you choose an extension?

Are you talking about transfers initiated by a SIP phone?

I am talking about an incoming external call to the FreePBX which is routed with an inbound route to the extension. The extension is used by the ISDN gateway.

The gateway connection needs to be a trunk on the PBX side as well. Why did you choose an extension?

Maybe I didn’t describe the problem well enough. This is how everything is connected:
FreePBX > LANCOM R884VA (ISDN Gateway) > Aastra Phone System (ISDN)

The FreePBX has trunk connection to a voip phone provider. For some DIDs there are inbound routes which are routed to the internal extension number 94. On the ISDN Gateway is a trunk connection to the extension 94.

So for example the number 01234 8888 10 is called. The call gets routed to 94. On the ISDN gateway I can see the incoming call. But the SIP header looks like this:

In the TO field should be the original DID 01234 8888 10 and not the 94 so the Aastra phone system can handle the call correctly.

Not tested, but I believe this should be pretty close. If you have trouble, post what you see wrong in the SIP trace.

In FreePBX, delete extension 94. Add a pjsip trunk with:
Trunk Name: 94
Secret: (same as you used for extension 94)
Registration: Receive
Authentication: Both (or as required by the Lancom).
Context: from-internal (or what you had on extension 94)

Confirm that the Lancom still registers correctly.

For the DIDs in question, the Inbound Route Set Destination should be Trunks → 94.

This sounds interesting. I will try this in a few hours and give an update on this. Thank you.

Awesome! Receiving calls is working now with this solution. This helped alot.

But on outgoing calls I allways get an authentication error in FreePBX.

[2023-01-27 18:30:06] NOTICE[21343]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'INVITE' from '<sip:[email protected];user=phone>' failed for '' (callid: [email protected]) - Failed to authenticate

After setting the registration in the trunk from “receive” to “none” the issue is resolved. But only as long as the ISDN gateway is registered. If it is reregistering the trunk, the registration to the FreePBX is failing completely and I have to revert the setting back to “receive”. I will look further into this problem and give an update if I found a solution.

Ouch. Try setting Match Inbound Authentication for the trunk to Auth Username. I am hoping this will get further but may still fail. Or maybe setting Authentication to Outbound will help, possibly also setting Match (Permit) to (assuming that the Lancom has a static address).

However, there is a basic problem, which is that the Lancom is sending caller ID in the From header. What is supposed to happen with that? When the link was an extension on the FreePBX side, did all outbound calls originating from the Lancom have the same caller ID? If so, was that intended? Acceptable? Does the SIP trunking provider permit using the caller IDs that the Aastra sends?

Also, what about calls between Aastra extensions and FreePBX extensions? If you want these to show extension numbers (rather than complete external numbers) on the destination phones, this will likely require some custom dialplan and/or multiple trunks.

Set “Match Inbound Authentication” to “Auth Username” fixed the authentication problem. But now when I try to make an outgoing call it says “Received an unknown call with DID set to ”. Also setting the authentication to “Outbound” changed nothing.

When the Lancom used the extension I was able to make outgoing calls. But it had always the same caller ID because the FROM field was the 94. This wasn’t intended. But the Lancom sends the original caller ID in the P-Preferred-Identity field. So I had hope to fix this also somehow in FreePBX.

Yes, all numbers are valid numbers. Also CLIP no screening is enabled by the provider for this trunk. So this should not be a problem at all.

Yes I know this will be another problem. But this is not a huge issue.

My ultimate goal is - and I should have said this early - that users have their old Aastra deskphone and Sangoma Phone Desktop as a softphone at the same time. So when someone tries to call a user the old deskphone and the new softphone are ringing. But I have just realised that this will be only possible when the Lancom uses an extension because for this solution I need to have a ring group for each user with the users own extension and the Lancom extension as a member. I can’t add trunks to ring groups. So I guess the trunk solution isn’t working at all :frowning:

Confirm that Context for the trunk is still set to from-internal. If it is, it sounds like the call is not being recognized as belonging to this trunk, but if that were the case, I don’t see why changing Match Inbound Authentication would make any difference. A full log of the failed call would be useful.

Is that a different number than what it is now putting in the From field? If it is, you can use a few lines of custom dial plan to fish that out and use it for outbound caller ID.

No, but if you have an Outbound Route that sends calls to Aastra extensions over the Lancom trunk, putting the Aastra extension number followed by # should work. If not, paste a log.

Another possibility, if supported by the Lancom, is having it register to multiple FreePBX extensions, corresponding to each Aastra extension.

You are correct. I had set the wrong context. Changing from from-pstn to from-internal fixed the problem with the outgoing calls. Now I am able to receive calls and make outgoing calls. Nice. I will try to fix the thing with the outbound caller ID with a custom dial plan as you said. I will try it tomorrow and post it here.

Sounds good. I will try it later.

The setup is now running as intended. Special thanks to @Stewart1 again.
I had to add the following lines to extensions_custom.conf to set the correct caller id on outgoing calls from the lancom trunk:

exten => s,1,Set(newcid=${CUT(CUT(PJSIP_HEADER(read,P-Preferred-Identity),@,1),:,2)})
exten => s,n,Set(trunknumber=${PJSIP_HEADER(read,from):5:2})
exten => s,n,ExecIf($["${trunknumber}" = "94"]?Set(CALLERID(number)=${newcid}))
exten => s,n,MacroExit()

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