1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 #include "common_def.h"
21 /*Spec 38.104, Table 5.4.2.1-1 ARFCN - FREQ mapping*/
22 /*{ F_REF(Mhz), ΔF_Global, F_REF-Offs, N_REF-offs, Range of N_REF }*/
23 uint32_t arfcnFreqTable[3][5] = {
24 { 3000, 5, 0, 0, 599999 }, /*index 0*/
25 { 24250, 15, 3000, 600000, 2016666 }, /*index 1*/
26 { 100000, 60, 24250.08, 2016667, 3279165 }, /*index 2*/
30 * @brief frequency domain allocation function.
34 * Function: fillCoresetFeqDomAllocMap
36 * This function does allocation in frequency domain resource.
37 * This is a bitmap defining non-overlapping groups of 6 PRBs in ascending order.
39 * @param[in] startPrb - start PRB from where the freq alloc starts.
40 * @param[in] prbSize - number of PRBs to be allocted.
41 * @param[in] freqDomain - 6 bytes of info, each bit represents a group of 6 PRB.
44 void fillCoresetFeqDomAllocMap(uint16_t startPrbGrp, uint16_t numPrbGrp, uint8_t *freqDomain)
47 uint8_t prbGrpStartBit = 0;
48 uint8_t numBitsToRightShift = 0;
50 uint64_t freqAllocBitMap = 0;
53 * Frequency allocation bit string is 45 bits long. Hence using 6 bytes (i.e. 48 bits) to represent it.
54 * Each bit corresponds to a group of 6 RBs.
56 * For example if a coreset includes PRB 24 to 47, then on dividing the PRBs into group of 6,
57 * startPrbGrp = 24/6 = 4
58 * numPrbGrp = 24/6 = 4
60 * Frequency allocation bit string is 48 bits long i.e. Bit 47...0
61 * Here, Bit 47 represents RB group 0, Bit 46 represent RB group 45 and so on.
62 * Since startPrbGrp = 4 and numPrbGrp = 4, it means RB group 4,5,6 and 7 are used in coreset.
63 * i.e. Bits 43, 42, 42 and 40 are masked to 1 and rest all bits are 0 in bitstring
69 mask = mask << (prbGrpStartBit - startPrbGrp);
70 freqAllocBitMap = freqAllocBitMap | mask;
75 /* Copying 48 LSBs from 64-bit integer to the 45 MSBS in 6-byte array
76 * The first (left-most / most significant) bit corresponds to the first RB
77 * group in the BWP, and so on
79 /* On right shifting freqAllocBitMap by 40 bits, the bits 47 to 40 of freqAllocBitMap
80 * will now become 8-LSB. Copying these 8-bits into freqDomain[].
81 * Now shifting freqAllocBitMap by 32 bits, the bit 39 to 32 of freqAllocBitMap will
82 * now become 8-LSB. Copying these 8-bits into next index of freqDomain.
85 numBitsToRightShift = 40;
86 mask = 0x0000FF0000000000;
87 for(idx=0; idx<FREQ_DOM_RSRC_SIZE; idx++)
89 freqDomain[idx] = (freqAllocBitMap & mask) >> numBitsToRightShift;
90 numBitsToRightShift -= 8;
95 /*******************************************************************
97 * @brief Reverse and copy fixed buffer to mBuf
101 * Function : oduCpyFixBufToMsg
103 * Functionality: Reverse and copy fixed buffer to mBuf
105 * @params[in] Fixed buffer, msg buffer, length of message
106 * @return ROK - success
109 * ****************************************************************/
110 void oduCpyFixBufToMsg(uint8_t *fixBuf, Buffer *mBuf, uint16_t len)
112 uint16_t idx = 0, revIdx = 0, temp = 0, copyLen = 0;
114 /* ODU_COPY_FIX_BUF_TO_MSG copies fixed buffer in reverse order. \
115 * Hence reversing the fixed buffer before copying in order to \
116 * maintain the actual order*/
117 for(idx = 0, revIdx = len-1; idx < len/2; idx++, revIdx--)
120 fixBuf[idx] = fixBuf[revIdx];
121 fixBuf[revIdx] = temp;
123 ODU_COPY_FIX_BUF_TO_MSG(fixBuf, mBuf, 0, len, (MsgLen *)©Len);
126 /*******************************************************************
128 * @brief Builds PLMN ID
132 * Function : plmnBuildId
134 * Functionality: Building the PLMN ID
136 * @params[in] PLMNID plmn
137 * @params[out] PLMNID in string format
138 * @return ROK - success
141 * ****************************************************************/
142 uint8_t buildPlmnId(Plmn plmn, uint8_t *buf)
146 buf[0] = ((plmn.mcc[1] << 4) | (plmn.mcc[0]));
149 buf[1] = ((0xf0) | (plmn.mcc[2]));
150 buf[2] = ((plmn.mnc[1] << 4) | (plmn.mnc[0]));
154 buf[1] = ((plmn.mnc[0] << 4) | (plmn.mcc[2]));
155 buf[2] = ((plmn.mnc[2] << 4) | (plmn.mnc[1]));
160 /*******************************************************************
162 * @brief Function to map Sub carrier spacing enum value to value in kHz
166 * Function : convertScsEnumValToScsVal
169 * Function to map Sub carrier spacing enum value to value in kHz
171 * @params[in] sub-carrier spacing enum value
172 * @return sub-carrier spacing value in kHz
174 * ****************************************************************/
175 uint16_t convertScsEnumValToScsVal(uint8_t scsEnumValue)
184 return (15 * pow(2,scsEnumValue));
190 /*******************************************************************
191 * @brief convert scs offset value into the enum value received from O1
195 * Function : convertScsValToScsEnum
198 * - convert scs periodicity value
200 * @params[in] uint32_t num
201 * @return ROK - success
204 * ****************************************************************/
206 uint8_t convertScsValToScsEnum(uint32_t num)
230 /*******************************************************************
231 * @brief convert scs periodicity value into the enum value received from O1
235 * Function : convertScsPeriodicityToEnum
238 * - convert scs periodicity value
240 * @params[in] uint32_t num
241 * @return ROK - success
244 * ****************************************************************/
245 uint8_t convertScsPeriodicityToEnum(uint32_t num)
271 /*******************************************************************
273 * @brief SGetSBuf with debug logs
277 * Function : SGetSBufNewForDebug
279 * Functionality: SGetSBuf with debug logs
281 * @params[in] file name, fun name, region, pool, data ptr, size
283 * @return ROK - success
286 * ****************************************************************/
287 uint8_t SGetSBufNewForDebug(char *file, const char *func, int line, Region region, Pool pool, Data **ptr, Size size)
289 if(SGetSBuf(region, pool, ptr, size) == ROK)
291 #ifdef ODU_MEMORY_DEBUG_LOG
292 if (strncmp(func,"cmInetRecvMsg",sizeof("cmInetRecvMsg")))
294 printf("\nCM,ALLOC,=== SGetSBufNewForDebug %s +%d, %s, %d, %p \n",\
295 file, line, func, size, *ptr);
304 /*******************************************************************
306 * @brief SPutSBuf with debug logs
310 * Function : SPutSBufNewForDebug
312 * Functionality: SPutSBuf with debug logs
314 * @params[in] file name, fun name, region, pool, data ptr, size
316 * @return ROK - success
319 * ****************************************************************/
320 uint8_t SPutSBufNewForDebug(char *file, const char *func, int line, Region region, Pool pool, Data *ptr, Size size)
322 if(SPutSBuf(region, pool, ptr, size) == ROK)
324 #ifdef ODU_MEMORY_DEBUG_LOG
325 if (strncmp(func,"cmInetRecvMsg",sizeof("cmInetRecvMsg")))
327 printf("\nCM,FREE,=== SPutSBufNewForDebug %s +%d, %s, %d, %p \n",\
328 file, line, func, size, ptr);
338 /*******************************************************************
340 * @brief SGetStaticBuf with debug logs
344 * Function : SGetStaticBufNewForDebug
346 * Functionality: SGetStaticBuf with debug logs
348 * @params[in] file name, fun name, region, pool, data ptr, size, memType
350 * @return ROK - success
353 * ****************************************************************/
354 uint8_t SGetStaticBufNewForDebug(char *file, const char *func, int line, \
355 Region region, Pool pool, Data **ptr, Size size, uint8_t memType)
357 if(SGetStaticBuffer(region, pool, ptr, size, memType) == ROK)
359 #ifdef ODU_MEMORY_DEBUG_LOG
360 printf("\nCM,ALLOC,=== SGetStaticBufNewForDebug %s +%d, %s, %d, %p \n",\
361 file, line, func, size, *ptr);
369 /*******************************************************************
371 * @brief SPutStaticBuf with debug logs
375 * Function : SPutStaticBufNewForDebug
377 * Functionality: SPutStaticBuf with debug logs
379 * @params[in] file name, fun name, region, pool, data ptr, size, memType
381 * @return ROK - success
384 * ****************************************************************/
385 uint8_t SPutStaticBufNewForDebug(char *file, const char *func, int line, \
386 Region region, Pool pool, Data *ptr, Size size, uint8_t memType)
388 if(SPutStaticBuffer(region, pool, ptr, size, memType) == ROK)
390 #ifdef ODU_MEMORY_DEBUG_LOG
391 printf("\nCM,FREE,=== SPutStaticBufNewForDebug %s +%d, %s, %d, %p \n",\
392 file, line, func, size, ptr);
401 /*******************************************************************
403 * @brief countSetBits in an integer
407 * Function : countSetBits
409 * Functionality: countSetBits in unsigned integer
411 * @params[in] uint32_t number/Bitmask
413 * @return [out] uint8_t count of Set Bits
415 * ****************************************************************/
416 uint8_t countSetBits(uint32_t num)
428 /*******************************************************************
430 * @brief convert ARFCN to freq in kHZ
434 * Function : convertArfcnToFreqKhz
436 * Functionality: convert ARFCN to freq in kHZ as per Table below
437 * 3GPP TS 38.104, Table 5.4.2.1-1
438 * Formula: F_REF = F_REF-Offs + ΔF_Global (N_REF – N_REF-Offs)
440 * @params[in] uint32_t number
442 * @return [out] uint32_t Freq in kHZ
444 * ****************************************************************/
445 uint32_t convertArfcnToFreqKhz(uint32_t arfcn)
447 uint8_t indexTable = 0;
450 for(indexTable = 0; indexTable < 4; indexTable++)
452 if(arfcn <= arfcnFreqTable[indexTable][4])
454 freq = arfcnFreqTable[indexTable][2] + (arfcnFreqTable[indexTable][1] * (arfcn - arfcnFreqTable[indexTable][3]));
458 DU_LOG("ERROR --> DUAPP: ARFCN vaid range is between 0 and 3279165");
463 /*******************************************************************
465 * @brief convert Freq(MHZ) to ARFCN
469 * Function : convertFreqToArfcn
471 * Functionality: convert freq to ARFCN as per Table below
472 * 3GPP TS 38.104, Table 5.4.2.1-1
473 * Formula: NREF = NREF-Offs + (FREF – FREF-Offs) / ΔFGlobal
475 * @params[in] uint32_t Freq(MHZ)
477 * @return [out] uint32_t ARFCN(number)
479 * ****************************************************************/
480 uint32_t convertFreqToArfcn(uint32_t freq)
482 uint8_t indexTable = 0;
485 for(indexTable = 0; indexTable < 4; indexTable++)
487 if(freq < arfcnFreqTable[indexTable][0])
489 arfcn = arfcnFreqTable[indexTable][3] + ((freq - arfcnFreqTable[indexTable][2]) / (arfcnFreqTable[indexTable][1]));
493 DU_LOG("ERROR --> DUAPP: FREQ vaid range is between 0 and 100000 MHz");
497 /**********************************************************************
499 **********************************************************************/