Memory handling fixes [Issue-ID: ODUHIGH-337]
[o-du/l2.git] / src / du_app / du_cfg.c
index 617743e..e9e8c26 100644 (file)
 #include "BWP-DownlinkCommon.h"
 #include "BWP-UplinkCommon.h"
 
+#ifdef O1_ENABLE
+#include "ConfigInterface.h"
+extern StartupConfig g_cfg;
+#endif
+
 DuCfgParams duCfgParam;
 char encBuf[ENC_BUF_MAX_LEN];
 
@@ -146,7 +151,11 @@ uint8_t readMacCfg()
 
    /* DL carrier configuration */
    duCfgParam.macCellCfg.dlCarrCfg.pres = TRUE;
+#ifdef NR_TDD
+   duCfgParam.macCellCfg.dlCarrCfg.bw = BANDWIDTH_100MHZ;
+#else
    duCfgParam.macCellCfg.dlCarrCfg.bw = BANDWIDTH_20MHZ;
+#endif
    duCfgParam.macCellCfg.dlCarrCfg.freq = NR_DL_ARFCN;
    duCfgParam.macCellCfg.dlCarrCfg.k0[0] = 1;
    duCfgParam.macCellCfg.dlCarrCfg.k0[1] = 1;
@@ -162,7 +171,11 @@ uint8_t readMacCfg()
 
    /* UL Carrier configuration */
    duCfgParam.macCellCfg.ulCarrCfg.pres = TRUE;
+#ifdef NR_TDD
+   duCfgParam.macCellCfg.dlCarrCfg.bw = BANDWIDTH_100MHZ;
+#else
    duCfgParam.macCellCfg.ulCarrCfg.bw = BANDWIDTH_20MHZ;
+#endif
    duCfgParam.macCellCfg.ulCarrCfg.freq = NR_UL_ARFCN;
    duCfgParam.macCellCfg.ulCarrCfg.k0[0] = 1;
    duCfgParam.macCellCfg.ulCarrCfg.k0[1] = 1;
@@ -181,7 +194,11 @@ uint8_t readMacCfg()
    /* SSB configuration */
    duCfgParam.macCellCfg.ssbCfg.ssbPbchPwr = SSB_PBCH_PWR;
    duCfgParam.macCellCfg.ssbCfg.bchPayloadFlag = BCH_PAYLOAD;
-   duCfgParam.macCellCfg.ssbCfg.scsCmn = SUBCARRIER_SPACING;
+#ifdef NR_TDD
+   duCfgParam.macCellCfg.ssbCfg.scsCmn = SCS_30KHZ;
+#else
+   duCfgParam.macCellCfg.ssbCfg.scsCmn = SCS_15KHZ;
+#endif
    duCfgParam.macCellCfg.ssbCfg.ssbOffsetPointA = OFFSET_TO_POINT_A;
    duCfgParam.macCellCfg.ssbCfg.betaPss = BETA_PSS;
    duCfgParam.macCellCfg.ssbCfg.ssbPeriod = SSB_PRDCTY_MS_20;
@@ -250,7 +267,6 @@ uint8_t readMacCfg()
    DU_ALLOC_SHRABL_BUF(duCfgParam.macCellCfg.sib1Cfg.sib1Pdu,duCfgParam.srvdCellLst[0].duSysInfo.sib1Len);
    memcpy(duCfgParam.macCellCfg.sib1Cfg.sib1Pdu, duCfgParam.srvdCellLst[0].duSysInfo.sib1Msg, \
         duCfgParam.srvdCellLst[0].duSysInfo.sib1Len);
-   duCfgParam.macCellCfg.sib1Cfg.sib1NewTxPeriod = SIB1_NEW_TX_PERIOD;
    duCfgParam.macCellCfg.sib1Cfg.sib1RepetitionPeriod = SIB1_REPETITION_PERIOD;
    duCfgParam.macCellCfg.sib1Cfg.coresetZeroIndex = CORESET_0_INDEX;
    duCfgParam.macCellCfg.sib1Cfg.searchSpaceZeroIndex = SEARCHSPACE_0_INDEX;
@@ -260,7 +276,11 @@ uint8_t readMacCfg()
    /* fill Intial DL BWP */
    duCfgParam.macCellCfg.initialDlBwp.bwp.firstPrb = 0;
    duCfgParam.macCellCfg.initialDlBwp.bwp.numPrb = TOTAL_PRB_20MHZ_MU0; /* configured to total BW */
