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 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, fapi_ul_pusch_pdu_t puschPdu)
290 uint8_t result[]={0,//MSG3
292 0,//MSG5 RRC Setup Complete
293 0,//Security Mode Complete
294 0,//Registraion Complete
295 0,//RRC Reconfiguration Complete
312 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
316 static uint8_t ind=0;
318 fapi_crc_ind_t *crcInd;
320 MAC_ALLOC(crcInd, sizeof(fapi_crc_ind_t));
323 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for CRC Indication Message");
326 memset(crcInd, 0, sizeof(fapi_crc_ind_t));
328 /* TODO: Fill the required values. As of now only 1 CRC status PASS is filled */
333 crcInd->crc[idx].handle = puschPdu.handle;
334 crcInd->crc[idx].rnti = puschPdu.rnti;
335 crcInd->crc[idx].harqId = puschPdu.puschData.harqProcessId;
336 crcInd->crc[idx].tbCrcStatus = 0;
337 crcInd->crc[idx].numCb = 1;
338 crcInd->crc[idx].cbCrcStatus[0] = result[ind%50];
339 ret = (0== crcInd->crc[idx].cbCrcStatus[0])?ROK:RFAILED;
340 /*TBD: To use crc ind with random number and percentage */
341 //crcInd->crc[idx].cbCrcStatus[0] = (crcPassPer >= rand()%(100))?0:1;
344 crcInd->crc[idx].ul_cqi = 0;
345 crcInd->crc[idx].timingAdvance = 0;
346 crcInd->crc[idx].rssi = 0;
348 fillMsgHeader(&crcInd->header, FAPI_CRC_INDICATION, \
349 sizeof(fapi_crc_ind_t) - sizeof(fapi_msg_t));
351 /* Sending CRC indication to MAC */
352 DU_LOG("\nINFO --> PHY STUB: Sending CRC Indication to MAC");
353 procPhyMessages(crcInd->header.msg_id, sizeof(fapi_crc_ind_t), (void *)crcInd);
354 MAC_FREE(crcInd, sizeof(fapi_crc_ind_t));
357 } /* l1BuildAndSendCrcInd */
360 /*******************************************************************
362 * @brief Build and send Rx data indication
366 * Function : l1BuildAndSendRxDataInd
369 * Build and send Rx data indication
373 * @return ROK - success
376 * ****************************************************************/
377 uint16_t l1BuildAndSendRxDataInd(uint16_t slot, uint16_t sfn, fapi_ul_pusch_pdu_t puschPdu)
379 uint8_t idx = 0, ueId = 0;
380 fapi_rx_data_indication_t *rxDataInd =NULLP;
381 fapi_pdu_ind_info_t *pduInfo =NULLP;
382 uint8_t *pdu = NULLP;
383 uint16_t byteIdx = 0;
387 GET_UE_ID(puschPdu.rnti, ueId);
388 if(phyDb.ueDb.ueCb[ueId-1].isCFRA)
390 if(!phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp)
392 /* In CF-RA in case of handover, RRC Reconfiguration Complete is sent
393 * by UE once RAR is received from DU */
394 phyDb.ueDb.ueCb[ueId-1].ueId = ueId;
395 phyDb.ueDb.ueCb[ueId-1].crnti = puschPdu.rnti;
396 phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp = true;
397 type = MSG_TYPE_RRC_RECONFIG_COMPLETE;
404 if(!phyDb.ueDb.ueCb[ueId-1].msg3Sent)
406 phyDb.ueDb.ueCb[ueId-1].ueId = ueId;
407 phyDb.ueDb.ueCb[ueId-1].crnti = puschPdu.rnti;
408 phyDb.ueDb.ueCb[ueId-1].msg3Sent = true;
409 type = MSG_TYPE_MSG3;
412 else if(!phyDb.ueDb.ueCb[ueId-1].msg5ShortBsrSent)
414 phyDb.ueDb.ueCb[ueId-1].msg5ShortBsrSent = true;
415 type = MSG_TYPE_SHORT_BSR;
417 else if(!phyDb.ueDb.ueCb[ueId-1].msg5Sent)
419 phyDb.ueDb.ueCb[ueId-1].msg5Sent = true;
420 type = MSG_TYPE_MSG5;
422 else if(!phyDb.ueDb.ueCb[ueId-1].msgNasSecurityModeComp)
424 phyDb.ueDb.ueCb[ueId-1].msgNasSecurityModeComp = true;
425 type = MSG_TYPE_NAS_SECURITY_MODE_COMPLETE;
427 else if(!phyDb.ueDb.ueCb[ueId-1].msgRrcSecurityModeComp)
429 phyDb.ueDb.ueCb[ueId-1].msgRrcSecurityModeComp = true;
430 type = MSG_TYPE_RRC_SECURITY_MODE_COMPLETE;
432 else if(!phyDb.ueDb.ueCb[ueId-1].msgRegistrationComp)
434 phyDb.ueDb.ueCb[ueId-1].msgRegistrationComp = true;
435 type = MSG_TYPE_REGISTRATION_COMPLETE;
437 else if(!phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp)
439 phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp = true;
440 type = MSG_TYPE_RRC_RECONFIG_COMPLETE;
446 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
449 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
452 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
454 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
455 rxDataInd->sfn = sfn;
456 rxDataInd->slot = slot;
457 rxDataInd->numPdus = 1;
459 pduInfo = &rxDataInd->pdus[idx];
460 pduInfo->handle = puschPdu.handle;
461 pduInfo->rnti = puschPdu.rnti;
462 pduInfo->harqId = puschPdu.puschData.harqProcessId;
463 pduInfo->pdu_length = puschPdu.puschData.tbSize ;
465 pduInfo->timingAdvance = 0;
468 /* Filling pdu with random values for testing */
469 pduInfo->pduData = NULL;
470 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
471 if(!pduInfo->pduData)
473 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
476 memset(pduInfo->pduData, 0, pduInfo->pdu_length);
478 pdu = (uint8_t *)pduInfo->pduData;
484 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG3 PDU ");
485 /* For Initial RRC setup Request,
486 MAC subheader format is R/R/LCId (1byte)
488 From 38.321 section 6.1.1
491 /* Hardcoding MAC PDU */
497 pdu[byteIdx++] = 103;
501 case MSG_TYPE_SHORT_BSR:
503 DU_LOG("\nDEBUG --> PHY_STUB: Forming SHORT BSR PDU ");
505 uint8_t bufferSizeIdx = 6;
508 MAC subheader format is R/R/LcId (1Byte)
510 From 38.321 section 6.1.1
512 pdu[byteIdx++] = 61; // LCID
513 pdu[byteIdx++] = (lcgId << 5) | bufferSizeIdx;
520 /* For RRC setup complete
522 * MAC subheader format is R/F/LCId/L (2/3 bytes)
524 * L is length of PDU i.e 6bytes here
525 * From 38.321 section 6.1.1
527 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
528 * From 38.322, section 6.2.2.4
530 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG5 PDU");
531 uint8_t msg5PduLen = 33; /* Length of MSG5 */
532 msg5PduLen += 2; /* RLC subheader */
533 uint8_t msg5[] = {1, msg5PduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 16, 0, \
534 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};
536 msg5PduLen += 2; /* 2 bytes of MAC header */
537 memcpy(pdu, &msg5, msg5PduLen);
538 byteIdx += msg5PduLen; /* 4 bytes of header : MAC+RLC */
542 case MSG_TYPE_NAS_SECURITY_MODE_COMPLETE:
544 /* For NAS security mode complete where RRC Container is dummy
546 * MAC subheader format is R/F/LCId/L (2/3 bytes)
548 * L is length of PDU i.e 6bytes here
549 * From 38.321 section 6.1.1
551 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
552 * From 38.322, section 6.2.2.4
554 DU_LOG("\nDEBUG --> PHY_STUB: Forming NAS SECURITY MODE COMPLETE PDU");
555 uint8_t pduLen = 93; /* Length of PDU */
556 pduLen += 2; /* RLC subheader */
557 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 0x3a, 0x2a, 0x3f,
558 0x02, 0x75, 0xa0, 0xa0, 0xc0, 0x80, 0x3f, 0x00, 0x2f, 0x3b, 0x80, 0x04, 0x9a, 0xa2, 0x81, 0x09, 0x80, 0xc0,
559 0x28, 0x04, 0xf8, 0xb8, 0x80, 0x1d, 0xbf, 0x00, 0x20, 0x8c, 0x80, 0x05, 0xf9, 0x00, 0x78, 0x88, 0x7a, 0x88,
560 0xd9, 0x00, 0x00, 0x00, 0x03, 0x08, 0x00, 0x81, 0x97, 0x02, 0x78, 0x38, 0x78, 0x38, 0x17, 0x82, 0x82, 0x00,
561 0x80, 0x00, 0x00, 0xa9, 0x00, 0x78, 0x88, 0x00, 0x00, 0x00, 0x8b, 0x83, 0xf8, 0x38, 0x60, 0x20, 0x0c, 0xc0,
562 0x50, 0x0c, 0x00, 0x80, 0x3a, 0x00, 0x00, 0x48, 0x29, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00};
564 pduLen += 2; /* 2 bytes of MAC header */
565 memcpy(pdu, &msg, pduLen);
566 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
569 case MSG_TYPE_RRC_SECURITY_MODE_COMPLETE:
571 /* For security mode complete where RRC Container is dummy
573 * MAC subheader format is R/F/LCId/L (2/3 bytes)
575 * L is length of PDU i.e 6bytes here
576 * From 38.321 section 6.1.1
578 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
579 * From 38.322, section 6.2.2.4
581 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC SECURITY MODE COMPLETE PDU");
582 uint8_t pduLen = 12; /* Length of PDU */
583 pduLen += 2; /* RLC subheader */
584 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 0x2a, 0x40, \
585 0, 0, 0, 0, 0, 0, 0, 0};
587 pduLen += 2; /* 2 bytes of MAC header */
588 memcpy(pdu, &msg, pduLen);
589 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
593 case MSG_TYPE_REGISTRATION_COMPLETE:
595 /* For rrc reconfig complete where RRC Container is dummy
597 * MAC subheader format is R/F/LCId/L (2/3 bytes)
599 * L is length of PDU i.e 6bytes here
600 * From 38.321 section 6.1.1
602 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
603 * From 38.322, section 6.2.2.4
605 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC REGISTRATION COMPLETE PDU");
606 uint8_t pduLen = 12; /* Length of PDU */
607 pduLen += 2; /* RLC subheader */
608 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 0x3a, 0x81, \
609 0xbf, 0, 0x21, 0x80, 0, 0, 0, 0};
611 pduLen += 2; /* 2 bytes of MAC header */
612 memcpy(pdu, &msg, pduLen);
613 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
617 case MSG_TYPE_RRC_RECONFIG_COMPLETE:
619 /* For rrc reconfig complete where RRC Container is dummy
621 * MAC subheader format is R/F/LCId/L (2/3 bytes)
623 * L is length of PDU i.e 6bytes here
624 * From 38.321 section 6.1.1
626 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
627 * From 38.322, section 6.2.2.4
629 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC RECONFIGURATION COMPLETE PDU");
630 uint8_t pduLen = 13; /* PDU length */
631 pduLen += 2; /* RLC sub header */
632 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 8, 64, 0, 0,\
633 0, 0, 0, 0, 0, 0, 0};
635 pduLen += 2; /* 2bytes of MAC header */
636 memcpy(pdu, &msg, pduLen);
637 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC*/
644 } /* End of switch(type) */
646 /* Filling MAC SDU for Padding bytes*/
647 if(byteIdx < pduInfo->pdu_length)
650 MAC subheader format is R/R/LCId (1byte)
651 LCId is 63 for padding
652 From 38.321 section 6.1.1
656 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
659 msgLen += pduInfo->pdu_length;
661 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
663 /* Sending Rx data indication to MAC */
664 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
665 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
667 if(pduInfo->pdu_length)
668 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
669 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
674 /*******************************************************************
676 * @brief Builds and Sends RACH indication to MAC
680 * Function : l1BuildAndSendRachInd
683 * Builds and Sends RACH indication to MAC
685 * @params[in] SFN value
687 * @return ROK - success
690 * ****************************************************************/
691 uint16_t l1BuildAndSendRachInd(uint16_t slot, uint16_t sfn, uint8_t raPreambleIdx)
694 uint8_t rachPduIdx = 0;
695 uint8_t preamIdx = 0;
696 fapi_rach_pdu_t *rachPdu;
697 fapi_rach_indication_t *rachInd;
699 /* Building RACH indication */
700 MAC_ALLOC(rachInd, sizeof(fapi_rach_indication_t));
703 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rach Indication Message");
706 memset(rachInd, 0, sizeof(fapi_rach_indication_t));
708 rachInd->slot = slot;
709 rachInd->numPdus = 1;
711 rachPdu = &rachInd->rachPdu[rachPduIdx];
712 rachPdu->phyCellId = NR_PCI;
713 rachPdu->symbolIndex = 0;
714 rachPdu->slotIndex = slot;
715 rachPdu->freqIndex = 0;
716 rachPdu->avgRssi = 0;
718 rachPdu->numPreamble = 1;
720 rachPdu->preambleInfo[preamIdx].preambleIndex = raPreambleIdx;
721 rachPdu->preambleInfo[preamIdx].timingAdvance = 0;
722 rachPdu->preambleInfo[preamIdx].preamblePwr = 0;
724 fillMsgHeader(&rachInd->header, FAPI_RACH_INDICATION, \
725 sizeof(fapi_rach_indication_t) - sizeof(fapi_msg_t));
727 /* Sending RACH indication to MAC */
728 DU_LOG("\nINFO --> PHY STUB: Sending RACH Indication to MAC");
729 procPhyMessages(rachInd->header.msg_id, sizeof(fapi_rach_indication_t), (void *)rachInd);
730 MAC_FREE(rachInd, sizeof(fapi_rach_indication_t));
735 /*******************************************************************
737 * @brief Builds and Send the Slot Indication message to MAC
741 * Function : l1BuildAndSendSlotIndication
744 * -Send the Slot indication Message to MAC
746 * @params[in] Message length
747 * config request message pointer
751 * ****************************************************************/
752 uint16_t l1BuildAndSendSlotIndication()
758 fapi_slot_ind_t *slotIndMsg;
760 MAC_ALLOC_SHRABL_BUF(slotIndMsg, sizeof(fapi_slot_ind_t));
763 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for slot Indication Message");
768 memset(slotIndMsg, 0, sizeof(fapi_slot_ind_t));
769 slotIndMsg->sfn = sfnValue;
770 slotIndMsg->slot = slotValue;
772 #ifdef ODU_SLOT_IND_DEBUG_LOG
773 DU_LOG("\n\nDEBUG --> PHY_STUB: Sending Slot Indication [%d : %d] to MAC", sfnValue, slotValue);
776 /* increment for the next TTI */
778 if(sfnValue >= MAX_SFN_VALUE && slotValue > MAX_SLOT_VALUE)
783 else if(slotValue > MAX_SLOT_VALUE)
788 fillMsgHeader(&slotIndMsg->header, FAPI_SLOT_INDICATION, \
789 sizeof(fapi_slot_ind_t) - sizeof(fapi_msg_t));
791 memset(&pst, 0, sizeof(Pst));
792 FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_SLOT_IND);
793 ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
796 DU_LOG("\nERROR --> PHY_STUB: Failed to allocate memory for slot indication buffer");
797 MAC_FREE_SHRABL_BUF(pst.region, pst.pool, slotIndMsg, sizeof(fapi_slot_ind_t));
800 CMCHKPK(oduPackPointer, (PTR)slotIndMsg, mBuf);
801 ODU_POST_TASK(&pst, mBuf);
807 /*******************************************************************
809 * @brief Handles start request received from MAC
813 * Function : l1HdlStartReq
816 * -Handles start request received from MAC
818 * @params[in] Message length
819 * config request message pointer
823 * ****************************************************************/
825 S16 l1HdlStartReq(uint32_t msgLen, void *msg)
828 if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
830 l1HdlSlotIndicaion(FALSE);
831 l1StartConsoleHandler();
832 MAC_FREE(msg, msgLen);
836 DU_LOG("\nINFO --> PHY_STUB: Received Start Req in PHY State %d", lwrMacCb.phyState);
837 MAC_FREE(msg, msgLen);
844 /*******************************************************************
846 * @brief Handles Dl Tti request received from MAC
850 * Function : l1HdlDlTtiReq
853 * -Handles Dl Tti request received from MAC
855 * @params[in] Message length
856 * Dl Tti request message pointer
860 * ****************************************************************/
862 S16 l1HdlDlTtiReq(uint16_t msgLen, void *msg)
865 p_fapi_api_queue_elem_t dlTtiElem = (p_fapi_api_queue_elem_t)msg;
866 fapi_dl_tti_req_t *dlTtiReq = (fapi_dl_tti_req_t *)(dlTtiElem +1);
868 uint8_t pduCount = 0;
870 #ifdef ODU_SLOT_IND_DEBUG_LOG
871 if(dlTtiReq->nPdus == 0)
873 DU_LOG("\nDEBUG --> PHY_STUB: No PDU in DL TTI Request");
877 DU_LOG("\nDEBUG --> PHY STUB: DL TTI Request at sfn=%d slot=%d",dlTtiReq->sfn,dlTtiReq->slot);
881 for(pduCount=0; pduCount<dlTtiReq->nPdus; pduCount++)
883 if(dlTtiReq->pdus[pduCount].pduType == 3) //SSB_PDU_TYPE
885 DU_LOG("\nINFO --> PHY_STUB: SSB PDU");
887 else if(dlTtiReq->pdus[pduCount].pduType == 0)
889 //DU_LOG("\nINFO --> PHY_STUB: PDCCH PDU");
890 DU_LOG("\nINFO --> PHY_STUB: PDCCH PDU sfn=%d slot=%d",dlTtiReq->sfn,dlTtiReq->slot);
892 else if(dlTtiReq->pdus[pduCount].pduType == 1)
894 DU_LOG("\nINFO --> PHY_STUB: PDSCH PDU");
898 /* Free FAPI message */
899 MAC_FREE(msg, msgLen);
904 /*******************************************************************
906 * @brief Handles tx_data request received from MAC
910 * Function : l1HdlTxDataReq
913 * -Handles tx_data request received from MAC
915 * @params[in] Message length
916 * tx_data request message pointer
920 * ****************************************************************/
922 S16 l1HdlTxDataReq(uint16_t msgLen, void *msg)
925 p_fapi_api_queue_elem_t txDataElem = (p_fapi_api_queue_elem_t)msg;
926 fapi_tx_data_req_t *txDataReq = (fapi_tx_data_req_t *)(txDataElem +1);
928 DU_LOG("\nINFO --> PHY STUB: TX DATA Request at sfn=%d slot=%d",txDataReq->sfn,txDataReq->slot);
932 DU_LOG("\nINFO --> PHY_STUB: TxDataPdu for DED MSG sent");
936 MAC_FREE(msg, msgLen);
942 /*******************************************************************
944 * @brief Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
948 * Function : fillPucchF0F1PduInfo
951 * Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
953 * @params[in] fapi_uci_o_pucch_f0f1_t *
955 * @return ROK - success
958 * ****************************************************************/
959 uint8_t fillPucchF0F1PduInfo(fapi_uci_o_pucch_f0f1_t *pduInfo, fapi_ul_pucch_pdu_t pucchPdu)
962 static uint8_t ind=0;
963 uint8_t result[]={0,//msg4
964 0,//Security Mode Command
965 0,//Registration Accept
966 0,//RRC Reconfiguration
985 pduInfo->handle = pucchPdu.handle;
986 pduInfo->pduBitmap = 1; //hardcoded for SR
987 if (pucchPdu.bitLenHarq)
989 pduInfo->pduBitmap |= HARQ_PDU_BITMASK;
991 pduInfo->pucchFormat = pucchPdu.formatType;
993 pduInfo->rnti = pucchPdu.rnti;
994 pduInfo->timingAdvance = 0;
996 if(pduInfo->pduBitmap & SR_PDU_BITMASK)
998 if (result[ind%50] == 0)
1000 pduInfo->srInfo.srIndication = SR_DETECTED;
1001 pduInfo->srInfo.srConfidenceLevel = CONFDC_LEVEL_GOOD;
1004 if(pduInfo->pduBitmap & HARQ_PDU_BITMASK)
1006 pduInfo->harqInfo.numHarq++;
1007 pduInfo->harqInfo.harqConfidenceLevel = CONFDC_LEVEL_GOOD;
1008 for(idx = 0; idx < pduInfo->harqInfo.numHarq; idx++)
1010 pduInfo->harqInfo.harqValue[idx] = result[ind%50];
1012 /*TBD: To use harq ind with random number and percentage*/
1013 //pduInfo->harqInfo.harqValue[idx] = (dlHqPassPer >= rand()%(100))?HARQ_PASS:HARQ_FAIL;
1018 /*******************************************************************
1020 * @brief Fills UCI Pdu Information
1024 * Function : fillUciPduInfo
1027 * Fills UCI Pdu Information
1029 * @params[in] Pointer to uciPdu
1031 * @return ROK - success
1034 * ****************************************************************/
1035 uint8_t fillUciPduInfo(fapi_uci_pdu_info_t *uciPdu, fapi_ul_pucch_pdu_t pucchPdu)
1039 /*TODO: The pduType is hardcoded here to support
1040 UCI Ind for PUCCH forat0/format1. This is to be
1041 modified when we get SR form UE */
1042 uciPdu->pduType = UCI_IND_PUCCH_F0F1;
1043 switch(uciPdu->pduType)
1047 case UCI_IND_PUCCH_F0F1:
1049 fapi_uci_o_pucch_f0f1_t *pduInfo = NULLP;
1051 pduInfo = &uciPdu->uci.uciPucchF0F1;
1052 ret = fillPucchF0F1PduInfo(pduInfo, pucchPdu);
1053 uciPdu->pduSize = sizeof(fapi_uci_o_pucch_f0f1_t);
1056 case UCI_IND_PUCCH_F2F3F4:
1059 DU_LOG("\nERROR --> PHY_STUB: Invalid Pdu Type %d", uciPdu->pduType);
1065 /*******************************************************************
1067 * @brief Build and send Uci indication
1071 * Function : l1BuildAndSendUciInd
1074 * Build and send Uci indication
1078 * @return ROK - success
1081 * ****************************************************************/
1082 uint8_t l1BuildAndSendUciInd(uint16_t slot, uint16_t sfn, fapi_ul_pucch_pdu_t pucchPdu)
1085 uint8_t nUciPdus = 0;
1087 uint32_t msgLen = 0;
1088 fapi_uci_indication_t *uciInd = NULLP;
1090 MAC_ALLOC(uciInd, sizeof(fapi_uci_indication_t));
1093 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for UCI Indication");
1096 memset(uciInd, 0, sizeof(fapi_uci_indication_t));
1098 uciInd->slot = slot;
1099 uciInd->numUcis = 1; //consdering the UCI Ind for SR
1100 nUciPdus = uciInd->numUcis;
1103 ret = fillUciPduInfo(&uciInd->uciPdu[uciIdx], pucchPdu);
1109 msgLen = sizeof(fapi_uci_indication_t)- sizeof(fapi_msg_t);
1110 fillMsgHeader(&uciInd->header, FAPI_UCI_INDICATION, msgLen);
1112 /* Sending UCI indication to MAC */
1113 DU_LOG("\nINFO --> PHY STUB: Sending UCI Indication to MAC");
1114 procPhyMessages(uciInd->header.msg_id, sizeof(fapi_uci_indication_t), (void *)uciInd);
1116 MAC_FREE(uciInd, sizeof(fapi_uci_indication_t));
1121 /*******************************************************************
1123 * @brief Handles Ul Tti request received from MAC
1127 * Function : l1HdlUlTtiReq
1130 * -Handles Ul Tti request received from MAC
1132 * @params[in] Message length
1133 * Ul Tti request message pointer
1137 * ****************************************************************/
1139 S16 l1HdlUlTtiReq(uint16_t msgLen, void *msg)
1142 p_fapi_api_queue_elem_t ulTtiElem = (p_fapi_api_queue_elem_t)msg;
1143 fapi_ul_tti_req_t *ulTtiReq = (fapi_ul_tti_req_t *)(ulTtiElem +1);
1144 uint8_t numPdus = ulTtiReq->nPdus;
1146 #ifdef ODU_SLOT_IND_DEBUG_LOG
1149 DU_LOG("\nINFO --> PHY STUB: No PDU received in UL TTI Req");
1153 DU_LOG("\nINFO --> PHY STUB: Received UL TTI Request");
1159 if(ulTtiReq->pdus[numPdus-1].pduType == 0)
1161 DU_LOG("\nINFO --> PHY STUB: PRACH PDU");
1163 /* Send RACH Ind to L2 for first UE */
1164 if(phyDb.ueDb.ueCb[UE_IDX_0].rachIndSent == false)
1166 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1167 phyDb.ueDb.ueCb[UE_IDX_0].rachIndSent = true;
1168 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1169 phyDb.ueDb.numActvUe++;
1172 /* Send RACH Ind to L2 for second UE */
1173 if(phyDb.ueDb.ueCb[UE_IDX_1].rachIndSent == false && phyDb.ueDb.ueCb[UE_IDX_0].msgRrcReconfigComp == true)
1175 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1176 phyDb.ueDb.ueCb[UE_IDX_1].rachIndSent = true;
1177 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1178 phyDb.ueDb.numActvUe++;
1181 /* Send RACH Ind to L2 for third UE */
1182 if(phyDb.ueDb.ueCb[UE_IDX_2].rachIndSent == false && phyDb.ueDb.ueCb[UE_IDX_1].msgRrcReconfigComp == true)
1184 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1185 phyDb.ueDb.ueCb[UE_IDX_2].rachIndSent = true;
1186 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1187 phyDb.ueDb.numActvUe++;
1191 if(ulTtiReq->pdus[numPdus-1].pduType == 1)
1193 DU_LOG("\nINFO --> PHY STUB: PUSCH PDU");
1194 if (ROK == l1BuildAndSendCrcInd(ulTtiReq->slot, ulTtiReq->sfn,ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu))
1196 l1BuildAndSendRxDataInd(ulTtiReq->slot, ulTtiReq->sfn, ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu);
1199 if(ulTtiReq->pdus[numPdus-1].pduType == 2)
1201 DU_LOG("\nINFO --> PHY STUB: PUCCH PDU");
1203 fapi_ul_tti_req_t ulTtiSlotInd;
1204 memset(&ulTtiSlotInd, 0, sizeof(fapi_ul_tti_req_t));
1205 ulTtiSlotInd.slot = ulTtiReq->slot;
1206 ulTtiSlotInd.sfn = ulTtiReq->sfn;
1207 ADD_DELTA_TO_TIME(ulTtiSlotInd, ulTtiSlotInd, SLOT_DELAY);
1208 l1BuildAndSendUciInd(ulTtiSlotInd.slot, ulTtiSlotInd.sfn, ulTtiReq->pdus[numPdus-1].pdu.pucch_pdu);
1213 MAC_FREE(msg, msgLen);
1218 /*******************************************************************
1220 * @brief Builds and Send the stop Indication message to MAC
1224 * Function : l1BuildAndSendStopInd
1227 * -Send the Stop indication Message to MAC
1232 * ****************************************************************/
1233 uint16_t l1BuildAndSendStopInd()
1237 Buffer *mBuf = NULLP;
1238 fapi_stop_ind_t *stopIndMsg = NULLP;
1239 uint32_t msgLen = 0;
1241 MAC_ALLOC_SHRABL_BUF(stopIndMsg, sizeof(fapi_stop_ind_t));
1244 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for stop Indication Message");
1249 fillMsgHeader(&stopIndMsg->header, FAPI_STOP_INDICATION, msgLen);
1250 DU_LOG("\n\nINFO --> PHY_STUB: Processing Stop indication to MAC");
1252 memset(&pst, 0, sizeof(Pst));
1253 FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_STOP_IND);
1254 ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
1257 DU_LOG("\nERROR --> PHY_STUB: Failed to allocate memory for slot indication buffer");
1258 MAC_FREE_SHRABL_BUF(pst.region, pst.pool, stopIndMsg, sizeof(fapi_stop_ind_t));
1261 CMCHKPK(oduPackPointer, (PTR)stopIndMsg, mBuf);
1262 ODU_POST_TASK(&pst, mBuf);
1268 /*******************************************************************
1270 * @brief Handles stop request received from MAC
1274 * Function : l1HdlStopReq
1277 * -Handles stop request received from MAC
1279 * @params[in] Message length
1280 * stop request message pointer
1284 * ****************************************************************/
1286 S16 l1HdlStopReq(uint32_t msgLen, void *msg)
1289 if(lwrMacCb.phyState == PHY_STATE_RUNNING)
1291 l1HdlSlotIndicaion(TRUE);
1293 /* Initialize all global variables */
1296 memset(&phyDb.ueDb, 0, sizeof(UeDb));
1298 DU_LOG("\nINFO --> PHY_STUB: Slot Indication is stopped successfully");
1299 MAC_FREE(msg, msgLen);
1303 DU_LOG("\nINFO --> PHY_STUB: Received Stop Req in PHY State %d", lwrMacCb.phyState);
1304 MAC_FREE(msg, msgLen);
1312 /*******************************************************************
1314 * @brief Build And Send Rx Data Ind for Msg5
1318 * Function : l1BuildAndSendMsg5
1320 * Functionality: Build And Send Rx Data Ind for Msg5
1324 * @return ROK - success
1327 * ****************************************************************/
1328 uint8_t l1BuildAndSendMsg5(uint16_t sfn, uint16_t slot)
1332 fapi_rx_data_indication_t *rxDataInd;
1333 fapi_pdu_ind_info_t *pduInfo;
1335 uint16_t byteIdx = 0;
1336 uint32_t msgLen = 0;
1338 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1341 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication for msg5");
1344 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1346 /* TODO: Fill the required values */
1347 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1348 rxDataInd->sfn = sfn;
1349 rxDataInd->slot = slot;
1350 rxDataInd->numPdus = 1;
1352 pduInfo = &rxDataInd->pdus[idx];
1353 pduInfo->handle = 100;
1354 pduInfo->rnti = 100;
1355 pduInfo->harqId = 1;
1356 pduInfo->pdu_length = 25;
1357 pduInfo->ul_cqi = 0;
1358 pduInfo->timingAdvance = 0;
1361 /* Filling pdu with random values for testing */
1362 pduInfo->pduData = NULL;
1363 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1364 if(!pduInfo->pduData)
1366 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1371 pdu = (uint8_t *)pduInfo->pduData;
1373 uint8_t msg5PduLen = 33;
1374 /* For RRC setup complete
1375 MAC subheader format is R/F/LCId/L (2/3 bytes)
1377 L is length of PDU i.e 6bytes here
1378 From 38.321 section 6.1.1
1380 uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
1381 64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
1382 184, 56, 0, 0, 0, 0, 0};
1384 msg5PduLen += 2; /* 2bytes of header */
1385 memcpy(pdu, &msg5, msg5PduLen);
1386 byteIdx += msg5PduLen; /* 2 bytes of header */
1388 /* Filling MAC SDU for Padding bytes*/
1389 if(byteIdx < pduInfo->pdu_length)
1392 MAC subheader format is R/R/LCId (1byte)
1393 LCId is 63 for padding
1394 From 38.321 section 6.1.1
1396 pdu[byteIdx++] = 63;
1398 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1401 msgLen += pduInfo->pdu_length;
1403 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1405 /* Sending Rx data indication to MAC */
1406 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
1407 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1409 if(pduInfo->pdu_length)
1410 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1411 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1417 /*******************************************************************
1419 * @brief Handles Ul Dci request received from MAC
1423 * Function : l1HdlUlDciReq
1426 * -Handles Ul Dci request received from MAC
1428 * @params[in] Message length
1429 * Ul Dci request message pointer
1433 * ****************************************************************/
1435 S16 l1HdlUlDciReq(uint16_t msgLen, void *msg)
1438 p_fapi_api_queue_elem_t ulDciElem = (p_fapi_api_queue_elem_t)msg;
1439 fapi_ul_dci_req_t *ulDciReq = (fapi_ul_dci_req_t *)(ulDciElem +1);
1440 uint8_t numPdus = ulDciReq->numPdus;
1444 if(ulDciReq->pdus[numPdus-1].pduType == 0)
1446 DU_LOG("\nINFO --> PHY STUB: Received UL DCI Request for PDCCH PDU");
1447 //l1BuildAndSendMsg5(ulDciReq->sfn, ulDciReq->slot);
1453 MAC_FREE(msg, msgLen);
1458 /*******************************************************************
1460 * @brief Send UL user data to DU
1464 * Function : l1SendUlUserData
1466 * Functionality: Send UL user data to DU
1469 * @return ROK - success
1472 * ****************************************************************/
1473 uint8_t l1SendUlUserData(uint8_t drbId, uint8_t ueIdx)
1476 fapi_rx_data_indication_t *rxDataInd;
1477 fapi_pdu_ind_info_t *pduInfo;
1478 uint8_t *pdu = NULLP;
1479 uint16_t byteIdx = 0;
1480 uint32_t msgLen = 0;
1484 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1487 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1490 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1492 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1494 rxDataInd->slot = 0;
1495 rxDataInd->numPdus = 1;
1497 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1498 pduInfo = &rxDataInd->pdus[idx];
1499 pduInfo->handle = ueIdx + ODU_START_CRNTI;
1500 pduInfo->rnti = ueIdx + ODU_START_CRNTI;
1501 pduInfo->harqId = 1;
1502 /* Since user data size = 50bytes and 2 bytes of MAC header and 3 byte of RLC header,
1503 * setting tbsize = 56 from Table 5.1.3.2-1 spec 38.214 */
1504 pduInfo->pdu_length = 56;
1505 pduInfo->ul_cqi = 0;
1506 pduInfo->timingAdvance = 0;
1509 /* Filling pdu with random values for testing */
1510 pduInfo->pduData = NULL;
1511 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1512 if(!pduInfo->pduData)
1514 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1519 pdu = (uint8_t *)pduInfo->pduData;
1523 MAC subheader format is R/F/LCId/L (2/3 bytes)
1525 L is length of PDU i.e 50 bytes
1526 From 38.321 section 6.1.1
1527 From 38.322 section 6.2.2.4, 6.2.2.3 for AM, UM Header
1530 /* Below ulMsg supports 12bit SN for UM mode */
1532 lcId = MIN_DRB_LCID + drbId;
1533 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,
1534 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};
1535 msgLen += 2; /* 2bytes of header */
1536 memcpy(pdu, &ulMsg, msgLen);
1537 byteIdx += msgLen; /* 2 bytes of header */
1539 /* Filling MAC SDU for Padding bytes*/
1540 if(byteIdx < pduInfo->pdu_length)
1543 MAC subheader format is R/R/LCId (1byte)
1544 LCId is 63 for padding
1545 From 38.321 section 6.1.1
1547 pdu[byteIdx++] = 63;
1549 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1552 msgLen += pduInfo->pdu_length;
1554 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1556 /* Send Message to peer */
1557 while(cnt < NUM_UL_PACKETS)
1559 DU_LOG("\nDEBUG --> PHY STUB : Sending UL User Data[%d][LCID:%d] at sfn %d slot %d", cnt+1, lcId, sfnValue, slotValue);
1560 /* Sending Rx data indication to MAC */
1561 rxDataInd->sfn = sfnValue;
1562 rxDataInd->slot = slotValue;
1563 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1567 if(pduInfo->pdu_length)
1568 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1569 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1573 /*******************************************************************
1575 * @brief Sends RLC Status PDU to DU
1579 * Function : l1SendStatusPdu
1581 * Functionality: Send RLC Status PDU to DU
1584 * @return ROK - success
1587 * ****************************************************************/
1588 uint8_t l1SendStatusPdu()
1590 fapi_rx_data_indication_t *rxDataInd;
1591 fapi_pdu_ind_info_t *pduInfo;
1592 uint8_t *pdu = NULLP;
1593 uint16_t byteIdx = 0;
1594 uint32_t msgLen = 0;
1597 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1600 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1603 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1605 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1607 rxDataInd->slot = 0;
1608 rxDataInd->numPdus = 1;
1610 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1611 pduInfo = &rxDataInd->pdus[idx];
1612 pduInfo->handle = 100;
1613 pduInfo->rnti = 100;
1614 pduInfo->harqId = 1;
1615 /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1616 * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1617 pduInfo->pdu_length = 24;
1618 pduInfo->ul_cqi = 0;
1619 pduInfo->timingAdvance = 0;
1622 /* Filling pdu with random values for testing */
1623 pduInfo->pduData = NULL;
1624 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1625 if(!pduInfo->pduData)
1627 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1632 pdu = (uint8_t *)pduInfo->pduData;
1635 /* For RLC Status PDU
1636 * MAC subheader format is R/F/LCId/L (2/3 bytes)
1637 * LCId is 4 for DRB1
1638 * L is length of Status PDU i.e 3 bytes
1639 * From 38.321 section 6.1.1
1641 * RLC Status PDU format :
1642 * ---------------------------------
1643 * |D/C|CPT| ACK_SN |
1644 * ---------------------------------
1646 * ---------------------------------
1647 * |E1 | R | R | R | R | R | R | R |
1648 * ---------------------------------
1650 * Here, D/C bit = 0 for Control PDU
1651 * CPT bit = 0 since control pdu type is Status PDU
1652 * ACK_SN = 0 as of now, this can be changed based on the
1653 * scenario being tested
1654 * E1 = 0 because no NACK_SN, E1, E2 and E3 follows it
1655 * R = 0 i.e. reserved bits
1656 * From Spec 38.322 section 6.2.2.5
1658 uint8_t statusPdu[] = {4, msgLen, 0, 0, 0};
1659 msgLen += 2; /* 2bytes of header */
1660 memcpy(pdu, &statusPdu, msgLen);
1661 byteIdx += msgLen; /* 2 bytes of header */
1664 /* Filling MAC SDU for Padding bytes*/
1665 if(byteIdx < pduInfo->pdu_length)
1668 MAC subheader format is R/R/LCId (1byte)
1669 LCId is 63 for padding
1670 From 38.321 section 6.1.1
1672 pdu[byteIdx++] = 63;
1674 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1677 msgLen += pduInfo->pdu_length;
1679 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1681 /* Send Message to peer */
1682 DU_LOG("\nDEBUG --> PHY STUB : Sending RLC status pdu at sfn %d slot %d", sfnValue, slotValue);
1683 /* Sending Rx data indication to MAC */
1684 rxDataInd->sfn = sfnValue;
1685 rxDataInd->slot = slotValue;
1686 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1688 if(pduInfo->pdu_length)
1689 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1690 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1694 /*******************************************************************
1696 * @brief Receives message from MAC
1700 * Function : l1ProcessFapiRequest
1703 * - Receives message from MAC and calls handler
1705 * @params[in] Message type
1711 * ****************************************************************/
1713 void l1ProcessFapiRequest(uint8_t msgType, uint32_t msgLen, void *msg)
1718 case FAPI_PARAM_REQUEST:
1719 l1HdlParamReq(msgLen, msg);
1721 case FAPI_CONFIG_REQUEST:
1722 l1HdlConfigReq(msgLen, msg);
1724 case FAPI_START_REQUEST:
1725 l1HdlStartReq(msgLen, msg);
1727 case FAPI_DL_TTI_REQUEST:
1728 l1HdlDlTtiReq(msgLen, msg);
1730 case FAPI_TX_DATA_REQUEST:
1731 l1HdlTxDataReq(msgLen, msg);
1733 case FAPI_UL_TTI_REQUEST:
1734 l1HdlUlTtiReq(msgLen, msg);
1736 case FAPI_STOP_REQUEST:
1737 l1HdlStopReq(msgLen, msg);
1739 case FAPI_UL_DCI_REQUEST:
1740 l1HdlUlDciReq(msgLen, msg);
1743 DU_LOG("\nERROR --> PHY_STUB: Invalid message type[%x] received at PHY", msgType);
1750 /*******************************************************************
1752 * @brief Builds and Send the BSR message to MAC
1756 * Function : l1BuildAndSendBSR
1759 * -Send the BSR Message to MAC
1761 * @params[in] BSR type
1762 * array of LCGID and BSIdx
1765 *****************************************************************/
1766 uint16_t l1BuildAndSendBSR(uint8_t ueIdx, BsrType bsrType,\
1767 LcgBufferSize lcgBsIdx[MAX_NUM_LOGICAL_CHANNEL_GROUPS])
1769 fapi_rx_data_indication_t *rxDataInd;
1770 fapi_pdu_ind_info_t *pduInfo;
1771 uint8_t *pdu = NULLP;
1772 uint16_t byteIdx = 0;
1773 uint32_t msgLen = 0;
1774 uint8_t pduIdx = 0, lcgIdx = 0, lcgIdxPos = 0;
1776 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1779 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1782 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1784 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1786 rxDataInd->slot = 0;
1787 rxDataInd->numPdus = 1;
1789 pduInfo = &rxDataInd->pdus[pduIdx];
1790 pduInfo->handle = (ODU_START_CRNTI + ueIdx);
1791 pduInfo->rnti = (ODU_START_CRNTI + ueIdx);
1792 pduInfo->harqId = 1;
1794 /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1795 * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1796 pduInfo->pdu_length = 24;
1797 pduInfo->ul_cqi = 0;
1798 pduInfo->timingAdvance = 0;
1801 /* Filling pdu with random values for testing */
1802 pduInfo->pduData = NULL;
1803 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1804 if(!pduInfo->pduData)
1806 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1807 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1812 pdu = (uint8_t *)pduInfo->pduData;
1818 DU_LOG("\nDEBUG --> PHY_STUB: Forming SHORT BSR PDU ");
1821 * MAC subheader format is R/R/LcId (1Byte)
1823 * From 38.321 section 6.1.1
1825 pdu[byteIdx++] = 61; // LCID
1826 pdu[byteIdx++] = (lcgBsIdx[0].lcgId << 5) | lcgBsIdx[0].bsIdx;
1832 DU_LOG("\nDEBUG --> PHY_STUB: Forming LONG BSR PDU ");
1835 * MAC subheader format is R/R/LcId (1Byte)
1837 * From 38.321 section 6.1.1
1839 pdu[byteIdx++] = 62; // LCID
1841 /*Octet where lcgId bitmap will be present*/
1842 lcgIdxPos = byteIdx;
1844 for(lcgIdx = 0; lcgIdx < MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
1846 if(lcgBsIdx[lcgIdx].bsIdx > 0)
1848 pdu[lcgIdxPos] |= 1 << lcgBsIdx[lcgIdx].lcgId;
1849 pdu[byteIdx++] = lcgBsIdx[lcgIdx].bsIdx;
1858 DU_LOG("\nERROR --> PHY_STUB: Incorrect BSR type:%d!", bsrType);
1859 if(pduInfo->pdu_length)
1860 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1861 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1865 /* Filling MAC SDU for Padding bytes*/
1866 if(byteIdx < pduInfo->pdu_length)
1869 * MAC subheader format is R/R/LCId (1byte)
1870 * LCId is 63 for padding
1871 * From 38.321 section 6.1.1
1873 pdu[byteIdx++] = 63;
1875 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1878 msgLen += pduInfo->pdu_length;
1879 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1881 /* Sending Rx data indication to MAC */
1882 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
1883 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1885 if(pduInfo->pdu_length)
1886 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1887 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1892 /**********************************************************************
1894 **********************************************************************/