From a458a251a029340f1b8a167fed28a4e1e7202df7 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Mon, 6 Mar 2023 10:59:35 +0100 Subject: [PATCH 1/7] PDCP: harmonize DL RRC Message transfer --- openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c | 41 ++++++++--------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c index e4bb7bb4f5..702aabd528 100644 --- a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c @@ -772,33 +772,20 @@ srb_found: LOG_D(PDCP, "%s(): (srb %d) calling rlc_data_req size %d\n", __func__, srb_id, size); //for (i = 0; i < size; i++) printf(" %2.2x", (unsigned char)memblock->data[i]); //printf("\n"); - if ((RC.nrrrc == NULL) || (!NODE_IS_CU(node_type))) { - if (entity->is_gnb) { - f1ap_dl_rrc_message_t dl_rrc = {.old_gNB_DU_ue_id = 0xFFFFFF, .rrc_container = (uint8_t *)buf, .rrc_container_length = size, .rnti = ue->rntiMaybeUEid, .srb_id = DCCH}; - gNB_RRC_INST *rrc = RC.nrrrc[0]; - rrc->mac_rrc.dl_rrc_message_transfer(0, &dl_rrc); - } else { // UE - mem_block_t *memblock; - protocol_ctxt_t ctxt = {.module_id = 0, .enb_flag = 1, .instance = 0, .frame = 0, .subframe = 0, .eNB_index = 0, .brOption = 0, .rntiMaybeUEid = ue->rntiMaybeUEid}; - memblock = get_free_mem_block(size, __FUNCTION__); - memcpy(memblock->data, buf, size); - enqueue_rlc_data_req(&ctxt, 1, MBMS_FLAG_NO, srb_id, sdu_id, 0, size, memblock); - } - } else { - MessageDef *message_p = itti_alloc_new_message (TASK_RRC_GNB, 0, F1AP_DL_RRC_MESSAGE); - uint8_t *message_buffer = itti_malloc (TASK_RRC_GNB, TASK_CU_F1, size); - memcpy (message_buffer, buf, size); - F1AP_DL_RRC_MESSAGE (message_p).rrc_container = message_buffer; - F1AP_DL_RRC_MESSAGE (message_p).rrc_container_length = size; - F1AP_DL_RRC_MESSAGE (message_p).gNB_CU_ue_id = 0; - F1AP_DL_RRC_MESSAGE (message_p).gNB_DU_ue_id = 0; - F1AP_DL_RRC_MESSAGE (message_p).old_gNB_DU_ue_id = 0xFFFFFFFF; // unknown - F1AP_DL_RRC_MESSAGE(message_p).rnti = ue->rntiMaybeUEid; - F1AP_DL_RRC_MESSAGE (message_p).srb_id = srb_id; - F1AP_DL_RRC_MESSAGE (message_p).execute_duplication = 1; - F1AP_DL_RRC_MESSAGE (message_p).RAT_frequency_priority_information.en_dc = 0; - itti_send_msg_to_task (TASK_CU_F1, 0, message_p); - LOG_D(PDCP, "Send F1AP_DL_RRC_MESSAGE with ITTI\n"); + if (entity->is_gnb) { + f1ap_dl_rrc_message_t dl_rrc = {.old_gNB_DU_ue_id = 0xFFFFFF, + .rrc_container = (uint8_t *)buf, + .rrc_container_length = size, + .rnti = ue->rntiMaybeUEid, + .srb_id = srb_id}; + gNB_RRC_INST *rrc = RC.nrrrc[0]; + rrc->mac_rrc.dl_rrc_message_transfer(0, &dl_rrc); + } else { // UE + mem_block_t *memblock; + protocol_ctxt_t ctxt = {.module_id = 0, .enb_flag = 1, .instance = 0, .frame = 0, .subframe = 0, .eNB_index = 0, .brOption = 0, .rntiMaybeUEid = ue->rntiMaybeUEid}; + memblock = get_free_mem_block(size, __FUNCTION__); + memcpy(memblock->data, buf, size); + enqueue_rlc_data_req(&ctxt, 1, MBMS_FLAG_NO, srb_id, sdu_id, 0, size, memblock); } } From 2ac2a7f0745f59dafe695dd215a9fa3939168f4e Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Sat, 18 Mar 2023 16:50:32 +0100 Subject: [PATCH 2/7] Make separate header for nr_pdcp instead of using 4G pdcp Creates function that have nr_pdcp_ prepended to their name, and change the signature of some functions for the 5G PDCP: - nr_pdcp_layer_init() - nr_pdcp_data_req() - nr_pdcp_remove_UE() - nr_pdcp_config_set_security() - nr_pdcp_remove_UE() - Make separate functions for nr_pdcp_data_req_srb/drb() --- doc/Doxyfile | 1 + doc/SW_archi.md | 19 +-- executables/lte-softmodem.c | 15 +++ executables/nr-cuup.c | 4 +- executables/nr-softmodem.c | 11 +- executables/nr-ue.c | 6 +- executables/nr-uesoftmodem.c | 4 +- openair2/F1AP/f1ap_cu_rrc_message_transfer.c | 2 +- openair2/F1AP/f1ap_cu_ue_context_management.c | 4 +- openair2/GNB_APP/gnb_app.c | 2 +- openair2/GNB_APP/gnb_config.c | 4 +- openair2/LAYER2/MAC/eNB_scheduler.c | 2 +- openair2/LAYER2/NR_MAC_UE/main_ue_nr.c | 4 +- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c | 5 +- .../LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c | 2 - openair2/LAYER2/NR_MAC_gNB/main.c | 5 +- openair2/LAYER2/PDCP_v10.1.0/pdcp.h | 2 - openair2/LAYER2/nr_pdcp/asn1_utils.c | 2 +- openair2/LAYER2/nr_pdcp/nr_pdcp_e1_api.h | 2 +- openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c | 127 +++++++++--------- openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h | 103 ++++++++++++++ openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c | 2 +- openair2/LAYER2/openair2_proc.c | 2 +- openair2/RRC/NR/L2_nr_interface.c | 4 +- openair2/RRC/NR/nr_rrc_common.c | 1 - openair2/RRC/NR/rrc_gNB.c | 32 ++--- openair2/RRC/NR/rrc_gNB_NGAP.c | 13 +- openair2/RRC/NR/rrc_gNB_nsa.c | 4 +- openair2/RRC/NR_UE/rrc_UE.c | 20 +-- openair2/SDAP/nr_sdap/nr_sdap_entity.c | 44 +++--- openair3/ocp-gtpu/gtp_itf.cpp | 3 +- 31 files changed, 269 insertions(+), 182 deletions(-) create mode 100644 openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h diff --git a/doc/Doxyfile b/doc/Doxyfile index 6a4dd850a3..afb89b43ef 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -1340,6 +1340,7 @@ INPUT = \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/NR_MAC_UE/mac_extern.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c \ +@CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/nr_pdcp/nr_pdcp_entity.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/nr_pdcp/nr_pdcp_timer_thread.h \ @CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/nr_pdcp/nr_pdcp_integrity_nia2.h \ diff --git a/doc/SW_archi.md b/doc/SW_archi.md index 7f16edab11..1e8e5cd011 100644 --- a/doc/SW_archi.md +++ b/doc/SW_archi.md @@ -327,25 +327,26 @@ successful_delivery() and max_retx_reached(): in ??? trigger, the RLC sends a it The PDCP implementation is also protected through a general mutex. The design is very similar to rlc layer. The pdcp data is isolated and encapsulated. -pdcp_layer_init(): same as rlc init +nr_pdcp_layer_init(): same as rlc init we have to call a second init function: pdcp_module_init() -At Tx side (DL in gNB), pdcp_data_req() is the entry function that the upper layer calls. +At Tx side (DL in gNB), `pdcp_data_req_drb()` and `pdcp_data_req_srb()` are the entry functions that the upper layer calls. The upper layer can be GTP or a PDCP internal thread enb_tun_read_thread() that read directly from Linux socket in case we skip 3GPP core implementation. -PDCP internals for pdcp_data_req() is thread safe: inside pdcp_data_req_drb(), the pdcp manager protects with the mutex the access to the SDU receiving function of PDCP (recv_sdu() callback, corresponding to nr_pdcp_entity_drb_am_recv_sdu() for DRBs). When it needs, the pdcp layer push this data to rlc by calling : rlc_data_req() +PDCP internals for nr_pdcp_data_req_srb()/nr_pdcp_data_req_drb() are thread safe: inside them, the pdcp manager protects with the mutex the access to the SDU receiving function of PDCP (recv_sdu() callback, corresponding to nr_pdcp_entity_drb_am_recv_sdu() for DRBs). When it needs, the pdcp layer push this data to rlc by calling : rlc_data_req() -Also, incoming downlink sdu can comme from internal RRC: in this case, pdcp_run() reads a itti queue, for message RRC_DCCH_DATA_REQ, to0 only call 'pdcp_data_req()' +Also, incoming downlink sdu can comme from internal RRC: in this case, nr +nr_pdcp_run() reads a itti queue, for message RRC_DCCH_DATA_REQ, to0 only call 'nr_pdcp_data_req_srb()' At Rx side, pdcp_data_ind() is the entry point that receives the data from RLC. - Inside pdcp_data_ind(), the pdcp manager mutex protects the access to the PDU receiving function of PDCP (recv_pdu() callback corresponding to nr_pdcp_entity_drb_am_recv_pdu() for DRBs) - Then deliver_sdu_drb() function sends the received data to GTP thread through an ITTI message (GTPV1U_TUNNEL_DATA_REQ). -pdcp_config_set_security(): not yet developped +nr_pdcp_config_set_security(): sets the keys for AS security of a UE -nr_DRB_preconfiguration(): the mac layer calls this for ??? +nr_DRB_preconfiguration(): the mac layer calls this for configuration in phy-test/do-ra mode -nr_pdcp_add_srbs() adds UE SRBs in pdcp, pdcp_remove_UE() removes it -nr_pdcp_add_drbs() adds UE DRBs in pdcp, pdcp_remove_UE() removes it +nr_pdcp_add_srbs() adds UE SRBs in pdcp, nr_pdcp_remove_UE() removes it +nr_pdcp_add_drbs() adds UE DRBs in pdcp, nr_pdcp_remove_UE() removes it # GTP Gtp + UDP are two twin threads performing the data plane interface to the core network @@ -357,7 +358,7 @@ PDCP layer push to the GTP queue (outside UDP thread that do almost nothing and ## GTP thread running code from other layers -gtp thread calls directly pdcp_data_req(), so it runs inside it's context internal pdcp structures updates +gtp thread calls directly nr_pdcp_data_req_drb(), so it runs inside it's context internal pdcp structures updates ## inside other threads gtpv1u_create_s1u_tunnel(), delete tunnel, ... functions are called inside the other threads, without mutex. diff --git a/executables/lte-softmodem.c b/executables/lte-softmodem.c index 6d75f0acbd..0c04456e27 100644 --- a/executables/lte-softmodem.c +++ b/executables/lte-softmodem.c @@ -181,6 +181,21 @@ bool sdap_data_req(protocol_ctxt_t *ctxt_p, abort(); } +/* hack: gtp_itf.cpp requires this empty function to be defined here */ +bool nr_pdcp_data_req_drb(protocol_ctxt_t *ctxt_pP, + const srb_flag_t srb_flagP, + const rb_id_t rb_id, + const mui_t muiP, + const confirm_t confirmP, + const sdu_size_t sdu_buffer_size, + unsigned char *const sdu_buffer, + const pdcp_transmission_mode_t mode, + const uint32_t *const sourceL2Id, + const uint32_t *const destinationL2Id) +{ + abort(); +} + /* forward declarations */ void set_default_frame_parms(LTE_DL_FRAME_PARMS *frame_parms[MAX_NUM_CCs]); diff --git a/executables/nr-cuup.c b/executables/nr-cuup.c index 25ebe6df13..34eae85810 100644 --- a/executables/nr-cuup.c +++ b/executables/nr-cuup.c @@ -28,7 +28,7 @@ #include "nfapi/oai_integration/vendor_ext.h" #include "openair2/F1AP/f1ap_common.h" #include "openair2/GNB_APP/gnb_config.h" -#include "pdcp.h" +#include "nr_pdcp/nr_pdcp_oai_api.h" RAN_CONTEXT_t RC; THREAD_STRUCT thread_struct; @@ -147,7 +147,7 @@ int main(int argc, char **argv) AssertFatal(rc >= 0, "Create task for GTPV1U failed\n"); rc = itti_create_task(TASK_CUUP_E1, E1AP_CUUP_task, NULL); AssertFatal(rc >= 0, "Create task for CUUP E1 failed\n"); - pdcp_layer_init(); + nr_pdcp_layer_init(); MessageDef *msg = RCconfig_NR_CU_E1(true); AssertFatal(msg != NULL, "Send init to task for E1AP UP failed\n"); itti_send_msg_to_task(TASK_CUUP_E1, 0, msg); diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c index 120a7c0e65..455bf83904 100644 --- a/executables/nr-softmodem.c +++ b/executables/nr-softmodem.c @@ -59,7 +59,7 @@ unsigned short config_frames[4] = {2,9,11,13}; #include "common/utils/LOG/log.h" #include "common/utils/LOG/vcd_signal_dumper.h" #include "UTIL/OPT/opt.h" -#include "pdcp.h" +#include "LAYER2/nr_pdcp/nr_pdcp_oai_api.h" #include "intertask_interface.h" @@ -556,13 +556,8 @@ void init_pdcp(void) { PDCP_USE_NETLINK_BIT | LINK_ENB_PDCP_TO_IP_DRIVER_BIT | ENB_NAS_USE_TUN_BIT | SOFTMODEM_NOKRNMOD_BIT: LINK_ENB_PDCP_TO_GTPV1U_BIT; - if (!get_softmodem_params()->nsa) { - if (!NODE_IS_DU(get_node_type())) { - pdcp_layer_init(); - nr_pdcp_module_init(pdcp_initmask, 0); - } - } else { - pdcp_layer_init(); + if (!NODE_IS_DU(get_node_type())) { + nr_pdcp_layer_init(); nr_pdcp_module_init(pdcp_initmask, 0); } } diff --git a/executables/nr-ue.c b/executables/nr-ue.c index 075789e12b..a1ec29a42a 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -33,7 +33,7 @@ #include "executables/softmodem-common.h" #include "PHY/NR_REFSIG/refsig_defs_ue.h" #include "radio/COMMON/common_lib.h" -#include "pdcp.h" +#include "LAYER2/nr_pdcp/nr_pdcp_oai_api.h" /* * NR SLOT PROCESSING SEQUENCE @@ -359,7 +359,7 @@ static void *NRUE_phy_stub_standalone_pnf_task(void *arg) NR_UE_MAC_INST_t *mac = get_mac_inst(0); protocol_ctxt_t ctxt; PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, ENB_FLAG_NO, mac->crnti, frame, slot, 0); - pdcp_run(&ctxt); + nr_pdcp_run(&ctxt); } process_queued_nr_nfapi_msgs(mac, sfn_slot); } @@ -627,7 +627,7 @@ void UE_processing(nr_rxtx_thread_data_t *rxtxD) { NR_UE_MAC_INST_t *mac = get_mac_inst(0); protocol_ctxt_t ctxt; PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, UE->Mod_id, ENB_FLAG_NO, mac->crnti, proc->frame_rx, proc->nr_slot_rx, 0); - pdcp_run(&ctxt); + nr_pdcp_run(&ctxt); } } diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c index eb6e160ec3..7169881ed0 100644 --- a/executables/nr-uesoftmodem.c +++ b/executables/nr-uesoftmodem.c @@ -59,7 +59,7 @@ unsigned short config_frames[4] = {2,9,11,13}; #include "UTIL/OPT/opt.h" #include "enb_config.h" -#include "pdcp.h" +#include "LAYER2/nr_pdcp/nr_pdcp_oai_api.h" #include "intertask_interface.h" @@ -386,7 +386,7 @@ static void init_pdcp(int ue_id) { if (get_softmodem_params()->nsa && rlc_module_init(0) != 0) { LOG_I(RLC, "Problem at RLC initiation \n"); } - pdcp_layer_init(); + nr_pdcp_layer_init(); nr_pdcp_module_init(pdcp_initmask, ue_id); pdcp_set_rlc_data_req_func((send_rlc_data_req_func_t) rlc_data_req); pdcp_set_pdcp_data_ind_func((pdcp_data_ind_func_t) pdcp_data_ind); diff --git a/openair2/F1AP/f1ap_cu_rrc_message_transfer.c b/openair2/F1AP/f1ap_cu_rrc_message_transfer.c index f1e0a7ade1..7fc30967de 100644 --- a/openair2/F1AP/f1ap_cu_rrc_message_transfer.c +++ b/openair2/F1AP/f1ap_cu_rrc_message_transfer.c @@ -37,7 +37,7 @@ #include "f1ap_cu_rrc_message_transfer.h" #include "common/ran_context.h" #include "openair3/UTILS/conversions.h" -#include "pdcp.h" +#include "LAYER2/nr_pdcp/nr_pdcp_oai_api.h" /* Initial UL RRC Message Transfer diff --git a/openair2/F1AP/f1ap_cu_ue_context_management.c b/openair2/F1AP/f1ap_cu_ue_context_management.c index 0cb476b2d7..bfa48a4f88 100644 --- a/openair2/F1AP/f1ap_cu_ue_context_management.c +++ b/openair2/F1AP/f1ap_cu_ue_context_management.c @@ -40,7 +40,7 @@ #include "rrc_extern.h" #include "openair2/RRC/NR/rrc_gNB_NGAP.h" #include -#include "pdcp.h" +#include "LAYER2/nr_pdcp/nr_pdcp_oai_api.h" static void setQos(F1AP_NonDynamic5QIDescriptor_t *toFill) { asn1cCalloc(toFill, tmp); @@ -958,7 +958,7 @@ int CU_handle_UE_CONTEXT_RELEASE_COMPLETE(instance_t instance, LOG_E(F1AP, "could not find ue_context of UE RNTI %x\n", rnti); } - pdcp_remove_UE(&ctxt); + nr_pdcp_remove_UE(ctxt.rntiMaybeUEid); LOG_I(F1AP, "Received UE CONTEXT RELEASE COMPLETE: Removing CU UE entry for RNTI %x\n", rnti); f1ap_remove_ue(CUtype, instance, rnti); diff --git a/openair2/GNB_APP/gnb_app.c b/openair2/GNB_APP/gnb_app.c index 6404b26418..84cbf0d424 100644 --- a/openair2/GNB_APP/gnb_app.c +++ b/openair2/GNB_APP/gnb_app.c @@ -49,7 +49,7 @@ #include "f1ap_du_task.h" #include "nfapi/oai_integration/vendor_ext.h" #include -#include "openair2/LAYER2/PDCP_v10.1.0/pdcp.h" +#include "openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h" #include "openair2/E1AP/e1ap.h" #include "gnb_config.h" extern unsigned char NB_gNB_INST; diff --git a/openair2/GNB_APP/gnb_config.c b/openair2/GNB_APP/gnb_config.c index 46044ca6df..97eae39842 100644 --- a/openair2/GNB_APP/gnb_config.c +++ b/openair2/GNB_APP/gnb_config.c @@ -54,7 +54,7 @@ #include "radio/ETHERNET/USERSPACE/LIB/ethernet_lib.h" #include "nfapi_vnf.h" #include "nfapi_pnf.h" -#include "pdcp.h" +#include "nr_pdcp/nr_pdcp_oai_api.h" //#include "L1_paramdef.h" #include "prs_nr_paramdef.h" @@ -2244,6 +2244,6 @@ void nr_read_config_and_init(void) { } if (NODE_IS_CU(RC.nrrrc[0]->node_type) && RC.nrrrc[0]->node_type != ngran_gNB_CUCP) { - pdcp_layer_init(); + nr_pdcp_layer_init(); } } diff --git a/openair2/LAYER2/MAC/eNB_scheduler.c b/openair2/LAYER2/MAC/eNB_scheduler.c index badcd36cc6..e56b3d4f6f 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler.c +++ b/openair2/LAYER2/MAC/eNB_scheduler.c @@ -958,7 +958,7 @@ eNB_dlsch_ulsch_scheduler(module_id_t module_idP, void rlc_tick(int, int); PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, subframeP, module_idP); rlc_tick(frameP, subframeP); - pdcp_run(&ctxt); + //pdcp_run(&ctxt); pdcp_mbms_run(&ctxt); rrc_rx_tx(&ctxt, CC_id); #endif diff --git a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c index 7fb2295f2d..2babe56ec8 100644 --- a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c +++ b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c @@ -38,7 +38,7 @@ #include "openair2/LAYER2/nr_pdcp/nr_pdcp_entity.h" #include "executables/softmodem-common.h" #include "openair2/LAYER2/nr_pdcp/nr_pdcp.h" -#include "openair2/LAYER2/PDCP_v10.1.0/pdcp.h" +#include "openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h" #include static NR_UE_MAC_INST_t *nr_ue_mac_inst; @@ -65,7 +65,7 @@ NR_UE_MAC_INST_t * nr_l2_init_ue(NR_UE_RRC_INST_t* rrc_inst) { nr_rrc_mac_config_req_ue(0,0,0,NULL,NULL,NULL,rrc_inst->scell_group_config); AssertFatal(rlc_module_init(0) == 0, "%s: Could not initialize RLC layer\n", __FUNCTION__); if (IS_SOFTMODEM_NOS1){ - pdcp_layer_init(); + nr_pdcp_layer_init(); nr_DRB_preconfiguration(nr_ue_mac_inst->crnti); nr_ue_mac_inst->logicalChannelBearer_exist[0] = true; } diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c index c641bf4d15..4a5b4cc626 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c @@ -42,8 +42,7 @@ #include "RRC/NR/nr_rrc_extern.h" -//#include "LAYER2/MAC/pre_processor.c" -#include "pdcp.h" +#include "nr_pdcp/nr_pdcp_oai_api.h" #include "intertask_interface.h" @@ -137,7 +136,7 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP, start_meas(&gNB->eNB_scheduler); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_DLSCH_ULSCH_SCHEDULER,VCD_FUNCTION_IN); - pdcp_run(&ctxt); + nr_pdcp_run(&ctxt); /* send tick to RLC and RRC every ms */ if ((slot & ((1 << *scc->ssbSubcarrierSpacing) - 1)) == 0) { void nr_rlc_tick(int frame, int subframe); diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c index 3224223631..121ad179cc 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c @@ -42,8 +42,6 @@ #include "common/utils/nr/nr_common.h" -#include "pdcp.h" - #define ENABLE_MAC_PAYLOAD_DEBUG #define DEBUG_eNB_SCHEDULER 1 diff --git a/openair2/LAYER2/NR_MAC_gNB/main.c b/openair2/LAYER2/NR_MAC_gNB/main.c index f78e7f224f..5dcaffce94 100644 --- a/openair2/LAYER2/NR_MAC_gNB/main.c +++ b/openair2/LAYER2/NR_MAC_gNB/main.c @@ -33,9 +33,8 @@ #include "NR_MAC_gNB/mac_proto.h" #include "NR_MAC_COMMON/nr_mac_extern.h" #include "assertions.h" -#include "pdcp.h" +#include "nr_pdcp/nr_pdcp_oai_api.h" -#include "LAYER2/nr_pdcp/nr_pdcp_entity.h" #include "RRC/NR/nr_rrc_defs.h" #include "common/utils/LOG/log.h" //#include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h" @@ -250,7 +249,7 @@ void mac_top_init_gNB(ngran_node_t node_type) AssertFatal(rlc_module_init(1) == 0,"Could not initialize RLC layer\n"); // These should be out of here later - if (get_softmodem_params()->usim_test == 0 ) pdcp_layer_init(); + if (get_softmodem_params()->usim_test == 0 ) nr_pdcp_layer_init(); if(IS_SOFTMODEM_NOS1 && get_softmodem_params()->phy_test) nr_DRB_preconfiguration(0x1234); diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h index b4303d1fdd..043ac7fb4a 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h @@ -402,9 +402,7 @@ void pdcp_mbms_run ( void pdcp_run ( const protocol_ctxt_t *const ctxt_pP); uint64_t pdcp_module_init (uint64_t pdcp_optmask, int ue_id); -uint64_t nr_pdcp_module_init(uint64_t _pdcp_optmask, int id); void pdcp_module_cleanup (void); -void nr_ip_over_LTE_DRB_preconfiguration (void); void pdcp_layer_init (void); void pdcp_layer_cleanup (void); #define PDCP2NW_DRIVER_FIFO 21 diff --git a/openair2/LAYER2/nr_pdcp/asn1_utils.c b/openair2/LAYER2/nr_pdcp/asn1_utils.c index 264a2815bb..ab0cdf48fd 100644 --- a/openair2/LAYER2/nr_pdcp/asn1_utils.c +++ b/openair2/LAYER2/nr_pdcp/asn1_utils.c @@ -19,7 +19,7 @@ * contact@openairinterface.org */ -#include "pdcp.h" +#include "common/utils/LOG/log.h" int decode_t_reordering(int v) { diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_e1_api.h b/openair2/LAYER2/nr_pdcp/nr_pdcp_e1_api.h index 68b146efeb..f45f3f0458 100644 --- a/openair2/LAYER2/nr_pdcp/nr_pdcp_e1_api.h +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_e1_api.h @@ -25,7 +25,7 @@ #include "common/utils/oai_asn1.h" #include "NR_RadioBearerConfig.h" -#include "pdcp.h" +#include "nr_pdcp_oai_api.h" #include "LAYER2/nr_rlc/nr_rlc_oai_api.h" #include #include "openair2/SDAP/nr_sdap/nr_sdap.h" diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c index 702aabd528..3b198ff17c 100644 --- a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c @@ -34,7 +34,7 @@ /* from OAI */ #include "oai_asn1.h" -#include "pdcp.h" +#include "nr_pdcp_oai_api.h" #include "LAYER2/nr_rlc/nr_rlc_oai_api.h" #include #include "openair2/SDAP/nr_sdap/nr_sdap.h" @@ -73,7 +73,7 @@ static ngran_node_t node_type; /* NR PDCP and RLC both use "big locks". In some cases a thread may do * lock(rlc) followed by lock(pdcp) (typically when running 'rx_sdu'). * Another thread may first do lock(pdcp) and then lock(rlc) (typically - * the GTP module calls 'pdcp_data_req' that, in a previous implementation + * the GTP module calls 'nr_pdcp_data_req' that, in a previous implementation * was indirectly calling 'rlc_data_req' which does lock(rlc)). * To avoid the resulting deadlock it is enough to ensure that a call * to lock(pdcp) will never be followed by a call to lock(rlc). So, @@ -531,7 +531,13 @@ static void set_node_type() { node_type = get_node_type(); } +/* hack: dummy function needed due to LTE dependencies */ void pdcp_layer_init(void) +{ + abort(); +} + +void nr_pdcp_layer_init(void) { /* hack: be sure to initialize only once */ static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; @@ -789,7 +795,7 @@ srb_found: } } -void pdcp_run(const protocol_ctxt_t *const ctxt_pP) +void nr_pdcp_run(const protocol_ctxt_t *const ctxt_pP) { MessageDef *msg_p; int result; @@ -811,15 +817,11 @@ void pdcp_run(const protocol_ctxt_t *const ctxt_pP) RRC_DCCH_DATA_REQ(msg_p).frame, 0, RRC_DCCH_DATA_REQ(msg_p).eNB_index); - result = pdcp_data_req(&ctxt, - SRB_FLAG_YES, - RRC_DCCH_DATA_REQ(msg_p).rb_id, - RRC_DCCH_DATA_REQ(msg_p).muip, - RRC_DCCH_DATA_REQ(msg_p).confirmp, - RRC_DCCH_DATA_REQ(msg_p).sdu_size, - RRC_DCCH_DATA_REQ(msg_p).sdu_p, - RRC_DCCH_DATA_REQ(msg_p).mode, - NULL, NULL); + result = nr_pdcp_data_req_srb(ctxt.rntiMaybeUEid, + RRC_DCCH_DATA_REQ(msg_p).rb_id, + RRC_DCCH_DATA_REQ(msg_p).muip, + RRC_DCCH_DATA_REQ(msg_p).sdu_size, + RRC_DCCH_DATA_REQ(msg_p).sdu_p); if (result != true) LOG_E(PDCP, "PDCP data request failed!\n"); @@ -1118,30 +1120,43 @@ uint64_t get_pdcp_optmask(void) return pdcp_optmask; } +/* hack: dummy function needed due to LTE dependencies */ bool pdcp_remove_UE(const protocol_ctxt_t *const ctxt_pP) { - ue_id_t rntiMaybeUEid = ctxt_pP->rntiMaybeUEid; + abort(); +} +bool nr_pdcp_remove_UE(ue_id_t ue_id) +{ nr_pdcp_manager_lock(nr_pdcp_ue_manager); - nr_pdcp_manager_remove_ue(nr_pdcp_ue_manager, rntiMaybeUEid); + nr_pdcp_manager_remove_ue(nr_pdcp_ue_manager, ue_id); nr_pdcp_manager_unlock(nr_pdcp_ue_manager); return 1; } -void pdcp_config_set_security( - const protocol_ctxt_t* const ctxt_pP, - pdcp_t *const pdcp_pP, - const rb_id_t rb_id, - const uint16_t lc_idP, - const uint8_t security_modeP, - uint8_t *const kRRCenc_pP, - uint8_t *const kRRCint_pP, - uint8_t *const kUPenc_pP) +/* hack: dummy function needed due to LTE dependencies */ +void pdcp_config_set_security(const protocol_ctxt_t *const ctxt_pP, + pdcp_t *const pdcp_pP, + const rb_id_t rb_id, + const uint16_t lc_idP, + const uint8_t security_modeP, + uint8_t *const kRRCenc_pP, + uint8_t *const kRRCint_pP, + uint8_t *const kUPenc_pP) +{ + abort(); +} + +void nr_pdcp_config_set_security(ue_id_t ue_id, + const rb_id_t rb_id, + const uint8_t security_modeP, + uint8_t *const kRRCenc_pP, + uint8_t *const kRRCint_pP, + uint8_t *const kUPenc_pP) { nr_pdcp_ue_t *ue; nr_pdcp_entity_t *rb; - ue_id_t ue_id = ctxt_pP->rntiMaybeUEid; int integrity_algorithm; int ciphering_algorithm; @@ -1173,27 +1188,15 @@ void pdcp_config_set_security( nr_pdcp_manager_unlock(nr_pdcp_ue_manager); } -static bool pdcp_data_req_srb(protocol_ctxt_t *ctxt_pP, - const rb_id_t rb_id, - const mui_t muiP, - const confirm_t confirmP, - const sdu_size_t sdu_buffer_size, - unsigned char *const sdu_buffer) +bool nr_pdcp_data_req_srb(ue_id_t ue_id, + const rb_id_t rb_id, + const mui_t muiP, + const sdu_size_t sdu_buffer_size, + unsigned char *const sdu_buffer) { LOG_D(PDCP, "%s() called, size %d\n", __func__, sdu_buffer_size); nr_pdcp_ue_t *ue; nr_pdcp_entity_t *rb; - ue_id_t ue_id = ctxt_pP->rntiMaybeUEid; - - if (ctxt_pP->module_id != 0 || - //ctxt_pP->enb_flag != 1 || - ctxt_pP->instance != 0 || - ctxt_pP->eNB_index != 0 /*|| - ctxt_pP->configured != 1 || - ctxt_pP->brOption != 0*/) { - LOG_E(PDCP, "%s:%d:%s: fatal\n", __FILE__, __LINE__, __FUNCTION__); - exit(1); - } nr_pdcp_manager_lock(nr_pdcp_ue_manager); @@ -1217,14 +1220,19 @@ static bool pdcp_data_req_srb(protocol_ctxt_t *ctxt_pP, return 1; } - -static bool pdcp_data_req_drb(protocol_ctxt_t *ctxt_pP, - const rb_id_t rb_id, - const mui_t muiP, - const confirm_t confirmP, - const sdu_size_t sdu_buffer_size, - unsigned char *const sdu_buffer) +bool nr_pdcp_data_req_drb(protocol_ctxt_t *ctxt_pP, + const srb_flag_t srb_flagP, + const rb_id_t rb_id, + const mui_t muiP, + const confirm_t confirmP, + const sdu_size_t sdu_buffer_size, + unsigned char *const sdu_buffer, + const pdcp_transmission_mode_t mode, + const uint32_t *const sourceL2Id, + const uint32_t *const destinationL2Id) { + DevAssert(srb_flagP == SRB_FLAG_NO); + LOG_D(PDCP, "%s() called, size %d\n", __func__, sdu_buffer_size); nr_pdcp_ue_t *ue; nr_pdcp_entity_t *rb; @@ -1288,23 +1296,20 @@ bool cu_f1u_data_req(protocol_ctxt_t *ctxt_pP, return ret; } +/* hack: dummy function needed due to LTE dependencies */ bool pdcp_data_req(protocol_ctxt_t *ctxt_pP, - const srb_flag_t srb_flagP, - const rb_id_t rb_id, - const mui_t muiP, - const confirm_t confirmP, - const sdu_size_t sdu_buffer_size, - unsigned char *const sdu_buffer, - const pdcp_transmission_mode_t mode, + const srb_flag_t srb_flagP, + const rb_id_t rb_idP, + const mui_t muiP, + const confirm_t confirmP, + const sdu_size_t sdu_buffer_sizeP, + unsigned char *const sdu_buffer_pP, + const pdcp_transmission_mode_t modeP, const uint32_t *const sourceL2Id, const uint32_t *const destinationL2Id) { - if (srb_flagP) { - return pdcp_data_req_srb(ctxt_pP, rb_id, muiP, confirmP, sdu_buffer_size, sdu_buffer); - } - else{ - return pdcp_data_req_drb(ctxt_pP, rb_id, muiP, confirmP, sdu_buffer_size, sdu_buffer); - } + abort(); + return false; } void pdcp_set_pdcp_data_ind_func(pdcp_data_ind_func_t pdcp_data_ind) diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h new file mode 100644 index 0000000000..56462297c1 --- /dev/null +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h @@ -0,0 +1,103 @@ +/* + * 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 + */ + +#ifndef NR_PDCP_OAI_API_H +#define NR_PDCP_OAI_API_H + +#include "pdcp.h" +#include "nr_pdcp_ue_manager.h" + +void nr_pdcp_layer_init(void); +uint64_t nr_pdcp_module_init(uint64_t _pdcp_optmask, int id); + +void du_rlc_data_req(const protocol_ctxt_t *const ctxt_pP, + const srb_flag_t srb_flagP, + const MBMS_flag_t MBMS_flagP, + const rb_id_t rb_idP, + const mui_t muiP, + confirm_t confirmP, + sdu_size_t sdu_sizeP, + mem_block_t *sdu_pP); + +bool pdcp_data_ind(const protocol_ctxt_t *const ctxt_pP, + const srb_flag_t srb_flagP, + const MBMS_flag_t MBMS_flagP, + const rb_id_t rb_id, + const sdu_size_t sdu_buffer_size, + mem_block_t *const sdu_buffer, + const uint32_t *const srcID, + const uint32_t *const dstID); + +void nr_pdcp_add_drbs(eNB_flag_t enb_flag, + ue_id_t rntiMaybeUEid, + ue_id_t reestablish_ue_id, + NR_DRB_ToAddModList_t *const drb2add_list, + const uint8_t security_modeP, + uint8_t *const kUPenc, + uint8_t *const kUPint, + struct NR_CellGroupConfig__rlc_BearerToAddModList *rlc_bearer2add_list); + +void nr_DRB_preconfiguration(ue_id_t crntiMaybeUEid); + +bool nr_pdcp_remove_UE(ue_id_t ue_id); + +void nr_pdcp_config_set_security(ue_id_t ue_id, + const rb_id_t rb_id, + const uint8_t security_modeP, + uint8_t *const kRRCenc_pP, + uint8_t *const kRRCint_pP, + uint8_t *const kUPenc_pP); + +bool cu_f1u_data_req(protocol_ctxt_t *ctxt_pP, + const srb_flag_t srb_flagP, + const rb_id_t rb_id, + const mui_t muiP, + const confirm_t confirmP, + const sdu_size_t sdu_buffer_size, + unsigned char *const sdu_buffer, + const pdcp_transmission_mode_t mode, + const uint32_t *const sourceL2Id, + const uint32_t *const destinationL2Id); + +bool nr_pdcp_data_req_srb(ue_id_t ue_id, + const rb_id_t rb_id, + const mui_t muiP, + const sdu_size_t sdu_buffer_size, + unsigned char *const sdu_buffer); +bool nr_pdcp_data_req_drb(protocol_ctxt_t *ctxt_pP, + const srb_flag_t srb_flagP, + const rb_id_t rb_id, + const mui_t muiP, + const confirm_t confirmP, + const sdu_size_t sdu_buffer_size, + unsigned char *const sdu_buffer, + const pdcp_transmission_mode_t mode, + const uint32_t *const sourceL2Id, + const uint32_t *const destinationL2Id); + +void nr_pdcp_run(const protocol_ctxt_t *const ctxt_pP); +void nr_pdcp_tick(int frame, int subframe); + +nr_pdcp_ue_manager_t *nr_pdcp_sdap_get_ue_manager(); + +const bool nr_pdcp_get_statistics(ue_id_t ue_id, int srb_flag, int rb_id, nr_pdcp_statistics_t *out); + +#endif /* NR_PDCP_OAI_API_H */ diff --git a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c index dab6f9fe58..103044f1bc 100644 --- a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c +++ b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c @@ -21,7 +21,7 @@ /* from openair */ #include "rlc.h" -#include "pdcp.h" +#include "LAYER2/nr_pdcp/nr_pdcp_oai_api.h" /* from nr rlc module */ #include "nr_rlc_asn1_utils.h" diff --git a/openair2/LAYER2/openair2_proc.c b/openair2/LAYER2/openair2_proc.c index 6ef447df5f..d68232b2e2 100644 --- a/openair2/LAYER2/openair2_proc.c +++ b/openair2/LAYER2/openair2_proc.c @@ -34,7 +34,7 @@ #include "LAYER2/RLC/rlc.h" #include "LAYER2/MAC/mac.h" #include "LAYER2/MAC/mac_extern.h" -#include "LAYER2/PDCP_v10.1.0/pdcp.h" +#include "LAYER2/nr_pdcp/nr_pdcp_oai_api.h" #include "common/utils/LOG/log.h" #include "common/ran_context.h" diff --git a/openair2/RRC/NR/L2_nr_interface.c b/openair2/RRC/NR/L2_nr_interface.c index 4a88b153bd..3554cb3715 100644 --- a/openair2/RRC/NR/L2_nr_interface.c +++ b/openair2/RRC/NR/L2_nr_interface.c @@ -32,7 +32,6 @@ #include "nr_rrc_defs.h" #include "nr_rrc_extern.h" #include "common/utils/LOG/log.h" -#include "pdcp.h" #include "common/ran_context.h" #include "LAYER2/NR_MAC_COMMON/nr_mac_common.h" #include "LAYER2/NR_MAC_COMMON/nr_mac_extern.h" @@ -43,6 +42,7 @@ #include "NR_BCCH-BCH-Message.h" #include "rrc_gNB_UE_context.h" #include +#include "nr_pdcp/nr_pdcp_oai_api.h" extern RAN_CONTEXT_t RC; @@ -100,7 +100,7 @@ nr_rrc_data_req( * Ideally, PDCP would not neet to be triggered like this but react to ITTI * messages automatically */ if (ctxt_pP->enb_flag) - pdcp_run(ctxt_pP); + nr_pdcp_run(ctxt_pP); return true; // TODO should be changed to a CNF message later, currently RRC lite does not used the returned value anyway. } diff --git a/openair2/RRC/NR/nr_rrc_common.c b/openair2/RRC/NR/nr_rrc_common.c index 1d231f20bf..c6f27c7325 100644 --- a/openair2/RRC/NR/nr_rrc_common.c +++ b/openair2/RRC/NR/nr_rrc_common.c @@ -37,7 +37,6 @@ #include "COMMON/mac_rrc_primitives.h" #include "common/utils/LOG/log.h" #include "asn1_msg.h" -#include "pdcp.h" #include "common/utils/LOG/vcd_signal_dumper.h" #include "common/ran_context.h" diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c index a4f57b0fae..c3afed5f6b 100644 --- a/openair2/RRC/NR/rrc_gNB.c +++ b/openair2/RRC/NR/rrc_gNB.c @@ -82,7 +82,7 @@ #include "rrc_gNB_GTPV1U.h" #include "nr_pdcp/nr_pdcp_entity.h" -#include "pdcp.h" +#include "nr_pdcp/nr_pdcp_oai_api.h" #include "intertask_interface.h" #include "SIMULATION/TOOLS/sim.h" // for taus @@ -105,15 +105,6 @@ extern RAN_CONTEXT_t RC; -extern void pdcp_config_set_security(const protocol_ctxt_t *const ctxt_pP, - pdcp_t *const pdcp_pP, - const rb_id_t rb_idP, - const uint16_t lc_idP, - const uint8_t security_modeP, - uint8_t *const kRRCenc, - uint8_t *const kRRCint, - uint8_t *const kUPenc); - static inline uint64_t bitStr_to_uint64(BIT_STRING_t *asn); mui_t rrc_gNB_mui = 0; @@ -1289,14 +1280,15 @@ void rrc_gNB_generate_RRCReestablishment(const protocol_ctxt_t *ctxt_pP, } // if (*SRB_configList != NULL) LOG_I(NR_RRC, "Set PDCP security RNTI %04lx nca %ld nia %d in RRCReestablishment\n", ctxt_pP->rntiMaybeUEid, ue_p->ciphering_algorithm, ue_p->integrity_algorithm); - pdcp_config_set_security(ctxt_pP, - NULL, /* pdcp_pP not used anymore in NR */ - DCCH, - DCCH + 2, - enable_ciphering ? ue_p->ciphering_algorithm | (ue_p->integrity_algorithm << 4) : 0 | (ue_p->integrity_algorithm << 4), - kRRCenc, - kRRCint, - kUPenc); + uint8_t security_mode = + enable_ciphering ? ue_p->ciphering_algorithm | (ue_p->integrity_algorithm << 4) : 0 | (ue_p->integrity_algorithm << 4); + + nr_pdcp_config_set_security(ctxt_pP->rntiMaybeUEid, + DCCH, + security_mode, + kRRCenc, + kRRCint, + kUPenc); if (!NODE_IS_CU(rrc->node_type)) { apply_macrlc_config_reest(rrc, ue_context_pP, ctxt_pP, ctxt_pP->rntiMaybeUEid); @@ -3225,7 +3217,7 @@ void nr_rrc_subframe_process(protocol_ctxt_t *const ctxt_pP, const int CC_id) { gNB_MAC_INST *nrmac = RC.nrmac[ctxt_pP->module_id]; // WHAT A BEAUTIFULL RACE CONDITION !!! mac_remove_nr_ue(nrmac, UE->rnti); rrc_rlc_remove_ue(ctxt_pP); - pdcp_remove_UE(ctxt_pP); + nr_pdcp_remove_UE(ctxt_pP->rntiMaybeUEid); /* remove RRC UE Context */ ue_context_p = rrc_gNB_get_ue_context_by_rnti(rrc, UE->rnti); @@ -3262,7 +3254,7 @@ void nr_rrc_subframe_process(protocol_ctxt_t *const ctxt_pP, const int CC_id) { mac_remove_nr_ue(nrmac, UE->rnti); } rrc_rlc_remove_ue(ctxt_pP); - pdcp_remove_UE(ctxt_pP); + nr_pdcp_remove_UE(ctxt_pP->rntiMaybeUEid); newGtpuDeleteAllTunnels(ctxt_pP->instance, UE->rnti); /* remove RRC UE Context */ diff --git a/openair2/RRC/NR/rrc_gNB_NGAP.c b/openair2/RRC/NR/rrc_gNB_NGAP.c index d3efb4b497..f9d7a492f5 100644 --- a/openair2/RRC/NR/rrc_gNB_NGAP.c +++ b/openair2/RRC/NR/rrc_gNB_NGAP.c @@ -36,7 +36,7 @@ #include "oai_asn1.h" #include "intertask_interface.h" -#include "pdcp.h" +#include "nr_pdcp/nr_pdcp_oai_api.h" #include "pdcp_primitives.h" #include "openair3/ocp-gtpu/gtp_itf.h" @@ -153,14 +153,9 @@ nr_rrc_pdcp_config_security( } } - pdcp_config_set_security(ctxt_pP, - NULL, /* pdcp_pP not used anymore in NR */ - DCCH, - DCCH + 2, - enable_ciphering ? UE->ciphering_algorithm | (UE->integrity_algorithm << 4) : 0 | (UE->integrity_algorithm << 4), - kRRCenc, - kRRCint, - kUPenc); + uint8_t security_mode = + enable_ciphering ? UE->ciphering_algorithm | (UE->integrity_algorithm << 4) : 0 | (UE->integrity_algorithm << 4); + nr_pdcp_config_set_security(ctxt_pP->rntiMaybeUEid, DCCH, security_mode, kRRCenc, kRRCint, kUPenc); } //------------------------------------------------------------------------------ diff --git a/openair2/RRC/NR/rrc_gNB_nsa.c b/openair2/RRC/NR/rrc_gNB_nsa.c index 0a6eb050e5..989c754c20 100644 --- a/openair2/RRC/NR/rrc_gNB_nsa.c +++ b/openair2/RRC/NR/rrc_gNB_nsa.c @@ -45,7 +45,7 @@ #include #include "UTIL/OSA/osa_defs.h" #include -#include "pdcp.h" +#include "nr_pdcp/nr_pdcp_oai_api.h" void rrc_parse_ue_capabilities(gNB_RRC_INST *rrc, NR_UE_CapabilityRAT_ContainerList_t *UE_CapabilityRAT_ContainerList, x2ap_ENDC_sgnb_addition_req_t *m, NR_CG_ConfigInfo_IEs_t *cg_config_info) { @@ -391,7 +391,7 @@ void rrc_remove_nsa_user(gNB_RRC_INST *rrc, int rnti) { return; } - pdcp_remove_UE(&ctxt); + nr_pdcp_remove_UE(ctxt.rntiMaybeUEid); rrc_rlc_remove_ue(&ctxt); diff --git a/openair2/RRC/NR_UE/rrc_UE.c b/openair2/RRC/NR_UE/rrc_UE.c index ecbaeea17e..3cff4e8c17 100644 --- a/openair2/RRC/NR_UE/rrc_UE.c +++ b/openair2/RRC/NR_UE/rrc_UE.c @@ -58,7 +58,7 @@ #include "nr-uesoftmodem.h" #include "executables/softmodem-common.h" #include "plmn_data.h" -#include "pdcp.h" +#include "nr_pdcp/nr_pdcp_oai_api.h" #include "UTIL/OSA/osa_defs.h" #include "common/utils/LOG/log.h" #include "common/utils/LOG/vcd_signal_dumper.h" @@ -90,17 +90,6 @@ static const char nr_nas_attach_req_imsi[] = { 0x01, 0x27, 0x11, }; -extern void pdcp_config_set_security( - const protocol_ctxt_t *const ctxt_pP, - pdcp_t *const pdcp_pP, - const rb_id_t rb_idP, - const uint16_t lc_idP, - const uint8_t security_modeP, - uint8_t *const kRRCenc, - uint8_t *const kRRCint, - uint8_t *const kUPenc -); - void nr_rrc_ue_process_ueCapabilityEnquiry( const protocol_ctxt_t *const ctxt_pP, @@ -1675,10 +1664,9 @@ int8_t nr_rrc_ue_decode_ccch( const protocol_ctxt_t *const ctxt_pP, const NR_SRB NR_UE_rrc_inst[ctxt_pP->module_id].kgnb[28], NR_UE_rrc_inst[ctxt_pP->module_id].kgnb[29], NR_UE_rrc_inst[ctxt_pP->module_id].kgnb[30], NR_UE_rrc_inst[ctxt_pP->module_id].kgnb[31]); if (securityMode != 0xff) { - pdcp_config_set_security(ctxt_pP, NULL, DCCH, DCCH+2, - NR_UE_rrc_inst[ctxt_pP->module_id].cipheringAlgorithm - | (NR_UE_rrc_inst[ctxt_pP->module_id].integrityProtAlgorithm << 4), - kRRCenc, kRRCint, kUPenc); + uint8_t security_mode = + NR_UE_rrc_inst[ctxt_pP->module_id].cipheringAlgorithm | (NR_UE_rrc_inst[ctxt_pP->module_id].integrityProtAlgorithm << 4); + nr_pdcp_config_set_security(ctxt_pP->rntiMaybeUEid, DCCH, security_mode, kRRCenc, kRRCint, kUPenc); } else { LOG_I(NR_RRC, "skipped pdcp_config_set_security() as securityMode == 0x%02x", securityMode); } diff --git a/openair2/SDAP/nr_sdap/nr_sdap_entity.c b/openair2/SDAP/nr_sdap/nr_sdap_entity.c index 280663e2b0..357bec24ad 100644 --- a/openair2/SDAP/nr_sdap/nr_sdap_entity.c +++ b/openair2/SDAP/nr_sdap/nr_sdap_entity.c @@ -21,7 +21,7 @@ #include "nr_sdap_entity.h" #include "common/utils/LOG/log.h" -#include +#include #include #include "openair2/LAYER2/nr_pdcp/nr_pdcp_ue_manager.h" @@ -37,8 +37,6 @@ static nr_sdap_entity_info sdap_info; instance_t *N3GTPUInst = NULL; -nr_pdcp_ue_manager_t *nr_pdcp_sdap_get_ue_manager(void); - void nr_pdcp_submit_sdap_ctrl_pdu(ue_id_t ue_id, rb_id_t sdap_ctrl_pdu_drb, nr_sdap_ul_hdr_t ctrl_pdu) { nr_pdcp_ue_t *ue; @@ -87,16 +85,16 @@ static bool nr_sdap_tx_entity(nr_sdap_entity_t *entity, if(!pdcp_ent_has_sdap){ LOG_D(SDAP, "TX - DRB ID: %ld does not have SDAP\n", entity->qfi2drb_table[qfi].drb_id); - ret = pdcp_data_req(ctxt_p, - srb_flag, - sdap_drb_id, - mui, - confirm, - sdu_buffer_size, - sdu_buffer, - pt_mode, - sourceL2Id, - destinationL2Id); + ret = nr_pdcp_data_req_drb(ctxt_p, + srb_flag, + sdap_drb_id, + mui, + confirm, + sdu_buffer_size, + sdu_buffer, + pt_mode, + sourceL2Id, + destinationL2Id); if(!ret) LOG_E(SDAP, "%s:%d:%s: PDCP refused PDU\n", __FILE__, __LINE__, __FUNCTION__); @@ -155,16 +153,16 @@ static bool nr_sdap_tx_entity(nr_sdap_entity_t *entity, * * Downlink gNB side */ - ret = pdcp_data_req(ctxt_p, - srb_flag, - sdap_drb_id, - mui, - confirm, - sdu_buffer_size+offset, - sdap_buf, - pt_mode, - sourceL2Id, - destinationL2Id); + ret = nr_pdcp_data_req_drb(ctxt_p, + srb_flag, + sdap_drb_id, + mui, + confirm, + sdu_buffer_size + offset, + sdap_buf, + pt_mode, + sourceL2Id, + destinationL2Id); if(!ret) LOG_E(SDAP, "%s:%d:%s: PDCP refused PDU\n", __FILE__, __LINE__, __FUNCTION__); diff --git a/openair3/ocp-gtpu/gtp_itf.cpp b/openair3/ocp-gtpu/gtp_itf.cpp index 2f60d5238c..f6255fb056 100644 --- a/openair3/ocp-gtpu/gtp_itf.cpp +++ b/openair3/ocp-gtpu/gtp_itf.cpp @@ -17,6 +17,7 @@ extern "C" { #include #include #include +#include #include #include "openair2/SDAP/nr_sdap/nr_sdap.h" #include "sim.h" @@ -748,7 +749,7 @@ int gtpv1u_create_ngu_tunnel( const instance_t instance, create_tunnel_req->outgoing_qfi[i], create_tunnel_req->dst_addr[i], dstport, - pdcp_data_req, + nr_pdcp_data_req_drb, sdap_data_req); create_tunnel_resp->status=0; create_tunnel_resp->ue_id=create_tunnel_req->ue_id; From c405ad16a826b143c5a9fdc81573d3db179fcbff Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Sun, 19 Mar 2023 14:50:34 +0100 Subject: [PATCH 3/7] Remove nr_rrc_data_req()/rrc_data_req_nr_ue() --- doc/SW_archi.md | 3 -- executables/nr-softmodem.c | 6 +++ executables/nr-ue.c | 13 ------ openair2/LAYER2/MAC/eNB_scheduler.c | 2 +- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c | 1 - openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c | 40 ----------------- openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h | 1 - openair2/RRC/NR/L2_nr_interface.c | 50 --------------------- openair2/RRC/NR/nr_rrc_proto.h | 11 ----- openair2/RRC/NR/rrc_gNB.c | 48 +++++--------------- openair2/RRC/NR/rrc_gNB_NGAP.c | 2 +- openair2/RRC/NR_UE/L2_interface_ue.c | 37 --------------- openair2/RRC/NR_UE/rrc_UE.c | 52 +++------------------- openair2/RRC/NR_UE/rrc_proto.h | 11 ----- 14 files changed, 25 insertions(+), 252 deletions(-) diff --git a/doc/SW_archi.md b/doc/SW_archi.md index 1e8e5cd011..6b509cc627 100644 --- a/doc/SW_archi.md +++ b/doc/SW_archi.md @@ -334,9 +334,6 @@ At Tx side (DL in gNB), `pdcp_data_req_drb()` and `pdcp_data_req_srb()` are the The upper layer can be GTP or a PDCP internal thread enb_tun_read_thread() that read directly from Linux socket in case we skip 3GPP core implementation. PDCP internals for nr_pdcp_data_req_srb()/nr_pdcp_data_req_drb() are thread safe: inside them, the pdcp manager protects with the mutex the access to the SDU receiving function of PDCP (recv_sdu() callback, corresponding to nr_pdcp_entity_drb_am_recv_sdu() for DRBs). When it needs, the pdcp layer push this data to rlc by calling : rlc_data_req() -Also, incoming downlink sdu can comme from internal RRC: in this case, nr -nr_pdcp_run() reads a itti queue, for message RRC_DCCH_DATA_REQ, to0 only call 'nr_pdcp_data_req_srb()' - At Rx side, pdcp_data_ind() is the entry point that receives the data from RLC. - Inside pdcp_data_ind(), the pdcp manager mutex protects the access to the PDU receiving function of PDCP (recv_pdu() callback corresponding to nr_pdcp_entity_drb_am_recv_pdu() for DRBs) - Then deliver_sdu_drb() function sends the received data to GTP thread through an ITTI message (GTPV1U_TUNNEL_DATA_REQ). diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c index 455bf83904..643d3a9cc7 100644 --- a/executables/nr-softmodem.c +++ b/executables/nr-softmodem.c @@ -176,6 +176,12 @@ openair0_config_t openair0_cfg[MAX_CARDS]; double cpuf; +/* hack: pdcp_run() is required by 4G scheduler which is compiled into + * nr-softmodem because of linker issues */ +void pdcp_run(const protocol_ctxt_t *const ctxt_pP) +{ + abort(); +} /* see file openair2/LAYER2/MAC/main.c for why abstraction_flag is needed * this is very hackish - find a proper solution diff --git a/executables/nr-ue.c b/executables/nr-ue.c index a1ec29a42a..d5b7866505 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -355,12 +355,6 @@ static void *NRUE_phy_stub_standalone_pnf_task(void *arg) nr_ue_ul_scheduler(&ul_info); nr_ue_pucch_scheduler(mod_id, ul_info.frame_tx, ul_info.slot_tx, NULL); } - if (!IS_SOFTMODEM_NOS1 && get_softmodem_params()->sa) { - NR_UE_MAC_INST_t *mac = get_mac_inst(0); - protocol_ctxt_t ctxt; - PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, 0, ENB_FLAG_NO, mac->crnti, frame, slot, 0); - nr_pdcp_run(&ctxt); - } process_queued_nr_nfapi_msgs(mac, sfn_slot); } return NULL; @@ -622,13 +616,6 @@ void UE_processing(nr_rxtx_thread_data_t *rxtxD) { phy_procedures_nrUE_RX(UE, proc, &phy_data); LOG_D(PHY, "In %s: slot %d, time %llu\n", __FUNCTION__, proc->nr_slot_rx, (rdtsc_oai()-a)/3500); #endif - - if(IS_SOFTMODEM_NOS1 || get_softmodem_params()->sa){ - NR_UE_MAC_INST_t *mac = get_mac_inst(0); - protocol_ctxt_t ctxt; - PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, UE->Mod_id, ENB_FLAG_NO, mac->crnti, proc->frame_rx, proc->nr_slot_rx, 0); - nr_pdcp_run(&ctxt); - } } ue_ta_procedures(UE, proc->nr_slot_tx, proc->frame_tx); diff --git a/openair2/LAYER2/MAC/eNB_scheduler.c b/openair2/LAYER2/MAC/eNB_scheduler.c index e56b3d4f6f..badcd36cc6 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler.c +++ b/openair2/LAYER2/MAC/eNB_scheduler.c @@ -958,7 +958,7 @@ eNB_dlsch_ulsch_scheduler(module_id_t module_idP, void rlc_tick(int, int); PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, subframeP, module_idP); rlc_tick(frameP, subframeP); - //pdcp_run(&ctxt); + pdcp_run(&ctxt); pdcp_mbms_run(&ctxt); rrc_rx_tx(&ctxt, CC_id); #endif diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c index 4a5b4cc626..41a2153cf8 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c @@ -136,7 +136,6 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP, start_meas(&gNB->eNB_scheduler); VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_gNB_DLSCH_ULSCH_SCHEDULER,VCD_FUNCTION_IN); - nr_pdcp_run(&ctxt); /* send tick to RLC and RRC every ms */ if ((slot & ((1 << *scc->ssbSubcarrierSpacing) - 1)) == 0) { void nr_rlc_tick(int frame, int subframe); diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c index 3b198ff17c..a91f4e883f 100644 --- a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c @@ -795,46 +795,6 @@ srb_found: } } -void nr_pdcp_run(const protocol_ctxt_t *const ctxt_pP) -{ - MessageDef *msg_p; - int result; - protocol_ctxt_t ctxt = {.module_id = 0, .enb_flag = 1, .instance = 0, .rntiMaybeUEid = 0, .frame = -1, .subframe = -1, .eNB_index = 0, .brOption = false}; - - while (1) { - itti_poll_msg(ctxt_pP->enb_flag ? TASK_PDCP_ENB : TASK_PDCP_UE, &msg_p); - if (msg_p == NULL){ - break; - } - switch (ITTI_MSG_ID(msg_p)) { - case RRC_DCCH_DATA_REQ: - LOG_D(PDCP, "Received RRC_DCCH_DATA_REQ type at PDCP task \n"); - PROTOCOL_CTXT_SET_BY_MODULE_ID( - &ctxt, - RRC_DCCH_DATA_REQ(msg_p).module_id, - RRC_DCCH_DATA_REQ(msg_p).enb_flag, - RRC_DCCH_DATA_REQ(msg_p).rnti, - RRC_DCCH_DATA_REQ(msg_p).frame, - 0, - RRC_DCCH_DATA_REQ(msg_p).eNB_index); - result = nr_pdcp_data_req_srb(ctxt.rntiMaybeUEid, - RRC_DCCH_DATA_REQ(msg_p).rb_id, - RRC_DCCH_DATA_REQ(msg_p).muip, - RRC_DCCH_DATA_REQ(msg_p).sdu_size, - RRC_DCCH_DATA_REQ(msg_p).sdu_p); - - if (result != true) - LOG_E(PDCP, "PDCP data request failed!\n"); - result = itti_free(ITTI_MSG_ORIGIN_ID(msg_p), RRC_DCCH_DATA_REQ(msg_p).sdu_p); - AssertFatal(result == EXIT_SUCCESS, "Failed to free memory (%d)!\n", result); - break; - default: - LOG_E(PDCP, "Received unexpected message %s\n", ITTI_MSG_NAME(msg_p)); - break; - } - } -} - static void add_srb(int is_gnb, ue_id_t rntiMaybeUEid, struct NR_SRB_ToAddMod *s, int ciphering_algorithm, int integrity_algorithm, unsigned char *ciphering_key, unsigned char *integrity_key) { nr_pdcp_entity_t *pdcp_srb; diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h index 56462297c1..1b69b9d2e7 100644 --- a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h @@ -93,7 +93,6 @@ bool nr_pdcp_data_req_drb(protocol_ctxt_t *ctxt_pP, const uint32_t *const sourceL2Id, const uint32_t *const destinationL2Id); -void nr_pdcp_run(const protocol_ctxt_t *const ctxt_pP); void nr_pdcp_tick(int frame, int subframe); nr_pdcp_ue_manager_t *nr_pdcp_sdap_get_ue_manager(); diff --git a/openair2/RRC/NR/L2_nr_interface.c b/openair2/RRC/NR/L2_nr_interface.c index 3554cb3715..d8d43e490c 100644 --- a/openair2/RRC/NR/L2_nr_interface.c +++ b/openair2/RRC/NR/L2_nr_interface.c @@ -55,56 +55,6 @@ nr_rrc_mac_remove_ue(module_id_t mod_idP, return 0; } -//------------------------------------------------------------------------------ -uint8_t -nr_rrc_data_req( - const protocol_ctxt_t *const ctxt_pP, - const rb_id_t rb_idP, - const mui_t muiP, - const confirm_t confirmP, - const sdu_size_t sdu_sizeP, - uint8_t *const buffer_pP, - const pdcp_transmission_mode_t modeP -) -//------------------------------------------------------------------------------ -{ - - MessageDef *message_p; - // Uses a new buffer to avoid issue with PDCP buffer content that could be changed by PDCP (asynchronous message handling). - uint8_t *message_buffer; - message_buffer = itti_malloc ( - ctxt_pP->enb_flag ? TASK_RRC_GNB : TASK_RRC_UE, - ctxt_pP->enb_flag ? TASK_PDCP_ENB : TASK_PDCP_UE, - sdu_sizeP); - memcpy (message_buffer, buffer_pP, sdu_sizeP); - message_p = itti_alloc_new_message (ctxt_pP->enb_flag ? TASK_RRC_GNB : TASK_RRC_UE, 0, RRC_DCCH_DATA_REQ); - RRC_DCCH_DATA_REQ (message_p).frame = ctxt_pP->frame; - RRC_DCCH_DATA_REQ (message_p).enb_flag = ctxt_pP->enb_flag; - RRC_DCCH_DATA_REQ (message_p).rb_id = rb_idP; - RRC_DCCH_DATA_REQ (message_p).muip = muiP; - RRC_DCCH_DATA_REQ (message_p).confirmp = confirmP; - RRC_DCCH_DATA_REQ (message_p).sdu_size = sdu_sizeP; - RRC_DCCH_DATA_REQ (message_p).sdu_p = message_buffer; - //memcpy (NR_RRC_DCCH_DATA_REQ (message_p).sdu_p, buffer_pP, sdu_sizeP); - RRC_DCCH_DATA_REQ (message_p).mode = modeP; - RRC_DCCH_DATA_REQ (message_p).module_id = ctxt_pP->module_id; - RRC_DCCH_DATA_REQ(message_p).rnti = ctxt_pP->rntiMaybeUEid; - RRC_DCCH_DATA_REQ (message_p).eNB_index = ctxt_pP->eNB_index; - itti_send_msg_to_task ( - ctxt_pP->enb_flag ? TASK_PDCP_ENB : TASK_PDCP_UE, - ctxt_pP->instance, - message_p); - LOG_I(NR_RRC,"send RRC_DCCH_DATA_REQ to PDCP\n"); - - /* Hack: only trigger PDCP if in CU, otherwise it is triggered by RU threads - * Ideally, PDCP would not neet to be triggered like this but react to ITTI - * messages automatically */ - if (ctxt_pP->enb_flag) - nr_pdcp_run(ctxt_pP); - - return true; // TODO should be changed to a CNF message later, currently RRC lite does not used the returned value anyway. -} - uint16_t mac_rrc_nr_data_req(const module_id_t Mod_idP, const int CC_id, const frame_t frameP, diff --git a/openair2/RRC/NR/nr_rrc_proto.h b/openair2/RRC/NR/nr_rrc_proto.h index 5ad9a71e39..b54165b13f 100644 --- a/openair2/RRC/NR/nr_rrc_proto.h +++ b/openair2/RRC/NR/nr_rrc_proto.h @@ -136,17 +136,6 @@ void nr_rrc_trigger(protocol_ctxt_t *ctxt, int CC_id, int frame, int subframe); \ *reOffset Pointer to RE Offset Value */ void rrc_config_dl_ptrs_params(NR_BWP_Downlink_t *bwp, int *ptrsNrb, int *ptrsMcs, int *epre_Ratio, int * reOffset); -uint8_t -nr_rrc_data_req( - const protocol_ctxt_t *const ctxt_pP, - const rb_id_t rb_idP, - const mui_t muiP, - const confirm_t confirmP, - const sdu_size_t sdu_size, - uint8_t *const buffer_pP, - const pdcp_transmission_mode_t modeP -); - int nr_rrc_mac_remove_ue(module_id_t mod_idP, rnti_t rntiP); diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c index c3afed5f6b..b51d4563da 100644 --- a/openair2/RRC/NR/rrc_gNB.c +++ b/openair2/RRC/NR/rrc_gNB.c @@ -573,7 +573,7 @@ static void rrc_gNB_generate_defaultRRCReconfiguration(const protocol_ctxt_t *co ue_context_pP->ue_context.rnti); AssertFatal(!NODE_IS_DU(rrc->node_type), "illegal node type DU!\n"); - nr_rrc_data_req(ctxt_pP, DCCH, rrc_gNB_mui++, SDU_CONFIRM_NO, size, buffer, PDCP_TRANSMISSION_MODE_CONTROL); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); if (NODE_IS_DU(rrc->node_type) || NODE_IS_MONOLITHIC(rrc->node_type)) { gNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context; @@ -762,14 +762,7 @@ rrc_gNB_generate_dedicatedRRCReconfiguration( ctxt_pP->module_id, DCCH); - nr_rrc_data_req( - ctxt_pP, - DCCH, - rrc_gNB_mui++, - SDU_CONFIRM_NO, - size, - buffer, - PDCP_TRANSMISSION_MODE_CONTROL); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); if (NODE_IS_DU(rrc->node_type) || NODE_IS_MONOLITHIC(rrc->node_type)) { nr_mac_update_cellgroup(RC.nrmac[rrc->module_id], ue_context_pP->ue_context.rnti, ue_context_pP->ue_context.masterCellGroup); @@ -936,14 +929,7 @@ rrc_gNB_modify_dedicatedRRCReconfiguration( ctxt_pP->module_id, DCCH); - nr_rrc_data_req( - ctxt_pP, - DCCH, - rrc_gNB_mui++, - SDU_CONFIRM_NO, - size, - buffer, - PDCP_TRANSMISSION_MODE_CONTROL); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); if (NODE_IS_DU(RC.nrrrc[ctxt_pP->module_id]->node_type) || NODE_IS_MONOLITHIC(RC.nrrrc[ctxt_pP->module_id]->node_type)) { uint32_t delay_ms = ue_p->masterCellGroup && ue_p->masterCellGroup->spCellConfig && ue_p->masterCellGroup->spCellConfig->spCellConfigDedicated @@ -1026,14 +1012,8 @@ rrc_gNB_generate_dedicatedRRCReconfiguration_release( rrc_gNB_mui, ctxt_pP->module_id, DCCH); - nr_rrc_data_req( - ctxt_pP, - DCCH, - rrc_gNB_mui++, - SDU_CONFIRM_NO, - size, - buffer, - PDCP_TRANSMISSION_MODE_CONTROL); + + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); if (NODE_IS_DU(RC.nrrrc[ctxt_pP->module_id]->node_type) || NODE_IS_MONOLITHIC(RC.nrrrc[ctxt_pP->module_id]->node_type)) { uint32_t delay_ms = ue_p->masterCellGroup && ue_p->masterCellGroup->spCellConfig && ue_p->masterCellGroup->spCellConfig->spCellConfigDedicated @@ -1294,7 +1274,7 @@ void rrc_gNB_generate_RRCReestablishment(const protocol_ctxt_t *ctxt_pP, apply_macrlc_config_reest(rrc, ue_context_pP, ctxt_pP, ctxt_pP->rntiMaybeUEid); } - nr_rrc_data_req(ctxt_pP, DCCH, rrc_gNB_mui++, SDU_CONFIRM_NO, size, buffer, PDCP_TRANSMISSION_MODE_CONTROL); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); } //----------------------------------------------------------------------------- @@ -1507,7 +1487,7 @@ cellGroupConfig->physicalCellGroupConfig = ue_p->masterCellGroup->physicalCellGr DCCH); nr_mac_update_cellgroup(RC.nrmac[rrc->module_id], ue_context_pP->ue_context.rnti, cellGroupConfig); - nr_rrc_data_req(ctxt_pP, DCCH, rrc_gNB_mui++, SDU_CONFIRM_NO, size, buffer, PDCP_TRANSMISSION_MODE_CONTROL); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); } if (NODE_IS_DU(RC.nrrrc[ctxt_pP->module_id]->node_type) || NODE_IS_MONOLITHIC(RC.nrrrc[ctxt_pP->module_id]->node_type)) { @@ -1558,13 +1538,7 @@ int nr_rrc_reconfiguration_req(rrc_gNB_ue_context_t *const ue_context_pP nr_mac_update_cellgroup(RC.nrmac[ctxt_pP->module_id], ue_context_pP->ue_context.rnti, masterCellGroup); - nr_rrc_data_req(ctxt_pP, - DCCH, - rrc_gNB_mui++, - SDU_CONFIRM_NO, - size, - buffer, - PDCP_TRANSMISSION_MODE_CONTROL); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); if (NODE_IS_DU(RC.nrrrc[ctxt_pP->module_id]->node_type) || NODE_IS_MONOLITHIC(RC.nrrrc[ctxt_pP->module_id]->node_type)) { uint32_t delay_ms = ue_p->masterCellGroup && ue_p->masterCellGroup->spCellConfig && ue_p->masterCellGroup->spCellConfig->spCellConfigDedicated @@ -3615,7 +3589,7 @@ rrc_gNB_generate_SecurityModeCommand( gNB_RRC_INST *rrc = RC.nrrrc[ctxt_pP->module_id]; AssertFatal(!NODE_IS_DU(rrc->node_type), "illegal node type DU!\n"); - nr_rrc_data_req(ctxt_pP, DCCH, rrc_gNB_mui++, SDU_CONFIRM_NO, size, buffer, PDCP_TRANSMISSION_MODE_CONTROL); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); } void @@ -3641,7 +3615,7 @@ rrc_gNB_generate_UECapabilityEnquiry( gNB_RRC_INST *rrc = RC.nrrrc[ctxt_pP->module_id]; AssertFatal(!NODE_IS_DU(rrc->node_type), "illegal node type DU!\n"); - nr_rrc_data_req(ctxt_pP, DCCH, rrc_gNB_mui++, SDU_CONFIRM_NO, size, buffer, PDCP_TRANSMISSION_MODE_CONTROL); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); } //----------------------------------------------------------------------------- @@ -3675,7 +3649,7 @@ rrc_gNB_generate_RRCRelease( rrc_gNB_mui, DCCH); - nr_rrc_data_req(ctxt_pP, DCCH, rrc_gNB_mui++, SDU_CONFIRM_NO, size, buffer, PDCP_TRANSMISSION_MODE_CONTROL); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); rrc_gNB_send_NGAP_UE_CONTEXT_RELEASE_COMPLETE(ctxt_pP->instance, ue_context_pP->ue_context.gNB_ue_ngap_id); ue_context_pP->ue_context.ue_release_timer_rrc = 1; diff --git a/openair2/RRC/NR/rrc_gNB_NGAP.c b/openair2/RRC/NR/rrc_gNB_NGAP.c index f9d7a492f5..2120d25920 100644 --- a/openair2/RRC/NR/rrc_gNB_NGAP.c +++ b/openair2/RRC/NR/rrc_gNB_NGAP.c @@ -620,7 +620,7 @@ int rrc_gNB_process_NGAP_DOWNLINK_NAS(MessageDef *msg_p, instance_t instance, mu AssertFatal(!NODE_IS_DU(RC.nrrrc[ctxt.module_id]->node_type), "illegal node type DU: receiving NGAP messages at this node\n"); /* Transfer data to PDCP */ rb_id_t srb_id = UE->Srb[2].Active ? DCCH1 : DCCH; - nr_rrc_data_req(&ctxt, srb_id, (*rrc_gNB_mui)++, SDU_CONFIRM_NO, length, buffer, PDCP_TRANSMISSION_MODE_CONTROL); + nr_pdcp_data_req_srb(ctxt.rntiMaybeUEid, srb_id, (*rrc_gNB_mui)++, length, buffer); return 0; } diff --git a/openair2/RRC/NR_UE/L2_interface_ue.c b/openair2/RRC/NR_UE/L2_interface_ue.c index c67069e975..9efb8e5012 100644 --- a/openair2/RRC/NR_UE/L2_interface_ue.c +++ b/openair2/RRC/NR_UE/L2_interface_ue.c @@ -148,40 +148,3 @@ int8_t nr_mac_rrc_data_req_ue(const module_id_t Mod_idP, return 0; } - -uint8_t -rrc_data_req_nr_ue( - const protocol_ctxt_t *const ctxt_pP, - const rb_id_t rb_idP, - const mui_t muiP, - const confirm_t confirmP, - const sdu_size_t sdu_sizeP, - uint8_t *const buffer_pP, - const pdcp_transmission_mode_t modeP -) -{ - MessageDef *message_p; - // Uses a new buffer to avoid issue with PDCP buffer content that could be changed by PDCP (asynchronous message handling). - uint8_t *message_buffer; - message_buffer = itti_malloc (TASK_RRC_UE, TASK_PDCP_UE, sdu_sizeP); - LOG_D(RRC,"Sending RRC message for SRB %ld, sdu_size %d\n",rb_idP, sdu_sizeP); - memcpy (message_buffer, buffer_pP, sdu_sizeP); - message_p = itti_alloc_new_message ( TASK_RRC_UE, 0, RRC_DCCH_DATA_REQ); - RRC_DCCH_DATA_REQ (message_p).frame = ctxt_pP->frame; - RRC_DCCH_DATA_REQ (message_p).enb_flag = ctxt_pP->enb_flag; - RRC_DCCH_DATA_REQ (message_p).rb_id = rb_idP; - RRC_DCCH_DATA_REQ (message_p).muip = muiP; - RRC_DCCH_DATA_REQ (message_p).confirmp = confirmP; - RRC_DCCH_DATA_REQ (message_p).sdu_size = sdu_sizeP; - RRC_DCCH_DATA_REQ (message_p).sdu_p = message_buffer; - RRC_DCCH_DATA_REQ (message_p).mode = modeP; - RRC_DCCH_DATA_REQ (message_p).module_id = ctxt_pP->module_id; - RRC_DCCH_DATA_REQ(message_p).rnti = ctxt_pP->rntiMaybeUEid; - RRC_DCCH_DATA_REQ (message_p).eNB_index = ctxt_pP->eNB_index; - itti_send_msg_to_task ( - TASK_PDCP_UE, - ctxt_pP->instance, - message_p); - return true; // TODO should be changed to a CNF message later, currently RRC lite does not used the returned value anyway. - -} diff --git a/openair2/RRC/NR_UE/rrc_UE.c b/openair2/RRC/NR_UE/rrc_UE.c index 3cff4e8c17..27390a1b51 100644 --- a/openair2/RRC/NR_UE/rrc_UE.c +++ b/openair2/RRC/NR_UE/rrc_UE.c @@ -1386,14 +1386,7 @@ static void rrc_ue_generate_RRCSetupComplete( //for (int i=0;irnti; - rrc_data_req_nr_ue(ctxt_pP, - DCCH, - nr_rrc_mui++, - SDU_CONFIRM_NO, - size, - buffer, - PDCP_TRANSMISSION_MODE_CONTROL); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, nr_rrc_mui++, size, buffer); } int8_t nr_rrc_ue_decode_ccch( const protocol_ctxt_t *const ctxt_pP, const NR_SRB_INFO *const Srb_info, const uint8_t gNB_index ){ @@ -1698,13 +1691,7 @@ int8_t nr_rrc_ue_decode_ccch( const protocol_ctxt_t *const ctxt_pP, const NR_SRB } LOG_T(NR_RRC, "\n"); - rrc_data_req_nr_ue (ctxt_pP, - DCCH, - nr_rrc_mui++, - SDU_CONFIRM_NO, - (enc_rval.encoded + 7) / 8, - buffer, - PDCP_TRANSMISSION_MODE_CONTROL); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, nr_rrc_mui++, (enc_rval.encoded + 7) / 8, buffer); } else LOG_W(NR_RRC,"securityModeCommand->criticalExtensions.present (%d) != NR_SecurityModeCommand__criticalExtensions_PR_securityModeCommand\n", securityModeCommand->criticalExtensions.present); @@ -2190,14 +2177,7 @@ nr_rrc_ue_establish_srb2( nr_rrc_mui, UE_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id), DCCH); - rrc_data_req_nr_ue ( - ctxt_pP, - DCCH, - nr_rrc_mui++, - SDU_CONFIRM_NO, - size, - buffer, - PDCP_TRANSMISSION_MODE_CONTROL); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, nr_rrc_mui++, size, buffer); } // from NR SRB1 @@ -2446,21 +2426,8 @@ nr_rrc_ue_establish_srb2( /* Transfer data to PDCP */ PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, GNB_FLAG_NO, NR_UE_rrc_inst[ue_mod_id].Info[0].rnti, 0, 0,0); // check if SRB2 is created, if yes request data_req on DCCH1 (SRB2) - if(NR_UE_rrc_inst[ue_mod_id].SRB2_config[0] == NULL) { - rrc_data_req_nr_ue (&ctxt, - DCCH, - nr_rrc_mui++, - SDU_CONFIRM_NO, - length, buffer, - PDCP_TRANSMISSION_MODE_CONTROL); - } else { - rrc_data_req_nr_ue (&ctxt, - DCCH1, - nr_rrc_mui++, - SDU_CONFIRM_NO, - length, buffer, - PDCP_TRANSMISSION_MODE_CONTROL); - } + rb_id_t srb_id = NR_UE_rrc_inst[ue_mod_id].SRB2_config[0] == NULL ? DCCH : DCCH1; + nr_pdcp_data_req_srb(ctxt.rntiMaybeUEid, srb_id, nr_rrc_mui++, length, buffer); break; } @@ -2604,14 +2571,7 @@ nr_rrc_ue_process_ueCapabilityEnquiry( } LOG_I(NR_RRC, "UECapabilityInformation Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8); - rrc_data_req_nr_ue ( - ctxt_pP, - DCCH, - nr_rrc_mui++, - SDU_CONFIRM_NO, - (enc_rval.encoded + 7) / 8, - buffer, - PDCP_TRANSMISSION_MODE_CONTROL); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, nr_rrc_mui++, (enc_rval.encoded + 7) / 8, buffer); } } } diff --git a/openair2/RRC/NR_UE/rrc_proto.h b/openair2/RRC/NR_UE/rrc_proto.h index 510fbff230..2b2bab13e0 100644 --- a/openair2/RRC/NR_UE/rrc_proto.h +++ b/openair2/RRC/NR_UE/rrc_proto.h @@ -145,17 +145,6 @@ int8_t nr_mac_rrc_data_req_ue(const module_id_t Mod_idP, const rb_id_t Srb_id, uint8_t *buffer_pP); -uint8_t -rrc_data_req_nr_ue( - const protocol_ctxt_t *const ctxt_pP, - const rb_id_t rb_idP, - const mui_t muiP, - const confirm_t confirmP, - const sdu_size_t sdu_sizeP, - uint8_t *const buffer_pP, - const pdcp_transmission_mode_t modeP -); - /**\brief RRC UE task. \param void *args_p Pointer on arguments to start the task. */ void *rrc_nrue_task(void *args_p); From 0f43c2c713e9b9f29a509e5ac69d5841b804806c Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Mon, 20 Mar 2023 11:24:08 +0100 Subject: [PATCH 4/7] PDCP DL handling: unlock PDCP before forwarding PDU nr_pdcp_entity_recv_sdu() processes PDCP SDUs, and forwards the PDU at the end of the function, while having the PDCP lock. This can lead to deadlocks, e.g., when another thread goes through RLC and tries to access the PDCP while the PDCP tries to lock the RLC. This commit changes the logic: instead of having recv_sdu() forward the PDU directly, it fills a buffer with the PDU (thus the name change to process_sdu()), and returns. We then unlock the PDCP, before forwarding the PDU, thus eliminating potential deadlocks. --- openair2/LAYER2/nr_pdcp/nr_pdcp_entity.c | 17 ++++++++++------- openair2/LAYER2/nr_pdcp/nr_pdcp_entity.h | 4 ++-- openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c | 14 ++++++++++++-- openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h | 2 ++ openair2/SDAP/nr_sdap/nr_sdap_entity.c | 17 ++++++++++++----- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.c b/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.c index e632fb2024..326ed49686 100644 --- a/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.c +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.c @@ -176,14 +176,19 @@ static void nr_pdcp_entity_recv_pdu(nr_pdcp_entity_t *entity, } } -static void nr_pdcp_entity_recv_sdu(nr_pdcp_entity_t *entity, - char *buffer, int size, int sdu_id) +static int nr_pdcp_entity_process_sdu(nr_pdcp_entity_t *entity, + char *buffer, + int size, + int sdu_id, + char *pdu_buffer, + int pdu_max_size) { uint32_t count; int sn; int header_size; int integrity_size; - char buf[size + 3 + 4]; + char *buf = pdu_buffer; + DevAssert(size + 3 + 4 <= pdu_max_size); int dc_bit; entity->stats.rxsdu_pkts++; entity->stats.rxsdu_bytes += size; @@ -243,13 +248,11 @@ static void nr_pdcp_entity_recv_sdu(nr_pdcp_entity_t *entity, entity->tx_next++; - entity->deliver_pdu(entity->deliver_pdu_data, entity, buf, - header_size + size + integrity_size, sdu_id); entity->stats.txpdu_pkts++; entity->stats.txpdu_bytes += header_size + size + integrity_size; entity->stats.txpdu_sn = sn; - + return header_size + size + integrity_size; } /* may be called several times, take care to clean previous settings */ @@ -420,7 +423,7 @@ nr_pdcp_entity_t *new_nr_pdcp_entity( ret->type = type; ret->recv_pdu = nr_pdcp_entity_recv_pdu; - ret->recv_sdu = nr_pdcp_entity_recv_sdu; + ret->process_sdu = nr_pdcp_entity_process_sdu; ret->set_security = nr_pdcp_entity_set_security; ret->set_time = nr_pdcp_entity_set_time; diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.h b/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.h index 4ad2508e4a..c693ed81d4 100644 --- a/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.h +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.h @@ -73,8 +73,8 @@ typedef struct nr_pdcp_entity_t { /* functions provided by the PDCP module */ void (*recv_pdu)(struct nr_pdcp_entity_t *entity, char *buffer, int size); - void (*recv_sdu)(struct nr_pdcp_entity_t *entity, char *buffer, int size, - int sdu_id); + int (*process_sdu)(struct nr_pdcp_entity_t *entity, char *buffer, int size, + int sdu_id, char *pdu_buffer, int pdu_max_size); void (*delete_entity)(struct nr_pdcp_entity_t *entity); void (*get_stats)(struct nr_pdcp_entity_t *entity, nr_pdcp_statistics_t *out); diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c index a91f4e883f..412b348302 100644 --- a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c @@ -1173,10 +1173,15 @@ bool nr_pdcp_data_req_srb(ue_id_t ue_id, return 0; } - rb->recv_sdu(rb, (char *)sdu_buffer, sdu_buffer_size, muiP); + int max_size = sdu_buffer_size + 3 + 4; // 3: max header, 4: max integrity + char pdu_buf[max_size]; + int pdu_size = rb->process_sdu(rb, (char *)sdu_buffer, sdu_buffer_size, muiP, pdu_buf, max_size); + deliver_pdu deliver_pdu_cb = rb->deliver_pdu; nr_pdcp_manager_unlock(nr_pdcp_ue_manager); + deliver_pdu_cb(rb->deliver_pdu_data, rb, pdu_buf, pdu_size, muiP); + return 1; } @@ -1223,10 +1228,15 @@ bool nr_pdcp_data_req_drb(protocol_ctxt_t *ctxt_pP, return 0; } - rb->recv_sdu(rb, (char *)sdu_buffer, sdu_buffer_size, muiP); + int max_size = sdu_buffer_size + 3 + 4; // 3: max header, 4: max integrity + char pdu_buf[max_size]; + int pdu_size = rb->process_sdu(rb, (char *)sdu_buffer, sdu_buffer_size, muiP, pdu_buf, max_size); + deliver_pdu deliver_pdu_cb = rb->deliver_pdu; nr_pdcp_manager_unlock(nr_pdcp_ue_manager); + deliver_pdu_cb(rb->deliver_pdu_data, rb, pdu_buf, pdu_size, muiP); + return 1; } diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h index 1b69b9d2e7..84b918529f 100644 --- a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h @@ -77,6 +77,8 @@ bool cu_f1u_data_req(protocol_ctxt_t *ctxt_pP, const uint32_t *const sourceL2Id, const uint32_t *const destinationL2Id); +typedef void (*deliver_pdu)(void *data, nr_pdcp_entity_t *entity, + char *buf, int size, int sdu_id); bool nr_pdcp_data_req_srb(ue_id_t ue_id, const rb_id_t rb_id, const mui_t muiP, diff --git a/openair2/SDAP/nr_sdap/nr_sdap_entity.c b/openair2/SDAP/nr_sdap/nr_sdap_entity.c index 357bec24ad..e81490630c 100644 --- a/openair2/SDAP/nr_sdap/nr_sdap_entity.c +++ b/openair2/SDAP/nr_sdap/nr_sdap_entity.c @@ -39,11 +39,18 @@ instance_t *N3GTPUInst = NULL; void nr_pdcp_submit_sdap_ctrl_pdu(ue_id_t ue_id, rb_id_t sdap_ctrl_pdu_drb, nr_sdap_ul_hdr_t ctrl_pdu) { - nr_pdcp_ue_t *ue; - nr_pdcp_ue_manager_t *nr_pdcp_ue_manager; - nr_pdcp_ue_manager = nr_pdcp_sdap_get_ue_manager(); - ue = nr_pdcp_manager_get_ue(nr_pdcp_ue_manager, ue_id); - ue->drb[sdap_ctrl_pdu_drb-1]->recv_sdu(ue->drb[sdap_ctrl_pdu_drb-1], (char*)&ctrl_pdu, SDAP_HDR_LENGTH, RLC_MUI_UNDEFINED); + + protocol_ctxt_t ctxt = { .rntiMaybeUEid = ue_id }; + nr_pdcp_data_req_drb(&ctxt, + SRB_FLAG_NO, + sdap_ctrl_pdu_drb, + RLC_MUI_UNDEFINED, + SDU_CONFIRM_NO, + SDAP_HDR_LENGTH, + (unsigned char *)&ctrl_pdu, + PDCP_TRANSMISSION_MODE_UNKNOWN, + NULL, + NULL); LOG_D(SDAP, "Control PDU - Submitting Control PDU to DRB ID: %ld\n", sdap_ctrl_pdu_drb); LOG_D(SDAP, "QFI: %u\n R: %u\n D/C: %u\n", ctrl_pdu.QFI, ctrl_pdu.R, ctrl_pdu.DC); return; From ffebe2498d1877be324375cd3ab1c995a0d9583f Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Mon, 20 Mar 2023 11:44:15 +0100 Subject: [PATCH 5/7] Simplify callback for deliver_pdu --- openair2/LAYER2/nr_pdcp/nr_pdcp_entity.c | 2 +- openair2/LAYER2/nr_pdcp/nr_pdcp_entity.h | 4 +- openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c | 65 +++++------------------ openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h | 2 +- 4 files changed, 16 insertions(+), 57 deletions(-) diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.c b/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.c index 326ed49686..b503fcc010 100644 --- a/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.c +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.c @@ -401,7 +401,7 @@ nr_pdcp_entity_t *new_nr_pdcp_entity( void (*deliver_sdu)(void *deliver_sdu_data, struct nr_pdcp_entity_t *entity, char *buf, int size), void *deliver_sdu_data, - void (*deliver_pdu)(void *deliver_pdu_data, struct nr_pdcp_entity_t *entity, + void (*deliver_pdu)(void *deliver_pdu_data, ue_id_t ue_id, int rb_id, char *buf, int size, int sdu_id), void *deliver_pdu_data, int sn_size, diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.h b/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.h index c693ed81d4..762c91c747 100644 --- a/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.h +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_entity.h @@ -95,7 +95,7 @@ typedef struct nr_pdcp_entity_t { void (*deliver_sdu)(void *deliver_sdu_data, struct nr_pdcp_entity_t *entity, char *buf, int size); void *deliver_sdu_data; - void (*deliver_pdu)(void *deliver_pdu_data, struct nr_pdcp_entity_t *entity, + void (*deliver_pdu)(void *deliver_pdu_data, ue_id_t ue_id, int rb_id, char *buf, int size, int sdu_id); void *deliver_pdu_data; @@ -176,7 +176,7 @@ nr_pdcp_entity_t *new_nr_pdcp_entity( void (*deliver_sdu)(void *deliver_sdu_data, struct nr_pdcp_entity_t *entity, char *buf, int size), void *deliver_sdu_data, - void (*deliver_pdu)(void *deliver_pdu_data, struct nr_pdcp_entity_t *entity, + void (*deliver_pdu)(void *deliver_pdu_data, ue_id_t ue_id, int rb_id, char *buf, int size, int sdu_id), void *deliver_pdu_data, int sn_size, diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c index 412b348302..e27fb2b25a 100644 --- a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c @@ -653,35 +653,12 @@ static void deliver_sdu_drb(void *_ue, nr_pdcp_entity_t *entity, } } -static void deliver_pdu_drb(void *_ue, nr_pdcp_entity_t *entity, +static void deliver_pdu_drb(void *deliver_pdu_data, ue_id_t ue_id, int rb_id, char *buf, int size, int sdu_id) { - nr_pdcp_ue_t *ue = _ue; - int rb_id; - protocol_ctxt_t ctxt; - int i; - mem_block_t *memblock; + DevAssert(deliver_pdu_data == NULL); + protocol_ctxt_t ctxt = { .enb_flag = 1, .rntiMaybeUEid = ue_id }; - for (i = 0; i < MAX_DRBS_PER_UE; i++) { - if (entity == ue->drb[i]) { - rb_id = i+1; - goto rb_found; - } - } - - LOG_E(PDCP, "%s:%d:%s: fatal, no RB found for UE ID/RNTI %ld\n", __FILE__, __LINE__, __FUNCTION__, ue->rntiMaybeUEid); - exit(1); - -rb_found: - ctxt.module_id = 0; - ctxt.enb_flag = 1; - ctxt.instance = 0; - ctxt.frame = 0; - ctxt.subframe = 0; - ctxt.eNB_index = 0; - ctxt.brOption = 0; - - ctxt.rntiMaybeUEid = ue->rntiMaybeUEid; if (NODE_IS_CU(node_type)) { MessageDef *message_p = itti_alloc_new_message_sized(TASK_PDCP_ENB, 0, GTPV1U_TUNNEL_DATA_REQ, @@ -696,14 +673,14 @@ rb_found: req->buffer = gtpu_buffer_p; req->length = size; req->offset = GTPU_HEADER_OVERHEAD_MAX; - req->ue_id = ue->rntiMaybeUEid; + req->ue_id = ue_id; req->bearer_id = rb_id; LOG_I(PDCP, "%s() (drb %d) sending message to gtp size %d\n", __func__, rb_id, size); extern instance_t CUuniqInstance; itti_send_msg_to_task(TASK_GTPV1_U, CUuniqInstance, message_p); } else { - memblock = get_free_mem_block(size, __FUNCTION__); + mem_block_t *memblock = get_free_mem_block(size, __FUNCTION__); memcpy(memblock->data, buf, size); LOG_D(PDCP, "%s(): (drb %d) calling rlc_data_req size %d\n", __func__, rb_id, size); //for (i = 0; i < size; i++) printf(" %2.2x", (unsigned char)memblock->data[i]); @@ -755,40 +732,22 @@ srb_found: } } -static void deliver_pdu_srb(void *_ue, nr_pdcp_entity_t *entity, +static void deliver_pdu_srb(void *deliver_pdu_data, ue_id_t ue_id, int srb_id, char *buf, int size, int sdu_id) { - nr_pdcp_ue_t *ue = _ue; - int srb_id; - int i; - - for (i = 0; i < sizeofArray(ue->srb) ; i++) { - if (entity == ue->srb[i]) { - srb_id = i+1; - goto srb_found; - } - } - - LOG_E(PDCP, "%s:%d:%s: fatal, no SRB found for UE ID/RNTI %ld\n", __FILE__, __LINE__, __FUNCTION__, ue->rntiMaybeUEid); - exit(1); - -srb_found: - - + bool is_gnb = *(bool *) deliver_pdu_data; LOG_D(PDCP, "%s(): (srb %d) calling rlc_data_req size %d\n", __func__, srb_id, size); - //for (i = 0; i < size; i++) printf(" %2.2x", (unsigned char)memblock->data[i]); - //printf("\n"); - if (entity->is_gnb) { + if (is_gnb) { f1ap_dl_rrc_message_t dl_rrc = {.old_gNB_DU_ue_id = 0xFFFFFF, .rrc_container = (uint8_t *)buf, .rrc_container_length = size, - .rnti = ue->rntiMaybeUEid, + .rnti = ue_id, .srb_id = srb_id}; gNB_RRC_INST *rrc = RC.nrrrc[0]; rrc->mac_rrc.dl_rrc_message_transfer(0, &dl_rrc); } else { // UE mem_block_t *memblock; - protocol_ctxt_t ctxt = {.module_id = 0, .enb_flag = 1, .instance = 0, .frame = 0, .subframe = 0, .eNB_index = 0, .brOption = 0, .rntiMaybeUEid = ue->rntiMaybeUEid}; + protocol_ctxt_t ctxt = { .enb_flag = 1, .rntiMaybeUEid = ue_id }; memblock = get_free_mem_block(size, __FUNCTION__); memcpy(memblock->data, buf, size); enqueue_rlc_data_req(&ctxt, 1, MBMS_FLAG_NO, srb_id, sdu_id, 0, size, memblock); @@ -1180,7 +1139,7 @@ bool nr_pdcp_data_req_srb(ue_id_t ue_id, nr_pdcp_manager_unlock(nr_pdcp_ue_manager); - deliver_pdu_cb(rb->deliver_pdu_data, rb, pdu_buf, pdu_size, muiP); + deliver_pdu_cb(&rb->is_gnb, ue_id, rb_id, pdu_buf, pdu_size, muiP); return 1; } @@ -1235,7 +1194,7 @@ bool nr_pdcp_data_req_drb(protocol_ctxt_t *ctxt_pP, nr_pdcp_manager_unlock(nr_pdcp_ue_manager); - deliver_pdu_cb(rb->deliver_pdu_data, rb, pdu_buf, pdu_size, muiP); + deliver_pdu_cb(NULL, ue_id, rb_id, pdu_buf, pdu_size, muiP); return 1; } diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h index 84b918529f..51c3e95cf5 100644 --- a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h @@ -77,7 +77,7 @@ bool cu_f1u_data_req(protocol_ctxt_t *ctxt_pP, const uint32_t *const sourceL2Id, const uint32_t *const destinationL2Id); -typedef void (*deliver_pdu)(void *data, nr_pdcp_entity_t *entity, +typedef void (*deliver_pdu)(void *data, ue_id_t ue_id, int srb_id, char *buf, int size, int sdu_id); bool nr_pdcp_data_req_srb(ue_id_t ue_id, const rb_id_t rb_id, From 6529d875d8ab45a6d901891e80b28ffc2c6f2398 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Wed, 22 Mar 2023 16:44:51 +0100 Subject: [PATCH 6/7] nr_pdcp_data_req_srb(): take callback to forward data --- openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c | 48 ++++++++++++----------- openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h | 9 ++++- openair2/RRC/NR/rrc_gNB.c | 38 ++++++++++-------- openair2/RRC/NR/rrc_gNB_NGAP.c | 2 +- openair2/RRC/NR_UE/rrc_UE.c | 10 ++--- 5 files changed, 60 insertions(+), 47 deletions(-) diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c index e27fb2b25a..efbb638a7e 100644 --- a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.c @@ -732,26 +732,26 @@ srb_found: } } -static void deliver_pdu_srb(void *deliver_pdu_data, ue_id_t ue_id, int srb_id, - char *buf, int size, int sdu_id) +void deliver_pdu_srb_rlc(void *deliver_pdu_data, ue_id_t ue_id, int srb_id, + char *buf, int size, int sdu_id) { - bool is_gnb = *(bool *) deliver_pdu_data; - LOG_D(PDCP, "%s(): (srb %d) calling rlc_data_req size %d\n", __func__, srb_id, size); - if (is_gnb) { - f1ap_dl_rrc_message_t dl_rrc = {.old_gNB_DU_ue_id = 0xFFFFFF, - .rrc_container = (uint8_t *)buf, - .rrc_container_length = size, - .rnti = ue_id, - .srb_id = srb_id}; - gNB_RRC_INST *rrc = RC.nrrrc[0]; - rrc->mac_rrc.dl_rrc_message_transfer(0, &dl_rrc); - } else { // UE - mem_block_t *memblock; - protocol_ctxt_t ctxt = { .enb_flag = 1, .rntiMaybeUEid = ue_id }; - memblock = get_free_mem_block(size, __FUNCTION__); - memcpy(memblock->data, buf, size); - enqueue_rlc_data_req(&ctxt, 1, MBMS_FLAG_NO, srb_id, sdu_id, 0, size, memblock); - } + protocol_ctxt_t ctxt = { .enb_flag = 1, .rntiMaybeUEid = ue_id }; + mem_block_t *memblock = get_free_mem_block(size, __FUNCTION__); + memcpy(memblock->data, buf, size); + enqueue_rlc_data_req(&ctxt, 1, MBMS_FLAG_NO, srb_id, sdu_id, 0, size, memblock); +} + +void deliver_pdu_srb_f1(void *deliver_pdu_data, ue_id_t ue_id, int srb_id, + char *buf, int size, int sdu_id) +{ + DevAssert(deliver_pdu_data != NULL); + gNB_RRC_INST *rrc = deliver_pdu_data; + f1ap_dl_rrc_message_t dl_rrc = {.old_gNB_DU_ue_id = 0xFFFFFF, + .rrc_container = (uint8_t *)buf, + .rrc_container_length = size, + .rnti = ue_id, + .srb_id = srb_id}; + rrc->mac_rrc.dl_rrc_message_transfer(0, &dl_rrc); } static void add_srb(int is_gnb, ue_id_t rntiMaybeUEid, struct NR_SRB_ToAddMod *s, int ciphering_algorithm, int integrity_algorithm, unsigned char *ciphering_key, unsigned char *integrity_key) @@ -772,7 +772,7 @@ static void add_srb(int is_gnb, ue_id_t rntiMaybeUEid, struct NR_SRB_ToAddMod *s } else { pdcp_srb = new_nr_pdcp_entity(NR_PDCP_SRB, is_gnb, srb_id, 0, false, false, // sdap parameters - deliver_sdu_srb, ue, deliver_pdu_srb, ue, + deliver_sdu_srb, ue, NULL, ue, 12, t_Reordering, -1, ciphering_algorithm, integrity_algorithm, @@ -1111,7 +1111,9 @@ bool nr_pdcp_data_req_srb(ue_id_t ue_id, const rb_id_t rb_id, const mui_t muiP, const sdu_size_t sdu_buffer_size, - unsigned char *const sdu_buffer) + unsigned char *const sdu_buffer, + deliver_pdu deliver_pdu_cb, + void *data) { LOG_D(PDCP, "%s() called, size %d\n", __func__, sdu_buffer_size); nr_pdcp_ue_t *ue; @@ -1135,11 +1137,11 @@ bool nr_pdcp_data_req_srb(ue_id_t ue_id, int max_size = sdu_buffer_size + 3 + 4; // 3: max header, 4: max integrity char pdu_buf[max_size]; int pdu_size = rb->process_sdu(rb, (char *)sdu_buffer, sdu_buffer_size, muiP, pdu_buf, max_size); - deliver_pdu deliver_pdu_cb = rb->deliver_pdu; + AssertFatal(rb->deliver_pdu == NULL, "SRB callback should be NULL, to be provided on every invocation\n"); nr_pdcp_manager_unlock(nr_pdcp_ue_manager); - deliver_pdu_cb(&rb->is_gnb, ue_id, rb_id, pdu_buf, pdu_size, muiP); + deliver_pdu_cb(data, ue_id, rb_id, pdu_buf, pdu_size, muiP); return 1; } diff --git a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h index 51c3e95cf5..0fd23d2f6b 100644 --- a/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h +++ b/openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h @@ -79,11 +79,18 @@ bool cu_f1u_data_req(protocol_ctxt_t *ctxt_pP, typedef void (*deliver_pdu)(void *data, ue_id_t ue_id, int srb_id, char *buf, int size, int sdu_id); +/* default implementation of deliver_pdu */ +void deliver_pdu_srb_rlc(void *data, ue_id_t ue_id, int srb_id, char *buf, + int size, int sdu_id); +void deliver_pdu_srb_f1(void *data, ue_id_t ue_id, int srb_id, char *buf, + int size, int sdu_id); bool nr_pdcp_data_req_srb(ue_id_t ue_id, const rb_id_t rb_id, const mui_t muiP, const sdu_size_t sdu_buffer_size, - unsigned char *const sdu_buffer); + unsigned char *const sdu_buffer, + deliver_pdu deliver_cb, + void *data); bool nr_pdcp_data_req_drb(protocol_ctxt_t *ctxt_pP, const srb_flag_t srb_flagP, const rb_id_t rb_id, diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c index b51d4563da..2af5e620f6 100644 --- a/openair2/RRC/NR/rrc_gNB.c +++ b/openair2/RRC/NR/rrc_gNB.c @@ -573,7 +573,7 @@ static void rrc_gNB_generate_defaultRRCReconfiguration(const protocol_ctxt_t *co ue_context_pP->ue_context.rnti); AssertFatal(!NODE_IS_DU(rrc->node_type), "illegal node type DU!\n"); - nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer, deliver_pdu_srb_f1, rrc); if (NODE_IS_DU(rrc->node_type) || NODE_IS_MONOLITHIC(rrc->node_type)) { gNB_RRC_UE_t *ue_p = &ue_context_pP->ue_context; @@ -762,7 +762,7 @@ rrc_gNB_generate_dedicatedRRCReconfiguration( ctxt_pP->module_id, DCCH); - nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer, deliver_pdu_srb_f1, rrc); if (NODE_IS_DU(rrc->node_type) || NODE_IS_MONOLITHIC(rrc->node_type)) { nr_mac_update_cellgroup(RC.nrmac[rrc->module_id], ue_context_pP->ue_context.rnti, ue_context_pP->ue_context.masterCellGroup); @@ -929,15 +929,16 @@ rrc_gNB_modify_dedicatedRRCReconfiguration( ctxt_pP->module_id, DCCH); - nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); + gNB_RRC_INST *rrc = RC.nrrrc[ctxt_pP->module_id]; + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer, deliver_pdu_srb_f1, rrc); - if (NODE_IS_DU(RC.nrrrc[ctxt_pP->module_id]->node_type) || NODE_IS_MONOLITHIC(RC.nrrrc[ctxt_pP->module_id]->node_type)) { + if (NODE_IS_DU(rrc->node_type) || NODE_IS_MONOLITHIC(rrc->node_type)) { uint32_t delay_ms = ue_p->masterCellGroup && ue_p->masterCellGroup->spCellConfig && ue_p->masterCellGroup->spCellConfig->spCellConfigDedicated && ue_p->masterCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList ? NR_RRC_RECONFIGURATION_DELAY_MS + NR_RRC_BWP_SWITCHING_DELAY_MS : NR_RRC_RECONFIGURATION_DELAY_MS; - nr_mac_enable_ue_rrc_processing_timer(ctxt_pP->module_id, ue_p->rnti, *RC.nrrrc[ctxt_pP->module_id]->carrier.servingcellconfigcommon->ssbSubcarrierSpacing, delay_ms); + nr_mac_enable_ue_rrc_processing_timer(ctxt_pP->module_id, ue_p->rnti, *rrc->carrier.servingcellconfigcommon->ssbSubcarrierSpacing, delay_ms); } } @@ -1013,15 +1014,16 @@ rrc_gNB_generate_dedicatedRRCReconfiguration_release( ctxt_pP->module_id, DCCH); - nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); + gNB_RRC_INST *rrc = RC.nrrrc[ctxt_pP->module_id]; + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer, deliver_pdu_srb_f1, rrc); - if (NODE_IS_DU(RC.nrrrc[ctxt_pP->module_id]->node_type) || NODE_IS_MONOLITHIC(RC.nrrrc[ctxt_pP->module_id]->node_type)) { + if (NODE_IS_DU(rrc->node_type) || NODE_IS_MONOLITHIC(rrc->node_type)) { uint32_t delay_ms = ue_p->masterCellGroup && ue_p->masterCellGroup->spCellConfig && ue_p->masterCellGroup->spCellConfig->spCellConfigDedicated && ue_p->masterCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList ? NR_RRC_RECONFIGURATION_DELAY_MS + NR_RRC_BWP_SWITCHING_DELAY_MS : NR_RRC_RECONFIGURATION_DELAY_MS; - nr_mac_enable_ue_rrc_processing_timer(ctxt_pP->module_id, ue_p->rnti, *RC.nrrrc[ctxt_pP->module_id]->carrier.servingcellconfigcommon->ssbSubcarrierSpacing, delay_ms); + nr_mac_enable_ue_rrc_processing_timer(ctxt_pP->module_id, ue_p->rnti, *rrc->carrier.servingcellconfigcommon->ssbSubcarrierSpacing, delay_ms); } } @@ -1274,7 +1276,7 @@ void rrc_gNB_generate_RRCReestablishment(const protocol_ctxt_t *ctxt_pP, apply_macrlc_config_reest(rrc, ue_context_pP, ctxt_pP, ctxt_pP->rntiMaybeUEid); } - nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer, deliver_pdu_srb_f1, rrc); } //----------------------------------------------------------------------------- @@ -1487,7 +1489,7 @@ cellGroupConfig->physicalCellGroupConfig = ue_p->masterCellGroup->physicalCellGr DCCH); nr_mac_update_cellgroup(RC.nrmac[rrc->module_id], ue_context_pP->ue_context.rnti, cellGroupConfig); - nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer, deliver_pdu_srb_f1, rrc); } if (NODE_IS_DU(RC.nrrrc[ctxt_pP->module_id]->node_type) || NODE_IS_MONOLITHIC(RC.nrrrc[ctxt_pP->module_id]->node_type)) { @@ -1538,15 +1540,16 @@ int nr_rrc_reconfiguration_req(rrc_gNB_ue_context_t *const ue_context_pP nr_mac_update_cellgroup(RC.nrmac[ctxt_pP->module_id], ue_context_pP->ue_context.rnti, masterCellGroup); - nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); + gNB_RRC_INST *rrc = RC.nrrrc[ctxt_pP->module_id]; + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer, deliver_pdu_srb_f1, rrc); - if (NODE_IS_DU(RC.nrrrc[ctxt_pP->module_id]->node_type) || NODE_IS_MONOLITHIC(RC.nrrrc[ctxt_pP->module_id]->node_type)) { + if (NODE_IS_DU(rrc->node_type) || NODE_IS_MONOLITHIC(rrc->node_type)) { uint32_t delay_ms = ue_p->masterCellGroup && ue_p->masterCellGroup->spCellConfig && ue_p->masterCellGroup->spCellConfig->spCellConfigDedicated && ue_p->masterCellGroup->spCellConfig->spCellConfigDedicated->downlinkBWP_ToAddModList ? NR_RRC_RECONFIGURATION_DELAY_MS + NR_RRC_BWP_SWITCHING_DELAY_MS : NR_RRC_RECONFIGURATION_DELAY_MS; - nr_mac_enable_ue_rrc_processing_timer(ctxt_pP->module_id, ue_p->rnti, *RC.nrrrc[ctxt_pP->module_id]->carrier.servingcellconfigcommon->ssbSubcarrierSpacing, delay_ms); + nr_mac_enable_ue_rrc_processing_timer(ctxt_pP->module_id, ue_p->rnti, *rrc->carrier.servingcellconfigcommon->ssbSubcarrierSpacing, delay_ms); } return 0; @@ -3589,7 +3592,7 @@ rrc_gNB_generate_SecurityModeCommand( gNB_RRC_INST *rrc = RC.nrrrc[ctxt_pP->module_id]; AssertFatal(!NODE_IS_DU(rrc->node_type), "illegal node type DU!\n"); - nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer, deliver_pdu_srb_f1, rrc); } void @@ -3615,7 +3618,7 @@ rrc_gNB_generate_UECapabilityEnquiry( gNB_RRC_INST *rrc = RC.nrrrc[ctxt_pP->module_id]; AssertFatal(!NODE_IS_DU(rrc->node_type), "illegal node type DU!\n"); - nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer, deliver_pdu_srb_f1, rrc); } //----------------------------------------------------------------------------- @@ -3649,12 +3652,13 @@ rrc_gNB_generate_RRCRelease( rrc_gNB_mui, DCCH); - nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer); + gNB_RRC_INST *rrc = RC.nrrrc[ctxt_pP->module_id]; + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, rrc_gNB_mui++, size, buffer, deliver_pdu_srb_f1, rrc); rrc_gNB_send_NGAP_UE_CONTEXT_RELEASE_COMPLETE(ctxt_pP->instance, ue_context_pP->ue_context.gNB_ue_ngap_id); ue_context_pP->ue_context.ue_release_timer_rrc = 1; - if (NODE_IS_CU(RC.nrrrc[ctxt_pP->module_id]->node_type)) { + if (NODE_IS_CU(rrc->node_type)) { uint8_t *message_buffer = itti_malloc (TASK_RRC_GNB, TASK_CU_F1, size); memcpy (message_buffer, buffer, size); MessageDef *m = itti_alloc_new_message(TASK_RRC_GNB, 0, F1AP_UE_CONTEXT_RELEASE_CMD); diff --git a/openair2/RRC/NR/rrc_gNB_NGAP.c b/openair2/RRC/NR/rrc_gNB_NGAP.c index 2120d25920..d38846e9ee 100644 --- a/openair2/RRC/NR/rrc_gNB_NGAP.c +++ b/openair2/RRC/NR/rrc_gNB_NGAP.c @@ -620,7 +620,7 @@ int rrc_gNB_process_NGAP_DOWNLINK_NAS(MessageDef *msg_p, instance_t instance, mu AssertFatal(!NODE_IS_DU(RC.nrrrc[ctxt.module_id]->node_type), "illegal node type DU: receiving NGAP messages at this node\n"); /* Transfer data to PDCP */ rb_id_t srb_id = UE->Srb[2].Active ? DCCH1 : DCCH; - nr_pdcp_data_req_srb(ctxt.rntiMaybeUEid, srb_id, (*rrc_gNB_mui)++, length, buffer); + nr_pdcp_data_req_srb(ctxt.rntiMaybeUEid, srb_id, (*rrc_gNB_mui)++, length, buffer, deliver_pdu_srb_f1, RC.nrrrc[instance]); return 0; } diff --git a/openair2/RRC/NR_UE/rrc_UE.c b/openair2/RRC/NR_UE/rrc_UE.c index 27390a1b51..87f5426b94 100644 --- a/openair2/RRC/NR_UE/rrc_UE.c +++ b/openair2/RRC/NR_UE/rrc_UE.c @@ -1386,7 +1386,7 @@ static void rrc_ue_generate_RRCSetupComplete( //for (int i=0;irntiMaybeUEid, DCCH, nr_rrc_mui++, size, buffer); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, nr_rrc_mui++, size, buffer, deliver_pdu_srb_rlc, NULL); } int8_t nr_rrc_ue_decode_ccch( const protocol_ctxt_t *const ctxt_pP, const NR_SRB_INFO *const Srb_info, const uint8_t gNB_index ){ @@ -1691,7 +1691,7 @@ int8_t nr_rrc_ue_decode_ccch( const protocol_ctxt_t *const ctxt_pP, const NR_SRB } LOG_T(NR_RRC, "\n"); - nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, nr_rrc_mui++, (enc_rval.encoded + 7) / 8, buffer); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, nr_rrc_mui++, (enc_rval.encoded + 7) / 8, buffer, deliver_pdu_srb_rlc, NULL); } else LOG_W(NR_RRC,"securityModeCommand->criticalExtensions.present (%d) != NR_SecurityModeCommand__criticalExtensions_PR_securityModeCommand\n", securityModeCommand->criticalExtensions.present); @@ -2177,7 +2177,7 @@ nr_rrc_ue_establish_srb2( nr_rrc_mui, UE_MODULE_ID_TO_INSTANCE(ctxt_pP->module_id), DCCH); - nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, nr_rrc_mui++, size, buffer); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, nr_rrc_mui++, size, buffer, deliver_pdu_srb_rlc, NULL); } // from NR SRB1 @@ -2427,7 +2427,7 @@ nr_rrc_ue_establish_srb2( PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, ue_mod_id, GNB_FLAG_NO, NR_UE_rrc_inst[ue_mod_id].Info[0].rnti, 0, 0,0); // check if SRB2 is created, if yes request data_req on DCCH1 (SRB2) rb_id_t srb_id = NR_UE_rrc_inst[ue_mod_id].SRB2_config[0] == NULL ? DCCH : DCCH1; - nr_pdcp_data_req_srb(ctxt.rntiMaybeUEid, srb_id, nr_rrc_mui++, length, buffer); + nr_pdcp_data_req_srb(ctxt.rntiMaybeUEid, srb_id, nr_rrc_mui++, length, buffer, deliver_pdu_srb_rlc, NULL); break; } @@ -2571,7 +2571,7 @@ nr_rrc_ue_process_ueCapabilityEnquiry( } LOG_I(NR_RRC, "UECapabilityInformation Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8); - nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, nr_rrc_mui++, (enc_rval.encoded + 7) / 8, buffer); + nr_pdcp_data_req_srb(ctxt_pP->rntiMaybeUEid, DCCH, nr_rrc_mui++, (enc_rval.encoded + 7) / 8, buffer, deliver_pdu_srb_rlc, NULL); } } } From d1fc95a8a14b9cd09968872037f9c0cd3941b204 Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Fri, 31 Mar 2023 11:53:50 +0200 Subject: [PATCH 7/7] GTP: when creating a tunnel, tell which functions to use The GTP module is common for 4G and 5G. It hardcodes the functions to call when creating S1U and NGU tunnels. The S1U case is both applicable for LTE and NR (NSA), which until now was not a problem as the PDCP data forwarding functions where called pdcp_data_req. The issue is that in this branch, the NR PDCP functions have changed to nr_pdcp_data_req_drb(). When setting up a GTP tunnel, we now pass the PDCP data forwarding functions into GTP, since the caller knows whether it is in 4G or 5G, but GTP itself does not. --- openair2/E1AP/e1ap_api.c | 4 +--- openair2/RRC/LTE/rrc_eNB_S1AP.c | 20 ++++---------------- openair2/RRC/NR/cucp_cuup_direct.c | 6 +++++- openair2/RRC/NR/rrc_gNB_NGAP.c | 3 ++- openair2/RRC/NR/rrc_gNB_nsa.c | 5 +---- openair3/ocp-gtpu/gtp_itf.cpp | 25 +++++++++++++++---------- openair3/ocp-gtpu/gtp_itf.h | 18 ++++++++++-------- 7 files changed, 38 insertions(+), 43 deletions(-) diff --git a/openair2/E1AP/e1ap_api.c b/openair2/E1AP/e1ap_api.c index 23a9fcd1ea..b67525acca 100644 --- a/openair2/E1AP/e1ap_api.c +++ b/openair2/E1AP/e1ap_api.c @@ -112,9 +112,7 @@ static int drb_config_N3gtpu_create(e1ap_bearer_setup_req_t * const req, create_tunnel_req.ue_id = (req->gNB_cu_cp_ue_id & 0xFFFF); // Create N3 tunnel - int ret = gtpv1u_create_ngu_tunnel(instance, - &create_tunnel_req, - create_tunnel_resp); + int ret = gtpv1u_create_ngu_tunnel(instance, &create_tunnel_req, create_tunnel_resp, nr_pdcp_data_req_drb, sdap_data_req); if (ret != 0) { LOG_E(NR_RRC,"rrc_gNB_process_NGAP_PDUSESSION_SETUP_REQ : gtpv1u_create_ngu_tunnel failed,start to release UE id %ld\n", create_tunnel_req.ue_id); diff --git a/openair2/RRC/LTE/rrc_eNB_S1AP.c b/openair2/RRC/LTE/rrc_eNB_S1AP.c index fbc19d0a47..bc4fc6d8cd 100644 --- a/openair2/RRC/LTE/rrc_eNB_S1AP.c +++ b/openair2/RRC/LTE/rrc_eNB_S1AP.c @@ -921,10 +921,7 @@ int rrc_eNB_process_S1AP_INITIAL_CONTEXT_SETUP_REQ(MessageDef *msg_p, const char create_tunnel_req.rnti = ue_context_p->ue_context.rnti; // warning put zero above // create_tunnel_req.num_tunnels = i; - ret = gtpv1u_create_s1u_tunnel( - instance, - &create_tunnel_req, - &create_tunnel_resp); + ret = gtpv1u_create_s1u_tunnel(instance, &create_tunnel_req, &create_tunnel_resp, pdcp_data_req); if ( ret != 0 ) { LOG_E(RRC,"rrc_eNB_process_S1AP_INITIAL_CONTEXT_SETUP_REQ : gtpv1u_create_s1u_tunnel failed,start to release UE %x\n",ue_context_p->ue_context.rnti); @@ -1234,10 +1231,7 @@ int rrc_eNB_process_S1AP_E_RAB_SETUP_REQ(MessageDef *msg_p, const char *msg_name create_tunnel_req.rnti = ue_context_p->ue_context.rnti; // warning put zero above create_tunnel_req.num_tunnels = e_rab_done; // NN: not sure if we should create a new tunnel: need to check teid, etc. - ret = gtpv1u_create_s1u_tunnel( - instance, - &create_tunnel_req, - &create_tunnel_resp); + ret = gtpv1u_create_s1u_tunnel(instance, &create_tunnel_req, &create_tunnel_resp, pdcp_data_req); if ( ret != 0 ) { LOG_E(RRC,"rrc_eNB_process_S1AP_E_RAB_SETUP_REQ : gtpv1u_create_s1u_tunnel failed,start to release UE %x\n",ue_context_p->ue_context.rnti); @@ -1908,14 +1902,8 @@ int rrc_eNB_send_PATH_SWITCH_REQ(const protocol_ctxt_t *const ctxt_pP, S1AP_PATH_SWITCH_REQ (msg_p).nb_of_e_rabs = e_rabs_done; create_tunnel_req.rnti = ue_context_pP->ue_context.rnti; create_tunnel_req.num_tunnels = e_rabs_done; - gtpv1u_create_s1u_tunnel( - ctxt_pP->instance, - &create_tunnel_req, - &create_tunnel_resp); - rrc_eNB_process_GTPV1U_CREATE_TUNNEL_RESP( - ctxt_pP, - &create_tunnel_resp, - &inde_list[0]); + gtpv1u_create_s1u_tunnel(ctxt_pP->instance, &create_tunnel_req, &create_tunnel_resp, pdcp_data_req); + rrc_eNB_process_GTPV1U_CREATE_TUNNEL_RESP(ctxt_pP, &create_tunnel_resp, &inde_list[0]); for (e_rab = 0; e_rab < e_rabs_done; e_rab++) { S1AP_PATH_SWITCH_REQ (msg_p).e_rabs_tobeswitched[e_rab].e_rab_id = create_tunnel_resp.eps_bearer_id[e_rab]; diff --git a/openair2/RRC/NR/cucp_cuup_direct.c b/openair2/RRC/NR/cucp_cuup_direct.c index d2c35e2c03..05ec9a837b 100644 --- a/openair2/RRC/NR/cucp_cuup_direct.c +++ b/openair2/RRC/NR/cucp_cuup_direct.c @@ -120,7 +120,11 @@ static int drb_config_gtpu_create(const protocol_ctxt_t *const ctxt_p, } create_tunnel_req.num_tunnels = UE->nb_of_pdusessions; create_tunnel_req.ue_id = UE->rnti; - int ret = gtpv1u_create_ngu_tunnel(getCxtE1(instance)->gtpInstN3, &create_tunnel_req, &create_tunnel_resp); + int ret = gtpv1u_create_ngu_tunnel(getCxtE1(instance)->gtpInstN3, + &create_tunnel_req, + &create_tunnel_resp, + nr_pdcp_data_req_drb, + sdap_data_req); if (ret != 0) { LOG_E(NR_RRC,"rrc_gNB_process_NGAP_PDUSESSION_SETUP_REQ : gtpv1u_create_ngu_tunnel failed,start to release UE rnti %ld\n", diff --git a/openair2/RRC/NR/rrc_gNB_NGAP.c b/openair2/RRC/NR/rrc_gNB_NGAP.c index d38846e9ee..1f37210b9c 100644 --- a/openair2/RRC/NR/rrc_gNB_NGAP.c +++ b/openair2/RRC/NR/rrc_gNB_NGAP.c @@ -38,6 +38,7 @@ #include "intertask_interface.h" #include "nr_pdcp/nr_pdcp_oai_api.h" #include "pdcp_primitives.h" +#include "SDAP/nr_sdap/nr_sdap.h" #include "openair3/ocp-gtpu/gtp_itf.h" #include @@ -391,7 +392,7 @@ int rrc_gNB_process_NGAP_INITIAL_CONTEXT_SETUP_REQ(MessageDef *msg_p, instance_t } create_tunnel_req.ue_id = UE->rnti; gtpv1u_gnb_create_tunnel_resp_t create_tunnel_resp = {0}; - int ret = gtpv1u_create_ngu_tunnel(instance, &create_tunnel_req, &create_tunnel_resp); + int ret = gtpv1u_create_ngu_tunnel(instance, &create_tunnel_req, &create_tunnel_resp, nr_pdcp_data_req_drb, sdap_data_req); if (ret != 0) { LOG_E(NR_RRC, "rrc_gNB_process_NGAP_INITIAL_CONTEXT_SETUP_REQ : gtpv1u_create_ngu_tunnel failed,start to release UE %x\n", UE->rnti); UE->ue_release_timer_ng = 1; diff --git a/openair2/RRC/NR/rrc_gNB_nsa.c b/openair2/RRC/NR/rrc_gNB_nsa.c index 989c754c20..4b4e06fc0f 100644 --- a/openair2/RRC/NR/rrc_gNB_nsa.c +++ b/openair2/RRC/NR/rrc_gNB_nsa.c @@ -282,10 +282,7 @@ void rrc_add_nsa_user(gNB_RRC_INST *rrc, rrc_gNB_ue_context_t *ue_context_p, x2a memset(&create_tunnel_resp, 0, sizeof(create_tunnel_resp)); if (!IS_SOFTMODEM_NOS1) { LOG_D(RRC, "Calling gtpv1u_create_s1u_tunnel()\n"); - gtpv1u_create_s1u_tunnel( - ctxt.instance, - &create_tunnel_req, - &create_tunnel_resp); + gtpv1u_create_s1u_tunnel(ctxt.instance, &create_tunnel_req, &create_tunnel_resp, nr_pdcp_data_req_drb); rrc_gNB_process_GTPV1U_CREATE_TUNNEL_RESP( &ctxt, &create_tunnel_resp, diff --git a/openair3/ocp-gtpu/gtp_itf.cpp b/openair3/ocp-gtpu/gtp_itf.cpp index f6255fb056..d8e1dc2314 100644 --- a/openair3/ocp-gtpu/gtp_itf.cpp +++ b/openair3/ocp-gtpu/gtp_itf.cpp @@ -648,7 +648,9 @@ teid_t newGtpuCreateTunnel(instance_t instance, int gtpv1u_create_s1u_tunnel(instance_t instance, const gtpv1u_enb_create_tunnel_req_t *create_tunnel_req, - gtpv1u_enb_create_tunnel_resp_t *create_tunnel_resp) { + gtpv1u_enb_create_tunnel_resp_t *create_tunnel_resp, + gtpCallback callBack) +{ LOG_D(GTPU, "[%ld] Start create tunnels for UE ID %u, num_tunnels %d, sgw_S1u_teid %x\n", instance, create_tunnel_req->rnti, @@ -675,7 +677,7 @@ int gtpv1u_create_s1u_tunnel(instance_t instance, -1, // no pdu session in 4G create_tunnel_req->sgw_addr[i], dstport, - pdcp_data_req, + callBack, NULL); create_tunnel_resp->status=0; create_tunnel_resp->rnti=create_tunnel_req->rnti; @@ -712,10 +714,10 @@ int gtpv1u_update_s1u_tunnel( auto it=inst->ue2te_mapping.find(prior_rnti); if ( it != inst->ue2te_mapping.end() ) { - LOG_W(GTPU,"[%ld] Update a not existing tunnel, start create the new one (new ue id %u, old ue id %u)\n", instance, create_tunnel_req->rnti, prior_rnti); pthread_mutex_unlock(&globGtp.gtp_lock); - gtpv1u_enb_create_tunnel_resp_t tmp; - (void)gtpv1u_create_s1u_tunnel(instance, create_tunnel_req, &tmp); + AssertFatal(false, "logic bug: update of non-existing tunnel (new ue id %u, old ue id %u)\n", create_tunnel_req->rnti, prior_rnti); + /* we don't know if we need 4G or 5G PDCP and can therefore not create a + * new tunnel */ return 0; } @@ -725,9 +727,12 @@ int gtpv1u_update_s1u_tunnel( return 0; } -int gtpv1u_create_ngu_tunnel( const instance_t instance, - const gtpv1u_gnb_create_tunnel_req_t *const create_tunnel_req, - gtpv1u_gnb_create_tunnel_resp_t *const create_tunnel_resp) { +int gtpv1u_create_ngu_tunnel(const instance_t instance, + const gtpv1u_gnb_create_tunnel_req_t *const create_tunnel_req, + gtpv1u_gnb_create_tunnel_resp_t *const create_tunnel_resp, + gtpCallback callBack, + gtpCallbackSDAP callBackSDAP) +{ LOG_D(GTPU, "[%ld] Start create tunnels for ue id %lu, num_tunnels %d, sgw_S1u_teid %x\n", instance, create_tunnel_req->ue_id, @@ -749,8 +754,8 @@ int gtpv1u_create_ngu_tunnel( const instance_t instance, create_tunnel_req->outgoing_qfi[i], create_tunnel_req->dst_addr[i], dstport, - nr_pdcp_data_req_drb, - sdap_data_req); + callBack, + callBackSDAP); create_tunnel_resp->status=0; create_tunnel_resp->ue_id=create_tunnel_req->ue_id; create_tunnel_resp->num_tunnels=create_tunnel_req->num_tunnels; diff --git a/openair3/ocp-gtpu/gtp_itf.h b/openair3/ocp-gtpu/gtp_itf.h index 8729be9fa5..9592070ca9 100644 --- a/openair3/ocp-gtpu/gtp_itf.h +++ b/openair3/ocp-gtpu/gtp_itf.h @@ -51,8 +51,10 @@ extern "C" { // the parameter originInstance will be sent back in each message from gtp to the creator void gtpv1uReceiver(int h); void gtpv1uProcessTimeout(int handle,void *arg); - int gtpv1u_create_s1u_tunnel(const instance_t instance, const gtpv1u_enb_create_tunnel_req_t *create_tunnel_req, - gtpv1u_enb_create_tunnel_resp_t *create_tunnel_resp); + int gtpv1u_create_s1u_tunnel(const instance_t instance, + const gtpv1u_enb_create_tunnel_req_t *create_tunnel_req, + gtpv1u_enb_create_tunnel_resp_t *create_tunnel_resp, + gtpCallback callBack); int gtpv1u_update_s1u_tunnel(const instance_t instanceP, const gtpv1u_enb_create_tunnel_req_t *create_tunnel_req_pP, const rnti_t prior_rnti @@ -66,12 +68,12 @@ extern "C" { int gtpv1u_delete_x2u_tunnel( const instance_t instanceP, const gtpv1u_enb_delete_tunnel_req_t *const req_pP); - int - gtpv1u_create_ngu_tunnel( - const instance_t instanceP, - const gtpv1u_gnb_create_tunnel_req_t *const create_tunnel_req_pP, - gtpv1u_gnb_create_tunnel_resp_t *const create_tunnel_resp_pP); - + int gtpv1u_create_ngu_tunnel(const instance_t instanceP, + const gtpv1u_gnb_create_tunnel_req_t *const create_tunnel_req_pP, + gtpv1u_gnb_create_tunnel_resp_t *const create_tunnel_resp_pP, + gtpCallback callBack, + gtpCallbackSDAP callBackSDAP); + int gtpv1u_delete_ngu_tunnel( const instance_t instance, gtpv1u_gnb_delete_tunnel_req_t *req);