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 /* In CF-RA in case of handover, RRC Reconfiguration Complete is sent
391 * by UE once RAR is received from DU */
392 phyDb.ueDb.ueCb[ueId-1].ueId = ueId;
393 phyDb.ueDb.ueCb[ueId-1].crnti = puschPdu.rnti;
394 phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp = true;
395 type = MSG_TYPE_RRC_RECONFIG_COMPLETE;
399 if(!phyDb.ueDb.ueCb[ueId-1].msg3Sent)
401 phyDb.ueDb.ueCb[ueId-1].ueId = ueId;
402 phyDb.ueDb.ueCb[ueId-1].crnti = puschPdu.rnti;
403 phyDb.ueDb.ueCb[ueId-1].msg3Sent = true;
404 type = MSG_TYPE_MSG3;
407 else if(!phyDb.ueDb.ueCb[ueId-1].msg5ShortBsrSent)
409 phyDb.ueDb.ueCb[ueId-1].msg5ShortBsrSent = true;
410 type = MSG_TYPE_SHORT_BSR;
412 else if(!phyDb.ueDb.ueCb[ueId-1].msg5Sent)
414 phyDb.ueDb.ueCb[ueId-1].msg5Sent = true;
415 type = MSG_TYPE_MSG5;
417 else if(!phyDb.ueDb.ueCb[ueId-1].msgSecurityModeComp)
419 phyDb.ueDb.ueCb[ueId-1].msgSecurityModeComp = true;
420 type = MSG_TYPE_SECURITY_MODE_COMPLETE;
422 else if(!phyDb.ueDb.ueCb[ueId-1].msgRegistrationComp)
424 phyDb.ueDb.ueCb[ueId-1].msgRegistrationComp = true;
425 type = MSG_TYPE_REGISTRATION_COMPLETE;
427 else if(!phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp)
429 phyDb.ueDb.ueCb[ueId-1].msgRrcReconfigComp = true;
430 type = MSG_TYPE_RRC_RECONFIG_COMPLETE;
436 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
439 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
442 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
444 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
445 rxDataInd->sfn = sfn;
446 rxDataInd->slot = slot;
447 rxDataInd->numPdus = 1;
449 pduInfo = &rxDataInd->pdus[idx];
450 pduInfo->handle = puschPdu.handle;
451 pduInfo->rnti = puschPdu.rnti;
452 pduInfo->harqId = puschPdu.puschData.harqProcessId;
453 pduInfo->pdu_length = puschPdu.puschData.tbSize ;
455 pduInfo->timingAdvance = 0;
458 /* Filling pdu with random values for testing */
459 pduInfo->pduData = NULL;
460 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
461 if(!pduInfo->pduData)
463 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
466 memset(pduInfo->pduData, 0, pduInfo->pdu_length);
468 pdu = (uint8_t *)pduInfo->pduData;
474 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG3 PDU ");
475 /* For Initial RRC setup Request,
476 MAC subheader format is R/R/LCId (1byte)
478 From 38.321 section 6.1.1
481 /* Hardcoding MAC PDU */
487 pdu[byteIdx++] = 103;
491 case MSG_TYPE_SHORT_BSR:
493 DU_LOG("\nDEBUG --> PHY_STUB: Forming SHORT BSR PDU ");
495 uint8_t bufferSizeIdx = 6;
498 MAC subheader format is R/R/LcId (1Byte)
500 From 38.321 section 6.1.1
502 pdu[byteIdx++] = 61; // LCID
503 pdu[byteIdx++] = (lcgId << 5) | bufferSizeIdx;
510 /* For RRC setup complete
512 * MAC subheader format is R/F/LCId/L (2/3 bytes)
514 * L is length of PDU i.e 6bytes here
515 * From 38.321 section 6.1.1
517 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
518 * From 38.322, section 6.2.2.4
520 DU_LOG("\nDEBUG --> PHY_STUB: Forming MSG5 PDU");
521 uint8_t msg5PduLen = 33; /* Length of MSG5 */
522 msg5PduLen += 2; /* RLC subheader */
523 uint8_t msg5[] = {1, msg5PduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 16, 0, \
524 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};
526 msg5PduLen += 2; /* 2 bytes of MAC header */
527 memcpy(pdu, &msg5, msg5PduLen);
528 byteIdx += msg5PduLen; /* 4 bytes of header : MAC+RLC */
532 case MSG_TYPE_SECURITY_MODE_COMPLETE:
534 /* For security mode complete where RRC Container is dummy
536 * MAC subheader format is R/F/LCId/L (2/3 bytes)
538 * L is length of PDU i.e 6bytes here
539 * From 38.321 section 6.1.1
541 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
542 * From 38.322, section 6.2.2.4
544 DU_LOG("\nDEBUG --> PHY_STUB: Forming SECURITY MODE COMPLETE PDU");
545 uint8_t pduLen = 12; /* Length of PDU */
546 pduLen += 2; /* RLC subheader */
547 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 0x2a, 0x40, \
548 0, 0, 0, 0, 0, 0, 0, 0};
550 pduLen += 2; /* 2 bytes of MAC header */
551 memcpy(pdu, &msg, pduLen);
552 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
556 case MSG_TYPE_REGISTRATION_COMPLETE:
558 /* For rrc reconfig complete where RRC Container is dummy
560 * MAC subheader format is R/F/LCId/L (2/3 bytes)
562 * L is length of PDU i.e 6bytes here
563 * From 38.321 section 6.1.1
565 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
566 * From 38.322, section 6.2.2.4
568 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC REGISTRATION COMPLETE PDU");
569 uint8_t pduLen = 12; /* Length of PDU */
570 pduLen += 2; /* RLC subheader */
571 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 0x3a, 0x81, \
572 0xbf, 0, 0x21, 0x80, 0, 0, 0, 0};
574 pduLen += 2; /* 2 bytes of MAC header */
575 memcpy(pdu, &msg, pduLen);
576 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC */
580 case MSG_TYPE_RRC_RECONFIG_COMPLETE:
582 /* For rrc reconfig complete where RRC Container is dummy
584 * MAC subheader format is R/F/LCId/L (2/3 bytes)
586 * L is length of PDU i.e 6bytes here
587 * From 38.321 section 6.1.1
589 * RLC subheader for AM PDU is D/C/P/SI/SN (2 bytes for 12-bit SN)
590 * From 38.322, section 6.2.2.4
592 DU_LOG("\nDEBUG --> PHY_STUB: Forming RRC RECONFIGURATION COMPLETE PDU");
593 uint8_t pduLen = 13; /* PDU length */
594 pduLen += 2; /* RLC sub header */
595 uint8_t msg[] = {1, pduLen, 128, phyDb.ueDb.ueCb[ueId-1].rlcSnForSrb1++, 0, phyDb.ueDb.ueCb[ueId-1].pdcpSn++, 8, 64, 0, 0,\
596 0, 0, 0, 0, 0, 0, 0};
598 pduLen += 2; /* 2bytes of MAC header */
599 memcpy(pdu, &msg, pduLen);
600 byteIdx += pduLen; /* 4 bytes of header : MAC+RLC*/
607 } /* End of switch(type) */
609 /* Filling MAC SDU for Padding bytes*/
610 if(byteIdx < pduInfo->pdu_length)
613 MAC subheader format is R/R/LCId (1byte)
614 LCId is 63 for padding
615 From 38.321 section 6.1.1
619 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
622 msgLen += pduInfo->pdu_length;
624 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
626 /* Sending Rx data indication to MAC */
627 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
628 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
630 if(pduInfo->pdu_length)
631 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
632 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
637 /*******************************************************************
639 * @brief Builds and Sends RACH indication to MAC
643 * Function : l1BuildAndSendRachInd
646 * Builds and Sends RACH indication to MAC
648 * @params[in] SFN value
650 * @return ROK - success
653 * ****************************************************************/
654 uint16_t l1BuildAndSendRachInd(uint16_t slot, uint16_t sfn, uint8_t raPreambleIdx)
657 uint8_t rachPduIdx = 0;
658 uint8_t preamIdx = 0;
659 fapi_rach_pdu_t *rachPdu;
660 fapi_rach_indication_t *rachInd;
662 /* Building RACH indication */
663 MAC_ALLOC(rachInd, sizeof(fapi_rach_indication_t));
666 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rach Indication Message");
669 memset(rachInd, 0, sizeof(fapi_rach_indication_t));
671 rachInd->slot = slot;
672 rachInd->numPdus = 1;
674 rachPdu = &rachInd->rachPdu[rachPduIdx];
675 rachPdu->phyCellId = NR_PCI;
676 rachPdu->symbolIndex = 0;
677 rachPdu->slotIndex = slot;
678 rachPdu->freqIndex = 0;
679 rachPdu->avgRssi = 0;
681 rachPdu->numPreamble = 1;
683 rachPdu->preambleInfo[preamIdx].preambleIndex = raPreambleIdx;
684 rachPdu->preambleInfo[preamIdx].timingAdvance = 0;
685 rachPdu->preambleInfo[preamIdx].preamblePwr = 0;
687 fillMsgHeader(&rachInd->header, FAPI_RACH_INDICATION, \
688 sizeof(fapi_rach_indication_t) - sizeof(fapi_msg_t));
690 /* Sending RACH indication to MAC */
691 DU_LOG("\nINFO --> PHY STUB: Sending RACH Indication to MAC");
692 procPhyMessages(rachInd->header.msg_id, sizeof(fapi_rach_indication_t), (void *)rachInd);
693 MAC_FREE(rachInd, sizeof(fapi_rach_indication_t));
698 /*******************************************************************
700 * @brief Builds and Send the Slot Indication message to MAC
704 * Function : l1BuildAndSendSlotIndication
707 * -Send the Slot indication Message to MAC
709 * @params[in] Message length
710 * config request message pointer
714 * ****************************************************************/
715 uint16_t l1BuildAndSendSlotIndication()
721 fapi_slot_ind_t *slotIndMsg;
723 MAC_ALLOC_SHRABL_BUF(slotIndMsg, sizeof(fapi_slot_ind_t));
726 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for slot Indication Message");
731 memset(slotIndMsg, 0, sizeof(fapi_slot_ind_t));
732 slotIndMsg->sfn = sfnValue;
733 slotIndMsg->slot = slotValue;
735 #ifdef ODU_SLOT_IND_DEBUG_LOG
736 DU_LOG("\n\nDEBUG --> PHY_STUB: Sending Slot Indication [%d : %d] to MAC", sfnValue, slotValue);
739 /* increment for the next TTI */
741 if(sfnValue >= MAX_SFN_VALUE && slotValue > MAX_SLOT_VALUE)
746 else if(slotValue > MAX_SLOT_VALUE)
751 fillMsgHeader(&slotIndMsg->header, FAPI_SLOT_INDICATION, \
752 sizeof(fapi_slot_ind_t) - sizeof(fapi_msg_t));
754 memset(&pst, 0, sizeof(Pst));
755 FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_SLOT_IND);
756 ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
759 DU_LOG("\nERROR --> PHY_STUB: Failed to allocate memory for slot indication buffer");
760 MAC_FREE_SHRABL_BUF(pst.region, pst.pool, slotIndMsg, sizeof(fapi_slot_ind_t));
763 CMCHKPK(oduPackPointer, (PTR)slotIndMsg, mBuf);
764 ODU_POST_TASK(&pst, mBuf);
770 /*******************************************************************
772 * @brief Handles start request received from MAC
776 * Function : l1HdlStartReq
779 * -Handles start request received from MAC
781 * @params[in] Message length
782 * config request message pointer
786 * ****************************************************************/
788 S16 l1HdlStartReq(uint32_t msgLen, void *msg)
791 if(lwrMacCb.phyState == PHY_STATE_CONFIGURED)
793 l1HdlSlotIndicaion(FALSE);
794 l1StartConsoleHandler();
795 MAC_FREE(msg, msgLen);
799 DU_LOG("\nINFO --> PHY_STUB: Received Start Req in PHY State %d", lwrMacCb.phyState);
800 MAC_FREE(msg, msgLen);
807 /*******************************************************************
809 * @brief Handles Dl Tti request received from MAC
813 * Function : l1HdlDlTtiReq
816 * -Handles Dl Tti request received from MAC
818 * @params[in] Message length
819 * Dl Tti request message pointer
823 * ****************************************************************/
825 S16 l1HdlDlTtiReq(uint16_t msgLen, void *msg)
828 p_fapi_api_queue_elem_t dlTtiElem = (p_fapi_api_queue_elem_t)msg;
829 fapi_dl_tti_req_t *dlTtiReq = (fapi_dl_tti_req_t *)(dlTtiElem +1);
831 uint8_t pduCount = 0;
833 #ifdef ODU_SLOT_IND_DEBUG_LOG
834 if(dlTtiReq->nPdus == 0)
836 DU_LOG("\nDEBUG --> PHY_STUB: No PDU in DL TTI Request");
840 DU_LOG("\nDEBUG --> PHY STUB: DL TTI Request at sfn=%d slot=%d",dlTtiReq->sfn,dlTtiReq->slot);
844 for(pduCount=0; pduCount<dlTtiReq->nPdus; pduCount++)
846 if(dlTtiReq->pdus[pduCount].pduType == 3) //SSB_PDU_TYPE
848 DU_LOG("\nINFO --> PHY_STUB: SSB PDU");
850 else if(dlTtiReq->pdus[pduCount].pduType == 0)
852 DU_LOG("\nINFO --> PHY_STUB: PDCCH PDU");
854 else if(dlTtiReq->pdus[pduCount].pduType == 1)
856 DU_LOG("\nINFO --> PHY_STUB: PDSCH PDU");
860 /* Free FAPI message */
861 MAC_FREE(msg, msgLen);
866 /*******************************************************************
868 * @brief Handles tx_data request received from MAC
872 * Function : l1HdlTxDataReq
875 * -Handles tx_data request received from MAC
877 * @params[in] Message length
878 * tx_data request message pointer
882 * ****************************************************************/
884 S16 l1HdlTxDataReq(uint16_t msgLen, void *msg)
887 p_fapi_api_queue_elem_t txDataElem = (p_fapi_api_queue_elem_t)msg;
888 fapi_tx_data_req_t *txDataReq = (fapi_tx_data_req_t *)(txDataElem +1);
890 DU_LOG("\nINFO --> PHY STUB: TX DATA Request at sfn=%d slot=%d",txDataReq->sfn,txDataReq->slot);
894 DU_LOG("\nINFO --> PHY_STUB: TxDataPdu for DED MSG sent");
898 MAC_FREE(msg, msgLen);
904 /*******************************************************************
906 * @brief Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
910 * Function : fillPucchF0F1PduInfo
913 * Fills Uci Ind Pdu Info carried on Pucch Format 0/Format 1
915 * @params[in] fapi_uci_o_pucch_f0f1_t *
917 * @return ROK - success
920 * ****************************************************************/
921 uint8_t fillPucchF0F1PduInfo(fapi_uci_o_pucch_f0f1_t *pduInfo, fapi_ul_pucch_pdu_t pucchPdu)
924 static uint8_t ind=0;
925 uint8_t result[]={0,//msg4
926 0,//Security Mode Command
927 0,//Registration Accept
928 0,//RRC Reconfiguration
947 pduInfo->handle = pucchPdu.handle;
948 pduInfo->pduBitmap = 1; //hardcoded for SR
949 if (pucchPdu.bitLenHarq)
951 pduInfo->pduBitmap |= HARQ_PDU_BITMASK;
953 pduInfo->pucchFormat = pucchPdu.formatType;
955 pduInfo->rnti = pucchPdu.rnti;
956 pduInfo->timingAdvance = 0;
958 if(pduInfo->pduBitmap & SR_PDU_BITMASK)
960 if (result[ind%50] == 0)
962 pduInfo->srInfo.srIndication = SR_DETECTED;
963 pduInfo->srInfo.srConfidenceLevel = CONFDC_LEVEL_GOOD;
966 if(pduInfo->pduBitmap & HARQ_PDU_BITMASK)
968 pduInfo->harqInfo.numHarq++;
969 pduInfo->harqInfo.harqConfidenceLevel = CONFDC_LEVEL_GOOD;
970 for(idx = 0; idx < pduInfo->harqInfo.numHarq; idx++)
972 pduInfo->harqInfo.harqValue[idx] = result[ind%50];
974 /*TBD: To use harq ind with random number and percentage*/
975 //pduInfo->harqInfo.harqValue[idx] = (dlHqPassPer >= rand()%(100))?HARQ_PASS:HARQ_FAIL;
980 /*******************************************************************
982 * @brief Fills UCI Pdu Information
986 * Function : fillUciPduInfo
989 * Fills UCI Pdu Information
991 * @params[in] Pointer to uciPdu
993 * @return ROK - success
996 * ****************************************************************/
997 uint8_t fillUciPduInfo(fapi_uci_pdu_info_t *uciPdu, fapi_ul_pucch_pdu_t pucchPdu)
1001 /*TODO: The pduType is hardcoded here to support
1002 UCI Ind for PUCCH forat0/format1. This is to be
1003 modified when we get SR form UE */
1004 uciPdu->pduType = UCI_IND_PUCCH_F0F1;
1005 switch(uciPdu->pduType)
1009 case UCI_IND_PUCCH_F0F1:
1011 fapi_uci_o_pucch_f0f1_t *pduInfo = NULLP;
1013 pduInfo = &uciPdu->uci.uciPucchF0F1;
1014 ret = fillPucchF0F1PduInfo(pduInfo, pucchPdu);
1015 uciPdu->pduSize = sizeof(fapi_uci_o_pucch_f0f1_t);
1018 case UCI_IND_PUCCH_F2F3F4:
1021 DU_LOG("\nERROR --> PHY_STUB: Invalid Pdu Type %d", uciPdu->pduType);
1027 /*******************************************************************
1029 * @brief Build and send Uci indication
1033 * Function : l1BuildAndSendUciInd
1036 * Build and send Uci indication
1040 * @return ROK - success
1043 * ****************************************************************/
1044 uint8_t l1BuildAndSendUciInd(uint16_t slot, uint16_t sfn, fapi_ul_pucch_pdu_t pucchPdu)
1047 uint8_t nUciPdus = 0;
1049 uint32_t msgLen = 0;
1050 fapi_uci_indication_t *uciInd = NULLP;
1052 MAC_ALLOC(uciInd, sizeof(fapi_uci_indication_t));
1055 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for UCI Indication");
1058 memset(uciInd, 0, sizeof(fapi_uci_indication_t));
1060 uciInd->slot = slot;
1061 uciInd->numUcis = 1; //consdering the UCI Ind for SR
1062 nUciPdus = uciInd->numUcis;
1065 ret = fillUciPduInfo(&uciInd->uciPdu[uciIdx], pucchPdu);
1071 msgLen = sizeof(fapi_uci_indication_t)- sizeof(fapi_msg_t);
1072 fillMsgHeader(&uciInd->header, FAPI_UCI_INDICATION, msgLen);
1074 /* Sending UCI indication to MAC */
1075 DU_LOG("\nINFO --> PHY STUB: Sending UCI Indication to MAC");
1076 procPhyMessages(uciInd->header.msg_id, sizeof(fapi_uci_indication_t), (void *)uciInd);
1078 MAC_FREE(uciInd, sizeof(fapi_uci_indication_t));
1083 /*******************************************************************
1085 * @brief Handles Ul Tti request received from MAC
1089 * Function : l1HdlUlTtiReq
1092 * -Handles Ul Tti request received from MAC
1094 * @params[in] Message length
1095 * Ul Tti request message pointer
1099 * ****************************************************************/
1101 S16 l1HdlUlTtiReq(uint16_t msgLen, void *msg)
1104 p_fapi_api_queue_elem_t ulTtiElem = (p_fapi_api_queue_elem_t)msg;
1105 fapi_ul_tti_req_t *ulTtiReq = (fapi_ul_tti_req_t *)(ulTtiElem +1);
1106 uint8_t numPdus = ulTtiReq->nPdus;
1108 #ifdef ODU_SLOT_IND_DEBUG_LOG
1111 DU_LOG("\nINFO --> PHY STUB: No PDU received in UL TTI Req");
1115 DU_LOG("\nINFO --> PHY STUB: Received UL TTI Request");
1121 if(ulTtiReq->pdus[numPdus-1].pduType == 0)
1123 DU_LOG("\nINFO --> PHY STUB: PRACH PDU");
1125 if(ulTtiReq->pdus[numPdus-1].pduType == 1)
1127 DU_LOG("\nINFO --> PHY STUB: PUSCH PDU");
1128 if (ROK == l1BuildAndSendCrcInd(ulTtiReq->slot, ulTtiReq->sfn,ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu))
1130 l1BuildAndSendRxDataInd(ulTtiReq->slot, ulTtiReq->sfn, ulTtiReq->pdus[numPdus-1].pdu.pusch_pdu);
1133 if(ulTtiReq->pdus[numPdus-1].pduType == 2)
1135 DU_LOG("\nINFO --> PHY STUB: PUCCH PDU");
1137 fapi_ul_tti_req_t ulTtiSlotInd;
1138 memset(&ulTtiSlotInd, 0, sizeof(fapi_ul_tti_req_t));
1139 ulTtiSlotInd.slot = ulTtiReq->slot;
1140 ulTtiSlotInd.sfn = ulTtiReq->sfn;
1141 ADD_DELTA_TO_TIME(ulTtiSlotInd, ulTtiSlotInd, SLOT_DELAY);
1142 l1BuildAndSendUciInd(ulTtiSlotInd.slot, ulTtiSlotInd.sfn, ulTtiReq->pdus[numPdus-1].pdu.pucch_pdu);
1147 /* TODO: [SFN:SLOT] at which RACH Indication is sent should be calculated
1148 * based on PRACH cfg index */
1149 /* Send RACH Ind to L2 for first UE */
1150 if(phyDb.ueDb.ueCb[UE_IDX_0].rachIndSent == false && ulTtiReq->sfn == 16 && ulTtiReq->slot == 6)
1152 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1153 phyDb.ueDb.ueCb[UE_IDX_0].rachIndSent = true;
1154 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1155 phyDb.ueDb.numActvUe++;
1159 /* Send RACH Ind to L2 for second UE */
1160 if(phyDb.ueDb.ueCb[UE_IDX_1].rachIndSent == false && ulTtiReq->sfn == 304 && ulTtiReq->slot == 0)
1162 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1163 phyDb.ueDb.ueCb[UE_IDX_1].rachIndSent = true;
1164 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1165 phyDb.ueDb.numActvUe++;
1168 /* Send RACH Ind to L2 for third UE */
1169 if(phyDb.ueDb.ueCb[UE_IDX_2].rachIndSent == false && ulTtiReq->sfn == 526 && ulTtiReq->slot == 0)
1171 phyDb.ueDb.ueCb[UE_IDX_0].isCFRA = false;
1172 phyDb.ueDb.ueCb[UE_IDX_2].rachIndSent = true;
1173 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn, CB_RA_PREAMBLE_IDX);
1174 phyDb.ueDb.numActvUe++;
1177 MAC_FREE(msg, msgLen);
1182 /*******************************************************************
1184 * @brief Builds and Send the stop Indication message to MAC
1188 * Function : l1BuildAndSendStopInd
1191 * -Send the Stop indication Message to MAC
1196 * ****************************************************************/
1197 uint16_t l1BuildAndSendStopInd()
1201 Buffer *mBuf = NULLP;
1202 fapi_stop_ind_t *stopIndMsg = NULLP;
1203 uint32_t msgLen = 0;
1205 MAC_ALLOC_SHRABL_BUF(stopIndMsg, sizeof(fapi_stop_ind_t));
1208 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for stop Indication Message");
1213 fillMsgHeader(&stopIndMsg->header, FAPI_STOP_INDICATION, msgLen);
1214 DU_LOG("\n\nINFO --> PHY_STUB: Processing Stop indication to MAC");
1216 memset(&pst, 0, sizeof(Pst));
1217 FILL_PST_PHY_STUB_TO_LWR_MAC(pst, EVT_PHY_STUB_STOP_IND);
1218 ODU_GET_MSG_BUF(pst.region, pst.pool, &mBuf);
1221 DU_LOG("\nERROR --> PHY_STUB: Failed to allocate memory for slot indication buffer");
1222 MAC_FREE_SHRABL_BUF(pst.region, pst.pool, stopIndMsg, sizeof(fapi_stop_ind_t));
1225 CMCHKPK(oduPackPointer, (PTR)stopIndMsg, mBuf);
1226 ODU_POST_TASK(&pst, mBuf);
1232 /*******************************************************************
1234 * @brief Handles stop request received from MAC
1238 * Function : l1HdlStopReq
1241 * -Handles stop request received from MAC
1243 * @params[in] Message length
1244 * stop request message pointer
1248 * ****************************************************************/
1250 S16 l1HdlStopReq(uint32_t msgLen, void *msg)
1253 if(lwrMacCb.phyState == PHY_STATE_RUNNING)
1255 l1HdlSlotIndicaion(TRUE);
1257 /* Initialize all global variables */
1260 memset(&phyDb.ueDb, 0, sizeof(UeDb));
1262 DU_LOG("\nINFO --> PHY_STUB: Slot Indication is stopped successfully");
1263 MAC_FREE(msg, msgLen);
1267 DU_LOG("\nINFO --> PHY_STUB: Received Stop Req in PHY State %d", lwrMacCb.phyState);
1268 MAC_FREE(msg, msgLen);
1276 /*******************************************************************
1278 * @brief Build And Send Rx Data Ind for Msg5
1282 * Function : l1BuildAndSendMsg5
1284 * Functionality: Build And Send Rx Data Ind for Msg5
1288 * @return ROK - success
1291 * ****************************************************************/
1292 uint8_t l1BuildAndSendMsg5(uint16_t sfn, uint16_t slot)
1296 fapi_rx_data_indication_t *rxDataInd;
1297 fapi_pdu_ind_info_t *pduInfo;
1299 uint16_t byteIdx = 0;
1300 uint32_t msgLen = 0;
1302 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1305 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication for msg5");
1308 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1310 /* TODO: Fill the required values */
1311 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1312 rxDataInd->sfn = sfn;
1313 rxDataInd->slot = slot;
1314 rxDataInd->numPdus = 1;
1316 pduInfo = &rxDataInd->pdus[idx];
1317 pduInfo->handle = 100;
1318 pduInfo->rnti = 100;
1319 pduInfo->harqId = 1;
1320 pduInfo->pdu_length = 25;
1321 pduInfo->ul_cqi = 0;
1322 pduInfo->timingAdvance = 0;
1325 /* Filling pdu with random values for testing */
1326 pduInfo->pduData = NULL;
1327 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1328 if(!pduInfo->pduData)
1330 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1335 pdu = (uint8_t *)pduInfo->pduData;
1337 uint8_t msg5PduLen = 33;
1338 /* For RRC setup complete
1339 MAC subheader format is R/F/LCId/L (2/3 bytes)
1341 L is length of PDU i.e 6bytes here
1342 From 38.321 section 6.1.1
1344 uint8_t msg5[] = {1, msg5PduLen, 0, 0, 16, 0, 5, 223, 128, 16, 94, \
1345 64, 3, 64, 89, 61, 138, 64, 0, 0, 0, 4, 0, 0, 4, 68, 11, 128, \
1346 184, 56, 0, 0, 0, 0, 0};
1348 msg5PduLen += 2; /* 2bytes of header */
1349 memcpy(pdu, &msg5, msg5PduLen);
1350 byteIdx += msg5PduLen; /* 2 bytes of header */
1352 /* Filling MAC SDU for Padding bytes*/
1353 if(byteIdx < pduInfo->pdu_length)
1356 MAC subheader format is R/R/LCId (1byte)
1357 LCId is 63 for padding
1358 From 38.321 section 6.1.1
1360 pdu[byteIdx++] = 63;
1362 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1365 msgLen += pduInfo->pdu_length;
1367 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1369 /* Sending Rx data indication to MAC */
1370 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
1371 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1373 if(pduInfo->pdu_length)
1374 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1375 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1381 /*******************************************************************
1383 * @brief Handles Ul Dci request received from MAC
1387 * Function : l1HdlUlDciReq
1390 * -Handles Ul Dci request received from MAC
1392 * @params[in] Message length
1393 * Ul Dci request message pointer
1397 * ****************************************************************/
1399 S16 l1HdlUlDciReq(uint16_t msgLen, void *msg)
1402 p_fapi_api_queue_elem_t ulDciElem = (p_fapi_api_queue_elem_t)msg;
1403 fapi_ul_dci_req_t *ulDciReq = (fapi_ul_dci_req_t *)(ulDciElem +1);
1404 uint8_t numPdus = ulDciReq->numPdus;
1408 if(ulDciReq->pdus[numPdus-1].pduType == 0)
1410 DU_LOG("\nINFO --> PHY STUB: Received UL DCI Request for PDCCH PDU");
1411 //l1BuildAndSendMsg5(ulDciReq->sfn, ulDciReq->slot);
1417 MAC_FREE(msg, msgLen);
1422 /*******************************************************************
1424 * @brief Send UL user data to DU
1428 * Function : l1SendUlUserData
1430 * Functionality: Send UL user data to DU
1433 * @return ROK - success
1436 * ****************************************************************/
1437 uint8_t l1SendUlUserData(uint8_t drbId, uint8_t ueIdx)
1440 fapi_rx_data_indication_t *rxDataInd;
1441 fapi_pdu_ind_info_t *pduInfo;
1442 uint8_t *pdu = NULLP;
1443 uint16_t byteIdx = 0;
1444 uint32_t msgLen = 0;
1448 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1451 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1454 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1456 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1458 rxDataInd->slot = 0;
1459 rxDataInd->numPdus = 1;
1461 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1462 pduInfo = &rxDataInd->pdus[idx];
1463 pduInfo->handle = ueIdx + ODU_START_CRNTI;
1464 pduInfo->rnti = ueIdx + ODU_START_CRNTI;
1465 pduInfo->harqId = 1;
1466 /* Since user data size = 50bytes and 2 bytes of MAC header and 3 byte of RLC header,
1467 * setting tbsize = 56 from Table 5.1.3.2-1 spec 38.214 */
1468 pduInfo->pdu_length = 56;
1469 pduInfo->ul_cqi = 0;
1470 pduInfo->timingAdvance = 0;
1473 /* Filling pdu with random values for testing */
1474 pduInfo->pduData = NULL;
1475 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1476 if(!pduInfo->pduData)
1478 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1483 pdu = (uint8_t *)pduInfo->pduData;
1487 MAC subheader format is R/F/LCId/L (2/3 bytes)
1489 L is length of PDU i.e 50 bytes
1490 From 38.321 section 6.1.1
1491 From 38.322 section 6.2.2.4, 6.2.2.3 for AM, UM Header
1494 /* Below ulMsg supports 12bit SN for UM mode */
1496 lcId = MIN_DRB_LCID + drbId;
1497 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,
1498 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};
1499 msgLen += 2; /* 2bytes of header */
1500 memcpy(pdu, &ulMsg, msgLen);
1501 byteIdx += msgLen; /* 2 bytes of header */
1503 /* Filling MAC SDU for Padding bytes*/
1504 if(byteIdx < pduInfo->pdu_length)
1507 MAC subheader format is R/R/LCId (1byte)
1508 LCId is 63 for padding
1509 From 38.321 section 6.1.1
1511 pdu[byteIdx++] = 63;
1513 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1516 msgLen += pduInfo->pdu_length;
1518 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1520 /* Send Message to peer */
1521 while(cnt < NUM_UL_PACKETS)
1523 DU_LOG("\nDEBUG --> PHY STUB : Sending UL User Data[%d][LCID:%d] at sfn %d slot %d", cnt+1, lcId, sfnValue, slotValue);
1524 /* Sending Rx data indication to MAC */
1525 rxDataInd->sfn = sfnValue;
1526 rxDataInd->slot = slotValue;
1527 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1531 if(pduInfo->pdu_length)
1532 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1533 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1537 /*******************************************************************
1539 * @brief Sends RLC Status PDU to DU
1543 * Function : l1SendStatusPdu
1545 * Functionality: Send RLC Status PDU to DU
1548 * @return ROK - success
1551 * ****************************************************************/
1552 uint8_t l1SendStatusPdu()
1554 fapi_rx_data_indication_t *rxDataInd;
1555 fapi_pdu_ind_info_t *pduInfo;
1556 uint8_t *pdu = NULLP;
1557 uint16_t byteIdx = 0;
1558 uint32_t msgLen = 0;
1561 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1564 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1567 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1569 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1571 rxDataInd->slot = 0;
1572 rxDataInd->numPdus = 1;
1574 /* TODO : Fill pduInfo using PUSCH PDU. Currently hardcoding */
1575 pduInfo = &rxDataInd->pdus[idx];
1576 pduInfo->handle = 100;
1577 pduInfo->rnti = 100;
1578 pduInfo->harqId = 1;
1579 /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1580 * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1581 pduInfo->pdu_length = 24;
1582 pduInfo->ul_cqi = 0;
1583 pduInfo->timingAdvance = 0;
1586 /* Filling pdu with random values for testing */
1587 pduInfo->pduData = NULL;
1588 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1589 if(!pduInfo->pduData)
1591 printf("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1596 pdu = (uint8_t *)pduInfo->pduData;
1599 /* For RLC Status PDU
1600 * MAC subheader format is R/F/LCId/L (2/3 bytes)
1601 * LCId is 4 for DRB1
1602 * L is length of Status PDU i.e 3 bytes
1603 * From 38.321 section 6.1.1
1605 * RLC Status PDU format :
1606 * ---------------------------------
1607 * |D/C|CPT| ACK_SN |
1608 * ---------------------------------
1610 * ---------------------------------
1611 * |E1 | R | R | R | R | R | R | R |
1612 * ---------------------------------
1614 * Here, D/C bit = 0 for Control PDU
1615 * CPT bit = 0 since control pdu type is Status PDU
1616 * ACK_SN = 0 as of now, this can be changed based on the
1617 * scenario being tested
1618 * E1 = 0 because no NACK_SN, E1, E2 and E3 follows it
1619 * R = 0 i.e. reserved bits
1620 * From Spec 38.322 section 6.2.2.5
1622 uint8_t statusPdu[] = {4, msgLen, 0, 0, 0};
1623 msgLen += 2; /* 2bytes of header */
1624 memcpy(pdu, &statusPdu, msgLen);
1625 byteIdx += msgLen; /* 2 bytes of header */
1628 /* Filling MAC SDU for Padding bytes*/
1629 if(byteIdx < pduInfo->pdu_length)
1632 MAC subheader format is R/R/LCId (1byte)
1633 LCId is 63 for padding
1634 From 38.321 section 6.1.1
1636 pdu[byteIdx++] = 63;
1638 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1641 msgLen += pduInfo->pdu_length;
1643 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1645 /* Send Message to peer */
1646 DU_LOG("\nDEBUG --> PHY STUB : Sending RLC status pdu at sfn %d slot %d", sfnValue, slotValue);
1647 /* Sending Rx data indication to MAC */
1648 rxDataInd->sfn = sfnValue;
1649 rxDataInd->slot = slotValue;
1650 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1652 if(pduInfo->pdu_length)
1653 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1654 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1658 /*******************************************************************
1660 * @brief Receives message from MAC
1664 * Function : l1ProcessFapiRequest
1667 * - Receives message from MAC and calls handler
1669 * @params[in] Message type
1675 * ****************************************************************/
1677 void l1ProcessFapiRequest(uint8_t msgType, uint32_t msgLen, void *msg)
1682 case FAPI_PARAM_REQUEST:
1683 l1HdlParamReq(msgLen, msg);
1685 case FAPI_CONFIG_REQUEST:
1686 l1HdlConfigReq(msgLen, msg);
1688 case FAPI_START_REQUEST:
1689 l1HdlStartReq(msgLen, msg);
1691 case FAPI_DL_TTI_REQUEST:
1692 l1HdlDlTtiReq(msgLen, msg);
1694 case FAPI_TX_DATA_REQUEST:
1695 l1HdlTxDataReq(msgLen, msg);
1697 case FAPI_UL_TTI_REQUEST:
1698 l1HdlUlTtiReq(msgLen, msg);
1700 case FAPI_STOP_REQUEST:
1701 l1HdlStopReq(msgLen, msg);
1703 case FAPI_UL_DCI_REQUEST:
1704 l1HdlUlDciReq(msgLen, msg);
1707 DU_LOG("\nERROR --> PHY_STUB: Invalid message type[%x] received at PHY", msgType);
1714 /*******************************************************************
1716 * @brief Builds and Send the BSR message to MAC
1720 * Function : l1BuildAndSendBSR
1723 * -Send the BSR Message to MAC
1725 * @params[in] BSR type
1726 * array of LCGID and BSIdx
1729 *****************************************************************/
1730 uint16_t l1BuildAndSendBSR(uint8_t ueIdx, BsrType bsrType,\
1731 LcgBufferSize lcgBsIdx[MAX_NUM_LOGICAL_CHANNEL_GROUPS])
1733 fapi_rx_data_indication_t *rxDataInd;
1734 fapi_pdu_ind_info_t *pduInfo;
1735 uint8_t *pdu = NULLP;
1736 uint16_t byteIdx = 0;
1737 uint32_t msgLen = 0;
1738 uint8_t pduIdx = 0, lcgIdx = 0, lcgIdxPos = 0;
1740 MAC_ALLOC(rxDataInd, sizeof(fapi_rx_data_indication_t));
1743 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Indication");
1746 memset(rxDataInd, 0, sizeof(fapi_rx_data_indication_t));
1748 msgLen = sizeof(fapi_rx_data_indication_t) - sizeof(fapi_msg_t);
1750 rxDataInd->slot = 0;
1751 rxDataInd->numPdus = 1;
1753 pduInfo = &rxDataInd->pdus[pduIdx];
1754 pduInfo->handle = (ODU_START_CRNTI + ueIdx);
1755 pduInfo->rnti = (ODU_START_CRNTI + ueIdx);
1756 pduInfo->harqId = 1;
1758 /* Since status pdu size = 3bytes and 2 bytes of MAC header,
1759 * setting tbsize = 24 from Table 5.1.3.2-1 spec 38.214 */
1760 pduInfo->pdu_length = 24;
1761 pduInfo->ul_cqi = 0;
1762 pduInfo->timingAdvance = 0;
1765 /* Filling pdu with random values for testing */
1766 pduInfo->pduData = NULL;
1767 MAC_ALLOC(pduInfo->pduData, pduInfo->pdu_length);
1768 if(!pduInfo->pduData)
1770 DU_LOG("\nERROR --> PHY_STUB: Memory allocation failed for Rx Data Pdu");
1771 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1776 pdu = (uint8_t *)pduInfo->pduData;
1782 DU_LOG("\nDEBUG --> PHY_STUB: Forming SHORT BSR PDU ");
1785 * MAC subheader format is R/R/LcId (1Byte)
1787 * From 38.321 section 6.1.1
1789 pdu[byteIdx++] = 61; // LCID
1790 pdu[byteIdx++] = (lcgBsIdx[0].lcgId << 5) | lcgBsIdx[0].bsIdx;
1796 DU_LOG("\nDEBUG --> PHY_STUB: Forming LONG BSR PDU ");
1799 * MAC subheader format is R/R/LcId (1Byte)
1801 * From 38.321 section 6.1.1
1803 pdu[byteIdx++] = 62; // LCID
1805 /*Octet where lcgId bitmap will be present*/
1806 lcgIdxPos = byteIdx;
1808 for(lcgIdx = 0; lcgIdx < MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
1810 if(lcgBsIdx[lcgIdx].bsIdx > 0)
1812 pdu[lcgIdxPos] |= 1 << lcgBsIdx[lcgIdx].lcgId;
1813 pdu[byteIdx++] = lcgBsIdx[lcgIdx].bsIdx;
1822 DU_LOG("\nERROR --> PHY_STUB: Incorrect BSR type:%d!", bsrType);
1823 if(pduInfo->pdu_length)
1824 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1825 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1829 /* Filling MAC SDU for Padding bytes*/
1830 if(byteIdx < pduInfo->pdu_length)
1833 * MAC subheader format is R/R/LCId (1byte)
1834 * LCId is 63 for padding
1835 * From 38.321 section 6.1.1
1837 pdu[byteIdx++] = 63;
1839 for(; byteIdx < pduInfo->pdu_length; byteIdx++)
1842 msgLen += pduInfo->pdu_length;
1843 fillMsgHeader(&rxDataInd->header, FAPI_RX_DATA_INDICATION, msgLen);
1845 /* Sending Rx data indication to MAC */
1846 DU_LOG("\nINFO --> PHY STUB: Sending Rx data Indication to MAC");
1847 procPhyMessages(rxDataInd->header.msg_id, sizeof(fapi_rx_data_indication_t), (void *)rxDataInd);
1849 if(pduInfo->pdu_length)
1850 MAC_FREE(pduInfo->pduData, pduInfo->pdu_length);
1851 MAC_FREE(rxDataInd, sizeof(fapi_rx_data_indication_t));
1856 /**********************************************************************
1858 **********************************************************************/