- packBytes(rarPdu, &bytePos, &bitPos, EBit, EBitSize);
- packBytes(rarPdu, &bytePos, &bitPos, TBit, TBitSize);
- packBytes(rarPdu, &bytePos, &bitPos, rapId, rapidSize);
- packBytes(rarPdu, &bytePos, &bitPos, RBit, RBitSize);
- packBytes(rarPdu, &bytePos, &bitPos, timeAdv, timeAdvSize);
- packBytes(rarPdu, &bytePos, &bitPos, ulGrant, ulGrantSize);
- packBytes(rarPdu, &bytePos, &bitPos, tmpCrnti, tmpCrntiSize);
-
- /* padding of 2 bytes */
- packBytes(rarPdu, &bytePos, &bitPos, RBit, RBitSize*2);
- packBytes(rarPdu, &bytePos, &bitPos, paddingLcid, paddingLcidSize);
- packBytes(rarPdu, &bytePos, &bitPos, 0, paddingSize);
+ packBytes(rarPdu, &bytePos, &bitPos, EBit, E_BIT_SIZE);
+ packBytes(rarPdu, &bytePos, &bitPos, TBit, T_BIT_SIZE);
+ packBytes(rarPdu, &bytePos, &bitPos, rarInfo->RAPID, RAPID_SIZE);
+ packBytes(rarPdu, &bytePos, &bitPos, RBit, R_BIT_SIZE);
+ packBytes(rarPdu, &bytePos, &bitPos, rarInfo->ta, TIMING_ADVANCE_SIZE);
+
+ /* Packing MSG3 UL Grant in RAR */
+ packBytes(rarPdu, &bytePos, &bitPos, rarInfo->ulGrant.freqHopFlag, FREQ_HOP_FLAG_SIZE);
+
+ /* Calculating freq domain resource allocation field value
+ * bwpSize = Size of BWP
+ * RBStart = Starting Resource block
+ * RBLen = length of contiguously allocted RBs
+ * Spec 38.214 Sec 6.1.2.2.2
+ */
+ bwpSize = rarInfo->ulGrant.bwpSize;
+ rbStart = rarInfo->ulGrant.msg3FreqAlloc.startPrb;
+ rbLen = rarInfo->ulGrant.msg3FreqAlloc.numPrb;
+
+ if((rbLen >=1) && (rbLen <= bwpSize - rbStart))
+ {
+ if((rbLen - 1) <= floor(bwpSize / 2))
+ msg3FreqResource = (bwpSize * (rbLen-1)) + rbStart;
+ else
+ msg3FreqResource = (bwpSize * (bwpSize - rbLen + 1)) \
+ + (bwpSize - 1 - rbStart);
+ }