diff --git a/opendbc_repo/opendbc/safety/modes/gm.h b/opendbc_repo/opendbc/safety/modes/gm.h index 3aa18ebd80..219917213f 100644 --- a/opendbc_repo/opendbc/safety/modes/gm.h +++ b/opendbc_repo/opendbc/safety/modes/gm.h @@ -409,7 +409,11 @@ static void gm_rx_hook(const CANPacket_t *msg) { if (gm_malibu_cc_f1 || gm_volt_cc_f1) { if (msg_matches(msg, 0xF1U, 0U) && (GET_LEN(msg) == 6U)) { - gm_malibu_f1_brake = gm_volt_cc_f1 ? (msg->data[1] >= 6U) : ((msg->data[1] >= 21U) || GET_BIT(msg, 1U)); + if (gm_volt_cc_f1) { + gm_malibu_f1_brake = msg->data[1] >= 6U; + } else { + gm_malibu_f1_brake = (msg->data[1] >= 21U) || GET_BIT(msg, 1U); + } } if (msg_matches(msg, 0xC9U, 0U) && (GET_LEN(msg) == 8U)) { gm_malibu_c9_brake = GET_BIT(msg, 40U); @@ -551,9 +555,7 @@ static bool gm_ascm_adas_valid(const CANPacket_t *msg) { return valid; } -static bool gm_tx_hook(const CANPacket_t *msg) { - // This topology has no camera-side receiver after harness interception. - if (gm_volt_camera_removed && (msg->bus == 2U)) { return false; } +static bool gm_vehicle_tx_hook(const CANPacket_t *msg) { const TorqueSteeringLimits GM_STEERING_LIMITS = { .max_torque = 300, .max_rate_up = 10, @@ -862,6 +864,11 @@ static bool gm_tx_hook(const CANPacket_t *msg) { return tx; } +static bool gm_tx_hook(const CANPacket_t *msg) { + // This topology has no camera-side receiver after harness interception. + return !(gm_volt_camera_removed && (msg->bus == 2U)) && gm_vehicle_tx_hook(msg); +} + static bool gm_fwd_hook(int bus_num, int addr) { const bool dashboard_owned = gm_acc_pedal_dashboard_current() && gm_acc_pedal_dashboard_seen && (safety_get_ts_elapsed(microsecond_timer_get(), gm_acc_pedal_dashboard_us) <= 100000U); @@ -878,9 +885,6 @@ static bool gm_fwd_hook(int bus_num, int addr) { (gm_ordinary_camera_removed && (bus_num == 0) && (addr == 0x184)) || (gm_ordinary_camera_removed && (bus_num == 2) && ((addr == 0x180) || (gm_ordinary_camera_removed_long && ((addr == 0x315) || (addr == 0x2CB) || (addr == 0x370) || (addr == 0x2CD))))) || - (gm_volt_camera_removed && (bus_num == 0) && (addr == 0x184)) || - (gm_volt_camera_removed && (bus_num == 2) && ((addr == 0x180) || - (gm_volt_removed_long && ((addr == 0x315) || (addr == 0x2CB) || (addr == 0x370) || (addr == 0x2CD))))) || (gm_sdgm && (bus_num == 0) && (addr == 0x184)) || ((gm_volt_sdgm_long || gm_ordinary_sdgm_long) && (bus_num == 2) && ((addr == 0x315) || (addr == 0x2CD))) || (gm_pedal_acc && (bus_num == 2) && (addr == 0x315) && gm_pedal_owns_longitudinal() && gm_pedal_main_ready() && diff --git a/opendbc_repo/opendbc/safety/tests/test_gm_volt_camera_removed.py b/opendbc_repo/opendbc/safety/tests/test_gm_volt_camera_removed.py index 50afa62fff..da189cd715 100644 --- a/opendbc_repo/opendbc/safety/tests/test_gm_volt_camera_removed.py +++ b/opendbc_repo/opendbc/safety/tests/test_gm_volt_camera_removed.py @@ -117,6 +117,21 @@ class TestGmVoltCameraRemoved(unittest.TestCase): self.mode(0xC150) self.assertFalse(self.safety.safety_tx_hook(self.packet(gmcan.create_buttons(self.packer, 0, 0, 6)))) + def test_removed_camera_blocks_all_forwarding_and_stock_mode_recovers(self): + for word in (0xC150, 0xC151): + if word == 0xC151 and self.release: + continue + self.mode(word) + # The harness has no bus-2 camera receiver. All traffic is withdrawn by + # the global forwarding gate, including identifiers unknown to GM's list. + for bus in (0, 1, 2): + for address in (*range(0x800), 0x18DA10F1, 0x1FFFFFFF): + self.assertEqual(self.safety.safety_fwd_hook(bus, address), -1, (word, bus, address)) + # A later connected-camera owner must restore its ordinary forwarding. + self.mode(5) + self.assertEqual(self.safety.safety_fwd_hook(0, 0x123), 2) + self.assertEqual(self.safety.safety_fwd_hook(2, 0x123), 0) + def test_neutral_checksum_cadence_and_timer_wrap(self): self.mode(0xC150) self.rx('ECMEngineStatus', {'CruiseMainOn': 1})