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 */
31 #include "lwr_mac_phy.h"
35 #include "lphy_stub.h"
40 #define MAX_SLOT_VALUE 9
41 #define MAX_SFN_VALUE 1023
44 uint16_t sfnValue = 0;
45 uint16_t slotValue = 0;
46 bool rachIndSent = false;
48 EXTERN void phyToMac ARGS((uint16_t msgType, uint32_t msgLen,void *msg));
50 EXTERN void fillTlvs ARGS((fapi_uint16_tlv_t *tlv, uint16_t tag, uint16_t
51 length, uint16_t value, uint32_t *msgLen));
52 EXTERN void fillMsgHeader ARGS((fapi_msg_t *hdr, uint16_t msgType, uint16_t msgLen));
54 EXTERN void handlePhyMessages(uint16_t msgType, uint32_t msgSize, void *msg);
56 /*******************************************************************
58 * @brief Builds and sends param response to MAC CL
62 * Function : l1BldAndSndParamRsp
65 * - Builds and sends param response to MAC
67 * @params[in] Config request message pointer
68 * @return ROK - success
71 * ****************************************************************/
72 S16 l1BldAndSndParamRsp(void *msg)
77 fapi_param_resp_t *fapiParamRsp = (fapi_param_resp_t *)msg;
80 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_RELEASE_CAPABILITY_TAG, sizeof(uint16_t), 1, &msgLen);
81 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PHY_STATE_TAG, sizeof(uint16_t), 0, &msgLen);
82 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SKIP_BLANK_DL_CONFIG_TAG, sizeof(uint8_t), 0, &msgLen);
83 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SKIP_BLANK_UL_CONFIG_TAG, sizeof(uint8_t), 0, &msgLen);
84 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_NUM_CONFIG_TLVS_TO_REPORT_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
87 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CYCLIC_PREFIX_TAG, sizeof(uint8_t), 1, &msgLen);
88 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_SUBCARRIER_SPACING_DL_TAG, sizeof(uint8_t), 1, &msgLen);
89 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_BANDWIDTH_DL_TAG, sizeof(uint16_t), 1, &msgLen);
90 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_SUBCARRIER_SPACING_UL_TAG, sizeof(uint8_t), 0, &msgLen);
91 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_BANDWIDTH_UL_TAG, sizeof(uint16_t), 0, &msgLen);
94 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CCE_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
95 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_CORESET_OUTSIDE_FIRST_3_OFDM_SYMS_OF_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
96 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRECODER_GRANULARITY_CORESET_TAG, sizeof(uint8_t), 0, &msgLen);
97 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDCCH_MU_MIMO_TAG, sizeof(uint8_t), 0, &msgLen);
98 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDCCH_PRECODER_CYCLING_TAG, sizeof(uint8_t), 0, &msgLen);
99 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDCCHS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
102 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUCCH_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
103 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PUCCHS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
106 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
107 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_ALLOCATION_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
108 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_VRB_TO_PRB_MAPPING_TAG, sizeof(uint8_t), 0, &msgLen);
109 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_CBG_TAG, sizeof(uint8_t), 0, &msgLen);
110 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_CONFIG_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
111 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_MAX_LENGTH_TAG, sizeof(uint8_t), 0, &msgLen);
112 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DMRS_ADDITIONAL_POS_TAG, sizeof(uint8_t), 0, &msgLen);
113 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDSCHS_TBS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
114 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_NUMBER_MIMO_LAYERS_PDSCH_TAG, sizeof(uint8_t), 0, &msgLen);
115 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_MAX_MODULATION_ORDER_DL_TAG, sizeof(uint8_t), 0, &msgLen);
116 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_MU_MIMO_USERS_DL_TAG, sizeof(uint8_t), 0, &msgLen);
117 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_DATA_IN_DMRS_SYMBOLS_TAG, sizeof(uint8_t), 0, &msgLen);
118 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PREMPTIONSUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
119 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PDSCH_NON_SLOT_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
122 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_UCI_MUX_ULSCH_IN_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
123 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_UCI_ONLY_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
124 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_FREQUENCY_HOPPING_TAG, sizeof(uint8_t), 0, &msgLen);
125 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_CONFIG_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
126 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_MAX_LEN_TAG, sizeof(uint8_t), 0, &msgLen);
127 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_DMRS_ADDITIONAL_POS_TAG, sizeof(uint8_t), 0, &msgLen);
128 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_CBG_TAG, sizeof(uint8_t), 0, &msgLen);
129 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_MAPPING_TYPE_TAG, sizeof(uint8_t), 0, &msgLen);
130 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_ALLOCATION_TYPES_TAG, sizeof(uint8_t), 0, &msgLen);
131 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_VRB_TO_PRB_MAPPING_TAG, sizeof(uint8_t), 0, &msgLen);
132 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_MAX_PTRS_PORTS_TAG, sizeof(uint8_t), 0, &msgLen);
133 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PDUSCHS_TBS_PER_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
134 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_NUMBER_MIMO_LAYERS_NON_CB_PUSCH_TAG, sizeof(uint8_t), 0, &msgLen);
135 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_SUPPORTED_MODULATION_ORDER_UL_TAG, sizeof(uint8_t), 0, &msgLen);
136 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_MU_MIMO_USERS_UL_TAG, sizeof(uint8_t), 0, &msgLen);
137 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_DFTS_OFDM_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
138 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PUSCH_AGGREGATION_FACTOR_TAG, sizeof(uint8_t), 0, &msgLen);
141 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_LONG_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
142 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_SHORT_FORMATS_TAG, sizeof(uint8_t), 0, &msgLen);
143 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_PRACH_RESTRICTED_SETS_TAG, sizeof(uint8_t), 0, &msgLen);
144 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_MAX_PRACH_FD_OCCASIONS_IN_A_SLOT_TAG, sizeof(uint8_t), 0, &msgLen);
146 /* MEASUREMENT TAG */
147 fillTlvs(&fapiParamRsp->tlvs[index++], FAPI_RSSI_MEASUREMENT_SUPPORT_TAG, sizeof(uint8_t), 0, &msgLen);
149 fapiParamRsp->number_of_tlvs = index;
150 msgLen = msgLen + sizeof(fapi_param_resp_t);
152 fillMsgHeader(&fapiParamRsp->header, FAPI_PARAM_RESPONSE, msgLen);
153 fapiParamRsp->error_code = MSG_OK;
154 DU_LOG("\nPHY_STUB: Sending Param Request to Lower Mac");
155 handlePhyMessages(fapiParamRsp->header.message_type_id, sizeof(fapi_param_resp_t), (void *)fapiParamRsp);
160 /*******************************************************************
162 * @brief Builds and sends config response to lower mac
166 * Function : l1BldAndSndConfigRsp
169 * - Builds and sends config response to MAC
171 * @params[in] Config request message pointer
172 * @return ROK - success
175 * ****************************************************************/
177 S16 l1BldAndSndConfigRsp(void *msg)
181 fapi_config_resp_t *fapiConfigRsp = (fapi_config_resp_t *)msg;
183 if(fapiConfigRsp != NULL)
185 fapiConfigRsp->number_of_invalid_tlvs = NULLP;
186 fapiConfigRsp->number_of_inv_tlvs_idle_only = NULLP;
187 fapiConfigRsp->number_of_missing_tlvs = NULLP;
188 fapiConfigRsp->error_code = MSG_OK;
189 msgLen += sizeof(fapi_config_resp_t);
190 fillMsgHeader(&fapiConfigRsp->header, FAPI_CONFIG_RESPONSE, msgLen);
191 DU_LOG("\nPHY_STUB: Sending Config Response to Lower Mac");
192 handlePhyMessages(fapiConfigRsp->header.message_type_id, sizeof(fapi_config_resp_t), (void *)fapiConfigRsp);
199 /*******************************************************************
201 * @brief Handles param request received from MAC
205 * Function : l1HdlParamReq
208 * -Handles param request received from MAC
210 * @params[in] Message length
211 * Param request message pointer
215 * ****************************************************************/
217 PUBLIC void l1HdlParamReq(uint32_t msgLen, void *msg)
219 DU_LOG("\nPHY_STUB: Received Param Request in PHY");
220 /* Handling PARAM RESPONSE */
221 if(l1BldAndSndParamRsp(msg)!= ROK)
223 DU_LOG("\nPHY_STUB: Failed Sending Param Response");
227 /*******************************************************************
229 * @brief Handles config request received from MAC
233 * Function : l1HdlConfigReq
236 * -Handles config request received from MAC
238 * @params[in] Message length
239 * config request message pointer
243 * ****************************************************************/
245 PUBLIC void l1HdlConfigReq(uint32_t msgLen, void *msg)
247 DU_LOG("\nPHY_STUB: Received Config Request in PHY");
249 /* Handling CONFIG RESPONSE */
250 if(l1BldAndSndConfigRsp(msg)!= ROK)
252 printf("\nPHY_STUB: Failed Sending config Response");
257 /*******************************************************************
259 * @brief Builds and Sends RACH indication to MAC
263 * Function : l1BuildAndSendRachInd
266 * Builds and Sends RACH indication to MAC
268 * @params[in] SFN value
270 * @return ROK - success
273 * ****************************************************************/
274 uint16_t l1BuildAndSendRachInd(uint16_t slot, uint16_t sfn)
277 uint8_t rachPduIdx = 0;
278 uint8_t preamIdx = 0;
279 fapi_rach_pdu_t *rachPdu;
280 fapi_rach_indication_t *rachInd;
282 /* Building RACH indication */
283 if(SGetSBuf(0, 0, (Data **)&rachInd, sizeof(fapi_rach_indication_t)) != ROK)
285 printf("\nPHY_STUB: Memory allocation failed for Rach Indication Message");
290 rachInd->slot = slot;
291 rachInd->numPdus = 1;
293 rachPdu = &rachInd->rachPdu[rachPduIdx];
294 rachPdu->physCellId = NR_PCI;
295 rachPdu->symbolIndex = 0;
296 rachPdu->slotIndex = slot;
297 rachPdu->freqIndex = 0;
298 rachPdu->avgRssi = 0;
300 rachPdu->numPreamble = 1;
302 rachPdu->preambleInfo[preamIdx].preambleIndex = 3;
303 rachPdu->preambleInfo[preamIdx].timingAdvance = 0;
304 rachPdu->preambleInfo[preamIdx].premblePwr = 0;
306 fillMsgHeader(&rachInd->header, FAPI_RACH_INDICATION, \
307 sizeof(fapi_rach_indication_t));
309 /* Sending RACH indication to MAC */
310 DU_LOG("\nPHY STUB: Sending RACH Indication to MAC");
311 handlePhyMessages(rachInd->header.message_type_id, sizeof(fapi_rach_indication_t), (void *)rachInd);
312 SPutSBuf(0, 0, (Data *)rachInd, sizeof(fapi_rach_indication_t));
317 /*******************************************************************
319 * @brief Builds and Send the Slot Indication message to MAC
323 * Function : l1BuildAndSendSlotIndication
326 * -Send the Slot indication Message to MAC
328 * @params[in] Message length
329 * config request message pointer
333 * ****************************************************************/
334 PUBLIC uint16_t l1BuildAndSendSlotIndication()
337 fapi_slot_ind_t *slotIndMsg;
338 if(SGetSBuf(0, 0, (Data **)&slotIndMsg, sizeof(slotIndMsg)) != ROK)
340 DU_LOG("\nPHY_STUB: Memory allocation failed for slot Indication Message");
346 if(sfnValue > MAX_SFN_VALUE && slotValue > MAX_SLOT_VALUE)
351 else if(slotValue > MAX_SLOT_VALUE)
356 slotIndMsg->sfn = sfnValue;
357 slotIndMsg->slot = slotValue;
358 fillMsgHeader(&slotIndMsg->header, FAPI_SLOT_INDICATION, sizeof(fapi_slot_ind_t));
359 DU_LOG("\nPHY_STUB: [%d:%d] ",sfnValue,slotValue);
360 handlePhyMessages(slotIndMsg->header.message_type_id, sizeof(fapi_slot_ind_t), (void*)slotIndMsg);
361 SPutSBuf(0, 0, (Data *)slotIndMsg, sizeof(slotIndMsg));
367 /*******************************************************************
369 * @brief Handles start request received from MAC
373 * Function : l1HdlStartReq
376 * -Handles start request received from MAC
378 * @params[in] Message length
379 * config request message pointer
383 * ****************************************************************/
385 PUBLIC S16 l1HdlStartReq(uint32_t msgLen, void *msg)
387 if(clGlobalCp.phyState == PHY_STATE_CONFIGURED)
389 duStartSlotIndicaion();
391 SPutSBuf(0, 0, (Data *)msg, sizeof(fapi_start_req_t));
397 DU_LOG("\nPHY_STUB: Received Start Req in PHY State %d", clGlobalCp.phyState);
402 /*******************************************************************
404 * @brief Handles Dl Tti request received from MAC
408 * Function : l1HdlDlTtiReq
411 * -Handles Dl Tti request received from MAC
413 * @params[in] Message length
414 * Dl Tti request message pointer
418 * ****************************************************************/
420 PUBLIC S16 l1HdlDlTtiReq(uint16_t msgLen, void *msg)
423 fapi_dl_tti_req_t *dlTtiReq;
424 dlTtiReq = (fapi_dl_tti_req_t *)msg;
426 printf("\nPHY STUB: Received DL TTI Request");
428 printf("\nPHY_STUB: SFN %d", dlTtiReq->sfn);
429 printf("\nPHY_STUB: SLOT %d", dlTtiReq->slot);
430 printf("\nPHY_STUB: nPdus %d", dlTtiReq->nPdus);
431 printf("\nPHY_STUB: nGroup %d", dlTtiReq->nGroup);
432 /* Printing SSB CONFIGURED VALUES */
433 printf("\nPHY_STUB: physCellId %d", dlTtiReq->pdus->u.ssb_pdu.physCellId);
434 printf("\nPHY_STUB: betaPss %d", dlTtiReq->pdus->u.ssb_pdu.betaPss);
435 printf("\nPHY_STUB: ssbBlockIndex %d", dlTtiReq->pdus->u.ssb_pdu.ssbBlockIndex);
436 printf("\nPHY_STUB: ssbSubCarrierOffset %d", dlTtiReq->pdus->u.ssb_pdu.ssbSubCarrierOffset);
437 printf("\nPHY_STUB: ssbOffsetPointA %d", dlTtiReq->pdus->u.ssb_pdu.ssbOffsetPointA);
438 printf("\nPHY_STUB: bchPayloadFlag %d", dlTtiReq->pdus->u.ssb_pdu.bchPayloadFlag);
439 printf("\nPHY_STUB: bchPayload %x", dlTtiReq->pdus->u.ssb_pdu.bchPayload);
441 uint8_t numPdus = dlTtiReq->nPdus;
444 DU_LOG("\nPHY_STUB: No PDU in DL TTI Request");
448 if(dlTtiReq->pdus->pduType == 3) //SSB_PDU_TYPE
449 DU_LOG("\nPHY_STUB: SSB PDU");
450 else if(dlTtiReq->pdus->pduType == 0)
451 DU_LOG("\nPHY_STUB: SIB1 PDCCH PDU");
452 else if(dlTtiReq->pdus->pduType == 1)
453 DU_LOG("\nPHY_STUB: SIB1 PDSCH PDU");
457 MAC_FREE(dlTtiReq, sizeof(fapi_dl_tti_req_t));
462 /*******************************************************************
464 * @brief Handles Ul Tti request received from MAC
468 * Function : l1HdlUlTtiReq
471 * -Handles Ul Tti request received from MAC
473 * @params[in] Message length
474 * Ul Tti request message pointer
478 * ****************************************************************/
480 PUBLIC S16 l1HdlUlTtiReq(uint16_t msgLen, void *msg)
483 fapi_ul_tti_req_t *ulTtiReq;
485 DU_LOG("\nPHY STUB: Received UL TTI Request");
487 ulTtiReq = (fapi_ul_tti_req_t *)msg;
488 uint8_t numPdus = ulTtiReq->nPdus;
492 DU_LOG("\nPHY STUB: No PDU in UL TTI");
496 if(ulTtiReq->pdus->pduType == 0)
497 DU_LOG("\nPHY STUB: PRACH PDU");
500 if(rachIndSent == false && ulTtiReq->slot == 8)
503 l1BuildAndSendRachInd(ulTtiReq->slot, ulTtiReq->sfn);
506 MAC_FREE(ulTtiReq, sizeof(fapi_ul_tti_req_t));
511 /*******************************************************************
513 * @brief Receives message from MAC
517 * Function : l1ProcessFapiRequest
520 * - Receives message from MAC and calls handler
522 * @params[in] Message type
528 * ****************************************************************/
530 void l1ProcessFapiRequest(uint8_t msgType, uint32_t msgLen, void *msg)
535 case FAPI_PARAM_REQUEST:
536 l1HdlParamReq(msgLen, msg);
538 case FAPI_CONFIG_REQUEST:
539 l1HdlConfigReq(msgLen, msg);
541 case FAPI_START_REQUEST:
542 l1HdlStartReq(msgLen, msg);
544 case FAPI_DL_TTI_REQUEST:
545 l1HdlDlTtiReq(msgLen, msg);
547 case FAPI_UL_TTI_REQUEST:
548 l1HdlUlTtiReq(msgLen, msg);
551 DU_LOG("\nPHY_STUB: Invalid message type[%x] received at PHY", msgType);
556 /**********************************************************************
558 **********************************************************************/