Committing in PDCP code
[o-du/l2.git] / src / 5gnrpdcp / pj.h
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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 *******************************************************************************/
18
19 /********************************************************************20**
20   
21         Name:     LTE PDCP file 
22     
23         Type:     C include file
24   
25         Desc:     This file contain the hash definations for PDCP 
26  
27         File:     pj.h
28
29   
30 *********************************************************************21*/
31 /** @file pj.h
32 @brief PDCP Hash definitions
33 */
34
35 #ifndef __PJH__
36 #define __PJH__
37
38 #include "rl_interface.h"
39 #include "rl_common.h"
40 #include "rl_rlog.h"
41
42 \f 
43 #define PJLAYERNAME   "LTE PDCP"     /* Layer Name */
44
45 #define EPJxxx 1
46 #define PJ_TMR_LEN                     10
47 #define PJ_MAX_KWUSAPS        2     /*!< Maximum number of KWU Saps. */
48 #define PJ_MAX_UDXSAPS        1     
49 #define PJ_MAX_RB_PER_CELL          10
50 #define PJ_MAX_SRB_PER_UE           3
51 #define PJ_MAX_DRB_PER_UE           32
52 #define PJ_MAX_LCH_PER_UE           12
53 #define PJ_MAX_LCH_PER_CELL         6
54 #define PJ_MAX_NUM_RB               24
55 #define PJ_MAX_UE                   0xffffffff 
56 #define PJ_UE_LIST_BUCKET_SIZE      128 
57 #define PJ_CELL_LIST_BUCKET_SIZE    10 
58 #define PJ_MAX_RB                   32
59 #define PJ_DEF_SEQ_NUM 0
60 #define PJ_ASYNC_WIN                 16
61
62 #define PJ_MAX_CPJSAPS        1     /*!< Maximum number of CPJ Saps. */
63 #define PJ_MAX_PJUSAPS        2     /*!< Maximum number of PJU Saps. */
64
65 #define PJ_LMM_GENCFG_DONE    2     /*!< PDCP LM general configuraiton done. */
66
67 #define PJ_PDCP_MODE_DL     1  
68 #define PJ_PDCP_MODE_UL     2
69
70 /* Direction defines */
71 #define PJ_DIR_UL        1     /*!< Unlink direction */
72 #define PJ_DIR_DL        2     /*!< Downlink direction */
73 #define PJ_DIR_BOTH      3     /*!< Both Downlink and Unlink */
74
75 #define PJ_DBG_SUB_MASK   DBGMASK_MI               /* Use for sub-mask */
76 #define PJ_DBGMASK_DETAIL (PJ_DBG_SUB_MASK << 0)   /* Parameters, It will give
77                                                       in depth info */
78 #define PJ_DBGMASK_BRIEF  (PJ_DBG_SUB_MASK << 1)   /* Info, It will give info at
79                                                       entry and exit places along
80                                                       with certain state changes */
81 #define PJ_DBGMASK_ERROR  (PJ_DBG_SUB_MASK << 2)   /* Error information */
82 #define PJ_DBGMASK_FATAL  (PJ_DBG_SUB_MASK << 3)   /* FATAL errors like memory
83                                                       resource failure etc., */
84
85
86 #define PJ_DBG_MDL_MASK   (PJ_DBG_SUB_MASK << 4) 
87
88 #define PJ_DBGMASK_DLM         (PJ_DBG_MDL_MASK << 0) /* DL */
89 #define PJ_DBGMASK_ULM         (PJ_DBG_MDL_MASK << 1) /* UL */
90 #define PJ_DBGMASK_UTL         (PJ_DBG_MDL_MASK << 2) /* DBM, UTL, TMR */
91 #define PJ_DBGMASK_CFG         (PJ_DBG_MDL_MASK << 3) /* LMM and CFG */
92 #define PJ_DBGMASK_LIB         (PJ_DBG_MDL_MASK << 4) /* LIB - means software
93                                                                or offboard hooks */
94 #define PJ_DBGMASK_INF         (PJ_DBG_MDL_MASK << 5)
95 #define PJ_DBGMASK_LMM         (PJ_DBG_MDL_MASK << 6)
96 #define PJ_DBGMASK_DL         (PJ_DBG_MDL_MASK << 7)
97 #define PJ_DBGMASK_UL         (PJ_DBG_MDL_MASK << 8)
98
99
100 #ifdef TENB_T2K3K_SPECIFIC_CHANGES
101
102 #define ICC_POOL_ZERO_SIZE 384
103 #define ICC_POOL_ONE_SIZE  1920
104 #define ICC_POOL_TWO_SIZE  3968
105 #define ICC_POOL_THREE_SIZE  16256
106 #endif /* TENB_T2K3K_SPECIFIC_CHANGES */
107
108 #ifdef DEBUGP
109 #define _pjPBuf   pjCb.init.prntBuf
110
111 #define PJ_PRNT(_cb,_prntbuf)      \
112 {                              \
113    sprintf _prntbuf;           \
114    SPrint(_cb->init.prntBuf);            \
115 }
116
117 #else  /* DEBUGP */ 
118 #define PJ_PRNT_HLINE(_pMsg)
119 #define PJ_PRNT(_cb,_prntbuf)
120 #define PJ_PRNT_TSTAMP
121 #define PJ_PRNT_MBUF(_mBufPtr)
122 #define PJ_PRNT_MEMINFO
123 #endif /* DEBUGP */
124
125 #ifdef DEBUGP
126 #define PJ_PRNT_HLINE(_pMsg)                                        \
127 {                                                                   \
128    sprintf(_pjPBuf, "[PDCP_LAYER: %s:%d]::", __FILE__, __LINE__);  \
129    SPrint(_pjPBuf);                                                 \
130    sprintf(_pjPBuf, _pMsg);                                         \
131    SPrint(_pjPBuf);                                                 \
132 }
133
134 #define PJDBGP(_cb,_mask, _arg)                               \
135 do                                                            \
136 {                                                             \
137    if (!((_cb->init.dbgMask & _mask) ^ _mask))                \
138    {                                                          \
139       PJ_PRNT(_cb,_arg);                                          \
140    }                                                          \
141 }while(0)
142 #else /* DEBUGP */
143 #define PJ_PJ_PRNT_HLINE(_pMsg)
144 #define PJDBGP(_cb,_mask, _arg) 
145 #endif /* DEBUGP */
146
147
148 \f 
149 /************************************************************************
150  *                            SAP States
151  ************************************************************************/
152  
153 /* ############################PDCP DEFINES ############################# */
154
155 #define PJ_SAP_NOT_CFG        0     /*!< SAP Not Configured */
156 #define PJ_SAP_CFG            1     /*!< SAP Configured but not not bound */
157 #define PJ_SAP_BND            2     /*!< SAP Bound */
158 #define PJ_SAP_BINDING        3     /*!< SAP Bind initiated */
159 #define PJ_SAP_UBND           4     /*!< SAP Unbind */
160 #define PJ_MAX_SAP_BND_RETRY  3     /*!< Maximum SAP Bin Retries */
161
162 /* Times related */
163 #define PJ_RB_MAX_TIMERS       1       /* No of timers */
164 #define PJ_MAX_OBD_TMR         3       /* Number of OBD Timers */
165 #define PJ_MAX_DISC_TMR        1       /* Number of Discard Timers */
166 #define PJ_MAX_KWUSAP_TMR      1     /*!< Maximum number of KWU SAP Timers. */
167 #define PJ_EVT_WAIT_BNDCFM     0x01    /* Bind confirm timer */
168 #define PJ_MAX_UDXSAP_TMR      1     /*!< Maximum number of UDX SAP Timers. */
169 #define PJ_EVT_DL_OBD_TMR      0x11
170 #define PJ_EVT_UL_OBD_TMR      0x12
171 #define PJ_EVT_OBD_TMR         0x13
172 #define PJ_EVT_TMR_NONE        0x14
173 #define PJ_EVT_OBD_WAIT_TMR    0x15
174 #define PJ_EVT_UE_DEL_WAIT_TMR 0x16
175 /* kw005.201 added support for L2 Measurement */
176 #ifdef LTE_L2_MEAS
177 #define PJ_EVT_L2_TMR          0x20
178 #define PJ_EVT_L2_MEAS_TMR     0x17
179 #endif /* LTE_L2_MEAS */
180 #define PJ_EVT_UL_REORD_TMR    0x21
181 #define PJ_MAX_UL_REORD_TMRS   1 
182 #define PJ_EVT_WAIT_KWU_BNDCFM 0x18    
183 #define PJ_EVT_WAIT_UDX_BNDCFM 0x19
184 #define PJ_DRB_12BIT_SN_HDR    0x8000
185 #define PJ_DRB_18BIT_SN_HDR    0x800000 /*!<18 bit SN setting the hdr for DRB */
186 #define PJ_ROHC_FEEDBACK_HDR   0x0010
187 #define PJ_FIRST_BIT           0x80
188
189 #define PJ_DATA_PDU            0x01
190 #define PJ_ROHC_FEEDBACK       0x02
191 #define PJ_STA_PDU             0x03
192
193 #define PJ_INTG_KEY_LEN        16
194 #define PJ_CIPHER_KEY_LEN      16
195
196 /*#define PJ_MAX_DAT_CFM         512 */
197 /* changed from 512 to 1024 */
198 #define PJ_MAX_DAT_CFM         1024
199
200 #define PJ_SDU_RECEIVED        0x01
201 #define PJ_WAIT_FOR_INTPROT    0x02
202 #define PJ_WAIT_FOR_CMP        0x03
203 #define PJ_WAIT_FOR_CIPHER     0x04
204 #define PJ_PDU_CONSTRUCTED     0x05
205 #define PJ_PDU_SUBMITTED       0x06
206 #define PJ_TX_ENT_TO_DEL       0x07
207
208 #define PJ_12_BIT_SN           12
209 #define PJ_18_BIT_SN           18
210
211 #define PJ_TX_BUF_LEN          256
212 #define PJ_MAX_SDU_SIZE        8188
213
214 #define PJ_SRB                 PJ_SRB_SAP
215 #define PJ_DRB                 PJ_DRB_SAP
216
217 #define PJ_SRB_SAP             0
218 #define PJ_DRB_SAP             1
219
220 #define PJ_DRB_UM              2
221 #define PJ_DRB_AM              3
222
223 #define PJ_CFM_NOK             1
224 #define PJ_CFM_OK              0
225
226 #define PJ_GET_PJCB(_inst) pjCb[_inst];  
227 #define PJ_BYTE_LEN            8
228
229
230 #define PJ_SEC_DIR_UL          0
231 #define PJ_SEC_DIR_DL          1
232
233 #define PJ_PDU_CONSTRUCT_FAILED  1
234 #define PJ_HDR_COMP_FAILED       2
235 #define PJ_INTG_PROT_FAILED      3
236 #define PJ_CIPHER_FAILED         4
237 #define PJ_CPY_MSG_FAILED        5
238 #define PJ_REM_MSG_FAILED        6
239 #define PJ_DISC_TMR_EXP          7
240 #define PJ_OBD_TIMEOUT           8
241
242 #define PJ_CFG_RLC             1
243 #define PJ_CFG_PDCP            2
244 #define PJ_CFG_BOTH            3
245 #define PJ_TRANS_ID_LST_BKT_SIZE   10  
246
247 /* PJ_MS_KENB_LEN: Its the max lenght of the key for derivation of CK and IK */
248 /* PJ_MS_STR_S_LEN: Length of "STR S" which is one of the inputs for CK and IK dervation */ 
249 #define PJ_MS_KENB_LEN  32
250 #define PJ_MS_STR_S_LEN 9
251 #define PJ_NUM_BYTES_FRESH   4      /*<!Number of Bytes for FRESH variable */
252
253 #define PJ_KDF_SAP      0       /*!<Dummy SAP for KDF functionality*/
254
255
256 #define PJ_VALIDATE_RBID(_ueId, _rbId, _rbType, _ret)          \
257 {                                                              \
258    _ret = ROK;                                                 \
259    if (_ueId == 0)                                             \
260    {                                                           \
261       if (_rbId >= PJ_MAX_RB_PER_CELL)                         \
262       {                                                        \
263          _ret = RFAILED;                                       \
264       }                                                        \
265    }                                                           \
266    else                                                        \
267    {                                                           \
268       if ((_rbType != CM_LTE_SRB) && (_rbType != CM_LTE_DRB))  \
269       {                                                        \
270          _ret = RFAILED;                                       \
271       }                                                        \
272       else if (_rbType == CM_LTE_SRB &&_rbId >= PJ_MAX_SRB_PER_UE)  \
273       {                                                        \
274          _ret = RFAILED;                                       \
275       }                                                        \
276       else if (_rbType == CM_LTE_DRB &&_rbId >= PJ_MAX_DRB_PER_UE)  \
277       {                                                        \
278          _ret = RFAILED;                                       \
279       }                                                        \
280    }                                                           \
281 }
282
283 #define PJ_DBM_FETCH_RBCB(_rbId, _rbType, _ueCb, _rbCb)     \
284 {                                                           \
285   PjRbCb  **_rbCbLst;                                         \
286    _rbCbLst = (_rbType==CM_LTE_SRB)?_ueCb->srbCb:_ueCb->drbCb;\
287    if (_rbCbLst[_rbId] != NULLP)                            \
288    {                                                        \
289       _rbCb = _rbCbLst[_rbId];                              \
290    }                                                        \
291    else                                                     \
292    {                                                        \
293       _rbCb = NULLP;                                        \
294    }                                                        \
295 }
296 #define PJ_DBM_FETCH_CELL_RBCB(_rbId, _rbCbLst, _rbCb)     \
297 {                                                           \
298    if (_rbCbLst[_rbId] != NULLP)                            \
299    {                                                        \
300       _rbCb = _rbCbLst[_rbId];                              \
301    }                                                        \
302    else                                                     \
303    {                                                        \
304       _rbCb = NULLP;                                        \
305    }                                                        \
306 }
307
308 #define PJ_GET_UL_UDX_SAP(_cb) (&(_cb->u.ulCb->udxUlSap[0])) 
309
310 /* LMM Module Macros */
311 #define PJ_LMM_RB_STS_INC(_cb)                                    \
312 {                                                              \
313    _cb->pjGenSts.numOfRb++;                                      \
314 }
315
316 #define PJ_LMM_RB_STS_DEC(_cb)                                    \
317 {                                                              \
318    _cb->pjGenSts.numOfRb--;                                      \
319 }
320
321
322
323
324 /* kw005.201 moved the definition from kw_pj_dlm.c file */
325 #define PJ_PJ_ASYNC_WIN        16
326 #ifdef LTE_L2_MEAS
327 /* L2 Measurement index to be used in rbCb to store measData */                                       
328 #define PJ_L2MEAS_UL_LOSS 0
329 #define PJ_L2CPU_PERCORE_STATS 1
330 #define PJ_L2MEM_PERPOOL_STATS 2
331 #define PJ_L2MEAS_ACT_UE        3
332 #define PJ_L2MEAS_DL_DELAY      4
333 #define PJ_L2MEAS_DL_DISC       5
334 #define PJ_MAX_L2MEAS_INRB      6
335 #define PJ_L2MEAS_UU_LOSS      7
336 #define PJ_L2MEAS_DL_IP        8
337 #define PJ_L2MEAS_UL_IP        9
338
339 #define PJ_L2_MAX_TIMERS        1
340
341 #define PJ_MAX_L2MEAS_EVT       10
342 #define PJ_INIT_RB_L2CB(_measVal, _measCb, _pjRbCb)                       \
343 {                                                                         \
344    cmLListAdd2Tail(&_measCb->rbList, &_pjRbCb->rbL2Cb.listNode[_measVal]);\
345    _pjRbCb->rbL2Cb.l2Sts[_measVal] = &_measCb->measData[_pjRbCb->qci];    \
346 }
347
348 #define PJ_RMV_RB_FRM_L2LIST(_measVal, _measCb, _pjRbCb)          \
349 cmLListDelFrm(&_measCb->rbList,                                    \
350      &_pjRbCb->rbL2Cb.listNode[_measVal]);
351
352 #define PJ_UPD_L2_DLDELAY_STS(_pjRbCb, _val)                      \
353 {                                                                 \
354    _pjRbCb->rbL2Cb.l2Sts[PJ_L2MEAS_DL_DELAY]->dlDelay.numPkts++;          \
355    _pjRbCb->rbL2Cb.l2Sts[PJ_L2MEAS_DL_DELAY]->dlDelay.val += _val;        \
356 }                                          
357 #define PJ_UPD_L2_DLDISC_PKT_STS(_pjCb, _pjRbCb)                         \
358 {                                                                 \
359    if((_pjRbCb->rbType == PJ_DRB) &&                              \
360       ((_pjCb)->u.dlCb->pjL2Cb.measOn[_pjRbCb->qci] & LPJ_L2MEAS_DL_DISC))   \
361    {                                                              \
362       _pjRbCb->rbL2Cb.l2Sts[PJ_L2MEAS_DL_DISC]->dlDisc.numPkts++;     \
363    }                                                              \
364 }                                              
365
366 #define PJ_UPD_L2_DLDISC_STS(_pjCb, _pjRbCb)                             \
367 {                                                                 \
368    if((_pjRbCb->rbType == PJ_DRB) &&                              \
369       ((_pjCb)->u.dlCb->pjL2Cb.measOn[_pjRbCb->qci] & LPJ_L2MEAS_DL_DISC))   \
370    {                                                              \
371       _pjRbCb->rbL2Cb.l2Sts[PJ_L2MEAS_DL_DISC]->dlDisc.val++;      \
372    }                                                              \
373 }                                      
374
375 #define PJ_SEND_SAPID_ALARM(_cb,_sapId, _evnt, _cause) \
376 { \
377    pjLmmSendAlarm(_cb,LCM_CATEGORY_INTERFACE, _evnt, _cause, _sapId, 0, 0); \
378 }
379 #define PJ_SEND_UEID_ALARM(_ueId, _qci, _evnt, _cause) \
380 { \
381    pjLmmSendAlarm(LCM_CATEGORY_INTERFACE, _evnt, _cause, 0, _ueId, _qci); \
382 }
383
384 #define PJ_UPD_L2_DECR_PER_QCI_RB_COUNT(_pjCb, _pjRbCb)                 \
385 {                                                                 \
386    if(((_pjRbCb)->rbType == CM_LTE_DRB) &&                    \
387       ((_pjCb)->u.dlCb->pjL2Cb.measOn[_pjRbCb->qci] & LPJ_L2MEAS_DL_DISC))   \
388    {                                                              \
389       U32 idx1;                                                    \
390       for (idx1 = 0; idx1 < LPJ_MAX_L2MEAS; idx1++)                  \
391       {                                                           \
392          if(_pjCb->u.dlCb->pjL2Cb.pjL2EvtCb[idx1].measCb.measType & LPJ_L2MEAS_DL_DISC)                 \
393          {                                                        \
394             if(_pjCb->u.dlCb->pjL2Cb.pjL2EvtCb[idx1].measCb.measData[(_pjRbCb)->qci].totDrbsPerQci > 0) \
395             {                                                                                               \
396                _pjCb->u.dlCb->pjL2Cb.pjL2EvtCb[idx1].measCb.measData[(_pjRbCb)->qci].totDrbsPerQci--;   \
397                if (_pjCb->u.dlCb->pjL2Cb.pjL2EvtCb[idx1].measCb.measData[(_pjRbCb)->qci].totDrbsPerQci == 0) \
398                {                                                                                                 \
399                   _pjCb->u.dlCb->pjL2Cb.pjL2EvtCb[idx1].measCb.qci[(_pjRbCb)->qci] = 0;                      \
400                   cmMemset((U8 *)&_pjCb->u.dlCb->pjL2Cb.pjL2EvtCb[idx1].measCb.measData[(_pjRbCb)->qci], 0,  \
401                      sizeof(_pjCb->u.dlCb->pjL2Cb.pjL2EvtCb[idx1].measCb.measData[(_pjRbCb)->qci]));            \
402                }                                                                                                 \
403             }                                                                                                    \
404          }                                                                                                       \
405       }                                                                                                          \
406    }                                                                                                             \
407 }
408
409 #define PJ_GET_SN_DIFF(_expSn, _rcvdSn, _snLen, _diff)  \
410 {                                                       \
411    if(_expSn > _rcvdSn)                                 \
412    {                                                    \
413       _diff = _rcvdSn + (1 << _snLen) - _expSn;         \
414    }                                                    \
415    else                                                 \
416    {                                                    \
417       _diff = _rcvdSn - _expSn;                         \
418    }                                                    \
419 }
420
421 #define PJ_UPD_L2_ULLOSS_CNTRS(_cb,_count, _pjRbCb)                                  \
422 {                                                                                \
423    PjSn _sn;                                                                     \
424    U32 _hfn;                                                                     \
425    PJ_GET_SN_HFN(_count, _pjRbCb->snLen, _sn, _hfn)                              \
426    if(_cb->u.ulCb->pjL2Cb.measOn[_pjRbCb->qci] & LPJ_L2MEAS_UL_LOSS)                               \
427    {                                                                             \
428        U32 _diff;                                                                \
429        PJ_GET_SN_DIFF(_pjRbCb->ulCb.nxtSubSn, _sn, _pjRbCb->snLen, _diff)        \
430       _pjRbCb->rbL2Cb.l2Sts[PJ_L2MEAS_UL_LOSS]->ulLoss.numPkts += _diff + 1;     \
431       _pjRbCb->rbL2Cb.l2Sts[PJ_L2MEAS_UL_LOSS]->ulLoss.val += _diff;             \
432    }                                                                             \
433    _pjRbCb->ulCb.nxtSubSn = (_sn + 1) % (1 << _pjRbCb->snLen);                   \
434 }
435
436 #else /* LTE_L2_MEAS */
437 #define PJ_UPD_L2_DLDELAY_STS(_pjRbCb, _val)
438 #define PJ_UPD_L2_ULLOSS_PKT_STS(_pjRbCb) 
439 #define PJ_UPD_L2_ULLOSS_STS(_pjRbCb)
440 #define PJ_UPD_L2_DLDISC_PKT_STS(_pjCb,_pjRbCb)  
441 #define PJ_UPD_L2_DLDISC_STS(_pjCb,_pjRbCb)      
442 #define PJ_SEND_SAPID_ALARM(_cb,_sapId, _evnt, _cause)
443 #define PJ_SEND_UEID_ALARM(_ueId, _qci, _evnt, _cause)
444 #define PJ_UPD_L2_DECR_PER_QCI_RB_COUNT(_pjCb, _pjRbCb)
445 #define PJ_UPD_L2_ULLOSS_CNTRS(_cb, _count, _pjRbCb)
446 #endif /* LTE_L2_MEAS */
447 /* kw005.201 added support for L2 Measurement */
448 #ifdef LTE_L2_MEAS 
449 #if (ERRCLASS & ERRCLS_INT_PAR)
450 #define PJ_VALDATE_SAP(_cb, _chkSpId, _sap, _ret)                    \
451 {                                                                    \
452    if (_chkSpId != _sap->spId)                                       \
453    {                                                                 \
454       RLOG0(L_ERROR,"Sap Id Validation Failed.");                    \
455       _ret = RFAILED;                                                \
456    }                                                                 \
457    /* SAP state validation */                                        \
458    if(_sap->state != PJ_SAP_BND)                                     \
459    {                                                                 \
460       RLOG0(L_ERROR,"Sap State Invalid.");                           \
461       pjLmmSendAlarm(_cb, LCM_CATEGORY_INTERFACE, LCM_EVENT_UI_INV_EVT,   \
462             LCM_CAUSE_INV_STATE, 0, 0, 0);                           \
463       _ret = RFAILED;                                                \
464    }                                                                 \
465 }
466 #else /* ERRCLASS & ERRCLS_INT_PAR */
467 #define PJ_VALDATE_SAP(_cb, _chkSpId, _sap, _ret)                    \
468 {                                                                    \
469    /* SAP state validation */                                        \
470    if(_sap->state != PJ_SAP_BND)                                     \
471    {                                                                 \
472       RLOG0(L_ERROR,"Sap State Invalid.");                            \
473       pjLmmSendAlarm(_cb, LCM_CATEGORY_INTERFACE, LCM_EVENT_UI_INV_EVT,   \
474             LCM_CAUSE_INV_STATE, 0, 0, 0);                           \
475       _ret = RFAILED;                                                \
476    }                                                                 \
477 }
478 #endif /* ERRCLASS & ERRCLS_INT_PAR */                              
479 #else /* LTE_L2_MEAS */
480 #if (ERRCLASS & ERRCLS_INT_PAR)
481 #define PJ_VALDATE_SAP(_cb, _chkSpId, _sap, _ret)                    \
482 {                                                                    \
483    if (_chkSpId != _sap->spId)                                       \
484    {                                                                 \
485       RLOG0(L_ERROR,"Sap Id Validation Failed.");                     \
486       _ret = RFAILED;                                                \
487    }                                                                 \
488    /* SAP state validation */                                        \
489    if(_sap->state != PJ_SAP_BND)                                     \
490    {                                                                 \
491       RLOG0(L_ERROR,"Sap State Invalid.");                            \
492       pjLmmSendAlarm(_cb, LCM_CATEGORY_INTERFACE, LCM_EVENT_UI_INV_EVT,   \
493             LCM_CAUSE_INV_STATE, 0, 0);                              \
494       _ret = RFAILED;                                                \
495    }                                                                 \
496 }
497 #else /* ERRCLASS & ERRCLS_INT_PAR */
498 #define PJ_VALDATE_SAP(_cb, _chkSpId, _sap, _ret)                         \
499 {                                                                    \
500    /* SAP state validation */                                        \
501    if(_sap->state != PJ_SAP_BND)                                     \
502    {                                                                 \
503       RLOG0(L_ERROR,"Sap State Invalid.");                            \
504       pjLmmSendAlarm(_cb, LCM_CATEGORY_INTERFACE, LCM_EVENT_UI_INV_EVT,   \
505             LCM_CAUSE_INV_STATE, 0, 0);                              \
506       _ret = RFAILED;                                                \
507    }                                                                 \
508 }
509 #endif /* ERRCLASS & ERRCLS_INT_PAR */
510 #endif/* LTE_L2_MEAS */
511
512 #ifdef TENB_DPDK_BUF
513 #define PJ_FREE_FLAT_BUF(_cb, _buf)                                 \
514 {                                                                   \
515    if(((_buf)->len != 0) && ((_buf)->startAddr != NULLP))           \
516    {                                                                \
517       (Void) SPutSBufDpdk((Data *) (_buf)->startAddr);                \
518    }                                                                \
519 }
520 #else /* TENB_DPDK_BUF */
521 #ifdef INTEL_WLS
522
523 #define PJ_FREE_FLAT_BUF(_cb, _buf)                                 \
524 {                                                                   \
525    if(((_buf)->len != 0) && ((_buf)->startAddr != NULLP))           \
526    {                                                                \
527       (Void) SPutSBufWls(_cb->init.region, _cb->init.pool,             \
528             (Data *) (_buf)->startAddr, (Size)(2048));              \
529    }\
530 }
531 #else
532 #ifdef FLAT_BUFFER_OPT
533 #define PJ_FREE_FLAT_BUF(_cb, _buf) \
534 { \
535    if(((_buf)->len != 0) && ((_buf)->startAddr != NULLP))\
536    {\
537       (Void) SPutStaticBuffer(_cb->init.region, _cb->init.pool,   \
538             (Data *) (_buf)->startAddr, (Size)((_buf)->ptr - (_buf)->startAddr + (_buf)->len) , 0);                 \
539    }\
540 }
541 #endif /* FLAT_BUFFER_OPT */
542 #endif /* INTEL_WLS */
543 #endif /* TENB_DPDK_BUF */
544
545
546 #define PJ_FREE_SHRABL_BUF(_cb,_buf, _size)                          \
547 {                                                         \
548    if (_buf != NULLP)                                     \
549    {                                                      \
550       (Void) SPutStaticBuffer(_cb->init.region, _cb->init.pool,   \
551             (Data *) _buf, (Size) _size, 0);                 \
552       _buf = NULLP;                                       \
553    }                                                      \
554 }
555
556 #define PJ_ALLOC_SHRABL_BUF(_cb,_buf, _size)                                    \
557 {                                                                    \
558  if (SGetStaticBuffer(_cb->init.region, _cb->init.pool, (Data **)&_buf,      \
559                 (Size) _size, 0) == ROK)                                \
560    {                                                                 \
561       cmMemset((U8 *)(_buf), 0, _size);                              \
562    }                                                                 \
563    else                                                              \
564    {                                                                 \
565       (_buf) = NULLP;                                                \
566    }                                                                 \
567 }
568
569 #define PJ_ALLOC_SHRABL_BUF_WM(_cb,_buf, _size)                                    \
570 {                                                                    \
571  SGetStaticBuffer(_cb->init.region, _cb->init.pool, (Data **)&_buf,      \
572                 (Size) _size, 0);                                \
573 }
574
575 #ifndef XEON_SPECIFIC_CHANGES
576 #define PJ_FREE_SHRABL_BUF_PST(_region, _pool, _buf, _size)                          \
577 {                                                         \
578    if (_buf != NULLP)                                     \
579    {                                                      \
580       (Void) SPutStaticBuffer(_region, _pool,   \
581             (Data *) _buf, (Size) _size, 0);                 \
582       _buf = NULLP;                                       \
583    }                                                      \
584 }
585 #else
586 #define PJ_FREE_SHRABL_BUF_PST(_region, _pool, _buf, _size)           \
587 {                                                          \
588    if (_buf != NULLP)                                      \
589    {                                                       \
590       (Void) SPutSBuf(_region, _pool,                      \
591                       (Data *) _buf, (Size) _size);        \
592       _buf = NULLP;                                        \
593    }                                                       \
594 }     
595 #endif
596
597 #define PJ_ALLOC_SHRABL_BUF_PST(_region, _pool, _buf, _size)                                    \
598 {                                                                    \
599  SGetStaticBuffer(_region, _pool, (Data **)&_buf,      \
600                 (Size) _size, 0);                                \
601 }
602
603 #ifndef XEON_SPECIFIC_CHANGES                                       
604 #define PJ_ALLOC_BUF_SHRABL(_pst, _buf, _size, _ret)                   \
605 {                                                                   \
606       if(SGetStaticBuffer(_pst.region, _pst.pool, (Data **)&_buf,   \
607                (Size) _size, 0) != ROK)                             \
608       {                                                             \
609          _ret = RFAILED;                                            \
610       }                                                             \
611 }
612 #else
613 #define PJ_ALLOC_BUF_SHRABL(_pst, _buf, _size, _ret)                   \
614 {                                                                   \
615       if(SGetSBuf(_pst.region, _pst.pool, (Data **)&_buf,   \
616                (Size) _size) != ROK)                             \
617       {                                                             \
618          _ret = RFAILED;                                            \
619       }                                                             \
620 }
621 #endif
622
623 #define PJ_PJDBM_CREATE_RBCB(_rbCb,_rbCbLst, _rbId, _rbType)    \
624 {                                                               \
625     /* Allocate memory for rbCb */                              \
626    PJ_ALLOC(_rbCb, sizeof(RbCb));                               \
627                                                                 \
628    if ( rbCb != NULLP)                                          \
629    {                                                            \
630       _rbCbLst[_rbId] = (_rbCb);                                \
631       _rbCb->kwRbCb.rlcId.rbId = _rbId;                         \
632    }                                                            \
633 }                                                               
634
635 /* Macros for configuration module */
636 #define PJ_CFG_FILL_CFG_CFM(_entCfm, _rbId, _rbType, _status, _reason)   \
637 {                                                                        \
638    _entCfm->rbId  = _rbId;                                               \
639    _entCfm->rbType  = _rbType;                                           \
640    _entCfm->status = _status;                                            \
641    _entCfm->reason = _reason;                                            \
642 }
643
644 #define PJ_CFG_FILL_SECCFG_CFM(_entCfm, _ueId, _cellId, _transId, _status, _reason)  \
645 {                                                               \
646    _entCfm->ueId   = _ueId;                                     \
647    _entCfm->cellId = _cellId;                                   \
648    _entCfm->transId = _transId;                                 \
649    _entCfm->status = _status;                                   \
650    _entCfm->reason = _reason;                                   \
651 }
652
653 #define PJ_CFG_FILL_SDUSTA_CFM(_entCfm, _ueId, _cellId, _transId, _status, _reason)  \
654 {                                                               \
655    _entCfm->ueId   = _ueId;                                     \
656    _entCfm->cellId = _cellId;                                   \
657    _entCfm->transId = _transId;                                 \
658    _entCfm->status = _status;                                   \
659    _entCfm->reason = _reason;                                   \
660 }
661
662 #define PJ_CFG_FILL_REESTREQ_CFM(_entCfm, _ueId, _cellId, _transId, _status)  \
663 {                                                               \
664    _entCfm->ueId   = _ueId;                                     \
665    _entCfm->cellId = _cellId;                                   \
666    _entCfm->transId = _transId;                                 \
667    _entCfm->status = _status;                                   \
668 }
669 /*
670 #define PJ_UPD_COUNT(_pjRbCb, _sn, _txHfn, _count)         \
671 {                                                          \
672    _count = _txHfn << (_pjRbCb->snLen);                    \
673    _count |= _sn;                                       \
674 } */
675 #define PJ_ADD_PST_MSG(_pdu, _hdr, _size, _ret)            \
676 {                                                          \
677    Data _liByte;                                           \
678    S16  _bytes;                                            \
679    _bytes = _size - 1;                                     \
680    while (_bytes >= 0 )                                    \
681    {                                                       \
682       _liByte = (U8) (_hdr >> (8*_bytes));                 \
683       _ret = SAddPstMsg((Data )_liByte, _pdu);             \
684       if ( _ret != ROK )                                   \
685       {                                                    \
686          break;                                            \
687       }                                                    \
688       _bytes--;                                            \
689    }                                                       \
690 }
691
692 #define PJ_RESET_ALL_VAR(_pjRbCb)                          \
693 {                                                          \
694    _pjRbCb->dlCb.cfmExp   = 0;                             \
695    _pjRbCb->dlCb.count    = 0;                             \
696    _pjRbCb->dlCb.txNext  =  0;                             \
697 }
698
699 #define PJ_ALLOC(_cb, _buf, _size)                         \
700 {                                                          \
701  if (SGetSBuf(_cb->init.region, _cb->init.pool, (Data **)&_buf,\
702                 (Size) _size) == ROK)                      \
703    {                                                       \
704       cmMemset((U8 *)(_buf), 0, _size);                    \
705    }                                                       \
706    else                                                    \
707    {                                                       \
708       (_buf) = NULLP;                                      \
709    }                                                       \
710 }
711
712 #define PJ_ALLOC_WC(_cb, _buf, _size)\
713 { \
714  if (SGetSBuf(_cb->init.region, _cb->init.pool, (Data **)&_buf,\
715                 (Size) _size) != ROK)                      \
716    {                                                       \
717       (_buf) = NULLP;                                      \
718    }                                                       \
719 }
720
721
722 #define PJ_FREE_BUF(_buf)                                  \
723 {                                                          \
724    if (_buf != NULLP)                                      \
725    {                                                       \
726       SPutMsg(_buf);                                       \
727    }                                                       \
728    _buf = NULLP;                                           \
729 }
730
731 #define PJ_FREE(_cb, _buf, _size)                               \
732 {                                                          \
733    if (_buf != NULLP)                                      \
734    {                                                       \
735       (Void) SPutSBuf(_cb->init.region, _cb->init.pool,    \
736                          (Data *) _buf, (Size) _size);     \
737       _buf = NULLP;                                        \
738    }                                                       \
739 }     
740
741 #define PJ_PST_FREE(_region, _pool, _buf, _size)           \
742 {                                                          \
743    if (_buf != NULLP)                                      \
744    {                                                       \
745       (Void) SPutSBuf(_region, _pool,                      \
746                       (Data *) _buf, (Size) _size);        \
747       _buf = NULLP;                                        \
748    }                                                       \
749 }     
750                                                                                         
751 #define PJ_MEM_CPY(_dst, _src, _size)                      \
752 {                                                          \
753    cmMemcpy((U8*)_dst, (U8 *)_src, _size);                 \
754 }
755
756 #define PJ_DLM_UPD_VAR(_pjRbCb, _count)               \
757 {                                                          \
758    PjDlCb    *_dlCb;                                       \
759                                                            \
760    _dlCb   = &_pjRbCb->dlCb;                              \
761    _count  = _dlCb->txNext;                               \
762    if ( (++_dlCb->txNext) ==  0xFFFFFFFF)                 \
763    {                                                       \
764       _dlCb->txNext = 0;                                   \
765    }                                                       \
766 }
767 #define PJ_DLM_GET_SN(_pjRbCb, _count,_sn) \
768 {\
769    _sn    = (_count % ( _pjRbCb->maxTxSn));      \
770 }
771
772
773 #define PJ_FILL_CFM_OK(_cb,_pjRbCb, _fms, _datCfm)             \
774 {                                                          \
775    U32     _startCount = _pjRbCb->dlCb.cfmExp;             \
776    U32     _stopCount  = _pjRbCb->dlCb.cfmExp;             \
777    PjTxEnt *_ent;                                          \
778    _ent = (PjTxEnt *)pjDbmGetTxEntSn(_cb, &(_pjRbCb->dlCb.txBuf), _fms); \
779    if ( _ent != NULLP )                                    \
780    {                                                       \
781       _stopCount = _ent->count;                            \
782       _pjRbCb->dlCb.cfmExp = _ent->count;                  \
783       _pjRbCb->dlCb.nxtToSub = _ent->count;                \
784    }                                                       \
785    while ( _startCount < _stopCount )                      \
786    {                                                       \
787       _ent = (PjTxEnt *)pjDbmGetTxEnt(_cb, &(_pjRbCb->dlCb.txBuf), _startCount);\
788       if ( _ent != NULLP )                                 \
789       {                                                    \
790          if ( _pjRbCb->dlCb.cfmReqd)                       \
791          {                                                 \
792             _datCfm->cfmSta[_datCfm->numSdus].sduId  = _ent->sduId;\
793             _datCfm->cfmSta[_datCfm->numSdus].status = PJ_CFM_OK;\
794             _datCfm->numSdus++;                            \
795          }                                                 \
796          pjDbmDelTxEnt(_cb, &(pjRbCb->dlCb.txBuf), _ent->count);\
797       }                                                    \
798       _startCount++;                                       \
799    }                                                       \
800 }
801
802 #define PJ_UPD_CFM_EXP(_cb,_dlCb)                              \
803 {                                                          \
804    U32 _curCount = _dlCb->count;                            \
805    U32 _count    = _dlCb->cfmExp;                           \
806    PjTxEnt *_txEnt = NULLP;                                \
807    while ( _count <= _curCount )                           \
808    {                                                       \
809       _txEnt = (PjTxEnt *)pjDbmGetTxEnt(_cb,&(_dlCb->txBuf), _count);\
810       if ( _txEnt != NULLP )                               \
811       {                                                    \
812          break;                                            \
813       }                                                    \
814       _count++;                                            \
815    }                                                       \
816    _dlCb->cfmExp = _count;                                  \
817 }
818
819 #define PJ_UPD_DL_VAR(_cb, _pjRbCb, _curCnt)                    \
820 {                                                          \
821    U32   _count = _curCnt + 1;                             \
822    if ( _pjRbCb->dlCb.nxtToSub == _curCnt )                \
823    {                                                       \
824       _pjRbCb->dlCb.nxtToSub = _count;                     \
825    }                                                       \
826    if ( _pjRbCb->dlCb.cfmExp  == _curCnt )                 \
827    {                                                       \
828       _pjRbCb->dlCb.cfmExp = _count;                       \
829    }                                                       \
830 }
831
832 #define PJ_CREATE_NEW_LIST(_cb,_pjRbCb, _tmpTxBuf, _ret)       \
833 {                                                          \
834    _tmpTxBuf.datQ  = _pjRbCb->dlCb.txBuf.datQ;             \
835    _tmpTxBuf.numEntries =  pjRbCb->dlCb.txBuf.numEntries;  \
836    _tmpTxBuf.numBins =  pjRbCb->dlCb.txBuf.numBins;        \
837    _tmpTxBuf.sduSubmitQ = pjRbCb->dlCb.txBuf.sduSubmitQ;   \
838    pjDbmDlBufInit(_cb,&pjRbCb->dlCb.txBuf,_cb->pjGenCfg.nmbDlBins);\
839    if ( _pjRbCb->dlCb.txBuf.datQ == NULLP )                \
840    {                                                       \
841       RLOG0(L_ERROR,"PJ_CREATE_NEW_LIST: PJ_ALLOC Failed.");          \
842       _ret = RFAILED;                                      \
843    }                                                       \
844 }
845
846 #define PJ_SND_ROHC_FDB(_cb,_pjRbCb, _rohcFdbPdu, _ret)        \
847 {                                                          \
848    Data _hdr = 0;                                          \
849    U32  _count = 0;                                        \
850    _hdr |= PJ_ROHC_FEEDBACK_HDR;                           \
851    _ret = SAddPreMsg((Data) _hdr, _rohcFdbPdu);            \
852    if ( _ret != ROK )                                      \
853    {                                                       \
854       RLOG0(L_ERROR,"PJ_SND__ROHC_FDB: SAddPreMsg failed for pdu ");\
855       PJ_FREE_BUF(_rohcFdbPdu);                            \
856       _ret  =  RFAILED;                                    \
857    }                                                       \
858    if ( _pjRbCb->mode == PJ_DRB_UM )                       \
859    {                                                       \
860       _count = _pjRbCb->dlCb.nxtToSub - 1;                 \
861    }                                                       \
862    else                                                    \
863    {                                                       \
864       _count = _pjRbCb->dlCb.cfmExp - 1;                   \
865    }                                                       \
866    if ( _ret == ROK )                                      \
867    {                                                       \
868       pjDlmSendDatReq(_cb, _pjRbCb, _count, _rohcFdbPdu);           \
869    }                                                       \
870 }
871
872 #define PJ_MAX_HASH_BINS 255
873
874 /* Defines used in gp_pj_dbm.c */
875 #define PJ_HASH_FN(_buf, _cnt) (_cnt % PJ_MAX_HASH_BINS)
876
877 /* Defines used in gp_pj_ulm.c */
878 #define MAX_BMAP_SIZE         2048
879 #define PJ_WINSIZE(_snLen) (1 << (_snLen - 1))    
880 #define PJ_MAX_HFN(_snLen) ((1 << (32 - _snLen)) - 1)
881 #define PJ_U16_BIT_SIZE       16
882 #define PJ_BYTE_SIZE          8
883 //#define PJ_SRB_SN_LEN         12
884 #define PJ_SRB_SN_LEN         12
885 #define PJ_DRBAM_SN_LEN       12
886 #define PJ_TYPE_DRB_DATA      0x80
887 #define PJ_TYPE_STATUS_REPORT  0x00
888 #define PJ_TYPE_ROHC_FEEDBACK 0x01
889 #define PJ_PDU_BIT_MASK       0x70
890 #define PJ_12_BIT_SN_MSB_MASK 0x0F
891 #define PJ_18_BIT_SN_MSB_MASK 0x03
892 #define PJ_CPDU_RES_VAL_MASK       0x0F
893 #define PJ_MACI_LEN           4
894
895 #define PJ_RDY_TO_DCIPHER      1
896 #define PJ_SENT_TO_DCIPHER     2
897 #define PJ_RDY_TO_INTVER       3
898 #define PJ_SENT_TO_INTVER      4
899 #define PJ_RDY_TO_DCOMP        5
900 #define PJ_SENT_TO_DCOMP       6
901 #define PJ_RDY_TO_SUBMIT       7
902 #define PJ_RX_ENT_TO_DEL       8
903 #define PJ_RX_INTVER_FAIL      9
904
905 #define PJ_STATE_NORMAL       1
906 #define PJ_STATE_REEST        2
907 #define PJ_STATE_REEST_HO     3
908 #define PJ_STATE_HO           4
909 #define PJ_TMR_ULM_OBD        10
910
911 /* Defines used in gp_pj_utl.c */
912 #define PJ_LIB_COMP_BIT_MASK     0x00000001
913 #define PJ_LIB_INT_BIT_MASK      0x00000002
914 #define PJ_LIB_CP_CIP_BIT_MASK   0x00000004
915 #define PJ_LIB_UP_CIP_BIT_MASK   0x00000008
916
917 #define PJ_MAX_SDU_IN_DAT_FWD_IND      5
918 /* Defines used for multi cfg confirms */
919 #define PJ_MAX_ASYNC_CFM   2
920
921 #define PJ_SEC_ASYNC_CFM         0x01
922 #define PJ_CFG_ASYNC_CFM         0x02
923 #define PJ_CFG_REEST_ASYNC_CFM   0x04
924 #define PJ_CFG_UEDEL_ASYNC_CFM   0x08
925 #define PJ_REEST_ASYNC_CFM       0x10
926
927 #define  PJ_SEC_INIT_CFM   1
928 #define  PJ_CMP_INIT_CFM   2
929
930 #define PJ_GET_MEM_REGION(_cb) (_cb->init.region)
931
932 #define PJ_GET_MEM_POOL(_cb) (_cb->init.pool)
933
934 #define PJ_GET_MEM_POOL_ADDRESS(_cb) (&_cb->init.pool)
935
936 #define PJ_GET_DBG_MASK(_cb) (_cb->init.dbgMask)
937
938 /* Memset to value */
939 #define PJ_MEM_SET(_arg, _val, _size) \
940 { \
941   cmMemset((U8 *)_arg, (U8)_val, _size); \
942 }
943
944 /* Set the unsolictated Status flag */
945 #define PJ_SET_USTA_FLAG(_cb, _value) \
946 { \
947    _cb->init.usta = _value; \
948 }
949
950 #define PJ_DATA_FWD_PKT   1
951 #define PJ_DATA_NRM_PKT   2
952
953 #define PJ_CHK_RESTART_OBD_TIMER(_cb,_ueCb, _cfgTxId)                    \
954 {                                                                             \
955    U16 _idx;                                                                  \
956    if(_ueCb->libInfo.crntTmrTxId == _cfgTxId)                                 \
957    {                                                                          \
958       pjStopTmr(_cb,(PTR)_ueCb, PJ_EVT_OBD_WAIT_TMR);                         \
959    }                                                                          \
960                                                                               \
961    if(pjChkTmr(_cb,(PTR)_ueCb, PJ_EVT_OBD_WAIT_TMR) == FALSE)                 \
962    {                                                                          \
963       for(_idx = 0; _idx < (PJ_MAX_ASYNC_CFM - 1) ; _idx++)                   \
964       {                                                                       \
965          _ueCb->libInfo.crntTmrTxId =                                         \
966                (U16)((_ueCb->libInfo.crntTmrTxId + 1) % PJ_MAX_ASYNC_CFM);          \
967          if((_ueCb->libInfo.asyncCfm[_ueCb->libInfo.crntTmrTxId] != NULLP) && \
968             (_ueCb->libInfo.asyncCfm[_ueCb->libInfo.crntTmrTxId]->startTmr    \
969                                                       == TRUE))               \
970          {                                                                    \
971             pjStartTmr(_cb,(PTR)_ueCb, PJ_EVT_OBD_WAIT_TMR);                 \
972             break;                                                            \
973          }                                                                    \
974       }                                                                       \
975    }                                                                          \
976 }                                                                             \
977
978 #define PJ_CLEAN_AND_UPD_ASYNCINFO(_cb,_ueCb, _txIdx)                 \
979 {                                                                 \
980    PJ_FREE(_cb,_ueCb->libInfo.asyncCfm[_txIdx], sizeof(PjAsyncCfm));  \
981    _ueCb->libInfo.asyncCfm[_txIdx]=NULLP;                         \
982    if(_ueCb->libInfo.nxtAvlbTxId  == PJ_MAX_ASYNC_CFM)            \
983    {                                                              \
984       _ueCb->libInfo.nxtAvlbTxId  = _txIdx;                       \
985    }                                                              \
986 }                                                                 \
987
988 #define PJ_FILL_TIMEOUT_CFG_CFM_INFO(_cb,_cfgCfm, _asyncCfm)               \
989 {                                                                            \
990       U16 _idx;                                                              \
991       PJ_ALLOC(_cb,_cfgCfm, sizeof(CpjCfgCfmInfo));                         \
992       if (_cfgCfm != NULLP)                                                  \
993       {                                                                      \
994          for ( _idx = 0; _idx < _asyncCfm->numEnt ; _idx++)                  \
995          {                                                                   \
996             if ( _asyncCfm->cmpInitBitMask &                                 \
997                            (1 << (_asyncCfm->cfmEnt[_idx].rbId - 1)))        \
998             {                                                                \
999                _cfgCfm->cfmEnt[_idx].status =  CPJ_CFG_CFM_NOK;              \
1000                _cfgCfm->cfmEnt[_idx].reason = CPJ_CFG_REAS_OBD_TIMEOUT;      \
1001             }                                                                \
1002             else                                                             \
1003             {                                                                \
1004                _cfgCfm->cfmEnt[_idx].status = _asyncCfm->cfmEnt[_idx].status;\
1005                _cfgCfm->cfmEnt[_idx].reason = _asyncCfm->cfmEnt[_idx].reason;\
1006             }                                                                \
1007             _cfgCfm->cfmEnt[_idx].rbId   = _asyncCfm->cfmEnt[_idx].rbId;     \
1008             _cfgCfm->cfmEnt[_idx].rbType = _asyncCfm->cfmEnt[_idx].rbType;   \
1009          }                                                                   \
1010          _cfgCfm->ueId    = _asyncCfm->ueId;                                 \
1011          _cfgCfm->cellId  = _asyncCfm->cellId;                               \
1012          _cfgCfm->transId = _asyncCfm->transId;                              \
1013          _cfgCfm->numEnt  = _asyncCfm->numEnt;                               \
1014       }                                                                      \
1015 }                                                                            \
1016
1017 #ifdef PJ_SEC_ASYNC
1018 /* In the case when all the elements in the reception buffer have already
1019  * been sent to the dcomp unit or sent up, our nxtSubDcomp will be pointing to 
1020  * NEXT_PDCP_RX_SN. So if there is a jump, this has to be updated accordingly */
1021 #define PJ_ULM_UPD_NXT2DCOMP(_ulCb, _snLen, _rcvdCount, _oldRxCnt)        \
1022 {                                                                  \
1023    if(_oldRxCnt == _ulCb->nxtSubDeCmp)                             \
1024    {                                                               \
1025       _ulCb->nxtSubCnt = _rcvdCount;                               \
1026    }                                                               \
1027 }
1028 #else  /* !PJ_SEC_ASYNC */
1029 #define PJ_ULM_UPD_NXT2DCOMP(_ulCb, _snLen, _sn, _oldRxCnt) 
1030 #endif /* PJ_SEC_ASYNC */
1031
1032 #if (defined(PJ_SEC_ASYNC) || defined (PJ_CMP_ASYNC))
1033 /* There can be a case where the first PDU that you receive *
1034  * does not match with the NEXT_PDCP_RX_SN. If nxtSubCnt is also
1035  * pointing to NETX_PDCP_RX_SN, it has to be updated. */
1036 #define PJ_ULM_UPD_NXT2SUB(_ulCb, _cnt)                      \
1037 {                                                            \
1038    if(_ulCb->recBuf.numEntries == 0)                         \
1039    {                                                         \
1040       _ulCb->nxtSubCnt = _cnt;                               \
1041       _ulCb->nxtSubDeCmp = _cnt;                             \
1042    }                                                         \
1043 }
1044 #define PJ_INC_OBD_COUNT(_pjRbCb, _count)                                \
1045 {                                                                        \
1046    if(_pjRbCb->state == PJ_STATE_REEST ||                                \
1047          _pjRbCb->state == PJ_STATE_REEST_HO)                            \
1048    {                                                                     \
1049       _pjRbCb->ulCb.obdCnt ++;                                           \
1050    }                                                                     \
1051 }
1052
1053 /* Notes: This will be called only for DRBs */
1054 #define PJ_DEC_OBD_COUNT(_cb, _pjRbCb, _count)                                \
1055 {                                                                        \
1056    if(_pjRbCb->state == PJ_STATE_REEST ||                                \
1057          _pjRbCb->state == PJ_STATE_REEST_HO)                            \
1058    {                                                                     \
1059       if((_count >= _pjRbCb->ulCb.firstReEstCnt)&&                       \
1060          (_pjRbCb->mode = PJ_DRB_AM))                                    \
1061       {                                                                  \
1062          _pjRbCb->ulCb.obdCnt --;                                        \
1063       }                                                                  \
1064    }                                                                     \
1065 }
1066 #else /* (defined(PJ_SEC_ASYNC) || defined (PJ_CMP_ASYNC)) */
1067 /* Dummy defines */
1068 #define PJ_ULM_UPD_NXT2SUB(_ulCb, _cnt)    
1069 #define PJ_INC_OBD_COUNT(_pjRbCb, _count)  
1070 #define PJ_DEC_OBD_COUNT(_cb,_pjRbCb, _count)  
1071 #endif /* (defined(PJ_SEC_ASYNC) || defined (PJ_CMP_ASYNC)) */
1072
1073
1074 #define PJ_INC_SN(_sn, _snLen) ((++_sn) % (1 << _snLen))                      \
1075
1076 #define PJ_GET_SN_HFN(_count, _snLen, _sn, _hfn)             \
1077 {                                                            \
1078    _sn   = (_count % (1 << _snLen));                          \
1079    _hfn  =  (_count >> _snLen);                              \
1080 }                                                            \
1081
1082 #define PJ_GET_HFN(_count,_snLen,_hfn)\
1083 {\
1084    _hfn = (_count >> _snLen);\
1085 }
1086 #define PJ_GET_SN(_count, _snLen, _sn)  (_sn   =  _count % (1 << _snLen));
1087
1088 #define PJ_ULM_REEST_DRB_AM(_pjRbCb)                         \
1089 {                                                            \
1090    _pjRbCb->frstReEstCnt =  _pjRbCb->rxDeliv;         \
1091    _pjRbCb->obdCnt  =  0;                                    \
1092                                                              \
1093 }                                                            
1094
1095
1096 /* kw005.201,replaced macro with function */
1097 #define PJ_SND_PJU_STA_IND(_cb,_pjRbCb, _rxEnt)              \
1098 {                                                        \
1099    CmLtePdcpId  _pdcpId;                                \
1100    Buffer   *_mBuf = NULLP;                              \
1101    PjuStaIndInfo  _staInd;                              \
1102    PjPjuSapCb  *_pjuSap;                                 \
1103                                                          \
1104    if (_pjRbCb->rbType == PJ_SRB)                        \
1105       _pjuSap   = &(_cb->u.ulCb->pjuSap[PJ_SRB_SAP]);                \
1106    else                                                  \
1107       _pjuSap   = &(_cb->u.ulCb->pjuSap[PJ_DRB_SAP]); \
1108                                                                      \
1109                                                          \
1110                                                          \
1111       _pdcpId.ueId   =  _pjRbCb->ueCb->key.ueId;        \
1112       _pdcpId.cellId =  _pjRbCb->ueCb->key.cellId;      \
1113       _pdcpId.rbId   =  _pjRbCb->rbId;                  \
1114       _pdcpId.rbType =  _pjRbCb->rbType;                \
1115                                                          \
1116       switch (_rxEnt->state)                             \
1117       {                                                  \
1118          case PJ_RDY_TO_DCIPHER:                         \
1119          case PJ_SENT_TO_DCIPHER:                        \
1120          {                                               \
1121             _staInd.cause  =  PJU_DCIP_FAILED;          \
1122             break;                                       \
1123          }                                               \
1124          case PJ_RDY_TO_INTVER:                          \
1125          case PJ_SENT_TO_INTVER:                         \
1126          {                                               \
1127             _staInd.cause  =  PJU_INTVER_FAILED;        \
1128                _mBuf          =  _rxEnt->mBuf;           \
1129                _rxEnt->mBuf    =  NULLP;                 \
1130             break;                                       \
1131          }                                               \
1132          case PJ_RDY_TO_DCOMP:                           \
1133          case PJ_SENT_TO_DCOMP:                          \
1134          {                                               \
1135             _staInd.cause  =  PJU_DCOMP_FAILED;         \
1136             if(_pjRbCb->ulCb.discReqd == FALSE)          \
1137             {                                            \
1138                _mBuf          =  _rxEnt->mBuf;           \
1139                _rxEnt->mBuf    =  NULLP;                 \
1140             }                                            \
1141             break;                                       \
1142          }                                               \
1143          default:                                        \
1144             break;                                       \
1145       }                                                  \
1146       PjUiPjuStaInd(&(_pjuSap->pst), _pjuSap->suId,      \
1147                     &_pdcpId, &_staInd, _mBuf);            \
1148 }
1149
1150
1151
1152 #define PJ_SND_PJU_DAT_IND(_cb,_pjRbCb, _rxEnt)         \
1153 {                                                   \
1154    CmLtePdcpId  _pdcpId;                   \
1155    Buffer        *_mBuf;                            \
1156    PjPjuSapCb  *_pjuSap;                            \
1157                                                     \
1158    if (_pjRbCb->rbType == PJ_SRB)                   \
1159    {                                                \
1160       _pjuSap   = &(_cb->u.ulCb->pjuSap[PJ_SRB_SAP]);       \
1161    }                                                \
1162    else                                             \
1163    {                                                \
1164       PJ_UPD_L2_ULLOSS_CNTRS(_cb,_rxEnt->count, _pjRbCb)        \
1165       _pjuSap   = &(_cb->u.ulCb->pjuSap[PJ_DRB_SAP]);       \
1166    }                                                \
1167                                                     \
1168       _pdcpId.ueId   =  _pjRbCb->ueCb->key.ueId;   \
1169       _pdcpId.cellId =  _pjRbCb->ueCb->key.cellId; \
1170       _pdcpId.rbType =  _pjRbCb->rbType;           \
1171       _pdcpId.rbId   =  _pjRbCb->rbId;             \
1172       _mBuf       =  _rxEnt->mBuf;                  \
1173       _rxEnt->mBuf =  NULLP;                        \
1174                                                     \
1175       /* If trace flag is enabled send the trace indication */\
1176       if(_cb->init.trc == TRUE)                     \
1177       {                                             \
1178          /* Populate the trace params */            \
1179          pjLmmSendTrc(_cb,EVTPJUDATIND, _mBuf);         \
1180       }                                             \
1181                                                     \
1182       PjUiPjuDatInd(&(_pjuSap->pst), _pjuSap->suId, \
1183              &_pdcpId, _mBuf);                       \
1184       PJ_STS_INC_PJU_CNT(_cb,_pjRbCb->rbType, txSdus)   \
1185 }
1186
1187
1188 #define  PJ_FILL_REEST_CFM_INFO(_reEstCfm, _asyncCfm, _status)  \
1189 {                                                               \
1190    _reEstCfm->ueId    =  _asyncCfm->ueId;                       \
1191    _reEstCfm->cellId  =  _asyncCfm->cellId;                     \
1192    _reEstCfm->transId =  _asyncCfm->transId;                    \
1193    _reEstCfm->status  =  _status;                               \
1194 }
1195
1196 #define  PJ_FILL_SEC_CFM_INFO(_secCfgCfm, _asyncCfm)  \
1197 {                                                     \
1198    _secCfgCfm->ueId    =  _asyncCfm->ueId;            \
1199    _secCfgCfm->cellId  =  _asyncCfm->cellId;          \
1200    _secCfgCfm->transId =  _asyncCfm->transId;         \
1201    _secCfgCfm->status  =  UDX_CFG_CFM_OK;             \
1202    _secCfgCfm->reason  =  UDX_CFG_REAS_NONE;          \
1203 }
1204
1205 #define  PJ_FILL_REEST_CFG_CFM_INFO(_cfmInfo, _asyncCfm)               \
1206 {                                                                      \
1207    U8 _idx;                                                            \
1208    for (_idx = 0; _idx < _asyncCfm->numEnt ; _idx++)                   \
1209    {                                                                   \
1210       if (_asyncCfm->cfmEnt[_idx].cfgType == CPJ_CFG_REESTABLISH)      \
1211       {                                                                \
1212          _cfmInfo->cfmEnt[_idx].status = CPJ_CFG_CFM_OK;               \
1213          _cfmInfo->cfmEnt[_idx].reason = LCM_REASON_NOT_APPL;          \
1214       }                                                                \
1215       else                                                             \
1216       {                                                                \
1217          _cfmInfo->cfmEnt[_idx].status = _asyncCfm->cfmEnt[_idx].status;\
1218          _cfmInfo->cfmEnt[_idx].reason = _asyncCfm->cfmEnt[_idx].reason;\
1219       }                                                                \
1220       _cfmInfo->cfmEnt[_idx].rbId  = _asyncCfm->cfmEnt[_idx].rbId;      \
1221       _cfmInfo->cfmEnt[_idx].rbType  = _asyncCfm->cfmEnt[_idx].rbType; \
1222    }                                                                   \
1223    _cfmInfo->ueId    = _asyncCfm->ueId;                                \
1224    _cfmInfo->cellId  = _asyncCfm->cellId;                              \
1225    _cfmInfo->transId = _asyncCfm->transId;                             \
1226    _cfmInfo->numEnt  = _asyncCfm->numEnt;                              \
1227 }
1228
1229
1230 #define PJ_PERFORM_ERR_UPDATES(_cb, _pjRbCb, _count) \
1231 {                                               \
1232    PjUlCb   *_upCb;                             \
1233                                                 \
1234    _upCb =  &_pjRbCb->ulCb;                  \
1235    if(_upCb->recBuf.numEntries != 0)            \
1236    {                                            \
1237       PJ_CALC_NXT2SUB(_cb, _upCb);        \
1238    }                                            \
1239    PJ_CHK_RDY_TO_DELIVER(_cb, _pjRbCb);              \
1240 }
1241
1242
1243 #define PJ_CALC_NXT2SUB(_cb, __ulCb)                                             \
1244 {                                                                          \
1245    PjRxEnt  *_rxEnt;                                                       \
1246    U32  _nxtToSub;                                                         \
1247    _nxtToSub = __ulCb->nxtSubCnt;                                           \
1248    if(__ulCb->recBuf.numEntries != 0)                                       \
1249    {                                                                       \
1250       _nxtToSub ++;                                                        \
1251       while( (_rxEnt = (PjRxEnt *)pjDbmGetRxEnt(_cb, &ulCb->recBuf, _nxtToSub)) != NULLP)\
1252       {                                                                 \
1253          __ulCb->nxtSubCnt++;                                            \
1254       }                                                                 \
1255    }                                                                       \
1256    __ulCb->nxtSubCnt  =  _nxtToSub;                                         \
1257 }
1258
1259
1260 #define PJ_CHK_RDY_TO_DELIVER(_cb, _pjRbCb)                     \
1261 {                                                          \
1262    PjUlCb   *_ulCb;                                       \
1263    PjRxEnt  *_rxEnt;                                      \
1264                                                            \
1265    _ulCb  =  &_pjRbCb->ulCb;                                     \
1266    if(_ulCb->recBuf.numEntries == 0)                       \
1267    {                                                       \
1268       if((_pjRbCb->rbType   ==  PJ_DRB)&&                  \
1269          (_pjRbCb->state != PJ_STATE_NORMAL))              \
1270       {                                                    \
1271             if((_ulCb->transCmp)                          \
1272                   && (_ulCb->obdCnt == 0)                \
1273               )                                            \
1274             {                                              \
1275                pjUlmReEstDrbAm(_cb, _pjRbCb);                     \
1276             }                                              \
1277       }                                                    \
1278    }                                                       \
1279    else                                                    \
1280    {                                                       \
1281      _rxEnt  =  (PjRxEnt *)pjDbmGetRxEnt(_cb, &_ulCb->recBuf, ulCb->nxtSubCnt);\
1282      if( _rxEnt && _rxEnt->state == PJ_RDY_TO_SUBMIT)      \
1283      {                                                     \
1284         if(_pjRbCb->rbType == PJ_SRB)                      \
1285         {                                                  \
1286            pjUlmDeliverSrb(_cb, _pjRbCb, _rxEnt);                \
1287         }                                                  \
1288         else                                               \
1289         {                                                  \
1290            if(_pjRbCb->mode   == PJ_DRB_UM)                \
1291            {                                               \
1292               pjUlmDeliverDrbUm(_cb, _pjRbCb, _rxEnt);           \
1293            }                                               \
1294            else                                            \
1295            {                                               \
1296               pjUlmDeliverDrbAm(_cb, _pjRbCb, _rxEnt);           \
1297            }                                               \
1298         }                                                  \
1299      }                                                     \
1300    }                                                       \
1301 }                                                          
1302
1303 #define PJ_GET_COUNT(_count, _snLen, _sn, _hfn)              \
1304 {                                                            \
1305    _count   = ((_hfn << _snLen) | _sn);                       \
1306 }
1307                                                             
1308
1309 #define PJ_CALC_RCVD_HFN(_rcvdSn,_snLen,_rxDeliv,_rcvdHfn)     \
1310 {                                                              \
1311    U32  _hfn;                                                  \
1312    U32  _sn;                                                   \
1313    S32  _winSize;                                              \
1314    PJ_GET_SN_HFN(_rxDeliv,_snLen,_sn,_hfn);                    \
1315    _winSize = _sn - PJ_WINSIZE(_snLen);                        \
1316    if((_winSize > 0) && (_rcvdSn < _winSize))                  \
1317    {                                                           \
1318        _rcvdHfn = _hfn + 1;                                    \
1319    }                                                           \
1320    else if(_rcvdSn >= (_sn + PJ_WINSIZE(_snLen)))              \
1321    {                                                           \
1322        _rcvdHfn = _hfn - 1;                                    \
1323    }                                                           \
1324    else                                                        \
1325    {                                                           \
1326        _rcvdHfn = _hfn;                                        \
1327    }                                                           \
1328 }                                                              
1329
1330
1331 #ifdef LTE_L2_MEAS
1332 #define PJ_ULM_DRBUM_REEST(_cb,_pjRbCb)       \
1333 {                                         \
1334    _pjRbCb->ulCb.rxNext   = 0;            \
1335    _pjRbCb->ulCb.rxDeliv  = 0;            \
1336    pjUtlUlHdlRbReEstComplete(_cb, _pjRbCb);         \
1337 }
1338 #else
1339 #define PJ_ULM_DRBUM_REEST(_cb,_pjRbCb)       \
1340 {                                         \
1341    _pjRbCb->ulCb.rxNext   = 0;            \
1342    _pjRbCb->ulCb.rxDeliv  = 0;            \
1343    pjUtlUlHdlRbReEstComplete(_cb, _pjRbCb);         \
1344 }
1345 #endif
1346
1347
1348 /* Update state and call the respective delivery 
1349  * function */
1350 #define PJ_ULM_DELIVER_DRB(_cb,_pjRbCb, _rxEnt)  \
1351 {                                            \
1352    if(_pjRbCb->mode == PJ_DRB_AM)            \
1353    {                                         \
1354       pjUlmDeliverDrbAm(_cb,_pjRbCb, _rxEnt);    \
1355    }                                         \
1356    else                                      \
1357    {                                         \
1358       pjUlmDeliverDrbUm(_cb,_pjRbCb, _rxEnt);    \
1359    }                                         \
1360 }
1361
1362 /*update the state variable RX_NEXT */
1363 #define PJ_ULM_UPDATE_RX_NEXT(_pjRbCb,_rxEnt) \
1364 {                                             \
1365    U32 _diffRxNext;\
1366    U32 _diffRcvdCount;\
1367    _diffRxNext    = ((_pjRbCb->ulCb.rxNext - _pjRbCb->ulCb.rxDeliv) % PJ_WINSIZE(_pjRbCb->snLen));\
1368    _diffRcvdCount = ((_rxEnt->count - _pjRbCb->ulCb.rxDeliv) %  PJ_WINSIZE(_pjRbCb->snLen));\
1369    if(_diffRcvdCount >= _diffRxNext)       \
1370    {                                          \
1371       _pjRbCb->ulCb.rxNext = _rxEnt->count + 1;    \
1372    }                                          \
1373 }                                              
1374 /* Update state and call the respective delivery 
1375  * function */
1376 #define PJ_ULM_DELIVER_PDU(_cb,_pjRbCb, _rxEnt)  \
1377 {                                            \
1378                                              \
1379    if(_pjRbCb->rbType == PJ_SRB)             \
1380    {                                         \
1381       pjUlmDeliverSrb(_cb,_pjRbCb, _rxEnt);      \
1382    }                                         \
1383    else                                      \
1384    {                                         \
1385       PJ_ULM_DELIVER_DRB(_cb,_pjRbCb, _rxEnt);   \
1386    }                                         \
1387 }
1388  
1389 /* There is case that all PDUs in the recv Buf can be back from off board 
1390  * but not sent up. In that case, though the the recvBuf has entries the 
1391  * obd timer should not be restarted. This works with the PJ_ULM_GET_DRBAM_SUBCNT
1392  * macro to acheive this. */
1393 #define PJ_DRBAM_ALL_PDU_RECVD(_pjRbCb)\
1394 ((pjRbCb->rbType == PJ_DRB) &&         \
1395  (pjRbCb->mode == PJ_DRB_AM) &&        \
1396  ((ulCb->rxDeliv - 1) == ulCb->obdPdu))   \
1397
1398
1399 #define PJ_ULM_GET_DRBAM_SUBCNT(_pjUlRbCb, _nxtSubCnt, _pjCb)                          \
1400 {                                                                             \
1401    U32 _count    = _pjUlRbCb->ulCb.rxDeliv - 1;                                  \
1402    U32 _nxtRxCnt  =  (_pjUlRbCb->ulCb.rxNext) ;\
1403    PjRxEnt *_rxEnt = NULLP;                                                   \
1404    _nxtSubCnt      = _count;                                                  \
1405    if(((_pjUlRbCb->state != PJ_STATE_NORMAL) &&                                 \
1406        (_pjUlRbCb->ulCb.obdCnt != 0)) ||                                        \
1407       ((_pjUlRbCb->state == PJ_STATE_NORMAL) &&                                 \
1408        (_pjUlRbCb->ulCb.recBuf.numEntries != 0)))                               \
1409    {                                                                          \
1410       _count ++;                                                              \
1411       for(;_count < _nxtRxCnt; _count ++)                                     \
1412       {                                                                       \
1413          _rxEnt   = (PjRxEnt *)pjDbmGetRxEnt(_pjCb, &_pjUlRbCb->ulCb.recBuf, _count);  \
1414          if((_rxEnt != NULLP) && (_rxEnt->state != PJ_RDY_TO_SUBMIT))         \
1415          {                                                                    \
1416             _nxtSubCnt  =  _count;                                            \
1417             break;                                                            \
1418          }                                                                    \
1419       }                                                                       \
1420    }                                                                          \
1421 }                                                                                   
1422
1423
1424 #define PJ_ULM_GET_SUBCNT(_pjUlRbCb, _subPdu, _pjCb)                        \
1425 {                                                                  \
1426    if((_pjUlRbCb->rbType == PJ_DRB) && (_pjUlRbCb->mode  == PJ_DRB_AM))\
1427    {                                                               \
1428       PJ_ULM_GET_DRBAM_SUBCNT(_pjUlRbCb, _subPdu, _pjCb);                   \
1429    }                                                               \
1430    else                                                            \
1431    {                                                               \
1432       _subPdu =  _pjUlRbCb->ulCb.nxtSubCnt;                           \
1433    }                                                               \
1434 }
1435
1436
1437 #define PJ_STS_INC_GEN_CNT(_cb, _cntr)       \
1438 {                                            \
1439    _cb->pjGenSts._cntr++;                    \
1440 }                                            \
1441
1442 #define PJ_STS_INC_PJU_CNT(_cb, _rbType, _cntr)   \
1443 {                                            \
1444    if (_rbType == PJ_SRB)                    \
1445       _cb->u.ulCb->pjuSap[PJ_SRB_SAP].sts._cntr++;   \
1446    else                                      \
1447       _cb->u.ulCb->pjuSap[PJ_DRB_SAP].sts._cntr++;   \
1448 }                                            \
1449
1450 #define PJ_PK_U8(_msg, _val, _ret)                                     \
1451 {                                                                      \
1452    (_ret) = SAddPstMsg((Data) (_val), (_msg));                         \
1453 }
1454
1455 #define PJ_PK_U16(_msg, _val, _ret)                                    \
1456 {                                                                      \
1457    PJ_PK_U8(_msg, (U8) GetHiByte(_val), _ret)                          \
1458    if ((_ret) == ROK)                                                  \
1459       PJ_PK_U8(_msg, (U8) GetLoByte(_val), _ret)                       \
1460 }
1461
1462 #define PJ_PK_U32(_msg, _val, _ret)                                    \
1463 {                                                                      \
1464    U16 _tmp16;                                                         \
1465    _tmp16 = (U16) GetHiWord(_val);                                     \
1466    PJ_PK_U16(_msg, _tmp16, _ret)                                       \
1467    if ((_ret) == ROK)                                                  \
1468    {                                                                   \
1469       _tmp16 = (U16) GetLoWord(_val);                                  \
1470       PJ_PK_U16(_msg, _tmp16, _ret)                                    \
1471    }                                                                   \
1472 }
1473
1474 #define PJ_PACK_MACI(_mBuf, _macI)              \
1475 {                                               \
1476    U16 _tmp;                                    \
1477    Data _pkArray[4];                            \
1478    _tmp = (U16) GetHiWord(_macI);               \
1479    _pkArray[0] = (Data) GetHiByte(_tmp);        \
1480    _pkArray[1] = (Data) GetLoByte(_tmp);        \
1481    _tmp = (U16) GetLoWord(_macI);               \
1482    _pkArray[2] = (Data) GetHiByte(_tmp);        \
1483    _pkArray[3] = (Data) GetLoByte(_tmp);        \
1484    SAddPstMsgMult(_pkArray, (MsgLen) 4, _mBuf); \
1485 }
1486
1487 #define PJ_UNPK_MACI(_mBuf, _macI)                          \
1488 {                                                           \
1489    U16 _tmp16 = 0;                                          \
1490    Data _unPkArray[4] = {0};                                      \
1491    SRemPstMsgMult(_unPkArray, (MsgLen)4, _mBuf);            \
1492    _tmp16 = (U16) PutHiByte(_tmp16, (U8) _unPkArray[3]);    \
1493    _tmp16 = (U16) PutLoByte(_tmp16, (U8) _unPkArray[2]);    \
1494    _macI  = (U32) PutHiWord(_macI, (U16) _tmp16);           \
1495    _tmp16 = (U16) PutHiByte(_tmp16, (U8) _unPkArray[1]);    \
1496    _tmp16 = (U16) PutLoByte(_tmp16, (U8) _unPkArray[0]);    \
1497    _macI  = (U32) PutLoWord(_macI, (U16) _tmp16);           \
1498 }
1499
1500 /*@def PJ_SEC_FILL_COUNT
1501 *
1502 *  This macro fills the COUNT value. COUNT value is composed 
1503 *  of a HFN and the PDCP SN. Refer to 36.323 for details.
1504
1505 *@param[in]_secInp      Count Value as Input 
1506 *@param[in]_pSecInfo    Variable into which count value needs to be populated
1507 *
1508 */
1509 #define PJ_SEC_FILL_COUNT(_secInp, _pSecInfo)              \
1510 {                                               \
1511    U16 _tmp;                                    \
1512    _tmp = (U16) GetHiWord(_secInp);               \
1513    _pSecInfo[0] = (Data) GetHiByte(_tmp);        \
1514    _pSecInfo[1] = (Data) GetLoByte(_tmp);        \
1515    _tmp = (U16) GetLoWord(_secInp);               \
1516    _pSecInfo[2] = (Data) GetHiByte(_tmp);        \
1517    _pSecInfo[3] = (Data) GetLoByte(_tmp);        \
1518 }
1519
1520 /*@def PJ_SEC_FILL_FRESH
1521 *
1522 *  This macro fills the FRESH value. FRESH [0], . FRESH [3]
1523 *  is set as BEARER[0] . BEARER[4] | 0 pow(27). Refer to 33.401 for details.
1524
1525 *@param[in]_fresh   Variable into which o/p needs to be set.
1526 *@param[in]_rbId    RbId of the RB to be filled in FRESH
1527 *
1528 */
1529 #define PJ_SEC_FILL_FRESH(_fresh, _rbId)              \
1530 {                                               \
1531    _fresh[0] = 0;        \
1532    _fresh[1] = 0;        \
1533    _fresh[2] = 0;        \
1534    _fresh[3] = _rbId;        \
1535 }
1536
1537 #define PJ_TIME_DIFF(cur,prev)                  \
1538    (cur<prev ? ((0xffffffff - prev) + cur ): (cur - prev)) 
1539 #define PJ_MAX_CNT_RB_OVERLOAD 10
1540 #endif /* __PJH__ */
1541 \f  
1542 /********************************************************************30**
1543   
1544          End of file
1545 **********************************************************************/