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