[Task-ID: ODUHIGH-432]Fix to send correct RLC header and PDCP SN for RRC messages...
[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
710       ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
711       if(!mBuf)
712       {
713          DU_LOG("\nERROR  --> PHY_STUB: Failed to allocate memory for slot indication buffer");
714          MAC_FREE_SHRABL_BUF(pst.region, pst.pool, slotIndMsg, sizeof(fapi_slot_ind_t));
715          return RFAILED;
716       }
717       CMCHKPK(oduPackPointer, (PTR)slotIndMsg, mBuf);
718       ODU_POST_TASK(&pst, mBuf);
719    }
720 #endif
721    return ROK;
722 }
723
724 /*******************************************************************
725  *
726  * @brief Handles start request received from MAC
727  *
728  * @details
729  *
730  *    Function : l1HdlStartReq
731  *
732  *    Functionality:
733  *          -Handles start request received from MAC
734  *
735  * @params[in]   Message length
736  *               config request message pointer
737  *
738  * @return void
739  *
740  * ****************************************************************/
741
742 S16 l1HdlStartReq(uint32_t msgLen, void *msg)
743 {
744 #ifdef INTEL_FAPI
745    if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
746    {
747       l1HdlSlotIndicaion(FALSE);
748       l1StartConsoleHandler();
749       MAC_FREE(msg, msgLen);
750    }
751    else
752    {
753       DU_LOG("\nINFO   -->  PHY_STUB: Received Start Req in PHY State %d", lwrMacCb.phyState);
754       MAC_FREE(msg, msgLen);
755       return RFAILED;
756    }
757 #endif
758    return ROK;
759 }
760
761 /*******************************************************************
762  *
763  * @brief Handles Dl Tti request received from MAC
764  *
765  * @details
766  *
767  *    Function : l1HdlDlTtiReq
768  *
769  *    Functionality:
770  *          -Handles Dl Tti request received from MAC
771  *
772  * @params[in]   Message length
773  *               Dl Tti request message pointer
774  *
775  * @return void
776  *
777  * ****************************************************************/
778
779 S16 l1HdlDlTtiReq(uint16_t msgLen, void *msg)
780 {
781 #ifdef INTEL_FAPI
782    p_fapi_api_queue_elem_t dlTtiElem = (p_fapi_api_queue_elem_t)msg;
783    fapi_dl_tti_req_t *dlTtiReq = (fapi_dl_tti_req_t *)(dlTtiElem +1);
784    
785    uint8_t pduCount = 0;
786
787 #ifdef ODU_SLOT_IND_DEBUG_LOG
788    if(dlTtiReq->nPdus == 0)
789    {
790       DU_LOG("\nDEBUG  -->  PHY_STUB: No PDU in DL TTI Request");
791    }
792    else
793    {  
794      DU_LOG("\nDEBUG  -->  PHY STUB: DL TTI Request at sfn=%d slot=%d",dlTtiReq->sfn,dlTtiReq->slot);
795    }
796 #endif 
797
798    for(pduCount=0; pduCount<dlTtiReq->nPdus; pduCount++)
799    {
800       if(dlTtiReq->pdus[pduCount].pduType == 3) //SSB_PDU_TYPE
801       {
802          DU_LOG("\nINFO   -->  PHY_STUB: SSB PDU");
803       }
804       else if(dlTtiReq->pdus[pduCount].pduType == 0)
805       {
806          DU_LOG("\nINFO   -->  PHY_STUB: PDCCH PDU");
807       }
808       else if(dlTtiReq->pdus[pduCount].pduType == 1)
809       {
810          DU_LOG("\nINFO   -->  PHY_STUB: PDSCH PDU");
811       }
812    }
813
814    /* Free FAPI message */
815    MAC_FREE(msg, msgLen);
816 #endif
817    return ROK;
818 }
819
820 /*******************************************************************
821  *
822  * @brief Handles tx_data request received from MAC
823  *
824  * @details
825  *
826  *    Function : l1HdlTxDataReq
827  *
828  *    Functionality:
829  *          -Handles tx_data request received from MAC
830  *
831  * @params[in]   Message length
832  *               tx_data request message pointer
833  *
834  * @return void
835  *
836  * ****************************************************************/
837
838 S16 l1HdlTxDataReq(uint16_t msgLen, void *msg)
839 {
840 #ifdef INTEL_FAPI
841    p_fapi_api_queue_elem_t txDataElem = (p_fapi_api_queue_elem_t)msg;
842    fapi_tx_data_req_t *txDataReq = (fapi_tx_data_req_t *)(txDataElem +1);
843
844    DU_LOG("\nINFO   -->  PHY STUB: TX DATA Request at sfn=%d slot=%d",txDataReq->sfn,txDataReq->slot);
845 /*
846    if(dlDedMsg)
847    {
848       DU_LOG("\nINFO   -->  PHY_STUB: TxDataPdu for DED MSG sent");
849       dlDedMsg = false;
850    }
851 */
852    MAC_FREE(msg, msgLen);
853 #endif
854    return ROK;
855 }
856
857 #ifdef INTEL_FAPI
858 /*******************************************************************
859  *
860  * @brief Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
861  *
862  * @details
863  *
864  *    Function : fillPucchF0F1PduInfo
865  *
866  *    Functionality:
867  *       Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1 
868  *
869  * @params[in] fapi_uci_o_pucch_f0f1_t *
870  *             pucchPdu
871  * @return ROK     - success
872  *         RFAILED - failure
873  *
874  * ****************************************************************/
875 uint8_t fillPucchF0F1PduInfo(fapi_uci_o_pucch_f0f1_t *pduInfo, fapi_ul_pucch_pdu_t pucchPdu)
876 {
877    uint8_t idx = 0;
878
879    pduInfo->handle = pucchPdu.handle;
880    pduInfo->pduBitmap = 1;  //hardcoded for SR
881    pduInfo->pucchFormat = pucchPdu.formatType;
882    pduInfo->ul_cqi = 0;
883    pduInfo->rnti = pucchPdu.rnti;
884    pduInfo->timingAdvance = 0;
885    pduInfo->rssi = 0;
886    if(pduInfo->pduBitmap & SR_PDU_BITMASK)
887    {
888       pduInfo->srInfo.srIndication = SR_DETECTED;
889       pduInfo->srInfo.srConfidenceLevel = CONFDC_LEVEL_GOOD;
890    }
891    if(pduInfo->pduBitmap & HARQ_PDU_BITMASK)
892    {
893       pduInfo->harqInfo.numHarq++;
894       pduInfo->harqInfo.harqConfidenceLevel = CONFDC_LEVEL_GOOD;
895       for(idx = 0; idx < pduInfo->harqInfo.numHarq; idx++)
896       {
897          pduInfo->harqInfo.harqValue[idx] = HARQ_PASS;
898       }
899    }
900    return ROK;
901 }
902 /*******************************************************************
903  *
904  * @brief Fills UCI Pdu Information
905  *
906  * @details
907  *
908  *    Function : fillUciPduInfo
909  *
910  *    Functionality:
911  *       Fills UCI Pdu Information
912  *
913  * @params[in] Pointer to uciPdu
914  *             pucchPdu
915  * @return ROK     - success
916  *         RFAILED - failure
917  *
918  * ****************************************************************/
919 uint8_t fillUciPduInfo(fapi_uci_pdu_info_t *uciPdu, fapi_ul_pucch_pdu_t pucchPdu)
920 {
921    uint8_t ret = ROK;
922
923    /*TODO: The pduType is hardcoded here to support 
924      UCI Ind for PUCCH forat0/format1. This is to be
925      modified when we get SR form UE */
926    uciPdu->pduType = UCI_IND_PUCCH_F0F1;
927    switch(uciPdu->pduType)
928    {
929       case UCI_IND_PUSCH:
930          break;
931       case UCI_IND_PUCCH_F0F1:
932          {
933             fapi_uci_o_pucch_f0f1_t *pduInfo = NULLP;
934
935             pduInfo = &uciPdu->uci.uciPucchF0F1;
936             ret = fillPucchF0F1PduInfo(pduInfo, pucchPdu);
937             uciPdu->pduSize = sizeof(fapi_uci_o_pucch_f0f1_t);
938          }
939          break;
940       case UCI_IND_PUCCH_F2F3F4:
941          break;
942       default:
943          DU_LOG("\nERROR  -->  PHY_STUB: Invalid Pdu Type %d", uciPdu->pduType);
944          break;
945    }
946    return ret;
947 }
948
949 /*******************************************************************
950  *
951  * @brief Build and send Uci indication
952  *
953  * @details
954  *
955  *    Function : l1BuildAndSendUciInd
956  *
957  *    Functionality:
958  *       Build and send Uci indication
959  *
960  * @params[in] SFN
961  *             Slot
962  * @return ROK     - success
963  *         RFAILED - failure
964  *
965  * ****************************************************************/
966 uint8_t l1BuildAndSendUciInd(uint16_t slot, uint16_t sfn, fapi_ul_pucch_pdu_t pucchPdu)
967 {
968    uint8_t uciIdx = 0;
969    uint8_t nUciPdus = 0;
970    uint8_t ret = ROK;
971    uint32_t msgLen = 0;
972    fapi_uci_indication_t *uciInd =  NULLP;
973
974    MAC_ALLOC(uciInd, sizeof(fapi_uci_indication_t));
975    if(!uciInd)
976    {
977       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for UCI Indication");
978       return RFAILED;
979    }
980    memset(uciInd, 0, sizeof(fapi_uci_indication_t));
981    uciInd->sfn = sfn;
982    uciInd->slot = slot;
983    uciInd->numUcis = 1;   //consdering the UCI Ind for SR
984    nUciPdus = uciInd->numUcis;
985    while(nUciPdus)
986    {
987       ret = fillUciPduInfo(&uciInd->uciPdu[uciIdx], pucchPdu);
988       uciIdx++;
989       nUciPdus--;
990    }
991    if(ret == ROK)
992    {
993       msgLen = sizeof(fapi_uci_indication_t)- sizeof(fapi_msg_t);
994       fillMsgHeader(&uciInd->header, FAPI_UCI_INDICATION, msgLen);
995
996       /* Sending UCI indication to MAC */
997       DU_LOG("\nINFO   -->  PHY STUB: Sending UCI Indication to MAC");
998       procPhyMessages(uciInd->header.msg_id, sizeof(fapi_uci_indication_t), (void *)uciInd);
999    }
1000    MAC_FREE(uciInd, sizeof(fapi_uci_indication_t));
1001    return ret;
1002 }
1003 #endif
1004
1005 /*******************************************************************
1006  *
1007  * @brief Handles Ul Tti request received from MAC
1008  *
1009  * @details
1010  *
1011  *    Function : l1HdlUlTtiReq
1012  *
1013  *    Functionality:
1014  *          -Handles Ul Tti request received from MAC
1015  *
1016  * @params[in]   Message length
1017  *               Ul Tti request message pointer
1018  *
1019  * @return void
1020  *
1021  * ****************************************************************/
1022
1023 S16 l1HdlUlTtiReq(uint16_t msgLen, void *msg)
1024 {
1025 #ifdef INTEL_FAPI
1026    p_fapi_api_queue_elem_t ulTtiElem = (p_fapi_api_queue_elem_t)msg;
1027    fapi_ul_tti_req_t *ulTtiReq = (fapi_ul_tti_req_t *)(ulTtiElem +1);
1028    uint8_t numPdus = ulTtiReq->nPdus;
1029
1030 #ifdef ODU_SLOT_IND_DEBUG_LOG
1031    if(numPdus == 0)
1032    {
1033       DU_LOG("\nINFO   -->  PHY STUB: No PDU received in UL TTI Req");
1034    }
1035    else
1036    {
1037       DU_LOG("\nINFO   -->  PHY STUB: Received UL TTI Request");
1038    }
1039 #endif 
1040
1041    while(numPdus)
1042    {
1043       if(ulTtiReq->pdus[numPdus-1].pduType == 0)
1044       {
1045          DU_LOG("\nINFO   -->  PHY STUB: PRACH PDU");
1046       }
1047       if(ulTtiReq->pdus[numPdus-1].pduType == 1)
1048       {
1049          DU_LOG("\nINFO   -->  PHY STUB: PUSCH PDU");
1050          l1BuildAndSendRxDataInd(ulTtiReq->slot, ulTtiReq->sfn, \
1051                ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu); 
1052       }
1053       if(ulTtiReq->pdus[numPdus-1].pduType == 2)
1054       {
1055          DU_LOG("\nINFO   -->  PHY STUB: PUCCH PDU");
1056          fapi_ul_tti_req_t ulTtiSlotInd;
1057          memset(&ulTtiSlotInd, 0, sizeof(fapi_ul_tti_req_t));
1058          ulTtiSlotInd.slot = ulTtiReq->slot;
1059          ulTtiSlotInd.sfn  = ulTtiReq->sfn;
1060          ADD_DELTA_TO_TIME(ulTtiSlotInd, ulTtiSlotInd, SLOT_DELAY);
1061          l1BuildAndSendUciInd(ulTtiSlotInd.slot, ulTtiSlotInd.sfn, \
1062                ulTtiReq->pdus[numPdus-1].pdu.pucch_pdu);
1063       }
1064       numPdus--;
1065    }
1066
1067    /* TODO: [SFN:SLOT] at which RACH Indication is sent should be calculated
1068     * based on PRACH cfg index */
1069    /* Send RACH Ind to L2 for first UE */
1070    if(ueDb.ueCb[UE_IDX_0].rachIndSent == false && ulTtiReq->sfn == 16 && ulTtiReq->slot == 6)
1071    {
1072       ueDb.ueCb[UE_IDX_0].rachIndSent = true;
1073       l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn);
1074       ueDb.numActvUe++;
1075    }
1076 #if 0
1077    /* Send RACH Ind to L2 for second UE */
1078    if(ueDb.ueCb[UE_IDX_1].rachIndSent == false && ulTtiReq->sfn == 304 && ulTtiReq->slot == 0)
1079    {
1080       ueDb.ueCb[UE_IDX_1].rachIndSent = true;
1081       l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn);
1082       ueDb.numActvUe++;
1083    }
1084
1085    /* Send RACH Ind to L2 for third UE */
1086    if(ueDb.ueCb[UE_IDX_2].rachIndSent == false && ulTtiReq->sfn == 526 && ulTtiReq->slot == 0)
1087    {
1088       ueDb.ueCb[UE_IDX_2].rachIndSent = true;
1089       l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn);
1090       ueDb.numActvUe++;
1091    }
1092 #endif
1093    MAC_FREE(msg, msgLen);
1094 #endif
1095    return ROK;
1096 }
1097
1098 /*******************************************************************
1099  *
1100  * @brief Builds and Send the stop Indication message to MAC
1101  *
1102  * @details
1103  *
1104  *    Function : l1BuildAndSendStopInd
1105  *
1106  *    Functionality:
1107  *          -Send the Stop indication Message to MAC
1108  *
1109  *
1110  * @return void
1111  *
1112  * ****************************************************************/
1113 uint16_t l1BuildAndSendStopInd()
1114 {
1115 #ifdef INTEL_FAPI
1116    Pst pst;
1117    Buffer *mBuf = NULLP;
1118    fapi_stop_ind_t *stopIndMsg = NULLP;
1119    uint32_t msgLen = 0;
1120
1121    MAC_ALLOC_SHRABL_BUF(stopIndMsg, sizeof(fapi_stop_ind_t));
1122    if(!stopIndMsg)
1123    {
1124       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for stop Indication Message");
1125       return RFAILED;
1126    }
1127    else
1128    {
1129       fillMsgHeader(&stopIndMsg->header, FAPI_STOP_INDICATION, msgLen);
1130       DU_LOG("\n\nINFO   -->  PHY_STUB: Processing Stop indication to MAC");
1131
1132       memset(&pst, 0, sizeof(Pst));
1133       FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_STOP_IND);
1134       ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
1135       if(!mBuf)
1136       {
1137          DU_LOG("\nERROR  --> PHY_STUB: Failed to allocate memory for slot indication buffer");
1138          MAC_FREE_SHRABL_BUF(pst.region, pst.pool, stopIndMsg, sizeof(fapi_stop_ind_t));
1139          return RFAILED;
1140       }
1141       CMCHKPK(oduPackPointer, (PTR)stopIndMsg, mBuf);
1142       ODU_POST_TASK(&pst, mBuf);
1143    }
1144 #endif
1145    return ROK;
1146 }
1147
1148 /*******************************************************************
1149  *
1150  * @brief Handles stop request received from MAC
1151  *
1152  * @details
1153  *
1154  *    Function : l1HdlStopReq
1155  *
1156  *    Functionality:
1157  *          -Handles stop request received from MAC
1158  *
1159  * @params[in]   Message length
1160  *               stop request message pointer
1161  *
1162  * @return void
1163  *
1164  * ****************************************************************/
1165
1166 S16 l1HdlStopReq(uint32_t msgLen, void *msg)
1167 {
1168 #ifdef INTEL_FAPI
1169    if(lwrMacCb.phyState == PHY_STATE_RUNNING)
1170    {
1171       l1HdlSlotIndicaion(TRUE);
1172
1173       /* Initialize all global variables */
1174       sfnValue = 0;
1175       slotValue = 0;
1176       memset(&ueDb, 0, sizeof(UeDb));
1177
1178       DU_LOG("\nINFO   -->  PHY_STUB: Slot Indication is stopped successfully");
1179       MAC_FREE(msg, msgLen);
1180    }
1181    else
1182    {
1183       DU_LOG("\nINFO  -->  PHY_STUB: Received Stop Req in PHY State %d", lwrMacCb.phyState);
1184       MAC_FREE(msg, msgLen);
1185       return RFAILED;
1186    }
1187 #endif
1188    return ROK;
1189 }
1190
1191 #if 0
1192 /*******************************************************************
1193  *
1194  * @brief Build And Send Rx Data Ind for Msg5
1195  *
1196  * @details
1197  *
1198  *    Function : l1BuildAndSendMsg5
1199  *
1200  *    Functionality: Build And Send Rx Data Ind for Msg5
1201  *
1202  * @params[in] SFN
1203  *             Slot
1204  * @return ROK     - success
1205  *         RFAILED - failure
1206  *
1207  * ****************************************************************/
1208 uint8_t l1BuildAndSendMsg5(uint16_t sfn, uint16_t slot)
1209 {   
1210 #ifdef INTEL_FAPI
1211    uint8_t idx = 0;
1212    fapi_rx_data_indication_t *rxDataInd;
1213    fapi_pdu_ind_info_t       *pduInfo;
1214    uint8_t  *pdu;
1215    uint16_t byteIdx = 0;
1216    uint32_t msgLen = 0;
1217
1218    MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1219    if(!rxDataInd)
1220    {
1221       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Indication for msg5");
1222       return RFAILED;
1223    }
1224    memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1225
1226    /* TODO: Fill the required values */
1227    msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1228    rxDataInd->sfn = sfn;
1229    rxDataInd->slot = slot;
1230    rxDataInd->numPdus = 1;
1231
1232    pduInfo = &rxDataInd->pdus[idx];
1233    pduInfo->handle = 100;
1234    pduInfo->rnti = 100;
1235    pduInfo->harqId = 1;
1236    pduInfo->pdu_length = 25;
1237    pduInfo->ul_cqi = 0;
1238    pduInfo->timingAdvance = 0;
1239    pduInfo->rssi = 0;
1240
1241    /* Filling pdu with random values for testing */
1242    pduInfo->pduData = NULL;
1243    MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1244    if(!pduInfo->pduData)
1245    {
1246       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Pdu");
1247       return RFAILED;
1248    }
1249
1250    /* Filling PDU */
1251    pdu = (uint8_t *)pduInfo->pduData;
1252
1253    uint8_t  msg5PduLen = 33;
1254    /* For RRC setup complete
1255       MAC subheader format is R/F/LCId/L (2/3 bytes)
1256       LCId is 1 for SRB1
1257       L is length of PDU i.e 6bytes here
1258       From 38.321 section 6.1.1
1259     */
1260    uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
1261       64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
1262          184, 56, 0, 0, 0, 0, 0};
1263
1264    msg5PduLen += 2;  /* 2bytes of header */
1265    memcpy(pdu, &msg5, msg5PduLen);
1266    byteIdx += msg5PduLen; /* 2 bytes of header */
1267
1268    /* Filling MAC SDU for Padding bytes*/
1269    if(byteIdx < pduInfo->pdu_length)
1270    {
1271       /* For Padding
1272          MAC subheader format is R/R/LCId (1byte)
1273          LCId is 63 for padding
1274          From 38.321 section 6.1.1
1275        */
1276       pdu[byteIdx++] = 63;
1277
1278       for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1279          pdu[byteIdx] = 0;
1280    }
1281    msgLen += pduInfo->pdu_length;
1282
1283    fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1284
1285    /* Sending Rx data indication to MAC */
1286    DU_LOG("\nINFO   -->  PHY STUB: Sending Rx data Indication to MAC");
1287    procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1288
1289    if(pduInfo->pdu_length)
1290       MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1291    MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1292 #endif
1293    return ROK;
1294 }
1295 #endif
1296
1297 /*******************************************************************
1298  *
1299  * @brief Handles Ul Dci request received from MAC
1300  *
1301  * @details
1302  *
1303  *    Function : l1HdlUlDciReq
1304  *
1305  *    Functionality:
1306  *          -Handles Ul Dci request received from MAC
1307  *
1308  * @params[in]   Message length
1309  *               Ul Dci request message pointer
1310  *
1311  * @return void
1312  *
1313  * ****************************************************************/
1314
1315 S16 l1HdlUlDciReq(uint16_t msgLen, void *msg)
1316 {
1317 #ifdef INTEL_FAPI
1318    p_fapi_api_queue_elem_t ulDciElem = (p_fapi_api_queue_elem_t)msg;
1319    fapi_ul_dci_req_t *ulDciReq = (fapi_ul_dci_req_t *)(ulDciElem +1);
1320    uint8_t numPdus = ulDciReq->numPdus;
1321
1322    while(numPdus)
1323    {
1324       if(ulDciReq->pdus[numPdus-1].pduType == 0)
1325       {
1326          DU_LOG("\nINFO   -->  PHY STUB: Received UL DCI Request for PDCCH PDU");
1327          //l1BuildAndSendMsg5(ulDciReq->sfn, ulDciReq->slot);
1328          //msg5Sent = true;
1329       }
1330       numPdus--;
1331    }
1332
1333    MAC_FREE(msg, msgLen);
1334 #endif
1335    return ROK;
1336 }
1337
1338 /*******************************************************************
1339  *
1340  * @brief Send UL user data to DU
1341  *
1342  * @details
1343  *
1344  *    Function : l1SendUlUserData
1345  *
1346  *    Functionality: Send UL user data to DU
1347  *
1348  * @params[in]
1349  * @return ROK     - success
1350  *         RFAILED - failure
1351  *
1352  * ****************************************************************/
1353 uint8_t l1SendUlUserData(uint8_t drbId, uint8_t ueIdx)
1354 {
1355    uint8_t cnt = 0;
1356    fapi_rx_data_indication_t *rxDataInd;
1357    fapi_pdu_ind_info_t       *pduInfo;
1358    uint8_t  *pdu = NULLP;
1359    uint16_t byteIdx = 0;
1360    uint32_t msgLen = 0;
1361    uint8_t idx = 0;
1362    uint8_t lcId = 0;
1363
1364    MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1365    if(!rxDataInd)
1366    {
1367       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Indication");
1368       return RFAILED;
1369    }
1370    memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1371
1372    msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1373    rxDataInd->sfn = 0;
1374    rxDataInd->slot = 0;
1375    rxDataInd->numPdus = 1;
1376
1377    /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1378    pduInfo = &rxDataInd->pdus[idx];
1379    pduInfo->handle = ueIdx + ODU_START_CRNTI;
1380    pduInfo->rnti = ueIdx + ODU_START_CRNTI;
1381    pduInfo->harqId = 1;
1382    /* Since user data size = 50bytes and 2 bytes of MAC header and 3 byte of RLC header, 
1383     * setting tbsize = 56 from Table 5.1.3.2-1 spec 38.214 */
1384    pduInfo->pdu_length = 56;
1385    pduInfo->ul_cqi = 0;
1386    pduInfo->timingAdvance = 0;
1387    pduInfo->rssi = 0;
1388
1389    /* Filling pdu with random values for testing */
1390    pduInfo->pduData = NULL;
1391    MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1392    if(!pduInfo->pduData)
1393    {
1394       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Pdu");
1395       return RFAILED;
1396    }
1397
1398    /* Filling PDU */
1399    pdu = (uint8_t *)pduInfo->pduData;
1400    msgLen = 52;
1401
1402    /* For UL User data
1403       MAC subheader format is R/F/LCId/L (2/3 bytes)
1404       LCId is 4 for DRB1
1405       L is length of PDU i.e 50 bytes
1406       From 38.321 section 6.1.1
1407       From 38.322 section 6.2.2.4, 6.2.2.3 for AM, UM Header
1408     */
1409
1410     /* Below ulMsg supports 12bit SN for UM mode */
1411                                /*  SI  SN */
1412     lcId = MIN_DRB_LCID + drbId;
1413     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,
1414     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};
1415     msgLen += 2;  /* 2bytes of header */
1416     memcpy(pdu, &ulMsg, msgLen);
1417     byteIdx += msgLen; /* 2 bytes of header */
1418
1419    /* Filling MAC SDU for Padding bytes*/
1420    if(byteIdx < pduInfo->pdu_length)
1421    {
1422       /* For Padding
1423          MAC subheader format is R/R/LCId (1byte)
1424          LCId is 63 for padding
1425          From 38.321 section 6.1.1
1426        */
1427       pdu[byteIdx++] = 63;
1428
1429       for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1430          pdu[byteIdx] = 0;
1431    }
1432    msgLen += pduInfo->pdu_length;
1433
1434    fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1435
1436     /* Send Message to peer */
1437     while(cnt < NUM_UL_PACKETS)
1438     {
1439        DU_LOG("\nDEBUG  -->  PHY STUB : Sending UL User Data[%d][LCID:%d] at sfn %d slot %d", cnt+1, lcId, sfnValue, slotValue);
1440        /* Sending Rx data indication to MAC */
1441        rxDataInd->sfn = sfnValue;
1442        rxDataInd->slot = slotValue;
1443        procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1444        cnt++;
1445     }
1446
1447     if(pduInfo->pdu_length)
1448        MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1449     MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1450     return ROK;
1451 }
1452
1453 /*******************************************************************
1454  *
1455  * @brief Sends RLC Status PDU to DU
1456  *
1457  * @details
1458  *
1459  *    Function : l1SendStatusPdu
1460  *
1461  *    Functionality: Send RLC Status PDU to DU
1462  *
1463  * @params[in]
1464  * @return ROK     - success
1465  *         RFAILED - failure
1466  *
1467  * ****************************************************************/
1468 uint8_t l1SendStatusPdu()
1469 {
1470    fapi_rx_data_indication_t *rxDataInd;
1471    fapi_pdu_ind_info_t       *pduInfo;
1472    uint8_t  *pdu = NULLP;
1473    uint16_t byteIdx = 0;
1474    uint32_t msgLen = 0;
1475    uint8_t idx = 0;
1476
1477    MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1478    if(!rxDataInd)
1479    {
1480       printf("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Indication");
1481       return RFAILED;
1482    }
1483    memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1484
1485    msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1486    rxDataInd->sfn = 0;
1487    rxDataInd->slot = 0;
1488    rxDataInd->numPdus = 1;
1489
1490    /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1491    pduInfo = &rxDataInd->pdus[idx];
1492    pduInfo->handle = 100;
1493    pduInfo->rnti = 100;
1494    pduInfo->harqId = 1;
1495    /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1496     * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1497    pduInfo->pdu_length = 24;
1498    pduInfo->ul_cqi = 0;
1499    pduInfo->timingAdvance = 0;
1500    pduInfo->rssi = 0;
1501
1502    /* Filling pdu with random values for testing */
1503    pduInfo->pduData = NULL;
1504    MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1505    if(!pduInfo->pduData)
1506    {
1507       printf("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Pdu");
1508       return RFAILED;
1509    }
1510
1511    /* Filling PDU */
1512    pdu = (uint8_t *)pduInfo->pduData;
1513    msgLen = 3;
1514
1515    /* For RLC Status PDU
1516     * MAC subheader format is R/F/LCId/L (2/3 bytes)
1517     * LCId is 4 for DRB1
1518     * L is length of Status PDU i.e 3 bytes
1519     * From 38.321 section 6.1.1
1520     *
1521     * RLC Status PDU format :
1522     * ---------------------------------
1523     * |D/C|CPT|    ACK_SN             |
1524     * ---------------------------------
1525     * |            ACK_SN             |
1526     * ---------------------------------
1527     * |E1 | R | R | R | R | R | R | R |
1528     * ---------------------------------
1529     *  
1530     * Here, D/C bit = 0 for Control PDU
1531     * CPT bit = 0 since control pdu type is Status PDU
1532     * ACK_SN = 0 as of now, this can be changed based on the 
1533     * scenario being tested
1534     * E1 = 0 because no NACK_SN, E1, E2 and E3 follows it
1535     * R = 0 i.e. reserved bits
1536     * From Spec 38.322 section 6.2.2.5
1537     */
1538    uint8_t statusPdu[] = {4, msgLen, 0, 0, 0};
1539    msgLen += 2;  /* 2bytes of header */
1540    memcpy(pdu, &statusPdu, msgLen);
1541    byteIdx += msgLen; /* 2 bytes of header */
1542
1543
1544    /* Filling MAC SDU for Padding bytes*/
1545    if(byteIdx < pduInfo->pdu_length)
1546    {
1547       /* For Padding
1548          MAC subheader format is R/R/LCId (1byte)
1549          LCId is 63 for padding
1550          From 38.321 section 6.1.1
1551        */
1552       pdu[byteIdx++] = 63;
1553
1554       for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1555          pdu[byteIdx] = 0;
1556    }
1557    msgLen += pduInfo->pdu_length;
1558
1559    fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1560
1561     /* Send Message to peer */
1562     DU_LOG("\nDEBUG  -->  PHY STUB : Sending RLC status pdu at sfn %d slot %d", sfnValue, slotValue);
1563     /* Sending Rx data indication to MAC */
1564     rxDataInd->sfn = sfnValue;
1565     rxDataInd->slot = slotValue;
1566     procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1567
1568     if(pduInfo->pdu_length)
1569        MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1570     MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1571     return ROK;
1572 }
1573
1574 /*******************************************************************
1575  *
1576  * @brief Receives message from MAC
1577  *
1578  * @details
1579  *
1580  *    Function :  l1ProcessFapiRequest
1581  *
1582  *    Functionality:
1583  *       - Receives message from MAC and calls handler
1584  *
1585  * @params[in] Message type
1586  *             Message length
1587  *             Message pointer
1588  *
1589  * @return void
1590  *
1591  * ****************************************************************/
1592
1593 void l1ProcessFapiRequest(uint8_t msgType, uint32_t msgLen, void *msg)
1594 {
1595    switch(msgType)
1596    {
1597 #ifdef INTEL_FAPI
1598       case FAPI_PARAM_REQUEST:
1599          l1HdlParamReq(msgLen, msg);
1600          break;
1601       case FAPI_CONFIG_REQUEST:
1602          l1HdlConfigReq(msgLen, msg);
1603          break;
1604       case FAPI_START_REQUEST:
1605          l1HdlStartReq(msgLen, msg);
1606          break;
1607       case FAPI_DL_TTI_REQUEST:
1608          l1HdlDlTtiReq(msgLen, msg);
1609          break;
1610       case FAPI_TX_DATA_REQUEST:
1611          l1HdlTxDataReq(msgLen, msg);
1612          break;
1613       case FAPI_UL_TTI_REQUEST:
1614          l1HdlUlTtiReq(msgLen, msg);
1615          break;
1616       case FAPI_STOP_REQUEST:
1617          l1HdlStopReq(msgLen, msg);
1618          break;
1619       case FAPI_UL_DCI_REQUEST:
1620          l1HdlUlDciReq(msgLen, msg);
1621          break;
1622       default:
1623          DU_LOG("\nERROR  -->  PHY_STUB: Invalid message type[%x] received at PHY", msgType);
1624          break;
1625 #endif
1626    }
1627 }
1628
1629 #ifdef INTEL_FAPI
1630 /*******************************************************************
1631  *
1632  * @brief Builds and Send the BSR message to MAC
1633  *
1634  * @details
1635  *
1636  *    Function : l1BuildAndSendBSR
1637  *
1638  *   Functionality:
1639  *          -Send the BSR Message to MAC
1640  *
1641  * @params[in]  BSR type 
1642  *              array of LCGID and BSIdx
1643  * @return void
1644  *
1645  *****************************************************************/
1646 uint16_t l1BuildAndSendBSR(uint8_t ueIdx, BsrType bsrType,\
1647              LcgBufferSize lcgBsIdx[MAX_NUM_LOGICAL_CHANNEL_GROUPS])
1648 {
1649    fapi_rx_data_indication_t *rxDataInd;
1650    fapi_pdu_ind_info_t       *pduInfo;
1651    uint8_t  *pdu = NULLP;
1652    uint16_t byteIdx = 0;
1653    uint32_t msgLen = 0;
1654    uint8_t pduIdx = 0, lcgIdx = 0, lcgIdxPos = 0;
1655
1656    MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1657    if(!rxDataInd)
1658    {
1659       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Indication");
1660       return RFAILED;
1661    }
1662    memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1663
1664    msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1665    rxDataInd->sfn = 0;
1666    rxDataInd->slot = 0;
1667    rxDataInd->numPdus = 1;
1668
1669    pduInfo = &rxDataInd->pdus[pduIdx];
1670    pduInfo->handle = (ODU_START_CRNTI + ueIdx);
1671    pduInfo->rnti = (ODU_START_CRNTI + ueIdx);
1672    pduInfo->harqId = 1;
1673
1674    /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1675     * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1676    pduInfo->pdu_length = 24;
1677    pduInfo->ul_cqi = 0;
1678    pduInfo->timingAdvance = 0;
1679    pduInfo->rssi = 0;
1680
1681    /* Filling pdu with random values for testing */
1682    pduInfo->pduData = NULL;
1683    MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1684    if(!pduInfo->pduData)
1685    {
1686       DU_LOG("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Pdu");
1687       MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1688       return RFAILED;
1689    }
1690
1691    /* Filling PDU */
1692    pdu = (uint8_t *)pduInfo->pduData;
1693
1694    switch(bsrType)
1695    {
1696       case SHORT_BSR:
1697          {
1698             DU_LOG("\nDEBUG  -->  PHY_STUB: Forming SHORT BSR PDU ");
1699
1700             /* For Short BSR
1701              * MAC subheader format is R/R/LcId (1Byte)
1702              * LCId is 61
1703              * From 38.321 section 6.1.1
1704              */
1705             pdu[byteIdx++] = 61;    // LCID
1706             pdu[byteIdx++] = (lcgBsIdx[0].lcgId << 5) | lcgBsIdx[0].bsIdx;
1707             break;
1708          }
1709
1710       case LONG_BSR:
1711          {
1712             DU_LOG("\nDEBUG  -->  PHY_STUB: Forming LONG BSR PDU ");
1713
1714             /* For Long BSR
1715              * MAC subheader format is R/R/LcId (1Byte)
1716              * LCId is 62
1717              * From 38.321 section 6.1.1
1718              */
1719             pdu[byteIdx++] = 62;    // LCID
1720
1721             /*Octet where lcgId bitmap will be present*/
1722             lcgIdxPos = byteIdx;
1723             byteIdx++;
1724             for(lcgIdx = 0; lcgIdx < MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
1725             {
1726                if(lcgBsIdx[lcgIdx].bsIdx > 0)
1727                {
1728                   pdu[lcgIdxPos] |= 1 << lcgBsIdx[lcgIdx].lcgId;
1729                   pdu[byteIdx++] = lcgBsIdx[lcgIdx].bsIdx;
1730                }
1731             }
1732
1733             break;
1734          }
1735
1736       default:
1737          {
1738             DU_LOG("\nERROR  -->  PHY_STUB: Incorrect BSR type:%d!", bsrType);
1739             if(pduInfo->pdu_length)
1740                MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1741             MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1742             return RFAILED;
1743          }
1744    }
1745    /* Filling MAC SDU for Padding bytes*/
1746    if(byteIdx < pduInfo->pdu_length)
1747    {
1748       /* For Padding
1749        * MAC subheader format is R/R/LCId (1byte)
1750        * LCId is 63 for padding
1751        * From 38.321 section 6.1.1
1752        */
1753       pdu[byteIdx++] = 63;
1754
1755       for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1756          pdu[byteIdx] = 0;
1757    }
1758    msgLen += pduInfo->pdu_length;
1759    fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1760
1761    /* Sending Rx data indication to MAC */
1762    DU_LOG("\nINFO   -->  PHY STUB: Sending Rx data Indication to MAC");
1763    procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1764
1765    if(pduInfo->pdu_length)
1766       MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1767    MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1768    return ROK;
1769 }
1770 #endif
1771
1772 /**********************************************************************
1773   End of file
1774  **********************************************************************/