Added code for MAC-PHY interface, DU_APP, F1AP, SCTP and CU stub
[o-du/l2.git] / src / 5gnrrlc / kw_tmm_ul.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
21      Name:     LTE-RLC Layer 
22   
23      Type:     C file
24   
25      Desc:     Source code for RLC Transparent mode assembly and
26                reassembly.This file contains following functions
27                 
28                   --kwTmmQSdu
29                   --kwTmmSndToLi
30                   --kwTmmRcvFrmLi
31                   --kwTmmReEstablish 
32
33      File:     kw_tmm_ul.c
34
35 **********************************************************************/
36 static const char* RLOG_MODULE_NAME="TMM";
37 static int RLOG_MODULE_ID=2048;
38 static int RLOG_FILE_ID=201;
39
40 /** @file kw_tmm_ul.c
41 @brief RLC Transparent Mode module
42 */
43 \f
44 /* header (.h) include files */
45 #include "envopt.h"        /* environment options */
46 #include "envdep.h"        /* environment dependent */
47 #include "envind.h"        /* environment independent */
48
49 #include "gen.h"           /* general */
50 #include "ssi.h"           /* system services */
51 #include "cm5.h"           /* common timer defines */
52 #include "cm_tkns.h"       /* common tokens defines */
53 #include "cm_mblk.h"       /* common memory allocation library defines */
54 #include "cm_llist.h"      /* common link list  defines  */
55 #include "cm_hash.h"       /* common hash list  defines */
56 #include "cm_lte.h"        /* common LTE defines */
57 #include "lkw.h"           /* LKW defines */
58 #include "ckw.h"           /* CKW defines */
59 #include "kwu.h"           /* KWU defines */
60 #include "rgu.h"           /* RGU defines */
61 #include "kw_env.h"        /* RLC environment options */
62
63 #include "kw.h"            /* RLC defines */
64 #include "kw_err.h"            /* RLC defines */
65 #include "kw_ul.h"
66
67 /* extern (.x) include files */
68 #include "gen.x"           /* general */
69 #include "ssi.x"           /* system services */
70
71 #include "cm5.x"           /* common timer library */
72 #include "cm_tkns.x"       /* common tokens */
73 #include "cm_mblk.x"       /* common memory allocation */
74 #include "cm_llist.x"      /* common link list */
75 #include "cm_hash.x"       /* common hash list */
76 #include "cm_lte.x"        /* common LTE includes */
77 #include "cm_lib.x"        /* common memory allocation library */
78 #include "lkw.x"           /* LKW */
79 #include "ckw.x"           /* CKW */
80 #include "kwu.x"           /* KWU */
81 #include "rgu.x"           /* RGU */
82
83 #include "kw.x"
84 #include "kw_ul.x"
85
86 #if defined(PRE_DEF_UE_CTX) || defined(PRE_DEF_UE_CTX_HO)
87 #ifdef EG_GEN_LOAD_5GTF
88 extern U32 loadStart;
89 #endif
90
91 EXTERN S16 PjUiPjuDatInd(Pst* pst,SuId suId,CmLtePdcpId * pdcpId,Buffer *mBuf);
92 #ifdef ANSI
93 PUBLIC Void AddUeContext
94 (
95 CmLteRnti   crnti,
96 U8 rrcMsgType
97 )
98 #else
99 PUBLIC Void AddUeContext(crnti,rrcMsgType)
100 CmLteRnti   crnti,
101 U8 rrcMsgType 
102 #endif
103 {
104    KwuDatIndInfo   *datIndInfo;   /* Data Indication Information */
105    U8 rrcConReq[6] ={ 0x50, 0x30, 0x30, 0x30, 0x30, 0x34 };
106    U8 rrcConSetupComplete[34] ={ 0x20, 0x00, 0x3e, 0x0e, 0x82, 0x02, 0x10, 0x12, 0x20, 0x02, 0x20, 0x64, 0xa8, 0x2c, 0x48, 0x05, 0x00, 0x80, 0x00, 0x08, 0x04, 0x03, 0xa0, 0x02, 0xa0, 0x10, 0x12, 0x20, 0x02, 0x20, 0x64, 0xa8, 0x2c, 0x48};
107 #ifndef CA_PAL_5GTF 
108    U8 rrcUeCapabilityInfo[12] ={0x38, 0x01, 0x00, 0x80, 0x1b, 0xff, 0x0c, 0x00, 0x20, 0x00, 0x80, 0x00};
109 #else
110   /* U8 rrcUeCapabilityInfo[44] ={0x38,0x01,0x02,0x84,0x9b,0xff,0x0c,0x00,0x20,0x00,0x80,0x1f,0xfe,0xf4,0x4f,0xe0,0x40,0x03,0x80,0x11,0x04,0x0c,0x20,0x88,0x20,0x7f,0xff,0xff,0xff,0xf3,0xff,0x81,0xff,0xff,0xff,0xff,0x7f,0xf0,0x3f,0xff,0xff,0xff,0xe0,0x00};
111 */
112 U8 rrcUeCapabilityInfo[] = 
113 {
114  0x38,0x01,0x03,0x34,0x9b,0xff,0x0c,0x00,0x20,0x00,0x80,0x1f,0xfe,0xf4,0x4f,0xe0
115  ,0x40,0x09,0x80,0x11,0x04,0x0c,0x20,0x88,0x20,0x63,0x04,0x41,0x03,0x20,0x22,0x08
116  ,0x19,0x61,0x10,0x40,0xff,0xff,0xff,0xff,0xe7,0xff,0x03,0xff,0xff,0xff,0xfe,0xff
117  ,0xe0,0x7f,0xff,0xff,0xff,0xc0,0x00
118 };
119
120 #endif
121    U8 rrcSecurityModeComplete[2] ={0x28, 0x80};
122    U8 rrcReconfigComplete[2] ={0x10, 0x80};
123
124    Buffer *pdu;
125
126    Pst ulPst1 ={100,100,217,0,215,0,PRIOR0,0,81,1,1,0,0};
127 #ifdef PJ
128    Pst ulPst2 ={100,100,217,0,216,0,PRIOR0,0,68,0,1,0,0};
129 #endif
130   TRC2(kwTmmRcvFrmLi) 
131
132   if(1 == rrcMsgType)
133   {
134
135    KwuDatIndInfo datIndInfoTmp;
136    datIndInfo = &datIndInfoTmp;
137    datIndInfo->rlcId.rbId = 5;
138    datIndInfo->rlcId.rbType = 0;
139    datIndInfo->rlcId.ueId = 0;
140    datIndInfo->rlcId.cellId = 1;
141    datIndInfo->tCrnti = crnti;
142    datIndInfo->isOutOfSeq = 16;
143
144    SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
145   
146    SAddPstMsgMult(rrcConReq,6,pdu);
147
148    RLOG1(L_INFO,"Profiling Framework Sending RRC Connection Req to RRC for UE :%d\n",crnti);
149    printf("Profiling Framework Sending RRC Connection Req to RRC for UE :%d\n",crnti);
150    KwUiKwuDatInd(&ulPst1, 1, datIndInfo, pdu);
151  }
152  else if(2 == rrcMsgType)
153  {
154 #ifdef PJ
155     CmLtePdcpId pdcpId;
156     pdcpId.cellId = 1;
157     pdcpId.ueId = crnti;
158     pdcpId.rbId = 1;
159     pdcpId.rbType = 0;
160 #endif   
161     SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
162   
163     SAddPstMsgMult(rrcConSetupComplete,34,pdu);
164
165     RLOG1(L_INFO,"Profiling Framework: Sending RRC Connection Setup Complete to RRC for UE :%d\n",crnti);
166     printf("Profiling Framework: Sending RRC Connection Setup Complete to RRC for UE :%d\n",crnti);
167 #ifdef PJ
168     PjUiPjuDatInd(&ulPst2, 1, &pdcpId, pdu);
169 #endif
170  }
171  
172  else if(3 == rrcMsgType)
173  {
174 #ifdef PJ
175     CmLtePdcpId pdcpId;
176     pdcpId.cellId = 1;
177     pdcpId.ueId = crnti;
178     pdcpId.rbId = 1;
179     pdcpId.rbType = 0;
180 #endif   
181     SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
182   
183 #ifndef CA_PAL_5GTF 
184     SAddPstMsgMult(rrcUeCapabilityInfo,12,pdu);
185 #else    
186     SAddPstMsgMult(rrcUeCapabilityInfo,sizeof(rrcUeCapabilityInfo),pdu);
187 #endif
188     RLOG1(L_INFO,"Profiling Framework: Sending RRC UE Capability Info to RRC for UE :%d\n",crnti);
189     printf("Profiling Framework: Sending RRC UE Capability Info to RRC for UE :%d\n",crnti);
190 #ifdef PJ
191     PjUiPjuDatInd(&ulPst2, 1, &pdcpId, pdu);
192 #endif
193
194  }
195  else if(4 == rrcMsgType)
196  {
197 #ifdef PJ
198     CmLtePdcpId pdcpId;
199     pdcpId.cellId = 1;
200     pdcpId.ueId = crnti;
201     pdcpId.rbId = 1;
202     pdcpId.rbType = 0;
203 #endif
204    
205     SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
206   
207     SAddPstMsgMult(rrcSecurityModeComplete,2,pdu);
208
209     RLOG1(L_INFO,"Profiling Framework: Sending RRC Security Mode Complete to RRC for UE :%d\n",crnti);
210     printf("Profiling Framework: Sending RRC Security Mode Complete to RRC for UE :%d\n",crnti);
211 #ifdef PJ
212     PjUiPjuDatInd(&ulPst2, 1, &pdcpId, pdu);
213 #endif
214  }
215  else if(5 == rrcMsgType)
216  {
217 #ifdef PJ
218     CmLtePdcpId pdcpId;
219     pdcpId.cellId = 1;
220     pdcpId.ueId = crnti;
221     pdcpId.rbId = 1;
222     pdcpId.rbType = 0;
223 #endif
224    
225     SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
226   
227     SAddPstMsgMult(rrcReconfigComplete,2,pdu);
228
229     RLOG1(L_INFO,"Profiling Framework: Sending RRC Reconfig Complete to RRC for UE :%d\n",crnti);
230     printf("Profiling Framework: Sending RRC Reconfig Complete to RRC for UE :%d\n",crnti);
231 #ifdef PJ
232     PjUiPjuDatInd(&ulPst2, 1, &pdcpId, pdu);
233 #ifdef EG_GEN_LOAD_5GTF
234     loadStart=1;
235 #endif
236 #endif
237  }
238  RETVOID;
239 }
240 #endif 
241 /** @addtogroup tmmode */
242 /*@{*/
243
244 #define KW_MODULE (KW_DBGMASK_TM | KW_DBGMASK_UL)
245
246 /**
247  * @brief
248  *    Handler to process the Data Indication from the lower layer and send the 
249  *    SDU to upper layer.
250  *
251  * @details
252  *    This function processes the PDU receivied from the lower layer and sends 
253  *    the same pdu as SDU to the upper layer.It sends CRNTI along with the SDU 
254  *    for CCCH.
255  *            
256  * @param[in] gCb     RLC Instance Control Block
257  * @param[in] rbCb    RB control block. 
258  * @param[in] tCrnti  TCRNTI  
259  * @param[in] pdu     PDU
260  * 
261  * @return  S16
262  *    -# ROK 
263  *    -# RFAILED 
264  */
265 #ifdef CCPU_OPT
266 #ifdef ANSI
267 PUBLIC Void kwTmmRcvFrmLi
268 (
269 KwCb        *gCb,
270 KwUlRbCb    *rbCb,  
271 CmLteRnti   tCrnti,  
272 Buffer      *pdu      
273 )
274 #else
275 PUBLIC Void kwTmmRcvFrmLi(gCb,rbCb, tCrnti, pdu)
276 KwCb        *gCb;
277 KwUlRbCb    *rbCb;  
278 CmLteRnti   tCrnti; 
279 Buffer      *pdu;  
280 #endif
281 #else
282 #ifdef ANSI
283 PUBLIC Void kwTmmRcvFrmLi
284 (
285 KwCb       *gCb,
286 KwUlRbCb   *rbCb,         
287 Buffer     *pdu            
288 )
289 #else
290 PUBLIC Void kwTmmRcvFrmLi(gCb,rbCb, pdu)
291 KwCb       *gCb;
292 KwUlRbCb   *rbCb;         
293 Buffer     *pdu;         
294 #endif
295 #endif 
296 {
297    KwuDatIndInfo   *datIndInfo;   /* Data Indication Information */
298    MsgLen          msgLen;
299  
300    TRC2(kwTmmRcvFrmLi) 
301
302    /* Creating static memory for KwuDatIndInfo. #else will be 
303     * removed once the sanity testing is performed for all platforms */
304    KwuDatIndInfo datIndInfoTmp;
305    datIndInfo = &datIndInfoTmp;
306 #if (ERRCLASS & ERRCLS_ADD_RES)
307    if ( datIndInfo == NULLP )
308    {   
309       RLOG_ARG2(L_FATAL,DBG_RBID,rbCb->rlcId.rbId,
310             "Memory Allocation failed UEID:%d CELLID:%d",
311             rbCb->rlcId.ueId,
312             rbCb->rlcId.cellId);   
313       RETVOID;
314    }
315 #endif /* ERRCLASS & ERRCLS_ADD_RES */
316    KW_MEM_CPY(&(datIndInfo->rlcId),&(rbCb->rlcId),sizeof(CmLteRlcId));
317 #ifdef CCPU_OPT 
318    if ( rbCb->lch.lChType == CM_LTE_LCH_CCCH ) 
319    {
320       datIndInfo->tCrnti = tCrnti;
321    }
322 #endif 
323    gCb->genSts.pdusRecv++;
324    SFndLenMsg(pdu, &msgLen);
325    gCb->genSts.bytesRecv += msgLen;
326    /* If trace flag is enabled send the trace indication */
327    if(gCb->init.trc == TRUE)
328    {
329       /* Populate the trace params */
330       kwLmmSendTrc(gCb,KWU_EVT_DAT_IND, pdu);
331    }
332    KwUiKwuDatInd( &gCb->u.ulCb->kwuUlSap->pst, 
333                   gCb->u.ulCb->kwuUlSap->suId, 
334                   datIndInfo, pdu);
335    
336    RETVOID;
337 }
338
339 /**
340  * @brief 
341  *    Handler to process the re-establishment request received from the upper 
342  *    layer. It is just a hook for future enhancement. 
343  *
344  *            
345  * @param[in] gCb   RLC Instance Control Block
346  * @param[in] rbCb  RB control block. 
347  *
348  * @return  S16
349  *    -# ROK 
350  *       
351  **/
352 #ifdef ANSI
353 PUBLIC Void kwTmmUlReEstablish
354 (
355 KwCb        *gCb,
356 KwUlRbCb    *rbCb        
357 )
358 #else
359 PUBLIC Void kwTmmUlReEstablish(rbCb)
360 KwCb        *gCb;
361 KwRbCb      *rbCb;          
362 #endif
363 {
364    TRC2(kwUlTmmReEstablish)
365
366    RLOG_ARG0(L_DEBUG,DBG_RBID,rbCb->rlcId.rbId,"do nothing for TMM for ReEstablish");
367    RETVOID;
368 }
369
370 #ifdef _cplusplus
371 }
372 #endif
373 /*@}*/
374 /********************************************************************30**
375          End of file
376 **********************************************************************/