1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
18 #include "common_def.h"
24 #include "du_app_mac_inf.h"
25 #include "du_app_rlc_inf.h"
26 #include "du_e2ap_mgr.h"
27 #include "du_e2ap_msg_hdl.h"
30 #include "du_mgr_main.h"
32 #include "GlobalE2node-gNB-ID.h"
33 #include "ProtocolIE-FieldE2.h"
34 #include "E2setupRequest.h"
35 #include "InitiatingMessageE2.h"
36 #include "SuccessfulOutcomeE2.h"
37 #include "UnsuccessfulOutcomeE2.h"
39 #include "odu_common_codec.h"
40 #include "E2nodeComponentInterfaceF1.h"
41 #include "E2setupRequest.h"
42 #include "du_e2_conversions.h"
43 #include "E2SM-KPM-RANfunction-Description.h"
44 #include "RANfunction-Name.h"
45 #include "RIC-EventTriggerStyle-Item.h"
46 #include "RIC-ReportStyle-Item.h"
47 #include "MeasurementInfo-Action-Item.h"
48 #include "E2SM-KPM-EventTriggerDefinition.h"
49 #include "E2SM-KPM-EventTriggerDefinition-Format1.h"
50 #include "E2SM-KPM-ActionDefinition.h"
51 #include "E2SM-KPM-ActionDefinition-Format1.h"
52 #include "MeasurementInfoItem.h"
53 #include "RANfunctionsIDcause-List.h"
54 #include "MeasurementRecord.h"
55 #include "MeasurementData.h"
56 #include "MeasurementRecordItem.h"
57 #include "MeasurementDataItem.h"
58 #include "E2SM-KPM-IndicationMessage-Format1.h"
59 #include "E2SM-KPM-IndicationMessage.h"
60 #include "E2SM-KPM-IndicationHeader.h"
61 #include "E2SM-KPM-IndicationHeader-Format1.h"
62 #include "LabelInfoItem.h"
64 /*******************************************************************
66 * @brief Fill E2 Failure Cause
70 * Function : fillE2Cause
72 * Functionality: Fill E2 Failure Cause
74 * @params[in] E2 Cause pointer to be filled in
75 * E2 Cause to be filled from
78 ******************************************************************/
79 void fillE2Cause(CauseE2_t *e2Cause, E2FailureCause failureCause)
81 e2Cause->present = failureCause.causeType;
82 switch(e2Cause->present)
84 case CauseE2_PR_ricRequest:
86 e2Cause->choice.ricRequest = failureCause.cause;
89 case CauseE2_PR_ricService:
91 e2Cause->choice.ricService = failureCause.cause;
94 case CauseE2_PR_e2Node:
96 e2Cause->choice.e2Node = failureCause.cause;
99 case CauseE2_PR_transport:
101 e2Cause->choice.transport = failureCause.cause;
104 case CauseE2_PR_protocol:
106 e2Cause->choice.protocol = failureCause.cause;
109 case CauseE2_PR_misc:
111 e2Cause->choice.misc = failureCause.cause;
114 case CauseE2_PR_NOTHING:
120 /*******************************************************************
122 * @brief Printing Type and Cause of failure
126 * Function : printE2ErrorCause
128 * Functionality: Printing Type and Cause of failure
130 * @params[in] E2 Cause
133 ******************************************************************/
134 void printE2ErrorCause(CauseE2_t *cause)
136 switch(cause->present)
138 case CauseE2_PR_ricRequest:
140 DU_LOG("Failure_Type [%s] Cause [%ld]", "RIC_Request", cause->choice.ricRequest);
143 case CauseE2_PR_ricService:
145 DU_LOG("Failure_Type [%s] Cause [%ld]", "RIC_Service", cause->choice.ricService);
148 case CauseE2_PR_e2Node:
150 DU_LOG("Failure_Type [%s] Cause [%ld]", "E2_Node", cause->choice.e2Node);
153 case CauseE2_PR_transport:
155 DU_LOG("Failure_Type [%s] Cause [%ld]", "Transport", cause->choice.transport);
158 case CauseE2_PR_protocol:
160 DU_LOG("Failure_Type [%s] Cause [%ld]", "Protocol", cause->choice.protocol);
163 case CauseE2_PR_misc:
165 DU_LOG("Failure_Type [%s] Cause [%ld]", "Miscellaneous", cause->choice.misc);
170 DU_LOG("Failure_Type and Cause unknown");
176 /*******************************************************************
178 * @brief Deallocate the memory allocated for E2 Removal Failure
182 * Function : FreeE2RemovalFailure
185 * - freeing the memory allocated for E2RemovalFailure
187 * @params[in] E2AP_PDU_t *e2apMsg
188 * @return ROK - success
191 * ****************************************************************/
192 void FreeE2RemovalFailure(E2AP_PDU_t *e2apMsg)
195 E2RemovalFailure_t *e2RemovalFailure=NULLP;
199 if(e2apMsg->choice.unsuccessfulOutcome != NULLP)
201 e2RemovalFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2RemovalFailure;
202 if(e2RemovalFailure->protocolIEs.list.array)
204 for(ieIdx=0; ieIdx < e2RemovalFailure->protocolIEs.list.count; ieIdx++)
206 if(e2RemovalFailure->protocolIEs.list.array[ieIdx])
208 DU_FREE(e2RemovalFailure->protocolIEs.list.array[ieIdx], sizeof(E2RemovalFailureIEs_t));
211 DU_FREE(e2RemovalFailure->protocolIEs.list.array, e2RemovalFailure->protocolIEs.list.size);
213 DU_FREE(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
215 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
219 /*******************************************************************
221 * @brief Buld and send the E2 Removal Failure msg
225 * Function : BuildAndSendE2RemovalFailure
228 * - Buld and send the E2 Removal Failure Message
229 * @params[in] Trans Id
230 * @return ROK - success
233 * ****************************************************************/
235 uint8_t BuildAndSendRemovalFailure(uint16_t transId, E2FailureCause failureCause)
237 uint8_t ieIdx = 0, elementCnt = 0;
238 uint8_t ret = RFAILED;
239 E2AP_PDU_t *e2apMsg = NULLP;
240 E2RemovalFailure_t *e2RemovalFailure=NULLP;
241 asn_enc_rval_t encRetVal; /* Encoder return value */
243 DU_LOG("\nINFO --> E2AP : Building E2 Removal Failure Message\n");
246 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
249 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
252 e2apMsg->present = E2AP_PDU_PR_unsuccessfulOutcome;
254 DU_ALLOC(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
255 if(e2apMsg->choice.unsuccessfulOutcome == NULLP)
257 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
261 e2apMsg->choice.unsuccessfulOutcome->procedureCode = ProcedureCodeE2_id_E2removal;
262 e2apMsg->choice.unsuccessfulOutcome->criticality = CriticalityE2_reject;
263 e2apMsg->choice.unsuccessfulOutcome->value.present = UnsuccessfulOutcomeE2__value_PR_E2RemovalFailure;
264 e2RemovalFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2RemovalFailure;
267 e2RemovalFailure->protocolIEs.list.count = elementCnt;
268 e2RemovalFailure->protocolIEs.list.size = elementCnt * sizeof(E2RemovalFailureIEs_t *);
269 DU_ALLOC(e2RemovalFailure->protocolIEs.list.array, e2RemovalFailure->protocolIEs.list.size);
270 if(!e2RemovalFailure->protocolIEs.list.array)
272 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
276 for(ieIdx=0; ieIdx < elementCnt; ieIdx++)
278 DU_ALLOC(e2RemovalFailure->protocolIEs.list.array[ieIdx], sizeof(E2RemovalFailureIEs_t));
279 if(!e2RemovalFailure->protocolIEs.list.array[ieIdx])
281 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
285 if(ieIdx < elementCnt)
289 e2RemovalFailure->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
290 e2RemovalFailure->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
291 e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.present = E2RemovalFailureIEs__value_PR_TransactionID;
292 e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
296 e2RemovalFailure->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_CauseE2;
297 e2RemovalFailure->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_ignore;
298 e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.present = ErrorIndicationE2_IEs__value_PR_CauseE2;
299 fillE2Cause(&e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.choice.CauseE2, failureCause);
301 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
303 memset(encBuf, 0, ENC_BUF_MAX_LEN);
305 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
306 if(encRetVal.encoded == ENCODE_FAIL)
308 DU_LOG("\nERROR --> E2AP : Could not encode E2 removal failure structure (at %s)\n",\
309 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
314 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Removal Failure \n");
315 for(int i=0; i< encBufSize; i++)
317 DU_LOG("%x",encBuf[i]);
322 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
324 DU_LOG("\nERROR --> E2AP : Failed to send E2 Removal Failure");
332 FreeE2RemovalFailure(e2apMsg);
336 /*******************************************************************
338 * @brief Deallocate the memory allocated for E2 Removal Response
342 * Function : FreeE2RemovalResponse
345 * - freeing the memory allocated for E2RemovalResponse
347 * @params[in] E2AP_PDU_t *e2apMsg
348 * @return ROK - success
351 * ****************************************************************/
352 void FreeE2RemovalResponse(E2AP_PDU_t *e2apMsg)
355 E2RemovalResponse_t *e2RemovalResponse=NULLP;
359 if(e2apMsg->choice.successfulOutcome != NULLP)
361 e2RemovalResponse = &e2apMsg->choice.successfulOutcome->value.choice.E2RemovalResponse;
362 if(e2RemovalResponse->protocolIEs.list.array)
364 for(ieIdx=0; ieIdx < e2RemovalResponse->protocolIEs.list.count; ieIdx++)
366 if(e2RemovalResponse->protocolIEs.list.array[ieIdx])
368 DU_FREE(e2RemovalResponse->protocolIEs.list.array[ieIdx], sizeof(E2RemovalResponseIEs_t));
371 DU_FREE(e2RemovalResponse->protocolIEs.list.array, e2RemovalResponse->protocolIEs.list.size);
373 DU_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
375 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
379 /*******************************************************************
381 * @brief Buld and send the E2 Removal Response msg
385 * Function : BuildAndSendE2RemovalResponse
388 * - Buld and send the E2 Removal Response Message
389 * @params[in] Trans Id
390 * @return ROK - success
393 * ****************************************************************/
394 uint8_t BuildAndSendRemovalResponse(uint16_t transId)
396 uint8_t ieIdx = 0, elementCnt = 0;
397 uint8_t ret = RFAILED;
398 E2AP_PDU_t *e2apMsg = NULLP;
399 E2RemovalResponse_t *e2RemovalResponse=NULLP;
400 asn_enc_rval_t encRetVal; /* Encoder return value */
402 DU_LOG("\nINFO --> E2AP : Building E2 Removal Response Message\n");
405 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
408 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
411 e2apMsg->present = E2AP_PDU_PR_successfulOutcome;
413 DU_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
414 if(e2apMsg->choice.successfulOutcome == NULLP)
416 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
420 e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_E2removal;
421 e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
422 e2apMsg->choice.successfulOutcome->value.present = SuccessfulOutcomeE2__value_PR_E2RemovalResponse;
423 e2RemovalResponse = &e2apMsg->choice.successfulOutcome->value.choice.E2RemovalResponse;
426 e2RemovalResponse->protocolIEs.list.count = elementCnt;
427 e2RemovalResponse->protocolIEs.list.size = elementCnt * sizeof(E2RemovalResponseIEs_t *);
428 DU_ALLOC(e2RemovalResponse->protocolIEs.list.array, e2RemovalResponse->protocolIEs.list.size);
429 if(!e2RemovalResponse->protocolIEs.list.array)
431 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
435 for(ieIdx=0; ieIdx < elementCnt; ieIdx++)
437 DU_ALLOC(e2RemovalResponse->protocolIEs.list.array[ieIdx], sizeof(E2RemovalResponseIEs_t));
438 if(!e2RemovalResponse->protocolIEs.list.array[ieIdx])
440 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
444 if(ieIdx < elementCnt)
448 e2RemovalResponse->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
449 e2RemovalResponse->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
450 e2RemovalResponse->protocolIEs.list.array[ieIdx]->value.present = E2RemovalResponseIEs__value_PR_TransactionID;
451 e2RemovalResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
453 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
455 memset(encBuf, 0, ENC_BUF_MAX_LEN);
457 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
458 if(encRetVal.encoded == ENCODE_FAIL)
460 DU_LOG("\nERROR --> E2AP : Could not encode E2 removal response structure (at %s)\n",\
461 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
466 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Removal Response \n");
467 for(int i=0; i< encBufSize; i++)
469 DU_LOG("%x",encBuf[i]);
474 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
476 DU_LOG("\nERROR --> E2AP : Failed to send E2 Removal Response");
484 FreeE2RemovalResponse(e2apMsg);
485 removeE2NodeInformation();
489 /******************************************************************
491 * @brief Deallocation of memory allocated by aper decoder for Removal req
495 * Function : freeAperDecodingOfE2RemovalReq
497 * Functionality: Deallocation of memory allocated by aper decoder for
500 * @params[in] Pointer to removalReq
503 * ****************************************************************/
504 void freeAperDecodingOfE2RemovalReq(E2RemovalRequest_t *removalReq)
510 if(removalReq->protocolIEs.list.array)
512 for(arrIdx=0; arrIdx<removalReq->protocolIEs.list.count; arrIdx++)
514 if(removalReq->protocolIEs.list.array[arrIdx])
516 free(removalReq->protocolIEs.list.array[arrIdx]);
519 free(removalReq->protocolIEs.list.array);
524 /*******************************************************************
526 * @brief Process Removal req received from RIC
530 * Function : procE2RemovalRequest
532 * Functionality: Process Removal req received from RIC
534 * @param E2AP_PDU_t *e2apMsg
537 ******************************************************************/
539 void procE2RemovalRequest(E2AP_PDU_t *e2apMsg)
543 E2FailureCause failureCause;
544 E2RemovalRequest_t *removalReq=NULLP;
546 DU_LOG("\nINFO --> E2AP : E2 Removal request received");
547 removalReq = &e2apMsg->choice.initiatingMessage->value.choice.E2RemovalRequest;
549 for(arrIdx=0; arrIdx<removalReq->protocolIEs.list.count; arrIdx++)
551 switch(removalReq->protocolIEs.list.array[arrIdx]->id)
553 case ProtocolIE_IDE2_id_TransactionID:
555 transId = removalReq->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
560 DU_LOG("\nERROR --> E2AP : Invalid IE recevied [%d]", transId);
566 if(transId>=0 && transId<=255)
568 if(BuildAndSendRemovalResponse(transId) != ROK)
570 DU_LOG("\nERROR --> E2AP : Failed to build and send Removal response");
575 failureCause.causeType = E2_PROTOCOL;
576 failureCause.cause = E2_ABSTRACT_SYNTAX_ERROR_FALSELY_CONSTRUCTED_MESSAGE;
578 if(BuildAndSendRemovalFailure(transId, failureCause) != ROK)
580 DU_LOG("\nERROR --> E2AP : Failed to build and send Removal response");
583 freeAperDecodingOfE2RemovalReq(removalReq);
586 /*******************************************************************
588 * @brief Free the ErrorIndication Message
592 * Function : FreeRicIndication
594 * Functionality: Free the ErrorIndication Message
597 * E2AP_PDU is to freed
600 ******************************************************************/
601 void FreeErrorIndication(E2AP_PDU_t *e2apMsg)
604 ErrorIndicationE2_t *errorIndicationMsg= NULLP;
608 if(e2apMsg->choice.initiatingMessage != NULLP)
610 errorIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.ErrorIndicationE2;
611 if(errorIndicationMsg!= NULLP)
613 if(errorIndicationMsg->protocolIEs.list.array != NULLP)
615 for(arrIdx=0; arrIdx<errorIndicationMsg->protocolIEs.list.count; arrIdx++)
617 DU_FREE(errorIndicationMsg->protocolIEs.list.array[arrIdx],sizeof(ErrorIndicationE2_t));
619 DU_FREE(errorIndicationMsg->protocolIEs.list.array,errorIndicationMsg->protocolIEs.list.size);
622 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
624 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
628 /*******************************************************************
630 * @brief Builds and Send the ErrorIndication Message
634 * Function : BuildAndSendErrorIndication
636 * Functionality:Fills the ErrorIndication Message
643 * @return ROK - success
646 ******************************************************************/
648 uint8_t BuildAndSendErrorIndication(int8_t transId, RicRequestId requestId, uint16_t ranFuncId, E2FailureCause failureCause)
650 uint8_t elementCnt =0, arrIdx=0, ret = RFAILED;
651 E2AP_PDU_t *e2apMsg = NULLP;
652 ErrorIndicationE2_t *errorIndicationMsg=NULLP;
653 asn_enc_rval_t encRetVal; /* Encoder return value */
657 DU_LOG("\nINFO --> E2AP : Building Error Indication Message\n");
659 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
662 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed in %s at line %d",__func__, __LINE__);
666 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
667 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
668 if(e2apMsg->choice.initiatingMessage == NULLP)
670 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed in %s at line %d",__func__, __LINE__);
673 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_ErrorIndicationE2;
674 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
675 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_ErrorIndicationE2;
677 errorIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.ErrorIndicationE2;
679 /* Element count is 2 for TransactionID/RICrequestID and Cause.
680 * If the RAN function id is present, the count will be increased.*/
687 errorIndicationMsg->protocolIEs.list.count = elementCnt;
688 errorIndicationMsg->protocolIEs.list.size = elementCnt * sizeof(ErrorIndicationE2_IEs_t*);
690 /* Initialize the E2Setup members */
691 DU_ALLOC(errorIndicationMsg->protocolIEs.list.array, errorIndicationMsg->protocolIEs.list.size);
692 if(errorIndicationMsg->protocolIEs.list.array == NULLP)
694 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements in %s at line %d",__func__, __LINE__);
698 for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
700 DU_ALLOC(errorIndicationMsg->protocolIEs.list.array[arrIdx], sizeof(ErrorIndicationE2_IEs_t));
701 if(errorIndicationMsg->protocolIEs.list.array[arrIdx] == NULLP)
703 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array [%d] elements in %s at line %d", arrIdx, __func__, __LINE__);
707 if(arrIdx < elementCnt)
712 if(transId >=0 && transId<=255)
715 errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
716 errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
717 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_TransactionID;
718 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
723 errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RICrequestID;
724 errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
725 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_RICrequestID;
726 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.RICrequestID.ricRequestorID = requestId.requestorId;
727 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.RICrequestID.ricInstanceID = requestId.instanceId;
732 /* RAN Function ID */
734 errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionID;
735 errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
736 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_RANfunctionID;
737 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionID = ranFuncId;
742 errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_CauseE2;
743 errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_ignore;
744 errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_CauseE2;
745 fillE2Cause(&errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.CauseE2, failureCause);
747 /* Prints the Msg formed */
748 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
749 memset(encBuf, 0, ENC_BUF_MAX_LEN);
751 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
753 if(encRetVal.encoded == ENCODE_FAIL)
755 DU_LOG("\nERROR --> E2AP : Could not encode Error Indication Message (at %s)\n",\
756 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
761 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for Error Indication Message \n");
762 #ifdef DEBUG_ASN_PRINT
763 for(int i=0; i< encBufSize; i++)
765 printf("%x",encBuf[i]);
770 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
772 DU_LOG("\nINFO --> E2AP : Sending Error Indication Message");
778 FreeErrorIndication(e2apMsg);
782 /******************************************************************
784 * @brief Deallocation of memory allocated by aper decoder for e2
785 * Config Update Failure
789 * Function : freeAperDecodingOfE2Node Config UpdateFailure
791 * Functionality: Deallocation of memory allocated by aper decoder
792 * for e2 Config Update Failure
794 * @params[in] E2nodeConfigurationUpdateFailure_t to be deallocated
797 * ****************************************************************/
799 void freeAperDecodingOfE2NodeConfigUpdateFailure(E2nodeConfigurationUpdateFailure_t *e2NodeCfgUpdFail)
805 if(e2NodeCfgUpdFail->protocolIEs.list.array)
807 for(arrIdx=0; arrIdx<e2NodeCfgUpdFail->protocolIEs.list.count; arrIdx++)
809 if(e2NodeCfgUpdFail->protocolIEs.list.array[arrIdx])
811 free(e2NodeCfgUpdFail->protocolIEs.list.array[arrIdx]);
814 free(e2NodeCfgUpdFail->protocolIEs.list.array);
819 /******************************************************************
821 * @brief Processes E2 Node Config Update Failure sent by RIC
825 * Function : procE2NodeConfigUpdateFailure
827 * Functionality: Processes E2 Node Config Update failure sent by RIC
829 * @params[in] E2AP_PDU_t ASN decoded E2AP message
830 * @return ROK - success
833 * ****************************************************************/
835 void procE2NodeConfigUpdateFailure(E2AP_PDU_t *e2apMsg)
837 uint8_t arrIdx =0, transId =0, timerValue=0;
838 E2nodeConfigurationUpdateFailure_t *e2NodeCfgUpdFail=NULL;
840 DU_LOG("\nINFO --> E2AP : E2 Node Config Update failure received");
841 e2NodeCfgUpdFail = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2nodeConfigurationUpdateFailure;
843 for(arrIdx=0; arrIdx<e2NodeCfgUpdFail->protocolIEs.list.count; arrIdx++)
845 switch(e2NodeCfgUpdFail->protocolIEs.list.array[arrIdx]->id)
847 case ProtocolIE_IDE2_id_TransactionID:
849 transId = e2NodeCfgUpdFail->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
850 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
851 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
853 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
857 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
861 case ProtocolIE_IDE2_id_TimeToWaitE2:
863 timerValue = convertE2WaitTimerEnumToValue(e2NodeCfgUpdFail->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2);
864 if((duChkTmr((PTR)&(duCb.e2apDb), EVENT_E2_NODE_CONFIG_UPDATE_TMR)) == FALSE)
866 duStartTmr((PTR)&(duCb.e2apDb), EVENT_E2_NODE_CONFIG_UPDATE_TMR, timerValue);
870 DU_LOG("\nERROR --> E2AP : EVENT_E2_NODE_CONFIG_UPDATE_TMR timer is already running");
877 freeAperDecodingOfE2NodeConfigUpdateFailure(e2NodeCfgUpdFail);
880 /*******************************************************************
882 * @brief Builds Global gNodeB Params
886 * Function : BuildGlobalgNBId
888 * Functionality: Building the Plmn and gNB id
890 * @params[in] GlobalE2node_gNB_ID_t *gNbId
891 * @return ROK - success
894 ******************************************************************/
896 uint8_t BuildGlobalgNBId(GlobalE2node_gNB_ID_t *gNbId)
899 uint8_t byteSize = 4;
900 uint8_t gnbId = duCb.gnbId;
903 /* fill Global gNB ID Id */
904 gNbId->global_gNB_ID.plmn_id.size = 3 * sizeof(uint8_t);
905 gNbId->global_gNB_ID.plmn_id.buf = NULLP;
906 DU_ALLOC(gNbId->global_gNB_ID.plmn_id.buf , gNbId->global_gNB_ID.plmn_id.size);
907 if(gNbId->global_gNB_ID.plmn_id.buf == NULLP)
909 DU_LOG("\nERROR --> E2AP: Memory allocation failed for Plmn buffer");
914 buildPlmnId(duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.nrCgi.plmn, \
915 gNbId->global_gNB_ID.plmn_id.buf);
916 gNbId->global_gNB_ID.gnb_id.present = GNB_ID_Choice_PR_gnb_ID;
917 /* Allocate Buffer size */
918 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size = byteSize * sizeof(uint8_t);
919 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf = NULLP;
920 DU_ALLOC(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf, \
921 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
922 if(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf == NULLP)
924 DU_LOG("\nERROR --> E2AP: Memory allocation failed for gnb buffer");
929 fillBitString(&gNbId->global_gNB_ID.gnb_id.choice.gnb_ID, unused, byteSize, gnbId);
934 DU_ALLOC( gNbId->gNB_DU_ID, sizeof(GNB_DU_ID_t));
935 if(gNbId->gNB_DU_ID == NULLP)
937 DU_LOG("\nERROR --> E2AP: Memory allocation failed for gNB_DU_ID ");
942 gNbId->gNB_DU_ID->size = sizeof(uint8_t);
943 DU_ALLOC( gNbId->gNB_DU_ID->buf, sizeof(uint8_t));
944 if(gNbId->gNB_DU_ID->buf)
946 gNbId->gNB_DU_ID->buf[0] =duCb.e2apDb.e2NodeId;
950 DU_LOG("\nERROR --> E2AP: Memory allocation failed for gNB_DU_ID buffer");
958 /*******************************************************************
960 * @brief fill the E2 node config information
964 * Function : fillE2NodeConfig
966 * Functionality: fill E2 node config information
969 * Pointer to e2NodeCfg to be filled
970 * E2 Node Component information
971 * Type of configuration
972 * @return ROK - success
975 ******************************************************************/
977 uint8_t fillE2NodeConfig(PTR e2NodeCfg, E2NodeComponent *e2NodeComponentInfo, ConfigType configType)
979 E2NodeConfig *e2NodeConfig=NULLP;
980 E2nodeComponentInterfaceType_t *interfaceType=NULLP;
981 E2nodeComponentID_t *componentID =NULLP;
982 E2nodeComponentConfiguration_t *configuration=NULLP;
983 E2nodeComponentConfigAddition_Item_t *e2NodeAddItem=NULL;
984 E2nodeComponentConfigUpdate_Item_t *e2NodeUpdateItem =NULL;
985 E2nodeComponentConfigRemoval_Item_t *e2NodeRemovalItem=NULL;
991 e2NodeAddItem = (E2nodeComponentConfigAddition_Item_t*)e2NodeCfg;
992 interfaceType = &e2NodeAddItem->e2nodeComponentInterfaceType;
993 componentID = &e2NodeAddItem->e2nodeComponentID;
994 configuration = &e2NodeAddItem->e2nodeComponentConfiguration;
995 e2NodeConfig = e2NodeComponentInfo->addConfiguration;
1000 e2NodeUpdateItem = (E2nodeComponentConfigUpdate_Item_t *) e2NodeCfg;
1001 interfaceType = &e2NodeUpdateItem->e2nodeComponentInterfaceType;
1002 componentID = &e2NodeUpdateItem->e2nodeComponentID;
1003 configuration = &e2NodeUpdateItem->e2nodeComponentConfiguration;
1004 e2NodeConfig = e2NodeComponentInfo->updateConfiguration;
1009 e2NodeRemovalItem = (E2nodeComponentConfigRemoval_Item_t*) e2NodeCfg;
1010 interfaceType = &e2NodeRemovalItem->e2nodeComponentInterfaceType;
1011 componentID = &e2NodeRemovalItem->e2nodeComponentID;
1016 DU_LOG("\nERROR --> E2AP : Configuration type %d does not supported ", configType);
1020 /* E2nodeComponentInterfaceType */
1021 *interfaceType = convertInterfaceToE2ComponentInterfaceType(e2NodeComponentInfo->interfaceType);
1023 /* We now only support the F1 interface out of these interfaces
1024 * (NG,XN,E1,F1,W1,S1,X2), therefore only the F1 component identifier was filled in. */
1026 if(*interfaceType == F1)
1028 /* E2 Node Component ID */
1029 componentID->present = E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1;
1030 DU_ALLOC(componentID->choice.e2nodeComponentInterfaceTypeF1,sizeof(E2nodeComponentInterfaceF1_t));
1031 if(componentID->choice.e2nodeComponentInterfaceTypeF1 == NULLP)
1033 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at line %d",__func__,__LINE__);
1036 componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size = sizeof(uint8_t);
1037 DU_ALLOC(componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
1038 componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
1040 if(componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf == NULLP)
1042 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at line %d",__func__,__LINE__);
1045 memcpy(componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf, &e2NodeComponentInfo->componentId,\
1046 componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
1049 if(configType == CONFIG_DEL)
1051 /* We don't need to fill out the E2 Node Component Request and Response
1052 * information in the case of CONFIG_DEL, therefore returning ROK from here. */
1056 /* E2 Node Component Request Part */
1057 if(e2NodeConfig->componentRequestPart)
1059 configuration->e2nodeComponentRequestPart.size = e2NodeConfig->reqBufSize ;
1060 DU_ALLOC(configuration->e2nodeComponentRequestPart.buf,\
1061 configuration->e2nodeComponentRequestPart.size);
1062 if(configuration->e2nodeComponentRequestPart.buf == NULLP)
1064 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at line %d",__func__,__LINE__);
1068 memcpy(configuration->e2nodeComponentRequestPart.buf,\
1069 e2NodeConfig->componentRequestPart, configuration->\
1070 e2nodeComponentRequestPart.size);
1074 DU_LOG("\nERROR --> E2AP: componentRequestPart is null ");
1078 /* E2 Node Component Response Part */
1079 if(e2NodeConfig->componentResponsePart)
1081 configuration->e2nodeComponentResponsePart.size = e2NodeConfig->rspBufSize;
1082 DU_ALLOC(configuration->e2nodeComponentResponsePart.buf, configuration->e2nodeComponentResponsePart.size);
1083 if(configuration->e2nodeComponentResponsePart.buf == NULLP)
1085 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at line %d",__func__,__LINE__);
1088 memcpy(configuration->e2nodeComponentResponsePart.buf, e2NodeConfig->componentResponsePart, configuration->\
1089 e2nodeComponentResponsePart.size);
1093 DU_LOG("\nERROR --> E2AP: componentResponsePart is null");
1100 /*******************************************************************
1102 * @brief Builds E2 node config addition list
1106 * Function : BuildE2NodeConfigAddList
1108 * Functionality: Building E2 node config addition list
1111 * E2nodeComponentConfigAddition_List_t to be filled
1113 * Count of E2 node to be added in the list
1114 * Received list of E2 node configuration
1116 * @return ROK - success
1119 ******************************************************************/
1121 uint8_t BuildE2NodeConfigAddList(E2nodeComponentConfigAddition_List_t *e2NodeAddList, uint8_t procedureCode, uint16_t count, E2NodeConfigItem *e2NodeList)
1124 CmLList *node =NULL;
1125 E2NodeComponent *e2NodeComponentInfo=NULL;
1126 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItemIe=NULL;
1127 E2nodeComponentConfigAddition_Item_t *e2NodeAddItem=NULL;
1130 /* For ProcedureCodeE2_id_E2setup, the number of E2 node configuration list items is
1131 * equal to the number of E2 node configuration entries stored in the database.
1132 * For any other procedure, the E2 node configuration list count is equal
1133 * to the count of E2 node configuration obtained from the function's caller */
1135 if(procedureCode == ProcedureCodeE2_id_E2setup)
1136 e2NodeAddList->list.count = duCb.e2apDb.e2NodeComponentList.count;
1138 e2NodeAddList->list.count = count;
1140 e2NodeAddList->list.size = e2NodeAddList->list.count * sizeof(E2nodeComponentConfigAddition_ItemIEs_t *);
1141 DU_ALLOC(e2NodeAddList->list.array, e2NodeAddList->list.size);
1142 if(e2NodeAddList->list.array == NULLP)
1144 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
1148 for(arrIdx = 0; arrIdx< e2NodeAddList->list.count; arrIdx++)
1150 DU_ALLOC(e2NodeAddList->list.array[arrIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
1151 if(e2NodeAddList->list.array[arrIdx] == NULLP)
1153 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigAddList %d",__LINE__);
1157 if(procedureCode == ProcedureCodeE2_id_E2setup)
1159 /* Getting all of the E2 node configuration's information from DuCb one by one*/
1162 CM_LLIST_FIRST_NODE(&duCb.e2apDb.e2NodeComponentList, node);
1170 DU_LOG("\nERROR --> E2AP : E2 node component list node is null");
1173 e2NodeComponentInfo = (E2NodeComponent*)node->node;
1177 /* Getting only those E2 node configuration from DuCb whose interface
1178 * and action type is present in the received array */
1179 e2NodeComponentInfo = fetchE2NodeComponentInfo(e2NodeList[arrIdx].interface, e2NodeList[arrIdx].componentId, &node);
1182 if(!e2NodeComponentInfo)
1184 DU_LOG("\nERROR --> E2AP : Received null e2NodeComponentInfo at line number %d",__LINE__);
1188 e2NodeAddItemIe = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[arrIdx];
1189 e2NodeAddItemIe->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition_Item;
1190 e2NodeAddItemIe->criticality = CriticalityE2_reject;
1191 e2NodeAddItemIe->value.present = E2nodeComponentConfigAddition_ItemIEs__value_PR_E2nodeComponentConfigAddition_Item;
1192 e2NodeAddItem = &e2NodeAddItemIe->value.choice.E2nodeComponentConfigAddition_Item;
1193 if(fillE2NodeConfig((PTR)e2NodeAddItem, e2NodeComponentInfo, CONFIG_ADD) != ROK)
1195 DU_LOG("\nERROR --> E2AP : Failed to fill the E2 node configuration");
1202 /*******************************************************************
1204 * @brief Builds E2 node config update list
1208 * Function : BuildE2NodeConfigUpdateList
1210 * Functionality: Building E2 node config update list
1213 * E2nodeComponentConfigUpdate_List_t to be filled
1214 * Count of E2 node to be update in the list
1215 * Received list of E2 node configuration
1217 * @return ROK - success
1220 ******************************************************************/
1222 uint8_t BuildE2NodeConfigUpdateList(E2nodeComponentConfigUpdate_List_t *e2NodeUpdateList, uint16_t count, E2NodeConfigItem *updateE2Node)
1225 CmLList *node =NULL;
1226 E2NodeComponent *e2NodeComponentInfo =NULL;
1227 E2nodeComponentConfigUpdate_ItemIEs_t *e2NodeUpdateItemIe =NULL;
1228 E2nodeComponentConfigUpdate_Item_t *e2NodeUpdateItem =NULL;
1230 e2NodeUpdateList->list.count = count;
1231 e2NodeUpdateList->list.size = e2NodeUpdateList->list.count * sizeof(E2nodeComponentConfigUpdate_ItemIEs_t *);
1232 DU_ALLOC(e2NodeUpdateList->list.array, e2NodeUpdateList->list.size);
1233 if(e2NodeUpdateList->list.array == NULLP)
1235 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigUpdateList %d",__LINE__);
1239 for(arrIdx = 0; arrIdx< e2NodeUpdateList->list.count; arrIdx++)
1241 DU_ALLOC(e2NodeUpdateList->list.array[arrIdx], sizeof(E2nodeComponentConfigUpdate_ItemIEs_t));
1242 if(e2NodeUpdateList->list.array[arrIdx] == NULLP)
1244 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigUpdateList %d",__LINE__);
1248 e2NodeComponentInfo= fetchE2NodeComponentInfo(updateE2Node[arrIdx].interface, updateE2Node[arrIdx].componentId, &node);
1249 if(!e2NodeComponentInfo)
1251 DU_LOG("\nERROR --> E2AP : Received null e2NodeComponentInfo at line number %d",__LINE__);
1255 e2NodeUpdateItemIe = (E2nodeComponentConfigUpdate_ItemIEs_t *) e2NodeUpdateList->list.array[arrIdx];
1256 e2NodeUpdateItemIe->id = ProtocolIE_IDE2_id_E2nodeComponentConfigUpdate_Item;
1257 e2NodeUpdateItemIe->criticality = CriticalityE2_reject;
1258 e2NodeUpdateItemIe->value.present = E2nodeComponentConfigUpdate_ItemIEs__value_PR_E2nodeComponentConfigUpdate_Item;
1259 e2NodeUpdateItem = &e2NodeUpdateItemIe->value.choice.E2nodeComponentConfigUpdate_Item;
1261 if(fillE2NodeConfig((PTR)e2NodeUpdateItem, e2NodeComponentInfo, CONFIG_MOD) != ROK)
1263 DU_LOG("\nERROR --> E2AP : Failed to fill the E2 node configuration");
1273 /*******************************************************************
1275 * @brief Builds E2 node config remove list
1279 * Function :BuildE2NodeConfigRemoveList
1281 * Functionality: Building E2 node config remove list
1284 * E2nodeComponentConfigRemoval_List_t to be filled
1285 * Count of E2 node to be remove in the list
1286 * Received list of E2 node configuration
1287 * @return ROK - success
1290 ******************************************************************/
1292 uint8_t BuildE2NodeConfigRemoveList(E2nodeComponentConfigRemoval_List_t *e2NodeRemoveList, uint16_t count, E2NodeConfigItem *updateE2Node)
1296 E2NodeComponent *e2NodeComponentInfo=NULL;
1297 E2nodeComponentConfigRemoval_ItemIEs_t *e2NodeRemovalItemIe=NULL;
1298 E2nodeComponentConfigRemoval_Item_t *e2NodeRemovalItem=NULL;
1300 e2NodeRemoveList->list.count = count;
1301 e2NodeRemoveList->list.size = e2NodeRemoveList->list.count * sizeof(E2nodeComponentConfigRemoval_ItemIEs_t *);
1302 DU_ALLOC(e2NodeRemoveList->list.array, e2NodeRemoveList->list.size);
1303 if(e2NodeRemoveList->list.array == NULLP)
1305 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigRemoveList %d",__LINE__);
1309 for(arrIdx = 0; arrIdx< e2NodeRemoveList->list.count; arrIdx++)
1311 DU_ALLOC(e2NodeRemoveList->list.array[arrIdx], sizeof(E2nodeComponentConfigRemoval_ItemIEs_t));
1312 if(e2NodeRemoveList->list.array[arrIdx] == NULLP)
1314 DU_LOG("\nERROR --> E2AP: Memory allocation failed for BuildE2NodeConfigRemoveList %d",__LINE__);
1318 e2NodeComponentInfo= fetchE2NodeComponentInfo(updateE2Node[arrIdx].interface,updateE2Node[arrIdx].componentId, &node);
1319 if(!e2NodeComponentInfo)
1321 DU_LOG("\nERROR --> E2AP : Received null e2NodeComponentInfo at line number %d",__LINE__);
1325 e2NodeRemovalItemIe = (E2nodeComponentConfigRemoval_ItemIEs_t *) e2NodeRemoveList->list.array[arrIdx];
1326 e2NodeRemovalItemIe->id = ProtocolIE_IDE2_id_E2nodeComponentConfigRemoval_Item;
1327 e2NodeRemovalItemIe->criticality = CriticalityE2_reject;
1328 e2NodeRemovalItemIe->value.present = E2nodeComponentConfigRemoval_ItemIEs__value_PR_E2nodeComponentConfigRemoval_Item;
1329 e2NodeRemovalItem = &e2NodeRemovalItemIe->value.choice.E2nodeComponentConfigRemoval_Item;
1331 if(fillE2NodeConfig((PTR)e2NodeRemovalItem, e2NodeComponentInfo, CONFIG_DEL) != ROK)
1333 DU_LOG("\nERROR --> E2AP : Failed to fill the E2 node configuration");
1340 /*******************************************************************
1342 * @brief deallocation of E2SM_KPM_RANfunction_Description_t
1346 * Function : freeE2smKpmRanFunctionDefinition
1348 * Functionality: deallocation of E2SM_KPM_RANfunction_Description_t
1350 * @params[in] E2SM_KPM_RANfunction_Description_t *ranFunctionDefinition
1353 ******************************************************************/
1355 void freeE2smKpmRanFunctionDefinition(E2SM_KPM_RANfunction_Description_t *ranFunctionDefinition)
1357 MeasurementInfo_Action_Item_t *measInfoList;
1358 uint8_t eventTriggerIdx, reportStyleIdx, measInfoIdx;
1359 RANfunction_Name_t *ranFuncName;
1360 struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle;
1361 struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List *eventTriggerStyle;
1362 if(ranFunctionDefinition)
1364 ranFuncName = &ranFunctionDefinition->ranFunction_Name;
1365 /* Free RAN function Name */
1366 DU_FREE(ranFuncName->ranFunction_ShortName.buf, ranFuncName->ranFunction_ShortName.size);
1367 DU_FREE(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncName->ranFunction_E2SM_OID.size);
1368 DU_FREE(ranFuncName->ranFunction_Description.buf, ranFuncName->ranFunction_Description.size);
1370 /* Sequence of Event Trigger styles */
1371 eventTriggerStyle = ranFunctionDefinition->ric_EventTriggerStyle_List;
1372 if(eventTriggerStyle)
1374 if(eventTriggerStyle->list.array)
1376 for(eventTriggerIdx =0;eventTriggerIdx<eventTriggerStyle->list.count; eventTriggerIdx++)
1378 if(eventTriggerStyle->list.array[eventTriggerIdx])
1380 DU_FREE(eventTriggerStyle->list.array[eventTriggerIdx]->ric_EventTriggerStyle_Name.buf,\
1381 eventTriggerStyle->list.array[eventTriggerIdx]->ric_EventTriggerStyle_Name.size);
1382 DU_FREE(eventTriggerStyle->list.array[eventTriggerIdx], sizeof(RIC_EventTriggerStyle_Item_t ));
1385 DU_FREE(eventTriggerStyle->list.array, eventTriggerStyle->list.size)
1387 DU_FREE(eventTriggerStyle, sizeof(struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
1390 /* Sequence of Report styles */
1391 ricReportStyle = ranFunctionDefinition->ric_ReportStyle_List;
1394 if(ricReportStyle->list.array)
1396 for(reportStyleIdx =0;reportStyleIdx<ricReportStyle->list.count; reportStyleIdx++)
1398 if(ricReportStyle->list.array[reportStyleIdx])
1400 if(ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.buf)
1402 DU_FREE(ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.buf,\
1403 ricReportStyle->list.array[reportStyleIdx]->ric_ReportStyle_Name.size);
1405 if(ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.array)
1407 for(measInfoIdx=0; measInfoIdx<ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.count; \
1410 measInfoList = ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.array[measInfoIdx];
1413 DU_FREE(measInfoList->measID, sizeof(long));
1414 DU_FREE(measInfoList->measName.buf, measInfoList->measName.size);
1415 DU_FREE(measInfoList,sizeof(MeasurementInfo_Action_Item_t));
1418 DU_FREE(measInfoList,ricReportStyle->list.array[reportStyleIdx]->measInfo_Action_List.list.size);
1420 DU_FREE(ricReportStyle->list.array[reportStyleIdx], sizeof(RIC_ReportStyle_Item_t));
1423 DU_FREE(ricReportStyle->list.array, ricReportStyle->list.size);
1425 DU_FREE(ricReportStyle, sizeof(struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
1427 DU_FREE(ranFunctionDefinition, sizeof(E2SM_KPM_RANfunction_Description_t));
1431 /*******************************************************************
1433 * @brief fill the e2sm ric report style
1437 * Function : fillRicReportStyle
1439 * Functionality: fill the report style
1441 * @params[in] RanFunction *ranFuncDb, struct
1442 * E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle
1443 * @return ROK - success
1446 ******************************************************************/
1447 uint8_t fillRicReportStyle(RanFunction *ranFuncDb, struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List *ricReportStyle)
1449 uint8_t styleIdx, measInfoIdx;
1450 MeasurementInfo_Action_List_t *measInfo;
1453 ricReportStyle->list.count = ranFuncDb->numOfReportStyleSupported;
1454 ricReportStyle->list.size = ricReportStyle->list.count * sizeof(RIC_ReportStyle_Item_t*);
1455 DU_ALLOC(ricReportStyle->list.array, ricReportStyle->list.size);
1456 if(!ricReportStyle->list.array)
1458 DU_LOG("\nERROR --> E2AP: Memory allocation failed for ranFuncDefinition %d",__LINE__);
1462 for(styleIdx =0;styleIdx<ricReportStyle->list.count; styleIdx++)
1464 DU_ALLOC(ricReportStyle->list.array[styleIdx], sizeof(RIC_ReportStyle_Item_t));
1465 if(!ricReportStyle->list.array[styleIdx])
1467 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1471 /* RIC Report Style Type */
1472 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Type = ranFuncDb->reportStyleList[styleIdx].reportStyle.styleType;
1474 /* RIC Report Style Format Type */
1475 ricReportStyle->list.array[styleIdx]->ric_ActionFormat_Type = ranFuncDb->reportStyleList[styleIdx].reportStyle.formatType;
1477 /* RIC Report Style Name */
1478 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size = strlen(ranFuncDb->reportStyleList[styleIdx].reportStyle.name);
1479 DU_ALLOC(ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf,\
1480 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size);
1481 if(!ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf)
1483 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1486 memcpy(ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.buf, ranFuncDb->reportStyleList[styleIdx].reportStyle.name,\
1487 ricReportStyle->list.array[styleIdx]->ric_ReportStyle_Name.size);
1489 /* RIC Indication Header Format Type*/
1490 ricReportStyle->list.array[styleIdx]->ric_IndicationHeaderFormat_Type = ranFuncDb->ricIndicationHeaderFormat;
1492 /* RIC Indication Message Format Type*/
1493 ricReportStyle->list.array[styleIdx]->ric_IndicationMessageFormat_Type = ranFuncDb->ricIndicationMessageFormat;
1495 /* Measurement Info Action List */
1496 CmLListCp measInfoList =ranFuncDb->reportStyleList[styleIdx].measurementInfoList;
1497 if(!measInfoList.count)
1502 CM_LLIST_FIRST_NODE(&ranFuncDb->reportStyleList[styleIdx].measurementInfoList, node);
1503 measInfo = &ricReportStyle->list.array[styleIdx]->measInfo_Action_List;
1505 measInfo->list.count = measInfoList.count;
1506 measInfo->list.size = measInfoList.count*sizeof(MeasurementInfo_Action_Item_t*);
1507 DU_ALLOC(measInfo->list.array, measInfo->list.size);
1508 if(!measInfo->list.array)
1510 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1514 for(measInfoIdx=0; measInfoIdx<measInfo->list.count; measInfoIdx++)
1518 DU_LOG("\nERROR --> E2AP: Measurement info node is null");
1522 DU_ALLOC(measInfo->list.array[measInfoIdx],sizeof(MeasurementInfo_Action_Item_t));
1523 if(!measInfo->list.array[measInfoIdx])
1525 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1528 MeasurementInfoForAction *measInfoForAction= (MeasurementInfoForAction*)node->node;
1529 DU_ALLOC(measInfo->list.array[measInfoIdx]->measID, sizeof(long));
1530 if(!measInfo->list.array[measInfoIdx]->measID)
1532 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1536 memcpy(measInfo->list.array[measInfoIdx]->measID, &measInfoForAction->measurementTypeId,sizeof(long));
1537 measInfo->list.array[measInfoIdx]->measName.size= strlen(measInfoForAction->measurementTypeName);
1538 DU_ALLOC(measInfo->list.array[measInfoIdx]->measName.buf, measInfo->list.array[measInfoIdx]->measName.size);
1539 if(!measInfo->list.array[measInfoIdx]->measName.size)
1541 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1545 memcpy(measInfo->list.array[measInfoIdx]->measName.buf, \
1546 measInfoForAction->measurementTypeName,\
1547 measInfo->list.array[measInfoIdx]->measName.size);
1554 /*******************************************************************
1556 * @brief fill the ric event trigger style
1560 * Function : fillRicEventTriggerStyle
1562 * Functionality: fill the ric event trigger style
1565 * @return ROK - success
1568 ******************************************************************/
1569 uint8_t fillRicEventTriggerStyle(RanFunction *ranFuncDb, struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List *ricEventTriggerStyle)
1573 ricEventTriggerStyle->list.count = ranFuncDb->numOfEventTriggerStyleSupported;
1574 ricEventTriggerStyle->list.size = ricEventTriggerStyle->list.count* sizeof(RIC_EventTriggerStyle_Item_t *);
1575 DU_ALLOC(ricEventTriggerStyle->list.array, ricEventTriggerStyle->list.size);
1576 if(!ricEventTriggerStyle->list.array)
1578 DU_LOG("\nERROR --> E2AP: Memory allocation failed for ric_EventTriggerStyle_List %d",__LINE__);
1582 for(styleIdx =0;styleIdx<ricEventTriggerStyle->list.count; styleIdx++)
1584 DU_ALLOC(ricEventTriggerStyle->list.array[styleIdx], sizeof(RIC_EventTriggerStyle_Item_t ));
1585 if(!ricEventTriggerStyle->list.array[styleIdx])
1587 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1590 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Type = ranFuncDb->eventTriggerStyleList[styleIdx].styleType;
1592 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerFormat_Type = ranFuncDb->eventTriggerStyleList[styleIdx].formatType;
1594 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size = strlen(ranFuncDb->eventTriggerStyleList[styleIdx].name);
1595 DU_ALLOC(ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf,\
1596 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size);
1597 if(!ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf)
1599 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1602 memcpy(ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.buf,ranFuncDb->eventTriggerStyleList[styleIdx].name,\
1603 ricEventTriggerStyle->list.array[styleIdx]->ric_EventTriggerStyle_Name.size);
1609 /*******************************************************************
1611 * @brief Builds Ran function item
1615 * Function : BuildRanFunctionItem
1617 * Functionality: Building RAN function item
1620 * RAN function item that has to be filled
1621 * Stored RAN Function information
1622 * @return ROK - success
1625 ******************************************************************/
1627 uint8_t BuildRanFunctionItem(RANfunction_Item_t *ranFuncItem, RanFunction *ranFuncDb)
1629 uint8_t ret =RFAILED;
1630 RANfunctionDefinition_t *ranFunctionDefinition;
1631 RANfunction_Name_t *ranFuncName;
1632 asn_enc_rval_t encRetVal;
1633 E2SM_KPM_RANfunction_Description_t *ranFuncDefinition;
1637 /* RAN function Id*/
1638 ranFuncItem->ranFunctionID = ranFuncDb->id;
1640 /* RAN Function Revision*/
1641 ranFuncItem->ranFunctionRevision = ranFuncDb->revisionCounter;
1643 /* RAN function OID*/
1644 ranFuncItem->ranFunctionOID.size = strlen(ranFuncDb->name.serviceModelOID);
1645 DU_ALLOC(ranFuncItem->ranFunctionOID.buf, ranFuncItem->ranFunctionOID.size);
1646 if(!ranFuncItem->ranFunctionOID.buf)
1648 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1651 memcpy(ranFuncItem->ranFunctionOID.buf, ranFuncDb->name.serviceModelOID, ranFuncItem->ranFunctionOID.size);
1653 /* RAN function Definition */
1654 DU_ALLOC(ranFuncDefinition, sizeof(E2SM_KPM_RANfunction_Description_t));
1655 if(!ranFuncDefinition)
1657 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1661 /* RAN function Name */
1662 ranFuncName = &ranFuncDefinition->ranFunction_Name;
1664 /* RAN function ShortName */
1665 ranFuncName->ranFunction_ShortName.size = strlen(ranFuncDb->name.shortName);
1666 DU_ALLOC(ranFuncName->ranFunction_ShortName.buf, ranFuncName->ranFunction_ShortName.size);
1667 if(!ranFuncName->ranFunction_ShortName.buf)
1669 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1672 memcpy(ranFuncName->ranFunction_ShortName.buf, ranFuncDb->name.shortName, strlen(ranFuncDb->name.shortName));
1674 /* RAN function E2SM_OID */
1675 ranFuncName->ranFunction_E2SM_OID.size = strlen(ranFuncDb->name.serviceModelOID);
1676 DU_ALLOC(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncName->ranFunction_E2SM_OID.size);
1677 if(!ranFuncName->ranFunction_E2SM_OID.buf)
1679 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1682 memcpy(ranFuncName->ranFunction_E2SM_OID.buf, ranFuncDb->name.serviceModelOID, ranFuncName->ranFunction_E2SM_OID.size);
1684 /* RAN Function Name Description */
1685 ranFuncName->ranFunction_Description.size = strlen(ranFuncDb->name.description);
1686 DU_ALLOC(ranFuncName->ranFunction_Description.buf, ranFuncName->ranFunction_Description.size);
1687 if(!ranFuncName->ranFunction_Description.buf)
1689 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1692 memcpy(ranFuncName->ranFunction_Description.buf, ranFuncDb->name.description, ranFuncName->ranFunction_Description.size);
1694 /* RIC Event Trigger Style List */
1695 DU_ALLOC(ranFuncDefinition->ric_EventTriggerStyle_List, sizeof(struct E2SM_KPM_RANfunction_Description__ric_EventTriggerStyle_List));
1696 if(!ranFuncDefinition->ric_EventTriggerStyle_List)
1698 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1702 if(fillRicEventTriggerStyle(ranFuncDb, ranFuncDefinition->ric_EventTriggerStyle_List)!=ROK)
1704 DU_LOG("\nERROR --> E2AP: failed to fill ric event trigger style");
1708 /* RIC Report Style List */
1709 DU_ALLOC(ranFuncDefinition->ric_ReportStyle_List, sizeof(struct E2SM_KPM_RANfunction_Description__ric_ReportStyle_List));
1710 if(!ranFuncDefinition->ric_ReportStyle_List)
1712 DU_LOG("\nERROR --> E2AP: Memory allocation failed in function %s at %d",__func__,__LINE__);
1715 if(fillRicReportStyle(ranFuncDb, ranFuncDefinition->ric_ReportStyle_List) != ROK)
1717 DU_LOG("\nERROR --> E2AP: failed to fill ric report style");
1721 /* Encode the F1SetupRequest type as APER */
1722 xer_fprint(stdout, &asn_DEF_E2SM_KPM_RANfunction_Description, ranFuncDefinition);
1724 memset(encBuf, 0, ENC_BUF_MAX_LEN);
1726 encRetVal = aper_encode(&asn_DEF_E2SM_KPM_RANfunction_Description, 0, ranFuncDefinition, PrepFinalEncBuf, encBuf);
1728 /* Encode results */
1729 if(encRetVal.encoded == ENCODE_FAIL)
1731 DU_LOG("\nERROR --> F1AP : Could not encode RAN function definition (at %s)\n",\
1732 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
1737 DU_LOG("\nDEBUG --> F1AP : Created APER encoded buffer for RAN function definition \n");
1738 for(uint8_t measIeIdx=0; measIeIdx< encBufSize; measIeIdx++)
1740 printf("%x",encBuf[measIeIdx]);
1742 ranFunctionDefinition = &ranFuncItem->ranFunctionDefinition;
1743 ranFunctionDefinition->size = encBufSize;
1744 DU_ALLOC(ranFunctionDefinition->buf, encBufSize);
1745 if(ranFunctionDefinition->buf == NULLP)
1747 DU_LOG("\nERROR --> F1AP : Memory allocation failed for RAN function definition buffer");
1750 memcpy(ranFunctionDefinition->buf, &encBuf, encBufSize);
1755 freeE2smKpmRanFunctionDefinition(ranFuncDefinition);
1759 /*******************************************************************
1761 * @brief Builds Ran function add list based on the procedure code
1765 * Function : BuildRanFunctionAddList
1767 * Functionality: Building RAN addition addition list
1768 * In case of ProcedureCodeE2_id_E2setup we add all the RAN Function list
1769 * which is present in E2 database.
1770 * In the case of other procedures, we just fill the RAN functions whose ID
1771 * is contained in recvList
1776 * Count of ran functions to be added in the list
1777 * Received list of RAN functions
1779 * @return ROK - success
1782 ******************************************************************/
1784 uint8_t BuildRanFunctionAddList(RANfunctions_List_t *ranFunctionsList, uint8_t procedureCode, uint8_t count, RanFuncInfo *recvList)
1787 RanFunction *ranFuncDb;
1789 RANfunction_ItemIEs_t *ranFuncItemIe;
1791 /* For ProcedureCodeE2_id_E2setup, the number of RAN function list items is
1792 * equal to the number of ran function entries stored in the database.
1793 * For any other procedure, the RAN function list count is equal
1794 * to the count of ran functions obtained from the function's caller */
1796 if(procedureCode == ProcedureCodeE2_id_E2setup)
1797 ranFunctionsList->list.count = duCb.e2apDb.numOfRanFunction;
1799 ranFunctionsList->list.count = count;
1801 ranFunctionsList->list.size = ranFunctionsList->list.count * sizeof(RANfunction_ItemIEs_t*);
1802 DU_ALLOC(ranFunctionsList->list.array, ranFunctionsList->list.size);
1803 if(ranFunctionsList->list.array == NULLP)
1805 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
1809 for(ranFuncIdx = 0; ranFuncIdx< ranFunctionsList->list.count; ranFuncIdx++)
1811 DU_ALLOC(ranFunctionsList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
1812 if(ranFunctionsList->list.array[ranFuncIdx] == NULLP)
1814 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
1817 if(procedureCode == ProcedureCodeE2_id_E2setup)
1819 /* Getting all of the RAN function's information from DuCb one by one*/
1820 ranFuncDb = &duCb.e2apDb.ranFunction[ranFuncIdx];
1824 /* Getting only the RAN function information from DuCb whose Id is
1825 * present in the received array */
1826 id =recvList[ranFuncIdx].id;
1827 ranFuncDb = &duCb.e2apDb.ranFunction[id-1];
1829 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncIdx];
1830 ranFuncItemIe->id = ProtocolIE_IDE2_id_RANfunction_Item;
1831 ranFuncItemIe->criticality = CriticalityE2_ignore;
1832 ranFuncItemIe->value.present = RANfunction_ItemIEs__value_PR_RANfunction_Item;
1833 BuildRanFunctionItem(&ranFuncItemIe->value.choice.RANfunction_Item, ranFuncDb);
1838 /*******************************************************************
1840 * @brief De Allocate E2 Setup Request Message
1844 * Function : FreeE2SetupReq
1846 * Functionality: De-Allocating E2 Setup request Message
1848 * @params[in] E2AP_PDU_t *e2apMsg
1852 * ****************************************************************/
1854 void FreeE2SetupReq(E2AP_PDU_t *e2apMsg)
1857 uint8_t e2NodeAddListIdx =0, ranFuncAddListIdx;
1858 E2setupRequest_t *e2SetupReq;
1859 E2nodeComponentConfigAddition_List_t *e2NodeAddList;
1860 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItem;
1861 RANfunctions_List_t *ranFunctionsList;
1862 RANfunction_ItemIEs_t *ranFuncItemIe;
1863 RANfunction_Item_t *ranFunItem;
1865 /* De-allocating Memory */
1866 if(e2apMsg != NULLP)
1868 if(e2apMsg->choice.initiatingMessage != NULLP)
1870 e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest;
1871 if(e2SetupReq->protocolIEs.list.array != NULLP)
1873 for(arrIdx = 0; arrIdx < e2SetupReq->protocolIEs.list.count; arrIdx++)
1875 if(e2SetupReq->protocolIEs.list.array[arrIdx] != NULLP)
1877 switch(e2SetupReq->protocolIEs.list.array[arrIdx]->id)
1879 case ProtocolIE_IDE2_id_TransactionID:
1881 case ProtocolIE_IDE2_id_GlobalE2node_ID:
1883 if(e2SetupReq->protocolIEs.list.array[arrIdx]->\
1884 value.choice.GlobalE2node_ID.choice.gNB != NULLP)
1886 GlobalE2node_gNB_ID_t *gNbId = NULLP;
1887 gNbId = e2SetupReq->protocolIEs.list.array[arrIdx]->\
1888 value.choice.GlobalE2node_ID.choice.gNB;
1889 if(gNbId->global_gNB_ID.plmn_id.buf != NULLP)
1891 DU_FREE(gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.buf,\
1892 gNbId->global_gNB_ID.gnb_id.choice.gnb_ID.size);
1893 DU_FREE(gNbId->global_gNB_ID.plmn_id.buf,\
1894 gNbId->global_gNB_ID.plmn_id.size);
1897 if(gNbId->gNB_DU_ID != NULLP)
1899 DU_FREE( gNbId->gNB_DU_ID->buf, gNbId->gNB_DU_ID->size);
1900 DU_FREE(gNbId->gNB_DU_ID, sizeof(GNB_DU_ID_t));
1902 DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\
1903 choice.GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
1907 case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition:
1909 e2NodeAddList = &e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List;
1910 if(e2NodeAddList->list.array)
1912 for(e2NodeAddListIdx = 0; e2NodeAddListIdx< e2NodeAddList->list.count; e2NodeAddListIdx++)
1914 e2NodeAddItem = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[e2NodeAddListIdx];
1916 /* Free E2 Node Component Request Part */
1917 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.buf,\
1918 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentRequestPart.size);
1920 /* Free E2 Node Component Response Part */
1921 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.\
1922 e2nodeComponentResponsePart.buf, \
1923 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration.e2nodeComponentResponsePart.size);
1925 /* Free E2 Node Component ID */
1926 if(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1)
1928 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
1929 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf,\
1930 e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.\
1931 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
1932 DU_FREE(e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1,\
1933 sizeof(E2nodeComponentInterfaceF1_t));
1935 DU_FREE(e2NodeAddList->list.array[e2NodeAddListIdx], sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
1937 DU_FREE(e2NodeAddList->list.array, e2NodeAddList->list.size);
1941 case ProtocolIE_IDE2_id_RANfunctionsAdded:
1943 ranFunctionsList = &(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List);
1944 if(ranFunctionsList->list.array)
1946 for(ranFuncAddListIdx= 0; ranFuncAddListIdx< ranFunctionsList->list.count; ranFuncAddListIdx++)
1948 if(ranFunctionsList->list.array[ranFuncAddListIdx])
1950 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncAddListIdx];
1951 ranFunItem = &ranFuncItemIe->value.choice.RANfunction_Item;
1952 DU_FREE(ranFunItem->ranFunctionOID.buf, ranFunItem->ranFunctionOID.size);
1953 DU_FREE(ranFunItem->ranFunctionDefinition.buf, ranFunItem->ranFunctionDefinition.size);
1954 DU_FREE(ranFunctionsList->list.array[ranFuncAddListIdx], sizeof(RANfunction_ItemIEs_t));
1957 DU_FREE(ranFunctionsList->list.array, ranFunctionsList->list.size);
1963 DU_LOG("\nERROR --> E2AP: Invalid event at e2SetupRequet %ld ",\
1964 (e2SetupReq->protocolIEs.list.array[arrIdx]->id));
1967 DU_FREE(e2SetupReq->protocolIEs.list.array[arrIdx], sizeof(E2setupRequestIEs_t));
1970 DU_FREE(e2SetupReq->protocolIEs.list.array, e2SetupReq->protocolIEs.list.size);
1972 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
1974 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
1978 /*******************************************************************
1980 * @brief Builds and Send the E2SetupRequest
1984 * Function : BuildAndSendE2SetupReq
1986 * Functionality:Fills the E2SetupRequest
1988 * @return ROK - success
1991 ******************************************************************/
1993 uint8_t BuildAndSendE2SetupReq()
1995 uint8_t arrIdx = 0, elementCnt=0;
1996 uint8_t transId = 0, ret = RFAILED;
1997 bool memAllocFailed = false;
1998 E2AP_PDU_t *e2apMsg = NULLP;
1999 E2setupRequest_t *e2SetupReq = NULLP;
2000 asn_enc_rval_t encRetVal; /* Encoder return value */
2002 DU_LOG("\nINFO --> E2AP : Building E2 Setup Request\n");
2005 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
2006 if(e2apMsg == NULLP)
2008 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2011 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
2012 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
2013 if(e2apMsg->choice.initiatingMessage == NULLP)
2015 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2018 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
2019 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2setup;
2020 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_E2setupRequest;
2021 e2SetupReq = &e2apMsg->choice.initiatingMessage->value.choice.E2setupRequest;
2024 e2SetupReq->protocolIEs.list.count = elementCnt;
2025 e2SetupReq->protocolIEs.list.size = elementCnt * sizeof(E2setupRequestIEs_t*);
2027 /* Initialize the E2Setup members */
2028 DU_ALLOC(e2SetupReq->protocolIEs.list.array, \
2029 e2SetupReq->protocolIEs.list.size);
2030 if(e2SetupReq->protocolIEs.list.array == NULLP)
2032 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements");
2035 for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
2037 DU_ALLOC(e2SetupReq->protocolIEs.list.array[arrIdx],\
2038 sizeof(E2setupRequestIEs_t));
2039 if(e2SetupReq->protocolIEs.list.array[arrIdx] == NULLP)
2041 memAllocFailed = true;
2042 DU_LOG("\nERROR --> E2AP : Memory allocation failed for arrayarrIdx [%d]", arrIdx);
2046 if(memAllocFailed == true)
2052 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
2053 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2054 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID;
2055 transId = assignTransactionId();
2056 e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
2059 /* GlobalE2node_gNB_ID */
2060 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_GlobalE2node_ID;
2061 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2062 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_GlobalE2node_ID;
2063 e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.GlobalE2node_ID.present = GlobalE2node_ID_PR_gNB;
2065 DU_ALLOC(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.\
2066 GlobalE2node_ID.choice.gNB, sizeof(GlobalE2node_gNB_ID_t));
2067 if(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.\
2068 GlobalE2node_ID.choice.gNB == NULLP)
2070 DU_LOG("\nERROR --> E2AP : Memory allocation failed for gNbId");
2075 ret = BuildGlobalgNBId(e2SetupReq->protocolIEs.list.array[arrIdx]->value.\
2076 choice.GlobalE2node_ID.choice.gNB);
2079 DU_LOG("\nERROR --> E2AP : Failed to build Global Gnb Id");
2084 /* RAN Functions Added List */
2086 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAdded;
2087 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2088 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_RANfunctions_List;
2089 if(BuildRanFunctionAddList(&(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List), ProcedureCodeE2_id_E2setup, 0, NULL)!=ROK)
2091 DU_LOG("\nERROR --> E2AP : Failed to create RAN Function");
2095 /* E2 Node Component Configuration Addition List */
2097 e2SetupReq->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition;
2098 e2SetupReq->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
2099 e2SetupReq->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_E2nodeComponentConfigAddition_List;
2100 if(BuildE2NodeConfigAddList(&(e2SetupReq->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List), ProcedureCodeE2_id_E2setup, 0, NULL)!=ROK)
2102 DU_LOG("\nERROR --> E2AP : Failed to create E2 Node config list");
2108 /* Prints the Msg formed */
2109 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
2111 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2113 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
2115 if(encRetVal.encoded == ENCODE_FAIL)
2117 DU_LOG("\nERROR --> E2AP : Could not encode E2SetupRequest structure (at %s)\n",\
2118 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2123 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SetupRequest\n");
2124 #ifdef DEBUG_ASN_PRINT
2125 for(int i=0; i< encBufSize; i++)
2127 printf("%x",encBuf[i]);
2131 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
2133 DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
2138 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
2139 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
2141 FreeE2SetupReq(e2apMsg);
2143 }/* End of BuildAndSendE2SetupReq */
2145 /*******************************************************************
2147 * @brief Builds RIC Action Admitted List
2151 * Function : BuildRicActionAdmitList
2153 * Functionality: Builds RIC Action Admitted List
2155 * @params[in] Pointer to RIC Action Admitted List to be filled
2156 * Subscription Response information
2157 * @return ROK - success
2160 * ****************************************************************/
2161 uint8_t BuildRicActionAdmitList(RICaction_Admitted_List_t *admitList, PendingSubsRspInfo *subsRspInfo)
2164 uint8_t elementCnt = 0;
2165 RICaction_Admitted_ItemIEs_t *admitItem = NULLP;
2167 elementCnt = subsRspInfo->numOfAcceptedActions;
2169 admitList->list.count = elementCnt;
2170 admitList->list.size = elementCnt * sizeof(RICaction_Admitted_ItemIEs_t *);
2172 DU_ALLOC(admitList->list.array, admitList->list.size);
2173 if(admitList->list.array == NULLP)
2175 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
2179 for(idx=0; idx<elementCnt; idx++)
2181 DU_ALLOC(admitList->list.array[idx], sizeof(RICaction_Admitted_ItemIEs_t));
2182 if(admitList->list.array[idx] == NULLP)
2184 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
2188 admitItem = (RICaction_Admitted_ItemIEs_t *)admitList->list.array[idx];
2189 admitItem->id = ProtocolIE_IDE2_id_RICaction_Admitted_Item;
2190 admitItem->criticality = CriticalityE2_reject;
2191 admitItem->value.present = RICaction_Admitted_ItemIEs__value_PR_RICaction_Admitted_Item;
2192 admitItem->value.choice.RICaction_Admitted_Item.ricActionID = subsRspInfo->acceptedActionList[idx];
2197 /*******************************************************************
2199 * @brief Builds RIC Action Not Admitted List
2203 * Function : BuildRicActionNotAdmitList
2205 * Functionality: Builds RIC Action Not Admitted List
2207 * @params[in] Pointer to RIC Action Not Admitted List to be filled
2208 * Subscription Response information
2209 * @return ROK - success
2212 * ****************************************************************/
2213 uint8_t BuildRicActionNotAdmitList(RICaction_NotAdmitted_List_t *notAdmitList, PendingSubsRspInfo *subsRspInfo)
2216 uint8_t elementCnt = 0;
2217 RICaction_NotAdmitted_ItemIEs_t *notAdmitItem = NULLP;
2219 elementCnt = subsRspInfo->numOfRejectedActions;
2221 notAdmitList->list.count = elementCnt;
2222 notAdmitList->list.size = elementCnt * sizeof(RICaction_NotAdmitted_ItemIEs_t *);
2224 DU_ALLOC(notAdmitList->list.array, notAdmitList->list.size);
2225 if(notAdmitList->list.array == NULLP)
2227 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
2231 for(idx=0; idx<elementCnt; idx++)
2233 DU_ALLOC(notAdmitList->list.array[idx], sizeof(RICaction_NotAdmitted_ItemIEs_t));
2234 if(notAdmitList->list.array[idx] == NULLP)
2236 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d]", __func__, __LINE__);
2240 notAdmitItem = (RICaction_NotAdmitted_ItemIEs_t *)notAdmitList->list.array[idx];
2241 notAdmitItem->id = ProtocolIE_IDE2_id_RICaction_NotAdmitted_Item;
2242 notAdmitItem->criticality = CriticalityE2_reject;
2243 notAdmitItem->value.present = RICaction_NotAdmitted_ItemIEs__value_PR_RICaction_NotAdmitted_Item;
2244 notAdmitItem->value.choice.RICaction_NotAdmitted_Item.ricActionID = \
2245 subsRspInfo->rejectedActionList[idx].id;
2246 fillE2Cause(¬AdmitItem->value.choice.RICaction_NotAdmitted_Item.cause, \
2247 subsRspInfo->rejectedActionList[idx].failureCause);
2252 /*******************************************************************
2254 * @breif Deallocation of BuildAndSendRicSubscriptionRsp memory
2258 * Function : FreeRicSubscriptionRsp
2260 * Functionality:Free the RicSubscriptionRsp
2262 * @param[in] E2AP_PDU_t *e2apRicMsg
2266 ******************************************************************/
2267 void FreeRicSubscriptionRsp(E2AP_PDU_t *e2apRicMsg)
2269 RICsubscriptionResponse_t *ricSubscriptionRsp= NULLP;
2272 RICaction_Admitted_List_t *admitList = NULLP;
2273 RICaction_NotAdmitted_List_t *notAdmitList = NULLP;
2275 if(e2apRicMsg != NULLP)
2277 if(e2apRicMsg->choice.successfulOutcome != NULLP)
2279 ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
2280 if(ricSubscriptionRsp)
2282 if(ricSubscriptionRsp->protocolIEs.list.array != NULLP)
2284 for(idx=0; idx<ricSubscriptionRsp->protocolIEs.list.count; idx++)
2286 if(ricSubscriptionRsp->protocolIEs.list.array[idx] != NULLP)
2288 switch(ricSubscriptionRsp->protocolIEs.list.array[idx]->id)
2290 case ProtocolIE_IDE2_id_RICactions_Admitted:
2292 admitList = &ricSubscriptionRsp->protocolIEs.list.\
2293 array[idx]->value.choice.RICaction_Admitted_List;
2294 if(admitList->list.array != NULLP)
2296 for(listIdx=0 ; listIdx < admitList->list.count; listIdx++)
2298 DU_FREE(admitList->list.array[listIdx], sizeof(RICaction_Admitted_ItemIEs_t));
2300 DU_FREE(admitList->list.array, admitList->list.size);
2304 case ProtocolIE_IDE2_id_RICactions_NotAdmitted:
2306 notAdmitList = &ricSubscriptionRsp->protocolIEs.list.\
2307 array[idx]->value.choice.RICaction_NotAdmitted_List;
2308 if(notAdmitList->list.array != NULLP)
2310 for(listIdx=0 ; listIdx < notAdmitList->list.count; listIdx++)
2312 DU_FREE(notAdmitList->list.array[listIdx], sizeof(RICaction_NotAdmitted_ItemIEs_t));
2314 DU_FREE(notAdmitList->list.array, notAdmitList->list.size);
2321 DU_FREE(ricSubscriptionRsp->protocolIEs.list.array[idx], sizeof(RICsubscriptionResponse_IEs_t));
2324 DU_FREE(ricSubscriptionRsp->protocolIEs.list.array, ricSubscriptionRsp->protocolIEs.list.size);
2327 DU_FREE(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
2329 DU_FREE(e2apRicMsg, sizeof(E2AP_PDU_t));
2333 /*******************************************************************
2335 * @brief Fill RIC Subscription Response IEs
2339 * Function : fillRicSubscriptionRsp
2341 * functionality: Fill RIC Subscription Response IEs
2343 * @param Pointer to RIC subscription response
2344 * Subscription response information
2345 * @return ROK - success
2348 ******************************************************************/
2349 uint8_t fillRicSubscriptionRsp(RICsubscriptionResponse_t *ricSubscriptionRsp, PendingSubsRspInfo *subsRspInfo)
2352 uint8_t elementCnt = 0;
2353 RICsubscriptionResponse_IEs_t *subsRspIe = NULLP;
2356 if(subsRspInfo->numOfRejectedActions)
2359 ricSubscriptionRsp->protocolIEs.list.count = elementCnt;
2360 ricSubscriptionRsp->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionResponse_IEs_t);
2361 DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array, ricSubscriptionRsp->protocolIEs.list.size);
2362 if(ricSubscriptionRsp->protocolIEs.list.array == NULLP)
2364 DU_LOG("\nERROR --> E2AP : Memory allocation failed at %s : line %d", __func__, __LINE__);
2368 for(ieIdx=0; ieIdx<ricSubscriptionRsp->protocolIEs.list.count; ieIdx++)
2370 DU_ALLOC(ricSubscriptionRsp->protocolIEs.list.array[ieIdx], sizeof(RICsubscriptionResponse_IEs_t));
2371 if(ricSubscriptionRsp->protocolIEs.list.array[ieIdx] == NULLP)
2373 DU_LOG("\nERROR --> E2AP : Memory allocation failed at [%s] : line [%d] : ieIdx [%d]", __func__, __LINE__,ieIdx);
2378 /* RIC Request ID */
2380 subsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
2381 subsRspIe->id = ProtocolIE_IDE2_id_RICrequestID;
2382 subsRspIe->criticality = CriticalityE2_reject;
2383 subsRspIe->value.present = RICsubscriptionRequest_IEs__value_PR_RICrequestID;
2384 subsRspIe->value.choice.RICrequestID.ricRequestorID = subsRspInfo->requestId.requestorId;
2385 subsRspIe->value.choice.RICrequestID.ricInstanceID = subsRspInfo->requestId.instanceId;
2387 /* RAN Function ID */
2389 subsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
2390 subsRspIe->id = ProtocolIE_IDE2_id_RANfunctionID;
2391 subsRspIe->criticality = CriticalityE2_reject;
2392 subsRspIe->value.present = RICsubscriptionRequest_IEs__value_PR_RANfunctionID;
2393 subsRspIe->value.choice.RANfunctionID = subsRspInfo->ranFuncId;
2395 /* RIC Action Admitted List */
2397 subsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
2398 subsRspIe->id = ProtocolIE_IDE2_id_RICactions_Admitted;
2399 subsRspIe->criticality = CriticalityE2_reject;
2400 subsRspIe->value.present = RICsubscriptionResponse_IEs__value_PR_RICaction_Admitted_List;
2401 if(BuildRicActionAdmitList(&subsRspIe->value.choice.RICaction_Admitted_List, subsRspInfo) != ROK)
2403 DU_LOG("\nERROR --> E2AP : Failed to fill RIC Action Admitted List in RIC Subscription Response");
2407 /* RIC Action Not Admitted List */
2408 if(subsRspInfo->numOfRejectedActions)
2411 subsRspIe = ricSubscriptionRsp->protocolIEs.list.array[ieIdx];
2412 subsRspIe->id = ProtocolIE_IDE2_id_RICactions_NotAdmitted;
2413 subsRspIe->criticality = CriticalityE2_reject;
2414 subsRspIe->criticality = CriticalityE2_reject;
2415 subsRspIe->value.present = RICsubscriptionResponse_IEs__value_PR_RICaction_NotAdmitted_List;
2416 if(BuildRicActionNotAdmitList(&subsRspIe->value.choice.RICaction_NotAdmitted_List, subsRspInfo) != ROK)
2418 DU_LOG("\nERROR --> E2AP : Failed to fill RIC Action Not Admitted List in RIC Subscription Response");
2426 /*******************************************************************
2428 * @brief Builds and Send the RicSubscriptionRsp
2432 * Function : BuildAndSendRicSubscriptionRsp
2434 * Functionality:Fills the RicSubscriptionRsp
2436 * @return ROK - success
2439 ******************************************************************/
2441 uint8_t BuildAndSendRicSubscriptionRsp(PendingSubsRspInfo *subsRspInfo)
2443 uint8_t ret = RFAILED;
2444 E2AP_PDU_t *e2apRicMsg = NULLP;
2445 RICsubscriptionResponse_t *ricSubscriptionRsp=NULLP;
2446 asn_enc_rval_t encRetVal;
2450 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Response\n");
2452 DU_ALLOC(e2apRicMsg, sizeof(E2AP_PDU_t));
2453 if(e2apRicMsg == NULLP)
2455 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
2459 e2apRicMsg->present = E2AP_PDU_PR_successfulOutcome;
2460 DU_ALLOC(e2apRicMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
2461 if(e2apRicMsg->choice.successfulOutcome == NULLP)
2463 DU_LOG("\nERROR --> E2AP : Memory allocation for RIC subscription Response failed");
2467 e2apRicMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_RICsubscription;
2468 e2apRicMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
2469 e2apRicMsg->choice.successfulOutcome->value.present = SuccessfulOutcomeE2__value_PR_RICsubscriptionResponse;
2471 ricSubscriptionRsp = &e2apRicMsg->choice.successfulOutcome->value.choice.RICsubscriptionResponse;
2473 if(fillRicSubscriptionRsp(ricSubscriptionRsp, subsRspInfo) != ROK)
2475 DU_LOG("\nERROR --> E2AP : Memory allocation for RICsubscriptionResponseIE failed");
2479 /* Prints the Msg formed */
2480 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apRicMsg);
2482 memset(encBuf, 0, ENC_BUF_MAX_LEN);
2484 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apRicMsg, PrepFinalEncBuf, encBuf);
2485 if(encRetVal.encoded == ENCODE_FAIL)
2487 DU_LOG("\nERROR --> E2AP : Could not encode RIC Subscription Response structure (at %s)\n",\
2488 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
2493 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC subscription response \n");
2494 #ifdef DEBUG_ASN_PRINT
2495 for(int i=0; i< encBufSize; i++)
2497 printf("%x",encBuf[i]);
2502 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
2504 DU_LOG("\nERROR --> E2AP : Sending RIC Subscription Response failed");
2513 FreeRicSubscriptionRsp(e2apRicMsg);
2517 /******************************************************************
2519 * @brief Deallocation of memory allocated by aper decoder for e2 setup response
2523 * Function : freeAperDecodingOfE2SetupRsp
2525 * Functionality: Deallocation of memory allocated by aper decoder for e2
2528 * @params[in] E2setupResponse_t *e2SetRspMsg;
2531 * ****************************************************************/
2532 void freeAperDecodingOfE2SetupRsp(E2setupResponse_t *e2SetRspMsg)
2534 uint8_t arrIdx, e2NodeConfigAddAckListIdx;
2535 E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItem;
2536 E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAddAckList;
2540 if(e2SetRspMsg->protocolIEs.list.array)
2542 for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
2544 if(e2SetRspMsg->protocolIEs.list.array[arrIdx])
2546 switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
2548 case ProtocolIE_IDE2_id_TransactionID:
2551 case ProtocolIE_IDE2_id_GlobalRIC_ID:
2553 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.pLMN_Identity.buf);
2554 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID.buf);
2558 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
2560 e2NodeConfigAddAckList = &e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
2561 if(e2NodeConfigAddAckList->list.array )
2563 for(e2NodeConfigAddAckListIdx = 0; e2NodeConfigAddAckListIdx< e2NodeConfigAddAckList->list.count; e2NodeConfigAddAckListIdx++)
2565 if(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx])
2567 e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx];
2568 free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
2569 e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf);
2570 free(e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.\
2571 e2nodeComponentInterfaceTypeF1);
2572 free(e2NodeConfigAddAckList->list.array[e2NodeConfigAddAckListIdx]);
2575 free(e2NodeConfigAddAckList->list.array);
2580 free(e2SetRspMsg->protocolIEs.list.array[arrIdx]);
2583 free(e2SetRspMsg->protocolIEs.list.array);
2588 /******************************************************************
2590 * @brief handling of e2 noe config update ack ies
2594 * Function :handleE2NodeConfigUpdateAckIes
2596 * Functionality: handling of e2 noe config update ack ies
2599 * Pointer to the E2 Node cfg
2602 ******************************************************************/
2604 void handleE2NodeConfigUpdateAckIes(PTR e2NodeCfg, uint8_t procedureCode)
2606 CmLList *node=NULLP;
2607 E2NodeComponent *e2NodeComponentInfo=NULLP;
2608 E2nodeComponentID_t *e2nodeComponentID=NULLP;
2609 E2nodeComponentConfigRemovalAck_Item_t *removalAckItem=NULLP;
2610 E2nodeComponentConfigUpdateAck_Item_t *updateAckItem=NULLP;
2611 E2nodeComponentConfigAdditionAck_Item_t *additionAckItem=NULLP;
2613 switch(procedureCode)
2615 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
2617 additionAckItem = (E2nodeComponentConfigAdditionAck_Item_t *)e2NodeCfg;
2618 e2nodeComponentID = &additionAckItem->e2nodeComponentID;
2621 case ProtocolIE_IDE2_id_E2nodeComponentConfigUpdateAck:
2623 updateAckItem = (E2nodeComponentConfigUpdateAck_Item_t*) e2NodeCfg;
2624 e2nodeComponentID = &updateAckItem->e2nodeComponentID;
2627 case ProtocolIE_IDE2_id_E2nodeComponentConfigRemovalAck:
2629 removalAckItem= (E2nodeComponentConfigRemovalAck_Item_t*)e2NodeCfg;
2630 e2nodeComponentID = &removalAckItem->e2nodeComponentID;
2635 switch(e2nodeComponentID->present)
2637 case E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1:
2639 e2NodeComponentInfo = fetchE2NodeComponentInfo(F1, e2nodeComponentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf[0], &node);
2640 if(!e2NodeComponentInfo)
2642 DU_LOG("\nERROR --> E2AP : Received null e2NodeComponentInfo at line number %d",__LINE__);
2651 switch(procedureCode)
2653 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
2655 DU_FREE(e2NodeComponentInfo->addConfiguration->componentRequestPart, e2NodeComponentInfo->addConfiguration->reqBufSize);
2656 DU_FREE(e2NodeComponentInfo->addConfiguration->componentResponsePart, e2NodeComponentInfo->addConfiguration->rspBufSize);
2657 DU_FREE(e2NodeComponentInfo->addConfiguration, sizeof(E2NodeConfig));
2660 case ProtocolIE_IDE2_id_E2nodeComponentConfigUpdateAck:
2662 DU_FREE(e2NodeComponentInfo->updateConfiguration->componentRequestPart, e2NodeComponentInfo->updateConfiguration->reqBufSize);
2663 DU_FREE(e2NodeComponentInfo->updateConfiguration->componentResponsePart, e2NodeComponentInfo->updateConfiguration->rspBufSize);
2664 DU_FREE(e2NodeComponentInfo->updateConfiguration, sizeof(E2NodeConfig));
2667 case ProtocolIE_IDE2_id_E2nodeComponentConfigRemovalAck:
2669 cmLListDelFrm(&duCb.e2apDb.e2NodeComponentList, node);
2670 if(e2NodeComponentInfo->addConfiguration)
2672 DU_FREE(e2NodeComponentInfo->addConfiguration->componentRequestPart, e2NodeComponentInfo->addConfiguration->reqBufSize);
2673 DU_FREE(e2NodeComponentInfo->addConfiguration->componentResponsePart, e2NodeComponentInfo->addConfiguration->rspBufSize);
2674 DU_FREE(e2NodeComponentInfo->addConfiguration, sizeof(E2NodeConfig));
2676 if(e2NodeComponentInfo->updateConfiguration)
2678 DU_FREE(e2NodeComponentInfo->updateConfiguration->componentRequestPart, e2NodeComponentInfo->updateConfiguration->reqBufSize);
2679 DU_FREE(e2NodeComponentInfo->updateConfiguration->componentResponsePart, e2NodeComponentInfo->updateConfiguration->rspBufSize);
2680 DU_FREE(e2NodeComponentInfo->updateConfiguration, sizeof(E2NodeConfig));
2682 DU_FREE(node, sizeof(CmLList));
2688 /******************************************************************
2690 * @brief Processes E2 Setup Response sent by RIC
2694 * Function : procE2SetupRsp
2696 * Functionality: Processes E2 Setup Response sent by RIC
2698 * @params[in] E2AP_PDU_t ASN decoded E2AP message
2701 * ****************************************************************/
2703 void procE2SetupRsp(E2AP_PDU_t *e2apMsg)
2705 bool invalidTransId = false;
2706 uint8_t arrIdx =0, transId=0, idx=0;
2707 uint32_t recvBufLen;
2708 E2setupResponse_t *e2SetRspMsg=NULL;
2709 E2nodeComponentConfigAdditionAck_List_t *e2NodeCfgAckList=NULL;
2710 E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAddAckItem=NULL;
2712 DU_LOG("\nINFO --> E2AP : E2 Setup Response received");
2713 duCb.e2Status = TRUE; //Set E2 status as true
2714 e2SetRspMsg = &e2apMsg->choice.successfulOutcome->value.choice.E2setupResponse;
2716 for(arrIdx=0; arrIdx<e2SetRspMsg->protocolIEs.list.count; arrIdx++)
2718 switch(e2SetRspMsg->protocolIEs.list.array[arrIdx]->id)
2720 case ProtocolIE_IDE2_id_TransactionID:
2722 transId = e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
2723 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
2724 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
2726 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
2730 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
2731 invalidTransId = true;
2736 case ProtocolIE_IDE2_id_GlobalRIC_ID:
2738 /* To store the Ric Id Params */
2739 recvBufLen = sizeof(e2SetRspMsg->protocolIEs.list.array[arrIdx]->value\
2740 .choice.GlobalRIC_ID.pLMN_Identity.size);
2741 memcpy(&duCb.e2apDb.ricId.plmnId, e2SetRspMsg->protocolIEs.list.array[arrIdx]\
2742 ->value.choice.GlobalRIC_ID.pLMN_Identity.buf, recvBufLen);
2743 bitStringToInt(&e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.GlobalRIC_ID.ric_ID, &duCb.e2apDb.ricId);
2744 /*TODO : duCb.e2apDb.ricId.plmnId memory to be deallocated after the usage */
2748 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
2750 e2NodeCfgAckList = &e2SetRspMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
2751 for(idx =0; idx <e2NodeCfgAckList->list.count; idx++)
2753 e2NodeAddAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeCfgAckList->list.array[idx];
2754 handleE2NodeConfigUpdateAckIes((PTR)&e2NodeAddAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item,\
2755 ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck);
2762 DU_LOG("\nERROR --> E2AP : Invalid IE received in E2SetupRsp:%ld",
2763 e2SetRspMsg->protocolIEs.list.array[arrIdx]->id);
2768 if(invalidTransId == true)
2773 freeAperDecodingOfE2SetupRsp(e2SetRspMsg);
2775 if(invalidTransId == false)
2777 if(duSendE2NodeConfigurationUpdate() != ROK)
2779 DU_LOG("\nERROR --> E2AP : Failed to send E2 node config update");
2784 /*******************************************************************
2786 * @brief Free RIC Subscription Request
2790 * Function : freeAperDecodingOfRicSubsReq
2792 * Functionality : Free RIC Subscription Request
2796 ******************************************************************/
2797 void freeAperDecodingOfRicSubsReq(RICsubscriptionRequest_t *ricSubscriptionReq)
2800 uint8_t elementIdx = 0;
2801 RICsubscriptionDetails_t *subsDetails = NULLP;
2802 RICaction_ToBeSetup_ItemIEs_t *actionItem = NULLP;
2804 if(ricSubscriptionReq->protocolIEs.list.array)
2806 for(idx=0; idx < ricSubscriptionReq->protocolIEs.list.count; idx++)
2808 switch(ricSubscriptionReq->protocolIEs.list.array[idx]->id)
2810 case ProtocolIE_IDE2_id_RICsubscriptionDetails:
2812 subsDetails = &(ricSubscriptionReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails);
2813 free(subsDetails->ricEventTriggerDefinition.buf);
2815 if(subsDetails->ricAction_ToBeSetup_List.list.array)
2817 for(elementIdx = 0; elementIdx < subsDetails->ricAction_ToBeSetup_List.list.count; elementIdx++)
2819 if(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx])
2821 actionItem = (RICaction_ToBeSetup_ItemIEs_t *)subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx];
2822 if(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition)
2824 free(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition->buf);
2825 free(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition);
2827 free(subsDetails->ricAction_ToBeSetup_List.list.array[elementIdx]);
2830 free(subsDetails->ricAction_ToBeSetup_List.list.array);
2835 free(ricSubscriptionReq->protocolIEs.list.array[idx]);
2837 free(ricSubscriptionReq->protocolIEs.list.array);
2841 /*******************************************************************
2843 * @brief Free Event Trigger Definition
2847 * Function : freeAperDecodingOfEventTriggerDef
2849 * Functionality: Free Event Trigger Definition
2851 * @params[in] E2SM-KPM Event Trigger Definition
2854 * ****************************************************************/
2855 void freeAperDecodingOfEventTriggerDef(E2SM_KPM_EventTriggerDefinition_t *eventTiggerDef)
2859 switch(eventTiggerDef->eventDefinition_formats.present)
2861 case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_NOTHING:
2864 case E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_eventDefinition_Format1:
2865 free(eventTiggerDef->eventDefinition_formats.choice.eventDefinition_Format1);
2871 /*******************************************************************
2873 * @brief Extract E2SM-KPM Event trigger definition
2877 * Function : extractEventTriggerDef
2879 * Functionality : This function :
2880 * - Decodes E2SM-KPM Event Trigger Definition
2881 * - Validates that even trigger style is supported by E2 node
2882 * - Stores event trigger details in local DB
2884 * @params[in] RAN Function Database structure
2885 * RIC Subscription Info to be added to RAN function
2886 * RIC Event Trigger Definition buffer received from RIC
2887 * @return ROK - success
2890 ******************************************************************/
2891 uint8_t extractEventTriggerDef(RanFunction *ranFuncDb, RicSubscription *ricSubscriptionInfo, \
2892 RICeventTriggerDefinition_t *ricEventTriggerDef, E2FailureCause *failureCause)
2894 uint8_t ret = RFAILED;
2895 uint8_t eventIdx = 0;
2896 asn_dec_rval_t rval ={0};
2897 E2SM_KPM_EventTriggerDefinition_t eventTiggerDef, *eventTiggerDefPtr = NULLP;
2899 /* Decoding E2SM-KPM Even Trigger Definition */
2900 eventTiggerDefPtr = &eventTiggerDef;
2901 memset(eventTiggerDefPtr, 0, sizeof(E2SM_KPM_EventTriggerDefinition_t));
2903 rval = aper_decode(0, &asn_DEF_E2SM_KPM_EventTriggerDefinition, (void **)&eventTiggerDefPtr, ricEventTriggerDef->buf,\
2904 ricEventTriggerDef->size, 0, 0);
2905 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
2907 DU_LOG("\nERROR --> E2AP : ASN decode failed for E2SM-KPM Event Trigger Definition");
2908 failureCause->causeType = E2_PROTOCOL;
2909 failureCause->cause = E2_ABSTRACT_SYNTAX_ERROR_FALSELY_CONSTRUCTED_MESSAGE;
2913 xer_fprint(stdout, &asn_DEF_E2SM_KPM_EventTriggerDefinition, eventTiggerDefPtr);
2915 /* Validating the received event trigger definition format */
2916 for(eventIdx = 0; eventIdx < ranFuncDb->numOfEventTriggerStyleSupported; eventIdx++)
2918 if((eventTiggerDefPtr->eventDefinition_formats.present != \
2919 E2SM_KPM_EventTriggerDefinition__eventDefinition_formats_PR_NOTHING) && \
2920 (eventTiggerDefPtr->eventDefinition_formats.present == ranFuncDb->eventTriggerStyleList[eventIdx].formatType))
2922 ricSubscriptionInfo->eventTriggerDefinition.formatType = ranFuncDb->eventTriggerStyleList[eventIdx].formatType;
2923 ricSubscriptionInfo->eventTriggerDefinition.choice.format1.reportingPeriod = \
2924 eventTiggerDefPtr->eventDefinition_formats.choice.eventDefinition_Format1->reportingPeriod;
2933 failureCause->causeType = E2_RIC_REQUEST;
2934 failureCause->cause = E2_EVENT_TRIGGER_NOT_SUPPORTED;
2936 /* Free E2SM_KPM_EventTriggerDefinition_t */
2937 freeAperDecodingOfEventTriggerDef(eventTiggerDefPtr);
2941 /*******************************************************************
2943 * @brief Free RIC Action Definition
2947 * Function : freeAperDecodingOfRicActionDefinition
2949 * Functionality: Free RIC Action Definition
2951 * @params[in] E2SM-KPM Action definition
2954 * ****************************************************************/
2955 void freeAperDecodingOfRicActionDefinition(E2SM_KPM_ActionDefinition_t *actionDef)
2957 uint8_t elementIdx = 0;
2958 E2SM_KPM_ActionDefinition_Format1_t *actionFormat1 = NULLP;
2959 MeasurementInfoItem_t *measItem = NULLP;
2961 switch(actionDef->actionDefinition_formats.present)
2963 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1:
2965 if(actionDef->actionDefinition_formats.choice.actionDefinition_Format1)
2967 actionFormat1 = actionDef->actionDefinition_formats.choice.actionDefinition_Format1;
2968 if(actionFormat1->measInfoList.list.array)
2970 for(elementIdx = 0; elementIdx < actionFormat1->measInfoList.list.count; elementIdx++)
2972 if(actionFormat1->measInfoList.list.array[elementIdx])
2974 measItem = actionFormat1->measInfoList.list.array[elementIdx];
2975 switch(measItem->measType.present)
2977 case MeasurementType_PR_NOTHING:
2980 case MeasurementType_PR_measName:
2982 free(measItem->measType.choice.measName.buf);
2986 case MeasurementType_PR_measID:
2992 free(actionFormat1->measInfoList.list.array);
2994 free(actionFormat1);
2998 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format2:
2999 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format3:
3000 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format4:
3001 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format5:
3007 /*******************************************************************
3009 * @brief Extract Measurement Info list from action definition
3013 * Function : extractMeasInfoList
3015 * Functionality : This function :
3016 * - Traverses Measurement-to-be-subscribed list
3017 * - Validates that each measurement in Measurement-to-be-subscribed
3018 * list is supported in RAN-Function->Measurement-supported list.
3019 * - If all measurements in an action is supported by RAN function,
3020 * it is added to measurement-subscribed list in local DB
3022 * @params[in] Measurement Info supported list by RAN function
3023 * Measurement Info to be subscribed as requested by RIC
3024 * Measurement Info finally subscribed
3025 * Memory failure indicator
3026 * @return ROK - success
3029 ******************************************************************/
3030 uint8_t extractMeasInfoList(CmLListCp *measInfoSupportedList, MeasurementInfoList_t *measInfoToBeSubscribedList, \
3031 CmLListCp *measInfoSubscribedList, bool *memFailure)
3033 uint8_t elementIdx = 0;
3034 MeasurementInfoForAction *measInfoSupportedDb = NULLP;
3035 MeasurementInfo *measInfoSubscribedDb = NULLP;
3036 CmLList *supportedMeasNode = NULLP, *measToAddNode = NULLP;
3037 MeasurementInfoItem_t *measItem = NULLP;
3039 /* Validate Measurement list is supported by E2 node.
3041 * Traverse and compare the Measurement-Supported List in E2
3042 * node with Measurement-to-be-subscribed list received from RIC.
3043 * If a match is found, add it to measurement-subscription list.
3045 for(elementIdx = 0; elementIdx < measInfoToBeSubscribedList->list.count; elementIdx++)
3047 measInfoSubscribedDb = NULLP;
3048 measToAddNode = NULLP;
3049 measItem = measInfoToBeSubscribedList->list.array[elementIdx];
3051 CM_LLIST_FIRST_NODE(measInfoSupportedList, supportedMeasNode);
3052 while(supportedMeasNode)
3054 measInfoSupportedDb = (MeasurementInfoForAction*)supportedMeasNode->node;
3055 switch(measItem->measType.present)
3057 case MeasurementType_PR_measName:
3059 if(!strcmp(measInfoSupportedDb->measurementTypeName, (char *)measItem->measType.choice.measName.buf))
3061 DU_ALLOC(measInfoSubscribedDb, sizeof(MeasurementInfo));
3066 case MeasurementType_PR_measID:
3068 if(measInfoSupportedDb->measurementTypeId == measItem->measType.choice.measID)
3070 DU_ALLOC(measInfoSubscribedDb, sizeof(MeasurementInfo));
3077 DU_LOG("\nERROR -> DUAPP: Invalid Measurement-type identifier in \
3078 E2SM-KPM Action Definition Format");
3081 } /* End of switch, for measurement type identifier */
3083 /* If measurement type is supported, add to measurement-subscription list */
3084 if(measInfoSubscribedDb)
3086 measInfoSubscribedDb->measurementTypeId = measInfoSupportedDb->measurementTypeId;
3087 memcpy(measInfoSubscribedDb->measurementTypeName, measInfoSupportedDb->measurementTypeName, \
3088 strlen(measInfoSupportedDb->measurementTypeName));
3090 DU_ALLOC(measToAddNode, sizeof(CmLList));
3093 measToAddNode->node = (PTR) measInfoSubscribedDb;
3094 cmLListAdd2Tail(measInfoSubscribedList, measToAddNode);
3096 /* Break out of while loop if measurement info is found in measurement-supported list */
3101 DU_FREE(measInfoSubscribedDb, sizeof(MeasurementInfo));
3102 measInfoSubscribedDb = NULLP;
3108 supportedMeasNode = supportedMeasNode->next;
3110 } /* End of while for traversing measurement-supported list in a report style */
3112 /* If a measurement-to-be-subscribed is not found in measurement-supported list in this report style
3114 * Delete all entries from measurement-subscription list and
3115 * Break out of for loop to search in next report style */
3116 if(!measInfoSubscribedDb)
3118 deleteMeasurementInfoList(measInfoSubscribedList);
3122 } /* End of for loop , traversing measurement-to-be-subscribed list */
3124 /* If all measurement-to-be-subscribed was found in measurement-supported list and
3125 * was added to measurement-subscription list successfully, return from here */
3126 if(measInfoToBeSubscribedList->list.count == measInfoSubscribedList->count)
3132 /*******************************************************************
3134 * @brief Extract E2SM-KPM Action definition
3138 * Function : extractRicActionDef
3140 * Functionality : This function :
3141 * - Decodes E2SM-KPM Action Definition
3142 * - Validates that action is supported by E2 node
3143 * - Stores action details in local DB
3145 * @params[in] RAN Function Database structure
3146 * RIC subscription's Action definition to be added to
3148 * RIC Action Definition buffer received from RIC
3149 * @return ROK - success
3152 ******************************************************************/
3153 uint8_t extractRicActionDef(RanFunction *ranFuncDb, ActionDefinition *actionDefDb, RICactionDefinition_t *ricActionDef,\
3154 E2FailureCause *failureCause)
3156 bool memFailure = false;
3157 uint8_t styleIdx = 0;
3158 asn_dec_rval_t rval ={0};
3160 E2SM_KPM_ActionDefinition_t actionDef, *actionDefPtr = NULLP;
3161 E2SM_KPM_ActionDefinition_Format1_t *actionFormat1 = NULLP;
3162 CmLListCp *measInfoSupportedList = NULLP;
3163 CmLListCp *measInfoSubscribedList = NULLP;
3165 /* Decoding E2SM-KPM Action Definition */
3166 actionDefPtr = &actionDef;
3167 memset(actionDefPtr, 0, sizeof(E2SM_KPM_EventTriggerDefinition_t));
3169 rval = aper_decode(0, &asn_DEF_E2SM_KPM_ActionDefinition, (void **)&actionDefPtr, ricActionDef->buf,\
3170 ricActionDef->size, 0, 0);
3171 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
3173 DU_LOG("\nERROR --> E2AP : ASN decode failed for E2SM-KPM Action Definition");
3174 failureCause->causeType = E2_PROTOCOL;
3175 failureCause->cause = E2_ABSTRACT_SYNTAX_ERROR_FALSELY_CONSTRUCTED_MESSAGE;
3179 xer_fprint(stdout, &asn_DEF_E2SM_KPM_ActionDefinition, actionDefPtr);
3182 /* Validate if Report style to subscribe is supported by E2 Node */
3183 for(styleIdx= 0; styleIdx < ranFuncDb->numOfReportStyleSupported; styleIdx++)
3185 /* Validate Report style type and report style format type is supported by E2 Node */
3186 if((ranFuncDb->reportStyleList[styleIdx].reportStyle.styleType == actionDefPtr->ric_Style_Type) &&
3187 (ranFuncDb->reportStyleList[styleIdx].reportStyle.formatType == actionDefPtr->actionDefinition_formats.present))
3189 /* Fetch Report stype type and format type */
3190 actionDefDb->styleType = actionDefPtr->ric_Style_Type;
3191 actionDefDb->formatType = actionDefPtr->actionDefinition_formats.present;
3193 switch(actionDefPtr->actionDefinition_formats.present)
3195 case E2SM_KPM_ActionDefinition__actionDefinition_formats_PR_actionDefinition_Format1:
3197 actionFormat1 = actionDefPtr->actionDefinition_formats.choice.actionDefinition_Format1;
3199 /* Fetch granularity period */
3200 actionDefDb->choice.format1.granularityPeriod = actionFormat1->granulPeriod;
3202 /* Validate and add the Measurement to subscription list */
3203 measInfoSupportedList = &ranFuncDb->reportStyleList[styleIdx].measurementInfoList;
3204 measInfoSubscribedList = &actionDefDb->choice.format1.measurementInfoList;
3205 if(extractMeasInfoList(measInfoSupportedList, &actionFormat1->measInfoList, \
3206 measInfoSubscribedList, &memFailure) == ROK)
3210 /* Free E2SM_KPM_ActionDefinition_t */
3211 freeAperDecodingOfRicActionDefinition(actionDefPtr);
3216 break; /* End of E2SM-KPM Action definition format 1 case */
3221 DU_LOG("\nERROR -> DUAPP: Only E2SM-KPM Action Definition Format 1 is supported");
3224 } /* End of switch for E2SM-KPM Action definition formats */
3229 failureCause->causeType = E2_MISCELLANEOUS;
3230 failureCause->cause = E2_MISCELLANEOUS_CAUSE_UNSPECIFIED;
3233 } /* End of for loop, traversing Report-styles-supported list in E2 node */
3235 /* Memset action Db and Free E2SM_KPM_ActionDefinition_t */
3236 memset(actionDefDb, 0, sizeof(ActionDefinition));
3237 freeAperDecodingOfRicActionDefinition(actionDefPtr);
3239 if(failureCause->causeType == E2_NOTHING)
3241 failureCause->causeType = E2_RIC_REQUEST;
3242 failureCause->cause = E2_ACTION_NOT_SUPPORTED;
3247 /*******************************************************************
3249 * @brief Extract RIC Action to be setup
3253 * Function : extractRicActionToBeSetup
3255 * Functionality : This function :
3256 * - Validates that each action-to-be-setup is supported by E2 node
3257 * - Stores event trigger details in local DB
3259 * @params[in] RAN Function Database structure
3260 * RIC Subscription Info to be added to RAN function
3261 * RIC Action To Be Setup List received from RIC
3262 * @return ROK - success
3265 ******************************************************************/
3266 uint8_t extractRicActionToBeSetup(RanFunction *ranFuncDb, RicSubscription *ricSubscriptionInfo, \
3267 RICactions_ToBeSetup_List_t *actionList, E2FailureCause *failureCause, PendingSubsRspInfo *subsRsp)
3269 uint8_t actionIdx = 0;
3270 uint8_t ricActionId = 0;
3271 RICaction_ToBeSetup_ItemIEs_t *actionItem = NULLP;
3273 if(actionList->list.array)
3275 for(actionIdx = 0; actionIdx < actionList->list.count; actionIdx++)
3277 actionItem =(RICaction_ToBeSetup_ItemIEs_t *)actionList->list.array[actionIdx];
3278 switch(actionItem->id)
3280 case ProtocolIE_IDE2_id_RICaction_ToBeSetup_Item:
3282 /* If Action type is REPORT and
3283 * If RIC action definition's extraction and validation passes,
3285 * This action is added to action sequence list of subscription info */
3286 ricActionId = actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionID;
3288 if(actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionType == RICactionType_report)
3290 ricSubscriptionInfo->actionSequence[ricActionId].actionId = ricActionId;
3291 ricSubscriptionInfo->actionSequence[ricActionId].type = REPORT;
3293 if(extractRicActionDef(ranFuncDb, &ricSubscriptionInfo->actionSequence[ricActionId].definition, \
3294 actionItem->value.choice.RICaction_ToBeSetup_Item.ricActionDefinition, failureCause) == ROK)
3296 ricSubscriptionInfo->actionSequence[ricActionId].action = CONFIG_ADD;
3297 ricSubscriptionInfo->numOfActions++;
3302 /* In case of any failure, action is rejected
3303 * Added to rejected-action-list in subscription response */
3304 deleteActionSequence(&ricSubscriptionInfo->actionSequence[ricActionId]);
3306 subsRsp->rejectedActionList[subsRsp->numOfRejectedActions].id = ricActionId;
3307 if(failureCause->causeType == E2_NOTHING)
3309 failureCause->causeType = E2_RIC_REQUEST;
3310 failureCause->cause = E2_ACTION_NOT_SUPPORTED;
3312 memcpy(&subsRsp->rejectedActionList[subsRsp->numOfRejectedActions].failureCause, \
3313 failureCause, sizeof(E2FailureCause));
3314 subsRsp->numOfRejectedActions++;
3318 DU_LOG("\nERROR --> E2AP : Invalid IE received in RicSetupLst:%ld",actionItem->id);
3324 /* If there is even 1 action that can be added, return ROK */
3325 if(ricSubscriptionInfo->numOfActions)
3328 if(failureCause->causeType == E2_NOTHING)
3330 failureCause->causeType = E2_RIC_REQUEST;
3331 failureCause->cause = E2_ACTION_NOT_SUPPORTED;
3336 /******************************************************************
3338 * @brief Processes RIC Subscription Req sent by RIC
3342 * Function : procRicSubscriptionRequest
3344 * Functionality: Processes RIC Subscription Request from RIC
3346 * @params[in] E2AP_PDU_t ASN decoded E2AP message
3347 * @return ROK - success
3350 * ****************************************************************/
3351 uint8_t procRicSubscriptionRequest(E2AP_PDU_t *e2apMsg)
3353 uint8_t idx = 0, actionIdx = 0;
3355 uint16_t ranFuncId = 0;
3356 RicRequestId ricReqId;
3357 CmLList *ricSubscriptionNode = NULLP;
3358 RanFunction *ranFuncDb = NULLP;
3359 RICsubscriptionRequest_t *ricSubsReq = NULLP;
3360 RICsubscriptionDetails_t *subsDetails = NULLP;
3361 RicSubscription *ricSubscriptionInfo = NULLP;
3362 E2FailureCause failureCause;
3364 DU_LOG("\nINFO --> E2AP : RIC Subscription request received");
3366 memset(&failureCause, 0, sizeof(E2FailureCause));
3367 memset(&ricReqId, 0, sizeof(RicRequestId));
3369 ricSubsReq = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionRequest;
3370 for(idx=0; idx<ricSubsReq->protocolIEs.list.count; idx++)
3372 if(ricSubsReq->protocolIEs.list.array[idx])
3374 switch(ricSubsReq->protocolIEs.list.array[idx]->id)
3376 case ProtocolIE_IDE2_id_RICrequestID:
3378 ricReqId.requestorId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID;
3379 ricReqId.instanceId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID;
3384 case ProtocolIE_IDE2_id_RANfunctionID:
3386 ranFuncId = ricSubsReq->protocolIEs.list.array[idx]->value.choice.RANfunctionID;
3388 /* Validating RAN Function id */
3389 ranFuncDb = fetchRanFuncFromRanFuncId(ranFuncId);
3393 failureCause.causeType = E2_RIC_REQUEST;
3394 failureCause.cause = E2_RAN_FUNCTION_ID_INVALID;
3399 if(ranFuncDb->numPendingSubsRsp >= MAX_PENDING_SUBSCRIPTION_RSP)
3401 failureCause.causeType = E2_RIC_REQUEST;
3402 failureCause.cause = E2_FUNCTION_RESOURCE_LIMIT;
3407 DU_ALLOC(ricSubscriptionInfo, sizeof(RicSubscription));
3408 if(!ricSubscriptionInfo)
3410 DU_LOG("\nERROR --> E2AP : Memory allocation failed for ricSubscriptionInfo");
3411 failureCause.causeType = E2_MISCELLANEOUS;
3412 failureCause.cause = E2_MISCELLANEOUS_CAUSE_UNSPECIFIED;
3416 ricSubscriptionInfo->requestId.requestorId = ricReqId.requestorId;
3417 ricSubscriptionInfo->requestId.instanceId = ricReqId.instanceId;
3418 ricSubscriptionInfo->ranFuncId = ranFuncId;
3420 for(actionIdx = 0; actionIdx < MAX_RIC_ACTION; actionIdx++)
3422 ricSubscriptionInfo->actionSequence[actionIdx].actionId = -1;
3425 memset(&ranFuncDb->pendingSubsRspInfo[ranFuncDb->numPendingSubsRsp], 0, sizeof(PendingSubsRspInfo));
3426 memcpy(&ranFuncDb->pendingSubsRspInfo[ranFuncDb->numPendingSubsRsp].requestId,
3427 &ricReqId, sizeof(RicRequestId));
3428 ranFuncDb->pendingSubsRspInfo[ranFuncDb->numPendingSubsRsp].ranFuncId = ranFuncId;
3432 case ProtocolIE_IDE2_id_RICsubscriptionDetails:
3434 subsDetails = &ricSubsReq->protocolIEs.list.array[idx]->value.choice.RICsubscriptionDetails;
3436 /* Decode, Validate and record Event Trigger Definition */
3437 if(extractEventTriggerDef(ranFuncDb, ricSubscriptionInfo, &subsDetails->ricEventTriggerDefinition, \
3438 &failureCause) != ROK)
3444 /* Decode, Validate and record RIC actions */
3445 if(extractRicActionToBeSetup(ranFuncDb, ricSubscriptionInfo, &subsDetails->ricAction_ToBeSetup_List, \
3446 &failureCause, &ranFuncDb->pendingSubsRspInfo[ranFuncDb->numPendingSubsRsp]) != ROK)
3455 DU_LOG("\nERROR --> E2AP : Invalid IE received in RIC SubsReq:%ld",
3456 ricSubsReq->protocolIEs.list.array[idx]->id);
3465 freeAperDecodingOfRicSubsReq(ricSubsReq);
3469 cmInitTimers(&(ricSubscriptionInfo->ricSubsReportTimer), 1);
3470 ricSubscriptionInfo->action = CONFIG_ADD;
3472 /* Add RAN subcription detail to RAN function */
3473 DU_ALLOC(ricSubscriptionNode, sizeof(CmLList));
3474 if(ricSubscriptionNode)
3476 ricSubscriptionNode->node = (PTR) ricSubscriptionInfo;
3477 cmLListAdd2Tail(&ranFuncDb->subscriptionList, ricSubscriptionNode);
3480 ranFuncDb->numPendingSubsRsp++;
3482 #ifdef KPI_CALCULATION
3483 /* Send statistics request to other DU entities */
3484 BuildAndSendStatsReq(ricSubscriptionInfo);
3489 DU_FREE(ricSubscriptionInfo, sizeof(RicSubscription));
3493 memset(&ranFuncDb->pendingSubsRspInfo[ranFuncDb->numPendingSubsRsp], 0, sizeof(PendingSubsRspInfo));
3496 /* Send RIC Subcription Failure */
3497 BuildAndSendRicSubscriptionFailure(ricReqId, ranFuncId, failureCause);
3503 /******************************************************************
3505 * @brief Free RIC Subscription Failure
3509 * Function : FreeRicSubscriptionFailure
3511 * Functionality: Free RIC Subscription Failure
3513 * @params[in] E2AP PDU
3516 * ****************************************************************/
3517 void FreeRicSubscriptionFailure(E2AP_PDU_t *e2apMsg)
3519 uint8_t elemIdx = 0;
3520 RICsubscriptionFailure_t *ricSubscriptionFailure = NULLP;
3524 if(e2apMsg->choice.unsuccessfulOutcome)
3526 ricSubscriptionFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICsubscriptionFailure;
3527 if(ricSubscriptionFailure->protocolIEs.list.array)
3529 for(elemIdx = 0; elemIdx < ricSubscriptionFailure->protocolIEs.list.count; elemIdx++)
3531 DU_ALLOC(ricSubscriptionFailure->protocolIEs.list.array[elemIdx], sizeof(RICsubscriptionFailure_IEs_t));
3533 DU_ALLOC(ricSubscriptionFailure->protocolIEs.list.array, ricSubscriptionFailure->protocolIEs.list.size);
3535 DU_ALLOC(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
3537 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
3541 /******************************************************************
3543 * @brief Fill and Send RIC Subscription Failure to RIC
3547 * Function : BuildAndSendRicSubscriptionFailure
3549 * Functionality: Fill and Send RIC Subscription Failure to RIC
3551 * @params[in] RIC Request ID
3554 * @return ROK - success
3557 * ****************************************************************/
3558 uint8_t BuildAndSendRicSubscriptionFailure(RicRequestId ricReqId, uint16_t ranFuncId, E2FailureCause failureCause)
3560 uint8_t ret = RFAILED;
3561 uint8_t elementCnt = 0, elemIdx = 0;
3562 E2AP_PDU_t *e2apMsg = NULLP;
3563 asn_enc_rval_t encRetVal; /* Encoder return value */
3564 RICsubscriptionFailure_t *ricSubscriptionFailure = NULLP;
3565 RICsubscriptionFailure_IEs_t *ricSubsFailIe = NULLP;
3569 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Failure\n");
3571 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
3572 if(e2apMsg == NULLP)
3574 DU_LOG("\nERROR --> E2AP : Memory allocation at [%s] : Line [%d]", __func__, __LINE__);
3578 e2apMsg->present = E2AP_PDU_PR_unsuccessfulOutcome;
3579 DU_ALLOC(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
3580 if(e2apMsg->choice.unsuccessfulOutcome == NULLP)
3582 DU_LOG("\nERROR --> E2AP : Memory allocation at [%s] : Line [%d]", __func__, __LINE__);
3585 e2apMsg->choice.unsuccessfulOutcome->procedureCode = ProcedureCodeE2_id_RICsubscription;
3586 e2apMsg->choice.unsuccessfulOutcome->criticality = CriticalityE2_reject;
3587 e2apMsg->choice.unsuccessfulOutcome->value.present = UnsuccessfulOutcomeE2__value_PR_RICsubscriptionFailure;
3589 ricSubscriptionFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICsubscriptionFailure;
3592 ricSubscriptionFailure->protocolIEs.list.count = elementCnt;
3593 ricSubscriptionFailure->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionFailure_IEs_t *);
3594 DU_ALLOC(ricSubscriptionFailure->protocolIEs.list.array, ricSubscriptionFailure->protocolIEs.list.size);
3595 if(!ricSubscriptionFailure->protocolIEs.list.array)
3597 DU_LOG("\nERROR --> E2AP : Memory allocation at [%s] : Line [%d]", __func__, __LINE__);
3601 for(elemIdx = 0; elemIdx < elementCnt; elemIdx++)
3603 DU_ALLOC(ricSubscriptionFailure->protocolIEs.list.array[elemIdx], sizeof(RICsubscriptionFailure_IEs_t));
3604 if(!ricSubscriptionFailure->protocolIEs.list.array[elemIdx])
3606 DU_LOG("\nERROR --> E2AP : Memory allocation at [%s] : Line [%d] for IE at index [%d]", \
3607 __func__, __LINE__, elemIdx);
3611 if(elemIdx < elementCnt)
3616 /* RIC Request ID */
3617 ricSubsFailIe = ricSubscriptionFailure->protocolIEs.list.array[elemIdx++];
3618 ricSubsFailIe->id = ProtocolIE_IDE2_id_RICrequestID;
3619 ricSubsFailIe->criticality = CriticalityE2_reject;
3620 ricSubsFailIe->value.present = RICsubscriptionFailure_IEs__value_PR_RICrequestID;
3621 ricSubsFailIe->value.choice.RICrequestID.ricRequestorID = ricReqId.requestorId;
3622 ricSubsFailIe->value.choice.RICrequestID.ricInstanceID = ricReqId.instanceId;
3624 /* RAN Function ID */
3625 ricSubsFailIe = ricSubscriptionFailure->protocolIEs.list.array[elemIdx++];
3626 ricSubsFailIe->id = ProtocolIE_IDE2_id_RANfunctionID;
3627 ricSubsFailIe->criticality = CriticalityE2_reject;
3628 ricSubsFailIe->value.present = RICsubscriptionFailure_IEs__value_PR_RANfunctionID;
3629 ricSubsFailIe->value.choice.RANfunctionID = ranFuncId;
3632 ricSubsFailIe = ricSubscriptionFailure->protocolIEs.list.array[elemIdx++];
3633 ricSubsFailIe->id = ProtocolIE_IDE2_id_CauseE2;
3634 ricSubsFailIe->criticality = CriticalityE2_reject;
3635 ricSubsFailIe->value.present = RICsubscriptionFailure_IEs__value_PR_CauseE2;
3636 fillE2Cause(&ricSubsFailIe->value.choice.CauseE2, failureCause);
3638 /* Prints the Msg formed */
3639 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
3640 memset(encBuf, 0, ENC_BUF_MAX_LEN);
3642 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
3643 if(encRetVal.encoded == ENCODE_FAIL)
3645 DU_LOG("\nERROR --> E2AP : Could not encode RIC Subscription Failure Message (at %s)\n",\
3646 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
3651 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC Subscription Failure Message \n");
3652 #ifdef DEBUG_ASN_PRINT
3653 for(int i=0; i< encBufSize; i++)
3655 printf("%x",encBuf[i]);
3660 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
3662 DU_LOG("\nINFO --> E2AP : Sending RIC Subscription Failure");
3668 FreeRicSubscriptionFailure(e2apMsg);
3672 /*******************************************************************
3674 * @brief Free the RicIndication Message
3678 * Function : FreeRicIndication
3680 * Functionality: Free the RicIndication Message
3685 ******************************************************************/
3686 void FreeRicIndication(E2AP_PDU_t *e2apMsg)
3689 RICindication_t *ricIndicationMsg= NULLP;
3691 if(e2apMsg != NULLP)
3693 if(e2apMsg->choice.initiatingMessage != NULLP)
3695 ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
3696 if(ricIndicationMsg!= NULLP)
3698 if(ricIndicationMsg->protocolIEs.list.array != NULLP)
3700 for(idx=0; idx<ricIndicationMsg->protocolIEs.list.count; idx++)
3702 if(ricIndicationMsg->protocolIEs.list.array[idx] != NULLP)
3704 switch(ricIndicationMsg->protocolIEs.list.array[idx]->id)
3706 case ProtocolIE_IDE2_id_RICrequestID:
3707 case ProtocolIE_IDE2_id_RANfunctionID:
3708 case ProtocolIE_IDE2_id_RICactionID:
3709 case ProtocolIE_IDE2_id_RICindicationType:
3712 case ProtocolIE_IDE2_id_RICindicationHeader:
3714 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.buf,\
3715 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader.size);
3718 case ProtocolIE_IDE2_id_RICindicationMessage:
3720 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.buf,\
3721 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage.size);
3727 DU_FREE(ricIndicationMsg->protocolIEs.list.array[idx],sizeof(RICindication_IEs_t));
3730 DU_FREE(ricIndicationMsg->protocolIEs.list.array,ricIndicationMsg->protocolIEs.list.size);
3733 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
3735 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
3739 /*******************************************************************
3741 * @brief Free measurement record
3745 * Function : freeMeasRecord
3747 * Functionality: Free all measurement recorded for a measurement
3748 * within an action in a RIC subscription
3750 * @param Measurement data to be freed
3753 ******************************************************************/
3754 void freeMeasData(MeasurementData_t *measData)
3756 uint8_t measIdx = 0, measRecIdx = 0;
3757 MeasurementRecord_t *measRecord = NULLP;
3759 if(measData->list.array)
3761 for(measIdx = 0; measIdx < measData->list.count; measIdx++)
3763 if(measData->list.array[measIdx])
3765 measRecord = &measData->list.array[measIdx]->measRecord;
3766 if(measRecord->list.array)
3768 for(measRecIdx = 0; measRecIdx < measRecord->list.count; measRecIdx++)
3770 DU_FREE(measRecord->list.array[measRecIdx], sizeof(MeasurementRecordItem_t));
3772 DU_FREE(measRecord->list.array, measRecord->list.size);
3774 DU_FREE(measData->list.array[measIdx], sizeof(MeasurementDataItem_t));
3777 DU_FREE(measData->list.array, measData->list.size);
3781 /*******************************************************************
3783 * @brief Fill measurement info list
3787 * Function : freeMeasInfoList
3789 * Functionality: Fills all measurement info within an action
3790 * in a RIC subscription
3792 * @param Measurement Info list to be freed
3795 ******************************************************************/
3796 void freeMeasInfoList(MeasurementInfoList_t *measInfoList)
3798 uint8_t measInfoIdx = 0;
3800 if(measInfoList->list.array)
3802 for(measInfoIdx = 0; measInfoIdx < measInfoList->list.count; measInfoIdx++)
3804 if(measInfoList->list.array[measInfoIdx])
3806 DU_FREE(measInfoList->list.array[measInfoIdx]->measType.choice.measName.buf, \
3807 measInfoList->list.array[measInfoIdx]->measType.choice.measName.size);
3809 DU_FREE(measInfoList->list.array[measInfoIdx], measInfoList->list.size);
3812 DU_FREE(measInfoList->list.array, measInfoList->list.size);
3816 /*******************************************************************
3818 * @brief Free E2SM-KPM Indication Message
3822 * Function : FreeE2smKpmIndicationMessage
3824 * Functionality: Free E2SM-KPM Indication Message
3826 * @param E2SM-KPM Indication message to be freed
3829 ******************************************************************/
3830 void FreeE2smKpmIndicationMessage(E2SM_KPM_IndicationMessage_t *e2smKpmIndMsg)
3832 E2SM_KPM_IndicationMessage_Format1_t *format1Msg = NULLP;
3834 switch(e2smKpmIndMsg->indicationMessage_formats.present)
3836 case E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_indicationMessage_Format1:
3838 if(e2smKpmIndMsg->indicationMessage_formats.choice.indicationMessage_Format1)
3840 format1Msg = e2smKpmIndMsg->indicationMessage_formats.choice.indicationMessage_Format1;
3842 /* Measurement Data */
3843 freeMeasData(&format1Msg->measData);
3845 /* Measurement Info List */
3846 if(format1Msg->measInfoList)
3848 freeMeasInfoList(format1Msg->measInfoList);
3849 DU_FREE(format1Msg->measInfoList, sizeof(MeasurementInfoList_t));
3852 /* Granularity Period */
3853 DU_FREE(format1Msg->granulPeriod, sizeof(GranularityPeriod_t));
3855 DU_FREE(format1Msg, sizeof(E2SM_KPM_IndicationMessage_Format1_t));
3860 case E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_NOTHING:
3861 case E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_indicationMessage_Format2:
3867 /*******************************************************************
3869 * @brief Fill measurement record
3873 * Function : fillMeasRecord
3875 * Functionality: Fills all measurement value for a measurement
3876 * within an action in a RIC subscription
3878 * @param Measurement record to be filled
3879 * Measurement database with measurement records
3880 * @return ROK - success
3883 ******************************************************************/
3884 uint8_t fillMeasRecord(MeasurementRecord_t *measRecord, MeasurementInfo *measInfoDb)
3886 uint8_t measRecIdx = 0;
3887 CmLList *measValNode = NULLP;
3890 measRecord->list.count = measInfoDb->measuredValue.count;
3891 measRecord->list.size = measRecord->list.count * sizeof(MeasurementRecordItem_t *);
3893 DU_ALLOC(measRecord->list.array, measRecord->list.size);
3894 if(!measRecord->list.array)
3896 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3900 for(measRecIdx = 0; measRecIdx < measRecord->list.count; measRecIdx++)
3902 DU_ALLOC(measRecord->list.array[measRecIdx], sizeof(MeasurementRecordItem_t));
3903 if(!measRecord->list.array[measRecIdx])
3905 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3911 CM_LLIST_FIRST_NODE(&measInfoDb->measuredValue, measValNode);
3914 measVal = *(double *)measValNode->node;
3915 if(measVal == (int)measVal)
3917 measRecord->list.array[measRecIdx]->present = MeasurementRecordItem_PR_integer;
3918 measRecord->list.array[measRecIdx]->choice.integer = (int)measVal;
3922 measRecord->list.array[measRecIdx]->present = MeasurementRecordItem_PR_real;
3923 measRecord->list.array[measRecIdx]->choice.real = measVal;
3926 measValNode= measValNode->next;
3927 /* Once the measurement record is added to the message, delete it from DB */
3930 deleteMeasuredValueList(&measInfoDb->measuredValue);
3934 /*******************************************************************
3936 * @brief Fills measuerement data
3940 * Function : fillMeasData
3942 * Functionality: Fill all measurement recorded for all measurements
3943 * in an action in a RIC subscription
3945 * @param Measurement data to be filled
3946 * Measurement info list from an action DB
3947 * @return ROK - success
3950 ******************************************************************/
3951 uint8_t fillMeasData(MeasurementData_t *measData, CmLListCp *measInfoListDb)
3953 uint8_t measIdx = 0;
3954 CmLList *measInfoNode = NULLP;
3955 MeasurementInfo *measInfoDb = NULLP;
3956 MeasurementRecord_t *measRecord = NULLP;
3958 measData->list.count = measInfoListDb->count;
3959 measData->list.size = measData->list.count * sizeof(MeasurementDataItem_t *);
3961 DU_ALLOC(measData->list.array, measData->list.size);
3962 if(!measData->list.array)
3964 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3969 CM_LLIST_FIRST_NODE(measInfoListDb, measInfoNode);
3972 measInfoDb = (MeasurementInfo *)measInfoNode->node;
3975 DU_ALLOC(measData->list.array[measIdx], sizeof(MeasurementDataItem_t));
3976 if(!measData->list.array[measIdx])
3978 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
3982 measRecord = &measData->list.array[measIdx]->measRecord;
3983 if(fillMeasRecord(measRecord, measInfoDb) != ROK)
3985 DU_LOG("\nERROR --> E2AP : Failed to fill measurement record");
3990 measInfoNode = measInfoNode->next;
3996 /*******************************************************************
3998 * @brief Fill all measurement info
4002 * Function : fillMeasInfoList
4004 * Functionality: Fills all measurement info belonging to an action
4005 * in a RIC subscription
4007 * @param Measurement Info list to be filled
4008 * Measurement Info list from E2AP DB
4009 * @return ROK - success
4012 ******************************************************************/
4013 uint8_t fillMeasInfoList(MeasurementInfoList_t *measInfoList, CmLListCp *measInfoListDb)
4015 uint8_t measInfoIdx = 0;
4016 CmLList *measInfoNode = NULLP;
4017 MeasurementInfo *measInfoDb = NULLP;
4018 MeasurementInfoItem_t *measInfoItem = NULLP;
4020 measInfoList->list.count = measInfoListDb->count;
4021 measInfoList->list.size = measInfoList->list.count * sizeof(MeasurementInfoItem_t *);
4023 DU_ALLOC(measInfoList->list.array, measInfoList->list.size);
4024 if(!measInfoList->list.array)
4026 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
4031 CM_LLIST_FIRST_NODE(measInfoListDb, measInfoNode);
4034 DU_ALLOC(measInfoList->list.array[measInfoIdx], sizeof(MeasurementInfoItem_t));
4035 if(!measInfoList->list.array[measInfoIdx])
4037 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
4041 measInfoItem = measInfoList->list.array[measInfoIdx];
4042 measInfoDb = (MeasurementInfo *)measInfoNode->node;
4045 /* Measurement Type */
4046 measInfoItem->measType.present = MeasurementType_PR_measName;
4047 measInfoItem->measType.choice.measName.size = strlen(measInfoDb->measurementTypeName);
4049 DU_ALLOC(measInfoItem->measType.choice.measName.buf, measInfoItem->measType.choice.measName.size);
4050 if(!measInfoItem->measType.choice.measName.buf)
4052 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
4056 memcpy(measInfoItem->measType.choice.measName.buf, measInfoDb->measurementTypeName,\
4057 measInfoItem->measType.choice.measName.size);
4061 measInfoNode = measInfoNode->next;
4068 /*******************************************************************
4070 * @brief Fill E2SM-KPM Indication Message Format 1
4074 * Function : fillE2smKpmIndMsgFormat1
4076 * Functionality: Fill E2SM-KPM Indication Message Format 1
4078 * @param Format 1 Message to be filled
4079 * Action Definition format 1 from E2AP DB
4080 * @return ROK - success
4083 ******************************************************************/
4084 uint8_t fillE2smKpmIndMsgFormat1(E2SM_KPM_IndicationMessage_Format1_t *format1Msg, ActionDefFormat1 *format1)
4086 /* Measurement Data */
4087 if(fillMeasData(&format1Msg->measData, &format1->measurementInfoList) != ROK)
4089 DU_LOG("\nERROR --> E2AP : Failed to fill measurement data");
4093 /* Measurement Information */
4094 DU_ALLOC(format1Msg->measInfoList, sizeof(MeasurementInfoList_t));
4095 if(!format1Msg->measInfoList)
4097 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
4101 if(fillMeasInfoList(format1Msg->measInfoList, &format1->measurementInfoList) != ROK)
4103 DU_LOG("\nERROR --> E2AP : Failed to fill measurement information list");
4107 /* Granularity Period */
4108 DU_ALLOC(format1Msg->granulPeriod, sizeof(GranularityPeriod_t));
4109 if(!format1Msg->granulPeriod)
4111 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
4114 *(format1Msg->granulPeriod) = format1->granularityPeriod;
4119 /*******************************************************************
4121 * @brief Fill RIC Indication Message buffer
4125 * Function : fillRicIndMsgBuf
4127 * Functionality: Fill E2SM-KPM Indication Message
4128 * Encode this message and copy to RIC Indication Message buffer
4130 * @param RIC Indication Message buffer to be filled
4131 * Source action info from E2AP DB
4132 * @return ROK - success
4135 ******************************************************************/
4136 uint8_t fillRicIndMsgBuf(RICindicationMessage_t *ricIndMsgBuf, ActionInfo *actionInfo)
4138 uint8_t ret = RFAILED;
4139 bool failedInFormat = false;
4140 E2SM_KPM_IndicationMessage_t e2smKpmIndMsg;
4141 asn_enc_rval_t encRetVal; /* Encoder return value */
4143 memset(&e2smKpmIndMsg, 0, sizeof(E2SM_KPM_IndicationMessage_t));
4147 /* E2SM-KPM Indication message format type */
4148 e2smKpmIndMsg.indicationMessage_formats.present = actionInfo->definition.formatType;
4149 switch(e2smKpmIndMsg.indicationMessage_formats.present)
4151 case E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_indicationMessage_Format1:
4153 /* E2SM-KPM Indication message format 1 */
4154 DU_ALLOC(e2smKpmIndMsg.indicationMessage_formats.choice.indicationMessage_Format1, \
4155 sizeof(E2SM_KPM_IndicationMessage_Format1_t));
4156 if(!e2smKpmIndMsg.indicationMessage_formats.choice.indicationMessage_Format1)
4158 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
4159 failedInFormat = true;
4163 if(fillE2smKpmIndMsgFormat1(e2smKpmIndMsg.indicationMessage_formats.choice.indicationMessage_Format1, \
4164 &actionInfo->definition.choice.format1) != ROK)
4166 DU_LOG("\nERROR --> E2AP : Failed to fill E2SM-KPM Indication message format 1");
4167 failedInFormat = true;
4173 case E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_NOTHING:
4174 case E2SM_KPM_IndicationMessage__indicationMessage_formats_PR_indicationMessage_Format2:
4177 DU_LOG("\nERROR --> E2AP : fillRicIndMsgBuf: Only Format 1 supported");
4178 failedInFormat = true;
4186 /* Encode E2SM-KPM Indication Message */
4187 xer_fprint(stdout, &asn_DEF_E2SM_KPM_IndicationMessage, &e2smKpmIndMsg);
4188 memset(encBuf, 0, ENC_BUF_MAX_LEN);
4190 encRetVal = aper_encode(&asn_DEF_E2SM_KPM_IndicationMessage, 0, &e2smKpmIndMsg, PrepFinalEncBuf, encBuf);
4191 if(encRetVal.encoded == ENCODE_FAIL)
4193 DU_LOG("\nERROR --> E2AP : Could not encode E2SM-KPM Indication Message (at %s)\n",\
4194 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
4199 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SM-KPM Indication Message \n");
4200 #ifdef DEBUG_ASN_PRINT
4201 for(int i=0; i< encBufSize; i++)
4203 printf("%x",encBuf[i]);
4208 /* Copy encoded string to RIC Indication Message buffer */
4209 ricIndMsgBuf->size = encBufSize;
4210 DU_ALLOC(ricIndMsgBuf->buf, ricIndMsgBuf->size);
4211 if(!ricIndMsgBuf->buf)
4213 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
4216 memset(ricIndMsgBuf->buf, 0, ricIndMsgBuf->size);
4217 memcpy(ricIndMsgBuf->buf, encBuf, encBufSize);
4223 /* Free E2SM-KPM Indication Message */
4224 FreeE2smKpmIndicationMessage(&e2smKpmIndMsg);
4229 /*******************************************************************
4231 * @brief Free E2SM-KPM Indication Header
4235 * Function : FreeE2smKpmIndicationHeader
4237 * Functionality: Free E2SM-KPM Indication Header
4239 * @param E2SM-KPM Indication Header to be free
4242 ******************************************************************/
4243 void FreeE2smKpmIndicationHeader(E2SM_KPM_IndicationHeader_t *e2smKpmIndHdr)
4245 E2SM_KPM_IndicationHeader_Format1_t *format1 = NULLP;
4249 switch(e2smKpmIndHdr->indicationHeader_formats.present)
4251 case E2SM_KPM_IndicationHeader__indicationHeader_formats_PR_indicationHeader_Format1:
4253 if(e2smKpmIndHdr->indicationHeader_formats.choice.indicationHeader_Format1)
4255 format1 = e2smKpmIndHdr->indicationHeader_formats.choice.indicationHeader_Format1;
4257 DU_FREE(format1->colletStartTime.buf, format1->colletStartTime.size);
4258 DU_FREE(format1, sizeof(E2SM_KPM_IndicationHeader_Format1_t));
4262 case E2SM_KPM_IndicationHeader__indicationHeader_formats_PR_NOTHING:
4269 /*******************************************************************
4271 * @brief Fill RIC Indication Header buffer
4275 * Function : fillRicIndHeader
4277 * Functionality: Fill E2SM-KPM Indication Header
4278 * Encode this message and copy to RIC Indication Header buffer
4280 * @param RIC Indication Header buffer to be filled
4281 * Source RIC subscription info from E2AP DB
4282 * @return ROK - success
4285 ******************************************************************/
4286 uint8_t fillRicIndHeader(RICindicationHeader_t *ricIndHdr, RicSubscription *ricSubsInfo)
4288 uint8_t ret = RFAILED;
4289 uint8_t secBufIdx = 0, milliSecBufIdx = 0;
4291 bool formatFailure = false;
4292 RanFunction *ranFunc = NULLP;
4293 ReportStartTime *startTime = NULLP;
4294 E2SM_KPM_IndicationHeader_t e2smKpmIndHdr;
4295 E2SM_KPM_IndicationHeader_Format1_t *format1 = NULLP;
4296 asn_enc_rval_t encRetVal; /* Encoder return value */
4300 ranFunc = fetchRanFuncFromRanFuncId(ricSubsInfo->ranFuncId);
4301 if(ranFunc == NULLP)
4303 DU_LOG("\nERROR --> E2AP : RAN Function ID [%d] not found", ricSubsInfo->ranFuncId);
4307 memset(&e2smKpmIndHdr, 0, sizeof(E2SM_KPM_IndicationHeader_t));
4309 e2smKpmIndHdr.indicationHeader_formats.present = ranFunc->ricIndicationHeaderFormat;
4310 switch(e2smKpmIndHdr.indicationHeader_formats.present)
4312 case E2SM_KPM_IndicationHeader__indicationHeader_formats_PR_indicationHeader_Format1:
4314 DU_ALLOC(e2smKpmIndHdr.indicationHeader_formats.choice.indicationHeader_Format1, \
4315 sizeof(E2SM_KPM_IndicationHeader_Format1_t));
4316 if(!e2smKpmIndHdr.indicationHeader_formats.choice.indicationHeader_Format1)
4318 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
4319 formatFailure = true;
4322 format1 = e2smKpmIndHdr.indicationHeader_formats.choice.indicationHeader_Format1;
4324 /* Fetch reporting period start time from DB */
4325 switch(ricSubsInfo->eventTriggerDefinition.formatType)
4329 startTime = &ricSubsInfo->eventTriggerDefinition.choice.format1.startTime;
4333 format1->colletStartTime.size = 8 * sizeof(uint8_t);
4334 DU_ALLOC(format1->colletStartTime.buf, format1->colletStartTime.size);
4335 if(!format1->colletStartTime.buf)
4337 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
4338 formatFailure = true;
4342 /* As per O-RAN.WG3.E2SM-KPM-R003-v03.00, section 8.3.12 and
4343 * RFC 5905, section 6 :
4344 * Time stamp has a 64-bit format where first 32-bit is seconds
4345 * and next 32-bit is fraction in picosecond-level.
4346 * This fraction has been rounded in microseconds.
4349 * Storing 32-bit seconds at MSB 0-3 and
4350 * 32-bit milliseconds at next 4 bytes i.e. bytes 4-7
4354 for(byteIdx = 3; byteIdx >= 0; byteIdx--)
4356 format1->colletStartTime.buf[secBufIdx++] = startTime->timeInSec >> (8*byteIdx);
4357 format1->colletStartTime.buf[milliSecBufIdx++] = startTime->timeInMilliSec >> (8*byteIdx);
4362 case E2SM_KPM_IndicationHeader__indicationHeader_formats_PR_NOTHING:
4365 DU_LOG("\nERROR --> E2AP : Only E2SM-KPM Indication Header Format 1 supported");
4366 formatFailure = true;
4374 /* Encode E2SM-KPM Indication Header */
4375 xer_fprint(stdout, &asn_DEF_E2SM_KPM_IndicationHeader, &e2smKpmIndHdr);
4376 memset(encBuf, 0, ENC_BUF_MAX_LEN);
4378 encRetVal = aper_encode(&asn_DEF_E2SM_KPM_IndicationHeader, 0, &e2smKpmIndHdr, PrepFinalEncBuf, encBuf);
4379 if(encRetVal.encoded == ENCODE_FAIL)
4381 DU_LOG("\nERROR --> E2AP : Could not encode E2SM-KPM Indication Header (at %s)\n",\
4382 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
4387 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2SM-KPM Indication Header \n");
4388 #ifdef DEBUG_ASN_PRINT
4389 for(int i=0; i< encBufSize; i++)
4391 printf("%x",encBuf[i]);
4396 /* Copy encoded string to RIC Indication Header buffer */
4397 ricIndHdr->size = encBufSize;
4398 DU_ALLOC(ricIndHdr->buf, ricIndHdr->size);
4401 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
4404 memset(ricIndHdr->buf, 0, ricIndHdr->size);
4405 memcpy(ricIndHdr->buf, encBuf, encBufSize);
4410 /* Free E2SM-KPM Indication Header */
4411 FreeE2smKpmIndicationHeader(&e2smKpmIndHdr);
4416 /*******************************************************************
4418 * brief Fill the RIC Indication Message
4422 * Function : fillRicIndication
4424 * Functionality: Fills the RIC Indication Message
4426 * @param RIC Indication Message to be filled
4427 * RIC Subscription DB
4429 * @return ROK - success
4432 ******************************************************************/
4433 uint8_t fillRicIndication(RICindication_t *ricIndicationMsg, RicSubscription *ricSubscriptionInfo, ActionInfo *actionInfo)
4435 uint8_t elementCnt = 0, idx = 0;
4440 ricIndicationMsg->protocolIEs.list.count = elementCnt;
4441 ricIndicationMsg->protocolIEs.list.size = elementCnt * sizeof(RICindication_IEs_t *);
4443 /* Initialize the Ric Indication members */
4444 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array, ricIndicationMsg->protocolIEs.list.size);
4445 if(ricIndicationMsg->protocolIEs.list.array == NULLP)
4447 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
4451 for(idx=0; idx<elementCnt; idx++)
4453 DU_ALLOC(ricIndicationMsg->protocolIEs.list.array[idx], sizeof(RICindication_IEs_t));
4454 if(ricIndicationMsg->protocolIEs.list.array[idx] == NULLP)
4456 DU_LOG("\nERROR --> E2AP : Memory allocation in [%s] at line [%d]", __func__, __LINE__);
4461 /* RIC Request ID */
4463 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICrequestID;
4464 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
4465 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RICrequestID;
4466 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricRequestorID = \
4467 ricSubscriptionInfo->requestId.requestorId;
4468 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICrequestID.ricInstanceID = \
4469 ricSubscriptionInfo->requestId.instanceId;
4471 /* RAN Function ID */
4473 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RANfunctionID;
4474 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
4475 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RANfunctionID;
4476 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RANfunctionID = ricSubscriptionInfo->ranFuncId;
4480 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICactionID;
4481 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
4482 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RICactionID;
4483 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICactionID = actionInfo->actionId;
4485 /* RIC Indication Type */
4487 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationType;
4488 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
4489 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RICindicationType;
4490 ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationType = actionInfo->type;
4492 /* RIC Indication Header */
4494 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationHeader;
4495 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
4496 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RICindicationHeader;
4497 if(fillRicIndHeader(&ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationHeader, \
4498 ricSubscriptionInfo) != ROK)
4500 DU_LOG("\nERROR --> E2AP : Failed to fill RIC Indication header");
4504 /* RIC Indication Message */
4506 ricIndicationMsg->protocolIEs.list.array[idx]->id = ProtocolIE_IDE2_id_RICindicationMessage;
4507 ricIndicationMsg->protocolIEs.list.array[idx]->criticality = CriticalityE2_reject;
4508 ricIndicationMsg->protocolIEs.list.array[idx]->value.present = RICindication_IEs__value_PR_RICindicationMessage;
4509 if(fillRicIndMsgBuf(&ricIndicationMsg->protocolIEs.list.array[idx]->value.choice.RICindicationMessage, \
4512 DU_LOG("\nERROR --> E2AP : Failed to fill RIC Indication Message");
4519 /*******************************************************************
4521 * @brief Builds and Send the RicIndication Message
4525 * Function : BuildAndSendRicIndication
4527 * Functionality:Fills the RicIndication Message
4529 * @return ROK - success
4532 ******************************************************************/
4534 uint8_t BuildAndSendRicIndication(RicSubscription *ricSubscriptionInfo, ActionInfo *actionInfo)
4536 uint8_t ret = RFAILED;
4537 E2AP_PDU_t *e2apMsg = NULLP;
4538 RICindication_t *ricIndicationMsg = NULLP;
4539 asn_enc_rval_t encRetVal; /* Encoder return value */
4543 DU_LOG("\nINFO --> E2AP : Building RIC Indication Message\n");
4545 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
4546 if(e2apMsg == NULLP)
4548 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
4552 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
4553 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
4554 if(e2apMsg->choice.initiatingMessage == NULLP)
4556 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
4559 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICindication;
4560 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
4561 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICindication;
4563 ricIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.RICindication;
4565 if(fillRicIndication(ricIndicationMsg, ricSubscriptionInfo, actionInfo) != ROK)
4567 DU_LOG("\nERROR --> E2AP : Failed to fill RIC Indication message");
4571 /* Prints the Msg formed */
4572 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
4573 memset(encBuf, 0, ENC_BUF_MAX_LEN);
4575 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
4577 if(encRetVal.encoded == ENCODE_FAIL)
4579 DU_LOG("\nERROR --> E2AP : Could not encode RIC Indication Message (at %s)\n",\
4580 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
4585 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC Indication Message \n");
4586 #ifdef DEBUG_ASN_PRINT
4587 for(int i=0; i< encBufSize; i++)
4589 printf("%x",encBuf[i]);
4594 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
4596 DU_LOG("\nINFO --> E2AP : Sending RIC Indication Message");
4602 FreeRicIndication(e2apMsg);
4606 /*******************************************************************
4608 * @brief free e2 node component configuration req and rsp
4612 * Function : freeE2NodeComponentConfiguration
4615 * - free e2 node component configuration req and rsp
4617 * @params[in] E2nodeComponentConfiguration_t *e2nodeComponentConfiguration
4618 * @return ROK - success
4621 * ****************************************************************/
4623 void freeE2NodeComponentConfiguration(E2nodeComponentConfiguration_t *e2nodeComponentConfiguration)
4625 /* Free E2 Node Component Request Part */
4626 DU_FREE(e2nodeComponentConfiguration->e2nodeComponentRequestPart.buf, e2nodeComponentConfiguration->e2nodeComponentRequestPart.size);
4628 /* Free E2 Node Component Response Part */
4629 DU_FREE(e2nodeComponentConfiguration->e2nodeComponentResponsePart.buf, e2nodeComponentConfiguration->e2nodeComponentResponsePart.size);
4633 /*******************************************************************
4635 * @brief free e2 node component component identifier
4639 * Function : freeE2NodeComponentIdentifier
4642 * - free e2 node component component identifier
4644 * @params[in] E2nodeComponentID_t *componentID
4645 * @return ROK - success
4648 * ****************************************************************/
4650 void freeE2NodeComponentIdentifier(E2nodeComponentID_t *componentID)
4652 if(componentID->choice.e2nodeComponentInterfaceTypeF1)
4654 DU_FREE(componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.buf, componentID->choice.e2nodeComponentInterfaceTypeF1->gNB_DU_ID.size);
4655 DU_FREE(componentID->choice.e2nodeComponentInterfaceTypeF1, sizeof(E2nodeComponentInterfaceF1_t));
4660 /*******************************************************************
4662 * @brief Deallocate the memory allocated for E2nodeConfigurationUpdate msg
4666 * Function : FreeE2NodeConfigUpdate
4669 * - freeing the memory allocated for E2nodeConfigurationUpdate
4671 * @params[in] E2AP_PDU_t *e2apMsg
4672 * @return ROK - success
4675 * ****************************************************************/
4677 void FreeE2NodeConfigUpdate(E2AP_PDU_t *e2apMsg)
4679 uint8_t arrIdx =0, e2NodeUpdateListIdx=0, e2NodeRemovalListIdx=0, e2NodeAddListIdx=0;
4680 E2nodeConfigurationUpdate_t *e2NodeConfigUpdate =NULL;
4681 E2nodeComponentConfigUpdate_List_t *e2NodeUpdateList =NULL;
4682 E2nodeComponentConfigUpdate_ItemIEs_t *e2NodeUpdateItem =NULL;
4683 E2nodeComponentConfigRemoval_List_t *e2NodeRemovalList =NULL;
4684 E2nodeComponentConfigRemoval_ItemIEs_t *e2NodeRemovalItem =NULL;
4685 E2nodeComponentConfigAddition_List_t *e2NodeAddList =NULL;
4686 E2nodeComponentConfigAddition_ItemIEs_t *e2NodeAddItem =NULL;
4688 if(e2apMsg != NULLP)
4690 if(e2apMsg->choice.initiatingMessage != NULLP)
4692 e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
4693 if(e2NodeConfigUpdate->protocolIEs.list.array != NULLP)
4695 for(arrIdx = 0; arrIdx < e2NodeConfigUpdate->protocolIEs.list.count; arrIdx++)
4697 if(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx])
4700 switch(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id)
4702 case ProtocolIE_IDE2_id_TransactionID:
4705 case ProtocolIE_IDE2_id_E2nodeComponentConfigAddition:
4707 e2NodeAddList = &e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List;
4708 if(e2NodeAddList->list.array)
4710 for(e2NodeAddListIdx = 0; e2NodeAddListIdx< e2NodeAddList->list.count; e2NodeAddListIdx++)
4712 e2NodeAddItem = (E2nodeComponentConfigAddition_ItemIEs_t *) e2NodeAddList->list.array[e2NodeAddListIdx];
4714 freeE2NodeComponentConfiguration(&e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentConfiguration);
4715 freeE2NodeComponentIdentifier(&e2NodeAddItem->value.choice.E2nodeComponentConfigAddition_Item.e2nodeComponentID);
4716 DU_FREE(e2NodeAddItem, sizeof(E2nodeComponentConfigAddition_ItemIEs_t));
4718 DU_FREE(e2NodeAddList->list.array, e2NodeAddList->list.size);
4722 case ProtocolIE_IDE2_id_E2nodeComponentConfigUpdate:
4724 e2NodeUpdateList = &e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigUpdate_List;
4725 if(e2NodeUpdateList->list.array)
4727 for(e2NodeUpdateListIdx = 0; e2NodeUpdateListIdx< e2NodeUpdateList->list.count; e2NodeUpdateListIdx++)
4729 e2NodeUpdateItem = (E2nodeComponentConfigUpdate_ItemIEs_t *) e2NodeUpdateList->list.array[e2NodeUpdateListIdx];
4731 freeE2NodeComponentConfiguration(&e2NodeUpdateItem->value.choice.E2nodeComponentConfigUpdate_Item.e2nodeComponentConfiguration);
4732 freeE2NodeComponentIdentifier(&e2NodeUpdateItem->value.choice.E2nodeComponentConfigUpdate_Item.e2nodeComponentID);
4733 DU_FREE(e2NodeUpdateItem, sizeof(E2nodeComponentConfigUpdate_ItemIEs_t));
4735 DU_FREE(e2NodeUpdateList->list.array, e2NodeUpdateList->list.size);
4739 case ProtocolIE_IDE2_id_E2nodeComponentConfigRemoval:
4741 e2NodeRemovalList = &e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigRemoval_List;
4742 if(e2NodeRemovalList->list.array)
4744 for(e2NodeRemovalListIdx = 0; e2NodeRemovalListIdx< e2NodeRemovalList->list.count; e2NodeRemovalListIdx++)
4746 e2NodeRemovalItem = (E2nodeComponentConfigRemoval_ItemIEs_t *) e2NodeRemovalList->list.array[e2NodeRemovalListIdx];
4748 freeE2NodeComponentIdentifier(&e2NodeRemovalItem->value.choice.E2nodeComponentConfigRemoval_Item.e2nodeComponentID);
4749 DU_FREE(e2NodeRemovalItem, sizeof(E2nodeComponentConfigRemoval_ItemIEs_t));
4751 DU_FREE(e2NodeRemovalList->list.array, e2NodeRemovalList->list.size);
4759 DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
4762 DU_FREE(e2NodeConfigUpdate->protocolIEs.list.array, e2NodeConfigUpdate->protocolIEs.list.size);
4764 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
4766 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
4770 /*******************************************************************
4772 * @brief Buld and send the E2 node config update msg
4776 * Function : BuildAndSendE2NodeConfigUpdate
4779 * - Buld and send the E2 node config update msg
4782 * @return ROK - success
4785 * ****************************************************************/
4787 uint8_t BuildAndSendE2NodeConfigUpdate(E2NodeConfigList *e2NodeList)
4789 uint8_t ret = RFAILED;
4790 uint8_t arrIdx = 0,elementCnt = 0, transId=0;
4791 E2AP_PDU_t *e2apMsg = NULLP;
4792 asn_enc_rval_t encRetVal; /* Encoder return value */
4793 E2nodeConfigurationUpdate_t *e2NodeConfigUpdate = NULLP;
4795 DU_LOG("\nINFO --> E2AP : Building E2 Node config update\n");
4798 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
4799 if(e2apMsg == NULLP)
4801 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
4805 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
4806 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
4807 if(e2apMsg->choice.initiatingMessage == NULLP)
4809 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
4812 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
4813 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2nodeConfigurationUpdate;
4814 e2apMsg->choice.initiatingMessage->value.present = \
4815 InitiatingMessageE2__value_PR_E2nodeConfigurationUpdate;
4816 e2NodeConfigUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2nodeConfigurationUpdate;
4819 if(e2NodeList->addE2NodeCount)
4821 if(e2NodeList->updateE2NodeCount)
4823 if(e2NodeList->removeE2NodeCount)
4826 e2NodeConfigUpdate->protocolIEs.list.count = elementCnt;
4827 e2NodeConfigUpdate->protocolIEs.list.size = elementCnt * sizeof(E2nodeConfigurationUpdate_IEs_t*);
4828 DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array, e2NodeConfigUpdate->protocolIEs.list.size);
4829 if(e2NodeConfigUpdate->protocolIEs.list.array == NULLP)
4831 DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed");
4835 for(arrIdx =0; arrIdx<elementCnt; arrIdx++)
4837 DU_ALLOC(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx], sizeof(E2nodeConfigurationUpdate_IEs_t));
4838 if(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx] == NULLP)
4841 DU_LOG("\nERROR --> E2AP : Memory allocation for e2NodeConfigUpdate failed");
4846 if(arrIdx<elementCnt)
4850 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
4851 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
4852 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_TransactionID;
4853 transId = assignTransactionId();
4854 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
4856 if(e2NodeList->addE2NodeCount)
4859 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigAddition;
4860 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
4861 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_E2nodeComponentConfigAddition_List;
4862 if(BuildE2NodeConfigAddList(&(e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAddition_List),\
4863 ProcedureCodeE2_id_E2nodeConfigurationUpdate, e2NodeList->addE2NodeCount, e2NodeList->addE2Node)!=ROK)
4865 DU_LOG("\nERROR --> E2AP : Failed to create E2 Node config list");
4870 if(e2NodeList->updateE2NodeCount)
4873 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigUpdate;
4874 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
4875 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_E2nodeComponentConfigUpdate_List;
4876 if(BuildE2NodeConfigUpdateList(&e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigUpdate_List,\
4877 e2NodeList->updateE2NodeCount, e2NodeList->updateE2Node) != ROK)
4880 DU_LOG("\nERROR --> E2AP : Failed to update the E2 node configuration");
4885 if(e2NodeList->removeE2NodeCount)
4888 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_E2nodeComponentConfigRemoval;
4889 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
4890 e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.present = E2nodeConfigurationUpdate_IEs__value_PR_E2nodeComponentConfigRemoval_List;
4891 if(BuildE2NodeConfigRemoveList(&e2NodeConfigUpdate->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigRemoval_List,\
4892 e2NodeList->removeE2NodeCount, e2NodeList->removeE2Node) != ROK)
4895 DU_LOG("\nERROR --> E2AP : Failed to remove the E2 node configuration");
4900 /* Prints the Msg formed */
4901 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
4903 memset(encBuf, 0, ENC_BUF_MAX_LEN);
4905 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
4906 if(encRetVal.encoded == ENCODE_FAIL)
4908 DU_LOG("\nERROR --> E2AP : Could not encode E2nodeConfigurationUpdate structure (at %s)\n",\
4909 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
4914 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2nodeConfigurationUpdate\n");
4915 #ifdef DEBUG_ASN_PRINT
4916 for(int i=0; i< encBufSize; i++)
4918 printf("%x",encBuf[i]);
4922 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize))
4924 DU_LOG("\nERROR --> E2AP : Sending E2 node config update failed");
4928 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
4929 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
4930 memcpy(&duCb.e2apDb.e2TimersInfo.e2Timers.e2NodeConfigUpdate.configList, e2NodeList, sizeof(E2NodeConfigList));
4935 FreeE2NodeConfigUpdate(e2apMsg);
4939 /*******************************************************************
4941 * @brief Deallocate the memory allocated for E2ResetRequest msg
4945 * Function : FreeE2ResetRequest
4948 * - freeing the memory allocated for E2ResetRequest
4950 * @params[in] E2AP_PDU_t *e2apMsg
4951 * @return ROK - success
4954 * ****************************************************************/
4955 void FreeE2ResetRequest(E2AP_PDU_t *e2apMsg)
4958 ResetRequestE2_t *resetReq = NULLP;
4960 if(e2apMsg != NULLP)
4962 if(e2apMsg->choice.initiatingMessage != NULLP)
4964 resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
4965 if(resetReq->protocolIEs.list.array)
4967 for(ieIdx = 0; ieIdx < resetReq->protocolIEs.list.count; ieIdx++)
4969 DU_FREE(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
4971 DU_FREE(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
4973 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
4975 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
4979 /*******************************************************************
4981 * @brief Build and send the E2 reset request msg
4985 * Function : BuildAndSendE2ResetRequest
4988 * - Buld and send the E2 reset request msg to RIC
4992 * @return ROK - success
4995 * ****************************************************************/
4996 uint8_t BuildAndSendE2ResetRequest(E2FailureCause resetCause)
4998 uint8_t ieIdx = 0, elementCnt = 0, transId = 0;
4999 uint8_t ret = RFAILED;
5000 E2AP_PDU_t *e2apMsg = NULLP;
5001 ResetRequestE2_t *resetReq = NULLP;
5002 asn_enc_rval_t encRetVal; /* Encoder return value */
5004 DU_LOG("\nINFO --> E2AP : Building E2 Reset Request\n");
5008 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
5009 if(e2apMsg == NULLP)
5011 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation for E2AP-PDU failed");
5015 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
5016 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
5017 if(e2apMsg->choice.initiatingMessage == NULLP)
5019 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation for initiatingMessage");
5023 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_Reset;
5024 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
5025 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_ResetRequestE2;
5026 resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
5029 resetReq->protocolIEs.list.count = elementCnt;
5030 resetReq->protocolIEs.list.size = elementCnt * sizeof(ResetRequestIEs_t *);
5032 DU_ALLOC(resetReq->protocolIEs.list.array, resetReq->protocolIEs.list.size);
5033 if(!resetReq->protocolIEs.list.array)
5035 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation failed for \
5036 Reset Request IE array");
5040 for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
5042 DU_ALLOC(resetReq->protocolIEs.list.array[ieIdx], sizeof(ResetRequestIEs_t));
5043 if(!resetReq->protocolIEs.list.array[ieIdx])
5045 DU_LOG("\nERROR --> E2AP : BuildAndSendE2ResetRequest(): Memory allocation failed for \
5046 Reset Request IE array element");
5051 /* In case of failure */
5052 if(ieIdx < elementCnt)
5056 resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
5057 resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
5058 resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_TransactionID;
5059 transId = assignTransactionId();
5060 resetReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
5063 resetReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_CauseE2;
5064 resetReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_ignore;
5065 resetReq->protocolIEs.list.array[ieIdx]->value.present = ResetRequestIEs__value_PR_CauseE2;
5066 fillE2Cause(&resetReq->protocolIEs.list.array[ieIdx]->value.choice.CauseE2, resetCause);
5068 /* Prints the Msg formed */
5069 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
5071 memset(encBuf, 0, ENC_BUF_MAX_LEN);
5073 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
5075 if(encRetVal.encoded == ENCODE_FAIL)
5077 DU_LOG("\nERROR --> E2AP : Could not encode reset request structure (at %s)\n",\
5078 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
5083 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for reset request\n");
5084 #ifdef DEBUG_ASN_PRINT
5085 for(int i=0; i< encBufSize; i++)
5087 printf("%x",encBuf[i]);
5091 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
5093 DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
5097 /* In case the message is sent successfully, store the transaction info to
5098 * be used when response is received */
5099 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
5100 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
5106 /* Free all memory */
5107 FreeE2ResetRequest(e2apMsg);
5111 /*******************************************************************
5113 * @brief Deallocate the memory allocated for Reset Response msg
5117 * Function : freeAperDecodingOfE2ResetRsp
5120 * - freeing the memory allocated for Reset response
5122 * @params[in] ResetResponseE2_t *resetResponse
5125 * ****************************************************************/
5126 void freeAperDecodingOfE2ResetRsp(ResetResponseE2_t *resetResponse)
5132 if(resetResponse->protocolIEs.list.array)
5134 for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
5136 if(resetResponse->protocolIEs.list.array[ieIdx])
5138 switch(resetResponse->protocolIEs.list.array[ieIdx]->id)
5140 case ProtocolIE_IDE2_id_TransactionID:
5143 case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
5146 free(resetResponse->protocolIEs.list.array[ieIdx]);
5149 free(resetResponse->protocolIEs.list.array);
5154 /******************************************************************
5156 * @brief Processes E2 Reset Response sent by RIC
5160 * Function : procResetResponse
5162 * Functionality: Processes E2 Reset Response sent by RIC
5164 * @params[in] E2AP_PDU_t ASN decoded E2AP message
5167 * ****************************************************************/
5168 void procResetResponse(E2AP_PDU_t *e2apMsg)
5170 bool invalidTransId=false;
5171 uint8_t ieIdx =0, transId =0;
5172 uint16_t ranFuncIdx=0;
5173 ResetResponseE2_t *resetResponse =NULLP;
5175 DU_LOG("\nINFO --> E2AP : E2 Reset Response received");
5176 resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2;;
5178 for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
5180 switch(resetResponse->protocolIEs.list.array[ieIdx]->id)
5182 case ProtocolIE_IDE2_id_TransactionID:
5184 transId = resetResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
5185 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) && \
5186 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.successfulOutcome->procedureCode))
5188 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
5192 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
5193 invalidTransId = true;
5197 case ProtocolIE_IDE2_id_CriticalityDiagnosticsE2:
5199 for(ranFuncIdx=0; ranFuncIdx<MAX_RAN_FUNCTION; ranFuncIdx++)
5201 if(duCb.e2apDb.ranFunction[ranFuncIdx].id >0)
5203 deleteRicSubscriptionList(&(duCb.e2apDb.ranFunction[ranFuncIdx].subscriptionList));
5204 memset(&(duCb.e2apDb.ranFunction[ranFuncIdx].pendingSubsRspInfo), 0, MAX_PENDING_SUBSCRIPTION_RSP*sizeof(PendingSubsRspInfo));
5211 DU_LOG("\nERROR --> E2AP : Invalid IE received in E2 Reset Response : %ld",
5212 resetResponse->protocolIEs.list.array[ieIdx]->id);
5217 if(invalidTransId == true)
5223 freeAperDecodingOfE2ResetRsp(resetResponse);
5226 /******************************************************************
5228 * @brief Deallocation of memory allocated by aper decoder for e2 setup Failure
5232 * Function : freeAperDecodingOfE2SetupFailure
5234 * Functionality: Deallocation of memory allocated by aper decoder for e2
5237 * @params[in] E2setupFailure_t *e2SetupFailure;
5240 * ****************************************************************/
5241 void freeAperDecodingOfE2SetupFailure(E2setupFailure_t *e2SetupFailure)
5247 if(e2SetupFailure->protocolIEs.list.array)
5249 for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
5251 if(e2SetupFailure->protocolIEs.list.array[arrIdx])
5253 free(e2SetupFailure->protocolIEs.list.array[arrIdx]);
5256 free(e2SetupFailure->protocolIEs.list.array);
5260 /******************************************************************
5262 * @brief Processes E2 Setup Failure sent by RIC
5266 * Function : procE2SetupFailure
5268 * Functionality: Processes E2 Setup failure sent by RIC
5270 * @params[in] E2AP_PDU_t ASN decoded E2AP message
5271 * @return ROK - success
5274 * ****************************************************************/
5275 void procE2SetupFailure(E2AP_PDU_t *e2apMsg)
5277 uint8_t arrIdx =0, transId =0, timerValue=0;
5278 E2setupFailure_t *e2SetupFailure;
5280 DU_LOG("\nINFO --> E2AP : E2 Setup failure received");
5281 e2SetupFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2setupFailure;
5283 for(arrIdx=0; arrIdx<e2SetupFailure->protocolIEs.list.count; arrIdx++)
5285 switch(e2SetupFailure->protocolIEs.list.array[arrIdx]->id)
5287 case ProtocolIE_IDE2_id_TransactionID:
5289 transId = e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
5290 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
5291 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
5293 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
5297 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
5302 case ProtocolIE_IDE2_id_TimeToWaitE2:
5304 timerValue = convertE2WaitTimerEnumToValue(e2SetupFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2);
5305 if((duChkTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.e2SetupTimer), EVENT_E2_SETUP_TMR)) == FALSE)
5307 duStartTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.e2SetupTimer), EVENT_E2_SETUP_TMR, timerValue);
5311 DU_LOG("\nERROR --> E2AP : EVENT_E2_SETUP_TMR timer is already running");
5319 freeAperDecodingOfE2SetupFailure(e2SetupFailure);
5321 /******************************************************************
5323 * @brief Deallocation of memory allocated by aper decoder for RIC service Query
5327 * Function : freeAperDecodingOfRicServiceQuery
5329 * Functionality: Deallocation of memory allocated by aper decoder for RIC
5332 * @params[in] RICserviceQuery_t *ricServiceQuery;
5335 * ****************************************************************/
5337 void freeAperDecodingOfRicServiceQuery(RICserviceQuery_t *ricServiceQuery)
5339 uint8_t arrIdx,ranFuncIdx;
5340 RANfunctionsID_List_t *ranFuncAddedList;
5344 if(ricServiceQuery->protocolIEs.list.array)
5346 for(arrIdx=0; arrIdx<ricServiceQuery->protocolIEs.list.count; arrIdx++)
5348 if(ricServiceQuery->protocolIEs.list.array[arrIdx])
5350 switch(ricServiceQuery->protocolIEs.list.array[arrIdx]->id)
5352 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
5354 ranFuncAddedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
5355 if(ranFuncAddedList->list.array)
5357 for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
5359 free(ranFuncAddedList->list.array[ranFuncIdx]);
5361 free(ranFuncAddedList->list.array);;
5368 free(ricServiceQuery->protocolIEs.list.array[arrIdx]);
5371 free(ricServiceQuery->protocolIEs.list.array);
5375 /*******************************************************************
5377 * @brief Build RanFunction Delete List
5381 * Function : BuildRanFunctionDeleteList
5383 * Functionality: Build RanFunction Delete List
5386 * RANfunctionsID List
5387 * Count of the RAN function
5388 * Received RAN function list
5390 * @return ROK - success
5393 ******************************************************************/
5395 uint8_t BuildRanFunctionDeleteList(RANfunctionsID_List_t *deleteList, uint8_t count, RanFuncInfo *recvdRanFunc)
5397 uint8_t ranFuncIdx=0;
5398 RANfunctionID_ItemIEs_t *delRanFuncItem;
5402 deleteList->list.count = count;
5403 deleteList->list.size = deleteList->list.count * sizeof(RANfunctionID_ItemIEs_t*);
5404 DU_ALLOC(deleteList->list.array, deleteList->list.size);
5405 if(deleteList->list.array == NULLP)
5407 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
5410 for(ranFuncIdx = 0; ranFuncIdx< deleteList->list.count; ranFuncIdx++)
5412 DU_ALLOC(deleteList->list.array[ranFuncIdx], sizeof(RANfunctionID_ItemIEs_t));
5413 if(deleteList->list.array[ranFuncIdx] == NULLP)
5415 DU_LOG("\nERROR --> E2AP: Memory allocation failed in %s at %d",__func__, __LINE__);
5418 delRanFuncItem= (RANfunctionID_ItemIEs_t *) deleteList->list.array[ranFuncIdx];
5419 delRanFuncItem->id = ProtocolIE_IDE2_id_RANfunctionID_Item;
5420 delRanFuncItem->criticality = CriticalityE2_ignore;
5421 delRanFuncItem->value.choice.RANfunctionID_Item.ranFunctionID = recvdRanFunc[ranFuncIdx].id;
5422 delRanFuncItem->value.choice.RANfunctionID_Item.ranFunctionRevision = recvdRanFunc[ranFuncIdx].revisionCounter;
5428 /*******************************************************************
5430 * @brief De Allocate Ric Service Update message
5434 * Function : FreeRicServiceUpdate
5436 * Functionality: De-Allocating Ric Service Update message
5438 * @params[in] E2AP_PDU_t *e2apMsg
5442 * ****************************************************************/
5444 void FreeRicServiceUpdate(E2AP_PDU_t *e2apMsg)
5447 uint8_t ranFuncAddListIdx=0, ranFuncDelIdx=0;
5448 RICserviceUpdate_t *ricServiceUpdate;
5449 RANfunctions_List_t *ranFunctionsList;
5450 RANfunction_ItemIEs_t *ranFuncItemIe;
5451 RANfunction_Item_t *ranFunItem;
5452 RANfunctionsID_List_t *deleteList;
5454 /* De-allocating Memory */
5455 if(e2apMsg != NULLP)
5457 if(e2apMsg->choice.initiatingMessage != NULLP)
5459 ricServiceUpdate = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceUpdate;
5460 if(ricServiceUpdate->protocolIEs.list.array != NULLP)
5462 for(arrIdx = 0; arrIdx < ricServiceUpdate->protocolIEs.list.count; arrIdx++)
5464 if(ricServiceUpdate->protocolIEs.list.array[arrIdx] != NULLP)
5466 switch(ricServiceUpdate->protocolIEs.list.array[arrIdx]->id)
5468 case ProtocolIE_IDE2_id_TransactionID:
5471 case ProtocolIE_IDE2_id_RANfunctionsAdded:
5472 case ProtocolIE_IDE2_id_RANfunctionsModified:
5474 ranFunctionsList = &(ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List);
5475 if(ranFunctionsList->list.array)
5477 for(ranFuncAddListIdx= 0; ranFuncAddListIdx< ranFunctionsList->list.count; ranFuncAddListIdx++)
5479 if(ranFunctionsList->list.array[ranFuncAddListIdx])
5481 ranFuncItemIe = (RANfunction_ItemIEs_t *) ranFunctionsList->list.array[ranFuncAddListIdx];
5482 ranFunItem = &ranFuncItemIe->value.choice.RANfunction_Item;
5483 DU_FREE(ranFunItem->ranFunctionOID.buf, ranFunItem->ranFunctionOID.size);
5484 DU_FREE(ranFunItem->ranFunctionDefinition.buf, ranFunItem->ranFunctionDefinition.size);
5485 DU_FREE(ranFunctionsList->list.array[ranFuncAddListIdx], sizeof(RANfunction_ItemIEs_t));
5488 DU_FREE(ranFunctionsList->list.array, ranFunctionsList->list.size);
5492 case ProtocolIE_IDE2_id_RANfunctionsDeleted:
5494 deleteList= &ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
5495 if(deleteList->list.array)
5497 for(ranFuncDelIdx = 0; ranFuncDelIdx< deleteList->list.count; ranFuncDelIdx++)
5499 DU_FREE(deleteList->list.array[ranFuncDelIdx], sizeof(RANfunctionID_ItemIEs_t));
5501 DU_FREE(deleteList->list.array, deleteList->list.size);
5507 DU_LOG("\nERROR --> E2AP: Invalid event at ricServiceUpdate %ld ",\
5508 (ricServiceUpdate->protocolIEs.list.array[arrIdx]->id));
5511 DU_FREE(ricServiceUpdate->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdate_IEs_t));
5514 DU_FREE(ricServiceUpdate->protocolIEs.list.array, ricServiceUpdate->protocolIEs.list.size);
5516 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
5518 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
5522 /*******************************************************************
5524 * @brief Builds and Send the RicServiceUpdateuest
5528 * Function : BuildAndSendRicServiceUpdate
5530 * Functionality:Fills the RicServiceUpdateuest
5532 * @return ROK - success
5535 ******************************************************************/
5537 uint8_t BuildAndSendRicServiceUpdate(RicServiceUpdate serviceUpdate)
5539 uint8_t arrIdx = 0, elementCnt=0;
5540 uint8_t transId = 0, ret = RFAILED;
5541 bool memAllocFailed =false;
5542 E2AP_PDU_t *e2apMsg = NULLP;
5543 RICserviceUpdate_t *ricServiceUpdate = NULLP;
5544 asn_enc_rval_t encRetVal; /* Encoder return value */
5546 DU_LOG("\nINFO --> E2AP : Building Ric Service Update\n");
5549 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
5550 if(e2apMsg == NULLP)
5552 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
5555 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
5556 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
5557 if(e2apMsg->choice.initiatingMessage == NULLP)
5559 DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
5562 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
5563 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICserviceUpdate;
5564 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICserviceUpdate;
5565 ricServiceUpdate = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceUpdate;
5567 /* For TransId IE, set elementCnt to 1.
5568 If there is any item in the RAN function add list, RAN function modification list, or RAN function delete list, increment the elementCnt.*/
5571 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
5573 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeModified)
5575 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted)
5578 ricServiceUpdate->protocolIEs.list.count = elementCnt;
5579 ricServiceUpdate->protocolIEs.list.size = elementCnt * sizeof(RICserviceUpdate_IEs_t*);
5581 /* Initialize the E2Setup members */
5582 DU_ALLOC(ricServiceUpdate->protocolIEs.list.array, ricServiceUpdate->protocolIEs.list.size);
5583 if(ricServiceUpdate->protocolIEs.list.array == NULLP)
5585 DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements");
5589 for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
5591 DU_ALLOC(ricServiceUpdate->protocolIEs.list.array[arrIdx], sizeof(RICserviceUpdate_IEs_t));
5592 if(ricServiceUpdate->protocolIEs.list.array[arrIdx] == NULLP)
5594 memAllocFailed = true;
5595 DU_LOG("\nERROR --> E2AP : Memory allocation failed for arrayIdx [%d]", arrIdx);
5599 if(memAllocFailed == true)
5605 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
5606 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
5607 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = E2setupRequestIEs__value_PR_TransactionID;
5608 if(serviceUpdate.dir == E2_NODE_INITIATED)
5609 transId = assignTransactionId();
5611 transId = serviceUpdate.transId;
5612 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
5614 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
5617 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAdded;
5618 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
5619 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List;
5620 if(BuildRanFunctionAddList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List,\
5621 e2apMsg->choice.initiatingMessage->procedureCode, serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded, serviceUpdate.recvRanFuncList.ranFunToBeAdded) !=ROK)
5627 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeModified)
5630 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsModified;
5631 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
5632 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctions_List;
5633 if(BuildRanFunctionAddList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctions_List,
5634 e2apMsg->choice.initiatingMessage->procedureCode, serviceUpdate.recvRanFuncList.numOfRanFunToBeModified, serviceUpdate.recvRanFuncList.ranFunToBeModified) !=ROK)
5640 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted)
5643 ricServiceUpdate->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsDeleted;
5644 ricServiceUpdate->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
5645 ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.present = RICserviceUpdate_IEs__value_PR_RANfunctionsID_List;
5646 if(BuildRanFunctionDeleteList(&ricServiceUpdate->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List,\
5647 serviceUpdate.recvRanFuncList.numOfRanFunToBeDeleted, serviceUpdate.recvRanFuncList.ranFunToBeDeleted) != ROK)
5652 /* Prints the Msg formed */
5653 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
5655 memset(encBuf, 0, ENC_BUF_MAX_LEN);
5657 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
5658 if(encRetVal.encoded == ENCODE_FAIL)
5660 DU_LOG("\nERROR --> E2AP : Could not encode RicServiceUpdateuest structure (at %s)\n",\
5661 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
5666 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RicServiceUpdateuest\n");
5667 #ifdef DEBUG_ASN_PRINT
5668 for(int i=0; i< encBufSize; i++)
5670 printf("%x",encBuf[i]);
5674 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
5676 DU_LOG("\nERROR --> E2AP : Sending E2 Setup request failed");
5685 if(serviceUpdate.dir == E2_NODE_INITIATED)
5687 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
5688 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
5692 duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].transactionId = transId;
5693 duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
5695 duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.dir = serviceUpdate.dir;
5696 duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.transId =transId;
5697 memcpy(&duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer.ricService.recvRanFuncList, &serviceUpdate.recvRanFuncList, sizeof(E2TmpRanFunList));
5699 FreeRicServiceUpdate(e2apMsg);
5702 /******************************************************************
5704 * @brief Processes RIC service Query sent by RIC
5708 * Function : procRicServiceQuery
5710 * Functionality: Processes RIC service Query sent by RIC
5712 * @params[in] E2AP_PDU_t ASN decoded E2AP message
5713 * @return ROK - success
5716 * ****************************************************************/
5718 void procRicServiceQuery(E2AP_PDU_t *e2apMsg)
5721 uint16_t arrIdx =0, ranFuncIdx=0,tmpIdx=0;
5722 uint16_t id,revisionCcounter;
5723 bool tmpArray[MAX_RAN_FUNCTION] = {false};
5724 RICserviceQuery_t *ricServiceQuery=NULL;
5725 RicServiceUpdate ricUpdate;
5726 RANfunctionID_ItemIEs_t *ranFuncAddedItemIe;
5727 RANfunctionsID_List_t *ranFuncAddedList;
5729 DU_LOG("\nINFO --> E2AP : RIC Service Query received");
5730 memset(&ricUpdate, 0, sizeof(RicServiceUpdate));
5731 ricUpdate.dir = RIC_INITIATED;
5732 ricServiceQuery = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceQuery;
5734 for(arrIdx=0; arrIdx<ricServiceQuery->protocolIEs.list.count; arrIdx++)
5736 switch(ricServiceQuery->protocolIEs.list.array[arrIdx]->id)
5738 /* TODO completing in next patch/gerrit */
5739 case ProtocolIE_IDE2_id_TransactionID:
5741 ricUpdate.transId = ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
5745 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
5747 ranFuncAddedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
5748 if(ranFuncAddedList->list.array)
5750 for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
5752 if(ranFuncAddedList->list.array[ranFuncIdx])
5754 /* Using the RAN function Id, identify the RAN function to be modified or deleted. */
5756 ranFuncAddedItemIe = (RANfunctionID_ItemIEs_t*)ranFuncAddedList->list.array[ranFuncIdx];
5757 id = ranFuncAddedItemIe->value.choice.RANfunctionID_Item.ranFunctionID;
5758 revisionCcounter = ranFuncAddedItemIe->value.choice.RANfunctionID_Item.ranFunctionRevision;
5760 if((id != duCb.e2apDb.ranFunction[id-1].id))
5762 action = CONFIG_DEL;
5764 else if((id == duCb.e2apDb.ranFunction[id-1].id)&&(revisionCcounter!=duCb.e2apDb.ranFunction[id-1].revisionCounter))
5766 action = CONFIG_MOD;
5769 if(action == CONFIG_DEL)
5771 ricUpdate.recvRanFuncList.ranFunToBeDeleted[ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted].id = id;
5772 ricUpdate.recvRanFuncList.ranFunToBeDeleted[ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted].revisionCounter = revisionCcounter;
5773 ricUpdate.recvRanFuncList.numOfRanFunToBeDeleted++;
5775 else if(action == CONFIG_MOD)
5777 ricUpdate.recvRanFuncList.ranFunToBeModified[ricUpdate.recvRanFuncList.numOfRanFunToBeModified].id = id;
5778 ricUpdate.recvRanFuncList.ranFunToBeModified[ricUpdate.recvRanFuncList.numOfRanFunToBeModified].revisionCounter = revisionCcounter;
5779 ricUpdate.recvRanFuncList.numOfRanFunToBeModified++;
5782 /* If any ID is set to true, it means that the ID has been used in either modification or deletion list.
5783 * Else we will add the IDs into the added list */
5784 tmpArray[id-1] = true;
5793 /* Traversing the whole RAN function list in ducb to check if any new Ran function ids have been added. */
5794 for(arrIdx =0; arrIdx<MAX_RAN_FUNCTION; arrIdx++)
5796 tmpIdx= ricUpdate.recvRanFuncList.numOfRanFunToBeAdded;
5797 if((duCb.e2apDb.ranFunction[arrIdx].id >0)&&(!tmpArray[arrIdx]))
5799 ricUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].id = duCb.e2apDb.ranFunction[arrIdx].id;
5800 ricUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].revisionCounter = duCb.e2apDb.ranFunction[arrIdx].revisionCounter;
5801 ricUpdate.recvRanFuncList.numOfRanFunToBeAdded++;
5805 if(BuildAndSendRicServiceUpdate(ricUpdate)!= ROK)
5807 DU_LOG("\nERROR --> E2AP : Failed to build and send ric service update message");
5810 freeAperDecodingOfRicServiceQuery(ricServiceQuery);
5813 /******************************************************************
5815 * @brief Deallocation of memory allocated by aper decoder for
5816 * RIC service update ack
5820 * Function : freeAperDecodingOfRicServiceUpdateAck
5822 * Functionality: Deallocation of memory allocated by aper decoder
5823 * for RIC service update ack
5825 * @params[in] RICserviceUpdateAck_t *ricServiceAck;
5828 * ****************************************************************/
5830 void freeAperDecodingOfRicServiceUpdateAck(RICserviceUpdateAcknowledge_t *ricServiceAck)
5832 uint8_t arrIdx=0,ranFuncIdx=0;
5833 RANfunctionsID_List_t *ranFuncAddedList=NULL;
5837 if(ricServiceAck->protocolIEs.list.array)
5839 for(arrIdx=0; arrIdx<ricServiceAck->protocolIEs.list.count; arrIdx++)
5841 if(ricServiceAck->protocolIEs.list.array[arrIdx])
5843 switch(ricServiceAck->protocolIEs.list.array[arrIdx]->id)
5845 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
5847 ranFuncAddedList= &ricServiceAck->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
5848 if(ranFuncAddedList->list.array)
5850 for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
5852 free(ranFuncAddedList->list.array[ranFuncIdx]);
5854 free(ranFuncAddedList->list.array);
5861 free(ricServiceAck->protocolIEs.list.array[arrIdx]);
5864 free(ricServiceAck->protocolIEs.list.array);
5869 /******************************************************************
5871 * @brief Processes RIC service update ack sent by RIC
5875 * Function : procRicServiceUpdateAck
5877 * Functionality: Processes RIC service update ack sent by RIC
5879 * @params[in] E2AP_PDU_t ASN decoded E2AP message
5880 * @return ROK - success
5883 * ****************************************************************/
5885 void procRicServiceUpdateAck(E2AP_PDU_t *e2apMsg)
5887 uint8_t arrIdx =0, transId =0;
5888 uint16_t id =0, tmpIdx=0, ranFuncIdx=0;
5889 RicServiceUpdate serviceUpdate;
5890 RANfunctionsIDcause_List_t *rejectedList=NULL;
5891 RICserviceUpdateAcknowledge_t *ricServiceAck=NULL;
5892 RANfunctionIDcause_ItemIEs_t *ranFuncRejectedItemIe=NULL;
5894 DU_LOG("\nINFO --> E2AP : RIC service update ack received");
5895 memset(&serviceUpdate, 0, sizeof(RicServiceUpdate));
5896 ricServiceAck = &e2apMsg->choice.successfulOutcome->value.choice.RICserviceUpdateAcknowledge;
5898 for(arrIdx=0; arrIdx<ricServiceAck->protocolIEs.list.count; arrIdx++)
5900 switch(ricServiceAck->protocolIEs.list.array[arrIdx]->id)
5902 case ProtocolIE_IDE2_id_TransactionID:
5904 transId = ricServiceAck->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
5905 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
5906 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
5908 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
5910 else if((duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].transactionId == transId) &&\
5911 (duCb.e2apDb.e2TransInfo.ricInitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
5913 memset(&duCb.e2apDb.e2TransInfo.ricInitTransaction[transId], 0, sizeof(E2TransInfo));
5917 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
5923 case ProtocolIE_IDE2_id_RANfunctionsAccepted:
5926 case ProtocolIE_IDE2_id_RANfunctionsRejected:
5928 rejectedList= &ricServiceAck->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsIDcause_List;
5929 if(rejectedList->list.array)
5931 for(ranFuncIdx=0;ranFuncIdx<rejectedList->list.count; ranFuncIdx++)
5933 ranFuncRejectedItemIe = (RANfunctionIDcause_ItemIEs_t*)rejectedList->list.array[ranFuncIdx];
5934 id = ranFuncRejectedItemIe->value.choice.RANfunctionIDcause_Item.ranFunctionID;
5935 tmpIdx= serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded;
5936 serviceUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].id = duCb.e2apDb.ranFunction[id-1].id;
5937 serviceUpdate.recvRanFuncList.ranFunToBeAdded[tmpIdx].revisionCounter = duCb.e2apDb.ranFunction[id-1].revisionCounter;
5938 serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded++;
5947 if(serviceUpdate.recvRanFuncList.numOfRanFunToBeAdded)
5949 serviceUpdate.dir = E2_NODE_INITIATED;
5950 BuildAndSendRicServiceUpdate(serviceUpdate);
5952 freeAperDecodingOfRicServiceUpdateAck(ricServiceAck);
5955 /******************************************************************
5957 * @brief Deallocation of memory allocated by aper decoder for
5958 * RIC service update failure
5962 * Function : freeAperDecodingOfRicServiceUpdateFailure
5964 * Functionality: Deallocation of memory allocated by aper decoder
5965 * for RIC service update failure
5967 * @params[in] RICserviceUpdateFailure_t *ricServiceFailure;
5970 * ****************************************************************/
5972 void freeAperDecodingOfRicServiceUpdateFailure(RICserviceUpdateFailure_t *ricServiceFailure)
5976 if(ricServiceFailure)
5978 if(ricServiceFailure->protocolIEs.list.array)
5980 for(arrIdx=0; arrIdx<ricServiceFailure->protocolIEs.list.count; arrIdx++)
5982 if(ricServiceFailure->protocolIEs.list.array[arrIdx])
5984 free(ricServiceFailure->protocolIEs.list.array[arrIdx]);
5987 free(ricServiceFailure->protocolIEs.list.array);
5992 /******************************************************************
5994 * @brief Processes RIC service update failure sent by RIC
5998 * Function : procRicServiceUpdateFailure
6000 * Functionality: Processes RIC service update failure sent by RIC
6002 * @params[in] E2AP_PDU_t ASN decoded E2AP message
6003 * @return ROK - success
6006 * ****************************************************************/
6008 void procRicServiceUpdateFailure(E2AP_PDU_t *e2apMsg)
6010 uint8_t arrIdx =0, timerValue=0;
6011 RICserviceUpdateFailure_t *ricServiceFailure=NULL;
6013 DU_LOG("\nINFO --> E2AP : RIC service update failure received");
6014 ricServiceFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICserviceUpdateFailure;
6016 for(arrIdx=0; arrIdx<ricServiceFailure->protocolIEs.list.count; arrIdx++)
6018 switch(ricServiceFailure->protocolIEs.list.array[arrIdx]->id)
6020 case ProtocolIE_IDE2_id_TransactionID:
6024 case ProtocolIE_IDE2_id_TimeToWaitE2:
6026 timerValue = convertE2WaitTimerEnumToValue(ricServiceFailure->protocolIEs.list.array[arrIdx]->value.choice.TimeToWaitE2);
6027 if((duChkTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer), EVENT_RIC_SERVICE_UPDATE_TMR)) == FALSE)
6029 duStartTmr((PTR)&(duCb.e2apDb.e2TimersInfo.e2Timers.ricServiceUpdateTimer), EVENT_RIC_SERVICE_UPDATE_TMR, timerValue);
6033 DU_LOG("\nERROR --> E2AP : EVENT_RIC_SERVICE_UPDATE_TMR timer is already running");
6038 case ProtocolIE_IDE2_id_CauseE2:
6045 freeAperDecodingOfRicServiceUpdateFailure(ricServiceFailure);
6048 /******************************************************************
6050 * @brief DU Send E2 Node Configuration Update
6054 * Function : duSendE2NodeConfigurationUpdate
6056 * Functionality: DU Send E2 Node Configuration Update
6058 * @return ROK - success
6061 * ****************************************************************/
6063 uint8_t duSendE2NodeConfigurationUpdate()
6065 E2NodeConfigList e2NodeList;
6066 CmLList *node =NULL;
6067 E2NodeComponent *e2NodeComponentInfo=NULL;
6069 memset(&e2NodeList, 0, sizeof(E2NodeConfigList));
6070 CM_LLIST_FIRST_NODE(&duCb.e2apDb.e2NodeComponentList, node);
6073 e2NodeComponentInfo = (E2NodeComponent*)node->node;
6075 if(e2NodeComponentInfo->addConfiguration)
6077 e2NodeList.addE2Node[e2NodeList.addE2NodeCount].interface = e2NodeComponentInfo->interfaceType;
6078 e2NodeList.addE2Node[e2NodeList.addE2NodeCount].componentId= e2NodeComponentInfo->componentId;
6079 e2NodeList.addE2NodeCount++;
6082 if(e2NodeComponentInfo->updateConfiguration)
6084 e2NodeList.updateE2Node[e2NodeList.updateE2NodeCount].interface = e2NodeComponentInfo->interfaceType;
6085 e2NodeList.updateE2Node[e2NodeList.updateE2NodeCount].componentId= e2NodeComponentInfo->componentId;
6086 e2NodeList.updateE2NodeCount++;
6089 if(e2NodeComponentInfo->deleteConfiguration == true)
6091 e2NodeList.removeE2Node[e2NodeList.removeE2NodeCount].interface = e2NodeComponentInfo->interfaceType;
6092 e2NodeList.removeE2Node[e2NodeList.removeE2NodeCount].componentId = e2NodeComponentInfo->componentId;
6093 e2NodeList.removeE2NodeCount++;
6099 if(BuildAndSendE2NodeConfigUpdate(&e2NodeList) !=ROK)
6101 DU_LOG("\nERROR --> E2AP : Failed to build and send e2 node config update message to RIC_stub");
6107 /*******************************************************************
6109 * @brief Free RIC Subscription Modification Required
6113 * Function : FreeRicSubsModRequired
6115 * Functionality: Freqq RIC Subscription Modification required
6117 * @param E2AP Message PDU to be freed
6120 ******************************************************************/
6121 void FreeRicSubsModRequired(E2AP_PDU_t *e2apMsg)
6123 uint8_t ieIdx = 0, arrIdx = 0;
6124 RICsubscriptionModificationRequired_t *ricSubsModReqd = NULLP;
6125 RICsubscriptionModificationRequired_IEs_t *ricSubsModReqdIe = NULLP;
6126 RICactions_RequiredToBeModified_List_t *actionToBeModList = NULLP;
6127 RICactions_RequiredToBeRemoved_List_t *actionToBeRmvList = NULLP;
6131 if(e2apMsg->choice.initiatingMessage)
6133 ricSubsModReqd = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionModificationRequired;
6134 if(ricSubsModReqd->protocolIEs.list.array)
6136 for(ieIdx = 0; ieIdx < ricSubsModReqd->protocolIEs.list.count; ieIdx++)
6138 if(ricSubsModReqd->protocolIEs.list.array[ieIdx])
6140 ricSubsModReqdIe = ricSubsModReqd->protocolIEs.list.array[ieIdx];
6141 switch(ricSubsModReqdIe->id)
6143 case ProtocolIE_IDE2_id_RICactionsRequiredToBeModified_List:
6145 actionToBeModList = &ricSubsModReqdIe->value.choice.RICactions_RequiredToBeModified_List;
6146 if(actionToBeModList->list.array)
6148 for(arrIdx = 0; arrIdx < actionToBeModList->list.count; arrIdx++)
6150 DU_FREE(actionToBeModList->list.array[arrIdx], \
6151 sizeof(RICaction_RequiredToBeModified_ItemIEs_t));
6153 DU_FREE(actionToBeModList->list.array, actionToBeModList->list.size);
6158 case ProtocolIE_IDE2_id_RICactionsRequiredToBeRemoved_List:
6160 actionToBeRmvList = &ricSubsModReqdIe->value.choice.RICactions_RequiredToBeRemoved_List;
6161 if(actionToBeRmvList->list.array)
6163 for(arrIdx = 0; arrIdx < actionToBeRmvList->list.count; arrIdx++)
6165 DU_FREE(actionToBeRmvList->list.array[arrIdx], \
6166 sizeof(RICaction_RequiredToBeRemoved_ItemIEs_t));
6168 DU_FREE(actionToBeRmvList->list.array, actionToBeRmvList->list.size);
6176 DU_FREE(ricSubsModReqd->protocolIEs.list.array[ieIdx], \
6177 sizeof(RICsubscriptionModificationRequired_IEs_t));
6180 DU_FREE(ricSubsModReqd->protocolIEs.list.array, ricSubsModReqd->protocolIEs.list.size);
6182 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
6184 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
6188 /* A RIC Subscription includes RIC subsequent action only for RIC Insert service.
6189 * However, E2SM-KPM supports only RIC Report service.
6190 * Hence there is no subsequent action in RIC subscription that may require modification.
6191 * So commenting the action-modification IEs for the time being
6194 /*******************************************************************
6196 * @brief Fill Action required to be modified list
6200 * Function : FillActionReqdToBeModList
6202 * Functionality: Fill Action required to be modified list
6204 * @param RIC Actions Required To Be Modified List to be filled
6205 * Number of actions to be modified
6206 * RIC Subscription DB
6207 * @return ROK - success
6210 ******************************************************************/
6211 uint8_t FillActionReqdToBeModList(RICactions_RequiredToBeModified_List_t *actionToBeModList, uint8_t numActionsMod, \
6212 RicSubscription *ricSubscription)
6214 uint8_t arrIdx = 0, actionIdx = 0;
6215 RICaction_RequiredToBeModified_ItemIEs_t *actionToBeMod = NULL;
6217 actionToBeModList->list.count = numActionsMod;
6218 actionToBeModList->list.size = numActionsMod * sizeof(RICaction_RequiredToBeModified_ItemIEs_t *);
6219 DU_ALLOC(actionToBeModList->list.array, actionToBeModList->list.size);
6220 if(!actionToBeModList->list.array)
6222 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
6227 for(actionIdx = 0; actionIdx < MAX_RIC_ACTION; actionIdx++)
6229 if(ricSubscription->actionSequence[actionIdx].action == CONFIG_MOD)
6231 DU_ALLOC(actionToBeModList->list.array[arrIdx], sizeof(RICaction_RequiredToBeModified_ItemIEs_t));
6232 if(!actionToBeModList->list.array[arrIdx])
6234 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
6237 actionToBeMod = (RICaction_RequiredToBeModified_ItemIEs_t *)actionToBeModList->list.array[arrIdx];
6239 actionToBeMod->id = ProtocolIE_IDE2_id_RICaction_RequiredToBeModified_Item;
6240 actionToBeMod->criticality = CriticalityE2_reject;
6241 actionToBeMod->value.present = \
6242 RICaction_RequiredToBeModified_ItemIEs__value_PR_RICaction_RequiredToBeModified_Item;
6243 actionToBeMod->value.choice.RICaction_RequiredToBeModified_Item.ricActionID = \
6244 ricSubscription->actionSequence[actionIdx].actionId;
6245 actionToBeMod->value.choice.RICaction_RequiredToBeModified_Item.ricTimeToWait = RICtimeToWait_w5ms;
6255 /*******************************************************************
6257 * @brief Fill Action required to be removed list
6261 * Function : FillActionReqdToBeRmvList
6263 * Functionality: Fill Action required to be removed list
6265 * @param RIC Actions Required To Be Removed List to be filled
6266 * Number of actions to be removed
6267 * RIC Subscription DB
6268 * @return ROK - success
6271 ******************************************************************/
6272 uint8_t FillActionReqdToBeRmvList(RICactions_RequiredToBeRemoved_List_t *actionToBeRmvList, uint8_t numActionsRmv, \
6273 RicSubscription *ricSubscription)
6275 uint8_t arrIdx = 0, actionIdx = 0;
6276 RICaction_RequiredToBeRemoved_ItemIEs_t *actionToBeRmv = NULL;
6278 actionToBeRmvList->list.count = numActionsRmv;
6279 actionToBeRmvList->list.size = numActionsRmv * sizeof(RICaction_RequiredToBeRemoved_ItemIEs_t *);
6280 DU_ALLOC(actionToBeRmvList->list.array, actionToBeRmvList->list.size);
6281 if(!actionToBeRmvList->list.array)
6283 DU_LOG("\nERROR --> E2AP : %s: Memory allocation failed at line %d", __func__, __LINE__);
6288 for(actionIdx = 0; actionIdx < MAX_RIC_ACTION; actionIdx++)
6290 if(ricSubscription->actionSequence[actionIdx].action == CONFIG_DEL)
6292 DU_ALLOC(actionToBeRmvList->list.array[arrIdx], sizeof(RICaction_RequiredToBeRemoved_ItemIEs_t));
6293 if(!actionToBeRmvList->list.array[arrIdx])
6295 DU_LOG("\nERROR --> E2AP : %s: Memory allocation failed at line %d", __func__, __LINE__);
6298 actionToBeRmv = (RICaction_RequiredToBeRemoved_ItemIEs_t *)actionToBeRmvList->list.array[arrIdx];
6300 actionToBeRmv->id = ProtocolIE_IDE2_id_RICaction_RequiredToBeRemoved_Item;
6301 actionToBeRmv->criticality = CriticalityE2_reject;
6302 actionToBeRmv->value.present = \
6303 RICaction_RequiredToBeRemoved_ItemIEs__value_PR_RICaction_RequiredToBeRemoved_Item;
6304 actionToBeRmv->value.choice.RICaction_RequiredToBeRemoved_Item.ricActionID = \
6305 ricSubscription->actionSequence[actionIdx].actionId;
6306 fillE2Cause(&actionToBeRmv->value.choice.RICaction_RequiredToBeRemoved_Item.cause, \
6307 ricSubscription->actionSequence[actionIdx].failureCause);
6316 /*******************************************************************
6318 * @brief Fill RIC Subscription Modification Required IEs
6322 * Function : FillRicSubsModRequired
6324 * Functionality: Fill RIC Subscription Modification Required IEs
6326 * @param RIC Subscription Modification Required IEs to be filled
6327 * RIC Subscription DB
6328 * @return ROK - success
6331 ******************************************************************/
6332 uint8_t FillRicSubsModRequired(RICsubscriptionModificationRequired_t *ricSubsModReqd, RicSubscription *ricSubscription)
6334 uint8_t ieIdx = 0, elementCnt=0, actionIdx = 0;
6335 uint8_t numActionsMod = 0, numActionsRmv = 0;
6336 RICsubscriptionModificationRequired_IEs_t *ricSubsModReqdIe = NULLP;
6337 RICactions_RequiredToBeRemoved_List_t *actionToBeRmvList = NULLP;
6339 /* Unused in case of E2SM-KPM */
6341 RICactions_RequiredToBeModified_List_t *actionToBeModList = NULLP;
6344 /* Count number of Actions to be modified or deleted */
6345 for(actionIdx = 0; actionIdx < MAX_RIC_ACTION; actionIdx++)
6347 if(ricSubscription->actionSequence[actionIdx].action == CONFIG_MOD)
6349 else if(ricSubscription->actionSequence[actionIdx].action == CONFIG_DEL)
6353 /* Count number of IEs to be added to messages */
6360 ricSubsModReqd->protocolIEs.list.count = elementCnt;
6361 ricSubsModReqd->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionModificationRequired_IEs_t *);
6362 DU_ALLOC(ricSubsModReqd->protocolIEs.list.array, ricSubsModReqd->protocolIEs.list.size);
6363 if(!ricSubsModReqd->protocolIEs.list.array)
6365 DU_LOG("\nERROR --> E2AP : %s: Memory allocation failed at line %d", __func__, __LINE__);
6369 for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
6371 DU_ALLOC(ricSubsModReqd->protocolIEs.list.array[ieIdx], sizeof(RICsubscriptionModificationRequired_IEs_t));
6372 if(!ricSubsModReqd->protocolIEs.list.array[ieIdx])
6374 DU_LOG("\nERROR --> E2AP : %s: Memory allocation failed at line %d", __func__, __LINE__);
6379 /* RIC Request ID */
6381 ricSubsModReqdIe = ricSubsModReqd->protocolIEs.list.array[ieIdx];
6382 ricSubsModReqdIe->id = ProtocolIE_IDE2_id_RICrequestID;
6383 ricSubsModReqdIe->criticality = CriticalityE2_reject;
6384 ricSubsModReqdIe->value.present = RICsubscriptionModificationRequired_IEs__value_PR_RICrequestID;
6385 ricSubsModReqdIe->value.choice.RICrequestID.ricRequestorID = ricSubscription->requestId.requestorId;
6386 ricSubsModReqdIe->value.choice.RICrequestID.ricInstanceID = ricSubscription->requestId.instanceId;
6388 /* RAN Function ID */
6390 ricSubsModReqdIe = ricSubsModReqd->protocolIEs.list.array[ieIdx];
6391 ricSubsModReqdIe->id = ProtocolIE_IDE2_id_RANfunctionID;
6392 ricSubsModReqdIe->criticality = CriticalityE2_reject;
6393 ricSubsModReqdIe->value.present = RICsubscriptionModificationRequired_IEs__value_PR_RANfunctionID;
6394 ricSubsModReqdIe->value.choice.RANfunctionID = ricSubscription->ranFuncId;
6396 /* A RIC Subscription includes RIC subsequent action only for RIC Insert service.
6397 * However, E2SM-KPM supports only RIC Report service.
6398 * Hence there is no subsequent action in RIC subscription that may require modification.
6399 * So commenting the action-modification IEs for the time being
6402 /* RIC Actions Required to be Modified */
6406 ricSubsModReqdIe = ricSubsModReqd->protocolIEs.list.array[ieIdx];
6407 ricSubsModReqdIe->id = ProtocolIE_IDE2_id_RICactionsRequiredToBeModified_List;
6408 ricSubsModReqdIe->criticality = CriticalityE2_reject;
6409 ricSubsModReqdIe->value.present = \
6410 RICsubscriptionModificationRequired_IEs__value_PR_RICactions_RequiredToBeModified_List;
6411 actionToBeModList = &ricSubsModReqdIe->value.choice.RICactions_RequiredToBeModified_List;
6413 if(FillActionReqdToBeModList(actionToBeModList, numActionsMod, ricSubscription) != ROK)
6415 DU_LOG("\nERROR --> E2AP : %s: Failed to fill actions required to be modified list", __func__);
6421 /* RIC Actions Required to be removed */
6425 ricSubsModReqdIe = ricSubsModReqd->protocolIEs.list.array[ieIdx];
6426 ricSubsModReqdIe->id = ProtocolIE_IDE2_id_RICactionsRequiredToBeRemoved_List;
6427 ricSubsModReqdIe->criticality = CriticalityE2_reject;
6428 ricSubsModReqdIe->value.present = \
6429 RICsubscriptionModificationRequired_IEs__value_PR_RICactions_RequiredToBeRemoved_List;
6430 actionToBeRmvList = &ricSubsModReqdIe->value.choice.RICactions_RequiredToBeRemoved_List;
6432 if(FillActionReqdToBeRmvList(actionToBeRmvList, numActionsRmv, ricSubscription) != ROK)
6434 DU_LOG("\nERROR --> E2AP : %s: Failed to fill actions required to be removed list", __func__);
6442 /*******************************************************************
6444 * @brief Builds and Send RIC Subscription Modification Required
6449 * Function : BuildAndSendRicSubsModRequired
6451 * Functionality: Builds and Send RIC Subscription Modification
6454 * @param RIC Subscription DB
6455 * @return ROK - success
6458 ******************************************************************/
6459 uint8_t BuildAndSendRicSubsModRequired(RicSubscription *ricSubscription)
6461 uint8_t ret = RFAILED;
6462 E2AP_PDU_t *e2apMsg = NULLP;
6463 RICsubscriptionModificationRequired_t *ricSubsModReqd = NULLP;
6464 asn_enc_rval_t encRetVal; /* Encoder return value */
6466 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Modification Required \n");
6469 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
6470 if(e2apMsg == NULLP)
6472 DU_LOG("\nERROR --> E2AP : %s: Memory allocation failed at line %d", __func__, __LINE__);
6476 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
6477 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
6478 if(e2apMsg->choice.initiatingMessage == NULLP)
6480 DU_LOG("\nERROR --> E2AP : %s: Memory allocation failed at line %d", __func__, __LINE__);
6483 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
6484 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICsubscriptionModificationRequired;
6485 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICsubscriptionModificationRequired;
6487 ricSubsModReqd = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionModificationRequired;
6489 if(FillRicSubsModRequired(ricSubsModReqd, ricSubscription) != ROK)
6491 DU_LOG("\nERROR --> E2AP : %s: Failed to fill RIC Subscription Modification Required IEs", __func__);
6496 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
6498 memset(encBuf, 0, ENC_BUF_MAX_LEN);
6500 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
6501 if(encRetVal.encoded == ENCODE_FAIL)
6503 DU_LOG("\nERROR --> E2AP : Could not encode RIC Subscription Modifiction Required structure (at %s)\n",\
6504 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
6509 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC Subscription Modification Required \n");
6510 #ifdef DEBUG_ASN_PRINT
6511 for(int i=0; i< encBufSize; i++)
6513 printf("%x",encBuf[i]);
6517 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
6519 DU_LOG("\nERROR --> E2AP : Sending RIC Subscription Modification Required failed");
6526 /* Free RIC Subscription modification required */
6527 FreeRicSubsModRequired(e2apMsg);
6531 /*******************************************************************
6533 * @brief Free APER decoding of RIC Subscription Modification Confirm
6537 * Function : freeAperDecodingOfRicSubsModConfirm
6539 * Functionality: Free APER decoding of RIC Subscription
6540 * Modification Confirm
6542 * @param E2AP Message PDU
6545 ******************************************************************/
6546 void freeAperDecodingOfRicSubsModConfirm(E2AP_PDU_t *e2apMsg)
6548 uint8_t ieIdx = 0, arrIdx=0;
6549 RICsubscriptionModificationConfirm_t *ricSubsModCfm = NULLP;
6550 RICsubscriptionModificationConfirm_IEs_t *ricSubsModCfmIe = NULLP;
6551 RICactions_ConfirmedForModification_List_t *modCfmList = NULLP;
6552 RICactions_RefusedToBeModified_List_t *modRefusedList = NULLP;
6553 RICactions_ConfirmedForRemoval_List_t *rmvCfmList = NULLP;
6554 RICactions_RefusedToBeRemoved_List_t *rmvFailList = NULLP;
6556 if(e2apMsg && e2apMsg->choice.successfulOutcome)
6558 ricSubsModCfm = &e2apMsg->choice.successfulOutcome->value.choice.RICsubscriptionModificationConfirm;
6559 if(ricSubsModCfm->protocolIEs.list.array)
6561 for(ieIdx = 0; ieIdx < ricSubsModCfm->protocolIEs.list.count; ieIdx++)
6563 if(ricSubsModCfm->protocolIEs.list.array[ieIdx])
6565 ricSubsModCfmIe = ricSubsModCfm->protocolIEs.list.array[ieIdx];
6566 switch(ricSubsModCfmIe->id)
6568 case ProtocolIE_IDE2_id_RICactionsConfirmedForModification_List:
6570 modCfmList = &ricSubsModCfmIe->value.choice.RICactions_ConfirmedForModification_List;
6571 if(modCfmList->list.array)
6573 for(arrIdx = 0; arrIdx < modCfmList->list.count; arrIdx++)
6575 if(modCfmList->list.array[arrIdx])
6576 free(modCfmList->list.array[arrIdx]);
6578 free(modCfmList->list.array);
6583 case ProtocolIE_IDE2_id_RICactionsRefusedToBeModified_List:
6585 modRefusedList = &ricSubsModCfmIe->value.choice.RICactions_RefusedToBeModified_List;
6586 if(modRefusedList->list.array)
6588 for(arrIdx = 0; arrIdx < modRefusedList->list.count; arrIdx++)
6590 if(modRefusedList->list.array[arrIdx])
6591 free(modRefusedList->list.array[arrIdx]);
6593 free(modRefusedList->list.array);
6598 case ProtocolIE_IDE2_id_RICactionsConfirmedForRemoval_List:
6600 rmvCfmList = &ricSubsModCfmIe->value.choice.RICactions_ConfirmedForRemoval_List;
6601 if(rmvCfmList->list.array)
6603 for(arrIdx = 0; arrIdx < rmvCfmList->list.count; arrIdx++)
6605 if(rmvCfmList->list.array[arrIdx])
6606 free(rmvCfmList->list.array[arrIdx]);
6608 free(rmvCfmList->list.array);
6613 case ProtocolIE_IDE2_id_RICactionsRefusedToBeRemoved_List:
6615 rmvFailList = &ricSubsModCfmIe->value.choice.RICactions_RefusedToBeRemoved_List;
6616 if(rmvFailList->list.array)
6618 for(arrIdx = 0; arrIdx < rmvFailList->list.count; arrIdx++)
6620 if(rmvFailList->list.array[arrIdx])
6621 free(rmvFailList->list.array[arrIdx]);
6623 free(rmvFailList->list.array);
6632 free(ricSubsModCfmIe);
6635 free(ricSubsModCfm->protocolIEs.list.array);
6640 /*******************************************************************
6642 * @brief Process RIC Subscription Modification Confirm Message
6646 * Function : procRicSubscriptionModificationConfirm
6648 * Functionality: Process RIC Subscription Modification Confirm
6649 * Message received from RIC.
6651 * @param E2AP Message PDU
6654 ******************************************************************/
6655 void procRicSubscriptionModificationConfirm(E2AP_PDU_t *e2apMsg)
6657 uint8_t actionId = 0, ieIdx = 0, arrIdx = 0;
6658 uint16_t ranFuncId = 0;
6659 bool procFailure = false;
6660 RicRequestId ricReqId;
6661 RanFunction *ranFuncDb = NULLP;
6662 CmLList *ricSubsNode = NULLP;
6663 RicSubscription *ricSubsDb = NULLP;
6664 ActionInfo *actionDb = NULLP;
6666 RICsubscriptionModificationConfirm_t *ricSubsModCfm = NULLP;
6667 RICsubscriptionModificationConfirm_IEs_t *ricSubsModCfmIe = NULLP;
6669 /* Not used in case of E2SM-KPM */
6671 RICactions_ConfirmedForModification_List_t *modCfmList = NULLP;
6672 RICaction_ConfirmedForModification_ItemIEs_t *modCfmListItem = NULLP;
6674 RICactions_RefusedToBeModified_List_t *modRefusedList = NULLP;
6675 RICaction_RefusedToBeModified_ItemIEs_t *modRefusedListItem = NULLP;
6678 RICactions_ConfirmedForRemoval_List_t *rmvCfmList = NULLP;
6679 RICaction_ConfirmedForRemoval_ItemIEs_t *rmvCfmListItem = NULLP;
6681 RICactions_RefusedToBeRemoved_List_t *rmvFailList = NULLP;
6682 RICaction_RefusedToBeRemoved_ItemIEs_t *rmvFailListItem = NULLP;
6684 DU_LOG("\nINFO --> E2AP : %s: Received RIC Subscription Modification Confirm", __func__);
6689 DU_LOG("\nERROR --> E2AP : %s: E2AP Message is NULL", __func__);
6693 if(!e2apMsg->choice.successfulOutcome)
6695 DU_LOG("\nERROR --> E2AP : %s: Successful Outcome in E2AP message is NULL", __func__);
6699 ricSubsModCfm = &e2apMsg->choice.successfulOutcome->value.choice.RICsubscriptionModificationConfirm;
6700 if(!ricSubsModCfm->protocolIEs.list.array)
6702 DU_LOG("\nERROR --> E2AP : %s: Array conatining E2AP message IEs is null", __func__);
6706 for(ieIdx = 0; ieIdx < ricSubsModCfm->protocolIEs.list.count; ieIdx++)
6708 if(!ricSubsModCfm->protocolIEs.list.array[ieIdx])
6710 DU_LOG("\nERROR --> E2AP : %s: IE at index [%d] in E2AP message IEs list is null", __func__, ieIdx);
6714 ricSubsModCfmIe = ricSubsModCfm->protocolIEs.list.array[ieIdx];
6715 switch(ricSubsModCfmIe->id)
6717 case ProtocolIE_IDE2_id_RICrequestID:
6719 memset(&ricReqId, 0, sizeof(RicRequestId));
6720 ricReqId.requestorId = ricSubsModCfmIe->value.choice.RICrequestID.ricRequestorID;
6721 ricReqId.instanceId = ricSubsModCfmIe->value.choice.RICrequestID.ricInstanceID;
6725 case ProtocolIE_IDE2_id_RANfunctionID:
6727 ranFuncId = ricSubsModCfmIe->value.choice.RANfunctionID;
6728 ranFuncDb = fetchRanFuncFromRanFuncId(ranFuncId);
6731 DU_LOG("\nERROR --> E2AP : %s: RAN Function ID [%d] not found", __func__, ranFuncId);
6736 ricSubsDb = fetchSubsInfoFromRicReqId(ricReqId, ranFuncDb, &ricSubsNode);
6739 DU_LOG("\nERROR --> E2AP : %s: RIC Subscription not found for Requestor_ID [%d] Instance_ID [%d]",\
6740 __func__, ricReqId.requestorId, ricReqId.instanceId);
6748 /* A RIC Subscription includes RIC subsequent action only for RIC Insert service.
6749 * However, E2SM-KPM supports only RIC Report service.
6750 * Hence there is no subsequent action in RIC subscription that may require modification.
6751 * So commenting the action-modification IEs for the time being
6754 case ProtocolIE_IDE2_id_RICactionsConfirmedForModification_List:
6756 modCfmList = &ricSubsModCfmIe->value.choice.RICactions_ConfirmedForModification_List;
6757 for(arrIdx = 0; arrIdx < modCfmList->list.count; arrIdx++)
6759 modCfmListItem = (RICaction_ConfirmedForModification_ItemIEs_t *)modCfmList->list.array[arrIdx];
6760 actionId = modCfmListItem->value.choice.RICaction_ConfirmedForModification_Item.ricActionID;
6762 actionDb = fetchActionInfoFromActionId(actionId, ricSubsDb);
6765 DU_LOG("\nERROR --> E2AP : %s: Action ID [%d] not found", __func__, actionId);
6769 actionDb->action = CONFIG_UNKNOWN;
6770 /* Further handling can be added here in future once the
6771 * use case of this procedure is identified */
6778 case ProtocolIE_IDE2_id_RICactionsRefusedToBeModified_List:
6780 modRefusedList = &ricSubsModCfmIe->value.choice.RICactions_RefusedToBeModified_List;
6781 for(arrIdx = 0; arrIdx < modRefusedList->list.count; arrIdx++)
6783 modRefusedListItem = (RICaction_RefusedToBeModified_ItemIEs_t *)modRefusedList->list.array[arrIdx];
6784 actionId = modRefusedListItem->value.choice.RICaction_RefusedToBeModified_Item.ricActionID;
6785 actionDb = fetchActionInfoFromActionId(actionId, ricSubsDb);
6788 DU_LOG("\nERROR --> E2AP : %s: Action ID [%d] not found", __func__, actionId);
6792 /* Spec doesnt mention if in case of failure, DU should retry for modify action
6793 * Hence, chaging the action from CONFIG_MOD to CONFIG_UNKNOWN
6795 actionDb->action = CONFIG_UNKNOWN;
6803 case ProtocolIE_IDE2_id_RICactionsConfirmedForRemoval_List:
6805 rmvCfmList = &ricSubsModCfmIe->value.choice.RICactions_ConfirmedForRemoval_List;
6806 for(arrIdx = 0; arrIdx < rmvCfmList->list.count; arrIdx++)
6808 rmvCfmListItem = (RICaction_ConfirmedForRemoval_ItemIEs_t *)rmvCfmList->list.array[arrIdx];
6809 actionId = rmvCfmListItem->value.choice.RICaction_ConfirmedForRemoval_Item.ricActionID;
6810 actionDb = fetchActionInfoFromActionId(actionId, ricSubsDb);
6813 DU_LOG("\nERROR --> E2AP : %s: Action ID [%d] not found", __func__, actionId);
6817 deleteActionSequence(actionDb);
6819 ricSubsDb->numOfActions--;
6820 /* Further handling can include :
6821 * Deletion of this action from all DU layers
6829 case ProtocolIE_IDE2_id_RICactionsRefusedToBeRemoved_List:
6831 rmvFailList = &ricSubsModCfmIe->value.choice.RICactions_RefusedToBeRemoved_List;
6832 for(arrIdx = 0; arrIdx < rmvFailList->list.count; arrIdx++)
6834 rmvFailListItem = (RICaction_RefusedToBeRemoved_ItemIEs_t *)rmvFailList->list.array[arrIdx];
6835 actionId = rmvFailListItem->value.choice.RICaction_RefusedToBeRemoved_Item.ricActionID;
6836 actionDb = fetchActionInfoFromActionId(actionId, ricSubsDb);
6839 DU_LOG("\nERROR --> E2AP : %s: Action ID [%d] not found", __func__, actionId);
6843 actionDb->action = CONFIG_UNKNOWN;
6852 } /* End of switch for Protocol IE Id */
6856 } /* End of for loop for Protocol IE list */
6861 freeAperDecodingOfRicSubsModConfirm(e2apMsg);
6865 /******************************************************************
6866 * @brief Deallocate the memory allocated for E2 Reset Response
6870 * Function : FreeE2ResetResponse
6873 * - freeing the memory allocated for E2ResetResponse
6875 * @params[in] E2AP_PDU_t *e2apMsg
6876 * @return ROK - success
6879 * ****************************************************************/
6880 void FreeE2ResetResponse(E2AP_PDU_t *e2apMsg)
6883 ResetResponseE2_t *resetResponse;
6885 if(e2apMsg != NULLP)
6887 if(e2apMsg->choice.successfulOutcome != NULLP)
6889 resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2;
6890 if(resetResponse->protocolIEs.list.array)
6892 for(ieIdx=0; ieIdx < resetResponse->protocolIEs.list.count; ieIdx++)
6894 if(resetResponse->protocolIEs.list.array[ieIdx])
6896 DU_FREE(resetResponse->protocolIEs.list.array[ieIdx], sizeof(ResetResponseIEs_t));
6899 DU_FREE(resetResponse->protocolIEs.list.array, resetResponse->protocolIEs.list.size);
6902 DU_FREE(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
6904 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
6908 /*******************************************************************
6910 * @brief Buld and send the E2 Reset Response msg
6914 * Function : BuildAndSendE2ResetResponse
6917 * - Buld and send the E2 Reset Response Message
6919 * @params[in] Trans Id
6920 * @return ROK - success
6923 * ****************************************************************/
6924 uint8_t BuildAndSendResetResponse(uint8_t transId)
6926 uint8_t ieIdx = 0, elementCnt = 0;
6927 uint8_t ret = RFAILED;
6928 E2AP_PDU_t *e2apMsg = NULLP;
6929 ResetResponseE2_t *resetResponse;
6930 asn_enc_rval_t encRetVal; /* Encoder return value */
6932 DU_LOG("\nINFO --> E2AP : Building E2 Reset Response Message\n");
6935 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
6936 if(e2apMsg == NULLP)
6938 DU_LOG("\nERROR --> E2AP : BuildAndSendResetResponse(): Memory allocation for E2AP-PDU failed");
6941 e2apMsg->present = E2AP_PDU_PR_successfulOutcome;
6943 DU_ALLOC(e2apMsg->choice.successfulOutcome, sizeof(SuccessfulOutcomeE2_t));
6944 if(e2apMsg->choice.successfulOutcome == NULLP)
6946 DU_LOG("\nERROR --> E2AP : BuildAndSendResetResponse: Memory allocation failed for successfulOutcome");
6950 e2apMsg->choice.successfulOutcome->procedureCode = ProcedureCodeE2_id_Reset;
6951 e2apMsg->choice.successfulOutcome->criticality = CriticalityE2_reject;
6952 e2apMsg->choice.successfulOutcome->value.present = SuccessfulOutcomeE2__value_PR_ResetResponseE2;
6953 resetResponse = &e2apMsg->choice.successfulOutcome->value.choice.ResetResponseE2;
6956 resetResponse->protocolIEs.list.count = elementCnt;
6957 resetResponse->protocolIEs.list.size = elementCnt * sizeof(ResetResponseIEs_t *);
6958 DU_ALLOC(resetResponse->protocolIEs.list.array, resetResponse->protocolIEs.list.size);
6959 if(!resetResponse->protocolIEs.list.array)
6961 DU_LOG("\nERROR --> E2AP : BuildAndSendResetResponse: Memory allocation failed for protocol IE array");
6965 for(ieIdx=0; ieIdx < elementCnt; ieIdx++)
6967 DU_ALLOC(resetResponse->protocolIEs.list.array[ieIdx], sizeof(ResetResponseIEs_t));
6968 if(!resetResponse->protocolIEs.list.array[ieIdx])
6970 DU_LOG("\nERROR --> E2AP : BuildAndSendResetResponse: Memory allocation failed for protocol IE array element");
6974 if(ieIdx < elementCnt)
6978 resetResponse->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
6979 resetResponse->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
6980 resetResponse->protocolIEs.list.array[ieIdx]->value.present = ResetResponseIEs__value_PR_TransactionID;
6981 resetResponse->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
6983 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
6985 memset(encBuf, 0, ENC_BUF_MAX_LEN);
6987 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
6988 if(encRetVal.encoded == ENCODE_FAIL)
6990 DU_LOG("\nERROR --> E2AP : Could not encode E2 reset response structure (at %s)\n",\
6991 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
6996 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Reset Response \n");
6997 for(int i=0; i< encBufSize; i++)
6999 DU_LOG("%x",encBuf[i]);
7004 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
7006 DU_LOG("\nERROR --> E2AP : Failed to send E2 Reset Response");
7014 FreeE2ResetResponse(e2apMsg);
7018 /******************************************************************
7020 * @brief Deallocation of memory allocated by aper decoder for reset req
7024 * Function : freeAperDecodingOfE2ResetReq
7026 * Functionality: Deallocation of memory allocated by aper decoder for
7029 * @params[in] Pointer to resetReq
7032 * ****************************************************************/
7033 void freeAperDecodingOfE2ResetReq(ResetRequestE2_t *resetReq)
7039 if(resetReq->protocolIEs.list.array)
7041 for(arrIdx=0; arrIdx<resetReq->protocolIEs.list.count; arrIdx++)
7043 if(resetReq->protocolIEs.list.array[arrIdx])
7045 free(resetReq->protocolIEs.list.array[arrIdx]);
7048 free(resetReq->protocolIEs.list.array);
7053 /*******************************************************************
7055 * @brief Process reset req received from RIC
7059 * Function : procE2ResetRequest
7061 * Functionality: Process reset req received from RIC
7063 * @param E2AP_PDU_t *e2apMsg
7066 ******************************************************************/
7068 void procE2ResetRequest(E2AP_PDU_t *e2apMsg)
7070 uint16_t ranFuncIdx=0;
7071 uint8_t arrIdx =0, transId =0;
7072 ResetRequestE2_t *resetReq;
7074 DU_LOG("\nINFO --> E2AP : E2 Reset request received");
7075 resetReq = &e2apMsg->choice.initiatingMessage->value.choice.ResetRequestE2;
7077 for(arrIdx=0; arrIdx<resetReq->protocolIEs.list.count; arrIdx++)
7079 switch(resetReq->protocolIEs.list.array[arrIdx]->id)
7081 case ProtocolIE_IDE2_id_TransactionID:
7083 transId = resetReq->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
7087 case ProtocolIE_IDE2_id_CauseE2:
7089 for(ranFuncIdx=0; ranFuncIdx<MAX_RAN_FUNCTION; ranFuncIdx++)
7091 if(duCb.e2apDb.ranFunction[ranFuncIdx].id >0)
7093 deleteRicSubscriptionList(&(duCb.e2apDb.ranFunction[ranFuncIdx].subscriptionList));
7094 memset(&(duCb.e2apDb.ranFunction[ranFuncIdx].pendingSubsRspInfo), 0, MAX_PENDING_SUBSCRIPTION_RSP*sizeof(PendingSubsRspInfo));
7101 if(BuildAndSendResetResponse(transId) != ROK)
7103 DU_LOG("\nERROR --> E2AP : Failed to build and send reset response");
7105 freeAperDecodingOfE2ResetReq(resetReq);
7108 /*******************************************************************
7110 * @brief Free APER decoding of RIC Subscription Modification Refuse
7114 * Function : freeAperDecodingOfRicSubsModRefuse
7116 * Functionality: Free APER decoding of RIC Subscription
7117 * Modification Refuse
7119 * @param E2AP Message PDU
7122 ******************************************************************/
7123 void freeAperDecodingOfRicSubsModRefuse(E2AP_PDU_t *e2apMsg)
7126 RICsubscriptionModificationRefuse_t *ricSubsModRefuse = NULLP;
7128 if(e2apMsg && e2apMsg->choice.unsuccessfulOutcome)
7130 ricSubsModRefuse = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICsubscriptionModificationRefuse;
7131 if(ricSubsModRefuse->protocolIEs.list.array)
7133 for(ieIdx = 0; ieIdx < ricSubsModRefuse->protocolIEs.list.count; ieIdx++)
7135 if(ricSubsModRefuse->protocolIEs.list.array[ieIdx])
7136 free(ricSubsModRefuse->protocolIEs.list.array[ieIdx]);
7138 free(ricSubsModRefuse->protocolIEs.list.array);
7143 /*******************************************************************
7145 * @brief Process RIC Subscription Modification Refuse Message
7149 * Function : procRicSubscriptionModificationRefuse
7151 * Functionality: Process RIC Subscription Modification Refuse
7152 * Message received from RIC.
7154 * @param E2AP Message PDU
7157 ******************************************************************/
7158 void procRicSubscriptionModificationRefuse(E2AP_PDU_t *e2apMsg)
7161 uint16_t ranFuncId = 0;
7162 RicRequestId ricReqId;
7163 RICsubscriptionModificationRefuse_t *ricSubsModRefuse = NULLP;
7164 RICsubscriptionModificationRefuse_IEs_t *ricSubsModRefuseIe = NULLP;
7165 CauseE2_t *cause = NULLP;
7167 DU_LOG("\nINFO --> E2AP : %s: Received RIC Subscription Modification Refuse", __func__);
7172 DU_LOG("\nERROR --> E2AP : %s: E2AP Message is NULL", __func__);
7176 if(!e2apMsg->choice.unsuccessfulOutcome)
7178 DU_LOG("\nERROR --> E2AP : %s: Unsuccessful Outcome in E2AP message is NULL", __func__);
7182 ricSubsModRefuse = &e2apMsg->choice.unsuccessfulOutcome->value.choice.RICsubscriptionModificationRefuse;
7183 if(!ricSubsModRefuse->protocolIEs.list.array)
7185 DU_LOG("\nERROR --> E2AP : %s: Array conatining E2AP message IEs is null", __func__);
7189 for(ieIdx = 0; ieIdx < ricSubsModRefuse->protocolIEs.list.count; ieIdx++)
7191 if(!ricSubsModRefuse->protocolIEs.list.array[ieIdx])
7193 DU_LOG("\nERROR --> E2AP : %s: IE at index [%d] in E2AP message IEs list is null", __func__, ieIdx);
7197 ricSubsModRefuseIe = ricSubsModRefuse->protocolIEs.list.array[ieIdx];
7198 switch(ricSubsModRefuseIe->id)
7200 case ProtocolIE_IDE2_id_RICrequestID:
7202 memset(&ricReqId, 0, sizeof(RicRequestId));
7203 ricReqId.requestorId = ricSubsModRefuseIe->value.choice.RICrequestID.ricRequestorID;
7204 ricReqId.instanceId = ricSubsModRefuseIe->value.choice.RICrequestID.ricInstanceID;
7208 case ProtocolIE_IDE2_id_RANfunctionID:
7210 ranFuncId = ricSubsModRefuseIe->value.choice.RANfunctionID;
7214 case ProtocolIE_IDE2_id_CauseE2:
7216 DU_LOG("\nDEBUG --> E2AP : %s: RIC subscriptiom modification refused for RIC_Requestor_ID [%d] \
7217 RIC_Instance_ID [%d] RAN_Function_ID [%d] ", __func__, ricReqId.requestorId, \
7218 ricReqId.instanceId, ranFuncId);
7220 cause = &ricSubsModRefuseIe->value.choice.CauseE2;
7221 printE2ErrorCause(cause);
7226 } /* End of switch for Protocol IE Id */
7227 } /* End of for loop for Protocol IE list */
7232 freeAperDecodingOfRicSubsModRefuse(e2apMsg);
7236 /*******************************************************************
7238 * @brief Free RIC Subscription Delete Required Message
7242 * Function : FreeRicSubscriptionDeleteRequired
7244 * Functionality: Free RIC Subscription Delete Required
7246 * @param E2AP Message PDU
7249 ******************************************************************/
7250 void FreeRicSubscriptionDeleteRequired(E2AP_PDU_t *e2apMsg, CmLListCp *ricSubsToBeDelList)
7252 uint8_t ieIdx = 0, arrIdx = 0;
7253 RICsubscriptionDeleteRequired_t *ricSubsDelRqd = NULLP;
7254 RICsubscriptionDeleteRequired_IEs_t *ricSubsDelRqdIe = NULLP;
7255 RICsubscription_List_withCause_t *ricSubsList = NULLP;
7256 CmLList *subsNode = NULLP;
7260 if(e2apMsg->choice.initiatingMessage)
7262 ricSubsDelRqd = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionDeleteRequired;
7263 if(ricSubsDelRqd->protocolIEs.list.array)
7265 for(ieIdx = 0; ieIdx < ricSubsDelRqd->protocolIEs.list.count; ieIdx++)
7267 if(ricSubsDelRqd->protocolIEs.list.array[ieIdx])
7269 ricSubsDelRqdIe = ricSubsDelRqd->protocolIEs.list.array[ieIdx];
7270 switch(ricSubsDelRqdIe->id)
7272 case ProtocolIE_IDE2_id_RICsubscriptionToBeRemoved:
7274 ricSubsList = &ricSubsDelRqdIe->value.choice.RICsubscription_List_withCause;
7275 if(ricSubsList->list.array)
7277 for(arrIdx = 0; arrIdx < ricSubsList->list.count; arrIdx++)
7279 DU_FREE(ricSubsList->list.array[ieIdx], sizeof(RICsubscription_withCause_ItemIEs_t));
7281 DU_FREE(ricSubsList->list.array, ricSubsList->list.size);
7286 DU_FREE(ricSubsDelRqd->protocolIEs.list.array[ieIdx], sizeof(RICsubscriptionDeleteRequired_IEs_t));
7289 DU_FREE(ricSubsDelRqd->protocolIEs.list.array, ricSubsDelRqd->protocolIEs.list.size);
7291 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
7293 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));;
7296 if(ricSubsToBeDelList)
7298 CM_LLIST_FIRST_NODE(ricSubsToBeDelList, subsNode);
7301 cmLListDelFrm(ricSubsToBeDelList, subsNode);
7302 DU_FREE(subsNode, sizeof(CmLList));
7303 CM_LLIST_FIRST_NODE(ricSubsToBeDelList, subsNode);
7308 /*******************************************************************
7310 * @brief Fill list of RIC subscriptions required to be deleted
7311 * with the cause of deletion
7315 * Function : fillRicSubsListWithCause
7317 * Functionality: Fill list of RIC subscriptions required to be
7318 * deleted with the cause of deletion
7320 * @param E2AP Message PDU
7323 ******************************************************************/
7324 uint8_t fillRicSubsListWithCause(RICsubscription_List_withCause_t *ricSubsList, CmLListCp ricSubsToBeDelList)
7327 CmLList *subsNode = NULLP;
7328 RicSubscription *subsInfo = NULLP;
7329 RICsubscription_withCause_ItemIEs_t *subsItemIe = NULLP;
7330 RICsubscription_withCause_Item_t *subsItem = NULLP;
7332 ricSubsList->list.count = ricSubsToBeDelList.count;
7333 ricSubsList->list.size = ricSubsList->list.count * sizeof(RICsubscription_withCause_ItemIEs_t *);
7334 DU_ALLOC(ricSubsList->list.array, ricSubsList->list.size);
7335 if(!ricSubsList->list.array)
7337 DU_LOG("\nERROR --> E2AP : %s: Memory allocation for E2AP-PDU failed at line %d",__func__, __LINE__);
7341 CM_LLIST_FIRST_NODE(&ricSubsToBeDelList, subsNode);
7342 while(subsNode && (ieIdx < ricSubsList->list.count))
7344 subsInfo = (RicSubscription *)subsNode->node;
7345 DU_ALLOC(ricSubsList->list.array[ieIdx], sizeof(RICsubscription_withCause_ItemIEs_t));
7346 if(!ricSubsList->list.array[ieIdx])
7348 DU_LOG("\nERROR --> E2AP : %s: Memory allocation for E2AP-PDU failed at line %d",__func__, __LINE__);
7352 subsItemIe = (RICsubscription_withCause_ItemIEs_t *)ricSubsList->list.array[ieIdx];
7353 subsItemIe->id = ProtocolIE_IDE2_id_RICsubscription_withCause_Item;
7354 subsItemIe->criticality = CriticalityE2_ignore;
7355 subsItemIe->value.present = RICsubscription_withCause_ItemIEs__value_PR_RICsubscription_withCause_Item;
7357 subsItem = & subsItemIe->value.choice.RICsubscription_withCause_Item;
7358 subsItem->ricRequestID.ricRequestorID = subsInfo->requestId.requestorId;
7359 subsItem->ricRequestID.ricInstanceID = subsInfo->requestId.instanceId;
7360 subsItem->ranFunctionID = subsInfo->ranFuncId;
7361 fillE2Cause(&subsItem->cause, subsInfo->failureCause);
7364 subsNode = subsNode->next;
7370 /*******************************************************************
7372 * @brief Builds and Send RIC Subscription delete required
7376 * Function : BuildAndSendRicSubscriptionDeleteRequired
7378 * Functionality: Build and send RIC subscription delete required.
7379 * There can be 2 approaches to trigger following. One of these
7380 * approaches may/may not be implemented in future:
7381 * 1. It can be triggerred immediately when a RIC subscription's
7382 * End Time has expired. In this case, only this subscription's
7383 * info will be sent in this message.
7384 * Since we have not yet added support to execute RIC
7385 * Subscription based on Start Time and End Timer, this message is
7386 * not triggered anywhere from DU APP yet.
7387 * 2. Another approach is to have a periodic timer to check subscription
7388 * status running in background.
7389 * When RIC Subscription End Time expires, this subscription is
7390 * marked to be deleted. Later when this background timer expires,
7391 * a RIC Subscription delete required is sent with all the
7392 * subscription's info which is marked to be deleted.
7393 * The following function is implemented keeping in mind the second
7397 * @return ROK - success
7400 ******************************************************************/
7401 uint8_t BuildAndSendRicSubscriptionDeleteRequired()
7403 uint8_t elementCnt = 0, ieIdx = 0, ret = RFAILED;
7404 E2AP_PDU_t *e2apMsg = NULLP;
7405 RICsubscriptionDeleteRequired_t *ricSubsDelRqd = NULLP;
7406 RICsubscriptionDeleteRequired_IEs_t *ricSubsDelRqdIe = NULLP;
7407 asn_enc_rval_t encRetVal; /* Encoder return value */
7408 CmLListCp ricSubsToBeDelList;
7412 /* Check if there are any RIC subscriptions to be deleted */
7413 cmLListInit(&ricSubsToBeDelList);
7414 fetchRicSubsToBeDeleted(&ricSubsToBeDelList);
7415 if(ricSubsToBeDelList.count == 0)
7417 DU_LOG("\nDEBUG --> E2AP : %s: No RIC subscriptions are required to be deleted", __func__);
7421 DU_LOG("\nINFO --> E2AP : Building RIC Subscription Delete Required Message\n");
7423 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
7424 if(e2apMsg == NULLP)
7426 DU_LOG("\nERROR --> E2AP : %s: Memory allocation for E2AP-PDU failed at line %d",__func__, __LINE__);
7430 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
7431 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
7432 if(e2apMsg->choice.initiatingMessage == NULLP)
7434 DU_LOG("\nERROR --> E2AP : %s: Memory allocation for E2AP-PDU failed at line %d",__func__, __LINE__);
7437 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICsubscriptionDeleteRequired;
7438 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
7439 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICsubscriptionDeleteRequired;
7441 ricSubsDelRqd = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionDeleteRequired;
7444 ricSubsDelRqd->protocolIEs.list.count = elementCnt;
7445 ricSubsDelRqd->protocolIEs.list.size = elementCnt * sizeof(RICsubscriptionDeleteRequired_IEs_t *);
7447 DU_ALLOC(ricSubsDelRqd->protocolIEs.list.array, ricSubsDelRqd->protocolIEs.list.size);
7448 if(ricSubsDelRqd->protocolIEs.list.array == NULLP)
7450 DU_LOG("\nERROR --> E2AP : %s: Memory allocation failed for array elements at line %d",__func__, __LINE__);
7454 for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
7456 DU_ALLOC(ricSubsDelRqd->protocolIEs.list.array[ieIdx], sizeof(RICsubscriptionDeleteRequired_IEs_t));
7457 if(ricSubsDelRqd->protocolIEs.list.array[ieIdx] == NULLP)
7459 DU_LOG("\nERROR --> E2AP : %s: Memory allocation failed for index [%d] at line %d", \
7460 __func__, ieIdx, __LINE__);
7464 if(ieIdx < elementCnt)
7468 ricSubsDelRqdIe = ricSubsDelRqd->protocolIEs.list.array[ieIdx];
7469 ricSubsDelRqdIe->id = ProtocolIE_IDE2_id_RICsubscriptionToBeRemoved;
7470 ricSubsDelRqdIe->criticality = CriticalityE2_ignore;
7471 ricSubsDelRqdIe->value.present = RICsubscriptionDeleteRequired_IEs__value_PR_RICsubscription_List_withCause;
7472 if(fillRicSubsListWithCause(&ricSubsDelRqdIe->value.choice.RICsubscription_List_withCause, ricSubsToBeDelList)\
7475 DU_LOG("\nERROR --> E2AP : %s: Failed to fill RIC Subscription list with cause", __func__);
7479 /* Prints the Msg formed */
7480 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
7481 memset(encBuf, 0, ENC_BUF_MAX_LEN);
7483 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
7484 if(encRetVal.encoded == ENCODE_FAIL)
7486 DU_LOG("\nERROR --> E2AP : Could not encode RIC Subscription Delete Required Message (at %s)\n",\
7487 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
7492 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC Subscription Delete Required Message \n");
7493 #ifdef DEBUG_ASN_PRINT
7494 for(int i=0; i< encBufSize; i++)
7496 printf("%x",encBuf[i]);
7501 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
7503 DU_LOG("\nERROR --> E2AP : Failed to send RIC Susbcription Delete Required Message");
7510 FreeRicSubscriptionDeleteRequired(e2apMsg, &ricSubsToBeDelList);
7514 /*******************************************************************
7516 * @brief Free RIC Subscription Delete Request Message
7520 * Function : freeAperDecodingOfRicSubsDeleteReq
7522 * Functionality: Free RIC Subscription Delete Request
7524 * @param E2AP Message PDU
7527 ******************************************************************/
7528 void freeAperDecodingOfRicSubsDeleteReq(E2AP_PDU_t *e2apMsg)
7531 RICsubscriptionDeleteRequest_t *ricSubsDelReq = NULLP;
7535 if(e2apMsg->choice.initiatingMessage)
7537 ricSubsDelReq = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionDeleteRequest;
7538 if(ricSubsDelReq->protocolIEs.list.array)
7540 for(ieIdx = 0; ieIdx < ricSubsDelReq->protocolIEs.list.count; ieIdx++)
7542 if(ricSubsDelReq->protocolIEs.list.array[ieIdx])
7544 free(ricSubsDelReq->protocolIEs.list.array[ieIdx]);
7547 free(ricSubsDelReq->protocolIEs.list.array);
7553 /*******************************************************************
7555 * @brief Process RIC Subscription delete request
7559 * Function : procRicSubscriptionDeleteRequest
7561 * Functionality: Process RIC subscription delete request.
7562 * Fetch RAN Function and RIC subscription to be deleted.
7563 * Send statistics delete request to MAC for all action sequence
7564 * within this RIC subscription.
7566 * @params[in] E2AP PDU
7569 ******************************************************************/
7570 void procRicSubscriptionDeleteRequest(E2AP_PDU_t *e2apMsg)
7573 uint16_t ranFuncId = 0;
7574 bool procFailure = false;
7575 RicRequestId ricReqId;
7576 RanFunction *ranFuncDb = NULLP;
7577 CmLList *ricSubsNode = NULLP;
7578 RicSubscription *ricSubsDb = NULLP;
7579 RICsubscriptionDeleteRequest_t *ricSubsDelReq = NULLP;
7580 RICsubscriptionDeleteRequest_IEs_t *ricSubsDelReqIe = NULLP;
7582 DU_LOG("\nINFO --> E2AP : %s: Received RIC Subscription Delete Request", __func__);
7587 DU_LOG("\nERROR --> E2AP : %s: E2AP Message is NULL", __func__);
7591 if(!e2apMsg->choice.initiatingMessage)
7593 DU_LOG("\nERROR --> E2AP : %s: Initiating Message in E2AP PDU is NULL", __func__);
7597 ricSubsDelReq = &e2apMsg->choice.initiatingMessage->value.choice.RICsubscriptionDeleteRequest;
7598 if(!ricSubsDelReq->protocolIEs.list.array)
7600 DU_LOG("\nERROR --> E2AP : %s: Array conatining E2AP message IEs is null", __func__);
7604 for(ieIdx = 0; ieIdx < ricSubsDelReq->protocolIEs.list.count; ieIdx++)
7606 if(!ricSubsDelReq->protocolIEs.list.array[ieIdx])
7608 DU_LOG("\nERROR --> E2AP : %s: IE at index [%d] in E2AP message IEs list is null", __func__, ieIdx);
7612 ricSubsDelReqIe = ricSubsDelReq->protocolIEs.list.array[ieIdx];
7613 switch(ricSubsDelReqIe->id)
7615 case ProtocolIE_IDE2_id_RICrequestID:
7617 memset(&ricReqId, 0, sizeof(RicRequestId));
7618 ricReqId.requestorId = ricSubsDelReqIe->value.choice.RICrequestID.ricRequestorID;
7619 ricReqId.instanceId = ricSubsDelReqIe->value.choice.RICrequestID.ricInstanceID;
7623 case ProtocolIE_IDE2_id_RANfunctionID:
7625 ranFuncId = ricSubsDelReqIe->value.choice.RANfunctionID;
7626 ranFuncDb = fetchRanFuncFromRanFuncId(ranFuncId);
7629 DU_LOG("\nERROR --> E2AP : %s: RAN Function ID [%d] not found", __func__, ranFuncId);
7634 ricSubsDb = fetchSubsInfoFromRicReqId(ricReqId, ranFuncDb, &ricSubsNode);
7637 DU_LOG("\nERROR --> E2AP : %s: RIC Subscription not found for Requestor_ID [%d] Instance_ID [%d]",\
7638 __func__, ricReqId.requestorId, ricReqId.instanceId);
7643 //TODO : Send statistics delete request to MAC
7649 } /* End of switch for Protocol IE Id */
7653 } /* End of for loop for Protocol IE list */
7658 freeAperDecodingOfRicSubsDeleteReq(e2apMsg);
7662 /*******************************************************************
7664 * @brief Deallocate the memory allocated for E2 node configuration
7665 * update ack msg by aper decoder
7669 * Function : freeAperDecodingOfE2NodeConfigUpdateAck
7672 * - Deallocate the memory allocated for E2 node configuration
7673 * update ack msg by aper decoder
7675 * @params[in] E2AP_PDU_t *e2apMsg
7676 * @return ROK - success
7679 * ****************************************************************/
7681 void freeAperDecodingOfE2NodeConfigUpdateAck(E2nodeConfigurationUpdateAcknowledge_t *updateAckMsg)
7683 uint8_t arrIdx =0, e2NodeConfigIdx=0;
7684 E2nodeComponentConfigUpdateAck_ItemIEs_t *updateAckItemIe=NULL;
7685 E2nodeComponentConfigUpdateAck_List_t *updateAckList=NULL;
7686 E2nodeComponentConfigRemovalAck_ItemIEs_t *removalAckItemIe=NULL;
7687 E2nodeComponentConfigRemovalAck_List_t *removalAckList=NULL;
7688 E2nodeComponentConfigAdditionAck_ItemIEs_t *additionAckItemIte=NULL;
7689 E2nodeComponentConfigAdditionAck_List_t *additionAckList=NULL;
7691 E2nodeComponentInterfaceF1_t *f1InterfaceInfo=NULLP;
7692 if(updateAckMsg->protocolIEs.list.array != NULLP)
7694 for(arrIdx = 0; arrIdx < updateAckMsg->protocolIEs.list.count; arrIdx++)
7696 if(updateAckMsg->protocolIEs.list.array[arrIdx])
7698 switch(updateAckMsg->protocolIEs.list.array[arrIdx]->id)
7700 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
7702 additionAckList =&updateAckMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
7703 if(additionAckList->list.array)
7705 for(e2NodeConfigIdx=0; e2NodeConfigIdx<additionAckList->list.count; e2NodeConfigIdx++)
7707 additionAckItemIte = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) additionAckList->list.array[e2NodeConfigIdx];
7708 if(additionAckItemIte)
7710 switch(additionAckItemIte->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.present)
7712 case E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1:
7714 f1InterfaceInfo = additionAckItemIte->value.choice.E2nodeComponentConfigAdditionAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1;
7715 free(f1InterfaceInfo->gNB_DU_ID.buf);
7716 free(f1InterfaceInfo);
7722 free(additionAckItemIte);
7724 free(additionAckList->list.array);
7729 case ProtocolIE_IDE2_id_E2nodeComponentConfigUpdateAck:
7731 updateAckList =&updateAckMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigUpdateAck_List;
7732 if(updateAckList->list.array)
7734 for(e2NodeConfigIdx=0; e2NodeConfigIdx<updateAckList->list.count; e2NodeConfigIdx++)
7736 updateAckItemIe = (E2nodeComponentConfigUpdateAck_ItemIEs_t*) updateAckList->list.array[e2NodeConfigIdx];
7739 switch(updateAckItemIe->value.choice.E2nodeComponentConfigUpdateAck_Item.e2nodeComponentID.present)
7741 case E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1:
7743 f1InterfaceInfo = updateAckItemIe->value.choice.E2nodeComponentConfigUpdateAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1;
7744 free(f1InterfaceInfo->gNB_DU_ID.buf);
7745 free(f1InterfaceInfo);
7751 free(updateAckItemIe);
7754 free(updateAckList->list.array);
7758 case ProtocolIE_IDE2_id_E2nodeComponentConfigRemovalAck:
7760 removalAckList =&updateAckMsg->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigRemovalAck_List;
7761 if(removalAckList->list.array)
7763 for(e2NodeConfigIdx=0; e2NodeConfigIdx<removalAckList->list.count; e2NodeConfigIdx++)
7765 removalAckItemIe = (E2nodeComponentConfigRemovalAck_ItemIEs_t*) removalAckList->list.array[e2NodeConfigIdx];
7766 if(removalAckItemIe)
7768 switch(removalAckItemIe->value.choice.E2nodeComponentConfigRemovalAck_Item.e2nodeComponentID.present)
7770 case E2nodeComponentID_PR_e2nodeComponentInterfaceTypeF1:
7772 f1InterfaceInfo = removalAckItemIe->value.choice.E2nodeComponentConfigRemovalAck_Item.e2nodeComponentID.choice.e2nodeComponentInterfaceTypeF1;
7773 free(f1InterfaceInfo->gNB_DU_ID.buf);
7774 free(f1InterfaceInfo);
7780 free(removalAckItemIe);
7783 free(removalAckList->list.array);
7788 free(updateAckMsg->protocolIEs.list.array[arrIdx]);
7791 free(updateAckMsg->protocolIEs.list.array);
7795 /******************************************************************
7797 * @brief Processes the E2 node config update ack msg
7801 * Function :procE2NodeConfigUpdateAck
7803 * Functionality: Processes the E2 node config update ack msg
7805 * @params[in] E2AP_PDU_t ASN decoded E2AP message
7806 * @return ROK - success
7809 * ****************************************************************/
7811 void procE2NodeConfigUpdateAck(E2AP_PDU_t *e2apMsg)
7814 uint16_t e2CfgIdx =0;
7815 E2nodeConfigurationUpdateAcknowledge_t *e2NodeConfigUpdateAck =NULLP;
7816 E2nodeComponentConfigUpdateAck_List_t *e2NodeConfigUpdateAckList=NULLP;
7817 E2nodeComponentConfigUpdateAck_ItemIEs_t *e2NodeUpdateAckItem=NULLP;
7818 E2nodeComponentConfigRemovalAck_List_t *e2NodeConfigRemovalAckList=NULLP;
7819 E2nodeComponentConfigRemovalAck_ItemIEs_t *e2NodeRemovalAckItem=NULLP;
7820 E2nodeComponentConfigAdditionAck_List_t *e2NodeConfigAdditionAckList=NULLP;
7821 E2nodeComponentConfigAdditionAck_ItemIEs_t *e2NodeAdditionAckItem=NULLP;
7823 e2NodeConfigUpdateAck = &e2apMsg->choice.successfulOutcome->value.choice.E2nodeConfigurationUpdateAcknowledge;
7825 if(e2NodeConfigUpdateAck->protocolIEs.list.array)
7827 for(arrIdx =0; arrIdx<e2NodeConfigUpdateAck->protocolIEs.list.count; arrIdx++)
7829 switch(e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->id)
7831 case ProtocolIE_IDE2_id_TransactionID:
7835 case ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck:
7837 e2NodeConfigAdditionAckList = &e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigAdditionAck_List;
7838 if(e2NodeConfigAdditionAckList->list.array)
7840 for(e2CfgIdx = 0; e2CfgIdx< e2NodeConfigAdditionAckList->list.count; e2CfgIdx++)
7842 e2NodeAdditionAckItem = (E2nodeComponentConfigAdditionAck_ItemIEs_t*) e2NodeConfigAdditionAckList->list.array[e2CfgIdx];
7843 handleE2NodeConfigUpdateAckIes((PTR)&e2NodeAdditionAckItem->value.choice.E2nodeComponentConfigAdditionAck_Item,\
7844 ProtocolIE_IDE2_id_E2nodeComponentConfigAdditionAck);
7849 case ProtocolIE_IDE2_id_E2nodeComponentConfigUpdateAck:
7851 e2NodeConfigUpdateAckList = &e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigUpdateAck_List;
7852 if(e2NodeConfigUpdateAckList->list.array)
7854 for(e2CfgIdx = 0; e2CfgIdx< e2NodeConfigUpdateAckList->list.count; e2CfgIdx++)
7856 e2NodeUpdateAckItem = (E2nodeComponentConfigUpdateAck_ItemIEs_t*) e2NodeConfigUpdateAckList->list.array[e2CfgIdx];
7857 handleE2NodeConfigUpdateAckIes((PTR)&e2NodeUpdateAckItem->value.choice.E2nodeComponentConfigUpdateAck_Item,\
7858 ProtocolIE_IDE2_id_E2nodeComponentConfigUpdateAck);
7863 case ProtocolIE_IDE2_id_E2nodeComponentConfigRemovalAck:
7865 e2NodeConfigRemovalAckList = &e2NodeConfigUpdateAck->protocolIEs.list.array[arrIdx]->value.choice.E2nodeComponentConfigRemovalAck_List;
7866 if(e2NodeConfigRemovalAckList->list.array)
7868 for(e2CfgIdx = 0; e2CfgIdx< e2NodeConfigRemovalAckList->list.count; e2CfgIdx++)
7870 e2NodeRemovalAckItem = (E2nodeComponentConfigRemovalAck_ItemIEs_t*) e2NodeConfigRemovalAckList->list.array[e2CfgIdx];
7871 handleE2NodeConfigUpdateAckIes((PTR)&e2NodeRemovalAckItem->value.choice.E2nodeComponentConfigRemovalAck_Item,\
7872 ProtocolIE_IDE2_id_E2nodeComponentConfigRemovalAck);
7881 freeAperDecodingOfE2NodeConfigUpdateAck(e2NodeConfigUpdateAck);
7884 /*******************************************************************
7886 * @brief Deallocate the memory allocated for RemovalRequest msg
7890 * Function : FreeRemovalRequest
7893 * - freeing the memory allocated for RemovalRequest
7895 * @params[in] E2AP_PDU_t *e2apMsg
7896 * @return ROK - success
7899 * ****************************************************************/
7900 void FreeRemovalRequest(E2AP_PDU_t *e2apMsg)
7903 E2RemovalRequest_t *removalReq = NULLP;
7905 if(e2apMsg != NULLP)
7907 if(e2apMsg->choice.initiatingMessage != NULLP)
7909 removalReq = &e2apMsg->choice.initiatingMessage->value.choice.E2RemovalRequest;
7910 if(removalReq->protocolIEs.list.array)
7912 for(ieIdx = 0; ieIdx < removalReq->protocolIEs.list.count; ieIdx++)
7914 DU_FREE(removalReq->protocolIEs.list.array[ieIdx], sizeof(E2RemovalRequestIEs_t));
7916 DU_FREE(removalReq->protocolIEs.list.array, removalReq->protocolIEs.list.size);
7918 DU_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
7920 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
7924 /*******************************************************************
7926 * @brief Build and send the removal request msg
7930 * Function : BuildAndSendRemovalRequest
7933 * - Buld and send the removal request msg to E2 node
7935 * @return ROK - success
7938 * ****************************************************************/
7940 uint8_t BuildAndSendRemovalRequest()
7942 uint8_t ieIdx = 0, elementCnt = 0, transId = 0;
7943 uint8_t ret = RFAILED;
7944 E2AP_PDU_t *e2apMsg = NULLP;
7945 E2RemovalRequest_t *removalReq = NULLP;
7946 asn_enc_rval_t encRetVal; /* Encoder return value */
7948 DU_LOG("\nINFO --> E2AP : Building Removal Request\n");
7952 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
7953 if(e2apMsg == NULLP)
7955 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
7959 e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
7960 DU_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
7961 if(e2apMsg->choice.initiatingMessage == NULLP)
7963 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
7967 e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_E2removal;
7968 e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
7969 e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_E2RemovalRequest;
7970 removalReq = &e2apMsg->choice.initiatingMessage->value.choice.E2RemovalRequest;
7973 removalReq->protocolIEs.list.count = elementCnt;
7974 removalReq->protocolIEs.list.size = elementCnt * sizeof(E2RemovalRequestIEs_t *);
7976 DU_ALLOC(removalReq->protocolIEs.list.array, removalReq->protocolIEs.list.size);
7977 if(!removalReq->protocolIEs.list.array)
7979 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
7983 for(ieIdx = 0; ieIdx < elementCnt; ieIdx++)
7985 DU_ALLOC(removalReq->protocolIEs.list.array[ieIdx], sizeof(E2RemovalRequestIEs_t));
7986 if(!removalReq->protocolIEs.list.array[ieIdx])
7988 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
7993 /* In case of failure */
7994 if(ieIdx < elementCnt)
7998 removalReq->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
7999 removalReq->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
8000 removalReq->protocolIEs.list.array[ieIdx]->value.present = E2RemovalRequestIEs__value_PR_TransactionID;
8001 transId = assignTransactionId();
8002 removalReq->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
8004 /* Prints the Msg formed */
8005 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
8007 memset(encBuf, 0, ENC_BUF_MAX_LEN);
8009 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
8011 if(encRetVal.encoded == ENCODE_FAIL)
8013 DU_LOG("\nERROR --> E2AP : Could not encode removal request structure (at %s)\n",\
8014 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
8019 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for removal request\n");
8020 #ifdef DEBUG_ASN_PRINT
8021 for(int i=0; i< encBufSize; i++)
8023 printf("%x",encBuf[i]);
8027 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
8029 DU_LOG("\nERROR --> E2AP : Sending removal request failed");
8035 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId = transId;
8036 duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode = e2apMsg->choice.initiatingMessage->procedureCode;
8040 /* Free all memory */
8041 FreeRemovalRequest(e2apMsg);
8046 /******************************************************************
8048 * @brief Deallocation of memory allocated by aper decoder
8049 * for Removal failure
8053 * Function : freeAperDecodingOfE2RemovalFailure
8055 * Functionality: Deallocation of memory allocated by aper decoder
8056 * for Removal failure
8058 * @params[in] Pointer to removalFailure
8061 * ****************************************************************/
8062 void freeAperDecodingOfE2RemovalFailure(E2RemovalFailure_t *removalFailure)
8068 if(removalFailure->protocolIEs.list.array)
8070 for(arrIdx=0; arrIdx<removalFailure->protocolIEs.list.count; arrIdx++)
8072 if(removalFailure->protocolIEs.list.array[arrIdx])
8074 free(removalFailure->protocolIEs.list.array[arrIdx]);
8077 free(removalFailure->protocolIEs.list.array);
8082 /******************************************************************
8084 * @brief Processes the E2 removal failure msg
8088 * Function : procE2RemovalFailure
8090 * Functionality: Processes the E2 removal failure msg
8093 * E2AP_PDU_t *e2apMsg
8097 * ****************************************************************/
8098 void ProcE2RemovalFailure(E2AP_PDU_t *e2apMsg)
8100 uint8_t ieIdx = 0, transId=0;
8101 CauseE2_t *cause = NULLP;
8102 E2RemovalFailure_t *e2RemovalFailure=NULLP;
8104 e2RemovalFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2RemovalFailure;
8106 if(!e2RemovalFailure->protocolIEs.list.array)
8108 DU_LOG("\nERROR --> E2AP : e2RemovalFailure array pointer is null");
8112 for(ieIdx=0; ieIdx < e2RemovalFailure->protocolIEs.list.count; ieIdx++)
8114 if(e2RemovalFailure->protocolIEs.list.array[ieIdx])
8116 switch(e2RemovalFailure->protocolIEs.list.array[ieIdx]->id)
8118 case ProtocolIE_IDE2_id_TransactionID:
8120 transId = e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
8121 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
8122 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
8124 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
8128 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
8132 case ProtocolIE_IDE2_id_CauseE2:
8134 cause = &e2RemovalFailure->protocolIEs.list.array[ieIdx]->value.choice.CauseE2;
8135 printE2ErrorCause(cause);
8140 DU_LOG("\nERROR --> E2AP : Received Invalid Ie [%ld]", e2RemovalFailure->protocolIEs.list.array[ieIdx]->id);
8146 freeAperDecodingOfE2RemovalFailure(e2RemovalFailure);
8149 /******************************************************************
8151 * @brief Deallocation of memory allocated by aper decoder
8152 * for Removal failure
8156 * Function : freeAperDecodingOfE2RemovalResponse
8158 * Functionality: Deallocation of memory allocated by aper decoder
8159 * for Removal failure
8161 * @params[in] Pointer to removalResponse
8164 * ****************************************************************/
8165 void freeAperDecodingOfE2RemovalResponse(E2RemovalResponse_t *removalResponse)
8171 if(removalResponse->protocolIEs.list.array)
8173 for(arrIdx=0; arrIdx<removalResponse->protocolIEs.list.count; arrIdx++)
8175 if(removalResponse->protocolIEs.list.array[arrIdx])
8177 free(removalResponse->protocolIEs.list.array[arrIdx]);
8180 free(removalResponse->protocolIEs.list.array);
8185 /*******************************************************************
8187 * @brief process the E2 Removal Response
8191 * Function : ProcE2RemovalResponse
8193 * Functionality: Process E2 Removal Response
8196 * E2AP_PDU_t *e2apMsg
8199 ******************************************************************/
8201 void ProcE2RemovalResponse(E2AP_PDU_t *e2apMsg)
8203 uint8_t ieIdx = 0, transId=0;
8204 E2RemovalResponse_t *removalRsp = NULLP;
8206 removalRsp = &e2apMsg->choice.successfulOutcome->value.choice.E2RemovalResponse;
8208 if(!removalRsp->protocolIEs.list.array)
8210 DU_LOG("\nERROR --> E2AP : removalRsp array pointer is null");
8214 for(ieIdx=0; ieIdx < removalRsp->protocolIEs.list.count; ieIdx++)
8216 if(removalRsp->protocolIEs.list.array[ieIdx])
8218 switch(removalRsp->protocolIEs.list.array[ieIdx]->id)
8220 case ProtocolIE_IDE2_id_TransactionID:
8222 transId = removalRsp->protocolIEs.list.array[ieIdx]->value.choice.TransactionID;
8223 if((duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].transactionId == transId) &&\
8224 (duCb.e2apDb.e2TransInfo.e2InitTransaction[transId].procedureCode == e2apMsg->choice.unsuccessfulOutcome->procedureCode))
8226 removeE2NodeInformation();
8227 memset(&duCb.e2apDb.e2TransInfo.e2InitTransaction[transId], 0, sizeof(E2TransInfo));
8231 DU_LOG("\nERROR --> E2AP : Invalid transaction id [%d]", transId);
8237 DU_LOG("\nERROR --> E2AP : Received Invalid Ie [%ld]", removalRsp->protocolIEs.list.array[ieIdx]->id);
8244 freeAperDecodingOfE2RemovalResponse(removalRsp);
8247 /*******************************************************************
8249 * @brief Deallocate the memory allocated for E2 Connection Update Failure
8253 * Function : FreeE2ConnectionUpdateFailure
8256 * - freeing the memory allocated for E2ConnectionUpdateFailure
8258 * @params[in] E2AP_PDU_t *e2apMsg
8259 * @return ROK - success
8262 * ****************************************************************/
8263 void FreeE2ConnectionUpdateFailure(E2AP_PDU_t *e2apMsg)
8266 E2connectionUpdateFailure_t *e2ConnectionUpdateFailure=NULLP;
8268 if(e2apMsg != NULLP)
8270 if(e2apMsg->choice.unsuccessfulOutcome != NULLP)
8272 e2ConnectionUpdateFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2connectionUpdateFailure;
8273 if(e2ConnectionUpdateFailure->protocolIEs.list.array)
8275 for(ieIdx=0; ieIdx < e2ConnectionUpdateFailure->protocolIEs.list.count; ieIdx++)
8277 DU_FREE(e2ConnectionUpdateFailure->protocolIEs.list.array[ieIdx], sizeof(E2connectionUpdateFailure_IEs_t));
8279 DU_FREE(e2ConnectionUpdateFailure->protocolIEs.list.array, e2ConnectionUpdateFailure->protocolIEs.list.size);
8281 DU_FREE(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
8283 DU_FREE(e2apMsg, sizeof(E2AP_PDU_t));
8287 /*******************************************************************
8289 * @brief Buld and send the E2 Connection Update Failure msg
8293 * Function : BuildAndSendE2ConnectionUpdateFailure
8296 * - Buld and send the E2 Connection Update Failure Message
8300 * @return ROK - success
8303 * ****************************************************************/
8305 uint8_t BuildAndSendE2ConnectionUpdateFailure(uint16_t transId, E2FailureCause failureCause)
8307 uint8_t ieIdx = 0, elementCnt = 0;
8308 uint8_t ret = RFAILED;
8309 E2AP_PDU_t *e2apMsg = NULLP;
8310 E2connectionUpdateFailure_t *e2ConnectionUpdateFailure=NULLP;
8311 asn_enc_rval_t encRetVal; /* Encoder return value */
8313 DU_LOG("\nINFO --> E2AP : Building E2 Connection Update Failure Message\n");
8316 DU_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
8317 if(e2apMsg == NULLP)
8319 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
8322 e2apMsg->present = E2AP_PDU_PR_unsuccessfulOutcome;
8324 DU_ALLOC(e2apMsg->choice.unsuccessfulOutcome, sizeof(UnsuccessfulOutcomeE2_t));
8325 if(e2apMsg->choice.unsuccessfulOutcome == NULLP)
8327 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
8331 e2apMsg->choice.unsuccessfulOutcome->procedureCode = ProcedureCodeE2_id_E2connectionUpdate;
8332 e2apMsg->choice.unsuccessfulOutcome->criticality = CriticalityE2_reject;
8333 e2apMsg->choice.unsuccessfulOutcome->value.present = UnsuccessfulOutcomeE2__value_PR_E2connectionUpdateFailure;
8334 e2ConnectionUpdateFailure = &e2apMsg->choice.unsuccessfulOutcome->value.choice.E2connectionUpdateFailure;
8337 e2ConnectionUpdateFailure->protocolIEs.list.count = elementCnt;
8338 e2ConnectionUpdateFailure->protocolIEs.list.size = elementCnt * sizeof(E2connectionUpdateFailure_IEs_t *);
8339 DU_ALLOC(e2ConnectionUpdateFailure->protocolIEs.list.array, e2ConnectionUpdateFailure->protocolIEs.list.size);
8340 if(!e2ConnectionUpdateFailure->protocolIEs.list.array)
8342 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
8346 for(ieIdx=0; ieIdx < elementCnt; ieIdx++)
8348 DU_ALLOC(e2ConnectionUpdateFailure->protocolIEs.list.array[ieIdx], sizeof(E2connectionUpdateFailure_IEs_t));
8349 if(!e2ConnectionUpdateFailure->protocolIEs.list.array[ieIdx])
8351 DU_LOG("\nERROR --> E2AP : Memory allocation failed in %s at line %d", __func__, __LINE__);
8355 if(ieIdx < elementCnt)
8359 e2ConnectionUpdateFailure->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_TransactionID;
8360 e2ConnectionUpdateFailure->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_reject;
8361 e2ConnectionUpdateFailure->protocolIEs.list.array[ieIdx]->value.present = E2connectionUpdateFailure_IEs__value_PR_TransactionID;
8362 e2ConnectionUpdateFailure->protocolIEs.list.array[ieIdx]->value.choice.TransactionID = transId;
8366 e2ConnectionUpdateFailure->protocolIEs.list.array[ieIdx]->id = ProtocolIE_IDE2_id_CauseE2;
8367 e2ConnectionUpdateFailure->protocolIEs.list.array[ieIdx]->criticality = CriticalityE2_ignore;
8368 e2ConnectionUpdateFailure->protocolIEs.list.array[ieIdx]->value.present = E2connectionUpdateFailure_IEs__value_PR_CauseE2;
8369 fillE2Cause(&e2ConnectionUpdateFailure->protocolIEs.list.array[ieIdx]->value.choice.CauseE2, failureCause);
8371 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
8373 memset(encBuf, 0, ENC_BUF_MAX_LEN);
8375 encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf, encBuf);
8376 if(encRetVal.encoded == ENCODE_FAIL)
8378 DU_LOG("\nERROR --> E2AP : Could not encode E2 connection update failure structure (at %s)\n",\
8379 encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
8384 DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for E2 Connection Update Failure \n");
8385 for(int i=0; i< encBufSize; i++)
8387 DU_LOG("%x",encBuf[i]);
8392 if(SendE2APMsg(DU_APP_MEM_REGION, DU_POOL, encBuf, encBufSize) != ROK)
8394 DU_LOG("\nERROR --> E2AP : Failed to send E2 Connection Update Failure");
8402 FreeE2ConnectionUpdateFailure(e2apMsg);
8406 /******************************************************************
8408 * @brief Deallocation of memory allocated by aper decoder for
8409 * E2 Connection Update
8413 * Function :freeAperDecodingOfE2ConnectionUpdate
8415 * Functionality: Deallocation of memory allocated by aper decoder for
8416 * E2 Connection Update
8418 * @params[in] Pointer to connectionUpdate
8421 * ****************************************************************/
8423 void freeAperDecodingOfE2ConnectionUpdate(E2connectionUpdate_t *connectionUpdate)
8425 uint8_t ieIdx =0, arrIdx=0;
8426 E2connectionUpdate_List_t *connectionToBeModifyList = NULLP;
8428 if(connectionUpdate->protocolIEs.list.array)
8430 for(ieIdx = 0; ieIdx < connectionUpdate->protocolIEs.list.count; ieIdx++)
8432 if(connectionUpdate->protocolIEs.list.array[ieIdx])
8434 switch(connectionUpdate->protocolIEs.list.array[ieIdx]->id)
8436 case ProtocolIE_IDE2_id_TransactionID:
8439 case ProtocolIE_IDE2_id_E2connectionUpdateModify:
8441 connectionToBeModifyList = &connectionUpdate->protocolIEs.list.array[ieIdx]->value.choice.E2connectionUpdate_List;
8442 if(connectionToBeModifyList->list.array)
8444 for(arrIdx= 0; arrIdx< connectionToBeModifyList->list.count; arrIdx++)
8446 free(connectionToBeModifyList->list.array[arrIdx]);
8448 free(connectionToBeModifyList->list.array);
8453 free(connectionUpdate->protocolIEs.list.array[ieIdx]);
8456 free(connectionUpdate->protocolIEs.list.array);
8460 /*******************************************************************
8462 * @brief Process e2 connection update received from RIC
8466 * Function : procE2ConnectionUpdate
8468 * Functionality: Process e2 connection update received from RIC
8470 * @param E2AP_PDU_t *e2apMsg
8473 ******************************************************************/
8475 void procE2ConnectionUpdate(E2AP_PDU_t *e2apMsg)
8477 bool invalidTransId = false;
8478 uint8_t arrIdx =0, transId =0, count=0;
8479 E2FailureCause failureCause;
8480 E2connectionUpdate_t *connectionUpdate=NULLP;
8482 DU_LOG("\nINFO --> E2AP : E2 connection update received");
8483 connectionUpdate = &e2apMsg->choice.initiatingMessage->value.choice.E2connectionUpdate;
8485 count = connectionUpdate->protocolIEs.list.count;
8486 for(arrIdx=0; arrIdx<connectionUpdate->protocolIEs.list.count; arrIdx++)
8488 switch(connectionUpdate->protocolIEs.list.array[arrIdx]->id)
8490 case ProtocolIE_IDE2_id_TransactionID:
8492 transId = connectionUpdate->protocolIEs.list.array[arrIdx]->value.choice.TransactionID;
8495 invalidTransId = true;
8499 case ProtocolIE_IDE2_id_E2connectionUpdateModify:
8506 if(invalidTransId == true)
8510 if(invalidTransId == true)
8512 failureCause.causeType = E2_PROTOCOL;
8513 failureCause.cause = E2_ABSTRACT_SYNTAX_ERROR_FALSELY_CONSTRUCTED_MESSAGE;
8514 if(BuildAndSendE2ConnectionUpdateFailure(transId, failureCause) != ROK)
8516 DU_LOG("\nERROR --> E2AP : Failed to build and send E2 connection update failure");
8524 freeAperDecodingOfE2ConnectionUpdate(connectionUpdate);
8527 /*******************************************************************
8529 * @brief Handles received E2AP message and sends back response
8533 * Function : E2APMsgHdlr
8536 * - Decodes received E2AP control message
8537 * - Prepares response message, encodes and sends to SCTP
8540 * @return ROK - success
8543 * ****************************************************************/
8544 void E2APMsgHdlr(Buffer *mBuf)
8547 char *recvBuf = NULLP;
8549 MsgLen recvBufLen =0;
8550 E2AP_PDU_t *e2apMsg = NULLP;
8551 asn_dec_rval_t rval ={0}; /* Decoder return value */
8552 E2AP_PDU_t e2apasnmsg={0} ;
8554 DU_LOG("\nDEBUG --> E2AP : Received E2AP message buffer");
8555 ODU_PRINT_MSG(mBuf, 0,0);
8557 /* Copy mBuf into char array to decode it */
8558 ODU_GET_MSG_LEN(mBuf, &recvBufLen);
8559 DU_ALLOC(recvBuf, (Size)recvBufLen);
8561 if(recvBuf == NULLP)
8563 DU_LOG("\nERROR --> E2AP : Memory allocation failed");
8566 if(ODU_COPY_MSG_TO_FIX_BUF(mBuf, 0, recvBufLen, (Data *)recvBuf, ©Cnt) != ROK)
8568 DU_LOG("\nERROR --> E2AP : Failed while copying %d", copyCnt);
8572 #ifdef DEBUG_ASN_PRINT
8573 printf("\nDEBUG --> E2AP : Received flat buffer to be decoded : ");
8574 for(i=0; i< recvBufLen; i++)
8576 printf("%x",recvBuf[i]);
8580 /* Decoding flat buffer into E2AP messsage */
8581 e2apMsg = &e2apasnmsg;
8582 memset(e2apMsg, 0, sizeof(E2AP_PDU_t));
8584 rval = aper_decode(0, &asn_DEF_E2AP_PDU, (void **)&e2apMsg, recvBuf, recvBufLen, 0, 0);
8585 DU_FREE(recvBuf, (Size)recvBufLen);
8587 if(rval.code == RC_FAIL || rval.code == RC_WMORE)
8589 DU_LOG("\nERROR --> E2AP : ASN decode failed");
8593 xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
8595 switch(e2apMsg->present)
8597 case E2AP_PDU_PR_unsuccessfulOutcome:
8599 switch(e2apMsg->choice.unsuccessfulOutcome->value.present)
8601 case UnsuccessfulOutcomeE2__value_PR_E2setupFailure:
8603 procE2SetupFailure(e2apMsg);
8606 case UnsuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateFailure:
8608 procE2NodeConfigUpdateFailure(e2apMsg);
8611 case UnsuccessfulOutcomeE2__value_PR_RICserviceUpdateFailure:
8613 procRicServiceUpdateFailure(e2apMsg);
8616 case UnsuccessfulOutcomeE2__value_PR_RICsubscriptionModificationRefuse:
8618 procRicSubscriptionModificationRefuse(e2apMsg);
8621 case UnsuccessfulOutcomeE2__value_PR_E2RemovalFailure:
8623 ProcE2RemovalFailure(e2apMsg);
8628 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_unsuccessfulOutcome [%d]",\
8629 e2apMsg->choice.unsuccessfulOutcome->value.present);
8633 free(e2apMsg->choice.unsuccessfulOutcome);
8636 case E2AP_PDU_PR_successfulOutcome:
8638 switch(e2apMsg->choice.successfulOutcome->value.present)
8640 case SuccessfulOutcomeE2__value_PR_E2setupResponse:
8644 procE2SetupRsp(e2apMsg);
8648 case SuccessfulOutcomeE2__value_PR_ResetResponseE2:
8650 procResetResponse(e2apMsg);
8653 case SuccessfulOutcomeE2__value_PR_RICserviceUpdateAcknowledge:
8655 procRicServiceUpdateAck(e2apMsg);
8658 case SuccessfulOutcomeE2__value_PR_RICsubscriptionModificationConfirm:
8660 procRicSubscriptionModificationConfirm(e2apMsg);
8663 case SuccessfulOutcomeE2__value_PR_E2nodeConfigurationUpdateAcknowledge:
8665 procE2NodeConfigUpdateAck(e2apMsg);
8668 case SuccessfulOutcomeE2__value_PR_E2RemovalResponse:
8670 ProcE2RemovalResponse(e2apMsg);
8675 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_successfulOutcome [%d]",\
8676 e2apMsg->choice.successfulOutcome->value.present);
8679 }/* End of switch(successfulOutcome) */
8680 free(e2apMsg->choice.successfulOutcome);
8684 case E2AP_PDU_PR_initiatingMessage:
8686 switch(e2apMsg->choice.initiatingMessage->value.present)
8688 case InitiatingMessageE2__value_PR_RICsubscriptionRequest:
8690 procRicSubscriptionRequest(e2apMsg);
8693 case InitiatingMessageE2__value_PR_RICserviceQuery:
8695 procRicServiceQuery(e2apMsg);
8698 case InitiatingMessageE2__value_PR_ErrorIndicationE2:
8700 DU_LOG("\nINFO --> E2AP : Error indication received");
8703 case InitiatingMessageE2__value_PR_ResetRequestE2:
8705 DU_LOG("\nINFO --> E2AP : Reset request received");
8706 procE2ResetRequest(e2apMsg);
8709 case InitiatingMessageE2__value_PR_RICsubscriptionDeleteRequest:
8711 DU_LOG("\nINFO --> E2AP : RIC Subscription Delete Request received");
8712 procRicSubscriptionDeleteRequest(e2apMsg);
8715 case InitiatingMessageE2__value_PR_E2RemovalRequest:
8717 DU_LOG("\nINFO --> E2AP : E2 Removal request received");
8718 procE2RemovalRequest(e2apMsg);
8721 case InitiatingMessageE2__value_PR_E2connectionUpdate:
8723 DU_LOG("\nINFO --> E2AP : E2 coneection update received");
8724 procE2ConnectionUpdate(e2apMsg);
8729 DU_LOG("\nERROR --> E2AP : Invalid type of E2AP_PDU_PR_initiatingMessage [%d]",\
8730 e2apMsg->choice.initiatingMessage->value.present);
8733 }/* End of switch(initiatingMessage) */
8734 free(e2apMsg->choice.initiatingMessage);
8739 DU_LOG("\nERROR --> E2AP : Invalid type of e2apMsg->present [%d]",e2apMsg->present);
8744 }/* End of switch(e2apMsg->present) */
8746 } /* End of E2APMsgHdlr */
8748 /**********************************************************************
8750 **********************************************************************/