RLC BO, BO response and DL Data handling. [Issue-ID: ODUHIGH-181]
[o-du/l2.git] / src / phy_stub / l1_bdy1.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_phy.h"
28 #ifdef INTEL_FAPI
29 #include "fapi.h"
30 #endif
31 #include "lphy_stub.h"
32 #include "lwr_mac_upr_inf.h"
33 #include "mac_utils.h"
34 #include "l1.h"
35
36 /*******************************************************************
37  *
38  * @brief Builds and sends param response to MAC CL
39  *
40  * @details
41  *
42  *    Function : l1BldAndSndParamRsp
43  *
44  *    Functionality:
45  *          - Builds and sends param response to MAC
46  *
47  * @params[in] Config request message pointer
48  * @return ROK     - success
49  *         RFAILED - failure
50  *
51  * ****************************************************************/
52 S16 l1BldAndSndParamRsp(void *msg)
53 {
54 #ifdef INTEL_FAPI
55    uint8_t index = 0;
56    uint32_t msgLen = 0;
57    fapi_param_resp_t *fapiParamRsp;
58
59    MAC_ALLOC(fapiParamRsp, sizeof(fapi_param_resp_t));
60    if(!fapiParamRsp)
61    {
62       DU_LOG("PHY STUB: Memory allocation failed");
63       return RFAILED;
64    }
65
66    /* Cell Params */
67    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_RELEASE_CAPABILITY_TAG,                         sizeof(uint16_t), 1, &msgLen);
68    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PHY_STATE_TAG,                                  sizeof(uint16_t), 0, &msgLen);
69    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SKIP_BLANK_DL_CONFIG_TAG,                       sizeof(uint8_t),  0, &msgLen);
70    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SKIP_BLANK_UL_CONFIG_TAG,                       sizeof(uint8_t),  0, &msgLen);
71    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_NUM_CONFIG_TLVS_TO_REPORT_TYPE_TAG,              sizeof(uint8_t),  0, &msgLen);
72
73    /* Carrier Params */
74    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_CYCLIC_PREFIX_TAG,                               sizeof(uint8_t),  1, &msgLen);
75    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_SUBCARRIER_SPACING_DL_TAG,            sizeof(uint8_t),  1, &msgLen);
76    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_BANDWIDTH_DL_TAG,                     sizeof(uint16_t), 1, &msgLen);
77    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_SUBCARRIER_SPACING_UL_TAG,            sizeof(uint8_t),  0, &msgLen);
78    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_BANDWIDTH_UL_TAG,                     sizeof(uint16_t), 0, &msgLen);
79
80    /* PDCCH Param*/
81    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_CCE_MAPPING_TYPE_TAG,                                   sizeof(uint8_t), 0, &msgLen);
82    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_CORESET_OUTSIDE_FIRST_3_OFDM_SYMS_OF_SLOT_TAG,   sizeof(uint8_t), 0, &msgLen);
83    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PRECODER_GRANULARITY_CORESET_TAG,               sizeof(uint8_t), 0, &msgLen);
84    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDCCH_MU_MIMO_TAG,                              sizeof(uint8_t), 0, &msgLen);
85    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDCCH_PRECODER_CYCLING_TAG,                     sizeof(uint8_t), 0, &msgLen);
86    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_PDCCHS_PER_SLOT_TAG,                                sizeof(uint8_t), 0, &msgLen);
87
88    /* PUCCH Param */
89    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUCCH_FORMATS_TAG,                              sizeof(uint8_t), 0, &msgLen);
90    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_PUCCHS_PER_SLOT_TAG,                         sizeof(uint8_t), 0, &msgLen);
91
92    /* PDSCH Param */
93    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_MAPPING_TYPE_TAG,                         sizeof(uint8_t), 0, &msgLen);
94    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_ALLOCATION_TYPES_TAG,                      sizeof(uint8_t), 0, &msgLen);
95    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_VRB_TO_PRB_MAPPING_TAG,                   sizeof(uint8_t), 0, &msgLen);
96    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_CBG_TAG,                                  sizeof(uint8_t), 0, &msgLen);
97    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_DMRS_CONFIG_TYPES_TAG,                    sizeof(uint8_t), 0, &msgLen);
98    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_DMRS_MAX_LENGTH_TAG,                      sizeof(uint8_t), 0, &msgLen);
99    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_DMRS_ADDITIONAL_POS_TAG,                  sizeof(uint8_t), 0, &msgLen);
100    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_PDSCHS_TBS_PER_SLOT_TAG,                    sizeof(uint8_t), 0, &msgLen);
101    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_NUMBER_MIMO_LAYERS_PDSCH_TAG,               sizeof(uint8_t), 0, &msgLen);
102    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_MAX_MODULATION_ORDER_DL_TAG,          sizeof(uint8_t), 0, &msgLen);
103    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_MU_MIMO_USERS_DL_TAG,                       sizeof(uint8_t), 0, &msgLen);
104    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_DATA_IN_DMRS_SYMBOLS_TAG,                 sizeof(uint8_t), 0, &msgLen);
105    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PREMPTIONSUPPORT_TAG,                           sizeof(uint8_t), 0, &msgLen);
106    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_NON_SLOT_SUPPORT_TAG,                      sizeof(uint8_t), 0, &msgLen);
107
108    /* PUSCH Param */
109    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_UCI_MUX_ULSCH_IN_PUSCH_TAG,                     sizeof(uint8_t), 0, &msgLen);
110    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_UCI_ONLY_PUSCH_TAG,                             sizeof(uint8_t), 0, &msgLen);
111    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_FREQUENCY_HOPPING_TAG,                    sizeof(uint8_t), 0, &msgLen);
112    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_DMRS_CONFIG_TYPES_TAG,                    sizeof(uint8_t), 0, &msgLen);
113    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_DMRS_MAX_LEN_TAG,                         sizeof(uint8_t), 0, &msgLen);
114    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_DMRS_ADDITIONAL_POS_TAG,                  sizeof(uint8_t), 0, &msgLen);
115    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_CBG_TAG,                                  sizeof(uint8_t), 0, &msgLen);
116    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_MAPPING_TYPE_TAG,                          sizeof(uint8_t), 0, &msgLen);
117    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_ALLOCATION_TYPES_TAG,                     sizeof(uint8_t), 0, &msgLen);
118    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_VRB_TO_PRB_MAPPING_TAG,                   sizeof(uint8_t), 0, &msgLen);
119    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_MAX_PTRS_PORTS_TAG,                        sizeof(uint8_t), 0, &msgLen);
120    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_PDUSCHS_TBS_PER_SLOT_TAG,                   sizeof(uint8_t), 0, &msgLen);
121    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_NUMBER_MIMO_LAYERS_NON_CB_PUSCH_TAG,         sizeof(uint8_t), 0, &msgLen);
122    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_MODULATION_ORDER_UL_TAG,               sizeof(uint8_t), 0, &msgLen);
123    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_MU_MIMO_USERS_UL_TAG,                        sizeof(uint8_t), 0, &msgLen);
124    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_DFTS_OFDM_SUPPORT_TAG,                           sizeof(uint8_t), 0, &msgLen);
125    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_AGGREGATION_FACTOR_TAG,                    sizeof(uint8_t), 0, &msgLen);
126
127    /* PRACH Params */
128    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PRACH_LONG_FORMATS_TAG,                         sizeof(uint8_t), 0, &msgLen);
129    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PRACH_SHORT_FORMATS_TAG,                         sizeof(uint8_t), 0, &msgLen);
130    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PRACH_RESTRICTED_SETS_TAG,                       sizeof(uint8_t), 0, &msgLen);
131    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_PRACH_FD_OCCASIONS_IN_A_SLOT_TAG,            sizeof(uint8_t), 0, &msgLen);
132
133    /* MEASUREMENT TAG */
134    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_RSSI_MEASUREMENT_SUPPORT_TAG,                    sizeof(uint8_t), 0, &msgLen);
135
136    fapiParamRsp->number_of_tlvs = index;
137    msgLen += sizeof(fapi_param_resp_t) - sizeof(fapi_msg_t);
138    fillMsgHeader(&fapiParamRsp->header, FAPI_PARAM_RESPONSE, msgLen);
139    fapiParamRsp->error_code = MSG_OK;
140
141    DU_LOG("\nPHY_STUB: Sending Param Request to Lower Mac");
142    procPhyMessages(fapiParamRsp->header.msg_id, sizeof(fapi_param_resp_t), (void *)fapiParamRsp);
143    MAC_FREE(fapiParamRsp, sizeof(fapi_param_resp_t));
144 #endif
145    return ROK;
146 }
147
148 /*******************************************************************
149  *
150  * @brief Builds and sends config response to lower mac
151  *
152  * @details
153  *
154  *    Function : l1BldAndSndConfigRsp
155  *
156  *    Functionality:
157  *          - Builds and sends config response to MAC
158  *
159  * @params[in] Config request message pointer
160  * @return ROK     - success
161  *         RFAILED - failure
162  *
163  * ****************************************************************/
164
165 S16 l1BldAndSndConfigRsp(void *msg)
166 {
167 #ifdef INTEL_FAPI
168    uint32_t msgLen = 0;
169    fapi_config_resp_t *fapiConfigRsp;
170
171    MAC_ALLOC(fapiConfigRsp, sizeof(fapi_config_resp_t));
172    if(!fapiConfigRsp)
173    {
174       DU_LOG("PHY STUB: Memory allocation failed");
175       return RFAILED;
176    }
177    memset(fapiConfigRsp, 0, sizeof(fapi_config_resp_t));
178    fapiConfigRsp->number_of_invalid_tlvs = NULLP;
179    fapiConfigRsp->number_of_inv_tlvs_idle_only = NULLP;
180    fapiConfigRsp->number_of_missing_tlvs = NULLP;
181    fapiConfigRsp->error_code = MSG_OK;
182    msgLen = sizeof(fapi_config_resp_t) - sizeof(fapi_msg_t);
183    fillMsgHeader(&fapiConfigRsp->header, FAPI_CONFIG_RESPONSE, msgLen);
184
185    DU_LOG("\nPHY_STUB: Sending Config Response to Lower Mac");
186    procPhyMessages(fapiConfigRsp->header.msg_id, \
187          sizeof(fapi_config_resp_t), (void *)fapiConfigRsp);
188    MAC_FREE(fapiConfigRsp, sizeof(fapi_config_resp_t));
189 #endif
190    return ROK;
191 }
192 /*******************************************************************
193  *
194  * @brief Handles param request received from MAC
195  *
196  * @details
197  *
198  *    Function : l1HdlParamReq
199  *
200  *    Functionality:
201  *          -Handles param request received from MAC
202  *
203  * @params[in]   Message length
204  *               Param request message pointer
205  *
206  * @return void
207  *
208  * ****************************************************************/
209
210 void l1HdlParamReq(uint32_t msgLen, void *msg)
211 {
212 #ifdef INTEL_FAPI
213    DU_LOG("\nPHY_STUB: Received Param Request in PHY");
214
215    /* Build and send PARAM RESPONSE */
216    if(l1BldAndSndParamRsp(msg)!= ROK)
217    {
218       DU_LOG("\nPHY_STUB: Failed Sending Param Response");
219    }
220    MAC_FREE(msg, sizeof(fapi_param_req_t));
221 #endif
222
223
224 /*******************************************************************
225  *
226  * @brief Handles config request received from MAC
227  *
228  * @details
229  *
230  *    Function : l1HdlConfigReq
231  *
232  *    Functionality:
233  *          -Handles config request received from MAC
234  *
235  * @params[in]   Message length
236  *               config request message pointer
237  *
238  * @return void
239  *
240  * ****************************************************************/
241
242 void l1HdlConfigReq(uint32_t msgLen, void *msg)
243 {
244 #ifdef INTEL_FAPI
245    fapi_config_req_t *configReq = (fapi_config_req_t *)msg;
246
247    DU_LOG("\nPHY_STUB: Received Config Request in PHY");
248
249    /* Handling CONFIG RESPONSE */
250    if(l1BldAndSndConfigRsp(msg)!= ROK)
251    {
252       printf("\nPHY_STUB: Failed Sending config Response");
253    }
254
255    MAC_FREE(configReq, msgLen);
256 #endif
257
258 }
259
260 /*******************************************************************
261  *
262  * @brief Build and Send CRC Indication
263  *
264  * @details
265  *
266  *    Function : l1BuildAndSendCrcInd
267  *
268  *    Functionality:
269  *      Build and Send CRC Indication
270  *
271  * @params[in] Slot
272  *             SFN 
273  * @return ROK     - success
274  *         RFAILED - failure
275  *
276  * ****************************************************************/
277 uint16_t l1BuildAndSendCrcInd(uint16_t slot, uint16_t sfn)
278 {
279 #ifdef INTEL_FAPI
280    uint8_t idx = 0;
281    fapi_crc_ind_t  *crcInd;
282
283    MAC_ALLOC(crcInd, sizeof(fapi_crc_ind_t));
284    if(!crcInd)
285    {
286       printf("\nPHY_STUB: Memory allocation failed for CRC Indication Message");
287       return RFAILED;
288    }
289    memset(crcInd, 0, sizeof(fapi_crc_ind_t));
290
291    /* TODO: Fill the required values. As of now only 1 CRC status PASS is filled */
292    crcInd->sfn = sfn;
293    crcInd->slot = slot;
294    crcInd->numCrcs = 1;
295
296    crcInd->crc[idx].handle = 0;
297    crcInd->crc[idx].rnti = 0;
298    crcInd->crc[idx].harqId = 0;
299    crcInd->crc[idx].tbCrcStatus = 0;
300    crcInd->crc[idx].numCb = 1;
301    crcInd->crc[idx].cbCrcStatus[0] = 0;
302    crcInd->crc[idx].ul_cqi = 0;
303    crcInd->crc[idx].timingAdvance = 0;
304    crcInd->crc[idx].rssi = 0;
305
306    fillMsgHeader(&crcInd->header, FAPI_CRC_INDICATION, \
307          sizeof(fapi_crc_ind_t) - sizeof(fapi_msg_t));
308
309    /* Sending RACH indication to MAC */
310    DU_LOG("\nPHY STUB: Sending CRC Indication to MAC");
311    procPhyMessages(crcInd->header.msg_id, sizeof(fapi_crc_ind_t), (void *)crcInd);
312    MAC_FREE(crcInd, sizeof(fapi_crc_ind_t));
313 #endif
314    return ROK;
315 } /* l1BuildAndSendCrcInd */
316
317 #ifdef INTEL_FAPI
318 /*******************************************************************
319  *
320  * @brief Build and send Rx data indication
321  *
322  * @details
323  *
324  *    Function : l1BuildAndSendRxDataInd
325  *
326  *    Functionality:
327  *       Build and send Rx data indication
328  *
329  * @params[in] SFN
330  *             Slot
331  * @return ROK     - success
332  *         RFAILED - failure
333  *
334  * ****************************************************************/
335 uint16_t l1BuildAndSendRxDataInd(uint16_t slot, uint16_t sfn, fapi_ul_pusch_pdu_t puschPdu)
336 {
337    uint8_t idx = 0;
338    fapi_rx_data_indication_t *rxDataInd;
339    fapi_pdu_ind_info_t       *pduInfo;
340    uint8_t  *pdu;
341    uint16_t byteIdx = 0;
342    uint32_t msgLen = 0;
343    MsgType type;
344
345    if(!msg3Sent)
346    {
347       msg3Sent = true;
348       type = MSG_TYPE_MSG3;
349    }
350    else if(!msg5ShortBsrSent)
351    {
352       msg5ShortBsrSent = true;
353       type = MSG_TYPE_SHORT_BSR;
354    }
355    else if(!msg5Sent)
356    {
357       msg5Sent = true;
358       type = MSG_TYPE_MSG5;
359       msg5ShortBsrSent = false;
360    }
361
362
363    MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
364    if(!rxDataInd)
365    {
366       printf("\nPHY_STUB: Memory allocation failed for Rx Data Indication");
367       return RFAILED;
368    }
369    memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
370
371    /* TODO: Fill the required values */
372    msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
373    rxDataInd->sfn = sfn;
374    rxDataInd->slot = slot;
375    rxDataInd->numPdus = 1;
376
377    pduInfo = &rxDataInd->pdus[idx];
378    pduInfo->handle = puschPdu.handle;
379    pduInfo->rnti = puschPdu.rnti;
380    pduInfo->harqId = puschPdu.puschData.harqProcessId;
381    pduInfo->pdu_length = puschPdu.puschData.tbSize ;
382    pduInfo->ul_cqi = 0;
383    pduInfo->timingAdvance = 0;
384    pduInfo->rssi = 0;
385
386    /* Filling pdu with random values for testing */
387    pduInfo->pduData = NULL;
388    MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
389    if(!pduInfo->pduData)
390    {
391       printf("\nPHY_STUB: Memory allocation failed for Rx Data Pdu");
392       return RFAILED;
393    }
394
395    /* Filling PDU */
396    pdu = (uint8_t *)pduInfo->pduData;
397
398    switch(type)
399    {
400       case MSG_TYPE_MSG3: 
401          {
402             /* For Initial RRC setup Request,
403                MAC subheader format is R/R/LCId (1byte)
404                LCId is CCCH(0)
405                From 38.321 section 6.1.1
406              */
407             pdu[byteIdx++] = 0;
408             /* Hardcoding MAC PDU */
409             pdu[byteIdx++] = 181;
410             pdu[byteIdx++] = 99;
411             pdu[byteIdx++] = 20;
412             pdu[byteIdx++] = 170;
413             pdu[byteIdx++] = 132;
414             pdu[byteIdx++] = 96;
415
416             break;
417          }
418
419       case MSG_TYPE_SHORT_BSR:
420          {
421             uint8_t lcgId = 0;
422             uint8_t bufferSizeIdx = 6;
423
424             /* For Short BSR
425                MAC subheader format is R/R/LcId (1Byte)
426                LCId is 61
427                From 38.321 section 6.1.1
428              */
429             pdu[byteIdx++] = 61;    // LCID
430             pdu[byteIdx++] = (lcgId << 5) | bufferSizeIdx;
431
432             break;
433          }
434
435       case MSG_TYPE_MSG5:
436          {
437             uint8_t  msg5PduLen = 33;
438             /* For RRC setup complete
439                MAC subheader format is R/F/LCId/L (2/3 bytes)
440                LCId is 1 for SRB1
441                L is length of PDU i.e 6bytes here 
442                From 38.321 section 6.1.1
443              */
444             uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
445                64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
446                184, 56, 0, 0, 0, 0, 0};
447
448             msg5PduLen += 2;  /* 2bytes of header */
449             memcpy(pdu, &msg5, msg5PduLen);
450             byteIdx += msg5PduLen; /* 2 bytes of header */
451          }
452
453       default:
454          break;
455    } /* End of switch(type) */
456    /* Filling MAC SDU for Padding bytes*/
457    if(byteIdx < pduInfo->pdu_length)
458    {
459       /* For Padding
460          MAC subheader format is R/R/LCId (1byte)
461          LCId is 63 for padding
462          From 38.321 section 6.1.1
463        */
464       pdu[byteIdx++] = 63;
465
466       for(; byteIdx < pduInfo->pdu_length; byteIdx++)
467          pdu[byteIdx] = 0;
468    }
469    msgLen += pduInfo->pdu_length;
470
471    fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
472
473    /* Sending Rx data indication to MAC */
474    DU_LOG("\nPHY STUB: Sending Rx data Indication to MAC");
475    procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
476
477    if(pduInfo->pdu_length)
478       MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
479    MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
480    return ROK;
481 }
482 #endif
483
484 /*******************************************************************
485  *
486  * @brief Builds and Sends RACH indication to MAC 
487  *
488  * @details
489  *
490  *    Function : l1BuildAndSendRachInd 
491  *
492  *    Functionality:
493  *      Builds and Sends RACH indication to MAC
494  *
495  * @params[in] SFN value 
496  *             slot value
497  * @return ROK     - success
498  *         RFAILED - failure
499  *
500  * ****************************************************************/
501 uint16_t l1BuildAndSendRachInd(uint16_t slot, uint16_t sfn)
502 {
503 #ifdef INTEL_FAPI
504    uint8_t   rachPduIdx = 0; 
505    uint8_t   preamIdx = 0;
506    fapi_rach_pdu_t  *rachPdu;
507    fapi_rach_indication_t  *rachInd;
508
509    /* Building RACH indication */
510    MAC_ALLOC(rachInd, sizeof(fapi_rach_indication_t));
511    if(!rachInd)
512    {
513       printf("\nPHY_STUB: Memory allocation failed for Rach Indication Message");
514       return RFAILED;
515    }
516    memset(rachInd, 0, sizeof(fapi_rach_indication_t)); 
517    rachInd->sfn = sfn;
518    rachInd->slot = slot;
519    rachInd->numPdus = 1;
520
521    rachPdu = &rachInd->rachPdu[rachPduIdx];
522    rachPdu->phyCellId = NR_PCI;
523    rachPdu->symbolIndex = 0;
524    rachPdu->slotIndex = slot;
525    rachPdu->freqIndex = 0;
526    rachPdu->avgRssi = 0;
527    rachPdu->avgSnr = 0;
528    rachPdu->numPreamble = 1;
529
530    rachPdu->preambleInfo[preamIdx].preambleIndex = 3;
531    rachPdu->preambleInfo[preamIdx].timingAdvance = 0;
532    rachPdu->preambleInfo[preamIdx].preamblePwr = 0;
533
534    fillMsgHeader(&rachInd->header, FAPI_RACH_INDICATION, \
535          sizeof(fapi_rach_indication_t) - sizeof(fapi_msg_t));
536
537    /* Sending RACH indication to MAC */
538    DU_LOG("\nPHY STUB: Sending RACH Indication to MAC");
539    procPhyMessages(rachInd->header.msg_id, sizeof(fapi_rach_indication_t), (void *)rachInd);
540    MAC_FREE(rachInd, sizeof(fapi_rach_indication_t));
541 #endif
542    return ROK;
543 }
544
545 /*******************************************************************
546  *
547  * @brief Builds and Send the Slot Indication message to MAC
548  *
549  * @details
550  *
551  *    Function : l1BuildAndSendSlotIndication
552  *
553  *    Functionality:
554  *          -Send the Slot indication Message to MAC
555  *
556  * @params[in]   Message length
557  *               config request message pointer
558  *
559  * @return void
560  *
561  * ****************************************************************/
562 uint16_t l1BuildAndSendSlotIndication()
563 {
564 #ifdef INTEL_FAPI
565    fapi_slot_ind_t *slotIndMsg;
566
567    MAC_ALLOC(slotIndMsg, sizeof(fapi_slot_ind_t));
568    if(!slotIndMsg)
569    {
570       DU_LOG("\nPHY_STUB: Memory allocation failed for slot Indication Message");
571       return RFAILED;
572    }
573    else
574    {
575       memset(slotIndMsg, 0, sizeof(fapi_slot_ind_t));
576       slotIndMsg->sfn = sfnValue;
577       slotIndMsg->slot = slotValue;
578       DU_LOG("\n\nPHY_STUB: SLOT indication [%d:%d]",sfnValue,slotValue);
579
580       /* increment for the next TTI */
581       slotValue++;
582       if(sfnValue >= MAX_SFN_VALUE && slotValue > MAX_SLOT_VALUE)
583       {
584          sfnValue = 0;
585          slotValue = 0;
586       }
587       else if(slotValue > MAX_SLOT_VALUE)
588       {
589          sfnValue++;
590          slotValue = 0;
591       }
592       fillMsgHeader(&slotIndMsg->header, FAPI_SLOT_INDICATION, \
593             sizeof(fapi_slot_ind_t) - sizeof(fapi_msg_t));
594       procPhyMessages(slotIndMsg->header.msg_id, sizeof(fapi_slot_ind_t), (void*)slotIndMsg);
595       MAC_FREE(slotIndMsg, sizeof(fapi_slot_ind_t));
596    }
597 #endif
598    return ROK;
599 }
600
601 /*******************************************************************
602  *
603  * @brief Handles start request received from MAC
604  *
605  * @details
606  *
607  *    Function : l1HdlStartReq
608  *
609  *    Functionality:
610  *          -Handles start request received from MAC
611  *
612  * @params[in]   Message length
613  *               config request message pointer
614  *
615  * @return void
616  *
617  * ****************************************************************/
618
619 S16 l1HdlStartReq(uint32_t msgLen, void *msg)
620 {
621 #ifdef INTEL_FAPI
622    fapi_start_req_t *startReq = (fapi_start_req_t *)msg;
623
624    if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
625    {
626       l1HdlSlotIndicaion(FALSE);
627       MAC_FREE(startReq, sizeof(fapi_start_req_t));
628    }
629    else
630    {
631       DU_LOG("\nPHY_STUB: Received Start Req in PHY State %d", lwrMacCb.phyState);
632       return RFAILED;
633    }
634 #endif
635    return ROK;
636 }
637
638 /*******************************************************************
639  *
640  * @brief Handles Dl Tti request received from MAC
641  *
642  * @details
643  *
644  *    Function : l1HdlDlTtiReq
645  *
646  *    Functionality:
647  *          -Handles Dl Tti request received from MAC
648  *
649  * @params[in]   Message length
650  *               Dl Tti request message pointer
651  *
652  * @return void
653  *
654  * ****************************************************************/
655
656 S16 l1HdlDlTtiReq(uint16_t msgLen, void *msg)
657 {
658 #ifdef INTEL_FAPI
659    fapi_dl_tti_req_t *dlTtiReq;
660    dlTtiReq = (fapi_dl_tti_req_t *)msg;
661
662    printf("\nPHY STUB: DL TTI Request at sfn=%d slot=%d",dlTtiReq->sfn,dlTtiReq->slot);
663 #if 0
664    printf("\nPHY_STUB:  SFN     %d", dlTtiReq->sfn);
665    printf("\nPHY_STUB:  SLOT    %d", dlTtiReq->slot);
666    printf("\nPHY_STUB:  nPdus   %d", dlTtiReq->nPdus);
667    printf("\nPHY_STUB:  nGroup  %d", dlTtiReq->nGroup);
668    /* Printing SSB CONFIGURED VALUES */
669    printf("\nPHY_STUB: physCellId   %d", dlTtiReq->pdus->u.ssb_pdu.physCellId);
670    printf("\nPHY_STUB: betaPss      %d", dlTtiReq->pdus->u.ssb_pdu.betaPss);
671    printf("\nPHY_STUB: ssbBlockIndex %d",       dlTtiReq->pdus->u.ssb_pdu.ssbBlockIndex);
672    printf("\nPHY_STUB: ssbSubCarrierOffset %d", dlTtiReq->pdus->u.ssb_pdu.ssbSubCarrierOffset);
673    printf("\nPHY_STUB: ssbOffsetPointA     %d", dlTtiReq->pdus->u.ssb_pdu.ssbOffsetPointA);
674    printf("\nPHY_STUB: bchPayloadFlag      %d", dlTtiReq->pdus->u.ssb_pdu.bchPayloadFlag);
675    printf("\nPHY_STUB: bchPayload          %x", dlTtiReq->pdus->u.ssb_pdu.bchPayload);
676 #endif
677    uint8_t pduCount = 0;
678    if(dlTtiReq->nPdus == 0)
679    {
680       DU_LOG("\nPHY_STUB: No PDU in DL TTI Request");
681    }
682    for(pduCount=0; pduCount<dlTtiReq->nPdus; pduCount++)
683    {
684       if(dlTtiReq->pdus[pduCount].pduType == 3) //SSB_PDU_TYPE
685          DU_LOG("\nPHY_STUB: SSB PDU");
686       else if(dlTtiReq->pdus[pduCount].pduType == 0)
687          DU_LOG("\nPHY_STUB: PDCCH PDU");
688       else if(dlTtiReq->pdus[pduCount].pduType == 1)
689          DU_LOG("\nPHY_STUB: PDSCH PDU");
690    }
691
692    /* Free FAPI message */
693    MAC_FREE(dlTtiReq, msgLen);
694
695 #endif
696    return ROK;
697 }
698
699 /*******************************************************************
700  *
701  * @brief Handles tx_data request received from MAC
702  *
703  * @details
704  *
705  *    Function : l1HdlTxDataReq
706  *
707  *    Functionality:
708  *          -Handles tx_data request received from MAC
709  *
710  * @params[in]   Message length
711  *               tx_data request message pointer
712  *
713  * @return void
714  *
715  * ****************************************************************/
716
717 S16 l1HdlTxDataReq(uint16_t msgLen, void *msg)
718 {
719 #ifdef INTEL_FAPI
720    fapi_tx_data_req_t *txDataReq;
721    txDataReq = (fapi_tx_data_req_t *)msg;
722
723    DU_LOG("\nPHY STUB: TX DATA Request at sfn=%d slot=%d",txDataReq->sfn,txDataReq->slot);
724
725    MAC_FREE(txDataReq, msgLen);
726 #endif
727    return ROK;
728 }
729
730 #ifdef INTEL_FAPI
731 /*******************************************************************
732  *
733  * @brief Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
734  *
735  * @details
736  *
737  *    Function : fillPucchF0F1PduInfo
738  *
739  *    Functionality:
740  *       Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1 
741  *
742  * @params[in] fapi_uci_o_pucch_f0f1_t *
743  *             pucchPdu
744  * @return ROK     - success
745  *         RFAILED - failure
746  *
747  * ****************************************************************/
748 uint8_t fillPucchF0F1PduInfo(fapi_uci_o_pucch_f0f1_t *pduInfo, fapi_ul_pucch_pdu_t pucchPdu)
749 {
750    uint8_t idx = 0;
751
752    pduInfo->handle = pucchPdu.handle;
753    pduInfo->pduBitmap = 1;  //hardcoded for SR
754    pduInfo->pucchFormat = pucchPdu.formatType;
755    pduInfo->ul_cqi = 0;
756    pduInfo->rnti = pucchPdu.rnti;
757    pduInfo->timingAdvance = 0;
758    pduInfo->rssi = 0;
759    pduInfo->uciBits[idx] = 0;   //TODO: FAPI spec ver. 222.10.01 has no info about UCI Bits
760    if(pduInfo->pduBitmap & SR_PDU_BITMASK)
761    {
762       pduInfo->srInfo.srIndication = SR_DETECTED;
763       pduInfo->srInfo.srConfidenceLevel = CONFDC_LEVEL_GOOD;
764    }
765    if(pduInfo->pduBitmap & HARQ_PDU_BITMASK)
766    {
767       pduInfo->harqInfo.numHarq++;
768       pduInfo->harqInfo.harqConfidenceLevel = CONFDC_LEVEL_GOOD;
769       for(idx = 0; idx < pduInfo->harqInfo.numHarq; idx++)
770       {
771          pduInfo->harqInfo.harqValue[idx] = HARQ_PASS;
772       }
773    }
774    return ROK;
775 }
776 /*******************************************************************
777  *
778  * @brief Fills UCI Pdu Information
779  *
780  * @details
781  *
782  *    Function : fillUciPduInfo
783  *
784  *    Functionality:
785  *       Fills UCI Pdu Information
786  *
787  * @params[in] Pointer to uciPdu
788  *             pucchPdu
789  * @return ROK     - success
790  *         RFAILED - failure
791  *
792  * ****************************************************************/
793 uint8_t fillUciPduInfo(fapi_uci_pdu_info_t *uciPdu, fapi_ul_pucch_pdu_t pucchPdu)
794 {
795    uint8_t ret = ROK;
796
797    /*TODO: The pduType is hardcoded here to support 
798      UCI Ind for PUCCH forat0/format1. This is to be
799      modified when we get SR form UE */
800    uciPdu->pduType = UCI_IND_PUCCH_F0F1;
801    switch(uciPdu->pduType)
802    {
803       case UCI_IND_PUSCH:
804          break;
805       case UCI_IND_PUCCH_F0F1:
806          {
807             fapi_uci_o_pucch_f0f1_t *pduInfo = NULLP;
808
809             pduInfo = &uciPdu->uci.uciPucchF0F1;
810             ret = fillPucchF0F1PduInfo(pduInfo, pucchPdu);
811             uciPdu->pduSize = sizeof(fapi_uci_o_pucch_f0f1_t);
812          }
813          break;
814       case UCI_IND_PUCCH_F2F3F4:
815          break;
816       default:
817          DU_LOG("\nPHY_STUB: Invalid Pdu Type %d", uciPdu->pduType);
818          break;
819    }
820    return ret;
821 }
822
823 /*******************************************************************
824  *
825  * @brief Build and send Uci indication
826  *
827  * @details
828  *
829  *    Function : l1BuildAndSendUciInd
830  *
831  *    Functionality:
832  *       Build and send Uci indication
833  *
834  * @params[in] SFN
835  *             Slot
836  * @return ROK     - success
837  *         RFAILED - failure
838  *
839  * ****************************************************************/
840 uint8_t l1BuildAndSendUciInd(uint16_t slot, uint16_t sfn, fapi_ul_pucch_pdu_t pucchPdu)
841 {
842    uint8_t uciIdx = 0;
843    uint8_t nUciPdus = 0;
844    uint8_t ret = ROK;
845    uint32_t msgLen = 0;
846    fapi_uci_indication_t *uciInd =  NULLP;
847
848    MAC_ALLOC(uciInd, sizeof(fapi_uci_indication_t));
849    if(!uciInd)
850    {
851       printf("\nPHY_STUB: Memory allocation failed for UCI Indication");
852       return RFAILED;
853    }
854    memset(uciInd, 0, sizeof(fapi_uci_indication_t));
855    uciInd->sfn = sfn;
856    uciInd->slot = slot;
857    uciInd->numUcis = 1;   //consdering the UCI Ind for SR
858    nUciPdus = uciInd->numUcis;
859    while(nUciPdus)
860    {
861       ret = fillUciPduInfo(&uciInd->uciPdu[uciIdx], pucchPdu);
862       uciIdx++;
863       nUciPdus--;
864    }
865    if(ret == ROK)
866    {
867       msgLen = sizeof(fapi_uci_indication_t)- sizeof(fapi_msg_t);
868       fillMsgHeader(&uciInd->header, FAPI_UCI_INDICATION, msgLen);
869
870       /* Sending UCI indication to MAC */
871       DU_LOG("\nPHY STUB: Sending UCI Indication to MAC");
872       procPhyMessages(uciInd->header.msg_id, sizeof(fapi_uci_indication_t), (void *)uciInd);
873    }
874    MAC_FREE(uciInd, sizeof(fapi_uci_indication_t));
875    return ret;
876 }
877 #endif
878
879 /*******************************************************************
880  *
881  * @brief Handles Ul Tti request received from MAC
882  *
883  * @details
884  *
885  *    Function : l1HdlUlTtiReq
886  *
887  *    Functionality:
888  *          -Handles Ul Tti request received from MAC
889  *
890  * @params[in]   Message length
891  *               Ul Tti request message pointer
892  *
893  * @return void
894  *
895  * ****************************************************************/
896
897 S16 l1HdlUlTtiReq(uint16_t msgLen, void *msg)
898 {
899 #ifdef INTEL_FAPI
900    fapi_ul_tti_req_t *ulTtiReq = NULLP;
901    
902    DU_LOG("\nPHY STUB: Received UL TTI Request");
903
904    ulTtiReq = (fapi_ul_tti_req_t *)msg;
905    uint8_t numPdus = ulTtiReq->nPdus;
906
907    if(numPdus == 0)
908    {
909       DU_LOG("\nPHY STUB: No PDU in UL TTI");
910    }
911    while(numPdus)
912    {
913       if(ulTtiReq->pdus[numPdus-1].pduType == 0)
914       {
915          DU_LOG("\nPHY STUB: PRACH PDU");
916       }
917       if(ulTtiReq->pdus[numPdus-1].pduType == 1)
918       {
919          DU_LOG("\nPHY STUB: PUSCH PDU");                       
920          l1BuildAndSendRxDataInd(ulTtiReq->slot, ulTtiReq->sfn, \
921                ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu); 
922       }
923       if(ulTtiReq->pdus[numPdus-1].pduType == 2)
924       {
925          DU_LOG("\nPHY STUB: PUCCH PDU");
926          fapi_ul_tti_req_t ulTtiSlotInd;
927          memset(&ulTtiSlotInd, 0, sizeof(fapi_ul_tti_req_t));
928          ulTtiSlotInd.slot = ulTtiReq->slot;
929          ulTtiSlotInd.sfn  = ulTtiReq->sfn;
930          ADD_DELTA_TO_TIME(ulTtiSlotInd, ulTtiSlotInd, SLOT_DELAY);
931          l1BuildAndSendUciInd(ulTtiSlotInd.slot, ulTtiSlotInd.sfn, \
932                ulTtiReq->pdus[numPdus-1].pdu.pucch_pdu);
933       }
934       numPdus--;
935    }
936
937    if(rachIndSent == false && ulTtiReq->sfn == 2 && ulTtiReq->slot == 6)
938    {
939       rachIndSent = true;
940       l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn);
941    }
942
943    MAC_FREE(ulTtiReq, msgLen);
944 #endif
945    return ROK;
946 }
947
948 /*******************************************************************
949  *
950  * @brief Builds and Send the stop Indication message to MAC
951  *
952  * @details
953  *
954  *    Function : l1BuildAndSendStopInd
955  *
956  *    Functionality:
957  *          -Send the Stop indication Message to MAC
958  *
959  *
960  * @return void
961  *
962  * ****************************************************************/
963 uint16_t l1BuildAndSendStopInd()
964 {
965 #ifdef INTEL_FAPI
966    fapi_stop_ind_t *stopIndMsg = NULLP;
967    uint32_t msgLen = 0;
968
969    MAC_ALLOC(stopIndMsg, sizeof(fapi_stop_ind_t));
970    if(!stopIndMsg)
971    {
972       DU_LOG("\nPHY_STUB: Memory allocation failed for stop Indication Message");
973       return RFAILED;
974    }
975    else
976    {
977       fillMsgHeader(&stopIndMsg->header, FAPI_STOP_INDICATION, msgLen);
978       DU_LOG("\n\nPHY_STUB: Processing Stop indication to MAC");
979       procPhyMessages(stopIndMsg->header.msg_id,\
980             sizeof(fapi_stop_ind_t), (void*)stopIndMsg);
981       MAC_FREE(stopIndMsg, sizeof(fapi_stop_ind_t));
982    }
983 #endif
984    return ROK;
985 }
986
987 /*******************************************************************
988  *
989  * @brief Handles stop request received from MAC
990  *
991  * @details
992  *
993  *    Function : l1HdlStopReq
994  *
995  *    Functionality:
996  *          -Handles stop request received from MAC
997  *
998  * @params[in]   Message length
999  *               stop request message pointer
1000  *
1001  * @return void
1002  *
1003  * ****************************************************************/
1004
1005 S16 l1HdlStopReq(uint32_t msgLen, void *msg)
1006 {
1007 #ifdef INTEL_FAPI
1008    fapi_stop_req_t *stopReq = (fapi_stop_req_t *)msg;
1009
1010    if(lwrMacCb.phyState == PHY_STATE_RUNNING)
1011    {
1012       l1HdlSlotIndicaion(TRUE);
1013       DU_LOG("\nPHY_STUB: Slot Indication is stopped successfully");
1014       l1BuildAndSendStopInd();
1015       MAC_FREE(stopReq, msgLen);
1016    }
1017    else
1018    {
1019       DU_LOG("\nPHY_STUB: Received Stop Req in PHY State %d", lwrMacCb.phyState);
1020       return RFAILED;
1021    }
1022 #endif
1023    return ROK;
1024 }
1025
1026 /*******************************************************************
1027  *
1028  * @brief Build And Send Rx Data Ind for Msg5
1029  *
1030  * @details
1031  *
1032  *    Function : l1BuildAndSendMsg5
1033  *
1034  *    Functionality: Build And Send Rx Data Ind for Msg5
1035  *
1036  * @params[in] SFN
1037  *             Slot
1038  * @return ROK     - success
1039  *         RFAILED - failure
1040  *
1041  * ****************************************************************/
1042 uint8_t l1BuildAndSendMsg5(uint16_t sfn, uint16_t slot)
1043 {   
1044 #ifdef INTEL_FAPI
1045    uint8_t idx = 0;
1046    fapi_rx_data_indication_t *rxDataInd;
1047    fapi_pdu_ind_info_t       *pduInfo;
1048    uint8_t  *pdu;
1049    uint16_t byteIdx = 0;
1050    uint32_t msgLen = 0;
1051
1052    MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1053    if(!rxDataInd)
1054    {
1055       printf("\nPHY_STUB: Memory allocation failed for Rx Data Indication for msg5");
1056       return RFAILED;
1057    }
1058    memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1059
1060    /* TODO: Fill the required values */
1061    msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1062    rxDataInd->sfn = sfn;
1063    rxDataInd->slot = slot;
1064    rxDataInd->numPdus = 1;
1065
1066    pduInfo = &rxDataInd->pdus[idx];
1067    pduInfo->handle = 100;
1068    pduInfo->rnti = 100;
1069    pduInfo->harqId = 1;
1070    pduInfo->pdu_length = 25;
1071    pduInfo->ul_cqi = 0;
1072    pduInfo->timingAdvance = 0;
1073    pduInfo->rssi = 0;
1074
1075    /* Filling pdu with random values for testing */
1076    pduInfo->pduData = NULL;
1077    MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1078    if(!pduInfo->pduData)
1079    {
1080       printf("\nPHY_STUB: Memory allocation failed for Rx Data Pdu");
1081       return RFAILED;
1082    }
1083
1084    /* Filling PDU */
1085    pdu = (uint8_t *)pduInfo->pduData;
1086
1087    uint8_t  msg5PduLen = 33;
1088    /* For RRC setup complete
1089       MAC subheader format is R/F/LCId/L (2/3 bytes)
1090       LCId is 1 for SRB1
1091       L is length of PDU i.e 6bytes here
1092       From 38.321 section 6.1.1
1093     */
1094    uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
1095       64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
1096          184, 56, 0, 0, 0, 0, 0};
1097
1098    msg5PduLen += 2;  /* 2bytes of header */
1099    memcpy(pdu, &msg5, msg5PduLen);
1100    byteIdx += msg5PduLen; /* 2 bytes of header */
1101
1102    /* Filling MAC SDU for Padding bytes*/
1103    if(byteIdx < pduInfo->pdu_length)
1104    {
1105       /* For Padding
1106          MAC subheader format is R/R/LCId (1byte)
1107          LCId is 63 for padding
1108          From 38.321 section 6.1.1
1109        */
1110       pdu[byteIdx++] = 63;
1111
1112       for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1113          pdu[byteIdx] = 0;
1114    }
1115    msgLen += pduInfo->pdu_length;
1116
1117    fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1118
1119    /* Sending Rx data indication to MAC */
1120    DU_LOG("\nPHY STUB: Sending Rx data Indication to MAC");
1121    procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1122
1123    if(pduInfo->pdu_length)
1124       MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1125    MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1126 #endif
1127    return ROK;
1128 }
1129
1130 /*******************************************************************
1131  *
1132  * @brief Handles Ul Dci request received from MAC
1133  *
1134  * @details
1135  *
1136  *    Function : l1HdlUlDciReq
1137  *
1138  *    Functionality:
1139  *          -Handles Ul Dci request received from MAC
1140  *
1141  * @params[in]   Message length
1142  *               Ul Dci request message pointer
1143  *
1144  * @return void
1145  *
1146  * ****************************************************************/
1147
1148 S16 l1HdlUlDciReq(uint16_t msgLen, void *msg)
1149 {
1150 #ifdef INTEL_FAPI
1151    fapi_ul_dci_req_t *ulDciReq = NULLP;
1152
1153    ulDciReq = (fapi_ul_dci_req_t *)msg;
1154    uint8_t numPdus = ulDciReq->numPdus;
1155
1156    while(numPdus)
1157    {
1158       if(ulDciReq->pdus[numPdus-1].pduType == 0)
1159       {
1160          DU_LOG("\nPHY STUB: Received UL DCI Request for PDCCH PDU");
1161          //l1BuildAndSendMsg5(ulDciReq->sfn, ulDciReq->slot);
1162          //msg5Sent = true;
1163       }
1164       numPdus--;
1165    }
1166
1167    MAC_FREE(ulDciReq, msgLen);
1168 #endif
1169    return ROK;
1170 }
1171
1172 /*******************************************************************
1173  *
1174  * @brief Receives message from MAC
1175  *
1176  * @details
1177  *
1178  *    Function :  l1ProcessFapiRequest
1179  *
1180  *    Functionality:
1181  *       - Receives message from MAC and calls handler
1182  *
1183  * @params[in] Message type
1184  *             Message length
1185  *             Message pointer
1186  *
1187  * @return void
1188  *
1189  * ****************************************************************/
1190
1191 void l1ProcessFapiRequest(uint8_t msgType, uint32_t msgLen, void *msg)
1192 {
1193    switch(msgType)
1194    {
1195 #ifdef INTEL_FAPI
1196       case FAPI_PARAM_REQUEST:
1197          l1HdlParamReq(msgLen, msg);
1198          break;
1199       case FAPI_CONFIG_REQUEST:
1200          l1HdlConfigReq(msgLen, msg);
1201          break;
1202       case FAPI_START_REQUEST:
1203          l1HdlStartReq(msgLen, msg);
1204          break;
1205       case FAPI_DL_TTI_REQUEST:
1206          l1HdlDlTtiReq(msgLen, msg);
1207          break;
1208       case FAPI_TX_DATA_REQUEST:
1209          l1HdlTxDataReq(msgLen, msg);
1210          break;
1211       case FAPI_UL_TTI_REQUEST:
1212          l1HdlUlTtiReq(msgLen, msg);
1213          break;
1214       case FAPI_STOP_REQUEST:
1215          l1HdlStopReq(msgLen, msg);
1216          break;
1217       case FAPI_UL_DCI_REQUEST:
1218          l1HdlUlDciReq(msgLen, msg);
1219          break;
1220       default:
1221          DU_LOG("\nPHY_STUB: Invalid message type[%x] received at PHY", msgType);
1222          break;
1223 #endif
1224    }
1225 }
1226 /**********************************************************************
1227   End of file
1228  **********************************************************************/