Skip to content

Commit 0de6405

Browse files
sshanechrispypatt
authored andcommitted
safety: relay malfunction config (commaai#1959)
* Do Toyota relay malfunction config * clean up * not needed * rm this * rm * fix * great name (rename after commaai#1954) * do gm * need this since we will dynamically block it * subie * some more brands * Ford * Chrysler * Hyundai * huge oof hyundai * toyota & vw * fix * tesla * 0x194 isn't on Honda Bosch * Honda: we can check bus 1 for 0xe4 * misra * static * ugh need this * correct * nl * like * space
1 parent 9344ecb commit 0de6405

19 files changed

+177
-209
lines changed

opendbc/safety/safety.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,18 @@ bool safety_rx_hook(const CANPacket_t *to_push) {
213213
bool valid = rx_msg_safety_check(to_push, &current_safety_config, current_hooks);
214214
if (valid) {
215215
current_hooks->rx(to_push);
216+
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+
}
227+
}
216228
}
217229

218230
// reset mismatches on rising edge of controls_allowed to avoid rare race condition
@@ -337,7 +349,7 @@ static void relay_malfunction_set(void) {
337349
fault_occurred(FAULT_RELAY_MALFUNCTION);
338350
}
339351

340-
void generic_rx_checks(bool stock_ecu_detected) {
352+
static void generic_rx_checks(bool stock_ecu_detected) {
341353
// allow 1s of transition timeout after relay changes state before assessing malfunctioning
342354
const uint32_t RELAY_TRNS_TIMEOUT = 1U;
343355

opendbc/safety/safety/safety_body.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ static safety_config body_init(uint16_t param) {
3434
{.msg = {{0x201, 0, 8, .ignore_checksum = true, .ignore_counter = true, .frequency = 100U}, { 0 }, { 0 }}},
3535
};
3636

37-
static const CanMsg BODY_TX_MSGS[] = {{0x250, 0, 8}, {0x250, 0, 6}, {0x251, 0, 5}, // body
38-
{0x350, 0, 8}, {0x350, 0, 6}, {0x351, 0, 5}, // knee
39-
{0x1, 0, 8}}; // CAN flasher
37+
static const CanMsg BODY_TX_MSGS[] = {{0x250, 0, 8, false}, {0x250, 0, 6, false}, {0x251, 0, 5, false}, // body
38+
{0x350, 0, 8, false}, {0x350, 0, 6, false}, {0x351, 0, 5, false}, // knee
39+
{0x1, 0, 8, false}}; // CAN flasher
4040

4141
UNUSED(param);
4242
return BUILD_SAFETY_CFG(body_rx_checks, BODY_TX_MSGS);

opendbc/safety/safety/safety_chrysler.h

+9-11
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ static void chrysler_rx_hook(const CANPacket_t *to_push) {
100100
if ((bus == 0) && (addr == chrysler_addrs->ESP_1)) {
101101
brake_pressed = ((GET_BYTE(to_push, 0U) & 0xFU) >> 2U) == 1U;
102102
}
103-
104-
generic_rx_checks((bus == 0) && (addr == chrysler_addrs->LKAS_COMMAND));
105103
}
106104

107105
static bool chrysler_tx_hook(const CANPacket_t *to_send) {
@@ -224,15 +222,15 @@ static safety_config chrysler_init(uint16_t param) {
224222
};
225223

226224
static const CanMsg CHRYSLER_TX_MSGS[] = {
227-
{CHRYSLER_ADDRS.CRUISE_BUTTONS, 0, 3},
228-
{CHRYSLER_ADDRS.LKAS_COMMAND, 0, 6},
229-
{CHRYSLER_ADDRS.DAS_6, 0, 8},
225+
{CHRYSLER_ADDRS.CRUISE_BUTTONS, 0, 3, false},
226+
{CHRYSLER_ADDRS.LKAS_COMMAND, 0, 6, true},
227+
{CHRYSLER_ADDRS.DAS_6, 0, 8, false},
230228
};
231229

232230
static const CanMsg CHRYSLER_RAM_DT_TX_MSGS[] = {
233-
{CHRYSLER_RAM_DT_ADDRS.CRUISE_BUTTONS, 2, 3},
234-
{CHRYSLER_RAM_DT_ADDRS.LKAS_COMMAND, 0, 8},
235-
{CHRYSLER_RAM_DT_ADDRS.DAS_6, 0, 8},
231+
{CHRYSLER_RAM_DT_ADDRS.CRUISE_BUTTONS, 2, 3, false},
232+
{CHRYSLER_RAM_DT_ADDRS.LKAS_COMMAND, 0, 8, true},
233+
{CHRYSLER_RAM_DT_ADDRS.DAS_6, 0, 8, false},
236234
};
237235

238236
#ifdef ALLOW_DEBUG
@@ -257,9 +255,9 @@ static safety_config chrysler_init(uint16_t param) {
257255
};
258256

259257
static const CanMsg CHRYSLER_RAM_HD_TX_MSGS[] = {
260-
{CHRYSLER_RAM_HD_ADDRS.CRUISE_BUTTONS, 2, 3},
261-
{CHRYSLER_RAM_HD_ADDRS.LKAS_COMMAND, 0, 8},
262-
{CHRYSLER_RAM_HD_ADDRS.DAS_6, 0, 8},
258+
{CHRYSLER_RAM_HD_ADDRS.CRUISE_BUTTONS, 2, 3, false},
259+
{CHRYSLER_RAM_HD_ADDRS.LKAS_COMMAND, 0, 8, true},
260+
{CHRYSLER_RAM_HD_ADDRS.DAS_6, 0, 8, false},
263261
};
264262

265263
const uint32_t CHRYSLER_PARAM_RAM_HD = 2U; // set for Ram HD platform

opendbc/safety/safety/safety_ford.h

+12-21
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,7 @@ static void ford_rx_hook(const CANPacket_t *to_push) {
186186
bool cruise_engaged = (cruise_state == 4U) || (cruise_state == 5U);
187187
pcm_cruise_check(cruise_engaged);
188188
}
189-
190-
// If steering controls messages are received on the destination bus, it's an indication
191-
// that the relay might be malfunctioning.
192-
bool stock_ecu_detected = ford_lkas_msg_check(addr);
193-
if (ford_longitudinal) {
194-
stock_ecu_detected = stock_ecu_detected || (addr == FORD_ACCDATA);
195-
}
196-
generic_rx_checks(stock_ecu_detected);
197189
}
198-
199190
}
200191

201192
static bool ford_tx_hook(const CANPacket_t *to_send) {
@@ -359,33 +350,33 @@ static safety_config ford_init(uint16_t param) {
359350
{.msg = {{FORD_DesiredTorqBrk, 0, 8, .ignore_checksum = true, .ignore_counter = true, .frequency = 50U}, { 0 }, { 0 }}},
360351
};
361352

362-
#define FORD_COMMON_TX_MSGS \
363-
{FORD_Steering_Data_FD1, 0, 8}, \
364-
{FORD_Steering_Data_FD1, 2, 8}, \
365-
{FORD_ACCDATA_3, 0, 8}, \
366-
{FORD_Lane_Assist_Data1, 0, 8}, \
367-
{FORD_IPMA_Data, 0, 8}, \
353+
#define FORD_COMMON_TX_MSGS \
354+
{FORD_Steering_Data_FD1, 0, 8, false}, \
355+
{FORD_Steering_Data_FD1, 2, 8, false}, \
356+
{FORD_ACCDATA_3, 0, 8, true}, \
357+
{FORD_Lane_Assist_Data1, 0, 8, true}, \
358+
{FORD_IPMA_Data, 0, 8, true}, \
368359

369360
static const CanMsg FORD_CANFD_LONG_TX_MSGS[] = {
370361
FORD_COMMON_TX_MSGS
371-
{FORD_ACCDATA, 0, 8},
372-
{FORD_LateralMotionControl2, 0, 8},
362+
{FORD_ACCDATA, 0, 8, true},
363+
{FORD_LateralMotionControl2, 0, 8, true},
373364
};
374365

375366
static const CanMsg FORD_CANFD_STOCK_TX_MSGS[] = {
376367
FORD_COMMON_TX_MSGS
377-
{FORD_LateralMotionControl2, 0, 8},
368+
{FORD_LateralMotionControl2, 0, 8, true},
378369
};
379370

380371
static const CanMsg FORD_STOCK_TX_MSGS[] = {
381372
FORD_COMMON_TX_MSGS
382-
{FORD_LateralMotionControl, 0, 8},
373+
{FORD_LateralMotionControl, 0, 8, true},
383374
};
384375

385376
static const CanMsg FORD_LONG_TX_MSGS[] = {
386377
FORD_COMMON_TX_MSGS
387-
{FORD_ACCDATA, 0, 8},
388-
{FORD_LateralMotionControl, 0, 8},
378+
{FORD_ACCDATA, 0, 8, true},
379+
{FORD_LateralMotionControl, 0, 8, true},
389380
};
390381

391382
const uint16_t FORD_PARAM_CANFD = 2;

opendbc/safety/safety/safety_gm.h

+7-15
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,6 @@ static void gm_rx_hook(const CANPacket_t *to_push) {
8484
if (addr == 0xBD) {
8585
regen_braking = (GET_BYTE(to_push, 0) >> 4) != 0U;
8686
}
87-
88-
bool stock_ecu_detected = (addr == 0x180); // ASCMLKASteeringCmd
89-
90-
// Check ASCMGasRegenCmd only if we're blocking it
91-
if (!gm_pcm_cruise && (addr == 0x2CB)) {
92-
stock_ecu_detected = true;
93-
}
94-
generic_rx_checks(stock_ecu_detected);
9587
}
9688
}
9789

@@ -194,9 +186,9 @@ static safety_config gm_init(uint16_t param) {
194186
.max_brake = 400,
195187
};
196188

197-
static const CanMsg GM_ASCM_TX_MSGS[] = {{0x180, 0, 4}, {0x409, 0, 7}, {0x40A, 0, 7}, {0x2CB, 0, 8}, {0x370, 0, 6}, // pt bus
198-
{0xA1, 1, 7}, {0x306, 1, 8}, {0x308, 1, 7}, {0x310, 1, 2}, // obs bus
199-
{0x315, 2, 5}}; // ch bus
189+
static const CanMsg GM_ASCM_TX_MSGS[] = {{0x180, 0, 4, true}, {0x409, 0, 7, false}, {0x40A, 0, 7, false}, {0x2CB, 0, 8, true}, {0x370, 0, 6, false}, // pt bus
190+
{0xA1, 1, 7, false}, {0x306, 1, 8, false}, {0x308, 1, 7, false}, {0x310, 1, 2, false}, // obs bus
191+
{0x315, 2, 5, false}}; // ch bus
200192

201193

202194
static const LongitudinalLimits GM_CAM_LONG_LIMITS = {
@@ -206,8 +198,8 @@ static safety_config gm_init(uint16_t param) {
206198
.max_brake = 400,
207199
};
208200

209-
static const CanMsg GM_CAM_LONG_TX_MSGS[] = {{0x180, 0, 4}, {0x315, 0, 5}, {0x2CB, 0, 8}, {0x370, 0, 6}, // pt bus
210-
{0x184, 2, 8}}; // camera bus
201+
static const CanMsg GM_CAM_LONG_TX_MSGS[] = {{0x180, 0, 4, true}, {0x315, 0, 5, false}, {0x2CB, 0, 8, true}, {0x370, 0, 6, false}, // pt bus
202+
{0x184, 2, 8, false}}; // camera bus
211203

212204

213205
// TODO: do checksum and counter checks. Add correct timestep, 0.1s for now.
@@ -222,8 +214,8 @@ static safety_config gm_init(uint16_t param) {
222214
{.msg = {{0xC9, 0, 8, .ignore_checksum = true, .ignore_counter = true, .frequency = 10U}, { 0 }, { 0 }}},
223215
};
224216

225-
static const CanMsg GM_CAM_TX_MSGS[] = {{0x180, 0, 4}, // pt bus
226-
{0x1E1, 2, 7}, {0x184, 2, 8}}; // camera bus
217+
static const CanMsg GM_CAM_TX_MSGS[] = {{0x180, 0, 4, true}, // pt bus
218+
{0x1E1, 2, 7, false}, {0x184, 2, 8, false}}; // camera bus
227219

228220
gm_hw = GET_FLAG(param, GM_PARAM_HW_CAM) ? GM_CAM : GM_ASCM;
229221

opendbc/safety/safety/safety_honda.h

+5-24
Original file line numberDiff line numberDiff line change
@@ -169,25 +169,6 @@ static void honda_rx_hook(const CANPacket_t *to_push) {
169169
}
170170
}
171171
}
172-
173-
int bus_rdr_car = (honda_hw == HONDA_BOSCH) ? 0 : 2; // radar bus, car side
174-
bool stock_ecu_detected = false;
175-
176-
// If steering controls messages are received on the destination bus, it's an indication
177-
// that the relay might be malfunctioning
178-
if ((addr == 0xE4) || (addr == 0x194)) {
179-
if (((honda_hw != HONDA_NIDEC) && (bus == bus_rdr_car)) || ((honda_hw == HONDA_NIDEC) && (bus == 0))) {
180-
stock_ecu_detected = true;
181-
}
182-
}
183-
// If Honda Bosch longitudinal mode is selected we need to ensure the radar is turned off
184-
// Verify this by ensuring ACC_CONTROL (0x1DF) is not received on the PT bus
185-
if (honda_bosch_long && !honda_bosch_radarless && (bus == pt_bus) && (addr == 0x1DF)) {
186-
stock_ecu_detected = true;
187-
}
188-
189-
generic_rx_checks(stock_ecu_detected);
190-
191172
}
192173

