Hi everyone, I'm new here and I'm new too with telephony, so maybe my problem is that I can't understand what I'm doing. Anyway, I have this code trying to make a call to an ip-telephone in my network. I'm using Net::SIP:Simple to do this, and after a loong time using the test and error method to write the program finally I can send a Invite Request without an error, but the PBX send me now an Option Request, when I send a 200 Ok Response to the PBX it sends me the same Request again, so as you can see I'm in a dead point now and I don't know what to do.
This is the code:
#!/usr/bin/perl
use IO::Socket::INET;
use Net::SIP::Leg;
use Net::SIP::Simple;
use Net::SIP::Simple::Call;
use Net::SIP::Simple::RTP;
use Net::SIP::Dispatcher;
use Net::SIP::Dispatcher::Eventloop;
use Net::SIP::Endpoint;
use Net::SIP::Endpoint::Context;
use Net::SIP::Packet;
use Net::SIP::Request;
$| = 1;
my $ip_me = 'xxx.xxx.xx.xx'; #The server where the code is executed
my $ip_pbx = 'yyy.yyy.yy.yy'; #The PBX
my $ip_to = 'zzz.zzz.zz.zzz'; #The phone ip
# create new socket and leg
print 'CREATING SOCKET AND LEG... ';
my $sock_tel_1 = IO::Socket::INET->new(LocalAddr => $ip_me, PeerAddr => $ip_pbx, PeerPort => '5060'
+, Proto => 'udp') or die "Can't bind : $@\n";
my $leg_tel_1 = Net::SIP::Leg->new( sock => $sock_tel_1);
print 'OK'.$/;
# create new rtp
print 'CREATING RTP... ';
my $echo_10 = Net::SIP::Simple->rtp( 'media_recv_echo', 'output.pcmu-8000' );
print 'OK'.$/;
# create new agent
print 'CREATING AGENT... ';
my $ua = Net::SIP::Simple->new(
registrar => $ip_pbx,
domain => 'mydomain.com',
from => 'user@mydomain.com',
leg => $leg_tel_1,
auth => ['user','password']
);
print $ua->error.' ';
print 'OK'.$/;
# get endpoint
print 'GETTING ENDPOINT... ';
my $endpoint = $ua->{endpoint};
print 'OK'.$/;
# get dispatcher
print 'GETTING DISPATCHER... ';
my $disp = $ua->{dispatcher};
print 'OK'.$/;
# Register agent
my $err = '';
print 'TRY TO REGISTER... ';
$ua->register();
$err = $ua->error;
if ($err ne ''){
print $err.$/;
}else{
print 'OK'.$/;
}
# Invite other party, send anncouncement once connected
print 'SEND INVITE... ';
my $call = $ua->invite( $ip_to, init_media => $echo_10);
$err = $ua->error;
if ($err ne ''){
print $err.$/;
}else{
print 'OK'.$/;
}
# Receive response/request
print 'RECEIVE REQUEST/RESPONSE... '.$/;
my ($packet,$ipport) = $leg_tel_1->receive;
print $packet->as_string.$/;
print 'OK'.$/;
# create a new context;
print 'CREATE CONTEXT... ';
$ctx = Net::SIP::Endpoint::Context->new(
incoming => 1,
from => scalar( $packet->get_header( 'from' )),
to => scalar( $packet->get_header( 'to' )),
remote_contact => scalar( $packet->get_header( 'contact' )),
callid => scalar( $packet->get_header( 'call-id' )),
via => [ $packet->get_header( 'via' ) ],
);
print 'OK'.$/;
# Create and send Response
my $response = $packet->create_response( '200','Ok',$call->{options} );
print $response->as_string.$/;
$endpoint->new_response( $ctx,$response,$leg_tel_1,$ip_to.':5060' );
# Receive response/request
print 'RECEIVE REQUEST/RESPONSE... '.$/;
my ($packet,$ipport) = $leg_tel_1->receive;
print $packet->as_string.$/;
print 'OK'.$/;
And this is the output:
CREATING SOCKET AND LEG... OK
CREATING RTP... OK
CREATING AGENT... OK
GETTING ENDPOINT... OK
GETTING DISPATCHER... OK
TRY TO REGISTER... OK
SEND INVITE... OK
RECEIVE REQUEST/RESPONSE...
OPTIONS user@xxx.xxx.xx.xx:35350 SIP/2.0
Via: SIP/2.0/UDP yyy.yyy.yy.yy:5060;branch=z9hG4bK06291840;rport
From: "asterisk" <sip:asterisk@yyy.yyy.yy.yy>;tag=as43c708cf
To: <user@xxx.xxx.xx.xx:35350>
Contact: <sip:asterisk@yyy.yyy.yy.yy>
Call-ID: 44dae00b34fa36304c11b779127f6c8d@yyy.yyy.yy.yy
CSeq: 102 OPTIONS
User-Agent: Asterisk PBX
Max-Forwards: 70
Date: Thu, 23 Sep 2010 21:09:03 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY
Content-Length: 0
OK
CREATE CONTEXT... OK
SIP/2.0 200 Ok
Accept: application/sdp
Accept-encoding:
Accept-language: en
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE
Call-id: 44dae00b34fa36304c11b779127f6c8d@yyy.yyy.yy.yy
Cseq: 102 OPTIONS
From: "asterisk" <sip:asterisk@yyy.yyy.yy.yy>;tag=as43c708cf
Supported:
To: <user@xxx.xxx.xx.xx:35350>
Via: SIP/2.0/UDP yyy.yyy.yy.yy:5060;branch=z9hG4bK06291840;rport
Content-length: 0
RECEIVE REQUEST/RESPONSE...
OPTIONS user@xxx.xxx.xx.xx:35350 SIP/2.0
Via: SIP/2.0/UDP yyy.yyy.yy.yy:5060;branch=z9hG4bK0843fb37;rport
From: "asterisk" <sip:asterisk@yyy.yyy.yy.yy>;tag=as536fab35
To: <user@xxx.xxx.xx.xx:35350>
Contact: <sip:asterisk@yyy.yyy.yy.yy>
Call-ID: 37966fe56ee040b40b89626535f0a09c@yyy.yyy.yy.yy
CSeq: 102 OPTIONS
User-Agent: Asterisk PBX
Max-Forwards: 70
Date: Thu, 23 Sep 2010 21:09:14 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY
Content-Length: 0
OK
As you can see, I get the same Request from the PBX.
Pleeeeease I need help with this code, it's breaking my head.