diff --git a/openair-cn/NAS/EURECOM-NAS/src/emm/SecurityModeControl.c b/openair-cn/NAS/EURECOM-NAS/src/emm/SecurityModeControl.c index 84678890d31e5ee4ac93bb3f4e484a7101340872..8027d81eceddccd0c53b45dc14230805a418cdc8 100644 --- a/openair-cn/NAS/EURECOM-NAS/src/emm/SecurityModeControl.c +++ b/openair-cn/NAS/EURECOM-NAS/src/emm/SecurityModeControl.c @@ -513,6 +513,7 @@ int emm_proc_security_mode_complete(unsigned int ueid) */ emm_sap.primitive = EMMREG_COMMON_PROC_CNF; emm_sap.u.emm_reg.ueid = ueid; + emm_sap.u.emm_reg.ctx = emm_ctx; emm_sap.u.emm_reg.u.common.is_attached = emm_ctx->is_attached; } else { LOG_TRACE(ERROR, "EMM-PROC - No EPS security context exists"); @@ -521,6 +522,7 @@ int emm_proc_security_mode_complete(unsigned int ueid) */ emm_sap.primitive = EMMREG_COMMON_PROC_REJ; emm_sap.u.emm_reg.ueid = ueid; + emm_sap.u.emm_reg.ctx = emm_ctx; } rc = emm_sap_send(&emm_sap); diff --git a/openair-cn/NAS/EURECOM-NAS/src/esm/msg/esm_msg.c b/openair-cn/NAS/EURECOM-NAS/src/esm/msg/esm_msg.c index 5ceb8aa661254aa4f8b1bfe5e2ea4c35fdcbe68e..ce139e705c50c56180fe8d3f0c574e0cc159e819 100644 --- a/openair-cn/NAS/EURECOM-NAS/src/esm/msg/esm_msg.c +++ b/openair-cn/NAS/EURECOM-NAS/src/esm/msg/esm_msg.c @@ -60,17 +60,17 @@ static int _esm_msg_encode_header(const esm_msg_header_t *header, uint8_t *buffe ***************************************************************************/ int esm_msg_decode(ESM_msg *msg, uint8_t *buffer, uint32_t len) { - LOG_FUNC_IN; - int header_result; int decode_result; + LOG_FUNC_IN; + /* First decode the ESM message header */ header_result = _esm_msg_decode_header(&msg->header, buffer, len); if (header_result < 0) { - LOG_TRACE(ERROR, "ESM-MSG - Failed to decode ESM message header " - "(%d)", header_result); - LOG_FUNC_RETURN(header_result); + LOG_TRACE(ERROR, "ESM-MSG - Failed to decode ESM message header " + "(%d)", header_result); + LOG_FUNC_RETURN(header_result); } buffer += header_result; @@ -146,14 +146,15 @@ int esm_msg_decode(ESM_msg *msg, uint8_t *buffer, uint32_t len) break; default: LOG_TRACE(ERROR, "ESM-MSG - Unexpected message type: 0x%x", - msg->header.message_type); - decode_result = TLV_DECODE_WRONG_MESSAGE_TYPE; + msg->header.message_type); + decode_result = TLV_DECODE_WRONG_MESSAGE_TYPE; + break; } if (decode_result < 0) { - LOG_TRACE(ERROR, "ESM-MSG - Failed to decode L3 ESM message 0x%x " - "(%d)", msg->header.message_type, decode_result); - LOG_FUNC_RETURN (decode_result); + LOG_TRACE(ERROR, "ESM-MSG - Failed to decode L3 ESM message 0x%x " + "(%u)", msg->header.message_type, decode_result); + LOG_FUNC_RETURN (decode_result); } LOG_FUNC_RETURN (header_result + decode_result); } @@ -305,7 +306,7 @@ static int _esm_msg_decode_header(esm_msg_header_t *header, /* Check the buffer length */ if (len < sizeof(esm_msg_header_t)) { - return (TLV_DECODE_BUFFER_TOO_SHORT); + return (TLV_DECODE_BUFFER_TOO_SHORT); } /* Decode the EPS bearer identity and the protocol discriminator */ @@ -318,9 +319,9 @@ static int _esm_msg_decode_header(esm_msg_header_t *header, /* Check the protocol discriminator */ if (header->protocol_discriminator != EPS_SESSION_MANAGEMENT_MESSAGE) { - LOG_TRACE(ERROR, "ESM-MSG - Unexpected protocol discriminator: 0x%x", - header->protocol_discriminator); - return (TLV_DECODE_PROTOCOL_NOT_SUPPORTED); + LOG_TRACE(ERROR, "ESM-MSG - Unexpected protocol discriminator: 0x%x", + header->protocol_discriminator); + return (TLV_DECODE_PROTOCOL_NOT_SUPPORTED); } return (size); diff --git a/openair-cn/NAS/EURECOM-NAS/src/esm/sap/esm_sap.c b/openair-cn/NAS/EURECOM-NAS/src/esm/sap/esm_sap.c index 5f7ef038e29e192d6ea5f175dbf33d1032348df7..440cdc3978c47e0abbc04996d80f8b157e88aa87 100644 --- a/openair-cn/NAS/EURECOM-NAS/src/esm/sap/esm_sap.c +++ b/openair-cn/NAS/EURECOM-NAS/src/esm/sap/esm_sap.c @@ -401,17 +401,19 @@ static int _esm_sap_recv(int msg_type, int is_standalone, const OctetString *req, OctetString *rsp, esm_sap_error_t *err) { - LOG_FUNC_IN; - esm_proc_procedure_t esm_procedure = NULL; int esm_cause = ESM_CAUSE_SUCCESS; int rc = RETURNerror; + int decoder_rc; ESM_msg esm_msg; + + LOG_FUNC_IN; + memset(&esm_msg, 0 , sizeof(ESM_msg)); /* Decode the received ESM message */ - int decoder_rc = esm_msg_decode(&esm_msg, req->value, req->length); + decoder_rc = esm_msg_decode(&esm_msg, req->value, req->length); /* Process decoding errors */ if (decoder_rc < 0) { diff --git a/openair-cn/NAS/EURECOM-NAS/src/ies/ProtocolConfigurationOptions.c b/openair-cn/NAS/EURECOM-NAS/src/ies/ProtocolConfigurationOptions.c index bd3f577af844ff83a90f8b557b2917e40ae15439..927c9ee190b85f8c3f3c950c25c92e0fd55889d5 100644 --- a/openair-cn/NAS/EURECOM-NAS/src/ies/ProtocolConfigurationOptions.c +++ b/openair-cn/NAS/EURECOM-NAS/src/ies/ProtocolConfigurationOptions.c @@ -2,14 +2,13 @@ #include <stdlib.h> #include <stdint.h> - #include "TLVEncoder.h" #include "TLVDecoder.h" #include "ProtocolConfigurationOptions.h" int decode_protocol_configuration_options(ProtocolConfigurationOptions *protocolconfigurationoptions, uint8_t iei, uint8_t *buffer, uint32_t len) { - int decoded = 0; + uint32_t decoded = 0; uint8_t ielen = 0; int decode_result; if (iei > 0) @@ -20,20 +19,31 @@ int decode_protocol_configuration_options(ProtocolConfigurationOptions *protocol ielen = *(buffer + decoded); decoded++; CHECK_LENGTH_DECODER(len - decoded, ielen); - if (((*buffer >> 7) & 0x1) != 1) + if (((*(buffer + decoded) >> 7) & 0x1) != 1) + { + errorCodeDecoder = TLV_DECODE_VALUE_DOESNT_MATCH; + return TLV_DECODE_VALUE_DOESNT_MATCH; + } + /* Bits 7 to 4 of octet 3 are spare, read as 0 */ + if (((*(buffer + decoded) & 0x78) >> 3) != 0) { errorCodeDecoder = TLV_DECODE_VALUE_DOESNT_MATCH; return TLV_DECODE_VALUE_DOESNT_MATCH; } protocolconfigurationoptions->configurationprotol = (*(buffer + decoded) >> 1) & 0x7; - //IES_DECODE_U16(protocolconfigurationoptions->protocolid, *(buffer + decoded)); - IES_DECODE_U16(buffer, decoded, protocolconfigurationoptions->protocolid); - protocolconfigurationoptions->lengthofprotocolid = *(buffer + decoded); decoded++; - if ((decode_result = decode_octet_string(&protocolconfigurationoptions->protocolidcontents, ielen, buffer + decoded, len - decoded)) < 0) - return decode_result; - else - decoded += decode_result; + //IES_DECODE_U16(protocolconfigurationoptions->protocolid, *(buffer + decoded)); + while ((len - decoded) > 0) { + IES_DECODE_U16(buffer, decoded, protocolconfigurationoptions->protocolid); + DECODE_U8(buffer + decoded, protocolconfigurationoptions->lengthofprotocolid, decoded); + if ((decode_result = decode_octet_string(&protocolconfigurationoptions->protocolidcontents, + protocolconfigurationoptions->lengthofprotocolid, buffer + decoded, len - decoded)) < 0) + { + return decode_result; + } else { + decoded += decode_result; + } + } #if defined (NAS_DEBUG) dump_protocol_configuration_options_xml(protocolconfigurationoptions, iei); #endif diff --git a/openair-cn/NAS/EURECOM-NAS/src/ies/ProtocolConfigurationOptions.h b/openair-cn/NAS/EURECOM-NAS/src/ies/ProtocolConfigurationOptions.h index 1074e3ee833bc9c20e2de3688cf4ea9fdb718617..2d08cec0a4ebb7a080a3534bd9b6a9f50fd837fc 100644 --- a/openair-cn/NAS/EURECOM-NAS/src/ies/ProtocolConfigurationOptions.h +++ b/openair-cn/NAS/EURECOM-NAS/src/ies/ProtocolConfigurationOptions.h @@ -10,6 +10,25 @@ #define PROTOCOL_CONFIGURATION_OPTIONS_MINIMUM_LENGTH 3 #define PROTOCOL_CONFIGURATION_OPTIONS_MAXIMUM_LENGTH 253 +/* 3GPP TS 24.008 Table 10.5.154 + * MS to network table + */ +typedef enum ProtocolConfigurationOptionsList_ids_tag{ + PCO_UNKNOWN = 0, + PCO_P_CSCF_IPV6_ADDRESS_REQ = 1, + PCO_IM_CN_SUBSYSTEM_SIGNALING_FLAG = 2, + PCO_DNS_SERVER_IPV6_ADDRESS_REQ = 3, + PCO_NOT_SUPPORTED = 4, + PCO_MS_SUPPORTED_OF_NETWORK_REQUESTED_BEARER_CONTROL_INDICATOR = 5, + PCO_RESERVED = 6, + /* TODO: complete me */ +} ProtocolConfigurationOptionsList_ids; + +/* 3GPP TS 24.008 Table 10.5.154 + * network to MS table + * TODO + */ + typedef struct ProtocolConfigurationOptions_tag { uint8_t configurationprotol:3; uint16_t protocolid; diff --git a/openair-cn/NAS/EURECOM-NAS/src/util/OctetString.c b/openair-cn/NAS/EURECOM-NAS/src/util/OctetString.c index 0f85d7a488eda09ed7a3b668722f11f6569a9e41..7314505cedcbca55c70aa8467dc0f0e168b714ad 100644 --- a/openair-cn/NAS/EURECOM-NAS/src/util/OctetString.c +++ b/openair-cn/NAS/EURECOM-NAS/src/util/OctetString.c @@ -8,28 +8,28 @@ int encode_octet_string(OctetString *octetstring, uint8_t *buffer, uint32_t buflen) { - CHECK_PDU_POINTER_AND_LENGTH_ENCODER(buffer, octetstring->length, buflen); - memcpy((void*)buffer, (void*)octetstring->value, octetstring->length); - return octetstring->length; + CHECK_PDU_POINTER_AND_LENGTH_ENCODER(buffer, octetstring->length, buflen); + memcpy((void*)buffer, (void*)octetstring->value, octetstring->length); + return octetstring->length; } int decode_octet_string(OctetString *octetstring, uint16_t pdulen, uint8_t *buffer, uint32_t buflen) { - if (buflen < pdulen) - return -1; - octetstring->length = pdulen; - octetstring->value = malloc(sizeof(uint8_t) * (pdulen+1)); - memcpy((void*)octetstring->value, (void*)buffer, pdulen); - octetstring->value[pdulen] = '\0'; - return octetstring->length; + if (buflen < pdulen) + return -1; + octetstring->length = pdulen; + octetstring->value = malloc(sizeof(uint8_t) * (pdulen+1)); + memcpy((void*)octetstring->value, (void*)buffer, pdulen); + octetstring->value[pdulen] = '\0'; + return octetstring->length; } void dump_octet_string_xml(OctetString *octetstring) { - int i; - printf(" <Length>%u</Length>\n <values>", octetstring->length); - for (i = 0; i < octetstring->length; i++) - printf("0x%x ", octetstring->value[i]); - printf("</values>\n"); + int i; + printf(" <Length>%u</Length>\n <values>", octetstring->length); + for (i = 0; i < octetstring->length; i++) + printf("0x%x ", octetstring->value[i]); + printf("</values>\n"); } diff --git a/openair-cn/NAS/EURECOM-NAS/src/util/TLVDecoder.h b/openair-cn/NAS/EURECOM-NAS/src/util/TLVDecoder.h index 05c4bdbeb805aec90a8b50f2acb461c13a1a892e..ff6501d266f67f308d56e43a341e17fcd9df1674 100644 --- a/openair-cn/NAS/EURECOM-NAS/src/util/TLVDecoder.h +++ b/openair-cn/NAS/EURECOM-NAS/src/util/TLVDecoder.h @@ -47,16 +47,17 @@ DECODE_U32(bUFFER + dECODED, vALUE, dECODED) typedef enum { - TLV_DECODE_ERROR_OK = 0, - TLV_DECODE_UNEXPECTED_IEI = -1, - TLV_DECODE_MANDATORY_FIELD_NOT_PRESENT = -2, - TLV_DECODE_VALUE_DOESNT_MATCH = -3, - /* Fatal errors - received message should not be processed */ - TLV_DECODE_WRONG_MESSAGE_TYPE = -10, - TLV_DECODE_PROTOCOL_NOT_SUPPORTED = -11, - TLV_DECODE_BUFFER_TOO_SHORT = -12, - TLV_DECODE_BUFFER_NULL = -13, - TLV_DECODE_MAC_MISMATCH = -14, + TLV_DECODE_ERROR_OK = 0, + TLV_DECODE_UNEXPECTED_IEI = -1, + TLV_DECODE_MANDATORY_FIELD_NOT_PRESENT = -2, + TLV_DECODE_VALUE_DOESNT_MATCH = -3, + + /* Fatal errors - received message should not be processed */ + TLV_DECODE_WRONG_MESSAGE_TYPE = -10, + TLV_DECODE_PROTOCOL_NOT_SUPPORTED = -11, + TLV_DECODE_BUFFER_TOO_SHORT = -12, + TLV_DECODE_BUFFER_NULL = -13, + TLV_DECODE_MAC_MISMATCH = -14, } tlv_decoder_error_code; /* Defines error code limit below which received message should be discarded