882eef9e80c980a1a3075b5877fb5e5b51406ef0
[o-du/l2.git] / src / du_app / du_utils.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2020] [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 /* Utility definitions to be used in du app */
19 #include "common_def.h"
20 #include "lrg.h"
21 #include "lrg.x"
22 #include "lkw.x"
23 #include "du_app_mac_inf.h"
24 #include "du_app_rlc_inf.h"
25 #include "du_e2ap_mgr.h"
26 #include "du_cfg.h"
27 #include "du_mgr.h"
28 #include "du_utils.h"
29
30 /* Spec Ref-38.214-Table 5.1.2.1-1 */
31 uint8_t slivCfgIdxTable[MAX_SLIV_CONFIG_IDX][3] = {
32 /*S    L     SLIV*/
33 { 0,   1,    0  },/* index0  */
34 { 0,   2,    14 },/* index1  */
35 { 0,   3,    28 },/* index2  */
36 { 0,   4,    42 },/* index3  */
37 { 0,   5,    56 },/* index4  */
38 { 0,   6,    70 },/* index5  */
39 { 0,   7,    84 },/* index6  */
40 { 0,   8,    98 },/* index7  */
41 { 0,   9,    97 },/* index8  */
42 { 0,   10,   83 },/* index9  */
43 { 0,   11,   69 },/* index10 */
44 { 0,   12,   55 },/* index11 */
45 { 0,   13,   41 },/* index12 */
46 { 0,   14,   27 },/* index13 */
47 { 1,   1,    1  },/* index14 */
48 { 1,   2,    15 },/* index15 */
49 { 1,   3,    29 },/* index16 */
50 { 1,   4,    43 },/* index17 */
51 { 1,   5,    57 },/* index18 */
52 { 1,   6,    71 },/* index19 */
53 { 1,   7,    85 },/* index20 */
54 { 1,   8,    99 },/* index21 */
55 { 1,   9,    96 },/* index22 */
56 { 1,   10,   82 },/* index23 */
57 { 1,   11,   68 },/* index24 */
58 { 1,   12,   54 },/* index25 */
59 { 1,   13,   40 },/* index26 */
60 { 2,   1,    2  },/* index27 */
61 { 2,   2,    16 },/* index28 */
62 { 2,   3,    30 },/* index29 */
63 { 2,   4,    44 },/* index30 */
64 { 2,   5,    58 },/* index31 */
65 { 2,   6,    72 },/* index32 */
66 { 2,   7,    86 },/* index33 */
67 { 2,   8,    100},/* index34 */
68 { 2,   9,    95 },/* index35 */
69 { 2,   10,   81 },/* index36 */
70 { 2,   11,   67 },/* index37 */
71 { 2,   12,   53 },/* index38 */
72 { 3,   1,    3  },/* index39 */
73 { 3,   2,    17 },/* index40 */
74 { 3,   3,    31 },/* index41 */
75 { 3,   4,    45 },/* index42 */
76 { 3,   5,    59 },/* index43 */
77 { 3,   6,    73 },/* index44 */
78 { 3,   7,    87 },/* index45 */
79 { 3,   8,    101},/* index46 */
80 { 3,   9,    94 },/* index47 */
81 { 3,   10,   80 },/* index48 */
82 { 3,   11,   66 },/* index49 */
83 { 4,   1,    4  },/* index50 */
84 { 4,   2,    18 },/* index51 */
85 { 4,   3,    32 },/* index52 */
86 { 4,   4,    46 },/* index53 */
87 { 4,   5,    60 },/* index54 */
88 { 4,   6,    74 },/* index55 */
89 { 4,   7,    88 },/* index56 */
90 { 4,   8,    102},/* index57 */
91 { 4,   9,    93 },/* index58 */
92 { 4,   10,   79 },/* index59 */
93 { 5,   1,    5  },/* index60 */
94 { 5,   2,    19 },/* index61 */
95 { 5,   3,    33 },/* index62 */
96 { 5,   4,    47 },/* index63 */
97 { 5,   5,    61 },/* index64 */
98 { 5,   6,    75 },/* index65 */
99 { 5,   7,    89 },/* index66 */
100 { 5,   8,    103},/* index67 */
101 { 5,   9,    92 },/* index68 */
102 { 6,   1,    6  },/* index69 */
103 { 6,   2,    20 },/* index70 */
104 { 6,   3,    34 },/* index71 */
105 { 6,   4,    48 },/* index72 */
106 { 6,   5,    62 },/* index73 */
107 { 6,   6,    76 },/* index74 */
108 { 6,   7,    90 },/* index75 */
109 { 6,   8,    104},/* index76 */
110 { 7,   1,    7  },/* index77 */
111 { 7,   2,    21 },/* index78 */
112 { 7,   3,    35 },/* index79 */
113 { 7,   4,    49 },/* index80 */
114 { 7,   5,    63 },/* index81 */
115 { 7,   6,    77 },/* index82 */
116 { 7,   7,    91 },/* index83 */
117 { 8,   1,    8  },/* index84 */
118 { 8,   2,    22 },/* index85 */
119 { 8,   3,    36 },/* index86 */
120 { 8,   4,    50 },/* index87 */
121 { 8,   5,    64 },/* index88 */
122 { 8,   6,    78 },/* index89 */
123 { 9,   1,    9  },/* index90 */
124 { 9,   2,    23 },/* index91 */
125 { 9,   3,    37 },/* index92 */
126 { 9,   4,    51 },/* index93 */
127 { 9,   5,    65 },/* index94 */
128 { 10,  1,    10 },/* index95 */
129 { 10,  2,    24 },/* index96 */
130 { 10,  3,    38 },/* index97 */
131 { 10,  4,    52 },/* index98 */
132 { 11,  1,    11 },/* index99 */
133 { 11,  2,    25 },/* index100*/
134 { 11,  3,    39 },/* index101*/
135 { 12,  1,    12 },/* index102*/
136 { 12,  2,    26 },/* index103*/
137 { 13,  1,    13 } /* index104*/
138 };
139
140 /*******************************************************************
141  *
142  * @brief Function to fill the start Symbol and Symbol Len from the 
143  * sliv Config Idx Table
144  *
145  * @details
146  *
147  *    Function : fillStartSymbolAndLen
148  *
149  *    Functionality: Function to fill the start Symbol and Symbol Len 
150  *                   from the sliv Config Idx Table
151  *
152  * @params[in] startSymbolIdx pointer,
153  *             symbolLen pointer,
154  *             sliv
155  * @return void
156  *
157  * ****************************************************************/
158 void fillStartSymbolAndLen(uint8_t numRsrcAlloc, PdschConfig *pdschCfg, PuschCfg *puschCfg)
159 {
160    uint8_t slivIdx, timeDomIdx;
161
162    for(timeDomIdx = 0; timeDomIdx < numRsrcAlloc; timeDomIdx++)
163    {
164       for(slivIdx = 0; slivIdx < MAX_SLIV_CONFIG_IDX; slivIdx++)
165       {
166          if(pdschCfg)/* PDSCH Config */
167          {
168             if(pdschCfg->timeDomRsrcAllociList[timeDomIdx].startSymbolAndLength ==\
169                slivCfgIdxTable[slivIdx][2])
170             {
171                pdschCfg->timeDomRsrcAllociList[timeDomIdx].startSymbol  = slivCfgIdxTable[slivIdx][0];
172                pdschCfg->timeDomRsrcAllociList[timeDomIdx].symbolLength = slivCfgIdxTable[slivIdx][1];
173                break;
174             }
175          }
176          if(puschCfg)/* PUSCH Config */
177          {
178             if(puschCfg->timeDomRsrcAllocList[timeDomIdx].startSymbolAndLength ==\
179                slivCfgIdxTable[slivIdx][2])
180             {
181                puschCfg->timeDomRsrcAllocList[timeDomIdx].startSymbol  = slivCfgIdxTable[slivIdx][0];
182                puschCfg->timeDomRsrcAllocList[timeDomIdx].symbolLength = slivCfgIdxTable[slivIdx][1];
183                break;
184             }
185
186          }
187       }
188    }
189 }
190
191 /*******************************************************************
192  * @brief Function to add a node to a linked list
193  *
194  * @details
195  *
196  *     Function: duAddNodeToLList
197  *
198  *     This function adds a new node to the linked list
199  *
200  *  @param[in]  Pointer to the list
201  *              Pointer to node to be added
202  *              Pointer to current node
203  *  @return     ROK
204  *              RFAILED
205 *******************************************************************/
206 uint8_t duAddNodeToLList(CmLListCp *llist, void *blockToAdd, CmLList *currNode)
207 {
208    CmLList  *newNode = NULLP;
209
210    DU_ALLOC(newNode, sizeof(CmLList));
211    if(newNode)
212    {
213       newNode->node = (PTR)blockToAdd;
214       
215       if(currNode == NULLP)
216          cmLListAdd2Tail(llist, newNode);
217       else
218       {
219          llist->crnt = currNode;
220          cmLListInsAfterCrnt(llist, newNode);
221       }
222       return ROK;
223    } 
224    return RFAILED;
225 }
226
227 /*******************************************************************
228  * @brief Function to delete a node from linked list
229  *
230  * @details
231  *
232  *     Function: duDelNodeFromLList
233  *
234  *     This function deletes a node from the linked list
235  *
236  *  @param[in]  Pointer to the list
237  *              Pointer to node to be deleted
238  *  @return     Pointer to the deleted node
239 *******************************************************************/
240
241 uint8_t duDelNodeFromLList(CmLListCp *llist, CmLList *node)
242 {
243    node = cmLListDelFrm(llist, node);
244    DU_FREE(node, sizeof(CmLList));
245
246    return ROK;
247 }
248
249 /*******************************************************************
250  * @brief Handle the PageUe List
251  *
252  * @details
253  *
254  *    Function : handlePageUeLL
255  *
256  *    Functionality: Handling the (SEARCH,CREATE,DELETE) PageUeList
257  *
258  * @params[in] DuPagingMsg *pagingParam, CmLListCp *pageUeLL, ActionTypeLL
259  * action
260  *
261  * @return DuPagUeRecord 
262  *
263  * ****************************************************************/
264 DuPagUeRecord* handlePageUeLL(uint16_t pagUeId, uint64_t sTmsi, CmLListCp *pageUeLL, ActionTypeLL action)
265 {
266    CmLList  *node = NULLP;
267    DuPagUeRecord *ueRecord = NULLP;
268    bool found = FALSE;
269
270    if((pageUeLL == NULLP) ||
271           ((pageUeLL->first == NULLP) && (action != CREATE)))
272    {
273       DU_LOG("\nERROR  -->  DU APP: UE Page Record LL is empty");
274       return NULLP;
275    }
276    node = pageUeLL->first;
277
278    while(node)
279    {
280       ueRecord = (DuPagUeRecord *)node->node;
281       if(action == PRINT)
282       {
283          DU_LOG("\n  INFO   -->  DU APP ueId:%d, sTmsi:%lu",\
284                  ueRecord->pagUeId, ueRecord->sTmsi);
285       }
286       else if(ueRecord && (ueRecord->pagUeId == pagUeId && 
287                ueRecord->sTmsi == sTmsi))
288       {
289          found = TRUE;
290          break;
291       }
292       node = node->next;
293    }
294
295    switch(action)
296    {
297       case SEARCH:
298          {
299             if(!found)
300             {
301                ueRecord = NULLP;
302             }
303             return ueRecord;
304          }
305
306       case CREATE:
307          {
308             if(node != NULLP)
309                return ueRecord;
310
311             /*Need to add a new node for this LC*/
312
313             /*List is empty; Initialize the LL ControlPointer*/
314             if(pageUeLL->count == 0)
315             {
316                cmLListInit(pageUeLL);
317             }
318
319             ueRecord = NULLP;
320             /*Allocate the List*/
321             DU_ALLOC(ueRecord, sizeof(DuPagUeRecord));
322             if(ueRecord)
323             {
324                ueRecord->pagUeId = pagUeId;
325                ueRecord->sTmsi = sTmsi;
326             }
327             else
328             {
329                DU_LOG("\nERROR  -->  DU APP : Allocation of UE Record failed,ueId:%d",pagUeId);
330                return NULLP;
331             }
332
333             if(duAddNodeToLList(pageUeLL, ueRecord, NULLP) == RFAILED)
334             {
335                DU_LOG("\nERROR  -->  DU APP : failed to Add Ue Record Node,ueId:%d",pagUeId);
336                DU_FREE(ueRecord, sizeof(DuPagUeRecord));
337                return NULLP;
338             }
339             return ueRecord;
340          }
341       case DELETE:
342          {
343             if(!found ||  ueRecord == NULLP)
344             {
345                DU_LOG("\nERROR  -->  DU APP: UeId:%d not found; thus Deletion unsuccessful",pagUeId);
346             }
347             else
348             {
349                if(duDelNodeFromLList(pageUeLL, node) == ROK)
350                   DU_FREE(ueRecord, sizeof(DuPagUeRecord));
351             }
352             return NULLP;
353          }
354       case PRINT:
355       case TRAVERSE_ALL:
356          {
357             break;
358          }
359       default:
360          {
361             DU_LOG("\nERROR  -->  DU APP: Incorrect ActionType:%d on UeRecord",action);
362          }
363    }
364    return NULLP;
365 }
366
367 /*******************************************************************
368  * @brief Handle the PageInfo List
369  *
370  * @details
371  *
372  *    Function : handlePageInfoLL
373  *
374  *    Functionality: Handling the (SEARCH,CREATE,DELETE) PageInfoList
375  *
376  * @params[in] uint8_t i_s, CmLListCp *pagInfoLL, ActionTypeLL action
377  *
378  * @return DuPagUeList 
379  *
380  * ****************************************************************/
381 DuPagUeList* handlePageInfoLL(uint16_t pf, uint8_t i_s, CmLListCp *pagInfoLL, ActionTypeLL action)
382 {
383    CmLList  *node = NULLP, *next = NULLP;
384    DuPagUeList *pagInfo = NULLP;
385    bool found = FALSE;
386    
387    if((pagInfoLL == NULLP) || 
388          ((pagInfoLL->first == NULLP) && (action != CREATE)))
389    {
390       DU_LOG("\nERROR  -->  DU APP: PagInfo LL is empty");
391       return NULLP;
392    }
393    node = pagInfoLL->first;
394
395    while(node)
396    {
397       next = node->next;
398       pagInfo = (DuPagUeList *)node->node;
399       if(action == PRINT)
400       {
401          DU_LOG("\n INFO   -->  DU APP: Paging Index (i_s):%d",pagInfo->i_s);
402          handlePageUeLL(NULLD, NULLD, &(pagInfo->pagUeList), PRINT);
403       }
404       else if(action == TRAVERSE_ALL)
405       {
406           return pagInfo;
407       }
408       else if(pagInfo->i_s == i_s)
409       {
410          found = TRUE;
411          break;
412       }
413       node = next;
414    }
415
416    switch(action)
417    {
418       case SEARCH:
419          {
420             if(!found)
421             {
422                pagInfo = NULLP;
423             }
424             return pagInfo;
425          }
426
427       case CREATE:
428          {
429             if(node != NULLP)
430                return pagInfo;
431
432             /*Need to add a new node for this LC*/
433
434             /*List is empty; Initialize the LL ControlPointer*/
435             if(pagInfoLL->count == 0)
436             {
437                cmLListInit(pagInfoLL);
438             }
439
440             pagInfo = NULLP;
441             /*Allocate the List*/
442             DU_ALLOC(pagInfo, sizeof(DuPagUeList));
443             if(pagInfo)
444             {
445                pagInfo->i_s = i_s;
446             }
447             else
448             {
449                DU_LOG("\nERROR  -->  DU APP : Allocation of List failed,i_s:%d",i_s);
450                return NULLP;
451             }
452
453             if(duAddNodeToLList(pagInfoLL, pagInfo, NULLP) == RFAILED)
454             {
455                DU_LOG("\nERROR  -->  DU APP : failed to Add Node,i_s:%d",i_s);
456                DU_FREE(pagInfo, sizeof(DuPagUeList));
457                return NULLP;
458             }
459             return pagInfo;
460          }
461       case DELETE:
462          {
463             if(!found ||  pagInfo == NULLP)
464             {
465                DU_LOG("\nERROR  -->  DU APP: i_s:%d not found; thus Deletion unsuccessful",i_s);
466             }
467             else
468             {
469                if(duDelNodeFromLList(pagInfoLL, node) == ROK)
470                   DU_FREE(pagInfo, sizeof(DuPagUeList));
471             }
472             return NULLP;
473          }
474       case PRINT:
475       case TRAVERSE_ALL:
476          {
477             break;
478          }
479       default:
480          {
481             DU_LOG("\nERROR  -->  DU APP: Incorrect ActionType:%d on PageInfo List",action);
482          }
483    }
484    return NULLP;
485 }
486
487 /*******************************************************************
488  * @brief Find the PageInfo List from HashMap 
489  *
490  * @details
491  *
492  *    Function : findPagingInfoFromMap
493  *
494  *    Functionality: Search for the PageInfoList for a PF from HashMap
495  *
496  * @params[in] uint16_t pf, CmHashListCp *pagingInfoMap
497  *
498  * @return DuPagInfoList 
499  *
500  * ****************************************************************/
501 DuPagInfoList* findPagingInfoFromMap(uint16_t pf, CmHashListCp *pagingInfoMap)
502 {
503    DuPagInfoList *pagInfoLL = NULLP;
504
505    cmHashListFind(pagingInfoMap, (uint8_t *)&(pf), sizeof(uint16_t), 0, (PTR *)&pagInfoLL);
506    
507    return pagInfoLL;
508 }
509
510 /*Below function for printing will be used in future so disabling it for now*/
511 #if 0 
512 /*******************************************************************
513  * @brief Print the Page Info List and UE Records
514  *
515  * @details
516  *
517  *    Function : printPageList
518  *
519  *    Functionality: Print the Page Info List and UE Records
520  *
521  * @params[in] CmHashListCp *pagingInfoMap
522  *
523  * @return void
524  *
525  * ****************************************************************/
526 void printPageList(CmHashListCp *pagingInfoMap)
527 {
528    uint8_t ret = ROK;
529    DuPagInfoList *pagInfoLLFromPF = NULLP, *prevPageInfoLL = NULLP;
530
531    do
532    {
533       ret = cmHashListGetNext(pagingInfoMap, (PTR)prevPageInfoLL, (PTR *)&pagInfoLLFromPF);
534       if(ret == ROK)
535       {
536          DU_LOG("\nDEBUG  --> DUAPP: Page List for PF:%d",pagInfoLLFromPF->pf);
537          handlePageInfoLL(NULLD, NULLD, &(pagInfoLLFromPF->pagInfoList), PRINT);
538          prevPageInfoLL = pagInfoLLFromPF;
539       }
540    }while(ret == ROK);
541    
542 }
543 #endif
544
545 /**********************************************************************
546 End of file
547 **********************************************************************/
548