-   duCfgParam.macCellCfg.initialDlBwp.bwp.scs = SUBCARRIER_SPACING; /* numerology is 0, 15Khz */
+#ifdef NR_TDD
+   duCfgParam.macCellCfg.initialDlBwp.bwp.scs = SCS_30KHZ; /* numerology is 1, 30Khz */
+#else
+   duCfgParam.macCellCfg.initialDlBwp.bwp.scs = SCS_15KHZ; /* numerology is 0, 15Khz */
+#endif
    duCfgParam.macCellCfg.initialDlBwp.bwp.cyclicPrefix = NORMAL_CYCLIC_PREFIX;
    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId = SEARCHSPACE_1_INDEX;
    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.coresetId = CORESET_0_INDEX;
@@ -292,7 +312,11 @@ uint8_t readMacCfg()
    /* fill Intial UL BWP */
    duCfgParam.macCellCfg.initialUlBwp.bwp.firstPrb = 0;
    duCfgParam.macCellCfg.initialUlBwp.bwp.numPrb = TOTAL_PRB_20MHZ_MU0; /* configured to total BW */
-   duCfgParam.macCellCfg.initialUlBwp.bwp.scs = SUBCARRIER_SPACING; /* numerology is 0, 15Khz */
+#ifdef NR_TDD
+   duCfgParam.macCellCfg.initialUlBwp.bwp.scs = SCS_30KHZ; /* numerology is 1, 30Khz */
+#else
+   duCfgParam.macCellCfg.initialUlBwp.bwp.scs = SCS_15KHZ; /* numerology is 0, 15Khz */
+#endif
    duCfgParam.macCellCfg.initialUlBwp.bwp.cyclicPrefix = NORMAL_CYCLIC_PREFIX;
    duCfgParam.macCellCfg.initialUlBwp.puschCommon.k2 = PUSCH_K2;
    duCfgParam.macCellCfg.initialUlBwp.puschCommon.mappingType = 
@@ -328,9 +352,14 @@ uint8_t readMacCfg()
  * ****************************************************************/
 uint8_t fillDuPort(uint16_t *duPort)
 {
+
+#ifdef O1_ENABLE
+   duPort[F1_INTERFACE]   = g_cfg.DU_Port;
+   duPort[E2_INTERFACE]   = g_cfg.RIC_Port;
+#else
    duPort[F1_INTERFACE]   = DU_PORT;     /* DU Port idx  0 38472 */
    duPort[E2_INTERFACE]   = RIC_PORT;    /* RIC Port idx 1 38482 */
-
+#endif
    return ROK;
 }
 
@@ -393,11 +422,16 @@ uint8_t fillServCellCfgCommSib(SrvCellCfgCommSib *srvCellCfgComm)
    TddUlDlCfgCommon   tddCfg;
 
    /* Configuring DL Config Common for SIB1*/
-   srvCellCfgComm->dlCfg.freqBandInd = NR_FREQ_BAND_IND
+   srvCellCfgComm->dlCfg.freqBandInd = NR_FREQ_BAND; 
    srvCellCfgComm->dlCfg.offsetToPointA = OFFSET_TO_POINT_A;
    srvCellCfgComm->dlCfg.dlScsCarrier.scsOffset = SSB_SUBCARRIER_OFFSET;
-   srvCellCfgComm->dlCfg.dlScsCarrier.scs = SUBCARRIER_SPACING;
+#ifdef NR_TDD
+   srvCellCfgComm->dlCfg.dlScsCarrier.scs = SCS_30KHZ;
+   srvCellCfgComm->dlCfg.dlScsCarrier.scsBw = BANDWIDTH_100MHZ;
+#else
+   srvCellCfgComm->dlCfg.dlScsCarrier.scs = SCS_15KHZ;
    srvCellCfgComm->dlCfg.dlScsCarrier.scsBw = BANDWIDTH_20MHZ;
+#endif
    srvCellCfgComm->dlCfg.locAndBw = FREQ_LOC_BW;
 
    /* Configuring PDCCH Config Common For SIB1 */
@@ -445,8 +479,13 @@ uint8_t fillServCellCfgCommSib(SrvCellCfgCommSib *srvCellCfgComm)
 
    /* Configuring UL Config Common */
    srvCellCfgComm->ulCfg.ulScsCarrier.scsOffset = SSB_SUBCARRIER_OFFSET;
-   srvCellCfgComm->ulCfg.ulScsCarrier.scs = SUBCARRIER_SPACING;
+#ifdef NR_TDD
+   srvCellCfgComm->ulCfg.ulScsCarrier.scs = SCS_30KHZ;
+   srvCellCfgComm->ulCfg.ulScsCarrier.scsBw = BANDWIDTH_100MHZ;
+#else
+   srvCellCfgComm->ulCfg.ulScsCarrier.scs = SCS_15KHZ;
    srvCellCfgComm->ulCfg.ulScsCarrier.scsBw = BANDWIDTH_20MHZ;
