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 "lwr_mac_upr_inf.h"
34 #include "mac_utils.h"
36 #include "phy_stub_utils.h"
37 #include "lwr_mac_phy_stub_inf.h"
39 /*******************************************************************
41 * @brief Builds and sends param response to MAC CL
45 * Function : l1BldAndSndParamRsp
48 * - Builds and sends param response to MAC
50 * @params[in] Config request message pointer
51 * @return ROK - success
54 * ****************************************************************/
55 S16 l1BldAndSndParamRsp(void *msg)
60 fapi_param_resp_t *fapiParamRsp;
62 MAC_ALLOC(fapiParamRsp, sizeof(fapi_param_resp_t));
65 DU_LOG("\nERROR --> PHY STUB: Memory allocation failed");
70 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_RELEASE_CAPABILITY_TAG, sizeof(uint16_t), 1, &msgLen);
71 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PHY_STATE_TAG, sizeof(uint16_t), 0, &msgLen);
72 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SKIP_BLANK_DL_CONFIG_TAG, sizeof(uint8_t), 0, &msgLen);
73 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SKIP_BLANK_UL_CONFIG_TAG, sizeof(uint8_t), 0, &msgLen);
74 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_NUM_CONFIG_TLVS_TO_REPORT_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
77 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CYCLIC_PREFIX_TAG, sizeof(uint8_t), 1, &msgLen);
78 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_SUBCARRIER_SPACING_DL_TAG, sizeof(uint8_t), 1, &msgLen);
79 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_BANDWIDTH_DL_TAG, sizeof(uint16_t), 1, &msgLen);
80 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_SUBCARRIER_SPACING_UL_TAG, sizeof(uint8_t), 0, &msgLen);
81 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_BANDWIDTH_UL_TAG, sizeof(uint16_t), 0, &msgLen);
84 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CCE_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
85 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CORESET_OUTSIDE_FIRST_3_OFDM_SYMS_OF_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
86 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRECODER_GRANULARITY_CORESET_TAG, sizeof(uint8_t), 0, &msgLen);
87 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDCCH_MU_MIMO_TAG, sizeof(uint8_t), 0, &msgLen);
88 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDCCH_PRECODER_CYCLING_TAG, sizeof(uint8_t), 0, &msgLen);
89 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDCCHS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
92 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUCCH_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
93 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PUCCHS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
96 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
97 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_ALLOCATION_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
98 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_VRB_TO_PRB_MAPPING_TAG, sizeof(uint8_t), 0, &msgLen);
99 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_CBG_TAG, sizeof(uint8_t), 0, &msgLen);
100 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_CONFIG_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
101 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_MAX_LENGTH_TAG, sizeof(uint8_t), 0, &msgLen);
102 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_ADDITIONAL_POS_TAG, sizeof(uint8_t), 0, &msgLen);
103 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDSCHS_TBS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
104 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_NUMBER_MIMO_LAYERS_PDSCH_TAG, sizeof(uint8_t), 0, &msgLen);
105 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_MAX_MODULATION_ORDER_DL_TAG, sizeof(uint8_t), 0, &msgLen);
106 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_MU_MIMO_USERS_DL_TAG, sizeof(uint8_t), 0, &msgLen);
107 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DATA_IN_DMRS_SYMBOLS_TAG, sizeof(uint8_t), 0, &msgLen);
108 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PREMPTIONSUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
109 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_NON_SLOT_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
112 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_UCI_MUX_ULSCH_IN_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
113 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_UCI_ONLY_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
114 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_FREQUENCY_HOPPING_TAG, sizeof(uint8_t), 0, &msgLen);
115 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_CONFIG_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
116 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_MAX_LEN_TAG, sizeof(uint8_t), 0, &msgLen);
117 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_ADDITIONAL_POS_TAG, sizeof(uint8_t), 0, &msgLen);
118 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_CBG_TAG, sizeof(uint8_t), 0, &msgLen);
119 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
120 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_ALLOCATION_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
121 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_VRB_TO_PRB_MAPPING_TAG, sizeof(uint8_t), 0, &msgLen);
122 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_MAX_PTRS_PORTS_TAG, sizeof(uint8_t), 0, &msgLen);
123 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDUSCHS_TBS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
124 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_NUMBER_MIMO_LAYERS_NON_CB_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
125 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_MODULATION_ORDER_UL_TAG, sizeof(uint8_t), 0, &msgLen);
126 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_MU_MIMO_USERS_UL_TAG, sizeof(uint8_t), 0, &msgLen);
127 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_DFTS_OFDM_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
128 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_AGGREGATION_FACTOR_TAG, sizeof(uint8_t), 0, &msgLen);
131 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_LONG_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
132 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_SHORT_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
133 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_RESTRICTED_SETS_TAG, sizeof(uint8_t), 0, &msgLen);
134 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PRACH_FD_OCCASIONS_IN_A_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
136 /* MEASUREMENT TAG */
137 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_RSSI_MEASUREMENT_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
139 fapiParamRsp->number_of_tlvs = index;
140 msgLen += sizeof(fapi_param_resp_t) - sizeof(fapi_msg_t);
141 fillMsgHeader(&fapiParamRsp->header, FAPI_PARAM_RESPONSE, msgLen);
142 fapiParamRsp->error_code = MSG_OK;
144 DU_LOG("\nINFO --> PHY_STUB: Sending Param Request to Lower Mac");
145 procPhyMessages(fapiParamRsp->header.msg_id, sizeof(fapi_param_resp_t), (void *)fapiParamRsp);
146 MAC_FREE(fapiParamRsp, sizeof(fapi_param_resp_t));
151 /*******************************************************************
153 * @brief Builds and sends config response to lower mac
157 * Function : l1BldAndSndConfigRsp
160 * - Builds and sends config response to MAC
162 * @params[in] Config request message pointer
163 * @return ROK - success
166 * ****************************************************************/
168 S16 l1BldAndSndConfigRsp(void *msg)
172 fapi_config_resp_t *fapiConfigRsp;
174 MAC_ALLOC(fapiConfigRsp, sizeof(fapi_config_resp_t));
177 DU_LOG("\nERROR --> PHY STUB: Memory allocation failed");
180 memset(fapiConfigRsp, 0, sizeof(fapi_config_resp_t));
181 fapiConfigRsp->number_of_invalid_tlvs = NULLP;
182 fapiConfigRsp->number_of_inv_tlvs_idle_only = NULLP;
183 fapiConfigRsp->number_of_missing_tlvs = NULLP;
184 fapiConfigRsp->error_code = MSG_OK;
185 msgLen = sizeof(fapi_config_resp_t) - sizeof(fapi_msg_t);
186 fillMsgHeader(&fapiConfigRsp->header, FAPI_CONFIG_RESPONSE, msgLen);
188 DU_LOG("\nINFO --> PHY_STUB: Sending Config Response to Lower Mac");
190 procPhyMessages(fapiConfigRsp->header.msg_id, \
191 sizeof(fapi_config_resp_t), (void *)fapiConfigRsp);
192 MAC_FREE(fapiConfigRsp, sizeof(fapi_config_resp_t));
196 /*******************************************************************
198 * @brief Handles param request received from MAC
202 * Function : l1HdlParamReq
205 * -Handles param request received from MAC
207 * @params[in] Message length
208 * Param request message pointer
212 * ****************************************************************/
214 void l1HdlParamReq(uint32_t msgLen, void *msg)
217 DU_LOG("\nINFO --> PHY_STUB: Received Param Request in PHY");
219 /* Build and send PARAM RESPONSE */
220 if(l1BldAndSndParamRsp(msg)!= ROK)
222 DU_LOG("\nERROR --> PHY_STUB: Failed Sending Param Response");
224 MAC_FREE(msg, sizeof(fapi_param_req_t));
228 /*******************************************************************
230 * @brief Handles config request received from MAC
234 * Function : l1HdlConfigReq
237 * -Handles config request received from MAC
239 * @params[in] Message length
240 * config request message pointer
244 * ****************************************************************/
246 void l1HdlConfigReq(uint32_t msgLen, void *msg)
250 msg5ShortBsrSent = false;
253 msgSecurityModeComp = false;
254 msgRrcReconfiguration = false;
255 msgRegistrationComp = false;
258 p_fapi_api_queue_elem_t configReqElem = (p_fapi_api_queue_elem_t)msg;
259 fapi_config_req_t *configReq = (fapi_config_req_t *)(configReqElem +1);
261 DU_LOG("\nINFO --> PHY_STUB: Received Config Request in PHY");
263 /* Handling CONFIG RESPONSE */
264 if(l1BldAndSndConfigRsp(configReq)!= ROK)
266 DU_LOG("\nERROR --> PHY_STUB: Failed Sending config Response");
269 MAC_FREE(msg, msgLen);
274 /*******************************************************************
276 * @brief Build and Send CRC Indication
280 * Function : l1BuildAndSendCrcInd
283 * Build and Send CRC Indication
287 * @return ROK - success
290 * ****************************************************************/
291 uint16_t l1BuildAndSendCrcInd(uint16_t slot, uint16_t sfn)
295 fapi_crc_ind_t *crcInd;
297 MAC_ALLOC(crcInd, sizeof(fapi_crc_ind_t));
300 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for CRC Indication Message");
303 memset(crcInd, 0, sizeof(fapi_crc_ind_t));
305 /* TODO: Fill the required values. As of now only 1 CRC status PASS is filled */
310 crcInd->crc[idx].handle = 0;
311 crcInd->crc[idx].rnti = 0;
312 crcInd->crc[idx].harqId = 0;
313 crcInd->crc[idx].tbCrcStatus = 0;
314 crcInd->crc[idx].numCb = 1;
315 crcInd->crc[idx].cbCrcStatus[0] = 0;
316 crcInd->crc[idx].ul_cqi = 0;
317 crcInd->crc[idx].timingAdvance = 0;
318 crcInd->crc[idx].rssi = 0;
320 fillMsgHeader(&crcInd->header, FAPI_CRC_INDICATION, \
321 sizeof(fapi_crc_ind_t) - sizeof(fapi_msg_t));
323 /* Sending RACH indication to MAC */
324 DU_LOG("\nINFO --> PHY STUB: Sending CRC Indication to MAC");
325 procPhyMessages(crcInd->header.msg_id, sizeof(fapi_crc_ind_t), (void *)crcInd);
326 MAC_FREE(crcInd, sizeof(fapi_crc_ind_t));
329 } /* l1BuildAndSendCrcInd */
332 /*******************************************************************
334 * @brief Build and send Rx data indication
338 * Function : l1BuildAndSendRxDataInd
341 * Build and send Rx data indication
345 * @return ROK - success
348 * ****************************************************************/
349 uint16_t l1BuildAndSendRxDataInd(uint16_t slot, uint16_t sfn, fapi_ul_pusch_pdu_t puschPdu)
352 fapi_rx_data_indication_t *rxDataInd =NULLP;
353 fapi_pdu_ind_info_t *pduInfo =NULLP;
354 uint8_t *pdu = NULLP;
355 uint16_t byteIdx = 0;
362 type = MSG_TYPE_MSG3;
365 else if(!msg5ShortBsrSent)
367 msg5ShortBsrSent = true;
368 type = MSG_TYPE_SHORT_BSR;
373 type = MSG_TYPE_MSG5;
375 else if(!msgRegistrationComp)
377 msgRegistrationComp = true;
378 type = MSG_TYPE_REGISTRATION_COMPLETE;
380 else if(!msgSecurityModeComp)
382 msgSecurityModeComp = true;
383 type = MSG_TYPE_SECURITY_MODE_COMPLETE;
385 else if(!msgRrcReconfiguration)
387 msgRrcReconfiguration = true;
388 type = MSG_TYPE_RRC_RECONFIG_COMPLETE;
393 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
396 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
399 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
401 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
402 rxDataInd->sfn = sfn;
403 rxDataInd->slot = slot;
404 rxDataInd->numPdus = 1;
406 pduInfo = &rxDataInd->pdus[idx];
407 pduInfo->handle = puschPdu.handle;
408 pduInfo->rnti = puschPdu.rnti;
409 pduInfo->harqId = puschPdu.puschData.harqProcessId;
410 pduInfo->pdu_length = puschPdu.puschData.tbSize ;
412 pduInfo->timingAdvance = 0;
415 /* Filling pdu with random values for testing */
416 pduInfo->pduData = NULL;
417 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
418 if(!pduInfo->pduData)
420 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
423 memset(pduInfo->pduData, 0, pduInfo->pdu_length);
425 pdu = (uint8_t *)pduInfo->pduData;
431 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG3 PDU ");
432 /* For Initial RRC setup Request,
433 MAC subheader format is R/R/LCId (1byte)
435 From 38.321 section 6.1.1
438 /* Hardcoding MAC PDU */
444 pdu[byteIdx++] = 103;
448 case MSG_TYPE_SHORT_BSR:
450 DU_LOG("\nDEBUG --> PHY_STUB: Forming SHORT BSR PDU ");
452 uint8_t bufferSizeIdx = 6;
455 MAC subheader format is R/R/LcId (1Byte)
457 From 38.321 section 6.1.1
459 pdu[byteIdx++] = 61; // LCID
460 pdu[byteIdx++] = (lcgId << 5) | bufferSizeIdx;
467 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG5 PDU");
468 uint8_t msg5PduLen = 33;
469 /* For RRC setup complete
470 MAC subheader format is R/F/LCId/L (2/3 bytes)
472 L is length of PDU i.e 6bytes here
473 From 38.321 section 6.1.1
475 uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
476 64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
477 184, 56, 0, 0, 0, 0, 0};
479 msg5PduLen += 2; /* 2bytes of header */
480 memcpy(pdu, &msg5, msg5PduLen);
481 byteIdx += msg5PduLen; /* 2 bytes of header */
485 case MSG_TYPE_SECURITY_MODE_COMPLETE:
487 DU_LOG("\nDEBUG --> PHY_STUB: Forming SECURITY MODE COMPLETE PDU");
489 /* For security mode complete where RRC Container is dummy
490 MAC subheader format is R/F/LCId/L (2/3 bytes)
492 L is length of PDU i.e 6bytes here
493 From 38.321 section 6.1.1
495 uint8_t msg[] = {1, pduLen, 0, 3, 0x2a, 0x40, 0, 0, 0, 0, 0, 0, 0, 0};
497 pduLen += 2; /* 2bytes of header */
498 memcpy(pdu, &msg, pduLen);
499 byteIdx += pduLen; /* 2 bytes of header */
502 case MSG_TYPE_REGISTRATION_COMPLETE:
505 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC REGISTRATION COMPLETE PDU");
507 /* For rrc reconfig complete where RRC Container is dummy
508 MAC subheader format is R/F/LCId/L (2/3 bytes)
510 L is length of PDU i.e 6bytes here
511 From 38.321 section 6.1.1
513 uint8_t msg[] = {1, pduLen, 0, 0x04, 0x3a, 0x81, 0xbf, 0, 0x21, 0x80, 0, \
516 pduLen += 2; /* 2bytes of header */
517 memcpy(pdu, &msg, pduLen);
518 byteIdx += pduLen; /* 2 bytes of header */
521 case MSG_TYPE_RRC_RECONFIG_COMPLETE:
523 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC RECONFIGURATION COMPLETE PDU");
525 /* For rrc reconfig complete where RRC Container is dummy
526 MAC subheader format is R/F/LCId/L (2/3 bytes)
528 L is length of PDU i.e 6bytes here
529 From 38.321 section 6.1.1
531 uint8_t msg[] = {1, pduLen, 0, 6, 8, 64, 0, 0, 0, 0, \
534 pduLen += 2; /* 2bytes of header */
535 memcpy(pdu, &msg, pduLen);
536 byteIdx += pduLen; /* 2 bytes of header */
543 } /* End of switch(type) */
544 /* Filling MAC SDU for Padding bytes*/
545 if(byteIdx < pduInfo->pdu_length)
548 MAC subheader format is R/R/LCId (1byte)
549 LCId is 63 for padding
550 From 38.321 section 6.1.1
554 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
557 msgLen += pduInfo->pdu_length;
559 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
561 /* Sending Rx data indication to MAC */
562 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
563 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
565 if(pduInfo->pdu_length)
566 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
567 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
572 /*******************************************************************
574 * @brief Builds and Sends RACH indication to MAC
578 * Function : l1BuildAndSendRachInd
581 * Builds and Sends RACH indication to MAC
583 * @params[in] SFN value
585 * @return ROK - success
588 * ****************************************************************/
589 uint16_t l1BuildAndSendRachInd(uint16_t slot, uint16_t sfn)
592 uint8_t rachPduIdx = 0;
593 uint8_t preamIdx = 0;
594 fapi_rach_pdu_t *rachPdu;
595 fapi_rach_indication_t *rachInd;
597 /* Building RACH indication */
598 MAC_ALLOC(rachInd, sizeof(fapi_rach_indication_t));
601 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rach Indication Message");
604 memset(rachInd, 0, sizeof(fapi_rach_indication_t));
606 rachInd->slot = slot;
607 rachInd->numPdus = 1;
609 rachPdu = &rachInd->rachPdu[rachPduIdx];
610 rachPdu->phyCellId = NR_PCI;
611 rachPdu->symbolIndex = 0;
612 rachPdu->slotIndex = slot;
613 rachPdu->freqIndex = 0;
614 rachPdu->avgRssi = 0;
616 rachPdu->numPreamble = 1;
618 rachPdu->preambleInfo[preamIdx].preambleIndex = 3;
619 rachPdu->preambleInfo[preamIdx].timingAdvance = 0;
620 rachPdu->preambleInfo[preamIdx].preamblePwr = 0;
622 fillMsgHeader(&rachInd->header, FAPI_RACH_INDICATION, \
623 sizeof(fapi_rach_indication_t) - sizeof(fapi_msg_t));
625 /* Sending RACH indication to MAC */
626 DU_LOG("\nINFO --> PHY STUB: Sending RACH Indication to MAC");
627 procPhyMessages(rachInd->header.msg_id, sizeof(fapi_rach_indication_t), (void *)rachInd);
628 MAC_FREE(rachInd, sizeof(fapi_rach_indication_t));
633 /*******************************************************************
635 * @brief Builds and Send the Slot Indication message to MAC
639 * Function : l1BuildAndSendSlotIndication
642 * -Send the Slot indication Message to MAC
644 * @params[in] Message length
645 * config request message pointer
649 * ****************************************************************/
650 uint16_t l1BuildAndSendSlotIndication()
656 fapi_slot_ind_t *slotIndMsg;
658 MAC_ALLOC_SHRABL_BUF(slotIndMsg, sizeof(fapi_slot_ind_t));
661 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for slot Indication Message");
666 memset(slotIndMsg, 0, sizeof(fapi_slot_ind_t));
667 slotIndMsg->sfn = sfnValue;
668 slotIndMsg->slot = slotValue;
670 #ifdef ODU_SLOT_IND_DEBUG_LOG
671 DU_LOG("\n\nDEBUG --> PHY_STUB: Sending Slot Indication [%d : %d] to MAC", sfnValue, slotValue);
674 /* increment for the next TTI */
676 if(sfnValue >= MAX_SFN_VALUE && slotValue > MAX_SLOT_VALUE)
681 else if(slotValue > MAX_SLOT_VALUE)
686 fillMsgHeader(&slotIndMsg->header, FAPI_SLOT_INDICATION, \
687 sizeof(fapi_slot_ind_t) - sizeof(fapi_msg_t));
689 memset(&pst, 0, sizeof(Pst));
690 FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_SLOT_IND);
692 ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
695 DU_LOG("\nERROR --> PHY_STUB: Failed to allocate memory for slot indication buffer");
696 MAC_FREE_SHRABL_BUF(pst.region, pst.pool, slotIndMsg, sizeof(fapi_slot_ind_t));
699 CMCHKPK(oduPackPointer, (PTR)slotIndMsg, mBuf);
700 ODU_POST_TASK(&pst, mBuf);
706 /*******************************************************************
708 * @brief Handles start request received from MAC
712 * Function : l1HdlStartReq
715 * -Handles start request received from MAC
717 * @params[in] Message length
718 * config request message pointer
722 * ****************************************************************/
724 S16 l1HdlStartReq(uint32_t msgLen, void *msg)
727 if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
729 l1HdlSlotIndicaion(FALSE);
730 l1StartConsoleHandler();
731 MAC_FREE(msg, msgLen);
735 DU_LOG("\nINFO --> PHY_STUB: Received Start Req in PHY State %d", lwrMacCb.phyState);
736 MAC_FREE(msg, msgLen);
743 /*******************************************************************
745 * @brief Handles Dl Tti request received from MAC
749 * Function : l1HdlDlTtiReq
752 * -Handles Dl Tti request received from MAC
754 * @params[in] Message length
755 * Dl Tti request message pointer
759 * ****************************************************************/
761 S16 l1HdlDlTtiReq(uint16_t msgLen, void *msg)
764 p_fapi_api_queue_elem_t dlTtiElem = (p_fapi_api_queue_elem_t)msg;
765 fapi_dl_tti_req_t *dlTtiReq = (fapi_dl_tti_req_t *)(dlTtiElem +1);
767 uint8_t pduCount = 0;
769 #ifdef ODU_SLOT_IND_DEBUG_LOG
770 if(dlTtiReq->nPdus == 0)
772 DU_LOG("\nDEBUG --> PHY_STUB: No PDU in DL TTI Request");
776 DU_LOG("\nDEBUG --> PHY STUB: DL TTI Request at sfn=%d slot=%d",dlTtiReq->sfn,dlTtiReq->slot);
780 for(pduCount=0; pduCount<dlTtiReq->nPdus; pduCount++)
782 if(dlTtiReq->pdus[pduCount].pduType == 3) //SSB_PDU_TYPE
784 DU_LOG("\nINFO --> PHY_STUB: SSB PDU");
786 else if(dlTtiReq->pdus[pduCount].pduType == 0)
788 DU_LOG("\nINFO --> PHY_STUB: PDCCH PDU");
789 if(dlTtiReq->pdus[pduCount].pdu.pdcch_pdu.\
795 else if(dlTtiReq->pdus[pduCount].pduType == 1)
797 DU_LOG("\nINFO --> PHY_STUB: PDSCH PDU");
801 /* Free FAPI message */
802 MAC_FREE(msg, msgLen);
807 /*******************************************************************
809 * @brief Handles tx_data request received from MAC
813 * Function : l1HdlTxDataReq
816 * -Handles tx_data request received from MAC
818 * @params[in] Message length
819 * tx_data request message pointer
823 * ****************************************************************/
825 S16 l1HdlTxDataReq(uint16_t msgLen, void *msg)
828 p_fapi_api_queue_elem_t txDataElem = (p_fapi_api_queue_elem_t)msg;
829 fapi_tx_data_req_t *txDataReq = (fapi_tx_data_req_t *)(txDataElem +1);
831 DU_LOG("\nINFO --> PHY STUB: TX DATA Request at sfn=%d slot=%d",txDataReq->sfn,txDataReq->slot);
834 DU_LOG("\nINFO --> PHY_STUB: TxDataPdu for DED MSG sent");
837 MAC_FREE(msg, msgLen);
843 /*******************************************************************
845 * @brief Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
849 * Function : fillPucchF0F1PduInfo
852 * Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
854 * @params[in] fapi_uci_o_pucch_f0f1_t *
856 * @return ROK - success
859 * ****************************************************************/
860 uint8_t fillPucchF0F1PduInfo(fapi_uci_o_pucch_f0f1_t *pduInfo, fapi_ul_pucch_pdu_t pucchPdu)
864 pduInfo->handle = pucchPdu.handle;
865 pduInfo->pduBitmap = 1; //hardcoded for SR
866 pduInfo->pucchFormat = pucchPdu.formatType;
868 pduInfo->rnti = pucchPdu.rnti;
869 pduInfo->timingAdvance = 0;
871 if(pduInfo->pduBitmap & SR_PDU_BITMASK)
873 pduInfo->srInfo.srIndication = SR_DETECTED;
874 pduInfo->srInfo.srConfidenceLevel = CONFDC_LEVEL_GOOD;
876 if(pduInfo->pduBitmap & HARQ_PDU_BITMASK)
878 pduInfo->harqInfo.numHarq++;
879 pduInfo->harqInfo.harqConfidenceLevel = CONFDC_LEVEL_GOOD;
880 for(idx = 0; idx < pduInfo->harqInfo.numHarq; idx++)
882 pduInfo->harqInfo.harqValue[idx] = HARQ_PASS;
887 /*******************************************************************
889 * @brief Fills UCI Pdu Information
893 * Function : fillUciPduInfo
896 * Fills UCI Pdu Information
898 * @params[in] Pointer to uciPdu
900 * @return ROK - success
903 * ****************************************************************/
904 uint8_t fillUciPduInfo(fapi_uci_pdu_info_t *uciPdu, fapi_ul_pucch_pdu_t pucchPdu)
908 /*TODO: The pduType is hardcoded here to support
909 UCI Ind for PUCCH forat0/format1. This is to be
910 modified when we get SR form UE */
911 uciPdu->pduType = UCI_IND_PUCCH_F0F1;
912 switch(uciPdu->pduType)
916 case UCI_IND_PUCCH_F0F1:
918 fapi_uci_o_pucch_f0f1_t *pduInfo = NULLP;
920 pduInfo = &uciPdu->uci.uciPucchF0F1;
921 ret = fillPucchF0F1PduInfo(pduInfo, pucchPdu);
922 uciPdu->pduSize = sizeof(fapi_uci_o_pucch_f0f1_t);
925 case UCI_IND_PUCCH_F2F3F4:
928 DU_LOG("\nERROR --> PHY_STUB: Invalid Pdu Type %d", uciPdu->pduType);
934 /*******************************************************************
936 * @brief Build and send Uci indication
940 * Function : l1BuildAndSendUciInd
943 * Build and send Uci indication
947 * @return ROK - success
950 * ****************************************************************/
951 uint8_t l1BuildAndSendUciInd(uint16_t slot, uint16_t sfn, fapi_ul_pucch_pdu_t pucchPdu)
954 uint8_t nUciPdus = 0;
957 fapi_uci_indication_t *uciInd = NULLP;
959 MAC_ALLOC(uciInd, sizeof(fapi_uci_indication_t));
962 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for UCI Indication");
965 memset(uciInd, 0, sizeof(fapi_uci_indication_t));
968 uciInd->numUcis = 1; //consdering the UCI Ind for SR
969 nUciPdus = uciInd->numUcis;
972 ret = fillUciPduInfo(&uciInd->uciPdu[uciIdx], pucchPdu);
978 msgLen = sizeof(fapi_uci_indication_t)- sizeof(fapi_msg_t);
979 fillMsgHeader(&uciInd->header, FAPI_UCI_INDICATION, msgLen);
981 /* Sending UCI indication to MAC */
982 DU_LOG("\nINFO --> PHY STUB: Sending UCI Indication to MAC");
983 procPhyMessages(uciInd->header.msg_id, sizeof(fapi_uci_indication_t), (void *)uciInd);
985 MAC_FREE(uciInd, sizeof(fapi_uci_indication_t));
990 /*******************************************************************
992 * @brief Handles Ul Tti request received from MAC
996 * Function : l1HdlUlTtiReq
999 * -Handles Ul Tti request received from MAC
1001 * @params[in] Message length
1002 * Ul Tti request message pointer
1006 * ****************************************************************/
1008 S16 l1HdlUlTtiReq(uint16_t msgLen, void *msg)
1011 p_fapi_api_queue_elem_t ulTtiElem = (p_fapi_api_queue_elem_t)msg;
1012 fapi_ul_tti_req_t *ulTtiReq = (fapi_ul_tti_req_t *)(ulTtiElem +1);
1013 uint8_t numPdus = ulTtiReq->nPdus;
1015 #ifdef ODU_SLOT_IND_DEBUG_LOG
1018 DU_LOG("\nINFO --> PHY STUB: No PDU received in UL TTI Req");
1022 DU_LOG("\nINFO --> PHY STUB: Received UL TTI Request");
1028 if(ulTtiReq->pdus[numPdus-1].pduType == 0)
1030 DU_LOG("\nINFO --> PHY STUB: PRACH PDU");
1032 if(ulTtiReq->pdus[numPdus-1].pduType == 1)
1034 DU_LOG("\nINFO --> PHY STUB: PUSCH PDU");
1035 l1BuildAndSendRxDataInd(ulTtiReq->slot, ulTtiReq->sfn, \
1036 ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu);
1038 if(ulTtiReq->pdus[numPdus-1].pduType == 2)
1040 DU_LOG("\nINFO --> PHY STUB: PUCCH PDU");
1041 fapi_ul_tti_req_t ulTtiSlotInd;
1042 memset(&ulTtiSlotInd, 0, sizeof(fapi_ul_tti_req_t));
1043 ulTtiSlotInd.slot = ulTtiReq->slot;
1044 ulTtiSlotInd.sfn = ulTtiReq->sfn;
1045 ADD_DELTA_TO_TIME(ulTtiSlotInd, ulTtiSlotInd, SLOT_DELAY);
1046 l1BuildAndSendUciInd(ulTtiSlotInd.slot, ulTtiSlotInd.sfn, \
1047 ulTtiReq->pdus[numPdus-1].pdu.pucch_pdu);
1052 if(rachIndSent == false && ulTtiReq->sfn == 16 && ulTtiReq->slot == 6)
1055 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn);
1058 MAC_FREE(msg, msgLen);
1063 /*******************************************************************
1065 * @brief Builds and Send the stop Indication message to MAC
1069 * Function : l1BuildAndSendStopInd
1072 * -Send the Stop indication Message to MAC
1077 * ****************************************************************/
1078 uint16_t l1BuildAndSendStopInd()
1082 Buffer *mBuf = NULLP;
1083 fapi_stop_ind_t *stopIndMsg = NULLP;
1084 uint32_t msgLen = 0;
1086 MAC_ALLOC_SHRABL_BUF(stopIndMsg, sizeof(fapi_stop_ind_t));
1089 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for stop Indication Message");
1094 fillMsgHeader(&stopIndMsg->header, FAPI_STOP_INDICATION, msgLen);
1095 DU_LOG("\n\nINFO --> PHY_STUB: Processing Stop indication to MAC");
1097 memset(&pst, 0, sizeof(Pst));
1098 FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_STOP_IND);
1099 ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
1102 DU_LOG("\nERROR --> PHY_STUB: Failed to allocate memory for slot indication buffer");
1103 MAC_FREE_SHRABL_BUF(pst.region, pst.pool, stopIndMsg, sizeof(fapi_stop_ind_t));
1106 CMCHKPK(oduPackPointer, (PTR)stopIndMsg, mBuf);
1107 ODU_POST_TASK(&pst, mBuf);
1113 /*******************************************************************
1115 * @brief Handles stop request received from MAC
1119 * Function : l1HdlStopReq
1122 * -Handles stop request received from MAC
1124 * @params[in] Message length
1125 * stop request message pointer
1129 * ****************************************************************/
1131 S16 l1HdlStopReq(uint32_t msgLen, void *msg)
1134 if(lwrMacCb.phyState == PHY_STATE_RUNNING)
1136 l1HdlSlotIndicaion(TRUE);
1138 /* Initialize all global variables */
1141 rachIndSent = false;
1143 msg5ShortBsrSent = false;
1146 msgSecurityModeComp = false;
1147 msgRrcReconfiguration = false;
1148 msgRegistrationComp = false;
1150 DU_LOG("\nINFO --> PHY_STUB: Slot Indication is stopped successfully");
1151 MAC_FREE(msg, msgLen);
1155 DU_LOG("\nINFO --> PHY_STUB: Received Stop Req in PHY State %d", lwrMacCb.phyState);
1156 MAC_FREE(msg, msgLen);
1163 /*******************************************************************
1165 * @brief Build And Send Rx Data Ind for Msg5
1169 * Function : l1BuildAndSendMsg5
1171 * Functionality: Build And Send Rx Data Ind for Msg5
1175 * @return ROK - success
1178 * ****************************************************************/
1179 uint8_t l1BuildAndSendMsg5(uint16_t sfn, uint16_t slot)
1183 fapi_rx_data_indication_t *rxDataInd;
1184 fapi_pdu_ind_info_t *pduInfo;
1186 uint16_t byteIdx = 0;
1187 uint32_t msgLen = 0;
1189 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1192 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication for msg5");
1195 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1197 /* TODO: Fill the required values */
1198 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1199 rxDataInd->sfn = sfn;
1200 rxDataInd->slot = slot;
1201 rxDataInd->numPdus = 1;
1203 pduInfo = &rxDataInd->pdus[idx];
1204 pduInfo->handle = 100;
1205 pduInfo->rnti = 100;
1206 pduInfo->harqId = 1;
1207 pduInfo->pdu_length = 25;
1208 pduInfo->ul_cqi = 0;
1209 pduInfo->timingAdvance = 0;
1212 /* Filling pdu with random values for testing */
1213 pduInfo->pduData = NULL;
1214 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1215 if(!pduInfo->pduData)
1217 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1222 pdu = (uint8_t *)pduInfo->pduData;
1224 uint8_t msg5PduLen = 33;
1225 /* For RRC setup complete
1226 MAC subheader format is R/F/LCId/L (2/3 bytes)
1228 L is length of PDU i.e 6bytes here
1229 From 38.321 section 6.1.1
1231 uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
1232 64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
1233 184, 56, 0, 0, 0, 0, 0};
1235 msg5PduLen += 2; /* 2bytes of header */
1236 memcpy(pdu, &msg5, msg5PduLen);
1237 byteIdx += msg5PduLen; /* 2 bytes of header */
1239 /* Filling MAC SDU for Padding bytes*/
1240 if(byteIdx < pduInfo->pdu_length)
1243 MAC subheader format is R/R/LCId (1byte)
1244 LCId is 63 for padding
1245 From 38.321 section 6.1.1
1247 pdu[byteIdx++] = 63;
1249 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1252 msgLen += pduInfo->pdu_length;
1254 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1256 /* Sending Rx data indication to MAC */
1257 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
1258 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1260 if(pduInfo->pdu_length)
1261 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1262 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1267 /*******************************************************************
1269 * @brief Handles Ul Dci request received from MAC
1273 * Function : l1HdlUlDciReq
1276 * -Handles Ul Dci request received from MAC
1278 * @params[in] Message length
1279 * Ul Dci request message pointer
1283 * ****************************************************************/
1285 S16 l1HdlUlDciReq(uint16_t msgLen, void *msg)
1288 p_fapi_api_queue_elem_t ulDciElem = (p_fapi_api_queue_elem_t)msg;
1289 fapi_ul_dci_req_t *ulDciReq = (fapi_ul_dci_req_t *)(ulDciElem +1);
1290 uint8_t numPdus = ulDciReq->numPdus;
1294 if(ulDciReq->pdus[numPdus-1].pduType == 0)
1296 DU_LOG("\nINFO --> PHY STUB: Received UL DCI Request for PDCCH PDU");
1297 //l1BuildAndSendMsg5(ulDciReq->sfn, ulDciReq->slot);
1303 MAC_FREE(msg, msgLen);
1308 /*******************************************************************
1310 * @brief Send UL user data to DU
1314 * Function : l1SendUlUserData
1316 * Functionality: Send UL user data to DU
1319 * @return ROK - success
1322 * ****************************************************************/
1323 uint8_t l1SendUlUserData()
1326 fapi_rx_data_indication_t *rxDataInd;
1327 fapi_pdu_ind_info_t *pduInfo;
1328 uint8_t *pdu = NULLP;
1329 uint16_t byteIdx = 0;
1330 uint32_t msgLen = 0;
1333 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1336 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1339 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1341 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1343 rxDataInd->slot = 0;
1344 rxDataInd->numPdus = 1;
1346 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1347 pduInfo = &rxDataInd->pdus[idx];
1348 pduInfo->handle = 100;
1349 pduInfo->rnti = 100;
1350 pduInfo->harqId = 1;
1351 /* Since user data size = 50bytes and 2 bytes of MAC header and 3 byte of RLC header,
1352 * setting tbsize = 56 from Table 5.1.3.2-1 spec 38.214 */
1353 pduInfo->pdu_length = 56;
1354 pduInfo->ul_cqi = 0;
1355 pduInfo->timingAdvance = 0;
1358 /* Filling pdu with random values for testing */
1359 pduInfo->pduData = NULL;
1360 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1361 if(!pduInfo->pduData)
1363 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1368 pdu = (uint8_t *)pduInfo->pduData;
1372 MAC subheader format is R/F/LCId/L (2/3 bytes)
1374 L is length of PDU i.e 50 bytes
1375 From 38.321 section 6.1.1
1376 From 38.322 section 6.2.2.4, 6.2.2.3 for AM, UM Header
1379 /* Below ulMsg supports 12bit SN for UM mode */
1381 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,
1382 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};
1383 msgLen += 2; /* 2bytes of header */
1384 memcpy(pdu, &ulMsg, msgLen);
1385 byteIdx += msgLen; /* 2 bytes of header */
1387 /* Filling MAC SDU for Padding bytes*/
1388 if(byteIdx < pduInfo->pdu_length)
1391 MAC subheader format is R/R/LCId (1byte)
1392 LCId is 63 for padding
1393 From 38.321 section 6.1.1
1395 pdu[byteIdx++] = 63;
1397 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1400 msgLen += pduInfo->pdu_length;
1402 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1404 /* Send Message to peer */
1407 DU_LOG("\nDEBUG --> PHY STUB : Sending UL User Data[%d] at sfn %d slot %d", cnt+1, sfnValue, slotValue);
1408 /* Sending Rx data indication to MAC */
1409 rxDataInd->sfn = sfnValue;
1410 rxDataInd->slot = slotValue;
1411 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1415 if(pduInfo->pdu_length)
1416 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1417 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1421 /*******************************************************************
1423 * @brief Sends RLC Status PDU to DU
1427 * Function : l1SendStatusPdu
1429 * Functionality: Send RLC Status PDU to DU
1432 * @return ROK - success
1435 * ****************************************************************/
1436 uint8_t l1SendStatusPdu()
1438 fapi_rx_data_indication_t *rxDataInd;
1439 fapi_pdu_ind_info_t *pduInfo;
1440 uint8_t *pdu = NULLP;
1441 uint16_t byteIdx = 0;
1442 uint32_t msgLen = 0;
1445 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1448 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1451 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1453 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1455 rxDataInd->slot = 0;
1456 rxDataInd->numPdus = 1;
1458 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1459 pduInfo = &rxDataInd->pdus[idx];
1460 pduInfo->handle = 100;
1461 pduInfo->rnti = 100;
1462 pduInfo->harqId = 1;
1463 /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1464 * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1465 pduInfo->pdu_length = 24;
1466 pduInfo->ul_cqi = 0;
1467 pduInfo->timingAdvance = 0;
1470 /* Filling pdu with random values for testing */
1471 pduInfo->pduData = NULL;
1472 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1473 if(!pduInfo->pduData)
1475 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1480 pdu = (uint8_t *)pduInfo->pduData;
1483 /* For RLC Status PDU
1484 MAC subheader format is R/F/LCId/L (2/3 bytes)
1486 L is length of Status PDU i.e 3 bytes
1487 From 38.321 section 6.1.1
1489 uint8_t statusPdu[] = {4, msgLen, 0, 0, 0};
1490 msgLen += 2; /* 2bytes of header */
1491 memcpy(pdu, &statusPdu, msgLen);
1492 byteIdx += msgLen; /* 2 bytes of header */
1495 /* Filling MAC SDU for Padding bytes*/
1496 if(byteIdx < pduInfo->pdu_length)
1499 MAC subheader format is R/R/LCId (1byte)
1500 LCId is 63 for padding
1501 From 38.321 section 6.1.1
1503 pdu[byteIdx++] = 63;
1505 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1508 msgLen += pduInfo->pdu_length;
1510 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1512 /* Send Message to peer */
1513 DU_LOG("\nDEBUG --> PHY STUB : Sending RLC status pdu at sfn %d slot %d", sfnValue, slotValue);
1514 /* Sending Rx data indication to MAC */
1515 rxDataInd->sfn = sfnValue;
1516 rxDataInd->slot = slotValue;
1517 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1519 if(pduInfo->pdu_length)
1520 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1521 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1525 /*******************************************************************
1527 * @brief Receives message from MAC
1531 * Function : l1ProcessFapiRequest
1534 * - Receives message from MAC and calls handler
1536 * @params[in] Message type
1542 * ****************************************************************/
1544 void l1ProcessFapiRequest(uint8_t msgType, uint32_t msgLen, void *msg)
1549 case FAPI_PARAM_REQUEST:
1550 l1HdlParamReq(msgLen, msg);
1552 case FAPI_CONFIG_REQUEST:
1553 l1HdlConfigReq(msgLen, msg);
1555 case FAPI_START_REQUEST:
1556 l1HdlStartReq(msgLen, msg);
1558 case FAPI_DL_TTI_REQUEST:
1559 l1HdlDlTtiReq(msgLen, msg);
1561 case FAPI_TX_DATA_REQUEST:
1562 l1HdlTxDataReq(msgLen, msg);
1564 case FAPI_UL_TTI_REQUEST:
1565 l1HdlUlTtiReq(msgLen, msg);
1567 case FAPI_STOP_REQUEST:
1568 l1HdlStopReq(msgLen, msg);
1570 case FAPI_UL_DCI_REQUEST:
1571 l1HdlUlDciReq(msgLen, msg);
1574 DU_LOG("\nERROR --> PHY_STUB: Invalid message type[%x] received at PHY", msgType);
1579 /**********************************************************************
1581 **********************************************************************/