[Epic-Id: ODUHIGH-576][Task-Id: ODUHIGH-594][SubTask-Id: ODUHIGH-616 | NFAPI_BRANCH... 81/13181/3
authorsvaidhya <svaidhya@radisys.com>
Wed, 17 Jul 2024 10:16:23 +0000 (15:46 +0530)
committersvaidhya <svaidhya@radisys.com>
Thu, 18 Jul 2024 09:09:36 +0000 (14:39 +0530)
Change-Id: Id1c8e7f8109f9fa14b225faf953c044f41e30444
Signed-off-by: svaidhya <svaidhya@radisys.com>
src/5gnrmac/mac_demux.c
src/5gnrmac/nfapi_p7_msg_hdl.c
src/intel_fapi/nfapi_interface.h
src/pnf_stub/pnf_stub.h
src/pnf_stub/pnf_stub_p7_msg_hdl.c
src/pnf_stub/pnf_stub_p7_udp.c

index 237cf71..d6ec611 100644 (file)
@@ -90,6 +90,7 @@ uint8_t unpackRxData(uint16_t cellId, SlotTimingInfo slotInfo, RxDataIndPdu *rxD
       {
          case MAC_LCID_CCCH :
             {
+               DU_LOG("INFO   --> MAC: LCID_CCH");
                pduLen--;
 
                /* for UL CCCH,fixed length of MAC SDU */
index 353717c..8edcce7 100644 (file)
@@ -832,6 +832,247 @@ uint8_t nfapiP7ProcRachInd(Buffer *mBuf)
     return ret;
 }
 
+/*******************************************************************
+ *
+ * @brief Build And Sends Crc indication to MAC
+ *
+ * @details
+ *
+ *    Function : nfapiSendCrcIndToMac
+ *
+ *    Functionality:
+ *      Builds and Sends EVENT_CRC_IND to MAC
+ *
+ * @params[in] fapi_crc_indication_t message pointer
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t nfapiSendCrcIndToMac(fapi_crc_ind_msg_body *nfapiCrcInd)
+{
+   Pst          pst;
+   uint8_t      crcInfoIdx = 0;
+   uint8_t      crcStatusIdx, ret = ROK;
+   CrcInfo      *crcIndInfo = NULLP;
+   CrcInd       *crcInd = NULLP;
+
+   MAC_ALLOC_SHRABL_BUF(crcInd, sizeof(CrcInd));
+   if(!crcInd)
+   {
+      DU_LOG("ERROR  -->  NFAPI_VNF : Memory Allocation failed in nfapiSendCrcIndToMac");
+      return RFAILED;
+   }
+
+   crcInd->cellId = vnfDb.cellId;
+   crcInd->timingInfo.sfn = nfapiCrcInd->sfn;
+   crcInd->timingInfo.slot = nfapiCrcInd->slot;
+   crcInd->numCrc = nfapiCrcInd->numCrcs;
+
+   for(crcInfoIdx = 0; crcInfoIdx < crcInd->numCrc; crcInfoIdx++)
+   {
+      crcIndInfo = &crcInd->crcInfo[crcInfoIdx];
+      crcIndInfo->handle      = nfapiCrcInd->crc[crcInfoIdx].handle;
+      crcIndInfo->rnti        = nfapiCrcInd->crc[crcInfoIdx].rnti;
+      crcIndInfo->harqId      = nfapiCrcInd->crc[crcInfoIdx].harqId;
+      crcIndInfo->tbCrcStatus = nfapiCrcInd->crc[crcInfoIdx].tbCrcStatus;
+      crcIndInfo->numCb       = nfapiCrcInd->crc[crcInfoIdx].numCb;
+      for(crcStatusIdx = 0; crcStatusIdx < crcIndInfo->numCb; crcStatusIdx++)
+      {
+             crcIndInfo->cbCrcStatus[crcStatusIdx] = \
+                nfapiCrcInd->crc[crcInfoIdx].cbCrcStatus[crcStatusIdx];
+      }
+      crcIndInfo->ul_cqi  = nfapiCrcInd->crc[crcInfoIdx].ul_cqi;
+      crcIndInfo->timingAdvance = nfapiCrcInd->crc[crcInfoIdx].timingAdvance;
+      crcIndInfo->rssi = nfapiCrcInd->crc[crcInfoIdx].rssi;
+   }
+
+   /* Fill post and sent to MAC */
+   FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_CRC_IND_TO_MAC);
+   pst.selector = ODU_SELECTOR_LWLC;
+   ret = packCrcInd(&pst, crcInd);
+   return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Process FAPI_CRC_IND from PNF
+ *
+ * @details
+ *
+ *    Function : nfapiP7ProcCrcInd
+ *
+ *    Functionality:
+ *           Processes FAPI_CRC_IND received from PNF
+ *           Parametes can be referred from SCF222v2222.10.03, Sec 3.4.8
+ *
+ * @params[in] UDP Buffer 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t nfapiP7ProcCrcInd(Buffer *mBuf)
+{
+    uint8_t crcCnt = 0, cbCnt = 0, ret = ROK;
+    fapi_crc_ind_msg_body  nfapiCrcInd;
+
+    CMCHKPK(oduUnpackUInt16, &(nfapiCrcInd.sfn), mBuf); 
+    CMCHKPK(oduUnpackUInt16, &(nfapiCrcInd.slot), mBuf); 
+    CMCHKPK(oduUnpackUInt16, &(nfapiCrcInd.numCrcs), mBuf);
+
+    for(crcCnt = 0; crcCnt < nfapiCrcInd.numCrcs; crcCnt++)
+    {
+       CMCHKPK(oduUnpackUInt32, &(nfapiCrcInd.crc[crcCnt].handle), mBuf);
+       CMCHKPK(oduUnpackUInt16, &(nfapiCrcInd.crc[crcCnt].rnti), mBuf);
+       CMCHKPK(oduUnpackUInt8,  &(nfapiCrcInd.crc[crcCnt].harqId), mBuf);
+       CMCHKPK(oduUnpackUInt8,  &(nfapiCrcInd.crc[crcCnt].tbCrcStatus), mBuf);
+       CMCHKPK(oduUnpackUInt8,  &(nfapiCrcInd.crc[crcCnt].ul_cqi), mBuf);
+       CMCHKPK(oduUnpackUInt8,  &(nfapiCrcInd.crc[crcCnt].pad), mBuf);
+       CMCHKPK(oduUnpackUInt16,  &(nfapiCrcInd.crc[crcCnt].numCb), mBuf);
+       CMCHKPK(oduUnpackUInt16,  &(nfapiCrcInd.crc[crcCnt].timingAdvance), mBuf);
+       CMCHKPK(oduUnpackUInt16,  &(nfapiCrcInd.crc[crcCnt].rssi), mBuf);
+
+       for(cbCnt = 0; cbCnt < nfapiCrcInd.crc[crcCnt].numCb; cbCnt++)
+       {
+          CMCHKPK(oduUnpackUInt8,  &(nfapiCrcInd.crc[crcCnt].cbCrcStatus[cbCnt]), mBuf);
+       }
+    }
+    ret = nfapiSendCrcIndToMac(&nfapiCrcInd);
+    return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Build And Sends Rx Data indication to MAC
+ *
+ * @details
+ *
+ *    Function : nfapiSendRxDataIndToMac
+ *
+ *    Functionality:
+ *      Builds and Sends EVENT_RX_DATA_IND to MAC
+ *
+ * @params[in] fapi_rx_data_indication_t message pointer
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t nfapiSendRxDataIndToMac(fapi_rx_data_ind_msg_body *nfapiRxDataInd)
+{
+   Pst           pst;
+   uint8_t       pduIdx = 0, ret = ROK;
+   RxDataInd     *rxDataInd = NULLP;
+   RxDataIndPdu  *pdu = NULLP;   
+
+   MAC_ALLOC_SHRABL_BUF(rxDataInd, sizeof(RxDataInd));
+   if(!rxDataInd)
+   {
+      DU_LOG("ERROR  -->  NFAPI_VNF : Memory Allocation failed in nfapiSendRxDataIndToMac");
+      return RFAILED;
+   }
+
+   rxDataInd->cellId = vnfDb.cellId;
+   rxDataInd->timingInfo.sfn = nfapiRxDataInd->sfn; 
+   rxDataInd->timingInfo.slot = nfapiRxDataInd->slot;
+   rxDataInd->numPdus = nfapiRxDataInd->numPdus;
+
+   for(pduIdx = 0; pduIdx < rxDataInd->numPdus; pduIdx++)
+   {
+      pdu = &rxDataInd->pdus[pduIdx];
+      pdu->handle = nfapiRxDataInd->pdus[pduIdx].handle;
+      pdu->rnti = nfapiRxDataInd->pdus[pduIdx].rnti;
+      pdu->harqId = nfapiRxDataInd->pdus[pduIdx].harqId;
+      pdu->pduLength = nfapiRxDataInd->pdus[pduIdx].pdu_length;
+      pdu->ul_cqi = nfapiRxDataInd->pdus[pduIdx].ul_cqi;
+      pdu->timingAdvance = nfapiRxDataInd->pdus[pduIdx].timingAdvance;
+      pdu->rssi = nfapiRxDataInd->pdus[pduIdx].rssi;
+
+      MAC_ALLOC_SHRABL_BUF(pdu->pduData, pdu->pduLength);
+      if(pdu->pduData == NULLP)
+      {
+         DU_LOG("ERROR  -->  NFAPI_VNF : Memory Allocation failed in nfapiSendRxDataIndToMac");
+         MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, rxDataInd, sizeof(RxDataInd));
+         return RFAILED;
+      }
+      memcpy(pdu->pduData, nfapiRxDataInd->pdus[pduIdx].pduData, pdu->pduLength);
+   }
+
+   /* Fill post and sent to MAC */
+   FILL_PST_LWR_MAC_TO_MAC(pst, EVENT_RX_DATA_IND_TO_MAC);
+   pst.selector = ODU_SELECTOR_LWLC;
+   ret = packRxDataInd(&pst, rxDataInd);
+   return ret;
+}
+
+
+/*******************************************************************
+ *
+ * @brief Process FAPI_RX_DATA_IND from PNF
+ *
+ * @details
+ *
+ *    Function : nfapiP7ProcRxDataInd
+ *
+ *    Functionality:
+ *           Processes FAPI_RX_DATA_IND received from PNF
+ *           Parametes can be referred from SCF222v2222.10.03, Sec 3.4.7
+ *
+ * @params[in] UDP Buffer 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t nfapiP7ProcRxDataInd(Buffer *mBuf)
+{
+    uint8_t pduCnt = 0, ret = ROK;
+    uint16_t byteIdx = 0;
+    fapi_rx_data_ind_msg_body  nfapiRxDataInd;
+
+    CMCHKPK(oduUnpackUInt16, &(nfapiRxDataInd.sfn), mBuf); 
+    CMCHKPK(oduUnpackUInt16, &(nfapiRxDataInd.slot), mBuf); 
+    CMCHKPK(oduUnpackUInt16, &(nfapiRxDataInd.numPdus), mBuf);
+
+    //Extract fapi_pdu_ind_info_t
+    for(pduCnt = 0; pduCnt < nfapiRxDataInd.numPdus; pduCnt++)
+    {
+       CMCHKPK(oduUnpackUInt32, &(nfapiRxDataInd.pdus[pduCnt].handle), mBuf); 
+       CMCHKPK(oduUnpackUInt16, &(nfapiRxDataInd.pdus[pduCnt].rnti), mBuf); 
+       CMCHKPK(oduUnpackUInt8, &(nfapiRxDataInd.pdus[pduCnt].harqId), mBuf); 
+       CMCHKPK(oduUnpackUInt8, &(nfapiRxDataInd.pdus[pduCnt].ul_cqi), mBuf); 
+       CMCHKPK(oduUnpackUInt16, &(nfapiRxDataInd.pdus[pduCnt].timingAdvance), mBuf); 
+       CMCHKPK(oduUnpackUInt16, &(nfapiRxDataInd.pdus[pduCnt].rssi), mBuf);
+       CMCHKPK(oduUnpackUInt16, &(nfapiRxDataInd.pdus[pduCnt].pdu_length), mBuf);
+       CMCHKPK(oduUnpackUInt8, &(nfapiRxDataInd.pdus[pduCnt].pad[0]), mBuf);
+       CMCHKPK(oduUnpackUInt8, &(nfapiRxDataInd.pdus[pduCnt].pad[1]), mBuf);
+
+       MAC_ALLOC(nfapiRxDataInd.pdus[pduCnt].pduData, nfapiRxDataInd.pdus[pduCnt].pdu_length);   
+       if(nfapiRxDataInd.pdus[pduCnt].pduData == NULLP)
+       {
+          DU_LOG("ERROR  --> NFAPI_VNF: Memory Allocation failed in nfapiP7ProcRxDataInd()");
+          while(pduCnt != 0)
+          {
+             pduCnt--;
+             MAC_FREE(nfapiRxDataInd.pdus[pduCnt].pduData, nfapiRxDataInd.pdus[pduCnt].pdu_length);
+          }
+          return RFAILED;
+       }
+       for(byteIdx = 0; byteIdx < nfapiRxDataInd.pdus[pduCnt].pdu_length; byteIdx++)
+       {
+          CMCHKPK(oduUnpackUInt8, &(nfapiRxDataInd.pdus[pduCnt].pduData[byteIdx]), mBuf);
+       }
+    }
+
+    ret = nfapiSendRxDataIndToMac(&nfapiRxDataInd);
+    for(pduCnt = 0; pduCnt < nfapiRxDataInd.numPdus; pduCnt++)
+    {
+       MAC_FREE(nfapiRxDataInd.pdus[pduCnt].pduData, nfapiRxDataInd.pdus[pduCnt].pdu_length);
+    }
+    return ret;
+}
+
 /*******************************************************************
  *
  * @brief Processed the NFAPI P7 message from UDP socket 
@@ -872,13 +1113,24 @@ uint8_t nfapiP7MsgHandler(Buffer *mBuf)
          nfapiP7ProcRachInd(mBuf);
          break;
       }
+      case FAPI_CRC_INDICATION:
+      {
+         DU_LOG("INFO  --> NFAPI_VNF: Received CRC INDICATIOn");
+         nfapiP7ProcCrcInd(mBuf);
+         break;
+      }
+      case FAPI_RX_DATA_INDICATION:
+      {
+         DU_LOG("INFO  --> NFAPI_VNF: Received RX DATA INDICATIOn");
+         nfapiP7ProcRxDataInd(mBuf);
+         break;
+      }
       default:
       {
          DU_LOG("ERROR --> NFAPI_VNF: Wrong MsgId:%d", msgHdr.msg_id);
          return RFAILED;
       }
    }
-
    return ROK;
 }
 
index 938a798..a327773 100644 (file)
@@ -358,7 +358,6 @@ typedef struct fapi_ul_dci_req_msg_body_t{
    uint16_t sfn;
    uint16_t slot;
    uint8_t numPdus;
-   uint8_t pad[3];
    fapi_dci_pdu_t pdus[FAPI_MAX_NUMBER_UCI_PDUS_PER_SLOT]; // 5G FAPI Table 3-54
 }fapi_ul_dci_req_msg_body;
 
@@ -372,7 +371,6 @@ typedef struct fapi_tx_data_req_msg_body_t{
    uint16_t sfn;
    uint16_t slot;
    uint16_t num_pdus;
-   uint8_t pad[2];
    fapi_tx_pdu_desc_t pdu_desc[FAPI_MAX_NUMBER_DL_PDUS_PER_TTI];   // 5G FAPI Table 3-58
 }fapi_tx_data_req_msg_body;
 
@@ -386,7 +384,6 @@ typedef struct fapi_rx_data_ind_msg_body_t{
    uint16_t sfn;
    uint16_t slot;
    uint16_t numPdus;
-   uint8_t pad[2];
    fapi_pdu_ind_info_t pdus[FAPI_MAX_NUMBER_OF_ULSCH_PDUS_PER_SLOT];   // 5G FAPI Table 3-61
 }fapi_rx_data_ind_msg_body;
 
@@ -400,7 +397,6 @@ typedef struct fapi_crc_ind_msg_body_t{
    uint16_t sfn;
    uint16_t slot;
    uint16_t numCrcs;
-   uint8_t pad[2];
    fapi_crc_ind_info_t crc[FAPI_MAX_NUMBER_OF_CRCS_PER_SLOT];  // 5G FAPI Table 3-62
 }fapi_crc_ind_msg_body;
 
@@ -414,7 +410,6 @@ typedef struct fapi_uci_ind_msg_body_t{
    uint16_t sfn;
    uint16_t slot;
    uint16_t numUcis;       // 5G FAPI Table 3-63
-   uint8_t pad[2];
    fapi_uci_pdu_info_t uciPdu[FAPI_MAX_NUMBER_UCI_PDUS_PER_SLOT];
 }fapi_uci_ind_msg_body;
 
@@ -428,7 +423,6 @@ typedef struct fapi_srs_ind_msg_body_t{
    uint16_t sfn;
    uint16_t slot;
    uint8_t numPdus;
-   uint8_t pad[3];
    fapi_srs_pdu_t srsPdus[FAPI_MAX_NUMBER_SRS_PDUS_PER_SLOT];  // 5G FAPI Table 3-73
 }fapi_srs_ind_msg_body;
 
index b543030..36a87fc 100644 (file)
@@ -92,6 +92,18 @@ typedef enum
    PNF_RUNNING
 }PnfState;
 
+typedef enum
+{
+   MSG_TYPE_MSG3,
+   MSG_TYPE_SHORT_BSR,
+   MSG_TYPE_MSG5,
+   MSG_TYPE_NAS_AUTHENTICATION_COMPLETE,
+   MSG_TYPE_NAS_SECURITY_MODE_COMPLETE,
+   MSG_TYPE_RRC_SECURITY_MODE_COMPLETE,
+   MSG_TYPE_REGISTRATION_COMPLETE,
+   MSG_TYPE_RRC_RECONFIG_COMPLETE
+}PnfMsgType;
+
 typedef struct pnfCfgParams
 {
    PnfState          pnfState;
@@ -143,6 +155,7 @@ typedef struct pnfGlobalCb
 }PnfGlobalCb;
 
 PnfGlobalCb pnfCb;
+
 uint8_t p5MsgHandlerAtPnf(Buffer *mBuf);
 void nfapiFillP5Hdr(Buffer *mBuf);
 void nfapiFillMsgHdr(Buffer *mBuf, uint8_t phyId, uint16_t msgId, uint32_t msgLen);
index 0006795..5f3c9b0 100644 (file)
@@ -259,6 +259,439 @@ uint8_t pnfBuildAndSendRachInd(uint16_t slot, uint16_t sfn, uint8_t raPreambleId
    return ROK;
 }
 
+/*******************************************************************
+ *
+ * @brief Build and Send CRC Indication
+ *
+ * @details
+ *
+ *    Function : pnfBuildAndSendCrcInd
+ *
+ *    Functionality:
+ *      Build and Send CRC Indication
+ *
+ * @params[in] Slot
+ *             SFN 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+uint16_t pnfBuildAndSendCrcInd(uint16_t slot, uint16_t sfn, fapi_ul_pusch_pdu_t puschPdu)
+{
+   Buffer *mBuf       = NULLP;
+   uint8_t numCrc = 0, ret = ROK;
+   static uint8_t ind = 0;
+
+   uint8_t result[]={0,//MSG3
+                     0,//BSR
+                     0,//MSG5 RRC Setup Complete
+                     0,//Security Mode Complete
+                     0,//Registraion Complete
+                     0,//RRC Reconfiguration Complete
+                     0,//UL DATA -1
+                     0,//UL DATA -2
+                     0,//UL DATA -3
+                     0,//UL DATA -4
+                     0,0,0,0,0,
+                     0,0,0,0,0,
+                     0,0,0,0,0,
+                     0,0,0,0,0,
+                     0,0,0,0,0,
+                     0,0,0,0,0,
+                     0,0,0,0,0,
+                     0,0,0,0,0,
+                     0,0,0,0,0,
+                     0,0,0,0,0,
+                     0,0,0,0,0,
+                     0,0,0,0,0,
+                     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+
+   if (ODU_GET_MSG_BUF(PNF_APP_MEM_REG, PNF_POOL, &mBuf) != ROK)
+   {
+      DU_LOG("ERROR  --> NFAPI_PNF : Memory allocation failed in pnfBuildAndSendCrcInd()");
+      return RFAILED;
+   }
+   nfapiFillP7Hdr(mBuf, (sizeof(fapi_crc_ind_msg_body) + sizeof(nFapi_msg_header)), 0, 0);
+   nfapiFillMsgHdr(mBuf, 1, FAPI_CRC_INDICATION, sizeof(fapi_crc_ind_msg_body));
+
+   //Fill fapi_crc_ind_msg_body
+   CMCHKPK(oduPackPostUInt16, sfn, mBuf);
+   CMCHKPK(oduPackPostUInt16, slot, mBuf);
+   CMCHKPK(oduPackPostUInt16, 1, mBuf); //numCrcs
+
+    numCrc = 1;
+   //Fill fapi_crc_ind_info_t
+   while(numCrc != 0)
+   {
+      CMCHKPK(oduPackPostUInt32, puschPdu.handle, mBuf); //handle
+      CMCHKPK(oduPackPostUInt16, puschPdu.rnti, mBuf); //rnti
+      CMCHKPK(oduPackPostUInt8, puschPdu.puschData.harqProcessId, mBuf); //rnti
+      CMCHKPK(oduPackPostUInt8, 0, mBuf); //tbCrcStatus
+      CMCHKPK(oduPackPostUInt8, 0, mBuf); //ul_cqi
+      CMCHKPK(oduPackPostUInt8, 0, mBuf); //pad
+      CMCHKPK(oduPackPostUInt16, 1, mBuf); //numCb
+      CMCHKPK(oduPackPostUInt16, 0, mBuf); //timingAdvance
+      CMCHKPK(oduPackPostUInt16, 0, mBuf); //rssi
+
+      //cbCrcStatus[0]
+      CMCHKPK(oduPackPostUInt8, result[ind % sizeof(result)], mBuf);
+
+      ret = (result[ind%sizeof(result)] == 0) ? ROK:RFAILED;
+      ind++;
+      numCrc--;
+   }
+   /* Sending CRC indication to VNF */
+   DU_LOG("INFO   -->  NFAPI_PNF: Sending CRC Indication to VNF");
+   if(pnfP7UdpSendMsg(mBuf) != ROK)
+   { 
+      DU_LOG("ERROR  -->  NFAPI_PNF: UDP Send Failed for CRC Indication to VNF");
+      return RFAILED;
+   }
+   return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Build and send Rx data indication
+ *
+ * @details
+ *
+ *    Function : pnfBuildAndSendRxDataInd
+ *
+ *    Functionality:
+ *       Build and send Rx data indication
+ *
+ * @params[in] SFN
+ *             Slot
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+uint16_t pnfBuildAndSendRxDataInd(uint16_t slot, uint16_t sfn, fapi_ul_pusch_pdu_t puschPdu)
+{
+   uint8_t idx = 0, ueId = 0;
+   fapi_rx_data_indication_t *rxDataInd =NULLP;
+   fapi_pdu_ind_info_t       *pduInfo =NULLP;
+   uint8_t  *pdu = NULLP;
+   uint16_t byteIdx = 0;
+   PnfMsgType type = 0;
+   Buffer *mBuf = NULLP;
+
+   GET_UE_ID(puschPdu.rnti, ueId);
+   if(pnfCb.pnfUeCb[ueId-1].isCFRA)
+   {
+      if(!pnfCb.pnfUeCb[ueId-1].msgRrcReconfigComp)
+      {
+         /* In CF-RA in case of handover, RRC Reconfiguration Complete is sent
+          * by UE once RAR is received from DU */
+         pnfCb.pnfUeCb[ueId-1].ueId = ueId;
+         pnfCb.pnfUeCb[ueId-1].crnti = puschPdu.rnti;
+         pnfCb.pnfUeCb[ueId-1].msgRrcReconfigComp = true;
+         type = MSG_TYPE_RRC_RECONFIG_COMPLETE;
+      }
+      else
+         return ROK; 
+   }
+   else
+   {
+      if(!pnfCb.pnfUeCb[ueId-1].msg3Sent)
+      {
+         pnfCb.pnfUeCb[ueId-1].ueId = ueId;
+         pnfCb.pnfUeCb[ueId-1].crnti = puschPdu.rnti;
+         pnfCb.pnfUeCb[ueId-1].msg3Sent = true;
+         type = MSG_TYPE_MSG3;
+         sleep(1);
+      }
+      else if(!pnfCb.pnfUeCb[ueId-1].msg5ShortBsrSent)
+      {
+         pnfCb.pnfUeCb[ueId-1].msg5ShortBsrSent = true;
+         type = MSG_TYPE_SHORT_BSR;
+      }
+      else if(!pnfCb.pnfUeCb[ueId-1].msg5Sent)
+      {
+         pnfCb.pnfUeCb[ueId-1].msg5Sent = true;
+         type = MSG_TYPE_MSG5;
+      }
+      else if(!pnfCb.pnfUeCb[ueId-1].msgNasAuthenticationComp)
+      {
+        pnfCb.pnfUeCb[ueId-1].msgNasAuthenticationComp = true;
+        type = MSG_TYPE_NAS_AUTHENTICATION_COMPLETE;
+      }
+      else if(!pnfCb.pnfUeCb[ueId-1].msgNasSecurityModeComp)
+      {
+         pnfCb.pnfUeCb[ueId-1].msgNasSecurityModeComp = true;
+         type = MSG_TYPE_NAS_SECURITY_MODE_COMPLETE;
+      }
+      else if(!pnfCb.pnfUeCb[ueId-1].msgRrcSecurityModeComp)
+      {
+         pnfCb.pnfUeCb[ueId-1].msgRrcSecurityModeComp = true;
+         type = MSG_TYPE_RRC_SECURITY_MODE_COMPLETE;
+      }
+      else if(!pnfCb.pnfUeCb[ueId-1].msgRegistrationComp)
+      {
+         pnfCb.pnfUeCb[ueId-1].msgRegistrationComp = true;
+         type = MSG_TYPE_REGISTRATION_COMPLETE; 
+      }
+      else if(!pnfCb.pnfUeCb[ueId-1].msgRrcReconfigComp)
+      {
+         pnfCb.pnfUeCb[ueId-1].msgRrcReconfigComp = true;
+         type = MSG_TYPE_RRC_RECONFIG_COMPLETE;
+      }
+      else
+         return ROK;
+   }
+
+   if (ODU_GET_MSG_BUF(PNF_APP_MEM_REG, PNF_POOL, &mBuf) != ROK)
+   {
+      DU_LOG("ERROR  --> NFAPI_PNF : Memory allocation failed in pnfBuildAndSendRxDataInd");
+      return RFAILED;
+   }
+   nfapiFillP7Hdr(mBuf, (sizeof(fapi_rx_data_ind_msg_body) + sizeof(nFapi_msg_header)), 0, 0);
+   nfapiFillMsgHdr(mBuf, 1, FAPI_RX_DATA_INDICATION, (sizeof(fapi_rx_data_ind_msg_body) + puschPdu.puschData.tbSize));
+
+   CMCHKPK(oduPackPostUInt16, sfn, mBuf);
+   CMCHKPK(oduPackPostUInt16, slot, mBuf);
+   CMCHKPK(oduPackPostUInt16, 1, mBuf);
+   
+   //Fill fapi_pdu_ind_info_t
+   CMCHKPK(oduPackPostUInt32, puschPdu.handle, mBuf); 
+   CMCHKPK(oduPackPostUInt16, puschPdu.rnti, mBuf); 
+   CMCHKPK(oduPackPostUInt8, puschPdu.puschData.harqProcessId, mBuf); 
+   CMCHKPK(oduPackPostUInt8, 0, mBuf); //ul_cqi
+   CMCHKPK(oduPackPostUInt16, 0, mBuf); //timingAdvance
+   CMCHKPK(oduPackPostUInt16, 0, mBuf); //rssi
+   CMCHKPK(oduPackPostUInt16, puschPdu.puschData.tbSize, mBuf);//pdu_length
+   CMCHKPK(oduPackPostUInt8, 0, mBuf);//pad[0]
+   CMCHKPK(oduPackPostUInt8, 0, mBuf);//pad[1]
+
+   switch(type)
+   {
+      case MSG_TYPE_MSG3: 
+         {
+            DU_LOG("DEBUG  -->  NFAPI_PNF: Forming MSG3 PDU ");
+            /* For Initial RRC setup Request,
+               MAC subheader format is R/R/LCId (1byte)
+               LCId is CCCH(0)
+               From 38.321 section 6.1.1
+               */
+            CMCHKPK(oduPackPostUInt8, 0, mBuf); //LCID = CCCH
+            byteIdx++;
+            /* Hardcoding MAC PDU */
+            CMCHKPK(oduPackPostUInt8, 16, mBuf);
+            byteIdx++;
+            CMCHKPK(oduPackPostUInt8, 0, mBuf);
+            byteIdx++;
+            CMCHKPK(oduPackPostUInt8, 0, mBuf);
+            byteIdx++;
+            CMCHKPK(oduPackPostUInt8, 0, mBuf);
+            byteIdx++;
+            CMCHKPK(oduPackPostUInt8, 0, mBuf);
+            byteIdx++;
+            CMCHKPK(oduPackPostUInt8, 103, mBuf);
+            byteIdx++;
+            break;
+         }
+#if 0
+      case MSG_TYPE_SHORT_BSR:
+         {
+            DU_LOG("DEBUG  -->  NFAPI_PNF: Forming SHORT BSR PDU ");
+            uint8_t lcgId = 1;
+            uint8_t bufferSizeIdx = 6;
+
+            /* For Short BSR
+               MAC subheader format is R/R/LcId (1Byte)
+               LCId is 61
+               From 38.321 section 6.1.1
+               */
+            CMCHKPK(oduPackPostUInt8, 61, mBuf); //LCID = 61
+            byteIdx++;
+            CMCHKPK(oduPackPostUInt8, (lcgId << 5) | bufferSizeIdx, mBuf); //LCG_ID and BufferSize
+            byteIdx++;
+
+            break;
+         }
+
+      case MSG_TYPE_MSG5:
+      {
+         /* For RRC setup complete
+          *
+          * MAC subheader format is R/F/LCId/L (2/3 bytes)
+          * LCId is 1 for SRB1
+          * L is length of PDU i.e 6bytes here 
+          * From 38.321 section 6.1.1
+          *
+          * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
+          * From 38.322, section 6.2.2.4
+          */
+         DU_LOG("DEBUG  -->  PHY_STUB: Forming MSG5 PDU");
+         uint8_t  msg5PduLen = 33; /* Length of MSG5 */
+         msg5PduLen += 2; /* RLC subheader */
+         uint8_t msg5[] = {1, msg5PduLen, 128, pnfCb.pnfUeCb[ueId-1].rlcSnForSrb1++, 0, pnfCb.pnfUeCb[ueId-1].pdcpSn++, 16, 0, \
+            5, 223, 128, 16, 94, 64, 3, 64, 68, 252, 97, 0, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, 184, 56, 0, 0, 0, 0, 0};
+
+         msg5PduLen += 2;  /* 2 bytes of MAC header */
+         memcpy(pdu, &msg5, msg5PduLen);
+         byteIdx += msg5PduLen; /* 4 bytes of header : MAC+RLC */
+         break;
+      }
+
+      case MSG_TYPE_NAS_AUTHENTICATION_COMPLETE:
+      {
+        /* For Authentication response where RRC Container is dummy
+          *
+          * MAC subheader format is R/F/LCId/L (2/3 bytes)
+          * LCId is 1 for SRB1
+          * L is length of PDU i.e 6bytes here 
+          * From 38.321 section 6.1.1
+          *
+          * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
+          * From 38.322, section 6.2.2.4
+          */
+         DU_LOG("DEBUG  -->  PHY_STUB: Forming AUTHENTICATION RESPONSE PDU");
+         uint8_t  pduLen = 37; /* Length of PDU */
+         pduLen += 2; /* RLC subheader */
+         uint8_t msg[] = {1, pduLen, 128, pnfCb.pnfUeCb[ueId-1].rlcSnForSrb1++, 0, pnfCb.pnfUeCb[ueId-1].pdcpSn++, 0x3a, \
+                          0x0e, 0x3f, 0x00, 0xca, 0x95, 0xe9, 0x19, 0x41, 0x3f, 0x00, 0x2b, 0x96, 0x88, 0x06, 0xd7, 0x16, 0xc6, \
+                          0x8b, 0xea, 0xae, 0x45, 0xd1, 0x01, 0xfd, 0x34, 0xd4, 0xfd, 0xd5, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+         pduLen += 2;  /* 2 bytes of MAC header */
+         memcpy(pdu, &msg, pduLen);
+         byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
+         break;
+      }
+      
+      case MSG_TYPE_NAS_SECURITY_MODE_COMPLETE:
+      {
+        /* For NAS security mode complete where RRC Container is dummy
+          *
+          * MAC subheader format is R/F/LCId/L (2/3 bytes)
+          * LCId is 1 for SRB1
+          * L is length of PDU i.e 6bytes here 
+          * From 38.321 section 6.1.1
+          *
+          * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
+          * From 38.322, section 6.2.2.4
+          */
+         DU_LOG("DEBUG  -->  PHY_STUB: Forming NAS SECURITY MODE COMPLETE PDU");
+         uint8_t  pduLen = 93; /* Length of PDU */
+         pduLen += 2; /* RLC subheader */
+         uint8_t msg[] = {1, pduLen, 128, pnfCb.pnfUeCb[ueId-1].rlcSnForSrb1++, 0, pnfCb.pnfUeCb[ueId-1].pdcpSn++, 0x3a, 0x2a, 0x3f, 
+                          0x02, 0x75, 0xa0, 0xa0, 0xc0, 0x80, 0x3f, 0x00, 0x2f, 0x3b, 0x80, 0x04, 0x9a, 0xa2, 0x81, 0x09, 0x80, 0xc0, 
+                          0x28, 0x04, 0xf8, 0xb8, 0x80, 0x1d, 0xbf, 0x00, 0x20, 0x8c, 0x80, 0x05, 0xf9, 0x00, 0x78, 0x88, 0x7a, 0x88, 
+                          0xd9, 0x00, 0x00, 0x00, 0x03, 0x08, 0x00, 0x81, 0x97, 0x02, 0x78, 0x38, 0x78, 0x38, 0x17, 0x82, 0x82, 0x00, 
+                          0x80, 0x00, 0x00, 0xa9, 0x00, 0x78, 0x88, 0x00, 0x00, 0x00, 0x8b, 0x83, 0xf8, 0x38, 0x60, 0x20, 0x0c, 0xc0, 
+                          0x50, 0x0c, 0x00, 0x80, 0x3a, 0x00, 0x00, 0x48, 0x29, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00};
+
+         pduLen += 2;  /* 2 bytes of MAC header */
+         memcpy(pdu, &msg, pduLen);
+         byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
+         break;
+      }
+
+      case MSG_TYPE_RRC_SECURITY_MODE_COMPLETE:
+      {
+         /* For security mode complete where RRC Container is dummy
+          *
+          * MAC subheader format is R/F/LCId/L (2/3 bytes)
+          * LCId is 1 for SRB1
+          * L is length of PDU i.e 6bytes here 
+          * From 38.321 section 6.1.1
+          *
+          * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
+          * From 38.322, section 6.2.2.4
+          */
+         DU_LOG("DEBUG  -->  PHY_STUB: Forming RRC SECURITY MODE COMPLETE PDU");
+         uint8_t  pduLen = 12; /* Length of PDU */
+         pduLen += 2; /* RLC subheader */
+         uint8_t msg[] = {1, pduLen, 128, pnfCb.pnfUeCb[ueId-1].rlcSnForSrb1++, 0, pnfCb.pnfUeCb[ueId-1].pdcpSn++, 0x2a, 0x40, \
+            0, 0, 0, 0, 0, 0, 0, 0};
+
+         pduLen += 2;  /* 2 bytes of MAC header */
+         memcpy(pdu, &msg, pduLen);
+         byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
+         break;
+      }
+
+      case MSG_TYPE_REGISTRATION_COMPLETE:
+      {
+         /* For rrc reconfig complete where RRC Container is dummy
+          *
+          * MAC subheader format is R/F/LCId/L (2/3 bytes)
+          * LCId is 1 for SRB1
+          * L is length of PDU i.e 6bytes here
+          * From 38.321 section 6.1.1
+          * 
+          * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
+          * From 38.322, section 6.2.2.4
+          */
+         DU_LOG("DEBUG  -->  PHY_STUB: Forming RRC REGISTRATION COMPLETE PDU");
+         uint8_t  pduLen = 12; /* Length of PDU */
+         pduLen += 2; /* RLC subheader */
+         uint8_t msg[] = {1, pduLen, 128, pnfCb.pnfUeCb[ueId-1].rlcSnForSrb1++, 0, pnfCb.pnfUeCb[ueId-1].pdcpSn++, 0x3a, 0x81, \
+            0xbf, 0, 0x21, 0x80, 0, 0, 0, 0};
+
+         pduLen += 2;  /* 2 bytes of MAC header */
+         memcpy(pdu, &msg, pduLen);
+         byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
+         break;
+      }
+
+      case MSG_TYPE_RRC_RECONFIG_COMPLETE:
+      {
+         /* For rrc reconfig complete where RRC Container is dummy
+          *
+          * MAC subheader format is R/F/LCId/L (2/3 bytes)
+          * LCId is 1 for SRB1
+          * L is length of PDU i.e 6bytes here
+          * From 38.321 section 6.1.1
+          *
+          * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
+          * From 38.322, section 6.2.2.4
+          */
+         DU_LOG("DEBUG  -->  PHY_STUB: Forming RRC RECONFIGURATION COMPLETE PDU");
+         uint8_t  pduLen = 13; /* PDU length */
+         pduLen += 2; /* RLC sub header */
+         uint8_t msg[] = {1, pduLen, 128, pnfCb.pnfUeCb[ueId-1].rlcSnForSrb1++, 0, pnfCb.pnfUeCb[ueId-1].pdcpSn++, 8, 64, 0, 0,\
+            0, 0, 0, 0, 0, 0, 0};
+
+         pduLen += 2;  /* 2bytes of MAC header */
+         memcpy(pdu, &msg, pduLen);
+         byteIdx += pduLen; /* 4 bytes of header : MAC+RLC*/
+         break;
+
+      }
+#endif
+      default:
+      break;
+   } /* End of switch(type) */
+
+   /* Filling MAC SDU for Padding bytes*/
+   if(byteIdx < puschPdu.puschData.tbSize)
+   {
+      /* For Padding
+         MAC subheader format is R/R/LCId (1byte)
+         LCId is 63 for padding
+         From 38.321 section 6.1.1
+         */
+      CMCHKPK(oduPackPostUInt8, 63, mBuf);
+      byteIdx++;
+
+      for(; byteIdx < puschPdu.puschData.tbSize; byteIdx++)
+      {
+         CMCHKPK(oduPackPostUInt8, 0, mBuf);
+      }
+   }
+
+   /* Sending Rx data indication to MAC */
+   DU_LOG("INFO   --> NFAPI_PNF: Sending Rx data Indication to VNF");
+
+   if(pnfP7UdpSendMsg(mBuf) != ROK)
+   { 
+      return RFAILED;
+   }
+   return ROK;
+}
+
 /*********************************************************************************
  * @Brief: Processes UL_TTI_REQ received from VNF
  *
@@ -275,6 +708,7 @@ uint8_t pnfBuildAndSendRachInd(uint16_t slot, uint16_t sfn, uint8_t raPreambleId
 void pnfProcUlTtiReq(fapi_ul_tti_req_msg_body *pnfUlTtiReq)
 {
    uint8_t numPdus = pnfUlTtiReq->nPdus;
+   uint8_t ret = ROK;
 
    while(numPdus)
    {
@@ -292,7 +726,21 @@ void pnfProcUlTtiReq(fapi_ul_tti_req_msg_body *pnfUlTtiReq)
       if(pnfUlTtiReq->pdus[numPdus-1].pduType == PUSCH_PDU_TYPE)
       {
          DU_LOG("INFO   --> NFAPI_PNF: PUSCH PDU");
-         /*TODO: CRC_IND and RX_DATA_IND to be built and Sent*/
+         if(ROK == pnfBuildAndSendCrcInd(pnfUlTtiReq->slot, pnfUlTtiReq->sfn, pnfUlTtiReq->pdus[numPdus-1].pdu.pusch_pdu))
+         {
+            if(pnfBuildAndSendRxDataInd(pnfUlTtiReq->slot, pnfUlTtiReq->sfn, pnfUlTtiReq->pdus[numPdus-1].pdu.pusch_pdu) != ROK)
+            {
+               DU_LOG("ERROR  --> NFAPI_PNF: Failure in Sending RX_DATA_IND");
+               ret = RFAILED;
+               break;
+            }
+         }
+         else
+         {
+            DU_LOG("ERROR  --> NFAPI_PNF: Failure in CRC Ind thus PNF will not send RX_DATA_IND");
+            ret = RFAILED;
+            break;
+         }
       }
       if(pnfUlTtiReq->pdus[numPdus-1].pduType == PUCCH_PDU_TYPE)
       {
@@ -301,7 +749,7 @@ void pnfProcUlTtiReq(fapi_ul_tti_req_msg_body *pnfUlTtiReq)
       }
       numPdus--;
    }
-   return ROK;
+   return ret;
 }
 
 /*********************************************************************************
index 8588651..0d2e727 100644 (file)
@@ -157,10 +157,12 @@ S16 pnfP7UdpSendMsg(Buffer *mBuf)
    if(ret != ROK && ret != RWOULDBLOCK)
    {
       DU_LOG("ERROR  -->  P7_UDP : Message send failure");
+      ODU_PUT_MSG_BUF(mBuf); 
       return RFAILED;
    }
    
    DU_LOG("DEBUG  -->  P7_UDP : Message Sent");
+
+   ODU_PUT_MSG_BUF(mBuf); 
    return ROK;
 }