Merge remote-tracking branch 'origin/use-asn1c-mouse' into integration_2023_w22

This commit is contained in:
Robert Schmidt
2023-06-02 17:29:16 +02:00
53 changed files with 1154 additions and 2928 deletions
+21 -3
View File
@@ -46,6 +46,24 @@ include_directories(${CONFIG_INCLUDE_DIRS})
pkg_search_module(CRYPTO libcrypto REQUIRED)
include_directories(${CRYPTO_INCLUDE_DIRS})
# Check if asn1c is installed, and check if it supports all options we need
# a user can provide ASN1C_EXEC to override an asn1c to use (e.g., parallel
# installation)
find_program(ASN1C_EXEC_PATH asn1c HINTS /opt/asn1c/bin)
set(ASN1C_EXEC ${ASN1C_EXEC_PATH} CACHE FILEPATH "path to asn1c executable")
if(NOT ASN1C_EXEC)
message(FATAL_ERROR "No asn1c found!
You might want to re-run ./build_oai -I
Or provide a path to asn1c using
./build_oai ... --cmake-opt -DASN1C_EXEC=/path/to/asn1c
")
endif()
check_option(${ASN1C_EXEC} -gen-APER ASN1C_EXEC)
check_option(${ASN1C_EXEC} -no-gen-UPER ASN1C_EXEC)
check_option(${ASN1C_EXEC} -no-gen-JER ASN1C_EXEC)
check_option(${ASN1C_EXEC} -no-gen-BER ASN1C_EXEC)
check_option(${ASN1C_EXEC} -no-gen-OER ASN1C_EXEC)
#uhd 4.0 and iris installs by default in /usr/local
include_directories("/usr/local/include/")
#use native cmake method as this package is not in pkg-config
@@ -307,6 +325,9 @@ if (DEBUG_ASN1C)
add_definitions(-DHAVE_CONFIG_H)
endif()
# asn1c skeletons need this
add_definitions(-DHAVE_NETINET_IN_H)
##################################################
# ASN.1 grammar C code generation & dependencies #
##################################################
@@ -2088,9 +2109,6 @@ add_custom_target (
DEPENDS ${OPENAIR_DIR}/common/utils/T/T_IDs.h
)
# Hack on a test of asn1c version (already dirty)
add_definitions(-DASN1_MINIMUM_VERSION=924)
#################################
# add executables for operation
#################################
+1 -1
View File
@@ -35,7 +35,7 @@
<mode>TesteNB</mode>
<class>Build_eNB</class>
<desc>Build gNB (USRP)</desc>
<Build_eNB_args>--gNB -w USRP --ninja -c -P --build-lib "ldpc_cuda ldpc_t1"</Build_eNB_args>
<Build_eNB_args>--gNB -w USRP --ninja -c -P --build-lib "ldpc_cuda ldpc_t1" --cmake-opt -DASN1C_EXEC=/opt/asn1c/bin/asn1c</Build_eNB_args>
<forced_workspace_cleanup>True</forced_workspace_cleanup>
</testCase>
+18
View File
@@ -89,3 +89,21 @@ macro(eval_boolean VARIABLE)
set(${VARIABLE} OFF)
endif()
endmacro()
function(check_option EXEC TEST_OPTION EXEC_HINT)
message(STATUS "Check if ${EXEC} supports ${TEST_OPTION}")
execute_process(COMMAND ${EXEC} ${TEST_OPTION}
RESULT_VARIABLE CHECK_STATUS
OUTPUT_VARIABLE CHECK_OUTPUT
ERROR_VARIABLE CHECK_OUTPUT)
if(NOT ${CHECK_STATUS} EQUAL 1)
get_filename_component(EXEC_FILE ${EXEC} NAME)
message(FATAL_ERROR "Error message: ${CHECK_OUTPUT}\
You might want to re-run ./build_oai -I
Or provide a path to ${EXEC_FILE} using
./build_oai ... --cmake-opt -D${EXEC_HINT}=/path/to/${EXEC_FILE}
or directly with
cmake .. -D${EXEC_HINT}=/path/to/${EXEC_FILE}
")
endif()
endfunction()
+5 -6
View File
@@ -674,19 +674,18 @@ check_install_oai_software() {
}
install_asn1c_from_source(){
mkdir -p $OPENAIR_DIR/cmake_targets/log
asn1_install_log=$OPENAIR_DIR/cmake_targets/log/asn1c_install_log.txt
echo_info "\nInstalling ASN1. The log file for ASN1 installation is here: $asn1_install_log "
(
$SUDO $INSTALLER -y install bison flex
$SUDO rm -rf /tmp/asn1c
# GIT_SSL_NO_VERIFY=true git clone https://gitlab.eurecom.fr/oai/asn1c.git /tmp/asn1c
git clone https://gitlab.eurecom.fr/oai/asn1c.git /tmp/asn1c
git clone https://github.com/mouse07410/asn1c /tmp/asn1c
cd /tmp/asn1c
# better to use a given commit than a branch in case the branch
# is updated and requires modifications in the source of OAI
#git checkout velichkov_s1ap_plus_option_group
git checkout f12568d617dbf48497588f8e227d70388fa217c9
git checkout vlm_master
autoreconf -iv
./configure
./configure --prefix /opt/asn1c/
make -j`nproc`
$SUDO make install
cd -
+52 -20
View File
@@ -12,6 +12,8 @@
</tr>
</table>
[[_TOC_]]
This page is valid on tags starting from **`2019.w09`**.
# Overview
@@ -72,31 +74,35 @@ cd openairinterface5g/cmake_targets/
Note the section on installing UHD further down for more information.
## Building PHY Simulators
## Installing (new) asn1c from source
The PHY layer simulators (LTE and NR) can be built as follows:
With tag 2023.w22, we switch from our [own
`asn1c`](https://gitlab.eurecom.fr/oai/asn1c.git) to a [community-maintained
`asn1c`](https://github.com/mouse07410/asn1c). This new version has many
bugfixes, but is incompatible with the previous version. To ease the
transition, both versions can be installed in parallel. Assuming you installed
`asn1c` using `build_oai`, tags before 2023.w22 will use the version under
`/usr/local/`; tag 2023.w22 and newer will use the version under `/opt/asn1c/`
(if present) or any system directory (e.g., also `/usr/local/`), and
additionally check that all command line options of the new `asn1c` are
supported.
```bash
cd openairinterface5g/cmake_targets/
./build_oai --phy_simulators
To install the new `asn1c`, either run `build_oai -I`. To not re-install all
packages, you can also just install `asn1c` like this:
```
cd openairinterface5g
sudo ls # open sudo session, required by install_asn1c_from_source
. oaienv # read of default variables
. cmake_targets/tools/build_helper # read in function
install_asn1c_from_source # install under `/opt/asn1c`
```
After completing the build, the binaries are available in the `cmake_targets/ran_build/build` directory.
Detailed information about these simulators can be found [in this dedicated page](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/OpenAirLTEPhySimul)
# Building UEs, eNodeB and gNodeB Executables
After downloading the source files, a single build command can be used to get the binaries supporting all the oai softmodem use cases (UE and [eg]NodeB):
```bash
cd openairinterface5g/cmake_targets/
./build_oai -w USRP --eNB --UE --nrUE --gNB
Additionally, you can also point to a specific `asn1c` to use if you chose to
install elsewhere, using one of these two methods:
```
./build_oai --ninja <other-options> --cmake-opt -DASN1C_EXEC=/opt/asn1c/bin/asn1c
cmake .. -GNinja -DASN1C_EXEC=/opt/asn1c/bin/asn1c
```
You can build any oai softmodem executable separately, you may not need all of them depending on your oai usage.
After completing the build, the binaries are available in the `cmake_targets/ran_build/build` directory.
## Installing UHD from source
@@ -130,6 +136,32 @@ See:
* `cmake_targets/tools/uhd-4.x-tdd-patch.diff`
* `cmake_targets/tools/build_helper` --> function `install_usrp_uhd_driver_from_source`
## Building PHY Simulators
The PHY layer simulators (LTE and NR) can be built as follows:
```bash
cd openairinterface5g/cmake_targets/
./build_oai --phy_simulators
```
After completing the build, the binaries are available in the `cmake_targets/ran_build/build` directory.
Detailed information about these simulators can be found [in this dedicated page](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/OpenAirLTEPhySimul)
## Building UEs, eNodeB and gNodeB Executables
After downloading the source files, a single build command can be used to get the binaries supporting all the oai softmodem use cases (UE and [eg]NodeB):
```bash
cd openairinterface5g/cmake_targets/
./build_oai -w USRP --eNB --UE --nrUE --gNB
```
You can build any oai softmodem executable separately, you may not need all of them depending on your oai usage.
After completing the build, the binaries are available in the `cmake_targets/ran_build/build` directory.
## Building Optional Binaries
There are a number of optional libraries that can be built in support of the
@@ -1,25 +1,53 @@
set(E1AP_GRAMMAR ASN.1/38463-g80.R16.78.0.asn)
set(e1ap_source
ANY_aper.c
ANY.c
ANY_uper.c
ANY_xer.c
aper_decoder.c
aper_encoder.c
aper_opentype.c
aper_support.c
asn_application.c
asn_bit_data.c
asn_codecs_prim.c
asn_codecs_prim_xer.c
asn_internal.c
asn_random_fill.c
asn_SEQUENCE_OF.c
asn_SET_OF.c
ber_decoder.c
ber_tlv_length.c
ber_tlv_tag.c
BIT_STRING.c
BIT_STRING_print.c
BIT_STRING_rfill.c
BIT_STRING_uper.c
BIT_STRING_xer.c
constraints.c
constr_CHOICE_aper.c
constr_CHOICE.c
constr_CHOICE_print.c
constr_CHOICE_rfill.c
constr_CHOICE_uper.c
constr_CHOICE_xer.c
constr_SEQUENCE_aper.c
constr_SEQUENCE.c
constr_SEQUENCE_OF_aper.c
constr_SEQUENCE_OF.c
constr_SEQUENCE_OF_uper.c
constr_SEQUENCE_OF_xer.c
constr_SEQUENCE_print.c
constr_SEQUENCE_rfill.c
constr_SEQUENCE_uper.c
constr_SEQUENCE_xer.c
constr_SET_OF_aper.c
constr_SET_OF.c
constr_SET_OF_print.c
constr_SET_OF_rfill.c
constr_SET_OF_uper.c
constr_SET_OF_xer.c
constr_TYPE.c
der_encoder.c
E1AP_ActivityInformation.c
E1AP_ActivityNotificationLevel.c
E1AP_AdditionalHandoverInfo.c
@@ -182,6 +210,7 @@ set(e1ap_source
E1AP_Extended-NR-CGI-Support-List.c
E1AP_ExtendedPacketDelayBudget.c
E1AP_ExtendedSliceSupportList.c
E1AP_EXTERNAL.c
E1AP_FirstDLCount.c
E1AP_GBR-QoSFlowInformation.c
E1AP_GBR-QosInformation.c
@@ -450,18 +479,50 @@ set(e1ap_source
E1AP_UPSecuritykey.c
E1AP_UP-TNL-Information.c
E1AP_URIaddress.c
GraphicString.c
INTEGER_aper.c
INTEGER.c
INTEGER_print.c
INTEGER_rfill.c
INTEGER_uper.c
INTEGER_xer.c
NativeEnumerated_aper.c
NativeEnumerated.c
NativeEnumerated_uper.c
NativeEnumerated_xer.c
NativeInteger_aper.c
NativeInteger.c
NativeInteger_print.c
NativeInteger_rfill.c
NativeInteger_uper.c
NativeInteger_xer.c
ObjectDescriptor.c
OBJECT_IDENTIFIER.c
OBJECT_IDENTIFIER_print.c
OBJECT_IDENTIFIER_rfill.c
OBJECT_IDENTIFIER_xer.c
OCTET_STRING_aper.c
OCTET_STRING.c
OCTET_STRING_print.c
OCTET_STRING_rfill.c
OCTET_STRING_uper.c
OCTET_STRING_xer.c
OPEN_TYPE_aper.c
OPEN_TYPE.c
OPEN_TYPE_uper.c
OPEN_TYPE_xer.c
per_decoder.c
per_encoder.c
per_opentype.c
per_support.c
PrintableString.c
uper_decoder.c
uper_encoder.c
uper_opentype.c
uper_support.c
UTF8String.c
UTF8String_print.c
UTF8String_rfill.c
VisibleString.c
xer_decoder.c
xer_encoder.c
@@ -470,17 +531,21 @@ set(e1ap_source
set(e1ap_headers
ANY.h
aper_decoder.h
aper_encoder.h
aper_opentype.h
aper_support.h
asn_application.h
asn_bit_data.h
asn_codecs.h
asn_codecs_prim.h
asn_config.h
asn_internal.h
asn_ioc.h
asn_random_fill.h
asn_SEQUENCE_OF.h
asn_SET_OF.h
asn_system.h
ber_decoder.h
ber_tlv_length.h
ber_tlv_tag.h
BIT_STRING.h
@@ -490,7 +555,6 @@ set(e1ap_headers
constr_SEQUENCE_OF.h
constr_SET_OF.h
constr_TYPE.h
der_encoder.h
E1AP_ActivityInformation.h
E1AP_ActivityNotificationLevel.h
E1AP_AdditionalHandoverInfo.h
@@ -654,6 +718,7 @@ set(e1ap_headers
E1AP_Extended-NR-CGI-Support-List.h
E1AP_ExtendedPacketDelayBudget.h
E1AP_ExtendedSliceSupportList.h
E1AP_EXTERNAL.h
E1AP_FirstDLCount.h
E1AP_GBR-QoSFlowInformation.h
E1AP_GBR-QosInformation.h
@@ -922,9 +987,11 @@ set(e1ap_headers
E1AP_UPSecuritykey.h
E1AP_UP-TNL-Information.h
E1AP_URIaddress.h
GraphicString.h
INTEGER.h
NativeEnumerated.h
NativeInteger.h
ObjectDescriptor.h
OBJECT_IDENTIFIER.h
OCTET_STRING.h
OPEN_TYPE.h
@@ -933,6 +1000,10 @@ set(e1ap_headers
per_opentype.h
per_support.h
PrintableString.h
uper_decoder.h
uper_encoder.h
uper_opentype.h
uper_support.h
UTF8String.h
VisibleString.h
xer_decoder.h
+1 -1
View File
@@ -10,7 +10,7 @@ else()
endif()
add_custom_command(OUTPUT ${e1ap_source} ${e1ap_headers}
COMMAND ASN1C_PREFIX=E1AP_ asn1c -gen-PER -no-gen-OER -fcompound-names -no-gen-example -findirect-choice -fno-include-deps -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${E1AP_GRAMMAR}
COMMAND ASN1C_PREFIX=E1AP_ ${ASN1C_EXEC} -gen-APER -gen-UPER -no-gen-JER -no-gen-BER -no-gen-OER -fcompound-names -no-gen-example -findirect-choice -fno-include-deps -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${E1AP_GRAMMAR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${E1AP_GRAMMAR}
COMMENT "Generating E1AP source files from ${CMAKE_CURRENT_SOURCE_DIR}/${E1AP_GRAMMAR}"
)
+1
View File
@@ -42,6 +42,7 @@
#include "common/ran_context.h"
#include "sctp_default_values.h"
#include "LTE_SystemInformationBlockType2.h"
#include "uper_decoder.h"
#include "LAYER2/MAC/mac_extern.h"
#include "LAYER2/MAC/mac_proto.h"
#include "PHY/phy_extern.h"
-697
View File
@@ -1,697 +0,0 @@
import re, os, sys, string
import datetime
import getopt
import getpass
version = "1.0.2"
lines = ""
iesDefs = {}
ieofielist = {}
outdir = './'
filenames = []
verbosity = 0
prefix = ""
FAIL = '\033[91m'
WARN = '\033[93m'
ENDC = '\033[0m'
fileprefix = ""
fileprefix_first_upper = ""
def printFail(string):
sys.stderr.write(FAIL + string + ENDC + "\n")
def printWarning(string):
print WARN + string + ENDC
def printDebug(string):
if verbosity > 0:
print string
def outputHeaderToFile(f, filename):
now = datetime.datetime.now()
f.write("""/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
""")
f.write("/*******************************************************************************\n")
f.write(" * This file had been created by asn1tostruct.py script v%s\n" % (version))
f.write(" * Please do not modify this file but regenerate it via script.\n")
f.write(" * Created on: %s by %s\n * from %s\n" % (str(now), getpass.getuser(), filenames))
f.write(" ******************************************************************************/\n")
def lowerFirstCamelWord(word):
""" puts the first word in a CamelCase Word in lowercase.
I.e. CustomerID becomes customerID, XMLInfoTest becomes xmlInfoTest
"""
newstr = ''
swapped = word.swapcase()
idx = 0
# if it's all-caps, return an all-lowered version
lowered = word.lower()
if swapped == lowered:
return lowered
for c in swapped:
if c in string.lowercase:
newstr += c
idx += 1
else:
break
if idx < 2:
newstr += word[idx:]
else:
newstr = newstr[:-1]+ word[idx-1:]
return newstr
def usage():
print "Python parser for asn1 v%s" % (version)
print "Usage: python asn1tostruct.py [options]"
print "Available options:"
print "-d Enable script debug"
print "-f [file] Input file to parse"
print "-o [dir] Output files to given directory"
print "-h Print this help and return"
try:
opts, args = getopt.getopt(sys.argv[1:], "df:ho:", ["debug", "file", "help", "outdir"])
except getopt.GetoptError as err:
# print help information and exit:
usage()
sys.exit(2)
for o, a in opts:
if o in ("-f", "--file"):
filenames.append(a)
if o in ("-d", "--debug"):
verbosity = 1
if o in ("-o", "--outdir"):
outdir = a
if outdir.rfind('/') != len(outdir):
outdir += '/'
if o in ("-h", "--help"):
usage()
sys.exit(2)
for filename in filenames:
file = open(filename, 'r')
for line in file:
# Removing any comment
if line.find('--') >= 0:
line = line[:line.find('--')]
# Removing any carriage return
lines += re.sub('\r', '', line)
for m in re.findall(r'([a-zA-Z0-9-]+)\s*::=\s+SEQUENCE\s+\(\s*SIZE\s*\(\s*\d+\s*\.\.\s*[0-9a-zA-Z-]+\s*\)\s*\)\s*OF\s+[a-zA-Z-]+\s*\{\s*\{\s*([0-9a-zA-Z-]+)\s*\}\s*\}', lines, re.MULTILINE):
ieofielist[m[0]] = m[1]
for m in re.findall(r'([a-zA-Z0-9-]+)\s*::=\s+E-RAB-IE-ContainerList\s*\{\s*\{\s*([a-zA-Z0-9-]+)\s*\}\s*\}', lines, re.MULTILINE):
ieofielist[m[0]] = m[1]
for i in re.findall(r'([a-zA-Z0-9-]+)\s+([A-Z0-9-]+)\s*::=\s*\{\s+([\,\|\{\}\t\n\.{3}\ \-a-zA-Z0-9]+)\s+}\n?', lines, re.MULTILINE):
ies = []
maxLength = 0
# TODO: handle extensions
if i[1].find('EXTENSION') >= 0:
continue
if fileprefix == "":
fileprefix = i[1][:i[1].find('-')].lower()
for j in re.findall(r'\s*\{\s*([a-zA-Z0-9-\ \t]+)\s*\}\s*[\|,]*', i[2], re.MULTILINE):
for k in re.findall(r'ID\s*([a-zA-Z0-9\-]+)\s*CRITICALITY\s*([a-zA-Z0-9\-]+)\s+[A-Z]+\s+([a-zA-Z0-9\-]+)\s*PRESENCE\s*([a-zA-Z0-9\-]+)', j, re.MULTILINE):
printDebug("Got new ie for message " + i[0] + ": " + str(k))
if len(k[2]) > maxLength:
maxLength = len(k[2])
ies.append(k)
if len(ies) > 0:
iesDefs[i[0]] = { "length": maxLength, "ies": ies }
else:
printWarning("Didn't find any information element for message: " + i[0])
if len(iesDefs) == 0:
printFail("No Information Element parsed, exiting")
sys.exit(0)
fileprefix_first_upper = fileprefix[0].upper() + fileprefix[1:]
f = open(outdir + fileprefix + '_ies_defs.h', 'w')
outputHeaderToFile(f, filename)
f.write("#include \"%s_common.h\"\n\n" % (fileprefix))
f.write("#ifndef %s_IES_DEFS_H_\n#define %s_IES_DEFS_H_\n\n" % (fileprefix.upper(), fileprefix.upper()))
f.write("/* Define the version of script used to generate this file */\n")
f.write("#define %s_SCRIPT_VERSION (%s)\n\n" % (fileprefix.upper(), re.sub('\.', '', version)))
for key in iesDefs:
if key not in ieofielist.values():
continue
for (i, j) in ieofielist.items():
if j == key:
break
f.write("typedef struct %sIEs_s {\n" % (re.sub('-', '_', i)))
f.write(" A_SEQUENCE_OF(struct %s_s) %s;\n" % (re.sub('IEs', '', re.sub('-', '_', ieofielist[i])), lowerFirstCamelWord(re.sub('IEs', '', re.sub('-', '_', ieofielist[i])))))
f.write("} %sIEs_t;\n\n" % (re.sub('-', '_', i)))
for key in iesDefs:
keyupperunderscore = re.sub('-', '_', key.upper())
keylowerunderscore = re.sub('-', '_', key.lower())
shift = 0
if len(iesDefs[key]["ies"]) == 0:
continue
# Presence mask
for ie in iesDefs[key]["ies"]:
ieupperunderscore = re.sub('-', '_', re.sub('id-', '', ie[0])).upper()
if ie[3] == "optional" or ie[3] == "conditional":
f.write("#define {0:<{pad}} {1}\n".format("%s_%s_PRESENT" % (keyupperunderscore, ieupperunderscore), "(1 << %d)" % shift,
pad=iesDefs[key]["length"] + len(keyupperunderscore) + 9))
shift += 1
if (shift > 0):
f.write("\n")
f.write("typedef struct %s_s {\n" % (re.sub('-', '_', key)))
if (shift > 0):
f.write(" {0:<{pad}} {1};\n".format("uint16_t", "presenceMask", pad=iesDefs[key]["length"] + 2))
for ie in iesDefs[key]["ies"]:
ieunderscore = re.sub('-', '_', ie[2])
iename = re.sub('id-', '', ie[0])
ienameunderscore = lowerFirstCamelWord(re.sub('-', '_', iename))
if ie[2] in ieofielist:
f.write(" %sIEs_t %s;" % (re.sub('-', '_', ie[2]), ienameunderscore))
else:
f.write(" {0:<{pad}} {1};".format("%s_t" % ieunderscore, ienameunderscore, pad=iesDefs[key]["length"] + 2))
if ie[3] == "optional":
f.write(" ///< Optional field")
elif ie[3] == "conditional":
f.write(" ///< Conditional field")
f.write("\n")
f.write("} %s_t;\n\n" % (re.sub('-', '_', key)))
f.write("typedef struct %s_message_s {\n" % (fileprefix))
f.write(" %s_ProcedureCode_t procedureCode;\n" % (fileprefix_first_upper))
f.write(" %s_Criticality_t criticality;\n" % (fileprefix_first_upper))
f.write(" uint8_t direction;\n")
f.write(" union {\n")
messageList = iesDefs.keys()
messageList.sort()
for message in messageList:
if message in ieofielist.values():
continue
if len(iesDefs[message]["ies"]) == 0:
continue
f.write(" %s_t %s;\n" % (re.sub('-', '_', message), lowerFirstCamelWord(re.sub('-', '_', message))))
f.write(" } msg;\n")
f.write("} %s_message;\n\n" % (fileprefix))
for key in iesDefs:
if key in ieofielist.values():
continue
structName = re.sub('ies', '', key)
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', re.sub('-IEs', '', key)))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
keylowerunderscore = re.sub('-', '_', key.lower())
firstlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
f.write("/** \\brief Decode function for %s ies.\n" % (key))
if len(iesDefs[key]["ies"]) != 0:
f.write(" * \\param %s Pointer to ASN1 structure in which data will be stored\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" * \\param any_p Pointer to the ANY value to decode.\n")
f.write(" **/\n")
f.write("int %s_decode_%s(\n" % (fileprefix, keylowerunderscore))
if len(iesDefs[key]["ies"]) != 0:
f.write(" %s_t *%s,\n" % (re.sub('-', '_', key), lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" ANY_t *any_p);\n\n")
if len(iesDefs[key]["ies"]) == 0:
continue
f.write("/** \\brief Encode function for %s ies.\n" % (key))
f.write(" * \\param %s Pointer to the ASN1 structure.\n" % (firstlower))
f.write(" * \\param %s Pointer to the IES structure.\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" **/\n")
f.write("int %s_encode_%s(\n" % (fileprefix, re.sub('-', '_', structName.lower())))
f.write(" %s_t *%s,\n" % (asn1cStruct, firstlower))
f.write(" %s_t *%s);\n\n" % (re.sub('-', '_', key), lowerFirstCamelWord(re.sub('-', '_', key))))
for key in iesDefs:
if key not in ieofielist.values():
continue
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', key))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
firstlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
f.write("/** \\brief Encode function for %s ies.\n" % (key))
f.write(" * \\param %s Pointer to the ASN1 structure.\n" % (firstlower))
f.write(" * \\param %s Pointer to the IES structure.\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" **/\n")
f.write("int %s_encode_%s(\n" % (fileprefix, firstlower.lower()))
f.write(" %s_t *%s,\n" % (asn1cStruct, firstlower))
f.write(" %sIEs_t *%sIEs);\n\n" % (asn1cStruct, firstlower))
f.write("/** \\brief Decode function for %s ies.\n" % (key))
f.write(" * \\param any_p Pointer to the ANY value to decode.\n")
f.write(" * \\param callback Callback function called when any_p is successfully decoded.\n")
f.write(" **/\n")
f.write("int %s_decode_%s(\n" % (fileprefix, firstlower.lower()))
f.write(" %sIEs_t *%sIEs,\n" % (asn1cStruct, firstlower))
f.write(" %s_t *%s);\n\n" % (asn1cStruct, lowerFirstCamelWord(asn1cStruct)))
for key in iesDefs:
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', key))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
firstlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
if key in ieofielist.values():
f.write("/** \\brief Display %s encapsulated IE using XER encoding.\n" % (asn1cStruct))
f.write(" * \\param %s Pointer to the IES structure.\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" * \\param file File descriptor to write output.\n")
f.write(" **/\n")
f.write("asn_enc_rval_t %s_xer_print_%s(\n" % (fileprefix, re.sub('item', 'list', firstlower.lower())))
f.write(" asn_app_consume_bytes_f *cb,\n")
f.write(" void *app_key,\n")
f.write(" %sIEs_t *%sIEs);\n\n" % (re.sub('item', 'list', asn1cStruct), firstlower))
else:
f.write("/** \\brief Display %s message using XER encoding.\n" % (asn1cStruct))
f.write(" * \\param message_p Pointer to root message.\n")
f.write(" * \\param file File descriptor to write output.\n")
f.write(" **/\n")
f.write("asn_enc_rval_t %s_xer_print_%s(\n" % (fileprefix, firstlower.lower()))
f.write(" asn_app_consume_bytes_f *cb,\n")
f.write(" void *app_key,\n")
f.write(" %s_message *message_p);\n\n" % (fileprefix))
f.write("int %s_xer__print2sp(const void *buffer, size_t size, void *app_key);\n\n" % (fileprefix.lower()))
f.write("int %s_xer__print2fp(const void *buffer, size_t size, void *app_key);\n\n" % (fileprefix.lower()))
f.write("extern size_t %s_string_total_size;\n\n" % (fileprefix.lower()))
f.write("#endif /* %s_IES_DEFS_H_ */\n\n" % (fileprefix.upper()))
#Generate Decode functions
f = open(outdir + fileprefix + '_decoder.c', 'w')
outputHeaderToFile(f, filename)
f.write("#include \"%s_common.h\"\n#include \"%s_ies_defs.h\"\n\n" % (fileprefix, fileprefix))
for key in iesDefs:
if key in ieofielist.values():
continue
structName = re.sub('ies', '', key)
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', key))
if asn1cStruct.rfind('_') == len(asn1cStruct) - 1:
asn1cStruct = asn1cStruct[:-1]
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
ielistname = re.sub('UE', 'ue', asn1cStruct)
ielistnamefirstlower = ielistname[:1].lower() + ielistname[1:]
asn1cStructfirstlower = asn1cStruct[:1].lower() + asn1cStruct[1:]
keyName = re.sub('-', '_', key)
keyupperunderscore = keyName.upper()
firstlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
iesaccess = ""
if key not in ieofielist.values():
iesaccess = "%s_ies." % (firstlower)
f.write("int %s_decode_%s(\n" % (fileprefix, re.sub('-', '_', structName.lower())))
if len(iesDefs[key]["ies"]) != 0:
f.write(" %s_t *%s,\n" % (re.sub('-', '_', key), lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" ANY_t *any_p) {\n\n")
f.write(" %s_t %s;\n %s_t *%s_p = &%s;\n" % (asn1cStruct, asn1cStructfirstlower, asn1cStruct, asn1cStructfirstlower, asn1cStructfirstlower))
f.write(" int i, decoded = 0;\n")
if len(iesDefs[key]["ies"]) != 0:
f.write(" int tempDecoded = 0;\n")
f.write(" assert(any_p != NULL);\n")
if len(iesDefs[key]["ies"]) != 0:
f.write(" assert(%s != NULL);\n\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" %s_DEBUG(\"Decoding message %s (%%s:%%d)\\n\", __FILE__, __LINE__);\n\n" % (fileprefix.upper(), re.sub('-', '_', keyName)))
f.write(" ANY_to_type_aper(any_p, &asn_DEF_%s, (void**)&%s_p);\n\n" % (asn1cStruct, asn1cStructfirstlower))
f.write(" for (i = 0; i < %s_p->%slist.count; i++) {\n" % (asn1cStructfirstlower, iesaccess))
f.write(" %s_IE_t *ie_p;\n" % (fileprefix[0].upper() + fileprefix[1:]))
f.write(" ie_p = %s_p->%slist.array[i];\n" % (asn1cStructfirstlower, iesaccess))
f.write(" switch(ie_p->id) {\n")
for ie in iesDefs[key]["ies"]:
iename = re.sub('id-', '', ie[0])
ienameunderscore = lowerFirstCamelWord(re.sub('-', '_', iename))
ienameunderscorefirstlower = lowerFirstCamelWord(ienameunderscore)
ietypesubst = re.sub('-', '', ie[2])
ietypeunderscore = re.sub('-', '_', ie[2])
ieupperunderscore = re.sub('-', '_', re.sub('id-', '', ie[0])).upper()
if ie[3] == "optional":
f.write(" /* Optional field */\n")
elif ie[3] == "conditional":
f.write(" /* Conditional field */\n")
f.write(" case %s_ProtocolIE_ID_%s:\n" % (fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" {\n")
f.write(" %s_t *%s_p = NULL;\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
if ie[3] != "mandatory":
f.write(" %s->presenceMask |= %s_%s_PRESENT;\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), keyupperunderscore, ieupperunderscore))
f.write(" tempDecoded = ANY_to_type_aper(&ie_p->value, &asn_DEF_%s, (void**)&%s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" if (tempDecoded < 0 || %s_p == NULL) {\n" % (lowerFirstCamelWord(ietypesubst)))
f.write(" %s_ERROR(\"Decoding of IE %s failed\\n\");\n" % (fileprefix.upper(), ienameunderscore))
f.write(" if (%s_p)\n" % (lowerFirstCamelWord(ietypesubst)))
f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" decoded += tempDecoded;\n")
f.write(" if (asn1_xer_print)\n")
f.write(" xer_fprint(stdout, &asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
if ie[2] in ieofielist.keys():
f.write(" if (%s_decode_%s(&%s->%s, %s_p) < 0) {\n" % (fileprefix, ietypeunderscore.lower(), lowerFirstCamelWord(re.sub('-', '_', key)), ienameunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" %s_ERROR(\"Decoding of encapsulated IE %s failed\\n\");\n" % (fileprefix.upper(), lowerFirstCamelWord(ietypesubst)))
f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" }\n")
else:
f.write(" memcpy(&%s->%s, %s_p, sizeof(%s_t));\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), ienameunderscore, lowerFirstCamelWord(ietypesubst), ietypeunderscore))
#f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" } break;\n")
f.write(" default:\n")
f.write(" %s_ERROR(\"Unknown protocol IE id (%%d) for message %s\\n\", (int)ie_p->id);\n" % (fileprefix.upper(), re.sub('-', '_', structName.lower())))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" }\n")
f.write(" return decoded;\n")
f.write("}\n\n")
for key in iesDefs:
if key not in ieofielist.values():
continue
keyname = re.sub('IEs', '', re.sub('Item', 'List', key))
f.write("int %s_decode_%s(\n" % (fileprefix, re.sub('-', '_', keyname).lower()))
f.write(" %sIEs_t *%sIEs,\n" % (re.sub('-', '_', keyname), lowerFirstCamelWord(re.sub('-', '_', keyname))))
f.write(" %s_t *%s) {\n\n" % (re.sub('-', '_', keyname), lowerFirstCamelWord(re.sub('-', '_', keyname))))
f.write(" int i, decoded = 0;\n")
f.write(" int tempDecoded = 0;\n\n")
f.write(" assert(%s != NULL);\n" % (lowerFirstCamelWord(re.sub('-', '_', keyname))));
f.write(" assert(%sIEs != NULL);\n\n" % (lowerFirstCamelWord(re.sub('-', '_', keyname))));
f.write(" for (i = 0; i < %s->list.count; i++) {\n" % (lowerFirstCamelWord(re.sub('-', '_', keyname))))
f.write(" %s_IE_t *ie_p = %s->list.array[i];\n" % (fileprefix[0].upper() + fileprefix[1:], lowerFirstCamelWord(re.sub('-', '_', keyname))))
f.write(" switch (ie_p->id) {\n")
for ie in iesDefs[key]["ies"]:
iename = re.sub('id-', '', ie[0])
ienameunderscore = lowerFirstCamelWord(re.sub('-', '_', iename))
f.write(" case %s_ProtocolIE_ID_%s:\n" % (fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" {\n")
f.write(" %s_t *%s_p = NULL;\n" % (re.sub('-', '_', ie[2]), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" tempDecoded = ANY_to_type_aper(&ie_p->value, &asn_DEF_%s, (void**)&%s_p);\n" % (re.sub('-', '_', ie[2]), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" if (tempDecoded < 0 || %s_p == NULL) {\n" % (lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" %s_ERROR(\"Decoding of IE %s for message %s failed\\n\");\n" % (fileprefix.upper(), ienameunderscore, re.sub('-', '_', keyname)))
f.write(" if (%s_p)\n" % (lowerFirstCamelWord(re.sub('-', '', ie[2]))))
#f.write(" free(%s_p);\n" % (lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (re.sub('-', '_', ie[2]), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" decoded += tempDecoded;\n")
f.write(" if (asn1_xer_print)\n")
f.write(" xer_fprint(stdout, &asn_DEF_%s, %s_p);\n" % (re.sub('-', '_', ie[2]), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" ASN_SEQUENCE_ADD(&%sIEs->%s, %s_p);\n" % (lowerFirstCamelWord(re.sub('-', '_', keyname)),
re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key))), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" } break;\n")
f.write(" default:\n")
f.write(" %s_ERROR(\"Unknown protocol IE id (%%d) for message %s\\n\", (int)ie_p->id);\n" % (fileprefix.upper(), re.sub('-', '_', structName.lower())))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" }\n")
f.write(" return decoded;\n")
f.write("}\n\n")
#Generate IES Encode functions
f = open(outdir + fileprefix + '_encoder.c', 'w')
outputHeaderToFile(f,filename)
f.write("#include \"%s_common.h\"\n" % (fileprefix))
f.write("#include \"%s_ies_defs.h\"\n\n" % (fileprefix))
for key in iesDefs:
if key in ieofielist.values():
continue
structName = re.sub('ies', '', key)
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', key))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
if asn1cStruct.rfind('_') == len(asn1cStruct) - 1:
asn1cStruct = asn1cStruct[:-1]
asn1cStructfirstlower = asn1cStruct[:1].lower() + asn1cStruct[1:]
firstwordlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
iesaccess = ""
if key not in ieofielist.values():
iesaccess = "%s_ies." % (firstwordlower)
keyName = re.sub('-', '_', key)
keyupperunderscore = keyName.upper()
# No IE to encode...
if len(iesDefs[key]["ies"]) == 0:
continue
f.write("int %s_encode_%s(\n" % (fileprefix, re.sub('-', '_', structName.lower())))
f.write(" %s_t *%s,\n" % (asn1cStruct, firstwordlower))
f.write(" %s_t *%s) {\n\n" % (re.sub('-', '_', key), lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" %s_IE_t *ie;\n\n" % (fileprefix_first_upper))
f.write(" assert(%s != NULL);\n" % (firstwordlower));
f.write(" assert(%s != NULL);\n\n" % (lowerFirstCamelWord(re.sub('-', '_', key))));
for ie in iesDefs[key]["ies"]:
iename = re.sub('-', '_', re.sub('id-', '', ie[0]))
ienameunderscore = re.sub('-', '_', iename)
ienamefirstwordlower = lowerFirstCamelWord(iename)
ieupperunderscore = re.sub('-', '_', re.sub('id-', '', ie[0])).upper()
ietypeunderscore = re.sub('-', '_', ie[2])
if ie[3] != "mandatory":
if ie[3] == "optional":
f.write(" /* Optional field */\n")
elif ie[3] == "conditional":
f.write(" /* Conditional field */\n")
f.write(" if (%s->presenceMask & %s_%s_PRESENT) {\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), keyupperunderscore, ieupperunderscore))
#f.write(" == %s_%s_PRESENT) {\n" % (keyupperunderscore, ieupperunderscore))
f.write(" if ((ie = %s_new_ie(%s_ProtocolIE_ID_%s,\n" % (fileprefix, fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" %s_Criticality_%s,\n" % (fileprefix_first_upper, ie[1]))
f.write(" &asn_DEF_%s,\n" % (ietypeunderscore))
f.write(" &%s->%s)) == NULL) {\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), ienamefirstwordlower))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" ASN_SEQUENCE_ADD(&%s->%slist, ie);\n" % (firstwordlower, iesaccess))
f.write(" }\n\n")
else:
if ie[2] in ieofielist.keys():
f.write(" %s_t %s;\n\n" % (ietypeunderscore, ienamefirstwordlower))
f.write(" memset(&%s, 0, sizeof(%s_t));\n" % (ienamefirstwordlower, ietypeunderscore))
f.write("\n")
f.write(" if (%s_encode_%s(&%s, &%s->%s) < 0) return -1;\n" % (fileprefix, ietypeunderscore.lower(), ienamefirstwordlower, lowerFirstCamelWord(re.sub('-', '_', key)), ienamefirstwordlower))
f.write(" if ((ie = %s_new_ie(%s_ProtocolIE_ID_%s,\n" % (fileprefix, fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" %s_Criticality_%s,\n" % (fileprefix_first_upper, ie[1]))
f.write(" &asn_DEF_%s,\n" % (ietypeunderscore))
if ie[2] in ieofielist.keys():
f.write(" &%s)) == NULL) {\n" % (ienamefirstwordlower))
else:
f.write(" &%s->%s)) == NULL) {\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), ienamefirstwordlower))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" ASN_SEQUENCE_ADD(&%s->%slist, ie);\n\n" % (firstwordlower, iesaccess))
if ie[2] in ieofielist.keys():
f.write(" /* Free any dynamic allocation that is no more used */\n")
f.write(" ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_%s, &%s);\n\n" % (ietypeunderscore, ienamefirstwordlower))
f.write(" return 0;\n")
f.write("}\n\n")
for (key, value) in iesDefs.items():
if key not in ieofielist.values():
continue
ie = value["ies"][0]
ietypeunderscore = re.sub('-', '_', ie[2])
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', re.sub('-IEs', '', key)))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
firstwordlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
for (i, j) in ieofielist.items():
if j == key:
break
f.write("int %s_encode_%s(\n" % (fileprefix, re.sub('-', '_', i).lower()))
f.write(" %s_t *%s,\n" % (asn1cStruct, firstwordlower))
f.write(" %sIEs_t *%sIEs) {\n\n" % (re.sub('-', '_', i), lowerFirstCamelWord(re.sub('-', '_', i))))
f.write(" int i;\n")
f.write(" %s_IE_t *ie;\n\n" % (fileprefix_first_upper))
f.write(" assert(%s != NULL);\n" % (firstwordlower));
f.write(" assert(%sIEs != NULL);\n\n" % (lowerFirstCamelWord(re.sub('-', '_', i))));
f.write(" for (i = 0; i < %sIEs->%s.count; i++) {\n" % (firstwordlower, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
f.write(" if ((ie = %s_new_ie(%s_ProtocolIE_ID_%s,\n" % (fileprefix, fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" %s_Criticality_%s,\n" % (fileprefix_first_upper, ie[1]))
f.write(" &asn_DEF_%s,\n" % (ietypeunderscore))
f.write(" %sIEs->%s.array[i])) == NULL) {\n" % (firstwordlower, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" ASN_SEQUENCE_ADD(&%s->list, ie);\n" % (firstwordlower))
f.write(" }\n")
f.write(" return 0;\n")
f.write("}\n\n")
#Generate xer print functions
f = open(outdir + fileprefix + '_xer_print.c', 'w')
outputHeaderToFile(f, filename)
f.write("#include <stdlib.h>\n")
f.write("#include <stdio.h>\n\n")
f.write("#include <asn_application.h>\n#include <asn_internal.h>\n\n")
f.write("#include \"%s_common.h\"\n#include \"%s_ies_defs.h\"\n\n" % (fileprefix, fileprefix))
f.write("size_t %s_string_total_size = 0;\n\n" % (fileprefix.lower()))
f.write("""int
%s_xer__print2fp(const void *buffer, size_t size, void *app_key) {
FILE *stream = (FILE *)app_key;
if(fwrite(buffer, 1, size, stream) != size)
return -1;
return 0;
}
""" % (fileprefix.lower()))
f.write("""int %s_xer__print2sp(const void *buffer, size_t size, void *app_key) {
char *string = (char *)app_key;
/* Copy buffer to the formatted string */
memcpy(&string[%s_string_total_size], buffer, size);
%s_string_total_size += size;
return 0;
}
""" % (fileprefix.lower(), fileprefix.lower(), fileprefix.lower()))
f.write("""static asn_enc_rval_t
xer_encode_local(asn_TYPE_descriptor_t *td, void *sptr,
asn_app_consume_bytes_f *cb, void *app_key, int indent) {
asn_enc_rval_t er, tmper;
const char *mname;
size_t mlen;
int xcan = 2;
if(!td || !sptr) goto cb_failed;
mname = td->xml_tag;
mlen = strlen(mname);
_i_ASN_TEXT_INDENT(0, indent);
_ASN_CALLBACK3("<", 1, mname, mlen, ">", 1);
tmper = td->xer_encoder(td, sptr, indent + 1, XER_F_BASIC, cb, app_key);
if(tmper.encoded == -1) return tmper;
_ASN_CALLBACK3("</", 2, mname, mlen, ">\\n", xcan);
er.encoded = 4 + xcan + (2 * mlen) + tmper.encoded;
_ASN_ENCODED_OK(er);
cb_failed:
_ASN_ENCODE_FAILED;
}
""")
for (key, value) in iesDefs.items():
keyName = re.sub('-', '_', key)
keyupperunderscore = keyName.upper()
iesStructName = lowerFirstCamelWord(re.sub('-', '_', key))
ie = value["ies"][0]
ietypeunderscore = re.sub('-', '_', ie[2])
if key in ieofielist.values():
f.write("asn_enc_rval_t %s_xer_print_%s(\n" % (fileprefix, re.sub('ies', '', re.sub('item', 'list', re.sub('-', '_', key).lower()))))
else:
f.write("asn_enc_rval_t %s_xer_print_%s(\n" % (fileprefix, re.sub('ies', '', re.sub('-', '_', key).lower())))
#f.write(" FILE *file,\n")
f.write(" asn_app_consume_bytes_f *cb,\n")
f.write(" void *app_key,\n")
if key in ieofielist.values():
iesStructName = lowerFirstCamelWord(re.sub('Item', 'List', re.sub('-', '_', key)))
f.write(" %sIEs_t *%s) {\n\n" % (re.sub('IEs', '', re.sub('Item', 'List', re.sub('-', '_', key))), iesStructName))
f.write(" int i;\n")
f.write(" asn_enc_rval_t er;\n")
else:
f.write(" %s_message *message_p)\n{\n" % (fileprefix))
f.write(" %s_t *%s;\n" % (re.sub('-', '_', key), iesStructName))
f.write(" asn_enc_rval_t er;\n")
#f.write(" void *app_key = (void *)file;\n")
#f.write(" asn_app_consume_bytes_f *cb = %s_xer__print2fp;\n\n" % (fileprefix.lower()))
f.write(" %s = &message_p->msg.%s;\n\n" % (iesStructName, iesStructName))
if key in ieofielist.values():
# Increase indentation level
f.write(" for (i = 0; i < %s->%s.count; i++) {\n" % (iesStructName, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
#f.write(" xer_fprint(file, &asn_DEF_%s, %s->%s.array[i]);\n" % (ietypeunderscore, iesStructName, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
f.write(" er = xer_encode(&asn_DEF_%s, %s->%s.array[i], XER_F_BASIC, cb, app_key);\n" % (ietypeunderscore, iesStructName, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
f.write(" }\n")
else:
f.write(" cb(\"<%s-PDU>\\n\", %d, app_key);\n" % (key, len("<%s-PDU>\n" % (key))))
f.write(" xer_encode_local(&asn_DEF_%s_Criticality, &message_p->criticality, cb, app_key, 1);\n" % fileprefix_first_upper)
f.write(" xer_encode_local(&asn_DEF_%s_ProcedureCode, &message_p->procedureCode, cb, app_key, 1);\n" % fileprefix_first_upper)
f.write(" cb(\" <%s>\\n\", %d, app_key);\n" % (key, len(" <%s>\n" % (key))))
for ie in iesDefs[key]["ies"]:
iename = re.sub('-', '_', re.sub('id-', '', ie[0]))
ienameunderscore = re.sub('-', '_', iename)
ienamefirstwordlower = lowerFirstCamelWord(iename)
ietypeunderscore = re.sub('-', '_', ie[2])
ieupperunderscore = re.sub('-', '_', re.sub('id-', '', ie[0])).upper()
if ie[3] != "mandatory":
if ie[3] == "optional":
f.write(" /* Optional field */\n")
elif ie[3] == "conditional":
f.write(" /* Conditional field */\n")
f.write(" if (%s->presenceMask & %s_%s_PRESENT)\n " % (iesStructName, keyupperunderscore, ieupperunderscore))
# Is it an encapsulated IE ?
if ie[2] in ieofielist.keys():
f.write(" %s_xer_print_%s(cb, app_key, &%s->%s);\n" % (fileprefix, re.sub('ies', '', re.sub('-', '_', ie[2]).lower()), iesStructName, ienamefirstwordlower))
else:
f.write(" xer_encode_local(&asn_DEF_%s, &%s->%s, cb, app_key, 2);\n" % (ietypeunderscore, iesStructName, ienamefirstwordlower))
f.write(" cb(\" </%s>\\n\", %d, app_key);\n" % (key, len(" </%s>\n" % (key))))
f.write(" cb(\"</%s-PDU>\\n\", %d, app_key);\n" % (key, len("</%s-PDU>\n" % (key))))
f.write(" _ASN_ENCODED_OK(er);\n")
#if key not in ieofielist.values():
#f.write("cb_failed:\n")
#f.write(" return er;\n")
f.write("}\n\n")
+85 -4
View File
@@ -1,26 +1,59 @@
set(F1AP_GRAMMAR ASN1/R16.3.1/38473-g31.asn)
set(f1ap_source
ANY_aper.c
ANY.c
ANY_uper.c
ANY_xer.c
aper_decoder.c
aper_encoder.c
aper_opentype.c
aper_support.c
asn_application.c
asn_bit_data.c
asn_codecs_prim.c
asn_codecs_prim_xer.c
asn_internal.c
asn_random_fill.c
asn_SEQUENCE_OF.c
asn_SET_OF.c
ber_decoder.c
ber_tlv_length.c
ber_tlv_tag.c
BIT_STRING.c
BIT_STRING_print.c
BIT_STRING_rfill.c
BIT_STRING_uper.c
BIT_STRING_xer.c
BOOLEAN_aper.c
BOOLEAN.c
BOOLEAN_print.c
BOOLEAN_rfill.c
BOOLEAN_uper.c
BOOLEAN_xer.c
constraints.c
constr_CHOICE_aper.c
constr_CHOICE.c
constr_CHOICE_print.c
constr_CHOICE_rfill.c
constr_CHOICE_uper.c
constr_CHOICE_xer.c
constr_SEQUENCE_aper.c
constr_SEQUENCE.c
constr_SEQUENCE_OF_aper.c
constr_SEQUENCE_OF.c
constr_SEQUENCE_OF_uper.c
constr_SEQUENCE_OF_xer.c
constr_SEQUENCE_print.c
constr_SEQUENCE_rfill.c
constr_SEQUENCE_uper.c
constr_SEQUENCE_xer.c
constr_SET_OF_aper.c
constr_SET_OF.c
constr_SET_OF_print.c
constr_SET_OF_rfill.c
constr_SET_OF_uper.c
constr_SET_OF_xer.c
constr_TYPE.c
der_encoder.c
F1AP_AbortTransmission.c
F1AP_AccessAndMobilityIndication.c
F1AP_AccessPointPosition.c
@@ -295,6 +328,7 @@ set(f1ap_source
F1AP_ExtendedServedPLMNs-Item.c
F1AP_ExtendedServedPLMNs-List.c
F1AP_ExtendedSliceSupportList.c
F1AP_EXTERNAL.c
F1AP_F1AP-PDU.c
F1AP_F1RemovalFailure.c
F1AP_F1RemovalRequest.c
@@ -969,19 +1003,56 @@ set(f1ap_source
F1AP_VictimgNBSetID.c
F1AP_WriteReplaceWarningRequest.c
F1AP_WriteReplaceWarningResponse.c
GraphicString.c
INTEGER_aper.c
INTEGER.c
INTEGER_print.c
INTEGER_rfill.c
INTEGER_uper.c
INTEGER_xer.c
NativeEnumerated_aper.c
NativeEnumerated.c
NativeEnumerated_uper.c
NativeEnumerated_xer.c
NativeInteger_aper.c
NativeInteger.c
NativeInteger_print.c
NativeInteger_rfill.c
NativeInteger_uper.c
NativeInteger_xer.c
NULL_aper.c
NULL.c
NULL_print.c
NULL_rfill.c
NULL_uper.c
NULL_xer.c
ObjectDescriptor.c
OBJECT_IDENTIFIER.c
OBJECT_IDENTIFIER_print.c
OBJECT_IDENTIFIER_rfill.c
OBJECT_IDENTIFIER_xer.c
OCTET_STRING_aper.c
OCTET_STRING.c
OCTET_STRING_print.c
OCTET_STRING_rfill.c
OCTET_STRING_uper.c
OCTET_STRING_xer.c
OPEN_TYPE_aper.c
OPEN_TYPE.c
OPEN_TYPE_uper.c
OPEN_TYPE_xer.c
per_decoder.c
per_encoder.c
per_opentype.c
per_support.c
PrintableString.c
uper_decoder.c
uper_encoder.c
uper_opentype.c
uper_support.c
UTF8String.c
UTF8String_print.c
UTF8String_rfill.c
VisibleString.c
xer_decoder.c
xer_encoder.c
@@ -990,17 +1061,21 @@ set(f1ap_source
set(f1ap_headers
ANY.h
aper_decoder.h
aper_encoder.h
aper_opentype.h
aper_support.h
asn_application.h
asn_bit_data.h
asn_codecs.h
asn_codecs_prim.h
asn_config.h
asn_internal.h
asn_ioc.h
asn_random_fill.h
asn_SEQUENCE_OF.h
asn_SET_OF.h
asn_system.h
ber_decoder.h
ber_tlv_length.h
ber_tlv_tag.h
BIT_STRING.h
@@ -1011,7 +1086,6 @@ set(f1ap_headers
constr_SEQUENCE_OF.h
constr_SET_OF.h
constr_TYPE.h
der_encoder.h
F1AP_AbortTransmission.h
F1AP_AccessAndMobilityIndication.h
F1AP_AccessPointPosition.h
@@ -1287,6 +1361,7 @@ set(f1ap_headers
F1AP_ExtendedServedPLMNs-Item.h
F1AP_ExtendedServedPLMNs-List.h
F1AP_ExtendedSliceSupportList.h
F1AP_EXTERNAL.h
F1AP_F1AP-PDU.h
F1AP_F1RemovalFailure.h
F1AP_F1RemovalRequest.h
@@ -1961,10 +2036,12 @@ set(f1ap_headers
F1AP_VictimgNBSetID.h
F1AP_WriteReplaceWarningRequest.h
F1AP_WriteReplaceWarningResponse.h
GraphicString.h
INTEGER.h
NativeEnumerated.h
NativeInteger.h
NULL.h
ObjectDescriptor.h
OBJECT_IDENTIFIER.h
OCTET_STRING.h
OPEN_TYPE.h
@@ -1973,6 +2050,10 @@ set(f1ap_headers
per_opentype.h
per_support.h
PrintableString.h
uper_decoder.h
uper_encoder.h
uper_opentype.h
uper_support.h
UTF8String.h
VisibleString.h
xer_decoder.h
+1 -1
View File
@@ -9,7 +9,7 @@ else()
endif()
add_custom_command(OUTPUT ${f1ap_source} ${f1ap_headers}
COMMAND ASN1C_PREFIX=F1AP_ asn1c -gen-PER -no-gen-OER -fcompound-names -no-gen-example -findirect-choice -fno-include-deps -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${F1AP_GRAMMAR}
COMMAND ASN1C_PREFIX=F1AP_ ${ASN1C_EXEC} -gen-APER -no-gen-BER -no-gen-JER -no-gen-OER -gen-UPER -fcompound-names -no-gen-example -findirect-choice -fno-include-deps -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${F1AP_GRAMMAR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${F1AP_GRAMMAR}
COMMENT "Generating F1AP source files from ${CMAKE_CURRENT_SOURCE_DIR}/${F1AP_GRAMMAR}"
)
@@ -37,6 +37,8 @@
#include "f1ap_du_rrc_message_transfer.h"
#include "uper_decoder.h"
#include "NR_DL-CCCH-Message.h"
#include "NR_UL-CCCH-Message.h"
#include "NR_DL-DCCH-Message.h"
+2
View File
@@ -83,6 +83,8 @@
#include "NR_SearchSpace.h"
#include "NR_ControlResourceSet.h"
#include "NR_EUTRA-MBSFN-SubframeConfig.h"
#include "uper_decoder.h"
#include "uper_encoder.h"
#include "RRC/NR/MESSAGES/asn1_msg.h"
#include "RRC/NR/nr_rrc_extern.h"
+1
View File
@@ -39,6 +39,7 @@
#include "NR_BCCH-BCH-Message.h"
#include "NR_ServingCellConfigCommon.h"
#include "uper_encoder.h"
#include "LAYER2/NR_MAC_gNB/mac_proto.h"
#include "SCHED_NR/phy_frame_config_nr.h"
@@ -28,6 +28,7 @@
*/
#include "platform_types.h"
#include "uper_decoder.h"
/* MAC */
#include "nr_mac_gNB.h"
@@ -50,6 +50,9 @@
#include "T.h"
#include "uper_encoder.h"
#include "uper_decoder.h"
#define ENABLE_MAC_PAYLOAD_DEBUG
#define DEBUG_gNB_SCHEDULER 1
@@ -25,6 +25,9 @@
#include "openair2/LAYER2/nr_rlc/nr_rlc_oai_api.h"
#include "openair2/RRC/NR/MESSAGES/asn1_msg.h"
#include "uper_decoder.h"
#include "uper_encoder.h"
static NR_RLC_BearerConfig_t *get_bearerconfig_from_srb(const f1ap_srb_to_be_setup_t *srb)
{
long priority = srb->srb_id; // high priority for SRB
+73 -4
View File
@@ -1,26 +1,60 @@
set(M2AP_GRAMMAR ASN1/m2ap-14.0.0.asn)
set(m2ap_source
ANY_aper.c
ANY.c
ANY_uper.c
ANY_xer.c
aper_decoder.c
aper_encoder.c
aper_opentype.c
aper_support.c
asn_application.c
asn_bit_data.c
asn_codecs_prim.c
asn_codecs_prim_xer.c
asn_internal.c
asn_random_fill.c
asn_SEQUENCE_OF.c
asn_SET_OF.c
ber_decoder.c
ber_tlv_length.c
ber_tlv_tag.c
BIT_STRING.c
BIT_STRING_print.c
BIT_STRING_rfill.c
BIT_STRING_uper.c
BIT_STRING_xer.c
constraints.c
constr_CHOICE_aper.c
constr_CHOICE.c
constr_CHOICE_print.c
constr_CHOICE_rfill.c
constr_CHOICE_uper.c
constr_CHOICE_xer.c
constr_SEQUENCE_aper.c
constr_SEQUENCE.c
constr_SEQUENCE_OF_aper.c
constr_SEQUENCE_OF.c
constr_SEQUENCE_OF_uper.c
constr_SEQUENCE_OF_xer.c
constr_SEQUENCE_print.c
constr_SEQUENCE_rfill.c
constr_SEQUENCE_uper.c
constr_SEQUENCE_xer.c
constr_SET_OF_aper.c
constr_SET_OF.c
constr_SET_OF_print.c
constr_SET_OF_rfill.c
constr_SET_OF_uper.c
constr_SET_OF_xer.c
constr_TYPE.c
der_encoder.c
GraphicString.c
INTEGER_aper.c
INTEGER.c
INTEGER_print.c
INTEGER_rfill.c
INTEGER_uper.c
INTEGER_xer.c
M2AP_Active-MBMS-Session-List.c
M2AP_AllocatedSubframesEnd.c
M2AP_AllocationAndRetentionPriority.c
@@ -51,6 +85,7 @@ set(m2ap_source
M2AP_ENBname.c
M2AP_ErrorIndication.c
M2AP_EUTRANCellIdentifier.c
M2AP_EXTERNAL.c
M2AP_GBR-QosInformation.c
M2AP_GlobalENB-ID.c
M2AP_GlobalMCE-ID.c
@@ -154,16 +189,40 @@ set(m2ap_source
M2AP_TriggeringMessage.c
M2AP_TypeOfError.c
M2AP_UnsuccessfulOutcome.c
NativeEnumerated_aper.c
NativeEnumerated.c
NativeEnumerated_uper.c
NativeEnumerated_xer.c
NativeInteger_aper.c
NativeInteger.c
NativeInteger_print.c
NativeInteger_rfill.c
NativeInteger_uper.c
NativeInteger_xer.c
ObjectDescriptor.c
OBJECT_IDENTIFIER.c
OBJECT_IDENTIFIER_print.c
OBJECT_IDENTIFIER_rfill.c
OBJECT_IDENTIFIER_xer.c
OCTET_STRING_aper.c
OCTET_STRING.c
OCTET_STRING_print.c
OCTET_STRING_rfill.c
OCTET_STRING_uper.c
OCTET_STRING_xer.c
OPEN_TYPE_aper.c
OPEN_TYPE.c
OPEN_TYPE_uper.c
OPEN_TYPE_xer.c
per_decoder.c
per_encoder.c
per_opentype.c
per_support.c
PrintableString.c
uper_decoder.c
uper_encoder.c
uper_opentype.c
uper_support.c
xer_decoder.c
xer_encoder.c
xer_support.c
@@ -171,17 +230,21 @@ set(m2ap_source
set(m2ap_headers
ANY.h
aper_decoder.h
aper_encoder.h
aper_opentype.h
aper_support.h
asn_application.h
asn_bit_data.h
asn_codecs.h
asn_codecs_prim.h
asn_config.h
asn_internal.h
asn_ioc.h
asn_random_fill.h
asn_SEQUENCE_OF.h
asn_SET_OF.h
asn_system.h
ber_decoder.h
ber_tlv_length.h
ber_tlv_tag.h
BIT_STRING.h
@@ -191,7 +254,7 @@ set(m2ap_headers
constr_SEQUENCE_OF.h
constr_SET_OF.h
constr_TYPE.h
der_encoder.h
GraphicString.h
INTEGER.h
M2AP_Active-MBMS-Session-List.h
M2AP_AllocatedSubframesEnd.h
@@ -224,6 +287,7 @@ set(m2ap_headers
M2AP_ENBname.h
M2AP_ErrorIndication.h
M2AP_EUTRANCellIdentifier.h
M2AP_EXTERNAL.h
M2AP_GBR-QosInformation.h
M2AP_GlobalENB-ID.h
M2AP_GlobalMCE-ID.h
@@ -329,6 +393,7 @@ set(m2ap_headers
M2AP_UnsuccessfulOutcome.h
NativeEnumerated.h
NativeInteger.h
ObjectDescriptor.h
OBJECT_IDENTIFIER.h
OCTET_STRING.h
OPEN_TYPE.h
@@ -337,6 +402,10 @@ set(m2ap_headers
per_opentype.h
per_support.h
PrintableString.h
uper_decoder.h
uper_encoder.h
uper_opentype.h
uper_support.h
xer_decoder.h
xer_encoder.h
xer_support.h
+1 -1
View File
@@ -19,7 +19,7 @@ else()
endif()
add_custom_command(OUTPUT ${m2ap_source} ${m2ap_headers}
COMMAND ASN1C_PREFIX=M2AP_ asn1c -gen-PER -no-gen-OER -fcompound-names -no-gen-example -fno-include-deps -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${M2AP_GRAMMAR}
COMMAND ASN1C_PREFIX=M2AP_ ${ASN1C_EXEC} -gen-APER -no-gen-BER -no-gen-JER -no-gen-OER -gen-UPER -fcompound-names -no-gen-example -fno-include-deps -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${M2AP_GRAMMAR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${M2AP_GRAMMAR}
COMMENT "Generating M2AP source files from ${CMAKE_CURRENT_SOURCE_DIR}/${M2AP_GRAMMAR}"
)
-697
View File
@@ -1,697 +0,0 @@
import re, os, sys, string
import datetime
import getopt
import getpass
version = "1.0.2"
lines = ""
iesDefs = {}
ieofielist = {}
outdir = './'
filenames = []
verbosity = 0
prefix = ""
FAIL = '\033[91m'
WARN = '\033[93m'
ENDC = '\033[0m'
fileprefix = ""
fileprefix_first_upper = ""
def printFail(string):
sys.stderr.write(FAIL + string + ENDC + "\n")
def printWarning(string):
print WARN + string + ENDC
def printDebug(string):
if verbosity > 0:
print string
def outputHeaderToFile(f, filename):
now = datetime.datetime.now()
f.write("""/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
""")
f.write("/*******************************************************************************\n")
f.write(" * This file had been created by asn1tostruct.py script v%s\n" % (version))
f.write(" * Please do not modify this file but regenerate it via script.\n")
f.write(" * Created on: %s by %s\n * from %s\n" % (str(now), getpass.getuser(), filenames))
f.write(" ******************************************************************************/\n")
def lowerFirstCamelWord(word):
""" puts the first word in a CamelCase Word in lowercase.
I.e. CustomerID becomes customerID, XMLInfoTest becomes xmlInfoTest
"""
newstr = ''
swapped = word.swapcase()
idx = 0
# if it's all-caps, return an all-lowered version
lowered = word.lower()
if swapped == lowered:
return lowered
for c in swapped:
if c in string.lowercase:
newstr += c
idx += 1
else:
break
if idx < 2:
newstr += word[idx:]
else:
newstr = newstr[:-1]+ word[idx-1:]
return newstr
def usage():
print "Python parser for asn1 v%s" % (version)
print "Usage: python asn1tostruct.py [options]"
print "Available options:"
print "-d Enable script debug"
print "-f [file] Input file to parse"
print "-o [dir] Output files to given directory"
print "-h Print this help and return"
try:
opts, args = getopt.getopt(sys.argv[1:], "df:ho:", ["debug", "file", "help", "outdir"])
except getopt.GetoptError as err:
# print help information and exit:
usage()
sys.exit(2)
for o, a in opts:
if o in ("-f", "--file"):
filenames.append(a)
if o in ("-d", "--debug"):
verbosity = 1
if o in ("-o", "--outdir"):
outdir = a
if outdir.rfind('/') != len(outdir):
outdir += '/'
if o in ("-h", "--help"):
usage()
sys.exit(2)
for filename in filenames:
file = open(filename, 'r')
for line in file:
# Removing any comment
if line.find('--') >= 0:
line = line[:line.find('--')]
# Removing any carriage return
lines += re.sub('\r', '', line)
for m in re.findall(r'([a-zA-Z0-9-]+)\s*::=\s+SEQUENCE\s+\(\s*SIZE\s*\(\s*\d+\s*\.\.\s*[0-9a-zA-Z-]+\s*\)\s*\)\s*OF\s+[a-zA-Z-]+\s*\{\s*\{\s*([0-9a-zA-Z-]+)\s*\}\s*\}', lines, re.MULTILINE):
ieofielist[m[0]] = m[1]
for m in re.findall(r'([a-zA-Z0-9-]+)\s*::=\s+E-RAB-IE-ContainerList\s*\{\s*\{\s*([a-zA-Z0-9-]+)\s*\}\s*\}', lines, re.MULTILINE):
ieofielist[m[0]] = m[1]
for i in re.findall(r'([a-zA-Z0-9-]+)\s+([A-Z0-9-]+)\s*::=\s*\{\s+([\,\|\{\}\t\n\.{3}\ \-a-zA-Z0-9]+)\s+}\n', lines, re.MULTILINE):
ies = []
maxLength = 0
# TODO: handle extensions
if i[1].find('EXTENSION') >= 0:
continue
if fileprefix == "":
fileprefix = i[1][:i[1].find('-')].lower()
for j in re.findall(r'\s*\{\s*([a-zA-Z0-9-\ \t]+)\s*\}\s*[\|,]*', i[2], re.MULTILINE):
for k in re.findall(r'ID\s*([a-zA-Z0-9\-]+)\s*CRITICALITY\s*([a-zA-Z0-9\-]+)\s+[A-Z]+\s+([a-zA-Z0-9\-]+)\s*PRESENCE\s*([a-zA-Z0-9\-]+)', j, re.MULTILINE):
printDebug("Got new ie for message " + i[0] + ": " + str(k))
if len(k[2]) > maxLength:
maxLength = len(k[2])
ies.append(k)
if len(ies) > 0:
iesDefs[i[0]] = { "length": maxLength, "ies": ies }
else:
printWarning("Didn't find any information element for message: " + i[0])
if len(iesDefs) == 0:
printFail("No Information Element parsed, exiting")
sys.exit(0)
fileprefix_first_upper = fileprefix[0].upper() + fileprefix[1:]
f = open(outdir + fileprefix + '_ies_defs.h', 'w')
outputHeaderToFile(f, filename)
f.write("#include \"%s_common.h\"\n\n" % (fileprefix))
f.write("#ifndef %s_IES_DEFS_H_\n#define %s_IES_DEFS_H_\n\n" % (fileprefix.upper(), fileprefix.upper()))
f.write("/* Define the version of script used to generate this file */\n")
f.write("#define %s_SCRIPT_VERSION (%s)\n\n" % (fileprefix.upper(), re.sub('\.', '', version)))
for key in iesDefs:
if key not in ieofielist.values():
continue
for (i, j) in ieofielist.items():
if j == key:
break
f.write("typedef struct %sIEs_s {\n" % (re.sub('-', '_', i)))
f.write(" A_SEQUENCE_OF(struct %s_s) %s;\n" % (re.sub('IEs', '', re.sub('-', '_', ieofielist[i])), lowerFirstCamelWord(re.sub('IEs', '', re.sub('-', '_', ieofielist[i])))))
f.write("} %sIEs_t;\n\n" % (re.sub('-', '_', i)))
for key in iesDefs:
keyupperunderscore = re.sub('-', '_', key.upper())
keylowerunderscore = re.sub('-', '_', key.lower())
shift = 0
if len(iesDefs[key]["ies"]) == 0:
continue
# Presence mask
for ie in iesDefs[key]["ies"]:
ieupperunderscore = re.sub('-', '_', re.sub('id-', '', ie[0])).upper()
if ie[3] == "optional" or ie[3] == "conditional":
f.write("#define {0:<{pad}} {1}\n".format("%s_%s_PRESENT" % (keyupperunderscore, ieupperunderscore), "(1 << %d)" % shift,
pad=iesDefs[key]["length"] + len(keyupperunderscore) + 9))
shift += 1
if (shift > 0):
f.write("\n")
f.write("typedef struct %s_s {\n" % (re.sub('-', '_', key)))
if (shift > 0):
f.write(" {0:<{pad}} {1};\n".format("uint16_t", "presenceMask", pad=iesDefs[key]["length"] + 2))
for ie in iesDefs[key]["ies"]:
ieunderscore = re.sub('-', '_', ie[2])
iename = re.sub('id-', '', ie[0])
ienameunderscore = lowerFirstCamelWord(re.sub('-', '_', iename))
if ie[2] in ieofielist:
f.write(" %sIEs_t %s;" % (re.sub('-', '_', ie[2]), ienameunderscore))
else:
f.write(" {0:<{pad}} {1};".format("%s_t" % ieunderscore, ienameunderscore, pad=iesDefs[key]["length"] + 2))
if ie[3] == "optional":
f.write(" ///< Optional field")
elif ie[3] == "conditional":
f.write(" ///< Conditional field")
f.write("\n")
f.write("} %s_t;\n\n" % (re.sub('-', '_', key)))
f.write("typedef struct %s_message_s {\n" % (fileprefix))
f.write(" %s_ProcedureCode_t procedureCode;\n" % (fileprefix_first_upper))
f.write(" %s_Criticality_t criticality;\n" % (fileprefix_first_upper))
f.write(" uint8_t direction;\n")
f.write(" union {\n")
messageList = iesDefs.keys()
messageList.sort()
for message in messageList:
if message in ieofielist.values():
continue
if len(iesDefs[message]["ies"]) == 0:
continue
f.write(" %s_t %s;\n" % (re.sub('-', '_', message), lowerFirstCamelWord(re.sub('-', '_', message))))
f.write(" } msg;\n")
f.write("} %s_message;\n\n" % (fileprefix))
for key in iesDefs:
if key in ieofielist.values():
continue
structName = re.sub('ies', '', key)
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', re.sub('-IEs', '', key)))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
keylowerunderscore = re.sub('-', '_', key.lower())
firstlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
f.write("/** \\brief Decode function for %s ies.\n" % (key))
if len(iesDefs[key]["ies"]) != 0:
f.write(" * \\param %s Pointer to ASN1 structure in which data will be stored\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" * \\param any_p Pointer to the ANY value to decode.\n")
f.write(" **/\n")
f.write("int %s_decode_%s(\n" % (fileprefix, keylowerunderscore))
if len(iesDefs[key]["ies"]) != 0:
f.write(" %s_t *%s,\n" % (re.sub('-', '_', key), lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" ANY_t *any_p);\n\n")
if len(iesDefs[key]["ies"]) == 0:
continue
f.write("/** \\brief Encode function for %s ies.\n" % (key))
f.write(" * \\param %s Pointer to the ASN1 structure.\n" % (firstlower))
f.write(" * \\param %s Pointer to the IES structure.\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" **/\n")
f.write("int %s_encode_%s(\n" % (fileprefix, re.sub('-', '_', structName.lower())))
f.write(" %s_t *%s,\n" % (asn1cStruct, firstlower))
f.write(" %s_t *%s);\n\n" % (re.sub('-', '_', key), lowerFirstCamelWord(re.sub('-', '_', key))))
for key in iesDefs:
if key not in ieofielist.values():
continue
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', key))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
firstlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
f.write("/** \\brief Encode function for %s ies.\n" % (key))
f.write(" * \\param %s Pointer to the ASN1 structure.\n" % (firstlower))
f.write(" * \\param %s Pointer to the IES structure.\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" **/\n")
f.write("int %s_encode_%s(\n" % (fileprefix, firstlower.lower()))
f.write(" %s_t *%s,\n" % (asn1cStruct, firstlower))
f.write(" %sIEs_t *%sIEs);\n\n" % (asn1cStruct, firstlower))
f.write("/** \\brief Decode function for %s ies.\n" % (key))
f.write(" * \\param any_p Pointer to the ANY value to decode.\n")
f.write(" * \\param callback Callback function called when any_p is successfully decoded.\n")
f.write(" **/\n")
f.write("int %s_decode_%s(\n" % (fileprefix, firstlower.lower()))
f.write(" %sIEs_t *%sIEs,\n" % (asn1cStruct, firstlower))
f.write(" %s_t *%s);\n\n" % (asn1cStruct, lowerFirstCamelWord(asn1cStruct)))
for key in iesDefs:
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', key))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
firstlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
if key in ieofielist.values():
f.write("/** \\brief Display %s encapsulated IE using XER encoding.\n" % (asn1cStruct))
f.write(" * \\param %s Pointer to the IES structure.\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" * \\param file File descriptor to write output.\n")
f.write(" **/\n")
f.write("asn_enc_rval_t %s_xer_print_%s(\n" % (fileprefix, re.sub('item', 'list', firstlower.lower())))
f.write(" asn_app_consume_bytes_f *cb,\n")
f.write(" void *app_key,\n")
f.write(" %sIEs_t *%sIEs);\n\n" % (re.sub('item', 'list', asn1cStruct), firstlower))
else:
f.write("/** \\brief Display %s message using XER encoding.\n" % (asn1cStruct))
f.write(" * \\param message_p Pointer to root message.\n")
f.write(" * \\param file File descriptor to write output.\n")
f.write(" **/\n")
f.write("asn_enc_rval_t %s_xer_print_%s(\n" % (fileprefix, firstlower.lower()))
f.write(" asn_app_consume_bytes_f *cb,\n")
f.write(" void *app_key,\n")
f.write(" %s_message *message_p);\n\n" % (fileprefix))
f.write("int %s_xer__print2sp(const void *buffer, size_t size, void *app_key);\n\n" % (fileprefix.lower()))
f.write("int %s_xer__print2fp(const void *buffer, size_t size, void *app_key);\n\n" % (fileprefix.lower()))
f.write("extern size_t %s_string_total_size;\n\n" % (fileprefix.lower()))
f.write("#endif /* %s_IES_DEFS_H_ */\n\n" % (fileprefix.upper()))
#Generate Decode functions
f = open(outdir + fileprefix + '_decoder.c', 'w')
outputHeaderToFile(f, filename)
f.write("#include \"%s_common.h\"\n#include \"%s_ies_defs.h\"\n\n" % (fileprefix, fileprefix))
for key in iesDefs:
if key in ieofielist.values():
continue
structName = re.sub('ies', '', key)
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', key))
if asn1cStruct.rfind('_') == len(asn1cStruct) - 1:
asn1cStruct = asn1cStruct[:-1]
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
ielistname = re.sub('UE', 'ue', asn1cStruct)
ielistnamefirstlower = ielistname[:1].lower() + ielistname[1:]
asn1cStructfirstlower = asn1cStruct[:1].lower() + asn1cStruct[1:]
keyName = re.sub('-', '_', key)
keyupperunderscore = keyName.upper()
firstlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
iesaccess = ""
if key not in ieofielist.values():
iesaccess = "%s_ies." % (firstlower)
f.write("int %s_decode_%s(\n" % (fileprefix, re.sub('-', '_', structName.lower())))
if len(iesDefs[key]["ies"]) != 0:
f.write(" %s_t *%s,\n" % (re.sub('-', '_', key), lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" ANY_t *any_p) {\n\n")
f.write(" %s_t %s;\n %s_t *%s_p = &%s;\n" % (asn1cStruct, asn1cStructfirstlower, asn1cStruct, asn1cStructfirstlower, asn1cStructfirstlower))
f.write(" int i, decoded = 0;\n")
if len(iesDefs[key]["ies"]) != 0:
f.write(" int tempDecoded = 0;\n")
f.write(" assert(any_p != NULL);\n")
if len(iesDefs[key]["ies"]) != 0:
f.write(" assert(%s != NULL);\n\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" %s_DEBUG(\"Decoding message %s (%%s:%%d)\\n\", __FILE__, __LINE__);\n\n" % (fileprefix.upper(), re.sub('-', '_', keyName)))
f.write(" ANY_to_type_aper(any_p, &asn_DEF_%s, (void**)&%s_p);\n\n" % (asn1cStruct, asn1cStructfirstlower))
f.write(" for (i = 0; i < %s_p->%slist.count; i++) {\n" % (asn1cStructfirstlower, iesaccess))
f.write(" %s_IE_t *ie_p;\n" % (fileprefix[0].upper() + fileprefix[1:]))
f.write(" ie_p = %s_p->%slist.array[i];\n" % (asn1cStructfirstlower, iesaccess))
f.write(" switch(ie_p->id) {\n")
for ie in iesDefs[key]["ies"]:
iename = re.sub('id-', '', ie[0])
ienameunderscore = lowerFirstCamelWord(re.sub('-', '_', iename))
ienameunderscorefirstlower = lowerFirstCamelWord(ienameunderscore)
ietypesubst = re.sub('-', '', ie[2])
ietypeunderscore = re.sub('-', '_', ie[2])
ieupperunderscore = re.sub('-', '_', re.sub('id-', '', ie[0])).upper()
if ie[3] == "optional":
f.write(" /* Optional field */\n")
elif ie[3] == "conditional":
f.write(" /* Conditional field */\n")
f.write(" case %s_ProtocolIE_ID_%s:\n" % (fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" {\n")
f.write(" %s_t *%s_p = NULL;\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
if ie[3] != "mandatory":
f.write(" %s->presenceMask |= %s_%s_PRESENT;\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), keyupperunderscore, ieupperunderscore))
f.write(" tempDecoded = ANY_to_type_aper(&ie_p->value, &asn_DEF_%s, (void**)&%s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" if (tempDecoded < 0 || %s_p == NULL) {\n" % (lowerFirstCamelWord(ietypesubst)))
f.write(" %s_ERROR(\"Decoding of IE %s failed\\n\");\n" % (fileprefix.upper(), ienameunderscore))
f.write(" if (%s_p)\n" % (lowerFirstCamelWord(ietypesubst)))
f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" decoded += tempDecoded;\n")
f.write(" if (asn1_xer_print)\n")
f.write(" xer_fprint(stdout, &asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
if ie[2] in ieofielist.keys():
f.write(" if (%s_decode_%s(&%s->%s, %s_p) < 0) {\n" % (fileprefix, ietypeunderscore.lower(), lowerFirstCamelWord(re.sub('-', '_', key)), ienameunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" %s_ERROR(\"Decoding of encapsulated IE %s failed\\n\");\n" % (fileprefix.upper(), lowerFirstCamelWord(ietypesubst)))
f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" }\n")
else:
f.write(" memcpy(&%s->%s, %s_p, sizeof(%s_t));\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), ienameunderscore, lowerFirstCamelWord(ietypesubst), ietypeunderscore))
#f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" } break;\n")
f.write(" default:\n")
f.write(" %s_ERROR(\"Unknown protocol IE id (%%d) for message %s\\n\", (int)ie_p->id);\n" % (fileprefix.upper(), re.sub('-', '_', structName.lower())))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" }\n")
f.write(" return decoded;\n")
f.write("}\n\n")
for key in iesDefs:
if key not in ieofielist.values():
continue
keyname = re.sub('IEs', '', re.sub('Item', 'List', key))
f.write("int %s_decode_%s(\n" % (fileprefix, re.sub('-', '_', keyname).lower()))
f.write(" %sIEs_t *%sIEs,\n" % (re.sub('-', '_', keyname), lowerFirstCamelWord(re.sub('-', '_', keyname))))
f.write(" %s_t *%s) {\n\n" % (re.sub('-', '_', keyname), lowerFirstCamelWord(re.sub('-', '_', keyname))))
f.write(" int i, decoded = 0;\n")
f.write(" int tempDecoded = 0;\n\n")
f.write(" assert(%s != NULL);\n" % (lowerFirstCamelWord(re.sub('-', '_', keyname))));
f.write(" assert(%sIEs != NULL);\n\n" % (lowerFirstCamelWord(re.sub('-', '_', keyname))));
f.write(" for (i = 0; i < %s->list.count; i++) {\n" % (lowerFirstCamelWord(re.sub('-', '_', keyname))))
f.write(" %s_IE_t *ie_p = %s->list.array[i];\n" % (fileprefix[0].upper() + fileprefix[1:], lowerFirstCamelWord(re.sub('-', '_', keyname))))
f.write(" switch (ie_p->id) {\n")
for ie in iesDefs[key]["ies"]:
iename = re.sub('id-', '', ie[0])
ienameunderscore = lowerFirstCamelWord(re.sub('-', '_', iename))
f.write(" case %s_ProtocolIE_ID_%s:\n" % (fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" {\n")
f.write(" %s_t *%s_p = NULL;\n" % (re.sub('-', '_', ie[2]), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" tempDecoded = ANY_to_type_aper(&ie_p->value, &asn_DEF_%s, (void**)&%s_p);\n" % (re.sub('-', '_', ie[2]), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" if (tempDecoded < 0 || %s_p == NULL) {\n" % (lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" %s_ERROR(\"Decoding of IE %s for message %s failed\\n\");\n" % (fileprefix.upper(), ienameunderscore, re.sub('-', '_', keyname)))
f.write(" if (%s_p)\n" % (lowerFirstCamelWord(re.sub('-', '', ie[2]))))
#f.write(" free(%s_p);\n" % (lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (re.sub('-', '_', ie[2]), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" decoded += tempDecoded;\n")
f.write(" if (asn1_xer_print)\n")
f.write(" xer_fprint(stdout, &asn_DEF_%s, %s_p);\n" % (re.sub('-', '_', ie[2]), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" ASN_SEQUENCE_ADD(&%sIEs->%s, %s_p);\n" % (lowerFirstCamelWord(re.sub('-', '_', keyname)),
re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key))), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" } break;\n")
f.write(" default:\n")
f.write(" %s_ERROR(\"Unknown protocol IE id (%%d) for message %s\\n\", (int)ie_p->id);\n" % (fileprefix.upper(), re.sub('-', '_', structName.lower())))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" }\n")
f.write(" return decoded;\n")
f.write("}\n\n")
#Generate IES Encode functions
f = open(outdir + fileprefix + '_encoder.c', 'w')
outputHeaderToFile(f,filename)
f.write("#include \"%s_common.h\"\n" % (fileprefix))
f.write("#include \"%s_ies_defs.h\"\n\n" % (fileprefix))
for key in iesDefs:
if key in ieofielist.values():
continue
structName = re.sub('ies', '', key)
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', key))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
if asn1cStruct.rfind('_') == len(asn1cStruct) - 1:
asn1cStruct = asn1cStruct[:-1]
asn1cStructfirstlower = asn1cStruct[:1].lower() + asn1cStruct[1:]
firstwordlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
iesaccess = ""
if key not in ieofielist.values():
iesaccess = "%s_ies." % (firstwordlower)
keyName = re.sub('-', '_', key)
keyupperunderscore = keyName.upper()
# No IE to encode...
if len(iesDefs[key]["ies"]) == 0:
continue
f.write("int %s_encode_%s(\n" % (fileprefix, re.sub('-', '_', structName.lower())))
f.write(" %s_t *%s,\n" % (asn1cStruct, firstwordlower))
f.write(" %s_t *%s) {\n\n" % (re.sub('-', '_', key), lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" %s_IE_t *ie;\n\n" % (fileprefix_first_upper))
f.write(" assert(%s != NULL);\n" % (firstwordlower));
f.write(" assert(%s != NULL);\n\n" % (lowerFirstCamelWord(re.sub('-', '_', key))));
for ie in iesDefs[key]["ies"]:
iename = re.sub('-', '_', re.sub('id-', '', ie[0]))
ienameunderscore = re.sub('-', '_', iename)
ienamefirstwordlower = lowerFirstCamelWord(iename)
ieupperunderscore = re.sub('-', '_', re.sub('id-', '', ie[0])).upper()
ietypeunderscore = re.sub('-', '_', ie[2])
if ie[3] != "mandatory":
if ie[3] == "optional":
f.write(" /* Optional field */\n")
elif ie[3] == "conditional":
f.write(" /* Conditional field */\n")
f.write(" if (%s->presenceMask & %s_%s_PRESENT) {\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), keyupperunderscore, ieupperunderscore))
#f.write(" == %s_%s_PRESENT) {\n" % (keyupperunderscore, ieupperunderscore))
f.write(" if ((ie = %s_new_ie(%s_ProtocolIE_ID_%s,\n" % (fileprefix, fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" %s_Criticality_%s,\n" % (fileprefix_first_upper, ie[1]))
f.write(" &asn_DEF_%s,\n" % (ietypeunderscore))
f.write(" &%s->%s)) == NULL) {\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), ienamefirstwordlower))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" ASN_SEQUENCE_ADD(&%s->%slist, ie);\n" % (firstwordlower, iesaccess))
f.write(" }\n\n")
else:
if ie[2] in ieofielist.keys():
f.write(" %s_t %s;\n\n" % (ietypeunderscore, ienamefirstwordlower))
f.write(" memset(&%s, 0, sizeof(%s_t));\n" % (ienamefirstwordlower, ietypeunderscore))
f.write("\n")
f.write(" if (%s_encode_%s(&%s, &%s->%s) < 0) return -1;\n" % (fileprefix, ietypeunderscore.lower(), ienamefirstwordlower, lowerFirstCamelWord(re.sub('-', '_', key)), ienamefirstwordlower))
f.write(" if ((ie = %s_new_ie(%s_ProtocolIE_ID_%s,\n" % (fileprefix, fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" %s_Criticality_%s,\n" % (fileprefix_first_upper, ie[1]))
f.write(" &asn_DEF_%s,\n" % (ietypeunderscore))
if ie[2] in ieofielist.keys():
f.write(" &%s)) == NULL) {\n" % (ienamefirstwordlower))
else:
f.write(" &%s->%s)) == NULL) {\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), ienamefirstwordlower))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" ASN_SEQUENCE_ADD(&%s->%slist, ie);\n\n" % (firstwordlower, iesaccess))
if ie[2] in ieofielist.keys():
f.write(" /* Free any dynamic allocation that is no more used */\n")
f.write(" ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_%s, &%s);\n\n" % (ietypeunderscore, ienamefirstwordlower))
f.write(" return 0;\n")
f.write("}\n\n")
for (key, value) in iesDefs.items():
if key not in ieofielist.values():
continue
ie = value["ies"][0]
ietypeunderscore = re.sub('-', '_', ie[2])
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', re.sub('-IEs', '', key)))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
firstwordlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
for (i, j) in ieofielist.items():
if j == key:
break
f.write("int %s_encode_%s(\n" % (fileprefix, re.sub('-', '_', i).lower()))
f.write(" %s_t *%s,\n" % (asn1cStruct, firstwordlower))
f.write(" %sIEs_t *%sIEs) {\n\n" % (re.sub('-', '_', i), lowerFirstCamelWord(re.sub('-', '_', i))))
f.write(" int i;\n")
f.write(" %s_IE_t *ie;\n\n" % (fileprefix_first_upper))
f.write(" assert(%s != NULL);\n" % (firstwordlower));
f.write(" assert(%sIEs != NULL);\n\n" % (lowerFirstCamelWord(re.sub('-', '_', i))));
f.write(" for (i = 0; i < %sIEs->%s.count; i++) {\n" % (firstwordlower, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
f.write(" if ((ie = %s_new_ie(%s_ProtocolIE_ID_%s,\n" % (fileprefix, fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" %s_Criticality_%s,\n" % (fileprefix_first_upper, ie[1]))
f.write(" &asn_DEF_%s,\n" % (ietypeunderscore))
f.write(" %sIEs->%s.array[i])) == NULL) {\n" % (firstwordlower, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" ASN_SEQUENCE_ADD(&%s->list, ie);\n" % (firstwordlower))
f.write(" }\n")
f.write(" return 0;\n")
f.write("}\n\n")
#Generate xer print functions
f = open(outdir + fileprefix + '_xer_print.c', 'w')
outputHeaderToFile(f, filename)
f.write("#include <stdlib.h>\n")
f.write("#include <stdio.h>\n\n")
f.write("#include <asn_application.h>\n#include <asn_internal.h>\n\n")
f.write("#include \"%s_common.h\"\n#include \"%s_ies_defs.h\"\n\n" % (fileprefix, fileprefix))
f.write("size_t %s_string_total_size = 0;\n\n" % (fileprefix.lower()))
f.write("""int
%s_xer__print2fp(const void *buffer, size_t size, void *app_key) {
FILE *stream = (FILE *)app_key;
if(fwrite(buffer, 1, size, stream) != size)
return -1;
return 0;
}
""" % (fileprefix.lower()))
f.write("""int %s_xer__print2sp(const void *buffer, size_t size, void *app_key) {
char *string = (char *)app_key;
/* Copy buffer to the formatted string */
memcpy(&string[%s_string_total_size], buffer, size);
%s_string_total_size += size;
return 0;
}
""" % (fileprefix.lower(), fileprefix.lower(), fileprefix.lower()))
f.write("""static asn_enc_rval_t
xer_encode_local(asn_TYPE_descriptor_t *td, void *sptr,
asn_app_consume_bytes_f *cb, void *app_key, int indent) {
asn_enc_rval_t er, tmper;
const char *mname;
size_t mlen;
int xcan = 2;
if(!td || !sptr) goto cb_failed;
mname = td->xml_tag;
mlen = strlen(mname);
_i_ASN_TEXT_INDENT(0, indent);
_ASN_CALLBACK3("<", 1, mname, mlen, ">", 1);
tmper = td->xer_encoder(td, sptr, indent + 1, XER_F_BASIC, cb, app_key);
if(tmper.encoded == -1) return tmper;
_ASN_CALLBACK3("</", 2, mname, mlen, ">\\n", xcan);
er.encoded = 4 + xcan + (2 * mlen) + tmper.encoded;
_ASN_ENCODED_OK(er);
cb_failed:
_ASN_ENCODE_FAILED;
}
""")
for (key, value) in iesDefs.items():
keyName = re.sub('-', '_', key)
keyupperunderscore = keyName.upper()
iesStructName = lowerFirstCamelWord(re.sub('-', '_', key))
ie = value["ies"][0]
ietypeunderscore = re.sub('-', '_', ie[2])
if key in ieofielist.values():
f.write("asn_enc_rval_t %s_xer_print_%s(\n" % (fileprefix, re.sub('ies', '', re.sub('item', 'list', re.sub('-', '_', key).lower()))))
else:
f.write("asn_enc_rval_t %s_xer_print_%s(\n" % (fileprefix, re.sub('ies', '', re.sub('-', '_', key).lower())))
#f.write(" FILE *file,\n")
f.write(" asn_app_consume_bytes_f *cb,\n")
f.write(" void *app_key,\n")
if key in ieofielist.values():
iesStructName = lowerFirstCamelWord(re.sub('Item', 'List', re.sub('-', '_', key)))
f.write(" %sIEs_t *%s) {\n\n" % (re.sub('IEs', '', re.sub('Item', 'List', re.sub('-', '_', key))), iesStructName))
f.write(" int i;\n")
f.write(" asn_enc_rval_t er;\n")
else:
f.write(" %s_message *message_p)\n{\n" % (fileprefix))
f.write(" %s_t *%s;\n" % (re.sub('-', '_', key), iesStructName))
f.write(" asn_enc_rval_t er;\n")
#f.write(" void *app_key = (void *)file;\n")
#f.write(" asn_app_consume_bytes_f *cb = %s_xer__print2fp;\n\n" % (fileprefix.lower()))
f.write(" %s = &message_p->msg.%s;\n\n" % (iesStructName, iesStructName))
if key in ieofielist.values():
# Increase indentation level
f.write(" for (i = 0; i < %s->%s.count; i++) {\n" % (iesStructName, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
#f.write(" xer_fprint(file, &asn_DEF_%s, %s->%s.array[i]);\n" % (ietypeunderscore, iesStructName, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
f.write(" er = xer_encode(&asn_DEF_%s, %s->%s.array[i], XER_F_BASIC, cb, app_key);\n" % (ietypeunderscore, iesStructName, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
f.write(" }\n")
else:
f.write(" cb(\"<%s-PDU>\\n\", %d, app_key);\n" % (key, len("<%s-PDU>\n" % (key))))
f.write(" xer_encode_local(&asn_DEF_%s_Criticality, &message_p->criticality, cb, app_key, 1);\n" % fileprefix_first_upper)
f.write(" xer_encode_local(&asn_DEF_%s_ProcedureCode, &message_p->procedureCode, cb, app_key, 1);\n" % fileprefix_first_upper)
f.write(" cb(\" <%s>\\n\", %d, app_key);\n" % (key, len(" <%s>\n" % (key))))
for ie in iesDefs[key]["ies"]:
iename = re.sub('-', '_', re.sub('id-', '', ie[0]))
ienameunderscore = re.sub('-', '_', iename)
ienamefirstwordlower = lowerFirstCamelWord(iename)
ietypeunderscore = re.sub('-', '_', ie[2])
ieupperunderscore = re.sub('-', '_', re.sub('id-', '', ie[0])).upper()
if ie[3] != "mandatory":
if ie[3] == "optional":
f.write(" /* Optional field */\n")
elif ie[3] == "conditional":
f.write(" /* Conditional field */\n")
f.write(" if (%s->presenceMask & %s_%s_PRESENT)\n " % (iesStructName, keyupperunderscore, ieupperunderscore))
# Is it an encapsulated IE ?
if ie[2] in ieofielist.keys():
f.write(" %s_xer_print_%s(cb, app_key, &%s->%s);\n" % (fileprefix, re.sub('ies', '', re.sub('-', '_', ie[2]).lower()), iesStructName, ienamefirstwordlower))
else:
f.write(" xer_encode_local(&asn_DEF_%s, &%s->%s, cb, app_key, 2);\n" % (ietypeunderscore, iesStructName, ienamefirstwordlower))
f.write(" cb(\" </%s>\\n\", %d, app_key);\n" % (key, len(" </%s>\n" % (key))))
f.write(" cb(\"</%s-PDU>\\n\", %d, app_key);\n" % (key, len("</%s-PDU>\n" % (key))))
f.write(" _ASN_ENCODED_OK(er);\n")
#if key not in ieofielist.values():
#f.write("cb_failed:\n")
#f.write(" return er;\n")
f.write("}\n\n")
+1
View File
@@ -44,6 +44,7 @@
#include "rrc_eNB_UE_context.h"
#include "pdcp.h"
#include "common/ran_context.h"
#include "uper_encoder.h"
#include "intertask_interface.h"
@@ -1,26 +1,66 @@
set(LTE_RRC_GRAMMAR ASN.1/lte-rrc-15.6.0.asn1)
set(lte_rrc_source
ANY_aper.c
ANY.c
ANY_uper.c
ANY_xer.c
aper_decoder.c
aper_encoder.c
aper_opentype.c
aper_support.c
asn_application.c
asn_bit_data.c
asn_codecs_prim.c
asn_codecs_prim_xer.c
asn_internal.c
asn_random_fill.c
asn_SEQUENCE_OF.c
asn_SET_OF.c
ber_decoder.c
ber_tlv_length.c
ber_tlv_tag.c
BIT_STRING.c
BIT_STRING_print.c
BIT_STRING_rfill.c
BIT_STRING_uper.c
BIT_STRING_xer.c
BOOLEAN_aper.c
BOOLEAN.c
BOOLEAN_print.c
BOOLEAN_rfill.c
BOOLEAN_uper.c
BOOLEAN_xer.c
constraints.c
constr_CHOICE_aper.c
constr_CHOICE.c
constr_CHOICE_print.c
constr_CHOICE_rfill.c
constr_CHOICE_uper.c
constr_CHOICE_xer.c
constr_SEQUENCE_aper.c
constr_SEQUENCE.c
constr_SEQUENCE_OF_aper.c
constr_SEQUENCE_OF.c
constr_SEQUENCE_OF_uper.c
constr_SEQUENCE_OF_xer.c
constr_SEQUENCE_print.c
constr_SEQUENCE_rfill.c
constr_SEQUENCE_uper.c
constr_SEQUENCE_xer.c
constr_SET_OF_aper.c
constr_SET_OF.c
constr_SET_OF_print.c
constr_SET_OF_rfill.c
constr_SET_OF_uper.c
constr_SET_OF_xer.c
constr_TYPE.c
der_encoder.c
GraphicString.c
INTEGER_aper.c
INTEGER.c
INTEGER_print.c
INTEGER_rfill.c
INTEGER_uper.c
INTEGER_xer.c
LTE_AB-Config-NB-r13.c
LTE_AB-ConfigPLMN-NB-r13.c
LTE_AbsoluteTimeInfo-r10.c
@@ -497,6 +537,7 @@ set(lte_rrc_source
LTE_EUTRA-5GC-Parameters-r15.c
LTE_EUTRA-CarrierList-r15.c
LTE_ExplicitListOfARFCNs.c
LTE_EXTERNAL.c
LTE_FailedLogicalChannelInfo-r15.c
LTE_FailureInformation-r15.c
LTE_FailureReportSCG-NR-r15.c
@@ -2387,32 +2428,67 @@ set(lte_rrc_source
LTE_WUS-MaxDurationFactor-NB-r15.c
LTE_ZeroTxPowerCSI-RS-Conf-r12.c
LTE_ZeroTxPowerCSI-RS-r12.c
NativeEnumerated_aper.c
NativeEnumerated.c
NativeEnumerated_uper.c
NativeEnumerated_xer.c
NativeInteger_aper.c
NativeInteger.c
NativeInteger_print.c
NativeInteger_rfill.c
NativeInteger_uper.c
NativeInteger_xer.c
NULL_aper.c
NULL.c
NULL_print.c
NULL_rfill.c
NULL_uper.c
NULL_xer.c
ObjectDescriptor.c
OBJECT_IDENTIFIER.c
OBJECT_IDENTIFIER_print.c
OBJECT_IDENTIFIER_rfill.c
OBJECT_IDENTIFIER_xer.c
OCTET_STRING_aper.c
OCTET_STRING.c
OCTET_STRING_print.c
OCTET_STRING_rfill.c
OCTET_STRING_uper.c
OCTET_STRING_xer.c
OPEN_TYPE_aper.c
OPEN_TYPE.c
OPEN_TYPE_uper.c
OPEN_TYPE_xer.c
per_decoder.c
per_encoder.c
per_opentype.c
per_support.c
uper_decoder.c
uper_encoder.c
uper_opentype.c
uper_support.c
xer_decoder.c
xer_encoder.c
xer_support.c
)
set(lte_rrc_headers
ANY.h
aper_decoder.h
aper_encoder.h
aper_opentype.h
aper_support.h
asn_application.h
asn_bit_data.h
asn_codecs.h
asn_codecs_prim.h
asn_config.h
asn_internal.h
asn_ioc.h
asn_random_fill.h
asn_SEQUENCE_OF.h
asn_SET_OF.h
asn_system.h
ber_decoder.h
ber_tlv_length.h
ber_tlv_tag.h
BIT_STRING.h
@@ -2423,7 +2499,7 @@ set(lte_rrc_headers
constr_SEQUENCE_OF.h
constr_SET_OF.h
constr_TYPE.h
der_encoder.h
GraphicString.h
INTEGER.h
LTE_AB-Config-NB-r13.h
LTE_AB-ConfigPLMN-NB-r13.h
@@ -2902,6 +2978,7 @@ set(lte_rrc_headers
LTE_EUTRA-5GC-Parameters-r15.h
LTE_EUTRA-CarrierList-r15.h
LTE_ExplicitListOfARFCNs.h
LTE_EXTERNAL.h
LTE_FailedLogicalChannelInfo-r15.h
LTE_FailureInformation-r15.h
LTE_FailureReportSCG-NR-r15.h
@@ -4795,12 +4872,18 @@ set(lte_rrc_headers
NativeEnumerated.h
NativeInteger.h
NULL.h
ObjectDescriptor.h
OBJECT_IDENTIFIER.h
OCTET_STRING.h
OPEN_TYPE.h
per_decoder.h
per_encoder.h
per_opentype.h
per_support.h
uper_decoder.h
uper_encoder.h
uper_opentype.h
uper_support.h
xer_decoder.h
xer_encoder.h
xer_support.h
+1 -1
View File
@@ -9,7 +9,7 @@ else()
endif()
add_custom_command(OUTPUT ${lte_rrc_source} ${lte_rrc_headers}
COMMAND ASN1C_PREFIX=LTE_ asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${LTE_RRC_GRAMMAR}
COMMAND ASN1C_PREFIX=LTE_ ${ASN1C_EXEC} -pdu=all -fcompound-names -gen-UPER -no-gen-BER -no-gen-JER -no-gen-OER -gen-APER -no-gen-example -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${LTE_RRC_GRAMMAR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${LTE_RRC_GRAMMAR}
COMMENT "Generating LTE RRC source file from ${CMAKE_CURRENT_SOURCE_DIR}/${LTE_RRC_GRAMMAR}"
)
+1 -1
View File
@@ -25,7 +25,7 @@ You should install the asn1c utility using `./build_oai -I`.
Run
```bash
ASN1C_PREFIX=LTE_ asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example -D <dir> <asn.1-file>
ASN1C_PREFIX=LTE_ asn1c -pdu=all -fcompound-names -gen-UPER -no-gen-BER -no-gen-JER -no-gen-OER -no-gen-APER -no-gen-example -D <dir> <asn.1-file>
```
to generate the files that result from the asn.1-file. Create an `ASN.1/*.cmake` file
with the following structure:
+2 -1
View File
@@ -31,7 +31,8 @@
#define RRC_ENB_C
#include "oai_asn1.h"
#include <asn_application.h>
#include <per_encoder.h>
#include "uper_encoder.h"
#include "uper_decoder.h"
#include "rrc_defs.h"
#include "rrc_extern.h"
#include "assertions.h"
+1
View File
@@ -36,6 +36,7 @@
# include "intertask_interface.h"
# include "common/ran_context.h"
#include "pdcp.h"
#include "uper_encoder.h"
extern RAN_CONTEXT_t RC;
+1
View File
@@ -47,6 +47,7 @@
#include "pdcp_primitives.h"
#include "LTE_UERadioAccessCapabilityInformation.h"
#include "uper_encoder.h"
#include "openair3/ocp-gtpu/gtp_itf.h"
#include <openair3/ocp-gtpu/gtp_itf.h>
+1
View File
@@ -25,6 +25,7 @@
#include "common/ran_context.h"
#include "oai_asn1.h"
#include "LTE_DL-DCCH-Message.h"
#include "uper_encoder.h"
#include <stdio.h>
#include <stdlib.h>
+2
View File
@@ -41,6 +41,8 @@
#include "intertask_interface.h"
#include "uper_encoder.h"
#include "NR_MIB.h"
#include "NR_BCCH-BCH-Message.h"
#include "rrc_gNB_UE_context.h"
@@ -1,28 +1,76 @@
set(NR_RRC_GRAMMAR ASN.1/nr-rrc-16.4.1.asn1)
set(nr_rrc_source
ANY_aper.c
ANY.c
ANY_uper.c
ANY_xer.c
aper_decoder.c
aper_encoder.c
aper_opentype.c
aper_support.c
asn_application.c
asn_bit_data.c
asn_codecs_prim.c
asn_codecs_prim_xer.c
asn_internal.c
asn_random_fill.c
asn_SEQUENCE_OF.c
asn_SET_OF.c
ber_decoder.c
ber_tlv_length.c
ber_tlv_tag.c
BIT_STRING.c
BIT_STRING_print.c
BIT_STRING_rfill.c
BIT_STRING_uper.c
BIT_STRING_xer.c
BOOLEAN_aper.c
BOOLEAN.c
BOOLEAN_print.c
BOOLEAN_rfill.c
BOOLEAN_uper.c
BOOLEAN_xer.c
constraints.c
constr_CHOICE_aper.c
constr_CHOICE.c
constr_CHOICE_print.c
constr_CHOICE_rfill.c
constr_CHOICE_uper.c
constr_CHOICE_xer.c
constr_SEQUENCE_aper.c
constr_SEQUENCE.c
constr_SEQUENCE_OF_aper.c
constr_SEQUENCE_OF.c
constr_SEQUENCE_OF_uper.c
constr_SEQUENCE_OF_xer.c
constr_SEQUENCE_print.c
constr_SEQUENCE_rfill.c
constr_SEQUENCE_uper.c
constr_SEQUENCE_xer.c
constr_SET_OF_aper.c
constr_SET_OF.c
constr_SET_OF_print.c
constr_SET_OF_rfill.c
constr_SET_OF_uper.c
constr_SET_OF_xer.c
constr_TYPE.c
der_encoder.c
GraphicString.c
INTEGER_aper.c
INTEGER.c
INTEGER_print.c
INTEGER_rfill.c
INTEGER_uper.c
INTEGER_xer.c
NativeEnumerated_aper.c
NativeEnumerated.c
NativeEnumerated_uper.c
NativeEnumerated_xer.c
NativeInteger_aper.c
NativeInteger.c
NativeInteger_print.c
NativeInteger_rfill.c
NativeInteger_uper.c
NativeInteger_xer.c
NR_AbsoluteTimeInfo-r16.c
NR_AccessStratumRelease.c
NR_AccessStratumReleaseSidelink-r16.c
@@ -369,6 +417,7 @@ set(nr_rrc_source
NR_EventTriggerConfigInterRAT.c
NR_EventTriggerConfigNR-SL-r16.c
NR_EventType-r16.c
NR_EXTERNAL.c
NR_FailureInfoDAPS-r16.c
NR_FailureInfoRLC-Bearer.c
NR_FailureInformation.c
@@ -1486,30 +1535,57 @@ set(nr_rrc_source
NR_ZP-CSI-RS-ResourceId.c
NR_ZP-CSI-RS-ResourceSet.c
NR_ZP-CSI-RS-ResourceSetId.c
NULL_aper.c
NULL.c
NULL_print.c
NULL_rfill.c
NULL_uper.c
NULL_xer.c
ObjectDescriptor.c
OBJECT_IDENTIFIER.c
OBJECT_IDENTIFIER_print.c
OBJECT_IDENTIFIER_rfill.c
OBJECT_IDENTIFIER_xer.c
OCTET_STRING_aper.c
OCTET_STRING.c
OCTET_STRING_print.c
OCTET_STRING_rfill.c
OCTET_STRING_uper.c
OCTET_STRING_xer.c
OPEN_TYPE_aper.c
OPEN_TYPE.c
OPEN_TYPE_uper.c
OPEN_TYPE_xer.c
per_decoder.c
per_encoder.c
per_opentype.c
per_support.c
uper_decoder.c
uper_encoder.c
uper_opentype.c
uper_support.c
xer_decoder.c
xer_encoder.c
xer_support.c
)
set(nr_rrc_headers
ANY.h
aper_decoder.h
aper_encoder.h
aper_opentype.h
aper_support.h
asn_application.h
asn_bit_data.h
asn_codecs.h
asn_codecs_prim.h
asn_config.h
asn_internal.h
asn_ioc.h
asn_random_fill.h
asn_SEQUENCE_OF.h
asn_SET_OF.h
asn_system.h
ber_decoder.h
ber_tlv_length.h
ber_tlv_tag.h
BIT_STRING.h
@@ -1520,7 +1596,7 @@ set(nr_rrc_headers
constr_SEQUENCE_OF.h
constr_SET_OF.h
constr_TYPE.h
der_encoder.h
GraphicString.h
INTEGER.h
NativeEnumerated.h
NativeInteger.h
@@ -1871,6 +1947,7 @@ set(nr_rrc_headers
NR_EventTriggerConfigInterRAT.h
NR_EventTriggerConfigNR-SL-r16.h
NR_EventType-r16.h
NR_EXTERNAL.h
NR_FailureInfoDAPS-r16.h
NR_FailureInfoRLC-Bearer.h
NR_FailureInformation.h
@@ -2989,12 +3066,18 @@ set(nr_rrc_headers
NR_ZP-CSI-RS-ResourceSet.h
NR_ZP-CSI-RS-ResourceSetId.h
NULL.h
ObjectDescriptor.h
OBJECT_IDENTIFIER.h
OCTET_STRING.h
OPEN_TYPE.h
per_decoder.h
per_encoder.h
per_opentype.h
per_support.h
uper_decoder.h
uper_encoder.h
uper_opentype.h
uper_support.h
xer_decoder.h
xer_encoder.h
xer_support.h
@@ -1,28 +1,76 @@
set(NR_RRC_GRAMMAR ASN.1/nr-rrc-17.3.0.asn1)
set(nr_rrc_source
ANY_aper.c
ANY.c
ANY_uper.c
ANY_xer.c
aper_decoder.c
aper_encoder.c
aper_opentype.c
aper_support.c
asn_application.c
asn_bit_data.c
asn_codecs_prim.c
asn_codecs_prim_xer.c
asn_internal.c
asn_random_fill.c
asn_SEQUENCE_OF.c
asn_SET_OF.c
ber_decoder.c
ber_tlv_length.c
ber_tlv_tag.c
BIT_STRING.c
BIT_STRING_print.c
BIT_STRING_rfill.c
BIT_STRING_uper.c
BIT_STRING_xer.c
BOOLEAN_aper.c
BOOLEAN.c
BOOLEAN_print.c
BOOLEAN_rfill.c
BOOLEAN_uper.c
BOOLEAN_xer.c
constraints.c
constr_CHOICE_aper.c
constr_CHOICE.c
constr_CHOICE_print.c
constr_CHOICE_rfill.c
constr_CHOICE_uper.c
constr_CHOICE_xer.c
constr_SEQUENCE_aper.c
constr_SEQUENCE.c
constr_SEQUENCE_OF_aper.c
constr_SEQUENCE_OF.c
constr_SEQUENCE_OF_uper.c
constr_SEQUENCE_OF_xer.c
constr_SEQUENCE_print.c
constr_SEQUENCE_rfill.c
constr_SEQUENCE_uper.c
constr_SEQUENCE_xer.c
constr_SET_OF_aper.c
constr_SET_OF.c
constr_SET_OF_print.c
constr_SET_OF_rfill.c
constr_SET_OF_uper.c
constr_SET_OF_xer.c
constr_TYPE.c
der_encoder.c
GraphicString.c
INTEGER_aper.c
INTEGER.c
INTEGER_print.c
INTEGER_rfill.c
INTEGER_uper.c
INTEGER_xer.c
NativeEnumerated_aper.c
NativeEnumerated.c
NativeEnumerated_uper.c
NativeEnumerated_xer.c
NativeInteger_aper.c
NativeInteger.c
NativeInteger_print.c
NativeInteger_rfill.c
NativeInteger_uper.c
NativeInteger_xer.c
NR_AbsoluteTimeInfo-r16.c
NR_AccessStratumRelease.c
NR_AccessStratumReleaseSidelink-r16.c
@@ -521,6 +569,7 @@ NR_EventTriggerConfigNR-SL-r16.c
NR_EventType-r16.c
NR_ExcessDelay-DRB-IdentityInfo-r17.c
NR_ExtendedPagingCycle-r17.c
NR_EXTERNAL.c
NR_FailureInfoDAPS-r16.c
NR_FailureInfoRLC-Bearer.c
NR_FailureInformation.c
@@ -2077,30 +2126,57 @@ NR_ZP-CSI-RS-Resource.c
NR_ZP-CSI-RS-ResourceId.c
NR_ZP-CSI-RS-ResourceSet.c
NR_ZP-CSI-RS-ResourceSetId.c
NULL_aper.c
NULL.c
NULL_print.c
NULL_rfill.c
NULL_uper.c
NULL_xer.c
ObjectDescriptor.c
OBJECT_IDENTIFIER.c
OBJECT_IDENTIFIER_print.c
OBJECT_IDENTIFIER_rfill.c
OBJECT_IDENTIFIER_xer.c
OCTET_STRING_aper.c
OCTET_STRING.c
OCTET_STRING_print.c
OCTET_STRING_rfill.c
OCTET_STRING_uper.c
OCTET_STRING_xer.c
OPEN_TYPE_aper.c
OPEN_TYPE.c
OPEN_TYPE_uper.c
OPEN_TYPE_xer.c
per_decoder.c
per_encoder.c
per_opentype.c
per_support.c
uper_decoder.c
uper_encoder.c
uper_opentype.c
uper_support.c
xer_decoder.c
xer_encoder.c
xer_support.c
)
set(nr_rrc_headers
ANY.h
aper_decoder.h
aper_encoder.h
aper_opentype.h
aper_support.h
asn_application.h
asn_bit_data.h
asn_codecs.h
asn_codecs_prim.h
asn_config.h
asn_internal.h
asn_ioc.h
asn_random_fill.h
asn_SEQUENCE_OF.h
asn_SET_OF.h
asn_system.h
ber_decoder.h
ber_tlv_length.h
ber_tlv_tag.h
BIT_STRING.h
@@ -2111,7 +2187,7 @@ constr_SEQUENCE.h
constr_SEQUENCE_OF.h
constr_SET_OF.h
constr_TYPE.h
der_encoder.h
GraphicString.h
INTEGER.h
NativeEnumerated.h
NativeInteger.h
@@ -2614,6 +2690,7 @@ NR_EventTriggerConfigNR-SL-r16.h
NR_EventType-r16.h
NR_ExcessDelay-DRB-IdentityInfo-r17.h
NR_ExtendedPagingCycle-r17.h
NR_EXTERNAL.h
NR_FailureInfoDAPS-r16.h
NR_FailureInfoRLC-Bearer.h
NR_FailureInformation.h
@@ -4171,12 +4248,18 @@ NR_ZP-CSI-RS-ResourceId.h
NR_ZP-CSI-RS-ResourceSet.h
NR_ZP-CSI-RS-ResourceSetId.h
NULL.h
ObjectDescriptor.h
OBJECT_IDENTIFIER.h
OCTET_STRING.h
OPEN_TYPE.h
per_decoder.h
per_encoder.h
per_opentype.h
per_support.h
uper_decoder.h
uper_encoder.h
uper_opentype.h
uper_support.h
xer_decoder.h
xer_encoder.h
xer_support.h
+2 -2
View File
@@ -11,7 +11,7 @@ else()
endif()
add_custom_command(OUTPUT ${nr_rrc_source} ${nr_rrc_headers}
COMMAND ASN1C_PREFIX=NR_ asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example -findirect-choice -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${NR_RRC_GRAMMAR}
COMMAND ASN1C_PREFIX=NR_ ${ASN1C_EXEC} -pdu=all -fcompound-names -gen-UPER -no-gen-BER -no-gen-JER -no-gen-OER -gen-APER -no-gen-example -findirect-choice -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${NR_RRC_GRAMMAR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${NR_RRC_GRAMMAR}
COMMENT "Generating NR RRC source file from ${CMAKE_CURRENT_SOURCE_DIR}/${NR_RRC_GRAMMAR}"
)
@@ -25,7 +25,7 @@ add_custom_command(OUTPUT ${nr_rrc_source} ${nr_rrc_headers}
# recommended way, see https://gitlab.kitware.com/cmake/cmake/-/issues/17366.
# In newer cmake version (e.g., 3.20), it is also possible to have
# ${nr_rrc_headers} directly in the add_library(asn1_nr_rrc_hdrs) statement,
# without the need for asn1_lte_rrc_hdrs
# without the need for asn1_nr_rrc_hdrs
add_custom_target(gen_nr_rrc_hdrs DEPENDS ${nr_rrc_headers})
add_library(asn1_nr_rrc_hdrs INTERFACE)
add_dependencies(asn1_nr_rrc_hdrs gen_nr_rrc_hdrs)
+3
View File
@@ -34,6 +34,9 @@
#include "oai_asn1.h"
#include "SIMULATION/TOOLS/sim.h" // for taus();
#include "uper_decoder.h"
#include "uper_encoder.h"
const uint8_t slotsperframe[5] = {10, 20, 40, 80, 160};
static NR_SearchSpace_t *rrc_searchspace_config(bool is_common, int searchspaceid, int coresetid)
+2
View File
@@ -65,6 +65,8 @@
#include "NR_RRCSetupComplete-IEs.h"
#include "NR_RRCReestablishmentRequest-IEs.h"
#include "NR_MIB.h"
#include "uper_encoder.h"
#include "uper_decoder.h"
#include "rlc.h"
#include "platform_types.h"
+3
View File
@@ -69,6 +69,9 @@
#include "NGAP_NonDynamic5QIDescriptor.h"
#include "conversions.h"
#include "RRC/NR/rrc_gNB_radio_bearers.h"
#include "uper_encoder.h"
extern RAN_CONTEXT_t RC;
/* Masks for NGAP Encryption algorithms, NEA0 is always supported (not coded) */
+2
View File
@@ -37,6 +37,8 @@
#include "NR_UE-CapabilityRAT-ContainerList.h"
#include "LTE_UE-CapabilityRAT-ContainerList.h"
#include "NR_CG-Config.h"
#include "uper_encoder.h"
#include "uper_decoder.h"
#include "executables/softmodem-common.h"
int parse_CG_ConfigInfo(gNB_RRC_INST *rrc, NR_CG_ConfigInfo_t *CG_ConfigInfo, x2ap_ENDC_sgnb_addition_req_t *m) {
+2
View File
@@ -36,6 +36,8 @@
#include "NR_CellGroupConfig.h"
#include "NR_CG-Config.h"
//#include "NR_SRB-ToAddModList.h"
#include "uper_encoder.h"
#include "uper_decoder.h"
#include "openair2/LAYER2/NR_MAC_gNB/mac_proto.h"
#include "openair2/LAYER2/nr_rlc/nr_rlc_oai_api.h"
#include "openair2/RRC/LTE/rrc_eNB_GTPV1U.h"
+1
View File
@@ -40,6 +40,7 @@
#include "NR_PDSCH-ServingCellConfig.h"
#include "NR_RLC-BearerConfig.h"
#include "BOOLEAN.h"
#include "uper_encoder.h"
#include "assertions.h"
#include "oai_asn1.h"
#include "common/utils/nr/nr_common.h"
+2
View File
@@ -44,6 +44,8 @@
#include "NR_RRCReconfiguration.h"
#include "NR_MeasConfig.h"
#include "NR_UL-DCCH-Message.h"
#include "uper_encoder.h"
#include "uper_decoder.h"
#include "rrc_defs.h"
#include "rrc_proto.h"
@@ -1,37 +1,105 @@
set(X2AP_GRAMMAR ASN1/R15/x2ap-15.6.0.asn1)
set(x2ap_source
ANY_aper.c
ANY.c
ANY_uper.c
ANY_xer.c
aper_decoder.c
aper_encoder.c
aper_opentype.c
aper_support.c
asn_application.c
asn_bit_data.c
asn_codecs_prim.c
asn_codecs_prim_xer.c
asn_internal.c
asn_random_fill.c
asn_SEQUENCE_OF.c
asn_SET_OF.c
ber_decoder.c
ber_tlv_length.c
ber_tlv_tag.c
BIT_STRING.c
BIT_STRING_print.c
BIT_STRING_rfill.c
BIT_STRING_uper.c
BIT_STRING_xer.c
BOOLEAN_aper.c
BOOLEAN.c
BOOLEAN_print.c
BOOLEAN_rfill.c
BOOLEAN_uper.c
BOOLEAN_xer.c
constraints.c
constr_CHOICE_aper.c
constr_CHOICE.c
constr_CHOICE_print.c
constr_CHOICE_rfill.c
constr_CHOICE_uper.c
constr_CHOICE_xer.c
constr_SEQUENCE_aper.c
constr_SEQUENCE.c
constr_SEQUENCE_OF_aper.c
constr_SEQUENCE_OF.c
constr_SEQUENCE_OF_uper.c
constr_SEQUENCE_OF_xer.c
constr_SEQUENCE_print.c
constr_SEQUENCE_rfill.c
constr_SEQUENCE_uper.c
constr_SEQUENCE_xer.c
constr_SET_OF_aper.c
constr_SET_OF.c
constr_SET_OF_print.c
constr_SET_OF_rfill.c
constr_SET_OF_uper.c
constr_SET_OF_xer.c
constr_TYPE.c
der_encoder.c
GraphicString.c
INTEGER_aper.c
INTEGER.c
INTEGER_print.c
INTEGER_rfill.c
INTEGER_uper.c
INTEGER_xer.c
NativeEnumerated_aper.c
NativeEnumerated.c
NativeEnumerated_uper.c
NativeEnumerated_xer.c
NativeInteger_aper.c
NativeInteger.c
NativeInteger_print.c
NativeInteger_rfill.c
NativeInteger_uper.c
NativeInteger_xer.c
NULL_aper.c
NULL.c
NULL_print.c
NULL_rfill.c
NULL_uper.c
NULL_xer.c
ObjectDescriptor.c
OBJECT_IDENTIFIER.c
OBJECT_IDENTIFIER_print.c
OBJECT_IDENTIFIER_rfill.c
OBJECT_IDENTIFIER_xer.c
OCTET_STRING_aper.c
OCTET_STRING.c
OCTET_STRING_print.c
OCTET_STRING_rfill.c
OCTET_STRING_uper.c
OCTET_STRING_xer.c
OPEN_TYPE_aper.c
OPEN_TYPE.c
OPEN_TYPE_uper.c
OPEN_TYPE_xer.c
per_decoder.c
per_encoder.c
per_opentype.c
per_support.c
uper_decoder.c
uper_encoder.c
uper_opentype.c
uper_support.c
X2AP_ABSInformation.c
X2AP_ABSInformationFDD.c
X2AP_ABSInformationTDD.c
@@ -303,6 +371,7 @@ set(x2ap_source
X2AP_ExpectedUEBehaviour.c
X2AP_ExtendedBitRate.c
X2AP_ExtendedULInterferenceOverloadInfo.c
X2AP_EXTERNAL.c
X2AP_FDD-Info.c
X2AP_FDD-InfoNeighbourServedNRCell-Information.c
X2AP_FDD-InfoServedNRCell-Information.c
@@ -728,17 +797,21 @@ set(x2ap_source
set(x2ap_headers
ANY.h
aper_decoder.h
aper_encoder.h
aper_opentype.h
aper_support.h
asn_application.h
asn_bit_data.h
asn_codecs.h
asn_codecs_prim.h
asn_config.h
asn_internal.h
asn_ioc.h
asn_random_fill.h
asn_SEQUENCE_OF.h
asn_SET_OF.h
asn_system.h
ber_decoder.h
ber_tlv_length.h
ber_tlv_tag.h
BIT_STRING.h
@@ -749,11 +822,12 @@ set(x2ap_headers
constr_SEQUENCE_OF.h
constr_SET_OF.h
constr_TYPE.h
der_encoder.h
GraphicString.h
INTEGER.h
NativeEnumerated.h
NativeInteger.h
NULL.h
ObjectDescriptor.h
OBJECT_IDENTIFIER.h
OCTET_STRING.h
OPEN_TYPE.h
@@ -761,6 +835,10 @@ set(x2ap_headers
per_encoder.h
per_opentype.h
per_support.h
uper_decoder.h
uper_encoder.h
uper_opentype.h
uper_support.h
X2AP_ABSInformationFDD.h
X2AP_ABSInformation.h
X2AP_ABSInformationTDD.h
@@ -1033,6 +1111,7 @@ set(x2ap_headers
X2AP_ExpectedUEBehaviour.h
X2AP_ExtendedBitRate.h
X2AP_ExtendedULInterferenceOverloadInfo.h
X2AP_EXTERNAL.h
X2AP_FDD-Info.h
X2AP_FDD-InfoNeighbourServedNRCell-Information.h
X2AP_FDD-InfoServedNRCell-Information.h
-697
View File
@@ -1,697 +0,0 @@
import re, os, sys, string
import datetime
import getopt
import getpass
version = "1.0.2"
lines = ""
iesDefs = {}
ieofielist = {}
outdir = './'
filenames = []
verbosity = 0
prefix = ""
FAIL = '\033[91m'
WARN = '\033[93m'
ENDC = '\033[0m'
fileprefix = ""
fileprefix_first_upper = ""
def printFail(string):
sys.stderr.write(FAIL + string + ENDC + "\n")
def printWarning(string):
print WARN + string + ENDC
def printDebug(string):
if verbosity > 0:
print string
def outputHeaderToFile(f, filename):
now = datetime.datetime.now()
f.write("""/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
""")
f.write("/*******************************************************************************\n")
f.write(" * This file had been created by asn1tostruct.py script v%s\n" % (version))
f.write(" * Please do not modify this file but regenerate it via script.\n")
f.write(" * Created on: %s by %s\n * from %s\n" % (str(now), getpass.getuser(), filenames))
f.write(" ******************************************************************************/\n")
def lowerFirstCamelWord(word):
""" puts the first word in a CamelCase Word in lowercase.
I.e. CustomerID becomes customerID, XMLInfoTest becomes xmlInfoTest
"""
newstr = ''
swapped = word.swapcase()
idx = 0
# if it's all-caps, return an all-lowered version
lowered = word.lower()
if swapped == lowered:
return lowered
for c in swapped:
if c in string.lowercase:
newstr += c
idx += 1
else:
break
if idx < 2:
newstr += word[idx:]
else:
newstr = newstr[:-1]+ word[idx-1:]
return newstr
def usage():
print "Python parser for asn1 v%s" % (version)
print "Usage: python asn1tostruct.py [options]"
print "Available options:"
print "-d Enable script debug"
print "-f [file] Input file to parse"
print "-o [dir] Output files to given directory"
print "-h Print this help and return"
try:
opts, args = getopt.getopt(sys.argv[1:], "df:ho:", ["debug", "file", "help", "outdir"])
except getopt.GetoptError as err:
# print help information and exit:
usage()
sys.exit(2)
for o, a in opts:
if o in ("-f", "--file"):
filenames.append(a)
if o in ("-d", "--debug"):
verbosity = 1
if o in ("-o", "--outdir"):
outdir = a
if outdir.rfind('/') != len(outdir):
outdir += '/'
if o in ("-h", "--help"):
usage()
sys.exit(2)
for filename in filenames:
file = open(filename, 'r')
for line in file:
# Removing any comment
if line.find('--') >= 0:
line = line[:line.find('--')]
# Removing any carriage return
lines += re.sub('\r', '', line)
for m in re.findall(r'([a-zA-Z0-9-]+)\s*::=\s+SEQUENCE\s+\(\s*SIZE\s*\(\s*\d+\s*\.\.\s*[0-9a-zA-Z-]+\s*\)\s*\)\s*OF\s+[a-zA-Z-]+\s*\{\s*\{\s*([0-9a-zA-Z-]+)\s*\}\s*\}', lines, re.MULTILINE):
ieofielist[m[0]] = m[1]
for m in re.findall(r'([a-zA-Z0-9-]+)\s*::=\s+E-RAB-IE-ContainerList\s*\{\s*\{\s*([a-zA-Z0-9-]+)\s*\}\s*\}', lines, re.MULTILINE):
ieofielist[m[0]] = m[1]
for i in re.findall(r'([a-zA-Z0-9-]+)\s+([A-Z0-9-]+)\s*::=\s*\{\s+([\,\|\{\}\t\n\.{3}\ \-a-zA-Z0-9]+)\s+}\n', lines, re.MULTILINE):
ies = []
maxLength = 0
# TODO: handle extensions
if i[1].find('EXTENSION') >= 0:
continue
if fileprefix == "":
fileprefix = i[1][:i[1].find('-')].lower()
for j in re.findall(r'\s*\{\s*([a-zA-Z0-9-\ \t]+)\s*\}\s*[\|,]*', i[2], re.MULTILINE):
for k in re.findall(r'ID\s*([a-zA-Z0-9\-]+)\s*CRITICALITY\s*([a-zA-Z0-9\-]+)\s+[A-Z]+\s+([a-zA-Z0-9\-]+)\s*PRESENCE\s*([a-zA-Z0-9\-]+)', j, re.MULTILINE):
printDebug("Got new ie for message " + i[0] + ": " + str(k))
if len(k[2]) > maxLength:
maxLength = len(k[2])
ies.append(k)
if len(ies) > 0:
iesDefs[i[0]] = { "length": maxLength, "ies": ies }
else:
printWarning("Didn't find any information element for message: " + i[0])
if len(iesDefs) == 0:
printFail("No Information Element parsed, exiting")
sys.exit(0)
fileprefix_first_upper = fileprefix[0].upper() + fileprefix[1:]
f = open(outdir + fileprefix + '_ies_defs.h', 'w')
outputHeaderToFile(f, filename)
f.write("#include \"%s_common.h\"\n\n" % (fileprefix))
f.write("#ifndef %s_IES_DEFS_H_\n#define %s_IES_DEFS_H_\n\n" % (fileprefix.upper(), fileprefix.upper()))
f.write("/* Define the version of script used to generate this file */\n")
f.write("#define %s_SCRIPT_VERSION (%s)\n\n" % (fileprefix.upper(), re.sub('\.', '', version)))
for key in iesDefs:
if key not in ieofielist.values():
continue
for (i, j) in ieofielist.items():
if j == key:
break
f.write("typedef struct %sIEs_s {\n" % (re.sub('-', '_', i)))
f.write(" A_SEQUENCE_OF(struct %s_s) %s;\n" % (re.sub('IEs', '', re.sub('-', '_', ieofielist[i])), lowerFirstCamelWord(re.sub('IEs', '', re.sub('-', '_', ieofielist[i])))))
f.write("} %sIEs_t;\n\n" % (re.sub('-', '_', i)))
for key in iesDefs:
keyupperunderscore = re.sub('-', '_', key.upper())
keylowerunderscore = re.sub('-', '_', key.lower())
shift = 0
if len(iesDefs[key]["ies"]) == 0:
continue
# Presence mask
for ie in iesDefs[key]["ies"]:
ieupperunderscore = re.sub('-', '_', re.sub('id-', '', ie[0])).upper()
if ie[3] == "optional" or ie[3] == "conditional":
f.write("#define {0:<{pad}} {1}\n".format("%s_%s_PRESENT" % (keyupperunderscore, ieupperunderscore), "(1 << %d)" % shift,
pad=iesDefs[key]["length"] + len(keyupperunderscore) + 9))
shift += 1
if (shift > 0):
f.write("\n")
f.write("typedef struct %s_s {\n" % (re.sub('-', '_', key)))
if (shift > 0):
f.write(" {0:<{pad}} {1};\n".format("uint16_t", "presenceMask", pad=iesDefs[key]["length"] + 2))
for ie in iesDefs[key]["ies"]:
ieunderscore = re.sub('-', '_', ie[2])
iename = re.sub('id-', '', ie[0])
ienameunderscore = lowerFirstCamelWord(re.sub('-', '_', iename))
if ie[2] in ieofielist:
f.write(" %sIEs_t %s;" % (re.sub('-', '_', ie[2]), ienameunderscore))
else:
f.write(" {0:<{pad}} {1};".format("%s_t" % ieunderscore, ienameunderscore, pad=iesDefs[key]["length"] + 2))
if ie[3] == "optional":
f.write(" ///< Optional field")
elif ie[3] == "conditional":
f.write(" ///< Conditional field")
f.write("\n")
f.write("} %s_t;\n\n" % (re.sub('-', '_', key)))
f.write("typedef struct %s_message_s {\n" % (fileprefix))
f.write(" %s_ProcedureCode_t procedureCode;\n" % (fileprefix_first_upper))
f.write(" %s_Criticality_t criticality;\n" % (fileprefix_first_upper))
f.write(" uint8_t direction;\n")
f.write(" union {\n")
messageList = iesDefs.keys()
messageList.sort()
for message in messageList:
if message in ieofielist.values():
continue
if len(iesDefs[message]["ies"]) == 0:
continue
f.write(" %s_t %s;\n" % (re.sub('-', '_', message), lowerFirstCamelWord(re.sub('-', '_', message))))
f.write(" } msg;\n")
f.write("} %s_message;\n\n" % (fileprefix))
for key in iesDefs:
if key in ieofielist.values():
continue
structName = re.sub('ies', '', key)
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', re.sub('-IEs', '', key)))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
keylowerunderscore = re.sub('-', '_', key.lower())
firstlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
f.write("/** \\brief Decode function for %s ies.\n" % (key))
if len(iesDefs[key]["ies"]) != 0:
f.write(" * \\param %s Pointer to ASN1 structure in which data will be stored\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" * \\param any_p Pointer to the ANY value to decode.\n")
f.write(" **/\n")
f.write("int %s_decode_%s(\n" % (fileprefix, keylowerunderscore))
if len(iesDefs[key]["ies"]) != 0:
f.write(" %s_t *%s,\n" % (re.sub('-', '_', key), lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" ANY_t *any_p);\n\n")
if len(iesDefs[key]["ies"]) == 0:
continue
f.write("/** \\brief Encode function for %s ies.\n" % (key))
f.write(" * \\param %s Pointer to the ASN1 structure.\n" % (firstlower))
f.write(" * \\param %s Pointer to the IES structure.\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" **/\n")
f.write("int %s_encode_%s(\n" % (fileprefix, re.sub('-', '_', structName.lower())))
f.write(" %s_t *%s,\n" % (asn1cStruct, firstlower))
f.write(" %s_t *%s);\n\n" % (re.sub('-', '_', key), lowerFirstCamelWord(re.sub('-', '_', key))))
for key in iesDefs:
if key not in ieofielist.values():
continue
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', key))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
firstlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
f.write("/** \\brief Encode function for %s ies.\n" % (key))
f.write(" * \\param %s Pointer to the ASN1 structure.\n" % (firstlower))
f.write(" * \\param %s Pointer to the IES structure.\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" **/\n")
f.write("int %s_encode_%s(\n" % (fileprefix, firstlower.lower()))
f.write(" %s_t *%s,\n" % (asn1cStruct, firstlower))
f.write(" %sIEs_t *%sIEs);\n\n" % (asn1cStruct, firstlower))
f.write("/** \\brief Decode function for %s ies.\n" % (key))
f.write(" * \\param any_p Pointer to the ANY value to decode.\n")
f.write(" * \\param callback Callback function called when any_p is successfully decoded.\n")
f.write(" **/\n")
f.write("int %s_decode_%s(\n" % (fileprefix, firstlower.lower()))
f.write(" %sIEs_t *%sIEs,\n" % (asn1cStruct, firstlower))
f.write(" %s_t *%s);\n\n" % (asn1cStruct, lowerFirstCamelWord(asn1cStruct)))
for key in iesDefs:
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', key))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
firstlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
if key in ieofielist.values():
f.write("/** \\brief Display %s encapsulated IE using XER encoding.\n" % (asn1cStruct))
f.write(" * \\param %s Pointer to the IES structure.\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" * \\param file File descriptor to write output.\n")
f.write(" **/\n")
f.write("asn_enc_rval_t %s_xer_print_%s(\n" % (fileprefix, re.sub('item', 'list', firstlower.lower())))
f.write(" asn_app_consume_bytes_f *cb,\n")
f.write(" void *app_key,\n")
f.write(" %sIEs_t *%sIEs);\n\n" % (re.sub('item', 'list', asn1cStruct), firstlower))
else:
f.write("/** \\brief Display %s message using XER encoding.\n" % (asn1cStruct))
f.write(" * \\param message_p Pointer to root message.\n")
f.write(" * \\param file File descriptor to write output.\n")
f.write(" **/\n")
f.write("asn_enc_rval_t %s_xer_print_%s(\n" % (fileprefix, firstlower.lower()))
f.write(" asn_app_consume_bytes_f *cb,\n")
f.write(" void *app_key,\n")
f.write(" %s_message *message_p);\n\n" % (fileprefix))
f.write("int %s_xer__print2sp(const void *buffer, size_t size, void *app_key);\n\n" % (fileprefix.lower()))
f.write("int %s_xer__print2fp(const void *buffer, size_t size, void *app_key);\n\n" % (fileprefix.lower()))
f.write("extern size_t %s_string_total_size;\n\n" % (fileprefix.lower()))
f.write("#endif /* %s_IES_DEFS_H_ */\n\n" % (fileprefix.upper()))
#Generate Decode functions
f = open(outdir + fileprefix + '_decoder.c', 'w')
outputHeaderToFile(f, filename)
f.write("#include \"%s_common.h\"\n#include \"%s_ies_defs.h\"\n\n" % (fileprefix, fileprefix))
for key in iesDefs:
if key in ieofielist.values():
continue
structName = re.sub('ies', '', key)
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', key))
if asn1cStruct.rfind('_') == len(asn1cStruct) - 1:
asn1cStruct = asn1cStruct[:-1]
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
ielistname = re.sub('UE', 'ue', asn1cStruct)
ielistnamefirstlower = ielistname[:1].lower() + ielistname[1:]
asn1cStructfirstlower = asn1cStruct[:1].lower() + asn1cStruct[1:]
keyName = re.sub('-', '_', key)
keyupperunderscore = keyName.upper()
firstlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
iesaccess = ""
if key not in ieofielist.values():
iesaccess = "%s_ies." % (firstlower)
f.write("int %s_decode_%s(\n" % (fileprefix, re.sub('-', '_', structName.lower())))
if len(iesDefs[key]["ies"]) != 0:
f.write(" %s_t *%s,\n" % (re.sub('-', '_', key), lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" ANY_t *any_p) {\n\n")
f.write(" %s_t %s;\n %s_t *%s_p = &%s;\n" % (asn1cStruct, asn1cStructfirstlower, asn1cStruct, asn1cStructfirstlower, asn1cStructfirstlower))
f.write(" int i, decoded = 0;\n")
if len(iesDefs[key]["ies"]) != 0:
f.write(" int tempDecoded = 0;\n")
f.write(" assert(any_p != NULL);\n")
if len(iesDefs[key]["ies"]) != 0:
f.write(" assert(%s != NULL);\n\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" %s_DEBUG(\"Decoding message %s (%%s:%%d)\\n\", __FILE__, __LINE__);\n\n" % (fileprefix.upper(), re.sub('-', '_', keyName)))
f.write(" ANY_to_type_aper(any_p, &asn_DEF_%s, (void**)&%s_p);\n\n" % (asn1cStruct, asn1cStructfirstlower))
f.write(" for (i = 0; i < %s_p->%slist.count; i++) {\n" % (asn1cStructfirstlower, iesaccess))
f.write(" %s_IE_t *ie_p;\n" % (fileprefix[0].upper() + fileprefix[1:]))
f.write(" ie_p = %s_p->%slist.array[i];\n" % (asn1cStructfirstlower, iesaccess))
f.write(" switch(ie_p->id) {\n")
for ie in iesDefs[key]["ies"]:
iename = re.sub('id-', '', ie[0])
ienameunderscore = lowerFirstCamelWord(re.sub('-', '_', iename))
ienameunderscorefirstlower = lowerFirstCamelWord(ienameunderscore)
ietypesubst = re.sub('-', '', ie[2])
ietypeunderscore = re.sub('-', '_', ie[2])
ieupperunderscore = re.sub('-', '_', re.sub('id-', '', ie[0])).upper()
if ie[3] == "optional":
f.write(" /* Optional field */\n")
elif ie[3] == "conditional":
f.write(" /* Conditional field */\n")
f.write(" case %s_ProtocolIE_ID_%s:\n" % (fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" {\n")
f.write(" %s_t *%s_p = NULL;\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
if ie[3] != "mandatory":
f.write(" %s->presenceMask |= %s_%s_PRESENT;\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), keyupperunderscore, ieupperunderscore))
f.write(" tempDecoded = ANY_to_type_aper(&ie_p->value, &asn_DEF_%s, (void**)&%s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" if (tempDecoded < 0 || %s_p == NULL) {\n" % (lowerFirstCamelWord(ietypesubst)))
f.write(" %s_ERROR(\"Decoding of IE %s failed\\n\");\n" % (fileprefix.upper(), ienameunderscore))
f.write(" if (%s_p)\n" % (lowerFirstCamelWord(ietypesubst)))
f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" decoded += tempDecoded;\n")
f.write(" if (asn1_xer_print)\n")
f.write(" xer_fprint(stdout, &asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
if ie[2] in ieofielist.keys():
f.write(" if (%s_decode_%s(&%s->%s, %s_p) < 0) {\n" % (fileprefix, ietypeunderscore.lower(), lowerFirstCamelWord(re.sub('-', '_', key)), ienameunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" %s_ERROR(\"Decoding of encapsulated IE %s failed\\n\");\n" % (fileprefix.upper(), lowerFirstCamelWord(ietypesubst)))
f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" }\n")
else:
f.write(" memcpy(&%s->%s, %s_p, sizeof(%s_t));\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), ienameunderscore, lowerFirstCamelWord(ietypesubst), ietypeunderscore))
#f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" } break;\n")
f.write(" default:\n")
f.write(" %s_ERROR(\"Unknown protocol IE id (%%d) for message %s\\n\", (int)ie_p->id);\n" % (fileprefix.upper(), re.sub('-', '_', structName.lower())))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" }\n")
f.write(" return decoded;\n")
f.write("}\n\n")
for key in iesDefs:
if key not in ieofielist.values():
continue
keyname = re.sub('IEs', '', re.sub('Item', 'List', key))
f.write("int %s_decode_%s(\n" % (fileprefix, re.sub('-', '_', keyname).lower()))
f.write(" %sIEs_t *%sIEs,\n" % (re.sub('-', '_', keyname), lowerFirstCamelWord(re.sub('-', '_', keyname))))
f.write(" %s_t *%s) {\n\n" % (re.sub('-', '_', keyname), lowerFirstCamelWord(re.sub('-', '_', keyname))))
f.write(" int i, decoded = 0;\n")
f.write(" int tempDecoded = 0;\n\n")
f.write(" assert(%s != NULL);\n" % (lowerFirstCamelWord(re.sub('-', '_', keyname))));
f.write(" assert(%sIEs != NULL);\n\n" % (lowerFirstCamelWord(re.sub('-', '_', keyname))));
f.write(" for (i = 0; i < %s->list.count; i++) {\n" % (lowerFirstCamelWord(re.sub('-', '_', keyname))))
f.write(" %s_IE_t *ie_p = %s->list.array[i];\n" % (fileprefix[0].upper() + fileprefix[1:], lowerFirstCamelWord(re.sub('-', '_', keyname))))
f.write(" switch (ie_p->id) {\n")
for ie in iesDefs[key]["ies"]:
iename = re.sub('id-', '', ie[0])
ienameunderscore = lowerFirstCamelWord(re.sub('-', '_', iename))
f.write(" case %s_ProtocolIE_ID_%s:\n" % (fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" {\n")
f.write(" %s_t *%s_p = NULL;\n" % (re.sub('-', '_', ie[2]), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" tempDecoded = ANY_to_type_aper(&ie_p->value, &asn_DEF_%s, (void**)&%s_p);\n" % (re.sub('-', '_', ie[2]), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" if (tempDecoded < 0 || %s_p == NULL) {\n" % (lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" %s_ERROR(\"Decoding of IE %s for message %s failed\\n\");\n" % (fileprefix.upper(), ienameunderscore, re.sub('-', '_', keyname)))
f.write(" if (%s_p)\n" % (lowerFirstCamelWord(re.sub('-', '', ie[2]))))
#f.write(" free(%s_p);\n" % (lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (re.sub('-', '_', ie[2]), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" decoded += tempDecoded;\n")
f.write(" if (asn1_xer_print)\n")
f.write(" xer_fprint(stdout, &asn_DEF_%s, %s_p);\n" % (re.sub('-', '_', ie[2]), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" ASN_SEQUENCE_ADD(&%sIEs->%s, %s_p);\n" % (lowerFirstCamelWord(re.sub('-', '_', keyname)),
re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key))), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" } break;\n")
f.write(" default:\n")
f.write(" %s_ERROR(\"Unknown protocol IE id (%%d) for message %s\\n\", (int)ie_p->id);\n" % (fileprefix.upper(), re.sub('-', '_', structName.lower())))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" }\n")
f.write(" return decoded;\n")
f.write("}\n\n")
#Generate IES Encode functions
f = open(outdir + fileprefix + '_encoder.c', 'w')
outputHeaderToFile(f,filename)
f.write("#include \"%s_common.h\"\n" % (fileprefix))
f.write("#include \"%s_ies_defs.h\"\n\n" % (fileprefix))
for key in iesDefs:
if key in ieofielist.values():
continue
structName = re.sub('ies', '', key)
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', key))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
if asn1cStruct.rfind('_') == len(asn1cStruct) - 1:
asn1cStruct = asn1cStruct[:-1]
asn1cStructfirstlower = asn1cStruct[:1].lower() + asn1cStruct[1:]
firstwordlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
iesaccess = ""
if key not in ieofielist.values():
iesaccess = "%s_ies." % (firstwordlower)
keyName = re.sub('-', '_', key)
keyupperunderscore = keyName.upper()
# No IE to encode...
if len(iesDefs[key]["ies"]) == 0:
continue
f.write("int %s_encode_%s(\n" % (fileprefix, re.sub('-', '_', structName.lower())))
f.write(" %s_t *%s,\n" % (asn1cStruct, firstwordlower))
f.write(" %s_t *%s) {\n\n" % (re.sub('-', '_', key), lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" %s_IE_t *ie;\n\n" % (fileprefix_first_upper))
f.write(" assert(%s != NULL);\n" % (firstwordlower));
f.write(" assert(%s != NULL);\n\n" % (lowerFirstCamelWord(re.sub('-', '_', key))));
for ie in iesDefs[key]["ies"]:
iename = re.sub('-', '_', re.sub('id-', '', ie[0]))
ienameunderscore = re.sub('-', '_', iename)
ienamefirstwordlower = lowerFirstCamelWord(iename)
ieupperunderscore = re.sub('-', '_', re.sub('id-', '', ie[0])).upper()
ietypeunderscore = re.sub('-', '_', ie[2])
if ie[3] != "mandatory":
if ie[3] == "optional":
f.write(" /* Optional field */\n")
elif ie[3] == "conditional":
f.write(" /* Conditional field */\n")
f.write(" if (%s->presenceMask & %s_%s_PRESENT) {\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), keyupperunderscore, ieupperunderscore))
#f.write(" == %s_%s_PRESENT) {\n" % (keyupperunderscore, ieupperunderscore))
f.write(" if ((ie = %s_new_ie(%s_ProtocolIE_ID_%s,\n" % (fileprefix, fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" %s_Criticality_%s,\n" % (fileprefix_first_upper, ie[1]))
f.write(" &asn_DEF_%s,\n" % (ietypeunderscore))
f.write(" &%s->%s)) == NULL) {\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), ienamefirstwordlower))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" ASN_SEQUENCE_ADD(&%s->%slist, ie);\n" % (firstwordlower, iesaccess))
f.write(" }\n\n")
else:
if ie[2] in ieofielist.keys():
f.write(" %s_t %s;\n\n" % (ietypeunderscore, ienamefirstwordlower))
f.write(" memset(&%s, 0, sizeof(%s_t));\n" % (ienamefirstwordlower, ietypeunderscore))
f.write("\n")
f.write(" if (%s_encode_%s(&%s, &%s->%s) < 0) return -1;\n" % (fileprefix, ietypeunderscore.lower(), ienamefirstwordlower, lowerFirstCamelWord(re.sub('-', '_', key)), ienamefirstwordlower))
f.write(" if ((ie = %s_new_ie(%s_ProtocolIE_ID_%s,\n" % (fileprefix, fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" %s_Criticality_%s,\n" % (fileprefix_first_upper, ie[1]))
f.write(" &asn_DEF_%s,\n" % (ietypeunderscore))
if ie[2] in ieofielist.keys():
f.write(" &%s)) == NULL) {\n" % (ienamefirstwordlower))
else:
f.write(" &%s->%s)) == NULL) {\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), ienamefirstwordlower))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" ASN_SEQUENCE_ADD(&%s->%slist, ie);\n\n" % (firstwordlower, iesaccess))
if ie[2] in ieofielist.keys():
f.write(" /* Free any dynamic allocation that is no more used */\n")
f.write(" ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_%s, &%s);\n\n" % (ietypeunderscore, ienamefirstwordlower))
f.write(" return 0;\n")
f.write("}\n\n")
for (key, value) in iesDefs.items():
if key not in ieofielist.values():
continue
ie = value["ies"][0]
ietypeunderscore = re.sub('-', '_', ie[2])
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', re.sub('-IEs', '', key)))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
firstwordlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
for (i, j) in ieofielist.items():
if j == key:
break
f.write("int %s_encode_%s(\n" % (fileprefix, re.sub('-', '_', i).lower()))
f.write(" %s_t *%s,\n" % (asn1cStruct, firstwordlower))
f.write(" %sIEs_t *%sIEs) {\n\n" % (re.sub('-', '_', i), lowerFirstCamelWord(re.sub('-', '_', i))))
f.write(" int i;\n")
f.write(" %s_IE_t *ie;\n\n" % (fileprefix_first_upper))
f.write(" assert(%s != NULL);\n" % (firstwordlower));
f.write(" assert(%sIEs != NULL);\n\n" % (lowerFirstCamelWord(re.sub('-', '_', i))));
f.write(" for (i = 0; i < %sIEs->%s.count; i++) {\n" % (firstwordlower, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
f.write(" if ((ie = %s_new_ie(%s_ProtocolIE_ID_%s,\n" % (fileprefix, fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" %s_Criticality_%s,\n" % (fileprefix_first_upper, ie[1]))
f.write(" &asn_DEF_%s,\n" % (ietypeunderscore))
f.write(" %sIEs->%s.array[i])) == NULL) {\n" % (firstwordlower, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" ASN_SEQUENCE_ADD(&%s->list, ie);\n" % (firstwordlower))
f.write(" }\n")
f.write(" return 0;\n")
f.write("}\n\n")
#Generate xer print functions
f = open(outdir + fileprefix + '_xer_print.c', 'w')
outputHeaderToFile(f, filename)
f.write("#include <stdlib.h>\n")
f.write("#include <stdio.h>\n\n")
f.write("#include <asn_application.h>\n#include <asn_internal.h>\n\n")
f.write("#include \"%s_common.h\"\n#include \"%s_ies_defs.h\"\n\n" % (fileprefix, fileprefix))
f.write("size_t %s_string_total_size = 0;\n\n" % (fileprefix.lower()))
f.write("""int
%s_xer__print2fp(const void *buffer, size_t size, void *app_key) {
FILE *stream = (FILE *)app_key;
if(fwrite(buffer, 1, size, stream) != size)
return -1;
return 0;
}
""" % (fileprefix.lower()))
f.write("""int %s_xer__print2sp(const void *buffer, size_t size, void *app_key) {
char *string = (char *)app_key;
/* Copy buffer to the formatted string */
memcpy(&string[%s_string_total_size], buffer, size);
%s_string_total_size += size;
return 0;
}
""" % (fileprefix.lower(), fileprefix.lower(), fileprefix.lower()))
f.write("""static asn_enc_rval_t
xer_encode_local(asn_TYPE_descriptor_t *td, void *sptr,
asn_app_consume_bytes_f *cb, void *app_key, int indent) {
asn_enc_rval_t er, tmper;
const char *mname;
size_t mlen;
int xcan = 2;
if(!td || !sptr) goto cb_failed;
mname = td->xml_tag;
mlen = strlen(mname);
_i_ASN_TEXT_INDENT(0, indent);
_ASN_CALLBACK3("<", 1, mname, mlen, ">", 1);
tmper = td->xer_encoder(td, sptr, indent + 1, XER_F_BASIC, cb, app_key);
if(tmper.encoded == -1) return tmper;
_ASN_CALLBACK3("</", 2, mname, mlen, ">\\n", xcan);
er.encoded = 4 + xcan + (2 * mlen) + tmper.encoded;
_ASN_ENCODED_OK(er);
cb_failed:
_ASN_ENCODE_FAILED;
}
""")
for (key, value) in iesDefs.items():
keyName = re.sub('-', '_', key)
keyupperunderscore = keyName.upper()
iesStructName = lowerFirstCamelWord(re.sub('-', '_', key))
ie = value["ies"][0]
ietypeunderscore = re.sub('-', '_', ie[2])
if key in ieofielist.values():
f.write("asn_enc_rval_t %s_xer_print_%s(\n" % (fileprefix, re.sub('ies', '', re.sub('item', 'list', re.sub('-', '_', key).lower()))))
else:
f.write("asn_enc_rval_t %s_xer_print_%s(\n" % (fileprefix, re.sub('ies', '', re.sub('-', '_', key).lower())))
#f.write(" FILE *file,\n")
f.write(" asn_app_consume_bytes_f *cb,\n")
f.write(" void *app_key,\n")
if key in ieofielist.values():
iesStructName = lowerFirstCamelWord(re.sub('Item', 'List', re.sub('-', '_', key)))
f.write(" %sIEs_t *%s) {\n\n" % (re.sub('IEs', '', re.sub('Item', 'List', re.sub('-', '_', key))), iesStructName))
f.write(" int i;\n")
f.write(" asn_enc_rval_t er;\n")
else:
f.write(" %s_message *message_p)\n{\n" % (fileprefix))
f.write(" %s_t *%s;\n" % (re.sub('-', '_', key), iesStructName))
f.write(" asn_enc_rval_t er;\n")
#f.write(" void *app_key = (void *)file;\n")
#f.write(" asn_app_consume_bytes_f *cb = %s_xer__print2fp;\n\n" % (fileprefix.lower()))
f.write(" %s = &message_p->msg.%s;\n\n" % (iesStructName, iesStructName))
if key in ieofielist.values():
# Increase indentation level
f.write(" for (i = 0; i < %s->%s.count; i++) {\n" % (iesStructName, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
#f.write(" xer_fprint(file, &asn_DEF_%s, %s->%s.array[i]);\n" % (ietypeunderscore, iesStructName, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
f.write(" er = xer_encode(&asn_DEF_%s, %s->%s.array[i], XER_F_BASIC, cb, app_key);\n" % (ietypeunderscore, iesStructName, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
f.write(" }\n")
else:
f.write(" cb(\"<%s-PDU>\\n\", %d, app_key);\n" % (key, len("<%s-PDU>\n" % (key))))
f.write(" xer_encode_local(&asn_DEF_%s_Criticality, &message_p->criticality, cb, app_key, 1);\n" % fileprefix_first_upper)
f.write(" xer_encode_local(&asn_DEF_%s_ProcedureCode, &message_p->procedureCode, cb, app_key, 1);\n" % fileprefix_first_upper)
f.write(" cb(\" <%s>\\n\", %d, app_key);\n" % (key, len(" <%s>\n" % (key))))
for ie in iesDefs[key]["ies"]:
iename = re.sub('-', '_', re.sub('id-', '', ie[0]))
ienameunderscore = re.sub('-', '_', iename)
ienamefirstwordlower = lowerFirstCamelWord(iename)
ietypeunderscore = re.sub('-', '_', ie[2])
ieupperunderscore = re.sub('-', '_', re.sub('id-', '', ie[0])).upper()
if ie[3] != "mandatory":
if ie[3] == "optional":
f.write(" /* Optional field */\n")
elif ie[3] == "conditional":
f.write(" /* Conditional field */\n")
f.write(" if (%s->presenceMask & %s_%s_PRESENT)\n " % (iesStructName, keyupperunderscore, ieupperunderscore))
# Is it an encapsulated IE ?
if ie[2] in ieofielist.keys():
f.write(" %s_xer_print_%s(cb, app_key, &%s->%s);\n" % (fileprefix, re.sub('ies', '', re.sub('-', '_', ie[2]).lower()), iesStructName, ienamefirstwordlower))
else:
f.write(" xer_encode_local(&asn_DEF_%s, &%s->%s, cb, app_key, 2);\n" % (ietypeunderscore, iesStructName, ienamefirstwordlower))
f.write(" cb(\" </%s>\\n\", %d, app_key);\n" % (key, len(" </%s>\n" % (key))))
f.write(" cb(\"</%s-PDU>\\n\", %d, app_key);\n" % (key, len("</%s-PDU>\n" % (key))))
f.write(" _ASN_ENCODED_OK(er);\n")
#if key not in ieofielist.values():
#f.write("cb_failed:\n")
#f.write(" return er;\n")
f.write("}\n\n")
+1 -1
View File
@@ -10,7 +10,7 @@ else()
endif()
add_custom_command(OUTPUT ${x2ap_source} ${x2ap_headers}
COMMAND ASN1C_PREFIX=X2AP_ asn1c -pdu=all -gen-PER -no-gen-OER -fcompound-names -no-gen-example -fno-include-deps -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${X2AP_GRAMMAR}
COMMAND ASN1C_PREFIX=X2AP_ ${ASN1C_EXEC} -pdu=all -gen-APER -no-gen-BER -no-gen-JER -no-gen-OER -gen-UPER -fcompound-names -no-gen-example -fno-include-deps -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${X2AP_GRAMMAR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${X2AP_GRAMMAR}
COMMENT "Generating X2AP source files from ${CMAKE_CURRENT_SOURCE_DIR}/${X2AP_GRAMMAR}"
)
+93 -4
View File
@@ -1,27 +1,70 @@
set(LPP_GRAMMAR ASN1/37355-g60.asn)
set(lpp_source
ANY_aper.c
ANY.c
ANY_uper.c
ANY_xer.c
aper_decoder.c
aper_encoder.c
aper_opentype.c
aper_support.c
asn_application.c
asn_bit_data.c
asn_codecs_prim.c
asn_codecs_prim_xer.c
asn_internal.c
asn_random_fill.c
asn_SEQUENCE_OF.c
asn_SET_OF.c
ber_decoder.c
ber_tlv_length.c
ber_tlv_tag.c
BIT_STRING.c
BIT_STRING_print.c
BIT_STRING_rfill.c
BIT_STRING_uper.c
BIT_STRING_xer.c
BOOLEAN_aper.c
BOOLEAN.c
BOOLEAN_print.c
BOOLEAN_rfill.c
BOOLEAN_uper.c
BOOLEAN_xer.c
constraints.c
constr_CHOICE_aper.c
constr_CHOICE.c
constr_CHOICE_print.c
constr_CHOICE_rfill.c
constr_CHOICE_uper.c
constr_CHOICE_xer.c
constr_SEQUENCE_aper.c
constr_SEQUENCE.c
constr_SEQUENCE_OF_aper.c
constr_SEQUENCE_OF.c
constr_SEQUENCE_OF_uper.c
constr_SEQUENCE_OF_xer.c
constr_SEQUENCE_print.c
constr_SEQUENCE_rfill.c
constr_SEQUENCE_uper.c
constr_SEQUENCE_xer.c
constr_SET_OF_aper.c
constr_SET_OF.c
constr_SET_OF_print.c
constr_SET_OF_rfill.c
constr_SET_OF_uper.c
constr_SET_OF_xer.c
constr_TYPE.c
der_encoder.c
GeneralizedTime.c
GeneralizedTime_print.c
GeneralizedTime_rfill.c
GeneralizedTime_xer.c
GraphicString.c
INTEGER_aper.c
INTEGER.c
INTEGER_print.c
INTEGER_rfill.c
INTEGER_uper.c
INTEGER_xer.c
LPP_Abort.c
LPP_Abort-r9-IEs.c
LPP_AccessTypes.c
@@ -150,6 +193,7 @@ set(lpp_source
LPP_EqualIntegerAmbiguityLevel-r16.c
LPP_Error.c
LPP_Error-r9-IEs.c
LPP_EXTERNAL.c
LPP_FKP-Gradients-Element-r15.c
LPP_FKP-Gradients-List-r15.c
LPP_FreqBandIndicatorNR-r16.c
@@ -637,16 +681,49 @@ set(lpp_source
LPP_WLAN-RequestLocationInformation-r13.c
LPP_WLAN-RTT-r13.c
LPP_WLAN-TargetDeviceErrorCauses-r13.c
NativeEnumerated_aper.c
NativeEnumerated.c
NativeEnumerated_uper.c
NativeEnumerated_xer.c
NativeInteger_aper.c
NativeInteger.c
NativeInteger_print.c
NativeInteger_rfill.c
NativeInteger_uper.c
NativeInteger_xer.c
NULL_aper.c
NULL.c
NULL_print.c
NULL_rfill.c
NULL_uper.c
NULL_xer.c
ObjectDescriptor.c
OBJECT_IDENTIFIER.c
OBJECT_IDENTIFIER_print.c
OBJECT_IDENTIFIER_rfill.c
OBJECT_IDENTIFIER_xer.c
OCTET_STRING_aper.c
OCTET_STRING.c
OCTET_STRING_print.c
OCTET_STRING_rfill.c
OCTET_STRING_uper.c
OCTET_STRING_xer.c
OPEN_TYPE_aper.c
OPEN_TYPE.c
OPEN_TYPE_uper.c
OPEN_TYPE_xer.c
per_decoder.c
per_encoder.c
per_opentype.c
per_support.c
uper_decoder.c
uper_encoder.c
uper_opentype.c
uper_support.c
UTCTime.c
UTCTime_print.c
UTCTime_rfill.c
UTCTime_xer.c
VisibleString.c
xer_decoder.c
xer_encoder.c
@@ -654,17 +731,22 @@ set(lpp_source
)
set(lpp_headers
ANY.h
aper_decoder.h
aper_encoder.h
aper_opentype.h
aper_support.h
asn_application.h
asn_bit_data.h
asn_codecs.h
asn_codecs_prim.h
asn_config.h
asn_internal.h
asn_ioc.h
asn_random_fill.h
asn_SEQUENCE_OF.h
asn_SET_OF.h
asn_system.h
ber_decoder.h
ber_tlv_length.h
ber_tlv_tag.h
BIT_STRING.h
@@ -675,8 +757,8 @@ set(lpp_headers
constr_SEQUENCE_OF.h
constr_SET_OF.h
constr_TYPE.h
der_encoder.h
GeneralizedTime.h
GraphicString.h
INTEGER.h
LPP_Abort.h
LPP_Abort-r9-IEs.h
@@ -807,6 +889,7 @@ set(lpp_headers
LPP_EqualIntegerAmbiguityLevel-r16.h
LPP_Error.h
LPP_Error-r9-IEs.h
LPP_EXTERNAL.h
LPP_FKP-Gradients-Element-r15.h
LPP_FKP-Gradients-List-r15.h
LPP_FreqBandIndicatorNR-r16.h
@@ -1297,12 +1380,18 @@ set(lpp_headers
NativeEnumerated.h
NativeInteger.h
NULL.h
ObjectDescriptor.h
OBJECT_IDENTIFIER.h
OCTET_STRING.h
OPEN_TYPE.h
per_decoder.h
per_encoder.h
per_opentype.h
per_support.h
uper_decoder.h
uper_encoder.h
uper_opentype.h
uper_support.h
UTCTime.h
VisibleString.h
xer_decoder.h
+1 -1
View File
@@ -10,7 +10,7 @@ include(ASN1/37355-g60.cmake)
#endif()
add_custom_command(OUTPUT ${lpp_source} ${lpp_headers}
COMMAND ASN1C_PREFIX=LPP_ asn1c -gen-PER -no-gen-OER -fcompound-names -no-gen-example -findirect-choice -fno-include-deps -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${LPP_GRAMMAR}
COMMAND ASN1C_PREFIX=LPP_ ${ASN1C_EXEC} -gen-UPER -no-gen-BER -no-gen-JER -no-gen-OER -gen-APER -fcompound-names -no-gen-example -findirect-choice -fno-include-deps -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${LPP_GRAMMAR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${LPP_GRAMMAR}
COMMENT "Generating LPP source files from ${CMAKE_CURRENT_SOURCE_DIR}/${LPP_GRAMMAR}"
)
+73 -4
View File
@@ -1,26 +1,60 @@
set(M3AP_GRAMMAR ASN1/m3ap-14.0.0.asn)
set(m3ap_source
ANY_aper.c
ANY.c
ANY_uper.c
ANY_xer.c
aper_decoder.c
aper_encoder.c
aper_opentype.c
aper_support.c
asn_application.c
asn_bit_data.c
asn_codecs_prim.c
asn_codecs_prim_xer.c
asn_internal.c
asn_random_fill.c
asn_SEQUENCE_OF.c
asn_SET_OF.c
ber_decoder.c
ber_tlv_length.c
ber_tlv_tag.c
BIT_STRING.c
BIT_STRING_print.c
BIT_STRING_rfill.c
BIT_STRING_uper.c
BIT_STRING_xer.c
constraints.c
constr_CHOICE_aper.c
constr_CHOICE.c
constr_CHOICE_print.c
constr_CHOICE_rfill.c
constr_CHOICE_uper.c
constr_CHOICE_xer.c
constr_SEQUENCE_aper.c
constr_SEQUENCE.c
constr_SEQUENCE_OF_aper.c
constr_SEQUENCE_OF.c
constr_SEQUENCE_OF_uper.c
constr_SEQUENCE_OF_xer.c
constr_SEQUENCE_print.c
constr_SEQUENCE_rfill.c
constr_SEQUENCE_uper.c
constr_SEQUENCE_xer.c
constr_SET_OF_aper.c
constr_SET_OF.c
constr_SET_OF_print.c
constr_SET_OF_rfill.c
constr_SET_OF_uper.c
constr_SET_OF_xer.c
constr_TYPE.c
der_encoder.c
GraphicString.c
INTEGER_aper.c
INTEGER.c
INTEGER_print.c
INTEGER_rfill.c
INTEGER_uper.c
INTEGER_xer.c
M3AP_Absolute-Time-ofMBMS-Data.c
M3AP_AllocationAndRetentionPriority.c
M3AP_BitRate.c
@@ -37,6 +71,7 @@ set(m3ap_source
M3AP_ErrorIndication.c
M3AP_EUTRANCellIdentifier.c
M3AP_ExtendedMCE-ID.c
M3AP_EXTERNAL.c
M3AP_GBR-QosInformation.c
M3AP_Global-MCE-ID.c
M3AP_GTP-TEID.c
@@ -105,16 +140,40 @@ set(m3ap_source
M3AP_TriggeringMessage.c
M3AP_TypeOfError.c
M3AP_UnsuccessfulOutcome.c
NativeEnumerated_aper.c
NativeEnumerated.c
NativeEnumerated_uper.c
NativeEnumerated_xer.c
NativeInteger_aper.c
NativeInteger.c
NativeInteger_print.c
NativeInteger_rfill.c
NativeInteger_uper.c
NativeInteger_xer.c
ObjectDescriptor.c
OBJECT_IDENTIFIER.c
OBJECT_IDENTIFIER_print.c
OBJECT_IDENTIFIER_rfill.c
OBJECT_IDENTIFIER_xer.c
OCTET_STRING_aper.c
OCTET_STRING.c
OCTET_STRING_print.c
OCTET_STRING_rfill.c
OCTET_STRING_uper.c
OCTET_STRING_xer.c
OPEN_TYPE_aper.c
OPEN_TYPE.c
OPEN_TYPE_uper.c
OPEN_TYPE_xer.c
per_decoder.c
per_encoder.c
per_opentype.c
per_support.c
PrintableString.c
uper_decoder.c
uper_encoder.c
uper_opentype.c
uper_support.c
xer_decoder.c
xer_encoder.c
xer_support.c
@@ -122,17 +181,21 @@ set(m3ap_source
set(m3ap_headers
ANY.h
aper_decoder.h
aper_encoder.h
aper_opentype.h
aper_support.h
asn_application.h
asn_bit_data.h
asn_codecs.h
asn_codecs_prim.h
asn_config.h
asn_internal.h
asn_ioc.h
asn_random_fill.h
asn_SEQUENCE_OF.h
asn_SET_OF.h
asn_system.h
ber_decoder.h
ber_tlv_length.h
ber_tlv_tag.h
BIT_STRING.h
@@ -142,7 +205,7 @@ set(m3ap_headers
constr_SEQUENCE_OF.h
constr_SET_OF.h
constr_TYPE.h
der_encoder.h
GraphicString.h
INTEGER.h
M3AP_Absolute-Time-ofMBMS-Data.h
M3AP_AllocationAndRetentionPriority.h
@@ -161,6 +224,7 @@ set(m3ap_headers
M3AP_ErrorIndication.h
M3AP_EUTRANCellIdentifier.h
M3AP_ExtendedMCE-ID.h
M3AP_EXTERNAL.h
M3AP_GBR-QosInformation.h
M3AP_Global-MCE-ID.h
M3AP_GTP-TEID.h
@@ -231,6 +295,7 @@ set(m3ap_headers
M3AP_UnsuccessfulOutcome.h
NativeEnumerated.h
NativeInteger.h
ObjectDescriptor.h
OBJECT_IDENTIFIER.h
OCTET_STRING.h
OPEN_TYPE.h
@@ -239,6 +304,10 @@ set(m3ap_headers
per_opentype.h
per_support.h
PrintableString.h
uper_decoder.h
uper_encoder.h
uper_opentype.h
uper_support.h
xer_decoder.h
xer_encoder.h
xer_support.h
+1 -1
View File
@@ -17,7 +17,7 @@ else()
endif()
add_custom_command(OUTPUT ${m3ap_source} ${m3ap_headers}
COMMAND ASN1C_PREFIX=M3AP_ asn1c -gen-PER -no-gen-OER -fcompound-names -no-gen-example -fno-include-deps -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${M3AP_GRAMMAR}
COMMAND ASN1C_PREFIX=M3AP_ ${ASN1C_EXEC} -gen-APER -no-gen-BER -no-gen-JER -no-gen-OER -gen-UPER -fcompound-names -no-gen-example -fno-include-deps -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${M3AP_GRAMMAR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${M3AP_GRAMMAR}
COMMENT "Generating M3AP source files from ${CMAKE_CURRENT_SOURCE_DIR}/${M3AP_GRAMMAR}"
)
+83 -14
View File
@@ -1,28 +1,70 @@
set(NGAP_GRAMMAR ASN1/ngap-15.8.0.asn1)
set(ngap_source
ANY_aper.c
ANY.c
ANY_uper.c
ANY_xer.c
aper_decoder.c
aper_encoder.c
aper_opentype.c
aper_support.c
asn_application.c
asn_bit_data.c
asn_codecs_prim.c
asn_codecs_prim_xer.c
asn_internal.c
asn_random_fill.c
asn_SEQUENCE_OF.c
asn_SET_OF.c
ber_decoder.c
ber_tlv_length.c
ber_tlv_tag.c
BIT_STRING.c
BIT_STRING_print.c
BIT_STRING_rfill.c
BIT_STRING_uper.c
BIT_STRING_xer.c
constraints.c
constr_CHOICE_aper.c
constr_CHOICE.c
constr_CHOICE_print.c
constr_CHOICE_rfill.c
constr_CHOICE_uper.c
constr_CHOICE_xer.c
constr_SEQUENCE_aper.c
constr_SEQUENCE.c
constr_SEQUENCE_OF_aper.c
constr_SEQUENCE_OF.c
constr_SEQUENCE_OF_uper.c
constr_SEQUENCE_OF_xer.c
constr_SEQUENCE_print.c
constr_SEQUENCE_rfill.c
constr_SEQUENCE_uper.c
constr_SEQUENCE_xer.c
constr_SET_OF_aper.c
constr_SET_OF.c
constr_SET_OF_print.c
constr_SET_OF_rfill.c
constr_SET_OF_uper.c
constr_SET_OF_xer.c
constr_TYPE.c
der_encoder.c
GraphicString.c
INTEGER_aper.c
INTEGER.c
INTEGER_print.c
INTEGER_rfill.c
INTEGER_uper.c
INTEGER_xer.c
NativeEnumerated_aper.c
NativeEnumerated.c
NativeEnumerated_uper.c
NativeEnumerated_xer.c
NativeInteger_aper.c
NativeInteger.c
NativeInteger_print.c
NativeInteger_rfill.c
NativeInteger_uper.c
NativeInteger_xer.c
NGAP_AdditionalDLUPTNLInformationForHOItem.c
NGAP_AdditionalDLUPTNLInformationForHOList.c
NGAP_AdditionalQosFlowInformation.c
@@ -111,7 +153,7 @@ set(ngap_source
NGAP_ConfidentialityProtectionIndication.c
NGAP_ConfidentialityProtectionResult.c
NGAP_ConfiguredNSSAI.c
NGAP_CoreNetworkAssistanceInformationForInactive.c
NGAP_CoreNetworkAssistanceInformationForInactive.c
NGAP_COUNTValueForPDCP-SN12.c
NGAP_COUNTValueForPDCP-SN18.c
NGAP_CPTransportLayerInformation.c
@@ -184,6 +226,7 @@ set(ngap_source
NGAP_ExpectedUEMobility.c
NGAP_ExpectedUEMovingTrajectory.c
NGAP_ExpectedUEMovingTrajectoryItem.c
NGAP_EXTERNAL.c
NGAP_FiveG-S-TMSI.c
NGAP_FiveG-TMSI.c
NGAP_FiveQI.c
@@ -213,7 +256,7 @@ set(ngap_source
NGAP_HandoverRequest.c
NGAP_HandoverRequired.c
NGAP_HandoverRequiredTransfer.c
NGAP_HandoverResourceAllocationUnsuccessfulTransfer.c
NGAP_HandoverResourceAllocationUnsuccessfulTransfer.c
NGAP_HandoverType.c
NGAP_IMSVoiceSupportIndicator.c
NGAP_IndexToRFSP.c
@@ -331,7 +374,7 @@ set(ngap_source
NGAP_PDUSessionResourceModifyConfirmTransfer.c
NGAP_PDUSessionResourceModifyIndication.c
NGAP_PDUSessionResourceModifyIndicationTransfer.c
NGAP_PDUSessionResourceModifyIndicationUnsuccessfulTransfer.c
NGAP_PDUSessionResourceModifyIndicationUnsuccessfulTransfer.c
NGAP_PDUSessionResourceModifyItemModCfm.c
NGAP_PDUSessionResourceModifyItemModInd.c
NGAP_PDUSessionResourceModifyItemModReq.c
@@ -344,7 +387,7 @@ set(ngap_source
NGAP_PDUSessionResourceModifyRequestTransfer.c
NGAP_PDUSessionResourceModifyResponse.c
NGAP_PDUSessionResourceModifyResponseTransfer.c
NGAP_PDUSessionResourceModifyUnsuccessfulTransfer.c
NGAP_PDUSessionResourceModifyUnsuccessfulTransfer.c
NGAP_PDUSessionResourceNotify.c
NGAP_PDUSessionResourceNotifyItem.c
NGAP_PDUSessionResourceNotifyList.c
@@ -378,7 +421,7 @@ set(ngap_source
NGAP_PDUSessionResourceSetupRequestTransfer.c
NGAP_PDUSessionResourceSetupResponse.c
NGAP_PDUSessionResourceSetupResponseTransfer.c
NGAP_PDUSessionResourceSetupUnsuccessfulTransfer.c
NGAP_PDUSessionResourceSetupUnsuccessfulTransfer.c
NGAP_PDUSessionResourceSwitchedItem.c
NGAP_PDUSessionResourceSwitchedList.c
NGAP_PDUSessionResourceToBeSwitchedDLItem.c
@@ -616,14 +659,30 @@ set(ngap_source
NGAP_XnGTP-TLAs.c
NGAP_XnTLAs.c
NGAP_XnTNLConfigurationInfo.c
ObjectDescriptor.c
OBJECT_IDENTIFIER.c
OBJECT_IDENTIFIER_print.c
OBJECT_IDENTIFIER_rfill.c
OBJECT_IDENTIFIER_xer.c
OCTET_STRING_aper.c
OCTET_STRING.c
OCTET_STRING_print.c
OCTET_STRING_rfill.c
OCTET_STRING_uper.c
OCTET_STRING_xer.c
OPEN_TYPE_aper.c
OPEN_TYPE.c
OPEN_TYPE_uper.c
OPEN_TYPE_xer.c
per_decoder.c
per_encoder.c
per_opentype.c
per_support.c
PrintableString.c
uper_decoder.c
uper_encoder.c
uper_opentype.c
uper_support.c
xer_decoder.c
xer_encoder.c
xer_support.c
@@ -631,17 +690,21 @@ set(ngap_source
set(ngap_headers
ANY.h
aper_decoder.h
aper_encoder.h
aper_opentype.h
aper_support.h
asn_application.h
asn_bit_data.h
asn_codecs.h
asn_codecs_prim.h
asn_config.h
asn_internal.h
asn_ioc.h
asn_random_fill.h
asn_SEQUENCE_OF.h
asn_SET_OF.h
asn_system.h
ber_decoder.h
ber_tlv_length.h
ber_tlv_tag.h
BIT_STRING.h
@@ -651,7 +714,7 @@ set(ngap_headers
constr_SEQUENCE_OF.h
constr_SET_OF.h
constr_TYPE.h
der_encoder.h
GraphicString.h
INTEGER.h
NativeEnumerated.h
NativeInteger.h
@@ -744,7 +807,7 @@ set(ngap_headers
NGAP_ConfidentialityProtectionIndication.h
NGAP_ConfidentialityProtectionResult.h
NGAP_ConfiguredNSSAI.h
NGAP_CoreNetworkAssistanceInformationForInactive.h
NGAP_CoreNetworkAssistanceInformationForInactive.h
NGAP_COUNTValueForPDCP-SN12.h
NGAP_COUNTValueForPDCP-SN18.h
NGAP_CPTransportLayerInformation.h
@@ -817,6 +880,7 @@ set(ngap_headers
NGAP_ExpectedUEMobility.h
NGAP_ExpectedUEMovingTrajectory.h
NGAP_ExpectedUEMovingTrajectoryItem.h
NGAP_EXTERNAL.h
NGAP_FiveG-S-TMSI.h
NGAP_FiveG-TMSI.h
NGAP_FiveQI.h
@@ -846,7 +910,7 @@ set(ngap_headers
NGAP_HandoverRequest.h
NGAP_HandoverRequired.h
NGAP_HandoverRequiredTransfer.h
NGAP_HandoverResourceAllocationUnsuccessfulTransfer.h
NGAP_HandoverResourceAllocationUnsuccessfulTransfer.h
NGAP_HandoverType.h
NGAP_IMSVoiceSupportIndicator.h
NGAP_IndexToRFSP.h
@@ -964,7 +1028,7 @@ set(ngap_headers
NGAP_PDUSessionResourceModifyConfirmTransfer.h
NGAP_PDUSessionResourceModifyIndication.h
NGAP_PDUSessionResourceModifyIndicationTransfer.h
NGAP_PDUSessionResourceModifyIndicationUnsuccessfulTransfer.h
NGAP_PDUSessionResourceModifyIndicationUnsuccessfulTransfer.h
NGAP_PDUSessionResourceModifyItemModCfm.h
NGAP_PDUSessionResourceModifyItemModInd.h
NGAP_PDUSessionResourceModifyItemModReq.h
@@ -977,7 +1041,7 @@ set(ngap_headers
NGAP_PDUSessionResourceModifyRequestTransfer.h
NGAP_PDUSessionResourceModifyResponse.h
NGAP_PDUSessionResourceModifyResponseTransfer.h
NGAP_PDUSessionResourceModifyUnsuccessfulTransfer.h
NGAP_PDUSessionResourceModifyUnsuccessfulTransfer.h
NGAP_PDUSessionResourceNotify.h
NGAP_PDUSessionResourceNotifyItem.h
NGAP_PDUSessionResourceNotifyList.h
@@ -1011,7 +1075,7 @@ set(ngap_headers
NGAP_PDUSessionResourceSetupRequestTransfer.h
NGAP_PDUSessionResourceSetupResponse.h
NGAP_PDUSessionResourceSetupResponseTransfer.h
NGAP_PDUSessionResourceSetupUnsuccessfulTransfer.h
NGAP_PDUSessionResourceSetupUnsuccessfulTransfer.h
NGAP_PDUSessionResourceSwitchedItem.h
NGAP_PDUSessionResourceSwitchedList.h
NGAP_PDUSessionResourceToBeSwitchedDLItem.h
@@ -1249,6 +1313,7 @@ set(ngap_headers
NGAP_XnGTP-TLAs.h
NGAP_XnTLAs.h
NGAP_XnTNLConfigurationInfo.h
ObjectDescriptor.h
OBJECT_IDENTIFIER.h
OCTET_STRING.h
OPEN_TYPE.h
@@ -1257,6 +1322,10 @@ set(ngap_headers
per_opentype.h
per_support.h
PrintableString.h
uper_decoder.h
uper_encoder.h
uper_opentype.h
uper_support.h
xer_decoder.h
xer_encoder.h
xer_support.h
+1 -1
View File
@@ -10,7 +10,7 @@ else()
endif()
add_custom_command(OUTPUT ${ngap_source} ${ngap_headers}
COMMAND ASN1C_PREFIX=NGAP_ asn1c -pdu=all -fcompound-names -gen-PER -no-gen-OER -no-gen-example -fno-include-deps -findirect-choice -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${NGAP_GRAMMAR}
COMMAND ASN1C_PREFIX=NGAP_ ${ASN1C_EXEC} -pdu=all -fcompound-names -gen-APER -no-gen-BER -no-gen-JER -no-gen-OER -gen-UPER -no-gen-example -fno-include-deps -findirect-choice -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${NGAP_GRAMMAR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${NGAP_GRAMMAR}
COMMENT "Generating NGAP source files from ${CMAKE_CURRENT_SOURCE_DIR}/${NGAP_GRAMMAR}"
)
+104 -5
View File
@@ -1,10 +1,21 @@
set(NRPPA_GRAMMAR ASN1/38455.asn)
set(nrppa_source
ANY_aper.c
ANY_ber.c
ANY.c
ANY_jer.c
ANY_uper.c
ANY_xer.c
aper_decoder.c
aper_encoder.c
aper_opentype.c
aper_support.c
asn_application.c
asn_bit_data.c
asn_codecs_prim_ber.c
asn_codecs_prim.c
asn_codecs_prim_xer.c
asn_internal.c
asn_random_fill.c
asn_SEQUENCE_OF.c
@@ -13,17 +24,67 @@ ber_decoder.c
ber_tlv_length.c
ber_tlv_tag.c
BIT_STRING.c
BOOLEAN.c
BIT_STRING_jer.c
BIT_STRING_print.c
BIT_STRING_rfill.c
BIT_STRING_uper.c
BIT_STRING_xer.c
constraints.c
constr_CHOICE_aper.c
constr_CHOICE_ber.c
constr_CHOICE.c
constr_CHOICE_jer.c
constr_CHOICE_print.c
constr_CHOICE_rfill.c
constr_CHOICE_uper.c
constr_CHOICE_xer.c
constr_SEQUENCE_aper.c
constr_SEQUENCE_ber.c
constr_SEQUENCE.c
constr_SEQUENCE_jer.c
constr_SEQUENCE_OF_aper.c
constr_SEQUENCE_OF_ber.c
constr_SEQUENCE_OF.c
constr_SEQUENCE_OF_jer.c
constr_SEQUENCE_OF_uper.c
constr_SEQUENCE_OF_xer.c
constr_SEQUENCE_print.c
constr_SEQUENCE_rfill.c
constr_SEQUENCE_uper.c
constr_SEQUENCE_xer.c
constr_SET_OF_aper.c
constr_SET_OF_ber.c
constr_SET_OF.c
constr_SET_OF_jer.c
constr_SET_OF_print.c
constr_SET_OF_rfill.c
constr_SET_OF_uper.c
constr_SET_OF_xer.c
constr_TYPE.c
der_encoder.c
GraphicString.c
INTEGER_aper.c
INTEGER_ber.c
INTEGER.c
INTEGER_jer.c
INTEGER_print.c
INTEGER_rfill.c
INTEGER_uper.c
INTEGER_xer.c
jer_encoder.c
NativeEnumerated_aper.c
NativeEnumerated.c
NativeEnumerated_jer.c
NativeEnumerated_uper.c
NativeEnumerated_xer.c
NativeInteger_aper.c
NativeInteger_ber.c
NativeInteger.c
NativeInteger_jer.c
NativeInteger_print.c
NativeInteger_rfill.c
NativeInteger_uper.c
NativeInteger_xer.c
NRPPA_AbortTransmission.c
NRPPA_ActivationTime.c
NRPPA_ActiveULBWP.c
@@ -72,6 +133,7 @@ NRPPA_E-CID-MeasurementResult.c
NRPPA_E-CIDMeasurementTerminationCommand.c
NRPPA_ErrorIndication.c
NRPPA_EUTRACellIdentifier.c
NRPPA_EXTERNAL.c
NRPPA_GeographicalCoordinates.c
NRPPA_GNB-RxTxTimeDiff.c
NRPPA_GNBRxTxTimeDiffMeas.c
@@ -341,26 +403,57 @@ NRPPA_WLANMeasurementResult.c
NRPPA_WLANMeasurementResult-Item.c
NRPPA_WLANOperatingClass.c
NRPPA_WLAN-RSSI.c
NULL_aper.c
NULL_ber.c
NULL.c
NULL_jer.c
NULL_print.c
NULL_rfill.c
NULL_uper.c
NULL_xer.c
ObjectDescriptor.c
OBJECT_IDENTIFIER.c
OBJECT_IDENTIFIER_jer.c
OBJECT_IDENTIFIER_print.c
OBJECT_IDENTIFIER_rfill.c
OBJECT_IDENTIFIER_xer.c
OCTET_STRING_aper.c
OCTET_STRING_ber.c
OCTET_STRING.c
OCTET_STRING_jer.c
OCTET_STRING_print.c
OCTET_STRING_rfill.c
OCTET_STRING_uper.c
OCTET_STRING_xer.c
OPEN_TYPE_aper.c
OPEN_TYPE_ber.c
OPEN_TYPE.c
OPEN_TYPE_uper.c
OPEN_TYPE_xer.c
per_decoder.c
per_encoder.c
per_opentype.c
per_support.c
uper_decoder.c
uper_encoder.c
uper_opentype.c
uper_support.c
xer_decoder.c
xer_encoder.c
xer_support.c
)
set(nrppa_headers
ANY.h
aper_decoder.h
aper_encoder.h
aper_opentype.h
aper_support.h
asn_application.h
asn_bit_data.h
asn_codecs.h
asn_codecs_prim.h
asn_config.h
asn_internal.h
asn_ioc.h
asn_random_fill.h
@@ -371,7 +464,6 @@ ber_decoder.h
ber_tlv_length.h
ber_tlv_tag.h
BIT_STRING.h
BOOLEAN.h
constraints.h
constr_CHOICE.h
constr_SEQUENCE.h
@@ -379,7 +471,9 @@ constr_SEQUENCE_OF.h
constr_SET_OF.h
constr_TYPE.h
der_encoder.h
GraphicString.h
INTEGER.h
jer_encoder.h
NativeEnumerated.h
NativeInteger.h
NRPPA_AbortTransmission.h
@@ -431,6 +525,7 @@ NRPPA_E-CID-MeasurementResult.h
NRPPA_E-CIDMeasurementTerminationCommand.h
NRPPA_ErrorIndication.h
NRPPA_EUTRACellIdentifier.h
NRPPA_EXTERNAL.h
NRPPA_GeographicalCoordinates.h
NRPPA_GNB-RxTxTimeDiff.h
NRPPA_GNBRxTxTimeDiffMeas.h
@@ -701,6 +796,7 @@ NRPPA_WLANMeasurementResult-Item.h
NRPPA_WLANOperatingClass.h
NRPPA_WLAN-RSSI.h
NULL.h
ObjectDescriptor.h
OBJECT_IDENTIFIER.h
OCTET_STRING.h
OPEN_TYPE.h
@@ -708,8 +804,11 @@ per_decoder.h
per_encoder.h
per_opentype.h
per_support.h
uper_decoder.h
uper_encoder.h
uper_opentype.h
uper_support.h
xer_decoder.h
xer_encoder.h
xer_support.h
)
)
+1 -1
View File
@@ -10,7 +10,7 @@ include(ASN1/38455.cmake)
#endif()
add_custom_command(OUTPUT ${nrppa_source} ${nrppa_headers}
COMMAND ASN1C_PREFIX=NRPPA_ asn1c -gen-PER -no-gen-OER -fcompound-names -no-gen-example -findirect-choice -fno-include-deps -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${NRPPA_GRAMMAR}
COMMAND ASN1C_PREFIX=NRPPA_ ${ASN1C_EXEC} -gen-APER -gen-UPER -no-gen-OER -fcompound-names -no-gen-example -findirect-choice -fno-include-deps -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${NRPPA_GRAMMAR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${NRPPA_GRAMMAR}
COMMENT "Generating NRPPA source files from ${CMAKE_CURRENT_SOURCE_DIR}/${NRPPA_GRAMMAR}"
)
@@ -1,33 +1,91 @@
set(S1AP_GRAMMAR ASN1/R15/s1ap-15.6.0.asn1)
set(s1ap_source
ANY_aper.c
ANY.c
ANY_uper.c
ANY_xer.c
aper_decoder.c
aper_encoder.c
aper_opentype.c
aper_support.c
asn_application.c
asn_bit_data.c
asn_codecs_prim.c
asn_codecs_prim_xer.c
asn_internal.c
asn_random_fill.c
asn_SEQUENCE_OF.c
asn_SET_OF.c
ber_decoder.c
ber_tlv_length.c
ber_tlv_tag.c
BIT_STRING.c
BOOLEAN.c
BIT_STRING_print.c
BIT_STRING_rfill.c
BIT_STRING_uper.c
BIT_STRING_xer.c
constraints.c
constr_CHOICE_aper.c
constr_CHOICE.c
constr_CHOICE_print.c
constr_CHOICE_rfill.c
constr_CHOICE_uper.c
constr_CHOICE_xer.c
constr_SEQUENCE_aper.c
constr_SEQUENCE.c
constr_SEQUENCE_OF_aper.c
constr_SEQUENCE_OF.c
constr_SEQUENCE_OF_uper.c
constr_SEQUENCE_OF_xer.c
constr_SEQUENCE_print.c
constr_SEQUENCE_rfill.c
constr_SEQUENCE_uper.c
constr_SEQUENCE_xer.c
constr_SET_OF_aper.c
constr_SET_OF.c
constr_SET_OF_print.c
constr_SET_OF_rfill.c
constr_SET_OF_uper.c
constr_SET_OF_xer.c
constr_TYPE.c
der_encoder.c
GraphicString.c
INTEGER_aper.c
INTEGER.c
INTEGER_print.c
INTEGER_rfill.c
INTEGER_uper.c
INTEGER_xer.c
NativeEnumerated_aper.c
NativeEnumerated.c
NativeEnumerated_uper.c
NativeEnumerated_xer.c
NativeInteger_aper.c
NativeInteger.c
NativeInteger_print.c
NativeInteger_rfill.c
NativeInteger_uper.c
NativeInteger_xer.c
NULL_aper.c
NULL.c
NULL_print.c
NULL_rfill.c
NULL_uper.c
NULL_xer.c
ObjectDescriptor.c
OBJECT_IDENTIFIER.c
OBJECT_IDENTIFIER_print.c
OBJECT_IDENTIFIER_rfill.c
OBJECT_IDENTIFIER_xer.c
OCTET_STRING_aper.c
OCTET_STRING.c
OCTET_STRING_print.c
OCTET_STRING_rfill.c
OCTET_STRING_uper.c
OCTET_STRING_xer.c
OPEN_TYPE_aper.c
OPEN_TYPE.c
OPEN_TYPE_uper.c
OPEN_TYPE_xer.c
per_decoder.c
per_encoder.c
per_opentype.c
@@ -265,6 +323,7 @@ set(s1ap_source
S1AP_ExtendedRepetitionPeriod.c
S1AP_ExtendedRNC-ID.c
S1AP_Extended-UEIdentityIndexValue.c
S1AP_EXTERNAL.c
S1AP_FailureEventReport.c
S1AP_FailureEventReportingCause.c
S1AP_FiveGSTAC.c
@@ -673,6 +732,10 @@ set(s1ap_source
S1AP_WriteReplaceWarningRequest.c
S1AP_WriteReplaceWarningResponse.c
S1AP_X2TNLConfigurationInfo.c
uper_decoder.c
uper_encoder.c
uper_opentype.c
uper_support.c
xer_decoder.c
xer_encoder.c
xer_support.c
@@ -680,32 +743,36 @@ set(s1ap_source
set(s1ap_headers
ANY.h
aper_decoder.h
aper_encoder.h
aper_opentype.h
aper_support.h
asn_application.h
asn_bit_data.h
asn_codecs.h
asn_codecs_prim.h
asn_config.h
asn_internal.h
asn_ioc.h
asn_random_fill.h
asn_SEQUENCE_OF.h
asn_SET_OF.h
asn_system.h
ber_decoder.h
ber_tlv_length.h
ber_tlv_tag.h
BIT_STRING.h
BOOLEAN.h
constraints.h
constr_CHOICE.h
constr_SEQUENCE.h
constr_SEQUENCE_OF.h
constr_SET_OF.h
constr_TYPE.h
der_encoder.h
GraphicString.h
INTEGER.h
NativeEnumerated.h
NativeInteger.h
NULL.h
ObjectDescriptor.h
OBJECT_IDENTIFIER.h
OCTET_STRING.h
OPEN_TYPE.h
@@ -947,6 +1014,7 @@ set(s1ap_headers
S1AP_ExtendedRepetitionPeriod.h
S1AP_ExtendedRNC-ID.h
S1AP_Extended-UEIdentityIndexValue.h
S1AP_EXTERNAL.h
S1AP_FailureEventReport.h
S1AP_FailureEventReportingCause.h
S1AP_FiveGSTAC.h
@@ -1355,6 +1423,10 @@ set(s1ap_headers
S1AP_WriteReplaceWarningRequest.h
S1AP_WriteReplaceWarningResponse.h
S1AP_X2TNLConfigurationInfo.h
uper_decoder.h
uper_encoder.h
uper_opentype.h
uper_support.h
xer_decoder.h
xer_encoder.h
xer_support.h
-732
View File
@@ -1,732 +0,0 @@
import re, os, sys, string
import datetime
import getopt
import getpass
version = "1.0.2"
lines = ""
iesDefs = {}
ieofielist = {}
outdir = './'
filenames = []
verbosity = 0
prefix = ""
FAIL = '\033[91m'
WARN = '\033[93m'
ENDC = '\033[0m'
fileprefix = ""
fileprefix_first_upper = ""
def printFail(string):
sys.stderr.write(FAIL + string + ENDC + "\n")
def printWarning(string):
print WARN + string + ENDC
def printDebug(string):
if verbosity > 0:
print string
def outputHeaderToFile(f, filename):
now = datetime.datetime.now()
f.write("""/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
""")
f.write("/*******************************************************************************\n")
f.write(" * This file had been created by asn1tostruct.py script v%s\n" % (version))
f.write(" * Please do not modify this file but regenerate it via script.\n")
f.write(" * Created on: %s by %s\n * from %s\n" % (str(now), getpass.getuser(), filenames))
f.write(" ******************************************************************************/\n")
def lowerFirstCamelWord(word):
""" puts the first word in a CamelCase Word in lowercase.
I.e. CustomerID becomes customerID, XMLInfoTest becomes xmlInfoTest
"""
newstr = ''
swapped = word.swapcase()
idx = 0
# if it's all-caps, return an all-lowered version
lowered = word.lower()
if swapped == lowered:
return lowered
for c in swapped:
if c in string.lowercase:
newstr += c
idx += 1
else:
break
if idx < 2:
newstr += word[idx:]
else:
newstr = newstr[:-1]+ word[idx-1:]
return newstr
def usage():
print "Python parser for asn1 v%s" % (version)
print "Usage: python asn1tostruct.py [options]"
print "Available options:"
print "-d Enable script debug"
print "-f [file] Input file to parse"
print "-o [dir] Output files to given directory"
print "-h Print this help and return"
try:
opts, args = getopt.getopt(sys.argv[1:], "df:ho:", ["debug", "file", "help", "outdir"])
except getopt.GetoptError as err:
# print help information and exit:
usage()
sys.exit(2)
for o, a in opts:
if o in ("-f", "--file"):
filenames.append(a)
if o in ("-d", "--debug"):
verbosity = 1
if o in ("-o", "--outdir"):
outdir = a
if outdir.rfind('/') != len(outdir):
outdir += '/'
if o in ("-h", "--help"):
usage()
sys.exit(2)
for filename in filenames:
file = open(filename, 'r')
for line in file:
# Removing any comment
if line.find('--') >= 0:
line = line[:line.find('--')]
# Removing any carriage return
lines += re.sub('\r', '', line)
for m in re.findall(r'([a-zA-Z0-9-]+)\s*::=\s+SEQUENCE\s+\(\s*SIZE\s*\(\s*\d+\s*\.\.\s*[0-9a-zA-Z-]+\s*\)\s*\)\s*OF\s+[a-zA-Z-]+\s*\{\s*\{\s*([0-9a-zA-Z-]+)\s*\}\s*\}', lines, re.MULTILINE):
ieofielist[m[0]] = m[1]
for m in re.findall(r'([a-zA-Z0-9-]+)\s*::=\s+E-RAB-IE-ContainerList\s*\{\s*\{\s*([a-zA-Z0-9-]+)\s*\}\s*\}', lines, re.MULTILINE):
ieofielist[m[0]] = m[1]
for i in re.findall(r'([a-zA-Z0-9-]+)\s+([A-Z0-9-]+)\s*::=\s*\{\s+([\,\|\{\}\t\n\.{3}\ \-a-zA-Z0-9]+)\s+}\n', lines, re.MULTILINE):
ies = []
maxLength = 0
# TODO: handle extensions
if i[1].find('EXTENSION') >= 0:
continue
if fileprefix == "":
fileprefix = i[1][:i[1].find('-')].lower()
for j in re.findall(r'\s*\{\s*([a-zA-Z0-9-\ \t]+)\s*\}\s*[\|,]*', i[2], re.MULTILINE):
for k in re.findall(r'ID\s*([a-zA-Z0-9\-]+)\s*CRITICALITY\s*([a-zA-Z0-9\-]+)\s+[A-Z]+\s+([a-zA-Z0-9\-]+)\s*PRESENCE\s*([a-zA-Z0-9\-]+)', j, re.MULTILINE):
printDebug("Got new ie for message " + i[0] + ": " + str(k))
if len(k[2]) > maxLength:
maxLength = len(k[2])
ies.append(k)
if len(ies) > 0:
iesDefs[i[0]] = { "length": maxLength, "ies": ies }
else:
printWarning("Didn't find any information element for message: " + i[0])
if len(iesDefs) == 0:
printFail("No Information Element parsed, exiting")
sys.exit(0)
fileprefix_first_upper = fileprefix[0].upper() + fileprefix[1:]
f = open(outdir + fileprefix + '_ies_defs.h', 'w')
outputHeaderToFile(f, filename)
f.write("#include \"%s_common.h\"\n\n" % (fileprefix))
f.write("#ifndef %s_IES_DEFS_H_\n#define %s_IES_DEFS_H_\n\n" % (fileprefix.upper(), fileprefix.upper()))
f.write("/* Define the version of script used to generate this file */\n")
f.write("#define %s_SCRIPT_VERSION (%s)\n\n" % (fileprefix.upper(), re.sub('\.', '', version)))
for key in iesDefs:
if key not in ieofielist.values():
continue
for (i, j) in ieofielist.items():
if j == key:
break
f.write("typedef struct %sIEs_s {\n" % (re.sub('-', '_', i)))
f.write(" A_SEQUENCE_OF(struct %s_s) %s;\n" % (re.sub('IEs', '', re.sub('-', '_', ieofielist[i])), lowerFirstCamelWord(re.sub('IEs', '', re.sub('-', '_', ieofielist[i])))))
f.write("} %sIEs_t;\n\n" % (re.sub('-', '_', i)))
for key in iesDefs:
keyupperunderscore = re.sub('-', '_', key.upper())
keylowerunderscore = re.sub('-', '_', key.lower())
shift = 0
if len(iesDefs[key]["ies"]) == 0:
continue
# Presence mask
for ie in iesDefs[key]["ies"]:
ieupperunderscore = re.sub('-', '_', re.sub('id-', '', ie[0])).upper()
if ie[3] == "optional" or ie[3] == "conditional":
f.write("#define {0:<{pad}} {1}\n".format("%s_%s_PRESENT" % (keyupperunderscore, ieupperunderscore), "(1 << %d)" % shift,
pad=iesDefs[key]["length"] + len(keyupperunderscore) + 9))
shift += 1
if (shift > 0):
f.write("\n")
f.write("typedef struct %s_s {\n" % (re.sub('-', '_', key)))
if (shift > 0):
f.write(" {0:<{pad}} {1};\n".format("uint16_t", "presenceMask", pad=iesDefs[key]["length"] + 2))
for ie in iesDefs[key]["ies"]:
ieunderscore = re.sub('-', '_', ie[2])
iename = re.sub('id-', '', ie[0])
ienameunderscore = lowerFirstCamelWord(re.sub('-', '_', iename))
if ie[2] in ieofielist:
f.write(" %sIEs_t %s;" % (re.sub('-', '_', ie[2]), ienameunderscore))
else:
f.write(" {0:<{pad}} {1};".format("%s_t" % ieunderscore, ienameunderscore, pad=iesDefs[key]["length"] + 2))
if ie[3] == "optional":
f.write(" ///< Optional field")
elif ie[3] == "conditional":
f.write(" ///< Conditional field")
f.write("\n")
f.write("} %s_t;\n\n" % (re.sub('-', '_', key)))
f.write("typedef struct %s_message_s {\n" % (fileprefix))
f.write(" %s_ProcedureCode_t procedureCode;\n" % (fileprefix_first_upper))
f.write(" %s_Criticality_t criticality;\n" % (fileprefix_first_upper))
f.write(" uint8_t direction;\n")
f.write(" union {\n")
messageList = iesDefs.keys()
messageList.sort()
for message in messageList:
if message in ieofielist.values():
continue
if len(iesDefs[message]["ies"]) == 0:
continue
f.write(" %s_t %s;\n" % (re.sub('-', '_', message), lowerFirstCamelWord(re.sub('-', '_', message))))
f.write(" } msg;\n")
f.write("} %s_message;\n\n" % (fileprefix))
for key in iesDefs:
if key in ieofielist.values():
continue
structName = re.sub('ies', '', key)
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', re.sub('-IEs', '', key)))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
keylowerunderscore = re.sub('-', '_', key.lower())
firstlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
f.write("/* %s in iesDefs not in ieofielist.values() */\n" % (key))
f.write("/** \\brief Decode function for %s ies.\n" % (key))
if len(iesDefs[key]["ies"]) != 0:
f.write(" * \\param %s Pointer to ASN1 structure in which data will be stored\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" * \\param any_p Pointer to the ANY value to decode.\n")
f.write(" **/\n")
f.write("int %s_decode_%s(\n" % (fileprefix, keylowerunderscore))
if len(iesDefs[key]["ies"]) != 0:
f.write(" %s_t *%s,\n" % (re.sub('-', '_', key), lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" ANY_t *any_p);\n\n")
if len(iesDefs[key]["ies"]) == 0:
continue
f.write("/* %s in iesDefs not in ieofielist.values() */\n" % (key))
f.write("/** \\brief Encode function for %s ies.\n" % (key))
f.write(" * \\param %s Pointer to the ASN1 structure.\n" % (firstlower))
f.write(" * \\param %s Pointer to the IES structure.\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" **/\n")
f.write("int %s_encode_%s(\n" % (fileprefix, re.sub('-', '_', structName.lower())))
f.write(" %s_t *%s,\n" % (asn1cStruct, firstlower))
f.write(" %s_t *%s);\n\n" % (re.sub('-', '_', key), lowerFirstCamelWord(re.sub('-', '_', key))))
for key in iesDefs:
if key not in ieofielist.values():
continue
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', key))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
firstlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
f.write("/* %s in iesDefs in ieofielist.values() */\n" % (key))
f.write("/** \\brief Encode function for %s ies.\n" % (key))
f.write(" * \\param %s Pointer to the ASN1 structure.\n" % (firstlower))
f.write(" * \\param %s Pointer to the IES structure.\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" **/\n")
f.write("/* %s in iesDefs in ieofielist.values() */\n" % (key))
f.write("int %s_encode_%s(\n" % (fileprefix, firstlower.lower()))
f.write(" %s_t *%s,\n" % (asn1cStruct, firstlower))
f.write(" %sIEs_t *%sIEs);\n\n" % (asn1cStruct, firstlower))
f.write("/** \\brief Decode function for %s ies.\n" % (key))
f.write(" * \\param any_p Pointer to the ANY value to decode.\n")
f.write(" * \\param callback Callback function called when any_p is successfully decoded.\n")
f.write(" **/\n")
f.write("/* %s in iesDefs in ieofielist.values() */\n" % (key))
f.write("int %s_decode_%s(\n" % (fileprefix, firstlower.lower()))
f.write(" %sIEs_t *%sIEs,\n" % (asn1cStruct, firstlower))
f.write(" %s_t *%s);\n\n" % (asn1cStruct, lowerFirstCamelWord(asn1cStruct)))
for key in iesDefs:
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', key))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
firstlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
if key in ieofielist.values():
f.write("/** \\brief Display %s encapsulated IE using XER encoding.\n" % (asn1cStruct))
f.write(" * \\param %s Pointer to the IES structure.\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" * \\param file File descriptor to write output.\n")
f.write(" **/\n")
f.write("asn_enc_rval_t %s_xer_print_%s(\n" % (fileprefix, re.sub('item', 'list', firstlower.lower())))
f.write(" asn_app_consume_bytes_f *cb,\n")
f.write(" void *app_key,\n")
f.write(" %sIEs_t *%sIEs);\n\n" % (re.sub('item', 'list', asn1cStruct), firstlower))
else:
f.write("/** \\brief Display %s message using XER encoding.\n" % (asn1cStruct))
f.write(" * \\param message_p Pointer to root message.\n")
f.write(" * \\param file File descriptor to write output.\n")
f.write(" **/\n")
f.write("asn_enc_rval_t %s_xer_print_%s(\n" % (fileprefix, firstlower.lower()))
f.write(" asn_app_consume_bytes_f *cb,\n")
f.write(" void *app_key,\n")
f.write(" %s_message *message_p);\n\n" % (fileprefix))
f.write("int %s_xer__print2sp(const void *buffer, size_t size, void *app_key);\n\n" % (fileprefix.lower()))
f.write("int %s_xer__print2fp(const void *buffer, size_t size, void *app_key);\n\n" % (fileprefix.lower()))
f.write("extern size_t %s_string_total_size;\n\n" % (fileprefix.lower()))
f.write("#endif /* %s_IES_DEFS_H_ */\n\n" % (fileprefix.upper()))
#Generate Decode functions
f = open(outdir + fileprefix + '_decoder.c', 'w')
outputHeaderToFile(f, filename)
f.write("#include \"%s_common.h\"\n#include \"%s_ies_defs.h\"\n\n" % (fileprefix, fileprefix))
for key in iesDefs:
if key in ieofielist.values():
continue
structName = re.sub('ies', '', key)
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', key))
if asn1cStruct.rfind('_') == len(asn1cStruct) - 1:
asn1cStruct = asn1cStruct[:-1]
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
ielistname = re.sub('UE', 'ue', asn1cStruct)
ielistnamefirstlower = ielistname[:1].lower() + ielistname[1:]
asn1cStructfirstlower = asn1cStruct[:1].lower() + asn1cStruct[1:]
keyName = re.sub('-', '_', key)
keyupperunderscore = keyName.upper()
firstlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
iesaccess = ""
if key not in ieofielist.values():
iesaccess = "%s_ies." % (firstlower)
f.write("int %s_decode_%s(\n" % (fileprefix, re.sub('-', '_', structName.lower())))
if len(iesDefs[key]["ies"]) != 0:
f.write(" %s_t *%s,\n" % (re.sub('-', '_', key), lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" ANY_t *any_p) {\n\n")
f.write(" %s_t %s;\n %s_t *%s_p = &%s;\n" % (asn1cStruct, asn1cStructfirstlower, asn1cStruct, asn1cStructfirstlower, asn1cStructfirstlower))
f.write(" int i, decoded = 0;\n")
if len(iesDefs[key]["ies"]) != 0:
f.write(" int tempDecoded = 0;\n")
f.write(" assert(any_p != NULL);\n")
if len(iesDefs[key]["ies"]) != 0:
f.write(" assert(%s != NULL);\n\n" % (lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" %s_DEBUG(\"Decoding message %s (%%s:%%d)\\n\", __FILE__, __LINE__);\n\n" % (fileprefix.upper(), re.sub('-', '_', keyName)))
f.write(" ANY_to_type_aper(any_p, &asn_DEF_%s, (void**)&%s_p);\n\n" % (asn1cStruct, asn1cStructfirstlower))
f.write(" for (i = 0; i < %s_p->%slist.count; i++) {\n" % (asn1cStructfirstlower, iesaccess))
f.write(" %s_IE_t *ie_p;\n" % (fileprefix[0].upper() + fileprefix[1:]))
f.write(" ie_p = %s_p->%slist.array[i];\n" % (asn1cStructfirstlower, iesaccess))
f.write(" switch(ie_p->id) {\n")
for ie in iesDefs[key]["ies"]:
iename = re.sub('id-', '', ie[0])
ienameunderscore = lowerFirstCamelWord(re.sub('-', '_', iename))
ienameunderscorefirstlower = lowerFirstCamelWord(ienameunderscore)
ietypesubst = re.sub('-', '', ie[2])
ietypeunderscore = re.sub('-', '_', ie[2])
ieupperunderscore = re.sub('-', '_', re.sub('id-', '', ie[0])).upper()
if ie[3] == "optional":
f.write(" /* Optional field */\n")
elif ie[3] == "conditional":
f.write(" /* Conditional field */\n")
f.write(" case %s_ProtocolIE_ID_%s:\n" % (fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" {\n")
f.write(" %s_t *%s_p = NULL;\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
if ie[3] != "mandatory":
f.write(" %s->presenceMask |= %s_%s_PRESENT;\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), keyupperunderscore, ieupperunderscore))
f.write(" tempDecoded = ANY_to_type_aper(&ie_p->value, &asn_DEF_%s, (void**)&%s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" if (tempDecoded < 0 || %s_p == NULL) {\n" % (lowerFirstCamelWord(ietypesubst)))
f.write(" %s_ERROR(\"Decoding of IE %s failed\\n\");\n" % (fileprefix.upper(), ienameunderscore))
f.write(" if (%s_p)\n" % (lowerFirstCamelWord(ietypesubst)))
f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" decoded += tempDecoded;\n")
f.write(" if (asn1_xer_print)\n")
f.write(" xer_fprint(stdout, &asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
if ie[2] in ieofielist.keys():
f.write(" if (%s_decode_%s(&%s->%s, %s_p) < 0) {\n" % (fileprefix, ietypeunderscore.lower(), lowerFirstCamelWord(re.sub('-', '_', key)), ienameunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" %s_ERROR(\"Decoding of encapsulated IE %s failed\\n\");\n" % (fileprefix.upper(), lowerFirstCamelWord(ietypesubst)))
f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" }\n")
else:
f.write(" memcpy(&%s->%s, %s_p, sizeof(%s_t));\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), ienameunderscore, lowerFirstCamelWord(ietypesubst), ietypeunderscore))
#f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (ietypeunderscore, lowerFirstCamelWord(ietypesubst)))
f.write(" } break;\n")
f.write(" default:\n")
f.write(" %s_ERROR(\"Unknown protocol IE id (%%d) for message %s\\n\", (int)ie_p->id);\n" % (fileprefix.upper(), re.sub('-', '_', structName.lower())))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" }\n")
f.write(" return decoded;\n")
f.write("}\n\n")
for key in iesDefs:
if key not in ieofielist.values():
continue
keyname = re.sub('IEs', '', re.sub('Item', 'List', key))
f.write("int %s_decode_%s(\n" % (fileprefix, re.sub('-', '_', keyname).lower()))
f.write(" %sIEs_t *%sIEs,\n" % (re.sub('-', '_', keyname), lowerFirstCamelWord(re.sub('-', '_', keyname))))
f.write(" %s_t *%s) {\n\n" % (re.sub('-', '_', keyname), lowerFirstCamelWord(re.sub('-', '_', keyname))))
f.write(" int i, decoded = 0;\n")
f.write(" int tempDecoded = 0;\n\n")
f.write(" assert(%s != NULL);\n" % (lowerFirstCamelWord(re.sub('-', '_', keyname))));
f.write(" assert(%sIEs != NULL);\n\n" % (lowerFirstCamelWord(re.sub('-', '_', keyname))));
f.write(" for (i = 0; i < %s->list.count; i++) {\n" % (lowerFirstCamelWord(re.sub('-', '_', keyname))))
f.write(" %s_IE_t *ie_p = %s->list.array[i];\n" % (fileprefix[0].upper() + fileprefix[1:], lowerFirstCamelWord(re.sub('-', '_', keyname))))
f.write(" switch (ie_p->id) {\n")
for ie in iesDefs[key]["ies"]:
iename = re.sub('id-', '', ie[0])
ienameunderscore = lowerFirstCamelWord(re.sub('-', '_', iename))
f.write(" case %s_ProtocolIE_ID_%s:\n" % (fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" {\n")
f.write(" %s_t *%s_p = NULL;\n" % (re.sub('-', '_', ie[2]), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" tempDecoded = ANY_to_type_aper(&ie_p->value, &asn_DEF_%s, (void**)&%s_p);\n" % (re.sub('-', '_', ie[2]), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" if (tempDecoded < 0 || %s_p == NULL) {\n" % (lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" %s_ERROR(\"Decoding of IE %s for message %s failed\\n\");\n" % (fileprefix.upper(), ienameunderscore, re.sub('-', '_', keyname)))
f.write(" if (%s_p)\n" % (lowerFirstCamelWord(re.sub('-', '', ie[2]))))
#f.write(" free(%s_p);\n" % (lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" ASN_STRUCT_FREE(asn_DEF_%s, %s_p);\n" % (re.sub('-', '_', ie[2]), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" decoded += tempDecoded;\n")
f.write(" if (asn1_xer_print)\n")
f.write(" xer_fprint(stdout, &asn_DEF_%s, %s_p);\n" % (re.sub('-', '_', ie[2]), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" ASN_SEQUENCE_ADD(&%sIEs->%s, %s_p);\n" % (lowerFirstCamelWord(re.sub('-', '_', keyname)),
re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key))), lowerFirstCamelWord(re.sub('-', '', ie[2]))))
f.write(" } break;\n")
f.write(" default:\n")
f.write(" %s_ERROR(\"Unknown protocol IE id (%%d) for message %s\\n\", (int)ie_p->id);\n" % (fileprefix.upper(), re.sub('-', '_', structName.lower())))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" }\n")
f.write(" return decoded;\n")
f.write("}\n\n")
#Generate IES Encode functions
f = open(outdir + fileprefix + '_encoder.c', 'w')
outputHeaderToFile(f,filename)
f.write("#include \"%s_common.h\"\n" % (fileprefix))
f.write("#include \"%s_ies_defs.h\"\n\n" % (fileprefix))
for key in iesDefs:
if key in ieofielist.values():
continue
structName = re.sub('ies', '', key)
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', key))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
if asn1cStruct.rfind('_') == len(asn1cStruct) - 1:
asn1cStruct = asn1cStruct[:-1]
asn1cStructfirstlower = asn1cStruct[:1].lower() + asn1cStruct[1:]
firstwordlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
iesaccess = ""
if key not in ieofielist.values():
iesaccess = "%s_ies." % (firstwordlower)
keyName = re.sub('-', '_', key)
keyupperunderscore = keyName.upper()
# No IE to encode...
if len(iesDefs[key]["ies"]) == 0:
continue
f.write("int %s_encode_%s(\n" % (fileprefix, re.sub('-', '_', structName.lower())))
f.write(" %s_t *%s,\n" % (asn1cStruct, firstwordlower))
f.write(" %s_t *%s) {\n\n" % (re.sub('-', '_', key), lowerFirstCamelWord(re.sub('-', '_', key))))
f.write(" %s_IE_t *ie;\n\n" % (fileprefix_first_upper))
f.write(" assert(%s != NULL);\n" % (firstwordlower));
f.write(" assert(%s != NULL);\n\n" % (lowerFirstCamelWord(re.sub('-', '_', key))));
for ie in iesDefs[key]["ies"]:
iename = re.sub('-', '_', re.sub('id-', '', ie[0]))
ienameunderscore = re.sub('-', '_', iename)
ienamefirstwordlower = lowerFirstCamelWord(iename)
ieupperunderscore = re.sub('-', '_', re.sub('id-', '', ie[0])).upper()
ietypeunderscore = re.sub('-', '_', ie[2])
if ie[3] != "mandatory":
if ie[3] == "optional":
f.write(" /* Optional field */\n")
elif ie[3] == "conditional":
f.write(" /* Conditional field */\n")
f.write(" if (%s->presenceMask & %s_%s_PRESENT) {\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), keyupperunderscore, ieupperunderscore))
#f.write(" == %s_%s_PRESENT) {\n" % (keyupperunderscore, ieupperunderscore))
f.write(" if ((ie = %s_new_ie(%s_ProtocolIE_ID_%s,\n" % (fileprefix, fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" %s_Criticality_%s,\n" % (fileprefix_first_upper, ie[1]))
f.write(" &asn_DEF_%s,\n" % (ietypeunderscore))
f.write(" &%s->%s)) == NULL) {\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), ienamefirstwordlower))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" ASN_SEQUENCE_ADD(&%s->%slist, ie);\n" % (firstwordlower, iesaccess))
f.write(" }\n\n")
else:
if ie[2] in ieofielist.keys():
f.write(" %s_t %s;\n\n" % (ietypeunderscore, ienamefirstwordlower))
f.write(" memset(&%s, 0, sizeof(%s_t));\n" % (ienamefirstwordlower, ietypeunderscore))
f.write("\n")
f.write(" if (%s_encode_%s(&%s, &%s->%s) < 0) return -1;\n" % (fileprefix, ietypeunderscore.lower(), ienamefirstwordlower, lowerFirstCamelWord(re.sub('-', '_', key)), ienamefirstwordlower))
f.write(" if ((ie = %s_new_ie(%s_ProtocolIE_ID_%s,\n" % (fileprefix, fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" %s_Criticality_%s,\n" % (fileprefix_first_upper, ie[1]))
f.write(" &asn_DEF_%s,\n" % (ietypeunderscore))
if ie[2] in ieofielist.keys():
f.write(" &%s)) == NULL) {\n" % (ienamefirstwordlower))
else:
f.write(" &%s->%s)) == NULL) {\n" % (lowerFirstCamelWord(re.sub('-', '_', key)), ienamefirstwordlower))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" ASN_SEQUENCE_ADD(&%s->%slist, ie);\n\n" % (firstwordlower, iesaccess))
if ie[2] in ieofielist.keys():
f.write(" /* Free any dynamic allocation that is no more used */\n")
f.write(" ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_%s, &%s);\n\n" % (ietypeunderscore, ienamefirstwordlower))
f.write(" return 0;\n")
f.write("}\n\n")
for (key, value) in iesDefs.items():
if key not in ieofielist.values():
continue
ie = value["ies"][0]
ietypeunderscore = re.sub('-', '_', ie[2])
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', re.sub('-IEs', '', key)))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
firstwordlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
for (i, j) in ieofielist.items():
if j == key:
break
f.write("int %s_encode_%s(\n" % (fileprefix, re.sub('-', '_', i).lower()))
f.write(" %s_t *%s,\n" % (asn1cStruct, firstwordlower))
f.write(" %sIEs_t *%sIEs) {\n\n" % (re.sub('-', '_', i), lowerFirstCamelWord(re.sub('-', '_', i))))
f.write(" int i;\n")
f.write(" %s_IE_t *ie;\n\n" % (fileprefix_first_upper))
f.write(" assert(%s != NULL);\n" % (firstwordlower));
f.write(" assert(%sIEs != NULL);\n\n" % (lowerFirstCamelWord(re.sub('-', '_', i))));
f.write(" for (i = 0; i < %sIEs->%s.count; i++) {\n" % (firstwordlower, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
f.write(" if ((ie = %s_new_ie(%s_ProtocolIE_ID_%s,\n" % (fileprefix, fileprefix_first_upper, re.sub('-', '_', ie[0])))
f.write(" %s_Criticality_%s,\n" % (fileprefix_first_upper, ie[1]))
f.write(" &asn_DEF_%s,\n" % (ietypeunderscore))
f.write(" %sIEs->%s.array[i])) == NULL) {\n" % (firstwordlower, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
f.write(" return -1;\n")
f.write(" }\n")
f.write(" ASN_SEQUENCE_ADD(&%s->list, ie);\n" % (firstwordlower))
f.write(" }\n")
f.write(" return 0;\n")
f.write("}\n\n")
#Generate xer print functions
f = open(outdir + fileprefix + '_xer_print.c', 'w')
outputHeaderToFile(f, filename)
f.write("#include <stdlib.h>\n")
f.write("#include <stdio.h>\n\n")
f.write("#include <asn_application.h>\n#include <asn_internal.h>\n\n")
f.write("#include \"%s_common.h\"\n#include \"%s_ies_defs.h\"\n\n" % (fileprefix, fileprefix))
f.write("size_t %s_string_total_size = 0;\n\n" % (fileprefix.lower()))
f.write("""int
%s_xer__print2fp(const void *buffer, size_t size, void *app_key) {
FILE *stream = (FILE *)app_key;
if(fwrite(buffer, 1, size, stream) != size)
return -1;
return 0;
}
""" % (fileprefix.lower()))
f.write("""int %s_xer__print2sp(const void *buffer, size_t size, void *app_key) {
char *string = (char *)app_key;
/* Copy buffer to the formatted string */
memcpy(&string[%s_string_total_size], buffer, size);
%s_string_total_size += size;
return 0;
}
""" % (fileprefix.lower(), fileprefix.lower(), fileprefix.lower()))
f.write("""static asn_enc_rval_t
xer_encode_local(asn_TYPE_descriptor_t *td, void *sptr,
asn_app_consume_bytes_f *cb, void *app_key, int indent) {
asn_enc_rval_t er, tmper;
const char *mname;
size_t mlen;
int xcan = 2;
if(!td || !sptr) goto cb_failed;
mname = td->xml_tag;
mlen = strlen(mname);
ASN__TEXT_INDENT(0, indent);
ASN__CALLBACK3("<", 1, mname, mlen, ">", 1);
tmper = td->op->xer_encoder(td, sptr, indent + 1, XER_F_BASIC, cb, app_key);
if(tmper.encoded == -1) return tmper;
ASN__CALLBACK3("</", 2, mname, mlen, ">\\n", xcan);
er.encoded = 4 + xcan + (2 * mlen) + tmper.encoded;
ASN__ENCODED_OK(er);
cb_failed:
ASN__ENCODE_FAILED;
}
""")
for (key, value) in iesDefs.items():
keyName = re.sub('-', '_', key)
keyupperunderscore = keyName.upper()
iesStructName = lowerFirstCamelWord(re.sub('-', '_', key))
ie = value["ies"][0]
ietypeunderscore = re.sub('-', '_', ie[2])
if key in ieofielist.values():
f.write("asn_enc_rval_t %s_xer_print_%s(\n" % (fileprefix, re.sub('ies', '', re.sub('item', 'list', re.sub('-', '_', key).lower()))))
else:
f.write("asn_enc_rval_t %s_xer_print_%s(\n" % (fileprefix, re.sub('ies', '', re.sub('-', '_', key).lower())))
#f.write(" FILE *file,\n")
f.write(" asn_app_consume_bytes_f *cb,\n")
f.write(" void *app_key,\n")
if key in ieofielist.values():
iesStructName = lowerFirstCamelWord(re.sub('Item', 'List', re.sub('-', '_', key)))
f.write(" %sIEs_t *%s) {\n\n" % (re.sub('IEs', '', re.sub('Item', 'List', re.sub('-', '_', key))), iesStructName))
f.write(" int i;\n")
f.write(" asn_enc_rval_t er;\n")
else:
f.write(" %s_message *message_p)\n{\n" % (fileprefix))
f.write(" %s_t *%s;\n" % (re.sub('-', '_', key), iesStructName))
f.write(" asn_enc_rval_t er;\n")
#f.write(" void *app_key = (void *)file;\n")
#f.write(" asn_app_consume_bytes_f *cb = %s_xer__print2fp;\n\n" % (fileprefix.lower()))
f.write(" %s = &message_p->msg.%s;\n\n" % (iesStructName, iesStructName))
if key in ieofielist.values():
# Increase indentation level
f.write(" for (i = 0; i < %s->%s.count; i++) {\n" % (iesStructName, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
#f.write(" xer_fprint(file, &asn_DEF_%s, %s->%s.array[i]);\n" % (ietypeunderscore, iesStructName, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
f.write(" er = xer_encode(&asn_DEF_%s, %s->%s.array[i], XER_F_BASIC, cb, app_key);\n" % (ietypeunderscore, iesStructName, re.sub('IEs', '', lowerFirstCamelWord(re.sub('-', '_', key)))))
f.write(" }\n")
else:
f.write(" cb(\"<%s-PDU>\\n\", %d, app_key);\n" % (key, len("<%s-PDU>\n" % (key))))
f.write(" xer_encode_local(&asn_DEF_%s_Criticality, &message_p->criticality, cb, app_key, 1);\n" % fileprefix_first_upper)
f.write(" xer_encode_local(&asn_DEF_%s_ProcedureCode, &message_p->procedureCode, cb, app_key, 1);\n" % fileprefix_first_upper)
f.write(" cb(\" <%s>\\n\", %d, app_key);\n" % (key, len(" <%s>\n" % (key))))
for ie in iesDefs[key]["ies"]:
iename = re.sub('-', '_', re.sub('id-', '', ie[0]))
ienameunderscore = re.sub('-', '_', iename)
ienamefirstwordlower = lowerFirstCamelWord(iename)
ietypeunderscore = re.sub('-', '_', ie[2])
ieupperunderscore = re.sub('-', '_', re.sub('id-', '', ie[0])).upper()
if ie[3] != "mandatory":
if ie[3] == "optional":
f.write(" /* Optional field */\n")
elif ie[3] == "conditional":
f.write(" /* Conditional field */\n")
f.write(" if (%s->presenceMask & %s_%s_PRESENT)\n " % (iesStructName, keyupperunderscore, ieupperunderscore))
# Is it an encapsulated IE ?
if ie[2] in ieofielist.keys():
f.write(" %s_xer_print_%s(cb, app_key, &%s->%s);\n" % (fileprefix, re.sub('ies', '', re.sub('-', '_', ie[2]).lower()), iesStructName, ienamefirstwordlower))
else:
f.write(" xer_encode_local(&asn_DEF_%s, &%s->%s, cb, app_key, 2);\n" % (ietypeunderscore, iesStructName, ienamefirstwordlower))
f.write(" cb(\" </%s>\\n\", %d, app_key);\n" % (key, len(" </%s>\n" % (key))))
f.write(" cb(\"</%s-PDU>\\n\", %d, app_key);\n" % (key, len("</%s-PDU>\n" % (key))))
f.write(" ASN__ENCODED_OK(er);\n")
#if key not in ieofielist.values():
#f.write("cb_failed:\n")
#f.write(" return er;\n")
f.write("}\n\n")
#Generate xer print functions
f = open(outdir + fileprefix + '_compare.c', 'w')
outputHeaderToFile(f, filename)
f.write("#include <stdlib.h>\n")
f.write("#include <stdio.h>\n\n")
f.write("#include <asn_application.h>\n#include <asn_internal.h>\n\n")
f.write("#include \"%s_common.h\"\n#include \"%s_ies_defs.h\"\n" % (fileprefix, fileprefix))
f.write("#include \"%s-ProtocolIE-ID.h\"\n\n" % (fileprefix_first_upper))
for (key, value) in iesDefs.items():
if key not in ieofielist.values():
continue
ie = value["ies"][0]
ietypeunderscore = re.sub('-', '_', ie[2])
asn1cStruct = re.sub('-', '_', re.sub('IEs', '', re.sub('-IEs', '', key)))
asn1cStruct = re.sub('Item', 'List', asn1cStruct)
firstwordlower = re.sub('Item', 'List', re.sub('enb', 'eNB', lowerFirstCamelWord(asn1cStruct)))
for (i, j) in ieofielist.items():
if j == key:
break
f.write("extern asn_TYPE_descriptor_t asn_DEF_%s;\n" % (ietypeunderscore))
+1 -1
View File
@@ -10,7 +10,7 @@ else()
endif()
add_custom_command(OUTPUT ${s1ap_source} ${s1ap_headers}
COMMAND ASN1C_PREFIX=S1AP_ asn1c -gen-PER -no-gen-OER -fcompound-names -no-gen-example -fno-include-deps -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${S1AP_GRAMMAR}
COMMAND ASN1C_PREFIX=S1AP_ ${ASN1C_EXEC} -gen-APER -no-gen-BER -no-gen-JER -no-gen-OER -gen-UPER -fcompound-names -no-gen-example -fno-include-deps -D ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${S1AP_GRAMMAR}
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${S1AP_GRAMMAR}
COMMENT "Generating S1AP source files from ${CMAKE_CURRENT_SOURCE_DIR}/${S1AP_GRAMMAR}"
)