Cisco 7940-7960 auto-answer config

Taken directly from a post by John Todd:

Subject: Office-wide paging with Asterisk and Cisco 7960 7940 phones

I spoke the other day about my preliminary tests with office-wide paging with Cisco phones
using the new SIP 6.1 image which supports auto-answer.

I've got a small and crude recipe for those of you who want to experiment and hopefully create some better and more complete examples than the one I've thrown together below.

Create a new line on each of the Cisco phones, and put the configuration into sip.conf as you normally would. I figure you have enough clue to create a new line in sip.conf and on your Cisco phones at this point. Go into settings -> Call Preferences -> Auto Answer (intercom) and then make the "new" line you've just created as auto-answer. (I wish there was a way to do this via the configuration file! Having to set this while sitting in front of the phone is silly and wasteful.) Note - A way to set this via a script is suggested in the "Setting auto_answer" section below

Now that you have created a valid Asterisk-capable SIP line that auto-answers, here's how you get the paging features to work:

Here's what I have in extensions.conf:

[conference]
exten => 5555,1,AbsoluteTimeout(21)
exten => 5555,2,AGI(callall)
exten => 5555,3,MeetMe(5555,dq)
exten => 5555,4,Hangup

exten => t,1,Hangup
exten => T,1,Hangup
exten => h,1,Hangup
;
[add-to-conference]
exten => start,1,AbsoluteTimeout(20)
exten => start,2,MeetMe(5555,dmq)
exten => h,1,Hangup
exten => t,1,Hangup
exten => T,1,Hangup

Here are the contents of /var/lib/asterisk/agi-bin/callall

