diff --git a/CMakeLists.txt b/CMakeLists.txt index f6e31180..b33f914b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,37 +5,44 @@ cmake_minimum_required(VERSION 3.5) set(TARGET_TYPE "freertos_idf" CACHE STRING "Type of build: 'linux', 'freertos_idf'") +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + file(TO_CMAKE_PATH "$ENV{IDF_PATH}" ENV_IDF_PATH) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") + if("${TARGET_TYPE}" STREQUAL "" OR "${TARGET_TYPE}" STREQUAL "freertos_idf") if(NOT "$ENV{IDF_PATH}" STREQUAL "") # Set a default target type. - if("${TARGET_TYPE}" STREQUAL "") - set(TARGET_TYPE "freertos_idf") - endif() + + set(TARGET_TYPE "freertos_idf") + set(ENV{TARGET_TYPE} "freertos_idf") message("Configuring: ESP-IDF build") include($ENV{IDF_PATH}/tools/cmake/project.cmake) add_compile_definitions(configUSE_POSIX_ERRNO=1) - add_compile_definitions( - -Wno-unused-but-set-variable - -Wno-unused-function - -Wno-unused-variable - -Wno-unused-parameter - ) - project(RINA_sensor) else() message(FATAL_ERROR "The 'freertos_idf' target needs the IDF_PATH environment variable to be defined") endif() + elseif (${TARGET_TYPE} STREQUAL "linux") project(RINA_sensor) + set(ENV{TARGET_TYPE} "linux") message("Configuring: POSIX build") - + include(lib.linux) + include(lib.common) include(CTest) + # Automagically find all the components in the source tree. + rs_scan_cmakelists() + + # Runs a sanity check on the dependencies and add all the required + # include paths to each libraries. + rs_resolve_dependencies() + add_compile_definitions(configUSE_POSIX_ERRNO=1) add_compile_options( @@ -60,504 +67,39 @@ elseif (${TARGET_TYPE} STREQUAL "linux") -include stdbool.h ) - set(CMAKE_VERBOSE_MAKEFILE ON) - - # set(CMAKE_C_COMPILER"/ugcc") - - # - # Set all include path variables here so as to avoid circular - # dependencies problem below. - # - set(CdapProto_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components/CdapProto/include") - set(configSensor_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components/configSensor/include") - set(configRINA_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components/configRINA/include") - set(Common_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components/Common/include") - set(ARP826_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components/ARP826/include") - set(BufferManagement_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components/BufferManagement/include") - set(EFCP_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components/EFCP/include") - set(IPCP_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components/IPCP/include") - set(NetworkInterface_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components/NetworkInterface/include") - set(NetworkInterface_MQ_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components/NetworkInterface/mq/include") - set(RINA_API_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components/RINA_API/include") - set(Rmt_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components/Rmt/include") - set(ShimIPCP_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components/ShimIPCP/include") - set(FlowAllocator_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components/FlowAllocator/include") - set(Ribd_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components/Ribd/include") - set(Enrollment_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components/Enrollment/include") - - set(mock_IPCP_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components_mocks/mock_IPCP/include") - set(mock_NetworkInterface_INCLUDES - "${CMAKE_CURRENT_SOURCE_DIR}/components_mocks/mock_NetworkInterface/include ") - set(mock_FlowAllocator_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components_mocks/mock_FlowAllocator/include") - set(mock_Ribd_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/components_mocks/mock_Ribd/include") - - # - # Portability layer, target specific - # - include("${CMAKE_CURRENT_SOURCE_DIR}/components/Portability/${TARGET_TYPE}/CMakeLists.txt") - - # - # Portability layer tests - # - include("${CMAKE_CURRENT_SOURCE_DIR}/components/Portability/test/CMakeLists.txt") - - # - # Mock objects - # - # FIXME: THIS IS BORING AND REPETITIVE, MOVE THAT ELSEWHERE! - # - set(mock_NetworkInterface_INCLUDES - "${CMAKE_CURRENT_SOURCE_DIR}/components_mocks/mock_NetworkInterface/include") - file(GLOB mock_NetworkInterface_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/components_mocks/mock_NetworkInterface/*.c" - ) - add_library(mock_NetworkInterface STATIC ${mock_NetworkInterface_SOURCES}) - target_include_directories(mock_NetworkInterface PUBLIC - ${mock_NetworkInterface_INCLUDES} - ${BufferManagement_INCLUDES} - ${Portability_INCLUDES} - ${IPCP_INCLUDES} - ${Common_INCLUDES} - ${configSensor_INCLUDES} - ) - - file(GLOB mock_IPCP_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/components_mocks/mock_IPCP/*.c" - ) - add_library(mock_IPCP STATIC ${mock_IPCP_SOURCES}) - target_include_directories(mock_IPCP PUBLIC - ${BufferManagement_INCLUDES} - ${Portability_INCLUDES} - ${IPCP_INCLUDES} - ) - - file(GLOB mock_RIBD_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/components_mocks/mock_Ribd/*.c" - ) - add_library(mock_Ribd STATIC ${mock_RIBD_SOURCES}) - target_include_directories(mock_Ribd PUBLIC - ${configSensor_INCLUDES} - ${Common_INCLUDES} - ${EFCP_INCLUDES} - ${BufferManagement_INCLUDES} - ${Portability_INCLUDES} - ${IPCP_INCLUDES} - ${Rmt_INCLUDES} - ${RINA_API_INCLUDES} - ) - - file(GLOB mock_FlowAllocator_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/components_mocks/mock_FlowAllocator/*.c" - ) - add_library(mock_FlowAllocator STATIC ${mock_FlowAllocator_SOURCES}) - target_include_directories(mock_FlowAllocator PUBLIC - ${configSensor_INCLUDES} - ${Common_INCLUDES} - ${EFCP_INCLUDES} - ${BufferManagement_INCLUDES} - ${Portability_INCLUDES} - ${IPCP_INCLUDES} - ${Rmt_INCLUDES} - ${RINA_API_INCLUDES} - ${Ribd_INCLUDES} - ) - - file(GLOB mock_EFCP_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/components_mocks/mock_EFCP/*.c" - ) - add_library(mock_EFCP STATIC ${mock_EFCP_SOURCES}) - target_include_directories(mock_EFCP PUBLIC - ${configSensor_INCLUDES} - ${Common_INCLUDES} - ${EFCP_INCLUDES} - ${BufferManagement_INCLUDES} - ${Portability_INCLUDES} - ${IPCP_INCLUDES} - ${Rmt_INCLUDES} - ${RINA_API_INCLUDES} - ) - - # - # Component: CDAP - # - file(GLOB CdapProto_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/components/CdapProto/*.c" - ) - add_library(CdapProto STATIC ${CdapProto_SOURCES}) - target_include_directories(CdapProto PUBLIC ${CdapProto_INCLUDES}) - set_target_properties(CdapProto PROPERTIES EXCLUDE_FROM_ALL TRUE) - - # - # Component: configSensor - # - file(GLOB configSensor_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/components/configSensor/*.c" - ) - add_library(configSensor STATIC ${configSensor_SOURCES}) - target_include_directories(configSensor PUBLIC ${configSensor_INCLUDES}) - set_target_properties(configSensor PROPERTIES EXCLUDE_FROM_ALL TRUE) - - # - # Component: Common - # - set(Common_DIR "${CMAKE_CURRENT_SOURCE_DIR}/components/Common") - set(Common_TEST_DIR "${Common_DIR}/test") - file(GLOB Common_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/components/Common/*.c" - ) - add_library(Common STATIC ${Common_SOURCES}) - target_include_directories(Common PUBLIC - ${Common_INCLUDES} - ${Portability_INCLUDES} - ${configSensor_INCLUDES} - ) - include("${Common_TEST_DIR}/CMakeLists.txt") - - # - # Component: BufferManagement - # - set(BufferManagement_DIR "${CMAKE_CURRENT_SOURCE_DIR}/components/BufferManagement") - set(BufferManagement_TEST_DIR "${BufferManagement_DIR}/test") - file(GLOB BufferManagement_SOURCES - "${BufferManagement_DIR}/*.c" - ) - add_library(BufferManagement STATIC ${BufferManagement_SOURCES}) - target_include_directories(BufferManagement PUBLIC - ${BufferManagement_INCLUDES} - ${configSensor_INCLUDES} - ${ARP826_INCLUDES} - ${Common_INCLUDES} - - # ${EFCP_INCLUDES} - ${IPCP_INCLUDES} - - # ${NetworkInterface_INCLUDES} - # ${Rmt_INCLUDES} - # ${ShimIPCP_INCLUDES} - ${Portability_INCLUDES} - ) - target_link_libraries(BufferManagement PUBLIC - ARP826 - Common - IPCP - portability - ) - include("${BufferManagement_TEST_DIR}/CMakeLists.txt") - - # - # Component: NetworkInterface (various) - # - set(NetworkInterface_DIR "${CMAKE_CURRENT_SOURCE_DIR}/components/NetworkInterface") - file(GLOB NetworkInterface_MQ_SOURCES - "${NetworkInterface_DIR}/mq/*.c" - ) - file(GLOB NetworkInterface_TAP_SOURCES - "${NetworkInterface_DIR}/linux_tap/*.c" - ) - add_library(NetworkInterface_MQ STATIC ${NetworkInterface_MQ_SOURCES}) - add_library(NetworkInterface_TAP STATIC ${NetworkInterface_TAP_SOURCES}) - set(NetworkInterface_Common_INCLUDES - ${Common_INCLUDES} - ${configRINA_INCLUDES} - ${BufferManagement_INCLUDES} - ${NetworkInterface_INCLUDES} - ${ARP826_INCLUDES} - ${IPCP_INCLUDES} - ${configSensor_INCLUDES} - ${Rmt_INCLUDES} - ${ShimIPCP_INCLUDES} - ${EFCP_INCLUDES} - ${Portability_INCLUDES} - ${RINA_API_INCLUDES} - ) - target_link_libraries(NetworkInterface_MQ PUBLIC - Common - ) - target_link_libraries(NetworkInterface_TAP PUBLIC - Common - ) - - target_include_directories(NetworkInterface_MQ PUBLIC - ${NetworkInterface_Common_INCLUDES} - ${NetworkInterface_MQ_INCLUDES} - ) - target_include_directories(NetworkInterface_TAP PUBLIC - ${NetworkInterface_Common_INCLUDES} - ) - include("${NetworkInterface_DIR}/test/CMakeLists.txt") - - # - # Component: ARP826 - # - set(ARP826_DIR "${CMAKE_CURRENT_SOURCE_DIR}/components/ARP826") - set(ARP826_TEST_DIR "${ARP826_DIR}/test") - file(GLOB ARP826_SOURCES "${ARP826_DIR}/*.c") - add_library(ARP826 STATIC ${ARP826_SOURCES}) - target_include_directories(ARP826 PUBLIC - ${configSensor_INCLUDES} - ${NetworkInterface_INCLUDES} - ${Common_INCLUDES} - ${BufferManagement_INCLUDES} - ${ARP826_INCLUDES} - ${IPCP_INCLUDES} - ${Portability_INCLUDES} - ${ShimIPCP_INCLUDES} - ) - target_link_libraries(ARP826 PUBLIC - Common - BufferManagement - IPCP - portability - ShimIPCP - ) - include("${ARP826_TEST_DIR}/CMakeLists.txt") - - # - # Component: Rmt - # - file(GLOB Rmt_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/components/Rmt/*.c" - ) - add_library(Rmt STATIC ${Rmt_SOURCES}) - target_include_directories(Rmt PUBLIC - ${configSensor_INCLUDES} - ${Common_INCLUDES} - ${ARP826_INCLUDES} - ${BufferManagement_INCLUDES} - ${Rmt_INCLUDES} - ${EFCP_INCLUDES} - ${Portability_INCLUDES} - ${IPCP_INCLUDES} - ) - target_link_libraries(Rmt PUBLIC - Common - BufferManagement - EFCP - portability - IPCP - ) - - # - # Component: EFCP - # - file(GLOB EFCP_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/components/EFCP/*.c" - ) - add_library(EFCP STATIC ${EFCP_SOURCES}) - target_include_directories(EFCP PUBLIC - ${Portability_INCLUDES} - ${Common_INCLUDES} - ${ARP826_INCLUDES} - ${IPCP_INCLUDES} - ${EFCP_INCLUDES} - ${Rmt_INCLUDES} - ${configSensor_INCLUDES} - ) - target_link_libraries(EFCP PUBLIC - portability - Common - ARP826 - IPCP - Rmt - ) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb3 -O0 -include stdbool.h") - # - # Component: ShimIPCP - # - set(ShimIPCP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/components/ShimIPCP") - set(ShimIPCP_TESTS_DIR "${ShimIPCP_DIR}/test") - file(GLOB ShimIPCP_SOURCES "${ShimIPCP_DIR}/*.c") - add_library(ShimIPCP STATIC ${ShimIPCP_SOURCES}) - target_include_directories(ShimIPCP PUBLIC - ${ShimIPCP_INCLUDES} - ${Common_INCLUDES} - ${Portability_INCLUDES} - ${configSensor_INCLUDES} - ${configRINA_INCLUDES} - ${ARP826_INCLUDES} - ${BufferManagement_INCLUDES} - ${EFCP_INCLUDES} - ${IPCP_INCLUDES} - ${NetworkInterface_INCLUDES} - ${Rmt_INCLUDES} - ) - target_link_libraries(ShimIPCP PUBLIC - Common - portability - ARP826 - BufferManagement - EFCP - IPCP - Rmt - ) - include("${ShimIPCP_TESTS_DIR}/CMakeLists.txt") + add_subdirectory(unity) + add_subdirectory(test_linux) - # - # Component: IPCP - # - set(IPCP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/components/IPCP") - set(IPCP_TESTS_DIR "${IPCP_DIR}/test") - set(IPCP_TEST_DIR "${IPCP_DIR}/test") - file(GLOB IPCP_SOURCES "${IPCP_DIR}/*.c") - add_library(IPCP STATIC ${IPCP_SOURCES}) - target_include_directories(IPCP PUBLIC - ${configSensor_INCLUDES} - ${configRINA_INCLUDES} - ${ARP826_INCLUDES} - ${NetworkInterface_INCLUDES} - ${ShimIPCP_INCLUDES} - ${BufferManagement_INCLUDES} - ${IPCP_INCLUDES} - ${Rmt_INCLUDES} - ${EFCP_INCLUDES} - ${Portability_INCLUDES} - ${Common_INCLUDES} - ${RINA_API_INCLUDES} - ${Ribd_INCLUDES} - ${Enrollment_INCLUDES} - ${Ribd_INCLUDES} - ${FlowAllocator_INCLUDES} - ) - target_link_libraries(IPCP PUBLIC + # Declares which components needs to be built in the shared library. + set(shared_library_components ARP826 - ShimIPCP BufferManagement - Rmt - EFCP - portability - Common - Ribd - Enrollment - Ribd - FlowAllocator - RINA_API - ) - include("${IPCP_TESTS_DIR}/CMakeLists.txt") - - # - # Component: Ribd - # - set(Ribd_DIR "${CMAKE_CURRENT_SOURCE_DIR}/components/Ribd") - set(Ribd_TEST_DIR "${Ribd_DIR}/test") - file(GLOB Ribd_SOURCES "${Ribd_DIR}/*.c") - add_library(Ribd STATIC ${Ribd_SOURCES}) - target_include_directories(Ribd PUBLIC - ${CdapProto_INCLUDES} - ${BufferManagement_INCLUDES} - ${configRINA_INCLUDES} - ${configSensor_INCLUDES} - ${IPCP_INCLUDES} - ${Ribd_INCLUDES} - ${Portability_INCLUDES} - ${Common_INCLUDES} - ${Enrollment_INCLUDES} - ${EFCP_INCLUDES} - ${Rmt_INCLUDES} - ${RINA_API_INCLUDES} - ${FlowAllocator_INCLUDES} - ) - target_link_libraries(Ribd PUBLIC CdapProto - BufferManagement - IPCP - portability Common - Enrollment - EFCP - Rmt - FlowAllocator - ) - include("${Ribd_TEST_DIR}/CMakeLists.txt") - - # - # Component: FlowAllocator - # - file(GLOB FlowAllocator_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/components/FlowAllocator/*.c" - ) - add_library(FlowAllocator STATIC ${FlowAllocator_SOURCES}) - target_include_directories(FlowAllocator PUBLIC - ${FlowAllocator_INCLUDES} - ${configSensor_INCLUDES} - ${configRINA_INCLUDES} - ${Common_INCLUDES} - ${Portability_INCLUDES} - ${EFCP_INCLUDES} - ${ARP826_INCLUDES} - ${CdapProto_INCLUDES} - ${Enrollment_INCLUDES} - ${IPCP_INCLUDES} - ${Ribd_INCLUDES} - ${RINA_API_INCLUDES} - ${Rmt_INCLUDES} - ) - target_link_libraries(FlowAllocator - Common - portability + configRINA + configSensor EFCP - ARP826 - CdapProto Enrollment - IPCP - Ribd - Rmt - ) - - # - # Component: Enrollment - # - file(GLOB Enrollment_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/components/Enrollment/*.c" - ) - add_library(Enrollment STATIC ${Enrollment_SOURCES}) - target_include_directories(Enrollment PUBLIC - ${configSensor_INCLUDES} - ${configRINA_INCLUDES} - ${Common_INCLUDES} - ${Portability_INCLUDES} - ${ARP826_INCLUDES} - ${CdapProto_INCLUDES} - ${Enrollment_INCLUDES} - ${FlowAllocator_INCLUDES} - ${IPCP_INCLUDES} - ${Ribd_INCLUDES} - ${RINA_API_INCLUDES} - ${Rmt_INCLUDES} - ) - target_link_libraries(Enrollment - Common - portability - ARP826 - CdapProto FlowAllocator IPCP + Portability Ribd + RINA_API Rmt - ) - - # - # Component: RINA API - # - file(GLOB RINA_API_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/components/RINA_API/*.c" - ) - add_library(RINA_API STATIC ${RINA_API_SOURCES}) - target_include_directories(RINA_API PUBLIC - ${configSensor_INCLUDES} - ${configRINA_INCLUDES} - ${Common_INCLUDES} - ${Portability_INCLUDES} - ) - target_link_libraries(RINA_API - Common - portability - BufferManagement - ) - - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb3 -O0 -include stdbool.h") - - add_subdirectory(unity) - add_subdirectory(test_linux) + ShimIPCP) + + # Add all components objects in the shared library. + foreach(component IN LISTS shared_library_components) + list(APPEND shared_library_objects $) + rs_get_component_include_dirs(${component} component_includes) + list(APPEND shared_library_includes ${component_includes}) + endforeach() + + # Declare the shared library. + add_library(RINA SHARED ${shared_library_objects}) + target_include_directories(RINA PUBLIC ${shared_library_includes}) else() message("Unknown target ${TARGET_TYPE}") diff --git a/cmake/lib.common.cmake b/cmake/lib.common.cmake new file mode 100644 index 00000000..38c326fc --- /dev/null +++ b/cmake/lib.common.cmake @@ -0,0 +1,13 @@ +macro(rs_scan_cmakelists) + file(GLOB component_dirs ${CMAKE_SOURCE_DIR}/components/*) + file(GLOB mock_component_dirs ${CMAKE_SOURCE_DIR}/components_mocks/*) + list(APPEND component_dirs ${mock_component_dirs}) + foreach(component_dir IN LISTS component_dirs) + message("Looking in ${component_dir}") + set(cmakelist "${component_dir}/CMakeLists.txt") + if(EXISTS ${cmakelist}) + message("Including ${cmakelist}") + include(${cmakelist}) + endif() + endforeach() +endmacro() diff --git a/cmake/lib.linux.cmake b/cmake/lib.linux.cmake new file mode 100644 index 00000000..05cdee05 --- /dev/null +++ b/cmake/lib.linux.cmake @@ -0,0 +1,182 @@ +macro(_rs_add_component component_name) + get_property(prop_components GLOBAL PROPERTY _RS_COMPONENTS) + list(APPEND prop_components ${component_name}) + set_property(GLOBAL PROPERTY _RS_COMPONENTS ${prop_components}) +endmacro() + +macro(_rs_set_component_data component_name data value) + set(prop_name _RS_COMPONENTS_${component_name}_${data}) + set_property(GLOBAL PROPERTY ${prop_name} ${value}) +endmacro() + +macro(_rs_get_component_data component_name data var) + set(prop_name _RS_COMPONENTS_${component_name}_${data}) + get_property(${var} GLOBAL PROPERTY ${prop_name}) +endmacro() + +macro(rs_get_component_include_dirs component_name var) + _rs_get_component_data(${component_name} INCLUDES ${var}) +endmacro() + +function(rs_component component_name) + set(single_value TEST_DIR) + set(multi_values SRCS INCLUDES REQUIRES) + cmake_parse_arguments(_ "${options}" "${single_value}" "${multi_values}" ${ARGN}) + + if(DEFINED __SRCS) + # Plain static library + set(${component_name}_SOURCES) + + foreach(src IN LISTS __SRCS) + set(file ${CMAKE_CURRENT_LIST_DIR}/${src}) + if(EXISTS ${file}) + # If it's a file that exists, add it as-is. + list(APPEND ${component_name}_SOURCES ${file}) + else() + # If it's not a file, assume it's globbing patern. + set(files) + # Execute the globbing pattern + file(GLOB files ${src}) + # Append the result to the list of source files for this + # target. + list(APPEND ${component_name}_SOURCES ${files}) + endif() + endforeach() + + # We're making OBJECT libraries because CMake doesn't make it + # super easy link static libraries together as a shared library. + add_library(${component_name} OBJECT ${${component_name}_SOURCES}) + + # Add the locally defined include directories. + target_include_directories(${component_name} PUBLIC ${__INCLUDES}) + + # Save the list of include directories for resolving dependencies. + _rs_set_component_data(${component_name} INCLUDES "${__INCLUDES}") + else() + # Include-only component + + add_library(${component_name} INTERFACE) + target_include_directories(${component_name} INTERFACE ${__INCLUDES}) + + # Save the list of include directories for resolving dependencies. + _rs_set_component_data(${component_name} INCLUDES "${__INCLUDES}") + endif() + + _rs_add_component(${component_name}) + + if(DEFINED __REQUIRES) + set(comp_requirements) + foreach(req_name ${__REQUIRES}) + list(APPEND comp_requirements ${req_name}) + endforeach() + + _rs_set_component_data(${component_name} REQUIRES "${comp_requirements}") + endif() + + if(DEFINED __TEST_DIR) + include("${__TEST_DIR}/CMakeLists.txt" OPTIONAL) + endif() +endfunction() + +function(rs_plain_component component_name) + set(single_value DIR TEST_DIR) + set(multi_values REQUIRES) + cmake_parse_arguments(_ "${options}" "${single_value}" "${multi_values}" ${ARGN}) + rs_component(${component_name} + SRCS ${__DIR}/*.c + INCLUDES ${__DIR}/include + TEST_DIR ${__TEST_DIR} + REQUIRES ${__REQUIRES}) +endfunction() + +function(rs_include_component component_name) + set(single_value DIR TEST_DIR) + set(multi_values REQUIRES) + cmake_parse_arguments(_ "${options}" "${single_value}" "${multi_values}" ${ARGN}) + rs_component(${component_name} + INCLUDES ${__DIR}/include + TEST_DIR ${__TEST_DIR} + REQUIRES ${__REQUIRES}) +endfunction() + +function(_rs_get_dep_list component_name target_var) + _rs_get_component_data(${component_name} REQUIRES component_req) + foreach(req IN LISTS component_req) + list(APPEND ${target_var} ${req}) + _rs_get_dep_list(${req} ${target_var}) + endforeach() +endfunction() + +function(_rs_add_includes_from_component component_name from_component) + set(seen_deps) + set(req_list) + + # Add the include path from the direct dependency + _rs_get_component_data(${from_component} INCLUDES from_includes) + target_include_directories(${component_name} PRIVATE ${from_includes}) + + # Make a list of ALL the include paths we need to add. + _rs_get_component_data(${from_component} REQUIRES req_list) + foreach(req IN LISTS req_list) + if(NOT ${req} IN_LIST seen_deps) + list(APPEND seen_deps ${req}) + _rs_get_component_data(${req} REQUIRES more_reqs) + list(APPEND req_list ${more_reqs}) + endif() + endforeach() + + # Add all the include paths + foreach(req IN LISTS req_list) + _rs_get_component_data(${req} INCLUDES req_includes) + target_include_directories(${component_name} PUBLIC ${req_includes}) + endforeach() +endfunction() + +function(rs_resolve_dependencies) + # Get the list of components + get_property(components GLOBAL PROPERTY _RS_COMPONENTS) + + # Iterate through all components to make sure that their dependency + # list is sound. + foreach(component_name ${components}) + message("Resolving dependencies of ${component_name}") + + _rs_get_component_data(${component_name} REQUIRES component_req_list) + + foreach(component_req IN LISTS component_req_list) + if(${component_req} IN_LIST components) + message("... requires ${component_req}: OK") + _rs_add_includes_from_component(${component_name} ${component_req}) + else() + message(FATAL_ERROR "... requires ${component_req}: NOT FOUND") + endif() + endforeach() + endforeach() +endfunction() + +# +# ESP-IDF compatibility function. +# +# This does not support everything that the ESP-IDF build system has +# to offer. +# +function(idf_component_register) + set(single_value DIR) + set(multi_values SRCS INCLUDE_DIRS REQUIRES) + cmake_parse_arguments(_ "${options}" "${single_value}" "${multi_values}" ${ARGN}) + + cmake_path(GET CMAKE_CURRENT_LIST_DIR FILENAME comp_name) + + # Automatically add the 'test' directory as TEST_DIR if it exists. + set(test_dir ${CMAKE_CURRENT_LIST_DIR}/test) + if(NOT EXISTS ${test_dir}) + set(test_dir "") + endif() + + # Call into our own component functions + rs_component(${comp_name} + SRCS ${CMAKE_CURRENT_LIST_DIR}/${__SRCS} + INCLUDES ${CMAKE_CURRENT_LIST_DIR}/${__INCLUDE_DIRS} + TEST_DIR ${test_dir} + REQUIRES ${__REQUIRES}) +endfunction() diff --git a/components/ARP826/ARP826.c b/components/ARP826/ARP826.c index 516c64d2..af753850 100644 --- a/components/ARP826/ARP826.c +++ b/components/ARP826/ARP826.c @@ -135,7 +135,7 @@ bool_t xARPAddressGPAShrink(gpa_t *pxGpa, uint8_t ucFiller) if (pucPosition >= pxGpa->pucAddress + pxGpa->uxLength) { LOGI(TAG_ARP, "GPA doesn't need to be shrinked ..."); - return false; + return true; } uxLength = pucPosition - pxGpa->pucAddress; @@ -353,7 +353,7 @@ bool_t vARPSendRequest(gpa_t *pxTpa, gpa_t *pxSpa, gha_t *pxSha) /* Send a message to the IPCP-task to send this ARP packet. */ xSendEvent.eEventType = eNetworkTxEvent; - xSendEvent.pvData = pxNetworkBuffer; + xSendEvent.xData.PV = (void *)pxNetworkBuffer; if (!xSendEventStructToIPCPTask(&xSendEvent, 1000)) { @@ -598,7 +598,7 @@ eFrameProcessingResult_t eARPProcessPacket(ARPPacket_t *const pxARPFrame) pxTmpTha = pxCreateGHA(MAC_ADDR_802_3, (MACAddress_t *)ucTha); // vARPPrintCache(); - if (xARPAddressGPAShrink(pxTmpSpa, 0x00)) + if (!xARPAddressGPAShrink(pxTmpSpa, 0x00)) { LOGE(TAG_ARP, "Problems parsing the source GPA"); vGPADestroy(pxTmpSpa); @@ -607,7 +607,7 @@ eFrameProcessingResult_t eARPProcessPacket(ARPPacket_t *const pxARPFrame) vGHADestroy(pxTmpTha); return eReturn; } - if (xARPAddressGPAShrink(pxTmpTpa, 0x00)) + if (!xARPAddressGPAShrink(pxTmpTpa, 0x00)) { LOGE(TAG_ARP, "Got problems parsing the target GPA"); vGPADestroy(pxTmpSpa); @@ -625,11 +625,19 @@ eFrameProcessingResult_t eARPProcessPacket(ARPPacket_t *const pxARPFrame) // handle = pvPortMalloc(sizeof(*handle)); // Check Cache by Address - LOGE(TAG_ARP, "ARP_REQUEST ptype 0x%04X", usOperation); + LOGI(TAG_ARP, "ARP_REQUEST for protocol type 0x%04X", usOperation); if (eARPLookupGPA(pxTmpSpa) == eARPCacheMiss) { - LOGE(TAG_ARP, "I don't have a table for ptype 0x%04X", usPtype); +#ifndef NDEBUG + char *psAddr; + + RsAssert((psAddr = xGPAAddressToString(pxTmpSpa)) != NULL); + LOGE(TAG_ARP, "Nothing found for entry %s for protocol type 0x%04X", psAddr, usPtype); + vRsMemFree(psAddr); +#else + LOGE(TAG_ARP, "Nothing found for protocol type 0x%04X", usPtype); +#endif vGPADestroy(pxTmpSpa); vGPADestroy(pxTmpTpa); vGHADestroy(pxTmpSha); @@ -712,12 +720,21 @@ eARPLookupResult_t eARPLookupGPA(const gpa_t *pxGpaToLookup) num_t x; eARPLookupResult_t eReturn = eARPCacheMiss; - LOGI(TAG_ARP, "eARPLookupGPA loop start"); - /* Loop through each entry in the ARP cache. */ for (x = 0; x < ARP_CACHE_ENTRIES; x++) { - LOGI(TAG_ARP, "eARPLookupGPA loop: %d", x); + /* Skip empty entries. */ + if (xARPCache[x].ucAge == 0) + continue; + +#ifndef NDEBUG + string_t pcLoopAddr; + + RsAssert((pcLoopAddr = xGPAAddressToString(xARPCache[x].pxProtocolAddress)) != NULL); + LOGD(TAG_ARP, "eARPLookupGPA -> %s", pcLoopAddr); + vRsMemFree(pcLoopAddr); +#endif + if (xGPACmp(xARPCache[x].pxProtocolAddress, pxGpaToLookup)) { /* A matching valid entry was found. */ @@ -879,6 +896,20 @@ void vARPInitCache(void) LOGI(TAG_ARP, "ARP CACHE Initialized"); } +void prvARPPrintCacheItem(int nIndex) +{ + LOGD(TAG_ARP, "Arp Entry %i: %3d - %s - %02x:%02x:%02x:%02x:%02x:%02x", + nIndex, + xARPCache[nIndex].ucAge, + xARPCache[nIndex].pxProtocolAddress->pucAddress, + xARPCache[nIndex].pxMACAddress->xAddress.ucBytes[0], + xARPCache[nIndex].pxMACAddress->xAddress.ucBytes[1], + xARPCache[nIndex].pxMACAddress->xAddress.ucBytes[2], + xARPCache[nIndex].pxMACAddress->xAddress.ucBytes[3], + xARPCache[nIndex].pxMACAddress->xAddress.ucBytes[4], + xARPCache[nIndex].pxMACAddress->xAddress.ucBytes[5]); +} + void vARPPrintCache(void) { num_t x, xCount = 0; @@ -886,18 +917,7 @@ void vARPPrintCache(void) for (x = 0; x < ARP_CACHE_ENTRIES; x++) { if ((xARPCache[x].pxProtocolAddress->pucAddress != 0UL) && (xARPCache[x].ucValid != 0)) - { - LOGI(TAG_ARP, "Arp Entry %i: %3d - %s - %02x:%02x:%02x:%02x:%02x:%02x\n", - x, - xARPCache[x].ucAge, - xARPCache[x].pxProtocolAddress->pucAddress, - xARPCache[x].pxMACAddress->xAddress.ucBytes[0], - xARPCache[x].pxMACAddress->xAddress.ucBytes[1], - xARPCache[x].pxMACAddress->xAddress.ucBytes[2], - xARPCache[x].pxMACAddress->xAddress.ucBytes[3], - xARPCache[x].pxMACAddress->xAddress.ucBytes[4], - xARPCache[x].pxMACAddress->xAddress.ucBytes[5]); - } + prvARPPrintCacheItem(x); xCount++; } LOGI(TAG_ARP, "Arp has %d entries\n", xCount); @@ -933,7 +953,11 @@ void vARPAddCacheEntry(struct rinarpHandle_t *pxHandle, uint8_t ucAge) xARPCache[x].pxMACAddress = pxHandle->pxHa; xARPCache[x].ucAge = ucAge; xARPCache[x].ucValid = 1; - LOGD(TAG_ARP, "ARP Entry successful"); + +#ifndef NDEBUG + prvARPPrintCacheItem(x); + LOGD(TAG_ARP, "ARP Entry added successfully"); +#endif break; } diff --git a/components/ARP826/CMakeLists.txt b/components/ARP826/CMakeLists.txt index 99f49ce4..b3869779 100644 --- a/components/ARP826/CMakeLists.txt +++ b/components/ARP826/CMakeLists.txt @@ -1,4 +1,16 @@ -idf_component_register(SRCS "ARP826.c" - INCLUDE_DIRS "include" - REQUIRES NetworkInterface ShimIPCP BufferManagement configSensor Common Portability RINA_API) +set(reqs + EFCP + Rmt + NetworkInterface + ShimIPCP + BufferManagement + configSensor + Common + Portability + RINA_API + IPCP) +idf_component_register( + SRCS "ARP826.c" + INCLUDE_DIRS "include" + REQUIRES ${reqs}) diff --git a/components/ARP826/test/CMakeLists.txt b/components/ARP826/test/CMakeLists.txt index da4fec81..6cdc25f3 100644 --- a/components/ARP826/test/CMakeLists.txt +++ b/components/ARP826/test/CMakeLists.txt @@ -5,7 +5,7 @@ if("$ENV{TARGET_TYPE}" STREQUAL "freertos_idf") else() add_executable(test_arp826 "${CMAKE_CURRENT_LIST_DIR}/test_arp826.c") target_link_libraries(test_arp826 PUBLIC - ARP826 + RINA NetworkInterface_MQ unity ) diff --git a/components/BufferManagement/CMakeLists.txt b/components/BufferManagement/CMakeLists.txt index 76ef7726..b0154a01 100644 --- a/components/BufferManagement/CMakeLists.txt +++ b/components/BufferManagement/CMakeLists.txt @@ -1,4 +1,20 @@ -idf_component_register(SRCS "BufferManagement.c" - INCLUDE_DIRS "include" - REQUIRES ShimIPCP NetworkInterface ARP826 Portability FreeRTOS-Plus-POSIX) +set(requirements + ShimIPCP + NetworkInterface + ARP826 + Portability +) + +# The FreeRTOS-Plus-POSIX module is only necessary for ESP-IDF +# on-device builds. +if("$ENV{TARGET_TYPE}" STREQUAL "freertos_idf") + list(APPEND requirements FreeRTOS-Plus-POSIX) +endif() + +idf_component_register( + SRCS "BufferManagement.c" + INCLUDE_DIRS "include" + REQUIRES ${requirements} +) + diff --git a/components/BufferManagement/include/unity_test_runner.h b/components/BufferManagement/include/unity_test_runner.h deleted file mode 100644 index 6d942e6c..00000000 --- a/components/BufferManagement/include/unity_test_runner.h +++ /dev/null @@ -1,176 +0,0 @@ -// Copyright 2016-2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 -// -// 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. -#pragma once - -#include -#include - -// This file gets included from unity.h via unity_internals.h via unity_config.h -// It is inside #ifdef __cplusplus / extern "C" block, so we can -// only use C features here - -// Define helpers to register test cases from multiple files -#define UNITY_EXPAND2(a, b) a ## b -#define UNITY_EXPAND(a, b) UNITY_EXPAND2(a, b) -#define UNITY_TEST_UID(what) UNITY_EXPAND(what, __LINE__) - -#define UNITY_TEST_REG_HELPER reg_helper ## UNITY_TEST_UID -#define UNITY_TEST_DESC_UID desc ## UNITY_TEST_UID - - -// get count of __VA_ARGS__ -#define PP_NARG(...) \ - PP_NARG_(__VA_ARGS__,PP_RSEQ_N()) -#define PP_NARG_(...) \ - PP_ARG_N(__VA_ARGS__) -#define PP_ARG_N( \ - _1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N -#define PP_RSEQ_N() 9,8,7,6,5,4,3,2,1,0 - -// support max 5 test func now -#define FN_NAME_SET_1(a) {#a} -#define FN_NAME_SET_2(a, b) {#a, #b} -#define FN_NAME_SET_3(a, b, c) {#a, #b, #c} -#define FN_NAME_SET_4(a, b, c, d) {#a, #b, #c, #d} -#define FN_NAME_SET_5(a, b, c, d, e) {#a, #b, #c, #d, #e} - -#define FN_NAME_SET2(n) FN_NAME_SET_##n -#define FN_NAME_SET(n, ...) FN_NAME_SET2(n)(__VA_ARGS__) - -#define UNITY_TEST_FN_SET(...) \ - static test_func UNITY_TEST_UID(test_functions)[] = {__VA_ARGS__}; \ - static const char* UNITY_TEST_UID(test_fn_name)[] = FN_NAME_SET(PP_NARG(__VA_ARGS__), __VA_ARGS__) - - -typedef void (* test_func)(void); - -typedef struct test_desc_t -{ - const char* name; - const char* desc; - test_func* fn; - const char* file; - int line; - uint8_t test_fn_count; - const char ** test_fn_name; - struct test_desc_t* next; -} test_desc_t; - -void unity_testcase_register(test_desc_t* desc); - - -/* Test case macro, a-la CATCH framework. - First argument is a free-form description, - second argument is (by convention) a list of identifiers, each one in square brackets. - Identifiers are used to group related tests, or tests with specific properties. - Use like: - - TEST_CASE("Frobnicator forbnicates", "[frobnicator][rom]") - { - // test goes here - } -*/ - -#define TEST_CASE(name_, desc_) \ - static void UNITY_TEST_UID(test_func_) (void); \ - static void __attribute__((constructor)) UNITY_TEST_UID(test_reg_helper_) (void) \ - { \ - static test_func test_fn_[] = {&UNITY_TEST_UID(test_func_)}; \ - static test_desc_t UNITY_TEST_UID(test_desc_) = { \ - .name = name_, \ - .desc = desc_, \ - .fn = test_fn_, \ - .file = __FILE__, \ - .line = __LINE__, \ - .test_fn_count = 1, \ - .test_fn_name = NULL, \ - .next = NULL \ - }; \ - unity_testcase_register( & UNITY_TEST_UID(test_desc_) ); \ - }\ - static void UNITY_TEST_UID(test_func_) (void) - - -/* - * Multiple stages test cases will handle the case that test steps are separated by DUT reset. - * e.g: we want to verify some function after SW reset, WDT reset or deep sleep reset. - * - * First argument is a free-form description, - * second argument is (by convention) a list of identifiers, each one in square brackets. - * subsequent arguments are names test functions separated by reset. - * e.g: - * TEST_CASE_MULTIPLE_STAGES("run light sleep after deep sleep","[sleep]", goto_deepsleep, light_sleep_after_deep_sleep_wakeup); - * */ - -#define TEST_CASE_MULTIPLE_STAGES(name_, desc_, ...) \ - UNITY_TEST_FN_SET(__VA_ARGS__); \ - static void __attribute__((constructor)) UNITY_TEST_UID(test_reg_helper_) (void) \ - { \ - static test_desc_t UNITY_TEST_UID(test_desc_) = { \ - .name = name_, \ - .desc = desc_"[multi_stage]", \ - .fn = UNITY_TEST_UID(test_functions), \ - .file = __FILE__, \ - .line = __LINE__, \ - .test_fn_count = PP_NARG(__VA_ARGS__), \ - .test_fn_name = UNITY_TEST_UID(test_fn_name), \ - .next = NULL \ - }; \ - unity_testcase_register( & UNITY_TEST_UID(test_desc_) ); \ - } - - - -/* - * First argument is a free-form description, - * second argument is (by convention) a list of identifiers, each one in square brackets. - * subsequent arguments are names of test functions for different DUTs - * e.g: - * TEST_CASE_MULTIPLE_DEVICES("master and slave spi","[spi][test_env=UT_T2_1]", master_test, slave_test); - * */ - -#define TEST_CASE_MULTIPLE_DEVICES(name_, desc_, ...) \ - UNITY_TEST_FN_SET(__VA_ARGS__); \ - static void __attribute__((constructor)) UNITY_TEST_UID(test_reg_helper_) (void) \ - { \ - static test_desc_t UNITY_TEST_UID(test_desc_) = { \ - .name = name_, \ - .desc = desc_"[multi_device]", \ - .fn = UNITY_TEST_UID(test_functions), \ - .file = __FILE__, \ - .line = __LINE__, \ - .test_fn_count = PP_NARG(__VA_ARGS__), \ - .test_fn_name = UNITY_TEST_UID(test_fn_name), \ - .next = NULL \ - }; \ - unity_testcase_register( & UNITY_TEST_UID(test_desc_) ); \ - } - -/** - * Note: initialization of test_desc_t fields above has to be done exactly - * in the same order as the fields are declared in the structure. - * Otherwise the initializer will not be valid in C++ (which doesn't - * support designated initializers). G++ can parse the syntax, but - * field names are treated as annotations and don't affect initialization - * order. Also make sure all the fields are initialized. - */ - -void unity_run_test_by_name(const char *name); - -void unity_run_tests_by_tag(const char *tag, bool invert); - -void unity_run_all_tests(void); - -void unity_run_menu(void); - diff --git a/components/BufferManagement/test/CMakeLists.txt b/components/BufferManagement/test/CMakeLists.txt index fe2d5427..e89f8141 100644 --- a/components/BufferManagement/test/CMakeLists.txt +++ b/components/BufferManagement/test/CMakeLists.txt @@ -5,8 +5,8 @@ if("$ENV{TARGET_TYPE}" STREQUAL "freertos_idf") else() add_executable(test_buffer_management "${CMAKE_CURRENT_LIST_DIR}/test_buffer_management.c") target_link_libraries(test_buffer_management - BufferManagement - portability + RINA + NetworkInterface_MQ pthread unity rt diff --git a/components/CdapProto/CMakeLists.txt b/components/CdapProto/CMakeLists.txt index a7ccda9c..04042d19 100644 --- a/components/CdapProto/CMakeLists.txt +++ b/components/CdapProto/CMakeLists.txt @@ -1,3 +1,19 @@ -idf_component_register(SRCS "FlowMessage.pb.c" "ApplicationProcessNamingInfoMessage.pb.c" "QoSSpecification.pb.c" "PolicyDescriptorMessage.pb.c" "ConnectionPoliciesMessage.pb.c" "CommonMessages.pb.c" "CDAP.pb.c" "pb_common.c" "pb_decode.c" "pb_encode.c" "EnrollmentInformationMessage.pb.c" "NeighborMessage.pb.c" - INCLUDE_DIRS "include") +set(srcs + "FlowMessage.pb.c" + "ApplicationProcessNamingInfoMessage.pb.c" + "QoSSpecification.pb.c" + "PolicyDescriptorMessage.pb.c" + "ConnectionPoliciesMessage.pb.c" + "CommonMessages.pb.c" + "CDAP.pb.c" + "pb_common.c" + "pb_decode.c" + "pb_encode.c" + "EnrollmentInformationMessage.pb.c" + "NeighborMessage.pb.c") + +idf_component_register( + SRCS ${srcs} + INCLUDE_DIRS "include") + diff --git a/components/Common/CMakeLists.txt b/components/Common/CMakeLists.txt index cdb344f7..8e692516 100644 --- a/components/Common/CMakeLists.txt +++ b/components/Common/CMakeLists.txt @@ -1,3 +1,4 @@ -idf_component_register(SRCS "rsrc.c" "rina_name.c" "rina_gpha.c" "rina_ids.c" "num_mgr.c" "mac.c" "list.c" - INCLUDE_DIRS "include" - REQUIRES Portability configSensor) +idf_component_register( + SRCS "rsrc.c" "rina_name.c" "rina_gpha.c" "rina_ids.c" "num_mgr.c" "mac.c" "list.c" + INCLUDE_DIRS "include" + REQUIRES Portability configSensor) diff --git a/components/Common/rina_gpha.c b/components/Common/rina_gpha.c index 824bc8c8..35b10f50 100644 --- a/components/Common/rina_gpha.c +++ b/components/Common/rina_gpha.c @@ -25,9 +25,6 @@ char *xGPAAddressToString(const gpa_t *pxGpa) p = tmp + pxGpa->uxLength; *(p) = '\0'; - LOGE(TAG_ARP, "GPA:%s", pxGpa->pucAddress); - LOGE(TAG_ARP, "GPA:%s", tmp); - return tmp; } diff --git a/components/Common/test/CMakeLists.txt b/components/Common/test/CMakeLists.txt index 654972f5..ef4c0118 100644 --- a/components/Common/test/CMakeLists.txt +++ b/components/Common/test/CMakeLists.txt @@ -5,43 +5,49 @@ if("$ENV{TARGET_TYPE}" STREQUAL "freertos_idf") else() add_executable(test_lists "${CMAKE_CURRENT_LIST_DIR}/test_lists.c") target_link_libraries(test_lists - Common - portability + RINA + NetworkInterface_MQ + Portability unity ) add_executable(test_rina_name "${CMAKE_CURRENT_LIST_DIR}/test_rina_name.c") target_link_libraries(test_rina_name - Common - portability + RINA + NetworkInterface_MQ + Portability unity ) add_executable(test_rina_gpha "${CMAKE_CURRENT_LIST_DIR}/test_rina_gpha.c") target_link_libraries(test_rina_gpha - Common - portability + RINA + NetworkInterface_MQ + Portability unity ) add_executable(test_bit_array "${CMAKE_CURRENT_LIST_DIR}/test_bit_array.c") target_link_libraries(test_bit_array - Common - portability + RINA + NetworkInterface_MQ + Portability unity ) add_executable(test_num_mgr "${CMAKE_CURRENT_LIST_DIR}/test_num_mgr.c") target_link_libraries(test_num_mgr - Common - portability + RINA + NetworkInterface_MQ + Portability unity ) add_executable(test_ids "${CMAKE_CURRENT_LIST_DIR}/test_ids.c") target_link_libraries(test_ids - Common - portability + RINA + NetworkInterface_MQ + Portability unity ) diff --git a/components/EFCP/CMakeLists.txt b/components/EFCP/CMakeLists.txt index 8638f393..45456e42 100644 --- a/components/EFCP/CMakeLists.txt +++ b/components/EFCP/CMakeLists.txt @@ -1,16 +1,4 @@ -idf_component_register(SRCS "connection.c" "delim.c" "EFCP.c" "dtp.c" "delim.c" - INCLUDE_DIRS "include" - REQUIRES IPCP Rmt FlowAllocator Portability) - -if("$ENV{USE_MOCKS}" STREQUAL "true") - target_include_directories(${COMPONENT_LIB} BEFORE PUBLIC - "${CMAKE_SOURCE_DIR}/../components_mocks/mock_FlowAllocator/include" - ) - - # Per https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/build-system.html#advanced-workaround-undefined-symbols - # - # I tried this randomly to fix a link error and it kind of magically - # worked so I'm leaving that here. I don't claim to understand the - # problem. - target_link_libraries(${COMPONENT_LIB} INTERFACE "-u mock_FlowAllocator_xFlowAllocatorDuPost") -endif() +idf_component_register( + SRCS "connection.c" "delim.c" "EFCP.c" "dtp.c" "delim.c" + INCLUDE_DIRS "include" + REQUIRES IPCP Rmt FlowAllocator Portability) diff --git a/components/Enrollment/CMakeLists.txt b/components/Enrollment/CMakeLists.txt index 042ff0e4..6bdce6d7 100644 --- a/components/Enrollment/CMakeLists.txt +++ b/components/Enrollment/CMakeLists.txt @@ -1,9 +1,4 @@ -idf_component_register(SRCS "SerdesMsg.c" "Enrollment.c" "SerdesMsg" - INCLUDE_DIRS "include" - REQUIRES IPCP BufferManagement Ribd CdapProto FlowAllocator) - -if("$ENV{USE_MOCKS}" STREQUAL "true") - target_include_directories(${COMPONENT_LIB} BEFORE PUBLIC - "${CMAKE_SOURCE_DIR}/../components_mocks/mock_Ribd/include" - ) -endif() +idf_component_register( + SRCS "SerdesMsg.c" "Enrollment.c" + INCLUDE_DIRS "include" + REQUIRES IPCP BufferManagement Ribd CdapProto FlowAllocator) diff --git a/components/FlowAllocator/CMakeLists.txt b/components/FlowAllocator/CMakeLists.txt index 1c26d5e6..ad4f54fb 100644 --- a/components/FlowAllocator/CMakeLists.txt +++ b/components/FlowAllocator/CMakeLists.txt @@ -1,9 +1,4 @@ -idf_component_register(SRCS "FlowAllocator.c" +idf_component_register( + SRCS "FlowAllocator.c" INCLUDE_DIRS "include" REQUIRES IPCP BufferManagement Ribd CdapProto Rmt) - -if("$ENV{USE_MOCKS}" STREQUAL "true") - target_include_directories(${COMPONENT_LIB} BEFORE PUBLIC - "${CMAKE_SOURCE_DIR}/../components_mocks/mock_Ribd/include" - ) -endif() diff --git a/components/FreeRTOS-Plus-POSIX/CMakeLists.txt b/components/FreeRTOS-Plus-POSIX/CMakeLists.txt index 7888249a..0cdc2e98 100644 --- a/components/FreeRTOS-Plus-POSIX/CMakeLists.txt +++ b/components/FreeRTOS-Plus-POSIX/CMakeLists.txt @@ -1,33 +1,32 @@ +if("$ENV{TARGET_TYPE}" STREQUAL "freertos_idf") + file(TO_CMAKE_PATH "$ENV{IDF_PATH}" ENV_IDF_PATH) - -file(TO_CMAKE_PATH "$ENV{IDF_PATH}" ENV_IDF_PATH) - -# set(esp_idf_dir $ENV{IDF_PATH}) - -if (EXISTS "${ENV_IDF_PATH}/components/freertos/include/freertos") - set(FREERTOS_INCLUDES "${ENV_IDF_PATH}/components/freertos/include/freertos") -else() - if(CONFIG_FREERTOS_SMP) - set(FREERTOS_INCLUDES "${ENV_IDF_PATH}/components/freertos/FreeRTOS-Kernel-SMP/include/freertos") + if (EXISTS "${ENV_IDF_PATH}/components/freertos/include/freertos") + set(FREERTOS_INCLUDES "${ENV_IDF_PATH}/components/freertos/include/freertos") else() - set(FREERTOS_INCLUDES "${ENV_IDF_PATH}/components/freertos/FreeRTOS-Kernel/include/freertos") + if(CONFIG_FREERTOS_SMP) + set(FREERTOS_INCLUDES "${ENV_IDF_PATH}/components/freertos/FreeRTOS-Kernel-SMP/include/freertos") + else() + set(FREERTOS_INCLUDES "${ENV_IDF_PATH}/components/freertos/FreeRTOS-Kernel/include/freertos") + endif() endif() -endif() -idf_component_register( - SRC_DIRS "FreeRTOS-Plus-POSIX/source" - INCLUDE_DIRS - "include" - "include/private" - "FreeRTOS-Plus-POSIX/include" - "FreeRTOS-Plus-POSIX/include/portable/espressif/esp32_devkitc_esp_wrover_kit" - "FreeRTOS-Plus-POSIX/include/portable" - PRIV_INCLUDE_DIRS - "include/private" - "${FREERTOS_INCLUDES}" -) + idf_component_register( + SRC_DIRS "FreeRTOS-Plus-POSIX/source" + INCLUDE_DIRS + "include" + "include/private" + "FreeRTOS-Plus-POSIX/include" + "FreeRTOS-Plus-POSIX/include/portable/espressif/esp32_devkitc_esp_wrover_kit" + "FreeRTOS-Plus-POSIX/include/portable" + PRIV_INCLUDE_DIRS + "include/private" + "${FREERTOS_INCLUDES}" + ) + + set_source_files_properties("${freertos_plus_posix_dir}/source/FreeRTOS_POSIX_pthread_cond.c" + PROPERTIES COMPILE_FLAGS + "-Wno-maybe-uninitialized" + ) +endif() -# set_source_files_properties("${freertos_plus_posix_dir}/source/FreeRTOS_POSIX_pthread_cond.c" -# PROPERTIES COMPILE_FLAGS -# "-Wno-maybe-uninitialized" -# ) diff --git a/components/IPCP/CMakeLists.txt b/components/IPCP/CMakeLists.txt index 7aad23b2..07e5cd1b 100644 --- a/components/IPCP/CMakeLists.txt +++ b/components/IPCP/CMakeLists.txt @@ -2,10 +2,3 @@ idf_component_register( SRCS "IpcManager.c" "normalIPCP.c" "IPCP.c" "common.c" INCLUDE_DIRS "include" REQUIRES configSensor NetworkInterface ShimIPCP BufferManagement ARP826 Rmt RINA_API EFCP Enrollment Ribd FlowAllocator) - -if("$ENV{USE_MOCKS}" STREQUAL "true") - target_include_directories(${COMPONENT_LIB} BEFORE PUBLIC - "${CMAKE_SOURCE_DIR}/../components_mocks/mock_FlowAllocator/include" - "${CMAKE_SOURCE_DIR}/../components_mocks/mock_Ribd/include" - ) -endif() diff --git a/components/IPCP/IPCP.c b/components/IPCP/IPCP.c index 1898afbd..719e4918 100644 --- a/components/IPCP/IPCP.c +++ b/components/IPCP/IPCP.c @@ -1,5 +1,3 @@ -#include "IPCP_events.h" -#include "linux_rsnet.h" #include #include #include @@ -19,6 +17,7 @@ #include "IPCP.h" #include "IPCP_api.h" +#include "IPCP_events.h" #include "ARP826.h" #include "BufferManagement.h" #include "NetworkInterface.h" @@ -30,8 +29,6 @@ #include "Enrollment.h" #include "Enrollment_api.h" #include "FlowAllocator.h" -#include "portability/rsqueue.h" -#include "portability/rstime.h" #include "rina_buffers.h" #include "rina_common_port.h" #include "RINA_API.h" @@ -182,7 +179,7 @@ static void *prvIPCPTask(void *pvParameters) { RINAStackEvent_t xReceivedEvent; struct timespec xNextIPCPSleep; - flowAllocateHandle_t *pxFlowAllocateRequest; + flowAllocateHandle_t *pxFlowAllocateHandle; useconds_t xSleepTimeUS; /* Just to prevent compiler warnings about unused parameters. */ @@ -263,14 +260,14 @@ static void *prvIPCPTask(void *pvParameters) /* The network hardware driver has received a new packet. A * pointer to the received buffer is located in the pvData member * of the received event structure. */ - prvHandleEthernetPacket((NetworkBufferDescriptor_t *)xReceivedEvent.pvData); + prvHandleEthernetPacket((NetworkBufferDescriptor_t *)xReceivedEvent.xData.PV); break; case eNetworkTxEvent: { NetworkBufferDescriptor_t *pxDescriptor; - pxDescriptor = (NetworkBufferDescriptor_t *)xReceivedEvent.pvData; + pxDescriptor = (NetworkBufferDescriptor_t *)xReceivedEvent.xData.PV; /* Send a network packet. The ownership will be transferred to * the driver, which will release it after delivery. */ @@ -314,16 +311,16 @@ static void *prvIPCPTask(void *pvParameters) case eFlowBindEvent: - pxFlowAllocateRequest = ((flowAllocateHandle_t *)xReceivedEvent.pvData); + pxFlowAllocateHandle = (flowAllocateHandle_t *)xReceivedEvent.xData.PV; - (void)xNormalFlowPrebind(pxIpcpData, pxFlowAllocateRequest); + (void)xNormalFlowPrebind(pxIpcpData, pxFlowAllocateHandle); #if 0 pxFlowAllocateRequest->xEventBits |= (EventBits_t)eFLOW_BOUND; vRINA_WeakUpUser(pxFlowAllocateRequest); #endif - vRINA_WakeUpFlowRequest(pxFlowAllocateRequest, eFLOW_BOUND); + vRINA_WakeUpFlowRequest(pxFlowAllocateHandle, eFLOW_BOUND); break; @@ -334,7 +331,7 @@ static void *prvIPCPTask(void *pvParameters) case eStackTxEvent: { // call Efcp to write SDU. - NetworkBufferDescriptor_t *pxNetBuffer = (NetworkBufferDescriptor_t *)xReceivedEvent.pvData; + NetworkBufferDescriptor_t *pxNetBuffer = (NetworkBufferDescriptor_t *)xReceivedEvent.xData.PV; (void)xNormalDuWrite(pxIpcpData, pxNetBuffer->ulBoundPort, pxNetBuffer); } @@ -480,7 +477,7 @@ bool_t xSendEventToIPCPTask(eRINAEvent_t eEvent) RINAStackEvent_t xEventMessage; xEventMessage.eEventType = eEvent; - xEventMessage.pvData = (void *)NULL; + xEventMessage.xData.PV = (void *)NULL; return xSendEventStructToIPCPTask(&xEventMessage, 0); } @@ -911,7 +908,10 @@ bool_t xIPCPIsNetworkTaskReady(void) void RINA_NetworkDown(void) { - static const RINAStackEvent_t xNetworkDownEvent = {eNetworkDownEvent, NULL}; + static const RINAStackEvent_t xNetworkDownEvent = { + .eEventType = eNetworkDownEvent, + .xData = { .PV = NULL } + }; LOGI(TAG_IPCPMANAGER, "RINA_NetworkDown"); diff --git a/components/IPCP/include/IPCP_events.h b/components/IPCP/include/IPCP_events.h index bc854444..9472eeef 100644 --- a/components/IPCP/include/IPCP_events.h +++ b/components/IPCP/include/IPCP_events.h @@ -1,6 +1,8 @@ #ifndef _COMPONENTS_IPCP_EVENTS_H #define _COMPONENTS_IPCP_EVENTS_H +#include + typedef enum RINA_EVENTS { eNoEvent = -1, @@ -28,7 +30,13 @@ typedef enum RINA_EVENTS typedef struct xRINA_TASK_COMMANDS { eRINAEvent_t eEventType; /**< The event-type enum */ - void *pvData; /**< The data in the event */ + union { + void *PV; + uint32_t UN; + int32_t N; + char C; + uint8_t B; + } xData; /**< The data in the event */ } RINAStackEvent_t; #endif // _COMPONENTS_IPCP_EVENTS_H diff --git a/components/IPCP/normalIPCP.c b/components/IPCP/normalIPCP.c index 629450d6..e92caf22 100644 --- a/components/IPCP/normalIPCP.c +++ b/components/IPCP/normalIPCP.c @@ -1,6 +1,7 @@ #include #include +#include "RINA_API_flows.h" #include "common/list.h" #include "common/rina_ids.h" #include "common/rina_name.h" @@ -13,11 +14,11 @@ #include "configRINA.h" #include "IpcManager.h" #include "FlowAllocator.h" - #include "BufferManagement.h" #include "Ribd.h" #include "Ribd_api.h" #include "IPCP_api.h" +#include "RINA_API_flows.h" extern struct ipcpInstanceData_t *pxIpcpData; @@ -172,12 +173,12 @@ bool_t xNormalDuWrite(struct ipcpInstanceData_t *pxData, }*/ bool_t xNormalFlowPrebind(struct ipcpInstanceData_t *pxData, - flowAllocateHandle_t *pxFlowHandle) + flowAllocateHandle_t *pxFlowAllocateHandle) { struct normalFlow_t *pxFlow; - LOGI(TAG_IPCPNORMAL, "Binding the flow with port id:%d", pxFlowHandle->xPortId); + LOGI(TAG_IPCPNORMAL, "Binding the flow with port id:%ud", pxFlowAllocateHandle->xPortId); if (!pxData) { @@ -192,9 +193,8 @@ bool_t xNormalFlowPrebind(struct ipcpInstanceData_t *pxData, return false; } - pxFlow->xPortId = pxFlowHandle->xPortId; + pxFlow->xPortId = pxFlowAllocateHandle->xPortId; pxFlow->eState = ePORT_STATE_PENDING; - pxFlow->pxFlowHandle = pxFlowHandle; LOGD(TAG_IPCPNORMAL, "Flow: %p portID: %d portState: %d", pxFlow, pxFlow->xPortId, pxFlow->eState); vRsListInitItem(&(pxFlow->xFlowListItem), pxFlow); @@ -869,6 +869,7 @@ bool_t xNormalConnectionDestroy(cepId_t xSrcCepId) return false; } */ + pxFlow = prvFindFlowCepid(xSrcCepId); if (!pxFlow) { diff --git a/components/IPCP/test/CMakeLists.txt b/components/IPCP/test/CMakeLists.txt index 97c6fcc4..8073f5d8 100644 --- a/components/IPCP/test/CMakeLists.txt +++ b/components/IPCP/test/CMakeLists.txt @@ -5,21 +5,8 @@ if("$ENV{TARGET_TYPE}" STREQUAL "freertos_idf") else() add_executable(test_ipcp "${CMAKE_CURRENT_LIST_DIR}/test_ipcp.c") target_link_libraries(test_ipcp - IPCP - FlowAllocator - BufferManagement - EFCP - ShimIPCP - ARP826 - Enrollment - Ribd - IPCP - CdapProto - Rmt - pthread - portability + RINA NetworkInterface_MQ - Common unity rt ) diff --git a/components/IPCP/test/test_ipcp.c b/components/IPCP/test/test_ipcp.c index a4e1cc75..41d5cd7d 100644 --- a/components/IPCP/test/test_ipcp.c +++ b/components/IPCP/test/test_ipcp.c @@ -32,7 +32,7 @@ RS_TEST_CASE(IPCPSendEvent, "[ipcp]") memcpy(buf->pucEthernetBuffer, txt, sizeof(txt)); ev.eEventType = eNetworkTxEvent; - ev.pvData = buf; + ev.xData.PV = buf; /* Send the bogus data */ TEST_ASSERT(xSendEventStructToIPCPTask(&ev, 100)); diff --git a/components/NetworkInterface/CMakeLists.txt b/components/NetworkInterface/CMakeLists.txt index af6d3ec0..0cd58d29 100644 --- a/components/NetworkInterface/CMakeLists.txt +++ b/components/NetworkInterface/CMakeLists.txt @@ -1,9 +1,27 @@ -if("$ENV{NETWORKINTERFACE_MODULE}" STREQUAL "") - set(NETWORKINTERFACE_MODULE esp32) +if("$ENV{TARGET_TYPE}" STREQUAL "freertos_idf") + if("$ENV{NETWORKINTERFACE_MODULE}" STREQUAL "") + set(NETWORKINTERFACE_MODULE esp32) + else() + set(NETWORKINTERFACE_MODULE $ENV{NETWORKINTERFACE_MODULE}) + endif() + + idf_component_register(SRCS "${NETWORKINTERFACE_MODULE}/NetworkInterface.c" + INCLUDE_DIRS "include" "mq/include" + REQUIRES Common BufferManagement ARP826 ShimIPCP configSensor FreeRTOS-Plus-POSIX) else() - set(NETWORKINTERFACE_MODULE $ENV{NETWORKINTERFACE_MODULE}) -endif() + rs_include_component(NetworkInterface + DIR "${CMAKE_SOURCE_DIR}/components/NetworkInterface") -idf_component_register(SRCS "${NETWORKINTERFACE_MODULE}/NetworkInterface.c" - INCLUDE_DIRS "include" "mq/include" - REQUIRES Common BufferManagement ARP826 ShimIPCP configSensor FreeRTOS-Plus-POSIX) + rs_component(NetworkInterface_TAP + SRCS "${CMAKE_SOURCE_DIR}/components/NetworkInterface/linux_tap/*.c" + INCLUDES "${CMAKE_SOURCE_DIR}/components/NetworkInterface/include" + REQUIRES Common configRINA BufferManagement ARP826 IPCP configSensor Rmt ShimIPCP + EFCP Portability RINA_API) + + rs_component(NetworkInterface_MQ + SRCS "${CMAKE_SOURCE_DIR}/components/NetworkInterface/mq/*.c" + INCLUDES "${CMAKE_SOURCE_DIR}/components/NetworkInterface/include" + "${CMAKE_SOURCE_DIR}/components/NetworkInterface/mq/include" + REQUIRES Common configRINA BufferManagement ARP826 IPCP configSensor Rmt ShimIPCP + EFCP Portability RINA_API) +endif() diff --git a/components/NetworkInterface/esp32/CMakeLists.txt b/components/NetworkInterface/esp32/CMakeLists.txt index 08598ca3..90950a96 100644 --- a/components/NetworkInterface/esp32/CMakeLists.txt +++ b/components/NetworkInterface/esp32/CMakeLists.txt @@ -1,4 +1,4 @@ -idf_component_register(SRCS "NetworkInterface.c" - INCLUDE_DIRS "include" - REQUIRES BufferManagement ARP826 ShimIPCP configSensor IPCP) +# idf_component_register(SRCS "NetworkInterface.c" +# INCLUDE_DIRS "include" +# REQUIRES BufferManagement ARP826 ShimIPCP configSensor IPCP) diff --git a/components/NetworkInterface/esp32/NetworkInterface.c b/components/NetworkInterface/esp32/NetworkInterface.c index 89669dd6..5a2c0428 100644 --- a/components/NetworkInterface/esp32/NetworkInterface.c +++ b/components/NetworkInterface/esp32/NetworkInterface.c @@ -290,9 +290,12 @@ BaseType_t xNetworkInterfaceDisconnect(void) esp_err_t xNetworkInterfaceInput(void *buffer, uint16_t len, void *eb) { NetworkBufferDescriptor_t *pxNetworkBuffer; - RINAStackEvent_t xRxEvent = {eNetworkRxEvent, NULL}; const TickType_t xDescriptorWaitTime = pdMS_TO_TICKS(250); struct timespec ts; + RINAStackEvent_t xRxEvent = { + .eEventType = eNetworkRxEvent, + .xData.PV = NULL + }; if (eConsiderFrameForProcessing(buffer) != eProcessBuffer) { @@ -315,7 +318,7 @@ esp_err_t xNetworkInterfaceInput(void *buffer, uint16_t len, void *eb) /* Copy the packet data. */ memcpy(pxNetworkBuffer->pucEthernetBuffer, buffer, len); - xRxEvent.pvData = (void *)pxNetworkBuffer; + xRxEvent.xData.PV = (void *)pxNetworkBuffer; // ESP_LOGE(TAG_RINA, "pucEthernetBuffer and len: %p, %d", pxNetworkBuffer->pucEthernetBuffer, len); @@ -340,7 +343,10 @@ esp_err_t xNetworkInterfaceInput(void *buffer, uint16_t len, void *eb) void vNetworkNotifyIFDown() { - RINAStackEvent_t xRxEvent = {eNetworkDownEvent, NULL}; + RINAStackEvent_t xRxEvent = { + .eEventType = eNetworkDownEvent, + .xData.PV = NULL + }; if (xInterfaceState != INTERFACE_DOWN) { diff --git a/components/NetworkInterface/linux_tap/NetworkInterface.c b/components/NetworkInterface/linux_tap/NetworkInterface.c index 451ebe48..9ba5ef84 100644 --- a/components/NetworkInterface/linux_tap/NetworkInterface.c +++ b/components/NetworkInterface/linux_tap/NetworkInterface.c @@ -505,7 +505,10 @@ bool_t xNetworkInterfaceOutput(NetworkBufferDescriptor_t *const pxNetworkBuffer, bool_t xNetworkInterfaceInput(void *buffer, uint16_t len, void *eb) { NetworkBufferDescriptor_t *pxNetworkBuffer; - RINAStackEvent_t xRxEvent = {eNetworkRxEvent, NULL}; + RINAStackEvent_t xRxEvent = { + .eEventType = eNetworkRxEvent, + .xData.PV = NULL + }; if (eConsiderFrameForProcessing(buffer) != eProcessBuffer) return true; @@ -518,7 +521,7 @@ bool_t xNetworkInterfaceInput(void *buffer, uint16_t len, void *eb) /* Copy the packet data. */ memcpy(pxNetworkBuffer->pucEthernetBuffer, buffer, len); - xRxEvent.pvData = (void *)pxNetworkBuffer; + xRxEvent.xData.PV = (void *)pxNetworkBuffer; if (!xSendEventStructToIPCPTask(&xRxEvent, 250 * 1000)) { LOGE(TAG_WIFI, "Failed to enqueue packet to network stack %p, len %d", buffer, len); diff --git a/components/NetworkInterface/mq/NetworkInterface.c b/components/NetworkInterface/mq/NetworkInterface.c index 6f167475..640a6826 100644 --- a/components/NetworkInterface/mq/NetworkInterface.c +++ b/components/NetworkInterface/mq/NetworkInterface.c @@ -299,7 +299,7 @@ bool_t xNetworkInterfaceInput(void *buffer, uint16_t len, void *eb) /* Copy the packet data. */ memcpy(pxNetworkBuffer->pucEthernetBuffer, buffer, len); - xRxEvent.pvData = (void *)pxNetworkBuffer; + xRxEvent.xData.PV = (void *)pxNetworkBuffer; if (xSendEventStructToIPCPTask(&xRxEvent, 0) == false) { diff --git a/components/Portability/CMakeLists.txt b/components/Portability/CMakeLists.txt index 6e1a0d5c..9f1f3c72 100644 --- a/components/Portability/CMakeLists.txt +++ b/components/Portability/CMakeLists.txt @@ -4,17 +4,16 @@ set(Portability_INCLUDES "${CMAKE_CURRENT_SOURCE_DIR}/posix/include" "${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_TYPE}/include") -if(NOT ${TARGET_TYPE} STREQUAL "freertos_idf") - include(${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_TYPE}/CMakeLists.txt) -else() +if("$ENV{TARGET_TYPE}" STREQUAL "freertos_idf") idf_component_register( SRCS "freertos_idf/rsmem.c" "freertos_idf/rslog.c" "posix/posix_rsqueue.c" "posix/posix_rstime.c" - INCLUDE_DIRS ${Portability_INCLUDES} REQUIRES FreeRTOS-Plus-POSIX) +else() + include(${CMAKE_CURRENT_LIST_DIR}/${TARGET_TYPE}/CMakeLists.txt) endif() diff --git a/components/Portability/freertos_idf/include/freertos_rsdefs.h b/components/Portability/freertos_idf/include/freertos_rsdefs.h index 89c5404f..f13877fd 100644 --- a/components/Portability/freertos_idf/include/freertos_rsdefs.h +++ b/components/Portability/freertos_idf/include/freertos_rsdefs.h @@ -12,6 +12,9 @@ typedef BaseType_t num_t; typedef char* string_t; #define PORT_HAS_STRING_T +typedef char stringbuf_t; +#define PORT_HAS_STRINGBUF_T + typedef uint8_t* buffer_t; #define PORT_HAS_BUFFER_T diff --git a/components/Portability/linux/CMakeLists.txt b/components/Portability/linux/CMakeLists.txt index b5aa9389..93d42f75 100644 --- a/components/Portability/linux/CMakeLists.txt +++ b/components/Portability/linux/CMakeLists.txt @@ -1,19 +1,15 @@ -if("${TARGET_TYPE}" STREQUAL "linux") - file(GLOB portability_SOURCES - "${CMAKE_CURRENT_SOURCE_DIR}/components/Portability/${TARGET_TYPE}/*.c" - "${CMAKE_CURRENT_SOURCE_DIR}/components/Portability/posix/*.c" - ) - set(Portability_INCLUDES - "${CMAKE_CURRENT_SOURCE_DIR}/components/Portability/include" - "${CMAKE_CURRENT_SOURCE_DIR}/components/Portability/posix/include" - "${CMAKE_CURRENT_SOURCE_DIR}/components/Portability/${TARGET_TYPE}/include" - "${deps_INCLUDE_DIRS}" - ) - add_library(portability STATIC ${portability_SOURCES}) - target_link_libraries(portability pthread rt) - target_include_directories(portability PUBLIC - ${Portability_INCLUDES} - ${Common_INCLUDES} - ${CMAKE_CURRENT_BINARY_DIR} - ) -endif() +set(local_INCLUDES + ${CMAKE_SOURCE_DIR}/components/Portability/include + ${CMAKE_SOURCE_DIR}/components/Portability/posix/include + ${CMAKE_SOURCE_DIR}/components/Portability/$ENV{TARGET_TYPE}/include) + +set(Portability_SOURCES + ${CMAKE_SOURCE_DIR}/components/Portability/$ENV{TARGET_TYPE}/*.c + ${CMAKE_SOURCE_DIR}/components/Portability/posix/*.c +) + +rs_component(Portability + SRCS ${Portability_SOURCES} + INCLUDES ${local_INCLUDES} + TEST_DIR ${CMAKE_CURRENT_LIST_DIR}/../test +) diff --git a/components/Portability/posix/posix_rstime.c b/components/Portability/posix/posix_rstime.c index 71a2fb68..6482a07a 100644 --- a/components/Portability/posix/posix_rstime.c +++ b/components/Portability/posix/posix_rstime.c @@ -24,6 +24,14 @@ bool_t rstime_waitnsec(struct timespec *ts, uint64_t n) { ts->tv_sec += (time_t)(n / 1000000000); ts->tv_nsec += (n % 1000000000); + /* Prevent overflow in tv_nsec. */ + if (ts->tv_nsec >= 1000000000) { + ts->tv_nsec = ts->tv_nsec - 1000000000; + ts->tv_sec++; + } + + RsAssert(ts->tv_nsec <= 999999999); + return true; } diff --git a/components/Portability/test/CMakeLists.txt b/components/Portability/test/CMakeLists.txt index 12310cbe..86d0469c 100644 --- a/components/Portability/test/CMakeLists.txt +++ b/components/Portability/test/CMakeLists.txt @@ -5,7 +5,8 @@ if("$ENV{TARGET_TYPE}" STREQUAL "freertos_idf") else() add_executable(test_queues "${CMAKE_CURRENT_LIST_DIR}/test_queues.c") target_link_libraries(test_queues - portability + Portability + Common unity pthread rt @@ -18,7 +19,8 @@ else() add_executable(test_time "${CMAKE_CURRENT_LIST_DIR}/test_time.c") target_link_libraries(test_time - portability + Portability + Common unity ) diff --git a/components/RINA_API/CMakeLists.txt b/components/RINA_API/CMakeLists.txt index e42e74c5..62f9ee9c 100644 --- a/components/RINA_API/CMakeLists.txt +++ b/components/RINA_API/CMakeLists.txt @@ -1,3 +1,4 @@ -idf_component_register(SRCS "RINA_API.c" - INCLUDE_DIRS "include" - REQUIRES configSensor BufferManagement IPCP FlowAllocator) \ No newline at end of file +idf_component_register( + SRCS "RINA_API.c" + INCLUDE_DIRS "include" + REQUIRES configSensor BufferManagement IPCP FlowAllocator) diff --git a/components/RINA_API/RINA_API.c b/components/RINA_API/RINA_API.c index 04ff0aac..f241ee01 100644 --- a/components/RINA_API/RINA_API.c +++ b/components/RINA_API/RINA_API.c @@ -61,7 +61,10 @@ struct appRegistration_t *RINA_application_register(string_t pcNameDif, { name_t *xDn, *xAppn, *xDan; registerApplicationHandle_t *xRegAppRequest; - RINAStackEvent_t xStackAppRegistrationEvent = {eStackAppRegistrationEvent, NULL}; + RINAStackEvent_t xStackAppRegistrationEvent = { + .eEventType = eStackAppRegistrationEvent, + .xData.PV = NULL + }; xRegAppRequest = pvRsMemAlloc(sizeof(registerApplicationHandle_t)); if (!xRegAppRequest) { @@ -107,7 +110,7 @@ struct appRegistration_t *RINA_application_register(string_t pcNameDif, xRegAppRequest->pxDifName = xDn; xRegAppRequest->pxDafName = xDan; - xStackAppRegistrationEvent.pvData = xRegAppRequest; + xStackAppRegistrationEvent.xData.PV = xRegAppRequest; if (xSendEventStructToIPCPTask(&xStackAppRegistrationEvent, (TickType_t)0U) == pdPASS) { @@ -128,7 +131,7 @@ bool_t xRINA_bind(flowAllocateHandle_t *pxFlowRequest) } xBindEvent.eEventType = eFlowBindEvent; - xBindEvent.pvData = (void *)pxFlowRequest; + xBindEvent.xData.PV = (void *)pxFlowRequest; if (xSendEventStructToIPCPTask(&xBindEvent, 0) == false) /* Failed to wake-up the IPCP-task, no use to wait for it */ @@ -292,7 +295,10 @@ bool_t RINA_flowStatus(portId_t xAppPortId) bool_t prvConnect(flowAllocateHandle_t *pxFlowAllocateRequest) { bool_t xResult = 0; - RINAStackEvent_t xStackFlowAllocateEvent = {eStackFlowAllocateEvent, NULL}; + RINAStackEvent_t xStackFlowAllocateEvent = { + .eEventType = eStackFlowAllocateEvent, + .xData.PV = NULL + }; if (pxFlowAllocateRequest == NULL) { LOGE(TAG_RINA, "No flow request passed"); @@ -405,7 +411,10 @@ size_t RINA_flow_write(portId_t xPortId, void *pvBuffer, size_t uxTotalDataLengt void *pvCopyDest; struct RsTimeOut xTimeOut; useconds_t xTimeToWait, xTimeDiff; - RINAStackEvent_t xStackTxEvent = {eStackTxEvent, NULL}; + RINAStackEvent_t xStackTxEvent = { + .eEventType = eStackTxEvent, + .xData.PV = NULL + }; /* Check that DataLength is not longer than MAX_SDU_SIZE. We * don't know yet WHAT to do if this is not true so make sure we @@ -437,7 +446,7 @@ size_t RINA_flow_write(portId_t xPortId, void *pvBuffer, size_t uxTotalDataLengt pxNetworkBuffer->xDataLength = uxTotalDataLength; pxNetworkBuffer->ulBoundPort = xPortId; - xStackTxEvent.pvData = pxNetworkBuffer; + xStackTxEvent.xData.PV = pxNetworkBuffer; if (xSendEventStructToIPCPTask(&xStackTxEvent, xTimeToWait)) return uxTotalDataLength; @@ -460,7 +469,7 @@ bool_t RINA_close(portId_t xAppPortId) RINAStackEvent_t xDeallocateEvent; xDeallocateEvent.eEventType = eFlowDeallocateEvent; - xDeallocateEvent.pvData = (void *)(long)xAppPortId; + xDeallocateEvent.xData.UN = xAppPortId; if (!is_port_id_ok(xAppPortId)) xResult = false; diff --git a/components/Ribd/CMakeLists.txt b/components/Ribd/CMakeLists.txt index 5e4c8cbc..090c188a 100644 --- a/components/Ribd/CMakeLists.txt +++ b/components/Ribd/CMakeLists.txt @@ -1,10 +1,5 @@ -idf_component_register(SRCS "Rib.c" "Ribd.c" - INCLUDE_DIRS "include" - REQUIRES FlowAllocator BufferManagement ShimIPCP configSensor IPCP CdapProto Enrollment RINA_API) - -if("$ENV{USE_MOCKS}" STREQUAL "true") - target_include_directories(${COMPONENT_LIB} BEFORE PUBLIC - "${CMAKE_SOURCE_DIR}/../components_mocks/mock_Ribd/include" - ) -endif() +idf_component_register( + SRCS "Rib.c" "Ribd.c" + INCLUDE_DIRS "include" + REQUIRES FlowAllocator BufferManagement ShimIPCP configSensor IPCP CdapProto Enrollment RINA_API) diff --git a/components/Ribd/test/CMakeLists.txt b/components/Ribd/test/CMakeLists.txt index 57b580bc..1157b642 100644 --- a/components/Ribd/test/CMakeLists.txt +++ b/components/Ribd/test/CMakeLists.txt @@ -4,23 +4,9 @@ if("$ENV{TARGET_TYPE}" STREQUAL "freertos_idf") REQUIRES unity Common Ribd) else() set(RIBD_DEPS - # This is odd but there seem to be a circular dependency between - # Ribd and Enrollment. - Ribd - Enrollment - Ribd - - CdapProto - Rmt - BufferManagement - IPCP - EFCP - FlowAllocator + RINA + NetworkInterface_MQ unity - rt - pthread - Common - portability ) add_executable(test_rib "${CMAKE_CURRENT_LIST_DIR}/test_rib.c") diff --git a/components/Rmt/CMakeLists.txt b/components/Rmt/CMakeLists.txt index f5069f5d..b3598954 100644 --- a/components/Rmt/CMakeLists.txt +++ b/components/Rmt/CMakeLists.txt @@ -1,4 +1,4 @@ -idf_component_register(SRCS "Rmt.c" "pci.c" "du.c" - INCLUDE_DIRS "include" - REQUIRES IPCP configRINA configSensor EFCP Common) - +idf_component_register( + SRCS "Rmt.c" "pci.c" "du.c" + INCLUDE_DIRS "include" + REQUIRES IPCP configRINA configSensor EFCP Common) diff --git a/components/ShimIPCP/CMakeLists.txt b/components/ShimIPCP/CMakeLists.txt index bc007ddb..c0644e39 100644 --- a/components/ShimIPCP/CMakeLists.txt +++ b/components/ShimIPCP/CMakeLists.txt @@ -1,4 +1,5 @@ -idf_component_register(SRCS "ShimIPCP.c" - INCLUDE_DIRS "include" - REQUIRES BufferManagement ARP826 NetworkInterface IPCP configRINA configSensor Rmt) +idf_component_register( + SRCS "ShimIPCP.c" + INCLUDE_DIRS "include" + REQUIRES BufferManagement ARP826 NetworkInterface IPCP configRINA configSensor Rmt) diff --git a/components/ShimIPCP/ShimIPCP.c b/components/ShimIPCP/ShimIPCP.c index a46daf67..7810b84a 100644 --- a/components/ShimIPCP/ShimIPCP.c +++ b/components/ShimIPCP/ShimIPCP.c @@ -262,7 +262,10 @@ bool_t xShimFlowAllocateResponse(struct ipcpInstanceData_t *pxShimInstanceData, portId_t xPortId) { - RINAStackEvent_t xEnrollEvent = {eShimFlowAllocatedEvent, NULL}; + RINAStackEvent_t xEnrollEvent = { + .eEventType = eShimFlowAllocatedEvent, + .xData.PV = NULL + }; shimFlow_t *pxFlow; struct ipcpInstance_t *pxShimIpcp; @@ -330,7 +333,7 @@ bool_t xShimFlowAllocateResponse(struct ipcpInstanceData_t *pxShimInstanceData, if (pxFlow->ePortIdState == eALLOCATED) { LOGI(TAG_SHIM, "Flow with id:%d was allocated", pxFlow->xPortId); - xEnrollEvent.pvData = (void *)(uintptr_t)xPortId; + xEnrollEvent.xData.UN = xPortId; xSendEventStructToIPCPTask(&xEnrollEvent, 250 * 1000); } @@ -741,7 +744,6 @@ static bool_t prvShimFlowDestroy(struct ipcpInstanceData_t *xData, shimFlow_t *x bool_t xShimSDUWrite(struct ipcpInstanceData_t *pxData, portId_t xId, struct du_t *pxDu, bool_t uxBlocking) { - shimFlow_t *pxFlow; NetworkBufferDescriptor_t *pxNetworkBuffer; EthernetHeader_t *pxEthernetHeader; @@ -749,7 +751,10 @@ bool_t xShimSDUWrite(struct ipcpInstanceData_t *pxData, portId_t xId, struct du_ gha_t *pxDestHw; size_t uxHeadLen, uxLength; struct timespec ts; - RINAStackEvent_t xTxEvent = {eNetworkTxEvent, NULL}; + RINAStackEvent_t xTxEvent = { + .eEventType = eNetworkTxEvent, + .xData.PV = NULL + }; unsigned char *pucArpPtr; LOGI(TAG_SHIM, "SDU write received"); @@ -843,7 +848,7 @@ bool_t xShimSDUWrite(struct ipcpInstanceData_t *pxData, portId_t xId, struct du_ /* ReleaseBuffer, no need anymore that why pdTRUE here */ - xTxEvent.pvData = (void *)pxNetworkBuffer; + xTxEvent.xData.PV = (void *)pxNetworkBuffer; if (xSendEventStructToIPCPTask(&xTxEvent, 250 * 1000) == false) { @@ -992,14 +997,17 @@ struct ipcpInstance_t *pxShimWiFiCreate(ipcProcessId_t xIpcpId) } /*Check this logic.*/ -bool_t xShimWiFiInit(ipcpInstance_t *pxShimWiFiInstance) +bool_t xShimWiFiInit(struct ipcpInstance_t *pxShimWiFiInstance) { /*xShimWiFiInit is going to init the WiFi drivers and associate to the AP. * Update de MacAddress variable depending on the WiFi drivers. Sent this variable * as event data to be used when the shimWiFi D(F will be created.*/ LOGI(TAG_SHIM, "Wifi shim initialization"); - RINAStackEvent_t xEnrollEvent = {eShimEnrolledEvent, NULL}; + RINAStackEvent_t xEnrollEvent = { + .eEventType = eShimEnrolledEvent, + .xData.PV = NULL + }; if (!xShimEnrollToDIF(pxShimWiFiInstance->pxData->pxPhyDev)) { LOGE(TAG_SHIM, "Wifi shim instance can't enroll to DIF"); @@ -1007,7 +1015,7 @@ bool_t xShimWiFiInit(ipcpInstance_t *pxShimWiFiInstance) } else { - xEnrollEvent.pvData = (void *)(pxShimWiFiInstance->pxData->pxPhyDev); + xEnrollEvent.xData.PV = (void *)(pxShimWiFiInstance->pxData->pxPhyDev); xSendEventStructToIPCPTask(&xEnrollEvent, 50 * 1000); return true; } diff --git a/components/ShimIPCP/include/ShimIPCP.h b/components/ShimIPCP/include/ShimIPCP.h index ac561c75..d9479fc0 100644 --- a/components/ShimIPCP/include/ShimIPCP.h +++ b/components/ShimIPCP/include/ShimIPCP.h @@ -118,7 +118,7 @@ void vShimWrite(void); * */ void vShimRead(void); -bool_t xShimWiFiInit(ipcpInstance_t *pxShimWiFiInstance); +bool_t xShimWiFiInit(struct ipcpInstance_t *pxShimWiFiInstance); struct ipcpInstance_t *pxShimWiFiCreate(ipcProcessId_t xIpcpId); diff --git a/components/ShimIPCP/test/CMakeLists.txt b/components/ShimIPCP/test/CMakeLists.txt index 51ab419a..52d562d3 100644 --- a/components/ShimIPCP/test/CMakeLists.txt +++ b/components/ShimIPCP/test/CMakeLists.txt @@ -2,10 +2,6 @@ if("$ENV{TARGET_TYPE}" STREQUAL "freertos_idf") idf_component_register(SRC_DIRS "." INCLUDE_DIRS "." REQUIRES mock_IPCP NetworkInterface unity Common Portability) - - # target_include_directories(${COMPONENT_LIB} BEFORE PUBLIC - # "/home/neumann/W/Tria/rinasense-merge/components_mocks/mock_NetworkInterface/include" - # ) else() add_executable(test_shim_ipcp "${CMAKE_CURRENT_LIST_DIR}/test_shim_ipcp.c") target_include_directories(test_shim_ipcp BEFORE PRIVATE @@ -13,13 +9,9 @@ else() ) target_link_libraries(test_shim_ipcp + RINA + Portability unity - IPCP - Rmt - BufferManagement - ShimIPCP - ARP826 - portability pthread Common rt diff --git a/components/configRINA/CMakeLists.txt b/components/configRINA/CMakeLists.txt index 49e184a1..7efd97ee 100644 --- a/components/configRINA/CMakeLists.txt +++ b/components/configRINA/CMakeLists.txt @@ -1,3 +1 @@ -idf_component_register(SRCS "configRINA.c" - INCLUDE_DIRS "include") - +idf_component_register(SRCS "configRINA.c" INCLUDE_DIRS "include") diff --git a/components/configRINA/include/configRINA.h b/components/configRINA/include/configRINA.h index cbae461e..5f47f3b2 100644 --- a/components/configRINA/include/configRINA.h +++ b/components/configRINA/include/configRINA.h @@ -52,9 +52,6 @@ #define DTP_INITIAL_A_TIMER (300) #define DTP_DTCP_PRESENT false - #define DTP_INITIAL_A_TIMER ( 300 ) - #define DTP_DTCP_PRESENT false - /* Linux NetworkInterface options. */ /* Decides if the TAP NetworkInterface will create the tap device itself. */ diff --git a/components/configSensor/CMakeLists.txt b/components/configSensor/CMakeLists.txt index a8f8966f..6ff1a828 100644 --- a/components/configSensor/CMakeLists.txt +++ b/components/configSensor/CMakeLists.txt @@ -1,3 +1,2 @@ -idf_component_register(SRCS "configSensor.c" - INCLUDE_DIRS "include") +idf_component_register(SRCS "configSensor.c" INCLUDE_DIRS "include") diff --git a/components_mocks/mock_EFCP/CMakeLists.txt b/components_mocks/mock_EFCP/CMakeLists.txt index 3b555550..07049d52 100644 --- a/components_mocks/mock_EFCP/CMakeLists.txt +++ b/components_mocks/mock_EFCP/CMakeLists.txt @@ -1,4 +1,10 @@ -idf_component_register( - SRCS "efcp.c" - INCLUDE_DIRS "include" - REQUIRES Portability Common IPCP mock_FlowAllocator) +if("$ENV{TARGET_TYPE}" STREQUAL "freertos_idf") + idf_component_register( + SRCS "efcp.c" + INCLUDE_DIRS "include" + REQUIRES Portability Common IPCP mock_FlowAllocator) +else() + rs_plain_component(mock_EFCP + DIR ${CMAKE_CURRENT_LIST_DIR} + REQUIRES Portability Common IPCP mock_FlowAllocator) +endif() diff --git a/components_mocks/mock_EFCP/efcp.c b/components_mocks/mock_EFCP/efcp.c index fe707047..9449e740 100644 --- a/components_mocks/mock_EFCP/efcp.c +++ b/components_mocks/mock_EFCP/efcp.c @@ -1,4 +1,5 @@ #include "common/rina_ids.h" +#include "efcpStructures.h" #include "du.h" #include "efcpStructures.h" diff --git a/components_mocks/mock_FlowAllocator/CMakeLists.txt b/components_mocks/mock_FlowAllocator/CMakeLists.txt index 0075b04e..45d9d611 100644 --- a/components_mocks/mock_FlowAllocator/CMakeLists.txt +++ b/components_mocks/mock_FlowAllocator/CMakeLists.txt @@ -1,4 +1,11 @@ -idf_component_register( - SRCS "flowAllocator.c" - INCLUDE_DIRS "include" - REQUIRES Portability Common IPCP mock_FlowAllocator) +if("$ENV{TARGET_TYPE}" STREQUAL "freertos_idf") + idf_component_register( + SRCS "flowAllocator.c" + INCLUDE_DIRS "include" + REQUIRES Portability Common IPCP mock_FlowAllocator) +else() + rs_plain_component(mock_FlowAllocator + DIR ${CMAKE_CURRENT_LIST_DIR} + REQUIRES Portability Common IPCP + ) +endif() diff --git a/components_mocks/mock_IPCP/CMakeLists.txt b/components_mocks/mock_IPCP/CMakeLists.txt index 7babc807..af774c34 100644 --- a/components_mocks/mock_IPCP/CMakeLists.txt +++ b/components_mocks/mock_IPCP/CMakeLists.txt @@ -1,4 +1,10 @@ -idf_component_register( - SRC_DIRS "." - INCLUDE_DIRS "include" - REQUIRES Portability Common IPCP) +if("$ENV{TARGET_TYPE}" STREQUAL "freertos_idf") + idf_component_register( + SRC_DIRS "." + INCLUDE_DIRS "include" + REQUIRES Portability Common IPCP) +else() + rs_plain_component(mock_IPCP + DIR ${CMAKE_CURRENT_LIST_DIR} + REQUIRES Portability Common IPCP) +endif() diff --git a/components_mocks/mock_IPCP/ipcp.c b/components_mocks/mock_IPCP/ipcp.c index c76838cf..0d7b2459 100644 --- a/components_mocks/mock_IPCP/ipcp.c +++ b/components_mocks/mock_IPCP/ipcp.c @@ -48,7 +48,7 @@ bool_t xSendEventStructToIPCPTask(const RINAStackEvent_t *pxEvent, pxEvent->eEventType == eNetworkTxEvent); sentEvent.eEventType = pxEvent->eEventType; - sentEvent.pvData = pxEvent->pvData; + sentEvent.xData.PV = pxEvent->xData.PV; LOGD(TAG_MOCK_IPCP, "Sending event: %d", pxEvent->eEventType); diff --git a/components_mocks/mock_NetworkInterface/CMakeLists.txt b/components_mocks/mock_NetworkInterface/CMakeLists.txt index edb173ae..9174f46b 100644 --- a/components_mocks/mock_NetworkInterface/CMakeLists.txt +++ b/components_mocks/mock_NetworkInterface/CMakeLists.txt @@ -1,4 +1,10 @@ -idf_component_register( - SRCS "NetworkInterface.c" - INCLUDE_DIRS "include" - REQUIRES Portability Common IPCP) +if("$ENV{TARGET_TYPE}" STREQUAL "freertos_idf") + idf_component_register( + SRCS "NetworkInterface.c" + INCLUDE_DIRS "include" + REQUIRES Portability Common IPCP) +else() + rs_plain_component(mock_NetworkInterface + DIR ${CMAKE_CURRENT_LIST_DIR} + REQUIRES Portability Common IPCP) +endif() diff --git a/test_linux/CMakeLists.txt b/test_linux/CMakeLists.txt index a2b86278..99c42fde 100644 --- a/test_linux/CMakeLists.txt +++ b/test_linux/CMakeLists.txt @@ -1,22 +1,14 @@ -if (${TARGET_TYPE} STREQUAL "linux") +if ("${TARGET_TYPE}" STREQUAL "linux") set(NETWORK_INTERFACE_MODULE "linux_tap") add_executable(test_linux test_linux.c ) target_link_libraries(test_linux PUBLIC - ShimIPCP - IPCP + RINA NetworkInterface_TAP - configSensor - BufferManagement - ARP826 - Rmt - EFCP - Enrollment - Ribd - FlowAllocator ) else() message(FATAL_ERROR "This CMakeLists file is to use with the 'linux' target only.") endif() +