+
+}
+
+/*******************************************************************
+ *
+ * @brief Database required to form MAC PDU
+ *
+ * @details
+ *
+ * Function : createMacRaCb
+ *
+ * Functionality:
+ * stores the required params for muxing
+ *
+ * @params[in] Pointer to cellId,
+ * crnti
+ * @return void
+ *
+ * ****************************************************************/
+void createMacRaCb(RachIndInfo *rachIndInfo)
+{
+ uint8_t ueIdx = 0;
+ uint16_t crnti = 0;
+ uint16_t cellIdx = 0;
+
+ GET_CELL_IDX(rachIndInfo->cellId, cellIdx);
+
+ crnti = getNewCrnti(&macCb.macCell[cellIdx]->crntiMap);
+ if(crnti == -1)
+ return;
+
+ GET_UE_IDX(crnti, ueIdx);
+ ueIdx = ueIdx -1;
+
+ /* store in rach ind structure */
+ rachIndInfo->crnti = crnti;
+
+ /* store in raCb */
+ macCb.macCell[cellIdx]->macRaCb[ueIdx].cellId = rachIndInfo->cellId;
+ macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti = crnti;
+}
+
+/*************************************************
+ * @brief fill RLC DL Data
+ *
+ * @details
+ *
+ * Function : fillMsg4DlData
+ * This function sends Dl Data
+ * to form MAC SDUs
+ *
+ * @param[in] MacDlData *dlData
+ * msg4Pdu pointer
+ ************************************************/
+
+void fillMsg4DlData(MacDlData *dlData, uint16_t msg4PduLen, uint8_t *msg4Pdu)
+{
+ dlData->pduInfo[dlData->numPdu].lcId = MAC_LCID_CCCH;
+ dlData->pduInfo[dlData->numPdu].pduLen = msg4PduLen;
+ memcpy(dlData->pduInfo[dlData->numPdu].dlPdu, msg4Pdu, msg4PduLen);
+ dlData->numPdu++;
+}
+
+/*************************************************
+ * @brief fill Mac Ce Info
+ *
+ * @details
+ *
+ * Function : fillMacCe
+ * This function fills Mac ce identities
+ *
+ * @param[in] RlcMacData *dlData
+ * Msg3Pdu Data
+ ************************************************/
+
+void fillMacCe(MacCeInfo *macCeInfo, uint8_t *msg3Pdu)
+{
+ uint8_t idx;
+ macCeInfo->numCes = 1;
+ for(idx = 0; idx < macCeInfo->numCes; idx++)
+ {
+ macCeInfo->macCe[idx].macCeLcid = MAC_LCID_CRI;
+ memcpy(macCeInfo->macCe[idx].macCeValue, \
+ msg3Pdu, MAX_CRI_SIZE);
+ }
+}
+
+/*******************************************************************
+ *
+ * @brief Forms MAC PDU
+ *
+ * @details
+ *
+ * Function : macMuxPdu
+ *
+ * Functionality:
+ * The MAC PDU will be MUXed and formed
+ *
+ * @params[in] MacDlData *, MacCeInfo *, txPdu *, tbSize
+ * @return void
+ * ****************************************************************/
+
+void macMuxPdu(MacDlData *dlData, MacCeInfo *macCeData, uint8_t *txPdu, uint16_t tbSize)
+{
+ uint16_t bytePos = 0;
+ uint8_t bitPos = 7;
+ uint8_t idx = 0;
+ uint8_t macPdu[tbSize];
+ memset(macPdu, 0, (tbSize * sizeof(uint8_t)));
+
+ /* subheader fields */
+ uint8_t RBit = 0; /* Reserved bit */
+ uint8_t FBit =0; /* Format Indicator */
+ uint8_t lcid =0; /* LCID */
+ uint16_t lenField = 0; /* Length field */
+
+ /* subheader field size (in bits) */
+ uint8_t RBitSize = 1;
+ uint8_t FBitSize = 1;
+ uint8_t lcidSize = 6;
+ uint8_t lenFieldSize = 0; /* 8-bit or 16-bit L field */
+
+ /* PACK ALL MAC CE */
+ if(macCeData != NULLP)
+ {
+ for(idx = 0; idx < macCeData->numCes; idx++)
+ {
+ lcid = macCeData->macCe[idx].macCeLcid;
+ switch(lcid)
+ {
+ case MAC_LCID_CRI:
+ {
+ /* Packing fields into MAC PDU R/R/LCID */
+ packBytes(macPdu, &bytePos, &bitPos, RBit, (RBitSize * 2));
+ packBytes(macPdu, &bytePos, &bitPos, lcid, lcidSize);
+ memcpy(&macPdu[bytePos], macCeData->macCe[idx].macCeValue,\
+ MAX_CRI_SIZE);
+ bytePos += MAX_CRI_SIZE;
+ break;
+ }
+ default:
+ DU_LOG("\nERROR --> MAC: Invalid LCID %d in mac pdu",lcid);
+ break;
+ }
+ }
+ }
+
+ /* PACK ALL MAC SDUs */
+ for(idx = 0; idx < dlData->numPdu; idx++)
+ {
+ lcid = dlData->pduInfo[idx].lcId;
+ switch(lcid)
+ {
+ case MAC_LCID_CCCH:
+ case MAC_LCID_MIN ... MAC_LCID_MAX :
+ {
+ lenField = dlData->pduInfo[idx].pduLen;
+ if(dlData->pduInfo[idx].pduLen > 255)
+ {
+ FBit = 1;
+ lenFieldSize = 16;
+
+ }
+ else
+ {
+ FBit = 0;
+ lenFieldSize = 8;
+ }
+ /* Packing fields into MAC PDU R/F/LCID/L */
+ packBytes(macPdu, &bytePos, &bitPos, RBit, RBitSize);
+ packBytes(macPdu, &bytePos, &bitPos, FBit, FBitSize);
+ packBytes(macPdu, &bytePos, &bitPos, lcid, lcidSize);
+ packBytes(macPdu, &bytePos, &bitPos, lenField, lenFieldSize);
+ memcpy(&macPdu[bytePos], dlData->pduInfo[idx].dlPdu, lenField);
+ bytePos += lenField;
+ break;
+ }
+
+ default:
+ DU_LOG("\nERROR --> MAC: Invalid LCID %d in mac pdu",lcid);
+ break;
+ }
+ }
+ if(bytePos < tbSize && (tbSize-bytePos >= 1))
+ {
+ /* padding remaining bytes */
+ RBitSize = 2;
+ lcid = MAC_LCID_PADDING;
+ packBytes(macPdu, &bytePos, &bitPos, RBit, RBitSize);
+ packBytes(macPdu, &bytePos, &bitPos, lcid, lcidSize);
+ }
+
+ /*Storing the muxed pdu */
+ if(txPdu != NULLP)
+ {
+ memcpy(txPdu, macPdu, tbSize);
+ }