U8, U16, U32 data type changes
[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 uint32_t  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    tRlcCb->u.ulCb->rlcUlUdxEventType = pst->event;
304    if (rlcDbmAddUlTransaction(tRlcCb, cfgTmpData) != ROK)
305    {
306       RLOG0(L_ERROR, "Addition to UL transId Lst Failed");
307       RLC_PST_FREE(pst->region, pst->pool, cfg, sizeof(RlcCfgInfo));
308       
309       return RFAILED;
310    }
311    
312    rlcUlHdlCfgReq(tRlcCb, cfgTmpData, cfg);
313    rlcUlUdxCfgReq(&(RLC_GET_UDX_SAP(tRlcCb)->pst),RLC_GET_UDX_SAP(tRlcCb)->spId,cfg); 
314
315    return ROK;
316
317
318 /**
319  * @brief 
320  *    Handler to change the UeId
321  *
322  * @details 
323  *    This primitive is used by RRC to change the UeId for the existing UE
324  *    context.
325  *     
326  * @param[in] pst     -  Point to the pst structure
327  * @param[in] spId    -  The ID of the service provider SAP in the RLC layer 
328  * @param[in] transId -  Transaction ID. This field uniquily identifies
329  *                       transaction between RRC and RLC
330  * @param[in] ueInfo    -  Old UE Id Info for which the change request has come 
331  * @param[in] newUeInfo -  New UE Id Info for existing UE context 
332  * 
333  * @return S16
334  *    -# ROK
335  *    -# RFAILED
336  */
337 #ifdef ANSI
338 S16 RlcUiCkwUeIdChgReq
339 (
340 Pst         *pst, 
341 SpId        spId, 
342 uint32_t    transId, 
343 CkwUeInfo   *ueInfo,
344 CkwUeInfo   *newUeInfo
345 )
346 #else
347 S16 RlcUiCkwUeIdChgReq(pst, spId, transId, ueInfo, newUeInfo)
348 Pst         *pst;
349 SpId        spId;
350 uint32_t    transId;
351 CkwUeInfo   *ueInfo;
352 CkwUeInfo   *newUeInfo;
353 #endif
354 {
355    S16              ret = ROK;
356    RlcCb             *tRlcCb;
357    RlcUlCfgTmpData   *cfgTmpData = NULLP;
358
359    do
360    {
361 #if (ERRCLASS & ERRCLS_INT_PAR)
362       if (pst->dstInst >= MAX_RLC_INSTANCES)
363       {
364          ret = RFAILED;
365          break;
366       }
367 #endif
368
369       tRlcCb = RLC_GET_RLCCB(pst->dstInst);
370 #ifndef ALIGN_64BIT
371       RLOG_ARG2(L_DEBUG,DBG_CELLID,newUeInfo->cellId,
372                    "RlcUiCkwUeIdChgReq(pst, spId(%d), transId(%ld))", 
373                    spId, 
374                    transId);
375 #else
376       RLOG_ARG2(L_DEBUG,DBG_CELLID,newUeInfo->cellId, 
377                    "RlcUiCkwUeIdChgReq(pst, spId(%d), transId(%d))\n", 
378                    spId, 
379                    transId);
380 #endif
381
382       RLC_ALLOC(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
383       if (!cfgTmpData)
384       {
385          ret = RFAILED;
386          break;
387       }
388
389       cfgTmpData->transId = transId;
390       cfgTmpData->ueInfo  = ueInfo;
391       cfgTmpData->newUeInfo  = newUeInfo; 
392
393       if (rlcDbmAddUlTransaction(tRlcCb, cfgTmpData))
394       {
395          RLOG0(L_ERROR, "Addition to UL transId Lst Failed");
396          ret = RFAILED;
397          break;
398       }
399    }while(0);
400
401    if(ret)
402    {
403       /* there was an error in the processing, free up all the memory
404        * that was passed and could have been allocated in this function
405        */
406       /* Freeing from proper region */
407       RLC_PST_FREE(pst->region, pst->pool, newUeInfo, sizeof(CkwUeInfo));
408       RLC_PST_FREE(pst->region, pst->pool, ueInfo, sizeof(CkwUeInfo));
409
410       if(cfgTmpData)
411       {
412          RLC_FREE(tRlcCb, cfgTmpData, sizeof (RlcUlCfgTmpData));
413       }
414       return RFAILED;
415    }
416
417    if(ROK != rlcCfgValidateUeIdChng(tRlcCb,ueInfo,newUeInfo,cfgTmpData))
418    {
419       RLOG_ARG0(L_ERROR,DBG_CELLID,cfgTmpData->ueInfo->cellId, 
420             "Validation Failure for UeId change");
421    }
422
423    rlcUlUdxUeIdChgReq(&(RLC_GET_UDX_SAP(tRlcCb)->pst),
424                      RLC_GET_UDX_SAP(tRlcCb)->spId,
425                      transId, 
426                      ueInfo,
427                      newUeInfo);
428
429    return ROK;
430
431
432 \f
433 /**
434  * @brief 
435  *    Handler for Configuration Request 
436  *
437  * @param[in] gCb      RLC Instance Control Block  
438  * @param[in] cfgTmpData  Configuration stored in Transaction Block  
439  * @param[in] cfg      Configuration block
440  *
441  * @return  S16
442  *    -# ROK 
443  *    -# RFAILED
444  */
445 #ifdef ANSI
446 Void rlcUlHdlCfgReq
447 (
448 RlcCb             *gCb,
449 RlcUlCfgTmpData   *cfgTmpData,
450 RlcCfgInfo       *cfg
451 )
452 #else
453 Void rlcUlHdlCfgReq(gCb, cfgTmpData, cfg)
454 RlcCb             *gCb;
455 RlcUlCfgTmpData   *cfgTmpData;
456 RlcCfgInfo       *cfg;
457 #endif
458 {
459    uint8_t   idx;  
460
461    cfgTmpData->ueId = cfg->ueId;
462    cfgTmpData->cellId = cfg->cellId;
463    for (idx = 0; idx < cfg->numEnt; idx++)
464    {
465       cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_OK;
466       cfgTmpData->cfgEntData[idx].entUlCfgCfm.rbId = cfg->entCfg[idx].rbId; 
467       cfgTmpData->cfgEntData[idx].entUlCfgCfm.rbType = cfg->entCfg[idx].rbType;
468       switch(cfg->entCfg[idx].cfgType)
469       {
470          case CKW_CFG_ADD:
471          case CKW_CFG_MODIFY:
472          case CKW_CFG_DELETE:
473          {
474          
475             if(cfg->entCfg[idx].dir & RLC_DIR_UL)
476             {
477                /* Configuration is for UL , thus validating */
478                if(ROK != rlcCfgValidateUlRb(gCb,
479                                            &cfg->entCfg[idx], 
480                                            &cfgTmpData->cfgEntData[idx],
481                                            cfgTmpData))
482                {
483                   RLOG_ARG2(L_ERROR,DBG_UEID, cfgTmpData->ueId,
484                         "CELLID [%u]:Validation Failure for UL RB [%d]",
485                          cfg->cellId,cfg->entCfg[idx].rbId);
486                   cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
487                   /*Validation is getting failed so no need to do configuration at DL.
488                    *Set dir as UL, so that no configuration is done at DL */
489                   cfg->entCfg[idx].dir = RLC_DIR_UL;
490                }
491             }
492             if(cfg->entCfg[idx].dir == RLC_DIR_UL)
493             {
494                /*If the configuration is for UL only then apply it */   
495                if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
496                {
497                   rlcCfgApplyUlRb(gCb, 
498                                  &cfg->entCfg[idx], 
499                                  &cfgTmpData->cfgEntData[idx],
500                                  cfgTmpData);
501                }
502             }
503             break;
504          }
505          case CKW_CFG_REESTABLISH:   
506          {
507             if(cfg->entCfg[idx].dir & RLC_DIR_UL)
508             {
509                if(ROK != rlcCfgValidateReEstRb(gCb,
510                                               cfg->ueId, 
511                                               cfg->cellId, 
512                                               &cfg->entCfg[idx], 
513                                               &cfgTmpData->cfgEntData[idx]))
514                {
515                   RLOG_ARG2(L_ERROR,DBG_UEID,cfg->ueId,
516                         "CellID [%u]:Validation Failure for Reest UL RB [%d]",
517                         cfg->cellId,cfg->entCfg[idx].rbId);
518                   cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
519                   /* Setting dir as UL, so that no configuration is done at DL */
520                   cfg->entCfg[idx].dir = RLC_DIR_UL;
521                   break;
522                }
523             }
524             if(cfg->entCfg[idx].dir == RLC_DIR_UL)
525             {
526                /*If the configuration is for UL only then apply it */   
527                if (cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status == CKW_CFG_CFM_OK)
528                {
529                   rlcCfgApplyReEstUlRb(gCb,  
530                                       cfg->ueId, 
531                                       cfg->cellId,
532                                       TRUE,
533                                       &cfgTmpData->cfgEntData[idx]);
534                }
535             }
536             break;
537          }
538          case CKW_CFG_DELETE_UE :   
539          {
540             if(ROK != rlcCfgValidateDelUlUe(gCb,  
541                                            &cfg->entCfg[idx], 
542                                            &cfgTmpData->cfgEntData[idx],
543                                            cfgTmpData))
544             {
545                RLOG_ARG1(L_ERROR,DBG_CELLID,cfg->cellId,
546                      "UL UEID [%d]:Validation Failure",
547                      cfgTmpData->ueId);
548                cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
549                /* Setting dir as UL, so that no configuration is done at DL */
550                cfg->entCfg[idx].dir = RLC_DIR_UL;
551             }
552             break;
553          }
554          case CKW_CFG_DELETE_CELL :   
555          {
556             if(ROK != rlcCfgValidateDelUlCell(gCb,
557                                              cfg->cellId, 
558                                              &cfg->entCfg[idx], 
559                                              &cfgTmpData->cfgEntData[idx],
560                                              cfgTmpData))
561             {
562                RLOG_ARG0(L_ERROR,DBG_CELLID,cfg->cellId,
563                      "Del UL Cell Validation Failure");
564                cfgTmpData->cfgEntData[idx].entUlCfgCfm.status.status = CKW_CFG_CFM_NOK;
565                /* Setting dir as UL, so that no configuration is done at DL */
566                cfg->entCfg[idx].dir = RLC_DIR_UL;
567             }
568             break;
569          }
570       }/* switch end */
571    }/* for end */
572    return;
573 }
574
575 \f
576 /*****************************************************************************
577  *                          KWU INTERFACE
578  ****************************************************************************/
579 /**
580  * @brief  
581  *    Handler for binding the RLC upper layer service user with 
582  *    the RLC layer.
583  *
584  * @details
585  *    This function is used by RLC user to request for binding to 
586  *    RLC.This function is called by the KWU interface to bind 
587  *    RLC's SAP (identified by spId) with the service user's
588  *    SAP (identified by suId). 
589  *
590  * @param[in] pst   Post structure  
591  * @param[in] suId  Service user SAP ID 
592  * @param[in] spId  Service provider ID
593  *
594  * @return  S16
595  *    -# ROK
596  *    -# RFAILED
597  *
598  */
599 #ifdef ANSI
600 S16 RlcUiKwuBndReq 
601 (
602 Pst    *pst,  
603 SuId   suId, 
604 SpId   spId 
605 )
606 #else
607 S16 RlcUiKwuBndReq (pst, suId, spId)
608 Pst    *pst;  
609 SuId   suId; 
610 SpId   spId; 
611 #endif
612 {
613    RlcKwuSapCb   *rlckwuSap;     /* SAP Config Block */
614    RlcCb         *tRlcCb;
615    
616 #if (ERRCLASS & ERRCLS_INT_PAR)
617    if (pst->dstInst >= MAX_RLC_INSTANCES)
618    {
619       return RFAILED;
620    }
621 #endif
622    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
623    RLOG2(L_DEBUG, "RlcUiKwuBndReq(pst, spId(%d), suId(%d))", spId, suId);
624
625     /* Validation of input parameters */
626 #if (ERRCLASS & ERRCLS_INT_PAR)
627    if(!((spId < (S16) tRlcCb->genCfg.maxKwuSaps) && (spId >=0))) 
628    {
629       RLOG0(L_ERROR,"Invalid spId");
630       RLC_SEND_SAPID_ALARM(tRlcCb,spId, LKW_EVENT_KWU_BND_REQ, LCM_CAUSE_INV_SAP);
631       return RFAILED; 
632    }
633 #endif
634
635    /* Get Sap control block */
636    rlckwuSap = (tRlcCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
637             (tRlcCb->u.dlCb->rlcKwuDlSap + spId):
638             (tRlcCb->u.ulCb->rlcKwuUlSap + spId);
639
640    /* Take action based on the current state of the SAP */
641    switch(rlckwuSap->state)
642    {
643       /* SAP is configured but not bound */
644       case RLC_SAP_CFG:
645       case RLC_SAP_UBND:
646       {
647          /* copy bind configuration parameters in sap */
648          rlckwuSap->suId          = suId;
649          rlckwuSap->pst.dstProcId = pst->srcProcId;
650          rlckwuSap->pst.dstEnt    = pst->srcEnt;
651          rlckwuSap->pst.dstInst   = pst->srcInst;
652
653          /* Update the State */
654          rlckwuSap->state = RLC_SAP_BND;
655
656          RLOG1(L_DEBUG, "RlcUiKwuBndReq: state (%d)", rlckwuSap->state);
657          break;
658       }
659       case RLC_SAP_BND:
660       {
661          /* Sap is already bound check source, destination Entity and Proc Id */
662          if (rlckwuSap->pst.dstProcId != pst->srcProcId ||
663              rlckwuSap->pst.dstEnt != pst->srcEnt ||
664              rlckwuSap->pst.dstInst != pst->srcInst ||
665              rlckwuSap->suId != suId)
666          {
667             RLC_SEND_SAPID_ALARM(tRlcCb,
668                                 spId, 
669                                 LKW_EVENT_KWU_BND_REQ, 
670                                 LCM_CAUSE_INV_PAR_VAL);
671             RLOG1(L_ERROR,"RLC Mode [%d] : KWU SAP already Bound",
672                   tRlcCb->genCfg.rlcMode);
673             RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_NOK);
674             return (RFAILED);
675          }
676          break;
677       }
678
679      default:
680       {
681 #if (ERRCLASS & ERRCLS_INT_PAR)
682          RLOG1(L_ERROR,"RLC Mode [%d]:Invalid KWU SAP State in Bind Req",
683                tRlcCb->genCfg.rlcMode);
684          RLC_SEND_SAPID_ALARM(tRlcCb,
685                              spId,
686                              LKW_EVENT_KWU_BND_REQ, 
687                              LCM_CAUSE_INV_STATE);
688 #endif /* ERRCLASS & ERRCLS_INT_PAR */
689          RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_NOK);
690          return (RFAILED);
691       }
692    }
693    RlcUiKwuBndCfm(&(rlckwuSap->pst), rlckwuSap->suId, CM_BND_OK);
694    return (ROK);
695
696
697 \f
698 /**
699  * @brief 
700  *    Handler for unbinding the RLC upper layer service user with 
701  *    the RLC layer.
702  *
703  * @details
704  *    This function is used by RLC user to request for unbinding  
705  *    with RLC.This function is called by the KWU interface to 
706  *    unbind with RLC. 
707  *
708  * @param[in] pst     Post structure  
709  * @param[in] spId    Service provider SAP ID 
710  * @param[in] reason  Reason for Unbinding 
711  *
712  * @return  S16
713  *     -# ROK 
714  *     -# RFAILED
715  */
716 #ifdef ANSI
717 S16 RlcUiKwuUbndReq
718 (
719 Pst      *pst,  
720 SpId     spId, 
721 Reason   reason 
722 )
723 #else
724 S16 RlcUiKwuUbndReq(pst, spId, reason)
725 Pst      *pst; 
726 SpId     spId; 
727 Reason   reason; 
728 #endif
729 {
730    RlcKwuSapCb   *rlckwuSap;   /* KWU SAP control block */
731    RlcCb         *tRlcCb;
732
733 #if (ERRCLASS & ERRCLS_INT_PAR)
734    if ((pst->dstInst >= MAX_RLC_INSTANCES) ||
735        (spId >= (S16) rlcCb[pst->dstInst]->genCfg.maxKwuSaps) ||
736        (spId < 0))
737    {
738       return  (RFAILED);
739    }
740 #endif
741
742    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
743
744    RLOG2(L_DEBUG, "spId(%d), reason(%d)", 
745                 spId, 
746                 reason);
747
748    /* Get Sap control block */
749    rlckwuSap = (tRlcCb->genCfg.rlcMode == LKW_RLC_MODE_DL) ?
750             (tRlcCb->u.dlCb->rlcKwuDlSap + spId):
751             (tRlcCb->u.ulCb->rlcKwuUlSap + spId);
752
753    rlckwuSap->state = RLC_SAP_CFG;
754
755    return ROK;
756
757
758 /**
759  * @brief Handler for receiving the data(SDU) from upper layer. 
760  *
761  * @details
762  *    This function is used by RLC service user (PDCP) to 
763  *    transfer data (SDU) to RLC.
764  *
765  * @param[in] pst         Post structure  
766  * @param[in] spId        Service Provider SAP ID 
767  * @param[in] datreq  Data Request Information
768  * @param[in] mBuf        Data Buffer (SDU) 
769  *
770  * @return  uint8_t
771  *    -# ROK 
772  *    -# RFAILED
773  */
774 uint8_t rlcProcDlData(Pst *pst, KwuDatReqInfo *datReq, Buffer *mBuf)
775 {
776    uint8_t       ret = ROK;   /* Return Value */
777    RlcDlRbCb     *rbCb;       /* RB Control Block */
778    RlcCb         *tRlcCb;
779
780    DU_LOG("\nRLC : Received DL Data");
781
782 #if (ERRCLASS & ERRCLS_INT_PAR)
783    if(pst->dstInst >= MAX_RLC_INSTANCES)
784    {
785       ODU_PUT_MSG_BUF(mBuf);
786       return RFAILED;
787    }
788 #endif
789
790    tRlcCb = RLC_GET_RLCCB(pst->dstInst);
791
792    /* Fetch the RbCb */
793    rlcDbmFetchDlRbCbByRbId(tRlcCb, &datReq->rlcId, &rbCb);
794    if(!rbCb)
795    {
796       DU_LOG("\nRLC : CellId[%u]:DL RbId [%d] not found",
797             datReq->rlcId.cellId,datReq->rlcId.rbId);
798       RLC_FREE_BUF(mBuf);
799
800       return RFAILED;
801    }
802
803    /* Dispatch according to mode of the rbCb */
804    switch (rbCb->mode)
805    {
806       case CM_LTE_MODE_TM:
807       {
808          /* Verify the user */
809          if (pst->srcEnt != ENTNH)
810          {
811             /* kw002.201 Freeing from proper region */
812             RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, datReq, 
813                         sizeof(KwuDatReqInfo));
814             RLC_FREE_BUF(mBuf);
815              
816             return RFAILED;
817          }
818
819          rlcTmmQSdu(tRlcCb,rbCb, datReq, mBuf);
820          break;
821       }
822       case CM_LTE_MODE_UM:
823       {
824          rlcUmmQSdu(tRlcCb,rbCb, datReq, mBuf);
825
826          break;
827       }
828       case CM_LTE_MODE_AM:
829       {
830          rlcAmmQSdu(tRlcCb,rbCb, mBuf, datReq);
831          break;
832       }
833       default:
834       {
835          DU_LOG("\nRLC : Invalid RB Mode");
836          break;
837       }
838    }
839    return ret;
840
841
842 \f
843 /**
844  * @brief 
845  *    Handler for discarding a SDU. 
846  *
847  * @details
848  *    This function is used by RLC AM  and RLC UM entities. 
849  *    This function is called by the service user to discard a particular
850  *    RLC SDU if it is present in the SDU queue of the RB control block 
851  *    and if it is not mapped to any PDU. 
852  *
853  * @param[in] pst            Post structure  
854  * @param[in] spId           Service Provider SAP ID 
855  * @param[in] discSdu        SDU discard Information 
856  *
857  * @return  S16
858  *    -# ROK 
859  *    -# RFAILED
860  */
861 #ifdef ANSI
862 S16 RlcUiKwuDiscSduReq 
863 (
864 Pst              *pst,   
865 SpId             spId,  
866 KwuDiscSduInfo   *discSdu 
867 )
868 #else
869 S16 RlcUiKwuDiscSduReq(pst, spId, discSdu)
870 Pst              *pst;   
871 SpId             spId;  
872 KwuDiscSduInfo   *discSdu; 
873 #endif
874 {
875    RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, discSdu, sizeof(KwuDiscSduInfo));
876    return ROK;
877
878
879 /********************************************************************30**
880          End of file
881 **********************************************************************/