9fab14439bcadab8d8d70261c6596f36d22d5944
[o-du/l2.git] / src / 5gnrrlc / kw_uim.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**
20   
21      Name:    LTE-RLC Layer - Upper Interface Functions
22     
23      Type:    C file
24   
25      Desc:     Source code for RLC Upper Interface Module
26                This file contains following functions
27       
28         --RlcUiCkwBndReq
29         --RlcUiCkwUbndReq
30         --RlcProcCfgReq
31
32         --RlcUiKwuBndReq
33         --RlcUiKwuUbndReq
34         --rlcProcDlData
35         --RlcUiKwuDiscSduReq 
36
37      File:     kw_uim.c
38
39 **********************************************************************/
40 /** 
41  * @file kw_uim.c
42  * @brief RLC Upper Interface Module
43 */
44
45 #define RLC_MODULE RLC_DBGMASK_INF
46
47 \f
48 /* header (.h) include files */
49 #include "common_def.h"
50 #include "lkw.h"           /* LKW defines */
51 #include "ckw.h"           /* CKW defines */
52 #include "kwu.h"           /* KWU defines */
53 #include "rgu.h"           /* RGU defines */
54 #include "kw_env.h"        /* RLC environment options */
55 #include "kw.h"            /* RLC defines */
56 #include "kw_dl.h"
57 #include "kw_ul.h"
58 #include "kw_udx.h"
59
60 /* extern (.x) include files */
61 #include "lkw.x"           /* LKW */
62 #include "ckw.x"           /* CKW */
63 #include "kwu.x"           /* KWU */
64 #include "rgu.x"           /* RGU */
65 #include "kw_err.h"
66 #include "kw.x"
67 #include "kw_udx.x"
68 #include "kw_dl.x"
69 #include "kw_ul.x"
70
71
72 /*****************************************************************************
73  *                          CKW INTERFACE
74  ****************************************************************************/
75
76 /**
77  * @brief 
78  *    Handler for binding the RLC upper layer service user with 
79  *    the RLC layer.
80  *
81  * @details
82  *    This function is used by RLC user to request for binding to 
83  *    RLC. This function is called by the CKW interface to bind 
84  *    RLC's SAP (identified by spId) with the service user's
85  *    SAP (identified by suId). 
86  *
87  * @param[in] pst     Post structure
88  * @param[in] suId    Service User ID
89  * @param[in] spId    Service provider ID
90  *
91  * @return  S16
92  *    -# ROK 
93  *    -# RFAILED
94  *
95 */
96 S16 RlcUiCkwBndReq 
97 (
98 Pst    *pst,
99 SuId   suId,
100 SpId   spId 
101 )
102 {
103    RlcCkwSapCb   *ckwSap;  
104    RlcCb         *tRlcCb;
105
106 #if (ERRCLASS & ERRCLS_INT_PAR)
107    if (pst->dstInst >= MAX_RLC_INSTANCES)
108    {
109       return RFAILED;
110    }
111 #endif
112
113    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
114
115    DU_LOG("\nDEBUG  -->  RLC_UL : spId(%d), suId(%d)", spId, suId);
116    ckwSap = &(tRlcCb->u.ulCb->ckwSap);
117    /* Take action based on the current state of the SAP */
118    switch(ckwSap->state)
119    {
120       /* SAP is configured but not bound */
121       case RLC_SAP_CFG:
122       case RLC_SAP_UBND:
123       {
124          /* copy bind configuration parameters in SSAP sap */
125          ckwSap->suId = suId;
126          ckwSap->pst.dstProcId = pst->srcProcId;
127          ckwSap->pst.dstEnt = pst->srcEnt;
128          ckwSap->pst.dstInst = pst->srcInst;
129
130          /* Update the State */
131          ckwSap->state = RLC_SAP_BND;
132
133          DU_LOG("\nDEBUG  -->  RLC_UL : RlcUiCkwBndReq: state (%d)", ckwSap->state);
134          break;
135       }
136       case RLC_SAP_BND:
137       {
138          /* Sap is already bound check source, destination Entity and  
139           * Proc Id  */
140          if (ckwSap->pst.dstProcId != pst->srcProcId ||
141              ckwSap->pst.dstEnt != pst->srcEnt ||
142              ckwSap->pst.dstInst != pst->srcInst ||
143              ckwSap->suId != suId)
144          {
145             RLC_SEND_SAPID_ALARM(tRlcCb,
146                                 spId, 
147                                 LKW_EVENT_CKW_BND_REQ, 
148                                 LCM_CAUSE_INV_PAR_VAL);
149
150             DU_LOG("\nERROR  -->  RLC_UL : CKW SAP already Bound");
151             RlcUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_NOK);
152             return (RFAILED);
153          }
154          break;
155       }
156       default:
157       {
158 #if (ERRCLASS & ERRCLS_INT_PAR)
159          DU_LOG("\nERROR  -->  RLC_UL : Invalid CKW SAP State in Bind Req");
160          RLC_SEND_SAPID_ALARM(tRlcCb,
161                              spId, 
162                              LKW_EVENT_CKW_BND_REQ, 
163                              LCM_CAUSE_INV_STATE);
164 #endif /* ERRCLASS & ERRCLS_INT_PAR */
165          RlcUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_NOK);
166          return (RFAILED);
167          break;
168       }
169    }
170
171    RlcUiCkwBndCfm(&(ckwSap->pst), ckwSap->suId, CM_BND_OK);
172    return (ROK);
173
174
175 \f
176 /**
177  * @brief 
178  *    Handler for unbinding the RLC upper layer service user CKW with 
179  *    the RLC layer.
180  *
181  * @details
182  *    This function is used by RLC user to request for unbinding  
183  *    with RLC.This function is called by the CKW interface to 
184  *    unbind with RLC.  
185  *
186  * @param[in] pst     Post structure
187  * @param[in] spId    Service provider SAP ID
188  * @param[in] reason  Reason for Unbinding 
189  *
190  * @return  S16
191  *    -# ROK 
192  *    -# RFAILED
193 */ 
194 S16 RlcUiCkwUbndReq
195 (
196 Pst      *pst,   
197 SpId     spId,  
198 Reason   reason 
199 )
200 {
201    RlcCb *tRlcCb;
202
203 #if (ERRCLASS & ERRCLS_INT_PAR)
204    if (pst->dstInst >= MAX_RLC_INSTANCES)
205    {
206       return RFAILED;
207    }
208 #endif /* ERRCLASS & ERRCLS_INT_PAR */
209    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
210
211    DU_LOG("\nDEBUG  -->  RLC_UL : spId(%d), reason(%d)", 
212                 spId, 
213                 reason);
214
215    UNUSED(reason);
216
217 #if (ERRCLASS & ERRCLS_INT_PAR)
218    RLC_GET_AND_VALIDATE_CKWSAP(tRlcCb, 
219                               (&(tRlcCb->u.ulCb->ckwSap)), 
220                               EKW208, 
221                               "RlcUiCkwUbndReq");
222 #endif /* ERRCLASS & ERRCLS_INT_PAR */
223
224    /* disable upper sap (CKW) */
225    tRlcCb->u.ulCb->ckwSap.state = RLC_SAP_CFG;
226    return ROK;
227
228
229 /**
230  * @brief  
231  *    Handler for configuring RLC entities.
232  *
233  * @details
234  *    This function is used by RRC to configure(add/delete/modify)
235  *    one or more RLC entities. 
236  *
237  * @param[in] pst   -  Post structure  
238  * @param[in] spId  -  Serive Provider ID 
239  * @param[in] cfg   -  Configuration information for one or more RLC entities. 
240  *
241  * @return  S16
242  *      -# ROK 
243  *      -# RFAILED
244  */
245 S16 RlcProcCfgReq
246 (
247 Pst          *pst,
248 RlcCfgInfo   *cfg
249 )
250 {
251    RlcCb        *tRlcCb;
252    RlcUlCfgTmpData   *cfgTmpData;
253
254    static uint32_t  transCount;
255
256 #if (ERRCLASS & ERRCLS_INT_PAR)
257    if (pst->dstInst >= MAX_RLC_INSTANCES)
258    {
259       RLC_PST_FREE(pst->region, pst->pool, cfg, sizeof(RlcCfgInfo));
260       return RFAILED;
261    }
262 #endif
263    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
264
265    RLC_ALLOC(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
266
267    if (cfgTmpData == NULLP)
268    {
269       RLC_PST_FREE(pst->region, pst->pool, cfg, sizeof(RlcCfgInfo));
270       return RFAILED;
271    }
272    
273    cfgTmpData->uprLyrTransId = cfg->transId; /*Save User TransId*/
274    cfgTmpData->transId = ++transCount;       /*Generate new TransId*/
275    cfg->transId = cfgTmpData->transId;
276    cfgTmpData->cfgInfo  = cfg;
277
278  
279    tRlcCb->u.ulCb->rlcUlUdxEventType = pst->event;
280    if (rlcDbmAddUlTransaction(tRlcCb, cfgTmpData) != ROK)
281    {
282       DU_LOG("\nERROR  -->  RLC_UL : Addition to UL transId Lst Failed");
283       RLC_PST_FREE(pst->region, pst->pool, cfg, sizeof(RlcCfgInfo));
284       
285       return RFAILED;
286    }
287    
288    rlcUlHdlCfgReq(tRlcCb, cfgTmpData, cfg);
289    rlcUlUdxCfgReq(&(RLC_GET_UDX_SAP(tRlcCb)->pst),RLC_GET_UDX_SAP(tRlcCb)->spId,cfg); 
290
291    return ROK;
292
293
294 /**
295  * @brief 
296  *    Handler to change the UeId
297  *
298  * @details 
299  *    This primitive is used by RRC to change the UeId for the existing UE
300  *    context.
301  *     
302  * @param[in] pst     -  Point to the pst structure
303  * @param[in] spId    -  The ID of the service provider SAP in the RLC layer 
304  * @param[in] transId -  Transaction ID. This field uniquily identifies
305  *                       transaction between RRC and RLC
306  * @param[in] ueInfo    -  Old UE Id Info for which the change request has come 
307  * @param[in] newUeInfo -  New UE Id Info for existing UE context 
308  * 
309  * @return S16
310  *    -# ROK
311  *    -# RFAILED
312  */
313 S16 RlcUiCkwUeIdChgReq
314 (
315 Pst         *pst, 
316 SpId        spId, 
317 uint32_t    transId, 
318 CkwUeInfo   *ueInfo,
319 CkwUeInfo   *newUeInfo
320 )
321 {
322    S16              ret = ROK;
323    RlcCb             *tRlcCb;
324    RlcUlCfgTmpData   *cfgTmpData = NULLP;
325
326    do
327    {
328 #if (ERRCLASS & ERRCLS_INT_PAR)
329       if (pst->dstInst >= MAX_RLC_INSTANCES)
330       {
331          ret = RFAILED;
332          break;
333       }
334 #endif
335
336       tRlcCb = RLC_GET_RLCCB(pst->dstInst);
337 #ifndef ALIGN_64BIT
338       DU_LOG("\nDEBUG  -->  RLC_UL : RlcUiCkwUeIdChgReq(pst, spId(%d), transId(%ld))", 
339                    spId, 
340                    transId);
341 #else
342       DU_LOG("\nDEBUG  -->  RLC_UL : RlcUiCkwUeIdChgReq(pst, spId(%d), transId(%d))\n", 
343                  spId, transId);
344 #endif
345
346       RLC_ALLOC(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
347       if (!cfgTmpData)
348       {
349          ret = RFAILED;
350          break;
351       }
352
353       cfgTmpData->transId = transId;
354       cfgTmpData->ueInfo  = ueInfo;
355       cfgTmpData->newUeInfo  = newUeInfo; 
356
357       if (rlcDbmAddUlTransaction(tRlcCb, cfgTmpData))
358       {
359          DU_LOG("\nERROR  -->  RLC_UL : Addition to UL transId Lst Failed");
360          ret = RFAILED;
361          break;
362       }
363    }while(0);
364
365    if(ret)
366    {
367       /* there was an error in the processing, free up all the memory
368        * that was passed and could have been allocated in this function
369        */
370       /* Freeing from proper region */
371       RLC_PST_FREE(pst->region, pst->pool, newUeInfo, sizeof(CkwUeInfo));
372       RLC_PST_FREE(pst->region, pst->pool, ueInfo, sizeof(CkwUeInfo));
373
374       if(cfgTmpData)
375       {
376          RLC_FREE(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
377       }
378       return RFAILED;
379    }
380
381    if(ROK != rlcCfgValidateUeIdChng(tRlcCb,ueInfo,newUeInfo,cfgTmpData))
382    {
383       DU_LOG("\nERROR  -->  RLC_UL : Validation Failure for UeId change");
384    }
385
386    rlcUlUdxUeIdChgReq(&(RLC_GET_UDX_SAP(tRlcCb)->pst),
387                      RLC_GET_UDX_SAP(tRlcCb)->spId,
388                      transId, 
389                      ueInfo,
390                      newUeInfo);
391
392    return ROK;
393
394
395 \f
396 /**
397  * @brief 
398  *    Handler for Configuration Request 
399  *
400  * @param[in] gCb      RLC Instance Control Block  
401  * @param[in] cfgTmpData  Configuration stored in Transaction Block  
402  * @param[in] cfg      Configuration block
403  *
404  * @return  S16
405  *    -# ROK 
406  *    -# RFAILED
407  */
408 Void rlcUlHdlCfgReq
409 (
410 RlcCb           *gCb,
411 RlcUlCfgTmpData *cfgTmpData,
412 RlcCfgInfo      *cfg
413 )
414 {
415    uint8_t   idx;  
416
417    cfgTmpData->ueId = cfg->ueId;
418    cfgTmpData->cellId = cfg->cellId;
419    for (idx = 0; idx < cfg->numEnt; idx++)
420    {
421       cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_OK;
422       cfgTmpData->cfgEntData[idx].entUlCfgCfm.rbId = cfg->entCfg[idx].rbId; 
423       cfgTmpData->cfgEntData[idx].entUlCfgCfm.rbType = cfg->entCfg[idx].rbType;
424       switch(cfg->entCfg[idx].cfgType)
425       {
426          case CKW_CFG_ADD:
427          case CKW_CFG_MODIFY:
428          case CKW_CFG_DELETE:
429          {
430          
431             if(cfg->entCfg[idx].dir & RLC_DIR_UL)
432             {
433                /* Configuration is for UL , thus validating */
434                if(ROK != rlcCfgValidateUlRb(gCb,
435                                            &cfg->entCfg[idx], 
436                                            &cfgTmpData->cfgEntData[idx],
437                                            cfgTmpData))
438                {
439                   DU_LOG("\nERROR  -->  RLC_UL : CELLID [%u]:Validation Failure for UL RB [%d]",
440                          cfg->cellId,cfg->entCfg[idx].rbId);
441                   cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
442                   /*Validation is getting failed so no need to do configuration at DL.
443                    *Set dir as UL, so that no configuration is done at DL */
444                   cfg->entCfg[idx].dir = RLC_DIR_UL;
445                }
446             }
447             if(cfg->entCfg[idx].dir == RLC_DIR_UL)
448             {
449                /*If the configuration is for UL only then apply it */   
450                if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
451                {
452                   rlcCfgApplyUlRb(gCb, 
453                                  &cfg->entCfg[idx], 
454                                  &cfgTmpData->cfgEntData[idx],
455                                  cfgTmpData);
456                }
457             }
458             break;
459          }
460          case CKW_CFG_REESTABLISH:   
461          {
462             if(cfg->entCfg[idx].dir & RLC_DIR_UL)
463             {
464                if(ROK != rlcCfgValidateReEstRb(gCb,
465                                               cfg->ueId, 
466                                               cfg->cellId, 
467                                               &cfg->entCfg[idx], 
468                                               &cfgTmpData->cfgEntData[idx]))
469                {
470                   DU_LOG("\nERROR  -->  RLC_UL : CellID [%u]:Validation Failure for Reest UL RB [%d]",
471                         cfg->cellId,cfg->entCfg[idx].rbId);
472                   cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
473                   /* Setting dir as UL, so that no configuration is done at DL */
474                   cfg->entCfg[idx].dir = RLC_DIR_UL;
475                   break;
476                }
477             }
478             if(cfg->entCfg[idx].dir == RLC_DIR_UL)
479             {
480                /*If the configuration is for UL only then apply it */   
481                if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
482                {
483                   rlcCfgApplyReEstUlRb(gCb,  
484                                       cfg->ueId, 
485                                       cfg->cellId,
486                                       TRUE,
487                                       &cfgTmpData->cfgEntData[idx]);
488                }
489             }
490             break;
491          }
492          case CKW_CFG_DELETE_UE :   
493          {
494             if(ROK != rlcCfgValidateDelUlUe(gCb,  
495                                            &cfg->entCfg[idx], 
496                                            &cfgTmpData->cfgEntData[idx],
497                                            cfgTmpData))
498             {
499                DU_LOG("\nERROR  -->  RLC_UL : UL UEID [%d]:Validation Failure",
500                      cfgTmpData->ueId);
501                cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
502                /* Setting dir as UL, so that no configuration is done at DL */
503                cfg->entCfg[idx].dir = RLC_DIR_UL;
504             }
505             break;
506          }
507          case CKW_CFG_DELETE_CELL :   
508          {
509             if(ROK != rlcCfgValidateDelUlCell(gCb,
510                                              cfg->cellId, 
511                                              &cfg->entCfg[idx], 
512                                              &cfgTmpData->cfgEntData[idx],
513                                              cfgTmpData))
514             {
515                DU_LOG("\nERROR  -->  RLC_UL : Del UL Cell Validation Failure");
516                cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
517                /* Setting dir as UL, so that no configuration is done at DL */
518                cfg->entCfg[idx].dir = RLC_DIR_UL;
519             }
520             break;
521          }
522       }/* switch end */
523    }/* for end */
524    return;
525 }
526
527 \f
528 /*****************************************************************************
529  *                          KWU INTERFACE
530  ****************************************************************************/
531 /**
532  * @brief  
533  *    Handler for binding the RLC upper layer service user with 
534  *    the RLC layer.
535  *
536  * @details
537  *    This function is used by RLC user to request for binding to 
538  *    RLC.This function is called by the KWU interface to bind 
539  *    RLC's SAP (identified by spId) with the service user's
540  *    SAP (identified by suId). 
541  *
542  * @param[in] pst   Post structure  
543  * @param[in] suId  Service user SAP ID 
544  * @param[in] spId  Service provider ID
545  *
546  * @return  S16
547  *    -# ROK
548  *    -# RFAILED
549  *
550  */
551 S16 RlcUiKwuBndReq 
552 (
553 Pst    *pst,  
554 SuId   suId, 
555 SpId   spId 
556 )
557 {
558    RlcKwuSapCb   *rlckwuSap;     /* SAP Config Block */
559    RlcCb         *tRlcCb;
560    
561 #if (ERRCLASS & ERRCLS_INT_PAR)
562    if (pst->dstInst >= MAX_RLC_INSTANCES)
563    {
564       return RFAILED;
565    }
566 #endif
567    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
568    DU_LOG("\nDEBUG  -->  RLC_UL : RlcUiKwuBndReq(pst, spId(%d), suId(%d))", spId, suId);
569
570     /* Validation of input parameters */
571 #if (ERRCLASS & ERRCLS_INT_PAR)
572    if(!((spId < (S16) tRlcCb->genCfg.maxKwuSaps) && (spId >=0))) 
573    {
574       DU_LOG("\nERROR  -->  RLC_UL : Invalid spId");
575       RLC_SEND_SAPID_ALARM(tRlcCb,spId, LKW_EVENT_KWU_BND_REQ, LCM_CAUSE_INV_SAP);
576       return RFAILED; 
577    }
578 #endif
579
580    /* Get Sap control block */
581    rlckwuSap = (tRlcCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
582             (tRlcCb->u.dlCb->rlcKwuDlSap + spId):
583             (tRlcCb->u.ulCb->rlcKwuUlSap + spId);
584
585    /* Take action based on the current state of the SAP */
586    switch(rlckwuSap->state)
587    {
588       /* SAP is configured but not bound */
589       case RLC_SAP_CFG:
590       case RLC_SAP_UBND:
591       {
592          /* copy bind configuration parameters in sap */
593          rlckwuSap->suId          = suId;
594          rlckwuSap->pst.dstProcId = pst->srcProcId;
595          rlckwuSap->pst.dstEnt    = pst->srcEnt;
596          rlckwuSap->pst.dstInst   = pst->srcInst;
597
598          /* Update the State */
599          rlckwuSap->state = RLC_SAP_BND;
600
601          DU_LOG("\nDEBUG  -->  RLC_UL : RlcUiKwuBndReq: state (%d)", rlckwuSap->state);
602          break;
603       }
604       case RLC_SAP_BND:
605       {
606          /* Sap is already bound check source, destination Entity and Proc Id */
607          if (rlckwuSap->pst.dstProcId != pst->srcProcId ||
608              rlckwuSap->pst.dstEnt != pst->srcEnt ||
609              rlckwuSap->pst.dstInst != pst->srcInst ||
610              rlckwuSap->suId != suId)
611          {
612             RLC_SEND_SAPID_ALARM(tRlcCb,
613                                 spId, 
614                                 LKW_EVENT_KWU_BND_REQ, 
615                                 LCM_CAUSE_INV_PAR_VAL);
616             DU_LOG("\nERROR  -->  RLC_UL : RLC Mode [%d] : KWU SAP already Bound",
617                   tRlcCb->genCfg.rlcMode);
618             RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_NOK);
619             return (RFAILED);
620          }
621          break;
622       }
623
624      default:
625       {
626 #if (ERRCLASS & ERRCLS_INT_PAR)
627          DU_LOG("\nERROR  -->  RLC_UL : RLC Mode [%d]:Invalid KWU SAP State in Bind Req",
628                tRlcCb->genCfg.rlcMode);
629          RLC_SEND_SAPID_ALARM(tRlcCb,
630                              spId,
631                              LKW_EVENT_KWU_BND_REQ, 
632                              LCM_CAUSE_INV_STATE);
633 #endif /* ERRCLASS & ERRCLS_INT_PAR */
634          RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_NOK);
635          return (RFAILED);
636       }
637    }
638    RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_OK);
639    return (ROK);
640
641
642 \f
643 /**
644  * @brief 
645  *    Handler for unbinding the RLC upper layer service user with 
646  *    the RLC layer.
647  *
648  * @details
649  *    This function is used by RLC user to request for unbinding  
650  *    with RLC.This function is called by the KWU interface to 
651  *    unbind with RLC. 
652  *
653  * @param[in] pst     Post structure  
654  * @param[in] spId    Service provider SAP ID 
655  * @param[in] reason  Reason for Unbinding 
656  *
657  * @return  S16
658  *     -# ROK 
659  *     -# RFAILED
660  */
661 S16 RlcUiKwuUbndReq
662 (
663 Pst      *pst,  
664 SpId     spId, 
665 Reason   reason 
666 )
667 {
668    RlcKwuSapCb   *rlckwuSap;   /* KWU SAP control block */
669    RlcCb         *tRlcCb;
670
671 #if (ERRCLASS & ERRCLS_INT_PAR)
672    if ((pst->dstInst >= MAX_RLC_INSTANCES) ||
673        (spId >= (S16) rlcCb[pst->dstInst]->genCfg.maxKwuSaps) ||
674        (spId < 0))
675    {
676       return  (RFAILED);
677    }
678 #endif
679
680    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
681
682    DU_LOG("\nDEBUG  -->  RLC_UL : spId(%d), reason(%d)", 
683                 spId, 
684                 reason);
685
686    /* Get Sap control block */
687    rlckwuSap = (tRlcCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
688             (tRlcCb->u.dlCb->rlcKwuDlSap + spId):
689             (tRlcCb->u.ulCb->rlcKwuUlSap + spId);
690
691    rlckwuSap->state = RLC_SAP_CFG;
692
693    return ROK;
694
695
696 /**
697  * @brief Handler for receiving the data(SDU) from upper layer. 
698  *
699  * @details
700  *    This function is used by RLC service user (PDCP) to 
701  *    transfer data (SDU) to RLC.
702  *
703  * @param[in] pst         Post structure  
704  * @param[in] spId        Service Provider SAP ID 
705  * @param[in] datreq  Data Request Information
706  * @param[in] mBuf        Data Buffer (SDU) 
707  *
708  * @return  uint8_t
709  *    -# ROK 
710  *    -# RFAILED
711  */
712 uint8_t rlcProcDlData(Pst *pst, KwuDatReqInfo *datReq, Buffer *mBuf)
713 {
714    uint8_t       ret = ROK;   /* Return Value */
715    RlcDlRbCb     *rbCb;       /* RB Control Block */
716    RlcCb         *tRlcCb;
717
718    DU_LOG("\nDEBUG  -->  RLC_UL : Received DL Data");
719
720 #if (ERRCLASS & ERRCLS_INT_PAR)
721    if(pst->dstInst >= MAX_RLC_INSTANCES)
722    {
723       ODU_PUT_MSG_BUF(mBuf);
724       return RFAILED;
725    }
726 #endif
727
728    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
729
730    /* Fetch the RbCb */
731    rlcDbmFetchDlRbCbByRbId(tRlcCb, &datReq->rlcId, &rbCb);
732    if(!rbCb)
733    {
734       DU_LOG("\nERROR  -->  RLC_UL : CellId[%u]:DL RbId [%d] not found",
735             datReq->rlcId.cellId,datReq->rlcId.rbId);
736       ODU_PUT_MSG_BUF(mBuf);
737
738       return RFAILED;
739    }
740
741    /* Dispatch according to mode of the rbCb */
742    switch (rbCb->mode)
743    {
744       case RLC_MODE_TM:
745       {
746          /* Verify the user */
747          if (pst->srcEnt != ENTNH)
748          {
749             /* kw002.201 Freeing from proper region */
750             RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, datReq, 
751                         sizeof(KwuDatReqInfo));
752             ODU_PUT_MSG_BUF(mBuf);
753              
754             return RFAILED;
755          }
756
757          rlcTmmQSdu(tRlcCb,rbCb, datReq, mBuf);
758          break;
759       }
760       case RLC_MODE_UM:
761       {
762          rlcUmmQSdu(tRlcCb,rbCb, datReq, mBuf);
763
764          break;
765       }
766       case RLC_MODE_AM:
767       {
768          rlcAmmQSdu(tRlcCb,rbCb, mBuf, datReq);
769          break;
770       }
771       default:
772       {
773          DU_LOG("\nERROR  -->  RLC_UL : Invalid RB Mode");
774          break;
775       }
776    }
777    return ret;
778
779
780 \f
781 /**
782  * @brief 
783  *    Handler for discarding a SDU. 
784  *
785  * @details
786  *    This function is used by RLC AM  and RLC UM entities. 
787  *    This function is called by the service user to discard a particular
788  *    RLC SDU if it is present in the SDU queue of the RB control block 
789  *    and if it is not mapped to any PDU. 
790  *
791  * @param[in] pst            Post structure  
792  * @param[in] spId           Service Provider SAP ID 
793  * @param[in] discSdu        SDU discard Information 
794  *
795  * @return  S16
796  *    -# ROK 
797  *    -# RFAILED
798  */
799 S16 RlcUiKwuDiscSduReq 
800 (
801 Pst              *pst,   
802 SpId             spId,  
803 KwuDiscSduInfo   *discSdu 
804 )
805 {
806    RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, discSdu, sizeof(KwuDiscSduInfo));
807    return ROK;
808
809
810 /********************************************************************30**
811          End of file
812 **********************************************************************/