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