From 698ff73c7f2e8baa2aa6f746091365d2c9e478fb Mon Sep 17 00:00:00 2001 From: Roberto Rosca Date: Mon, 16 Sep 2024 14:51:55 +0300 Subject: [PATCH] Added SIB19 related calculations on UE --- openair2/LAYER2/NR_MAC_UE/config_ue.c | 40 ++++++++++++++++++++++---- openair2/LAYER2/NR_MAC_UE/main_ue_nr.c | 23 --------------- openair2/RRC/NR_UE/rrc_UE.c | 7 +++-- 3 files changed, 39 insertions(+), 31 deletions(-) diff --git a/openair2/LAYER2/NR_MAC_UE/config_ue.c b/openair2/LAYER2/NR_MAC_UE/config_ue.c index b430727955..fb027c2083 100644 --- a/openair2/LAYER2/NR_MAC_UE/config_ue.c +++ b/openair2/LAYER2/NR_MAC_UE/config_ue.c @@ -31,6 +31,7 @@ */ #define _GNU_SOURCE +#define SPEED_OF_LIGHT 299792458 //#include "mac_defs.h" #include @@ -41,6 +42,7 @@ #include "executables/softmodem-common.h" #include "SCHED_NR/phy_frame_config_nr.h" #include "oai_asn1.h" +#include "executables/position_interface.h" void set_tdd_config_nr_ue(fapi_nr_tdd_table_t *tdd_table, int mu, @@ -1746,15 +1748,43 @@ void nr_rrc_mac_config_req_sib1(module_id_t module_id, AssertFatal(!ret, "mutex failed %d\n", ret); } -void nr_rrc_mac_config_req_sib19_r17(module_id_t module_id, - NR_SIB19_r17_t *sib19_r17) +// computes delay between ue and sat based on SIB19 ephemeris data +static double calculate_ue_sat_ta(position_t *position_params, struct NR_PositionVelocity_r17 *sat_pos) +{ + // get UE position coordinates + double posx = position_params->positionX; + double posy = position_params->positionY; + double posz = position_params->positionZ; + + // get sat position coordinates + double posx_0 = (double)sat_pos->positionX_r17 * 1.3; + double posy_0 = (double)sat_pos->positionY_r17 * 1.3; + double posz_0 = (double)sat_pos->positionZ_r17 * 1.3; + + double distance = sqrt(pow(posx - posx_0, 2) + pow(posy - posy_0, 2) + pow(posz - posz_0, 2)); + // this computation will ensure 3 decimal precision + double ta_ms = round(((distance / SPEED_OF_LIGHT) * 1000) * 1000.0) / 1000.0; + + return ta_ms; +} + +void nr_rrc_mac_config_req_sib19_r17(module_id_t module_id, NR_SIB19_r17_t *sib19_r17) { NR_UE_MAC_INST_t *mac = get_mac_inst(module_id); - // ntn-Config-r17 - UPDATE_IE(mac->sc_info.ntn_Config_r17, sib19_r17->ntn_Config_r17, NR_NTN_Config_r17_t); + // ntn-Config-r17 deep copy into mac + asn_copy(&asn_DEF_NR_NTN_Config_r17, (void **)&mac->sc_info.ntn_Config_r17, sib19_r17->ntn_Config_r17); - // TODO handle other SIB19 elements + // if ephemerisInfo_r17 present in SIB19 + if (mac->sc_info.ntn_Config_r17->ephemerisInfo_r17 && mac->sc_info.ntn_Config_r17->ephemerisInfo_r17->choice.positionVelocity_r17 + && (mac->sc_info.ntn_Config_r17->ephemerisInfo_r17->choice.positionVelocity_r17->positionX_r17 != 0 + || mac->sc_info.ntn_Config_r17->ephemerisInfo_r17->choice.positionVelocity_r17->positionY_r17 != 0 + || mac->sc_info.ntn_Config_r17->ephemerisInfo_r17->choice.positionVelocity_r17->positionZ_r17 != 0)) { + get_nrUE_params()->ntn_ta_common = + calculate_ue_sat_ta(get_position(module_id), mac->sc_info.ntn_Config_r17->ephemerisInfo_r17->choice.positionVelocity_r17); + } + + get_nrUE_params()->ntn_koffset = *mac->sc_info.ntn_Config_r17->cellSpecificKoffset_r17; } static void handle_reconfiguration_with_sync(NR_UE_MAC_INST_t *mac, diff --git a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c index 76dd88d07d..064fcc4e78 100644 --- a/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c +++ b/openair2/LAYER2/NR_MAC_UE/main_ue_nr.c @@ -86,29 +86,6 @@ void nr_ue_init_mac(NR_UE_MAC_INST_t *mac) mac->pucch_power_control_initialized = false; mac->pusch_power_control_initialized = false; - - // Fake SIB19 reception for NTN - // TODO: remove this and implement the actual SIB19 reception instead! - if (get_nrUE_params()->ntn_koffset || get_nrUE_params()->ntn_ta_common || get_nrUE_params()->ntn_ta_commondrift) { - NR_SIB19_r17_t *sib19_r17 = calloc(1, sizeof(*sib19_r17)); - sib19_r17->ntn_Config_r17 = calloc(1, sizeof(*sib19_r17->ntn_Config_r17)); - - // NTN cellSpecificKoffset-r17 - if (get_nrUE_params()->ntn_koffset) { - asn1cCallocOne(sib19_r17->ntn_Config_r17->cellSpecificKoffset_r17, get_nrUE_params()->ntn_koffset); - } - - // NTN ta-Common-r17 - if (get_nrUE_params()->ntn_ta_common || get_nrUE_params()->ntn_ta_commondrift) { - sib19_r17->ntn_Config_r17->ta_Info_r17 = calloc(1, sizeof(*sib19_r17->ntn_Config_r17->ta_Info_r17)); - sib19_r17->ntn_Config_r17->ta_Info_r17->ta_Common_r17 = get_nrUE_params()->ntn_ta_common / 4.072e-6; // ta-Common-r17 is in units of 4.072e-3 µs, ntn_ta_common is in ms - if (get_nrUE_params()->ntn_ta_commondrift) - asn1cCallocOne(sib19_r17->ntn_Config_r17->ta_Info_r17->ta_CommonDrift_r17, get_nrUE_params()->ntn_ta_commondrift / 0.2e-3); // is in units of 0.2e-3 µs/s, ntn_ta_commondrift is in µs/s - } - - nr_rrc_mac_config_req_sib19_r17(mac->ue_id, sib19_r17); - asn1cFreeStruc(asn_DEF_NR_SIB19_r17, sib19_r17); - } } void nr_ue_mac_default_configs(NR_UE_MAC_INST_t *mac) diff --git a/openair2/RRC/NR_UE/rrc_UE.c b/openair2/RRC/NR_UE/rrc_UE.c index b46da32374..70708625f7 100644 --- a/openair2/RRC/NR_UE/rrc_UE.c +++ b/openair2/RRC/NR_UE/rrc_UE.c @@ -165,7 +165,7 @@ static void set_DRB_status(NR_UE_RRC_INST_t *rrc, NR_DRB_Identity_t drb_id, NR_R rrc->status_DRBs[drb_id - 1] = status; } -static void nr_decode_SI(NR_UE_RRC_SI_INFO *SI_info, NR_SystemInformation_t *si) +static void nr_decode_SI(NR_UE_RRC_SI_INFO *SI_info, NR_SystemInformation_t *si, instance_t ue_id) { VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_UE_DECODE_SI, VCD_FUNCTION_IN); @@ -241,6 +241,7 @@ static void nr_decode_SI(NR_UE_RRC_SI_INFO *SI_info, NR_SystemInformation_t *si) SI_info->SInfo_r17.sib19_validity = true; if (g_log->log_component[NR_RRC].level >= OAILOG_DEBUG) xer_fprint(stdout, &asn_DEF_NR_SIB19_r17, (const void *)typeandinfo->choice.sib19_v1700); + nr_rrc_mac_config_req_sib19_r17(ue_id, typeandinfo->choice.sib19_v1700); nr_timer_start(&SI_info->SInfo_r17.sib19_timer); break; default: @@ -386,7 +387,7 @@ static void nr_rrc_process_reconfiguration_v1530(NR_UE_RRC_INST_t *rrc, NR_RRCRe SEQUENCE_free(&asn_DEF_NR_SystemInformation, si, 1); } else { LOG_I(NR_RRC, "[UE %ld] Decoding dedicatedSystemInformationDelivery\n", rrc->ue_id); - nr_decode_SI(SI_info, si); + nr_decode_SI(SI_info, si, rrc->ue_id); } } if (rec_1530->otherConfig) { @@ -895,7 +896,7 @@ static int8_t nr_rrc_ue_decode_NR_BCCH_DL_SCH_Message(NR_UE_RRC_INST_t *rrc, case NR_BCCH_DL_SCH_MessageType__c1_PR_systemInformation: LOG_I(NR_RRC, "[UE %ld] Decoding SI\n", rrc->ue_id); NR_SystemInformation_t *si = bcch_message->message.choice.c1->choice.systemInformation; - nr_decode_SI(SI_info, si); + nr_decode_SI(SI_info, si, rrc->ue_id); break; case NR_BCCH_DL_SCH_MessageType__c1_PR_NOTHING: default: