[Epic-ID: ODUHIGH-405][Task-ID: ODUHIGH-434] EGTP connection towards multiple DUs...
[o-du/l2.git] / src / phy_stub / phy_stub_msg_hdl.c
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 /*This file contains stub for PHY to handle messages to/from MAC CL */
20
21 #include "common_def.h"
22 #include "lrg.h"
23 #include "lrg.x"
24 #include "du_app_mac_inf.h"
25 #include "mac_sch_interface.h"
26 #include "lwr_mac.h"
27 #include "lwr_mac_fsm.h"
28 #include "lwr_mac_phy.h"
29 #ifdef INTEL_FAPI
30 #include "fapi.h"
31 #include "fapi_vendor_extension.h"
32 #endif
33 #include "lwr_mac_upr_inf.h"
34 #include "mac_utils.h"
35 #include "phy_stub.h"
36 #include "phy_stub_utils.h"
37 #include "lwr_mac_phy_stub_inf.h"
38
39 /*******************************************************************
40  *
41  * @brief Builds and sends param response to MAC CL
42  *
43  * @details
44  *
45  *    Function : l1BldAndSndParamRsp
46  *
47  *    Functionality:
48  *          - Builds and sends param response to MAC
49  *
50  * @params[in] Config request message pointer
51  * @return ROK     - success
52  *         RFAILED - failure
53  *
54  * ****************************************************************/
55 S16 l1BldAndSndParamRsp(void *msg)
56 {
57 #ifdef INTEL_FAPI
58    uint8_t index = 0;
59    uint32_t msgLen = 0;
60    fapi_param_resp_t *fapiParamRsp;
61
62    MAC_ALLOC(fapiParamRsp, sizeof(fapi_param_resp_t));
63    if(!fapiParamRsp)
64    {
65       DU_LOG("\nERROR  -->  PHY STUB: Memory allocation failed");
66       return RFAILED;
67    }
68
69    /* Cell Params */
70    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_RELEASE_CAPABILITY_TAG,                         sizeof(uint16_t), 1, &msgLen);
71    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PHY_STATE_TAG,                                  sizeof(uint16_t), 0, &msgLen);
72    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SKIP_BLANK_DL_CONFIG_TAG,                       sizeof(uint8_t),  0, &msgLen);
73    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SKIP_BLANK_UL_CONFIG_TAG,                       sizeof(uint8_t),  0, &msgLen);
74    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_NUM_CONFIG_TLVS_TO_REPORT_TYPE_TAG,              sizeof(uint8_t),  0, &msgLen);
75
76    /* Carrier Params */
77    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_CYCLIC_PREFIX_TAG,                               sizeof(uint8_t),  1, &msgLen);
78    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_SUBCARRIER_SPACING_DL_TAG,            sizeof(uint8_t),  1, &msgLen);
79    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_BANDWIDTH_DL_TAG,                     sizeof(uint16_t), 1, &msgLen);
80    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_SUBCARRIER_SPACING_UL_TAG,            sizeof(uint8_t),  0, &msgLen);
81    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_BANDWIDTH_UL_TAG,                     sizeof(uint16_t), 0, &msgLen);
82
83    /* PDCCH Param*/
84    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_CCE_MAPPING_TYPE_TAG,                                   sizeof(uint8_t), 0, &msgLen);
85    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_CORESET_OUTSIDE_FIRST_3_OFDM_SYMS_OF_SLOT_TAG,   sizeof(uint8_t), 0, &msgLen);
86    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PRECODER_GRANULARITY_CORESET_TAG,               sizeof(uint8_t), 0, &msgLen);
87    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDCCH_MU_MIMO_TAG,                              sizeof(uint8_t), 0, &msgLen);
88    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDCCH_PRECODER_CYCLING_TAG,                     sizeof(uint8_t), 0, &msgLen);
89    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_PDCCHS_PER_SLOT_TAG,                                sizeof(uint8_t), 0, &msgLen);
90
91    /* PUCCH Param */
92    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUCCH_FORMATS_TAG,                              sizeof(uint8_t), 0, &msgLen);
93    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_PUCCHS_PER_SLOT_TAG,                         sizeof(uint8_t), 0, &msgLen);
94
95    /* PDSCH Param */
96    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_MAPPING_TYPE_TAG,                         sizeof(uint8_t), 0, &msgLen);
97    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_ALLOCATION_TYPES_TAG,                      sizeof(uint8_t), 0, &msgLen);
98    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_VRB_TO_PRB_MAPPING_TAG,                   sizeof(uint8_t), 0, &msgLen);
99    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_CBG_TAG,                                  sizeof(uint8_t), 0, &msgLen);
100    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_DMRS_CONFIG_TYPES_TAG,                    sizeof(uint8_t), 0, &msgLen);
101    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_DMRS_MAX_LENGTH_TAG,                      sizeof(uint8_t), 0, &msgLen);
102    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_DMRS_ADDITIONAL_POS_TAG,                  sizeof(uint8_t), 0, &msgLen);
103    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_PDSCHS_TBS_PER_SLOT_TAG,                    sizeof(uint8_t), 0, &msgLen);
104    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_NUMBER_MIMO_LAYERS_PDSCH_TAG,               sizeof(uint8_t), 0, &msgLen);
105    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_MAX_MODULATION_ORDER_DL_TAG,          sizeof(uint8_t), 0, &msgLen);
106    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_MU_MIMO_USERS_DL_TAG,                       sizeof(uint8_t), 0, &msgLen);
107    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_DATA_IN_DMRS_SYMBOLS_TAG,                 sizeof(uint8_t), 0, &msgLen);
108    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PREMPTIONSUPPORT_TAG,                           sizeof(uint8_t), 0, &msgLen);
109    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_NON_SLOT_SUPPORT_TAG,                      sizeof(uint8_t), 0, &msgLen);
110
111    /* PUSCH Param */
112    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_UCI_MUX_ULSCH_IN_PUSCH_TAG,                     sizeof(uint8_t), 0, &msgLen);
113    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_UCI_ONLY_PUSCH_TAG,                             sizeof(uint8_t), 0, &msgLen);
114    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_FREQUENCY_HOPPING_TAG,                    sizeof(uint8_t), 0, &msgLen);
115    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_DMRS_CONFIG_TYPES_TAG,                    sizeof(uint8_t), 0, &msgLen);
116    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_DMRS_MAX_LEN_TAG,                         sizeof(uint8_t), 0, &msgLen);
117    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_DMRS_ADDITIONAL_POS_TAG,                  sizeof(uint8_t), 0, &msgLen);
118    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_CBG_TAG,                                  sizeof(uint8_t), 0, &msgLen);
119    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_MAPPING_TYPE_TAG,                          sizeof(uint8_t), 0, &msgLen);
120    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_ALLOCATION_TYPES_TAG,                     sizeof(uint8_t), 0, &msgLen);
121    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_VRB_TO_PRB_MAPPING_TAG,                   sizeof(uint8_t), 0, &msgLen);
122    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_MAX_PTRS_PORTS_TAG,                        sizeof(uint8_t), 0, &msgLen);
123    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_PDUSCHS_TBS_PER_SLOT_TAG,                   sizeof(uint8_t), 0, &msgLen);
124    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_NUMBER_MIMO_LAYERS_NON_CB_PUSCH_TAG,         sizeof(uint8_t), 0, &msgLen);
125    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_MODULATION_ORDER_UL_TAG,               sizeof(uint8_t), 0, &msgLen);
126    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_MU_MIMO_USERS_UL_TAG,                        sizeof(uint8_t), 0, &msgLen);
127    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_DFTS_OFDM_SUPPORT_TAG,                           sizeof(uint8_t), 0, &msgLen);
128    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_AGGREGATION_FACTOR_TAG,                    sizeof(uint8_t), 0, &msgLen);
129
130    /* PRACH Params */
131    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PRACH_LONG_FORMATS_TAG,                         sizeof(uint8_t), 0, &msgLen);
132    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PRACH_SHORT_FORMATS_TAG,                         sizeof(uint8_t), 0, &msgLen);
133    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PRACH_RESTRICTED_SETS_TAG,                       sizeof(uint8_t), 0, &msgLen);
134    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_PRACH_FD_OCCASIONS_IN_A_SLOT_TAG,            sizeof(uint8_t), 0, &msgLen);
135
136    /* MEASUREMENT TAG */
137    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_RSSI_MEASUREMENT_SUPPORT_TAG,                    sizeof(uint8_t), 0, &msgLen);
138
139    fapiParamRsp->number_of_tlvs = index;
140    msgLen += sizeof(fapi_param_resp_t) - sizeof(fapi_msg_t);
141    fillMsgHeader(&fapiParamRsp->header, FAPI_PARAM_RESPONSE, msgLen);
142    fapiParamRsp->error_code = MSG_OK;
143
144    DU_LOG("\nINFO   -->  PHY_STUB: Sending Param Request to Lower Mac");
145    procPhyMessages(fapiParamRsp->header.msg_id, sizeof(fapi_param_resp_t), (void *)fapiParamRsp);
146    MAC_FREE(fapiParamRsp, sizeof(fapi_param_resp_t));
147 #endif
148    return ROK;
149 }
150
151 /*******************************************************************
152  *
153  * @brief Builds and sends config response to lower mac
154  *
155  * @details
156  *
157  *    Function : l1BldAndSndConfigRsp
158  *
159  *    Functionality:
160  *          - Builds and sends config response to MAC
161  *
162  * @params[in] Config request message pointer
163  * @return ROK     - success
164  *         RFAILED - failure
165  *
166  * ****************************************************************/
167
168 S16 l1BldAndSndConfigRsp(void *msg)
169 {
170 #ifdef INTEL_FAPI
171    uint32_t msgLen = 0;
172    fapi_config_resp_t *fapiConfigRsp;
173
174    MAC_ALLOC(fapiConfigRsp, sizeof(fapi_config_resp_t));
175    if(!fapiConfigRsp)
176    {
177       DU_LOG("\nERROR  -->  PHY STUB: Memory allocation failed");
178       return RFAILED;
179    }
180    memset(fapiConfigRsp, 0, sizeof(fapi_config_resp_t));
181    fapiConfigRsp->number_of_invalid_tlvs = NULLP;
182    fapiConfigRsp->number_of_inv_tlvs_idle_only = NULLP;
183    fapiConfigRsp->number_of_missing_tlvs = NULLP;
184    fapiConfigRsp->error_code = MSG_OK;
185    msgLen = sizeof(fapi_config_resp_t) - sizeof(fapi_msg_t);
186    fillMsgHeader(&fapiConfigRsp->header, FAPI_CONFIG_RESPONSE, msgLen);
187
188    DU_LOG("\nINFO   -->  PHY_STUB: Sending Config Response to Lower Mac");
189
190    procPhyMessages(fapiConfigRsp->header.msg_id, \
191          sizeof(fapi_config_resp_t), (void *)fapiConfigRsp);
192    MAC_FREE(fapiConfigRsp, sizeof(fapi_config_resp_t));
193 #endif
194    return ROK;
195 }
196 /*******************************************************************
197  *
198  * @brief Handles param request received from MAC
199  *
200  * @details
201  *
202  *    Function : l1HdlParamReq
203  *
204  *    Functionality:
205  *          -Handles param request received from MAC
206  *
207  * @params[in]   Message length
208  *               Param request message pointer
209  *
210  * @return void
211  *
212  * ****************************************************************/
213
214 void l1HdlParamReq(uint32_t msgLen, void *msg)
215 {
216 #ifdef INTEL_FAPI
217    DU_LOG("\nINFO   -->  PHY_STUB: Received Param Request in PHY");
218
219    /* Build and send PARAM RESPONSE */
220    if(l1BldAndSndParamRsp(msg)!= ROK)
221    {
222       DU_LOG("\nERROR  -->  PHY_STUB: Failed Sending Param Response");
223    }
224    MAC_FREE(msg, sizeof(fapi_param_req_t));
225 #endif
226
227
228 /*******************************************************************
229  *
230  * @brief Handles config request received from MAC
231  *
232  * @details
233  *
234  *    Function : l1HdlConfigReq
235  *
236  *    Functionality:
237  *          -Handles config request received from MAC
238  *
239  * @params[in]   Message length
240  *               config request message pointer
241  *
242  * @return void
243  *
244  * ****************************************************************/
245
246 void l1HdlConfigReq(uint32_t msgLen, void *msg)
247 {
248    memset(&ueDb, 0, sizeof(UeDb));
249
250 #ifdef INTEL_FAPI
251    p_fapi_api_queue_elem_t configReqElem = (p_fapi_api_queue_elem_t)msg;
252    fapi_config_req_t *configReq = (fapi_config_req_t *)(configReqElem +1);
253
254    DU_LOG("\nINFO   -->  PHY_STUB: Received Config Request in PHY");
255
256    /* Handling CONFIG RESPONSE */
257    if(l1BldAndSndConfigRsp(configReq)!= ROK)
258    {
259       DU_LOG("\nERROR  -->  PHY_STUB: Failed Sending config Response");
260    }
261
262    MAC_FREE(msg, msgLen);
263 #endif
264
265 }
266
267 /*******************************************************************
268  *
269  * @brief Build and Send CRC Indication
270  *
271  * @details
272  *
273  *    Function : l1BuildAndSendCrcInd
274  *
275  *    Functionality:
276  *      Build and Send CRC Indication
277  *
278  * @params[in] Slot
279  *             SFN 
280  * @return ROK     - success
281  *         RFAILED - failure
282  *
283  * ****************************************************************/
284 uint16_t l1BuildAndSendCrcInd(uint16_t slot, uint16_t sfn)
285 {
286 #ifdef INTEL_FAPI
287    uint8_t idx = 0;
288    fapi_crc_ind_t  *crcInd;
289
290    MAC_ALLOC(crcInd, sizeof(fapi_crc_ind_t));
291    if(!crcInd)
292    {
293       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for CRC Indication Message");
294       return RFAILED;
295    }
296    memset(crcInd, 0, sizeof(fapi_crc_ind_t));
297
298    /* TODO: Fill the required values. As of now only 1 CRC status PASS is filled */
299    crcInd->sfn = sfn;
300    crcInd->slot = slot;
301    crcInd->numCrcs = 1;
302
303    crcInd->crc[idx].handle = 0;
304    crcInd->crc[idx].rnti = 0;
305    crcInd->crc[idx].harqId = 0;
306    crcInd->crc[idx].tbCrcStatus = 0;
307    crcInd->crc[idx].numCb = 1;
308    crcInd->crc[idx].cbCrcStatus[0] = 0;
309    crcInd->crc[idx].ul_cqi = 0;
310    crcInd->crc[idx].timingAdvance = 0;
311    crcInd->crc[idx].rssi = 0;
312
313    fillMsgHeader(&crcInd->header, FAPI_CRC_INDICATION, \
314          sizeof(fapi_crc_ind_t) - sizeof(fapi_msg_t));
315
316    /* Sending RACH indication to MAC */
317    DU_LOG("\nINFO   -->  PHY STUB: Sending CRC Indication to MAC");
318    procPhyMessages(crcInd->header.msg_id, sizeof(fapi_crc_ind_t), (void *)crcInd);
319    MAC_FREE(crcInd, sizeof(fapi_crc_ind_t));
320 #endif
321    return ROK;
322 } /* l1BuildAndSendCrcInd */
323
324 #ifdef INTEL_FAPI
325 /*******************************************************************
326  *
327  * @brief Build and send Rx data indication
328  *
329  * @details
330  *
331  *    Function : l1BuildAndSendRxDataInd
332  *
333  *    Functionality:
334  *       Build and send Rx data indication
335  *
336  * @params[in] SFN
337  *             Slot
338  * @return ROK     - success
339  *         RFAILED - failure
340  *
341  * ****************************************************************/
342 uint16_t l1BuildAndSendRxDataInd(uint16_t slot, uint16_t sfn, fapi_ul_pusch_pdu_t puschPdu)
343 {
344    uint8_t idx = 0, ueId = 0;
345    fapi_rx_data_indication_t *rxDataInd =NULLP;
346    fapi_pdu_ind_info_t       *pduInfo =NULLP;
347    uint8_t  *pdu = NULLP;
348    uint16_t byteIdx = 0;
349    uint32_t msgLen = 0;
350    MsgType type = 0;
351
352    GET_UE_ID(puschPdu.rnti, ueId);
353    if(!ueDb.ueCb[ueId-1].msg3Sent)
354    {
355       ueDb.ueCb[ueId-1].ueId = ueId;
356       ueDb.ueCb[ueId-1].crnti = puschPdu.rnti;
357       ueDb.ueCb[ueId-1].msg3Sent = true;
358       type = MSG_TYPE_MSG3;
359       sleep(2);
360    }
361    else if(!ueDb.ueCb[ueId-1].msg5ShortBsrSent)
362    {
363       ueDb.ueCb[ueId-1].msg5ShortBsrSent = true;
364       type = MSG_TYPE_SHORT_BSR;
365    }
366    else if(!ueDb.ueCb[ueId-1].msg5Sent)
367    {
368       ueDb.ueCb[ueId-1].msg5Sent = true;
369       type = MSG_TYPE_MSG5;
370    }
371    else if(!ueDb.ueCb[ueId-1].msgRegistrationComp)
372    {
373       ueDb.ueCb[ueId-1].msgRegistrationComp = true;
374       type = MSG_TYPE_REGISTRATION_COMPLETE; 
375    }
376    else if(!ueDb.ueCb[ueId-1].msgSecurityModeComp)
377    {
378       ueDb.ueCb[ueId-1].msgSecurityModeComp = true;
379       type = MSG_TYPE_SECURITY_MODE_COMPLETE;
380    }
381    else if(!ueDb.ueCb[ueId-1].msgRrcReconfiguration)
382    {
383       ueDb.ueCb[ueId-1].msgRrcReconfiguration = true;
384       type = MSG_TYPE_RRC_RECONFIG_COMPLETE;
385    }
386    else
387       return RFAILED;
388
389    MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
390    if(!rxDataInd)
391    {
392       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Indication");
393       return RFAILED;
394    }
395    memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
396    
397    msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
398    rxDataInd->sfn = sfn;
399    rxDataInd->slot = slot;
400    rxDataInd->numPdus = 1;
401
402    pduInfo = &rxDataInd->pdus[idx];
403    pduInfo->handle = puschPdu.handle;
404    pduInfo->rnti = puschPdu.rnti;
405    pduInfo->harqId = puschPdu.puschData.harqProcessId;
406    pduInfo->pdu_length = puschPdu.puschData.tbSize ;
407    pduInfo->ul_cqi = 0;
408    pduInfo->timingAdvance = 0;
409    pduInfo->rssi = 0;
410
411    /* Filling pdu with random values for testing */
412    pduInfo->pduData = NULL;
413    MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
414    if(!pduInfo->pduData)
415    {
416       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Pdu");
417       return RFAILED;
418    }
419    memset(pduInfo->pduData, 0, pduInfo->pdu_length);
420    /* Filling PDU */
421    pdu = (uint8_t *)pduInfo->pduData;
422
423    switch(type)
424    {
425       case MSG_TYPE_MSG3: 
426          {
427             DU_LOG("\nDEBUG  -->  PHY_STUB: Forming MSG3 PDU ");
428             /* For Initial RRC setup Request,
429                MAC subheader format is R/R/LCId (1byte)
430                LCId is CCCH(0)
431                From 38.321 section 6.1.1
432                */
433             pdu[byteIdx++] = 0;
434             /* Hardcoding MAC PDU */
435             pdu[byteIdx++] = 16;
436             pdu[byteIdx++] = 00;
437             pdu[byteIdx++] = 00;
438             pdu[byteIdx++] = 00;
439             pdu[byteIdx++] = 00;
440             pdu[byteIdx++] = 103;
441
442             break;
443          }
444       case MSG_TYPE_SHORT_BSR:
445          {
446             DU_LOG("\nDEBUG  -->  PHY_STUB: Forming SHORT BSR PDU ");
447             uint8_t lcgId = 0;
448             uint8_t bufferSizeIdx = 6;
449
450             /* For Short BSR
451                MAC subheader format is R/R/LcId (1Byte)
452                LCId is 61
453                From 38.321 section 6.1.1
454                */
455             pdu[byteIdx++] = 61;    // LCID
456             pdu[byteIdx++] = (lcgId << 5) | bufferSizeIdx;
457
458             break;
459          }
460
461       case MSG_TYPE_MSG5:
462       {
463          /* For RRC setup complete
464           *
465           * MAC subheader format is R/F/LCId/L (2/3 bytes)
466           * LCId is 1 for SRB1
467           * L is length of PDU i.e 6bytes here 
468           * From 38.321 section 6.1.1
469           *
470           * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
471           * From 38.322, section 6.2.2.4
472           */
473          DU_LOG("\nDEBUG  -->  PHY_STUB: Forming MSG5 PDU");
474          uint8_t  msg5PduLen = 33; /* Length of MSG5 */
475          msg5PduLen += 2; /* RLC subheader */
476          uint8_t msg5[] = {1, msg5PduLen, 128, ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, ueDb.ueCb[ueId-1].pdcpSn++, 16, 0, \
477             5, 223, 128, 16, 94, 64, 3, 64, 68, 252, 97, 0, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, 184, 56, 0, 0, 0, 0, 0};
478
479          msg5PduLen += 2;  /* 2 bytes of MAC header */
480          memcpy(pdu, &msg5, msg5PduLen);
481          byteIdx += msg5PduLen; /* 4 bytes of header : MAC+RLC */
482          break;
483       }
484
485       case MSG_TYPE_SECURITY_MODE_COMPLETE:
486       {
487          /* For security mode complete where RRC Container is dummy
488           *
489           * MAC subheader format is R/F/LCId/L (2/3 bytes)
490           * LCId is 1 for SRB1
491           * L is length of PDU i.e 6bytes here 
492           * From 38.321 section 6.1.1
493           *
494           * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
495           * From 38.322, section 6.2.2.4
496           */
497          DU_LOG("\nDEBUG  -->  PHY_STUB: Forming SECURITY MODE COMPLETE PDU");
498          uint8_t  pduLen = 12; /* Length of PDU */
499          pduLen += 2; /* RLC subheader */
500          uint8_t msg[] = {1, pduLen, 128, ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, ueDb.ueCb[ueId-1].pdcpSn++, 0x2a, 0x40, \
501             0, 0, 0, 0, 0, 0, 0, 0};
502
503          pduLen += 2;  /* 2 bytes of MAC header */
504          memcpy(pdu, &msg, pduLen);
505          byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
506          break;
507       }
508
509       case MSG_TYPE_REGISTRATION_COMPLETE:
510       {
511          /* For rrc reconfig complete where RRC Container is dummy
512           *
513           * MAC subheader format is R/F/LCId/L (2/3 bytes)
514           * LCId is 1 for SRB1
515           * L is length of PDU i.e 6bytes here
516           * From 38.321 section 6.1.1
517           * 
518           * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
519           * From 38.322, section 6.2.2.4
520           */
521          DU_LOG("\nDEBUG  -->  PHY_STUB: Forming RRC REGISTRATION COMPLETE PDU");
522          uint8_t  pduLen = 12; /* Length of PDU */
523          pduLen += 2; /* RLC subheader */
524          uint8_t msg[] = {1, pduLen, 128, ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, ueDb.ueCb[ueId-1].pdcpSn++, 0x3a, 0x81, \
525             0xbf, 0, 0x21, 0x80, 0, 0, 0, 0};
526
527          pduLen += 2;  /* 2 bytes of MAC header */
528          memcpy(pdu, &msg, pduLen);
529          byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
530          break;
531       }
532
533       case MSG_TYPE_RRC_RECONFIG_COMPLETE:
534       {
535          /* For rrc reconfig complete where RRC Container is dummy
536           *
537           * MAC subheader format is R/F/LCId/L (2/3 bytes)
538           * LCId is 1 for SRB1
539           * L is length of PDU i.e 6bytes here
540           * From 38.321 section 6.1.1
541           *
542           * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
543           * From 38.322, section 6.2.2.4
544           */
545          DU_LOG("\nDEBUG  -->  PHY_STUB: Forming RRC RECONFIGURATION COMPLETE PDU");
546          uint8_t  pduLen = 13; /* PDU length */
547          pduLen += 2; /* RLC sub header */
548          uint8_t msg[] = {1, pduLen, 128, ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, ueDb.ueCb[ueId-1].pdcpSn++, 8, 64, 0, 0,\
549             0, 0, 0, 0, 0, 0, 0};
550
551          pduLen += 2;  /* 2bytes of MAC header */
552          memcpy(pdu, &msg, pduLen);
553          byteIdx += pduLen; /* 4 bytes of header : MAC+RLC*/
554          break;
555
556       }
557
558       default:
559       break;
560    } /* End of switch(type) */
561
562    /* Filling MAC SDU for Padding bytes*/
563    if(byteIdx < pduInfo->pdu_length)
564    {
565       /* For Padding
566          MAC subheader format is R/R/LCId (1byte)
567          LCId is 63 for padding
568          From 38.321 section 6.1.1
569          */
570       pdu[byteIdx++] = 63;
571
572       for(; byteIdx < pduInfo->pdu_length; byteIdx++)
573          pdu[byteIdx] = 0;
574    }
575    msgLen += pduInfo->pdu_length;
576
577    fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
578
579    /* Sending Rx data indication to MAC */
580    DU_LOG("\nINFO   -->  PHY STUB: Sending Rx data Indication to MAC");
581    procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
582
583    if(pduInfo->pdu_length)
584       MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
585    MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
586    return ROK;
587 }
588 #endif
589
590 /*******************************************************************
591  *
592  * @brief Builds and Sends RACH indication to MAC 
593  *
594  * @details
595  *
596  *    Function : l1BuildAndSendRachInd 
597  *
598  *    Functionality:
599  *      Builds and Sends RACH indication to MAC
600  *
601  * @params[in] SFN value 
602  *             slot value
603  * @return ROK     - success
604  *         RFAILED - failure
605  *
606  * ****************************************************************/
607 uint16_t l1BuildAndSendRachInd(uint16_t slot, uint16_t sfn)
608 {
609 #ifdef INTEL_FAPI
610    uint8_t   rachPduIdx = 0; 
611    uint8_t   preamIdx = 0;
612    fapi_rach_pdu_t  *rachPdu;
613    fapi_rach_indication_t  *rachInd;
614
615    /* Building RACH indication */
616    MAC_ALLOC(rachInd, sizeof(fapi_rach_indication_t));
617    if(!rachInd)
618    {
619       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for Rach Indication Message");
620       return RFAILED;
621    }
622    memset(rachInd, 0, sizeof(fapi_rach_indication_t)); 
623    rachInd->sfn = sfn;
624    rachInd->slot = slot;
625    rachInd->numPdus = 1;
626
627    rachPdu = &rachInd->rachPdu[rachPduIdx];
628    rachPdu->phyCellId = NR_PCI;
629    rachPdu->symbolIndex = 0;
630    rachPdu->slotIndex = slot;
631    rachPdu->freqIndex = 0;
632    rachPdu->avgRssi = 0;
633    rachPdu->avgSnr = 0;
634    rachPdu->numPreamble = 1;
635
636    rachPdu->preambleInfo[preamIdx].preambleIndex = 3;
637    rachPdu->preambleInfo[preamIdx].timingAdvance = 0;
638    rachPdu->preambleInfo[preamIdx].preamblePwr = 0;
639
640    fillMsgHeader(&rachInd->header, FAPI_RACH_INDICATION, \
641          sizeof(fapi_rach_indication_t) - sizeof(fapi_msg_t));
642
643    /* Sending RACH indication to MAC */
644    DU_LOG("\nINFO   -->  PHY STUB: Sending RACH Indication to MAC");
645    procPhyMessages(rachInd->header.msg_id, sizeof(fapi_rach_indication_t), (void *)rachInd);
646    MAC_FREE(rachInd, sizeof(fapi_rach_indication_t));
647 #endif
648    return ROK;
649 }
650
651 /*******************************************************************
652  *
653  * @brief Builds and Send the Slot Indication message to MAC
654  *
655  * @details
656  *
657  *    Function : l1BuildAndSendSlotIndication
658  *
659  *    Functionality:
660  *          -Send the Slot indication Message to MAC
661  *
662  * @params[in]   Message length
663  *               config request message pointer
664  *
665  * @return void
666  *
667  * ****************************************************************/
668 uint16_t l1BuildAndSendSlotIndication()
669 {
670    Pst pst;
671    Buffer *mBuf;
672
673 #ifdef INTEL_FAPI
674    fapi_slot_ind_t *slotIndMsg;
675
676    MAC_ALLOC_SHRABL_BUF(slotIndMsg, sizeof(fapi_slot_ind_t));
677    if(!slotIndMsg)
678    {
679       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for slot Indication Message");
680       return RFAILED;
681    }
682    else
683    {
684       memset(slotIndMsg, 0, sizeof(fapi_slot_ind_t));
685       slotIndMsg->sfn = sfnValue;
686       slotIndMsg->slot = slotValue;
687
688 #ifdef ODU_SLOT_IND_DEBUG_LOG
689       DU_LOG("\n\nDEBUG  -->  PHY_STUB: Sending Slot Indication [%d : %d] to MAC", sfnValue, slotValue);
690 #endif
691
692       /* increment for the next TTI */
693       slotValue++;
694       if(sfnValue >= MAX_SFN_VALUE && slotValue > MAX_SLOT_VALUE)
695       {
696          sfnValue = 0;
697          slotValue = 0;
698       }
699       else if(slotValue > MAX_SLOT_VALUE)
700       {
701          sfnValue++;
702          slotValue = 0;
703       }
704       fillMsgHeader(&slotIndMsg->header, FAPI_SLOT_INDICATION, \
705             sizeof(fapi_slot_ind_t) - sizeof(fapi_msg_t));
706
707       memset(&pst, 0, sizeof(Pst));
708       FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_SLOT_IND);
709       ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
710       if(!mBuf)
711       {
712          DU_LOG("\nERROR  --> PHY_STUB: Failed to allocate memory for slot indication buffer");
713          MAC_FREE_SHRABL_BUF(pst.region, pst.pool, slotIndMsg, sizeof(fapi_slot_ind_t));
714          return RFAILED;
715       }
716       CMCHKPK(oduPackPointer, (PTR)slotIndMsg, mBuf);
717       ODU_POST_TASK(&pst, mBuf);
718    }
719 #endif
720    return ROK;
721 }
722
723 /*******************************************************************
724  *
725  * @brief Handles start request received from MAC
726  *
727  * @details
728  *
729  *    Function : l1HdlStartReq
730  *
731  *    Functionality:
732  *          -Handles start request received from MAC
733  *
734  * @params[in]   Message length
735  *               config request message pointer
736  *
737  * @return void
738  *
739  * ****************************************************************/
740
741 S16 l1HdlStartReq(uint32_t msgLen, void *msg)
742 {
743 #ifdef INTEL_FAPI
744    if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
745    {
746       l1HdlSlotIndicaion(FALSE);
747       l1StartConsoleHandler();
748       MAC_FREE(msg, msgLen);
749    }
750    else
751    {
752       DU_LOG("\nINFO   -->  PHY_STUB: Received Start Req in PHY State %d", lwrMacCb.phyState);
753       MAC_FREE(msg, msgLen);
754       return RFAILED;
755    }
756 #endif
757    return ROK;
758 }
759
760 /*******************************************************************
761  *
762  * @brief Handles Dl Tti request received from MAC
763  *
764  * @details
765  *
766  *    Function : l1HdlDlTtiReq
767  *
768  *    Functionality:
769  *          -Handles Dl Tti request received from MAC
770  *
771  * @params[in]   Message length
772  *               Dl Tti request message pointer
773  *
774  * @return void
775  *
776  * ****************************************************************/
777
778 S16 l1HdlDlTtiReq(uint16_t msgLen, void *msg)
779 {
780 #ifdef INTEL_FAPI
781    p_fapi_api_queue_elem_t dlTtiElem = (p_fapi_api_queue_elem_t)msg;
782    fapi_dl_tti_req_t *dlTtiReq = (fapi_dl_tti_req_t *)(dlTtiElem +1);
783    
784    uint8_t pduCount = 0;
785
786 #ifdef ODU_SLOT_IND_DEBUG_LOG
787    if(dlTtiReq->nPdus == 0)
788    {
789       DU_LOG("\nDEBUG  -->  PHY_STUB: No PDU in DL TTI Request");
790    }
791    else
792    {  
793      DU_LOG("\nDEBUG  -->  PHY STUB: DL TTI Request at sfn=%d slot=%d",dlTtiReq->sfn,dlTtiReq->slot);
794    }
795 #endif 
796
797    for(pduCount=0; pduCount<dlTtiReq->nPdus; pduCount++)
798    {
799       if(dlTtiReq->pdus[pduCount].pduType == 3) //SSB_PDU_TYPE
800       {
801          DU_LOG("\nINFO   -->  PHY_STUB: SSB PDU");
802       }
803       else if(dlTtiReq->pdus[pduCount].pduType == 0)
804       {
805          DU_LOG("\nINFO   -->  PHY_STUB: PDCCH PDU");
806       }
807       else if(dlTtiReq->pdus[pduCount].pduType == 1)
808       {
809          DU_LOG("\nINFO   -->  PHY_STUB: PDSCH PDU");
810       }
811    }
812
813    /* Free FAPI message */
814    MAC_FREE(msg, msgLen);
815 #endif
816    return ROK;
817 }
818
819 /*******************************************************************
820  *
821  * @brief Handles tx_data request received from MAC
822  *
823  * @details
824  *
825  *    Function : l1HdlTxDataReq
826  *
827  *    Functionality:
828  *          -Handles tx_data request received from MAC
829  *
830  * @params[in]   Message length
831  *               tx_data request message pointer
832  *
833  * @return void
834  *
835  * ****************************************************************/
836
837 S16 l1HdlTxDataReq(uint16_t msgLen, void *msg)
838 {
839 #ifdef INTEL_FAPI
840    p_fapi_api_queue_elem_t txDataElem = (p_fapi_api_queue_elem_t)msg;
841    fapi_tx_data_req_t *txDataReq = (fapi_tx_data_req_t *)(txDataElem +1);
842
843    DU_LOG("\nINFO   -->  PHY STUB: TX DATA Request at sfn=%d slot=%d",txDataReq->sfn,txDataReq->slot);
844 /*
845    if(dlDedMsg)
846    {
847       DU_LOG("\nINFO   -->  PHY_STUB: TxDataPdu for DED MSG sent");
848       dlDedMsg = false;
849    }
850 */
851    MAC_FREE(msg, msgLen);
852 #endif
853    return ROK;
854 }
855
856 #ifdef INTEL_FAPI
857 /*******************************************************************
858  *
859  * @brief Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
860  *
861  * @details
862  *
863  *    Function : fillPucchF0F1PduInfo
864  *
865  *    Functionality:
866  *       Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1 
867  *
868  * @params[in] fapi_uci_o_pucch_f0f1_t *
869  *             pucchPdu
870  * @return ROK     - success
871  *         RFAILED - failure
872  *
873  * ****************************************************************/
874 uint8_t fillPucchF0F1PduInfo(fapi_uci_o_pucch_f0f1_t *pduInfo, fapi_ul_pucch_pdu_t pucchPdu)
875 {
876    uint8_t idx = 0;
877
878    pduInfo->handle = pucchPdu.handle;
879    pduInfo->pduBitmap = 1;  //hardcoded for SR
880    pduInfo->pucchFormat = pucchPdu.formatType;
881    pduInfo->ul_cqi = 0;
882    pduInfo->rnti = pucchPdu.rnti;
883    pduInfo->timingAdvance = 0;
884    pduInfo->rssi = 0;
885    if(pduInfo->pduBitmap & SR_PDU_BITMASK)
886    {
887       pduInfo->srInfo.srIndication = SR_DETECTED;
888       pduInfo->srInfo.srConfidenceLevel = CONFDC_LEVEL_GOOD;
889    }
890    if(pduInfo->pduBitmap & HARQ_PDU_BITMASK)
891    {
892       pduInfo->harqInfo.numHarq++;
893       pduInfo->harqInfo.harqConfidenceLevel = CONFDC_LEVEL_GOOD;
894       for(idx = 0; idx < pduInfo->harqInfo.numHarq; idx++)
895       {
896          pduInfo->harqInfo.harqValue[idx] = HARQ_PASS;
897       }
898    }
899    return ROK;
900 }
901 /*******************************************************************
902  *
903  * @brief Fills UCI Pdu Information
904  *
905  * @details
906  *
907  *    Function : fillUciPduInfo
908  *
909  *    Functionality:
910  *       Fills UCI Pdu Information
911  *
912  * @params[in] Pointer to uciPdu
913  *             pucchPdu
914  * @return ROK     - success
915  *         RFAILED - failure
916  *
917  * ****************************************************************/
918 uint8_t fillUciPduInfo(fapi_uci_pdu_info_t *uciPdu, fapi_ul_pucch_pdu_t pucchPdu)
919 {
920    uint8_t ret = ROK;
921
922    /*TODO: The pduType is hardcoded here to support 
923      UCI Ind for PUCCH forat0/format1. This is to be
924      modified when we get SR form UE */
925    uciPdu->pduType = UCI_IND_PUCCH_F0F1;
926    switch(uciPdu->pduType)
927    {
928       case UCI_IND_PUSCH:
929          break;
930       case UCI_IND_PUCCH_F0F1:
931          {
932             fapi_uci_o_pucch_f0f1_t *pduInfo = NULLP;
933
934             pduInfo = &uciPdu->uci.uciPucchF0F1;
935             ret = fillPucchF0F1PduInfo(pduInfo, pucchPdu);
936             uciPdu->pduSize = sizeof(fapi_uci_o_pucch_f0f1_t);
937          }
938          break;
939       case UCI_IND_PUCCH_F2F3F4:
940          break;
941       default:
942          DU_LOG("\nERROR  -->  PHY_STUB: Invalid Pdu Type %d", uciPdu->pduType);
943          break;
944    }
945    return ret;
946 }
947
948 /*******************************************************************
949  *
950  * @brief Build and send Uci indication
951  *
952  * @details
953  *
954  *    Function : l1BuildAndSendUciInd
955  *
956  *    Functionality:
957  *       Build and send Uci indication
958  *
959  * @params[in] SFN
960  *             Slot
961  * @return ROK     - success
962  *         RFAILED - failure
963  *
964  * ****************************************************************/
965 uint8_t l1BuildAndSendUciInd(uint16_t slot, uint16_t sfn, fapi_ul_pucch_pdu_t pucchPdu)
966 {
967    uint8_t uciIdx = 0;
968    uint8_t nUciPdus = 0;
969    uint8_t ret = ROK;
970    uint32_t msgLen = 0;
971    fapi_uci_indication_t *uciInd =  NULLP;
972
973    MAC_ALLOC(uciInd, sizeof(fapi_uci_indication_t));
974    if(!uciInd)
975    {
976       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for UCI Indication");
977       return RFAILED;
978    }
979    memset(uciInd, 0, sizeof(fapi_uci_indication_t));
980    uciInd->sfn = sfn;
981    uciInd->slot = slot;
982    uciInd->numUcis = 1;   //consdering the UCI Ind for SR
983    nUciPdus = uciInd->numUcis;
984    while(nUciPdus)
985    {
986       ret = fillUciPduInfo(&uciInd->uciPdu[uciIdx], pucchPdu);
987       uciIdx++;
988       nUciPdus--;
989    }
990    if(ret == ROK)
991    {
992       msgLen = sizeof(fapi_uci_indication_t)- sizeof(fapi_msg_t);
993       fillMsgHeader(&uciInd->header, FAPI_UCI_INDICATION, msgLen);
994
995       /* Sending UCI indication to MAC */
996       DU_LOG("\nINFO   -->  PHY STUB: Sending UCI Indication to MAC");
997       procPhyMessages(uciInd->header.msg_id, sizeof(fapi_uci_indication_t), (void *)uciInd);
998    }
999    MAC_FREE(uciInd, sizeof(fapi_uci_indication_t));
1000    return ret;
1001 }
1002 #endif
1003
1004 /*******************************************************************
1005  *
1006  * @brief Handles Ul Tti request received from MAC
1007  *
1008  * @details
1009  *
1010  *    Function : l1HdlUlTtiReq
1011  *
1012  *    Functionality:
1013  *          -Handles Ul Tti request received from MAC
1014  *
1015  * @params[in]   Message length
1016  *               Ul Tti request message pointer
1017  *
1018  * @return void
1019  *
1020  * ****************************************************************/
1021
1022 S16 l1HdlUlTtiReq(uint16_t msgLen, void *msg)
1023 {
1024 #ifdef INTEL_FAPI
1025    p_fapi_api_queue_elem_t ulTtiElem = (p_fapi_api_queue_elem_t)msg;
1026    fapi_ul_tti_req_t *ulTtiReq = (fapi_ul_tti_req_t *)(ulTtiElem +1);
1027    uint8_t numPdus = ulTtiReq->nPdus;
1028
1029 #ifdef ODU_SLOT_IND_DEBUG_LOG
1030    if(numPdus == 0)
1031    {
1032       DU_LOG("\nINFO   -->  PHY STUB: No PDU received in UL TTI Req");
1033    }
1034    else
1035    {
1036       DU_LOG("\nINFO   -->  PHY STUB: Received UL TTI Request");
1037    }
1038 #endif 
1039
1040    while(numPdus)
1041    {
1042       if(ulTtiReq->pdus[numPdus-1].pduType == 0)
1043       {
1044          DU_LOG("\nINFO   -->  PHY STUB: PRACH PDU");
1045       }
1046       if(ulTtiReq->pdus[numPdus-1].pduType == 1)
1047       {
1048          DU_LOG("\nINFO   -->  PHY STUB: PUSCH PDU");
1049          l1BuildAndSendRxDataInd(ulTtiReq->slot, ulTtiReq->sfn, \
1050                ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu); 
1051       }
1052       if(ulTtiReq->pdus[numPdus-1].pduType == 2)
1053       {
1054          DU_LOG("\nINFO   -->  PHY STUB: PUCCH PDU");
1055          fapi_ul_tti_req_t ulTtiSlotInd;
1056          memset(&ulTtiSlotInd, 0, sizeof(fapi_ul_tti_req_t));
1057          ulTtiSlotInd.slot = ulTtiReq->slot;
1058          ulTtiSlotInd.sfn  = ulTtiReq->sfn;
1059          ADD_DELTA_TO_TIME(ulTtiSlotInd, ulTtiSlotInd, SLOT_DELAY);
1060          l1BuildAndSendUciInd(ulTtiSlotInd.slot, ulTtiSlotInd.sfn, \
1061                ulTtiReq->pdus[numPdus-1].pdu.pucch_pdu);
1062       }
1063       numPdus--;
1064    }
1065
1066    /* TODO: [SFN:SLOT] at which RACH Indication is sent should be calculated
1067     * based on PRACH cfg index */
1068    /* Send RACH Ind to L2 for first UE */
1069    if(ueDb.ueCb[UE_IDX_0].rachIndSent == false && ulTtiReq->sfn == 16 && ulTtiReq->slot == 6)
1070    {
1071       ueDb.ueCb[UE_IDX_0].rachIndSent = true;
1072       l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn);
1073       ueDb.numActvUe++;
1074    }
1075 #if 0
1076    /* Send RACH Ind to L2 for second UE */
1077    if(ueDb.ueCb[UE_IDX_1].rachIndSent == false && ulTtiReq->sfn == 304 && ulTtiReq->slot == 0)
1078    {
1079       ueDb.ueCb[UE_IDX_1].rachIndSent = true;
1080       l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn);
1081       ueDb.numActvUe++;
1082    }
1083
1084    /* Send RACH Ind to L2 for third UE */
1085    if(ueDb.ueCb[UE_IDX_2].rachIndSent == false && ulTtiReq->sfn == 526 && ulTtiReq->slot == 0)
1086    {
1087       ueDb.ueCb[UE_IDX_2].rachIndSent = true;
1088       l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn);
1089       ueDb.numActvUe++;
1090    }
1091 #endif
1092    MAC_FREE(msg, msgLen);
1093 #endif
1094    return ROK;
1095 }
1096
1097 /*******************************************************************
1098  *
1099  * @brief Builds and Send the stop Indication message to MAC
1100  *
1101  * @details
1102  *
1103  *    Function : l1BuildAndSendStopInd
1104  *
1105  *    Functionality:
1106  *          -Send the Stop indication Message to MAC
1107  *
1108  *
1109  * @return void
1110  *
1111  * ****************************************************************/
1112 uint16_t l1BuildAndSendStopInd()
1113 {
1114 #ifdef INTEL_FAPI
1115    Pst pst;
1116    Buffer *mBuf = NULLP;
1117    fapi_stop_ind_t *stopIndMsg = NULLP;
1118    uint32_t msgLen = 0;
1119
1120    MAC_ALLOC_SHRABL_BUF(stopIndMsg, sizeof(fapi_stop_ind_t));
1121    if(!stopIndMsg)
1122    {
1123       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for stop Indication Message");
1124       return RFAILED;
1125    }
1126    else
1127    {
1128       fillMsgHeader(&stopIndMsg->header, FAPI_STOP_INDICATION, msgLen);
1129       DU_LOG("\n\nINFO   -->  PHY_STUB: Processing Stop indication to MAC");
1130
1131       memset(&pst, 0, sizeof(Pst));
1132       FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_STOP_IND);
1133       ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
1134       if(!mBuf)
1135       {
1136          DU_LOG("\nERROR  --> PHY_STUB: Failed to allocate memory for slot indication buffer");
1137          MAC_FREE_SHRABL_BUF(pst.region, pst.pool, stopIndMsg, sizeof(fapi_stop_ind_t));
1138          return RFAILED;
1139       }
1140       CMCHKPK(oduPackPointer, (PTR)stopIndMsg, mBuf);
1141       ODU_POST_TASK(&pst, mBuf);
1142    }
1143 #endif
1144    return ROK;
1145 }
1146
1147 /*******************************************************************
1148  *
1149  * @brief Handles stop request received from MAC
1150  *
1151  * @details
1152  *
1153  *    Function : l1HdlStopReq
1154  *
1155  *    Functionality:
1156  *          -Handles stop request received from MAC
1157  *
1158  * @params[in]   Message length
1159  *               stop request message pointer
1160  *
1161  * @return void
1162  *
1163  * ****************************************************************/
1164
1165 S16 l1HdlStopReq(uint32_t msgLen, void *msg)
1166 {
1167 #ifdef INTEL_FAPI
1168    if(lwrMacCb.phyState == PHY_STATE_RUNNING)
1169    {
1170       l1HdlSlotIndicaion(TRUE);
1171
1172       /* Initialize all global variables */
1173       sfnValue = 0;
1174       slotValue = 0;
1175       memset(&ueDb, 0, sizeof(UeDb));
1176
1177       DU_LOG("\nINFO   -->  PHY_STUB: Slot Indication is stopped successfully");
1178       MAC_FREE(msg, msgLen);
1179    }
1180    else
1181    {
1182       DU_LOG("\nINFO  -->  PHY_STUB: Received Stop Req in PHY State %d", lwrMacCb.phyState);
1183       MAC_FREE(msg, msgLen);
1184       return RFAILED;
1185    }
1186 #endif
1187    return ROK;
1188 }
1189
1190 #if 0
1191 /*******************************************************************
1192  *
1193  * @brief Build And Send Rx Data Ind for Msg5
1194  *
1195  * @details
1196  *
1197  *    Function : l1BuildAndSendMsg5
1198  *
1199  *    Functionality: Build And Send Rx Data Ind for Msg5
1200  *
1201  * @params[in] SFN
1202  *             Slot
1203  * @return ROK     - success
1204  *         RFAILED - failure
1205  *
1206  * ****************************************************************/
1207 uint8_t l1BuildAndSendMsg5(uint16_t sfn, uint16_t slot)
1208 {   
1209 #ifdef INTEL_FAPI
1210    uint8_t idx = 0;
1211    fapi_rx_data_indication_t *rxDataInd;
1212    fapi_pdu_ind_info_t       *pduInfo;
1213    uint8_t  *pdu;
1214    uint16_t byteIdx = 0;
1215    uint32_t msgLen = 0;
1216
1217    MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1218    if(!rxDataInd)
1219    {
1220       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Indication for msg5");
1221       return RFAILED;
1222    }
1223    memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1224
1225    /* TODO: Fill the required values */
1226    msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1227    rxDataInd->sfn = sfn;
1228    rxDataInd->slot = slot;
1229    rxDataInd->numPdus = 1;
1230
1231    pduInfo = &rxDataInd->pdus[idx];
1232    pduInfo->handle = 100;
1233    pduInfo->rnti = 100;
1234    pduInfo->harqId = 1;
1235    pduInfo->pdu_length = 25;
1236    pduInfo->ul_cqi = 0;
1237    pduInfo->timingAdvance = 0;
1238    pduInfo->rssi = 0;
1239
1240    /* Filling pdu with random values for testing */
1241    pduInfo->pduData = NULL;
1242    MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1243    if(!pduInfo->pduData)
1244    {
1245       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Pdu");
1246       return RFAILED;
1247    }
1248
1249    /* Filling PDU */
1250    pdu = (uint8_t *)pduInfo->pduData;
1251
1252    uint8_t  msg5PduLen = 33;
1253    /* For RRC setup complete
1254       MAC subheader format is R/F/LCId/L (2/3 bytes)
1255       LCId is 1 for SRB1
1256       L is length of PDU i.e 6bytes here
1257       From 38.321 section 6.1.1
1258     */
1259    uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
1260       64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
1261          184, 56, 0, 0, 0, 0, 0};
1262
1263    msg5PduLen += 2;  /* 2bytes of header */
1264    memcpy(pdu, &msg5, msg5PduLen);
1265    byteIdx += msg5PduLen; /* 2 bytes of header */
1266
1267    /* Filling MAC SDU for Padding bytes*/
1268    if(byteIdx < pduInfo->pdu_length)
1269    {
1270       /* For Padding
1271          MAC subheader format is R/R/LCId (1byte)
1272          LCId is 63 for padding
1273          From 38.321 section 6.1.1
1274        */
1275       pdu[byteIdx++] = 63;
1276
1277       for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1278          pdu[byteIdx] = 0;
1279    }
1280    msgLen += pduInfo->pdu_length;
1281
1282    fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1283
1284    /* Sending Rx data indication to MAC */
1285    DU_LOG("\nINFO   -->  PHY STUB: Sending Rx data Indication to MAC");
1286    procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1287
1288    if(pduInfo->pdu_length)
1289       MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1290    MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1291 #endif
1292    return ROK;
1293 }
1294 #endif
1295
1296 /*******************************************************************
1297  *
1298  * @brief Handles Ul Dci request received from MAC
1299  *
1300  * @details
1301  *
1302  *    Function : l1HdlUlDciReq
1303  *
1304  *    Functionality:
1305  *          -Handles Ul Dci request received from MAC
1306  *
1307  * @params[in]   Message length
1308  *               Ul Dci request message pointer
1309  *
1310  * @return void
1311  *
1312  * ****************************************************************/
1313
1314 S16 l1HdlUlDciReq(uint16_t msgLen, void *msg)
1315 {
1316 #ifdef INTEL_FAPI
1317    p_fapi_api_queue_elem_t ulDciElem = (p_fapi_api_queue_elem_t)msg;
1318    fapi_ul_dci_req_t *ulDciReq = (fapi_ul_dci_req_t *)(ulDciElem +1);
1319    uint8_t numPdus = ulDciReq->numPdus;
1320
1321    while(numPdus)
1322    {
1323       if(ulDciReq->pdus[numPdus-1].pduType == 0)
1324       {
1325          DU_LOG("\nINFO   -->  PHY STUB: Received UL DCI Request for PDCCH PDU");
1326          //l1BuildAndSendMsg5(ulDciReq->sfn, ulDciReq->slot);
1327          //msg5Sent = true;
1328       }
1329       numPdus--;
1330    }
1331
1332    MAC_FREE(msg, msgLen);
1333 #endif
1334    return ROK;
1335 }
1336
1337 /*******************************************************************
1338  *
1339  * @brief Send UL user data to DU
1340  *
1341  * @details
1342  *
1343  *    Function : l1SendUlUserData
1344  *
1345  *    Functionality: Send UL user data to DU
1346  *
1347  * @params[in]
1348  * @return ROK     - success
1349  *         RFAILED - failure
1350  *
1351  * ****************************************************************/
1352 uint8_t l1SendUlUserData(uint8_t drbId, uint8_t ueIdx)
1353 {
1354    uint8_t cnt = 0;
1355    fapi_rx_data_indication_t *rxDataInd;
1356    fapi_pdu_ind_info_t       *pduInfo;
1357    uint8_t  *pdu = NULLP;
1358    uint16_t byteIdx = 0;
1359    uint32_t msgLen = 0;
1360    uint8_t idx = 0;
1361    uint8_t lcId = 0;
1362
1363    MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1364    if(!rxDataInd)
1365    {
1366       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Indication");
1367       return RFAILED;
1368    }
1369    memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1370
1371    msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1372    rxDataInd->sfn = 0;
1373    rxDataInd->slot = 0;
1374    rxDataInd->numPdus = 1;
1375
1376    /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1377    pduInfo = &rxDataInd->pdus[idx];
1378    pduInfo->handle = ueIdx + ODU_START_CRNTI;
1379    pduInfo->rnti = ueIdx + ODU_START_CRNTI;
1380    pduInfo->harqId = 1;
1381    /* Since user data size = 50bytes and 2 bytes of MAC header and 3 byte of RLC header, 
1382     * setting tbsize = 56 from Table 5.1.3.2-1 spec 38.214 */
1383    pduInfo->pdu_length = 56;
1384    pduInfo->ul_cqi = 0;
1385    pduInfo->timingAdvance = 0;
1386    pduInfo->rssi = 0;
1387
1388    /* Filling pdu with random values for testing */
1389    pduInfo->pduData = NULL;
1390    MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1391    if(!pduInfo->pduData)
1392    {
1393       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Pdu");
1394       return RFAILED;
1395    }
1396
1397    /* Filling PDU */
1398    pdu = (uint8_t *)pduInfo->pduData;
1399    msgLen = 52;
1400
1401    /* For UL User data
1402       MAC subheader format is R/F/LCId/L (2/3 bytes)
1403       LCId is 4 for DRB1
1404       L is length of PDU i.e 50 bytes
1405       From 38.321 section 6.1.1
1406       From 38.322 section 6.2.2.4, 6.2.2.3 for AM, UM Header
1407     */
1408
1409     /* Below ulMsg supports 12bit SN for UM mode */
1410                                /*  SI  SN */
1411     lcId = MIN_DRB_LCID + drbId;
1412     uint8_t ulMsg[] = {lcId, msgLen,   0, 0, 0, 0, 0, 50, 0, 0, 0, 0, 0, 1, 0, 0, 192, 168, 130, 81, 192, 168, 130, 82, 84, 104,
1413     105, 115, 32, 105, 115, 32, 69, 71, 84, 80, 32, 100, 97, 116, 97, 32, 102, 114, 111, 109, 32, 68, 85, 0, 0, 0, 0, 0};
1414     msgLen += 2;  /* 2bytes of header */
1415     memcpy(pdu, &ulMsg, msgLen);
1416     byteIdx += msgLen; /* 2 bytes of header */
1417
1418    /* Filling MAC SDU for Padding bytes*/
1419    if(byteIdx < pduInfo->pdu_length)
1420    {
1421       /* For Padding
1422          MAC subheader format is R/R/LCId (1byte)
1423          LCId is 63 for padding
1424          From 38.321 section 6.1.1
1425        */
1426       pdu[byteIdx++] = 63;
1427
1428       for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1429          pdu[byteIdx] = 0;
1430    }
1431    msgLen += pduInfo->pdu_length;
1432
1433    fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1434
1435     /* Send Message to peer */
1436     while(cnt < NUM_UL_PACKETS)
1437     {
1438        DU_LOG("\nDEBUG  -->  PHY STUB : Sending UL User Data[%d][LCID:%d] at sfn %d slot %d", cnt+1, lcId, sfnValue, slotValue);
1439        /* Sending Rx data indication to MAC */
1440        rxDataInd->sfn = sfnValue;
1441        rxDataInd->slot = slotValue;
1442        procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1443        cnt++;
1444     }
1445
1446     if(pduInfo->pdu_length)
1447        MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1448     MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1449     return ROK;
1450 }
1451
1452 /*******************************************************************
1453  *
1454  * @brief Sends RLC Status PDU to DU
1455  *
1456  * @details
1457  *
1458  *    Function : l1SendStatusPdu
1459  *
1460  *    Functionality: Send RLC Status PDU to DU
1461  *
1462  * @params[in]
1463  * @return ROK     - success
1464  *         RFAILED - failure
1465  *
1466  * ****************************************************************/
1467 uint8_t l1SendStatusPdu()
1468 {
1469    fapi_rx_data_indication_t *rxDataInd;
1470    fapi_pdu_ind_info_t       *pduInfo;
1471    uint8_t  *pdu = NULLP;
1472    uint16_t byteIdx = 0;
1473    uint32_t msgLen = 0;
1474    uint8_t idx = 0;
1475
1476    MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1477    if(!rxDataInd)
1478    {
1479       printf("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Indication");
1480       return RFAILED;
1481    }
1482    memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1483
1484    msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1485    rxDataInd->sfn = 0;
1486    rxDataInd->slot = 0;
1487    rxDataInd->numPdus = 1;
1488
1489    /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1490    pduInfo = &rxDataInd->pdus[idx];
1491    pduInfo->handle = 100;
1492    pduInfo->rnti = 100;
1493    pduInfo->harqId = 1;
1494    /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1495     * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1496    pduInfo->pdu_length = 24;
1497    pduInfo->ul_cqi = 0;
1498    pduInfo->timingAdvance = 0;
1499    pduInfo->rssi = 0;
1500
1501    /* Filling pdu with random values for testing */
1502    pduInfo->pduData = NULL;
1503    MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1504    if(!pduInfo->pduData)
1505    {
1506       printf("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Pdu");
1507       return RFAILED;
1508    }
1509
1510    /* Filling PDU */
1511    pdu = (uint8_t *)pduInfo->pduData;
1512    msgLen = 3;
1513
1514    /* For RLC Status PDU
1515     * MAC subheader format is R/F/LCId/L (2/3 bytes)
1516     * LCId is 4 for DRB1
1517     * L is length of Status PDU i.e 3 bytes
1518     * From 38.321 section 6.1.1
1519     *
1520     * RLC Status PDU format :
1521     * ---------------------------------
1522     * |D/C|CPT|    ACK_SN             |
1523     * ---------------------------------
1524     * |            ACK_SN             |
1525     * ---------------------------------
1526     * |E1 | R | R | R | R | R | R | R |
1527     * ---------------------------------
1528     *  
1529     * Here, D/C bit = 0 for Control PDU
1530     * CPT bit = 0 since control pdu type is Status PDU
1531     * ACK_SN = 0 as of now, this can be changed based on the 
1532     * scenario being tested
1533     * E1 = 0 because no NACK_SN, E1, E2 and E3 follows it
1534     * R = 0 i.e. reserved bits
1535     * From Spec 38.322 section 6.2.2.5
1536     */
1537    uint8_t statusPdu[] = {4, msgLen, 0, 0, 0};
1538    msgLen += 2;  /* 2bytes of header */
1539    memcpy(pdu, &statusPdu, msgLen);
1540    byteIdx += msgLen; /* 2 bytes of header */
1541
1542
1543    /* Filling MAC SDU for Padding bytes*/
1544    if(byteIdx < pduInfo->pdu_length)
1545    {
1546       /* For Padding
1547          MAC subheader format is R/R/LCId (1byte)
1548          LCId is 63 for padding
1549          From 38.321 section 6.1.1
1550        */
1551       pdu[byteIdx++] = 63;
1552
1553       for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1554          pdu[byteIdx] = 0;
1555    }
1556    msgLen += pduInfo->pdu_length;
1557
1558    fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1559
1560     /* Send Message to peer */
1561     DU_LOG("\nDEBUG  -->  PHY STUB : Sending RLC status pdu at sfn %d slot %d", sfnValue, slotValue);
1562     /* Sending Rx data indication to MAC */
1563     rxDataInd->sfn = sfnValue;
1564     rxDataInd->slot = slotValue;
1565     procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1566
1567     if(pduInfo->pdu_length)
1568        MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1569     MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1570     return ROK;
1571 }
1572
1573 /*******************************************************************
1574  *
1575  * @brief Receives message from MAC
1576  *
1577  * @details
1578  *
1579  *    Function :  l1ProcessFapiRequest
1580  *
1581  *    Functionality:
1582  *       - Receives message from MAC and calls handler
1583  *
1584  * @params[in] Message type
1585  *             Message length
1586  *             Message pointer
1587  *
1588  * @return void
1589  *
1590  * ****************************************************************/
1591
1592 void l1ProcessFapiRequest(uint8_t msgType, uint32_t msgLen, void *msg)
1593 {
1594    switch(msgType)
1595    {
1596 #ifdef INTEL_FAPI
1597       case FAPI_PARAM_REQUEST:
1598          l1HdlParamReq(msgLen, msg);
1599          break;
1600       case FAPI_CONFIG_REQUEST:
1601          l1HdlConfigReq(msgLen, msg);
1602          break;
1603       case FAPI_START_REQUEST:
1604          l1HdlStartReq(msgLen, msg);
1605          break;
1606       case FAPI_DL_TTI_REQUEST:
1607          l1HdlDlTtiReq(msgLen, msg);
1608          break;
1609       case FAPI_TX_DATA_REQUEST:
1610          l1HdlTxDataReq(msgLen, msg);
1611          break;
1612       case FAPI_UL_TTI_REQUEST:
1613          l1HdlUlTtiReq(msgLen, msg);
1614          break;
1615       case FAPI_STOP_REQUEST:
1616          l1HdlStopReq(msgLen, msg);
1617          break;
1618       case FAPI_UL_DCI_REQUEST:
1619          l1HdlUlDciReq(msgLen, msg);
1620          break;
1621       default:
1622          DU_LOG("\nERROR  -->  PHY_STUB: Invalid message type[%x] received at PHY", msgType);
1623          break;
1624 #endif
1625    }
1626 }
1627
1628 #ifdef INTEL_FAPI
1629 /*******************************************************************
1630  *
1631  * @brief Builds and Send the BSR message to MAC
1632  *
1633  * @details
1634  *
1635  *    Function : l1BuildAndSendBSR
1636  *
1637  *   Functionality:
1638  *          -Send the BSR Message to MAC
1639  *
1640  * @params[in]  BSR type 
1641  *              array of LCGID and BSIdx
1642  * @return void
1643  *
1644  *****************************************************************/
1645 uint16_t l1BuildAndSendBSR(uint8_t ueIdx, BsrType bsrType,\
1646              LcgBufferSize lcgBsIdx[MAX_NUM_LOGICAL_CHANNEL_GROUPS])
1647 {
1648    fapi_rx_data_indication_t *rxDataInd;
1649    fapi_pdu_ind_info_t       *pduInfo;
1650    uint8_t  *pdu = NULLP;
1651    uint16_t byteIdx = 0;
1652    uint32_t msgLen = 0;
1653    uint8_t pduIdx = 0, lcgIdx = 0, lcgIdxPos = 0;
1654
1655    MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1656    if(!rxDataInd)
1657    {
1658       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Indication");
1659       return RFAILED;
1660    }
1661    memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1662
1663    msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1664    rxDataInd->sfn = 0;
1665    rxDataInd->slot = 0;
1666    rxDataInd->numPdus = 1;
1667
1668    pduInfo = &rxDataInd->pdus[pduIdx];
1669    pduInfo->handle = (ODU_START_CRNTI + ueIdx);
1670    pduInfo->rnti = (ODU_START_CRNTI + ueIdx);
1671    pduInfo->harqId = 1;
1672
1673    /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1674     * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1675    pduInfo->pdu_length = 24;
1676    pduInfo->ul_cqi = 0;
1677    pduInfo->timingAdvance = 0;
1678    pduInfo->rssi = 0;
1679
1680    /* Filling pdu with random values for testing */
1681    pduInfo->pduData = NULL;
1682    MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1683    if(!pduInfo->pduData)
1684    {
1685       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Pdu");
1686       MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1687       return RFAILED;
1688    }
1689
1690    /* Filling PDU */
1691    pdu = (uint8_t *)pduInfo->pduData;
1692
1693    switch(bsrType)
1694    {
1695       case SHORT_BSR:
1696          {
1697             DU_LOG("\nDEBUG  -->  PHY_STUB: Forming SHORT BSR PDU ");
1698
1699             /* For Short BSR
1700              * MAC subheader format is R/R/LcId (1Byte)
1701              * LCId is 61
1702              * From 38.321 section 6.1.1
1703              */
1704             pdu[byteIdx++] = 61;    // LCID
1705             pdu[byteIdx++] = (lcgBsIdx[0].lcgId << 5) | lcgBsIdx[0].bsIdx;
1706             break;
1707          }
1708
1709       case LONG_BSR:
1710          {
1711             DU_LOG("\nDEBUG  -->  PHY_STUB: Forming LONG BSR PDU ");
1712
1713             /* For Long BSR
1714              * MAC subheader format is R/R/LcId (1Byte)
1715              * LCId is 62
1716              * From 38.321 section 6.1.1
1717              */
1718             pdu[byteIdx++] = 62;    // LCID
1719
1720             /*Octet where lcgId bitmap will be present*/
1721             lcgIdxPos = byteIdx;
1722             byteIdx++;
1723             for(lcgIdx = 0; lcgIdx < MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
1724             {
1725                if(lcgBsIdx[lcgIdx].bsIdx > 0)
1726                {
1727                   pdu[lcgIdxPos] |= 1 << lcgBsIdx[lcgIdx].lcgId;
1728                   pdu[byteIdx++] = lcgBsIdx[lcgIdx].bsIdx;
1729                }
1730             }
1731
1732             break;
1733          }
1734
1735       default:
1736          {
1737             DU_LOG("\nERROR  -->  PHY_STUB: Incorrect BSR type:%d!", bsrType);
1738             if(pduInfo->pdu_length)
1739                MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1740             MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1741             return RFAILED;
1742          }
1743    }
1744    /* Filling MAC SDU for Padding bytes*/
1745    if(byteIdx < pduInfo->pdu_length)
1746    {
1747       /* For Padding
1748        * MAC subheader format is R/R/LCId (1byte)
1749        * LCId is 63 for padding
1750        * From 38.321 section 6.1.1
1751        */
1752       pdu[byteIdx++] = 63;
1753
1754       for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1755          pdu[byteIdx] = 0;
1756    }
1757    msgLen += pduInfo->pdu_length;
1758    fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1759
1760    /* Sending Rx data indication to MAC */
1761    DU_LOG("\nINFO   -->  PHY STUB: Sending Rx data Indication to MAC");
1762    procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1763
1764    if(pduInfo->pdu_length)
1765       MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1766    MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1767    return ROK;
1768 }
1769 #endif
1770
1771 /**********************************************************************
1772   End of file
1773  **********************************************************************/