1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /*This file contains stub for PHY to handle messages to/from MAC CL */
21 #include "common_def.h"
24 #include "du_app_mac_inf.h"
25 #include "mac_sch_interface.h"
27 #include "lwr_mac_fsm.h"
28 #include "lwr_mac_phy.h"
31 #include "fapi_vendor_extension.h"
33 #include "lwr_mac_upr_inf.h"
34 #include "mac_utils.h"
36 #include "phy_stub_utils.h"
37 #include "lwr_mac_phy_stub_inf.h"
39 /*******************************************************************
41 * @brief Builds and sends param response to MAC CL
45 * Function : l1BldAndSndParamRsp
48 * - Builds and sends param response to MAC
50 * @params[in] Config request message pointer
51 * @return ROK - success
54 * ****************************************************************/
55 S16 l1BldAndSndParamRsp(void *msg)
60 fapi_param_resp_t *fapiParamRsp;
62 MAC_ALLOC(fapiParamRsp, sizeof(fapi_param_resp_t));
65 DU_LOG("\nERROR --> PHY STUB: Memory allocation failed");
70 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_RELEASE_CAPABILITY_TAG, sizeof(uint16_t), 1, &msgLen);
71 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PHY_STATE_TAG, sizeof(uint16_t), 0, &msgLen);
72 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SKIP_BLANK_DL_CONFIG_TAG, sizeof(uint8_t), 0, &msgLen);
73 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SKIP_BLANK_UL_CONFIG_TAG, sizeof(uint8_t), 0, &msgLen);
74 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_NUM_CONFIG_TLVS_TO_REPORT_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
77 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CYCLIC_PREFIX_TAG, sizeof(uint8_t), 1, &msgLen);
78 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_SUBCARRIER_SPACING_DL_TAG, sizeof(uint8_t), 1, &msgLen);
79 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_BANDWIDTH_DL_TAG, sizeof(uint16_t), 1, &msgLen);
80 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_SUBCARRIER_SPACING_UL_TAG, sizeof(uint8_t), 0, &msgLen);
81 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_BANDWIDTH_UL_TAG, sizeof(uint16_t), 0, &msgLen);
84 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CCE_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
85 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CORESET_OUTSIDE_FIRST_3_OFDM_SYMS_OF_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
86 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRECODER_GRANULARITY_CORESET_TAG, sizeof(uint8_t), 0, &msgLen);
87 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDCCH_MU_MIMO_TAG, sizeof(uint8_t), 0, &msgLen);
88 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDCCH_PRECODER_CYCLING_TAG, sizeof(uint8_t), 0, &msgLen);
89 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDCCHS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
92 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUCCH_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
93 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PUCCHS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
96 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
97 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_ALLOCATION_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
98 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_VRB_TO_PRB_MAPPING_TAG, sizeof(uint8_t), 0, &msgLen);
99 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_CBG_TAG, sizeof(uint8_t), 0, &msgLen);
100 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_CONFIG_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
101 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_MAX_LENGTH_TAG, sizeof(uint8_t), 0, &msgLen);
102 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_ADDITIONAL_POS_TAG, sizeof(uint8_t), 0, &msgLen);
103 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDSCHS_TBS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
104 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_NUMBER_MIMO_LAYERS_PDSCH_TAG, sizeof(uint8_t), 0, &msgLen);
105 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_MAX_MODULATION_ORDER_DL_TAG, sizeof(uint8_t), 0, &msgLen);
106 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_MU_MIMO_USERS_DL_TAG, sizeof(uint8_t), 0, &msgLen);
107 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DATA_IN_DMRS_SYMBOLS_TAG, sizeof(uint8_t), 0, &msgLen);
108 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PREMPTIONSUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
109 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_NON_SLOT_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
112 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_UCI_MUX_ULSCH_IN_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
113 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_UCI_ONLY_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
114 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_FREQUENCY_HOPPING_TAG, sizeof(uint8_t), 0, &msgLen);
115 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_CONFIG_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
116 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_MAX_LEN_TAG, sizeof(uint8_t), 0, &msgLen);
117 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_ADDITIONAL_POS_TAG, sizeof(uint8_t), 0, &msgLen);
118 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_CBG_TAG, sizeof(uint8_t), 0, &msgLen);
119 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
120 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_ALLOCATION_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
121 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_VRB_TO_PRB_MAPPING_TAG, sizeof(uint8_t), 0, &msgLen);
122 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_MAX_PTRS_PORTS_TAG, sizeof(uint8_t), 0, &msgLen);
123 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDUSCHS_TBS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
124 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_NUMBER_MIMO_LAYERS_NON_CB_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
125 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_MODULATION_ORDER_UL_TAG, sizeof(uint8_t), 0, &msgLen);
126 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_MU_MIMO_USERS_UL_TAG, sizeof(uint8_t), 0, &msgLen);
127 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_DFTS_OFDM_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
128 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_AGGREGATION_FACTOR_TAG, sizeof(uint8_t), 0, &msgLen);
131 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_LONG_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
132 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_SHORT_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
133 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_RESTRICTED_SETS_TAG, sizeof(uint8_t), 0, &msgLen);
134 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PRACH_FD_OCCASIONS_IN_A_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
136 /* MEASUREMENT TAG */
137 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_RSSI_MEASUREMENT_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
139 fapiParamRsp->number_of_tlvs = index;
140 msgLen += sizeof(fapi_param_resp_t) - sizeof(fapi_msg_t);
141 fillMsgHeader(&fapiParamRsp->header, FAPI_PARAM_RESPONSE, msgLen);
142 fapiParamRsp->error_code = MSG_OK;
144 DU_LOG("\nINFO --> PHY_STUB: Sending Param Request to Lower Mac");
145 procPhyMessages(fapiParamRsp->header.msg_id, sizeof(fapi_param_resp_t), (void *)fapiParamRsp);
146 MAC_FREE(fapiParamRsp, sizeof(fapi_param_resp_t));
151 /*******************************************************************
153 * @brief Builds and sends config response to lower mac
157 * Function : l1BldAndSndConfigRsp
160 * - Builds and sends config response to MAC
162 * @params[in] Config request message pointer
163 * @return ROK - success
166 * ****************************************************************/
168 S16 l1BldAndSndConfigRsp(void *msg)
172 fapi_config_resp_t *fapiConfigRsp;
174 MAC_ALLOC(fapiConfigRsp, sizeof(fapi_config_resp_t));
177 DU_LOG("\nERROR --> PHY STUB: Memory allocation failed");
180 memset(fapiConfigRsp, 0, sizeof(fapi_config_resp_t));
181 fapiConfigRsp->number_of_invalid_tlvs = NULLP;
182 fapiConfigRsp->number_of_inv_tlvs_idle_only = NULLP;
183 fapiConfigRsp->number_of_missing_tlvs = NULLP;
184 fapiConfigRsp->error_code = MSG_OK;
185 msgLen = sizeof(fapi_config_resp_t) - sizeof(fapi_msg_t);
186 fillMsgHeader(&fapiConfigRsp->header, FAPI_CONFIG_RESPONSE, msgLen);
188 DU_LOG("\nINFO --> PHY_STUB: Sending Config Response to Lower Mac");
190 procPhyMessages(fapiConfigRsp->header.msg_id, \
191 sizeof(fapi_config_resp_t), (void *)fapiConfigRsp);
192 MAC_FREE(fapiConfigRsp, sizeof(fapi_config_resp_t));
196 /*******************************************************************
198 * @brief Handles param request received from MAC
202 * Function : l1HdlParamReq
205 * -Handles param request received from MAC
207 * @params[in] Message length
208 * Param request message pointer
212 * ****************************************************************/
214 void l1HdlParamReq(uint32_t msgLen, void *msg)
217 DU_LOG("\nINFO --> PHY_STUB: Received Param Request in PHY");
219 /* Build and send PARAM RESPONSE */
220 if(l1BldAndSndParamRsp(msg)!= ROK)
222 DU_LOG("\nERROR --> PHY_STUB: Failed Sending Param Response");
224 MAC_FREE(msg, sizeof(fapi_param_req_t));
228 /*******************************************************************
230 * @brief Handles config request received from MAC
234 * Function : l1HdlConfigReq
237 * -Handles config request received from MAC
239 * @params[in] Message length
240 * config request message pointer
244 * ****************************************************************/
246 void l1HdlConfigReq(uint32_t msgLen, void *msg)
248 memset(&phyDb.ueDb, 0, sizeof(UeDb));
249 cmInetAddr((char *)SOURCE_DU_IPV4_ADDR, &phyDb.ipCfgInfo.sourceDu);
250 cmInetAddr((char *)DESTINATION_DU_IPV4_ADDR, &phyDb.ipCfgInfo.destinationDu);
251 phyDb.ipCfgInfo.portNumber = PORT_NUMBER;
252 phyDb.isServer = true;
255 p_fapi_api_queue_elem_t configReqElem = (p_fapi_api_queue_elem_t)msg;
256 fapi_config_req_t *configReq = (fapi_config_req_t *)(configReqElem +1);
258 DU_LOG("\nINFO --> PHY_STUB: Received Config Request in PHY");
260 /* Handling CONFIG RESPONSE */
261 if(l1BldAndSndConfigRsp(configReq)!= ROK)
263 DU_LOG("\nERROR --> PHY_STUB: Failed Sending config Response");
266 MAC_FREE(msg, msgLen);
271 /*******************************************************************
273 * @brief Build and Send CRC Indication
277 * Function : l1BuildAndSendCrcInd
280 * Build and Send CRC Indication
284 * @return ROK - success
287 * ****************************************************************/
288 uint16_t l1BuildAndSendCrcInd(uint16_t slot, uint16_t sfn)
292 fapi_crc_ind_t *crcInd;
294 MAC_ALLOC(crcInd, sizeof(fapi_crc_ind_t));
297 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for CRC Indication Message");
300 memset(crcInd, 0, sizeof(fapi_crc_ind_t));
302 /* TODO: Fill the required values. As of now only 1 CRC status PASS is filled */
307 crcInd->crc[idx].handle = 0;
308 crcInd->crc[idx].rnti = 0;
309 crcInd->crc[idx].harqId = 0;
310 crcInd->crc[idx].tbCrcStatus = 0;
311 crcInd->crc[idx].numCb = 1;
312 crcInd->crc[idx].cbCrcStatus[0] = 0;
313 crcInd->crc[idx].ul_cqi = 0;
314 crcInd->crc[idx].timingAdvance = 0;
315 crcInd->crc[idx].rssi = 0;
317 fillMsgHeader(&crcInd->header, FAPI_CRC_INDICATION, \
318 sizeof(fapi_crc_ind_t) - sizeof(fapi_msg_t));
320 /* Sending RACH indication to MAC */
321 DU_LOG("\nINFO --> PHY STUB: Sending CRC Indication to MAC");
322 procPhyMessages(crcInd->header.msg_id, sizeof(fapi_crc_ind_t), (void *)crcInd);
323 MAC_FREE(crcInd, sizeof(fapi_crc_ind_t));
326 } /* l1BuildAndSendCrcInd */
329 /*******************************************************************
331 * @brief Build and send Rx data indication
335 * Function : l1BuildAndSendRxDataInd
338 * Build and send Rx data indication
342 * @return ROK - success
345 * ****************************************************************/
346 uint16_t l1BuildAndSendRxDataInd(uint16_t slot, uint16_t sfn, fapi_ul_pusch_pdu_t puschPdu)
348 uint8_t idx = 0, ueId = 0;
349 fapi_rx_data_indication_t *rxDataInd =NULLP;
350 fapi_pdu_ind_info_t *pduInfo =NULLP;
351 uint8_t *pdu = NULLP;
352 uint16_t byteIdx = 0;
356 GET_UE_ID(puschPdu.rnti, ueId);
357 if(phyDb.ueDb.ueCb[ueId-1].isCFRA)
359 /* In CF-RA in case of handover, RRC Reconfiguration Complete is sent
360 * by UE once RAR is received from DU */
361 phyDb.ueDb.ueCb[ueId-1].ueId = ueId;
362 phyDb.ueDb.ueCb[ueId-1].crnti = puschPdu.rnti;
363 phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp = true;
364 type = MSG_TYPE_RRC_RECONFIG_COMPLETE;
368 if(!phyDb.ueDb.ueCb[ueId-1].msg3Sent)
370 phyDb.ueDb.ueCb[ueId-1].ueId = ueId;
371 phyDb.ueDb.ueCb[ueId-1].crnti = puschPdu.rnti;
372 phyDb.ueDb.ueCb[ueId-1].msg3Sent = true;
373 type = MSG_TYPE_MSG3;
376 else if(!phyDb.ueDb.ueCb[ueId-1].msg5ShortBsrSent)
378 phyDb.ueDb.ueCb[ueId-1].msg5ShortBsrSent = true;
379 type = MSG_TYPE_SHORT_BSR;
381 else if(!phyDb.ueDb.ueCb[ueId-1].msg5Sent)
383 phyDb.ueDb.ueCb[ueId-1].msg5Sent = true;
384 type = MSG_TYPE_MSG5;
386 else if(!phyDb.ueDb.ueCb[ueId-1].msgRegistrationComp)
388 phyDb.ueDb.ueCb[ueId-1].msgRegistrationComp = true;
389 type = MSG_TYPE_REGISTRATION_COMPLETE;
391 else if(!phyDb.ueDb.ueCb[ueId-1].msgSecurityModeComp)
393 phyDb.ueDb.ueCb[ueId-1].msgSecurityModeComp = true;
394 type = MSG_TYPE_SECURITY_MODE_COMPLETE;
396 else if(!phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp)
398 phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp = true;
399 type = MSG_TYPE_RRC_RECONFIG_COMPLETE;
405 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
408 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
411 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
413 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
414 rxDataInd->sfn = sfn;
415 rxDataInd->slot = slot;
416 rxDataInd->numPdus = 1;
418 pduInfo = &rxDataInd->pdus[idx];
419 pduInfo->handle = puschPdu.handle;
420 pduInfo->rnti = puschPdu.rnti;
421 pduInfo->harqId = puschPdu.puschData.harqProcessId;
422 pduInfo->pdu_length = puschPdu.puschData.tbSize ;
424 pduInfo->timingAdvance = 0;
427 /* Filling pdu with random values for testing */
428 pduInfo->pduData = NULL;
429 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
430 if(!pduInfo->pduData)
432 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
435 memset(pduInfo->pduData, 0, pduInfo->pdu_length);
437 pdu = (uint8_t *)pduInfo->pduData;
443 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG3 PDU ");
444 /* For Initial RRC setup Request,
445 MAC subheader format is R/R/LCId (1byte)
447 From 38.321 section 6.1.1
450 /* Hardcoding MAC PDU */
456 pdu[byteIdx++] = 103;
460 case MSG_TYPE_SHORT_BSR:
462 DU_LOG("\nDEBUG --> PHY_STUB: Forming SHORT BSR PDU ");
464 uint8_t bufferSizeIdx = 6;
467 MAC subheader format is R/R/LcId (1Byte)
469 From 38.321 section 6.1.1
471 pdu[byteIdx++] = 61; // LCID
472 pdu[byteIdx++] = (lcgId << 5) | bufferSizeIdx;
479 /* For RRC setup complete
481 * MAC subheader format is R/F/LCId/L (2/3 bytes)
483 * L is length of PDU i.e 6bytes here
484 * From 38.321 section 6.1.1
486 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
487 * From 38.322, section 6.2.2.4
489 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG5 PDU");
490 uint8_t msg5PduLen = 33; /* Length of MSG5 */
491 msg5PduLen += 2; /* RLC subheader */
492 uint8_t msg5[] = {1, msg5PduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 16, 0, \
493 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};
495 msg5PduLen += 2; /* 2 bytes of MAC header */
496 memcpy(pdu, &msg5, msg5PduLen);
497 byteIdx += msg5PduLen; /* 4 bytes of header : MAC+RLC */
501 case MSG_TYPE_SECURITY_MODE_COMPLETE:
503 /* For security mode complete where RRC Container is dummy
505 * MAC subheader format is R/F/LCId/L (2/3 bytes)
507 * L is length of PDU i.e 6bytes here
508 * From 38.321 section 6.1.1
510 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
511 * From 38.322, section 6.2.2.4
513 DU_LOG("\nDEBUG --> PHY_STUB: Forming SECURITY MODE COMPLETE PDU");
514 uint8_t pduLen = 12; /* Length of PDU */
515 pduLen += 2; /* RLC subheader */
516 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 0x2a, 0x40, \
517 0, 0, 0, 0, 0, 0, 0, 0};
519 pduLen += 2; /* 2 bytes of MAC header */
520 memcpy(pdu, &msg, pduLen);
521 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
525 case MSG_TYPE_REGISTRATION_COMPLETE:
527 /* For rrc reconfig complete where RRC Container is dummy
529 * MAC subheader format is R/F/LCId/L (2/3 bytes)
531 * L is length of PDU i.e 6bytes here
532 * From 38.321 section 6.1.1
534 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
535 * From 38.322, section 6.2.2.4
537 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC REGISTRATION COMPLETE PDU");
538 uint8_t pduLen = 12; /* Length of PDU */
539 pduLen += 2; /* RLC subheader */
540 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 0x3a, 0x81, \
541 0xbf, 0, 0x21, 0x80, 0, 0, 0, 0};
543 pduLen += 2; /* 2 bytes of MAC header */
544 memcpy(pdu, &msg, pduLen);
545 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
549 case MSG_TYPE_RRC_RECONFIG_COMPLETE:
551 /* For rrc reconfig complete where RRC Container is dummy
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 RRC RECONFIGURATION COMPLETE PDU");
562 uint8_t pduLen = 13; /* PDU length */
563 pduLen += 2; /* RLC sub header */
564 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 8, 64, 0, 0,\
565 0, 0, 0, 0, 0, 0, 0};
567 pduLen += 2; /* 2bytes of MAC header */
568 memcpy(pdu, &msg, pduLen);
569 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC*/
576 } /* End of switch(type) */
578 /* Filling MAC SDU for Padding bytes*/
579 if(byteIdx < pduInfo->pdu_length)
582 MAC subheader format is R/R/LCId (1byte)
583 LCId is 63 for padding
584 From 38.321 section 6.1.1
588 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
591 msgLen += pduInfo->pdu_length;
593 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
595 /* Sending Rx data indication to MAC */
596 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
597 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
599 if(pduInfo->pdu_length)
600 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
601 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
606 /*******************************************************************
608 * @brief Builds and Sends RACH indication to MAC
612 * Function : l1BuildAndSendRachInd
615 * Builds and Sends RACH indication to MAC
617 * @params[in] SFN value
619 * @return ROK - success
622 * ****************************************************************/
623 uint16_t l1BuildAndSendRachInd(uint16_t slot, uint16_t sfn, uint8_t raPreambleIdx)
626 uint8_t rachPduIdx = 0;
627 uint8_t preamIdx = 0;
628 fapi_rach_pdu_t *rachPdu;
629 fapi_rach_indication_t *rachInd;
631 /* Building RACH indication */
632 MAC_ALLOC(rachInd, sizeof(fapi_rach_indication_t));
635 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rach Indication Message");
638 memset(rachInd, 0, sizeof(fapi_rach_indication_t));
640 rachInd->slot = slot;
641 rachInd->numPdus = 1;
643 rachPdu = &rachInd->rachPdu[rachPduIdx];
644 rachPdu->phyCellId = NR_PCI;
645 rachPdu->symbolIndex = 0;
646 rachPdu->slotIndex = slot;
647 rachPdu->freqIndex = 0;
648 rachPdu->avgRssi = 0;
650 rachPdu->numPreamble = 1;
652 rachPdu->preambleInfo[preamIdx].preambleIndex = raPreambleIdx;
653 rachPdu->preambleInfo[preamIdx].timingAdvance = 0;
654 rachPdu->preambleInfo[preamIdx].preamblePwr = 0;
656 fillMsgHeader(&rachInd->header, FAPI_RACH_INDICATION, \
657 sizeof(fapi_rach_indication_t) - sizeof(fapi_msg_t));
659 /* Sending RACH indication to MAC */
660 DU_LOG("\nINFO --> PHY STUB: Sending RACH Indication to MAC");
661 procPhyMessages(rachInd->header.msg_id, sizeof(fapi_rach_indication_t), (void *)rachInd);
662 MAC_FREE(rachInd, sizeof(fapi_rach_indication_t));
667 /*******************************************************************
669 * @brief Builds and Send the Slot Indication message to MAC
673 * Function : l1BuildAndSendSlotIndication
676 * -Send the Slot indication Message to MAC
678 * @params[in] Message length
679 * config request message pointer
683 * ****************************************************************/
684 uint16_t l1BuildAndSendSlotIndication()
690 fapi_slot_ind_t *slotIndMsg;
692 MAC_ALLOC_SHRABL_BUF(slotIndMsg, sizeof(fapi_slot_ind_t));
695 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for slot Indication Message");
700 memset(slotIndMsg, 0, sizeof(fapi_slot_ind_t));
701 slotIndMsg->sfn = sfnValue;
702 slotIndMsg->slot = slotValue;
704 #ifdef ODU_SLOT_IND_DEBUG_LOG
705 DU_LOG("\n\nDEBUG --> PHY_STUB: Sending Slot Indication [%d : %d] to MAC", sfnValue, slotValue);
708 /* increment for the next TTI */
710 if(sfnValue >= MAX_SFN_VALUE && slotValue > MAX_SLOT_VALUE)
715 else if(slotValue > MAX_SLOT_VALUE)
720 fillMsgHeader(&slotIndMsg->header, FAPI_SLOT_INDICATION, \
721 sizeof(fapi_slot_ind_t) - sizeof(fapi_msg_t));
723 memset(&pst, 0, sizeof(Pst));
724 FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_SLOT_IND);
725 ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
728 DU_LOG("\nERROR --> PHY_STUB: Failed to allocate memory for slot indication buffer");
729 MAC_FREE_SHRABL_BUF(pst.region, pst.pool, slotIndMsg, sizeof(fapi_slot_ind_t));
732 CMCHKPK(oduPackPointer, (PTR)slotIndMsg, mBuf);
733 ODU_POST_TASK(&pst, mBuf);
739 /*******************************************************************
741 * @brief Handles start request received from MAC
745 * Function : l1HdlStartReq
748 * -Handles start request received from MAC
750 * @params[in] Message length
751 * config request message pointer
755 * ****************************************************************/
757 S16 l1HdlStartReq(uint32_t msgLen, void *msg)
760 if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
762 l1HdlSlotIndicaion(FALSE);
763 l1StartConsoleHandler();
764 MAC_FREE(msg, msgLen);
768 DU_LOG("\nINFO --> PHY_STUB: Received Start Req in PHY State %d", lwrMacCb.phyState);
769 MAC_FREE(msg, msgLen);
776 /*******************************************************************
778 * @brief Handles Dl Tti request received from MAC
782 * Function : l1HdlDlTtiReq
785 * -Handles Dl Tti request received from MAC
787 * @params[in] Message length
788 * Dl Tti request message pointer
792 * ****************************************************************/
794 S16 l1HdlDlTtiReq(uint16_t msgLen, void *msg)
797 p_fapi_api_queue_elem_t dlTtiElem = (p_fapi_api_queue_elem_t)msg;
798 fapi_dl_tti_req_t *dlTtiReq = (fapi_dl_tti_req_t *)(dlTtiElem +1);
800 uint8_t pduCount = 0;
802 #ifdef ODU_SLOT_IND_DEBUG_LOG
803 if(dlTtiReq->nPdus == 0)
805 DU_LOG("\nDEBUG --> PHY_STUB: No PDU in DL TTI Request");
809 DU_LOG("\nDEBUG --> PHY STUB: DL TTI Request at sfn=%d slot=%d",dlTtiReq->sfn,dlTtiReq->slot);
813 for(pduCount=0; pduCount<dlTtiReq->nPdus; pduCount++)
815 if(dlTtiReq->pdus[pduCount].pduType == 3) //SSB_PDU_TYPE
817 DU_LOG("\nINFO --> PHY_STUB: SSB PDU");
819 else if(dlTtiReq->pdus[pduCount].pduType == 0)
821 DU_LOG("\nINFO --> PHY_STUB: PDCCH PDU");
823 else if(dlTtiReq->pdus[pduCount].pduType == 1)
825 DU_LOG("\nINFO --> PHY_STUB: PDSCH PDU");
829 /* Free FAPI message */
830 MAC_FREE(msg, msgLen);
835 /*******************************************************************
837 * @brief Handles tx_data request received from MAC
841 * Function : l1HdlTxDataReq
844 * -Handles tx_data request received from MAC
846 * @params[in] Message length
847 * tx_data request message pointer
851 * ****************************************************************/
853 S16 l1HdlTxDataReq(uint16_t msgLen, void *msg)
856 p_fapi_api_queue_elem_t txDataElem = (p_fapi_api_queue_elem_t)msg;
857 fapi_tx_data_req_t *txDataReq = (fapi_tx_data_req_t *)(txDataElem +1);
859 DU_LOG("\nINFO --> PHY STUB: TX DATA Request at sfn=%d slot=%d",txDataReq->sfn,txDataReq->slot);
863 DU_LOG("\nINFO --> PHY_STUB: TxDataPdu for DED MSG sent");
867 MAC_FREE(msg, msgLen);
873 /*******************************************************************
875 * @brief Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
879 * Function : fillPucchF0F1PduInfo
882 * Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
884 * @params[in] fapi_uci_o_pucch_f0f1_t *
886 * @return ROK - success
889 * ****************************************************************/
890 uint8_t fillPucchF0F1PduInfo(fapi_uci_o_pucch_f0f1_t *pduInfo, fapi_ul_pucch_pdu_t pucchPdu)
894 pduInfo->handle = pucchPdu.handle;
895 pduInfo->pduBitmap = 1; //hardcoded for SR
896 pduInfo->pucchFormat = pucchPdu.formatType;
898 pduInfo->rnti = pucchPdu.rnti;
899 pduInfo->timingAdvance = 0;
901 if(pduInfo->pduBitmap & SR_PDU_BITMASK)
903 pduInfo->srInfo.srIndication = SR_DETECTED;
904 pduInfo->srInfo.srConfidenceLevel = CONFDC_LEVEL_GOOD;
906 if(pduInfo->pduBitmap & HARQ_PDU_BITMASK)
908 pduInfo->harqInfo.numHarq++;
909 pduInfo->harqInfo.harqConfidenceLevel = CONFDC_LEVEL_GOOD;
910 for(idx = 0; idx < pduInfo->harqInfo.numHarq; idx++)
912 pduInfo->harqInfo.harqValue[idx] = HARQ_PASS;
917 /*******************************************************************
919 * @brief Fills UCI Pdu Information
923 * Function : fillUciPduInfo
926 * Fills UCI Pdu Information
928 * @params[in] Pointer to uciPdu
930 * @return ROK - success
933 * ****************************************************************/
934 uint8_t fillUciPduInfo(fapi_uci_pdu_info_t *uciPdu, fapi_ul_pucch_pdu_t pucchPdu)
938 /*TODO: The pduType is hardcoded here to support
939 UCI Ind for PUCCH forat0/format1. This is to be
940 modified when we get SR form UE */
941 uciPdu->pduType = UCI_IND_PUCCH_F0F1;
942 switch(uciPdu->pduType)
946 case UCI_IND_PUCCH_F0F1:
948 fapi_uci_o_pucch_f0f1_t *pduInfo = NULLP;
950 pduInfo = &uciPdu->uci.uciPucchF0F1;
951 ret = fillPucchF0F1PduInfo(pduInfo, pucchPdu);
952 uciPdu->pduSize = sizeof(fapi_uci_o_pucch_f0f1_t);
955 case UCI_IND_PUCCH_F2F3F4:
958 DU_LOG("\nERROR --> PHY_STUB: Invalid Pdu Type %d", uciPdu->pduType);
964 /*******************************************************************
966 * @brief Build and send Uci indication
970 * Function : l1BuildAndSendUciInd
973 * Build and send Uci indication
977 * @return ROK - success
980 * ****************************************************************/
981 uint8_t l1BuildAndSendUciInd(uint16_t slot, uint16_t sfn, fapi_ul_pucch_pdu_t pucchPdu)
984 uint8_t nUciPdus = 0;
987 fapi_uci_indication_t *uciInd = NULLP;
989 MAC_ALLOC(uciInd, sizeof(fapi_uci_indication_t));
992 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for UCI Indication");
995 memset(uciInd, 0, sizeof(fapi_uci_indication_t));
998 uciInd->numUcis = 1; //consdering the UCI Ind for SR
999 nUciPdus = uciInd->numUcis;
1002 ret = fillUciPduInfo(&uciInd->uciPdu[uciIdx], pucchPdu);
1008 msgLen = sizeof(fapi_uci_indication_t)- sizeof(fapi_msg_t);
1009 fillMsgHeader(&uciInd->header, FAPI_UCI_INDICATION, msgLen);
1011 /* Sending UCI indication to MAC */
1012 DU_LOG("\nINFO --> PHY STUB: Sending UCI Indication to MAC");
1013 procPhyMessages(uciInd->header.msg_id, sizeof(fapi_uci_indication_t), (void *)uciInd);
1015 MAC_FREE(uciInd, sizeof(fapi_uci_indication_t));
1020 /*******************************************************************
1022 * @brief Handles Ul Tti request received from MAC
1026 * Function : l1HdlUlTtiReq
1029 * -Handles Ul Tti request received from MAC
1031 * @params[in] Message length
1032 * Ul Tti request message pointer
1036 * ****************************************************************/
1038 S16 l1HdlUlTtiReq(uint16_t msgLen, void *msg)
1041 p_fapi_api_queue_elem_t ulTtiElem = (p_fapi_api_queue_elem_t)msg;
1042 fapi_ul_tti_req_t *ulTtiReq = (fapi_ul_tti_req_t *)(ulTtiElem +1);
1043 uint8_t numPdus = ulTtiReq->nPdus;
1045 #ifdef ODU_SLOT_IND_DEBUG_LOG
1048 DU_LOG("\nINFO --> PHY STUB: No PDU received in UL TTI Req");
1052 DU_LOG("\nINFO --> PHY STUB: Received UL TTI Request");
1058 if(ulTtiReq->pdus[numPdus-1].pduType == 0)
1060 DU_LOG("\nINFO --> PHY STUB: PRACH PDU");
1062 if(ulTtiReq->pdus[numPdus-1].pduType == 1)
1064 DU_LOG("\nINFO --> PHY STUB: PUSCH PDU");
1065 l1BuildAndSendRxDataInd(ulTtiReq->slot, ulTtiReq->sfn, ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu);
1067 if(ulTtiReq->pdus[numPdus-1].pduType == 2)
1069 DU_LOG("\nINFO --> PHY STUB: PUCCH PDU");
1071 fapi_ul_tti_req_t ulTtiSlotInd;
1072 memset(&ulTtiSlotInd, 0, sizeof(fapi_ul_tti_req_t));
1073 ulTtiSlotInd.slot = ulTtiReq->slot;
1074 ulTtiSlotInd.sfn = ulTtiReq->sfn;
1075 ADD_DELTA_TO_TIME(ulTtiSlotInd, ulTtiSlotInd, SLOT_DELAY);
1076 l1BuildAndSendUciInd(ulTtiSlotInd.slot, ulTtiSlotInd.sfn, ulTtiReq->pdus[numPdus-1].pdu.pucch_pdu);
1081 /* TODO: [SFN:SLOT] at which RACH Indication is sent should be calculated
1082 * based on PRACH cfg index */
1083 /* Send RACH Ind to L2 for first UE */
1084 if(phyDb.ueDb.ueCb[UE_IDX_0].rachIndSent == false && ulTtiReq->sfn == 16 && ulTtiReq->slot == 6)
1086 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1087 phyDb.ueDb.ueCb[UE_IDX_0].rachIndSent = true;
1088 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1089 phyDb.ueDb.numActvUe++;
1092 /* Send RACH Ind to L2 for second UE */
1093 if(phyDb.ueDb.ueCb[UE_IDX_1].rachIndSent == false && ulTtiReq->sfn == 304 && ulTtiReq->slot == 0)
1095 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1096 phyDb.ueDb.ueCb[UE_IDX_1].rachIndSent = true;
1097 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1098 phyDb.ueDb.numActvUe++;
1101 /* Send RACH Ind to L2 for third UE */
1102 if(phyDb.ueDb.ueCb[UE_IDX_2].rachIndSent == false && ulTtiReq->sfn == 526 && ulTtiReq->slot == 0)
1104 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1105 phyDb.ueDb.ueCb[UE_IDX_2].rachIndSent = true;
1106 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1107 phyDb.ueDb.numActvUe++;
1110 MAC_FREE(msg, msgLen);
1115 /*******************************************************************
1117 * @brief Builds and Send the stop Indication message to MAC
1121 * Function : l1BuildAndSendStopInd
1124 * -Send the Stop indication Message to MAC
1129 * ****************************************************************/
1130 uint16_t l1BuildAndSendStopInd()
1134 Buffer *mBuf = NULLP;
1135 fapi_stop_ind_t *stopIndMsg = NULLP;
1136 uint32_t msgLen = 0;
1138 MAC_ALLOC_SHRABL_BUF(stopIndMsg, sizeof(fapi_stop_ind_t));
1141 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for stop Indication Message");
1146 fillMsgHeader(&stopIndMsg->header, FAPI_STOP_INDICATION, msgLen);
1147 DU_LOG("\n\nINFO --> PHY_STUB: Processing Stop indication to MAC");
1149 memset(&pst, 0, sizeof(Pst));
1150 FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_STOP_IND);
1151 ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
1154 DU_LOG("\nERROR --> PHY_STUB: Failed to allocate memory for slot indication buffer");
1155 MAC_FREE_SHRABL_BUF(pst.region, pst.pool, stopIndMsg, sizeof(fapi_stop_ind_t));
1158 CMCHKPK(oduPackPointer, (PTR)stopIndMsg, mBuf);
1159 ODU_POST_TASK(&pst, mBuf);
1165 /*******************************************************************
1167 * @brief Handles stop request received from MAC
1171 * Function : l1HdlStopReq
1174 * -Handles stop request received from MAC
1176 * @params[in] Message length
1177 * stop request message pointer
1181 * ****************************************************************/
1183 S16 l1HdlStopReq(uint32_t msgLen, void *msg)
1186 if(lwrMacCb.phyState == PHY_STATE_RUNNING)
1188 l1HdlSlotIndicaion(TRUE);
1190 /* Initialize all global variables */
1193 memset(&phyDb.ueDb, 0, sizeof(UeDb));
1195 DU_LOG("\nINFO --> PHY_STUB: Slot Indication is stopped successfully");
1196 MAC_FREE(msg, msgLen);
1200 DU_LOG("\nINFO --> PHY_STUB: Received Stop Req in PHY State %d", lwrMacCb.phyState);
1201 MAC_FREE(msg, msgLen);
1209 /*******************************************************************
1211 * @brief Build And Send Rx Data Ind for Msg5
1215 * Function : l1BuildAndSendMsg5
1217 * Functionality: Build And Send Rx Data Ind for Msg5
1221 * @return ROK - success
1224 * ****************************************************************/
1225 uint8_t l1BuildAndSendMsg5(uint16_t sfn, uint16_t slot)
1229 fapi_rx_data_indication_t *rxDataInd;
1230 fapi_pdu_ind_info_t *pduInfo;
1232 uint16_t byteIdx = 0;
1233 uint32_t msgLen = 0;
1235 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1238 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication for msg5");
1241 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1243 /* TODO: Fill the required values */
1244 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1245 rxDataInd->sfn = sfn;
1246 rxDataInd->slot = slot;
1247 rxDataInd->numPdus = 1;
1249 pduInfo = &rxDataInd->pdus[idx];
1250 pduInfo->handle = 100;
1251 pduInfo->rnti = 100;
1252 pduInfo->harqId = 1;
1253 pduInfo->pdu_length = 25;
1254 pduInfo->ul_cqi = 0;
1255 pduInfo->timingAdvance = 0;
1258 /* Filling pdu with random values for testing */
1259 pduInfo->pduData = NULL;
1260 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1261 if(!pduInfo->pduData)
1263 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1268 pdu = (uint8_t *)pduInfo->pduData;
1270 uint8_t msg5PduLen = 33;
1271 /* For RRC setup complete
1272 MAC subheader format is R/F/LCId/L (2/3 bytes)
1274 L is length of PDU i.e 6bytes here
1275 From 38.321 section 6.1.1
1277 uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
1278 64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
1279 184, 56, 0, 0, 0, 0, 0};
1281 msg5PduLen += 2; /* 2bytes of header */
1282 memcpy(pdu, &msg5, msg5PduLen);
1283 byteIdx += msg5PduLen; /* 2 bytes of header */
1285 /* Filling MAC SDU for Padding bytes*/
1286 if(byteIdx < pduInfo->pdu_length)
1289 MAC subheader format is R/R/LCId (1byte)
1290 LCId is 63 for padding
1291 From 38.321 section 6.1.1
1293 pdu[byteIdx++] = 63;
1295 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1298 msgLen += pduInfo->pdu_length;
1300 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1302 /* Sending Rx data indication to MAC */
1303 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
1304 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1306 if(pduInfo->pdu_length)
1307 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1308 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1314 /*******************************************************************
1316 * @brief Handles Ul Dci request received from MAC
1320 * Function : l1HdlUlDciReq
1323 * -Handles Ul Dci request received from MAC
1325 * @params[in] Message length
1326 * Ul Dci request message pointer
1330 * ****************************************************************/
1332 S16 l1HdlUlDciReq(uint16_t msgLen, void *msg)
1335 p_fapi_api_queue_elem_t ulDciElem = (p_fapi_api_queue_elem_t)msg;
1336 fapi_ul_dci_req_t *ulDciReq = (fapi_ul_dci_req_t *)(ulDciElem +1);
1337 uint8_t numPdus = ulDciReq->numPdus;
1341 if(ulDciReq->pdus[numPdus-1].pduType == 0)
1343 DU_LOG("\nINFO --> PHY STUB: Received UL DCI Request for PDCCH PDU");
1344 //l1BuildAndSendMsg5(ulDciReq->sfn, ulDciReq->slot);
1350 MAC_FREE(msg, msgLen);
1355 /*******************************************************************
1357 * @brief Send UL user data to DU
1361 * Function : l1SendUlUserData
1363 * Functionality: Send UL user data to DU
1366 * @return ROK - success
1369 * ****************************************************************/
1370 uint8_t l1SendUlUserData(uint8_t drbId, uint8_t ueIdx)
1373 fapi_rx_data_indication_t *rxDataInd;
1374 fapi_pdu_ind_info_t *pduInfo;
1375 uint8_t *pdu = NULLP;
1376 uint16_t byteIdx = 0;
1377 uint32_t msgLen = 0;
1381 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1384 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1387 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1389 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1391 rxDataInd->slot = 0;
1392 rxDataInd->numPdus = 1;
1394 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1395 pduInfo = &rxDataInd->pdus[idx];
1396 pduInfo->handle = ueIdx + ODU_START_CRNTI;
1397 pduInfo->rnti = ueIdx + ODU_START_CRNTI;
1398 pduInfo->harqId = 1;
1399 /* Since user data size = 50bytes and 2 bytes of MAC header and 3 byte of RLC header,
1400 * setting tbsize = 56 from Table 5.1.3.2-1 spec 38.214 */
1401 pduInfo->pdu_length = 56;
1402 pduInfo->ul_cqi = 0;
1403 pduInfo->timingAdvance = 0;
1406 /* Filling pdu with random values for testing */
1407 pduInfo->pduData = NULL;
1408 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1409 if(!pduInfo->pduData)
1411 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1416 pdu = (uint8_t *)pduInfo->pduData;
1420 MAC subheader format is R/F/LCId/L (2/3 bytes)
1422 L is length of PDU i.e 50 bytes
1423 From 38.321 section 6.1.1
1424 From 38.322 section 6.2.2.4, 6.2.2.3 for AM, UM Header
1427 /* Below ulMsg supports 12bit SN for UM mode */
1429 lcId = MIN_DRB_LCID + drbId;
1430 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,
1431 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};
1432 msgLen += 2; /* 2bytes of header */
1433 memcpy(pdu, &ulMsg, msgLen);
1434 byteIdx += msgLen; /* 2 bytes of header */
1436 /* Filling MAC SDU for Padding bytes*/
1437 if(byteIdx < pduInfo->pdu_length)
1440 MAC subheader format is R/R/LCId (1byte)
1441 LCId is 63 for padding
1442 From 38.321 section 6.1.1
1444 pdu[byteIdx++] = 63;
1446 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1449 msgLen += pduInfo->pdu_length;
1451 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1453 /* Send Message to peer */
1454 while(cnt < NUM_UL_PACKETS)
1456 DU_LOG("\nDEBUG --> PHY STUB : Sending UL User Data[%d][LCID:%d] at sfn %d slot %d", cnt+1, lcId, sfnValue, slotValue);
1457 /* Sending Rx data indication to MAC */
1458 rxDataInd->sfn = sfnValue;
1459 rxDataInd->slot = slotValue;
1460 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1464 if(pduInfo->pdu_length)
1465 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1466 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1470 /*******************************************************************
1472 * @brief Sends RLC Status PDU to DU
1476 * Function : l1SendStatusPdu
1478 * Functionality: Send RLC Status PDU to DU
1481 * @return ROK - success
1484 * ****************************************************************/
1485 uint8_t l1SendStatusPdu()
1487 fapi_rx_data_indication_t *rxDataInd;
1488 fapi_pdu_ind_info_t *pduInfo;
1489 uint8_t *pdu = NULLP;
1490 uint16_t byteIdx = 0;
1491 uint32_t msgLen = 0;
1494 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1497 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1500 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1502 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1504 rxDataInd->slot = 0;
1505 rxDataInd->numPdus = 1;
1507 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1508 pduInfo = &rxDataInd->pdus[idx];
1509 pduInfo->handle = 100;
1510 pduInfo->rnti = 100;
1511 pduInfo->harqId = 1;
1512 /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1513 * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1514 pduInfo->pdu_length = 24;
1515 pduInfo->ul_cqi = 0;
1516 pduInfo->timingAdvance = 0;
1519 /* Filling pdu with random values for testing */
1520 pduInfo->pduData = NULL;
1521 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1522 if(!pduInfo->pduData)
1524 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1529 pdu = (uint8_t *)pduInfo->pduData;
1532 /* For RLC Status PDU
1533 * MAC subheader format is R/F/LCId/L (2/3 bytes)
1534 * LCId is 4 for DRB1
1535 * L is length of Status PDU i.e 3 bytes
1536 * From 38.321 section 6.1.1
1538 * RLC Status PDU format :
1539 * ---------------------------------
1540 * |D/C|CPT| ACK_SN |
1541 * ---------------------------------
1543 * ---------------------------------
1544 * |E1 | R | R | R | R | R | R | R |
1545 * ---------------------------------
1547 * Here, D/C bit = 0 for Control PDU
1548 * CPT bit = 0 since control pdu type is Status PDU
1549 * ACK_SN = 0 as of now, this can be changed based on the
1550 * scenario being tested
1551 * E1 = 0 because no NACK_SN, E1, E2 and E3 follows it
1552 * R = 0 i.e. reserved bits
1553 * From Spec 38.322 section 6.2.2.5
1555 uint8_t statusPdu[] = {4, msgLen, 0, 0, 0};
1556 msgLen += 2; /* 2bytes of header */
1557 memcpy(pdu, &statusPdu, msgLen);
1558 byteIdx += msgLen; /* 2 bytes of header */
1561 /* Filling MAC SDU for Padding bytes*/
1562 if(byteIdx < pduInfo->pdu_length)
1565 MAC subheader format is R/R/LCId (1byte)
1566 LCId is 63 for padding
1567 From 38.321 section 6.1.1
1569 pdu[byteIdx++] = 63;
1571 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1574 msgLen += pduInfo->pdu_length;
1576 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1578 /* Send Message to peer */
1579 DU_LOG("\nDEBUG --> PHY STUB : Sending RLC status pdu at sfn %d slot %d", sfnValue, slotValue);
1580 /* Sending Rx data indication to MAC */
1581 rxDataInd->sfn = sfnValue;
1582 rxDataInd->slot = slotValue;
1583 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1585 if(pduInfo->pdu_length)
1586 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1587 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1591 /*******************************************************************
1593 * @brief Receives message from MAC
1597 * Function : l1ProcessFapiRequest
1600 * - Receives message from MAC and calls handler
1602 * @params[in] Message type
1608 * ****************************************************************/
1610 void l1ProcessFapiRequest(uint8_t msgType, uint32_t msgLen, void *msg)
1615 case FAPI_PARAM_REQUEST:
1616 l1HdlParamReq(msgLen, msg);
1618 case FAPI_CONFIG_REQUEST:
1619 l1HdlConfigReq(msgLen, msg);
1621 case FAPI_START_REQUEST:
1622 l1HdlStartReq(msgLen, msg);
1624 case FAPI_DL_TTI_REQUEST:
1625 l1HdlDlTtiReq(msgLen, msg);
1627 case FAPI_TX_DATA_REQUEST:
1628 l1HdlTxDataReq(msgLen, msg);
1630 case FAPI_UL_TTI_REQUEST:
1631 l1HdlUlTtiReq(msgLen, msg);
1633 case FAPI_STOP_REQUEST:
1634 l1HdlStopReq(msgLen, msg);
1636 case FAPI_UL_DCI_REQUEST:
1637 l1HdlUlDciReq(msgLen, msg);
1640 DU_LOG("\nERROR --> PHY_STUB: Invalid message type[%x] received at PHY", msgType);
1647 /*******************************************************************
1649 * @brief Builds and Send the BSR message to MAC
1653 * Function : l1BuildAndSendBSR
1656 * -Send the BSR Message to MAC
1658 * @params[in] BSR type
1659 * array of LCGID and BSIdx
1662 *****************************************************************/
1663 uint16_t l1BuildAndSendBSR(uint8_t ueIdx, BsrType bsrType,\
1664 LcgBufferSize lcgBsIdx[MAX_NUM_LOGICAL_CHANNEL_GROUPS])
1666 fapi_rx_data_indication_t *rxDataInd;
1667 fapi_pdu_ind_info_t *pduInfo;
1668 uint8_t *pdu = NULLP;
1669 uint16_t byteIdx = 0;
1670 uint32_t msgLen = 0;
1671 uint8_t pduIdx = 0, lcgIdx = 0, lcgIdxPos = 0;
1673 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1676 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1679 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1681 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1683 rxDataInd->slot = 0;
1684 rxDataInd->numPdus = 1;
1686 pduInfo = &rxDataInd->pdus[pduIdx];
1687 pduInfo->handle = (ODU_START_CRNTI + ueIdx);
1688 pduInfo->rnti = (ODU_START_CRNTI + ueIdx);
1689 pduInfo->harqId = 1;
1691 /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1692 * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1693 pduInfo->pdu_length = 24;
1694 pduInfo->ul_cqi = 0;
1695 pduInfo->timingAdvance = 0;
1698 /* Filling pdu with random values for testing */
1699 pduInfo->pduData = NULL;
1700 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1701 if(!pduInfo->pduData)
1703 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1704 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1709 pdu = (uint8_t *)pduInfo->pduData;
1715 DU_LOG("\nDEBUG --> PHY_STUB: Forming SHORT BSR PDU ");
1718 * MAC subheader format is R/R/LcId (1Byte)
1720 * From 38.321 section 6.1.1
1722 pdu[byteIdx++] = 61; // LCID
1723 pdu[byteIdx++] = (lcgBsIdx[0].lcgId << 5) | lcgBsIdx[0].bsIdx;
1729 DU_LOG("\nDEBUG --> PHY_STUB: Forming LONG BSR PDU ");
1732 * MAC subheader format is R/R/LcId (1Byte)
1734 * From 38.321 section 6.1.1
1736 pdu[byteIdx++] = 62; // LCID
1738 /*Octet where lcgId bitmap will be present*/
1739 lcgIdxPos = byteIdx;
1741 for(lcgIdx = 0; lcgIdx < MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
1743 if(lcgBsIdx[lcgIdx].bsIdx > 0)
1745 pdu[lcgIdxPos] |= 1 << lcgBsIdx[lcgIdx].lcgId;
1746 pdu[byteIdx++] = lcgBsIdx[lcgIdx].bsIdx;
1755 DU_LOG("\nERROR --> PHY_STUB: Incorrect BSR type:%d!", bsrType);
1756 if(pduInfo->pdu_length)
1757 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1758 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1762 /* Filling MAC SDU for Padding bytes*/
1763 if(byteIdx < pduInfo->pdu_length)
1766 * MAC subheader format is R/R/LCId (1byte)
1767 * LCId is 63 for padding
1768 * From 38.321 section 6.1.1
1770 pdu[byteIdx++] = 63;
1772 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1775 msgLen += pduInfo->pdu_length;
1776 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1778 /* Sending Rx data indication to MAC */
1779 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
1780 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1782 if(pduInfo->pdu_length)
1783 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1784 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1789 /**********************************************************************
1791 **********************************************************************/