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 tests: more coverage #1714

Merged
merged 3 commits into from
Nov 10, 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
9 changes: 2 additions & 7 deletions board/safety/safety_ford.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,22 @@ addr_checks ford_rx_checks = {ford_addr_checks, FORD_ADDR_CHECK_LEN};
static uint8_t ford_get_counter(CANPacket_t *to_push) {
int addr = GET_ADDR(to_push);

uint8_t cnt;
uint8_t cnt = 0;
if (addr == FORD_BrakeSysFeatures) {
// Signal: VehVActlBrk_No_Cnt
cnt = (GET_BYTE(to_push, 2) >> 2) & 0xFU;
} else if (addr == FORD_EngVehicleSpThrottle2) {
// Signal: VehVActlEng_No_Cnt
cnt = (GET_BYTE(to_push, 2) >> 3) & 0xFU;
} else if (addr == FORD_Yaw_Data_FD1) {
// Signal: VehRollYaw_No_Cnt
cnt = GET_BYTE(to_push, 5);
} else {
cnt = 0;
}
return cnt;
}

static uint32_t ford_get_checksum(CANPacket_t *to_push) {
int addr = GET_ADDR(to_push);

uint8_t chksum;
uint8_t chksum = 0;
if (addr == FORD_BrakeSysFeatures) {
// Signal: VehVActlBrk_No_Cs
chksum = GET_BYTE(to_push, 3);
Expand All @@ -107,7 +103,6 @@ static uint32_t ford_get_checksum(CANPacket_t *to_push) {
// Signal: VehRollYawW_No_Cs
chksum = GET_BYTE(to_push, 4);
} else {
chksum = 0;
}
return chksum;
}
Expand Down
6 changes: 2 additions & 4 deletions board/safety/safety_hyundai.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ addr_checks hyundai_rx_checks = SET_ADDR_CHECKS(hyundai_addr_checks);
static uint8_t hyundai_get_counter(CANPacket_t *to_push) {
int addr = GET_ADDR(to_push);

uint8_t cnt;
uint8_t cnt = 0;
if (addr == 0x260) {
cnt = (GET_BYTE(to_push, 7) >> 4) & 0x3U;
} else if (addr == 0x386) {
Expand All @@ -101,15 +101,14 @@ static uint8_t hyundai_get_counter(CANPacket_t *to_push) {
} else if (addr == 0x4F1) {
cnt = (GET_BYTE(to_push, 3) >> 4) & 0xFU;
} else {
cnt = 0;
}
return cnt;
}

static uint32_t hyundai_get_checksum(CANPacket_t *to_push) {
int addr = GET_ADDR(to_push);

uint8_t chksum;
uint8_t chksum = 0;
if (addr == 0x260) {
chksum = GET_BYTE(to_push, 7) & 0xFU;
} else if (addr == 0x386) {
Expand All @@ -119,7 +118,6 @@ static uint32_t hyundai_get_checksum(CANPacket_t *to_push) {
} else if (addr == 0x421) {
chksum = GET_BYTE(to_push, 7) >> 4;
} else {
chksum = 0;
}
return chksum;
}
Expand Down
6 changes: 1 addition & 5 deletions board/safety/safety_hyundai_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ uint32_t hyundai_common_canfd_compute_checksum(CANPacket_t *to_push) {
crc = (crc << 8U) ^ hyundai_canfd_crc_lut[(crc >> 8U) ^ ((address >> 0U) & 0xFFU)];
crc = (crc << 8U) ^ hyundai_canfd_crc_lut[(crc >> 8U) ^ ((address >> 8U) & 0xFFU)];

if (len == 8) {
crc ^= 0x5f29U;
} else if (len == 16) {
crc ^= 0x041dU;
} else if (len == 24) {
if (len == 24) {
crc ^= 0x819dU;
} else if (len == 32) {
crc ^= 0x9f5bU;
Expand Down
24 changes: 9 additions & 15 deletions board/safety/safety_volkswagen_mqb.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,15 @@ static uint32_t volkswagen_mqb_compute_crc(CANPacket_t *to_push) {
}

uint8_t counter = volkswagen_mqb_get_counter(to_push);
switch(addr) {
case MSG_LH_EPS_03:
crc ^= (uint8_t[]){0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5}[counter];
break;
case MSG_ESP_05:
crc ^= (uint8_t[]){0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07}[counter];
break;
case MSG_TSK_06:
crc ^= (uint8_t[]){0xC4,0xE2,0x4F,0xE4,0xF8,0x2F,0x56,0x81,0x9F,0xE5,0x83,0x44,0x05,0x3F,0x97,0xDF}[counter];
break;
case MSG_MOTOR_20:
crc ^= (uint8_t[]){0xE9,0x65,0xAE,0x6B,0x7B,0x35,0xE5,0x5F,0x4E,0xC7,0x86,0xA2,0xBB,0xDD,0xEB,0xB4}[counter];
break;
default: // Undefined CAN message, CRC check expected to fail
break;
if (addr == MSG_LH_EPS_03) {
crc ^= (uint8_t[]){0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5,0xF5}[counter];
} else if (addr == MSG_ESP_05) {
crc ^= (uint8_t[]){0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07}[counter];
} else if (addr == MSG_TSK_06) {
crc ^= (uint8_t[]){0xC4,0xE2,0x4F,0xE4,0xF8,0x2F,0x56,0x81,0x9F,0xE5,0x83,0x44,0x05,0x3F,0x97,0xDF}[counter];
} else if (addr == MSG_MOTOR_20) {
crc ^= (uint8_t[]){0xE9,0x65,0xAE,0x6B,0x7B,0x35,0xE5,0x5F,0x4E,0xC7,0x86,0xA2,0xBB,0xDD,0xEB,0xB4}[counter];
} else { // Undefined CAN message, CRC check expected to fail
}
crc = volkswagen_crc8_lut_8h2f[crc];

Expand Down
1 change: 0 additions & 1 deletion board/safety/safety_volkswagen_pq.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ static uint8_t volkswagen_pq_get_counter(CANPacket_t *to_push) {
} else if (addr == MSG_GRA_NEU) {
counter = (uint8_t)(GET_BYTE(to_push, 2) & 0xF0U) >> 4;
} else {
counter = 0U;
}

return counter;
Expand Down
Loading