Asterisk and UK Caller ID

Getting it to work with a TDM400 for incoming call from BT line and internal analogue phone on UK phones


To get callerid to work with the TDM400 you have to add a few options to the zapata.conf, These are,

; in the global section
usecallerid=yes
cidsignalling=v23 ; Added for UK CLI detection
cidstart=polarity ; Added for UK CLI detection

For your incoming BT line connected to an FXO module (red)

signalling=fxs_ks
callerid=asreceived ; propagate the CID received from BT

for your internal analogue phone lines connected to an FSX module (green)

signalling=fxo_ks
sendcalleridafter=2 ; the hidden option given by Slav from Digium
callerid="Dominique DECT"<621> ; the CID that any call make from this line will pushed to other phone 


In your file extension.conf I advise you to add a debug statment which will help you to see from your asterisk log if you receive the CID
You need to add the "o" flag in the Dial command to push the CID


[incoming]  ; I assume that incoming call are routed to the incoming context.
exten => s,1,Verbose(Incoming call from BT line -- CallerID=${CALLERID})                 ; add a debug line with the received CID on asterisk console
exten => s,n,Dial(Zap/1,90,190,o)  ;dial DECT base via analog interface the "o" flag push the CID as received



Latest Update

The CVS has been patched to facilitate various non-US caller ID standards including UK CID. However, Mark will not add the specific support for the X100P as "adds otherwise needless bloat to the zaptel side". Ho hum. You must either use a TDM400 with FXO module or use a patch against the latest CVS. This is available from Kevin Walsh ( kevin .at. cursor .dot. biz ). Patches written by Marc McLaughlin for v1.0 are also available and can be downloaded from LUSYN's website.

Update

A patch has just been submitted which allows the digium x100p analog line cards to receive UK caller id! It may take a little while before this patch gets included in asterisk but if you need the feature now, it can be done. The patch was designed for cvs head as of late May 2004, YMMV on other versions.

The patch

Announcement of patch on mailing list

Asrterisk/zaptel debs, currently with UK Caller ID patch, for Debian/Sarge



Unfortunately, BT does not use the standard bellcore method for transmitting caller ID information which means that Asterisk (or more specifically, the X100P interface card) can't detect it.

There is a way round this of course, and that is to use a modem that supports BT CID information, and read this off the serial port. I've managed to get an old Pace modem working quite well, along with a couple of perl scripts. Unfortunately Pace went out of business in 1999, so the only place I've found to get hold of these modems is Ebay, where you can expect to pay around 20 pounds for one.

