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, val);
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 for(int i=0; i< encBufSize; i++)
481 printf("%x",encBuf[i]);
484 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
486 DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
492 FreeE2SetupReq(e2apMsg);
494 }/* End of BuildAndSendE2SetupReq */
496 /*******************************************************************
498 * @brief Builds Ric Request Id
502 * Function : BuildRicRequestId
504 * Functionality: Building the Ric Request Id
506 * @params[in] RICrequestID_t *ricReqId
507 * @return ROK - success
510 * ****************************************************************/
512 uint8_t BuildRicRequestId(RICrequestID_t *ricReqId)
514 if(ricReqId == NULLP)
519 ricReqId->ricRequestorID = 1;
520 ricReqId->ricInstanceID = 1;
524 /*******************************************************************
526 * @brief Fills the mandatory RicAdmitted List Items
530 * Function : fillRicAdmitList
532 * Functionality: Fills the mandatory Ric Admitted List Items
534 * @params[in] RICaction_Admitted_ItemIEs_t *ricAdmitItems
535 * @return ROK - success
538 * ****************************************************************/
540 uint8_t fillRicAdmitList(RICaction_Admitted_ItemIEs_t *ricAdmitItems)
543 if(ricAdmitItems != NULLP)
545 ricAdmitItems->id = ProtocolIE_IDE2_id_RICaction_Admitted_Item;
546 ricAdmitItems->criticality = CriticalityE2_reject;
547 ricAdmitItems->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
548 ricAdmitItems->value.choice.RICaction_Admitted_Item.ricActionID = 1;
556 /*******************************************************************
558 * @brief Builds the mandatory RicAdmitted List Params
562 * Function : BuildRicAdmitList
564 * Functionality: Builds the mandatory Ric Admitted List Params
566 * @params[in] RICaction_Admitted_List_t *admitListPtr
567 * @return ROK - success
570 * ****************************************************************/
572 uint8_t BuildRicAdmitList(RICaction_Admitted_List_t *admitListPtr)
579 if(admitListPtr == NULLP)
581 DU_LOG("\nERROR --> E2AP : Memory allocation for RIC Admit List failed");
586 admitListPtr->list.count = elementCnt;
587 admitListPtr->list.size = elementCnt * sizeof(RICaction_Admitted_ItemIEs_t);
588 DU_ALLOC(admitListPtr->list.array, admitListPtr->list.size);
589 if(admitListPtr->list.array == NULLP)
591 DU_LOG("\nERROR --> E2AP : Memory allocation for RIC Admit List failed");
596 for(idx=0 ; idx<elementCnt ; idx++ )
598 DU_ALLOC(admitListPtr->list.array[idx], sizeof(RICaction_Admitted_ItemIEs_t));
599 if(admitListPtr->list.array[idx] == NULLP)
607 fillRicAdmitList((RICaction_Admitted_ItemIEs_t *)admitListPtr->list.array[idx]);
613 /*******************************************************************
615 * @breif Deallocation of BuildAndSendRicSubscriptionRsp memory
619 * Function : FreeRicSubscriptionRsp
621 * Functionality:Free the RicSubscriptionRsp
623 * @param[in] E2AP_PDU_t *e2apRicMsg
628 ******************************************************************/
629 void FreeRicSubscriptionRsp(E2AP_PDU_t *e2apRicMsg)
631 RICsubscriptionResponse_t *ricSubscriptionRsp= NULLP;
634 RICaction_Admitted_List_t *admitListPtr;
636 if(e2apRicMsg != NULLP)
638 if(e2apRicMsg->choice.successfulOutcome != NULLP)
640 ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
641 if(ricSubscriptionRsp)
643 if(ricSubscriptionRsp->protocolIEs.list.array != NULLP)
645 for(idx=0; idx<ricSubscriptionRsp->protocolIEs.list.count; idx++)
647 if(ricSubscriptionRsp->protocolIEs.list.array[idx] != NULLP)
649 switch(ricSubscriptionRsp->protocolIEs.list.array[idx]->id)
651 case ProtocolIE_IDE2_id_RICrequestID:
654 case ProtocolIE_IDE2_id_RANfunctionID:
657 case ProtocolIE_IDE2_id_RICactions_Admitted:
659 admitListPtr = &ricSubscriptionRsp->protocolIEs.list.\
660 array[idx]->value.choice.RICaction_Admitted_List;
661 if(admitListPtr->list.array != NULLP)
663 for(idx1=0 ; idx1<admitListPtr->list.count; idx1++ )
665 if(admitListPtr->list.array[idx1] != NULLP)
667 DU_FREE(admitListPtr->list.array[idx1],
668 sizeof(RICaction_Admitted_ItemIEs_t));
671 DU_FREE(admitListPtr->list.array, admitListPtr->list.size);
678 DU_FREE(ricSubscriptionRsp->protocolIEs.list.array[idx], \
679 sizeof(RICsubscriptionResponse_IEs_t));
682 DU_FREE(ricSubscriptionRsp->protocolIEs.list.array, \
683 ricSubscriptionRsp->protocolIEs.list.size);
686 DU_FREE(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
688 DU_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
691 /*******************************************************************
693 * @brief Builds and Send the RicSubscriptionRsp
697 * Function : BuildAndSendRicSubscriptionRsp
699 * functionality:Fills the RicSubscriptionRsp
701 * @return ROK - success
704 ******************************************************************/
705 uint8_t FillRicSubscriptionRsp(RICsubscriptionResponse_t *ricSubscriptionRsp )
709 uint8_t elementCnt = 0;
710 uint8_t BuildRicRequestIdret=ROK;
711 uint8_t BuildRicAdmitListret=ROK;
714 ricSubscriptionRsp->protocolIEs.list.count = elementCnt;
715 ricSubscriptionRsp->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionResponse_IEs_t);
716 DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array, \
717 ricSubscriptionRsp->protocolIEs.list.size);
718 if(ricSubscriptionRsp->protocolIEs.list.array == NULLP)
720 DU_LOG("\nERROR --> E2AP : Memory allocation for FillRicSubscriptionRsp failed");
725 for(idx=0; idx<ricSubscriptionRsp->protocolIEs.list.count; idx++)
727 DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array[idx], \
728 sizeof(RICsubscriptionResponse_IEs_t));
729 if(ricSubscriptionRsp->protocolIEs.list.array[idx] == NULLP)
738 ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
739 ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
740 ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
741 RICsubscriptionRequest_IEs__value_PR_RICrequestID;
742 BuildRicRequestIdret =
743 BuildRicRequestId(&ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RICrequestID);
744 if(BuildRicRequestIdret != ROK)
751 ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
752 ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
753 ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
754 RICsubscriptionRequest_IEs__value_PR_RANfunctionID;
755 ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RANfunctionID = 1;
758 ricSubscriptionRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICactions_Admitted;
759 ricSubscriptionRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
760 ricSubscriptionRsp->protocolIEs.list.array[idx]->value.present =\
761 RICsubscriptionResponse_IEs__value_PR_RICaction_Admitted_List;
762 BuildRicAdmitListret =
763 BuildRicAdmitList(&ricSubscriptionRsp->protocolIEs.list.array[idx]->value.choice.RICaction_Admitted_List);
764 if(BuildRicAdmitListret != ROK)
773 /*******************************************************************
775 * @brief Builds and Send the RicSubscriptionRsp
779 * Function : BuildAndSendRicSubscriptionRsp
781 * Functionality:Fills the RicSubscriptionRsp
783 * @return ROK - success
786 ******************************************************************/
788 uint8_t BuildAndSendRicSubscriptionRsp()
791 E2AP_PDU_t *e2apRicMsg = NULLP;
792 RICsubscriptionResponse_t *ricSubscriptionRsp=NULLP;
793 asn_enc_rval_t encRetVal;
794 uint8_t ret = RFAILED;
795 uint8_t FillRicricSubscriptionRspret;
799 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Response\n");
801 DU_ALLOC(e2apRicMsg, sizeof(E2AP_PDU_t));
802 if(e2apRicMsg == NULLP)
804 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
807 e2apRicMsg->present = E2AP_PDU_PR_successfulOutcome;
808 DU_ALLOC(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
809 if(e2apRicMsg->choice.successfulOutcome == NULLP)
811 DU_LOG("\nERROR --> E2AP : Memory allocation for RIC subscription Response failed");
815 e2apRicMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_RICsubscription;
816 e2apRicMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
817 e2apRicMsg->choice.successfulOutcome->value.present = \
818 SuccessfulOutcomeE2__value_PR_RICsubscriptionResponse;
819 ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
821 FillRicricSubscriptionRspret = FillRicSubscriptionRsp(ricSubscriptionRsp);
822 if(FillRicricSubscriptionRspret != ROK)
824 DU_LOG("\nERROR --> E2AP : Memory allocation for RICsubscriptionResponseIE failed");
828 /* Prints the Msg formed */
829 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apRicMsg);
831 memset(encBuf, 0, ENC_BUF_MAX_LEN);
833 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apRicMsg, PrepFinalEncBuf,\
835 if(encRetVal.encoded == ENCODE_FAIL)
837 DU_LOG("\nERROR --> E2AP : Could not encode RIC Subscription Response structure (at %s)\n",\
838 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
843 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC subscription response \n");
844 for(int i=0; i< encBufSize; i++)
846 printf("%x",encBuf[i]);
850 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
852 DU_LOG("\nERROR --> E2AP : Sending RIC Subscription Response failed");
860 FreeRicSubscriptionRsp(e2apRicMsg);
865 /******************************************************************
867 * @brief Deallocation of memory allocated bu aper decoder for e2 setup response
871 * Function : freeAperDecodingOfE2SetupRsp
873 * Functionality: Deallocation of memory allocated bu aper decoder for e2
876 * @params[in] E2setupResponse_t *e2SetRspMsg;
879 * ****************************************************************/
880 void freeAperDecodingOfE2SetupRsp(E2setupResponse_t *e2SetRspMsg)
882 uint8_t arrIdx, e2NodeConfigAddAckListIdx;
883 E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItem;
884 E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAddAckList;
888 if(e2SetRspMsg->protocolIEs.list.array)
890 for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
892 if(e2SetRspMsg->protocolIEs.list.array[arrIdx])
894 switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
896 case ProtocolIE_IDE2_id_TransactionID:
899 case ProtocolIE_IDE2_id_GlobalRIC_ID:
901 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.pLMN_Identity.buf);
902 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID.buf);
906 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
908 e2NodeConfigAddAckList = &e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
909 if(e2NodeConfigAddAckList->list.array )
911 for(e2NodeConfigAddAckListIdx = 0; e2NodeConfigAddAckListIdx< e2NodeConfigAddAckList->list.count; e2NodeConfigAddAckListIdx++)
913 if(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx])
915 e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx];
916 free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
917 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf);
918 free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
919 e2nodeComponentInterfaceTypeF1);
920 free(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx]);
923 free(e2NodeConfigAddAckList->list.array);
928 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]);
931 free(e2SetRspMsg->protocolIEs.list.array);
935 /******************************************************************
937 * @brief Processes E2 Setup Response sent by RIC
941 * Function : procE2SetupRsp
943 * Functionality: Processes E2 Setup Response sent by RIC
945 * @params[in] E2AP_PDU_t ASN decoded E2AP message
946 * @return ROK - success
949 * ****************************************************************/
950 uint8_t procE2SetupRsp(E2AP_PDU_t *e2apMsg)
954 E2setupResponse_t *e2SetRspMsg;
956 DU_LOG("\nINFO --> E2AP : E2 Setup Response received");
957 duCb.e2Status = TRUE; //Set E2 status as true
958 e2SetRspMsg = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse;
960 for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
962 switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
964 case ProtocolIE_IDE2_id_TransactionID:
967 case ProtocolIE_IDE2_id_GlobalRIC_ID:
969 /* To store the Ric Id Params */
970 recvBufLen = sizeof(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value\
971 .choice.GlobalRIC_ID.pLMN_Identity.size);
972 e2apMsgDb.plmn = NULLP;
973 DU_ALLOC(e2apMsgDb.plmn, recvBufLen);
976 memcpy(e2apMsgDb.plmn, e2SetRspMsg->protocolIEs.list.array[arrIdx]\
977 ->value.choice.GlobalRIC_ID.pLMN_Identity.buf, recvBufLen);
979 bitStringToInt(&e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID, &e2apMsgDb.ricId);
980 /*TODO : e2apMsgDb.plmn memory to be deallocated after the usage */
984 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
988 DU_LOG("\nERROR --> E2AP : Invalid IE received in E2SetupRsp:%ld",
989 e2SetRspMsg->protocolIEs.list.array[arrIdx]->id);
993 freeAperDecodingOfE2SetupRsp(e2SetRspMsg);
994 BuildAndSendE2NodeConfigUpdate();
998 /******************************************************************
1000 * @brief Processes RIC Subscription Req sent by RIC
1004 * Function : procRicSubsReq
1006 * Functionality: Processes E2 Setup Response sent by CU
1008 * @params[in] E2AP_PDU_t ASN decoded E2AP message
1009 * @return ROK - success
1012 * ****************************************************************/
1014 uint8_t procRicSubsReq(E2AP_PDU_t *e2apMsg)
1019 uint32_t recvBufLen;
1020 RICsubscriptionRequest_t *ricSubsReq;
1021 RICaction_ToBeSetup_ItemIEs_t *actionItem;
1023 DU_LOG("\nINFO --> E2AP : RIC Subscription request received");
1024 ricSubsReq = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
1026 for(idx=0; idx<ricSubsReq->protocolIEs.list.count; idx++)
1028 if(ricSubsReq->protocolIEs.list.array[idx])
1030 switch(ricSubsReq->protocolIEs.list.array[idx]->id)
1032 case ProtocolIE_IDE2_id_RICrequestID:
1034 e2apMsgDb.ricReqId = ricSubsReq->protocolIEs.list.array[idx]->\
1035 value.choice.RICrequestID.ricRequestorID;
1036 e2apMsgDb.ricInstanceId = ricSubsReq->protocolIEs.list.array[idx]-> \
1037 value.choice.RICrequestID.ricInstanceID;
1040 case ProtocolIE_IDE2_id_RANfunctionID:
1042 e2apMsgDb.ranFuncId = ricSubsReq->protocolIEs.list.array[idx]-> \
1043 value.choice.RANfunctionID;
1046 case ProtocolIE_IDE2_id_RICsubscriptionDetails:
1048 recvBufLen = sizeof(ricSubsReq->protocolIEs.list.array[idx]->value\
1049 .choice.RICsubscriptionDetails.ricEventTriggerDefinition.size);
1050 e2apMsgDb.ricEventTrigger = NULLP;
1051 DU_ALLOC(e2apMsgDb.ricEventTrigger, recvBufLen);
1052 /*TODO : e2apMsgDb.ricEventTrigger memory to be deallocated after the usage */
1053 if(e2apMsgDb.ricEventTrigger)
1055 memcpy(e2apMsgDb.ricEventTrigger, ricSubsReq->protocolIEs.list.array[idx]\
1056 ->value.choice.RICsubscriptionDetails.ricEventTriggerDefinition.buf, \
1058 free(ricSubsReq->protocolIEs.list.array[idx]->value.choice.\
1059 RICsubscriptionDetails.ricEventTriggerDefinition.buf);
1061 if(ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List.\
1064 actionItem =(RICaction_ToBeSetup_ItemIEs_t *)ricSubsReq->protocolIEs.list\
1065 .array[idx]->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List\
1068 for(ied = 0; ied < ricSubsReq->protocolIEs.list.array[idx]->value.choice.\
1069 RICsubscriptionDetails.ricAction_ToBeSetup_List.list.count; ied++)
1071 switch(actionItem->id)
1073 case ProtocolIE_IDE2_id_RICaction_ToBeSetup_Item:
1075 e2apMsgDb.ricActionId = actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionID;
1076 e2apMsgDb.ricActionType = actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionType;
1080 DU_LOG("\nERROR --> E2AP : Invalid IE received in RicSetupLst:%ld",actionItem->id);
1085 free(ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails.ricAction_ToBeSetup_List.\
1092 DU_LOG("\nERROR --> E2AP : Invalid IE received in RIC SubsReq:%ld",
1093 ricSubsReq->protocolIEs.list.array[idx]->id);
1096 free(ricSubsReq->protocolIEs.list.array[idx]);
1099 free(ricSubsReq->protocolIEs.list.array);
1100 ret = BuildAndSendRicSubscriptionRsp();
1105 /*******************************************************************
1107 * @brief Free the RicIndication Message
1111 * Function : FreeRicIndication
1113 * Functionality: Free the RicIndication Message
1118 ******************************************************************/
1119 void FreeRicIndication(E2AP_PDU_t *e2apMsg)
1122 RICindication_t *ricIndicationMsg= NULLP;
1125 if(e2apMsg != NULLP)
1127 if(e2apMsg->choice.initiatingMessage != NULLP)
1129 ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
1130 if(ricIndicationMsg!= NULLP)
1132 if(ricIndicationMsg->protocolIEs.list.array != NULLP)
1134 for(idx=0; idx<ricIndicationMsg->protocolIEs.list.count; idx++)
1136 if(ricIndicationMsg->protocolIEs.list.array[idx] != NULLP)
1138 switch(ricIndicationMsg->protocolIEs.list.array[idx]->id)
1140 case ProtocolIE_IDE2_id_RICrequestID:
1143 case ProtocolIE_IDE2_id_RANfunctionID:
1146 case ProtocolIE_IDE2_id_RICactionID:
1149 case ProtocolIE_IDE2_id_RICindicationType:
1152 case ProtocolIE_IDE2_id_RICindicationHeader:
1154 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf,\
1155 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
1158 case ProtocolIE_IDE2_id_RICindicationMessage:
1160 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf,\
1161 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
1167 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx],sizeof(RICindication_IEs_t));
1170 DU_FREE(ricIndicationMsg->protocolIEs.list.array,ricIndicationMsg->protocolIEs.list.size);
1173 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1175 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
1178 /*******************************************************************
1180 * brief Fill the RicIndication Message
1184 * Function : FillRicIndication
1186 * Functionality:Fills the RicIndication Message
1188 * @return ROK - success
1191 ******************************************************************/
1192 uint8_t FillRicIndication(RICindication_t *ricIndicationMsg)
1194 uint8_t elementCnt=0;
1199 ricIndicationMsg->protocolIEs.list.count = elementCnt;
1200 ricIndicationMsg->protocolIEs.list.size = elementCnt * sizeof(RICindication_t);
1201 /* Initialize the Ric Indication members */
1202 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array, \
1203 ricIndicationMsg->protocolIEs.list.size);
1204 if(ricIndicationMsg->protocolIEs.list.array == NULLP)
1206 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
1211 for(idx=0; idx<elementCnt; idx++)
1213 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx],\
1214 sizeof(RICindication_IEs_t));
1215 if(ricIndicationMsg->protocolIEs.list.array[idx] == NULLP)
1217 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
1225 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
1226 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1227 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1228 RICindication_IEs__value_PR_RICrequestID;
1229 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID =\
1231 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID =\
1232 e2apMsgDb.ricInstanceId;
1235 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
1236 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1237 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1238 RICindication_IEs__value_PR_RANfunctionID;
1239 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RANfunctionID =
1240 e2apMsgDb.ranFuncId;
1243 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICactionID;
1244 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1245 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1246 RICindication_IEs__value_PR_RICactionID;
1247 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICactionID =
1248 e2apMsgDb.ricActionId;
1251 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationType;
1252 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1253 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1254 RICindication_IEs__value_PR_RICindicationType;
1255 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationType =
1256 e2apMsgDb.ricActionType;
1259 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationHeader;
1260 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1261 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1262 RICindication_IEs__value_PR_RICindicationHeader;
1263 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size = 3 *
1265 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf ,\
1266 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
1267 if(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf == NULLP)
1269 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
1274 buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
1275 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf);
1277 /* TO BE CHANGED: RIC INDICATION DATA */
1278 /* For now filling a dummy octect data, need to tested with PRBs*/
1279 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationMessage;
1280 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1281 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = \
1282 RICindication_IEs__value_PR_RICindicationMessage;
1283 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size = 3 *
1285 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf ,\
1286 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
1287 if(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf == NULLP)
1289 DU_LOG("\nERROR --> E2AP : Memory allocation for RICindicationIEs failed");
1294 buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
1295 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf);
1303 /*******************************************************************
1305 * @brief Builds and Send the RicIndication Message
1309 * Function : BuildAndSendRicIndication
1311 * Functionality:Fills the RicIndication Message
1313 * @return ROK - success
1316 ******************************************************************/
1318 uint8_t BuildAndSendRicIndication()
1320 E2AP_PDU_t *e2apMsg = NULLP;
1321 RICindication_t *ricIndicationMsg=NULLP;
1322 asn_enc_rval_t encRetVal; /* Encoder return value */
1323 uint8_t ret = RFAILED;
1324 uint8_t FillRicIndicationret = ROK;
1328 DU_LOG("\nINFO --> E2AP : Building RIC Indication Message\n");
1330 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
1331 if(e2apMsg == NULLP)
1333 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1337 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
1338 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1339 if(e2apMsg->choice.initiatingMessage == NULLP)
1341 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1344 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICindication;
1345 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
1346 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICindication;
1348 ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
1350 FillRicIndicationret = FillRicIndication(ricIndicationMsg);
1351 if(FillRicIndicationret != ROK)
1355 /* Prints the Msg formed */
1356 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
1357 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1359 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
1361 if(encRetVal.encoded == ENCODE_FAIL)
1363 DU_LOG("\nERROR --> E2AP : Could not encode RIC Indication Message (at %s)\n",\
1364 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1369 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC Indication Message \n");
1370 for(int i=0; i< encBufSize; i++)
1372 printf("%x",encBuf[i]);
1376 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
1378 DU_LOG("\nINFO --> E2AP : Sending RIC Indication Message");
1384 FreeRicIndication(e2apMsg);
1388 /*******************************************************************
1390 * @brief Sends E2 msg over SCTP
1394 * Function : SendE2APMsg
1396 * Functionality: Sends E2 msg over SCTP
1398 * @params[in] Region region
1400 * @return ROK - success
1403 * ****************************************************************/
1405 uint8_t SendE2APMsg(Region region, Pool pool)
1409 if(ODU_GET_MSG_BUF(region, pool, &mBuf) == ROK)
1411 if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
1413 ODU_PRINT_MSG(mBuf, 0,0);
1415 if(sctpSend(mBuf, E2_INTERFACE) != ROK)
1417 DU_LOG("\nERROR --> E2AP : SCTP Send for E2 failed");
1418 ODU_PUT_MSG_BUF(mBuf);
1424 DU_LOG("\nERROR --> E2AP : ODU_ADD_POST_MSG_MULT failed");
1425 ODU_PUT_MSG_BUF(mBuf);
1428 ODU_PUT_MSG_BUF(mBuf);
1432 DU_LOG("\nERROR --> E2AP : Failed to allocate memory");
1439 /*******************************************************************
1441 * @brief Deallocate the memory allocated for E2nodeConfigurationUpdate msg
1445 * Function : FreeE2NodeConfigUpdate
1448 * - freeing the memory allocated for E2nodeConfigurationUpdate
1450 * @params[in] E2AP_PDU_t *e2apMsg
1451 * @return ROK - success
1454 * ****************************************************************/
1455 void FreeE2NodeConfigUpdate(E2AP_PDU_t *e2apMsg)
1458 E2nodeConfigurationUpdate_t *e2NodeConfigUpdate;
1460 if(e2apMsg != NULLP)
1462 if(e2apMsg->choice.initiatingMessage != NULLP)
1464 e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
1465 if(e2NodeConfigUpdate->protocolIEs.list.array != NULLP)
1467 for(arrIdx = 0; arrIdx < e2NodeConfigUpdate->protocolIEs.list.count; arrIdx++)
1469 DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_t));
1471 DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array, e2NodeConfigUpdate->protocolIEs.list.size);
1473 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1475 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
1479 /*******************************************************************
1481 * @brief Buld and send the E2 node config update msg
1485 * Function : BuildAndSendE2NodeConfigUpdate
1488 * - Buld and send the E2 node config update msg
1491 * @return ROK - success
1494 * ****************************************************************/
1496 uint8_t BuildAndSendE2NodeConfigUpdate()
1498 uint8_t arrIdx = 0,elementCnt = 1;
1500 E2AP_PDU_t *e2apMsg = NULLP;
1501 E2nodeConfigurationUpdate_t *e2NodeConfigUpdate = NULLP;
1502 asn_enc_rval_t encRetVal; /* Encoder return value */
1504 DU_LOG("\nINFO --> E2AP : Building E2 Node config update\n");
1507 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
1508 if(e2apMsg == NULLP)
1510 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1513 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
1514 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1515 if(e2apMsg->choice.initiatingMessage == NULLP)
1517 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1518 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
1521 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
1522 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2nodeConfigurationUpdate;
1523 e2apMsg->choice.initiatingMessage->value.present = \
1524 InitiatingMessageE2__value_PR_E2nodeConfigurationUpdate;
1525 e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
1527 e2NodeConfigUpdate->protocolIEs.list.count = elementCnt;
1528 e2NodeConfigUpdate->protocolIEs.list.size = elementCnt * sizeof(E2nodeConfigurationUpdate_IEs_t*);
1529 /* Initialize the Ric Indication members */
1530 DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array, \
1531 e2NodeConfigUpdate->protocolIEs.list.size);
1532 if(e2NodeConfigUpdate->protocolIEs.list.array == NULLP)
1534 DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed");
1538 for(arrIdx =0; arrIdx<elementCnt; arrIdx++)
1540 DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
1541 if(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx] == NULLP)
1544 DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed");
1551 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
1552 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1553 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_TransactionID;
1554 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = TRANS_ID;
1557 /* Prints the Msg formed */
1558 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
1560 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1562 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
1564 if(encRetVal.encoded == ENCODE_FAIL)
1566 DU_LOG("\nERROR --> E2AP : Could not encode E2nodeConfigurationUpdate structure (at %s)\n",\
1567 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1572 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2nodeConfigurationUpdate\n");
1573 for(int i=0; i< encBufSize; i++)
1575 printf("%x",encBuf[i]);
1578 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL) != ROK)
1580 DU_LOG("\nERROR --> E2AP : Sending E2 node config update failed");
1587 FreeE2NodeConfigUpdate(e2apMsg);
1591 /*******************************************************************
1593 * @brief Handles received E2AP message and sends back response
1597 * Function : E2APMsgHdlr
1600 * - Decodes received E2AP control message
1601 * - Prepares response message, encodes and sends to SCTP
1604 * @return ROK - success
1607 * ****************************************************************/
1608 void E2APMsgHdlr(Buffer *mBuf)
1611 char *recvBuf = NULLP;
1613 MsgLen recvBufLen =0;
1614 E2AP_PDU_t *e2apMsg = NULLP;
1615 asn_dec_rval_t rval ={0}; /* Decoder return value */
1616 E2AP_PDU_t e2apasnmsg={0} ;
1618 DU_LOG("\nDEBUG --> E2AP : Received E2AP message buffer");
1619 ODU_PRINT_MSG(mBuf, 0,0);
1621 /* Copy mBuf into char array to decode it */
1622 ODU_GET_MSG_LEN(mBuf, &recvBufLen);
1623 DU_ALLOC(recvBuf, (Size)recvBufLen);
1625 if(recvBuf == NULLP)
1627 DU_LOG("\nERROR --> E2AP : Memory allocation failed");
1630 if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, ©Cnt) != ROK)
1632 DU_LOG("\nERROR --> E2AP : Failed while copying %d", copyCnt);
1636 printf("\nDEBUG --> E2AP : Received flat buffer to be decoded : ");
1637 for(i=0; i< recvBufLen; i++)
1639 printf("%x",recvBuf[i]);
1642 /* Decoding flat buffer into E2AP messsage */
1643 e2apMsg = &e2apasnmsg;
1644 memset(e2apMsg, 0, sizeof(E2AP_PDU_t));
1646 rval = aper_decode(0, &asn_DEF_E2AP_PDU, (void **)&e2apMsg, recvBuf, recvBufLen, 0, 0);
1647 DU_FREE(recvBuf, (Size)recvBufLen);
1649 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
1651 DU_LOG("\nERROR --> E2AP : ASN decode failed");
1655 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
1657 switch(e2apMsg->present)
1659 case E2AP_PDU_PR_successfulOutcome:
1661 switch(e2apMsg->choice.successfulOutcome->value.present)
1663 case SuccessfulOutcomeE2__value_PR_E2setupResponse:
1667 DU_LOG("\nDEBUG --> E2AP : Store E2 setup response Params");
1668 procE2SetupRsp(e2apMsg);
1672 case SuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateAcknowledge:
1674 DU_LOG("\nDEBUG --> E2AP : E2 node Config update ack message recevied");
1679 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_successfulOutcome [%d]",\
1680 e2apMsg->choice.successfulOutcome->value.present);
1683 }/* End of switch(successfulOutcome) */
1684 free(e2apMsg->choice.successfulOutcome);
1687 case E2AP_PDU_PR_initiatingMessage:
1689 switch(e2apMsg->choice.initiatingMessage->value.present)
1691 case InitiatingMessageE2__value_PR_RICsubscriptionRequest:
1693 if(procRicSubsReq(e2apMsg) == ROK)
1695 BuildAndSendRicIndication();
1701 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_initiatingMessage [%d]",\
1702 e2apMsg->choice.initiatingMessage->value.present);
1705 }/* End of switch(initiatingMessage) */
1706 free(e2apMsg->choice.initiatingMessage);
1711 DU_LOG("\nERROR --> E2AP : Invalid type of e2apMsg->present [%d]",e2apMsg->present);
1716 }/* End of switch(e2apMsg->present) */
1718 } /* End of E2APMsgHdlr */
1720 /**********************************************************************
1722 **********************************************************************/