From 26be61167dec9068e572e08a21ddc96a0f2a7731 Mon Sep 17 00:00:00 2001
From: laurent <laurent Thomas>
Date: Sun, 10 Jul 2022 10:50:57 +0200
Subject: [PATCH] fix a race, add asn1c debug method

---
 CMakeLists.txt                        | 14 +++------
 openair2/COMMON/e1ap_messages_types.h |  8 -----
 openair2/E1AP/e1ap.c                  | 43 +++++----------------------
 openair2/E1AP/e1ap_common.h           |  3 +-
 openair2/F1AP/f1ap_decoder.c          |  3 +-
 openair2/GNB_APP/gnb_app.c            |  6 ++--
 openair2/GNB_APP/gnb_app.h            |  5 ++--
 openair2/GNB_APP/gnb_config.c         |  4 +--
 openair2/RRC/NR/rrc_gNB_NGAP.c        |  4 +--
 9 files changed, 25 insertions(+), 65 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1f88da21fe9..d385130f161 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -277,7 +277,7 @@ if (SANITIZE_UNDEFINED)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -fno-sanitize-recover=all")
 endif ()
 
-add_definitions("-DASN_DISABLE_OER_SUPPORT")
+add_definitions("-DASN_DISABLE_OER_SUPPORT -DHAVE_CONFIG_H -DHAVE_CONFIG_H_")
 
 #########################
 set(CMAKE_EXE_LINKER_FLAGS  "${CMAKE_EXE_LINKER_FLAGS} -ggdb2 -Wl,-rpath -Wl,${CMAKE_CURRENT_BINARY_DIR}")
@@ -334,20 +334,12 @@ add_definitions("-DPACKAGE_BUGREPORT=\"openair4g-devel@lists.eurecom.fr\"")
 
 # Debug related options
 #########################################
-add_boolean_option(ASN_EMIT_DEBUG      True "ASN1 coder/decoder Debug")
-add_boolean_option(ASN_THREAD_SAFE     True "ASN1 coder/decoder Debug")
-add_boolean_option(MSG_PRINT           True "print debug messages")
-add_boolean_option(DISABLE_XER_PRINT   False "print XER Format")
-add_boolean_option(XER_PRINT           False "print XER Format")
-add_boolean_option(DEBUG_PDCP_PAYLOAD  False "print PDCP PDU to stdout")  # if true, make sure that global and PDCP log levels are trace
+add_boolean_option(DEBUG_ASN1      False "ASN1 coder/decoder Debug")
 add_boolean_option(DEBUG_MAC_INTERFACE False "print MAC-RLC PDU exchange to stdout") # if true, make sure that global and PDCP log levels are trace
-add_boolean_option(TRACE_RLC_PAYLOAD   False "print RLC PDU to stdout") # if true, make sure that global and PDCP log levels are trace
-add_boolean_option(PRINT_STATS         False "This adds the possibility to see the status")
 add_boolean_option(T_TRACER            True  "Activate the T tracer, a debugging/monitoring framework" )
 add_boolean_option(UE_AUTOTEST_TRACE   False "Activate UE autotest specific logs")
 add_boolean_option(UE_DEBUG_TRACE      False "Activate UE debug trace")
 add_boolean_option(UE_TIMING_TRACE     False "Activate UE timing trace")
