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