From 09527c3ab6dfdecf33c99e2bbe6eddaa64c30aa3 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 20 May 2023 01:15:36 +0300 Subject: [PATCH 1/9] keeloq --- .../main/subghz/helpers/subghz_txrx.c | 6 + .../main/subghz/helpers/subghz_txrx.h | 2 + .../scenes/subghz_scene_receiver_info.c | 7 +- .../main/subghz/scenes/subghz_scene_rpc.c | 7 +- .../subghz/scenes/subghz_scene_transmitter.c | 8 +- .../main/subghz_remote/subghz_remote_app_i.c | 5 +- firmware/targets/f7/api_symbols.csv | 6 +- lib/subghz/environment.c | 30 +++++ lib/subghz/environment.h | 12 ++ lib/subghz/protocols/keeloq.c | 120 ++++++++++-------- lib/subghz/protocols/keeloq.h | 4 - lib/subghz/protocols/star_line.c | 77 ++++++----- 12 files changed, 176 insertions(+), 108 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index c1f519ba0..c2d7e1bf5 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -557,6 +557,12 @@ bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance) { return instance->debug_pin_state; } +void subghz_txrx_reset_dynamic(SubGhzTxRx* instance) { + furi_assert(instance); + subghz_environment_reset_keeloq(instance->environment); + subghz_custom_btns_reset(); +} + SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance) { furi_assert(instance); return instance->receiver; diff --git a/applications/main/subghz/helpers/subghz_txrx.h b/applications/main/subghz/helpers/subghz_txrx.h index fd7c024b8..6c28cc5f0 100644 --- a/applications/main/subghz/helpers/subghz_txrx.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -293,4 +293,6 @@ void subghz_txrx_set_raw_file_encoder_worker_callback_end( void subghz_txrx_set_debug_pin_state(SubGhzTxRx* instance, bool state); bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance); +void subghz_txrx_reset_dynamic(SubGhzTxRx* instance); + SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance); // TODO use only in DecodeRaw diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index 2d89de731..d9ba5bd84 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -191,10 +191,5 @@ void subghz_scene_receiver_info_on_exit(void* context) { SubGhz* subghz = context; widget_reset(subghz->widget); - keeloq_reset_mfname(); - keeloq_reset_kl_type(); - keeloq_reset_original_btn(); - subghz_custom_btns_reset(); - star_line_reset_mfname(); - star_line_reset_kl_type(); + subghz_txrx_reset_dynamic(subghz->txrx); } diff --git a/applications/main/subghz/scenes/subghz_scene_rpc.c b/applications/main/subghz/scenes/subghz_scene_rpc.c index ef718c4e1..edadc89bb 100644 --- a/applications/main/subghz/scenes/subghz_scene_rpc.c +++ b/applications/main/subghz/scenes/subghz_scene_rpc.c @@ -110,10 +110,5 @@ void subghz_scene_rpc_on_exit(void* context) { popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop); popup_set_icon(popup, 0, 0, NULL); - keeloq_reset_mfname(); - keeloq_reset_kl_type(); - keeloq_reset_original_btn(); - subghz_custom_btns_reset(); - star_line_reset_mfname(); - star_line_reset_kl_type(); + subghz_txrx_reset_dynamic(subghz->txrx); } diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index 15a53603d..933f619f0 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -107,10 +107,6 @@ bool subghz_scene_transmitter_on_event(void* context, SceneManagerEvent event) { void subghz_scene_transmitter_on_exit(void* context) { SubGhz* subghz = context; subghz->state_notifications = SubGhzNotificationStateIDLE; - keeloq_reset_mfname(); - keeloq_reset_kl_type(); - keeloq_reset_original_btn(); - subghz_custom_btns_reset(); - star_line_reset_mfname(); - star_line_reset_kl_type(); + + subghz_txrx_reset_dynamic(subghz->txrx); } diff --git a/applications/main/subghz_remote/subghz_remote_app_i.c b/applications/main/subghz_remote/subghz_remote_app_i.c index 349fb87cd..6086b4c25 100644 --- a/applications/main/subghz_remote/subghz_remote_app_i.c +++ b/applications/main/subghz_remote/subghz_remote_app_i.c @@ -256,12 +256,9 @@ bool subrem_tx_stop_sub(SubGhzRemoteApp* app, bool forced) { subrem_save_protocol_to_file( sub_preset->fff_data, furi_string_get_cstr(sub_preset->file_path)); - keeloq_reset_mfname(); - keeloq_reset_kl_type(); + subghz_environment_reset_keeloq(app->environment); keeloq_reset_original_btn(); subghz_custom_btns_reset(); - star_line_reset_mfname(); - star_line_reset_kl_type(); } app->tx_running = false; diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index 84d0beda8..ddda9dcba 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.5,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/cli/cli.h,, Header,+,applications/services/cli/cli_vcp.h,, @@ -2731,7 +2731,11 @@ Function,+,subghz_environment_get_keystore,SubGhzKeystore*,SubGhzEnvironment* Function,+,subghz_environment_get_nice_flor_s_rainbow_table_file_name,const char*,SubGhzEnvironment* Function,+,subghz_environment_get_protocol_name_registry,const char*,"SubGhzEnvironment*, size_t" Function,+,subghz_environment_get_protocol_registry,void*,SubGhzEnvironment* +Function,-,subghz_environment_keeloq_get_kl_type,uint8_t,SubGhzEnvironment* +Function,-,subghz_environment_keeloq_get_mf,const char*,SubGhzEnvironment* +Function,-,subghz_environment_keeloq_set_mf,void,"SubGhzEnvironment*, const char*, uint8_t" Function,+,subghz_environment_load_keystore,_Bool,"SubGhzEnvironment*, const char*" +Function,+,subghz_environment_reset_keeloq,void,SubGhzEnvironment* Function,+,subghz_environment_set_alutech_at_4n_rainbow_table_file_name,void,"SubGhzEnvironment*, const char*" Function,+,subghz_environment_set_came_atomo_rainbow_table_file_name,void,"SubGhzEnvironment*, const char*" Function,+,subghz_environment_set_nice_flor_s_rainbow_table_file_name,void,"SubGhzEnvironment*, const char*" diff --git a/lib/subghz/environment.c b/lib/subghz/environment.c index 5ded243c4..55caedb6d 100644 --- a/lib/subghz/environment.c +++ b/lib/subghz/environment.c @@ -7,6 +7,8 @@ struct SubGhzEnvironment { const char* came_atomo_rainbow_table_file_name; const char* nice_flor_s_rainbow_table_file_name; const char* alutech_at_4n_rainbow_table_file_name; + const char* mfname; + uint8_t kl_type; }; SubGhzEnvironment* subghz_environment_alloc() { @@ -17,6 +19,8 @@ SubGhzEnvironment* subghz_environment_alloc() { instance->came_atomo_rainbow_table_file_name = NULL; instance->nice_flor_s_rainbow_table_file_name = NULL; instance->alutech_at_4n_rainbow_table_file_name = NULL; + instance->mfname = ""; + instance->kl_type = 0; return instance; } @@ -115,4 +119,30 @@ const char* } else { return NULL; } +} + +void subghz_environment_reset_keeloq(SubGhzEnvironment* instance) { + furi_assert(instance); + + instance->mfname = ""; + instance->kl_type = 0; +} + +const char* subghz_environment_keeloq_get_mf(SubGhzEnvironment* instance) { + furi_assert(instance); + + return instance->mfname; +} + +uint8_t subghz_environment_keeloq_get_kl_type(SubGhzEnvironment* instance) { + furi_assert(instance); + + return instance->kl_type; +} + +void subghz_environment_keeloq_set_mf(SubGhzEnvironment* instance, const char* mf, uint8_t kl_type) { + furi_assert(instance); + + instance->mfname = mf; + instance->kl_type = kl_type; } \ No newline at end of file diff --git a/lib/subghz/environment.h b/lib/subghz/environment.h index 7bd38ba2f..a23341e2f 100644 --- a/lib/subghz/environment.h +++ b/lib/subghz/environment.h @@ -110,6 +110,18 @@ void* subghz_environment_get_protocol_registry(SubGhzEnvironment* instance); */ const char* subghz_environment_get_protocol_name_registry(SubGhzEnvironment* instance, size_t idx); +/** + * Resetting the parameters used in the keeloq protocol. + * @param instance Pointer to a SubGhzEnvironment instance + */ +void subghz_environment_reset_keeloq(SubGhzEnvironment* instance); + +// Private + +const char* subghz_environment_keeloq_get_mf(SubGhzEnvironment* instance); +uint8_t subghz_environment_keeloq_get_kl_type(SubGhzEnvironment* instance); +void subghz_environment_keeloq_set_mf(SubGhzEnvironment* instance, const char* mf, uint8_t kl_type); + #ifdef __cplusplus } #endif diff --git a/lib/subghz/protocols/keeloq.c b/lib/subghz/protocols/keeloq.c index 26b5a20a9..0d151e68f 100644 --- a/lib/subghz/protocols/keeloq.c +++ b/lib/subghz/protocols/keeloq.c @@ -89,26 +89,20 @@ const SubGhzProtocol subghz_protocol_keeloq = { .decoder = &subghz_protocol_keeloq_decoder, .encoder = &subghz_protocol_keeloq_encoder, }; - -static const char* mfname; -static uint8_t kl_type; +// TODO: +// static const char* mfname; +// static uint8_t kl_type; static uint8_t klq_prog_mode; static uint16_t temp_counter; +static SubGhzEnvironment* kl_environment; + void keeloq_reset_original_btn() { subghz_custom_btns_reset(); temp_counter = 0; klq_prog_mode = KEELOQ_PROG_MODE_OFF; } -void keeloq_reset_mfname() { - mfname = ""; -} - -void keeloq_reset_kl_type() { - kl_type = 0; -} - /** * Analysis of received data * @param instance Pointer to a SubGhzBlockGeneric* instance @@ -127,6 +121,8 @@ void* subghz_protocol_encoder_keeloq_alloc(SubGhzEnvironment* environment) { instance->generic.protocol_name = instance->base.protocol->name; instance->keystore = subghz_environment_get_keystore(environment); + kl_environment = environment; + instance->encoder.repeat = 100; instance->encoder.size_upload = 256; instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration)); @@ -252,7 +248,7 @@ static bool subghz_protocol_keeloq_gen_data( decrypt = btn << 28 | (0x000) << 16 | instance->generic.cnt; // Beninca / Allmatic -> no serial - simple XOR } - + uint8_t kl_type_en = subghz_environment_keeloq_get_kl_type(kl_environment); for M_EACH( manufacture_code, @@ -292,21 +288,21 @@ static bool subghz_protocol_keeloq_gen_data( hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); break; case KEELOQ_LEARNING_UNKNOWN: - if(kl_type == 1) { + if(kl_type_en == 1) { hop = subghz_protocol_keeloq_common_encrypt( decrypt, manufacture_code->key); } - if(kl_type == 2) { + if(kl_type_en == 2) { man = subghz_protocol_keeloq_common_normal_learning( fix, manufacture_code->key); hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); } - if(kl_type == 3) { + if(kl_type_en == 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) { + if(kl_type_en == 4) { man = subghz_protocol_keeloq_common_magic_xor_type1_learning( instance->generic.serial, manufacture_code->key); hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); @@ -507,7 +503,15 @@ SubGhzProtocolStatus if(flipper_format_read_string( flipper_format, "Manufacture", instance->manufacture_from_file)) { instance->manufacture_name = furi_string_get_cstr(instance->manufacture_from_file); - mfname = furi_string_get_cstr(instance->manufacture_from_file); + subghz_environment_keeloq_set_mf( + kl_environment, + furi_string_get_cstr(instance->manufacture_from_file), + subghz_environment_keeloq_get_kl_type(kl_environment)); + // TODO: + FURI_LOG_W( + "MF encoder", + "Alloc enviro 0x%X", + (uintptr_t)subghz_environment_keeloq_get_mf(kl_environment)); } else { FURI_LOG_D(TAG, "ENCODER: Missing Manufacture"); } @@ -579,6 +583,7 @@ void* subghz_protocol_decoder_keeloq_alloc(SubGhzEnvironment* environment) { instance->keystore = subghz_environment_get_keystore(environment); instance->manufacture_from_file = furi_string_alloc(); + kl_environment = environment; klq_prog_mode = KEELOQ_PROG_MODE_OFF; return instance; @@ -596,8 +601,7 @@ void subghz_protocol_decoder_keeloq_reset(void* context) { furi_assert(context); SubGhzProtocolDecoderKeeloq* instance = context; instance->decoder.parser_step = KeeloqDecoderStepReset; - mfname = ""; - kl_type = 0; + subghz_environment_reset_keeloq(kl_environment); } void subghz_protocol_decoder_keeloq_feed(void* context, bool level, uint32_t duration) { @@ -740,9 +744,15 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( uint32_t decrypt = 0; uint64_t man; bool mf_not_set = false; - if(mfname == 0x0) { - mfname = ""; - } + // TODO: + // if(mfname == 0x0) { + // mfname = ""; + // } + + const char* mfname = subghz_environment_keeloq_get_mf(kl_environment); + uint8_t kl_type_en = subghz_environment_keeloq_get_kl_type(kl_environment); + // TODO: + FURI_LOG_W("RMcontroll", "MF NAME: %s", mfname); if(strcmp(mfname, "Unknown") == 0) { return 1; @@ -758,7 +768,8 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf( + kl_environment, *manufacture_name, kl_type_en); return 1; } break; @@ -770,7 +781,8 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf( + kl_environment, *manufacture_name, kl_type_en); return 1; } break; @@ -780,7 +792,8 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf( + kl_environment, *manufacture_name, kl_type_en); return 1; } break; @@ -790,7 +803,8 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf( + kl_environment, *manufacture_name, kl_type_en); return 1; } break; @@ -800,7 +814,8 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf( + kl_environment, *manufacture_name, kl_type_en); return 1; } break; @@ -810,7 +825,8 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf( + kl_environment, *manufacture_name, kl_type_en); return 1; } break; @@ -820,7 +836,8 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf( + kl_environment, *manufacture_name, kl_type_en); return 1; } break; @@ -829,8 +846,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 1); return 1; } @@ -845,8 +861,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 1); return 1; } @@ -858,8 +873,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 2); return 1; } @@ -868,8 +882,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 2); return 1; } @@ -879,8 +892,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 3); return 1; } @@ -890,8 +902,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 3); return 1; } @@ -901,8 +912,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 4); return 1; } @@ -911,8 +921,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 4); return 1; } @@ -922,7 +931,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( } *manufacture_name = "Unknown"; - mfname = "Unknown"; + subghz_environment_keeloq_set_mf(kl_environment, "Unknown", kl_type_en); instance->cnt = 0; return 0; @@ -935,6 +944,7 @@ static void subghz_protocol_keeloq_check_remote_controller( uint64_t key = subghz_protocol_blocks_reverse_key(instance->data, instance->data_count_bit); uint32_t key_fix = key >> 32; uint32_t key_hop = key & 0x00000000ffffffff; + uint8_t kl_type_en = subghz_environment_keeloq_get_kl_type(kl_environment); // 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) { @@ -942,11 +952,11 @@ static void subghz_protocol_keeloq_check_remote_controller( if((key_hop >> 24) == ((key_hop >> 16) & 0x00ff) && (key_fix >> 28) == ((key_hop >> 12) & 0x0f) && (key_hop & 0xFFF) == 0x404) { *manufacture_name = "AN-Motors"; - mfname = *manufacture_name; + subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, kl_type_en); instance->cnt = key_hop >> 16; } else if((key_hop & 0xFFF) == (0x000) && (key_fix >> 28) == ((key_hop >> 12) & 0x0f)) { *manufacture_name = "HCS101"; - mfname = *manufacture_name; + subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, kl_type_en); instance->cnt = key_hop >> 16; } else { subghz_protocol_keeloq_check_remote_controller_selector( @@ -956,11 +966,11 @@ static void subghz_protocol_keeloq_check_remote_controller( } else if(klq_prog_mode == KEELOQ_PROG_MODE_BFT) { *manufacture_name = "BFT"; - mfname = *manufacture_name; + subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, kl_type_en); instance->cnt = temp_counter; } else if(klq_prog_mode == KEELOQ_PROG_MODE_APRIMATIC) { *manufacture_name = "Aprimatic"; - mfname = *manufacture_name; + subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, kl_type_en); instance->cnt = temp_counter; } @@ -1052,7 +1062,15 @@ SubGhzProtocolStatus if(flipper_format_read_string( flipper_format, "Manufacture", instance->manufacture_from_file)) { instance->manufacture_name = furi_string_get_cstr(instance->manufacture_from_file); - mfname = furi_string_get_cstr(instance->manufacture_from_file); + subghz_environment_keeloq_set_mf( + kl_environment, + furi_string_get_cstr(instance->manufacture_from_file), + subghz_environment_keeloq_get_kl_type(kl_environment)); + // TODO: + FURI_LOG_W( + "MF decoder", + "Alloc enviro 0x%X", + (uintptr_t)subghz_environment_keeloq_get_mf(kl_environment)); } else { FURI_LOG_D(TAG, "DECODER: Missing Manufacture"); } diff --git a/lib/subghz/protocols/keeloq.h b/lib/subghz/protocols/keeloq.h index 9862e0e92..26f569e8c 100644 --- a/lib/subghz/protocols/keeloq.h +++ b/lib/subghz/protocols/keeloq.h @@ -13,10 +13,6 @@ extern const SubGhzProtocolDecoder subghz_protocol_keeloq_decoder; extern const SubGhzProtocolEncoder subghz_protocol_keeloq_encoder; extern const SubGhzProtocol subghz_protocol_keeloq; -void keeloq_reset_mfname(); - -void keeloq_reset_kl_type(); - void keeloq_reset_original_btn(); /** diff --git a/lib/subghz/protocols/star_line.c b/lib/subghz/protocols/star_line.c index 362e34f3c..64d9bef80 100644 --- a/lib/subghz/protocols/star_line.c +++ b/lib/subghz/protocols/star_line.c @@ -82,18 +82,12 @@ const SubGhzProtocol subghz_protocol_star_line = { .decoder = &subghz_protocol_star_line_decoder, .encoder = &subghz_protocol_star_line_encoder, }; +// TODO: +// static const char* mfname; -static const char* mfname; +// static int kl_type; -static int kl_type; - -void star_line_reset_mfname() { - mfname = ""; -} - -void star_line_reset_kl_type() { - kl_type = 0; -} +static SubGhzEnvironment* kl_environment; /** * Analysis of received data @@ -113,6 +107,8 @@ void* subghz_protocol_encoder_star_line_alloc(SubGhzEnvironment* environment) { instance->generic.protocol_name = instance->base.protocol->name; instance->keystore = subghz_environment_get_keystore(environment); + kl_environment = environment; + instance->manufacture_from_file = furi_string_alloc(); instance->encoder.repeat = 10; @@ -163,6 +159,7 @@ static bool instance->generic.data, instance->generic.data_count_bit); hop = code_found_reverse & 0x00000000ffffffff; } else { + uint8_t kl_type_en = subghz_environment_keeloq_get_kl_type(kl_environment); for M_EACH( manufacture_code, @@ -184,11 +181,11 @@ static bool hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); break; case KEELOQ_LEARNING_UNKNOWN: - if(kl_type == 1) { + if(kl_type_en == 1) { hop = subghz_protocol_keeloq_common_encrypt( decrypt, manufacture_code->key); } - if(kl_type == 2) { + if(kl_type_en == 2) { man = subghz_protocol_keeloq_common_normal_learning( fix, manufacture_code->key); hop = subghz_protocol_keeloq_common_encrypt(decrypt, man); @@ -300,7 +297,15 @@ SubGhzProtocolStatus if(flipper_format_read_string( flipper_format, "Manufacture", instance->manufacture_from_file)) { instance->manufacture_name = furi_string_get_cstr(instance->manufacture_from_file); - mfname = furi_string_get_cstr(instance->manufacture_from_file); + subghz_environment_keeloq_set_mf( + kl_environment, + furi_string_get_cstr(instance->manufacture_from_file), + subghz_environment_keeloq_get_kl_type(kl_environment)); + // TODO: + FURI_LOG_W( + "MF encoder", + "Alloc enviro 0x%X", + (uintptr_t)subghz_environment_keeloq_get_mf(kl_environment)); } else { FURI_LOG_D(TAG, "ENCODER: Missing Manufacture"); } @@ -366,6 +371,7 @@ void* subghz_protocol_decoder_star_line_alloc(SubGhzEnvironment* environment) { instance->manufacture_from_file = furi_string_alloc(); instance->keystore = subghz_environment_get_keystore(environment); + kl_environment = environment; return instance; } @@ -382,8 +388,7 @@ void subghz_protocol_decoder_star_line_reset(void* context) { furi_assert(context); SubGhzProtocolDecoderStarLine* instance = context; instance->decoder.parser_step = StarLineDecoderStepReset; - mfname = ""; - kl_type = 0; + subghz_environment_reset_keeloq(kl_environment); } void subghz_protocol_decoder_star_line_feed(void* context, bool level, uint32_t duration) { @@ -523,9 +528,15 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( uint32_t decrypt = 0; uint64_t man_normal_learning; bool mf_not_set = false; - if(mfname == 0x0) { - mfname = ""; - } + // TODO: + // if(mfname == 0x0) { + // mfname = ""; + // } + + const char* mfname = subghz_environment_keeloq_get_mf(kl_environment); + uint8_t kl_type_en = subghz_environment_keeloq_get_kl_type(kl_environment); + // TODO: + FURI_LOG_W("RMcontroll", "MF NAME: %s", mfname); if(strcmp(mfname, "Unknown") == 0) { return 1; @@ -542,7 +553,8 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( if(subghz_protocol_star_line_check_decrypt( instance, decrypt, btn, end_serial)) { *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; + subghz_environment_keeloq_set_mf( + kl_environment, *manufacture_name, kl_type_en); return 1; } break; @@ -555,7 +567,8 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( if(subghz_protocol_star_line_check_decrypt( instance, decrypt, btn, end_serial)) { *manufacture_name = furi_string_get_cstr(manufacture_code->name); - mfname = *manufacture_name; + subghz_environment_keeloq_set_mf( + kl_environment, *manufacture_name, kl_type_en); return 1; } break; @@ -565,8 +578,7 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 1); return 1; } // Check for mirrored man @@ -580,8 +592,7 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 1); return 1; } //########################### @@ -593,8 +604,7 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 2); return 1; } // Check for mirrored man @@ -604,8 +614,7 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( 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; + subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 2); return 1; } break; @@ -614,7 +623,7 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( } *manufacture_name = "Unknown"; - mfname = "Unknown"; + subghz_environment_keeloq_set_mf(kl_environment, "Unknown", kl_type_en); instance->cnt = 0; return 0; @@ -690,7 +699,15 @@ SubGhzProtocolStatus if(flipper_format_read_string( flipper_format, "Manufacture", instance->manufacture_from_file)) { instance->manufacture_name = furi_string_get_cstr(instance->manufacture_from_file); - mfname = furi_string_get_cstr(instance->manufacture_from_file); + subghz_environment_keeloq_set_mf( + kl_environment, + furi_string_get_cstr(instance->manufacture_from_file), + subghz_environment_keeloq_get_kl_type(kl_environment)); + // TODO: + FURI_LOG_W( + "MF decoder", + "Alloc enviro 0x%X", + (uintptr_t)subghz_environment_keeloq_get_mf(kl_environment)); } else { FURI_LOG_D(TAG, "DECODER: Missing Manufacture"); } From 230965612087afc3a9c67312d32040b16fd6ba3a Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 20 May 2023 01:19:13 +0300 Subject: [PATCH 2/9] clean up --- lib/subghz/protocols/keeloq.c | 16 +--------------- lib/subghz/protocols/star_line.c | 16 ---------------- 2 files changed, 1 insertion(+), 31 deletions(-) diff --git a/lib/subghz/protocols/keeloq.c b/lib/subghz/protocols/keeloq.c index 0d151e68f..94126c4e7 100644 --- a/lib/subghz/protocols/keeloq.c +++ b/lib/subghz/protocols/keeloq.c @@ -89,9 +89,7 @@ const SubGhzProtocol subghz_protocol_keeloq = { .decoder = &subghz_protocol_keeloq_decoder, .encoder = &subghz_protocol_keeloq_encoder, }; -// TODO: -// static const char* mfname; -// static uint8_t kl_type; + static uint8_t klq_prog_mode; static uint16_t temp_counter; @@ -507,11 +505,6 @@ SubGhzProtocolStatus kl_environment, furi_string_get_cstr(instance->manufacture_from_file), subghz_environment_keeloq_get_kl_type(kl_environment)); - // TODO: - FURI_LOG_W( - "MF encoder", - "Alloc enviro 0x%X", - (uintptr_t)subghz_environment_keeloq_get_mf(kl_environment)); } else { FURI_LOG_D(TAG, "ENCODER: Missing Manufacture"); } @@ -751,8 +744,6 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( const char* mfname = subghz_environment_keeloq_get_mf(kl_environment); uint8_t kl_type_en = subghz_environment_keeloq_get_kl_type(kl_environment); - // TODO: - FURI_LOG_W("RMcontroll", "MF NAME: %s", mfname); if(strcmp(mfname, "Unknown") == 0) { return 1; @@ -1066,11 +1057,6 @@ SubGhzProtocolStatus kl_environment, furi_string_get_cstr(instance->manufacture_from_file), subghz_environment_keeloq_get_kl_type(kl_environment)); - // TODO: - FURI_LOG_W( - "MF decoder", - "Alloc enviro 0x%X", - (uintptr_t)subghz_environment_keeloq_get_mf(kl_environment)); } else { FURI_LOG_D(TAG, "DECODER: Missing Manufacture"); } diff --git a/lib/subghz/protocols/star_line.c b/lib/subghz/protocols/star_line.c index 64d9bef80..4b5412c39 100644 --- a/lib/subghz/protocols/star_line.c +++ b/lib/subghz/protocols/star_line.c @@ -82,10 +82,6 @@ const SubGhzProtocol subghz_protocol_star_line = { .decoder = &subghz_protocol_star_line_decoder, .encoder = &subghz_protocol_star_line_encoder, }; -// TODO: -// static const char* mfname; - -// static int kl_type; static SubGhzEnvironment* kl_environment; @@ -301,11 +297,6 @@ SubGhzProtocolStatus kl_environment, furi_string_get_cstr(instance->manufacture_from_file), subghz_environment_keeloq_get_kl_type(kl_environment)); - // TODO: - FURI_LOG_W( - "MF encoder", - "Alloc enviro 0x%X", - (uintptr_t)subghz_environment_keeloq_get_mf(kl_environment)); } else { FURI_LOG_D(TAG, "ENCODER: Missing Manufacture"); } @@ -535,8 +526,6 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( const char* mfname = subghz_environment_keeloq_get_mf(kl_environment); uint8_t kl_type_en = subghz_environment_keeloq_get_kl_type(kl_environment); - // TODO: - FURI_LOG_W("RMcontroll", "MF NAME: %s", mfname); if(strcmp(mfname, "Unknown") == 0) { return 1; @@ -703,11 +692,6 @@ SubGhzProtocolStatus kl_environment, furi_string_get_cstr(instance->manufacture_from_file), subghz_environment_keeloq_get_kl_type(kl_environment)); - // TODO: - FURI_LOG_W( - "MF decoder", - "Alloc enviro 0x%X", - (uintptr_t)subghz_environment_keeloq_get_mf(kl_environment)); } else { FURI_LOG_D(TAG, "DECODER: Missing Manufacture"); } From 2af8f00d0df40915e3b574166c674709334c8a19 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 20 May 2023 01:25:05 +0300 Subject: [PATCH 3/9] fix --- firmware/targets/f7/api_symbols.csv | 4 ---- lib/subghz/protocols/star_line.h | 4 ---- 2 files changed, 8 deletions(-) diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index ddda9dcba..441352021 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1825,8 +1825,6 @@ Function,-,j1f,float,float Function,-,jn,double,"int, double" Function,-,jnf,float,"int, float" Function,-,jrand48,long,unsigned short[3] -Function,-,keeloq_reset_kl_type,void, -Function,-,keeloq_reset_mfname,void, Function,-,keeloq_reset_original_btn,void, Function,-,l64a,char*,long Function,-,labs,long,long @@ -2568,8 +2566,6 @@ Function,+,srand,void,unsigned Function,-,srand48,void,long Function,-,srandom,void,unsigned Function,+,sscanf,int,"const char*, const char*, ..." -Function,-,star_line_reset_kl_type,void, -Function,-,star_line_reset_mfname,void, Function,+,storage_common_copy,FS_Error,"Storage*, const char*, const char*" Function,+,storage_common_exists,_Bool,"Storage*, const char*" Function,+,storage_common_fs_info,FS_Error,"Storage*, const char*, uint64_t*, uint64_t*" diff --git a/lib/subghz/protocols/star_line.h b/lib/subghz/protocols/star_line.h index 901b82f7c..851819ec7 100644 --- a/lib/subghz/protocols/star_line.h +++ b/lib/subghz/protocols/star_line.h @@ -11,10 +11,6 @@ extern const SubGhzProtocolDecoder subghz_protocol_star_line_decoder; extern const SubGhzProtocolEncoder subghz_protocol_star_line_encoder; extern const SubGhzProtocol subghz_protocol_star_line; -void star_line_reset_mfname(); - -void star_line_reset_kl_type(); - /** * Allocate SubGhzProtocolEncoderStarLine. * @param environment Pointer to a SubGhzEnvironment instance From 2414346ec3f217610c0043a3093061fab51a4a30 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sat, 20 May 2023 16:15:01 +0300 Subject: [PATCH 4/9] keeloq to kestore --- .../main/subghz/helpers/subghz_txrx.c | 2 + firmware/targets/f7/api_symbols.csv | 6 +- lib/subghz/environment.c | 22 +---- lib/subghz/environment.h | 6 -- lib/subghz/protocols/keeloq.c | 81 +++++++++---------- lib/subghz/protocols/star_line.c | 46 +++++------ lib/subghz/subghz_keystore.c | 14 +++- lib/subghz/subghz_keystore.h | 2 + lib/subghz/subghz_keystore_i.h | 9 +++ 9 files changed, 83 insertions(+), 105 deletions(-) create mode 100644 lib/subghz/subghz_keystore_i.h diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index c2d7e1bf5..9d957cd29 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -560,6 +560,8 @@ bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance) { void subghz_txrx_reset_dynamic(SubGhzTxRx* instance) { furi_assert(instance); subghz_environment_reset_keeloq(instance->environment); + + keeloq_reset_original_btn(); subghz_custom_btns_reset(); } diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index 441352021..1e00e181c 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.5,, +Version,+,26.6,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/cli/cli.h,, Header,+,applications/services/cli/cli_vcp.h,, @@ -2727,9 +2727,6 @@ Function,+,subghz_environment_get_keystore,SubGhzKeystore*,SubGhzEnvironment* Function,+,subghz_environment_get_nice_flor_s_rainbow_table_file_name,const char*,SubGhzEnvironment* Function,+,subghz_environment_get_protocol_name_registry,const char*,"SubGhzEnvironment*, size_t" Function,+,subghz_environment_get_protocol_registry,void*,SubGhzEnvironment* -Function,-,subghz_environment_keeloq_get_kl_type,uint8_t,SubGhzEnvironment* -Function,-,subghz_environment_keeloq_get_mf,const char*,SubGhzEnvironment* -Function,-,subghz_environment_keeloq_set_mf,void,"SubGhzEnvironment*, const char*, uint8_t" Function,+,subghz_environment_load_keystore,_Bool,"SubGhzEnvironment*, const char*" Function,+,subghz_environment_reset_keeloq,void,SubGhzEnvironment* Function,+,subghz_environment_set_alutech_at_4n_rainbow_table_file_name,void,"SubGhzEnvironment*, const char*" @@ -2742,6 +2739,7 @@ Function,-,subghz_keystore_get_data,SubGhzKeyArray_t*,SubGhzKeystore* Function,-,subghz_keystore_load,_Bool,"SubGhzKeystore*, const char*" Function,-,subghz_keystore_raw_encrypted_save,_Bool,"const char*, const char*, uint8_t*" Function,-,subghz_keystore_raw_get_data,_Bool,"const char*, size_t, uint8_t*, size_t" +Function,-,subghz_keystore_reset_kl,void,SubGhzKeystore* Function,-,subghz_keystore_save,_Bool,"SubGhzKeystore*, const char*, uint8_t*" Function,-,subghz_protocol_alutech_at_4n_create_data,_Bool,"void*, FlipperFormat*, uint32_t, uint8_t, uint16_t, SubGhzRadioPreset*" Function,+,subghz_protocol_blocks_add_bit,void,"SubGhzBlockDecoder*, uint8_t" diff --git a/lib/subghz/environment.c b/lib/subghz/environment.c index 55caedb6d..bcada8752 100644 --- a/lib/subghz/environment.c +++ b/lib/subghz/environment.c @@ -124,25 +124,5 @@ const char* void subghz_environment_reset_keeloq(SubGhzEnvironment* instance) { furi_assert(instance); - instance->mfname = ""; - instance->kl_type = 0; + subghz_keystore_reset_kl(instance->keystore); } - -const char* subghz_environment_keeloq_get_mf(SubGhzEnvironment* instance) { - furi_assert(instance); - - return instance->mfname; -} - -uint8_t subghz_environment_keeloq_get_kl_type(SubGhzEnvironment* instance) { - furi_assert(instance); - - return instance->kl_type; -} - -void subghz_environment_keeloq_set_mf(SubGhzEnvironment* instance, const char* mf, uint8_t kl_type) { - furi_assert(instance); - - instance->mfname = mf; - instance->kl_type = kl_type; -} \ No newline at end of file diff --git a/lib/subghz/environment.h b/lib/subghz/environment.h index a23341e2f..67de48df9 100644 --- a/lib/subghz/environment.h +++ b/lib/subghz/environment.h @@ -116,12 +116,6 @@ const char* subghz_environment_get_protocol_name_registry(SubGhzEnvironment* ins */ void subghz_environment_reset_keeloq(SubGhzEnvironment* instance); -// Private - -const char* subghz_environment_keeloq_get_mf(SubGhzEnvironment* instance); -uint8_t subghz_environment_keeloq_get_kl_type(SubGhzEnvironment* instance); -void subghz_environment_keeloq_set_mf(SubGhzEnvironment* instance, const char* mf, uint8_t kl_type); - #ifdef __cplusplus } #endif diff --git a/lib/subghz/protocols/keeloq.c b/lib/subghz/protocols/keeloq.c index 94126c4e7..df7ae748d 100644 --- a/lib/subghz/protocols/keeloq.c +++ b/lib/subghz/protocols/keeloq.c @@ -11,6 +11,7 @@ #include "../blocks/math.h" #include "../blocks/custom_btn.h" +#include "../subghz_keystore_i.h" #define TAG "SubGhzProtocolKeeloq" @@ -93,8 +94,6 @@ const SubGhzProtocol subghz_protocol_keeloq = { static uint8_t klq_prog_mode; static uint16_t temp_counter; -static SubGhzEnvironment* kl_environment; - void keeloq_reset_original_btn() { subghz_custom_btns_reset(); temp_counter = 0; @@ -119,8 +118,6 @@ void* subghz_protocol_encoder_keeloq_alloc(SubGhzEnvironment* environment) { instance->generic.protocol_name = instance->base.protocol->name; instance->keystore = subghz_environment_get_keystore(environment); - kl_environment = environment; - instance->encoder.repeat = 100; instance->encoder.size_upload = 256; instance->encoder.upload = malloc(instance->encoder.size_upload * sizeof(LevelDuration)); @@ -246,7 +243,7 @@ static bool subghz_protocol_keeloq_gen_data( decrypt = btn << 28 | (0x000) << 16 | instance->generic.cnt; // Beninca / Allmatic -> no serial - simple XOR } - uint8_t kl_type_en = subghz_environment_keeloq_get_kl_type(kl_environment); + uint8_t kl_type_en = instance->keystore->kl_type; for M_EACH( manufacture_code, @@ -501,10 +498,7 @@ SubGhzProtocolStatus if(flipper_format_read_string( flipper_format, "Manufacture", instance->manufacture_from_file)) { instance->manufacture_name = furi_string_get_cstr(instance->manufacture_from_file); - subghz_environment_keeloq_set_mf( - kl_environment, - furi_string_get_cstr(instance->manufacture_from_file), - subghz_environment_keeloq_get_kl_type(kl_environment)); + instance->keystore->mfname = instance->manufacture_name; } else { FURI_LOG_D(TAG, "ENCODER: Missing Manufacture"); } @@ -576,7 +570,6 @@ void* subghz_protocol_decoder_keeloq_alloc(SubGhzEnvironment* environment) { instance->keystore = subghz_environment_get_keystore(environment); instance->manufacture_from_file = furi_string_alloc(); - kl_environment = environment; klq_prog_mode = KEELOQ_PROG_MODE_OFF; return instance; @@ -594,7 +587,9 @@ void subghz_protocol_decoder_keeloq_reset(void* context) { furi_assert(context); SubGhzProtocolDecoderKeeloq* instance = context; instance->decoder.parser_step = KeeloqDecoderStepReset; - subghz_environment_reset_keeloq(kl_environment); + // TODO + instance->keystore->mfname = ""; + instance->keystore->kl_type = 0; } void subghz_protocol_decoder_keeloq_feed(void* context, bool level, uint32_t duration) { @@ -742,8 +737,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( // mfname = ""; // } - const char* mfname = subghz_environment_keeloq_get_mf(kl_environment); - uint8_t kl_type_en = subghz_environment_keeloq_get_kl_type(kl_environment); + const char* mfname = keystore->mfname; if(strcmp(mfname, "Unknown") == 0) { return 1; @@ -759,8 +753,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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); - subghz_environment_keeloq_set_mf( - kl_environment, *manufacture_name, kl_type_en); + keystore->mfname = *manufacture_name; return 1; } break; @@ -772,8 +765,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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); - subghz_environment_keeloq_set_mf( - kl_environment, *manufacture_name, kl_type_en); + keystore->mfname = *manufacture_name; return 1; } break; @@ -783,8 +775,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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); - subghz_environment_keeloq_set_mf( - kl_environment, *manufacture_name, kl_type_en); + keystore->mfname = *manufacture_name; return 1; } break; @@ -794,8 +785,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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); - subghz_environment_keeloq_set_mf( - kl_environment, *manufacture_name, kl_type_en); + keystore->mfname = *manufacture_name; return 1; } break; @@ -805,8 +795,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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); - subghz_environment_keeloq_set_mf( - kl_environment, *manufacture_name, kl_type_en); + keystore->mfname = *manufacture_name; return 1; } break; @@ -816,8 +805,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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); - subghz_environment_keeloq_set_mf( - kl_environment, *manufacture_name, kl_type_en); + keystore->mfname = *manufacture_name; return 1; } break; @@ -827,8 +815,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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); - subghz_environment_keeloq_set_mf( - kl_environment, *manufacture_name, kl_type_en); + keystore->mfname = *manufacture_name; return 1; } break; @@ -837,7 +824,8 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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); - subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 1); + keystore->mfname = *manufacture_name; + keystore->kl_type = 1; return 1; } @@ -852,7 +840,8 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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); - subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 1); + keystore->mfname = *manufacture_name; + keystore->kl_type = 1; return 1; } @@ -864,7 +853,8 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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); - subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 2); + keystore->mfname = *manufacture_name; + keystore->kl_type = 2; return 1; } @@ -873,7 +863,8 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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); - subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 2); + keystore->mfname = *manufacture_name; + keystore->kl_type = 2; return 1; } @@ -883,7 +874,8 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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); - subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 3); + keystore->mfname = *manufacture_name; + keystore->kl_type = 3; return 1; } @@ -893,7 +885,8 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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); - subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 3); + keystore->mfname = *manufacture_name; + keystore->kl_type = 3; return 1; } @@ -903,7 +896,8 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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); - subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 4); + keystore->mfname = *manufacture_name; + keystore->kl_type = 4; return 1; } @@ -912,7 +906,8 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( 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); - subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 4); + keystore->mfname = *manufacture_name; + keystore->kl_type = 4; return 1; } @@ -922,7 +917,7 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( } *manufacture_name = "Unknown"; - subghz_environment_keeloq_set_mf(kl_environment, "Unknown", kl_type_en); + keystore->mfname = "Unknown"; instance->cnt = 0; return 0; @@ -935,7 +930,6 @@ static void subghz_protocol_keeloq_check_remote_controller( uint64_t key = subghz_protocol_blocks_reverse_key(instance->data, instance->data_count_bit); uint32_t key_fix = key >> 32; uint32_t key_hop = key & 0x00000000ffffffff; - uint8_t kl_type_en = subghz_environment_keeloq_get_kl_type(kl_environment); // 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) { @@ -943,11 +937,11 @@ static void subghz_protocol_keeloq_check_remote_controller( if((key_hop >> 24) == ((key_hop >> 16) & 0x00ff) && (key_fix >> 28) == ((key_hop >> 12) & 0x0f) && (key_hop & 0xFFF) == 0x404) { *manufacture_name = "AN-Motors"; - subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, kl_type_en); + keystore->mfname = *manufacture_name; instance->cnt = key_hop >> 16; } else if((key_hop & 0xFFF) == (0x000) && (key_fix >> 28) == ((key_hop >> 12) & 0x0f)) { *manufacture_name = "HCS101"; - subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, kl_type_en); + keystore->mfname = *manufacture_name; instance->cnt = key_hop >> 16; } else { subghz_protocol_keeloq_check_remote_controller_selector( @@ -957,11 +951,11 @@ static void subghz_protocol_keeloq_check_remote_controller( } else if(klq_prog_mode == KEELOQ_PROG_MODE_BFT) { *manufacture_name = "BFT"; - subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, kl_type_en); + keystore->mfname = *manufacture_name; instance->cnt = temp_counter; } else if(klq_prog_mode == KEELOQ_PROG_MODE_APRIMATIC) { *manufacture_name = "Aprimatic"; - subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, kl_type_en); + keystore->mfname = *manufacture_name; instance->cnt = temp_counter; } @@ -1053,10 +1047,7 @@ SubGhzProtocolStatus if(flipper_format_read_string( flipper_format, "Manufacture", instance->manufacture_from_file)) { instance->manufacture_name = furi_string_get_cstr(instance->manufacture_from_file); - subghz_environment_keeloq_set_mf( - kl_environment, - furi_string_get_cstr(instance->manufacture_from_file), - subghz_environment_keeloq_get_kl_type(kl_environment)); + instance->keystore->mfname = instance->manufacture_name; } else { FURI_LOG_D(TAG, "DECODER: Missing Manufacture"); } diff --git a/lib/subghz/protocols/star_line.c b/lib/subghz/protocols/star_line.c index 4b5412c39..05afd80a6 100644 --- a/lib/subghz/protocols/star_line.c +++ b/lib/subghz/protocols/star_line.c @@ -10,6 +10,8 @@ #include "../blocks/generic.h" #include "../blocks/math.h" +#include "../subghz_keystore_i.h" + #define TAG "SubGhzProtocolStarLine" static const SubGhzBlockConst subghz_protocol_star_line_const = { @@ -83,8 +85,6 @@ const SubGhzProtocol subghz_protocol_star_line = { .encoder = &subghz_protocol_star_line_encoder, }; -static SubGhzEnvironment* kl_environment; - /** * Analysis of received data * @param instance Pointer to a SubGhzBlockGeneric* instance @@ -103,8 +103,6 @@ void* subghz_protocol_encoder_star_line_alloc(SubGhzEnvironment* environment) { instance->generic.protocol_name = instance->base.protocol->name; instance->keystore = subghz_environment_get_keystore(environment); - kl_environment = environment; - instance->manufacture_from_file = furi_string_alloc(); instance->encoder.repeat = 10; @@ -155,7 +153,7 @@ static bool instance->generic.data, instance->generic.data_count_bit); hop = code_found_reverse & 0x00000000ffffffff; } else { - uint8_t kl_type_en = subghz_environment_keeloq_get_kl_type(kl_environment); + uint8_t kl_type_en = instance->keystore->kl_type; for M_EACH( manufacture_code, @@ -293,10 +291,7 @@ SubGhzProtocolStatus if(flipper_format_read_string( flipper_format, "Manufacture", instance->manufacture_from_file)) { instance->manufacture_name = furi_string_get_cstr(instance->manufacture_from_file); - subghz_environment_keeloq_set_mf( - kl_environment, - furi_string_get_cstr(instance->manufacture_from_file), - subghz_environment_keeloq_get_kl_type(kl_environment)); + instance->keystore->mfname = instance->manufacture_name; } else { FURI_LOG_D(TAG, "ENCODER: Missing Manufacture"); } @@ -362,7 +357,6 @@ void* subghz_protocol_decoder_star_line_alloc(SubGhzEnvironment* environment) { instance->manufacture_from_file = furi_string_alloc(); instance->keystore = subghz_environment_get_keystore(environment); - kl_environment = environment; return instance; } @@ -379,7 +373,9 @@ void subghz_protocol_decoder_star_line_reset(void* context) { furi_assert(context); SubGhzProtocolDecoderStarLine* instance = context; instance->decoder.parser_step = StarLineDecoderStepReset; - subghz_environment_reset_keeloq(kl_environment); + // TODO + instance->keystore->mfname = ""; + instance->keystore->kl_type = 0; } void subghz_protocol_decoder_star_line_feed(void* context, bool level, uint32_t duration) { @@ -524,8 +520,7 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( // mfname = ""; // } - const char* mfname = subghz_environment_keeloq_get_mf(kl_environment); - uint8_t kl_type_en = subghz_environment_keeloq_get_kl_type(kl_environment); + const char* mfname = keystore->mfname; if(strcmp(mfname, "Unknown") == 0) { return 1; @@ -542,8 +537,7 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( if(subghz_protocol_star_line_check_decrypt( instance, decrypt, btn, end_serial)) { *manufacture_name = furi_string_get_cstr(manufacture_code->name); - subghz_environment_keeloq_set_mf( - kl_environment, *manufacture_name, kl_type_en); + keystore->mfname = *manufacture_name; return 1; } break; @@ -556,8 +550,7 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( if(subghz_protocol_star_line_check_decrypt( instance, decrypt, btn, end_serial)) { *manufacture_name = furi_string_get_cstr(manufacture_code->name); - subghz_environment_keeloq_set_mf( - kl_environment, *manufacture_name, kl_type_en); + keystore->mfname = *manufacture_name; return 1; } break; @@ -567,7 +560,8 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( if(subghz_protocol_star_line_check_decrypt( instance, decrypt, btn, end_serial)) { *manufacture_name = furi_string_get_cstr(manufacture_code->name); - subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 1); + keystore->mfname = *manufacture_name; + keystore->kl_type = 1; return 1; } // Check for mirrored man @@ -581,7 +575,8 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( if(subghz_protocol_star_line_check_decrypt( instance, decrypt, btn, end_serial)) { *manufacture_name = furi_string_get_cstr(manufacture_code->name); - subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 1); + keystore->mfname = *manufacture_name; + keystore->kl_type = 1; return 1; } //########################### @@ -593,7 +588,8 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( if(subghz_protocol_star_line_check_decrypt( instance, decrypt, btn, end_serial)) { *manufacture_name = furi_string_get_cstr(manufacture_code->name); - subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 2); + keystore->mfname = *manufacture_name; + keystore->kl_type = 2; return 1; } // Check for mirrored man @@ -603,7 +599,8 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( if(subghz_protocol_star_line_check_decrypt( instance, decrypt, btn, end_serial)) { *manufacture_name = furi_string_get_cstr(manufacture_code->name); - subghz_environment_keeloq_set_mf(kl_environment, *manufacture_name, 2); + keystore->mfname = *manufacture_name; + keystore->kl_type = 2; return 1; } break; @@ -612,7 +609,7 @@ static uint8_t subghz_protocol_star_line_check_remote_controller_selector( } *manufacture_name = "Unknown"; - subghz_environment_keeloq_set_mf(kl_environment, "Unknown", kl_type_en); + keystore->mfname = "Unknown"; instance->cnt = 0; return 0; @@ -688,10 +685,7 @@ SubGhzProtocolStatus if(flipper_format_read_string( flipper_format, "Manufacture", instance->manufacture_from_file)) { instance->manufacture_name = furi_string_get_cstr(instance->manufacture_from_file); - subghz_environment_keeloq_set_mf( - kl_environment, - furi_string_get_cstr(instance->manufacture_from_file), - subghz_environment_keeloq_get_kl_type(kl_environment)); + instance->keystore->mfname = instance->manufacture_name; } else { FURI_LOG_D(TAG, "DECODER: Missing Manufacture"); } diff --git a/lib/subghz/subghz_keystore.c b/lib/subghz/subghz_keystore.c index e0b1cf6ca..d8f83fc89 100644 --- a/lib/subghz/subghz_keystore.c +++ b/lib/subghz/subghz_keystore.c @@ -1,4 +1,5 @@ #include "subghz_keystore.h" +#include "subghz_keystore_i.h" #include #include @@ -26,18 +27,25 @@ typedef enum { SubGhzKeystoreEncryptionAES256, } SubGhzKeystoreEncryption; -struct SubGhzKeystore { - SubGhzKeyArray_t data; -}; + SubGhzKeystore* subghz_keystore_alloc() { SubGhzKeystore* instance = malloc(sizeof(SubGhzKeystore)); SubGhzKeyArray_init(instance->data); + subghz_keystore_reset_kl(instance); + return instance; } +void subghz_keystore_reset_kl(SubGhzKeystore* instance) { + furi_assert(instance); + + instance->mfname = ""; + instance->kl_type = 0; +} + void subghz_keystore_free(SubGhzKeystore* instance) { furi_assert(instance); diff --git a/lib/subghz/subghz_keystore.h b/lib/subghz/subghz_keystore.h index 06ae8adae..dfb5c7373 100644 --- a/lib/subghz/subghz_keystore.h +++ b/lib/subghz/subghz_keystore.h @@ -75,6 +75,8 @@ bool subghz_keystore_raw_encrypted_save( */ bool subghz_keystore_raw_get_data(const char* file_name, size_t offset, uint8_t* data, size_t len); +void subghz_keystore_reset_kl(SubGhzKeystore* instance); + #ifdef __cplusplus } #endif diff --git a/lib/subghz/subghz_keystore_i.h b/lib/subghz/subghz_keystore_i.h new file mode 100644 index 000000000..8bf2f1e51 --- /dev/null +++ b/lib/subghz/subghz_keystore_i.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +struct SubGhzKeystore { + SubGhzKeyArray_t data; + const char* mfname; + uint8_t kl_type; +}; From a260465721171f5c4ed0e97276fbbbbde58289e9 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 30 May 2023 22:18:54 +0300 Subject: [PATCH 5/9] Prog_mode to custom_btn --- .../main/subghz/helpers/subghz_txrx.c | 2 +- .../scenes/subghz_scene_receiver_info.c | 1 - .../subghz/scenes/subghz_scene_transmitter.c | 1 - .../main/subghz_remote/subghz_remote_app_i.c | 3 - firmware/targets/f7/api_symbols.csv | 8 --- lib/subghz/blocks/custom_btn.c | 13 ++++- lib/subghz/blocks/custom_btn.h | 4 -- lib/subghz/blocks/custom_btn_i.h | 17 ++++++ lib/subghz/protocols/alutech_at_4n.c | 2 +- lib/subghz/protocols/came_atomo.c | 2 +- lib/subghz/protocols/keeloq.c | 56 +++++++++---------- lib/subghz/protocols/keeloq.h | 4 -- lib/subghz/protocols/nice_flor_s.c | 2 +- lib/subghz/protocols/secplus_v2.c | 2 +- lib/subghz/protocols/somfy_telis.c | 2 +- 15 files changed, 61 insertions(+), 58 deletions(-) create mode 100644 lib/subghz/blocks/custom_btn_i.h diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index 9d957cd29..79d05b5be 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -1,5 +1,6 @@ #include "subghz_txrx_i.h" #include +#include #define TAG "SubGhz" @@ -561,7 +562,6 @@ void subghz_txrx_reset_dynamic(SubGhzTxRx* instance) { furi_assert(instance); subghz_environment_reset_keeloq(instance->environment); - keeloq_reset_original_btn(); subghz_custom_btns_reset(); } diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index d9ba5bd84..b0c538a58 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -108,7 +108,6 @@ void subghz_scene_receiver_info_draw_widget(SubGhz* subghz) { void subghz_scene_receiver_info_on_enter(void* context) { SubGhz* subghz = context; - keeloq_reset_original_btn(); subghz_custom_btns_reset(); subghz_scene_receiver_info_draw_widget(subghz); diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index 933f619f0..dba8d13c7 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -46,7 +46,6 @@ bool subghz_scene_transmitter_update_data_show(void* context) { void subghz_scene_transmitter_on_enter(void* context) { SubGhz* subghz = context; - keeloq_reset_original_btn(); subghz_custom_btns_reset(); if(!subghz_scene_transmitter_update_data_show(subghz)) { diff --git a/applications/main/subghz_remote/subghz_remote_app_i.c b/applications/main/subghz_remote/subghz_remote_app_i.c index 6086b4c25..6ed8978de 100644 --- a/applications/main/subghz_remote/subghz_remote_app_i.c +++ b/applications/main/subghz_remote/subghz_remote_app_i.c @@ -179,8 +179,6 @@ bool subrem_tx_start_sub( FURI_LOG_I(TAG, "Send %s", furi_string_get_cstr(sub_preset->label)); - subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_OK); - keeloq_reset_original_btn(); subghz_custom_btns_reset(); do { @@ -257,7 +255,6 @@ bool subrem_tx_stop_sub(SubGhzRemoteApp* app, bool forced) { sub_preset->fff_data, furi_string_get_cstr(sub_preset->file_path)); subghz_environment_reset_keeloq(app->environment); - keeloq_reset_original_btn(); subghz_custom_btns_reset(); } diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index 1e00e181c..a7470a0b9 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1825,7 +1825,6 @@ Function,-,j1f,float,float Function,-,jn,double,"int, double" Function,-,jnf,float,"int, float" Function,-,jrand48,long,unsigned short[3] -Function,-,keeloq_reset_original_btn,void, Function,-,l64a,char*,long Function,-,labs,long,long Function,-,lcong48,void,unsigned short[7] @@ -2712,13 +2711,6 @@ Function,+,subghz_block_generic_deserialize,SubGhzProtocolStatus,"SubGhzBlockGen Function,+,subghz_block_generic_deserialize_check_count_bit,SubGhzProtocolStatus,"SubGhzBlockGeneric*, FlipperFormat*, uint16_t" 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_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, Function,+,subghz_environment_alloc,SubGhzEnvironment*, Function,+,subghz_environment_free,void,SubGhzEnvironment* Function,+,subghz_environment_get_alutech_at_4n_rainbow_table_file_name,const char*,SubGhzEnvironment* diff --git a/lib/subghz/blocks/custom_btn.c b/lib/subghz/blocks/custom_btn.c index 275a4c930..1919fc5e4 100644 --- a/lib/subghz/blocks/custom_btn.c +++ b/lib/subghz/blocks/custom_btn.c @@ -1,8 +1,9 @@ -#include "custom_btn.h" +#include "custom_btn_i.h" 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; +static uint8_t controller_programming_mode = PROG_MODE_OFF; bool subghz_custom_btn_set(uint8_t btn_id) { if(btn_id > custom_btn_max_btns) { @@ -33,8 +34,18 @@ void subghz_custom_btn_set_max(uint8_t b) { void subghz_custom_btns_reset() { custom_btn_original = 0; custom_btn_max_btns = 0; + controller_programming_mode = PROG_MODE_OFF; + custom_btn_id = SUBGHZ_CUSTOM_BTN_OK; } bool subghz_custom_btn_is_allowed() { return custom_btn_max_btns != 0; +} + +void subghz_custom_btn_set_prog_mode(ProgMode prog_mode) { + controller_programming_mode = prog_mode; +} + +ProgMode subghz_custom_btn_get_prog_mode() { + return controller_programming_mode; } \ No newline at end of file diff --git a/lib/subghz/blocks/custom_btn.h b/lib/subghz/blocks/custom_btn.h index c13842fa8..e06457ccd 100644 --- a/lib/subghz/blocks/custom_btn.h +++ b/lib/subghz/blocks/custom_btn.h @@ -15,12 +15,8 @@ bool subghz_custom_btn_set(uint8_t btn_id); uint8_t subghz_custom_btn_get(); -void subghz_custom_btn_set_original(uint8_t btn_code); - uint8_t subghz_custom_btn_get_original(); -void subghz_custom_btn_set_max(uint8_t b); - void subghz_custom_btns_reset(); bool subghz_custom_btn_is_allowed(); \ No newline at end of file diff --git a/lib/subghz/blocks/custom_btn_i.h b/lib/subghz/blocks/custom_btn_i.h new file mode 100644 index 000000000..f75ba4068 --- /dev/null +++ b/lib/subghz/blocks/custom_btn_i.h @@ -0,0 +1,17 @@ +#pragma once + +#include "custom_btn.h" + +#define PROG_MODE_OFF (0U) +#define PROG_MODE_KEELOQ_BFT (1U) +#define PROG_MODE_KEELOQ_APRIMATIC (2U) + +typedef uint8_t ProgMode; + +void subghz_custom_btn_set_original(uint8_t btn_code); + +void subghz_custom_btn_set_max(uint8_t b); + +void subghz_custom_btn_set_prog_mode(ProgMode prog_mode); + +ProgMode subghz_custom_btn_get_prog_mode(); \ No newline at end of file diff --git a/lib/subghz/protocols/alutech_at_4n.c b/lib/subghz/protocols/alutech_at_4n.c index 281e820f0..1a35550c6 100644 --- a/lib/subghz/protocols/alutech_at_4n.c +++ b/lib/subghz/protocols/alutech_at_4n.c @@ -5,7 +5,7 @@ #include "../blocks/generic.h" #include "../blocks/math.h" -#include "../blocks/custom_btn.h" +#include "../blocks/custom_btn_i.h" #define TAG "SubGhzProtocoAlutech_at_4n" diff --git a/lib/subghz/protocols/came_atomo.c b/lib/subghz/protocols/came_atomo.c index 4723ec99f..cea7ebf6f 100644 --- a/lib/subghz/protocols/came_atomo.c +++ b/lib/subghz/protocols/came_atomo.c @@ -7,7 +7,7 @@ #include "../blocks/generic.h" #include "../blocks/math.h" -#include "../blocks/custom_btn.h" +#include "../blocks/custom_btn_i.h" #define TAG "SubGhzProtocoCameAtomo" diff --git a/lib/subghz/protocols/keeloq.c b/lib/subghz/protocols/keeloq.c index df7ae748d..2163c0500 100644 --- a/lib/subghz/protocols/keeloq.c +++ b/lib/subghz/protocols/keeloq.c @@ -10,15 +10,11 @@ #include "../blocks/generic.h" #include "../blocks/math.h" -#include "../blocks/custom_btn.h" +#include "../blocks/custom_btn_i.h" #include "../subghz_keystore_i.h" #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, @@ -91,15 +87,6 @@ const SubGhzProtocol subghz_protocol_keeloq = { .encoder = &subghz_protocol_keeloq_encoder, }; -static uint8_t klq_prog_mode; -static uint16_t temp_counter; - -void keeloq_reset_original_btn() { - subghz_custom_btns_reset(); - temp_counter = 0; - klq_prog_mode = KEELOQ_PROG_MODE_OFF; -} - /** * Analysis of received data * @param instance Pointer to a SubGhzBlockGeneric* instance @@ -156,29 +143,32 @@ static bool subghz_protocol_keeloq_gen_data( } // programming mode on / off conditions + ProgMode prog_mode = subghz_custom_btn_get_prog_mode(); 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; + prog_mode = PROG_MODE_KEELOQ_BFT; + } else if(prog_mode == PROG_MODE_KEELOQ_BFT) { + prog_mode = 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; + prog_mode = PROG_MODE_KEELOQ_APRIMATIC; + } else if(prog_mode == PROG_MODE_KEELOQ_APRIMATIC) { + prog_mode = PROG_MODE_OFF; } } + subghz_custom_btn_set_prog_mode(prog_mode); + // If we using BFT programming mode we will trasmit its seed in hop part like original remote - if(klq_prog_mode == KEELOQ_PROG_MODE_BFT) { + if(prog_mode == PROG_MODE_KEELOQ_BFT) { hop = instance->generic.seed; - } else if(klq_prog_mode == KEELOQ_PROG_MODE_APRIMATIC) { + } else if(prog_mode == PROG_MODE_KEELOQ_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 == KEELOQ_PROG_MODE_OFF) { + if(counter_up && prog_mode == PROG_MODE_OFF) { if(instance->generic.cnt < 0xFFFF) { if((instance->generic.cnt + furi_hal_subghz_get_rolling_counter_mult()) >= 0xFFFF) { instance->generic.cnt = 0; @@ -189,7 +179,7 @@ static bool subghz_protocol_keeloq_gen_data( instance->generic.cnt = 0; } } - if(klq_prog_mode == KEELOQ_PROG_MODE_OFF) { + if(prog_mode == PROG_MODE_OFF) { // Protocols that do not use encryption if(strcmp(instance->manufacture_name, "Unknown") == 0) { code_found_reverse = subghz_protocol_blocks_reverse_key( @@ -390,9 +380,10 @@ static bool if(instance->manufacture_name == 0x0) { instance->manufacture_name = ""; } - if(klq_prog_mode == KEELOQ_PROG_MODE_BFT) { + ProgMode prog_mode = subghz_custom_btn_get_prog_mode(); + if(prog_mode == PROG_MODE_KEELOQ_BFT) { instance->manufacture_name = "BFT"; - } else if(klq_prog_mode == KEELOQ_PROG_MODE_APRIMATIC) { + } else if(prog_mode == PROG_MODE_KEELOQ_APRIMATIC) { instance->manufacture_name = "Aprimatic"; } uint8_t klq_last_custom_btn = 0xA; @@ -570,7 +561,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 = KEELOQ_PROG_MODE_OFF; + subghz_custom_btn_set_prog_mode(PROG_MODE_OFF); return instance; } @@ -930,9 +921,11 @@ static void subghz_protocol_keeloq_check_remote_controller( uint64_t key = subghz_protocol_blocks_reverse_key(instance->data, instance->data_count_bit); uint32_t key_fix = key >> 32; uint32_t key_hop = key & 0x00000000ffffffff; + static uint16_t temp_counter = 0; // Be careful with prog_mode // 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) { + ProgMode prog_mode = subghz_custom_btn_get_prog_mode(); + if(prog_mode == 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) { @@ -949,14 +942,17 @@ static void subghz_protocol_keeloq_check_remote_controller( } temp_counter = instance->cnt; - } else if(klq_prog_mode == KEELOQ_PROG_MODE_BFT) { + } else if(prog_mode == PROG_MODE_KEELOQ_BFT) { *manufacture_name = "BFT"; keystore->mfname = *manufacture_name; instance->cnt = temp_counter; - } else if(klq_prog_mode == KEELOQ_PROG_MODE_APRIMATIC) { + } else if(prog_mode == PROG_MODE_KEELOQ_APRIMATIC) { *manufacture_name = "Aprimatic"; keystore->mfname = *manufacture_name; instance->cnt = temp_counter; + } else { + // Counter protection + furi_crash("Unsuported Prog Mode"); } instance->serial = key_fix & 0x0FFFFFFF; diff --git a/lib/subghz/protocols/keeloq.h b/lib/subghz/protocols/keeloq.h index 26f569e8c..a757e82d5 100644 --- a/lib/subghz/protocols/keeloq.h +++ b/lib/subghz/protocols/keeloq.h @@ -2,8 +2,6 @@ #include "base.h" -#include "../blocks/custom_btn.h" - #define SUBGHZ_PROTOCOL_KEELOQ_NAME "KeeLoq" typedef struct SubGhzProtocolDecoderKeeloq SubGhzProtocolDecoderKeeloq; @@ -13,8 +11,6 @@ extern const SubGhzProtocolDecoder subghz_protocol_keeloq_decoder; extern const SubGhzProtocolEncoder subghz_protocol_keeloq_encoder; extern const SubGhzProtocol subghz_protocol_keeloq; -void keeloq_reset_original_btn(); - /** * Allocate SubGhzProtocolEncoderKeeloq. * @param environment Pointer to a SubGhzEnvironment instance diff --git a/lib/subghz/protocols/nice_flor_s.c b/lib/subghz/protocols/nice_flor_s.c index 5eaa21274..eca9c4e95 100644 --- a/lib/subghz/protocols/nice_flor_s.c +++ b/lib/subghz/protocols/nice_flor_s.c @@ -6,7 +6,7 @@ #include "../blocks/generic.h" #include "../blocks/math.h" -#include "../blocks/custom_btn.h" +#include "../blocks/custom_btn_i.h" /* * https://phreakerclub.com/1615 diff --git a/lib/subghz/protocols/secplus_v2.c b/lib/subghz/protocols/secplus_v2.c index d39f794ab..607c929ea 100644 --- a/lib/subghz/protocols/secplus_v2.c +++ b/lib/subghz/protocols/secplus_v2.c @@ -7,7 +7,7 @@ #include "../blocks/generic.h" #include "../blocks/math.h" -#include "../blocks/custom_btn.h" +#include "../blocks/custom_btn_i.h" /* * Help diff --git a/lib/subghz/protocols/somfy_telis.c b/lib/subghz/protocols/somfy_telis.c index 6a159a7ea..5fbd90275 100644 --- a/lib/subghz/protocols/somfy_telis.c +++ b/lib/subghz/protocols/somfy_telis.c @@ -7,7 +7,7 @@ #include "../blocks/generic.h" #include "../blocks/math.h" -#include "../blocks/custom_btn.h" +#include "../blocks/custom_btn_i.h" #define TAG "SubGhzProtocolSomfyTelis" From 6ad58276f89cbf92a86800e94d9b7bd007ce99ac Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 30 May 2023 22:21:47 +0300 Subject: [PATCH 6/9] Cleanup and rename --- applications/main/subghz/helpers/subghz_txrx.c | 2 +- applications/main/subghz/helpers/subghz_txrx.h | 2 +- applications/main/subghz/scenes/subghz_scene_receiver_info.c | 4 +--- applications/main/subghz/scenes/subghz_scene_rpc.c | 4 +--- applications/main/subghz/scenes/subghz_scene_transmitter.c | 4 +--- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index 79d05b5be..3275b7288 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -558,7 +558,7 @@ bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance) { return instance->debug_pin_state; } -void subghz_txrx_reset_dynamic(SubGhzTxRx* instance) { +void subghz_txrx_reset_dynamic_and_custom_btns(SubGhzTxRx* instance) { furi_assert(instance); subghz_environment_reset_keeloq(instance->environment); diff --git a/applications/main/subghz/helpers/subghz_txrx.h b/applications/main/subghz/helpers/subghz_txrx.h index 6c28cc5f0..6ad5d97bd 100644 --- a/applications/main/subghz/helpers/subghz_txrx.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -293,6 +293,6 @@ void subghz_txrx_set_raw_file_encoder_worker_callback_end( void subghz_txrx_set_debug_pin_state(SubGhzTxRx* instance, bool state); bool subghz_txrx_get_debug_pin_state(SubGhzTxRx* instance); -void subghz_txrx_reset_dynamic(SubGhzTxRx* instance); +void subghz_txrx_reset_dynamic_and_custom_btns(SubGhzTxRx* instance); SubGhzReceiver* subghz_txrx_get_receiver(SubGhzTxRx* instance); // TODO use only in DecodeRaw diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index b0c538a58..e3ff485d2 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -1,7 +1,5 @@ #include "../subghz_i.h" #include "../helpers/subghz_custom_event.h" -#include -#include #include @@ -190,5 +188,5 @@ void subghz_scene_receiver_info_on_exit(void* context) { SubGhz* subghz = context; widget_reset(subghz->widget); - subghz_txrx_reset_dynamic(subghz->txrx); + subghz_txrx_reset_dynamic_and_custom_btns(subghz->txrx); } diff --git a/applications/main/subghz/scenes/subghz_scene_rpc.c b/applications/main/subghz/scenes/subghz_scene_rpc.c index edadc89bb..7b3c940a5 100644 --- a/applications/main/subghz/scenes/subghz_scene_rpc.c +++ b/applications/main/subghz/scenes/subghz_scene_rpc.c @@ -1,6 +1,4 @@ #include "../subghz_i.h" -#include -#include #include @@ -110,5 +108,5 @@ void subghz_scene_rpc_on_exit(void* context) { popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop); popup_set_icon(popup, 0, 0, NULL); - subghz_txrx_reset_dynamic(subghz->txrx); + subghz_txrx_reset_dynamic_and_custom_btns(subghz->txrx); } diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index dba8d13c7..ab5605f95 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -1,8 +1,6 @@ #include "../subghz_i.h" #include "../views/transmitter.h" #include -#include -#include #include @@ -107,5 +105,5 @@ void subghz_scene_transmitter_on_exit(void* context) { SubGhz* subghz = context; subghz->state_notifications = SubGhzNotificationStateIDLE; - subghz_txrx_reset_dynamic(subghz->txrx); + subghz_txrx_reset_dynamic_and_custom_btns(subghz->txrx); } From 6374474b259c3ad18edc8e9778121f7d2152febb Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 31 May 2023 10:39:11 +0300 Subject: [PATCH 7/9] fmt --- applications/main/subghz_remote/subghz_remote_app_i.c | 4 ++-- lib/subghz/subghz_keystore.c | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/applications/main/subghz_remote/subghz_remote_app_i.c b/applications/main/subghz_remote/subghz_remote_app_i.c index f530a4356..543c39d08 100644 --- a/applications/main/subghz_remote/subghz_remote_app_i.c +++ b/applications/main/subghz_remote/subghz_remote_app_i.c @@ -221,7 +221,7 @@ bool subrem_tx_start_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset) subghz_txrx_load_decoder_by_name_protocol( app->txrx, furi_string_get_cstr(sub_preset->protocaol_name)); - subghz_custom_btns_reset(); + subghz_custom_btns_reset(); subghz_txrx_set_preset( app->txrx, furi_string_get_cstr(sub_preset->freq_preset.name), @@ -251,7 +251,7 @@ bool subrem_tx_stop_sub(SubGhzRemoteApp* app, bool forced) { subghz_txrx_stop(app->txrx); #ifdef APP_SUBGHZREMOTE if(sub_preset->type == SubGhzProtocolTypeDynamic) { - subghz_environment_reset_keeloq(app->environment); + subghz_environment_reset_keeloq(app->environment); } keeloq_reset_original_btn(); subghz_custom_btns_reset(); diff --git a/lib/subghz/subghz_keystore.c b/lib/subghz/subghz_keystore.c index d8f83fc89..54ed15a99 100644 --- a/lib/subghz/subghz_keystore.c +++ b/lib/subghz/subghz_keystore.c @@ -27,8 +27,6 @@ typedef enum { SubGhzKeystoreEncryptionAES256, } SubGhzKeystoreEncryption; - - SubGhzKeystore* subghz_keystore_alloc() { SubGhzKeystore* instance = malloc(sizeof(SubGhzKeystore)); From e60707d7ef9160af73f5d28590b6aa62b3043f1e Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 31 May 2023 12:18:24 +0300 Subject: [PATCH 8/9] need to fix that --- applications/main/subghz_remote/subghz_remote_app_i.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/applications/main/subghz_remote/subghz_remote_app_i.c b/applications/main/subghz_remote/subghz_remote_app_i.c index 543c39d08..6d23427eb 100644 --- a/applications/main/subghz_remote/subghz_remote_app_i.c +++ b/applications/main/subghz_remote/subghz_remote_app_i.c @@ -231,7 +231,6 @@ bool subrem_tx_start_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset) #ifdef APP_SUBGHZREMOTE subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_OK); - keeloq_reset_original_btn(); subghz_custom_btns_reset(); #endif @@ -251,9 +250,8 @@ bool subrem_tx_stop_sub(SubGhzRemoteApp* app, bool forced) { subghz_txrx_stop(app->txrx); #ifdef APP_SUBGHZREMOTE if(sub_preset->type == SubGhzProtocolTypeDynamic) { - subghz_environment_reset_keeloq(app->environment); + //subghz_environment_reset_keeloq(&app->txrx->environment); } - keeloq_reset_original_btn(); subghz_custom_btns_reset(); #endif return true; From 53dbf8de726ea942300253d39bb8d44e874a3490 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Wed, 31 May 2023 12:25:45 +0300 Subject: [PATCH 9/9] fix --- applications/main/subghz_remote/subghz_remote_app_i.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/applications/main/subghz_remote/subghz_remote_app_i.c b/applications/main/subghz_remote/subghz_remote_app_i.c index 6d23427eb..26659ccb1 100644 --- a/applications/main/subghz_remote/subghz_remote_app_i.c +++ b/applications/main/subghz_remote/subghz_remote_app_i.c @@ -221,7 +221,6 @@ bool subrem_tx_start_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset) subghz_txrx_load_decoder_by_name_protocol( app->txrx, furi_string_get_cstr(sub_preset->protocaol_name)); - subghz_custom_btns_reset(); subghz_txrx_set_preset( app->txrx, furi_string_get_cstr(sub_preset->freq_preset.name), @@ -230,7 +229,6 @@ bool subrem_tx_start_sub(SubGhzRemoteApp* app, SubRemSubFilePreset* sub_preset) 0); #ifdef APP_SUBGHZREMOTE - subghz_custom_btn_set(SUBGHZ_CUSTOM_BTN_OK); subghz_custom_btns_reset(); #endif @@ -250,7 +248,7 @@ bool subrem_tx_stop_sub(SubGhzRemoteApp* app, bool forced) { subghz_txrx_stop(app->txrx); #ifdef APP_SUBGHZREMOTE if(sub_preset->type == SubGhzProtocolTypeDynamic) { - //subghz_environment_reset_keeloq(&app->txrx->environment); + subghz_txrx_reset_dynamic_and_custom_btns(app->txrx); } subghz_custom_btns_reset(); #endif