remove/replaced PRIVATE and EXTERN keywords
[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 uint32_t loadStart;
71 #endif
72
73 S16 PjUiPjuDatInd(Pst* pst,SuId suId,CmLtePdcpId * pdcpId,Buffer *mBuf);
74 #ifdef ANSI
75 Void AddUeContext
76 (
77 CmLteRnti   crnti,
78 uint8_t rrcMsgType
79 )
80 #else
81 Void AddUeContext(crnti,rrcMsgType)
82 CmLteRnti   crnti,
83 uint8_t rrcMsgType 
84 #endif
85 {
86    KwuDatIndInfo   *datIndInfo;   /* Data Indication Information */
87    uint8_t rrcConReq[6] ={ 0x50, 0x30, 0x30, 0x30, 0x30, 0x34 };
88    uint8_t 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    uint8_t rrcUeCapabilityInfo[12] ={0x38, 0x01, 0x00, 0x80, 0x1b, 0xff, 0x0c, 0x00, 0x20, 0x00, 0x80, 0x00};
91 #else
92   /* uint8_t 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 uint8_t 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    uint8_t rrcSecurityModeComplete[2] ={0x28, 0x80};
104    uint8_t 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
113   if(1 == rrcMsgType)
114   {
115
116    KwuDatIndInfo datIndInfoTmp;
117    datIndInfo = &datIndInfoTmp;
118    datIndInfo->rlcId.rbId = 5;
119    datIndInfo->rlcId.rbType = 0;
120    datIndInfo->rlcId.ueId = 0;
121    datIndInfo->rlcId.cellId = 1;
122    datIndInfo->tCrnti = crnti;
123    datIndInfo->isOutOfSeq = 16;
124
125    SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
126   
127    SAddPstMsgMult(rrcConReq,6,pdu);
128
129    RLOG1(L_INFO,"Profiling Framework Sending RRC Connection Req to RRC for UE :%d\n",crnti);
130    printf("Profiling Framework Sending RRC Connection Req to RRC for UE :%d\n",crnti);
131    rlcSendUlDataToDu(&ulPst1, datIndInfo, pdu);
132  }
133  else if(2 == rrcMsgType)
134  {
135 #ifdef PJ
136     CmLtePdcpId pdcpId;
137     pdcpId.cellId = 1;
138     pdcpId.ueId = crnti;
139     pdcpId.rbId = 1;
140     pdcpId.rbType = 0;
141 #endif   
142     SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
143   
144     SAddPstMsgMult(rrcConSetupComplete,34,pdu);
145
146     RLOG1(L_INFO,"Profiling Framework: Sending RRC Connection Setup Complete to RRC for UE :%d\n",crnti);
147     printf("Profiling Framework: Sending RRC Connection Setup Complete to RRC for UE :%d\n",crnti);
148 #ifdef PJ
149     PjUiPjuDatInd(&ulPst2, 1, &pdcpId, pdu);
150 #endif
151  }
152  
153  else if(3 == rrcMsgType)
154  {
155 #ifdef PJ
156     CmLtePdcpId pdcpId;
157     pdcpId.cellId = 1;
158     pdcpId.ueId = crnti;
159     pdcpId.rbId = 1;
160     pdcpId.rbType = 0;
161 #endif   
162     SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
163   
164 #ifndef CA_PAL_5GTF 
165     SAddPstMsgMult(rrcUeCapabilityInfo,12,pdu);
166 #else    
167     SAddPstMsgMult(rrcUeCapabilityInfo,sizeof(rrcUeCapabilityInfo),pdu);
168 #endif
169     RLOG1(L_INFO,"Profiling Framework: Sending RRC UE Capability Info to RRC for UE :%d\n",crnti);
170     printf("Profiling Framework: Sending RRC UE Capability Info to RRC for UE :%d\n",crnti);
171 #ifdef PJ
172     PjUiPjuDatInd(&ulPst2, 1, &pdcpId, pdu);
173 #endif
174
175  }
176  else if(4 == rrcMsgType)
177  {
178 #ifdef PJ
179     CmLtePdcpId pdcpId;
180     pdcpId.cellId = 1;
181     pdcpId.ueId = crnti;
182     pdcpId.rbId = 1;
183     pdcpId.rbType = 0;
184 #endif
185    
186     SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
187   
188     SAddPstMsgMult(rrcSecurityModeComplete,2,pdu);
189
190     RLOG1(L_INFO,"Profiling Framework: Sending RRC Security Mode Complete to RRC for UE :%d\n",crnti);
191     printf("Profiling Framework: Sending RRC Security Mode Complete to RRC for UE :%d\n",crnti);
192 #ifdef PJ
193     PjUiPjuDatInd(&ulPst2, 1, &pdcpId, pdu);
194 #endif
195  }
196  else if(5 == rrcMsgType)
197  {
198 #ifdef PJ
199     CmLtePdcpId pdcpId;
200     pdcpId.cellId = 1;
201     pdcpId.ueId = crnti;
202     pdcpId.rbId = 1;
203     pdcpId.rbType = 0;
204 #endif
205    
206     SGetMsg(DFLT_REGION, DFLT_POOL, (Buffer **) &pdu);
207   
208     SAddPstMsgMult(rrcReconfigComplete,2,pdu);
209
210     RLOG1(L_INFO,"Profiling Framework: Sending RRC Reconfig Complete to RRC for UE :%d\n",crnti);
211     printf("Profiling Framework: Sending RRC Reconfig Complete to RRC for UE :%d\n",crnti);
212 #ifdef PJ
213     PjUiPjuDatInd(&ulPst2, 1, &pdcpId, pdu);
214 #ifdef EG_GEN_LOAD_5GTF
215     loadStart=1;
216 #endif
217 #endif
218  }
219  return;
220 }
221 #endif 
222 /** @addtogroup tmmode */
223 /*@{*/
224
225 #define RLC_MODULE (RLC_DBGMASK_TM | RLC_DBGMASK_UL)
226
227 /**
228  * @brief
229  *    Handler to process the Data Indication from the lower layer and send the 
230  *    SDU to upper layer.
231  *
232  * @details
233  *    This function processes the PDU receivied from the lower layer and sends 
234  *    the same pdu as SDU to the upper layer.It sends CRNTI along with the SDU 
235  *    for CCCH.
236  *            
237  * @param[in] gCb     RLC Instance Control Block
238  * @param[in] rbCb    RB control block. 
239  * @param[in] tCrnti  TCRNTI  
240  * @param[in] pdu     PDU
241  * 
242  * @return  S16
243  *    -# ROK 
244  *    -# RFAILED 
245  */
246 #ifdef CCPU_OPT
247 void rlcTmmRcvFrmMac(RlcCb *gCb, RlcUlRbCb *rbCb, CmLteRnti tCrnti, Buffer *pdu)
248 #else
249 void rlcTmmRcvFrmMac(RlcCb *gCb, RlcUlRbCb *rbCb, Buffer *pdu)
250 #endif
251 {
252    RlcUlRrcMsgInfo  *ulRrcMsgInfo;
253    uint16_t         msgLen;
254    uint16_t         copyLen;    /* Number of bytes copied */
255    Pst              pst;
256  
257    gCb->genSts.pdusRecv++;
258    ODU_GET_MSG_LEN(pdu, (MsgLen *)&msgLen);
259    gCb->genSts.bytesRecv += msgLen;
260   
261    /* Filling UL RRC Message Info */
262    RLC_ALLOC_SHRABL_BUF(RLC_MEM_REGION_UL, RLC_POOL,
263       ulRrcMsgInfo, sizeof(RlcUlRrcMsgInfo));
264    if (ulRrcMsgInfo)
265    {
266       ulRrcMsgInfo->cellId = rbCb->rlcId.cellId;
267       ulRrcMsgInfo->ueIdx = rbCb->rlcId.ueId;
268       ulRrcMsgInfo->lcId = rbCb->lch.lChId;
269       RLC_ALLOC_SHRABL_BUF(RLC_MEM_REGION_UL, RLC_POOL,
270          ulRrcMsgInfo->rrcMsg, msgLen);
271       if (ulRrcMsgInfo->rrcMsg)
272       {
273          ODU_COPY_MSG_TO_FIX_BUF(pdu, 0, msgLen, ulRrcMsgInfo->rrcMsg, (MsgLen *)&copyLen);
274          ulRrcMsgInfo->msgLen = msgLen;
275
276          /* Sending UL RRC Message transfeer to DU APP */
277          memset(&pst, 0, sizeof(Pst));
278          FILL_PST_RLC_TO_DUAPP(pst, RLC_UL_INST, EVENT_UL_RRC_MSG_TRANS_TO_DU);
279          rlcSendUlRrcMsgToDu(&pst, ulRrcMsgInfo);
280       }
281       else
282       {
283          DU_LOG("\nRLC : rlcTmmRcvFrmMac: Memory allocation failed for UL RRC Msg");
284       }
285    }
286    else
287    {
288       DU_LOG("\nRLC : rlcTmmRcvFrmMac: Memory allocation failed for ulRrcMsgInfo");
289    }
290  
291    return;
292 }
293
294 /**
295  * @brief 
296  *    Handler to process the re-establishment request received from the upper 
297  *    layer. It is just a hook for future enhancement. 
298  *
299  *            
300  * @param[in] gCb   RLC Instance Control Block
301  * @param[in] rbCb  RB control block. 
302  *
303  * @return  S16
304  *    -# ROK 
305  *       
306  **/
307 #ifdef ANSI
308 Void rlcTmmUlReEstablish
309 (
310 RlcCb        *gCb,
311 RlcUlRbCb    *rbCb        
312 )
313 #else
314 Void rlcTmmUlReEstablish(rbCb)
315 RlcCb        *gCb;
316 RlcUlRbCb    *rbCb;          
317 #endif
318 {
319
320    RLOG_ARG0(L_DEBUG,DBG_RBID,rbCb->rlcId.rbId,"do nothing for TMM for ReEstablish");
321    return;
322 }
323
324 #ifdef _cplusplus
325 }
326 #endif
327 /*@}*/
328 /********************************************************************30**
329          End of file
330 **********************************************************************/