From c4d7e11c1c861596fee7b87669734be983a6fa51 Mon Sep 17 00:00:00 2001 From: Melissa Elkadi Date: Wed, 5 May 2021 16:42:22 -0700 Subject: [PATCH] Working on do_nrMeasurementReport --- openair2/RRC/LTE/MESSAGES/asn1_msg.c | 94 +++++++++++++++++++++ openair2/RRC/LTE/MESSAGES/asn1_msg.h | 2 + openair2/RRC/LTE/rrc_UE.c | 119 ++++++++++++++------------- 3 files changed, 158 insertions(+), 57 deletions(-) diff --git a/openair2/RRC/LTE/MESSAGES/asn1_msg.c b/openair2/RRC/LTE/MESSAGES/asn1_msg.c index 64018729ec..fe7e666a0d 100644 --- a/openair2/RRC/LTE/MESSAGES/asn1_msg.c +++ b/openair2/RRC/LTE/MESSAGES/asn1_msg.c @@ -4216,6 +4216,100 @@ uint8_t do_MeasurementReport(uint8_t Mod_id, uint8_t *buffer,int measid,int phy_ return((enc_rval.encoded+7)/8); } +ssize_t do_nrMeasurementReport(uint8_t Mod_id, uint8_t *buffer,int measid,int phy_id,long rsrp_s,long rsrq_s,long rsrp_t,long rsrq_t) { + asn_enc_rval_t enc_rval; + LTE_UL_DCCH_Message_t ul_dcch_msg; + LTE_MeasurementReport_t *measurementReport; + ul_dcch_msg.message.present = LTE_UL_DCCH_MessageType_PR_c1; + ul_dcch_msg.message.choice.c1.present = LTE_UL_DCCH_MessageType__c1_PR_measurementReport; + measurementReport = &ul_dcch_msg.message.choice.c1.choice.measurementReport; + measurementReport->criticalExtensions.present=LTE_MeasurementReport__criticalExtensions_PR_c1; + measurementReport->criticalExtensions.choice.c1.present=LTE_MeasurementReport__criticalExtensions__c1_PR_measurementReport_r8; + measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.nonCriticalExtension=CALLOC(1, + sizeof(*measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.nonCriticalExtension)); + measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measId=measid; + measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measResultPCell.rsrpResult=rsrp_s; + measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measResultPCell.rsrqResult=rsrq_s; + measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measResultNeighCells=CALLOC(1, + sizeof(*measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measResultNeighCells)); + measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measResultNeighCells->present=LTE_MeasResults__measResultNeighCells_PR_measResultNeighCellListNR_r15; + LTE_MeasResultCellListNR_r15_t *measResultListNR_r15; + measResultListNR_r15 = CALLOC(1,sizeof(*measResultListNR_r15)); + struct LTE_MeasResultCellNR_r15 *measResultNR_r15; + measResultNR_r15 = CALLOC(1,sizeof(*measResultNR_r15)); + measResultNR_r15->pci_r15; + struct LTE_CGI_InfoNR_r15 *measresult_nr_cgi2; + measresult_nr_cgi2 = CALLOC(1,sizeof(*measresult_nr_cgi2)); + + int count = measresult_nr_cgi2->plmn_IdentityInfoList_r15->list.count; + for (int i = 0; i < count; i++) + { + AssertFatal(i < count, "%d >= measresult_nr_cgi2->plmn_IdentityInfoList_r15->list.count", i); + //LTE_PLMN_IdentityInfoNR_r15_t *plmn_info_list = measResultNR_r15->ext1->cgi_Info_r15->plmn_IdentityInfoList_r15->list.array[i]->cellIdentity_r15. + LTE_PLMN_IdentityInfoNR_r15_t *plmn_info_list = measresult_nr_cgi2->plmn_IdentityInfoList_r15->list.array[i]; + memset(&plmn_info_list,0,sizeof(plmn_info_list)); + LTE_PLMN_Identity_t *plmn_id = plmn_info_list->plmn_IdentityList_r15.list.array[i]; + memset(&plmn_id, 0, sizeof(plmn_id)); + plmn_id->mcc = CALLOC(1, sizeof(plmn_id->mcc)); + asn_set_empty(plmn_id->mcc->list); + + LTE_MCC_MNC_Digit_t dummy; + dummy=2; + ASN_SEQUENCE_ADD(plmn_id->mcc->list, &dummy); + dummy=6; + ASN_SEQUENCE_ADD(plmn_id->mcc->list, &dummy); + dummy=2; + ASN_SEQUENCE_ADD(plmn_id->mcc->list, &dummy); + + plmn_id->mnc.list.size=0; + plmn_id->mnc.list.count=0; + dummy=8; + ASN_SEQUENCE_ADD(&plmn_id->mnc.list, &dummy); + dummy=0; + ASN_SEQUENCE_ADD(&plmn_id->mnc.list, &dummy); + + plmn_info_list->cellIdentity_r15.buf = MALLOC(8); + plmn_info_list->cellIdentity_r15.buf[0] = 0x01; + plmn_info_list->cellIdentity_r15.buf[1] = 0x48; + plmn_info_list->cellIdentity_r15.buf[2] = 0x0f; + plmn_info_list->cellIdentity_r15.buf[3] = 0x03; + plmn_info_list->cellIdentity_r15.size = 4; + plmn_info_list->cellIdentity_r15.bits_unused = 4; + plmn_info_list->trackingAreaCode_r15->buf = MALLOC(2); + plmn_info_list->trackingAreaCode_r15->buf[0]=0x00; + plmn_info_list->trackingAreaCode_r15->buf[1]=0x10; + plmn_info_list->trackingAreaCode_r15->size=2; + plmn_info_list->trackingAreaCode_r15->bits_unused=0; + } + + measResultNR_r15->ext1->cgi_Info_r15 = measResultNR_r15; + struct LTE_MeasResultNR_r15_t meas2; + meas2.rsrpResult_r15 = &(rsrp_t); + meas2.rsrqResult_r15 = &(rsrq_t); + measResultNR_r15->measResultCell_r15 = meas2; + + ASN_SEQUENCE_ADD(&measResultListNR_r15->list, measResultListNR_r15); + measurementReport->criticalExtensions.choice.c1.choice.measurementReport_r8.measResults.measResultNeighCells->choice.measResultNeighCellListNR_r15 = *(measResultListNR_r15); + + enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_UL_DCCH_Message, + NULL, + (void *)&ul_dcch_msg, + buffer, + RRC_BUF_SIZE); + + if(enc_rval.encoded == -1) { + LOG_I(RRC, "[eNB AssertFatal]ASN1 message encoding failed (%s, %lu)!\n", + enc_rval.failed_type->name, enc_rval.encoded); + free(measResultListNR_r15); + measResultListNR_r15 = NULL; + return -1; + } + + free(measResultListNR_r15); + measResultListNR_r15 = NULL; + return((enc_rval.encoded+7)/8); +} + uint8_t do_DLInformationTransfer(uint8_t Mod_id, uint8_t **buffer, uint8_t transaction_id, uint32_t pdu_length, uint8_t *pdu_buffer) { ssize_t encoded; LTE_DL_DCCH_Message_t dl_dcch_msg; diff --git a/openair2/RRC/LTE/MESSAGES/asn1_msg.h b/openair2/RRC/LTE/MESSAGES/asn1_msg.h index 026f4577dc..35651c4c6d 100644 --- a/openair2/RRC/LTE/MESSAGES/asn1_msg.h +++ b/openair2/RRC/LTE/MESSAGES/asn1_msg.h @@ -343,6 +343,8 @@ uint8_t do_MBSFNAreaConfig(uint8_t Mod_id, uint8_t do_MeasurementReport(uint8_t Mod_id, uint8_t *buffer,int measid,int phy_id,long rsrp_s,long rsrq_s,long rsrp_t,long rsrq_t); +uint8_t do_nrMeasurementReport(uint8_t Mod_id, uint8_t *buffer,int measid,int phy_id,long rsrp_s,long rsrq_s,long rsrp_t,long rsrq_t); + uint8_t do_DLInformationTransfer(uint8_t Mod_id, uint8_t **buffer, uint8_t transaction_id, uint32_t pdu_length, uint8_t *pdu_buffer); uint8_t do_Paging(uint8_t Mod_id, uint8_t *buffer, ue_paging_identity_t ue_paging_identity, cn_domain_t cn_domain); diff --git a/openair2/RRC/LTE/rrc_UE.c b/openair2/RRC/LTE/rrc_UE.c index 5440725dd7..dd920d4fea 100644 --- a/openair2/RRC/LTE/rrc_UE.c +++ b/openair2/RRC/LTE/rrc_UE.c @@ -824,7 +824,6 @@ rrc_ue_process_measConfig( LOG_I(RRC, "Calling nsa_sendmsg_to_nr_ue to send a RRC_MEASUREMENT_PROCEDURE\n"); nsa_sendmsg_to_nrue(buffer, (enc_rval.encoded + 7)/8, RRC_MEASUREMENT_PROCEDURE); } - UE_rrc_inst[ctxt_pP->module_id].MeasObj[eNB_index][ind-1]=measObj; LOG_D(RRC, "Adding measurement object [%d][%ld]\n", eNB_index, ind); ue->MeasObj[eNB_index][ind-1]=measObj; } @@ -4096,8 +4095,7 @@ void ue_meas_filtering( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_ //Below routine implements Measurement Reporting procedure from 36.331 Section 5.5.5 //----------------------------------------------------------------------------- void rrc_ue_generate_MeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t eNB_index ) { - uint8_t buffer[32], size; - uint8_t i; + uint8_t buffer[RRC_BUF_SIZE]; uint8_t target_eNB_offset; LTE_MeasId_t measId; LTE_PhysCellId_t targetCellId; @@ -4111,7 +4109,7 @@ void rrc_ue_generate_MeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t e nElem1 = 35; target_eNB_offset = UE_rrc_inst[ctxt_pP->module_id].Info[0].handoverTarget; // eNB_offset of target eNB: used to obtain the mod_id of target eNB - for (i=0; imodule_id].measReportList[0][i] != NULL) { measId = UE_rrc_inst[ctxt_pP->module_id].measReportList[0][i]->measId; // Note: Values in the meas report have to be the mapped values...to implement binary search for LUT @@ -4119,7 +4117,7 @@ void rrc_ue_generate_MeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t e rsrp_s = binary_search_float(RSRP_meas_mapping,nElem, rsrp_filtered); rsrq_filtered = UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[eNB_index];//nid_cell]; //RSRQ of serving cell rsrq_s = binary_search_float(RSRQ_meas_mapping,nElem1,rsrq_filtered);//mapped RSRQ of serving cell - LOG_D(RRC,"[UE %d] Frame %d: source eNB %d :rsrp_s: %ld rsrq_s: %ld rsrp_filtered: %f rsrq_filtered: %f \n", + LOG_I(RRC,"Melissa [UE %d] Frame %d: source eNB %d :rsrp_s: %ld rsrq_s: %ld rsrp_filtered: %f rsrq_filtered: %f \n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index, @@ -4129,7 +4127,7 @@ void rrc_ue_generate_MeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t e rsrq_filtered); rsrp_t = binary_search_float(RSRP_meas_mapping,nElem,UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[target_eNB_offset]); //RSRP of target cell rsrq_t = binary_search_float(RSRQ_meas_mapping,nElem1,UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[target_eNB_offset]); //RSRQ of target cell - LOG_D(RRC,"[UE %d] Frame %d: target eNB %d :rsrp_t: %ld rsrq_t: %ld rsrp_filtered: %f rsrq_filtered: %f \n", + LOG_I(RRC,"Melissa [UE %d] Frame %d: target eNB %d :rsrp_t: %ld rsrq_t: %ld rsrp_filtered: %f rsrq_filtered: %f \n", ctxt_pP->module_id, ctxt_pP->frame, target_eNB_offset, @@ -4142,7 +4140,7 @@ void rrc_ue_generate_MeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t e if (pframe!=ctxt_pP->frame) { pframe=ctxt_pP->frame; - LOG_D(RRC, "[UE %d] Frame %ld: doing MeasReport: servingCell(%ld) targetCell(%ld) rsrp_s(%ld) rsrq_s(%ld) rsrp_t(%ld) rsrq_t(%ld) \n", + LOG_I(RRC, "[UE %d] Frame %ld: doing MeasReport: servingCell(%ld) targetCell(%ld) rsrp_s(%ld) rsrq_s(%ld) rsrp_t(%ld) rsrq_t(%ld) \n", ctxt_pP->module_id, (long int)ctxt_pP->frame, (long int)get_adjacent_cell_id(ctxt_pP->module_id, eNB_index), @@ -4151,8 +4149,9 @@ void rrc_ue_generate_MeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t e (long int)rsrq_s, (long int)rsrp_t, (long int)rsrq_t); - size = do_MeasurementReport(ctxt_pP->module_id, buffer,measId,targetCellId,rsrp_s,rsrq_s,rsrp_t,rsrq_t); - LOG_I(RRC, "[UE %d] Frame %d : Generating Measurement Report for eNB %d\n", + ssize_t size = do_nrMeasurementReport(ctxt_pP->module_id, buffer,measId,targetCellId,rsrp_s,rsrq_s,rsrp_t,rsrq_t); + AssertFatal(size >= 0, "do_nrMeasurementReport failed \n"); + LOG_I(RRC, "Melissa [UE %d] Frame %d : Generating Measurement Report for eNB %d\n", ctxt_pP->module_id, ctxt_pP->frame, eNB_index); result = pdcp_data_req(ctxt_pP, SRB_FLAG_YES, DCCH, rrc_mui++, 0, size, buffer, PDCP_TRANSMISSION_MODE_DATA,NULL, NULL); AssertFatal (result == TRUE, "PDCP data request failed!\n"); @@ -4165,6 +4164,43 @@ void rrc_ue_generate_MeasurementReport(protocol_ctxt_t *const ctxt_pP, uint8_t e } /* Melissa: also need to generate report based on MeasObj for 5G (can look in eNB for these)*/ } +static bool have_received_nr_meas_msg(void) +{ + return true; +} + +static bool does_rrcConnReconfig_have_nr(const UE_RRC_INST *ue) { + for (int i = 0; i < NB_CNX_UE; i++) { + for (int j = 0; j < MAX_MEAS_ID; j++) { + LTE_ReportConfigId_t reportConfigId = ue->MeasId[i][j]->reportConfigId; + AssertFatal(reportConfigId >= 1 && reportConfigId <= MAX_MEAS_CONFIG, "Bad index\n"); + const LTE_ReportConfigToAddMod_t *rc = ue->ReportConfig[i][reportConfigId-1]; + if (rc == NULL) { + LOG_D(RRC, "UE_rrc_inst[ctxt_pP->module_id]->ReportConfig[%d][%ld] = NULL\n", i, reportConfigId-1); + continue; + } + if (rc->reportConfig.present != LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigInterRAT) { + LOG_D(RRC, "reportConfig.present = %d, not LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigInterRAT\n", + rc->reportConfig.present); + continue; + } + LTE_ReportConfigInterRAT_t irat = rc->reportConfig.choice.reportConfigInterRAT; + if (irat.triggerType.present != LTE_ReportConfigInterRAT__triggerType_PR_event) { + LOG_D(RRC, "irat.triggerType.present = %d, not LTE_ReportConfigInterRAT__triggerType_PR_event\n", + irat.triggerType.present); + continue; + } + if (irat.triggerType.choice.event.eventId.present != LTE_ReportConfigInterRAT__triggerType__event__eventId_PR_eventB1_NR_r15) { + LOG_D(RRC, "irat.triggerType.choice.event.eventId.present = %d\n", + irat.triggerType.choice.event.eventId.present); + continue; + } + return true; + } + } + return false; +} + // Measurement report triggering, described in 36.331 Section 5.5.4.1: called periodically //----------------------------------------------------------------------------- @@ -4177,7 +4213,6 @@ void ue_measurement_report_triggering(protocol_ctxt_t *const ctxt_pP, const uint LTE_Q_OffsetRange_t ofs = 0; LTE_Q_OffsetRange_t ocs = 0; long a3_offset; - LTE_RSRP_RangeNR_r15_t rsrp; LTE_MeasObjectId_t measObjId; LTE_ReportConfigId_t reportConfigId; UE_RRC_INST *ue = &UE_rrc_inst[ctxt_pP->module_id]; @@ -4269,55 +4304,25 @@ void ue_measurement_report_triggering(protocol_ctxt_t *const ctxt_pP, const uint } if (ue->MeasObj[i][measObjId-1]->measObject.present == LTE_MeasObjectToAddMod__measObject_PR_measObjectNR_r15) { - if((ue->ReportConfig[i][reportConfigId-1] != NULL) && - (ue->ReportConfig[i][reportConfigId-1]->reportConfig.present == - LTE_ReportConfigToAddMod__reportConfig_PR_reportConfigInterRAT) && - (ue->ReportConfig[i][reportConfigId-1]->reportConfig.choice.reportConfigInterRAT.triggerType.present == - LTE_ReportConfigInterRAT__triggerType_PR_event)) { + LOG_I(RRC,"[UE %d] Frame %d: B1_NR_r15 event\n", ctxt_pP->module_id, ctxt_pP->frame); + if (does_rrcConnReconfig_have_nr(ue) && have_received_nr_meas_msg()) { + LOG_I(RRC,"[UE %d] Frame %d: Triggering generation of Meas Report for NR_r15\n", + ctxt_pP->module_id, ctxt_pP->frame); - LTE_ReportConfigToAddMod_t *rc = ue->ReportConfig[i][reportConfigId-1]; - hys = rc->reportConfig.choice.reportConfigInterRAT.triggerType.choice.event.hysteresis; - ttt_ms = timeToTrigger_ms[rc->reportConfig.choice.reportConfigInterRAT.triggerType.choice.event.timeToTrigger]; - ofn = 5; - ocn = 0; - rsrp = rc->reportConfig.choice.reportConfigInterRAT.triggerType.choice.event. - eventId.choice.eventB1_NR_r15.b1_ThresholdNR_r15.choice.nr_RSRP_r15; - switch (rc->reportConfig.choice.reportConfigInterRAT.triggerType.choice.event.eventId.present) { - case LTE_ReportConfigInterRAT__triggerType__event__eventId_PR_eventB1_NR_r15: - LOG_I(RRC,"[UE %d] Frame %d : B1_NR_r15 event!\n", ctxt_pP->module_id, ctxt_pP->frame); - if ((check_trigger_meas_event( - ctxt_pP->module_id, - ctxt_pP->frame, - eNB_index, - i, j, ofn, ocn, hys, ofs, ocs, 0, ttt_ms)) && - (ue->Info[0].State >= RRC_CONNECTED) && - (ue->Info[0].T304_active == 0 ) && - (ue->HandoverInfoUe.measFlag == 1)) { - //trigger measurement reporting procedure (36.331, section 5.5.5) - if (ue->measReportList[i][j] == NULL) { - ue->measReportList[i][j] = malloc(sizeof(MEAS_REPORT_LIST)); - } - - ue->measReportList[i][j]->measId = ue->MeasId[i][j]->measId; - ue->measReportList[i][j]->numberOfReportsSent = 0; - rrc_ue_generate_MeasurementReport(ctxt_pP, eNB_index); - ue->HandoverInfoUe.measFlag = 1; - LOG_I(RRC,"[UE %d] Frame %d: RSRB detected, state: %d \n", - ctxt_pP->module_id, ctxt_pP->frame, ue->Info[0].State); - } else { - if(ue->measReportList[i][j] != NULL) { - free(ue->measReportList[i][j]); - } - - ue->measReportList[i][j] = NULL; - } - break; - - default: - LOG_I(RRC,"Invalid LTE_ReportConfigInterRAT__triggerType__event__eventId: %d", - ue->ReportConfig[i][j]->reportConfig.choice.reportConfigEUTRA.triggerType.present); - break; + if (ue->measReportList[i][j] == NULL) { + ue->measReportList[i][j] = malloc(sizeof(MEAS_REPORT_LIST)); } + ue->measReportList[i][j]->measId = ue->MeasId[i][j]->measId; + ue->measReportList[i][j]->numberOfReportsSent = 0; + rrc_ue_generate_MeasurementReport(ctxt_pP, eNB_index); + ue->HandoverInfoUe.measFlag = 1; + LOG_I(RRC,"[UE %d] Frame %d: RSRB detected, state: %d \n", + ctxt_pP->module_id, ctxt_pP->frame, ue->Info[0].State); + } else { + if(ue->measReportList[i][j] != NULL) { + free(ue->measReportList[i][j]); + } + ue->measReportList[i][j] = NULL; } } }