How to test if a call is originally an external call

I wish to have a distinctive ringtone for internal transfers of external calls. I have already obtained distinctive ringtones for external and internal calls. So the desired scenario is this:

  1. internal call - ringtone A on called station
  2. external call - ringtone B on all called stations
  3. internal transfer of answered external call - ringtone C on called stations.

At the moment what happens is that 1. and 2. work. But if an external call is answered and then transferred the transfer is treated as a simple internal call and the ringtone becomes A. Instead I would like to change it to C in that case.

Ringtone A is set inside extensions_override_freepbx.conf. I test for internal calls using this method:

. . .
exten => _X.,n,Set(CallerIDNum=${CALLERID(num)})
exten => _417XX,n,Set(AlertInternalCall=alert_internal_call)
e
. . .
exten => _417XX,n,GotoIf( $[$["${CallerIDNum}" > “41799”] || $["${CallerIDNum}" < “41700”]]?notfromlocal:)
exten => _417XX,n,Set(__ALERT_INFO=${AlertSnom}${AlertInternalCall})
. . .

Is there anyway of determining if an internal call is actually a forwarded call? What happens to the original caller id from the external call once it is answered. It seems not to be forwarded together with the call to the second extension.