How to display caller ID when passing through Asterisk

Scenario
Asterisk FreePBX 1.6.2.11 used as a IVR to play an outgoing warning message for users so that they are aware that they are making an external call.
The source IP PBX is a Mitel 3300 and the call is passed over SIP trunks to the Asterisk, The FreePBX then plays a short message before passing the call back to the Mitel 3300. Once the call is back on the Mitel 3300 the call is then passed over to an external PSTN SIP gateway.
We are trying to get the OLI (originating calling line ID) to present correctly
Currently when dialling a call through the Asterisk I can see that the extension dialling the external number has a from field populated with it’s full PSTN number
however when the call is passed back to the Mitel SIP gateway and then passed to the external SIP gateway the OLI has now changed to the calling number that was dialled.

e.g extension 59990 dials 901234567890
this routed in to the Asterisk with the leading 9 stripped off
I can see in the SIP trace that the from field has the full PSTN number of the extn
From: <sip:01234559990@IP address of Mitel 3300>
Then I can see the calling number
To: <sip:01234567890@IP address of Asterisk>
then there is the Contact
Contact: “Handset Username” <sip:01234567890@IP address of Mitel 3300>

Later once the call has passed through the Asterisk I see
REFER sip:01234567890@IP address of Mitel 3300
From <sip:01234567890@IP address of Asterisk>
To “Handset Username” <sip:01234559990@IP address of Mitel 3300>
Contact: <sip:01234567890@IP address of Asterisk>
Refer-To: sip:7701234567890@Mitel1 (77 is the new routing digits when passing back to the Mitel 3300)
Referred-By: <sip:01234567890@IP address of Asterisk>

Then I get a Makecall
To :sip:01234567890@IP address of external SIP gateway
From :<sip:IP address of Mitel 3300>
RequestUri :sip:01234567890@IP address of external SIP gateway

So now I have lost the OLI as the calling number is now the called number 01234567890
This in turn prevents the OLI from being displayed as a caller ID

My extension.conf file has the following

[to-Asterisk]
include => from-internal
exten => _.,1,Noop(Destination number found ${EXTEN})
exten => _.,n,Noop(${CALLERID(num)}===${CALLERID(name)})
exten => _.,n,Answer
exten => _.,n,Playback(/var/lib/asterisk/sounds/custom/externalwarning)
exten => _.,n,Transfer(SIP/ 77${EXTEN}@Mitel1)
exten => _.,n,Hangup
exten => h,1,Hangup()

I think that the CALLERID may have to be changed but do not know all the context variables other that Set or Noop

Do you have any ideas as how we might get the correct CLI displayed?

As you are using the Transfer application, the call is not passing through Asterisk.

This is a Mitel issue. Normal systems, receiving a REFER, will make the new call as though it came from the original caller, but, as the Mitel is acting as a back to back user agent, SIP doesn’t mandate that behaviour.

You could try using Dial, but you will waste network capacity.

Hi thanks for the info.
I have also tried Dial instead of Transfer and I get the same result.
You are correct that when using Dial I hold up 2 SIP sessions for the duration of the call, If this is the only way to get it working then I am prepared to accept this as the call volume should not be extreme.
If I set the peer to Dial what settings will I need to change to get CLI to work?

Asterisk will pass through the caller ID by default, so you need to work out what you have set that frustrates that, or whether it is a Mitel limitation.

Are you configured as a Mitel extension and/or using fromuser? If you are configured as an extension, it is unlikely that you will be able to do what you want to do. If you are not an extension, you shouldn’t need fromdomain. In these cases, there is a very small chance that setting sendrpid will help.

Otherwise, do you have callerid set on the trunk to the Mitel?

The Mitel is set as Trunks calling not extension. Caller ID is set on Mitel as I am getting this in the trace files.
Sendrpid?
Where can I set this option? is it in FreePBX GUI or the extension.conf file?

When I was talking about callerID, I meant the callerid option on Asterisk, which will override any caller ID incoming on the line. However, looking at your trace, it would seem that that is not the problem.

This is not a FreePBX forum. sendrpid is a sip.conf option. I have no idea whether it can be set through the FreePBX GUI.

It is looking more and more to me like you need to look at the Mitel. However, can you provide the INVITE sent back to the Mitel and confirm that the user part of the From: address is the Mitel extension number. If it is, sendrpid is your last hope, but the problem is most likely on the Mitel.

It is possible that you will have to set presentation screened and allowed, using the CALLERID function, for the Mitel to actually use the RPID.