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