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)
248 memset(&ueDb, 0, sizeof(UeDb));
251 p_fapi_api_queue_elem_t configReqElem = (p_fapi_api_queue_elem_t)msg;
252 fapi_config_req_t *configReq = (fapi_config_req_t *)(configReqElem +1);
254 DU_LOG("\nINFO --> PHY_STUB: Received Config Request in PHY");
256 /* Handling CONFIG RESPONSE */
257 if(l1BldAndSndConfigRsp(configReq)!= ROK)
259 DU_LOG("\nERROR --> PHY_STUB: Failed Sending config Response");
262 MAC_FREE(msg, msgLen);
267 /*******************************************************************
269 * @brief Build and Send CRC Indication
273 * Function : l1BuildAndSendCrcInd
276 * Build and Send CRC Indication
280 * @return ROK - success
283 * ****************************************************************/
284 uint16_t l1BuildAndSendCrcInd(uint16_t slot, uint16_t sfn)
288 fapi_crc_ind_t *crcInd;
290 MAC_ALLOC(crcInd, sizeof(fapi_crc_ind_t));
293 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for CRC Indication Message");
296 memset(crcInd, 0, sizeof(fapi_crc_ind_t));
298 /* TODO: Fill the required values. As of now only 1 CRC status PASS is filled */
303 crcInd->crc[idx].handle = 0;
304 crcInd->crc[idx].rnti = 0;
305 crcInd->crc[idx].harqId = 0;
306 crcInd->crc[idx].tbCrcStatus = 0;
307 crcInd->crc[idx].numCb = 1;
308 crcInd->crc[idx].cbCrcStatus[0] = 0;
309 crcInd->crc[idx].ul_cqi = 0;
310 crcInd->crc[idx].timingAdvance = 0;
311 crcInd->crc[idx].rssi = 0;
313 fillMsgHeader(&crcInd->header, FAPI_CRC_INDICATION, \
314 sizeof(fapi_crc_ind_t) - sizeof(fapi_msg_t));
316 /* Sending RACH indication to MAC */
317 DU_LOG("\nINFO --> PHY STUB: Sending CRC Indication to MAC");
318 procPhyMessages(crcInd->header.msg_id, sizeof(fapi_crc_ind_t), (void *)crcInd);
319 MAC_FREE(crcInd, sizeof(fapi_crc_ind_t));
322 } /* l1BuildAndSendCrcInd */
325 /*******************************************************************
327 * @brief Build and send Rx data indication
331 * Function : l1BuildAndSendRxDataInd
334 * Build and send Rx data indication
338 * @return ROK - success
341 * ****************************************************************/
342 uint16_t l1BuildAndSendRxDataInd(uint16_t slot, uint16_t sfn, fapi_ul_pusch_pdu_t puschPdu)
344 uint8_t idx = 0, ueId = 0;
345 fapi_rx_data_indication_t *rxDataInd =NULLP;
346 fapi_pdu_ind_info_t *pduInfo =NULLP;
347 uint8_t *pdu = NULLP;
348 uint16_t byteIdx = 0;
352 GET_UE_IDX(puschPdu.rnti, ueId);
353 if(!ueDb.ueCb[ueId-1].msg3Sent)
355 ueDb.ueCb[ueId-1].ueId = ueId;
356 ueDb.ueCb[ueId-1].crnti = puschPdu.rnti;
357 ueDb.ueCb[ueId-1].msg3Sent = true;
358 type = MSG_TYPE_MSG3;
361 else if(!ueDb.ueCb[ueId-1].msg5ShortBsrSent)
363 ueDb.ueCb[ueId-1].msg5ShortBsrSent = true;
364 type = MSG_TYPE_SHORT_BSR;
366 else if(!ueDb.ueCb[ueId-1].msg5Sent)
368 ueDb.ueCb[ueId-1].msg5Sent = true;
369 type = MSG_TYPE_MSG5;
371 else if(!ueDb.ueCb[ueId-1].msgRegistrationComp)
373 ueDb.ueCb[ueId-1].msgRegistrationComp = true;
374 type = MSG_TYPE_REGISTRATION_COMPLETE;
376 else if(!ueDb.ueCb[ueId-1].msgSecurityModeComp)
378 ueDb.ueCb[ueId-1].msgSecurityModeComp = true;
379 type = MSG_TYPE_SECURITY_MODE_COMPLETE;
381 else if(!ueDb.ueCb[ueId-1].msgRrcReconfiguration)
383 ueDb.ueCb[ueId-1].msgRrcReconfiguration = true;
384 type = MSG_TYPE_RRC_RECONFIG_COMPLETE;
389 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
392 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
395 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
397 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
398 rxDataInd->sfn = sfn;
399 rxDataInd->slot = slot;
400 rxDataInd->numPdus = 1;
402 pduInfo = &rxDataInd->pdus[idx];
403 pduInfo->handle = puschPdu.handle;
404 pduInfo->rnti = puschPdu.rnti;
405 pduInfo->harqId = puschPdu.puschData.harqProcessId;
406 pduInfo->pdu_length = puschPdu.puschData.tbSize ;
408 pduInfo->timingAdvance = 0;
411 /* Filling pdu with random values for testing */
412 pduInfo->pduData = NULL;
413 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
414 if(!pduInfo->pduData)
416 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
419 memset(pduInfo->pduData, 0, pduInfo->pdu_length);
421 pdu = (uint8_t *)pduInfo->pduData;
427 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG3 PDU ");
428 /* For Initial RRC setup Request,
429 MAC subheader format is R/R/LCId (1byte)
431 From 38.321 section 6.1.1
434 /* Hardcoding MAC PDU */
440 pdu[byteIdx++] = 103;
444 case MSG_TYPE_SHORT_BSR:
446 DU_LOG("\nDEBUG --> PHY_STUB: Forming SHORT BSR PDU ");
448 uint8_t bufferSizeIdx = 6;
451 MAC subheader format is R/R/LcId (1Byte)
453 From 38.321 section 6.1.1
455 pdu[byteIdx++] = 61; // LCID
456 pdu[byteIdx++] = (lcgId << 5) | bufferSizeIdx;
463 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG5 PDU");
464 uint8_t msg5PduLen = 33;
465 /* For RRC setup complete
466 MAC subheader format is R/F/LCId/L (2/3 bytes)
468 L is length of PDU i.e 6bytes here
469 From 38.321 section 6.1.1
471 uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
472 64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
473 184, 56, 0, 0, 0, 0, 0};
475 msg5PduLen += 2; /* 2bytes of header */
476 memcpy(pdu, &msg5, msg5PduLen);
477 byteIdx += msg5PduLen; /* 2 bytes of header */
481 case MSG_TYPE_SECURITY_MODE_COMPLETE:
483 DU_LOG("\nDEBUG --> PHY_STUB: Forming SECURITY MODE COMPLETE PDU");
485 /* For security mode complete where RRC Container is dummy
486 MAC subheader format is R/F/LCId/L (2/3 bytes)
488 L is length of PDU i.e 6bytes here
489 From 38.321 section 6.1.1
491 uint8_t msg[] = {1, pduLen, 0, 3, 0x2a, 0x40, 0, 0, 0, 0, 0, 0, 0, 0};
493 pduLen += 2; /* 2bytes of header */
494 memcpy(pdu, &msg, pduLen);
495 byteIdx += pduLen; /* 2 bytes of header */
498 case MSG_TYPE_REGISTRATION_COMPLETE:
501 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC REGISTRATION COMPLETE PDU");
503 /* For rrc reconfig complete where RRC Container is dummy
504 MAC subheader format is R/F/LCId/L (2/3 bytes)
506 L is length of PDU i.e 6bytes here
507 From 38.321 section 6.1.1
509 uint8_t msg[] = {1, pduLen, 0, 0x04, 0x3a, 0x81, 0xbf, 0, 0x21, 0x80, 0, \
512 pduLen += 2; /* 2bytes of header */
513 memcpy(pdu, &msg, pduLen);
514 byteIdx += pduLen; /* 2 bytes of header */
517 case MSG_TYPE_RRC_RECONFIG_COMPLETE:
519 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC RECONFIGURATION COMPLETE PDU");
521 /* For rrc reconfig complete where RRC Container is dummy
522 MAC subheader format is R/F/LCId/L (2/3 bytes)
524 L is length of PDU i.e 6bytes here
525 From 38.321 section 6.1.1
527 uint8_t msg[] = {1, pduLen, 0, 6, 8, 64, 0, 0, 0, 0, \
530 pduLen += 2; /* 2bytes of header */
531 memcpy(pdu, &msg, pduLen);
532 byteIdx += pduLen; /* 2 bytes of header */
539 } /* End of switch(type) */
540 /* Filling MAC SDU for Padding bytes*/
541 if(byteIdx < pduInfo->pdu_length)
544 MAC subheader format is R/R/LCId (1byte)
545 LCId is 63 for padding
546 From 38.321 section 6.1.1
550 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
553 msgLen += pduInfo->pdu_length;
555 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
557 /* Sending Rx data indication to MAC */
558 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
559 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
561 if(pduInfo->pdu_length)
562 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
563 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
568 /*******************************************************************
570 * @brief Builds and Sends RACH indication to MAC
574 * Function : l1BuildAndSendRachInd
577 * Builds and Sends RACH indication to MAC
579 * @params[in] SFN value
581 * @return ROK - success
584 * ****************************************************************/
585 uint16_t l1BuildAndSendRachInd(uint16_t slot, uint16_t sfn)
588 uint8_t rachPduIdx = 0;
589 uint8_t preamIdx = 0;
590 fapi_rach_pdu_t *rachPdu;
591 fapi_rach_indication_t *rachInd;
593 /* Building RACH indication */
594 MAC_ALLOC(rachInd, sizeof(fapi_rach_indication_t));
597 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rach Indication Message");
600 memset(rachInd, 0, sizeof(fapi_rach_indication_t));
602 rachInd->slot = slot;
603 rachInd->numPdus = 1;
605 rachPdu = &rachInd->rachPdu[rachPduIdx];
606 rachPdu->phyCellId = NR_PCI;
607 rachPdu->symbolIndex = 0;
608 rachPdu->slotIndex = slot;
609 rachPdu->freqIndex = 0;
610 rachPdu->avgRssi = 0;
612 rachPdu->numPreamble = 1;
614 rachPdu->preambleInfo[preamIdx].preambleIndex = 3;
615 rachPdu->preambleInfo[preamIdx].timingAdvance = 0;
616 rachPdu->preambleInfo[preamIdx].preamblePwr = 0;
618 fillMsgHeader(&rachInd->header, FAPI_RACH_INDICATION, \
619 sizeof(fapi_rach_indication_t) - sizeof(fapi_msg_t));
621 /* Sending RACH indication to MAC */
622 DU_LOG("\nINFO --> PHY STUB: Sending RACH Indication to MAC");
623 procPhyMessages(rachInd->header.msg_id, sizeof(fapi_rach_indication_t), (void *)rachInd);
624 MAC_FREE(rachInd, sizeof(fapi_rach_indication_t));
629 /*******************************************************************
631 * @brief Builds and Send the Slot Indication message to MAC
635 * Function : l1BuildAndSendSlotIndication
638 * -Send the Slot indication Message to MAC
640 * @params[in] Message length
641 * config request message pointer
645 * ****************************************************************/
646 uint16_t l1BuildAndSendSlotIndication()
652 fapi_slot_ind_t *slotIndMsg;
654 MAC_ALLOC_SHRABL_BUF(slotIndMsg, sizeof(fapi_slot_ind_t));
657 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for slot Indication Message");
662 memset(slotIndMsg, 0, sizeof(fapi_slot_ind_t));
663 slotIndMsg->sfn = sfnValue;
664 slotIndMsg->slot = slotValue;
666 #ifdef ODU_SLOT_IND_DEBUG_LOG
667 DU_LOG("\n\nDEBUG --> PHY_STUB: Sending Slot Indication [%d : %d] to MAC", sfnValue, slotValue);
670 /* increment for the next TTI */
672 if(sfnValue >= MAX_SFN_VALUE && slotValue > MAX_SLOT_VALUE)
677 else if(slotValue > MAX_SLOT_VALUE)
682 fillMsgHeader(&slotIndMsg->header, FAPI_SLOT_INDICATION, \
683 sizeof(fapi_slot_ind_t) - sizeof(fapi_msg_t));
685 memset(&pst, 0, sizeof(Pst));
686 FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_SLOT_IND);
688 ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
691 DU_LOG("\nERROR --> PHY_STUB: Failed to allocate memory for slot indication buffer");
692 MAC_FREE_SHRABL_BUF(pst.region, pst.pool, slotIndMsg, sizeof(fapi_slot_ind_t));
695 CMCHKPK(oduPackPointer, (PTR)slotIndMsg, mBuf);
696 ODU_POST_TASK(&pst, mBuf);
702 /*******************************************************************
704 * @brief Handles start request received from MAC
708 * Function : l1HdlStartReq
711 * -Handles start request received from MAC
713 * @params[in] Message length
714 * config request message pointer
718 * ****************************************************************/
720 S16 l1HdlStartReq(uint32_t msgLen, void *msg)
723 if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
725 l1HdlSlotIndicaion(FALSE);
726 l1StartConsoleHandler();
727 MAC_FREE(msg, msgLen);
731 DU_LOG("\nINFO --> PHY_STUB: Received Start Req in PHY State %d", lwrMacCb.phyState);
732 MAC_FREE(msg, msgLen);
739 /*******************************************************************
741 * @brief Handles Dl Tti request received from MAC
745 * Function : l1HdlDlTtiReq
748 * -Handles Dl Tti request received from MAC
750 * @params[in] Message length
751 * Dl Tti request message pointer
755 * ****************************************************************/
757 S16 l1HdlDlTtiReq(uint16_t msgLen, void *msg)
760 p_fapi_api_queue_elem_t dlTtiElem = (p_fapi_api_queue_elem_t)msg;
761 fapi_dl_tti_req_t *dlTtiReq = (fapi_dl_tti_req_t *)(dlTtiElem +1);
763 uint8_t pduCount = 0;
765 #ifdef ODU_SLOT_IND_DEBUG_LOG
766 if(dlTtiReq->nPdus == 0)
768 DU_LOG("\nDEBUG --> PHY_STUB: No PDU in DL TTI Request");
772 DU_LOG("\nDEBUG --> PHY STUB: DL TTI Request at sfn=%d slot=%d",dlTtiReq->sfn,dlTtiReq->slot);
776 for(pduCount=0; pduCount<dlTtiReq->nPdus; pduCount++)
778 if(dlTtiReq->pdus[pduCount].pduType == 3) //SSB_PDU_TYPE
780 DU_LOG("\nINFO --> PHY_STUB: SSB PDU");
782 else if(dlTtiReq->pdus[pduCount].pduType == 0)
784 DU_LOG("\nINFO --> PHY_STUB: PDCCH PDU");
786 else if(dlTtiReq->pdus[pduCount].pduType == 1)
788 DU_LOG("\nINFO --> PHY_STUB: PDSCH PDU");
792 /* Free FAPI message */
793 MAC_FREE(msg, msgLen);
798 /*******************************************************************
800 * @brief Handles tx_data request received from MAC
804 * Function : l1HdlTxDataReq
807 * -Handles tx_data request received from MAC
809 * @params[in] Message length
810 * tx_data request message pointer
814 * ****************************************************************/
816 S16 l1HdlTxDataReq(uint16_t msgLen, void *msg)
819 p_fapi_api_queue_elem_t txDataElem = (p_fapi_api_queue_elem_t)msg;
820 fapi_tx_data_req_t *txDataReq = (fapi_tx_data_req_t *)(txDataElem +1);
822 DU_LOG("\nINFO --> PHY STUB: TX DATA Request at sfn=%d slot=%d",txDataReq->sfn,txDataReq->slot);
826 DU_LOG("\nINFO --> PHY_STUB: TxDataPdu for DED MSG sent");
830 MAC_FREE(msg, msgLen);
836 /*******************************************************************
838 * @brief Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
842 * Function : fillPucchF0F1PduInfo
845 * Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
847 * @params[in] fapi_uci_o_pucch_f0f1_t *
849 * @return ROK - success
852 * ****************************************************************/
853 uint8_t fillPucchF0F1PduInfo(fapi_uci_o_pucch_f0f1_t *pduInfo, fapi_ul_pucch_pdu_t pucchPdu)
857 pduInfo->handle = pucchPdu.handle;
858 pduInfo->pduBitmap = 1; //hardcoded for SR
859 pduInfo->pucchFormat = pucchPdu.formatType;
861 pduInfo->rnti = pucchPdu.rnti;
862 pduInfo->timingAdvance = 0;
864 if(pduInfo->pduBitmap & SR_PDU_BITMASK)
866 pduInfo->srInfo.srIndication = SR_DETECTED;
867 pduInfo->srInfo.srConfidenceLevel = CONFDC_LEVEL_GOOD;
869 if(pduInfo->pduBitmap & HARQ_PDU_BITMASK)
871 pduInfo->harqInfo.numHarq++;
872 pduInfo->harqInfo.harqConfidenceLevel = CONFDC_LEVEL_GOOD;
873 for(idx = 0; idx < pduInfo->harqInfo.numHarq; idx++)
875 pduInfo->harqInfo.harqValue[idx] = HARQ_PASS;
880 /*******************************************************************
882 * @brief Fills UCI Pdu Information
886 * Function : fillUciPduInfo
889 * Fills UCI Pdu Information
891 * @params[in] Pointer to uciPdu
893 * @return ROK - success
896 * ****************************************************************/
897 uint8_t fillUciPduInfo(fapi_uci_pdu_info_t *uciPdu, fapi_ul_pucch_pdu_t pucchPdu)
901 /*TODO: The pduType is hardcoded here to support
902 UCI Ind for PUCCH forat0/format1. This is to be
903 modified when we get SR form UE */
904 uciPdu->pduType = UCI_IND_PUCCH_F0F1;
905 switch(uciPdu->pduType)
909 case UCI_IND_PUCCH_F0F1:
911 fapi_uci_o_pucch_f0f1_t *pduInfo = NULLP;
913 pduInfo = &uciPdu->uci.uciPucchF0F1;
914 ret = fillPucchF0F1PduInfo(pduInfo, pucchPdu);
915 uciPdu->pduSize = sizeof(fapi_uci_o_pucch_f0f1_t);
918 case UCI_IND_PUCCH_F2F3F4:
921 DU_LOG("\nERROR --> PHY_STUB: Invalid Pdu Type %d", uciPdu->pduType);
927 /*******************************************************************
929 * @brief Build and send Uci indication
933 * Function : l1BuildAndSendUciInd
936 * Build and send Uci indication
940 * @return ROK - success
943 * ****************************************************************/
944 uint8_t l1BuildAndSendUciInd(uint16_t slot, uint16_t sfn, fapi_ul_pucch_pdu_t pucchPdu)
947 uint8_t nUciPdus = 0;
950 fapi_uci_indication_t *uciInd = NULLP;
952 MAC_ALLOC(uciInd, sizeof(fapi_uci_indication_t));
955 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for UCI Indication");
958 memset(uciInd, 0, sizeof(fapi_uci_indication_t));
961 uciInd->numUcis = 1; //consdering the UCI Ind for SR
962 nUciPdus = uciInd->numUcis;
965 ret = fillUciPduInfo(&uciInd->uciPdu[uciIdx], pucchPdu);
971 msgLen = sizeof(fapi_uci_indication_t)- sizeof(fapi_msg_t);
972 fillMsgHeader(&uciInd->header, FAPI_UCI_INDICATION, msgLen);
974 /* Sending UCI indication to MAC */
975 DU_LOG("\nINFO --> PHY STUB: Sending UCI Indication to MAC");
976 procPhyMessages(uciInd->header.msg_id, sizeof(fapi_uci_indication_t), (void *)uciInd);
978 MAC_FREE(uciInd, sizeof(fapi_uci_indication_t));
983 /*******************************************************************
985 * @brief Handles Ul Tti request received from MAC
989 * Function : l1HdlUlTtiReq
992 * -Handles Ul Tti request received from MAC
994 * @params[in] Message length
995 * Ul Tti request message pointer
999 * ****************************************************************/
1001 S16 l1HdlUlTtiReq(uint16_t msgLen, void *msg)
1004 p_fapi_api_queue_elem_t ulTtiElem = (p_fapi_api_queue_elem_t)msg;
1005 fapi_ul_tti_req_t *ulTtiReq = (fapi_ul_tti_req_t *)(ulTtiElem +1);
1006 uint8_t numPdus = ulTtiReq->nPdus;
1008 #ifdef ODU_SLOT_IND_DEBUG_LOG
1011 DU_LOG("\nINFO --> PHY STUB: No PDU received in UL TTI Req");
1015 DU_LOG("\nINFO --> PHY STUB: Received UL TTI Request");
1021 if(ulTtiReq->pdus[numPdus-1].pduType == 0)
1023 DU_LOG("\nINFO --> PHY STUB: PRACH PDU");
1025 if(ulTtiReq->pdus[numPdus-1].pduType == 1)
1027 DU_LOG("\nINFO --> PHY STUB: PUSCH PDU");
1028 l1BuildAndSendRxDataInd(ulTtiReq->slot, ulTtiReq->sfn, \
1029 ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu);
1031 if(ulTtiReq->pdus[numPdus-1].pduType == 2)
1033 DU_LOG("\nINFO --> PHY STUB: PUCCH PDU");
1034 fapi_ul_tti_req_t ulTtiSlotInd;
1035 memset(&ulTtiSlotInd, 0, sizeof(fapi_ul_tti_req_t));
1036 ulTtiSlotInd.slot = ulTtiReq->slot;
1037 ulTtiSlotInd.sfn = ulTtiReq->sfn;
1038 ADD_DELTA_TO_TIME(ulTtiSlotInd, ulTtiSlotInd, SLOT_DELAY);
1039 l1BuildAndSendUciInd(ulTtiSlotInd.slot, ulTtiSlotInd.sfn, \
1040 ulTtiReq->pdus[numPdus-1].pdu.pucch_pdu);
1045 /* TODO: [SFN:SLOT] at which RACH Indication is sent should be calculated
1046 * based on PRACH cfg index */
1047 /* Send RACH Ind to L2 for first UE */
1048 if(ueDb.ueCb[UE_IDX_0].rachIndSent == false && ulTtiReq->sfn == 16 && ulTtiReq->slot == 6)
1050 ueDb.ueCb[UE_IDX_0].rachIndSent = true;
1051 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn);
1054 /* Send RACH Ind to L2 for second UE */
1055 if(ueDb.ueCb[UE_IDX_1].rachIndSent == false && ulTtiReq->sfn == 304 && ulTtiReq->slot == 0)
1057 ueDb.ueCb[UE_IDX_1].rachIndSent = true;
1058 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn);
1062 /* Send RACH Ind to L2 for third UE */
1063 if(ueDb.ueCb[UE_IDX_2].rachIndSent == false && ulTtiReq->sfn == 526 && ulTtiReq->slot == 0)
1065 ueDb.ueCb[UE_IDX_2].rachIndSent = true;
1066 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn);
1069 MAC_FREE(msg, msgLen);
1074 /*******************************************************************
1076 * @brief Builds and Send the stop Indication message to MAC
1080 * Function : l1BuildAndSendStopInd
1083 * -Send the Stop indication Message to MAC
1088 * ****************************************************************/
1089 uint16_t l1BuildAndSendStopInd()
1093 Buffer *mBuf = NULLP;
1094 fapi_stop_ind_t *stopIndMsg = NULLP;
1095 uint32_t msgLen = 0;
1097 MAC_ALLOC_SHRABL_BUF(stopIndMsg, sizeof(fapi_stop_ind_t));
1100 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for stop Indication Message");
1105 fillMsgHeader(&stopIndMsg->header, FAPI_STOP_INDICATION, msgLen);
1106 DU_LOG("\n\nINFO --> PHY_STUB: Processing Stop indication to MAC");
1108 memset(&pst, 0, sizeof(Pst));
1109 FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_STOP_IND);
1110 ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
1113 DU_LOG("\nERROR --> PHY_STUB: Failed to allocate memory for slot indication buffer");
1114 MAC_FREE_SHRABL_BUF(pst.region, pst.pool, stopIndMsg, sizeof(fapi_stop_ind_t));
1117 CMCHKPK(oduPackPointer, (PTR)stopIndMsg, mBuf);
1118 ODU_POST_TASK(&pst, mBuf);
1124 /*******************************************************************
1126 * @brief Handles stop request received from MAC
1130 * Function : l1HdlStopReq
1133 * -Handles stop request received from MAC
1135 * @params[in] Message length
1136 * stop request message pointer
1140 * ****************************************************************/
1142 S16 l1HdlStopReq(uint32_t msgLen, void *msg)
1145 if(lwrMacCb.phyState == PHY_STATE_RUNNING)
1147 l1HdlSlotIndicaion(TRUE);
1149 /* Initialize all global variables */
1152 memset(&ueDb, 0, sizeof(UeDb));
1154 DU_LOG("\nINFO --> PHY_STUB: Slot Indication is stopped successfully");
1155 MAC_FREE(msg, msgLen);
1159 DU_LOG("\nINFO --> PHY_STUB: Received Stop Req in PHY State %d", lwrMacCb.phyState);
1160 MAC_FREE(msg, msgLen);
1168 /*******************************************************************
1170 * @brief Build And Send Rx Data Ind for Msg5
1174 * Function : l1BuildAndSendMsg5
1176 * Functionality: Build And Send Rx Data Ind for Msg5
1180 * @return ROK - success
1183 * ****************************************************************/
1184 uint8_t l1BuildAndSendMsg5(uint16_t sfn, uint16_t slot)
1188 fapi_rx_data_indication_t *rxDataInd;
1189 fapi_pdu_ind_info_t *pduInfo;
1191 uint16_t byteIdx = 0;
1192 uint32_t msgLen = 0;
1194 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1197 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication for msg5");
1200 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1202 /* TODO: Fill the required values */
1203 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1204 rxDataInd->sfn = sfn;
1205 rxDataInd->slot = slot;
1206 rxDataInd->numPdus = 1;
1208 pduInfo = &rxDataInd->pdus[idx];
1209 pduInfo->handle = 100;
1210 pduInfo->rnti = 100;
1211 pduInfo->harqId = 1;
1212 pduInfo->pdu_length = 25;
1213 pduInfo->ul_cqi = 0;
1214 pduInfo->timingAdvance = 0;
1217 /* Filling pdu with random values for testing */
1218 pduInfo->pduData = NULL;
1219 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1220 if(!pduInfo->pduData)
1222 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1227 pdu = (uint8_t *)pduInfo->pduData;
1229 uint8_t msg5PduLen = 33;
1230 /* For RRC setup complete
1231 MAC subheader format is R/F/LCId/L (2/3 bytes)
1233 L is length of PDU i.e 6bytes here
1234 From 38.321 section 6.1.1
1236 uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
1237 64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
1238 184, 56, 0, 0, 0, 0, 0};
1240 msg5PduLen += 2; /* 2bytes of header */
1241 memcpy(pdu, &msg5, msg5PduLen);
1242 byteIdx += msg5PduLen; /* 2 bytes of header */
1244 /* Filling MAC SDU for Padding bytes*/
1245 if(byteIdx < pduInfo->pdu_length)
1248 MAC subheader format is R/R/LCId (1byte)
1249 LCId is 63 for padding
1250 From 38.321 section 6.1.1
1252 pdu[byteIdx++] = 63;
1254 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1257 msgLen += pduInfo->pdu_length;
1259 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1261 /* Sending Rx data indication to MAC */
1262 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
1263 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1265 if(pduInfo->pdu_length)
1266 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1267 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1273 /*******************************************************************
1275 * @brief Handles Ul Dci request received from MAC
1279 * Function : l1HdlUlDciReq
1282 * -Handles Ul Dci request received from MAC
1284 * @params[in] Message length
1285 * Ul Dci request message pointer
1289 * ****************************************************************/
1291 S16 l1HdlUlDciReq(uint16_t msgLen, void *msg)
1294 p_fapi_api_queue_elem_t ulDciElem = (p_fapi_api_queue_elem_t)msg;
1295 fapi_ul_dci_req_t *ulDciReq = (fapi_ul_dci_req_t *)(ulDciElem +1);
1296 uint8_t numPdus = ulDciReq->numPdus;
1300 if(ulDciReq->pdus[numPdus-1].pduType == 0)
1302 DU_LOG("\nINFO --> PHY STUB: Received UL DCI Request for PDCCH PDU");
1303 //l1BuildAndSendMsg5(ulDciReq->sfn, ulDciReq->slot);
1309 MAC_FREE(msg, msgLen);
1314 /*******************************************************************
1316 * @brief Send UL user data to DU
1320 * Function : l1SendUlUserData
1322 * Functionality: Send UL user data to DU
1325 * @return ROK - success
1328 * ****************************************************************/
1329 uint8_t l1SendUlUserData(uint8_t drbId, uint8_t ueIdx)
1332 fapi_rx_data_indication_t *rxDataInd;
1333 fapi_pdu_ind_info_t *pduInfo;
1334 uint8_t *pdu = NULLP;
1335 uint16_t byteIdx = 0;
1336 uint32_t msgLen = 0;
1340 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1343 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1346 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1348 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1350 rxDataInd->slot = 0;
1351 rxDataInd->numPdus = 1;
1353 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1354 pduInfo = &rxDataInd->pdus[idx];
1355 pduInfo->handle = ueIdx + ODU_START_CRNTI;
1356 pduInfo->rnti = ueIdx + ODU_START_CRNTI;
1357 pduInfo->harqId = 1;
1358 /* Since user data size = 50bytes and 2 bytes of MAC header and 3 byte of RLC header,
1359 * setting tbsize = 56 from Table 5.1.3.2-1 spec 38.214 */
1360 pduInfo->pdu_length = 56;
1361 pduInfo->ul_cqi = 0;
1362 pduInfo->timingAdvance = 0;
1365 /* Filling pdu with random values for testing */
1366 pduInfo->pduData = NULL;
1367 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1368 if(!pduInfo->pduData)
1370 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1375 pdu = (uint8_t *)pduInfo->pduData;
1379 MAC subheader format is R/F/LCId/L (2/3 bytes)
1381 L is length of PDU i.e 50 bytes
1382 From 38.321 section 6.1.1
1383 From 38.322 section 6.2.2.4, 6.2.2.3 for AM, UM Header
1386 /* Below ulMsg supports 12bit SN for UM mode */
1388 lcId = MIN_DRB_LCID + drbId;
1389 uint8_t ulMsg[] = {lcId, 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,
1390 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};
1391 msgLen += 2; /* 2bytes of header */
1392 memcpy(pdu, &ulMsg, msgLen);
1393 byteIdx += msgLen; /* 2 bytes of header */
1395 /* Filling MAC SDU for Padding bytes*/
1396 if(byteIdx < pduInfo->pdu_length)
1399 MAC subheader format is R/R/LCId (1byte)
1400 LCId is 63 for padding
1401 From 38.321 section 6.1.1
1403 pdu[byteIdx++] = 63;
1405 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1408 msgLen += pduInfo->pdu_length;
1410 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1412 /* Send Message to peer */
1413 while(cnt < NUM_UL_PACKETS)
1415 DU_LOG("\nDEBUG --> PHY STUB : Sending UL User Data[%d][LCID:%d] at sfn %d slot %d", cnt+1, lcId, sfnValue, slotValue);
1416 /* Sending Rx data indication to MAC */
1417 rxDataInd->sfn = sfnValue;
1418 rxDataInd->slot = slotValue;
1419 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1423 if(pduInfo->pdu_length)
1424 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1425 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1429 /*******************************************************************
1431 * @brief Sends RLC Status PDU to DU
1435 * Function : l1SendStatusPdu
1437 * Functionality: Send RLC Status PDU to DU
1440 * @return ROK - success
1443 * ****************************************************************/
1444 uint8_t l1SendStatusPdu()
1446 fapi_rx_data_indication_t *rxDataInd;
1447 fapi_pdu_ind_info_t *pduInfo;
1448 uint8_t *pdu = NULLP;
1449 uint16_t byteIdx = 0;
1450 uint32_t msgLen = 0;
1453 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1456 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1459 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1461 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1463 rxDataInd->slot = 0;
1464 rxDataInd->numPdus = 1;
1466 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1467 pduInfo = &rxDataInd->pdus[idx];
1468 pduInfo->handle = 100;
1469 pduInfo->rnti = 100;
1470 pduInfo->harqId = 1;
1471 /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1472 * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1473 pduInfo->pdu_length = 24;
1474 pduInfo->ul_cqi = 0;
1475 pduInfo->timingAdvance = 0;
1478 /* Filling pdu with random values for testing */
1479 pduInfo->pduData = NULL;
1480 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1481 if(!pduInfo->pduData)
1483 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1488 pdu = (uint8_t *)pduInfo->pduData;
1491 /* For RLC Status PDU
1492 MAC subheader format is R/F/LCId/L (2/3 bytes)
1494 L is length of Status PDU i.e 3 bytes
1495 From 38.321 section 6.1.1
1497 uint8_t statusPdu[] = {4, msgLen, 0, 0, 0};
1498 msgLen += 2; /* 2bytes of header */
1499 memcpy(pdu, &statusPdu, msgLen);
1500 byteIdx += msgLen; /* 2 bytes of header */
1503 /* Filling MAC SDU for Padding bytes*/
1504 if(byteIdx < pduInfo->pdu_length)
1507 MAC subheader format is R/R/LCId (1byte)
1508 LCId is 63 for padding
1509 From 38.321 section 6.1.1
1511 pdu[byteIdx++] = 63;
1513 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1516 msgLen += pduInfo->pdu_length;
1518 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1520 /* Send Message to peer */
1521 DU_LOG("\nDEBUG --> PHY STUB : Sending RLC status pdu at sfn %d slot %d", sfnValue, slotValue);
1522 /* Sending Rx data indication to MAC */
1523 rxDataInd->sfn = sfnValue;
1524 rxDataInd->slot = slotValue;
1525 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1527 if(pduInfo->pdu_length)
1528 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1529 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1533 /*******************************************************************
1535 * @brief Receives message from MAC
1539 * Function : l1ProcessFapiRequest
1542 * - Receives message from MAC and calls handler
1544 * @params[in] Message type
1550 * ****************************************************************/
1552 void l1ProcessFapiRequest(uint8_t msgType, uint32_t msgLen, void *msg)
1557 case FAPI_PARAM_REQUEST:
1558 l1HdlParamReq(msgLen, msg);
1560 case FAPI_CONFIG_REQUEST:
1561 l1HdlConfigReq(msgLen, msg);
1563 case FAPI_START_REQUEST:
1564 l1HdlStartReq(msgLen, msg);
1566 case FAPI_DL_TTI_REQUEST:
1567 l1HdlDlTtiReq(msgLen, msg);
1569 case FAPI_TX_DATA_REQUEST:
1570 l1HdlTxDataReq(msgLen, msg);
1572 case FAPI_UL_TTI_REQUEST:
1573 l1HdlUlTtiReq(msgLen, msg);
1575 case FAPI_STOP_REQUEST:
1576 l1HdlStopReq(msgLen, msg);
1578 case FAPI_UL_DCI_REQUEST:
1579 l1HdlUlDciReq(msgLen, msg);
1582 DU_LOG("\nERROR --> PHY_STUB: Invalid message type[%x] received at PHY", msgType);
1589 /*******************************************************************
1591 * @brief Builds and Send the BSR message to MAC
1595 * Function : l1BuildAndSendBSR
1598 * -Send the BSR Message to MAC
1600 * @params[in] BSR type
1601 * array of LCGID and BSIdx
1604 *****************************************************************/
1605 uint16_t l1BuildAndSendBSR(uint8_t ueIdx, BsrType bsrType,\
1606 LcgBufferSize lcgBsIdx[MAX_NUM_LOGICAL_CHANNEL_GROUPS])
1608 fapi_rx_data_indication_t *rxDataInd;
1609 fapi_pdu_ind_info_t *pduInfo;
1610 uint8_t *pdu = NULLP;
1611 uint16_t byteIdx = 0;
1612 uint32_t msgLen = 0;
1613 uint8_t pduIdx = 0, lcgIdx = 0, lcgIdxPos = 0;
1615 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1618 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1621 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1623 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1625 rxDataInd->slot = 0;
1626 rxDataInd->numPdus = 1;
1628 pduInfo = &rxDataInd->pdus[pduIdx];
1629 pduInfo->handle = (ODU_START_CRNTI + ueIdx);
1630 pduInfo->rnti = (ODU_START_CRNTI + ueIdx);
1631 pduInfo->harqId = 1;
1633 /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1634 * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1635 pduInfo->pdu_length = 24;
1636 pduInfo->ul_cqi = 0;
1637 pduInfo->timingAdvance = 0;
1640 /* Filling pdu with random values for testing */
1641 pduInfo->pduData = NULL;
1642 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1643 if(!pduInfo->pduData)
1645 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1646 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1651 pdu = (uint8_t *)pduInfo->pduData;
1657 DU_LOG("\nDEBUG --> PHY_STUB: Forming SHORT BSR PDU ");
1660 * MAC subheader format is R/R/LcId (1Byte)
1662 * From 38.321 section 6.1.1
1664 pdu[byteIdx++] = 61; // LCID
1665 pdu[byteIdx++] = (lcgBsIdx[0].lcgId << 5) | lcgBsIdx[0].bsIdx;
1671 DU_LOG("\nDEBUG --> PHY_STUB: Forming LONG BSR PDU ");
1674 * MAC subheader format is R/R/LcId (1Byte)
1676 * From 38.321 section 6.1.1
1678 pdu[byteIdx++] = 62; // LCID
1680 /*Octet where lcgId bitmap will be present*/
1681 lcgIdxPos = byteIdx;
1683 for(lcgIdx = 0; lcgIdx < MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
1685 if(lcgBsIdx[lcgIdx].bsIdx > 0)
1687 pdu[lcgIdxPos] |= 1 << lcgBsIdx[lcgIdx].lcgId;
1688 pdu[byteIdx++] = lcgBsIdx[lcgIdx].bsIdx;
1697 DU_LOG("\nERROR --> PHY_STUB: Incorrect BSR type:%d!", bsrType);
1698 if(pduInfo->pdu_length)
1699 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1700 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1704 /* Filling MAC SDU for Padding bytes*/
1705 if(byteIdx < pduInfo->pdu_length)
1708 * MAC subheader format is R/R/LCId (1byte)
1709 * LCId is 63 for padding
1710 * From 38.321 section 6.1.1
1712 pdu[byteIdx++] = 63;
1714 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1717 msgLen += pduInfo->pdu_length;
1718 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1720 /* Sending Rx data indication to MAC */
1721 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
1722 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1724 if(pduInfo->pdu_length)
1725 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1726 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1731 /**********************************************************************
1733 **********************************************************************/