Commit ca98864c authored by winckel's avatar winckel
Browse files

Added NAS ITTI log message.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4841 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 0f42c092
//WARNING: Do not include this header directly. Use intertask_interface.h instead.
MESSAGE_DEF(NAS_PAGING_IND, MESSAGE_PRIORITY_MED, nas_paging_ind_t, nas_paging_ind)
MESSAGE_DEF(NAS_CONNECTION_ESTABLISHMENT_IND, MESSAGE_PRIORITY_MED, nas_conn_est_ind_t, nas_conn_est_ind)
MESSAGE_DEF(NAS_CONNECTION_ESTABLISHMENT_CNF, MESSAGE_PRIORITY_MED, nas_conn_est_cnf_t, nas_conn_est_cnf)
MESSAGE_DEF(NAS_CONNECTION_RELEASE_IND, MESSAGE_PRIORITY_MED, nas_conn_rel_ind_t, nas_conn_rel_ind)
MESSAGE_DEF(NAS_UPLINK_DATA_IND, MESSAGE_PRIORITY_MED, nas_ul_data_ind_t, nas_ul_data_ind)
MESSAGE_DEF(NAS_DOWNLINK_DATA_REQ, MESSAGE_PRIORITY_MED, nas_dl_data_req_t, nas_dl_data_req)
MESSAGE_DEF(NAS_DOWNLINK_DATA_CNF, MESSAGE_PRIORITY_MED, nas_dl_data_cnf_t, nas_dl_data_cnf)
MESSAGE_DEF(NAS_NON_DELIVERY_IND, MESSAGE_PRIORITY_MED, nas_non_del_ind_t, nas_non_del_ind)
MESSAGE_DEF(NAS_RAB_ESTABLISHMENT_REQ, MESSAGE_PRIORITY_MED, nas_rab_est_req_t, nas_rab_est_req)
MESSAGE_DEF(NAS_RAB_ESTABLISHMENT_RESP, MESSAGE_PRIORITY_MED, nas_rab_est_rsp_t, nas_rab_est_rsp)
MESSAGE_DEF(NAS_RAB_RELEASE_REQ, MESSAGE_PRIORITY_MED, nas_rab_rel_req_t, nas_rab_rel_req)
// Messages for NAS logging
MESSAGE_DEF(NAS_RAW_MSG, MESSAGE_PRIORITY_MED, nas_raw_msg_t, nas_raw_msg)
MESSAGE_DEF(NAS_EMM_PLAIN_MSG, MESSAGE_PRIORITY_MED, nas_emm_plain_msg_t, nas_emm_plain_msg)
MESSAGE_DEF(NAS_EMM_PROTECTED_MSG, MESSAGE_PRIORITY_MED, nas_emm_protected_msg_t, nas_emm_protected_msg)
MESSAGE_DEF(NAS_ESM_PLAIN_MSG, MESSAGE_PRIORITY_MED, nas_esm_plain_msg_t, nas_esm_plain_msg)
MESSAGE_DEF(NAS_ESM_PROTECTED_MSG, MESSAGE_PRIORITY_MED, nas_esm_protected_msg_t, nas_esm_protected_msg)
/* */
MESSAGE_DEF(NAS_PAGING_IND, MESSAGE_PRIORITY_MED, nas_paging_ind_t, nas_paging_ind)
MESSAGE_DEF(NAS_CONNECTION_ESTABLISHMENT_IND, MESSAGE_PRIORITY_MED, nas_conn_est_ind_t, nas_conn_est_ind)
MESSAGE_DEF(NAS_CONNECTION_ESTABLISHMENT_CNF, MESSAGE_PRIORITY_MED, nas_conn_est_cnf_t, nas_conn_est_cnf)
MESSAGE_DEF(NAS_CONNECTION_RELEASE_IND, MESSAGE_PRIORITY_MED, nas_conn_rel_ind_t, nas_conn_rel_ind)
MESSAGE_DEF(NAS_UPLINK_DATA_IND, MESSAGE_PRIORITY_MED, nas_ul_data_ind_t, nas_ul_data_ind)
MESSAGE_DEF(NAS_DOWNLINK_DATA_REQ, MESSAGE_PRIORITY_MED, nas_dl_data_req_t, nas_dl_data_req)
MESSAGE_DEF(NAS_DOWNLINK_DATA_CNF, MESSAGE_PRIORITY_MED, nas_dl_data_cnf_t, nas_dl_data_cnf)
MESSAGE_DEF(NAS_NON_DELIVERY_IND, MESSAGE_PRIORITY_MED, nas_non_del_ind_t, nas_non_del_ind)
MESSAGE_DEF(NAS_RAB_ESTABLISHMENT_REQ, MESSAGE_PRIORITY_MED, nas_rab_est_req_t, nas_rab_est_req)
MESSAGE_DEF(NAS_RAB_ESTABLISHMENT_RESP, MESSAGE_PRIORITY_MED, nas_rab_est_rsp_t, nas_rab_est_rsp)
MESSAGE_DEF(NAS_RAB_RELEASE_REQ, MESSAGE_PRIORITY_MED, nas_rab_rel_req_t, nas_rab_rel_req)
/* NAS layer -> MME app messages */
MESSAGE_DEF(NAS_AUTHENTICATION_PARAM_REQ, MESSAGE_PRIORITY_MED, nas_auth_param_req_t, nas_auth_param_req)
MESSAGE_DEF(NAS_AUTHENTICATION_PARAM_REQ, MESSAGE_PRIORITY_MED, nas_auth_param_req_t, nas_auth_param_req)
/* MME app -> NAS layer messages */
MESSAGE_DEF(NAS_BEARER_PARAM, MESSAGE_PRIORITY_MED, nas_bearer_param_t, nas_bearer_param)
MESSAGE_DEF(NAS_AUTHENTICATION_PARAM_RSP, MESSAGE_PRIORITY_MED, nas_auth_param_rsp_t, nas_auth_param_rsp)
MESSAGE_DEF(NAS_AUTHENTICATION_PARAM_FAIL, MESSAGE_PRIORITY_MED, nas_auth_param_fail_t, nas_auth_param_fail)
MESSAGE_DEF(NAS_BEARER_PARAM, MESSAGE_PRIORITY_MED, nas_bearer_param_t, nas_bearer_param)
MESSAGE_DEF(NAS_AUTHENTICATION_PARAM_RSP, MESSAGE_PRIORITY_MED, nas_auth_param_rsp_t, nas_auth_param_rsp)
MESSAGE_DEF(NAS_AUTHENTICATION_PARAM_FAIL, MESSAGE_PRIORITY_MED, nas_auth_param_fail_t, nas_auth_param_fail)
#if defined(DISABLE_USE_NAS)
MESSAGE_DEF(NAS_ATTACH_REQ, MESSAGE_PRIORITY_MED, nas_attach_req_t, nas_attach_req)
MESSAGE_DEF(NAS_ATTACH_ACCEPT, MESSAGE_PRIORITY_MED, nas_attach_accept_t, nas_attach_accept)
MESSAGE_DEF(NAS_AUTHENTICATION_RESP, MESSAGE_PRIORITY_MED, nas_auth_resp_t, nas_auth_resp)
MESSAGE_DEF(NAS_AUTHENTICATION_REQ, MESSAGE_PRIORITY_MED, nas_auth_req_t, nas_auth_req)
#endif
\ No newline at end of file
MESSAGE_DEF(NAS_ATTACH_REQ, MESSAGE_PRIORITY_MED, nas_attach_req_t, nas_attach_req)
MESSAGE_DEF(NAS_ATTACH_ACCEPT, MESSAGE_PRIORITY_MED, nas_attach_accept_t, nas_attach_accept)
MESSAGE_DEF(NAS_AUTHENTICATION_RESP, MESSAGE_PRIORITY_MED, nas_auth_resp_t, nas_auth_resp)
MESSAGE_DEF(NAS_AUTHENTICATION_REQ, MESSAGE_PRIORITY_MED, nas_auth_req_t, nas_auth_req)
#endif
#include "as_message.h"
#include "nas_message.h"
#ifndef NAS_MESSAGES_TYPES_H_
#define NAS_MESSAGES_TYPES_H_
#define NAS_UL_DATA_IND(mSGpTR) (mSGpTR)->ittiMsg.nas_ul_data_ind
#define NAS_DL_DATA_REQ(mSGpTR) (mSGpTR)->ittiMsg.nas_dl_data_req
#define NAS_DL_DATA_CNF(mSGpTR) (mSGpTR)->ittiMsg.nas_dl_data_cnf
#define NAS_CONN_EST_IND(mSGpTR) (mSGpTR)->ittiMsg.nas_conn_est_ind
#define NAS_CONNECTION_ESTABLISHMENT_CNF(mSGpTR) (mSGpTR)->ittiMsg.nas_conn_est_cnf
#define NAS_BEARER_PARAM(mSGpTR) (mSGpTR)->ittiMsg.nas_bearer_param
#define NAS_AUTHENTICATION_REQ(mSGpTR) (mSGpTR)->ittiMsg.nas_auth_req
#define NAS_AUTHENTICATION_PARAM_REQ(mSGpTR) (mSGpTR)->ittiMsg.nas_auth_param_req
#define NAS_AUTHENTICATION_PARAM_RSP(mSGpTR) (mSGpTR)->ittiMsg.nas_auth_param_rsp
#define NAS_AUTHENTICATION_PARAM_FAIL(mSGpTR) (mSGpTR)->ittiMsg.nas_auth_param_fail
#define NAS_RAW_MSG(mSGpTR) (mSGpTR)->ittiMsg.nas_raw_msg
#define NAS_EMM_PROTECTED_MSG(mSGpTR) (mSGpTR)->ittiMsg.nas_emm_protected_msg
#define NAS_EMM_PLAIN_MSG(mSGpTR) (mSGpTR)->ittiMsg.nas_emm_plain_msg
#define NAS_ESM_PROTECTED_MSG(mSGpTR) (mSGpTR)->ittiMsg.nas_esm_protected_msg
#define NAS_ESM_PLAIN_MSG(mSGpTR) (mSGpTR)->ittiMsg.nas_esm_plain_msg
#define NAS_UL_DATA_IND(mSGpTR) (mSGpTR)->ittiMsg.nas_ul_data_ind
#define NAS_DL_DATA_REQ(mSGpTR) (mSGpTR)->ittiMsg.nas_dl_data_req
#define NAS_DL_DATA_CNF(mSGpTR) (mSGpTR)->ittiMsg.nas_dl_data_cnf
#define NAS_CONN_EST_IND(mSGpTR) (mSGpTR)->ittiMsg.nas_conn_est_ind
#define NAS_CONNECTION_ESTABLISHMENT_CNF(mSGpTR) (mSGpTR)->ittiMsg.nas_conn_est_cnf
#define NAS_BEARER_PARAM(mSGpTR) (mSGpTR)->ittiMsg.nas_bearer_param
#define NAS_AUTHENTICATION_REQ(mSGpTR) (mSGpTR)->ittiMsg.nas_auth_req
#define NAS_AUTHENTICATION_PARAM_REQ(mSGpTR) (mSGpTR)->ittiMsg.nas_auth_param_req
#define NAS_AUTHENTICATION_PARAM_RSP(mSGpTR) (mSGpTR)->ittiMsg.nas_auth_param_rsp
#define NAS_AUTHENTICATION_PARAM_FAIL(mSGpTR) (mSGpTR)->ittiMsg.nas_auth_param_fail
#define NAS_DATA_LENGHT_MAX 256
typedef enum {
EMM_MSG_HEADER = 1,
EMM_MSG_ATTACH_REQUEST,
EMM_MSG_ATTACH_ACCEPT,
EMM_MSG_ATTACH_COMPLETE,
EMM_MSG_ATTACH_REJECT,
EMM_MSG_DETACH_REQUEST,
EMM_MSG_DETACH_ACCEPT,
EMM_MSG_TRACKING_AREA_UPDATE_REQUEST,
EMM_MSG_TRACKING_AREA_UPDATE_ACCEPT,
EMM_MSG_TRACKING_AREA_UPDATE_COMPLETE,
EMM_MSG_TRACKING_AREA_UPDATE_REJECT,
EMM_MSG_EXTENDED_SERVICE_REQUEST,
EMM_MSG_SERVICE_REQUEST,
EMM_MSG_SERVICE_REJECT,
EMM_MSG_GUTI_REALLOCATION_COMMAND,
EMM_MSG_GUTI_REALLOCATION_COMPLETE,
EMM_MSG_AUTHENTICATION_REQUEST,
EMM_MSG_AUTHENTICATION_RESPONSE,
EMM_MSG_AUTHENTICATION_REJECT,
EMM_MSG_AUTHENTICATION_FAILURE,
EMM_MSG_IDENTITY_REQUEST,
EMM_MSG_IDENTITY_RESPONSE,
EMM_MSG_SECURITY_MODE_COMMAND,
EMM_MSG_SECURITY_MODE_COMPLETE,
EMM_MSG_SECURITY_MODE_REJECT,
EMM_MSG_EMM_STATUS,
EMM_MSG_EMM_INFORMATION,
EMM_MSG_DOWNLINK_NAS_TRANSPORT,
EMM_MSG_UPLINK_NAS_TRANSPORT,
EMM_MSG_CS_SERVICE_NOTIFICATION,
} emm_message_ids_t;
typedef enum {
ESM_MSG_HEADER = 1,
ESM_MSG_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST,
ESM_MSG_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_ACCEPT,
ESM_MSG_ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REJECT,
ESM_MSG_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST,
ESM_MSG_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_ACCEPT,
ESM_MSG_ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REJECT,
ESM_MSG_MODIFY_EPS_BEARER_CONTEXT_REQUEST,
ESM_MSG_MODIFY_EPS_BEARER_CONTEXT_ACCEPT,
ESM_MSG_MODIFY_EPS_BEARER_CONTEXT_REJECT,
ESM_MSG_DEACTIVATE_EPS_BEARER_CONTEXT_REQUEST,
ESM_MSG_DEACTIVATE_EPS_BEARER_CONTEXT_ACCEPT,
ESM_MSG_PDN_CONNECTIVITY_REQUEST,
ESM_MSG_PDN_CONNECTIVITY_REJECT,
ESM_MSG_PDN_DISCONNECT_REQUEST,
ESM_MSG_PDN_DISCONNECT_REJECT,
ESM_MSG_BEARER_RESOURCE_ALLOCATION_REQUEST,
ESM_MSG_BEARER_RESOURCE_ALLOCATION_REJECT,
ESM_MSG_BEARER_RESOURCE_MODIFICATION_REQUEST,
ESM_MSG_BEARER_RESOURCE_MODIFICATION_REJECT,
ESM_MSG_ESM_INFORMATION_REQUEST,
ESM_MSG_ESM_INFORMATION_RESPONSE,
ESM_MSG_ESM_STATUS,
} esm_message_ids_t;
typedef struct nas_raw_msg_s {
uint32_t lenght;
uint8_t data[NAS_DATA_LENGHT_MAX];
} nas_raw_msg_t;
typedef struct nas_emm_plain_msg_s {
emm_message_ids_t present;
EMM_msg choice;
} nas_emm_plain_msg_t;
typedef struct nas_emm_protected_msg_s {
nas_message_security_header_t header;
emm_message_ids_t present;
EMM_msg choice;
} nas_emm_protected_msg_t;
typedef struct nas_esm_plain_msg_s {
esm_message_ids_t present;
ESM_msg choice;
} nas_esm_plain_msg_t;
typedef struct nas_esm_protected_msg_s {
nas_message_security_header_t header;
esm_message_ids_t present;
ESM_msg choice;
} nas_esm_protected_msg_t;
typedef struct nas_paging_ind_s {
} nas_paging_ind_t;
typedef struct nas_conn_est_ind_s {
......
AM_CFLAGS = @ADD_CFLAGS@ \
-I$(top_srcdir)/COMMON \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/api/network \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/include \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/api/network \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/include \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/ies \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/emm/msg \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/esm/msg \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/util \
-I$(top_srcdir)/INTERTASK_INTERFACE \
-I$(top_srcdir)/GTPV1-U/nw-gtpv1u/include \
-I$(top_srcdir)/GTPV1-U/nw-gtpv1u/shared \
......
AM_CFLAGS = \
@ADD_CFLAGS@ \
-I$(top_srcdir)/COMMON \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/api/network \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/include \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/api/network \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/include \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/ies \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/emm/msg \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/esm/msg \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/util \
-I$(top_srcdir)/INTERTASK_INTERFACE \
-I$(top_srcdir)/S1AP \
-I$(top_srcdir)/S6A \
......
ACLOCAL_AMFLAGS = -I m4
AM_CFLAGS = @ADD_CFLAGS@ \
-I$(top_srcdir)/COMMON \
-I$(top_srcdir)/UTILS \
AM_CFLAGS = @ADD_CFLAGS@ \
-I$(top_srcdir)/COMMON \
-I$(top_srcdir)/UTILS \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/api/network \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/include \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/include \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/ies \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/emm/msg \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/esm/msg \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/util \
-I$(top_srcdir)/INTERTASK_INTERFACE
if HAVE_GCCXML
......
......@@ -28,6 +28,10 @@ Description Defines the layer 3 messages supported by the NAS sublayer
#include <stdlib.h> // malloc, free
#include <string.h> // memcpy
#if (defined(EPC_BUILD) && defined(NAS_MME))
# include "nas_itti_messaging.h"
#endif
/****************************************************************************/
/**************** E X T E R N A L D E F I N I T I O N S ****************/
/****************************************************************************/
......@@ -215,7 +219,7 @@ int nas_message_decrypt(const char* inbuf, char* outbuf,
** Others: None **
** **
***************************************************************************/
int nas_message_decode(const char* buffer, nas_message_t* msg, int length)
int nas_message_decode(const char* const buffer, nas_message_t* msg, int length)
{
LOG_FUNC_IN;
......@@ -225,35 +229,42 @@ int nas_message_decode(const char* buffer, nas_message_t* msg, int length)
int size = _nas_message_header_decode(buffer, &msg->header, length);
if (size < 0) {
LOG_FUNC_RETURN (TLV_DECODE_BUFFER_TOO_SHORT);
LOG_FUNC_RETURN (TLV_DECODE_BUFFER_TOO_SHORT);
}
else if (size > 1) {
/* Compute offset of the sequence number field */
int offset = size - sizeof(UInt8_t);
/* Compute the NAS message authentication code */
UInt32_t mac = _nas_message_get_mac(buffer + offset,
0, // TODO !!! dl counter
length - offset);
/* Check NAS message integrity */
if (mac != msg->header.message_authentication_code) {
LOG_FUNC_RETURN (TLV_DECODE_MAC_MISMATCH);
}
/* Decode security protected NAS message */
bytes = _nas_message_protected_decode(buffer + size, &msg->header,
&msg->plain, length - size);
/* Compute offset of the sequence number field */
int offset = size - sizeof(UInt8_t);
/* Compute the NAS message authentication code */
UInt32_t mac = _nas_message_get_mac(buffer + offset,
0, // TODO !!! dl counter
length - offset);
/* Check NAS message integrity */
if (mac != msg->header.message_authentication_code) {
LOG_FUNC_RETURN (TLV_DECODE_MAC_MISMATCH);
}
/* Decode security protected NAS message */
bytes = _nas_message_protected_decode(buffer + size, &msg->header,
&msg->plain, length - size);
#if defined(EPC_BUILD) && defined(NAS_MME)
/* Message has been decoded and security header removed, handle it has a plain message */
nas_itti_plain_msg(buffer, msg, length, 0);
#endif
}
else {
/* Decode plain NAS message */
bytes = _nas_message_plain_decode(buffer, &msg->header,
&msg->plain, length);
/* Decode plain NAS message */
bytes = _nas_message_plain_decode(buffer, &msg->header,
&msg->plain, length);
#if defined(EPC_BUILD) && defined(NAS_MME)
nas_itti_plain_msg(buffer, msg, length, 0);
#endif
}
if (bytes < 0) {
LOG_FUNC_RETURN (bytes);
LOG_FUNC_RETURN (bytes);
}
if (size > 1) {
LOG_FUNC_RETURN (size + bytes);
LOG_FUNC_RETURN (size + bytes);
}
LOG_FUNC_RETURN (bytes);
}
......@@ -275,7 +286,7 @@ int nas_message_decode(const char* buffer, nas_message_t* msg, int length)
** Others: None **
** **
***************************************************************************/
int nas_message_encode(char* buffer, const nas_message_t* msg, int length)
int nas_message_encode(char* buffer, const nas_message_t* const msg, int length)
{
LOG_FUNC_IN;
......@@ -285,35 +296,41 @@ int nas_message_encode(char* buffer, const nas_message_t* msg, int length)
int size = _nas_message_header_encode(buffer, &msg->header, length);
if (size < 0) {
LOG_FUNC_RETURN (TLV_ENCODE_BUFFER_TOO_SHORT);
LOG_FUNC_RETURN (TLV_ENCODE_BUFFER_TOO_SHORT);
}
else if (size > 1) {
/* Encode security protected NAS message */
bytes = _nas_message_protected_encode(buffer + size, &msg->protected,
length - size);
/* Integrity protect the NAS message */
if (bytes > 0) {
/* Compute offset of the sequence number field */
int offset = size - sizeof(UInt8_t);
/* Compute the NAS message authentication code */
UInt32_t mac = _nas_message_get_mac(buffer + offset,
0, // TODO !!! ul counter
length - offset);
/* Set the message authentication code of the NAS message */
*(UInt32_t*)(buffer + sizeof(UInt8_t)) = mac;
}
/* Encode security protected NAS message */
bytes = _nas_message_protected_encode(buffer + size, &msg->security_protected,
length - size);
/* Integrity protect the NAS message */
if (bytes > 0) {
/* Compute offset of the sequence number field */
int offset = size - sizeof(UInt8_t);
/* Compute the NAS message authentication code */
UInt32_t mac = _nas_message_get_mac(buffer + offset,
0, // TODO !!! ul counter
length - offset);
/* Set the message authentication code of the NAS message */
*(UInt32_t*)(buffer + sizeof(UInt8_t)) = mac;
}
#if defined(EPC_BUILD) && defined(NAS_MME)
nas_itti_protected_msg(buffer, msg, length, 1);
#endif
}
else {
/* Encode plain NAS message */
bytes = _nas_message_plain_encode(buffer, &msg->header,
&msg->plain, length);
/* Encode plain NAS message */
bytes = _nas_message_plain_encode(buffer, &msg->header,
&msg->plain, length);
#if defined(EPC_BUILD) && defined(NAS_MME)
nas_itti_plain_msg(buffer, msg, length, 1);
#endif
}
if (bytes < 0) {
LOG_FUNC_RETURN (bytes);
LOG_FUNC_RETURN (bytes);
}
if (size > 1) {
LOG_FUNC_RETURN (size + bytes);
LOG_FUNC_RETURN (size + bytes);
}
LOG_FUNC_RETURN (bytes);
}
......@@ -349,8 +366,8 @@ int nas_message_encode(char* buffer, const nas_message_t* msg, int length)
** **
***************************************************************************/
static int _nas_message_header_decode(const char* buffer,
nas_message_security_header_t* header,
int length)
nas_message_security_header_t* header,
int length)
{
LOG_FUNC_IN;
......@@ -361,20 +378,20 @@ static int _nas_message_header_decode(const char* buffer,
DECODE_U8(buffer, *(UInt8_t*)(header), size);
if (header->protocol_discriminator == EPS_MOBILITY_MANAGEMENT_MESSAGE) {
if (header->security_header_type != SECURITY_HEADER_TYPE_NOT_PROTECTED)
{
if (length < NAS_MESSAGE_SECURITY_HEADER_SIZE) {
/* The buffer is not big enough to contain security header */
LOG_TRACE(WARNING, "NET-API - The size of the header (%u) "
"exceeds the buffer length (%u)",
NAS_MESSAGE_SECURITY_HEADER_SIZE, length);
LOG_FUNC_RETURN (-1);
}
/* Decode the message authentication code */
DECODE_U32(buffer+size, header->message_authentication_code, size);
/* Decode the sequence number */
DECODE_U8(buffer+size, header->sequence_number, size);
}
if (header->security_header_type != SECURITY_HEADER_TYPE_NOT_PROTECTED)
{
if (length < NAS_MESSAGE_SECURITY_HEADER_SIZE) {
/* The buffer is not big enough to contain security header */
LOG_TRACE(WARNING, "NET-API - The size of the header (%u) "
"exceeds the buffer length (%u)",
NAS_MESSAGE_SECURITY_HEADER_SIZE, length);
LOG_FUNC_RETURN (-1);
}
/* Decode the message authentication code */
DECODE_U32(buffer+size, header->message_authentication_code, size);
/* Decode the sequence number */
DECODE_U8(buffer+size, header->sequence_number, size);
}
}
LOG_FUNC_RETURN (size);
......@@ -495,7 +512,7 @@ static int _nas_message_protected_decode(const char* buffer,
** **
***************************************************************************/
static int _nas_message_header_encode(char* buffer,
const nas_message_security_header_t* header, int length)
const nas_message_security_header_t* header, int length)
{
LOG_FUNC_IN;
......@@ -506,20 +523,23 @@ static int _nas_message_header_encode(char* buffer,
ENCODE_U8(buffer, *(UInt8_t*)(header), size);
if (header->protocol_discriminator == EPS_MOBILITY_MANAGEMENT_MESSAGE) {
if (header->security_header_type != SECURITY_HEADER_TYPE_NOT_PROTECTED)
{
if (length < NAS_MESSAGE_SECURITY_HEADER_SIZE) {
/* The buffer is not big enough to contain security header */
LOG_TRACE(WARNING, "NET-API - The size of the header (%u) "
"exceeds the buffer length (%u)",
NAS_MESSAGE_SECURITY_HEADER_SIZE, length);
LOG_FUNC_RETURN (-1);
}
/* Encode the message authentication code */
ENCODE_U32(buffer+size, header->message_authentication_code, size);
/* Encode the sequence number */
ENCODE_U8(buffer+size, header->sequence_number, size);
}
if (header->security_header_type != SECURITY_HEADER_TYPE_NOT_PROTECTED)
{
//static uint8_t seq = 0;
if (length < NAS_MESSAGE_SECURITY_HEADER_SIZE) {
/* The buffer is not big enough to contain security header */
LOG_TRACE(WARNING, "NET-API - The size of the header (%u) "
"exceeds the buffer length (%u)",
NAS_MESSAGE_SECURITY_HEADER_SIZE, length);
LOG_FUNC_RETURN (-1);
}
/* Encode the message authentication code */
ENCODE_U32(buffer+size, header->message_authentication_code, size);
/* Encode the sequence number */
ENCODE_U8(buffer+size, header->sequence_number, size);
//ENCODE_U8(buffer+size, seq, size);
//seq++;
}
}
LOG_FUNC_RETURN (size);
......@@ -600,11 +620,14 @@ static int _nas_message_protected_encode(char* buffer,
int size = _nas_message_plain_encode(plain_msg, &msg->header,
&msg->plain, length);
if (size > 0) {
//static uint8_t seq = 0;
/* Encrypt the encoded plain NAS message */
bytes = _nas_message_encrypt(buffer, plain_msg,
msg->header.security_header_type,
msg->header.message_authentication_code,
msg->header.sequence_number, size);
//seq, size);
//seq ++;
}
free(plain_msg);
}
......
......@@ -38,8 +38,8 @@ Description Defines the layer 3 messages supported by the NAS sublayer
/* Structure of security protected header */
typedef struct {
#ifdef __LITTLE_ENDIAN_BITFIELD
UInt8_t protocol_discriminator:4;
UInt8_t security_header_type:4;
eps_protocol_discriminator_t protocol_discriminator:4;
UInt8_t security_header_type:4;
#endif
#ifdef __BIG_ENDIAN_BITFIELD
UInt8_t security_header_type:4;
......@@ -66,7 +66,7 @@ typedef struct {
*/
typedef union {
nas_message_security_header_t header;
nas_message_security_protected_t protected;
nas_message_security_protected_t security_protected;
nas_message_plain_t plain;
} nas_message_t;
......@@ -84,8 +84,8 @@ int nas_message_encrypt(const char *inbuf, char *outbuf,
int nas_message_decrypt(const char *inbuf, char *outbuf,
nas_message_security_header_t *header, int length);
int nas_message_decode(const char *buffer, nas_message_t *msg, int length);
int nas_message_decode(const char * const buffer, nas_message_t *msg, int length);
int nas_message_encode(char *buffer, const nas_message_t *msg, int length);
int nas_message_encode(char *buffer, const nas_message_t * const msg, int length);
#endif /* __NAS_MESSAGE_H__*/
......@@ -31,9 +31,6 @@ Description Defines identifiers of the EPS Mobility Management messages.
#define EMM_HEADER_MINIMUM_LENGTH EMM_HEADER_LENGTH
#define EMM_HEADER_MAXIMUM_LENGTH EMM_HEADER_LENGTH
/* Protocol discriminator identifier for EPS Mobility Management */
#define EPS_MOBILITY_MANAGEMENT_MESSAGE 0x7
/* EPS Mobility Management Security header type */
#define SECURITY_HEADER_TYPE_NOT_PROTECTED 0b0000
#define SECURITY_HEADER_TYPE_INTEGRITY_PROTECTED 0b0001
......
......@@ -866,7 +866,7 @@ static EMM_msg *_emm_as_set_header(nas_message_t *msg,
msg->header.security_header_type =
SECURITY_HEADER_TYPE_INTEGRITY_PROTECTED_NEW;
}
LOG_FUNC_RETURN (&msg->protected.plain.emm);
LOG_FUNC_RETURN (&msg->security_protected.plain.emm);
}
} else if (security->k_int) {
if (security->k_enc) {
......@@ -878,7 +878,11 @@ static EMM_msg *_emm_as_set_header(nas_message_t *msg,
msg->header.security_header_type =
SECURITY_HEADER_TYPE_INTEGRITY_PROTECTED;
}
LOG_FUNC_RETURN (&msg->protected.plain.emm);
LOG_FUNC_RETURN (&msg->security_protected.plain.emm);
} else {
/* No valid EPS security context exists */
msg->header.security_header_type = SECURITY_HEADER_TYPE_NOT_PROTECTED;
LOG_FUNC_RETURN (&msg->plain.emm);
}
} else {
/* No valid EPS security context exists */
......@@ -914,7 +918,7 @@ static int _emm_as_encode(as_nas_info_t *info, nas_message_t *msg, int length)
int bytes = 0;
if (msg->header.security_header_type != SECURITY_HEADER_TYPE_NOT_PROTECTED) {
emm_msg_header_t *header = &msg->protected.plain.emm.header;
emm_msg_header_t *header = &msg->security_protected.plain.emm.header;
/* Expand size of protected NAS message */
length += NAS_MESSAGE_SECURITY_HEADER_SIZE;
/* Set header of plain NAS message */
......
......@@ -31,9 +31,6 @@ Description Defines identifiers of the EPS Session Management messages
#define ESM_HEADER_MINIMUM_LENGTH ESM_HEADER_LENGTH
#define ESM_HEADER_MAXIMUM_LENGTH ESM_HEADER_LENGTH
/* Protocol discriminator identifier for EPS Session Management */
#define EPS_SESSION_MANAGEMENT_MESSAGE 0x2
/* Message identifiers for EPS Session Management */
# define ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST 0b11000001 /* 193 = 0xc1 */
# define ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_ACCEPT 0b11000010 /* 194 = 0xc2 */
......
......@@ -34,6 +34,80 @@
#include "nas_itti_messaging.h"
#if defined(EPC_BUILD) && defined(NAS_MME)
static const UInt8_t emm_message_ids[] =
{
ATTACH_REQUEST,
ATTACH_ACCEPT,
ATTACH_COMPLETE,
ATTACH_REJECT,
DETACH_REQUEST,
DETACH_ACCEPT,
TRACKING_AREA_UPDATE_REQUEST,
TRACKING_AREA_UPDATE_ACCEPT,
TRACKING_AREA_UPDATE_COMPLETE,