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