diff --git a/openair1/SIMULATION/NR_PHY/nr_unitary_defs.h b/openair1/SIMULATION/NR_PHY/nr_unitary_defs.h index a7150fb2f9..e9e3039c71 100644 --- a/openair1/SIMULATION/NR_PHY/nr_unitary_defs.h +++ b/openair1/SIMULATION/NR_PHY/nr_unitary_defs.h @@ -55,19 +55,6 @@ signed char quantize(double D, double x, unsigned char B) { return ((char) qxd); } - -int8_t -mac_rrc_data_req_ue( - const module_id_t Mod_idP, - const int CC_id, - const frame_t frameP, - const rb_id_t Srb_id, - const uint8_t Nb_tb, - uint8_t *const buffer_pP, - const mac_enb_index_t eNB_indexP, - const uint8_t mbsfn_sync_area - ) { return(0);} - int oai_nfapi_rach_ind(nfapi_rach_indication_t *rach_ind) {return(0);} //NR_IF_Module_t *NR_IF_Module_init(int Mod_id){return(NULL);} int oai_nfapi_ul_config_req(nfapi_ul_config_request_t *ul_config_req) { return(0); } diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h index e13ae1424c..e41ca67229 100644 --- a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h +++ b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h @@ -160,19 +160,6 @@ typedef struct Type0_PDCCH_CSS_config_s { uint32_t cset_start_rb; } NR_Type0_PDCCH_CSS_config_t; -// 3GPP TS 38.300 Section 9.2.6 -typedef enum RA_trigger_e { - RA_NOT_RUNNING, - INITIAL_ACCESS_FROM_RRC_IDLE, - RRC_CONNECTION_REESTABLISHMENT, - DURING_HANDOVER, - NON_SYNCHRONISED, - TRANSITION_FROM_RRC_INACTIVE, - TO_ESTABLISH_TA, - REQUEST_FOR_OTHER_SI, - BEAM_FAILURE_RECOVERY, -} RA_trigger_t; - uint16_t config_bandwidth(int mu, int nb_rb, int nr_band); void get_frame_type(uint16_t nr_bandP, uint8_t scs_index, lte_frame_type_t *current_type); diff --git a/openair2/LAYER2/NR_MAC_UE/config_ue.c b/openair2/LAYER2/NR_MAC_UE/config_ue.c index e9ebd16d0f..20fe84d819 100755 --- a/openair2/LAYER2/NR_MAC_UE/config_ue.c +++ b/openair2/LAYER2/NR_MAC_UE/config_ue.c @@ -272,9 +272,8 @@ void config_common_ue(NR_UE_MAC_INST_t *mac, } // PRACH configuration - uint8_t nb_preambles = 64; - mac->ra_trigger = RA_NOT_RUNNING; + uint8_t nb_preambles = 64; if(scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup->totalNumberOfRA_Preambles != NULL) nb_preambles = *scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup->totalNumberOfRA_Preambles; diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h index fefe712e43..6bbbc00c00 100755 --- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h @@ -185,8 +185,6 @@ typedef struct { /* Random Access parameters */ /// state of RA procedure RA_state_t ra_state; - /// trigger of RA procedure - RA_trigger_t ra_trigger; /// RA rx frame offset: compensate RA rx offset introduced by OAI gNB. uint8_t RA_offset; /// RA-rnti diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c index 1f5d81060e..f297ae1ded 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ra_procedures.c @@ -50,6 +50,7 @@ /* RRC */ #include "NR_RACH-ConfigCommon.h" +#include "RRC/NR_UE/rrc_proto.h" /* PHY */ #include "PHY/NR_TRANSPORT/nr_transport_common_proto.h" @@ -456,36 +457,20 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, prach_resources->RA_SCALING_FACTOR_BI = 1; prach_resources->RA_PCMAX = 0; // currently hardcoded to 0 - payload = (uint8_t*) &mac->CCCH_pdu.payload; + payload = (uint8_t*) mac->CCCH_pdu.payload; mac_ce_len = 0; num_sdus = 1; post_padding = 1; + sdu_lcids[0] = lcid; - if (0){ - // initialisation by RRC - // CCCH PDU - // size_sdu = (uint16_t) mac_rrc_data_req_ue(mod_id, - // CC_id, - // frame, - // CCCH, - // 1, - // mac_sdus, - // gNB_id, - // 0); - LOG_D(MAC,"[UE %d] Frame %d: Requested RRCConnectionRequest, got %d bytes\n", mod_id, frame, size_sdu); - } else { - // fill ulsch_buffer with random data - for (int i = 0; i < TBS_bytes; i++){ - mac_sdus[i] = (unsigned char) (lrand48()&0xff); - } - //Sending SDUs with size 1 - //Initialize elements of sdu_lcids and sdu_lengths - sdu_lcids[0] = lcid; - sdu_lengths[0] = TBS_bytes - 3 - post_padding - mac_ce_len; - header_length_total += 2 + (sdu_lengths[0] >= 128); - size_sdu += sdu_lengths[0]; - } + // initialisation by RRC + // CCCH PDU + size_sdu = (uint16_t) nr_mac_rrc_data_req_ue(mod_id, CC_id, gNB_id, frame, CCCH, mac_sdus); + + sdu_lengths[0] = size_sdu; + + LOG_D(MAC,"[UE %d] Frame %d: Requested RRCConnectionRequest, got %d bytes\n", mod_id, frame, size_sdu); //mac->RA_tx_frame = frame; //mac->RA_tx_slot = nr_slot_tx; @@ -529,7 +514,14 @@ uint8_t nr_ue_get_rach(NR_PRACH_RESOURCES_t *prach_resources, for (int j = 0; j < (TBS_bytes - offset); j++) payload[offset + j] = 0; // mac_pdu[offset + j] = 0; } - } + } + + LOG_I(MAC,"size_sdu = %i\n", size_sdu); + LOG_I(MAC,"offset = %i\n", offset); + for(int k = 0; kMsg3[k]); + } + } else if (mac->RA_window_cnt != -1) { // RACH is active //////////////////////////////////////////////////////////////// diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index be476c2775..b69ecafc89 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -987,7 +987,7 @@ int8_t nr_ue_decode_mib(module_id_t module_id, LOG_D(MAC,"cell barred (0=barred,1=notBarred): %d\n", (int)mac->mib->cellBarred); LOG_D(MAC,"intra frequency reselection (0=allowed,1=notAllowed): %d\n", (int)mac->mib->intraFreqReselection); LOG_D(MAC,"half frame bit(extra bits): %d\n", (int)half_frame_bit); - LOG_I(MAC,"ssb index(extra bits): %d\n", (int)ssb_index); + LOG_D(MAC,"ssb index(extra bits): %d\n", (int)ssb_index); //storing ssb index in the mac structure mac->mib_ssb = ssb_index; diff --git a/openair2/RRC/NR/nr_rrc_types.h b/openair2/RRC/NR/nr_rrc_types.h index 02495591a9..61f90e3572 100644 --- a/openair2/RRC/NR/nr_rrc_types.h +++ b/openair2/RRC/NR/nr_rrc_types.h @@ -32,11 +32,11 @@ #define RRC_TYPES_NR_H_ typedef enum Rrc_State_NR_e { - RRC_STATE_INACTIVE_NR=0, - RRC_STATE_IDLE_NR, + RRC_STATE_IDLE_NR=0, + RRC_STATE_INACTIVE_NR, RRC_STATE_CONNECTED_NR, - RRC_STATE_FIRST_NR = RRC_STATE_INACTIVE_NR, + RRC_STATE_FIRST_NR = RRC_STATE_IDLE_NR, RRC_STATE_LAST_NR = RRC_STATE_CONNECTED_NR, } Rrc_State_NR_t; diff --git a/openair2/RRC/NR_UE/L2_interface_ue.c b/openair2/RRC/NR_UE/L2_interface_ue.c index 22e17f6266..c56d75e48b 100644 --- a/openair2/RRC/NR_UE/L2_interface_ue.c +++ b/openair2/RRC/NR_UE/L2_interface_ue.c @@ -33,6 +33,7 @@ #include "rrc_defs.h" #include "rrc_proto.h" #include "assertions.h" +#include "rrc_vars.h" typedef uint32_t channel_t; @@ -59,13 +60,36 @@ nr_mac_rrc_data_ind_ue( return(0); } -int8_t mac_rrc_nr_data_req_ue(const module_id_t Mod_idP, +int8_t nr_mac_rrc_data_req_ue(const module_id_t Mod_idP, const int CC_id, + const uint8_t gNB_id, const frame_t frameP, const rb_id_t Srb_id, - uint8_t *const buffer_pP ){ + uint8_t *buffer_pP){ - // todo + switch(Srb_id){ + + case CCCH: + + // TODO: Enable timer T300 + //NR_UE_rrc_inst[Mod_idP].Info[gNB_id].T300_active = 1; + //NR_UE_rrc_inst[Mod_idP].Info[gNB_id].T300_cnt = 0; + + LOG_I(RRC, "nr_mac_rrc_data_req_ue: Payload size = %i\n", NR_UE_rrc_inst[Mod_idP].Srb0[gNB_id].Tx_buffer.payload_size); + memcpy(buffer_pP, (uint8_t*)NR_UE_rrc_inst[Mod_idP].Srb0[gNB_id].Tx_buffer.Payload, NR_UE_rrc_inst[Mod_idP].Srb0[gNB_id].Tx_buffer.payload_size); + for(int i = 0; imodule_id].MBMS_flag < 3) // see -Q option if (AMF_MODE_ENABLED) { - rrc_ue_generate_RRCSetupRequest( ctxt_pP, gNB_index ); + nr_rrc_ue_generate_RRCSetupRequest( ctxt_pP->module_id, gNB_index ); } if (NR_UE_rrc_inst[ctxt_pP->module_id].Info[gNB_index].State == NR_RRC_IDLE) { @@ -1287,7 +1289,7 @@ int nr_decode_BCCH_DLSCH_Message( if (nr_rrc_get_sub_state(ctxt_pP->module_id) == RRC_SUB_STATE_IDLE_SIB_COMPLETE_NR) { //if ( (NR_UE_rrc_inst[ctxt_pP->module_id].initialNasMsg.data != NULL) || (!AMF_MODE_ENABLED)) { - rrc_ue_generate_RRCSetupRequest(ctxt_pP, 0); + nr_rrc_ue_generate_RRCSetupRequest(ctxt_pP->module_id, 0); nr_rrc_set_sub_state( ctxt_pP->module_id, RRC_SUB_STATE_IDLE_CONNECTING ); //} } @@ -1493,13 +1495,13 @@ int8_t check_requested_SI_List(module_id_t module_id, BIT_STRING_t requested_SI_ bool SIB_to_request[32] = {}; - LOG_I(RRC, "SIBs broadcasting: "); + LOG_D(RRC, "SIBs broadcasting: "); for(int i = 0; i < sib1.si_SchedulingInfo->schedulingInfoList.list.array[0]->sib_MappingInfo.list.count; i++) { printf("SIB%li ", sib1.si_SchedulingInfo->schedulingInfoList.list.array[0]->sib_MappingInfo.list.array[i]->type + 2); } printf("\n"); - LOG_I(RRC, "SIBs needed by UE: "); + LOG_D(RRC, "SIBs needed by UE: "); for(int j = 0; j < 8*requested_SI_List.size; j++) { if( ((requested_SI_List.buf[j/8]>>(j%8))&1) == 1) { @@ -1517,7 +1519,7 @@ int8_t check_requested_SI_List(module_id_t module_id, BIT_STRING_t requested_SI_ } printf("\n"); - LOG_I(RRC, "SIBs to request by UE: "); + LOG_D(RRC, "SIBs to request by UE: "); bool do_ra = false; for(int j = 0; j < 8*requested_SI_List.size; j++) { if(SIB_to_request[j]) { @@ -1529,14 +1531,13 @@ int8_t check_requested_SI_List(module_id_t module_id, BIT_STRING_t requested_SI_ if(do_ra) { - NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); - mac->ra_trigger = REQUEST_FOR_OTHER_SI; + NR_UE_rrc_inst[module_id].ra_trigger = REQUEST_FOR_OTHER_SI; get_softmodem_params()->do_ra = 1; if(sib1.si_SchedulingInfo->si_RequestConfig) { - LOG_I(RRC, "Trigger contention-free RA procedure (ra_trigger = %i)\n", mac->ra_trigger); + LOG_D(RRC, "Trigger contention-free RA procedure (ra_trigger = %i)\n", NR_UE_rrc_inst[module_id].ra_trigger); } else { - LOG_I(RRC, "Trigger contention-based RA procedure (ra_trigger = %i)\n", mac->ra_trigger); + LOG_D(RRC, "Trigger contention-based RA procedure (ra_trigger = %i)\n", NR_UE_rrc_inst[module_id].ra_trigger); } } @@ -1546,6 +1547,41 @@ int8_t check_requested_SI_List(module_id_t module_id, BIT_STRING_t requested_SI_ return 0; } +int8_t nr_rrc_ue_generate_ra_msg(module_id_t module_id, uint8_t gNB_index) { + + switch(NR_UE_rrc_inst[module_id].ra_trigger){ + case INITIAL_ACCESS_FROM_RRC_IDLE: + nr_rrc_ue_generate_RRCSetupRequest(module_id,gNB_index); + break; + case RRC_CONNECTION_REESTABLISHMENT: + AssertFatal(1==0, "ra_trigger not implemented yet!\n"); + break; + case DURING_HANDOVER: + AssertFatal(1==0, "ra_trigger not implemented yet!\n"); + break; + case NON_SYNCHRONISED: + AssertFatal(1==0, "ra_trigger not implemented yet!\n"); + break; + case TRANSITION_FROM_RRC_INACTIVE: + AssertFatal(1==0, "ra_trigger not implemented yet!\n"); + break; + case TO_ESTABLISH_TA: + AssertFatal(1==0, "ra_trigger not implemented yet!\n"); + break; + case REQUEST_FOR_OTHER_SI: + AssertFatal(1==0, "ra_trigger not implemented yet!\n"); + break; + case BEAM_FAILURE_RECOVERY: + AssertFatal(1==0, "ra_trigger not implemented yet!\n"); + break; + default: + AssertFatal(1==0, "Invalid ra_trigger value!\n"); + break; + } + +} + + /*brief decode SIB1 message*/ int8_t nr_rrc_ue_decode_NR_SIB1_Message(module_id_t module_id, uint8_t gNB_index, uint8_t *const bufferP, const uint8_t buffer_len) { @@ -1574,7 +1610,15 @@ int8_t nr_rrc_ue_decode_NR_SIB1_Message(module_id_t module_id, uint8_t gNB_index if( g_log->log_component[RRC].level >= OAILOG_DEBUG ) xer_fprint(stdout, &asn_DEF_NR_SIB1, (const void*)sib1); - check_requested_SI_List(module_id, NR_UE_rrc_inst[module_id].requested_SI_List, *sib1); + // FIXME: fix condition for the RA trigger + if( nr_rrc_get_state(module_id) == RRC_STATE_IDLE_NR ) { + NR_UE_rrc_inst[module_id].ra_trigger = INITIAL_ACCESS_FROM_RRC_IDLE; + get_softmodem_params()->do_ra = 1; + } else { + check_requested_SI_List(module_id, NR_UE_rrc_inst[module_id].requested_SI_List, *sib1); + } + + nr_rrc_ue_generate_ra_msg(module_id,gNB_index); } else LOG_E(PHY, "sib1 is starting by 8 times 0\n"); @@ -1844,10 +1888,10 @@ nr_rrc_ue_process_securityModeCommand( } //----------------------------------------------------------------------------- -void rrc_ue_generate_RRCSetupRequest( const protocol_ctxt_t *const ctxt_pP, const uint8_t gNB_index ) { +void nr_rrc_ue_generate_RRCSetupRequest(module_id_t module_id, const uint8_t gNB_index ) { uint8_t i=0,rv[6]; - if(NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.payload_size ==0) { + if(NR_UE_rrc_inst[module_id].Srb0[gNB_index].Tx_buffer.payload_size ==0) { // Get RRCConnectionRequest, fill random for now // Generate random byte stream for contention resolution for (i=0; i<6; i++) { @@ -1861,16 +1905,16 @@ void rrc_ue_generate_RRCSetupRequest( const protocol_ctxt_t *const ctxt_pP, cons } LOG_T(NR_RRC,"\n"); - // NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.payload_size = - // do_RRCSetupRequest( - // ctxt_pP->module_id, - // (uint8_t *)NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.Payload, - // rv); - LOG_I(NR_RRC,"[UE %d] : Frame %d, Logical Channel UL-CCCH (SRB0), Generating RRCSetupRequest (bytes %d, eNB %d)\n", - ctxt_pP->module_id, ctxt_pP->frame, NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.payload_size, gNB_index); + NR_UE_rrc_inst[module_id].Srb0[gNB_index].Tx_buffer.payload_size = + do_RRCSetupRequest( + module_id, + (uint8_t *)NR_UE_rrc_inst[module_id].Srb0[gNB_index].Tx_buffer.Payload, + rv); + LOG_I(NR_RRC,"[UE %d] : Logical Channel UL-CCCH (SRB0), Generating RRCSetupRequest (bytes %d, gNB %d)\n", + module_id, NR_UE_rrc_inst[module_id].Srb0[gNB_index].Tx_buffer.payload_size, gNB_index); - for (i=0; imodule_id].Srb0[gNB_index].Tx_buffer.payload_size; i++) { - LOG_T(NR_RRC,"%x.",NR_UE_rrc_inst[ctxt_pP->module_id].Srb0[gNB_index].Tx_buffer.Payload[i]); + for (i=0; i