1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
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 #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
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 *******************************************************************************/
19 /*This file contains stub for PHY to handle messages to/from MAC CL */
21 #include "common_def.h"
24 #include "du_app_mac_inf.h"
25 #include "mac_sch_interface.h"
27 #include "lwr_mac_fsm.h"
28 #include "lwr_mac_phy.h"
31 #include "fapi_vendor_extension.h"
33 #include "lphy_stub.h"
34 #include "lwr_mac_upr_inf.h"
35 #include "mac_utils.h"
38 /*******************************************************************
40 * @brief Builds and sends param response to MAC CL
44 * Function : l1BldAndSndParamRsp
47 * - Builds and sends param response to MAC
49 * @params[in] Config request message pointer
50 * @return ROK - success
53 * ****************************************************************/
54 S16 l1BldAndSndParamRsp(void *msg)
59 fapi_param_resp_t *fapiParamRsp;
61 MAC_ALLOC(fapiParamRsp, sizeof(fapi_param_resp_t));
64 DU_LOG("\nERROR --> PHY STUB: Memory allocation failed");
69 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_RELEASE_CAPABILITY_TAG, sizeof(uint16_t), 1, &msgLen);
70 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PHY_STATE_TAG, sizeof(uint16_t), 0, &msgLen);
71 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SKIP_BLANK_DL_CONFIG_TAG, sizeof(uint8_t), 0, &msgLen);
72 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SKIP_BLANK_UL_CONFIG_TAG, sizeof(uint8_t), 0, &msgLen);
73 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_NUM_CONFIG_TLVS_TO_REPORT_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
76 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CYCLIC_PREFIX_TAG, sizeof(uint8_t), 1, &msgLen);
77 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_SUBCARRIER_SPACING_DL_TAG, sizeof(uint8_t), 1, &msgLen);
78 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_BANDWIDTH_DL_TAG, sizeof(uint16_t), 1, &msgLen);
79 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_SUBCARRIER_SPACING_UL_TAG, sizeof(uint8_t), 0, &msgLen);
80 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_BANDWIDTH_UL_TAG, sizeof(uint16_t), 0, &msgLen);
83 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CCE_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
84 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CORESET_OUTSIDE_FIRST_3_OFDM_SYMS_OF_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
85 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRECODER_GRANULARITY_CORESET_TAG, sizeof(uint8_t), 0, &msgLen);
86 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDCCH_MU_MIMO_TAG, sizeof(uint8_t), 0, &msgLen);
87 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDCCH_PRECODER_CYCLING_TAG, sizeof(uint8_t), 0, &msgLen);
88 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDCCHS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
91 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUCCH_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
92 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PUCCHS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
95 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
96 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_ALLOCATION_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
97 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_VRB_TO_PRB_MAPPING_TAG, sizeof(uint8_t), 0, &msgLen);
98 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_CBG_TAG, sizeof(uint8_t), 0, &msgLen);
99 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_CONFIG_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
100 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_MAX_LENGTH_TAG, sizeof(uint8_t), 0, &msgLen);
101 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_ADDITIONAL_POS_TAG, sizeof(uint8_t), 0, &msgLen);
102 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDSCHS_TBS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
103 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_NUMBER_MIMO_LAYERS_PDSCH_TAG, sizeof(uint8_t), 0, &msgLen);
104 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_MAX_MODULATION_ORDER_DL_TAG, sizeof(uint8_t), 0, &msgLen);
105 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_MU_MIMO_USERS_DL_TAG, sizeof(uint8_t), 0, &msgLen);
106 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DATA_IN_DMRS_SYMBOLS_TAG, sizeof(uint8_t), 0, &msgLen);
107 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PREMPTIONSUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
108 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_NON_SLOT_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
111 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_UCI_MUX_ULSCH_IN_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
112 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_UCI_ONLY_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
113 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_FREQUENCY_HOPPING_TAG, sizeof(uint8_t), 0, &msgLen);
114 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_CONFIG_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
115 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_MAX_LEN_TAG, sizeof(uint8_t), 0, &msgLen);
116 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_ADDITIONAL_POS_TAG, sizeof(uint8_t), 0, &msgLen);
117 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_CBG_TAG, sizeof(uint8_t), 0, &msgLen);
118 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
119 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_ALLOCATION_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
120 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_VRB_TO_PRB_MAPPING_TAG, sizeof(uint8_t), 0, &msgLen);
121 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_MAX_PTRS_PORTS_TAG, sizeof(uint8_t), 0, &msgLen);
122 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDUSCHS_TBS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
123 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_NUMBER_MIMO_LAYERS_NON_CB_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
124 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_MODULATION_ORDER_UL_TAG, sizeof(uint8_t), 0, &msgLen);
125 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_MU_MIMO_USERS_UL_TAG, sizeof(uint8_t), 0, &msgLen);
126 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_DFTS_OFDM_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
127 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_AGGREGATION_FACTOR_TAG, sizeof(uint8_t), 0, &msgLen);
130 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_LONG_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
131 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_SHORT_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
132 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_RESTRICTED_SETS_TAG, sizeof(uint8_t), 0, &msgLen);
133 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PRACH_FD_OCCASIONS_IN_A_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
135 /* MEASUREMENT TAG */
136 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_RSSI_MEASUREMENT_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
138 fapiParamRsp->number_of_tlvs = index;
139 msgLen += sizeof(fapi_param_resp_t) - sizeof(fapi_msg_t);
140 fillMsgHeader(&fapiParamRsp->header, FAPI_PARAM_RESPONSE, msgLen);
141 fapiParamRsp->error_code = MSG_OK;
143 DU_LOG("\nINFO --> PHY_STUB: Sending Param Request to Lower Mac");
144 procPhyMessages(fapiParamRsp->header.msg_id, sizeof(fapi_param_resp_t), (void *)fapiParamRsp);
145 MAC_FREE(fapiParamRsp, sizeof(fapi_param_resp_t));
150 /*******************************************************************
152 * @brief Builds and sends config response to lower mac
156 * Function : l1BldAndSndConfigRsp
159 * - Builds and sends config response to MAC
161 * @params[in] Config request message pointer
162 * @return ROK - success
165 * ****************************************************************/
167 S16 l1BldAndSndConfigRsp(void *msg)
171 fapi_config_resp_t *fapiConfigRsp;
173 MAC_ALLOC(fapiConfigRsp, sizeof(fapi_config_resp_t));
176 DU_LOG("\nERROR --> PHY STUB: Memory allocation failed");
179 memset(fapiConfigRsp, 0, sizeof(fapi_config_resp_t));
180 fapiConfigRsp->number_of_invalid_tlvs = NULLP;
181 fapiConfigRsp->number_of_inv_tlvs_idle_only = NULLP;
182 fapiConfigRsp->number_of_missing_tlvs = NULLP;
183 fapiConfigRsp->error_code = MSG_OK;
184 msgLen = sizeof(fapi_config_resp_t) - sizeof(fapi_msg_t);
185 fillMsgHeader(&fapiConfigRsp->header, FAPI_CONFIG_RESPONSE, msgLen);
187 DU_LOG("\nINFO --> PHY_STUB: Sending Config Response to Lower Mac");
189 procPhyMessages(fapiConfigRsp->header.msg_id, \
190 sizeof(fapi_config_resp_t), (void *)fapiConfigRsp);
191 MAC_FREE(fapiConfigRsp, sizeof(fapi_config_resp_t));
195 /*******************************************************************
197 * @brief Handles param request received from MAC
201 * Function : l1HdlParamReq
204 * -Handles param request received from MAC
206 * @params[in] Message length
207 * Param request message pointer
211 * ****************************************************************/
213 void l1HdlParamReq(uint32_t msgLen, void *msg)
216 DU_LOG("\nINFO --> PHY_STUB: Received Param Request in PHY");
218 /* Build and send PARAM RESPONSE */
219 if(l1BldAndSndParamRsp(msg)!= ROK)
221 DU_LOG("\nERROR --> PHY_STUB: Failed Sending Param Response");
223 MAC_FREE(msg, sizeof(fapi_param_req_t));
227 /*******************************************************************
229 * @brief Handles config request received from MAC
233 * Function : l1HdlConfigReq
236 * -Handles config request received from MAC
238 * @params[in] Message length
239 * config request message pointer
243 * ****************************************************************/
245 void l1HdlConfigReq(uint32_t msgLen, void *msg)
248 p_fapi_api_queue_elem_t configReqElem = (p_fapi_api_queue_elem_t)msg;
249 fapi_config_req_t *configReq = (fapi_config_req_t *)(configReqElem +1);
251 DU_LOG("\nINFO --> PHY_STUB: Received Config Request in PHY");
253 /* Handling CONFIG RESPONSE */
254 if(l1BldAndSndConfigRsp(configReq)!= ROK)
256 DU_LOG("\nERROR --> PHY_STUB: Failed Sending config Response");
259 MAC_FREE(msg, msgLen);
264 /*******************************************************************
266 * @brief Build and Send CRC Indication
270 * Function : l1BuildAndSendCrcInd
273 * Build and Send CRC Indication
277 * @return ROK - success
280 * ****************************************************************/
281 uint16_t l1BuildAndSendCrcInd(uint16_t slot, uint16_t sfn)
285 fapi_crc_ind_t *crcInd;
287 MAC_ALLOC(crcInd, sizeof(fapi_crc_ind_t));
290 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for CRC Indication Message");
293 memset(crcInd, 0, sizeof(fapi_crc_ind_t));
295 /* TODO: Fill the required values. As of now only 1 CRC status PASS is filled */
300 crcInd->crc[idx].handle = 0;
301 crcInd->crc[idx].rnti = 0;
302 crcInd->crc[idx].harqId = 0;
303 crcInd->crc[idx].tbCrcStatus = 0;
304 crcInd->crc[idx].numCb = 1;
305 crcInd->crc[idx].cbCrcStatus[0] = 0;
306 crcInd->crc[idx].ul_cqi = 0;
307 crcInd->crc[idx].timingAdvance = 0;
308 crcInd->crc[idx].rssi = 0;
310 fillMsgHeader(&crcInd->header, FAPI_CRC_INDICATION, \
311 sizeof(fapi_crc_ind_t) - sizeof(fapi_msg_t));
313 /* Sending RACH indication to MAC */
314 DU_LOG("\nINFO --> PHY STUB: Sending CRC Indication to MAC");
315 procPhyMessages(crcInd->header.msg_id, sizeof(fapi_crc_ind_t), (void *)crcInd);
316 MAC_FREE(crcInd, sizeof(fapi_crc_ind_t));
319 } /* l1BuildAndSendCrcInd */
322 /*******************************************************************
324 * @brief Build and send Rx data indication
328 * Function : l1BuildAndSendRxDataInd
331 * Build and send Rx data indication
335 * @return ROK - success
338 * ****************************************************************/
339 uint16_t l1BuildAndSendRxDataInd(uint16_t slot, uint16_t sfn, fapi_ul_pusch_pdu_t puschPdu)
342 fapi_rx_data_indication_t *rxDataInd =NULLP;
343 fapi_pdu_ind_info_t *pduInfo =NULLP;
344 uint8_t *pdu = NULLP;
345 uint16_t byteIdx = 0;
352 type = MSG_TYPE_MSG3;
355 else if(!msg5ShortBsrSent)
357 msg5ShortBsrSent = true;
358 type = MSG_TYPE_SHORT_BSR;
363 type = MSG_TYPE_MSG5;
365 else if(!msgRegistrationComp)
367 msgRegistrationComp = true;
368 type = MSG_TYPE_REGISTRATION_COMPLETE;
370 else if(!msgSecurityModeComp)
372 msgSecurityModeComp = true;
373 type = MSG_TYPE_SECURITY_MODE_COMPLETE;
375 else if(!msgRrcReconfiguration)
377 msgRrcReconfiguration = true;
378 type = MSG_TYPE_RRC_RECONFIG_COMPLETE;
383 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
386 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
389 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
391 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
392 rxDataInd->sfn = sfn;
393 rxDataInd->slot = slot;
394 rxDataInd->numPdus = 1;
396 pduInfo = &rxDataInd->pdus[idx];
397 pduInfo->handle = puschPdu.handle;
398 pduInfo->rnti = puschPdu.rnti;
399 pduInfo->harqId = puschPdu.puschData.harqProcessId;
400 pduInfo->pdu_length = puschPdu.puschData.tbSize ;
402 pduInfo->timingAdvance = 0;
405 /* Filling pdu with random values for testing */
406 pduInfo->pduData = NULL;
407 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
408 if(!pduInfo->pduData)
410 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
413 memset(pduInfo->pduData, 0, pduInfo->pdu_length);
415 pdu = (uint8_t *)pduInfo->pduData;
421 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG3 PDU ");
422 /* For Initial RRC setup Request,
423 MAC subheader format is R/R/LCId (1byte)
425 From 38.321 section 6.1.1
428 /* Hardcoding MAC PDU */
434 pdu[byteIdx++] = 103;
438 case MSG_TYPE_SHORT_BSR:
440 DU_LOG("\nDEBUG --> PHY_STUB: Forming SHORT BSR PDU ");
442 uint8_t bufferSizeIdx = 6;
445 MAC subheader format is R/R/LcId (1Byte)
447 From 38.321 section 6.1.1
449 pdu[byteIdx++] = 61; // LCID
450 pdu[byteIdx++] = (lcgId << 5) | bufferSizeIdx;
457 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG5 PDU");
458 uint8_t msg5PduLen = 33;
459 /* For RRC setup complete
460 MAC subheader format is R/F/LCId/L (2/3 bytes)
462 L is length of PDU i.e 6bytes here
463 From 38.321 section 6.1.1
465 uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
466 64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
467 184, 56, 0, 0, 0, 0, 0};
469 msg5PduLen += 2; /* 2bytes of header */
470 memcpy(pdu, &msg5, msg5PduLen);
471 byteIdx += msg5PduLen; /* 2 bytes of header */
475 case MSG_TYPE_SECURITY_MODE_COMPLETE:
477 DU_LOG("\nDEBUG --> PHY_STUB: Forming SECURITY MODE COMPLETE PDU");
479 /* For security mode complete where RRC Container is dummy
480 MAC subheader format is R/F/LCId/L (2/3 bytes)
482 L is length of PDU i.e 6bytes here
483 From 38.321 section 6.1.1
485 uint8_t msg[] = {1, pduLen, 0, 3, 0x2a, 0x40, 0, 0, 0, 0, 0, 0, 0, 0};
487 pduLen += 2; /* 2bytes of header */
488 memcpy(pdu, &msg, pduLen);
489 byteIdx += pduLen; /* 2 bytes of header */
492 case MSG_TYPE_REGISTRATION_COMPLETE:
495 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC REGISTRATION COMPLETE PDU");
497 /* For rrc reconfig complete where RRC Container is dummy
498 MAC subheader format is R/F/LCId/L (2/3 bytes)
500 L is length of PDU i.e 6bytes here
501 From 38.321 section 6.1.1
503 uint8_t msg[] = {1, pduLen, 0, 0x04, 0x3a, 0x81, 0xbf, 0, 0x21, 0x80, 0, \
506 pduLen += 2; /* 2bytes of header */
507 memcpy(pdu, &msg, pduLen);
508 byteIdx += pduLen; /* 2 bytes of header */
511 case MSG_TYPE_RRC_RECONFIG_COMPLETE:
513 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC RECONFIGURATION COMPLETE PDU");
515 /* For rrc reconfig complete where RRC Container is dummy
516 MAC subheader format is R/F/LCId/L (2/3 bytes)
518 L is length of PDU i.e 6bytes here
519 From 38.321 section 6.1.1
521 uint8_t msg[] = {1, pduLen, 0, 6, 8, 64, 0, 0, 0, 0, \
524 pduLen += 2; /* 2bytes of header */
525 memcpy(pdu, &msg, pduLen);
526 byteIdx += pduLen; /* 2 bytes of header */
533 } /* End of switch(type) */
534 /* Filling MAC SDU for Padding bytes*/
535 if(byteIdx < pduInfo->pdu_length)
538 MAC subheader format is R/R/LCId (1byte)
539 LCId is 63 for padding
540 From 38.321 section 6.1.1
544 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
547 msgLen += pduInfo->pdu_length;
549 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
551 /* Sending Rx data indication to MAC */
552 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
553 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
555 if(pduInfo->pdu_length)
556 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
557 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
562 /*******************************************************************
564 * @brief Builds and Sends RACH indication to MAC
568 * Function : l1BuildAndSendRachInd
571 * Builds and Sends RACH indication to MAC
573 * @params[in] SFN value
575 * @return ROK - success
578 * ****************************************************************/
579 uint16_t l1BuildAndSendRachInd(uint16_t slot, uint16_t sfn)
582 uint8_t rachPduIdx = 0;
583 uint8_t preamIdx = 0;
584 fapi_rach_pdu_t *rachPdu;
585 fapi_rach_indication_t *rachInd;
587 /* Building RACH indication */
588 MAC_ALLOC(rachInd, sizeof(fapi_rach_indication_t));
591 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rach Indication Message");
594 memset(rachInd, 0, sizeof(fapi_rach_indication_t));
596 rachInd->slot = slot;
597 rachInd->numPdus = 1;
599 rachPdu = &rachInd->rachPdu[rachPduIdx];
600 rachPdu->phyCellId = NR_PCI;
601 rachPdu->symbolIndex = 0;
602 rachPdu->slotIndex = slot;
603 rachPdu->freqIndex = 0;
604 rachPdu->avgRssi = 0;
606 rachPdu->numPreamble = 1;
608 rachPdu->preambleInfo[preamIdx].preambleIndex = 3;
609 rachPdu->preambleInfo[preamIdx].timingAdvance = 0;
610 rachPdu->preambleInfo[preamIdx].preamblePwr = 0;
612 fillMsgHeader(&rachInd->header, FAPI_RACH_INDICATION, \
613 sizeof(fapi_rach_indication_t) - sizeof(fapi_msg_t));
615 /* Sending RACH indication to MAC */
616 DU_LOG("\nINFO --> PHY STUB: Sending RACH Indication to MAC");
617 procPhyMessages(rachInd->header.msg_id, sizeof(fapi_rach_indication_t), (void *)rachInd);
618 MAC_FREE(rachInd, sizeof(fapi_rach_indication_t));
623 /*******************************************************************
625 * @brief Builds and Send the Slot Indication message to MAC
629 * Function : l1BuildAndSendSlotIndication
632 * -Send the Slot indication Message to MAC
634 * @params[in] Message length
635 * config request message pointer
639 * ****************************************************************/
640 uint16_t l1BuildAndSendSlotIndication()
643 fapi_slot_ind_t *slotIndMsg;
645 MAC_ALLOC(slotIndMsg, sizeof(fapi_slot_ind_t));
648 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for slot Indication Message");
653 memset(slotIndMsg, 0, sizeof(fapi_slot_ind_t));
654 slotIndMsg->sfn = sfnValue;
655 slotIndMsg->slot = slotValue;
657 #ifdef ODU_SLOT_IND_DEBUG_LOG
658 DU_LOG("\n\nDEBUG --> PHY_STUB: SLOT indication [%d:%d]",sfnValue,slotValue);
660 /* increment for the next TTI */
662 if(sfnValue >= MAX_SFN_VALUE && slotValue > MAX_SLOT_VALUE)
667 else if(slotValue > MAX_SLOT_VALUE)
672 fillMsgHeader(&slotIndMsg->header, FAPI_SLOT_INDICATION, \
673 sizeof(fapi_slot_ind_t) - sizeof(fapi_msg_t));
674 procPhyMessages(slotIndMsg->header.msg_id, sizeof(fapi_slot_ind_t), (void*)slotIndMsg);
675 MAC_FREE(slotIndMsg, sizeof(fapi_slot_ind_t));
681 /*******************************************************************
683 * @brief Handles start request received from MAC
687 * Function : l1HdlStartReq
690 * -Handles start request received from MAC
692 * @params[in] Message length
693 * config request message pointer
697 * ****************************************************************/
699 S16 l1HdlStartReq(uint32_t msgLen, void *msg)
702 if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
704 l1HdlSlotIndicaion(FALSE);
705 l1StartConsoleHandler();
706 MAC_FREE(msg, msgLen);
710 DU_LOG("\nINFO --> PHY_STUB: Received Start Req in PHY State %d", lwrMacCb.phyState);
711 MAC_FREE(msg, msgLen);
718 /*******************************************************************
720 * @brief Handles Dl Tti request received from MAC
724 * Function : l1HdlDlTtiReq
727 * -Handles Dl Tti request received from MAC
729 * @params[in] Message length
730 * Dl Tti request message pointer
734 * ****************************************************************/
736 S16 l1HdlDlTtiReq(uint16_t msgLen, void *msg)
739 p_fapi_api_queue_elem_t dlTtiElem = (p_fapi_api_queue_elem_t)msg;
740 fapi_dl_tti_req_t *dlTtiReq = (fapi_dl_tti_req_t *)(dlTtiElem +1);
742 uint8_t pduCount = 0;
744 #ifdef ODU_SLOT_IND_DEBUG_LOG
745 if(dlTtiReq->nPdus == 0)
747 DU_LOG("\nDEBUG --> PHY_STUB: No PDU in DL TTI Request");
751 DU_LOG("\nDEBUG --> PHY STUB: DL TTI Request at sfn=%d slot=%d",dlTtiReq->sfn,dlTtiReq->slot);
755 for(pduCount=0; pduCount<dlTtiReq->nPdus; pduCount++)
757 if(dlTtiReq->pdus[pduCount].pduType == 3) //SSB_PDU_TYPE
759 DU_LOG("\nINFO --> PHY_STUB: SSB PDU");
761 else if(dlTtiReq->pdus[pduCount].pduType == 0)
763 DU_LOG("\nINFO --> PHY_STUB: PDCCH PDU");
764 if(dlTtiReq->pdus[pduCount].pdu.pdcch_pdu.\
770 else if(dlTtiReq->pdus[pduCount].pduType == 1)
772 DU_LOG("\nINFO --> PHY_STUB: PDSCH PDU");
776 /* Free FAPI message */
777 MAC_FREE(msg, msgLen);
782 /*******************************************************************
784 * @brief Handles tx_data request received from MAC
788 * Function : l1HdlTxDataReq
791 * -Handles tx_data request received from MAC
793 * @params[in] Message length
794 * tx_data request message pointer
798 * ****************************************************************/
800 S16 l1HdlTxDataReq(uint16_t msgLen, void *msg)
803 p_fapi_api_queue_elem_t txDataElem = (p_fapi_api_queue_elem_t)msg;
804 fapi_tx_data_req_t *txDataReq = (fapi_tx_data_req_t *)(txDataElem +1);
806 DU_LOG("\nINFO --> PHY STUB: TX DATA Request at sfn=%d slot=%d",txDataReq->sfn,txDataReq->slot);
809 DU_LOG("\nINFO --> PHY_STUB: TxDataPdu for DED MSG sent");
812 MAC_FREE(msg, msgLen);
818 /*******************************************************************
820 * @brief Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
824 * Function : fillPucchF0F1PduInfo
827 * Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
829 * @params[in] fapi_uci_o_pucch_f0f1_t *
831 * @return ROK - success
834 * ****************************************************************/
835 uint8_t fillPucchF0F1PduInfo(fapi_uci_o_pucch_f0f1_t *pduInfo, fapi_ul_pucch_pdu_t pucchPdu)
839 pduInfo->handle = pucchPdu.handle;
840 pduInfo->pduBitmap = 1; //hardcoded for SR
841 pduInfo->pucchFormat = pucchPdu.formatType;
843 pduInfo->rnti = pucchPdu.rnti;
844 pduInfo->timingAdvance = 0;
846 if(pduInfo->pduBitmap & SR_PDU_BITMASK)
848 pduInfo->srInfo.srIndication = SR_DETECTED;
849 pduInfo->srInfo.srConfidenceLevel = CONFDC_LEVEL_GOOD;
851 if(pduInfo->pduBitmap & HARQ_PDU_BITMASK)
853 pduInfo->harqInfo.numHarq++;
854 pduInfo->harqInfo.harqConfidenceLevel = CONFDC_LEVEL_GOOD;
855 for(idx = 0; idx < pduInfo->harqInfo.numHarq; idx++)
857 pduInfo->harqInfo.harqValue[idx] = HARQ_PASS;
862 /*******************************************************************
864 * @brief Fills UCI Pdu Information
868 * Function : fillUciPduInfo
871 * Fills UCI Pdu Information
873 * @params[in] Pointer to uciPdu
875 * @return ROK - success
878 * ****************************************************************/
879 uint8_t fillUciPduInfo(fapi_uci_pdu_info_t *uciPdu, fapi_ul_pucch_pdu_t pucchPdu)
883 /*TODO: The pduType is hardcoded here to support
884 UCI Ind for PUCCH forat0/format1. This is to be
885 modified when we get SR form UE */
886 uciPdu->pduType = UCI_IND_PUCCH_F0F1;
887 switch(uciPdu->pduType)
891 case UCI_IND_PUCCH_F0F1:
893 fapi_uci_o_pucch_f0f1_t *pduInfo = NULLP;
895 pduInfo = &uciPdu->uci.uciPucchF0F1;
896 ret = fillPucchF0F1PduInfo(pduInfo, pucchPdu);
897 uciPdu->pduSize = sizeof(fapi_uci_o_pucch_f0f1_t);
900 case UCI_IND_PUCCH_F2F3F4:
903 DU_LOG("\nERROR --> PHY_STUB: Invalid Pdu Type %d", uciPdu->pduType);
909 /*******************************************************************
911 * @brief Build and send Uci indication
915 * Function : l1BuildAndSendUciInd
918 * Build and send Uci indication
922 * @return ROK - success
925 * ****************************************************************/
926 uint8_t l1BuildAndSendUciInd(uint16_t slot, uint16_t sfn, fapi_ul_pucch_pdu_t pucchPdu)
929 uint8_t nUciPdus = 0;
932 fapi_uci_indication_t *uciInd = NULLP;
934 MAC_ALLOC(uciInd, sizeof(fapi_uci_indication_t));
937 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for UCI Indication");
940 memset(uciInd, 0, sizeof(fapi_uci_indication_t));
943 uciInd->numUcis = 1; //consdering the UCI Ind for SR
944 nUciPdus = uciInd->numUcis;
947 ret = fillUciPduInfo(&uciInd->uciPdu[uciIdx], pucchPdu);
953 msgLen = sizeof(fapi_uci_indication_t)- sizeof(fapi_msg_t);
954 fillMsgHeader(&uciInd->header, FAPI_UCI_INDICATION, msgLen);
956 /* Sending UCI indication to MAC */
957 DU_LOG("\nINFO --> PHY STUB: Sending UCI Indication to MAC");
958 procPhyMessages(uciInd->header.msg_id, sizeof(fapi_uci_indication_t), (void *)uciInd);
960 MAC_FREE(uciInd, sizeof(fapi_uci_indication_t));
965 /*******************************************************************
967 * @brief Handles Ul Tti request received from MAC
971 * Function : l1HdlUlTtiReq
974 * -Handles Ul Tti request received from MAC
976 * @params[in] Message length
977 * Ul Tti request message pointer
981 * ****************************************************************/
983 S16 l1HdlUlTtiReq(uint16_t msgLen, void *msg)
986 p_fapi_api_queue_elem_t ulTtiElem = (p_fapi_api_queue_elem_t)msg;
987 fapi_ul_tti_req_t *ulTtiReq = (fapi_ul_tti_req_t *)(ulTtiElem +1);
988 uint8_t numPdus = ulTtiReq->nPdus;
990 #ifdef ODU_SLOT_IND_DEBUG_LOG
993 DU_LOG("\nINFO --> PHY STUB: No PDU received in UL TTI Req");
997 DU_LOG("\nINFO --> PHY STUB: Received UL TTI Request");
1003 if(ulTtiReq->pdus[numPdus-1].pduType == 0)
1005 DU_LOG("\nINFO --> PHY STUB: PRACH PDU");
1007 if(ulTtiReq->pdus[numPdus-1].pduType == 1)
1009 DU_LOG("\nINFO --> PHY STUB: PUSCH PDU");
1010 l1BuildAndSendRxDataInd(ulTtiReq->slot, ulTtiReq->sfn, \
1011 ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu);
1013 if(ulTtiReq->pdus[numPdus-1].pduType == 2)
1015 DU_LOG("\nINFO --> PHY STUB: PUCCH PDU");
1016 fapi_ul_tti_req_t ulTtiSlotInd;
1017 memset(&ulTtiSlotInd, 0, sizeof(fapi_ul_tti_req_t));
1018 ulTtiSlotInd.slot = ulTtiReq->slot;
1019 ulTtiSlotInd.sfn = ulTtiReq->sfn;
1020 ADD_DELTA_TO_TIME(ulTtiSlotInd, ulTtiSlotInd, SLOT_DELAY);
1021 l1BuildAndSendUciInd(ulTtiSlotInd.slot, ulTtiSlotInd.sfn, \
1022 ulTtiReq->pdus[numPdus-1].pdu.pucch_pdu);
1027 if(rachIndSent == false && ulTtiReq->sfn == 16 && ulTtiReq->slot == 6)
1030 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn);
1033 MAC_FREE(msg, msgLen);
1038 /*******************************************************************
1040 * @brief Builds and Send the stop Indication message to MAC
1044 * Function : l1BuildAndSendStopInd
1047 * -Send the Stop indication Message to MAC
1052 * ****************************************************************/
1053 uint16_t l1BuildAndSendStopInd()
1056 fapi_stop_ind_t *stopIndMsg = NULLP;
1057 uint32_t msgLen = 0;
1059 MAC_ALLOC(stopIndMsg, sizeof(fapi_stop_ind_t));
1062 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for stop Indication Message");
1067 fillMsgHeader(&stopIndMsg->header, FAPI_STOP_INDICATION, msgLen);
1068 DU_LOG("\n\nINFO --> PHY_STUB: Processing Stop indication to MAC");
1069 procPhyMessages(stopIndMsg->header.msg_id,\
1070 sizeof(fapi_stop_ind_t), (void*)stopIndMsg);
1071 MAC_FREE(stopIndMsg, sizeof(fapi_stop_ind_t));
1077 /*******************************************************************
1079 * @brief Handles stop request received from MAC
1083 * Function : l1HdlStopReq
1086 * -Handles stop request received from MAC
1088 * @params[in] Message length
1089 * stop request message pointer
1093 * ****************************************************************/
1095 S16 l1HdlStopReq(uint32_t msgLen, void *msg)
1098 if(lwrMacCb.phyState == PHY_STATE_RUNNING)
1100 l1HdlSlotIndicaion(TRUE);
1101 DU_LOG("\nINFO --> PHY_STUB: Slot Indication is stopped successfully");
1102 l1BuildAndSendStopInd();
1103 MAC_FREE(msg, msgLen);
1107 DU_LOG("\nINFO --> PHY_STUB: Received Stop Req in PHY State %d", lwrMacCb.phyState);
1108 MAC_FREE(msg, msgLen);
1115 /*******************************************************************
1117 * @brief Build And Send Rx Data Ind for Msg5
1121 * Function : l1BuildAndSendMsg5
1123 * Functionality: Build And Send Rx Data Ind for Msg5
1127 * @return ROK - success
1130 * ****************************************************************/
1131 uint8_t l1BuildAndSendMsg5(uint16_t sfn, uint16_t slot)
1135 fapi_rx_data_indication_t *rxDataInd;
1136 fapi_pdu_ind_info_t *pduInfo;
1138 uint16_t byteIdx = 0;
1139 uint32_t msgLen = 0;
1141 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1144 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication for msg5");
1147 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1149 /* TODO: Fill the required values */
1150 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1151 rxDataInd->sfn = sfn;
1152 rxDataInd->slot = slot;
1153 rxDataInd->numPdus = 1;
1155 pduInfo = &rxDataInd->pdus[idx];
1156 pduInfo->handle = 100;
1157 pduInfo->rnti = 100;
1158 pduInfo->harqId = 1;
1159 pduInfo->pdu_length = 25;
1160 pduInfo->ul_cqi = 0;
1161 pduInfo->timingAdvance = 0;
1164 /* Filling pdu with random values for testing */
1165 pduInfo->pduData = NULL;
1166 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1167 if(!pduInfo->pduData)
1169 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1174 pdu = (uint8_t *)pduInfo->pduData;
1176 uint8_t msg5PduLen = 33;
1177 /* For RRC setup complete
1178 MAC subheader format is R/F/LCId/L (2/3 bytes)
1180 L is length of PDU i.e 6bytes here
1181 From 38.321 section 6.1.1
1183 uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
1184 64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
1185 184, 56, 0, 0, 0, 0, 0};
1187 msg5PduLen += 2; /* 2bytes of header */
1188 memcpy(pdu, &msg5, msg5PduLen);
1189 byteIdx += msg5PduLen; /* 2 bytes of header */
1191 /* Filling MAC SDU for Padding bytes*/
1192 if(byteIdx < pduInfo->pdu_length)
1195 MAC subheader format is R/R/LCId (1byte)
1196 LCId is 63 for padding
1197 From 38.321 section 6.1.1
1199 pdu[byteIdx++] = 63;
1201 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1204 msgLen += pduInfo->pdu_length;
1206 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1208 /* Sending Rx data indication to MAC */
1209 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
1210 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1212 if(pduInfo->pdu_length)
1213 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1214 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1219 /*******************************************************************
1221 * @brief Handles Ul Dci request received from MAC
1225 * Function : l1HdlUlDciReq
1228 * -Handles Ul Dci request received from MAC
1230 * @params[in] Message length
1231 * Ul Dci request message pointer
1235 * ****************************************************************/
1237 S16 l1HdlUlDciReq(uint16_t msgLen, void *msg)
1240 p_fapi_api_queue_elem_t ulDciElem = (p_fapi_api_queue_elem_t)msg;
1241 fapi_ul_dci_req_t *ulDciReq = (fapi_ul_dci_req_t *)(ulDciElem +1);
1242 uint8_t numPdus = ulDciReq->numPdus;
1246 if(ulDciReq->pdus[numPdus-1].pduType == 0)
1248 DU_LOG("\nINFO --> PHY STUB: Received UL DCI Request for PDCCH PDU");
1249 //l1BuildAndSendMsg5(ulDciReq->sfn, ulDciReq->slot);
1255 MAC_FREE(msg, msgLen);
1260 /*******************************************************************
1262 * @brief Send UL user data to DU
1266 * Function : l1SendUlUserData
1268 * Functionality: Send UL user data to DU
1271 * @return ROK - success
1274 * ****************************************************************/
1275 uint8_t l1SendUlUserData()
1278 fapi_rx_data_indication_t *rxDataInd;
1279 fapi_pdu_ind_info_t *pduInfo;
1280 uint8_t *pdu = NULLP;
1281 uint16_t byteIdx = 0;
1282 uint32_t msgLen = 0;
1285 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1288 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1291 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1293 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1295 rxDataInd->slot = 0;
1296 rxDataInd->numPdus = 1;
1298 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1299 pduInfo = &rxDataInd->pdus[idx];
1300 pduInfo->handle = 100;
1301 pduInfo->rnti = 100;
1302 pduInfo->harqId = 1;
1303 /* Since user data size = 50bytes and 2 bytes of MAC header and 3 byte of RLC header,
1304 * setting tbsize = 56 from Table 5.1.3.2-1 spec 38.214 */
1305 pduInfo->pdu_length = 56;
1306 pduInfo->ul_cqi = 0;
1307 pduInfo->timingAdvance = 0;
1310 /* Filling pdu with random values for testing */
1311 pduInfo->pduData = NULL;
1312 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1313 if(!pduInfo->pduData)
1315 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1320 pdu = (uint8_t *)pduInfo->pduData;
1324 MAC subheader format is R/F/LCId/L (2/3 bytes)
1326 L is length of PDU i.e 50 bytes
1327 From 38.321 section 6.1.1
1328 From 38.322 section 6.2.2.4, 6.2.2.3 for AM, UM Header
1331 /* Below ulMsg supports 12bit SN for UM mode */
1333 uint8_t ulMsg[] = {4, msgLen, 0, 0, 0, 0, 0, 50, 0, 0, 0, 0, 0, 1, 0, 0, 192, 168, 130, 81, 192, 168, 130, 82, 84, 104,
1334 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};
1335 msgLen += 2; /* 2bytes of header */
1336 memcpy(pdu, &ulMsg, msgLen);
1337 byteIdx += msgLen; /* 2 bytes of header */
1339 /* Filling MAC SDU for Padding bytes*/
1340 if(byteIdx < pduInfo->pdu_length)
1343 MAC subheader format is R/R/LCId (1byte)
1344 LCId is 63 for padding
1345 From 38.321 section 6.1.1
1347 pdu[byteIdx++] = 63;
1349 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1352 msgLen += pduInfo->pdu_length;
1354 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1356 /* Send Message to peer */
1359 DU_LOG("\nDEBUG --> PHY STUB : Sending UL User Data[%d] at sfn %d slot %d", cnt+1, sfnValue, slotValue);
1360 /* Sending Rx data indication to MAC */
1361 rxDataInd->sfn = sfnValue;
1362 rxDataInd->slot = slotValue;
1363 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1367 if(pduInfo->pdu_length)
1368 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1369 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1373 /*******************************************************************
1375 * @brief Sends RLC Status PDU to DU
1379 * Function : l1SendStatusPdu
1381 * Functionality: Send RLC Status PDU to DU
1384 * @return ROK - success
1387 * ****************************************************************/
1388 uint8_t l1SendStatusPdu()
1390 fapi_rx_data_indication_t *rxDataInd;
1391 fapi_pdu_ind_info_t *pduInfo;
1392 uint8_t *pdu = NULLP;
1393 uint16_t byteIdx = 0;
1394 uint32_t msgLen = 0;
1397 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1400 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1403 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1405 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1407 rxDataInd->slot = 0;
1408 rxDataInd->numPdus = 1;
1410 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1411 pduInfo = &rxDataInd->pdus[idx];
1412 pduInfo->handle = 100;
1413 pduInfo->rnti = 100;
1414 pduInfo->harqId = 1;
1415 /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1416 * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1417 pduInfo->pdu_length = 24;
1418 pduInfo->ul_cqi = 0;
1419 pduInfo->timingAdvance = 0;
1422 /* Filling pdu with random values for testing */
1423 pduInfo->pduData = NULL;
1424 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1425 if(!pduInfo->pduData)
1427 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1432 pdu = (uint8_t *)pduInfo->pduData;
1435 /* For RLC Status PDU
1436 MAC subheader format is R/F/LCId/L (2/3 bytes)
1438 L is length of Status PDU i.e 3 bytes
1439 From 38.321 section 6.1.1
1441 uint8_t statusPdu[] = {4, msgLen, 0, 0, 0};
1442 msgLen += 2; /* 2bytes of header */
1443 memcpy(pdu, &statusPdu, msgLen);
1444 byteIdx += msgLen; /* 2 bytes of header */
1447 /* Filling MAC SDU for Padding bytes*/
1448 if(byteIdx < pduInfo->pdu_length)
1451 MAC subheader format is R/R/LCId (1byte)
1452 LCId is 63 for padding
1453 From 38.321 section 6.1.1
1455 pdu[byteIdx++] = 63;
1457 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1460 msgLen += pduInfo->pdu_length;
1462 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1464 /* Send Message to peer */
1465 DU_LOG("\nDEBUG --> PHY STUB : Sending RLC status pdu at sfn %d slot %d", sfnValue, slotValue);
1466 /* Sending Rx data indication to MAC */
1467 rxDataInd->sfn = sfnValue;
1468 rxDataInd->slot = slotValue;
1469 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1471 if(pduInfo->pdu_length)
1472 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1473 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1477 /*******************************************************************
1479 * @brief Receives message from MAC
1483 * Function : l1ProcessFapiRequest
1486 * - Receives message from MAC and calls handler
1488 * @params[in] Message type
1494 * ****************************************************************/
1496 void l1ProcessFapiRequest(uint8_t msgType, uint32_t msgLen, void *msg)
1501 case FAPI_PARAM_REQUEST:
1502 l1HdlParamReq(msgLen, msg);
1504 case FAPI_CONFIG_REQUEST:
1505 l1HdlConfigReq(msgLen, msg);
1507 case FAPI_START_REQUEST:
1508 l1HdlStartReq(msgLen, msg);
1510 case FAPI_DL_TTI_REQUEST:
1511 l1HdlDlTtiReq(msgLen, msg);
1513 case FAPI_TX_DATA_REQUEST:
1514 l1HdlTxDataReq(msgLen, msg);
1516 case FAPI_UL_TTI_REQUEST:
1517 l1HdlUlTtiReq(msgLen, msg);
1519 case FAPI_STOP_REQUEST:
1520 l1HdlStopReq(msgLen, msg);
1522 case FAPI_UL_DCI_REQUEST:
1523 l1HdlUlDciReq(msgLen, msg);
1526 DU_LOG("\nERROR --> PHY_STUB: Invalid message type[%x] received at PHY", msgType);
1531 /**********************************************************************
1533 **********************************************************************/