+#endif
    srvCellCfgComm->ulCfg.pMax = UL_P_MAX;
    srvCellCfgComm->ulCfg.locAndBw = FREQ_LOC_BW;
    srvCellCfgComm->ulCfg.timeAlignTimerComm = TimeAlignmentTimer_infinity;
@@ -530,9 +569,26 @@ uint8_t readCfg()
    MibParams mib;
    Sib1Params sib1;    
 
+#ifdef O1_ENABLE
+   if( getStartupConfig(&g_cfg) != ROK )
+   {
+      RETVALUE(RFAILED);
+   }
+   cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
+   cmInetAddr((S8*)g_cfg.CU_IPV4_Addr, &ipv4_cu);
+   cmInetAddr((S8*)g_cfg.RIC_IPV4_Addr, &ipv4_ric);
+
+   duCfgParam.sctpParams.cuPort = g_cfg.CU_Port;
+   duCfgParam.sctpParams.ricPort = g_cfg.RIC_Port;
+#else   
    cmInetAddr((S8*)DU_IP_V4_ADDR, &ipv4_du);
    cmInetAddr((S8*)CU_IP_V4_ADDR, &ipv4_cu);
    cmInetAddr((S8*)RIC_IP_V4_ADDR, &ipv4_ric);
+
+   duCfgParam.sctpParams.cuPort = CU_PORT;
+   duCfgParam.sctpParams.ricPort = RIC_PORT;
+#endif
+
    fillDuPort(duCfgParam.sctpParams.duPort);
 
    /* F1 DU IP Address and Port*/
@@ -540,11 +596,10 @@ uint8_t readCfg()
 
    /* F1 CU IP Address and Port*/
    duCfgParam.sctpParams.cuIpAddr.ipV4Addr = ipv4_cu;
-   duCfgParam.sctpParams.cuPort = CU_PORT;
 
    /* Fill RIC Params */
    duCfgParam.sctpParams.ricIpAddr.ipV4Addr = ipv4_ric;
-   duCfgParam.sctpParams.ricPort            = RIC_PORT;
+
    /* EGTP Parameters */
    duCfgParam.egtpParams.localIp.ipV4Pres = TRUE;
    duCfgParam.egtpParams.localIp.ipV4Addr = ipv4_du;
@@ -562,12 +617,16 @@ uint8_t readCfg()
 
    /* Mib Params */
    mib.sysFrmNum = SYS_FRAME_NUM;
+#ifdef NR_TDD
+   mib.subCarrierSpacingCommon = MIB__subCarrierSpacingCommon_scs30or120;
+#else
    mib.subCarrierSpacingCommon = MIB__subCarrierSpacingCommon_scs15or60;
-   mib.ssb_SubcarrierOffset = SSB_SC_OFFSET; 
+#endif
+   mib.ssb_SubcarrierOffset = SSB_SC_OFFSET; //Kssb
    mib.dmrs_TypeA_Position = MIB__dmrs_TypeA_Position_pos2;
    mib.controlResourceSetZero = CORESET_0_INDEX;
    mib.searchSpaceZero = SEARCHSPACE_0_INDEX;
-   mib.cellBarred = MIB__cellBarred_barred;
+   mib.cellBarred = MIB__cellBarred_notBarred;
    mib.intraFreqReselection =
       MIB__intraFreqReselection_notAllowed;
    duCfgParam.mibParams = mib;
@@ -725,14 +784,13 @@ uint8_t readCfg()
 
       /*gnb DU System Info mib msg*/
       BuildMibMsg();
-      DU_ALLOC(duCfgParam.srvdCellLst[i].duSysInfo.mibMsg,\
-           strlen(encBuf));
+      DU_ALLOC(duCfgParam.srvdCellLst[i].duSysInfo.mibMsg, encBufSize);
       if(!(duCfgParam.srvdCellLst[i].duSysInfo.mibMsg))
       {
         DU_LOG("\nERROR  -->  DU APP : Memory allocation failure at readCfg");
         return RFAILED;
       }
-      strcpy((char *)duCfgParam.srvdCellLst[i].duSysInfo.mibMsg, encBuf);
+      memcpy(duCfgParam.srvdCellLst[i].duSysInfo.mibMsg, encBuf, encBufSize);
       duCfgParam.srvdCellLst[i].duSysInfo.mibLen = encBufSize;
 
       /*gnb DU System Info mib msg*/