From 23396cca00097ffd3f1fab0d221155acba1f9124 Mon Sep 17 00:00:00 2001 From: pborla Date: Thu, 8 Aug 2024 00:58:08 +0530 Subject: [PATCH] [Epic-Id: ODUHIGH-618][Issue-Id: ODUHIGH-620] Implementation of socket connection b/w fapi decoder and lwr_mac Change-Id: I5cdb9af52cc4fec2f6c1c133c3d57ccc76b09e40 Signed-off-by: pborla --- build/odu/makefile | 2 +- src/5gnrmac/lwr_mac_phy.c | 236 ++++++++++++++++++++++++++++++++++++++++++- tools/Fapi_Decoder/decoder.c | 173 +++++++++++++++++++++++++++++++ 3 files changed, 409 insertions(+), 2 deletions(-) create mode 100644 tools/Fapi_Decoder/decoder.c diff --git a/build/odu/makefile b/build/odu/makefile index d932b88c5..a230fb2cf 100644 --- a/build/odu/makefile +++ b/build/odu/makefile @@ -74,7 +74,7 @@ endif # macro for output file name and makefile name # -PLTFRM_FLAGS=-UMSPD -DODU -DINTEL_FAPI -UODU_MEMORY_DEBUG_LOG -DDEBUG_ASN_PRINT -UDEBUG_PRINT -DERROR_PRINT -USTART_DL_UL_DATA -UNR_DRX -UCALL_FLOW_DEBUG_LOG -UODU_SLOT_IND_DEBUG_LOG -UNFAPI_ENABLED -UTHREAD_AFFINITY -UMEM_SIZE_CHECK +PLTFRM_FLAGS=-UMSPD -DODU -DINTEL_FAPI -UODU_MEMORY_DEBUG_LOG -DDEBUG_ASN_PRINT -UDEBUG_PRINT -DERROR_PRINT -USTART_DL_UL_DATA -UNR_DRX -UCALL_FLOW_DEBUG_LOG -UODU_SLOT_IND_DEBUG_LOG -UNFAPI_ENABLED -UTHREAD_AFFINITY -UMEM_SIZE_CHECK -DFAPI_DECODER ifeq ($(MODE),TDD) PLTFRM_FLAGS += -DNR_TDD diff --git a/src/5gnrmac/lwr_mac_phy.c b/src/5gnrmac/lwr_mac_phy.c index a9bf88d3c..1b1cd49f6 100644 --- a/src/5gnrmac/lwr_mac_phy.c +++ b/src/5gnrmac/lwr_mac_phy.c @@ -45,6 +45,237 @@ CmLListCp wlsBlockToFreeList[WLS_MEM_FREE_PRD]; uint8_t rgClHndlCfgReq ARGS((void *msg)); void l1ProcessFapiRequest ARGS((uint8_t msgType, uint32_t msgLen, void *msg)); +#ifdef FAPI_DECODER +int sockfd=0; + +/******************************************************************* + * + * @brief copy the fapi msg in a buffer and send it to fapi decoder + * + * @details + * + * Function : processFapiMsg + * + * Functionality: + * copy the fapi msg in a buffer and send it to fapi decoder + * + * @params[in] p_fapi_api_queue_elem_t msg + * @return ROK/RFAILED + * + * ****************************************************************/ + +uint8_t processFapiMsg(p_fapi_api_queue_elem_t msg) +{ + uint8_t *buffer=NULLP; + uint16_t buffer_size=0; + switch (msg->msg_type) + { + case FAPI_PARAM_REQUEST: + { + buffer_size = sizeof(fapi_param_req_t); + LWR_MAC_ALLOC(buffer,buffer_size); + if(buffer == NULLP) + { + DU_LOG("\nERROR --> LWR MAC : Failed to allocate memory"); + return RFAILED; + } + fapi_param_req_t *paramReq = (fapi_param_req_t *)(msg+1); + memcpy(buffer, paramReq, sizeof(fapi_param_req_t)); + } + break; + case FAPI_CONFIG_REQUEST: + { + buffer_size = sizeof(fapi_config_req_t); + LWR_MAC_ALLOC(buffer,buffer_size); + if(buffer == NULLP) + { + DU_LOG("\nERROR --> LWR MAC : Failed to allocate memory"); + return RFAILED; + } + fapi_config_req_t *configReq = (fapi_config_req_t *)(msg+1); + memcpy(buffer, configReq, sizeof(fapi_config_req_t)); + } + break; + case FAPI_START_REQUEST: + { + buffer_size = sizeof(fapi_start_req_t); + LWR_MAC_ALLOC(buffer,buffer_size); + if(buffer == NULLP) + { + DU_LOG("\nERROR --> LWR MAC : Failed to allocate memory"); + return RFAILED; + } + fapi_start_req_t *startReq = (fapi_start_req_t *)(msg+1); + memcpy(buffer, startReq, sizeof(fapi_start_req_t)); + } + break; + case FAPI_DL_TTI_REQUEST: + { + buffer_size = sizeof(fapi_dl_tti_req_t); + LWR_MAC_ALLOC(buffer,buffer_size); + if(buffer == NULLP) + { + DU_LOG("\nERROR --> LWR MAC : Failed to allocate memory"); + return RFAILED; + } + fapi_dl_tti_req_t *dlTtiReq = (fapi_dl_tti_req_t *)(msg+1); + memcpy(buffer, dlTtiReq, sizeof(fapi_dl_tti_req_t)); + } + break; + case FAPI_TX_DATA_REQUEST: + { + buffer_size = sizeof(fapi_tx_data_req_t); + LWR_MAC_ALLOC(buffer,buffer_size); + if(buffer == NULLP) + { + DU_LOG("\nERROR --> LWR MAC : Failed to allocate memory"); + return RFAILED; + } + fapi_tx_data_req_t *txDataReq = (fapi_tx_data_req_t *)(msg+1); + memcpy(buffer, txDataReq, sizeof(fapi_tx_data_req_t)); + } + break; + case FAPI_STOP_REQUEST: + { + buffer_size = sizeof(fapi_stop_req_t); + LWR_MAC_ALLOC(buffer,buffer_size); + if(buffer == NULLP) + { + DU_LOG("\nERROR --> LWR MAC : Failed to allocate memory"); + return RFAILED; + } + fapi_stop_req_t *stopReq = (fapi_stop_req_t *)(msg+1); + memcpy(buffer, stopReq, sizeof(fapi_stop_req_t)); + } + break; + case FAPI_UL_DCI_REQUEST: + { + buffer_size = sizeof(fapi_ul_dci_req_t); + LWR_MAC_ALLOC(buffer,buffer_size); + if(buffer == NULLP) + { + DU_LOG("\nERROR --> LWR MAC : Failed to allocate memory"); + return RFAILED; + } + fapi_ul_dci_req_t *ulDciReq = (fapi_ul_dci_req_t *)(msg+1); + memcpy(buffer, ulDciReq, sizeof(fapi_ul_dci_req_t)); + } + break; + case FAPI_UL_TTI_REQUEST: + { + buffer_size = sizeof(fapi_ul_tti_req_t); + LWR_MAC_ALLOC(buffer,buffer_size); + if(buffer == NULLP) + { + DU_LOG("\nERROR --> LWR MAC : Failed to allocate memory"); + return RFAILED; + } + fapi_ul_tti_req_t *ulTtiReq = (fapi_ul_tti_req_t *)(msg+1); + memcpy(buffer, ulTtiReq, sizeof(fapi_ul_tti_req_t)); + } + break; + default: + fprintf(stderr, "ERROR: Invalid message type[%d] received\n", msg->msg_type); + LWR_MAC_FREE(buffer,buffer_size); + return RFAILED; + } + + printf("Processed request of type %d, buffer size: %d\n", msg->msg_type, buffer_size); + + if (send(sockfd, buffer, buffer_size, 0) < 0) + { + perror("ERROR sending message"); + LWR_MAC_FREE(buffer,buffer_size); + return RFAILED; + } + LWR_MAC_FREE(buffer,buffer_size); + return ROK; +} + +/******************************************************************* + * + * @brief create socket and connect with fapi decoder + * + * @details + * + * Function : create_socket + * + * Functionality: + * create socket and connect with fapi decoder + * + * @params[in] server ip and port + * @return sockfd + * + * ****************************************************************/ + + +int create_socket(const char *server_ip, int port) +{ + struct sockaddr_in serv_addr; + + // Create socket + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if (sockfd < 0) { + perror("ERROR opening socket"); + return -1; + } + + // Set up the server address struct + bzero((char *)&serv_addr, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + serv_addr.sin_port = htons(port); + serv_addr.sin_addr.s_addr = inet_addr(server_ip); + + // Connect to server + if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { + perror("ERROR connecting"); + close(sockfd); + return -1; + } + + return sockfd; +} + +/******************************************************************* + * + * @brief Build and send fapi msg to fapi decoder + * + * @details + * + * Function : buildandsendfapimsgtofapidecoder + * + * Functionality: + * build and send fapi msg to fapi decoder + * + * @params[in] p_fapi_api_queue_elem_t msg + * @return ROK/RFAILED + * + * ****************************************************************/ + + +uint8_t buildandsendfapimsgtofapidecoder(p_fapi_api_queue_elem_t msg) +{ + // Create and connect socket + if(sockfd==0) + { + sockfd = create_socket("127.0.0.1", 8080); + if(sockfd<=0) + { + DU_LOG("\nERROR --> LWR MAC : Failed to establish connection"); + return RFAILED; + } + } + // Process the message (for demonstration purposes) + if(processFapiMsg(msg) != ROK) + { + DU_LOG("\nERROR --> LWR MAC : Failed to establish connection"); + return RFAILED; + } + + return ROK; +} +#endif + #ifdef INTEL_WLS_MEM /******************************************************************* @@ -385,7 +616,10 @@ uint8_t LwrMacSendToL1(void *msg) if((currMsg->msg_type != FAPI_VENDOR_MSG_HEADER_IND) && \ (currMsg->msg_type != FAPI_VENDOR_MESSAGE)) { - l1ProcessFapiRequest(currMsg->msg_type, msgLen, currMsg); +#ifdef FAPI_DECODER + buildandsendfapimsgtofapidecoder(currMsg); +#endif + l1ProcessFapiRequest(currMsg->msg_type, msgLen, currMsg); } else { diff --git a/tools/Fapi_Decoder/decoder.c b/tools/Fapi_Decoder/decoder.c new file mode 100644 index 000000000..428515c34 --- /dev/null +++ b/tools/Fapi_Decoder/decoder.c @@ -0,0 +1,173 @@ +#include +#include +#include +#include +#include +#include +#include +#include "../../src/intel_fapi/fapi_interface.h" +#include "../../src/intel_fapi/fapi_vendor_extension.h" +#include "../../src/intel_fapi/nfapi_interface.h" +#include "../../src/intel_fapi/nr5g_fapi_common_types.h" +#include "../../src/intel_fapi/nr5g_fapi_internal.h" +#include "fapi_interface.c" + +#define PORT 8080 + + + +uint8_t processFapiMsg(uint8_t *buffer, size_t buffer_size) +{ + if (buffer == NULL || buffer_size == 0) + { + fprintf(stderr, "ERROR: Invalid buffer or buffer size\n"); + return 0; + } + + if(buffer_size == sizeof(fapi_param_req_t)) + { + printf("\nPrinting fapi_param_req\n"); + fapi_param_req_t *paramReq = (fapi_param_req_t *)buffer; + decode_fapi_param_req(paramReq); + } + else if(buffer_size == sizeof(fapi_config_req_t)) + { + printf("\nPrinting fapi_config_req_t\n"); + fapi_config_req_t *configReq = (fapi_config_req_t *)buffer; + decode_fapi_config_req(configReq); + } + else if(buffer_size == sizeof(fapi_start_req_t)) + { + printf("\nPrinting fapi_start_req_t\n"); + fapi_start_req_t *startReq = (fapi_start_req_t *)buffer; + decode_fapi_start_req(startReq); + } + else if(buffer_size == sizeof(fapi_dl_tti_req_t)) + { + printf("\nPrinting fapi_dl_tti_req_t\n"); + fapi_dl_tti_req_t *dlTtiReq = (fapi_dl_tti_req_t *)buffer; + decode_fapi_dl_tti_req(dlTtiReq); + } + else if(buffer_size == sizeof(fapi_tx_data_req_t)) + { + printf("\nPrinting fapi_tx_data_req_t\n"); + fapi_tx_data_req_t *txDataReq = (fapi_tx_data_req_t *)buffer; + decode_fapi_tx_data_req(txDataReq); + } + else if(buffer_size == sizeof(fapi_stop_req_t)) + { + printf("\nPrinting fapi_stop_req_t\n"); + fapi_stop_req_t *stopReq = (fapi_stop_req_t *)buffer; + decode_fapi_stop_req(stopReq); + } + else if(buffer_size == sizeof(fapi_ul_dci_req_t)) + { + printf("\nPrinting fapi_ul_dci_req_t\n"); + fapi_ul_dci_req_t *ulDciReq = (fapi_ul_dci_req_t *)buffer; + decode_fapi_ul_dci_req(ulDciReq); + } + else if(buffer_size == sizeof(fapi_ul_tti_req_t)) + { + printf("\nPrinting fapi_ul_tti_req_t\n"); + fapi_ul_tti_req_t *ulTtiReq = (fapi_ul_tti_req_t *)buffer; + decode_fapi_ul_tti_req(ulTtiReq); + } + printf("\nPrinting fapi_config_req_t\n"); + printf("\nPrinting fapi_config_req_t\n"); + return 1; +} + +int create_server_socket(int port) { + int sockfd; + struct sockaddr_in serv_addr; + + // Create socket + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if (sockfd < 0) { + perror("ERROR opening socket"); + exit(1); + } + + // Set up the server address struct + bzero((char *)&serv_addr, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + serv_addr.sin_port = htons(port); + serv_addr.sin_addr.s_addr = INADDR_ANY; + + // Bind the socket to the address + if (bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { + perror("ERROR on binding"); + close(sockfd); + exit(1); + } + + // Listen for incoming connections + listen(sockfd, 5); + + return sockfd; +} + +int handle_client(int client_sockfd) +{ + uint8_t buffer[60000]; + ssize_t bytes_received; + size_t buffer_size; + + // Receive the message from the client + bytes_received = recv(client_sockfd, buffer, sizeof(buffer), 0); + if (bytes_received < 0) + { + perror("ERROR receiving message"); + return 0; + } + + // Set buffer_size to the number of bytes received + buffer_size = (size_t)bytes_received; + printf("\n################################ bytes_received %lu", bytes_received); + // Process the received message + if(processFapiMsg(buffer, bytes_received) == 0) + { + printf("failed to process"); + return 0; + } + return 1; +} + +int main() +{ + int server_sockfd, client_sockfd; + struct sockaddr_in cli_addr; + socklen_t cli_len = sizeof(cli_addr); + + // Create server socket + server_sockfd = create_server_socket(PORT); + + while (1) + { + // Accept an incoming connection + client_sockfd = accept(server_sockfd, (struct sockaddr *)&cli_addr, &cli_len); + if (client_sockfd < 0) { + perror("ERROR on accept"); + continue; + } + else + break; + } + + while(1) + { + printf("\n############################################################################################\n"); + // Handle the client connection + if(handle_client(client_sockfd) == 0) + { + printf("\nfailed to handle the recevied message\n"); + break; + } + printf("\n############################################################################################\n"); + } + // Close the server socket + close(client_sockfd); + close(server_sockfd); + return 0; +} + -- 2.16.6