JIRA ID - ODUHIGH-241 Implementation of RRC DELIVERY REPORT
[o-du/l2.git] / src / 5gnrrlc / rlc_msg_hdl.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 /* header include files (.h) */
20 #include "common_def.h"
21 #include "rgu.h"           /* RGU interface includes*/
22 #include "lkw.h"           /* LKW defines */
23 #include "ckw.h"           /* CKW defines */
24 #include "kwu.h"           /* KWU defines */
25 #include "kw_env.h"        /* RLC environment options */
26 #include "kw.h"            /* RLC defines */
27
28
29 /* header/extern include files (.x) */
30 #include "rgu.x"           
31 #include "lkw.x"           /* LKW */
32 #include "ckw.x"           /* CKW */
33 #include "kwu.x"           /* KWU */
34 #include "kw_err.h"
35 #include "kw.x"
36
37 #include "du_app_rlc_inf.h"
38 #include "rlc_utils.h"
39 #include "rlc_upr_inf_api.h"
40 /*******************************************************************
41  *
42  * @brief Fills RLC UL UE Cfg Rsp from RlcCRsp 
43  *
44  * @details
45  *
46  *    Function : fillRlcUlUeCfgRsp
47  *
48  *    Functionality: 
49  *     Fills RLC UL UE Cfg Rsp from RlcCRsp
50  * 
51  *  @params[in]  Pointer to RlcCfgCfm
52  *               Pointer to RlcUeCfgRsp
53  *
54  *  @return void
55  * 
56  *****************************************************************/
57
58 void fillRlcUlUeCfgRsp(RlcUeCfgRsp *rlcCfgRsp, RlcCfgCfmInfo *rlcCRsp)
59 {
60    uint8_t idx;
61  
62    rlcCfgRsp->cellId = rlcCRsp->cellId;
63    rlcCfgRsp->ueIdx  = rlcCRsp->ueId;
64    for(idx = 0; idx < rlcCRsp->numEnt; idx++)
65    {
66       if(rlcCRsp->entCfgCfm[idx].status.status == CKW_CFG_CFM_OK)
67       {
68          rlcCfgRsp->result = RLC_DU_APP_RSP_OK;
69          rlcCfgRsp->reason = rlcCRsp->entCfgCfm[idx].status.reason;
70       }
71       else
72       {
73          rlcCfgRsp->result = RLC_DU_APP_RSP_NOK;
74          rlcCfgRsp->reason = rlcCRsp->entCfgCfm[idx].status.reason;
75       }
76    }
77 }
78
79 /*******************************************************************
80  *
81  * @brief Fills the entity mode and direction compiling to seed code
82  *
83  * @details
84  *
85  *    Function : fillEntModeAndDir
86  *
87  *    Functionality:
88  *      Fills the entity mode and direction compiling to seed code
89  *
90  * @params[in] Pointer to entMode
91  *             Pointer to direction
92  *             RlcMode Param 
93  * @return void
94  * ****************************************************************/
95
96 void fillEntModeAndDir(uint8_t *entMode, uint8_t *direction, RlcMode rlcMode)
97 {
98    switch(rlcMode)
99    {
100       case RLC_AM:
101          *entMode   = CM_LTE_MODE_AM;
102          *direction = RLC_CFG_DIR_BOTH;
103          break;
104       case RLC_UM_BI_DIRECTIONAL:
105          *entMode = CM_LTE_MODE_UM;
106          *direction = RLC_CFG_DIR_BOTH;
107          break;
108       case RLC_UM_UNI_DIRECTIONAL_UL:
109          *entMode = CM_LTE_MODE_UM;
110          *direction = RLC_CFG_DIR_UL;
111          break;
112       case RLC_UM_UNI_DIRECTIONAL_DL:
113          *entMode = CM_LTE_MODE_UM;
114          *direction = RLC_CFG_DIR_DL;
115          break;
116       default : 
117          DU_LOG("\nRLC: Rlc Mode invalid %d", rlcMode);
118     break;
119    }
120 }
121 /*******************************************************************
122  *
123  * @brief Handles Ue Create Request from DU APP
124  *
125  * @details
126  *
127  *    Function : RlcUlProcUeCreateReq
128  *
129  *    Functionality:
130  *      Handles Ue create Request from DU APP
131  *
132  * @params[in] Post structure pointer
133  *             RlcUeCfg pointer 
134  * @return ROK     - success
135  *         RFAILED - failure
136  *
137  * ****************************************************************/
138 uint8_t RlcUlProcUeCreateReq(Pst *pst, RlcUeCfg *ueCfg)
139 {
140    uint8_t idx;
141    uint8_t ret = ROK;
142    uint8_t lChRbIdx;
143    RlcCfgInfo *rlcUeCfg = NULLP;
144
145    RlcCb *rlcUeCb = NULLP;
146    rlcUeCb = RLC_GET_RLCCB(pst->dstInst);
147    RLC_ALLOC(rlcUeCb, rlcUeCfg, sizeof(RlcCfgInfo));
148    if(rlcUeCfg)
149    {
150       memset(rlcUeCfg, 0, sizeof(RlcCfgInfo));
151
152       rlcUeCfg->ueId    = ueCfg->ueIdx;
153       rlcUeCfg->cellId  = ueCfg->cellId;
154       rlcUeCfg->numEnt  = ueCfg->numLcs;
155       rlcUeCfg->transId = getTransId();
156  
157       for(idx = 0; idx < ueCfg->numLcs; idx++)
158       {
159          lChRbIdx = 0;
160          rlcUeCfg->entCfg[idx].rbId           = ueCfg->rlcBearerCfg[idx].rbId;
161          rlcUeCfg->entCfg[idx].rbType         = ueCfg->rlcBearerCfg[idx].rbType;   // SRB or DRB
162          rlcUeCfg->entCfg[idx].lCh[lChRbIdx].lChId   = ueCfg->rlcBearerCfg[idx].lcId;   
163          rlcUeCfg->entCfg[idx].lCh[lChRbIdx].type    = ueCfg->rlcBearerCfg[idx].lcType;
164          fillEntModeAndDir(&rlcUeCfg->entCfg[idx].entMode, &rlcUeCfg->entCfg[idx].dir,\
165             ueCfg->rlcBearerCfg[idx].rlcMode);
166          rlcUeCfg->entCfg[idx].cfgType        = CKW_CFG_ADD;
167          switch(rlcUeCfg->entCfg[idx].entMode)
168          {
169
170             case CM_LTE_MODE_AM:
171             {
172                /* DL AM INFO */
173                rlcUeCfg->entCfg[idx].m.amInfo.dl.snLen = ueCfg->rlcBearerCfg[idx].u.amCfg.dlAmCfg.snLenDl; 
174                rlcUeCfg->entCfg[idx].m.amInfo.dl.pollRetxTmr = ueCfg->rlcBearerCfg[idx].u.amCfg.dlAmCfg.pollRetxTmr;
175                rlcUeCfg->entCfg[idx].m.amInfo.dl.pollPdu = ueCfg->rlcBearerCfg[idx].u.amCfg.dlAmCfg.pollPdu; 
176                rlcUeCfg->entCfg[idx].m.amInfo.dl.pollByte = ueCfg->rlcBearerCfg[idx].u.amCfg.dlAmCfg.pollByte; 
177                rlcUeCfg->entCfg[idx].m.amInfo.dl.maxRetx = ueCfg->rlcBearerCfg[idx].u.amCfg.dlAmCfg.maxRetxTh;
178
179                /* UL AM INFO */
180                lChRbIdx++;   //lChRbIdx = 1, indicates UL AM
181                rlcUeCfg->entCfg[idx].lCh[lChRbIdx].lChId   = ueCfg->rlcBearerCfg[idx].lcId;   
182                rlcUeCfg->entCfg[idx].lCh[lChRbIdx].type    = ueCfg->rlcBearerCfg[idx].lcType;
183                rlcUeCfg->entCfg[idx].m.amInfo.ul.snLen = ueCfg->rlcBearerCfg[idx].u.amCfg.ulAmCfg.snLenUl; 
184                rlcUeCfg->entCfg[idx].m.amInfo.ul.staProhTmr = ueCfg->rlcBearerCfg[idx].u.amCfg.ulAmCfg.statProhTmr;
185                rlcUeCfg->entCfg[idx].m.amInfo.ul.reOrdTmr = ueCfg->rlcBearerCfg[idx].u.amCfg.ulAmCfg.reAssemTmr;
186                break;
187             }
188             case CM_LTE_MODE_UM:
189             {
190                /* UL UM CONFIG */
191                rlcUeCfg->entCfg[idx].m.umInfo.ul.snLen = ueCfg->rlcBearerCfg[idx].u.umBiDirCfg.ulUmCfg.snLenUlUm; 
192                rlcUeCfg->entCfg[idx].m.umInfo.ul.reOrdTmr = ueCfg->rlcBearerCfg[idx].u.umBiDirCfg.ulUmCfg.reAssemTmr;
193
194                /* DL UM CONFIG */
195                rlcUeCfg->entCfg[idx].m.umInfo.dl.snLen = ueCfg->rlcBearerCfg[idx].u.umBiDirCfg.dlUmCfg.snLenDlUm; 
196                break;
197             }
198             default:
199                break;
200          }/* End of switch(entMode) */
201       }
202       ret = RlcProcCfgReq(pst, rlcUeCfg);
203       }
204       else
205       {
206          DU_LOG("\nRLC: Failed to allocate memory ");
207          ret = RFAILED;
208       }
209       RLC_FREE_SHRABL_BUF(pst->region, pst->pool, ueCfg, sizeof(RlcUeCfg));
210       return ret;
211 }
212 /*******************************************************************
213 *
214 * @brief filling the structure of rrc delivery msg info
215 *
216 * @details
217 *
218 *    Function : BuildAndSendRrcDeliveryReportToDu
219 *
220 *    Functionality: filling the structure of rrc delivery msg info
221 *
222 * @return ROK     - success
223 *         RFAILED - failure
224 *
225 * ****************************************************************/
226 uint8_t BuildAndSendRrcDeliveryReportToDu( RlcDlRrcMsgInfo *dlRrcMsgInfo )
227 {
228     Pst             pst;
229     RrcDeliveryReport *rrcDelivery;
230     
231     DU_LOG("\nRLC : Filling the RRC Delivery Report");
232     RLC_ALLOC_SHRABL_BUF(RLC_MEM_REGION_UL, RLC_POOL, rrcDelivery, sizeof(RrcDeliveryReport));
233
234     if(rrcDelivery)
235     {
236        rrcDelivery->cellId = dlRrcMsgInfo->cellId;
237        rrcDelivery->ueIdx  = dlRrcMsgInfo->ueIdx;
238        rrcDelivery->srbId  = dlRrcMsgInfo->lcId ;
239        rrcDelivery->rrcDeliveryStatus.deliveryStatus    = PDCP_SN;
240        rrcDelivery->rrcDeliveryStatus.triggeringMessage = PDCP_SN;
241
242        /* Sending UL RRC Message transfeer to DU APP */
243        memset(&pst, 0, sizeof(Pst));
244        FILL_PST_RLC_TO_DUAPP(pst, SFndProcId(), RLC_UL_INST, EVENT_RRC_DELIVERY_MSG_TRANS_TO_DU);
245        rlcSendRrcDeliveryReportToDu(&pst, rrcDelivery);
246     }
247     else
248     {
249        DU_LOG("\nRLC : Memory allocation failed");
250     }
251
252    return ROK;
253 }
254 /* ****************************************************************
255  *
256  * @brief Process the DL RRC Message from DU APP
257  *
258  * @details
259  *
260  *    Function : RlcProcDlRrcMsgTransfer
261  *
262  *    Functionality: Process the DL RRC Message from DU APP
263  *
264  * @params[in] Post structure
265  *             DL RRC Message info
266  * @return ROK     - success
267  *         RFAILED - failure
268  *
269  * ****************************************************************/
270 uint8_t RlcProcDlRrcMsgTransfer(Pst *pst, RlcDlRrcMsgInfo *dlRrcMsgInfo)
271 {
272    uint16_t      copyLen;
273    Buffer        *mBuf;
274    KwuDatReqInfo *datReqInfo;
275
276    RLC_SHRABL_STATIC_BUF_ALLOC(RLC_MEM_REGION_DL, RLC_POOL, datReqInfo, sizeof(KwuDatReqInfo));
277    if(!datReqInfo)
278    {
279       DU_LOG("\nRLC : Memory allocation failed in RlcProcDlRrcMsgTransfer");
280       return RFAILED;
281    }
282
283    datReqInfo->rlcId.rbType = dlRrcMsgInfo->rbType;
284    datReqInfo->rlcId.rbId = dlRrcMsgInfo->rbId;
285    datReqInfo->rlcId.ueId = dlRrcMsgInfo->ueIdx;
286    datReqInfo->rlcId.cellId = dlRrcMsgInfo->cellId;
287    datReqInfo->lcType = dlRrcMsgInfo->lcType;
288    datReqInfo->sduId = ++(rlcCb[pst->dstInst]->dlSduId);
289
290    /* Copy fixed buffer to message */
291    if(ODU_GET_MSG_BUF(RLC_MEM_REGION_UL, RLC_POOL, &mBuf) != ROK)
292    {
293       DU_LOG("\nRLC : Memory allocation failed at RlcMacProcUlData");
294       RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_DL, RLC_POOL, datReqInfo, sizeof(KwuDatReqInfo));
295       return RFAILED;
296    }
297    /* ODU_COPY_FIX_BUF_TO_MSG copies fixed buffer in reverse order. Hence reversing the
298     * fixed buffer before copying in order to maintain the actual order*/
299    reverseFixBuf(dlRrcMsgInfo->rrcMsg, dlRrcMsgInfo->msgLen);
300    ODU_COPY_FIX_BUF_TO_MSG(dlRrcMsgInfo->rrcMsg, mBuf, 0, dlRrcMsgInfo->msgLen, \
301          (MsgLen *)&copyLen);
302
303    RlcUiKwuDatReq(pst, datReqInfo, mBuf);
304    
305    /* RRC Delivery report is only send when RRC Delivery status report is true in DL RRC Message */
306    if(dlRrcMsgInfo->deliveryStaRpt)
307    {
308       BuildAndSendRrcDeliveryReportToDu(dlRrcMsgInfo);
309    }
310
311    /* Free memory allocated by du app */
312    RLC_SHRABL_STATIC_BUF_FREE(RLC_MEM_REGION_DL, RLC_POOL, datReqInfo, sizeof(KwuDatReqInfo));
313    RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, dlRrcMsgInfo->rrcMsg, dlRrcMsgInfo->msgLen);
314    RLC_SHRABL_STATIC_BUF_FREE(pst->region, pst->pool, dlRrcMsgInfo, sizeof(RlcDlRrcMsgInfo));
315    return ROK;
316 }
317 /**********************************************************************
318          End of file
319 **********************************************************************/