code changes in Gnb-DU config update for CLA [Issue Id - ODUHIGH-335]
[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 "ConfigInterface.h"
38
39 #endif
40
41 /*******************************************************************
42  *
43  * @brief Processes cells to be activated
44  *
45  * @details
46  *
47  *    Function : duProcCellsToBeActivated
48  *
49  *    Functionality:
50  *      - Processes cells to be activated list received in F1SetupRsp
51  *
52  * @params[in] void
53  * @return ROK     - success
54  *         RFAILED - failure
55  *
56  * ****************************************************************/
57 uint8_t duProcCellsToBeActivated(uint8_t *plmnStr, uint16_t nci, uint16_t nRPci)
58 {
59    uint8_t ret = ROK;
60    DuCellCb *cellCb = NULLP;
61    uint8_t cfgIdx, tmpPlmn[4];
62
63    for(cfgIdx=0; cfgIdx<duCb.numCfgCells; cfgIdx++)
64    {
65       memset(tmpPlmn, 0, 4);
66       buildPlmnId(duCb.cfgCellLst[cfgIdx]->cellInfo.nrEcgi.plmn, tmpPlmn);
67       if(duCb.cfgCellLst[cfgIdx]->cellInfo.nrEcgi.cellId == nci &&
68             (strcmp((const char*)tmpPlmn, (const char*)plmnStr) == 0))
69       {
70          cellCb = duCb.cfgCellLst[cfgIdx];
71          break;
72       }
73       else
74       {
75          DU_LOG("\nERROR  -->  DU APP : No Cell found for NCI %d", nci);
76          return RFAILED;
77       }
78    }
79
80    cellCb->cellStatus = ACTIVATION_IN_PROGRESS; 
81    cellCb->cellInfo.nrPci = nRPci;
82
83    duCb.actvCellLst[duCb.numActvCells++] = cellCb;
84
85    if(duBuildAndSendMacCellCfg(cellCb->cellId) != ROK)
86    {
87       DU_LOG("\nERROR  -->  DU APP : macCellCfg build and send failed");
88       /* Delete cell from actvCellList */
89       duCb.actvCellLst[--(duCb.numActvCells)] = NULLP;
90       ret = RFAILED;
91    }
92    return ret;
93 }
94
95 /*******************************************************************
96  *
97  * @brief Handles DU F1Setup Rsp received in F1AP
98  *
99  * @details
100  *
101  *    Function : duProcF1SetupRsp
102  *
103  *    Functionality:
104  *      - Handles DU F1Setup Rsp received in F1AP
105  *
106  * @params[in] Pointer to F1SetupRsp 
107  * @return void
108  *
109  ******************************************************************/
110 void duProcF1SetupRsp()
111 {
112    DU_LOG("\nINFO   -->  DU_APP : F1 Setup Response received");
113    duCb.f1Status = TRUE; //Set F1 status as true
114 }
115
116 /*******************************************************************
117 *
118 * @brief Returns cellCb based on cell ID
119 *
120 * @details
121 *
122 *    Function : duGetCellCb
123 *
124 *    Functionality: Returns DU APP CellCb based on cell ID
125 *
126 * @params[in] F1AP_PDU_t ASN decoded F1AP message
127 * @return ROK     - success
128 *         RFAILED - failure
129 *
130 * ****************************************************************/
131 uint8_t duGetCellCb(uint16_t cellId, DuCellCb **cellCb)
132 {
133    uint8_t cellIdx = 0;
134    for(cellIdx=0; cellIdx<duCb.numActvCells; cellIdx++)
135    {
136       if(duCb.actvCellLst[cellIdx]->cellId == cellId)
137          *cellCb = duCb.actvCellLst[cellIdx];
138          break;
139    }
140
141    if(!*cellCb)
142    {
143       DU_LOG("\nERROR  -->  DU APP : Cell Id %d not found in DU APP", cellId);
144       return RFAILED;
145    }
146
147    return ROK;
148 }
149
150 /*******************************************************************
151  *
152  * @brief Handles cell up indication from MAC
153  *
154  * @details
155  *
156  *    Function : duHandleCellUpInd
157  *
158  *    Functionality:
159  *      Handles cell up indication from MAC
160  *
161  * @params[in] Post structure pointer
162  *             cell Up info
163  * @return ROK     - success
164  *         RFAILED - failure
165  *
166  * ****************************************************************/
167 uint8_t duHandleCellUpInd(Pst *pst, OduCellId *cellId)
168 {
169    DuCellCb *cellCb = NULLP;
170
171    if(cellId->cellId <=0 || cellId->cellId > MAX_NUM_CELL)
172    {
173       DU_LOG("\nERROR  -->  DU APP : Invalid Cell Id %d in duHandleCellUpInd()", cellId->cellId);
174       return RFAILED;
175    }
176
177    if(duGetCellCb(cellId->cellId, &cellCb) != ROK)
178       return RFAILED;
179
180    if((cellCb != NULL) && (cellCb->cellStatus == ACTIVATION_IN_PROGRESS))
181    {
182       DU_LOG("\nINFO   -->  DU APP : 5G-NR Cell %d is UP", cellId->cellId);
183       cellCb->cellStatus = ACTIVATED;
184       gCellStatus = CELL_UP;
185
186 #ifdef O1_ENABLE
187       DU_LOG("\nINFO   -->  DU APP : Raise cell UP alarm for cell id=%d", cellId->cellId);
188       raiseCellAlrm(CELL_UP_ALARM_ID, cellId->cellId);
189       setCellOpState(cellId->cellId, ENABLED, ACTIVE);
190 #endif
191    }
192
193    if((pst->selector == ODU_SELECTOR_LWLC) || (pst->selector == ODU_SELECTOR_TC))
194       DU_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, sizeof(OduCellId));
195    return ROK;
196 }
197
198 /**********************************************************************
199   End of file
200  **********************************************************************/