1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
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 #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
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 #include "common_def.h"
23 #include "du_app_mac_inf.h"
24 #include "du_app_rlc_inf.h"
27 #include "du_mgr_main.h"
29 #include "GlobalE2node-gNB-ID.h"
30 #include<ProtocolIE-FieldE2.h>
31 #include "E2setupRequest.h"
32 #include "InitiatingMessageE2.h"
33 #include "SuccessfulOutcomeE2.h"
35 #include "du_e2ap_msg_hdl.h"
36 #include "odu_common_codec.h"
37 #include "E2nodeComponentInterfaceF1.h"
38 #include "E2setupRequest.h"
40 /*******************************************************************
42 * @brief Builds Global gNodeB Params
46 * Function : BuildGlobalgNBId
48 * Functionality: Building the Plmn and gNB id
50 * @params[in] GlobalE2node_gNB_ID_t *gNbId
51 * @return ROK - success
54 ******************************************************************/
56 uint8_t BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId)
63 /* Allocate Buffer size */
64 gNbId->global_gNB_ID.plmn_id.size = 3 * sizeof(uint8_t);
65 gNbId->global_gNB_ID.plmn_id.buf = NULLP;
66 DU_ALLOC(gNbId->global_gNB_ID.plmn_id.buf , gNbId->global_gNB_ID.plmn_id.size);
67 if(gNbId->global_gNB_ID.plmn_id.buf == NULLP)
69 DU_LOG("\nERROR --> E2AP: Memory allocation failed for Plmn buffer");
74 buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
75 gNbId->global_gNB_ID.plmn_id.buf);
77 gNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
78 /* Allocate Buffer size */
79 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = byteSize * sizeof(uint8_t);
80 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf = NULLP;
81 DU_ALLOC(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf, \
82 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
83 if(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf == NULLP)
85 DU_LOG("\nERROR --> E2AP: Memory allocation failed for gnb buffer");
90 fillBitString(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, gnbId);
96 /*******************************************************************
98 * @brief Builds E2 node config addition list
102 * Function : BuildE2NodeConfigAddList
104 * Functionality: Building E2 node config addition list
106 * @params[in] E2nodeComponentConfigAddition_List_t *e2NodeAddList
107 * @return ROK - success
110 ******************************************************************/
112 uint8_t BuildE2NodeConfigAddList(E2nodeComponentConfigAddition_List_t *e2NodeAddList)
115 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItemIe;
116 E2nodeComponentConfigAddition_Item_t *e2NodeAddItem;
118 e2NodeAddList->list.count = 1;
119 e2NodeAddList->list.size = e2NodeAddList->list.count * sizeof(E2nodeComponentConfigAddition_ItemIEs_t *);
120 DU_ALLOC(e2NodeAddList->list.array, e2NodeAddList->list.size);
121 if(e2NodeAddList->list.array == NULLP)
123 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
127 for(arrIdx = 0; arrIdx< e2NodeAddList->list.count; arrIdx++)
129 DU_ALLOC(e2NodeAddList->list.array[arrIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
130 if(e2NodeAddList->list.array[arrIdx] == NULLP)
132 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
138 e2NodeAddItemIe = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[arrIdx];
139 e2NodeAddItemIe->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition_Item;
140 e2NodeAddItemIe->criticality = CriticalityE2_reject;
141 e2NodeAddItemIe->value.present = E2nodeComponentConfigAddition_ItemIEs__value_PR_E2nodeComponentConfigAddition_Item;
142 e2NodeAddItem = &e2NodeAddItemIe->value.choice.E2nodeComponentConfigAddition_Item;
144 /* E2nodeComponentInterfaceType */
145 e2NodeAddItem->e2nodeComponentInterfaceType = E2nodeComponentInterfaceType_f1;
147 /* E2 Node Component Request Part */
148 e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.size = duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize;
149 DU_ALLOC(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
150 e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.size);
151 if(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf == NULLP)
153 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
157 memcpy(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
158 duCb.f1SetupReqAndRspMsg.f1MsgReqBuf, e2NodeAddItem->e2nodeComponentConfiguration.\
159 e2nodeComponentRequestPart.size);
160 DU_FREE(duCb.f1SetupReqAndRspMsg.f1MsgReqBuf,duCb.f1SetupReqAndRspMsg.f1MsgReqBufSize);
162 /* E2 Node Component Response Part */
163 e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.size = duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize;
164 DU_ALLOC(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf, \
165 e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.size);
166 if(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf == NULLP)
168 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
171 memcpy(e2NodeAddItem->e2nodeComponentConfiguration.e2nodeComponentResponsePart.buf, \
172 duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, e2NodeAddItem->e2nodeComponentConfiguration.\
173 e2nodeComponentResponsePart.size);
174 DU_FREE(duCb.f1SetupReqAndRspMsg.f1MsgRspBuf, duCb.f1SetupReqAndRspMsg.f1MsgRspBufSize);
176 /* E2 Node Component ID */
177 e2NodeAddItem->e2nodeComponentID.present = E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1;
178 DU_ALLOC(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\
179 sizeof(E2nodeComponentInterfaceF1_t));
180 if(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1 == NULLP)
182 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
185 e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size = sizeof(uint8_t);
186 DU_ALLOC(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
187 e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
189 if(e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf == NULLP)
191 DU_LOG("\nERROR -->list. E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
194 e2NodeAddItem->e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[arrIdx] = duCfgParam.duId;
199 /*******************************************************************
201 * @brief Fills the initiating IE for E2 Setup Request
205 * Function : fillE2SetupReq
207 * Functionality:Fills the Initiating message for
210 * @params[in] E2setupRequest_t *e2SetupReq,
212 * @return ROK - success
215 ******************************************************************/
217 uint8_t fillE2SetupReq(E2setupRequest_t **e2SetupReq, uint8_t *idx)
219 uint8_t elementCnt = 0;
223 if(*e2SetupReq != NULLP)
226 (*e2SetupReq)->protocolIEs.list.count = elementCnt;
227 (*e2SetupReq)->protocolIEs.list.size = elementCnt * sizeof(E2setupRequestIEs_t*);
229 /* Initialize the E2Setup members */
230 DU_ALLOC((*e2SetupReq)->protocolIEs.list.array, \
231 (*e2SetupReq)->protocolIEs.list.size);
232 if((*e2SetupReq)->protocolIEs.list.array == NULLP)
234 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements");
237 for(*idx = 0; *idx < elementCnt; (*idx)++)
239 DU_ALLOC((*e2SetupReq)->protocolIEs.list.array[*idx],\
240 sizeof(E2setupRequestIEs_t));
241 if((*e2SetupReq)->protocolIEs.list.array[*idx] == NULLP)
243 DU_LOG("\nERROR --> E2AP : Memory allocation failed for arrayidx [%d]", *idx);
250 (*e2SetupReq)->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
251 (*e2SetupReq)->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
252 (*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID;
253 (*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = TRANS_ID;
256 /* GlobalE2node_gNB_ID */
257 (*e2SetupReq)->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_GlobalE2node_ID;
258 (*e2SetupReq)->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
259 (*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
260 (*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB;
262 DU_ALLOC((*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.choice.\
263 GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
264 if((*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.choice.\
265 GlobalE2node_ID.choice.gNB == NULLP)
267 DU_LOG("\nERROR --> E2AP : Memory allocation failed for gNbId");
272 ret = BuildGlobalgNBId((*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.\
273 choice.GlobalE2node_ID.choice.gNB);
276 DU_LOG("\nERROR --> E2AP : Failed to build Global Gnb Id");
282 /* E2 Node Component Configuration Addition List */
283 (*e2SetupReq)->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition;
284 (*e2SetupReq)->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
285 (*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_E2nodeComponentConfigAddition_List;
286 if(BuildE2NodeConfigAddList(&((*e2SetupReq)->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List))!=ROK)
288 DU_LOG("\nERROR --> E2AP : Failed to E2 Node config addition list");
295 DU_LOG("\nERROR --> E2AP : received e2SetupReq is NULL");
302 /*******************************************************************
304 * @brief De Allocate E2 Setup Request Message
308 * Function : FreeE2SetupReq
310 * Functionality: De-Allocating E2 Setup request Message
312 * @params[in] E2AP_PDU_t *e2apMsg
316 * ****************************************************************/
318 void FreeE2SetupReq(E2AP_PDU_t *e2apMsg)
321 uint8_t e2NodeAddListIdx =0;
322 E2setupRequest_t *e2SetupReq;
323 E2nodeComponentConfigAddition_List_t *e2NodeAddList;
324 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItem;
326 /* De-allocating Memory */
329 if(e2apMsg->choice.initiatingMessage != NULLP)
331 e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest;
332 if(e2SetupReq->protocolIEs.list.array != NULLP)
334 for(arrIdx = 0; arrIdx < e2SetupReq->protocolIEs.list.count; arrIdx++)
336 if(e2SetupReq->protocolIEs.list.array[arrIdx] != NULLP)
338 switch(e2SetupReq->protocolIEs.list.array[arrIdx]->id)
340 case ProtocolIE_IDE2_id_TransactionID:
342 case ProtocolIE_IDE2_id_GlobalE2node_ID:
344 if(e2SetupReq->protocolIEs.list.array[arrIdx]->\
345 value.choice.GlobalE2node_ID.choice.gNB != NULLP)
347 GlobalE2node_gNB_ID_t *gNbId = NULLP;
348 gNbId = e2SetupReq->protocolIEs.list.array[arrIdx]->\
349 value.choice.GlobalE2node_ID.choice.gNB;
350 if(gNbId->global_gNB_ID.plmn_id.buf != NULLP)
352 DU_FREE(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf,\
353 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
354 DU_FREE(gNbId->global_gNB_ID.plmn_id.buf,\
355 gNbId->global_gNB_ID.plmn_id.size);
357 DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\
358 choice.GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
362 case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition:
364 e2NodeAddList = &e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List;
365 if(e2NodeAddList->list.array)
367 for(e2NodeAddListIdx = 0; e2NodeAddListIdx< e2NodeAddList->list.count; e2NodeAddListIdx++)
369 e2NodeAddItem = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[e2NodeAddListIdx];
371 /* Free E2 Node Component Request Part */
372 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
373 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.size);
375 /* Free E2 Node Component Response Part */
376 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.\
377 e2nodeComponentResponsePart.buf, \
378 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentResponsePart.size);
380 /* Free E2 Node Component ID */
381 if(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1)
383 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
384 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
385 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
386 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
387 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\
388 sizeof(E2nodeComponentInterfaceF1_t));
390 DU_FREE(e2NodeAddList->list.array[e2NodeAddListIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
392 DU_FREE(e2NodeAddList->list.array, e2NodeAddList->list.size);
397 DU_LOG("\nERROR --> E2AP: Invalid event at e2SetupRequet %ld ",\
398 (e2SetupReq->protocolIEs.list.array[arrIdx]->id));
401 DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx], sizeof(E2setupRequestIEs_t));
404 DU_FREE(e2SetupReq->protocolIEs.list.array, e2SetupReq->protocolIEs.list.size);
406 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
408 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
412 /*******************************************************************
414 * @brief Builds and Send the E2SetupRequest
418 * Function : BuildAndSendE2SetupReq
420 * Functionality:Fills the E2SetupRequest
422 * @return ROK - success
425 ******************************************************************/
427 uint8_t BuildAndSendE2SetupReq()
431 E2AP_PDU_t *e2apMsg = NULLP;
432 E2setupRequest_t *e2SetupReq = NULLP;
433 asn_enc_rval_t encRetVal; /* Encoder return value */
435 DU_LOG("\nINFO --> E2AP : Building E2 Setup Request\n");
438 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
441 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
444 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
445 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
446 if(e2apMsg->choice.initiatingMessage == NULLP)
448 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
449 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
452 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
453 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2setup;
454 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_E2setupRequest;
455 e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest;
457 ret = fillE2SetupReq(&e2SetupReq, &idx);
460 DU_LOG("\nERROR --> E2AP : fillE2SetupReq() failed");
463 /* Prints the Msg formed */
464 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
466 memset(encBuf, 0, ENC_BUF_MAX_LEN);
468 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
470 if(encRetVal.encoded == ENCODE_FAIL)
472 DU_LOG("\nERROR --> E2AP : Could not encode E2SetupRequest structure (at %s)\n",\
473 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
478 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupRequest\n");
479 #ifdef DEBUG_ASN_PRINT
480 for(int i=0; i< encBufSize; i++)
482 printf("%x",encBuf[i]);
486 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
488 DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
494 FreeE2SetupReq(e2apMsg);
496 }/* End of BuildAndSendE2SetupReq */
498 /*******************************************************************
500 * @brief Builds Ric Request Id
504 * Function : BuildRicRequestId
506 * Functionality: Building the Ric Request Id
508 * @params[in] RICrequestID_t *ricReqId
509 * @return ROK - success
512 * ****************************************************************/
514 uint8_t BuildRicRequestId(RICrequestID_t *ricReqId)
516 if(ricReqId == NULLP)
521 ricReqId->ricRequestorID = 1;
522 ricReqId->ricInstanceID = 1;
526 /*******************************************************************
528 * @brief Fills the mandatory RicAdmitted List Items
532 * Function : fillRicAdmitList
534 * Functionality: Fills the mandatory Ric Admitted List Items
536 * @params[in] RICaction_Admitted_ItemIEs_t *ricAdmitItems
537 * @return ROK - success
540 * ****************************************************************/
542 uint8_t fillRicAdmitList(RICaction_Admitted_ItemIEs_t *ricAdmitItems)
545 if(ricAdmitItems != NULLP)
547 ricAdmitItems->id = ProtocolIE_IDE2_id_RICaction_Admitted_Item;
548 ricAdmitItems->criticality = CriticalityE2_reject;
549 ricAdmitItems->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
550 ricAdmitItems->value.choice.RICaction_Admitted_Item.ricActionID = 1;
558 /*******************************************************************
560 * @brief Builds the mandatory RicAdmitted List Params
564 * Function : BuildRicAdmitList
566 * Functionality: Builds the mandatory Ric Admitted List Params
568 * @params[in] RICaction_Admitted_List_t *admitListPtr
569 * @return ROK - success
572 * ****************************************************************/
574 uint8_t BuildRicAdmitList(RICaction_Admitted_List_t *admitListPtr)
581 if(admitListPtr == NULLP)
583 DU_LOG("\nERROR --> E2AP : Memory allocation for RIC Admit List failed");
588 admitListPtr->list.count = elementCnt;
589 admitListPtr->list.size = elementCnt * sizeof(RICaction_Admitted_ItemIEs_t);
590 DU_ALLOC(admitListPtr->list.array, admitListPtr->list.size);
591 if(admitListPtr->list.array == NULLP)
593 DU_LOG("\nERROR --> E2AP : Memory allocation for RIC Admit List failed");
598 for(idx=0 ; idx<elementCnt ; idx++ )
600 DU_ALLOC(admitListPtr->list.array[idx], sizeof(RICaction_Admitted_ItemIEs_t));
601 if(admitListPtr->list.array[idx] == NULLP)
609 fillRicAdmitList((RICaction_Admitted_ItemIEs_t *)admitListPtr->list.array[idx]);
615 /*******************************************************************
617 * @breif Deallocation of BuildAndSendRicSubscriptionRsp memory
621 * Function : FreeRicSubscriptionRsp
623 * Functionality:Free the RicSubscriptionRsp
625 * @param[in] E2AP_PDU_t *e2apRicMsg
630 ******************************************************************/
631 void FreeRicSubscriptionRsp(E2AP_PDU_t *e2apRicMsg)
633 RICsubscriptionResponse_t *ricSubscriptionRsp= NULLP;
636 RICaction_Admitted_List_t *admitListPtr;
638 if(e2apRicMsg != NULLP)
640 if(e2apRicMsg->choice.successfulOutcome != NULLP)
642 ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
643 if(ricSubscriptionRsp)
645 if(ricSubscriptionRsp->protocolIEs.list.array != NULLP)
647 for(idx=0; idx<ricSubscriptionRsp->protocolIEs.list.count; idx++)
649 if(ricSubscriptionRsp->protocolIEs.list.array[idx] != NULLP)
651 switch(ricSubscriptionRsp->protocolIEs.list.array[idx]->id)
653 case ProtocolIE_IDE2_id_RICrequestID:
656 case ProtocolIE_IDE2_id_RANfunctionID:
659 case ProtocolIE_IDE2_id_RICactions_Admitted:
661 admitListPtr = &ricSubscriptionRsp->protocolIEs.list.\
662 array[idx]->value.choice.RICaction_Admitted_List;
663 if(admitListPtr->list.array != NULLP)
665 for(idx1=0 ; idx1<admitListPtr->list.count; idx1++ )
667 if(admitListPtr->list.array[idx1] != NULLP)
669 DU_FREE(admitListPtr->list.array[idx1],
670 sizeof(RICaction_Admitted_ItemIEs_t));
673 DU_FREE(admitListPtr->list.array, admitListPtr->list.size);
680 DU_FREE(ricSubscriptionRsp->protocolIEs.list.array[idx], \
681 sizeof(RICsubscriptionResponse_IEs_t));
684 DU_FREE(ricSubscriptionRsp->protocolIEs.list.array, \
685 ricSubscriptionRsp->protocolIEs.list.size);
688 DU_FREE(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
690 DU_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
693 /*******************************************************************
695 * @brief Builds and Send the RicSubscriptionRsp
699 * Function : BuildAndSendRicSubscriptionRsp
701 * functionality:Fills the RicSubscriptionRsp
703 * @return ROK - success
706 ******************************************************************/
707 uint8_t FillRicSubscriptionRsp(RICsubscriptionResponse_t *ricSubscriptionRsp )
711 uint8_t elementCnt = 0;
712 uint8_t BuildRicRequestIdret=ROK;
713 uint8_t BuildRicAdmitListret=ROK;
716 ricSubscriptionRsp->protocolIEs.list.count = elementCnt;
717 ricSubscriptionRsp->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionResponse_IEs_t);
718 DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array, \
719 ricSubscriptionRsp->protocolIEs.list.size);
720 if(ricSubscriptionRsp->protocolIEs.list.array == NULLP)
722 DU_LOG("\nERROR --> E2AP : Memory allocation for FillRicSubscriptionRsp failed");
727 for(idx=0; idx<ricSubscriptionRsp->protocolIEs.list.count; idx++)
729 DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array[idx], \
730 sizeof(RICsubscriptionResponse_IEs_t));
731 if(ricSubscriptionRsp->protocolIEs.list.array[idx] == NULLP)
740 ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
741 ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
742 ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
743 RICsubscriptionRequest_IEs__value_PR_RICrequestID;
744 BuildRicRequestIdret =
745 BuildRicRequestId(&ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RICrequestID);
746 if(BuildRicRequestIdret != ROK)
753 ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
754 ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
755 ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
756 RICsubscriptionRequest_IEs__value_PR_RANfunctionID;
757 ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RANfunctionID = 1;
760 ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICactions_Admitted;
761 ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
762 ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
763 RICsubscriptionResponse_IEs__value_PR_RICaction_Admitted_List;
764 BuildRicAdmitListret =
765 BuildRicAdmitList(&ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RICaction_Admitted_List);
766 if(BuildRicAdmitListret != ROK)
775 /*******************************************************************
777 * @brief Builds and Send the RicSubscriptionRsp
781 * Function : BuildAndSendRicSubscriptionRsp
783 * Functionality:Fills the RicSubscriptionRsp
785 * @return ROK - success
788 ******************************************************************/
790 uint8_t BuildAndSendRicSubscriptionRsp()
793 E2AP_PDU_t *e2apRicMsg = NULLP;
794 RICsubscriptionResponse_t *ricSubscriptionRsp=NULLP;
795 asn_enc_rval_t encRetVal;
796 uint8_t ret = RFAILED;
797 uint8_t FillRicricSubscriptionRspret;
801 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Response\n");
803 DU_ALLOC(e2apRicMsg, sizeof(E2AP_PDU_t));
804 if(e2apRicMsg == NULLP)
806 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
809 e2apRicMsg->present = E2AP_PDU_PR_successfulOutcome;
810 DU_ALLOC(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
811 if(e2apRicMsg->choice.successfulOutcome == NULLP)
813 DU_LOG("\nERROR --> E2AP : Memory allocation for RIC subscription Response failed");
817 e2apRicMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_RICsubscription;
818 e2apRicMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
819 e2apRicMsg->choice.successfulOutcome->value.present = \
820 SuccessfulOutcomeE2__value_PR_RICsubscriptionResponse;
821 ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
823 FillRicricSubscriptionRspret = FillRicSubscriptionRsp(ricSubscriptionRsp);
824 if(FillRicricSubscriptionRspret != ROK)
826 DU_LOG("\nERROR --> E2AP : Memory allocation for RICsubscriptionResponseIE failed");
830 /* Prints the Msg formed */
831 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apRicMsg);
833 memset(encBuf, 0, ENC_BUF_MAX_LEN);
835 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apRicMsg, PrepFinalEncBuf,\
837 if(encRetVal.encoded == ENCODE_FAIL)
839 DU_LOG("\nERROR --> E2AP : Could not encode RIC Subscription Response structure (at %s)\n",\
840 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
845 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC subscription response \n");
846 #ifdef DEBUG_ASN_PRINT
847 for(int i=0; i< encBufSize; i++)
849 printf("%x",encBuf[i]);
854 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
856 DU_LOG("\nERROR --> E2AP : Sending RIC Subscription Response failed");
864 FreeRicSubscriptionRsp(e2apRicMsg);
869 /******************************************************************
871 * @brief Deallocation of memory allocated bu aper decoder for e2 setup response
875 * Function : freeAperDecodingOfE2SetupRsp
877 * Functionality: Deallocation of memory allocated bu aper decoder for e2
880 * @params[in] E2setupResponse_t *e2SetRspMsg;
883 * ****************************************************************/
884 void freeAperDecodingOfE2SetupRsp(E2setupResponse_t *e2SetRspMsg)
886 uint8_t arrIdx, e2NodeConfigAddAckListIdx;
887 E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItem;
888 E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAddAckList;
892 if(e2SetRspMsg->protocolIEs.list.array)
894 for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
896 if(e2SetRspMsg->protocolIEs.list.array[arrIdx])
898 switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
900 case ProtocolIE_IDE2_id_TransactionID:
903 case ProtocolIE_IDE2_id_GlobalRIC_ID:
905 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.pLMN_Identity.buf);
906 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID.buf);
910 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
912 e2NodeConfigAddAckList = &e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
913 if(e2NodeConfigAddAckList->list.array )
915 for(e2NodeConfigAddAckListIdx = 0; e2NodeConfigAddAckListIdx< e2NodeConfigAddAckList->list.count; e2NodeConfigAddAckListIdx++)
917 if(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx])
919 e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx];
920 free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
921 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf);
922 free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
923 e2nodeComponentInterfaceTypeF1);
924 free(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx]);
927 free(e2NodeConfigAddAckList->list.array);
932 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]);
935 free(e2SetRspMsg->protocolIEs.list.array);
939 /******************************************************************
941 * @brief Processes E2 Setup Response sent by RIC
945 * Function : procE2SetupRsp
947 * Functionality: Processes E2 Setup Response sent by RIC
949 * @params[in] E2AP_PDU_t ASN decoded E2AP message
950 * @return ROK - success
953 * ****************************************************************/
954 uint8_t procE2SetupRsp(E2AP_PDU_t *e2apMsg)
958 E2setupResponse_t *e2SetRspMsg;
960 DU_LOG("\nINFO --> E2AP : E2 Setup Response received");
961 duCb.e2Status = TRUE; //Set E2 status as true
962 e2SetRspMsg = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse;
964 for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
966 switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
968 case ProtocolIE_IDE2_id_TransactionID:
971 case ProtocolIE_IDE2_id_GlobalRIC_ID:
973 /* To store the Ric Id Params */
974 recvBufLen = sizeof(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value\
975 .choice.GlobalRIC_ID.pLMN_Identity.size);
976 e2apMsgDb.plmn = NULLP;
977 DU_ALLOC(e2apMsgDb.plmn, recvBufLen);
980 memcpy(e2apMsgDb.plmn, e2SetRspMsg->protocolIEs.list.array[arrIdx]\
981 ->value.choice.GlobalRIC_ID.pLMN_Identity.buf, recvBufLen);
983 bitStringToInt(&e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID, &e2apMsgDb.ricId);
984 /*TODO : e2apMsgDb.plmn memory to be deallocated after the usage */
988 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
992 DU_LOG("\nERROR --> E2AP : Invalid IE received in E2SetupRsp:%ld",
993 e2SetRspMsg->protocolIEs.list.array[arrIdx]->id);
997 freeAperDecodingOfE2SetupRsp(e2SetRspMsg);
998 BuildAndSendE2NodeConfigUpdate();
1002 /******************************************************************
1004 * @brief Processes RIC Subscription Req sent by RIC
1008 * Function : procRicSubsReq
1010 * Functionality: Processes E2 Setup Response sent by CU
1012 * @params[in] E2AP_PDU_t ASN decoded E2AP message
1013 * @return ROK - success
1016 * ****************************************************************/
1018 uint8_t procRicSubsReq(E2AP_PDU_t *e2apMsg)
1023 uint32_t recvBufLen;
1024 RICsubscriptionRequest_t *ricSubsReq;
1025 RICaction_ToBeSetup_ItemIEs_t *actionItem;
1027 DU_LOG("\nINFO --> E2AP : RIC Subscription request received");
1028 ricSubsReq = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
1030 for(idx=0; idx<ricSubsReq->protocolIEs.list.count; idx++)
1032 if(ricSubsReq->protocolIEs.list.array[idx])
1034 switch(ricSubsReq->protocolIEs.list.array[idx]->id)
1036 case ProtocolIE_IDE2_id_RICrequestID:
1038 e2apMsgDb.ricReqId = ricSubsReq->protocolIEs.list.array[idx]->\
1039 value.choice.RICrequestID.ricRequestorID;
1040 e2apMsgDb.ricInstanceId = ricSubsReq->protocolIEs.list.array[idx]-> \
1041 value.choice.RICrequestID.ricInstanceID;
1044 case ProtocolIE_IDE2_id_RANfunctionID:
1046 e2apMsgDb.ranFuncId = ricSubsReq->protocolIEs.list.array[idx]-> \
1047 value.choice.RANfunctionID;
1050 case ProtocolIE_IDE2_id_RICsubscriptionDetails:
1052 recvBufLen = sizeof(ricSubsReq->protocolIEs.list.array[idx]->value\
1053 .choice.RICsubscriptionDetails.ricEventTriggerDefinition.size);
1054 e2apMsgDb.ricEventTrigger = NULLP;
1055 DU_ALLOC(e2apMsgDb.ricEventTrigger, recvBufLen);
1056 /*TODO : e2apMsgDb.ricEventTrigger memory to be deallocated after the usage */
1057 if(e2apMsgDb.ricEventTrigger)
1059 memcpy(e2apMsgDb.ricEventTrigger, ricSubsReq->protocolIEs.list.array[idx]\
1060 ->value.choice.RICsubscriptionDetails.ricEventTriggerDefinition.buf, \
1062 free(ricSubsReq->protocolIEs.list.array[idx]->value.choice.\
1063 RICsubscriptionDetails.ricEventTriggerDefinition.buf);
1065 if(ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List.\
1068 actionItem =(RICaction_ToBeSetup_ItemIEs_t *)ricSubsReq->protocolIEs.list\
1069 .array[idx]->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List\
1072 for(ied = 0; ied < ricSubsReq->protocolIEs.list.array[idx]->value.choice.\
1073 RICsubscriptionDetails.ricAction_ToBeSetup_List.list.count; ied++)
1075 switch(actionItem->id)
1077 case ProtocolIE_IDE2_id_RICaction_ToBeSetup_Item:
1079 e2apMsgDb.ricActionId = actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionID;
1080 e2apMsgDb.ricActionType = actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionType;
1084 DU_LOG("\nERROR --> E2AP : Invalid IE received in RicSetupLst:%ld",actionItem->id);
1089 free(ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List.\
1096 DU_LOG("\nERROR --> E2AP : Invalid IE received in RIC SubsReq:%ld",
1097 ricSubsReq->protocolIEs.list.array[idx]->id);
1100 free(ricSubsReq->protocolIEs.list.array[idx]);
1103 free(ricSubsReq->protocolIEs.list.array);
1104 ret = BuildAndSendRicSubscriptionRsp();
1109 /*******************************************************************
1111 * @brief Free the RicIndication Message
1115 * Function : FreeRicIndication
1117 * Functionality: Free the RicIndication Message
1122 ******************************************************************/
1123 void FreeRicIndication(E2AP_PDU_t *e2apMsg)
1126 RICindication_t *ricIndicationMsg= NULLP;
1129 if(e2apMsg != NULLP)
1131 if(e2apMsg->choice.initiatingMessage != NULLP)
1133 ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
1134 if(ricIndicationMsg!= NULLP)
1136 if(ricIndicationMsg->protocolIEs.list.array != NULLP)
1138 for(idx=0; idx<ricIndicationMsg->protocolIEs.list.count; idx++)
1140 if(ricIndicationMsg->protocolIEs.list.array[idx] != NULLP)
1142 switch(ricIndicationMsg->protocolIEs.list.array[idx]->id)
1144 case ProtocolIE_IDE2_id_RICrequestID:
1147 case ProtocolIE_IDE2_id_RANfunctionID:
1150 case ProtocolIE_IDE2_id_RICactionID:
1153 case ProtocolIE_IDE2_id_RICindicationType:
1156 case ProtocolIE_IDE2_id_RICindicationHeader:
1158 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf,\
1159 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
1162 case ProtocolIE_IDE2_id_RICindicationMessage:
1164 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf,\
1165 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
1171 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx],sizeof(RICindication_IEs_t));
1174 DU_FREE(ricIndicationMsg->protocolIEs.list.array,ricIndicationMsg->protocolIEs.list.size);
1177 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1179 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
1182 /*******************************************************************
1184 * brief Fill the RicIndication Message
1188 * Function : FillRicIndication
1190 * Functionality:Fills the RicIndication Message
1192 * @return ROK - success
1195 ******************************************************************/
1196 uint8_t FillRicIndication(RICindication_t *ricIndicationMsg)
1198 uint8_t elementCnt=0;
1203 ricIndicationMsg->protocolIEs.list.count = elementCnt;
1204 ricIndicationMsg->protocolIEs.list.size = elementCnt * sizeof(RICindication_t);
1205 /* Initialize the Ric Indication members */
1206 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array, \
1207 ricIndicationMsg->protocolIEs.list.size);
1208 if(ricIndicationMsg->protocolIEs.list.array == NULLP)
1210 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
1215 for(idx=0; idx<elementCnt; idx++)
1217 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx],\
1218 sizeof(RICindication_IEs_t));
1219 if(ricIndicationMsg->protocolIEs.list.array[idx] == NULLP)
1221 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
1229 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
1230 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1231 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1232 RICindication_IEs__value_PR_RICrequestID;
1233 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID =\
1235 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID =\
1236 e2apMsgDb.ricInstanceId;
1239 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
1240 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1241 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1242 RICindication_IEs__value_PR_RANfunctionID;
1243 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RANfunctionID =
1244 e2apMsgDb.ranFuncId;
1247 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICactionID;
1248 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1249 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1250 RICindication_IEs__value_PR_RICactionID;
1251 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICactionID =
1252 e2apMsgDb.ricActionId;
1255 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationType;
1256 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1257 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1258 RICindication_IEs__value_PR_RICindicationType;
1259 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationType =
1260 e2apMsgDb.ricActionType;
1263 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationHeader;
1264 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1265 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1266 RICindication_IEs__value_PR_RICindicationHeader;
1267 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size = 3 *
1269 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf ,\
1270 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
1271 if(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf == NULLP)
1273 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
1278 buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
1279 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf);
1281 /* TO BE CHANGED: RIC INDICATION DATA */
1282 /* For now filling a dummy octect data, need to tested with PRBs*/
1283 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationMessage;
1284 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1285 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1286 RICindication_IEs__value_PR_RICindicationMessage;
1287 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size = 3 *
1289 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf ,\
1290 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
1291 if(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf == NULLP)
1293 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
1298 buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
1299 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf);
1307 /*******************************************************************
1309 * @brief Builds and Send the RicIndication Message
1313 * Function : BuildAndSendRicIndication
1315 * Functionality:Fills the RicIndication Message
1317 * @return ROK - success
1320 ******************************************************************/
1322 uint8_t BuildAndSendRicIndication()
1324 E2AP_PDU_t *e2apMsg = NULLP;
1325 RICindication_t *ricIndicationMsg=NULLP;
1326 asn_enc_rval_t encRetVal; /* Encoder return value */
1327 uint8_t ret = RFAILED;
1328 uint8_t FillRicIndicationret = ROK;
1332 DU_LOG("\nINFO --> E2AP : Building RIC Indication Message\n");
1334 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
1335 if(e2apMsg == NULLP)
1337 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1341 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
1342 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1343 if(e2apMsg->choice.initiatingMessage == NULLP)
1345 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1348 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICindication;
1349 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
1350 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICindication;
1352 ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
1354 FillRicIndicationret = FillRicIndication(ricIndicationMsg);
1355 if(FillRicIndicationret != ROK)
1359 /* Prints the Msg formed */
1360 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
1361 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1363 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
1365 if(encRetVal.encoded == ENCODE_FAIL)
1367 DU_LOG("\nERROR --> E2AP : Could not encode RIC Indication Message (at %s)\n",\
1368 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1373 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC Indication Message \n");
1374 #ifdef DEBUG_ASN_PRINT
1375 for(int i=0; i< encBufSize; i++)
1377 printf("%x",encBuf[i]);
1382 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
1384 DU_LOG("\nINFO --> E2AP : Sending RIC Indication Message");
1390 FreeRicIndication(e2apMsg);
1394 /*******************************************************************
1396 * @brief Sends E2 msg over SCTP
1400 * Function : SendE2APMsg
1402 * Functionality: Sends E2 msg over SCTP
1404 * @params[in] Region region
1406 * @return ROK - success
1409 * ****************************************************************/
1411 uint8_t SendE2APMsg(Region region, Pool pool)
1415 if(ODU_GET_MSG_BUF(region, pool, &mBuf) == ROK)
1417 if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
1419 ODU_PRINT_MSG(mBuf, 0,0);
1421 if(sctpSend(mBuf, E2_INTERFACE) != ROK)
1423 DU_LOG("\nERROR --> E2AP : SCTP Send for E2 failed");
1424 ODU_PUT_MSG_BUF(mBuf);
1430 DU_LOG("\nERROR --> E2AP : ODU_ADD_POST_MSG_MULT failed");
1431 ODU_PUT_MSG_BUF(mBuf);
1434 ODU_PUT_MSG_BUF(mBuf);
1438 DU_LOG("\nERROR --> E2AP : Failed to allocate memory");
1445 /*******************************************************************
1447 * @brief Deallocate the memory allocated for E2nodeConfigurationUpdate msg
1451 * Function : FreeE2NodeConfigUpdate
1454 * - freeing the memory allocated for E2nodeConfigurationUpdate
1456 * @params[in] E2AP_PDU_t *e2apMsg
1457 * @return ROK - success
1460 * ****************************************************************/
1461 void FreeE2NodeConfigUpdate(E2AP_PDU_t *e2apMsg)
1464 E2nodeConfigurationUpdate_t *e2NodeConfigUpdate;
1466 if(e2apMsg != NULLP)
1468 if(e2apMsg->choice.initiatingMessage != NULLP)
1470 e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
1471 if(e2NodeConfigUpdate->protocolIEs.list.array != NULLP)
1473 for(arrIdx = 0; arrIdx < e2NodeConfigUpdate->protocolIEs.list.count; arrIdx++)
1475 DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
1477 DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array, e2NodeConfigUpdate->protocolIEs.list.size);
1479 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1481 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
1485 /*******************************************************************
1487 * @brief Buld and send the E2 node config update msg
1491 * Function : BuildAndSendE2NodeConfigUpdate
1494 * - Buld and send the E2 node config update msg
1497 * @return ROK - success
1500 * ****************************************************************/
1502 uint8_t BuildAndSendE2NodeConfigUpdate()
1504 uint8_t arrIdx = 0,elementCnt = 1;
1506 E2AP_PDU_t *e2apMsg = NULLP;
1507 E2nodeConfigurationUpdate_t *e2NodeConfigUpdate = NULLP;
1508 asn_enc_rval_t encRetVal; /* Encoder return value */
1510 DU_LOG("\nINFO --> E2AP : Building E2 Node config update\n");
1513 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
1514 if(e2apMsg == NULLP)
1516 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1519 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
1520 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1521 if(e2apMsg->choice.initiatingMessage == NULLP)
1523 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1524 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
1527 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
1528 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2nodeConfigurationUpdate;
1529 e2apMsg->choice.initiatingMessage->value.present = \
1530 InitiatingMessageE2__value_PR_E2nodeConfigurationUpdate;
1531 e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
1533 e2NodeConfigUpdate->protocolIEs.list.count = elementCnt;
1534 e2NodeConfigUpdate->protocolIEs.list.size = elementCnt * sizeof(E2nodeConfigurationUpdate_IEs_t*);
1535 /* Initialize the Ric Indication members */
1536 DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array, \
1537 e2NodeConfigUpdate->protocolIEs.list.size);
1538 if(e2NodeConfigUpdate->protocolIEs.list.array == NULLP)
1540 DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed");
1544 for(arrIdx =0; arrIdx<elementCnt; arrIdx++)
1546 DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
1547 if(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx] == NULLP)
1550 DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed");
1557 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
1558 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1559 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_TransactionID;
1560 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = TRANS_ID;
1563 /* Prints the Msg formed */
1564 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
1566 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1568 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
1570 if(encRetVal.encoded == ENCODE_FAIL)
1572 DU_LOG("\nERROR --> E2AP : Could not encode E2nodeConfigurationUpdate structure (at %s)\n",\
1573 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1578 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2nodeConfigurationUpdate\n");
1579 #ifdef DEBUG_ASN_PRINT
1580 for(int i=0; i< encBufSize; i++)
1582 printf("%x",encBuf[i]);
1586 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
1588 DU_LOG("\nERROR --> E2AP : Sending E2 node config update failed");
1595 FreeE2NodeConfigUpdate(e2apMsg);
1599 /*******************************************************************
1601 * @brief Handles received E2AP message and sends back response
1605 * Function : E2APMsgHdlr
1608 * - Decodes received E2AP control message
1609 * - Prepares response message, encodes and sends to SCTP
1612 * @return ROK - success
1615 * ****************************************************************/
1616 void E2APMsgHdlr(Buffer *mBuf)
1619 char *recvBuf = NULLP;
1621 MsgLen recvBufLen =0;
1622 E2AP_PDU_t *e2apMsg = NULLP;
1623 asn_dec_rval_t rval ={0}; /* Decoder return value */
1624 E2AP_PDU_t e2apasnmsg={0} ;
1626 DU_LOG("\nDEBUG --> E2AP : Received E2AP message buffer");
1627 ODU_PRINT_MSG(mBuf, 0,0);
1629 /* Copy mBuf into char array to decode it */
1630 ODU_GET_MSG_LEN(mBuf, &recvBufLen);
1631 DU_ALLOC(recvBuf, (Size)recvBufLen);
1633 if(recvBuf == NULLP)
1635 DU_LOG("\nERROR --> E2AP : Memory allocation failed");
1638 if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, ©Cnt) != ROK)
1640 DU_LOG("\nERROR --> E2AP : Failed while copying %d", copyCnt);
1644 #ifdef DEBUG_ASN_PRINT
1645 printf("\nDEBUG --> E2AP : Received flat buffer to be decoded : ");
1646 for(i=0; i< recvBufLen; i++)
1648 printf("%x",recvBuf[i]);
1652 /* Decoding flat buffer into E2AP messsage */
1653 e2apMsg = &e2apasnmsg;
1654 memset(e2apMsg, 0, sizeof(E2AP_PDU_t));
1656 rval = aper_decode(0, &asn_DEF_E2AP_PDU, (void **)&e2apMsg, recvBuf, recvBufLen, 0, 0);
1657 DU_FREE(recvBuf, (Size)recvBufLen);
1659 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
1661 DU_LOG("\nERROR --> E2AP : ASN decode failed");
1665 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
1667 switch(e2apMsg->present)
1669 case E2AP_PDU_PR_successfulOutcome:
1671 switch(e2apMsg->choice.successfulOutcome->value.present)
1673 case SuccessfulOutcomeE2__value_PR_E2setupResponse:
1677 DU_LOG("\nDEBUG --> E2AP : Store E2 setup response Params");
1678 procE2SetupRsp(e2apMsg);
1682 case SuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateAcknowledge:
1684 DU_LOG("\nDEBUG --> E2AP : E2 node Config update ack message recevied");
1689 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_successfulOutcome [%d]",\
1690 e2apMsg->choice.successfulOutcome->value.present);
1693 }/* End of switch(successfulOutcome) */
1694 free(e2apMsg->choice.successfulOutcome);
1697 case E2AP_PDU_PR_initiatingMessage:
1699 switch(e2apMsg->choice.initiatingMessage->value.present)
1701 case InitiatingMessageE2__value_PR_RICsubscriptionRequest:
1703 if(procRicSubsReq(e2apMsg) == ROK)
1705 BuildAndSendRicIndication();
1711 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_initiatingMessage [%d]",\
1712 e2apMsg->choice.initiatingMessage->value.present);
1715 }/* End of switch(initiatingMessage) */
1716 free(e2apMsg->choice.initiatingMessage);
1721 DU_LOG("\nERROR --> E2AP : Invalid type of e2apMsg->present [%d]",e2apMsg->present);
1726 }/* End of switch(e2apMsg->present) */
1728 } /* End of E2APMsgHdlr */
1730 /**********************************************************************
1732 **********************************************************************/