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