NAS RRC UsersGuide
NAS RRC UsersGuide
The software described in this document is furnished under a license agreement and may be used only in
accordance with the terms of this agreement. This document may be distributed in any form, electronic or
otherwise, provided that it is distributed in its entirety with the copyright and this notice intact. Comments,
suggestions, and inquiries may be sent by electronic mail to <[email protected]>.
• TS 24.008 - Mobile radio interface Layer 3 specification; Core network protocols; Stage 3
• TS 24.011 - Point-to-Point (PP) Short Message Service (SMS) support on mobile radio interface
• TS 24.301 - Non-Access-Stratum (NAS) protocol for Evolved Packet System (EPS); Stage 3
• TS 44.060 - Mobile Station (MS) - Base Station System (BSS) interface; Radio Link Control / Medium Access
Control (RLC/MAC) protocol
• TS 44.018 - Mobile radio interface layer 3 specification; Radio Resource Control (RRC) protocol
This document explains how to build and use this API using the add-on package available for the ASN1C Compiler.
Methodology
This API has been developed in the C programming language, using Objective Systems' ASN1C compiler to
generate the structures and encode/decode functions. The code was generated from a mixture of ASN.1 and
CSN.1 specifications. In cases where the relevant technical specifications did not use either ASN.1 or CSN.1,
we approximated the given message or information element using one of these notations. Since this was an
approximation, it was also necessary to use a combination of configuration directives and custom code to
achieve the desired results. The configuration directives are made effective by using the '-3gl3' command-line
option with ASN1C. Our white paper, "Using ASN.1 to Describe 3GPP Messages" [http://www.obj-sys.com/docs/
UsingASNtoDescribe3GPPMessages.pdf], describes how messages were approximated using ASN.1. (Note that this
paper does not reflect our more recently capability to directly compile CSN.1 notation.)
The end result is an API that consisted of C types and structures similar to what a user would get by compiling a standard
ASN.1 specification. The other benefit of this approach is that in addition to encode/decode functions, supporting
functions such as print, copy, compare, etc. can be generated from the definitions.
Note that one or more ASN.1 modules are associated with each of the above 3GPP specifications. In some of these
modules, PDU (“Protocol Definition Unit”) types are defined. These PDU types are used to represent an entire group
of (or possibly all) messages from that module. Common fields are also factored out into the PDU type.
The prefixes for each of the types in the API are given in the following table:
1
C Encode/Decode API for 3GPP Non-Access
Stratum (NAS) and Radio Resource Control (RRC)
The PDU types we have defined are given in the following table:
Table 2. PDUs
TS24008Msg_PDU PDU for the messages defined in 24.008
TS24011Msg_CP_PDU PDU for the CP messages defined in 24.011
TS24011Msg_RP_PDU PDU for the RP messages defined in 24.011
TS24301Msg_PDU PDU for the messages defined in 24.301
TS44018Msg_L2_PSEUDO_LEN_PDU PDU for 44.018 RRC messages using an L2 Pseudo
Length
TS44018Msg_RR_Short_PD_PDU PDU for 44.018 RRC messages using a short protocol
discriminator
TS44018Msg_DL_DCCH_PDU PDU for 44.018 RRC standard L3 messages transmitted
on the main DCCH from network to MS (downlink)
TS44018Msg_UL_DCCH_PDU PDU for 44.018 RRC standard L3 messages transmitted
on the main DCCH from MS to network (uplink)
TS44018Msg_UL_SACCH_PDU PDU for 44.018 RRC standard L3 messages transmitted
on the SACCH from MS to network (uplink)
Note that for 44.018 RRC messages, you must choose the PDU type according to the message format and (in some
cases) the channel and message direction.
nas_dev
|
+- custsrc
+- doc
|
+- debug
| +- build
| +- lib
|
+- release
| +- build
| +- lib
|
+- src
+- src2
+- test_ts24008_ies
+- test_ts24008_msgs
+- test_ts24301_msgs
+- test_ts44018_ies
+- test_ts44018_msgs
2
C Encode/Decode API for 3GPP Non-Access
Stratum (NAS) and Radio Resource Control (RRC)
+- util
In addition, 3GPP NAS and RRC ASN.1 and CSN.1 specifications are added to the specs subdirectory in folder 3GPP-
NAS.
1. Open a Visual Studio command-prompt Window and change directory (cd) to the c\nas_dev subdirectory with the
ASN1C hierarchy.
nmake
That should be all that is necessary. It will cause the ASN1C compiler to be invoked to generate C source code for
all of related ASN.1 and CSN.1 specifications. It will then compile the resulting files with Visual Studio C/C++
compiler. Resulting libraries in both debug and release configurations may be found in the debug\lib and release\lib
subdirectories respectively.
If you wish to build the API with a different version of Visual Studio instead of the default version, all that needs to
be done is moving the nas_dev folder from under the 'c' subdirectory to a different 'c_' subdirectory. So, for example,
if you wanted to build with Visual Studio 2012, you would move the nas_dev folder under c_vs2012 and execute the
procedure above.
1. From a terminal window, change directory (cd) to the c/nas_dev subdirectory within the installation.
make
Getting Started
The easiest way to get started is by examining the test_* subdirectories within the package. These contains test
programs for encoding and decoding all of the different message types defined in the standards. Typically, code from
within these samples can be used to form larger programs that can encode or decode larger message sets.
Sample Programs
Numerous sample programs are included in this package.
Sample programs for Windows can be built by using the Visual C++ nmake utility program to execute the provided
makefile. The procedure is as follows:
3
C Encode/Decode API for 3GPP Non-Access
Stratum (NAS) and Radio Resource Control (RRC)
cd c:\<acroot>\c\nas_dev\test_ts24008_msgs\Abort
3. Execute nmake:
nmake
The procedure would be similar on Linux except that the make utility would be used.
The result should be writer and reader programs. The writer should be executed first. It will encode a set of test data
and write the record out to a message.dat file. The reader program can then be executed (via reader -v) to read
the encoded file and decode the contents.
Encoding Messages
As mentioned above, the ASN.1 modules define one or more PDU (“Protocol Definition Unit”) types to encompass
all, or a subset of, the messages for the corresponding specification. Generally, the procedure for encoding is the same
for all PDU types. However, TS24301Msg_PDU does have some additional requirements related to NAS security.
The first 4 elements within this definition (l3HdrOpts, protoDiscr, sendSeqNum, and msgType) describe
header fields as defined in the TS 24.007 and TS 24.008 documents. The final data field is a variable type field that
defines the contents for all of the different message types. The combination of protocol discriminator and message
type serve to specify the message type.
1. Declare variables of the generated PDU type (e.g. TS24008Msg_PDU) and the specific message type to be sent
(e.g. TS24008Msg_IdentityRequest).
2. Populate the types. The address of the specific message structure would be stored within the PDU union structure.
The generated asn1SetTC_* (set table constraint) functions can be used to set fixed value fields (protocol
discriminator and message type) and the pointer to the message data in one call.
4
C Encode/Decode API for 3GPP Non-Access
Stratum (NAS) and Radio Resource Control (RRC)
3. Initialize the context structure and set the context buffer pointer.
5. Get the message pointer and length to work with the binary message.
Before a NAS encode function can be called, the user must first initialize an encoding context block structure. The
context block is initialized by calling the rtInitContext function.
Only memory-buffer based encoding is supported because the message sizes are generally small (normally less than
256 bytes).
To do memory-based encoding, the rtxInitContextBuffer function would be called. This can be used to specify
use of a static or dynamic memory buffer. Specification of a dynamic buffer is possible by setting the buffer address
argument to null and the buffer size argument to zero.
The PDU encode function can then be called to encode the message. If the return status indicates success (0), then the
message will have been encoded in the given buffer. The length of the encoded message can be obtained by calling the
rtxCtxtGetMsgLen run-time function. If dynamic encoding was specified (i.e., a buffer start address and length
were not given), the rtxCtxtGetMsgPtr run-time function can be used to obtain the start address of the message.
This routine will also return the length of the encoded message.
A program fragment that could be used to encode a 3G NAS Identity Request message is as follows:
main ()
{
TS24008Msg_PDU pdu;
TS24008Msg_IdentityRequest idReq;
OSCTXT ctxt;
OSOCTET msgbuf[256], *msgptr;
int i, len, stat;
const char* filename = "message.dat";
/* Populate C structure */
pdu.l3HdrOpts.u.skipInd = 0;
asn1SetTC_TS24008Msg_PDU_obj_IdentityRequest (&ctxt, &pdu, &idReq);
/* Encode */
5
C Encode/Decode API for 3GPP Non-Access
Stratum (NAS) and Radio Resource Control (RRC)
...
}
Encoding TS24301Msg_PDU
The procedure for encoding TS24301Msg_PDU is basically the same as given above. When the message is to be
encoded with security protection, however, there are a few additional requirements. These steps are not necessary
when encoding a message without security protection.
For security protected messages, including SERVICE REQUEST messages (which always have integrity protection):
The following code illustrates these steps. It encodes an ACTIVATE DEDICATED EPS BEARER CONTEXT
ACCEPT message with both integrity and confidentiality protection.
#include "TS24301Msgs.h"
#include "rt3gppsrc/rt3gppNasSec.h"
6
C Encode/Decode API for 3GPP Non-Access
Stratum (NAS) and Radio Resource Control (RRC)
asn1Init_TS24301Msg_PDU (&pdu);
...
7
C Encode/Decode API for 3GPP Non-Access
Stratum (NAS) and Radio Resource Control (RRC)
/* Encode data.
NASEnc_TS24301Msg_PDU will encrypt the message and compute the message
authentication code according to the security settings chosen above.
*/
...
rtx3gppSecFree(&ctxt);
...
}
When the message being security protected is a SERVICE REQUEST message, the above procedure is basically the
same, but a few differences do exist:
• TS24301Msg_ServiceRequest has its own secHdr field that is simply the security header type. This means
there are two fields (this one and TS24301Msg_PDU.secHdr.secHdrType) that have the security header
type; both should be set to TS24007L3_SecHdrType_secHdrForSvcReq.
• TS24301Msg_ServiceRequest has its own MAC field, shortMAC. This does not need to be set. It
will be assigned by NASEnc_TS24301Msg_PDU (TS24301Msg_PDU.secHdr.msgAuthCode will not be
assigned).
Decoding Messages
As mentioned above, the ASN.1 modules define one or more PDU (“Protocol Definition Unit”) types to encompass
all, or a subset of, the messages for the corresponding standard. Generally, the procedure for decoding is the same for
all PDU types. However, TS24301Msg_PDU does have some additional requirements related to NAS security.
4. Free the context after use of the decoded data is complete to free allocated memory structures
Before a NAS decode function can be called, the user must first initialize a context block structure. The context block
is initialized by calling the rtInitContext function.
8
C Encode/Decode API for 3GPP Non-Access
Stratum (NAS) and Radio Resource Control (RRC)
Only memory-buffer based encoding is supported for 3GPP layer 3 because the message sizes are generally small
(normally less than 256 bytes).
The PDU variable that is to receive the decoded data must then be initialized. This can be done by either initializing
the variable to zero using memset, or by calling the ASN1C generated initialization function.
The PDU decode function can then be called to decode the message. If the return status indicates success (0), then the
message will have been decoded into the PDU type variable. The decode function may automatically allocate dynamic
memory to hold variable length variables during the course of decoding. This memory will be tracked in the context
structure, so the programmer does not need to worry about freeing it. It will be released when the either the context is
freed or explicitly when the rtxMemFree or rtxMemReset function is called.
The final step of the procedure is to free the context block. This must be done regardless of whether the block is static
(declared on the stack and initialized using rtInitContext), or dynamic (created using rtNewContext). The
function to free the context is rtFreeContext.
main ()
{
TS24008Msg_PDU data;
OSCTXT ctxt;
OSOCTET* msgbuf;
const char* filename = "message.dat";
int stat;
OSSIZE len;
if (stat != 0) {
printf (“rtInitContext failed (check license)\n“);
rtErrPrint (&ctxt);
return stat;
}
9
C Encode/Decode API for 3GPP Non-Access
Stratum (NAS) and Radio Resource Control (RRC)
if (stat == 0)
{
process received data..
}
else {
/* error processing... */
rtxErrPrint (&ctxt);
}
Decoding TS24301Msg_PDU
The procedure for decoding TS24301Msg_PDU is basically the same as given above. When the encoded message is
security protected, however, there are a few additional requirements. These steps are not necessary when decoding a
message without security protection (but, unless you are certain the message is not security protected, you will need
to follow these requirements).
For security protected messages, including SERVICE REQUEST messages (which always have integrity protection):
Each of these steps is illustrated in the encoding example above. The NASDec_TS24301Msg_PDU function will:
• verify the message authentication code of an integrity protected message. The MAC (or short MAC) will be decoded
into either TS24301Msg_PDU.secHdr.msgAuthCode or TS24301Msg_ServiceRequest.shortMAC.
If MAC verification fails, RTERR_INVMAC is returned.
NAS Security
Functions NASDec_TS24301Msg_PDU and NASDec_TS24301Msg_PDU support security protected messages as
described in TS 24.301. This section provides some important details about this support.
First, TS 24.301 specifies multiple security algorithms that can be used for security protection. This API supports
two of them: the null algorithm and the AES-based algorithms. The algorithms based on SNOW3G and ZUC are not
currently supported.
10
C Encode/Decode API for 3GPP Non-Access
Stratum (NAS) and Radio Resource Control (RRC)
Finally, by design, you may provide your own implementation of the security functions exported by the asn1rt3gpp
library. This would be useful in any of the following situations:
• You want to use a different implementation of the AES algorithms than we have provided.
• You want to implement the algorithms we have not implemented (SNOW3G, ZUC).
If you choose to provide your own implementation, the functions to implement (declared and documented in
rt3gppNasSec.h) are:
• rtx3gppAssignAlgorithmKeys
• rtx3gppCipher
• rtx3gppComputeMAC
The msgType field determines the type of the value in the data field.
L2 Pseudo Length
For messges using the L2 pseudo length format, use the following PDU:
Fields protoDiscr and msgType determine the types of the values in data and restOctets.
11
C Encode/Decode API for 3GPP Non-Access
Stratum (NAS) and Radio Resource Control (RRC)
Tips
• All of the supported RRC messages have example code in test_ts44018_msgs
• There are a few messages that consist of nothing more than a single octet value (e.g. "Channel Request"). We haven't
defined a type for these messages.
• There are two messages that don't use any of the above formats and don't carry a message type. They are
"Synchronization Channel Information" and "COMPACT Synchronization Channel Information". For these, there
is no PDU type; you only need the message types to work with: TS44018Msg_SynchChannelInfo and
TS44018Msg_CompactSynchChannelInfo.
• src2/TS44018Misc.h declares several helper functions for working with ARFCN lists.
12