From 8012f9cd44c8431da011f6431a7c5e46dc433a1e Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Fri, 12 May 2023 23:38:09 +0300 Subject: [PATCH 01/10] Fix offset in some files --- lib/subghz/protocols/keeloq.c | 483 ++++++++++++++++--------------- lib/subghz/protocols/star_line.c | 216 +++++++------- 2 files changed, 368 insertions(+), 331 deletions(-) diff --git a/lib/subghz/protocols/keeloq.c b/lib/subghz/protocols/keeloq.c index 4900e7e49..c9e603297 100644 --- a/lib/subghz/protocols/keeloq.c +++ b/lib/subghz/protocols/keeloq.c @@ -247,64 +247,69 @@ static bool subghz_protocol_keeloq_gen_data( } else if(strcmp(instance->manufacture_name, "HCS101") == 0) { hop = instance->generic.cnt << 16 | (btn & 0xF) << 12 | 0x000; } else { - for - M_EACH(manufacture_code, *subghz_keystore_get_data(instance->keystore), SubGhzKeyArray_t) { - res = strcmp(furi_string_get_cstr(manufacture_code->name), instance->manufacture_name); - if(res == 0) { - switch(manufacture_code->type) { - case KEELOQ_LEARNING_SIMPLE: - //Simple Learning - hop = subghz_protocol_keeloq_common_encrypt(decrypt, manufacture_code->key); - break; - case KEELOQ_LEARNING_NORMAL: - //Simple Learning - man = - subghz_protocol_keeloq_common_normal_learning(fix, manufacture_code->key); - hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); - break; - case KEELOQ_LEARNING_SECURE: - //Secure Learning - man = subghz_protocol_keeloq_common_secure_learning( - fix, instance->generic.seed, manufacture_code->key); - hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); - break; - case KEELOQ_LEARNING_MAGIC_XOR_TYPE_1: - //Magic XOR type-1 Learning - man = subghz_protocol_keeloq_common_magic_xor_type1_learning( - instance->generic.serial, manufacture_code->key); - hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); - break; - case KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_1: - //Magic Serial Type 1 learning - man = subghz_protocol_keeloq_common_magic_serial_type1_learning( - fix, manufacture_code->key); - hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); - break; - case KEELOQ_LEARNING_UNKNOWN: - if(kl_type == 1) { - hop = - subghz_protocol_keeloq_common_encrypt(decrypt, manufacture_code->key); + for + M_EACH( + manufacture_code, + *subghz_keystore_get_data(instance->keystore), + SubGhzKeyArray_t) { + res = strcmp( + furi_string_get_cstr(manufacture_code->name), instance->manufacture_name); + if(res == 0) { + switch(manufacture_code->type) { + case KEELOQ_LEARNING_SIMPLE: + //Simple Learning + hop = subghz_protocol_keeloq_common_encrypt( + decrypt, manufacture_code->key); + break; + case KEELOQ_LEARNING_NORMAL: + //Simple Learning + man = subghz_protocol_keeloq_common_normal_learning( + fix, manufacture_code->key); + hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); + break; + case KEELOQ_LEARNING_SECURE: + //Secure Learning + man = subghz_protocol_keeloq_common_secure_learning( + fix, instance->generic.seed, manufacture_code->key); + hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); + break; + case KEELOQ_LEARNING_MAGIC_XOR_TYPE_1: + //Magic XOR type-1 Learning + man = subghz_protocol_keeloq_common_magic_xor_type1_learning( + instance->generic.serial, manufacture_code->key); + hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); + break; + case KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_1: + //Magic Serial Type 1 learning + man = subghz_protocol_keeloq_common_magic_serial_type1_learning( + fix, manufacture_code->key); + hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); + break; + case KEELOQ_LEARNING_UNKNOWN: + if(kl_type == 1) { + hop = subghz_protocol_keeloq_common_encrypt( + decrypt, manufacture_code->key); + } + if(kl_type == 2) { + man = subghz_protocol_keeloq_common_normal_learning( + fix, manufacture_code->key); + hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); + } + if(kl_type == 3) { + man = subghz_protocol_keeloq_common_secure_learning( + fix, instance->generic.seed, manufacture_code->key); + hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); + } + if(kl_type == 4) { + man = subghz_protocol_keeloq_common_magic_xor_type1_learning( + instance->generic.serial, manufacture_code->key); + hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); + } + break; + } + break; } - if(kl_type == 2) { - man = subghz_protocol_keeloq_common_normal_learning( - fix, manufacture_code->key); - hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); - } - if(kl_type == 3) { - man = subghz_protocol_keeloq_common_secure_learning( - fix, instance->generic.seed, manufacture_code->key); - hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); - } - if(kl_type == 4) { - man = subghz_protocol_keeloq_common_magic_xor_type1_learning( - instance->generic.serial, manufacture_code->key); - hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); - } - break; } - break; - } - } } } if(hop) { @@ -835,179 +840,8 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( } if(strcmp(mfname, "") == 0) { - for - M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) { - switch(manufacture_code->type) { - case KEELOQ_LEARNING_SIMPLE: - // Simple Learning - decrypt = subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } - break; - case KEELOQ_LEARNING_NORMAL: - // Normal Learning - // https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37 - man = subghz_protocol_keeloq_common_normal_learning(fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } - break; - case KEELOQ_LEARNING_SECURE: - man = subghz_protocol_keeloq_common_secure_learning( - fix, instance->seed, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } - break; - case KEELOQ_LEARNING_MAGIC_XOR_TYPE_1: - man = subghz_protocol_keeloq_common_magic_xor_type1_learning( - fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } - break; - case KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_1: - man = subghz_protocol_keeloq_common_magic_serial_type1_learning( - fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } - break; - case KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_2: - man = subghz_protocol_keeloq_common_magic_serial_type2_learning( - fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } - break; - case KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_3: - man = subghz_protocol_keeloq_common_magic_serial_type3_learning( - fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } - break; - case KEELOQ_LEARNING_UNKNOWN: - // Simple Learning - decrypt = subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 1; - return 1; - } - - // Check for mirrored man - uint64_t man_rev = 0; - uint64_t man_rev_byte = 0; - for(uint8_t i = 0; i < 64; i += 8) { - man_rev_byte = (uint8_t)(manufacture_code->key >> i); - man_rev = man_rev | man_rev_byte << (56 - i); - } - - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man_rev); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 1; - return 1; - } - - //########################### - // Normal Learning - // https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37 - man = subghz_protocol_keeloq_common_normal_learning(fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 2; - return 1; - } - - // Check for mirrored man - man = subghz_protocol_keeloq_common_normal_learning(fix, man_rev); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 2; - return 1; - } - - // Secure Learning - man = subghz_protocol_keeloq_common_secure_learning( - fix, instance->seed, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 3; - return 1; - } - - // Check for mirrored man - man = subghz_protocol_keeloq_common_secure_learning(fix, instance->seed, man_rev); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 3; - return 1; - } - - // Magic xor type1 learning - man = subghz_protocol_keeloq_common_magic_xor_type1_learning( - fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 4; - return 1; - } - - // Check for mirrored man - man = subghz_protocol_keeloq_common_magic_xor_type1_learning(fix, man_rev); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 4; - return 1; - } - - break; - } - } - } else if(strcmp(mfname, "Unknown") == 0) { - return 1; - } else { - for - M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) { - res = strcmp(furi_string_get_cstr(manufacture_code->name), mfname); - if(res == 0) { + for + M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) { switch(manufacture_code->type) { case KEELOQ_LEARNING_SIMPLE: // Simple Learning @@ -1060,6 +894,26 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( return 1; } break; + case KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_2: + man = subghz_protocol_keeloq_common_magic_serial_type2_learning( + fix, manufacture_code->key); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); + if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + return 1; + } + break; + case KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_3: + man = subghz_protocol_keeloq_common_magic_serial_type3_learning( + fix, manufacture_code->key); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); + if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + return 1; + } + break; case KEELOQ_LEARNING_UNKNOWN: // Simple Learning decrypt = subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key); @@ -1069,6 +923,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( kl_type = 1; return 1; } + // Check for mirrored man uint64_t man_rev = 0; uint64_t man_rev_byte = 0; @@ -1076,6 +931,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( man_rev_byte = (uint8_t)(manufacture_code->key >> i); man_rev = man_rev | man_rev_byte << (56 - i); } + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man_rev); if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { *manufacture_name = furi_string_get_cstr(manufacture_code->name); @@ -1083,6 +939,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( kl_type = 1; return 1; } + //########################### // Normal Learning // https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37 @@ -1152,7 +1009,173 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( break; } } - } + } else if(strcmp(mfname, "Unknown") == 0) { + return 1; + } else { + for + M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) { + res = strcmp(furi_string_get_cstr(manufacture_code->name), mfname); + if(res == 0) { + switch(manufacture_code->type) { + case KEELOQ_LEARNING_SIMPLE: + // Simple Learning + decrypt = + subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key); + if(subghz_protocol_keeloq_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + return 1; + } + break; + case KEELOQ_LEARNING_NORMAL: + // Normal Learning + // https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37 + man = subghz_protocol_keeloq_common_normal_learning( + fix, manufacture_code->key); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); + if(subghz_protocol_keeloq_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + return 1; + } + break; + case KEELOQ_LEARNING_SECURE: + man = subghz_protocol_keeloq_common_secure_learning( + fix, instance->seed, manufacture_code->key); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); + if(subghz_protocol_keeloq_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + return 1; + } + break; + case KEELOQ_LEARNING_MAGIC_XOR_TYPE_1: + man = subghz_protocol_keeloq_common_magic_xor_type1_learning( + fix, manufacture_code->key); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); + if(subghz_protocol_keeloq_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + return 1; + } + break; + case KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_1: + man = subghz_protocol_keeloq_common_magic_serial_type1_learning( + fix, manufacture_code->key); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); + if(subghz_protocol_keeloq_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + return 1; + } + break; + case KEELOQ_LEARNING_UNKNOWN: + // Simple Learning + decrypt = + subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key); + if(subghz_protocol_keeloq_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + kl_type = 1; + return 1; + } + // Check for mirrored man + uint64_t man_rev = 0; + uint64_t man_rev_byte = 0; + for(uint8_t i = 0; i < 64; i += 8) { + man_rev_byte = (uint8_t)(manufacture_code->key >> i); + man_rev = man_rev | man_rev_byte << (56 - i); + } + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man_rev); + if(subghz_protocol_keeloq_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + kl_type = 1; + return 1; + } + //########################### + // Normal Learning + // https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37 + man = subghz_protocol_keeloq_common_normal_learning( + fix, manufacture_code->key); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); + if(subghz_protocol_keeloq_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + kl_type = 2; + return 1; + } + + // Check for mirrored man + man = subghz_protocol_keeloq_common_normal_learning(fix, man_rev); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); + if(subghz_protocol_keeloq_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + kl_type = 2; + return 1; + } + + // Secure Learning + man = subghz_protocol_keeloq_common_secure_learning( + fix, instance->seed, manufacture_code->key); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); + if(subghz_protocol_keeloq_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + kl_type = 3; + return 1; + } + + // Check for mirrored man + man = subghz_protocol_keeloq_common_secure_learning( + fix, instance->seed, man_rev); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); + if(subghz_protocol_keeloq_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + kl_type = 3; + return 1; + } + + // Magic xor type1 learning + man = subghz_protocol_keeloq_common_magic_xor_type1_learning( + fix, manufacture_code->key); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); + if(subghz_protocol_keeloq_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + kl_type = 4; + return 1; + } + + // Check for mirrored man + man = subghz_protocol_keeloq_common_magic_xor_type1_learning(fix, man_rev); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); + if(subghz_protocol_keeloq_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + kl_type = 4; + return 1; + } + + break; + } + } + } } *manufacture_name = "Unknown"; diff --git a/lib/subghz/protocols/star_line.c b/lib/subghz/protocols/star_line.c index cb9b26760..792622412 100644 --- a/lib/subghz/protocols/star_line.c +++ b/lib/subghz/protocols/star_line.c @@ -163,36 +163,41 @@ static bool instance->generic.data, instance->generic.data_count_bit); hop = code_found_reverse & 0x00000000ffffffff; } else { - for - M_EACH(manufacture_code, *subghz_keystore_get_data(instance->keystore), SubGhzKeyArray_t) { - res = strcmp(furi_string_get_cstr(manufacture_code->name), instance->manufacture_name); - if(res == 0) { - switch(manufacture_code->type) { - case KEELOQ_LEARNING_SIMPLE: - //Simple Learning - hop = subghz_protocol_keeloq_common_encrypt(decrypt, manufacture_code->key); - break; - case KEELOQ_LEARNING_NORMAL: - //Normal Learning - man = - subghz_protocol_keeloq_common_normal_learning(fix, manufacture_code->key); - hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); - break; - case KEELOQ_LEARNING_UNKNOWN: - if(kl_type == 1) { + for + M_EACH( + manufacture_code, + *subghz_keystore_get_data(instance->keystore), + SubGhzKeyArray_t) { + res = strcmp( + furi_string_get_cstr(manufacture_code->name), instance->manufacture_name); + if(res == 0) { + switch(manufacture_code->type) { + case KEELOQ_LEARNING_SIMPLE: + //Simple Learning hop = subghz_protocol_keeloq_common_encrypt(decrypt, manufacture_code->key); - } - if(kl_type == 2) { + break; + case KEELOQ_LEARNING_NORMAL: + //Normal Learning man = subghz_protocol_keeloq_common_normal_learning( fix, manufacture_code->key); hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); + break; + case KEELOQ_LEARNING_UNKNOWN: + if(kl_type == 1) { + hop = subghz_protocol_keeloq_common_encrypt( + decrypt, manufacture_code->key); + } + if(kl_type == 2) { + man = subghz_protocol_keeloq_common_normal_learning( + fix, manufacture_code->key); + hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); + } + break; } break; } - break; } - } } if(hop) { uint64_t yek = (uint64_t)fix << 32 | hop; @@ -523,84 +528,8 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( } if(strcmp(mfname, "") == 0) { - for - M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) { - switch(manufacture_code->type) { - case KEELOQ_LEARNING_SIMPLE: - // Simple Learning - decrypt = subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key); - if(subghz_protocol_star_line_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } - break; - case KEELOQ_LEARNING_NORMAL: - // Normal Learning - // https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37 - man_normal_learning = - subghz_protocol_keeloq_common_normal_learning(fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man_normal_learning); - if(subghz_protocol_star_line_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } - break; - case KEELOQ_LEARNING_UNKNOWN: - // Simple Learning - decrypt = subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key); - if(subghz_protocol_star_line_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 1; - return 1; - } - // Check for mirrored man - uint64_t man_rev = 0; - uint64_t man_rev_byte = 0; - for(uint8_t i = 0; i < 64; i += 8) { - man_rev_byte = (uint8_t)(manufacture_code->key >> i); - man_rev = man_rev | man_rev_byte << (56 - i); - } - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man_rev); - if(subghz_protocol_star_line_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 1; - return 1; - } - //########################### - // Normal Learning - // https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37 - man_normal_learning = - subghz_protocol_keeloq_common_normal_learning(fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man_normal_learning); - if(subghz_protocol_star_line_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 2; - return 1; - } - // Check for mirrored man - man_normal_learning = subghz_protocol_keeloq_common_normal_learning(fix, man_rev); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man_normal_learning); - if(subghz_protocol_star_line_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 2; - return 1; - } - break; - } - } - } else if(strcmp(mfname, "Unknown") == 0) { - return 1; - } else { - for - M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) { - res = strcmp(furi_string_get_cstr(manufacture_code->name), mfname); - if(res == 0) { + for + M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) { switch(manufacture_code->type) { case KEELOQ_LEARNING_SIMPLE: // Simple Learning @@ -663,7 +592,6 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( kl_type = 2; return 1; } - // Check for mirrored man man_normal_learning = subghz_protocol_keeloq_common_normal_learning(fix, man_rev); @@ -678,7 +606,93 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( break; } } - } + } else if(strcmp(mfname, "Unknown") == 0) { + return 1; + } else { + for + M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) { + res = strcmp(furi_string_get_cstr(manufacture_code->name), mfname); + if(res == 0) { + switch(manufacture_code->type) { + case KEELOQ_LEARNING_SIMPLE: + // Simple Learning + decrypt = + subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key); + if(subghz_protocol_star_line_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + return 1; + } + break; + case KEELOQ_LEARNING_NORMAL: + // Normal Learning + // https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37 + man_normal_learning = subghz_protocol_keeloq_common_normal_learning( + fix, manufacture_code->key); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man_normal_learning); + if(subghz_protocol_star_line_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + return 1; + } + break; + case KEELOQ_LEARNING_UNKNOWN: + // Simple Learning + decrypt = + subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key); + if(subghz_protocol_star_line_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + kl_type = 1; + return 1; + } + // Check for mirrored man + uint64_t man_rev = 0; + uint64_t man_rev_byte = 0; + for(uint8_t i = 0; i < 64; i += 8) { + man_rev_byte = (uint8_t)(manufacture_code->key >> i); + man_rev = man_rev | man_rev_byte << (56 - i); + } + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man_rev); + if(subghz_protocol_star_line_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + kl_type = 1; + return 1; + } + //########################### + // Normal Learning + // https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37 + man_normal_learning = subghz_protocol_keeloq_common_normal_learning( + fix, manufacture_code->key); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man_normal_learning); + if(subghz_protocol_star_line_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + kl_type = 2; + return 1; + } + + // Check for mirrored man + man_normal_learning = + subghz_protocol_keeloq_common_normal_learning(fix, man_rev); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man_normal_learning); + if(subghz_protocol_star_line_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + kl_type = 2; + return 1; + } + break; + } + } + } } *manufacture_name = "Unknown"; From c0a26cf1eb0d8aa143798543f43e8eeef62978b4 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 13 May 2023 14:43:11 +0300 Subject: [PATCH 02/10] SubGhz custom btn improved code readability some "if" optimization --- .../subghz/scenes/subghz_scene_transmitter.c | 4 +-- applications/main/subghz/views/transmitter.c | 18 +++++------ .../main/subghz_remote/subghz_remote_app.c | 2 +- lib/subghz/blocks/custom_btn.c | 14 ++++----- lib/subghz/blocks/custom_btn.h | 11 +++++-- lib/subghz/protocols/alutech_at_4n.c | 28 ++++++++--------- lib/subghz/protocols/keeloq.c | 31 +++++++++---------- lib/subghz/protocols/nice_flor_s.c | 24 +++++++------- lib/subghz/protocols/secplus_v2.c | 24 +++++++------- lib/subghz/protocols/somfy_telis.c | 24 +++++++------- 10 files changed, 90 insertions(+), 90 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index b07785c06..15a53603d 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -76,8 +76,8 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { } else if(event.event == SubGhzCustomEventViewTransmitterSendStop) { subghz->state_notifications = SubGhzNotificationStateIDLE; subghz_txrx_stop(subghz->txrx); - if(subghz_custom_btn_get() != 0) { - subghz_custom_btn_set(0); + if(subghz_custom_btn_get() != SUBGHZ_CUSTOM_BTN_OK) { + subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_OK); uint8_t tmp_counter = furi_hal_subghz_get_rolling_counter_mult(); furi_hal_subghz_set_rolling_counter_mult(0); // Calling restore! diff --git a/applications/main/subghz/views/transmitter.c b/applications/main/subghz/views/transmitter.c index 5ae1a6e2c..ad2b3efd7 100644 --- a/applications/main/subghz/views/transmitter.c +++ b/applications/main/subghz/views/transmitter.c @@ -137,7 +137,7 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { true); if(can_be_sent && event->key == InputKeyOk && event->type == InputTypePress) { - subghz_custom_btn_set(0); + subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_OK); with_view_model( subghz_transmitter->view, SubGhzViewTransmitterModel * model, @@ -157,14 +157,14 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { // Temp Buttons (UP) if(can_be_sent && event->key == InputKeyUp && event->type == InputTypePress) { - subghz_custom_btn_set(1); + subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_UP); with_view_model( subghz_transmitter->view, SubGhzViewTransmitterModel * model, { furi_string_reset(model->temp_button_id); if(subghz_custom_btn_get_original() != 0) { - if(subghz_custom_btn_get() == 1) { + if(subghz_custom_btn_get() == SUBGHZ_CUSTOM_BTN_UP) { furi_string_printf( model->temp_button_id, "%01X", subghz_custom_btn_get_original()); model->draw_temp_button = true; @@ -182,14 +182,14 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { } // Down if(can_be_sent && event->key == InputKeyDown && event->type == InputTypePress) { - subghz_custom_btn_set(2); + subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_DOWN); with_view_model( subghz_transmitter->view, SubGhzViewTransmitterModel * model, { furi_string_reset(model->temp_button_id); if(subghz_custom_btn_get_original() != 0) { - if(subghz_custom_btn_get() == 2) { + if(subghz_custom_btn_get() == SUBGHZ_CUSTOM_BTN_DOWN) { furi_string_printf( model->temp_button_id, "%01X", subghz_custom_btn_get_original()); model->draw_temp_button = true; @@ -207,14 +207,14 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { } // Left if(can_be_sent && event->key == InputKeyLeft && event->type == InputTypePress) { - subghz_custom_btn_set(3); + subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_LEFT); with_view_model( subghz_transmitter->view, SubGhzViewTransmitterModel * model, { furi_string_reset(model->temp_button_id); if(subghz_custom_btn_get_original() != 0) { - if(subghz_custom_btn_get() == 3) { + if(subghz_custom_btn_get() == SUBGHZ_CUSTOM_BTN_LEFT) { furi_string_printf( model->temp_button_id, "%01X", subghz_custom_btn_get_original()); model->draw_temp_button = true; @@ -232,14 +232,14 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { } // Right if(can_be_sent && event->key == InputKeyRight && event->type == InputTypePress) { - subghz_custom_btn_set(4); + subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_RIGHT); with_view_model( subghz_transmitter->view, SubGhzViewTransmitterModel * model, { furi_string_reset(model->temp_button_id); if(subghz_custom_btn_get_original() != 0) { - if(subghz_custom_btn_get() == 4) { + if(subghz_custom_btn_get() == SUBGHZ_CUSTOM_BTN_RIGHT) { furi_string_printf( model->temp_button_id, "%01X", subghz_custom_btn_get_original()); model->draw_temp_button = true; diff --git a/applications/main/subghz_remote/subghz_remote_app.c b/applications/main/subghz_remote/subghz_remote_app.c index d215a1d0e..dd23533cc 100644 --- a/applications/main/subghz_remote/subghz_remote_app.c +++ b/applications/main/subghz_remote/subghz_remote_app.c @@ -354,7 +354,7 @@ bool subghz_remote_key_load( bool res = false; - subghz_custom_btn_set(0); + subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_OK); keeloq_reset_original_btn(); subghz_custom_btns_reset(); diff --git a/lib/subghz/blocks/custom_btn.c b/lib/subghz/blocks/custom_btn.c index 3023e09ea..158c10a2f 100644 --- a/lib/subghz/blocks/custom_btn.c +++ b/lib/subghz/blocks/custom_btn.c @@ -1,14 +1,14 @@ #include "custom_btn.h" -static uint8_t custom_btn_id = 0; +static uint8_t custom_btn_id = SUBGHZ_CUSTOM_BTN_OK; static uint8_t custom_btn_original = 0; static uint8_t custom_btn_max_btns = 0; -void subghz_custom_btn_set(uint8_t b) { - if(b > custom_btn_max_btns) { - custom_btn_id = 0; +void subghz_custom_btn_set(uint8_t btn_id) { + if(btn_id > custom_btn_max_btns) { + custom_btn_id = SUBGHZ_CUSTOM_BTN_OK; } else { - custom_btn_id = b; + custom_btn_id = btn_id; } } @@ -16,8 +16,8 @@ uint8_t subghz_custom_btn_get() { return custom_btn_id; } -void subghz_custom_btn_set_original(uint8_t b) { - custom_btn_original = b; +void subghz_custom_btn_set_original(uint8_t btn_code) { + custom_btn_original = btn_code; } uint8_t subghz_custom_btn_get_original() { diff --git a/lib/subghz/blocks/custom_btn.h b/lib/subghz/blocks/custom_btn.h index 0ea5ee654..a92567321 100644 --- a/lib/subghz/blocks/custom_btn.h +++ b/lib/subghz/blocks/custom_btn.h @@ -4,11 +4,18 @@ #include #include -void subghz_custom_btn_set(uint8_t b); +// Default btn ID +#define SUBGHZ_CUSTOM_BTN_OK (0U) +#define SUBGHZ_CUSTOM_BTN_UP (1U) +#define SUBGHZ_CUSTOM_BTN_DOWN (2U) +#define SUBGHZ_CUSTOM_BTN_LEFT (3U) +#define SUBGHZ_CUSTOM_BTN_RIGHT (4U) + +void subghz_custom_btn_set(uint8_t btn_id); uint8_t subghz_custom_btn_get(); -void subghz_custom_btn_set_original(uint8_t b); +void subghz_custom_btn_set_original(uint8_t btn_code); uint8_t subghz_custom_btn_get_original(); diff --git a/lib/subghz/protocols/alutech_at_4n.c b/lib/subghz/protocols/alutech_at_4n.c index 47cf37d6b..6733613c4 100644 --- a/lib/subghz/protocols/alutech_at_4n.c +++ b/lib/subghz/protocols/alutech_at_4n.c @@ -334,11 +334,15 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload( } uint8_t custom_btn_id = subghz_custom_btn_get(); - uint8_t original_btn_num = subghz_custom_btn_get_original(); + uint8_t original_btn_code = subghz_custom_btn_get_original(); // Set custom button - if(custom_btn_id == 1) { - switch(original_btn_num) { + // Basic set | 0x11 | 0x22 | 0xFF | 0x44 | 0x33 | + if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) { + // Restore original button code + btn = original_btn_code; + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) { + switch(original_btn_code) { case 0x11: btn = 0x22; break; @@ -358,9 +362,8 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload( default: break; } - } - if(custom_btn_id == 2) { - switch(original_btn_num) { + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) { + switch(original_btn_code) { case 0x11: btn = 0x44; break; @@ -380,9 +383,8 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload( default: break; } - } - if(custom_btn_id == 3) { - switch(original_btn_num) { + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) { + switch(original_btn_code) { case 0x11: btn = 0x33; break; @@ -402,9 +404,8 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload( default: break; } - } - if(custom_btn_id == 4) { - switch(original_btn_num) { + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_RIGHT) { + switch(original_btn_code) { case 0x11: btn = 0xFF; break; @@ -426,9 +427,6 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload( } } - if((custom_btn_id == 0) && (original_btn_num != 0)) { - btn = original_btn_num; - } // Gen new key if(!subghz_protocol_alutech_at_4n_gen_data(instance, btn)) { return false; diff --git a/lib/subghz/protocols/keeloq.c b/lib/subghz/protocols/keeloq.c index c9e603297..37e8c30e1 100644 --- a/lib/subghz/protocols/keeloq.c +++ b/lib/subghz/protocols/keeloq.c @@ -397,10 +397,15 @@ static bool } uint8_t custom_btn_id = subghz_custom_btn_get(); - uint8_t original_btn_num = subghz_custom_btn_get_original(); + uint8_t original_btn_code = subghz_custom_btn_get_original(); + // Set custom button - if(custom_btn_id == 1) { - switch(original_btn_num) { + // Basic set | 0x1 | 0x2 | 0x4 | 0x8 | 0xA or Special Learning Code | + if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) { + // Restore original button code + btn = original_btn_code; + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) { + switch(original_btn_code) { case 0x1: btn = 0x2; break; @@ -424,9 +429,8 @@ static bool btn = 0x1; break; } - } - if(custom_btn_id == 2) { - switch(original_btn_num) { + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) { + switch(original_btn_code) { case 0x1: btn = 0x4; break; @@ -450,9 +454,8 @@ static bool btn = 0x4; break; } - } - if(custom_btn_id == 3) { - switch(original_btn_num) { + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) { + switch(original_btn_code) { case 0x1: btn = 0x8; break; @@ -476,9 +479,8 @@ static bool btn = 0x8; break; } - } - if(custom_btn_id == 4) { - switch(original_btn_num) { + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_RIGHT) { + switch(original_btn_code) { case 0x1: btn = klq_last_custom_btn; break; @@ -503,11 +505,8 @@ static bool break; } } - if((custom_btn_id == 0) && (original_btn_num != 0)) { - btn = original_btn_num; - } + // Generate new key - if(subghz_protocol_keeloq_gen_data(instance, btn, true)) { // OK } else { diff --git a/lib/subghz/protocols/nice_flor_s.c b/lib/subghz/protocols/nice_flor_s.c index 5d8e7f587..f337ca105 100644 --- a/lib/subghz/protocols/nice_flor_s.c +++ b/lib/subghz/protocols/nice_flor_s.c @@ -136,11 +136,15 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload( } uint8_t custom_btn_id = subghz_custom_btn_get(); - uint8_t original_btn_num = subghz_custom_btn_get_original(); + uint8_t original_btn_code = subghz_custom_btn_get_original(); // Set custom button - if(custom_btn_id == 1) { - switch(original_btn_num) { + // Basic set | 0x1 | 0x2 | 0x4 | 0x8 | + if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) { + // Restore original button code + btn = original_btn_code; + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) { + switch(original_btn_code) { case 0x1: btn = 0x2; break; @@ -157,9 +161,8 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload( default: break; } - } - if(custom_btn_id == 2) { - switch(original_btn_num) { + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) { + switch(original_btn_code) { case 0x1: btn = 0x4; break; @@ -176,9 +179,8 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload( default: break; } - } - if(custom_btn_id == 3) { - switch(original_btn_num) { + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) { + switch(original_btn_code) { case 0x1: btn = 0x8; break; @@ -197,10 +199,6 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload( } } - if((custom_btn_id == 0) && (original_btn_num != 0)) { - btn = original_btn_num; - } - size_t size_upload = ((instance->generic.data_count_bit * 2) + ((37 + 2 + 2) * 2) * 16); if(size_upload > instance->encoder.size_upload) { FURI_LOG_E(TAG, "Size upload exceeds allocated encoder buffer."); diff --git a/lib/subghz/protocols/secplus_v2.c b/lib/subghz/protocols/secplus_v2.c index 5d0ecb0dd..97631ce34 100644 --- a/lib/subghz/protocols/secplus_v2.c +++ b/lib/subghz/protocols/secplus_v2.c @@ -387,11 +387,15 @@ static void subghz_protocol_secplus_v2_encode(SubGhzProtocolEncoderSecPlus_v2* i } uint8_t custom_btn_id = subghz_custom_btn_get(); - uint8_t original_btn_num = subghz_custom_btn_get_original(); + uint8_t original_btn_code = subghz_custom_btn_get_original(); // Set custom button - if(custom_btn_id == 1) { - switch(original_btn_num) { + // Basic set | 0x68 | 0x80 | 0x81 | 0xE2 | + if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) { + // Restore original button code + instance->generic.btn = original_btn_code; + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) { + switch(original_btn_code) { case 0x68: instance->generic.btn = 0x80; break; @@ -408,9 +412,8 @@ static void subghz_protocol_secplus_v2_encode(SubGhzProtocolEncoderSecPlus_v2* i default: break; } - } - if(custom_btn_id == 2) { - switch(original_btn_num) { + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) { + switch(original_btn_code) { case 0x68: instance->generic.btn = 0x81; break; @@ -427,9 +430,8 @@ static void subghz_protocol_secplus_v2_encode(SubGhzProtocolEncoderSecPlus_v2* i default: break; } - } - if(custom_btn_id == 3) { - switch(original_btn_num) { + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) { + switch(original_btn_code) { case 0x68: instance->generic.btn = 0xE2; break; @@ -447,9 +449,7 @@ static void subghz_protocol_secplus_v2_encode(SubGhzProtocolEncoderSecPlus_v2* i break; } } - if((custom_btn_id == 0) && (original_btn_num != 0)) { - instance->generic.btn = original_btn_num; - } + uint32_t fixed_1[1] = {instance->generic.btn << 12 | instance->generic.serial >> 20}; uint32_t fixed_2[1] = {instance->generic.serial & 0xFFFFF}; uint8_t rolling_digits[18] = {0}; diff --git a/lib/subghz/protocols/somfy_telis.c b/lib/subghz/protocols/somfy_telis.c index 57c6c510b..fc4034d1f 100644 --- a/lib/subghz/protocols/somfy_telis.c +++ b/lib/subghz/protocols/somfy_telis.c @@ -116,11 +116,15 @@ static bool subghz_protocol_somfy_telis_gen_data( } uint8_t custom_btn_id = subghz_custom_btn_get(); - uint8_t original_btn_num = subghz_custom_btn_get_original(); + uint8_t original_btn_code = subghz_custom_btn_get_original(); // Set custom button - if(custom_btn_id == 1) { - switch(original_btn_num) { + // Basic set | 0x1 | 0x2 | 0x4 | 0x8 | + if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) { + // Restore original button code + btn = original_btn_code; + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) { + switch(original_btn_code) { case 0x1: btn = 0x2; break; @@ -137,9 +141,8 @@ static bool subghz_protocol_somfy_telis_gen_data( default: break; } - } - if(custom_btn_id == 2) { - switch(original_btn_num) { + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) { + switch(original_btn_code) { case 0x1: btn = 0x4; break; @@ -156,9 +159,8 @@ static bool subghz_protocol_somfy_telis_gen_data( default: break; } - } - if(custom_btn_id == 3) { - switch(original_btn_num) { + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) { + switch(original_btn_code) { case 0x1: btn = 0x8; break; @@ -177,10 +179,6 @@ static bool subghz_protocol_somfy_telis_gen_data( } } - if((custom_btn_id == 0) && (original_btn_num != 0)) { - btn = original_btn_num; - } - if(instance->generic.cnt < 0xFFFF) { if((instance->generic.cnt + furi_hal_subghz_get_rolling_counter_mult()) >= 0xFFFF) { instance->generic.cnt = 0; From 23a24c42c10712f0a97da3c7a66c68570b335294 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 13 May 2023 16:48:51 +0300 Subject: [PATCH 03/10] SubGhz: Fix add manual Alutech AT 4N --- lib/subghz/protocols/alutech_at_4n.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/subghz/protocols/alutech_at_4n.c b/lib/subghz/protocols/alutech_at_4n.c index 6733613c4..83d98b7aa 100644 --- a/lib/subghz/protocols/alutech_at_4n.c +++ b/lib/subghz/protocols/alutech_at_4n.c @@ -308,8 +308,8 @@ bool subghz_protocol_alutech_at_4n_create_data( instance->generic.data_count_bit = 72; bool res = subghz_protocol_alutech_at_4n_gen_data(instance, btn); if(res) { - res = subghz_block_generic_serialize(&instance->generic, flipper_format, preset); - if((res == SubGhzProtocolStatusOk) && + if((subghz_block_generic_serialize(&instance->generic, flipper_format, preset) != + SubGhzProtocolStatusOk) || !flipper_format_write_uint32(flipper_format, "CRC", &instance->crc, 1)) { FURI_LOG_E(TAG, "Unable to add CRC"); res = false; From a74461d903c7bfa9cc2db0c792a70cc0c3ebe4e1 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 13 May 2023 16:55:35 +0300 Subject: [PATCH 04/10] Removed duplicate code in transmitter.c --- applications/main/subghz/views/transmitter.c | 174 ++++++------------- 1 file changed, 57 insertions(+), 117 deletions(-) diff --git a/applications/main/subghz/views/transmitter.c b/applications/main/subghz/views/transmitter.c index ad2b3efd7..08db03334 100644 --- a/applications/main/subghz/views/transmitter.c +++ b/applications/main/subghz/views/transmitter.c @@ -124,7 +124,7 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { }, false); return false; - } + } // Finish "Back" key processing with_view_model( subghz_transmitter->view, @@ -136,124 +136,64 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { }, true); - if(can_be_sent && event->key == InputKeyOk && event->type == InputTypePress) { - subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_OK); - with_view_model( - subghz_transmitter->view, - SubGhzViewTransmitterModel * model, - { - furi_string_reset(model->temp_button_id); - model->draw_temp_button = false; - }, - true); - subghz_transmitter->callback( - SubGhzCustomEventViewTransmitterSendStart, subghz_transmitter->context); - return true; - } else if(can_be_sent && event->key == InputKeyOk && event->type == InputTypeRelease) { - subghz_transmitter->callback( - SubGhzCustomEventViewTransmitterSendStop, subghz_transmitter->context); - return true; - } + if(can_be_sent) { + if(event->key == InputKeyOk && event->type == InputTypePress) { + subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_OK); + with_view_model( + subghz_transmitter->view, + SubGhzViewTransmitterModel * model, + { + furi_string_reset(model->temp_button_id); + model->draw_temp_button = false; + }, + true); + subghz_transmitter->callback( + SubGhzCustomEventViewTransmitterSendStart, subghz_transmitter->context); + return true; + } else if(event->key == InputKeyOk && event->type == InputTypeRelease) { + subghz_transmitter->callback( + SubGhzCustomEventViewTransmitterSendStop, subghz_transmitter->context); + return true; + } // Finish "OK" key processing - // Temp Buttons (UP) - if(can_be_sent && event->key == InputKeyUp && event->type == InputTypePress) { - subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_UP); - with_view_model( - subghz_transmitter->view, - SubGhzViewTransmitterModel * model, - { - furi_string_reset(model->temp_button_id); - if(subghz_custom_btn_get_original() != 0) { - if(subghz_custom_btn_get() == SUBGHZ_CUSTOM_BTN_UP) { - furi_string_printf( - model->temp_button_id, "%01X", subghz_custom_btn_get_original()); - model->draw_temp_button = true; + uint8_t temp_btn_id; + if(event->key == InputKeyUp) { + temp_btn_id = SUBGHZ_CUSTOM_BTN_UP; + } else if(event->key == InputKeyDown) { + temp_btn_id = SUBGHZ_CUSTOM_BTN_DOWN; + } else if(event->key == InputKeyLeft) { + temp_btn_id = SUBGHZ_CUSTOM_BTN_LEFT; + } else if(event->key == InputKeyRight) { + temp_btn_id = SUBGHZ_CUSTOM_BTN_RIGHT; + } else { + // Finish processing if the button is different + return true; + } + + if(event->type == InputTypePress) { + subghz_custom_btn_set(temp_btn_id); + with_view_model( + subghz_transmitter->view, + SubGhzViewTransmitterModel * model, + { + furi_string_reset(model->temp_button_id); + if(subghz_custom_btn_get_original() != 0) { + if(subghz_custom_btn_get() == temp_btn_id) { + furi_string_printf( + model->temp_button_id, "%01X", subghz_custom_btn_get_original()); + model->draw_temp_button = true; + } } - } - }, - true); - subghz_transmitter->callback( - SubGhzCustomEventViewTransmitterSendStart, subghz_transmitter->context); - return true; - } else if(can_be_sent && event->key == InputKeyUp && event->type == InputTypeRelease) { - subghz_transmitter->callback( - SubGhzCustomEventViewTransmitterSendStop, subghz_transmitter->context); - return true; - } - // Down - if(can_be_sent && event->key == InputKeyDown && event->type == InputTypePress) { - subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_DOWN); - with_view_model( - subghz_transmitter->view, - SubGhzViewTransmitterModel * model, - { - furi_string_reset(model->temp_button_id); - if(subghz_custom_btn_get_original() != 0) { - if(subghz_custom_btn_get() == SUBGHZ_CUSTOM_BTN_DOWN) { - furi_string_printf( - model->temp_button_id, "%01X", subghz_custom_btn_get_original()); - model->draw_temp_button = true; - } - } - }, - true); - subghz_transmitter->callback( - SubGhzCustomEventViewTransmitterSendStart, subghz_transmitter->context); - return true; - } else if(can_be_sent && event->key == InputKeyDown && event->type == InputTypeRelease) { - subghz_transmitter->callback( - SubGhzCustomEventViewTransmitterSendStop, subghz_transmitter->context); - return true; - } - // Left - if(can_be_sent && event->key == InputKeyLeft && event->type == InputTypePress) { - subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_LEFT); - with_view_model( - subghz_transmitter->view, - SubGhzViewTransmitterModel * model, - { - furi_string_reset(model->temp_button_id); - if(subghz_custom_btn_get_original() != 0) { - if(subghz_custom_btn_get() == SUBGHZ_CUSTOM_BTN_LEFT) { - furi_string_printf( - model->temp_button_id, "%01X", subghz_custom_btn_get_original()); - model->draw_temp_button = true; - } - } - }, - true); - subghz_transmitter->callback( - SubGhzCustomEventViewTransmitterSendStart, subghz_transmitter->context); - return true; - } else if(can_be_sent && event->key == InputKeyLeft && event->type == InputTypeRelease) { - subghz_transmitter->callback( - SubGhzCustomEventViewTransmitterSendStop, subghz_transmitter->context); - return true; - } - // Right - if(can_be_sent && event->key == InputKeyRight && event->type == InputTypePress) { - subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_RIGHT); - with_view_model( - subghz_transmitter->view, - SubGhzViewTransmitterModel * model, - { - furi_string_reset(model->temp_button_id); - if(subghz_custom_btn_get_original() != 0) { - if(subghz_custom_btn_get() == SUBGHZ_CUSTOM_BTN_RIGHT) { - furi_string_printf( - model->temp_button_id, "%01X", subghz_custom_btn_get_original()); - model->draw_temp_button = true; - } - } - }, - true); - subghz_transmitter->callback( - SubGhzCustomEventViewTransmitterSendStart, subghz_transmitter->context); - return true; - } else if(can_be_sent && event->key == InputKeyRight && event->type == InputTypeRelease) { - subghz_transmitter->callback( - SubGhzCustomEventViewTransmitterSendStop, subghz_transmitter->context); - return true; + }, + true); + subghz_transmitter->callback( + SubGhzCustomEventViewTransmitterSendStart, subghz_transmitter->context); + return true; + } else if(event->type == InputTypeRelease) { + subghz_transmitter->callback( + SubGhzCustomEventViewTransmitterSendStop, subghz_transmitter->context); + return true; + } } return true; From 07b2f0109a758255237bb397a65f73c8b673e136 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 13 May 2023 21:57:25 +0300 Subject: [PATCH 05/10] SubGhz: keloq --- lib/subghz/protocols/keeloq.c | 152 ++++++++++++++++++---------------- 1 file changed, 79 insertions(+), 73 deletions(-) diff --git a/lib/subghz/protocols/keeloq.c b/lib/subghz/protocols/keeloq.c index 37e8c30e1..bbe97237e 100644 --- a/lib/subghz/protocols/keeloq.c +++ b/lib/subghz/protocols/keeloq.c @@ -14,6 +14,10 @@ #define TAG "SubGhzProtocolKeeloq" +#define KEELOQ_PROG_MODE_OFF (0U) +#define KEELOQ_PROG_MODE_BFT (1U) +#define KEELOQ_PROG_MODE_APRIMATIC (2U) + static const SubGhzBlockConst subghz_protocol_keeloq_const = { .te_short = 400, .te_long = 800, @@ -92,10 +96,9 @@ static uint8_t klq_prog_mode; static uint16_t temp_counter; void keeloq_reset_original_btn() { - subghz_custom_btn_set_original(0); - subghz_custom_btn_set_max(0); + subghz_custom_btns_reset(); temp_counter = 0; - klq_prog_mode = 0; + klq_prog_mode = KEELOQ_PROG_MODE_OFF; } void keeloq_reset_mfname() { @@ -146,6 +149,7 @@ void subghz_protocol_encoder_keeloq_free(void* context) { * Key generation from simple data * @param instance Pointer to a SubGhzProtocolEncoderKeeloq* instance * @param btn Button number, 4 bit + * @param counter_up increasing the counter if the value is true */ static bool subghz_protocol_keeloq_gen_data( SubGhzProtocolEncoderKeeloq* instance, @@ -160,29 +164,30 @@ static bool subghz_protocol_keeloq_gen_data( instance->manufacture_name = ""; } - // BFT programming mode on / off conditions - if((strcmp(instance->manufacture_name, "BFT") == 0) && (btn == 0xF)) { - klq_prog_mode = 1; - } - if((strcmp(instance->manufacture_name, "BFT") == 0) && (btn != 0xF) && (klq_prog_mode == 1)) { - klq_prog_mode = 0; - } - // Aprimatic programming mode on / off conditions - if((strcmp(instance->manufacture_name, "Aprimatic") == 0) && (btn == 0xF)) { - klq_prog_mode = 2; - } - if((strcmp(instance->manufacture_name, "Aprimatic") == 0) && (btn != 0xF) && - (klq_prog_mode == 2)) { - klq_prog_mode = 0; + // programming mode on / off conditions + if(strcmp(instance->manufacture_name, "BFT") == 0) { + // BFT programming mode on / off conditions + if(btn == 0xF) { + klq_prog_mode = KEELOQ_PROG_MODE_BFT; + } else if(klq_prog_mode == KEELOQ_PROG_MODE_BFT) { + klq_prog_mode = KEELOQ_PROG_MODE_OFF; + } + } else if(strcmp(instance->manufacture_name, "Aprimatic") == 0) { + // Aprimatic programming mode on / off conditions + if(btn == 0xF) { + klq_prog_mode = KEELOQ_PROG_MODE_APRIMATIC; + } else if(klq_prog_mode == KEELOQ_PROG_MODE_APRIMATIC) { + klq_prog_mode = KEELOQ_PROG_MODE_OFF; + } } // If we using BFT programming mode we will trasmit its seed in hop part like original remote - if(klq_prog_mode == 1) { + if(klq_prog_mode == KEELOQ_PROG_MODE_BFT) { hop = instance->generic.seed; - } else if(klq_prog_mode == 2) { + } else if(klq_prog_mode == KEELOQ_PROG_MODE_APRIMATIC) { // If we using Aprimatic programming mode we will trasmit some strange looking hop value, why? cuz manufacturer did it this way :) hop = 0x1A2B3C4D; } - if(counter_up && klq_prog_mode == 0) { + if(counter_up && klq_prog_mode == KEELOQ_PROG_MODE_OFF) { if(instance->generic.cnt < 0xFFFF) { if((instance->generic.cnt + furi_hal_subghz_get_rolling_counter_mult()) >= 0xFFFF) { instance->generic.cnt = 0; @@ -193,50 +198,8 @@ static bool subghz_protocol_keeloq_gen_data( instance->generic.cnt = 0; } } - if(klq_prog_mode == 0) { - uint32_t decrypt = (uint32_t)btn << 28 | - (instance->generic.serial & 0x3FF) - << 16 | //ToDo in some protocols the discriminator is 0 - instance->generic.cnt; - - if(strcmp(instance->manufacture_name, "Aprimatic") == 0) { - // Aprimatic uses 12bit serial number + 2bit APR1 "parity" bit in front of it replacing first 2 bits of serial - // Thats in theory! We need to check if this is true for all Aprimatic remotes but we got only 3 recordings to test - // For now lets assume that this is true for all Aprimatic remotes, if not we will need to add some more code here - uint32_t apri_serial = instance->generic.serial; - uint8_t apr1 = 0; - for(uint16_t i = 1; i != 0b10000000000; i <<= 1) { - if(apri_serial & i) apr1++; - } - apri_serial &= 0b00001111111111; - if(apr1 % 2 == 0) { - apri_serial |= 0b110000000000; - } - decrypt = btn << 28 | (apri_serial & 0xFFF) << 16 | instance->generic.cnt; - } - - // DTM Neo, Came_Space uses 12bit -> simple learning -- FAAC_RC,XT , Mutanco_Mutancode, Stilmatic(Schellenberg) -> 12bit normal learning - if((strcmp(instance->manufacture_name, "DTM_Neo") == 0) || - (strcmp(instance->manufacture_name, "FAAC_RC,XT") == 0) || - (strcmp(instance->manufacture_name, "Mutanco_Mutancode") == 0) || - (strcmp(instance->manufacture_name, "Stilmatic") == 0) || - (strcmp(instance->manufacture_name, "Came_Space") == 0)) { - decrypt = btn << 28 | (instance->generic.serial & 0xFFF) << 16 | instance->generic.cnt; - } - - // Nice Smilo, MHouse, JCM, Normstahl -> 8bit serial - simple learning - if((strcmp(instance->manufacture_name, "NICE_Smilo") == 0) || - (strcmp(instance->manufacture_name, "NICE_MHOUSE") == 0) || - (strcmp(instance->manufacture_name, "JCM_Tech") == 0) || - (strcmp(instance->manufacture_name, "Normstahl") == 0)) { - decrypt = btn << 28 | (instance->generic.serial & 0xFF) << 16 | instance->generic.cnt; - } - - // Beninca / Allmatic -> no serial - simple XOR - if(strcmp(instance->manufacture_name, "Beninca") == 0) { - decrypt = btn << 28 | (0x000) << 16 | instance->generic.cnt; - } - + if(klq_prog_mode == KEELOQ_PROG_MODE_OFF) { + // Protocols that do not use encryption if(strcmp(instance->manufacture_name, "Unknown") == 0) { code_found_reverse = subghz_protocol_blocks_reverse_key( instance->generic.data, instance->generic.data_count_bit); @@ -247,6 +210,49 @@ static bool subghz_protocol_keeloq_gen_data( } else if(strcmp(instance->manufacture_name, "HCS101") == 0) { hop = instance->generic.cnt << 16 | (btn & 0xF) << 12 | 0x000; } else { + // Protocols that use encryption + uint32_t decrypt = (uint32_t)btn << 28 | + (instance->generic.serial & 0x3FF) + << 16 | //ToDo in some protocols the discriminator is 0 + instance->generic.cnt; + + if(strcmp(instance->manufacture_name, "Aprimatic") == 0) { + // Aprimatic uses 12bit serial number + 2bit APR1 "parity" bit in front of it replacing first 2 bits of serial + // Thats in theory! We need to check if this is true for all Aprimatic remotes but we got only 3 recordings to test + // For now lets assume that this is true for all Aprimatic remotes, if not we will need to add some more code here + uint32_t apri_serial = instance->generic.serial; + uint8_t apr1 = 0; + for(uint16_t i = 1; i != 0b10000000000; i <<= 1) { + if(apri_serial & i) apr1++; + } + apri_serial &= 0b00001111111111; + if(apr1 % 2 == 0) { + apri_serial |= 0b110000000000; + } + decrypt = btn << 28 | (apri_serial & 0xFFF) << 16 | instance->generic.cnt; + } else if( + (strcmp(instance->manufacture_name, "DTM_Neo") == 0) || + (strcmp(instance->manufacture_name, "FAAC_RC,XT") == 0) || + (strcmp(instance->manufacture_name, "Mutanco_Mutancode") == 0) || + (strcmp(instance->manufacture_name, "Stilmatic") == 0) || + (strcmp(instance->manufacture_name, "Came_Space") == 0)) { + // DTM Neo, Came_Space uses 12bit serial -> simple learning + // FAAC_RC,XT , Mutanco_Mutancode, Stilmatic(Schellenberg) 12bit serial -> normal learning + decrypt = btn << 28 | (instance->generic.serial & 0xFFF) << 16 | + instance->generic.cnt; + } else if( + (strcmp(instance->manufacture_name, "NICE_Smilo") == 0) || + (strcmp(instance->manufacture_name, "NICE_MHOUSE") == 0) || + (strcmp(instance->manufacture_name, "JCM_Tech") == 0) || + (strcmp(instance->manufacture_name, "Normstahl") == 0)) { + // Nice Smilo, MHouse, JCM, Normstahl -> 8bit serial - simple learning + decrypt = btn << 28 | (instance->generic.serial & 0xFF) << 16 | + instance->generic.cnt; + } else if(strcmp(instance->manufacture_name, "Beninca") == 0) { + decrypt = btn << 28 | (0x000) << 16 | instance->generic.cnt; + // Beninca / Allmatic -> no serial - simple XOR + } + for M_EACH( manufacture_code, @@ -316,8 +322,8 @@ static bool subghz_protocol_keeloq_gen_data( uint64_t yek = (uint64_t)fix << 32 | hop; instance->generic.data = subghz_protocol_blocks_reverse_key(yek, instance->generic.data_count_bit); - } - return true; + } // What should happen if seed = 0 in bft programming mode + return true; // Always return true } bool subghz_protocol_keeloq_create_data( @@ -385,9 +391,9 @@ static bool if(instance->manufacture_name == 0x0) { instance->manufacture_name = ""; } - if(klq_prog_mode == 1) { + if(klq_prog_mode == KEELOQ_PROG_MODE_BFT) { instance->manufacture_name = "BFT"; - } else if(klq_prog_mode == 2) { + } else if(klq_prog_mode == KEELOQ_PROG_MODE_APRIMATIC) { instance->manufacture_name = "Aprimatic"; } uint8_t klq_last_custom_btn = 0xA; @@ -673,7 +679,7 @@ void* subghz_protocol_decoder_keeloq_alloc(SubGhzEnvironment* environment) { instance->keystore = subghz_environment_get_keystore(environment); instance->manufacture_from_file = furi_string_alloc(); - klq_prog_mode = 0; + klq_prog_mode = KEELOQ_PROG_MODE_OFF; return instance; } @@ -1192,8 +1198,8 @@ static void subghz_protocol_keeloq_check_remote_controller( uint32_t key_fix = key >> 32; uint32_t key_hop = key & 0x00000000ffffffff; - // If we are in BFT programming mode we will set previous remembered counter and skip mf keys check - if(klq_prog_mode == 0) { + // If we are in BFT / Aprimatic programming mode we will set previous remembered counter and skip mf keys check + if(klq_prog_mode == KEELOQ_PROG_MODE_OFF) { // Check key AN-Motors if((key_hop >> 24) == ((key_hop >> 16) & 0x00ff) && (key_fix >> 28) == ((key_hop >> 12) & 0x0f) && (key_hop & 0xFFF) == 0x404) { @@ -1210,11 +1216,11 @@ static void subghz_protocol_keeloq_check_remote_controller( } temp_counter = instance->cnt; - } else if(klq_prog_mode == 1) { + } else if(klq_prog_mode == KEELOQ_PROG_MODE_BFT) { *manufacture_name = "BFT"; mfname = *manufacture_name; instance->cnt = temp_counter; - } else if(klq_prog_mode == 2) { + } else if(klq_prog_mode == KEELOQ_PROG_MODE_APRIMATIC) { *manufacture_name = "Aprimatic"; mfname = *manufacture_name; instance->cnt = temp_counter; From 6b56de5c93adaf13157ef137ebb92e4e574198ec Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 13 May 2023 23:16:28 +0300 Subject: [PATCH 06/10] SubGhz some changes --- .../main/subghz_remote/subghz_remote_app.c | 4 +- lib/subghz/protocols/alutech_at_4n.c | 199 ++++++++------- lib/subghz/protocols/keeloq.c | 237 ++++++++++-------- lib/subghz/protocols/nice_flor_s.c | 139 +++++----- lib/subghz/protocols/secplus_v2.c | 139 +++++----- lib/subghz/protocols/somfy_telis.c | 139 +++++----- 6 files changed, 465 insertions(+), 392 deletions(-) diff --git a/applications/main/subghz_remote/subghz_remote_app.c b/applications/main/subghz_remote/subghz_remote_app.c index dd23533cc..8cef4da3a 100644 --- a/applications/main/subghz_remote/subghz_remote_app.c +++ b/applications/main/subghz_remote/subghz_remote_app.c @@ -12,7 +12,9 @@ #include #include -#include +#include +#include +#include #include #include diff --git a/lib/subghz/protocols/alutech_at_4n.c b/lib/subghz/protocols/alutech_at_4n.c index 83d98b7aa..281e820f0 100644 --- a/lib/subghz/protocols/alutech_at_4n.c +++ b/lib/subghz/protocols/alutech_at_4n.c @@ -318,6 +318,13 @@ bool subghz_protocol_alutech_at_4n_create_data( return res; } +/** + * Defines the button value for the current btn_id + * Basic set | 0x11 | 0x22 | 0xFF | 0x44 | 0x33 | + * @return Button code + */ +static uint8_t subghz_protocol_alutech_at_4n_get_btn_code(); + /** * Generating an upload from data. * @param instance Pointer to a SubGhzProtocolEncoderAlutech instance @@ -333,99 +340,7 @@ static bool subghz_protocol_encoder_alutech_at_4n_get_upload( subghz_custom_btn_set_original(btn); } - uint8_t custom_btn_id = subghz_custom_btn_get(); - uint8_t original_btn_code = subghz_custom_btn_get_original(); - - // Set custom button - // Basic set | 0x11 | 0x22 | 0xFF | 0x44 | 0x33 | - if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) { - // Restore original button code - btn = original_btn_code; - } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) { - switch(original_btn_code) { - case 0x11: - btn = 0x22; - break; - case 0x22: - btn = 0x11; - break; - case 0xFF: - btn = 0x11; - break; - case 0x44: - btn = 0x11; - break; - case 0x33: - btn = 0x11; - break; - - default: - break; - } - } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) { - switch(original_btn_code) { - case 0x11: - btn = 0x44; - break; - case 0x22: - btn = 0x44; - break; - case 0xFF: - btn = 0x44; - break; - case 0x44: - btn = 0xFF; - break; - case 0x33: - btn = 0x44; - break; - - default: - break; - } - } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) { - switch(original_btn_code) { - case 0x11: - btn = 0x33; - break; - case 0x22: - btn = 0x33; - break; - case 0xFF: - btn = 0x33; - break; - case 0x44: - btn = 0x33; - break; - case 0x33: - btn = 0x22; - break; - - default: - break; - } - } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_RIGHT) { - switch(original_btn_code) { - case 0x11: - btn = 0xFF; - break; - case 0x22: - btn = 0xFF; - break; - case 0xFF: - btn = 0x22; - break; - case 0x44: - btn = 0x22; - break; - case 0x33: - btn = 0xFF; - break; - - default: - break; - } - } + btn = subghz_protocol_alutech_at_4n_get_btn_code(); // Gen new key if(!subghz_protocol_alutech_at_4n_gen_data(instance, btn)) { @@ -786,6 +701,104 @@ SubGhzProtocolStatus subghz_protocol_decoder_alutech_at_4n_deserialize( return ret; } +static uint8_t subghz_protocol_alutech_at_4n_get_btn_code() { + uint8_t custom_btn_id = subghz_custom_btn_get(); + uint8_t original_btn_code = subghz_custom_btn_get_original(); + uint8_t btn = original_btn_code; + + // Set custom button + if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) { + // Restore original button code + btn = original_btn_code; + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) { + switch(original_btn_code) { + case 0x11: + btn = 0x22; + break; + case 0x22: + btn = 0x11; + break; + case 0xFF: + btn = 0x11; + break; + case 0x44: + btn = 0x11; + break; + case 0x33: + btn = 0x11; + break; + + default: + break; + } + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) { + switch(original_btn_code) { + case 0x11: + btn = 0x44; + break; + case 0x22: + btn = 0x44; + break; + case 0xFF: + btn = 0x44; + break; + case 0x44: + btn = 0xFF; + break; + case 0x33: + btn = 0x44; + break; + + default: + break; + } + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) { + switch(original_btn_code) { + case 0x11: + btn = 0x33; + break; + case 0x22: + btn = 0x33; + break; + case 0xFF: + btn = 0x33; + break; + case 0x44: + btn = 0x33; + break; + case 0x33: + btn = 0x22; + break; + + default: + break; + } + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_RIGHT) { + switch(original_btn_code) { + case 0x11: + btn = 0xFF; + break; + case 0x22: + btn = 0xFF; + break; + case 0xFF: + btn = 0x22; + break; + case 0x44: + btn = 0x22; + break; + case 0x33: + btn = 0xFF; + break; + + default: + break; + } + } + + return btn; +} + void subghz_protocol_decoder_alutech_at_4n_get_string(void* context, FuriString* output) { furi_assert(context); SubGhzProtocolDecoderAlutech_at_4n* instance = context; diff --git a/lib/subghz/protocols/keeloq.c b/lib/subghz/protocols/keeloq.c index bbe97237e..6c7e074fe 100644 --- a/lib/subghz/protocols/keeloq.c +++ b/lib/subghz/protocols/keeloq.c @@ -374,6 +374,14 @@ bool subghz_protocol_keeloq_bft_create_data( return res; } +/** + * Defines the button value for the current btn_id + * Basic set | 0x1 | 0x2 | 0x4 | 0x8 | 0xA or Special Learning Code | + * @param last_btn_code Candidate for the last button + * @return Button code + */ +static uint8_t subghz_protocol_keeloq_get_btn_code(uint8_t last_btn_code); + /** * Generating an upload from data. * @param instance Pointer to a SubGhzProtocolEncoderKeeloq instance @@ -402,115 +410,7 @@ static bool klq_last_custom_btn = 0xF; } - uint8_t custom_btn_id = subghz_custom_btn_get(); - uint8_t original_btn_code = subghz_custom_btn_get_original(); - - // Set custom button - // Basic set | 0x1 | 0x2 | 0x4 | 0x8 | 0xA or Special Learning Code | - if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) { - // Restore original button code - btn = original_btn_code; - } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) { - switch(original_btn_code) { - case 0x1: - btn = 0x2; - break; - case 0x2: - btn = 0x1; - break; - case 0xA: - btn = 0x1; - break; - case 0x4: - btn = 0x1; - break; - case 0x8: - btn = 0x1; - break; - case 0xF: - btn = 0x1; - break; - - default: - btn = 0x1; - break; - } - } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) { - switch(original_btn_code) { - case 0x1: - btn = 0x4; - break; - case 0x2: - btn = 0x4; - break; - case 0xA: - btn = 0x4; - break; - case 0x4: - btn = klq_last_custom_btn; - break; - case 0x8: - btn = 0x4; - break; - case 0xF: - btn = 0x4; - break; - - default: - btn = 0x4; - break; - } - } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) { - switch(original_btn_code) { - case 0x1: - btn = 0x8; - break; - case 0x2: - btn = 0x8; - break; - case 0xA: - btn = 0x8; - break; - case 0x4: - btn = 0x8; - break; - case 0x8: - btn = 0x2; - break; - case 0xF: - btn = 0x8; - break; - - default: - btn = 0x8; - break; - } - } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_RIGHT) { - switch(original_btn_code) { - case 0x1: - btn = klq_last_custom_btn; - break; - case 0x2: - btn = klq_last_custom_btn; - break; - case 0xA: - btn = 0x2; - break; - case 0x4: - btn = 0x2; - break; - case 0x8: - btn = klq_last_custom_btn; - break; - case 0xF: - btn = 0x2; - break; - - default: - btn = 0x2; - break; - } - } + btn = subghz_protocol_keeloq_get_btn_code(klq_last_custom_btn); // Generate new key if(subghz_protocol_keeloq_gen_data(instance, btn, true)) { @@ -1330,6 +1230,125 @@ SubGhzProtocolStatus return res; } +static uint8_t subghz_protocol_keeloq_get_btn_code(uint8_t last_btn_code) { + uint8_t custom_btn_id = subghz_custom_btn_get(); + uint8_t original_btn_code = subghz_custom_btn_get_original(); + uint8_t btn = original_btn_code; + + if(last_btn_code == 0) { + last_btn_code = 0xA; + } + + // Set custom button + // Basic set | 0x1 | 0x2 | 0x4 | 0x8 | 0xA or Special Learning Code | + if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) { + // Restore original button code + btn = original_btn_code; + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) { + switch(original_btn_code) { + case 0x1: + btn = 0x2; + break; + case 0x2: + btn = 0x1; + break; + case 0xA: + btn = 0x1; + break; + case 0x4: + btn = 0x1; + break; + case 0x8: + btn = 0x1; + break; + case 0xF: + btn = 0x1; + break; + + default: + btn = 0x1; + break; + } + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) { + switch(original_btn_code) { + case 0x1: + btn = 0x4; + break; + case 0x2: + btn = 0x4; + break; + case 0xA: + btn = 0x4; + break; + case 0x4: + btn = last_btn_code; + break; + case 0x8: + btn = 0x4; + break; + case 0xF: + btn = 0x4; + break; + + default: + btn = 0x4; + break; + } + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) { + switch(original_btn_code) { + case 0x1: + btn = 0x8; + break; + case 0x2: + btn = 0x8; + break; + case 0xA: + btn = 0x8; + break; + case 0x4: + btn = 0x8; + break; + case 0x8: + btn = 0x2; + break; + case 0xF: + btn = 0x8; + break; + + default: + btn = 0x8; + break; + } + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_RIGHT) { + switch(original_btn_code) { + case 0x1: + btn = last_btn_code; + break; + case 0x2: + btn = last_btn_code; + break; + case 0xA: + btn = 0x2; + break; + case 0x4: + btn = 0x2; + break; + case 0x8: + btn = last_btn_code; + break; + case 0xF: + btn = 0x2; + break; + + default: + btn = 0x2; + break; + } + } + + return btn; +} + void subghz_protocol_decoder_keeloq_get_string(void* context, FuriString* output) { furi_assert(context); SubGhzProtocolDecoderKeeloq* instance = context; diff --git a/lib/subghz/protocols/nice_flor_s.c b/lib/subghz/protocols/nice_flor_s.c index f337ca105..5eaa21274 100644 --- a/lib/subghz/protocols/nice_flor_s.c +++ b/lib/subghz/protocols/nice_flor_s.c @@ -117,6 +117,13 @@ void subghz_protocol_encoder_nice_flor_s_free(void* context) { static void subghz_protocol_nice_one_get_data(uint8_t* p, uint8_t num_parcel, uint8_t hold_bit); +/** + * Defines the button value for the current btn_id + * Basic set | 0x1 | 0x2 | 0x4 | 0x8 | + * @return Button code + */ +static uint8_t subghz_protocol_nice_flor_s_get_btn_code(); + /** * Generating an upload from data. * @param instance Pointer to a SubGhzProtocolEncoderNiceFlorS instance @@ -135,69 +142,7 @@ static void subghz_protocol_encoder_nice_flor_s_get_upload( subghz_custom_btn_set_original(btn); } - uint8_t custom_btn_id = subghz_custom_btn_get(); - uint8_t original_btn_code = subghz_custom_btn_get_original(); - - // Set custom button - // Basic set | 0x1 | 0x2 | 0x4 | 0x8 | - if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) { - // Restore original button code - btn = original_btn_code; - } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) { - switch(original_btn_code) { - case 0x1: - btn = 0x2; - break; - case 0x2: - btn = 0x1; - break; - case 0x4: - btn = 0x1; - break; - case 0x8: - btn = 0x1; - break; - - default: - break; - } - } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) { - switch(original_btn_code) { - case 0x1: - btn = 0x4; - break; - case 0x2: - btn = 0x4; - break; - case 0x4: - btn = 0x2; - break; - case 0x8: - btn = 0x4; - break; - - default: - break; - } - } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) { - switch(original_btn_code) { - case 0x1: - btn = 0x8; - break; - case 0x2: - btn = 0x8; - break; - case 0x4: - btn = 0x8; - break; - case 0x8: - btn = 0x2; - break; - - default: - break; - } - } + btn = subghz_protocol_nice_flor_s_get_btn_code(); size_t size_upload = ((instance->generic.data_count_bit * 2) + ((37 + 2 + 2) * 2) * 16); if(size_upload > instance->encoder.size_upload) { @@ -806,6 +751,74 @@ SubGhzProtocolStatus return ret; } +static uint8_t subghz_protocol_nice_flor_s_get_btn_code() { + uint8_t custom_btn_id = subghz_custom_btn_get(); + uint8_t original_btn_code = subghz_custom_btn_get_original(); + uint8_t btn = original_btn_code; + + // Set custom button + if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) { + // Restore original button code + btn = original_btn_code; + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) { + switch(original_btn_code) { + case 0x1: + btn = 0x2; + break; + case 0x2: + btn = 0x1; + break; + case 0x4: + btn = 0x1; + break; + case 0x8: + btn = 0x1; + break; + + default: + break; + } + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) { + switch(original_btn_code) { + case 0x1: + btn = 0x4; + break; + case 0x2: + btn = 0x4; + break; + case 0x4: + btn = 0x2; + break; + case 0x8: + btn = 0x4; + break; + + default: + break; + } + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) { + switch(original_btn_code) { + case 0x1: + btn = 0x8; + break; + case 0x2: + btn = 0x8; + break; + case 0x4: + btn = 0x8; + break; + case 0x8: + btn = 0x2; + break; + + default: + break; + } + } + + return btn; +} + void subghz_protocol_decoder_nice_flor_s_get_string(void* context, FuriString* output) { furi_assert(context); SubGhzProtocolDecoderNiceFlorS* instance = context; diff --git a/lib/subghz/protocols/secplus_v2.c b/lib/subghz/protocols/secplus_v2.c index 97631ce34..d39f794ab 100644 --- a/lib/subghz/protocols/secplus_v2.c +++ b/lib/subghz/protocols/secplus_v2.c @@ -375,6 +375,13 @@ static uint64_t subghz_protocol_secplus_v2_encode_half(uint8_t roll_array[], uin return data; } +/** + * Defines the button value for the current btn_id + * Basic set | 0x68 | 0x80 | 0x81 | 0xE2 | + * @return Button code + */ +static uint8_t subghz_protocol_secplus_v2_get_btn_code(); + /** * Security+ 2.0 message encoding * @param instance SubGhzProtocolEncoderSecPlus_v2* @@ -386,69 +393,7 @@ static void subghz_protocol_secplus_v2_encode(SubGhzProtocolEncoderSecPlus_v2* i subghz_custom_btn_set_original(instance->generic.btn); } - uint8_t custom_btn_id = subghz_custom_btn_get(); - uint8_t original_btn_code = subghz_custom_btn_get_original(); - - // Set custom button - // Basic set | 0x68 | 0x80 | 0x81 | 0xE2 | - if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) { - // Restore original button code - instance->generic.btn = original_btn_code; - } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) { - switch(original_btn_code) { - case 0x68: - instance->generic.btn = 0x80; - break; - case 0x80: - instance->generic.btn = 0x68; - break; - case 0x81: - instance->generic.btn = 0x80; - break; - case 0xE2: - instance->generic.btn = 0x80; - break; - - default: - break; - } - } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) { - switch(original_btn_code) { - case 0x68: - instance->generic.btn = 0x81; - break; - case 0x80: - instance->generic.btn = 0x81; - break; - case 0x81: - instance->generic.btn = 0x68; - break; - case 0xE2: - instance->generic.btn = 0x81; - break; - - default: - break; - } - } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) { - switch(original_btn_code) { - case 0x68: - instance->generic.btn = 0xE2; - break; - case 0x80: - instance->generic.btn = 0xE2; - break; - case 0x81: - instance->generic.btn = 0xE2; - break; - case 0xE2: - instance->generic.btn = 0x68; - break; - - default: - break; - } - } + instance->generic.btn = subghz_protocol_secplus_v2_get_btn_code(); uint32_t fixed_1[1] = {instance->generic.btn << 12 | instance->generic.serial >> 20}; uint32_t fixed_2[1] = {instance->generic.serial & 0xFFFFF}; @@ -888,6 +833,74 @@ SubGhzProtocolStatus return ret; } +static uint8_t subghz_protocol_secplus_v2_get_btn_code() { + uint8_t custom_btn_id = subghz_custom_btn_get(); + uint8_t original_btn_code = subghz_custom_btn_get_original(); + uint8_t btn = original_btn_code; + + // Set custom button + if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) { + // Restore original button code + btn = original_btn_code; + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) { + switch(original_btn_code) { + case 0x68: + btn = 0x80; + break; + case 0x80: + btn = 0x68; + break; + case 0x81: + btn = 0x80; + break; + case 0xE2: + btn = 0x80; + break; + + default: + break; + } + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) { + switch(original_btn_code) { + case 0x68: + btn = 0x81; + break; + case 0x80: + btn = 0x81; + break; + case 0x81: + btn = 0x68; + break; + case 0xE2: + btn = 0x81; + break; + + default: + break; + } + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) { + switch(original_btn_code) { + case 0x68: + btn = 0xE2; + break; + case 0x80: + btn = 0xE2; + break; + case 0x81: + btn = 0xE2; + break; + case 0xE2: + btn = 0x68; + break; + + default: + break; + } + } + + return btn; +} + void subghz_protocol_decoder_secplus_v2_get_string(void* context, FuriString* output) { furi_assert(context); SubGhzProtocolDecoderSecPlus_v2* instance = context; diff --git a/lib/subghz/protocols/somfy_telis.c b/lib/subghz/protocols/somfy_telis.c index fc4034d1f..6a159a7ea 100644 --- a/lib/subghz/protocols/somfy_telis.c +++ b/lib/subghz/protocols/somfy_telis.c @@ -97,6 +97,13 @@ void subghz_protocol_encoder_somfy_telis_free(void* context) { free(instance); } +/** + * Defines the button value for the current btn_id + * Basic set | 0x1 | 0x2 | 0x4 | 0x8 | + * @return Button code + */ +static uint8_t subghz_protocol_somfy_telis_get_btn_code(); + static bool subghz_protocol_somfy_telis_gen_data( SubGhzProtocolEncoderSomfyTelis* instance, uint8_t btn, @@ -115,69 +122,7 @@ static bool subghz_protocol_somfy_telis_gen_data( subghz_custom_btn_set_original(btn); } - uint8_t custom_btn_id = subghz_custom_btn_get(); - uint8_t original_btn_code = subghz_custom_btn_get_original(); - - // Set custom button - // Basic set | 0x1 | 0x2 | 0x4 | 0x8 | - if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) { - // Restore original button code - btn = original_btn_code; - } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) { - switch(original_btn_code) { - case 0x1: - btn = 0x2; - break; - case 0x2: - btn = 0x1; - break; - case 0x4: - btn = 0x1; - break; - case 0x8: - btn = 0x1; - break; - - default: - break; - } - } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) { - switch(original_btn_code) { - case 0x1: - btn = 0x4; - break; - case 0x2: - btn = 0x4; - break; - case 0x4: - btn = 0x2; - break; - case 0x8: - btn = 0x4; - break; - - default: - break; - } - } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) { - switch(original_btn_code) { - case 0x1: - btn = 0x8; - break; - case 0x2: - btn = 0x8; - break; - case 0x4: - btn = 0x8; - break; - case 0x8: - btn = 0x2; - break; - - default: - break; - } - } + btn = subghz_protocol_somfy_telis_get_btn_code(); if(instance->generic.cnt < 0xFFFF) { if((instance->generic.cnt + furi_hal_subghz_get_rolling_counter_mult()) >= 0xFFFF) { @@ -723,6 +668,74 @@ SubGhzProtocolStatus subghz_protocol_somfy_telis_const.min_count_bit_for_found); } +static uint8_t subghz_protocol_somfy_telis_get_btn_code() { + uint8_t custom_btn_id = subghz_custom_btn_get(); + uint8_t original_btn_code = subghz_custom_btn_get_original(); + uint8_t btn = original_btn_code; + + // Set custom button + if((custom_btn_id == SUBGHZ_CUSTOM_BTN_OK) && (original_btn_code != 0)) { + // Restore original button code + btn = original_btn_code; + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_UP) { + switch(original_btn_code) { + case 0x1: + btn = 0x2; + break; + case 0x2: + btn = 0x1; + break; + case 0x4: + btn = 0x1; + break; + case 0x8: + btn = 0x1; + break; + + default: + break; + } + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_DOWN) { + switch(original_btn_code) { + case 0x1: + btn = 0x4; + break; + case 0x2: + btn = 0x4; + break; + case 0x4: + btn = 0x2; + break; + case 0x8: + btn = 0x4; + break; + + default: + break; + } + } else if(custom_btn_id == SUBGHZ_CUSTOM_BTN_LEFT) { + switch(original_btn_code) { + case 0x1: + btn = 0x8; + break; + case 0x2: + btn = 0x8; + break; + case 0x4: + btn = 0x8; + break; + case 0x8: + btn = 0x2; + break; + + default: + break; + } + } + + return btn; +} + void subghz_protocol_decoder_somfy_telis_get_string(void* context, FuriString* output) { furi_assert(context); SubGhzProtocolDecoderSomfyTelis* instance = context; From 71f48ea39ef148c4c7ca97680be2e210964eae21 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sun, 14 May 2023 00:48:06 +0300 Subject: [PATCH 07/10] Keeloq and Star line remove duplicate code --- lib/subghz/protocols/keeloq.c | 216 +++++-------------------------- lib/subghz/protocols/star_line.c | 102 ++------------- 2 files changed, 40 insertions(+), 278 deletions(-) diff --git a/lib/subghz/protocols/keeloq.c b/lib/subghz/protocols/keeloq.c index 6c7e074fe..9b86eb5e8 100644 --- a/lib/subghz/protocols/keeloq.c +++ b/lib/subghz/protocols/keeloq.c @@ -739,14 +739,19 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( uint8_t btn = (uint8_t)(fix >> 28); uint32_t decrypt = 0; uint64_t man; - int res = 0; + bool mf_not_set = false; if(mfname == 0x0) { mfname = ""; } - if(strcmp(mfname, "") == 0) { - for - M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) { + if(strcmp(mfname, "Unknown") == 0) { + return 1; + } else if(strcmp(mfname, "") == 0) { + mf_not_set = true; + } + for + M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) { + if(mf_not_set || (strcmp(furi_string_get_cstr(manufacture_code->name), mfname) == 0)) { switch(manufacture_code->type) { case KEELOQ_LEARNING_SIMPLE: // Simple Learning @@ -800,23 +805,29 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( } break; case KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_2: - man = subghz_protocol_keeloq_common_magic_serial_type2_learning( - fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; + if(mf_not_set) { + man = subghz_protocol_keeloq_common_magic_serial_type2_learning( + fix, manufacture_code->key); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); + if(subghz_protocol_keeloq_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + return 1; + } } break; case KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_3: - man = subghz_protocol_keeloq_common_magic_serial_type3_learning( - fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; + if(mf_not_set) { + man = subghz_protocol_keeloq_common_magic_serial_type3_learning( + fix, manufacture_code->key); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); + if(subghz_protocol_keeloq_check_decrypt( + instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + return 1; + } } break; case KEELOQ_LEARNING_UNKNOWN: @@ -914,174 +925,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( break; } } - } else if(strcmp(mfname, "Unknown") == 0) { - return 1; - } else { - for - M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) { - res = strcmp(furi_string_get_cstr(manufacture_code->name), mfname); - if(res == 0) { - switch(manufacture_code->type) { - case KEELOQ_LEARNING_SIMPLE: - // Simple Learning - decrypt = - subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key); - if(subghz_protocol_keeloq_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } - break; - case KEELOQ_LEARNING_NORMAL: - // Normal Learning - // https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37 - man = subghz_protocol_keeloq_common_normal_learning( - fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } - break; - case KEELOQ_LEARNING_SECURE: - man = subghz_protocol_keeloq_common_secure_learning( - fix, instance->seed, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } - break; - case KEELOQ_LEARNING_MAGIC_XOR_TYPE_1: - man = subghz_protocol_keeloq_common_magic_xor_type1_learning( - fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } - break; - case KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_1: - man = subghz_protocol_keeloq_common_magic_serial_type1_learning( - fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } - break; - case KEELOQ_LEARNING_UNKNOWN: - // Simple Learning - decrypt = - subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key); - if(subghz_protocol_keeloq_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 1; - return 1; - } - // Check for mirrored man - uint64_t man_rev = 0; - uint64_t man_rev_byte = 0; - for(uint8_t i = 0; i < 64; i += 8) { - man_rev_byte = (uint8_t)(manufacture_code->key >> i); - man_rev = man_rev | man_rev_byte << (56 - i); - } - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man_rev); - if(subghz_protocol_keeloq_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 1; - return 1; - } - //########################### - // Normal Learning - // https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37 - man = subghz_protocol_keeloq_common_normal_learning( - fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 2; - return 1; - } - - // Check for mirrored man - man = subghz_protocol_keeloq_common_normal_learning(fix, man_rev); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 2; - return 1; - } - - // Secure Learning - man = subghz_protocol_keeloq_common_secure_learning( - fix, instance->seed, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 3; - return 1; - } - - // Check for mirrored man - man = subghz_protocol_keeloq_common_secure_learning( - fix, instance->seed, man_rev); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 3; - return 1; - } - - // Magic xor type1 learning - man = subghz_protocol_keeloq_common_magic_xor_type1_learning( - fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 4; - return 1; - } - - // Check for mirrored man - man = subghz_protocol_keeloq_common_magic_xor_type1_learning(fix, man_rev); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 4; - return 1; - } - - break; - } - } - } - } + } *manufacture_name = "Unknown"; mfname = "Unknown"; diff --git a/lib/subghz/protocols/star_line.c b/lib/subghz/protocols/star_line.c index 792622412..83a4846cd 100644 --- a/lib/subghz/protocols/star_line.c +++ b/lib/subghz/protocols/star_line.c @@ -522,14 +522,19 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( uint8_t btn = (uint8_t)(fix >> 24); uint32_t decrypt = 0; uint64_t man_normal_learning; - int res = 0; + bool mf_not_set = false; if(mfname == 0x0) { mfname = ""; } - if(strcmp(mfname, "") == 0) { - for - M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) { + if(strcmp(mfname, "Unknown") == 0) { + return 1; + } else if(strcmp(mfname, "") == 0) { + mf_not_set = true; + } + for + M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) { + if(mf_not_set || strcmp(furi_string_get_cstr(manufacture_code->name), mfname)) { switch(manufacture_code->type) { case KEELOQ_LEARNING_SIMPLE: // Simple Learning @@ -606,94 +611,7 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( break; } } - } else if(strcmp(mfname, "Unknown") == 0) { - return 1; - } else { - for - M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) { - res = strcmp(furi_string_get_cstr(manufacture_code->name), mfname); - if(res == 0) { - switch(manufacture_code->type) { - case KEELOQ_LEARNING_SIMPLE: - // Simple Learning - decrypt = - subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key); - if(subghz_protocol_star_line_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } - break; - case KEELOQ_LEARNING_NORMAL: - // Normal Learning - // https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37 - man_normal_learning = subghz_protocol_keeloq_common_normal_learning( - fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man_normal_learning); - if(subghz_protocol_star_line_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } - break; - case KEELOQ_LEARNING_UNKNOWN: - // Simple Learning - decrypt = - subghz_protocol_keeloq_common_decrypt(hop, manufacture_code->key); - if(subghz_protocol_star_line_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 1; - return 1; - } - // Check for mirrored man - uint64_t man_rev = 0; - uint64_t man_rev_byte = 0; - for(uint8_t i = 0; i < 64; i += 8) { - man_rev_byte = (uint8_t)(manufacture_code->key >> i); - man_rev = man_rev | man_rev_byte << (56 - i); - } - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man_rev); - if(subghz_protocol_star_line_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 1; - return 1; - } - //########################### - // Normal Learning - // https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37 - man_normal_learning = subghz_protocol_keeloq_common_normal_learning( - fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man_normal_learning); - if(subghz_protocol_star_line_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 2; - return 1; - } - - // Check for mirrored man - man_normal_learning = - subghz_protocol_keeloq_common_normal_learning(fix, man_rev); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man_normal_learning); - if(subghz_protocol_star_line_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - kl_type = 2; - return 1; - } - break; - } - } - } - } + } *manufacture_name = "Unknown"; mfname = "Unknown"; From d87df3e6c25dddc71891c255dffdf05a7e81ea4d Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sun, 14 May 2023 01:34:43 +0300 Subject: [PATCH 08/10] Change custom btn sending logic --- applications/main/subghz/views/transmitter.c | 73 ++++++++++---------- firmware/targets/f7/api_symbols.csv | 5 +- lib/subghz/blocks/custom_btn.c | 8 ++- lib/subghz/blocks/custom_btn.h | 6 +- 4 files changed, 52 insertions(+), 40 deletions(-) diff --git a/applications/main/subghz/views/transmitter.c b/applications/main/subghz/views/transmitter.c index 08db03334..7ae865064 100644 --- a/applications/main/subghz/views/transmitter.c +++ b/applications/main/subghz/views/transmitter.c @@ -156,43 +156,46 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) { return true; } // Finish "OK" key processing - uint8_t temp_btn_id; - if(event->key == InputKeyUp) { - temp_btn_id = SUBGHZ_CUSTOM_BTN_UP; - } else if(event->key == InputKeyDown) { - temp_btn_id = SUBGHZ_CUSTOM_BTN_DOWN; - } else if(event->key == InputKeyLeft) { - temp_btn_id = SUBGHZ_CUSTOM_BTN_LEFT; - } else if(event->key == InputKeyRight) { - temp_btn_id = SUBGHZ_CUSTOM_BTN_RIGHT; - } else { - // Finish processing if the button is different - return true; - } + if(subghz_custom_btn_is_allowed()) { + uint8_t temp_btn_id; + if(event->key == InputKeyUp) { + temp_btn_id = SUBGHZ_CUSTOM_BTN_UP; + } else if(event->key == InputKeyDown) { + temp_btn_id = SUBGHZ_CUSTOM_BTN_DOWN; + } else if(event->key == InputKeyLeft) { + temp_btn_id = SUBGHZ_CUSTOM_BTN_LEFT; + } else if(event->key == InputKeyRight) { + temp_btn_id = SUBGHZ_CUSTOM_BTN_RIGHT; + } else { + // Finish processing if the button is different + return true; + } - if(event->type == InputTypePress) { - subghz_custom_btn_set(temp_btn_id); - with_view_model( - subghz_transmitter->view, - SubGhzViewTransmitterModel * model, - { - furi_string_reset(model->temp_button_id); - if(subghz_custom_btn_get_original() != 0) { - if(subghz_custom_btn_get() == temp_btn_id) { - furi_string_printf( - model->temp_button_id, "%01X", subghz_custom_btn_get_original()); - model->draw_temp_button = true; + if(event->type == InputTypePress) { + with_view_model( + subghz_transmitter->view, + SubGhzViewTransmitterModel * model, + { + furi_string_reset(model->temp_button_id); + if(subghz_custom_btn_get_original() != 0) { + if(subghz_custom_btn_set(temp_btn_id)) { + furi_string_printf( + model->temp_button_id, + "%01X", + subghz_custom_btn_get_original()); + model->draw_temp_button = true; + } } - } - }, - true); - subghz_transmitter->callback( - SubGhzCustomEventViewTransmitterSendStart, subghz_transmitter->context); - return true; - } else if(event->type == InputTypeRelease) { - subghz_transmitter->callback( - SubGhzCustomEventViewTransmitterSendStop, subghz_transmitter->context); - return true; + }, + true); + subghz_transmitter->callback( + SubGhzCustomEventViewTransmitterSendStart, subghz_transmitter->context); + return true; + } else if(event->type == InputTypeRelease) { + subghz_transmitter->callback( + SubGhzCustomEventViewTransmitterSendStop, subghz_transmitter->context); + return true; + } } } diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index 7eac9ab00..4bf96d2a9 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,26.2,, +Version,+,26.3,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/cli/cli.h,, Header,+,applications/services/cli/cli_vcp.h,, @@ -2703,7 +2703,8 @@ Function,+,subghz_block_generic_get_preset_name,void,"const char*, FuriString*" Function,+,subghz_block_generic_serialize,SubGhzProtocolStatus,"SubGhzBlockGeneric*, FlipperFormat*, SubGhzRadioPreset*" Function,-,subghz_custom_btn_get,uint8_t, Function,-,subghz_custom_btn_get_original,uint8_t, -Function,-,subghz_custom_btn_set,void,uint8_t +Function,-,subghz_custom_btn_is_allowed,_Bool, +Function,-,subghz_custom_btn_set,_Bool,uint8_t Function,-,subghz_custom_btn_set_max,void,uint8_t Function,-,subghz_custom_btn_set_original,void,uint8_t Function,-,subghz_custom_btns_reset,void, diff --git a/lib/subghz/blocks/custom_btn.c b/lib/subghz/blocks/custom_btn.c index 158c10a2f..275a4c930 100644 --- a/lib/subghz/blocks/custom_btn.c +++ b/lib/subghz/blocks/custom_btn.c @@ -4,11 +4,13 @@ static uint8_t custom_btn_id = SUBGHZ_CUSTOM_BTN_OK; static uint8_t custom_btn_original = 0; static uint8_t custom_btn_max_btns = 0; -void subghz_custom_btn_set(uint8_t btn_id) { +bool subghz_custom_btn_set(uint8_t btn_id) { if(btn_id > custom_btn_max_btns) { custom_btn_id = SUBGHZ_CUSTOM_BTN_OK; + return false; } else { custom_btn_id = btn_id; + return true; } } @@ -31,4 +33,8 @@ void subghz_custom_btn_set_max(uint8_t b) { void subghz_custom_btns_reset() { custom_btn_original = 0; custom_btn_max_btns = 0; +} + +bool subghz_custom_btn_is_allowed() { + return custom_btn_max_btns != 0; } \ No newline at end of file diff --git a/lib/subghz/blocks/custom_btn.h b/lib/subghz/blocks/custom_btn.h index a92567321..c13842fa8 100644 --- a/lib/subghz/blocks/custom_btn.h +++ b/lib/subghz/blocks/custom_btn.h @@ -11,7 +11,7 @@ #define SUBGHZ_CUSTOM_BTN_LEFT (3U) #define SUBGHZ_CUSTOM_BTN_RIGHT (4U) -void subghz_custom_btn_set(uint8_t btn_id); +bool subghz_custom_btn_set(uint8_t btn_id); uint8_t subghz_custom_btn_get(); @@ -21,4 +21,6 @@ uint8_t subghz_custom_btn_get_original(); void subghz_custom_btn_set_max(uint8_t b); -void subghz_custom_btns_reset(); \ No newline at end of file +void subghz_custom_btns_reset(); + +bool subghz_custom_btn_is_allowed(); \ No newline at end of file From 43e5daded277d01108816e9adb1eb7c96cc147c0 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sun, 14 May 2023 04:11:26 +0300 Subject: [PATCH 09/10] fix small bugs --- lib/subghz/protocols/keeloq.c | 34 +++++++++++++------------------- lib/subghz/protocols/star_line.c | 2 +- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/lib/subghz/protocols/keeloq.c b/lib/subghz/protocols/keeloq.c index 9b86eb5e8..26b5a20a9 100644 --- a/lib/subghz/protocols/keeloq.c +++ b/lib/subghz/protocols/keeloq.c @@ -805,29 +805,23 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( } break; case KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_2: - if(mf_not_set) { - man = subghz_protocol_keeloq_common_magic_serial_type2_learning( - fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } + man = subghz_protocol_keeloq_common_magic_serial_type2_learning( + fix, manufacture_code->key); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); + if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + return 1; } break; case KEELOQ_LEARNING_MAGIC_SERIAL_TYPE_3: - if(mf_not_set) { - man = subghz_protocol_keeloq_common_magic_serial_type3_learning( - fix, manufacture_code->key); - decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt( - instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; - return 1; - } + man = subghz_protocol_keeloq_common_magic_serial_type3_learning( + fix, manufacture_code->key); + decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); + if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + mfname = *manufacture_name; + return 1; } break; case KEELOQ_LEARNING_UNKNOWN: diff --git a/lib/subghz/protocols/star_line.c b/lib/subghz/protocols/star_line.c index 83a4846cd..362e34f3c 100644 --- a/lib/subghz/protocols/star_line.c +++ b/lib/subghz/protocols/star_line.c @@ -534,7 +534,7 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( } for M_EACH(manufacture_code, *subghz_keystore_get_data(keystore), SubGhzKeyArray_t) { - if(mf_not_set || strcmp(furi_string_get_cstr(manufacture_code->name), mfname)) { + if(mf_not_set || (strcmp(furi_string_get_cstr(manufacture_code->name), mfname) == 0)) { switch(manufacture_code->type) { case KEELOQ_LEARNING_SIMPLE: // Simple Learning From c0b3a18316b01fd3cbb1cebab559e170811dbac9 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sun, 14 May 2023 04:27:25 +0300 Subject: [PATCH 10/10] api --- firmware/targets/f7/api_symbols.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index bbe92e30f..b69a251e0 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,26.3,, +Version,+,26.2,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/cli/cli.h,, Header,+,applications/services/cli/cli_vcp.h,,