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