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 # Wireshark - Network traffic analyzer
14 # By Gerald Combs <gerald@wireshark.org>
15 # Copyright 1998 Gerald Combs
17 # This program is free software; you can redistribute it and/or
18 # modify it under the terms of the GNU General Public License
19 # as published by the Free Software Foundation; either version 2
20 # of the License, or (at your option) any later version.
22 # This program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU General Public License for more details.
27 # You should have received a copy of the GNU General Public License
28 # along with this program; if not, write to the Free Software
29 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 $input_file = $ARGV[0];
35 sub extract_spec_version;
38 open(INPUT_FILE, "< $input_file") or die "Can not open file $input_file";
40 extract_spec_version();
46 # This subroutine extracts the version of the specification
47 sub extract_spec_version {
49 while($line = <INPUT_FILE>){
50 if($line =~ m/3GPP TS ((25|36)\.331|36\.355) V/){
57 # This subroutine copies the text delimited by -- ASN1START and -- ASN1STOP in INPUT_FILE
58 # and copies it into OUTPUT_FILE.
59 # The OUTPUT_FILE is opened on encounter of the keyword "DEFINITIONS AUTOMATIC TAGS"
60 # and closed on encounter of the keyword "END"
64 my $output_file_name = 0;
65 my $file_name_found = 0;
67 while($line = <INPUT_FILE>){
68 if ($line =~ m/-- ASN1STOP/) {
72 if($line =~ m/
\96 LPP-PDU-Definitions/){
73 $output_file_name = "LPP.asn";
74 print "generating $output_file_name\n";
75 open(OUTPUT_FILE, "> $output_file_name") or die "Can not open file $output_file_name";
79 if(($file_name_found == 0) && ($line =~ m/DEFINITIONS AUTOMATIC TAGS ::=/)){
80 ($output_file_name) = ($line =~ m/^([a-zA-Z0-9\-]+)\s+DEFINITIONS AUTOMATIC TAGS ::=/);
81 $output_file_name = "$output_file_name".".asn";
82 print "generating $output_file_name\n";
83 open(OUTPUT_FILE, "> $output_file_name") or die "Can not open file $output_file_name";
88 if (($line =~ /END/) && (defined fileno OUTPUT_FILE)){
89 syswrite OUTPUT_FILE,"$line";
95 if (($is_asn1 == 1) && (defined fileno OUTPUT_FILE)){
96 syswrite OUTPUT_FILE,"$line";
99 if ($line =~ m/-- ASN1START/) {