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: enforce expected messages in rx hook #1657

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion board/safety.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,11 @@ bool addr_safety_check(CANPacket_t *to_push,
} else {
rx_checks->check[index].valid_quality_flag = true;
}
return is_msg_valid(rx_checks->check, index);
} else {
// messages not in address checks are not valid
return false;
}
return is_msg_valid(rx_checks->check, index);
}

void generic_rx_checks(bool stock_ecu_detected) {
Expand Down
2 changes: 1 addition & 1 deletion board/safety/safety_hyundai.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ static int hyundai_rx_hook(CANPacket_t *to_push) {
}
generic_rx_checks(stock_ecu_detected);
}
return valid;
return true;
}

static int hyundai_tx_hook(CANPacket_t *to_send) {
Expand Down
6 changes: 4 additions & 2 deletions board/safety/safety_hyundai_canfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ AddrCheckStruct hyundai_canfd_ice_addr_checks[] = {
{.msg = {{0xea, 0, 24, .check_checksum = true, .max_counter = 0xffU, .expected_timestep = 10000U}, { 0 }, { 0 }}},
{.msg = {{0x175, 0, 24, .check_checksum = true, .max_counter = 0xffU, .expected_timestep = 20000U}, { 0 }, { 0 }}},
{.msg = {{0x1aa, 0, 16, .check_checksum = false, .max_counter = 0xffU, .expected_timestep = 20000U}, { 0 }, { 0 }}},
{.msg = {{0x1a0, 0, 32, .check_checksum = true, .max_counter = 0xffU, .expected_timestep = 20000U},
{0x1a0, 2, 32, .check_checksum = true, .max_counter = 0xffU, .expected_timestep = 20000U}, { 0 }}},
Copy link
Contributor Author

@sshane sshane Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't do this, race condition. need new rx check list, pending a PR like #1655 for CAN FD. ICE cars can be radar ACC or camera ACC

};
#define HYUNDAI_CANFD_ICE_ADDR_CHECK_LEN (sizeof(hyundai_canfd_ice_addr_checks) / sizeof(hyundai_canfd_ice_addr_checks[0]))

Expand Down Expand Up @@ -235,7 +237,7 @@ static int hyundai_canfd_rx_hook(CANPacket_t *to_push) {

if (valid && (bus == scc_bus)) {
// cruise state
if ((addr == 0x1a0) && !hyundai_longitudinal) {
if ((addr == 0x1a0)) {
// 1=enabled, 2=driver override
int cruise_status = ((GET_BYTE(to_push, 8) >> 4) & 0x7U);
bool cruise_engaged = (cruise_status == 1) || (cruise_status == 2);
Expand All @@ -253,7 +255,7 @@ static int hyundai_canfd_rx_hook(CANPacket_t *to_push) {
}
generic_rx_checks(stock_ecu_detected);

return valid;
return true;
}

static int hyundai_canfd_tx_hook(CANPacket_t *to_send) {
Expand Down
Loading