+/*******************************************************************
+ *
+ * @brief Builds PLMN ID
+ *
+ * @details
+ *
+ * Function : plmnBuildId
+ *
+ * Functionality: Building the PLMN ID
+ *
+ * @params[in] PLMNID plmn
+ * @params[out] PLMNID in string format
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t buildPlmnId(Plmn plmn, uint8_t *buf)
+{
+ uint8_t mncCnt;
+ mncCnt = 2;
+ buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0]));
+ if(mncCnt == 2)
+ {
+ buf[1] = ((0xf0) | (plmn.mcc[2]));
+ buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0]));
+ }
+ else
+ {
+ buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2]));
+ buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1]));
+ }
+ return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Function to map Sub carrier spacing enum value to value in kHz
+ *
+ * @details
+ *
+ * Function : convertScsEnumValToScsVal
+ *
+ * Functionality:
+ * Function to map Sub carrier spacing enum value to value in kHz
+ *
+ * @params[in] sub-carrier spacing enum value
+ * @return sub-carrier spacing value in kHz
+ *
+ * ****************************************************************/
+uint16_t convertScsEnumValToScsVal(uint8_t scsEnumValue)
+{
+ switch(scsEnumValue)
+ {
+ case SCS_15KHZ:
+ case SCS_30KHZ:
+ case SCS_60KHZ:
+ case SCS_120KHZ:
+ case SCS_240KHZ:
+ return (15 * pow(2,scsEnumValue));
+ default:
+ return 15;
+ }
+}
+
+/*******************************************************************
+ * @brief convert scs offset value into the enum value received from O1
+ *
+ * @details
+ *
+ * Function : convertScsValToScsEnum
+ *
+ * Functionality:
+ * - convert scs periodicity value
+ *
+ * @params[in] uint32_t num
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t convertScsValToScsEnum(uint32_t num)
+{
+ switch(num)
+ {
+ case 15:
+ return SCS_15KHZ;
+
+ case 30:
+ return SCS_30KHZ;
+
+ case 60:
+ return SCS_60KHZ;
+
+ case 120:
+ return SCS_120KHZ;
+
+ case 240:
+ return SCS_240KHZ;
+
+ default:
+ return SCS_15KHZ;
+ }
+}
+
+/*******************************************************************
+ * @brief convert scs periodicity value into the enum value received from O1
+ *
+ * @details
+ *
+ * Function : convertScsPeriodicityToEnum
+ *
+ * Functionality:
+ * - convert scs periodicity value
+ *
+ * @params[in] uint32_t num
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t convertScsPeriodicityToEnum(uint32_t num)
+{
+ switch(num)
+ {
+ case 5:
+ return SCS_5MS;
+
+ case 10:
+ return SCS_10MS;
+
+ case 20:
+ return SCS_20MS;
+
+ case 40:
+ return SCS_40MS;
+
+ case 80:
+ return SCS_80MS;
+
+ case 160:
+ return SCS_160MS;
+
+ default:
+ return SCS_5MS;
+ }
+}
+/*******************************************************************
+*
+* @brief SGetSBuf with debug logs
+*
+* @details
+*
+* Function : SGetSBufNewForDebug
+*
+* Functionality: SGetSBuf with debug logs
+*
+* @params[in] file name, fun name, region, pool, data ptr, size
+*
+* @return ROK - success
+* RFAILED - failure
+*
+* ****************************************************************/
+uint8_t SGetSBufNewForDebug(char *file, const char *func, int line, Region region, Pool pool, Data **ptr, Size size)
+{
+ if(SGetSBuf(region, pool, ptr, size) == ROK)
+ {
+#ifdef ODU_MEMORY_DEBUG_LOG
+ if (strncmp(func,"cmInetRecvMsg",sizeof("cmInetRecvMsg")))
+ {
+ printf("\nCM,ALLOC,=== SGetSBufNewForDebug %s +%d, %s, %d, %p \n",\
+ file, line, func, size, *ptr);
+ }
+#endif
+ return ROK;
+ }
+ else
+ return RFAILED;
+}
+
+/*******************************************************************
+*
+* @brief SPutSBuf with debug logs
+*
+* @details
+*
+* Function : SPutSBufNewForDebug
+*
+* Functionality: SPutSBuf with debug logs
+*
+* @params[in] file name, fun name, region, pool, data ptr, size
+*
+* @return ROK - success
+* RFAILED - failure
+*
+* ****************************************************************/
+uint8_t SPutSBufNewForDebug(char *file, const char *func, int line, Region region, Pool pool, Data *ptr, Size size)
+{
+ if(SPutSBuf(region, pool, ptr, size) == ROK)
+ {
+#ifdef ODU_MEMORY_DEBUG_LOG
+ if (strncmp(func,"cmInetRecvMsg",sizeof("cmInetRecvMsg")))
+ {
+ printf("\nCM,FREE,=== SPutSBufNewForDebug %s +%d, %s, %d, %p \n",\
+ file, line, func, size, ptr);
+ }
+#endif
+ return ROK;
+ }
+ else
+ return RFAILED;
+}
+
+
+/*******************************************************************
+*
+* @brief SGetStaticBuf with debug logs
+*
+* @details
+*
+* Function : SGetStaticBufNewForDebug
+*
+* Functionality: SGetStaticBuf with debug logs
+*
+* @params[in] file name, fun name, region, pool, data ptr, size, memType
+*
+* @return ROK - success
+* RFAILED - failure
+*
+* ****************************************************************/
+uint8_t SGetStaticBufNewForDebug(char *file, const char *func, int line, \
+Region region, Pool pool, Data **ptr, Size size, uint8_t memType)
+{
+ if(SGetStaticBuffer(region, pool, ptr, size, memType) == ROK)
+ {
+#ifdef ODU_MEMORY_DEBUG_LOG
+ printf("\nCM,ALLOC,=== SGetStaticBufNewForDebug %s +%d, %s, %d, %p \n",\
+ file, line, func, size, *ptr);
+#endif
+ return ROK;
+ }
+ else
+ return RFAILED;
+}
+
+/*******************************************************************
+*
+* @brief SPutStaticBuf with debug logs
+*
+* @details
+*
+* Function : SPutStaticBufNewForDebug
+*
+* Functionality: SPutStaticBuf with debug logs
+*
+* @params[in] file name, fun name, region, pool, data ptr, size, memType
+*
+* @return ROK - success
+* RFAILED - failure
+*
+* ****************************************************************/
+uint8_t SPutStaticBufNewForDebug(char *file, const char *func, int line, \
+Region region, Pool pool, Data *ptr, Size size, uint8_t memType)
+{
+ if(SPutStaticBuffer(region, pool, ptr, size, memType) == ROK)
+ {
+#ifdef ODU_MEMORY_DEBUG_LOG
+ printf("\nCM,FREE,=== SPutStaticBufNewForDebug %s +%d, %s, %d, %p \n",\
+ file, line, func, size, ptr);
+#endif
+ return ROK;
+ }
+ else
+ return RFAILED;
+}
+
+
+/*******************************************************************
+*
+* @brief countSetBits in an integer
+*
+* @details
+*
+* Function : countSetBits
+*
+* Functionality: countSetBits in unsigned integer
+*
+* @params[in] uint32_t number/Bitmask
+*
+* @return [out] uint8_t count of Set Bits
+*
+* ****************************************************************/
+uint8_t countSetBits(uint32_t num)
+{
+ uint8_t count = 0;
+
+ while(num)
+ {
+ count += num & 1;
+ num >>= 1;
+ }
+ return(count);
+}
+
+/*******************************************************************
+*
+* @brief convert ARFCN to freq in kHZ
+*
+* @details
+*
+* Function : convertArfcnToFreqKhz
+*
+* Functionality: convert ARFCN to freq in kHZ as per Table below
+* 3GPP TS 38.104, Table 5.4.2.1-1
+* Formula: F_REF = F_REF-Offs + ΔF_Global (N_REF – N_REF-Offs)
+*
+* @params[in] uint32_t number
+*
+* @return [out] uint32_t Freq in kHZ
+*
+* ****************************************************************/
+uint32_t convertArfcnToFreqKhz(uint32_t arfcn)
+{
+ uint8_t indexTable = 0;
+ uint32_t freq = 0;
+
+ for(indexTable = 0; indexTable < 4; indexTable++)
+ {
+ if(arfcn <= arfcnFreqTable[indexTable][4])
+ {
+ freq = arfcnFreqTable[indexTable][2] + (arfcnFreqTable[indexTable][1] * (arfcn - arfcnFreqTable[indexTable][3]));
+ return (freq*1000);
+ }
+ }
+ DU_LOG("ERROR --> DUAPP: ARFCN vaid range is between 0 and 3279165");
+ return (freq*1000);
+}
+
+
+/*******************************************************************
+*
+* @brief convert Freq(MHZ) to ARFCN
+*
+* @details
+*
+* Function : convertFreqToArfcn
+*
+* Functionality: convert freq to ARFCN as per Table below
+* 3GPP TS 38.104, Table 5.4.2.1-1
+* Formula: NREF = NREF-Offs + (FREF – FREF-Offs) / ΔFGlobal
+*
+* @params[in] uint32_t Freq(MHZ)
+*
+* @return [out] uint32_t ARFCN(number)
+*
+* ****************************************************************/
+uint32_t convertFreqToArfcn(uint32_t freq)
+{
+ uint8_t indexTable = 0;
+ uint32_t arfcn = 0;
+
+ for(indexTable = 0; indexTable < 4; indexTable++)
+ {
+ if(freq < arfcnFreqTable[indexTable][0])
+ {
+ arfcn = arfcnFreqTable[indexTable][3] + ((freq - arfcnFreqTable[indexTable][2]) / (arfcnFreqTable[indexTable][1]));
+ return (arfcn);
+ }
+ }
+ DU_LOG("ERROR --> DUAPP: FREQ vaid range is between 0 and 100000 MHz");
+ return (arfcn);
+}