Revert "drsuapi_dissect_element_DsGetNCChangesCtr6TS_ctr6 dissect_krb5_PAC_NDRHEADERBLOB"
[wireshark-sm.git] / tools / extract_asn1_from_spec.pl
blobf542632c58e321d786dff3553e0b6f8ce4ecda0b
1 #!/usr/bin/perl
3 # This script extracts the ASN1 definition from TS 36.331/36.355/25.331/38.331/37.355/36.413/38.413/36.423/38.423
4 # /38.463/38.473 , 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
19 use warnings;
20 $input_file = $ARGV[0];
21 $version = 0;
23 sub extract_spec_version;
24 sub extract_asn1;
26 open(INPUT_FILE, "< $input_file") or die "Can not open file $input_file";
28 extract_spec_version();
30 extract_asn1();
32 close(INPUT_FILE);
34 # This subroutine extracts the version of the specification
35 sub extract_spec_version {
36 my $line;
37 while($line = <INPUT_FILE>){
38 if($line =~ m/3GPP TS ((25|36|38)\.331|(36|37)\.355|(36|38)\.413|(36|38)\.423|36\.(443|444)|(36|38)\.455|38\.463|38\.473|37\.483) V/){
39 $version = $line;
40 return;
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"
49 sub extract_asn1 {
50 my $line;
51 my $prev_line;
52 my $is_asn1 = 0;
53 my $output_file_name = 0;
54 my $file_name_found = 0;
56 while($line = <INPUT_FILE>){
57 if ($line =~ m/-- ASN1STOP/) {
58 $is_asn1 = 0;
61 if(($file_name_found == 0) && ($line =~ m/^LPP-PDU-Definitions/)){
62 $output_file_name = "LPP-PDU-Definitions.asn";
63 print "generating $output_file_name\n";
64 open(OUTPUT_FILE, "> $output_file_name") or die "Can not open file $output_file_name";
65 $file_name_found = 1;
66 syswrite OUTPUT_FILE,"-- "."$version"."\n";
69 if(($file_name_found == 0) && ($line =~ m/^LPP-Broadcast-Definitions/)){
70 $output_file_name = "LPP-Broadcast-Definitions.asn";
71 print "generating $output_file_name\n";
72 open(OUTPUT_FILE, "> $output_file_name") or die "Can not open file $output_file_name";
73 $file_name_found = 1;
74 syswrite OUTPUT_FILE,"-- "."$version"."\n";
77 if(($file_name_found == 0) && ($line =~ m/SonTransfer-IEs/)){
78 $output_file_name = "S1AP-SonTransfer-IEs.asn";
79 print "generating $output_file_name\n";
80 open(OUTPUT_FILE, "> $output_file_name") or die "Can not open file $output_file_name";
81 $is_asn1 = 1;
82 $file_name_found = 1;
83 syswrite OUTPUT_FILE,"-- "."$version"."\n";
86 if(($file_name_found == 0) && ($line =~ m/itu-t \(0\) identified-organization \(4\) etsi \(0\) mobileDomain \(0\)/)){
87 ($output_file_name) = ($prev_line =~ m/^([a-zA-Z0-9\-]+)\s/);
88 $output_file_name = "$output_file_name".".asn";
89 print "generating $output_file_name\n";
90 open(OUTPUT_FILE, "> $output_file_name") or die "Can not open file $output_file_name";
91 $is_asn1 = 1;
92 $file_name_found = 1;
93 syswrite OUTPUT_FILE,"-- "."$version"."\n";
94 syswrite OUTPUT_FILE,"$prev_line";
97 if(($file_name_found == 0) && ($line =~ m/DEFINITIONS AUTOMATIC TAGS ::=/)){
98 ($output_file_name) = ($line =~ m/^([a-zA-Z0-9\-]+)\s+DEFINITIONS AUTOMATIC TAGS ::=/);
99 $output_file_name = "$output_file_name".".asn";
100 print "generating $output_file_name\n";
101 open(OUTPUT_FILE, "> $output_file_name") or die "Can not open file $output_file_name";
102 $is_asn1 = 1;
103 $file_name_found = 1;
104 syswrite OUTPUT_FILE,"-- "."$version"."\n";
107 if (($line =~ /^END[\r\n]/) && (defined fileno OUTPUT_FILE)){
108 syswrite OUTPUT_FILE,"$line";
109 close(OUTPUT_FILE);
110 $is_asn1 = 0;
111 $file_name_found = 0;
114 if (($is_asn1 == 1) && (defined fileno OUTPUT_FILE)){
115 syswrite OUTPUT_FILE,"$line";
118 if ($line =~ m/-- ASN1START/) {
119 $is_asn1 = 1;
122 $prev_line = $line;