diff --git a/CMakeLists.txt b/CMakeLists.txt index 4dc8c9ce7a..123d08c3bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -715,7 +715,11 @@ add_library(NFAPI_LIB ${NFAPI_SRC}) target_link_libraries(NFAPI_LIB PUBLIC nfapi_common) target_link_libraries(NFAPI_LIB PUBLIC nr_fapi_p5 nr_fapi_p7) -target_compile_definitions(NFAPI_LIB PRIVATE ENABLE_SOCKET) +if(OAI_WLS) + target_compile_definitions(NFAPI_LIB PRIVATE ENABLE_WLS) +else() + target_compile_definitions(NFAPI_LIB PRIVATE ENABLE_SOCKET) +endif() include_directories(${NFAPI_DIR}/nfapi/public_inc) include_directories(${NFAPI_DIR}/nfapi/inc) @@ -729,6 +733,9 @@ add_library(NFAPI_PNF_LIB ${NFAPI_PNF_SRC}) target_link_libraries(NFAPI_PNF_LIB PRIVATE asn1_lte_rrc_hdrs asn1_nr_rrc_hdrs) target_link_libraries(NFAPI_PNF_LIB PUBLIC nr_fapi_p7) +if(OAI_WLS) + target_compile_definitions(NFAPI_PNF_LIB PRIVATE ENABLE_WLS) +endif() include_directories(${NFAPI_DIR}/pnf/public_inc) include_directories(${NFAPI_DIR}/pnf/inc) @@ -756,7 +763,11 @@ set(NFAPI_USER_SRC ${NFAPI_USER_DIR}/gnb_ind_vars.c ) add_library(NFAPI_USER_LIB ${NFAPI_USER_SRC}) -target_compile_definitions(NFAPI_USER_LIB PRIVATE ENABLE_SOCKET) +if(OAI_WLS) + target_compile_definitions(NFAPI_USER_LIB PRIVATE ENABLE_WLS) +else() + target_compile_definitions(NFAPI_USER_LIB PRIVATE ENABLE_SOCKET) +endif() target_link_libraries(NFAPI_USER_LIB PRIVATE asn1_lte_rrc_hdrs asn1_nr_rrc_hdrs UTIL) target_link_libraries(NFAPI_USER_LIB PRIVATE nr_fapi_p7) if(OAI_AERIAL) @@ -1841,8 +1852,12 @@ target_link_libraries(nr-softmodem PRIVATE pthread m CONFIG_LIB rt sctp) target_link_libraries(nr-softmodem PRIVATE ${T_LIB}) target_link_libraries(nr-softmodem PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) target_link_libraries(nr-softmodem PRIVATE asn1_nr_rrc_hdrs asn1_lte_rrc_hdrs) - -target_link_libraries(nr-softmodem PUBLIC nfapi_socket_lib) +add_boolean_option(OAI_WLS OFF "Activate OAI's WLS driver" OFF) +if (OAI_WLS) + target_link_libraries(nr-softmodem PUBLIC wls_integration_lib) +else() + target_link_libraries(nr-softmodem PUBLIC nfapi_socket_lib) +endif() add_boolean_option(OAI_AERIAL OFF "Activate OAI's AERIAL driver" OFF) if (OAI_AERIAL) target_compile_definitions(nr-softmodem PUBLIC ENABLE_AERIAL) diff --git a/cmake_targets/build_oai b/cmake_targets/build_oai index 5e9bfaf444..cbe197c973 100755 --- a/cmake_targets/build_oai +++ b/cmake_targets/build_oai @@ -99,7 +99,7 @@ Options: USRP, BLADERF, LMSSDR, IRIS, SIMU, AW2SORI, AERIAL, None (Default) Adds this RF board support (in external packages installation and in compilation) -t | --transport - Selects the transport protocol type, options: None, Ethernet, benetel4g, benetel5g, oran_fhlib_5g, oran_fhlib_5g_mplane + Selects the transport protocol type, options: None, Ethernet, benetel4g, benetel5g, oran_fhlib_5g, oran_fhlib_5g_mplane, WLS -P | --phy_simulators Makes the unitary tests Layer 1 simulators -s | --check @@ -308,6 +308,9 @@ function main() { TARGET_LIST="$TARGET_LIST $2" CMAKE_CMD="$CMAKE_CMD -DOAI_FHI72=ON -DOAI_FHI72_MPLANE=ON" ;; + "WLS"|"Wls"|"wls") + CMAKE_CMD="$CMAKE_CMD -DOAI_WLS=ON" + ;; "None") ;; *) diff --git a/nfapi/CMakeLists.txt b/nfapi/CMakeLists.txt index e79905b07c..6b9c75b5a8 100644 --- a/nfapi/CMakeLists.txt +++ b/nfapi/CMakeLists.txt @@ -1,4 +1,9 @@ add_subdirectory(oai_integration/aerial) -add_subdirectory(oai_integration/socket) +if (OAI_WLS) + add_subdirectory(oai_integration/wls_integration) +else () # Not WLS, means its SOCKET-based comms, maybe add a flag specific for UDP + message(STATUS "No Support for WLS") + add_subdirectory(oai_integration/socket) +endif () add_subdirectory(open-nFAPI) add_subdirectory(tests) diff --git a/nfapi/oai_integration/nfapi_pnf.c b/nfapi/oai_integration/nfapi_pnf.c index 88b82ad480..24d7d0fbfa 100644 --- a/nfapi/oai_integration/nfapi_pnf.c +++ b/nfapi/oai_integration/nfapi_pnf.c @@ -63,6 +63,12 @@ #include "executables/lte-softmodem.h" #include "nfapi/open-nFAPI/pnf/inc/pnf_p7.h" +#ifdef ENABLE_WLS +#include +#include +#include "nfapi/oai_integration/wls_integration/include/wls_pnf.h" +#endif + #ifdef ENABLE_SOCKET #include #endif @@ -1752,6 +1758,15 @@ int nr_start_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, nf p7_config->codec_config.unpack_vendor_extension_tlv = &pnf_nr_phy_unpack_vendor_extension_tlv; p7_config->codec_config.pack_vendor_extension_tlv = &pnf_nr_phy_pack_vendor_extention_tlv; +#ifdef ENABLE_WLS + p7_config->unpack_func = &fapi_nr_p7_message_unpack; + p7_config->hdr_unpack_func = &fapi_nr_p7_message_header_unpack; + p7_config->pack_func = &fapi_nr_p7_message_pack; + p7_config->send_p7_msg = &wls_pnf_nr_send_p7_message; + // pass p7_config to WLS handler + wls_pnf_set_p7_config(p7_config); +#endif + #ifdef ENABLE_SOCKET p7_config->unpack_func = &nfapi_nr_p7_message_unpack; p7_config->hdr_unpack_func = &nfapi_nr_p7_message_header_unpack; @@ -1806,10 +1821,11 @@ int nr_start_request(nfapi_pnf_config_t *config, nfapi_pnf_phy_config_t *phy, nf usleep(50000); printf("[PNF] waiting for OAI to be started\n"); } - +#ifndef ENABLE_WLS printf("[PNF] Sending PNF_START_RESP\n"); nfapi_nr_send_pnf_start_resp(config, p7_config->phy_id); printf("[PNF] Sending first P7 slot indication\n"); +#endif #if 1 nfapi_pnf_p7_slot_ind(p7_config, p7_config->phy_id, 0, 0); printf("[PNF] Sent first P7 slot ind\n"); @@ -2192,6 +2208,17 @@ void configure_nr_nfapi_pnf(char *vnf_ip_addr, int vnf_p5_port, char *pnf_ip_add config->codec_config.unpack_p4_p5_vendor_extension = &pnf_nr_sim_unpack_p4_p5_vendor_extension; config->codec_config.pack_p4_p5_vendor_extension = &pnf_nr_sim_pack_p4_p5_vendor_extension; +#ifdef ENABLE_WLS + printf("WLS MODE PNF\n"); + NFAPI_TRACE(NFAPI_TRACE_INFO, "[PNF] Creating WLS PNF NFAPI start thread %s\n", __FUNCTION__); + // Assume it's the FAPI handler, change from within the PNF if it's not the case + config->unpack_func = &fapi_nr_p5_message_unpack; + config->hdr_unpack_func = &fapi_nr_message_header_unpack; + config->pack_func = &fapi_nr_p5_message_pack; + config->send_p5_msg = &wls_pnf_nr_send_p5_message; + //wls_fapi_pnf_nr_start_thread(config); + threadCreate(&pnf_p5_init_and_receive_pthread, wls_fapi_pnf_nr_start_thread, config, "NFAPI_WLS_PNF", -1, OAI_PRIORITY_RT_MAX); +#endif #ifdef ENABLE_SOCKET NFAPI_TRACE(NFAPI_TRACE_INFO, "[PNF] Creating PNF NFAPI start thread %s\n", __FUNCTION__); diff --git a/nfapi/oai_integration/wls_integration/CMakeLists.txt b/nfapi/oai_integration/wls_integration/CMakeLists.txt new file mode 100644 index 0000000000..0a217dd5b6 --- /dev/null +++ b/nfapi/oai_integration/wls_integration/CMakeLists.txt @@ -0,0 +1,21 @@ +message(STATUS "Building with support for WLS") +add_library(wls_integration_lib + wls_pnf.c + wls_common.c +) + +find_library(WLS_LIB wls REQUIRED) +message(STATUS " wls library found in ${WLS_LIB}") + +find_library(hugetlbfs_LIB hugetlbfs REQUIRED) +message(STATUS " hugetlbfs library found in ${hugetlbfs_LIB}") + +pkg_check_modules(dpdk REQUIRED libdpdk=20.11.3) +target_link_libraries(wls_integration_lib PRIVATE ${dpdk_LINK_LIBRARIES}) +target_include_directories(wls_integration_lib PRIVATE ${dpdk_INCLUDE_DIRS}) +target_include_directories(wls_integration_lib PRIVATE include/) + +target_compile_definitions(wls_integration_lib PUBLIC ENABLE_WLS) +target_link_libraries(wls_integration_lib PRIVATE NFAPI_LIB NFAPI_USER_LIB) +target_link_libraries(wls_integration_lib PRIVATE nr_fapi_p5 nr_fapi_p7) +target_link_libraries(wls_integration_lib PRIVATE "${WLS_LIB}" "${hugetlbfs_LIB}") diff --git a/nfapi/oai_integration/wls_integration/include/wls_common.h b/nfapi/oai_integration/wls_integration/include/wls_common.h new file mode 100644 index 0000000000..1b6a8e4cdf --- /dev/null +++ b/nfapi/oai_integration/wls_integration/include/wls_common.h @@ -0,0 +1,108 @@ +/* +* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#ifndef OPENAIRINTERFACE_WLS_COMMON_H +#define OPENAIRINTERFACE_WLS_COMMON_H + +#include +#include +#include +#include "wls_lib.h" +#include "nfapi/open-nFAPI/fapi/inc/nr_fapi_p5_utils.h" +#include "nfapi/open-nFAPI/fapi/inc/nr_fapi_p7_utils.h" + +#define WLS_DEV_NAME "wls" +#define WLS_MAC_MEMORY_SIZE 0x7F000000 +#define WLS_PHY_MEMORY_SIZE 0x7F000000 + +#define MAX_NUM_LOCATIONS (508) + +#define MIN_DL_BUF_LOCATIONS (0) /* Used for stats collection 0-49 */ +#define MIN_UL_BUF_LOCATIONS (MIN_DL_BUF_LOCATIONS + MAX_NUM_LOCATIONS) /* Used for stats collection 50-99 */ + +#define MAX_DL_BUF_LOCATIONS (MIN_DL_BUF_LOCATIONS + MAX_NUM_LOCATIONS) /* Used for stats collection 0-49 */ +#define MAX_UL_BUF_LOCATIONS (MIN_UL_BUF_LOCATIONS + MAX_NUM_LOCATIONS) /* Used for stats collection 50-99 */ + +#define ALLOC_TRACK_SIZE ( 16384 ) + +typedef struct { + uint64_t *values; + uint16_t values_size; + uint16_t values_count; +}pa_store_t; + +/* ----- WLS Operation --- */ +#define FAPI_VENDOR_MSG_HEADER_IND 0x1A +// Linked list header present at the top of all messages +typedef struct _fapi_api_queue_elem { + struct _fapi_api_queue_elem *p_next; + // p_tx_data_elm_list used for TX_DATA.request processing + struct _fapi_api_queue_elem *p_tx_data_elm_list; + uint8_t msg_type; + uint8_t num_message_in_block; + uint32_t msg_len; + uint32_t align_offset; + uint64_t time_stamp; +} fapi_api_queue_elem_t, + *p_fapi_api_queue_elem_t; + + +typedef struct wls_mac_mem_array +{ + void **ppFreeBlock; + void *pStorage; + void *pEndOfStorage; + uint32_t nBlockSize; + uint32_t nBlockCount; +} WLS_MAC_MEM_SRUCT, *PWLS_MAC_MEM_SRUCT; + +typedef struct wls_mac_ctx +{ + void *hWls; + void *pWlsMemBase; + void *pWlsMemBaseUsable; + WLS_MAC_MEM_SRUCT sWlsStruct; + + uint64_t nTotalMemorySize; + uint64_t nTotalMemorySizeUsable; + uint32_t nBlockSize; + uint32_t nTotalBlocks; + uint32_t nAllocBlocks; + uint32_t nTotalAllocCnt; + uint32_t nTotalFreeCnt; + uint32_t nTotalUlBufAllocCnt; + uint32_t nTotalUlBufFreeCnt; + uint32_t nTotalDlBufAllocCnt; + uint32_t nTotalDlBufFreeCnt; + // Support for FAPI Translator + uint32_t nPartitionMemSize; + void *pPartitionMemBase; + + volatile pthread_mutex_t lock; + volatile pthread_mutex_t lock_alloc; +} WLS_MAC_CTX, *PWLS_MAC_CTX; + +void fill_fapi_list_elem(p_fapi_api_queue_elem_t currElem, p_fapi_api_queue_elem_t nextElem, const uint8_t msgType, const uint8_t numMsgInBlock, const uint32_t alignOffset); +uint64_t dequeueBlock(PWLS_MAC_CTX pWls); +void wls_return_msg_to_master(PWLS_MAC_CTX pWls, const uint64_t msg_PA); +uint8_t wls_send_fapi_msg(PWLS_MAC_CTX pWls, const uint16_t message_id, const int packed_len, const uint8_t *message ); +uint8_t wls_msg_send(PWLS_MAC_CTX pWls, p_fapi_api_queue_elem_t currMsg); +#endif //OPENAIRINTERFACE_WLS_COMMON_H diff --git a/nfapi/oai_integration/wls_integration/include/wls_pnf.h b/nfapi/oai_integration/wls_integration/include/wls_pnf.h new file mode 100644 index 0000000000..c678345967 --- /dev/null +++ b/nfapi/oai_integration/wls_integration/include/wls_pnf.h @@ -0,0 +1,33 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#ifndef OPENAIRINTERFACE_WLS_PNF_H +#define OPENAIRINTERFACE_WLS_PNF_H +#include "nfapi_pnf_interface.h" +#include "pnf.h" +#include "wls_common.h" + +bool wls_pnf_nr_send_p5_message(pnf_t *pnf, nfapi_nr_p4_p5_message_header_t* msg, uint32_t msg_len); +bool wls_pnf_nr_send_p7_message(pnf_p7_t* pnf_p7,nfapi_nr_p7_message_header_t *msg, uint32_t msg_len); +void *wls_fapi_pnf_nr_start_thread(void *ptr); +int wls_fapi_nr_pnf_start(); +void wls_pnf_set_p7_config(void *p7_config); +#endif // OPENAIRINTERFACE_WLS_PNF_H diff --git a/nfapi/oai_integration/wls_integration/wls_common.c b/nfapi/oai_integration/wls_integration/wls_common.c new file mode 100644 index 0000000000..fe4112eba8 --- /dev/null +++ b/nfapi/oai_integration/wls_integration/wls_common.c @@ -0,0 +1,118 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#include "wls_common.h" + +void fill_fapi_list_elem(p_fapi_api_queue_elem_t currElem, p_fapi_api_queue_elem_t nextElem, const uint8_t msgType, const uint8_t numMsgInBlock, const uint32_t alignOffset) +{ + currElem->msg_type = msgType; + currElem->num_message_in_block = numMsgInBlock; + currElem->align_offset = alignOffset; + currElem->msg_len = numMsgInBlock * alignOffset; + currElem->p_next = nextElem; + currElem->p_tx_data_elm_list = NULL; + currElem->time_stamp = 0; +} + +uint64_t dequeueBlock(PWLS_MAC_CTX pWls) +{ + uint64_t pa = WLS_DequeueBlock(pWls->hWls); + AssertFatal(pa, "WLS_DequeueBlock failed for pa_hdr\n"); + unsigned long* va = WLS_PA2VA(pWls->hWls, pa); + AssertFatal(va, "WLS_PA2VA failed for headerElem\n"); + while (*va != -1) { + pa = WLS_DequeueBlock(pWls->hWls); + AssertFatal(pa, "WLS_DequeueBlock failed for pa_hdr\n"); + va = WLS_PA2VA(pWls->hWls, pa); + } + return pa; +} + +uint8_t wls_msg_send(PWLS_MAC_CTX pWls, p_fapi_api_queue_elem_t currMsg) +{ + uint32_t msgLen = 0; + + AssertFatal(currMsg, "currMsg can't be NULL"); + AssertFatal(currMsg->p_next, "There needs to be at least 2 blocks to send!"); + msgLen = currMsg->msg_len + sizeof(fapi_api_queue_elem_t); + // Send the first block + if (WLS_Put(pWls, WLS_VA2PA(pWls, currMsg), msgLen, currMsg->msg_type, WLS_SG_FIRST) != 0) { + NFAPI_TRACE(NFAPI_TRACE_ERROR, "Failure in sending the header block\n"); + return false; + } + // Iterate over the linked list, until a NULL block or a block set to 0xFFFFFFFFFFFFFFFF ( invalid ) + while (((currMsg = currMsg->p_next)) && (uint64_t)(currMsg) != -1) { + msgLen = currMsg->msg_len + sizeof(fapi_api_queue_elem_t); + /* Send the block with appropriate flags, either WLS_SG_NEXT or WLS_SG_LAST */ + const unsigned short flags = currMsg->p_next != NULL ? WLS_SG_NEXT : WLS_SG_LAST; + if (WLS_Put(pWls, WLS_VA2PA(pWls, currMsg), msgLen, currMsg->msg_type, flags) != 0) { + NFAPI_TRACE(NFAPI_TRACE_ERROR, "Failure in sending the message block\n"); + return false; + } + } + return true; +} + +void wls_return_msg_to_master(PWLS_MAC_CTX pWls,const uint64_t msg_PA) +{ + p_fapi_api_queue_elem_t fapiMsgElem = WLS_PA2VA(pWls->hWls, msg_PA); + AssertFatal(fapiMsgElem, "WLS_PA2VA failed for fapiMsgElem\n"); + const uint8_t wls_header[] = {1, 0}; // num_messages , opaque_handle + // No need to return the message contents, just the block + fill_fapi_list_elem(fapiMsgElem, NULL, FAPI_VENDOR_MSG_HEADER_IND, 1, 2); + memcpy((uint8_t *)(fapiMsgElem + 1), wls_header, 2); + const uint32_t msgLen = fapiMsgElem->msg_len + sizeof(fapi_api_queue_elem_t); + /* Send the block with appropriate only WLS_SG_FIRST flag, since we send only 1 block*/ + if (WLS_Put(pWls->hWls, msg_PA, msgLen, FAPI_VENDOR_MSG_HEADER_IND, WLS_SG_FIRST) != 0) { + NFAPI_TRACE(NFAPI_TRACE_ERROR,"Failure in sending block back to master\n"); + } +} + +uint8_t wls_send_fapi_msg(PWLS_MAC_CTX pWls, const uint16_t message_id, const int packed_len, const uint8_t *message) +{ + int num_avail_blocks = WLS_NumBlocks(pWls->hWls); + NFAPI_TRACE(NFAPI_TRACE_DEBUG,"num_avail_blocks is %d\n", num_avail_blocks); + while (num_avail_blocks < 2) { + num_avail_blocks = WLS_NumBlocks(pWls->hWls); + NFAPI_TRACE(NFAPI_TRACE_DEBUG,"num_avail_blocks is %d\n", num_avail_blocks); + } + /* get PA blocks for header and msg */ + uint64_t pa_hdr = dequeueBlock(pWls); + AssertFatal(pa_hdr, "WLS_DequeueBlock failed for pa_hdr\n"); + uint64_t pa_msg = dequeueBlock(pWls); + AssertFatal(pa_msg, "WLS_DequeueBlock failed for pa_msg\n"); + p_fapi_api_queue_elem_t headerElem = WLS_PA2VA(pWls->hWls, pa_hdr); + AssertFatal(headerElem, "WLS_PA2VA failed for headerElem\n"); + p_fapi_api_queue_elem_t fapiMsgElem = WLS_PA2VA(pWls->hWls, pa_msg); + AssertFatal(fapiMsgElem, "WLS_PA2VA failed for fapiMsgElem\n"); + fill_fapi_list_elem(fapiMsgElem, NULL, message_id, 1, packed_len + NFAPI_HEADER_LENGTH); + memcpy((uint8_t *)(fapiMsgElem + 1), message, packed_len + NFAPI_HEADER_LENGTH); + uint8_t wls_header[] = {1, 0}; // num_messages , opaque_handle + if (NFAPI_MODE == NFAPI_MODE_VNF) { + // Use the opaque handle to signal to our PNF to not progress the FAPI PNF state machine + wls_header[1] = 0xff; + } + fill_fapi_list_elem(headerElem, fapiMsgElem, FAPI_VENDOR_MSG_HEADER_IND, 1, 2); + memcpy((uint8_t *)(headerElem + 1), wls_header, 2); + uint8_t retval = wls_msg_send(pWls->hWls, headerElem); + return retval; +} + diff --git a/nfapi/oai_integration/wls_integration/wls_pnf.c b/nfapi/oai_integration/wls_integration/wls_pnf.c new file mode 100644 index 0000000000..e02cef30a4 --- /dev/null +++ b/nfapi/oai_integration/wls_integration/wls_pnf.c @@ -0,0 +1,290 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +#include "wls_pnf.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "pnf.h" +#include "nr_nfapi_p7.h" +#include "nr_fapi_p5.h" + +// A copy of the PNF P7 config is needed for the message processing thread, in other transport mechanisms where P7 is handled in a +// different thread, the config is passed to it upon the thread creation +nfapi_pnf_p7_config_t *wls_pnf_p7_config = NULL; + +void wls_pnf_set_p7_config(void *p7_config) +{ + wls_pnf_p7_config = (nfapi_pnf_p7_config_t *)p7_config; +} + +static WLS_MAC_CTX g_phy_wls; +uint8_t phy_dpdk_init(void); +uint8_t phy_wls_init(const char *dev_name, uint64_t nWlsMacMemSize, uint64_t nWlsPhyMemSize); +void phy_mac_recv(); +void wls_mac_print_stats(void); + +pnf_t *_this = NULL; + +static PWLS_MAC_CTX wls_mac_get_ctx(void) +{ + return &g_phy_wls; +} + +static nfapi_pnf_config_t *cfg; + +void *wls_fapi_pnf_nr_start_thread(void *ptr) +{ + NFAPI_TRACE(NFAPI_TRACE_INFO, "[PNF] IN WLS PNF NFAPI start thread %s\n", __FUNCTION__); + cfg = (nfapi_pnf_config_t *)ptr; + wls_fapi_nr_pnf_start(); + return (void *)0; +} + +int wls_fapi_nr_pnf_start() +{ + int64_t ret; + // Verify that config is not null + if (cfg == 0) + return -1; + + NFAPI_TRACE(NFAPI_TRACE_INFO, "%s\n", __FUNCTION__); + + _this = (pnf_t *)(cfg); + _this->terminate = 0; + // Init PNF config + nfapi_pnf_phy_config_t *phy = (nfapi_pnf_phy_config_t *)malloc(sizeof(nfapi_pnf_phy_config_t)); + memset(phy, 0, sizeof(nfapi_pnf_phy_config_t)); + + phy->state = NFAPI_PNF_PHY_IDLE; + phy->phy_id = 0; + phy->next = (_this->_public).phys; + (_this->_public).phys = phy; + _this->_public.state = NFAPI_PNF_RUNNING; + + // DPDK init + ret = phy_dpdk_init(); + if (!ret) { + NFAPI_TRACE(NFAPI_TRACE_ERROR, "[PNF] DPDK Init - Failed\n"); + return false; + } + NFAPI_TRACE(NFAPI_TRACE_INFO, "\n[PHY] DPDK Init - Done\n"); + + // WLS init + ret = phy_wls_init(WLS_DEV_NAME, WLS_MAC_MEMORY_SIZE, WLS_PHY_MEMORY_SIZE); + if (!ret) { + NFAPI_TRACE(NFAPI_TRACE_ERROR, "[PNF] WLS Init - Failed\n"); + return false; + } + NFAPI_TRACE(NFAPI_TRACE_INFO, "\n[PHY] WLS Init - Done\n"); + + // Start Receiving loop from the VNF + NFAPI_TRACE(NFAPI_TRACE_INFO, "Start Receiving loop from the VNF\n"); + phy_mac_recv(); + // Should never get here, to be removed, align with present implementation of PNF loop + NFAPI_TRACE(NFAPI_TRACE_INFO, "\n[PHY] Exiting...\n"); + + return true; +} + +uint8_t phy_dpdk_init(void) +{ + unsigned long i; + char *argv[] = {"OAI_PNF", "--proc-type=primary", "--file-prefix", WLS_DEV_NAME, "--iova-mode=pa", "--no-pci"}; + int argc = RTE_DIM(argv); + /* initialize EAL first */ + NFAPI_TRACE(NFAPI_TRACE_INFO, "\n[PHY] Calling rte_eal_init: "); + + for (i = 0; i < RTE_DIM(argv); i++) { + NFAPI_TRACE(NFAPI_TRACE_INFO, "%s ", argv[i]); + } + + NFAPI_TRACE(NFAPI_TRACE_INFO, "\n"); + + if (rte_eal_init(argc, argv) < 0) + rte_panic("Cannot init EAL\n"); + + return true; +} + +uint8_t phy_wls_init(const char *dev_name, uint64_t nWlsMacMemSize, uint64_t nWlsPhyMemSize) +// uint8_t phy_wls_init(const char *dev_name, uint64_t nBlockSize) +{ + PWLS_MAC_CTX pWls = wls_mac_get_ctx(); + pWls->nTotalAllocCnt = 0; + pWls->nTotalFreeCnt = 0; + pWls->nTotalUlBufAllocCnt = 0; + pWls->nTotalUlBufFreeCnt = 0; + pWls->nTotalDlBufAllocCnt = 0; + pWls->nTotalDlBufFreeCnt = 0; + + pWls->hWls = WLS_Open(dev_name, WLS_SLAVE_CLIENT, &nWlsMacMemSize, &nWlsPhyMemSize); + if (pWls->hWls) { + /* allocate chuck of memory */ + if (WLS_Alloc(pWls->hWls, nWlsMacMemSize + nWlsPhyMemSize) != NULL) { + NFAPI_TRACE(NFAPI_TRACE_DEBUG, "WLS Memory allocated successfully\n"); + } else { + NFAPI_TRACE(NFAPI_TRACE_ERROR, "Unable to alloc WLS Memory\n"); + return false; + } + } else { + NFAPI_TRACE(NFAPI_TRACE_ERROR, "can't open WLS instance"); + return false; + } + return true; +} + +bool wls_pnf_nr_send_p5_message(pnf_t *pnf, nfapi_nr_p4_p5_message_header_t *msg, uint32_t msg_len) +{ + int packed_len = cfg->pack_func(msg, msg_len, pnf->tx_message_buffer, sizeof(pnf->tx_message_buffer), &pnf->_public.codec_config); + + if (packed_len < 0) { + NFAPI_TRACE(NFAPI_TRACE_ERROR, "nfapi_p5_message_pack failed (%d)\n", packed_len); + return false; + } + + NFAPI_TRACE(NFAPI_TRACE_DEBUG, "fapi_nr_p5_message_pack succeeded having packed %d bytes\n", packed_len); + NFAPI_TRACE(NFAPI_TRACE_DEBUG, "in msg, msg_len is %d\n", msg->message_length); + PWLS_MAC_CTX pWls = wls_mac_get_ctx(); + + + return wls_send_fapi_msg(pWls, msg->message_id, packed_len, pnf->tx_message_buffer); +} + +bool wls_pnf_nr_send_p7_message(pnf_p7_t *pnf_p7, nfapi_nr_p7_message_header_t *msg, uint32_t msg_len) +{ + UNUSED_VARIABLE(msg_len); + + if (!isFAPIMessageIDValid(msg->message_id)) { + return false; + } + + // if it's an nFAPI message, ignore + if ((msg->message_id == NFAPI_NR_PHY_MSG_TYPE_UL_NODE_SYNC || msg->message_id == NFAPI_NR_PHY_MSG_TYPE_DL_NODE_SYNC + || msg->message_id == NFAPI_NR_PHY_MSG_TYPE_TIMING_INFO)) { + return false; + } + + PWLS_MAC_CTX pWls = wls_mac_get_ctx(); + int num_avail_blocks = WLS_NumBlocks(pWls->hWls); + NFAPI_TRACE(NFAPI_TRACE_DEBUG, "num_avail_blocks is %d\n", num_avail_blocks); + while (num_avail_blocks < 2) { + num_avail_blocks = WLS_NumBlocks(pWls->hWls); + NFAPI_TRACE(NFAPI_TRACE_DEBUG, "num_avail_blocks is %d\n", num_avail_blocks); + } + /* get PA blocks for header and msg */ + const uint64_t pa_hdr = dequeueBlock(pWls); + AssertFatal(pa_hdr, "WLS_DequeueBlock failed for pa_hdr\n"); + const uint64_t pa_msg = dequeueBlock(pWls); + AssertFatal(pa_msg, "WLS_DequeueBlock failed for pa_msg\n"); + p_fapi_api_queue_elem_t headerElem = WLS_PA2VA(pWls->hWls, pa_hdr); + AssertFatal(headerElem, "WLS_PA2VA failed for headerElem\n"); + p_fapi_api_queue_elem_t fapiMsgElem = WLS_PA2VA(pWls->hWls, pa_msg); + AssertFatal(fapiMsgElem, "WLS_PA2VA failed for fapiMsgElem\n"); + const uint8_t wls_header[] = {1, 0}; // num_messages , opaque_handle + fill_fapi_list_elem(headerElem, fapiMsgElem, FAPI_VENDOR_MSG_HEADER_IND, 1, 2); + memcpy((uint8_t *)(headerElem + 1), wls_header, 2); + + const int packed_len = ((nfapi_pnf_p7_config_t *)pnf_p7)->pack_func(msg, (fapiMsgElem + 1), NFAPI_MAX_PACKED_MESSAGE_SIZE, NULL); + + if (packed_len < 0) { + NFAPI_TRACE(NFAPI_TRACE_ERROR, "nfapi_p7_message_pack failed (%d)\n", packed_len); + return false; + } + fill_fapi_list_elem(fapiMsgElem, NULL, msg->message_id, 1, packed_len + NFAPI_HEADER_LENGTH); + const uint8_t retval = wls_msg_send(pWls->hWls, headerElem); + return retval; +} + +static void procPhyMessages(uint32_t msg_size, void *msg_buf, uint16_t msg_id) +{ + + NFAPI_TRACE(NFAPI_TRACE_DEBUG, "[PHY] Received Msg ID 0x%02x Length %d\n", msg_id, msg_size); + if (msg_buf == NULL || _this == NULL) { + AssertFatal(msg_buf != NULL && _this != NULL, "%s: NULL parameters\n", __FUNCTION__); + } + // Add the size of the header to the message_size, because the size in the header does not include the header length + msg_size += NFAPI_NR_P5_HEADER_LENGTH; + switch (msg_id) { + case NFAPI_NR_PHY_MSG_TYPE_PARAM_REQUEST ... NFAPI_NR_PHY_MSG_TYPE_STOP_REQUEST: + pnf_nr_handle_p5_message(_this, msg_buf, msg_size); + break; + case NFAPI_NR_PHY_MSG_TYPE_DL_TTI_REQUEST ... NFAPI_NR_PHY_MSG_TYPE_RACH_INDICATION: { + pnf_nr_handle_p7_message(msg_buf, msg_size, (pnf_p7_t *)wls_pnf_p7_config, 0); + break; + } + default: + printf("\n Unknown Msg ID 0x%02x\n", msg_id); + break; + } +} + +void phy_mac_recv() +{ + /* Number of Memory blocks to get */ + uint32_t msgSize; + uint16_t msgType; + uint16_t flags; + PWLS_MAC_CTX pWls = wls_mac_get_ctx(); + // This flag is used to determine whether to return the received blocks to the PNF + bool to_return = false; + while (_this->terminate == 0) { + int numMsgToGet = WLS_Wait(pWls->hWls); + if (numMsgToGet == 0) { + continue; + } + uint64_t PAs[numMsgToGet]; + uint8_t pa_idx = 0; + while (numMsgToGet--) { + PAs[pa_idx] = WLS_Get(pWls->hWls, &msgSize, &msgType, &flags); + pa_idx++; + } + for (int i = 0; i < pa_idx; i++) { + p_fapi_api_queue_elem_t msg = WLS_PA2VA(pWls->hWls, PAs[i]); + if (msg->msg_type != FAPI_VENDOR_MSG_HEADER_IND) { + uint8_t *msgt = (uint8_t *)(msg + 1); + uint32_t len = msgt[7] | (msgt[6] << 8) | (msgt[5] << 16) | (msgt[4] << 24); + procPhyMessages(len, (void *)(msg + 1), msg->msg_type); + } else { + // We check the header block to determine if it's the OAI VNF, if so, we're required to return the pages for enqueueing + if (!to_return) { + uint8_t *msgt = (uint8_t *)(msg + 1); + if (msgt[1] == 0xff) { + to_return = true; + } + } + } + } + if (to_return) { + // We only return the pages to be enqueued in case we're using the OAI VNF, + // The Radisys O-DU handles enqueueing the blocks differently, and also doesn't handle receiving a single block + for (int i = 0; i < pa_idx; i++) { + wls_return_msg_to_master(pWls, PAs[i]); + } + } + } +} diff --git a/nfapi/open-nFAPI/fapi/CMakeLists.txt b/nfapi/open-nFAPI/fapi/CMakeLists.txt index a97f5f6e6f..cf7f85052f 100644 --- a/nfapi/open-nFAPI/fapi/CMakeLists.txt +++ b/nfapi/open-nFAPI/fapi/CMakeLists.txt @@ -23,4 +23,8 @@ if (OAI_AERIAL) target_compile_definitions(nr_fapi_p7 PRIVATE ENABLE_AERIAL) endif () -target_compile_definitions(nr_fapi_common PRIVATE ENABLE_SOCKET) +if(OAI_WLS) + target_compile_definitions(nr_fapi_common PRIVATE ENABLE_WLS) +else() + target_compile_definitions(nr_fapi_common PRIVATE ENABLE_SOCKET) +endif() diff --git a/nfapi/open-nFAPI/fapi/inc/nr_fapi.h b/nfapi/open-nFAPI/fapi/inc/nr_fapi.h index fcf4b97973..e71e1bae5c 100644 --- a/nfapi/open-nFAPI/fapi/inc/nr_fapi.h +++ b/nfapi/open-nFAPI/fapi/inc/nr_fapi.h @@ -77,12 +77,34 @@ bool isFAPIMessageIDValid(uint16_t id); int check_nr_fapi_unpack_length(nfapi_nr_phy_msg_type_e msgId, uint32_t unpackedBufLen); -int fapi_nr_message_header_unpack(void *pMessageBuf, +/*! \brief Decodes a FAPI P5 message header + * \param pMessageBuf A pointer to an encoded P5 message header + * \param messageBufLen The size of the encoded P5 message header + * \param pUnpackedBuf A pointer to the fapi_message_header + * \param unpackedBufLen The size of fapi_message_header structure. + * \param config A pointer to the nfapi configuration structure + * \return true on success, false on failure. + * + * The function will decode a byte stream pointed to by pMessageBuf into a FAPI p5 header structure pointed to by pUnpackedBuf + */ +bool fapi_nr_message_header_unpack(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen, nfapi_p4_p5_codec_config_t *config); -int fapi_nr_p7_message_header_unpack(void *pMessageBuf, + +/*! \brief Decodes a FAPI P7 message header + * \param pMessageBuf A pointer to an encoded P5 message header + * \param messageBufLen The size of the encoded P5 message header + * \param pUnpackedBuf A pointer to the fapi_message_header + * \param unpackedBufLen The size of fapi_message_header structure. + * \param config A pointer to the nfapi configuration structure + * \return true on success, false on failure. + * + * This function is a dummy function that points to fapi_nr_message_header_unpack, + * since in FAPI there's no difference in the structure of the message headers for P5 and P7 + */ +bool fapi_nr_p7_message_header_unpack(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen, diff --git a/nfapi/open-nFAPI/fapi/inc/nr_fapi_p5.h b/nfapi/open-nFAPI/fapi/inc/nr_fapi_p5.h index 307b5bad27..d47f0ec929 100644 --- a/nfapi/open-nFAPI/fapi/inc/nr_fapi_p5.h +++ b/nfapi/open-nFAPI/fapi/inc/nr_fapi_p5.h @@ -30,7 +30,7 @@ int fapi_nr_p5_message_pack(void *pMessageBuf, uint32_t packedBufLen, nfapi_p4_p5_codec_config_t *config); -int fapi_nr_p5_message_unpack(void *pMessageBuf, +bool fapi_nr_p5_message_unpack(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen, diff --git a/nfapi/open-nFAPI/fapi/inc/nr_fapi_p5_utils.h b/nfapi/open-nFAPI/fapi/inc/nr_fapi_p5_utils.h index 77ed67e2ef..8ef5fbade2 100644 --- a/nfapi/open-nFAPI/fapi/inc/nr_fapi_p5_utils.h +++ b/nfapi/open-nFAPI/fapi/inc/nr_fapi_p5_utils.h @@ -23,7 +23,7 @@ #define OPENAIRINTERFACE_NR_FAPI_P5_UTILS_H #include "stdio.h" #include "stdint.h" -#include "nr_fapi.h" +#include "nfapi/open-nFAPI/fapi/inc/nr_fapi.h" #include "nfapi/oai_integration/vendor_ext.h" bool eq_param_request(const nfapi_nr_param_request_scf_t *unpacked_req, const nfapi_nr_param_request_scf_t *req); diff --git a/nfapi/open-nFAPI/fapi/inc/nr_fapi_p7.h b/nfapi/open-nFAPI/fapi/inc/nr_fapi_p7.h index c2701acb5f..80b39f7386 100644 --- a/nfapi/open-nFAPI/fapi/inc/nr_fapi_p7.h +++ b/nfapi/open-nFAPI/fapi/inc/nr_fapi_p7.h @@ -23,7 +23,7 @@ int fapi_nr_p7_message_pack(void *pMessageBuf, void *pPackedBuf, uint32_t packedBufLen, nfapi_p7_codec_config_t *config); -int fapi_nr_p7_message_unpack(void *pMessageBuf, +bool fapi_nr_p7_message_unpack(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen, diff --git a/nfapi/open-nFAPI/fapi/inc/nr_fapi_p7_utils.h b/nfapi/open-nFAPI/fapi/inc/nr_fapi_p7_utils.h index f915548783..5c1df2dcef 100644 --- a/nfapi/open-nFAPI/fapi/inc/nr_fapi_p7_utils.h +++ b/nfapi/open-nFAPI/fapi/inc/nr_fapi_p7_utils.h @@ -33,7 +33,7 @@ #define OPENAIRINTERFACE_NR_FAPI_P7_UTILS_H #include "stdio.h" #include "stdint.h" -#include "nr_fapi.h" +#include "nfapi/open-nFAPI/fapi/inc/nr_fapi.h" bool eq_dl_tti_request(const nfapi_nr_dl_tti_request_t *a, const nfapi_nr_dl_tti_request_t *b); bool eq_ul_tti_request(const nfapi_nr_ul_tti_request_t *a, const nfapi_nr_ul_tti_request_t *b); diff --git a/nfapi/open-nFAPI/fapi/src/nr_fapi.c b/nfapi/open-nFAPI/fapi/src/nr_fapi.c index 475b6c07dd..4da483db17 100644 --- a/nfapi/open-nFAPI/fapi/src/nr_fapi.c +++ b/nfapi/open-nFAPI/fapi/src/nr_fapi.c @@ -54,7 +54,6 @@ bool isFAPIMessageIDValid(const uint16_t id) int check_nr_fapi_unpack_length(nfapi_nr_phy_msg_type_e msgId, uint32_t unpackedBufLen) { int retLen = 0; - // check for size of nFAPI struct without the nFAPI specific parameters switch (msgId) { case NFAPI_NR_PHY_MSG_TYPE_PARAM_REQUEST: @@ -165,7 +164,7 @@ int check_nr_fapi_unpack_length(nfapi_nr_phy_msg_type_e msgId, uint32_t unpacked return retLen; } -int fapi_nr_p7_message_header_unpack(void *pMessageBuf, +bool fapi_nr_p7_message_header_unpack(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen, @@ -178,7 +177,7 @@ int fapi_nr_p7_message_header_unpack(void *pMessageBuf, NULL); } -int fapi_nr_message_header_unpack(void *pMessageBuf, +bool fapi_nr_message_header_unpack(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen, @@ -190,12 +189,12 @@ int fapi_nr_message_header_unpack(void *pMessageBuf, if (pMessageBuf == NULL || pUnpackedBuf == NULL || messageBufLen < NFAPI_HEADER_LENGTH || unpackedBufLen < sizeof(fapi_message_header_t)) { - return -1; + return false; } uint8_t *end = pMessageBuf + messageBufLen; // process the header int result = (pull8(&pReadPackedMessage, &fapi_msg.num_msg, end) && pull8(&pReadPackedMessage, &fapi_msg.opaque_handle, end) && pull16(&pReadPackedMessage, &header->message_id, end) && pull32(&pReadPackedMessage, &header->message_length, end)); - return (result); + return result != 0; } diff --git a/nfapi/open-nFAPI/fapi/src/nr_fapi_p5.c b/nfapi/open-nFAPI/fapi/src/nr_fapi_p5.c index 554898cbd4..9339a666a3 100644 --- a/nfapi/open-nFAPI/fapi/src/nr_fapi_p5.c +++ b/nfapi/open-nFAPI/fapi/src/nr_fapi_p5.c @@ -128,7 +128,7 @@ int fapi_nr_p5_message_pack(void *pMessageBuf, return packedMsgLen; } -int fapi_nr_p5_message_unpack(void *pMessageBuf, +bool fapi_nr_p5_message_unpack(void *pMessageBuf, const uint32_t messageBufLen, void *pUnpackedBuf, const uint32_t unpackedBufLen, @@ -143,10 +143,9 @@ int fapi_nr_p5_message_unpack(void *pMessageBuf, unpackedBufLen); // clean the supplied buffer for - tag value blanking (void)memset(pUnpackedBuf, 0, unpackedBufLen); - if (fapi_nr_message_header_unpack(pMessageBuf, NFAPI_HEADER_LENGTH, pMessageHeader, sizeof(fapi_message_header_t), 0) - < 0) { + if (!fapi_nr_message_header_unpack(pMessageBuf, NFAPI_HEADER_LENGTH, pMessageHeader, sizeof(fapi_message_header_t), 0)) { // failed to read the header - return -1; + return false; } uint8_t *pReadPackedMessage = pMessageBuf + NFAPI_HEADER_LENGTH; uint8_t *end = (uint8_t *)pMessageBuf + messageBufLen; @@ -154,14 +153,14 @@ int fapi_nr_p5_message_unpack(void *pMessageBuf, if (check_nr_fapi_unpack_length(pMessageHeader->message_id, unpackedBufLen) == 0) { // the unpack buffer is not big enough for the struct - return -1; + return false; } // look for the specific message switch (pMessageHeader->message_id) { case NFAPI_NR_PHY_MSG_TYPE_PARAM_REQUEST: // PARAM request has no body; - result = 0; + result = 1; break; case NFAPI_NR_PHY_MSG_TYPE_PARAM_RESPONSE: @@ -209,7 +208,7 @@ int fapi_nr_p5_message_unpack(void *pMessageBuf, break; } - return result; + return result != 0; } uint8_t pack_nr_param_request(void *msg, uint8_t **ppWritePackedMsg, uint8_t *end, nfapi_p4_p5_codec_config_t *config) diff --git a/nfapi/open-nFAPI/fapi/src/nr_fapi_p7.c b/nfapi/open-nFAPI/fapi/src/nr_fapi_p7.c index 4f73e4596c..4945e6da45 100644 --- a/nfapi/open-nFAPI/fapi/src/nr_fapi_p7.c +++ b/nfapi/open-nFAPI/fapi/src/nr_fapi_p7.c @@ -134,7 +134,7 @@ int fapi_nr_p7_message_pack(void *pMessageBuf, void *pPackedBuf, uint32_t packed return packedMsgLen; } -int fapi_nr_p7_message_unpack(void *pMessageBuf, +bool fapi_nr_p7_message_unpack(void *pMessageBuf, uint32_t messageBufLen, void *pUnpackedBuf, uint32_t unpackedBufLen, @@ -150,9 +150,9 @@ int fapi_nr_p7_message_unpack(void *pMessageBuf, messageBufLen, unpackedBufLen); - if (fapi_nr_message_header_unpack(pMessageBuf, NFAPI_HEADER_LENGTH, &fapi_hdr, sizeof(fapi_message_header_t), 0) < 0) { + if (!fapi_nr_message_header_unpack(pMessageBuf, NFAPI_HEADER_LENGTH, &fapi_hdr, sizeof(fapi_message_header_t), 0)) { // failed to read the header - return -1; + return false; } uint8_t *pReadPackedMessage = pMessageBuf + NFAPI_HEADER_LENGTH; uint8_t *end = (uint8_t *)pMessageBuf + messageBufLen; @@ -160,7 +160,7 @@ int fapi_nr_p7_message_unpack(void *pMessageBuf, pMessageHeader->message_id = fapi_hdr.message_id; if ((uint8_t *)(pMessageBuf + pMessageHeader->message_length) > end) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "P7 unpack message length is greater than the message buffer \n"); - return -1; + return false; } // look for the specific message @@ -231,9 +231,9 @@ int fapi_nr_p7_message_unpack(void *pMessageBuf, if (result == 0) { NFAPI_TRACE(NFAPI_TRACE_ERROR, "P7 Unpack failed to unpack message\n"); - return -1; + return false; } - return 0; + return true; } static uint8_t pack_nr_tx_beamforming_pdu(const nfapi_nr_tx_precoding_and_beamforming_t *beamforming_pdu, diff --git a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h index 3cfd0591fc..d146408abf 100644 --- a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h +++ b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h @@ -28,8 +28,11 @@ #define NFAPI_PNF_PARAM_GENERAL_OUI_LENGTH 3 #define NFAPI_MAX_NUM_RF_BANDS 16 +#ifdef ENABLE_WLS +#define NFAPI_MAX_PACKED_MESSAGE_SIZE 1024*1024*2 +#else #define NFAPI_MAX_PACKED_MESSAGE_SIZE 32768 - +#endif // The following definition control the size of arrays used in the interface. // These may be changed if desired. They are used in the encoder to make sure // that the user has not specified a 'count' larger than the max array, and also diff --git a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c index f7c55cd2e0..e75e418500 100644 --- a/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c +++ b/nfapi/open-nFAPI/nfapi/src/nfapi_p7.c @@ -6206,6 +6206,10 @@ bool peek_nr_nfapi_p7_sfn_slot(void *pMessageBuf, uint32_t messageBufLen, uint16 #ifdef ENABLE_SOCKET // Socket transport will always use nFAPI encoding uint8_t *pReadPackedMessage = &((uint8_t *)pMessageBuf)[NFAPI_NR_P7_HEADER_LENGTH]; +#endif +#ifdef ENABLE_WLS + // WLS transport will always use FAPI encoding + uint8_t *pReadPackedMessage = &((uint8_t *)pMessageBuf)[NFAPI_HEADER_LENGTH]; #endif uint8_t *end = (uint8_t*)pMessageBuf + messageBufLen; if(!(pull16(&pReadPackedMessage, SFN, end) && pull16(&pReadPackedMessage, Slot, end))) { diff --git a/nfapi/open-nFAPI/pnf/inc/pnf.h b/nfapi/open-nFAPI/pnf/inc/pnf.h index 968359dfee..2dc2ce9de6 100644 --- a/nfapi/open-nFAPI/pnf/inc/pnf.h +++ b/nfapi/open-nFAPI/pnf/inc/pnf.h @@ -20,7 +20,6 @@ #include "nfapi_pnf_interface.h" -#define NFAPI_MAX_PACKED_MESSAGE_SIZE 32768 struct pnf_t { @@ -46,5 +45,15 @@ int pnf_send_message(pnf_t* pnf, uint8_t* msg, uint32_t msg_len, uint16_t stream nfapi_pnf_phy_config_t* nfapi_pnf_phy_config_find(nfapi_pnf_config_t* config, uint16_t phy_id); +void pnf_nr_handle_pnf_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen); +void pnf_nr_handle_pnf_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen); +void pnf_nr_handle_pnf_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen); +void pnf_handle_pnf_stop_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen); +void pnf_nr_handle_param_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen); +void pnf_nr_handle_config_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen); +void pnf_nr_handle_start_request(pnf_t* pnf, void *pRecvMsg, int recvMsgLen); +void pnf_nr_handle_stop_request(pnf_t* pnf, void* pRecvMsg, int recvMsgLen); + + #endif // _PNF_H_ diff --git a/nfapi/open-nFAPI/pnf/inc/pnf_p7.h b/nfapi/open-nFAPI/pnf/inc/pnf_p7.h index 49868bde8d..5805e07445 100644 --- a/nfapi/open-nFAPI/pnf/inc/pnf_p7.h +++ b/nfapi/open-nFAPI/pnf/inc/pnf_p7.h @@ -25,7 +25,6 @@ #include "nfapi_pnf_interface.h" -#define NFAPI_MAX_PACKED_MESSAGE_SIZE 32768 typedef struct { uint16_t dl_conf_ontime; diff --git a/nfapi/open-nFAPI/pnf/src/pnf.c b/nfapi/open-nFAPI/pnf/src/pnf.c index fd572cf77f..1c851ce277 100644 --- a/nfapi/open-nFAPI/pnf/src/pnf.c +++ b/nfapi/open-nFAPI/pnf/src/pnf.c @@ -49,7 +49,9 @@ #include "NR_MIB.h" #include "openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h" - +#ifdef ENABLE_WLS +#include "wls_integration/include/wls_pnf.h" +#endif #endif #define MAX_SCTP_STREAMS 16 diff --git a/nfapi/open-nFAPI/utils/nfapi_hex_parser.c b/nfapi/open-nFAPI/utils/nfapi_hex_parser.c index 342492ba92..a037f1221e 100644 --- a/nfapi/open-nFAPI/utils/nfapi_hex_parser.c +++ b/nfapi/open-nFAPI/utils/nfapi_hex_parser.c @@ -281,10 +281,9 @@ int main(int argc, char *argv[]) printf("\n"); AssertFatal(byte_count >= sizeof(fapi_message_header_t), "Read byte amount not enough to encode the header. Should have a minimum of %lu bytes, aborting...", sizeof(fapi_message_header_t)); uint8_t *ptr = hex_values; // Points to the first element of the array - uint8_t **msg_ptr = &ptr; // Pointer to the pointer fapi_message_header_t hdr = {.num_msg = 0, .opaque_handle = 0, .message_id = 0, .message_length = 0}; - fapi_nr_message_header_unpack(msg_ptr, NFAPI_HEADER_LENGTH, &hdr, sizeof(fapi_message_header_t), 0); + fapi_nr_message_header_unpack(ptr, NFAPI_HEADER_LENGTH, &hdr, sizeof(fapi_message_header_t), 0); printf("Decoded message %s message length 0x%02x\n", message_id_to_str(hdr.message_id), hdr.message_length); // Unpack the message diff --git a/nfapi/open-nFAPI/vnf/public_inc/nfapi_vnf_interface.h b/nfapi/open-nFAPI/vnf/public_inc/nfapi_vnf_interface.h index 54754fce05..b98a91e2ac 100644 --- a/nfapi/open-nFAPI/vnf/public_inc/nfapi_vnf_interface.h +++ b/nfapi/open-nFAPI/vnf/public_inc/nfapi_vnf_interface.h @@ -33,7 +33,6 @@ extern "C" { typedef struct vnf_t vnf_t; typedef struct vnf_p7_t vnf_p7_t; -#define NFAPI_MAX_PACKED_MESSAGE_SIZE 32768 /*! The nfapi VNF phy configuration information */