safety: make the RX check tables const (#3870)

This commit is contained in:
Adeeb Shihadeh
2026-11-02 20:16:44 +00:00
committed by firestar5683
parent 2645933f91
commit c7d78e5462
21 changed files with 62 additions and 265 deletions
+1 -1
View File
@@ -43,7 +43,7 @@ static bool body_tx_hook(const CANPacket_t *msg) {
}
static safety_config body_init(uint16_t param) {
static RxCheck body_rx_checks[] = {
static const RxCheck body_rx_checks[] = {
{.msg = {{0x201, 0, 8, 100U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
};
+1 -1
View File
@@ -99,7 +99,7 @@ static safety_config byd_init(uint16_t param) {
{0x3B0, 0, 8, .check_relay = false}, // PCM_BUTTONS (cruise cancel button spoof)
};
static RxCheck byd_rx_checks[] = {
static const RxCheck byd_rx_checks[] = {
{.msg = {{0x11F, 0, 5, 100U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, // STEER_MODULE_2 (steering angle)
{.msg = {{0x1F0, 0, 8, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}}, // WHEELSPEED_CLEAN (vehicle speed)
{.msg = {{0x242, 0, 8, 50U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, // DRIVE_STATE (gas and brake pressed)
+3 -3
View File
@@ -196,7 +196,7 @@ static safety_config chrysler_init(uint16_t param) {
chrysler_hold_stock_timestamp = 0U;
for (int i = 0; i < 8; i++) { chrysler_hold_stock[i] = 0U; }
static RxCheck chrysler_ram_dt_rx_checks[] = {
static const RxCheck chrysler_ram_dt_rx_checks[] = {
{.msg = {{CHRYSLER_RAM_DT_EPS_2, 0, 8, 100U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{CHRYSLER_RAM_DT_ESP_1, 0, 8, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{CHRYSLER_RAM_DT_ESP_8, 0, 8, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
@@ -204,7 +204,7 @@ static safety_config chrysler_init(uint16_t param) {
{.msg = {{CHRYSLER_RAM_DT_DAS_3, 2, 8, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
};
static RxCheck chrysler_rx_checks[] = {
static const RxCheck chrysler_rx_checks[] = {
{.msg = {{CHRYSLER_EPS_2, 0, 8, 100U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{CHRYSLER_ESP_1, 0, 8, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{514, 0, 8, 100U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}},
@@ -232,7 +232,7 @@ static safety_config chrysler_init(uint16_t param) {
};
#ifdef ALLOW_DEBUG
static RxCheck chrysler_ram_hd_rx_checks[] = {
static const RxCheck chrysler_ram_hd_rx_checks[] = {
{.msg = {{CHRYSLER_RAM_HD_EPS_2, 0, 8, 100U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{CHRYSLER_RAM_HD_ESP_1, 0, 8, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{CHRYSLER_RAM_HD_ESP_8, 0, 8, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
@@ -9,7 +9,7 @@ static safety_config chrysler_cusw_init(uint16_t param) {
{0x2FAU, 0, 3, .check_relay = false},
};
static RxCheck chrysler_cusw_rx_checks[] = {
static const RxCheck chrysler_cusw_rx_checks[] = {
{.msg = {{0x1E4U, 0, 8, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{0x1E8U, 0, 5, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{0x1ECU, 0, 8, 100U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
+10 -7
View File
@@ -444,13 +444,16 @@ static safety_config ford_init(uint16_t configured_param) {
const bool manual_valid = !manual || ford_aol_param_valid(configured_param);
// warning: quality flags are not yet checked in openpilot's CAN parser,
// this may be the cause of blocked messages
// Shared entries preserve all current checksum/counter/quality contracts.
#define FORD_COMMON_RX_CHECKS \
{.msg = {{FORD_BrakeSysFeatures, 0, 8, 50U, .max_counter = 15U}, { 0 }, { 0 }}}, \
{.msg = {{FORD_EngVehicleSpThrottle2, 0, 8, 50U, .ignore_checksum = true, .ignore_counter = true}, { 0 }, { 0 }}}, \
{.msg = {{FORD_Yaw_Data_FD1, 0, 8, 100U, .max_counter = 255U}, { 0 }, { 0 }}}, \
{.msg = {{FORD_EngBrakeData, 0, 8, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, \
{.msg = {{FORD_EngVehicleSpThrottle, 0, 8, 100U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, \
static const RxCheck ford_rx_checks[] = {
{.msg = {{FORD_BrakeSysFeatures, 0, 8, 50U, .max_counter = 15U}, { 0 }, { 0 }}},
// FORD_EngVehicleSpThrottle2 has a counter that either randomly skips or by 2, likely ECU bug
// Some hybrid models also experience a bug where this checksum mismatches for one or two frames under heavy acceleration with ACC
// It has been confirmed that the Bronco Sport's camera only disallows ACC for bad quality flags, not counters or checksums, so we match that
{.msg = {{FORD_EngVehicleSpThrottle2, 0, 8, 50U, .ignore_checksum = true, .ignore_counter = true}, { 0 }, { 0 }}},
{.msg = {{FORD_Yaw_Data_FD1, 0, 8, 100U, .max_counter = 255U}, { 0 }, { 0 }}},
// These messages have no counter or checksum
{.msg = {{FORD_EngBrakeData, 0, 8, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{FORD_EngVehicleSpThrottle, 0, 8, 100U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{FORD_DesiredTorqBrk, 0, 8, 50U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}},
static RxCheck ford_rx_checks[] = { FORD_COMMON_RX_CHECKS };
static RxCheck ford_lka_rx_checks[] = {
+2 -2
View File
@@ -1160,7 +1160,7 @@ static safety_config gm_init(uint16_t safety_param) {
gm_extended_rx_checks[3].msg[0].addr = (gm_camera_pedal && !gm_camera_pedal_f1) ? 0xBEU : 0xF1U;
static RxCheck gm_rx_checks[] = {
static const RxCheck gm_rx_checks[] = {
GM_COMMON_RX_CHECKS
};
#define GM_ASCM_INTERCEPT_RX_CHECKS \
@@ -1237,7 +1237,7 @@ static safety_config gm_init(uint16_t safety_param) {
{.msg = {{0x1F5, 0, 8, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}},
};
static RxCheck gm_ev_rx_checks[] = {
static const RxCheck gm_ev_rx_checks[] = {
GM_COMMON_RX_CHECKS
{.msg = {{0xBD, 0, 7, 40U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}},
};
+8 -87
View File
@@ -668,88 +668,9 @@ static safety_config hyundai_init(uint16_t param) {
hyundai_legacy = false;
safety_config ret;
#ifdef ALLOW_DEBUG
if (hyundai_blended_alpha) {
static const CanMsg alpha_hda1_tx[] = {
{0x340, 0, 8, .check_relay = true, .disable_static_blocking = true},
{0x485, 0, 8, .check_relay = true, .disable_static_blocking = true},
{0x364, 0, 8, .check_relay = true, .disable_static_blocking = true}, {0x420, 0, 8, .check_relay = true},
{0x421, 0, 8, .check_relay = true}, {0x389, 0, 8, .check_relay = true},
{0x7D0, 0, 8, .check_relay = false}, {0x363, 0, 8, .check_relay = false},
{0x398, 0, 8, .check_relay = false},
};
static const CanMsg alpha_hda2_tx[] = {
{0x50, 0, 16, .check_relay = true, .disable_static_blocking = true},
{0x2A4, 0, 24, .check_relay = true, .disable_static_blocking = true},
{0x51, 0, 32, .check_relay = false}, {0x730, 1, 8, .check_relay = false},
{0x340, 1, 8, .check_relay = true, .disable_static_blocking = true},
{0x485, 1, 8, .check_relay = true, .disable_static_blocking = true},
{0x420, 1, 8, .check_relay = true}, {0x421, 1, 8, .check_relay = true},
{0x389, 1, 8, .check_relay = true}, {0x38D, 1, 8, .check_relay = false},
{0x363, 1, 8, .check_relay = false},
{0x398, 1, 8, .check_relay = false}, {0x399, 1, 8, .check_relay = false},
{0x39A, 1, 8, .check_relay = false}, {0x39B, 1, 8, .check_relay = false},
{0x39C, 1, 8, .check_relay = false}, {0x43A, 1, 8, .check_relay = false},
};
if (hyundai_blended_hda2) {
static RxCheck alpha_hda2_rx[] = {
HYUNDAI_BLENDED_ALPHA_RX_CHECKS(1, 50U)
{.msg = {{0x2A4, 2, 24, 20U, .max_counter = 255U, .ignore_quality_flag = true}, {0}, {0}}},
};
ret = BUILD_SAFETY_CFG(alpha_hda2_rx, alpha_hda2_tx);
} else {
static RxCheck alpha_hda1_rx[] = {
HYUNDAI_BLENDED_ALPHA_RX_CHECKS(0, 100U)
{.msg = {{0x391, 0, 8, 100U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true},
{0x50C, 0, 8, 50U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true},
{0x50C, 1, 8, 50U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}}},
};
ret = BUILD_SAFETY_CFG(alpha_hda1_rx, alpha_hda1_tx);
}
} else
#endif
if (hyundai_blended_stock) {
static const CanMsg blended_tx[] = {
{0x340, 0, 8, .check_relay = true},
{0x4F1, 0, 4, .check_relay = false},
{0x485, 0, 8, .check_relay = true},
{0x364, 0, 8, .check_relay = true},
};
static const CanMsg blended_hda2_tx[] = {
{0x50, 0, 16, .check_relay = true},
{0x4F1, 1, 4, .check_relay = false},
{0x2A4, 0, 24, .check_relay = true},
{0x485, 1, 8, .check_relay = false},
};
static const CanMsg blended_hda2_aol_tx[] = {
{0x50, 0, 16, .check_relay = true, .disable_static_blocking = true},
{0x4F1, 1, 4, .check_relay = false},
{0x2A4, 0, 24, .check_relay = true, .disable_static_blocking = true},
{0x485, 1, 8, .check_relay = false, .disable_static_blocking = true},
};
static const CanMsg blended_aol_tx_msgs[] = {
{0x340, 0, 8, .check_relay = true, .disable_static_blocking = true},
{0x4F1, 0, 4, .check_relay = false},
{0x485, 0, 8, .check_relay = true, .disable_static_blocking = true},
{0x364, 0, 8, .check_relay = true, .disable_static_blocking = true},
};
if (hyundai_blended_hda2) {
static RxCheck blended_hda2_rx[] = {
HYUNDAI_BLENDED_COMMON_RX_CHECKS(1, 50U)
{.msg = {{0x2A4, 2, 24, 20U, .max_counter = 255U, .ignore_quality_flag = true}, {0}, {0}}},
};
ret = blended_aol_enabled ? BUILD_SAFETY_CFG(blended_hda2_rx, blended_hda2_aol_tx) :
BUILD_SAFETY_CFG(blended_hda2_rx, blended_hda2_tx);
} else {
static RxCheck blended_rx[] = {HYUNDAI_BLENDED_COMMON_RX_CHECKS(0, 100U)};
ret = blended_aol_enabled ? BUILD_SAFETY_CFG(blended_rx, blended_aol_tx_msgs) : BUILD_SAFETY_CFG(blended_rx, blended_tx);
}
} else if (hyundai_ray_pedal) {
static const CanMsg ray_tx_msgs[] = {
HYUNDAI_COMMON_TX_MSGS(0, true)
{0x200, 0, 6, .check_relay = false},
};
static RxCheck ray_rx_checks[] = {
if (hyundai_longitudinal) {
// Use CLU11 (buttons) to manage controls allowed instead of SCC cruise state
static const RxCheck hyundai_long_rx_checks[] = {
HYUNDAI_COMMON_RX_CHECKS(false)
{.msg = {{0x592, 0, 8, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, {0}, {0}}},
HYUNDAI_LDA_BUTTON_ADDR_CHECK
@@ -760,7 +681,7 @@ static safety_config hyundai_init(uint16_t param) {
} else if (hyundai_longitudinal) {
// Use CLU11 (buttons) to manage controls allowed instead of SCC cruise state
static RxCheck hyundai_fcev_long_rx_checks[] = {
static const RxCheck hyundai_fcev_long_rx_checks[] = {
HYUNDAI_COMMON_RX_CHECKS(false)
HYUNDAI_FCEV_GAS_ADDR_CHECK
};
@@ -784,7 +705,7 @@ static safety_config hyundai_init(uint16_t param) {
}
}
} else if (hyundai_camera_scc) {
static RxCheck hyundai_cam_scc_rx_checks[] = {
static const RxCheck hyundai_cam_scc_rx_checks[] = {
HYUNDAI_COMMON_RX_CHECKS(false)
HYUNDAI_SCC12_ADDR_CHECK(2)
};
@@ -796,12 +717,12 @@ static safety_config hyundai_init(uint16_t param) {
ret = BUILD_SAFETY_CFG(hyundai_cam_scc_rx_checks, HYUNDAI_CAMERA_SCC_TX_MSGS);
}
} else {
static RxCheck hyundai_rx_checks[] = {
static const RxCheck hyundai_rx_checks[] = {
HYUNDAI_COMMON_RX_CHECKS(false)
HYUNDAI_SCC12_ADDR_CHECK(0)
};
static RxCheck hyundai_fcev_rx_checks[] = {
static const RxCheck hyundai_fcev_rx_checks[] = {
HYUNDAI_COMMON_RX_CHECKS(false)
HYUNDAI_SCC12_ADDR_CHECK(0)
HYUNDAI_FCEV_GAS_ADDR_CHECK
@@ -908,7 +829,7 @@ static safety_config hyundai_init(uint16_t param) {
static safety_config hyundai_legacy_init(uint16_t param) {
// older hyundai models have less checks due to missing counters and checksums
static RxCheck hyundai_legacy_rx_checks[] = {
static const RxCheck hyundai_legacy_rx_checks[] = {
HYUNDAI_COMMON_RX_CHECKS(true)
HYUNDAI_SCC12_ADDR_CHECK(0)
};
@@ -1744,7 +1744,7 @@ static safety_config hyundai_canfd_init_validated(uint16_t supplied_param) {
#endif
if (hyundai_longitudinal) {
if (hyundai_canfd_lka_steer_msg) {
static RxCheck hyundai_canfd_lka_steer_msg_long_rx_checks[] = {
static const RxCheck hyundai_canfd_lka_steer_msg_long_rx_checks[] = {
HYUNDAI_CANFD_STD_BUTTONS_RX_CHECKS(1)
};
@@ -1754,11 +1754,11 @@ static safety_config hyundai_canfd_init_validated(uint16_t supplied_param) {
}
} else {
// Longitudinal checks for LFA steering
static RxCheck hyundai_canfd_long_rx_checks[] = {
static const RxCheck hyundai_canfd_long_rx_checks[] = {
HYUNDAI_CANFD_STD_BUTTONS_RX_CHECKS(0)
};
static RxCheck hyundai_canfd_alt_buttons_long_rx_checks[] = {
static const RxCheck hyundai_canfd_alt_buttons_long_rx_checks[] = {
HYUNDAI_CANFD_ALT_BUTTONS_RX_CHECKS(0)
};
@@ -1790,7 +1790,7 @@ static safety_config hyundai_canfd_init_validated(uint16_t supplied_param) {
// *** LKA steering checks ***
// E-CAN is on bus 1, SCC messages are sent on cars with ADRV ECU.
// Does not use the alt buttons message
static RxCheck hyundai_canfd_lka_steer_msg_rx_checks[] = {
static const RxCheck hyundai_canfd_lka_steer_msg_rx_checks[] = {
HYUNDAI_CANFD_STD_BUTTONS_RX_CHECKS(1)
HYUNDAI_CANFD_SCC_ADDR_CHECK(1)
};
@@ -1819,12 +1819,12 @@ static safety_config hyundai_canfd_init_validated(uint16_t supplied_param) {
}
} else if (!hyundai_camera_scc) {
// Radar sends SCC messages on these cars instead of camera
static RxCheck hyundai_canfd_radar_scc_rx_checks[] = {
static const RxCheck hyundai_canfd_radar_scc_rx_checks[] = {
HYUNDAI_CANFD_STD_BUTTONS_RX_CHECKS(0)
HYUNDAI_CANFD_SCC_ADDR_CHECK(0)
};
static RxCheck hyundai_canfd_alt_buttons_radar_scc_rx_checks[] = {
static const RxCheck hyundai_canfd_alt_buttons_radar_scc_rx_checks[] = {
HYUNDAI_CANFD_ALT_BUTTONS_RX_CHECKS(0)
HYUNDAI_CANFD_SCC_ADDR_CHECK(0)
};
@@ -1840,12 +1840,12 @@ static safety_config hyundai_canfd_init_validated(uint16_t supplied_param) {
// *** LFA steering checks ***
// Camera sends SCC messages on LFA steering cars.
// Both button messages exist on some platforms, so we ensure we track the correct one using flag
static RxCheck hyundai_canfd_rx_checks[] = {
static const RxCheck hyundai_canfd_rx_checks[] = {
HYUNDAI_CANFD_STD_BUTTONS_RX_CHECKS(0)
HYUNDAI_CANFD_SCC_ADDR_CHECK(2)
};
static RxCheck hyundai_canfd_alt_buttons_rx_checks[] = {
static const RxCheck hyundai_canfd_alt_buttons_rx_checks[] = {
HYUNDAI_CANFD_ALT_BUTTONS_RX_CHECKS(0)
HYUNDAI_CANFD_SCC_ADDR_CHECK(2)
};
+1 -1
View File
@@ -91,7 +91,7 @@ static safety_config mazda_init(uint16_t param) {
{MAZDA_LKAS_HUD, 0, 8, .check_relay = true},
};
static RxCheck mazda_rx_checks[] = {
static const RxCheck mazda_rx_checks[] = {
{.msg = {{MAZDA_CRZ_CTRL, 0, 8, 50U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{MAZDA_CRZ_BTNS, 0, 8, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{MAZDA_STEER_TORQUE, 0, 8, 83U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}},
+1 -1
View File
@@ -124,7 +124,7 @@ static safety_config mg_init(uint16_t param) {
static const CanMsg MG_TX_MSGS[] = {{0x1fd, 0, 8, .check_relay = true}};
static RxCheck mg_rx_checks[] = {
static const RxCheck mg_rx_checks[] = {
{.msg = {{0x23c, 0, 8, .frequency = 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}}, // SCS_HSC2_FrP19 (speed)
{.msg = {{0xaf, 0, 8, .frequency = 100U, .ignore_checksum = true, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}}, // GW_HSC2_HCU_FrP00 (gas pedal)
{.msg = {{0x1ec, 0, 8, .frequency = 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}}, // EPS_HSC2_FrP03 (driver torque)
+1 -1
View File
@@ -105,7 +105,7 @@ static safety_config nissan_init(uint16_t param) {
};
// Signals duplicated below due to the fact that these messages can come in on either CAN bus, depending on car model.
static const RxCheck nissan_rx_defaults[] = {
static const RxCheck nissan_rx_checks[] = {
{.msg = {{0x185, 0, 8, 100U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, // STEER_TORQUE_SENSOR
{.msg = {{0x285, 0, 8, 50U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true},
{0x285, 1, 8, 50U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }}}, // WHEEL_SPEEDS_REAR
+1 -1
View File
@@ -109,7 +109,7 @@ static safety_config psa_init(uint16_t param) {
{PSA_LANE_KEEP_ASSIST, PSA_MAIN_BUS, 8, .check_relay = true}, // EPS steering
};
static RxCheck psa_rx_checks[] = {
static const RxCheck psa_rx_checks[] = {
{.msg = {{PSA_HS2_DAT_MDD_CMD_452, PSA_ADAS_BUS, 6, 20U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}}, // cruise state
{.msg = {{PSA_HS2_DYN_ABR_38D, PSA_MAIN_BUS, 8, 25U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}}, // speed
{.msg = {{PSA_STEERING_ALT, PSA_MAIN_BUS, 7, 100U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, // steering angle
+1 -1
View File
@@ -165,7 +165,7 @@ static safety_config rivian_init(uint16_t param) {
};
#endif
static const RxCheck rivian_rx_descriptors[] = {
static const RxCheck rivian_rx_checks[] = {
{.msg = {{0x208, 0, 8, 50U, .max_counter = 14U}, { 0 }, { 0 }}}, // ESP_Status (speed)
{.msg = {{0x150, 0, 7, 50U, .max_counter = 14U}, { 0 }, { 0 }}}, // VDM_PropStatus (gas pedal & 2nd speed)
{.msg = {{0x38f, 0, 6, 50U, .max_counter = 14U}, { 0 }, { 0 }}}, // iBESP2 (brakes)
+1 -32
View File
@@ -416,38 +416,7 @@ static safety_config subaru_init(uint16_t raw_param) {
}
safety_config ret;
// Only one Subaru profile is active; share its mutable RX workspace.
static RxCheck subaru_rx_workspace[8];
int rx_count;
if (subaru_lkas_angle) {
static const RxCheck subaru_gen2_angle_rx_checks[] = {
SUBARU_GEN2_ANGLE_RX_CHECKS()
{.msg = {{MSG_SUBARU_ES_Distance, SUBARU_ALT_BUS, 8, 20U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
};
rx_count = sizeof(subaru_gen2_angle_rx_checks) / sizeof(subaru_gen2_angle_rx_checks[0]);
for (int i = 0; i < rx_count; i++) {
subaru_rx_workspace[i] = subaru_gen2_angle_rx_checks[i];
}
// Only one Subaru angle profile is active. Rebind the complete topology
// on every init; the safety selector resets every selected RX status afterward.
subaru_rx_workspace[0].msg[0].bus = subaru_d_platform ? SUBARU_ALT_BUS : SUBARU_MAIN_BUS;
subaru_rx_workspace[3].msg[0].bus = subaru_forester_angle ? SUBARU_MAIN_BUS : SUBARU_ALT_BUS;
subaru_rx_workspace[4].msg[0].bus = subaru_forester_angle ? SUBARU_MAIN_BUS : SUBARU_ALT_BUS;
subaru_rx_workspace[5].msg[0].bus = subaru_forester_angle ? SUBARU_CAM_BUS : SUBARU_ALT_BUS;
ret = subaru_d_platform ? (stop_start ? BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_OUTBACK_STOP_START_TX_MSGS) :
BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_ASCENT_ANGLE_TX_MSGS_LIST)) :
subaru_forester_angle ? BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_FORESTER_ANGLE_TX_MSGS) :
avh ? (stop_start ? BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_AVH_STOP_START_TX_MSGS) :
BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_AVH_TX_MSGS)) :
stop_start ? BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_STOP_START_TX_MSGS) :
ascent_alert ? BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_ASCENT_ALERT_TX_MSGS) :
subaru_angle_main_bus ? BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_ASCENT_ANGLE_TX_MSGS_LIST) :
BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_GEN2_ANGLE_TX_MSGS_LIST);
// Keep the original seven checks on other profiles; only MAIN arming needs ACC health.
if (!subaru_aol_main_arm) {
rx_count--;
}
} else if (subaru_gen2) {
if (subaru_gen2) {
static const RxCheck subaru_gen2_rx_checks[] = {
SUBARU_COMMON_RX_CHECKS(SUBARU_ALT_BUS)
};
@@ -83,7 +83,7 @@ static safety_config subaru_preglobal_init(uint16_t param) {
};
// TODO: do checksum and counter checks after adding the signals to the outback dbc file
static RxCheck subaru_preglobal_rx_checks[] = {
static const RxCheck subaru_preglobal_rx_checks[] = {
{.msg = {{MSG_SUBARU_PG_Throttle, SUBARU_PG_MAIN_BUS, 8, 100U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{MSG_SUBARU_PG_Steering_Torque, SUBARU_PG_MAIN_BUS, 8, 50U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{MSG_SUBARU_PG_CruiseControl, SUBARU_PG_MAIN_BUS, 8, 50U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}},
+1 -1
View File
@@ -341,7 +341,7 @@ static safety_config tesla_init(uint16_t param) {
tesla_autopark = true;
tesla_autopark_prev = false;
static RxCheck tesla_model3_y_rx_checks[] = {
static const RxCheck tesla_model3_y_rx_checks[] = {
{.msg = {{0x2b9, 2, 8, 25U, .max_counter = 7U, .ignore_quality_flag = true}, { 0 }, { 0 }}}, // DAS_control
{.msg = {{0x488, 2, 4, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}}, // DAS_steeringControl
{.msg = {{0x257, 0, 8, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}}, // DI_speed (speed in kph)
+15 -99
View File
@@ -729,116 +729,32 @@ static safety_config toyota_init(uint16_t param) {
}
if (toyota_secoc) {
static RxCheck toyota_secoc_rx_checks[] = {
static const RxCheck toyota_secoc_rx_checks[] = {
TOYOTA_SECOC_RX_CHECKS
};
SET_RX_CHECKS(toyota_secoc_rx_checks, ret);
} else if (toyota_lta) {
// Check the quality flag for angle measurement when using LTA, since it's not set on TSS-P cars
static const RxCheck toyota_lta_rx_checks[] = {
TOYOTA_RX_CHECKS(true)
};
SET_RX_CHECKS(toyota_lta_rx_checks, ret);
} else {
// These profiles use the same four base checks. Share their mutable
// workspace; set_safety_hooks resets every active status on each switch.
static RxCheck toyota_rx_checks[] = {
static const RxCheck toyota_lka_rx_checks[] = {
TOYOTA_RX_CHECKS(false)
{.msg = {{0x2FF, 0, 8, 50U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = false}, { 0 }, { 0 }}},
{.msg = {{0x365, 0, 7, 10U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{0x1D3, 0, 8, 10U, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{0x201, 0, 6, 50U, .max_counter = 15U, .ignore_quality_flag = false}, { 0 }, { 0 }}},
};
// LTA alone validates initialized measured angle. Preserve the existing
// alternate-brake selection only on non-LTA profiles.
toyota_rx_checks[1].msg[0].ignore_quality_flag = !toyota_lta;
toyota_rx_checks[3].msg[0].addr = (!toyota_lta && toyota_alt_brake) ? 0x224U : 0x226U;
const bool standalone_pedal = toyota_pedal && !toyota_pedal_composite;
toyota_rx_checks[4].msg[0] = (CanMsgCheck){.addr = toyota_alt_cruise ? 0x365 : (standalone_pedal ? 0x201 : 0x2FF),
.bus = 0U, .len = toyota_alt_cruise ? 7 : (standalone_pedal ? 6 : 8), .frequency = toyota_alt_cruise ? 10U : 50U,
.ignore_checksum = !standalone_pedal, .ignore_counter = !standalone_pedal,
.max_counter = standalone_pedal ? 15U : 0U, .ignore_quality_flag = toyota_alt_cruise};
if (toyota_legacy_sdsu) {
// Alternate DSU MAIN and smartDSU state are independent mandatory sources.
toyota_rx_checks[4].msg[0] = (CanMsgCheck){.addr = 0x2FF, .bus = 0U, .len = 8, .frequency = 50U,
.ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = false};
}
// Restore the sixth row on every warm switch before specializing the new owner.
toyota_rx_checks[5].msg[0] = (CanMsgCheck){.addr = 0x365, .bus = 0U, .len = 7, .frequency = 10U,
.ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true};
if (toyota_legacy_advert_param(base_param) || toyota_camera_2aa_param(base_param) || toyota_prius_advert_param(base_param) || (base_param == 856U)) {
toyota_rx_checks[4].msg[0] = (CanMsgCheck){.addr = 0x262, .bus = 0U, .len = (toyota_camera_2aa_param(base_param) || toyota_prius_advert_param(base_param)) ? 8 : 5, .frequency = 25U,
.ignore_counter = true, .ignore_quality_flag = true};
if (!toyota_alt_cruise) {
toyota_rx_checks[5].msg[0] = (CanMsgCheck){.addr = 0x1D3, .bus = 0U, .len = 8, .frequency = 10U,
.ignore_counter = true, .ignore_quality_flag = true};
}
}
if (toyota_prius_sdsu_param(base_param)) {
toyota_rx_checks[5].msg[0] = (CanMsgCheck){.addr = 0x262, .bus = 0U, .len = 8, .frequency = 25U,
.ignore_counter = true, .ignore_quality_flag = true};
toyota_rx_checks[6].msg[0] = (CanMsgCheck){.addr = 0x1D3, .bus = 0U, .len = 8, .frequency = 10U,
.ignore_counter = true, .ignore_quality_flag = true};
}
if (toyota_factory_stock) {
toyota_rx_checks[4].msg[0] = (CanMsgCheck){.addr = 0x262, .bus = 0U, .len = toyota_factory_eps5 ? 5 : 8,
.frequency = 25U, .ignore_counter = true, .ignore_quality_flag = true};
toyota_rx_checks[5].msg[0] = (CanMsgCheck){.addr = toyota_factory_alt_main ? 0x365 : 0x1D3, .bus = 0U,
.len = toyota_factory_alt_main ? 7 : 8, .frequency = 10U, .ignore_checksum = toyota_factory_alt_main,
.ignore_counter = true, .ignore_quality_flag = true};
}
ret.rx_checks = toyota_rx_checks;
ret.disable_forwarding = false;
if (toyota_factory_stock) {
ret.rx_checks_len = 6;
} else if (toyota_prius_sdsu_param(base_param)) {
ret.rx_checks_len = 7;
} else if ((toyota_legacy_sdsu && toyota_alt_cruise) || toyota_legacy_advert_param(base_param) || toyota_camera_2aa_param(base_param) || toyota_prius_advert_param(base_param) || (base_param == 856U)) {
ret.rx_checks_len = 6;
} else if (standalone_pedal || toyota_alt_cruise || toyota_sdsu_status) {
ret.rx_checks_len = 5;
} else {
ret.rx_checks_len = 4;
}
if (toyota_dsu_bypass) {
toyota_rx_checks[4].msg[0] = (CanMsgCheck){.addr = 0x343, .bus = 2U, .len = 8, .frequency = 33U,
.ignore_counter = true, .ignore_quality_flag = true};
toyota_rx_checks[5].msg[0] = (CanMsgCheck){.addr = 0x262, .bus = 0U, .len = toyota_bypass_eps5 ? 5 : 8, .frequency = 25U,
.ignore_counter = true, .ignore_quality_flag = true};
toyota_rx_checks[6].msg[0] = (CanMsgCheck){.addr = toyota_alt_cruise ? 0x365 : 0x1D3, .bus = 0U,
.len = toyota_alt_cruise ? 7 : 8, .frequency = 10U, .ignore_checksum = toyota_alt_cruise,
.ignore_counter = true, .ignore_quality_flag = true};
ret.rx_checks_len = 7;
}
if ((param == 0xB049U) || (param == 0xB249U)) {
// Keep all parent checks, including smartDSU status, independently required.
toyota_rx_checks[5].msg[0] = (CanMsgCheck){.addr = 0x201, .bus = 0U, .len = 6, .frequency = 50U,
.max_counter = 15U, .ignore_quality_flag = false};
toyota_rx_checks[6].msg[0] = (CanMsgCheck){.addr = 0x262, .bus = 0U, .len = 5, .frequency = 25U,
.ignore_counter = true, .ignore_quality_flag = true};
toyota_rx_checks[7].msg[0] = (CanMsgCheck){.addr = 0x1D3, .bus = 0U, .len = 8, .frequency = 10U,
.ignore_counter = true, .ignore_quality_flag = true};
ret.rx_checks_len = 8;
} else if (toyota_pedal_composite) {
// Append independent physical sources and pedal to the unchanged parent
// catalog. Eight rows cover the largest parent without shrinking buffers.
bool eps_required = false;
bool main_required = false;
for (int i = 0; i < ret.rx_checks_len; i++) {
eps_required |= toyota_rx_checks[i].msg[0].addr == 0x262;
main_required |= toyota_rx_checks[i].msg[0].addr == (toyota_alt_cruise ? 0x365 : 0x1D3);
}
if (!eps_required) {
const bool eps5 = (toyota_dsu_bypass && toyota_bypass_eps5) || toyota_aol_rav4h_filter ||
toyota_legacy_sdsu || toyota_legacy_advert();
toyota_rx_checks[ret.rx_checks_len].msg[0] = (CanMsgCheck){.addr = 0x262, .bus = 0U,
.len = eps5 ? 5 : 8, .frequency = 25U, .ignore_counter = true, .ignore_quality_flag = true};
ret.rx_checks_len++;
}
if (!main_required) {
toyota_rx_checks[ret.rx_checks_len].msg[0] = (CanMsgCheck){.addr = toyota_alt_cruise ? 0x365 : 0x1D3,
.bus = 0U, .len = toyota_alt_cruise ? 7 : 8, .frequency = 10U, .ignore_checksum = toyota_alt_cruise,
.ignore_counter = true, .ignore_quality_flag = true};
ret.rx_checks_len++;
}
toyota_rx_checks[ret.rx_checks_len].msg[0] = (CanMsgCheck){.addr = 0x201, .bus = 0U, .len = 6,
.frequency = 50U, .max_counter = 15U, .ignore_quality_flag = false};
ret.rx_checks_len++;
static const RxCheck toyota_lka_alt_brake_rx_checks[] = {
TOYOTA_ALT_BRAKE_RX_CHECKS(false)
};
if (!toyota_alt_brake) {
SET_RX_CHECKS(toyota_lka_rx_checks, ret);
} else {
}
}
@@ -138,7 +138,7 @@ static safety_config volkswagen_meb_init(uint16_t param) {
safety_config ret;
if (volkswagen_meb_alt_crc) {
static RxCheck volkswagen_meb_gen2_rx_checks[] = {
static const RxCheck volkswagen_meb_gen2_rx_checks[] = {
VOLKSWAGEN_MEB_COMMON_RX_CHECKS
{.msg = {{MSG_Motor_51, 0, 48, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{MSG_ESC_51, 0, 64, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
@@ -146,7 +146,7 @@ static safety_config volkswagen_meb_init(uint16_t param) {
ret = BUILD_SAFETY_CFG(volkswagen_meb_gen2_rx_checks, VOLKSWAGEN_MEB_TX_MSGS);
} else {
static RxCheck volkswagen_meb_rx_checks[] = {
static const RxCheck volkswagen_meb_rx_checks[] = {
VOLKSWAGEN_MEB_COMMON_RX_CHECKS
{.msg = {{MSG_Motor_51, 0, 32, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{MSG_ESC_51, 0, 48, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
@@ -12,7 +12,7 @@ static safety_config volkswagen_mlb_init(uint16_t param) {
{MSG_LS_01, 2, 4, .check_relay = false},
};
static RxCheck volkswagen_mlb_rx_checks[] = {
static const RxCheck volkswagen_mlb_rx_checks[] = {
// TODO: implement checksum validation
{.msg = {{MSG_ESP_03, 0, 8, 50U, .ignore_checksum = true, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{MSG_LH_EPS_03, 0, 8, 100U, .ignore_checksum = true, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
@@ -24,19 +24,7 @@ static safety_config volkswagen_mqb_init(uint16_t param) {
{MSG_ACC_07, 0, 8, .check_relay = true},
};
#ifdef ALLOW_DEBUG
static const CanMsg VOLKSWAGEN_MQB_AOL_LONG_TX_MSGS[] = {
{MSG_HCA_01, 0, 8, .check_relay = true, .disable_static_blocking = true},
{MSG_LDW_02, 0, 8, .check_relay = true, .disable_static_blocking = true},
{MSG_LH_EPS_03, 2, 8, .check_relay = true, .disable_static_blocking = true},
{MSG_ACC_02, 0, 8, .check_relay = true},
{MSG_ACC_06, 0, 8, .check_relay = true},
{MSG_ACC_07, 0, 8, .check_relay = true},
};
#endif
static RxCheck volkswagen_mqb_rx_checks[] = {
static const RxCheck volkswagen_mqb_rx_checks[] = {
{.msg = {{MSG_ESP_19, 0, 8, 100U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{MSG_LH_EPS_03, 0, 8, 100U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{MSG_ESP_05, 0, 8, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
@@ -62,7 +62,7 @@ static safety_config volkswagen_pq_init(uint16_t param) {
{MSG_ACC_GRA_ANZEIGE, 0, 8, .check_relay = true},
};
static RxCheck volkswagen_pq_rx_checks[] = {
static const RxCheck volkswagen_pq_rx_checks[] = {
{.msg = {{MSG_LENKHILFE_3, 0, 6, 100U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{MSG_BREMSE_1, 0, 8, 100U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}},
{.msg = {{MSG_MOTOR_2, 0, 8, 50U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}},