Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

safety: use address check helper #1721

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions board/safety/safety_body.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ const CanMsg BODY_TX_MSGS[] = {{0x250, 0, 8}, {0x250, 0, 6}, {0x251, 0, 5}, //
AddrCheckStruct body_addr_checks[] = {
{.msg = {{0x201, 0, 8, .check_checksum = false, .max_counter = 0U, .expected_timestep = 10000U}, { 0 }, { 0 }}},
};
#define BODY_ADDR_CHECK_LEN (sizeof(body_addr_checks) / sizeof(body_addr_checks[0]))
addr_checks body_rx_checks = {body_addr_checks, BODY_ADDR_CHECK_LEN};
addr_checks body_rx_checks = SET_ADDR_CHECKS(body_addr_checks);

static int body_rx_hook(CANPacket_t *to_push) {

Expand Down
13 changes: 5 additions & 8 deletions board/safety/safety_chrysler.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ AddrCheckStruct chrysler_addr_checks[] = {
{.msg = {{CHRYSLER_ADDRS.ECM_5, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}},
{.msg = {{CHRYSLER_ADDRS.DAS_3, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}},
};
#define CHRYSLER_ADDR_CHECK_LEN (sizeof(chrysler_addr_checks) / sizeof(chrysler_addr_checks[0]))

AddrCheckStruct chrysler_ram_dt_addr_checks[] = {
{.msg = {{CHRYSLER_RAM_DT_ADDRS.EPS_2, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 10000U}, { 0 }, { 0 }}},
Expand All @@ -110,7 +109,6 @@ AddrCheckStruct chrysler_ram_dt_addr_checks[] = {
{.msg = {{CHRYSLER_RAM_DT_ADDRS.ECM_5, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}},
{.msg = {{CHRYSLER_RAM_DT_ADDRS.DAS_3, 2, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}},
};
#define CHRYSLER_RAM_DT_ADDR_CHECK_LEN (sizeof(chrysler_ram_dt_addr_checks) / sizeof(chrysler_ram_dt_addr_checks[0]))

AddrCheckStruct chrysler_ram_hd_addr_checks[] = {
{.msg = {{CHRYSLER_RAM_HD_ADDRS.EPS_2, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 10000U}, { 0 }, { 0 }}},
Expand All @@ -119,10 +117,9 @@ AddrCheckStruct chrysler_ram_hd_addr_checks[] = {
{.msg = {{CHRYSLER_RAM_HD_ADDRS.ECM_5, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}},
{.msg = {{CHRYSLER_RAM_HD_ADDRS.DAS_3, 2, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}},
};
#define CHRYSLER_RAM_HD_ADDR_CHECK_LEN (sizeof(chrysler_ram_hd_addr_checks) / sizeof(chrysler_ram_hd_addr_checks[0]))


addr_checks chrysler_rx_checks = {chrysler_addr_checks, CHRYSLER_ADDR_CHECK_LEN};
addr_checks chrysler_rx_checks = SET_ADDR_CHECKS(chrysler_addr_checks);

const uint32_t CHRYSLER_PARAM_RAM_DT = 1U; // set for Ram DT platform
const uint32_t CHRYSLER_PARAM_RAM_HD = 2U; // set for Ram DT platform
Expand Down Expand Up @@ -247,7 +244,7 @@ static int chrysler_tx_hook(CANPacket_t *to_send) {

const SteeringLimits limits = (chrysler_platform == CHRYSLER_PACIFICA) ? CHRYSLER_STEERING_LIMITS :
(chrysler_platform == CHRYSLER_RAM_DT) ? CHRYSLER_RAM_DT_STEERING_LIMITS : CHRYSLER_RAM_HD_STEERING_LIMITS;

bool steer_req = (chrysler_platform == CHRYSLER_PACIFICA) ? (GET_BIT(to_send, 4U) != 0U) : ((GET_BYTE(to_send, 3) & 0x7U) == 2U);
if (steer_torque_cmd_checks(desired_torque, steer_req, limits)) {
tx = 0;
Expand Down Expand Up @@ -288,17 +285,17 @@ static const addr_checks* chrysler_init(uint16_t param) {
if (GET_FLAG(param, CHRYSLER_PARAM_RAM_DT)) {
chrysler_platform = CHRYSLER_RAM_DT;
chrysler_addrs = &CHRYSLER_RAM_DT_ADDRS;
chrysler_rx_checks = (addr_checks){chrysler_ram_dt_addr_checks, CHRYSLER_RAM_DT_ADDR_CHECK_LEN};
chrysler_rx_checks = SET_ADDR_CHECKS(chrysler_ram_dt_addr_checks);
} else if (GET_FLAG(param, CHRYSLER_PARAM_RAM_HD)) {
#ifdef ALLOW_DEBUG
chrysler_platform = CHRYSLER_RAM_HD;
chrysler_addrs = &CHRYSLER_RAM_HD_ADDRS;
chrysler_rx_checks = (addr_checks){chrysler_ram_hd_addr_checks, CHRYSLER_RAM_HD_ADDR_CHECK_LEN};
chrysler_rx_checks = SET_ADDR_CHECKS(chrysler_ram_hd_addr_checks);
#endif
} else {
chrysler_platform = CHRYSLER_PACIFICA;
chrysler_addrs = &CHRYSLER_ADDRS;
chrysler_rx_checks = (addr_checks){chrysler_addr_checks, CHRYSLER_ADDR_CHECK_LEN};
chrysler_rx_checks = SET_ADDR_CHECKS(chrysler_addr_checks);
}

return &chrysler_rx_checks;
Expand Down
3 changes: 1 addition & 2 deletions board/safety/safety_ford.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ AddrCheckStruct ford_addr_checks[] = {
{.msg = {{FORD_EngVehicleSpThrottle, 0, 8, .expected_timestep = 10000U}, { 0 }, { 0 }}},
{.msg = {{FORD_DesiredTorqBrk, 0, 8, .expected_timestep = 20000U}, { 0 }, { 0 }}},
};
#define FORD_ADDR_CHECK_LEN (sizeof(ford_addr_checks) / sizeof(ford_addr_checks[0]))
addr_checks ford_rx_checks = {ford_addr_checks, FORD_ADDR_CHECK_LEN};
addr_checks ford_rx_checks = SET_ADDR_CHECKS(ford_addr_checks);

static uint8_t ford_get_counter(CANPacket_t *to_push) {
int addr = GET_ADDR(to_push);
Expand Down
3 changes: 1 addition & 2 deletions board/safety/safety_gm.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ AddrCheckStruct gm_addr_checks[] = {
{.msg = {{0x1C4, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}},
{.msg = {{0xC9, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}},
};
#define GM_RX_CHECK_LEN (sizeof(gm_addr_checks) / sizeof(gm_addr_checks[0]))
addr_checks gm_rx_checks = {gm_addr_checks, GM_RX_CHECK_LEN};
addr_checks gm_rx_checks = SET_ADDR_CHECKS(gm_addr_checks);

const uint16_t GM_PARAM_HW_CAM = 1;
const uint16_t GM_PARAM_HW_CAM_LONG = 2;
Expand Down
13 changes: 5 additions & 8 deletions board/safety/safety_honda.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ AddrCheckStruct honda_common_addr_checks[] = {
{0x1BE, 0, 3, .check_checksum = true, .max_counter = 3U, .expected_timestep = 20000U}, { 0 }}}, // BRAKE_MODULE (for bosch radarless)
{.msg = {{0x326, 0, 8, .check_checksum = true, .max_counter = 3U, .expected_timestep = 100000U}, { 0 }, { 0 }}}, // SCM_FEEDBACK
};
#define HONDA_COMMON_ADDR_CHECKS_LEN (sizeof(honda_common_addr_checks) / sizeof(honda_common_addr_checks[0]))

// For Nidecs with main on signal on an alternate msg
AddrCheckStruct honda_nidec_alt_addr_checks[] = {
Expand All @@ -51,7 +50,6 @@ AddrCheckStruct honda_nidec_alt_addr_checks[] = {
{.msg = {{0x158, 0, 8, .check_checksum = true, .max_counter = 3U, .expected_timestep = 10000U}, { 0 }, { 0 }}},
{.msg = {{0x17C, 0, 8, .check_checksum = true, .max_counter = 3U, .expected_timestep = 10000U}, { 0 }, { 0 }}},
};
#define HONDA_NIDEC_ALT_ADDR_CHECKS_LEN (sizeof(honda_nidec_alt_addr_checks) / sizeof(honda_nidec_alt_addr_checks[0]))

// Bosch has pt on bus 1
AddrCheckStruct honda_bosch_addr_checks[] = {
Expand All @@ -61,7 +59,6 @@ AddrCheckStruct honda_bosch_addr_checks[] = {
{0x1BE, 1, 3, .check_checksum = true, .max_counter = 3U, .expected_timestep = 20000U}, { 0 }}},
{.msg = {{0x326, 1, 8, .check_checksum = true, .max_counter = 3U, .expected_timestep = 100000U}, { 0 }, { 0 }}},
};
#define HONDA_BOSCH_ADDR_CHECKS_LEN (sizeof(honda_bosch_addr_checks) / sizeof(honda_bosch_addr_checks[0]))

const uint16_t HONDA_PARAM_ALT_BRAKE = 1;
const uint16_t HONDA_PARAM_BOSCH_LONG = 2;
Expand All @@ -83,7 +80,7 @@ bool honda_fwd_brake = false;
bool honda_bosch_long = false;
bool honda_bosch_radarless = false;
enum {HONDA_NIDEC, HONDA_BOSCH} honda_hw = HONDA_NIDEC;
addr_checks honda_rx_checks = {honda_common_addr_checks, HONDA_COMMON_ADDR_CHECKS_LEN};
addr_checks honda_rx_checks = SET_ADDR_CHECKS(honda_common_addr_checks);


int honda_get_pt_bus(void) {
Expand Down Expand Up @@ -385,9 +382,9 @@ static const addr_checks* honda_nidec_init(uint16_t param) {
honda_bosch_radarless = false;

if (GET_FLAG(param, HONDA_PARAM_NIDEC_ALT)) {
honda_rx_checks = (addr_checks){honda_nidec_alt_addr_checks, HONDA_NIDEC_ALT_ADDR_CHECKS_LEN};
honda_rx_checks = SET_ADDR_CHECKS(honda_nidec_alt_addr_checks);
} else {
honda_rx_checks = (addr_checks){honda_common_addr_checks, HONDA_COMMON_ADDR_CHECKS_LEN};
honda_rx_checks = SET_ADDR_CHECKS(honda_common_addr_checks);
}
return &honda_rx_checks;
}
Expand All @@ -404,9 +401,9 @@ static const addr_checks* honda_bosch_init(uint16_t param) {
#endif

if (honda_bosch_radarless) {
honda_rx_checks = (addr_checks){honda_common_addr_checks, HONDA_COMMON_ADDR_CHECKS_LEN};
honda_rx_checks = SET_ADDR_CHECKS(honda_common_addr_checks);
} else {
honda_rx_checks = (addr_checks){honda_bosch_addr_checks, HONDA_BOSCH_ADDR_CHECKS_LEN};
honda_rx_checks = SET_ADDR_CHECKS(honda_bosch_addr_checks);
}
return &honda_rx_checks;
}
Expand Down
3 changes: 1 addition & 2 deletions board/safety/safety_mazda.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ AddrCheckStruct mazda_addr_checks[] = {
{.msg = {{MAZDA_ENGINE_DATA, 0, 8, .expected_timestep = 10000U}, { 0 }, { 0 }}},
{.msg = {{MAZDA_PEDALS, 0, 8, .expected_timestep = 20000U}, { 0 }, { 0 }}},
};
#define MAZDA_ADDR_CHECKS_LEN (sizeof(mazda_addr_checks) / sizeof(mazda_addr_checks[0]))
addr_checks mazda_rx_checks = {mazda_addr_checks, MAZDA_ADDR_CHECKS_LEN};
addr_checks mazda_rx_checks = SET_ADDR_CHECKS(mazda_addr_checks);

// track msgs coming from OP so that we know what CAM msgs to drop and what to forward
static int mazda_rx_hook(CANPacket_t *to_push) {
Expand Down
3 changes: 1 addition & 2 deletions board/safety/safety_nissan.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ AddrCheckStruct nissan_addr_checks[] = {
{0x454, 1, 8, .expected_timestep = 100000U},
{0x1cc, 0, 4, .expected_timestep = 10000U}}}, // DOORS_LIGHTS (10Hz) / BRAKE (100Hz)
};
#define NISSAN_ADDR_CHECK_LEN (sizeof(nissan_addr_checks) / sizeof(nissan_addr_checks[0]))
addr_checks nissan_rx_checks = {nissan_addr_checks, NISSAN_ADDR_CHECK_LEN};
addr_checks nissan_rx_checks = SET_ADDR_CHECKS(nissan_addr_checks);

// EPS Location. false = V-CAN, true = C-CAN
const int NISSAN_PARAM_ALT_EPS_BUS = 1;
Expand Down
10 changes: 4 additions & 6 deletions board/safety/safety_subaru.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,12 @@ const CanMsg SUBARU_GEN2_LONG_TX_MSGS[] = {
AddrCheckStruct subaru_addr_checks[] = {
SUBARU_COMMON_ADDR_CHECKS(SUBARU_MAIN_BUS)
};
#define SUBARU_ADDR_CHECK_LEN (sizeof(subaru_addr_checks) / sizeof(subaru_addr_checks[0]))
addr_checks subaru_rx_checks = {subaru_addr_checks, SUBARU_ADDR_CHECK_LEN};
addr_checks subaru_rx_checks = SET_ADDR_CHECKS(subaru_addr_checks);

AddrCheckStruct subaru_gen2_addr_checks[] = {
SUBARU_COMMON_ADDR_CHECKS(SUBARU_ALT_BUS)
};
#define SUBARU_GEN2_ADDR_CHECK_LEN (sizeof(subaru_gen2_addr_checks) / sizeof(subaru_gen2_addr_checks[0]))
addr_checks subaru_gen2_rx_checks = {subaru_gen2_addr_checks, SUBARU_GEN2_ADDR_CHECK_LEN};
addr_checks subaru_gen2_rx_checks = SET_ADDR_CHECKS(subaru_gen2_addr_checks);


const uint16_t SUBARU_PARAM_GEN2 = 1;
Expand Down Expand Up @@ -300,9 +298,9 @@ static const addr_checks* subaru_init(uint16_t param) {
#endif

if (subaru_gen2) {
subaru_rx_checks = (addr_checks){subaru_gen2_addr_checks, SUBARU_GEN2_ADDR_CHECK_LEN};
subaru_rx_checks = SET_ADDR_CHECKS(subaru_gen2_addr_checks);
} else {
subaru_rx_checks = (addr_checks){subaru_addr_checks, SUBARU_ADDR_CHECK_LEN};
subaru_rx_checks = SET_ADDR_CHECKS(subaru_addr_checks);
}

return &subaru_rx_checks;
Expand Down
3 changes: 1 addition & 2 deletions board/safety/safety_subaru_preglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ AddrCheckStruct subaru_preglobal_addr_checks[] = {
{.msg = {{MSG_SUBARU_PG_Steering_Torque, SUBARU_PG_MAIN_BUS, 8, .expected_timestep = 20000U}, { 0 }, { 0 }}},
{.msg = {{MSG_SUBARU_PG_CruiseControl, SUBARU_PG_MAIN_BUS, 8, .expected_timestep = 50000U}, { 0 }, { 0 }}},
};
#define SUBARU_PG_ADDR_CHECK_LEN (sizeof(subaru_preglobal_addr_checks) / sizeof(subaru_preglobal_addr_checks[0]))
addr_checks subaru_preglobal_rx_checks = {subaru_preglobal_addr_checks, SUBARU_PG_ADDR_CHECK_LEN};
addr_checks subaru_preglobal_rx_checks = SET_ADDR_CHECKS(subaru_preglobal_addr_checks);


const int SUBARU_PG_PARAM_REVERSED_DRIVER_TORQUE = 1;
Expand Down
6 changes: 2 additions & 4 deletions board/safety/safety_tesla.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ AddrCheckStruct tesla_addr_checks[] = {
{.msg = {{0x368, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}}, // DI_state (10Hz)
{.msg = {{0x318, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}}, // GTW_carState (10Hz)
};
#define TESLA_ADDR_CHECK_LEN (sizeof(tesla_addr_checks) / sizeof(tesla_addr_checks[0]))
addr_checks tesla_rx_checks = {tesla_addr_checks, TESLA_ADDR_CHECK_LEN};
addr_checks tesla_rx_checks = SET_ADDR_CHECKS(tesla_addr_checks);

AddrCheckStruct tesla_pt_addr_checks[] = {
{.msg = {{0x106, 0, 8, .expected_timestep = 10000U}, { 0 }, { 0 }}}, // DI_torque1 (100Hz)
Expand All @@ -52,8 +51,7 @@ AddrCheckStruct tesla_pt_addr_checks[] = {
{.msg = {{0x2bf, 2, 8, .expected_timestep = 40000U}, { 0 }, { 0 }}}, // DAS_control (25Hz)
{.msg = {{0x256, 0, 8, .expected_timestep = 100000U}, { 0 }, { 0 }}}, // DI_state (10Hz)
};
#define TESLA_PT_ADDR_CHECK_LEN (sizeof(tesla_pt_addr_checks) / sizeof(tesla_pt_addr_checks[0]))
addr_checks tesla_pt_rx_checks = {tesla_pt_addr_checks, TESLA_PT_ADDR_CHECK_LEN};
addr_checks tesla_pt_rx_checks = SET_ADDR_CHECKS(tesla_pt_addr_checks);

bool tesla_longitudinal = false;
bool tesla_powertrain = false; // Are we the second panda intercepting the powertrain bus?
Expand Down
3 changes: 1 addition & 2 deletions board/safety/safety_toyota.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ AddrCheckStruct toyota_addr_checks[] = {
{.msg = {{0x224, 0, 8, .check_checksum = false, .expected_timestep = 25000U},
{0x226, 0, 8, .check_checksum = false, .expected_timestep = 25000U}, { 0 }}},
};
#define TOYOTA_ADDR_CHECKS_LEN (sizeof(toyota_addr_checks) / sizeof(toyota_addr_checks[0]))
addr_checks toyota_rx_checks = {toyota_addr_checks, TOYOTA_ADDR_CHECKS_LEN};
addr_checks toyota_rx_checks = SET_ADDR_CHECKS(toyota_addr_checks);

// safety param flags
// first byte is for eps factor, second is for flags
Expand Down
3 changes: 1 addition & 2 deletions board/safety/safety_volkswagen_mqb.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ AddrCheckStruct volkswagen_mqb_addr_checks[] = {
{.msg = {{MSG_MOTOR_20, 0, 8, .check_checksum = true, .max_counter = 15U, .expected_timestep = 20000U}, { 0 }, { 0 }}},
{.msg = {{MSG_MOTOR_14, 0, 8, .check_checksum = false, .max_counter = 0U, .expected_timestep = 100000U}, { 0 }, { 0 }}},
};
#define VOLKSWAGEN_MQB_ADDR_CHECKS_LEN (sizeof(volkswagen_mqb_addr_checks) / sizeof(volkswagen_mqb_addr_checks[0]))
addr_checks volkswagen_mqb_rx_checks = {volkswagen_mqb_addr_checks, VOLKSWAGEN_MQB_ADDR_CHECKS_LEN};
addr_checks volkswagen_mqb_rx_checks = SET_ADDR_CHECKS(volkswagen_mqb_addr_checks);

uint8_t volkswagen_crc8_lut_8h2f[256]; // Static lookup table for CRC8 poly 0x2F, aka 8H2F/AUTOSAR
bool volkswagen_mqb_brake_pedal_switch = false;
Expand Down
3 changes: 1 addition & 2 deletions board/safety/safety_volkswagen_pq.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ AddrCheckStruct volkswagen_pq_addr_checks[] = {
{.msg = {{MSG_MOTOR_5, 0, 8, .check_checksum = true, .max_counter = 0U, .expected_timestep = 20000U}, { 0 }, { 0 }}},
{.msg = {{MSG_GRA_NEU, 0, 4, .check_checksum = true, .max_counter = 15U, .expected_timestep = 33000U}, { 0 }, { 0 }}},
};
#define VOLKSWAGEN_PQ_ADDR_CHECKS_LEN (sizeof(volkswagen_pq_addr_checks) / sizeof(volkswagen_pq_addr_checks[0]))
addr_checks volkswagen_pq_rx_checks = {volkswagen_pq_addr_checks, VOLKSWAGEN_PQ_ADDR_CHECKS_LEN};
addr_checks volkswagen_pq_rx_checks = SET_ADDR_CHECKS(volkswagen_pq_addr_checks);

static uint32_t volkswagen_pq_get_checksum(CANPacket_t *to_push) {
int addr = GET_ADDR(to_push);
Expand Down