From 48f82a63aaa09af63bf9385ba04a2cd8350d0d8d Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Tue, 30 May 2023 13:48:32 +0200 Subject: [PATCH] F1: do not assert on unknown F1 message Previously, in f1ap_decoder.c, we asserted if we did not know a message. Apart form decoding, we did not do anything in that file. Additionally, in f1ap_handlers.c, we were also checking for an unknown message, and printing a warning if a handler is not known. This commit moves the F1AP message decoding to f1ap_handlers.c, and deletes f1ap_decoder.c. In summary, we don't assert on an unknown message, and compile less files. The rest is unchanged. --- CMakeLists.txt | 1 - doc/Doxyfile | 2 - openair2/F1AP/f1ap_cu_interface_management.c | 1 - openair2/F1AP/f1ap_cu_rrc_message_transfer.c | 1 - openair2/F1AP/f1ap_cu_ue_context_management.c | 1 - openair2/F1AP/f1ap_decoder.c | 205 ------------------ openair2/F1AP/f1ap_decoder.h | 39 ---- openair2/F1AP/f1ap_du_interface_management.c | 1 - openair2/F1AP/f1ap_du_rrc_message_transfer.c | 1 - openair2/F1AP/f1ap_du_ue_context_management.c | 1 - openair2/F1AP/f1ap_handlers.c | 64 ++++-- 11 files changed, 44 insertions(+), 273 deletions(-) delete mode 100644 openair2/F1AP/f1ap_decoder.c delete mode 100644 openair2/F1AP/f1ap_decoder.h diff --git a/CMakeLists.txt b/CMakeLists.txt index a4a4b94028..dd16792faf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -449,7 +449,6 @@ add_library(f1ap ${F1AP_DIR}/f1ap_cu_task.c ${F1AP_DIR}/f1ap_cu_ue_context_management.c ${F1AP_DIR}/f1ap_cu_warning_message_transmission.c - ${F1AP_DIR}/f1ap_decoder.c ${F1AP_DIR}/f1ap_du_interface_management.c ${F1AP_DIR}/f1ap_du_paging.c ${F1AP_DIR}/f1ap_du_rrc_message_transfer.c diff --git a/doc/Doxyfile b/doc/Doxyfile index afb89b43ef..aba95ed7ec 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -1010,12 +1010,10 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/F1AP/f1ap_du_rrc_message_transfer.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/F1AP/f1ap_default_values.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/F1AP/f1ap_du_rrc_message_transfer.h \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair2/F1AP/f1ap_decoder.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/F1AP/f1ap_encoder.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/F1AP/f1ap_itti_messaging.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/F1AP/f1ap_itti_messaging.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/F1AP/f1ap_cu_ue_context_management.c \ -@CMAKE_CURRENT_SOURCE_DIR@/../openair2/F1AP/f1ap_decoder.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/F1AP/f1ap_cu_paging.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/F1AP/f1ap_du_warning_message_transmission.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/F1AP/f1ap_encoder.h \ diff --git a/openair2/F1AP/f1ap_cu_interface_management.c b/openair2/F1AP/f1ap_cu_interface_management.c index 8638355b88..6b2384b7c8 100644 --- a/openair2/F1AP/f1ap_cu_interface_management.c +++ b/openair2/F1AP/f1ap_cu_interface_management.c @@ -32,7 +32,6 @@ #include "f1ap_common.h" #include "f1ap_encoder.h" -#include "f1ap_decoder.h" #include "f1ap_itti_messaging.h" #include "f1ap_cu_interface_management.h" diff --git a/openair2/F1AP/f1ap_cu_rrc_message_transfer.c b/openair2/F1AP/f1ap_cu_rrc_message_transfer.c index 7fc30967de..06251fcff8 100644 --- a/openair2/F1AP/f1ap_cu_rrc_message_transfer.c +++ b/openair2/F1AP/f1ap_cu_rrc_message_transfer.c @@ -32,7 +32,6 @@ #include "f1ap_common.h" #include "f1ap_encoder.h" -#include "f1ap_decoder.h" #include "f1ap_itti_messaging.h" #include "f1ap_cu_rrc_message_transfer.h" #include "common/ran_context.h" diff --git a/openair2/F1AP/f1ap_cu_ue_context_management.c b/openair2/F1AP/f1ap_cu_ue_context_management.c index 3e2197c282..a38dd7c68f 100644 --- a/openair2/F1AP/f1ap_cu_ue_context_management.c +++ b/openair2/F1AP/f1ap_cu_ue_context_management.c @@ -32,7 +32,6 @@ #include "f1ap_common.h" #include "f1ap_encoder.h" -#include "f1ap_decoder.h" #include "f1ap_itti_messaging.h" #include "f1ap_cu_ue_context_management.h" #include diff --git a/openair2/F1AP/f1ap_decoder.c b/openair2/F1AP/f1ap_decoder.c deleted file mode 100644 index e0d7db216d..0000000000 --- a/openair2/F1AP/f1ap_decoder.c +++ /dev/null @@ -1,205 +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 - */ - -/*! \file f1ap_decoder.c - * \brief f1ap pdu decode procedures - * \author EURECOM/NTUST - * \date 2018 - * \version 0.1 - * \company Eurecom - * \email: navid.nikaein@eurecom.fr, bing-kai.hong@eurecom.fr - * \note - * \warning - */ - -#include "f1ap_common.h" -#include "f1ap_decoder.h" - -int asn1_decoder_xer_print = 0; - -static int f1ap_decode_initiating_message(F1AP_F1AP_PDU_t *pdu) { - //MessageDef *message_p; - //MessagesIds message_id; - //asn_encode_to_new_buffer_result_t res = { NULL, {0, NULL, NULL} }; - DevAssert(pdu != NULL); - - switch(pdu->choice.initiatingMessage->procedureCode) { - case F1AP_ProcedureCode_id_F1Setup: - //res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu); - LOG_D(F1AP, "%s(): F1AP_ProcedureCode_id_F1Setup\n", __func__); - break; - - case F1AP_ProcedureCode_id_gNBCUConfigurationUpdate: - //res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu); - LOG_D(F1AP, "%s(): F1AP_ProcedureCode_id_gNBCUConfigurationUpdate\n", __func__); - break; - - case F1AP_ProcedureCode_id_InitialULRRCMessageTransfer: - //res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu); - LOG_D(F1AP, "%s(): F1AP_ProcedureCode_id_InitialULRRCMessageTransfer\n", __func__); - break; - - case F1AP_ProcedureCode_id_DLRRCMessageTransfer: - //res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu); - LOG_D(F1AP, "%s(): F1AP_ProcedureCode_id_DLRRCMessageTransfer\n", __func__); - break; - - case F1AP_ProcedureCode_id_ULRRCMessageTransfer: - //res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu); - LOG_D(F1AP, "%s(): F1AP_ProcedureCode_id_ULRRCMessageTransfer\n", __func__); - break; - - case F1AP_ProcedureCode_id_UEContextRelease: - LOG_D(F1AP, "%s(): F1AP_ProcedureCode_id_UEContextRelease\n", __func__); - break; - - case F1AP_ProcedureCode_id_UEContextReleaseRequest: - LOG_D(F1AP, "%s(): F1AP_ProcedureCode_id_UEContextReleaseRequest\n", __func__); - break; - - case F1AP_ProcedureCode_id_UEContextSetup: - LOG_D(F1AP, "%s(): F1AP_ProcedureCode_id_UEContextSetup\n", __func__); - break; - - case F1AP_ProcedureCode_id_UEContextModification: - LOG_D(F1AP, "%s(): F1AP_ProcedureCode_id_UEContextModification\n", __func__); - break; - - case F1AP_ProcedureCode_id_Paging: - LOG_D(F1AP, "%s(): F1AP_ProcedureCode_id_Paging\n", __func__); - break; - - // case F1AP_ProcedureCode_id_InitialContextSetup: - // res = asn_encode_to_new_buffer(NULL, ATS_CANONICAL_XER, &asn_DEF_F1AP_F1AP_PDU, pdu); - // message_id = F1AP_INITIAL_CONTEXT_SETUP_LOG; - // message_p = itti_alloc_new_message_sized(TASK_F1AP, message_id, - // res.result.encoded + sizeof (IttiMsgText)); - // message_p->ittiMsg.f1ap_initial_context_setup_log.size = res.result.encoded; - // memcpy(&message_p->ittiMsg.f1ap_initial_context_setup_log.text, res.buffer, res.result.encoded); - // itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p); - // free(res.buffer); - // break; - - default: - // F1AP_ERROR("Unknown procedure ID (%d) for initiating message\n", - // (int)pdu->choice.initiatingMessage->procedureCode); - LOG_E(F1AP, "Unknown procedure ID (%d) for initiating message\n", - (int)pdu->choice.initiatingMessage->procedureCode); - AssertFatal( 0, "Unknown procedure ID (%d) for initiating message\n", - (int)pdu->choice.initiatingMessage->procedureCode); - return -1; - } - - return 0; -} - -static int f1ap_decode_successful_outcome(F1AP_F1AP_PDU_t *pdu) { - DevAssert(pdu != NULL); - - switch(pdu->choice.successfulOutcome->procedureCode) { - case F1AP_ProcedureCode_id_F1Setup: - LOG_D(F1AP, "%s(): F1AP_ProcedureCode_id_F1Setup\n", __func__); - break; - - case F1AP_ProcedureCode_id_gNBCUConfigurationUpdate: - LOG_D(F1AP, "%s(): F1AP_ProcedureCode_id_gNBCUConfigurationUpdate\n", __func__); - break; - - case F1AP_ProcedureCode_id_UEContextRelease: - LOG_D(F1AP, "%s(): F1AP_ProcedureCode_id_UEContextRelease\n", __func__); - break; - - case F1AP_ProcedureCode_id_UEContextSetup: - LOG_D(F1AP, "%s(): F1AP_ProcedureCode_id_UEContextSetup\n", __func__); - break; - - case F1AP_ProcedureCode_id_UEContextModification: - LOG_D(F1AP, "%s(): F1AP_ProcedureCode_id_UEContextModification\n", __func__); - break; - - default: - LOG_E(F1AP,"Unknown procedure ID (%d) for successfull outcome message\n", - (int)pdu->choice.successfulOutcome->procedureCode); - return -1; - } - - return 0; -} - -static int f1ap_decode_unsuccessful_outcome(F1AP_F1AP_PDU_t *pdu) { - DevAssert(pdu != NULL); - - switch(pdu->choice.unsuccessfulOutcome->procedureCode) { - case F1AP_ProcedureCode_id_F1Setup: - LOG_D(F1AP, "%s(): F1AP_ProcedureCode_id_F1Setup\n", __func__); - break; - - default: - // F1AP_ERROR("Unknown procedure ID (%d) for unsuccessfull outcome message\n", - // (int)pdu->choice.unsuccessfulOutcome->procedureCode); - LOG_E(F1AP, "Unknown procedure ID (%d) for unsuccessfull outcome message\n", - (int)pdu->choice.unsuccessfulOutcome->procedureCode); - return -1; - } - - return 0; -} - -int f1ap_decode_pdu(F1AP_F1AP_PDU_t *pdu, const uint8_t *const buffer, uint32_t length) { - asn_dec_rval_t dec_ret; - DevAssert(buffer != NULL); - asn_codec_ctx_t st={.max_stack_size = 100 * 1000}; - dec_ret = aper_decode(&st, - &asn_DEF_F1AP_F1AP_PDU, - (void **)&pdu, - buffer, - length, - 0, - 0); - - if (asn1_decoder_xer_print) { - LOG_E(F1AP, "----------------- ASN1 DECODER PRINT START----------------- \n"); - xer_fprint(stdout, &asn_DEF_F1AP_F1AP_PDU, pdu); - LOG_E(F1AP, "----------------- ASN1 DECODER PRINT END ----------------- \n"); - } - - if (dec_ret.code != RC_OK) { - AssertFatal(1==0,"Failed to decode pdu\n"); - return -1; - } - - switch(pdu->present) { - case F1AP_F1AP_PDU_PR_initiatingMessage: - return f1ap_decode_initiating_message(pdu); - - case F1AP_F1AP_PDU_PR_successfulOutcome: - return f1ap_decode_successful_outcome(pdu); - - case F1AP_F1AP_PDU_PR_unsuccessfulOutcome: - return f1ap_decode_unsuccessful_outcome(pdu); - - default: - LOG_E(F1AP, "Unknown presence (%d) or not implemented\n", (int)pdu->present); - break; - } - - return -1; -} diff --git a/openair2/F1AP/f1ap_decoder.h b/openair2/F1AP/f1ap_decoder.h deleted file mode 100644 index 57814db34d..0000000000 --- a/openair2/F1AP/f1ap_decoder.h +++ /dev/null @@ -1,39 +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 - */ - -/*! \file f1ap_decoder.h - * \brief f1ap pdu decode procedures - * \author EURECOM/NTUST - * \date 2018 - * \version 0.1 - * \company Eurecom - * \email: navid.nikaein@eurecom.fr, bing-kai.hong@eurecom.fr - * \note - * \warning - */ - -#ifndef F1AP_ENB_ENCODER_H_ -#define F1AP_ENB_ENCODER_H_ - -int f1ap_decode_pdu(F1AP_F1AP_PDU_t *pdu, const uint8_t *const buffer, uint32_t length) -__attribute__ ((warn_unused_result)); - -#endif /* F1AP_ENB_ENCODER_H_ */ diff --git a/openair2/F1AP/f1ap_du_interface_management.c b/openair2/F1AP/f1ap_du_interface_management.c index 94fecfea11..053e302f13 100644 --- a/openair2/F1AP/f1ap_du_interface_management.c +++ b/openair2/F1AP/f1ap_du_interface_management.c @@ -32,7 +32,6 @@ #include "f1ap_common.h" #include "f1ap_encoder.h" -#include "f1ap_decoder.h" #include "f1ap_itti_messaging.h" #include "f1ap_du_interface_management.h" #include "assertions.h" diff --git a/openair2/F1AP/f1ap_du_rrc_message_transfer.c b/openair2/F1AP/f1ap_du_rrc_message_transfer.c index c2fefec662..be2a9b8348 100644 --- a/openair2/F1AP/f1ap_du_rrc_message_transfer.c +++ b/openair2/F1AP/f1ap_du_rrc_message_transfer.c @@ -32,7 +32,6 @@ #include "f1ap_common.h" #include "f1ap_encoder.h" -#include "f1ap_decoder.h" #include "f1ap_itti_messaging.h" #include "f1ap_du_rrc_message_transfer.h" diff --git a/openair2/F1AP/f1ap_du_ue_context_management.c b/openair2/F1AP/f1ap_du_ue_context_management.c index 9aa3c42213..ccd3381e95 100644 --- a/openair2/F1AP/f1ap_du_ue_context_management.c +++ b/openair2/F1AP/f1ap_du_ue_context_management.c @@ -32,7 +32,6 @@ #include "f1ap_common.h" #include "f1ap_encoder.h" -#include "f1ap_decoder.h" #include "f1ap_itti_messaging.h" #include "f1ap_du_ue_context_management.h" #include "openair2/LAYER2/NR_MAC_gNB/mac_rrc_dl_handler.h" diff --git a/openair2/F1AP/f1ap_handlers.c b/openair2/F1AP/f1ap_handlers.c index 99a591bd05..8b6cc38fec 100644 --- a/openair2/F1AP/f1ap_handlers.c +++ b/openair2/F1AP/f1ap_handlers.c @@ -31,7 +31,6 @@ */ #include "f1ap_common.h" -#include "f1ap_decoder.h" #include "f1ap_cu_interface_management.h" #include "f1ap_du_interface_management.h" #include "f1ap_cu_rrc_message_transfer.h" @@ -81,41 +80,66 @@ const char *f1ap_direction2String(int f1ap_dir) { return(f1ap_direction_String[f1ap_dir]); } -int f1ap_handle_message(instance_t instance, uint32_t assoc_id, int32_t stream, - const uint8_t *const data, const uint32_t data_length) { - F1AP_F1AP_PDU_t pdu= {0}; - int ret; +static F1AP_F1AP_PDU_t *f1ap_decode_pdu(const uint8_t *const buffer, uint32_t length) +{ + DevAssert(buffer != NULL); + asn_codec_ctx_t st = {.max_stack_size = 100 * 1000}; + F1AP_F1AP_PDU_t *pdu = NULL; + asn_dec_rval_t dec_ret = aper_decode(&st, &asn_DEF_F1AP_F1AP_PDU, (void **)&pdu, buffer, length, 0, 0); + + if (LOG_DEBUGFLAG(DEBUG_ASN1)) { + LOG_E(F1AP, "----------------- ASN1 DECODER PRINT START----------------- \n"); + xer_fprint(stdout, &asn_DEF_F1AP_F1AP_PDU, pdu); + LOG_E(F1AP, "----------------- ASN1 DECODER PRINT END ----------------- \n"); + } + + return dec_ret.code == RC_OK ? pdu : NULL; +} + +int f1ap_handle_message(instance_t instance, + uint32_t assoc_id, + int32_t stream, + const uint8_t *const data, + const uint32_t data_length) +{ DevAssert(data != NULL); - if (f1ap_decode_pdu(&pdu, data, data_length) < 0) { + F1AP_F1AP_PDU_t *pdu = f1ap_decode_pdu(data, data_length); + if (pdu == NULL) { LOG_E(F1AP, "Failed to decode PDU\n"); return -1; } /* Checking procedure Code and direction of message */ - if (pdu.choice.initiatingMessage->procedureCode >= - sizeof(f1ap_messages_processing) / - (3 * sizeof(f1ap_message_processing_t)) - || (pdu.present > F1AP_F1AP_PDU_PR_unsuccessfulOutcome)) { - LOG_E(F1AP, "[SCTP %d] Either procedureCode %ld or direction %d exceed expected\n", - assoc_id, pdu.choice.initiatingMessage->procedureCode, pdu.present); - ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_F1AP_F1AP_PDU, &pdu); + if (pdu->choice.initiatingMessage->procedureCode >= sizeof(f1ap_messages_processing) / (3 * sizeof(f1ap_message_processing_t)) + || (pdu->present > F1AP_F1AP_PDU_PR_unsuccessfulOutcome)) { + LOG_E(F1AP, + "[SCTP %d] Either procedureCode %ld or direction %d exceed expected\n", + assoc_id, + pdu->choice.initiatingMessage->procedureCode, + pdu->present); + ASN_STRUCT_FREE(asn_DEF_F1AP_F1AP_PDU, pdu); return -1; } - if (f1ap_messages_processing[pdu.choice.initiatingMessage->procedureCode][pdu.present - 1] == NULL) { + int ret; + if (f1ap_messages_processing[pdu->choice.initiatingMessage->procedureCode][pdu->present - 1] == NULL) { // No handler present. This can mean not implemented or no procedure for eNB (wrong direction). - LOG_E(F1AP, "[SCTP %d] No handler for procedureCode %ld in %s\n", - assoc_id, pdu.choice.initiatingMessage->procedureCode, - f1ap_direction2String(pdu.present - 1)); + LOG_E(F1AP, + "[SCTP %d] No handler for procedureCode %ld in %s\n", + assoc_id, + pdu->choice.initiatingMessage->procedureCode, + f1ap_direction2String(pdu->present - 1)); ret=-1; } else { /* Calling the right handler */ LOG_D(F1AP, "Calling handler with instance %ld\n",instance); - ret = (*f1ap_messages_processing[pdu.choice.initiatingMessage->procedureCode][pdu.present - 1]) - (instance, assoc_id, stream, &pdu); + ret = (*f1ap_messages_processing[pdu->choice.initiatingMessage->procedureCode][pdu->present - 1])(instance, + assoc_id, + stream, + pdu); } - ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_F1AP_F1AP_PDU, &pdu); + ASN_STRUCT_FREE(asn_DEF_F1AP_F1AP_PDU, pdu); return ret; }