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