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