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