diff --git a/openair1/SIMULATION/NR_PHY/nr_dummy_functions.c b/openair1/SIMULATION/NR_PHY/nr_dummy_functions.c index ed72823789..3646e479d1 100644 --- a/openair1/SIMULATION/NR_PHY/nr_dummy_functions.c +++ b/openair1/SIMULATION/NR_PHY/nr_dummy_functions.c @@ -32,7 +32,7 @@ void nr_mac_rrc_sync_ind(const module_id_t module_id, const frame_t frame, const bool in_sync) {} -void nr_mac_rrc_msg3_ind(const module_id_t mod_id, int rnti) {} +void nr_mac_rrc_msg3_ind(const module_id_t mod_id, int rnti, int gnb_id) {} void nr_mac_rrc_ra_ind(const module_id_t mod_id, int frame, bool success) {} @@ -48,6 +48,7 @@ int8_t nr_mac_rrc_data_ind_ue(const module_id_t module_id, const frame_t frame, const int slot, const rnti_t rnti, + const uint32_t cellid, const channel_t channel, const uint8_t* pduP, const sdu_size_t pdu_len) { return 0; } diff --git a/openair2/COMMON/mac_messages_types.h b/openair2/COMMON/mac_messages_types.h index 9a6817a41c..79d483891d 100644 --- a/openair2/COMMON/mac_messages_types.h +++ b/openair2/COMMON/mac_messages_types.h @@ -76,7 +76,8 @@ typedef struct NRRrcMacRaInd_s { } NRRrcMacRaInd; typedef struct NRRrcMacMsg3Ind_s { - uint16_t rnti; + uint16_t rnti; + int gnb_id; } NRRrcMacMsg3Ind; typedef struct RrcMacInSyncInd_s { @@ -118,6 +119,7 @@ typedef struct NRRrcMacBcchDataInd_s { bool is_bch; uint8_t rsrq; uint8_t rsrp; + uint32_t phycellid; } NRRrcMacBcchDataInd; typedef struct NRRrcMacSBcchDataInd_s { diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index f81a142cd4..2f6d5f084f 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -264,7 +264,7 @@ int8_t nr_ue_decode_BCCH_DL_SCH(NR_UE_MAC_INST_t *mac, { if(ack_nack) { LOG_D(NR_MAC, "Decoding NR-BCCH-DL-SCH-Message (SIB1 or SI)\n"); - nr_mac_rrc_data_ind_ue(mac->ue_id, cc_id, gNB_index, 0, 0, 0, NR_BCCH_DL_SCH, (uint8_t *) pduP, pdu_len); + nr_mac_rrc_data_ind_ue(mac->ue_id, cc_id, gNB_index, 0, 0, 0, mac->physCellId, NR_BCCH_DL_SCH, (uint8_t *) pduP, pdu_len); mac->get_sib1 = false; mac->get_otherSI = false; } @@ -3774,7 +3774,7 @@ int nr_write_ce_ulsch_pdu(uint8_t *mac_ce, // - optimize: mu_pusch, j and table_6_1_2_1_1_2_time_dom_res_alloc_A are already defined in nr_ue_procedures static void nr_ue_process_rar(NR_UE_MAC_INST_t *mac, nr_downlink_indication_t *dl_info, int pdu_id) { - frame_t frame = dl_info->frame; + frame_t frame = dl_info->frame; int slot = dl_info->slot; if(dl_info->rx_ind->rx_indication_body[pdu_id].pdsch_pdu.ack_nack == 0) { @@ -3976,7 +3976,7 @@ static void nr_ue_process_rar(NR_UE_MAC_INST_t *mac, nr_downlink_indication_t *d if (!ra->cfra) { ra->t_crnti = rar->TCRNTI_2 + (rar->TCRNTI_1 << 8); rnti = ra->t_crnti; - nr_mac_rrc_msg3_ind(mac->ue_id, rnti); + nr_mac_rrc_msg3_ind(mac->ue_id, rnti, dl_info->gNB_index); } fapi_nr_ul_config_request_pdu_t *pdu = lockGet_ul_config(mac, frame_tx, slot_tx, FAPI_NR_UL_CONFIG_TYPE_PUSCH); if (!pdu) diff --git a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c index f678b2a0ca..d1bda61f82 100644 --- a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c +++ b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c @@ -83,6 +83,24 @@ static void release_rlc_entity_from_lcid(nr_rlc_ue_t *ue, logical_chan_id_t chan } } +logical_chan_id_t nr_rlc_get_lcid_from_rb(int ue_id, bool is_srb, int rb_id) +{ + nr_rlc_manager_lock(nr_rlc_ue_manager); + nr_rlc_ue_t *ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, ue_id); + for (logical_chan_id_t id = 1; id <= 32; id++) { + nr_rlc_rb_t *rb = &ue->lcid2rb[id - 1]; + if (is_srb) { + if (rb->type == NR_RLC_SRB && rb->choice.srb_id == rb_id) + return id; + } else { + if (rb->type == NR_RLC_DRB && rb->choice.drb_id == rb_id) + return id; + } + } + LOG_E(RLC, "Couldn't find LCID corresponding to %s %d\n", is_srb ? "SRB" : "DRB", rb_id); + return 0; +} + static nr_rlc_entity_t *get_rlc_entity_from_lcid(nr_rlc_ue_t *ue, logical_chan_id_t channel_id) { if (channel_id == 0) @@ -120,7 +138,7 @@ void nr_rlc_release_entity(int rnti, logical_chan_id_t channel_id) void mac_rlc_data_ind(const module_id_t module_idP, const rnti_t rntiP, const eNB_index_t eNB_index, - const frame_t rameP, + const frame_t frameP, const eNB_flag_t enb_flagP, const MBMS_flag_t MBMS_flagP, const logical_chan_id_t channel_idP, @@ -631,9 +649,10 @@ void nr_rlc_reestablish_entity(int rnti, int lc_id) nr_rlc_manager_lock(nr_rlc_ue_manager); nr_rlc_ue_t *ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rnti); - if (ue == NULL) + if (ue == NULL) { LOG_E(RLC, "RLC instance for the given UE was not found \n"); - + return; + } nr_rlc_entity_t *rb = get_rlc_entity_from_lcid(ue, lc_id); if (rb != NULL) { @@ -644,7 +663,6 @@ void nr_rlc_reestablish_entity(int rnti, int lc_id) } nr_rlc_manager_unlock(nr_rlc_ue_manager); } - void nr_rlc_reconfigure_entity(int rnti, int lc_id, NR_RLC_Config_t *rlc_Config) { nr_rlc_manager_lock(nr_rlc_ue_manager); @@ -703,6 +721,18 @@ void nr_rlc_reconfigure_entity(int rnti, int lc_id, NR_RLC_Config_t *rlc_Config) AssertFatal(um->ul_UM_RLC.sn_FieldLength == NULL, "Cannot handle different sn_FieldLength for DL and UL\n"); nr_rlc_entity_um_reconfigure(rb, t_reassembly, sn_field_length); } + } else { + AssertFatal(rb->stats.mode == NR_RLC_AM, "Invalid RLC mode\n"); + // default values as in 9.2.1 of 38.331 + int sn_field_length = 12; + nr_rlc_entity_am_reconfigure(rb, + 45, //t_poll_retransmit + 35, //t_reassembly + 0, //t_status_prohibit + -1, //poll_pdu + -1, //poll_byte + 8, //max_retx_threshold + &sn_field_length); } nr_rlc_manager_unlock(nr_rlc_ue_manager); } diff --git a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.h b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.h index 4f4578ec80..607538b15c 100644 --- a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.h +++ b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.h @@ -45,6 +45,7 @@ void nr_rlc_add_srb(int rnti, int srb_id, const NR_RLC_BearerConfig_t *rlc_Beare void nr_rlc_add_drb(int rnti, int drb_id, const NR_RLC_BearerConfig_t *rlc_BearerConfig); void nr_rlc_reestablish_entity(int rnti, int lc_id); +logical_chan_id_t nr_rlc_get_lcid_from_rb(int ue_id, bool is_srb, int rb_id); void nr_rlc_remove_ue(int rnti); bool nr_rlc_update_rnti(int from_rnti, int to_rnti); diff --git a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c index 7f9f5aa55e..2f0892b66f 100644 --- a/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_UE_PHY_INTERFACE/NR_IF_Module.c @@ -1048,7 +1048,8 @@ static int handle_bcch_bch(NR_UE_MAC_INST_t *mac, mac->frequency_range = FR2; else mac->frequency_range = FR1; - nr_mac_rrc_data_ind_ue(mac->ue_id, cc_id, gNB_index, 0, 0, 0, NR_BCCH_BCH, (uint8_t *) pduP, 3); // fixed 3 bytes MIB PDU + // fixed 3 bytes MIB PDU + nr_mac_rrc_data_ind_ue(mac->ue_id, cc_id, gNB_index, 0, 0, 0, cell_id, NR_BCCH_BCH, (uint8_t *) pduP, 3); return 0; } diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.c b/openair2/RRC/NR/MESSAGES/asn1_msg.c index 5b50ecb44e..82798b4b75 100644 --- a/openair2/RRC/NR/MESSAGES/asn1_msg.c +++ b/openair2/RRC/NR/MESSAGES/asn1_msg.c @@ -979,7 +979,10 @@ uint8_t do_NR_ULInformationTransfer(uint8_t **buffer, uint32_t pdu_length, uint8 return encoded; } -uint8_t do_RRCReestablishmentRequest(uint8_t *buffer, uint16_t c_rnti) +uint8_t do_RRCReestablishmentRequest(uint8_t *buffer, + NR_ReestablishmentCause_t cause, + uint32_t cell_id, + uint16_t c_rnti) { asn_enc_rval_t enc_rval; NR_UL_CCCH_Message_t ul_ccch_msg; @@ -994,16 +997,16 @@ uint8_t do_RRCReestablishmentRequest(uint8_t *buffer, uint16_t c_rnti) rrcReestablishmentRequest = ul_ccch_msg.message.choice.c1->choice.rrcReestablishmentRequest; // test - rrcReestablishmentRequest->rrcReestablishmentRequest.reestablishmentCause = NR_ReestablishmentCause_reconfigurationFailure; + rrcReestablishmentRequest->rrcReestablishmentRequest.reestablishmentCause = cause; rrcReestablishmentRequest->rrcReestablishmentRequest.ue_Identity.c_RNTI = c_rnti; - rrcReestablishmentRequest->rrcReestablishmentRequest.ue_Identity.physCellId = 0; + rrcReestablishmentRequest->rrcReestablishmentRequest.ue_Identity.physCellId = cell_id; + // TODO properly setting shortMAC-I (see 5.3.7.4 of 331) rrcReestablishmentRequest->rrcReestablishmentRequest.ue_Identity.shortMAC_I.buf = buf; rrcReestablishmentRequest->rrcReestablishmentRequest.ue_Identity.shortMAC_I.buf[0] = 0x08; rrcReestablishmentRequest->rrcReestablishmentRequest.ue_Identity.shortMAC_I.buf[1] = 0x32; rrcReestablishmentRequest->rrcReestablishmentRequest.ue_Identity.shortMAC_I.size = 2; - - if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) { + if (LOG_DEBUGFLAG(DEBUG_ASN1)) { xer_fprint(stdout, &asn_DEF_NR_UL_CCCH_Message, (void *)&ul_ccch_msg); } diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.h b/openair2/RRC/NR/MESSAGES/asn1_msg.h index 143717390c..de57a339d5 100644 --- a/openair2/RRC/NR/MESSAGES/asn1_msg.h +++ b/openair2/RRC/NR/MESSAGES/asn1_msg.h @@ -131,7 +131,10 @@ uint8_t do_NR_ULInformationTransfer(uint8_t **buffer, uint32_t pdu_length, uint8_t *pdu_buffer); -uint8_t do_RRCReestablishmentRequest(uint8_t *buffer, uint16_t c_rnti); +uint8_t do_RRCReestablishmentRequest(uint8_t *buffer, + NR_ReestablishmentCause_t cause, + uint32_t cell_id, + uint16_t c_rnti); int do_RRCReestablishment(rrc_gNB_ue_context_t *const ue_context_pP, uint8_t *const buffer, diff --git a/openair2/RRC/NR_UE/L2_interface_ue.c b/openair2/RRC/NR_UE/L2_interface_ue.c index b3eac63e4c..1e93cc935e 100644 --- a/openair2/RRC/NR_UE/L2_interface_ue.c +++ b/openair2/RRC/NR_UE/L2_interface_ue.c @@ -54,6 +54,7 @@ int8_t nr_mac_rrc_data_ind_ue(const module_id_t module_id, const frame_t frame, const int slot, const rnti_t rnti, + const uint32_t cellid, const channel_t channel, const uint8_t* pduP, const sdu_size_t pdu_len) @@ -84,6 +85,7 @@ int8_t nr_mac_rrc_data_ind_ue(const module_id_t module_id, NR_RRC_MAC_BCCH_DATA_IND (message_p).slot = slot; NR_RRC_MAC_BCCH_DATA_IND (message_p).sdu_size = sdu_size; NR_RRC_MAC_BCCH_DATA_IND (message_p).gnb_index = gNB_index; + NR_RRC_MAC_BCCH_DATA_IND (message_p).phycellid = cellid; NR_RRC_MAC_BCCH_DATA_IND (message_p).is_bch = (channel == NR_BCCH_BCH); itti_send_msg_to_task(TASK_RRC_NRUE, GNB_MODULE_ID_TO_INSTANCE(module_id), message_p); } @@ -122,10 +124,11 @@ int8_t nr_mac_rrc_data_ind_ue(const module_id_t module_id, return(0); } -void nr_mac_rrc_msg3_ind(const module_id_t mod_id, const int rnti) +void nr_mac_rrc_msg3_ind(const module_id_t mod_id, const int rnti, int gnb_id) { MessageDef *message_p = itti_alloc_new_message(TASK_MAC_UE, 0, NR_RRC_MAC_MSG3_IND); NR_RRC_MAC_MSG3_IND (message_p).rnti = rnti; + NR_RRC_MAC_MSG3_IND (message_p).gnb_id = gnb_id; itti_send_msg_to_task(TASK_RRC_NRUE, GNB_MODULE_ID_TO_INSTANCE(mod_id), message_p); } diff --git a/openair2/RRC/NR_UE/rrc_UE.c b/openair2/RRC/NR_UE/rrc_UE.c index bee8e293c9..2c45ce4526 100644 --- a/openair2/RRC/NR_UE/rrc_UE.c +++ b/openair2/RRC/NR_UE/rrc_UE.c @@ -428,10 +428,12 @@ int check_si_status(NR_UE_RRC_SI_INFO *SI_info) /*brief decode BCCH-BCH (MIB) message*/ static void nr_rrc_ue_decode_NR_BCCH_BCH_Message(NR_UE_RRC_INST_t *rrc, const uint8_t gNB_index, + const uint32_t phycellid, uint8_t *const bufferP, const uint8_t buffer_len) { NR_BCCH_BCH_Message_t *bcch_message = NULL; + rrc->phyCellID = phycellid; asn_dec_rval_t dec_rval = uper_decode_complete(NULL, &asn_DEF_NR_BCCH_BCH_Message, @@ -448,9 +450,17 @@ static void nr_rrc_ue_decode_NR_BCCH_BCH_Message(NR_UE_RRC_INST_t *rrc, NR_UE_Timers_Constants_t *timers = &rrc->timers_and_constants; if (is_nr_timer_active(timers->T311)) { nr_timer_stop(&timers->T311); - nr_timer_start(&timers->T301); rrc->ra_trigger = RRC_CONNECTION_REESTABLISHMENT; + // preparing MSG3 for re-establishment in advance + uint8_t buffer[1024]; + int buf_size = do_RRCReestablishmentRequest(buffer, + rrc->reestablishment_cause, + rrc->phyCellID, + rrc->rnti); // old rnti + + nr_rlc_srb_recv_sdu(rrc->ue_id, 0, buffer, buf_size); + // apply the default MAC Cell Group configuration // (done at MAC by calling nr_ue_mac_default_configs) @@ -590,16 +600,28 @@ static int nr_decode_SI(NR_UE_RRC_SI_INFO *SI_info, NR_SystemInformation_t *si) static void nr_rrc_handle_msg3_indication(NR_UE_RRC_INST_t *rrc, rnti_t rnti) { + NR_UE_Timers_Constants_t *tac = &rrc->timers_and_constants; switch (rrc->ra_trigger) { case INITIAL_ACCESS_FROM_RRC_IDLE: // After SIB1 is received, prepare RRCConnectionRequest rrc->rnti = rnti; // start timer T300 - NR_UE_Timers_Constants_t *tac = &rrc->timers_and_constants; nr_timer_start(&tac->T300); break; case RRC_CONNECTION_REESTABLISHMENT: - AssertFatal(1==0, "ra_trigger not implemented yet!\n"); + rrc->rnti = rnti; + nr_timer_start(&tac->T301); + int srb_id = 1; + // re-establish PDCP for SRB1 + nr_pdcp_reestablishment(rrc->ue_id, srb_id, true); + // re-establish RLC for SRB1 + int lc_id = nr_rlc_get_lcid_from_rb(rrc->ue_id, true, 1); + nr_rlc_reestablish_entity(rrc->ue_id, lc_id); + // apply the specified configuration defined in 9.2.1 for SRB1 + nr_rlc_reconfigure_entity(rrc->ue_id, lc_id, NULL); + // TODO configure lower layers to suspend integrity protection and ciphering for SRB1 + // resume SRB1 + rrc->Srb[srb_id] = RB_ESTABLISHED; break; case DURING_HANDOVER: AssertFatal(1==0, "ra_trigger not implemented yet!\n"); @@ -750,7 +772,8 @@ static void nr_rrc_manage_rlc_bearers(NR_UE_RRC_INST_t *rrc, if (rrc->active_RLC_entity[lcid]) { if (rlc_bearer->reestablishRLC) nr_rlc_reestablish_entity(rrc->ue_id, lcid); - nr_rlc_reconfigure_entity(rrc->ue_id, lcid, rlc_bearer->rlc_Config); + if (rlc_bearer->rlc_Config) + nr_rlc_reconfigure_entity(rrc->ue_id, lcid, rlc_bearer->rlc_Config); } else { rrc->active_RLC_entity[lcid] = true; AssertFatal(rlc_bearer->servedRadioBearer, "servedRadioBearer mandatory in case of setup\n"); @@ -1467,7 +1490,7 @@ void *rrc_nrue(void *notUsed) LOG_D(NR_RRC, "[UE %ld] Received %s: gNB %d\n", rrc->ue_id, ITTI_MSG_NAME(msg_p), NR_RRC_MAC_BCCH_DATA_IND(msg_p).gnb_index); NRRrcMacBcchDataInd *bcch = &NR_RRC_MAC_BCCH_DATA_IND(msg_p); if (bcch->is_bch) - nr_rrc_ue_decode_NR_BCCH_BCH_Message(rrc, bcch->gnb_index, bcch->sdu, bcch->sdu_size); + nr_rrc_ue_decode_NR_BCCH_BCH_Message(rrc, bcch->gnb_index, bcch->phycellid, bcch->sdu, bcch->sdu_size); else nr_rrc_ue_decode_NR_BCCH_DL_SCH_Message(rrc, bcch->gnb_index, bcch->sdu, bcch->sdu_size, bcch->rsrq, bcch->rsrp); break; @@ -1615,8 +1638,11 @@ static void nr_rrc_ue_process_ueCapabilityEnquiry(NR_UE_RRC_INST_t *rrc, NR_UECa } void nr_rrc_initiate_rrcReestablishment(NR_UE_RRC_INST_t *rrc, + NR_ReestablishmentCause_t cause, const int gnb_id) { + rrc->reestablishment_cause = cause; + NR_UE_Timers_Constants_t *timers = &rrc->timers_and_constants; rrcPerNB_t *rrcNB = rrc->perNB + gnb_id; @@ -1645,7 +1671,6 @@ void nr_rrc_initiate_rrcReestablishment(NR_UE_RRC_INST_t *rrc, } // release the MCG SCell(s), if configured // no SCell configured in our implementation - rrc->nrRrcState = RRC_STATE_REESTABLISHMENT; // reset MAC // release spCellConfig, if configured diff --git a/openair2/RRC/NR_UE/rrc_defs.h b/openair2/RRC/NR_UE/rrc_defs.h index 448978a7d0..40cbca3ad5 100644 --- a/openair2/RRC/NR_UE/rrc_defs.h +++ b/openair2/RRC/NR_UE/rrc_defs.h @@ -56,6 +56,7 @@ #include "NR_UE-NR-Capability.h" #include "NR_SL-PreconfigurationNR-r16.h" #include "NR_MasterInformationBlockSidelink.h" +#include "NR_ReestablishmentCause.h" #include "RRC/NR/nr_rrc_common.h" #include "as_message.h" @@ -85,7 +86,6 @@ typedef enum Rrc_State_NR_e { RRC_STATE_INACTIVE_NR, RRC_STATE_CONNECTED_NR, RRC_STATE_DETACH_NR, - RRC_STATE_REESTABLISHMENT } Rrc_State_NR_t; typedef enum requested_SI_List_e { @@ -186,10 +186,13 @@ typedef struct NR_UE_RRC_INST_s { rrcPerNB_t perNB[NB_CNX_UE]; rnti_t rnti; + uint32_t phyCellID; OAI_NR_UECapability_t UECap; NR_UE_Timers_Constants_t timers_and_constants; + RA_trigger_t ra_trigger; + NR_ReestablishmentCause_t reestablishment_cause; plmn_t plmnID; NR_BWP_Id_t dl_bwp_id; diff --git a/openair2/RRC/NR_UE/rrc_proto.h b/openair2/RRC/NR_UE/rrc_proto.h index 9ce17336d2..fa8eee3830 100644 --- a/openair2/RRC/NR_UE/rrc_proto.h +++ b/openair2/RRC/NR_UE/rrc_proto.h @@ -73,6 +73,7 @@ int8_t nr_mac_rrc_data_ind_ue(const module_id_t module_id, const frame_t frame, const int slot, const rnti_t rnti, + const uint32_t cellid, const channel_t channel, const uint8_t* pduP, const sdu_size_t pdu_len); @@ -86,7 +87,7 @@ void nr_rrc_going_to_IDLE(NR_UE_RRC_INST_t *rrc, NR_RRCRelease_t *RRCRelease); void nr_mac_rrc_ra_ind(const module_id_t mod_id, int frame, bool success); -void nr_mac_rrc_msg3_ind(const module_id_t mod_id, const int rnti); +void nr_mac_rrc_msg3_ind(const module_id_t mod_id, const int rnti, int gnb_id); void set_rlf_sib1_timers_and_constants(NR_UE_Timers_Constants_t *tac, NR_SIB1_t *sib1); /**\brief RRC UE task.