Encoding 24.501 Messages

Encoding begins with a PDU ("Protocol Definition Unit") type which encompasses the messages for the corresponding specification.

Class PDU (com.objsys.nas.TS24501Msgs.PDU) has the following fields:

            public NAS5GSecProtMsgHdr secHdr;  // optional
            public NAS5GProtoDiscr protoDiscr = null;
            public PDU_hdrData hdrData;
            public _NAS5G_PROTOCOL_CLASS_msgType msgType;
            public Asn1Type data;
            public Asn1Null eom;            
        

The secHdr field is for use with security-protected messages, which are not currently supported for Java. This field will thus not be used.

protoDiscr identifies whether the message is a Mobility Management or Session Management message. It will be either NAS5GProtoDiscr.sessMgmt5G() or NAS5GProtoDiscr.mobMgmt5G() (these are static enum values).

hdrData will contain either a PDU_hdrData_mm or PDU_hdrData_sm, depending on the protocol.

msgType identifies the message type (not surprisingly). This, together with protoDiscr, determines the actual type of the object in the data field. Class _TS24501MsgsValuesdefines constants for the various messages (see code example below).

data holds the message payload. For example, for an Authentication Request message, it is an AuthRequest object. A lengthy comment in PDU.java identifies the Java type that should be in this field for each {protocol discriminator, message type} pair.

eom is not used. It is there as a result of the techniques used to model these non-ASN.1 messages in a way ASN1C can work with.

PDU_hdrData_mm also has a secHdrType field. The only supported value is NAS5GSecHdrType.noSec().

The general procedure to encode a message is as follows:

  1. Create an instance of the generated PDU type (e.g. com.objsys.nas.TS24501Msgs.PDU) and the specific message type to be sent (e.g. com.objsys.nas.TS24501Msgs.AuthRequest).

  2. Populate the types. For the PDU, set the header fields described above. Set the message object into the PDU's data field.

  3. Initialize the encode buffer.

  4. Call the PDU encode function

  5. Get the message from the buffer to work with the binary message.

An example with some comments follows. This example is based on the AuthRequest sample.

            /* Create the PDU and Message objects */
            com.objsys.nas.TS24501Msgs.PDU pdu = new PDU();
            com.objsys.nas.TS24501Msgs.AuthRequest data = new AuthRequest();
            
            /* Populate data structure */  
            pdu.protoDiscr = NAS5GProtoDiscr.mobMgmt5G();
            pdu.hdrData = new PDU_hdrData();
            PDU_hdrData_mm mmHeader = new PDU_hdrData_mm();
            pdu.hdrData.set_mm(mmHeader);
            
            mmHeader.secHdrType = NAS5GSecHdrType.noSec();
            mmHeader.spare1 = new Asn1Integer(0);
            
            pdu.msgType = new _NAS5G_PROTOCOL_CLASS_msgType(_TS24501MsgsValues.mt_AuthRequest5G);
            pdu.data = data;
            
            ...
            
            /* Create a message buffer object */
            
            Asn1NasEncodeBuffer encodeBuffer = new Asn1NasEncodeBuffer();
            
            /* Encode the PDU into the buffer */
            pdu.encode (encodeBuffer);
            
            /* Write message to a file.  You could also use encodeBuffer.getMsgCopy()
            to get the message into a byte array.
            */
            encodeBuffer.write (new FileOutputStream (filename));

Some general tips for encoding: