Added NAS ITTI log message.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4841 818b1a75-f10b-46b9-bf7c-635c3b92a50f
This commit is contained in:
winckel
2014-01-10 08:27:21 +00:00
parent 0f42c092b1
commit ca98864cd0
24 changed files with 498 additions and 147 deletions
@@ -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);
}
/* 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);
/* 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 */
+156
View File
@@ -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,
TRACKING_AREA_UPDATE_REJECT,
EXTENDED_SERVICE_REQUEST,
SERVICE_REQUEST,
SERVICE_REJECT,
GUTI_REALLOCATION_COMMAND,
GUTI_REALLOCATION_COMPLETE,
AUTHENTICATION_REQUEST,
AUTHENTICATION_RESPONSE,
AUTHENTICATION_REJECT,
AUTHENTICATION_FAILURE,
IDENTITY_REQUEST,
IDENTITY_RESPONSE,
SECURITY_MODE_COMMAND,
SECURITY_MODE_COMPLETE,
SECURITY_MODE_REJECT,
EMM_STATUS,
EMM_INFORMATION,
DOWNLINK_NAS_TRANSPORT,
UPLINK_NAS_TRANSPORT,
CS_SERVICE_NOTIFICATION,
};
static const UInt8_t esm_message_ids[] =
{
ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REQUEST,
ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_ACCEPT,
ACTIVATE_DEFAULT_EPS_BEARER_CONTEXT_REJECT,
ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REQUEST,
ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_ACCEPT,
ACTIVATE_DEDICATED_EPS_BEARER_CONTEXT_REJECT,
MODIFY_EPS_BEARER_CONTEXT_REQUEST,
MODIFY_EPS_BEARER_CONTEXT_ACCEPT,
MODIFY_EPS_BEARER_CONTEXT_REJECT,
DEACTIVATE_EPS_BEARER_CONTEXT_REQUEST,
DEACTIVATE_EPS_BEARER_CONTEXT_ACCEPT,
PDN_CONNECTIVITY_REQUEST,
PDN_CONNECTIVITY_REJECT,
PDN_DISCONNECT_REQUEST,
PDN_DISCONNECT_REJECT,
BEARER_RESOURCE_ALLOCATION_REQUEST,
BEARER_RESOURCE_ALLOCATION_REJECT,
BEARER_RESOURCE_MODIFICATION_REQUEST,
BEARER_RESOURCE_MODIFICATION_REJECT,
ESM_INFORMATION_REQUEST,
ESM_INFORMATION_RESPONSE,
ESM_STATUS,
};
static int _nas_find_message_index(const UInt8_t message_id, const UInt8_t *message_ids, const int ids_number)
{
int i;
for(i = 0; i < ids_number; i ++)
{
if (message_id == message_ids[i])
{
return (2 + i);
}
}
return (1);
}
int nas_itti_dl_data_req(const uint32_t ue_id, void *const data,
const uint32_t length)
{
@@ -47,6 +121,88 @@ int nas_itti_dl_data_req(const uint32_t ue_id, void *const data,
return itti_send_msg_to_task(TASK_S1AP, INSTANCE_DEFAULT, message_p);
}
int nas_itti_plain_msg(const char* buffer, const nas_message_t* msg, const int length, const int instance)
{
MessageDef *message_p;
int data_length = length < NAS_DATA_LENGHT_MAX ? length : NAS_DATA_LENGHT_MAX;
{
message_p = itti_alloc_new_message(TASK_NAS, NAS_RAW_MSG);
NAS_RAW_MSG(message_p).lenght = length;
memset ((void *) &(NAS_RAW_MSG(message_p).data), 0, NAS_DATA_LENGHT_MAX);
memcpy ((void *) &(NAS_RAW_MSG(message_p).data), buffer, data_length);
itti_send_msg_to_task(TASK_UNKNOWN, instance, message_p);
message_p = NULL;
}
if (msg->header.protocol_discriminator == EPS_MOBILITY_MANAGEMENT_MESSAGE)
{
message_p = itti_alloc_new_message(TASK_NAS, NAS_EMM_PLAIN_MSG);
NAS_EMM_PLAIN_MSG(message_p).present = _nas_find_message_index(msg->plain.emm.header.message_type, emm_message_ids, sizeof(emm_message_ids) / sizeof(emm_message_ids[0]));
memcpy ((void *) &(NAS_EMM_PLAIN_MSG(message_p).choice), &msg->plain.emm, sizeof (EMM_msg));
}
else {
if (msg->header.protocol_discriminator == EPS_SESSION_MANAGEMENT_MESSAGE)
{
message_p = itti_alloc_new_message(TASK_NAS, NAS_ESM_PLAIN_MSG);
NAS_ESM_PLAIN_MSG(message_p).present = _nas_find_message_index(msg->plain.esm.header.message_type, esm_message_ids, sizeof(esm_message_ids) / sizeof(esm_message_ids[0]));
memcpy ((void *) &(NAS_ESM_PLAIN_MSG(message_p).choice), &msg->plain.emm, sizeof (ESM_msg));
}
}
if (message_p != NULL) {
return itti_send_msg_to_task(TASK_UNKNOWN, instance, message_p);
}
return EXIT_FAILURE;
}
int nas_itti_protected_msg(const char* buffer, const nas_message_t* msg, const int length, const int instance)
{
MessageDef *message_p;
int data_length = length < NAS_DATA_LENGHT_MAX ? length : NAS_DATA_LENGHT_MAX;
{
message_p = itti_alloc_new_message(TASK_NAS, NAS_RAW_MSG);
NAS_RAW_MSG(message_p).lenght = length;
memset ((void *) &(NAS_RAW_MSG(message_p).data), 0, NAS_DATA_LENGHT_MAX);
memcpy ((void *) &(NAS_RAW_MSG(message_p).data), buffer, data_length);
itti_send_msg_to_task(TASK_UNKNOWN, instance, message_p);
message_p = NULL;
}
if (msg->header.protocol_discriminator == EPS_MOBILITY_MANAGEMENT_MESSAGE)
{
message_p = itti_alloc_new_message(TASK_NAS, NAS_EMM_PROTECTED_MSG);
memcpy ((void *) &(NAS_EMM_PROTECTED_MSG(message_p).header), &msg->header, sizeof (nas_message_security_header_t));
NAS_EMM_PROTECTED_MSG(message_p).present = _nas_find_message_index(msg->security_protected.plain.emm.header.message_type, emm_message_ids, sizeof(emm_message_ids) / sizeof(emm_message_ids[0]));
memcpy ((void *) &(NAS_EMM_PROTECTED_MSG(message_p).choice), &msg->security_protected.plain.emm, sizeof (EMM_msg));
}
else {
if (msg->header.protocol_discriminator == EPS_SESSION_MANAGEMENT_MESSAGE)
{
message_p = itti_alloc_new_message(TASK_NAS, NAS_ESM_PROTECTED_MSG);
memcpy ((void *) &(NAS_ESM_PROTECTED_MSG(message_p).header), &msg->header, sizeof (nas_message_security_header_t));
NAS_ESM_PROTECTED_MSG(message_p).present = _nas_find_message_index(msg->security_protected.plain.esm.header.message_type, esm_message_ids, sizeof(esm_message_ids) / sizeof(esm_message_ids[0]));
memcpy ((void *) &(NAS_ESM_PROTECTED_MSG(message_p).choice), &msg->security_protected.plain.esm, sizeof (ESM_msg));
}
}
if (message_p != NULL) {
return itti_send_msg_to_task(TASK_UNKNOWN, instance, message_p);
}
return EXIT_FAILURE;
}
#endif
#if defined(UE_BUILD) && defined(NAS_UE)
+4
View File
@@ -43,6 +43,10 @@
int nas_itti_dl_data_req(const uint32_t ue_id, void *const data,
const uint32_t length);
int nas_itti_plain_msg(const char* buffer, const nas_message_t* msg, const int length, const int instance);
int nas_itti_protected_msg(const char* buffer, const nas_message_t* msg, const int length, const int instance);
static inline void nas_itti_establish_cnf(const uint32_t ue_id,
const nas_error_code_t error_code, void *const data,
const uint32_t length)
+3 -2
View File
@@ -163,9 +163,10 @@ next_message:
} break;
default: {
NAS_DEBUG("Unkwnon message ID %d:%s\n",
NAS_DEBUG("Unkwnon message ID %d:%s from %s\n",
ITTI_MSG_ID(received_message_p),
ITTI_MSG_NAME(received_message_p));
ITTI_MSG_NAME(received_message_p),
ITTI_MSG_ORIGIN_NAME(received_message_p));
} break;
}
itti_free(ITTI_MSG_ORIGIN_ID(received_message_p), received_message_p);