Encoding 24.301 Messages

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

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

            public SecProtMsgHeader secHdr;  // optional
            public L3HdrOptions l3HdrOpts;
            public ProtoDiscr protoDiscr = null;
            public PDU_pti pti;
            public _NAS_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.

l3HdrOpts holds the EPS Bearer identity (for Session Management messages) or the Security header type (for Mobility Management messages)

protoDiscr identifies whether the message is a Mobility Management or Session Management message. It will be either ProtoDiscr.epsSessMgmt() or ProtoDiscr.epsMobMgmt() (these are static enum values).

pti is the procedure transaction identity. It is only used for Session Management messages, but for Mobility Management messages it must be set to "no value".

msgType identifies the message type. This, together with protoDiscr, determines the actual type of the object in the data field. Class _TS24301MsgsValuesdefines 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.

The general procedure to encode a message is as follows:

  1. Create an instance of the generated PDU type (e.g. com.objsys.nas.TS24301Msgs.PDU) and the specific message type to be sent (e.g. com.objsys.nas.TS24301Msgs.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.TS24301Msgs.PDU pdu = new PDU();
   com.objsys.nas.TS24301Msgs.AuthRequest data = new AuthRequest();
   
   /* Populate data structure */  
   pdu.protoDiscr = ProtoDiscr.epsMobMgmt();
   pdu.pti = new PDU_pti(PDU_pti._NOVALUE, null);
   pdu.l3HdrOpts = new L3HdrOptions();
   pdu.l3HdrOpts.set_secHdr(new Asn1Integer(0));
   pdu.msgType = new _NAS_PROTOCOL_CLASS_msgType(_TS24301MsgsValues.mt_AuthRequest);
   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: