Moving all common header file into common_def.h file
[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 "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
65 #if defined(PRE_DEF_UE_CTX) || defined(PRE_DEF_UE_CTX_HO)
66 #ifdef EG_GEN_LOAD_5GTF
67 extern U32 loadStart;
68 #endif
69
70 EXTERN S16 PjUiPjuDatInd(Pst* pst,SuId suId,CmLtePdcpId * pdcpId,Buffer *mBuf);
71 #ifdef ANSI
72 PUBLIC Void AddUeContext
73 (
74 CmLteRnti   crnti,
75 U8 rrcMsgType
76 )
77 #else
78 PUBLIC Void AddUeContext(crnti,rrcMsgType)
79 CmLteRnti   crnti,
80 U8 rrcMsgType 
81 #endif
82 {
83    KwuDatIndInfo   *datIndInfo;   /* Data Indication Information */
84    U8 rrcConReq[6] ={ 0x50, 0x30, 0x30, 0x30, 0x30, 0x34 };
85    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};
86 #ifndef CA_PAL_5GTF 
87    U8 rrcUeCapabilityInfo[12] ={0x38, 0x01, 0x00, 0x80, 0x1b, 0xff, 0x0c, 0x00, 0x20, 0x00, 0x80, 0x00};
88 #else
89   /* 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};
90 */
91 U8 rrcUeCapabilityInfo[] = 
92 {
93  0x38,0x01,0x03,0x34,0x9b,0xff,0x0c,0x00,0x20,0x00,0x80,0x1f,0xfe,0xf4,0x4f,0xe0
94  ,0x40,0x09,0x80,0x11,0x04,0x0c,0x20,0x88,0x20,0x63,0x04,0x41,0x03,0x20,0x22,0x08
95  ,0x19,0x61,0x10,0x40,0xff,0xff,0xff,0xff,0xe7,0xff,0x03,0xff,0xff,0xff,0xfe,0xff
96  ,0xe0,0x7f,0xff,0xff,0xff,0xc0,0x00
97 };
98
99 #endif
100    U8 rrcSecurityModeComplete[2] ={0x28, 0x80};
101    U8 rrcReconfigComplete[2] ={0x10, 0x80};
102
103    Buffer *pdu;
104
105    Pst ulPst1 ={100,100,217,0,215,0,PRIOR0,0,81,1,1,0,0};
106 #ifdef PJ
107    Pst ulPst2 ={100,100,217,0,216,0,PRIOR0,0,68,0,1,0,0};
108 #endif
109   TRC2(kwTmmRcvFrmLi) 
110
111   if(1 == rrcMsgType)
112   {
113
114    KwuDatIndInfo datIndInfoTmp;
115    datIndInfo = &datIndInfoTmp;
116    datIndInfo->rlcId.rbId = 5;
117    datIndInfo->rlcId.rbType = 0;
118    datIndInfo->rlcId.ueId = 0;
119    datIndInfo->rlcId.cellId = 1;
120    datIndInfo->tCrnti = crnti;
121    datIndInfo->isOutOfSeq = 16;
122
123    SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
124   
125    SAddPstMsgMult(rrcConReq,6,pdu);
126
127    RLOG1(L_INFO,"Profiling Framework Sending RRC Connection Req to RRC for UE :%d\n",crnti);
128    printf("Profiling Framework Sending RRC Connection Req to RRC for UE :%d\n",crnti);
129    KwUiKwuDatInd(&ulPst1, datIndInfo, pdu);
130  }
131  else if(2 == rrcMsgType)
132  {
133 #ifdef PJ
134     CmLtePdcpId pdcpId;
135     pdcpId.cellId = 1;
136     pdcpId.ueId = crnti;
137     pdcpId.rbId = 1;
138     pdcpId.rbType = 0;
139 #endif   
140     SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
141   
142     SAddPstMsgMult(rrcConSetupComplete,34,pdu);
143
144     RLOG1(L_INFO,"Profiling Framework: Sending RRC Connection Setup Complete to RRC for UE :%d\n",crnti);
145     printf("Profiling Framework: Sending RRC Connection Setup Complete to RRC for UE :%d\n",crnti);
146 #ifdef PJ
147     PjUiPjuDatInd(&ulPst2, 1, &pdcpId, pdu);
148 #endif
149  }
150  
151  else if(3 == rrcMsgType)
152  {
153 #ifdef PJ
154     CmLtePdcpId pdcpId;
155     pdcpId.cellId = 1;
156     pdcpId.ueId = crnti;
157     pdcpId.rbId = 1;
158     pdcpId.rbType = 0;
159 #endif   
160     SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
161   
162 #ifndef CA_PAL_5GTF 
163     SAddPstMsgMult(rrcUeCapabilityInfo,12,pdu);
164 #else    
165     SAddPstMsgMult(rrcUeCapabilityInfo,sizeof(rrcUeCapabilityInfo),pdu);
166 #endif
167     RLOG1(L_INFO,"Profiling Framework: Sending RRC UE Capability Info to RRC for UE :%d\n",crnti);
168     printf("Profiling Framework: Sending RRC UE Capability Info to RRC for UE :%d\n",crnti);
169 #ifdef PJ
170     PjUiPjuDatInd(&ulPst2, 1, &pdcpId, pdu);
171 #endif
172
173  }
174  else if(4 == rrcMsgType)
175  {
176 #ifdef PJ
177     CmLtePdcpId pdcpId;
178     pdcpId.cellId = 1;
179     pdcpId.ueId = crnti;
180     pdcpId.rbId = 1;
181     pdcpId.rbType = 0;
182 #endif
183    
184     SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
185   
186     SAddPstMsgMult(rrcSecurityModeComplete,2,pdu);
187
188     RLOG1(L_INFO,"Profiling Framework: Sending RRC Security Mode Complete to RRC for UE :%d\n",crnti);
189     printf("Profiling Framework: Sending RRC Security Mode Complete to RRC for UE :%d\n",crnti);
190 #ifdef PJ
191     PjUiPjuDatInd(&ulPst2, 1, &pdcpId, pdu);
192 #endif
193  }
194  else if(5 == rrcMsgType)
195  {
196 #ifdef PJ
197     CmLtePdcpId pdcpId;
198     pdcpId.cellId = 1;
199     pdcpId.ueId = crnti;
200     pdcpId.rbId = 1;
201     pdcpId.rbType = 0;
202 #endif
203    
204     SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
205   
206     SAddPstMsgMult(rrcReconfigComplete,2,pdu);
207
208     RLOG1(L_INFO,"Profiling Framework: Sending RRC Reconfig Complete to RRC for UE :%d\n",crnti);
209     printf("Profiling Framework: Sending RRC Reconfig Complete to RRC for UE :%d\n",crnti);
210 #ifdef PJ
211     PjUiPjuDatInd(&ulPst2, 1, &pdcpId, pdu);
212 #ifdef EG_GEN_LOAD_5GTF
213     loadStart=1;
214 #endif
215 #endif
216  }
217  RETVOID;
218 }
219 #endif 
220 /** @addtogroup tmmode */
221 /*@{*/
222
223 #define KW_MODULE (KW_DBGMASK_TM | KW_DBGMASK_UL)
224
225 /**
226  * @brief
227  *    Handler to process the Data Indication from the lower layer and send the 
228  *    SDU to upper layer.
229  *
230  * @details
231  *    This function processes the PDU receivied from the lower layer and sends 
232  *    the same pdu as SDU to the upper layer.It sends CRNTI along with the SDU 
233  *    for CCCH.
234  *            
235  * @param[in] gCb     RLC Instance Control Block
236  * @param[in] rbCb    RB control block. 
237  * @param[in] tCrnti  TCRNTI  
238  * @param[in] pdu     PDU
239  * 
240  * @return  S16
241  *    -# ROK 
242  *    -# RFAILED 
243  */
244 #ifdef CCPU_OPT
245 #ifdef ANSI
246 PUBLIC Void kwTmmRcvFrmLi
247 (
248 KwCb        *gCb,
249 KwUlRbCb    *rbCb,  
250 CmLteRnti   tCrnti,  
251 Buffer      *pdu      
252 )
253 #else
254 PUBLIC Void kwTmmRcvFrmLi(gCb,rbCb, tCrnti, pdu)
255 KwCb        *gCb;
256 KwUlRbCb    *rbCb;  
257 CmLteRnti   tCrnti; 
258 Buffer      *pdu;  
259 #endif
260 #else
261 #ifdef ANSI
262 PUBLIC Void kwTmmRcvFrmLi
263 (
264 KwCb       *gCb,
265 KwUlRbCb   *rbCb,         
266 Buffer     *pdu            
267 )
268 #else
269 PUBLIC Void kwTmmRcvFrmLi(gCb,rbCb, pdu)
270 KwCb       *gCb;
271 KwUlRbCb   *rbCb;         
272 Buffer     *pdu;         
273 #endif
274 #endif 
275 {
276    KwuDatIndInfo   *datIndInfo;   /* Data Indication Information */
277    MsgLen          msgLen;
278  
279    TRC2(kwTmmRcvFrmLi) 
280
281    /* Creating static memory for KwuDatIndInfo. #else will be 
282     * removed once the sanity testing is performed for all platforms */
283    KwuDatIndInfo datIndInfoTmp;
284    datIndInfo = &datIndInfoTmp;
285 #if (ERRCLASS & ERRCLS_ADD_RES)
286    if ( datIndInfo == NULLP )
287    {   
288       RLOG_ARG2(L_FATAL,DBG_RBID,rbCb->rlcId.rbId,
289             "Memory Allocation failed UEID:%d CELLID:%d",
290             rbCb->rlcId.ueId,
291             rbCb->rlcId.cellId);   
292       RETVOID;
293    }
294 #endif /* ERRCLASS & ERRCLS_ADD_RES */
295    KW_MEM_CPY(&(datIndInfo->rlcId),&(rbCb->rlcId),sizeof(CmLteRlcId));
296 #ifdef CCPU_OPT 
297    if ( rbCb->lch.lChType == CM_LTE_LCH_CCCH ) 
298    {
299       datIndInfo->tCrnti = tCrnti;
300    }
301 #endif 
302    gCb->genSts.pdusRecv++;
303    SFndLenMsg(pdu, &msgLen);
304    gCb->genSts.bytesRecv += msgLen;
305    /* If trace flag is enabled send the trace indication */
306    if(gCb->init.trc == TRUE)
307    {
308       /* Populate the trace params */
309       kwLmmSendTrc(gCb,KWU_EVT_DAT_IND, pdu);
310    }
311    KwUiKwuDatInd( &gCb->u.ulCb->kwuUlSap->pst, 
312                   //gCb->u.ulCb->kwuUlSap->suId, 
313                   datIndInfo, pdu);
314    
315    RETVOID;
316 }
317
318 /**
319  * @brief 
320  *    Handler to process the re-establishment request received from the upper 
321  *    layer. It is just a hook for future enhancement. 
322  *
323  *            
324  * @param[in] gCb   RLC Instance Control Block
325  * @param[in] rbCb  RB control block. 
326  *
327  * @return  S16
328  *    -# ROK 
329  *       
330  **/
331 #ifdef ANSI
332 PUBLIC Void kwTmmUlReEstablish
333 (
334 KwCb        *gCb,
335 KwUlRbCb    *rbCb        
336 )
337 #else
338 PUBLIC Void kwTmmUlReEstablish(rbCb)
339 KwCb        *gCb;
340 KwRbCb      *rbCb;          
341 #endif
342 {
343    TRC2(kwUlTmmReEstablish)
344
345    RLOG_ARG0(L_DEBUG,DBG_RBID,rbCb->rlcId.rbId,"do nothing for TMM for ReEstablish");
346    RETVOID;
347 }
348
349 #ifdef _cplusplus
350 }
351 #endif
352 /*@}*/
353 /********************************************************************30**
354          End of file
355 **********************************************************************/