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