This sample is provided as part of the OSS ASN.1 Tools trial and commercial shipments. The source code and related files are listed below for reference.
The sample demonstrates how to use the OSS ASN.1 Tools to process messages for the 3GPP LTE RRC standard (TS 36.331 version 19.0.0).
It runs on Windows as an example and illustrates how to decode, inspect, and create PER Unaligned LTE RRC messages using the OSS ASN.1 Tools API.
The sample reads RRC messages from .uper files, decodes and prints them, accesses message components, and creates and encodes a response message.
A Windows batch script (run.bat) is included for running the test program.
To explore more samples (LTE RRC, 5G RRC, S1AP, X2AP, NGAP), visit the main Sample Code page.
This sample shows how to:
The files listed below are included in the OSS ASN.1 Tools trial and commercial shipments and are used by this sample program:
| File | Description |
|---|---|
| README.TXT | Instructions and sample overview. |
| rrc.asn | ASN.1 source file that describes the 3GPP LTE RRC protocol (TS 36.331), used with this program example. |
| ConnectionRelease.uper | Valid ConnectionRelease message encoded with PER Unaligned. |
| SecurityModeCommand.uper | Valid SecurityModeCommand message encoded with PER Unaligned. |
| LoggedMeasurementConfiguration.uper | Valid LoggedMeasurementConfiguration-r10 message encoded with PER Unaligned. |
| app.cs | Simple C# program that shows how to work with LTE RRC protocol data. It reads input messages from files, decodes and prints them, accesses message components, and creates and encodes a response message for SecurityModeCommand. |
| gui/ | ASN.1 Studio project for viewing/compiling schema and generating sample data. |
| run.bat | Windows batch script that runs the sample test. |
(Installation instructions for the OSS ASN.1 Tools are included in all trial and commercial shipments.)
To build and run this sample, install a trial or licensed version of the OSS ASN.1 Tools for C#.
If you use the OSS command prompt window, you do not need to set environment variables to run this sample. Otherwise, ensure the following are defined:
If using Visual Studio, run the Microsoft vsvars32.bat script to set up the .NET command-line environment. If Visual Studio is not installed, ensure your PATH includes the required .NET directories. For details, see ossvars.bat installed with the product.
run
run clean
Note: The C# source code in this sample is platform-independent.indows commands are shown as an example, but equivalent samples and run instructions may be available for other platforms. For help with platform-specific instructions, please contact OSS Support.
The following listing shows the main C# source file for this sample test program, app.cs. It demonstrates how to read PER-encoded LTE RRC messages from files, decode and print them, and create and encode a response message using the OSS ASN.1 Tools API.
///////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2025 OSS Nokalva, Inc. All rights reserved. //
// //
// THIS FILE IS PROPRIETARY MATERIAL OF OSS NOKALVA, INC. //
// AND MAY BE USED ONLY BY DIRECT LICENSEES OF OSS NOKALVA, INC. //
// THIS FILE MAY NOT BE DISTRIBUTED. //
// THIS COPYRIGHT STATEMENT MAY NOT BE REMOVED. //
///////////////////////////////////////////////////////////////////////////////
// THIS SAMPLE PROGRAM IS PROVIDED AS IS. THE SAMPLE PROGRAM AND ANY RESULTS //
// OBTAINED FROM IT ARE PROVIDED WITHOUT ANY WARRANTIES OR REPRESENTATIONS, //
// EXPRESS, IMPLIED OR STATUTORY. //
///////////////////////////////////////////////////////////////////////////////
// $Id: e3ae625d284b62dac83194f4ed3c7cd6bb6715c8
//
// Demonstrates part of RRC protocol layer of an LTE UE stack.
//
// Classes generated from ASN.1 specification.
using Rrc;
using Rrc.EUTRARRCDefinitions;
// Classes from the OSS runtime library.
using Oss.Asn1;
// C# system classes.
using System;
using System.Collections.Generic;
using System.IO;
public class Program
{
public static int Main(string[] args)
{
try
{
// A folder with encoded messages.
string dataDir = (args.Length > 0) ? args[0] : "../../";
Trrc trrc = new Trrc();
trrc.Process(dataDir, "ConnectionRelease.uper");
trrc.Process(dataDir, "SecurityModeCommand.uper");
trrc.Process(dataDir, "LoggedMeasurementConfiguration.uper");
Console.WriteLine("Message processing has completed successfully.");
}
catch (Exception e)
{
// Print complete exception information.
Console.WriteLine(e);
return 1;
}
return 0;
}
}
/// <summary>
/// This represents an incomplete implementation of UE-side function processing a downlink DCCH message.
/// It decodes the message, prints it, and creates a response for some particular alternatives.
/// The class can be used to implement a complete LTE RRC UE-side dispatcher.
/// </summary>
public class Trrc
{
PerUnalignedCodec codec = new PerUnalignedCodec();
/// <summary>
/// Processes an input file.
/// Decodes and prints the input messages.
/// Creates, encodes and prints the output (response) messages.
/// </summary>
public void Process(String dataDir, String fileName)
{
try
{
String fullPath = Path.Combine(dataDir, fileName);
DLDCCHMessage request = GetRequest(fullPath);
ULDCCHMessage response = GetResponse(request);
if (response != null)
Send(response);
Console.WriteLine();
}
catch (Exception e)
{
throw new Exception("Processing error for file: " + fileName, e);
}
}
/// <summary>
/// This methods decodes a DLDCCHMessage PDU from a file.
/// </summary>
DLDCCHMessage GetRequest(String fileName)
{
using (Stream stream = File.OpenRead(fileName))
{
Console.WriteLine("Decoding the DLDCCHMessage PDU from the file " + fileName + "...");
DLDCCHMessage request = new DLDCCHMessage();
codec.Decode(stream, request);
Console.WriteLine("PDU decoded successfully.");
return request;
}
}
/// <summary>
/// This method creates an UL_DCCH_Message PDU for a given DL_DCCH_Message PDU
/// </summary>
ULDCCHMessage GetResponse(DLDCCHMessage request)
{
// Checking message.
// The selected CHOICE alternative can be found by comparing the fields with null.
if (request.Message.C1 == null)
throw new Exception("Invalid message.");
// The selected CHOICE alternative can be found
// by comparing the Selected field with the corresponding enum items.
switch (request.Message.C1.Selected) {
// You can take unimplemented CHOICE alternatives one by one and add support for them
case DLDCCHMessageType.C1Type.Id.CsfbParametersResponseCDMA2000Chosen :
Console.WriteLine("Unimplemented.");
return null;
case DLDCCHMessageType.C1Type.Id.DlInformationTransferChosen :
Console.WriteLine("Unimplemented.");
return null;
case DLDCCHMessageType.C1Type.Id.HandoverFromEUTRAPreparationRequestChosen :
Console.WriteLine("Unimplemented.");
return null;
case DLDCCHMessageType.C1Type.Id.MobilityFromEUTRACommandChosen :
Console.WriteLine("Unimplemented.");
return null;
case DLDCCHMessageType.C1Type.Id.RrcConnectionReconfigurationChosen :
Console.WriteLine("Unimplemented.");
return null;
case DLDCCHMessageType.C1Type.Id.RrcConnectionReleaseChosen :
Console.WriteLine("Printing the decoded request RRCConnectionRelease...");
ValueNotationFormatter.Print(request, Console.Out);
return null;
case DLDCCHMessageType.C1Type.Id.SecurityModeCommandChosen :
Console.WriteLine("Printing the decoded request SecurityModeCommand...");
ValueNotationFormatter.Print(request, Console.Out);
return CreateSecurityModeCommandResponse(request);
case DLDCCHMessageType.C1Type.Id.UeCapabilityEnquiryChosen :
Console.WriteLine("Unimplemented.");
return null;
case DLDCCHMessageType.C1Type.Id.CounterCheckChosen :
Console.WriteLine("Unimplemented.");
return null;
case DLDCCHMessageType.C1Type.Id.UeInformationRequestR9Chosen :
Console.WriteLine("Unimplemented.");
return null;
case DLDCCHMessageType.C1Type.Id.LoggedMeasurementConfigurationR10Chosen :
Console.WriteLine("Printing the decoded request LoggedMeasurementConfigurationR10...");
ValueNotationFormatter.Print(request, Console.Out);
return null;
case DLDCCHMessageType.C1Type.Id.RnReconfigurationR10Chosen :
Console.WriteLine("The message is not intended for UE");
return null;
default:
Console.WriteLine("Unknown CHOICE alternative selected.");
return null;
}
}
/// <summary>
/// This method creates a "security mode complete" ULDCCHMessage PDU
/// for the given "security mode command" DL_DCCH_Message PDU.
/// </summary>
ULDCCHMessage CreateSecurityModeCommandResponse(DLDCCHMessage request)
{
Console.WriteLine("\nCreating the ULDCCHMessage response message...");
// Check if request is valid.
if (request.Message.C1 == null ||
request.Message.C1.SecurityModeCommand == null ||
request.Message.C1.SecurityModeCommand.CriticalExtensions.C1 == null ||
request.Message.C1.SecurityModeCommand.CriticalExtensions.C1.SecurityModeCommandR8 == null)
throw new Exception("Cannot handle ASN.1 data");
SecurityAlgorithmConfig config = request.Message.C1.
SecurityModeCommand.CriticalExtensions.C1.
SecurityModeCommandR8.SecurityConfigSMC.SecurityAlgorithmConfig;
switch (config.IntegrityProtAlgorithm) {
case SecurityAlgorithmConfig.IntegrityProtAlgorithmType.Eia0V920:
case SecurityAlgorithmConfig.IntegrityProtAlgorithmType.Eia1:
case SecurityAlgorithmConfig.IntegrityProtAlgorithmType.Eia2:
case SecurityAlgorithmConfig.IntegrityProtAlgorithmType.Eia3V1130:
break;
default:
throw new Exception("Unknown integrity protection");
}
switch (config.CipheringAlgorithm) {
case CipheringAlgorithmR12.Eea0:
case CipheringAlgorithmR12.Eea1:
case CipheringAlgorithmR12.Eea2:
case CipheringAlgorithmR12.Eea3V1130:
break;
default:
throw new Exception("Unknown ciphering");
}
SecurityModeComplete securityModeComplete = new SecurityModeComplete();
securityModeComplete.CriticalExtensions = new SecurityModeComplete.CriticalExtensionsType();
securityModeComplete.CriticalExtensions.SecurityModeCompleteR8 = new SecurityModeCompleteR8IEs();
securityModeComplete.RrcTransactionIdentifier = request.Message.C1.SecurityModeCommand.RrcTransactionIdentifier;
ULDCCHMessage response = new ULDCCHMessage();
response.Message = new ULDCCHMessageType();
response.Message.C1 = new ULDCCHMessageType.C1Type();
response.Message.C1.SecurityModeComplete = securityModeComplete;
Console.WriteLine("Response created successfully.");
Console.WriteLine("\nPrinting the created response...");
ValueNotationFormatter.Print(response, Console.Out);
return response;
}
/// <summary>
/// Encodes and sends a ULDCCHMessage message.
/// </summary>
void Send(ULDCCHMessage message)
{
using (MemoryStream stream = new MemoryStream())
{
Console.WriteLine("Encoding the response...");
codec.Encode(message, stream);
Console.WriteLine("Encoded successfully.\n");
// Print the encoded outcome message.
Console.WriteLine("Printing the response PDU in " + stream.Length + " bytes...");
Console.WriteLine(BitConverter.ToString(stream.ToArray()));
}
}
}
This is the expected output when running the sample:
Decoded ConnectionRelease: ... Decoded SecurityModeCommand: ... Encoding response message... Encoding successful.
-- Excerpt from rrc.asn 3GPP TS 36.331 V19.0.0 (2025-10)
EUTRA-RRC-Definitions DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
BCCH-BCH-Message ::= SEQUENCE {
message BCCH-BCH-MessageType
}
BCCH-BCH-MessageType ::= MasterInformationBlock
BCCH-BCH-Message-MBMS::= SEQUENCE {
message BCCH-BCH-MessageType-MBMS-r14
}
BCCH-BCH-MessageType-MBMS-r14 ::= MasterInformationBlock-MBMS-r14
BCCH-DL-SCH-Message ::= SEQUENCE {
message BCCH-DL-SCH-MessageType
}
BCCH-DL-SCH-MessageType ::= CHOICE {
c1 CHOICE {
systemInformation SystemInformation,
systemInformationBlockType1 SystemInformationBlockType1
},
messageClassExtension SEQUENCE {}
}
BCCH-DL-SCH-Message-BR ::= SEQUENCE {
message BCCH-DL-SCH-MessageType-BR-r13
}
BCCH-DL-SCH-MessageType-BR-r13 ::= CHOICE {
c1 CHOICE {
systemInformation-BR-r13 SystemInformation-BR-r13,
systemInformationBlockType1-BR-r13 SystemInformationBlockType1-BR-r13
},
messageClassExtension SEQUENCE {}
}
BCCH-DL-SCH-Message-MBMS ::= SEQUENCE {
message BCCH-DL-SCH-MessageType-MBMS-r14
}
BCCH-DL-SCH-MessageType-MBMS-r14 ::= CHOICE {
c1 CHOICE {
systemInformation-MBMS-r14 SystemInformation-MBMS-r14,
systemInformationBlockType1-MBMS-r14 SystemInformationBlockType1-MBMS-r14
},
messageClassExtension SEQUENCE {}
}
MCCH-Message ::= SEQUENCE {
message MCCH-MessageType
}
MCCH-MessageType ::= CHOICE {
c1 CHOICE {
mbsfnAreaConfiguration-r9 MBSFNAreaConfiguration-r9
},
later CHOICE {
c2 CHOICE{
mbmsCountingRequest-r10 MBMSCountingRequest-r10
},
messageClassExtension SEQUENCE {}
}
}
PCCH-Message ::= SEQUENCE {
message PCCH-MessageType
}
PCCH-MessageType ::= CHOICE {
c1 CHOICE {
paging Paging
},
messageClassExtension SEQUENCE {}
}
DL-CCCH-Message ::= SEQUENCE {
message DL-CCCH-MessageType
}
DL-CCCH-MessageType ::= CHOICE {
c1 CHOICE {
rrcConnectionReestablishment RRCConnectionReestablishment,
rrcConnectionReestablishmentReject RRCConnectionReestablishmentReject,
rrcConnectionReject RRCConnectionReject,
rrcConnectionSetup RRCConnectionSetup
},
messageClassExtension CHOICE {
c2 CHOICE {
rrcEarlyDataComplete-r15 RRCEarlyDataComplete-r15,
spare3 NULL, spare2 NULL, spare1 NULL
},
messageClassExtensionFuture-r15 SEQUENCE {}
}
}
DL-DCCH-Message ::= SEQUENCE {
message DL-DCCH-MessageType
}
DL-DCCH-MessageType ::= CHOICE {
c1 CHOICE {
csfbParametersResponseCDMA2000 CSFBParametersResponseCDMA2000,
dlInformationTransfer DLInformationTransfer,
handoverFromEUTRAPreparationRequest HandoverFromEUTRAPreparationRequest,
mobilityFromEUTRACommand MobilityFromEUTRACommand,
rrcConnectionReconfiguration RRCConnectionReconfiguration,
rrcConnectionRelease RRCConnectionRelease,
securityModeCommand SecurityModeCommand,
ueCapabilityEnquiry UECapabilityEnquiry,
counterCheck CounterCheck,
ueInformationRequest-r9 UEInformationRequest-r9,
loggedMeasurementConfiguration-r10 LoggedMeasurementConfiguration-r10,
rnReconfiguration-r10 RNReconfiguration-r10,
rrcConnectionResume-r13 RRCConnectionResume-r13,
dlDedicatedMessageSegment-r16 DLDedicatedMessageSegment-r16,
spare2 NULL, spare1 NULL
},
messageClassExtension SEQUENCE {}
}
UL-CCCH-Message ::= SEQUENCE {
message UL-CCCH-MessageType
}
UL-CCCH-MessageType ::= CHOICE {
c1 CHOICE {
rrcConnectionReestablishmentRequest RRCConnectionReestablishmentRequest,
rrcConnectionRequest RRCConnectionRequest
},
messageClassExtension CHOICE {
c2 CHOICE {
rrcConnectionResumeRequest-r13 RRCConnectionResumeRequest-r13
},
messageClassExtensionFuture-r13 CHOICE {
c3 CHOICE {
rrcEarlyDataRequest-r15 RRCEarlyDataRequest-r15,
spare3 NULL, spare2 NULL, spare1 NULL
},
messageClassExtensionFuture-r15 SEQUENCE {}
}
}
}
The gui/ subdirectory contains an ASN.1 Studio project for this sample. With ASN.1 Studio you can:
This sample is provided solely for illustration purposes, for example to demonstrate usage of the OSS ASN.1 Tools API with 3GPP LTE RRC messages. It does not represent a complete application. To build and run this sample, you must use a trial or licensed version of the appropriate OSS ASN.1 Tools. The copyright and license statements included in each source file remain fully applicable.
If you have questions about using this sample, contact OSS Nokalva Support.