Merge "MAC Clean-up [Issue-ID: ODUHIGH-212]"
[o-du/l2.git] / src / phy_stub / l1_bdy1.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /*This file contains stub for PHY to handle messages to/from MAC CL */
20
21 #include "common_def.h"
22 #include "lrg.h"
23 #include "lrg.x"
24 #include "du_app_mac_inf.h"
25 #include "mac_sch_interface.h"
26 #include "lwr_mac.h"
27 #include "lwr_mac_phy.h"
28 #ifdef INTEL_FAPI
29 #include "fapi.h"
30 #endif
31 #include "lphy_stub.h"
32 #include "lwr_mac_upr_inf.h"
33 #include "mac_utils.h"
34
35 #define MAX_SLOT_VALUE   9
36 #define MAX_SFN_VALUE    1023
37 #define NR_PCI            1
38
39 uint16_t sfnValue = 0;
40 uint16_t slotValue = 0;
41 bool     rachIndSent = false;
42
43 EXTERN void phyToMac ARGS((uint16_t msgType, uint32_t msgLen,void *msg));
44 #ifdef INTEL_FAPI
45 EXTERN void fillTlvs ARGS((fapi_uint16_tlv_t *tlv, uint16_t tag, uint16_t
46 length, uint16_t value, uint32_t *msgLen));
47 EXTERN void fillMsgHeader ARGS((fapi_msg_t *hdr, uint16_t msgType, uint16_t msgLen));
48 #endif
49 EXTERN void procPhyMessages(uint16_t msgType, uint32_t msgSize, void *msg);
50
51 /*******************************************************************
52  *
53  * @brief Builds and sends param response to MAC CL
54  *
55  * @details
56  *
57  *    Function : l1BldAndSndParamRsp
58  *
59  *    Functionality:
60  *          - Builds and sends param response to MAC
61  *
62  * @params[in] Config request message pointer
63  * @return ROK     - success
64  *         RFAILED - failure
65  *
66  * ****************************************************************/
67 S16 l1BldAndSndParamRsp(void *msg)
68 {
69 #ifdef INTEL_FAPI
70    uint8_t index = 0;
71    uint32_t msgLen = 0;
72    fapi_param_resp_t *fapiParamRsp;
73
74    MAC_ALLOC(fapiParamRsp, sizeof(fapi_param_resp_t));
75    if(!fapiParamRsp)
76    {
77       DU_LOG("PHY STUB: Memory allocation failed");
78       return RFAILED;
79    }
80
81    /* Cell Params */
82    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_RELEASE_CAPABILITY_TAG,                         sizeof(uint16_t), 1, &msgLen);
83    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PHY_STATE_TAG,                                  sizeof(uint16_t), 0, &msgLen);
84    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SKIP_BLANK_DL_CONFIG_TAG,                       sizeof(uint8_t),  0, &msgLen);
85    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SKIP_BLANK_UL_CONFIG_TAG,                       sizeof(uint8_t),  0, &msgLen);
86    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_NUM_CONFIG_TLVS_TO_REPORT_TYPE_TAG,              sizeof(uint8_t),  0, &msgLen);
87
88    /* Carrier Params */
89    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_CYCLIC_PREFIX_TAG,                               sizeof(uint8_t),  1, &msgLen);
90    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_SUBCARRIER_SPACING_DL_TAG,            sizeof(uint8_t),  1, &msgLen);
91    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_BANDWIDTH_DL_TAG,                     sizeof(uint16_t), 1, &msgLen);
92    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_SUBCARRIER_SPACING_UL_TAG,            sizeof(uint8_t),  0, &msgLen);
93    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_BANDWIDTH_UL_TAG,                     sizeof(uint16_t), 0, &msgLen);
94
95    /* PDCCH Param*/
96    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_CCE_MAPPING_TYPE_TAG,                                   sizeof(uint8_t), 0, &msgLen);
97    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_CORESET_OUTSIDE_FIRST_3_OFDM_SYMS_OF_SLOT_TAG,   sizeof(uint8_t), 0, &msgLen);
98    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PRECODER_GRANULARITY_CORESET_TAG,               sizeof(uint8_t), 0, &msgLen);
99    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDCCH_MU_MIMO_TAG,                              sizeof(uint8_t), 0, &msgLen);
100    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDCCH_PRECODER_CYCLING_TAG,                     sizeof(uint8_t), 0, &msgLen);
101    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_PDCCHS_PER_SLOT_TAG,                                sizeof(uint8_t), 0, &msgLen);
102
103    /* PUCCH Param */
104    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUCCH_FORMATS_TAG,                              sizeof(uint8_t), 0, &msgLen);
105    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_PUCCHS_PER_SLOT_TAG,                         sizeof(uint8_t), 0, &msgLen);
106
107    /* PDSCH Param */
108    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_MAPPING_TYPE_TAG,                         sizeof(uint8_t), 0, &msgLen);
109    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_ALLOCATION_TYPES_TAG,                      sizeof(uint8_t), 0, &msgLen);
110    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_VRB_TO_PRB_MAPPING_TAG,                   sizeof(uint8_t), 0, &msgLen);
111    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_CBG_TAG,                                  sizeof(uint8_t), 0, &msgLen);
112    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_DMRS_CONFIG_TYPES_TAG,                    sizeof(uint8_t), 0, &msgLen);
113    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_DMRS_MAX_LENGTH_TAG,                      sizeof(uint8_t), 0, &msgLen);
114    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_DMRS_ADDITIONAL_POS_TAG,                  sizeof(uint8_t), 0, &msgLen);
115    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_PDSCHS_TBS_PER_SLOT_TAG,                    sizeof(uint8_t), 0, &msgLen);
116    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_NUMBER_MIMO_LAYERS_PDSCH_TAG,               sizeof(uint8_t), 0, &msgLen);
117    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_MAX_MODULATION_ORDER_DL_TAG,          sizeof(uint8_t), 0, &msgLen);
118    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_MU_MIMO_USERS_DL_TAG,                       sizeof(uint8_t), 0, &msgLen);
119    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_DATA_IN_DMRS_SYMBOLS_TAG,                 sizeof(uint8_t), 0, &msgLen);
120    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PREMPTIONSUPPORT_TAG,                           sizeof(uint8_t), 0, &msgLen);
121    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PDSCH_NON_SLOT_SUPPORT_TAG,                      sizeof(uint8_t), 0, &msgLen);
122
123    /* PUSCH Param */
124    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_UCI_MUX_ULSCH_IN_PUSCH_TAG,                     sizeof(uint8_t), 0, &msgLen);
125    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_UCI_ONLY_PUSCH_TAG,                             sizeof(uint8_t), 0, &msgLen);
126    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_FREQUENCY_HOPPING_TAG,                    sizeof(uint8_t), 0, &msgLen);
127    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_DMRS_CONFIG_TYPES_TAG,                    sizeof(uint8_t), 0, &msgLen);
128    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_DMRS_MAX_LEN_TAG,                         sizeof(uint8_t), 0, &msgLen);
129    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_DMRS_ADDITIONAL_POS_TAG,                  sizeof(uint8_t), 0, &msgLen);
130    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_CBG_TAG,                                  sizeof(uint8_t), 0, &msgLen);
131    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_MAPPING_TYPE_TAG,                          sizeof(uint8_t), 0, &msgLen);
132    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_ALLOCATION_TYPES_TAG,                     sizeof(uint8_t), 0, &msgLen);
133    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_VRB_TO_PRB_MAPPING_TAG,                   sizeof(uint8_t), 0, &msgLen);
134    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_MAX_PTRS_PORTS_TAG,                        sizeof(uint8_t), 0, &msgLen);
135    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_PDUSCHS_TBS_PER_SLOT_TAG,                   sizeof(uint8_t), 0, &msgLen);
136    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_NUMBER_MIMO_LAYERS_NON_CB_PUSCH_TAG,         sizeof(uint8_t), 0, &msgLen);
137    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_SUPPORTED_MODULATION_ORDER_UL_TAG,               sizeof(uint8_t), 0, &msgLen);
138    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_MU_MIMO_USERS_UL_TAG,                        sizeof(uint8_t), 0, &msgLen);
139    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_DFTS_OFDM_SUPPORT_TAG,                           sizeof(uint8_t), 0, &msgLen);
140    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PUSCH_AGGREGATION_FACTOR_TAG,                    sizeof(uint8_t), 0, &msgLen);
141
142    /* PRACH Params */
143    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PRACH_LONG_FORMATS_TAG,                         sizeof(uint8_t), 0, &msgLen);
144    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PRACH_SHORT_FORMATS_TAG,                         sizeof(uint8_t), 0, &msgLen);
145    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_PRACH_RESTRICTED_SETS_TAG,                       sizeof(uint8_t), 0, &msgLen);
146    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_MAX_PRACH_FD_OCCASIONS_IN_A_SLOT_TAG,            sizeof(uint8_t), 0, &msgLen);
147
148    /* MEASUREMENT TAG */
149    fillTlvs(&fapiParamRsp->tlvs[index++],  FAPI_RSSI_MEASUREMENT_SUPPORT_TAG,                    sizeof(uint8_t), 0, &msgLen);
150
151    fapiParamRsp->number_of_tlvs = index;
152    msgLen += sizeof(fapi_param_resp_t) - sizeof(fapi_msg_t);
153    fillMsgHeader(&fapiParamRsp->header, FAPI_PARAM_RESPONSE, msgLen);
154    fapiParamRsp->error_code = MSG_OK;
155
156    DU_LOG("\nPHY_STUB: Sending Param Request to Lower Mac");
157    procPhyMessages(fapiParamRsp->header.msg_id, sizeof(fapi_param_resp_t), (void *)fapiParamRsp);
158    MAC_FREE(fapiParamRsp, sizeof(fapi_param_resp_t));
159 #endif
160    return ROK;
161 }
162
163 /*******************************************************************
164  *
165  * @brief Builds and sends config response to lower mac
166  *
167  * @details
168  *
169  *    Function : l1BldAndSndConfigRsp
170  *
171  *    Functionality:
172  *          - Builds and sends config response to MAC
173  *
174  * @params[in] Config request message pointer
175  * @return ROK     - success
176  *         RFAILED - failure
177  *
178  * ****************************************************************/
179
180 S16 l1BldAndSndConfigRsp(void *msg)
181 {
182 #ifdef INTEL_FAPI
183    uint32_t msgLen = 0;
184    fapi_config_resp_t *fapiConfigRsp;
185
186    MAC_ALLOC(fapiConfigRsp, sizeof(fapi_config_resp_t));
187    if(!fapiConfigRsp)
188    {
189       DU_LOG("PHY STUB: Memory allocation failed");
190       return RFAILED;
191    }
192    memset(fapiConfigRsp, 0, sizeof(fapi_config_resp_t));
193    fapiConfigRsp->number_of_invalid_tlvs = NULLP;
194    fapiConfigRsp->number_of_inv_tlvs_idle_only = NULLP;
195    fapiConfigRsp->number_of_missing_tlvs = NULLP;
196    fapiConfigRsp->error_code = MSG_OK;
197    msgLen = sizeof(fapi_config_resp_t) - sizeof(fapi_msg_t);
198    fillMsgHeader(&fapiConfigRsp->header, FAPI_CONFIG_RESPONSE, msgLen);
199
200    DU_LOG("\nPHY_STUB: Sending Config Response to Lower Mac");
201    procPhyMessages(fapiConfigRsp->header.msg_id, \
202          sizeof(fapi_config_resp_t), (void *)fapiConfigRsp);
203    MAC_FREE(fapiConfigRsp, sizeof(fapi_config_resp_t));
204 #endif
205    return ROK;
206 }
207 /*******************************************************************
208  *
209  * @brief Handles param request received from MAC
210  *
211  * @details
212  *
213  *    Function : l1HdlParamReq
214  *
215  *    Functionality:
216  *          -Handles param request received from MAC
217  *
218  * @params[in]   Message length
219  *               Param request message pointer
220  *
221  * @return void
222  *
223  * ****************************************************************/
224
225 PUBLIC void l1HdlParamReq(uint32_t msgLen, void *msg)
226 {
227 #ifdef INTEL_FAPI
228    DU_LOG("\nPHY_STUB: Received Param Request in PHY");
229
230    /* Build and send PARAM RESPONSE */
231    if(l1BldAndSndParamRsp(msg)!= ROK)
232    {
233       DU_LOG("\nPHY_STUB: Failed Sending Param Response");
234    }
235    MAC_FREE(msg, sizeof(fapi_param_req_t));
236 #endif
237
238
239 /*******************************************************************
240  *
241  * @brief Handles config request received from MAC
242  *
243  * @details
244  *
245  *    Function : l1HdlConfigReq
246  *
247  *    Functionality:
248  *          -Handles config request received from MAC
249  *
250  * @params[in]   Message length
251  *               config request message pointer
252  *
253  * @return void
254  *
255  * ****************************************************************/
256
257 PUBLIC void l1HdlConfigReq(uint32_t msgLen, void *msg)
258 {
259 #ifdef INTEL_FAPI
260    fapi_config_req_t *configReq = (fapi_config_req_t *)msg;
261
262    DU_LOG("\nPHY_STUB: Received Config Request in PHY");
263
264    /* Handling CONFIG RESPONSE */
265    if(l1BldAndSndConfigRsp(msg)!= ROK)
266    {
267       printf("\nPHY_STUB: Failed Sending config Response");
268    }
269
270    MAC_FREE(configReq, msgLen);
271 #endif
272
273 }
274
275 /*******************************************************************
276  *
277  * @brief Build and Send CRC Indication
278  *
279  * @details
280  *
281  *    Function : l1BuildAndSendCrcInd
282  *
283  *    Functionality:
284  *      Build and Send CRC Indication
285  *
286  * @params[in] Slot
287  *             SFN 
288  * @return ROK     - success
289  *         RFAILED - failure
290  *
291  * ****************************************************************/
292 uint16_t l1BuildAndSendCrcInd(uint16_t slot, uint16_t sfn)
293 {
294 #ifdef INTEL_FAPI
295    uint8_t idx = 0;
296    fapi_crc_ind_t  *crcInd;
297
298    MAC_ALLOC(crcInd, sizeof(fapi_crc_ind_t));
299    if(!crcInd)
300    {
301       printf("\nPHY_STUB: Memory allocation failed for CRC Indication Message");
302       return RFAILED;
303    }
304    memset(crcInd, 0, sizeof(fapi_crc_ind_t));
305
306    /* TODO: Fill the required values. As of now only 1 CRC status PASS is filled */
307    crcInd->sfn = sfn;
308    crcInd->slot = slot;
309    crcInd->numCrcs = 1;
310
311    crcInd->crc[idx].handle = 0;
312    crcInd->crc[idx].rnti = 0;
313    crcInd->crc[idx].harqId = 0;
314    crcInd->crc[idx].tbCrcStatus = 0;
315    crcInd->crc[idx].numCb = 1;
316    crcInd->crc[idx].cbCrcStatus[0] = 0;
317    crcInd->crc[idx].ul_cqi = 0;
318    crcInd->crc[idx].timingAdvance = 0;
319    crcInd->crc[idx].rssi = 0;
320
321    fillMsgHeader(&crcInd->header, FAPI_CRC_INDICATION, \
322          sizeof(fapi_crc_ind_t) - sizeof(fapi_msg_t));
323
324    /* Sending RACH indication to MAC */
325    DU_LOG("\nPHY STUB: Sending CRC Indication to MAC");
326    procPhyMessages(crcInd->header.msg_id, sizeof(fapi_crc_ind_t), (void *)crcInd);
327    MAC_FREE(crcInd, sizeof(fapi_crc_ind_t));
328 #endif
329    return ROK;
330 } /* l1BuildAndSendCrcInd */
331
332 #ifdef INTEL_FAPI
333 /*******************************************************************
334  *
335  * @brief Build and send Rx data indication
336  *
337  * @details
338  *
339  *    Function : l1BuildAndSendRxDataInd
340  *
341  *    Functionality:
342  *       Build and send Rx data indication
343  *
344  * @params[in] SFN
345  *             Slot
346  * @return ROK     - success
347  *         RFAILED - failure
348  *
349  * ****************************************************************/
350 uint16_t l1BuildAndSendRxDataInd(uint16_t slot, uint16_t sfn, fapi_ul_pusch_pdu_t puschPdu)
351 {
352    uint8_t idx = 0;
353    fapi_rx_data_indication_t *rxDataInd;
354    fapi_pdu_ind_info_t       *pduInfo;
355    uint8_t  *pdu;
356    uint16_t byteIdx = 0;
357    uint32_t msgLen = 0;
358
359    MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
360    if(!rxDataInd)
361    {
362       printf("\nPHY_STUB: Memory allocation failed for Rx Data Indication");
363       return RFAILED;
364    }
365    memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
366
367    /* TODO: Fill the required values */
368    msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
369    rxDataInd->sfn = sfn;
370    rxDataInd->slot = slot;
371    rxDataInd->numPdus = 1;
372
373    pduInfo = &rxDataInd->pdus[idx];
374    pduInfo->handle = puschPdu.handle;
375    pduInfo->rnti = puschPdu.rnti;
376    pduInfo->harqId = puschPdu.puschData.harqProcessId;
377    pduInfo->pdu_length = puschPdu.puschData.tbSize;
378    pduInfo->ul_cqi = 0;
379    pduInfo->timingAdvance = 0;
380    pduInfo->rssi = 0;
381
382    /* Filling pdu with random values for testing */
383    pduInfo->pduData = NULL;
384    MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
385    if(!pduInfo->pduData)
386    {
387       printf("\nPHY_STUB: Memory allocation failed for Rx Data Pdu");
388       return RFAILED;
389    }
390
391    /* Harcoded Initial RRC setup Request */
392    pdu = (uint8_t *)pduInfo->pduData;
393    pdu[byteIdx++] = 0;
394    pdu[byteIdx++] = 181;
395    pdu[byteIdx++] = 99;
396    pdu[byteIdx++] = 20;
397    pdu[byteIdx++] = 170;
398    pdu[byteIdx++] = 132;
399    pdu[byteIdx++] = 96;
400
401    /* Harcoding the pad bytes */
402    pdu[byteIdx++] = 63;
403
404    for(; byteIdx < pduInfo->pdu_length; byteIdx++)
405       pdu[byteIdx] = 0;
406    msgLen += pduInfo->pdu_length;
407
408    fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
409
410    /* Sending Rx data indication to MAC */
411    DU_LOG("\nPHY STUB: Sending Rx data Indication to MAC");
412    procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
413
414    if(pduInfo->pdu_length)
415       MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
416    MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
417    return ROK;
418 }
419 #endif
420
421 /*******************************************************************
422  *
423  * @brief Builds and Sends RACH indication to MAC 
424  *
425  * @details
426  *
427  *    Function : l1BuildAndSendRachInd 
428  *
429  *    Functionality:
430  *      Builds and Sends RACH indication to MAC
431  *
432  * @params[in] SFN value 
433  *             slot value
434  * @return ROK     - success
435  *         RFAILED - failure
436  *
437  * ****************************************************************/
438 uint16_t l1BuildAndSendRachInd(uint16_t slot, uint16_t sfn)
439 {
440 #ifdef INTEL_FAPI
441    uint8_t   rachPduIdx = 0; 
442    uint8_t   preamIdx = 0;
443    fapi_rach_pdu_t  *rachPdu;
444    fapi_rach_indication_t  *rachInd;
445
446    /* Building RACH indication */
447    MAC_ALLOC(rachInd, sizeof(fapi_rach_indication_t));
448    if(!rachInd)
449    {
450       printf("\nPHY_STUB: Memory allocation failed for Rach Indication Message");
451       return RFAILED;
452    }
453    memset(rachInd, 0, sizeof(fapi_rach_indication_t)); 
454    rachInd->sfn = sfn;
455    rachInd->slot = slot;
456    rachInd->numPdus = 1;
457
458    rachPdu = &rachInd->rachPdu[rachPduIdx];
459    rachPdu->phyCellId = NR_PCI;
460    rachPdu->symbolIndex = 0;
461    rachPdu->slotIndex = slot;
462    rachPdu->freqIndex = 0;
463    rachPdu->avgRssi = 0;
464    rachPdu->avgSnr = 0;
465    rachPdu->numPreamble = 1;
466
467    rachPdu->preambleInfo[preamIdx].preambleIndex = 3;
468    rachPdu->preambleInfo[preamIdx].timingAdvance = 0;
469    rachPdu->preambleInfo[preamIdx].preamblePwr = 0;
470
471    fillMsgHeader(&rachInd->header, FAPI_RACH_INDICATION, \
472          sizeof(fapi_rach_indication_t) - sizeof(fapi_msg_t));
473
474    /* Sending RACH indication to MAC */
475    DU_LOG("\nPHY STUB: Sending RACH Indication to MAC");
476    procPhyMessages(rachInd->header.msg_id, sizeof(fapi_rach_indication_t), (void *)rachInd);
477    MAC_FREE(rachInd, sizeof(fapi_rach_indication_t));
478 #endif
479    return ROK;
480 }
481
482 /*******************************************************************
483  *
484  * @brief Builds and Send the Slot Indication message to MAC
485  *
486  * @details
487  *
488  *    Function : l1BuildAndSendSlotIndication
489  *
490  *    Functionality:
491  *          -Send the Slot indication Message to MAC
492  *
493  * @params[in]   Message length
494  *               config request message pointer
495  *
496  * @return void
497  *
498  * ****************************************************************/
499 PUBLIC uint16_t l1BuildAndSendSlotIndication()
500 {
501 #ifdef INTEL_FAPI
502    fapi_slot_ind_t *slotIndMsg;
503
504    MAC_ALLOC(slotIndMsg, sizeof(fapi_slot_ind_t));
505    if(!slotIndMsg)
506    {
507       DU_LOG("\nPHY_STUB: Memory allocation failed for slot Indication Message");
508       return RFAILED;
509    }
510    else
511    {
512       memset(slotIndMsg, 0, sizeof(fapi_slot_ind_t));
513       slotIndMsg->sfn = sfnValue;
514       slotIndMsg->slot = slotValue;
515       DU_LOG("\n\nPHY_STUB: SLOT indication [%d:%d]",sfnValue,slotValue);
516
517       /* increment for the next TTI */
518       slotValue++;
519       if(sfnValue >= MAX_SFN_VALUE && slotValue > MAX_SLOT_VALUE)
520       {
521          sfnValue = 0;
522          slotValue = 0;
523       }
524       else if(slotValue > MAX_SLOT_VALUE)
525       {
526          sfnValue++;
527          slotValue = 0;
528       }
529       fillMsgHeader(&slotIndMsg->header, FAPI_SLOT_INDICATION, \
530             sizeof(fapi_slot_ind_t) - sizeof(fapi_msg_t));
531       procPhyMessages(slotIndMsg->header.msg_id, sizeof(fapi_slot_ind_t), (void*)slotIndMsg);
532       MAC_FREE(slotIndMsg, sizeof(fapi_slot_ind_t));
533    }
534 #endif
535    return ROK;
536 }
537
538 /*******************************************************************
539  *
540  * @brief Handles start request received from MAC
541  *
542  * @details
543  *
544  *    Function : l1HdlStartReq
545  *
546  *    Functionality:
547  *          -Handles start request received from MAC
548  *
549  * @params[in]   Message length
550  *               config request message pointer
551  *
552  * @return void
553  *
554  * ****************************************************************/
555
556 PUBLIC S16 l1HdlStartReq(uint32_t msgLen, void *msg)
557 {
558 #ifdef INTEL_FAPI
559    fapi_start_req_t *startReq = (fapi_start_req_t *)msg;
560
561    if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
562    {
563       l1HdlSlotIndicaion(FALSE);
564       MAC_FREE(startReq, sizeof(fapi_start_req_t));
565    }
566    else
567    {
568       DU_LOG("\nPHY_STUB: Received Start Req in PHY State %d", lwrMacCb.phyState);
569       return RFAILED;
570    }
571 #endif
572    return ROK;
573 }
574
575 /*******************************************************************
576  *
577  * @brief Handles Dl Tti request received from MAC
578  *
579  * @details
580  *
581  *    Function : l1HdlDlTtiReq
582  *
583  *    Functionality:
584  *          -Handles Dl Tti request received from MAC
585  *
586  * @params[in]   Message length
587  *               Dl Tti request message pointer
588  *
589  * @return void
590  *
591  * ****************************************************************/
592
593 PUBLIC S16 l1HdlDlTtiReq(uint16_t msgLen, void *msg)
594 {
595 #ifdef INTEL_FAPI
596    fapi_dl_tti_req_t *dlTtiReq;
597    dlTtiReq = (fapi_dl_tti_req_t *)msg;
598
599    printf("\nPHY STUB: DL TTI Request at sfn=%d slot=%d",dlTtiReq->sfn,dlTtiReq->slot);
600 #if 0
601    printf("\nPHY_STUB:  SFN     %d", dlTtiReq->sfn);
602    printf("\nPHY_STUB:  SLOT    %d", dlTtiReq->slot);
603    printf("\nPHY_STUB:  nPdus   %d", dlTtiReq->nPdus);
604    printf("\nPHY_STUB:  nGroup  %d", dlTtiReq->nGroup);
605    /* Printing SSB CONFIGURED VALUES */
606    printf("\nPHY_STUB: physCellId   %d", dlTtiReq->pdus->u.ssb_pdu.physCellId);
607    printf("\nPHY_STUB: betaPss      %d", dlTtiReq->pdus->u.ssb_pdu.betaPss);
608    printf("\nPHY_STUB: ssbBlockIndex %d",       dlTtiReq->pdus->u.ssb_pdu.ssbBlockIndex);
609    printf("\nPHY_STUB: ssbSubCarrierOffset %d", dlTtiReq->pdus->u.ssb_pdu.ssbSubCarrierOffset);
610    printf("\nPHY_STUB: ssbOffsetPointA     %d", dlTtiReq->pdus->u.ssb_pdu.ssbOffsetPointA);
611    printf("\nPHY_STUB: bchPayloadFlag      %d", dlTtiReq->pdus->u.ssb_pdu.bchPayloadFlag);
612    printf("\nPHY_STUB: bchPayload          %x", dlTtiReq->pdus->u.ssb_pdu.bchPayload);
613 #endif
614    uint8_t pduCount = 0;
615    if(dlTtiReq->nPdus == 0)
616    {
617       DU_LOG("\nPHY_STUB: No PDU in DL TTI Request");
618    }
619    for(pduCount=0; pduCount<dlTtiReq->nPdus; pduCount++)
620    {
621       if(dlTtiReq->pdus[pduCount].pduType == 3) //SSB_PDU_TYPE
622          DU_LOG("\nPHY_STUB: SSB PDU");
623       else if(dlTtiReq->pdus[pduCount].pduType == 0)
624          DU_LOG("\nPHY_STUB: PDCCH PDU");
625       else if(dlTtiReq->pdus[pduCount].pduType == 1)
626          DU_LOG("\nPHY_STUB: PDSCH PDU");
627    }
628
629    /* Free FAPI message */
630    MAC_FREE(dlTtiReq, msgLen);
631
632 #endif
633    return ROK;
634 }
635
636 /*******************************************************************
637  *
638  * @brief Handles tx_data request received from MAC
639  *
640  * @details
641  *
642  *    Function : l1HdlTxDataReq
643  *
644  *    Functionality:
645  *          -Handles tx_data request received from MAC
646  *
647  * @params[in]   Message length
648  *               tx_data request message pointer
649  *
650  * @return void
651  *
652  * ****************************************************************/
653
654 PUBLIC S16 l1HdlTxDataReq(uint16_t msgLen, void *msg)
655 {
656 #ifdef INTEL_FAPI
657    fapi_tx_data_req_t *txDataReq;
658    txDataReq = (fapi_tx_data_req_t *)msg;
659
660    DU_LOG("\nPHY STUB: TX DATA Request at sfn=%d slot=%d",txDataReq->sfn,txDataReq->slot);
661
662    MAC_FREE(txDataReq, msgLen);
663 #endif
664    return ROK;
665 }
666 /*******************************************************************
667  *
668  * @brief Handles Ul Tti request received from MAC
669  *
670  * @details
671  *
672  *    Function : l1HdlUlTtiReq
673  *
674  *    Functionality:
675  *          -Handles Ul Tti request received from MAC
676  *
677  * @params[in]   Message length
678  *               Ul Tti request message pointer
679  *
680  * @return void
681  *
682  * ****************************************************************/
683
684 PUBLIC S16 l1HdlUlTtiReq(uint16_t msgLen, void *msg)
685 {
686 #ifdef INTEL_FAPI
687    fapi_ul_tti_req_t *ulTtiReq;
688
689    DU_LOG("\nPHY STUB: Received UL TTI Request");
690
691    ulTtiReq = (fapi_ul_tti_req_t *)msg;
692    uint8_t numPdus = ulTtiReq->nPdus;
693
694    if(numPdus == 0)
695    {
696       DU_LOG("\nPHY STUB: No PDU in UL TTI");
697    }
698    while(numPdus)
699    {
700       if(ulTtiReq->pdus[numPdus-1].pduType == 0)
701       {
702          DU_LOG("\nPHY STUB: PRACH PDU");
703       }
704       if(ulTtiReq->pdus[numPdus-1].pduType == 1)
705       {
706          DU_LOG("\nPHY STUB: PUSCH PDU");                       
707          l1BuildAndSendRxDataInd(ulTtiReq->slot, ulTtiReq->sfn, \
708                ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu); 
709       }
710       if(ulTtiReq->pdus[numPdus-1].pduType == 2)
711       {
712          DU_LOG("\nPHY STUB: PUCCH PDU");
713       }
714       numPdus--;
715    }
716
717    if(rachIndSent == false && ulTtiReq->sfn == 2 && ulTtiReq->slot == 6)
718    {
719       rachIndSent = true;
720       l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn);
721    }
722
723    MAC_FREE(ulTtiReq, msgLen);
724 #endif
725    return ROK;
726 }
727
728 /*******************************************************************
729  *
730  * @brief Builds and Send the stop Indication message to MAC
731  *
732  * @details
733  *
734  *    Function : l1BuildAndSendStopInd
735  *
736  *    Functionality:
737  *          -Send the Stop indication Message to MAC
738  *
739  *
740  * @return void
741  *
742  * ****************************************************************/
743 PUBLIC uint16_t l1BuildAndSendStopInd()
744 {
745 #ifdef INTEL_FAPI
746    fapi_stop_ind_t *stopIndMsg = NULLP;
747    uint32_t msgLen = 0;
748
749    MAC_ALLOC(stopIndMsg, sizeof(fapi_stop_ind_t));
750    if(!stopIndMsg)
751    {
752       DU_LOG("\nPHY_STUB: Memory allocation failed for stop Indication Message");
753       return RFAILED;
754    }
755    else
756    {
757       fillMsgHeader(&stopIndMsg->header, FAPI_STOP_INDICATION, msgLen);
758       DU_LOG("\n\nPHY_STUB: Processing Stop indication to MAC");
759       procPhyMessages(stopIndMsg->header.msg_id,\
760             sizeof(fapi_stop_ind_t), (void*)stopIndMsg);
761       MAC_FREE(stopIndMsg, sizeof(fapi_stop_ind_t));
762    }
763 #endif
764    return ROK;
765 }
766
767 /*******************************************************************
768  *
769  * @brief Handles stop request received from MAC
770  *
771  * @details
772  *
773  *    Function : l1HdlStopReq
774  *
775  *    Functionality:
776  *          -Handles stop request received from MAC
777  *
778  * @params[in]   Message length
779  *               stop request message pointer
780  *
781  * @return void
782  *
783  * ****************************************************************/
784
785 PUBLIC S16 l1HdlStopReq(uint32_t msgLen, void *msg)
786 {
787 #ifdef INTEL_FAPI
788    fapi_stop_req_t *stopReq = (fapi_stop_req_t *)msg;
789
790    if(lwrMacCb.phyState == PHY_STATE_RUNNING)
791    {
792       l1HdlSlotIndicaion(TRUE);
793       DU_LOG("\nPHY_STUB: Slot Indication is stopped successfully");
794       l1BuildAndSendStopInd();
795       MAC_FREE(stopReq, msgLen);
796    }
797    else
798    {
799       DU_LOG("\nPHY_STUB: Received Stop Req in PHY State %d", lwrMacCb.phyState);
800       return RFAILED;
801    }
802 #endif
803    return ROK;
804 }
805
806 /*******************************************************************
807  *
808  * @brief Receives message from MAC
809  *
810  * @details
811  *
812  *    Function :  l1ProcessFapiRequest
813  *
814  *    Functionality:
815  *       - Receives message from MAC and calls handler
816  *
817  * @params[in] Message type
818  *             Message length
819  *             Message pointer
820  *
821  * @return void
822  *
823  * ****************************************************************/
824
825 void l1ProcessFapiRequest(uint8_t msgType, uint32_t msgLen, void *msg)
826 {
827    switch(msgType)
828    {
829 #ifdef INTEL_FAPI
830       case FAPI_PARAM_REQUEST:
831          l1HdlParamReq(msgLen, msg);
832          break;
833       case FAPI_CONFIG_REQUEST:
834          l1HdlConfigReq(msgLen, msg);
835          break;
836       case FAPI_START_REQUEST:
837          l1HdlStartReq(msgLen, msg);
838          break;
839       case FAPI_DL_TTI_REQUEST:
840          l1HdlDlTtiReq(msgLen, msg);
841          break;
842       case FAPI_TX_DATA_REQUEST:
843          l1HdlTxDataReq(msgLen, msg);
844          break;
845       case FAPI_UL_TTI_REQUEST:
846          l1HdlUlTtiReq(msgLen, msg);
847          break;
848       case FAPI_STOP_REQUEST:
849          l1HdlStopReq(msgLen, msg);
850          break;
851       default:
852          DU_LOG("\nPHY_STUB: Invalid message type[%x] received at PHY", msgType);
853          break;
854 #endif
855    }
856 }
857 /**********************************************************************
858   End of file
859  **********************************************************************/