UL data path changes at Phy stub, RLC UL UM and DU APP [Issue-ID: ODUHIGH-262]
[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_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 "phy_stub.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 =NULLP;
342    fapi_pdu_ind_info_t       *pduInfo =NULLP;
343    uint8_t  *pdu = NULLP;
344    uint16_t byteIdx = 0;
345    uint32_t msgLen = 0;
346    MsgType type = 0;
347
348    if(!msg3Sent)
349    {
350       msg3Sent = true;
351       type = MSG_TYPE_MSG3;
352       sleep(2);
353    }
354    else if(!msg5ShortBsrSent)
355    {
356       msg5ShortBsrSent = true;
357       type = MSG_TYPE_SHORT_BSR;
358    }
359    else if(!msg5Sent)
360    {
361       msg5Sent = true;
362       type = MSG_TYPE_MSG5;
363    }
364    else if(!msgRegistrationComp)
365    {
366       msgRegistrationComp = true;
367       type = MSG_TYPE_REGISTRATION_COMPLETE; 
368    }
369    else if(!msgSecurityModeComp)
370    {
371       msgSecurityModeComp = true;
372       type = MSG_TYPE_SECURITY_MODE_COMPLETE;
373    }
374    else if(!msgRrcReconfiguration)
375    {
376       msgRrcReconfiguration = true;
377       type = MSG_TYPE_RRC_RECONFIG_COMPLETE;
378    }
379    else
380       return RFAILED;
381
382    MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
383    if(!rxDataInd)
384    {
385       printf("\nPHY_STUB: Memory allocation failed for Rx Data Indication");
386       return RFAILED;
387    }
388    memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
389    
390    msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
391    rxDataInd->sfn = sfn;
392    rxDataInd->slot = slot;
393    rxDataInd->numPdus = 1;
394
395    pduInfo = &rxDataInd->pdus[idx];
396    pduInfo->handle = puschPdu.handle;
397    pduInfo->rnti = puschPdu.rnti;
398    pduInfo->harqId = puschPdu.puschData.harqProcessId;
399    pduInfo->pdu_length = puschPdu.puschData.tbSize ;
400    pduInfo->ul_cqi = 0;
401    pduInfo->timingAdvance = 0;
402    pduInfo->rssi = 0;
403
404    /* Filling pdu with random values for testing */
405    pduInfo->pduData = NULL;
406    MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
407    if(!pduInfo->pduData)
408    {
409       printf("\nPHY_STUB: Memory allocation failed for Rx Data Pdu");
410       return RFAILED;
411    }
412    memset(pduInfo->pduData, 0, pduInfo->pdu_length);
413    /* Filling PDU */
414    pdu = (uint8_t *)pduInfo->pduData;
415
416    switch(type)
417    {
418       case MSG_TYPE_MSG3: 
419          {
420             DU_LOG("\nPHY_STUB: Forming MSG3 PDU ");
421             /* For Initial RRC setup Request,
422                MAC subheader format is R/R/LCId (1byte)
423                LCId is CCCH(0)
424                From 38.321 section 6.1.1
425              */
426             pdu[byteIdx++] = 0;
427             /* Hardcoding MAC PDU */
428             pdu[byteIdx++] = 16;
429             pdu[byteIdx++] = 00;
430             pdu[byteIdx++] = 00;
431             pdu[byteIdx++] = 00;
432             pdu[byteIdx++] = 00;
433             pdu[byteIdx++] = 103;
434
435             break;
436          }
437       case MSG_TYPE_SHORT_BSR:
438       {
439          DU_LOG("\nPHY_STUB: Forming SHORT BSR PDU ");
440          uint8_t lcgId = 0;
441          uint8_t bufferSizeIdx = 6;
442
443          /* For Short BSR
444             MAC subheader format is R/R/LcId (1Byte)
445             LCId is 61
446             From 38.321 section 6.1.1
447           */
448          pdu[byteIdx++] = 61;    // LCID
449          pdu[byteIdx++] = (lcgId << 5) | bufferSizeIdx;
450
451          break;
452       }
453
454       case MSG_TYPE_MSG5:
455       {
456          DU_LOG("\nPHY_STUB: Forming MSG5 PDU");
457          uint8_t  msg5PduLen = 33;
458          /* For RRC setup complete
459             MAC subheader format is R/F/LCId/L (2/3 bytes)
460             LCId is 1 for SRB1
461             L is length of PDU i.e 6bytes here 
462             From 38.321 section 6.1.1
463           */
464          uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
465             64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
466                184, 56, 0, 0, 0, 0, 0};
467
468          msg5PduLen += 2;  /* 2bytes of header */
469          memcpy(pdu, &msg5, msg5PduLen);
470          byteIdx += msg5PduLen; /* 2 bytes of header */
471          break;
472       }
473
474       case MSG_TYPE_SECURITY_MODE_COMPLETE:
475       {
476          DU_LOG("\nPHY_STUB: Forming SECURITY MODE COMPLETE PDU");
477          uint8_t  pduLen = 12;
478          /* For security mode complete where RRC Container is dummy
479             MAC subheader format is R/F/LCId/L (2/3 bytes)
480             LCId is 1 for SRB1
481             L is length of PDU i.e 6bytes here 
482             From 38.321 section 6.1.1
483           */
484          uint8_t msg[] = {1, pduLen, 0, 3, 0x2a, 0x40, 0, 0, 0, 0, 0, 0, 0, 0};
485
486          pduLen += 2;  /* 2bytes of header */
487          memcpy(pdu, &msg, pduLen);
488          byteIdx += pduLen; /* 2 bytes of header */
489          break;
490       }
491       case MSG_TYPE_REGISTRATION_COMPLETE:
492       {
493           
494           DU_LOG("\nPHY_STUB: Forming RRC REGISTRATION COMPLETE PDU");
495           uint8_t  pduLen = 12;
496           /* For rrc reconfig complete where RRC Container is dummy
497           MAC subheader format is R/F/LCId/L (2/3 bytes)
498           LCId is 1 for SRB1
499           L is length of PDU i.e 6bytes here
500           From 38.321 section 6.1.1
501           */
502           uint8_t msg[] = {1, pduLen, 0, 0x04, 0x3a, 0x81, 0xbf, 0, 0x21, 0x80, 0, \
503           0, 0, 0};
504         
505           pduLen += 2;  /* 2bytes of header */
506           memcpy(pdu, &msg, pduLen);
507           byteIdx += pduLen; /* 2 bytes of header */
508           break;
509       }
510       case MSG_TYPE_RRC_RECONFIG_COMPLETE:
511       {
512          DU_LOG("\nPHY_STUB: Forming RRC RECONFIGURATION COMPLETE PDU");
513          uint8_t  pduLen = 14;
514          /* For rrc reconfig complete where RRC Container is dummy
515          MAC subheader format is R/F/LCId/L (2/3 bytes)
516          LCId is 1 for SRB1
517          L is length of PDU i.e 6bytes here
518          From 38.321 section 6.1.1
519          */
520          uint8_t msg[] = {1, pduLen, 0, 6, 8, 64, 0, 0, 0, 0, \
521                           0, 0, 0, 0, 0};
522         
523          pduLen += 2;  /* 2bytes of header */
524          memcpy(pdu, &msg, pduLen);
525          byteIdx += pduLen; /* 2 bytes of header */
526          break;
527
528       }
529       
530       default:
531          break;
532    } /* End of switch(type) */
533    /* Filling MAC SDU for Padding bytes*/
534    if(byteIdx < pduInfo->pdu_length)
535    {
536       /* For Padding
537          MAC subheader format is R/R/LCId (1byte)
538          LCId is 63 for padding
539          From 38.321 section 6.1.1
540        */
541       pdu[byteIdx++] = 63;
542
543       for(; byteIdx < pduInfo->pdu_length; byteIdx++)
544          pdu[byteIdx] = 0;
545    }
546    msgLen += pduInfo->pdu_length;
547
548    fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
549
550    /* Sending Rx data indication to MAC */
551    DU_LOG("\nPHY STUB: Sending Rx data Indication to MAC");
552    procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
553
554    if(pduInfo->pdu_length)
555       MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
556    MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
557    return ROK;
558 }
559 #endif
560
561 /*******************************************************************
562  *
563  * @brief Builds and Sends RACH indication to MAC 
564  *
565  * @details
566  *
567  *    Function : l1BuildAndSendRachInd 
568  *
569  *    Functionality:
570  *      Builds and Sends RACH indication to MAC
571  *
572  * @params[in] SFN value 
573  *             slot value
574  * @return ROK     - success
575  *         RFAILED - failure
576  *
577  * ****************************************************************/
578 uint16_t l1BuildAndSendRachInd(uint16_t slot, uint16_t sfn)
579 {
580 #ifdef INTEL_FAPI
581    uint8_t   rachPduIdx = 0; 
582    uint8_t   preamIdx = 0;
583    fapi_rach_pdu_t  *rachPdu;
584    fapi_rach_indication_t  *rachInd;
585
586    /* Building RACH indication */
587    MAC_ALLOC(rachInd, sizeof(fapi_rach_indication_t));
588    if(!rachInd)
589    {
590       printf("\nPHY_STUB: Memory allocation failed for Rach Indication Message");
591       return RFAILED;
592    }
593    memset(rachInd, 0, sizeof(fapi_rach_indication_t)); 
594    rachInd->sfn = sfn;
595    rachInd->slot = slot;
596    rachInd->numPdus = 1;
597
598    rachPdu = &rachInd->rachPdu[rachPduIdx];
599    rachPdu->phyCellId = NR_PCI;
600    rachPdu->symbolIndex = 0;
601    rachPdu->slotIndex = slot;
602    rachPdu->freqIndex = 0;
603    rachPdu->avgRssi = 0;
604    rachPdu->avgSnr = 0;
605    rachPdu->numPreamble = 1;
606
607    rachPdu->preambleInfo[preamIdx].preambleIndex = 3;
608    rachPdu->preambleInfo[preamIdx].timingAdvance = 0;
609    rachPdu->preambleInfo[preamIdx].preamblePwr = 0;
610
611    fillMsgHeader(&rachInd->header, FAPI_RACH_INDICATION, \
612          sizeof(fapi_rach_indication_t) - sizeof(fapi_msg_t));
613
614    /* Sending RACH indication to MAC */
615    DU_LOG("\nPHY STUB: Sending RACH Indication to MAC");
616    procPhyMessages(rachInd->header.msg_id, sizeof(fapi_rach_indication_t), (void *)rachInd);
617    MAC_FREE(rachInd, sizeof(fapi_rach_indication_t));
618 #endif
619    return ROK;
620 }
621
622 /*******************************************************************
623  *
624  * @brief Builds and Send the Slot Indication message to MAC
625  *
626  * @details
627  *
628  *    Function : l1BuildAndSendSlotIndication
629  *
630  *    Functionality:
631  *          -Send the Slot indication Message to MAC
632  *
633  * @params[in]   Message length
634  *               config request message pointer
635  *
636  * @return void
637  *
638  * ****************************************************************/
639 uint16_t l1BuildAndSendSlotIndication()
640 {
641 #ifdef INTEL_FAPI
642    fapi_slot_ind_t *slotIndMsg;
643
644    MAC_ALLOC(slotIndMsg, sizeof(fapi_slot_ind_t));
645    if(!slotIndMsg)
646    {
647       DU_LOG("\nPHY_STUB: Memory allocation failed for slot Indication Message");
648       return RFAILED;
649    }
650    else
651    {
652       memset(slotIndMsg, 0, sizeof(fapi_slot_ind_t));
653       slotIndMsg->sfn = sfnValue;
654       slotIndMsg->slot = slotValue;
655
656 #ifdef ODU_SLOT_IND_DEBUG_LOG
657       DU_LOG("\n\nPHY_STUB: SLOT indication [%d:%d]",sfnValue,slotValue);
658 #endif
659       /* increment for the next TTI */
660       slotValue++;
661       if(sfnValue >= MAX_SFN_VALUE && slotValue > MAX_SLOT_VALUE)
662       {
663          sfnValue = 0;
664          slotValue = 0;
665       }
666       else if(slotValue > MAX_SLOT_VALUE)
667       {
668          sfnValue++;
669          slotValue = 0;
670       }
671       fillMsgHeader(&slotIndMsg->header, FAPI_SLOT_INDICATION, \
672             sizeof(fapi_slot_ind_t) - sizeof(fapi_msg_t));
673       procPhyMessages(slotIndMsg->header.msg_id, sizeof(fapi_slot_ind_t), (void*)slotIndMsg);
674       MAC_FREE(slotIndMsg, sizeof(fapi_slot_ind_t));
675    }
676 #endif
677    return ROK;
678 }
679
680 /*******************************************************************
681  *
682  * @brief Handles start request received from MAC
683  *
684  * @details
685  *
686  *    Function : l1HdlStartReq
687  *
688  *    Functionality:
689  *          -Handles start request received from MAC
690  *
691  * @params[in]   Message length
692  *               config request message pointer
693  *
694  * @return void
695  *
696  * ****************************************************************/
697
698 S16 l1HdlStartReq(uint32_t msgLen, void *msg)
699 {
700 #ifdef INTEL_FAPI
701    if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
702    {
703       l1HdlSlotIndicaion(FALSE);
704       l1StartConsoleHandler();
705       MAC_FREE(msg, msgLen);
706    }
707    else
708    {
709       DU_LOG("\nPHY_STUB: Received Start Req in PHY State %d", lwrMacCb.phyState);
710       MAC_FREE(msg, msgLen);
711       return RFAILED;
712    }
713 #endif
714    return ROK;
715 }
716
717 /*******************************************************************
718  *
719  * @brief Handles Dl Tti request received from MAC
720  *
721  * @details
722  *
723  *    Function : l1HdlDlTtiReq
724  *
725  *    Functionality:
726  *          -Handles Dl Tti request received from MAC
727  *
728  * @params[in]   Message length
729  *               Dl Tti request message pointer
730  *
731  * @return void
732  *
733  * ****************************************************************/
734
735 S16 l1HdlDlTtiReq(uint16_t msgLen, void *msg)
736 {
737 #ifdef INTEL_FAPI
738    p_fapi_api_queue_elem_t dlTtiElem = (p_fapi_api_queue_elem_t)msg;
739    fapi_dl_tti_req_t *dlTtiReq = (fapi_dl_tti_req_t *)(dlTtiElem +1);
740    
741    uint8_t pduCount = 0;
742
743 #ifdef ODU_SLOT_IND_DEBUG_LOG
744    if(dlTtiReq->nPdus == 0)
745    {
746       DU_LOG("\nPHY_STUB: No PDU in DL TTI Request");
747    }
748    else
749    {  
750      DU_LOG("\nPHY STUB: DL TTI Request at sfn=%d slot=%d",dlTtiReq->sfn,dlTtiReq->slot);
751    }
752 #endif 
753
754    for(pduCount=0; pduCount<dlTtiReq->nPdus; pduCount++)
755    {
756       if(dlTtiReq->pdus[pduCount].pduType == 3) //SSB_PDU_TYPE
757       {
758          DU_LOG("\nPHY_STUB: SSB PDU");
759       }
760       else if(dlTtiReq->pdus[pduCount].pduType == 0)
761       {
762          DU_LOG("\nPHY_STUB: PDCCH PDU");
763          if(dlTtiReq->pdus[pduCount].pdu.pdcch_pdu.\
764             coreSetType == 1)
765          {
766             dlDedMsg = true;
767          }
768       }
769       else if(dlTtiReq->pdus[pduCount].pduType == 1)
770       {
771          DU_LOG("\nPHY_STUB: PDSCH PDU");
772       }
773    }
774
775    /* Free FAPI message */
776    MAC_FREE(msg, msgLen);
777 #endif
778    return ROK;
779 }
780
781 /*******************************************************************
782  *
783  * @brief Handles tx_data request received from MAC
784  *
785  * @details
786  *
787  *    Function : l1HdlTxDataReq
788  *
789  *    Functionality:
790  *          -Handles tx_data request received from MAC
791  *
792  * @params[in]   Message length
793  *               tx_data request message pointer
794  *
795  * @return void
796  *
797  * ****************************************************************/
798
799 S16 l1HdlTxDataReq(uint16_t msgLen, void *msg)
800 {
801 #ifdef INTEL_FAPI
802    p_fapi_api_queue_elem_t txDataElem = (p_fapi_api_queue_elem_t)msg;
803    fapi_tx_data_req_t *txDataReq = (fapi_tx_data_req_t *)(txDataElem +1);
804
805    DU_LOG("\nPHY STUB: TX DATA Request at sfn=%d slot=%d",txDataReq->sfn,txDataReq->slot);
806    if(dlDedMsg)
807    {
808       DU_LOG("\nPHY_STUB: TxDataPdu for DED MSG sent");
809       dlDedMsg = false;
810    }
811    MAC_FREE(msg, msgLen);
812 #endif
813    return ROK;
814 }
815
816 #ifdef INTEL_FAPI
817 /*******************************************************************
818  *
819  * @brief Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
820  *
821  * @details
822  *
823  *    Function : fillPucchF0F1PduInfo
824  *
825  *    Functionality:
826  *       Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1 
827  *
828  * @params[in] fapi_uci_o_pucch_f0f1_t *
829  *             pucchPdu
830  * @return ROK     - success
831  *         RFAILED - failure
832  *
833  * ****************************************************************/
834 uint8_t fillPucchF0F1PduInfo(fapi_uci_o_pucch_f0f1_t *pduInfo, fapi_ul_pucch_pdu_t pucchPdu)
835 {
836    uint8_t idx = 0;
837
838    pduInfo->handle = pucchPdu.handle;
839    pduInfo->pduBitmap = 1;  //hardcoded for SR
840    pduInfo->pucchFormat = pucchPdu.formatType;
841    pduInfo->ul_cqi = 0;
842    pduInfo->rnti = pucchPdu.rnti;
843    pduInfo->timingAdvance = 0;
844    pduInfo->rssi = 0;
845    if(pduInfo->pduBitmap & SR_PDU_BITMASK)
846    {
847       pduInfo->srInfo.srIndication = SR_DETECTED;
848       pduInfo->srInfo.srConfidenceLevel = CONFDC_LEVEL_GOOD;
849    }
850    if(pduInfo->pduBitmap & HARQ_PDU_BITMASK)
851    {
852       pduInfo->harqInfo.numHarq++;
853       pduInfo->harqInfo.harqConfidenceLevel = CONFDC_LEVEL_GOOD;
854       for(idx = 0; idx < pduInfo->harqInfo.numHarq; idx++)
855       {
856          pduInfo->harqInfo.harqValue[idx] = HARQ_PASS;
857       }
858    }
859    return ROK;
860 }
861 /*******************************************************************
862  *
863  * @brief Fills UCI Pdu Information
864  *
865  * @details
866  *
867  *    Function : fillUciPduInfo
868  *
869  *    Functionality:
870  *       Fills UCI Pdu Information
871  *
872  * @params[in] Pointer to uciPdu
873  *             pucchPdu
874  * @return ROK     - success
875  *         RFAILED - failure
876  *
877  * ****************************************************************/
878 uint8_t fillUciPduInfo(fapi_uci_pdu_info_t *uciPdu, fapi_ul_pucch_pdu_t pucchPdu)
879 {
880    uint8_t ret = ROK;
881
882    /*TODO: The pduType is hardcoded here to support 
883      UCI Ind for PUCCH forat0/format1. This is to be
884      modified when we get SR form UE */
885    uciPdu->pduType = UCI_IND_PUCCH_F0F1;
886    switch(uciPdu->pduType)
887    {
888       case UCI_IND_PUSCH:
889          break;
890       case UCI_IND_PUCCH_F0F1:
891          {
892             fapi_uci_o_pucch_f0f1_t *pduInfo = NULLP;
893
894             pduInfo = &uciPdu->uci.uciPucchF0F1;
895             ret = fillPucchF0F1PduInfo(pduInfo, pucchPdu);
896             uciPdu->pduSize = sizeof(fapi_uci_o_pucch_f0f1_t);
897          }
898          break;
899       case UCI_IND_PUCCH_F2F3F4:
900          break;
901       default:
902          DU_LOG("\nPHY_STUB: Invalid Pdu Type %d", uciPdu->pduType);
903          break;
904    }
905    return ret;
906 }
907
908 /*******************************************************************
909  *
910  * @brief Build and send Uci indication
911  *
912  * @details
913  *
914  *    Function : l1BuildAndSendUciInd
915  *
916  *    Functionality:
917  *       Build and send Uci indication
918  *
919  * @params[in] SFN
920  *             Slot
921  * @return ROK     - success
922  *         RFAILED - failure
923  *
924  * ****************************************************************/
925 uint8_t l1BuildAndSendUciInd(uint16_t slot, uint16_t sfn, fapi_ul_pucch_pdu_t pucchPdu)
926 {
927    uint8_t uciIdx = 0;
928    uint8_t nUciPdus = 0;
929    uint8_t ret = ROK;
930    uint32_t msgLen = 0;
931    fapi_uci_indication_t *uciInd =  NULLP;
932
933    MAC_ALLOC(uciInd, sizeof(fapi_uci_indication_t));
934    if(!uciInd)
935    {
936       printf("\nPHY_STUB: Memory allocation failed for UCI Indication");
937       return RFAILED;
938    }
939    memset(uciInd, 0, sizeof(fapi_uci_indication_t));
940    uciInd->sfn = sfn;
941    uciInd->slot = slot;
942    uciInd->numUcis = 1;   //consdering the UCI Ind for SR
943    nUciPdus = uciInd->numUcis;
944    while(nUciPdus)
945    {
946       ret = fillUciPduInfo(&uciInd->uciPdu[uciIdx], pucchPdu);
947       uciIdx++;
948       nUciPdus--;
949    }
950    if(ret == ROK)
951    {
952       msgLen = sizeof(fapi_uci_indication_t)- sizeof(fapi_msg_t);
953       fillMsgHeader(&uciInd->header, FAPI_UCI_INDICATION, msgLen);
954
955       /* Sending UCI indication to MAC */
956       DU_LOG("\nPHY STUB: Sending UCI Indication to MAC");
957       procPhyMessages(uciInd->header.msg_id, sizeof(fapi_uci_indication_t), (void *)uciInd);
958    }
959    MAC_FREE(uciInd, sizeof(fapi_uci_indication_t));
960    return ret;
961 }
962 #endif
963
964 /*******************************************************************
965  *
966  * @brief Handles Ul Tti request received from MAC
967  *
968  * @details
969  *
970  *    Function : l1HdlUlTtiReq
971  *
972  *    Functionality:
973  *          -Handles Ul Tti request received from MAC
974  *
975  * @params[in]   Message length
976  *               Ul Tti request message pointer
977  *
978  * @return void
979  *
980  * ****************************************************************/
981
982 S16 l1HdlUlTtiReq(uint16_t msgLen, void *msg)
983 {
984 #ifdef INTEL_FAPI
985    p_fapi_api_queue_elem_t ulTtiElem = (p_fapi_api_queue_elem_t)msg;
986    fapi_ul_tti_req_t *ulTtiReq = (fapi_ul_tti_req_t *)(ulTtiElem +1);
987    uint8_t numPdus = ulTtiReq->nPdus;
988
989 #ifdef ODU_SLOT_IND_DEBUG_LOG
990    if(numPdus == 0)
991    {
992       DU_LOG("\nPHY STUB: No PDU received in UL TTI Req");
993    }
994    else
995    {
996       DU_LOG("\nPHY STUB: Received UL TTI Request");
997    }
998 #endif 
999
1000    while(numPdus)
1001    {
1002       if(ulTtiReq->pdus[numPdus-1].pduType == 0)
1003       {
1004          DU_LOG("\nPHY STUB: PRACH PDU");
1005       }
1006       if(ulTtiReq->pdus[numPdus-1].pduType == 1)
1007       {
1008          DU_LOG("\nPHY STUB: PUSCH PDU");
1009          l1BuildAndSendRxDataInd(ulTtiReq->slot, ulTtiReq->sfn, \
1010                ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu); 
1011       }
1012       if(ulTtiReq->pdus[numPdus-1].pduType == 2)
1013       {
1014          DU_LOG("\nPHY STUB: PUCCH PDU");
1015          fapi_ul_tti_req_t ulTtiSlotInd;
1016          memset(&ulTtiSlotInd, 0, sizeof(fapi_ul_tti_req_t));
1017          ulTtiSlotInd.slot = ulTtiReq->slot;
1018          ulTtiSlotInd.sfn  = ulTtiReq->sfn;
1019          ADD_DELTA_TO_TIME(ulTtiSlotInd, ulTtiSlotInd, SLOT_DELAY);
1020          l1BuildAndSendUciInd(ulTtiSlotInd.slot, ulTtiSlotInd.sfn, \
1021                ulTtiReq->pdus[numPdus-1].pdu.pucch_pdu);
1022       }
1023       numPdus--;
1024    }
1025
1026    if(rachIndSent == false && ulTtiReq->sfn == 2 && ulTtiReq->slot == 6)
1027    {
1028       rachIndSent = true;
1029       l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn);
1030    }
1031
1032    MAC_FREE(msg, msgLen);
1033 #endif
1034    return ROK;
1035 }
1036
1037 /*******************************************************************
1038  *
1039  * @brief Builds and Send the stop Indication message to MAC
1040  *
1041  * @details
1042  *
1043  *    Function : l1BuildAndSendStopInd
1044  *
1045  *    Functionality:
1046  *          -Send the Stop indication Message to MAC
1047  *
1048  *
1049  * @return void
1050  *
1051  * ****************************************************************/
1052 uint16_t l1BuildAndSendStopInd()
1053 {
1054 #ifdef INTEL_FAPI
1055    fapi_stop_ind_t *stopIndMsg = NULLP;
1056    uint32_t msgLen = 0;
1057
1058    MAC_ALLOC(stopIndMsg, sizeof(fapi_stop_ind_t));
1059    if(!stopIndMsg)
1060    {
1061       DU_LOG("\nPHY_STUB: Memory allocation failed for stop Indication Message");
1062       return RFAILED;
1063    }
1064    else
1065    {
1066       fillMsgHeader(&stopIndMsg->header, FAPI_STOP_INDICATION, msgLen);
1067       DU_LOG("\n\nPHY_STUB: Processing Stop indication to MAC");
1068       procPhyMessages(stopIndMsg->header.msg_id,\
1069             sizeof(fapi_stop_ind_t), (void*)stopIndMsg);
1070       MAC_FREE(stopIndMsg, sizeof(fapi_stop_ind_t));
1071    }
1072 #endif
1073    return ROK;
1074 }
1075
1076 /*******************************************************************
1077  *
1078  * @brief Handles stop request received from MAC
1079  *
1080  * @details
1081  *
1082  *    Function : l1HdlStopReq
1083  *
1084  *    Functionality:
1085  *          -Handles stop request received from MAC
1086  *
1087  * @params[in]   Message length
1088  *               stop request message pointer
1089  *
1090  * @return void
1091  *
1092  * ****************************************************************/
1093
1094 S16 l1HdlStopReq(uint32_t msgLen, void *msg)
1095 {
1096 #ifdef INTEL_FAPI
1097    if(lwrMacCb.phyState == PHY_STATE_RUNNING)
1098    {
1099       l1HdlSlotIndicaion(TRUE);
1100       DU_LOG("\nPHY_STUB: Slot Indication is stopped successfully");
1101       l1BuildAndSendStopInd();
1102       MAC_FREE(msg, msgLen);
1103    }
1104    else
1105    {
1106       DU_LOG("\nPHY_STUB: Received Stop Req in PHY State %d", lwrMacCb.phyState);
1107       MAC_FREE(msg, msgLen);
1108       return RFAILED;
1109    }
1110 #endif
1111    return ROK;
1112 }
1113
1114 /*******************************************************************
1115  *
1116  * @brief Build And Send Rx Data Ind for Msg5
1117  *
1118  * @details
1119  *
1120  *    Function : l1BuildAndSendMsg5
1121  *
1122  *    Functionality: Build And Send Rx Data Ind for Msg5
1123  *
1124  * @params[in] SFN
1125  *             Slot
1126  * @return ROK     - success
1127  *         RFAILED - failure
1128  *
1129  * ****************************************************************/
1130 uint8_t l1BuildAndSendMsg5(uint16_t sfn, uint16_t slot)
1131 {   
1132 #ifdef INTEL_FAPI
1133    uint8_t idx = 0;
1134    fapi_rx_data_indication_t *rxDataInd;
1135    fapi_pdu_ind_info_t       *pduInfo;
1136    uint8_t  *pdu;
1137    uint16_t byteIdx = 0;
1138    uint32_t msgLen = 0;
1139
1140    MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1141    if(!rxDataInd)
1142    {
1143       printf("\nPHY_STUB: Memory allocation failed for Rx Data Indication for msg5");
1144       return RFAILED;
1145    }
1146    memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1147
1148    /* TODO: Fill the required values */
1149    msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1150    rxDataInd->sfn = sfn;
1151    rxDataInd->slot = slot;
1152    rxDataInd->numPdus = 1;
1153
1154    pduInfo = &rxDataInd->pdus[idx];
1155    pduInfo->handle = 100;
1156    pduInfo->rnti = 100;
1157    pduInfo->harqId = 1;
1158    pduInfo->pdu_length = 25;
1159    pduInfo->ul_cqi = 0;
1160    pduInfo->timingAdvance = 0;
1161    pduInfo->rssi = 0;
1162
1163    /* Filling pdu with random values for testing */
1164    pduInfo->pduData = NULL;
1165    MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1166    if(!pduInfo->pduData)
1167    {
1168       printf("\nPHY_STUB: Memory allocation failed for Rx Data Pdu");
1169       return RFAILED;
1170    }
1171
1172    /* Filling PDU */
1173    pdu = (uint8_t *)pduInfo->pduData;
1174
1175    uint8_t  msg5PduLen = 33;
1176    /* For RRC setup complete
1177       MAC subheader format is R/F/LCId/L (2/3 bytes)
1178       LCId is 1 for SRB1
1179       L is length of PDU i.e 6bytes here
1180       From 38.321 section 6.1.1
1181     */
1182    uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
1183       64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
1184          184, 56, 0, 0, 0, 0, 0};
1185
1186    msg5PduLen += 2;  /* 2bytes of header */
1187    memcpy(pdu, &msg5, msg5PduLen);
1188    byteIdx += msg5PduLen; /* 2 bytes of header */
1189
1190    /* Filling MAC SDU for Padding bytes*/
1191    if(byteIdx < pduInfo->pdu_length)
1192    {
1193       /* For Padding
1194          MAC subheader format is R/R/LCId (1byte)
1195          LCId is 63 for padding
1196          From 38.321 section 6.1.1
1197        */
1198       pdu[byteIdx++] = 63;
1199
1200       for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1201          pdu[byteIdx] = 0;
1202    }
1203    msgLen += pduInfo->pdu_length;
1204
1205    fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1206
1207    /* Sending Rx data indication to MAC */
1208    DU_LOG("\nPHY STUB: Sending Rx data Indication to MAC");
1209    procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1210
1211    if(pduInfo->pdu_length)
1212       MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1213    MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1214 #endif
1215    return ROK;
1216 }
1217
1218 /*******************************************************************
1219  *
1220  * @brief Handles Ul Dci request received from MAC
1221  *
1222  * @details
1223  *
1224  *    Function : l1HdlUlDciReq
1225  *
1226  *    Functionality:
1227  *          -Handles Ul Dci request received from MAC
1228  *
1229  * @params[in]   Message length
1230  *               Ul Dci request message pointer
1231  *
1232  * @return void
1233  *
1234  * ****************************************************************/
1235
1236 S16 l1HdlUlDciReq(uint16_t msgLen, void *msg)
1237 {
1238 #ifdef INTEL_FAPI
1239    p_fapi_api_queue_elem_t ulDciElem = (p_fapi_api_queue_elem_t)msg;
1240    fapi_ul_dci_req_t *ulDciReq = (fapi_ul_dci_req_t *)(ulDciElem +1);
1241    uint8_t numPdus = ulDciReq->numPdus;
1242
1243    while(numPdus)
1244    {
1245       if(ulDciReq->pdus[numPdus-1].pduType == 0)
1246       {
1247          DU_LOG("\nPHY STUB: Received UL DCI Request for PDCCH PDU");
1248          //l1BuildAndSendMsg5(ulDciReq->sfn, ulDciReq->slot);
1249          //msg5Sent = true;
1250       }
1251       numPdus--;
1252    }
1253
1254    MAC_FREE(msg, msgLen);
1255 #endif
1256    return ROK;
1257 }
1258
1259 /*******************************************************************
1260  *
1261  * @brief Send UL user data to DU
1262  *
1263  * @details
1264  *
1265  *    Function : l1SendUlUserData
1266  *
1267  *    Functionality: Send UL user data to DU
1268  *
1269  * @params[in]
1270  * @return ROK     - success
1271  *         RFAILED - failure
1272  *
1273  * ****************************************************************/
1274 uint8_t l1SendUlUserData()
1275 {
1276    uint8_t cnt = 0;
1277    fapi_rx_data_indication_t *rxDataInd;
1278    fapi_pdu_ind_info_t       *pduInfo;
1279    uint8_t  *pdu = NULLP;
1280    uint16_t byteIdx = 0;
1281    uint32_t msgLen = 0;
1282    uint8_t idx = 0;
1283
1284    MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1285    if(!rxDataInd)
1286    {
1287       printf("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Indication");
1288       return RFAILED;
1289    }
1290    memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1291
1292    msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1293    rxDataInd->sfn = 0;
1294    rxDataInd->slot = 0;
1295    rxDataInd->numPdus = 1;
1296
1297    /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1298    pduInfo = &rxDataInd->pdus[idx];
1299    pduInfo->handle = 100;
1300    pduInfo->rnti = 100;
1301    pduInfo->harqId = 1;
1302    /* Since user data size = 50bytes and 2 bytes of MAC header and 3 byte of RLC header, 
1303     * setting tbsize = 56 from Table 5.1.3.2-1 spec 38.214 */
1304    pduInfo->pdu_length = 56;
1305    pduInfo->ul_cqi = 0;
1306    pduInfo->timingAdvance = 0;
1307    pduInfo->rssi = 0;
1308
1309    /* Filling pdu with random values for testing */
1310    pduInfo->pduData = NULL;
1311    MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1312    if(!pduInfo->pduData)
1313    {
1314       printf("\nERROR  -->  PHY_STUB: Memory allocation failed for Rx Data Pdu");
1315       return RFAILED;
1316    }
1317
1318    /* Filling PDU */
1319    pdu = (uint8_t *)pduInfo->pduData;
1320    msgLen = 51;
1321
1322    /* For UL User data
1323       MAC subheader format is R/F/LCId/L (2/3 bytes)
1324       LCId is 4 for DRB1
1325       L is length of PDU i.e 50 bytes
1326       From 38.321 section 6.1.1
1327     */
1328    uint8_t ulMsg[] = {4, msgLen, 0, 69, 0, 0, 50, 0, 0, 0, 0, 0, 1, 0, 0, 192, 168, 130, 81, 192, 168, 130, 82, 84, 104,
1329    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};
1330    msgLen += 2;  /* 2bytes of header */
1331    memcpy(pdu, &ulMsg, msgLen);
1332    byteIdx += msgLen; /* 2 bytes of header */
1333
1334
1335    /* Filling MAC SDU for Padding bytes*/
1336    if(byteIdx < pduInfo->pdu_length)
1337    {
1338       /* For Padding
1339          MAC subheader format is R/R/LCId (1byte)
1340          LCId is 63 for padding
1341          From 38.321 section 6.1.1
1342        */
1343       pdu[byteIdx++] = 63;
1344
1345       for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1346          pdu[byteIdx] = 0;
1347    }
1348    msgLen += pduInfo->pdu_length;
1349
1350    fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1351
1352     /* Send Message to peer */
1353     while(cnt < 200)
1354     {
1355        DU_LOG("\nDEBUG  -->  PHY STUB : Sending UL User Data[%d] at sfn %d slot %d", cnt+1, sfnValue, slotValue);
1356        /* Sending Rx data indication to MAC */
1357        rxDataInd->sfn = sfnValue;
1358        rxDataInd->slot = slotValue;
1359        procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1360        cnt++;
1361     }
1362
1363     if(pduInfo->pdu_length)
1364        MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1365     MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1366     return ROK;
1367 }
1368
1369 /*******************************************************************
1370  *
1371  * @brief Receives message from MAC
1372  *
1373  * @details
1374  *
1375  *    Function :  l1ProcessFapiRequest
1376  *
1377  *    Functionality:
1378  *       - Receives message from MAC and calls handler
1379  *
1380  * @params[in] Message type
1381  *             Message length
1382  *             Message pointer
1383  *
1384  * @return void
1385  *
1386  * ****************************************************************/
1387
1388 void l1ProcessFapiRequest(uint8_t msgType, uint32_t msgLen, void *msg)
1389 {
1390    switch(msgType)
1391    {
1392 #ifdef INTEL_FAPI
1393       case FAPI_PARAM_REQUEST:
1394          l1HdlParamReq(msgLen, msg);
1395          break;
1396       case FAPI_CONFIG_REQUEST:
1397          l1HdlConfigReq(msgLen, msg);
1398          break;
1399       case FAPI_START_REQUEST:
1400          l1HdlStartReq(msgLen, msg);
1401          break;
1402       case FAPI_DL_TTI_REQUEST:
1403          l1HdlDlTtiReq(msgLen, msg);
1404          break;
1405       case FAPI_TX_DATA_REQUEST:
1406          l1HdlTxDataReq(msgLen, msg);
1407          break;
1408       case FAPI_UL_TTI_REQUEST:
1409          l1HdlUlTtiReq(msgLen, msg);
1410          break;
1411       case FAPI_STOP_REQUEST:
1412          l1HdlStopReq(msgLen, msg);
1413          break;
1414       case FAPI_UL_DCI_REQUEST:
1415          l1HdlUlDciReq(msgLen, msg);
1416          break;
1417       default:
1418          DU_LOG("\nPHY_STUB: Invalid message type[%x] received at PHY", msgType);
1419          break;
1420 #endif
1421    }
1422 }
1423 /**********************************************************************
1424   End of file
1425  **********************************************************************/