U8, U16, U32 data type changes
[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 uint8_t status 
105 )
106 #else
107 S16 rlcUlUdxBndCfm (pst, suId, status)
108 Pst    *pst; 
109 SuId   suId;   
110 uint8_t status; 
111 #endif
112 {
113    uint16_t        event;        
114    uint16_t        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    if(tRlcCb->u.ulCb->rlcUlUdxEventType == EVENT_RLC_UE_CREATE_REQ)
286    {
287       FILL_PST_RLC_TO_DUAPP(rspPst, RLC_UL_INST, EVENT_RLC_UE_CREATE_RSP);
288    }
289    else if(tRlcCb->u.ulCb->rlcUlUdxEventType == EVENT_RLC_UE_RECONFIG_REQ)
290    {
291       FILL_PST_RLC_TO_DUAPP(rspPst, RLC_UL_INST, EVENT_RLC_UE_RECONFIG_RSP);
292    }
293    SendRlcUeRspToDu(&rspPst, cfgCfm);
294
295    /* free the memory from DL */
296    RLC_FREE_SHRABL_BUF(pst->region,
297                       pst->pool,
298                       cfmInfo,
299                       sizeof(RlcCfgCfmInfo));
300
301    /* free the cfgInfo that came from LM */
302    RLC_PST_FREE(pst->region, pst->pool, cfgTmpData->cfgInfo, sizeof(RlcCfgInfo));
303    RLC_FREE(tRlcCb,cfgTmpData,sizeof(RlcUlCfgTmpData));
304    
305    return ROK;
306
307
308 /**
309  * @brief 
310  *    Handler for UeId change confirm 
311  *
312  * @details
313  *    This function handles the UeId Change Confirm from DL Instance 
314  *
315  *  @param[in] pst     Post structure  
316  *  @param[in] suId    Service User ID
317  *  @param[in] transId Transaction Id 
318  *  @param[in] status  Status of confirmation 
319  *  @return  S16
320  *      -# ROK 
321  *      -# RFAILED
322  */
323
324 #ifdef ANSI
325 S16 rlcUlUdxUeIdChgCfm
326 (
327 Pst        *pst,          
328 SuId       suId,           
329 uint32_t        transId,
330 CmStatus   status
331 )
332 #else
333 S16 rlcUlUdxUeIdChgCfm (pst, suId, cfmInfo)
334 Pst        *pst;         
335 SuId       suId;        
336 uint32_t        transId;
337 CmStatus   status;
338 #endif
339 {
340    RlcCb             *tRlcCb;
341    RlcUlCfgTmpData   *cfgTmpData;
342
343 #if (ERRCLASS & ERRCLS_INT_PAR)
344    if (pst->dstInst >= MAX_RLC_INSTANCES)
345    {
346       return  (RFAILED);
347    }
348 #endif
349    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
350
351    RLCDBGP_BRIEF(tRlcCb, " suId(%d) \n", suId);
352
353 #if (ERRCLASS & ERRCLS_INT_PAR)
354    if (suId < 0)
355    {
356       RLOG0(L_ERROR, "Invalid suId");
357       return RFAILED;
358    }
359 #endif /* ERRCLASS & ERRCLS_INT_PAR */
360
361    if(ROK != rlcDbmFindUlTransaction(tRlcCb, transId, &cfgTmpData))
362    {
363       RLOG0(L_ERROR, "Invalid transId");
364       return  (RFAILED);
365    }
366
367    if(ROK != rlcDbmDelUlTransaction(tRlcCb, cfgTmpData))
368    {
369       return RFAILED;
370    }
371
372    if(status.status == CKW_CFG_CFM_OK)
373    {
374        if(cfgTmpData->ueCb != NULLP) 
375        {
376       rlcCfgApplyUlUeIdChng(tRlcCb, cfgTmpData->ueInfo, cfgTmpData->newUeInfo, cfgTmpData);
377    }
378    }
379    RlcUiCkwUeIdChgCfm(&(tRlcCb->u.ulCb->ckwSap.pst),
380                      tRlcCb->u.ulCb->ckwSap.suId,
381                      transId,cfgTmpData->ueInfo,status);
382    /* only newUeInfo needs to be freed here, ueInfo would be freed at the 
383       interface or by he receipient in case of tight coupling */
384    RLC_PST_FREE(pst->region, pst->pool, cfgTmpData->newUeInfo, sizeof(CkwUeInfo));
385    RLC_FREE_WC(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
386    return ROK;
387
388
389 /**
390  * @brief 
391  *    Udx Status Prohibit Timer Start
392  *
393  *  @param[in] pst     Post structure  
394  *  @param[in] suId    Service User ID
395  *  @param[in] rlcId   rlc Id 
396  *  @return  S16
397  *      -# ROK 
398  *      -# RFAILED
399  */
400 S16  rlcUlUdxStaProhTmrStart
401 (
402 Pst*         pst,
403 SuId         suId,
404 CmLteRlcId   *rlcId
405 )
406 {
407    RlcCb       *tRlcCb= NULLP;
408    RlcUlRbCb   *rbCb;        
409
410 #if (ERRCLASS & ERRCLS_INT_PAR)
411    if (pst->dstInst >= MAX_RLC_INSTANCES)
412    {
413       return  (RFAILED);
414    }
415 #endif
416    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
417
418    rlcDbmFetchUlRbCbByRbId(tRlcCb, rlcId, &rbCb);
419    if (rbCb == NULLP)
420    {    
421       RLOG_ARG2(L_ERROR, DBG_UEID,rlcId->ueId, "CellId [%u]:RbId[%d] not found",
422             rlcId->cellId,rlcId->rbId);
423       return RFAILED;
424    }
425
426    /* Start staProhTmr */
427    rlcStartTmr(tRlcCb,(PTR)rbCb, RLC_EVT_AMUL_STA_PROH_TMR);
428
429    return  (ROK);
430
431
432 /**
433  * @brief 
434  *    Handler for configuration confirm from DL.
435  *
436  * @param[in] gCb        - RLC Instance Control Block
437  * @param[in] cfgTmpData - Configuration Temporary Data 
438  * @param[in] cfmInfo    - DL Configuration Confirm Info
439  * @param[out] cfgCfm    - Configuration Confirm to be sent to RRC
440  *
441  * @return  S16
442  *    -# ROK 
443  *    -# RFAILED
444  */
445 #ifdef ANSI
446 S16 rlcHdlCrlcUlCfgReq
447 (
448 RlcCb             *gCb,
449 RlcUlCfgTmpData   *cfgTmpData,
450 RlcCfgCfmInfo    *cfmInfo,
451 RlcCfgCfmInfo    *cfgCfm
452 )
453 #else
454 S16 rlcHdlCrlcUlCfgReq(gCb,cfgTmpData,cfmInfo,cfmInfo)
455 RlcCb             *gCb;
456 RlcUlCfgTmpData   *cfgTmpData;
457 RlcCfgCfmInfo    *cfmInfo;
458 RlcCfgCfmInfo    *cfgCfm;
459 #endif
460 {
461    RlcCfgInfo   *cfg;
462    uint32_t     idx;
463    uint32_t     maxEnt;
464    
465    cfg = cfgTmpData->cfgInfo;
466    maxEnt = (cfg->numEnt < CKW_MAX_ENT_CFG)? cfg->numEnt:CKW_MAX_ENT_CFG;
467
468    for (idx = 0; idx < maxEnt; idx++)
469    {
470       RlcEntCfgCfmInfo   *entCfgCfm;
471       RlcEntCfgCfmInfo   *entDlCfgCfm;
472       RlcEntCfgInfo      *entCfg;
473
474       entCfg  = &(cfg->entCfg[idx]);
475       entCfgCfm   = &(cfgCfm->entCfgCfm[idx]);
476       entDlCfgCfm = &(cfmInfo->entCfgCfm[idx]);
477       switch (entCfg->cfgType)
478       {
479          case CKW_CFG_ADD:
480          case CKW_CFG_MODIFY:
481          case CKW_CFG_DELETE:
482             {
483                if (entCfg->dir == RLC_DIR_UL)
484                {
485                   RLC_MEM_CPY(entCfgCfm, 
486                              &cfgTmpData->cfgEntData[idx].entUlCfgCfm, 
487                              sizeof(RlcEntCfgCfmInfo)); 
488                }
489                else if (entCfg->dir == RLC_DIR_DL)
490                {
491                   RLC_MEM_CPY(entCfgCfm, entDlCfgCfm, sizeof(RlcEntCfgCfmInfo)); 
492                }
493                else if(entCfg->dir == RLC_DIR_BOTH)
494                {
495                   if (entDlCfgCfm->status.status != CKW_CFG_CFM_OK)
496                   {
497                      rlcCfgRollBackUlRb(gCb,
498                                        cfg->ueId,
499                                        &cfg->entCfg[idx], 
500                                        &cfgTmpData->cfgEntData[idx]);
501                   }
502                   else
503                   {
504                      rlcCfgApplyUlRb(gCb,  
505                                     &cfg->entCfg[idx], 
506                                     &cfgTmpData->cfgEntData[idx],
507                                     cfgTmpData);
508                   }
509                   RLC_MEM_CPY(entCfgCfm, entDlCfgCfm, sizeof(RlcEntCfgCfmInfo)); 
510                }
511                else
512                {
513                             RLC_CFG_FILL_CFG_CFM(entCfgCfm, entCfg->rbId, entCfg->rbType,
514                                            CKW_CFG_CFM_NOK, CKW_CFG_REAS_INVALID_DIR);
515                   RLOG_ARG2(L_ERROR,DBG_UEID,cfg->ueId,"RBID[%d] direction[%d] is invalid",
516                          entCfg->rbId,entCfg->dir);
517                }
518                break;
519             }
520
521          case CKW_CFG_REESTABLISH:
522             {
523                if (entCfg->dir == RLC_DIR_UL)
524                {
525                   RLC_MEM_CPY(entCfgCfm, 
526                              &cfgTmpData->cfgEntData[idx].entUlCfgCfm, 
527                              sizeof(RlcEntCfgCfmInfo)); 
528                }
529                else if (entCfg->dir == RLC_DIR_DL)
530                {
531                   RLC_MEM_CPY(entCfgCfm, entDlCfgCfm, sizeof(RlcEntCfgCfmInfo)); 
532                }
533                else
534                {
535                   if (entCfg->dir & RLC_DIR_UL)
536                   {
537                      /* Reestablish indication is sent from UL Instance only*/
538                      if (entDlCfgCfm->status.status == CKW_CFG_CFM_OK)
539                      {
540                         rlcCfgApplyReEstUlRb (gCb, cfg->ueId, 
541                                              cfg->cellId, TRUE, 
542                                              &cfgTmpData->cfgEntData[idx]);
543                      }
544                      RLC_MEM_CPY(entCfgCfm, entDlCfgCfm, sizeof(RlcEntCfgCfmInfo)); 
545                   }
546                }
547                break;
548             }
549          case CKW_CFG_DELETE_UE:
550             {
551                if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
552                {
553                   rlcCfgApplyDelUlUe(gCb, cfgTmpData);
554                   RLC_MEM_CPY(entCfgCfm, 
555                              &cfgTmpData->cfgEntData[idx].entUlCfgCfm, 
556                              sizeof(RlcEntCfgCfmInfo)); 
557                }
558                else
559                {
560                    RLC_MEM_CPY(entCfgCfm, entDlCfgCfm,
561                               sizeof(RlcEntCfgCfmInfo)); 
562                }
563                break;
564             }
565          case CKW_CFG_DELETE_CELL:
566             {
567                if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
568                {
569                   rlcCfgApplyDelUlCell(gCb, cfgTmpData);
570                   RLC_MEM_CPY(entCfgCfm, 
571                              &cfgTmpData->cfgEntData[idx].entUlCfgCfm, 
572                              sizeof(RlcEntCfgCfmInfo)); 
573                }
574                else
575                {
576                    RLC_MEM_CPY(entCfgCfm, entDlCfgCfm,
577                               sizeof(RlcEntCfgCfmInfo)); 
578                }
579                break;
580             }
581          default:
582             {
583                RLC_CFG_FILL_CFG_CFM(entCfgCfm, entCfg->rbId, entCfg->rbType,
584                                    CKW_CFG_CFM_NOK, CKW_CFG_REAS_INVALID_CFG);
585
586                RLOG0(L_ERROR,"Invalid configuration type");
587             }
588       }
589    }
590
591    /* Assign number of entity configurations and suId */
592    cfgCfm->transId = cfgTmpData->uprLyrTransId;
593    cfgCfm->ueId = cfg->ueId;
594    cfgCfm->cellId = cfg->cellId;
595    cfgCfm->numEnt = cfg->numEnt;
596
597    return ROK;
598 }
599 #ifdef __cplusplus
600 }
601 #endif /* __cplusplus */
602
603 \f
604 /**********************************************************************
605          End of file
606 **********************************************************************/