Committing in PDCP code
[o-du/l2.git] / src / 5gnrpdcp / pj_ul_ex_ms.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-PDCP Layer - System Services Interface Functions
22
23    Type:    C file
24
25    Desc:    C source code for the interface to System Services of LTE-PDCP
26
27    File:    pj_ul_ex_ms.c
28
29 *********************************************************************21*/
30 static const char* RLOG_MODULE_NAME="PDCP";
31 static int RLOG_MODULE_ID=1024;
32 static int RLOG_FILE_ID=243;
33 /** @file pj_ul_ex_ms.c
34   @brief PDCP System Services Interface
35  */
36
37
38 /* header (.h) include files */
39 #include "envopt.h"        /* environment options */
40 #include "envdep.h"        /* environment dependent */
41 #include "envind.h"        /* environment independent */
42
43 #include "gen.h"           /* general */
44 #include "ssi.h"           /* system services */
45 #include "cm5.h"           /* common timer defines */
46 #include "cm_tkns.h"       /* common tokens defines */
47 #include "cm_mblk.h"       /* common memory allocation library defines */
48 #include "cm_llist.h"      /* common link list  defines  */
49 #include "cm_hash.h"       /* common hash list  defines */
50 #include "cm_lte.h"        /* common LTE defines */
51 #include "kwu.h"           /* KWU defines */
52 #include "cpj.h"           /* CPJ defines */
53 #include "pju.h"           /* PJU defines */
54 #include "lpj.h"           /* LPJ defines */
55 #include "pj_err.h"        /* Err defines */
56 #include "pj_env.h"        /* RLC environment options */
57 #include "pj.h"            /* RLC defines */
58 #include "pj_udx.h"
59 #include "pj_dl.h"        
60 #include "pj_lib.h"
61
62 /* extern (.x) include files */
63 #include "gen.x"           /* general */
64 #include "ssi.x"           /* system services */
65
66 #include "cm5.x"           /* common timer library */
67 #include "cm_tkns.x"       /* common tokens */
68 #include "cm_mblk.x"       /* common memory allocation */
69 #include "cm_llist.x"      /* common link list */
70 #include "cm_hash.x"       /* common hash list */
71 #include "cm_lte.x"        /* common LTE includes */
72 #include "cm_lib.x"        /* common memory allocation library */
73 #include "kwu.x"           /* KWU */
74 #include "cpj.x"           /* CPJ defines */
75 #include "pju.x"           /* PJU defines */
76 #include "lpj.x"           /* LPJ defines */
77 #include "pj.x"
78 #include "pj_udx.x"
79 #include "pj_dl.x"        
80 #include "pj_lib.x"
81 #ifdef TENB_STATS
82 #ifndef L2_L3_SPLIT
83 #include "pj_tenb_stats.x"   
84 #else
85 #include "l2_tenb_stats.x"
86 #endif
87 #endif
88 #if (defined(TENB_STATS) && !(defined(L2_L3_SPLIT)))
89 #include "l2_tenb_stats.x"   
90 #endif
91
92 EXTERN Void pjMsNativeSpaccProcessUlOutput(Void);
93 EXTERN Void EgTLSendMsg(Bool);
94 /***********************************************************************
95   System Service Interface Functions
96  ***********************************************************************/
97 /**
98  *
99  * @brief
100  *
101  *    <b> Activates Initialization </b>
102  *
103  *    @b Description:
104  *    This function is invoked by system services to initialize the LTE-PDCP
105  *    layer. This is an entry point used by LTE_PDCP layer to initialize its
106  *    global variables, before becoming operational.
107  *
108  *    Allowable values for parameters are specified in ssi.h.
109  *
110  *    @param[in] ent    - Specify the entity id of the LTE-RLC task.
111  *    @param[in] inst   - Specify the entity id of the LTE-RLC task.
112  *    @param[in] region - Specifies the memory region from which
113  *                         LTE-PDCP should allocate structures and buffers.
114  *    @param[in] reason - Specifies the reason for calling this
115  *                         initialization function.
116  *
117  *  @return  S16
118  *      -# ROK
119  *
120  */
121 #ifdef ANSI
122 PUBLIC S16 pjUlActvInit
123 (
124  Ent    ent,                 /* entity */
125  Inst   inst,                /* instance */
126  Region region,              /* region */
127  Reason reason               /* reason */
128  )
129 #else
130 PUBLIC S16 pjUlActvInit(ent, inst, region, reason)
131   Ent    ent;                 /* entity */
132   Inst   inst;                /* instance */
133   Region region;              /* region */
134   Reason reason;              /* reason */
135 #endif
136 {
137    PjCb   *tPjCb;
138    TRC3(pjUlActvInit)
139          
140    if (inst >= PJ_MAX_PDCP_INSTANCES)
141    {
142        /* intance greater than MAX instances */ 
143        RETVALUE(RFAILED); 
144    }
145
146    if (pjCb[inst] != NULLP)
147    {
148       RETVALUE (RFAILED);
149    }
150
151    if (SGetSBuf(region, 0, (Data **)&tPjCb,
152             (Size)sizeof (PjCb)) != ROK)
153    {
154       RETVALUE(RFAILED);
155    }
156    /* Initialize kwCb */
157    PJ_MEM_SET(tPjCb, 0, sizeof(PjCb));
158
159    /* Initialize task configuration parameters */
160    /* We will take only entity name */
161    tPjCb->init.ent     = ent;           /* entity */
162    tPjCb->init.inst    = inst;          /* instance */
163    tPjCb->init.region  = region;        /* static region */
164    tPjCb->init.pool    = 0;             /* static pool */
165    tPjCb->init.reason  = reason;        /* reason */
166    tPjCb->init.cfgDone = FALSE;         /* configuration done */
167    tPjCb->init.acnt    = TRUE;          /* enable accounting */
168    tPjCb->init.usta    = TRUE;          /* enable unsolicited status */
169    tPjCb->init.trc     = FALSE;         /* enable trace */
170 #ifdef DEBUGP
171    tPjCb->init.dbgMask = 0x00000;
172 #endif
173    tPjCb->init.procId  = SFndProcId();
174
175    pjCb[inst] = tPjCb;
176 #if (defined(TENB_STATS) && !(defined(L2_L3_SPLIT)))
177    TSL2AllocStatsMem(tPjCb->init.region, tPjCb->init.pool); 
178 #endif
179
180   RETVALUE(ROK);
181 } /* pjActvInit */
182
183 \f
184 /**
185  *
186  * @brief
187  *
188  *  <b> Activation Task </b>
189  *
190  *  @b Description:
191  *  Processes events received for LTE-PDCP layer via System Services from
192  *  other layers.
193  *
194  *  @param[in] pst   - Pst Structure
195  *  @param[in] mBuf  - Message Buffer
196  *
197  *  @return  S16
198  *      -# ROK 
199  *
200  */
201 #ifdef ANSI
202 PUBLIC S16 pjUlActvTsk
203 (
204 Pst *pst,              /* pst structure */
205 Buffer *mBuf            /* message buffer */
206 )
207 #else
208 PUBLIC S16 pjUlActvTsk(pst, mBuf)
209 Pst *pst;              /* pst structure */
210 Buffer *mBuf;           /* message buffer */
211 #endif
212 {
213    S16 ret = ROK;
214
215    TRC3(pjUlActvTsk);
216
217    switch(pst->srcEnt)
218    {
219       case ENTSM:
220          {
221             switch(pst->event)
222             {
223 #ifdef LCLPJ
224                case LPJ_EVT_CFG_REQ:
225                   {
226                      ret = cmUnpkLpjCfgReq(PjMiLpjCfgReq, pst, mBuf);
227                      break;
228                   }
229
230                case LPJ_EVT_CNTRL_REQ:
231                   {
232                      ret = cmUnpkLpjCntrlReq(PjMiLpjCntrlReq, pst, mBuf);
233                      break;
234                   }
235
236                case LPJ_EVT_STS_REQ:
237                   {
238                      ret = cmUnpkLpjStsReq(PjMiLpjStsReq, pst, mBuf);
239                      break;
240                   }
241
242                case LPJ_EVT_STA_REQ:
243                   {
244                      ret = cmUnpkLpjStaReq(PjMiLpjStaReq, pst, mBuf);
245                      break;
246                   }
247                   /* kw005.201 added support for L2 Measurement */
248 #ifdef LTE_L2_MEAS
249                case LPJ_EVT_L2MEAS_REQ:
250                   {
251                      ret = cmUnpkLpjL2MeasReq(PjMiLpjL2MeasReq, pst, mBuf);
252                      break;
253                   }
254                case LPJ_EVT_L2MEAS_SEND_REQ:
255                  {
256
257                     ret = cmUnpkLpjL2MeasSendReq(PjMiLpjL2MeasSendReq, pst, mBuf); 
258   
259                      break;
260                  }
261                case LPJ_EVT_L2MEAS_STOP_REQ:
262                  {
263                      ret = cmUnpkLpjL2MeasStopReq(PjMiLpjL2MeasStopReq, pst, mBuf);
264                      break;
265                  }
266 #endif
267
268                default:
269                   {
270                      RLOG1(L_ERROR, "Received Invalid Event[%d] from SM", pst->event);
271                      ret = RFAILED;
272                      break;
273                   }
274 #endif  /* LCLPJ */
275             }
276             break;
277          }
278
279       case ENTWR:
280          {
281             switch(pst->event)
282             {
283
284                case EVTCPJKDFREQ:
285                {
286                    cmUnpkCpjKdfReq(PjUiCpjKdfReq, pst, mBuf);
287                   break;
288                }
289
290             default:
291                   SPutMsg(mBuf);
292                    RLOG1(L_ERROR, "Received Invalid Event[%d] from APP", pst->event);
293                   ret = RFAILED;
294                   break;
295             }
296             break;
297          }
298
299       case ENTPJ:
300          {
301             switch(pst->event)
302             {
303 #ifdef LCUDX
304             case EVTUDXBNDCFM:
305                   {
306                      cmUnpkPjUdxBndCfm(PjUlUdxBndCfm, pst, mBuf);
307                      break;
308                   }
309
310             case EVTUDXCFGCFM:
311                   {
312                      cmUnpkPjUdxCfgCfm(PjUlUdxCfgCfm, pst, mBuf);
313                      break;
314                   }
315
316             case EVTUDXREESTCFM:
317                   {
318                      cmUnpkPjUdxReEstCfm(PjUlUdxReEstCfm, pst, mBuf);
319                      break;
320                   }
321
322             case EVTUDXSECCFGCFM:
323                   {
324                      cmUnpkPjUdxSecCfgCfm(PjUlUdxSecCfgCfm, pst, mBuf);
325                      break;
326                   }
327
328             case EVTUDXUEIDCHGCFM:
329                   {
330                      cmUnpkPjUdxUeIdChgCfm(PjUlUdxUeIdChgCfm, pst, mBuf);
331                      break;
332                   }
333
334             case EVTUDXCOUNTCFM:
335                   {
336                      cmUnpkPjUdxCountCfm(PjUlUdxCountCfm, pst, mBuf);
337                      break;
338                   }
339
340             case EVTUDXSDUSTACFM:
341                   {
342                      cmUnpkPjUdxSduStaCfm(PjUlUdxSduStaCfm, pst, mBuf);
343                      break;
344                   }
345             case EVTUDXDATRESUMECFM:
346                   {
347                      cmUnpkPjUdxDatResumeCfm(PjUlUdxDatResumeCfm, pst, mBuf);
348                      break;
349                   }
350             case EVTUDXDATFRWDCFM:
351                   {
352                      cmUnpkPjUdxDatForwardCfm(PjUlUdxDatForwardCfm, pst, mBuf);
353                      break; 
354                   }                  
355 #endif /* LCCPJ */
356               default:
357                   SPutMsg(mBuf);
358                   RLOG1(L_ERROR, "Received Invalid Event[%d] from PDCP DL", pst->event);
359                   ret = RFAILED;
360                   break;
361
362             }
363             break;
364          }
365
366
367       case ENTNH:
368          {
369             switch(pst->event)
370             {
371 #ifdef LCCPJ
372             case EVTCPJBNDREQ:
373                   {
374                      cmUnpkCpjBndReq(PjUiCpjBndReq, pst, mBuf);
375                      break;
376                   }
377
378             case EVTCPJUBNDREQ:
379                   {
380                      cmUnpkCpjUbndReq(PjUiCpjUbndReq, pst, mBuf);
381                      break;
382                   }
383
384             case EVTCPJCFGREQ:
385                   {
386                      cmUnpkCpjCfgReq(PjUiCpjCfgReq, pst, mBuf);
387                      break;
388                   }
389
390             case EVTCPJREESTREQ:
391                   {
392                      cmUnpkCpjReEstReq(PjUiCpjReEstReq, pst, mBuf);
393                      break;
394                   }
395
396             case EVTCPJSECCFGREQ:
397                   {
398                      cmUnpkCpjSecCfgReq(PjUiCpjSecCfgReq, pst, mBuf);
399                      break;
400                   }
401
402             case EVTCPJUEIDCHGREQ:
403                   {
404                      cmUnpkCpjUeIdChgReq(PjUiCpjUeIdChgReq, pst, mBuf);
405                      break;
406                   }
407
408             case EVTCPJCOUNTREQ:
409                   {
410                      cmUnpkCpjCountReq(PjUiCpjCountReq, pst, mBuf);
411                      break;
412                   }
413
414             case EVTCPJSDUSTAREQ:
415                   {
416                      cmUnpkCpjSduStaReq(PjUiCpjSduStaReq, pst, mBuf);
417                      break;
418                   }
419               case EVTCPJSTARTDATAFWDREQ: /* Start Data Forwarding Request from RRC user for Source eNB during HO */
420                   {
421                       cmUnpkCpjStartDataFwdReq(PjUiCpjDatForwardReq, pst, mBuf);
422                       break;
423                   }
424               case EVTCPJDATRESUMEREQ: /* Data Resume Request from RRC user during Re-establishment */
425                   {
426                       cmUnpkCpjDatResumeReq(PjUiCpjDatResumeReq, pst, mBuf);
427                       break;
428                   }
429 #endif /* LCCPJ */
430 #ifdef LCPJU 
431             case EVTPJUBNDREQ:
432                   {
433                      cmUnpkPjuBndReq(PjUiPjuBndReq, pst, mBuf);
434                      break;
435                   }
436
437             case EVTPJUUBNDREQ:
438                   {
439                      cmUnpkPjuUbndReq(PjUiPjuUbndReq, pst, mBuf);
440                      break;
441                   }
442
443               case EVTPJUDATFWDREQ:
444                   {
445                      cmUnpkPjuDatFwdReq(PjUiPjuDatFwdReq, pst, mBuf);
446                      break;
447                   }
448 #endif
449               default:
450                   SPutMsg(mBuf);
451                   RLOG1(L_ERROR, "Received Invalid Event[%d] from RRC",pst->event);
452                   ret = RFAILED;
453                   break;
454
455             }
456             break;
457          }
458     case ENTPX:
459          {
460             switch(pst->event)
461             {
462 #ifdef LCPJU
463                case EVTPJUBNDREQ:
464                   {
465                      cmUnpkPjuBndReq(PjUiPjuBndReq, pst, mBuf);
466                      break;
467                   }
468
469                case EVTPJUUBNDREQ:
470                   {
471                      cmUnpkPjuUbndReq(PjUiPjuUbndReq, pst, mBuf);
472                      break;
473                   }
474
475                case EVTPJUDATREQ:
476                   {
477                      cmUnpkPjuDatReq(PjUiPjuDatReq, pst, mBuf);
478                      break;
479                   }
480
481                case EVTPJUDATFWDREQ:
482                   {
483                      cmUnpkPjuDatFwdReq(PjUiPjuDatFwdReq, pst, mBuf);
484                      break;
485                   }
486 #endif
487                default:
488                   SPutMsg(mBuf);
489                   RLOG1(L_ERROR, "Received Invalid Event[%d] from Relay", pst->event);
490                   ret = RFAILED;
491                   break;
492             }
493             break;
494          }
495    
496       case ENTOC:
497          {
498             switch(pst->event)
499             {
500 #ifdef PJ_CMP_ASYNC
501                /* Compression Confirmations */
502                case OBD_EVT_CMP_INIT_CFM:
503                   ret = cmUnpkLibObdCmpInitCfm(PjLibObdCmpInitCfm, pst, mBuf);
504                   break;
505
506                case OBD_EVT_DECMP_CFM:
507                   ret = cmUnpkLibObdDecmpCfm(PjLibObdDecmpCfm, pst, mBuf);
508                   break;
509 #endif /* PJ_CMP_ASYNC */
510                default:
511                   SPutMsg(mBuf);
512                   RLOG1(L_ERROR, "Received Invalid Event[%d] from Offboard Compression",pst->event);
513                   ret = RFAILED;
514                   break;
515             }
516             break;
517          }
518
519       case ENTOS:
520          {
521             switch(pst->event)
522             {
523 #ifdef PJ_SEC_ASYNC
524                   /* Integrity Confirmations */
525                case OBD_EVT_INT_INIT_CFM:
526                   ret = cmUnpkLibObdIntInitCfm(PjLibObdIntInitCfm, pst, mBuf);
527                   break;
528
529                case OBD_EVT_INT_VER_CFM:
530                   ret = cmUnpkLibObdIntVerCfm(PjLibObdIntVerCfm, pst, mBuf);
531                   break;
532
533                   /* Ciphering Confirmations */
534                case OBD_EVT_CP_INIT_CFM:
535                   ret = cmUnpkLibObdCpInitCfm(PjLibObdCpInitCfm, pst, mBuf); /* TODO - Only Dl path? */
536                   break;
537
538                case OBD_EVT_UP_INIT_CFM:
539                   ret = cmUnpkLibObdUpInitCfm(PjLibObdUpInitCfm, pst, mBuf); /* TODO - Only Dl path? */
540                   break;
541
542                case OBD_EVT_DECIPHER_CFM:
543                   ret = cmUnpkLibObdDecipherCfm(PjLibObdDecipherCfm, pst, mBuf);
544                   break;
545 #endif /* PJ_SEC_ASYNC */
546                default:
547                   SPutMsg(mBuf);
548                   RLOG1(L_ERROR, "Received Invalid Event[%d] from Offboard Security",pst->event);
549                   ret = RFAILED;
550                   break;
551             }
552             break;
553          }
554       case ENTKW:
555          {
556             switch(pst->event)
557             {
558 #ifdef LCKWU
559                case KWU_EVT_BND_CFM:     /* Bind request */
560                   {
561                      ret = cmUnpkKwuBndCfm(PjLiKwuBndCfm, pst, mBuf );
562                      break;
563                   }
564
565                case KWU_EVT_DAT_IND:    /* Coomon Channel Data request */
566                   {
567                      ret = cmUnpkKwuDatInd(PjLiKwuDatInd, pst, mBuf);
568                      break;
569                   }
570
571                case KWU_EVT_REEST_CMP_IND:    /* Dedicated Channel Status Response */
572                   {
573                      ret = cmUnpkKwuReEstCmpInd(PjLiKwuReEstCmpInd, pst, mBuf);
574                      break;
575                   }
576 #ifdef LTE_L2_MEAS
577                case KWU_EVT_DAT_ACK_IND:    /* Harq status indication */
578                   {
579                      ret = cmUnpkKwuDatAckInd(PjLiKwuDatAckInd, pst, mBuf);
580                      break;
581                   }
582 #endif
583                default:
584                   {
585                      SPutMsg(mBuf);
586                      RLOG1(L_ERROR, "Received Invalid Event[%d] from RLC", pst->event);
587                      ret = RFAILED;
588                      break;
589                    }
590
591 #endif  /* LCRGU */
592             }
593             break;
594          }
595 #if (defined(TENB_STATS) && !(defined(L2_L3_SPLIT)))
596       case ENTTF:
597          {
598             switch(pst->event)
599             {
600                case TENBSTATSINIT:
601                {
602                   PjCb *tPjCb;
603                   tPjCb = PJ_GET_PJCB(pst->dstInst);
604                   TSL2SendStatsToApp(&(tPjCb->pjGenCfg.lmPst), 0);
605                   SPutMsg(mBuf);
606                   break;
607                }
608                default:
609                {
610                   printf("\n ERROR Invalid Event[%d] from CL to PDCPUL\n", 
611                          pst->event);
612                   SPutMsg(mBuf);
613                   break;
614                }
615             }
616             break;
617          }
618 #endif
619 #if (defined(TENB_AS_SECURITY) && defined(UL_DL_SPLIT))
620       case ENTYS:
621          {
622             switch(pst->event)
623             {
624                case EVTPJUTTIIND:
625                {
626                   pjMsNativeSpaccProcessUlOutput();
627                   SPutMsg(mBuf);
628
629 #ifndef SS_RBUF
630                      EgTLSendMsg(FALSE); /* Arg FALSE is req if ENB_CPU_OVERLOAD_CONTROL is enabled,
631                                             just to control the num of pkts to be sent over the socket*/
632 #else
633                      EgTLSendMsg();
634 #endif
635                   break;
636                } 
637             }
638             break;
639          }
640 #endif
641       default:
642          {
643             RLOG1(L_ERROR, "Received Invalid Src Entity[%d]", pst->event);
644             SPutMsg(mBuf);
645             ret = RFAILED;
646             break;
647          }
648    }
649
650    SExitTsk();
651
652    RETVALUE(ret);
653 } /* pjActvTsk */
654
655 \f  
656 /********************************************************************30**
657          End of file
658 **********************************************************************/