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