Skip to content

Commit febbf0f

Browse files
authored
safety: only run rx hooks on whitelisted msgs (#1903)
* don't run rx hook on non-allowed messages * better name * fix toyota (bug w/ secoc) * looks like honda is broken * rivian is also bad! (missing EPAS_SystemStatus) * misra so far rivian is also bad! * nissan is fine * tesla is also borked * mazda's good * subaru's fine * gm broke * ford's good * chrysler's good * vw is good * hyundai is broky, canfd is good * Fix Rivian * revert these * do relay malfunction check on all addresses * Found a Tesla bug * fix subaru pg * body * rm * Fix Honda * stash * fix Hyundai * fix * Hyundai: buttons are used always (for interaction) * revert tesla * body: we don't rx _torque_cmd_msg * Revert "body: we don't rx _torque_cmd_msg" This reverts commit 2f973f6. * simpler * GM EV param for correct rxchecks * no need * might read better * rm extras * fix hyundai * we weren't testing lfa (non-hda2), alt buttons, long * fix * tested * rm * not needed * clean up * that too * .
1 parent 05b47fb commit febbf0f

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

opendbc/safety/safety.h

+12-11
Original file line numberDiff line numberDiff line change
@@ -211,19 +211,20 @@ bool safety_rx_hook(const CANPacket_t *to_push) {
211211
bool controls_allowed_prev = controls_allowed;
212212

213213
bool valid = rx_msg_safety_check(to_push, &current_safety_config, current_hooks);
214-
if (valid) {
214+
bool whitelisted = get_addr_check_index(to_push, current_safety_config.rx_checks, current_safety_config.rx_checks_len) != -1;
215+
if (valid && whitelisted) {
215216
current_hooks->rx(to_push);
217+
}
216218

217-
const int bus = GET_BUS(to_push);
218-
const int addr = GET_ADDR(to_push);
219-
220-
// check all tx msgs for liveness on sending bus if specified.
221-
// used to detect a relay malfunction or control messages from disabled ECUs like the radar
222-
for (int i = 0; i < current_safety_config.tx_msgs_len; i++) {
223-
const CanMsg *m = &current_safety_config.tx_msgs[i];
224-
if (m->check_relay) {
225-
generic_rx_checks((m->addr == addr) && (m->bus == bus));
226-
}
219+
// the relay malfunction hook runs on all incoming rx messages.
220+
// check all tx msgs for liveness on sending bus if specified.
221+
// used to detect a relay malfunction or control messages from disabled ECUs like the radar
222+
const int bus = GET_BUS(to_push);
223+
const int addr = GET_ADDR(to_push);
224+
for (int i = 0; i < current_safety_config.tx_msgs_len; i++) {
225+
const CanMsg *m = &current_safety_config.tx_msgs[i];
226+
if (m->check_relay) {
227+
generic_rx_checks((m->addr == addr) && (m->bus == bus));
227228
}
228229
}
229230

opendbc/safety/safety/safety_defaults.h

+3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
#include "safety_declarations.h"
44

5+
// GCOV_EXCL_START
6+
// Unreachable by design (doesn't define any rx msgs)
57
void default_rx_hook(const CANPacket_t *to_push) {
68
UNUSED(to_push);
79
}
10+
// GCOV_EXCL_STOP
811

912
// *** no output safety mode ***
1013

opendbc/safety/tests/test_body.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def test_rx_hook(self):
3838
self.assertFalse(self.safety.get_controls_allowed())
3939
self.assertFalse(self.safety.get_vehicle_moving())
4040

41-
# controls allowed when we get MOTORS_DATA message
41+
# controls allowed and vehicle moving when we get MOTORS_DATA message
4242
self.assertTrue(self._rx(self._torque_cmd_msg(0, 0)))
43-
self.assertTrue(self.safety.get_vehicle_moving()) # always moving
43+
self.assertFalse(self.safety.get_vehicle_moving())
4444
self.assertFalse(self.safety.get_controls_allowed())
4545

4646
self.assertTrue(self._rx(self._motors_data_msg(0, 0)))

0 commit comments

Comments
 (0)