Set outgoing MSN on ISDN based on internal MSN


I’m using Asterisk on Ubuntu with CAPI on a Fritz! Card and ZAPHFC on an internal HFC card in NT mode as well as a few SIP phones.

When I dial an external phone number with one of my internal ISDN phones, the internal ISDN phones used to have a preset for “outgoing MSN”, which was different, depending on the ISDN phone that I used. So did I use phone1 to call an external number, the outgoing MSN 123 was used, when i used a different ISDN phone, the outgoing MSN that was entered in that phone was used.

Now that my phones are connected to the internal ISDN Card of Asterisk, they still send the outgoing MSN towards Asterisk (I can tell because I see the MSN in my Sip-phone when I do an internal call ISDN-Phone to Sip-phone), but when Asterisk calls an external number, not the MSN that was used by the ISDN phone is being sent, but one of my other MSNs. If I give the outgoing rule a setting for the callerID like this:

exten => _XXXX.,1,SetCallerID(12345)
exten => _XXXX.,2,Dial(CAPI/g1/${EXTEN})
exten => _XXXX.,3,Hangup

then this MSN is being used for all outgoing calls that are initiated by the ISDN phones. What I’d need would be a way to set the outgoing MSN depending on the MSN supplied by the ISDN phone. Is this possible?

Thanks in advance!


when you’ve defined your phones in the conf files, are you able to set a callerid=xxxxxx there ? then you wouldn’t need to set one before dialling. of course, this also get’s shown internally (although it sounds as if it might be overwritten by the phone)

do your MSNs relate in any way to the internal extension numbers ? if so, you could use that as part of the command to set callerid.

other options are to use ASTDB and query that before setting callerid, or to use an AGI script and external db.

I’m still having trouble setting the outgoing MSN when calling from an internal phone (SIP or Zap) over CAPI to the PSTN.

I was wrong in my first posting. I cannot set the callerID at all! Not even by using SetCallerID (which I first thought). This is what I try: I call my mobile phone from my ISDN-phone (on Zap) and look at the mobile to see the MSN that’s being sent.

exten => _XXXX.,1,Set(CALLERID=9123456) exten => _XXXX.,2,Dial(CAPI/g1/${EXTEN}) exten => _XXXX.,3,Hangup
And this is what Asterisk shows me on the CLI:

*CLI> -- Accepting overlap voice call from '023459123456' to '<unspecified>' on channel 0/2, span 1 -- Starting simple switch on 'Zap/2-1' -- Executing Set("Zap/2-1", "CALLERID=9123456") in new stack -- Executing Dial("Zap/2-1", "CAPI/g1/01749999999") in new stack -- Called g1/01749999999 Jan 11 18:52:59 WARNING[14223]: channel.c:1639 ast_waitfor_nandfds: Thread -1228805216 Blocking 'CAPI/ISDN1/01749999999-3', already blocked by thread 0 in procedure (null) -- CAPI/ISDN1/01749999999-3 is proceeding passing it to Zap/2-1 -- CAPI/ISDN1/01749999999-3 is ringing -- Channel 0/2, span 1 got hangup request == Spawn extension (intern, 01749999999, 2) exited non-zero on 'Zap/2-1' -- Hungup 'Zap/2-1'
It all looks good. Except that I see a different number on my mobile than the one I set the call to! CAPI always seems to use one particular MSN and I haven’t made it yet that it uses a different MSN for outgoing calls.

