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