updated protoview

This commit is contained in:
jbohack
2023-01-23 14:21:10 -05:00
parent 35fe007814
commit 5c4f4cfbd2
26 changed files with 2224 additions and 274 deletions

View File

@@ -32,9 +32,11 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
const char *sync_pattern = "101010101010101010101010" "0000";
uint8_t sync_len = 24+4;
if (numbits-sync_len+sync_len < 3*66) return false;
uint64_t off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_pattern);
uint32_t off = bitmap_seek_bits(bits,numbytes,0,numbits,sync_pattern);
if (off == BITMAP_SEEK_NOT_FOUND) return false;
off += sync_len;
info->start_off = off;
off += sync_len; // Seek start of message.
/* Now there is half the gap left, but we allow from 3 to 7, instead of 5
* symbols of gap, to avoid missing the signal for a matter of wrong
@@ -52,36 +54,72 @@ static bool decode(uint8_t *bits, uint32_t numbytes, uint32_t numbits, ProtoView
convert_from_line_code(raw,sizeof(raw),bits,numbytes,off,
"110","100"); /* Pulse width modulation. */
FURI_LOG_E(TAG, "Keeloq decoded bits: %lu", decoded);
if (decoded < 66) return false; /* Require the full 66 bits. */
bitmap_reverse_bytes(raw,sizeof(raw)); /* Keeloq is LSB first. */
info->pulses_count = (off+66*3) - info->start_off;
bitmap_reverse_bytes_bits(raw,sizeof(raw)); /* Keeloq is LSB first. */
int buttons = raw[7]>>4;
int s3 = (buttons&1) != 0;
int s0 = (buttons&2) != 0;
int s1 = (buttons&4) != 0;
int s2 = (buttons&8) != 0;
int lowbat = (raw[8]&0x1) == 0; // Actual bit meaning: good battery level
int alwaysone = (raw[8]&0x2) != 0;
int remote_id = ((raw[7]&0x0f) << 24) |
(raw[6] << 16) |
(raw[5] << 8) |
(raw[4] << 0);
int lowbat = raw[8]&0x80;
snprintf(info->name,sizeof(info->name),"%s","Keeloq remote");
snprintf(info->raw,sizeof(info->raw),"%02X%02X%02X%02X%02X%02X%02X%02X%02X",
raw[0],raw[1],raw[2],raw[3],raw[4],raw[5],
raw[6],raw[7],raw[8]);
snprintf(info->info1,sizeof(info->info1),"Encrpyted %02X%02X%02X%02X",
raw[3],raw[2],raw[1],raw[0]);
snprintf(info->info2,sizeof(info->info2),"ID %08X", remote_id);
snprintf(info->info3,sizeof(info->info3),"s0-s3: %d%d%d%d",
s0,s1,s2,s3);
snprintf(info->info4,sizeof(info->info4),"Low battery? %s",
lowbat ? "yes" : "no");
fieldset_add_bytes(info->fieldset,"encr",raw,8);
raw[7] = raw[7]<<4; // Make ID bits contiguous
fieldset_add_bytes(info->fieldset,"id",raw+4,7); // 28 bits, 7 nibbles
fieldset_add_bin(info->fieldset,"s[2,1,0,3]",buttons,4);
fieldset_add_bin(info->fieldset,"low battery",lowbat,1);
fieldset_add_bin(info->fieldset,"always one",alwaysone,1);
return true;
}
static void get_fields(ProtoViewFieldSet *fieldset) {
uint8_t remote_id[4] = {0xab, 0xcd, 0xef, 0xa0};
uint8_t encr[4] = {0xab, 0xab, 0xab, 0xab};
fieldset_add_bytes(fieldset,"encr",encr,8);
fieldset_add_bytes(fieldset,"id",remote_id,7);
fieldset_add_bin(fieldset,"s[2,1,0,3]",2,4);
fieldset_add_bin(fieldset,"low battery",0,1);
fieldset_add_bin(fieldset,"always one",1,1);
}
static void build_message(RawSamplesBuffer *samples, ProtoViewFieldSet *fieldset)
{
uint32_t te = 380; // Short pulse duration in microseconds.
// Sync: 12 pairs of pulse/gap + 9 times gap
for (int j = 0; j < 12; j++) {
raw_samples_add(samples,true,te);
raw_samples_add(samples,false,te);
}
raw_samples_add(samples,false,te*9);
// Data, 66 bits.
uint8_t data[9] = {0};
memcpy(data,fieldset->fields[0]->bytes,4); // Encrypted part.
memcpy(data+4,fieldset->fields[1]->bytes,4); // ID.
data[7] = data[7]>>4 | fieldset->fields[2]->uvalue << 4; // s[2,1,0,3]
int low_battery = fieldset->fields[3] != 0;
int always_one = fieldset->fields[4] != 0;
low_battery = !low_battery; // Bit real meaning is good battery level.
data[8] |= low_battery;
data[8] |= (always_one << 1);
bitmap_reverse_bytes_bits(data,sizeof(data)); /* Keeloq is LSB first. */
for (int j = 0; j < 66; j++) {
if (bitmap_get(data,9,j)) {
raw_samples_add(samples,true,te);
raw_samples_add(samples,false,te*2);
} else {
raw_samples_add(samples,true,te*2);
raw_samples_add(samples,false,te);
}
}
}
ProtoViewDecoder KeeloqDecoder = {
"Keeloq", decode
.name = "Keeloq",
.decode = decode,
.get_fields = get_fields,
.build_message = build_message
};