+/*******************************************************************
+ *
+ * @brief Processing RIC subscription failure from DU
+ *
+ * @details
+ *
+ * Function : ProcRicSubscriptionFailure
+ *
+ * Functionality: Processing RIC subscription failure from DU
+ *
+ * @param ID of DU from which message was sent
+ * RIC Subscription failure message
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+uint8_t ProcRicSubscriptionFailure(uint32_t duId, RICsubscriptionFailure_t *ricSubscriptionFailure)
+{
+ uint8_t ieIdx = 0, duIdx = 0, subsIdx = 0;
+ uint8_t ranFuncId = 0;
+ bool ricReqIdDecoded = false;
+ DuDb *duDb = NULLP;
+ RanFunction *ranFuncDb = NULLP;
+ RicRequestId ricReqId;
+ RICsubscriptionFailure_IEs_t *ricSubsFailIe = NULLP;
+
+ DU_LOG("\nINFO --> E2AP : Received RIC subscription failure");
+
+ SEARCH_DU_DB(duIdx, duId, duDb);
+ if(duDb == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : duDb is not present for duId %d",duId);
+ return RFAILED;
+ }
+
+ memset(&ricReqId, 0, sizeof(RicRequestId));
+ if(ricSubscriptionFailure)
+ {
+ if(ricSubscriptionFailure->protocolIEs.list.array)
+ {
+ for(ieIdx=0; ieIdx<ricSubscriptionFailure->protocolIEs.list.count; ieIdx++)
+ {
+ if(ricSubscriptionFailure->protocolIEs.list.array[ieIdx])
+ {
+ ricSubsFailIe = ricSubscriptionFailure->protocolIEs.list.array[ieIdx];
+ switch(ricSubscriptionFailure->protocolIEs.list.array[ieIdx]->id)
+ {
+ case ProtocolIE_IDE2_id_RICrequestID:
+ {
+ ricReqId.requestorId = ricSubsFailIe->value.choice.RICrequestID.ricRequestorID;
+ ricReqId.instanceId = ricSubsFailIe->value.choice.RICrequestID.ricInstanceID;
+ ricReqIdDecoded = true;
+ break;
+ }
+ case ProtocolIE_IDE2_id_RANfunctionID:
+ {
+ ranFuncId = ricSubsFailIe->value.choice.RANfunctionID;
+ if(duDb->ranFunction[ranFuncId-1].id == ranFuncId)
+ {
+ ranFuncDb = &duDb->ranFunction[ranFuncId-1];
+ }
+ break;
+ }
+ case ProtocolIE_IDE2_id_CauseE2:
+ default:
+ /* No handling required as of now since this is a stub */
+ break;
+
+ }
+ }
+ }
+
+ /* Remove subscription entry from RAN Function */
+ if(ranFuncDb && ricReqIdDecoded)
+ {
+ for(subsIdx = 0; subsIdx < ranFuncDb->numOfSubscription; subsIdx++)
+ {
+ if((ranFuncDb->subscriptionList[subsIdx].requestId.requestorId == ricReqId.requestorId) &&
+ (ranFuncDb->subscriptionList[subsIdx].requestId.instanceId == ricReqId.instanceId))
+ {
+ memset(&ranFuncDb->subscriptionList[subsIdx], 0, sizeof(RicSubscription));
+ break;
+ }
+ }
+ }
+ }
+ }
+ return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Free the ErrorIndication Message
+ *
+ * @details
+ *
+ * Function : FreeRicIndication
+ *
+ * Functionality: Free the ErrorIndication Message
+ *
+ * @return void
+ *
+ *
+ ******************************************************************/
+void FreeErrorIndication(E2AP_PDU_t *e2apMsg)
+{
+ uint8_t arrIdx = 0;
+ ErrorIndicationE2_t *errorIndicationMsg= NULLP;
+
+ if(e2apMsg != NULLP)
+ {
+ if(e2apMsg->choice.initiatingMessage != NULLP)
+ {
+ errorIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.ErrorIndicationE2;
+ if(errorIndicationMsg!= NULLP)
+ {
+ if(errorIndicationMsg->protocolIEs.list.array != NULLP)
+ {
+ for(arrIdx=0; arrIdx<errorIndicationMsg->protocolIEs.list.count; arrIdx++)
+ {
+ RIC_FREE(errorIndicationMsg->protocolIEs.list.array[arrIdx],sizeof(ErrorIndicationE2_t));
+ }
+ RIC_FREE(errorIndicationMsg->protocolIEs.list.array,errorIndicationMsg->protocolIEs.list.size);
+ }
+ }
+ RIC_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+ }
+ RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
+ }
+}
+
+
+/*******************************************************************
+ *
+ * @brief Builds and Send the ErrorIndication Message
+ *
+ * @details
+ *
+ * Function : BuildAndSendErrorIndication
+ *
+ * Functionality:Fills the ErrorIndication Message
+ *
+ * @params[in]
+ * DU id
+ * Trans id
+ * Ric req id
+ * Ran function id
+ * Reason of failure
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ******************************************************************/
+
+uint8_t BuildAndSendErrorIndication(uint32_t duId, int8_t transId, RicRequestId requestId, uint16_t ranFuncId, uint8_t reason)
+{
+ uint8_t elementCnt =0, arrIdx=0, ret = RFAILED;
+ E2AP_PDU_t *e2apMsg = NULLP;
+ ErrorIndicationE2_t *errorIndicationMsg=NULLP;
+ asn_enc_rval_t encRetVal; /* Encoder return value */
+
+ while(true)
+ {
+ DU_LOG("\nINFO --> E2AP : Building Error Indication Message\n");
+
+ RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
+ if(e2apMsg == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed in %s at line %d",__func__, __LINE__);
+ break;
+ }
+
+ e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
+ RIC_ALLOC(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+ if(e2apMsg->choice.initiatingMessage == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed in %s at line %d",__func__, __LINE__);
+ break;
+ }
+ e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_ErrorIndicationE2;
+ e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
+ e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_ErrorIndicationE2;
+
+ errorIndicationMsg = &e2apMsg->choice.initiatingMessage->value.choice.ErrorIndicationE2;
+
+ /* Element count is 2 for TransactionID/RICrequestID and Cause.
+ * If the RAN function id is present, the count will be increased.*/
+ elementCnt = 2;
+ if(ranFuncId>0)
+ elementCnt++;
+
+ errorIndicationMsg->protocolIEs.list.count = elementCnt;
+ errorIndicationMsg->protocolIEs.list.size = elementCnt * sizeof(ErrorIndicationE2_IEs_t*);
+
+ /* Initialize the E2Setup members */
+ RIC_ALLOC(errorIndicationMsg->protocolIEs.list.array, errorIndicationMsg->protocolIEs.list.size);
+ if(errorIndicationMsg->protocolIEs.list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed for array elements in %s at line %d",__func__, __LINE__);
+ break;
+ }
+ for(arrIdx = 0; arrIdx < elementCnt; (arrIdx)++)
+ {
+ RIC_ALLOC(errorIndicationMsg->protocolIEs.list.array[arrIdx], sizeof(ErrorIndicationE2_IEs_t));
+ if(errorIndicationMsg->protocolIEs.list.array[arrIdx] == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation failed for array Idx %d in %s at line %d",arrIdx,__func__, __LINE__);
+ break;
+ }
+ }
+ if(arrIdx < elementCnt)
+ break;
+
+ arrIdx = 0;
+
+ if(transId >=0 && transId<=255)
+ {
+ /* TransactionID */
+ errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
+ errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_TransactionID;
+ errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = transId;
+ }
+ else
+ {
+ /* RICrequestID */
+ errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RICrequestID;
+ errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_RICrequestID;
+ errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.RICrequestID.ricRequestorID = requestId.requestorId;
+ errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.RICrequestID.ricInstanceID = requestId.instanceId;
+ }
+
+ if(ranFuncId>0)
+ {
+ /* RAN Function ID */
+ arrIdx++;
+ errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionID;
+ errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_RANfunctionID;
+ errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionID = ranFuncId;
+ }
+
+ /* Cause */
+ arrIdx++;
+ errorIndicationMsg->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_CauseE2;
+ errorIndicationMsg->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_ignore;
+ errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.present = ErrorIndicationE2_IEs__value_PR_CauseE2;
+ fillE2FailureCause(&errorIndicationMsg->protocolIEs.list.array[arrIdx]->value.choice.CauseE2, CauseE2_PR_misc, reason);
+
+
+ /* Prints the Msg formed */
+ xer_fprint(stdout, &asn_DEF_E2AP_PDU, e2apMsg);
+ memset(encBuf, 0, ENC_BUF_MAX_LEN);
+ encBufSize = 0;
+ encRetVal = aper_encode(&asn_DEF_E2AP_PDU, 0, e2apMsg, PrepFinalEncBuf,\
+ encBuf);
+ if(encRetVal.encoded == ENCODE_FAIL)
+ {
+ DU_LOG("\nERROR --> E2AP : Could not encode Error Indication Message (at %s)\n",\
+ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+ break;
+ }
+ else
+ {
+ DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for Error Indication Message \n");
+#ifdef DEBUG_ASN_PRINT
+ for(int i=0; i< encBufSize; i++)
+ {
+ printf("%x",encBuf[i]);
+ }
+#endif
+ }
+
+ if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duId) != ROK)
+ {
+ DU_LOG("\nINFO --> E2AP : Sending Error Indication Message");
+
+ }
+ ret = ROK;
+ break;
+ }
+ FreeErrorIndication(e2apMsg);
+ return ret;
+}