Memory handling fixes
[o-du/l2.git] / src / 5gnrrlc / rlc_dl_ul_inf_ul.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
19 /**********************************************************************
20  
21     Name:   NR RLC layer
22  
23     Type:   C include file
24  
25     Desc:   Defines required by LTE MAC
26  
27     File:   rlc_dl_ul_inf_ul.c
28  
29 **********************************************************************/
30
31 /** @file rlc_dl_ul_inf_ul.c
32 @brief  UDX Uplink Module 
33 */
34  
35 /* header include files (.h) */
36 #include "common_def.h"
37 #include "lkw.h"           /* LKW defines */
38 #include "ckw.h"           /* CKW defines */
39 #include "kwu.h"           /* KWU defines */
40 #include "rgu.h"           /* RGU defines */
41 #include "rlc_err.h"        /* Err defines */
42 #include "rlc_env.h"        /* RLC environment options */
43
44 /* extern (.x) include files */
45 #include "lkw.x"           /* LKW */
46 #include "ckw.x"           /* CKW */
47 #include "kwu.x"           /* KWU */
48 #include "rgu.x"           /* RGU */
49
50 #include "rlc_utils.h"            /* RLC defines */
51 #include "rlc_dl_ul_inf.h"
52 #include "rlc_dl.h"
53 #include "rlc_ul.h"
54 #include "du_app_rlc_inf.h"
55 #include "rlc_mgr.h"
56
57 #define RLC_MODULE RLC_DBGMASK_UDX
58 /* local defines */
59
60 /* local externs */
61
62 /* forward references */
63
64 /* public variable declarations */
65 S16 rlcHdlCrlcUlCfgReq ARGS((RlcCb  *gCb,RlcUlCfgTmpData *cfgTmpData,
66                                   RlcCfgCfmInfo *cfmInfo, RlcCfgCfmInfo *cfgCfm));
67
68 /**
69   * @brief
70   * UDX APIs
71   */
72 /**
73  * @brief 
74  *    Handler for bind confirmation from DL.
75  *
76  * @details
77  *    This function handles the bind confirmation received
78  *    from DL. 
79  *
80  * @param[in] pst     Post structure  
81  * @param[in] suId    Service User ID
82  * @param[in] status  Status of confirmation 
83  * 
84  * @return  S16
85  *    -# ROK 
86  *    -# RFAILED
87  */
88
89 S16 rlcUlUdxBndCfm
90 (
91 Pst    *pst,  
92 SuId   suId, 
93 uint8_t status 
94 )
95 {
96    uint16_t        event;        
97    uint16_t        cause;       
98    RlcUdxUlSapCb   *udxSap;   /* RGU SAP Control Block */
99    RlcCb           *tRlcCb;
100
101 #if (ERRCLASS & ERRCLS_INT_PAR)
102    if (pst->dstInst >= MAX_RLC_INSTANCES)
103    {
104       return  (RFAILED);
105    }
106 #endif
107    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
108
109    RLCDBGP_BRIEF(tRlcCb, "rlcUlUdxBndCfm(post, suId(%d), status(%d)\n", 
110                 suId, status);
111
112 #if (ERRCLASS & ERRCLS_INT_PAR)
113    if (tRlcCb->init.cfgDone != TRUE)
114    {
115       DU_LOG("\nERROR  -->  RLC_UL : General configuration not done");
116       RLC_SEND_SAPID_ALARM(tRlcCb,suId, 
117                           LKW_EVENT_LI_BND_CFM, LCM_CAUSE_INV_STATE);
118
119       return RFAILED;
120    }
121
122    if (suId < 0)
123    {
124       DU_LOG("\nERROR  -->  RLC_UL : Invalid suId");
125       RLC_SEND_SAPID_ALARM(tRlcCb,suId, 
126                            LKW_EVENT_LI_BND_CFM, LCM_CAUSE_INV_SUID);
127
128       return RFAILED;
129    }
130 #endif /* ERRCLASS & ERRCLS_INT_PAR */
131
132    udxSap = tRlcCb->u.ulCb->udxUlSap + suId;
133
134    RLCDBGP_DETAIL(tRlcCb, "RlcLiRguBndCfm: For RGU SAP state=%d\n", 
135                  udxSap->state);
136
137    /* Check rguSap state */
138    switch (udxSap->state)
139    {
140       case RLC_SAP_BINDING:
141       {
142          if(TRUE == rlcChkTmr(tRlcCb,(PTR)udxSap,EVENT_RLC_WAIT_BNDCFM))
143          {
144              rlcStopTmr (tRlcCb,(PTR)udxSap, EVENT_RLC_WAIT_BNDCFM);
145          }
146          udxSap->retryCnt = 0;
147           
148          if (status == CM_BND_OK)
149          {
150             udxSap->state = RLC_SAP_BND;
151             event = LCM_EVENT_BND_OK;
152             cause = LKW_CAUSE_SAP_BNDENB;
153          }
154          else
155          {
156             udxSap->state = RLC_SAP_CFG;
157             event = LCM_EVENT_BND_FAIL;
158             cause = LKW_CAUSE_UNKNOWN;
159          }
160       }
161       break;
162
163      default:
164         event = LKW_EVENT_RGU_BND_CFM;
165         cause = LCM_CAUSE_INV_STATE;
166         break;
167    }
168    /* Send an alarm with proper event and cause */
169    RLC_SEND_SAPID_ALARM(tRlcCb,suId, event, cause);
170
171    return ROK;
172
173
174 /**
175  * @brief 
176  *    Handles UDX Configuration Confirm 
177  *
178  * @details
179  *    This function handles the UDX configuration Confirm from DL Instance
180  *
181  * @param[in] pst     Post structure  
182  * @param[in] suId    Service User ID
183  * @param[in] cfmInfo Confirm Information 
184  * 
185  * @return  S16
186  *    -# ROK 
187  *    -# RFAILED
188  */
189 S16 rlcUlUdxCfgCfm
190 (
191 Pst             *pst,  
192 SuId            suId, 
193 RlcCfgCfmInfo   *cfmInfo  
194 )
195 {
196    RlcCb             *tRlcCb;
197    RlcCfgCfmInfo    *cfgCfm;
198    RlcUlCfgTmpData   *cfgTmpData;
199    Pst rspPst;
200    memset(&rspPst, 0, sizeof(Pst));
201
202 #if (ERRCLASS & ERRCLS_INT_PAR)
203    if (pst->dstInst >= MAX_RLC_INSTANCES)
204    {
205       RLC_FREE_SHRABL_BUF(pst->region,
206                          pst->pool,
207                          cfmInfo,
208                          sizeof(RlcCfgCfmInfo));
209       return  (RFAILED);
210    }
211 #endif
212    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
213    RLCDBGP_BRIEF(tRlcCb, " suId(%d)\n", suId);
214
215 #if (ERRCLASS & ERRCLS_INT_PAR)
216    if (suId < 0)
217    {
218       DU_LOG("\nERROR  -->  RLC_UL : Invalid suId");
219       RLC_SEND_SAPID_ALARM(tRlcCb,suId, 
220                            LKW_EVENT_LI_BND_CFM, LCM_CAUSE_INV_SUID);
221       RLC_FREE_SHRABL_BUF(pst->region,
222                          pst->pool,
223                          cfmInfo,
224                          sizeof(RlcCfgCfmInfo));
225       return RFAILED;
226    }
227 #endif /* ERRCLASS & ERRCLS_INT_PAR */
228
229    if(ROK != rlcDbmFindUlTransaction(tRlcCb,cfmInfo->transId, &cfgTmpData))
230    {
231       DU_LOG("\nERROR  -->  RLC_UL : Invalid transId");
232       RLC_FREE_SHRABL_BUF(pst->region,
233                          pst->pool,
234                          cfmInfo,
235                          sizeof(RlcCfgCfmInfo));
236       return  (RFAILED);
237    }
238
239    if(ROK != rlcDbmDelUlTransaction(tRlcCb, cfgTmpData))
240    {
241       RLC_FREE_SHRABL_BUF(pst->region,
242                          pst->pool,
243                          cfmInfo,
244                          sizeof(RlcCfgCfmInfo));
245        return RFAILED;
246    }
247       /* Allocate memory and memset to 0 for cfmInfo */
248    RLC_ALLOC(tRlcCb,cfgCfm, sizeof(RlcCfgCfmInfo));
249 #if (ERRCLASS & ERRCLS_ADD_RES)
250    if (cfgCfm == NULLP)
251    {
252       DU_LOG("\nERROR  -->  RLC_UL : Memory Allocation failed.");
253       RLC_FREE_SHRABL_BUF(pst->region,
254                          pst->pool,
255                          cfmInfo,
256                          sizeof(RlcCfgCfmInfo));
257        return RFAILED;
258    }
259 #endif /* ERRCLASS & ERRCLS_ADD_RES */
260    rlcHdlCrlcUlCfgReq(tRlcCb,cfgTmpData, cfmInfo, cfgCfm);
261    if(tRlcCb->u.ulCb->rlcUlUdxEventType == EVENT_RLC_UE_CREATE_REQ)
262    {
263       FILL_PST_RLC_TO_DUAPP(rspPst, RLC_UL_INST, EVENT_RLC_UE_CREATE_RSP);
264       SendRlcUeCfgRspToDu(&rspPst, cfgCfm);
265    }
266    else if(tRlcCb->u.ulCb->rlcUlUdxEventType == EVENT_RLC_UE_RECONFIG_REQ)
267    {
268       FILL_PST_RLC_TO_DUAPP(rspPst, RLC_UL_INST, EVENT_RLC_UE_RECONFIG_RSP);
269       SendRlcUeCfgRspToDu(&rspPst, cfgCfm);
270    }
271    else if (tRlcCb->u.ulCb->rlcUlUdxEventType == EVENT_RLC_UE_DELETE_REQ)
272    {
273       FILL_PST_RLC_TO_DUAPP(rspPst, RLC_UL_INST, EVENT_RLC_UE_DELETE_RSP);
274       if(sendRlcUeDeleteRspToDu(cfgCfm->cellId, cfgCfm->ueId, SUCCESSFUL) != ROK)
275       {
276          DU_LOG("ERROR  --> RLC_UL: rlcUlUdxCfgCfm(): Failed to send UE delete response ");
277          RLC_FREE(tRlcCb, cfgCfm, sizeof(RlcCfgCfmInfo));
278          return RFAILED;
279       }
280       RLC_FREE(tRlcCb, cfgCfm, sizeof(RlcCfgCfmInfo));
281    }
282
283    /* free the memory from DL */
284    RLC_FREE_SHRABL_BUF(pst->region, pst->pool, cfmInfo, sizeof(RlcCfgCfmInfo));
285
286    /* free the cfgInfo that came from LM */
287    RLC_PST_FREE(pst->region, pst->pool, cfgTmpData->cfgInfo, sizeof(RlcCfgInfo));
288    RLC_FREE(tRlcCb,cfgTmpData,sizeof(RlcUlCfgTmpData));
289    
290    return ROK;
291
292
293 /**
294  * @brief 
295  *    Handler for UeId change confirm 
296  *
297  * @details
298  *    This function handles the UeId Change Confirm from DL Instance 
299  *
300  *  @param[in] pst     Post structure  
301  *  @param[in] suId    Service User ID
302  *  @param[in] transId Transaction Id 
303  *  @param[in] status  Status of confirmation 
304  *  @return  S16
305  *      -# ROK 
306  *      -# RFAILED
307  */
308
309 S16 rlcUlUdxUeIdChgCfm
310 (
311 Pst        *pst,          
312 SuId       suId,           
313 uint32_t        transId,
314 CmStatus   status
315 )
316 {
317    RlcCb             *tRlcCb;
318    RlcUlCfgTmpData   *cfgTmpData;
319
320 #if (ERRCLASS & ERRCLS_INT_PAR)
321    if (pst->dstInst >= MAX_RLC_INSTANCES)
322    {
323       return  (RFAILED);
324    }
325 #endif
326    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
327
328    RLCDBGP_BRIEF(tRlcCb, " suId(%d) \n", suId);
329
330 #if (ERRCLASS & ERRCLS_INT_PAR)
331    if (suId < 0)
332    {
333       DU_LOG("\nERROR  -->  RLC_UL : Invalid suId");
334       return RFAILED;
335    }
336 #endif /* ERRCLASS & ERRCLS_INT_PAR */
337
338    if(ROK != rlcDbmFindUlTransaction(tRlcCb, transId, &cfgTmpData))
339    {
340       DU_LOG("\nERROR  -->  RLC_UL : Invalid transId");
341       return  (RFAILED);
342    }
343
344    if(ROK != rlcDbmDelUlTransaction(tRlcCb, cfgTmpData))
345    {
346       return RFAILED;
347    }
348
349    if(status.status == CKW_CFG_CFM_OK)
350    {
351        if(cfgTmpData->ueCb != NULLP) 
352        {
353       rlcCfgApplyUlUeIdChng(tRlcCb, cfgTmpData->ueInfo, cfgTmpData->newUeInfo, cfgTmpData);
354    }
355    }
356    RlcUiCkwUeIdChgCfm(&(tRlcCb->u.ulCb->ckwSap.pst),
357                      tRlcCb->u.ulCb->ckwSap.suId,
358                      transId,cfgTmpData->ueInfo,status);
359    /* only newUeInfo needs to be freed here, ueInfo would be freed at the 
360       interface or by he receipient in case of tight coupling */
361    RLC_PST_FREE(pst->region, pst->pool, cfgTmpData->newUeInfo, sizeof(CkwUeInfo));
362    RLC_FREE(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
363    return ROK;
364
365
366 /**
367  * @brief 
368  *    Udx Status Prohibit Timer Start
369  *
370  *  @param[in] pst     Post structure  
371  *  @param[in] suId    Service User ID
372  *  @param[in] rlcId   rlc Id 
373  *  @return  S16
374  *      -# ROK 
375  *      -# RFAILED
376  */
377 S16  rlcUlUdxStaProhTmrStart
378 (
379 Pst*         pst,
380 SuId         suId,
381 CmLteRlcId   *rlcId
382 )
383 {
384    RlcCb       *tRlcCb= NULLP;
385    RlcUlRbCb   *rbCb;        
386
387 #if (ERRCLASS & ERRCLS_INT_PAR)
388    if (pst->dstInst >= MAX_RLC_INSTANCES)
389    {
390       return  (RFAILED);
391    }
392 #endif
393    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
394
395    rlcDbmFetchUlRbCbByRbId(tRlcCb, rlcId, &rbCb);
396    if (rbCb == NULLP)
397    {    
398       DU_LOG("\nERROR  -->  RLC_UL : CellId [%u]:RbId[%d] not found",
399             rlcId->cellId,rlcId->rbId);
400       return RFAILED;
401    }
402
403    /* Start staProhTmr */
404    rlcStartTmr(tRlcCb,(PTR)rbCb, EVENT_RLC_AMUL_STA_PROH_TMR);
405
406    return  (ROK);
407
408
409 /**
410  * @brief 
411  *    Handler for configuration confirm from DL.
412  *
413  * @param[in] gCb        - RLC Instance Control Block
414  * @param[in] cfgTmpData - Configuration Temporary Data 
415  * @param[in] cfmInfo    - DL Configuration Confirm Info
416  * @param[out] cfgCfm    - Configuration Confirm to be sent to RRC
417  *
418  * @return  S16
419  *    -# ROK 
420  *    -# RFAILED
421  */
422 S16 rlcHdlCrlcUlCfgReq
423 (
424 RlcCb             *gCb,
425 RlcUlCfgTmpData   *cfgTmpData,
426 RlcCfgCfmInfo    *cfmInfo,
427 RlcCfgCfmInfo    *cfgCfm
428 )
429 {
430    RlcCfgInfo   *cfg;
431    uint32_t     idx;
432    uint32_t     maxEnt;
433    
434    cfg = cfgTmpData->cfgInfo;
435    maxEnt = (cfg->numEnt < CKW_MAX_ENT_CFG)? cfg->numEnt:CKW_MAX_ENT_CFG;
436
437    for (idx = 0; idx < maxEnt; idx++)
438    {
439       RlcEntCfgCfmInfo   *entCfgCfm;
440       RlcEntCfgCfmInfo   *entDlCfgCfm;
441       RlcEntCfgInfo      *entCfg;
442
443       entCfg  = &(cfg->entCfg[idx]);
444       entCfgCfm   = &(cfgCfm->entCfgCfm[idx]);
445       entDlCfgCfm = &(cfmInfo->entCfgCfm[idx]);
446       switch (entCfg->cfgType)
447       {
448          case CKW_CFG_ADD:
449          case CKW_CFG_MODIFY:
450          case CKW_CFG_DELETE:
451             {
452                if (entCfg->dir == RLC_DIR_UL)
453                {
454                   RLC_MEM_CPY(entCfgCfm, 
455                              &cfgTmpData->cfgEntData[idx].entUlCfgCfm, 
456                              sizeof(RlcEntCfgCfmInfo)); 
457                }
458                else if (entCfg->dir == RLC_DIR_DL)
459                {
460                   RLC_MEM_CPY(entCfgCfm, entDlCfgCfm, sizeof(RlcEntCfgCfmInfo)); 
461                }
462                else if(entCfg->dir == RLC_DIR_BOTH)
463                {
464                   if (entDlCfgCfm->status.status != CKW_CFG_CFM_OK)
465                   {
466                      rlcCfgRollBackUlRb(gCb,
467                                        cfg->ueId,
468                                        &cfg->entCfg[idx], 
469                                        &cfgTmpData->cfgEntData[idx]);
470                   }
471                   else
472                   {
473                      rlcCfgApplyUlRb(gCb,  
474                                     &cfg->entCfg[idx], 
475                                     &cfgTmpData->cfgEntData[idx],
476                                     cfgTmpData);
477                   }
478                   RLC_MEM_CPY(entCfgCfm, entDlCfgCfm, sizeof(RlcEntCfgCfmInfo)); 
479                }
480                else
481                {
482                             RLC_CFG_FILL_CFG_CFM(entCfgCfm, entCfg->rbId, entCfg->rbType,
483                                            CKW_CFG_CFM_NOK, CKW_CFG_REAS_INVALID_DIR);
484                   DU_LOG("\nDEBUG  -->  RLC_UL : RBID[%d] direction[%d] is invalid",
485                          entCfg->rbId,entCfg->dir);
486                }
487                break;
488             }
489
490          case CKW_CFG_REESTABLISH:
491             {
492                if (entCfg->dir == RLC_DIR_UL)
493                {
494                   RLC_MEM_CPY(entCfgCfm, 
495                              &cfgTmpData->cfgEntData[idx].entUlCfgCfm, 
496                              sizeof(RlcEntCfgCfmInfo)); 
497                }
498                else if (entCfg->dir == RLC_DIR_DL)
499                {
500                   RLC_MEM_CPY(entCfgCfm, entDlCfgCfm, sizeof(RlcEntCfgCfmInfo)); 
501                }
502                else
503                {
504                   if (entCfg->dir & RLC_DIR_UL)
505                   {
506                      /* Reestablish indication is sent from UL Instance only*/
507                      if (entDlCfgCfm->status.status == CKW_CFG_CFM_OK)
508                      {
509                         rlcCfgApplyReEstUlRb (gCb, cfg->ueId, 
510                                              cfg->cellId, TRUE, 
511                                              &cfgTmpData->cfgEntData[idx]);
512                      }
513                      RLC_MEM_CPY(entCfgCfm, entDlCfgCfm, sizeof(RlcEntCfgCfmInfo)); 
514                   }
515                }
516                break;
517             }
518          case CKW_CFG_DELETE_UE:
519             {
520                if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
521                {
522                   rlcCfgApplyDelUlUe(gCb, cfgTmpData);
523                   RLC_MEM_CPY(entCfgCfm, 
524                              &cfgTmpData->cfgEntData[idx].entUlCfgCfm, 
525                              sizeof(RlcEntCfgCfmInfo));
526                }
527                else
528                {
529                    RLC_MEM_CPY(entCfgCfm, entDlCfgCfm,
530                               sizeof(RlcEntCfgCfmInfo)); 
531                }
532                break;
533             }
534          case CKW_CFG_DELETE_CELL:
535             {
536                if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
537                {
538                   rlcCfgApplyDelUlCell(gCb, cfgTmpData);
539                   RLC_MEM_CPY(entCfgCfm, 
540                              &cfgTmpData->cfgEntData[idx].entUlCfgCfm, 
541                              sizeof(RlcEntCfgCfmInfo)); 
542                }
543                else
544                {
545                    RLC_MEM_CPY(entCfgCfm, entDlCfgCfm,
546                               sizeof(RlcEntCfgCfmInfo)); 
547                }
548                break;
549             }
550          default:
551             {
552                RLC_CFG_FILL_CFG_CFM(entCfgCfm, entCfg->rbId, entCfg->rbType,
553                                    CKW_CFG_CFM_NOK, CKW_CFG_REAS_INVALID_CFG);
554
555                DU_LOG("\nERROR  -->  RLC_UL : Invalid configuration type");
556             }
557       }
558    }
559
560    /* Assign number of entity configurations and suId */
561    cfgCfm->transId = cfgTmpData->uprLyrTransId;
562    cfgCfm->ueId = cfg->ueId;
563    cfgCfm->cellId = cfg->cellId;
564    cfgCfm->numEnt = cfg->numEnt;
565
566    return ROK;
567 }
568 #ifdef __cplusplus
569 }
570 #endif /* __cplusplus */
571
572 \f
573 /**********************************************************************
574          End of file
575 **********************************************************************/