Merge remote-tracking branch 'origin/nr-ue-nas-service-request' into integration_2024_w49 (!3065)
NAS Service Request enc/dec implementation NAS Service Request: - encoding - decoding - unit test Related to #852
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
add_subdirectory(IES)
|
||||
add_subdirectory(EMM)
|
||||
@@ -0,0 +1,5 @@
|
||||
add_subdirectory(MSG)
|
||||
|
||||
if(ENABLE_TESTS)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
@@ -47,7 +47,7 @@ int decode_attach_request(attach_request_msg *attach_request, uint8_t *buffer, u
|
||||
LOG_FUNC_RETURN(decoded_result);
|
||||
}
|
||||
|
||||
if ((decoded_result = decode_u8_nas_key_set_identifier(&attach_request->naskeysetidentifier, 0, *(buffer + decoded) >> 4, len - decoded)) < 0) {
|
||||
if ((decoded_result = decode_nas_key_set_identifier(&attach_request->naskeysetidentifier, 0, *(buffer + decoded) >> 4)) < 0) {
|
||||
// return decoded_result;
|
||||
LOG_FUNC_RETURN(decoded_result);
|
||||
}
|
||||
@@ -299,7 +299,8 @@ int encode_attach_request(attach_request_msg *attach_request, uint8_t *buffer, u
|
||||
/* Checking IEI and pointer */
|
||||
CHECK_PDU_POINTER_AND_LENGTH_ENCODER(buffer, ATTACH_REQUEST_MINIMUM_LENGTH, len);
|
||||
|
||||
*(buffer + encoded) = ((encode_u8_nas_key_set_identifier(&attach_request->naskeysetidentifier) & 0x0f) << 4) | (encode_u8_eps_attach_type(&attach_request->epsattachtype) & 0x0f);
|
||||
*(buffer + encoded) = ((encode_nas_key_set_identifier(&attach_request->naskeysetidentifier, 0) & 0x0f) << 4)
|
||||
| (encode_u8_eps_attach_type(&attach_request->epsattachtype) & 0x0f);
|
||||
encoded++;
|
||||
|
||||
if ((encode_result =
|
||||
|
||||
@@ -38,7 +38,8 @@ int decode_authentication_request(authentication_request_msg *authentication_req
|
||||
CHECK_PDU_POINTER_AND_LENGTH_DECODER(buffer, AUTHENTICATION_REQUEST_MINIMUM_LENGTH, len);
|
||||
|
||||
/* Decoding mandatory fields */
|
||||
if ((decoded_result = decode_u8_nas_key_set_identifier(&authentication_request->naskeysetidentifierasme, 0, *(buffer + decoded), len - decoded)) < 0)
|
||||
if ((decoded_result = decode_nas_key_set_identifier(&authentication_request->naskeysetidentifierasme, 0, *(buffer + decoded)))
|
||||
< 0)
|
||||
return decoded_result;
|
||||
|
||||
decoded++;
|
||||
@@ -64,7 +65,7 @@ int encode_authentication_request(authentication_request_msg *authentication_req
|
||||
/* Checking IEI and pointer */
|
||||
CHECK_PDU_POINTER_AND_LENGTH_ENCODER(buffer, AUTHENTICATION_REQUEST_MINIMUM_LENGTH, len);
|
||||
|
||||
*(buffer + encoded) = ((encode_u8_nas_key_set_identifier(&authentication_request->naskeysetidentifierasme) & 0x0f) << 4) | 0x00;
|
||||
*(buffer + encoded) = ((encode_nas_key_set_identifier(&authentication_request->naskeysetidentifierasme, 0) & 0x0f) << 4) | 0x00;
|
||||
encoded++;
|
||||
|
||||
if ((encode_result =
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
add_library(fgs_lib OBJECT
|
||||
fgs_service_request.c
|
||||
)
|
||||
|
||||
target_link_libraries(fgs_lib PUBLIC fgs_ies_lib)
|
||||
|
||||
target_include_directories(fgs_lib PUBLIC
|
||||
${CMAKE_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
@@ -41,7 +41,7 @@ int decode_detach_request(detach_request_msg *detach_request, uint8_t *buffer, u
|
||||
if ((decoded_result = decode_u8_detach_type(&detach_request->detachtype, 0, *(buffer + decoded) & 0x0f, len - decoded)) < 0)
|
||||
return decoded_result;
|
||||
|
||||
if ((decoded_result = decode_u8_nas_key_set_identifier(&detach_request->naskeysetidentifier, 0, *(buffer + decoded) >> 4, len - decoded)) < 0)
|
||||
if ((decoded_result = decode_nas_key_set_identifier(&detach_request->naskeysetidentifier, 0, *(buffer + decoded) >> 4)) < 0)
|
||||
return decoded_result;
|
||||
|
||||
decoded++;
|
||||
@@ -62,7 +62,8 @@ int encode_detach_request(detach_request_msg *detach_request, uint8_t *buffer, u
|
||||
/* Checking IEI and pointer */
|
||||
CHECK_PDU_POINTER_AND_LENGTH_ENCODER(buffer, DETACH_REQUEST_MINIMUM_LENGTH, len);
|
||||
|
||||
*(buffer + encoded) = ((encode_u8_nas_key_set_identifier(&detach_request->naskeysetidentifier) << 4) | (encode_u8_detach_type(&detach_request->detachtype) & 0x0f));
|
||||
*(buffer + encoded) = ((encode_nas_key_set_identifier(&detach_request->naskeysetidentifier, 0) << 4)
|
||||
| (encode_u8_detach_type(&detach_request->detachtype) & 0x0f));
|
||||
encoded++;
|
||||
|
||||
if ((encode_result = encode_eps_mobile_identity(&detach_request->gutiorimsi,
|
||||
|
||||
@@ -41,7 +41,9 @@ int decode_extended_service_request(extended_service_request_msg *extended_servi
|
||||
if ((decoded_result = decode_u8_service_type(&extended_service_request->servicetype, 0, *(buffer + decoded) >> 4, len - decoded)) < 0)
|
||||
return decoded_result;
|
||||
|
||||
if ((decoded_result = decode_u8_nas_key_set_identifier(&extended_service_request->naskeysetidentifier, 0, *(buffer + decoded) & 0x0f, len - decoded)) < 0)
|
||||
if ((decoded_result =
|
||||
decode_nas_key_set_identifier(&extended_service_request->naskeysetidentifier, 0, *(buffer + decoded) & 0x0f))
|
||||
< 0)
|
||||
return decoded_result;
|
||||
|
||||
decoded++;
|
||||
@@ -62,7 +64,8 @@ int encode_extended_service_request(extended_service_request_msg *extended_servi
|
||||
/* Checking IEI and pointer */
|
||||
CHECK_PDU_POINTER_AND_LENGTH_ENCODER(buffer, EXTENDED_SERVICE_REQUEST_MINIMUM_LENGTH, len);
|
||||
|
||||
*(buffer + encoded) = ((encode_u8_service_type(&extended_service_request->servicetype) & 0x0f) << 4) | (encode_u8_nas_key_set_identifier(&extended_service_request->naskeysetidentifier) & 0x0f);
|
||||
*(buffer + encoded) = ((encode_u8_service_type(&extended_service_request->servicetype) & 0x0f) << 4)
|
||||
| (encode_nas_key_set_identifier(&extended_service_request->naskeysetidentifier, 0) & 0x0f);
|
||||
encoded++;
|
||||
|
||||
if ((encode_result =
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "FGSDeregistrationRequestUEOriginating.h"
|
||||
#include "NR_NAS_defs.h"
|
||||
|
||||
int encode_fgs_deregistration_request_ue_originating(fgs_deregistration_request_ue_originating_msg *drr,
|
||||
uint8_t *buffer,
|
||||
@@ -45,7 +46,7 @@ int encode_fgs_deregistration_request_ue_originating(fgs_deregistration_request_
|
||||
| ((dt->access_type & 0x3) << 4);
|
||||
|
||||
int encode_result;
|
||||
if ((encode_result = encode_nas_key_set_identifier(&drr->naskeysetidentifier, 0, buffer + encoded, len - encoded)) < 0)
|
||||
if ((encode_result = encode_nas_key_set_identifier(&drr->naskeysetidentifier, IEI_NULL)) < 0)
|
||||
return encode_result;
|
||||
|
||||
encoded++;
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "nas_log.h"
|
||||
|
||||
#include "RegistrationRequest.h"
|
||||
#include "NR_NAS_defs.h"
|
||||
|
||||
int decode_registration_request(registration_request_msg *registration_request, uint8_t *buffer, uint32_t len)
|
||||
{
|
||||
@@ -51,7 +52,8 @@ int decode_registration_request(registration_request_msg *registration_request,
|
||||
LOG_FUNC_RETURN(decoded_result);
|
||||
}
|
||||
|
||||
if ((decoded_result = decode_u8_nas_key_set_identifier(®istration_request->naskeysetidentifier, 0, *(buffer + decoded) >> 4, len - decoded)) < 0) {
|
||||
if ((decoded_result = decode_nas_key_set_identifier(®istration_request->naskeysetidentifier, IEI_NULL, *(buffer + decoded) >> 4))
|
||||
< 0) {
|
||||
// return decoded_result;
|
||||
LOG_FUNC_RETURN(decoded_result);
|
||||
}
|
||||
@@ -75,7 +77,8 @@ int encode_registration_request(registration_request_msg *registration_request,
|
||||
int encoded = 0;
|
||||
int encode_result = 0;
|
||||
|
||||
*(buffer + encoded) = ((encode_u8_nas_key_set_identifier(®istration_request->naskeysetidentifier) & 0x0f) << 4) | (encode_5gs_registration_type(®istration_request->fgsregistrationtype) & 0x0f);
|
||||
*(buffer + encoded) = ((encode_nas_key_set_identifier(®istration_request->naskeysetidentifier, IEI_NULL) & 0x0f) << 4)
|
||||
| (encode_5gs_registration_type(®istration_request->fgsregistrationtype) & 0x0f);
|
||||
encoded++;
|
||||
|
||||
if ((encode_result =
|
||||
|
||||
@@ -43,7 +43,8 @@ int decode_security_mode_command(security_mode_command_msg *security_mode_comman
|
||||
else
|
||||
decoded += decoded_result;
|
||||
|
||||
if ((decoded_result = decode_u8_nas_key_set_identifier(&security_mode_command->naskeysetidentifier, 0, *(buffer + decoded) & 0x0f, len - decoded)) < 0)
|
||||
if ((decoded_result = decode_nas_key_set_identifier(&security_mode_command->naskeysetidentifier, 0, *(buffer + decoded) & 0x0f))
|
||||
< 0)
|
||||
return decoded_result;
|
||||
|
||||
decoded++;
|
||||
@@ -124,7 +125,7 @@ int encode_security_mode_command(security_mode_command_msg *security_mode_comman
|
||||
else
|
||||
encoded += encode_result;
|
||||
|
||||
*(buffer + encoded) = (encode_u8_nas_key_set_identifier(&security_mode_command->naskeysetidentifier) & 0x0f);
|
||||
*(buffer + encoded) = (encode_nas_key_set_identifier(&security_mode_command->naskeysetidentifier, 0) & 0x0f);
|
||||
encoded++;
|
||||
|
||||
if ((encode_result =
|
||||
|
||||
@@ -41,7 +41,9 @@ int decode_tracking_area_update_request(tracking_area_update_request_msg *tracki
|
||||
if ((decoded_result = decode_u8_eps_update_type(&tracking_area_update_request->epsupdatetype, 0, *(buffer + decoded) >> 4, len - decoded)) < 0)
|
||||
return decoded_result;
|
||||
|
||||
if ((decoded_result = decode_u8_nas_key_set_identifier(&tracking_area_update_request->naskeysetidentifier, 0, *(buffer + decoded) & 0x0f, len - decoded)) < 0)
|
||||
if ((decoded_result =
|
||||
decode_nas_key_set_identifier(&tracking_area_update_request->naskeysetidentifier, 0, *(buffer + decoded) & 0x0f))
|
||||
< 0)
|
||||
return decoded_result;
|
||||
|
||||
decoded++;
|
||||
@@ -61,10 +63,10 @@ int decode_tracking_area_update_request(tracking_area_update_request_msg *tracki
|
||||
|
||||
switch(ieiDecoded) {
|
||||
case TRACKING_AREA_UPDATE_REQUEST_NONCURRENT_NATIVE_NAS_KEY_SET_IDENTIFIER_IEI:
|
||||
if ((decoded_result =
|
||||
decode_nas_key_set_identifier(&tracking_area_update_request->noncurrentnativenaskeysetidentifier,
|
||||
TRACKING_AREA_UPDATE_REQUEST_NONCURRENT_NATIVE_NAS_KEY_SET_IDENTIFIER_IEI,
|
||||
buffer + decoded, len - decoded)) <= 0)
|
||||
if ((decoded_result = decode_nas_key_set_identifier(&tracking_area_update_request->noncurrentnativenaskeysetidentifier,
|
||||
TRACKING_AREA_UPDATE_REQUEST_NONCURRENT_NATIVE_NAS_KEY_SET_IDENTIFIER_IEI,
|
||||
*(buffer + decoded)))
|
||||
<= 0)
|
||||
return decoded_result;
|
||||
|
||||
decoded += decoded_result;
|
||||
@@ -293,8 +295,8 @@ int encode_tracking_area_update_request(tracking_area_update_request_msg *tracki
|
||||
/* Checking IEI and pointer */
|
||||
CHECK_PDU_POINTER_AND_LENGTH_ENCODER(buffer, TRACKING_AREA_UPDATE_REQUEST_MINIMUM_LENGTH, len);
|
||||
|
||||
*(buffer + encoded) = ((encode_u8_eps_update_type(&tracking_area_update_request->epsupdatetype) & 0x0f) << 4) | (encode_u8_nas_key_set_identifier(
|
||||
&tracking_area_update_request->naskeysetidentifier) & 0x0f);
|
||||
*(buffer + encoded) = ((encode_u8_eps_update_type(&tracking_area_update_request->epsupdatetype) & 0x0f) << 4)
|
||||
| (encode_nas_key_set_identifier(&tracking_area_update_request->naskeysetidentifier, 0) & 0x0f);
|
||||
encoded++;
|
||||
|
||||
if ((encode_result =
|
||||
@@ -306,10 +308,9 @@ int encode_tracking_area_update_request(tracking_area_update_request_msg *tracki
|
||||
|
||||
if ((tracking_area_update_request->presencemask & TRACKING_AREA_UPDATE_REQUEST_NONCURRENT_NATIVE_NAS_KEY_SET_IDENTIFIER_PRESENT)
|
||||
== TRACKING_AREA_UPDATE_REQUEST_NONCURRENT_NATIVE_NAS_KEY_SET_IDENTIFIER_PRESENT) {
|
||||
if ((encode_result =
|
||||
encode_nas_key_set_identifier(&tracking_area_update_request->noncurrentnativenaskeysetidentifier,
|
||||
TRACKING_AREA_UPDATE_REQUEST_NONCURRENT_NATIVE_NAS_KEY_SET_IDENTIFIER_IEI,
|
||||
buffer + encoded, len - encoded)) < 0)
|
||||
if ((encode_result = encode_nas_key_set_identifier(&tracking_area_update_request->noncurrentnativenaskeysetidentifier,
|
||||
TRACKING_AREA_UPDATE_REQUEST_NONCURRENT_NATIVE_NAS_KEY_SET_IDENTIFIER_IEI))
|
||||
< 0)
|
||||
// Return in case of error
|
||||
return encode_result;
|
||||
else
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The OpenAirInterface Software Alliance licenses this file to You under
|
||||
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.openairinterface.org/?page_id=698
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*-------------------------------------------------------------------------------
|
||||
* For more information about the OpenAirInterface (OAI) Software Alliance:
|
||||
* contact@openairinterface.org
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "TLVEncoder.h"
|
||||
#include "TLVDecoder.h"
|
||||
#include "fgs_service_request.h"
|
||||
#include "FGSMobileIdentity.h"
|
||||
#include "NasKeySetIdentifier.h"
|
||||
#include "ServiceType.h"
|
||||
#include "NR_NAS_defs.h"
|
||||
|
||||
#define LEN_FGS_MOBILE_ID_CONTENTS_SIZE 2 // octets
|
||||
#define MIN_LEN_FGS_SERVICE_REQUEST 10 // octets
|
||||
|
||||
/**
|
||||
* @brief Encode 5GMM NAS Service Request message (8.2.16 of 3GPP TS 24.501)
|
||||
*/
|
||||
int encode_fgs_service_request(uint8_t *buffer, fgs_service_request_msg_t *service_request, uint32_t len)
|
||||
{
|
||||
// Return if buffer is shorter than min length
|
||||
if (len < MIN_LEN_FGS_SERVICE_REQUEST)
|
||||
return -1;
|
||||
|
||||
int encoded = 0;
|
||||
|
||||
// ngKSI + Service type (1 octet) (M)
|
||||
*buffer = ((encode_nas_key_set_identifier(&service_request->naskeysetidentifier, IEI_NULL) & 0x0f) << 4)
|
||||
| (service_request->serviceType & 0x0f);
|
||||
encoded++;
|
||||
len -= encoded;
|
||||
|
||||
// 5GS Mobile Identity (M) type 5G-S-TMSI (9 octets)
|
||||
encoded += LEN_FGS_MOBILE_ID_CONTENTS_SIZE; // skip "Length of 5GS mobile identity contents" IE
|
||||
len -= encoded;
|
||||
encoded += encode_stmsi_5gs_mobile_identity(buffer + encoded, &service_request->fiveg_s_tmsi, len);
|
||||
// encode length of 5GS mobile identity contents
|
||||
uint16_t tmp = htons(encoded - LEN_FGS_MOBILE_ID_CONTENTS_SIZE - 1);
|
||||
memcpy(buffer + 1, &tmp, sizeof(tmp));
|
||||
|
||||
return encoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Decode 5GMM NAS Service Request message (8.2.16 of 3GPP TS 24.501)
|
||||
*/
|
||||
int decode_fgs_service_request(fgs_service_request_msg_t *sr, const uint8_t *buffer, uint32_t len)
|
||||
{
|
||||
uint32_t decoded = 0;
|
||||
int decoded_rc = 0;
|
||||
|
||||
// Service type (1/2 octet) (M)
|
||||
sr->serviceType = *buffer & 0x0f;
|
||||
// KSI (1/2 octet) (M)
|
||||
if ((decoded_rc = decode_nas_key_set_identifier(&sr->naskeysetidentifier, IEI_NULL, *buffer >> 4)) < 0) {
|
||||
return decoded_rc;
|
||||
}
|
||||
decoded++;
|
||||
|
||||
// 5GS Mobile Identity (M) type 5G-S-TMSI (9 octets) (M)
|
||||
decoded += LEN_FGS_MOBILE_ID_CONTENTS_SIZE; // skip "Length of 5GS mobile identity contents" IE
|
||||
if ((decoded_rc = decode_stmsi_5gs_mobile_identity(&sr->fiveg_s_tmsi, buffer + decoded, len - decoded)) < 0) {
|
||||
return decoded_rc;
|
||||
}
|
||||
decoded += decoded_rc;
|
||||
|
||||
return decoded;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The OpenAirInterface Software Alliance licenses this file to You under
|
||||
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.openairinterface.org/?page_id=698
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*-------------------------------------------------------------------------------
|
||||
* For more information about the OpenAirInterface (OAI) Software Alliance:
|
||||
* contact@openairinterface.org
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "ProtocolDiscriminator.h"
|
||||
#include "SecurityHeaderType.h"
|
||||
#include "NasKeySetIdentifier.h"
|
||||
#include "ServiceType.h"
|
||||
#include "ExtendedProtocolDiscriminator.h"
|
||||
#include "FGCNasMessageContainer.h"
|
||||
//#include "PDUSessionStatus.h"
|
||||
#include "MessageType.h"
|
||||
#include "SpareHalfOctet.h"
|
||||
#include "FGSMobileIdentity.h"
|
||||
|
||||
#ifndef FGS_SERVICE_REQUEST_H_
|
||||
#define FGS_SERVICE_REQUEST_H_
|
||||
|
||||
/**
|
||||
* Message name: Service request (8.2.16 of 3GPP TS 24.501)
|
||||
* Description: The SERVICE REQUEST message is sent by the UE to the AMF
|
||||
* in order to request the establishment of an N1 NAS signalling
|
||||
* connection and/or to request the establishment of user-plane
|
||||
* resources for PDU sessions which are established without
|
||||
* user-plane resources
|
||||
* Direction: UE to network
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
/* Mandatory fields */
|
||||
NasKeySetIdentifier naskeysetidentifier;
|
||||
ServiceType serviceType: 4;
|
||||
Stmsi5GSMobileIdentity_t fiveg_s_tmsi;
|
||||
/* Optional fields */
|
||||
FGCNasMessageContainer *fgsnasmessagecontainer;
|
||||
} fgs_service_request_msg_t;
|
||||
|
||||
int encode_fgs_service_request(uint8_t *buffer, fgs_service_request_msg_t *servicerequest, uint32_t len);
|
||||
int decode_fgs_service_request(fgs_service_request_msg_t *sr, const uint8_t *buffer, uint32_t len);
|
||||
|
||||
#endif /* ! defined(FGS_SERVICE_REQUEST_H_) */
|
||||
@@ -0,0 +1,13 @@
|
||||
message(STATUS "Add test nas_lib_test")
|
||||
|
||||
add_executable(nas_lib_test nas_lib_test.c)
|
||||
|
||||
add_dependencies(tests nas_lib_test)
|
||||
add_test(NAME nas_lib_test COMMAND nas_lib_test)
|
||||
|
||||
target_link_libraries(nas_lib_test PRIVATE fgs_lib fgs_ies_lib)
|
||||
|
||||
target_include_directories(nas_lib_test PRIVATE
|
||||
${CMAKE_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
@@ -0,0 +1,82 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "fgs_service_request.h"
|
||||
#include "nr_nas_msg.h"
|
||||
|
||||
void exit_function(const char *file, const char *function, const int line, const char *s, const int assert)
|
||||
{
|
||||
printf("detected error at %s:%d:%s: %s\n", file, line, function, s);
|
||||
abort();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Equality check for NAS Service Request enc/dec
|
||||
*/
|
||||
static bool eq_service_request(const fgs_service_request_msg_t *a, const fgs_service_request_msg_t *b)
|
||||
{
|
||||
bool result = true;
|
||||
result &= memcmp(&a->naskeysetidentifier, &b->naskeysetidentifier, sizeof(NasKeySetIdentifier)) == 0;
|
||||
result &= a->serviceType == b->serviceType;
|
||||
result &= memcmp(&a->fiveg_s_tmsi, &b->fiveg_s_tmsi, sizeof(Stmsi5GSMobileIdentity_t)) == 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Test NAS Service Request enc/dec
|
||||
*/
|
||||
static void test_service_request(void)
|
||||
{
|
||||
// Dummy NAS Service Request message
|
||||
uint16_t amf_set_id = 0x48;
|
||||
uint16_t amf_pointer = 0x34;
|
||||
uint32_t tmsi = 0x56789ABC;
|
||||
fgs_service_request_msg_t original_msg = {
|
||||
.naskeysetidentifier = {.tsc = NAS_KEY_SET_IDENTIFIER_NATIVE, .naskeysetidentifier = NAS_KEY_SET_IDENTIFIER_NOT_AVAILABLE},
|
||||
.serviceType = SERVICE_TYPE_DATA,
|
||||
.fiveg_s_tmsi = {.spare = 0,
|
||||
.typeofidentity = FGS_MOBILE_IDENTITY_5GS_TMSI,
|
||||
.amfsetid = amf_set_id,
|
||||
.amfpointer = amf_pointer,
|
||||
.tmsi = tmsi}};
|
||||
|
||||
uint8_t expected_encoded_data[] = {0x71,
|
||||
0x00,
|
||||
0x00,
|
||||
0xF4,
|
||||
(amf_set_id >> 2) & 0xFF,
|
||||
(amf_set_id << 6) | (amf_pointer & 0x3F),
|
||||
(tmsi >> 24) & 0xFF,
|
||||
(tmsi >> 16) & 0xFF,
|
||||
(tmsi >> 8) & 0xFF,
|
||||
tmsi & 0xFF};
|
||||
uint16_t tmp = htons(7); // length of 5GS mobile identity IE for 5G-S-TMSI (bytes)
|
||||
memcpy(expected_encoded_data + 1, &tmp, sizeof(tmp));
|
||||
|
||||
// Buffer
|
||||
uint8_t buffer[64];
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
|
||||
// Encode NAS Service Request
|
||||
int encoded_length = encode_fgs_service_request(buffer, &original_msg, sizeof(buffer));
|
||||
AssertFatal(encoded_length >= 0, "encode_fgs_service_request() failed\n");
|
||||
|
||||
// Compare the raw encoded buffer with expected encoded data
|
||||
AssertFatal(memcmp(buffer, expected_encoded_data, encoded_length) == 0, "Encoding mismatch!\n");
|
||||
|
||||
// Decode NAS Service Request
|
||||
fgs_service_request_msg_t decoded_service_request = {0};
|
||||
int decoded_length = decode_fgs_service_request(&decoded_service_request, buffer, sizeof(buffer));
|
||||
AssertFatal(decoded_length >= 0, "decode_fgs_service_request() failed\n");
|
||||
|
||||
// Compare original and decoded messages
|
||||
AssertFatal(eq_service_request(&original_msg, &decoded_service_request) == 0,
|
||||
"test_service_request() failed: original and decoded messages do not match\n");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_service_request();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
add_library(fgs_ies_lib OBJECT
|
||||
NasKeySetIdentifier.c
|
||||
FGSMobileIdentity.c
|
||||
)
|
||||
|
||||
target_include_directories(fgs_ies_lib PUBLIC
|
||||
${CMAKE_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
@@ -31,18 +31,71 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "TLVEncoder.h"
|
||||
#include "TLVDecoder.h"
|
||||
#include "FGSMobileIdentity.h"
|
||||
|
||||
#define MIN_LEN_FGS_MOBILE_ID_IE 3 // type of identity "No identity"
|
||||
#define LEN_5G_FGS_TMSI_IE 9
|
||||
|
||||
static int decode_guti_5gs_mobile_identity(Guti5GSMobileIdentity_t *guti, const uint8_t *buffer);
|
||||
|
||||
static int encode_guti_5gs_mobile_identity(Guti5GSMobileIdentity_t *guti, uint8_t *buffer);
|
||||
static int encode_suci_5gs_mobile_identity(Suci5GSMobileIdentity_t *suci, uint8_t *buffer);
|
||||
static int encode_imeisv_5gs_mobile_identity(Imeisv5GSMobileIdentity_t *imeisv, uint8_t *buffer);
|
||||
|
||||
int encode_stmsi_5gs_mobile_identity(uint8_t *buffer, Stmsi5GSMobileIdentity_t *stmsi, uint32_t len)
|
||||
{
|
||||
// Return if buffer is shorter than min length
|
||||
if (len < LEN_5G_FGS_TMSI_IE)
|
||||
return -1;
|
||||
|
||||
uint32_t encoded = 0;
|
||||
// octet 4
|
||||
*(buffer + encoded) = (DIGIT1 << 4) | ((stmsi->spare & 0x1) << 3) | (stmsi->typeofidentity & 0x7);
|
||||
encoded++;
|
||||
// octet 5-6
|
||||
uint16_t temp = 0x00 | ((stmsi->amfsetid) << 6) | (stmsi->amfpointer & 0x3f);
|
||||
IES_ENCODE_U16(buffer, encoded, temp);
|
||||
// octet 7
|
||||
IES_ENCODE_U32(buffer, encoded, stmsi->tmsi);
|
||||
return encoded;
|
||||
}
|
||||
|
||||
int decode_stmsi_5gs_mobile_identity(Stmsi5GSMobileIdentity_t *stmsi, const uint8_t *buffer, uint32_t len)
|
||||
{
|
||||
int decoded = 0;
|
||||
uint16_t temp;
|
||||
|
||||
// Return if buffer is shorter than min length
|
||||
if (len < LEN_5G_FGS_TMSI_IE)
|
||||
return -1;
|
||||
|
||||
// Octet 4: spare (bit 3) and type of identity (bits 0-2)
|
||||
stmsi->digit1 = DIGIT1;
|
||||
stmsi->spare = (*(buffer + decoded) >> 3) & 0x1;
|
||||
stmsi->typeofidentity = *(buffer + decoded) & 0x7;
|
||||
|
||||
// Validate type of identity
|
||||
if (stmsi->typeofidentity != FGS_MOBILE_IDENTITY_5GS_TMSI) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
decoded++;
|
||||
|
||||
// Octet 5-6: AMF Set ID (bits 6-15) and AMF Pointer (bits 0-5)
|
||||
IES_DECODE_U16(buffer, decoded, temp);
|
||||
stmsi->amfsetid = (temp >> 6) & 0x03ff;
|
||||
stmsi->amfpointer = temp & 0x3f;
|
||||
|
||||
// Octet 7-10: 32-bit TMSI
|
||||
IES_DECODE_U32(buffer, decoded, stmsi->tmsi);
|
||||
|
||||
return decoded;
|
||||
}
|
||||
|
||||
int decode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei, const uint8_t *buffer, uint32_t len)
|
||||
{
|
||||
int decoded_rc = TLV_DECODE_VALUE_DOESNT_MATCH;
|
||||
@@ -77,6 +130,10 @@ int decode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei
|
||||
|
||||
int encode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei, uint8_t *buffer, uint32_t len)
|
||||
{
|
||||
// Return if buffer is shorter than min length
|
||||
if (len < MIN_LEN_FGS_MOBILE_ID_IE)
|
||||
return -1;
|
||||
|
||||
int encoded_rc = TLV_ENCODE_VALUE_DOESNT_MATCH;
|
||||
uint32_t encoded = 0;
|
||||
|
||||
@@ -86,6 +143,7 @@ int encode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei
|
||||
}
|
||||
|
||||
encoded = encoded + 2;
|
||||
len -= encoded;
|
||||
|
||||
if (fgsmobileidentity->guti.typeofidentity == FGS_MOBILE_IDENTITY_5G_GUTI) {
|
||||
encoded_rc = encode_guti_5gs_mobile_identity(&fgsmobileidentity->guti,
|
||||
@@ -102,6 +160,10 @@ int encode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei
|
||||
buffer + encoded);
|
||||
}
|
||||
|
||||
if (fgsmobileidentity->stmsi.typeofidentity == FGS_MOBILE_IDENTITY_5GS_TMSI) {
|
||||
encoded_rc = encode_stmsi_5gs_mobile_identity(buffer + encoded, &fgsmobileidentity->stmsi, len);
|
||||
}
|
||||
|
||||
if (encoded_rc < 0) {
|
||||
return encoded_rc;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
#ifndef FGS_MOBILE_IDENTITY_H_
|
||||
#define FGS_MOBILE_IDENTITY_H_
|
||||
|
||||
// 4x 1bit according to 9.11.3.4 5GS mobile identity (type 5G-S-TMSI)
|
||||
#define DIGIT1 0xF
|
||||
|
||||
typedef struct {
|
||||
uint8_t spare:5;
|
||||
@@ -151,5 +153,8 @@ int encode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei
|
||||
|
||||
int decode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei, const uint8_t *buffer, uint32_t len);
|
||||
|
||||
int encode_stmsi_5gs_mobile_identity(uint8_t *buffer, Stmsi5GSMobileIdentity_t *stmsi, uint32_t len);
|
||||
int decode_stmsi_5gs_mobile_identity(Stmsi5GSMobileIdentity_t *stmsi, const uint8_t *buffer, uint32_t len);
|
||||
|
||||
#endif /* FGS MOBILE IDENTITY_H_ */
|
||||
|
||||
|
||||
@@ -28,67 +28,34 @@
|
||||
#include "TLVDecoder.h"
|
||||
#include "NasKeySetIdentifier.h"
|
||||
|
||||
int decode_nas_key_set_identifier(NasKeySetIdentifier *naskeysetidentifier, uint8_t iei, uint8_t *buffer, uint32_t len)
|
||||
/**
|
||||
* @brief Decode the NAS key set identifier from one byte
|
||||
*/
|
||||
int decode_nas_key_set_identifier(NasKeySetIdentifier *naskeysetidentifier, uint8_t iei, uint8_t value)
|
||||
{
|
||||
int decoded = 0;
|
||||
CHECK_PDU_POINTER_AND_LENGTH_DECODER(buffer, NAS_KEY_SET_IDENTIFIER_MINIMUM_LENGTH, len);
|
||||
|
||||
if (iei > 0) {
|
||||
CHECK_IEI_DECODER((*buffer & 0xf0), iei);
|
||||
CHECK_IEI_DECODER((value & 0xf0), iei);
|
||||
}
|
||||
|
||||
naskeysetidentifier->tsc = (*(buffer + decoded) >> 3) & 0x1;
|
||||
naskeysetidentifier->naskeysetidentifier = *(buffer + decoded) & 0x7;
|
||||
decoded++;
|
||||
naskeysetidentifier->tsc = (value >> 3) & 0x1;
|
||||
naskeysetidentifier->naskeysetidentifier = value & 0x7;
|
||||
|
||||
#if defined(NAS_DEBUG)
|
||||
dump_nas_key_set_identifier_xml(naskeysetidentifier, iei);
|
||||
#endif
|
||||
|
||||
return 1; // 1 octet
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Encode the NAS key set identifier in one byte
|
||||
*/
|
||||
uint8_t encode_nas_key_set_identifier(NasKeySetIdentifier *naskeysetidentifier, uint8_t iei)
|
||||
{
|
||||
#if defined (NAS_DEBUG)
|
||||
dump_nas_key_set_identifier_xml(naskeysetidentifier, iei);
|
||||
#endif
|
||||
return decoded;
|
||||
}
|
||||
|
||||
int decode_u8_nas_key_set_identifier(NasKeySetIdentifier *naskeysetidentifier, uint8_t iei, uint8_t value, uint32_t len)
|
||||
{
|
||||
int decoded = 0;
|
||||
uint8_t *buffer = &value;
|
||||
naskeysetidentifier->tsc = (*(buffer + decoded) >> 3) & 0x1;
|
||||
naskeysetidentifier->naskeysetidentifier = *(buffer + decoded) & 0x7;
|
||||
decoded++;
|
||||
#if defined (NAS_DEBUG)
|
||||
dump_nas_key_set_identifier_xml(naskeysetidentifier, iei);
|
||||
#endif
|
||||
return decoded;
|
||||
}
|
||||
|
||||
int encode_nas_key_set_identifier(NasKeySetIdentifier *naskeysetidentifier, uint8_t iei, uint8_t *buffer, uint32_t len)
|
||||
{
|
||||
uint8_t encoded = 0;
|
||||
/* Checking length and pointer */
|
||||
CHECK_PDU_POINTER_AND_LENGTH_ENCODER(buffer, NAS_KEY_SET_IDENTIFIER_MINIMUM_LENGTH, len);
|
||||
#if defined (NAS_DEBUG)
|
||||
dump_nas_key_set_identifier_xml(naskeysetidentifier, iei);
|
||||
#endif
|
||||
*(buffer + encoded) = 0x00 | (iei & 0xf0) |
|
||||
((naskeysetidentifier->tsc & 0x1) << 3) |
|
||||
(naskeysetidentifier->naskeysetidentifier & 0x7);
|
||||
encoded++;
|
||||
return encoded;
|
||||
}
|
||||
|
||||
uint8_t encode_u8_nas_key_set_identifier(NasKeySetIdentifier *naskeysetidentifier)
|
||||
{
|
||||
uint8_t bufferReturn;
|
||||
uint8_t *buffer = &bufferReturn;
|
||||
uint8_t encoded = 0;
|
||||
uint8_t iei = 0;
|
||||
#if defined (NAS_DEBUG)
|
||||
dump_nas_key_set_identifier_xml(naskeysetidentifier, 0);
|
||||
#endif
|
||||
*(buffer + encoded) = 0x00 | (iei & 0xf0) |
|
||||
((naskeysetidentifier->tsc & 0x1) << 3) |
|
||||
(naskeysetidentifier->naskeysetidentifier & 0x7);
|
||||
encoded++;
|
||||
|
||||
return bufferReturn;
|
||||
return ((iei & 0xf0) | (naskeysetidentifier->tsc & 0x1) << 3) | (naskeysetidentifier->naskeysetidentifier & 0x7);
|
||||
}
|
||||
|
||||
void dump_nas_key_set_identifier_xml(NasKeySetIdentifier *naskeysetidentifier, uint8_t iei)
|
||||
|
||||
@@ -39,15 +39,11 @@ typedef struct NasKeySetIdentifier_tag {
|
||||
uint8_t naskeysetidentifier:3;
|
||||
} NasKeySetIdentifier;
|
||||
|
||||
int encode_nas_key_set_identifier(NasKeySetIdentifier *naskeysetidentifier, uint8_t iei, uint8_t *buffer, uint32_t len);
|
||||
uint8_t encode_nas_key_set_identifier(NasKeySetIdentifier *naskeysetidentifier, uint8_t iei);
|
||||
|
||||
void dump_nas_key_set_identifier_xml(NasKeySetIdentifier *naskeysetidentifier, uint8_t iei);
|
||||
|
||||
uint8_t encode_u8_nas_key_set_identifier(NasKeySetIdentifier *naskeysetidentifier);
|
||||
|
||||
int decode_nas_key_set_identifier(NasKeySetIdentifier *naskeysetidentifier, uint8_t iei, uint8_t *buffer, uint32_t len);
|
||||
|
||||
int decode_u8_nas_key_set_identifier(NasKeySetIdentifier *naskeysetidentifier, uint8_t iei, uint8_t value, uint32_t len);
|
||||
int decode_nas_key_set_identifier(NasKeySetIdentifier *naskeysetidentifier, uint8_t iei, uint8_t value);
|
||||
|
||||
#endif /* NAS KEY SET IDENTIFIER_H_ */
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
|
||||
#include <common/utils/LOG/log.h>
|
||||
#include <openair3/UICC/usim_interface.h>
|
||||
#include <openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h>
|
||||
|
||||
/* TS 24.007 possible L3 formats:
|
||||
Table 11.1: Formats of information elements
|
||||
@@ -72,9 +71,9 @@ typedef enum {
|
||||
TYPE_DEF(FGS_DEREGISTRATION_ACCEPT_UE_ORIGINATING, 0x46) \
|
||||
TYPE_DEF(DeregistrationrequestUEterminated, 0x47) \
|
||||
TYPE_DEF(DeregistrationacceptUEterminated, 0x48) \
|
||||
TYPE_DEF(Servicerequest, 0x4c) \
|
||||
TYPE_DEF(Servicereject, 0x4d) \
|
||||
TYPE_DEF(Serviceaccept, 0x4e) \
|
||||
TYPE_DEF(FGS_SERVICE_REQUEST, 0x4c) \
|
||||
TYPE_DEF(FGS_SERVICE_REJECT, 0x4d) \
|
||||
TYPE_DEF(FGS_SERVICE_ACCEPT, 0x4e) \
|
||||
TYPE_DEF(Controlplaneservicerequest, 0x4f) \
|
||||
TYPE_DEF(Networkslicespecificauthenticationcommand, 0x50) \
|
||||
TYPE_DEF(Networkslicespecificauthenticationcomplete, 0x51) \
|
||||
@@ -257,6 +256,7 @@ typedef enum {
|
||||
} cause_secu_id_t;
|
||||
|
||||
// IEI (information element identifier) are spread in each message definition
|
||||
#define IEI_NULL 0x00
|
||||
#define IEI_RAND 0x21
|
||||
#define IEI_AUTN 0x20
|
||||
#define IEI_EAP 0x78
|
||||
@@ -381,18 +381,6 @@ int resToresStar(uint8_t *msg, const uicc_t* uicc);
|
||||
|
||||
int identityResponse(void **msg, nr_user_nas_t *UE);
|
||||
int authenticationResponse(void **msg, nr_user_nas_t *UE);
|
||||
void UEprocessNAS(void *msg,nr_user_nas_t *UE);
|
||||
void SGSabortUE(void *msg, NRUEcontext_t *UE) ;
|
||||
void SGSregistrationReq(void *msg, NRUEcontext_t *UE);
|
||||
void SGSderegistrationUEReq(void *msg, NRUEcontext_t *UE);
|
||||
void SGSauthenticationResp(void *msg, NRUEcontext_t *UE);
|
||||
void SGSidentityResp(void *msg, NRUEcontext_t *UE);
|
||||
void SGSsecurityModeComplete(void *msg, NRUEcontext_t *UE);
|
||||
void SGSregistrationComplete(void *msg, NRUEcontext_t *UE);
|
||||
void processNAS(void *msg, NRUEcontext_t *UE);
|
||||
int identityRequest(void **msg, NRUEcontext_t *UE);
|
||||
int authenticationRequest(void **msg, NRUEcontext_t *UE);
|
||||
int securityModeCommand(void **msg, NRUEcontext_t *UE);
|
||||
void servingNetworkName(uint8_t *msg, char * imsiStr, int nmc_size);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,28 +23,4 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "TLVDecoder.h"
|
||||
|
||||
int errorCodeDecoder = 0;
|
||||
|
||||
static const char* const errorCodeStringDecoder[] = {
|
||||
"No error",
|
||||
"Buffer NULL",
|
||||
"Buffer too short",
|
||||
"Unexpected IEI",
|
||||
"Mandatory field not present",
|
||||
"Wrong message type",
|
||||
"EXT value doesn't match",
|
||||
"Protocol not supported",
|
||||
};
|
||||
|
||||
void tlv_decode_perror(void)
|
||||
{
|
||||
if (errorCodeDecoder >= 0)
|
||||
// No error or TLV_DECODE_ERR_OK
|
||||
return;
|
||||
|
||||
printf("TLV decoder error: (%d, %s)\n", errorCodeDecoder, errorCodeStringDecoder[errorCodeDecoder * -1]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -95,48 +95,56 @@ typedef enum {
|
||||
|
||||
extern int errorCodeDecoder;
|
||||
|
||||
void tlv_decode_perror(void);
|
||||
#ifdef ENABLE_TESTS
|
||||
#define TLV_DEC_ERROR(...) fprintf(stderr, "TLV Decoder: " __VA_ARGS__)
|
||||
#else
|
||||
#define TLV_DEC_ERROR(...) // Do nothing
|
||||
#endif
|
||||
|
||||
#define CHECK_PDU_POINTER_AND_LENGTH_DECODER(bUFFER, mINIMUMlENGTH, lENGTH) \
|
||||
if (bUFFER == NULL) \
|
||||
{ \
|
||||
printf("(%s:%d) Got NULL pointer for the payload\n", \
|
||||
__FILE__, __LINE__); \
|
||||
errorCodeDecoder = TLV_DECODE_BUFFER_NULL; \
|
||||
LOG_FUNC_RETURN(TLV_DECODE_BUFFER_NULL); \
|
||||
} \
|
||||
if (lENGTH < mINIMUMlENGTH) \
|
||||
{ \
|
||||
printf("(%s:%d) Expecting at least %d bytes, got %u\n", \
|
||||
__FILE__, __LINE__, mINIMUMlENGTH, lENGTH); \
|
||||
errorCodeDecoder = TLV_DECODE_BUFFER_TOO_SHORT; \
|
||||
LOG_FUNC_RETURN(TLV_DECODE_BUFFER_TOO_SHORT); \
|
||||
}
|
||||
#define CHECK_PDU_POINTER_AND_LENGTH_DECODER(bUFFER, mINIMUMlENGTH, lENGTH) \
|
||||
do { \
|
||||
if ((bUFFER) == NULL) { \
|
||||
TLV_DEC_ERROR("(%s:%d) Got NULL pointer for the payload\n", __FILE__, __LINE__); \
|
||||
return TLV_DECODE_BUFFER_NULL; \
|
||||
} \
|
||||
if ((lENGTH) < (mINIMUMlENGTH)) { \
|
||||
TLV_DEC_ERROR("(%s:%d) Expecting at least %d bytes, got %u\n", __FILE__, __LINE__, (mINIMUMlENGTH), (lENGTH)); \
|
||||
return TLV_DECODE_BUFFER_TOO_SHORT; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_LENGTH_DECODER(bUFFERlENGTH, lENGTH) \
|
||||
if (bUFFERlENGTH < lENGTH) \
|
||||
{ \
|
||||
errorCodeDecoder = TLV_DECODE_BUFFER_TOO_SHORT; \
|
||||
LOG_FUNC_RETURN(TLV_DECODE_BUFFER_TOO_SHORT); \
|
||||
}
|
||||
#define CHECK_LENGTH_DECODER(bUFFERlENGTH, lENGTH) \
|
||||
do { \
|
||||
if ((bUFFERlENGTH) < (lENGTH)) { \
|
||||
TLV_DEC_ERROR("(%s:%d) Buffer is too short, length (%u) is less than the required length (%u)\n", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
(bUFFERlENGTH), \
|
||||
(lENGTH)); \
|
||||
return TLV_DECODE_BUFFER_TOO_SHORT; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_MESSAGE_TYPE(mESSAGE_tYPE, bUFFER) \
|
||||
{ \
|
||||
if (mESSAGE_tYPE != bUFFER) \
|
||||
{ \
|
||||
errorCodeDecoder = TLV_DECODE_WRONG_MESSAGE_TYPE; \
|
||||
LOG_FUNC_RETURN(errorCodeDecoder); \
|
||||
} \
|
||||
}
|
||||
#define CHECK_MESSAGE_TYPE(mESSAGE_TYPE, BUFFER) \
|
||||
do { \
|
||||
if ((MESSAGE_TYPE) != (BUFFER)) { \
|
||||
TLV_DEC_ERROR("(%s:%d) Wrong message type: Got: %u, Expected: %u\n", __FILE__, __LINE__, (BUFFER), (MESSAGE_TYPE)); \
|
||||
return TLV_DECODE_WRONG_MESSAGE_TYPE; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_IEI_DECODER(iEI, bUFFER) \
|
||||
if(iEI != bUFFER) \
|
||||
{ \
|
||||
printf("IEI is different than the one expected." \
|
||||
"(Got: 0x%x, expecting: 0x%x)\n", bUFFER, iEI); \
|
||||
errorCodeDecoder = TLV_DECODE_UNEXPECTED_IEI; \
|
||||
LOG_FUNC_RETURN(TLV_DECODE_UNEXPECTED_IEI); \
|
||||
}
|
||||
#define CHECK_IEI_DECODER(iEI, bUFFER) \
|
||||
do { \
|
||||
if ((iEI) != (bUFFER)) { \
|
||||
TLV_DEC_ERROR( \
|
||||
"IEI check failure: %s:%d: IEI is different than the one expected: " \
|
||||
"(Got: 0x%x, expecting: 0x%x)\n", \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
(bUFFER), \
|
||||
(iEI)); \
|
||||
return TLV_DECODE_UNEXPECTED_IEI; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif /* define (TLV_DECODER_H_) */
|
||||
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The OpenAirInterface Software Alliance licenses this file to You under
|
||||
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.openairinterface.org/?page_id=698
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*-------------------------------------------------------------------------------
|
||||
* For more information about the OpenAirInterface (OAI) Software Alliance:
|
||||
* contact@openairinterface.org
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "TLVEncoder.h"
|
||||
|
||||
int errorCodeEncoder = 0;
|
||||
|
||||
const char *const errorCodeStringEncoder[] = {
|
||||
"No error",
|
||||
"Buffer NULL",
|
||||
"Buffer too short",
|
||||
"Octet string too long for IEI",
|
||||
"Wrong message type",
|
||||
"Protocol not supported",
|
||||
};
|
||||
|
||||
void tlv_encode_perror(void)
|
||||
{
|
||||
if (errorCodeEncoder >= 0)
|
||||
// No error or TLV_DECODE_ERR_OK
|
||||
return;
|
||||
|
||||
printf("error: (%d, %s)\n", errorCodeEncoder, errorCodeStringEncoder[errorCodeEncoder * -1]);
|
||||
}
|
||||
|
||||
@@ -84,32 +84,32 @@ typedef enum {
|
||||
* it cannot be further processed */
|
||||
#define TLV_ENCODE_FATAL_ERROR (TLV_ENCODE_VALUE_DOESNT_MATCH)
|
||||
|
||||
extern int errorCodeEncoder;
|
||||
#ifdef ENABLE_TESTS
|
||||
#define TLV_ENC_ERROR(...) fprintf(stderr, "TLV Encoder: " __VA_ARGS__)
|
||||
#else
|
||||
#define TLV_ENC_ERROR(...) // Do nothing
|
||||
#endif
|
||||
|
||||
void tlv_encode_perror(void);
|
||||
#define CHECK_PDU_POINTER_AND_LENGTH_ENCODER(bUFFER, mINIMUMlENGTH, lENGTH) \
|
||||
do { \
|
||||
if ((bUFFER) == NULL) { \
|
||||
TLV_ENC_ERROR("Got NULL pointer for the payload\n"); \
|
||||
return TLV_ENCODE_BUFFER_NULL; \
|
||||
} \
|
||||
if ((lENGTH) < (mINIMUMlENGTH)) { \
|
||||
TLV_ENC_ERROR("(%s:%d) Expecting at least %d bytes, got %u\n", __FILE__, __LINE__, (mINIMUMlENGTH), (lENGTH)); \
|
||||
return TLV_ENCODE_BUFFER_TOO_SHORT; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_PDU_POINTER_AND_LENGTH_ENCODER(bUFFER, mINIMUMlENGTH, lENGTH) \
|
||||
if (bUFFER == NULL) \
|
||||
{ \
|
||||
printf("Got NULL pointer for the payload\n"); \
|
||||
errorCodeEncoder = TLV_ENCODE_BUFFER_NULL; \
|
||||
return TLV_ENCODE_BUFFER_NULL; \
|
||||
} \
|
||||
if (lENGTH < mINIMUMlENGTH) \
|
||||
{ \
|
||||
printf("(%s:%d) Expecting at least %d bytes, got %u\n", \
|
||||
__FILE__, __LINE__, mINIMUMlENGTH, lENGTH); \
|
||||
errorCodeEncoder = TLV_ENCODE_BUFFER_TOO_SHORT; \
|
||||
return TLV_ENCODE_BUFFER_TOO_SHORT; \
|
||||
}
|
||||
|
||||
#define CHECK_PDU_POINTER_ENCODER(bUFFER) \
|
||||
if (bUFFER == NULL) \
|
||||
{ \
|
||||
printf("Got NULL pointer for the payload\n"); \
|
||||
errorCodeEncoder = TLV_ENCODE_BUFFER_NULL; \
|
||||
return TLV_ENCODE_BUFFER_NULL; \
|
||||
}
|
||||
#define CHECK_PDU_POINTER_ENCODER(bUFFER) \
|
||||
do { \
|
||||
if ((bUFFER) == NULL) { \
|
||||
TLV_ENC_ERROR("Got NULL pointer for the payload\n"); \
|
||||
errorCodeEncoder = TLV_ENCODE_BUFFER_NULL; \
|
||||
return TLV_ENCODE_BUFFER_NULL; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif /* define (TLV_ENCODER_H_) */
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
* contact@openairinterface.org
|
||||
*/
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <openair3/NAS/COMMON/NR_NAS_defs.h>
|
||||
#include <openair3/SECU/secu_defs.h>
|
||||
#include <openair3/SECU/kdf.h>
|
||||
|
||||
Reference in New Issue
Block a user