lte/gateway/c/core/oai/tasks/amf/nas5g_message.cpp
/****************************************************************************
 **                                                                        **
 ** Name:  _nas5g_message_protected_encode()                               **
 **                                                                        **
 ** Description: Encode security protected NAS message                     **
 **                                                                        **
 ** Inputs    msg:     Security protected NAS message structure            **
 **                    to encode                                           **
 **           length:  Maximal capacity of the output buffer               **
 **           Others:  None                                                **
 **                                                                        **
 ** Outputs:  buffer:  Pointer to the encoded data buffer                  **
 ** Return:   The number of bytes in the buffer if the                     **
 **           data have been successfully encoded;                         **
 **           A negative error code otherwise.                             **
 ** Others:   None                                                         **
 **                                                                        **
 ***************************************************************************/


Encode security protected NAS message

Inputs    msg:     Security protected NAS message structure
to encode
length:  Maximal capacity of the output buffer
Others:  None

Pointer to the encoded data buffer
Return:   The number of bytes in the buffer if the
data have been successfully encoded;
A negative error code otherwise.
Others:   None
Encode security protected NAS message Inputs msg : Security protected NAS message structure to encode length : Maximal capacity of the output buffer Others : None Pointer to the encoded data buffer Return : The number of bytes in the buffer if the data have been successfully encoded ; A negative error code otherwise . Others : None
static int _nas5g_message_protected_encode(
    unsigned char* buffer, const nas_message_security_protected_t* msg,
    uint32_t length, void* security) {
  OAILOG_FUNC_IN(LOG_AMF_APP);
  amf_security_context_t* amf_security_context =
      (amf_security_context_t*) security;
  int bytes                = TLV_BUFFER_TOO_SHORT;
  unsigned char* plain_msg = (unsigned char*) calloc(1, length);
  if (plain_msg) {
    int size = _nas5g_message_plain_encode(
        plain_msg, &msg->header, &msg->plain, length);
    if (size > 0 && security) {
      bytes = _nas5g_message_encrypt(
          buffer, plain_msg, msg->header.security_header_type,
          msg->header.message_authentication_code, msg->header.sequence_number,
          amf_security_context->direction_encode, size, amf_security_context);
    }
  }
  free(plain_msg);
  OAILOG_FUNC_RETURN(LOG_AMF_APP, bytes);
}
static int _nas5g_message_protected_encode ( unsigned char * buffer , const nas_message_security_protected_t * msg , uint32_t length , void * security ) { OAILOG_FUNC_IN ( LOG_AMF_APP ) ; amf_security_context_t * amf_security_context = ( amf_security_context_t * ) security ; int bytes = TLV_BUFFER_TOO_SHORT ; unsigned char * plain_msg = ( unsigned char * ) calloc ( 1 , length ) ; if ( plain_msg ) { int size = _nas5g_message_plain_encode ( plain_msg , & msg -> header , & msg -> plain , length ) ; if ( size > 0 && security ) { bytes = _nas5g_message_encrypt ( buffer , plain_msg , msg -> header . security_header_type , msg -> header . message_authentication_code , msg -> header . sequence_number , amf_security_context -> direction_encode , size , amf_security_context ) ; } } free ( plain_msg ) ; OAILOG_FUNC_RETURN ( LOG_AMF_APP , bytes ) ; }
Name:  _nas5g_message_protected_encode()
Name : _nas5g_message_protected_encode ()
/*
     * Encode the security protected NAS message as plain NAS message
     */ /*
       * Encrypt the encoded plain NAS message
       */