Once you have a working modem and have turned caller ID on on it (AT#CID=1 on my Pace modem) you can integrate this with Asterisk. I've used two perl scripts, (provided on the Asterisk-dev mailing list by Jonathan McHarg, edited by me) to collect and process the CID info. The first script runs constantly in the background, listening to the modem port for any line that begins NMBR and grabbing the number it displays.


#!/usr/bin/perl
$PortName = "/dev/tts/0";
$PortObj = open(MODEM,$PortName) || die "Can't open $PortName:$!";
print MODEM "AT S7=45 S0=0 L1 V1 X4 &c1 E1 Q0 #CID=1";
while (1==1) {
 local $/ = "\n";
 while ($line=) {
   chomp;
   if ( $line =~ s/NMBR = //) {
     open(OUTFILE, ">/usr/share/cid/callerid.txt") or die "Can't open callerid.txt: $!";
     $line =~ s/^M//; # Strip off any carriage return chars
     $line =~ s/\n//; # Strip off any line feeds
                        # The output must only contain a single line.
     print OUTFILE "$line";
     close OUTFILE;
   };
 }
}


The second script is run using AGI in the extensions.conf file whenever an incoming call is detected and simply sets the CID information. My version also looks the number up in the database and adds the name of the calling party if known.


#!/usr/bin/perl

use DBI;

open(INFILE, "/usr/share/cid/callerid.txt") or die "cannot open file";
if ($callerID=) {
 my $dbh = DBI->connect ("dbi:mysql:host=alice:database=asterisk","asterisk","password") 
 or die "Can't connect to database: $DBI::errstr";
 my $sth = $dbh->prepare( "SELECT cid FROM known_numbers WHERE source='$callerID'" );
 $sth->execute();
 @row = $sth->fetchrow_array();
 print "SET CALLERID "@row"<$callerID>";
}
close INFILE;

To run this script, change the s extension in the default config to look something like:

exten => s,1,agi,/var/scratch/cid/getcid.pl
exten => s,2,Dial(extensions to ring)

Now, whenever someone rings, the CID info will be processed by asterisk.


Notes:

  • NB. You must have CID activated on your line!
  • I had some problems with the modem not activating the CID mode. In the end I simply used minicom to access the modem, issued the AT#CID=1 command, followed by AT&W to save the current config.
  • To use with a database on numbers, just create a table in a database with two columns; source and cid and populate them with a list of numbers. To not use the database just remove all the database commands from the script (including the use DBI; line)
  • For more information on CID, check out: CID FAQ
  • In the UK, it is best to turn off the caller ID in zapata.conf by adding a line usecallerid=no to the incoming channel. This makes asterisk pick the call up quicker.
  • Non-BT lines in the UK (eg cable company lines) may use another (partially bellcore compatible) standard - see here.

See also:

Getting it to work with a TDM400 for incoming call from BT line and internal analogue phone on UK phones


To get callerid to work with the TDM400 you have to add a few options to the zapata.conf, These are,

; in the global section
usecallerid=yes
cidsignalling=v23 ; Added for UK CLI detection
cidstart=polarity ; Added for UK CLI detection

For your incoming BT line connected to an FXO module (red)

signalling=fxs_ks
callerid=asreceived ; propagate the CID received from BT

for your internal analogue phone lines connected to an FSX module (green)

signalling=fxo_ks
sendcalleridafter=2 ; the hidden option given by Slav from Digium
callerid="Dominique DECT"<621> ; the CID that any call make from this line will pushed to other phone 


In your file extension.conf I advise you to add a debug statment which will help you to see from your asterisk log if you receive the CID
You need to add the "o" flag in the Dial command to push the CID


[incoming]  ; I assume that incoming call are routed to the incoming context.
exten => s,1,Verbose(Incoming call from BT line -- CallerID=${CALLERID})                 ; add a debug line with the received CID on asterisk console
exten => s,n,Dial(Zap/1,90,190,o)  ;dial DECT base via analog interface the "o" flag push the CID as received



Latest Update

The CVS has been patched to facilitate various non-US caller ID standards including UK CID. However, Mark will not add the specific support for the X100P as "adds otherwise needless bloat to the zaptel side". Ho hum. You must either use a TDM400 with FXO module or use a patch against the latest CVS. This is available from Kevin Walsh ( kevin .at. cursor .dot. biz ). Patches written by Marc McLaughlin for v1.0 are also available and can be downloaded from LUSYN's website.

Update

A patch has just been submitted which allows the digium x100p analog line cards to receive UK caller id! It may take a little while before this patch gets included in asterisk but if you need the feature now, it can be done. The patch was designed for cvs head as of late May 2004, YMMV on other versions.

The patch

Announcement of patch on mailing list

Asrterisk/zaptel debs, currently with UK Caller ID patch, for Debian/Sarge



Unfortunately, BT does not use the standard bellcore method for transmitting caller ID information which means that Asterisk (or more specifically, the X100P interface card) can't detect it.

There is a way round this of course, and that is to use a modem that supports BT CID information, and read this off the serial port. I've managed to get an old Pace modem working quite well, along with a couple of perl scripts. Unfortunately Pace went out of business in 1999, so the only place I've found to get hold of these modems is Ebay, where you can expect to pay around 20 pounds for one.

Once you have a working modem and have turned caller ID on on it (AT#CID=1 on my Pace modem) you can integrate this with Asterisk. I've used two perl scripts, (provided on the Asterisk-dev mailing list by Jonathan McHarg, edited by me) to collect and process the CID info. The first script runs constantly in the background, listening to the modem port for any line that begins NMBR and grabbing the number it displays.


#!/usr/bin/perl
$PortName = "/dev/tts/0";
$PortObj = open(MODEM,$PortName) || die "Can't open $PortName:$!";
print MODEM "AT S7=45 S0=0 L1 V1 X4 &c1 E1 Q0 #CID=1";
while (1==1) {
 local $/ = "\n";
 while ($line=) {
   chomp;
   if ( $line =~ s/NMBR = //) {
     open(OUTFILE, ">/usr/share/cid/callerid.txt") or die "Can't open callerid.txt: $!";
     $line =~ s/^M//; # Strip off any carriage return chars
     $line =~ s/\n//; # Strip off any line feeds
                        # The output must only contain a single line.
     print OUTFILE "$line";
     close OUTFILE;
   };
 }
}


The second script is run using AGI in the extensions.conf file whenever an incoming call is detected and simply sets the CID information. My version also looks the number up in the database and adds the name of the calling party if known.


#!/usr/bin/perl

use DBI;

open(INFILE, "/usr/share/cid/callerid.txt") or die "cannot open file";
if ($callerID=) {
 my $dbh = DBI->connect ("dbi:mysql:host=alice:database=asterisk","asterisk","password") 
 or die "Can't connect to database: $DBI::errstr";
 my $sth = $dbh->prepare( "SELECT cid FROM known_numbers WHERE source='$callerID'" );
 $sth->execute();
 @row = $sth->fetchrow_array();
 print "SET CALLERID "@row"<$callerID>";
}
close INFILE;

To run this script, change the s extension in the default config to look something like:

exten => s,1,agi,/var/scratch/cid/getcid.pl
exten => s,2,Dial(extensions to ring)

Now, whenever someone rings, the CID info will be processed by asterisk.


Notes:

  • NB. You must have CID activated on your line!
  • I had some problems with the modem not activating the CID mode. In the end I simply used minicom to access the modem, issued the AT#CID=1 command, followed by AT&W to save the current config.
  • To use with a database on numbers, just create a table in a database with two columns; source and cid and populate them with a list of numbers. To not use the database just remove all the database commands from the script (including the use DBI; line)
  • For more information on CID, check out: CID FAQ
  • In the UK, it is best to turn off the caller ID in zapata.conf by adding a line usecallerid=no to the incoming channel. This makes asterisk pick the call up quicker.
  • Non-BT lines in the UK (eg cable company lines) may use another (partially bellcore compatible) standard - see here.

See also:
Created by: drbob, Last modification: Tue 13 of Aug, 2013 (02:05 UTC) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+