MAC Clean-up [Issue-ID: ODUHIGH-212]
[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 "du_app_mac_inf.h"
26 #include "du_cfg.h"
27 #include "E2AP-PDU.h"
28 #include<ProtocolIE-Field.h>
29 #include "F1AP-PDU.h"
30 #include "du_cell_mgr.h"
31 #include "odu_common_codec.h"
32
33 extern DuCfgParams duCfgParam;
34 extern S16 duBuildAndSendMacCellCfg();
35
36 /*******************************************************************
37  *
38  * @brief Processes cells to be activated
39  *
40  * @details
41  *
42  *    Function : procCellsToBeActivated
43  *
44  *    Functionality:
45  *      - Processes cells to be activated list received in F1SetupRsp
46  *
47  * @params[in] void
48  * @return ROK     - success
49  *         RFAILED - failure
50  *
51  * ****************************************************************/
52 S16 procCellsToBeActivated(Cells_to_be_Activated_List_t cellsToActivate)
53 {
54    U16 idx = 0;
55    S16 ret = ROK;
56
57    for(idx=0; idx<cellsToActivate.list.count; idx++)
58    {
59       U16 nci = 0;
60       U16 pci = 0;
61       DuCellCb *cellCb = NULLP;
62
63       Cells_to_be_Activated_List_Item_t cell = cellsToActivate.list.array[idx]->\
64           value.choice.Cells_to_be_Activated_List_Item;
65
66       bitStringToInt(&cell.nRCGI.nRCellIdentity, &nci);
67       if(nci <= 0 || nci > MAX_NUM_CELL)
68       {
69          DU_LOG("\nDU APP : Invalid NCI %d", nci);
70          return RFAILED;
71       }
72
73       if(cell.nRPCI)
74       {
75          pci = *cell.nRPCI;
76       }
77
78       cellCb = duCb.cfgCellLst[nci-1];
79
80       if(!cellCb)
81       {
82          DU_LOG("\nDU APP : No Cell found for NCI %d", nci);
83          return RFAILED;
84       }
85       cellCb->cellStatus = ACTIVATION_IN_PROGRESS; 
86       cellCb->cellInfo.nrPci = pci;
87
88       /* Now remove this cell from configured list and move to active list */
89       duCb.cfgCellLst[nci-1] = NULL;
90       duCb.actvCellLst[nci-1] = cellCb;
91       duCb.numActvCells++;
92       /* Build and send Mac Cell Cfg for the number of active cells */
93       ret = duBuildAndSendMacCellCfg();
94       if(ret != ROK)
95       {
96          DU_LOG("\nDU APP : macCellCfg build and send failed");
97          return RFAILED;
98       }
99    }
100    return ret;
101 }
102
103 /******************************************************************
104 *
105 * @brief Processes F1 Setup Response sent by CU
106 *
107 * @details
108 *
109 *    Function : procF1SetupRsp
110 *
111 *    Functionality: Processes F1 Setup Response sent by CU
112 *
113 * @params[in] F1AP_PDU_t ASN decoded F1AP message
114 * @return ROK     - success
115 *         RFAILED - failure
116 *
117 * ****************************************************************/
118 uint8_t procF1SetupRsp(F1AP_PDU_t *f1apMsg)
119 {
120    uint8_t ret = ROK;
121
122    F1SetupResponse_t *f1SetRspMsg;
123    F1SetupRsp    f1SetRspDb;
124    GNB_CU_Name_t *cuName;
125    RRC_Version_t *rrc_Ver;
126    U16 idx;
127
128    DU_LOG("\nDU_APP : F1 Setup Response received"); 
129         printf("\nDU_APP : F1 Setup Response received");
130    duCb.f1Status = TRUE; //Set F1 status as true
131    f1SetRspMsg = &f1apMsg->choice.successfulOutcome->value.choice.F1SetupResponse;
132
133    for(idx=0; idx<f1SetRspMsg->protocolIEs.list.count; idx++)
134    {
135 //      F1SetupResponseIEs_t f1RspIe = f1SetRspMsg->protocolIEs.list.array[idx];
136       switch(f1SetRspMsg->protocolIEs.list.array[idx]->id)
137       {
138          case ProtocolIE_ID_id_Cells_to_be_Activated_List:
139          {
140             procCellsToBeActivated(f1SetRspMsg->protocolIEs.list.array[idx]->\
141                   value.choice.Cells_to_be_Activated_List);
142             break;
143          }
144          //TODO: where to store and how to use below variables?can they be skipped
145          case ProtocolIE_ID_id_TransactionID:
146          {
147             f1SetRspDb.transId = f1SetRspMsg->protocolIEs.list.array[idx]->\
148                                  value.choice.TransactionID;
149             break;
150          }
151          case ProtocolIE_ID_id_gNB_CU_Name:
152          {
153             cuName = &f1SetRspMsg->protocolIEs.list.array[idx]->\
154                      value.choice.GNB_CU_Name;
155             strcpy(f1SetRspDb.cuName, (const char*)cuName->buf);
156             break;
157          }
158          case ProtocolIE_ID_id_GNB_CU_RRC_Version:
159          {
160             rrc_Ver = &f1SetRspMsg->protocolIEs.list.array[idx]->\
161                       value.choice.RRC_Version;
162             strcpy(f1SetRspDb.rrcVersion.rrcVer,
163                   (const char*)rrc_Ver->latest_RRC_Version.buf);
164             break;
165          }
166          default:
167             DU_LOG("\nDU_APP : Invalid IE received in F1SetupRsp:%ld",
168                   f1SetRspMsg->protocolIEs.list.array[idx]->id);
169       }
170    }
171  
172    /* TODO :Check the deallocation */
173 #if 0
174    SPutSBuf(DU_APP_MEM_REGION, DU_POOL,(Data *)&(f1SetupRsp->protocolIEs.list.array),\
175          (Size)elementCnt * sizeof(F1SetupResponseIEs_t *));
176    SPutSBuf(DU_APP_MEM_REGION, DU_POOL,(Data *)&(f1apMsg->choice.successfulOutcome),\
177          (Size)sizeof(SuccessfulOutcome_t));
178    SPutSBuf(DU_APP_MEM_REGION, DU_POOL,(Data *)&f1apMsg,(Size)sizeof(F1AP_PDU_t));
179 #endif
180  
181    return ret;
182 }
183
184 /*******************************************************************
185  *
186  * @brief Processes GNB DU config update ack
187  *
188  * @details
189  *
190  *    Function : procGNBDUCfgUpdAck
191  *
192  *    Functionality: Processes GNB DU config update ack
193  *
194  * @params[in] F1AP_PDU_t ASN decoded F1AP message
195  * @return ROK     - success
196  *         RFAILED - failure
197  *
198  * ****************************************************************/
199 S16 procGNBDUCfgUpdAck(F1AP_PDU_t *f1apMsg)
200 {
201    DU_LOG("\nF1AP : GNB-DU config update acknowledgment received");
202 /* TODO :Check the deallocation */
203 #if 0
204    SPutSBuf(DU_APP_MEM_REGION,DU_POOL,(Data*)&(gNBDuCfgAck->protocolIEs.list.array),\
205            (Size)elementCnt * sizeof(GNBDUConfigurationUpdateAcknowledgeIEs_t
206 ));
207    SPutSBuf(DU_APP_MEM_REGION,DU_POOL,(Data*)&(f1apMsg->choice.successfulOutcome),\
208            (Size)sizeof(SuccessfulOutcome_t));
209    SPutSBuf(DU_APP_MEM_REGION,DU_POOL,(Data*)&f1apMsg,(Size)sizeof(F1AP_PDU_t));
210 #endif
211     return ROK;
212 }
213
214
215 /**********************************************************************
216   End of file
217  **********************************************************************/