|
| 1 | +/** @file |
| 2 | + 6SC2 - Car Remote. |
| 3 | +
|
| 4 | + Copyright (C) 2024 Ethan Halsall |
| 5 | +
|
| 6 | + This program is free software; you can redistribute it and/or modify |
| 7 | + it under the terms of the GNU General Public License as published by |
| 8 | + the Free Software Foundation; either version 2 of the License, or |
| 9 | + (at your option) any later version. |
| 10 | +*/ |
| 11 | +/** @fn int six_sc_two_car_remote_decode(r_device *decoder, bitbuffer_t *bitbuffer) |
| 12 | +6SC2 - Car Remote (315 MHz) |
| 13 | +
|
| 14 | +Manufacturer: |
| 15 | +- Unknown |
| 16 | +
|
| 17 | +Supported Models: |
| 18 | +- 6SC2 CMGU |
| 19 | +- 6SC2 CDFA |
| 20 | +
|
| 21 | +Data structure: |
| 22 | +
|
| 23 | +The transmitter uses a rolling code message with an unencrypted sequence number. |
| 24 | +
|
| 25 | +Button operation: |
| 26 | +This transmitter has up to 4 buttons which can be pressed once to transmit a single message |
| 27 | +
|
| 28 | +Data layout: |
| 29 | +
|
| 30 | +Bytes are reflected |
| 31 | +
|
| 32 | +PPPP EEEEEEEE bbbb uuuu SSSS CC |
| 33 | +
|
| 34 | +- P: 16 bit preamble |
| 35 | +- E: 32 bit encrypted |
| 36 | +- b: 4 bit button |
| 37 | +- u: 4 bit unknown |
| 38 | +- S: 16 bit sequence |
| 39 | +- C: 8 bit checksum |
| 40 | +
|
| 41 | +Format string: |
| 42 | +
|
| 43 | +PREAMBLE: hhhh ENCRYPTED: hh hh hh hh BUTTON: bbbb UNKNOWN: bbbb SEQUENCE: hhhh CHECKSUM: hh |
| 44 | +
|
| 45 | +*/ |
| 46 | + |
| 47 | +#include "decoder.h" |
| 48 | + |
| 49 | +static int six_sc_two_car_remote_decode(r_device *decoder, bitbuffer_t *bitbuffer) |
| 50 | +{ |
| 51 | + int row = bitbuffer_find_repeated_row(bitbuffer, 1, 48); |
| 52 | + |
| 53 | + if (bitbuffer->bits_per_row[row] > 88) { |
| 54 | + return DECODE_ABORT_LENGTH; |
| 55 | + } |
| 56 | + |
| 57 | + uint8_t *bytes = bitbuffer->bb[row]; |
| 58 | + |
| 59 | + if (bytes[0] != 0x55 || bytes[1] != 0x54) { |
| 60 | + return DECODE_FAIL_SANITY; |
| 61 | + } |
| 62 | + |
| 63 | + if (xor_bytes(bytes + 2, 9)) { |
| 64 | + return DECODE_FAIL_MIC; |
| 65 | + } |
| 66 | + |
| 67 | + // The transmission is LSB first, big endian. |
| 68 | + uint32_t encrypted = (uint32_t)reverse8(bytes[5]) << 24 | (uint32_t)reverse8(bytes[4]) << 16 | (uint32_t)reverse8(bytes[3]) << 8 | reverse8(bytes[2]); |
| 69 | + int button = reverse8(bytes[6]) & 0xf; |
| 70 | + int sequence = (reverse8(bytes[8]) << 8) | reverse8(bytes[7]); |
| 71 | + |
| 72 | + char encrypted_str[9]; |
| 73 | + snprintf(encrypted_str, sizeof(encrypted_str), "%08X", encrypted); |
| 74 | + |
| 75 | + char const *button_str; |
| 76 | + |
| 77 | + /* clang-format off */ |
| 78 | + switch (button) { |
| 79 | + case 0x1: button_str = "Unlock"; break; |
| 80 | + case 0x2: button_str = "Lock"; break; |
| 81 | + case 0x3: button_str = "Trunk"; break; |
| 82 | + case 0x4: button_str = "Panic"; break; |
| 83 | + default: button_str = "?"; break; |
| 84 | + } |
| 85 | + /* clang-format on */ |
| 86 | + |
| 87 | + /* clang-format off */ |
| 88 | + data_t *data = data_make( |
| 89 | + "model", "model", DATA_STRING, "6SC2-CarRemote", |
| 90 | + "encrypted", "", DATA_STRING, encrypted_str, |
| 91 | + "button_code", "Button Code", DATA_INT, button, |
| 92 | + "button_str", "Button", DATA_STRING, button_str, |
| 93 | + "sequence", "Sequence", DATA_INT, sequence, |
| 94 | + "mic", "Integrity", DATA_STRING, "CHECKSUM", |
| 95 | + NULL); |
| 96 | + /* clang-format on */ |
| 97 | + |
| 98 | + decoder_output_data(decoder, data); |
| 99 | + return 1; |
| 100 | +} |
| 101 | + |
| 102 | +static char const *const output_fields[] = { |
| 103 | + "model", |
| 104 | + "encrypted", |
| 105 | + "button_code", |
| 106 | + "button_str", |
| 107 | + "sequence", |
| 108 | + "mic", |
| 109 | + NULL, |
| 110 | +}; |
| 111 | + |
| 112 | +r_device const six_sc_two_car_remote = { |
| 113 | + .name = "6SC2 Car Remote (-f 315.1M)", |
| 114 | + .modulation = OOK_PULSE_MANCHESTER_ZEROBIT, |
| 115 | + .short_width = 250, |
| 116 | + .reset_limit = 10000, |
| 117 | + .decode_fn = &six_sc_two_car_remote_decode, |
| 118 | + .fields = output_fields, |
| 119 | +}; |
0 commit comments