aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-07-16 18:54:19 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-07-16 18:54:19 +0200
commit2074fe653b9668023f568770de6155d7ea87434b (patch)
tree3fc10fbdf1a5d572fa141271ef13031f1e8d0c18 /misc
parent9b7332658e40e7133dfc7e8263657edd14b2b406 (diff)
perltidy
Diffstat (limited to 'misc')
-rw-r--r--misc/OGM.pl805
-rw-r--r--misc/makecall.pl657
-rw-r--r--misc/monitorCallerID.pl310
-rw-r--r--misc/monitorCallerID2.pl522
-rwxr-xr-xmisc/monitorTDE2.pl541
-rw-r--r--misc/snapshot.pl999
6 files changed, 2081 insertions, 1753 deletions
diff --git a/misc/OGM.pl b/misc/OGM.pl
index 7931379..0d4e973 100644
--- a/misc/OGM.pl
+++ b/misc/OGM.pl
@@ -1,353 +1,452 @@
-#ver 0.06 (C)Cyr
-use strict;
-use warnings;
-use diagnostics;
-use IO::Socket;
-use Convert::ASN1;
-#use Data::Dumper;
-use Carp;
-use POSIX;
-my $CSTAapdu;
-my $socket;
-my %calls;
-sub decode_msg_header {
- my $bin = shift;
- my $len = unpack('n', $bin);
- return $len;
-}
-sub encode_msg_header {
- my $len = shift;
- die "Message larger than allowed!" unless ($len <= 240);
- my $bin = pack('n', $len);
- return $bin;
-}
-sub convert_to_hex {
- my $pdu = $_[0];
- my $hexdata = unpack('H*', $pdu);
- $hexdata =~ tr/a-z/A-Z/;
- $hexdata =~ s/(..)/$1 /g;
- $hexdata =~ s/ $//g;
- return $hexdata;
-}
-sub send_pdu {
- my $pdu = $_[0];
- my $header = encode_msg_header(length($pdu));
- $socket->write($header);
- $socket->write($pdu);
-# my $hexdata = convert_to_hex($pdu);
-# print("SENT: [$hexdata]\n");
-}
-sub csta_connect {
- my %args = %{$_[0]};
- open_csta_socket($args{host}, $args{port});
- # A-ASSOCIATE Request
- my $pdu = "602380020780A10706052B0C00815ABE14281206072B0C00821D8148A007A0050303000800";
- $pdu = pack('H*', $pdu);
- send_pdu($pdu);
- # A-ASSOCIATE Result
- $pdu = receive_stuff();
- my $hexdata = convert_to_hex($pdu);
- if ($hexdata =~/A2 03 02 01 01/){
- print "rejected-permanent\n";
- exit 0
- }
- #SystemStatus Request
- $pdu = receive_stuff();
- my $out = $CSTAapdu->decode($pdu);
- my $invokeID = $out->{svcRequest}->{invokeID};
- SystemStatusResult($invokeID);
-}
-
-sub open_csta_socket {
- my $host = shift;
- my $port = shift;
- $socket = new IO::Socket::INET(
- PeerAddr => $host,
- PeerPort => $port,
- Blocking => 1,
- Proto => 'tcp') || die "Error creating socket: $!\n";
- $socket->autoflush(1);
- print("opened a connection to $host on port $port\n");
-}
-sub receive_stuff {
- my $header = '';
- my $pdu = '';
- my $nbytes = $socket->sysread($header, 2);
- if ($nbytes==1) { # фрагмент пакета
- my $header2;
- my $nbytes2= $socket->sysread($header2, 1);
- $header = $header.$header2;
- $nbytes = 2;
- }
- croak "Didn't receive the specified amount of data (2 bytes)!\n".chr(7) unless ($nbytes == 2);
- my $len = decode_msg_header($header);
- $nbytes = $socket->sysread($pdu, $len);
- if ($nbytes<$len) { # фрагмент пакета
- my $pdu2;
- my $nbytes2= $socket->sysread($pdu2, $len-$nbytes);
- $pdu = $pdu.$pdu2;
- $nbytes = $nbytes + $nbytes2;
- }
- croak "Didn't receive the specified amount of data ($len bytes)!\n".chr(7) unless ($nbytes == $len);
-# my $hexdata = convert_to_hex($pdu);
-# print("RECEIVED:[$hexdata]\n");
- return $pdu;
-}
-
-sub SystemStatusResult{
- my $invokeID = shift;
- my $pdu = $CSTAapdu->encode({svcResult=>{invokeID=>$invokeID,result=>{serviceID=>211,serviceResult=>{noData=>1}}}});
- send_pdu($pdu); # send SystemStatus Result
-}
-sub playOGM{
- my $ogmId = shift;
- if (!$ogmId) {$ogmId=10}
- my $connectionID = shift;
- my $pdu = $CSTAapdu->encode({svcRequest=>{
- invokeID=>11,
- serviceID=>51,
- serviceArgs=>{
- privateData=>{
- private =>{
- kmeResourceControl=>{
- ogmStart=>{
- connection=>$connectionID,
- ogmId=>$ogmId
- }
- }
- }
- }
- }
- }
- });
- send_pdu($pdu);
-}
-sub numberOfMsgPort{
-#EscapeArgument.privateData.private.kmeSystemData.getSystemData.request
-my $pdu = $CSTAapdu->encode({svcRequest=>{
- invokeID=>8,
- serviceID=>51,
- serviceArgs=>{
- privateData=>{
- private =>{
- kmeSystemData=>{
- getSystemData=>{
- request =>{
- systemData=>18
- }
- }
- }
- }
- }
- }
- }
- });
- send_pdu($pdu);
- while (1) {
- $pdu = receive_stuff();
- my $out = $CSTAapdu->decode($pdu);
- if (defined $out->{svcRequest}->{serviceArgs}->{privateData}->{private}->{kmeSystemData}->{systemDataLinkedReply}->{sysData}->{numberOfMsgPort}) {
- my $MsgPorts = $out->{svcRequest}->{serviceArgs}->{privateData}->{private}->{kmeSystemData}->{systemDataLinkedReply}->{sysData}->{numberOfMsgPort};
- return $MsgPorts
- }
- }
-}
-sub answer{
- my $callerID = shift;
- my $connectionID = shift;
- my $MsgPorts = numberOfMsgPort();
- #берём трубку
- my $pdu = $CSTAapdu->encode({svcRequest=>{
- invokeID=>10,
- serviceID=>2,
- serviceArgs=>{
- callToBeAnswered=>$connectionID
- }
- }
- });
- send_pdu($pdu);
- my $callID = $connectionID->{both}->{callID};
- print "answered callID:",$callID," callerID:",$callerID, "\n";
- my $numberOfFreePort = $MsgPorts->{numberOfFreePort};
- print "numberOfFreePort:",$numberOfFreePort,"\n";
- if (!$numberOfFreePort) {
- my $pdu = $CSTAapdu->encode({svcRequest=>{
- invokeID=>13,
- serviceID=>5,
- serviceArgs=>{
- connectionToBeCleared=>$connectionID
- }
- }
- });
- send_pdu($pdu);
- print "connection callID:",$callID," cleared\n";
- next
- }
- my $digits = [split('',$callerID)];
- $calls{$callID} = $digits;
- print "digits in the array:", scalar @{$calls{$callID}}, "\n";
- my $digit = shift @{$calls{$callID}};
- playOGM($digit, $connectionID)
-}
-# parse ASN.1 desciptions
-my $asn = Convert::ASN1->new;
-$asn->prepare_file('d:\111\asn_perl\kxtde.asn') or die "prepare: ", $asn->error;
-my %serviceArgs = ( 2 => 'AnswerCallArgument',
- 5 => 'ClearConnectionArgument',
- 21=> 'CSTAEventReportArgument',
- 51=> 'EscapeArgument',
-# 10=> 'MakeCallArgument',
- 71=> 'MonitorStartArgument',
- 211=> 'SystemStatusArg');
-foreach (keys %serviceArgs) {
- $asn->registertype('serviceArgs',$_,$asn->find($serviceArgs{$_}));
-}
-my %serviceResults = ( 51=> 'EscapeResult',
-# 10=> 'MakeCallResult',
- 71=> 'MonitorStartResult',
- 211=> 'SystemStatusRes');
- foreach (keys %serviceResults) {
- $asn->registertype('serviceResult',$_,$asn->find($serviceResults{$_}));
-}
-$CSTAapdu = $asn->find('CSTAapdu');
-csta_connect({'host'=>'192.168.0.101', 'port'=>33333});
-my $Number=177; # ! ICD номер
-my $MsgPorts = numberOfMsgPort();
-print "numberOfMsgPort:", $MsgPorts->{numberOfMsgPort}, "\n";
-#EscapeArgument.privateData.private.kmeSystemData.setSystemData
-my $pdu = $CSTAapdu->encode({svcRequest=>{
- invokeID=>9,
- serviceID=>51,
- serviceArgs=>{
- privateData=>{
- private =>{
- kmeSystemData=>{
- setSystemData=>{
- acdQueue =>{
- device =>{
- deviceIdentifier=>{
- dialingNumber=>$Number
- }
- },
- attribute=>{
- acdMode =>1
- }
- }
- }
- }
- }
- }
- }
- }
- });
-send_pdu($pdu);
-#EscapeArgument.privateData.private.kmeSystemData.setSystemData
-$pdu = $CSTAapdu->encode({svcRequest=>{
- invokeID=>9,
- serviceID=>51,
- serviceArgs=>{
- privateData=>{
- private =>{
- kmeSystemData=>{
- setSystemData=>{
- acdQueue =>{
- device =>{
- deviceIdentifier=>{
- dialingNumber=>$Number
- }
- },
- attribute=>{
- ctiWaitTime =>20
- }
- }
- }
- }
- }
- }
- }
- }
- });
-send_pdu($pdu);
-#monitor
-$pdu = $CSTAapdu->encode({svcRequest=>{
- invokeID=>9,
- serviceID=>71,
- serviceArgs=>{
- monitorObject=>{
- deviceObject=>{
- deviceIdentifier=>{
- dialingNumber=>$Number
- }
- }
- },
- requestedMonitorFilter=>{}
- }
- }
- });
-send_pdu($pdu);
-while (1) {
- $pdu = receive_stuff();
- #Convert::ASN1::asn_dump($pdu);
- my $out = $CSTAapdu->decode($pdu);
- # $Data::Dumper::Indent=1;
- # $Data::Dumper::Pair=' ';
- # $Data::Dumper::Quotekeys=0;
- # $Data::Dumper::Varname='CSTAapdu';
- #print Dumper($out);
- if (defined $out->{svcRequest}) {
- my $serviceID = $out->{svcRequest}->{serviceID};
- my $invokeID = $out->{svcRequest}->{invokeID};
- my $serviceArgs=$out->{svcRequest}->{serviceArgs};
- if ($serviceID==21) {
- if (defined $serviceArgs->{eventSpecificInfo}->{callControlEvents}->{delivered}) {
- my $connectionID = $serviceArgs->{eventSpecificInfo}->{callControlEvents}->{delivered}->{connection};
- if (defined $serviceArgs->{eventSpecificInfo}->{callControlEvents}->{delivered}->{callingDevice}->{deviceIdentifier}->{deviceIdentifier}->{dialingNumber}) {
- my $callerID = $serviceArgs->{eventSpecificInfo}->{callControlEvents}->{delivered}->{callingDevice}->{deviceIdentifier}->{deviceIdentifier}->{dialingNumber};
- answer($callerID, $connectionID);
- } elsif ($serviceArgs->{eventSpecificInfo}->{callControlEvents}->{delivered}->{extensions}->{privateData}[0]->{private}->{kmeAdditionalData}->{device}->{deviceIdentifier}->{other}) {
- my $callerID = $serviceArgs->{eventSpecificInfo}->{callControlEvents}->{delivered}->{extensions}->{privateData}[0]->{private}->{kmeAdditionalData}->{device}->{deviceIdentifier}->{other};
- substr($callerID, 0, 1) = "";
- answer($callerID, $connectionID);
- }
- else {print "not number\n"}
- } elsif ($serviceArgs->{eventSpecificInfo}->{callControlEvents}->{transferred}) {
- my $callID = $serviceArgs->{eventSpecificInfo}->{callControlEvents}->{transferred}->{transferredConnections}[0]->{newConnection}->{both}->{callID};
- my $oldCallID = $serviceArgs->{eventSpecificInfo}->{callControlEvents}->{transferred}->{primaryOldCall}->{both}->{callID};
- $calls{$callID} = $calls{$oldCallID};
- delete $calls{$oldCallID};
- print "transferred: new callID:",$callID,"\n";
- } elsif (defined $serviceArgs->{eventSpecificInfo}->{vendorSpecEvents}->{privateEvent}->{privateData}->{private}->{kmePrivateEvent}->{ogmStatus}) {
- my $ogmStatus=$serviceArgs->{eventSpecificInfo}->{vendorSpecEvents}->{privateEvent}->{privateData}->{private}->{kmePrivateEvent}->{ogmStatus};
- print "ogmPortNumber:",$ogmStatus->{ogmPortNumber}->{deviceIdentifier}->{deviceNumber} & 0xFFFF;
- print " ogmId:",$ogmStatus->{ogmId};
- if ($ogmStatus->{state}) {
- print " state:stop\n";
- my $connectionID = $ogmStatus->{connection};
- my $callID = $connectionID->{both}->{callID};
- if (scalar @{$calls{$callID}}) {
- print "digits in the array:", scalar @{$calls{$callID}}, "\n";
- my $digit = shift @{$calls{$callID}};
- playOGM($digit, $connectionID)
- } else {
- delete $calls{$callID};
- # кладём трубку
- my $pdu = $CSTAapdu->encode({svcRequest=>{
- invokeID=>13,
- serviceID=>5,
- serviceArgs=>{
- connectionToBeCleared=>$connectionID
- }
- }
- });
- send_pdu($pdu);
- print "connection callID:",$callID," cleared\n"
- }
- }
- else {print " state:start\n"}
- }
- } elsif ($serviceID==211) { # if SystemStatus Request
- SystemStatusResult($invokeID);
- }
-
- }
-}
+#ver 0.06 (C)Cyr
+use strict;
+use warnings;
+use diagnostics;
+use IO::Socket;
+use Convert::ASN1;
+
+#use Data::Dumper;
+use Carp;
+use POSIX;
+my $CSTAapdu;
+my $socket;
+my %calls;
+
+sub decode_msg_header {
+ my $bin = shift;
+ my $len = unpack( 'n', $bin );
+ return $len;
+}
+
+sub encode_msg_header {
+ my $len = shift;
+ die "Message larger than allowed!" unless ( $len <= 240 );
+ my $bin = pack( 'n', $len );
+ return $bin;
+}
+
+sub convert_to_hex {
+ my $pdu = $_[0];
+ my $hexdata = unpack( 'H*', $pdu );
+ $hexdata =~ tr/a-z/A-Z/;
+ $hexdata =~ s/(..)/$1 /g;
+ $hexdata =~ s/ $//g;
+ return $hexdata;
+}
+
+sub send_pdu {
+ my $pdu = $_[0];
+ my $header = encode_msg_header( length($pdu) );
+ $socket->write($header);
+ $socket->write($pdu);
+
+ # my $hexdata = convert_to_hex($pdu);
+ # print("SENT: [$hexdata]\n");
+}
+
+sub csta_connect {
+ my %args = %{ $_[0] };
+ open_csta_socket( $args{host}, $args{port} );
+
+ # A-ASSOCIATE Request
+ my $pdu =
+"602380020780A10706052B0C00815ABE14281206072B0C00821D8148A007A0050303000800";
+ $pdu = pack( 'H*', $pdu );
+ send_pdu($pdu);
+
+ # A-ASSOCIATE Result
+ $pdu = receive_stuff();
+ my $hexdata = convert_to_hex($pdu);
+ if ( $hexdata =~ /A2 03 02 01 01/ ) {
+ print "rejected-permanent\n";
+ exit 0;
+ }
+
+ #SystemStatus Request
+ $pdu = receive_stuff();
+ my $out = $CSTAapdu->decode($pdu);
+ my $invokeID = $out->{svcRequest}->{invokeID};
+ SystemStatusResult($invokeID);
+}
+
+sub open_csta_socket {
+ my $host = shift;
+ my $port = shift;
+ $socket = new IO::Socket::INET(
+ PeerAddr => $host,
+ PeerPort => $port,
+ Blocking => 1,
+ Proto => 'tcp'
+ ) || die "Error creating socket: $!\n";
+ $socket->autoflush(1);
+ print("opened a connection to $host on port $port\n");
+}
+
+sub receive_stuff {
+ my $header = '';
+ my $pdu = '';
+ my $nbytes = $socket->sysread( $header, 2 );
+ if ( $nbytes == 1 ) { # фрагмент пакета
+ my $header2;
+ my $nbytes2 = $socket->sysread( $header2, 1 );
+ $header = $header . $header2;
+ $nbytes = 2;
+ }
+ croak "Didn't receive the specified amount of data (2 bytes)!\n" . chr(7)
+ unless ( $nbytes == 2 );
+ my $len = decode_msg_header($header);
+ $nbytes = $socket->sysread( $pdu, $len );
+ if ( $nbytes < $len ) { # фрагмент пакета
+ my $pdu2;
+ my $nbytes2 = $socket->sysread( $pdu2, $len - $nbytes );
+ $pdu = $pdu . $pdu2;
+ $nbytes = $nbytes + $nbytes2;
+ }
+ croak "Didn't receive the specified amount of data ($len bytes)!\n" . chr(7)
+ unless ( $nbytes == $len );
+
+ # my $hexdata = convert_to_hex($pdu);
+ # print("RECEIVED:[$hexdata]\n");
+ return $pdu;
+}
+
+sub SystemStatusResult {
+ my $invokeID = shift;
+ my $pdu = $CSTAapdu->encode(
+ {
+ svcResult => {
+ invokeID => $invokeID,
+ result => { serviceID => 211, serviceResult => { noData => 1 } }
+ }
+ }
+ );
+ send_pdu($pdu); # send SystemStatus Result
+}
+
+sub playOGM {
+ my $ogmId = shift;
+ if ( !$ogmId ) { $ogmId = 10 }
+ my $connectionID = shift;
+ my $pdu = $CSTAapdu->encode(
+ {
+ svcRequest => {
+ invokeID => 11,
+ serviceID => 51,
+ serviceArgs => {
+ privateData => {
+ private => {
+ kmeResourceControl => {
+ ogmStart => {
+ connection => $connectionID,
+ ogmId => $ogmId
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ );
+ send_pdu($pdu);
+}
+
+sub numberOfMsgPort {
+
+ #EscapeArgument.privateData.private.kmeSystemData.getSystemData.request
+ my $pdu = $CSTAapdu->encode(
+ {
+ svcRequest => {
+ invokeID => 8,
+ serviceID => 51,
+ serviceArgs => {
+ privateData => {
+ private => {
+ kmeSystemData => {
+ getSystemData =>
+ { request => { systemData => 18 } }
+ }
+ }
+ }
+ }
+ }
+ }
+ );
+ send_pdu($pdu);
+ while (1) {
+ $pdu = receive_stuff();
+ my $out = $CSTAapdu->decode($pdu);
+ if (
+ defined $out->{svcRequest}->{serviceArgs}->{privateData}->{private}
+ ->{kmeSystemData}->{systemDataLinkedReply}->{sysData}
+ ->{numberOfMsgPort} )
+ {
+ my $MsgPorts =
+ $out->{svcRequest}->{serviceArgs}->{privateData}->{private}
+ ->{kmeSystemData}->{systemDataLinkedReply}->{sysData}
+ ->{numberOfMsgPort};
+ return $MsgPorts;
+ }
+ }
+}
+
+sub answer {
+ my $callerID = shift;
+ my $connectionID = shift;
+ my $MsgPorts = numberOfMsgPort();
+
+ #берём трубку
+ my $pdu = $CSTAapdu->encode(
+ {
+ svcRequest => {
+ invokeID => 10,
+ serviceID => 2,
+ serviceArgs => { callToBeAnswered => $connectionID }
+ }
+ }
+ );
+ send_pdu($pdu);
+ my $callID = $connectionID->{both}->{callID};
+ print "answered callID:", $callID, " callerID:", $callerID, "\n";
+ my $numberOfFreePort = $MsgPorts->{numberOfFreePort};
+ print "numberOfFreePort:", $numberOfFreePort, "\n";
+ if ( !$numberOfFreePort ) {
+ my $pdu = $CSTAapdu->encode(
+ {
+ svcRequest => {
+ invokeID => 13,
+ serviceID => 5,
+ serviceArgs => { connectionToBeCleared => $connectionID }
+ }
+ }
+ );
+ send_pdu($pdu);
+ print "connection callID:", $callID, " cleared\n";
+ next;
+ }
+ my $digits = [ split( '', $callerID ) ];
+ $calls{$callID} = $digits;
+ print "digits in the array:", scalar @{ $calls{$callID} }, "\n";
+ my $digit = shift @{ $calls{$callID} };
+ playOGM( $digit, $connectionID );
+}
+
+# parse ASN.1 desciptions
+my $asn = Convert::ASN1->new;
+$asn->prepare_file('d:\111\asn_perl\kxtde.asn') or die "prepare: ", $asn->error;
+my %serviceArgs = (
+ 2 => 'AnswerCallArgument',
+ 5 => 'ClearConnectionArgument',
+ 21 => 'CSTAEventReportArgument',
+ 51 => 'EscapeArgument',
+
+ # 10=> 'MakeCallArgument',
+ 71 => 'MonitorStartArgument',
+ 211 => 'SystemStatusArg'
+);
+foreach ( keys %serviceArgs ) {
+ $asn->registertype( 'serviceArgs', $_, $asn->find( $serviceArgs{$_} ) );
+}
+my %serviceResults = (
+ 51 => 'EscapeResult',
+
+ # 10=> 'MakeCallResult',
+ 71 => 'MonitorStartResult',
+ 211 => 'SystemStatusRes'
+);
+foreach ( keys %serviceResults ) {
+ $asn->registertype( 'serviceResult', $_,
+ $asn->find( $serviceResults{$_} ) );
+}
+$CSTAapdu = $asn->find('CSTAapdu');
+csta_connect( { 'host' => '192.168.0.101', 'port' => 33333 } );
+my $Number = 177; # ! ICD номер
+my $MsgPorts = numberOfMsgPort();
+print "numberOfMsgPort:", $MsgPorts->{numberOfMsgPort}, "\n";
+
+#EscapeArgument.privateData.private.kmeSystemData.setSystemData
+my $pdu = $CSTAapdu->encode(
+ {
+ svcRequest => {
+ invokeID => 9,
+ serviceID => 51,
+ serviceArgs => {
+ privateData => {
+ private => {
+ kmeSystemData => {
+ setSystemData => {
+ acdQueue => {
+ device => {
+ deviceIdentifier =>
+ { dialingNumber => $Number }
+ },
+ attribute => { acdMode => 1 }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+);
+send_pdu($pdu);
+
+#EscapeArgument.privateData.private.kmeSystemData.setSystemData
+$pdu = $CSTAapdu->encode(
+ {
+ svcRequest => {
+ invokeID => 9,
+ serviceID => 51,
+ serviceArgs => {
+ privateData => {
+ private => {
+ kmeSystemData => {
+ setSystemData => {
+ acdQueue => {
+ device => {
+ deviceIdentifier =>
+ { dialingNumber => $Number }
+ },
+ attribute => { ctiWaitTime => 20 }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+);
+send_pdu($pdu);
+
+#monitor
+$pdu = $CSTAapdu->encode(
+ {
+ svcRequest => {
+ invokeID => 9,
+ serviceID => 71,
+ serviceArgs => {
+ monitorObject => {
+ deviceObject =>
+ { deviceIdentifier => { dialingNumber => $Number } }
+ },
+ requestedMonitorFilter => {}
+ }
+ }
+ }
+);
+send_pdu($pdu);
+while (1) {
+ $pdu = receive_stuff();
+
+ #Convert::ASN1::asn_dump($pdu);
+ my $out = $CSTAapdu->decode($pdu);
+
+ # $Data::Dumper::Indent=1;
+ # $Data::Dumper::Pair=' ';
+ # $Data::Dumper::Quotekeys=0;
+ # $Data::Dumper::Varname='CSTAapdu';
+ #print Dumper($out);
+ if ( defined $out->{svcRequest} ) {
+ my $serviceID = $out->{svcRequest}->{serviceID};
+ my $invokeID = $out->{svcRequest}->{invokeID};
+ my $serviceArgs = $out->{svcRequest}->{serviceArgs};
+ if ( $serviceID == 21 ) {
+ if (
+ defined $serviceArgs->{eventSpecificInfo}->{callControlEvents}
+ ->{delivered} )
+ {
+ my $connectionID =
+ $serviceArgs->{eventSpecificInfo}->{callControlEvents}
+ ->{delivered}->{connection};
+ if (
+ defined $serviceArgs->{eventSpecificInfo}
+ ->{callControlEvents}->{delivered}->{callingDevice}
+ ->{deviceIdentifier}->{deviceIdentifier}->{dialingNumber} )
+ {
+ my $callerID =
+ $serviceArgs->{eventSpecificInfo}->{callControlEvents}
+ ->{delivered}->{callingDevice}->{deviceIdentifier}
+ ->{deviceIdentifier}->{dialingNumber};
+ answer( $callerID, $connectionID );
+ }
+ elsif ( $serviceArgs->{eventSpecificInfo}->{callControlEvents}
+ ->{delivered}->{extensions}->{privateData}[0]->{private}
+ ->{kmeAdditionalData}->{device}->{deviceIdentifier}
+ ->{other} )
+ {
+ my $callerID =
+ $serviceArgs->{eventSpecificInfo}->{callControlEvents}
+ ->{delivered}->{extensions}->{privateData}[0]->{private}
+ ->{kmeAdditionalData}->{device}->{deviceIdentifier}
+ ->{other};
+ substr( $callerID, 0, 1 ) = "";
+ answer( $callerID, $connectionID );
+ }
+ else { print "not number\n" }
+ }
+ elsif ( $serviceArgs->{eventSpecificInfo}->{callControlEvents}
+ ->{transferred} )
+ {
+ my $callID =
+ $serviceArgs->{eventSpecificInfo}->{callControlEvents}
+ ->{transferred}->{transferredConnections}[0]->{newConnection}
+ ->{both}->{callID};
+ my $oldCallID =
+ $serviceArgs->{eventSpecificInfo}->{callControlEvents}
+ ->{transferred}->{primaryOldCall}->{both}->{callID};
+ $calls{$callID} = $calls{$oldCallID};
+ delete $calls{$oldCallID};
+ print "transferred: new callID:", $callID, "\n";
+ }
+ elsif (
+ defined $serviceArgs->{eventSpecificInfo}->{vendorSpecEvents}
+ ->{privateEvent}->{privateData}->{private}->{kmePrivateEvent}
+ ->{ogmStatus} )
+ {
+ my $ogmStatus =
+ $serviceArgs->{eventSpecificInfo}->{vendorSpecEvents}
+ ->{privateEvent}->{privateData}->{private}->{kmePrivateEvent}
+ ->{ogmStatus};
+ print "ogmPortNumber:",
+ $ogmStatus->{ogmPortNumber}->{deviceIdentifier}
+ ->{deviceNumber} & 0xFFFF;
+ print " ogmId:", $ogmStatus->{ogmId};
+ if ( $ogmStatus->{state} ) {
+ print " state:stop\n";
+ my $connectionID = $ogmStatus->{connection};
+ my $callID = $connectionID->{both}->{callID};
+ if ( scalar @{ $calls{$callID} } ) {
+ print "digits in the array:",
+ scalar @{ $calls{$callID} }, "\n";
+ my $digit = shift @{ $calls{$callID} };
+ playOGM( $digit, $connectionID );
+ }
+ else {
+ delete $calls{$callID};
+
+ # кладём трубку
+ my $pdu = $CSTAapdu->encode(
+ {
+ svcRequest => {
+ invokeID => 13,
+ serviceID => 5,
+ serviceArgs => {
+ connectionToBeCleared => $connectionID
+ }
+ }
+ }
+ );
+ send_pdu($pdu);
+ print "connection callID:", $callID, " cleared\n";
+ }
+ }
+ else { print " state:start\n" }
+ }
+ }
+ elsif ( $serviceID == 211 ) { # if SystemStatus Request
+ SystemStatusResult($invokeID);
+ }
+
+ }
+}
diff --git a/misc/makecall.pl b/misc/makecall.pl
index f4ad669..dff02ef 100644
--- a/misc/makecall.pl
+++ b/misc/makecall.pl
@@ -1,299 +1,358 @@
-#ver 0.03 (C)Cyr
-use strict;
-use warnings;
-use diagnostics;
-use IO::Socket;
-use Convert::ASN1;
-#use Data::Dumper;
-use Carp;
-use POSIX;
-my $CSTAapdu;
-my $socket;
-
-sub decode_msg_header {
- my $bin = shift;
- my $len = unpack('n', $bin);
- return $len;
-}
-sub encode_msg_header {
- my $len = shift;
- die "Message larger than allowed!" unless ($len <= 240);
- my $bin = pack('n', $len);
- return $bin;
-}
-sub convert_to_hex {
- my $pdu = $_[0];
- my $hexdata = unpack('H*', $pdu);
- $hexdata =~ tr/a-z/A-Z/;
- $hexdata =~ s/(..)/$1 /g;
- $hexdata =~ s/ $//g;
- return $hexdata;
-}
-sub send_pdu {
- my $pdu = $_[0];
- my $header = encode_msg_header(length($pdu));
- $socket->write($header);
- $socket->write($pdu);
-# my $hexdata = convert_to_hex($pdu);
-# print("SENT: [$hexdata]\n");
-}
-sub csta_connect {
- my %args = %{$_[0]};
- open_csta_socket($args{host}, $args{port});
- # A-ASSOCIATE Request
- my $pdu = "602380020780A10706052B0C00815ABE14281206072B0C00821D8148A007A0050303000800";
- $pdu = pack('H*', $pdu);
- send_pdu($pdu);
- # A-ASSOCIATE Result
- $pdu = receive_stuff();
- my $hexdata = convert_to_hex($pdu);
- if ($hexdata =~/A2 03 02 01 01/){
- print "rejected-permanent\n";
- exit 0
- }
- #SystemStatus Request
- $pdu = receive_stuff();
- my $out = $CSTAapdu->decode($pdu);
- my $invokeID = $out->{svcRequest}->{invokeID};
- SystemStatusResult($invokeID);
-}
-
-sub open_csta_socket {
- my $host = shift;
- my $port = shift;
- $socket = new IO::Socket::INET(
- PeerAddr => $host,
- PeerPort => $port,
- Blocking => 1,
- Proto => 'tcp') || die "Error creating socket: $!\n";
- $socket->autoflush(1);
- print("opened a connection to $host on port $port\n");
-}
-sub receive_stuff {
- my $header = '';
- my $pdu = '';
- my $nbytes = $socket->sysread($header, 2);
- if ($nbytes==1) { # фрагмент пакета
- my $header2;
- my $nbytes2= $socket->sysread($header2, 1);
- $header = $header.$header2;
- $nbytes = 2;
- }
- croak "Didn't receive the specified amount of data (2 bytes)!\n".chr(7) unless ($nbytes == 2);
- my $len = decode_msg_header($header);
- $nbytes = $socket->sysread($pdu, $len);
- if ($nbytes<$len) { # фрагмент пакета
- my $pdu2;
- my $nbytes2= $socket->sysread($pdu2, $len-$nbytes);
- $pdu = $pdu.$pdu2;
- $nbytes = $nbytes + $nbytes2;
- }
- croak "Didn't receive the specified amount of data ($len bytes)!\n".chr(7) unless ($nbytes == $len);
-# my $hexdata = convert_to_hex($pdu);
-# print("RECEIVED:[$hexdata]\n");
- return $pdu;
-}
-sub SystemStatusResult{
- my $invokeID = shift;
- my $pdu = $CSTAapdu->encode({svcResult=>{invokeID=>$invokeID,result=>{serviceID=>211,serviceResult=>{noData=>1}}}});
- send_pdu($pdu); # send SystemStatus Result
-}
-sub makeCall{
- my $dialingNumber = shift;
- my $pdu = $CSTAapdu->encode({svcRequest=>{
- invokeID=>9,
- serviceID=>10,
- serviceArgs=>{
- callingDevice=>{
- deviceIdentifier=>{
- dialingNumber=>$dialingNumber # номер абонента
- }
- },
- calledDirectoryNumber=>{
- deviceIdentifier=>{
- dialingNumber=>178 # номер ICD автоинформатора
- }
- }
- }
- }
- });
- send_pdu($pdu);
- $pdu = receive_stuff();
- #Convert::ASN1::asn_dump($pdu);
- my $out = $CSTAapdu->decode($pdu);
- #$Data::Dumper::Indent=1;
- #$Data::Dumper::Pair=' ';
- #$Data::Dumper::Quotekeys=0;
- #$Data::Dumper::Varname='CSTAapdu';
- #print Dumper($out);
- if (defined $out->{svcResult}->{result}->{serviceResult}->{callingDevice}) {
- print $out->{svcResult}->{result}->{serviceResult}->{callingDevice}->{both}->{deviceID}->{staticID}->{deviceIdentifier}->{dialingNumber},"\n"
- } elsif (defined $out->{svcError}->{parameter}) {
- #my $error_parameter = (keys %{$out->{svcError}->{parameter}})[0];
- #print $error_parameter,"\n";
- if (defined $out->{svcError}->{parameter}->{operation}) {
- my $OperationErrors = $out->{svcError}->{parameter}->{operation};
- if ($OperationErrors ==12) {
- print $dialingNumber," - invalidDeviceID\n"
- } elsif ($OperationErrors ==6) {
- print $dialingNumber," - invalidCalledDeviceID\n"
- } elsif ($OperationErrors ==31) {
- print $dialingNumber," - invalidParameterValue\n"
- } elsif ($OperationErrors ==2) {
- print $dialingNumber," - requestIncompatibleWithObject\n"
- } else {
- print "OperationErrors:",$OperationErrors,"\n"
- }
- } elsif (defined $out->{svcError}->{parameter}->{stateIncompatibility}) {
- my $StateIncompatibilityErrors = $out->{svcError}->{parameter}->{stateIncompatibility};
- if ($StateIncompatibilityErrors == 2) {
- print $dialingNumber," - invalidObjectState\n"
- } else {
- print "StateIncompatibilityErrors:",$StateIncompatibilityErrors;
- }
- } elsif (defined $out->{svcError}->{parameter}->{systemResourceAvailability}) {
- my $SystemResourceAvailabilityErrors = $out->{svcError}->{parameter}->{systemResourceAvailability};
- if ($SystemResourceAvailabilityErrors == 15) {
- print $dialingNumber," - deviceOutOfService\n"
- } else {
- print "SystemResourceAvailabilityErrors:",$SystemResourceAvailabilityErrors;
- }
- } else {
- print Dumper($out)
- }
- } else {
- print Dumper($out)
- }
-}
-# parse ASN.1 desciptions
-my $asn = Convert::ASN1->new;
-#$asn->configure(tagdefault=>'EXPLICIT');
-$asn->prepare(<<ASN1) or die "prepare: ", $asn->error;
-CSTAapdu ::= CHOICE {
- svcRequest ROIVapdu,
- svcResult RORSapdu,
- svcError ROERapdu
--- svcReject RORJapdu
-}
-ROIVapdu ::= [1] IMPLICIT SEQUENCE {
- invokeID INTEGER,
- serviceID INTEGER,
- serviceArgs ANY DEFINED BY serviceID
-}
-RORSapdu ::= [2] IMPLICIT SEQUENCE {
- invokeID INTEGER,
- result SEQUENCE {
- serviceID INTEGER,
- serviceResult ANY DEFINED BY serviceID OPTIONAL
- }
-}
-ROERapdu ::= [3] IMPLICIT SEQUENCE {
- invokeID INTEGER,
- code INTEGER, -- local:1
- parameter UniversalFailure
-}
-UniversalFailure ::= CHOICE
-{ operation [0] EXPLICIT OperationErrors,
- stateIncompatibility [2] EXPLICIT StateIncompatibilityErrors,
- systemResourceAvailability [3] EXPLICIT SystemResourceAvailabilityErrors,
- unspecified [7] UnspecifiedErrors
-}
-OperationErrors ::= ENUMERATED
-{
- invalidDeviceID (12),
- invalidCalledDeviceID (6),
- invalidParameterValue (31),
- requestIncompatibleWithObject (2)
-}
-StateIncompatibilityErrors ::= ENUMERATED
-{
- invalidObjectState (2)
-}
-SystemResourceAvailabilityErrors ::= ENUMERATED
-{
- deviceOutOfService (15)
-}
-UnspecifiedErrors ::= NULL
-
---makeCall OPERATION ::=
---{ ARGUMENT MakeCallArgument
--- RESULT MakeCallResult
--- ERRORS {universalFailure}
--- CODE local: 10
---}
-
-MakeCallArgument ::= SEQUENCE
-{ callingDevice DeviceID,
- calledDirectoryNumber DeviceID
-}
-MakeCallResult ::= SEQUENCE
-{ callingDevice ConnectionID}
-
-ConnectionID ::= [APPLICATION 11] CHOICE
-{
- deviceID [1] LocalDeviceID,
- both SEQUENCE
- { callID [0] IMPLICIT CallID,
- deviceID [1] LocalDeviceID
- }
-}
-
-CallID ::= OCTET STRING
-
-LocalDeviceID ::= CHOICE
-{ staticID DeviceID}
-
-DeviceID ::= SEQUENCE
-{ deviceIdentifier CHOICE
- { dialingNumber [0] IMPLICIT NumberDigits,
- deviceNumber [1] IMPLICIT DeviceNumber,
- other [6] IMPLICIT OtherPlan
- }
-}
-OtherPlan ::= OCTET STRING
-
-NumberDigits ::= IA5String
-
-DeviceNumber ::= INTEGER
-
-systemStatus ::= CHOICE
-{ ARGUMENT SystemStatusArg,
- RESULT SystemStatusRes
--- ERRORS {universalFailure}
--- CODE local: 211
-}
-SystemStatusArg ::= SEQUENCE
-{ systemStatus SystemStatus}
-
-SystemStatusRes ::= CHOICE
-{ noData NULL}
-
-SystemStatus ::= ENUMERATED
-{ normal (2),
- messageLost (3),
- overloadReached (6)
-}
-ASN1
-my %serviceArgs = ( #51=> 'EscapeArgument',
- 10 => 'MakeCallArgument',
- 211=> 'SystemStatusArg');
-foreach (keys %serviceArgs) {
- $asn->registertype('serviceArgs',$_,$asn->find($serviceArgs{$_}));
-}
-my %serviceResults = ( #51=> 'EscapeResult',
- 10 => 'MakeCallResult',
- 211=> 'SystemStatusRes');
-foreach (keys %serviceResults) {
- $asn->registertype('serviceResult',$_,$asn->find($serviceResults{$_}));
-}
-$CSTAapdu = $asn->find('CSTAapdu');
-csta_connect({'host'=>'192.168.0.66', 'port'=>33333});
-print "makeCall:\n";
-my @devices = (106, 111, 155, 156); # список номеров
-my $i=0;
-for (@devices) {
- makeCall($_);
- if ($i++%2) { # 2 - количество каналов SVM
- sleep 3 # задержка на сообщение
- }
-}
+#ver 0.03 (C)Cyr
+use strict;
+use warnings;
+use diagnostics;
+use IO::Socket;
+use Convert::ASN1;
+
+#use Data::Dumper;
+use Carp;
+use POSIX;
+my $CSTAapdu;
+my $socket;
+
+sub decode_msg_header {
+ my $bin = shift;
+ my $len = unpack( 'n', $bin );
+ return $len;
+}
+
+sub encode_msg_header {
+ my $len = shift;
+ die "Message larger than allowed!" unless ( $len <= 240 );
+ my $bin = pack( 'n', $len );
+ return $bin;
+}
+
+sub convert_to_hex {
+ my $pdu = $_[0];
+ my $hexdata = unpack( 'H*', $pdu );
+ $hexdata =~ tr/a-z/A-Z/;
+ $hexdata =~ s/(..)/$1 /g;
+ $hexdata =~ s/ $//g;
+ return $hexdata;
+}
+
+sub send_pdu {
+ my $pdu = $_[0];
+ my $header = encode_msg_header( length($pdu) );
+ $socket->write($header);
+ $socket->write($pdu);
+
+ # my $hexdata = convert_to_hex($pdu);
+ # print("SENT: [$hexdata]\n");
+}
+
+sub csta_connect {
+ my %args = %{ $_[0] };
+ open_csta_socket( $args{host}, $args{port} );
+
+ # A-ASSOCIATE Request
+ my $pdu =
+"602380020780A10706052B0C00815ABE14281206072B0C00821D8148A007A0050303000800";
+ $pdu = pack( 'H*', $pdu );
+ send_pdu($pdu);
+
+ # A-ASSOCIATE Result
+ $pdu = receive_stuff();
+ my $hexdata = convert_to_hex($pdu);
+ if ( $hexdata =~ /A2 03 02 01 01/ ) {
+ print "rejected-permanent\n";
+ exit 0;
+ }
+
+ #SystemStatus Request
+ $pdu = receive_stuff();
+ my $out = $CSTAapdu->decode($pdu);
+ my $invokeID = $out->{svcRequest}->{invokeID};
+ SystemStatusResult($invokeID);
+}
+
+sub open_csta_socket {
+ my $host = shift;
+ my $port = shift;
+ $socket = new IO::Socket::INET(
+ PeerAddr => $host,
+ PeerPort => $port,
+ Blocking => 1,
+ Proto => 'tcp'
+ ) || die "Error creating socket: $!\n";
+ $socket->autoflush(1);
+ print("opened a connection to $host on port $port\n");
+}
+
+sub receive_stuff {
+ my $header = '';
+ my $pdu = '';
+ my $nbytes = $socket->sysread( $header, 2 );
+ if ( $nbytes == 1 ) { # фрагмент пакета
+ my $header2;
+ my $nbytes2 = $socket->sysread( $header2, 1 );
+ $header = $header . $header2;
+ $nbytes = 2;
+ }
+ croak "Didn't receive the specified amount of data (2 bytes)!\n" . chr(7)
+ unless ( $nbytes == 2 );
+ my $len = decode_msg_header($header);
+ $nbytes = $socket->sysread( $pdu, $len );
+ if ( $nbytes < $len ) { # фрагмент пакета
+ my $pdu2;
+ my $nbytes2 = $socket->sysread( $pdu2, $len - $nbytes );
+ $pdu = $pdu . $pdu2;
+ $nbytes = $nbytes + $nbytes2;
+ }
+ croak "Didn't receive the specified amount of data ($len bytes)!\n" . chr(7)
+ unless ( $nbytes == $len );
+
+ # my $hexdata = convert_to_hex($pdu);
+ # print("RECEIVED:[$hexdata]\n");
+ return $pdu;
+}
+
+sub SystemStatusResult {
+ my $invokeID = shift;
+ my $pdu = $CSTAapdu->encode(
+ {
+ svcResult => {
+ invokeID => $invokeID,
+ result => { serviceID => 211, serviceResult => { noData => 1 } }
+ }
+ }
+ );
+ send_pdu($pdu); # send SystemStatus Result
+}
+
+sub makeCall {
+ my $dialingNumber = shift;
+ my $pdu = $CSTAapdu->encode(
+ {
+ svcRequest => {
+ invokeID => 9,
+ serviceID => 10,
+ serviceArgs => {
+ callingDevice => {
+ deviceIdentifier => {
+ dialingNumber =>
+ $dialingNumber # номер абонента
+ }
+ },
+ calledDirectoryNumber => {
+ deviceIdentifier => {
+ dialingNumber =>
+ 178 # номер ICD автоинформатора
+ }
+ }
+ }
+ }
+ }
+ );
+ send_pdu($pdu);
+ $pdu = receive_stuff();
+
+ #Convert::ASN1::asn_dump($pdu);
+ my $out = $CSTAapdu->decode($pdu);
+
+ #$Data::Dumper::Indent=1;
+ #$Data::Dumper::Pair=' ';
+ #$Data::Dumper::Quotekeys=0;
+ #$Data::Dumper::Varname='CSTAapdu';
+ #print Dumper($out);
+ if ( defined $out->{svcResult}->{result}->{serviceResult}->{callingDevice} )
+ {
+ print $out->{svcResult}->{result}->{serviceResult}->{callingDevice}
+ ->{both}->{deviceID}->{staticID}->{deviceIdentifier}->{dialingNumber},
+ "\n";
+ }
+ elsif ( defined $out->{svcError}->{parameter} ) {
+
+ #my $error_parameter = (keys %{$out->{svcError}->{parameter}})[0];
+ #print $error_parameter,"\n";
+ if ( defined $out->{svcError}->{parameter}->{operation} ) {
+ my $OperationErrors = $out->{svcError}->{parameter}->{operation};
+ if ( $OperationErrors == 12 ) {
+ print $dialingNumber, " - invalidDeviceID\n";
+ }
+ elsif ( $OperationErrors == 6 ) {
+ print $dialingNumber, " - invalidCalledDeviceID\n";
+ }
+ elsif ( $OperationErrors == 31 ) {
+ print $dialingNumber, " - invalidParameterValue\n";
+ }
+ elsif ( $OperationErrors == 2 ) {
+ print $dialingNumber, " - requestIncompatibleWithObject\n";
+ }
+ else {
+ print "OperationErrors:", $OperationErrors, "\n";
+ }
+ }
+ elsif ( defined $out->{svcError}->{parameter}->{stateIncompatibility} )
+ {
+ my $StateIncompatibilityErrors =
+ $out->{svcError}->{parameter}->{stateIncompatibility};
+ if ( $StateIncompatibilityErrors == 2 ) {
+ print $dialingNumber, " - invalidObjectState\n";
+ }
+ else {
+ print "StateIncompatibilityErrors:",
+ $StateIncompatibilityErrors;
+ }
+ }
+ elsif (
+ defined $out->{svcError}->{parameter}
+ ->{systemResourceAvailability} )
+ {
+ my $SystemResourceAvailabilityErrors =
+ $out->{svcError}->{parameter}->{systemResourceAvailability};
+ if ( $SystemResourceAvailabilityErrors == 15 ) {
+ print $dialingNumber, " - deviceOutOfService\n";
+ }
+ else {
+ print "SystemResourceAvailabilityErrors:",
+ $SystemResourceAvailabilityErrors;
+ }
+ }
+ else {
+ print Dumper($out);
+ }
+ }
+ else {
+ print Dumper($out);
+ }
+}
+
+# parse ASN.1 desciptions
+my $asn = Convert::ASN1->new;
+
+#$asn->configure(tagdefault=>'EXPLICIT');
+$asn->prepare(<<ASN1) or die "prepare: ", $asn->error;
+CSTAapdu ::= CHOICE {
+ svcRequest ROIVapdu,
+ svcResult RORSapdu,
+ svcError ROERapdu
+-- svcReject RORJapdu
+}
+ROIVapdu ::= [1] IMPLICIT SEQUENCE {
+ invokeID INTEGER,
+ serviceID INTEGER,
+ serviceArgs ANY DEFINED BY serviceID
+}
+RORSapdu ::= [2] IMPLICIT SEQUENCE {
+ invokeID INTEGER,
+ result SEQUENCE {
+ serviceID INTEGER,
+ serviceResult ANY DEFINED BY serviceID OPTIONAL
+ }
+}
+ROERapdu ::= [3] IMPLICIT SEQUENCE {
+ invokeID INTEGER,
+ code INTEGER, -- local:1
+ parameter UniversalFailure
+}
+UniversalFailure ::= CHOICE
+{ operation [0] EXPLICIT OperationErrors,
+ stateIncompatibility [2] EXPLICIT StateIncompatibilityErrors,
+ systemResourceAvailability [3] EXPLICIT SystemResourceAvailabilityErrors,
+ unspecified [7] UnspecifiedErrors
+}
+OperationErrors ::= ENUMERATED
+{
+ invalidDeviceID (12),
+ invalidCalledDeviceID (6),
+ invalidParameterValue (31),
+ requestIncompatibleWithObject (2)
+}
+StateIncompatibilityErrors ::= ENUMERATED
+{
+ invalidObjectState (2)
+}
+SystemResourceAvailabilityErrors ::= ENUMERATED
+{
+ deviceOutOfService (15)
+}
+UnspecifiedErrors ::= NULL
+
+--makeCall OPERATION ::=
+--{ ARGUMENT MakeCallArgument
+-- RESULT MakeCallResult
+-- ERRORS {universalFailure}
+-- CODE local: 10
+--}
+
+MakeCallArgument ::= SEQUENCE
+{ callingDevice DeviceID,
+ calledDirectoryNumber DeviceID
+}
+MakeCallResult ::= SEQUENCE
+{ callingDevice ConnectionID}
+
+ConnectionID ::= [APPLICATION 11] CHOICE
+{
+ deviceID [1] LocalDeviceID,
+ both SEQUENCE
+ { callID [0] IMPLICIT CallID,
+ deviceID [1] LocalDeviceID
+ }
+}
+
+CallID ::= OCTET STRING
+
+LocalDeviceID ::= CHOICE
+{ staticID DeviceID}
+
+DeviceID ::= SEQUENCE
+{ deviceIdentifier CHOICE
+ { dialingNumber [0] IMPLICIT NumberDigits,
+ deviceNumber [1] IMPLICIT DeviceNumber,
+ other [6] IMPLICIT OtherPlan
+ }
+}
+OtherPlan ::= OCTET STRING
+
+NumberDigits ::= IA5String
+
+DeviceNumber ::= INTEGER
+
+systemStatus ::= CHOICE
+{ ARGUMENT SystemStatusArg,
+ RESULT SystemStatusRes
+-- ERRORS {universalFailure}
+-- CODE local: 211
+}
+SystemStatusArg ::= SEQUENCE
+{ systemStatus SystemStatus}
+
+SystemStatusRes ::= CHOICE
+{ noData NULL}
+
+SystemStatus ::= ENUMERATED
+{ normal (2),
+ messageLost (3),
+ overloadReached (6)
+}
+ASN1
+my %serviceArgs = ( #51=> 'EscapeArgument',
+ 10 => 'MakeCallArgument',
+ 211 => 'SystemStatusArg'
+);
+foreach ( keys %serviceArgs ) {
+ $asn->registertype( 'serviceArgs', $_, $asn->find( $serviceArgs{$_} ) );
+}
+my %serviceResults = ( #51=> 'EscapeResult',
+ 10 => 'MakeCallResult',
+ 211 => 'SystemStatusRes'
+);
+foreach ( keys %serviceResults ) {
+ $asn->registertype( 'serviceResult', $_,
+ $asn->find( $serviceResults{$_} ) );
+}
+$CSTAapdu = $asn->find('CSTAapdu');
+csta_connect( { 'host' => '192.168.0.66', 'port' => 33333 } );
+print "makeCall:\n";
+my @devices = ( 106, 111, 155, 156 ); # список номеров
+my $i = 0;
+for (@devices) {
+ makeCall($_);
+ if ( $i++ % 2 ) { # 2 - количество каналов SVM
+ sleep 3 # задержка на сообщение
+ }
+}
diff --git a/misc/monitorCallerID.pl b/misc/monitorCallerID.pl
index 2ec0ea4..7980811 100644
--- a/misc/monitorCallerID.pl
+++ b/misc/monitorCallerID.pl
@@ -1,136 +1,174 @@
-use POSIX;
-use Carp;
-#use Data::Dumper;
-use IO::Socket;
-sub decode_msg_header {
- my $bin = shift;
- my $len = unpack('n', $bin);
- return $len;
-}
-sub encode_msg_header {
- my $len = shift;
-# print("len: [$len]\n");
- die "Message larger than allowed!" unless ($len <= 240);
- my $bin = pack('n', $len);
- return $bin;
-}
-sub convert_to_hex {
- my $pdu = $_[0];
- my $hexdata = unpack('H*', $pdu);
- $hexdata =~ tr/a-z/A-Z/;
- $hexdata =~ s/(..)/$1 /g;
- $hexdata =~ s/ $//g;
- return $hexdata;
-}
-sub send_pdu {
- my $pdu = $_[0];
- my $header = encode_msg_header(length($pdu));
- $socket->write($header);
- $headerdata = convert_to_hex($header);
-# print("SENT HEADER: [$headerdata]\n");
- $socket->write($pdu);
- $hexdata = convert_to_hex($pdu);
-# print("SENT: [$hexdata]\n");
-}
-sub csta_connect {
- my %args = %{$_[0]};
- open_csta_socket($args{host}, $args{port});
- # A-ASSOCIATE Request
- my $pdu = "602380020780A10706052B0C00815ABE14281206072B0C00821D8148A007A0050303000800";
- $pdu = pack('H*', $pdu);
- send_pdu($pdu);
- # A-ASSOCIATE Result
- receive_stuff();
-}
-sub open_csta_socket {
- my $host = shift;
- my $port = shift;
-# print("trying to open a connection to $host on port $port\n");
- $socket = new IO::Socket::INET(
- PeerAddr => $host,
- PeerPort => $port,
- Blocking => 1,
- Proto => 'tcp') || die "Error creating socket: $!\n";
- $socket->autoflush(1);
- print("opened a connection to $host on port $port\n");
-}
-sub receive_stuff {
- my $header = '';
- my $pdu = '';
- my $nbytes = $socket->sysread($header, 2);
- if ($nbytes==1) { #
-# print("RECEIVED fragment".chr(7)."\n");
- $nbytes2= $socket->sysread($header2, 1);
- $header = $header.$header2;
- $nbytes = 2;
- }
- croak "Didn't receive the specified amount of data (2 bytes)!\n".chr(7) unless ($nbytes == 2);
-# print("Received 2 bytes, assuming it's a data length\n");
- my $len = decode_msg_header($header);
-# print("Waiting for [$len] bytes of ASN1 data now\n");
- $nbytes = $socket->sysread($pdu, $len);
- if ($nbytes<$len) { #
-# print("RECEIVED fragment".chr(7)."\n");
- $nbytes2= $socket->sysread($pdu2, $len-$nbytes);
- $pdu = $pdu.$pdu2;
- $nbytes = $nbytes + $nbytes2;
- }
- croak "Didn't receive the specified amount of data ($len bytes)!\n".chr(7) unless ($nbytes == $len);
- my $hexdata = convert_to_hex($pdu);
-# print("RECEIVED:[$hexdata]\n");
- return $pdu;
-}
-sub main_loop {
- while (1) {
- my $pdu = receive_stuff();
- my $hexdata = convert_to_hex($pdu);
- # If SystemStatus Request
- if ($hexdata =~/A1 0C 02 01 .. 02 02 00 D3 30 03 0A 01 02/) {
- # SystemStatus Response
- my $pdu = "A20B0201".substr($hexdata, 12, 2)."3006020200D30500";
- $pdu = pack('H*', $pdu);
- send_pdu($pdu);
- }
- # If SystemStatus Request 2
- elsif ($hexdata =~/A1 0D 02 02 .. .. 02 02 00 D3 30 03 0A 01 02/){
- # SystemStatus Response 2
- my $pdu = "A20C0202".substr($hexdata, 12, 2).substr($hexdata, 15, 2)."3006020200D30500";
- $pdu = pack('H*', $pdu);
- send_pdu($pdu);
- }
- # if localConnectionInfo=alerting and cause=newCall|distributed
- elsif ($hexdata =~m/4E 01 02 0A 01 [12]6/) {
- #
- if ($hexdata =~m/61 .. 30 .. 80 /) {
- $num = hex(substr($', 0, 2));
- $str = substr($', 3, $num*3);
- $str =~s/\s//g;
- $CallerID=pack ("H*", $str);
- } else {
- $CallerID="CO".substr($hexdata, length($hexdata)-2, 2);
- }
- #
- if ($hexdata =~m/63 .. 30 .. 80 /) {
- $num = hex(substr($', 0, 2));
- $str = substr($', 3, $num*3);
- $str =~s/\s//g;
- $CalledID=pack ("H*", $str);
- }
- print strftime("%H:%M:%S ", localtime);
- print("Call to:$CalledID from:$CallerID\n");
- }
- }
-}
-sub MonitorStart{
- my $ext = shift;
- $ext =~s/(.)/sprintf("%02x",ord($1))/eg;
- my $pdu = "A111020178020147300930058003".$ext."A000";
- $pdu = pack('H*', $pdu);
- send_pdu($pdu);
- $pdu = receive_stuff();
-}
-csta_connect({'host'=>'192.168.0.101', 'port'=>33333});
-for ($ext_num = 101; $ext_num <=156; $ext_num++){
- MonitorStart($ext_num);
-}
-main_loop();
+use POSIX;
+use Carp;
+
+#use Data::Dumper;
+use IO::Socket;
+
+sub decode_msg_header {
+ my $bin = shift;
+ my $len = unpack( 'n', $bin );
+ return $len;
+}
+
+sub encode_msg_header {
+ my $len = shift;
+
+ # print("len: [$len]\n");
+ die "Message larger than allowed!" unless ( $len <= 240 );
+ my $bin = pack( 'n', $len );
+ return $bin;
+}
+
+sub convert_to_hex {
+ my $pdu = $_[0];
+ my $hexdata = unpack( 'H*', $pdu );
+ $hexdata =~ tr/a-z/A-Z/;
+ $hexdata =~ s/(..)/$1 /g;
+ $hexdata =~ s/ $//g;
+ return $hexdata;
+}
+
+sub send_pdu {
+ my $pdu = $_[0];
+ my $header = encode_msg_header( length($pdu) );
+ $socket->write($header);
+ $headerdata = convert_to_hex($header);
+
+ # print("SENT HEADER: [$headerdata]\n");
+ $socket->write($pdu);
+ $hexdata = convert_to_hex($pdu);
+
+ # print("SENT: [$hexdata]\n");
+}
+
+sub csta_connect {
+ my %args = %{ $_[0] };
+ open_csta_socket( $args{host}, $args{port} );
+
+ # A-ASSOCIATE Request
+ my $pdu =
+"602380020780A10706052B0C00815ABE14281206072B0C00821D8148A007A0050303000800";
+ $pdu = pack( 'H*', $pdu );
+ send_pdu($pdu);
+
+ # A-ASSOCIATE Result
+ receive_stuff();
+}
+
+sub open_csta_socket {
+ my $host = shift;
+ my $port = shift;
+
+ # print("trying to open a connection to $host on port $port\n");
+ $socket = new IO::Socket::INET(
+ PeerAddr => $host,
+ PeerPort => $port,
+ Blocking => 1,
+ Proto => 'tcp'
+ ) || die "Error creating socket: $!\n";
+ $socket->autoflush(1);
+ print("opened a connection to $host on port $port\n");
+}
+
+sub receive_stuff {
+ my $header = '';
+ my $pdu = '';
+ my $nbytes = $socket->sysread( $header, 2 );
+ if ( $nbytes == 1 ) { #
+
+ # print("RECEIVED fragment".chr(7)."\n");
+ $nbytes2 = $socket->sysread( $header2, 1 );
+ $header = $header . $header2;
+ $nbytes = 2;
+ }
+ croak "Didn't receive the specified amount of data (2 bytes)!\n" . chr(7)
+ unless ( $nbytes == 2 );
+
+ # print("Received 2 bytes, assuming it's a data length\n");
+ my $len = decode_msg_header($header);
+
+ # print("Waiting for [$len] bytes of ASN1 data now\n");
+ $nbytes = $socket->sysread( $pdu, $len );
+ if ( $nbytes < $len ) { #
+
+ # print("RECEIVED fragment".chr(7)."\n");
+ $nbytes2 = $socket->sysread( $pdu2, $len - $nbytes );
+ $pdu = $pdu . $pdu2;
+ $nbytes = $nbytes + $nbytes2;
+ }
+ croak "Didn't receive the specified amount of data ($len bytes)!\n" . chr(7)
+ unless ( $nbytes == $len );
+ my $hexdata = convert_to_hex($pdu);
+
+ # print("RECEIVED:[$hexdata]\n");
+ return $pdu;
+}
+
+sub main_loop {
+ while (1) {
+ my $pdu = receive_stuff();
+ my $hexdata = convert_to_hex($pdu);
+
+ # If SystemStatus Request
+ if ( $hexdata =~ /A1 0C 02 01 .. 02 02 00 D3 30 03 0A 01 02/ ) {
+
+ # SystemStatus Response
+ my $pdu =
+ "A20B0201" . substr( $hexdata, 12, 2 ) . "3006020200D30500";
+ $pdu = pack( 'H*', $pdu );
+ send_pdu($pdu);
+ }
+
+ # If SystemStatus Request 2
+ elsif ( $hexdata =~ /A1 0D 02 02 .. .. 02 02 00 D3 30 03 0A 01 02/ ) {
+
+ # SystemStatus Response 2
+ my $pdu =
+ "A20C0202"
+ . substr( $hexdata, 12, 2 )
+ . substr( $hexdata, 15, 2 )
+ . "3006020200D30500";
+ $pdu = pack( 'H*', $pdu );
+ send_pdu($pdu);
+ }
+
+ # if localConnectionInfo=alerting and cause=newCall|distributed
+ elsif ( $hexdata =~ m/4E 01 02 0A 01 [12]6/ ) {
+
+ #
+ if ( $hexdata =~ m/61 .. 30 .. 80 / ) {
+ $num = hex( substr( $', 0, 2 ) );
+ $str = substr( $', 3, $num * 3 );
+ $str =~ s/\s//g;
+ $CallerID = pack( "H*", $str );
+ }
+ else {
+ $CallerID = "CO" . substr( $hexdata, length($hexdata) - 2, 2 );
+ }
+
+ #
+ if ( $hexdata =~ m/63 .. 30 .. 80 / ) {
+ $num = hex( substr( $', 0, 2 ) );
+ $str = substr( $', 3, $num * 3 );
+ $str =~ s/\s//g;
+ $CalledID = pack( "H*", $str );
+ }
+ print strftime( "%H:%M:%S ", localtime );
+ print("Call to:$CalledID from:$CallerID\n");
+ }
+ }
+}
+
+sub MonitorStart {
+ my $ext = shift;
+ $ext =~ s/(.)/sprintf("%02x",ord($1))/eg;
+ my $pdu = "A111020178020147300930058003" . $ext . "A000";
+ $pdu = pack( 'H*', $pdu );
+ send_pdu($pdu);
+ $pdu = receive_stuff();
+}
+csta_connect( { 'host' => '192.168.0.101', 'port' => 33333 } );
+for ( $ext_num = 101 ; $ext_num <= 156 ; $ext_num++ ) {
+ MonitorStart($ext_num);
+}
+main_loop();
diff --git a/misc/monitorCallerID2.pl b/misc/monitorCallerID2.pl
index c930053..d39c38f 100644
--- a/misc/monitorCallerID2.pl
+++ b/misc/monitorCallerID2.pl
@@ -1,261 +1,261 @@
-#ver 0.02 (C)Cyr
-use strict;
-use warnings;
-use diagnostics;
-use IO::Socket;
-use Convert::ASN1;
-use Data::Dumper;
-use Carp;
-use POSIX;
-my $CSTAapdu;
-my $socket;
-my @devices;
-sub deviceNumber{
- my $deviceNumber = shift;
- my $deviceType = $deviceNumber & 0xFFFF0000;
- if ($deviceType==0x1310000) {
- $deviceType='CO'
- } elsif ($deviceType==0x1210000) {
- $deviceType='PS'
- } elsif ($deviceType==0x1110000) {
- $deviceType='EXT'
- } elsif ($deviceType==0x1550000) {
- $deviceType='DISA'
- }
- $deviceNumber = $deviceNumber & 0x0000FFFF;
- return $deviceType.sprintf("%03s",$deviceNumber);
-}
-sub decode_msg_header {
- my $bin = shift;
- my $len = unpack('n', $bin);
- return $len;
-}
-sub encode_msg_header {
- my $len = shift;
- die "Message larger than allowed!" unless ($len <= 240);
- my $bin = pack('n', $len);
- return $bin;
-}
-sub convert_to_hex {
- my $pdu = $_[0];
- my $hexdata = unpack('H*', $pdu);
- $hexdata =~ tr/a-z/A-Z/;
- $hexdata =~ s/(..)/$1 /g;
- $hexdata =~ s/ $//g;
- return $hexdata;
-}
-sub send_pdu {
- my $pdu = $_[0];
- my $header = encode_msg_header(length($pdu));
- $socket->write($header);
- $socket->write($pdu);
-# my $hexdata = convert_to_hex($pdu);
-# print("SENT: [$hexdata]\n");
-}
-sub csta_connect {
- my %args = %{$_[0]};
- open_csta_socket($args{host}, $args{port});
- # A-ASSOCIATE Request
- my $pdu = "602380020780A10706052B0C00815ABE14281206072B0C00821D8148A007A0050303000800";
- $pdu = pack('H*', $pdu);
- send_pdu($pdu);
- # A-ASSOCIATE Result
- $pdu = receive_stuff();
- my $hexdata = convert_to_hex($pdu);
- if ($hexdata =~/A2 03 02 01 01/){
- print "rejected-permanent\n";
- exit 0
- }
- #SystemStatus Request
- $pdu = receive_stuff();
- my $out = $CSTAapdu->decode($pdu);
- my $invokeID = $out->{svcRequest}->{invokeID};
- SystemStatusResult($invokeID);
-}
-
-sub open_csta_socket {
- my $host = shift;
- my $port = shift;
- $socket = new IO::Socket::INET(
- PeerAddr => $host,
- PeerPort => $port,
- Blocking => 1,
- Proto => 'tcp') || die "Error creating socket: $!\n";
- $socket->autoflush(1);
- print("opened a connection to $host on port $port\n");
-}
-sub receive_stuff {
- my $header = '';
- my $pdu = '';
- my $nbytes = $socket->sysread($header, 2);
- if ($nbytes==1) { # фрагмент пакета
- my $header2;
- my $nbytes2= $socket->sysread($header2, 1);
- $header = $header.$header2;
- $nbytes = 2;
- }
- croak "Didn't receive the specified amount of data (2 bytes)!\n".chr(7) unless ($nbytes == 2);
- my $len = decode_msg_header($header);
- $nbytes = $socket->sysread($pdu, $len);
- if ($nbytes<$len) { # фрагмент пакета
- my $pdu2;
- my $nbytes2= $socket->sysread($pdu2, $len-$nbytes);
- $pdu = $pdu.$pdu2;
- $nbytes = $nbytes + $nbytes2;
- }
- croak "Didn't receive the specified amount of data ($len bytes)!\n".chr(7) unless ($nbytes == $len);
-# my $hexdata = convert_to_hex($pdu);
-# print("RECEIVED:[$hexdata]\n");
- return $pdu;
-}
-sub GetSystemData{
- my $DeviceCategory = shift;
- #EXT=5
- #CO =2
- my $pdu = $CSTAapdu->encode({svcRequest=>{
- invokeID=>4,
- serviceID=>51,
- serviceArgs=>{
- privateData=>{
- private=>{
- kmeSystemData=>{
- getSystemData=>{
- request=>{
- deviceList=>{
- category=>{
- standardDevice=>$DeviceCategory
- }
- }
- }
- }
- }
- }
- }
- }
- }
- });
- #my $pdu = "A11602020602020133300DA40BA009A407A105A0030A010".$DeviceCategory;
- #$pdu = pack('H*', $pdu);
- send_pdu($pdu);
- # getSystemDataPosAck
- $pdu = receive_stuff();
- my $out = $CSTAapdu->decode($pdu);
- my $crossRefID = $out->{svcResult}->{result}->{serviceResult}->{extensions}->{privateData}[0]->{private}->{kmeSystemData}->{getSystemDataPosAck};
- my $lastSegment=0;
- # systemDataLinkedReply
- while (!$lastSegment) {
- $pdu = receive_stuff();
- my $out = $CSTAapdu->decode($pdu);
- my $systemDataLinkedReply = $out->{svcRequest}->{serviceArgs}->{privateData}->{private}->{kmeSystemData}->{systemDataLinkedReply};
- if (defined $systemDataLinkedReply) {
- if ($systemDataLinkedReply->{crossRefID} cmp $crossRefID) {next}
- $lastSegment = $systemDataLinkedReply->{lastSegment};
- foreach my $KmeDeviceStateEntry (@{$systemDataLinkedReply->{sysData}->{deviceList}}) {
- if ($KmeDeviceStateEntry->{status}==0) {
-# print "device:",$KmeDeviceStateEntry->{number},"\n";
- push @devices, ($KmeDeviceStateEntry->{device}->{deviceIdentifier}->{deviceNumber});
- }
- }
- }
- }
-}
-sub MonitorStartArgument{
-my $device = shift;
-my $pdu = $CSTAapdu->encode({svcRequest=>{
- invokeID=>9,
- serviceID=>71,
- serviceArgs=>{
- monitorObject=>{
- deviceObject=>{
- deviceIdentifier=>{
- deviceNumber=>$device
- }
- }
- },
- requestedMonitorFilter=>{}
- }
- }
- });
-send_pdu($pdu);
-#$pdu = receive_stuff();
-}
-sub CSTAEventReportArgument{
-my $refeventSpecificInfo = shift;
-if (defined $refeventSpecificInfo->{eventSpecificInfo}->{callControlEvents}) {
- my $refcallControlEvents = $refeventSpecificInfo->{eventSpecificInfo}->{callControlEvents};
- my $callControlEvents = (keys %{$refcallControlEvents})[0];
- my $Event = $refcallControlEvents->{$callControlEvents};
- #print Dumper($refcallControlEvents);
- if ((($Event->{localConnectionInfo}==2) & (($Event->{cause}==22) | ($Event->{cause}==38))) |
- (($Event->{localConnectionInfo}==3) & ($Event->{cause}==74))) {
- #localConnectionInfo = allerting and cause=newCall|distributed
- my $CalledID = deviceID($Event->{alertingDevice}->{deviceIdentifier});
- my $CallerID;
- if (defined $Event->{callingDevice}->{notKnown}) {
- $CallerID = deviceID($Event->{associatedCallingDevice}->{deviceIdentifier})
- } else {
- $CallerID = deviceID($Event->{callingDevice}->{deviceIdentifier})
- }
- print strftime("%H:%M:%S ", localtime);
- print("Call to:$CalledID from:$CallerID\n");
- }
- }
-}
-sub deviceID{
- my $deviceIdentifier = shift;
- $deviceIdentifier = $deviceIdentifier->{deviceIdentifier};
- if (defined $deviceIdentifier->{dialingNumber}) {
- return $deviceIdentifier->{dialingNumber}
- } elsif (defined $deviceIdentifier->{deviceNumber}) {
- return deviceNumber($deviceIdentifier->{deviceNumber})
- } elsif (defined $deviceIdentifier->{other}) {
- return $deviceIdentifier->{other}
- }
-}
-sub SystemStatusResult{
- my $invokeID = shift;
- my $pdu = $CSTAapdu->encode({svcResult=>{invokeID=>$invokeID,result=>{serviceID=>211,serviceResult=>{noData=>1}}}});
- send_pdu($pdu); # send SystemStatus Result
-}
-$Data::Dumper::Indent=1;
-$Data::Dumper::Pair=' ';
-$Data::Dumper::Quotekeys=0;
-$Data::Dumper::Varname='calls';
-# parse ASN.1 desciptions
-my $asn = Convert::ASN1->new;
-#$asn->configure(tagdefault=>'EXPLICIT');
-$asn->prepare_file('d:\111\asn_perl\kxtde.asn') or die "prepare: ", $asn->error;
-my %serviceArgs = ( 21=> 'CSTAEventReportArgument',
- 51=> 'EscapeArgument',
- 71=> 'MonitorStartArgument',
- 211=> 'SystemStatusArg');
-foreach (keys %serviceArgs) {
- $asn->registertype('serviceArgs',$_,$asn->find($serviceArgs{$_}));
-}
-my %serviceResults = ( 51=> 'EscapeResult',
- 71=> 'MonitorStartResult',
- 211=> 'SystemStatusRes');
-foreach (keys %serviceResults) {
- $asn->registertype('serviceResult',$_,$asn->find($serviceResults{$_}));
-}
-$CSTAapdu = $asn->find('CSTAapdu');
-csta_connect({'host'=>'192.168.0.101', 'port'=>33333});
-GetSystemData(2);
-GetSystemData(5);
-foreach my $number (@devices) {
- MonitorStartArgument($number);
-}
-while (1) {
- my $pdu = receive_stuff();
- my $out = $CSTAapdu->decode($pdu);
- if (defined $out->{svcRequest}) {
- my $serviceID = $out->{svcRequest}->{serviceID};
- my $invokeID = $out->{svcRequest}->{invokeID};
- my $serviceArgs = $out->{svcRequest}->{serviceArgs};
- if ($serviceID==21) {
- CSTAEventReportArgument($serviceArgs);
- } elsif ($serviceID==211) { # if SystemStatus Request
- SystemStatusResult($invokeID);
- }
- }
-}
+#ver 0.02 (C)Cyr
+use strict;
+use warnings;
+use diagnostics;
+use IO::Socket;
+use Convert::ASN1;
+use Data::Dumper;
+use Carp;
+use POSIX;
+my $CSTAapdu;
+my $socket;
+my @devices;
+sub deviceNumber{
+ my $deviceNumber = shift;
+ my $deviceType = $deviceNumber & 0xFFFF0000;
+ if ($deviceType==0x1310000) {
+ $deviceType='CO'
+ } elsif ($deviceType==0x1210000) {
+ $deviceType='PS'
+ } elsif ($deviceType==0x1110000) {
+ $deviceType='EXT'
+ } elsif ($deviceType==0x1550000) {
+ $deviceType='DISA'
+ }
+ $deviceNumber = $deviceNumber & 0x0000FFFF;
+ return $deviceType.sprintf("%03s",$deviceNumber);
+}
+sub decode_msg_header {
+ my $bin = shift;
+ my $len = unpack('n', $bin);
+ return $len;
+}
+sub encode_msg_header {
+ my $len = shift;
+ die "Message larger than allowed!" unless ($len <= 240);
+ my $bin = pack('n', $len);
+ return $bin;
+}
+sub convert_to_hex {
+ my $pdu = $_[0];
+ my $hexdata = unpack('H*', $pdu);
+ $hexdata =~ tr/a-z/A-Z/;
+ $hexdata =~ s/(..)/$1 /g;
+ $hexdata =~ s/ $//g;
+ return $hexdata;
+}
+sub send_pdu {
+ my $pdu = $_[0];
+ my $header = encode_msg_header(length($pdu));
+ $socket->write($header);
+ $socket->write($pdu);
+# my $hexdata = convert_to_hex($pdu);
+# print("SENT: [$hexdata]\n");
+}
+sub csta_connect {
+ my %args = %{$_[0]};
+ open_csta_socket($args{host}, $args{port});
+ # A-ASSOCIATE Request
+ my $pdu = "602380020780A10706052B0C00815ABE14281206072B0C00821D8148A007A0050303000800";
+ $pdu = pack('H*', $pdu);
+ send_pdu($pdu);
+ # A-ASSOCIATE Result
+ $pdu = receive_stuff();
+ my $hexdata = convert_to_hex($pdu);
+ if ($hexdata =~/A2 03 02 01 01/){
+ print "rejected-permanent\n";
+ exit 0
+ }
+ #SystemStatus Request
+ $pdu = receive_stuff();
+ my $out = $CSTAapdu->decode($pdu);
+ my $invokeID = $out->{svcRequest}->{invokeID};
+ SystemStatusResult($invokeID);
+}
+
+sub open_csta_socket {
+ my $host = shift;
+ my $port = shift;
+ $socket = new IO::Socket::INET(
+ PeerAddr => $host,
+ PeerPort => $port,
+ Blocking => 1,
+ Proto => 'tcp') || die "Error creating socket: $!\n";
+ $socket->autoflush(1);
+ print("opened a connection to $host on port $port\n");
+}
+sub receive_stuff {
+ my $header = '';
+ my $pdu = '';
+ my $nbytes = $socket->sysread($header, 2);
+ if ($nbytes==1) { # фрагмент пакета
+ my $header2;
+ my $nbytes2= $socket->sysread($header2, 1);
+ $header = $header.$header2;
+ $nbytes = 2;
+ }
+ croak "Didn't receive the specified amount of data (2 bytes)!\n".chr(7) unless ($nbytes == 2);
+ my $len = decode_msg_header($header);
+ $nbytes = $socket->sysread($pdu, $len);
+ if ($nbytes<$len) { # фрагмент пакета
+ my $pdu2;
+ my $nbytes2= $socket->sysread($pdu2, $len-$nbytes);
+ $pdu = $pdu.$pdu2;
+ $nbytes = $nbytes + $nbytes2;
+ }
+ croak "Didn't receive the specified amount of data ($len bytes)!\n".chr(7) unless ($nbytes == $len);
+# my $hexdata = convert_to_hex($pdu);
+# print("RECEIVED:[$hexdata]\n");
+ return $pdu;
+}
+sub GetSystemData{
+ my $DeviceCategory = shift;
+ #EXT=5
+ #CO =2
+ my $pdu = $CSTAapdu->encode({svcRequest=>{
+ invokeID=>4,
+ serviceID=>51,
+ serviceArgs=>{
+ privateData=>{
+ private=>{
+ kmeSystemData=>{
+ getSystemData=>{
+ request=>{
+ deviceList=>{
+ category=>{
+ standardDevice=>$DeviceCategory
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ });
+ #my $pdu = "A11602020602020133300DA40BA009A407A105A0030A010".$DeviceCategory;
+ #$pdu = pack('H*', $pdu);
+ send_pdu($pdu);
+ # getSystemDataPosAck
+ $pdu = receive_stuff();
+ my $out = $CSTAapdu->decode($pdu);
+ my $crossRefID = $out->{svcResult}->{result}->{serviceResult}->{extensions}->{privateData}[0]->{private}->{kmeSystemData}->{getSystemDataPosAck};
+ my $lastSegment=0;
+ # systemDataLinkedReply
+ while (!$lastSegment) {
+ $pdu = receive_stuff();
+ my $out = $CSTAapdu->decode($pdu);
+ my $systemDataLinkedReply = $out->{svcRequest}->{serviceArgs}->{privateData}->{private}->{kmeSystemData}->{systemDataLinkedReply};
+ if (defined $systemDataLinkedReply) {
+ if ($systemDataLinkedReply->{crossRefID} cmp $crossRefID) {next}
+ $lastSegment = $systemDataLinkedReply->{lastSegment};
+ foreach my $KmeDeviceStateEntry (@{$systemDataLinkedReply->{sysData}->{deviceList}}) {
+ if ($KmeDeviceStateEntry->{status}==0) {
+# print "device:",$KmeDeviceStateEntry->{number},"\n";
+ push @devices, ($KmeDeviceStateEntry->{device}->{deviceIdentifier}->{deviceNumber});
+ }
+ }
+ }
+ }
+}
+sub MonitorStartArgument{
+my $device = shift;
+my $pdu = $CSTAapdu->encode({svcRequest=>{
+ invokeID=>9,
+ serviceID=>71,
+ serviceArgs=>{
+ monitorObject=>{
+ deviceObject=>{
+ deviceIdentifier=>{
+ deviceNumber=>$device
+ }
+ }
+ },
+ requestedMonitorFilter=>{}
+ }
+ }
+ });
+send_pdu($pdu);
+#$pdu = receive_stuff();
+}
+sub CSTAEventReportArgument{
+my $refeventSpecificInfo = shift;
+if (defined $refeventSpecificInfo->{eventSpecificInfo}->{callControlEvents}) {
+ my $refcallControlEvents = $refeventSpecificInfo->{eventSpecificInfo}->{callControlEvents};
+ my $callControlEvents = (keys %{$refcallControlEvents})[0];
+ my $Event = $refcallControlEvents->{$callControlEvents};
+ #print Dumper($refcallControlEvents);
+ if ((($Event->{localConnectionInfo}==2) & (($Event->{cause}==22) | ($Event->{cause}==38))) |
+ (($Event->{localConnectionInfo}==3) & ($Event->{cause}==74))) {
+ #localConnectionInfo = allerting and cause=newCall|distributed
+ my $CalledID = deviceID($Event->{alertingDevice}->{deviceIdentifier});
+ my $CallerID;
+ if (defined $Event->{callingDevice}->{notKnown}) {
+ $CallerID = deviceID($Event->{associatedCallingDevice}->{deviceIdentifier})
+ } else {
+ $CallerID = deviceID($Event->{callingDevice}->{deviceIdentifier})
+ }
+ print strftime("%H:%M:%S ", localtime);
+ print("Call to:$CalledID from:$CallerID\n");
+ }
+ }
+}
+sub deviceID{
+ my $deviceIdentifier = shift;
+ $deviceIdentifier = $deviceIdentifier->{deviceIdentifier};
+ if (defined $deviceIdentifier->{dialingNumber}) {
+ return $deviceIdentifier->{dialingNumber}
+ } elsif (defined $deviceIdentifier->{deviceNumber}) {
+ return deviceNumber($deviceIdentifier->{deviceNumber})
+ } elsif (defined $deviceIdentifier->{other}) {
+ return $deviceIdentifier->{other}
+ }
+}
+sub SystemStatusResult{
+ my $invokeID = shift;
+ my $pdu = $CSTAapdu->encode({svcResult=>{invokeID=>$invokeID,result=>{serviceID=>211,serviceResult=>{noData=>1}}}});
+ send_pdu($pdu); # send SystemStatus Result
+}
+$Data::Dumper::Indent=1;
+$Data::Dumper::Pair=' ';
+$Data::Dumper::Quotekeys=0;
+$Data::Dumper::Varname='calls';
+# parse ASN.1 desciptions
+my $asn = Convert::ASN1->new;
+#$asn->configure(tagdefault=>'EXPLICIT');
+$asn->prepare_file('d:\111\asn_perl\kxtde.asn') or die "prepare: ", $asn->error;
+my %serviceArgs = ( 21=> 'CSTAEventReportArgument',
+ 51=> 'EscapeArgument',
+ 71=> 'MonitorStartArgument',
+ 211=> 'SystemStatusArg');
+foreach (keys %serviceArgs) {
+ $asn->registertype('serviceArgs',$_,$asn->find($serviceArgs{$_}));
+}
+my %serviceResults = ( 51=> 'EscapeResult',
+ 71=> 'MonitorStartResult',
+ 211=> 'SystemStatusRes');
+foreach (keys %serviceResults) {
+ $asn->registertype('serviceResult',$_,$asn->find($serviceResults{$_}));
+}
+$CSTAapdu = $asn->find('CSTAapdu');
+csta_connect({'host'=>'192.168.0.101', 'port'=>33333});
+GetSystemData(2);
+GetSystemData(5);
+foreach my $number (@devices) {
+ MonitorStartArgument($number);
+}
+while (1) {
+ my $pdu = receive_stuff();
+ my $out = $CSTAapdu->decode($pdu);
+ if (defined $out->{svcRequest}) {
+ my $serviceID = $out->{svcRequest}->{serviceID};
+ my $invokeID = $out->{svcRequest}->{invokeID};
+ my $serviceArgs = $out->{svcRequest}->{serviceArgs};
+ if ($serviceID==21) {
+ CSTAEventReportArgument($serviceArgs);
+ } elsif ($serviceID==211) { # if SystemStatus Request
+ SystemStatusResult($invokeID);
+ }
+ }
+}
diff --git a/misc/monitorTDE2.pl b/misc/monitorTDE2.pl
index 3e20616..929d243 100755
--- a/misc/monitorTDE2.pl
+++ b/misc/monitorTDE2.pl
@@ -1,242 +1,299 @@
-#!/usr/bin/perl -w
-#ver 0.01 (C)Cyr
-use strict;
-use warnings;
-use diagnostics;
-use IO::Socket;
-use Convert::ASN1;
-use Data::Dumper;
-use Carp;
-use POSIX;
-my $CSTAapdu;
-my $socket;
-my @devices;
-sub deviceNumber{
- my $deviceNumber = shift;
- my $deviceType = $deviceNumber & 0xFFFF0000;
- if ($deviceType==0x1310000) {
- $deviceType='CO'
- } elsif ($deviceType==0x1210000) {
- $deviceType='PS'
- } elsif ($deviceType==0x1110000) {
- $deviceType='EXT'
- } elsif ($deviceType==0x1550000) {
- $deviceType='DISA'
- }
- $deviceNumber = $deviceNumber & 0x0000FFFF;
- return $deviceType.sprintf("%03s",$deviceNumber);
-}
-sub decode_msg_header {
- my $bin = shift;
- my $len = unpack('n', $bin);
- return $len;
-}
-sub encode_msg_header {
- my $len = shift;
- die "Message larger than allowed!" unless ($len <= 240);
- my $bin = pack('n', $len);
- return $bin;
-}
-sub convert_to_hex {
- my $pdu = $_[0];
- my $hexdata = unpack('H*', $pdu);
- $hexdata =~ tr/a-z/A-Z/;
- $hexdata =~ s/(..)/$1 /g;
- $hexdata =~ s/ $//g;
- return $hexdata;
-}
-sub send_pdu {
- my $pdu = $_[0];
- my $header = encode_msg_header(length($pdu));
- $socket->write($header);
- $socket->write($pdu);
-# my $hexdata = convert_to_hex($pdu);
-# print("SENT: [$hexdata]\n");
-}
-sub csta_connect {
- my %args = %{$_[0]};
- open_csta_socket($args{host}, $args{port});
- # A-ASSOCIATE Request
- my $pdu = "602380020780A10706052B0C00815ABE14281206072B0C00821D8148A007A0050303000800";
- $pdu = pack('H*', $pdu);
- send_pdu($pdu);
- # A-ASSOCIATE Result
- $pdu = receive_stuff();
- my $hexdata = convert_to_hex($pdu);
- if ($hexdata =~/A2 03 02 01 01/){
- print "rejected-permanent\n";
- exit 0
- }
- #SystemStatus Request
- $pdu = receive_stuff();
- my $out = $CSTAapdu->decode($pdu);
- my $invokeID = $out->{svcRequest}->{invokeID};
- SystemStatusResult($invokeID);
-}
-
-sub open_csta_socket {
- my $host = shift;
- my $port = shift;
- $socket = new IO::Socket::INET(
- PeerAddr => $host,
- PeerPort => $port,
- Blocking => 1,
- Proto => 'tcp') || die "Error creating socket: $!\n";
- $socket->autoflush(1);
- print("opened a connection to $host on port $port\n");
-}
-sub receive_stuff {
- my $header = '';
- my $pdu = '';
- my $nbytes;
- $nbytes = $socket->sysread($header, 2);
- if ($nbytes==1) { # фрагмент пакета
- my $header2;
- my $nbytes2= $socket->sysread($header2, 1);
- $header = $header.$header2;
- $nbytes = 2;
- }
- croak "Didn't receive the specified amount of data (2 bytes)!\n".chr(7) unless ($nbytes == 2);
- my $len = decode_msg_header($header);
- $nbytes = $socket->sysread($pdu, $len);
- if ($nbytes<$len) { # фрагмент пакета
- my $pdu2;
- my $nbytes2= $socket->sysread($pdu2, $len-$nbytes);
- $pdu = $pdu.$pdu2;
- $nbytes = $nbytes + $nbytes2;
- }
- croak "Didn't receive the specified amount of data ($len bytes)!\n".chr(7) unless ($nbytes == $len);
-# my $hexdata = convert_to_hex($pdu);
-# print("RECEIVED:[$hexdata]\n");
- return $pdu;
-}
-sub GetSystemData{
- my $DeviceCategory = shift;
- #EXT=5
- #CO =2
- my $pdu = $CSTAapdu->encode({svcRequest=>{
- invokeID=>4,
- serviceID=>51,
- serviceArgs=>{
- privateData=>{
- private=>{
- kmeSystemData=>{
- getSystemData=>{
- request=>{
- deviceList=>{
- category=>{
- standardDevice=>$DeviceCategory
- }
- }
- }
- }
- }
- }
- }
- }
- }
- });
- #my $pdu = "A11602020602020133300DA40BA009A407A105A0030A010".$DeviceCategory;
- #$pdu = pack('H*', $pdu);
- send_pdu($pdu);
- # getSystemDataPosAck
- $pdu = receive_stuff();
- my $out = $CSTAapdu->decode($pdu);
- my $crossRefID = $out->{svcResult}->{result}->{serviceResult}->{extensions}->{privateData}[0]->{private}->{kmeSystemData}->{getSystemDataPosAck};
- my $lastSegment=0;
- # systemDataLinkedReply
- while (!$lastSegment) {
- $pdu = receive_stuff();
- my $out = $CSTAapdu->decode($pdu);
- my $systemDataLinkedReply = $out->{svcRequest}->{serviceArgs}->{privateData}->{private}->{kmeSystemData}->{systemDataLinkedReply};
- if (defined $systemDataLinkedReply) {
- if ($systemDataLinkedReply->{crossRefID} cmp $crossRefID) {next}
- $lastSegment = $systemDataLinkedReply->{lastSegment};
- foreach my $KmeDeviceStateEntry (@{$systemDataLinkedReply->{sysData}->{deviceList}}) {
- if ($KmeDeviceStateEntry->{status}==0) {
-# print "device:",$KmeDeviceStateEntry->{number},"\n";
- push @devices, ($KmeDeviceStateEntry->{device}->{deviceIdentifier}->{deviceNumber});
- }
- }
- }
- }
-}
-sub MonitorStartArgument{
- my $device = shift;
- my $pdu = $CSTAapdu->encode({svcRequest=>{
- invokeID=>9,
- serviceID=>71,
- serviceArgs=>{
- monitorObject=>{
- deviceObject=>{
- deviceIdentifier=>{
- deviceNumber=>$device
- }
- }
- },
- requestedMonitorFilter=>{}
- }
- }
- });
- send_pdu($pdu);
- #$pdu = receive_stuff();
-}
-sub deviceID{
- my $deviceIdentifier = shift;
- $deviceIdentifier = $deviceIdentifier->{deviceIdentifier};
- if (defined $deviceIdentifier->{dialingNumber}) {
- return $deviceIdentifier->{dialingNumber}
- } elsif (defined $deviceIdentifier->{deviceNumber}) {
- return deviceNumber($deviceIdentifier->{deviceNumber})
- } elsif (defined $deviceIdentifier->{other}) {
- return $deviceIdentifier->{other}
- }
-}
-sub SystemStatusResult{
- my $invokeID = shift;
- my $pdu = $CSTAapdu->encode({svcResult=>{invokeID=>$invokeID,result=>{serviceID=>211,serviceResult=>{noData=>1}}}});
- send_pdu($pdu); # send SystemStatus Result
-}
-$Data::Dumper::Indent=1;
-$Data::Dumper::Pair=' ';
-$Data::Dumper::Quotekeys=0;
-$Data::Dumper::Varname='calls';
-# parse ASN.1 desciptions
-my $asn = Convert::ASN1->new;
-#$asn->configure(tagdefault=>'EXPLICIT');
-$asn->prepare_file('kxtde.asn') or die "prepare: ", $asn->error;
-my %serviceArgs = ( 21=> 'CSTAEventReportArgument',
- 51=> 'EscapeArgument',
- 71=> 'MonitorStartArgument',
- 211=> 'SystemStatusArg');
-foreach (keys %serviceArgs) {
- $asn->registertype('serviceArgs',$_,$asn->find($serviceArgs{$_}));
-}
-my %serviceResults = ( 51=> 'EscapeResult',
- 71=> 'MonitorStartResult',
- 211=> 'SystemStatusRes');
-foreach (keys %serviceResults) {
- $asn->registertype('serviceResult',$_,$asn->find($serviceResults{$_}));
-}
-$CSTAapdu = $asn->find('CSTAapdu');
-csta_connect({'host'=>'192.168.240.20', 'port'=>33333});
-GetSystemData(2);
-GetSystemData(5);
-foreach my $number (@devices) {
- MonitorStartArgument($number);
-}
-while (1) {
- my $pdu = receive_stuff();
- Convert::ASN1::asn_hexdump($pdu);
- Convert::ASN1::asn_dump($pdu);
- my $out = $CSTAapdu->decode($pdu);
- print Dumper($out);
- if (defined $out->{svcRequest}) {
- my $serviceID = $out->{svcRequest}->{serviceID};
- my $invokeID = $out->{svcRequest}->{invokeID};
- my $serviceArgs = $out->{svcRequest}->{serviceArgs};
- if ($serviceID==211) { # if SystemStatus Request
- SystemStatusResult($invokeID);
- }
- }
-}
+#!/usr/bin/perl -w
+#ver 0.01 (C)Cyr
+use strict;
+use warnings;
+use diagnostics;
+use IO::Socket;
+use Convert::ASN1;
+use Data::Dumper;
+use Carp;
+use POSIX;
+my $CSTAapdu;
+my $socket;
+my @devices;
+
+sub deviceNumber {
+ my $deviceNumber = shift;
+ my $deviceType = $deviceNumber & 0xFFFF0000;
+ if ( $deviceType == 0x1310000 ) {
+ $deviceType = 'CO';
+ }
+ elsif ( $deviceType == 0x1210000 ) {
+ $deviceType = 'PS';
+ }
+ elsif ( $deviceType == 0x1110000 ) {
+ $deviceType = 'EXT';
+ }
+ elsif ( $deviceType == 0x1550000 ) {
+ $deviceType = 'DISA';
+ }
+ $deviceNumber = $deviceNumber & 0x0000FFFF;
+ return $deviceType . sprintf( "%03s", $deviceNumber );
+}
+
+sub decode_msg_header {
+ my $bin = shift;
+ my $len = unpack( 'n', $bin );
+ return $len;
+}
+
+sub encode_msg_header {
+ my $len = shift;
+ die "Message larger than allowed!" unless ( $len <= 240 );
+ my $bin = pack( 'n', $len );
+ return $bin;
+}
+
+sub convert_to_hex {
+ my $pdu = $_[0];
+ my $hexdata = unpack( 'H*', $pdu );
+ $hexdata =~ tr/a-z/A-Z/;
+ $hexdata =~ s/(..)/$1 /g;
+ $hexdata =~ s/ $//g;
+ return $hexdata;
+}
+
+sub send_pdu {
+ my $pdu = $_[0];
+ my $header = encode_msg_header( length($pdu) );
+ $socket->write($header);
+ $socket->write($pdu);
+
+ # my $hexdata = convert_to_hex($pdu);
+ # print("SENT: [$hexdata]\n");
+}
+
+sub csta_connect {
+ my %args = %{ $_[0] };
+ open_csta_socket( $args{host}, $args{port} );
+
+ # A-ASSOCIATE Request
+ my $pdu =
+"602380020780A10706052B0C00815ABE14281206072B0C00821D8148A007A0050303000800";
+ $pdu = pack( 'H*', $pdu );
+ send_pdu($pdu);
+
+ # A-ASSOCIATE Result
+ $pdu = receive_stuff();
+ my $hexdata = convert_to_hex($pdu);
+ if ( $hexdata =~ /A2 03 02 01 01/ ) {
+ print "rejected-permanent\n";
+ exit 0;
+ }
+
+ #SystemStatus Request
+ $pdu = receive_stuff();
+ my $out = $CSTAapdu->decode($pdu);
+ my $invokeID = $out->{svcRequest}->{invokeID};
+ SystemStatusResult($invokeID);
+}
+
+sub open_csta_socket {
+ my $host = shift;
+ my $port = shift;
+ $socket = new IO::Socket::INET(
+ PeerAddr => $host,
+ PeerPort => $port,
+ Blocking => 1,
+ Proto => 'tcp'
+ ) || die "Error creating socket: $!\n";
+ $socket->autoflush(1);
+ print("opened a connection to $host on port $port\n");
+}
+
+sub receive_stuff {
+ my $header = '';
+ my $pdu = '';
+ my $nbytes;
+ $nbytes = $socket->sysread( $header, 2 );
+ if ( $nbytes == 1 ) { # фрагмент пакета
+ my $header2;
+ my $nbytes2 = $socket->sysread( $header2, 1 );
+ $header = $header . $header2;
+ $nbytes = 2;
+ }
+ croak "Didn't receive the specified amount of data (2 bytes)!\n" . chr(7)
+ unless ( $nbytes == 2 );
+ my $len = decode_msg_header($header);
+ $nbytes = $socket->sysread( $pdu, $len );
+ if ( $nbytes < $len ) { # фрагмент пакета
+ my $pdu2;
+ my $nbytes2 = $socket->sysread( $pdu2, $len - $nbytes );
+ $pdu = $pdu . $pdu2;
+ $nbytes = $nbytes + $nbytes2;
+ }
+ croak "Didn't receive the specified amount of data ($len bytes)!\n" . chr(7)
+ unless ( $nbytes == $len );
+
+ # my $hexdata = convert_to_hex($pdu);
+ # print("RECEIVED:[$hexdata]\n");
+ return $pdu;
+}
+
+sub GetSystemData {
+ my $DeviceCategory = shift;
+
+ #EXT=5
+ #CO =2
+ my $pdu = $CSTAapdu->encode(
+ {
+ svcRequest => {
+ invokeID => 4,
+ serviceID => 51,
+ serviceArgs => {
+ privateData => {
+ private => {
+ kmeSystemData => {
+ getSystemData => {
+ request => {
+ deviceList => {
+ category => {
+ standardDevice =>
+ $DeviceCategory
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ );
+
+ #my $pdu = "A11602020602020133300DA40BA009A407A105A0030A010".$DeviceCategory;
+ #$pdu = pack('H*', $pdu);
+ send_pdu($pdu);
+
+ # getSystemDataPosAck
+ $pdu = receive_stuff();
+ my $out = $CSTAapdu->decode($pdu);
+ my $crossRefID =
+ $out->{svcResult}->{result}->{serviceResult}->{extensions}
+ ->{privateData}[0]->{private}->{kmeSystemData}->{getSystemDataPosAck};
+ my $lastSegment = 0;
+
+ # systemDataLinkedReply
+ while ( !$lastSegment ) {
+ $pdu = receive_stuff();
+ my $out = $CSTAapdu->decode($pdu);
+ my $systemDataLinkedReply =
+ $out->{svcRequest}->{serviceArgs}->{privateData}->{private}
+ ->{kmeSystemData}->{systemDataLinkedReply};
+ if ( defined $systemDataLinkedReply ) {
+ if ( $systemDataLinkedReply->{crossRefID} cmp $crossRefID ) { next }
+ $lastSegment = $systemDataLinkedReply->{lastSegment};
+ foreach my $KmeDeviceStateEntry (
+ @{ $systemDataLinkedReply->{sysData}->{deviceList} } )
+ {
+ if ( $KmeDeviceStateEntry->{status} == 0 ) {
+
+ # print "device:",$KmeDeviceStateEntry->{number},"\n";
+ push @devices,
+ ( $KmeDeviceStateEntry->{device}->{deviceIdentifier}
+ ->{deviceNumber} );
+ }
+ }
+ }
+ }
+}
+
+sub MonitorStartArgument {
+ my $device = shift;
+ my $pdu = $CSTAapdu->encode(
+ {
+ svcRequest => {
+ invokeID => 9,
+ serviceID => 71,
+ serviceArgs => {
+ monitorObject => {
+ deviceObject =>
+ { deviceIdentifier => { deviceNumber => $device } }
+ },
+ requestedMonitorFilter => {}
+ }
+ }
+ }
+ );
+ send_pdu($pdu);
+
+ #$pdu = receive_stuff();
+}
+
+sub deviceID {
+ my $deviceIdentifier = shift;
+ $deviceIdentifier = $deviceIdentifier->{deviceIdentifier};
+ if ( defined $deviceIdentifier->{dialingNumber} ) {
+ return $deviceIdentifier->{dialingNumber};
+ }
+ elsif ( defined $deviceIdentifier->{deviceNumber} ) {
+ return deviceNumber( $deviceIdentifier->{deviceNumber} );
+ }
+ elsif ( defined $deviceIdentifier->{other} ) {
+ return $deviceIdentifier->{other};
+ }
+}
+
+sub SystemStatusResult {
+ my $invokeID = shift;
+ my $pdu = $CSTAapdu->encode(
+ {
+ svcResult => {
+ invokeID => $invokeID,
+ result => { serviceID => 211, serviceResult => { noData => 1 } }
+ }
+ }
+ );
+ send_pdu($pdu); # send SystemStatus Result
+}
+$Data::Dumper::Indent = 1;
+$Data::Dumper::Pair = ' ';
+$Data::Dumper::Quotekeys = 0;
+$Data::Dumper::Varname = 'calls';
+
+# parse ASN.1 desciptions
+my $asn = Convert::ASN1->new;
+
+#$asn->configure(tagdefault=>'EXPLICIT');
+$asn->prepare_file('kxtde.asn') or die "prepare: ", $asn->error;
+my %serviceArgs = (
+ 21 => 'CSTAEventReportArgument',
+ 51 => 'EscapeArgument',
+ 71 => 'MonitorStartArgument',
+ 211 => 'SystemStatusArg'
+);
+foreach ( keys %serviceArgs ) {
+ $asn->registertype( 'serviceArgs', $_, $asn->find( $serviceArgs{$_} ) );
+}
+my %serviceResults = (
+ 51 => 'EscapeResult',
+ 71 => 'MonitorStartResult',
+ 211 => 'SystemStatusRes'
+);
+foreach ( keys %serviceResults ) {
+ $asn->registertype( 'serviceResult', $_,
+ $asn->find( $serviceResults{$_} ) );
+}
+$CSTAapdu = $asn->find('CSTAapdu');
+csta_connect( { 'host' => '192.168.240.20', 'port' => 33333 } );
+GetSystemData(2);
+GetSystemData(5);
+foreach my $number (@devices) {
+ MonitorStartArgument($number);
+}
+while (1) {
+ my $pdu = receive_stuff();
+ Convert::ASN1::asn_hexdump($pdu);
+ Convert::ASN1::asn_dump($pdu);
+ my $out = $CSTAapdu->decode($pdu);
+ print Dumper($out);
+ if ( defined $out->{svcRequest} ) {
+ my $serviceID = $out->{svcRequest}->{serviceID};
+ my $invokeID = $out->{svcRequest}->{invokeID};
+ my $serviceArgs = $out->{svcRequest}->{serviceArgs};
+ if ( $serviceID == 211 ) { # if SystemStatus Request
+ SystemStatusResult($invokeID);
+ }
+ }
+}
diff --git a/misc/snapshot.pl b/misc/snapshot.pl
index bd4953b..de0c63b 100644
--- a/misc/snapshot.pl
+++ b/misc/snapshot.pl
@@ -1,462 +1,537 @@
-#ver 0.11 (C)Cyr
-use strict;
-use warnings;
-use diagnostics;
-use IO::Socket;
-use Convert::ASN1;
-#use Data::Dumper;
-use Carp;
-use POSIX;
-my $CSTAapdu;
-my $socket;
-my @devices;
-my @calls;
-sub deviceNumber{
- my $deviceNumber = shift;
- if (defined $deviceNumber->{deviceNumber}) {
- $deviceNumber = $deviceNumber->{deviceNumber};
- my $deviceType = $deviceNumber & 0xFFFF0000;
- if ($deviceType==0x1310000) {
- $deviceType='CO'
- } elsif ($deviceType==0x1210000) {
- $deviceType='PS'
- } elsif ($deviceType==0x1110000) {
- $deviceType='EXT'
- }
- $deviceNumber = $deviceNumber & 0x0000FFFF;
- return $deviceType.sprintf("%03s",$deviceNumber);
- } elsif (defined $deviceNumber->{dialingNumber}) {
- return $deviceNumber->{dialingNumber}
- }
-}
-sub localConnectionInfo{
- my $localConnectionInfo = shift;
- if ($localConnectionInfo== 0){
- return 'null'
- } elsif ($localConnectionInfo== 1){
- return 'initiated'
- } elsif ($localConnectionInfo== 2){
- return 'alerting'
- } elsif ($localConnectionInfo== 3){
- return 'connected'
- } elsif ($localConnectionInfo== 4){
- return 'hold'
- } elsif ($localConnectionInfo== 5){
- return 'queued'
- } elsif ($localConnectionInfo== 6){
- return 'fail'
- } else {return $localConnectionInfo}
-}
-
-sub decode_msg_header {
- my $bin = shift;
- my $len = unpack('n', $bin);
- return $len;
-}
-sub encode_msg_header {
- my $len = shift;
- die "Message larger than allowed!" unless ($len <= 240);
- my $bin = pack('n', $len);
- return $bin;
-}
-sub convert_to_hex {
- my $pdu = $_[0];
- my $hexdata = unpack('H*', $pdu);
- $hexdata =~ tr/a-z/A-Z/;
- $hexdata =~ s/(..)/$1 /g;
- $hexdata =~ s/ $//g;
- return $hexdata;
-}
-sub send_pdu {
- my $pdu = $_[0];
- my $header = encode_msg_header(length($pdu));
- $socket->write($header);
- $socket->write($pdu);
-# my $hexdata = convert_to_hex($pdu);
-# print("SENT: [$hexdata]\n");
-}
-sub csta_connect {
- my %args = %{$_[0]};
- open_csta_socket($args{host}, $args{port});
- # A-ASSOCIATE Request
- my $pdu = "602380020780A10706052B0C00815ABE14281206072B0C00821D8148A007A0050303000800";
- $pdu = pack('H*', $pdu);
- send_pdu($pdu);
- # A-ASSOCIATE Result
- $pdu = receive_stuff();
- my $hexdata = convert_to_hex($pdu);
- if ($hexdata =~/A2 03 02 01 01/){
- print "rejected-permanent\n";
- exit 0
- }
- #SystemStatus Request
- $pdu = receive_stuff();
- my $out = $CSTAapdu->decode($pdu);
- my $invokeID = $out->{svcRequest}->{invokeID};
- SystemStatusResult($invokeID);
-}
-
-sub open_csta_socket {
- my $host = shift;
- my $port = shift;
- $socket = new IO::Socket::INET(
- PeerAddr => $host,
- PeerPort => $port,
- Blocking => 1,
- Proto => 'tcp') || die "Error creating socket: $!\n";
- $socket->autoflush(1);
- print("opened a connection to $host on port $port\n");
-}
-sub receive_stuff {
- my $header = '';
- my $pdu = '';
- my $nbytes = $socket->sysread($header, 2);
- if ($nbytes==1) { # фрагмент пакета
- my $header2;
- my $nbytes2= $socket->sysread($header2, 1);
- $header = $header.$header2;
- $nbytes = 2;
- }
- croak "Didn't receive the specified amount of data (2 bytes)!\n".chr(7) unless ($nbytes == 2);
- my $len = decode_msg_header($header);
- $nbytes = $socket->sysread($pdu, $len);
- if ($nbytes<$len) { # фрагмент пакета
- my $pdu2;
- my $nbytes2= $socket->sysread($pdu2, $len-$nbytes);
- $pdu = $pdu.$pdu2;
- $nbytes = $nbytes + $nbytes2;
- }
- croak "Didn't receive the specified amount of data ($len bytes)!\n".chr(7) unless ($nbytes == $len);
-# my $hexdata = convert_to_hex($pdu);
-# print("RECEIVED:[$hexdata]\n");
- return $pdu;
-}
-sub GetSystemData{
- my $DeviceCategory = shift;
- #EXT=5
- #CO =2
- my $pdu = $CSTAapdu->encode({svcRequest=>{
- invokeID=>4,
- serviceID=>51,
- serviceArgs=>{
- privateData=>{
- private=>{
- kmeSystemData=>{
- getSystemData=>{
- request=>{
- deviceList=>{
- category=>{
- standardDevice=>$DeviceCategory
- }
- }
- }
- }
- }
- }
- }
- }
- }
- });
- #my $pdu = "A11602020602020133300DA40BA009A407A105A0030A010".$DeviceCategory;
- #$pdu = pack('H*', $pdu);
- send_pdu($pdu);
- # getSystemDataPosAck
- $pdu = receive_stuff();
- my $out = $CSTAapdu->decode($pdu);
- my $crossRefID = $out->{svcResult}->{result}->{serviceResult}->{extensions}->{privateData}[0]->{private}->{kmeSystemData}->{getSystemDataPosAck};
- my $lastSegment=0;
- # systemDataLinkedReply
- while (!$lastSegment) {
- $pdu = receive_stuff();
- my $out = $CSTAapdu->decode($pdu);
- my $systemDataLinkedReply = $out->{svcRequest}->{serviceArgs}->{privateData}->{private}->{kmeSystemData}->{systemDataLinkedReply};
- if (defined $systemDataLinkedReply) {
- if ($systemDataLinkedReply->{crossRefID} cmp $crossRefID) {next}
- $lastSegment = $systemDataLinkedReply->{lastSegment};
- foreach my $KmeDeviceStateEntry (@{$systemDataLinkedReply->{sysData}->{deviceList}}) {
- if ($KmeDeviceStateEntry->{status}==0) {
- print "device:",$KmeDeviceStateEntry->{number},"\n";
- push @devices, ($KmeDeviceStateEntry->{device}->{deviceIdentifier}->{deviceNumber});
- }
- }
- }
- }
-}
-sub SnapshotDeviceRequest{
- my $device = shift;
- my $pdu = $CSTAapdu->encode({svcRequest=>{
- invokeID=>9,
- serviceID=>74,
- serviceArgs=>{
- snapshotObject=>{
- deviceIdentifier=>{
- deviceNumber=>$device
- }
- }
- }
- }
- });
- #$device = sprintf("%08X",$device);
- #print("SnapshotDeviceRequest: $device\n");
- #my $pdu = "A11002010202014A300830068104".$device;
- #$pdu = pack('H*', $pdu);
- send_pdu($pdu);
-}
-sub SnapshotDeviceResult{
- my $refSnapshotDeviceResult = shift;
- my $refsnapshotData = ($refSnapshotDeviceResult->{crossRefIDorSnapshotData}->{snapshotData});
- foreach my $SnapshotDeviceResponseInfo (@{$refsnapshotData}) {
- my $callID = $SnapshotDeviceResponseInfo->{connectionIdentifier}->{both}->{callID};
- my $deviceID = deviceNumber($SnapshotDeviceResponseInfo->{connectionIdentifier}->{both}->{deviceID}->{staticID}->{deviceIdentifier});
- foreach my $LocalConnectionState (@{$SnapshotDeviceResponseInfo->{localCallState}->{compoundCallState}}) {
- my $ConnectionState = localConnectionInfo($LocalConnectionState);
- push @calls, [$callID, $deviceID, $ConnectionState];
- }
-
- }
-}
-sub SystemStatusResult{
- my $invokeID = shift;
- my $pdu = $CSTAapdu->encode({svcResult=>{invokeID=>$invokeID,result=>{serviceID=>211,serviceResult=>{noData=>1}}}});
- send_pdu($pdu); # send SystemStatus Result
-}
-# parse ASN.1 desciptions
-my $asn = Convert::ASN1->new;
-#$asn->configure(tagdefault=>'EXPLICIT');
-$asn->prepare(<<ASN1) or die "prepare: ", $asn->error;
-CSTAapdu ::= CHOICE {
- svcRequest ROIVapdu,
- svcResult RORSapdu
--- svcError ROERapdu,
--- svcReject RORJapdu
-}
-ROIVapdu ::= [1] IMPLICIT SEQUENCE {
- invokeID INTEGER,
- serviceID INTEGER,
- serviceArgs ANY DEFINED BY serviceID
-}
-RORSapdu ::= [2] IMPLICIT SEQUENCE {
- invokeID INTEGER,
- result SEQUENCE {
- serviceID INTEGER,
- serviceResult ANY DEFINED BY serviceID OPTIONAL
- }
-}
-EscapeArgument ::= SEQUENCE
-{ --escapeRegisterID EscapeRegisterID OPTIONAL,
- --security CSTASecurityData OPTIONAL,
- privateData CSTAPrivateData }
-
-CSTAPrivateData ::= CHOICE
-{ string OCTET STRING,
- private KmeSpecificPrivateData
-}
-KmeSpecificPrivateData ::= CHOICE
-{ kmeSystemData [4] KmeSystemData
-}
-KmeSystemData ::= CHOICE
-{ getSystemData [0] KmeGetSystemData,
- systemDataLinkedReply [3] EXPLICIT KmeSystemDataLinkedReply,
- getSystemDataPosAck [4] EXPLICIT KmeGetSystemDataPosAck
-}
-KmeGetSystemData ::= CHOICE
-{ request KmeGetSystemDataReq --!
---result KmeGetSystemDataRsp
-}
-KmeGetSystemDataReq ::= CHOICE
-{
-deviceList [4] KmeRequestedDevice --!
-}
-KmeRequestedDevice ::= CHOICE -- for GetSystemData.deviceList
-{ --device [0] DeviceID,
- category [1] KmeDeviceCategory} --!
-
-KmeDeviceCategory ::= CHOICE
-{ standardDevice [0] EXPLICIT DeviceCategory--!
- -- kmeDevice [1] KmeOtherDevice
-}
-DeviceCategory ::= ENUMERATED
-{ acd (0),
- group (1),
- networkInterface (2), --!
- park (3),
- routeingDevice (4),
- station (5), --!
- voiceUnit (6),
- other (7)
-}
-KmeSystemDataLinkedReply ::= SEQUENCE
-{ crossRefID [0] EXPLICIT ServiceCrossRefID,
- segmentID [1] EXPLICIT INTEGER,
- lastSegment [2] EXPLICIT BOOLEAN,
- sysData [3] EXPLICIT KmeGetSystemDataRsp OPTIONAL
-}
-ServiceCrossRefID ::= OCTET STRING
-
-KmeGetSystemDataPosAck ::= ServiceCrossRefID
-
-KmeGetSystemDataRsp ::= SEQUENCE
-{ deviceList [38] EXPLICIT KmeDeviceStateList OPTIONAL
-}
-KmeDeviceStateList ::= SEQUENCE OF KmeDeviceStateEntry
-
-KmeDeviceStateEntry ::= SEQUENCE
-{ device DeviceID,
- number IA5String OPTIONAL, -- Ext No, CO No, Park Area No.
- status KmeDeviceState
-}
-KmeDeviceState ::= ENUMERATED
-{ ins (0),
- ous (1)
-}
-EscapeResult ::= CHOICE
-{ extensions CSTACommonArguments,
- noData NULL
-}
-CSTACommonArguments ::= [APPLICATION 30] IMPLICIT SEQUENCE
-{ privateData [1] IMPLICIT SEQUENCE OF CSTAPrivateData OPTIONAL }
-
-CSTAPrivateData ::= CHOICE
-{ string OCTET STRING,
- private KmeSpecificPrivateData
-}
-
---snapshotDevice OPERATION ::=
---{ ARGUMENT SnapshotDeviceArgument,
--- RESULT SnapshotDeviceResult
--- ERRORS {universalFailure}
--- CODE local: 74}
-
-SnapshotDeviceArgument ::= SEQUENCE
-{ snapshotObject DeviceID}
-
-SnapshotDeviceResult ::= SEQUENCE
-{ crossRefIDorSnapshotData
- CHOICE
- { serviceCrossRefID ServiceCrossRefID,
- snapshotData SnapshotDeviceData
- }
-}
-
-ServiceCrossRefID ::= OCTET STRING
-
-SnapshotDeviceData ::= [APPLICATION 22] IMPLICIT SEQUENCE OF SnapshotDeviceResponseInfo
-
-SnapshotDeviceResponseInfo ::= SEQUENCE
-{ connectionIdentifier ConnectionID,
- localCallState CallState}
-
-ConnectionID ::= [APPLICATION 11] CHOICE
-{
- deviceID [1] LocalDeviceID,
- both SEQUENCE
- { callID [0] IMPLICIT CallID,
- deviceID [1] LocalDeviceID
- }
-}
-
-CallID ::= OCTET STRING
-
-LocalDeviceID ::= CHOICE
-{ staticID DeviceID}
-
-DeviceID ::= SEQUENCE
-{ deviceIdentifier CHOICE
- { dialingNumber [0] IMPLICIT NumberDigits,
- deviceNumber [1] IMPLICIT DeviceNumber,
- other [6] IMPLICIT OtherPlan
- }
-}
-OtherPlan ::= OCTET STRING
-
-NumberDigits ::= IA5String
-
-DeviceNumber ::= INTEGER
-
-CallState ::= CHOICE
-{ compoundCallState [0] IMPLICIT CompoundCallState}
-
-CompoundCallState ::= SEQUENCE OF LocalConnectionState
-
-LocalConnectionState ::= [APPLICATION 14] IMPLICIT ENUMERATED
-{ null (0),
- initiated (1),
- alerting (2),
- connected (3),
- hold (4),
- queued (5),
- fail (6)
-}
-systemStatus ::= CHOICE
-{ ARGUMENT SystemStatusArg,
- RESULT SystemStatusRes
--- ERRORS {universalFailure}
--- CODE local: 211
-}
-SystemStatusArg ::= SEQUENCE
-{ systemStatus SystemStatus}
-
-SystemStatusRes ::= CHOICE
-{ noData NULL}
-
-SystemStatus ::= ENUMERATED
-{ normal (2),
- messageLost (3),
- overloadReached (6)
-}
-ASN1
-my %serviceArgs = ( 51=> 'EscapeArgument',
- 74=> 'SnapshotDeviceArgument',
- 211=> 'SystemStatusArg');
-foreach (keys %serviceArgs) {
- $asn->registertype('serviceArgs',$_,$asn->find($serviceArgs{$_}));
-}
-my %serviceResults = ( 51=> 'EscapeResult',
- 74=> 'SnapshotDeviceResult',
- 211=> 'SystemStatusRes');
- foreach (keys %serviceResults) {
- $asn->registertype('serviceResult',$_,$asn->find($serviceResults{$_}));
-}
-$CSTAapdu = $asn->find('CSTAapdu');
-csta_connect({'host'=>'192.168.0.101', 'port'=>33333});
-GetSystemData(2);
-GetSystemData(5);
-my $maxCO=0;
-while (1) {
- foreach my $number (@devices) {
- SnapshotDeviceRequest($number);
- }
- undef @calls;
- my $alldevices=$#devices+1;
- while ($alldevices) {
- my $pdu = receive_stuff();
- my $out = $CSTAapdu->decode($pdu);
- if (defined $out->{svcRequest}) {
- my $serviceID = $out->{svcRequest}->{serviceID};
- my $invokeID = $out->{svcRequest}->{invokeID};
- if ($serviceID==211) { # if SystemStatus Request
- SystemStatusResult($invokeID);
- }
- } elsif (defined $out->{svcResult}) {
- my $serviceResult= $out->{svcResult}->{result}->{serviceResult};
- my $serviceID = $out->{svcResult}->{result}->{serviceID};
- if ($serviceID==74) {
- SnapshotDeviceResult($serviceResult);
- $alldevices = $alldevices-1;
- }
- }
- }
- my $CO=0;
- for (@calls) {
- $CO++ if $_->[1] =~/^CO/;
- }
- if ($maxCO<$CO) {
- $maxCO=$CO;
- print chr(7);
- }
- system ('CLS'); # for windows, 'clear' for linux
- print strftime("%H:%M:%S ", localtime),"maxCO:",$maxCO," CO:",$CO,"\n";
- print "callID: deviceID: CallState:\n";
- printf ("%-8s%-10s%-10s\n",$_->[0],$_->[1],$_->[2]) for sort {$a -> [0] cmp $b -> [0]} @calls;
- sleep 1;
-}
+#ver 0.11 (C)Cyr
+use strict;
+use warnings;
+use diagnostics;
+use IO::Socket;
+use Convert::ASN1;
+
+#use Data::Dumper;
+use Carp;
+use POSIX;
+my $CSTAapdu;
+my $socket;
+my @devices;
+my @calls;
+
+sub deviceNumber {
+ my $deviceNumber = shift;
+ if ( defined $deviceNumber->{deviceNumber} ) {
+ $deviceNumber = $deviceNumber->{deviceNumber};
+ my $deviceType = $deviceNumber & 0xFFFF0000;
+ if ( $deviceType == 0x1310000 ) {
+ $deviceType = 'CO';
+ }
+ elsif ( $deviceType == 0x1210000 ) {
+ $deviceType = 'PS';
+ }
+ elsif ( $deviceType == 0x1110000 ) {
+ $deviceType = 'EXT';
+ }
+ $deviceNumber = $deviceNumber & 0x0000FFFF;
+ return $deviceType . sprintf( "%03s", $deviceNumber );
+ }
+ elsif ( defined $deviceNumber->{dialingNumber} ) {
+ return $deviceNumber->{dialingNumber};
+ }
+}
+
+sub localConnectionInfo {
+ my $localConnectionInfo = shift;
+ if ( $localConnectionInfo == 0 ) {
+ return 'null';
+ }
+ elsif ( $localConnectionInfo == 1 ) {
+ return 'initiated';
+ }
+ elsif ( $localConnectionInfo == 2 ) {
+ return 'alerting';
+ }
+ elsif ( $localConnectionInfo == 3 ) {
+ return 'connected';
+ }
+ elsif ( $localConnectionInfo == 4 ) {
+ return 'hold';
+ }
+ elsif ( $localConnectionInfo == 5 ) {
+ return 'queued';
+ }
+ elsif ( $localConnectionInfo == 6 ) {
+ return 'fail';
+ }
+ else { return $localConnectionInfo }
+}
+
+sub decode_msg_header {
+ my $bin = shift;
+ my $len = unpack( 'n', $bin );
+ return $len;
+}
+
+sub encode_msg_header {
+ my $len = shift;
+ die "Message larger than allowed!" unless ( $len <= 240 );
+ my $bin = pack( 'n', $len );
+ return $bin;
+}
+
+sub convert_to_hex {
+ my $pdu = $_[0];
+ my $hexdata = unpack( 'H*', $pdu );
+ $hexdata =~ tr/a-z/A-Z/;
+ $hexdata =~ s/(..)/$1 /g;
+ $hexdata =~ s/ $//g;
+ return $hexdata;
+}
+
+sub send_pdu {
+ my $pdu = $_[0];
+ my $header = encode_msg_header( length($pdu) );
+ $socket->write($header);
+ $socket->write($pdu);
+
+ # my $hexdata = convert_to_hex($pdu);
+ # print("SENT: [$hexdata]\n");
+}
+
+sub csta_connect {
+ my %args = %{ $_[0] };
+ open_csta_socket( $args{host}, $args{port} );
+
+ # A-ASSOCIATE Request
+ my $pdu =
+"602380020780A10706052B0C00815ABE14281206072B0C00821D8148A007A0050303000800";
+ $pdu = pack( 'H*', $pdu );
+ send_pdu($pdu);
+
+ # A-ASSOCIATE Result
+ $pdu = receive_stuff();
+ my $hexdata = convert_to_hex($pdu);
+ if ( $hexdata =~ /A2 03 02 01 01/ ) {
+ print "rejected-permanent\n";
+ exit 0;
+ }
+
+ #SystemStatus Request
+ $pdu = receive_stuff();
+ my $out = $CSTAapdu->decode($pdu);
+ my $invokeID = $out->{svcRequest}->{invokeID};
+ SystemStatusResult($invokeID);
+}
+
+sub open_csta_socket {
+ my $host = shift;
+ my $port = shift;
+ $socket = new IO::Socket::INET(
+ PeerAddr => $host,
+ PeerPort => $port,
+ Blocking => 1,
+ Proto => 'tcp'
+ ) || die "Error creating socket: $!\n";
+ $socket->autoflush(1);
+ print("opened a connection to $host on port $port\n");
+}
+
+sub receive_stuff {
+ my $header = '';
+ my $pdu = '';
+ my $nbytes = $socket->sysread( $header, 2 );
+ if ( $nbytes == 1 ) { # фрагмент пакета
+ my $header2;
+ my $nbytes2 = $socket->sysread( $header2, 1 );
+ $header = $header . $header2;
+ $nbytes = 2;
+ }
+ croak "Didn't receive the specified amount of data (2 bytes)!\n" . chr(7)
+ unless ( $nbytes == 2 );
+ my $len = decode_msg_header($header);
+ $nbytes = $socket->sysread( $pdu, $len );
+ if ( $nbytes < $len ) { # фрагмент пакета
+ my $pdu2;
+ my $nbytes2 = $socket->sysread( $pdu2, $len - $nbytes );
+ $pdu = $pdu . $pdu2;
+ $nbytes = $nbytes + $nbytes2;
+ }
+ croak "Didn't receive the specified amount of data ($len bytes)!\n" . chr(7)
+ unless ( $nbytes == $len );
+
+ # my $hexdata = convert_to_hex($pdu);
+ # print("RECEIVED:[$hexdata]\n");
+ return $pdu;
+}
+
+sub GetSystemData {
+ my $DeviceCategory = shift;
+
+ #EXT=5
+ #CO =2
+ my $pdu = $CSTAapdu->encode(
+ {
+ svcRequest => {
+ invokeID => 4,
+ serviceID => 51,
+ serviceArgs => {
+ privateData => {
+ private => {
+ kmeSystemData => {
+ getSystemData => {
+ request => {
+ deviceList => {
+ category => {
+ standardDevice =>
+ $DeviceCategory
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ );
+
+ #my $pdu = "A11602020602020133300DA40BA009A407A105A0030A010".$DeviceCategory;
+ #$pdu = pack('H*', $pdu);
+ send_pdu($pdu);
+
+ # getSystemDataPosAck
+ $pdu = receive_stuff();
+ my $out = $CSTAapdu->decode($pdu);
+ my $crossRefID =
+ $out->{svcResult}->{result}->{serviceResult}->{extensions}
+ ->{privateData}[0]->{private}->{kmeSystemData}->{getSystemDataPosAck};
+ my $lastSegment = 0;
+
+ # systemDataLinkedReply
+ while ( !$lastSegment ) {
+ $pdu = receive_stuff();
+ my $out = $CSTAapdu->decode($pdu);
+ my $systemDataLinkedReply =
+ $out->{svcRequest}->{serviceArgs}->{privateData}->{private}
+ ->{kmeSystemData}->{systemDataLinkedReply};
+ if ( defined $systemDataLinkedReply ) {
+ if ( $systemDataLinkedReply->{crossRefID} cmp $crossRefID ) { next }
+ $lastSegment = $systemDataLinkedReply->{lastSegment};
+ foreach my $KmeDeviceStateEntry (
+ @{ $systemDataLinkedReply->{sysData}->{deviceList} } )
+ {
+ if ( $KmeDeviceStateEntry->{status} == 0 ) {
+ print "device:", $KmeDeviceStateEntry->{number}, "\n";
+ push @devices,
+ ( $KmeDeviceStateEntry->{device}->{deviceIdentifier}
+ ->{deviceNumber} );
+ }
+ }
+ }
+ }
+}
+
+sub SnapshotDeviceRequest {
+ my $device = shift;
+ my $pdu = $CSTAapdu->encode(
+ {
+ svcRequest => {
+ invokeID => 9,
+ serviceID => 74,
+ serviceArgs => {
+ snapshotObject =>
+ { deviceIdentifier => { deviceNumber => $device } }
+ }
+ }
+ }
+ );
+
+ #$device = sprintf("%08X",$device);
+ #print("SnapshotDeviceRequest: $device\n");
+ #my $pdu = "A11002010202014A300830068104".$device;
+ #$pdu = pack('H*', $pdu);
+ send_pdu($pdu);
+}
+
+sub SnapshotDeviceResult {
+ my $refSnapshotDeviceResult = shift;
+ my $refsnapshotData =
+ ( $refSnapshotDeviceResult->{crossRefIDorSnapshotData}->{snapshotData} );
+ foreach my $SnapshotDeviceResponseInfo ( @{$refsnapshotData} ) {
+ my $callID =
+ $SnapshotDeviceResponseInfo->{connectionIdentifier}->{both}->{callID};
+ my $deviceID = deviceNumber(
+ $SnapshotDeviceResponseInfo->{connectionIdentifier}->{both}
+ ->{deviceID}->{staticID}->{deviceIdentifier} );
+ foreach my $LocalConnectionState (
+ @{
+ $SnapshotDeviceResponseInfo->{localCallState}
+ ->{compoundCallState}
+ }
+ )
+ {
+ my $ConnectionState = localConnectionInfo($LocalConnectionState);
+ push @calls, [ $callID, $deviceID, $ConnectionState ];
+ }
+
+ }
+}
+
+sub SystemStatusResult {
+ my $invokeID = shift;
+ my $pdu = $CSTAapdu->encode(
+ {
+ svcResult => {
+ invokeID => $invokeID,
+ result => { serviceID => 211, serviceResult => { noData => 1 } }
+ }
+ }
+ );
+ send_pdu($pdu); # send SystemStatus Result
+}
+
+# parse ASN.1 desciptions
+my $asn = Convert::ASN1->new;
+
+#$asn->configure(tagdefault=>'EXPLICIT');
+$asn->prepare(<<ASN1) or die "prepare: ", $asn->error;
+CSTAapdu ::= CHOICE {
+ svcRequest ROIVapdu,
+ svcResult RORSapdu
+-- svcError ROERapdu,
+-- svcReject RORJapdu
+}
+ROIVapdu ::= [1] IMPLICIT SEQUENCE {
+ invokeID INTEGER,
+ serviceID INTEGER,
+ serviceArgs ANY DEFINED BY serviceID
+}
+RORSapdu ::= [2] IMPLICIT SEQUENCE {
+ invokeID INTEGER,
+ result SEQUENCE {
+ serviceID INTEGER,
+ serviceResult ANY DEFINED BY serviceID OPTIONAL
+ }
+}
+EscapeArgument ::= SEQUENCE
+{ --escapeRegisterID EscapeRegisterID OPTIONAL,
+ --security CSTASecurityData OPTIONAL,
+ privateData CSTAPrivateData }
+
+CSTAPrivateData ::= CHOICE
+{ string OCTET STRING,
+ private KmeSpecificPrivateData
+}
+KmeSpecificPrivateData ::= CHOICE
+{ kmeSystemData [4] KmeSystemData
+}
+KmeSystemData ::= CHOICE
+{ getSystemData [0] KmeGetSystemData,
+ systemDataLinkedReply [3] EXPLICIT KmeSystemDataLinkedReply,
+ getSystemDataPosAck [4] EXPLICIT KmeGetSystemDataPosAck
+}
+KmeGetSystemData ::= CHOICE
+{ request KmeGetSystemDataReq --!
+--result KmeGetSystemDataRsp
+}
+KmeGetSystemDataReq ::= CHOICE
+{
+deviceList [4] KmeRequestedDevice --!
+}
+KmeRequestedDevice ::= CHOICE -- for GetSystemData.deviceList
+{ --device [0] DeviceID,
+ category [1] KmeDeviceCategory} --!
+
+KmeDeviceCategory ::= CHOICE
+{ standardDevice [0] EXPLICIT DeviceCategory--!
+ -- kmeDevice [1] KmeOtherDevice
+}
+DeviceCategory ::= ENUMERATED
+{ acd (0),
+ group (1),
+ networkInterface (2), --!
+ park (3),
+ routeingDevice (4),
+ station (5), --!
+ voiceUnit (6),
+ other (7)
+}
+KmeSystemDataLinkedReply ::= SEQUENCE
+{ crossRefID [0] EXPLICIT ServiceCrossRefID,
+ segmentID [1] EXPLICIT INTEGER,
+ lastSegment [2] EXPLICIT BOOLEAN,
+ sysData [3] EXPLICIT KmeGetSystemDataRsp OPTIONAL
+}
+ServiceCrossRefID ::= OCTET STRING
+
+KmeGetSystemDataPosAck ::= ServiceCrossRefID
+
+KmeGetSystemDataRsp ::= SEQUENCE
+{ deviceList [38] EXPLICIT KmeDeviceStateList OPTIONAL
+}
+KmeDeviceStateList ::= SEQUENCE OF KmeDeviceStateEntry
+
+KmeDeviceStateEntry ::= SEQUENCE
+{ device DeviceID,
+ number IA5String OPTIONAL, -- Ext No, CO No, Park Area No.
+ status KmeDeviceState
+}
+KmeDeviceState ::= ENUMERATED
+{ ins (0),
+ ous (1)
+}
+EscapeResult ::= CHOICE
+{ extensions CSTACommonArguments,
+ noData NULL
+}
+CSTACommonArguments ::= [APPLICATION 30] IMPLICIT SEQUENCE
+{ privateData [1] IMPLICIT SEQUENCE OF CSTAPrivateData OPTIONAL }
+
+CSTAPrivateData ::= CHOICE
+{ string OCTET STRING,
+ private KmeSpecificPrivateData
+}
+
+--snapshotDevice OPERATION ::=
+--{ ARGUMENT SnapshotDeviceArgument,
+-- RESULT SnapshotDeviceResult
+-- ERRORS {universalFailure}
+-- CODE local: 74}
+
+SnapshotDeviceArgument ::= SEQUENCE
+{ snapshotObject DeviceID}
+
+SnapshotDeviceResult ::= SEQUENCE
+{ crossRefIDorSnapshotData
+ CHOICE
+ { serviceCrossRefID ServiceCrossRefID,
+ snapshotData SnapshotDeviceData
+ }
+}
+
+ServiceCrossRefID ::= OCTET STRING
+
+SnapshotDeviceData ::= [APPLICATION 22] IMPLICIT SEQUENCE OF SnapshotDeviceResponseInfo
+
+SnapshotDeviceResponseInfo ::= SEQUENCE
+{ connectionIdentifier ConnectionID,
+ localCallState CallState}
+
+ConnectionID ::= [APPLICATION 11] CHOICE
+{
+ deviceID [1] LocalDeviceID,
+ both SEQUENCE
+ { callID [0] IMPLICIT CallID,
+ deviceID [1] LocalDeviceID
+ }
+}
+
+CallID ::= OCTET STRING
+
+LocalDeviceID ::= CHOICE
+{ staticID DeviceID}
+
+DeviceID ::= SEQUENCE
+{ deviceIdentifier CHOICE
+ { dialingNumber [0] IMPLICIT NumberDigits,
+ deviceNumber [1] IMPLICIT DeviceNumber,
+ other [6] IMPLICIT OtherPlan
+ }
+}
+OtherPlan ::= OCTET STRING
+
+NumberDigits ::= IA5String
+
+DeviceNumber ::= INTEGER
+
+CallState ::= CHOICE
+{ compoundCallState [0] IMPLICIT CompoundCallState}
+
+CompoundCallState ::= SEQUENCE OF LocalConnectionState
+
+LocalConnectionState ::= [APPLICATION 14] IMPLICIT ENUMERATED
+{ null (0),
+ initiated (1),
+ alerting (2),
+ connected (3),
+ hold (4),
+ queued (5),
+ fail (6)
+}
+systemStatus ::= CHOICE
+{ ARGUMENT SystemStatusArg,
+ RESULT SystemStatusRes
+-- ERRORS {universalFailure}
+-- CODE local: 211
+}
+SystemStatusArg ::= SEQUENCE
+{ systemStatus SystemStatus}
+
+SystemStatusRes ::= CHOICE
+{ noData NULL}
+
+SystemStatus ::= ENUMERATED
+{ normal (2),
+ messageLost (3),
+ overloadReached (6)
+}
+ASN1
+my %serviceArgs = (
+ 51 => 'EscapeArgument',
+ 74 => 'SnapshotDeviceArgument',
+ 211 => 'SystemStatusArg'
+);
+foreach ( keys %serviceArgs ) {
+ $asn->registertype( 'serviceArgs', $_, $asn->find( $serviceArgs{$_} ) );
+}
+my %serviceResults = (
+ 51 => 'EscapeResult',
+ 74 => 'SnapshotDeviceResult',
+ 211 => 'SystemStatusRes'
+);
+foreach ( keys %serviceResults ) {
+ $asn->registertype( 'serviceResult', $_,
+ $asn->find( $serviceResults{$_} ) );
+}
+$CSTAapdu = $asn->find('CSTAapdu');
+csta_connect( { 'host' => '192.168.0.101', 'port' => 33333 } );
+GetSystemData(2);
+GetSystemData(5);
+my $maxCO = 0;
+while (1) {
+ foreach my $number (@devices) {
+ SnapshotDeviceRequest($number);
+ }
+ undef @calls;
+ my $alldevices = $#devices + 1;
+ while ($alldevices) {
+ my $pdu = receive_stuff();
+ my $out = $CSTAapdu->decode($pdu);
+ if ( defined $out->{svcRequest} ) {
+ my $serviceID = $out->{svcRequest}->{serviceID};
+ my $invokeID = $out->{svcRequest}->{invokeID};
+ if ( $serviceID == 211 ) { # if SystemStatus Request
+ SystemStatusResult($invokeID);
+ }
+ }
+ elsif ( defined $out->{svcResult} ) {
+ my $serviceResult = $out->{svcResult}->{result}->{serviceResult};
+ my $serviceID = $out->{svcResult}->{result}->{serviceID};
+ if ( $serviceID == 74 ) {
+ SnapshotDeviceResult($serviceResult);
+ $alldevices = $alldevices - 1;
+ }
+ }
+ }
+ my $CO = 0;
+ for (@calls) {
+ $CO++ if $_->[1] =~ /^CO/;
+ }
+ if ( $maxCO < $CO ) {
+ $maxCO = $CO;
+ print chr(7);
+ }
+ system('CLS'); # for windows, 'clear' for linux
+ print strftime( "%H:%M:%S ", localtime ), "maxCO:", $maxCO, " CO:", $CO,
+ "\n";
+ print "callID: deviceID: CallState:\n";
+ printf( "%-8s%-10s%-10s\n", $_->[0], $_->[1], $_->[2] )
+ for sort { $a->[0] cmp $b->[0] } @calls;
+ sleep 1;
+}