6777cdf933196728f4411aa332ac376fba7e2eb9
[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                   --rlcTmmQSdu
29                   --rlcTmmSndToLi
30                   --rlcTmmRcvFrmLi
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 "common_def.h"
46 #include "lkw.h"           /* LKW defines */
47 #include "ckw.h"           /* CKW defines */
48 #include "kwu.h"           /* KWU defines */
49 #include "rgu.h"           /* RGU defines */
50 #include "kw_env.h"        /* RLC environment options */
51
52 #include "kw.h"            /* RLC defines */
53 #include "kw_err.h"            /* RLC defines */
54 #include "kw_ul.h"
55
56 /* extern (.x) include files */
57 #include "lkw.x"           /* LKW */
58 #include "ckw.x"           /* CKW */
59 #include "kwu.x"           /* KWU */
60 #include "rgu.x"           /* RGU */
61
62 #include "kw.x"
63 #include "kw_ul.x"
64 #include "du_app_rlc_inf.h"
65 #include "rlc_utils.h"
66 #include "rlc_upr_inf_api.h"
67
68 #if defined(PRE_DEF_UE_CTX) || defined(PRE_DEF_UE_CTX_HO)
69 #ifdef EG_GEN_LOAD_5GTF
70 extern U32 loadStart;
71 #endif
72
73 EXTERN S16 PjUiPjuDatInd(Pst* pst,SuId suId,CmLtePdcpId * pdcpId,Buffer *mBuf);
74 #ifdef ANSI
75 Void AddUeContext
76 (
77 CmLteRnti   crnti,
78 U8 rrcMsgType
79 )
80 #else
81 Void AddUeContext(crnti,rrcMsgType)
82 CmLteRnti   crnti,
83 U8 rrcMsgType 
84 #endif
85 {
86    KwuDatIndInfo   *datIndInfo;   /* Data Indication Information */
87    U8 rrcConReq[6] ={ 0x50, 0x30, 0x30, 0x30, 0x30, 0x34 };
88    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};
89 #ifndef CA_PAL_5GTF 
90    U8 rrcUeCapabilityInfo[12] ={0x38, 0x01, 0x00, 0x80, 0x1b, 0xff, 0x0c, 0x00, 0x20, 0x00, 0x80, 0x00};
91 #else
92   /* 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};
93 */
94 U8 rrcUeCapabilityInfo[] = 
95 {
96  0x38,0x01,0x03,0x34,0x9b,0xff,0x0c,0x00,0x20,0x00,0x80,0x1f,0xfe,0xf4,0x4f,0xe0
97  ,0x40,0x09,0x80,0x11,0x04,0x0c,0x20,0x88,0x20,0x63,0x04,0x41,0x03,0x20,0x22,0x08
98  ,0x19,0x61,0x10,0x40,0xff,0xff,0xff,0xff,0xe7,0xff,0x03,0xff,0xff,0xff,0xfe,0xff
99  ,0xe0,0x7f,0xff,0xff,0xff,0xc0,0x00
100 };
101
102 #endif
103    U8 rrcSecurityModeComplete[2] ={0x28, 0x80};
104    U8 rrcReconfigComplete[2] ={0x10, 0x80};
105
106    Buffer *pdu;
107
108    Pst ulPst1 ={100,100,217,0,215,0,PRIOR0,0,81,1,1,0,0};
109 #ifdef PJ
110    Pst ulPst2 ={100,100,217,0,216,0,PRIOR0,0,68,0,1,0,0};
111 #endif
112   TRC2(rlcTmmRcvFrmLi) 
113
114   if(1 == rrcMsgType)
115   {
116
117    KwuDatIndInfo datIndInfoTmp;
118    datIndInfo = &datIndInfoTmp;
119    datIndInfo->rlcId.rbId = 5;
120    datIndInfo->rlcId.rbType = 0;
121    datIndInfo->rlcId.ueId = 0;
122    datIndInfo->rlcId.cellId = 1;
123    datIndInfo->tCrnti = crnti;
124    datIndInfo->isOutOfSeq = 16;
125
126    SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
127   
128    SAddPstMsgMult(rrcConReq,6,pdu);
129
130    RLOG1(L_INFO,"Profiling Framework Sending RRC Connection Req to RRC for UE :%d\n",crnti);
131    printf("Profiling Framework Sending RRC Connection Req to RRC for UE :%d\n",crnti);
132    RlcUiKwuDatInd(&ulPst1, datIndInfo, pdu);
133  }
134  else if(2 == rrcMsgType)
135  {
136 #ifdef PJ
137     CmLtePdcpId pdcpId;
138     pdcpId.cellId = 1;
139     pdcpId.ueId = crnti;
140     pdcpId.rbId = 1;
141     pdcpId.rbType = 0;
142 #endif   
143     SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
144   
145     SAddPstMsgMult(rrcConSetupComplete,34,pdu);
146
147     RLOG1(L_INFO,"Profiling Framework: Sending RRC Connection Setup Complete to RRC for UE :%d\n",crnti);
148     printf("Profiling Framework: Sending RRC Connection Setup Complete to RRC for UE :%d\n",crnti);
149 #ifdef PJ
150     PjUiPjuDatInd(&ulPst2, 1, &pdcpId, pdu);
151 #endif
152  }
153  
154  else if(3 == rrcMsgType)
155  {
156 #ifdef PJ
157     CmLtePdcpId pdcpId;
158     pdcpId.cellId = 1;
159     pdcpId.ueId = crnti;
160     pdcpId.rbId = 1;
161     pdcpId.rbType = 0;
162 #endif   
163     SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
164   
165 #ifndef CA_PAL_5GTF 
166     SAddPstMsgMult(rrcUeCapabilityInfo,12,pdu);
167 #else    
168     SAddPstMsgMult(rrcUeCapabilityInfo,sizeof(rrcUeCapabilityInfo),pdu);
169 #endif
170     RLOG1(L_INFO,"Profiling Framework: Sending RRC UE Capability Info to RRC for UE :%d\n",crnti);
171     printf("Profiling Framework: Sending RRC UE Capability Info to RRC for UE :%d\n",crnti);
172 #ifdef PJ
173     PjUiPjuDatInd(&ulPst2, 1, &pdcpId, pdu);
174 #endif
175
176  }
177  else if(4 == rrcMsgType)
178  {
179 #ifdef PJ
180     CmLtePdcpId pdcpId;
181     pdcpId.cellId = 1;
182     pdcpId.ueId = crnti;
183     pdcpId.rbId = 1;
184     pdcpId.rbType = 0;
185 #endif
186    
187     SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
188   
189     SAddPstMsgMult(rrcSecurityModeComplete,2,pdu);
190
191     RLOG1(L_INFO,"Profiling Framework: Sending RRC Security Mode Complete to RRC for UE :%d\n",crnti);
192     printf("Profiling Framework: Sending RRC Security Mode Complete to RRC for UE :%d\n",crnti);
193 #ifdef PJ
194     PjUiPjuDatInd(&ulPst2, 1, &pdcpId, pdu);
195 #endif
196  }
197  else if(5 == rrcMsgType)
198  {
199 #ifdef PJ
200     CmLtePdcpId pdcpId;
201     pdcpId.cellId = 1;
202     pdcpId.ueId = crnti;
203     pdcpId.rbId = 1;
204     pdcpId.rbType = 0;
205 #endif
206    
207     SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
208   
209     SAddPstMsgMult(rrcReconfigComplete,2,pdu);
210
211     RLOG1(L_INFO,"Profiling Framework: Sending RRC Reconfig Complete to RRC for UE :%d\n",crnti);
212     printf("Profiling Framework: Sending RRC Reconfig Complete to RRC for UE :%d\n",crnti);
213 #ifdef PJ
214     PjUiPjuDatInd(&ulPst2, 1, &pdcpId, pdu);
215 #ifdef EG_GEN_LOAD_5GTF
216     loadStart=1;
217 #endif
218 #endif
219  }
220  RETVOID;
221 }
222 #endif 
223 /** @addtogroup tmmode */
224 /*@{*/
225
226 #define RLC_MODULE (RLC_DBGMASK_TM | RLC_DBGMASK_UL)
227
228 /**
229  * @brief
230  *    Handler to process the Data Indication from the lower layer and send the 
231  *    SDU to upper layer.
232  *
233  * @details
234  *    This function processes the PDU receivied from the lower layer and sends 
235  *    the same pdu as SDU to the upper layer.It sends CRNTI along with the SDU 
236  *    for CCCH.
237  *            
238  * @param[in] gCb     RLC Instance Control Block
239  * @param[in] rbCb    RB control block. 
240  * @param[in] tCrnti  TCRNTI  
241  * @param[in] pdu     PDU
242  * 
243  * @return  S16
244  *    -# ROK 
245  *    -# RFAILED 
246  */
247 #ifdef CCPU_OPT
248 #ifdef ANSI
249 Void rlcTmmRcvFrmLi
250 (
251 RlcCb        *gCb,
252 RlcUlRbCb    *rbCb,  
253 CmLteRnti   tCrnti,  
254 Buffer      *pdu      
255 )
256 #else
257 Void rlcTmmRcvFrmLi(gCb,rbCb, tCrnti, pdu)
258 RlcCb        *gCb;
259 RlcUlRbCb    *rbCb;  
260 CmLteRnti   tCrnti; 
261 Buffer      *pdu;  
262 #endif
263 #else
264 #ifdef ANSI
265 Void rlcTmmRcvFrmLi
266 (
267 RlcCb       *gCb,
268 RlcUlRbCb   *rbCb,         
269 Buffer     *pdu            
270 )
271 #else
272 Void rlcTmmRcvFrmLi(gCb,rbCb, pdu)
273 RlcCb       *gCb;
274 RlcUlRbCb   *rbCb;         
275 Buffer     *pdu;         
276 #endif
277 #endif 
278 {
279    RlcUlRrcMsgInfo  *ulRrcMsgInfo;
280    uint16_t         msgLen;
281    uint16_t         copyLen;    /* Number of bytes copied */
282    Pst              pst;
283  
284    TRC2(rlcTmmRcvFrmLi) 
285
286    gCb->genSts.pdusRecv++;
287    SFndLenMsg(pdu, (MsgLen *)&msgLen);
288    gCb->genSts.bytesRecv += msgLen;
289    /* If trace flag is enabled send the trace indication */
290    if(gCb->init.trc == TRUE)
291    {
292       /* Populate the trace params */
293       rlcLmmSendTrc(gCb, EVENT_UL_RRC_MSG_TRANS_TO_DU, pdu);
294    }
295   
296    /* Filling UL RRC Message Info */
297    RLC_ALLOC_SHRABL_BUF(RLC_MEM_REGION_UL, RLC_POOL,
298       ulRrcMsgInfo, sizeof(RlcUlRrcMsgInfo));
299    if (ulRrcMsgInfo)
300    {
301       ulRrcMsgInfo->cellId = rbCb->rlcId.cellId;
302       ulRrcMsgInfo->ueIdx = rbCb->rlcId.ueId;
303       ulRrcMsgInfo->lcId = rbCb->lch.lChId;
304       RLC_ALLOC_SHRABL_BUF(RLC_MEM_REGION_UL, RLC_POOL,
305          ulRrcMsgInfo->rrcMsg, msgLen);
306       if (ulRrcMsgInfo->rrcMsg)
307       {
308          SCpyMsgFix(pdu, 0, msgLen, ulRrcMsgInfo->rrcMsg, (MsgLen *)&copyLen);
309          ulRrcMsgInfo->msgLen = msgLen;
310
311          /* Sending UL RRC Message transfeer to DU APP */
312          memset(&pst, 0, sizeof(Pst));
313          FILL_PST_RLC_TO_DUAPP(pst, SFndProcId(), RLC_UL_INST, EVENT_UL_RRC_MSG_TRANS_TO_DU);
314          rlcSendUlRrcMsgToDu(&pst, ulRrcMsgInfo);
315       }
316       else
317       {
318          DU_LOG("\nRLC : Memory allocation failed");
319       }
320    }
321    else
322    {
323       DU_LOG("\nRLC : Memory allocation failed");
324    }
325  
326    RETVOID;
327 }
328
329 /**
330  * @brief 
331  *    Handler to process the re-establishment request received from the upper 
332  *    layer. It is just a hook for future enhancement. 
333  *
334  *            
335  * @param[in] gCb   RLC Instance Control Block
336  * @param[in] rbCb  RB control block. 
337  *
338  * @return  S16
339  *    -# ROK 
340  *       
341  **/
342 #ifdef ANSI
343 Void rlcTmmUlReEstablish
344 (
345 RlcCb        *gCb,
346 RlcUlRbCb    *rbCb        
347 )
348 #else
349 Void rlcTmmUlReEstablish(rbCb)
350 RlcCb        *gCb;
351 RlcUlRbCb    *rbCb;          
352 #endif
353 {
354    TRC2(rlcUlTmmReEstablish)
355
356    RLOG_ARG0(L_DEBUG,DBG_RBID,rbCb->rlcId.rbId,"do nothing for TMM for ReEstablish");
357    RETVOID;
358 }
359
360 #ifdef _cplusplus
361 }
362 #endif
363 /*@}*/
364 /********************************************************************30**
365          End of file
366 **********************************************************************/