193174
static bool honda_tx_hook(const CANPacket_t *to_send) {
@@ -303,7 +284,7 @@ static bool honda_tx_hook(const CANPacket_t *to_send) {
303284
}
304285

305286
static safety_config honda_nidec_init(uint16_t param) {
306-
static CanMsg HONDA_N_TX_MSGS[] = {{0xE4, 0, 5}, {0x194, 0, 4}, {0x1FA, 0, 8}, {0x30C, 0, 8}, {0x33D, 0, 5}};
287+
static CanMsg HONDA_N_TX_MSGS[] = {{0xE4, 0, 5, true}, {0x194, 0, 4, true}, {0x1FA, 0, 8, false}, {0x30C, 0, 8, false}, {0x33D, 0, 5, false}};
307288

308289
const uint16_t HONDA_PARAM_NIDEC_ALT = 4;
309290

@@ -336,10 +317,10 @@ static safety_config honda_nidec_init(uint16_t param) {
336317
}
337318

338319
static safety_config honda_bosch_init(uint16_t param) {
339-
static CanMsg HONDA_BOSCH_TX_MSGS[] = {{0xE4, 0, 5}, {0xE5, 0, 8}, {0x296, 1, 4}, {0x33D, 0, 5}, {0x33DA, 0, 5}, {0x33DB, 0, 8}}; // Bosch
340-
static CanMsg HONDA_BOSCH_LONG_TX_MSGS[] = {{0xE4, 1, 5}, {0x1DF, 1, 8}, {0x1EF, 1, 8}, {0x1FA, 1, 8}, {0x30C, 1, 8}, {0x33D, 1, 5}, {0x33DA, 1, 5}, {0x33DB, 1, 8}, {0x39F, 1, 8}, {0x18DAB0F1, 1, 8}}; // Bosch w/ gas and brakes
341-
static CanMsg HONDA_RADARLESS_TX_MSGS[] = {{0xE4, 0, 5}, {0x296, 2, 4}, {0x33D, 0, 8}}; // Bosch radarless
342-
static CanMsg HONDA_RADARLESS_LONG_TX_MSGS[] = {{0xE4, 0, 5}, {0x33D, 0, 8}, {0x1C8, 0, 8}, {0x30C, 0, 8}}; // Bosch radarless w/ gas and brakes
320+
static CanMsg HONDA_BOSCH_TX_MSGS[] = {{0xE4, 0, 5, true}, {0xE5, 0, 8, false}, {0x296, 1, 4, false}, {0x33D, 0, 5, false}, {0x33DA, 0, 5, false}, {0x33DB, 0, 8, false}}; // Bosch
321+
static CanMsg HONDA_BOSCH_LONG_TX_MSGS[] = {{0xE4, 1, 5, true}, {0x1DF, 1, 8, true}, {0x1EF, 1, 8, false}, {0x1FA, 1, 8, false}, {0x30C, 1, 8, false}, {0x33D, 1, 5, false}, {0x33DA, 1, 5, false}, {0x33DB, 1, 8, false}, {0x39F, 1, 8, false}, {0x18DAB0F1, 1, 8, false}}; // Bosch w/ gas and brakes
322+
static CanMsg HONDA_RADARLESS_TX_MSGS[] = {{0xE4, 0, 5, true}, {0x296, 2, 4, false}, {0x33D, 0, 8, false}}; // Bosch radarless
323+
static CanMsg HONDA_RADARLESS_LONG_TX_MSGS[] = {{0xE4, 0, 5, true}, {0x33D, 0, 8, false}, {0x1C8, 0, 8, false}, {0x30C, 0, 8, false}}; // Bosch radarless w/ gas and brakes
343324

344325
const uint16_t HONDA_PARAM_ALT_BRAKE = 1;
345326
const uint16_t HONDA_PARAM_RADARLESS = 8;

opendbc/safety/safety/safety_hyundai.h

+12-21
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ const LongitudinalLimits HYUNDAI_LONG_LIMITS = {
2727
};
2828

2929
#define HYUNDAI_COMMON_TX_MSGS(scc_bus) \
30-
{0x340, 0, 8}, /* LKAS11 Bus 0 */ \
31-
{0x4F1, scc_bus, 4}, /* CLU11 Bus 0 (radar-SCC) or 2 (camera-SCC) */ \
32-
{0x485, 0, 4}, /* LFAHDA_MFC Bus 0 */ \
30+
{0x340, 0, 8, true}, /* LKAS11 Bus 0 */ \
31+
{0x4F1, scc_bus, 4, false}, /* CLU11 Bus 0 (radar-SCC) or 2 (camera-SCC) */ \
32+
{0x485, 0, 4, false}, /* LFAHDA_MFC Bus 0 */ \
3333

3434
#define HYUNDAI_LONG_COMMON_TX_MSGS(scc_bus) \
35-
HYUNDAI_COMMON_TX_MSGS(scc_bus) \
36-
{0x420, 0, 8}, /* SCC11 Bus 0 */ \
37-
{0x421, 0, 8}, /* SCC12 Bus 0 */ \
38-
{0x50A, 0, 8}, /* SCC13 Bus 0 */ \
39-
{0x389, 0, 8}, /* SCC14 Bus 0 */ \
40-
{0x4A2, 0, 2}, /* FRT_RADAR11 Bus 0 */ \
35+
HYUNDAI_COMMON_TX_MSGS(scc_bus) \
36+
{0x420, 0, 8, false}, /* SCC11 Bus 0 */ \
37+
{0x421, 0, 8, (scc_bus) == 0}, /* SCC12 Bus 0 */ \
38+
{0x50A, 0, 8, false}, /* SCC13 Bus 0 */ \
39+
{0x389, 0, 8, false}, /* SCC14 Bus 0 */ \
40+
{0x4A2, 0, 2, false}, /* FRT_RADAR11 Bus 0 */ \
4141

4242
#define HYUNDAI_COMMON_RX_CHECKS(legacy) \
4343
{.msg = {{0x260, 0, 8, .max_counter = 3U, .frequency = 100U}, \
@@ -176,15 +176,6 @@ static void hyundai_rx_hook(const CANPacket_t *to_push) {
176176
if (addr == 0x394) {
177177
brake_pressed = ((GET_BYTE(to_push, 5) >> 5U) & 0x3U) == 0x2U;
178178
}
179-
180-
bool stock_ecu_detected = (addr == 0x340);
181-
182-
// If openpilot is controlling longitudinal we need to ensure the radar is turned off
183-
// Enforce by checking we don't see SCC12
184-
if (hyundai_longitudinal && !hyundai_camera_scc && (addr == 0x421)) {
185-
stock_ecu_detected = true;
186-
}
187-
generic_rx_checks(stock_ecu_detected);
188179
}
189180
}
190181

@@ -281,9 +272,9 @@ static bool hyundai_fwd_hook(int bus_num, int addr) {
281272
static safety_config hyundai_init(uint16_t param) {
282273
static const CanMsg HYUNDAI_LONG_TX_MSGS[] = {
283274
HYUNDAI_LONG_COMMON_TX_MSGS(0)
284-
{0x38D, 0, 8}, // FCA11 Bus 0
285-
{0x483, 0, 8}, // FCA12 Bus 0
286-
{0x7D0, 0, 8}, // radar UDS TX addr Bus 0 (for radar disable)
275+
{0x38D, 0, 8, false}, // FCA11 Bus 0
276+
{0x483, 0, 8, false}, // FCA12 Bus 0
277+
{0x7D0, 0, 8, false}, // radar UDS TX addr Bus 0 (for radar disable)
287278
};
288279

289280
static const CanMsg HYUNDAI_CAMERA_SCC_TX_MSGS[] = {

0 commit comments

Comments
 (0)