Unexpected username when making an IAX2 call

Hi all,

I’m trying to make an IAX2 call between two asterisk servers. My aim is to connect asterisk server number 1 (AS1) with a SIP device(SDev) connected to asterisk server number 2 (AS2).

Both servers have the same configuration.

In my iax.conf file, there are some different servers configured like this:

[Template](!)
secret=*****
type=friend
disallow=all
allow=alaw
qualify=yes
trunk=yes

[AS1](Template)			    		
context=FROM-OTHER-AS			
host=IP.AS1.X.X


[AS2](Template)			    		
context=FROM-OTHER-AS		
host=IP.AS2.X.X


[RS1](Template)			    	
context=FROM-RS			
host=IP.RS1.X.X


[RS2](Template)
context=FROM-RS
host=IP.RS2.X.X


[AS3](Template)			    		
context=FROM-OTHER-AS		
host=IP.AS3.X.X


[AS4](Template)			    		
context=FROM-OTHER-AS		
host=IP.AS4.X.X

And in my extensions.conf file:


[TO-RS]
exten => rec,1,NoOP(Entrando REC ...)
exten => rec,n,Set(IAXVAR(PART)=${participante})
exten => rec,n,Set(IAXVAR(FILE)=${fichero})
exten => rec,n,Dial(IAX2/${server}/rec)

[FROM-RS]
exten => 100,1,Answer()
exten => 100,n,Background(thanks)
exten => 100,n,Wait(60)
exten => 100,n,Hangup 


[FROM-OTHER-AS]
exten => s,1,NoOP(FROM-OTHER-AS)
exten => s,n,Dial(SIP/${IAXVAR(PART)})

[TO-OTHER-AS]
exten => s,1,NoOP(Entrando ...)
exten => s,n,Set(IAXVAR(PART)=${SIPdev})
exten => s,n,Dial(IAX2/${server}/s)

And the AMI command I use to make this call is:

action: originate
channel: local/s@TO-OTHER-AS
context: my-context
exten: xxxx
priority: 1
variable: SIPdev=Sdev
variable: server=AS2
async:1
actionID: 1234
Timeout: 3000

So my problem is: when I try to make a call from AS1 to AS2 in the AUTHREQ sent from AS2 to AS1 says “Username (peer or user) for authentication: RS1”. So when the call goes into the dialplan, it doesn’t find the context/exten needed. Why does it use such username?? If I add the [FROM-OTHER-AS] extensions to the context “FROM-RS” it works but I want it to be clear and understandable.

Any help would be much appreciated!

Ben.