Chrysler: calculate checksum in can packer/parser (#255)

* calculate chrysler checksum in can packer/parser

* remove comment
This commit is contained in:
Adeeb 2020-04-30 14:06:26 -07:00 committed by GitHub
parent 0c0215516f
commit 7f3b1774dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 53 additions and 1 deletions

View File

@ -35,6 +35,38 @@ unsigned int subaru_checksum(unsigned int address, uint64_t d, int l) {
return s & 0xFF;
}
unsigned int chrysler_checksum(unsigned int address, uint64_t d, int l) {
/* This function does not want the checksum byte in the input data.
jeep chrysler canbus checksum from http://illmatics.com/Remote%20Car%20Hacking.pdf */
uint8_t checksum = 0xFF;
for (int j = 0; j < (l - 1); j++) {
uint8_t shift = 0x80;
uint8_t curr = (d >> 8*j) & 0xFF;
for (int i=0; i<8; i++) {
uint8_t bit_sum = curr & shift;
uint8_t temp_chk = checksum & 0x80U;
if (bit_sum != 0U) {
bit_sum = 0x1C;
if (temp_chk != 0U) {
bit_sum = 1;
}
checksum = checksum << 1;
temp_chk = checksum | 1U;
bit_sum ^= temp_chk;
} else {
if (temp_chk != 0U) {
bit_sum = 0x1D;
}
checksum = checksum << 1;
bit_sum ^= checksum;
}
checksum = bit_sum;
shift = shift >> 1;
}
}
return ~checksum & 0xFF;
}
// Static lookup table for fast computation of CRC8 poly 0x2F, aka 8H2F/AUTOSAR
uint8_t crc8_lut_8h2f[256];

View File

@ -14,6 +14,7 @@
unsigned int honda_checksum(unsigned int address, uint64_t d, int l);
unsigned int toyota_checksum(unsigned int address, uint64_t d, int l);
unsigned int subaru_checksum(unsigned int address, uint64_t d, int l);
unsigned int chrysler_checksum(unsigned int address, uint64_t d, int l);
void init_crc_lookup_tables();
unsigned int volkswagen_crc(unsigned int address, uint64_t d, int l);
unsigned int pedal_checksum(uint64_t d, int l);

View File

@ -19,7 +19,8 @@ cdef extern from "common_dbc.h":
PEDAL_COUNTER,
VOLKSWAGEN_CHECKSUM,
VOLKSWAGEN_COUNTER,
SUBARU_CHECKSUM
SUBARU_CHECKSUM,
CHRYSLER_CHECKSUM
cdef struct Signal:
const char* name

View File

@ -39,6 +39,7 @@ enum SignalType {
VOLKSWAGEN_CHECKSUM,
VOLKSWAGEN_COUNTER,
SUBARU_CHECKSUM,
CHRYSLER_CHECKSUM,
};
struct Signal {

View File

@ -31,6 +31,8 @@ const Signal sigs_{{address}}[] = {
.type = SignalType::VOLKSWAGEN_COUNTER,
{% elif checksum_type == "subaru" and sig.name == "CHECKSUM" %}
.type = SignalType::SUBARU_CHECKSUM,
{% elif checksum_type == "chrysler" and sig.name == "CHECKSUM" %}
.type = SignalType::CHRYSLER_CHECKSUM,
{% elif address in [512, 513] and sig.name == "CHECKSUM_PEDAL" %}
.type = SignalType::PEDAL_CHECKSUM,
{% elif address in [512, 513] and sig.name == "COUNTER_PEDAL" %}

View File

@ -102,6 +102,9 @@ uint64_t CANPacker::pack(uint32_t address, const std::vector<SignalPackValue> &s
} else if (sig.type == SignalType::SUBARU_CHECKSUM) {
unsigned int chksm = subaru_checksum(address, ret, message_lookup[address].size);
ret = set_value(ret, sig, chksm);
} else if (sig.type == SignalType::CHRYSLER_CHECKSUM) {
unsigned int chksm = chrysler_checksum(address, ReverseBytes(ret), message_lookup[address].size);
ret = set_value(ret, sig, chksm);
} else {
//WARN("CHECKSUM signal type not valid\n");
}

View File

@ -57,6 +57,11 @@ bool MessageState::parse(uint64_t sec, uint16_t ts_, uint8_t * dat) {
if (!update_counter_generic(tmp, sig.b2)) {
return false;
}
} else if (sig.type == SignalType::CHRYSLER_CHECKSUM) {
if (chrysler_checksum(address, dat_le, size) != tmp) {
INFO("0x%X CHECKSUM FAIL\n", address);
return false;
}
} else if (sig.type == SignalType::PEDAL_CHECKSUM) {
if (pedal_checksum(dat_be, size) != tmp) {
INFO("0x%X PEDAL CHECKSUM FAIL\n", address);

View File

@ -53,6 +53,13 @@ def process(in_fn, out_fn):
checksum_start_bit = 0
counter_start_bit = None
little_endian = True
elif can_dbc.name.startswith(("chrysler_")):
checksum_type = "chrysler"
checksum_size = 8
counter_size = None
checksum_start_bit = 7
counter_start_bit = None
little_endian = False
else:
checksum_type = None
checksum_size = None