Asterisk + Linksys SPA400

Hi everyone

I'm using Asterisk 1.18.13 + 2 Linksys SPA400 (firmware I need select each FXO port to make outbound calls, and too identify incoming calls by FXO port.
I found this code to solve my problem:
  for incoming:

exten => spa400,1,Set(TOLINE=${SIP_HEADER(To)})
exten => spa400,n,Set(FROMLINE=${SIP_HEADER(From)})
exten => spa400,n,Set(TOLINE=${CUT(TOLINE,:,2)})
exten => spa400,n,Set(FROMLINE=${CUT(FROMLINE,:,2)})
exten => spa400,n,Set(INCOMINGLINE=${CUT(TOLINE,@,1)})
exten => spa400,n,Set(CLID=${CUT(FROMLINE,@,1)})
exten => spa400,n,Noop(${INCOMINGLINE})
exten => spa400,n,Noop(${CLID})
exten => spa400,n,Set(CALLERID(name)=PSTN)
exten => spa400,n,Set(CALLERID(num)=${CLID})
exten => spa400,n,Goto(incoming,${INCOMINGLINE},1)
exten => Linea-1,1,Dial(SIP/100,tT)
exten => Linea-2,1,Dial(SIP/101,tT)
exten => Linea-3,1,Dial(SIP/102,tT)
exten => Linea-4,1,Dial(SIP/103,tT)[/code]

for ontbound:

But, where I can put this code? will work with two SPA400?
:arrow_right: Help please

In extensions.conf.

Note that it assumes that the sip.conf entry for the gateway has its context set to incoming, and that the local devices have device names of SIP/100, upwards. I suspect that the outgoing extensions are there as examples, and you are supposed to adapt this to you specific case.

I assume you can use it for two if you duplicate it with a different context, and match different outgoing numbers.

There is a missing “$” in the outgoing example. There is also either an “_” missing, or the X’s should be specific digits.

I would strongly advise you to go to and read the chapter on dialplans, and also to study extensions.conf.sample, from the source distribution, as I don’t think your questions would have been needed if you had a basic understanding of how Asterisk is configured. The only other thing you need to know to interpret this code is the structure of SIP headers.

Thank you David55, this worked very well for me. I created two contexts for incoming:

exten => SPA93,1,Set(TOLINE=${SIP_HEADER(To)})
exten => SPA93,n,Set(FROMLINE=${SIP_HEADER(From)})
exten => SPA93,n,Set(TOLINE=${CUT(TOLINE,:,2)})
exten => SPA93,n,Set(FROMLINE=${CUT(FROMLINE,:,2)})
exten => SPA93,n,Set(INCOMINGLINE=${CUT(TOLINE,@,1)})
exten => SPA93,n,Set(CLID=${CUT(FROMLINE,@,1)})
exten => SPA93,n,Noop(${INCOMINGLINE})
exten => SPA93,n,Noop(${CLID})
exten => SPA93,n,Set(CALLERID(name)=From-SPA93)
exten => SPA93,n,Set(CALLERID(num)=${CLID})
exten => SPA93,n,Goto(from-trunk,${INCOMINGLINE},1)

exten => SPA92,1,Set(TOLINE=${SIP_HEADER(To)})
exten => SPA92,n,Set(FROMLINE=${SIP_HEADER(From)})
exten => SPA92,n,Set(TOLINE=${CUT(TOLINE,:,2)})
exten => SPA92,n,Set(FROMLINE=${CUT(FROMLINE,:,2)})
exten => SPA92,n,Set(INCOMINGLINE=${CUT(TOLINE,@,1)})
exten => SPA92,n,Set(CLID=${CUT(FROMLINE,@,1)})
exten => SPA92,n,Noop(${INCOMINGLINE})
exten => SPA92,n,Noop(${CLID})
exten => SPA92,n,Set(CALLERID(name)=From-SPA92)
exten => SPA92,n,Set(CALLERID(num)=${CLID})
exten => SPA92,n,Goto(from-trunk,${INCOMINGLINE},1)[/code]

And for outbound, this small change fixed the problem:

[outrt-5] ; test
include => outrt-5-custom
exten => _X.,1,Macro(user-callerid,LIMIT,)

exten => _X./33,1,Macro(user-callerid,LIMIT,)
exten => _X./33,n,Set(MOHCLASS=${IF($["${MOHCLASS}"=""]?default:${MOHCLASS})})
exten => _X./33,n,Set(_NODEST=)
exten => _X./33,n,Gosub(sub-record-check,s,1(out,${EXTEN},))
exten => _X./33,n,Macro(dialout-trunk,3,[b]L[/b]2${EXTEN},)
exten => _X./33,n,Macro(outisbusy,)

… but, the Freepbx no permit fill something like “L1” or “L3” (to select the SPA400 lines), it accept only numbers to prepend field. I tried but no found where change this validation script, some tip?

There is no fundamental reason to use alphanumeric values.

I need put L + one number to select a specific line in my gateway FXO… so my fxo gateway will select the line and remove LX to dial

That’s a FreePBX problem not an Asterisk one!

yes, sorry… :unamused:
… any hint will be welcome