3 # This script extracts the ASN1 definition from and TS 36.331/36.355/25.331/38.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 # SPDX-License-Identifier: GPL-2.0-or-later
20 $input_file = $ARGV[0];
23 sub extract_spec_version;
26 open(INPUT_FILE, "< $input_file") or die "Can not open file $input_file";
28 extract_spec_version();
34 # This subroutine extracts the version of the specification
35 sub extract_spec_version {
37 while($line = <INPUT_FILE>){
38 if($line =~ m/3GPP TS ((25|36|38)\.331|36\.355) V/){
45 # This subroutine copies the text delimited by -- ASN1START and -- ASN1STOP in INPUT_FILE
46 # and copies it into OUTPUT_FILE.
47 # The OUTPUT_FILE is opened on encounter of the keyword "DEFINITIONS AUTOMATIC TAGS"
48 # and closed on encounter of the keyword "END"
52 my $output_file_name = 0;
53 my $file_name_found = 0;
55 while($line = <INPUT_FILE>){
56 if ($line =~ m/-- ASN1STOP/) {
60 if($line =~ m/ LPP-PDU-Definitions/){
61 $output_file_name = "LPP.asn";
62 print "generating $output_file_name\n";
63 open(OUTPUT_FILE, "> $output_file_name") or die "Can not open file $output_file_name";
67 if(($file_name_found == 0) && ($line =~ m/DEFINITIONS AUTOMATIC TAGS ::=/)){
68 ($output_file_name) = ($line =~ m/^([a-zA-Z0-9\-]+)\s+DEFINITIONS AUTOMATIC TAGS ::=/);
69 $output_file_name = "$output_file_name".".asn";
70 print "generating $output_file_name\n";
71 open(OUTPUT_FILE, "> $output_file_name") or die "Can not open file $output_file_name";
76 if (($line =~ /^END/) && (defined fileno OUTPUT_FILE)){
77 syswrite OUTPUT_FILE,"$line";
83 if (($is_asn1 == 1) && (defined fileno OUTPUT_FILE)){
84 syswrite OUTPUT_FILE,"$line";
87 if ($line =~ m/-- ASN1START/) {