From 18db5f68aca138b9f6491525ebe11761af47b7af Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Wed, 23 Aug 2023 08:59:59 +0200 Subject: [PATCH] Put PLMN/TAC/CellID into SIB1, correct CellIdentity encoding --- openair2/LAYER2/NR_MAC_gNB/config.c | 12 ++++++++++++ openair2/LAYER2/NR_MAC_gNB/mac_proto.h | 2 ++ openair2/LAYER2/NR_MAC_gNB/main.c | 6 ------ openair2/RRC/NR/nr_rrc_config.c | 20 +++++++++----------- openair2/RRC/NR/nr_rrc_config.h | 2 +- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/openair2/LAYER2/NR_MAC_gNB/config.c b/openair2/LAYER2/NR_MAC_gNB/config.c index 6ea3e10458..a04ffad88d 100644 --- a/openair2/LAYER2/NR_MAC_gNB/config.c +++ b/openair2/LAYER2/NR_MAC_gNB/config.c @@ -557,6 +557,18 @@ void nr_mac_config_scc(gNB_MAC_INST *nrmac, NR_ServingCellConfigCommon_t *scc, c //NR_SCHED_UNLOCK(&nrmac->sched_lock); } +void nr_mac_configure_sib1(gNB_MAC_INST *nrmac, const f1ap_plmn_t *plmn, uint64_t cellID, int tac) +{ + AssertFatal(get_softmodem_params()->sa > 0, "error: SIB1 only applicable for SA\n"); + + NR_COMMON_channels_t *cc = &nrmac->common_channels[0]; + NR_ServingCellConfigCommon_t *scc = cc->ServingCellConfigCommon; + NR_BCCH_DL_SCH_Message_t *sib1 = get_SIB1_NR(scc, plmn, cellID, tac); + cc->sib1 = sib1; + cc->sib1_bcch_length = encode_SIB1_NR(sib1, cc->sib1_bcch_pdu, sizeof(cc->sib1_bcch_pdu)); + AssertFatal(cc->sib1_bcch_length > 0, "could not encode SIB1\n"); +} + bool nr_mac_add_test_ue(gNB_MAC_INST *nrmac, uint32_t rnti, NR_CellGroupConfig_t *CellGroup) { DevAssert(nrmac != NULL); diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h index 6d0896427a..386788170b 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h @@ -50,6 +50,8 @@ int nr_mac_enable_ue_rrc_processing_timer(module_id_t Mod_idP, uint32_t rrc_reconfiguration_delay); void nr_mac_config_scc(gNB_MAC_INST *nrmac, NR_ServingCellConfigCommon_t *scc, const nr_mac_config_t *mac_config); +void nr_mac_configure_sib1(gNB_MAC_INST *nrmac, const f1ap_plmn_t *plmn, uint64_t cellID, int tac); + bool nr_mac_add_test_ue(gNB_MAC_INST *nrmac, uint32_t rnti, NR_CellGroupConfig_t *CellGroup); bool nr_mac_prepare_ra_ue(gNB_MAC_INST *nrmac, uint32_t rnti, NR_CellGroupConfig_t *CellGroup); bool nr_mac_update_cellgroup(gNB_MAC_INST *nrmac, uint32_t rnti, NR_CellGroupConfig_t *CellGroup); diff --git a/openair2/LAYER2/NR_MAC_gNB/main.c b/openair2/LAYER2/NR_MAC_gNB/main.c index 960310ff9a..f38e70d66e 100644 --- a/openair2/LAYER2/NR_MAC_gNB/main.c +++ b/openair2/LAYER2/NR_MAC_gNB/main.c @@ -255,12 +255,6 @@ void mac_top_init_gNB(ngran_node_t node_type, RC.nrmac[i]->cset0_bwp_start = 0; RC.nrmac[i]->cset0_bwp_size = 0; - NR_BCCH_DL_SCH_Message_t *sib1 = get_SIB1_NR(config, scc); - NR_COMMON_channels_t *cc = &RC.nrmac[i]->common_channels[0]; - cc->sib1 = sib1; - cc->sib1_bcch_length = encode_SIB1_NR(sib1, cc->sib1_bcch_pdu, sizeof(cc->sib1_bcch_pdu)); - AssertFatal(cc->sib1_bcch_length > 0, "could not encode SIB1\n"); - pthread_mutex_init(&RC.nrmac[i]->sched_lock, NULL); pthread_mutex_init(&RC.nrmac[i]->UE_info.mutex, NULL); diff --git a/openair2/RRC/NR/nr_rrc_config.c b/openair2/RRC/NR/nr_rrc_config.c index 97bfa73547..d1c55d17cf 100644 --- a/openair2/RRC/NR/nr_rrc_config.c +++ b/openair2/RRC/NR/nr_rrc_config.c @@ -28,6 +28,7 @@ * \email: raymond.knopp@eurecom.fr, kroempa@gmail.com */ +#include "openair3/UTILS/conversions.h" #include "nr_rrc_config.h" #include "common/utils/nr/nr_common.h" #include "openair2/LAYER2/NR_MAC_gNB/nr_mac_gNB.h" @@ -1713,8 +1714,10 @@ int encode_MIB_NR(NR_BCCH_BCH_Message_t *mib, int frame, uint8_t *buf, int buf_s return (enc_rval.encoded + 7) / 8; } -NR_BCCH_DL_SCH_Message_t *get_SIB1_NR(const nr_mac_config_t *configuration, const NR_ServingCellConfigCommon_t *scc) +NR_BCCH_DL_SCH_Message_t *get_SIB1_NR(const NR_ServingCellConfigCommon_t *scc, const f1ap_plmn_t *plmn, uint64_t cellID, int tac) { + AssertFatal(cellID < (1l << 36), "cellID must fit within 36 bits, but is %ld\n", cellID); + NR_BCCH_DL_SCH_Message_t *sib1_message = CALLOC(1,sizeof(NR_BCCH_DL_SCH_Message_t)); AssertFatal(sib1_message != NULL, "out of memory\n"); sib1_message->message.present = NR_BCCH_DL_SCH_MessageType_PR_c1; @@ -1741,15 +1744,15 @@ NR_BCCH_DL_SCH_Message_t *get_SIB1_NR(const nr_mac_config_t *configuration, cons for (int i = 0; i < num_plmn; ++i) { asn1cSequenceAdd(nr_plmn_info->plmn_IdentityList.list, struct NR_PLMN_Identity, nr_plmn); asn1cCalloc(nr_plmn->mcc, mcc); - int confMcc = 0; + int confMcc = plmn->mcc; asn1cSequenceAdd(mcc->list, NR_MCC_MNC_Digit_t, mcc0); *mcc0 = (confMcc / 100) % 10; asn1cSequenceAdd(mcc->list, NR_MCC_MNC_Digit_t, mcc1); *mcc1 = (confMcc / 10) % 10; asn1cSequenceAdd(mcc->list, NR_MCC_MNC_Digit_t, mcc2); *mcc2 = confMcc % 10; - int mnc = 0; - if (0 == 3) { + int mnc = plmn->mnc; + if (plmn->mnc_digit_length == 3) { asn1cSequenceAdd(nr_plmn->mnc.list, NR_MCC_MNC_Digit_t, mnc0); *mnc0 = (0 / 100) % 10; } @@ -1759,17 +1762,12 @@ NR_BCCH_DL_SCH_Message_t *get_SIB1_NR(const nr_mac_config_t *configuration, cons *mnc2 = (mnc) % 10; } - nr_plmn_info->cellIdentity.buf = CALLOC(1, 5); - AssertFatal(nr_plmn_info->cellIdentity.buf != NULL, "out of memory\n"); - nr_plmn_info->cellIdentity.size = 5; - nr_plmn_info->cellIdentity.bits_unused = 4; - uint64_t tmp = htobe64(0) << 4; - memcpy(nr_plmn_info->cellIdentity.buf, ((char *)&tmp) + 3, 5); + NR_CELL_ID_TO_BIT_STRING(cellID, &nr_plmn_info->cellIdentity); nr_plmn_info->cellReservedForOperatorUse = NR_PLMN_IdentityInfo__cellReservedForOperatorUse_notReserved; nr_plmn_info->trackingAreaCode = CALLOC(1, sizeof(NR_TrackingAreaCode_t)); AssertFatal(nr_plmn_info->trackingAreaCode != NULL, "out of memory\n"); - uint32_t tmp2 = htobe32(0); + uint32_t tmp2 = htobe32(tac); nr_plmn_info->trackingAreaCode->buf = CALLOC(1, 3); AssertFatal(nr_plmn_info->trackingAreaCode->buf != NULL, "out of memory\n"); memcpy(nr_plmn_info->trackingAreaCode->buf, ((char *)&tmp2) + 1, 3); diff --git a/openair2/RRC/NR/nr_rrc_config.h b/openair2/RRC/NR/nr_rrc_config.h index ae1e31743e..802d57428c 100644 --- a/openair2/RRC/NR/nr_rrc_config.h +++ b/openair2/RRC/NR/nr_rrc_config.h @@ -57,7 +57,7 @@ int encode_MIB_NR(NR_BCCH_BCH_Message_t *mib, int frame, uint8_t *buf, int buf_s #define NR_MAX_SIB_LENGTH 2976 // 3GPP TS 38.331 section 5.2.1 -NR_BCCH_DL_SCH_Message_t *get_SIB1_NR(const nr_mac_config_t *configuration, const NR_ServingCellConfigCommon_t *scc); +NR_BCCH_DL_SCH_Message_t *get_SIB1_NR(const NR_ServingCellConfigCommon_t *scc, const f1ap_plmn_t *plmn, uint64_t cellID, int tac); void free_SIB1_NR(NR_BCCH_DL_SCH_Message_t *sib1); int encode_SIB1_NR(NR_BCCH_DL_SCH_Message_t *sib1, uint8_t *buffer, int max_buffer_size);