-add_boolean_option(DEBUG_CONSOLE       False "disables stdout/stderr buffering")
 
 set (OCP_ITTI ${OPENAIR_DIR}/common/utils/ocp_itti)
 add_library(ITTI
@@ -355,6 +347,8 @@ add_library(ITTI
   ${OPENAIR_DIR}/common/utils/backtrace.c
   )
 add_dependencies(ITTI rrc_flag)
+add_dependencies(ITTI ASN1_E1AP_LIB)
+
 
 # asn1c skeletons have hardcoded this flag to make customized debug logs
 # OAI uses this feature to re-use OAI LOG_I(ASN, ...)
diff --git a/openair2/COMMON/e1ap_messages_types.h b/openair2/COMMON/e1ap_messages_types.h
index 11fdd0e7bf9..81bd1b484db 100644
--- a/openair2/COMMON/e1ap_messages_types.h
+++ b/openair2/COMMON/e1ap_messages_types.h
@@ -24,9 +24,6 @@
 #ifndef E1AP_MESSAGES_TYPES_H
 #define E1AP_MESSAGES_TYPES_H
 
-#include "E1AP_E1AP-PDU.h"
-#include "E1AP_TransactionID.h"
-#include "E1AP_PriorityLevel.h"
 #include "ngap_messages_types.h"
 
 #define E1AP_MAX_NUM_TRANSAC_IDS 4
@@ -49,11 +46,6 @@
 
 typedef f1ap_net_ip_address_t e1ap_net_ip_address_t;
 
-typedef int (*e1ap_message_processing_t)(
-  instance_t            instance,
-  E1AP_E1AP_PDU_t       *message_p
-);
-
 typedef struct PLMN_ID_s {
   int mcc;
   int mnc;
diff --git a/openair2/E1AP/e1ap.c b/openair2/E1AP/e1ap.c
index 9f1bcea1dfe..6aaead77da7 100644
--- a/openair2/E1AP/e1ap.c
+++ b/openair2/E1AP/e1ap.c
@@ -25,7 +25,10 @@
 #include "e1ap_common.h"
 
 #define E1AP_NUM_MSG_HANDLERS 14
-
+typedef int (*e1ap_message_processing_t)(
+  instance_t            instance,
+  E1AP_E1AP_PDU_t       *message_p
+);
 e1ap_message_processing_t e1ap_message_processing[E1AP_NUM_MSG_HANDLERS][3] = {
 
   { 0, 0, 0 }, /* Reset */
@@ -556,46 +559,16 @@ int e1apCUCP_send_BEARER_CONTEXT_SETUP_REQUEST(instance_t instance,
   ieC5->id                         = E1AP_ProtocolIE_ID_id_ActivityNotificationLevel;
   ieC5->criticality                = E1AP_Criticality_reject;
   ieC5->value.present              = E1AP_BearerContextSetupRequestIEs__value_PR_ActivityNotificationLevel;
-  ieC5->value.choice.ActivityNotificationLevel = 2;// TODO: Remove hard coding
+  ieC5->value.choice.ActivityNotificationLevel = E1AP_ActivityNotificationLevel_pdu_session;// TODO: Remove hard coding
   /* mandatory */
   /*  */
   asn1cSequenceAdd(out->protocolIEs.list, E1AP_BearerContextSetupRequestIEs_t, ieC6);
   ieC6->id = E1AP_ProtocolIE_ID_id_System_BearerContextSetupRequest;
   ieC6->criticality = E1AP_Criticality_reject;
-  if (0) { // EUTRAN
-    ieC6->value.choice.System_BearerContextSetupRequest.present = E1AP_System_BearerContextSetupRequest_PR_e_UTRAN_BearerContextSetupRequest;
-    E1AP_EUTRAN_BearerContextSetupRequest_t *msgEUTRAN = calloc(1, sizeof(E1AP_EUTRAN_BearerContextSetupRequest_t));
-    ieC6->value.choice.System_BearerContextSetupRequest.choice.e_UTRAN_BearerContextSetupRequest = (struct E1AP_ProtocolIE_Container *) msgEUTRAN;
-    msgEUTRAN->id = E1AP_ProtocolIE_ID_id_DRB_To_Setup_List_EUTRAN;
-    msgEUTRAN->value.present = E1AP_EUTRAN_BearerContextSetupRequest__value_PR_DRB_To_Setup_List_EUTRAN;
-    E1AP_DRB_To_Setup_List_EUTRAN_t *drb2Setup = &msgEUTRAN->value.choice.DRB_To_Setup_List_EUTRAN;
-
-    for (drb_to_setup_t *i=bearerCxt->DRBList; i < bearerCxt->DRBList+bearerCxt->numDRBs; i++) {
-      asn1cSequenceAdd(drb2Setup->list, E1AP_DRB_To_Setup_Item_EUTRAN_t, ieC6_1);
-      ieC6_1->dRB_ID = i->drbId;
-
-      ieC6_1->pDCP_Configuration.pDCP_SN_Size_UL = i->pDCP_SN_Size_UL;
-      ieC6_1->pDCP_Configuration.pDCP_SN_Size_DL = i->pDCP_SN_Size_DL;
-      ieC6_1->pDCP_Configuration.rLC_Mode        = i->rLC_Mode;
-
-      ieC6_1->eUTRAN_QoS.qCI = i->qci;
-      ieC6_1->eUTRAN_QoS.eUTRANallocationAndRetentionPriority.priorityLevel = i->qosPriorityLevel;
-      ieC6_1->eUTRAN_QoS.eUTRANallocationAndRetentionPriority.pre_emptionCapability = i->pre_emptionCapability;
-      ieC6_1->eUTRAN_QoS.eUTRANallocationAndRetentionPriority.pre_emptionVulnerability = i->pre_emptionVulnerability;
-
-      ieC6_1->s1_UL_UP_TNL_Information.present = E1AP_UP_TNL_Information_PR_gTPTunnel;
-      asn1cCalloc(ieC6_1->s1_UL_UP_TNL_Information.choice.gTPTunnel, gTPTunnel);
-      TRANSPORT_LAYER_ADDRESS_IPv4_TO_BIT_STRING(i->tlAddress, &gTPTunnel->transportLayerAddress);
-      INT32_TO_OCTET_STRING(i->teId, &gTPTunnel->gTP_TEID);
-
-      for (cell_group_t *j=i->cellGroupList; j < i->cellGroupList+i->numCellGroups; j++) {
-        asn1cSequenceAdd(ieC6_1->cell_Group_Information.list, E1AP_Cell_Group_Information_Item_t, ieC6_1_1);
-        ieC6_1_1->cell_Group_ID = j->id;
-      }
-    }
-  } else {
+  
     /* mandatory */
     /*  */
+    ieC6->value.present = E1AP_System_BearerContextSetupRequest_PR_nG_RAN_BearerContextSetupRequest;
     ieC6->value.choice.System_BearerContextSetupRequest.present = E1AP_System_BearerContextSetupRequest_PR_nG_RAN_BearerContextSetupRequest;
     E1AP_NG_RAN_BearerContextSetupRequest_t *msgNGRAN = calloc(1, sizeof(E1AP_NG_RAN_BearerContextSetupRequest_t));
     ieC6->value.choice.System_BearerContextSetupRequest.choice.nG_RAN_BearerContextSetupRequest = (struct E1AP_ProtocolIE_Container *) msgNGRAN;
@@ -656,7 +629,7 @@ int e1apCUCP_send_BEARER_CONTEXT_SETUP_REQUEST(instance_t instance,
           ieC6_1_1_1->qoSFlowLevelQoSParameters.nGRANallocationRetentionPriority.pre_emptionCapability = k->pre_emptionCapability;
           ieC6_1_1_1->qoSFlowLevelQoSParameters.nGRANallocationRetentionPriority.pre_emptionVulnerability = k->pre_emptionVulnerability;
         }
-      }
+      
     }
   }
 
diff --git a/openair2/E1AP/e1ap_common.h b/openair2/E1AP/e1ap_common.h
index 2a28b542d57..b820c1f3c4e 100644
--- a/openair2/E1AP/e1ap_common.h
+++ b/openair2/E1AP/e1ap_common.h
@@ -23,9 +23,8 @@
 
 #ifndef E1AP_COMMON_H_
 #define E1AP_COMMON_H_
-
+ 
 #include "openair2/COMMON/e1ap_messages_types.h"
-//#define ASN_DEBUG( x... )  LOG_I(ASN, x)
 int e1ap_decode_pdu(E1AP_E1AP_PDU_t *pdu, const uint8_t *const buffer, uint32_t length);
 
 e1ap_upcp_inst_t *getCxtE1(E1_t type, instance_t instance);
diff --git a/openair2/F1AP/f1ap_decoder.c b/openair2/F1AP/f1ap_decoder.c
index 60b3f94310e..47e1f274d3f 100644
--- a/openair2/F1AP/f1ap_decoder.c
+++ b/openair2/F1AP/f1ap_decoder.c
@@ -162,7 +162,8 @@ static int f1ap_decode_unsuccessful_outcome(F1AP_F1AP_PDU_t *pdu) {
 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);
-  dec_ret = aper_decode(NULL,
+  asn_codec_ctx_t st={100*1000};
+  dec_ret = aper_decode(&st,
                         &asn_DEF_F1AP_F1AP_PDU,
                         (void **)&pdu,
                         buffer,
diff --git a/openair2/GNB_APP/gnb_app.c b/openair2/GNB_APP/gnb_app.c
index e65c53f259b..3fe1b262b82 100644
--- a/openair2/GNB_APP/gnb_app.c
+++ b/openair2/GNB_APP/gnb_app.c
@@ -60,7 +60,7 @@ extern RAN_CONTEXT_t RC;
 #define GNB_REGISTER_RETRY_DELAY 10
 
 /*------------------------------------------------------------------------------*/
-static void configure_nr_rrc(uint32_t gnb_id)
+void configure_nr_rrc(uint32_t gnb_id)
 {
   MessageDef *msg_p = NULL;
   //  int CC_id;
@@ -81,7 +81,7 @@ static void configure_nr_rrc(uint32_t gnb_id)
 /*------------------------------------------------------------------------------*/
 
 
-static uint32_t gNB_app_register(uint32_t gnb_id_start, uint32_t gnb_id_end)//, const Enb_properties_array_t *enb_properties)
+uint32_t gNB_app_register(uint32_t gnb_id_start, uint32_t gnb_id_end)//, const Enb_properties_array_t *enb_properties)
 {
   uint32_t         gnb_id;
   MessageDef      *msg_p;
@@ -116,7 +116,7 @@ static uint32_t gNB_app_register(uint32_t gnb_id_start, uint32_t gnb_id_end)//,
 
 
 /*------------------------------------------------------------------------------*/
-static uint32_t gNB_app_register_x2(uint32_t gnb_id_start, uint32_t gnb_id_end) {
+uint32_t gNB_app_register_x2(uint32_t gnb_id_start, uint32_t gnb_id_end) {
   uint32_t         gnb_id;
   MessageDef      *msg_p;
   uint32_t         register_gnb_x2_pending = 0;
diff --git a/openair2/GNB_APP/gnb_app.h b/openair2/GNB_APP/gnb_app.h
index b0b422aae1b..44c4374fc3b 100644
--- a/openair2/GNB_APP/gnb_app.h
+++ b/openair2/GNB_APP/gnb_app.h
@@ -33,6 +33,7 @@
 #include <stdint.h>
 
 void *gNB_app_task(void *args_p);
-
-
+void configure_nr_rrc(uint32_t gnb_id);
+uint32_t gNB_app_register(uint32_t gnb_id_start, uint32_t gnb_id_end);
+uint32_t gNB_app_register_x2(uint32_t gnb_id_start, uint32_t gnb_id_end);
 #endif /* GNB_APP_H_ */
diff --git a/openair2/GNB_APP/gnb_config.c b/openair2/GNB_APP/gnb_config.c
index d779ff3827c..4187e618af2 100644
--- a/openair2/GNB_APP/gnb_config.c
+++ b/openair2/GNB_APP/gnb_config.c
@@ -2013,8 +2013,8 @@ int RCconfig_NR_DU_F1(MessageDef *msg_p, uint32_t i) {
         f1Setup->mib_length[k]                                 = rrc->carrier.sizeof_MIB;
 
         NR_BCCH_DL_SCH_Message_t *bcch_message = NULL;
-
-        asn_dec_rval_t dec_rval = uper_decode_complete( NULL,
+        asn_codec_ctx_t st={100*1000};
+        asn_dec_rval_t dec_rval = uper_decode_complete( &st,
             &asn_DEF_NR_BCCH_DL_SCH_Message,
             (void **)&bcch_message,
             (const void *)rrc->carrier.SIB1,
diff --git a/openair2/RRC/NR/rrc_gNB_NGAP.c b/openair2/RRC/NR/rrc_gNB_NGAP.c
index c905b59d82a..14170c4a403 100644
--- a/openair2/RRC/NR/rrc_gNB_NGAP.c
+++ b/openair2/RRC/NR/rrc_gNB_NGAP.c
@@ -1006,8 +1006,8 @@ rrc_gNB_process_NGAP_PDUSESSION_SETUP_REQ(
       pdu->sessionId   = msg->pdusession_setup_params[i].pdusession_id;
       pdu->sessionType = msg->pdusession_setup_params[i].upf_addr.pdu_session_type;
       pdu->sst         = msg->allowed_nssai[i].sST;
-      pdu->integrityProtectionIndication       = 1; // Preferred. TODO: Remove hardcoding
-      pdu->confidentialityProtectionIndication = 1; // Preferred. TODO: Remove hardcoding
+      pdu->integrityProtectionIndication       = 2; //E1AP_IntegrityProtectionIndication_not_needed; // Preferred. TODO: Remove hardcoding
+      pdu->confidentialityProtectionIndication = 2; //E1AP_ConfidentialityProtectionIndication_not_needed; // Preferred. TODO: Remove hardcoding
       pdu->teId                                = msg->pdusession_setup_params[i].gtp_teid;
       memcpy(&pdu->tlAddress,
              msg->pdusession_setup_params[i].upf_addr.buffer,
-- 
GitLab