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 *******************************************************************************/
19 /* This file contains E2AP message handler functions */
20 #include "common_def.h"
21 #include "OCTET_STRING.h"
22 #include "BIT_STRING.h"
23 #include "odu_common_codec.h"
24 #include "ric_stub_sctp.h"
26 #include "ric_e2ap_msg_hdl.h"
27 #include "GlobalE2node-gNB-ID.h"
28 #include "ProtocolIE-FieldE2.h"
29 #include "InitiatingMessageE2.h"
30 #include "SuccessfulOutcomeE2.h"
31 #include "UnsuccessfulOutcomeE2.h"
34 #include "E2nodeComponentInterfaceF1.h"
35 #include "E2SM-KPM-RANfunction-Description.h"
36 #include "RANfunction-Name.h"
37 #include "RIC-EventTriggerStyle-Item.h"
38 #include "RIC-ReportStyle-Item.h"
39 #include "MeasurementInfo-Action-Item.h"
40 #include "MeasurementInfoItem.h"
41 #include "E2SM-KPM-ActionDefinition-Format1.h"
42 #include "E2SM-KPM-ActionDefinition.h"
43 #include "E2SM-KPM-EventTriggerDefinition-Format1.h"
44 #include "E2SM-KPM-EventTriggerDefinition.h"
47 /*******************************************************************
49 * @brief Assigns new transaction id to RIC initiated procedure
53 * Function : assignTransactionId
55 * Functionality: Assigns new transaction id to a RIC initiated
58 * @params[in] Region region
60 * @return ROK - success
63 * ****************************************************************/
65 uint8_t assignTransactionId(DuDb *duDb)
67 uint8_t currTransId = duDb->ricTransIdCounter;
69 /* Update to next valid value */
70 duDb->ricTransIdCounter++;
71 if(duDb->ricTransIdCounter == MAX_NUM_TRANSACTION)
72 duDb->ricTransIdCounter = 0;
77 /*******************************************************************
79 * @brief Sends E2 msg over SCTP
83 * Function : SendE2APMsg
85 * Functionality: Sends E2 msg over SCTP
87 * @params[in] Region region
89 * @return ROK - success
92 * ****************************************************************/
94 uint8_t SendE2APMsg(Region region, Pool pool, uint32_t duId)
98 if(ODU_GET_MSG_BUF(region, pool, &mBuf) == ROK)
100 if(ODU_ADD_POST_MSG_MULT((Data *)encBuf, encBufSize, mBuf) == ROK)
102 ODU_PRINT_MSG(mBuf, 0,0);
104 if(sctpSend(duId, mBuf) != ROK)
106 DU_LOG("\nERROR --> E2AP : SCTP Send for E2 failed");
107 ODU_PUT_MSG_BUF(mBuf);
113 DU_LOG("\nERROR --> E2AP : ODU_ADD_POST_MSG_MULT failed");
114 ODU_PUT_MSG_BUF(mBuf);
117 ODU_PUT_MSG_BUF(mBuf);
121 DU_LOG("\nERROR --> E2AP : Failed to allocate memory");
128 /*******************************************************************
130 * @brief deallocate memory allocated in E2 Node Config Update Failure
134 * Function : FreeE2ConfigUpdateFail
136 * Functionality: deallocate memory allocated in E2 Node Config Update Failure
138 * @params[in] E2AP_PDU_t *e2apMsg
141 * ****************************************************************/
143 void FreeE2ConfigUpdateFail(E2AP_PDU_t *e2apMsg)
146 E2nodeConfigurationUpdateFailure_t *e2NodeCfgUpdFail=NULL;
150 if(e2apMsg->choice.unsuccessfulOutcome)
152 e2NodeCfgUpdFail = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2nodeConfigurationUpdateFailure;
153 if(e2NodeCfgUpdFail->protocolIEs.list.array)
155 for(arrIdx=0; arrIdx<e2NodeCfgUpdFail->protocolIEs.list.count; arrIdx++)
157 RIC_FREE(e2NodeCfgUpdFail->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdateFailure_IEs_t));
159 RIC_FREE(e2NodeCfgUpdFail->protocolIEs.list.array, e2NodeCfgUpdFail->protocolIEs.list.size);
161 RIC_FREE(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
163 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
167 /*******************************************************************
169 * @brief Buld and send the E2 Node Config Update failure
173 * Function : BuildAndSendE2NodeConfigUpdateFailure
176 * - Buld and send the E2 Node Config Update failure
177 * @return ROK - success
180 * ****************************************************************/
182 uint8_t BuildAndSendE2NodeConfigUpdateFailure(uint32_t duId, uint8_t transId, uint8_t causeInfo, uint8_t causeReason)
184 E2AP_PDU_t *e2apMsg = NULL;
185 asn_enc_rval_t encRetVal;
187 uint8_t elementCnt=0;
188 bool memAllocFailed = false;
189 E2nodeConfigurationUpdateFailure_t *e2NodeCfgUpdateFail=NULL;
191 DU_LOG("\nINFO --> E2AP : Building E2 Node Config Update failure\n");
194 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
197 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
200 e2apMsg->present = E2AP_PDU_PR_unsuccessfulOutcome;
201 RIC_ALLOC(e2apMsg->choice.unsuccessfulOutcome , sizeof(struct UnsuccessfulOutcomeE2));
202 if(e2apMsg->choice.unsuccessfulOutcome == NULLP)
204 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
208 e2apMsg->choice.unsuccessfulOutcome->procedureCode = ProcedureCodeE2_id_E2nodeConfigurationUpdate;
209 e2apMsg->choice.unsuccessfulOutcome->criticality = CriticalityE2_reject;
210 e2apMsg->choice.unsuccessfulOutcome->value.present = UnsuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateFailure;
211 e2NodeCfgUpdateFail = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2nodeConfigurationUpdateFailure;
214 e2NodeCfgUpdateFail->protocolIEs.list.count = elementCnt;
215 e2NodeCfgUpdateFail->protocolIEs.list.size = elementCnt * sizeof(struct E2nodeConfigurationUpdateFailure_IEs *);
217 RIC_ALLOC(e2NodeCfgUpdateFail->protocolIEs.list.array, e2NodeCfgUpdateFail->protocolIEs.list.size);
218 if(e2NodeCfgUpdateFail->protocolIEs.list.array == NULLP)
220 DU_LOG("\nERROR --> E2AP : Memory allocation for E2 node config update failure array failed");
224 for(arrIdx=0; arrIdx<elementCnt; arrIdx++)
226 RIC_ALLOC(e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx], sizeof(struct E2nodeConfigurationUpdateFailure_IEs));
227 if(e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx] == NULLP)
229 DU_LOG("\nERROR --> E2AP : Memory allocation for E2 node config update failure IEs failed");
230 memAllocFailed = true;
235 if(memAllocFailed == true)
242 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
243 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
244 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->value.present = E2setupFailureIEs__value_PR_TransactionID;
245 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
248 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_CauseE2;
249 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
250 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->value.present = E2setupFailureIEs__value_PR_CauseE2;
251 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->value.choice.CauseE2.present = causeInfo;
252 if(causeInfo == CauseE2_PR_e2Node)
253 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->value.choice.CauseE2.choice.e2Node = causeReason;
255 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->value.choice.CauseE2.choice.misc = causeReason;
258 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TimeToWaitE2;
259 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_ignore;
260 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->value.present = E2setupFailureIEs__value_PR_TimeToWaitE2;
261 e2NodeCfgUpdateFail->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2 = TimeToWaitE2_v5s;
263 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
264 memset(encBuf, 0, ENC_BUF_MAX_LEN);
266 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
268 /* Check encode results */
269 if(encRetVal.encoded == ENCODE_FAIL)
271 DU_LOG("\nERROR --> E2AP : Could not encode E2 Node Config Update failure structure (at %s)\n",\
272 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
277 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Node Config Update Failure\n");
278 for(int i=0; i< encBufSize; i++)
280 DU_LOG("%x",encBuf[i]);
284 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
286 DU_LOG("\nERROR --> E2AP : Sending E2 Node Config Update Failure failed");
292 FreeE2ConfigUpdateFail(e2apMsg);
296 /*******************************************************************
298 * @brief process the E2 node configuration update
302 * Function : ProcE2NodeConfigUpdate
304 * Functionality: Process E2 node configuration update
306 * @return ROK - success
309 ******************************************************************/
311 void ProcE2NodeConfigUpdate(uint32_t duId, E2nodeConfigurationUpdate_t *e2NodeConfigUpdate)
313 uint8_t ieIdx = 0, duIdx = 0;
314 uint8_t transId = 0, e2NodeUpdateListIdx=0;
316 E2nodeComponentConfigUpdate_List_t *e2NodeUpdateList=NULLP;
317 E2nodeComponentConfigUpdate_ItemIEs_t *e2NodeUpdateItemIe=NULLP;
318 E2nodeComponentConfigUpdate_Item_t *e2NodeUpdateItem =NULLP;
320 if(e2NodeConfigUpdate)
322 if(e2NodeConfigUpdate->protocolIEs.list.array)
324 for(ieIdx=0; ieIdx < e2NodeConfigUpdate->protocolIEs.list.count; ieIdx++)
326 if(e2NodeConfigUpdate->protocolIEs.list.array[ieIdx])
328 switch(e2NodeConfigUpdate->protocolIEs.list.array[ieIdx]->id)
330 case ProtocolIE_IDE2_id_TransactionID:
331 transId = e2NodeConfigUpdate->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
336 /*TODO - Other IEs will be handling in next gerrit*/
346 /*******************************************************************
348 * @brief Builds Global RIC Id Params
352 * Function : BuildGlobalRicId
354 * Functionality: Building the Plmn and ric id
356 * @params[in] GlobalRIC_ID_t *ricId
357 * @return ROK - success
360 * ****************************************************************/
362 uint8_t BuildGlobalRicId(GlobalRIC_ID_t *ricId)
365 uint8_t byteSize = 3;
369 ricId->pLMN_Identity.size = byteSize * sizeof(uint8_t);
370 RIC_ALLOC(ricId->pLMN_Identity.buf, ricId->pLMN_Identity.size);
371 buildPlmnId(ricCb.ricCfgParams.plmn , ricId->pLMN_Identity.buf);
373 ricId->ric_ID.size = byteSize * sizeof(uint8_t);
374 RIC_ALLOC(ricId->ric_ID.buf, ricId->ric_ID.size);
375 fillBitString(&ricId->ric_ID, unused, byteSize, ricVal);
380 /*******************************************************************
382 * @brief deallocate the memory allocated in E2SetupResponse
386 * Function : FreeE2SetupRsp
388 * Functionality: deallocate the memory allocated in E2SetupResponse
390 * @params[in] E2AP_PDU_t *e2apMsg
393 * ****************************************************************/
394 void FreeE2SetupRsp(E2AP_PDU_t *e2apMsg)
396 uint8_t arrIdx = 0, e2NodeConfigIdx=0, ranFuncIdx=0;
397 RANfunctionsID_List_t *ranFuncAcceptedList=NULL;
398 E2setupResponse_t *e2SetupRsp=NULL;
399 E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItemIe=NULL;
400 E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAdditionAckList=NULL;
401 E2nodeComponentInterfaceF1_t *f1InterfaceInfo=NULL;
405 if(e2apMsg->choice.successfulOutcome)
407 e2SetupRsp = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse;
408 if(e2SetupRsp->protocolIEs.list.array)
410 for(arrIdx=0; arrIdx<e2SetupRsp->protocolIEs.list.count; arrIdx++)
412 switch(e2SetupRsp->protocolIEs.list.array[arrIdx]->id)
414 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
416 ranFuncAcceptedList= &e2SetupRsp->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
417 if(ranFuncAcceptedList->list.array)
419 for(ranFuncIdx=0;ranFuncIdx<ranFuncAcceptedList->list.count; ranFuncIdx++)
421 if(ranFuncAcceptedList->list.array[ranFuncIdx])
423 RIC_FREE(ranFuncAcceptedList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
426 RIC_FREE(ranFuncAcceptedList->list.array, ranFuncAcceptedList->list.size);
430 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
432 e2NodeConfigAdditionAckList =&e2SetupRsp->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
433 if(e2NodeConfigAdditionAckList->list.count)
435 for(e2NodeConfigIdx=0; e2NodeConfigIdx<e2NodeConfigAdditionAckList->list.count; e2NodeConfigIdx++)
437 e2NodeAddAckItemIe = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAdditionAckList->list.array[e2NodeConfigIdx];
438 if(e2NodeAddAckItemIe)
440 f1InterfaceInfo = e2NodeAddAckItemIe->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1;
443 RIC_FREE(f1InterfaceInfo->gNB_DU_ID.buf, f1InterfaceInfo->gNB_DU_ID.size);
444 RIC_FREE(f1InterfaceInfo, sizeof(E2nodeComponentInterfaceF1_t));
446 RIC_FREE(e2NodeAddAckItemIe, sizeof(E2nodeComponentConfigAdditionAck_ItemIEs_t));
449 RIC_FREE(e2NodeConfigAdditionAckList->list.array, e2NodeConfigAdditionAckList->list.size);
454 RIC_FREE(e2SetupRsp->protocolIEs.list.array[arrIdx], sizeof(E2setupResponseIEs_t));
456 RIC_FREE(e2SetupRsp->protocolIEs.list.array, e2SetupRsp->protocolIEs.list.size);
458 RIC_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
460 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
464 /*******************************************************************
466 * @brief Build E2node Component config addition ack list
470 * Function : BuildE2nodeComponentConfigAdditionAck
472 * Functionality: deallocate the memory allocated in E2SetupResponse
474 * @params[in] E2nodeComponentConfigAdditionAck_List_t
475 * *e2NodeConfigAdditionAckList
477 * @return ROK - success
479 * ****************************************************************/
481 uint8_t BuildE2nodeComponentConfigAdditionAck(E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAdditionAckList, DuDb *duDb)
484 E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItem;
486 e2NodeConfigAdditionAckList->list.count = 1;
487 e2NodeConfigAdditionAckList->list.size = e2NodeConfigAdditionAckList->list.count * sizeof(E2nodeComponentConfigAdditionAck_ItemIEs_t*);
488 RIC_ALLOC(e2NodeConfigAdditionAckList->list.array, e2NodeConfigAdditionAckList->list.size);
489 if(e2NodeConfigAdditionAckList->list.array == NULLP)
491 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2nodeComponentConfigAdditionAck %d",__LINE__);
495 for(arrIdx = 0; arrIdx< e2NodeConfigAdditionAckList->list.count; arrIdx++)
497 RIC_ALLOC(e2NodeConfigAdditionAckList->list.array[arrIdx], sizeof(E2nodeComponentConfigAdditionAck_ItemIEs_t));
498 if(e2NodeConfigAdditionAckList->list.array[arrIdx] == NULLP)
500 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2nodeComponentConfigAdditionAck %d",__LINE__);
504 e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAdditionAckList->list.array[0];
505 e2NodeAddAckItem->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck_Item;
506 e2NodeAddAckItem->criticality = CriticalityE2_reject;
507 e2NodeAddAckItem->value.present = E2nodeComponentConfigAdditionAck_ItemIEs__value_PR_E2nodeComponentConfigAdditionAck_Item;
508 e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentInterfaceType = duDb->e2NodeComponent.interfaceType;
510 /* >E2 Node Component ID */
511 e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.present = E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1;
512 RIC_ALLOC(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\
513 sizeof(E2nodeComponentInterfaceF1_t));
514 if(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1 == NULLP)
516 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2nodeComponentConfigAdditionAck %d",__LINE__);
519 e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size = sizeof(uint8_t);
520 RIC_ALLOC(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
521 e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
523 if(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf == NULLP)
525 DU_LOG("\nERROR -->list. E2AP: Memory allocation failed for BuildE2nodeComponentConfigAdditionAck %d",__LINE__);
528 e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[0] = duDb->e2NodeComponent.componentId;
530 /* >E2 Node Component Configuration Acknowledge*/
531 e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentConfigurationAck.updateOutcome = \
532 E2nodeComponentConfigurationAck__updateOutcome_success;
537 /*******************************************************************
539 * @brief Build RAN function accepted list
543 * Function : BuildRanFunctionAcceptedList
545 * Functionality: Build RAN function accepted list
546 * ->For ProcedureCodeE2_id_E2setup or ProcedureCodeE2_id_RICserviceQuery
547 * we add all the RAN Function list which is present in RIC database.
548 * ->For any other procedures, we just fill the RAN functions whose ID
549 * is present in the recvList
553 * Count of ran functions to be accepted in the list
554 * Received list of RAN functions
558 * @return ROK - success
560 * ****************************************************************/
562 uint8_t BuildRanFunctionAcceptedList(DuDb *duDb, uint8_t count, RanFunction *ranFunAcceptedList, RANfunctionsID_List_t *ranFuncAcceptedList, uint8_t procedureCode)
564 uint8_t ranFuncIdx = 0;
565 RANfunctionID_ItemIEs_t *ranFuncAcceptedItemIe=NULL;
567 /* For ProcedureCodeE2_id_E2setup and ProcedureCodeE2_id_RICserviceQuery,
568 * the number of RAN function list items is equal to the number of
569 * ran function entries stored in the database.
570 * For any other procedure, the RAN function list count is equal
571 * to the count of ran functions obtained from the function's caller */
573 if((procedureCode == ProcedureCodeE2_id_RICserviceQuery)||(procedureCode == ProcedureCodeE2_id_E2setup))
574 ranFuncAcceptedList->list.count = duDb->numOfRanFunction;
576 ranFuncAcceptedList->list.count = count;
578 ranFuncAcceptedList->list.size = ranFuncAcceptedList->list.count*sizeof(RANfunctionID_ItemIEs_t*);
579 RIC_ALLOC(ranFuncAcceptedList->list.array, ranFuncAcceptedList->list.size);
580 if(ranFuncAcceptedList->list.array)
582 for(ranFuncIdx = 0; ranFuncIdx< ranFuncAcceptedList->list.count; ranFuncIdx++)
584 RIC_ALLOC(ranFuncAcceptedList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
585 if(ranFuncAcceptedList->list.array[ranFuncIdx] == NULLP)
587 DU_LOG("\nERROR --> E2AP : Memory allocation for RAN function added list array item");
590 ranFuncAcceptedItemIe = (RANfunctionID_ItemIEs_t*)ranFuncAcceptedList->list.array[ranFuncIdx];
591 ranFuncAcceptedItemIe->id = ProtocolIE_IDE2_id_RANfunctionID_Item;
592 ranFuncAcceptedItemIe->criticality= CriticalityE2_ignore;
593 ranFuncAcceptedItemIe->value.present = RANfunctionID_ItemIEs__value_PR_RANfunctionID_Item;
594 if((procedureCode == ProcedureCodeE2_id_RICserviceQuery)||(procedureCode == ProcedureCodeE2_id_E2setup))
596 /* filling the RAN function information with the help of DuDb */
597 ranFuncAcceptedItemIe->value.choice.RANfunctionID_Item.ranFunctionID = duDb->ranFunction[ranFuncIdx].id;
598 ranFuncAcceptedItemIe->value.choice.RANfunctionID_Item.ranFunctionRevision= duDb->ranFunction[ranFuncIdx].revisionCounter;
602 /* filling the the RAN function information with the help received list of RAN functions */
603 ranFuncAcceptedItemIe->value.choice.RANfunctionID_Item.ranFunctionID = ranFunAcceptedList[ranFuncIdx].id;
604 ranFuncAcceptedItemIe->value.choice.RANfunctionID_Item.ranFunctionRevision= ranFunAcceptedList[ranFuncIdx].revisionCounter;
610 DU_LOG("\nERROR --> E2AP : Memory allocation for RAN function added list array");
616 /*******************************************************************
618 * @brief Builds and sends the E2SetupResponse
622 * Function : BuildAndSendE2SetupRsp
624 * Functionality: Constructs the F1SetupResponse message and sends
625 * it back to the DU through SCTP.
627 * @params[in] void **buf,Buffer to which encoded pattern is written into
628 * @params[in] int *size,size of buffer
630 * @return ROK - success
633 * ****************************************************************/
635 uint8_t BuildAndSendE2SetupRsp(DuDb *duDb, uint8_t transId)
637 E2AP_PDU_t *e2apMsg = NULL;
638 E2setupResponse_t *e2SetupRsp;
639 asn_enc_rval_t encRetVal;
642 bool memAllocFailed = false;
644 DU_LOG("\nINFO --> E2AP : Building E2 Setup Response\n");
647 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
650 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
653 e2apMsg->present = E2AP_PDU_PR_successfulOutcome;
654 RIC_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
655 if(e2apMsg->choice.successfulOutcome == NULLP)
657 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
661 e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_E2setup;
662 e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
663 e2apMsg->choice.successfulOutcome->value.present = \
664 SuccessfulOutcomeE2__value_PR_E2setupResponse;
665 e2SetupRsp = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse;
668 /* Fill Accepted RAN function IE If Ran function information is stored in databse */
669 if(duDb->numOfRanFunction)
672 e2SetupRsp->protocolIEs.list.count = elementCnt;
673 e2SetupRsp->protocolIEs.list.size = elementCnt * sizeof(E2setupResponseIEs_t*);
675 RIC_ALLOC(e2SetupRsp->protocolIEs.list.array, e2SetupRsp->protocolIEs.list.size);
676 if(e2SetupRsp->protocolIEs.list.array == NULLP)
678 DU_LOG("\nERROR --> E2AP : Memory allocation for E2ResponseIEs failed");
682 for(idx=0; idx<elementCnt; idx++)
684 RIC_ALLOC(e2SetupRsp->protocolIEs.list.array[idx], sizeof(E2setupResponseIEs_t));
685 if(e2SetupRsp->protocolIEs.list.array[idx] == NULLP)
687 DU_LOG("\nERROR --> E2AP : Memory allocation for E2ResponseIEs failed");
688 memAllocFailed = true;
693 if(memAllocFailed == true)
695 DU_LOG("\nERROR --> E2AP : Memory allocation for E2ResponseIEs failed");
700 e2SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_TransactionID;
701 e2SetupRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
702 e2SetupRsp->protocolIEs.list.array[idx]->value.present = E2setupResponseIEs__value_PR_TransactionID;
703 e2SetupRsp->protocolIEs.list.array[idx]->value.choice.TransactionID = transId;
707 e2SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_GlobalRIC_ID;
708 e2SetupRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
709 e2SetupRsp->protocolIEs.list.array[idx]->value.present = E2setupResponseIEs__value_PR_GlobalRIC_ID;
711 if(BuildGlobalRicId(&(e2SetupRsp->protocolIEs.list.array[idx]->value.choice.GlobalRIC_ID))!=ROK)
713 DU_LOG("\nERROR --> E2AP : Failed to build Global Ric Id");
717 if(duDb->numOfRanFunction)
719 /* Accepted RAN function Id */
721 e2SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionsAccepted;
722 e2SetupRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
723 e2SetupRsp->protocolIEs.list.array[idx]->value.present = E2setupResponseIEs__value_PR_RANfunctionsID_List;
724 if(BuildRanFunctionAcceptedList(duDb, 0, NULL, &e2SetupRsp->protocolIEs.list.array[idx]->value.choice.RANfunctionsID_List, ProcedureCodeE2_id_E2setup)!=ROK)
726 DU_LOG("\nERROR --> E2AP : Failed to build Ran function added list");
731 /* E2 Node Component Configuration Addition Acknowledge List*/
733 e2SetupRsp->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck;
734 e2SetupRsp->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
735 e2SetupRsp->protocolIEs.list.array[idx]->value.present = \
736 E2setupResponseIEs__value_PR_E2nodeComponentConfigAdditionAck_List;
737 if(BuildE2nodeComponentConfigAdditionAck(&e2SetupRsp->protocolIEs.list.array[idx]->\
738 value.choice.E2nodeComponentConfigAdditionAck_List, duDb) != ROK)
740 DU_LOG("\nERROR --> E2AP : Failed to build E2Node Component config addition ack list");
744 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
745 memset(encBuf, 0, ENC_BUF_MAX_LEN);
747 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
749 /* Check encode results */
750 if(encRetVal.encoded == ENCODE_FAIL)
752 DU_LOG("\nERROR --> E2AP : Could not encode E2SetupResponse structure (at %s)\n",\
753 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
758 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupResponse\n");
759 for(int i=0; i< encBufSize; i++)
761 DU_LOG("%x",encBuf[i]);
765 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duDb->duId) != ROK)
767 DU_LOG("\nERROR --> E2AP : Sending E2 Setup Response failed");
773 FreeE2SetupRsp(e2apMsg);
774 BuildAndSendRicSubscriptionReq(duDb);
778 /*******************************************************************
780 * @brief Free RIC Subscription Details
784 * Function : FreeRicSubsDetails
786 * Functionality: Free the RIC Subscription Details
788 * @params[in] RICsubscriptionDetails_t *subsDetails
791 * ****************************************************************/
792 void FreeRicSubsDetails(RICsubscriptionDetails_t *subsDetails)
794 uint8_t elementIdx = 0;
795 RICaction_ToBeSetup_ItemIEs_t *actionItem = NULLP;
797 RIC_FREE(subsDetails->ricEventTriggerDefinition.buf, subsDetails->ricEventTriggerDefinition.size);
799 if(subsDetails->ricAction_ToBeSetup_List.list.array)
801 for(elementIdx = 0; elementIdx < subsDetails->ricAction_ToBeSetup_List.list.count; elementIdx++)
803 if(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx])
805 actionItem = (RICaction_ToBeSetup_ItemIEs_t *)subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx];
806 if(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition)
808 RIC_FREE(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->buf, \
809 actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->size);
810 RIC_FREE(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition, sizeof(RICactionDefinition_t));
812 RIC_FREE(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx], sizeof(RICaction_ToBeSetup_ItemIEs_t))
815 RIC_FREE(subsDetails->ricAction_ToBeSetup_List.list.array, subsDetails->ricAction_ToBeSetup_List.list.size);
819 /*******************************************************************
821 * @brief Free RIC Subscription Request
825 * Function : FreeRicSubscriptionReq
827 * Functionality : Free RIC Subscription Request
829 * @return ROK - success
832 ******************************************************************/
833 void FreeRicSubscriptionReq(E2AP_PDU_t *e2apRicMsg)
836 RICsubscriptionRequest_t *ricSubscriptionReq;
840 if(e2apRicMsg->choice.initiatingMessage)
842 ricSubscriptionReq = &e2apRicMsg->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
843 if(ricSubscriptionReq->protocolIEs.list.array)
845 for(idx=0; idx < ricSubscriptionReq->protocolIEs.list.count; idx++)
847 switch(ricSubscriptionReq->protocolIEs.list.array[idx]->id)
849 case ProtocolIE_IDE2_id_RICsubscriptionDetails:
851 FreeRicSubsDetails(&(ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails));
855 RIC_FREE(ricSubscriptionReq->protocolIEs.list.array[idx], sizeof(RICsubscriptionRequest_IEs_t));
857 RIC_FREE(ricSubscriptionReq->protocolIEs.list.array, ricSubscriptionReq->protocolIEs.list.size);
859 RIC_FREE(e2apRicMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
861 RIC_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
865 /*******************************************************************
867 * @brief Builds Ric Request Id
871 * Function : BuildNewRicRequestId
873 * Functionality: Assign new Ric Request ID
875 * @params[in] RIC request ID to be sent
876 * RIC request ID stored in DB
877 * @return ROK - success
880 * ****************************************************************/
882 uint8_t BuildNewRicRequestId(RICrequestID_t *ricReqId, RicRequestId *reqIdDb)
884 static uint16_t requestorId = 0;
885 static uint16_t instanceId = 0;
887 if(ricReqId != NULLP)
889 ricReqId->ricRequestorID = ++requestorId;
890 ricReqId->ricInstanceID = ++instanceId;
892 reqIdDb->requestorId = ricReqId->ricRequestorID;
893 reqIdDb->instanceId = ricReqId->ricInstanceID;
898 /*******************************************************************
900 * @brief Free RIC Action Definition
904 * Function : FreeRicActionDefinition
906 * Functionality: Free RIC Action Definition
908 * @params[in] E2SM-KPM Action definition
911 * ****************************************************************/
912 void FreeRicActionDefinition(E2SM_KPM_ActionDefinition_t actionDef)
914 uint8_t elementIdx = 0;
915 E2SM_KPM_ActionDefinition_Format1_t *actionFormat1 = NULLP;
916 MeasurementInfoItem_t *measItem = NULLP;
918 switch(actionDef.actionDefinition_formats.present)
920 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1:
922 if(actionDef.actionDefinition_formats.choice.actionDefinition_Format1)
924 actionFormat1 = actionDef.actionDefinition_formats.choice.actionDefinition_Format1;
925 if(actionFormat1->measInfoList.list.array)
927 for(elementIdx = 0; elementIdx < actionFormat1->measInfoList.list.count; elementIdx++)
929 if(actionFormat1->measInfoList.list.array[elementIdx])
931 measItem = actionFormat1->measInfoList.list.array[elementIdx];
932 switch(measItem->measType.present)
934 case MeasurementType_PR_NOTHING:
935 case MeasurementType_PR_measID:
937 case MeasurementType_PR_measName:
939 RIC_FREE(measItem->measType.choice.measName.buf, measItem->measType.choice.measName.size)
943 RIC_FREE(measItem, sizeof(MeasurementInfoItem_t));
946 RIC_FREE(actionFormat1->measInfoList.list.array, actionFormat1->measInfoList.list.size);
948 RIC_FREE(actionFormat1, sizeof(E2SM_KPM_ActionDefinition_Format1_t));
953 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format2:
954 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format3:
955 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format4:
956 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format5:
957 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_NOTHING:
962 /*******************************************************************
964 * @brief Fill RIC Action Definition
968 * Function : fillRicActionDef
970 * Functionality: Fill RIC Action Definition
972 * @params[in] RIC Action definition
976 * ****************************************************************/
977 uint8_t fillRicActionDef(RICactionDefinition_t *ricActionDef)
979 uint8_t ret = RFAILED;
980 asn_enc_rval_t encRetVal;
981 uint8_t elementCnt = 0, elementIdx = 0;
982 char *measurementTypeName[] = {"RRU.PrbTotDl", "RRU.PrbTotUl"};
983 E2SM_KPM_ActionDefinition_t actionDef;
984 E2SM_KPM_ActionDefinition_Format1_t *actionFormat1 = NULLP;
985 MeasurementInfoItem_t *measItem = NULLP;
989 /* Fill E2SM-KPM Action Definition Format 1 */
992 actionDef.ric_Style_Type = RIC_STYLE_TYPE;
994 /* RIC Action Definition Format 1 */
995 actionDef.actionDefinition_formats.present = \
996 E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1;
998 RIC_ALLOC(actionDef.actionDefinition_formats.choice.actionDefinition_Format1, \
999 sizeof(E2SM_KPM_ActionDefinition_Format1_t));
1000 if(actionDef.actionDefinition_formats.choice.actionDefinition_Format1 == NULLP)
1002 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1005 actionFormat1 = actionDef.actionDefinition_formats.choice.actionDefinition_Format1;
1007 /* Measurement Info List */
1009 actionFormat1->measInfoList.list.count = elementCnt;
1010 actionFormat1->measInfoList.list.size = elementCnt * sizeof(MeasurementInfoItem_t *);
1011 RIC_ALLOC(actionFormat1->measInfoList.list.array, actionFormat1->measInfoList.list.size);
1012 if(actionFormat1->measInfoList.list.array == NULL)
1014 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1018 for(elementIdx = 0; elementIdx < elementCnt; elementIdx++)
1020 RIC_ALLOC(actionFormat1->measInfoList.list.array[elementIdx], sizeof(MeasurementInfoItem_t));
1021 if(actionFormat1->measInfoList.list.array[elementIdx] == NULLP)
1023 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1027 measItem = actionFormat1->measInfoList.list.array[elementIdx];
1028 measItem->measType.present = MeasurementType_PR_measName;
1030 measItem->measType.choice.measName.size = strlen(measurementTypeName[elementIdx]);
1031 RIC_ALLOC(measItem->measType.choice.measName.buf, measItem->measType.choice.measName.size);
1032 if(measItem->measType.choice.measName.buf == NULLP)
1034 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1037 memcpy(measItem->measType.choice.measName.buf, measurementTypeName[elementIdx], measItem->measType.choice.measName.size);
1039 if(elementIdx < elementCnt)
1042 /* Granularity Period */
1043 actionFormat1->granulPeriod = RIC_ACTION_GRANULARITY_PERIOD; /* In ms */
1045 /* Prints the Msg formed */
1046 xer_fprint(stdout, &asn_DEF_E2SM_KPM_ActionDefinition, &actionDef);
1048 /* Encode E2SM-KPM RIC Action Definition */
1049 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1051 encRetVal = aper_encode(&asn_DEF_E2SM_KPM_ActionDefinition, 0, &actionDef, PrepFinalEncBuf, encBuf);
1052 if(encRetVal.encoded == ENCODE_FAIL)
1054 DU_LOG("\nERROR --> E2AP : Could not encode E2SM-KPM action definition structure (at %s)\n",\
1055 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1059 /* Copty encoded E2SM-KPM RIC action definition to E2AP octet string buffer */
1060 ricActionDef->size = encBufSize;
1061 RIC_ALLOC(ricActionDef->buf, encBufSize);
1062 if(ricActionDef->buf == NULLP)
1064 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1067 memcpy(ricActionDef->buf, encBuf, encBufSize);
1073 FreeRicActionDefinition(actionDef);
1077 /*******************************************************************
1079 * @brief Fills RIC Action To Be Setup Item
1083 * Function : fillActionToBeSetup
1085 * Functionality: Fill the RIC Action To Be Setup Ite,
1086 * RIC subscription DB
1088 * @params[in] RICaction_ToBeSetup_ItemIEs_t *items
1089 * @return ROK - success
1092 * ****************************************************************/
1093 uint8_t fillActionToBeSetup(RICaction_ToBeSetup_ItemIEs_t *actionItem, RicSubscription *ricSubsDb)
1095 static uint8_t ricActionId = 0;
1097 if(actionItem == NULLP)
1099 DU_LOG("\nERROR --> E2AP : Failed at [%s] : line [%d]", __func__, __LINE__);
1105 actionItem->id = ProtocolIE_IDE2_id_RICaction_ToBeSetup_Item;
1106 actionItem->criticality = CriticalityE2_ignore;
1107 actionItem->value.present = RICaction_ToBeSetup_ItemIEs__value_PR_RICaction_ToBeSetup_Item;
1110 actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionID = ricActionId++;
1111 ricSubsDb->actionSequence[ricActionId].actionId = \
1112 actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionID;
1114 /* RIC Action Type */
1115 actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionType = RICactionType_report;
1117 /* RIC Action Definition */
1118 RIC_ALLOC(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition, sizeof(RICactionDefinition_t));
1119 if(!actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition)
1121 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1124 if(fillRicActionDef(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition) != ROK)
1126 DU_LOG("\nERROR --> E2AP : Failed at [%s] : line [%d]", __func__, __LINE__);
1130 ricSubsDb->numOfActions++;
1134 memset(&ricSubsDb->actionSequence[ricActionId], 0, sizeof(ActionInfo));
1135 ricSubsDb->actionSequence[ricActionId].actionId = -1;
1139 /*******************************************************************
1141 * @brief Free Event Trigger Definition
1145 * Function : FreeEventTriggerDef
1147 * Functionality: Free Event Trigger Definition
1149 * @params[in] E2SM-KPM Event Trigger Definition
1152 * ****************************************************************/
1153 void FreeEventTriggerDef(E2SM_KPM_EventTriggerDefinition_t *eventTiggerDef)
1157 switch(eventTiggerDef->eventDefinition_formats.present)
1159 case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_NOTHING:
1161 case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_eventDefinition_Format1:
1162 RIC_FREE(eventTiggerDef->eventDefinition_formats.choice.eventDefinition_Format1, \
1163 sizeof(E2SM_KPM_EventTriggerDefinition_Format1_t));
1169 /*******************************************************************
1171 * @brief Fill Event Trigger Definition
1175 * Function : fillEventTriggerDef
1177 * Functionality: Fill Event Trigger Definition
1179 * @params[in] RIC Event Trigger Definition
1183 * ****************************************************************/
1184 uint8_t fillEventTriggerDef(RICeventTriggerDefinition_t *ricEventTriggerDef)
1186 uint8_t ret = RFAILED;
1187 asn_enc_rval_t encRetVal;
1188 E2SM_KPM_EventTriggerDefinition_t eventTiggerDef;
1192 /* Fill E2SM-KPM Event Trigger Definition Format 1 */
1193 eventTiggerDef.eventDefinition_formats.present = \
1194 E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_eventDefinition_Format1;
1196 RIC_ALLOC(eventTiggerDef.eventDefinition_formats.choice.eventDefinition_Format1, \
1197 sizeof(E2SM_KPM_EventTriggerDefinition_Format1_t));
1198 if(eventTiggerDef.eventDefinition_formats.choice.eventDefinition_Format1 == NULLP)
1200 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1204 eventTiggerDef.eventDefinition_formats.choice.eventDefinition_Format1->reportingPeriod = 1000; /* In ms */
1206 /* Prints the Msg formed */
1207 xer_fprint(stdout, &asn_DEF_E2SM_KPM_EventTriggerDefinition, &eventTiggerDef);
1209 /* Encode E2SM-KPM Event Trigger Definition */
1210 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1212 encRetVal = aper_encode(&asn_DEF_E2SM_KPM_EventTriggerDefinition, 0, &eventTiggerDef, PrepFinalEncBuf, encBuf);
1213 if(encRetVal.encoded == ENCODE_FAIL)
1215 DU_LOG("\nERROR --> E2AP : Could not encode E2SM-KPM event trigger definition structure (at %s)\n",\
1216 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1220 /* Copy encoded E2SM-KPM event trigger definition to E2AP octet string buffer */
1221 ricEventTriggerDef->size = encBufSize;
1222 RIC_ALLOC(ricEventTriggerDef->buf, encBufSize);
1223 if(ricEventTriggerDef->buf == NULLP)
1225 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1228 memcpy(ricEventTriggerDef->buf, encBuf, encBufSize);
1234 FreeEventTriggerDef(&eventTiggerDef);
1238 /*******************************************************************
1240 * @brief builds RIC Subscription Details
1244 * Function : BuildsRicSubsDetails
1246 * Functionality: Builds the RIC Subscription Details
1248 * @params[in] RIC Subscription details to be filled
1249 * RIC subscriotion DB
1250 * @return ROK - success
1253 * ****************************************************************/
1255 uint8_t BuildRicSubsDetails(RICsubscriptionDetails_t *subsDetails, RicSubscription *ricSubsDb)
1257 uint8_t actionIdx = 0;
1258 uint8_t elementCnt = 0;
1259 uint8_t elementIdx = 0;
1261 if(subsDetails == NULLP)
1263 DU_LOG("\nERROR --> E2AP : Failed at [%s] : line [%d]", __func__, __LINE__);
1269 /* RIC Event Trigger Definition */
1270 if(fillEventTriggerDef(&subsDetails->ricEventTriggerDefinition) != ROK)
1272 DU_LOG("\nERROR --> E2AP : Failed at [%s] : line [%d]", __func__, __LINE__);
1276 /* RIC Actions To Be Setup List */
1278 subsDetails->ricAction_ToBeSetup_List.list.count = elementCnt;
1279 subsDetails->ricAction_ToBeSetup_List.list.size = elementCnt * sizeof(RICaction_ToBeSetup_ItemIEs_t *);
1280 RIC_ALLOC(subsDetails->ricAction_ToBeSetup_List.list.array, subsDetails->ricAction_ToBeSetup_List.list.size);
1281 if(subsDetails->ricAction_ToBeSetup_List.list.array == NULLP)
1283 DU_LOG("\nERROR --> E2AP : Memory allocation for RICactionToBeSetup Items failed");
1287 for(elementIdx = 0; elementIdx < elementCnt; elementIdx++)
1289 RIC_ALLOC(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx], sizeof(RICaction_ToBeSetup_ItemIEs_t));
1290 if(!subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx])
1292 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1296 if(elementIdx < elementCnt)
1299 for(actionIdx = 0; actionIdx < MAX_RIC_ACTION; actionIdx++)
1301 ricSubsDb->actionSequence[actionIdx].actionId = -1;
1305 if(fillActionToBeSetup((RICaction_ToBeSetup_ItemIEs_t *)subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx], \
1308 DU_LOG("\nERROR --> E2AP : Failed at [%s] : line [%d]", __func__, __LINE__);
1317 /*******************************************************************
1319 * @brief Builds and Send the RicSubscriptionReq
1323 * Function : BuildAndSendRicSubscriptionReq
1325 * Functionality:Fills the RicSubscriptionReq
1327 * @return ROK - success
1330 ******************************************************************/
1331 uint8_t BuildAndSendRicSubscriptionReq(DuDb *duDb)
1333 uint8_t ret = RFAILED;
1334 E2AP_PDU_t *e2apRicMsg = NULL;
1335 RICsubscriptionRequest_t *ricSubscriptionReq;
1338 asn_enc_rval_t encRetVal; /* Encoder return value */
1339 RanFunction *ranFuncDb = &duDb->ranFunction[0];
1341 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Request\n");
1345 RIC_ALLOC(e2apRicMsg, sizeof(E2AP_PDU_t));
1346 if(e2apRicMsg == NULLP)
1348 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1352 e2apRicMsg->present = E2AP_PDU_PR_initiatingMessage;
1353 RIC_ALLOC(e2apRicMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1354 if(e2apRicMsg->choice.initiatingMessage == NULLP)
1356 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1359 e2apRicMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICsubscription;
1360 e2apRicMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
1361 e2apRicMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICsubscriptionRequest;
1363 ricSubscriptionReq = &e2apRicMsg->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
1366 ricSubscriptionReq->protocolIEs.list.count = elementCnt;
1367 ricSubscriptionReq->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionRequest_IEs_t);
1369 /* Initialize the subscription members */
1370 RIC_ALLOC(ricSubscriptionReq->protocolIEs.list.array, ricSubscriptionReq->protocolIEs.list.size);
1371 if(ricSubscriptionReq->protocolIEs.list.array == NULLP)
1373 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1377 for(idx=0; idx<elementCnt; idx++)
1379 RIC_ALLOC(ricSubscriptionReq->protocolIEs.list.array[idx], sizeof(RICsubscriptionRequest_IEs_t));
1380 if(ricSubscriptionReq->protocolIEs.list.array[idx] == NULLP)
1382 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
1386 if(idx < elementCnt)
1389 /* Filling RIC Request Id */
1391 ricSubscriptionReq->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
1392 ricSubscriptionReq->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1393 ricSubscriptionReq->protocolIEs.list.array[idx]->value.present =\
1394 RICsubscriptionRequest_IEs__value_PR_RICrequestID;
1395 if(BuildNewRicRequestId(&ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RICrequestID, \
1396 &ranFuncDb->subscriptionList[ranFuncDb->numOfSubscription].requestId) != ROK)
1398 DU_LOG("\nERROR --> E2AP : Failed at [%s] : Line [%d]", __func__, __LINE__);
1403 /* Filling RAN Function Id */
1405 ricSubscriptionReq->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
1406 ricSubscriptionReq->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1407 ricSubscriptionReq->protocolIEs.list.array[idx]->value.present =\
1408 RICsubscriptionRequest_IEs__value_PR_RANfunctionID;
1409 ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RANfunctionID = ranFuncDb->id;
1411 /* Filling RIC Subscription Details */
1413 ricSubscriptionReq->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICsubscriptionDetails;
1414 ricSubscriptionReq->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
1415 ricSubscriptionReq->protocolIEs.list.array[idx]->value.present =\
1416 RICsubscriptionRequest_IEs__value_PR_RICsubscriptionDetails;
1417 if(BuildRicSubsDetails(&(ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails),\
1418 &ranFuncDb->subscriptionList[ranFuncDb->numOfSubscription]) != ROK)
1420 DU_LOG("\nERROR --> E2AP : Failed at [%s] : Line [%d]", __func__, __LINE__);
1424 /* Prints the Msg formed */
1425 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apRicMsg);
1427 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1429 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apRicMsg, PrepFinalEncBuf, encBuf);
1430 if(encRetVal.encoded == ENCODE_FAIL)
1432 DU_LOG("\nERROR --> E2AP : Could not encode RicSubscriptionRequest structure (at %s)\n",\
1433 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1438 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RicSubscriptionRequest\n");
1439 for(int i=0; i< encBufSize; i++)
1441 DU_LOG("%x",encBuf[i]);
1446 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duDb->duId) != ROK)
1448 DU_LOG("\nERROR --> E2AP : Sending RIC subscription Request failed");
1452 ranFuncDb->numOfSubscription++;
1458 memset(&ranFuncDb->subscriptionList[ranFuncDb->numOfSubscription], 0, sizeof(RicSubscription));
1459 FreeRicSubscriptionReq(e2apRicMsg);
1463 /*******************************************************************
1465 * @brief Process RicSubscriptionResponse
1469 * Function : ProcRicSubscriptionRsp
1471 * Functionality: Processes RicSubscriptionRsp
1473 * @return ROK - void
1475 ******************************************************************/
1477 void ProcRicSubscriptionResponse(uint32_t duId, RICsubscriptionResponse_t *ricSubscriptionRsp)
1479 uint8_t duIdx = 0, ieIdx = 0,subsIdx = 0, notAdmitIdx = 0;
1480 uint8_t ranFuncId = 0, actionId = 0;
1482 bool ricReqIdDecoded = false;
1483 RicRequestId ricReqId;
1484 RanFunction *ranFuncDb = NULLP;
1485 RICsubscriptionResponse_IEs_t *ricSubsRspIe = NULLP;
1486 RICaction_NotAdmitted_List_t *notAdmitList = NULLP;
1488 DU_LOG("\nINFO --> E2AP : RIC Subscription Response received");
1491 SEARCH_DU_DB(duIdx, duId, duDb);
1494 DU_LOG("\nERROR --> E2AP : duDb is not present for duId %d",duId);
1498 memset(&ricReqId, 0, sizeof(RicRequestId));
1499 if(ricSubscriptionRsp)
1501 if(ricSubscriptionRsp->protocolIEs.list.array)
1503 for(ieIdx=0; ieIdx<ricSubscriptionRsp->protocolIEs.list.count; ieIdx++)
1505 if(ricSubscriptionRsp->protocolIEs.list.array[ieIdx])
1507 ricSubsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
1508 switch(ricSubscriptionRsp->protocolIEs.list.array[ieIdx]->id)
1510 case ProtocolIE_IDE2_id_RICrequestID:
1512 ricReqId.requestorId = ricSubsRspIe->value.choice.RICrequestID.ricRequestorID;
1513 ricReqId.instanceId = ricSubsRspIe->value.choice.RICrequestID.ricInstanceID;
1514 ricReqIdDecoded = true;
1517 case ProtocolIE_IDE2_id_RANfunctionID:
1519 ranFuncId = ricSubsRspIe->value.choice.RANfunctionID;
1520 if(duDb->ranFunction[ranFuncId-1].id == ranFuncId)
1522 ranFuncDb = &duDb->ranFunction[ranFuncId-1];
1526 DU_LOG("\nERROR --> E2AP : ProcRicSubscriptionResponse: RAN Function ID [%d] not found", ranFuncId);
1531 case ProtocolIE_IDE2_id_RICactions_Admitted:
1535 case ProtocolIE_IDE2_id_RICactions_NotAdmitted:
1537 if(!(ranFuncDb && ricReqIdDecoded))
1540 notAdmitList = &ricSubsRspIe->value.choice.RICaction_NotAdmitted_List;
1541 for(notAdmitIdx = 0; notAdmitIdx < notAdmitList->list.count; notAdmitIdx++)
1543 actionId = ((RICaction_NotAdmitted_ItemIEs_t *)(notAdmitList->list.array[notAdmitIdx]))->\
1544 value.choice.RICaction_NotAdmitted_Item.ricActionID;
1546 /* Remove action from RAN Function's subscription list */
1547 for(subsIdx = 0; subsIdx < ranFuncDb->numOfSubscription; subsIdx++)
1549 if((ranFuncDb->subscriptionList[subsIdx].requestId.requestorId == ricReqId.requestorId) &&
1550 (ranFuncDb->subscriptionList[subsIdx].requestId.instanceId == ricReqId.instanceId))
1552 if(ranFuncDb->subscriptionList[subsIdx].actionSequence[actionId].actionId == actionId)
1554 memset(&ranFuncDb->subscriptionList[subsIdx].actionSequence[actionId], 0, \
1555 sizeof(ActionInfo));
1556 ranFuncDb->subscriptionList[subsIdx].actionSequence[actionId].actionId = -1;
1557 ranFuncDb->subscriptionList[subsIdx].numOfActions--;
1572 /*******************************************************************
1574 * @brief deallocate the memory allocated in E2SetupFailure
1578 * Function : FreeE2SetupFailure
1580 * Functionality: deallocate the memory allocated in E2SetupFailure
1582 * @params[in] E2AP_PDU_t *e2apMsg
1585 * ****************************************************************/
1586 void FreeE2SetupFailure(E2AP_PDU_t *e2apMsg)
1589 E2setupFailure_t *e2SetupFail;
1593 if(e2apMsg->choice.unsuccessfulOutcome)
1595 e2SetupFail = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2setupFailure;
1596 if(e2SetupFail->protocolIEs.list.array)
1598 for(arrIdx=0; arrIdx<e2SetupFail->protocolIEs.list.count; arrIdx++)
1600 RIC_FREE(e2SetupFail->protocolIEs.list.array[arrIdx], sizeof(E2setupFailureIEs_t));
1602 RIC_FREE(e2SetupFail->protocolIEs.list.array, e2SetupFail->protocolIEs.list.size);
1604 RIC_FREE(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
1606 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
1610 /*******************************************************************
1612 * @brief Buld and send the E2 Setup failure
1616 * Function : BuildAndSendE2SetupFailure
1619 * - Buld and send the E2 Setup failure
1620 * @return ROK - success
1623 * ****************************************************************/
1625 uint8_t BuildAndSendE2SetupFailure(uint32_t duId, uint8_t transId)
1627 E2AP_PDU_t *e2apMsg = NULL;
1628 E2setupFailure_t *e2SetupFailure;
1629 asn_enc_rval_t encRetVal;
1632 bool memAllocFailed = false;
1634 DU_LOG("\nINFO --> E2AP : Building E2 Setup failure\n");
1637 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
1638 if(e2apMsg == NULLP)
1640 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1643 e2apMsg->present = E2AP_PDU_PR_unsuccessfulOutcome;
1644 RIC_ALLOC(e2apMsg->choice.unsuccessfulOutcome , sizeof(struct UnsuccessfulOutcomeE2));
1645 if(e2apMsg->choice.unsuccessfulOutcome == NULLP)
1647 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
1651 e2apMsg->choice.unsuccessfulOutcome->procedureCode = ProcedureCodeE2_id_E2setup;
1652 e2apMsg->choice.unsuccessfulOutcome->criticality = CriticalityE2_reject;
1653 e2apMsg->choice.unsuccessfulOutcome->value.present = UnsuccessfulOutcomeE2__value_PR_E2setupFailure;
1654 e2SetupFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2setupFailure;
1657 e2SetupFailure->protocolIEs.list.count = elementCnt;
1658 e2SetupFailure->protocolIEs.list.size = elementCnt * sizeof(struct E2setupFailureIEs *);
1660 RIC_ALLOC(e2SetupFailure->protocolIEs.list.array, e2SetupFailure->protocolIEs.list.size);
1661 if(e2SetupFailure->protocolIEs.list.array == NULLP)
1663 DU_LOG("\nERROR --> E2AP : Memory allocation for E2FailureIEs failed");
1667 for(arrIdx=0; arrIdx<elementCnt; arrIdx++)
1669 RIC_ALLOC(e2SetupFailure->protocolIEs.list.array[arrIdx], sizeof(struct E2setupFailureIEs));
1670 if(e2SetupFailure->protocolIEs.list.array[arrIdx] == NULLP)
1672 DU_LOG("\nERROR --> E2AP : Memory allocation for E2FailureIEs failed");
1673 memAllocFailed = true;
1678 if(memAllocFailed == true)
1680 DU_LOG("\nERROR --> E2AP : Memory allocation for E2FailureIEs failed");
1686 e2SetupFailure->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
1687 e2SetupFailure->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1688 e2SetupFailure->protocolIEs.list.array[arrIdx]->value.present = E2setupFailureIEs__value_PR_TransactionID;
1689 e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
1692 e2SetupFailure->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_CauseE2;
1693 e2SetupFailure->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
1694 e2SetupFailure->protocolIEs.list.array[arrIdx]->value.present = E2setupFailureIEs__value_PR_CauseE2;
1695 e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.CauseE2.present = CauseE2_PR_protocol;
1696 e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.CauseE2.choice.protocol = CauseE2Protocol_unspecified;
1699 e2SetupFailure->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TimeToWaitE2;
1700 e2SetupFailure->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_ignore;
1701 e2SetupFailure->protocolIEs.list.array[arrIdx]->value.present = E2setupFailureIEs__value_PR_TimeToWaitE2;
1702 e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2 = TimeToWaitE2_v5s;
1704 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
1705 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1707 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
1709 /* Check encode results */
1710 if(encRetVal.encoded == ENCODE_FAIL)
1712 DU_LOG("\nERROR --> E2AP : Could not encode E2 Setup failure structure (at %s)\n",\
1713 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1718 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Setup Failure\n");
1719 for(int i=0; i< encBufSize; i++)
1721 DU_LOG("%x",encBuf[i]);
1725 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
1727 DU_LOG("\nERROR --> E2AP : Sending E2 Setup Failure failed");
1733 FreeE2SetupFailure(e2apMsg);
1736 /*******************************************************************
1738 * @brief process the e2setup request
1742 * Function : ProcE2SetupReq
1744 * Functionality: process the e2setup request
1746 * @return ROK - success
1749 ******************************************************************/
1751 uint8_t ProcE2SetupReq(uint32_t *duId, E2setupRequest_t *e2SetupReq)
1753 uint8_t arrIdx = 0, e2NodeAddListIdx =0, duIdx = 0, transId =0, ranFuncIdx;
1755 E2nodeComponentConfigAddition_List_t *e2NodeAddList;
1756 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItem;
1757 RANfunction_ItemIEs_t *ranFuncItemIe;
1758 RANfunction_Item_t *ranFunItem;
1759 RANfunctions_List_t *ranFunctionsList;
1763 if(e2SetupReq->protocolIEs.list.array)
1765 for(arrIdx=0; arrIdx<e2SetupReq->protocolIEs.list.count; arrIdx++)
1767 if(e2SetupReq->protocolIEs.list.array[arrIdx])
1769 switch(e2SetupReq->protocolIEs.list.array[arrIdx]->id)
1771 case ProtocolIE_IDE2_id_TransactionID:
1773 transId = e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
1776 case ProtocolIE_IDE2_id_GlobalE2node_ID:
1778 if(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.GlobalE2node_ID.choice.gNB->gNB_DU_ID)
1780 *duId =e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.GlobalE2node_ID.choice.gNB->gNB_DU_ID->buf[0];
1782 SEARCH_DU_DB(duIdx, *duId, duDb);
1785 duDb = &ricCb.duInfo[ricCb.numDu];
1788 memset(duDb, 0, sizeof(DuDb));
1793 case ProtocolIE_IDE2_id_RANfunctionsAdded:
1795 ranFunctionsList = &e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List;
1797 if(ranFunctionsList->list.array)
1799 for(ranFuncIdx=0;ranFuncIdx<ranFunctionsList->list.count; ranFuncIdx++)
1801 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncIdx];
1802 ranFunItem = &ranFuncItemIe->value.choice.RANfunction_Item;
1803 duDb->ranFunction[ranFunItem->ranFunctionID-1].id = ranFunItem->ranFunctionID;
1804 duDb->ranFunction[ranFunItem->ranFunctionID-1].revisionCounter = ranFunItem->ranFunctionRevision;
1805 duDb->numOfRanFunction++;
1810 case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition:
1812 e2NodeAddList = &e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List;
1813 if(e2NodeAddList->list.array)
1815 for(e2NodeAddListIdx = 0; e2NodeAddListIdx< e2NodeAddList->list.count; e2NodeAddListIdx++)
1817 if(e2NodeAddList->list.array[e2NodeAddListIdx])
1820 (E2nodeComponentConfigAddition_ItemIEs_t *)e2NodeAddList->list.array[e2NodeAddListIdx];
1821 if(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.\
1822 choice.e2nodeComponentInterfaceTypeF1)
1824 duDb->e2NodeComponent.interfaceType = F1;
1825 duDb->e2NodeComponent.componentId = \
1826 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.\
1827 choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[0];
1842 if(BuildAndSendE2SetupRsp(duDb, transId) !=ROK)
1844 DU_LOG("\nERROR --> E2AP : Failed to build and send E2 setup response");
1849 /*******************************************************************
1851 * @brief Deallocate the memory allocated for E2 Reset Response
1855 * Function : FreeE2ResetResponse
1858 * - freeing the memory allocated for E2ResetResponse
1860 * @params[in] E2AP_PDU_t *e2apMsg
1861 * @return ROK - success
1864 * ****************************************************************/
1865 void FreeE2ResetResponse(E2AP_PDU_t *e2apMsg)
1868 ResetResponseE2_t *resetResponse;
1870 if(e2apMsg != NULLP)
1872 if(e2apMsg->choice.successfulOutcome != NULLP)
1874 resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2;
1875 if(resetResponse->protocolIEs.list.array)
1877 for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
1879 if(resetResponse->protocolIEs.list.array[ieIdx])
1881 RIC_FREE(resetResponse->protocolIEs.list.array[ieIdx], sizeof(ResetResponseIEs_t));
1884 RIC_FREE(resetResponse->protocolIEs.list.array, resetResponse->protocolIEs.list.size);
1886 RIC_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
1888 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
1892 /*******************************************************************
1894 * @brief Buld and send the E2 Reset Response msg
1898 * Function : BuildAndSendE2ResetResponse
1901 * - Buld and send the E2 Reset Response Message
1902 * @return ROK - success
1905 * ****************************************************************/
1906 uint8_t BuildAndSendResetResponse(uint32_t duId, uint8_t transId)
1908 uint8_t ieIdx = 0, elementCnt = 0;
1909 uint8_t ret = RFAILED;
1910 E2AP_PDU_t *e2apMsg = NULLP;
1911 ResetResponseE2_t *resetResponse;
1912 asn_enc_rval_t encRetVal; /* Encoder return value */
1914 DU_LOG("\nINFO --> E2AP : Building E2 Reset Response Message\n");
1917 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
1918 if(e2apMsg == NULLP)
1920 DU_LOG("\nERROR --> E2AP : BuildAndSendResetResponse(): Memory allocation for E2AP-PDU failed");
1923 e2apMsg->present = E2AP_PDU_PR_successfulOutcome;
1925 RIC_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
1926 if(e2apMsg->choice.successfulOutcome == NULLP)
1928 DU_LOG("\nERROR --> E2AP : BuildAndSendResetResponse: Memory allocation failed for successfulOutcome");
1929 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
1933 e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_Reset;
1934 e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
1935 e2apMsg->choice.successfulOutcome->value.present = SuccessfulOutcomeE2__value_PR_ResetResponseE2;
1936 resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2;
1939 resetResponse->protocolIEs.list.count = elementCnt;
1940 resetResponse->protocolIEs.list.size = elementCnt * sizeof(ResetResponseIEs_t *);
1941 RIC_ALLOC(resetResponse->protocolIEs.list.array, resetResponse->protocolIEs.list.size);
1942 if(!resetResponse->protocolIEs.list.array)
1944 DU_LOG("\nERROR --> E2AP : BuildAndSendResetResponse: Memory allocation failed for protocol IE array");
1948 for(ieIdx=0; ieIdx < elementCnt; ieIdx++)
1950 RIC_ALLOC(resetResponse->protocolIEs.list.array[ieIdx], sizeof(ResetResponseIEs_t));
1951 if(!resetResponse->protocolIEs.list.array[ieIdx])
1953 DU_LOG("\nERROR --> E2AP : BuildAndSendResetResponse: Memory allocation failed for protocol IE array element");
1957 if(ieIdx < elementCnt)
1961 resetResponse->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
1962 resetResponse->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
1963 resetResponse->protocolIEs.list.array[ieIdx]->value.present = ResetResponseIEs__value_PR_TransactionID;
1964 resetResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
1966 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
1968 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1970 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
1971 if(encRetVal.encoded == ENCODE_FAIL)
1973 DU_LOG("\nERROR --> E2AP : Could not encode E2 reset response structure (at %s)\n",\
1974 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1979 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Reset Response \n");
1980 for(int i=0; i< encBufSize; i++)
1982 DU_LOG("%x",encBuf[i]);
1987 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
1989 DU_LOG("\nERROR --> E2AP : Failed to send E2 Reset Response");
1997 FreeE2ResetResponse(e2apMsg);
2001 /*******************************************************************
2003 * @brief process the E2 Reset Request
2007 * Function : ProcE2ResetReq
2009 * Functionality: Process E2 Reset Request
2011 * @return ROK - success
2014 ******************************************************************/
2016 uint8_t ProcE2ResetReq(uint32_t duId, ResetRequestE2_t *resetReq)
2018 uint8_t ieIdx = 0, duIdx = 0;
2019 uint8_t transId = 0, cause = 0;
2024 if(resetReq->protocolIEs.list.array)
2026 for(ieIdx=0; ieIdx < resetReq->protocolIEs.list.count; ieIdx++)
2028 if(resetReq->protocolIEs.list.array[ieIdx])
2030 switch(resetReq->protocolIEs.list.array[ieIdx]->id)
2032 case ProtocolIE_IDE2_id_TransactionID:
2033 transId = resetReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
2035 case ProtocolIE_IDE2_id_CauseE2:
2036 DU_LOG("\nDEBUG --> E2AP : Reset reason %d", resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.present);
2037 switch(resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.present)
2039 case CauseE2_PR_NOTHING:
2041 case CauseE2_PR_ricRequest:
2042 cause = resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.ricRequest;
2044 case CauseE2_PR_ricService:
2045 cause = resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.ricService;
2047 case CauseE2_PR_e2Node:
2048 cause = resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.e2Node;
2050 case CauseE2_PR_transport:
2051 cause = resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.transport;
2053 case CauseE2_PR_protocol:
2054 cause = resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.protocol;
2056 case CauseE2_PR_misc:
2057 cause = resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2.choice.misc;
2060 DU_LOG("\nDEBUG --> E2AP : Reset cause %d", cause);
2067 BuildAndSendResetResponse(duId, transId);
2071 /*******************************************************************
2073 * @brief deallocate the memory allocated in building the
2074 * Service Query message
2078 * Function : FreeRicServiceQuery
2080 * Functionality: deallocate the memory allocated in building
2081 * Ric Service Query message
2083 * @params[in] E2AP_PDU_t *e2apMsg
2086 * ****************************************************************/
2088 void FreeRicServiceQuery(E2AP_PDU_t *e2apMsg)
2090 uint8_t arrIdx = 0, ranFuncIdx=0;
2091 RANfunctionsID_List_t *ranFuncAcceptedList=NULL;
2092 RICserviceQuery_t *ricServiceQuery=NULL;
2096 if(e2apMsg->choice.initiatingMessage)
2098 ricServiceQuery = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceQuery;
2099 if(ricServiceQuery->protocolIEs.list.array)
2101 for(arrIdx=0; arrIdx<ricServiceQuery->protocolIEs.list.count; arrIdx++)
2103 if(ricServiceQuery->protocolIEs.list.array[arrIdx])
2105 switch(ricServiceQuery->protocolIEs.list.array[arrIdx]->id)
2107 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
2109 ranFuncAcceptedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
2110 if(ranFuncAcceptedList->list.array)
2112 for(ranFuncIdx=0;ranFuncIdx<ranFuncAcceptedList->list.count; ranFuncIdx++)
2114 RIC_FREE(ranFuncAcceptedList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
2116 RIC_FREE(ranFuncAcceptedList->list.array, ranFuncAcceptedList->list.size);
2120 case RICserviceQuery_IEs__value_PR_TransactionID:
2125 RIC_FREE(ricServiceQuery->protocolIEs.list.array[arrIdx], sizeof(RICserviceQuery_IEs_t));
2128 RIC_FREE(ricServiceQuery->protocolIEs.list.array, ricServiceQuery->protocolIEs.list.size);
2130 RIC_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2132 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2136 /*******************************************************************
2138 * @brief build and send the ric service Query
2142 * Function : BuildAndSendRicServiceQuery
2144 * Functionality: build and send the ric service Query
2145 * @return ROK - success
2146 * RFAILED - Acknowledge
2148 ******************************************************************/
2150 uint8_t BuildAndSendRicServiceQuery(DuDb *duDb)
2154 uint8_t ret = RFAILED;
2155 bool memAllocFailed = false;
2156 E2AP_PDU_t *e2apMsg = NULL;
2157 asn_enc_rval_t encRetVal;
2158 RICserviceQuery_t *ricServiceQuery;
2160 DU_LOG("\nINFO --> E2AP : Building Ric service Query\n");
2163 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2164 if(e2apMsg == NULLP)
2166 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2169 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
2170 RIC_ALLOC(e2apMsg->choice.initiatingMessage , sizeof(struct InitiatingMessageE2));
2171 if(e2apMsg->choice.initiatingMessage == NULLP)
2173 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2177 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICserviceQuery;
2178 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
2179 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICserviceQuery;
2180 ricServiceQuery = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceQuery;
2183 /* Fill Accepted RAN function IE If Ran function information is stored in databse */
2184 if(duDb->numOfRanFunction)
2187 ricServiceQuery->protocolIEs.list.count = elementCnt;
2188 ricServiceQuery->protocolIEs.list.size = elementCnt * sizeof(RICserviceQuery_IEs_t*);
2190 RIC_ALLOC(ricServiceQuery->protocolIEs.list.array, ricServiceQuery->protocolIEs.list.size);
2191 if(ricServiceQuery->protocolIEs.list.array == NULLP)
2193 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceQueryIEs failed");
2197 for(arrIdx=0; arrIdx<elementCnt; arrIdx++)
2199 RIC_ALLOC(ricServiceQuery->protocolIEs.list.array[arrIdx], sizeof(RICserviceQuery_IEs_t));
2200 if(ricServiceQuery->protocolIEs.list.array[arrIdx] == NULLP)
2202 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceQueryIEs failed");
2203 memAllocFailed = true;
2207 if(memAllocFailed == true)
2209 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceQueryIEs failed");
2215 ricServiceQuery->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
2216 ricServiceQuery->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2217 ricServiceQuery->protocolIEs.list.array[arrIdx]->value.present = RICserviceQuery_IEs__value_PR_TransactionID;
2218 ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = assignTransactionId(duDb);
2220 if(duDb->numOfRanFunction)
2222 /* Accepted RAN function Id */
2224 ricServiceQuery->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAccepted;
2225 ricServiceQuery->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2226 ricServiceQuery->protocolIEs.list.array[arrIdx]->value.present = RICserviceQuery_IEs__value_PR_RANfunctionsID_List;
2227 if(BuildRanFunctionAcceptedList(duDb, 0, NULL, &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List, ProcedureCodeE2_id_RICserviceQuery)!=ROK)
2229 DU_LOG("\nERROR --> E2AP : Failed to build Ran function added list");
2234 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2235 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2237 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
2239 /* Check encode results */
2240 if(encRetVal.encoded == ENCODE_FAIL)
2242 DU_LOG("\nERROR --> E2AP : Could not encode RIC service Query structure (at %s)\n",\
2243 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2248 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC service Query\n");
2249 for(int i=0; i< encBufSize; i++)
2251 DU_LOG("%x",encBuf[i]);
2255 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duDb->duId) != ROK)
2257 DU_LOG("\nERROR --> E2AP : Sending of RIC service Query failed");
2264 FreeRicServiceQuery(e2apMsg);
2268 /*******************************************************************
2270 * @brief deallocate the memory allocated in RicServiceUpdateFailure
2274 * Function : FreeRicServiceUpdateFailure
2276 * Functionality: deallocate the memory allocated in RicServiceUpdatefailure
2278 * @params[in] E2AP_PDU_t *e2apMsg
2281 * ****************************************************************/
2283 void FreeRicServiceUpdateFailure(E2AP_PDU_t *e2apMsg)
2286 RICserviceUpdateFailure_t *ricServiceUpdateFailure=NULL;
2290 if(e2apMsg->choice.unsuccessfulOutcome)
2292 ricServiceUpdateFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICserviceUpdateFailure;
2293 if(ricServiceUpdateFailure->protocolIEs.list.array)
2295 for(arrIdx=0; arrIdx<ricServiceUpdateFailure->protocolIEs.list.count; arrIdx++)
2297 RIC_FREE(ricServiceUpdateFailure->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdateFailure_IEs_t));
2299 RIC_FREE(ricServiceUpdateFailure->protocolIEs.list.array, ricServiceUpdateFailure->protocolIEs.list.size);
2301 RIC_FREE(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
2303 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2307 /*******************************************************************
2309 * @brief fill E2 failure cause
2313 * Function : fillE2FailureCause
2315 * Functionality: fill E2 failure cause
2316 * @return ROK - success
2319 ******************************************************************/
2321 void fillE2FailureCause(CauseE2_t *cause, CauseE2_PR causePresent, uint8_t reason)
2323 cause->present = causePresent;
2325 switch(cause->present)
2327 case CauseE2_PR_ricRequest:
2328 cause->choice.ricRequest = reason;
2330 case CauseE2_PR_ricService:
2331 cause->choice.ricService = reason;
2333 case CauseE2_PR_e2Node:
2334 cause->choice.e2Node = reason;
2336 case CauseE2_PR_transport:
2337 cause->choice.transport = reason;
2339 case CauseE2_PR_protocol:
2340 cause->choice.protocol = reason;
2342 case CauseE2_PR_misc:
2343 cause->choice.misc = reason;
2346 cause->choice.misc = CauseE2Misc_unspecified;
2351 /*******************************************************************
2353 * @brief build and send the ric service update failure
2357 * Function : BuildAndSendRicServiceUpdateFailure
2359 * Functionality: build and send the ric service update failure
2360 * @return ROK - success
2363 ******************************************************************/
2365 uint8_t BuildAndSendRicServiceUpdateFailure(uint32_t duId, int8_t transId, CauseE2_PR causePresent, uint8_t reason)
2368 E2AP_PDU_t *e2apMsg = NULL;
2369 asn_enc_rval_t encRetVal;
2370 uint8_t ret = RFAILED;
2372 uint8_t elementCnt=0;
2373 RICserviceUpdateFailure_t *ricServiceFailure=NULL;
2375 DU_LOG("\nINFO --> E2AP : Building Ric service update failure\n");
2378 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2379 if(e2apMsg == NULLP)
2381 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2384 e2apMsg->present = E2AP_PDU_PR_unsuccessfulOutcome;
2385 RIC_ALLOC(e2apMsg->choice.unsuccessfulOutcome , sizeof(struct UnsuccessfulOutcomeE2));
2386 if(e2apMsg->choice.unsuccessfulOutcome == NULLP)
2388 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2392 e2apMsg->choice.unsuccessfulOutcome->procedureCode = ProcedureCodeE2_id_RICserviceUpdate;
2393 e2apMsg->choice.unsuccessfulOutcome->criticality = CriticalityE2_reject;
2394 e2apMsg->choice.unsuccessfulOutcome->value.present = UnsuccessfulOutcomeE2__value_PR_RICserviceUpdateFailure;
2395 ricServiceFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICserviceUpdateFailure;
2398 ricServiceFailure->protocolIEs.list.count = elementCnt;
2399 ricServiceFailure->protocolIEs.list.size = elementCnt * sizeof(RICserviceUpdateFailure_IEs_t *);
2401 RIC_ALLOC(ricServiceFailure->protocolIEs.list.array, ricServiceFailure->protocolIEs.list.size);
2402 if(ricServiceFailure->protocolIEs.list.array == NULLP)
2404 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceFailureIEs failed");
2408 for(arrIdx=0; arrIdx<elementCnt; arrIdx++)
2410 RIC_ALLOC(ricServiceFailure->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdateFailure_IEs_t));
2411 if(ricServiceFailure->protocolIEs.list.array[arrIdx] == NULLP)
2413 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceFailureIEs failed");
2417 if(arrIdx<elementCnt)
2419 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceFailureIEs failed");
2425 ricServiceFailure->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
2426 ricServiceFailure->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2427 ricServiceFailure->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdateFailure_IEs__value_PR_TransactionID;
2428 ricServiceFailure->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
2431 ricServiceFailure->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_CauseE2;
2432 ricServiceFailure->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2433 ricServiceFailure->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdateFailure_IEs__value_PR_CauseE2;
2434 fillE2FailureCause(&ricServiceFailure->protocolIEs.list.array[arrIdx]->value.choice.CauseE2, causePresent, reason);
2437 ricServiceFailure->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TimeToWaitE2;
2438 ricServiceFailure->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_ignore;
2439 ricServiceFailure->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdateFailure_IEs__value_PR_TimeToWaitE2;
2440 ricServiceFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2 = TimeToWaitE2_v5s;
2442 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2443 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2445 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
2447 /* Check encode results */
2448 if(encRetVal.encoded == ENCODE_FAIL)
2450 DU_LOG("\nERROR --> E2AP : Could not encode RIC service update failure structure (at %s)\n",\
2451 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2456 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC service update Failure\n");
2457 for(int i=0; i< encBufSize; i++)
2459 DU_LOG("%x",encBuf[i]);
2463 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
2465 DU_LOG("\nERROR --> E2AP : Sending RIC service update failed");
2472 FreeRicServiceUpdateFailure(e2apMsg);
2477 /*******************************************************************
2479 * @brief deallocate the memory allocated in RicServiceUpdateAck(
2483 * Function : FreeRicServiceUpdateAck
2485 * Functionality: deallocate the memory allocated in RicServiceUpdateAck
2487 * @params[in] E2AP_PDU_t *e2apMsg
2490 * ****************************************************************/
2492 void FreeRicServiceUpdateAck(E2AP_PDU_t *e2apMsg)
2494 uint8_t arrIdx = 0, ranFuncIdx=0;
2495 RANfunctionsID_List_t *acceptedList=NULL;
2496 RICserviceUpdateAcknowledge_t *ricServiceUpdateAck=NULL;
2497 RANfunctionsIDcause_List_t *rejectedList=NULL;
2501 if(e2apMsg->choice.successfulOutcome)
2503 ricServiceUpdateAck = &e2apMsg->choice.successfulOutcome->value.choice.RICserviceUpdateAcknowledge;
2504 if(ricServiceUpdateAck->protocolIEs.list.array)
2506 for(arrIdx=0; arrIdx<ricServiceUpdateAck->protocolIEs.list.count; arrIdx++)
2508 if(ricServiceUpdateAck->protocolIEs.list.array[arrIdx])
2510 switch(ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->id)
2512 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
2514 acceptedList= &ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
2515 if(acceptedList->list.array)
2517 for(ranFuncIdx=0;ranFuncIdx<acceptedList->list.count; ranFuncIdx++)
2519 RIC_FREE(acceptedList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
2521 RIC_FREE(acceptedList->list.array, acceptedList->list.size);
2526 case ProtocolIE_IDE2_id_RANfunctionsRejected:
2528 rejectedList= &ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsIDcause_List;
2529 if(rejectedList->list.array)
2531 for(ranFuncIdx=0;ranFuncIdx<rejectedList->list.count; ranFuncIdx++)
2533 RIC_FREE(rejectedList->list.array[ranFuncIdx], sizeof(RANfunctionIDcause_ItemIEs_t));
2535 RIC_FREE(rejectedList->list.array, rejectedList->list.size);
2540 RIC_FREE(ricServiceUpdateAck->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdateAcknowledge_IEs_t));
2543 RIC_FREE(ricServiceUpdateAck->protocolIEs.list.array, ricServiceUpdateAck->protocolIEs.list.size);
2545 RIC_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
2547 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
2551 /*******************************************************************
2553 * @brief Build RAN function rejected list
2557 * Function : BuildRanFunctionRejectedList
2559 * Functionality: Build RAN function rejected list
2562 * Count of ran functions to be rejected in the list
2563 * Received list of RAN functions
2565 * @return ROK - success
2567 * ****************************************************************/
2569 uint8_t BuildRanFunctionRejectedList(uint8_t count, RanFunction *ranFunRejectedList, RANfunctionsIDcause_List_t *ranFuncRejectedList)
2571 uint8_t ranFuncIdx = 0;
2572 RANfunctionIDcause_ItemIEs_t *ranFuncRejectedItemIe=NULL;
2574 ranFuncRejectedList->list.count = count;
2576 ranFuncRejectedList->list.size = ranFuncRejectedList->list.count*sizeof(RANfunctionIDcause_ItemIEs_t*);
2577 RIC_ALLOC(ranFuncRejectedList->list.array, ranFuncRejectedList->list.size);
2578 if(ranFuncRejectedList->list.array == NULLP)
2580 DU_LOG("\nERROR --> E2AP : Memory allocation for RAN function rejected list array");
2584 for(ranFuncIdx = 0; ranFuncIdx< ranFuncRejectedList->list.count; ranFuncIdx++)
2586 RIC_ALLOC(ranFuncRejectedList->list.array[ranFuncIdx], sizeof(RANfunctionIDcause_ItemIEs_t));
2587 if(ranFuncRejectedList->list.array[ranFuncIdx] == NULLP)
2589 DU_LOG("\nERROR --> E2AP : Memory allocation for RAN function rejected list array item");
2592 ranFuncRejectedItemIe = (RANfunctionIDcause_ItemIEs_t*)ranFuncRejectedList->list.array[ranFuncIdx];
2593 ranFuncRejectedItemIe->id = ProtocolIE_IDE2_id_RANfunctionIEcause_Item;
2594 ranFuncRejectedItemIe->criticality= CriticalityE2_ignore;
2595 ranFuncRejectedItemIe->value.present = RANfunctionIDcause_ItemIEs__value_PR_RANfunctionIDcause_Item;
2596 ranFuncRejectedItemIe->value.choice.RANfunctionIDcause_Item.ranFunctionID = ranFunRejectedList[ranFuncIdx].id;
2597 fillE2FailureCause(&ranFuncRejectedItemIe->value.choice.RANfunctionIDcause_Item.cause, CauseE2_PR_ricService,\
2598 CauseE2RICservice_ran_function_not_supported);
2604 /*******************************************************************
2606 * @brief build and send the ric service update Acknowledge
2610 * Function : BuildAndSendRicServiceUpdateAcknowledge
2612 * Functionality: build and send the ric service update Acknowledge
2613 * @return ROK - success
2614 * RFAILED - Acknowledge
2616 ******************************************************************/
2618 uint8_t BuildAndSendRicServiceUpdateAcknowledge(DuDb *duDb, int8_t transId, RicTmpRanFunList ricRanFuncList)
2620 E2AP_PDU_t *e2apMsg = NULL;
2621 asn_enc_rval_t encRetVal;
2622 uint8_t arrIdx=0, elementCnt=0, ret=RFAILED;;
2623 RICserviceUpdateAcknowledge_t *ricServiceUpdateAck=NULL;
2625 DU_LOG("\nINFO --> E2AP : Building Ric service update Acknowledge\n");
2628 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2629 if(e2apMsg == NULLP)
2631 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2634 e2apMsg->present = E2AP_PDU_PR_successfulOutcome;
2635 RIC_ALLOC(e2apMsg->choice.successfulOutcome , sizeof(struct SuccessfulOutcomeE2));
2636 if(e2apMsg->choice.successfulOutcome == NULLP)
2638 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2642 e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_RICserviceUpdate;
2643 e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
2644 e2apMsg->choice.successfulOutcome->value.present = SuccessfulOutcomeE2__value_PR_RICserviceUpdateAcknowledge;
2645 ricServiceUpdateAck = &e2apMsg->choice.successfulOutcome->value.choice.RICserviceUpdateAcknowledge;
2648 if(ricRanFuncList.numOfRanFunAccepted)
2650 if(ricRanFuncList.numOfRanFuneRejected)
2654 ricServiceUpdateAck->protocolIEs.list.count = elementCnt;
2655 ricServiceUpdateAck->protocolIEs.list.size = elementCnt * sizeof(RICserviceUpdateAcknowledge_IEs_t*);
2657 RIC_ALLOC(ricServiceUpdateAck->protocolIEs.list.array, ricServiceUpdateAck->protocolIEs.list.size);
2658 if(ricServiceUpdateAck->protocolIEs.list.array == NULLP)
2660 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceUpdateAckIEs failed");
2664 for(arrIdx=0; arrIdx<elementCnt; arrIdx++)
2666 RIC_ALLOC(ricServiceUpdateAck->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdateAcknowledge_IEs_t));
2667 if(ricServiceUpdateAck->protocolIEs.list.array[arrIdx] == NULLP)
2669 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceUpdateAckIEs failed");
2673 if(arrIdx<elementCnt)
2675 DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceUpdateAckIEs failed");
2681 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
2682 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2683 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdateAcknowledge_IEs__value_PR_TransactionID;
2684 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
2686 if(ricRanFuncList.numOfRanFunAccepted)
2688 /* Accepted RAN function List */
2690 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAccepted;
2691 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2692 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdateAcknowledge_IEs__value_PR_RANfunctionsID_List;
2693 if(BuildRanFunctionAcceptedList(duDb, ricRanFuncList.numOfRanFunAccepted, ricRanFuncList.ranFunAcceptedList,\
2694 &ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List, ProcedureCodeE2_id_RICserviceUpdate)!=ROK)
2696 DU_LOG("\nERROR --> E2AP : Failed to build Ran function added list");
2701 if(ricRanFuncList.numOfRanFuneRejected)
2703 /* RAN Functions Rejected List */
2705 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsRejected;
2706 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2707 ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdateAcknowledge_IEs__value_PR_RANfunctionsIDcause_List;
2708 if(BuildRanFunctionRejectedList(ricRanFuncList.numOfRanFuneRejected, ricRanFuncList.ranFunRejectedList, \
2709 &ricServiceUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsIDcause_List)!=ROK)
2711 DU_LOG("\nERROR --> E2AP : Failed to build Ran function rejected list");
2717 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2718 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2720 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
2722 /* Check encode results */
2723 if(encRetVal.encoded == ENCODE_FAIL)
2725 DU_LOG("\nERROR --> E2AP : Could not encode RIC service update Acknowledge structure (at %s)\n",\
2726 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2731 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC service update Acknowledge\n");
2732 for(int i=0; i< encBufSize; i++)
2734 DU_LOG("%x",encBuf[i]);
2738 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duDb->duId) != ROK)
2740 DU_LOG("\nERROR --> E2AP : Sending RIC service update ack failed");
2746 FreeRicServiceUpdateAck(e2apMsg);
2750 /*******************************************************************
2752 * @brief process the RIC service update
2756 * Function : ProcRicserviceUpdate
2758 * Functionality: process the RIC service update
2760 * @return ROK - success
2763 ******************************************************************/
2765 void ProcRicServiceUpdate(uint32_t duId, RICserviceUpdate_t *ricServiceUpdate)
2767 RicTmpRanFunList ricRanFuncList;
2770 uint8_t duIdx = 0, elementCnt =0, arrIdx = 0;
2771 uint16_t ranFuncIdx = 0, failedRanFuncCount=0, recvdRanFuncCount=0;
2772 RANfunction_ItemIEs_t *ranFuncItemIe =NULL;
2773 RANfunction_Item_t *ranFuncItem =NULL;
2774 RANfunctionID_Item_t *ranFuncIdItem=NULL;
2775 RANfunctions_List_t *ranFuncList=NULL;
2776 RANfunctionsID_List_t *deleteList=NULL;
2777 RANfunctionID_ItemIEs_t *delRanFuncItem=NULL;
2779 SEARCH_DU_DB(duIdx, duId, duDb);
2782 DU_LOG("\nERROR --> E2AP : duDb is not present for duId %d",duId);
2785 memset(&ricRanFuncList, 0, sizeof(RicTmpRanFunList));
2787 if(!ricServiceUpdate)
2789 DU_LOG("\nERROR --> E2AP : ricServiceUpdate pointer is null");
2793 if(!ricServiceUpdate->protocolIEs.list.array)
2795 DU_LOG("\nERROR --> E2AP : ricServiceUpdate array pointer is null");
2798 elementCnt = ricServiceUpdate->protocolIEs.list.count;
2799 for(arrIdx=0; arrIdx<ricServiceUpdate->protocolIEs.list.count; arrIdx++)
2801 if(!ricServiceUpdate->protocolIEs.list.array[arrIdx])
2803 DU_LOG("\nERROR --> E2AP : ricServiceUpdate array idx %d pointer is null",arrIdx);
2807 switch(ricServiceUpdate->protocolIEs.list.array[arrIdx]->id)
2809 case ProtocolIE_IDE2_id_TransactionID:
2811 transId = ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
2813 if(transId < 0 || transId > 255)
2815 DU_LOG("\nERROR --> E2AP : Received invalid transId %d",transId);
2821 case ProtocolIE_IDE2_id_RANfunctionsAdded:
2823 ranFuncList = &ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List;
2825 if(ranFuncList->list.array)
2827 for(ranFuncIdx=0;ranFuncIdx<ranFuncList->list.count; ranFuncIdx++)
2829 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFuncList->list.array[ranFuncIdx];
2830 ranFuncItem = &ranFuncItemIe->value.choice.RANfunction_Item;
2832 /* Adding the ran function in temporary list */
2833 ricRanFuncList.ranFunAcceptedList[ricRanFuncList.numOfRanFunAccepted].id = ranFuncItem->ranFunctionID;
2834 ricRanFuncList.ranFunAcceptedList[ricRanFuncList.numOfRanFunAccepted].revisionCounter = ranFuncItem->ranFunctionRevision;
2835 ricRanFuncList.numOfRanFunAccepted++;
2837 /* Adding the new ran function in DB*/
2838 duDb->ranFunction[ranFuncItem->ranFunctionID-1].id = ranFuncItem->ranFunctionID;
2839 duDb->ranFunction[ranFuncItem->ranFunctionID-1].revisionCounter = ranFuncItem->ranFunctionRevision;
2840 duDb->numOfRanFunction++;
2842 /* Calculating total number of ran fuctions which are received for addition */
2843 recvdRanFuncCount++;
2849 case ProtocolIE_IDE2_id_RANfunctionsModified:
2852 ranFuncList = &ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List;
2853 if(ranFuncList->list.array)
2855 for(ranFuncIdx = 0; ranFuncIdx< ranFuncList->list.count; ranFuncIdx++)
2857 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFuncList->list.array[ranFuncIdx];
2858 ranFuncItem = &ranFuncItemIe->value.choice.RANfunction_Item;
2859 if(duDb->ranFunction[ranFuncItem->ranFunctionID-1].id != ranFuncItem->ranFunctionID)
2861 /* Calculating total number of ran fuctions which are not present */
2862 failedRanFuncCount++;
2864 /* Adding the ran function in temporary list */
2865 ricRanFuncList.ranFunRejectedList[ricRanFuncList.numOfRanFuneRejected].id = ranFuncItem->ranFunctionID;
2866 ricRanFuncList.numOfRanFuneRejected++;
2871 /* Adding the ran function in temporary list */
2872 ricRanFuncList.ranFunAcceptedList[ricRanFuncList.numOfRanFunAccepted].id = ranFuncItem->ranFunctionID;
2873 ricRanFuncList.ranFunAcceptedList[ricRanFuncList.numOfRanFunAccepted].revisionCounter = ranFuncItem->ranFunctionRevision;
2874 ricRanFuncList.numOfRanFunAccepted++;
2876 /* Updating the new ran function in DB*/
2877 duDb->ranFunction[ranFuncItem->ranFunctionID-1].revisionCounter = ranFuncItem->ranFunctionRevision;
2879 /* Calculating total number of ran fuctions which are received for modification */
2880 recvdRanFuncCount++;
2885 case ProtocolIE_IDE2_id_RANfunctionsDeleted:
2888 deleteList = &ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
2889 if(deleteList->list.array)
2891 for(ranFuncIdx = 0; ranFuncIdx< deleteList->list.count; ranFuncIdx++)
2893 delRanFuncItem = (RANfunctionID_ItemIEs_t*) deleteList->list.array[ranFuncIdx];
2894 ranFuncIdItem = &delRanFuncItem->value.choice.RANfunctionID_Item;
2895 if(duDb->ranFunction[ranFuncIdItem->ranFunctionID-1].id == ranFuncIdItem->ranFunctionID)
2897 memset(&duDb->ranFunction[ranFuncIdItem->ranFunctionID-1], 0, sizeof(RanFunction));
2898 duDb->numOfRanFunction--;
2901 /* Calculating total number of ran fuctions which are received for deletion */
2902 recvdRanFuncCount++;
2910 DU_LOG("\nERROR --> E2AP : IE [%ld] is not supported",ricServiceUpdate->protocolIEs.list.array[arrIdx]->id);
2916 /* Sending RIC Service Update Failed if all RAN Functions received fail or if any IE processing fails
2917 * Else sending RIC Service Update Acknowledge */
2918 if((elementCnt > arrIdx) ||((recvdRanFuncCount > 0) && (recvdRanFuncCount == failedRanFuncCount)))
2920 if(BuildAndSendRicServiceUpdateFailure(duDb->duId, transId, CauseE2_PR_misc, CauseE2Misc_unspecified) != ROK)
2922 DU_LOG("\nERROR --> E2AP : Failed to build and send RIC service update Failure");
2928 if(BuildAndSendRicServiceUpdateAcknowledge(duDb, transId, ricRanFuncList) != ROK)
2930 DU_LOG("\nERROR --> E2AP : Failed to build and send RIC service update acknowledge");
2936 /*******************************************************************
2938 * @brief Processing RIC subscription failure from DU
2942 * Function : ProcRicSubscriptionFailure
2944 * Functionality: Processing RIC subscription failure from DU
2946 * @param ID of DU from which message was sent
2947 * RIC Subscription failure message
2948 * @return ROK - success
2951 ******************************************************************/
2952 uint8_t ProcRicSubscriptionFailure(uint32_t duId, RICsubscriptionFailure_t *ricSubscriptionFailure)
2954 uint8_t ieIdx = 0, duIdx = 0, subsIdx = 0;
2955 uint8_t ranFuncId = 0;
2956 bool ricReqIdDecoded = false;
2958 RanFunction *ranFuncDb = NULLP;
2959 RicRequestId ricReqId;
2960 RICsubscriptionFailure_IEs_t *ricSubsFailIe = NULLP;
2962 DU_LOG("\nINFO --> E2AP : Received RIC subscription failure");
2964 SEARCH_DU_DB(duIdx, duId, duDb);
2967 DU_LOG("\nERROR --> E2AP : duDb is not present for duId %d",duId);
2971 memset(&ricReqId, 0, sizeof(RicRequestId));
2972 if(ricSubscriptionFailure)
2974 if(ricSubscriptionFailure->protocolIEs.list.array)
2976 for(ieIdx=0; ieIdx<ricSubscriptionFailure->protocolIEs.list.count; ieIdx++)
2978 if(ricSubscriptionFailure->protocolIEs.list.array[ieIdx])
2980 ricSubsFailIe = ricSubscriptionFailure->protocolIEs.list.array[ieIdx];
2981 switch(ricSubscriptionFailure->protocolIEs.list.array[ieIdx]->id)
2983 case ProtocolIE_IDE2_id_RICrequestID:
2985 ricReqId.requestorId = ricSubsFailIe->value.choice.RICrequestID.ricRequestorID;
2986 ricReqId.instanceId = ricSubsFailIe->value.choice.RICrequestID.ricInstanceID;
2987 ricReqIdDecoded = true;
2990 case ProtocolIE_IDE2_id_RANfunctionID:
2992 ranFuncId = ricSubsFailIe->value.choice.RANfunctionID;
2993 if(duDb->ranFunction[ranFuncId-1].id == ranFuncId)
2995 ranFuncDb = &duDb->ranFunction[ranFuncId-1];
2999 case ProtocolIE_IDE2_id_CauseE2:
3001 /* No handling required as of now since this is a stub */
3008 /* Remove subscription entry from RAN Function */
3009 if(ranFuncDb && ricReqIdDecoded)
3011 for(subsIdx = 0; subsIdx < ranFuncDb->numOfSubscription; subsIdx++)
3013 if((ranFuncDb->subscriptionList[subsIdx].requestId.requestorId == ricReqId.requestorId) &&
3014 (ranFuncDb->subscriptionList[subsIdx].requestId.instanceId == ricReqId.instanceId))
3016 memset(&ranFuncDb->subscriptionList[subsIdx], 0, sizeof(RicSubscription));
3026 /*******************************************************************
3028 * @brief Free the ErrorIndication Message
3032 * Function : FreeRicIndication
3034 * Functionality: Free the ErrorIndication Message
3039 ******************************************************************/
3040 void FreeErrorIndication(E2AP_PDU_t *e2apMsg)
3043 ErrorIndicationE2_t *errorIndicationMsg= NULLP;
3045 if(e2apMsg != NULLP)
3047 if(e2apMsg->choice.initiatingMessage != NULLP)
3049 errorIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.ErrorIndicationE2;
3050 if(errorIndicationMsg!= NULLP)
3052 if(errorIndicationMsg->protocolIEs.list.array != NULLP)
3054 for(arrIdx=0; arrIdx<errorIndicationMsg->protocolIEs.list.count; arrIdx++)
3056 RIC_FREE(errorIndicationMsg->protocolIEs.list.array[arrIdx],sizeof(ErrorIndicationE2_t));
3058 RIC_FREE(errorIndicationMsg->protocolIEs.list.array,errorIndicationMsg->protocolIEs.list.size);
3061 RIC_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
3063 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
3068 /*******************************************************************
3070 * @brief Builds and Send the ErrorIndication Message
3074 * Function : BuildAndSendErrorIndication
3076 * Functionality:Fills the ErrorIndication Message
3084 * @return ROK - success
3087 ******************************************************************/
3089 uint8_t BuildAndSendErrorIndication(uint32_t duId, int8_t transId, RicRequestId requestId, uint16_t ranFuncId, uint8_t reason)
3091 uint8_t elementCnt =0, arrIdx=0, ret = RFAILED;
3092 E2AP_PDU_t *e2apMsg = NULLP;
3093 ErrorIndicationE2_t *errorIndicationMsg=NULLP;
3094 asn_enc_rval_t encRetVal; /* Encoder return value */
3098 DU_LOG("\nINFO --> E2AP : Building Error Indication Message\n");
3100 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
3101 if(e2apMsg == NULLP)
3103 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed in %s at line %d",__func__, __LINE__);
3107 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
3108 RIC_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
3109 if(e2apMsg->choice.initiatingMessage == NULLP)
3111 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed in %s at line %d",__func__, __LINE__);
3114 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_ErrorIndicationE2;
3115 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
3116 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_ErrorIndicationE2;
3118 errorIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.ErrorIndicationE2;
3120 /* Element count is 2 for TransactionID/RICrequestID and Cause.
3121 * If the RAN function id is present, the count will be increased.*/
3126 errorIndicationMsg->protocolIEs.list.count = elementCnt;
3127 errorIndicationMsg->protocolIEs.list.size = elementCnt * sizeof(ErrorIndicationE2_IEs_t*);
3129 /* Initialize the E2Setup members */
3130 RIC_ALLOC(errorIndicationMsg->protocolIEs.list.array, errorIndicationMsg->protocolIEs.list.size);
3131 if(errorIndicationMsg->protocolIEs.list.array == NULLP)
3133 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements in %s at line %d",__func__, __LINE__);
3136 for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
3138 RIC_ALLOC(errorIndicationMsg->protocolIEs.list.array[arrIdx], sizeof(ErrorIndicationE2_IEs_t));
3139 if(errorIndicationMsg->protocolIEs.list.array[arrIdx] == NULLP)
3141 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array Idx %d in %s at line %d",arrIdx,__func__, __LINE__);
3145 if(arrIdx < elementCnt)
3150 if(transId >=0 && transId<=255)
3153 errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
3154 errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3155 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_TransactionID;
3156 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
3161 errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RICrequestID;
3162 errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3163 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_RICrequestID;
3164 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.RICrequestID.ricRequestorID = requestId.requestorId;
3165 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.RICrequestID.ricInstanceID = requestId.instanceId;
3170 /* RAN Function ID */
3172 errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionID;
3173 errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
3174 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_RANfunctionID;
3175 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionID = ranFuncId;
3180 errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_CauseE2;
3181 errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_ignore;
3182 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_CauseE2;
3183 fillE2FailureCause(&errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.CauseE2, CauseE2_PR_misc, reason);
3186 /* Prints the Msg formed */
3187 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
3188 memset(encBuf, 0, ENC_BUF_MAX_LEN);
3190 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
3192 if(encRetVal.encoded == ENCODE_FAIL)
3194 DU_LOG("\nERROR --> E2AP : Could not encode Error Indication Message (at %s)\n",\
3195 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
3200 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for Error Indication Message \n");
3201 #ifdef DEBUG_ASN_PRINT
3202 for(int i=0; i< encBufSize; i++)
3204 printf("%x",encBuf[i]);
3209 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
3211 DU_LOG("\nINFO --> E2AP : Sending Error Indication Message");
3217 FreeErrorIndication(e2apMsg);
3221 /*******************************************************************
3223 * @brief Deallocate the memory allocated for ResetRequest msg
3227 * Function : FreeResetRequest
3230 * - freeing the memory allocated for ResetRequest
3232 * @params[in] E2AP_PDU_t *e2apMsg
3233 * @return ROK - success
3236 * ****************************************************************/
3237 void FreeResetRequest(E2AP_PDU_t *e2apMsg)
3240 ResetRequestE2_t *resetReq = NULLP;
3242 if(e2apMsg != NULLP)
3244 if(e2apMsg->choice.initiatingMessage != NULLP)
3246 resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
3247 if(resetReq->protocolIEs.list.array)
3249 for(ieIdx = 0; ieIdx < resetReq->protocolIEs.list.count; ieIdx++)
3251 RIC_FREE(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
3253 RIC_FREE(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
3255 RIC_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
3257 RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
3261 /*******************************************************************
3263 * @brief Build and send the reset request msg
3267 * Function : BuildAndSendResetRequest
3270 * - Buld and send the reset request msg to E2 node
3276 * @return ROK - success
3279 * ****************************************************************/
3280 uint8_t BuildAndSendResetRequest(DuDb *duDb, CauseE2_PR causePresent, uint8_t reason)
3282 uint8_t ieIdx = 0, elementCnt = 0, transId = 0;
3283 uint8_t ret = RFAILED;
3284 E2AP_PDU_t *e2apMsg = NULLP;
3285 ResetRequestE2_t *resetReq = NULLP;
3286 asn_enc_rval_t encRetVal; /* Encoder return value */
3288 DU_LOG("\nINFO --> E2AP : Building Reset Request\n");
3292 RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
3293 if(e2apMsg == NULLP)
3295 DU_LOG("\nERROR --> E2AP : BuildAndSendResetRequest(): Memory allocation for E2AP-PDU failed");
3299 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
3300 RIC_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
3301 if(e2apMsg->choice.initiatingMessage == NULLP)
3303 DU_LOG("\nERROR --> E2AP : BuildAndSendResetRequest(): Memory allocation for initiatingMessage");
3307 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_Reset;
3308 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
3309 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_ResetRequestE2;
3310 resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
3313 resetReq->protocolIEs.list.count = elementCnt;
3314 resetReq->protocolIEs.list.size = elementCnt * sizeof(ResetRequestIEs_t *);
3316 RIC_ALLOC(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
3317 if(!resetReq->protocolIEs.list.array)
3319 DU_LOG("\nERROR --> E2AP : BuildAndSendResetRequest(): Memory allocation failed for \
3320 Reset Request IE array");
3324 for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
3326 RIC_ALLOC(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
3327 if(!resetReq->protocolIEs.list.array[ieIdx])
3329 DU_LOG("\nERROR --> E2AP : BuildAndSendResetRequest(): Memory allocation failed for \
3330 Reset Request IE array element");
3335 /* In case of failure */
3336 if(ieIdx < elementCnt)
3340 resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
3341 resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
3342 resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_TransactionID;
3343 transId = assignTransactionId(duDb);
3344 resetReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
3347 resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_CauseE2;
3348 resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_ignore;
3349 resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_CauseE2;
3350 fillE2FailureCause(&resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2, causePresent, reason);
3352 /* Prints the Msg formed */
3353 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
3355 memset(encBuf, 0, ENC_BUF_MAX_LEN);
3357 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
3359 if(encRetVal.encoded == ENCODE_FAIL)
3361 DU_LOG("\nERROR --> E2AP : Could not encode reset request structure (at %s)\n",\
3362 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
3367 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for reset request\n");
3368 #ifdef DEBUG_ASN_PRINT
3369 for(int i=0; i< encBufSize; i++)
3371 printf("%x",encBuf[i]);
3375 if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duDb->duId) != ROK)
3377 DU_LOG("\nERROR --> E2AP : Sending reset request failed");
3386 /* Free all memory */
3387 FreeResetRequest(e2apMsg);
3391 /*******************************************************************
3393 * @brief Handles received E2AP message and sends back response
3397 * Function : E2APMsgHdlr
3400 * - Decodes received E2AP control message
3401 * - Prepares response message, encodes and sends to SCTP
3404 * @return ROK - success
3407 * ****************************************************************/
3408 void E2APMsgHdlr(uint32_t *duId, Buffer *mBuf)
3414 E2AP_PDU_t *e2apMsg;
3415 asn_dec_rval_t rval; /* Decoder return value */
3416 E2AP_PDU_t e2apasnmsg ;
3418 DU_LOG("\nINFO --> E2AP : Received E2AP message buffer");
3419 ODU_PRINT_MSG(mBuf, 0,0);
3421 /* Copy mBuf into char array to decode it */
3422 ODU_GET_MSG_LEN(mBuf, &recvBufLen);
3423 RIC_ALLOC(recvBuf, (Size)recvBufLen);
3425 if(recvBuf == NULLP)
3427 DU_LOG("\nERROR --> E2AP : Memory allocation failed");
3430 if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, ©Cnt) != ROK)
3432 DU_LOG("\nERROR --> E2AP : Failed while copying %d", copyCnt);
3436 DU_LOG("\nDEBUG --> E2AP : Received flat buffer to be decoded : ");
3437 for(i=0; i< recvBufLen; i++)
3439 DU_LOG("%x",recvBuf[i]);
3442 /* Decoding flat buffer into E2AP messsage */
3443 e2apMsg = &e2apasnmsg;
3444 memset(e2apMsg, 0, sizeof(E2AP_PDU_t));
3446 rval = aper_decode(0, &asn_DEF_E2AP_PDU, (void **)&e2apMsg, recvBuf, recvBufLen, 0, 0);
3447 RIC_FREE(recvBuf, (Size)recvBufLen);
3449 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
3451 DU_LOG("\nERROR --> E2AP : ASN decode failed");
3455 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
3457 switch(e2apMsg->present)
3459 case E2AP_PDU_PR_initiatingMessage:
3461 switch(e2apMsg->choice.initiatingMessage->value.present)
3463 case InitiatingMessageE2__value_PR_E2setupRequest:
3465 DU_LOG("\nINFO --> E2AP : E2 setup request received");
3466 ProcE2SetupReq(duId, &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest);
3469 case InitiatingMessageE2__value_PR_E2nodeConfigurationUpdate:
3471 DU_LOG("\nINFO --> E2AP : E2 node config update received");
3472 ProcE2NodeConfigUpdate(*duId, &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate);
3475 case InitiatingMessageE2__value_PR_ResetRequestE2:
3477 DU_LOG("\nINFO --> E2AP : E2 Reset Request received");
3478 ProcE2ResetReq(*duId, &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2);
3481 case InitiatingMessageE2__value_PR_RICindication:
3483 DU_LOG("\nINFO --> E2AP : RIC Indication received");
3486 case InitiatingMessageE2__value_PR_RICserviceUpdate:
3488 DU_LOG("\nINFO --> E2AP : RIC Service update received");
3489 ProcRicServiceUpdate(*duId, &e2apMsg->choice.initiatingMessage->value.choice.RICserviceUpdate);
3492 case InitiatingMessageE2__value_PR_ErrorIndicationE2:
3494 DU_LOG("\nINFO --> E2AP : Error indication received");
3499 DU_LOG("\nERROR --> E2AP : Invalid type of intiating message [%d]", \
3500 e2apMsg->choice.initiatingMessage->value.present);
3503 }/* End of switch(initiatingMessage) */
3506 case E2AP_PDU_PR_successfulOutcome:
3508 switch(e2apMsg->choice.successfulOutcome->value.present)
3510 case SuccessfulOutcomeE2__value_PR_RICsubscriptionResponse:
3512 ProcRicSubscriptionResponse(*duId, \
3513 &e2apMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse);
3518 DU_LOG("\nERROR --> E2AP : Invalid type of successfulOutcome message [%d]", \
3519 e2apMsg->choice.successfulOutcome->value.present);
3526 case E2AP_PDU_PR_unsuccessfulOutcome:
3528 switch(e2apMsg->choice.successfulOutcome->value.present)
3530 case UnsuccessfulOutcomeE2__value_PR_RICsubscriptionFailure:
3532 ProcRicSubscriptionFailure(*duId, \
3533 &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICsubscriptionFailure);
3538 DU_LOG("\nERROR --> E2AP : Invalid type of unsuccessfulOutcome message [%d]", \
3539 e2apMsg->choice.unsuccessfulOutcome->value.present);
3547 DU_LOG("\nERROR --> E2AP : Invalid type message type ");
3551 }/* End of switch(e2apMsg->present) */
3552 } /* End of E2APMsgHdlr */
3555 /**********************************************************************
3557 **********************************************************************/