From cb6af1f3d207140c3d24d954964a0ebf3ac2580d Mon Sep 17 00:00:00 2001 From: zariiii9003 <52598363+zariiii9003@users.noreply.github.com> Date: Tue, 1 Dec 2026 19:58:23 +0000 Subject: [PATCH] etas: mask filter can_id with can_mask before passing it to BOA --- can/interfaces/etas/__init__.py | 2 +- .../+etas-filter-id-mask.fixed.rst | 1 + test/test_etas.py | 25 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 doc/changelog.d/+etas-filter-id-mask.fixed.rst diff --git a/can/interfaces/etas/__init__.py b/can/interfaces/etas/__init__.py index 5f2570c7d..171e52767 100644 --- a/can/interfaces/etas/__init__.py +++ b/can/interfaces/etas/__init__.py @@ -230,7 +230,7 @@ def _apply_filters(self, filters: can.typechecking.CanFilters | None) -> None: for i, filter_ in enumerate(filters): f = OCI_CANRxFilterEx() - f.frameIDValue = filter_["can_id"] + f.frameIDValue = filter_["can_id"] & filter_["can_mask"] f.frameIDMask = filter_["can_mask"] f.tag = 0 f.flagsValue = 0 diff --git a/doc/changelog.d/+etas-filter-id-mask.fixed.rst b/doc/changelog.d/+etas-filter-id-mask.fixed.rst new file mode 100644 index 000000000..b72e316d4 --- /dev/null +++ b/doc/changelog.d/+etas-filter-id-mask.fixed.rst @@ -0,0 +1 @@ +Fixed ``EtasBus`` receiving no frames through a filter whose ``can_id`` sets bits above the 11-bit (standard) or 29-bit (extended) identifier range outside ``can_mask``. diff --git a/test/test_etas.py b/test/test_etas.py index 34ffeca3d..fb61107f0 100644 --- a/test/test_etas.py +++ b/test/test_etas.py @@ -149,6 +149,31 @@ def test_extended_false_filter_rejects_extended_frames(self): [(0x123, 0x7FF, 0, selfreception | extended)], ) + def test_filter_id_bits_outside_mask_are_ignored(self): + """ + Test Scope: + A standard-ID filter whose can_id has bits outside can_mask and + above the 11-bit identifier range installs a BOA filter whose + frameIDValue holds only the bits covered by can_mask. + Preconditions: + An EtasBus created with the filter can_id=0x18FF0123, + can_mask=0x7FF, "extended": False. + Events: + The constructor installs the filter. + Evaluate: + The installed frameIDValue is 0x123 and has no bits above the + 11-bit range, which BOA documents as a filter that passes no frames. + """ + selfreception = self.etas.OCI_CAN_MSG_FLAG_SELFRECEPTION + extended = self.etas.OCI_CAN_MSG_FLAG_EXTENDED + self._bus( + can_filters=[{"can_id": 0x18FF0123, "can_mask": 0x7FF, "extended": False}] + ) + self.assertEqual( + self.installed, + [(0x123, 0x7FF, 0, selfreception | extended)], + ) + if __name__ == "__main__": unittest.main()