Jump to content
Калькуляторы

Как распарсить CSTA ASN.1? perl

Здравствуйте. Пишу скриптик декодирующий сообщения от АТС.

Попался мне участок одного сообщение которое никак не хочет распарсиваться.

   use strict;
   use warnings;
   use diagnostics;
   use Convert::ASN1;
   use Data::Dumper;
   my $pdu ="A1 40 30 27 A0 1B 6B 19 30 17 80 04 30 30 38 41 A1 0F 30 0D
      80 0B 38 39 35 31 39 39 39 39 39 39 39 A3 08 30 06 81 04 01
      31 00 11 30 15 A0 13 6B 11 30 0F 80 04 30 30 38 41 A1 07 30
      05 80 03 31 32 36";
   $pdu =~s/\s//g; # убираем пробелы
   $pdu =pack ("H*", $pdu); # превращаем строку в бинарник
   Convert::ASN1::asn_dump($pdu);
   # parse ASN.1 desciptions
   my $asn = Convert::ASN1->new;
   $asn->prepare(<<ASN1) or die "prepare: ", $asn->error;

   TransferredEvent ::= SEQUENCE
   {
--  primaryOldCall          ConnectionID,
   --  secondaryOldCall        [0] IMPLICIT ConnectionID               OPTIONAL,
   --  transferringDevice      SubjectDeviceID,
   --  transferredToDevice     SubjectDeviceID,
       transferredConnections  [1] IMPLICIT ConnectionList
   --  localConnectionInfo     LocalConnectionState                    OPTIONAL,
   --  correlatorData          [2] IMPLICIT CorrelatorData             OPTIONAL,
   --  userData                UserData                                OPTIONAL,
   --  chargingInfo            [3] IMPLICIT ChargingInfo               OPTIONAL,
   --  cause                   EventCause
   --  servicesPermitted       [4] IMPLICIT ServicesPermitted          OPTIONAL,
   --  mediaCallCharacteristics [5] IMPLICIT MediaCallCharacteristics  OPTIONAL,
   --  callCharacteristics     [6] IMPLICIT CallCharacteristics        OPTIONAL,
   --  callLinkageDataList     [7] IMPLICIT CallLinkageDataList        OPTIONAL,
   --  extensions              CSTACommonArguments                     OPTIONAL
   }
   ConnectionID ::= [APPLICATION 11] CHOICE
   {       callID          [0] IMPLICIT CallID,
           deviceID        [1]     LocalDeviceID,
           both    SEQUENCE
           {       callID  [0] IMPLICIT CallID,
                   deviceID [1] LocalDeviceID
           }
   }

   CallID ::= OCTET STRING 

LocalDeviceID ::= CHOICE
   {   staticID        DeviceID,
       dynamicID       [3] IMPLICIT   OCTET STRING
   }
   DeviceID ::= SEQUENCE
   {       deviceIdentifier                CHOICE
           {       dialingNumber           [0] IMPLICIT    NumberDigits,
                   deviceNumber            [1] IMPLICIT    DeviceNumber
   --              implicitPublic          [2] IMPLICIT    NumberDigits,
   --              explicitPublic          [3]     PublicTON,
   --              implicitPrivate         [4] IMPLICIT    NumberDigits,
   --              explicitPrivate         [5]     PrivateTON,
   --              other                           [6] IMPLICIT    OtherPlan
           }
   }

   NumberDigits    ::= IA5String

   DeviceNumber    ::= INTEGER

   SubjectDeviceID ::= [APPLICATION 3] CHOICE
           {deviceIdentifier               DeviceID,
            notKnown               [7] IMPLICIT            NULL}

   ConnectionList ::= SEQUENCE OF SEQUENCE
           {       newConnection [0] ConnectionID                  OPTIONAL,
   --              oldConnection [1] ConnectionID                  OPTIONAL,
   --      		endpoint [2] CHOICE
   --              {       deviceID        DeviceID,
   --                      notKnown        NULL}    OPTIONAL,
                   associatedNID [3] CHOICE
				{       deviceID        DeviceID,
						notKnown        NULL}      -- должно быть OPTIONAL, но компилятору не нра
   --              resultingConnectionInfo ConnectionInformation OPTIONAL
           }

ASN1
   my $obj = $asn->find('TransferredEvent');
   my $out = $obj->decode($pdu) or die $asn->error;
$Data::Dumper::Indent=1;
$Data::Dumper::Pair=' ';
$Data::Dumper::Quotekeys=0;
   print Dumper($out);   

грамматика взята из Ecma-285.asn

должно получиться вот это:

                   transferredConnections[0] {
                     newConnection {
                        both {
                           callID = 30303841
                           deviceID {
                              staticID {
                                 deviceIdentifier {
                                    dialingNumber = 89519999999
                                 }
                              }
                           }
                        }
                     }
                     associatedNID {
                        deviceID {
                           deviceIdentifier {
                              deviceNumber = 19988497
                           }
                        }
                     }
                  }
                  transferredConnections[1] {
                     newConnection {
                        both {
                           callID = 30303841
                           deviceID {
                              staticID {
                                 deviceIdentifier {
                                    dialingNumber = 126
                                 }
                              }
                           }
                        }
                     }
                  }

Помогите, кто разбирается.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.