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].msgNasAuthenticationComp)
455 phyDb.ueDb.ueCb[ueId-1].msgNasAuthenticationComp = true;
456 type = MSG_TYPE_NAS_AUTHENTICATION_COMPLETE;
458 else if(!phyDb.ueDb.ueCb[ueId-1].msgNasSecurityModeComp)
460 phyDb.ueDb.ueCb[ueId-1].msgNasSecurityModeComp = true;
461 type = MSG_TYPE_NAS_SECURITY_MODE_COMPLETE;
463 else if(!phyDb.ueDb.ueCb[ueId-1].msgRrcSecurityModeComp)
465 phyDb.ueDb.ueCb[ueId-1].msgRrcSecurityModeComp = true;
466 type = MSG_TYPE_RRC_SECURITY_MODE_COMPLETE;
468 else if(!phyDb.ueDb.ueCb[ueId-1].msgRegistrationComp)
470 phyDb.ueDb.ueCb[ueId-1].msgRegistrationComp = true;
471 type = MSG_TYPE_REGISTRATION_COMPLETE;
473 else if(!phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp)
475 phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp = true;
476 type = MSG_TYPE_RRC_RECONFIG_COMPLETE;
482 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
485 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
488 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
490 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
491 rxDataInd->sfn = sfn;
492 rxDataInd->slot = slot;
493 rxDataInd->numPdus = 1;
495 pduInfo = &rxDataInd->pdus[idx];
496 pduInfo->handle = puschPdu.handle;
497 pduInfo->rnti = puschPdu.rnti;
498 pduInfo->harqId = puschPdu.puschData.harqProcessId;
499 pduInfo->pdu_length = puschPdu.puschData.tbSize ;
501 pduInfo->timingAdvance = 0;
504 /* Filling pdu with random values for testing */
505 pduInfo->pduData = NULL;
506 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
507 if(!pduInfo->pduData)
509 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
512 memset(pduInfo->pduData, 0, pduInfo->pdu_length);
514 pdu = (uint8_t *)pduInfo->pduData;
520 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG3 PDU ");
521 /* For Initial RRC setup Request,
522 MAC subheader format is R/R/LCId (1byte)
524 From 38.321 section 6.1.1
527 /* Hardcoding MAC PDU */
533 pdu[byteIdx++] = 103;
537 case MSG_TYPE_SHORT_BSR:
539 DU_LOG("\nDEBUG --> PHY_STUB: Forming SHORT BSR PDU ");
541 uint8_t bufferSizeIdx = 6;
544 MAC subheader format is R/R/LcId (1Byte)
546 From 38.321 section 6.1.1
548 pdu[byteIdx++] = 61; // LCID
549 pdu[byteIdx++] = (lcgId << 5) | bufferSizeIdx;
556 /* For RRC setup complete
558 * MAC subheader format is R/F/LCId/L (2/3 bytes)
560 * L is length of PDU i.e 6bytes here
561 * From 38.321 section 6.1.1
563 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
564 * From 38.322, section 6.2.2.4
566 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG5 PDU");
567 uint8_t msg5PduLen = 33; /* Length of MSG5 */
568 msg5PduLen += 2; /* RLC subheader */
569 uint8_t msg5[] = {1, msg5PduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 16, 0, \
570 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};
572 msg5PduLen += 2; /* 2 bytes of MAC header */
573 memcpy(pdu, &msg5, msg5PduLen);
574 byteIdx += msg5PduLen; /* 4 bytes of header : MAC+RLC */
578 case MSG_TYPE_NAS_AUTHENTICATION_COMPLETE:
580 /* For Authentication response where RRC Container is dummy
582 * MAC subheader format is R/F/LCId/L (2/3 bytes)
584 * L is length of PDU i.e 6bytes here
585 * From 38.321 section 6.1.1
587 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
588 * From 38.322, section 6.2.2.4
590 DU_LOG("\nDEBUG --> PHY_STUB: Forming AUTHENTICATION RESPONSE PDU");
591 uint8_t pduLen = 37; /* Length of PDU */
592 pduLen += 2; /* RLC subheader */
593 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 0x3a, \
594 0x0e, 0x3f, 0x00, 0xca, 0x95, 0xe9, 0x19, 0x41, 0x3f, 0x00, 0x2b, 0x96, 0x88, 0x06, 0xd7, 0x16, 0xc6, \
595 0x8b, 0xea, 0xae, 0x45, 0xd1, 0x01, 0xfd, 0x34, 0xd4, 0xfd, 0xd5, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00};
597 pduLen += 2; /* 2 bytes of MAC header */
598 memcpy(pdu, &msg, pduLen);
599 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
603 case MSG_TYPE_NAS_SECURITY_MODE_COMPLETE:
605 /* For NAS security mode complete where RRC Container is dummy
607 * MAC subheader format is R/F/LCId/L (2/3 bytes)
609 * L is length of PDU i.e 6bytes here
610 * From 38.321 section 6.1.1
612 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
613 * From 38.322, section 6.2.2.4
615 DU_LOG("\nDEBUG --> PHY_STUB: Forming NAS SECURITY MODE COMPLETE PDU");
616 uint8_t pduLen = 93; /* Length of PDU */
617 pduLen += 2; /* RLC subheader */
618 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 0x3a, 0x2a, 0x3f,
619 0x02, 0x75, 0xa0, 0xa0, 0xc0, 0x80, 0x3f, 0x00, 0x2f, 0x3b, 0x80, 0x04, 0x9a, 0xa2, 0x81, 0x09, 0x80, 0xc0,
620 0x28, 0x04, 0xf8, 0xb8, 0x80, 0x1d, 0xbf, 0x00, 0x20, 0x8c, 0x80, 0x05, 0xf9, 0x00, 0x78, 0x88, 0x7a, 0x88,
621 0xd9, 0x00, 0x00, 0x00, 0x03, 0x08, 0x00, 0x81, 0x97, 0x02, 0x78, 0x38, 0x78, 0x38, 0x17, 0x82, 0x82, 0x00,
622 0x80, 0x00, 0x00, 0xa9, 0x00, 0x78, 0x88, 0x00, 0x00, 0x00, 0x8b, 0x83, 0xf8, 0x38, 0x60, 0x20, 0x0c, 0xc0,
623 0x50, 0x0c, 0x00, 0x80, 0x3a, 0x00, 0x00, 0x48, 0x29, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00};
625 pduLen += 2; /* 2 bytes of MAC header */
626 memcpy(pdu, &msg, pduLen);
627 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
631 case MSG_TYPE_RRC_SECURITY_MODE_COMPLETE:
633 /* For security mode complete where RRC Container is dummy
635 * MAC subheader format is R/F/LCId/L (2/3 bytes)
637 * L is length of PDU i.e 6bytes here
638 * From 38.321 section 6.1.1
640 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
641 * From 38.322, section 6.2.2.4
643 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC SECURITY MODE COMPLETE PDU");
644 uint8_t pduLen = 12; /* Length of PDU */
645 pduLen += 2; /* RLC subheader */
646 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 0x2a, 0x40, \
647 0, 0, 0, 0, 0, 0, 0, 0};
649 pduLen += 2; /* 2 bytes of MAC header */
650 memcpy(pdu, &msg, pduLen);
651 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
655 case MSG_TYPE_REGISTRATION_COMPLETE:
657 /* For rrc reconfig complete where RRC Container is dummy
659 * MAC subheader format is R/F/LCId/L (2/3 bytes)
661 * L is length of PDU i.e 6bytes here
662 * From 38.321 section 6.1.1
664 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
665 * From 38.322, section 6.2.2.4
667 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC REGISTRATION COMPLETE PDU");
668 uint8_t pduLen = 12; /* Length of PDU */
669 pduLen += 2; /* RLC subheader */
670 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 0x3a, 0x81, \
671 0xbf, 0, 0x21, 0x80, 0, 0, 0, 0};
673 pduLen += 2; /* 2 bytes of MAC header */
674 memcpy(pdu, &msg, pduLen);
675 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
679 case MSG_TYPE_RRC_RECONFIG_COMPLETE:
681 /* For rrc reconfig complete where RRC Container is dummy
683 * MAC subheader format is R/F/LCId/L (2/3 bytes)
685 * L is length of PDU i.e 6bytes here
686 * From 38.321 section 6.1.1
688 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
689 * From 38.322, section 6.2.2.4
691 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC RECONFIGURATION COMPLETE PDU");
692 uint8_t pduLen = 13; /* PDU length */
693 pduLen += 2; /* RLC sub header */
694 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 8, 64, 0, 0,\
695 0, 0, 0, 0, 0, 0, 0};
697 pduLen += 2; /* 2bytes of MAC header */
698 memcpy(pdu, &msg, pduLen);
699 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC*/
706 } /* End of switch(type) */
708 /* Filling MAC SDU for Padding bytes*/
709 if(byteIdx < pduInfo->pdu_length)
712 MAC subheader format is R/R/LCId (1byte)
713 LCId is 63 for padding
714 From 38.321 section 6.1.1
718 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
721 msgLen += pduInfo->pdu_length;
723 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
725 /* Sending Rx data indication to MAC */
726 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
727 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
729 if(pduInfo->pdu_length)
730 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
731 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
733 #ifdef START_DL_UL_DATA
734 if(phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp == true)
743 /*******************************************************************
745 * @brief Builds and Sends RACH indication to MAC
749 * Function : l1BuildAndSendRachInd
752 * Builds and Sends RACH indication to MAC
754 * @params[in] SFN value
756 * @return ROK - success
759 * ****************************************************************/
760 uint16_t l1BuildAndSendRachInd(uint16_t slot, uint16_t sfn, uint8_t raPreambleIdx)
763 uint8_t rachPduIdx = 0;
764 uint8_t preamIdx = 0;
765 fapi_rach_pdu_t *rachPdu;
766 fapi_rach_indication_t *rachInd;
768 /* Building RACH indication */
769 MAC_ALLOC(rachInd, sizeof(fapi_rach_indication_t));
772 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rach Indication Message");
775 memset(rachInd, 0, sizeof(fapi_rach_indication_t));
777 rachInd->slot = slot;
778 rachInd->numPdus = 1;
780 rachPdu = &rachInd->rachPdu[rachPduIdx];
781 rachPdu->phyCellId = NR_PCI;
782 rachPdu->symbolIndex = 0;
783 rachPdu->slotIndex = slot;
784 rachPdu->freqIndex = 0;
785 rachPdu->avgRssi = 0;
787 rachPdu->numPreamble = 1;
789 rachPdu->preambleInfo[preamIdx].preambleIndex = raPreambleIdx;
790 rachPdu->preambleInfo[preamIdx].timingAdvance = 0;
791 rachPdu->preambleInfo[preamIdx].preamblePwr = 0;
793 fillMsgHeader(&rachInd->header, FAPI_RACH_INDICATION, \
794 sizeof(fapi_rach_indication_t) - sizeof(fapi_msg_t));
796 /* Sending RACH indication to MAC */
797 DU_LOG("\nINFO --> PHY STUB: Sending RACH Indication to MAC");
798 procPhyMessages(rachInd->header.msg_id, sizeof(fapi_rach_indication_t), (void *)rachInd);
799 MAC_FREE(rachInd, sizeof(fapi_rach_indication_t));
805 /*******************************************************************
807 * @brief Builds and Send the Slot Indication message to MAC
811 * Function : l1BuildAndSendSlotIndication
814 * -Send the Slot indication Message to MAC
816 * @params[in] Message length
817 * config request message pointer
821 * ****************************************************************/
822 uint16_t l1BuildAndSendSlotIndication()
828 fapi_slot_ind_t *slotIndMsg;
830 MAC_ALLOC_SHRABL_BUF(slotIndMsg, sizeof(fapi_slot_ind_t));
833 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for slot Indication Message");
838 memset(slotIndMsg, 0, sizeof(fapi_slot_ind_t));
839 slotIndMsg->sfn = sfnValue;
840 slotIndMsg->slot = slotValue;
842 #ifdef ODU_SLOT_IND_DEBUG_LOG
843 DU_LOG("\n\nDEBUG --> PHY_STUB: Sending Slot Indication [%d : %d] to MAC", sfnValue, slotValue);
846 /* increment for the next TTI */
848 if(sfnValue >= MAX_SFN_VALUE && slotValue > MAX_SLOT_VALUE)
853 else if(slotValue > MAX_SLOT_VALUE)
858 fillMsgHeader(&slotIndMsg->header, FAPI_SLOT_INDICATION, \
859 sizeof(fapi_slot_ind_t) - sizeof(fapi_msg_t));
861 memset(&pst, 0, sizeof(Pst));
862 FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_SLOT_IND);
863 ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
866 DU_LOG("\nERROR --> PHY_STUB: Failed to allocate memory for slot indication buffer");
867 MAC_FREE_SHRABL_BUF(pst.region, pst.pool, slotIndMsg, sizeof(fapi_slot_ind_t));
870 CMCHKPK(oduPackPointer, (PTR)slotIndMsg, mBuf);
871 ODU_POST_TASK(&pst, mBuf);
878 /*******************************************************************
880 * @brief Handles start request received from MAC
884 * Function : l1HdlStartReq
887 * -Handles start request received from MAC
889 * @params[in] Message length
890 * config request message pointer
894 * ****************************************************************/
896 S16 l1HdlStartReq(uint32_t msgLen, void *msg)
899 if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
901 l1HdlSlotIndicaion(FALSE);
902 l1StartConsoleHandler();
903 MAC_FREE(msg, msgLen);
907 DU_LOG("\nINFO --> PHY_STUB: Received Start Req in PHY State %d", lwrMacCb.phyState);
908 MAC_FREE(msg, msgLen);
915 /*******************************************************************
917 * @brief Handles Dl Tti request received from MAC
921 * Function : l1HdlDlTtiReq
924 * -Handles Dl Tti request received from MAC
926 * @params[in] Message length
927 * Dl Tti request message pointer
931 * ****************************************************************/
933 S16 l1HdlDlTtiReq(uint32_t msgLen, void *msg)
936 p_fapi_api_queue_elem_t dlTtiElem = (p_fapi_api_queue_elem_t)msg;
937 fapi_dl_tti_req_t *dlTtiReq = (fapi_dl_tti_req_t *)(dlTtiElem +1);
939 uint8_t pduCount = 0;
941 #ifdef ODU_SLOT_IND_DEBUG_LOG
942 if(dlTtiReq->nPdus == 0)
944 DU_LOG("\nDEBUG --> PHY_STUB: No PDU in DL TTI Request");
948 DU_LOG("\nDEBUG --> PHY STUB: DL TTI Request at sfn=%d slot=%d",dlTtiReq->sfn,dlTtiReq->slot);
952 for(pduCount=0; pduCount<dlTtiReq->nPdus; pduCount++)
954 if(dlTtiReq->pdus[pduCount].pduType == 3) //SSB_PDU_TYPE
956 DU_LOG("\nINFO --> PHY_STUB: SSB PDU");
958 else if(dlTtiReq->pdus[pduCount].pduType == 0)
960 DU_LOG("\nINFO --> PHY_STUB: PDCCH PDU");
962 else if(dlTtiReq->pdus[pduCount].pduType == 1)
964 DU_LOG("\nINFO --> PHY_STUB: PDSCH PDU");
968 /* Free FAPI message */
969 MAC_FREE(msg, msgLen);
974 /*******************************************************************
976 * @brief Handles tx_data request received from MAC
980 * Function : l1HdlTxDataReq
983 * -Handles tx_data request received from MAC
985 * @params[in] Message length
986 * tx_data request message pointer
990 * ****************************************************************/
992 S16 l1HdlTxDataReq(uint32_t msgLen, void *msg)
995 p_fapi_api_queue_elem_t txDataElem = (p_fapi_api_queue_elem_t)msg;
996 fapi_tx_data_req_t *txDataReq = (fapi_tx_data_req_t *)(txDataElem +1);
998 DU_LOG("\nINFO --> PHY STUB: TX DATA Request at sfn=%d slot=%d",txDataReq->sfn,txDataReq->slot);
1002 DU_LOG("\nINFO --> PHY_STUB: TxDataPdu for DED MSG sent");
1006 MAC_FREE(msg, msgLen);
1012 /*******************************************************************
1014 * @brief Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
1018 * Function : fillPucchF0F1PduInfo
1021 * Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
1023 * @params[in] fapi_uci_o_pucch_f0f1_t *
1025 * @return ROK - success
1028 * ****************************************************************/
1029 uint8_t fillPucchF0F1PduInfo(fapi_uci_o_pucch_f0f1_t *pduInfo, fapi_ul_pucch_pdu_t pucchPdu)
1032 static uint8_t ind=0;
1033 uint8_t result[]={0,//msg4
1034 0,//Security Mode Command
1035 0,//Registration Accept
1036 0,//RRC Reconfiguration
1055 pduInfo->handle = pucchPdu.handle;
1056 pduInfo->pduBitmap = 1; //hardcoded for SR
1057 if (pucchPdu.bitLenHarq)
1059 pduInfo->pduBitmap |= HARQ_PDU_BITMASK;
1061 pduInfo->pucchFormat = pucchPdu.formatType;
1062 pduInfo->ul_cqi = 0;
1063 pduInfo->rnti = pucchPdu.rnti;
1064 pduInfo->timingAdvance = 0;
1066 if(pduInfo->pduBitmap & SR_PDU_BITMASK)
1068 if (result[ind%50] == 0)
1070 pduInfo->srInfo.srIndication = SR_DETECTED;
1071 pduInfo->srInfo.srConfidenceLevel = CONFDC_LEVEL_GOOD;
1074 if(pduInfo->pduBitmap & HARQ_PDU_BITMASK)
1076 pduInfo->harqInfo.numHarq++;
1077 pduInfo->harqInfo.harqConfidenceLevel = CONFDC_LEVEL_GOOD;
1078 for(idx = 0; idx < pduInfo->harqInfo.numHarq; idx++)
1080 pduInfo->harqInfo.harqValue[idx] = result[ind%50];
1082 /*TBD: To use harq ind with random number and percentage*/
1083 //pduInfo->harqInfo.harqValue[idx] = (dlHqPassPer >= rand()%(100))?HARQ_PASS:HARQ_FAIL;
1088 /*******************************************************************
1090 * @brief Fills UCI Pdu Information
1094 * Function : fillUciPduInfo
1097 * Fills UCI Pdu Information
1099 * @params[in] Pointer to uciPdu
1101 * @return ROK - success
1104 * ****************************************************************/
1105 uint8_t fillUciPduInfo(fapi_uci_pdu_info_t *uciPdu, fapi_ul_pucch_pdu_t pucchPdu)
1109 /*TODO: The pduType is hardcoded here to support
1110 UCI Ind for PUCCH forat0/format1. This is to be
1111 modified when we get SR form UE */
1112 uciPdu->pduType = UCI_IND_PUCCH_F0F1;
1113 switch(uciPdu->pduType)
1117 case UCI_IND_PUCCH_F0F1:
1119 fapi_uci_o_pucch_f0f1_t *pduInfo = NULLP;
1121 pduInfo = &uciPdu->uci.uciPucchF0F1;
1122 ret = fillPucchF0F1PduInfo(pduInfo, pucchPdu);
1123 uciPdu->pduSize = sizeof(fapi_uci_o_pucch_f0f1_t);
1126 case UCI_IND_PUCCH_F2F3F4:
1129 DU_LOG("\nERROR --> PHY_STUB: Invalid Pdu Type %d", uciPdu->pduType);
1135 /*******************************************************************
1137 * @brief Build and send Uci indication
1141 * Function : l1BuildAndSendUciInd
1144 * Build and send Uci indication
1148 * @return ROK - success
1151 * ****************************************************************/
1152 uint8_t l1BuildAndSendUciInd(uint16_t slot, uint16_t sfn, fapi_ul_pucch_pdu_t pucchPdu)
1155 uint8_t nUciPdus = 0;
1157 uint32_t msgLen = 0;
1158 fapi_uci_indication_t *uciInd = NULLP;
1160 MAC_ALLOC(uciInd, sizeof(fapi_uci_indication_t));
1163 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for UCI Indication");
1166 memset(uciInd, 0, sizeof(fapi_uci_indication_t));
1168 uciInd->slot = slot;
1169 uciInd->numUcis = 1; //consdering the UCI Ind for SR
1170 nUciPdus = uciInd->numUcis;
1173 ret = fillUciPduInfo(&uciInd->uciPdu[uciIdx], pucchPdu);
1179 msgLen = sizeof(fapi_uci_indication_t)- sizeof(fapi_msg_t);
1180 fillMsgHeader(&uciInd->header, FAPI_UCI_INDICATION, msgLen);
1182 /* Sending UCI indication to MAC */
1183 DU_LOG("\nINFO --> PHY STUB: Sending UCI Indication to MAC");
1184 procPhyMessages(uciInd->header.msg_id, sizeof(fapi_uci_indication_t), (void *)uciInd);
1186 MAC_FREE(uciInd, sizeof(fapi_uci_indication_t));
1191 /*******************************************************************
1193 * @brief Handles Ul Tti request received from MAC
1197 * Function : l1HdlUlTtiReq
1200 * -Handles Ul Tti request received from MAC
1202 * @params[in] Message length
1203 * Ul Tti request message pointer
1207 * ****************************************************************/
1209 S16 l1HdlUlTtiReq(uint32_t msgLen, void *msg)
1212 p_fapi_api_queue_elem_t ulTtiElem = (p_fapi_api_queue_elem_t)msg;
1213 fapi_ul_tti_req_t *ulTtiReq = (fapi_ul_tti_req_t *)(ulTtiElem +1);
1214 uint8_t numPdus = ulTtiReq->nPdus;
1216 #ifdef ODU_SLOT_IND_DEBUG_LOG
1219 DU_LOG("\nINFO --> PHY STUB: No PDU received in UL TTI Req");
1223 DU_LOG("\nINFO --> PHY STUB: Received UL TTI Request");
1229 if(ulTtiReq->pdus[numPdus-1].pduType == 0)
1231 DU_LOG("\nINFO --> PHY STUB: PRACH PDU");
1233 /* Send RACH Ind to L2 for first UE */
1234 if(phyDb.ueDb.ueCb[UE_IDX_0].rachIndSent == false)
1236 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1237 phyDb.ueDb.ueCb[UE_IDX_0].rachIndSent = true;
1238 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1239 phyDb.ueDb.numActvUe++;
1242 /* Send RACH Ind to L2 for second UE */
1243 if(phyDb.ueDb.ueCb[UE_IDX_1].rachIndSent == false && phyDb.ueDb.ueCb[UE_IDX_0].msgRrcReconfigComp == true)
1245 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1246 phyDb.ueDb.ueCb[UE_IDX_1].rachIndSent = true;
1247 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1248 phyDb.ueDb.numActvUe++;
1251 /* Send RACH Ind to L2 for third UE */
1252 if(phyDb.ueDb.ueCb[UE_IDX_2].rachIndSent == false && phyDb.ueDb.ueCb[UE_IDX_1].msgRrcReconfigComp == true)
1254 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1255 phyDb.ueDb.ueCb[UE_IDX_2].rachIndSent = true;
1256 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1257 phyDb.ueDb.numActvUe++;
1261 if(ulTtiReq->pdus[numPdus-1].pduType == 1)
1263 DU_LOG("\nINFO --> PHY STUB: PUSCH PDU");
1264 if (ROK == l1BuildAndSendCrcInd(ulTtiReq->slot, ulTtiReq->sfn,ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu))
1266 l1BuildAndSendRxDataInd(ulTtiReq->slot, ulTtiReq->sfn, ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu);
1269 if(ulTtiReq->pdus[numPdus-1].pduType == 2)
1271 DU_LOG("\nINFO --> PHY STUB: PUCCH PDU");
1273 fapi_ul_tti_req_t ulTtiSlotInd;
1274 memset(&ulTtiSlotInd, 0, sizeof(fapi_ul_tti_req_t));
1275 ulTtiSlotInd.slot = ulTtiReq->slot;
1276 ulTtiSlotInd.sfn = ulTtiReq->sfn;
1277 ADD_DELTA_TO_TIME(ulTtiSlotInd, ulTtiSlotInd, SLOT_DELAY, MAX_SLOTS);
1278 l1BuildAndSendUciInd(ulTtiSlotInd.slot, ulTtiSlotInd.sfn, ulTtiReq->pdus[numPdus-1].pdu.pucch_pdu);
1283 MAC_FREE(msg, msgLen);
1288 /*******************************************************************
1290 * @brief Builds and Send the stop Indication message to MAC
1294 * Function : l1BuildAndSendStopInd
1297 * -Send the Stop indication Message to MAC
1302 * ****************************************************************/
1303 uint16_t l1BuildAndSendStopInd()
1307 Buffer *mBuf = NULLP;
1308 fapi_stop_ind_t *stopIndMsg = NULLP;
1309 uint32_t msgLen = 0;
1311 MAC_ALLOC_SHRABL_BUF(stopIndMsg, sizeof(fapi_stop_ind_t));
1314 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for stop Indication Message");
1319 fillMsgHeader(&stopIndMsg->header, FAPI_STOP_INDICATION, msgLen);
1320 DU_LOG("\n\nINFO --> PHY_STUB: Processing Stop indication to MAC");
1322 memset(&pst, 0, sizeof(Pst));
1323 FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_STOP_IND);
1324 ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
1327 DU_LOG("\nERROR --> PHY_STUB: Failed to allocate memory for slot indication buffer");
1328 MAC_FREE_SHRABL_BUF(pst.region, pst.pool, stopIndMsg, sizeof(fapi_stop_ind_t));
1331 CMCHKPK(oduPackPointer, (PTR)stopIndMsg, mBuf);
1332 ODU_POST_TASK(&pst, mBuf);
1338 /*******************************************************************
1340 * @brief Handles stop request received from MAC
1344 * Function : l1HdlStopReq
1347 * -Handles stop request received from MAC
1349 * @params[in] Message length
1350 * stop request message pointer
1354 * ****************************************************************/
1356 S16 l1HdlStopReq(uint32_t msgLen, void *msg)
1359 if(lwrMacCb.phyState == PHY_STATE_RUNNING)
1361 l1HdlSlotIndicaion(TRUE);
1363 /* Initialize all global variables */
1366 memset(&phyDb.ueDb, 0, sizeof(UeDb));
1368 DU_LOG("\nINFO --> PHY_STUB: Slot Indication is stopped successfully");
1369 MAC_FREE(msg, msgLen);
1373 DU_LOG("\nINFO --> PHY_STUB: Received Stop Req in PHY State %d", lwrMacCb.phyState);
1374 MAC_FREE(msg, msgLen);
1382 /*******************************************************************
1384 * @brief Build And Send Rx Data Ind for Msg5
1388 * Function : l1BuildAndSendMsg5
1390 * Functionality: Build And Send Rx Data Ind for Msg5
1394 * @return ROK - success
1397 * ****************************************************************/
1398 uint8_t l1BuildAndSendMsg5(uint16_t sfn, uint16_t slot)
1402 fapi_rx_data_indication_t *rxDataInd;
1403 fapi_pdu_ind_info_t *pduInfo;
1405 uint16_t byteIdx = 0;
1406 uint32_t msgLen = 0;
1408 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1411 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication for msg5");
1414 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1416 /* TODO: Fill the required values */
1417 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1418 rxDataInd->sfn = sfn;
1419 rxDataInd->slot = slot;
1420 rxDataInd->numPdus = 1;
1422 pduInfo = &rxDataInd->pdus[idx];
1423 pduInfo->handle = 100;
1424 pduInfo->rnti = 100;
1425 pduInfo->harqId = 1;
1426 pduInfo->pdu_length = 25;
1427 pduInfo->ul_cqi = 0;
1428 pduInfo->timingAdvance = 0;
1431 /* Filling pdu with random values for testing */
1432 pduInfo->pduData = NULL;
1433 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1434 if(!pduInfo->pduData)
1436 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1441 pdu = (uint8_t *)pduInfo->pduData;
1443 uint8_t msg5PduLen = 33;
1444 /* For RRC setup complete
1445 MAC subheader format is R/F/LCId/L (2/3 bytes)
1447 L is length of PDU i.e 6bytes here
1448 From 38.321 section 6.1.1
1450 uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
1451 64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
1452 184, 56, 0, 0, 0, 0, 0};
1454 msg5PduLen += 2; /* 2bytes of header */
1455 memcpy(pdu, &msg5, msg5PduLen);
1456 byteIdx += msg5PduLen; /* 2 bytes of header */
1458 /* Filling MAC SDU for Padding bytes*/
1459 if(byteIdx < pduInfo->pdu_length)
1462 MAC subheader format is R/R/LCId (1byte)
1463 LCId is 63 for padding
1464 From 38.321 section 6.1.1
1466 pdu[byteIdx++] = 63;
1468 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1471 msgLen += pduInfo->pdu_length;
1473 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1475 /* Sending Rx data indication to MAC */
1476 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
1477 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1479 if(pduInfo->pdu_length)
1480 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1481 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1487 /*******************************************************************
1489 * @brief Handles Ul Dci request received from MAC
1493 * Function : l1HdlUlDciReq
1496 * -Handles Ul Dci request received from MAC
1498 * @params[in] Message length
1499 * Ul Dci request message pointer
1503 * ****************************************************************/
1505 S16 l1HdlUlDciReq(uint32_t msgLen, void *msg)
1508 p_fapi_api_queue_elem_t ulDciElem = (p_fapi_api_queue_elem_t)msg;
1509 fapi_ul_dci_req_t *ulDciReq = (fapi_ul_dci_req_t *)(ulDciElem +1);
1510 uint8_t numPdus = ulDciReq->numPdus;
1514 if(ulDciReq->pdus[numPdus-1].pduType == 0)
1516 DU_LOG("\nINFO --> PHY STUB: Received UL DCI Request for PDCCH PDU");
1517 //l1BuildAndSendMsg5(ulDciReq->sfn, ulDciReq->slot);
1523 MAC_FREE(msg, msgLen);
1528 /*******************************************************************
1530 * @brief Send UL user data to DU
1534 * Function : l1SendUlUserData
1536 * Functionality: Send UL user data to DU
1539 * @return ROK - success
1542 * ****************************************************************/
1543 uint8_t l1SendUlUserData(uint8_t drbId, uint8_t ueIdx)
1546 fapi_rx_data_indication_t *rxDataInd;
1547 fapi_pdu_ind_info_t *pduInfo;
1548 uint8_t *pdu = NULLP;
1549 uint16_t byteIdx = 0;
1550 uint32_t msgLen = 0;
1554 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1557 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1560 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1562 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1564 rxDataInd->slot = 0;
1565 rxDataInd->numPdus = 1;
1567 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1568 pduInfo = &rxDataInd->pdus[idx];
1569 pduInfo->handle = ueIdx + ODU_START_CRNTI;
1570 pduInfo->rnti = ueIdx + ODU_START_CRNTI;
1571 pduInfo->harqId = 1;
1572 /* Since user data size = 50bytes and 2 bytes of MAC header and 3 byte of RLC header,
1573 * setting tbsize = 56 from Table 5.1.3.2-1 spec 38.214 */
1574 pduInfo->pdu_length = 56;
1575 pduInfo->ul_cqi = 0;
1576 pduInfo->timingAdvance = 0;
1579 /* Filling pdu with random values for testing */
1580 pduInfo->pduData = NULL;
1581 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1582 if(!pduInfo->pduData)
1584 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1589 pdu = (uint8_t *)pduInfo->pduData;
1593 MAC subheader format is R/F/LCId/L (2/3 bytes)
1595 L is length of PDU i.e 50 bytes
1596 From 38.321 section 6.1.1
1597 From 38.322 section 6.2.2.4, 6.2.2.3 for AM, UM Header
1600 /* Below ulMsg supports 12bit SN for UM mode */
1602 lcId = MIN_DRB_LCID + drbId;
1603 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,
1604 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};
1605 msgLen += 2; /* 2bytes of header */
1606 memcpy(pdu, &ulMsg, msgLen);
1607 byteIdx += msgLen; /* 2 bytes of header */
1609 /* Filling MAC SDU for Padding bytes*/
1610 if(byteIdx < pduInfo->pdu_length)
1613 MAC subheader format is R/R/LCId (1byte)
1614 LCId is 63 for padding
1615 From 38.321 section 6.1.1
1617 pdu[byteIdx++] = 63;
1619 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1622 msgLen += pduInfo->pdu_length;
1624 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1626 /* Send Message to peer */
1627 while(cnt < NUM_UL_PACKETS)
1629 DU_LOG("\nDEBUG --> PHY STUB : Sending UL User Data[%d][LCID:%d] at sfn %d slot %d", cnt+1, lcId, sfnValue, slotValue);
1630 /* Sending Rx data indication to MAC */
1631 rxDataInd->sfn = sfnValue;
1632 rxDataInd->slot = slotValue;
1633 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1637 if(pduInfo->pdu_length)
1638 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1639 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1643 /*******************************************************************
1645 * @brief Sends RLC Status PDU to DU
1649 * Function : l1SendStatusPdu
1651 * Functionality: Send RLC Status PDU to DU
1654 * @return ROK - success
1657 * ****************************************************************/
1658 uint8_t l1SendStatusPdu()
1660 fapi_rx_data_indication_t *rxDataInd;
1661 fapi_pdu_ind_info_t *pduInfo;
1662 uint8_t *pdu = NULLP;
1663 uint16_t byteIdx = 0;
1664 uint32_t msgLen = 0;
1667 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1670 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1673 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1675 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1677 rxDataInd->slot = 0;
1678 rxDataInd->numPdus = 1;
1680 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1681 pduInfo = &rxDataInd->pdus[idx];
1682 pduInfo->handle = 100;
1683 pduInfo->rnti = 100;
1684 pduInfo->harqId = 1;
1685 /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1686 * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1687 pduInfo->pdu_length = 24;
1688 pduInfo->ul_cqi = 0;
1689 pduInfo->timingAdvance = 0;
1692 /* Filling pdu with random values for testing */
1693 pduInfo->pduData = NULL;
1694 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1695 if(!pduInfo->pduData)
1697 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1702 pdu = (uint8_t *)pduInfo->pduData;
1705 /* For RLC Status PDU
1706 * MAC subheader format is R/F/LCId/L (2/3 bytes)
1707 * LCId is 4 for DRB1
1708 * L is length of Status PDU i.e 3 bytes
1709 * From 38.321 section 6.1.1
1711 * RLC Status PDU format :
1712 * ---------------------------------
1713 * |D/C|CPT| ACK_SN |
1714 * ---------------------------------
1716 * ---------------------------------
1717 * |E1 | R | R | R | R | R | R | R |
1718 * ---------------------------------
1720 * Here, D/C bit = 0 for Control PDU
1721 * CPT bit = 0 since control pdu type is Status PDU
1722 * ACK_SN = 0 as of now, this can be changed based on the
1723 * scenario being tested
1724 * E1 = 0 because no NACK_SN, E1, E2 and E3 follows it
1725 * R = 0 i.e. reserved bits
1726 * From Spec 38.322 section 6.2.2.5
1728 uint8_t statusPdu[] = {4, msgLen, 0, 0, 0};
1729 msgLen += 2; /* 2bytes of header */
1730 memcpy(pdu, &statusPdu, msgLen);
1731 byteIdx += msgLen; /* 2 bytes of header */
1734 /* Filling MAC SDU for Padding bytes*/
1735 if(byteIdx < pduInfo->pdu_length)
1738 MAC subheader format is R/R/LCId (1byte)
1739 LCId is 63 for padding
1740 From 38.321 section 6.1.1
1742 pdu[byteIdx++] = 63;
1744 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1747 msgLen += pduInfo->pdu_length;
1749 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1751 /* Send Message to peer */
1752 DU_LOG("\nDEBUG --> PHY STUB : Sending RLC status pdu at sfn %d slot %d", sfnValue, slotValue);
1753 /* Sending Rx data indication to MAC */
1754 rxDataInd->sfn = sfnValue;
1755 rxDataInd->slot = slotValue;
1756 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1758 if(pduInfo->pdu_length)
1759 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1760 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1764 /*******************************************************************
1766 * @brief Receives message from MAC
1770 * Function : l1ProcessFapiRequest
1773 * - Receives message from MAC and calls handler
1775 * @params[in] Message type
1781 * ****************************************************************/
1783 void l1ProcessFapiRequest(uint8_t msgType, uint32_t msgLen, void *msg)
1788 case FAPI_PARAM_REQUEST:
1789 l1HdlParamReq(msgLen, msg);
1791 case FAPI_CONFIG_REQUEST:
1792 l1HdlConfigReq(msgLen, msg);
1794 case FAPI_START_REQUEST:
1795 l1HdlStartReq(msgLen, msg);
1797 case FAPI_DL_TTI_REQUEST:
1798 l1HdlDlTtiReq(msgLen, msg);
1800 case FAPI_TX_DATA_REQUEST:
1801 l1HdlTxDataReq(msgLen, msg);
1803 case FAPI_UL_TTI_REQUEST:
1804 l1HdlUlTtiReq(msgLen, msg);
1806 case FAPI_STOP_REQUEST:
1807 l1HdlStopReq(msgLen, msg);
1809 case FAPI_UL_DCI_REQUEST:
1810 l1HdlUlDciReq(msgLen, msg);
1813 DU_LOG("\nERROR --> PHY_STUB: Invalid message type[%x] received at PHY", msgType);
1820 /*******************************************************************
1822 * @brief Builds and Send the BSR message to MAC
1826 * Function : l1BuildAndSendBSR
1829 * -Send the BSR Message to MAC
1831 * @params[in] BSR type
1832 * array of LCGID and BSIdx
1835 *****************************************************************/
1836 uint16_t l1BuildAndSendBSR(uint8_t ueIdx, BsrType bsrType,\
1837 LcgBufferSize lcgBsIdx[MAX_NUM_LOGICAL_CHANNEL_GROUPS])
1839 fapi_rx_data_indication_t *rxDataInd;
1840 fapi_pdu_ind_info_t *pduInfo;
1841 uint8_t *pdu = NULLP;
1842 uint16_t byteIdx = 0;
1843 uint32_t msgLen = 0;
1844 uint8_t pduIdx = 0, lcgIdx = 0, lcgIdxPos = 0;
1846 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1849 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1852 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1854 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1856 rxDataInd->slot = 0;
1857 rxDataInd->numPdus = 1;
1859 pduInfo = &rxDataInd->pdus[pduIdx];
1860 pduInfo->handle = (ODU_START_CRNTI + ueIdx);
1861 pduInfo->rnti = (ODU_START_CRNTI + ueIdx);
1862 pduInfo->harqId = 1;
1864 /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1865 * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1866 pduInfo->pdu_length = 24;
1867 pduInfo->ul_cqi = 0;
1868 pduInfo->timingAdvance = 0;
1871 /* Filling pdu with random values for testing */
1872 pduInfo->pduData = NULL;
1873 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1874 if(!pduInfo->pduData)
1876 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1877 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1882 pdu = (uint8_t *)pduInfo->pduData;
1888 DU_LOG("\nDEBUG --> PHY_STUB: Forming SHORT BSR PDU ");
1891 * MAC subheader format is R/R/LcId (1Byte)
1893 * From 38.321 section 6.1.1
1895 pdu[byteIdx++] = 61; // LCID
1896 pdu[byteIdx++] = (lcgBsIdx[0].lcgId << 5) | lcgBsIdx[0].bsIdx;
1902 DU_LOG("\nDEBUG --> PHY_STUB: Forming LONG BSR PDU ");
1905 * MAC subheader format is R/R/LcId (1Byte)
1907 * From 38.321 section 6.1.1
1909 pdu[byteIdx++] = 62; // LCID
1911 /*Octet where lcgId bitmap will be present*/
1912 lcgIdxPos = byteIdx;
1914 for(lcgIdx = 0; lcgIdx < MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
1916 if(lcgBsIdx[lcgIdx].bsIdx > 0)
1918 pdu[lcgIdxPos] |= 1 << lcgBsIdx[lcgIdx].lcgId;
1919 pdu[byteIdx++] = lcgBsIdx[lcgIdx].bsIdx;
1928 DU_LOG("\nERROR --> PHY_STUB: Incorrect BSR type:%d!", bsrType);
1929 if(pduInfo->pdu_length)
1930 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1931 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1935 /* Filling MAC SDU for Padding bytes*/
1936 if(byteIdx < pduInfo->pdu_length)
1939 * MAC subheader format is R/R/LCId (1byte)
1940 * LCId is 63 for padding
1941 * From 38.321 section 6.1.1
1943 pdu[byteIdx++] = 63;
1945 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1948 msgLen += pduInfo->pdu_length;
1949 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1951 /* Sending Rx data indication to MAC */
1952 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
1953 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1955 if(pduInfo->pdu_length)
1956 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1957 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1962 /**********************************************************************
1964 **********************************************************************/