Moving all common header file into common_def.h file
[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
64 #define KW_MODULE KW_DBGMASK_UDX
65 /* local defines */
66
67 /* local externs */
68
69 /* forward references */
70
71 /* public variable declarations */
72 EXTERN S16 kwHdlCkwUlCfgReq ARGS((KwCb  *gCb,KwUlCfgTmpData *cfgTmpData,
73                                   CkwCfgCfmInfo *cfmInfo, CkwCfgCfmInfo *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 #ifdef ANSI
97 PUBLIC S16 KwUlUdxBndCfm
98 (
99 Pst    *pst,  
100 SuId   suId, 
101 U8     status 
102 )
103 #else
104 PUBLIC S16 KwUlUdxBndCfm (pst, suId, status)
105 Pst    *pst; 
106 SuId   suId;   
107 U8     status; 
108 #endif
109 {
110    U16            event;        
111    U16            cause;       
112    KwUdxUlSapCb   *udxSap;   /* RGU SAP Control Block */
113    KwCb           *tKwCb;
114
115    TRC3(KwUlUdxBndCfm)
116
117 #if (ERRCLASS & ERRCLS_INT_PAR)
118    if (pst->dstInst >= KW_MAX_RLC_INSTANCES)
119    {
120       RETVALUE (RFAILED);
121    }
122 #endif
123    tKwCb = KW_GET_KWCB(pst->dstInst);
124
125    KWDBGP_BRIEF(tKwCb, "KwUlUdxBndCfm(post, suId(%d), status(%d)\n", 
126                 suId, status);
127
128 #if (ERRCLASS & ERRCLS_INT_PAR)
129    if (tKwCb->init.cfgDone != TRUE)
130    {
131       RLOG0(L_FATAL, "General configuration not done");
132       KW_SEND_SAPID_ALARM(tKwCb,suId, 
133                           LKW_EVENT_LI_BND_CFM, LCM_CAUSE_INV_STATE);
134
135       RETVALUE(RFAILED);
136    }
137
138    if (suId < 0)
139    {
140       RLOG0(L_ERROR, "Invalid suId");
141       KW_SEND_SAPID_ALARM(tKwCb,suId, 
142                            LKW_EVENT_LI_BND_CFM, LCM_CAUSE_INV_SUID);
143
144       RETVALUE(RFAILED);
145    }
146 #endif /* ERRCLASS & ERRCLS_INT_PAR */
147
148    udxSap = tKwCb->u.ulCb->udxUlSap + suId;
149
150    KWDBGP_DETAIL(tKwCb, "KwLiRguBndCfm: For RGU SAP state=%d\n", 
151                  udxSap->state);
152
153    /* Check rguSap state */
154    switch (udxSap->state)
155    {
156       case KW_SAP_BINDING:
157       {
158          if(TRUE == kwChkTmr(tKwCb,(PTR)udxSap,KW_EVT_WAIT_BNDCFM))
159          {
160              kwStopTmr (tKwCb,(PTR)udxSap, KW_EVT_WAIT_BNDCFM);
161          }
162          udxSap->retryCnt = 0;
163           
164          if (status == CM_BND_OK)
165          {
166             udxSap->state = KW_SAP_BND;
167             event = LCM_EVENT_BND_OK;
168             cause = LKW_CAUSE_SAP_BNDENB;
169          }
170          else
171          {
172             udxSap->state = KW_SAP_CFG;
173             event = LCM_EVENT_BND_FAIL;
174             cause = LKW_CAUSE_UNKNOWN;
175          }
176       }
177       break;
178
179      default:
180         event = LKW_EVENT_RGU_BND_CFM;
181         cause = LCM_CAUSE_INV_STATE;
182         break;
183    }
184    /* Send an alarm with proper event and cause */
185    KW_SEND_SAPID_ALARM(tKwCb,suId, event, cause);
186
187    RETVALUE(ROK);
188
189
190 /**
191  * @brief 
192  *    Handles UDX Configuration Confirm 
193  *
194  * @details
195  *    This function handles the UDX configuration Confirm from DL Instance
196  *
197  * @param[in] pst     Post structure  
198  * @param[in] suId    Service User ID
199  * @param[in] cfmInfo Confirm Information 
200  * 
201  * @return  S16
202  *    -# ROK 
203  *    -# RFAILED
204  */
205 #ifdef ANSI
206 PUBLIC S16 KwUlUdxCfgCfm
207 (
208 Pst             *pst,  
209 SuId            suId, 
210 CkwCfgCfmInfo   *cfmInfo  
211 )
212 #else
213 PUBLIC S16 KwUlUdxCfgCfm (pst, suId, cfmInfo)
214 Pst             *pst;   
215 SuId            suId;  
216 CkwCfgCfmInfo   *cfmInfo;  
217 #endif
218 {
219    KwCb             *tKwCb;
220    CkwCfgCfmInfo    *cfgCfm;
221    KwUlCfgTmpData   *cfgTmpData;
222
223    TRC3(KwUlUdxCfgCfm)
224
225 #if (ERRCLASS & ERRCLS_INT_PAR)
226    if (pst->dstInst >= KW_MAX_RLC_INSTANCES)
227    {
228       KW_FREE_SHRABL_BUF(pst->region,
229                          pst->pool,
230                          cfmInfo,
231                          sizeof(CkwCfgCfmInfo));
232       RETVALUE (RFAILED);
233    }
234 #endif
235    tKwCb = KW_GET_KWCB(pst->dstInst);
236    KWDBGP_BRIEF(tKwCb, " suId(%d)\n", suId);
237
238 #if (ERRCLASS & ERRCLS_INT_PAR)
239    if (suId < 0)
240    {
241       RLOG0(L_ERROR, "Invalid suId");
242       KW_SEND_SAPID_ALARM(tKwCb,suId, 
243                            LKW_EVENT_LI_BND_CFM, LCM_CAUSE_INV_SUID);
244       KW_FREE_SHRABL_BUF(pst->region,
245                          pst->pool,
246                          cfmInfo,
247                          sizeof(CkwCfgCfmInfo));
248       RETVALUE(RFAILED);
249    }
250 #endif /* ERRCLASS & ERRCLS_INT_PAR */
251
252    if(ROK != kwDbmFindUlTransaction(tKwCb,cfmInfo->transId, &cfgTmpData))
253    {
254       RLOG0(L_ERROR, "Invalid transId");
255       KW_FREE_SHRABL_BUF(pst->region,
256                          pst->pool,
257                          cfmInfo,
258                          sizeof(CkwCfgCfmInfo));
259       RETVALUE (RFAILED);
260    }
261
262    if(ROK != kwDbmDelUlTransaction(tKwCb, cfgTmpData))
263    {
264       KW_FREE_SHRABL_BUF(pst->region,
265                          pst->pool,
266                          cfmInfo,
267                          sizeof(CkwCfgCfmInfo));
268        RETVALUE(RFAILED);
269    }
270       /* Allocate memory and memset to 0 for cfmInfo */
271    KW_ALLOC(tKwCb,cfgCfm, sizeof(CkwCfgCfmInfo));
272 #if (ERRCLASS & ERRCLS_ADD_RES)
273    if (cfgCfm == NULLP)
274    {
275       RLOG0(L_FATAL, "Memory Allocation failed.");
276       KW_FREE_SHRABL_BUF(pst->region,
277                          pst->pool,
278                          cfmInfo,
279                          sizeof(CkwCfgCfmInfo));
280        RETVALUE(RFAILED);
281    }
282 #endif /* ERRCLASS & ERRCLS_ADD_RES */
283    kwHdlCkwUlCfgReq(tKwCb,cfgTmpData, cfmInfo, cfgCfm);
284    KwUiCkwCfgCfm(&(tKwCb->u.ulCb->ckwSap.pst), 
285                  tKwCb->u.ulCb->ckwSap.suId , cfgCfm);
286
287    /* free the memory from DL */
288    KW_FREE_SHRABL_BUF(pst->region,
289                       pst->pool,
290                       cfmInfo,
291                       sizeof(CkwCfgCfmInfo));
292
293    /* free the cfgInfo that came from LM */
294    KW_PST_FREE(pst->region, pst->pool, cfgTmpData->cfgInfo, sizeof(CkwCfgInfo));
295    KW_FREE(tKwCb,cfgTmpData,sizeof(KwUlCfgTmpData));
296    
297    RETVALUE(ROK);
298
299
300 /**
301  * @brief 
302  *    Handler for UeId change confirm 
303  *
304  * @details
305  *    This function handles the UeId Change Confirm from DL Instance 
306  *
307  *  @param[in] pst     Post structure  
308  *  @param[in] suId    Service User ID
309  *  @param[in] transId Transaction Id 
310  *  @param[in] status  Status of confirmation 
311  *  @return  S16
312  *      -# ROK 
313  *      -# RFAILED
314  */
315
316 #ifdef ANSI
317 PUBLIC S16 KwUlUdxUeIdChgCfm
318 (
319 Pst        *pst,          
320 SuId       suId,           
321 U32        transId,
322 CmStatus   status
323 )
324 #else
325 PUBLIC S16 KwUlUdxUeIdChgCfm (pst, suId, cfmInfo)
326 Pst        *pst;         
327 SuId       suId;        
328 U32        transId;
329 CmStatus   status;
330 #endif
331 {
332    KwCb             *tKwCb;
333    KwUlCfgTmpData   *cfgTmpData;
334
335    TRC3(KwUlUdxUeIdChgCfm)
336
337 #if (ERRCLASS & ERRCLS_INT_PAR)
338    if (pst->dstInst >= KW_MAX_RLC_INSTANCES)
339    {
340       RETVALUE (RFAILED);
341    }
342 #endif
343    tKwCb = KW_GET_KWCB(pst->dstInst);
344
345    KWDBGP_BRIEF(tKwCb, " suId(%d) \n", suId);
346
347 #if (ERRCLASS & ERRCLS_INT_PAR)
348    if (suId < 0)
349    {
350       RLOG0(L_ERROR, "Invalid suId");
351       RETVALUE(RFAILED);
352    }
353 #endif /* ERRCLASS & ERRCLS_INT_PAR */
354
355    if(ROK != kwDbmFindUlTransaction(tKwCb, transId, &cfgTmpData))
356    {
357       RLOG0(L_ERROR, "Invalid transId");
358       RETVALUE (RFAILED);
359    }
360
361    if(ROK != kwDbmDelUlTransaction(tKwCb, cfgTmpData))
362    {
363       RETVALUE(RFAILED);
364    }
365
366    if(status.status == CKW_CFG_CFM_OK)
367    {
368        if(cfgTmpData->ueCb != NULLP) 
369        {
370       kwCfgApplyUlUeIdChng(tKwCb, cfgTmpData->ueInfo, cfgTmpData->newUeInfo, cfgTmpData);
371    }
372    }
373    KwUiCkwUeIdChgCfm(&(tKwCb->u.ulCb->ckwSap.pst),
374                      tKwCb->u.ulCb->ckwSap.suId,
375                      transId,cfgTmpData->ueInfo,status);
376    /* only newUeInfo needs to be freed here, ueInfo would be freed at the 
377       interface or by he receipient in case of tight coupling */
378    KW_PST_FREE(pst->region, pst->pool, cfgTmpData->newUeInfo, sizeof(CkwUeInfo));
379    KW_FREE_WC(tKwCb, cfgTmpData, sizeof (KwUlCfgTmpData));
380    RETVALUE(ROK);
381
382
383 /**
384  * @brief 
385  *    Udx Status Prohibit Timer Start
386  *
387  *  @param[in] pst     Post structure  
388  *  @param[in] suId    Service User ID
389  *  @param[in] rlcId   rlc Id 
390  *  @return  S16
391  *      -# ROK 
392  *      -# RFAILED
393  */
394 PUBLIC S16  KwUlUdxStaProhTmrStart
395 (
396 Pst*         pst,
397 SuId         suId,
398 CmLteRlcId   *rlcId
399 )
400 {
401    KwCb       *tKwCb= NULLP;
402    KwUlRbCb   *rbCb;        
403
404 #if (ERRCLASS & ERRCLS_INT_PAR)
405    if (pst->dstInst >= KW_MAX_RLC_INSTANCES)
406    {
407       RETVALUE (RFAILED);
408    }
409 #endif
410    tKwCb = KW_GET_KWCB(pst->dstInst);
411
412    kwDbmFetchUlRbCbByRbId(tKwCb, rlcId, &rbCb);
413    if (rbCb == NULLP)
414    {    
415       RLOG_ARG2(L_ERROR, DBG_UEID,rlcId->ueId, "CellId [%u]:RbId[%d] not found",
416             rlcId->cellId,rlcId->rbId);
417       RETVALUE(RFAILED);
418    }
419
420    /* Start staProhTmr */
421    kwStartTmr(tKwCb,(PTR)rbCb, KW_EVT_AMUL_STA_PROH_TMR);
422
423    RETVALUE (ROK);
424
425
426 /**
427  * @brief 
428  *    Handler for configuration confirm from DL.
429  *
430  * @param[in] gCb        - RLC Instance Control Block
431  * @param[in] cfgTmpData - Configuration Temporary Data 
432  * @param[in] cfmInfo    - DL Configuration Confirm Info
433  * @param[out] cfgCfm    - Configuration Confirm to be sent to RRC
434  *
435  * @return  S16
436  *    -# ROK 
437  *    -# RFAILED
438  */
439 #ifdef ANSI
440 PUBLIC S16 kwHdlCkwUlCfgReq
441 (
442 KwCb             *gCb,
443 KwUlCfgTmpData   *cfgTmpData,
444 CkwCfgCfmInfo    *cfmInfo,
445 CkwCfgCfmInfo    *cfgCfm
446 )
447 #else
448 PUBLIC S16 kwHdlCkwUlCfgReq(gCb,cfgTmpData,cfmInfo,cfmInfo)
449 KwCb             *gCb;
450 KwUlCfgTmpData   *cfgTmpData;
451 CkwCfgCfmInfo    *cfmInfo;
452 CkwCfgCfmInfo    *cfgCfm;
453 #endif
454 {
455    CkwCfgInfo   *cfg;
456    U32          idx;
457    U32          maxEnt;
458    
459    cfg = cfgTmpData->cfgInfo;
460    maxEnt = (cfg->numEnt < CKW_MAX_ENT_CFG)? cfg->numEnt:CKW_MAX_ENT_CFG;
461
462    for (idx = 0; idx < maxEnt; idx++)
463    {
464       CkwEntCfgCfmInfo   *entCfgCfm;
465       CkwEntCfgCfmInfo   *entDlCfgCfm;
466       CkwEntCfgInfo      *entCfg;
467
468       entCfg  = &(cfg->entCfg[idx]);
469       entCfgCfm   = &(cfgCfm->entCfgCfm[idx]);
470       entDlCfgCfm = &(cfmInfo->entCfgCfm[idx]);
471       switch (entCfg->cfgType)
472       {
473          case CKW_CFG_ADD:
474          case CKW_CFG_MODIFY:
475          case CKW_CFG_DELETE:
476             {
477                if (entCfg->dir == KW_DIR_UL)
478                {
479                   KW_MEM_CPY(entCfgCfm, 
480                              &cfgTmpData->cfgEntData[idx].entUlCfgCfm, 
481                              sizeof(CkwEntCfgCfmInfo)); 
482                }
483                else if (entCfg->dir == KW_DIR_DL)
484                {
485                   KW_MEM_CPY(entCfgCfm, entDlCfgCfm, sizeof(CkwEntCfgCfmInfo)); 
486                }
487                else if(entCfg->dir == KW_DIR_BOTH)
488                {
489                   if (entDlCfgCfm->status.status != CKW_CFG_CFM_OK)
490                   {
491                      kwCfgRollBackUlRb(gCb,
492                                        cfg->ueId,
493                                        &cfg->entCfg[idx], 
494                                        &cfgTmpData->cfgEntData[idx]);
495                   }
496                   else
497                   {
498                      kwCfgApplyUlRb(gCb,  
499                                     &cfg->entCfg[idx], 
500                                     &cfgTmpData->cfgEntData[idx],
501                                     cfgTmpData);
502                   }
503                   KW_MEM_CPY(entCfgCfm, entDlCfgCfm, sizeof(CkwEntCfgCfmInfo)); 
504                }
505                else
506                {
507                             KW_CFG_FILL_CFG_CFM(entCfgCfm, entCfg->rbId, entCfg->rbType,
508                                            CKW_CFG_CFM_NOK, CKW_CFG_REAS_INVALID_DIR);
509                   RLOG_ARG2(L_ERROR,DBG_UEID,cfg->ueId,"RBID[%d] direction[%d] is invalid",
510                          entCfg->rbId,entCfg->dir);
511                }
512                break;
513             }
514
515          case CKW_CFG_REESTABLISH:
516             {
517                if (entCfg->dir == KW_DIR_UL)
518                {
519                   KW_MEM_CPY(entCfgCfm, 
520                              &cfgTmpData->cfgEntData[idx].entUlCfgCfm, 
521                              sizeof(CkwEntCfgCfmInfo)); 
522                }
523                else if (entCfg->dir == KW_DIR_DL)
524                {
525                   KW_MEM_CPY(entCfgCfm, entDlCfgCfm, sizeof(CkwEntCfgCfmInfo)); 
526                }
527                else
528                {
529                   if (entCfg->dir & KW_DIR_UL)
530                   {
531                      /* Reestablish indication is sent from UL Instance only*/
532                      if (entDlCfgCfm->status.status == CKW_CFG_CFM_OK)
533                      {
534                         kwCfgApplyReEstUlRb (gCb, cfg->ueId, 
535                                              cfg->cellId, TRUE, 
536                                              &cfgTmpData->cfgEntData[idx]);
537                      }
538                      KW_MEM_CPY(entCfgCfm, entDlCfgCfm, sizeof(CkwEntCfgCfmInfo)); 
539                   }
540                }
541                break;
542             }
543          case CKW_CFG_DELETE_UE:
544             {
545                if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
546                {
547                   kwCfgApplyDelUlUe(gCb, cfgTmpData);
548                   KW_MEM_CPY(entCfgCfm, 
549                              &cfgTmpData->cfgEntData[idx].entUlCfgCfm, 
550                              sizeof(CkwEntCfgCfmInfo)); 
551                }
552                else
553                {
554                    KW_MEM_CPY(entCfgCfm, entDlCfgCfm,
555                               sizeof(CkwEntCfgCfmInfo)); 
556                }
557                break;
558             }
559          case CKW_CFG_DELETE_CELL:
560             {
561                if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
562                {
563                   kwCfgApplyDelUlCell(gCb, cfgTmpData);
564                   KW_MEM_CPY(entCfgCfm, 
565                              &cfgTmpData->cfgEntData[idx].entUlCfgCfm, 
566                              sizeof(CkwEntCfgCfmInfo)); 
567                }
568                else
569                {
570                    KW_MEM_CPY(entCfgCfm, entDlCfgCfm,
571                               sizeof(CkwEntCfgCfmInfo)); 
572                }
573                break;
574             }
575          default:
576             {
577                KW_CFG_FILL_CFG_CFM(entCfgCfm, entCfg->rbId, entCfg->rbType,
578                                    CKW_CFG_CFM_NOK, CKW_CFG_REAS_INVALID_CFG);
579
580                RLOG0(L_ERROR,"Invalid configuration type");
581             }
582       }
583    }
584
585    /* Assign number of entity configurations and suId */
586    cfgCfm->transId = cfgTmpData->uprLyrTransId;
587    cfgCfm->ueId = cfg->ueId;
588    cfgCfm->cellId = cfg->cellId;
589    cfgCfm->numEnt = cfg->numEnt;
590
591    RETVALUE(ROK);
592 }
593 #ifdef __cplusplus
594 }
595 #endif /* __cplusplus */
596
597 \f
598 /**********************************************************************
599          End of file
600 **********************************************************************/