RLC BO, BO response and DL Data handling. [Issue-ID: ODUHIGH-181]
[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                   --rlcTmmSendToMac
30                   --rlcTmmRcvFrmMac
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(rlcTmmRcvFrmMac) 
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    rlcSendUlDataToDu(&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 void rlcTmmRcvFrmMac(RlcCb *gCb, RlcUlRbCb *rbCb, CmLteRnti tCrnti, Buffer *pdu)
249 #else
250 void rlcTmmRcvFrmMac(RlcCb *gCb, RlcUlRbCb *rbCb, Buffer *pdu)
251 #endif
252 {
253    RlcUlRrcMsgInfo  *ulRrcMsgInfo;
254    uint16_t         msgLen;
255    uint16_t         copyLen;    /* Number of bytes copied */
256    Pst              pst;
257  
258    gCb->genSts.pdusRecv++;
259    ODU_GET_MSG_LEN(pdu, (MsgLen *)&msgLen);
260    gCb->genSts.bytesRecv += msgLen;
261   
262    /* Filling UL RRC Message Info */
263    RLC_ALLOC_SHRABL_BUF(RLC_MEM_REGION_UL, RLC_POOL,
264       ulRrcMsgInfo, sizeof(RlcUlRrcMsgInfo));
265    if (ulRrcMsgInfo)
266    {
267       ulRrcMsgInfo->cellId = rbCb->rlcId.cellId;
268       ulRrcMsgInfo->ueIdx = rbCb->rlcId.ueId;
269       ulRrcMsgInfo->lcId = rbCb->lch.lChId;
270       RLC_ALLOC_SHRABL_BUF(RLC_MEM_REGION_UL, RLC_POOL,
271          ulRrcMsgInfo->rrcMsg, msgLen);
272       if (ulRrcMsgInfo->rrcMsg)
273       {
274          ODU_COPY_MSG_TO_FIX_BUF(pdu, 0, msgLen, ulRrcMsgInfo->rrcMsg, (MsgLen *)&copyLen);
275          ulRrcMsgInfo->msgLen = msgLen;
276
277          /* Sending UL RRC Message transfeer to DU APP */
278          memset(&pst, 0, sizeof(Pst));
279          FILL_PST_RLC_TO_DUAPP(pst, RLC_UL_INST, EVENT_UL_RRC_MSG_TRANS_TO_DU);
280          rlcSendUlRrcMsgToDu(&pst, ulRrcMsgInfo);
281       }
282       else
283       {
284          DU_LOG("\nRLC : rlcTmmRcvFrmMac: Memory allocation failed for UL RRC Msg");
285       }
286    }
287    else
288    {
289       DU_LOG("\nRLC : rlcTmmRcvFrmMac: Memory allocation failed for ulRrcMsgInfo");
290    }
291  
292    return;
293 }
294
295 /**
296  * @brief 
297  *    Handler to process the re-establishment request received from the upper 
298  *    layer. It is just a hook for future enhancement. 
299  *
300  *            
301  * @param[in] gCb   RLC Instance Control Block
302  * @param[in] rbCb  RB control block. 
303  *
304  * @return  S16
305  *    -# ROK 
306  *       
307  **/
308 #ifdef ANSI
309 Void rlcTmmUlReEstablish
310 (
311 RlcCb        *gCb,
312 RlcUlRbCb    *rbCb        
313 )
314 #else
315 Void rlcTmmUlReEstablish(rbCb)
316 RlcCb        *gCb;
317 RlcUlRbCb    *rbCb;          
318 #endif
319 {
320    TRC2(rlcUlTmmReEstablish)
321
322    RLOG_ARG0(L_DEBUG,DBG_RBID,rbCb->rlcId.rbId,"do nothing for TMM for ReEstablish");
323    RETVOID;
324 }
325
326 #ifdef _cplusplus
327 }
328 #endif
329 /*@}*/
330 /********************************************************************30**
331          End of file
332 **********************************************************************/