Files
Ashin Walpola ce18a393ea Fragment large V2X_RX messages and decode road-RSU SPATEMs
The firmware dropped every received ITS message over 494 bytes (one link
message), so a road RSU's 888-byte SPATEM and 1198-byte MAPEM never reached
the phone. V2X_RX now goes out in link fragments up to 2300 bytes, best
effort and non-blocking; messages up to 494 bytes are unchanged.

The app's SPATEM decoder then refused those messages because they carry
intersection and movement names and advisory speed lists. It now reads past
both, checked against asn1tools on 718 distinct messages.

Adds the pure fragmenter with host tests and a pcap replay, a Kotlin
cross-check on the firmware's own fragments, tools/rx_size_compare.py,
docs/08-large-message-reception.md and station-link revision 3.
2026-11-23 17:34:56 +01:00

113 lines
4.7 KiB
Makefile

# Host-side tests for obu-firmware. See README.md: needs gcc and make on PATH (MSYS2 UCRT64), and
# asn1tools under `py -3.11` for the replay check.
#
# make build and run everything: chain, replay, fuzz
# make chain | replay | fuzz | battery one of them
# make fuzz FUZZ_ITER=50000000 FUZZ_SEED=7 a longer or different fuzz run
# make clean remove build/
#
# The firmware sources are compiled straight from ../../main, never copied.
CC = gcc
CXX = g++
PYTHON = python
PYTHON_ASN1 = py -3.11
FW = ../../main
BUILD = build
EXE = $(if $(filter Windows_NT,$(OS)),.exe,)
RECORDINGS = $(wildcard ../../../its-g5-receiver-firmware/recordings/*.pcap)
FUZZ_ITER = 2000000
FUZZ_SEED = 1
# -Werror: these sources must stay warning-free on the host compiler too.
# UBSan in trap mode needs no runtime library, so it works on MinGW; a trap shows up as a crash.
CFLAGS = -std=c11 -O2 -g -Wall -Wextra -Wpedantic -Werror -I$(FW) -I. \
-fsanitize=undefined -fsanitize-undefined-trap-on-error
FW_SRCS = $(FW)/geonet.c dot11p.c $(FW)/gn_unwrap.c
DEPS = test_util.c test_util.h dot11p.h $(FW_SRCS) $(wildcard $(FW)/*.h)
.PHONY: all check chain replay fuzz battery firmware fragments corpus clean
all: check
check: chain replay fuzz battery firmware fragments
$(BUILD):
mkdir -p $@
$(BUILD)/%$(EXE): %.c $(DEPS) | $(BUILD)
$(CC) $(CFLAGS) -o $@ $< test_util.c $(FW_SRCS)
# The pcap goes through pcap_gn_tally.py as a second, independent parser of the same frames.
chain: $(BUILD)/test_chain$(EXE)
$(BUILD)/test_chain$(EXE) $(BUILD)/test_chain.pcap
$(PYTHON) ../pcap_gn_tally.py $(BUILD)/test_chain.pcap
replay: $(BUILD)/test_replay$(EXE)
ifeq ($(RECORDINGS),)
@echo "replay: no recordings in ../../../its-g5-receiver-firmware/recordings, skipped"
else
$(BUILD)/test_replay$(EXE) $(BUILD)/replay.tsv $(RECORDINGS)
$(PYTHON_ASN1) check_replay.py $(BUILD)/replay.tsv $(RECORDINGS)
endif
fuzz: $(BUILD)/fuzz_gn_unwrap$(EXE)
$(BUILD)/fuzz_gn_unwrap$(EXE) $(FUZZ_ITER) $(FUZZ_SEED) $(RECORDINGS)
# Battery policy: C++17, so its own flags.
CXXFLAGS = -std=c++17 -O2 -g -Wall -Wextra -Wpedantic -Werror -I$(FW)
$(BUILD)/test_battery$(EXE): test_battery.cpp $(FW)/battery_policy.hpp | $(BUILD)
$(CXX) $(CXXFLAGS) -o $@ test_battery.cpp
battery: $(BUILD)/test_battery$(EXE)
$(BUILD)/test_battery$(EXE)
clean:
rm -rf $(BUILD)
# Unit tests of the firmware logic that needs no ESP32: link codec against the app's bytes, request
# reassembly, V2X_RX, radio / BLE-guard / clock / battery policies. Prints PASS or FAIL per test and a RESULT line.
$(BUILD)/fw_c_%.o: $(FW)/%.c | $(BUILD)
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD)/fw_c_dot11p.o: dot11p.c dot11p.h | $(BUILD)
$(CC) $(CFLAGS) -c -o $@ $<
FW_CXX_SRCS = $(FW)/link_protocol.cpp $(FW)/tx_policy.cpp $(FW)/its_clock.cpp
$(BUILD)/test_firmware$(EXE): test_firmware.cpp $(FW_CXX_SRCS) $(wildcard $(FW)/*.hpp) $(BUILD)/fw_c_geonet.o $(BUILD)/fw_c_gn_unwrap.o $(BUILD)/fw_c_dot11p.o | $(BUILD)
$(CXX) $(CXXFLAGS) -std=c++20 -I. -o $@ test_firmware.cpp $(FW_CXX_SRCS) $(BUILD)/fw_c_geonet.o $(BUILD)/fw_c_gn_unwrap.o $(BUILD)/fw_c_dot11p.o
firmware: $(BUILD)/test_firmware$(EXE)
$(BUILD)/test_firmware$(EXE)
# Recorded traffic through unwrap -> V2X_RX body -> fragments -> reassembly (the large MAPEMs and SPATEMs of a road RSU).
# Needs a capture: the CiT node's 2026-11-23 recording has 1198-byte MAPEMs and 888-byte SPATEMs.
FRAG_PCAPS = $(wildcard ../../../databases/its5_20261123_150746.pcap) $(RECORDINGS)
$(BUILD)/fw_c_test_util.o: test_util.c test_util.h | $(BUILD)
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD)/test_v2x_fragments$(EXE): test_v2x_fragments.cpp $(BUILD)/fw_c_test_util.o $(BUILD)/fw_c_gn_unwrap.o $(FW)/link_protocol.cpp $(wildcard $(FW)/*.hpp) | $(BUILD)
$(CXX) $(CXXFLAGS) -std=c++20 -I. -fsanitize=undefined -fsanitize-undefined-trap-on-error -o $@ test_v2x_fragments.cpp $(FW)/link_protocol.cpp $(BUILD)/fw_c_test_util.o $(BUILD)/fw_c_gn_unwrap.o
fragments: $(BUILD)/test_v2x_fragments$(EXE)
ifeq ($(FRAG_PCAPS),)
@echo "fragments: no captures, skipped"
else
$(BUILD)/test_v2x_fragments$(EXE) $(FRAG_PCAPS)
endif
# Corpus for the app's GnUnwrapTest (the Kotlin port of gn_unwrap.c): recorded frames, cut and corrupted copies of
# them, with the verdict and fields of the firmware's own code. Writes ../../../app/src/test/resources/gn_unwrap_corpus.tsv
CORPUS_OUT = ../../../app/src/test/resources/gn_unwrap_corpus.tsv
$(BUILD)/dump_corpus$(EXE): dump_corpus.c test_util.c test_util.h $(FW)/gn_unwrap.c $(FW)/gn_unwrap.h | $(BUILD)
$(CC) $(CFLAGS) -o $@ dump_corpus.c test_util.c $(FW)/gn_unwrap.c
corpus: $(BUILD)/dump_corpus$(EXE)
mkdir -p $(dir $(CORPUS_OUT))
$(BUILD)/dump_corpus$(EXE) $(CORPUS_OUT) $(RECORDINGS)