diff --git a/openair2/COMMON/mac_messages_def.h b/openair2/COMMON/mac_messages_def.h index e3ef328017..f342444c65 100644 --- a/openair2/COMMON/mac_messages_def.h +++ b/openair2/COMMON/mac_messages_def.h @@ -60,3 +60,5 @@ MESSAGE_DEF(NR_RRC_MAC_CCCH_DATA_IND, MESSAGE_PRIORITY_MED_PLUS, NRRrcMacCcch MESSAGE_DEF(NR_RRC_MAC_BCCH_DATA_IND, MESSAGE_PRIORITY_MED_PLUS, NRRrcMacBcchDataInd, nr_rrc_mac_bcch_data_ind) MESSAGE_DEF(NR_RRC_MAC_SBCCH_DATA_IND, MESSAGE_PRIORITY_MED_PLUS, NRRrcMacSBcchDataInd, nr_rrc_mac_sbcch_data_ind) +// Message to GNB_APP to update SIB19 satellite position information +MESSAGE_DEF(GNB_SAT_POSITION_UPDATE, MESSAGE_PRIORITY_MED, gnb_sat_position_update_t, gnb_sat_position_update) diff --git a/openair2/COMMON/mac_messages_types.h b/openair2/COMMON/mac_messages_types.h index ebbda2fc26..f5712b115a 100644 --- a/openair2/COMMON/mac_messages_types.h +++ b/openair2/COMMON/mac_messages_types.h @@ -31,6 +31,7 @@ #include #include "OCTET_STRING.h" +#include "NR_MAC_gNB/mac_config.h" //-------------------------------------------------------------------------------------------// // Defines to access message fields. @@ -61,6 +62,8 @@ #define RRC_MAC_DRX_CONFIG_REQ(mSGpTR) (mSGpTR)->ittiMsg.rrc_mac_drx_config_req +#define GNB_SAT_POSITION_UPDATE(mSGpTR) (mSGpTR)->ittiMsg.gnb_sat_position_update + // Some constants from "LAYER2/MAC/defs.h" #define BCCH_SDU_SIZE (512) #define BCCH_SDU_MBMS_SIZE (512) diff --git a/openair2/GNB_APP/gnb_app.c b/openair2/GNB_APP/gnb_app.c index e90a83d3bc..3b97dfe515 100644 --- a/openair2/GNB_APP/gnb_app.c +++ b/openair2/GNB_APP/gnb_app.c @@ -212,6 +212,11 @@ void *gNB_app_task(void *args_p) LOG_I(GNB_APP, " Received %s: timer_id %ld\n", msg_name, TIMER_HAS_EXPIRED(msg_p).timer_id); break; + case GNB_SAT_POSITION_UPDATE: + LOG_I(GNB_APP, " Received GNB_SAT_POSITION_UPDATE message\n"); + nr_update_sib19(&GNB_SAT_POSITION_UPDATE(msg_p)); + break; + default: LOG_E(GNB_APP, "Received unexpected message %s\n", msg_name); break; diff --git a/openair2/LAYER2/NR_MAC_gNB/config.c b/openair2/LAYER2/NR_MAC_gNB/config.c index f87b4024b9..8224170271 100644 --- a/openair2/LAYER2/NR_MAC_gNB/config.c +++ b/openair2/LAYER2/NR_MAC_gNB/config.c @@ -927,6 +927,96 @@ bool nr_mac_configure_other_sib(gNB_MAC_INST *nrmac, int num_cu_sib, const f1ap_ return true; } +bool nr_update_sib19(const gnb_sat_position_update_t *sat_position) +{ + gNB_MAC_INST *nrmac = RC.nrmac[0]; + NR_COMMON_channels_t *cc = &nrmac->common_channels[0]; + NR_ServingCellConfigCommon_t *scc = cc->ServingCellConfigCommon; + + if (!scc || !scc->ext2 || !scc->ext2->ntn_Config_r17) + return false; + + const vector_t *pos = &sat_position->position; + const vector_t *vel = &sat_position->velocity; + + LOG_D(NR_MAC, "SFN = %d, SubFrame = %d\n", sat_position->sfn, sat_position->subframe); + LOG_D(NR_MAC, "TA_Common: value %d, %f msec\n", sat_position->delay, sat_position->delay * 4.072e-6); + LOG_D(NR_MAC, "TA_CommonDrift: value %d, = %f µsec/sec\n", sat_position->drift, sat_position->drift * 0.2e-3); + LOG_D(NR_MAC, "TA_CommonDriftVariant: value %d, %f µsec/sec^2\n", sat_position->accel, sat_position->accel * 0.2e-4); + LOG_D(NR_MAC, "SAT Position: values %d/%d/%d, %.3f/%3f/%3f metres in X/Y/Z\n", pos->X, pos->Y, pos->Z, pos->X * 1.3, pos->Y * 1.3, pos->Z * 1.3); + LOG_D(NR_MAC, "SAT Velocity: values %d/%d/%d, %.3f/%3f/%3f m/s in X/Y/Z\n", vel->X, vel->Y, vel->Z, vel->X * 0.06, vel->Y * 0.06, vel->Z * 0.06); + + NR_SCHED_LOCK(&nrmac->sched_lock); + + if (!scc->ext2->ntn_Config_r17->epochTime_r17) + scc->ext2->ntn_Config_r17->epochTime_r17 = calloc (1, sizeof(*scc->ext2->ntn_Config_r17->epochTime_r17)); + + NR_EpochTime_r17_t *epoch_time_r17 = scc->ext2->ntn_Config_r17->epochTime_r17; + epoch_time_r17->sfn_r17 = sat_position->sfn; + epoch_time_r17->subFrameNR_r17 = sat_position->subframe; + + if (!scc->ext2->ntn_Config_r17->ta_Info_r17) + scc->ext2->ntn_Config_r17->ta_Info_r17 = calloc(1, sizeof(*scc->ext2->ntn_Config_r17->ta_Info_r17)); + + NR_TA_Info_r17_t *sib19_ta_info = scc->ext2->ntn_Config_r17->ta_Info_r17; + + // SIB19 provides Round trip delay on feeder link (between gNB and SAT). + sib19_ta_info->ta_Common_r17 = sat_position->delay; + + if (sat_position->drift) { + if (!sib19_ta_info->ta_CommonDrift_r17) + sib19_ta_info->ta_CommonDrift_r17 = calloc(1, sizeof(*sib19_ta_info->ta_CommonDrift_r17)); + *sib19_ta_info->ta_CommonDrift_r17 = sat_position->drift; + } else + free_and_zero(sib19_ta_info->ta_CommonDrift_r17); + + if (sat_position->accel) { + if (!sib19_ta_info->ta_CommonDriftVariant_r17) + sib19_ta_info->ta_CommonDriftVariant_r17 = calloc(1, sizeof(*sib19_ta_info->ta_CommonDriftVariant_r17)); + *sib19_ta_info->ta_CommonDriftVariant_r17 = sat_position->accel; + } else + free_and_zero(sib19_ta_info->ta_CommonDriftVariant_r17); + + // Currently PositionVelocity is supported and not yet the OrbitalParams + if (!scc->ext2->ntn_Config_r17->ephemerisInfo_r17) { + scc->ext2->ntn_Config_r17->ephemerisInfo_r17 = calloc(1, sizeof(*scc->ext2->ntn_Config_r17->ephemerisInfo_r17)); + scc->ext2->ntn_Config_r17->ephemerisInfo_r17->present = NR_EphemerisInfo_r17_PR_NOTHING; + } + if (scc->ext2->ntn_Config_r17->ephemerisInfo_r17->present == NR_EphemerisInfo_r17_PR_orbital_r17) { + ASN_STRUCT_FREE(asn_DEF_NR_Orbital_r17, scc->ext2->ntn_Config_r17->ephemerisInfo_r17->choice.orbital_r17); + scc->ext2->ntn_Config_r17->ephemerisInfo_r17->choice.orbital_r17 = NULL; + scc->ext2->ntn_Config_r17->ephemerisInfo_r17->present = NR_EphemerisInfo_r17_PR_NOTHING; + } + if (!scc->ext2->ntn_Config_r17->ephemerisInfo_r17->choice.positionVelocity_r17) + scc->ext2->ntn_Config_r17->ephemerisInfo_r17->choice.positionVelocity_r17 = + calloc(1, sizeof(*scc->ext2->ntn_Config_r17->ephemerisInfo_r17->choice.positionVelocity_r17)); + + scc->ext2->ntn_Config_r17->ephemerisInfo_r17->present = NR_EphemerisInfo_r17_PR_positionVelocity_r17; + NR_PositionVelocity_r17_t *sib19_PosVel = scc->ext2->ntn_Config_r17->ephemerisInfo_r17->choice.positionVelocity_r17; + + sib19_PosVel->positionX_r17 = pos->X; + sib19_PosVel->positionY_r17 = pos->Y; + sib19_PosVel->positionZ_r17 = pos->Z; + sib19_PosVel->velocityVX_r17 = vel->X; + sib19_PosVel->velocityVY_r17 = vel->Y; + sib19_PosVel->velocityVZ_r17 = vel->Z; + + NR_SystemInformation_IEs_t *sysInfov17 = calloc(1, sizeof(*sysInfov17)); // for othersibs + struct NR_SystemInformation_IEs__sib_TypeAndInfo__Member *type_du = calloc(1, sizeof(*type_du)); + type_du->present = NR_SystemInformation_IEs__sib_TypeAndInfo__Member_PR_sib19_v1700; + NR_SIB19_r17_t *sib19 = get_SIB19_NR(cc->ServingCellConfigCommon); + type_du->choice.sib19_v1700 = sib19; + add_sib_to_systeminformation(sysInfov17, type_du); + + cc->other_sib_bcch_length[1] = encode_sysinfo_ie(sysInfov17, cc->other_sib_bcch_pdu[1], sizeof(cc->other_sib_bcch_pdu[1])); + AssertFatal(cc->other_sib_bcch_length[1] > 0, "could not encode SIB19\n"); + ASN_STRUCT_FREE(asn_DEF_NR_SystemInformation_IEs, sysInfov17); + + NR_SCHED_UNLOCK(&nrmac->sched_lock); + + return true; +} + void prepare_du_configuration_update(gNB_MAC_INST *mac, f1ap_served_cell_info_t *info, NR_BCCH_BCH_Message_t *mib, diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_config.h b/openair2/LAYER2/NR_MAC_gNB/mac_config.h new file mode 100644 index 0000000000..1fdbe62115 --- /dev/null +++ b/openair2/LAYER2/NR_MAC_gNB/mac_config.h @@ -0,0 +1,46 @@ +/* + * 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 __LAYER2_NR_MAC_CONFIG_H__ +#define __LAYER2_NR_MAC_CONFIG_H__ + +#include + +typedef struct vector_s { + int X; + int Y; + int Z; +} vector_t; + +// Format similar to values sent in SIB19 +typedef struct gnb_sat_position_update_s { + int sfn; + int subframe; + uint32_t delay; + int drift; + uint32_t accel; + vector_t position; + vector_t velocity; +} gnb_sat_position_update_t; + +bool nr_update_sib19(const gnb_sat_position_update_t *sat_position); + +#endif /*__LAYER2_NR_MAC_CONFIG_H__*/ diff --git a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h index 3918e0215c..64bdb86980 100644 --- a/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h +++ b/openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h @@ -88,6 +88,7 @@ /* MAC */ #include "LAYER2/NR_MAC_COMMON/nr_mac_common.h" +#include "LAYER2/NR_MAC_gNB/mac_config.h" #include "NR_TAG.h" /* Defs */