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

Honda Car Keyfob #2767

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ See [CONTRIBUTING.md](./docs/CONTRIBUTING.md).
[249] Bresser lightning
[250] Schou 72543 Day Rain Gauge, Motonet MTX Rain, MarQuant Rain Gauge
[251] Fine Offset / Ecowitt WH55 water leak sensor
[252] Honda Keyfob KR5V2X/1X

* Disabled by default, use -R n or a conf file to enable

Expand All @@ -346,7 +347,7 @@ See [CONTRIBUTING.md](./docs/CONTRIBUTING.md).
[-d <RTL-SDR USB device index>] (default: 0)
[-d :<RTL-SDR USB device serial (can be set with rtl_eeprom -s)>]
To set gain for RTL-SDR use -g <gain> to set an overall gain in dB.
SoapySDR device driver is available.
SoapySDR device driver is not available.
[-d ""] Open default SoapySDR device
[-d driver=rtlsdr] Open e.g. specific SoapySDR device
To set gain for SoapySDR use -g ELEM=val,ELEM=val,... e.g. -g LNA=20,TIA=8,PGA=2 (for LimeSDR).
Expand Down
1 change: 1 addition & 0 deletions conf/rtl_433.example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ convert si
protocol 249 # Bresser lightning
protocol 250 # Schou 72543 Day Rain Gauge, Motonet MTX Rain, MarQuant Rain Gauge
protocol 251 # Fine Offset / Ecowitt WH55 water leak sensor
protocol 252 # Honda Keyfob KR5V2X/1X

## Flex devices (command line option "-X")

Expand Down
1 change: 1 addition & 0 deletions include/rtl_433_devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
DECL(bresser_lightning) \
DECL(schou_72543_rain) \
DECL(fineoffset_wh55) \
DECL(honda_keyfob) \

/* Add new decoders here. */

Expand Down
2 changes: 1 addition & 1 deletion man/man1/rtl_433.1
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ RTL\-SDR device driver is available.
To set gain for RTL\-SDR use \-g <gain> to set an overall gain in dB.
.RE
.RS
SoapySDR device driver is available.
SoapySDR device driver is not available.
.RE
.TP
[ \fB\-d\fI ""\fP ]
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ add_library(r_433 STATIC
devices/hcs200.c
devices/hideki.c
devices/holman_ws5029.c
devices/honda_kr5vxx.c
devices/hondaremote.c
devices/honeywell.c
devices/honeywell_cm921.c
Expand Down
120 changes: 120 additions & 0 deletions src/devices/honda_kr5vxx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/** @file
Honda Car Key FCCID KR5V2X and KR5V1X

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

*/

/**
Decoder for Honda Car Keyfob
FCCID KR5V2X
Frequency 433.66 MHz or 434.18 MHz

FCCID KR5V1X
Frequency 313.55 MHz or 314.15 MHz

Signal is 2FSK, 15 kHz deviation, datarate(baud) 16.66 kbps
Device uses Manchester encoded pulses of 60 us and 120 us
Data packets are usually 180 bits (with entire sync)
Data packet starts with sync of 0xFFFFFFFFFFF
Data layout after sync:
MMMMMM HH DDDDDDDD EE NNNNNN RRRRRRRR CC

- M: 24 bit Manufacturer ID
- H: 8 bit indicator of packet number (keyfob button press sends packet 2 times, receiver requires both packets. 0x08 is first packet, 0x0a is second packet)
- D: 32 bit Device ID of keyfob
- E: 8 bit Keyfob command (event)
- N: 24 bit counter
- R: 32 bit Rolling Code
- C: 8 bit CRC, OPENSAFETY poly 0x2f init 0x00

Flex decoder: rtl_433 -f 433657000 -R 0 -X 'n=honda,m=FSK_MC_ZEROBIT,s=60,l=120,r=75000,preamble={32}0xffffec0f'
*/



#include "decoder.h"

static int honda_decode(r_device *decoder, bitbuffer_t *bitbuffer){
if (bitbuffer->num_rows > 1){ return DECODE_ABORT_EARLY; } //should only be 1 row

if( bitbuffer->bits_per_row[0] < 150 || bitbuffer->bits_per_row[0] > 184 ){ return DECODE_ABORT_EARLY; }

uint16_t bit_offset;
uint8_t const preamble[] = {0xEC, 0x0F, 0x62}; //honda keyfob manufacture code
bit_offset = bitbuffer_search(bitbuffer, 0, 0, preamble, sizeof(preamble) * 8);
if( bit_offset >= bitbuffer->bits_per_row[0] ||
(bit_offset + 136) > bitbuffer->bits_per_row[0] ){ return DECODE_ABORT_EARLY; }


uint8_t b[16];
bitbuffer_extract_bytes( bitbuffer, 0, bit_offset + 16, b, 120); //extract 120 bits after sync, excluding first 2 bytes of manufacture code

char const *event = "Unknown";
int device_id = ((unsigned)b[2] << 24) | (b[3] << 16) | (b[4] << 8) | (b[5]);
int device_counter = (b[7] << 16) | (b[8] << 8) | (b[9]); //keyfob counter hex value
int rolling_code = ((unsigned)b[10] << 24) | (b[11] << 16) | (b[12] << 8) | (b[13]);

switch( b[6] ){
case 0x21:
event = "Lock";
break;
case 0x22:
event = "Unlock";
break;
case 0x24:
event = "Trunk";
break;
case 0x2d:
event = "RemoteStart";
break;
case 0x27:
event = "Emergency";
break;
}


int crc_value = crc8(b, 14, 0x2f, 0x00); //OPENSAFETY-CRC8
if( crc_value != (b[14])){
decoder_log(decoder, 1, __func__, "CRC error");
return DECODE_FAIL_MIC;
}

data_t *data = data_make(
"model", "model", DATA_STRING, "Honda Keyfob KR5V2X/1X",
"id", "Device ID", DATA_FORMAT, "%08x", DATA_INT, device_id,
"event", "Event", DATA_STRING, event,
"counter","Counter", DATA_FORMAT, "%06x", DATA_INT, device_counter,
"code", "Code", DATA_FORMAT, "%08x", DATA_INT, rolling_code,
"mic", "Integrity", DATA_STRING, "CRC",
NULL);

decoder_output_data(decoder, data);
return 1;
}


static char const *const output_fields[] = {
"model",
"id",
"event",
"counter",
"code",
"mic",
NULL,
};


r_device const honda_keyfob = {
.name = "Honda Keyfob KR5V2X/1X",
.modulation = FSK_PULSE_MANCHESTER_ZEROBIT,
.short_width = 60,
.long_width = 120,
.gap_limit = 1000, //this gap is kinda irrelevant
.reset_limit = 75000,
.decode_fn = &honda_decode,
.fields = output_fields,
};