Skip to content

Commit

Permalink
correct the LKAS can message spoofing
Browse files Browse the repository at this point in the history
  • Loading branch information
visualage committed Feb 26, 2024
1 parent df9d38f commit 3e86787
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions board/safety/safety_defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ static void send_steer_enable_speed(CAN_FIFOMailBox_TypeDef *to_fwd){
if (actual_speed < apa_enable_speed) {
eps_cutoff_speed = apa_enable_speed >> 8 | ((apa_enable_speed << 8) & 0xFFFF); //2kph with 128 factor
}
is_speed_spoofed = true;
counter_speed_spoofed = counter_speed_spoofed + 1;
}
else if (steer_type == 1) {
if (actual_speed < lkas_enable_speed) {
eps_cutoff_speed = lkas_enable_speed >> 8 | ((lkas_enable_speed << 8) & 0xFFFF); //65kph with 128 factor
}
is_speed_spoofed = true;
counter_speed_spoofed = counter_speed_spoofed + 1;
}

to_fwd->RDHR &= 0x00FF0000; //clear speed and Checksum
Expand Down Expand Up @@ -119,11 +119,12 @@ static void send_apa_signature(CAN_FIFOMailBox_TypeDef *to_fwd){
static void send_lkas_command(CAN_FIFOMailBox_TypeDef *to_fwd){
int crc;

if ((steer_type == 1) && is_op_active && !is_speed_spoofed) {
to_fwd->RDLR &= 0x00000000; //clear everything for new lkas command
to_fwd->RDHR &= 0x00FF0000; //clear everything except counter
if ((steer_type == 1) && is_op_active && counter_speed_spoofed < 5) {
to_fwd->RDLR &= 0x00000000; // clear everything for new lkas command
to_fwd->RDLR |= 0x00000004; // make sure torque highest bit is 1
to_fwd->RDHR &= 0x000000FF; // clear everything except counter
crc = fca_compute_checksum(to_fwd);
to_fwd->RDHR |= (((crc << 8) << 8) << 8); //replace Checksum
to_fwd->RDHR |= (crc << 8); // replace Checksum
} else { //pass through
to_fwd->RDLR |= 0x00000000;
to_fwd->RDHR |= 0x00000000;
Expand Down Expand Up @@ -224,7 +225,7 @@ int default_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
steer_type = 1;
} else {
steer_type = 3;
is_speed_spoofed = false;
counter_speed_spoofed = 0;
}
lkas_torq = ((GET_BYTE(to_push, 0) & 0x7) << 8) | GET_BYTE(to_push, 1);
counter_658 += 1;
Expand All @@ -245,7 +246,7 @@ int default_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
counter_284_658 += 2;
if (counter_284_658 - counter_658 > 25){
is_op_active = false;
is_speed_spoofed = false;
counter_speed_spoofed = 0;
steer_type = 3;
counter_658 = 0;
counter_284_658 = 0;
Expand Down
2 changes: 1 addition & 1 deletion board/safety_declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ bool vehicle_moving = false;
bool is_op_active = false;
int lkas_torq = 1024;
int steer_type = 3;
bool is_speed_spoofed = false;
uint32_t counter_speed_spoofed = 0;

bool is_oplong_enabled = false;
int acc_set_speed_kph = 255;
Expand Down

0 comments on commit 3e86787

Please sign in to comment.