Skip to content

Apply listen-only mode requested via ip link - #20

Open
knakazawa-ics wants to merge 1 commit into
intrepidcs:masterfrom
knakazawa-ics:feature/listenonly-issue25
Open

Apply listen-only mode requested via ip link#20
knakazawa-ics wants to merge 1 commit into
intrepidcs:masterfrom
knakazawa-ics:feature/listenonly-issue25

Conversation

@knakazawa-ics

@knakazawa-ics knakazawa-ics commented Aug 11, 2026

Copy link
Copy Markdown

Companion to intrepidcs/intrepid-socketcan-kernel-module#27; the two are meant to
land together.

The kernel module encodes CAN_CTRLMODE_LISTENONLY in bit 30 of the settings-change
report. This PR masks the flag out of the bitrate and toggles CAN_SETTINGS.Mode
between LISTEN_ONLY and NORMAL through
IDeviceSettings::getMutableCANSettingsFor(), alongside the existing baudrate
handling.

Design decisions (please push back if you disagree):

  • The mode is only toggled between NORMAL and LISTEN_ONLY. Other modes (LOOPBACK,
    LISTEN_ALL, DISABLE) that may have been configured with other tools are left
    untouched by bitrate-only changes.
  • The mode is staged only after both baudrates were accepted, so a rejected baudrate
    cannot leave a half-staged mode in the settings buffer (which a later unrelated
    apply() would otherwise flush to the device).
  • The device lookup now takes openDevicesMutex: this branch previously scanned
    openDevices unlocked while the search thread can erase entries (this is the
    branch the PR extends, so the fix is included here rather than split out).
    Settings are staged and applied outside the lock so the search and RPC threads
    are not blocked while IDeviceSettings::apply() runs, which can take several
    seconds.
  • settings->apply() persists to EEPROM, same as the existing baudrate path. That
    means a listen-only setting survives daemon shutdown and is visible to other tools
    (we hit exactly this during testing: a device left in listen-only kept withholding
    ACKs on a bench bus afterwards, failing every other node's transmissions). If you
    would rather use volatile settings (apply(true)) for ip-link-driven changes, I
    can change it, though that would also change the existing baudrate behavior.
  • CMakeLists is already at VERSION 3.2.0 on master, which is what the kernel module's
    version gate expects, so no version bump is included.

Tested end-to-end on Ubuntu 22.04.5 with a neoVI FIRE 3 and a ValueCAN 4-2, each
exercised as the SocketCAN device (details in the kernel PR), with
LIBICSNEO_USE_SERVD=0 set for discovery (stock discovery is currently affected by #21). The daemon logs the decoded request:

Settings change, device 0, baudrate 500000 fd_baudrate 0 listen_only 1

The kernel module (intrepidcs/intrepid-socketcan-kernel-module#25)
encodes CAN_CTRLMODE_LISTENONLY in a spare high bit of the
settings-change report. Decode it and toggle CAN_SETTINGS.Mode
between LISTEN_ONLY and NORMAL through
IDeviceSettings::getMutableCANSettingsFor() when applying, alongside the
existing baudrate handling. Other modes (LOOPBACK, LISTEN_ALL, DISABLE)
that may have been configured with other tools are left untouched by
bitrate-only changes, and the mode is only staged once the requested
baudrates have been accepted, so a rejected baudrate cannot leave a
half-staged mode behind.

The device lookup now takes openDevicesMutex (this path previously
scanned openDevices unlocked while the search thread could mutate it),
and settings are staged and applied outside the lock so the search and
RPC threads are not blocked while IDeviceSettings::apply() runs, which
can take several seconds.

Signed-off-by: Koki Nakazawa <knakazawa@intrepidcs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant