diff --git a/opendbc_repo/opendbc/car/volvo/helpers.py b/opendbc_repo/opendbc/car/volvo/helpers.py index a479456d26..c648e9fe11 100644 --- a/opendbc_repo/opendbc/car/volvo/helpers.py +++ b/opendbc_repo/opendbc/car/volvo/helpers.py @@ -163,8 +163,9 @@ def pscm_status_validation_class(data): # Keep pending stock status in the same validation class as the native cache. checksum_valid = (data[0] == checksum_1_pscm_related_message(data[1], data[2]) and data[3] == checksum_2_pscm_related_message(data[2])) - quality_valid = ((data[1] & 8) == 0 and 0x80 <= data[2] <= 0x8E and - data[1] >> 4 == data[2] & 15) + counter, replica = data[1] >> 4, data[2] & 15 + quality_valid = ((data[1] & 8) == 0 and 0x80 <= data[2] <= 0x8E and counter < 15 and + (counter - replica) % 15 in (0, 1)) return data[2] >> 4, checksum_valid, quality_valid diff --git a/opendbc_repo/opendbc/car/volvo/tests/test_cma_pscm_withdrawal.py b/opendbc_repo/opendbc/car/volvo/tests/test_cma_pscm_withdrawal.py index f8e7d69973..1068bdce9f 100644 --- a/opendbc_repo/opendbc/car/volvo/tests/test_cma_pscm_withdrawal.py +++ b/opendbc_repo/opendbc/car/volvo/tests/test_cma_pscm_withdrawal.py @@ -39,7 +39,7 @@ def forwarded(frames): GOOD = status(0x11, 0x81) -OFFSET = status(0x21, 0x81) +OFFSET = status(0x31, 0x81) @pytest.mark.parametrize('unsupported', [ @@ -86,3 +86,27 @@ def test_missing_status_cannot_grant_host_lateral(): assert not ci.CC.lat_active assert pscm_status_validation_class(GOOD) == (8, True, True) assert pscm_status_validation_class(OFFSET) == (8, True, False) + + +@pytest.mark.parametrize('counter', range(15)) +@pytest.mark.parametrize('lag', [0, 1]) +def test_supported_counter_relationship_keeps_host_active(counter, lag): + ci = interface() + step(ci, 40, True) + packet = status((counter << 4) | 1, 0x80 | ((counter - lag) % 15)) + assert pscm_status_validation_class(packet) == (8, True, True) + step(ci, 41, True, packet) + assert ci.CC.lat_active and not ci.CS.pscm_rearm_required + incoming, messages = step(ci, 42, False, packet) + assert messages == forwarded(incoming) + + +@pytest.mark.parametrize('counter,replica', [(15, 14), (15, 0), (0, 1), (0, 13), (1, 14)]) +def test_other_counter_relationships_still_withdraw(counter, replica): + ci = interface() + step(ci, 40, True) + packet = status((counter << 4) | 1, 0x80 | replica) + assert pscm_status_validation_class(packet) == (8, True, False) + incoming, messages = step(ci, 41, True, packet) + assert not ci.CC.lat_active and ci.CS.pscm_rearm_required + assert messages == forwarded(incoming) diff --git a/opendbc_repo/opendbc/safety/modes/volvo_cma.h b/opendbc_repo/opendbc/safety/modes/volvo_cma.h index d93e366ae0..e498a0926a 100644 --- a/opendbc_repo/opendbc/safety/modes/volvo_cma.h +++ b/opendbc_repo/opendbc/safety/modes/volvo_cma.h @@ -277,7 +277,7 @@ static bool volvo_cma_lca2_quality(const CANPacket_t *msg) { return valid; } static bool volvo_cma_receiver_quality(const CANPacket_t *msg) { - return volvo_cma_quality(msg) && volvo_cma_lca2_quality(msg); + return volvo_cma_quality(msg, volvo_cma_lca2_mod15) && volvo_cma_lca2_quality(msg); } // Unchanged native status is transport evidence, never valid control evidence. diff --git a/opendbc_repo/opendbc/safety/modes/volvo_cma_integrity.h b/opendbc_repo/opendbc/safety/modes/volvo_cma_integrity.h index db841acd73..54cfabef10 100644 --- a/opendbc_repo/opendbc/safety/modes/volvo_cma_integrity.h +++ b/opendbc_repo/opendbc/safety/modes/volvo_cma_integrity.h @@ -117,15 +117,15 @@ static uint32_t volvo_cma_compute_checksum(const CANPacket_t *msg) { } return value; } -static bool volvo_cma_quality(const CANPacket_t *msg) { +static bool volvo_cma_quality(const CANPacket_t *msg, bool allow_counter_lag) { bool valid = true; if (msg->addr == 0x17U) { - // Pinned encoder uses modulo-15 replicated counters and the captured - // checksum table only covers byte2 0x80..0x8E. A fallback zero checksum - // cannot turn an unobserved receiver state into valid control evidence. - // Echo bit3 is explicitly unconstrained in the pinned checksum derivation. + // Captured source counters are equal or the replica lags one modulo 15. + // Unknown status/checksum domains and unconstrained echo bit3 stay unsupported. + const uint8_t counter = msg->data[1] >> 4U; + const uint8_t replica = msg->data[2] & 0xFU; valid = ((msg->data[1] & 0x8U) == 0U) && (msg->data[2] >= 0x80U) && (msg->data[2] <= 0x8EU) && - ((msg->data[1] >> 4U) == (msg->data[2] & 0xFU)); + (counter < 15U) && ((counter == replica) || (allow_counter_lag && (counter == ((replica + 1U) % 15U)))); } return valid; } diff --git a/opendbc_repo/opendbc/safety/tests/test_polestar_counters.py b/opendbc_repo/opendbc/safety/tests/test_polestar_counters.py index 2f31d5809b..a1776b3d68 100644 --- a/opendbc_repo/opendbc/safety/tests/test_polestar_counters.py +++ b/opendbc_repo/opendbc/safety/tests/test_polestar_counters.py @@ -282,3 +282,68 @@ class TestPolestarCounters(unittest.TestCase): self.assertEqual(unchanged[1], status[1]) self.assertTrue(self.tx(unchanged)) self.assertFalse(self.safety.get_controls_allowed()) + + def pscm_counter_status(self, counter, replica): + data = bytearray(8) + data[1] = (counter << 4) | 1 + data[2] = 0x80 | replica + return cma.checksummed((0x17, data, 2)) + + def test_pscm_equal_and_one_count_lag_keep_permission(self): + for counter in range(15): + for lag in (0, 1): + with self.subTest(counter=counter, lag=lag): + self.reset() + self.feed() + status = self.pscm_counter_status(counter, (counter - lag) % 15) + self.assertTrue(self.rx(status)) + self.assertTrue(self.safety.get_controls_allowed()) + self.assertTrue(self.tx(self.relay(status))) + self.assertTrue(self.tx(self.lca_command())) + + def test_pscm_other_counter_relationships_still_withdraw(self): + for counter, replica in ((15, 14), (15, 0), (0, 1), (0, 13), (1, 14)): + with self.subTest(counter=counter, replica=replica): + self.reset() + self.feed() + status = self.pscm_counter_status(counter, replica) + self.assertFalse(self.rx(status)) + self.assertFalse(self.safety.get_controls_allowed()) + self.safety.safety_tick() + self.assertFalse(self.safety.safety_config_valid()) + self.assertTrue(self.tx(self.relay(status))) + self.safety.set_controls_allowed(True) + self.assertFalse(self.tx(self.lca_command())) + + def test_pscm_lag_retains_crc_identity_and_freshness_checks(self): + status = self.pscm_counter_status(0, 14) + for pos in (0, 3): + self.reset() + self.feed() + data = bytearray(status[1]) + data[pos] ^= 1 + self.assertFalse(self.rx((0x17, data, 2))) + self.assertFalse(self.safety.get_controls_allowed()) + for bus in (0, 1, 3, 4, 5, 6, 7): + self.reset() + self.feed(cruise=False) + self.rx((0x17, status[1], bus)) + self.assertFalse(self.tx(self.relay(status))) + self.reset() + self.feed(cruise=False) + self.assertTrue(self.rx(status)) + self.safety.set_timer(110000) + self.assertTrue(self.tx(self.relay(status))) + self.safety.set_timer(110001) + self.assertFalse(self.tx(self.relay(status))) + + def test_pscm_lag_does_not_change_other_native_profiles(self): + try: + for param in (0, 1): + self.PARAM = param + self.setUp() + self.feed() + self.assertFalse(self.rx(self.pscm_counter_status(0, 14))) + self.assertFalse(self.safety.get_controls_allowed()) + finally: + self.PARAM = 5 diff --git a/panda/board/obj/body_h7.bin.signed b/panda/board/obj/body_h7.bin.signed index ac9ed432e3..d1adda8429 100644 Binary files a/panda/board/obj/body_h7.bin.signed and b/panda/board/obj/body_h7.bin.signed differ diff --git a/panda/board/obj/bootstub.body_h7.bin b/panda/board/obj/bootstub.body_h7.bin index 52e490816f..776e422d56 100644 Binary files a/panda/board/obj/bootstub.body_h7.bin and b/panda/board/obj/bootstub.body_h7.bin differ diff --git a/panda/board/obj/bootstub.panda.bin b/panda/board/obj/bootstub.panda.bin index 0b3f97afde..3eb85afc09 100644 Binary files a/panda/board/obj/bootstub.panda.bin and b/panda/board/obj/bootstub.panda.bin differ diff --git a/panda/board/obj/bootstub.panda_can_ignition_only.bin b/panda/board/obj/bootstub.panda_can_ignition_only.bin index 0b3f97afde..3eb85afc09 100644 Binary files a/panda/board/obj/bootstub.panda_can_ignition_only.bin and b/panda/board/obj/bootstub.panda_can_ignition_only.bin differ diff --git a/panda/board/obj/bootstub.panda_h7.bin b/panda/board/obj/bootstub.panda_h7.bin index 78d180ab69..ce3019d184 100644 Binary files a/panda/board/obj/bootstub.panda_h7.bin and b/panda/board/obj/bootstub.panda_h7.bin differ diff --git a/panda/board/obj/bootstub.panda_h7_can_ignition_only.bin b/panda/board/obj/bootstub.panda_h7_can_ignition_only.bin index 78d180ab69..ce3019d184 100644 Binary files a/panda/board/obj/bootstub.panda_h7_can_ignition_only.bin and b/panda/board/obj/bootstub.panda_h7_can_ignition_only.bin differ diff --git a/panda/board/obj/bootstub.panda_h7_hkg_remote.bin b/panda/board/obj/bootstub.panda_h7_hkg_remote.bin index 78d180ab69..ce3019d184 100644 Binary files a/panda/board/obj/bootstub.panda_h7_hkg_remote.bin and b/panda/board/obj/bootstub.panda_h7_hkg_remote.bin differ diff --git a/panda/board/obj/bootstub.panda_h7_hkg_remote_can_ignition_only.bin b/panda/board/obj/bootstub.panda_h7_hkg_remote_can_ignition_only.bin index 78d180ab69..ce3019d184 100644 Binary files a/panda/board/obj/bootstub.panda_h7_hkg_remote_can_ignition_only.bin and b/panda/board/obj/bootstub.panda_h7_hkg_remote_can_ignition_only.bin differ diff --git a/panda/board/obj/bootstub.panda_h7_remote.bin b/panda/board/obj/bootstub.panda_h7_remote.bin index 78d180ab69..ce3019d184 100644 Binary files a/panda/board/obj/bootstub.panda_h7_remote.bin and b/panda/board/obj/bootstub.panda_h7_remote.bin differ diff --git a/panda/board/obj/bootstub.panda_h7_remote_can_ignition_only.bin b/panda/board/obj/bootstub.panda_h7_remote_can_ignition_only.bin index 78d180ab69..ce3019d184 100644 Binary files a/panda/board/obj/bootstub.panda_h7_remote_can_ignition_only.bin and b/panda/board/obj/bootstub.panda_h7_remote_can_ignition_only.bin differ diff --git a/panda/board/obj/bootstub.panda_h7_tesla_wake.bin b/panda/board/obj/bootstub.panda_h7_tesla_wake.bin index 78d180ab69..ce3019d184 100644 Binary files a/panda/board/obj/bootstub.panda_h7_tesla_wake.bin and b/panda/board/obj/bootstub.panda_h7_tesla_wake.bin differ diff --git a/panda/board/obj/bootstub.panda_h7_tesla_wake_can_ignition_only.bin b/panda/board/obj/bootstub.panda_h7_tesla_wake_can_ignition_only.bin index 78d180ab69..ce3019d184 100644 Binary files a/panda/board/obj/bootstub.panda_h7_tesla_wake_can_ignition_only.bin and b/panda/board/obj/bootstub.panda_h7_tesla_wake_can_ignition_only.bin differ diff --git a/panda/board/obj/bootstub.panda_hkg_remote.bin b/panda/board/obj/bootstub.panda_hkg_remote.bin index 0b3f97afde..3eb85afc09 100644 Binary files a/panda/board/obj/bootstub.panda_hkg_remote.bin and b/panda/board/obj/bootstub.panda_hkg_remote.bin differ diff --git a/panda/board/obj/bootstub.panda_hkg_remote_can_ignition_only.bin b/panda/board/obj/bootstub.panda_hkg_remote_can_ignition_only.bin index 0b3f97afde..3eb85afc09 100644 Binary files a/panda/board/obj/bootstub.panda_hkg_remote_can_ignition_only.bin and b/panda/board/obj/bootstub.panda_hkg_remote_can_ignition_only.bin differ diff --git a/panda/board/obj/bootstub.panda_remote.bin b/panda/board/obj/bootstub.panda_remote.bin index 0b3f97afde..3eb85afc09 100644 Binary files a/panda/board/obj/bootstub.panda_remote.bin and b/panda/board/obj/bootstub.panda_remote.bin differ diff --git a/panda/board/obj/bootstub.panda_remote_can_ignition_only.bin b/panda/board/obj/bootstub.panda_remote_can_ignition_only.bin index 0b3f97afde..3eb85afc09 100644 Binary files a/panda/board/obj/bootstub.panda_remote_can_ignition_only.bin and b/panda/board/obj/bootstub.panda_remote_can_ignition_only.bin differ diff --git a/panda/board/obj/bootstub.panda_tesla_wake.bin b/panda/board/obj/bootstub.panda_tesla_wake.bin index 0b3f97afde..3eb85afc09 100644 Binary files a/panda/board/obj/bootstub.panda_tesla_wake.bin and b/panda/board/obj/bootstub.panda_tesla_wake.bin differ diff --git a/panda/board/obj/bootstub.panda_tesla_wake_can_ignition_only.bin b/panda/board/obj/bootstub.panda_tesla_wake_can_ignition_only.bin index 0b3f97afde..3eb85afc09 100644 Binary files a/panda/board/obj/bootstub.panda_tesla_wake_can_ignition_only.bin and b/panda/board/obj/bootstub.panda_tesla_wake_can_ignition_only.bin differ diff --git a/panda/board/obj/gitversion.h b/panda/board/obj/gitversion.h index 0d1c0d4f26..ba6cc04123 100644 --- a/panda/board/obj/gitversion.h +++ b/panda/board/obj/gitversion.h @@ -1,4 +1,4 @@ #pragma once extern const uint8_t gitversion[29]; -const uint8_t gitversion[29] = "DEV-5b5ea7b3-Pf38f504f-DEBUG"; +const uint8_t gitversion[29] = "DEV-efa73f99-Pf38f504f-DEBUG"; diff --git a/panda/board/obj/panda.bin.signed b/panda/board/obj/panda.bin.signed index a27f65b472..16242f8548 100644 Binary files a/panda/board/obj/panda.bin.signed and b/panda/board/obj/panda.bin.signed differ diff --git a/panda/board/obj/panda_can_ignition_only.bin.signed b/panda/board/obj/panda_can_ignition_only.bin.signed index 33c3587c61..b0800597fc 100644 Binary files a/panda/board/obj/panda_can_ignition_only.bin.signed and b/panda/board/obj/panda_can_ignition_only.bin.signed differ diff --git a/panda/board/obj/panda_h7.bin.signed b/panda/board/obj/panda_h7.bin.signed index 79cf14e469..45a5ec40ee 100644 Binary files a/panda/board/obj/panda_h7.bin.signed and b/panda/board/obj/panda_h7.bin.signed differ diff --git a/panda/board/obj/panda_h7_can_ignition_only.bin.signed b/panda/board/obj/panda_h7_can_ignition_only.bin.signed index d919de6f49..99ec6afbfb 100644 Binary files a/panda/board/obj/panda_h7_can_ignition_only.bin.signed and b/panda/board/obj/panda_h7_can_ignition_only.bin.signed differ diff --git a/panda/board/obj/panda_h7_hkg_remote.bin.signed b/panda/board/obj/panda_h7_hkg_remote.bin.signed index a905cbf3b7..ddef8e67bf 100644 Binary files a/panda/board/obj/panda_h7_hkg_remote.bin.signed and b/panda/board/obj/panda_h7_hkg_remote.bin.signed differ diff --git a/panda/board/obj/panda_h7_hkg_remote_can_ignition_only.bin.signed b/panda/board/obj/panda_h7_hkg_remote_can_ignition_only.bin.signed index 6cd3204990..efa015e887 100644 Binary files a/panda/board/obj/panda_h7_hkg_remote_can_ignition_only.bin.signed and b/panda/board/obj/panda_h7_hkg_remote_can_ignition_only.bin.signed differ diff --git a/panda/board/obj/panda_h7_remote.bin.signed b/panda/board/obj/panda_h7_remote.bin.signed index b0be7b3936..627b0b4575 100644 Binary files a/panda/board/obj/panda_h7_remote.bin.signed and b/panda/board/obj/panda_h7_remote.bin.signed differ diff --git a/panda/board/obj/panda_h7_remote_can_ignition_only.bin.signed b/panda/board/obj/panda_h7_remote_can_ignition_only.bin.signed index 8a447733c3..d322cdfc12 100644 Binary files a/panda/board/obj/panda_h7_remote_can_ignition_only.bin.signed and b/panda/board/obj/panda_h7_remote_can_ignition_only.bin.signed differ diff --git a/panda/board/obj/panda_h7_tesla_wake.bin.signed b/panda/board/obj/panda_h7_tesla_wake.bin.signed index db31d94651..a794437b5a 100644 Binary files a/panda/board/obj/panda_h7_tesla_wake.bin.signed and b/panda/board/obj/panda_h7_tesla_wake.bin.signed differ diff --git a/panda/board/obj/panda_h7_tesla_wake_can_ignition_only.bin.signed b/panda/board/obj/panda_h7_tesla_wake_can_ignition_only.bin.signed index 4207b999b3..e0def8ee3f 100644 Binary files a/panda/board/obj/panda_h7_tesla_wake_can_ignition_only.bin.signed and b/panda/board/obj/panda_h7_tesla_wake_can_ignition_only.bin.signed differ diff --git a/panda/board/obj/panda_hkg_remote.bin.signed b/panda/board/obj/panda_hkg_remote.bin.signed index 1bdfcb2b0d..b6cc7175ce 100644 Binary files a/panda/board/obj/panda_hkg_remote.bin.signed and b/panda/board/obj/panda_hkg_remote.bin.signed differ diff --git a/panda/board/obj/panda_hkg_remote_can_ignition_only.bin.signed b/panda/board/obj/panda_hkg_remote_can_ignition_only.bin.signed index 54ec7fb91c..c8407be291 100644 Binary files a/panda/board/obj/panda_hkg_remote_can_ignition_only.bin.signed and b/panda/board/obj/panda_hkg_remote_can_ignition_only.bin.signed differ diff --git a/panda/board/obj/panda_remote.bin.signed b/panda/board/obj/panda_remote.bin.signed index 0f9c9a9483..d9adccf3c9 100644 Binary files a/panda/board/obj/panda_remote.bin.signed and b/panda/board/obj/panda_remote.bin.signed differ diff --git a/panda/board/obj/panda_remote_can_ignition_only.bin.signed b/panda/board/obj/panda_remote_can_ignition_only.bin.signed index 5a60fcf6e8..6d7d81f5f5 100644 Binary files a/panda/board/obj/panda_remote_can_ignition_only.bin.signed and b/panda/board/obj/panda_remote_can_ignition_only.bin.signed differ diff --git a/panda/board/obj/panda_tesla_wake.bin.signed b/panda/board/obj/panda_tesla_wake.bin.signed index f30c74eb27..f8bb6eafea 100644 Binary files a/panda/board/obj/panda_tesla_wake.bin.signed and b/panda/board/obj/panda_tesla_wake.bin.signed differ diff --git a/panda/board/obj/panda_tesla_wake_can_ignition_only.bin.signed b/panda/board/obj/panda_tesla_wake_can_ignition_only.bin.signed index 2829f71b39..69645bb4aa 100644 Binary files a/panda/board/obj/panda_tesla_wake_can_ignition_only.bin.signed and b/panda/board/obj/panda_tesla_wake_can_ignition_only.bin.signed differ diff --git a/panda/board/obj/version b/panda/board/obj/version index 1483834353..3bea84d3c0 100644 --- a/panda/board/obj/version +++ b/panda/board/obj/version @@ -1 +1 @@ -DEV-5b5ea7b3-Pf38f504f-DEBUG \ No newline at end of file +DEV-efa73f99-Pf38f504f-DEBUG \ No newline at end of file diff --git a/panda/tests/libpanda/libpanda.so b/panda/tests/libpanda/libpanda.so index 9b07ffe48b..bd0de88876 100755 Binary files a/panda/tests/libpanda/libpanda.so and b/panda/tests/libpanda/libpanda.so differ diff --git a/prebuilt.json b/prebuilt.json index 91d93f2faf..872ee64830 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "3e5c60a01a1c91e2c04e025036427855ca11d783e40ac532dd0e6c144364e548", "schema_version": 1} +{"protected_inventory_sha256": "24f6dfb6ce84fb7dd8c559ae929bfa490e8f6181efaa74461ef1134bb593041d", "schema_version": 1}