1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /********************************************************************20**
21 Name: RLC - AM module file
25 Desc: Source code for Acknowledged Mode Module functions such as,
27 Transmission of data/control PDUs
28 Retransmission (Feedback in terms of status)
31 Reception - reordering
32 Duplicate detection for byte segments
37 *********************************************************************21*/
38 static const char* RLOG_MODULE_NAME="AMM";
39 static int RLOG_MODULE_ID=2048;
40 static int RLOG_FILE_ID=190;
42 /* header include files (.h) */
43 #include "common_def.h"
44 #include "lkw.h" /* LKW defines */
45 #include "ckw.h" /* CKW defines */
46 #include "kwu.h" /* KWU defines */
47 #include "rgu.h" /* RGU defines */
49 #include "kw_err.h" /* Err defines */
50 #include "kw_env.h" /* RLC environment options */
52 #include "kw.h" /* RLC defines */
55 /* extern (.x) include files */
56 #include "lkw.x" /* LKW */
57 #include "ckw.x" /* CKW */
58 #include "kwu.x" /* KWU */
59 #include "rgu.x" /* RGU */
65 /* Variable for logging, declared in cl */
66 #ifndef RGL_SPECIFIC_CHANGES
73 #ifndef RGL_SPECIFIC_CHANGES
75 #ifndef TENB_T2K3K_SPECIFIC_CHANGES
77 uint32_t isMemThreshReached(Region region);
81 uint32_t isMemThreshReached(Region region);
87 @brief RLC Acknowledged Mode Uplink Module
89 #define RLC_MODULE (RLC_DBGMASK_AM | RLC_DBGMASK_UL) /* for debugging purpose */
91 /* private function declarations */
93 static void rlcAmmUlAssembleCntrlInfo ARGS ((RlcCb *gCb, RlcUlRbCb *rbCb));
95 static uint8_t rlcAmmExtractHdr ARGS ((RlcCb *gCb,
101 static bool rlcAmmUlPlacePduInRecBuf ARGS ((RlcCb *gCb,
106 static void rlcAmmTriggerStatus ARGS ((RlcCb *gCb,
111 static uint8_t rlcAmmUlReassembleSdus ARGS ((RlcCb *gCb,
113 RlcAmRecBuf *recBuf));
115 static Void rlcAmmProcPduOrSeg ARGS ((RlcCb *gCb,
120 static Void rlcAmmUpdExpByteSeg ARGS ((RlcCb *gCb,RlcAmUl *amUl, RlcSeg* newSeg));
122 static Void rlcAmmExtractElmnt ARGS ((RlcCb *gCb, Buffer *pdu, RlcExtHdr *hdrInfo));
124 static Void rlcAmmUlHndlStatusPdu ARGS ((RlcCb *gCb,
129 /******************************************************************************
131 AM Module contains the following funcitons:
134 - rlcAmmUlAssembleCntrlInfo
139 - rlcAmmUlHndlStatusPdu
140 - rlcAmmTriggerStatus
141 - rlcAmmUlReassembleSdus
143 *******************************************************************************/
144 /** @addtogroup ammode */
148 * @brief Private function to fill NACK information in status Pdu as per 5GNR
150 * @param[in] rbCb Ul RbCb
151 * @param[in] sn Sequence number of the PDU for which the NACK
152 * @param[in] isSegment TRUE means NACK for segment; FALSE for PDU
153 * @param[in] soStart SOStart
154 * @param[in] soEnd SOEnd
155 * @param[out] statusPdu status Pdu holder to be filled
156 * @param[in] prevNackSn It holds previous nack Sn
159 * The number of bytes required to encode this NACK information
162 static uint8_t rlcAmmUlSetNackInfo(RlcUlRbCb *rbCb, RlcSn sn, bool isSegment, \
163 uint16_t soStart, uint16_t soEnd, RlcUdxDlStaPdu *statusPdu, RlcSn *prevNackSn)
165 RlcNackInfo *nackInfo = (statusPdu->nackInfo + statusPdu->nackCount);
166 uint16_t sizeToBeEncd = 0; /* Status PDu size to be encoded */
168 /* In following cases we should increment the nackCnt & fill new NACK_SN info:
169 * 1) First NACK_SN of the statusdPdu
170 * 2) NACK_SN is not continuous with previous
171 * 3) NACK_SN is same as previuos but segments are not continuous
172 * 4) NACK_SN is continuous with previous but previous NACK_SN segments
173 * are not missing in sequence till end
175 if((*prevNackSn == 0xffffffff) || ((((*prevNackSn) + 1) & AMUL.snModMask) != sn) ||
176 (((*prevNackSn) == sn) && (((nackInfo->soEnd + 1) != soStart))) ||
177 ((nackInfo->isSegment) && (((*prevNackSn) + 1) == sn) && (nackInfo->soEnd != RLC_ALL_BYTES_MISSING)))
179 if(nackInfo->nackRange)
181 if((nackInfo->soEnd) && (!nackInfo->soStart))
183 /*First nack_sn of this nackRange not segmented but last is segmented */
184 sizeToBeEncd = 5; /*32 for soStart and soEnd and 8 for nackRange */
188 /*First nack_sn of this nackRange was segmented */
189 sizeToBeEncd = 1; /*8 for nackRange */
193 if(*prevNackSn != 0xffffffff)
195 /* Increment nackCount as this sn is continous */
196 statusPdu->nackCount++;
197 nackInfo = statusPdu->nackInfo + statusPdu->nackCount;
201 nackInfo->isSegment = isSegment;
202 nackInfo->soStart = soStart;
203 nackInfo->soEnd = soEnd;
204 nackInfo->nackRange = 0;
208 sizeToBeEncd += ((AMUL.snLen == RLC_AM_CFG_12BIT_SN_LEN)?6:7); /* NACK,E1,E2,Sostart,SoEnd */
212 sizeToBeEncd += ((AMUL.snLen == RLC_AM_CFG_12BIT_SN_LEN)?2:3); /* NACK,E1,E2 */
217 if(!(nackInfo->nackRange))
219 nackInfo->nackRange++;
221 /* This case means there are continuous SNs/Segments. If it is the next
222 * Sn then increment nackRnage. if same SN but different segment then
223 * dont increment nackRange */
224 if((((*prevNackSn) + 1) & AMUL.snModMask) == sn)
226 nackInfo->nackRange++;
229 /* If NackRange is reached to max value then increment statusPdu->nackCount*/
230 if(nackInfo->nackRange == 255)
232 statusPdu->nackCount++;
233 if(nackInfo->isSegment)
235 sizeToBeEncd = 1; /* return only nackRangeSize*/
239 /* First SN was not segmented of this nackRange but last SN is segmented */
240 sizeToBeEncd = 5; /* return size of soSatrt + soEnd + nackRnage */
246 nackInfo->isSegment = isSegment;
247 nackInfo->soEnd = soEnd;
249 else if(nackInfo->isSegment)
251 nackInfo->soEnd = RLC_ALL_BYTES_MISSING;
255 nackInfo->soStart = 0;
262 return (sizeToBeEncd);
266 * @brief Private handler to gather information required to create the STATUS
270 * Scans the reception buffer and copies information to the UdxDlStaPdu
271 * structure about SN's and segments not yet received. This data is
272 * sent to the DL instance so that it can create an appropriate (depending
273 * on the grants from MAC) STATUS PDU and send it to MAC.
275 * @param[in] gCb RLC instance control block
276 * @param[in] rbCb Uplink RB control block
281 static void rlcAmmUlAssembleCntrlInfo(RlcCb *gCb, RlcUlRbCb *rbCb)
283 RlcUdxDlStaPdu *pStatusPdu;
284 RlcNackInfo *nackInfo;
285 RlcSn sn; /* sequence number */
286 RlcSn mSn; /* Mod val of sequence number */
287 RlcSn rxHighestStatus; /* Mod val of rxHighestStatus */
288 RlcSeg *seg; /* pdu segment */
289 uint16_t nackCnt = 0; /* Index for staPdu */
290 uint16_t seqSo; /* segmment offset */
291 RlcUdxUlSapCb *sapCb;
292 uint16_t staPduEncSize = 3; /* size that would be of the encoded
293 STATUS PDU, it is in bits; 15 for
294 first fixed part of STATUS PDU */
295 RlcAmRecBuf *recBuf = NULLP;
296 RlcSn prevNackSn = 0xffffffff;
298 sapCb = RLC_GET_UDX_SAP(gCb);
300 RLC_ALLOC_SHRABL_BUF(sapCb->pst.region,
303 sizeof(RlcUdxDlStaPdu));
305 #if (ERRCLASS & ERRCLS_ADD_RES)
306 /* Memory allocation failure can not be expected */
314 MODAMR(sn, mSn, AMUL.rxNext, AMUL.snModMask);
315 MODAMR(AMUL.rxHighestStatus, rxHighestStatus, AMUL.rxNext, AMUL.snModMask);
317 recBuf = rlcUtlGetRecBuf(AMUL.recBufLst, sn);
319 while (mSn < rxHighestStatus )
321 /* For missing PDUs */
322 if ((NULLP == recBuf) && nackCnt < RLC_MAX_NACK_CNT )
324 DU_LOG("\nRLC: rlcAmmUlAssembleCntrlInfo: Missing PDU's SN = %d UEID:%d \
325 CELLID:%d", sn, rbCb->rlcId.ueId, rbCb->rlcId.cellId);
326 staPduEncSize += rlcAmmUlSetNackInfo(rbCb,
328 FALSE, /* isSegment */
334 else if (recBuf && (recBuf->pdu == NULLP) &&
335 (recBuf->segLst.count > 0))
337 /* Scan through the byte segments of PDU and add this sn
338 with soStart and soEnd info to staPdu */
341 RLC_LLIST_FIRST_SEG(recBuf->segLst, seg);
342 while (seg != NULLP && nackCnt < RLC_MAX_NACK_CNT)
344 /* For missing byte segments */
345 if (seg->amHdr.so != seqSo)
347 staPduEncSize += rlcAmmUlSetNackInfo(rbCb,
355 DU_LOG("\nRLC: rlcAmmUlAssembleCntrlInfo: Missing byte segment's"
356 " SN:%d UEID:%d CELLID:%d", sn, rbCb->rlcId.ueId, rbCb->rlcId.cellId);
357 DU_LOG("\nRLC: rlcAmmUlAssembleCntrlInfo: soStart and soEnd = %d, %d \
358 UEID:%d CELLID:%d", seqSo, seg->amHdr.so - 1, rbCb->rlcId.ueId,
362 seqSo = seg->soEnd + 1;
363 RLC_LLIST_NEXT_SEG(recBuf->segLst, seg);
366 /* Check if the last segment is missing */
367 RLC_LLIST_LAST_SEG(recBuf->segLst, seg);
368 if ((seg != NULLP) &&
369 (seg->amHdr.si != RLC_SI_LAST_SEG && nackCnt < RLC_MAX_NACK_CNT))
371 staPduEncSize += rlcAmmUlSetNackInfo(rbCb,
375 RLC_ALL_BYTES_MISSING,
379 DU_LOG("\nRLC: rlcAmmUlAssembleCntrlInfo: Missing (last) byte "
380 "segment's SN:%d UEID:%d CELLID:%d", sn, rbCb->rlcId.ueId,
382 DU_LOG("\nRLC: rlcAmmUlAssembleCntrlInfo: soStart and soEnd = %d, %d\
383 UEID:%d CELLID:%d", seqSo, RLC_ALL_BYTES_MISSING, rbCb->rlcId.ueId,
389 sn = (sn + 1) & (AMUL.snModMask); /* MOD 1024 */
390 MODAMR(sn, mSn, AMUL.rxNext, AMUL.snModMask);
392 /* Get the received Buffer the updated/next SN */
393 recBuf = rlcUtlGetRecBuf(AMUL.recBufLst, sn);
395 /* Find the next missing sequence number if nackCnt reaches maximum and
396 still Reordering window has some missing AMDPDUs / AMDPDU segments. The
397 next missing sequence number will be considered as the ack sequnece
398 number in the status pdu.*/
399 if((nackCnt == RLC_MAX_NACK_CNT) &&
400 ((recBuf == NULLP) ||
401 ((recBuf->pdu == NULLP) &&
402 (recBuf->segLst.count > 0))))
408 /*Unfortunately i have write below peice of code here because kwAmmsetNackInfo()
409 * don't know that this is the last nackSn with nackRange*/
410 nackInfo = &(pStatusPdu->nackInfo[pStatusPdu->nackCount]);
411 if(nackInfo->nackRange)
413 if((nackInfo->soEnd) && (!nackInfo->soStart))
415 /*First nack_sn of this nackRange not segmented but last is segmented */
416 staPduEncSize += 5; /*32 for soStart and soEnd and 8 for nackRange */
420 /*First nack_sn of this nackRange was segmented */
421 staPduEncSize += 1; /*8 for nackRange */
424 /* nackCount is used as an index to nackInfo array but in status Pdu it
425 * should be equal to number nackInfo that are filled. hence incrementing by 1*/
426 if(prevNackSn != 0xffffffff)
428 pStatusPdu->nackCount++;
430 /* Update ACK SN with the last sn for which feedback is not assembled */
431 if ( mSn == rxHighestStatus)
433 pStatusPdu->ackSn = AMUL.rxHighestStatus;
437 pStatusPdu->ackSn = sn;
440 DU_LOG("\nRLC: rlcAmmUlAssembleCntrlInfo: ACK PDU's SN = %d"
441 "UEID:%d CELLID:%d", pStatusPdu->ackSn, rbCb->rlcId.ueId,
444 pStatusPdu->controlBo = staPduEncSize; /*Its already in bytes */
447 AMUL.gatherStaPduInfo = FALSE;
450 if (rlcUlUdxStaPduReq(&sapCb->pst,
455 DU_LOG("\nRLC: rlcAmmUlAssembleCntrlInfo: Failed to Send Sta Pdu UEID:%d \
456 CELLID:%d", rbCb->rlcId.ueId, rbCb->rlcId.cellId);
457 RLC_FREE_SHRABL_BUF_WC(sapCb->pst.region,
460 sizeof(RlcUdxDlStaPdu));
466 #ifdef XEON_SPECIFIC_CHANGES
467 uint32_t gRlcDatIndUL;
470 #ifdef T2K_TRIGGER_RLC_REEST
471 uint32_t drpRlcDrbPack;
474 * @brief Handler to process the PDUs received from MAC and send it to PDCP
477 * This function is invoked by UTL with the PDU(s) received from MAC.
478 * It reorders the received data PDUs and trigger status report as
479 * needed. Reassembles the SDUs in sequence and send it to PDCP.
480 * It also processes the control PDU
482 * @param[in] gCb RLC instance control block
483 * @param[in] rbCb RB control block
484 * @param[out] pduInfo PDU Info received from MAC
490 void rlcAmmProcessPdus(RlcCb *gCb, RlcUlRbCb *rbCb, KwPduInfo *pduInfo, uint32_t ttiCnt)
492 void rlcAmmProcessPdus(RlcCb *gCb, RlcUlRbCb *rbCb, KwPduInfo *pduInfo)
499 uint8_t numPduToProcess;
505 #ifdef LTE_L2_MEAS_RLC
506 MsgLen rlcSduSz; /*Holds length of Rlc Sdu*/
507 #endif /* LTE_L2_MEAS */
511 numPduToProcess = RLC_MIN(pduInfo->numPdu, RGU_MAX_PDU);
512 DU_LOG("\nRLC : rlcAmmProcessPdus: numPdu[%d],numPduToProcess[%d] UEID:%d CELLID:%d",
513 numPdu, numPduToProcess, rbCb->rlcId.ueId, rbCb->rlcId.cellId);
515 while (numPdu < numPduToProcess)
518 pdu = pduInfo->mBuf[numPdu++];
523 DU_LOG("\nRLC : rlcAmmProcessPdus: Null Pdu UEID:%d CELLID:%d",
524 rbCb->rlcId.ueId, rbCb->rlcId.cellId);
525 gCb->genSts.errorPdusRecv++;
528 #ifndef RGL_SPECIFIC_CHANGES
532 ODU_GET_MSG_LEN(pdu, &len);
537 /* Extract AM PDU/SEG header Info */
538 RLC_MEM_ZERO(&amHdr, sizeof(RlcAmHdr));
539 /* Avoided the allocation of amHdr and sending
541 if (rlcAmmExtractHdr(gCb, rbCb, pdu, &amHdr, &fByte) != ROK)
543 DU_LOG("\nRLC : rlcAmmProcessPdus: Header Extraction Failed UEID:%d CELLID:%d",
544 rbCb->rlcId.ueId, rbCb->rlcId.cellId);
546 gCb->genSts.errorPdusRecv++;
549 /* Check if its a control PDU */
552 rlcAmmUlHndlStatusPdu(gCb, rbCb, pdu, &fByte);
556 if((amHdr.si == RLC_SI_LAST_SEG) && (!amHdr.so))
558 DU_LOG("\nRLC: rlcAmmProcessPdus: Dropping PDU because SO can't be zero\
559 for last segment sn:%u UEID:%d CELLID:%d", amHdr.sn, rbCb->rlcId.ueId,
564 #ifndef RGL_SPECIFIC_CHANGES
567 #ifndef TENB_T2K3K_SPECIFIC_CHANGES
569 /* Changed the condition to TRUE from ROK */
570 if(isMemThreshReached(rlcCb[0]->init.region) == TRUE)
580 /*ccpu00142274 - UL memory based flow control*/
581 if(isMemThreshReached(rlcCb[0]->init.region) != ROK)
594 #ifdef T2K_TRIGGER_RLC_REEST
595 if(drpRlcDrbPack > 1000)
597 if(rbCb->rlcId.rbType == CM_LTE_DRB)
605 /* Reordering data PDU */
607 if (rlcAmmUlPlacePduInRecBuf(gCb,pdu, rbCb, &amHdr) == TRUE)
612 RlcSn mrxNextHighestRcvd;
615 rlcUtlCalUlIpThrPut(gCb, rbCb, pdu, ttiCnt);
616 #endif /* LTE_L2_MEAS */
618 /* Update rxNextHighestRcvd */
619 MODAMR(sn, mSn, amUl->rxNext, amUl->snModMask);
620 MODAMR(amUl->rxNextHighestRcvd, mrxNextHighestRcvd, amUl->rxNext, amUl->snModMask);
621 if (mSn >= mrxNextHighestRcvd)
623 amUl->rxNextHighestRcvd = ((sn + 1) & (amUl->snModMask));
625 DU_LOG("\nRLC: rlcAmmProcessPdus: Updated rxNextHighestRcvd = %d UEID:%d CELLID:%d",
626 amUl->rxNextHighestRcvd, rbCb->rlcId.ueId, rbCb->rlcId.cellId);
629 recBuf = rlcUtlGetRecBuf(amUl->recBufLst, sn);
630 if ((NULLP != recBuf) && ( recBuf->allRcvd))
632 /* deliver the reassembled RLC SDU to upper layer,
633 But not removed from the table */
634 rlcAmmUlReassembleSdus(gCb, rbCb, recBuf);
635 recBuf->isDelvUpperLayer = TRUE;
637 MODAMR(amUl->vrMr, tVrMr, amUl->rxNext, amUl->snModMask);
639 /* Update rxHighestStatus */
640 if (sn == amUl->rxHighestStatus)
642 tSn = (sn + 1) & (amUl->snModMask) ; /* MOD (2 Pwr SN LEN- 1) */
644 recBuf = rlcUtlGetRecBuf(amUl->recBufLst, tSn);
645 /* Scan through till the upper edge of the window */
646 MODAMR(tSn, mSn, amUl->rxNext, amUl->snModMask);
649 if ((NULLP == recBuf) || (!recBuf->allRcvd))
651 RLOG_ARG3(L_UNUSED,DBG_RBID,rbCb->rlcId.rbId,
652 "rlcAmmProcessPdus: Updated rxHighestStatus:%d "
658 amUl->rxHighestStatus = tSn;
661 tSn = (tSn + 1) & (amUl->snModMask); /* MOD (2 Pwr SN LEN- 1) */
662 recBuf = rlcUtlGetRecBuf(amUl->recBufLst, tSn);
669 if (sn == amUl->rxNext)
672 recBuf = rlcUtlGetRecBuf(amUl->recBufLst, tSn);
673 MODAMR(tSn, mSn, amUl->rxNext, amUl->snModMask);
674 /* Scan through till the upper edge of the window */
677 if ((NULLP != recBuf) && (recBuf->allRcvd) &&
678 (TRUE == recBuf->isDelvUpperLayer))
680 /* RecBuf should remove from table
681 since PDU is already sent to upper layer */
682 recBuf->isDelvUpperLayer = FALSE;
683 rlcUtlDelRecBuf(amUl->recBufLst, recBuf, gCb);
688 amUl->vrMr = (amUl->rxNext + (RLC_AM_GET_WIN_SZ(amUl->snLen))) & (amUl->snModMask);
691 tSn = (tSn + 1) & (amUl->snModMask);
692 recBuf = rlcUtlGetRecBuf(amUl->recBufLst, tSn);
698 /* Check if reOrdTmr is running and update rxNextStatusTrig accordingly */
699 tmrRunning = rlcChkTmr(gCb,(PTR)rbCb, RLC_EVT_AMUL_REORD_TMR);
702 Bool snInWin = RLC_AM_CHK_SN_WITHIN_RECV_WINDOW(amUl->rxNextStatusTrig, amUl);
704 if ( (amUl->rxNextStatusTrig == amUl->rxNext) || ( (!snInWin) &&
705 (amUl->rxNextStatusTrig != amUl->vrMr) ) )
707 rlcStopTmr(gCb,(PTR)rbCb, RLC_EVT_AMUL_REORD_TMR);
714 if (amUl->rxNextHighestRcvd > amUl->rxNext)
716 rlcStartTmr(gCb,(PTR)rbCb, RLC_EVT_AMUL_REORD_TMR);
717 amUl->rxNextStatusTrig = amUl->rxNextHighestRcvd;
719 DU_LOG("\nRLC: rlcAmmProcessPdus: Updated rxNextStatusTrig = %d \
720 UEID:%d CELLID:%d", amUl->rxNextStatusTrig, rbCb->rlcId.ueId,
728 gRlcStats.amRlcStats.numULPdusDiscarded++;
733 rlcAmmTriggerStatus(gCb,rbCb, sn, discFlg);
738 rlcUtlCalUlIpThrPutIncTTI(gCb, rbCb,ttiCnt);
739 #endif /* LTE_L2_MEAS */
740 gCb->genSts.pdusRecv += pduInfo->numPdu;
741 if (amUl->gatherStaPduInfo)
743 rlcAmmUlAssembleCntrlInfo(gCb,rbCb);
751 * @brief Private handler to extract header Information of the PDU
754 * This function extracts the header elements of the PDU and store them
755 * in db for future reference.
757 * fByte - is the first byte removed from the PDU as part of calling
760 * @param[in] gCb RLC instance control block
761 * @param[in] rbCb Uplink RB control block
762 * @param[in] pdu Received PDU
763 * @param[out] amHdr Pointer to the extracted AM header
764 * @param[out] fByte First byte removed from the PDU
771 static uint8_t rlcAmmExtractHdr(RlcCb *gCb, RlcUlRbCb *rbCb, Buffer *pdu, RlcAmHdr *amHdr, uint8_t *fByte)
778 RLC_MEM_ZERO(&hdrInfo, sizeof(RlcExtHdr));
780 /* Extract fixed part of the header */
781 ODU_GET_MSG_LEN(pdu,&pduSz);
782 ODU_REM_PRE_MSG(fByte, pdu);
783 amHdr->dc = (*fByte & RLC_DC_POS) >> RLC_DC_SHT;
784 if (RLC_CNTRL_PDU == amHdr->dc)
786 //printf ("++++++++++++ 5GNRLOG HDR extracted CTRL : \n");
790 amHdr->p = (*fByte & RLC_POLL_POS) >> RLC_POLL_SHT;
792 amHdr->si = (*fByte & RLC_SI_POS) >> RLC_SI_SHT;
795 if (rbCb->m.amUl.snLen == RLC_AM_CFG_12BIT_SN_LEN)
797 ODU_REM_PRE_MSG(&snByte, pdu);
798 sn = (RlcSn)(((*fByte & RLC_SN_POS_12BIT) << RLC_BYTE_LEN ) | snByte);
801 else if (rbCb->m.amUl.snLen == RLC_AM_CFG_18BIT_SN_LEN)
803 ODU_REM_PRE_MSG(&snByte, pdu);
804 sn = (RlcSn)(((*fByte & RLC_SN_POS_18BIT) << RLC_BYTE_LEN ) | snByte);
806 ODU_REM_PRE_MSG(&snByte, pdu);
807 sn = ((sn << RLC_BYTE_LEN) | snByte);
811 if ((amHdr->si != 0) && (amHdr->si != 0x01))
813 hdrInfo.len = RLC_SO_LEN_5GNR;
814 rlcAmmExtractElmnt(gCb, pdu, &hdrInfo);
815 amHdr->so = hdrInfo.val;
824 * @brief Private handler to extract header Information of the PDU
827 * This function extracts the header elements of the PDU and store them
828 * in db for future reference.
830 * fByte - is the first byte removed from the PDU as part of calling
833 * @param[in] gCb RLC instance control block
834 * @param[in] rbCb Uplink RB control block
835 * @param[in] pdu Received PDU
836 * @param[out] amHdr Pointer to the extracted AM header
837 * @param[out] fByte First byte removed from the PDU
844 static S16 rlcAmmExtractHdrOld(RlcCb *gCb,Buffer *pdu,RlcAmHdr *amHdr,uint8_t *fByte)
853 RLC_MEM_ZERO(&hdrInfo, sizeof(RlcExtHdr));
855 /* Extract fixed part of the header */
856 SFndLenMsg(pdu,&pduSz);
857 SRemPreMsg(fByte, pdu);
858 amHdr->dc = (*fByte & RLC_DC_POS) >> RLC_DC_SHT;
859 if (RLC_CNTRL_PDU == amHdr->dc)
863 /* kw002.201 : Changed the extraction of hdr elements to avoid */
865 amHdr->rf = (*fByte & RLC_RF_POS) >> RLC_RF_SHT;
866 amHdr->p = (*fByte & RLC_POLL_POS) >> RLC_POLL_SHT;
867 amHdr->fi = (*fByte & RLC_FI_POS) >> RLC_FI_SHT;
868 e = amHdr->e = (*fByte & RLC_E_POS)>> RLC_E_SHT;
870 SRemPreMsg(&snByte, pdu);
871 sn = (uint16_t)(((*fByte & RLC_SN_POS) << RLC_BYTE_LEN ) | snByte);
875 /* Extract extn part of the header */
876 hdrInfo.len = RLC_LSF_LEN;
877 rlcAmmExtractElmnt(gCb, pdu, &hdrInfo);
878 amHdr->lsf = (uint8_t)hdrInfo.val;
880 hdrInfo.len = RLC_SO_LEN;
881 rlcAmmExtractElmnt(gCb, pdu, &hdrInfo);
882 amHdr->so = hdrInfo.val;
888 while (e && (amHdr->numLi < RLC_MAX_UL_LI))
890 hdrInfo.len = RLC_E_LEN;
891 rlcAmmExtractElmnt(gCb, pdu, &hdrInfo);
892 e = amHdr->e = (uint8_t)hdrInfo.val;
894 /* Extract LI value*/
895 hdrInfo.len = RLC_LI_LEN;
896 rlcAmmExtractElmnt(gCb, pdu, &hdrInfo);
897 /* li = hdrInfo.val;*/
899 /* check if LI is zero */
902 RLOG0(L_ERROR, "Received LI as 0");
906 /* store the extracted LI value */
907 amHdr->li[amHdr->numLi++] = hdrInfo.val;
908 totalSz += hdrInfo.val; /* incrment the size by LI value */
911 /*ccpu00122597:PDU is dropped if liCnt exceeds RLC_MAX_LI*/
912 if(e && (amHdr->numLi >= RLC_MAX_UL_LI))
914 RLOG2(L_ERROR,"LI Count [%u] exceeds Max LI Count[%u]",
915 amHdr->numLi, RLC_MAX_UL_LI);
919 /* first 2 bytes + Add one for Odd LI*/
920 pduSz -= ( amHdr->numLi + (amHdr->numLi >> 1) + 2 + (amHdr->numLi & 1) );
922 if ( totalSz >= pduSz )
924 RLOG3(L_ERROR,"SN [%d]:Corrupted PDU as TotSz[%lu] PduSz[%lu] ",
925 amHdr->sn, totalSz, pduSz);
934 * @brief Private handler to process the status PDU
937 * Private handler invokded by rlcAmmProcessPdus to process the
938 * control PDU (status report) received from its peer RLC entity.
940 * - Decode the values from the received control pdu
941 * - Create a RlcUdxStaPdu structure, copy the values onto it and
942 * send it to the DL instance for further processing
944 * @param[in] gCb RLC instance control block
945 * @param[in] rbCb Uplink RB control block
946 * @param[in] cntrlPdu Control PDU received from MAC
947 * @param[in] fByte First byte already removed from the STATUS PDU
952 static void rlcAmmUlHndlStatusPdu(RlcCb *gCb, RlcUlRbCb *rbCb, Buffer *cntrlPdu, uint8_t *fByte)
956 RlcUdxStaPdu *pStaPdu;
957 RlcUdxUlSapCb *sapCb;
958 uint8_t e3; /* NACK RANGE : 5GNR */
961 uint32_t resrvdBitsAckSn=0;
962 uint32_t resrvdBitsNackSn=0;
964 RLC_MEM_ZERO(&hdrInfo, sizeof(RlcExtHdr));
966 /* Extract the Control PDU */
967 hdrInfo.hdr = (*fByte << 1);
970 /* D/C has been shifted in the calling function */
971 if (hdrInfo.hdr & 0xE0)
973 DU_LOG("\nRLC: rlcAmmUlHndlStatusPdu: Reserved value for CPT received UEID:%d \
974 CELLID:%d", rbCb->rlcId.ueId, rbCb->rlcId.cellId);
978 sapCb = RLC_GET_UDX_SAP(gCb);
980 RLC_ALLOC_SHRABL_BUF(sapCb->pst.region,
983 sizeof(RlcUdxStaPdu));
985 #if (ERRCLASS & ERRCLS_ADD_RES)
986 /* Memory allocation failure can not be expected */
993 if (rbCb->m.amUl.snLen == RLC_AM_CFG_12BIT_SN_LEN)
996 resrvdBitsAckSn = RLC_STA_PDU_R_BITS_ACKSN_12BITS;
997 resrvdBitsNackSn = RLC_STA_PDU_R_BITS_NACKSN_12BITS;
999 else if (rbCb->m.amUl.snLen == RLC_AM_CFG_18BIT_SN_LEN)
1002 resrvdBitsAckSn = RLC_STA_PDU_R_BITS_ACKSN_18BITS;
1003 resrvdBitsNackSn = RLC_STA_PDU_R_BITS_NACKSN_18BITS;
1008 resrvdBitsAckSn = 0;
1009 resrvdBitsAckSn = 0;
1012 pStaPdu->nackCnt = 0;
1014 hdrInfo.hdr = hdrInfo.hdr << RLC_CPT_LEN;
1017 hdrInfo.len = snLen;
1018 rlcAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
1019 pStaPdu->ackSn = hdrInfo.val;
1021 //printf ("++++++++++++ 5GNRLOG HNDL STATUS acksn %d : \n", pStaPdu->ackSn);
1022 /* Check if NACK Exists */
1023 hdrInfo.len = RLC_E1_LEN;
1024 rlcAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
1025 e1 = (uint8_t)hdrInfo.val;
1026 DU_LOG("\nRLC: rlcAmmUlHndlStatusPdu: ACK SN = %d UEID:%d CELLID:%d",
1027 pStaPdu->ackSn, rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1029 /* Extract the Reserved Bits after ACK SN field */
1030 hdrInfo.len = resrvdBitsAckSn;
1031 rlcAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
1033 /* If NACK exists in control PDU */
1034 /* For ACKs and NACKs */
1035 while (e1 && (pStaPdu->nackCnt < RLC_MAX_NACK_CNT))
1037 hdrInfo.len = snLen;
1038 rlcAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
1039 pStaPdu->nackInfo[pStaPdu->nackCnt].sn = hdrInfo.val;
1041 hdrInfo.len = RLC_E1_LEN;
1042 rlcAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
1043 e1 = (uint8_t)hdrInfo.val;
1046 /* hdrInfo.len = RLC_E1_LEN; --> previusly stored value (for e1) is
1048 rlcAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
1049 /* e2 = (uint8_t) hdrInfo.val;*/
1051 /* Store e2 value */
1052 pStaPdu->nackInfo[pStaPdu->nackCnt].isSegment = (uint8_t) hdrInfo.val;
1054 /* Extract e3 : 5GNR */
1055 /* hdrInfo.len = RLC_E1_LEN; --> previusly stored value (for e1) is
1057 rlcAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
1058 e3 = (uint8_t) hdrInfo.val;
1060 /* Extract Reserved Bits after NACK SN */
1061 hdrInfo.len = resrvdBitsNackSn;
1062 rlcAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
1064 /* Test for resegmentation */
1065 if (pStaPdu->nackInfo[pStaPdu->nackCnt].isSegment)
1067 hdrInfo.len = RLC_SO_LEN_5GNR; /* 5GNR : SO Len 16 Bits */
1068 rlcAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
1069 pStaPdu->nackInfo[pStaPdu->nackCnt].soStart = hdrInfo.val;
1071 rlcAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
1072 pStaPdu->nackInfo[pStaPdu->nackCnt].soEnd = hdrInfo.val;
1074 DU_LOG("\nRLC: rlcAmmUlHndlStatusPdu: soStart and soEnd = %d %d"
1075 "UEID:%d CELLID:%d", pStaPdu->nackInfo[pStaPdu->nackCnt].soStart,
1076 pStaPdu->nackInfo[pStaPdu->nackCnt].soEnd, rbCb->rlcId.ueId,
1077 rbCb->rlcId.cellId);
1082 pStaPdu->nackInfo[pStaPdu->nackCnt].soStart = 0;
1083 pStaPdu->nackInfo[pStaPdu->nackCnt].soEnd = 0;
1086 /* NACK RANGE Field is SET */
1089 /* Extract NACK range field */
1090 hdrInfo.len = RLC_NACK_RANGE_LEN;
1091 rlcAmmExtractElmnt(gCb, cntrlPdu, &hdrInfo);
1092 snRange = (uint8_t)hdrInfo.val;
1094 pStaPdu->nackInfo[pStaPdu->nackCnt].nackRange = snRange;
1100 gRlcStats.amRlcStats.numULStaPduRcvd++;
1101 gRlcStats.amRlcStats.numULNackInStaPduRcvd += pStaPdu->nackCnt;
1103 /* In case we have reached the MAX NACK CNT, then we should modify the ACK_SN
1104 to the last NACK SN + 1 and discard the original ACK_SN*/
1105 if(pStaPdu->nackCnt == RLC_MAX_NACK_CNT)
1107 pStaPdu->ackSn = (pStaPdu->nackInfo[RLC_MAX_NACK_CNT-1].sn + 1) & (rbCb->m.amUl.snModMask);
1111 /* Parse & send Status PDU to RLC-DL */
1112 rlcUlUdxStaUpdReq(&(sapCb->pst), sapCb->spId, &rbCb->rlcId, pStaPdu);
1118 * @brief Private handler to release all stored segments
1121 * Private handler invokded by rlcAmmUlPlacePduInRecBuf to release the
1122 * stored segements in case a complete PDU is received later.
1124 * @param[in] gCb RLC instance control block
1125 * @param[in] recBuf Buffer that stores a received PDU or segments
1130 static void rlcAmmUlRlsAllSegs(RlcCb *gCb, RlcAmRecBuf *recBuf)
1134 RLC_LLIST_FIRST_SEG(recBuf->segLst, seg);
1135 while (seg != NULLP)
1137 RLC_FREE_BUF_WC(seg->seg);
1138 cmLListDelFrm(&(recBuf->segLst),&(seg->lstEnt));
1139 RLC_FREE_WC(gCb,seg, sizeof(RlcSeg));
1140 RLC_LLIST_FIRST_SEG(recBuf->segLst, seg);
1147 * @brief Private handler to store the received segment
1150 * Private handler invokded by rlcAmmUlPlacePduInRecBuf to add a received
1151 * segment in reception buffer of a RBCB.
1152 * - It is responsible for detecting duplicate segments
1153 * - Adding it at appropriate position in the received buffer
1154 * - Calling ExpByteSeg to set expSo field in the receiver buffer
1156 * @param[in] gCb RLC instance control block
1157 * @param[in] rbCb Radio Bearer Contro Block
1158 * @param[in] amHdr AM Header received
1159 * @param[in] pdu Buffer received other than the headers
1160 * @param[in] pduSz size of the PDU buffer received
1163 * -#TRUE Successful insertion into the receiver buffer
1164 * -#FALSE Possibly a duplicate segment
1166 static bool rlcAmmAddRcvdSeg(RlcCb *gCb, RlcUlRbCb *rbCb, RlcAmHdr *amHdr, Buffer *pdu, uint16_t pduSz)
1168 RlcAmRecBuf *recBuf = NULLP;
1171 uint16_t soEnd; /* Holds the SoEnd of received segment */
1172 uint16_t expSo = 0; /* Expected SO */
1174 soEnd = amHdr->so + pduSz - 1;
1175 recBuf = rlcUtlGetRecBuf(AMUL.recBufLst, amHdr->sn);
1177 if (NULLP == recBuf)
1179 RLC_ALLOC(gCb,recBuf, sizeof(RlcAmRecBuf));
1180 #if (ERRCLASS & ERRCLS_ADD_RES)
1181 if (recBuf == NULLP)
1183 DU_LOG("\nRLC: rlcAmmAddRcvdSeg: Memory allocation failed UEID:%d CELLID:%d",
1184 rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1189 #endif /* ERRCLASS & ERRCLS_RES */
1190 rlcUtlStoreRecBuf(AMUL.recBufLst, recBuf, amHdr->sn);
1194 if (recBuf->allRcvd == TRUE)
1201 recBuf->isDelvUpperLayer = FALSE;
1202 /* kw003.201 - Move past the segments that are different than the */
1204 RLC_LLIST_FIRST_SEG(recBuf->segLst, seg);
1205 while ((seg != NULLP) && (seg->amHdr.so < amHdr->so))
1207 expSo = seg->amHdr.so + seg->segSz;
1208 RLC_LLIST_NEXT_SEG(recBuf->segLst, seg);
1211 /* The received segment should start after the end of previous seg */
1212 if (expSo > amHdr->so)
1214 /* This is a duplicate segment */
1215 gRlcStats.amRlcStats.numRlcAmCellDupPduRx++;
1220 if ((seg) && (seg->amHdr.so <= soEnd))
1222 /* This is a duplicate segment */
1223 gRlcStats.amRlcStats.numRlcAmCellDupPduRx++;
1228 /* If we have come this far, we have to add this segment to the */
1229 /* reception buffer as we either have eliminated duplicates or */
1230 /* have found none. */
1231 RLC_ALLOC_WC(gCb,tseg, sizeof(RlcSeg));
1232 #if (ERRCLASS & ERRCLS_ADD_RES)
1235 DU_LOG("\nRLC: rlcAmmAddRcvdSeg: Memory allocation failed UEID:%d CELLID:%d",
1236 rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1240 #endif /* ERRCLASS & ERRCLS_RES */
1243 tseg->segSz = pduSz;
1244 RLC_MEM_CPY(&tseg->amHdr, amHdr, sizeof(RlcAmHdr));
1245 recBuf->amHdr.si = amHdr->si;
1246 recBuf->amHdr.sn = amHdr->sn;
1247 tseg->soEnd = soEnd;
1250 cmLListAdd2Tail(&recBuf->segLst, &tseg->lstEnt);
1254 recBuf->segLst.crnt = &seg->lstEnt;
1255 cmLListInsCrnt(&recBuf->segLst, &tseg->lstEnt);
1257 tseg->lstEnt.node = (PTR)tseg;
1258 rlcAmmUpdExpByteSeg(gCb,&AMUL,tseg);
1264 * @brief Private handler to place the PDU in the reception buffer
1267 * This function checks if the received PDU's SN falls within the
1268 * receiving window, after which it places the same in the reception
1269 * buffer if its not a duplicate.
1271 * @param[in] gCb RLC instance control block
1272 * @param[in] pdu Received PDU
1273 * @param[in] rbCb Uplink AM Radio Bearer
1274 * @param[out] amUl AM UL Info
1281 static bool rlcAmmUlPlacePduInRecBuf(RlcCb *gCb, Buffer *pdu, RlcUlRbCb *rbCb, RlcAmHdr *amHdr)
1285 RlcAmUl *amUl = &(rbCb->m.amUl);
1288 SFndLenMsg(pdu, &pduSz);
1290 gCb->genSts.bytesRecv += pduSz;
1291 gRlcStats.amRlcStats.numRlcAmCellSduBytesRx += pduSz;
1292 if (!RLC_AM_CHK_SN_WITHIN_RECV_WINDOW(sn, amUl))
1294 gRlcStats.amRlcStats.numRlcAmCellDropOutWinRx++;
1295 DU_LOG("\nRLC: rlcAmmUlPlacePduInRecBuf: SN %d outside the window"
1296 "UEID:%d CELLID:%d", sn, rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1298 gCb->genSts.unexpPdusRecv++;
1305 RlcAmRecBuf *recBuf = rlcUtlGetRecBuf(amUl->recBufLst, sn);
1307 /* We received a complete PDU. Either we already have it, in which */
1308 /* case we just ignore the new PDU and discard it. Otherwise, */
1309 /* store the received PDU in the reception buffer */
1310 if (NULLP == recBuf)
1312 RLC_ALLOC(gCb, recBuf, sizeof(RlcAmRecBuf));
1313 #if (ERRCLASS & ERRCLS_ADD_RES)
1314 if (recBuf == NULLP)
1316 DU_LOG("\nRLC: rlcAmmUlPlacePduInRecBuf: Memory allocation failed \
1317 UEID:%d CELLID:%d", rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1321 #endif /* ERRCLASS & ERRCLS_RES */
1322 rlcUtlStoreRecBuf(AMUL.recBufLst, recBuf, sn);
1324 else if (recBuf->allRcvd != TRUE)
1326 rlcAmmUlRlsAllSegs(gCb,recBuf);
1330 gRlcStats.amRlcStats.numRlcAmCellDupPduRx++;
1331 gCb->genSts.unexpPdusRecv++;
1335 recBuf->isDelvUpperLayer = FALSE;
1337 recBuf->pduSz = pduSz;
1338 recBuf->allRcvd = TRUE;
1339 gRlcStats.amRlcStats.numRlcAmCellSduRx++;
1340 RLC_MEM_CPY(&recBuf->amHdr, amHdr, sizeof(RlcAmHdr));
1345 /* We received a segment. We need to add that to the existing */
1346 /* segments, if any. */
1347 return (rlcAmmAddRcvdSeg(gCb,rbCb, amHdr, pdu, pduSz));
1352 * @brief Private handler to trigger status report
1355 * Private handler invokded by rlcAmmProcessPdus to check if the
1356 * status report need to be sent, and update the status trigger
1357 * flag accordingly based on status prohibit timer.
1359 * - Check if the received pdu's sn is less than rxHighestStatus, set the
1361 * - If staProhTmr is not running, calculate cntrlBo, else it'll be
1362 * updated at the expiry of staProhTmr.
1363 * - Expiry of reOrdTmr also will set staTrg flag.
1365 * @param[in] gCb RLC instance control block
1366 * @param[in] rbCb Uplink RB control block
1367 * @param[in] sn Sequence number of the pdu based on which to check if
1368 * status needs to be triggered
1369 * @param[in] discFlg Whether this pdu was discarded or not
1374 static void rlcAmmTriggerStatus(RlcCb *gCb, RlcUlRbCb *rbCb, RlcSn sn, bool discFlg)
1379 RlcSn trxHighestStatus;
1380 RlcAmUl *amUl = &(rbCb->m.amUl);
1382 MODAMR(amUl->vrMr, tVrMr, amUl->rxNext, amUl->snModMask);
1383 MODAMR(amUl->rxHighestStatus, trxHighestStatus, amUl->rxNext, amUl->snModMask);
1384 MODAMR(sn , tSn, amUl->rxNext, amUl->snModMask);
1386 /* kw005.201 Product CR ccpu00117114 *
1387 * The "=" in the 2nd condition is removed */
1388 if ((discFlg) || (tSn < trxHighestStatus) || (tSn >= tVrMr))
1390 DU_LOG("\nRLC: rlcAmmTriggerStatus: Set Status Trigger UEID:%d CELLID:%d",
1391 rbCb->rlcId.ueId, rbCb->rlcId.cellId);
1393 amUl->staTrg = TRUE;
1394 amUl->gatherStaPduInfo = FALSE;
1396 /* Check if staProhTmr is running */
1397 tmrRunning = rlcChkTmr(gCb,(PTR) rbCb, RLC_EVT_AMUL_STA_PROH_TMR);
1401 amUl->gatherStaPduInfo = TRUE;
1409 * @brief Private handler to reassemble from a segment or a PDU
1412 * Private handler invokded by kwAmmReassembleSdus with either a
1413 * PDU or a segment of a PDU. This is also called in the case of
1414 * reestablishment and hence out of sequence joining is also to
1418 * @param[in] gCb RLC instance control block
1419 * @param[in] rbCb Uplink RB control block
1420 * @param[in] amHdr AM header received for this segment/PDU
1421 * @param[in] pdu PDU to be reassembled
1426 static void rlcAmmProcPduOrSeg(RlcCb *gCb, RlcUlRbCb *rbCb, RlcAmHdr *amHdr, Buffer *pdu)
1429 if ((AMUL.expSn != amHdr->sn) || (AMUL.expSo != amHdr->so))
1431 /* Release the existing partial SDU as we have PDUs or */
1432 /* segments that are out of sequence */
1433 rbCb->m.amUl.isOutOfSeq = TRUE;
1434 RLC_FREE_BUF(AMUL.partialSdu);
1437 //if (amHdr->fi & RLC_FI_FIRST_SEG)
1438 if (amHdr->si == 0x01)
1439 {/* first Segment of the SDU */
1440 if (AMUL.partialSdu != NULLP)
1441 { /* Some old SDU may be present */
1442 RLC_FREE_BUF_WC(AMUL.partialSdu);
1444 AMUL.partialSdu = pdu;
1447 else if(amHdr->si == 0x03)
1448 {/* Middle or last segment of the SUD */
1449 ODU_CAT_MSG(AMUL.partialSdu,pdu, M1M2);
1450 RLC_FREE_BUF_WC(pdu);
1453 else if (amHdr->si == 0x02)
1455 ODU_CAT_MSG(pdu,AMUL.partialSdu,M2M1);
1456 RLC_FREE_BUF_WC(AMUL.partialSdu);
1461 AMUL.partialSdu = NULLP;
1462 rlcUtlSendUlDataToDu(gCb,rbCb, pdu);
1470 * @brief Private handler to reassemble SDUs
1473 * Private handler invokded by rlcAmmProcessPdus with the PDU
1474 * from the reception buffer in sequence to reassemble SDUs and
1477 * - With the stored header info, FI and LSF segment / concatenate
1478 * PDUs or byte segments of PDUs to get the associated SDU.
1480 * @param[in] rbCb RB control block
1481 * @param[in] pdu PDU to be reassembled
1488 static uint8_t rlcAmmUlReassembleSdus(RlcCb *gCb, RlcUlRbCb *rbCb, RlcAmRecBuf *recBuf)
1492 //if (recBuf->amHdr.rf == 0)
1493 if (recBuf->amHdr.si == 0)
1496 rlcAmmProcPduOrSeg(gCb,rbCb, &recBuf->amHdr, recBuf->pdu);
1497 /* Assign NULLP to recBuf->pdu as this PDU is sent to PDCP */
1498 recBuf->pdu = NULLP;
1499 AMUL.expSn = (recBuf->amHdr.sn + 1) & (AMUL.snModMask); /* MOD 1024 */
1504 /* This is a set of segments */
1505 RLC_LLIST_FIRST_SEG(recBuf->segLst, seg);
1506 AMUL.expSn = recBuf->amHdr.sn;
1510 rlcAmmProcPduOrSeg(gCb,rbCb, &seg->amHdr, seg->seg);
1511 AMUL.expSo = seg->soEnd + 1;
1513 cmLListDelFrm(&(recBuf->segLst),&(seg->lstEnt));
1514 RLC_FREE_WC(gCb, seg, sizeof(RlcSeg));
1516 RLC_LLIST_FIRST_SEG(recBuf->segLst, seg);
1518 AMUL.expSn = (recBuf->amHdr.sn + 1) & (AMUL.snModMask); /* MOD 1024 */
1526 * @brief Handler to process the re-establishment request received from UIM
1528 * @param[in] gCb RLC instance control block
1529 * @param[in] rlcId RLC identifier
1530 * @param[in] sendReEst Whether to send back restablishment complete or not
1531 * @param[in] rbCb Uplink RB control block
1536 Void rlcAmmUlReEstablish(RlcCb *gCb,CmLteRlcId rlcId,Bool sendReEst,RlcUlRbCb *rbCb)
1543 RlcKwuSapCb *rlcKwuSap;
1545 RlcAmRecBuf *recBuf = NULLP;
1549 MODAMR(AMUL.vrMr, mVrMr, AMUL.rxNext, AMUL.snModMask);
1550 MODAMR(sn, mSn, AMUL.rxNext, AMUL.snModMask);
1552 /* Reassemble SDUs from PDUs with SN less than upper edge of the window */
1555 recBuf = rlcUtlGetRecBuf(AMUL.recBufLst, sn);
1556 if (NULLP != recBuf)
1558 if (recBuf->allRcvd == TRUE)
1560 rlcAmmUlReassembleSdus(gCb,rbCb, recBuf);
1564 /* Remove PDU and segments */
1567 RLC_FREE_BUF_WC(recBuf->pdu);
1569 /* Release all the segments*/
1570 rlcAmmUlRlsAllSegs(gCb,recBuf);
1572 rlcUtlDelRecBuf(AMUL.recBufLst, recBuf, gCb);
1574 sn = (sn + 1) & (AMUL.snModMask); /* MOD 1024 */
1575 MODAMR(sn, mSn, AMUL.rxNext, AMUL.snModMask);
1577 /* Discard remaining PDUs and bytesegments in recBuf */
1579 /* Stop all timers and reset variables */
1580 if(TRUE == rlcChkTmr(gCb,(PTR)rbCb,RLC_EVT_AMUL_REORD_TMR))
1582 rlcStopTmr(gCb,(PTR)rbCb, RLC_EVT_AMUL_REORD_TMR);
1584 if(TRUE == rlcChkTmr(gCb,(PTR)rbCb,RLC_EVT_AMUL_STA_PROH_TMR))
1586 rlcStopTmr(gCb,(PTR)rbCb, RLC_EVT_AMUL_STA_PROH_TMR);
1590 AMUL.rxNextHighestRcvd = 0;
1591 AMUL.rxNextStatusTrig = 0;
1592 rbCb->m.amUl.vrMr = (rbCb->m.amUl.rxNext + RLC_AM_GET_WIN_SZ(rbCb->m.amUl.snLen)) & (rbCb->m.amUl.snModMask);
1593 AMUL.rxHighestStatus = 0;
1594 AMUL.staTrg = FALSE;
1595 AMUL.gatherStaPduInfo = FALSE;
1598 if (AMUL.partialSdu != NULLP)
1600 RLC_FREE_BUF(AMUL.partialSdu);
1602 rlcKwuSap = gCb->u.ulCb->rlcKwuUlSap + RLC_UI_PDCP;
1606 RlcUiKwuReEstCmpInd(&rlcKwuSap->pst, rlcKwuSap->suId, rlcId);
1607 rbCb->m.amUl.isOutOfSeq = FALSE;
1614 * @brief Handler for reorder timer expiry
1617 * This function is used to handle events upon expiry of reorder timer
1619 * @param[in] gCb RLC instance control block
1620 * @param[in] rbCb RB control block
1626 Void rlcAmmReOrdTmrExp(RlcCb *gCb,RlcUlRbCb *rbCb)
1628 RlcAmUl *amUl = &(rbCb->m.amUl);
1632 RlcSn mrxHighestStatus;
1633 RlcSn mrxNextHighestRcvd;
1634 Bool tmrRunning = FALSE;
1635 RlcAmRecBuf *recBuf = NULLP;
1637 /* Update rxHighestStatus */
1638 sn = amUl->rxNextStatusTrig;
1640 MODAMR(sn, mSn, amUl->rxNext, amUl->snModMask);
1641 MODAMR(amUl->vrMr, mVrMr, amUl->rxNext, amUl->snModMask);
1642 recBuf = rlcUtlGetRecBuf(AMUL.recBufLst, sn);
1646 if ((recBuf == NULLP) ||
1647 ((recBuf != NULLP) && (!recBuf->allRcvd)) )
1649 amUl->rxHighestStatus = sn;
1650 amUl->staTrg = TRUE;
1651 amUl->gatherStaPduInfo = FALSE;
1653 /* Check if staProhTmr is running */
1654 tmrRunning = rlcChkTmr(gCb,(PTR) rbCb, RLC_EVT_AMUL_STA_PROH_TMR);
1658 gRlcStats.amRlcStats.numULReOrdTimerExpires++;
1659 amUl->gatherStaPduInfo = TRUE;
1660 rlcAmmUlAssembleCntrlInfo(gCb, rbCb);
1665 sn = (sn + 1) & (amUl->snModMask);
1666 MODAMR(sn, mSn, amUl->rxNext, amUl->snModMask);
1669 /* Update rxNextStatusTrig */
1670 MODAMR(amUl->rxNextHighestRcvd, mrxNextHighestRcvd, amUl->rxNext, amUl->snModMask);
1671 MODAMR(amUl->rxHighestStatus, mrxHighestStatus, amUl->rxNext, amUl->snModMask);
1672 if (mrxNextHighestRcvd > mrxHighestStatus)
1674 rlcStartTmr(gCb,(PTR)rbCb, RLC_EVT_AMUL_REORD_TMR);
1675 amUl->rxNextStatusTrig = amUl->rxNextHighestRcvd;
1679 } /* rlcAmmReOrdTmrExp */
1682 * @brief Handler for status prohibit timer expiry
1685 * This function is used to handle events upon expiry of status prohibit
1688 * @param[in] gCb RLC instance control block
1689 * @param[in] rbCb RB control block
1695 Void rlcAmmStaProTmrExp(RlcCb *gCb,RlcUlRbCb *rbCb)
1697 RlcAmUl *amUl = &(rbCb->m.amUl);
1699 amUl->gatherStaPduInfo = FALSE;
1701 if (amUl->staTrg == TRUE)
1703 amUl->gatherStaPduInfo = TRUE;
1704 /* kw002.201 : Sending StaRsp after StaProhibit tmr expiry */
1705 rlcAmmUlAssembleCntrlInfo(gCb,rbCb);
1709 } /* rlcAmmStaProTmrExp */
1712 * @brief Handler to extract an element of AM Header
1715 * This function is used to extract an element of AM header.
1717 * @param[in] pdu The pdu to be decoded
1718 * @param[in,out] hdrInfo Container to hold the decoded info
1724 static void rlcAmmExtractElmnt(RlcCb *gCb, Buffer *pdu, RlcExtHdr *hdrInfo)
1727 uint8_t pLen = hdrInfo->pLen;
1728 uint8_t len = (uint8_t)hdrInfo->len;
1733 /* uint8_t rLen1 = 0; */
1740 ODU_REM_PRE_MSG(&hdr, pdu);
1746 val = tHdr >> (RLC_BYTE_LEN - (len));
1750 else /*if (len > 8) */
1754 val = val >> (RLC_BYTE_LEN - fLen);
1755 val = val << (len - fLen);
1757 ODU_REM_PRE_MSG(&hdr, pdu);
1761 hdr = hdr >> (RLC_BYTE_LEN - rLen);
1764 pLen = (RLC_BYTE_LEN - rLen);
1768 rLen = rLen - RLC_BYTE_LEN;
1770 tVal = tVal << rLen;
1773 ODU_REM_PRE_MSG(&hdr, pdu);
1775 hdr = hdr >> (RLC_BYTE_LEN - rLen);
1778 pLen = (RLC_BYTE_LEN - rLen);
1782 hdrInfo->pLen = pLen;
1790 * @brief Handler to updated expected byte seg
1793 * This function is used to update expected byte segment. The next segment
1794 * expected is indicated by the SO of the segment which is expected. Intially
1795 * the segment with SO 0 is expected and then in order. When all the segments
1796 * are received (which would happen when an expected SO is encountered
1797 * with LSF set) the allRcvd flag is set to TRUE
1799 * @param[in] gCb RLC instance control block
1800 * @param[in] amUl AM Uplink Control Block
1801 * @param[in] seg Newly received segment
1807 static void rlcAmmUpdExpByteSeg(RlcCb *gCb, RlcAmUl *amUl, RlcSeg *seg)
1809 uint16_t newExpSo; /* The new expected SO */
1810 RlcSn sn = seg->amHdr.sn;
1812 RlcAmRecBuf *recBuf = NULLP;
1814 recBuf = rlcUtlGetRecBuf(amUl->recBufLst, sn);
1815 if ((recBuf == NULLP) || (recBuf && (seg->amHdr.so != recBuf->expSo)))
1820 newExpSo = seg->soEnd + 1;
1821 recBuf->expSo = newExpSo;
1822 //lstRcvd = seg->amHdr.lsf;
1823 if(seg->amHdr.si == 0x2)
1827 /* kw003.201 - This should update seg with the one after newSeg */
1828 RLC_LLIST_NEXT_SEG(recBuf->segLst, seg);
1831 /* keep going ahead as long as the expectedSo match with the header so
1832 else store the expSo for later checking again */
1833 if(seg->amHdr.si == 0x2)
1837 if (seg->amHdr.so == newExpSo)
1839 newExpSo = seg->soEnd + 1;
1840 recBuf->expSo = newExpSo;
1841 //lstRcvd = seg->amHdr.lsf;
1842 RLC_LLIST_NEXT_SEG(recBuf->segLst, seg);
1846 recBuf->expSo = newExpSo;
1850 if (lstRcvd == TRUE)
1852 recBuf->allRcvd = TRUE;
1853 gRlcStats.amRlcStats.numRlcAmCellSduRx++;
1861 * Function to release/free the Acknowledged Mode Module RbCb buffers
1864 * This primitive Frees the AM RbCb transmission Buffer, retransmission
1865 * Buffer and reciption Buffers
1867 * @param [in] gCb - RLC instance Control Block
1868 * @param [in] rbCb - RB Control Block
1872 Void rlcAmmFreeUlRbCb(RlcCb *gCb,RlcUlRbCb *rbCb)
1874 RlcSn curSn = 0; /* Sequence number of PDU */
1875 RlcSn windSz; /* PDU window size */
1876 RlcAmRecBuf *recBuf = NULLP;
1878 windSz = (RLC_AM_GET_WIN_SZ(rbCb->m.amUl.snLen)) << 1;
1880 if(TRUE == rlcChkTmr(gCb,(PTR)rbCb,RLC_EVT_AMUL_REORD_TMR))
1882 rlcStopTmr(gCb,(PTR)rbCb, RLC_EVT_AMUL_REORD_TMR);
1884 if(TRUE == rlcChkTmr(gCb,(PTR)rbCb,RLC_EVT_AMUL_STA_PROH_TMR))
1886 rlcStopTmr(gCb,(PTR)rbCb, RLC_EVT_AMUL_STA_PROH_TMR);
1890 /* on the first loop winSz is always greater than zero
1891 while( ( curSn < windSz ) hence changing to do while */
1894 recBuf = rlcUtlGetRecBuf(rbCb->m.amUl.recBufLst, curSn);
1895 if ( recBuf != NULLP )
1897 if (recBuf->pdu != NULLP)
1899 RLC_FREE_BUF_WC(recBuf->pdu);
1901 /* Release all the segments */
1902 rlcAmmUlRlsAllSegs(gCb,recBuf);
1903 rlcUtlDelRecBuf(rbCb->m.amUl.recBufLst, recBuf, gCb);
1906 }while ( curSn < windSz );
1909 RLC_FREE_WC(gCb,rbCb->m.amUl.recBufLst, (RLC_RCV_BUF_BIN_SIZE * sizeof(CmLListCp)));
1910 rbCb->m.amUl.recBufLst = NULLP;
1913 if(rbCb->m.amUl.partialSdu != NULLP)
1915 RLC_FREE_BUF_WC(rbCb->m.amUl.partialSdu);
1918 } /* rlcAmmFreeUlRbCb */
1924 /********************************************************************30**
1927 **********************************************************************/