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