#!/bin/sh
cp /var/lib/asterisk/agi-bin/*conf /var/spool/asterisk/outgoing


Make sure to make the script executable.

And then for every extension I have as an auto-answer, I have a file like this
in /var/lib/asterisk/agi-bin:

Channel: SIP/2006
Context: add-to-conference
WaitTime: 2
Extension: start
Priority: 1
CallerID: Office Pager <5555>

So, I have three lines that are configured for automatic answering - SIP/2006, SIP/2007, SIP/2008. I have three files named 2006-conf, 2007-conf, 2008-conf in /var/lib/asterisk/agi-bin that get copied into the outgoing call spool directory every time I call extension 5555. These three lines are the auto-answer lines on each of the three phone devices I'm experimenting with.

Now, dial 5555 from any phone and you should have one-way paging. Voila! People who use the pager may have to get used to waiting 1-2 seconds before speaking to allow all the phones to catch up with the audio stream. All of the phones hang up after 20 seconds, regardless of if the person originating the page has stopped talking. Change the AbsoluteTimeout values to increase this interval.

If you want a really confusing loud mess, then change the "dmq" options to "dq" and you'll get an N-way conversation going with everyone who has a phone. Bad.

If you want a really interesting office surveillance tool, change the "dmq" to "dt" and you'll suddenly be listening to all of the extensions in the office, like some kind of mega-snoop tool. Useful for after-hours listening throughout the entire office.

Someone should improve my scripts with the following changes:
  1. AGI should automatically show the caller ID of the person originating the call instead of a generic pager address
  2. The AGI should take arguments of what extensions to call and then dynamically create the list of files that get copied out to the /var/spool/asterisk/outgoing directory

JT

Improved extension.conf (evolved with new Asterisk features):

extensions.conf without the need for a timeout:

[conference]
exten => 5555,1,AGI(callall)
exten => 5555,2,MeetMe(5555,dtqp) ; press # to exit the conference
exten => 5555,3,MeetMeAdmin(5555,K) ; kick all users out
exten => 5555,4,Hangup
exten => h,1,Hangup
;
[add-to-conference]
exten => start,1,MeetMe(5555,dmqp)
exten => h,1,Hangup


Here is a much improved version of the paging function:

First setup a second extension for each phone that is +100 of the base extension (ie. base=200, intercom=300)
Under the extensions.conf add each of your intercom extensions to the intercom context
extensions.conf

[intercom]
exten => *30,1,AGI(callall|5555|${CALLERIDNUM}|300|302) ; Change to match the range of extensions you want to page
exten => *30,2,Hangup
exten => h,1,Hangup

exten => 300,1,Macro(call-intercom,300)
exten => 301,1,Macro(call-intercom,301)
exten => 302,1,Macro(call-intercom,302)
; add your extensions here

[macro-call-intercom]
exten => s,1,AGI(callall|${CALLERIDNUM}|${CALLERIDNUM}|${ARG1}|${ARG1})
exten => s,2,Hangup
exten => h,1,Hangup

[add-to-intercom]
exten => start,1,Playback(beep)
exten => start,2,MeetMe(${iConf},${iConfParm})
exten => start,3,Macro(hangupcall)
exten => h,1,Hangup


Then in callall:

#!/bin/sh

# Parameters are: [conference number] [callers number] [start call number] [end call number]

asteriskdir=/var/spool/asterisk/outgoing/
outdir=/var/lib/asterisk/agi-bin/intercom/

conf=$2
startchan=$3
endchan=$4

if [[ "$2" == "" ]]; then
conf=5555
fi

if [[ "$3" == "" ]]; then
startchan=300
fi

if [[ "$4" == "" ]]; then
endchan=302
fi

intercom=$(($1+100)) # Change me if you need a bigger offset between the extensions

for (( channel=$startchan ; channel <= $endchan ; channel++ )) do

if [[ $1 != $channel && $intercom != $channel ]]; then
echo Channel: SIP/$channel > $outdir$channel-conf
echo Context: add-to-intercom >> $outdir$channel-conf
echo Extension: start >> $outdir$channel-conf
echo Priority: 1 >> $outdir$channel-conf
echo WaitTime: 2 >> $outdir$channel-conf
echo CallerID: Intercom \<$1\> >> $outdir$channel-conf
echo MaxRetries: 0 >> $outdir$channel-conf
echo SetVar: iConf=$conf >> $outdir$channel-conf
if [[ $startchan == $endchan ]]; then
echo SetVar: iConfParm=dqp >> $outdir$channel-conf
else
echo SetVar: iConfParm=dmqp >> $outdir$channel-conf
fi
fi
done

mv $outdir*conf $asteriskdir

if [[ $startchan == $endchan ]]; then
echo EXEC meetme $conf\|dqp
else
echo EXEC meetme $conf\|dtqp
fi
echo EXEC MeetMeAdmin $conf\|K

Change the default startchan and endchan to match your configuration.
You might also want to rename the conf-kick.gsm and replace it with the beep.gsm

This will allow you to call an intercom number, it will beep and you can talk, or dial *30 and page all the intercom phones, they will beep before you talk, and then beep again before hanging up. Also the caller can just hang up instead of hitting pound.

Setting auto_answer

As noted above, the 79xx does not support setting auto_answer via a config file. This means users have to go into the menus on the phones themselves to do it. One solution is to use the below script. It logs in via telnet and simulates keypresses in order to set auto_answer. While not an ideal solution it seems the best there is. It has only been tested on a small number of phones.


 
#!/usr/bin/perl

#Set auto_answer on cisco 79xx phone via telnet.
#Hack around the inability of the sip software to set via a config file.

#Public domain, no warranty at all. (http://www.comtek.co.uk)

use Net::Telnet();
use List::Util qw(reduce);
use constant PROMPT => "SIP Phone";
use constant PASSWORD => "roline2";

@to_set=();
@to_unset=();

if((@ARGV<3)||(!(@ARGV%2)))
{
        print "Syntax: set_auto_answer <ip> <list>\n\twhere <list> is a list of "
          ." one or more '<line num> <0|1>'\n"
          ."\nEg: set_auto_answer 1.1.1.1 1 0 2 1\n";
        exit 1;
}
$target_ip=shift;

do
{
        my ($line, $setting)=(shift, shift);
        if($setting)
        {
                push(@to_set, $line);
        }
        else
        {
                push(@to_unset, $line);
        }
}while(@ARGV);

#For logs, use "" or *STDOUT
$t=new Net::Telnet(Timeout => 1, Output_log => "", Input_log => "", Dump_log => "");
$t->open($target_ip);

$t->waitfor('/Password :.*$/');
$t->print(PASSWORD);

$t->waitfor('/'.PROMPT.'>.*$/');

@tmp=$t->cmd("show config");
@tmp=grep(/^auto_answer : /, @tmp);
die("Bad auto_answer")
  if(scalar(@tmp)!=1);

@tmp[0]=~/([0-9]+)/;
$auto_answer=$1;

@to_set=grep {  !(1<<($_-1) & $auto_answer)  } @to_set;
@to_unset=grep {1<<($_-1) & $auto_answer} @to_unset;

exit 0
  if( !@to_unset && !@to_set  );

print "Enabling auto-answer for line(s): ".(reduce {$a.", ".$b} @to_set)."\n"
  if(@to_set);
print "Disabling auto-answer for line(s): ".(reduce {$a.", ".$b} @to_unset)."\n"
  if(@to_unset);

$t->print("test open");

sub wait_then_press
{
        foreach my $key (@_)
        {
                $t->waitfor('/'.PROMPT.'>.*$/');
                $t->print("test ".$key);
        }
}

sub toggle_line
{
        my($line)=@_;
        wait_then_press("offhook", "onhook", "key set", "key 6", "key 8", "key ".$line, "key soft1", "key soft2", "key soft2", "key set");
}

foreach my $line (@to_unset, @to_set)
{
        print "Toggling line: $line\n";
        toggle_line($line);
}

$t->waitfor('/'.PROMPT.'>.*$/');
$t->print("test close");

$t->waitfor('/'.PROMPT.'>.*$/');
$t->print("exit");

print "Success.\n";



See also




Taken directly from a post by John Todd:

Subject: Office-wide paging with Asterisk and Cisco 7960 7940 phones

I spoke the other day about my preliminary tests with office-wide paging with Cisco phones
using the new SIP 6.1 image which supports auto-answer.

I've got a small and crude recipe for those of you who want to experiment and hopefully create some better and more complete examples than the one I've thrown together below.

Create a new line on each of the Cisco phones, and put the configuration into sip.conf as you normally would. I figure you have enough clue to create a new line in sip.conf and on your Cisco phones at this point. Go into settings -> Call Preferences -> Auto Answer (intercom) and then make the "new" line you've just created as auto-answer. (I wish there was a way to do this via the configuration file! Having to set this while sitting in front of the phone is silly and wasteful.) Note - A way to set this via a script is suggested in the "Setting auto_answer" section below

Now that you have created a valid Asterisk-capable SIP line that auto-answers, here's how you get the paging features to work:

Here's what I have in extensions.conf:

[conference]
exten => 5555,1,AbsoluteTimeout(21)
exten => 5555,2,AGI(callall)
exten => 5555,3,MeetMe(5555,dq)
exten => 5555,4,Hangup

exten => t,1,Hangup
exten => T,1,Hangup
exten => h,1,Hangup
;
[add-to-conference]
exten => start,1,AbsoluteTimeout(20)
exten => start,2,MeetMe(5555,dmq)
exten => h,1,Hangup
exten => t,1,Hangup
exten => T,1,Hangup

Here are the contents of /var/lib/asterisk/agi-bin/callall

#!/bin/sh
cp /var/lib/asterisk/agi-bin/*conf /var/spool/asterisk/outgoing


Make sure to make the script executable.

And then for every extension I have as an auto-answer, I have a file like this
in /var/lib/asterisk/agi-bin:

Channel: SIP/2006
Context: add-to-conference
WaitTime: 2
Extension: start
Priority: 1
CallerID: Office Pager <5555>

So, I have three lines that are configured for automatic answering - SIP/2006, SIP/2007, SIP/2008. I have three files named 2006-conf, 2007-conf, 2008-conf in /var/lib/asterisk/agi-bin that get copied into the outgoing call spool directory every time I call extension 5555. These three lines are the auto-answer lines on each of the three phone devices I'm experimenting with.

Now, dial 5555 from any phone and you should have one-way paging. Voila! People who use the pager may have to get used to waiting 1-2 seconds before speaking to allow all the phones to catch up with the audio stream. All of the phones hang up after 20 seconds, regardless of if the person originating the page has stopped talking. Change the AbsoluteTimeout values to increase this interval.

If you want a really confusing loud mess, then change the "dmq" options to "dq" and you'll get an N-way conversation going with everyone who has a phone. Bad.

If you want a really interesting office surveillance tool, change the "dmq" to "dt" and you'll suddenly be listening to all of the extensions in the office, like some kind of mega-snoop tool. Useful for after-hours listening throughout the entire office.

Someone should improve my scripts with the following changes:
  1. AGI should automatically show the caller ID of the person originating the call instead of a generic pager address
  2. The AGI should take arguments of what extensions to call and then dynamically create the list of files that get copied out to the /var/spool/asterisk/outgoing directory

JT

Improved extension.conf (evolved with new Asterisk features):

extensions.conf without the need for a timeout:

[conference]
exten => 5555,1,AGI(callall)
exten => 5555,2,MeetMe(5555,dtqp) ; press # to exit the conference
exten => 5555,3,MeetMeAdmin(5555,K) ; kick all users out
exten => 5555,4,Hangup
exten => h,1,Hangup
;
[add-to-conference]
exten => start,1,MeetMe(5555,dmqp)
exten => h,1,Hangup


Here is a much improved version of the paging function:

First setup a second extension for each phone that is +100 of the base extension (ie. base=200, intercom=300)
Under the extensions.conf add each of your intercom extensions to the intercom context
extensions.conf

[intercom]
exten => *30,1,AGI(callall|5555|${CALLERIDNUM}|300|302) ; Change to match the range of extensions you want to page
exten => *30,2,Hangup
exten => h,1,Hangup

exten => 300,1,Macro(call-intercom,300)
exten => 301,1,Macro(call-intercom,301)
exten => 302,1,Macro(call-intercom,302)
; add your extensions here

[macro-call-intercom]
exten => s,1,AGI(callall|${CALLERIDNUM}|${CALLERIDNUM}|${ARG1}|${ARG1})
exten => s,2,Hangup
exten => h,1,Hangup

[add-to-intercom]
exten => start,1,Playback(beep)
exten => start,2,MeetMe(${iConf},${iConfParm})
exten => start,3,Macro(hangupcall)
exten => h,1,Hangup


Then in callall:

#!/bin/sh

# Parameters are: [conference number] [callers number] [start call number] [end call number]

asteriskdir=/var/spool/asterisk/outgoing/
outdir=/var/lib/asterisk/agi-bin/intercom/

conf=$2
startchan=$3
endchan=$4

if [[ "$2" == "" ]]; then
conf=5555
fi

if [[ "$3" == "" ]]; then
startchan=300
fi

if [[ "$4" == "" ]]; then
endchan=302
fi

intercom=$(($1+100)) # Change me if you need a bigger offset between the extensions

for (( channel=$startchan ; channel <= $endchan ; channel++ )) do

if [[ $1 != $channel && $intercom != $channel ]]; then
echo Channel: SIP/$channel > $outdir$channel-conf
echo Context: add-to-intercom >> $outdir$channel-conf
echo Extension: start >> $outdir$channel-conf
echo Priority: 1 >> $outdir$channel-conf
echo WaitTime: 2 >> $outdir$channel-conf
echo CallerID: Intercom \<$1\> >> $outdir$channel-conf
echo MaxRetries: 0 >> $outdir$channel-conf
echo SetVar: iConf=$conf >> $outdir$channel-conf
if [[ $startchan == $endchan ]]; then
echo SetVar: iConfParm=dqp >> $outdir$channel-conf
else
echo SetVar: iConfParm=dmqp >> $outdir$channel-conf
fi
fi
done

mv $outdir*conf $asteriskdir

if [[ $startchan == $endchan ]]; then
echo EXEC meetme $conf\|dqp
else
echo EXEC meetme $conf\|dtqp
fi
echo EXEC MeetMeAdmin $conf\|K

Change the default startchan and endchan to match your configuration.
You might also want to rename the conf-kick.gsm and replace it with the beep.gsm

This will allow you to call an intercom number, it will beep and you can talk, or dial *30 and page all the intercom phones, they will beep before you talk, and then beep again before hanging up. Also the caller can just hang up instead of hitting pound.

Setting auto_answer

As noted above, the 79xx does not support setting auto_answer via a config file. This means users have to go into the menus on the phones themselves to do it. One solution is to use the below script. It logs in via telnet and simulates keypresses in order to set auto_answer. While not an ideal solution it seems the best there is. It has only been tested on a small number of phones.


 
#!/usr/bin/perl

#Set auto_answer on cisco 79xx phone via telnet.
#Hack around the inability of the sip software to set via a config file.

#Public domain, no warranty at all. (http://www.comtek.co.uk)

use Net::Telnet();
use List::Util qw(reduce);
use constant PROMPT => "SIP Phone";
use constant PASSWORD => "roline2";

@to_set=();
@to_unset=();

if((@ARGV<3)||(!(@ARGV%2)))
{
        print "Syntax: set_auto_answer <ip> <list>\n\twhere <list> is a list of "
          ." one or more '<line num> <0|1>'\n"
          ."\nEg: set_auto_answer 1.1.1.1 1 0 2 1\n";
        exit 1;
}
$target_ip=shift;

do
{
        my ($line, $setting)=(shift, shift);
        if($setting)
        {
                push(@to_set, $line);
        }
        else
        {
                push(@to_unset, $line);
        }
}while(@ARGV);

#For logs, use "" or *STDOUT
$t=new Net::Telnet(Timeout => 1, Output_log => "", Input_log => "", Dump_log => "");
$t->open($target_ip);

$t->waitfor('/Password :.*$/');
$t->print(PASSWORD);

$t->waitfor('/'.PROMPT.'>.*$/');

@tmp=$t->cmd("show config");
@tmp=grep(/^auto_answer : /, @tmp);
die("Bad auto_answer")
  if(scalar(@tmp)!=1);

@tmp[0]=~/([0-9]+)/;
$auto_answer=$1;

@to_set=grep {  !(1<<($_-1) & $auto_answer)  } @to_set;
@to_unset=grep {1<<($_-1) & $auto_answer} @to_unset;

exit 0
  if( !@to_unset && !@to_set  );

print "Enabling auto-answer for line(s): ".(reduce {$a.", ".$b} @to_set)."\n"
  if(@to_set);
print "Disabling auto-answer for line(s): ".(reduce {$a.", ".$b} @to_unset)."\n"
  if(@to_unset);

$t->print("test open");

sub wait_then_press
{
        foreach my $key (@_)
        {
                $t->waitfor('/'.PROMPT.'>.*$/');
                $t->print("test ".$key);
        }
}

sub toggle_line
{
        my($line)=@_;
        wait_then_press("offhook", "onhook", "key set", "key 6", "key 8", "key ".$line, "key soft1", "key soft2", "key soft2", "key set");
}

foreach my $line (@to_unset, @to_set)
{
        print "Toggling line: $line\n";
        toggle_line($line);
}

$t->waitfor('/'.PROMPT.'>.*$/');
$t->print("test close");

$t->waitfor('/'.PROMPT.'>.*$/');
$t->print("exit");

print "Success.\n";



See also




Created by: jkstark, Last modification: Wed 03 of Dec, 2008 (22:42 UTC) by iancomtek
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+