LTE RRC Java Sample Code Using OSS ASN.1 Tools


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 Linux on x86-64 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 Unix shell script (run.sh) is included for running the test program using the OSS ASN.1/Java runtime.

To explore more samples (LTE RRC, 5G RRC, S1AP, X2AP, NGAP), visit the main Sample Code page.

Overview

This sample shows how to:

  • Initialize the OSS ASN.1/Java runtime for the LTE RRC schema.
  • Read .uper files that contain valid PER-encoded LTE RRC messages.
  • Decode and print LTE RRC messages.
  • Access RRC message components.
  • Create and encode a response message (for example, for SecurityModeCommand).
  • Run the sample test program using the provided run.sh script.

Files in This Sample

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 files that describe the 3GPP LTE RRC protocol (TS 36.331), used with this program example.
rrc-directives.dir Additional directives for rrc.asn.
RRCConnectionRelease.uper Valid RRCConnectionRelease message encoded with PER Unaligned.
SecurityModeCommand.uper Valid SecurityModeCommand message encoded with PER Unaligned.
LoggedMeasurementConfiguration.uper Valid LoggedMeasurementConfiguration-r10 message encoded with PER Unaligned.
Trrc.java Simple Java 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.
rrc.cmd ASN.1 compiler command file used to ASN.1-compile the LTE RRC specifications.
run.sh Unix shell script that runs the sample test.
sample.out Expected output from this test.
gui/ ASN.1 Studio project for viewing/compiling schema and generating sample data.

Build and Run Instructions