This Executing Set(“Zap/2-1”, “CALLERID=9123456”: Shouldn’t I set the CAPI to that MSN instead Zap/2-1? Zap/2-1 is the channel I’m coming from, not the one I’m just about to use for dialing out?!? It seems I have missed something…

don’t know much about CAPI but i do know that it’s:

Set(CALLERID(number)=12345), not Set(CALLERID=9123456)

also, most telecom providers do not let you change the callerid. the telecom provider will overwrite it with their own data, which is the number you’ve been assigned by them.

[quote=“gtcleaves”]don’t know much about CAPI but i do know that it’s:

Set(CALLERID(number)=12345), not Set(CALLERID=9123456)


I changed that, but the result was the same.

Yes, off cause. But I don’t want to set a number which I have not been assigned. The MSNs that I try to set are the ones that I have been given. Also, when I disconnect Asterisk and reconnect an ISDN-Phone to the NTBA, the outgoing MSN is being set properly by the ISDN phone. There must be a way to configure Asterisk to use the outgoing MSN, but I just don’t know how.


I don’t get it! When I’m calling from a SIP phone over CAPI to PSTN, I can set the outgoing MSN with Set(CALLERID(number)=${PRIVATE}) successfully. But if I use an internal ISDN phone instead (while still using the same rule in the dialplan to do the call) the same number the Default-MSN is being sent!

This is my config:

Ubuntu 4.1.1-13 with
chan_capi 0.6.5-1

an internal HFC card in NT Mode and a Fritz card using CAPI to the PSTN.

This is the Dialplan I’m using:


PRIVATE =92345

[extern] ; Fritz-Karte in TE mode towards PSTN
exten => ${PRIVATE},1,GoTo(an_privat,${EXTEN},1)
exten => ${BUSINESS},1,GoTo(an_business,${EXTEN},1)
exten => ${TEST},1,GoTo(an_test,${EXTEN},1)

[intern] ; internal ISDN-card(HFC) in NT mode
include => parkedcalls
include => nach_extern_erlaubt ;calls to PSTN allowed
include => nach_sip_erlaubt ;calls to SIP allowed
include => voicemail_access
include => isdn_phones

[from-sip] ; Sip phones
include => parkedcalls
include => nach_extern_erlaubt
include => nach_intern_erlaubt
include => voicemail_access
; Sip phones start with 2
exten => _2X,1,Dial(SIP/${EXTEN},20,Ttr)
exten => _2X,2,Voicemail(u${EXTEN})
exten => _2X,102,Voicemail(b20)
exten => _2X,103,Hangup

[nach_extern_erlaubt] ;Rule to dial out on PSTN
exten => _XXXX.,1,NOOP
exten => _XXXX.,2,Set(CALLERID(number)=${PRIVATE})
exten => _XXXX.,3,Dial(CAPI/g1/${EXTEN})
exten => _XXXX.,4,Hangup()

exten => _2X,1,GoTo(from-sip,${EXTEN},1)

exten => _3X,1,GoTo(isdn_phones,${EXTEN},1)

[an_privat] ;Rufe an die Privatnummer; private calls
exten => ${PRIVATE},1,Dial(SIP/21&SIP/20&Zap/g2/${EXTEN},60,tTr)
exten => ${PRIVATE},2,Hangup

[an_business] ;Rufe an die Geschaeftsnummer; business calls
exten => ${BUSINESS},1,Dial(SIP/21&SIP/20&Zap/g2/${EXTEN},60,tTr)
exten => ${BUSINESS},2,Hangup

exten => ${TEST},1,Dial(SIP/20&SIP/21,60,tTr)
exten => ${TEST},2,Hangup()

exten => 30,1,Answer()
exten => 30,2,Dial(Zap/g2/${PRIVATE},60,tTr)
exten => 30,3,Hangup()

exten => 31,1,Answer()
exten => 31,2,Dial(Zap/g2/${BUSINESS},60,tTr)
exten => 31,3,Hangup()

; Direct access to the voice-mail box
exten => _5XX,1,NOOP
exten => _5XX,2,Answer()
exten => _5XX,3,VoiceMailMain(${EXTEN:1})
exten => _5XX,4,Hangup()

exten => _2X,1,GoTo(from-sip,${EXTEN},1)
exten => _3x,1,GoTo(isdn_phones,${EXTEN},1)

I can see on the CLI that the CallerID is being set on channel Zap :

It seems to me like chan_capi wouldn’t read the callerid from zap…

Help will be appreciated!



The solution was to set the callerid to the full number including the area-code but without the leading zero.

Man, that took me hours!!!


happy to hear it!