00af8075f2684bb26e1c54a3e695f7c8595bf2ff
[o-du/l2.git] / src / 5gnrmac / mac_utils.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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  *******************************************************************************/
18 /* header include files (.h) */
19 #include "common_def.h"
20 #include "mac_utils.h"
21
22
23 uint32_t shortBsrBytesTable[MAX_SHORT_BSR_TABLE_ENTRIES] = { 0, 10, 14, 20, 28, \
24    38, 53, 74, 102, 142, 198, 276, 384, 535, 745, 1038, 1446, 2014, 2806, 3909, \
25    5446, 7587, 10570, 14726, 20516, 28581, 39818, 55474, 77284, 107669, 150000, \
26    150001 };
27
28 /*******************************************************************
29  *
30  * @brief Allocates a crnti for new UE 
31  *
32  * @details
33  *
34  *    Function : getNewCrnti
35  *
36  *    Functionality: Allocates a crnti for new UE
37  *
38  * @params[in] CRNTI bit map
39  * @return ROK     - success
40  *         RFAILED - failure
41  *
42  * ****************************************************************/
43 uint16_t getNewCrnti(uint8_t *crntiMap)
44 {
45    uint8_t bitIdx = 0;  /* bit position */
46    uint8_t mask = 1;    /* bit mask */
47    uint16_t newCrnti;   /* new crnti */
48
49    while(bitIdx < 8)
50    {
51       /* Find the first unset bit in crntiMap and allocate
52        * this as new crnti */
53       if((*crntiMap & (mask << bitIdx)) == 0)
54       {
55          newCrnti = ODU_START_CRNTI + bitIdx;
56          SET_ONE_BIT(bitIdx, *crntiMap);
57          return newCrnti;
58       }
59       else
60          bitIdx++;
61    }
62    return -1;
63 }