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_phy.h"
31 #include "lphy_stub.h"
32 #include "lwr_mac_upr_inf.h"
33 #include "mac_utils.h"
36 /*******************************************************************
38 * @brief Builds and sends param response to MAC CL
42 * Function : l1BldAndSndParamRsp
45 * - Builds and sends param response to MAC
47 * @params[in] Config request message pointer
48 * @return ROK - success
51 * ****************************************************************/
52 S16 l1BldAndSndParamRsp(void *msg)
57 fapi_param_resp_t *fapiParamRsp;
59 MAC_ALLOC(fapiParamRsp, sizeof(fapi_param_resp_t));
62 DU_LOG("PHY STUB: Memory allocation failed");
67 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_RELEASE_CAPABILITY_TAG, sizeof(uint16_t), 1, &msgLen);
68 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PHY_STATE_TAG, sizeof(uint16_t), 0, &msgLen);
69 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SKIP_BLANK_DL_CONFIG_TAG, sizeof(uint8_t), 0, &msgLen);
70 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SKIP_BLANK_UL_CONFIG_TAG, sizeof(uint8_t), 0, &msgLen);
71 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_NUM_CONFIG_TLVS_TO_REPORT_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
74 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CYCLIC_PREFIX_TAG, sizeof(uint8_t), 1, &msgLen);
75 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_SUBCARRIER_SPACING_DL_TAG, sizeof(uint8_t), 1, &msgLen);
76 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_BANDWIDTH_DL_TAG, sizeof(uint16_t), 1, &msgLen);
77 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_SUBCARRIER_SPACING_UL_TAG, sizeof(uint8_t), 0, &msgLen);
78 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_BANDWIDTH_UL_TAG, sizeof(uint16_t), 0, &msgLen);
81 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CCE_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
82 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CORESET_OUTSIDE_FIRST_3_OFDM_SYMS_OF_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
83 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRECODER_GRANULARITY_CORESET_TAG, sizeof(uint8_t), 0, &msgLen);
84 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDCCH_MU_MIMO_TAG, sizeof(uint8_t), 0, &msgLen);
85 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDCCH_PRECODER_CYCLING_TAG, sizeof(uint8_t), 0, &msgLen);
86 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDCCHS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
89 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUCCH_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
90 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PUCCHS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
93 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
94 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_ALLOCATION_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
95 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_VRB_TO_PRB_MAPPING_TAG, sizeof(uint8_t), 0, &msgLen);
96 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_CBG_TAG, sizeof(uint8_t), 0, &msgLen);
97 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_CONFIG_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
98 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_MAX_LENGTH_TAG, sizeof(uint8_t), 0, &msgLen);
99 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_ADDITIONAL_POS_TAG, sizeof(uint8_t), 0, &msgLen);
100 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDSCHS_TBS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
101 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_NUMBER_MIMO_LAYERS_PDSCH_TAG, sizeof(uint8_t), 0, &msgLen);
102 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_MAX_MODULATION_ORDER_DL_TAG, sizeof(uint8_t), 0, &msgLen);
103 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_MU_MIMO_USERS_DL_TAG, sizeof(uint8_t), 0, &msgLen);
104 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DATA_IN_DMRS_SYMBOLS_TAG, sizeof(uint8_t), 0, &msgLen);
105 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PREMPTIONSUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
106 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_NON_SLOT_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
109 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_UCI_MUX_ULSCH_IN_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
110 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_UCI_ONLY_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
111 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_FREQUENCY_HOPPING_TAG, sizeof(uint8_t), 0, &msgLen);
112 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_CONFIG_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
113 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_MAX_LEN_TAG, sizeof(uint8_t), 0, &msgLen);
114 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_ADDITIONAL_POS_TAG, sizeof(uint8_t), 0, &msgLen);
115 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_CBG_TAG, sizeof(uint8_t), 0, &msgLen);
116 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
117 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_ALLOCATION_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
118 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_VRB_TO_PRB_MAPPING_TAG, sizeof(uint8_t), 0, &msgLen);
119 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_MAX_PTRS_PORTS_TAG, sizeof(uint8_t), 0, &msgLen);
120 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDUSCHS_TBS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
121 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_NUMBER_MIMO_LAYERS_NON_CB_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
122 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_MODULATION_ORDER_UL_TAG, sizeof(uint8_t), 0, &msgLen);
123 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_MU_MIMO_USERS_UL_TAG, sizeof(uint8_t), 0, &msgLen);
124 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_DFTS_OFDM_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
125 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_AGGREGATION_FACTOR_TAG, sizeof(uint8_t), 0, &msgLen);
128 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_LONG_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
129 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_SHORT_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
130 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_RESTRICTED_SETS_TAG, sizeof(uint8_t), 0, &msgLen);
131 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PRACH_FD_OCCASIONS_IN_A_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
133 /* MEASUREMENT TAG */
134 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_RSSI_MEASUREMENT_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
136 fapiParamRsp->number_of_tlvs = index;
137 msgLen += sizeof(fapi_param_resp_t) - sizeof(fapi_msg_t);
138 fillMsgHeader(&fapiParamRsp->header, FAPI_PARAM_RESPONSE, msgLen);
139 fapiParamRsp->error_code = MSG_OK;
141 DU_LOG("\nPHY_STUB: Sending Param Request to Lower Mac");
142 procPhyMessages(fapiParamRsp->header.msg_id, sizeof(fapi_param_resp_t), (void *)fapiParamRsp);
143 MAC_FREE(fapiParamRsp, sizeof(fapi_param_resp_t));
148 /*******************************************************************
150 * @brief Builds and sends config response to lower mac
154 * Function : l1BldAndSndConfigRsp
157 * - Builds and sends config response to MAC
159 * @params[in] Config request message pointer
160 * @return ROK - success
163 * ****************************************************************/
165 S16 l1BldAndSndConfigRsp(void *msg)
169 fapi_config_resp_t *fapiConfigRsp;
171 MAC_ALLOC(fapiConfigRsp, sizeof(fapi_config_resp_t));
174 DU_LOG("PHY STUB: Memory allocation failed");
177 memset(fapiConfigRsp, 0, sizeof(fapi_config_resp_t));
178 fapiConfigRsp->number_of_invalid_tlvs = NULLP;
179 fapiConfigRsp->number_of_inv_tlvs_idle_only = NULLP;
180 fapiConfigRsp->number_of_missing_tlvs = NULLP;
181 fapiConfigRsp->error_code = MSG_OK;
182 msgLen = sizeof(fapi_config_resp_t) - sizeof(fapi_msg_t);
183 fillMsgHeader(&fapiConfigRsp->header, FAPI_CONFIG_RESPONSE, msgLen);
185 DU_LOG("\nPHY_STUB: Sending Config Response to Lower Mac");
187 procPhyMessages(fapiConfigRsp->header.msg_id, \
188 sizeof(fapi_config_resp_t), (void *)fapiConfigRsp);
189 MAC_FREE(fapiConfigRsp, sizeof(fapi_config_resp_t));
193 /*******************************************************************
195 * @brief Handles param request received from MAC
199 * Function : l1HdlParamReq
202 * -Handles param request received from MAC
204 * @params[in] Message length
205 * Param request message pointer
209 * ****************************************************************/
211 void l1HdlParamReq(uint32_t msgLen, void *msg)
214 DU_LOG("\nPHY_STUB: Received Param Request in PHY");
216 /* Build and send PARAM RESPONSE */
217 if(l1BldAndSndParamRsp(msg)!= ROK)
219 DU_LOG("\nPHY_STUB: Failed Sending Param Response");
221 MAC_FREE(msg, sizeof(fapi_param_req_t));
225 /*******************************************************************
227 * @brief Handles config request received from MAC
231 * Function : l1HdlConfigReq
234 * -Handles config request received from MAC
236 * @params[in] Message length
237 * config request message pointer
241 * ****************************************************************/
243 void l1HdlConfigReq(uint32_t msgLen, void *msg)
246 fapi_config_req_t *configReq = (fapi_config_req_t *)(msg +1);
248 DU_LOG("\nPHY_STUB: Received Config Request in PHY");
250 /* Handling CONFIG RESPONSE */
251 if(l1BldAndSndConfigRsp(configReq)!= ROK)
253 printf("\nPHY_STUB: Failed Sending config Response");
256 MAC_FREE(msg, msgLen);
261 /*******************************************************************
263 * @brief Build and Send CRC Indication
267 * Function : l1BuildAndSendCrcInd
270 * Build and Send CRC Indication
274 * @return ROK - success
277 * ****************************************************************/
278 uint16_t l1BuildAndSendCrcInd(uint16_t slot, uint16_t sfn)
282 fapi_crc_ind_t *crcInd;
284 MAC_ALLOC(crcInd, sizeof(fapi_crc_ind_t));
287 printf("\nPHY_STUB: Memory allocation failed for CRC Indication Message");
290 memset(crcInd, 0, sizeof(fapi_crc_ind_t));
292 /* TODO: Fill the required values. As of now only 1 CRC status PASS is filled */
297 crcInd->crc[idx].handle = 0;
298 crcInd->crc[idx].rnti = 0;
299 crcInd->crc[idx].harqId = 0;
300 crcInd->crc[idx].tbCrcStatus = 0;
301 crcInd->crc[idx].numCb = 1;
302 crcInd->crc[idx].cbCrcStatus[0] = 0;
303 crcInd->crc[idx].ul_cqi = 0;
304 crcInd->crc[idx].timingAdvance = 0;
305 crcInd->crc[idx].rssi = 0;
307 fillMsgHeader(&crcInd->header, FAPI_CRC_INDICATION, \
308 sizeof(fapi_crc_ind_t) - sizeof(fapi_msg_t));
310 /* Sending RACH indication to MAC */
311 DU_LOG("\nPHY STUB: Sending CRC Indication to MAC");
312 procPhyMessages(crcInd->header.msg_id, sizeof(fapi_crc_ind_t), (void *)crcInd);
313 MAC_FREE(crcInd, sizeof(fapi_crc_ind_t));
316 } /* l1BuildAndSendCrcInd */
319 /*******************************************************************
321 * @brief Build and send Rx data indication
325 * Function : l1BuildAndSendRxDataInd
328 * Build and send Rx data indication
332 * @return ROK - success
335 * ****************************************************************/
336 uint16_t l1BuildAndSendRxDataInd(uint16_t slot, uint16_t sfn, fapi_ul_pusch_pdu_t puschPdu)
339 fapi_rx_data_indication_t *rxDataInd;
340 fapi_pdu_ind_info_t *pduInfo;
341 uint8_t *pdu = NULLP;
342 uint16_t byteIdx = 0;
349 type = MSG_TYPE_MSG3;
351 else if(!msg5ShortBsrSent)
353 msg5ShortBsrSent = true;
354 type = MSG_TYPE_SHORT_BSR;
359 type = MSG_TYPE_MSG5;
361 else if(!msgSecurityModeComp)
363 msgSecurityModeComp = true;
364 type = MSG_TYPE_SECURITY_MODE_COMPLETE;
369 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
372 printf("\nPHY_STUB: Memory allocation failed for Rx Data Indication");
375 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
377 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
378 rxDataInd->sfn = sfn;
379 rxDataInd->slot = slot;
380 rxDataInd->numPdus = 1;
382 pduInfo = &rxDataInd->pdus[idx];
383 pduInfo->handle = puschPdu.handle;
384 pduInfo->rnti = puschPdu.rnti;
385 pduInfo->harqId = puschPdu.puschData.harqProcessId;
386 pduInfo->pdu_length = puschPdu.puschData.tbSize ;
388 pduInfo->timingAdvance = 0;
391 /* Filling pdu with random values for testing */
392 pduInfo->pduData = NULL;
393 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
394 if(!pduInfo->pduData)
396 printf("\nPHY_STUB: Memory allocation failed for Rx Data Pdu");
401 pdu = (uint8_t *)pduInfo->pduData;
407 DU_LOG("\nPHY_STUB: Forming MSG3 PDU ");
408 /* For Initial RRC setup Request,
409 MAC subheader format is R/R/LCId (1byte)
411 From 38.321 section 6.1.1
414 /* Hardcoding MAC PDU */
420 pdu[byteIdx++] = 103;
425 case MSG_TYPE_SHORT_BSR:
427 DU_LOG("\nPHY_STUB: Forming SHORT BSR PDU ");
429 uint8_t bufferSizeIdx = 6;
432 MAC subheader format is R/R/LcId (1Byte)
434 From 38.321 section 6.1.1
436 pdu[byteIdx++] = 61; // LCID
437 pdu[byteIdx++] = (lcgId << 5) | bufferSizeIdx;
444 DU_LOG("\nPHY_STUB: Forming MSG5 PDU");
445 uint8_t msg5PduLen = 33;
446 /* For RRC setup complete
447 MAC subheader format is R/F/LCId/L (2/3 bytes)
449 L is length of PDU i.e 6bytes here
450 From 38.321 section 6.1.1
452 uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
453 64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
454 184, 56, 0, 0, 0, 0, 0};
456 msg5PduLen += 2; /* 2bytes of header */
457 memcpy(pdu, &msg5, msg5PduLen);
458 byteIdx += msg5PduLen; /* 2 bytes of header */
462 case MSG_TYPE_SECURITY_MODE_COMPLETE:
464 DU_LOG("\nPHY_STUB: Forming SECURITY MODE COMPLETE PDU");
466 /* For security mode complete
467 MAC subheader format is R/F/LCId/L (2/3 bytes)
469 L is length of PDU i.e 6bytes here
470 From 38.321 section 6.1.1
472 uint8_t msg[] = {1, pduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
473 64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
474 184, 56, 0, 0, 0, 0, 0};
476 pduLen += 2; /* 2bytes of header */
477 memcpy(pdu, &msg, pduLen);
478 byteIdx += pduLen; /* 2 bytes of header */
483 } /* End of switch(type) */
484 /* Filling MAC SDU for Padding bytes*/
485 if(byteIdx < pduInfo->pdu_length)
488 MAC subheader format is R/R/LCId (1byte)
489 LCId is 63 for padding
490 From 38.321 section 6.1.1
494 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
497 msgLen += pduInfo->pdu_length;
499 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
501 /* Sending Rx data indication to MAC */
502 DU_LOG("\nPHY STUB: Sending Rx data Indication to MAC");
503 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
505 if(pduInfo->pdu_length)
506 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
507 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
512 /*******************************************************************
514 * @brief Builds and Sends RACH indication to MAC
518 * Function : l1BuildAndSendRachInd
521 * Builds and Sends RACH indication to MAC
523 * @params[in] SFN value
525 * @return ROK - success
528 * ****************************************************************/
529 uint16_t l1BuildAndSendRachInd(uint16_t slot, uint16_t sfn)
532 uint8_t rachPduIdx = 0;
533 uint8_t preamIdx = 0;
534 fapi_rach_pdu_t *rachPdu;
535 fapi_rach_indication_t *rachInd;
537 /* Building RACH indication */
538 MAC_ALLOC(rachInd, sizeof(fapi_rach_indication_t));
541 printf("\nPHY_STUB: Memory allocation failed for Rach Indication Message");
544 memset(rachInd, 0, sizeof(fapi_rach_indication_t));
546 rachInd->slot = slot;
547 rachInd->numPdus = 1;
549 rachPdu = &rachInd->rachPdu[rachPduIdx];
550 rachPdu->phyCellId = NR_PCI;
551 rachPdu->symbolIndex = 0;
552 rachPdu->slotIndex = slot;
553 rachPdu->freqIndex = 0;
554 rachPdu->avgRssi = 0;
556 rachPdu->numPreamble = 1;
558 rachPdu->preambleInfo[preamIdx].preambleIndex = 3;
559 rachPdu->preambleInfo[preamIdx].timingAdvance = 0;
560 rachPdu->preambleInfo[preamIdx].preamblePwr = 0;
562 fillMsgHeader(&rachInd->header, FAPI_RACH_INDICATION, \
563 sizeof(fapi_rach_indication_t) - sizeof(fapi_msg_t));
565 /* Sending RACH indication to MAC */
566 DU_LOG("\nPHY STUB: Sending RACH Indication to MAC");
567 procPhyMessages(rachInd->header.msg_id, sizeof(fapi_rach_indication_t), (void *)rachInd);
568 MAC_FREE(rachInd, sizeof(fapi_rach_indication_t));
573 /*******************************************************************
575 * @brief Builds and Send the Slot Indication message to MAC
579 * Function : l1BuildAndSendSlotIndication
582 * -Send the Slot indication Message to MAC
584 * @params[in] Message length
585 * config request message pointer
589 * ****************************************************************/
590 uint16_t l1BuildAndSendSlotIndication()
593 fapi_slot_ind_t *slotIndMsg;
595 MAC_ALLOC(slotIndMsg, sizeof(fapi_slot_ind_t));
598 DU_LOG("\nPHY_STUB: Memory allocation failed for slot Indication Message");
603 memset(slotIndMsg, 0, sizeof(fapi_slot_ind_t));
604 slotIndMsg->sfn = sfnValue;
605 slotIndMsg->slot = slotValue;
607 #ifdef ODU_SLOT_IND_DEBUG_LOG
608 DU_LOG("\n\nPHY_STUB: SLOT indication [%d:%d]",sfnValue,slotValue);
610 /* increment for the next TTI */
612 if(sfnValue >= MAX_SFN_VALUE && slotValue > MAX_SLOT_VALUE)
617 else if(slotValue > MAX_SLOT_VALUE)
622 fillMsgHeader(&slotIndMsg->header, FAPI_SLOT_INDICATION, \
623 sizeof(fapi_slot_ind_t) - sizeof(fapi_msg_t));
624 procPhyMessages(slotIndMsg->header.msg_id, sizeof(fapi_slot_ind_t), (void*)slotIndMsg);
625 MAC_FREE(slotIndMsg, sizeof(fapi_slot_ind_t));
631 /*******************************************************************
633 * @brief Handles start request received from MAC
637 * Function : l1HdlStartReq
640 * -Handles start request received from MAC
642 * @params[in] Message length
643 * config request message pointer
647 * ****************************************************************/
649 S16 l1HdlStartReq(uint32_t msgLen, void *msg)
652 if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
654 l1HdlSlotIndicaion(FALSE);
655 MAC_FREE(msg, msgLen);
659 DU_LOG("\nPHY_STUB: Received Start Req in PHY State %d", lwrMacCb.phyState);
660 MAC_FREE(msg, msgLen);
667 /*******************************************************************
669 * @brief Handles Dl Tti request received from MAC
673 * Function : l1HdlDlTtiReq
676 * -Handles Dl Tti request received from MAC
678 * @params[in] Message length
679 * Dl Tti request message pointer
683 * ****************************************************************/
685 S16 l1HdlDlTtiReq(uint16_t msgLen, void *msg)
688 fapi_dl_tti_req_t *dlTtiReq;
689 dlTtiReq = (fapi_dl_tti_req_t *)msg;
691 uint8_t pduCount = 0;
693 #ifdef ODU_SLOT_IND_DEBUG_LOG
694 if(dlTtiReq->nPdus == 0)
696 DU_LOG("\nPHY_STUB: No PDU in DL TTI Request");
700 DU_LOG("\nPHY STUB: DL TTI Request at sfn=%d slot=%d",dlTtiReq->sfn,dlTtiReq->slot);
704 for(pduCount=0; pduCount<dlTtiReq->nPdus; pduCount++)
706 if(dlTtiReq->pdus[pduCount].pduType == 3) //SSB_PDU_TYPE
708 DU_LOG("\nPHY_STUB: SSB PDU");
710 else if(dlTtiReq->pdus[pduCount].pduType == 0)
712 DU_LOG("\nPHY_STUB: PDCCH PDU");
713 if(dlTtiReq->pdus[pduCount].pdu.pdcch_pdu.\
719 else if(dlTtiReq->pdus[pduCount].pduType == 1)
721 DU_LOG("\nPHY_STUB: PDSCH PDU");
725 /* Free FAPI message */
726 MAC_FREE(dlTtiReq, msgLen);
732 /*******************************************************************
734 * @brief Handles tx_data request received from MAC
738 * Function : l1HdlTxDataReq
741 * -Handles tx_data request received from MAC
743 * @params[in] Message length
744 * tx_data request message pointer
748 * ****************************************************************/
750 S16 l1HdlTxDataReq(uint16_t msgLen, void *msg)
753 fapi_tx_data_req_t *txDataReq;
754 txDataReq = (fapi_tx_data_req_t *)msg;
755 DU_LOG("\nPHY STUB: TX DATA Request at sfn=%d slot=%d",txDataReq->sfn,txDataReq->slot);
758 DU_LOG("\nPHY_STUB: TxDataPdu for DED MSG sent");
761 MAC_FREE(txDataReq, msgLen);
767 /*******************************************************************
769 * @brief Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
773 * Function : fillPucchF0F1PduInfo
776 * Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
778 * @params[in] fapi_uci_o_pucch_f0f1_t *
780 * @return ROK - success
783 * ****************************************************************/
784 uint8_t fillPucchF0F1PduInfo(fapi_uci_o_pucch_f0f1_t *pduInfo, fapi_ul_pucch_pdu_t pucchPdu)
788 pduInfo->handle = pucchPdu.handle;
789 pduInfo->pduBitmap = 1; //hardcoded for SR
790 pduInfo->pucchFormat = pucchPdu.formatType;
792 pduInfo->rnti = pucchPdu.rnti;
793 pduInfo->timingAdvance = 0;
795 if(pduInfo->pduBitmap & SR_PDU_BITMASK)
797 pduInfo->srInfo.srIndication = SR_DETECTED;
798 pduInfo->srInfo.srConfidenceLevel = CONFDC_LEVEL_GOOD;
800 if(pduInfo->pduBitmap & HARQ_PDU_BITMASK)
802 pduInfo->harqInfo.numHarq++;
803 pduInfo->harqInfo.harqConfidenceLevel = CONFDC_LEVEL_GOOD;
804 for(idx = 0; idx < pduInfo->harqInfo.numHarq; idx++)
806 pduInfo->harqInfo.harqValue[idx] = HARQ_PASS;
811 /*******************************************************************
813 * @brief Fills UCI Pdu Information
817 * Function : fillUciPduInfo
820 * Fills UCI Pdu Information
822 * @params[in] Pointer to uciPdu
824 * @return ROK - success
827 * ****************************************************************/
828 uint8_t fillUciPduInfo(fapi_uci_pdu_info_t *uciPdu, fapi_ul_pucch_pdu_t pucchPdu)
832 /*TODO: The pduType is hardcoded here to support
833 UCI Ind for PUCCH forat0/format1. This is to be
834 modified when we get SR form UE */
835 uciPdu->pduType = UCI_IND_PUCCH_F0F1;
836 switch(uciPdu->pduType)
840 case UCI_IND_PUCCH_F0F1:
842 fapi_uci_o_pucch_f0f1_t *pduInfo = NULLP;
844 pduInfo = &uciPdu->uci.uciPucchF0F1;
845 ret = fillPucchF0F1PduInfo(pduInfo, pucchPdu);
846 uciPdu->pduSize = sizeof(fapi_uci_o_pucch_f0f1_t);
849 case UCI_IND_PUCCH_F2F3F4:
852 DU_LOG("\nPHY_STUB: Invalid Pdu Type %d", uciPdu->pduType);
858 /*******************************************************************
860 * @brief Build and send Uci indication
864 * Function : l1BuildAndSendUciInd
867 * Build and send Uci indication
871 * @return ROK - success
874 * ****************************************************************/
875 uint8_t l1BuildAndSendUciInd(uint16_t slot, uint16_t sfn, fapi_ul_pucch_pdu_t pucchPdu)
878 uint8_t nUciPdus = 0;
881 fapi_uci_indication_t *uciInd = NULLP;
883 MAC_ALLOC(uciInd, sizeof(fapi_uci_indication_t));
886 printf("\nPHY_STUB: Memory allocation failed for UCI Indication");
889 memset(uciInd, 0, sizeof(fapi_uci_indication_t));
892 uciInd->numUcis = 1; //consdering the UCI Ind for SR
893 nUciPdus = uciInd->numUcis;
896 ret = fillUciPduInfo(&uciInd->uciPdu[uciIdx], pucchPdu);
902 msgLen = sizeof(fapi_uci_indication_t)- sizeof(fapi_msg_t);
903 fillMsgHeader(&uciInd->header, FAPI_UCI_INDICATION, msgLen);
905 /* Sending UCI indication to MAC */
906 DU_LOG("\nPHY STUB: Sending UCI Indication to MAC");
907 procPhyMessages(uciInd->header.msg_id, sizeof(fapi_uci_indication_t), (void *)uciInd);
909 MAC_FREE(uciInd, sizeof(fapi_uci_indication_t));
914 /*******************************************************************
916 * @brief Handles Ul Tti request received from MAC
920 * Function : l1HdlUlTtiReq
923 * -Handles Ul Tti request received from MAC
925 * @params[in] Message length
926 * Ul Tti request message pointer
930 * ****************************************************************/
932 S16 l1HdlUlTtiReq(uint16_t msgLen, void *msg)
935 fapi_ul_tti_req_t *ulTtiReq = NULLP;
936 ulTtiReq = (fapi_ul_tti_req_t *)msg;
937 uint8_t numPdus = ulTtiReq->nPdus;
939 #ifdef ODU_SLOT_IND_DEBUG_LOG
942 DU_LOG("\nPHY STUB: No PDU received in UL TTI Req");
946 DU_LOG("\nPHY STUB: Received UL TTI Request");
952 if(ulTtiReq->pdus[numPdus-1].pduType == 0)
954 DU_LOG("\nPHY STUB: PRACH PDU");
956 if(ulTtiReq->pdus[numPdus-1].pduType == 1)
958 DU_LOG("\nPHY STUB: PUSCH PDU");
959 l1BuildAndSendRxDataInd(ulTtiReq->slot, ulTtiReq->sfn, \
960 ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu);
962 if(ulTtiReq->pdus[numPdus-1].pduType == 2)
964 DU_LOG("\nPHY STUB: PUCCH PDU");
965 fapi_ul_tti_req_t ulTtiSlotInd;
966 memset(&ulTtiSlotInd, 0, sizeof(fapi_ul_tti_req_t));
967 ulTtiSlotInd.slot = ulTtiReq->slot;
968 ulTtiSlotInd.sfn = ulTtiReq->sfn;
969 ADD_DELTA_TO_TIME(ulTtiSlotInd, ulTtiSlotInd, SLOT_DELAY);
970 l1BuildAndSendUciInd(ulTtiSlotInd.slot, ulTtiSlotInd.sfn, \
971 ulTtiReq->pdus[numPdus-1].pdu.pucch_pdu);
976 if(rachIndSent == false && ulTtiReq->sfn == 2 && ulTtiReq->slot == 6)
979 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn);
982 MAC_FREE(ulTtiReq, msgLen);
987 /*******************************************************************
989 * @brief Builds and Send the stop Indication message to MAC
993 * Function : l1BuildAndSendStopInd
996 * -Send the Stop indication Message to MAC
1001 * ****************************************************************/
1002 uint16_t l1BuildAndSendStopInd()
1005 fapi_stop_ind_t *stopIndMsg = NULLP;
1006 uint32_t msgLen = 0;
1008 MAC_ALLOC(stopIndMsg, sizeof(fapi_stop_ind_t));
1011 DU_LOG("\nPHY_STUB: Memory allocation failed for stop Indication Message");
1016 fillMsgHeader(&stopIndMsg->header, FAPI_STOP_INDICATION, msgLen);
1017 DU_LOG("\n\nPHY_STUB: Processing Stop indication to MAC");
1018 procPhyMessages(stopIndMsg->header.msg_id,\
1019 sizeof(fapi_stop_ind_t), (void*)stopIndMsg);
1020 MAC_FREE(stopIndMsg, sizeof(fapi_stop_ind_t));
1026 /*******************************************************************
1028 * @brief Handles stop request received from MAC
1032 * Function : l1HdlStopReq
1035 * -Handles stop request received from MAC
1037 * @params[in] Message length
1038 * stop request message pointer
1042 * ****************************************************************/
1044 S16 l1HdlStopReq(uint32_t msgLen, void *msg)
1047 fapi_stop_req_t *stopReq = (fapi_stop_req_t *)msg;
1049 if(lwrMacCb.phyState == PHY_STATE_RUNNING)
1051 l1HdlSlotIndicaion(TRUE);
1052 DU_LOG("\nPHY_STUB: Slot Indication is stopped successfully");
1053 l1BuildAndSendStopInd();
1054 MAC_FREE(stopReq, msgLen);
1058 DU_LOG("\nPHY_STUB: Received Stop Req in PHY State %d", lwrMacCb.phyState);
1065 /*******************************************************************
1067 * @brief Build And Send Rx Data Ind for Msg5
1071 * Function : l1BuildAndSendMsg5
1073 * Functionality: Build And Send Rx Data Ind for Msg5
1077 * @return ROK - success
1080 * ****************************************************************/
1081 uint8_t l1BuildAndSendMsg5(uint16_t sfn, uint16_t slot)
1085 fapi_rx_data_indication_t *rxDataInd;
1086 fapi_pdu_ind_info_t *pduInfo;
1088 uint16_t byteIdx = 0;
1089 uint32_t msgLen = 0;
1091 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1094 printf("\nPHY_STUB: Memory allocation failed for Rx Data Indication for msg5");
1097 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1099 /* TODO: Fill the required values */
1100 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1101 rxDataInd->sfn = sfn;
1102 rxDataInd->slot = slot;
1103 rxDataInd->numPdus = 1;
1105 pduInfo = &rxDataInd->pdus[idx];
1106 pduInfo->handle = 100;
1107 pduInfo->rnti = 100;
1108 pduInfo->harqId = 1;
1109 pduInfo->pdu_length = 25;
1110 pduInfo->ul_cqi = 0;
1111 pduInfo->timingAdvance = 0;
1114 /* Filling pdu with random values for testing */
1115 pduInfo->pduData = NULL;
1116 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1117 if(!pduInfo->pduData)
1119 printf("\nPHY_STUB: Memory allocation failed for Rx Data Pdu");
1124 pdu = (uint8_t *)pduInfo->pduData;
1126 uint8_t msg5PduLen = 33;
1127 /* For RRC setup complete
1128 MAC subheader format is R/F/LCId/L (2/3 bytes)
1130 L is length of PDU i.e 6bytes here
1131 From 38.321 section 6.1.1
1133 uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
1134 64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
1135 184, 56, 0, 0, 0, 0, 0};
1137 msg5PduLen += 2; /* 2bytes of header */
1138 memcpy(pdu, &msg5, msg5PduLen);
1139 byteIdx += msg5PduLen; /* 2 bytes of header */
1141 /* Filling MAC SDU for Padding bytes*/
1142 if(byteIdx < pduInfo->pdu_length)
1145 MAC subheader format is R/R/LCId (1byte)
1146 LCId is 63 for padding
1147 From 38.321 section 6.1.1
1149 pdu[byteIdx++] = 63;
1151 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1154 msgLen += pduInfo->pdu_length;
1156 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1158 /* Sending Rx data indication to MAC */
1159 DU_LOG("\nPHY STUB: Sending Rx data Indication to MAC");
1160 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1162 if(pduInfo->pdu_length)
1163 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1164 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1169 /*******************************************************************
1171 * @brief Handles Ul Dci request received from MAC
1175 * Function : l1HdlUlDciReq
1178 * -Handles Ul Dci request received from MAC
1180 * @params[in] Message length
1181 * Ul Dci request message pointer
1185 * ****************************************************************/
1187 S16 l1HdlUlDciReq(uint16_t msgLen, void *msg)
1190 fapi_ul_dci_req_t *ulDciReq = NULLP;
1192 ulDciReq = (fapi_ul_dci_req_t *)msg;
1193 uint8_t numPdus = ulDciReq->numPdus;
1197 if(ulDciReq->pdus[numPdus-1].pduType == 0)
1199 DU_LOG("\nPHY STUB: Received UL DCI Request for PDCCH PDU");
1200 //l1BuildAndSendMsg5(ulDciReq->sfn, ulDciReq->slot);
1206 MAC_FREE(ulDciReq, msgLen);
1211 /*******************************************************************
1213 * @brief Receives message from MAC
1217 * Function : l1ProcessFapiRequest
1220 * - Receives message from MAC and calls handler
1222 * @params[in] Message type
1228 * ****************************************************************/
1230 void l1ProcessFapiRequest(uint8_t msgType, uint32_t msgLen, void *msg)
1235 case FAPI_PARAM_REQUEST:
1236 l1HdlParamReq(msgLen, msg);
1238 case FAPI_CONFIG_REQUEST:
1239 l1HdlConfigReq(msgLen, msg);
1241 case FAPI_START_REQUEST:
1242 l1HdlStartReq(msgLen, msg);
1244 case FAPI_DL_TTI_REQUEST:
1245 l1HdlDlTtiReq(msgLen, msg);
1247 case FAPI_TX_DATA_REQUEST:
1248 l1HdlTxDataReq(msgLen, msg);
1250 case FAPI_UL_TTI_REQUEST:
1251 l1HdlUlTtiReq(msgLen, msg);
1253 case FAPI_STOP_REQUEST:
1254 l1HdlStopReq(msgLen, msg);
1256 case FAPI_UL_DCI_REQUEST:
1257 l1HdlUlDciReq(msgLen, msg);
1260 DU_LOG("\nPHY_STUB: Invalid message type[%x] received at PHY", msgType);
1265 /**********************************************************************
1267 **********************************************************************/