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