(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 Java.

1. Verify environment variables

Before running the test, ensure the following are set appropriately:

  • OSS_ASN1_JAVA
  • CLASSPATH
  • PATH
2. Run the sample
./run.sh
3. Clean up generated files
./run.sh cleanup
4. Other Platforms

Note: The Java source code in this sample is platform-independent. Linux commands are shown as an example, but equivalent samples and build instructions are available for Windows, macOS, and other platforms. For help with platform-specific instructions, please contact OSS Support.

Code Listing: Trrc.java

The following listing shows the main Java source file for this sample test program, Trrc.java. 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.

Show Trrc.java source code
/*****************************************************************************/
/* 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.
 */

import java.io.*;

import com.oss.asn1.*;
import com.oss.util.*;

import rrc.*;
import rrc.oss_rrc_eutra_rrc_definitions.*;

public class Trrc {

    static Coder coder;
    static String border = "-------------------------------------------------------";

    /*
     * Decodes and prints the input messages; creates, encodes and prints
     * the output (response) messages.
     */
    public static void main(String[] args)
    {
	// Initialize the project
	try {
	    Rrc.initialize();
	} catch (Exception e) {
	    System.out.println("Initialization exception: " + e);
	    System.exit(1);
	}

	coder = Rrc.getPERUnalignedCoder();
	coder.enableAutomaticEncoding();
	coder.enableAutomaticDecoding();
	coder.enableEncoderDebugging();
	coder.enableDecoderDebugging();

	// An optional parameter includes the path to all the files that are used by
	// the program.
	String path = (args.length > 0) ? args[0] : null;

	try {
	    testDL_DCCH_Message(path, "RRCConnectionRelease.uper");
	} catch (Exception e) {
	    System.out.println(e);
	}

	try {
	    testDL_DCCH_Message(path, "SecurityModeCommand.uper");
	} catch (Exception e) {
	    System.out.println(e);
	}

	try {
	    testDL_DCCH_Message(path, "LoggedMeasurementConfiguration.uper");
	} catch (Exception e) {
	    System.out.println(e);
	}

	System.out.println("\nTesting successful");
    }

    /*
     * Represents am imcomplete 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 function can be used
     * to implement a complete LTE RRC UE-side dispatcher.
     */
    static void testDL_DCCH_Message(String path, String filename) throws IOException, Exception
    {
	OSS_RRC_DL_DCCH_Message 	request;
	OSS_RRC_UL_DCCH_Message 	response;

	File file = new File(path, filename);
	if (!file.exists()) {
	    throw new IOException("Failed to open the " + file.toString() + " file. " +
		"Restart the sample program using as input parameter the name of the directory " +
		"where the '" + file.getName() + "' file is located.\n");
	}
	FileInputStream source = new FileInputStream(file);

	System.out.println("============================================================================");
	System.out.println("Read encoding from file: " + filename + "\n");
	System.out.println("Decoding the input downlink DCCH message");
	System.out.println(border);
	/* Deserialize input message */
        request = (OSS_RRC_DL_DCCH_Message)coder.decode(
    			    source, new OSS_RRC_DL_DCCH_Message());
	source.close();
	System.out.println("\nPDU decoded");

	if (!request.getMessage().hasC1()) {
	    throw new Exception("Incorrect message");
	}

	OSS_RRC_DL_DCCH_MessageType.C1 msg_typ =
		(OSS_RRC_DL_DCCH_MessageType.C1)
					request.getMessage().getChosenValue();
	System.out.println(border);
	switch (msg_typ.getChosenFlag()) {
	    /* You can take unimplemented CHOICE alternatives one by
	     * one and add support for them */
	    case OSS_RRC_DL_DCCH_MessageType.C1.csfbParametersResponseCDMA2000_chosen:
		System.out.println("Unimplemented");
		break;
	    case OSS_RRC_DL_DCCH_MessageType.C1.dlInformationTransfer_chosen:
		System.out.println("Unimplemented");
		break;
	    case OSS_RRC_DL_DCCH_MessageType.C1.handoverFromEUTRAPreparationRequest_chosen:
		System.out.println("Unimplemented");
		break;
	    case OSS_RRC_DL_DCCH_MessageType.C1.mobilityFromEUTRACommand_chosen:
		System.out.println("Unimplemented");
		break;
	    case OSS_RRC_DL_DCCH_MessageType.C1.rrcConnectionReconfiguration_chosen:
		System.out.println("Unimplemented");
		break;
	    case OSS_RRC_DL_DCCH_MessageType.C1.rrcConnectionRelease_chosen:
		/* Print deserialized message */
		System.out.println(request);
		break;
	    case OSS_RRC_DL_DCCH_MessageType.C1.securityModeCommand_chosen:
		/* Print deserialized message */
		System.out.println(request);
		System.out.println("Creating response");
		System.out.println(border);
		/* Create response */
		response = createSecurityModeCommandResponse(request);

		System.out.println();
		System.out.println("Response created successfully");
		System.out.println(border);
		/* Print outcome message */
		System.out.println(response);
		System.out.println("Encoding response");
		System.out.println(border);
		/* Serialize outcome message */
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		try {
		    coder.encode(response, out);
		    out.close();
		} catch (Exception e) {
		    System.out.println("Encoding failed: " + e);
		    System.exit(1);
		}

		/* Print serialized outcome message */
		System.out.println("\nEncoded response "
				+ "(" + out.size() + " bytes):");
		System.out.println(HexTool.getHex(out.toByteArray()));

		break;
	    case OSS_RRC_DL_DCCH_MessageType.C1.ueCapabilityEnquiry_chosen:
		System.out.println("Unimplemented");
		break;
	    case OSS_RRC_DL_DCCH_MessageType.C1.counterCheck_chosen:
		System.out.println("Unimplemented");
		break;
	    case OSS_RRC_DL_DCCH_MessageType.C1.ueInformationRequest_r9_chosen:
		System.out.println("Unimplemented");
		break;
	    case OSS_RRC_DL_DCCH_MessageType.C1.loggedMeasurementConfiguration_r10_chosen:
		System.out.println(request);
		break;
	    case OSS_RRC_DL_DCCH_MessageType.C1.rnReconfiguration_r10_chosen:
		System.out.println("The message is not intended for UE");
		break;
	    default:
		System.out.println("Unknown CHOICE alternative selected");
		break;
	}
    }

    /*
     * Creates an OSS_RRC_UL_DCCH_Message PDU (security mode complete)
     * for given OSS_RRC_DL_DCCH_Message PDU (security mode command).
     */
    static OSS_RRC_UL_DCCH_Message createSecurityModeCommandResponse(
				OSS_RRC_DL_DCCH_Message request)
    throws IOException, Exception
    {
	OSS_RRC_SecurityAlgorithmConfig.IntegrityProtAlgorithm ipalg;
	OSS_RRC_CipheringAlgorithm_r12 calg;

	if (!request.getMessage().hasC1()
	    || !((OSS_RRC_DL_DCCH_MessageType.C1)
		request.getMessage().getChosenValue()).hasSecurityModeCommand()
	    || !((OSS_RRC_SecurityModeCommand)((OSS_RRC_DL_DCCH_MessageType.C1)
	    	    request.getMessage().getChosenValue()).getChosenValue()
	    	).getCriticalExtensions().hasC1()
	    || !((OSS_RRC_SecurityModeCommand.CriticalExtensions.C1)
		((OSS_RRC_SecurityModeCommand)((OSS_RRC_DL_DCCH_MessageType.C1)
	    	    request.getMessage().getChosenValue()).getChosenValue()
	        ).getCriticalExtensions().getChosenValue()).hasSecurityModeCommand_r8()
	   )
	    throw new Exception("cannot handle ASN.1 data");



	ipalg = ((OSS_RRC_SecurityModeCommand_r8_IEs)
		((OSS_RRC_SecurityModeCommand.CriticalExtensions.C1)((OSS_RRC_SecurityModeCommand)
		 ((OSS_RRC_DL_DCCH_MessageType.C1)request.getMessage().getChosenValue()
		 ).getChosenValue()).getCriticalExtensions().getChosenValue()).getChosenValue()
		).getSecurityConfigSMC().getSecurityAlgorithmConfig().getIntegrityProtAlgorithm();

	calg = ((OSS_RRC_SecurityModeCommand_r8_IEs)
		((OSS_RRC_SecurityModeCommand.CriticalExtensions.C1)((OSS_RRC_SecurityModeCommand)
		 ((OSS_RRC_DL_DCCH_MessageType.C1)request.getMessage().getChosenValue()
		 ).getChosenValue()).getCriticalExtensions().getChosenValue()).getChosenValue()
		).getSecurityConfigSMC().getSecurityAlgorithmConfig().getCipheringAlgorithm();

	if (ipalg != OSS_RRC_SecurityAlgorithmConfig.IntegrityProtAlgorithm.eia0_v920
		&& ipalg != OSS_RRC_SecurityAlgorithmConfig.IntegrityProtAlgorithm.eia1
		&& ipalg != OSS_RRC_SecurityAlgorithmConfig.IntegrityProtAlgorithm.eia2)
	    throw new Exception("unknown integrity protection");

	if (calg != OSS_RRC_CipheringAlgorithm_r12.eea0
		&& calg != OSS_RRC_CipheringAlgorithm_r12.eea1
		&& calg != OSS_RRC_CipheringAlgorithm_r12.eea2)
	    throw new Exception("unknown ciphering");

	OSS_RRC_RRC_TransactionIdentifier transactionIdentifier =
	    ((OSS_RRC_SecurityModeCommand)((OSS_RRC_DL_DCCH_MessageType.C1)
		request.getMessage().getChosenValue()).getChosenValue()).getRrc_TransactionIdentifier();
	OSS_RRC_SecurityModeComplete.CriticalExtensions criticalExtensions =
	    OSS_RRC_SecurityModeComplete.CriticalExtensions.
		createCriticalExtensionsWithSecurityModeComplete_r8(
		    new OSS_RRC_SecurityModeComplete_r8_IEs());
	OSS_RRC_SecurityModeComplete securityModeComplete =
	    new OSS_RRC_SecurityModeComplete(transactionIdentifier, criticalExtensions);
	OSS_RRC_UL_DCCH_MessageType.C1 c1 =
	    OSS_RRC_UL_DCCH_MessageType.C1.createC1WithSecurityModeComplete(securityModeComplete);
	OSS_RRC_UL_DCCH_MessageType message =
	    OSS_RRC_UL_DCCH_MessageType.createOSS_RRC_UL_DCCH_MessageTypeWithC1(c1);
	OSS_RRC_UL_DCCH_Message response = new OSS_RRC_UL_DCCH_Message(message);

	return response;
    }
}

Expected Output (Excerpt)

This is the expected output when running the sample:

Decoded RRCConnectionRelease:
  rrc-TransactionId = 1
  criticalExtensions = ...
Encoding response message...
Encoding successful.

ASN.1 Schema Excerpt (rrc.asn)

Show excerpt from rrc.asn
-- 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 {}
		}
	}
}

Using ASN.1 Studio (Optional)

The gui/ subdirectory contains an ASN.1 Studio project for this sample. With ASN.1 Studio you can:

  • Open the LTE RRC ASN.1 modules.
  • Generate code from the ASN.1 schema.
  • Create and edit sample encoded LTE RRC messages.
  • Export projects to a shell script. When exporting trrc.a1sproj, specify Trrc as the "Class or .jar name to execute".

Related Samples

Disclaimer

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.

Need Help?

If you have questions about using this sample, contact OSS Nokalva Support.

See Also