Skip to content

Add PGN keyed sniffing callbacks and passive transport protocol reassembly - #709

Open
sujandumaru wants to merge 2 commits into
mainfrom
sujan/passive-message-sniffing
Open

Add PGN keyed sniffing callbacks and passive transport protocol reassembly#709
sujandumaru wants to merge 2 commits into
mainfrom
sujan/passive-message-sniffing

Conversation

@sujandumaru

Copy link
Copy Markdown
Member

Describe your changes

This is the first part of #297. It adds a sniffing callback surface on CANNetworkManager, and also a passive observer which reassembles the destination specific transport protocol messages that are sent between two external control functions.

  • add_sniffed_message_callback(pgn, callback, parent) and its remove on CANNetworkManager. They are shaped like add_any_control_function_parameter_group_number_callback, only without the destination filter. The existing callback families are not touched.
  • is_sniffed_parameter_group_number_of_interest(pgn) tells if somebody asked for a PGN or not. This is what makes the sniffing enabled implicitly, like we discussed, so there is no new configuration option. Registering the first callback is the switch.
  • New TransportProtocolSniffer, one per channel. It follows RTS, CTS, DT and EOMACK between two external control functions and gives the assembled message to those callbacks. It is passive by construction and not by a flag, because the class does not hold any send frame callback at all, so nothing inside it can answer somebody else connection with a CTS or an abort. I did not want to thread a passive bool through TransportProtocolManager, because one mistake there will put frames on a real machine bus.
  • A session is opened only if some callback asked for the PGN in the RTS and the claimed size and the packet count agree. The observed sessions have their own capacity budget, so the third party traffic can not use up a slot which we need for ourself. Sessions are dropped on abort, on EOMACK, on a bad sequence number, or after T2_T3_TIMEOUT_MS of silence.

How has this been tested?

11 new tests in test/core_network_management_tests.cpp, on the network manager level with VirtualCAN. They cover the callback surface, the assembled BAM and connection mode paths, and every way that a passive session can be dropped.

cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DBUILD_EXAMPLES=ON -DBUILD_TESTING=ON -DCAN_DRIVER=SocketCAN
cmake --build build
cd build && ctest --output-on-failure

Out of scope

  1. ETP. There the MAX_PROTOCOL_DATA_LENGTH is around 117 MB, so passively assembling a transfer which nobody asked for is a real memory hazard on a microcontroller. TP is bounded to 1785 bytes per session, that is why it is safe to ship it alone. Need some more discussion on how to handle ETP.
  2. Filtering by control function or by NAME. For now it is PGN filtering only. A consumer can filter on message.get_source_control_function() in two lines, so I did not want to add the API surface speculatively.

@sujandumaru sujandumaru added the enhancement New feature or request label Aug 18, 2026
@sujandumaru
sujandumaru requested a review from ad3154 August 18, 2026 19:43
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant