add WERR_INVALID_STATE
[wireshark-wip.git] / tools / extract_asn1_from_spec.pl
blob118c824f141fb6e038fcd84bf15a6c59970ad013
1 #!/usr/bin/perl
3 # This script extracts the ASN1 definition from and TS 36.331/36.355/25.331
4 # and generates asn files that can be processed by asn2wrs
5 # First download the specification from 3gpp.org as a word document and open it
6 # Then in "view" menu, select normal, draft or web layout (any kind that removes page header and footers)
7 # Finally save the document as a text file
8 # Example with TS 36.331: "perl extract_asn1_from_spec.pl 36331-xxx.txt"
9 # It should generate: EUTRA-RRC-Definitions.asn, EUTRA-UE-Variables.asn and EUTRA-InterNodeDefinitions
11 # Copyright 2011 Vincent Helfre and Erwan Yvin
13 # $Id$
15 # Wireshark - Network traffic analyzer
16 # By Gerald Combs <gerald@wireshark.org>
17 # Copyright 1998 Gerald Combs
19 # This program is free software; you can redistribute it and/or
20 # modify it under the terms of the GNU General Public License
21 # as published by the Free Software Foundation; either version 2
22 # of the License, or (at your option) any later version.
24 # This program is distributed in the hope that it will be useful,
25 # but WITHOUT ANY WARRANTY; without even the implied warranty of
26 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 # GNU General Public License for more details.
29 # You should have received a copy of the GNU General Public License
30 # along with this program; if not, write to the Free Software
31 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
33 use warnings;
34 $input_file = $ARGV[0];
35 $version = 0;
37 sub extract_spec_version;
38 sub extract_asn1;
40 open(INPUT_FILE, "< $input_file") or die "Can not open file $input_file";
42 extract_spec_version();
44 extract_asn1();
46 close(INPUT_FILE);
48 # This subroutine extracts the version of the specification
49 sub extract_spec_version {
50 my $line;
51 while($line = <INPUT_FILE>){
52 if($line =~ m/3GPP TS ((25|36)\.331|36\.355) V/){
53 $version = $line;
54 return;
59 # This subroutine copies the text delimited by -- ASN1START and -- ASN1STOP in INPUT_FILE
60 # and copies it into OUTPUT_FILE.
61 # The OUTPUT_FILE is opened on encounter of the keyword "DEFINITIONS AUTOMATIC TAGS"
62 # and closed on encounter of the keyword "END"
63 sub extract_asn1 {
64 my $line;
65 my $is_asn1 = 0;
66 my $output_file_name = 0;
67 my $file_name_found = 0;
69 while($line = <INPUT_FILE>){
70 if ($line =~ m/-- ASN1STOP/) {
71 $is_asn1 = 0;
74 if($line =~ m/– LPP-PDU-Definitions/){
75 $output_file_name = "LPP.asn";
76 print "generating $output_file_name\n";
77 open(OUTPUT_FILE, "> $output_file_name") or die "Can not open file $output_file_name";
78 syswrite OUTPUT_FILE,"-- $version-- \$Id\$\n--\n";
79 $file_name_found = 1;
82 if(($file_name_found == 0) && ($line =~ m/DEFINITIONS AUTOMATIC TAGS ::=/)){
83 ($output_file_name) = ($line =~ m/^([a-zA-Z\-]+)\s+DEFINITIONS AUTOMATIC TAGS ::=/);
84 $output_file_name = "$output_file_name".".asn";
85 print "generating $output_file_name\n";
86 open(OUTPUT_FILE, "> $output_file_name") or die "Can not open file $output_file_name";
87 syswrite OUTPUT_FILE,"-- $version-- \$Id\$\n--\n";
88 $is_asn1 = 1;
89 $file_name_found = 1;
92 if (($line =~ /END/) && (defined fileno OUTPUT_FILE)){
93 syswrite OUTPUT_FILE,"$line";
94 close(OUTPUT_FILE);
95 $is_asn1 = 0;
96 $file_name_found = 0;
99 if (($is_asn1 == 1) && (defined fileno OUTPUT_FILE)){
100 syswrite OUTPUT_FILE,"$line";
103 if ($line =~ m/-- ASN1START/) {
104 $is_asn1 = 1;