v1.2.0: Add 4 new protocols, fix 5 existing, port Kia V6 encoder

New protocols (from ProtoPirate):
- Mazda V0: 433MHz, pair-based decoding, XOR deobfuscation
- Mitsubishi V0: 868MHz, PWM, bit negation + XOR unscrambling
- Porsche Touareg: 433/868MHz, sync preamble, 24-bit rotate cipher
- Fiat V1 (Magneti Marelli BSI): 433MHz, auto-detected timing variants

Protocol fixes aligned with ProtoPirate reference:
- Kia V1: Fix Manchester level mapping (inverted convention), off-by-one
  bit count, CRC4 simplified to 7 bytes + offset 1
- Kia V2: Fix CRC byte layout (was double-counting nibbles), off-by-one
  bit count, preamble short-HIGH handling
- Fiat V0: Fix endbyte transform (remove (<<1)|1), standard Manchester
  encoder (was differential), 7 btn bits (was 6), gap path fallback
- PSA: Fix modified TEA (XTEA-like dynamic key selection), XOR decrypt
  byte mapping, critical key2_low construction bug, encoder polarity and
  preamble, add key1_high nibble validation, dual preamble patterns
- Ford V0: Add calculate_checksum (sums all serial+count bytes) for encoder

Kia V6 encoder ported:
- Forward AES-128 (SubBytes, ShiftRows, MixColumns, encrypt)
- encrypt_payload: build plaintext, AES encrypt, pack into 3 parts
- Two-pass Manchester upload (640 + 38 preamble pairs)
- fx_field extraction stored in DecodedSignal.extra for encode roundtrip

Updated README, protocol docs, and version bump to 1.2.0.
This commit is contained in:
KaraZajac
2026-03-22 12:05:01 -04:00
parent 84b75ee6b5
commit 48ee413c9b
22 changed files with 2318 additions and 305 deletions
+16 -15
View File
@@ -57,18 +57,17 @@ impl KiaV2Decoder {
}
}
/// CRC4 for Kia V2 (matches kia_v2.c: 6-byte permuted input, XOR nibbles, offset 1)
/// CRC4 for Kia V2 (matches kia_v2.c: strip CRC nibble, XOR all remaining nibbles, + offset 1)
fn calculate_crc(data: u64) -> u8 {
let serial = ((data >> 20) & 0xFFFFFFFF) as u32;
let u_var4 = (data & 0xFFFFFFFF) as u32;
// C code: data_without_crc = data >> 4; then read 6 sequential bytes (bits 4..51)
let data_without_crc = data >> 4;
let mut bytes = [0u8; 6];
bytes[0] = (u_var4 >> 20) as u8;
bytes[1] = ((u_var4 >> 28) | ((serial & 0x0F) << 4)) as u8;
bytes[2] = (serial >> 4) as u8;
bytes[3] = (serial >> 12) as u8;
bytes[4] = (u_var4 >> 4) as u8;
bytes[5] = (u_var4 >> 12) as u8;
bytes[0] = (data_without_crc & 0xFF) as u8;
bytes[1] = ((data_without_crc >> 8) & 0xFF) as u8;
bytes[2] = ((data_without_crc >> 16) & 0xFF) as u8;
bytes[3] = ((data_without_crc >> 24) & 0xFF) as u8;
bytes[4] = ((data_without_crc >> 32) & 0xFF) as u8;
bytes[5] = ((data_without_crc >> 40) & 0xFF) as u8;
let mut crc: u8 = 0;
for &byte in &bytes {
@@ -181,19 +180,21 @@ impl ProtocolDecoder for KiaV2Decoder {
self.te_last = duration;
self.header_count += 1;
} else if is_short && self.header_count >= 100 {
// C code: decode_count_bit=1, then add_bit(1) which shifts and increments to 2
self.header_count = 0;
self.decode_data = 0;
self.decode_count_bit = 1;
self.step = DecoderStep::CollectRawBits;
self.decode_data = 1; // First bit
self.decode_count_bit = 2;
self.step = DecoderStep::CollectRawBits;
} else {
self.step = DecoderStep::Reset;
self.te_last = duration; // C stays in CheckPreamble, updates te_last
}
} else {
if is_long {
self.header_count += 1;
self.te_last = duration;
} else if !is_short {
} else if is_short {
self.te_last = duration; // C stays in CheckPreamble for short LOW
} else {
self.step = DecoderStep::Reset;
}
}