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, 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].msgSecurityModeComp)
424 phyDb.ueDb.ueCb[ueId-1].msgSecurityModeComp = true;
425 type = MSG_TYPE_SECURITY_MODE_COMPLETE;
427 else if(!phyDb.ueDb.ueCb[ueId-1].msgRegistrationComp)
429 phyDb.ueDb.ueCb[ueId-1].msgRegistrationComp = true;
430 type = MSG_TYPE_REGISTRATION_COMPLETE;
432 else if(!phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp)
434 phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp = true;
435 type = MSG_TYPE_RRC_RECONFIG_COMPLETE;
441 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
444 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
447 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
449 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
450 rxDataInd->sfn = sfn;
451 rxDataInd->slot = slot;
452 rxDataInd->numPdus = 1;
454 pduInfo = &rxDataInd->pdus[idx];
455 pduInfo->handle = puschPdu.handle;
456 pduInfo->rnti = puschPdu.rnti;
457 pduInfo->harqId = puschPdu.puschData.harqProcessId;
458 pduInfo->pdu_length = puschPdu.puschData.tbSize ;
460 pduInfo->timingAdvance = 0;
463 /* Filling pdu with random values for testing */
464 pduInfo->pduData = NULL;
465 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
466 if(!pduInfo->pduData)
468 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
471 memset(pduInfo->pduData, 0, pduInfo->pdu_length);
473 pdu = (uint8_t *)pduInfo->pduData;
479 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG3 PDU ");
480 /* For Initial RRC setup Request,
481 MAC subheader format is R/R/LCId (1byte)
483 From 38.321 section 6.1.1
486 /* Hardcoding MAC PDU */
492 pdu[byteIdx++] = 103;
496 case MSG_TYPE_SHORT_BSR:
498 DU_LOG("\nDEBUG --> PHY_STUB: Forming SHORT BSR PDU ");
500 uint8_t bufferSizeIdx = 6;
503 MAC subheader format is R/R/LcId (1Byte)
505 From 38.321 section 6.1.1
507 pdu[byteIdx++] = 61; // LCID
508 pdu[byteIdx++] = (lcgId << 5) | bufferSizeIdx;
515 /* For RRC setup complete
517 * MAC subheader format is R/F/LCId/L (2/3 bytes)
519 * L is length of PDU i.e 6bytes here
520 * From 38.321 section 6.1.1
522 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
523 * From 38.322, section 6.2.2.4
525 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG5 PDU");
526 uint8_t msg5PduLen = 33; /* Length of MSG5 */
527 msg5PduLen += 2; /* RLC subheader */
528 uint8_t msg5[] = {1, msg5PduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 16, 0, \
529 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};
531 msg5PduLen += 2; /* 2 bytes of MAC header */
532 memcpy(pdu, &msg5, msg5PduLen);
533 byteIdx += msg5PduLen; /* 4 bytes of header : MAC+RLC */
537 case MSG_TYPE_SECURITY_MODE_COMPLETE:
539 /* For security mode complete where RRC Container is dummy
541 * MAC subheader format is R/F/LCId/L (2/3 bytes)
543 * L is length of PDU i.e 6bytes here
544 * From 38.321 section 6.1.1
546 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
547 * From 38.322, section 6.2.2.4
549 DU_LOG("\nDEBUG --> PHY_STUB: Forming SECURITY MODE COMPLETE PDU");
550 uint8_t pduLen = 12; /* Length of PDU */
551 pduLen += 2; /* RLC subheader */
552 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 0x2a, 0x40, \
553 0, 0, 0, 0, 0, 0, 0, 0};
555 pduLen += 2; /* 2 bytes of MAC header */
556 memcpy(pdu, &msg, pduLen);
557 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
561 case MSG_TYPE_REGISTRATION_COMPLETE:
563 /* For rrc reconfig complete where RRC Container is dummy
565 * MAC subheader format is R/F/LCId/L (2/3 bytes)
567 * L is length of PDU i.e 6bytes here
568 * From 38.321 section 6.1.1
570 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
571 * From 38.322, section 6.2.2.4
573 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC REGISTRATION COMPLETE PDU");
574 uint8_t pduLen = 12; /* Length of PDU */
575 pduLen += 2; /* RLC subheader */
576 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 0x3a, 0x81, \
577 0xbf, 0, 0x21, 0x80, 0, 0, 0, 0};
579 pduLen += 2; /* 2 bytes of MAC header */
580 memcpy(pdu, &msg, pduLen);
581 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
585 case MSG_TYPE_RRC_RECONFIG_COMPLETE:
587 /* For rrc reconfig complete where RRC Container is dummy
589 * MAC subheader format is R/F/LCId/L (2/3 bytes)
591 * L is length of PDU i.e 6bytes here
592 * From 38.321 section 6.1.1
594 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
595 * From 38.322, section 6.2.2.4
597 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC RECONFIGURATION COMPLETE PDU");
598 uint8_t pduLen = 13; /* PDU length */
599 pduLen += 2; /* RLC sub header */
600 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 8, 64, 0, 0,\
601 0, 0, 0, 0, 0, 0, 0};
603 pduLen += 2; /* 2bytes of MAC header */
604 memcpy(pdu, &msg, pduLen);
605 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC*/
612 } /* End of switch(type) */
614 /* Filling MAC SDU for Padding bytes*/
615 if(byteIdx < pduInfo->pdu_length)
618 MAC subheader format is R/R/LCId (1byte)
619 LCId is 63 for padding
620 From 38.321 section 6.1.1
624 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
627 msgLen += pduInfo->pdu_length;
629 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
631 /* Sending Rx data indication to MAC */
632 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
633 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
635 if(pduInfo->pdu_length)
636 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
637 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
642 /*******************************************************************
644 * @brief Builds and Sends RACH indication to MAC
648 * Function : l1BuildAndSendRachInd
651 * Builds and Sends RACH indication to MAC
653 * @params[in] SFN value
655 * @return ROK - success
658 * ****************************************************************/
659 uint16_t l1BuildAndSendRachInd(uint16_t slot, uint16_t sfn, uint8_t raPreambleIdx)
662 uint8_t rachPduIdx = 0;
663 uint8_t preamIdx = 0;
664 fapi_rach_pdu_t *rachPdu;
665 fapi_rach_indication_t *rachInd;
667 /* Building RACH indication */
668 MAC_ALLOC(rachInd, sizeof(fapi_rach_indication_t));
671 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rach Indication Message");
674 memset(rachInd, 0, sizeof(fapi_rach_indication_t));
676 rachInd->slot = slot;
677 rachInd->numPdus = 1;
679 rachPdu = &rachInd->rachPdu[rachPduIdx];
680 rachPdu->phyCellId = NR_PCI;
681 rachPdu->symbolIndex = 0;
682 rachPdu->slotIndex = slot;
683 rachPdu->freqIndex = 0;
684 rachPdu->avgRssi = 0;
686 rachPdu->numPreamble = 1;
688 rachPdu->preambleInfo[preamIdx].preambleIndex = raPreambleIdx;
689 rachPdu->preambleInfo[preamIdx].timingAdvance = 0;
690 rachPdu->preambleInfo[preamIdx].preamblePwr = 0;
692 fillMsgHeader(&rachInd->header, FAPI_RACH_INDICATION, \
693 sizeof(fapi_rach_indication_t) - sizeof(fapi_msg_t));
695 /* Sending RACH indication to MAC */
696 DU_LOG("\nINFO --> PHY STUB: Sending RACH Indication to MAC");
697 procPhyMessages(rachInd->header.msg_id, sizeof(fapi_rach_indication_t), (void *)rachInd);
698 MAC_FREE(rachInd, sizeof(fapi_rach_indication_t));
703 /*******************************************************************
705 * @brief Builds and Send the Slot Indication message to MAC
709 * Function : l1BuildAndSendSlotIndication
712 * -Send the Slot indication Message to MAC
714 * @params[in] Message length
715 * config request message pointer
719 * ****************************************************************/
720 uint16_t l1BuildAndSendSlotIndication()
726 fapi_slot_ind_t *slotIndMsg;
728 MAC_ALLOC_SHRABL_BUF(slotIndMsg, sizeof(fapi_slot_ind_t));
731 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for slot Indication Message");
736 memset(slotIndMsg, 0, sizeof(fapi_slot_ind_t));
737 slotIndMsg->sfn = sfnValue;
738 slotIndMsg->slot = slotValue;
740 #ifdef ODU_SLOT_IND_DEBUG_LOG
741 DU_LOG("\n\nDEBUG --> PHY_STUB: Sending Slot Indication [%d : %d] to MAC", sfnValue, slotValue);
744 /* increment for the next TTI */
746 if(sfnValue >= MAX_SFN_VALUE && slotValue > MAX_SLOT_VALUE)
751 else if(slotValue > MAX_SLOT_VALUE)
756 fillMsgHeader(&slotIndMsg->header, FAPI_SLOT_INDICATION, \
757 sizeof(fapi_slot_ind_t) - sizeof(fapi_msg_t));
759 memset(&pst, 0, sizeof(Pst));
760 FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_SLOT_IND);
761 ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
764 DU_LOG("\nERROR --> PHY_STUB: Failed to allocate memory for slot indication buffer");
765 MAC_FREE_SHRABL_BUF(pst.region, pst.pool, slotIndMsg, sizeof(fapi_slot_ind_t));
768 CMCHKPK(oduPackPointer, (PTR)slotIndMsg, mBuf);
769 ODU_POST_TASK(&pst, mBuf);
775 /*******************************************************************
777 * @brief Handles start request received from MAC
781 * Function : l1HdlStartReq
784 * -Handles start request received from MAC
786 * @params[in] Message length
787 * config request message pointer
791 * ****************************************************************/
793 S16 l1HdlStartReq(uint32_t msgLen, void *msg)
796 if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
798 l1HdlSlotIndicaion(FALSE);
799 l1StartConsoleHandler();
800 MAC_FREE(msg, msgLen);
804 DU_LOG("\nINFO --> PHY_STUB: Received Start Req in PHY State %d", lwrMacCb.phyState);
805 MAC_FREE(msg, msgLen);
812 /*******************************************************************
814 * @brief Handles Dl Tti request received from MAC
818 * Function : l1HdlDlTtiReq
821 * -Handles Dl Tti request received from MAC
823 * @params[in] Message length
824 * Dl Tti request message pointer
828 * ****************************************************************/
830 S16 l1HdlDlTtiReq(uint16_t msgLen, void *msg)
833 p_fapi_api_queue_elem_t dlTtiElem = (p_fapi_api_queue_elem_t)msg;
834 fapi_dl_tti_req_t *dlTtiReq = (fapi_dl_tti_req_t *)(dlTtiElem +1);
836 uint8_t pduCount = 0;
838 #ifdef ODU_SLOT_IND_DEBUG_LOG
839 if(dlTtiReq->nPdus == 0)
841 DU_LOG("\nDEBUG --> PHY_STUB: No PDU in DL TTI Request");
845 DU_LOG("\nDEBUG --> PHY STUB: DL TTI Request at sfn=%d slot=%d",dlTtiReq->sfn,dlTtiReq->slot);
849 for(pduCount=0; pduCount<dlTtiReq->nPdus; pduCount++)
851 if(dlTtiReq->pdus[pduCount].pduType == 3) //SSB_PDU_TYPE
853 DU_LOG("\nINFO --> PHY_STUB: SSB PDU");
855 else if(dlTtiReq->pdus[pduCount].pduType == 0)
857 DU_LOG("\nINFO --> PHY_STUB: PDCCH PDU");
859 else if(dlTtiReq->pdus[pduCount].pduType == 1)
861 DU_LOG("\nINFO --> PHY_STUB: PDSCH PDU");
865 /* Free FAPI message */
866 MAC_FREE(msg, msgLen);
871 /*******************************************************************
873 * @brief Handles tx_data request received from MAC
877 * Function : l1HdlTxDataReq
880 * -Handles tx_data request received from MAC
882 * @params[in] Message length
883 * tx_data request message pointer
887 * ****************************************************************/
889 S16 l1HdlTxDataReq(uint16_t msgLen, void *msg)
892 p_fapi_api_queue_elem_t txDataElem = (p_fapi_api_queue_elem_t)msg;
893 fapi_tx_data_req_t *txDataReq = (fapi_tx_data_req_t *)(txDataElem +1);
895 DU_LOG("\nINFO --> PHY STUB: TX DATA Request at sfn=%d slot=%d",txDataReq->sfn,txDataReq->slot);
899 DU_LOG("\nINFO --> PHY_STUB: TxDataPdu for DED MSG sent");
903 MAC_FREE(msg, msgLen);
909 /*******************************************************************
911 * @brief Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
915 * Function : fillPucchF0F1PduInfo
918 * Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
920 * @params[in] fapi_uci_o_pucch_f0f1_t *
922 * @return ROK - success
925 * ****************************************************************/
926 uint8_t fillPucchF0F1PduInfo(fapi_uci_o_pucch_f0f1_t *pduInfo, fapi_ul_pucch_pdu_t pucchPdu)
929 static uint8_t ind=0;
930 uint8_t result[]={0,//msg4
931 0,//Security Mode Command
932 0,//Registration Accept
933 0,//RRC Reconfiguration
952 pduInfo->handle = pucchPdu.handle;
953 pduInfo->pduBitmap = 1; //hardcoded for SR
954 if (pucchPdu.bitLenHarq)
956 pduInfo->pduBitmap |= HARQ_PDU_BITMASK;
958 pduInfo->pucchFormat = pucchPdu.formatType;
960 pduInfo->rnti = pucchPdu.rnti;
961 pduInfo->timingAdvance = 0;
963 if(pduInfo->pduBitmap & SR_PDU_BITMASK)
965 if (result[ind%50] == 0)
967 pduInfo->srInfo.srIndication = SR_DETECTED;
968 pduInfo->srInfo.srConfidenceLevel = CONFDC_LEVEL_GOOD;
971 if(pduInfo->pduBitmap & HARQ_PDU_BITMASK)
973 pduInfo->harqInfo.numHarq++;
974 pduInfo->harqInfo.harqConfidenceLevel = CONFDC_LEVEL_GOOD;
975 for(idx = 0; idx < pduInfo->harqInfo.numHarq; idx++)
977 pduInfo->harqInfo.harqValue[idx] = result[ind%50];
979 /*TBD: To use harq ind with random number and percentage*/
980 //pduInfo->harqInfo.harqValue[idx] = (dlHqPassPer >= rand()%(100))?HARQ_PASS:HARQ_FAIL;
985 /*******************************************************************
987 * @brief Fills UCI Pdu Information
991 * Function : fillUciPduInfo
994 * Fills UCI Pdu Information
996 * @params[in] Pointer to uciPdu
998 * @return ROK - success
1001 * ****************************************************************/
1002 uint8_t fillUciPduInfo(fapi_uci_pdu_info_t *uciPdu, fapi_ul_pucch_pdu_t pucchPdu)
1006 /*TODO: The pduType is hardcoded here to support
1007 UCI Ind for PUCCH forat0/format1. This is to be
1008 modified when we get SR form UE */
1009 uciPdu->pduType = UCI_IND_PUCCH_F0F1;
1010 switch(uciPdu->pduType)
1014 case UCI_IND_PUCCH_F0F1:
1016 fapi_uci_o_pucch_f0f1_t *pduInfo = NULLP;
1018 pduInfo = &uciPdu->uci.uciPucchF0F1;
1019 ret = fillPucchF0F1PduInfo(pduInfo, pucchPdu);
1020 uciPdu->pduSize = sizeof(fapi_uci_o_pucch_f0f1_t);
1023 case UCI_IND_PUCCH_F2F3F4:
1026 DU_LOG("\nERROR --> PHY_STUB: Invalid Pdu Type %d", uciPdu->pduType);
1032 /*******************************************************************
1034 * @brief Build and send Uci indication
1038 * Function : l1BuildAndSendUciInd
1041 * Build and send Uci indication
1045 * @return ROK - success
1048 * ****************************************************************/
1049 uint8_t l1BuildAndSendUciInd(uint16_t slot, uint16_t sfn, fapi_ul_pucch_pdu_t pucchPdu)
1052 uint8_t nUciPdus = 0;
1054 uint32_t msgLen = 0;
1055 fapi_uci_indication_t *uciInd = NULLP;
1057 MAC_ALLOC(uciInd, sizeof(fapi_uci_indication_t));
1060 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for UCI Indication");
1063 memset(uciInd, 0, sizeof(fapi_uci_indication_t));
1065 uciInd->slot = slot;
1066 uciInd->numUcis = 1; //consdering the UCI Ind for SR
1067 nUciPdus = uciInd->numUcis;
1070 ret = fillUciPduInfo(&uciInd->uciPdu[uciIdx], pucchPdu);
1076 msgLen = sizeof(fapi_uci_indication_t)- sizeof(fapi_msg_t);
1077 fillMsgHeader(&uciInd->header, FAPI_UCI_INDICATION, msgLen);
1079 /* Sending UCI indication to MAC */
1080 DU_LOG("\nINFO --> PHY STUB: Sending UCI Indication to MAC");
1081 procPhyMessages(uciInd->header.msg_id, sizeof(fapi_uci_indication_t), (void *)uciInd);
1083 MAC_FREE(uciInd, sizeof(fapi_uci_indication_t));
1088 /*******************************************************************
1090 * @brief Handles Ul Tti request received from MAC
1094 * Function : l1HdlUlTtiReq
1097 * -Handles Ul Tti request received from MAC
1099 * @params[in] Message length
1100 * Ul Tti request message pointer
1104 * ****************************************************************/
1106 S16 l1HdlUlTtiReq(uint16_t msgLen, void *msg)
1109 p_fapi_api_queue_elem_t ulTtiElem = (p_fapi_api_queue_elem_t)msg;
1110 fapi_ul_tti_req_t *ulTtiReq = (fapi_ul_tti_req_t *)(ulTtiElem +1);
1111 uint8_t numPdus = ulTtiReq->nPdus;
1113 #ifdef ODU_SLOT_IND_DEBUG_LOG
1116 DU_LOG("\nINFO --> PHY STUB: No PDU received in UL TTI Req");
1120 DU_LOG("\nINFO --> PHY STUB: Received UL TTI Request");
1126 if(ulTtiReq->pdus[numPdus-1].pduType == 0)
1128 DU_LOG("\nINFO --> PHY STUB: PRACH PDU");
1130 if(ulTtiReq->pdus[numPdus-1].pduType == 1)
1132 DU_LOG("\nINFO --> PHY STUB: PUSCH PDU");
1133 if (ROK == l1BuildAndSendCrcInd(ulTtiReq->slot, ulTtiReq->sfn,ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu))
1135 l1BuildAndSendRxDataInd(ulTtiReq->slot, ulTtiReq->sfn, ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu);
1138 if(ulTtiReq->pdus[numPdus-1].pduType == 2)
1140 DU_LOG("\nINFO --> PHY STUB: PUCCH PDU");
1142 fapi_ul_tti_req_t ulTtiSlotInd;
1143 memset(&ulTtiSlotInd, 0, sizeof(fapi_ul_tti_req_t));
1144 ulTtiSlotInd.slot = ulTtiReq->slot;
1145 ulTtiSlotInd.sfn = ulTtiReq->sfn;
1146 ADD_DELTA_TO_TIME(ulTtiSlotInd, ulTtiSlotInd, SLOT_DELAY);
1147 l1BuildAndSendUciInd(ulTtiSlotInd.slot, ulTtiSlotInd.sfn, ulTtiReq->pdus[numPdus-1].pdu.pucch_pdu);
1152 /* TODO: [SFN:SLOT] at which RACH Indication is sent should be calculated
1153 * based on PRACH cfg index */
1154 /* Send RACH Ind to L2 for first UE */
1155 if(phyDb.ueDb.ueCb[UE_IDX_0].rachIndSent == false && ulTtiReq->sfn == 16 && ulTtiReq->slot == 6)
1157 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1158 phyDb.ueDb.ueCb[UE_IDX_0].rachIndSent = true;
1159 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1160 phyDb.ueDb.numActvUe++;
1164 /* Send RACH Ind to L2 for second UE */
1165 if(phyDb.ueDb.ueCb[UE_IDX_1].rachIndSent == false && ulTtiReq->sfn == 304 && ulTtiReq->slot == 0)
1167 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1168 phyDb.ueDb.ueCb[UE_IDX_1].rachIndSent = true;
1169 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1170 phyDb.ueDb.numActvUe++;
1173 /* Send RACH Ind to L2 for third UE */
1174 if(phyDb.ueDb.ueCb[UE_IDX_2].rachIndSent == false && ulTtiReq->sfn == 526 && ulTtiReq->slot == 0)
1176 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1177 phyDb.ueDb.ueCb[UE_IDX_2].rachIndSent = true;
1178 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1179 phyDb.ueDb.numActvUe++;
1182 MAC_FREE(msg, msgLen);
1187 /*******************************************************************
1189 * @brief Builds and Send the stop Indication message to MAC
1193 * Function : l1BuildAndSendStopInd
1196 * -Send the Stop indication Message to MAC
1201 * ****************************************************************/
1202 uint16_t l1BuildAndSendStopInd()
1206 Buffer *mBuf = NULLP;
1207 fapi_stop_ind_t *stopIndMsg = NULLP;
1208 uint32_t msgLen = 0;
1210 MAC_ALLOC_SHRABL_BUF(stopIndMsg, sizeof(fapi_stop_ind_t));
1213 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for stop Indication Message");
1218 fillMsgHeader(&stopIndMsg->header, FAPI_STOP_INDICATION, msgLen);
1219 DU_LOG("\n\nINFO --> PHY_STUB: Processing Stop indication to MAC");
1221 memset(&pst, 0, sizeof(Pst));
1222 FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_STOP_IND);
1223 ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
1226 DU_LOG("\nERROR --> PHY_STUB: Failed to allocate memory for slot indication buffer");
1227 MAC_FREE_SHRABL_BUF(pst.region, pst.pool, stopIndMsg, sizeof(fapi_stop_ind_t));
1230 CMCHKPK(oduPackPointer, (PTR)stopIndMsg, mBuf);
1231 ODU_POST_TASK(&pst, mBuf);
1237 /*******************************************************************
1239 * @brief Handles stop request received from MAC
1243 * Function : l1HdlStopReq
1246 * -Handles stop request received from MAC
1248 * @params[in] Message length
1249 * stop request message pointer
1253 * ****************************************************************/
1255 S16 l1HdlStopReq(uint32_t msgLen, void *msg)
1258 if(lwrMacCb.phyState == PHY_STATE_RUNNING)
1260 l1HdlSlotIndicaion(TRUE);
1262 /* Initialize all global variables */
1265 memset(&phyDb.ueDb, 0, sizeof(UeDb));
1267 DU_LOG("\nINFO --> PHY_STUB: Slot Indication is stopped successfully");
1268 MAC_FREE(msg, msgLen);
1272 DU_LOG("\nINFO --> PHY_STUB: Received Stop Req in PHY State %d", lwrMacCb.phyState);
1273 MAC_FREE(msg, msgLen);
1281 /*******************************************************************
1283 * @brief Build And Send Rx Data Ind for Msg5
1287 * Function : l1BuildAndSendMsg5
1289 * Functionality: Build And Send Rx Data Ind for Msg5
1293 * @return ROK - success
1296 * ****************************************************************/
1297 uint8_t l1BuildAndSendMsg5(uint16_t sfn, uint16_t slot)
1301 fapi_rx_data_indication_t *rxDataInd;
1302 fapi_pdu_ind_info_t *pduInfo;
1304 uint16_t byteIdx = 0;
1305 uint32_t msgLen = 0;
1307 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1310 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication for msg5");
1313 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1315 /* TODO: Fill the required values */
1316 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1317 rxDataInd->sfn = sfn;
1318 rxDataInd->slot = slot;
1319 rxDataInd->numPdus = 1;
1321 pduInfo = &rxDataInd->pdus[idx];
1322 pduInfo->handle = 100;
1323 pduInfo->rnti = 100;
1324 pduInfo->harqId = 1;
1325 pduInfo->pdu_length = 25;
1326 pduInfo->ul_cqi = 0;
1327 pduInfo->timingAdvance = 0;
1330 /* Filling pdu with random values for testing */
1331 pduInfo->pduData = NULL;
1332 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1333 if(!pduInfo->pduData)
1335 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1340 pdu = (uint8_t *)pduInfo->pduData;
1342 uint8_t msg5PduLen = 33;
1343 /* For RRC setup complete
1344 MAC subheader format is R/F/LCId/L (2/3 bytes)
1346 L is length of PDU i.e 6bytes here
1347 From 38.321 section 6.1.1
1349 uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
1350 64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
1351 184, 56, 0, 0, 0, 0, 0};
1353 msg5PduLen += 2; /* 2bytes of header */
1354 memcpy(pdu, &msg5, msg5PduLen);
1355 byteIdx += msg5PduLen; /* 2 bytes of header */
1357 /* Filling MAC SDU for Padding bytes*/
1358 if(byteIdx < pduInfo->pdu_length)
1361 MAC subheader format is R/R/LCId (1byte)
1362 LCId is 63 for padding
1363 From 38.321 section 6.1.1
1365 pdu[byteIdx++] = 63;
1367 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1370 msgLen += pduInfo->pdu_length;
1372 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1374 /* Sending Rx data indication to MAC */
1375 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
1376 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1378 if(pduInfo->pdu_length)
1379 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1380 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1386 /*******************************************************************
1388 * @brief Handles Ul Dci request received from MAC
1392 * Function : l1HdlUlDciReq
1395 * -Handles Ul Dci request received from MAC
1397 * @params[in] Message length
1398 * Ul Dci request message pointer
1402 * ****************************************************************/
1404 S16 l1HdlUlDciReq(uint16_t msgLen, void *msg)
1407 p_fapi_api_queue_elem_t ulDciElem = (p_fapi_api_queue_elem_t)msg;
1408 fapi_ul_dci_req_t *ulDciReq = (fapi_ul_dci_req_t *)(ulDciElem +1);
1409 uint8_t numPdus = ulDciReq->numPdus;
1413 if(ulDciReq->pdus[numPdus-1].pduType == 0)
1415 DU_LOG("\nINFO --> PHY STUB: Received UL DCI Request for PDCCH PDU");
1416 //l1BuildAndSendMsg5(ulDciReq->sfn, ulDciReq->slot);
1422 MAC_FREE(msg, msgLen);
1427 /*******************************************************************
1429 * @brief Send UL user data to DU
1433 * Function : l1SendUlUserData
1435 * Functionality: Send UL user data to DU
1438 * @return ROK - success
1441 * ****************************************************************/
1442 uint8_t l1SendUlUserData(uint8_t drbId, uint8_t ueIdx)
1445 fapi_rx_data_indication_t *rxDataInd;
1446 fapi_pdu_ind_info_t *pduInfo;
1447 uint8_t *pdu = NULLP;
1448 uint16_t byteIdx = 0;
1449 uint32_t msgLen = 0;
1453 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1456 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1459 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1461 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1463 rxDataInd->slot = 0;
1464 rxDataInd->numPdus = 1;
1466 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1467 pduInfo = &rxDataInd->pdus[idx];
1468 pduInfo->handle = ueIdx + ODU_START_CRNTI;
1469 pduInfo->rnti = ueIdx + ODU_START_CRNTI;
1470 pduInfo->harqId = 1;
1471 /* Since user data size = 50bytes and 2 bytes of MAC header and 3 byte of RLC header,
1472 * setting tbsize = 56 from Table 5.1.3.2-1 spec 38.214 */
1473 pduInfo->pdu_length = 56;
1474 pduInfo->ul_cqi = 0;
1475 pduInfo->timingAdvance = 0;
1478 /* Filling pdu with random values for testing */
1479 pduInfo->pduData = NULL;
1480 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1481 if(!pduInfo->pduData)
1483 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1488 pdu = (uint8_t *)pduInfo->pduData;
1492 MAC subheader format is R/F/LCId/L (2/3 bytes)
1494 L is length of PDU i.e 50 bytes
1495 From 38.321 section 6.1.1
1496 From 38.322 section 6.2.2.4, 6.2.2.3 for AM, UM Header
1499 /* Below ulMsg supports 12bit SN for UM mode */
1501 lcId = MIN_DRB_LCID + drbId;
1502 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,
1503 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};
1504 msgLen += 2; /* 2bytes of header */
1505 memcpy(pdu, &ulMsg, msgLen);
1506 byteIdx += msgLen; /* 2 bytes of header */
1508 /* Filling MAC SDU for Padding bytes*/
1509 if(byteIdx < pduInfo->pdu_length)
1512 MAC subheader format is R/R/LCId (1byte)
1513 LCId is 63 for padding
1514 From 38.321 section 6.1.1
1516 pdu[byteIdx++] = 63;
1518 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1521 msgLen += pduInfo->pdu_length;
1523 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1525 /* Send Message to peer */
1526 while(cnt < NUM_UL_PACKETS)
1528 DU_LOG("\nDEBUG --> PHY STUB : Sending UL User Data[%d][LCID:%d] at sfn %d slot %d", cnt+1, lcId, sfnValue, slotValue);
1529 /* Sending Rx data indication to MAC */
1530 rxDataInd->sfn = sfnValue;
1531 rxDataInd->slot = slotValue;
1532 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1536 if(pduInfo->pdu_length)
1537 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1538 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1542 /*******************************************************************
1544 * @brief Sends RLC Status PDU to DU
1548 * Function : l1SendStatusPdu
1550 * Functionality: Send RLC Status PDU to DU
1553 * @return ROK - success
1556 * ****************************************************************/
1557 uint8_t l1SendStatusPdu()
1559 fapi_rx_data_indication_t *rxDataInd;
1560 fapi_pdu_ind_info_t *pduInfo;
1561 uint8_t *pdu = NULLP;
1562 uint16_t byteIdx = 0;
1563 uint32_t msgLen = 0;
1566 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1569 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1572 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1574 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1576 rxDataInd->slot = 0;
1577 rxDataInd->numPdus = 1;
1579 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1580 pduInfo = &rxDataInd->pdus[idx];
1581 pduInfo->handle = 100;
1582 pduInfo->rnti = 100;
1583 pduInfo->harqId = 1;
1584 /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1585 * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1586 pduInfo->pdu_length = 24;
1587 pduInfo->ul_cqi = 0;
1588 pduInfo->timingAdvance = 0;
1591 /* Filling pdu with random values for testing */
1592 pduInfo->pduData = NULL;
1593 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1594 if(!pduInfo->pduData)
1596 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1601 pdu = (uint8_t *)pduInfo->pduData;
1604 /* For RLC Status PDU
1605 * MAC subheader format is R/F/LCId/L (2/3 bytes)
1606 * LCId is 4 for DRB1
1607 * L is length of Status PDU i.e 3 bytes
1608 * From 38.321 section 6.1.1
1610 * RLC Status PDU format :
1611 * ---------------------------------
1612 * |D/C|CPT| ACK_SN |
1613 * ---------------------------------
1615 * ---------------------------------
1616 * |E1 | R | R | R | R | R | R | R |
1617 * ---------------------------------
1619 * Here, D/C bit = 0 for Control PDU
1620 * CPT bit = 0 since control pdu type is Status PDU
1621 * ACK_SN = 0 as of now, this can be changed based on the
1622 * scenario being tested
1623 * E1 = 0 because no NACK_SN, E1, E2 and E3 follows it
1624 * R = 0 i.e. reserved bits
1625 * From Spec 38.322 section 6.2.2.5
1627 uint8_t statusPdu[] = {4, msgLen, 0, 0, 0};
1628 msgLen += 2; /* 2bytes of header */
1629 memcpy(pdu, &statusPdu, msgLen);
1630 byteIdx += msgLen; /* 2 bytes of header */
1633 /* Filling MAC SDU for Padding bytes*/
1634 if(byteIdx < pduInfo->pdu_length)
1637 MAC subheader format is R/R/LCId (1byte)
1638 LCId is 63 for padding
1639 From 38.321 section 6.1.1
1641 pdu[byteIdx++] = 63;
1643 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1646 msgLen += pduInfo->pdu_length;
1648 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1650 /* Send Message to peer */
1651 DU_LOG("\nDEBUG --> PHY STUB : Sending RLC status pdu at sfn %d slot %d", sfnValue, slotValue);
1652 /* Sending Rx data indication to MAC */
1653 rxDataInd->sfn = sfnValue;
1654 rxDataInd->slot = slotValue;
1655 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1657 if(pduInfo->pdu_length)
1658 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1659 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1663 /*******************************************************************
1665 * @brief Receives message from MAC
1669 * Function : l1ProcessFapiRequest
1672 * - Receives message from MAC and calls handler
1674 * @params[in] Message type
1680 * ****************************************************************/
1682 void l1ProcessFapiRequest(uint8_t msgType, uint32_t msgLen, void *msg)
1687 case FAPI_PARAM_REQUEST:
1688 l1HdlParamReq(msgLen, msg);
1690 case FAPI_CONFIG_REQUEST:
1691 l1HdlConfigReq(msgLen, msg);
1693 case FAPI_START_REQUEST:
1694 l1HdlStartReq(msgLen, msg);
1696 case FAPI_DL_TTI_REQUEST:
1697 l1HdlDlTtiReq(msgLen, msg);
1699 case FAPI_TX_DATA_REQUEST:
1700 l1HdlTxDataReq(msgLen, msg);
1702 case FAPI_UL_TTI_REQUEST:
1703 l1HdlUlTtiReq(msgLen, msg);
1705 case FAPI_STOP_REQUEST:
1706 l1HdlStopReq(msgLen, msg);
1708 case FAPI_UL_DCI_REQUEST:
1709 l1HdlUlDciReq(msgLen, msg);
1712 DU_LOG("\nERROR --> PHY_STUB: Invalid message type[%x] received at PHY", msgType);
1719 /*******************************************************************
1721 * @brief Builds and Send the BSR message to MAC
1725 * Function : l1BuildAndSendBSR
1728 * -Send the BSR Message to MAC
1730 * @params[in] BSR type
1731 * array of LCGID and BSIdx
1734 *****************************************************************/
1735 uint16_t l1BuildAndSendBSR(uint8_t ueIdx, BsrType bsrType,\
1736 LcgBufferSize lcgBsIdx[MAX_NUM_LOGICAL_CHANNEL_GROUPS])
1738 fapi_rx_data_indication_t *rxDataInd;
1739 fapi_pdu_ind_info_t *pduInfo;
1740 uint8_t *pdu = NULLP;
1741 uint16_t byteIdx = 0;
1742 uint32_t msgLen = 0;
1743 uint8_t pduIdx = 0, lcgIdx = 0, lcgIdxPos = 0;
1745 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1748 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1751 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1753 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1755 rxDataInd->slot = 0;
1756 rxDataInd->numPdus = 1;
1758 pduInfo = &rxDataInd->pdus[pduIdx];
1759 pduInfo->handle = (ODU_START_CRNTI + ueIdx);
1760 pduInfo->rnti = (ODU_START_CRNTI + ueIdx);
1761 pduInfo->harqId = 1;
1763 /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1764 * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1765 pduInfo->pdu_length = 24;
1766 pduInfo->ul_cqi = 0;
1767 pduInfo->timingAdvance = 0;
1770 /* Filling pdu with random values for testing */
1771 pduInfo->pduData = NULL;
1772 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1773 if(!pduInfo->pduData)
1775 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1776 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1781 pdu = (uint8_t *)pduInfo->pduData;
1787 DU_LOG("\nDEBUG --> PHY_STUB: Forming SHORT BSR PDU ");
1790 * MAC subheader format is R/R/LcId (1Byte)
1792 * From 38.321 section 6.1.1
1794 pdu[byteIdx++] = 61; // LCID
1795 pdu[byteIdx++] = (lcgBsIdx[0].lcgId << 5) | lcgBsIdx[0].bsIdx;
1801 DU_LOG("\nDEBUG --> PHY_STUB: Forming LONG BSR PDU ");
1804 * MAC subheader format is R/R/LcId (1Byte)
1806 * From 38.321 section 6.1.1
1808 pdu[byteIdx++] = 62; // LCID
1810 /*Octet where lcgId bitmap will be present*/
1811 lcgIdxPos = byteIdx;
1813 for(lcgIdx = 0; lcgIdx < MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
1815 if(lcgBsIdx[lcgIdx].bsIdx > 0)
1817 pdu[lcgIdxPos] |= 1 << lcgBsIdx[lcgIdx].lcgId;
1818 pdu[byteIdx++] = lcgBsIdx[lcgIdx].bsIdx;
1827 DU_LOG("\nERROR --> PHY_STUB: Incorrect BSR type:%d!", bsrType);
1828 if(pduInfo->pdu_length)
1829 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1830 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1834 /* Filling MAC SDU for Padding bytes*/
1835 if(byteIdx < pduInfo->pdu_length)
1838 * MAC subheader format is R/R/LCId (1byte)
1839 * LCId is 63 for padding
1840 * From 38.321 section 6.1.1
1842 pdu[byteIdx++] = 63;
1844 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1847 msgLen += pduInfo->pdu_length;
1848 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1850 /* Sending Rx data indication to MAC */
1851 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
1852 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1854 if(pduInfo->pdu_length)
1855 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1856 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1861 /**********************************************************************
1863 **********************************************************************/