Files
Ashin Walpola 50bbf6552d Rebuild obu-firmware on Niklas Dathe's microbu-firmware
Replace the vanetza-idf port with his current station firmware (microbu-firmware
e4e4bd8: main/, components/microbu_v2x, components/vanetza, external/vanetza) and
re-apply the MicrOBU additions, each marked "MicrOBU:" in the sources:

- V2X_RX (opcode 0x90): every received ITS message, signed or not, through
  gn_unwrap.c, because the stack drops unsigned and foreign-root traffic. 0x85 is
  the spec's RAW_FRAME and 0x86 is reserved. The body is built in v2x_rx.hpp.
- Unsigned transmission (geonet.c) for security profile 1 or station security 0,
  from a random MAC per configuration.
- Radio polled from STATION_CONFIGURE on; manual country policy, TX power
  read-back, static RX buffer, short frames ignored.
- Battery guard (battery_policy.hpp): deep sleep below 3.30 V with no phone on USB.
- No USB writes without a host; last_frame_ms() for the guard.
- 80 KB NVS with the app at 0x20000, 8 MB flash, XIAO ESP32-C5 board, 20 dBm.

Remove the old C firmware, the bench listener and the old vanetza-idf copy. Add
docs/station-link.tex as revision 2 of the interface reference (V2X_RX, unsigned
sending, battery rule, revision history). Add 39 host unit tests (make firmware in
test/host) next to the existing chain, replay, fuzz and battery tests, and point
tools/station_status_watch.py at the new CONFIRM-based status.
2026-11-11 00:13:57 +01:00

167 lines
8.3 KiB
CMake

