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