Edit-conf changes for CLA use case.
[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 Handles GNB DU Cfg Update Ack received in F1AP
119  *
120  * @details
121  *
122  *    Function : duProcGnbDuCfgUpdAckMsg
123  *
124  *    Functionality:
125  *      - Handles GNB DU Cfg Update Ack received in F1AP
126  *
127  * @params[in] Pointer to F1GnbDuCfgUpdAck
128  * @return void
129  *  
130  ******************************************************************/
131 void duProcGnbDuCfgUpdAckMsg()
132 {
133    DU_LOG("\nINFO   -->  DU APP: GNB-DU config update Ack received ");
134 }
135 /*******************************************************************
136 *
137 * @brief Returns cellCb based on cell ID
138 *
139 * @details
140 *
141 *    Function : duGetCellCb
142 *
143 *    Functionality: Returns DU APP CellCb based on cell ID
144 *
145 * @params[in] F1AP_PDU_t ASN decoded F1AP message
146 * @return ROK     - success
147 *         RFAILED - failure
148 *
149 * ****************************************************************/
150 uint8_t duGetCellCb(uint16_t cellId, DuCellCb **cellCb)
151 {
152    uint8_t cellIdx = 0;
153    for(cellIdx=0; cellIdx<duCb.numActvCells; cellIdx++)
154    {
155       if(duCb.actvCellLst[cellIdx]->cellId == cellId)
156          *cellCb = duCb.actvCellLst[cellIdx];
157          break;
158    }
159
160    if(!*cellCb)
161    {
162       DU_LOG("\nERROR  -->  DU APP : Cell Id %d not found in DU APP", cellId);
163       return RFAILED;
164    }
165
166    return ROK;
167 }
168
169 /*******************************************************************
170  *
171  * @brief Handles cell up indication from MAC
172  *
173  * @details
174  *
175  *    Function : duHandleCellUpInd
176  *
177  *    Functionality:
178  *      Handles cell up indication from MAC
179  *
180  * @params[in] Post structure pointer
181  *             cell Up info
182  * @return ROK     - success
183  *         RFAILED - failure
184  *
185  * ****************************************************************/
186 uint8_t duHandleCellUpInd(Pst *pst, OduCellId *cellId)
187 {
188    DuCellCb *cellCb = NULLP;
189
190    if(cellId->cellId <=0 || cellId->cellId > MAX_NUM_CELL)
191    {
192       DU_LOG("\nERROR  -->  DU APP : Invalid Cell Id %d in duHandleCellUpInd()", cellId->cellId);
193       return RFAILED;
194    }
195
196    if(duGetCellCb(cellId->cellId, &cellCb) != ROK)
197       return RFAILED;
198
199    if((cellCb != NULL) && (cellCb->cellStatus == ACTIVATION_IN_PROGRESS))
200    {
201       DU_LOG("\nINFO   -->  DU APP : 5G-NR Cell %d is UP", cellId->cellId);
202       cellCb->cellStatus = ACTIVATED;
203
204 #ifdef O1_ENABLE
205       DU_LOG("\nINFO   -->  DU APP : Raise cell UP alarm for cell id=%d", cellId->cellId);
206       raiseCellAlrm(CELL_UP_ALARM_ID, cellId->cellId);
207       setCellOpState(cellId->cellId, ENABLED, ACTIVE);
208 #endif
209    }
210
211    if((pst->selector == ODU_SELECTOR_LWLC) || (pst->selector == ODU_SELECTOR_TC))
212       DU_FREE_SHRABL_BUF(pst->region, pst->pool, cellId, sizeof(OduCellId));
213    return ROK;
214 }
215
216 /**********************************************************************
217   End of file
218  **********************************************************************/