2009-01-07 19:57:51 +00:00
|
|
|
#!/usr/bin/perl
|
2013-07-29 20:24:02 +00:00
|
|
|
#
|
2020-09-25 05:14:11 +00:00
|
|
|
# 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
|
2020-09-24 09:18:13 +00:00
|
|
|
# /38.463/38.473 , and generates asn files that can be processed by asn2wrs
|
2009-01-07 19:57:51 +00:00
|
|
|
# First download the specification from 3gpp.org as a word document and open it
|
2011-04-04 14:35:21 +00:00
|
|
|
# Then in "view" menu, select normal, draft or web layout (any kind that removes page header and footers)
|
2009-01-07 19:57:51 +00:00
|
|
|
# Finally save the document as a text file
|
2011-04-04 14:35:21 +00:00
|
|
|
# Example with TS 36.331: "perl extract_asn1_from_spec.pl 36331-xxx.txt"
|
2009-01-07 19:57:51 +00:00
|
|
|
# It should generate: EUTRA-RRC-Definitions.asn, EUTRA-UE-Variables.asn and EUTRA-InterNodeDefinitions
|
2013-07-29 20:24:02 +00:00
|
|
|
#
|
|
|
|
# Copyright 2011 Vincent Helfre and Erwan Yvin
|
|
|
|
#
|
|
|
|
# Wireshark - Network traffic analyzer
|
|
|
|
# By Gerald Combs <gerald@wireshark.org>
|
|
|
|
# Copyright 1998 Gerald Combs
|
|
|
|
#
|
2018-03-06 14:31:02 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
2013-07-29 20:24:02 +00:00
|
|
|
|
2009-01-07 19:57:51 +00:00
|
|
|
use warnings;
|
|
|
|
$input_file = $ARGV[0];
|
2011-04-04 14:35:21 +00:00
|
|
|
$version = 0;
|
2009-01-07 19:57:51 +00:00
|
|
|
|
2011-04-04 14:35:21 +00:00
|
|
|
sub extract_spec_version;
|
2009-01-07 19:57:51 +00:00
|
|
|
sub extract_asn1;
|
|
|
|
|
|
|
|
open(INPUT_FILE, "< $input_file") or die "Can not open file $input_file";
|
|
|
|
|
2011-04-04 14:35:21 +00:00
|
|
|
extract_spec_version();
|
2009-01-07 19:57:51 +00:00
|
|
|
|
2011-04-04 14:35:21 +00:00
|
|
|
extract_asn1();
|
2009-01-07 19:57:51 +00:00
|
|
|
|
2011-04-04 14:35:21 +00:00
|
|
|
close(INPUT_FILE);
|
2009-01-07 19:57:51 +00:00
|
|
|
|
2011-04-04 14:35:21 +00:00
|
|
|
# This subroutine extracts the version of the specification
|
|
|
|
sub extract_spec_version {
|
|
|
|
my $line;
|
|
|
|
while($line = <INPUT_FILE>){
|
2023-01-11 11:52:23 +00:00
|
|
|
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/){
|
2011-04-04 14:35:21 +00:00
|
|
|
$version = $line;
|
|
|
|
return;
|
|
|
|
}
|
2009-01-07 19:57:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# This subroutine copies the text delimited by -- ASN1START and -- ASN1STOP in INPUT_FILE
|
|
|
|
# and copies it into OUTPUT_FILE.
|
2011-04-04 14:35:21 +00:00
|
|
|
# The OUTPUT_FILE is opened on encounter of the keyword "DEFINITIONS AUTOMATIC TAGS"
|
|
|
|
# and closed on encounter of the keyword "END"
|
2009-01-07 19:57:51 +00:00
|
|
|
sub extract_asn1 {
|
2011-04-04 14:35:21 +00:00
|
|
|
my $line;
|
2020-09-24 06:19:04 +00:00
|
|
|
my $prev_line;
|
2009-01-07 19:57:51 +00:00
|
|
|
my $is_asn1 = 0;
|
2011-04-04 14:35:21 +00:00
|
|
|
my $output_file_name = 0;
|
2013-01-11 19:31:15 +00:00
|
|
|
my $file_name_found = 0;
|
2009-01-07 19:57:51 +00:00
|
|
|
|
2011-04-04 14:35:21 +00:00
|
|
|
while($line = <INPUT_FILE>){
|
2009-01-07 19:57:51 +00:00
|
|
|
if ($line =~ m/-- ASN1STOP/) {
|
|
|
|
$is_asn1 = 0;
|
|
|
|
}
|
2011-04-04 14:35:21 +00:00
|
|
|
|
2022-04-19 07:56:49 +00:00
|
|
|
if(($file_name_found == 0) && ($line =~ m/^LPP-PDU-Definitions/)){
|
|
|
|
$output_file_name = "LPP-PDU-Definitions.asn";
|
|
|
|
print "generating $output_file_name\n";
|
|
|
|
open(OUTPUT_FILE, "> $output_file_name") or die "Can not open file $output_file_name";
|
|
|
|
$file_name_found = 1;
|
|
|
|
syswrite OUTPUT_FILE,"-- "."$version"."\n";
|
|
|
|
}
|
|
|
|
|
2021-01-07 10:52:17 +00:00
|
|
|
if(($file_name_found == 0) && ($line =~ m/^LPP-Broadcast-Definitions/)){
|
|
|
|
$output_file_name = "LPP-Broadcast-Definitions.asn";
|
2013-01-11 19:31:15 +00:00
|
|
|
print "generating $output_file_name\n";
|
|
|
|
open(OUTPUT_FILE, "> $output_file_name") or die "Can not open file $output_file_name";
|
|
|
|
$file_name_found = 1;
|
2020-09-27 06:18:51 +00:00
|
|
|
syswrite OUTPUT_FILE,"-- "."$version"."\n";
|
2013-01-11 19:31:15 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 05:14:11 +00:00
|
|
|
if(($file_name_found == 0) && ($line =~ m/SonTransfer-IEs/)){
|
|
|
|
$output_file_name = "S1AP-SonTransfer-IEs.asn";
|
|
|
|
print "generating $output_file_name\n";
|
|
|
|
open(OUTPUT_FILE, "> $output_file_name") or die "Can not open file $output_file_name";
|
|
|
|
$is_asn1 = 1;
|
|
|
|
$file_name_found = 1;
|
2020-09-27 06:18:51 +00:00
|
|
|
syswrite OUTPUT_FILE,"-- "."$version"."\n";
|
2020-09-25 05:14:11 +00:00
|
|
|
}
|
|
|
|
|
2020-09-24 06:19:04 +00:00
|
|
|
if(($file_name_found == 0) && ($line =~ m/itu-t \(0\) identified-organization \(4\) etsi \(0\) mobileDomain \(0\)/)){
|
|
|
|
($output_file_name) = ($prev_line =~ m/^([a-zA-Z0-9\-]+)\s/);
|
|
|
|
$output_file_name = "$output_file_name".".asn";
|
|
|
|
print "generating $output_file_name\n";
|
|
|
|
open(OUTPUT_FILE, "> $output_file_name") or die "Can not open file $output_file_name";
|
|
|
|
$is_asn1 = 1;
|
|
|
|
$file_name_found = 1;
|
2020-09-27 06:18:51 +00:00
|
|
|
syswrite OUTPUT_FILE,"-- "."$version"."\n";
|
2020-09-24 06:19:04 +00:00
|
|
|
syswrite OUTPUT_FILE,"$prev_line";
|
|
|
|
}
|
|
|
|
|
2013-01-11 19:31:15 +00:00
|
|
|
if(($file_name_found == 0) && ($line =~ m/DEFINITIONS AUTOMATIC TAGS ::=/)){
|
2015-03-31 20:05:43 +00:00
|
|
|
($output_file_name) = ($line =~ m/^([a-zA-Z0-9\-]+)\s+DEFINITIONS AUTOMATIC TAGS ::=/);
|
2011-04-04 14:35:21 +00:00
|
|
|
$output_file_name = "$output_file_name".".asn";
|
|
|
|
print "generating $output_file_name\n";
|
|
|
|
open(OUTPUT_FILE, "> $output_file_name") or die "Can not open file $output_file_name";
|
|
|
|
$is_asn1 = 1;
|
2013-01-11 19:31:15 +00:00
|
|
|
$file_name_found = 1;
|
2020-09-27 06:18:51 +00:00
|
|
|
syswrite OUTPUT_FILE,"-- "."$version"."\n";
|
2011-04-04 14:35:21 +00:00
|
|
|
}
|
|
|
|
|
2020-12-15 21:00:49 +00:00
|
|
|
if (($line =~ /^END[\r\n]/) && (defined fileno OUTPUT_FILE)){
|
2011-04-04 14:35:21 +00:00
|
|
|
syswrite OUTPUT_FILE,"$line";
|
|
|
|
close(OUTPUT_FILE);
|
|
|
|
$is_asn1 = 0;
|
2013-01-11 19:31:15 +00:00
|
|
|
$file_name_found = 0;
|
2011-04-04 14:35:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (($is_asn1 == 1) && (defined fileno OUTPUT_FILE)){
|
2009-01-07 19:57:51 +00:00
|
|
|
syswrite OUTPUT_FILE,"$line";
|
|
|
|
}
|
2013-01-11 19:31:15 +00:00
|
|
|
|
2009-01-07 19:57:51 +00:00
|
|
|
if ($line =~ m/-- ASN1START/) {
|
|
|
|
$is_asn1 = 1;
|
|
|
|
}
|
2020-09-24 06:19:04 +00:00
|
|
|
|
|
|
|
$prev_line = $line;
|
2009-01-07 19:57:51 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-04 14:35:21 +00:00
|
|
|
|