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"
30 #include "nr5g_fapi_internal.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 start the uplink data
45 * Function : startUlData
47 * Functionality: start the uplink data
53 * ****************************************************************/
57 uint8_t ueIdx=0, drbIdx=0;
59 /* Start Pumping data from PHY stub to DU */
60 for(ueIdx=0; ueIdx < phyDb.ueDb.numActvUe; ueIdx++)
62 for(drbIdx = 0; drbIdx < NUM_DRB_TO_PUMP_DATA; drbIdx++) //Number of DRB times the loop will run
64 DU_LOG("\nDEBUG --> PHY STUB: Sending UL User Data[DrbId:%d] for UEIdx %d\n",drbIdx,ueIdx);
65 l1SendUlUserData(drbIdx,ueIdx);
70 /*******************************************************************
72 * @brief Builds and sends param response to MAC CL
76 * Function : l1BldAndSndParamRsp
79 * - Builds and sends param response to MAC
81 * @params[in] Config request message pointer
82 * @return ROK - success
85 * ****************************************************************/
86 S16 l1BldAndSndParamRsp(void *msg)
91 fapi_param_resp_t *fapiParamRsp;
93 MAC_ALLOC(fapiParamRsp, sizeof(fapi_param_resp_t));
96 DU_LOG("\nERROR --> PHY STUB: Memory allocation failed");
101 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_RELEASE_CAPABILITY_TAG, sizeof(uint16_t), 1, &msgLen);
102 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PHY_STATE_TAG, sizeof(uint16_t), 0, &msgLen);
103 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SKIP_BLANK_DL_CONFIG_TAG, sizeof(uint8_t), 0, &msgLen);
104 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SKIP_BLANK_UL_CONFIG_TAG, sizeof(uint8_t), 0, &msgLen);
105 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_NUM_CONFIG_TLVS_TO_REPORT_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
108 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CYCLIC_PREFIX_TAG, sizeof(uint8_t), 1, &msgLen);
109 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_SUBCARRIER_SPACING_DL_TAG, sizeof(uint8_t), 1, &msgLen);
110 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_BANDWIDTH_DL_TAG, sizeof(uint16_t), 1, &msgLen);
111 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_SUBCARRIER_SPACING_UL_TAG, sizeof(uint8_t), 0, &msgLen);
112 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_BANDWIDTH_UL_TAG, sizeof(uint16_t), 0, &msgLen);
115 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CCE_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
116 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CORESET_OUTSIDE_FIRST_3_OFDM_SYMS_OF_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
117 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRECODER_GRANULARITY_CORESET_TAG, sizeof(uint8_t), 0, &msgLen);
118 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDCCH_MU_MIMO_TAG, sizeof(uint8_t), 0, &msgLen);
119 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDCCH_PRECODER_CYCLING_TAG, sizeof(uint8_t), 0, &msgLen);
120 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDCCHS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
123 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUCCH_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
124 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PUCCHS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
127 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
128 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_ALLOCATION_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
129 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_VRB_TO_PRB_MAPPING_TAG, sizeof(uint8_t), 0, &msgLen);
130 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_CBG_TAG, sizeof(uint8_t), 0, &msgLen);
131 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_CONFIG_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
132 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_MAX_LENGTH_TAG, sizeof(uint8_t), 0, &msgLen);
133 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_ADDITIONAL_POS_TAG, sizeof(uint8_t), 0, &msgLen);
134 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDSCHS_TBS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
135 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_NUMBER_MIMO_LAYERS_PDSCH_TAG, sizeof(uint8_t), 0, &msgLen);
136 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_MAX_MODULATION_ORDER_DL_TAG, sizeof(uint8_t), 0, &msgLen);
137 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_MU_MIMO_USERS_DL_TAG, sizeof(uint8_t), 0, &msgLen);
138 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DATA_IN_DMRS_SYMBOLS_TAG, sizeof(uint8_t), 0, &msgLen);
139 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PREMPTIONSUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
140 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_NON_SLOT_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
143 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_UCI_MUX_ULSCH_IN_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
144 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_UCI_ONLY_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
145 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_FREQUENCY_HOPPING_TAG, sizeof(uint8_t), 0, &msgLen);
146 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_CONFIG_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
147 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_MAX_LEN_TAG, sizeof(uint8_t), 0, &msgLen);
148 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_ADDITIONAL_POS_TAG, sizeof(uint8_t), 0, &msgLen);
149 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_CBG_TAG, sizeof(uint8_t), 0, &msgLen);
150 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
151 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_ALLOCATION_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
152 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_VRB_TO_PRB_MAPPING_TAG, sizeof(uint8_t), 0, &msgLen);
153 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_MAX_PTRS_PORTS_TAG, sizeof(uint8_t), 0, &msgLen);
154 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDUSCHS_TBS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
155 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_NUMBER_MIMO_LAYERS_NON_CB_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
156 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_MODULATION_ORDER_UL_TAG, sizeof(uint8_t), 0, &msgLen);
157 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_MU_MIMO_USERS_UL_TAG, sizeof(uint8_t), 0, &msgLen);
158 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_DFTS_OFDM_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
159 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_AGGREGATION_FACTOR_TAG, sizeof(uint8_t), 0, &msgLen);
162 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_LONG_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
163 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_SHORT_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
164 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_RESTRICTED_SETS_TAG, sizeof(uint8_t), 0, &msgLen);
165 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PRACH_FD_OCCASIONS_IN_A_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
167 /* MEASUREMENT TAG */
168 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_RSSI_MEASUREMENT_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
170 fapiParamRsp->number_of_tlvs = index;
171 msgLen += sizeof(fapi_param_resp_t) - sizeof(fapi_msg_t);
172 fillMsgHeader(&fapiParamRsp->header, FAPI_PARAM_RESPONSE, msgLen);
173 fapiParamRsp->error_code = MSG_OK;
175 DU_LOG("\nINFO --> PHY_STUB: Sending Param Request to Lower Mac");
176 procPhyMessages(fapiParamRsp->header.msg_id, sizeof(fapi_param_resp_t), (void *)fapiParamRsp);
177 MAC_FREE(fapiParamRsp, sizeof(fapi_param_resp_t));
182 /*******************************************************************
184 * @brief Builds and sends config response to lower mac
188 * Function : l1BldAndSndConfigRsp
191 * - Builds and sends config response to MAC
193 * @params[in] Config request message pointer
194 * @return ROK - success
197 * ****************************************************************/
199 S16 l1BldAndSndConfigRsp(void *msg)
203 fapi_config_resp_t *fapiConfigRsp;
205 MAC_ALLOC(fapiConfigRsp, sizeof(fapi_config_resp_t));
208 DU_LOG("\nERROR --> PHY STUB: Memory allocation failed");
211 memset(fapiConfigRsp, 0, sizeof(fapi_config_resp_t));
212 fapiConfigRsp->number_of_invalid_tlvs = NULLP;
213 fapiConfigRsp->number_of_inv_tlvs_idle_only = NULLP;
214 fapiConfigRsp->number_of_missing_tlvs = NULLP;
215 fapiConfigRsp->error_code = MSG_OK;
216 msgLen = sizeof(fapi_config_resp_t) - sizeof(fapi_msg_t);
217 fillMsgHeader(&fapiConfigRsp->header, FAPI_CONFIG_RESPONSE, msgLen);
219 DU_LOG("\nINFO --> PHY_STUB: Sending Config Response to Lower Mac");
221 procPhyMessages(fapiConfigRsp->header.msg_id, \
222 sizeof(fapi_config_resp_t), (void *)fapiConfigRsp);
223 MAC_FREE(fapiConfigRsp, sizeof(fapi_config_resp_t));
227 /*******************************************************************
229 * @brief Handles param request received from MAC
233 * Function : l1HdlParamReq
236 * -Handles param request received from MAC
238 * @params[in] Message length
239 * Param request message pointer
243 * ****************************************************************/
245 void l1HdlParamReq(uint32_t msgLen, void *msg)
248 DU_LOG("\nINFO --> PHY_STUB: Received Param Request in PHY");
250 /* Build and send PARAM RESPONSE */
251 if(l1BldAndSndParamRsp(msg)!= ROK)
253 DU_LOG("\nERROR --> PHY_STUB: Failed Sending Param Response");
255 MAC_FREE(msg, sizeof(fapi_param_req_t));
259 /*******************************************************************
261 * @brief Handles config request received from MAC
265 * Function : l1HdlConfigReq
268 * -Handles config request received from MAC
270 * @params[in] Message length
271 * config request message pointer
275 * ****************************************************************/
277 void l1HdlConfigReq(uint32_t msgLen, void *msg)
279 memset(&phyDb.ueDb, 0, sizeof(UeDb));
280 cmInetAddr((char *)SOURCE_DU_IPV4_ADDR, &phyDb.ipCfgInfo.sourceDu);
281 cmInetAddr((char *)DESTINATION_DU_IPV4_ADDR, &phyDb.ipCfgInfo.destinationDu);
282 phyDb.ipCfgInfo.portNumber = PORT_NUMBER;
283 phyDb.isServer = true;
286 p_fapi_api_queue_elem_t configReqElem = (p_fapi_api_queue_elem_t)msg;
287 fapi_config_req_t *configReq = (fapi_config_req_t *)(configReqElem +1);
289 DU_LOG("\nINFO --> PHY_STUB: Received Config Request in PHY");
291 /* Handling CONFIG RESPONSE */
292 if(l1BldAndSndConfigRsp(configReq)!= ROK)
294 DU_LOG("\nERROR --> PHY_STUB: Failed Sending config Response");
297 MAC_FREE(msg, msgLen);
302 /*******************************************************************
304 * @brief Build and Send CRC Indication
308 * Function : l1BuildAndSendCrcInd
311 * Build and Send CRC Indication
315 * @return ROK - success
318 * ****************************************************************/
319 uint16_t l1BuildAndSendCrcInd(uint16_t slot, uint16_t sfn, fapi_ul_pusch_pdu_t puschPdu)
321 uint8_t result[]={0,//MSG3
323 0,//MSG5 RRC Setup Complete
324 0,//Security Mode Complete
325 0,//Registraion Complete
326 0,//RRC Reconfiguration Complete
343 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
347 static uint8_t ind=0;
349 fapi_crc_ind_t *crcInd;
351 MAC_ALLOC(crcInd, sizeof(fapi_crc_ind_t));
354 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for CRC Indication Message");
357 memset(crcInd, 0, sizeof(fapi_crc_ind_t));
359 /* TODO: Fill the required values. As of now only 1 CRC status PASS is filled */
364 crcInd->crc[idx].handle = puschPdu.handle;
365 crcInd->crc[idx].rnti = puschPdu.rnti;
366 crcInd->crc[idx].harqId = puschPdu.puschData.harqProcessId;
367 crcInd->crc[idx].tbCrcStatus = 0;
368 crcInd->crc[idx].numCb = 1;
369 crcInd->crc[idx].cbCrcStatus[0] = result[ind%50];
370 ret = (0== crcInd->crc[idx].cbCrcStatus[0])?ROK:RFAILED;
371 /*TBD: To use crc ind with random number and percentage */
372 //crcInd->crc[idx].cbCrcStatus[0] = (crcPassPer >= rand()%(100))?0:1;
375 crcInd->crc[idx].ul_cqi = 0;
376 crcInd->crc[idx].timingAdvance = 0;
377 crcInd->crc[idx].rssi = 0;
379 fillMsgHeader(&crcInd->header, FAPI_CRC_INDICATION, \
380 sizeof(fapi_crc_ind_t) - sizeof(fapi_msg_t));
382 /* Sending CRC indication to MAC */
383 DU_LOG("\nINFO --> PHY STUB: Sending CRC Indication to MAC");
384 procPhyMessages(crcInd->header.msg_id, sizeof(fapi_crc_ind_t), (void *)crcInd);
385 MAC_FREE(crcInd, sizeof(fapi_crc_ind_t));
388 } /* l1BuildAndSendCrcInd */
391 /*******************************************************************
393 * @brief Build and send Rx data indication
397 * Function : l1BuildAndSendRxDataInd
400 * Build and send Rx data indication
404 * @return ROK - success
407 * ****************************************************************/
408 uint16_t l1BuildAndSendRxDataInd(uint16_t slot, uint16_t sfn, fapi_ul_pusch_pdu_t puschPdu)
410 uint8_t idx = 0, ueId = 0;
411 fapi_rx_data_indication_t *rxDataInd =NULLP;
412 fapi_pdu_ind_info_t *pduInfo =NULLP;
413 uint8_t *pdu = NULLP;
414 uint16_t byteIdx = 0;
418 GET_UE_ID(puschPdu.rnti, ueId);
419 if(phyDb.ueDb.ueCb[ueId-1].isCFRA)
421 if(!phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp)
423 /* In CF-RA in case of handover, RRC Reconfiguration Complete is sent
424 * by UE once RAR is received from DU */
425 phyDb.ueDb.ueCb[ueId-1].ueId = ueId;
426 phyDb.ueDb.ueCb[ueId-1].crnti = puschPdu.rnti;
427 phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp = true;
428 type = MSG_TYPE_RRC_RECONFIG_COMPLETE;
435 if(!phyDb.ueDb.ueCb[ueId-1].msg3Sent)
437 phyDb.ueDb.ueCb[ueId-1].ueId = ueId;
438 phyDb.ueDb.ueCb[ueId-1].crnti = puschPdu.rnti;
439 phyDb.ueDb.ueCb[ueId-1].msg3Sent = true;
440 type = MSG_TYPE_MSG3;
443 else if(!phyDb.ueDb.ueCb[ueId-1].msg5ShortBsrSent)
445 phyDb.ueDb.ueCb[ueId-1].msg5ShortBsrSent = true;
446 type = MSG_TYPE_SHORT_BSR;
448 else if(!phyDb.ueDb.ueCb[ueId-1].msg5Sent)
450 phyDb.ueDb.ueCb[ueId-1].msg5Sent = true;
451 type = MSG_TYPE_MSG5;
453 else if(!phyDb.ueDb.ueCb[ueId-1].msgNasSecurityModeComp)
455 phyDb.ueDb.ueCb[ueId-1].msgNasSecurityModeComp = true;
456 type = MSG_TYPE_NAS_SECURITY_MODE_COMPLETE;
458 else if(!phyDb.ueDb.ueCb[ueId-1].msgRrcSecurityModeComp)
460 phyDb.ueDb.ueCb[ueId-1].msgRrcSecurityModeComp = true;
461 type = MSG_TYPE_RRC_SECURITY_MODE_COMPLETE;
463 else if(!phyDb.ueDb.ueCb[ueId-1].msgRegistrationComp)
465 phyDb.ueDb.ueCb[ueId-1].msgRegistrationComp = true;
466 type = MSG_TYPE_REGISTRATION_COMPLETE;
468 else if(!phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp)
470 phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp = true;
471 type = MSG_TYPE_RRC_RECONFIG_COMPLETE;
477 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
480 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
483 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
485 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
486 rxDataInd->sfn = sfn;
487 rxDataInd->slot = slot;
488 rxDataInd->numPdus = 1;
490 pduInfo = &rxDataInd->pdus[idx];
491 pduInfo->handle = puschPdu.handle;
492 pduInfo->rnti = puschPdu.rnti;
493 pduInfo->harqId = puschPdu.puschData.harqProcessId;
494 pduInfo->pdu_length = puschPdu.puschData.tbSize ;
496 pduInfo->timingAdvance = 0;
499 /* Filling pdu with random values for testing */
500 pduInfo->pduData = NULL;
501 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
502 if(!pduInfo->pduData)
504 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
507 memset(pduInfo->pduData, 0, pduInfo->pdu_length);
509 pdu = (uint8_t *)pduInfo->pduData;
515 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG3 PDU ");
516 /* For Initial RRC setup Request,
517 MAC subheader format is R/R/LCId (1byte)
519 From 38.321 section 6.1.1
522 /* Hardcoding MAC PDU */
528 pdu[byteIdx++] = 103;
532 case MSG_TYPE_SHORT_BSR:
534 DU_LOG("\nDEBUG --> PHY_STUB: Forming SHORT BSR PDU ");
536 uint8_t bufferSizeIdx = 6;
539 MAC subheader format is R/R/LcId (1Byte)
541 From 38.321 section 6.1.1
543 pdu[byteIdx++] = 61; // LCID
544 pdu[byteIdx++] = (lcgId << 5) | bufferSizeIdx;
551 /* For RRC setup complete
553 * MAC subheader format is R/F/LCId/L (2/3 bytes)
555 * L is length of PDU i.e 6bytes here
556 * From 38.321 section 6.1.1
558 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
559 * From 38.322, section 6.2.2.4
561 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG5 PDU");
562 uint8_t msg5PduLen = 33; /* Length of MSG5 */
563 msg5PduLen += 2; /* RLC subheader */
564 uint8_t msg5[] = {1, msg5PduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 16, 0, \
565 5, 223, 128, 16, 94, 64, 3, 64, 68, 252, 97, 0, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, 184, 56, 0, 0, 0, 0, 0};
567 msg5PduLen += 2; /* 2 bytes of MAC header */
568 memcpy(pdu, &msg5, msg5PduLen);
569 byteIdx += msg5PduLen; /* 4 bytes of header : MAC+RLC */
573 case MSG_TYPE_NAS_SECURITY_MODE_COMPLETE:
575 /* For NAS security mode complete where RRC Container is dummy
577 * MAC subheader format is R/F/LCId/L (2/3 bytes)
579 * L is length of PDU i.e 6bytes here
580 * From 38.321 section 6.1.1
582 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
583 * From 38.322, section 6.2.2.4
585 DU_LOG("\nDEBUG --> PHY_STUB: Forming NAS SECURITY MODE COMPLETE PDU");
586 uint8_t pduLen = 93; /* Length of PDU */
587 pduLen += 2; /* RLC subheader */
588 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 0x3a, 0x2a, 0x3f,
589 0x02, 0x75, 0xa0, 0xa0, 0xc0, 0x80, 0x3f, 0x00, 0x2f, 0x3b, 0x80, 0x04, 0x9a, 0xa2, 0x81, 0x09, 0x80, 0xc0,
590 0x28, 0x04, 0xf8, 0xb8, 0x80, 0x1d, 0xbf, 0x00, 0x20, 0x8c, 0x80, 0x05, 0xf9, 0x00, 0x78, 0x88, 0x7a, 0x88,
591 0xd9, 0x00, 0x00, 0x00, 0x03, 0x08, 0x00, 0x81, 0x97, 0x02, 0x78, 0x38, 0x78, 0x38, 0x17, 0x82, 0x82, 0x00,
592 0x80, 0x00, 0x00, 0xa9, 0x00, 0x78, 0x88, 0x00, 0x00, 0x00, 0x8b, 0x83, 0xf8, 0x38, 0x60, 0x20, 0x0c, 0xc0,
593 0x50, 0x0c, 0x00, 0x80, 0x3a, 0x00, 0x00, 0x48, 0x29, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00};
595 pduLen += 2; /* 2 bytes of MAC header */
596 memcpy(pdu, &msg, pduLen);
597 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
600 case MSG_TYPE_RRC_SECURITY_MODE_COMPLETE:
602 /* For security mode complete where RRC Container is dummy
604 * MAC subheader format is R/F/LCId/L (2/3 bytes)
606 * L is length of PDU i.e 6bytes here
607 * From 38.321 section 6.1.1
609 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
610 * From 38.322, section 6.2.2.4
612 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC SECURITY MODE COMPLETE PDU");
613 uint8_t pduLen = 12; /* Length of PDU */
614 pduLen += 2; /* RLC subheader */
615 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 0x2a, 0x40, \
616 0, 0, 0, 0, 0, 0, 0, 0};
618 pduLen += 2; /* 2 bytes of MAC header */
619 memcpy(pdu, &msg, pduLen);
620 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
624 case MSG_TYPE_REGISTRATION_COMPLETE:
626 /* For rrc reconfig complete where RRC Container is dummy
628 * MAC subheader format is R/F/LCId/L (2/3 bytes)
630 * L is length of PDU i.e 6bytes here
631 * From 38.321 section 6.1.1
633 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
634 * From 38.322, section 6.2.2.4
636 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC REGISTRATION COMPLETE PDU");
637 uint8_t pduLen = 12; /* Length of PDU */
638 pduLen += 2; /* RLC subheader */
639 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 0x3a, 0x81, \
640 0xbf, 0, 0x21, 0x80, 0, 0, 0, 0};
642 pduLen += 2; /* 2 bytes of MAC header */
643 memcpy(pdu, &msg, pduLen);
644 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
648 case MSG_TYPE_RRC_RECONFIG_COMPLETE:
650 /* For rrc reconfig complete where RRC Container is dummy
652 * MAC subheader format is R/F/LCId/L (2/3 bytes)
654 * L is length of PDU i.e 6bytes here
655 * From 38.321 section 6.1.1
657 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
658 * From 38.322, section 6.2.2.4
660 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC RECONFIGURATION COMPLETE PDU");
661 uint8_t pduLen = 13; /* PDU length */
662 pduLen += 2; /* RLC sub header */
663 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 8, 64, 0, 0,\
664 0, 0, 0, 0, 0, 0, 0};
666 pduLen += 2; /* 2bytes of MAC header */
667 memcpy(pdu, &msg, pduLen);
668 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC*/
675 } /* End of switch(type) */
677 /* Filling MAC SDU for Padding bytes*/
678 if(byteIdx < pduInfo->pdu_length)
681 MAC subheader format is R/R/LCId (1byte)
682 LCId is 63 for padding
683 From 38.321 section 6.1.1
687 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
690 msgLen += pduInfo->pdu_length;
692 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
694 /* Sending Rx data indication to MAC */
695 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
696 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
698 if(pduInfo->pdu_length)
699 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
700 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
702 #ifdef START_DL_UL_DATA
703 if(phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp == true)
712 /*******************************************************************
714 * @brief Builds and Sends RACH indication to MAC
718 * Function : l1BuildAndSendRachInd
721 * Builds and Sends RACH indication to MAC
723 * @params[in] SFN value
725 * @return ROK - success
728 * ****************************************************************/
729 uint16_t l1BuildAndSendRachInd(uint16_t slot, uint16_t sfn, uint8_t raPreambleIdx)
732 uint8_t rachPduIdx = 0;
733 uint8_t preamIdx = 0;
734 fapi_rach_pdu_t *rachPdu;
735 fapi_rach_indication_t *rachInd;
737 /* Building RACH indication */
738 MAC_ALLOC(rachInd, sizeof(fapi_rach_indication_t));
741 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rach Indication Message");
744 memset(rachInd, 0, sizeof(fapi_rach_indication_t));
746 rachInd->slot = slot;
747 rachInd->numPdus = 1;
749 rachPdu = &rachInd->rachPdu[rachPduIdx];
750 rachPdu->phyCellId = NR_PCI;
751 rachPdu->symbolIndex = 0;
752 rachPdu->slotIndex = slot;
753 rachPdu->freqIndex = 0;
754 rachPdu->avgRssi = 0;
756 rachPdu->numPreamble = 1;
758 rachPdu->preambleInfo[preamIdx].preambleIndex = raPreambleIdx;
759 rachPdu->preambleInfo[preamIdx].timingAdvance = 0;
760 rachPdu->preambleInfo[preamIdx].preamblePwr = 0;
762 fillMsgHeader(&rachInd->header, FAPI_RACH_INDICATION, \
763 sizeof(fapi_rach_indication_t) - sizeof(fapi_msg_t));
765 /* Sending RACH indication to MAC */
766 DU_LOG("\nINFO --> PHY STUB: Sending RACH Indication to MAC");
767 procPhyMessages(rachInd->header.msg_id, sizeof(fapi_rach_indication_t), (void *)rachInd);
768 MAC_FREE(rachInd, sizeof(fapi_rach_indication_t));
774 /*******************************************************************
776 * @brief Builds and Send the Slot Indication message to MAC
780 * Function : l1BuildAndSendSlotIndication
783 * -Send the Slot indication Message to MAC
785 * @params[in] Message length
786 * config request message pointer
790 * ****************************************************************/
791 uint16_t l1BuildAndSendSlotIndication()
797 fapi_slot_ind_t *slotIndMsg;
799 MAC_ALLOC_SHRABL_BUF(slotIndMsg, sizeof(fapi_slot_ind_t));
802 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for slot Indication Message");
807 memset(slotIndMsg, 0, sizeof(fapi_slot_ind_t));
808 slotIndMsg->sfn = sfnValue;
809 slotIndMsg->slot = slotValue;
811 #ifdef ODU_SLOT_IND_DEBUG_LOG
812 DU_LOG("\n\nDEBUG --> PHY_STUB: Sending Slot Indication [%d : %d] to MAC", sfnValue, slotValue);
815 /* increment for the next TTI */
817 if(sfnValue >= MAX_SFN_VALUE && slotValue > MAX_SLOT_VALUE)
822 else if(slotValue > MAX_SLOT_VALUE)
827 fillMsgHeader(&slotIndMsg->header, FAPI_SLOT_INDICATION, \
828 sizeof(fapi_slot_ind_t) - sizeof(fapi_msg_t));
830 memset(&pst, 0, sizeof(Pst));
831 FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_SLOT_IND);
832 ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
835 DU_LOG("\nERROR --> PHY_STUB: Failed to allocate memory for slot indication buffer");
836 MAC_FREE_SHRABL_BUF(pst.region, pst.pool, slotIndMsg, sizeof(fapi_slot_ind_t));
839 CMCHKPK(oduPackPointer, (PTR)slotIndMsg, mBuf);
840 ODU_POST_TASK(&pst, mBuf);
847 /*******************************************************************
849 * @brief Handles start request received from MAC
853 * Function : l1HdlStartReq
856 * -Handles start request received from MAC
858 * @params[in] Message length
859 * config request message pointer
863 * ****************************************************************/
865 S16 l1HdlStartReq(uint32_t msgLen, void *msg)
868 if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
870 l1HdlSlotIndicaion(FALSE);
871 l1StartConsoleHandler();
872 MAC_FREE(msg, msgLen);
876 DU_LOG("\nINFO --> PHY_STUB: Received Start Req in PHY State %d", lwrMacCb.phyState);
877 MAC_FREE(msg, msgLen);
884 /*******************************************************************
886 * @brief Handles Dl Tti request received from MAC
890 * Function : l1HdlDlTtiReq
893 * -Handles Dl Tti request received from MAC
895 * @params[in] Message length
896 * Dl Tti request message pointer
900 * ****************************************************************/
902 S16 l1HdlDlTtiReq(uint16_t msgLen, void *msg)
905 p_fapi_api_queue_elem_t dlTtiElem = (p_fapi_api_queue_elem_t)msg;
906 fapi_dl_tti_req_t *dlTtiReq = (fapi_dl_tti_req_t *)(dlTtiElem +1);
908 uint8_t pduCount = 0;
910 #ifdef ODU_SLOT_IND_DEBUG_LOG
911 if(dlTtiReq->nPdus == 0)
913 DU_LOG("\nDEBUG --> PHY_STUB: No PDU in DL TTI Request");
917 DU_LOG("\nDEBUG --> PHY STUB: DL TTI Request at sfn=%d slot=%d",dlTtiReq->sfn,dlTtiReq->slot);
921 for(pduCount=0; pduCount<dlTtiReq->nPdus; pduCount++)
923 if(dlTtiReq->pdus[pduCount].pduType == 3) //SSB_PDU_TYPE
925 DU_LOG("\nINFO --> PHY_STUB: SSB PDU");
927 else if(dlTtiReq->pdus[pduCount].pduType == 0)
929 DU_LOG("\nINFO --> PHY_STUB: PDCCH PDU");
931 else if(dlTtiReq->pdus[pduCount].pduType == 1)
933 DU_LOG("\nINFO --> PHY_STUB: PDSCH PDU");
937 /* Free FAPI message */
938 MAC_FREE(msg, msgLen);
943 /*******************************************************************
945 * @brief Handles tx_data request received from MAC
949 * Function : l1HdlTxDataReq
952 * -Handles tx_data request received from MAC
954 * @params[in] Message length
955 * tx_data request message pointer
959 * ****************************************************************/
961 S16 l1HdlTxDataReq(uint16_t msgLen, void *msg)
964 p_fapi_api_queue_elem_t txDataElem = (p_fapi_api_queue_elem_t)msg;
965 fapi_tx_data_req_t *txDataReq = (fapi_tx_data_req_t *)(txDataElem +1);
967 DU_LOG("\nINFO --> PHY STUB: TX DATA Request at sfn=%d slot=%d",txDataReq->sfn,txDataReq->slot);
971 DU_LOG("\nINFO --> PHY_STUB: TxDataPdu for DED MSG sent");
975 MAC_FREE(msg, msgLen);
981 /*******************************************************************
983 * @brief Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
987 * Function : fillPucchF0F1PduInfo
990 * Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
992 * @params[in] fapi_uci_o_pucch_f0f1_t *
994 * @return ROK - success
997 * ****************************************************************/
998 uint8_t fillPucchF0F1PduInfo(fapi_uci_o_pucch_f0f1_t *pduInfo, fapi_ul_pucch_pdu_t pucchPdu)
1001 static uint8_t ind=0;
1002 uint8_t result[]={0,//msg4
1003 0,//Security Mode Command
1004 0,//Registration Accept
1005 0,//RRC Reconfiguration
1024 pduInfo->handle = pucchPdu.handle;
1025 pduInfo->pduBitmap = 1; //hardcoded for SR
1026 if (pucchPdu.bitLenHarq)
1028 pduInfo->pduBitmap |= HARQ_PDU_BITMASK;
1030 pduInfo->pucchFormat = pucchPdu.formatType;
1031 pduInfo->ul_cqi = 0;
1032 pduInfo->rnti = pucchPdu.rnti;
1033 pduInfo->timingAdvance = 0;
1035 if(pduInfo->pduBitmap & SR_PDU_BITMASK)
1037 if (result[ind%50] == 0)
1039 pduInfo->srInfo.srIndication = SR_DETECTED;
1040 pduInfo->srInfo.srConfidenceLevel = CONFDC_LEVEL_GOOD;
1043 if(pduInfo->pduBitmap & HARQ_PDU_BITMASK)
1045 pduInfo->harqInfo.numHarq++;
1046 pduInfo->harqInfo.harqConfidenceLevel = CONFDC_LEVEL_GOOD;
1047 for(idx = 0; idx < pduInfo->harqInfo.numHarq; idx++)
1049 pduInfo->harqInfo.harqValue[idx] = result[ind%50];
1051 /*TBD: To use harq ind with random number and percentage*/
1052 //pduInfo->harqInfo.harqValue[idx] = (dlHqPassPer >= rand()%(100))?HARQ_PASS:HARQ_FAIL;
1057 /*******************************************************************
1059 * @brief Fills UCI Pdu Information
1063 * Function : fillUciPduInfo
1066 * Fills UCI Pdu Information
1068 * @params[in] Pointer to uciPdu
1070 * @return ROK - success
1073 * ****************************************************************/
1074 uint8_t fillUciPduInfo(fapi_uci_pdu_info_t *uciPdu, fapi_ul_pucch_pdu_t pucchPdu)
1078 /*TODO: The pduType is hardcoded here to support
1079 UCI Ind for PUCCH forat0/format1. This is to be
1080 modified when we get SR form UE */
1081 uciPdu->pduType = UCI_IND_PUCCH_F0F1;
1082 switch(uciPdu->pduType)
1086 case UCI_IND_PUCCH_F0F1:
1088 fapi_uci_o_pucch_f0f1_t *pduInfo = NULLP;
1090 pduInfo = &uciPdu->uci.uciPucchF0F1;
1091 ret = fillPucchF0F1PduInfo(pduInfo, pucchPdu);
1092 uciPdu->pduSize = sizeof(fapi_uci_o_pucch_f0f1_t);
1095 case UCI_IND_PUCCH_F2F3F4:
1098 DU_LOG("\nERROR --> PHY_STUB: Invalid Pdu Type %d", uciPdu->pduType);
1104 /*******************************************************************
1106 * @brief Build and send Uci indication
1110 * Function : l1BuildAndSendUciInd
1113 * Build and send Uci indication
1117 * @return ROK - success
1120 * ****************************************************************/
1121 uint8_t l1BuildAndSendUciInd(uint16_t slot, uint16_t sfn, fapi_ul_pucch_pdu_t pucchPdu)
1124 uint8_t nUciPdus = 0;
1126 uint32_t msgLen = 0;
1127 fapi_uci_indication_t *uciInd = NULLP;
1129 MAC_ALLOC(uciInd, sizeof(fapi_uci_indication_t));
1132 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for UCI Indication");
1135 memset(uciInd, 0, sizeof(fapi_uci_indication_t));
1137 uciInd->slot = slot;
1138 uciInd->numUcis = 1; //consdering the UCI Ind for SR
1139 nUciPdus = uciInd->numUcis;
1142 ret = fillUciPduInfo(&uciInd->uciPdu[uciIdx], pucchPdu);
1148 msgLen = sizeof(fapi_uci_indication_t)- sizeof(fapi_msg_t);
1149 fillMsgHeader(&uciInd->header, FAPI_UCI_INDICATION, msgLen);
1151 /* Sending UCI indication to MAC */
1152 DU_LOG("\nINFO --> PHY STUB: Sending UCI Indication to MAC");
1153 procPhyMessages(uciInd->header.msg_id, sizeof(fapi_uci_indication_t), (void *)uciInd);
1155 MAC_FREE(uciInd, sizeof(fapi_uci_indication_t));
1160 /*******************************************************************
1162 * @brief Handles Ul Tti request received from MAC
1166 * Function : l1HdlUlTtiReq
1169 * -Handles Ul Tti request received from MAC
1171 * @params[in] Message length
1172 * Ul Tti request message pointer
1176 * ****************************************************************/
1178 S16 l1HdlUlTtiReq(uint16_t msgLen, void *msg)
1181 p_fapi_api_queue_elem_t ulTtiElem = (p_fapi_api_queue_elem_t)msg;
1182 fapi_ul_tti_req_t *ulTtiReq = (fapi_ul_tti_req_t *)(ulTtiElem +1);
1183 uint8_t numPdus = ulTtiReq->nPdus;
1185 #ifdef ODU_SLOT_IND_DEBUG_LOG
1188 DU_LOG("\nINFO --> PHY STUB: No PDU received in UL TTI Req");
1192 DU_LOG("\nINFO --> PHY STUB: Received UL TTI Request");
1198 if(ulTtiReq->pdus[numPdus-1].pduType == 0)
1200 DU_LOG("\nINFO --> PHY STUB: PRACH PDU");
1202 /* Send RACH Ind to L2 for first UE */
1203 if(phyDb.ueDb.ueCb[UE_IDX_0].rachIndSent == false)
1205 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1206 phyDb.ueDb.ueCb[UE_IDX_0].rachIndSent = true;
1207 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1208 phyDb.ueDb.numActvUe++;
1211 /* Send RACH Ind to L2 for second UE */
1212 if(phyDb.ueDb.ueCb[UE_IDX_1].rachIndSent == false && phyDb.ueDb.ueCb[UE_IDX_0].msgRrcReconfigComp == true)
1214 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1215 phyDb.ueDb.ueCb[UE_IDX_1].rachIndSent = true;
1216 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1217 phyDb.ueDb.numActvUe++;
1220 /* Send RACH Ind to L2 for third UE */
1221 if(phyDb.ueDb.ueCb[UE_IDX_2].rachIndSent == false && phyDb.ueDb.ueCb[UE_IDX_1].msgRrcReconfigComp == true)
1223 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1224 phyDb.ueDb.ueCb[UE_IDX_2].rachIndSent = true;
1225 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1226 phyDb.ueDb.numActvUe++;
1230 if(ulTtiReq->pdus[numPdus-1].pduType == 1)
1232 DU_LOG("\nINFO --> PHY STUB: PUSCH PDU");
1233 if (ROK == l1BuildAndSendCrcInd(ulTtiReq->slot, ulTtiReq->sfn,ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu))
1235 l1BuildAndSendRxDataInd(ulTtiReq->slot, ulTtiReq->sfn, ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu);
1238 if(ulTtiReq->pdus[numPdus-1].pduType == 2)
1240 DU_LOG("\nINFO --> PHY STUB: PUCCH PDU");
1242 fapi_ul_tti_req_t ulTtiSlotInd;
1243 memset(&ulTtiSlotInd, 0, sizeof(fapi_ul_tti_req_t));
1244 ulTtiSlotInd.slot = ulTtiReq->slot;
1245 ulTtiSlotInd.sfn = ulTtiReq->sfn;
1246 ADD_DELTA_TO_TIME(ulTtiSlotInd, ulTtiSlotInd, SLOT_DELAY, MAX_SLOTS);
1247 l1BuildAndSendUciInd(ulTtiSlotInd.slot, ulTtiSlotInd.sfn, ulTtiReq->pdus[numPdus-1].pdu.pucch_pdu);
1252 MAC_FREE(msg, msgLen);
1257 /*******************************************************************
1259 * @brief Builds and Send the stop Indication message to MAC
1263 * Function : l1BuildAndSendStopInd
1266 * -Send the Stop indication Message to MAC
1271 * ****************************************************************/
1272 uint16_t l1BuildAndSendStopInd()
1276 Buffer *mBuf = NULLP;
1277 fapi_stop_ind_t *stopIndMsg = NULLP;
1278 uint32_t msgLen = 0;
1280 MAC_ALLOC_SHRABL_BUF(stopIndMsg, sizeof(fapi_stop_ind_t));
1283 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for stop Indication Message");
1288 fillMsgHeader(&stopIndMsg->header, FAPI_STOP_INDICATION, msgLen);
1289 DU_LOG("\n\nINFO --> PHY_STUB: Processing Stop indication to MAC");
1291 memset(&pst, 0, sizeof(Pst));
1292 FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_STOP_IND);
1293 ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
1296 DU_LOG("\nERROR --> PHY_STUB: Failed to allocate memory for slot indication buffer");
1297 MAC_FREE_SHRABL_BUF(pst.region, pst.pool, stopIndMsg, sizeof(fapi_stop_ind_t));
1300 CMCHKPK(oduPackPointer, (PTR)stopIndMsg, mBuf);
1301 ODU_POST_TASK(&pst, mBuf);
1307 /*******************************************************************
1309 * @brief Handles stop request received from MAC
1313 * Function : l1HdlStopReq
1316 * -Handles stop request received from MAC
1318 * @params[in] Message length
1319 * stop request message pointer
1323 * ****************************************************************/
1325 S16 l1HdlStopReq(uint32_t msgLen, void *msg)
1328 if(lwrMacCb.phyState == PHY_STATE_RUNNING)
1330 l1HdlSlotIndicaion(TRUE);
1332 /* Initialize all global variables */
1335 memset(&phyDb.ueDb, 0, sizeof(UeDb));
1337 DU_LOG("\nINFO --> PHY_STUB: Slot Indication is stopped successfully");
1338 MAC_FREE(msg, msgLen);
1342 DU_LOG("\nINFO --> PHY_STUB: Received Stop Req in PHY State %d", lwrMacCb.phyState);
1343 MAC_FREE(msg, msgLen);
1351 /*******************************************************************
1353 * @brief Build And Send Rx Data Ind for Msg5
1357 * Function : l1BuildAndSendMsg5
1359 * Functionality: Build And Send Rx Data Ind for Msg5
1363 * @return ROK - success
1366 * ****************************************************************/
1367 uint8_t l1BuildAndSendMsg5(uint16_t sfn, uint16_t slot)
1371 fapi_rx_data_indication_t *rxDataInd;
1372 fapi_pdu_ind_info_t *pduInfo;
1374 uint16_t byteIdx = 0;
1375 uint32_t msgLen = 0;
1377 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1380 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication for msg5");
1383 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1385 /* TODO: Fill the required values */
1386 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1387 rxDataInd->sfn = sfn;
1388 rxDataInd->slot = slot;
1389 rxDataInd->numPdus = 1;
1391 pduInfo = &rxDataInd->pdus[idx];
1392 pduInfo->handle = 100;
1393 pduInfo->rnti = 100;
1394 pduInfo->harqId = 1;
1395 pduInfo->pdu_length = 25;
1396 pduInfo->ul_cqi = 0;
1397 pduInfo->timingAdvance = 0;
1400 /* Filling pdu with random values for testing */
1401 pduInfo->pduData = NULL;
1402 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1403 if(!pduInfo->pduData)
1405 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1410 pdu = (uint8_t *)pduInfo->pduData;
1412 uint8_t msg5PduLen = 33;
1413 /* For RRC setup complete
1414 MAC subheader format is R/F/LCId/L (2/3 bytes)
1416 L is length of PDU i.e 6bytes here
1417 From 38.321 section 6.1.1
1419 uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
1420 64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
1421 184, 56, 0, 0, 0, 0, 0};
1423 msg5PduLen += 2; /* 2bytes of header */
1424 memcpy(pdu, &msg5, msg5PduLen);
1425 byteIdx += msg5PduLen; /* 2 bytes of header */
1427 /* Filling MAC SDU for Padding bytes*/
1428 if(byteIdx < pduInfo->pdu_length)
1431 MAC subheader format is R/R/LCId (1byte)
1432 LCId is 63 for padding
1433 From 38.321 section 6.1.1
1435 pdu[byteIdx++] = 63;
1437 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1440 msgLen += pduInfo->pdu_length;
1442 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1444 /* Sending Rx data indication to MAC */
1445 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
1446 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1448 if(pduInfo->pdu_length)
1449 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1450 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1456 /*******************************************************************
1458 * @brief Handles Ul Dci request received from MAC
1462 * Function : l1HdlUlDciReq
1465 * -Handles Ul Dci request received from MAC
1467 * @params[in] Message length
1468 * Ul Dci request message pointer
1472 * ****************************************************************/
1474 S16 l1HdlUlDciReq(uint16_t msgLen, void *msg)
1477 p_fapi_api_queue_elem_t ulDciElem = (p_fapi_api_queue_elem_t)msg;
1478 fapi_ul_dci_req_t *ulDciReq = (fapi_ul_dci_req_t *)(ulDciElem +1);
1479 uint8_t numPdus = ulDciReq->numPdus;
1483 if(ulDciReq->pdus[numPdus-1].pduType == 0)
1485 DU_LOG("\nINFO --> PHY STUB: Received UL DCI Request for PDCCH PDU");
1486 //l1BuildAndSendMsg5(ulDciReq->sfn, ulDciReq->slot);
1492 MAC_FREE(msg, msgLen);
1497 /*******************************************************************
1499 * @brief Send UL user data to DU
1503 * Function : l1SendUlUserData
1505 * Functionality: Send UL user data to DU
1508 * @return ROK - success
1511 * ****************************************************************/
1512 uint8_t l1SendUlUserData(uint8_t drbId, uint8_t ueIdx)
1515 fapi_rx_data_indication_t *rxDataInd;
1516 fapi_pdu_ind_info_t *pduInfo;
1517 uint8_t *pdu = NULLP;
1518 uint16_t byteIdx = 0;
1519 uint32_t msgLen = 0;
1523 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1526 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1529 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1531 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1533 rxDataInd->slot = 0;
1534 rxDataInd->numPdus = 1;
1536 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1537 pduInfo = &rxDataInd->pdus[idx];
1538 pduInfo->handle = ueIdx + ODU_START_CRNTI;
1539 pduInfo->rnti = ueIdx + ODU_START_CRNTI;
1540 pduInfo->harqId = 1;
1541 /* Since user data size = 50bytes and 2 bytes of MAC header and 3 byte of RLC header,
1542 * setting tbsize = 56 from Table 5.1.3.2-1 spec 38.214 */
1543 pduInfo->pdu_length = 56;
1544 pduInfo->ul_cqi = 0;
1545 pduInfo->timingAdvance = 0;
1548 /* Filling pdu with random values for testing */
1549 pduInfo->pduData = NULL;
1550 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1551 if(!pduInfo->pduData)
1553 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1558 pdu = (uint8_t *)pduInfo->pduData;
1562 MAC subheader format is R/F/LCId/L (2/3 bytes)
1564 L is length of PDU i.e 50 bytes
1565 From 38.321 section 6.1.1
1566 From 38.322 section 6.2.2.4, 6.2.2.3 for AM, UM Header
1569 /* Below ulMsg supports 12bit SN for UM mode */
1571 lcId = MIN_DRB_LCID + drbId;
1572 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,
1573 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};
1574 msgLen += 2; /* 2bytes of header */
1575 memcpy(pdu, &ulMsg, msgLen);
1576 byteIdx += msgLen; /* 2 bytes of header */
1578 /* Filling MAC SDU for Padding bytes*/
1579 if(byteIdx < pduInfo->pdu_length)
1582 MAC subheader format is R/R/LCId (1byte)
1583 LCId is 63 for padding
1584 From 38.321 section 6.1.1
1586 pdu[byteIdx++] = 63;
1588 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1591 msgLen += pduInfo->pdu_length;
1593 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1595 /* Send Message to peer */
1596 while(cnt < NUM_UL_PACKETS)
1598 DU_LOG("\nDEBUG --> PHY STUB : Sending UL User Data[%d][LCID:%d] at sfn %d slot %d", cnt+1, lcId, sfnValue, slotValue);
1599 /* Sending Rx data indication to MAC */
1600 rxDataInd->sfn = sfnValue;
1601 rxDataInd->slot = slotValue;
1602 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1606 if(pduInfo->pdu_length)
1607 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1608 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1612 /*******************************************************************
1614 * @brief Sends RLC Status PDU to DU
1618 * Function : l1SendStatusPdu
1620 * Functionality: Send RLC Status PDU to DU
1623 * @return ROK - success
1626 * ****************************************************************/
1627 uint8_t l1SendStatusPdu()
1629 fapi_rx_data_indication_t *rxDataInd;
1630 fapi_pdu_ind_info_t *pduInfo;
1631 uint8_t *pdu = NULLP;
1632 uint16_t byteIdx = 0;
1633 uint32_t msgLen = 0;
1636 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1639 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1642 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1644 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1646 rxDataInd->slot = 0;
1647 rxDataInd->numPdus = 1;
1649 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1650 pduInfo = &rxDataInd->pdus[idx];
1651 pduInfo->handle = 100;
1652 pduInfo->rnti = 100;
1653 pduInfo->harqId = 1;
1654 /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1655 * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1656 pduInfo->pdu_length = 24;
1657 pduInfo->ul_cqi = 0;
1658 pduInfo->timingAdvance = 0;
1661 /* Filling pdu with random values for testing */
1662 pduInfo->pduData = NULL;
1663 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1664 if(!pduInfo->pduData)
1666 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1671 pdu = (uint8_t *)pduInfo->pduData;
1674 /* For RLC Status PDU
1675 * MAC subheader format is R/F/LCId/L (2/3 bytes)
1676 * LCId is 4 for DRB1
1677 * L is length of Status PDU i.e 3 bytes
1678 * From 38.321 section 6.1.1
1680 * RLC Status PDU format :
1681 * ---------------------------------
1682 * |D/C|CPT| ACK_SN |
1683 * ---------------------------------
1685 * ---------------------------------
1686 * |E1 | R | R | R | R | R | R | R |
1687 * ---------------------------------
1689 * Here, D/C bit = 0 for Control PDU
1690 * CPT bit = 0 since control pdu type is Status PDU
1691 * ACK_SN = 0 as of now, this can be changed based on the
1692 * scenario being tested
1693 * E1 = 0 because no NACK_SN, E1, E2 and E3 follows it
1694 * R = 0 i.e. reserved bits
1695 * From Spec 38.322 section 6.2.2.5
1697 uint8_t statusPdu[] = {4, msgLen, 0, 0, 0};
1698 msgLen += 2; /* 2bytes of header */
1699 memcpy(pdu, &statusPdu, msgLen);
1700 byteIdx += msgLen; /* 2 bytes of header */
1703 /* Filling MAC SDU for Padding bytes*/
1704 if(byteIdx < pduInfo->pdu_length)
1707 MAC subheader format is R/R/LCId (1byte)
1708 LCId is 63 for padding
1709 From 38.321 section 6.1.1
1711 pdu[byteIdx++] = 63;
1713 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1716 msgLen += pduInfo->pdu_length;
1718 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1720 /* Send Message to peer */
1721 DU_LOG("\nDEBUG --> PHY STUB : Sending RLC status pdu at sfn %d slot %d", sfnValue, slotValue);
1722 /* Sending Rx data indication to MAC */
1723 rxDataInd->sfn = sfnValue;
1724 rxDataInd->slot = slotValue;
1725 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1727 if(pduInfo->pdu_length)
1728 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1729 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1733 /*******************************************************************
1735 * @brief Receives message from MAC
1739 * Function : l1ProcessFapiRequest
1742 * - Receives message from MAC and calls handler
1744 * @params[in] Message type
1750 * ****************************************************************/
1752 void l1ProcessFapiRequest(uint8_t msgType, uint32_t msgLen, void *msg)
1757 case FAPI_PARAM_REQUEST:
1758 l1HdlParamReq(msgLen, msg);
1760 case FAPI_CONFIG_REQUEST:
1761 l1HdlConfigReq(msgLen, msg);
1763 case FAPI_START_REQUEST:
1764 l1HdlStartReq(msgLen, msg);
1766 case FAPI_DL_TTI_REQUEST:
1767 l1HdlDlTtiReq(msgLen, msg);
1769 case FAPI_TX_DATA_REQUEST:
1770 l1HdlTxDataReq(msgLen, msg);
1772 case FAPI_UL_TTI_REQUEST:
1773 l1HdlUlTtiReq(msgLen, msg);
1775 case FAPI_STOP_REQUEST:
1776 l1HdlStopReq(msgLen, msg);
1778 case FAPI_UL_DCI_REQUEST:
1779 l1HdlUlDciReq(msgLen, msg);
1782 DU_LOG("\nERROR --> PHY_STUB: Invalid message type[%x] received at PHY", msgType);
1789 /*******************************************************************
1791 * @brief Builds and Send the BSR message to MAC
1795 * Function : l1BuildAndSendBSR
1798 * -Send the BSR Message to MAC
1800 * @params[in] BSR type
1801 * array of LCGID and BSIdx
1804 *****************************************************************/
1805 uint16_t l1BuildAndSendBSR(uint8_t ueIdx, BsrType bsrType,\
1806 LcgBufferSize lcgBsIdx[MAX_NUM_LOGICAL_CHANNEL_GROUPS])
1808 fapi_rx_data_indication_t *rxDataInd;
1809 fapi_pdu_ind_info_t *pduInfo;
1810 uint8_t *pdu = NULLP;
1811 uint16_t byteIdx = 0;
1812 uint32_t msgLen = 0;
1813 uint8_t pduIdx = 0, lcgIdx = 0, lcgIdxPos = 0;
1815 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1818 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1821 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1823 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1825 rxDataInd->slot = 0;
1826 rxDataInd->numPdus = 1;
1828 pduInfo = &rxDataInd->pdus[pduIdx];
1829 pduInfo->handle = (ODU_START_CRNTI + ueIdx);
1830 pduInfo->rnti = (ODU_START_CRNTI + ueIdx);
1831 pduInfo->harqId = 1;
1833 /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1834 * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1835 pduInfo->pdu_length = 24;
1836 pduInfo->ul_cqi = 0;
1837 pduInfo->timingAdvance = 0;
1840 /* Filling pdu with random values for testing */
1841 pduInfo->pduData = NULL;
1842 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1843 if(!pduInfo->pduData)
1845 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1846 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1851 pdu = (uint8_t *)pduInfo->pduData;
1857 DU_LOG("\nDEBUG --> PHY_STUB: Forming SHORT BSR PDU ");
1860 * MAC subheader format is R/R/LcId (1Byte)
1862 * From 38.321 section 6.1.1
1864 pdu[byteIdx++] = 61; // LCID
1865 pdu[byteIdx++] = (lcgBsIdx[0].lcgId << 5) | lcgBsIdx[0].bsIdx;
1871 DU_LOG("\nDEBUG --> PHY_STUB: Forming LONG BSR PDU ");
1874 * MAC subheader format is R/R/LcId (1Byte)
1876 * From 38.321 section 6.1.1
1878 pdu[byteIdx++] = 62; // LCID
1880 /*Octet where lcgId bitmap will be present*/
1881 lcgIdxPos = byteIdx;
1883 for(lcgIdx = 0; lcgIdx < MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
1885 if(lcgBsIdx[lcgIdx].bsIdx > 0)
1887 pdu[lcgIdxPos] |= 1 << lcgBsIdx[lcgIdx].lcgId;
1888 pdu[byteIdx++] = lcgBsIdx[lcgIdx].bsIdx;
1897 DU_LOG("\nERROR --> PHY_STUB: Incorrect BSR type:%d!", bsrType);
1898 if(pduInfo->pdu_length)
1899 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1900 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1904 /* Filling MAC SDU for Padding bytes*/
1905 if(byteIdx < pduInfo->pdu_length)
1908 * MAC subheader format is R/R/LCId (1byte)
1909 * LCId is 63 for padding
1910 * From 38.321 section 6.1.1
1912 pdu[byteIdx++] = 63;
1914 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1917 msgLen += pduInfo->pdu_length;
1918 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1920 /* Sending Rx data indication to MAC */
1921 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
1922 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1924 if(pduInfo->pdu_length)
1925 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1926 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1931 /**********************************************************************
1933 **********************************************************************/