# micrOBU V2X runtime on the Vanetza component (LGPL-3.0-or-later).
cmake_minimum_required(VERSION 3.22)
set(V2X_PORT "${CMAKE_CURRENT_LIST_DIR}")
if(ESP_PLATFORM)
# IDF dependency discovery evaluates this file before Kconfig is available.
idf_component_register(SRCS "${V2X_PORT}/src/access.cpp"
INCLUDE_DIRS "${V2X_PORT}/include"
REQUIRES vanetza mbedtls ${MICROBU_CRYPTO_ADAPTER_COMPONENT}
PRIV_REQUIRES esp_wifi esp_phy esp_event nvs_flash)
if(CMAKE_BUILD_EARLY_EXPANSION)
return()
endif()
if(NOT CONFIG_COMPILER_CXX_EXCEPTIONS OR NOT CONFIG_COMPILER_CXX_RTTI)
message(FATAL_ERROR "microbu_v2x requires CONFIG_COMPILER_CXX_EXCEPTIONS=y and CONFIG_COMPILER_CXX_RTTI=y")
endif()
set(V2X_TARGET ${COMPONENT_LIB})
set(V2X_NETWORK ${CONFIG_MICROBU_V2X_NETWORK})
set(V2X_CAM ${CONFIG_MICROBU_V2X_CAM})
set(V2X_DENM ${CONFIG_MICROBU_V2X_DENM})
set(V2X_VAM ${CONFIG_MICROBU_V2X_VAM})
set(V2X_HIL ${CONFIG_MICROBU_V2X_HIL})
set(V2X_SECURITY ${CONFIG_MICROBU_V2X_SECURITY})
set(V2X_SECURITY_VERIFY ${CONFIG_MICROBU_V2X_SECURITY_VERIFY})
set(V2X_PKI ${CONFIG_MICROBU_V2X_PKI})
set(V2X_NVS_CREDENTIALS ${CONFIG_MICROBU_V2X_NVS_CREDENTIALS})
else()
project(microbu_v2x LANGUAGES C CXX)
option(V2X_NETWORK "GeoNetworking router, BTP and DCC" ON)
option(V2X_CAM "Release 2 CAM codec/endpoint" ON)
option(V2X_DENM "Release 2 DENM codec/endpoint" ON)
option(V2X_VAM "Release 2 VAM codec/endpoint" ON)
set(V2X_HIL OFF)
option(V2X_SECURITY "TS 103 097 signing security entity and TS 102 723-8 identifier-change service" ON)
option(V2X_SECURITY_VERIFY "SN-DECAP verification of received secured packets (IEEE 1609.2 clause 5.2, TS 103 097 clause 7.1)" ON)
option(V2X_PKI "TS 102 941 enrolment/authorization request-response core" OFF)
set(V2X_MBEDTLS_ROOT "" CACHE PATH
"Host only: mbedTLS (>= 3.6 or 4.x/TF-PSA-Crypto) source tree; builds the PSA backend for testing against OpenSSL")
set(VANETZA_SOURCE_DIR "" CACHE PATH
"Host only: an already patched Vanetza tree (default: build it from external/vanetza and ../vanetza/patches)")
add_subdirectory("${V2X_PORT}/../vanetza" "${CMAKE_BINARY_DIR}/vanetza")
add_library(microbu_v2x STATIC src/access.cpp)
add_library(Microbu::v2x ALIAS microbu_v2x)
set(V2X_TARGET microbu_v2x)
target_include_directories(${V2X_TARGET} PUBLIC include)
target_link_libraries(${V2X_TARGET} PUBLIC vanetza)
endif()
target_compile_features(${V2X_TARGET} PUBLIC cxx_std_17)
set_target_properties(${V2X_TARGET} PROPERTIES C_STANDARD 11 CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES)
if(V2X_SECURITY AND NOT V2X_NETWORK)
message(FATAL_ERROR "The security entity serves the GeoNetworking layer: V2X_SECURITY requires V2X_NETWORK")
endif()
if(V2X_SECURITY_VERIFY AND NOT V2X_SECURITY)
message(FATAL_ERROR "V2X_SECURITY_VERIFY requires V2X_SECURITY")
endif()
if(V2X_PKI AND NOT V2X_SECURITY)
message(FATAL_ERROR "V2X_PKI requires V2X_SECURITY")
endif()
target_compile_definitions(${V2X_TARGET} PUBLIC
V2X_NETWORK=$<BOOL:${V2X_NETWORK}> V2X_CAM=$<BOOL:${V2X_CAM}>
V2X_DENM=$<BOOL:${V2X_DENM}> V2X_VAM=$<BOOL:${V2X_VAM}> V2X_HIL=$<BOOL:${V2X_HIL}>
V2X_SECURITY=$<BOOL:${V2X_SECURITY}> V2X_SECURITY_VERIFY=$<BOOL:${V2X_SECURITY_VERIFY}>
V2X_PKI=$<BOOL:${V2X_PKI}>)
set(_sources "${V2X_PORT}/src/its_g5_frame.cpp")
if(V2X_NETWORK)
list(APPEND _sources "${V2X_PORT}/src/stack.cpp" "${V2X_PORT}/src/management.cpp")
if(NOT ESP_PLATFORM)
find_package(OpenSSL REQUIRED COMPONENTS Crypto)
target_link_libraries(${V2X_TARGET} PRIVATE OpenSSL::Crypto)
endif()
endif()
if(V2X_CAM OR V2X_DENM OR V2X_VAM)
list(APPEND _sources "${V2X_PORT}/src/facilities.cpp")
endif()
if(V2X_HIL)
list(APPEND _sources "${V2X_PORT}/src/hil.cpp")
endif()
if(V2X_SECURITY)
list(APPEND _sources "${V2X_PORT}/src/ecc.cpp" "${V2X_PORT}/src/security_module.cpp"
"${V2X_PORT}/src/security.cpp" "${V2X_PORT}/src/identity_manager.cpp"
"${V2X_PORT}/src/sign_header_policy.cpp" "${V2X_PORT}/src/credentials.cpp")
if(ESP_PLATFORM)
list(APPEND _sources "${V2X_PORT}/src/backend_mbedtls.cpp" "${V2X_PORT}/src/security_backend.cpp"
"${V2X_PORT}/src/local_security.cpp")
if(CONFIG_MICROBU_V2X_CRYPTO_SE051 OR CONFIG_MICROBU_V2X_CRYPTO_V2X_HSM)
if(NOT MICROBU_CRYPTO_ADAPTER_COMPONENT)
message(FATAL_ERROR "External security module selected: set MICROBU_CRYPTO_ADAPTER_COMPONENT to a real adapter component")
endif()
endif()
target_compile_definitions(${V2X_TARGET} PUBLIC V2X_BACKEND_MBEDTLS=1)
if(V2X_NVS_CREDENTIALS)
# CredentialStore on nvs_flash (credentials.hpp); the application initialises NVS
list(APPEND _sources "${V2X_PORT}/src/nvs_credential_store.cpp")
target_compile_definitions(${V2X_TARGET} PUBLIC V2X_NVS_CREDENTIALS=1)
endif()
else()
target_compile_definitions(${V2X_TARGET} PUBLIC V2X_BACKEND_OPENSSL=1)
target_compile_definitions(${V2X_TARGET} PRIVATE OPENSSL_API_COMPAT=0x10101000L)
if(V2X_MBEDTLS_ROOT)
set(ENABLE_PROGRAMS OFF CACHE BOOL "" FORCE)
set(ENABLE_TESTING OFF CACHE BOOL "" FORCE)
set(MBEDTLS_FATAL_WARNINGS OFF CACHE BOOL "" FORCE)
set(GEN_FILES OFF CACHE BOOL "" FORCE)
# ESP-IDF's mbedTLS fork includes "mbedtls/bignum.h"/"mbedtls/ecp.h" wrappers that only
# its own port directory provides (they wrap the TF-PSA-Crypto private headers and add
# hardware-acceleration hooks). Recreate the plain wrappers so the same tree builds here.
set(_v2x_mbedtls_shim "${CMAKE_BINARY_DIR}/mbedtls-shim/mbedtls")
foreach(_hdr bignum ecp)
if(EXISTS "${V2X_MBEDTLS_ROOT}/tf-psa-crypto/drivers/builtin/include/mbedtls/private/${_hdr}.h"
AND NOT EXISTS "${V2X_MBEDTLS_ROOT}/include/mbedtls/${_hdr}.h")
file(WRITE "${_v2x_mbedtls_shim}/${_hdr}.h"
"#pragma once
#define MBEDTLS_DECLARE_PRIVATE_IDENTIFIERS
#include \"mbedtls/private/${_hdr}.h\"
")
endif()
endforeach()
if(EXISTS "${_v2x_mbedtls_shim}")
file(WRITE "${CMAKE_BINARY_DIR}/mbedtls-shim/sdkconfig.h" "#pragma once
")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I${CMAKE_BINARY_DIR}/mbedtls-shim")
endif()
add_subdirectory("${V2X_MBEDTLS_ROOT}" "${CMAKE_BINARY_DIR}/mbedtls" EXCLUDE_FROM_ALL)
if(TARGET tfpsacrypto)
set(_v2x_psa tfpsacrypto) # mbedTLS 4.x
else()
set(_v2x_psa mbedcrypto) # mbedTLS 3.x
endif()
list(APPEND _sources "${V2X_PORT}/src/backend_mbedtls.cpp")
target_link_libraries(${V2X_TARGET} PUBLIC ${_v2x_psa})
target_compile_definitions(${V2X_TARGET} PUBLIC V2X_BACKEND_MBEDTLS=1)
endif()
endif()
if(V2X_PKI)
list(APPEND _sources "${V2X_PORT}/src/pki.cpp" "${V2X_PORT}/src/trust_update.cpp")
if(ESP_PLATFORM OR V2X_MBEDTLS_ROOT)
list(APPEND _sources "${V2X_PORT}/src/ecies_mbedtls.cpp")
endif()
if(NOT ESP_PLATFORM)
list(APPEND _sources "${V2X_PORT}/src/ecies_openssl.cpp")
endif()
endif()
endif()
list(REMOVE_DUPLICATES _sources)
target_sources(${V2X_TARGET} PRIVATE ${_sources})
if(ESP_PLATFORM AND CONFIG_MICROBU_V2X_RADIO_C5)
include("${V2X_PORT}/radio_c5.cmake")
endif()
if(ESP_PLATFORM AND CONFIG_IDF_TARGET_ESP32C5)
# ROM UART0 clock repair for warm resets (see the source); kept by an undefined-symbol reference.
target_sources(${V2X_TARGET} PRIVATE "${V2X_PORT}/src/esp32c5_rom_uart_clock.c")
target_link_libraries(${V2X_TARGET} INTERFACE "-u v2x_esp32c5_rom_uart_clock_link")
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(${V2X_TARGET} PRIVATE -ffunction-sections -fdata-sections
-Wno-error=deprecated-declarations)
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15)
target_compile_options(${V2X_TARGET} PRIVATE -Wno-error=deprecated-variadic-comma-omission)
endif()
endif()
if(ESP_PLATFORM)
target_compile_options(${V2X_TARGET} PRIVATE
$<$<COMPILE_LANGUAGE:C>:-Wno-error=unused-function>
$<$<COMPILE_LANGUAGE:C>:-Wno-error=maybe-uninitialized>)
endif()