From bf62f66dc8bd37fc5887874bf994a84a4ef42eb0 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Thu, 24 Nov 2022 17:03:50 +0300 Subject: [PATCH] SubGHz: Fix keeloq, SL, counter going higher than 16bits Proper reset to 0 after we get to 0xFFFF --- lib/subghz/protocols/keeloq.c | 6 +++++- lib/subghz/protocols/star_line.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/subghz/protocols/keeloq.c b/lib/subghz/protocols/keeloq.c index 10993d706..46c86fee4 100644 --- a/lib/subghz/protocols/keeloq.c +++ b/lib/subghz/protocols/keeloq.c @@ -137,7 +137,11 @@ void subghz_protocol_encoder_keeloq_free(void* context) { * @param btn Button number, 4 bit */ static bool subghz_protocol_keeloq_gen_data(SubGhzProtocolEncoderKeeloq* instance, uint8_t btn) { - instance->generic.cnt++; + if(instance->generic.cnt < 0xFFFF) { + instance->generic.cnt++; + } else if(instance->generic.cnt >= 0xFFFF) { + instance->generic.cnt = 0; + } uint32_t fix = btn << 28 | instance->generic.serial; uint32_t decrypt = btn << 28 | (instance->generic.serial & 0x3FF) diff --git a/lib/subghz/protocols/star_line.c b/lib/subghz/protocols/star_line.c index 182aa2136..3066c6e2b 100644 --- a/lib/subghz/protocols/star_line.c +++ b/lib/subghz/protocols/star_line.c @@ -138,7 +138,11 @@ void subghz_protocol_encoder_star_line_free(void* context) { */ static bool subghz_protocol_star_line_gen_data(SubGhzProtocolEncoderStarLine* instance, uint8_t btn) { - instance->generic.cnt++; + if(instance->generic.cnt < 0xFFFF) { + instance->generic.cnt++; + } else if(instance->generic.cnt >= 0xFFFF) { + instance->generic.cnt = 0; + } uint32_t fix = btn << 24 | instance->generic.serial; uint32_t decrypt = btn << 24 | (instance->generic.serial & 0xFF) << 16 | instance->generic.cnt; uint32_t hop = 0;