[Epic-ID: ODUHIGH-406][Task-ID: ODUHIGH-423] UE context setup request from CU to...
[o-du/l2.git] / src / du_app / du_cell_mgr.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 /* This file contains message handling functionality for DU cell management */
20 #include "common_def.h"
21 #include "lrg.h"
22 #include "legtp.h"
23 #include "lrg.x"
24 #include "lkw.x"
25 #include "rgr.h"
26 #include "rgr.x"
27 #include "du_app_mac_inf.h"
28 #include "du_app_rlc_inf.h"
29 #include "du_cfg.h"
30 #include "du_mgr.h"
31 #include "du_utils.h"
32 #include "du_cell_mgr.h"
33
34 #ifdef O1_ENABLE
35
36 #include "AlarmInterface.h"
37 #include "CmInterface.h"
38
39 #endif
40
41 DuMacCellDeleteReq packMacCellDeleteReqOpts[] =
42 {
43    packDuMacCellDeleteReq,       /* Loose coupling */
44    MacProcCellDeleteReq,         /* TIght coupling */
45    packDuMacCellDeleteReq        /* Light weight-loose coupling */
46 };
47
48 /*******************************************************************
49  *
50  * @brief Processes cells to be activated
51  *
52  * @details
53  *
54  *    Function : duProcCellsToBeActivated
55  *
56  *    Functionality:
57  *      - Processes cells to be activated list received in F1SetupRsp
58  *
59  * @params[in] void
60  * @return ROK     - success
61  *         RFAILED - failure
62  *
63  * ****************************************************************/
64 uint8_t duProcCellsToBeActivated(uint8_t *plmnStr, uint16_t nci, uint16_t nRPci)
65 {
66    uint8_t ret = ROK;
67    DuCellCb *cellCb = NULLP;
68    uint8_t cfgIdx, tmpPlmn[4];
69
70    for(cfgIdx=0; cfgIdx<duCb.numCfgCells; cfgIdx++)
71    {
72       memset(tmpPlmn, 0, 4);
73       buildPlmnId(duCb.cfgCellLst[cfgIdx]->cellInfo.nrEcgi.plmn, tmpPlmn);
74       if(duCb.cfgCellLst[cfgIdx]->cellInfo.nrEcgi.cellId == nci &&
75             (strcmp((const char*)tmpPlmn, (const char*)plmnStr) == 0))
76       {
77          cellCb = duCb.cfgCellLst[cfgIdx];
78          break;
79       }
80       else
81       {
82          DU_LOG("\nERROR  -->  DU APP : No Cell found for NCI %d", nci);
83          return RFAILED;
84       }
85    }
86
87    cellCb->cellStatus = ACTIVATION_IN_PROGRESS; 
88    cellCb->cellInfo.nrPci = nRPci;
89
90    duCb.actvCellLst[cellCb->cellId -1] = cellCb;
91    duCb.numActvCells++;
92
93    if(duBuildAndSendMacCellCfg(cellCb->cellId) != ROK)
94    {
95       DU_LOG("\nERROR  -->  DU APP : macCellCfg build and send failed");
96       /* Delete cell from actvCellList */
97       duCb.actvCellLst[cellCb->cellId -1] = NULLP;
98       --(duCb.numActvCells);
99       ret = RFAILED;
100    }
101    return ret;
102 }
103
104 /*******************************************************************
105  *
106  * @brief Handles DU F1Setup Rsp received in F1AP
107  *
108  * @details
109  *
110  *    Function : duProcF1SetupRsp
111  *
112  *    Functionality:
113  *      - Handles DU F1Setup Rsp received in F1AP
114  *
115  * @params[in] Pointer to F1SetupRsp 
116  * @return void
117  *
118  ******************************************************************/
119 void duProcF1SetupRsp()
120 {
121    DU_LOG("\nINFO   -->  DU_APP : F1 Setup Response received");
122    duCb.f1Status = TRUE; //Set F1 status as true
123 }
124
125 /*******************************************************************
126 *
127 * @brief Returns cellCb based on cell ID
128 *
129 * @details
130 *
131 *    Function : duGetCellCb
132 *
133 *    Functionality: Returns DU APP CellCb based on cell ID
134 *
135 * @params[in] F1AP_PDU_t ASN decoded F1AP message
136 * @return ROK     - success
137 *         RFAILED - failure
138 *
139 * ****************************************************************/
140 uint8_t duGetCellCb(uint16_t cellId, DuCellCb **cellCb)
141 {
142    uint8_t cellIdx = 0;
143
144    for(cellIdx=0; cellIdx < MAX_NUM_CELL; cellIdx++)
145    {
146       if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->cellId == cellId))
147       {
148          *cellCb = duCb.actvCellLst[cellIdx];
149               break;
150       }
151    }
152
153    if(!*cellCb)
154    {
155       DU_LOG("\nERROR  -->  DU APP : Cell Id %d not found in DU APP", cellId);
156       return RFAILED;
157    }
158
159    return ROK;
160 }
161
162 /*****************************************************************
163 * @brief Handles slot indication from MAC
164 *
165 * @details
166 *
167 *   Function : duHandleSlotInd
168 *
169 *   Functionality:
170 *       Handles  slot indication from MAC
171
172 *  @params[in] Post structure pointer
173 *              SlotTimingInfo *slotIndInfo
174 *  @return ROK     - success
175 *          RFAILED - failure
176
177
178 *****************************************************************/
179 uint8_t duHandleSlotInd(Pst *pst, SlotTimingInfo *slotIndInfo)
180 {
181    uint8_t cellIdx = 0, ret = ROK;
182    DuCellCb *duCellCb;
183
184    if(slotIndInfo)
185    {
186       GET_CELL_IDX(slotIndInfo->cellId, cellIdx);
187       duCellCb = duCb.actvCellLst[cellIdx];
188
189       if(duCellCb)
190       {
191          duCellCb->currSlotInfo.sfn = slotIndInfo->sfn;
192          duCellCb->currSlotInfo.slot = slotIndInfo->slot;
193       }
194       else
195       {
196          DU_LOG("\nERROR  -->  DU APP : CellId[%d] doesnot exist", slotIndInfo->cellId);
197          ret = RFAILED;
198       }
199       DU_FREE_SHRABL_BUF(pst->region, pst->pool, slotIndInfo, sizeof(SlotTimingInfo));
200    }
201    else
202    {
203       DU_LOG("\nERROR  -->  DU APP : Recevied null pointer from MAC");
204       ret = RFAILED;
205    }
206    return(ret);
207 }
208 /*******************************************************************
209  *
210  * @brief Handles cell up indication from MAC
211  *
212  * @details
213  *
214  *    Function : duHandleCellUpInd
215  *
216  *    Functionality:
217  *      Handles cell up indication from MAC
218  *
219  * @params[in] Post structure pointer
220  *             cell Up info
221  * @return ROK     - success
222  *         RFAILED - failure
223  *
224  * ****************************************************************/
225 uint8_t duHandleCellUpInd(Pst *pst, OduCellId *cellId)
226 {
227    DuCellCb *cellCb = NULLP; 
228
229 #ifndef O1_ENABLE
230
231    /*Note: Static Configuration, when O1 is not configuring the RRM policy*/
232    RrmPolicy *rrmPolicy;
233    DU_ALLOC(rrmPolicy, sizeof(RrmPolicy));
234    rrmPolicy->rsrcType = RSRC_PRB;
235    rrmPolicy->numMemberList = 1;
236    DU_ALLOC(rrmPolicy->memberList, sizeof(PolicyMemberList *));
237    DU_ALLOC(rrmPolicy->memberList[0], sizeof(PolicyMemberList));
238    
239    memset(&rrmPolicy->memberList[0]->plmn, 0, sizeof(Plmn)); 
240    rrmPolicy->memberList[0]->snssai.sst = 1;
241    rrmPolicy->memberList[0]->snssai.sd[0] = 2;
242    rrmPolicy->memberList[0]->snssai.sd[1] = 3;
243    rrmPolicy->memberList[0]->snssai.sd[2] = 4;
244    rrmPolicy->policyMinRatio = 30;
245    rrmPolicy->policyMaxRatio = 90;
246    rrmPolicy->policyDedicatedRatio = 10;
247 #endif
248
249    if(cellId->cellId <=0 || cellId->cellId > MAX_NUM_CELL)
250    {
251       DU_LOG("\nERROR  -->  DU APP : Invalid Cell Id %d in duHandleCellUpInd()", cellId->cellId);
252       return RFAILED;
253    }
254
255    if(duGetCellCb(cellId->cellId, &cellCb) != ROK)
256       return RFAILED;
257
258    if((cellCb != NULL) && (cellCb->cellStatus == ACTIVATION_IN_PROGRESS))
259    {
260       DU_LOG("\nINFO   -->  DU APP : 5G-NR Cell %d is UP", cellId->cellId);
261       cellCb->cellStatus = ACTIVATED;
262       gCellStatus = CELL_UP;
263
264 #ifdef O1_ENABLE
265       if(duCfgParam.tempSliceCfg.rrmPolicy)
266          BuildAndSendSliceConfigReq(duCfgParam.tempSliceCfg.rrmPolicy, duCfgParam.tempSliceCfg.totalRrmPolicy, duCfgParam.tempSliceCfg.totalSliceCount);
267       DU_LOG("\nINFO   -->  DU APP : Raise cell UP alarm for cell id=%d", cellId->cellId);
268       raiseCellAlrm(CELL_UP_ALARM_ID, cellId->cellId);
269       setCellOpState(cellId->cellId, ENABLED, ACTIVE);
270 #else
271       BuildAndSendSliceConfigReq(&rrmPolicy,1, rrmPolicy->numMemberList);
272 #endif
273
274    }
275
276    if((pst->selector == ODU_SELECTOR_LWLC) || (pst->selector == ODU_SELECTOR_TC))
277       DU_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, sizeof(OduCellId));
278    return ROK;
279 }
280
281 /*******************************************************************
282  *
283  * @brief Handle Cell delete response from MAC
284  *
285  * @details
286  *
287  *    Function : DuProcMacCellDeleteRsp
288  *
289  *    Functionality: Handle Cell delete response from MAC
290  *
291  * @params[in] Pointer to MacCellDeleteRsp and Pst
292  * @return ROK     - success
293  *         RFAILED - failure
294  *
295  * ****************************************************************/
296
297 uint8_t DuProcMacCellDeleteRsp(Pst *pst, MacCellDeleteRsp *deleteRsp)
298 {
299    uint8_t ret = ROK;
300    uint16_t cellIdx=0;
301    
302    if(deleteRsp)
303    {
304       if(deleteRsp->result == SUCCESSFUL_RSP)
305       {
306          GET_CELL_IDX(deleteRsp->cellId, cellIdx);
307          DU_LOG("\nINFO   -->  DU APP : MAC CELL Delete Response : SUCCESS [CELL IDX : %d]", deleteRsp->cellId);
308          if(duCb.actvCellLst[cellIdx] && (duCb.actvCellLst[cellIdx]->cellId == deleteRsp->cellId))
309          {
310             memset(duCb.actvCellLst[cellIdx], 0, sizeof(DuCellCb));
311             gCellStatus = CELL_DOWN;
312
313 #ifdef O1_ENABLE
314             DU_LOG("\nINFO   -->  DU APP : Raise cell down alarm for cell id=%d", deleteRsp->cellId);
315             raiseCellAlrm(CELL_DOWN_ALARM_ID, deleteRsp->cellId);
316             setCellOpState(deleteRsp->cellId, DISABLED, INACTIVE);
317 #endif
318
319             duCb.numActvCells--;
320             duCb.numCfgCells--;
321             DU_FREE(duCb.actvCellLst[cellIdx], sizeof(DuCellCb));
322
323          }
324          else
325          {
326             DU_LOG("\nERROR  -->  DU APP : DuProcMacCellDeleteRsp(): CellId [%d] doesnot exist", deleteRsp->cellId);
327             ret = RFAILED;
328          }
329       }
330       else
331       {
332          DU_LOG("\nERROR  -->  DU APP : DuProcMacCellDeleteRsp(): MAC CELL Delete Response : FAILED\
333          [CELL IDX : %d]", deleteRsp->cellId);
334          ret = RFAILED;
335       }
336       DU_FREE_SHRABL_BUF(pst->region, pst->pool, deleteRsp, sizeof(MacCellDeleteRsp));
337    }
338    else
339    {
340       DU_LOG("\nERROR  -->  DU APP : DuProcMacCellDeleteRsp(): Received MAC cell delete response is NULL");
341       ret = RFAILED;
342    }
343    return ret;
344 }
345
346 /*******************************************************************
347  *
348  * @brief Sending Cell Delete Req To Mac
349  *
350  * @details
351  *
352  *    Function : sendCellDeleteReqToMac
353  *
354  *    Functionality:
355  *     sending Cell Delete Req To Mac
356  *
357  *  @params[in]    uint16_t cellId
358  *  @return ROK     - success
359  *          RFAILED - failure
360  *
361  *
362  *****************************************************************/
363
364 uint8_t sendCellDeleteReqToMac(uint16_t cellId)
365 {
366    Pst pst;
367    uint8_t ret=ROK;
368    MacCellDelete *cellDelete = NULLP;
369    
370    DU_ALLOC_SHRABL_BUF(cellDelete, sizeof(MacCellDelete));
371    if(cellDelete)
372    {
373       cellDelete->cellId = cellId;
374       FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_DELETE_REQ);
375
376       DU_LOG("\nINFO   -->  DU APP : Sending Cell Delete Request to MAC");  
377       /* Processing one Cell at a time to MAC */
378       ret = (*packMacCellDeleteReqOpts[pst.selector])(&pst, cellDelete);
379       if(ret == RFAILED)
380       {
381          DU_LOG("\nERROR  -->  DU APP : sendCellDeleteReqToMac(): Failed to send Cell delete Req to MAC");
382          DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cellDelete, sizeof(MacCellDelete));
383       }
384    }
385    else
386    {
387       DU_LOG("\nERROR  -->   DU APP : sendCellDeleteReqToMac(): Failed to allocate memory"); 
388       ret = RFAILED;
389    }
390    return ret;
391 }
392
393 /*******************************************************************
394  *
395  * @brief DU preocess Cell Delete Req to MAC 
396  *
397  * @details
398  *
399  *    Function : duSendCellDeletReq 
400  *
401  *    Functionality: DU process Cell Delete Req to MAC 
402  *
403  * @params[in] uint16_t cellId
404  * @return ROK     - success
405  *         RFAILED - failure
406  *
407  * ****************************************************************/
408
409 uint8_t duSendCellDeletReq(uint16_t cellId)
410 {
411    uint16_t cellIdx = 0;
412    DU_LOG("\nINFO   -->  DU APP : Processing Cell Delete Request ");
413    GET_CELL_IDX(cellId, cellIdx);
414
415    if(duCb.actvCellLst[cellIdx] == NULLP)
416    {
417       DU_LOG("\nERROR  -->  DU APP : duSendCellDeletReq(): CellId[%d] is not found", cellId);
418       return RFAILED;
419    }
420    
421    if(duCb.actvCellLst[cellIdx]->cellId != cellId)
422    {
423       DU_LOG("\nERROR  -->  DU APP : duSendCellDeletReq(): CellId[%d] is not found", cellId);
424       return RFAILED;
425
426    }  
427    
428    if(duCb.actvCellLst[cellIdx]->cellStatus != DELETION_IN_PROGRESS)
429    {
430       DU_LOG("\nERROR  -->  DU APP : duSendCellDeletReq(): CellStatus[%d] of cellId[%d] is not correct.\
431       Expected CellStatus is DELETION_IN_PROGRESS",duCb.actvCellLst[cellIdx]->cellStatus, cellId);
432       return RFAILED;  
433    }
434
435    if(duBuildAndSendMacCellStop(cellId) == RFAILED)
436    {
437       DU_LOG("\nERROR  -->  DU APP : duSendCellDeletReq(): Failed to build and send cell stop request to MAC for\
438             cellId[%d]",cellId);
439       return RFAILED;
440    }
441
442    return ROK;
443 }
444
445 /**********************************************************************
446   End of file
447  **********************************************************************/