+/*******************************************************************
+ *
+ * @brief deallocate the memory allocated in building the
+ * Service Query message
+ *
+ * @details
+ *
+ * Function : FreeRicServiceQuery
+ *
+ * Functionality: deallocate the memory allocated in building
+ * Ric Service Query message
+ *
+ * @params[in] E2AP_PDU_t *e2apMsg
+ *
+ * @return void
+ * ****************************************************************/
+
+void FreeRicServiceQuery(E2AP_PDU_t *e2apMsg)
+{
+ uint8_t arrIdx = 0, ranFuncIdx=0;
+ RANfunctionsID_List_t *ranFuncAddedList;
+ RICserviceQuery_t *ricServiceQuery;
+
+ if(e2apMsg)
+ {
+ if(e2apMsg->choice.initiatingMessage)
+ {
+ ricServiceQuery = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceQuery;
+ if(ricServiceQuery->protocolIEs.list.array)
+ {
+ for(arrIdx=0; arrIdx<ricServiceQuery->protocolIEs.list.count; arrIdx++)
+ {
+ if(ricServiceQuery->protocolIEs.list.array[arrIdx])
+ {
+ switch(ricServiceQuery->protocolIEs.list.array[arrIdx]->id)
+ {
+ case ProtocolIE_IDE2_id_RANfunctionsAccepted:
+ {
+ ranFuncAddedList= &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List;
+ if(ranFuncAddedList->list.array)
+ {
+ for(ranFuncIdx=0;ranFuncIdx<ranFuncAddedList->list.count; ranFuncIdx++)
+ {
+ RIC_FREE(ranFuncAddedList->list.array[ranFuncIdx], sizeof(RANfunction_ItemIEs_t));
+ }
+ RIC_FREE(ranFuncAddedList->list.array, ranFuncAddedList->list.size);
+ }
+ break;
+ }
+ case RICserviceQuery_IEs__value_PR_TransactionID:
+ {
+ break;
+ }
+ }
+ RIC_FREE(ricServiceQuery->protocolIEs.list.array[arrIdx], sizeof(RICserviceQuery_IEs_t));
+ }
+ }
+ RIC_FREE(ricServiceQuery->protocolIEs.list.array, ricServiceQuery->protocolIEs.list.size);
+ }
+ RIC_FREE(e2apMsg->choice.initiatingMessage, sizeof(InitiatingMessageE2_t));
+ }
+ RIC_FREE(e2apMsg, sizeof(E2AP_PDU_t));
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief build and send the ric service Query
+ *
+ * @details
+ *
+ * Function : BuildAndSendRicServiceQuery
+ *
+ * Functionality: build and send the ric service Query
+ * @return ROK - success
+ * RFAILED - Acknowledge
+ *
+ ******************************************************************/
+
+uint8_t BuildAndSendRicServiceQuery(DuDb *duDb)
+{
+ uint8_t arrIdx;
+ uint8_t elementCnt;
+ uint8_t ret = RFAILED;
+ bool memAllocFailed = false;
+ E2AP_PDU_t *e2apMsg = NULL;
+ asn_enc_rval_t encRetVal;
+ RICserviceQuery_t *ricServiceQuery;
+
+ DU_LOG("\nINFO --> E2AP : Building Ric service Query\n");
+ while(true)
+ {
+ RIC_ALLOC(e2apMsg, sizeof(E2AP_PDU_t));
+ if(e2apMsg == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
+ break;
+ }
+ e2apMsg->present = E2AP_PDU_PR_initiatingMessage;
+ RIC_ALLOC(e2apMsg->choice.initiatingMessage , sizeof(struct InitiatingMessageE2));
+ if(e2apMsg->choice.initiatingMessage == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for E2AP-PDU failed");
+ break;
+ }
+
+ e2apMsg->choice.initiatingMessage->procedureCode = ProcedureCodeE2_id_RICserviceQuery;
+ e2apMsg->choice.initiatingMessage->criticality = CriticalityE2_reject;
+ e2apMsg->choice.initiatingMessage->value.present = InitiatingMessageE2__value_PR_RICserviceQuery;
+ ricServiceQuery = &e2apMsg->choice.initiatingMessage->value.choice.RICserviceQuery;
+
+ elementCnt = 1;
+ /* Fill Accepted RAN function IE If Ran function information is stored in databse */
+ if(duDb->numOfRanFunction)
+ elementCnt++;
+
+ ricServiceQuery->protocolIEs.list.count = elementCnt;
+ ricServiceQuery->protocolIEs.list.size = elementCnt * sizeof(RICserviceQuery_IEs_t*);
+
+ RIC_ALLOC(ricServiceQuery->protocolIEs.list.array, ricServiceQuery->protocolIEs.list.size);
+ if(ricServiceQuery->protocolIEs.list.array == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceQueryIEs failed");
+ break;
+ }
+
+ for(arrIdx=0; arrIdx<elementCnt; arrIdx++)
+ {
+ RIC_ALLOC(ricServiceQuery->protocolIEs.list.array[arrIdx], sizeof(RICserviceQuery_IEs_t));
+ if(ricServiceQuery->protocolIEs.list.array[arrIdx] == NULLP)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceQueryIEs failed");
+ memAllocFailed = true;
+ break;
+ }
+ }
+ if(memAllocFailed == true)
+ {
+ DU_LOG("\nERROR --> E2AP : Memory allocation for ricServiceQueryIEs failed");
+ break;
+ }
+
+ /* Trans Id */
+ arrIdx = 0;
+ ricServiceQuery->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_TransactionID;
+ ricServiceQuery->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ ricServiceQuery->protocolIEs.list.array[arrIdx]->value.present = RICserviceQuery_IEs__value_PR_TransactionID;
+ ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.TransactionID = assignTransactionId(duDb);
+
+ if(duDb->numOfRanFunction)
+ {
+ /* Accepted RAN function Id */
+ arrIdx++;
+ ricServiceQuery->protocolIEs.list.array[arrIdx]->id = ProtocolIE_IDE2_id_RANfunctionsAccepted;
+ ricServiceQuery->protocolIEs.list.array[arrIdx]->criticality = CriticalityE2_reject;
+ ricServiceQuery->protocolIEs.list.array[arrIdx]->value.present = RICserviceQuery_IEs__value_PR_RANfunctionsID_List;
+ if(BuildRanFunctionAddedList(duDb, 0, NULL, &ricServiceQuery->protocolIEs.list.array[arrIdx]->value.choice.RANfunctionsID_List, ProcedureCodeE2_id_RICserviceQuery)!=ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Failed to build Ran function added list");
+ break;
+ }
+ }
+
+ 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);
+
+ /* Check encode results */
+ if(encRetVal.encoded == ENCODE_FAIL)
+ {
+ DU_LOG("\nERROR --> E2AP : Could not encode RIC service Query structure (at %s)\n",\
+ encRetVal.failed_type ? encRetVal.failed_type->name : "unknown");
+ break;
+ }
+ else
+ {
+ DU_LOG("\nDEBUG --> E2AP : Created APER encoded buffer for RIC service Query\n");
+ for(int i=0; i< encBufSize; i++)
+ {
+ DU_LOG("%x",encBuf[i]);
+ }
+ }
+
+ if(SendE2APMsg(RIC_APP_MEM_REG, RIC_POOL, duDb->duId) != ROK)
+ {
+ DU_LOG("\nERROR --> E2AP : Sending of RIC service Query failed");
+ break;
+ }
+
+ ret =ROK;
+ break;
+ }
+ FreeRicServiceQuery(e2apMsg);
+ return ret;
+}
+