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 S1AP standard (TS 36.413 version 19.0.0).
It runs on Linux on x86-64 as an example and illustrates how to decode, inspect, and create LTE S1AP messages using the OSS ASN.1 Tools API.
The sample reads S1AP messages from .per files, decodes and prints them, and creates and encodes an S1AP message.
A makefile is included for building and running the test program using the OSS ASN.1/C runtime.
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. |
| *.asn | ASN.1 source files that describe the 3GPP LTE S1AP protocol (TS 36.413), used with this program example. |
| S1AP-PDU_HandoverRequest_bin.per | Valid PER-encoded S1AP message (HandoverRequest). It should pass testing. |
| ts1ap.c | Simple C program that shows how to work with LTE S1AP protocol data. It reads input messages from files, decodes and prints them, and creates and encodes an S1AP message. |
| makefile | Makefile that builds and runs the sample test. |
| makefile.rtoed | Makefile that builds and runs the sample test using RTOED. |
| gui/ | ASN.1 Studio project for viewing/compiling schema and generating sample data. |
(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 your shipment is runtime-only, generate the .c and .h files by running:
make cross
This creates a samples/cross directory with:
make
This command compiles the sample C source, links it with the OSS ASN.1 static library, and executes the test. To use another type of library in the shipment (such as a shared library), set the A makefile variable, for example:
make A=so
make clean
Note: The C 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.
The following listing shows the main C source file for this sample test program, ts1ap.c. It demonstrates how to read PER-encoded LTE S1AP 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. */
/*****************************************************************************/
/*
*Demonstrates work with data for S1 protocol of LTE
*/
#include <errno.h>
#include <string.h>
#include "s1ap_r19.h"
/* Names of Criticality values */
static const char *Criticalities[] = { "reject", "ignore", "notify" };
/* Names of HandoverType values */
static const char *HandoverType[] = {
"intralte", "ltetoutran", "ltetogeran", "utrantolte", "gerantolte"
};
#define printBorder() \
ossPrint(world, "-------------------------------------------------------\n")
/* The directory where input files reside. It is set to the command line parameter
* if any and to the directory where the sample is started, otherwise.
*/
char *filesDir;
/*
* FUNCTION reportError() prints error message and error code returned
* by any runtime API function.
*
* PARAMETERS
* world OSS environment variable
* where error origin
* errcode error code
* errmsg error message or NULL if ossGetErrMsg() should be used
* to get it
*
* RETURNS errcode
*/
static int reportError(OssGlobal *world, const char *where,
int errcode, const char *errmsg)
{
/* Error occured */
if (errcode) {
ossPrint(world, "%s failed, error code: %d\n", where, errcode);
/* Get and print error message */
if (errmsg || (world && NULL != (errmsg = ossGetErrMsg(world))))
ossPrint(world, "Error text: %s\n", errmsg);
}
return errcode;
}
/*
* FUNCTION Helper function to open file in the specified directory.
*
* PARAMETERS
* world OSS environment variable
* directoryName directory where fileName resides
* fileName file to open
*
* RETURNS pointer to file on success, NULL on failure
*/
FILE * openInputFile(OssGlobal *world, char *directoryName, const char *fileName)
{
char *path;
FILE *fv;
const char kPathSeparator =
#ifdef _WIN32
'\\';
#else
'/';
#endif
if (directoryName) {
size_t dLength = strlen(directoryName);
if (NULL == (path = ossGetMemory(world, dLength + strlen(fileName) + 2))) {
return NULL;
}
memcpy(path, directoryName, dLength);
if (path[dLength - 1] != kPathSeparator)
path[dLength++] = kPathSeparator;
strcpy(path+dLength, fileName);
} else {
path = (char *) fileName;
}
if (!(fv = fopen(path, "rb"))) {
ossPrint(world, "Failed to open the '%s' file. Restart the sample program using the file "
"location as the input parameter.\n", path);
}
if (path != fileName)
ossFreeMemory(world, path);
return fv;
}
/*
* FUNCTION readEncodingFromFile() reads serialized message from specified
* file
*
* PARAMETERS
* world OSS environment variable
* filename name of file containing serialized message
* encoding read message
*
* RETURNS 0 on success, error code on failure
*/
static int readEncodingFromFile(OssGlobal *world,
const char *filename, OssBuf *encoding)
{
FILE *in = openInputFile(world, filesDir, filename);
long length;
unsigned char *data;
if (!in)
return reportError(world, "fopen()", errno, strerror(errno));
if (fseek(in, 0, SEEK_END))
return reportError(world, "fseek()", errno, strerror(errno));
length = ftell(in);
if (length < 0)
return reportError(world, "ftell()", errno, strerror(errno));
/* Allocate memory to store completely read message in it */
data = ossGetMemory(world, (size_t)length);
if (!data) {
reportError(world, "ossGetMemory()", OUT_MEMORY, NULL);
fclose(in);
return OUT_MEMORY;
}
rewind(in);
if ((size_t)length != fread(data, sizeof(char), (size_t)length, in))
return reportError(world, "fread()", 1, NULL);
fclose(in);
/* Store read message in output argument */
encoding->value = data;
encoding->length = (size_t)length;
return 0;
}
/*****************************************************************************
* Printing functions below are intended to demonstrate how to access S1AP
* PDU components and to analyze their contents.
*****************************************************************************/
/*
* FUNCTION printHexString() prints data (octet string) as a sequence of
* hexadecimal digits 'XXXX...'H
*
* PARAMETERS
* world OSS environment variable
* length length of input data
* value pointer to input data
* indent indentation
*
* RETURNS 0 on success, error code on failure
*/
static int printHexString(OssGlobal *world,
unsigned int length, unsigned char *value, int indent)
{
unsigned int i, j,
max_pos = 74 - indent;
ossPrint(world, "'");
for (i = 0, j = 1; i < length; i++, j += 2) {
/* skip to next line when the current one is filled */
if (j >= max_pos) {
ossPrint(world, "'\n%*s'", indent, "");
j = 1;
}
ossPrint(world, "%02X", value[i]);
}
ossPrint(world, "'H");
return 0;
}
/* Prints a BIT STRING as a sequence of hexadecimal digits */
#define printHexBitString(ctx, length, value, indent)\
printHexString(ctx, (length + 7)/8, value, indent)
/*
* FUNCTION copyOctets() copies necessary number of bytes from input string
*
* PARAMETERS
* world OSS environment variable
* value pointer to input data
* length length of new string in bytes
* (number of bytes that should be copied from the input string)
*
* RETURNS copied string on success, NULL on failure
*/
static unsigned char *copyOctets(OssGlobal *world, unsigned char *value, OSS_UINT32 length)
{
unsigned char *return_value;
if (!length || NULL == (return_value = (unsigned char*)ossGetInitializedMemory(world, length)))
return NULL;
memcpy(return_value, value, length);
return return_value;
}
/*
* FUNCTION printProtocolExtensions() prints ProtocolExtensionContainer
* data. ossPrintPDU() is called to print PDU stored in
* an OpenType value.
*
* PARAMETERS
* world OSS environment variable
* ie_ext pointer to ProtocolExtensionContainer data to print
* indent indentation
*
* RETURNS 0 on success, error code on failure
*/
static int printProtocolExtensions(OssGlobal *world, struct OSS_S1AP_ProtExtContainer_ *ie_ext,
int indent)
{
size_t i;
ossPrint(world, "%*s%s includes the following IEs:\n", indent++, "",
"iE-Extensions");
/* Print each IE in the list */
for (i = 1; ie_ext; ie_ext = ie_ext->next, i++) {
OSS_S1AP_E_RABDataForwardingItem_ExtIEs_Extension *extval = &ie_ext->value.extensionValue;
ossPrint(world, "%*s#%d: id = %2u, criticality = %s\n", indent, "",
i, ie_ext->value.id, Criticalities[ie_ext->value.criticality]);
if (extval->pduNum && extval->decoded.other.pdu_S1AP_PDU)
ossPrintPDU(world, extval->pduNum, extval->decoded.other.pdu_S1AP_PDU);
else
ossPrint(world, "PDU is not decoded\n");
}
return 0;
}
/*
* FUNCTION printProtocolIEs() prints ProtocolIE_Container data.
* ossPrintPDU() is called to print IEs that are not
* handled by this function.
*
* PARAMETERS
* world OSS environment variable
* pdu input S1AP PDU which data should be printed
* ies pointer to ProtocolIE-Container data to print
* indent indentation
*
* RETURNS 0 on success, error code on failure
*/
static int printProtocolIEs(OssGlobal *world, struct OSS_S1AP_HndvrRequiredIEs_ *ies, int indent)
{
int err = 0;
int i;
ossPrint(world, "%*s%s includes the following IEs:\n", indent++, "",
"protocolIEs");
/* Print each IE */
for (i = 1; ies; ies = ies->next, i++) {
struct OSS_S1AP_HndvrRequiredIE *field = &ies->value;
OSS_S1AP_HandoverRequiredIEs_Value *value = &field->value;
ossPrint(world, "\n%*s#%d: id = %2u, criticality = %s\n", indent, "",
i, field->id, Criticalities[field->criticality]);
++indent;
/* Print MME-UE-S1AP-ID IE */
if (field->id == OSS_S1AP_id_MME_UE_S1AP_ID) {
ossPrint(world, "%*svalue %s: %u\n", indent, "", "MME-UE-S1AP-ID",
*field->value.decoded.pdu_MME_UE_S1AP_ID);
/* ENB-UE-S1AP-ID IE */
} else if (field->id == OSS_S1AP_id_eNB_UE_S1AP_ID) {
ossPrint(world, "%*svalue %s: %u\n", indent, "", "ENB-UE-S1AP-ID",
*field->value.decoded.pdu_ENB_UE_S1AP_ID);
/* HandoverType IE */
} else if (field->id == OSS_S1AP_id_HandoverType) {
ossPrint(world, "%*svalue %s: %s\n", indent, "", "HandoverType",
HandoverType[*field->value.decoded.pdu_HandoverType]);
/* Cause IE */
} else if (field->id == OSS_S1AP_id_Cause) {
OSS_S1AP_Cause *pcause = field->value.decoded.pdu_Cause;
/*
* Named values can be printed below instead of numbers for all
* Cause components
*/
ossPrint(world, "%*svalue %s: ", indent, "", "Cause");
/* radioNetwork */
if (pcause->choice == OSS_S1AP_radioNetwork_chosen)
ossPrint(world, "%s : %d", "radioNetwork",
pcause->u.radioNetwork);
/* transport */
else if (pcause->choice == OSS_S1AP_transport_chosen)
ossPrint(world, "%s : %d", "transport", pcause->u.transport);
/* nas */
else if (pcause->choice == OSS_S1AP_nas_chosen)
ossPrint(world, "%s : %d", "nas", pcause->u.nas);
/* protocol */
else if (pcause->choice == OSS_S1AP_protocol_chosen)
ossPrint(world, "%s : %d", "protocol", pcause->u.protocol);
/* misc */
else if (pcause->choice == OSS_S1AP_misc_chosen)
ossPrint(world, "%s : %d", "misc", pcause->u.misc);
ossPrint(world, "\n");
/* TargetID IE */
} else if (field->id == OSS_S1AP_id_TargetID) {
OSS_S1AP_TargetID *ptarget = field->value.decoded.pdu_TargetID;
ossPrint(world, "%*svalue %s : ", indent, "", "TargetID");
indent++;
/* targeteNB-ID */
if (ptarget->choice == OSS_S1AP_targeteNB_ID_chosen) {
OSS_S1AP_TargeteNB_ID *targeteNB_ID = &ptarget->u.targeteNB_ID;
ossPrint(world, "%s :", "targeteNB-ID");
/* global-ENB-ID */
ossPrint(world, "\n%*s%s: ", indent, "", "global-ENB-ID");
indent++;
/* pLMNidentity */
ossPrint(world, "\n%*s%s: ", indent, "", "pLMNidentity");
printHexString(world, targeteNB_ID->global_ENB_ID.pLMNidentity.length,
targeteNB_ID->global_ENB_ID.pLMNidentity.value, indent);
/* eNB-ID */
ossPrint(world, "\n%*s%s: ", indent, "", "eNB-ID");
if (targeteNB_ID->global_ENB_ID.eNB_ID.choice == OSS_S1AP_macroENB_ID_chosen) {
ossPrint(world, "%s: ", "macroENB-ID");
printHexBitString(world,
targeteNB_ID->global_ENB_ID.eNB_ID.u.macroENB_ID.length,
targeteNB_ID->global_ENB_ID.eNB_ID.u.macroENB_ID.value,
indent);
/* homeENB-ID */
} else if (targeteNB_ID->global_ENB_ID.eNB_ID.choice ==
OSS_S1AP_homeENB_ID_chosen) {
ossPrint(world, "%s: ", "homeENB-ID");
printHexBitString(world,
targeteNB_ID->global_ENB_ID.eNB_ID.u.homeENB_ID.length,
targeteNB_ID->global_ENB_ID.eNB_ID.u.homeENB_ID.value,
indent);
}
if (targeteNB_ID->global_ENB_ID.iE_Extensions)
printProtocolExtensions(world,
targeteNB_ID->global_ENB_ID.iE_Extensions, indent);
indent --;
/* selected-TAI */
ossPrint(world, "\n%*s%s: ", indent, "", "selected-TAI");
/* pLMNidentity */
indent ++;
ossPrint(world, "\n%*s%s: ", indent, "", "pLMNidentity");
printHexString(world, targeteNB_ID->selected_TAI.pLMNidentity.length,
targeteNB_ID->selected_TAI.pLMNidentity.value, indent);
/* tAC */
ossPrint(world, "\n%*s%s: ", indent, "", "tAC");
printHexString(world, targeteNB_ID->selected_TAI.tAC.length,
targeteNB_ID->selected_TAI.tAC.value, indent);
if (targeteNB_ID->selected_TAI.iE_Extensions)
printProtocolExtensions(world,
targeteNB_ID->selected_TAI.iE_Extensions, indent);
indent--;
ossPrint(world, "\n");
/* iE_Extensions is optional */
if (targeteNB_ID->iE_Extensions)
printProtocolExtensions(world, targeteNB_ID->iE_Extensions, indent);
/* targetRNC-ID */
} else if (ptarget->choice == OSS_S1AP_targetRNC_ID_chosen) {
OSS_S1AP_TargetRNC_ID *targetRNC_ID = &ptarget->u.targetRNC_ID;
ossPrint(world, "%s :", "targetRNC-ID");
/* lAI */
ossPrint(world, "\n%*s%s: ", indent, "", "lAI");
indent++;
/* pLMNidentity */
ossPrint(world, "\n%*s%s: ", indent, "", "pLMNidentity");
printHexString(world, targetRNC_ID->lAI.pLMNidentity.length,
targetRNC_ID->lAI.pLMNidentity.value, indent);
/* lAC */
ossPrint(world, "\n%*s%s: ", indent, "", "lAC");
printHexString(world, targetRNC_ID->lAI.lAC.length,
targetRNC_ID->lAI.lAC.value, indent);
ossPrint(world, "\n");
/* iE_Extensions is optional */
if (targetRNC_ID->lAI.iE_Extensions)
printProtocolExtensions(world,
targetRNC_ID->lAI.iE_Extensions, indent);
indent--;
/* rAC is optional */
if (targetRNC_ID->bit_mask & OSS_S1AP_TargetRNC_ID_rAC_present) {
ossPrint(world, "%*s%s: ", indent, "", "rAC");
printHexString(world, targetRNC_ID->rAC.length,
targetRNC_ID->rAC.value, indent);
}
/* rNC-ID */
ossPrint(world, "%*s%s: %u", indent, "", "rNC-ID",
targetRNC_ID->rNC_ID);
/* extendedRNC-ID is optional */
if (targetRNC_ID->bit_mask & OSS_S1AP_extendedRNC_ID_present)
ossPrint(world, "\n%*s%s: %u", indent, "", "extendedRNC-ID",
targetRNC_ID->extendedRNC_ID);
ossPrint(world, "\n");
/* cGI */
} else if (ptarget->choice == OSS_S1AP_cGI_chosen) {
OSS_S1AP_CGI *cGI = &ptarget->u.cGI;
ossPrint(world, "%s :", "cGI");
/* pLMNidentity */
ossPrint(world, "\n%*s%s: ", indent, "", "pLMNidentity");
printHexString(world, cGI->pLMNidentity.length,
cGI->pLMNidentity.value, indent);
/* lAC */
ossPrint(world, "\n%*s%s: ", indent, "", "lAC");
printHexString(world, cGI->lAC.length, cGI->lAC.value, indent);
/* cI */
ossPrint(world, "\n%*s%s: ", indent, "", "cI");
printHexString(world, cGI->cI.length, cGI->cI.value, indent);
/* rAC is optional */
if (cGI->bit_mask & OSS_S1AP_CGI_rAC_present) {
ossPrint(world, "\n%*s%s: ", indent, "", "rAC");
printHexString(world, cGI->rAC.length,
cGI->rAC.value, indent);
}
ossPrint(world, "\n");
}
indent--;
/* Direct-Forwarding-Path-Availability IE */
} else if (field->id == OSS_S1AP_id_Direct_Forwarding_Path_Availability) {
ossPrint(world, "%*svalue %s: %u\n", indent, "", "Direct-Forwarding-Path-Availability",
*field->value.decoded.pdu_Direct_Forwarding_Path_Availability);
/* other IEs are printed via OSS_S1AP_PrintDecoded() */
} else if (value->pduNum && value->decoded.pdu_MME_UE_S1AP_ID) {
ossPrint(world, "%*s", indent, "");
ossPrintPDU(world, value->pduNum, value->decoded.pdu_MME_UE_S1AP_ID);
} else
ossPrint(world, "PDU is not decoded\n");
indent--;
}
return err;
}
/*
* FUNCTION printHandoverRequiredMsg() prints S1AP pdu which contains
* HandoverRequired message. The function is not intended to
* handle other types of messages.
*
* PARAMETERS
* world OSS enviroonment variable
* pdu input S1AP PDU which data should be printed
*
* RETURNS 0 on success, error code on failure
*/
static int printHandoverRequiredMsg(OssGlobal *world, OSS_S1AP_PDU *pdu)
{
int msg_id;
OSS_S1AP_S1AP_ELEMENTARY_PROCEDURES_InitiatingMessage *msg_value;
OSS_S1AP_HandoverRequired *hr_value;
ossPrint(world, "\nGet message information\n");
printBorder();
/* Get identifier of message stored in PDU */
if (pdu->choice != OSS_S1AP_initiatingMessage_chosen) {
ossPrint(world, "Unexpected type of message");
return -1;
}
msg_value = &pdu->u.initiatingMessage.value;
msg_id = msg_value->pduNum;
if ( msg_id != OSS_S1AP_HandoverRequired_PDU) {
ossPrint(world, "Unexpected message id = %d\n", msg_id);
return -1;
} else {
hr_value = msg_value->decoded.pdu_HandoverRequired;
}
ossPrint(world, "Message id = %d (HandoverRequired)\n\n", msg_id);
if (!hr_value || !hr_value->protocolIEs) {
ossPrint(world, "Incorrect message \n");
return -1;
}
return printProtocolIEs(world, hr_value->protocolIEs, 0);
}
/*
* FUNCTION createSuccessResponse() creates S1AP successful outcome
* message for given HandoverRequired request.
*
* PARAMETERS
* world OSS environment variable
* req input message (request)
* resp pointer to the successful outcome message (response)
* created by the function
*
* RETURNS 0 on success, error code on failure
*/
static int createSuccessResponse(OssGlobal *world, OSS_S1AP_PDU *req,
OSS_S1AP_PDU **resp)
{
OSS_S1AP_E_RABItem *pitem_cmd_item;
OSS_S1AP_E_RABList plist_cmd_item;
OSS_S1AP_HndvrRequiredIEs reqies;
OSS_S1AP_HndvrCmdRequiredIEs respies;
OSS_S1AP_E_RABListElement *sing_cont;
OSS_S1AP_HandoverRequired *hr_value;
OSS_S1AP_SuccessfulOutcome *outcome_msg;
OSS_S1AP_HndvrCmdRequiredIE *ie_field;
OSS_S1AP_S1AP_ELEMENTARY_PROCEDURES_SuccessfulOutcome *ot_val;
OSS_S1AP_HandoverCommandIEs_Value *ot_val2;
OSS_S1AP_E_RABItemIEs_Value *ot_val3;
ossBoolean element_was_found;
ossPrint(world, "\nCreate response\n");
printBorder();
if (req->choice != OSS_S1AP_initiatingMessage_chosen) {
ossPrint(world, "Unexpected type of message");
return -1;
}
if (req->u.initiatingMessage.value.pduNum == 0
|| req->u.initiatingMessage.value.encoded.value) {
ossPrint(world, "Unexpected HandoverRequired request data");
return -1;
}
hr_value = req->u.initiatingMessage.value.decoded.pdu_HandoverRequired;
if (NULL == (reqies = hr_value->protocolIEs)) {
ossPrint(world, "No IEs in HandoverRequired request");
return -1;
}
/*
* Create successful outcome message from initiating message. Copy
* some IEs from input to output.
*/
*resp = ossGetInitializedMemory(world, sizeof(OSS_S1AP_PDU));
if (!*resp)
return reportError(world, "ossGetInitializedMemory for OSS_S1AP_PDU", OUT_MEMORY, NULL);
(*resp)->choice = OSS_S1AP_successfulOutcome_chosen;
outcome_msg = &(*resp)->u.successfulOutcome;
outcome_msg->procedureCode = req->u.initiatingMessage.procedureCode;
outcome_msg->criticality = OSS_S1AP_reject;
ot_val = &outcome_msg->value;
ot_val->pduNum = OSS_S1AP_HandoverCommand_PDU;
ot_val->decoded.pdu_HandoverCommand =
ossGetInitializedMemory(world, sizeof(OSS_S1AP_HandoverCommand));
if (!ot_val->decoded.pdu_HandoverCommand) {
/* Deallocate OSS_S1AP_PDU on error */
ossFreePDU(world, OSS_S1AP_PDU_PDU, *resp);
return reportError(world, "ossGetInitializedMemory for OSS_S1AP_HandoverCommand", OUT_MEMORY, NULL);
}
ot_val->decoded.pdu_HandoverCommand->protocolIEs =
ossGetInitializedMemory(world, sizeof(struct OSS_S1AP_HndvrCmdRequiredIEs_));
if (NULL == (respies = ot_val->decoded.pdu_HandoverCommand->protocolIEs)) {
/* Deallocate OSS_S1AP_PDU on error */
ossFreePDU(world, OSS_S1AP_PDU_PDU, *resp);
return reportError(world, "ossGetInitializedMemory for OSS_S1AP_ProtocolIE_Container", OUT_MEMORY, NULL);
}
for (element_was_found = FALSE; reqies; reqies = reqies->next) {
if (reqies->value.id == OSS_S1AP_id_eNB_UE_S1AP_ID ||
reqies->value.id == OSS_S1AP_id_MME_UE_S1AP_ID ||
reqies->value.id == OSS_S1AP_id_HandoverType) {
if (element_was_found) {
respies->next = ossGetInitializedMemory(world,
sizeof(struct OSS_S1AP_HndvrCmdRequiredIEs_));
if (!respies->next) {
/* Deallocate OSS_S1AP_PDU on error */
ossFreePDU(world, OSS_S1AP_PDU_PDU, *resp);
return reportError(world, "ossGetInitializedMemory for OSS_S1AP_ProtocolIE_Container",
OUT_MEMORY, NULL);
}
respies = respies->next;
}
if (reqies->value.id == OSS_S1AP_id_eNB_UE_S1AP_ID) {
respies->value.value.decoded.pdu_ENB_UE_S1AP_ID = ossGetInitializedMemory(world, sizeof(OSS_S1AP_ENB_UE_S1AP_ID));
if (!respies->value.value.decoded.pdu_ENB_UE_S1AP_ID) {
/* Deallocate OSS_S1AP_PDU on error */
ossFreePDU(world, OSS_S1AP_PDU_PDU, *resp);
return reportError(world, "ossGetInitializedMemory for OSS_S1AP_ENB_UE_S1AP_ID",
OUT_MEMORY, NULL);
}
respies->value.value.pduNum = OSS_S1AP_PDU_HandoverCommandIEs_Value_ENB_UE_S1AP_ID;
*respies->value.value.decoded.pdu_ENB_UE_S1AP_ID =
*reqies->value.value.decoded.pdu_ENB_UE_S1AP_ID;
} else if (reqies->value.id == OSS_S1AP_id_MME_UE_S1AP_ID) {
respies->value.value.decoded.pdu_MME_UE_S1AP_ID = ossGetInitializedMemory(world, sizeof(OSS_S1AP_MME_UE_S1AP_ID));
if (!respies->value.value.decoded.pdu_MME_UE_S1AP_ID) {
/* Deallocate OSS_S1AP_PDU on error */
ossFreePDU(world, OSS_S1AP_PDU_PDU, *resp);
return reportError(world, "ossGetInitializedMemory for OSS_S1AP_MME_UE_S1AP_ID",
OUT_MEMORY, NULL);
}
respies->value.value.pduNum = OSS_S1AP_PDU_HandoverCommandIEs_Value_MME_UE_S1AP_ID;
*respies->value.value.decoded.pdu_MME_UE_S1AP_ID =
*reqies->value.value.decoded.pdu_MME_UE_S1AP_ID;
} else {
respies->value.value.decoded.pdu_HandoverType = ossGetInitializedMemory(world, sizeof(OSS_S1AP_HandoverType));
if (!respies->value.value.decoded.pdu_HandoverType) {
/* Deallocate OSS_S1AP_PDU on error */
ossFreePDU(world, OSS_S1AP_PDU_PDU, *resp);
return reportError(world, "ossGetInitializedMemory for OSS_S1AP_HandoverType",
OUT_MEMORY, NULL);
}
respies->value.value.pduNum = OSS_S1AP_PDU_HandoverCommandIEs_Value_HandoverType;
*respies->value.value.decoded.pdu_HandoverType =
*reqies->value.value.decoded.pdu_HandoverType;
}
respies->value.id = reqies->value.id;
element_was_found = TRUE;
}
}
/* Add E-RABList IE to outcome message */
respies->next = ossGetInitializedMemory(world, sizeof(struct OSS_S1AP_HndvrCmdRequiredIEs_));
if (!respies->next) {
/* Deallocate OSS_S1AP_PDU on error */
ossFreePDU(world, OSS_S1AP_PDU_PDU, *resp);
return reportError(world, "ossGetInitializedMemory for OSS_S1AP_ProtocolIE_Container", OUT_MEMORY, NULL);
}
respies = respies->next;
ie_field = &respies->value;
ie_field->id = OSS_S1AP_id_E_RABtoReleaseListHOCmd;
ie_field->criticality = OSS_S1AP_ignore;
ot_val2 = &ie_field->value;
ot_val2->decoded.pdu_E_RABList = ossGetInitializedMemory(world, sizeof(OSS_S1AP_E_RABList));
if (!ot_val2->decoded.pdu_E_RABList) {
/* Deallocate OSS_S1AP_PDU on error */
ossFreePDU(world, OSS_S1AP_PDU_PDU, *resp);
return reportError(world, "ossGetInitializedMemory for OSS_S1AP_E_RABList", OUT_MEMORY, NULL);
}
*ot_val2->decoded.pdu_E_RABList =
ossGetInitializedMemory(world, sizeof(struct OSS_S1AP_E_RABList_));
if (!(*ot_val2->decoded.pdu_E_RABList)) {
/* Deallocate OSS_S1AP_PDU on error */
ossFreePDU(world, OSS_S1AP_PDU_PDU, *resp);
return reportError(world, "ossGetInitializedMemory for OSS_S1AP_E_RABList", OUT_MEMORY, NULL);
}
ot_val2->pduNum = OSS_S1AP_E_RABList_PDU;
plist_cmd_item = *ot_val2->decoded.pdu_E_RABList;
sing_cont = &plist_cmd_item->value;
sing_cont->id = OSS_S1AP_id_E_RABItem;
sing_cont->criticality = OSS_S1AP_ignore;
ot_val3 = &sing_cont->value;
ot_val3->decoded.pdu_E_RABItem = ossGetInitializedMemory(world, sizeof(OSS_S1AP_E_RABItem));
if (!ot_val3->decoded.pdu_E_RABItem) {
/* Deallocate OSS_S1AP_PDU on error */
ossFreePDU(world, OSS_S1AP_PDU_PDU, *resp);
return reportError(world, "ossGetInitializedMemory for OSS_S1AP_E_RABItem", OUT_MEMORY, NULL);
}
ot_val3->pduNum = OSS_S1AP_E_RABItem_PDU;
pitem_cmd_item = ot_val3->decoded.pdu_E_RABItem;
pitem_cmd_item->e_RAB_ID = 13;
pitem_cmd_item->cause.choice = OSS_S1AP_radioNetwork_chosen;
pitem_cmd_item->cause.u.radioNetwork = OSS_S1AP_x2_handover_triggered;
/* Add Target-ToSource-TransparentContainer IE to outcome message */
respies->next = ossGetInitializedMemory(world, sizeof(struct OSS_S1AP_HndvrCmdRequiredIEs_));
if (!respies->next) {
/* Deallocate OSS_S1AP_PDU on error */
ossFreePDU(world, OSS_S1AP_PDU_PDU, *resp);
return reportError(world, "ossGetInitializedMemory for OSS_S1AP_ProtocolIE_Container", OUT_MEMORY, NULL);
}
respies= respies->next;
ie_field = &respies->value;
ie_field->id = OSS_S1AP_id_Target_ToSource_TransparentContainer;
ie_field->criticality = OSS_S1AP_reject;
ot_val2 = &ie_field->value;
ot_val2->decoded.pdu_Target_ToSource_TransparentContainer =
ossGetInitializedMemory(world, sizeof(OSS_S1AP_Target_ToSource_TransparentContainer));
if (!ot_val2->decoded.pdu_Target_ToSource_TransparentContainer) {
/* Deallocate OSS_s1AP_PDU on error */
ossFreePDU(world, OSS_S1AP_PDU_PDU, *resp);
return reportError(world,
"ossGetInitializedMemory for OSS_S1AP_Target_ToSource_TransparentContainer", OUT_MEMORY, NULL);
}
ot_val2->pduNum = OSS_S1AP_Target_ToSource_TransparentContainer_PDU;
ot_val2->decoded.pdu_Target_ToSource_TransparentContainer->value =
copyOctets(world, (unsigned char*)"\x55", 1);
ot_val2->decoded.pdu_Target_ToSource_TransparentContainer->length = 1;
if (!(ot_val2->decoded.pdu_Target_ToSource_TransparentContainer->value)) {
/* Deallocate OSS_S1AP_PDU on error */
ossFreePDU(world, OSS_S1AP_PDU_PDU, *resp);
return reportError(world, "copyOctets", OUT_MEMORY, NULL);
}
return 0;
}
/*
* FUNCTION testS1AP() is used to test S1AP message, the input serialized
* pdu is deserialized and printed, then an outcome message
* is created, printed and encoded.
*
* PARAMETERS
* world OSS environment variable
* filename name of file containing serialized message
*
* RETURNS 0 on success, error code on failure
*/
static int testS1AP(OssGlobal *world, const char *filename)
{
OssBuf encoded_data;
int err, pdu_num = OSS_S1AP_PDU_PDU;
ossPrint(world, "======================================================"
"======================\n");
ossPrint(world, "Read encoding from file: %s\n\n", filename);
/* Read serialized message from file */
err = readEncodingFromFile(world, filename, &encoded_data);
if (!err) {
/*
* Zero deserilaized message pointer in order to allocate it
* in API call
*/
OSS_S1AP_PDU *req = NULL;
ossPrint(world, "Deserialize request\n");
printBorder();
/* Deserialize input message */
err = ossDecode(world, &pdu_num, &encoded_data, (void**)&req);
ossPrint(world, "\n");
/* Print error diagnostics if an error takes place */
if (err) {
reportError(world, "ossDecode()", err, NULL);
} else {
ossPrint(world, "Deserialized request\n");
printBorder();
/* Print deserialized message */
err = ossPrintPDU(world, OSS_S1AP_PDU_PDU, req);
ossPrint(world, "\n");
if (err)
reportError(world, "ossPrintPDU()", err, NULL);
/* Parse and print input message */
else if (0 == (err = printHandoverRequiredMsg(world, req))) {
OSS_S1AP_PDU *resp;
/* Create successful outcome message */
err = createSuccessResponse(world, req, &resp);
if (!err) {
OssBuf msg = { 0, NULL };
/* Print outcome message */
err = ossPrintPDU(world, OSS_S1AP_PDU_PDU, resp);
ossPrint(world, "\n");
ossPrint(world, "Serialize response\n");
printBorder();
/* Serialize outcome message */
err = ossEncode(world, OSS_S1AP_PDU_PDU, resp, &msg);
ossPrint(world, "\n");
if (err) {
reportError(world, "ossEncode()", err, NULL);
/* Print serialized outcome message */
} else {
ossPrint(world, "Serialized response (%ld bytes):\n",
msg.length);
printBorder();
printHexString(world, msg.length, msg.value, 0);
ossFreeMemory(world, msg.value);
ossPrint(world, "\n\n");
}
/* Free memory allocated for outcome message */
ossFreePDU(world, OSS_S1AP_PDU_PDU, resp);
}
}
}
/*
* Free memory allocated for input message if it is deserialized
* successfully
*/
if (req)
ossFreePDU(world, OSS_S1AP_PDU_PDU, req);
/* Free memory allocated for reading of input message from file */
ossFreeMemory(world, encoded_data.value);
}
return err;
}
/*
* Deserializes and prints input messages, creates and prints successful
* outcome messages
*/
int main(int argc, char *argv[])
{
OssGlobal world_data, *world = &world_data;
int err = 0;
err = ossinit(world, _oss_s1ap_control_table);
if (err)
return reportError(NULL, "ossinit()", err, NULL);
filesDir = argc > 1 ? argv[1] : ".";
/* Set flags */
ossSetFlags(world, AUTOMATIC_ENCDEC);
/* Set debug mode */
ossSetDebugFlags(world, PRINT_ERROR_MESSAGES | PRINT_DECODING_DETAILS | PRINT_ENCODING_DETAILS);
err = testS1AP(world, "S1AP-PDU_HandoverRequest_bin.per");
/* Free all resources */
ossterm(world);
if (!err)
printf("Testing successful.\n");
return err;
}
This is the expected output when running the sample:
Encoding response message... Encoding successful.
-- Excerpt from s1ap.asn 3GPP TS 36.413 V19.0.0 (2025-09)
-- Elementary Procedure definitions
--
-- **************************************************************
S1AP-PDU-Descriptions {
itu-t (0) identified-organization (4) etsi (0) mobileDomain (0)
eps-Access (21) modules (3) s1ap (1) version1 (1) s1ap-PDU-Descriptions (0)}
DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
-- **************************************************************
--
-- IE parameter types from other modules.
--
-- **************************************************************
IMPORTS
Criticality,
ProcedureCode
FROM S1AP-CommonDataTypes
CellTrafficTrace,
DeactivateTrace,
DownlinkUEAssociatedLPPaTransport,
DownlinkNASTransport,
DownlinkNonUEAssociatedLPPaTransport,
DownlinkS1cdma2000tunnelling,
ENBDirectInformationTransfer,
ENBStatusTransfer,
ENBConfigurationUpdate,
ENBConfigurationUpdateAcknowledge,
ENBConfigurationUpdateFailure,
ErrorIndication,
HandoverCancel,
HandoverCancelAcknowledge,
HandoverCommand,
HandoverFailure,
HandoverNotify,
HandoverPreparationFailure,
HandoverRequest,
HandoverRequestAcknowledge,
HandoverRequired,
InitialContextSetupFailure,
InitialContextSetupRequest,
InitialContextSetupResponse,
InitialUEMessage,
KillRequest,
KillResponse,
LocationReportingControl,
LocationReportingFailureIndication,
LocationReport,
MMEConfigurationUpdate,
MMEConfigurationUpdateAcknowledge,
MMEConfigurationUpdateFailure,
MMEDirectInformationTransfer,
MMEStatusTransfer,
NASNonDeliveryIndication,
OverloadStart,
OverloadStop,
Paging,
PathSwitchRequest,
PathSwitchRequestAcknowledge,
PathSwitchRequestFailure,
PrivateMessage,
Reset,
ResetAcknowledge,
S1SetupFailure,
S1SetupRequest,
S1SetupResponse,
E-RABModifyRequest,
E-RABModifyResponse,
E-RABModificationIndication,
E-RABModificationConfirm,
E-RABReleaseCommand,
E-RABReleaseResponse,
E-RABReleaseIndication,
E-RABSetupRequest,
E-RABSetupResponse,
TraceFailureIndication,
TraceStart,
UECapabilityInfoIndication,
UEContextModificationFailure,
UEContextModificationRequest,
UEContextModificationResponse,
UEContextReleaseCommand,
UEContextReleaseComplete,
UEContextReleaseRequest,
UERadioCapabilityMatchRequest,
UERadioCapabilityMatchResponse,
UplinkUEAssociatedLPPaTransport,
UplinkNASTransport,
UplinkNonUEAssociatedLPPaTransport,
UplinkS1cdma2000tunnelling,
WriteReplaceWarningRequest,
WriteReplaceWarningResponse,
ENBConfigurationTransfer,
MMEConfigurationTransfer,
PWSRestartIndication,
UEContextModificationIndication,
UEContextModificationConfirm,
RerouteNASRequest,
PWSFailureIndication,
UEContextSuspendRequest,
UEContextSuspendResponse,
UEContextResumeRequest,
UEContextResumeResponse,
UEContextResumeFailure,
ConnectionEstablishmentIndication,
NASDeliveryIndication,
RetrieveUEInformation,
UEInformationTransfer,
ENBCPRelocationIndication,
MMECPRelocationIndication,
SecondaryRATDataUsageReport,
UERadioCapabilityIDMappingRequest,
UERadioCapabilityIDMappingResponse,
HandoverSuccess,
ENBEarlyStatusTransfer,
MMEEarlyStatusTransfer,
S1RemovalFailure,
S1RemovalRequest,
S1RemovalResponse
FROM S1AP-PDU-Contents
id-CellTrafficTrace,
id-DeactivateTrace,
id-downlinkUEAssociatedLPPaTransport,
id-downlinkNASTransport,
id-downlinkNonUEAssociatedLPPaTransport,
id-DownlinkS1cdma2000tunnelling,
id-eNBStatusTransfer,
id-ErrorIndication,
id-HandoverCancel,
id-HandoverNotification,
id-HandoverPreparation,
id-HandoverResourceAllocation,
id-InitialContextSetup,
id-initialUEMessage,
id-ENBConfigurationUpdate,
id-Kill,
id-LocationReportingControl,
id-LocationReportingFailureIndication,
id-LocationReport,
id-eNBDirectInformationTransfer,
id-MMEConfigurationUpdate,
id-MMEDirectInformationTransfer,
id-MMEStatusTransfer,
id-NASNonDeliveryIndication,
id-OverloadStart,
id-OverloadStop,
id-Paging,
id-PathSwitchRequest,
id-PrivateMessage,
id-Reset,
id-S1Setup,
id-E-RABModify,
id-E-RABModificationIndication,
id-E-RABRelease,
id-E-RABReleaseIndication,
id-E-RABSetup,
id-TraceFailureIndication,
id-TraceStart,
id-UECapabilityInfoIndication,
id-UEContextModification,
id-UEContextRelease,
id-UEContextReleaseRequest,
id-UERadioCapabilityMatch,
id-uplinkUEAssociatedLPPaTransport,
id-uplinkNASTransport,
id-uplinkNonUEAssociatedLPPaTransport,
id-UplinkS1cdma2000tunnelling,
id-WriteReplaceWarning,
id-eNBConfigurationTransfer,
id-MMEConfigurationTransfer,
id-PWSRestartIndication,
id-UEContextModificationIndication,
id-RerouteNASRequest,
id-PWSFailureIndication,
id-UEContextSuspend,
id-UEContextResume,
id-ConnectionEstablishmentIndication,
id-NASDeliveryIndication,
id-RetrieveUEInformation,
id-UEInformationTransfer,
id-eNBCPRelocationIndication,
id-MMECPRelocationIndication,
id-SecondaryRATDataUsageReport,
id-UERadioCapabilityIDMapping,
id-HandoverSuccess,
id-eNBEarlyStatusTransfer,
id-MMEEarlyStatusTransfer,
id-S1Removal
FROM S1AP-Constants;
-- **************************************************************
--
-- Interface Elementary Procedure Class
--
-- **************************************************************
S1AP-ELEMENTARY-PROCEDURE ::= CLASS {
&InitiatingMessage ,
&SuccessfulOutcome OPTIONAL,
&UnsuccessfulOutcome OPTIONAL,
&procedureCode ProcedureCode UNIQUE,
&criticality Criticality DEFAULT ignore
}
WITH SYNTAX {
INITIATING MESSAGE &InitiatingMessage
[SUCCESSFUL OUTCOME &SuccessfulOutcome]
[UNSUCCESSFUL OUTCOME &UnsuccessfulOutcome]
PROCEDURE CODE &procedureCode
[CRITICALITY &criticality]
}
-- **************************************************************
--
-- Interface PDU Definition
--
-- **************************************************************
S1AP-PDU ::= CHOICE {
initiatingMessage InitiatingMessage,
successfulOutcome SuccessfulOutcome,
unsuccessfulOutcome UnsuccessfulOutcome,
...
}
InitiatingMessage ::= SEQUENCE {
procedureCode S1AP-ELEMENTARY-PROCEDURE.&procedureCode ({S1AP-ELEMENTARY-PROCEDURES}),
criticality S1AP-ELEMENTARY-PROCEDURE.&criticality ({S1AP-ELEMENTARY-PROCEDURES}{@procedureCode}),
value S1AP-ELEMENTARY-PROCEDURE.&InitiatingMessage ({S1AP-ELEMENTARY-PROCEDURES}{@procedureCode})
}
SuccessfulOutcome ::= SEQUENCE {
procedureCode S1AP-ELEMENTARY-PROCEDURE.&procedureCode ({S1AP-ELEMENTARY-PROCEDURES}),
criticality S1AP-ELEMENTARY-PROCEDURE.&criticality ({S1AP-ELEMENTARY-PROCEDURES}{@procedureCode}),
value S1AP-ELEMENTARY-PROCEDURE.&SuccessfulOutcome ({S1AP-ELEMENTARY-PROCEDURES}{@procedureCode})
}
UnsuccessfulOutcome ::= SEQUENCE {
procedureCode S1AP-ELEMENTARY-PROCEDURE.&procedureCode ({S1AP-ELEMENTARY-PROCEDURES}),
criticality S1AP-ELEMENTARY-PROCEDURE.&criticality ({S1AP-ELEMENTARY-PROCEDURES}{@procedureCode}),
value S1AP-ELEMENTARY-PROCEDURE.&UnsuccessfulOutcome ({S1AP-ELEMENTARY-PROCEDURES}{@procedureCode})
}
-- **************************************************************
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 S1AP 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.