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